aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acorn/char/i2c.c1
-rw-r--r--drivers/acpi/acpi_memhotplug.c4
-rw-r--r--drivers/acpi/i2c_ec.c2
-rw-r--r--drivers/acpi/osl.c2
-rw-r--r--drivers/acpi/processor_idle.c38
-rw-r--r--drivers/ata/Kconfig3
-rw-r--r--drivers/ata/ata_generic.c2
-rw-r--r--drivers/ata/ata_piix.c10
-rw-r--r--drivers/ata/libata-core.c5
-rw-r--r--drivers/ata/libata-eh.c6
-rw-r--r--drivers/ata/libata-sff.c6
-rw-r--r--drivers/ata/pata_ali.c8
-rw-r--r--drivers/ata/pata_amd.c37
-rw-r--r--drivers/ata/pata_artop.c22
-rw-r--r--drivers/ata/pata_atiixp.c12
-rw-r--r--drivers/ata/pata_cmd64x.c6
-rw-r--r--drivers/ata/pata_cs5520.c2
-rw-r--r--drivers/ata/pata_cs5530.c2
-rw-r--r--drivers/ata/pata_cs5535.c2
-rw-r--r--drivers/ata/pata_cypress.c2
-rw-r--r--drivers/ata/pata_efar.c12
-rw-r--r--drivers/ata/pata_hpt366.c4
-rw-r--r--drivers/ata/pata_hpt37x.c8
-rw-r--r--drivers/ata/pata_hpt3x2n.c2
-rw-r--r--drivers/ata/pata_hpt3x3.c2
-rw-r--r--drivers/ata/pata_isapnp.c2
-rw-r--r--drivers/ata/pata_it821x.c4
-rw-r--r--drivers/ata/pata_jmicron.c5
-rw-r--r--drivers/ata/pata_legacy.c14
-rw-r--r--drivers/ata/pata_mpiix.c11
-rw-r--r--drivers/ata/pata_netcell.c3
-rw-r--r--drivers/ata/pata_ns87410.c9
-rw-r--r--drivers/ata/pata_oldpiix.c9
-rw-r--r--drivers/ata/pata_opti.c12
-rw-r--r--drivers/ata/pata_optidma.c14
-rw-r--r--drivers/ata/pata_pcmcia.c2
-rw-r--r--drivers/ata/pata_pdc2027x.c8
-rw-r--r--drivers/ata/pata_qdi.c4
-rw-r--r--drivers/ata/pata_radisys.c2
-rw-r--r--drivers/ata/pata_rz1000.c2
-rw-r--r--drivers/ata/pata_sc1200.c2
-rw-r--r--drivers/ata/pata_serverworks.c12
-rw-r--r--drivers/ata/pata_sil680.c2
-rw-r--r--drivers/ata/pata_sis.c20
-rw-r--r--drivers/ata/pata_sl82c105.c11
-rw-r--r--drivers/ata/pata_triflex.c15
-rw-r--r--drivers/ata/pata_via.c13
-rw-r--r--drivers/ata/sata_mv.c1
-rw-r--r--drivers/ata/sata_nv.c6
-rw-r--r--drivers/ata/sata_sis.c6
-rw-r--r--drivers/ata/sata_uli.c6
-rw-r--r--drivers/ata/sata_via.c7
-rw-r--r--drivers/base/Makefile2
-rw-r--r--drivers/base/base.h2
-rw-r--r--drivers/base/bus.c133
-rw-r--r--drivers/base/class.c42
-rw-r--r--drivers/base/core.c230
-rw-r--r--drivers/base/dd.c147
-rw-r--r--drivers/base/driver.c16
-rw-r--r--drivers/base/firmware_class.c14
-rw-r--r--drivers/base/node.c13
-rw-r--r--drivers/base/platform.c30
-rw-r--r--drivers/base/power/resume.c37
-rw-r--r--drivers/base/power/suspend.c92
-rw-r--r--drivers/base/power/sysfs.c35
-rw-r--r--drivers/block/DAC960.c4
-rw-r--r--drivers/block/DAC960.h2
-rw-r--r--drivers/block/Kconfig4
-rw-r--r--drivers/block/cciss.c238
-rw-r--r--drivers/block/cciss.h3
-rw-r--r--drivers/block/cciss_cmd.h33
-rw-r--r--drivers/block/cciss_scsi.c2
-rw-r--r--drivers/block/cpqarray.c1
-rw-r--r--drivers/block/floppy.c4
-rw-r--r--drivers/block/loop.c247
-rw-r--r--drivers/block/nbd.c8
-rw-r--r--drivers/block/paride/pd.c8
-rw-r--r--drivers/block/pktcdvd.c10
-rw-r--r--drivers/block/swim3.c4
-rw-r--r--drivers/block/swim_iop.c4
-rw-r--r--drivers/block/ub.c38
-rw-r--r--drivers/block/umem.c3
-rw-r--r--drivers/block/xd.c2
-rw-r--r--drivers/bluetooth/bfusb.c316
-rw-r--r--drivers/bluetooth/hci_ldisc.c13
-rw-r--r--drivers/bluetooth/hci_usb.c3
-rw-r--r--drivers/bluetooth/hci_vhci.c99
-rw-r--r--drivers/cdrom/Kconfig2
-rw-r--r--drivers/cdrom/cdrom.c2
-rw-r--r--drivers/cdrom/cdu31a.c4
-rw-r--r--drivers/char/Kconfig19
-rw-r--r--drivers/char/Makefile2
-rw-r--r--drivers/char/agp/amd64-agp.c8
-rw-r--r--drivers/char/agp/generic.c9
-rw-r--r--drivers/char/amiserial.c2
-rw-r--r--drivers/char/cyclades.c2
-rw-r--r--drivers/char/drm/Kconfig9
-rw-r--r--drivers/char/drm/Makefile6
-rw-r--r--drivers/char/drm/drmP.h68
-rw-r--r--drivers/char/drm/drm_auth.c64
-rw-r--r--drivers/char/drm/drm_bufs.c74
-rw-r--r--drivers/char/drm/drm_drv.c12
-rw-r--r--drivers/char/drm/drm_fops.c10
-rw-r--r--drivers/char/drm/drm_hashtab.c190
-rw-r--r--drivers/char/drm/drm_hashtab.h67
-rw-r--r--drivers/char/drm/drm_ioc32.c2
-rw-r--r--drivers/char/drm/drm_ioctl.c34
-rw-r--r--drivers/char/drm/drm_irq.c12
-rw-r--r--drivers/char/drm/drm_mm.c201
-rw-r--r--drivers/char/drm/drm_pciids.h187
-rw-r--r--drivers/char/drm/drm_proc.c2
-rw-r--r--drivers/char/drm/drm_sman.c352
-rw-r--r--drivers/char/drm/drm_sman.h176
-rw-r--r--drivers/char/drm/drm_stub.c12
-rw-r--r--drivers/char/drm/drm_vm.c45
-rw-r--r--drivers/char/drm/i810_dma.c10
-rw-r--r--drivers/char/drm/i830_dma.c4
-rw-r--r--drivers/char/drm/i915_dma.c45
-rw-r--r--drivers/char/drm/i915_drm.h6
-rw-r--r--drivers/char/drm/i915_drv.h10
-rw-r--r--drivers/char/drm/i915_irq.c16
-rw-r--r--drivers/char/drm/radeon_cp.c72
-rw-r--r--drivers/char/drm/radeon_drv.c2
-rw-r--r--drivers/char/drm/radeon_drv.h36
-rw-r--r--drivers/char/drm/radeon_state.c48
-rw-r--r--drivers/char/drm/sis_drv.c39
-rw-r--r--drivers/char/drm/sis_drv.h34
-rw-r--r--drivers/char/drm/sis_ds.c299
-rw-r--r--drivers/char/drm/sis_ds.h146
-rw-r--r--drivers/char/drm/sis_mm.c504
-rw-r--r--drivers/char/drm/via_dmablit.c68
-rw-r--r--drivers/char/drm/via_drm.h8
-rw-r--r--drivers/char/drm/via_drv.c3
-rw-r--r--drivers/char/drm/via_drv.h16
-rw-r--r--drivers/char/drm/via_ds.c273
-rw-r--r--drivers/char/drm/via_ds.h104
-rw-r--r--drivers/char/drm/via_map.c9
-rw-r--r--drivers/char/drm/via_mm.c375
-rw-r--r--drivers/char/ds1286.c15
-rw-r--r--drivers/char/epca.c2
-rw-r--r--drivers/char/esp.c2
-rw-r--r--drivers/char/generic_serial.c11
-rw-r--r--drivers/char/hpet.c4
-rw-r--r--drivers/char/hvc_console.c2
-rw-r--r--drivers/char/hvcs.c2
-rw-r--r--drivers/char/hvsi.c2
-rw-r--r--drivers/char/hw_random/intel-rng.c186
-rw-r--r--drivers/char/ip2/ip2main.c14
-rw-r--r--drivers/char/ipmi/ipmi_devintf.c34
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c75
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c26
-rw-r--r--drivers/char/isicom.c37
-rw-r--r--drivers/char/istallion.c22
-rw-r--r--drivers/char/keyboard.c25
-rw-r--r--drivers/char/lp.c4
-rw-r--r--drivers/char/mbcs.c7
-rw-r--r--drivers/char/mem.c47
-rw-r--r--drivers/char/moxa.c82
-rw-r--r--drivers/char/mspec.c421
-rw-r--r--drivers/char/mwave/mwavedd.c4
-rw-r--r--drivers/char/mxser.c68
-rw-r--r--drivers/char/nwbutton.c5
-rw-r--r--drivers/char/pc8736x_gpio.c10
-rw-r--r--drivers/char/pcmcia/synclink_cs.c2
-rw-r--r--drivers/char/pty.c2
-rw-r--r--drivers/char/random.c8
-rw-r--r--drivers/char/raw.c50
-rw-r--r--drivers/char/rio/rio_linux.c2
-rw-r--r--drivers/char/riscom8.c24
-rw-r--r--drivers/char/rocket.c2
-rw-r--r--drivers/char/rtc.c4
-rw-r--r--drivers/char/s3c2410-rtc.c591
-rw-r--r--drivers/char/scx200_gpio.c4
-rw-r--r--drivers/char/selection.c2
-rw-r--r--drivers/char/ser_a2232.c2
-rw-r--r--drivers/char/serial167.c2
-rw-r--r--drivers/char/snsc_event.c2
-rw-r--r--drivers/char/specialix.c29
-rw-r--r--drivers/char/stallion.c2
-rw-r--r--drivers/char/sx.c2
-rw-r--r--drivers/char/synclink.c2
-rw-r--r--drivers/char/synclink_gt.c96
-rw-r--r--drivers/char/synclinkmp.c2
-rw-r--r--drivers/char/sysrq.c3
-rw-r--r--drivers/char/tipar.c6
-rw-r--r--drivers/char/tty_io.c107
-rw-r--r--drivers/char/tty_ioctl.c35
-rw-r--r--drivers/char/vc_screen.c5
-rw-r--r--drivers/char/viocons.c2
-rw-r--r--drivers/char/vme_scc.c2
-rw-r--r--drivers/char/vt.c146
-rw-r--r--drivers/char/vt_ioctl.c34
-rw-r--r--drivers/char/watchdog/Kconfig26
-rw-r--r--drivers/char/watchdog/Makefile2
-rw-r--r--drivers/char/watchdog/acquirewdt.c2
-rw-r--r--drivers/char/watchdog/advantechwdt.c2
-rw-r--r--drivers/char/watchdog/alim1535_wdt.c12
-rw-r--r--drivers/char/watchdog/alim7101_wdt.c17
-rw-r--r--drivers/char/watchdog/at91_wdt.c2
-rw-r--r--drivers/char/watchdog/booke_wdt.c2
-rw-r--r--drivers/char/watchdog/cpu5wdt.c2
-rw-r--r--drivers/char/watchdog/ep93xx_wdt.c2
-rw-r--r--drivers/char/watchdog/eurotechwdt.c2
-rw-r--r--drivers/char/watchdog/i6300esb.c2
-rw-r--r--drivers/char/watchdog/i8xx_tco.c35
-rw-r--r--drivers/char/watchdog/ib700wdt.c2
-rw-r--r--drivers/char/watchdog/ibmasr.c2
-rw-r--r--drivers/char/watchdog/indydog.c2
-rw-r--r--drivers/char/watchdog/ixp2000_wdt.c2
-rw-r--r--drivers/char/watchdog/ixp4xx_wdt.c2
-rw-r--r--drivers/char/watchdog/machzwd.c5
-rw-r--r--drivers/char/watchdog/mixcomwd.c2
-rw-r--r--drivers/char/watchdog/mpc83xx_wdt.c2
-rw-r--r--drivers/char/watchdog/mpc8xx_wdt.c2
-rw-r--r--drivers/char/watchdog/mpcore_wdt.c4
-rw-r--r--drivers/char/watchdog/mv64x60_wdt.c2
-rw-r--r--drivers/char/watchdog/omap_wdt.c391
-rw-r--r--drivers/char/watchdog/omap_wdt.h64
-rw-r--r--drivers/char/watchdog/pcwd.c2
-rw-r--r--drivers/char/watchdog/pcwd_pci.c2
-rw-r--r--drivers/char/watchdog/pcwd_usb.c2
-rw-r--r--drivers/char/watchdog/pnx4008_wdt.c362
-rw-r--r--drivers/char/watchdog/s3c2410_wdt.c12
-rw-r--r--drivers/char/watchdog/sa1100_wdt.c2
-rw-r--r--drivers/char/watchdog/sbc60xxwdt.c2
-rw-r--r--drivers/char/watchdog/sbc_epx_c3.c2
-rw-r--r--drivers/char/watchdog/sc1200wdt.c2
-rw-r--r--drivers/char/watchdog/sc520_wdt.c2
-rw-r--r--drivers/char/watchdog/scx200_wdt.c2
-rw-r--r--drivers/char/watchdog/shwdt.c112
-rw-r--r--drivers/char/watchdog/softdog.c2
-rw-r--r--drivers/char/watchdog/w83627hf_wdt.c2
-rw-r--r--drivers/char/watchdog/w83877f_wdt.c2
-rw-r--r--drivers/char/watchdog/w83977f_wdt.c2
-rw-r--r--drivers/char/watchdog/wafer5823wdt.c2
-rw-r--r--drivers/char/watchdog/wdrtas.c2
-rw-r--r--drivers/char/watchdog/wdt.c2
-rw-r--r--drivers/char/watchdog/wdt285.c2
-rw-r--r--drivers/char/watchdog/wdt977.c2
-rw-r--r--drivers/char/watchdog/wdt_pci.c2
-rw-r--r--drivers/cpufreq/cpufreq.c2
-rw-r--r--drivers/eisa/eisa-bus.c23
-rw-r--r--drivers/fc4/fc.c1
-rw-r--r--drivers/firmware/dell_rbu.c4
-rw-r--r--drivers/firmware/dmi_scan.c23
-rw-r--r--drivers/hwmon/Kconfig51
-rw-r--r--drivers/hwmon/Makefile2
-rw-r--r--drivers/hwmon/abituguru.c30
-rw-r--r--drivers/hwmon/adm1021.c31
-rw-r--r--drivers/hwmon/adm1025.c94
-rw-r--r--drivers/hwmon/adm1026.c286
-rw-r--r--drivers/hwmon/adm1031.c114
-rw-r--r--drivers/hwmon/adm9240.c105
-rw-r--r--drivers/hwmon/asb100.c122
-rw-r--r--drivers/hwmon/atxp1.c28
-rw-r--r--drivers/hwmon/ds1621.c28
-rw-r--r--drivers/hwmon/f71805f.c336
-rw-r--r--drivers/hwmon/fscher.c106
-rw-r--r--drivers/hwmon/fscpos.c75
-rw-r--r--drivers/hwmon/gl518sm.c74
-rw-r--r--drivers/hwmon/gl520sm.c128
-rw-r--r--drivers/hwmon/hdaps.c7
-rw-r--r--drivers/hwmon/it87.c470
-rw-r--r--drivers/hwmon/k8temp.c294
-rw-r--r--drivers/hwmon/lm63.c96
-rw-r--r--drivers/hwmon/lm75.c24
-rw-r--r--drivers/hwmon/lm77.c33
-rw-r--r--drivers/hwmon/lm78.c89
-rw-r--r--drivers/hwmon/lm80.c85
-rw-r--r--drivers/hwmon/lm83.c128
-rw-r--r--drivers/hwmon/lm85.c173
-rw-r--r--drivers/hwmon/lm87.c191
-rw-r--r--drivers/hwmon/lm90.c90
-rw-r--r--drivers/hwmon/lm92.c34
-rw-r--r--drivers/hwmon/max1619.c33
-rw-r--r--drivers/hwmon/pc87360.c231
-rw-r--r--drivers/hwmon/sis5595.c102
-rw-r--r--drivers/hwmon/smsc47b397.c40
-rw-r--r--drivers/hwmon/smsc47m1.c82
-rw-r--r--drivers/hwmon/smsc47m192.c150
-rw-r--r--drivers/hwmon/via686a.c84
-rw-r--r--drivers/hwmon/vt1211.c1355
-rw-r--r--drivers/hwmon/vt8231.c187
-rw-r--r--drivers/hwmon/w83627ehf.c486
-rw-r--r--drivers/hwmon/w83627hf.c233
-rw-r--r--drivers/hwmon/w83781d.c278
-rw-r--r--drivers/hwmon/w83791d.c7
-rw-r--r--drivers/hwmon/w83792d.c554
-rw-r--r--drivers/hwmon/w83l785ts.c28
-rw-r--r--drivers/i2c/Kconfig2
-rw-r--r--drivers/i2c/algos/Kconfig6
-rw-r--r--drivers/i2c/algos/Makefile1
-rw-r--r--drivers/i2c/algos/i2c-algo-bit.c23
-rw-r--r--drivers/i2c/algos/i2c-algo-pca.c2
-rw-r--r--drivers/i2c/algos/i2c-algo-pcf.c2
-rw-r--r--drivers/i2c/algos/i2c-algo-sgi.c2
-rw-r--r--drivers/i2c/algos/i2c-algo-sibyte.c215
-rw-r--r--drivers/i2c/busses/Kconfig36
-rw-r--r--drivers/i2c/busses/Makefile1
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c2
-rw-r--r--drivers/i2c/busses/i2c-ali1563.c2
-rw-r--r--drivers/i2c/busses/i2c-ali15x3.c2
-rw-r--r--drivers/i2c/busses/i2c-amd756.c2
-rw-r--r--drivers/i2c/busses/i2c-amd8111.c2
-rw-r--r--drivers/i2c/busses/i2c-au1550.c21
-rw-r--r--drivers/i2c/busses/i2c-elektor.c1
-rw-r--r--drivers/i2c/busses/i2c-hydra.c1
-rw-r--r--drivers/i2c/busses/i2c-i801.c2
-rw-r--r--drivers/i2c/busses/i2c-i810.c2
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c2
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c18
-rw-r--r--drivers/i2c/busses/i2c-isa.c42
-rw-r--r--drivers/i2c/busses/i2c-ite.c2
-rw-r--r--drivers/i2c/busses/i2c-ixp2000.c1
-rw-r--r--drivers/i2c/busses/i2c-ixp4xx.c1
-rw-r--r--drivers/i2c/busses/i2c-mpc.c2
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c2
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c2
-rw-r--r--drivers/i2c/busses/i2c-ocores.c2
-rw-r--r--drivers/i2c/busses/i2c-omap.c676
-rw-r--r--drivers/i2c/busses/i2c-parport-light.c1
-rw-r--r--drivers/i2c/busses/i2c-parport.c1
-rw-r--r--drivers/i2c/busses/i2c-piix4.c2
-rw-r--r--drivers/i2c/busses/i2c-powermac.c2
-rw-r--r--drivers/i2c/busses/i2c-prosavage.c1
-rw-r--r--drivers/i2c/busses/i2c-pxa.c2
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c2
-rw-r--r--drivers/i2c/busses/i2c-savage4.c1
-rw-r--r--drivers/i2c/busses/i2c-sibyte.c160
-rw-r--r--drivers/i2c/busses/i2c-sis5595.c2
-rw-r--r--drivers/i2c/busses/i2c-sis630.c2
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c2
-rw-r--r--drivers/i2c/busses/i2c-stub.c21
-rw-r--r--drivers/i2c/busses/i2c-via.c1
-rw-r--r--drivers/i2c/busses/i2c-viapro.c10
-rw-r--r--drivers/i2c/busses/i2c-voodoo3.c2
-rw-r--r--drivers/i2c/busses/scx200_acb.c2
-rw-r--r--drivers/i2c/busses/scx200_i2c.c12
-rw-r--r--drivers/i2c/chips/eeprom.c8
-rw-r--r--drivers/i2c/chips/isp1301_omap.c2
-rw-r--r--drivers/i2c/chips/max6875.c25
-rw-r--r--drivers/i2c/chips/pca9539.c11
-rw-r--r--drivers/i2c/chips/pcf8574.c22
-rw-r--r--drivers/i2c/chips/pcf8591.c58
-rw-r--r--drivers/i2c/chips/tps65010.c2
-rw-r--r--drivers/i2c/i2c-core.c87
-rw-r--r--drivers/i2c/i2c-dev.c109
-rw-r--r--drivers/ide/Kconfig12
-rw-r--r--drivers/ide/ide-cd.c69
-rw-r--r--drivers/ide/ide-disk.c5
-rw-r--r--drivers/ide/ide-dma.c64
-rw-r--r--drivers/ide/ide-floppy.c17
-rw-r--r--drivers/ide/ide-io.c82
-rw-r--r--drivers/ide/ide-iops.c4
-rw-r--r--drivers/ide/ide-lib.c130
-rw-r--r--drivers/ide/ide-probe.c25
-rw-r--r--drivers/ide/ide-proc.c22
-rw-r--r--drivers/ide/ide-tape.c16
-rw-r--r--drivers/ide/ide-taskfile.c8
-rw-r--r--drivers/ide/ide.c41
-rw-r--r--drivers/ide/legacy/hd.c2
-rw-r--r--drivers/ide/legacy/ide-cs.c7
-rw-r--r--drivers/ide/mips/au1xxx-ide.c4
-rw-r--r--drivers/ide/pci/Makefile1
-rw-r--r--drivers/ide/pci/atiixp.c21
-rw-r--r--drivers/ide/pci/cs5530.c13
-rw-r--r--drivers/ide/pci/cy82c693.c5
-rw-r--r--drivers/ide/pci/generic.c11
-rw-r--r--drivers/ide/pci/jmicron.c269
-rw-r--r--drivers/ide/pci/pdc202xx_old.c22
-rw-r--r--drivers/ide/pci/piix.c33
-rw-r--r--drivers/ide/pci/sc1200.c4
-rw-r--r--drivers/ide/pci/serverworks.c8
-rw-r--r--drivers/ide/pci/sgiioc4.c20
-rw-r--r--drivers/ide/pci/siimage.c1
-rw-r--r--drivers/ide/pci/sis5513.c3
-rw-r--r--drivers/ide/pci/via82cxxx.c5
-rw-r--r--drivers/ide/ppc/pmac.c14
-rw-r--r--drivers/ide/setup-pci.c20
-rw-r--r--drivers/ieee1394/Kconfig11
-rw-r--r--drivers/ieee1394/csr.c31
-rw-r--r--drivers/ieee1394/csr.h109
-rw-r--r--drivers/ieee1394/dma.c7
-rw-r--r--drivers/ieee1394/dma.h90
-rw-r--r--drivers/ieee1394/dv1394-private.h6
-rw-r--r--drivers/ieee1394/dv1394.c47
-rw-r--r--drivers/ieee1394/eth1394.c12
-rw-r--r--drivers/ieee1394/highlevel.h201
-rw-r--r--drivers/ieee1394/hosts.c23
-rw-r--r--drivers/ieee1394/hosts.h51
-rw-r--r--drivers/ieee1394/ieee1394-ioctl.h9
-rw-r--r--drivers/ieee1394/ieee1394.h316
-rw-r--r--drivers/ieee1394/ieee1394_core.c9
-rw-r--r--drivers/ieee1394/ieee1394_core.h28
-rw-r--r--drivers/ieee1394/ieee1394_hotplug.h30
-rw-r--r--drivers/ieee1394/ieee1394_transactions.c114
-rw-r--r--drivers/ieee1394/ieee1394_transactions.h41
-rw-r--r--drivers/ieee1394/ieee1394_types.h68
-rw-r--r--drivers/ieee1394/iso.c5
-rw-r--r--drivers/ieee1394/iso.h87
-rw-r--r--drivers/ieee1394/nodemgr.c227
-rw-r--r--drivers/ieee1394/nodemgr.h27
-rw-r--r--drivers/ieee1394/ohci1394.c73
-rw-r--r--drivers/ieee1394/pcilynx.c1
-rw-r--r--drivers/ieee1394/raw1394-private.h3
-rw-r--r--drivers/ieee1394/raw1394.c138
-rw-r--r--drivers/ieee1394/sbp2.c481
-rw-r--r--drivers/ieee1394/sbp2.h37
-rw-r--r--drivers/ieee1394/video1394.c52
-rw-r--r--drivers/infiniband/core/addr.c4
-rw-r--r--drivers/infiniband/core/cma.c47
-rw-r--r--drivers/infiniband/core/mad.c5
-rw-r--r--drivers/infiniband/hw/amso1100/c2_ae.c2
-rw-r--r--drivers/infiniband/hw/amso1100/c2_alloc.c2
-rw-r--r--drivers/infiniband/hw/amso1100/c2_cm.c15
-rw-r--r--drivers/infiniband/hw/amso1100/c2_provider.c8
-rw-r--r--drivers/infiniband/hw/amso1100/c2_rnic.c4
-rw-r--r--drivers/infiniband/hw/ehca/ehca_main.c36
-rw-r--r--drivers/infiniband/hw/ehca/ehca_tools.h2
-rw-r--r--drivers/infiniband/hw/ipath/ipath_common.h54
-rw-r--r--drivers/infiniband/hw/ipath/ipath_cq.c48
-rw-r--r--drivers/infiniband/hw/ipath/ipath_driver.c359
-rw-r--r--drivers/infiniband/hw/ipath/ipath_eeprom.c17
-rw-r--r--drivers/infiniband/hw/ipath/ipath_file_ops.c974
-rw-r--r--drivers/infiniband/hw/ipath/ipath_fs.c26
-rw-r--r--drivers/infiniband/hw/ipath/ipath_iba6110.c137
-rw-r--r--drivers/infiniband/hw/ipath/ipath_iba6120.c263
-rw-r--r--drivers/infiniband/hw/ipath/ipath_init_chip.c56
-rw-r--r--drivers/infiniband/hw/ipath/ipath_intr.c280
-rw-r--r--drivers/infiniband/hw/ipath/ipath_kernel.h116
-rw-r--r--drivers/infiniband/hw/ipath/ipath_keys.c12
-rw-r--r--drivers/infiniband/hw/ipath/ipath_mad.c16
-rw-r--r--drivers/infiniband/hw/ipath/ipath_mr.c3
-rw-r--r--drivers/infiniband/hw/ipath/ipath_qp.c16
-rw-r--r--drivers/infiniband/hw/ipath/ipath_rc.c136
-rw-r--r--drivers/infiniband/hw/ipath/ipath_registers.h40
-rw-r--r--drivers/infiniband/hw/ipath/ipath_ruc.c14
-rw-r--r--drivers/infiniband/hw/ipath/ipath_srq.c23
-rw-r--r--drivers/infiniband/hw/ipath/ipath_sysfs.c21
-rw-r--r--drivers/infiniband/hw/ipath/ipath_uc.c6
-rw-r--r--drivers/infiniband/hw/ipath/ipath_ud.c6
-rw-r--r--drivers/infiniband/hw/ipath/ipath_user_pages.c56
-rw-r--r--drivers/infiniband/hw/ipath/ipath_verbs.c45
-rw-r--r--drivers/infiniband/hw/ipath/ipath_verbs.h18
-rw-r--r--drivers/infiniband/hw/ipath/ipath_wc_ppc64.c20
-rw-r--r--drivers/infiniband/hw/ipath/ipath_wc_x86_64.c13
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_fs.c4
-rw-r--r--drivers/infiniband/ulp/iser/Kconfig13
-rw-r--r--drivers/infiniband/ulp/iser/iscsi_iser.c2
-rw-r--r--drivers/infiniband/ulp/iser/iscsi_iser.h9
-rw-r--r--drivers/infiniband/ulp/iser/iser_initiator.c60
-rw-r--r--drivers/infiniband/ulp/iser/iser_memory.c42
-rw-r--r--drivers/infiniband/ulp/iser/iser_verbs.c8
-rw-r--r--drivers/input/Kconfig14
-rw-r--r--drivers/input/Makefile6
-rw-r--r--drivers/input/evbug.c11
-rw-r--r--drivers/input/evdev.c42
-rw-r--r--drivers/input/ff-core.c367
-rw-r--r--drivers/input/ff-memless.c515
-rw-r--r--drivers/input/fixp-arith.h (renamed from drivers/usb/input/fixp-arith.h)0
-rw-r--r--drivers/input/input.c46
-rw-r--r--drivers/input/joydev.c12
-rw-r--r--drivers/input/joystick/iforce/iforce-ff.c118
-rw-r--r--drivers/input/joystick/iforce/iforce-main.c226
-rw-r--r--drivers/input/joystick/iforce/iforce-packets.c15
-rw-r--r--drivers/input/joystick/iforce/iforce.h26
-rw-r--r--drivers/input/keyboard/Kconfig20
-rw-r--r--drivers/input/keyboard/Makefile2
-rw-r--r--drivers/input/keyboard/atkbd.c4
-rw-r--r--drivers/input/keyboard/omap-keypad.c492
-rw-r--r--drivers/input/keyboard/stowaway.c187
-rw-r--r--drivers/input/misc/uinput.c67
-rw-r--r--drivers/input/misc/wistron_btns.c18
-rw-r--r--drivers/input/mouse/alps.c8
-rw-r--r--drivers/input/mouse/alps.h2
-rw-r--r--drivers/input/mouse/lifebook.c8
-rw-r--r--drivers/input/mouse/logips2pp.c23
-rw-r--r--drivers/input/mouse/psmouse-base.c42
-rw-r--r--drivers/input/mouse/sermouse.c2
-rw-r--r--drivers/input/mouse/synaptics.c10
-rw-r--r--drivers/input/mousedev.c28
-rw-r--r--drivers/input/power.c7
-rw-r--r--drivers/input/serio/i8042-io.h15
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h14
-rw-r--r--drivers/input/serio/i8042.c741
-rw-r--r--drivers/input/serio/i8042.h9
-rw-r--r--drivers/input/serio/libps2.c36
-rw-r--r--drivers/input/touchscreen/Kconfig36
-rw-r--r--drivers/input/touchscreen/Makefile3
-rw-r--r--drivers/input/touchscreen/elo.c167
-rw-r--r--drivers/input/touchscreen/hp680_ts_input.c14
-rw-r--r--drivers/input/touchscreen/penmount.c185
-rw-r--r--drivers/input/touchscreen/touchright.c196
-rw-r--r--drivers/input/touchscreen/touchwin.c203
-rw-r--r--drivers/input/tsdev.c12
-rw-r--r--drivers/isdn/capi/capi.c2
-rw-r--r--drivers/isdn/capi/capifs.c2
-rw-r--r--drivers/isdn/gigaset/bas-gigaset.c2
-rw-r--r--drivers/isdn/gigaset/interface.c2
-rw-r--r--drivers/isdn/gigaset/proc.c3
-rw-r--r--drivers/isdn/hardware/eicon/dsp_defs.h3
-rw-r--r--drivers/isdn/hisax/config.c6
-rw-r--r--drivers/isdn/hisax/hfc4s8s_l1.c7
-rw-r--r--drivers/isdn/hisax/hfc_sx.c4
-rw-r--r--drivers/isdn/hisax/hfc_usb.c4
-rw-r--r--drivers/isdn/hisax/hfc_usb.h6
-rw-r--r--drivers/isdn/hisax/hisax.h13
-rw-r--r--drivers/isdn/hisax/hisax_fcpcipnp.c17
-rw-r--r--drivers/isdn/hisax/st5481_b.c8
-rw-r--r--drivers/isdn/hisax/st5481_d.c4
-rw-r--r--drivers/isdn/i4l/isdn_net.c4
-rw-r--r--drivers/isdn/i4l/isdn_tty.c2
-rw-r--r--drivers/isdn/sc/command.c22
-rw-r--r--drivers/isdn/sc/event.c2
-rw-r--r--drivers/isdn/sc/interrupt.c2
-rw-r--r--drivers/isdn/sc/timer.c2
-rw-r--r--drivers/leds/led-triggers.c1
-rw-r--r--drivers/leds/leds-net48xx.c9
-rw-r--r--drivers/macintosh/smu.c4
-rw-r--r--drivers/macintosh/via-pmu-backlight.c2
-rw-r--r--drivers/macintosh/via-pmu.c14
-rw-r--r--drivers/macintosh/via-pmu68k.c6
-rw-r--r--drivers/macintosh/windfarm_smu_controls.c2
-rw-r--r--drivers/macintosh/windfarm_smu_sat.c7
-rw-r--r--drivers/macintosh/windfarm_smu_sensors.c2
-rw-r--r--drivers/md/Kconfig21
-rw-r--r--drivers/md/bitmap.c17
-rw-r--r--drivers/md/dm-crypt.c506
-rw-r--r--drivers/md/dm-emc.c3
-rw-r--r--drivers/md/dm-exception-store.c176
-rw-r--r--drivers/md/dm-linear.c19
-rw-r--r--drivers/md/dm-mpath.c83
-rw-r--r--drivers/md/dm-raid1.c4
-rw-r--r--drivers/md/dm-snap.c351
-rw-r--r--drivers/md/dm-snap.h17
-rw-r--r--drivers/md/dm-table.c109
-rw-r--r--drivers/md/dm.c113
-rw-r--r--drivers/md/dm.h7
-rw-r--r--drivers/md/linear.c15
-rw-r--r--drivers/md/md.c275
-rw-r--r--drivers/md/multipath.c27
-rw-r--r--drivers/md/raid0.c17
-rw-r--r--drivers/md/raid1.c247
-rw-r--r--drivers/md/raid10.c261
-rw-r--r--drivers/md/raid5.c74
-rw-r--r--drivers/media/common/Kconfig1
-rw-r--r--drivers/media/common/ir-keymaps.c79
-rw-r--r--drivers/media/common/saa7146_fops.c1
-rw-r--r--drivers/media/dvb/b2c2/Kconfig14
-rw-r--r--drivers/media/dvb/b2c2/flexcop-fe-tuner.c24
-rw-r--r--drivers/media/dvb/bt8xx/Kconfig14
-rw-r--r--drivers/media/dvb/bt8xx/dst.c9
-rw-r--r--drivers/media/dvb/bt8xx/dst_ca.c11
-rw-r--r--drivers/media/dvb/bt8xx/dst_common.h3
-rw-r--r--drivers/media/dvb/bt8xx/dvb-bt8xx.c37
-rw-r--r--drivers/media/dvb/cinergyT2/cinergyT2.c2
-rw-r--r--drivers/media/dvb/dvb-core/Kconfig13
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c42
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.h7
-rw-r--r--drivers/media/dvb/dvb-core/dvb_ringbuffer.c1
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.h22
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig17
-rw-r--r--drivers/media/dvb/dvb-usb/a800.c8
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.c11
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-common.c200
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mb.c18
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mc.c41
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb.h3
-rw-r--r--drivers/media/dvb/dvb-usb/digitv.c86
-rw-r--r--drivers/media/dvb/dvb-usb/dtt200u.c50
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-dvb.c20
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h124
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-remote.c5
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-urb.c1
-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/frontends/Kconfig71
-rw-r--r--drivers/media/dvb/frontends/Makefile8
-rw-r--r--drivers/media/dvb/frontends/bcm3510.h9
-rw-r--r--drivers/media/dvb/frontends/cx22700.h9
-rw-r--r--drivers/media/dvb/frontends/cx22702.c4
-rw-r--r--drivers/media/dvb/frontends/cx22702.h9
-rw-r--r--drivers/media/dvb/frontends/cx24110.c17
-rw-r--r--drivers/media/dvb/frontends/cx24110.h19
-rw-r--r--drivers/media/dvb/frontends/cx24123.c98
-rw-r--r--drivers/media/dvb/frontends/cx24123.h12
-rw-r--r--drivers/media/dvb/frontends/dib3000-common.c83
-rw-r--r--drivers/media/dvb/frontends/dib3000-common.h135
-rw-r--r--drivers/media/dvb/frontends/dib3000.h11
-rw-r--r--drivers/media/dvb/frontends/dib3000mb.c76
-rw-r--r--drivers/media/dvb/frontends/dib3000mb_priv.h93
-rw-r--r--drivers/media/dvb/frontends/dib3000mc.c1432
-rw-r--r--drivers/media/dvb/frontends/dib3000mc.h58
-rw-r--r--drivers/media/dvb/frontends/dib3000mc_priv.h428
-rw-r--r--drivers/media/dvb/frontends/dibx000_common.c152
-rw-r--r--drivers/media/dvb/frontends/dibx000_common.h166
-rw-r--r--drivers/media/dvb/frontends/dvb-pll.c11
-rw-r--r--drivers/media/dvb/frontends/dvb-pll.h4
-rw-r--r--drivers/media/dvb/frontends/isl6421.c30
-rw-r--r--drivers/media/dvb/frontends/isl6421.h11
-rw-r--r--drivers/media/dvb/frontends/l64781.h10
-rw-r--r--drivers/media/dvb/frontends/lgdt330x.h9
-rw-r--r--drivers/media/dvb/frontends/lnbp21.c30
-rw-r--r--drivers/media/dvb/frontends/lnbp21.h12
-rw-r--r--drivers/media/dvb/frontends/mt2060.c367
-rw-r--r--drivers/media/dvb/frontends/mt2060.h35
-rw-r--r--drivers/media/dvb/frontends/mt2060_priv.h105
-rw-r--r--drivers/media/dvb/frontends/mt312.h10
-rw-r--r--drivers/media/dvb/frontends/mt352.c16
-rw-r--r--drivers/media/dvb/frontends/mt352.h16
-rw-r--r--drivers/media/dvb/frontends/nxt200x.h9
-rw-r--r--drivers/media/dvb/frontends/nxt6000.h9
-rw-r--r--drivers/media/dvb/frontends/or51132.h9
-rw-r--r--drivers/media/dvb/frontends/or51211.h9
-rw-r--r--drivers/media/dvb/frontends/s5h1420.h9
-rw-r--r--drivers/media/dvb/frontends/sp8870.h9
-rw-r--r--drivers/media/dvb/frontends/sp887x.h9
-rw-r--r--drivers/media/dvb/frontends/stv0297.h9
-rw-r--r--drivers/media/dvb/frontends/stv0299.c9
-rw-r--r--drivers/media/dvb/frontends/stv0299.h19
-rw-r--r--drivers/media/dvb/frontends/tda10021.c63
-rw-r--r--drivers/media/dvb/frontends/tda10021.h19
-rw-r--r--drivers/media/dvb/frontends/tda1004x.c10
-rw-r--r--drivers/media/dvb/frontends/tda1004x.h25
-rw-r--r--drivers/media/dvb/frontends/tda10086.c740
-rw-r--r--drivers/media/dvb/frontends/tda10086.h41
-rw-r--r--drivers/media/dvb/frontends/tda8083.h9
-rw-r--r--drivers/media/dvb/frontends/tda826x.c173
-rw-r--r--drivers/media/dvb/frontends/tda826x.h40
-rw-r--r--drivers/media/dvb/frontends/tua6100.c205
-rw-r--r--drivers/media/dvb/frontends/tua6100.h47
-rw-r--r--drivers/media/dvb/frontends/ves1820.h9
-rw-r--r--drivers/media/dvb/frontends/ves1x93.h9
-rw-r--r--drivers/media/dvb/frontends/zl10353.c11
-rw-r--r--drivers/media/dvb/frontends/zl10353.h14
-rw-r--r--drivers/media/dvb/ttpci/Kconfig57
-rw-r--r--drivers/media/dvb/ttpci/av7110.c58
-rw-r--r--drivers/media/dvb/ttpci/av7110_av.c1
-rw-r--r--drivers/media/dvb/ttpci/av7110_ca.c1
-rw-r--r--drivers/media/dvb/ttpci/av7110_hw.c1
-rw-r--r--drivers/media/dvb/ttpci/av7110_v4l.c3
-rw-r--r--drivers/media/dvb/ttpci/budget-av.c184
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c32
-rw-r--r--drivers/media/dvb/ttpci/budget-patch.c17
-rw-r--r--drivers/media/dvb/ttpci/budget.c53
-rw-r--r--drivers/media/dvb/ttusb-budget/Kconfig14
-rw-r--r--drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c28
-rw-r--r--drivers/media/dvb/ttusb-dec/ttusb_dec.c8
-rw-r--r--drivers/media/radio/Kconfig30
-rw-r--r--drivers/media/radio/dsbr100.c198
-rw-r--r--drivers/media/radio/radio-aimslab.c151
-rw-r--r--drivers/media/radio/radio-aztech.c166
-rw-r--r--drivers/media/radio/radio-cadet.c250
-rw-r--r--drivers/media/radio/radio-gemtek-pci.c170
-rw-r--r--drivers/media/radio/radio-gemtek.c165
-rw-r--r--drivers/media/radio/radio-maestro.c197
-rw-r--r--drivers/media/radio/radio-maxiradio.c166
-rw-r--r--drivers/media/radio/radio-rtrack2.c163
-rw-r--r--drivers/media/radio/radio-sf16fmi.c158
-rw-r--r--drivers/media/radio/radio-sf16fmr2.c223
-rw-r--r--drivers/media/radio/radio-terratec.c154
-rw-r--r--drivers/media/radio/radio-trust.c188
-rw-r--r--drivers/media/radio/radio-typhoon.c171
-rw-r--r--drivers/media/radio/radio-zoltrix.c183
-rw-r--r--drivers/media/video/Kconfig476
-rw-r--r--drivers/media/video/Makefile45
-rw-r--r--drivers/media/video/bt866.c2
-rw-r--r--drivers/media/video/bt8xx/Kconfig5
-rw-r--r--drivers/media/video/bt8xx/bttv-cards.c2
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c12
-rw-r--r--drivers/media/video/bt8xx/bttv-i2c.c17
-rw-r--r--drivers/media/video/compat_ioctl32.c59
-rw-r--r--drivers/media/video/cpia2/cpia2.h4
-rw-r--r--drivers/media/video/cx2341x.c25
-rw-r--r--drivers/media/video/cx25840/Kconfig2
-rw-r--r--drivers/media/video/cx25840/cx25840-vbi.c4
-rw-r--r--drivers/media/video/cx88/Kconfig109
-rw-r--r--drivers/media/video/cx88/Makefile7
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c2
-rw-r--r--drivers/media/video/cx88/cx88-cards.c161
-rw-r--r--drivers/media/video/cx88/cx88-core.c13
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c330
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c14
-rw-r--r--drivers/media/video/cx88/cx88-input.c19
-rw-r--r--drivers/media/video/cx88/cx88-tvaudio.c5
-rw-r--r--drivers/media/video/cx88/cx88-video.c7
-rw-r--r--drivers/media/video/cx88/cx88-vp3054-i2c.c1
-rw-r--r--drivers/media/video/cx88/cx88.h5
-rw-r--r--drivers/media/video/em28xx/Kconfig3
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c2
-rw-r--r--drivers/media/video/ks0127.c3
-rw-r--r--drivers/media/video/ov511.c7
-rw-r--r--drivers/media/video/pvrusb2/Kconfig18
-rw-r--r--drivers/media/video/pvrusb2/Makefile6
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-ctrl.c21
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-encoder.c4
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h31
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.c84
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c4
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-core.c6
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-main.c1
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-sysfs.c3
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-v4l2.c36
-rw-r--r--drivers/media/video/pwc/pwc-if.c2
-rw-r--r--drivers/media/video/saa5246a.c1
-rw-r--r--drivers/media/video/saa5249.c1
-rw-r--r--drivers/media/video/saa7115.c1250
-rw-r--r--drivers/media/video/saa711x_regs.h549
-rw-r--r--drivers/media/video/saa7134/Kconfig50
-rw-r--r--drivers/media/video/saa7134/Makefile3
-rw-r--r--drivers/media/video/saa7134/saa7134-alsa.c8
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c127
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c2
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c197
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c6
-rw-r--r--drivers/media/video/saa7134/saa7134-tvaudio.c1
-rw-r--r--drivers/media/video/saa7134/saa7134.h3
-rw-r--r--drivers/media/video/tda9887.c2
-rw-r--r--drivers/media/video/tuner-simple.c6
-rw-r--r--drivers/media/video/tuner-types.c1
-rw-r--r--drivers/media/video/tvaudio.c42
-rw-r--r--drivers/media/video/tveeprom.c2
-rw-r--r--drivers/media/video/tvp5150.c7
-rw-r--r--drivers/media/video/usbvideo/konicawc.c9
-rw-r--r--drivers/media/video/usbvideo/vicam.c4
-rw-r--r--drivers/media/video/v4l1-compat.c12
-rw-r--r--drivers/media/video/v4l2-common.c1
-rw-r--r--drivers/media/video/video-buf-dvb.c2
-rw-r--r--drivers/media/video/videodev.c32
-rw-r--r--drivers/media/video/vino.c1
-rw-r--r--drivers/media/video/vivi.c5
-rw-r--r--drivers/media/video/vpx3220.c2
-rw-r--r--drivers/media/video/w9968cf.c7
-rw-r--r--drivers/media/video/zoran_card.c7
-rw-r--r--drivers/media/video/zoran_driver.c7
-rw-r--r--drivers/media/video/zr36120.c6
-rw-r--r--drivers/message/i2o/Kconfig2
-rw-r--r--drivers/message/i2o/i2o_block.c7
-rw-r--r--drivers/message/i2o/pci.c7
-rw-r--r--drivers/mfd/ucb1x00-ts.c45
-rw-r--r--drivers/misc/Makefile3
-rw-r--r--drivers/misc/ibmasm/ibmasmfs.c17
-rw-r--r--drivers/misc/lkdtm.c342
-rw-r--r--drivers/mmc/Kconfig2
-rw-r--r--drivers/mmc/Makefile3
-rw-r--r--drivers/mmc/at91_mci.c5
-rw-r--r--drivers/mmc/au1xmmc.c2
-rw-r--r--drivers/mmc/imxmmc.c2
-rw-r--r--drivers/mmc/mmc.c1
-rw-r--r--drivers/mmc/mmc_block.c66
-rw-r--r--drivers/mmc/mmc_queue.c6
-rw-r--r--drivers/mmc/mmci.c13
-rw-r--r--drivers/mmc/omap.c7
-rw-r--r--drivers/mmc/sdhci.c7
-rw-r--r--drivers/mmc/sdhci.h5
-rw-r--r--drivers/mmc/wbsd.c7
-rw-r--r--drivers/mmc/wbsd.h5
-rw-r--r--drivers/mtd/Kconfig12
-rw-r--r--drivers/mtd/devices/Kconfig2
-rw-r--r--drivers/mtd/maps/arctic-mtd.c6
-rw-r--r--drivers/mtd/maps/beech-mtd.c6
-rw-r--r--drivers/mtd/maps/cstm_mips_ixx.c8
-rw-r--r--drivers/mtd/maps/nettel.c2
-rw-r--r--drivers/mtd/maps/redwood.c2
-rw-r--r--drivers/mtd/mtd_blkdevs.c4
-rw-r--r--drivers/mtd/nand/edb7312.c2
-rw-r--r--drivers/mtd/nand/nand_base.c172
-rw-r--r--drivers/mtd/nand/nand_bbt.c2
-rw-r--r--drivers/mtd/nftlcore.c4
-rw-r--r--drivers/mtd/onenand/Kconfig6
-rw-r--r--drivers/mtd/onenand/onenand_base.c154
-rw-r--r--drivers/net/3c509.c1
-rw-r--r--drivers/net/3c59x.c1
-rw-r--r--drivers/net/8390.c6
-rw-r--r--drivers/net/Kconfig5
-rw-r--r--drivers/net/Space.c2
-rw-r--r--drivers/net/acenic.c4
-rw-r--r--drivers/net/appletalk/ipddp.c5
-rw-r--r--drivers/net/arm/at91_ether.c2
-rw-r--r--drivers/net/bnx2.c32
-rw-r--r--drivers/net/bonding/bond_3ad.c70
-rw-r--r--drivers/net/bonding/bond_main.c230
-rw-r--r--drivers/net/bonding/bond_sysfs.c56
-rw-r--r--drivers/net/bonding/bonding.h34
-rw-r--r--drivers/net/dgrs.c1
-rw-r--r--drivers/net/e100.c82
-rw-r--r--drivers/net/e1000/LICENSE339
-rw-r--r--drivers/net/e1000/Makefile35
-rw-r--r--drivers/net/e1000/e1000.h59
-rw-r--r--drivers/net/e1000/e1000_ethtool.c150
-rw-r--r--drivers/net/e1000/e1000_hw.c1074
-rw-r--r--drivers/net/e1000/e1000_hw.h90
-rw-r--r--drivers/net/e1000/e1000_main.c271
-rw-r--r--drivers/net/e1000/e1000_osdep.h35
-rw-r--r--drivers/net/e1000/e1000_param.c47
-rw-r--r--drivers/net/fec_8xx/fec_main.c2
-rw-r--r--drivers/net/forcedeth.c8
-rw-r--r--drivers/net/fs_enet/fs_enet.h3
-rw-r--r--drivers/net/gt64240eth.h402
-rw-r--r--drivers/net/hp100.c9
-rw-r--r--drivers/net/ifb.c4
-rw-r--r--drivers/net/irda/Kconfig1
-rw-r--r--drivers/net/irda/irda-usb.c18
-rw-r--r--drivers/net/irda/nsc-ircc.c2
-rw-r--r--drivers/net/irda/smsc-ircc2.c38
-rw-r--r--drivers/net/irda/stir4200.c15
-rw-r--r--drivers/net/irda/via-ircc.c7
-rw-r--r--drivers/net/irda/vlsi_ir.h2
-rw-r--r--drivers/net/ixgb/Makefile38
-rw-r--r--drivers/net/ixgb/ixgb.h38
-rw-r--r--drivers/net/ixgb/ixgb_ee.c36
-rw-r--r--drivers/net/ixgb/ixgb_ee.h36
-rw-r--r--drivers/net/ixgb/ixgb_ethtool.c36
-rw-r--r--drivers/net/ixgb/ixgb_hw.c36
-rw-r--r--drivers/net/ixgb/ixgb_hw.h36
-rw-r--r--drivers/net/ixgb/ixgb_ids.h36
-rw-r--r--drivers/net/ixgb/ixgb_main.c46
-rw-r--r--drivers/net/ixgb/ixgb_osdep.h36
-rw-r--r--drivers/net/ixgb/ixgb_param.c36
-rw-r--r--drivers/net/loopback.c31
-rw-r--r--drivers/net/ne3210.c1
-rw-r--r--drivers/net/phy/fixed.c6
-rw-r--r--drivers/net/phy/phy_device.c10
-rw-r--r--drivers/net/pppoe.c1
-rw-r--r--drivers/net/s2io.c10
-rw-r--r--drivers/net/skge.c357
-rw-r--r--drivers/net/skge.h37
-rw-r--r--drivers/net/sky2.c548
-rw-r--r--drivers/net/sky2.h62
-rw-r--r--drivers/net/smc91x.h19
-rw-r--r--drivers/net/spider_net.c6
-rw-r--r--drivers/net/stnic.c2
-rw-r--r--drivers/net/tg3.c480
-rw-r--r--drivers/net/tg3.h48
-rw-r--r--drivers/net/tokenring/lanstreamer.c59
-rw-r--r--drivers/net/tokenring/lanstreamer.h12
-rw-r--r--drivers/net/tulip/de4x5.c1
-rw-r--r--drivers/net/tun.c39
-rw-r--r--drivers/net/typhoon.c4
-rw-r--r--drivers/net/wan/Kconfig12
-rw-r--r--drivers/net/wan/Makefile19
-rw-r--r--drivers/net/wan/hdlc.c (renamed from drivers/net/wan/hdlc_generic.c)169
-rw-r--r--drivers/net/wan/hdlc_cisco.c200
-rw-r--r--drivers/net/wan/hdlc_fr.c389
-rw-r--r--drivers/net/wan/hdlc_ppp.c77
-rw-r--r--drivers/net/wan/hdlc_raw.c50
-rw-r--r--drivers/net/wan/hdlc_raw_eth.c49
-rw-r--r--drivers/net/wan/hdlc_x25.c54
-rw-r--r--drivers/net/wan/pc300.h1
-rw-r--r--drivers/net/wan/pc300_drv.c30
-rw-r--r--drivers/net/wan/syncppp.c4
-rw-r--r--drivers/net/wireless/airo.c42
-rw-r--r--drivers/net/wireless/atmel.c18
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx.h1
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c2
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_main.c10
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_phy.c15
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_wx.c2
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_xmit.c5
-rw-r--r--drivers/net/wireless/hostap/hostap_ioctl.c10
-rw-r--r--drivers/net/wireless/ipw2100.c36
-rw-r--r--drivers/net/wireless/ipw2200.c16
-rw-r--r--drivers/net/wireless/orinoco.c10
-rw-r--r--drivers/net/wireless/prism54/isl_ioctl.c16
-rw-r--r--drivers/net/wireless/ray_cs.c2
-rw-r--r--drivers/net/wireless/strip.c4
-rw-r--r--drivers/net/wireless/wl3501_cs.c6
-rw-r--r--drivers/net/wireless/zd1201.c6
-rw-r--r--drivers/net/wireless/zd1211rw/zd_chip.c137
-rw-r--r--drivers/net/wireless/zd1211rw/zd_chip.h23
-rw-r--r--drivers/net/wireless/zd1211rw/zd_mac.c50
-rw-r--r--drivers/net/wireless/zd1211rw/zd_mac.h5
-rw-r--r--drivers/net/wireless/zd1211rw/zd_netdev.c2
-rw-r--r--drivers/net/wireless/zd1211rw/zd_usb.c10
-rw-r--r--drivers/net/wireless/zd1211rw/zd_usb.h2
-rw-r--r--drivers/oprofile/oprofilefs.c11
-rw-r--r--drivers/parisc/led.c2
-rw-r--r--drivers/parisc/power.c3
-rw-r--r--drivers/parport/parport_serial.c4
-rw-r--r--drivers/pci/Kconfig25
-rw-r--r--drivers/pci/bus.c22
-rw-r--r--drivers/pci/hotplug/acpiphp.h5
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c127
-rw-r--r--drivers/pci/hotplug/acpiphp_ibm.c4
-rw-r--r--drivers/pci/hotplug/cpqphp_sysfs.c2
-rw-r--r--drivers/pci/hotplug/fakephp.c18
-rw-r--r--drivers/pci/hotplug/pci_hotplug.h4
-rw-r--r--drivers/pci/hotplug/pci_hotplug_core.c157
-rw-r--r--drivers/pci/hotplug/pciehp_ctrl.c12
-rw-r--r--drivers/pci/hotplug/pcihp_skeleton.c9
-rw-r--r--drivers/pci/hotplug/shpchp.h2
-rw-r--r--drivers/pci/hotplug/shpchp_core.c6
-rw-r--r--drivers/pci/hotplug/shpchp_sysfs.c4
-rw-r--r--drivers/pci/msi.c64
-rw-r--r--drivers/pci/pci-driver.c47
-rw-r--r--drivers/pci/pci-sysfs.c153
-rw-r--r--drivers/pci/pci.c59
-rw-r--r--drivers/pci/pci.h2
-rw-r--r--drivers/pci/pcie/Kconfig1
-rw-r--r--drivers/pci/pcie/Makefile3
-rw-r--r--drivers/pci/pcie/aer/Kconfig12
-rw-r--r--drivers/pci/pcie/aer/Makefile8
-rw-r--r--drivers/pci/pcie/aer/aerdrv.c346
-rw-r--r--drivers/pci/pcie/aer/aerdrv.h125
-rw-r--r--drivers/pci/pcie/aer/aerdrv_acpi.c68
-rw-r--r--drivers/pci/pcie/aer/aerdrv_core.c758
-rw-r--r--drivers/pci/pcie/aer/aerdrv_errprint.c248
-rw-r--r--drivers/pci/pcie/portdrv.h2
-rw-r--r--drivers/pci/pcie/portdrv_bus.c1
-rw-r--r--drivers/pci/pcie/portdrv_core.c11
-rw-r--r--drivers/pci/pcie/portdrv_pci.c211
-rw-r--r--drivers/pci/probe.c16
-rw-r--r--drivers/pci/quirks.c121
-rw-r--r--drivers/pci/remove.c37
-rw-r--r--drivers/pci/setup-bus.c13
-rw-r--r--drivers/pcmcia/cardbus.c5
-rw-r--r--drivers/pcmcia/omap_cf.c25
-rw-r--r--drivers/pcmcia/socket_sysfs.c27
-rw-r--r--drivers/pnp/pnpbios/core.c8
-rw-r--r--drivers/rtc/Kconfig38
-rw-r--r--drivers/rtc/Makefile5
-rw-r--r--drivers/rtc/class.c6
-rw-r--r--drivers/rtc/rtc-at91.c24
-rw-r--r--drivers/rtc/rtc-dev.c7
-rw-r--r--drivers/rtc/rtc-ds1307.c2
-rw-r--r--drivers/rtc/rtc-ds1553.c10
-rw-r--r--drivers/rtc/rtc-ds1672.c2
-rw-r--r--drivers/rtc/rtc-ds1742.c12
-rw-r--r--drivers/rtc/rtc-ep93xx.c2
-rw-r--r--drivers/rtc/rtc-isl1208.c2
-rw-r--r--drivers/rtc/rtc-lib.c8
-rw-r--r--drivers/rtc/rtc-m48t86.c2
-rw-r--r--drivers/rtc/rtc-max6902.c2
-rw-r--r--drivers/rtc/rtc-pcf8563.c6
-rw-r--r--drivers/rtc/rtc-pcf8583.c2
-rw-r--r--drivers/rtc/rtc-pl031.c2
-rw-r--r--drivers/rtc/rtc-proc.c6
-rw-r--r--drivers/rtc/rtc-rs5c348.c11
-rw-r--r--drivers/rtc/rtc-rs5c372.c2
-rw-r--r--drivers/rtc/rtc-s3c.c2
-rw-r--r--drivers/rtc/rtc-sa1100.c2
-rw-r--r--drivers/rtc/rtc-sh.c467
-rw-r--r--drivers/rtc/rtc-sysfs.c2
-rw-r--r--drivers/rtc/rtc-test.c2
-rw-r--r--drivers/rtc/rtc-v3020.c5
-rw-r--r--drivers/rtc/rtc-vr41xx.c2
-rw-r--r--drivers/rtc/rtc-x1205.c2
-rw-r--r--drivers/s390/block/Kconfig2
-rw-r--r--drivers/s390/block/dasd_diag.c36
-rw-r--r--drivers/s390/block/dasd_eckd.c2
-rw-r--r--drivers/s390/block/dasd_fba.c2
-rw-r--r--drivers/s390/block/xpram.c54
-rw-r--r--drivers/s390/char/con3215.c2
-rw-r--r--drivers/s390/char/fs3270.c12
-rw-r--r--drivers/s390/char/sclp.c31
-rw-r--r--drivers/s390/char/sclp_tty.c2
-rw-r--r--drivers/s390/char/sclp_vt220.c2
-rw-r--r--drivers/s390/char/tty3270.c3
-rw-r--r--drivers/s390/char/vmwatchdog.c52
-rw-r--r--drivers/s390/cio/device_id.c38
-rw-r--r--drivers/s390/cio/ioasm.h220
-rw-r--r--drivers/s390/cio/qdio.h192
-rw-r--r--drivers/s390/net/iucv.c39
-rw-r--r--drivers/s390/net/qeth_main.c2
-rw-r--r--drivers/s390/s390mach.c95
-rw-r--r--drivers/s390/scsi/zfcp_scsi.c2
-rw-r--r--drivers/sbus/char/aurora.c2
-rw-r--r--drivers/sbus/char/bbc_envctrl.c5
-rw-r--r--drivers/sbus/char/envctrl.c7
-rw-r--r--drivers/scsi/53c700.c2
-rw-r--r--drivers/scsi/BusLogic.h5
-rw-r--r--drivers/scsi/Kconfig2
-rw-r--r--drivers/scsi/aha1740.c1
-rw-r--r--drivers/scsi/aic7xxx/aic7770_osm.c3
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.c4
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm.c2
-rw-r--r--drivers/scsi/aic7xxx_old.c4
-rw-r--r--drivers/scsi/gdth.c4
-rw-r--r--drivers/scsi/ide-scsi.c16
-rw-r--r--drivers/scsi/libsas/sas_scsi_host.c2
-rw-r--r--drivers/scsi/lpfc/lpfc_ct.c8
-rw-r--r--drivers/scsi/mesh.c15
-rw-r--r--drivers/scsi/pluto.c6
-rw-r--r--drivers/scsi/qla1280.c4
-rw-r--r--drivers/scsi/scsi.c13
-rw-r--r--drivers/scsi/scsi_lib.c37
-rw-r--r--drivers/scsi/sd.c5
-rw-r--r--drivers/scsi/sim710.c1
-rw-r--r--drivers/scsi/sun3_NCR5380.c2
-rw-r--r--drivers/scsi/sun3_scsi.c2
-rw-r--r--drivers/scsi/sun3_scsi_vme.c2
-rw-r--r--drivers/serial/68328serial.c2
-rw-r--r--drivers/serial/68360serial.c2
-rw-r--r--drivers/serial/8250_acorn.c9
-rw-r--r--drivers/serial/8250_gsc.c1
-rw-r--r--drivers/serial/Kconfig11
-rw-r--r--drivers/serial/at91_serial.c2
-rw-r--r--drivers/serial/crisv10.c2
-rw-r--r--drivers/serial/ioc4_serial.c3
-rw-r--r--drivers/serial/ip22zilog.c16
-rw-r--r--drivers/serial/mcfserial.c2
-rw-r--r--drivers/serial/mpc52xx_uart.c11
-rw-r--r--drivers/serial/mpsc.c12
-rw-r--r--drivers/serial/mux.c2
-rw-r--r--drivers/serial/serial_core.c16
-rw-r--r--drivers/serial/sh-sci.c1146
-rw-r--r--drivers/serial/sh-sci.h90
-rw-r--r--drivers/serial/sunsu.c3
-rw-r--r--drivers/serial/sunzilog.c2
-rw-r--r--drivers/tc/zs.c2
-rw-r--r--drivers/usb/Kconfig1
-rw-r--r--drivers/usb/Makefile12
-rw-r--r--drivers/usb/atm/ueagle-atm.c74
-rw-r--r--drivers/usb/class/cdc-acm.c2
-rw-r--r--drivers/usb/class/usblp.c15
-rw-r--r--drivers/usb/core/Makefile2
-rw-r--r--drivers/usb/core/buffer.c4
-rw-r--r--drivers/usb/core/config.c4
-rw-r--r--drivers/usb/core/devices.c6
-rw-r--r--drivers/usb/core/devio.c78
-rw-r--r--drivers/usb/core/driver.c1012
-rw-r--r--drivers/usb/core/endpoint.c30
-rw-r--r--drivers/usb/core/file.c2
-rw-r--r--drivers/usb/core/generic.c208
-rw-r--r--drivers/usb/core/hcd-pci.c18
-rw-r--r--drivers/usb/core/hcd.c254
-rw-r--r--drivers/usb/core/hcd.h60
-rw-r--r--drivers/usb/core/hub.c555
-rw-r--r--drivers/usb/core/hub.h3
-rw-r--r--drivers/usb/core/inode.c26
-rw-r--r--drivers/usb/core/message.c148
-rw-r--r--drivers/usb/core/notify.c3
-rw-r--r--drivers/usb/core/sysfs.c60
-rw-r--r--drivers/usb/core/urb.c15
-rw-r--r--drivers/usb/core/usb.c569
-rw-r--r--drivers/usb/core/usb.h95
-rw-r--r--drivers/usb/gadget/Kconfig16
-rw-r--r--drivers/usb/gadget/Makefile2
-rw-r--r--drivers/usb/gadget/at91_udc.c8
-rw-r--r--drivers/usb/gadget/dummy_hcd.c41
-rw-r--r--drivers/usb/gadget/ether.c11
-rw-r--r--drivers/usb/gadget/file_storage.c37
-rw-r--r--drivers/usb/gadget/gmidi.c1337
-rw-r--r--drivers/usb/gadget/inode.c149
-rw-r--r--drivers/usb/gadget/net2280.c156
-rw-r--r--drivers/usb/gadget/omap_udc.c6
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.c70
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.h24
-rw-r--r--drivers/usb/gadget/serial.c7
-rw-r--r--drivers/usb/gadget/zero.c2
-rw-r--r--drivers/usb/host/Kconfig29
-rw-r--r--drivers/usb/host/Makefile1
-rw-r--r--drivers/usb/host/ehci-au1xxx.c2
-rw-r--r--drivers/usb/host/ehci-dbg.c31
-rw-r--r--drivers/usb/host/ehci-fsl.c2
-rw-r--r--drivers/usb/host/ehci-hcd.c95
-rw-r--r--drivers/usb/host/ehci-hub.c14
-rw-r--r--drivers/usb/host/ehci-mem.c14
-rw-r--r--drivers/usb/host/ehci-pci.c10
-rw-r--r--drivers/usb/host/ehci-q.c26
-rw-r--r--drivers/usb/host/ehci-sched.c26
-rw-r--r--drivers/usb/host/ehci.h59
-rw-r--r--drivers/usb/host/isp116x-hcd.c4
-rw-r--r--drivers/usb/host/isp116x.h2
-rw-r--r--drivers/usb/host/ohci-at91.c7
-rw-r--r--drivers/usb/host/ohci-au1xxx.c7
-rw-r--r--drivers/usb/host/ohci-dbg.c18
-rw-r--r--drivers/usb/host/ohci-ep93xx.c3
-rw-r--r--drivers/usb/host/ohci-hcd.c64
-rw-r--r--drivers/usb/host/ohci-hub.c273
-rw-r--r--drivers/usb/host/ohci-lh7a404.c7
-rw-r--r--drivers/usb/host/ohci-mem.c1
-rw-r--r--drivers/usb/host/ohci-omap.c120
-rw-r--r--drivers/usb/host/ohci-pci.c16
-rw-r--r--drivers/usb/host/ohci-pnx4008.c476
-rw-r--r--drivers/usb/host/ohci-ppc-soc.c3
-rw-r--r--drivers/usb/host/ohci-pxa27x.c3
-rw-r--r--drivers/usb/host/ohci-s3c2410.c5
-rw-r--r--drivers/usb/host/ohci-sa1111.c5
-rw-r--r--drivers/usb/host/ohci.h5
-rw-r--r--drivers/usb/host/sl811-hcd.c13
-rw-r--r--drivers/usb/host/u132-hcd.c3295
-rw-r--r--drivers/usb/host/uhci-debug.c6
-rw-r--r--drivers/usb/host/uhci-hcd.c12
-rw-r--r--drivers/usb/host/uhci-hub.c12
-rw-r--r--drivers/usb/image/mdc800.c4
-rw-r--r--drivers/usb/image/microtek.c18
-rw-r--r--drivers/usb/image/microtek.h4
-rw-r--r--drivers/usb/input/Kconfig48
-rw-r--r--drivers/usb/input/Makefile7
-rw-r--r--drivers/usb/input/acecad.c5
-rw-r--r--drivers/usb/input/appletouch.c5
-rw-r--r--drivers/usb/input/ati_remote.c8
-rw-r--r--drivers/usb/input/hid-core.c33
-rw-r--r--drivers/usb/input/hid-ff.c49
-rw-r--r--drivers/usb/input/hid-input.c23
-rw-r--r--drivers/usb/input/hid-lgff.c523
-rw-r--r--drivers/usb/input/hid-pidff.c1330
-rw-r--r--drivers/usb/input/hid-tmff.c399
-rw-r--r--drivers/usb/input/hid-zpff.c110
-rw-r--r--drivers/usb/input/hid.h32
-rw-r--r--drivers/usb/input/hiddev.c2
-rw-r--r--drivers/usb/input/itmtouch.c2
-rw-r--r--drivers/usb/input/keyspan_remote.c3
-rw-r--r--drivers/usb/input/mtouchusb.c2
-rw-r--r--drivers/usb/input/pid.c295
-rw-r--r--drivers/usb/input/pid.h62
-rw-r--r--drivers/usb/input/powermate.c4
-rw-r--r--drivers/usb/input/touchkitusb.c2
-rw-r--r--drivers/usb/input/trancevibrator.c159
-rw-r--r--drivers/usb/input/usbmouse.c2
-rw-r--r--drivers/usb/input/usbtouchscreen.c285
-rw-r--r--drivers/usb/input/wacom.c1003
-rw-r--r--drivers/usb/input/wacom.h132
-rw-r--r--drivers/usb/input/wacom_sys.c315
-rw-r--r--drivers/usb/input/wacom_wac.c646
-rw-r--r--drivers/usb/input/wacom_wac.h48
-rw-r--r--drivers/usb/input/yealink.c2
-rw-r--r--drivers/usb/misc/Kconfig61
-rw-r--r--drivers/usb/misc/Makefile5
-rw-r--r--drivers/usb/misc/adutux.c900
-rw-r--r--drivers/usb/misc/auerswald.c6
-rw-r--r--drivers/usb/misc/cypress_cy7c63.c19
-rw-r--r--drivers/usb/misc/cytherm.c35
-rw-r--r--drivers/usb/misc/ftdi-elan.c2809
-rw-r--r--drivers/usb/misc/idmouse.c2
-rw-r--r--drivers/usb/misc/ldusb.c10
-rw-r--r--drivers/usb/misc/legousbtower.c2
-rw-r--r--drivers/usb/misc/phidget.c43
-rw-r--r--drivers/usb/misc/phidget.h12
-rw-r--r--drivers/usb/misc/phidgetkit.c372
-rw-r--r--drivers/usb/misc/phidgetmotorcontrol.c466
-rw-r--r--drivers/usb/misc/phidgetservo.c117
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c2
-rw-r--r--drivers/usb/misc/usb_u132.h97
-rw-r--r--drivers/usb/misc/usblcd.c10
-rw-r--r--drivers/usb/misc/usbled.c20
-rw-r--r--drivers/usb/mon/mon_main.c7
-rw-r--r--drivers/usb/mon/mon_stat.c4
-rw-r--r--drivers/usb/mon/mon_text.c19
-rw-r--r--drivers/usb/mon/usb_mon.h5
-rw-r--r--drivers/usb/net/asix.c1005
-rw-r--r--drivers/usb/net/kaweth.c1
-rw-r--r--drivers/usb/net/net1080.c15
-rw-r--r--drivers/usb/net/pegasus.c20
-rw-r--r--drivers/usb/net/rtl8150.c2
-rw-r--r--drivers/usb/net/usbnet.c44
-rw-r--r--drivers/usb/net/usbnet.h1
-rw-r--r--drivers/usb/serial/Kconfig25
-rw-r--r--drivers/usb/serial/Makefile2
-rw-r--r--drivers/usb/serial/aircable.c625
-rw-r--r--drivers/usb/serial/airprime.c261
-rw-r--r--drivers/usb/serial/ark3116.c233
-rw-r--r--drivers/usb/serial/cyberjack.c6
-rw-r--r--drivers/usb/serial/cypress_m8.c129
-rw-r--r--drivers/usb/serial/ftdi_sio.c34
-rw-r--r--drivers/usb/serial/ftdi_sio.h10
-rw-r--r--drivers/usb/serial/garmin_gps.c219
-rw-r--r--drivers/usb/serial/generic.c6
-rw-r--r--drivers/usb/serial/ipaq.c39
-rw-r--r--drivers/usb/serial/ipw.c6
-rw-r--r--drivers/usb/serial/ir-usb.c6
-rw-r--r--drivers/usb/serial/keyspan_pda.c6
-rw-r--r--drivers/usb/serial/mos7840.c2962
-rw-r--r--drivers/usb/serial/omninet.c6
-rw-r--r--drivers/usb/serial/pl2303.c828
-rw-r--r--drivers/usb/serial/pl2303.h8
-rw-r--r--drivers/usb/serial/safe_serial.c6
-rw-r--r--drivers/usb/serial/usb-serial.c30
-rw-r--r--drivers/usb/storage/Kconfig17
-rw-r--r--drivers/usb/storage/Makefile1
-rw-r--r--drivers/usb/storage/initializers.c73
-rw-r--r--drivers/usb/storage/initializers.h1
-rw-r--r--drivers/usb/storage/karma.c155
-rw-r--r--drivers/usb/storage/karma.h7
-rw-r--r--drivers/usb/storage/libusual.c10
-rw-r--r--drivers/usb/storage/onetouch.c8
-rw-r--r--drivers/usb/storage/scsiglue.c15
-rw-r--r--drivers/usb/storage/transport.c5
-rw-r--r--drivers/usb/storage/unusual_devs.h32
-rw-r--r--drivers/usb/storage/usb.c11
-rw-r--r--drivers/usb/usb-skeleton.c101
-rw-r--r--drivers/video/Kconfig39
-rw-r--r--drivers/video/Makefile1
-rw-r--r--drivers/video/aty/atyfb.h6
-rw-r--r--drivers/video/aty/atyfb_base.c11
-rw-r--r--drivers/video/aty/mach64_ct.c2
-rw-r--r--drivers/video/aty/radeon_i2c.c106
-rw-r--r--drivers/video/aty/radeon_pm.c18
-rw-r--r--drivers/video/au1100fb.c30
-rw-r--r--drivers/video/backlight/hp680_bl.c4
-rw-r--r--drivers/video/backlight/locomolcd.c30
-rw-r--r--drivers/video/console/Kconfig2
-rw-r--r--drivers/video/console/fbcon.c54
-rw-r--r--drivers/video/console/fbcon.h2
-rw-r--r--drivers/video/console/fbcon_ccw.c2
-rw-r--r--drivers/video/console/fbcon_cw.c2
-rw-r--r--drivers/video/console/fbcon_ud.c2
-rw-r--r--drivers/video/console/softcursor.c31
-rw-r--r--drivers/video/fb_ddc.c116
-rw-r--r--drivers/video/fbmem.c3
-rw-r--r--drivers/video/fbsysfs.c35
-rw-r--r--drivers/video/hitfb.c229
-rw-r--r--drivers/video/i810/i810-i2c.c43
-rw-r--r--drivers/video/i810/i810_main.c18
-rw-r--r--drivers/video/intelfb/Makefile4
-rw-r--r--drivers/video/intelfb/intelfb.h79
-rw-r--r--drivers/video/intelfb/intelfb_i2c.c200
-rw-r--r--drivers/video/intelfb/intelfbdrv.c64
-rw-r--r--drivers/video/intelfb/intelfbhw.c136
-rw-r--r--drivers/video/intelfb/intelfbhw.h25
-rw-r--r--drivers/video/matrox/i2c-matroxfb.c12
-rw-r--r--drivers/video/matrox/matroxfb_base.c12
-rw-r--r--drivers/video/mbx/mbxfb.c21
-rw-r--r--drivers/video/nvidia/nv_i2c.c45
-rw-r--r--drivers/video/nvidia/nvidia.c29
-rw-r--r--drivers/video/pvr2fb.c22
-rw-r--r--drivers/video/riva/fbdev.c8
-rw-r--r--drivers/video/riva/rivafb-i2c.c44
-rw-r--r--drivers/video/savage/savagefb-i2c.c50
-rw-r--r--drivers/video/savage/savagefb_driver.c14
-rw-r--r--drivers/video/sis/init.h7
-rw-r--r--drivers/video/sis/init301.h7
-rw-r--r--drivers/video/sis/initextlfb.c4
-rw-r--r--drivers/video/sis/osdef.h4
-rw-r--r--drivers/video/sis/sis_accel.c26
-rw-r--r--drivers/video/sis/sis_accel.h14
-rw-r--r--drivers/video/sis/sis_main.c232
-rw-r--r--drivers/video/sis/sis_main.h65
-rw-r--r--drivers/video/sis/vgatypes.h2
-rw-r--r--drivers/video/sstfb.c170
1233 files changed, 60921 insertions, 25923 deletions
diff --git a/drivers/acorn/char/i2c.c b/drivers/acorn/char/i2c.c
index c26c08b36829..bdb9c8b78ed8 100644
--- a/drivers/acorn/char/i2c.c
+++ b/drivers/acorn/char/i2c.c
@@ -308,7 +308,6 @@ static struct i2c_algo_bit_data ioc_data = {
308 .getsda = ioc_getsda, 308 .getsda = ioc_getsda,
309 .getscl = ioc_getscl, 309 .getscl = ioc_getscl,
310 .udelay = 80, 310 .udelay = 80,
311 .mdelay = 80,
312 .timeout = 100 311 .timeout = 100
313}; 312};
314 313
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index 1dda370f402b..98099de59b45 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -238,6 +238,10 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
238 num_enabled++; 238 num_enabled++;
239 continue; 239 continue;
240 } 240 }
241
242 if (node < 0)
243 node = memory_add_physaddr_to_nid(info->start_addr);
244
241 result = add_memory(node, info->start_addr, info->length); 245 result = add_memory(node, info->start_addr, info->length);
242 if (result) 246 if (result)
243 continue; 247 continue;
diff --git a/drivers/acpi/i2c_ec.c b/drivers/acpi/i2c_ec.c
index 6809c283ec58..6342e612c203 100644
--- a/drivers/acpi/i2c_ec.c
+++ b/drivers/acpi/i2c_ec.c
@@ -293,7 +293,7 @@ static u32 acpi_ec_smb_func(struct i2c_adapter *adapter)
293 I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_HWPEC_CALC); 293 I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_HWPEC_CALC);
294} 294}
295 295
296static struct i2c_algorithm acpi_ec_smbus_algorithm = { 296static const struct i2c_algorithm acpi_ec_smbus_algorithm = {
297 .smbus_xfer = acpi_ec_smb_access, 297 .smbus_xfer = acpi_ec_smb_access,
298 .functionality = acpi_ec_smb_func, 298 .functionality = acpi_ec_smb_func,
299}; 299};
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 507f051d1cef..20beea778ea2 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -1079,7 +1079,7 @@ acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
1079 1079
1080acpi_status acpi_os_delete_cache(acpi_cache_t * cache) 1080acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
1081{ 1081{
1082 (void)kmem_cache_destroy(cache); 1082 kmem_cache_destroy(cache);
1083 return (AE_OK); 1083 return (AE_OK);
1084} 1084}
1085 1085
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 71066066d626..0a395fca843b 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -38,6 +38,7 @@
38#include <linux/dmi.h> 38#include <linux/dmi.h>
39#include <linux/moduleparam.h> 39#include <linux/moduleparam.h>
40#include <linux/sched.h> /* need_resched() */ 40#include <linux/sched.h> /* need_resched() */
41#include <linux/latency.h>
41 42
42#include <asm/io.h> 43#include <asm/io.h>
43#include <asm/uaccess.h> 44#include <asm/uaccess.h>
@@ -453,7 +454,8 @@ static void acpi_processor_idle(void)
453 */ 454 */
454 if (cx->promotion.state && 455 if (cx->promotion.state &&
455 ((cx->promotion.state - pr->power.states) <= max_cstate)) { 456 ((cx->promotion.state - pr->power.states) <= max_cstate)) {
456 if (sleep_ticks > cx->promotion.threshold.ticks) { 457 if (sleep_ticks > cx->promotion.threshold.ticks &&
458 cx->promotion.state->latency <= system_latency_constraint()) {
457 cx->promotion.count++; 459 cx->promotion.count++;
458 cx->demotion.count = 0; 460 cx->demotion.count = 0;
459 if (cx->promotion.count >= 461 if (cx->promotion.count >=
@@ -494,8 +496,10 @@ static void acpi_processor_idle(void)
494 end: 496 end:
495 /* 497 /*
496 * Demote if current state exceeds max_cstate 498 * Demote if current state exceeds max_cstate
499 * or if the latency of the current state is unacceptable
497 */ 500 */
498 if ((pr->power.state - pr->power.states) > max_cstate) { 501 if ((pr->power.state - pr->power.states) > max_cstate ||
502 pr->power.state->latency > system_latency_constraint()) {
499 if (cx->demotion.state) 503 if (cx->demotion.state)
500 next_state = cx->demotion.state; 504 next_state = cx->demotion.state;
501 } 505 }
@@ -1009,9 +1013,11 @@ static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset)
1009 1013
1010 seq_printf(seq, "active state: C%zd\n" 1014 seq_printf(seq, "active state: C%zd\n"
1011 "max_cstate: C%d\n" 1015 "max_cstate: C%d\n"
1012 "bus master activity: %08x\n", 1016 "bus master activity: %08x\n"
1017 "maximum allowed latency: %d usec\n",
1013 pr->power.state ? pr->power.state - pr->power.states : 0, 1018 pr->power.state ? pr->power.state - pr->power.states : 0,
1014 max_cstate, (unsigned)pr->power.bm_activity); 1019 max_cstate, (unsigned)pr->power.bm_activity,
1020 system_latency_constraint());
1015 1021
1016 seq_puts(seq, "states:\n"); 1022 seq_puts(seq, "states:\n");
1017 1023
@@ -1077,6 +1083,28 @@ static const struct file_operations acpi_processor_power_fops = {
1077 .release = single_release, 1083 .release = single_release,
1078}; 1084};
1079 1085
1086static void smp_callback(void *v)
1087{
1088 /* we already woke the CPU up, nothing more to do */
1089}
1090
1091/*
1092 * This function gets called when a part of the kernel has a new latency
1093 * requirement. This means we need to get all processors out of their C-state,
1094 * and then recalculate a new suitable C-state. Just do a cross-cpu IPI; that
1095 * wakes them all right up.
1096 */
1097static int acpi_processor_latency_notify(struct notifier_block *b,
1098 unsigned long l, void *v)
1099{
1100 smp_call_function(smp_callback, NULL, 0, 1);
1101 return NOTIFY_OK;
1102}
1103
1104static struct notifier_block acpi_processor_latency_notifier = {
1105 .notifier_call = acpi_processor_latency_notify,
1106};
1107
1080int acpi_processor_power_init(struct acpi_processor *pr, 1108int acpi_processor_power_init(struct acpi_processor *pr,
1081 struct acpi_device *device) 1109 struct acpi_device *device)
1082{ 1110{
@@ -1093,6 +1121,7 @@ int acpi_processor_power_init(struct acpi_processor *pr,
1093 "ACPI: processor limited to max C-state %d\n", 1121 "ACPI: processor limited to max C-state %d\n",
1094 max_cstate); 1122 max_cstate);
1095 first_run++; 1123 first_run++;
1124 register_latency_notifier(&acpi_processor_latency_notifier);
1096 } 1125 }
1097 1126
1098 if (!pr) 1127 if (!pr)
@@ -1164,6 +1193,7 @@ int acpi_processor_power_exit(struct acpi_processor *pr,
1164 * copies of pm_idle before proceeding. 1193 * copies of pm_idle before proceeding.
1165 */ 1194 */
1166 cpu_idle_wait(); 1195 cpu_idle_wait();
1196 unregister_latency_notifier(&acpi_processor_latency_notifier);
1167 } 1197 }
1168 1198
1169 return 0; 1199 return 0;
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 99837d932f36..3f4aa0c99ee4 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -311,7 +311,7 @@ config PATA_JMICRON
311 311
312config PATA_LEGACY 312config PATA_LEGACY
313 tristate "Legacy ISA PATA support (Experimental)" 313 tristate "Legacy ISA PATA support (Experimental)"
314 depends on PCI && EXPERIMENTAL 314 depends on ISA && EXPERIMENTAL
315 help 315 help
316 This option enables support for ISA/VLB bus legacy PATA 316 This option enables support for ISA/VLB bus legacy PATA
317 ports and allows them to be accessed via the new ATA layer. 317 ports and allows them to be accessed via the new ATA layer.
@@ -400,6 +400,7 @@ config PATA_PDC_OLD
400 400
401config PATA_QDI 401config PATA_QDI
402 tristate "QDI VLB PATA support" 402 tristate "QDI VLB PATA support"
403 depends on ISA
403 help 404 help
404 Support for QDI 6500 and 6580 PATA controllers on VESA local bus. 405 Support for QDI 6500 and 6580 PATA controllers on VESA local bus.
405 406
diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c
index 1d1c30a2fcd0..377425e71391 100644
--- a/drivers/ata/ata_generic.c
+++ b/drivers/ata/ata_generic.c
@@ -143,7 +143,7 @@ static struct ata_port_operations generic_port_ops = {
143 143
144 .qc_prep = ata_qc_prep, 144 .qc_prep = ata_qc_prep,
145 .qc_issue = ata_qc_issue_prot, 145 .qc_issue = ata_qc_issue_prot,
146 .eng_timeout = ata_eng_timeout, 146
147 .irq_handler = ata_interrupt, 147 .irq_handler = ata_interrupt,
148 .irq_clear = ata_bmdma_irq_clear, 148 .irq_clear = ata_bmdma_irq_clear,
149 149
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index ab2ecccf7798..5719704eb0ee 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -643,11 +643,9 @@ static int piix_pata_prereset(struct ata_port *ap)
643{ 643{
644 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 644 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
645 645
646 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no])) { 646 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no]))
647 ata_port_printk(ap, KERN_INFO, "port disabled. ignoring.\n"); 647 return -ENOENT;
648 ap->eh_context.i.action &= ~ATA_EH_RESET_MASK; 648
649 return 0;
650 }
651 ap->cbl = ATA_CBL_PATA40; 649 ap->cbl = ATA_CBL_PATA40;
652 return ata_std_prereset(ap); 650 return ata_std_prereset(ap);
653} 651}
@@ -851,7 +849,7 @@ static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev)
851 * @ap: Port whose timings we are configuring 849 * @ap: Port whose timings we are configuring
852 * @adev: Drive in question 850 * @adev: Drive in question
853 * @udma: udma mode, 0 - 6 851 * @udma: udma mode, 0 - 6
854 * @is_ich: set if the chip is an ICH device 852 * @isich: set if the chip is an ICH device
855 * 853 *
856 * Set UDMA mode for device, in host controller PCI config space. 854 * Set UDMA mode for device, in host controller PCI config space.
857 * 855 *
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 753b0152afd1..b4abd6850367 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -5453,6 +5453,11 @@ int ata_device_add(const struct ata_probe_ent *ent)
5453 int rc; 5453 int rc;
5454 5454
5455 DPRINTK("ENTER\n"); 5455 DPRINTK("ENTER\n");
5456
5457 if (ent->irq == 0) {
5458 dev_printk(KERN_ERR, dev, "is not available: No interrupt assigned.\n");
5459 return 0;
5460 }
5456 /* alloc a container for our list of ATA ports (buses) */ 5461 /* alloc a container for our list of ATA ports (buses) */
5457 host = kzalloc(sizeof(struct ata_host) + 5462 host = kzalloc(sizeof(struct ata_host) +
5458 (ent->n_ports * sizeof(void *)), GFP_KERNEL); 5463 (ent->n_ports * sizeof(void *)), GFP_KERNEL);
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 3fa80f09f2ae..02b2b2787d9b 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -1515,7 +1515,11 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1515 if (prereset) { 1515 if (prereset) {
1516 rc = prereset(ap); 1516 rc = prereset(ap);
1517 if (rc) { 1517 if (rc) {
1518 ata_port_printk(ap, KERN_ERR, 1518 if (rc == -ENOENT) {
1519 ata_port_printk(ap, KERN_DEBUG, "port disabled. ignoring.\n");
1520 ap->eh_context.i.action &= ~ATA_EH_RESET_MASK;
1521 } else
1522 ata_port_printk(ap, KERN_ERR,
1519 "prereset failed (errno=%d)\n", rc); 1523 "prereset failed (errno=%d)\n", rc);
1520 return rc; 1524 return rc;
1521 } 1525 }
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index 688bb55e197a..08b3a407473e 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -881,7 +881,7 @@ static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
881 probe_ent->private_data = port[0]->private_data; 881 probe_ent->private_data = port[0]->private_data;
882 882
883 if (port_mask & ATA_PORT_PRIMARY) { 883 if (port_mask & ATA_PORT_PRIMARY) {
884 probe_ent->irq = 14; 884 probe_ent->irq = ATA_PRIMARY_IRQ;
885 probe_ent->port[0].cmd_addr = ATA_PRIMARY_CMD; 885 probe_ent->port[0].cmd_addr = ATA_PRIMARY_CMD;
886 probe_ent->port[0].altstatus_addr = 886 probe_ent->port[0].altstatus_addr =
887 probe_ent->port[0].ctl_addr = ATA_PRIMARY_CTL; 887 probe_ent->port[0].ctl_addr = ATA_PRIMARY_CTL;
@@ -896,9 +896,9 @@ static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
896 896
897 if (port_mask & ATA_PORT_SECONDARY) { 897 if (port_mask & ATA_PORT_SECONDARY) {
898 if (probe_ent->irq) 898 if (probe_ent->irq)
899 probe_ent->irq2 = 15; 899 probe_ent->irq2 = ATA_SECONDARY_IRQ;
900 else 900 else
901 probe_ent->irq = 15; 901 probe_ent->irq = ATA_SECONDARY_IRQ;
902 probe_ent->port[1].cmd_addr = ATA_SECONDARY_CMD; 902 probe_ent->port[1].cmd_addr = ATA_SECONDARY_CMD;
903 probe_ent->port[1].altstatus_addr = 903 probe_ent->port[1].altstatus_addr =
904 probe_ent->port[1].ctl_addr = ATA_SECONDARY_CTL; 904 probe_ent->port[1].ctl_addr = ATA_SECONDARY_CTL;
diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
index 8448ee6e0eed..87af3b5861ab 100644
--- a/drivers/ata/pata_ali.c
+++ b/drivers/ata/pata_ali.c
@@ -369,7 +369,7 @@ static struct ata_port_operations ali_early_port_ops = {
369 369
370 .qc_prep = ata_qc_prep, 370 .qc_prep = ata_qc_prep,
371 .qc_issue = ata_qc_issue_prot, 371 .qc_issue = ata_qc_issue_prot,
372 .eng_timeout = ata_eng_timeout, 372
373 .data_xfer = ata_pio_data_xfer, 373 .data_xfer = ata_pio_data_xfer,
374 374
375 .irq_handler = ata_interrupt, 375 .irq_handler = ata_interrupt,
@@ -410,7 +410,7 @@ static struct ata_port_operations ali_20_port_ops = {
410 410
411 .qc_prep = ata_qc_prep, 411 .qc_prep = ata_qc_prep,
412 .qc_issue = ata_qc_issue_prot, 412 .qc_issue = ata_qc_issue_prot,
413 .eng_timeout = ata_eng_timeout, 413
414 .data_xfer = ata_pio_data_xfer, 414 .data_xfer = ata_pio_data_xfer,
415 415
416 .irq_handler = ata_interrupt, 416 .irq_handler = ata_interrupt,
@@ -448,7 +448,7 @@ static struct ata_port_operations ali_c2_port_ops = {
448 448
449 .qc_prep = ata_qc_prep, 449 .qc_prep = ata_qc_prep,
450 .qc_issue = ata_qc_issue_prot, 450 .qc_issue = ata_qc_issue_prot,
451 .eng_timeout = ata_eng_timeout, 451
452 .data_xfer = ata_pio_data_xfer, 452 .data_xfer = ata_pio_data_xfer,
453 453
454 .irq_handler = ata_interrupt, 454 .irq_handler = ata_interrupt,
@@ -485,7 +485,7 @@ static struct ata_port_operations ali_c5_port_ops = {
485 485
486 .qc_prep = ata_qc_prep, 486 .qc_prep = ata_qc_prep,
487 .qc_issue = ata_qc_issue_prot, 487 .qc_issue = ata_qc_issue_prot,
488 .eng_timeout = ata_eng_timeout, 488
489 .data_xfer = ata_pio_data_xfer, 489 .data_xfer = ata_pio_data_xfer,
490 490
491 .irq_handler = ata_interrupt, 491 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c
index 3293cf9a7eb5..599ee266722c 100644
--- a/drivers/ata/pata_amd.c
+++ b/drivers/ata/pata_amd.c
@@ -25,7 +25,7 @@
25#include <linux/libata.h> 25#include <linux/libata.h>
26 26
27#define DRV_NAME "pata_amd" 27#define DRV_NAME "pata_amd"
28#define DRV_VERSION "0.2.3" 28#define DRV_VERSION "0.2.4"
29 29
30/** 30/**
31 * timing_setup - shared timing computation and load 31 * timing_setup - shared timing computation and load
@@ -137,11 +137,8 @@ static int amd_pre_reset(struct ata_port *ap)
137 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 137 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
138 u8 ata66; 138 u8 ata66;
139 139
140 if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no])) { 140 if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no]))
141 ata_port_disable(ap); 141 return -ENOENT;
142 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id);
143 return 0;
144 }
145 142
146 pci_read_config_byte(pdev, 0x42, &ata66); 143 pci_read_config_byte(pdev, 0x42, &ata66);
147 if (ata66 & bitmask[ap->port_no]) 144 if (ata66 & bitmask[ap->port_no])
@@ -167,11 +164,9 @@ static int amd_early_pre_reset(struct ata_port *ap)
167 { 0x40, 1, 0x01, 0x01 } 164 { 0x40, 1, 0x01, 0x01 }
168 }; 165 };
169 166
170 if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no])) { 167 if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no]))
171 ata_port_disable(ap); 168 return -ENOENT;
172 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id); 169
173 return 0;
174 }
175 /* No host side cable detection */ 170 /* No host side cable detection */
176 ap->cbl = ATA_CBL_PATA80; 171 ap->cbl = ATA_CBL_PATA80;
177 return ata_std_prereset(ap); 172 return ata_std_prereset(ap);
@@ -262,12 +257,8 @@ static int nv_pre_reset(struct ata_port *ap) {
262 u8 ata66; 257 u8 ata66;
263 u16 udma; 258 u16 udma;
264 259
265 if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no])) { 260 if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no]))
266 ata_port_disable(ap); 261 return -ENOENT;
267 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id);
268 return 0;
269 }
270
271 262
272 pci_read_config_byte(pdev, 0x52, &ata66); 263 pci_read_config_byte(pdev, 0x52, &ata66);
273 if (ata66 & bitmask[ap->port_no]) 264 if (ata66 & bitmask[ap->port_no])
@@ -368,7 +359,7 @@ static struct ata_port_operations amd33_port_ops = {
368 359
369 .qc_prep = ata_qc_prep, 360 .qc_prep = ata_qc_prep,
370 .qc_issue = ata_qc_issue_prot, 361 .qc_issue = ata_qc_issue_prot,
371 .eng_timeout = ata_eng_timeout, 362
372 .data_xfer = ata_pio_data_xfer, 363 .data_xfer = ata_pio_data_xfer,
373 364
374 .irq_handler = ata_interrupt, 365 .irq_handler = ata_interrupt,
@@ -402,7 +393,7 @@ static struct ata_port_operations amd66_port_ops = {
402 393
403 .qc_prep = ata_qc_prep, 394 .qc_prep = ata_qc_prep,
404 .qc_issue = ata_qc_issue_prot, 395 .qc_issue = ata_qc_issue_prot,
405 .eng_timeout = ata_eng_timeout, 396
406 .data_xfer = ata_pio_data_xfer, 397 .data_xfer = ata_pio_data_xfer,
407 398
408 .irq_handler = ata_interrupt, 399 .irq_handler = ata_interrupt,
@@ -436,7 +427,7 @@ static struct ata_port_operations amd100_port_ops = {
436 427
437 .qc_prep = ata_qc_prep, 428 .qc_prep = ata_qc_prep,
438 .qc_issue = ata_qc_issue_prot, 429 .qc_issue = ata_qc_issue_prot,
439 .eng_timeout = ata_eng_timeout, 430
440 .data_xfer = ata_pio_data_xfer, 431 .data_xfer = ata_pio_data_xfer,
441 432
442 .irq_handler = ata_interrupt, 433 .irq_handler = ata_interrupt,
@@ -470,7 +461,7 @@ static struct ata_port_operations amd133_port_ops = {
470 461
471 .qc_prep = ata_qc_prep, 462 .qc_prep = ata_qc_prep,
472 .qc_issue = ata_qc_issue_prot, 463 .qc_issue = ata_qc_issue_prot,
473 .eng_timeout = ata_eng_timeout, 464
474 .data_xfer = ata_pio_data_xfer, 465 .data_xfer = ata_pio_data_xfer,
475 466
476 .irq_handler = ata_interrupt, 467 .irq_handler = ata_interrupt,
@@ -504,7 +495,7 @@ static struct ata_port_operations nv100_port_ops = {
504 495
505 .qc_prep = ata_qc_prep, 496 .qc_prep = ata_qc_prep,
506 .qc_issue = ata_qc_issue_prot, 497 .qc_issue = ata_qc_issue_prot,
507 .eng_timeout = ata_eng_timeout, 498
508 .data_xfer = ata_pio_data_xfer, 499 .data_xfer = ata_pio_data_xfer,
509 500
510 .irq_handler = ata_interrupt, 501 .irq_handler = ata_interrupt,
@@ -538,7 +529,7 @@ static struct ata_port_operations nv133_port_ops = {
538 529
539 .qc_prep = ata_qc_prep, 530 .qc_prep = ata_qc_prep,
540 .qc_issue = ata_qc_issue_prot, 531 .qc_issue = ata_qc_issue_prot,
541 .eng_timeout = ata_eng_timeout, 532
542 .data_xfer = ata_pio_data_xfer, 533 .data_xfer = ata_pio_data_xfer,
543 534
544 .irq_handler = ata_interrupt, 535 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_artop.c b/drivers/ata/pata_artop.c
index d6ef3bf1bac7..c4ccb75a4f1d 100644
--- a/drivers/ata/pata_artop.c
+++ b/drivers/ata/pata_artop.c
@@ -28,7 +28,7 @@
28#include <linux/ata.h> 28#include <linux/ata.h>
29 29
30#define DRV_NAME "pata_artop" 30#define DRV_NAME "pata_artop"
31#define DRV_VERSION "0.4.1" 31#define DRV_VERSION "0.4.2"
32 32
33/* 33/*
34 * The ARTOP has 33 Mhz and "over clocked" timing tables. Until we 34 * The ARTOP has 33 Mhz and "over clocked" timing tables. Until we
@@ -47,11 +47,9 @@ static int artop6210_pre_reset(struct ata_port *ap)
47 { 0x4AU, 1U, 0x04UL, 0x04UL }, /* port 1 */ 47 { 0x4AU, 1U, 0x04UL, 0x04UL }, /* port 1 */
48 }; 48 };
49 49
50 if (!pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no])) { 50 if (!pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no]))
51 ata_port_disable(ap); 51 return -ENOENT;
52 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id); 52
53 return 0;
54 }
55 ap->cbl = ATA_CBL_PATA40; 53 ap->cbl = ATA_CBL_PATA40;
56 return ata_std_prereset(ap); 54 return ata_std_prereset(ap);
57} 55}
@@ -90,11 +88,9 @@ static int artop6260_pre_reset(struct ata_port *ap)
90 u8 tmp; 88 u8 tmp;
91 89
92 /* Odd numbered device ids are the units with enable bits (the -R cards) */ 90 /* Odd numbered device ids are the units with enable bits (the -R cards) */
93 if (pdev->device % 1 && !pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no])) { 91 if (pdev->device % 1 && !pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no]))
94 ata_port_disable(ap); 92 return -ENOENT;
95 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id); 93
96 return 0;
97 }
98 pci_read_config_byte(pdev, 0x49, &tmp); 94 pci_read_config_byte(pdev, 0x49, &tmp);
99 if (tmp & (1 >> ap->port_no)) 95 if (tmp & (1 >> ap->port_no))
100 ap->cbl = ATA_CBL_PATA40; 96 ap->cbl = ATA_CBL_PATA40;
@@ -344,7 +340,7 @@ static const struct ata_port_operations artop6210_ops = {
344 .bmdma_status = ata_bmdma_status, 340 .bmdma_status = ata_bmdma_status,
345 .qc_prep = ata_qc_prep, 341 .qc_prep = ata_qc_prep,
346 .qc_issue = ata_qc_issue_prot, 342 .qc_issue = ata_qc_issue_prot,
347 .eng_timeout = ata_eng_timeout, 343
348 .data_xfer = ata_pio_data_xfer, 344 .data_xfer = ata_pio_data_xfer,
349 345
350 .irq_handler = ata_interrupt, 346 .irq_handler = ata_interrupt,
@@ -379,8 +375,6 @@ static const struct ata_port_operations artop6260_ops = {
379 .qc_issue = ata_qc_issue_prot, 375 .qc_issue = ata_qc_issue_prot,
380 .data_xfer = ata_pio_data_xfer, 376 .data_xfer = ata_pio_data_xfer,
381 377
382 .eng_timeout = ata_eng_timeout,
383
384 .irq_handler = ata_interrupt, 378 .irq_handler = ata_interrupt,
385 .irq_clear = ata_bmdma_irq_clear, 379 .irq_clear = ata_bmdma_irq_clear,
386 380
diff --git a/drivers/ata/pata_atiixp.c b/drivers/ata/pata_atiixp.c
index 3f78a1e54a75..6c2269b6bd3c 100644
--- a/drivers/ata/pata_atiixp.c
+++ b/drivers/ata/pata_atiixp.c
@@ -22,7 +22,7 @@
22#include <linux/libata.h> 22#include <linux/libata.h>
23 23
24#define DRV_NAME "pata_atiixp" 24#define DRV_NAME "pata_atiixp"
25#define DRV_VERSION "0.4.2" 25#define DRV_VERSION "0.4.3"
26 26
27enum { 27enum {
28 ATIIXP_IDE_PIO_TIMING = 0x40, 28 ATIIXP_IDE_PIO_TIMING = 0x40,
@@ -41,11 +41,9 @@ static int atiixp_pre_reset(struct ata_port *ap)
41 { 0x48, 1, 0x08, 0x00 } 41 { 0x48, 1, 0x08, 0x00 }
42 }; 42 };
43 43
44 if (!pci_test_config_bits(pdev, &atiixp_enable_bits[ap->port_no])) { 44 if (!pci_test_config_bits(pdev, &atiixp_enable_bits[ap->port_no]))
45 ata_port_disable(ap); 45 return -ENOENT;
46 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id); 46
47 return 0;
48 }
49 ap->cbl = ATA_CBL_PATA80; 47 ap->cbl = ATA_CBL_PATA80;
50 return ata_std_prereset(ap); 48 return ata_std_prereset(ap);
51} 49}
@@ -244,7 +242,7 @@ static struct ata_port_operations atiixp_port_ops = {
244 242
245 .qc_prep = ata_qc_prep, 243 .qc_prep = ata_qc_prep,
246 .qc_issue = ata_qc_issue_prot, 244 .qc_issue = ata_qc_issue_prot,
247 .eng_timeout = ata_eng_timeout, 245
248 .data_xfer = ata_pio_data_xfer, 246 .data_xfer = ata_pio_data_xfer,
249 247
250 .irq_handler = ata_interrupt, 248 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_cmd64x.c b/drivers/ata/pata_cmd64x.c
index abf1bb7bd322..e92b0ef43ec5 100644
--- a/drivers/ata/pata_cmd64x.c
+++ b/drivers/ata/pata_cmd64x.c
@@ -301,7 +301,7 @@ static struct ata_port_operations cmd64x_port_ops = {
301 301
302 .qc_prep = ata_qc_prep, 302 .qc_prep = ata_qc_prep,
303 .qc_issue = ata_qc_issue_prot, 303 .qc_issue = ata_qc_issue_prot,
304 .eng_timeout = ata_eng_timeout, 304
305 .data_xfer = ata_pio_data_xfer, 305 .data_xfer = ata_pio_data_xfer,
306 306
307 .irq_handler = ata_interrupt, 307 .irq_handler = ata_interrupt,
@@ -335,7 +335,7 @@ static struct ata_port_operations cmd646r1_port_ops = {
335 335
336 .qc_prep = ata_qc_prep, 336 .qc_prep = ata_qc_prep,
337 .qc_issue = ata_qc_issue_prot, 337 .qc_issue = ata_qc_issue_prot,
338 .eng_timeout = ata_eng_timeout, 338
339 .data_xfer = ata_pio_data_xfer, 339 .data_xfer = ata_pio_data_xfer,
340 340
341 .irq_handler = ata_interrupt, 341 .irq_handler = ata_interrupt,
@@ -369,7 +369,7 @@ static struct ata_port_operations cmd648_port_ops = {
369 369
370 .qc_prep = ata_qc_prep, 370 .qc_prep = ata_qc_prep,
371 .qc_issue = ata_qc_issue_prot, 371 .qc_issue = ata_qc_issue_prot,
372 .eng_timeout = ata_eng_timeout, 372
373 .data_xfer = ata_pio_data_xfer, 373 .data_xfer = ata_pio_data_xfer,
374 374
375 .irq_handler = ata_interrupt, 375 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c
index 792ce4828510..a6c6cebd0dae 100644
--- a/drivers/ata/pata_cs5520.c
+++ b/drivers/ata/pata_cs5520.c
@@ -193,8 +193,6 @@ static struct ata_port_operations cs5520_port_ops = {
193 .qc_issue = ata_qc_issue_prot, 193 .qc_issue = ata_qc_issue_prot,
194 .data_xfer = ata_pio_data_xfer, 194 .data_xfer = ata_pio_data_xfer,
195 195
196 .eng_timeout = ata_eng_timeout,
197
198 .irq_handler = ata_interrupt, 196 .irq_handler = ata_interrupt,
199 .irq_clear = ata_bmdma_irq_clear, 197 .irq_clear = ata_bmdma_irq_clear,
200 198
diff --git a/drivers/ata/pata_cs5530.c b/drivers/ata/pata_cs5530.c
index f3d8a3bc1e78..7bba4d954e9c 100644
--- a/drivers/ata/pata_cs5530.c
+++ b/drivers/ata/pata_cs5530.c
@@ -207,7 +207,7 @@ static struct ata_port_operations cs5530_port_ops = {
207 207
208 .qc_prep = ata_qc_prep, 208 .qc_prep = ata_qc_prep,
209 .qc_issue = cs5530_qc_issue_prot, 209 .qc_issue = cs5530_qc_issue_prot,
210 .eng_timeout = ata_eng_timeout, 210
211 .data_xfer = ata_pio_data_xfer, 211 .data_xfer = ata_pio_data_xfer,
212 212
213 .irq_handler = ata_interrupt, 213 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_cs5535.c b/drivers/ata/pata_cs5535.c
index 69d6b4258724..d64fcdceaf01 100644
--- a/drivers/ata/pata_cs5535.c
+++ b/drivers/ata/pata_cs5535.c
@@ -211,7 +211,7 @@ static struct ata_port_operations cs5535_port_ops = {
211 211
212 .qc_prep = ata_qc_prep, 212 .qc_prep = ata_qc_prep,
213 .qc_issue = ata_qc_issue_prot, 213 .qc_issue = ata_qc_issue_prot,
214 .eng_timeout = ata_eng_timeout, 214
215 .data_xfer = ata_pio_data_xfer, 215 .data_xfer = ata_pio_data_xfer,
216 216
217 .irq_handler = ata_interrupt, 217 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_cypress.c b/drivers/ata/pata_cypress.c
index fd55474e0d15..dfa5ac539048 100644
--- a/drivers/ata/pata_cypress.c
+++ b/drivers/ata/pata_cypress.c
@@ -162,7 +162,7 @@ static struct ata_port_operations cy82c693_port_ops = {
162 162
163 .qc_prep = ata_qc_prep, 163 .qc_prep = ata_qc_prep,
164 .qc_issue = ata_qc_issue_prot, 164 .qc_issue = ata_qc_issue_prot,
165 .eng_timeout = ata_eng_timeout, 165
166 .data_xfer = ata_pio_data_xfer, 166 .data_xfer = ata_pio_data_xfer,
167 167
168 .irq_handler = ata_interrupt, 168 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_efar.c b/drivers/ata/pata_efar.c
index c30bc181304f..95cd1ca181f5 100644
--- a/drivers/ata/pata_efar.c
+++ b/drivers/ata/pata_efar.c
@@ -22,7 +22,7 @@
22#include <linux/ata.h> 22#include <linux/ata.h>
23 23
24#define DRV_NAME "pata_efar" 24#define DRV_NAME "pata_efar"
25#define DRV_VERSION "0.4.1" 25#define DRV_VERSION "0.4.2"
26 26
27/** 27/**
28 * efar_pre_reset - check for 40/80 pin 28 * efar_pre_reset - check for 40/80 pin
@@ -42,11 +42,9 @@ static int efar_pre_reset(struct ata_port *ap)
42 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 42 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
43 u8 tmp; 43 u8 tmp;
44 44
45 if (!pci_test_config_bits(pdev, &efar_enable_bits[ap->port_no])) { 45 if (!pci_test_config_bits(pdev, &efar_enable_bits[ap->port_no]))
46 ata_port_disable(ap); 46 return -ENOENT;
47 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id); 47
48 return 0;
49 }
50 pci_read_config_byte(pdev, 0x47, &tmp); 48 pci_read_config_byte(pdev, 0x47, &tmp);
51 if (tmp & (2 >> ap->port_no)) 49 if (tmp & (2 >> ap->port_no))
52 ap->cbl = ATA_CBL_PATA40; 50 ap->cbl = ATA_CBL_PATA40;
@@ -263,8 +261,6 @@ static const struct ata_port_operations efar_ops = {
263 .qc_issue = ata_qc_issue_prot, 261 .qc_issue = ata_qc_issue_prot,
264 .data_xfer = ata_pio_data_xfer, 262 .data_xfer = ata_pio_data_xfer,
265 263
266 .eng_timeout = ata_eng_timeout,
267
268 .irq_handler = ata_interrupt, 264 .irq_handler = ata_interrupt,
269 .irq_clear = ata_bmdma_irq_clear, 265 .irq_clear = ata_bmdma_irq_clear,
270 266
diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
index 94bb1dfc3f19..8c757438f350 100644
--- a/drivers/ata/pata_hpt366.c
+++ b/drivers/ata/pata_hpt366.c
@@ -360,7 +360,7 @@ static struct ata_port_operations hpt366_port_ops = {
360 360
361 .qc_prep = ata_qc_prep, 361 .qc_prep = ata_qc_prep,
362 .qc_issue = ata_qc_issue_prot, 362 .qc_issue = ata_qc_issue_prot,
363 .eng_timeout = ata_eng_timeout, 363
364 .data_xfer = ata_pio_data_xfer, 364 .data_xfer = ata_pio_data_xfer,
365 365
366 .irq_handler = ata_interrupt, 366 .irq_handler = ata_interrupt,
@@ -429,7 +429,7 @@ static int hpt36x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
429 429
430 /* PCI clocking determines the ATA timing values to use */ 430 /* PCI clocking determines the ATA timing values to use */
431 /* info_hpt366 is safe against re-entry so we can scribble on it */ 431 /* info_hpt366 is safe against re-entry so we can scribble on it */
432 switch(reg1 & 0x700) { 432 switch((reg1 & 0x700) >> 8) {
433 case 5: 433 case 5:
434 info_hpt366.private_data = &hpt366_40; 434 info_hpt366.private_data = &hpt366_40;
435 break; 435 break;
diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index 532a7928f803..10318c0012ef 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -793,7 +793,7 @@ static struct ata_port_operations hpt370_port_ops = {
793 793
794 .qc_prep = ata_qc_prep, 794 .qc_prep = ata_qc_prep,
795 .qc_issue = ata_qc_issue_prot, 795 .qc_issue = ata_qc_issue_prot,
796 .eng_timeout = ata_eng_timeout, 796
797 .data_xfer = ata_pio_data_xfer, 797 .data_xfer = ata_pio_data_xfer,
798 798
799 .irq_handler = ata_interrupt, 799 .irq_handler = ata_interrupt,
@@ -832,7 +832,7 @@ static struct ata_port_operations hpt370a_port_ops = {
832 832
833 .qc_prep = ata_qc_prep, 833 .qc_prep = ata_qc_prep,
834 .qc_issue = ata_qc_issue_prot, 834 .qc_issue = ata_qc_issue_prot,
835 .eng_timeout = ata_eng_timeout, 835
836 .data_xfer = ata_pio_data_xfer, 836 .data_xfer = ata_pio_data_xfer,
837 837
838 .irq_handler = ata_interrupt, 838 .irq_handler = ata_interrupt,
@@ -872,7 +872,7 @@ static struct ata_port_operations hpt372_port_ops = {
872 872
873 .qc_prep = ata_qc_prep, 873 .qc_prep = ata_qc_prep,
874 .qc_issue = ata_qc_issue_prot, 874 .qc_issue = ata_qc_issue_prot,
875 .eng_timeout = ata_eng_timeout, 875
876 .data_xfer = ata_pio_data_xfer, 876 .data_xfer = ata_pio_data_xfer,
877 877
878 .irq_handler = ata_interrupt, 878 .irq_handler = ata_interrupt,
@@ -912,7 +912,7 @@ static struct ata_port_operations hpt374_port_ops = {
912 912
913 .qc_prep = ata_qc_prep, 913 .qc_prep = ata_qc_prep,
914 .qc_issue = ata_qc_issue_prot, 914 .qc_issue = ata_qc_issue_prot,
915 .eng_timeout = ata_eng_timeout, 915
916 .data_xfer = ata_pio_data_xfer, 916 .data_xfer = ata_pio_data_xfer,
917 917
918 .irq_handler = ata_interrupt, 918 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
index 06c8db079b91..5c5d4f6ab901 100644
--- a/drivers/ata/pata_hpt3x2n.c
+++ b/drivers/ata/pata_hpt3x2n.c
@@ -372,7 +372,7 @@ static struct ata_port_operations hpt3x2n_port_ops = {
372 372
373 .qc_prep = ata_qc_prep, 373 .qc_prep = ata_qc_prep,
374 .qc_issue = hpt3x2n_qc_issue_prot, 374 .qc_issue = hpt3x2n_qc_issue_prot,
375 .eng_timeout = ata_eng_timeout, 375
376 .data_xfer = ata_pio_data_xfer, 376 .data_xfer = ata_pio_data_xfer,
377 377
378 .irq_handler = ata_interrupt, 378 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_hpt3x3.c b/drivers/ata/pata_hpt3x3.c
index 152770133ab1..1f084ab1ccc6 100644
--- a/drivers/ata/pata_hpt3x3.c
+++ b/drivers/ata/pata_hpt3x3.c
@@ -145,7 +145,7 @@ static struct ata_port_operations hpt3x3_port_ops = {
145 145
146 .qc_prep = ata_qc_prep, 146 .qc_prep = ata_qc_prep,
147 .qc_issue = ata_qc_issue_prot, 147 .qc_issue = ata_qc_issue_prot,
148 .eng_timeout = ata_eng_timeout, 148
149 .data_xfer = ata_pio_data_xfer, 149 .data_xfer = ata_pio_data_xfer,
150 150
151 .irq_handler = ata_interrupt, 151 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_isapnp.c b/drivers/ata/pata_isapnp.c
index 73948c8b7270..640b8b0954f5 100644
--- a/drivers/ata/pata_isapnp.c
+++ b/drivers/ata/pata_isapnp.c
@@ -52,7 +52,7 @@ static struct ata_port_operations isapnp_port_ops = {
52 52
53 .qc_prep = ata_qc_prep, 53 .qc_prep = ata_qc_prep,
54 .qc_issue = ata_qc_issue_prot, 54 .qc_issue = ata_qc_issue_prot,
55 .eng_timeout = ata_eng_timeout, 55
56 .data_xfer = ata_pio_data_xfer, 56 .data_xfer = ata_pio_data_xfer,
57 57
58 .irq_handler = ata_interrupt, 58 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
index af39097d8081..82a46ff40000 100644
--- a/drivers/ata/pata_it821x.c
+++ b/drivers/ata/pata_it821x.c
@@ -703,7 +703,7 @@ static struct ata_port_operations it821x_smart_port_ops = {
703 703
704 .qc_prep = ata_qc_prep, 704 .qc_prep = ata_qc_prep,
705 .qc_issue = it821x_smart_qc_issue_prot, 705 .qc_issue = it821x_smart_qc_issue_prot,
706 .eng_timeout = ata_eng_timeout, 706
707 .data_xfer = ata_pio_data_xfer, 707 .data_xfer = ata_pio_data_xfer,
708 708
709 .irq_handler = ata_interrupt, 709 .irq_handler = ata_interrupt,
@@ -739,7 +739,7 @@ static struct ata_port_operations it821x_passthru_port_ops = {
739 739
740 .qc_prep = ata_qc_prep, 740 .qc_prep = ata_qc_prep,
741 .qc_issue = it821x_passthru_qc_issue_prot, 741 .qc_issue = it821x_passthru_qc_issue_prot,
742 .eng_timeout = ata_eng_timeout, 742
743 .data_xfer = ata_pio_data_xfer, 743 .data_xfer = ata_pio_data_xfer,
744 744
745 .irq_clear = ata_bmdma_irq_clear, 745 .irq_clear = ata_bmdma_irq_clear,
diff --git a/drivers/ata/pata_jmicron.c b/drivers/ata/pata_jmicron.c
index 6832a643a9eb..be3a866b111f 100644
--- a/drivers/ata/pata_jmicron.c
+++ b/drivers/ata/pata_jmicron.c
@@ -51,7 +51,7 @@ static int jmicron_pre_reset(struct ata_port *ap)
51 /* Check if our port is enabled */ 51 /* Check if our port is enabled */
52 pci_read_config_dword(pdev, 0x40, &control); 52 pci_read_config_dword(pdev, 0x40, &control);
53 if ((control & port_mask) == 0) 53 if ((control & port_mask) == 0)
54 return 0; 54 return -ENOENT;
55 55
56 /* There are two basic mappings. One has the two SATA ports merged 56 /* There are two basic mappings. One has the two SATA ports merged
57 as master/slave and the secondary as PATA, the other has only the 57 as master/slave and the secondary as PATA, the other has only the
@@ -164,8 +164,7 @@ static const struct ata_port_operations jmicron_ops = {
164 .qc_issue = ata_qc_issue_prot, 164 .qc_issue = ata_qc_issue_prot,
165 .data_xfer = ata_pio_data_xfer, 165 .data_xfer = ata_pio_data_xfer,
166 166
167 /* Timeout handling. Special recovery hooks here */ 167 /* IRQ-related hooks */
168 .eng_timeout = ata_eng_timeout,
169 .irq_handler = ata_interrupt, 168 .irq_handler = ata_interrupt,
170 .irq_clear = ata_bmdma_irq_clear, 169 .irq_clear = ata_bmdma_irq_clear,
171 170
diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
index ad37c220bb2c..10231ef731d1 100644
--- a/drivers/ata/pata_legacy.c
+++ b/drivers/ata/pata_legacy.c
@@ -161,7 +161,7 @@ static struct ata_port_operations simple_port_ops = {
161 161
162 .qc_prep = ata_qc_prep, 162 .qc_prep = ata_qc_prep,
163 .qc_issue = ata_qc_issue_prot, 163 .qc_issue = ata_qc_issue_prot,
164 .eng_timeout = ata_eng_timeout, 164
165 .data_xfer = ata_pio_data_xfer_noirq, 165 .data_xfer = ata_pio_data_xfer_noirq,
166 166
167 .irq_handler = ata_interrupt, 167 .irq_handler = ata_interrupt,
@@ -186,7 +186,7 @@ static struct ata_port_operations legacy_port_ops = {
186 186
187 .qc_prep = ata_qc_prep, 187 .qc_prep = ata_qc_prep,
188 .qc_issue = ata_qc_issue_prot, 188 .qc_issue = ata_qc_issue_prot,
189 .eng_timeout = ata_eng_timeout, 189
190 .data_xfer = ata_pio_data_xfer_noirq, 190 .data_xfer = ata_pio_data_xfer_noirq,
191 191
192 .irq_handler = ata_interrupt, 192 .irq_handler = ata_interrupt,
@@ -296,7 +296,7 @@ static struct ata_port_operations pdc20230_port_ops = {
296 296
297 .qc_prep = ata_qc_prep, 297 .qc_prep = ata_qc_prep,
298 .qc_issue = ata_qc_issue_prot, 298 .qc_issue = ata_qc_issue_prot,
299 .eng_timeout = ata_eng_timeout, 299
300 .data_xfer = pdc_data_xfer_vlb, 300 .data_xfer = pdc_data_xfer_vlb,
301 301
302 .irq_handler = ata_interrupt, 302 .irq_handler = ata_interrupt,
@@ -348,7 +348,7 @@ static struct ata_port_operations ht6560a_port_ops = {
348 348
349 .qc_prep = ata_qc_prep, 349 .qc_prep = ata_qc_prep,
350 .qc_issue = ata_qc_issue_prot, 350 .qc_issue = ata_qc_issue_prot,
351 .eng_timeout = ata_eng_timeout, 351
352 .data_xfer = ata_pio_data_xfer, /* Check vlb/noirq */ 352 .data_xfer = ata_pio_data_xfer, /* Check vlb/noirq */
353 353
354 .irq_handler = ata_interrupt, 354 .irq_handler = ata_interrupt,
@@ -411,7 +411,7 @@ static struct ata_port_operations ht6560b_port_ops = {
411 411
412 .qc_prep = ata_qc_prep, 412 .qc_prep = ata_qc_prep,
413 .qc_issue = ata_qc_issue_prot, 413 .qc_issue = ata_qc_issue_prot,
414 .eng_timeout = ata_eng_timeout, 414
415 .data_xfer = ata_pio_data_xfer, /* FIXME: Check 32bit and noirq */ 415 .data_xfer = ata_pio_data_xfer, /* FIXME: Check 32bit and noirq */
416 416
417 .irq_handler = ata_interrupt, 417 .irq_handler = ata_interrupt,
@@ -529,7 +529,7 @@ static struct ata_port_operations opti82c611a_port_ops = {
529 529
530 .qc_prep = ata_qc_prep, 530 .qc_prep = ata_qc_prep,
531 .qc_issue = ata_qc_issue_prot, 531 .qc_issue = ata_qc_issue_prot,
532 .eng_timeout = ata_eng_timeout, 532
533 .data_xfer = ata_pio_data_xfer, 533 .data_xfer = ata_pio_data_xfer,
534 534
535 .irq_handler = ata_interrupt, 535 .irq_handler = ata_interrupt,
@@ -659,7 +659,7 @@ static struct ata_port_operations opti82c46x_port_ops = {
659 659
660 .qc_prep = ata_qc_prep, 660 .qc_prep = ata_qc_prep,
661 .qc_issue = opti82c46x_qc_issue_prot, 661 .qc_issue = opti82c46x_qc_issue_prot,
662 .eng_timeout = ata_eng_timeout, 662
663 .data_xfer = ata_pio_data_xfer, 663 .data_xfer = ata_pio_data_xfer,
664 664
665 .irq_handler = ata_interrupt, 665 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_mpiix.c b/drivers/ata/pata_mpiix.c
index 1958c4ed09a8..3c65393c1f01 100644
--- a/drivers/ata/pata_mpiix.c
+++ b/drivers/ata/pata_mpiix.c
@@ -18,7 +18,7 @@
18 * The driver conciously keeps this logic internally to avoid pushing quirky 18 * The driver conciously keeps this logic internally to avoid pushing quirky
19 * PATA history into the clean libata layer. 19 * PATA history into the clean libata layer.
20 * 20 *
21 * Thinkpad specific note: If you boot an MPIIX using thinkpad with a PCMCIA 21 * Thinkpad specific note: If you boot an MPIIX using a thinkpad with a PCMCIA
22 * hard disk present this driver will not detect it. This is not a bug. In this 22 * hard disk present this driver will not detect it. This is not a bug. In this
23 * configuration the secondary port of the MPIIX is disabled and the addresses 23 * configuration the secondary port of the MPIIX is disabled and the addresses
24 * are decoded by the PCMCIA bridge and therefore are for a generic IDE driver 24 * are decoded by the PCMCIA bridge and therefore are for a generic IDE driver
@@ -35,7 +35,7 @@
35#include <linux/libata.h> 35#include <linux/libata.h>
36 36
37#define DRV_NAME "pata_mpiix" 37#define DRV_NAME "pata_mpiix"
38#define DRV_VERSION "0.7.1" 38#define DRV_VERSION "0.7.2"
39 39
40enum { 40enum {
41 IDETIM = 0x6C, /* IDE control register */ 41 IDETIM = 0x6C, /* IDE control register */
@@ -54,11 +54,8 @@ static int mpiix_pre_reset(struct ata_port *ap)
54 { 0x6F, 1, 0x80, 0x80 } 54 { 0x6F, 1, 0x80, 0x80 }
55 }; 55 };
56 56
57 if (!pci_test_config_bits(pdev, &mpiix_enable_bits[ap->port_no])) { 57 if (!pci_test_config_bits(pdev, &mpiix_enable_bits[ap->port_no]))
58 ata_port_disable(ap); 58 return -ENOENT;
59 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id);
60 return 0;
61 }
62 ap->cbl = ATA_CBL_PATA40; 59 ap->cbl = ATA_CBL_PATA40;
63 return ata_std_prereset(ap); 60 return ata_std_prereset(ap);
64} 61}
diff --git a/drivers/ata/pata_netcell.c b/drivers/ata/pata_netcell.c
index 16cb254cb973..76eb9c90bee1 100644
--- a/drivers/ata/pata_netcell.c
+++ b/drivers/ata/pata_netcell.c
@@ -90,8 +90,7 @@ static const struct ata_port_operations netcell_ops = {
90 .qc_issue = ata_qc_issue_prot, 90 .qc_issue = ata_qc_issue_prot,
91 .data_xfer = ata_pio_data_xfer, 91 .data_xfer = ata_pio_data_xfer,
92 92
93 /* Timeout handling. Special recovery hooks here */ 93 /* IRQ-related hooks */
94 .eng_timeout = ata_eng_timeout,
95 .irq_handler = ata_interrupt, 94 .irq_handler = ata_interrupt,
96 .irq_clear = ata_bmdma_irq_clear, 95 .irq_clear = ata_bmdma_irq_clear,
97 96
diff --git a/drivers/ata/pata_ns87410.c b/drivers/ata/pata_ns87410.c
index 93d6646d2954..2005a95f48f6 100644
--- a/drivers/ata/pata_ns87410.c
+++ b/drivers/ata/pata_ns87410.c
@@ -45,11 +45,8 @@ static int ns87410_pre_reset(struct ata_port *ap)
45 { 0x47, 1, 0x08, 0x08 } 45 { 0x47, 1, 0x08, 0x08 }
46 }; 46 };
47 47
48 if (!pci_test_config_bits(pdev, &ns87410_enable_bits[ap->port_no])) { 48 if (!pci_test_config_bits(pdev, &ns87410_enable_bits[ap->port_no]))
49 ata_port_disable(ap); 49 return -ENOENT;
50 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id);
51 return 0;
52 }
53 ap->cbl = ATA_CBL_PATA40; 50 ap->cbl = ATA_CBL_PATA40;
54 return ata_std_prereset(ap); 51 return ata_std_prereset(ap);
55} 52}
@@ -179,7 +176,7 @@ static struct ata_port_operations ns87410_port_ops = {
179 176
180 .qc_prep = ata_qc_prep, 177 .qc_prep = ata_qc_prep,
181 .qc_issue = ns87410_qc_issue_prot, 178 .qc_issue = ns87410_qc_issue_prot,
182 .eng_timeout = ata_eng_timeout, 179
183 .data_xfer = ata_pio_data_xfer, 180 .data_xfer = ata_pio_data_xfer,
184 181
185 .irq_handler = ata_interrupt, 182 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_oldpiix.c b/drivers/ata/pata_oldpiix.c
index 04c618a2664b..31a285ca88dc 100644
--- a/drivers/ata/pata_oldpiix.c
+++ b/drivers/ata/pata_oldpiix.c
@@ -25,7 +25,7 @@
25#include <linux/ata.h> 25#include <linux/ata.h>
26 26
27#define DRV_NAME "pata_oldpiix" 27#define DRV_NAME "pata_oldpiix"
28#define DRV_VERSION "0.5.1" 28#define DRV_VERSION "0.5.2"
29 29
30/** 30/**
31 * oldpiix_pre_reset - probe begin 31 * oldpiix_pre_reset - probe begin
@@ -42,11 +42,8 @@ static int oldpiix_pre_reset(struct ata_port *ap)
42 { 0x43U, 1U, 0x80UL, 0x80UL }, /* port 1 */ 42 { 0x43U, 1U, 0x80UL, 0x80UL }, /* port 1 */
43 }; 43 };
44 44
45 if (!pci_test_config_bits(pdev, &oldpiix_enable_bits[ap->port_no])) { 45 if (!pci_test_config_bits(pdev, &oldpiix_enable_bits[ap->port_no]))
46 ata_port_disable(ap); 46 return -ENOENT;
47 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id);
48 return 0;
49 }
50 ap->cbl = ATA_CBL_PATA40; 47 ap->cbl = ATA_CBL_PATA40;
51 return ata_std_prereset(ap); 48 return ata_std_prereset(ap);
52} 49}
diff --git a/drivers/ata/pata_opti.c b/drivers/ata/pata_opti.c
index c3d01325e0e2..57fe21f3a975 100644
--- a/drivers/ata/pata_opti.c
+++ b/drivers/ata/pata_opti.c
@@ -34,7 +34,7 @@
34#include <linux/libata.h> 34#include <linux/libata.h>
35 35
36#define DRV_NAME "pata_opti" 36#define DRV_NAME "pata_opti"
37#define DRV_VERSION "0.2.4" 37#define DRV_VERSION "0.2.5"
38 38
39enum { 39enum {
40 READ_REG = 0, /* index of Read cycle timing register */ 40 READ_REG = 0, /* index of Read cycle timing register */
@@ -59,11 +59,9 @@ static int opti_pre_reset(struct ata_port *ap)
59 { 0x40, 1, 0x08, 0x00 } 59 { 0x40, 1, 0x08, 0x00 }
60 }; 60 };
61 61
62 if (!pci_test_config_bits(pdev, &opti_enable_bits[ap->port_no])) { 62 if (!pci_test_config_bits(pdev, &opti_enable_bits[ap->port_no]))
63 ata_port_disable(ap); 63 return -ENOENT;
64 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id); 64
65 return 0;
66 }
67 ap->cbl = ATA_CBL_PATA40; 65 ap->cbl = ATA_CBL_PATA40;
68 return ata_std_prereset(ap); 66 return ata_std_prereset(ap);
69} 67}
@@ -229,7 +227,7 @@ static struct ata_port_operations opti_port_ops = {
229 227
230 .qc_prep = ata_qc_prep, 228 .qc_prep = ata_qc_prep,
231 .qc_issue = ata_qc_issue_prot, 229 .qc_issue = ata_qc_issue_prot,
232 .eng_timeout = ata_eng_timeout, 230
233 .data_xfer = ata_pio_data_xfer, 231 .data_xfer = ata_pio_data_xfer,
234 232
235 .irq_handler = ata_interrupt, 233 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_optidma.c b/drivers/ata/pata_optidma.c
index 177a455f4251..7296a20cd107 100644
--- a/drivers/ata/pata_optidma.c
+++ b/drivers/ata/pata_optidma.c
@@ -33,7 +33,7 @@
33#include <linux/libata.h> 33#include <linux/libata.h>
34 34
35#define DRV_NAME "pata_optidma" 35#define DRV_NAME "pata_optidma"
36#define DRV_VERSION "0.2.1" 36#define DRV_VERSION "0.2.2"
37 37
38enum { 38enum {
39 READ_REG = 0, /* index of Read cycle timing register */ 39 READ_REG = 0, /* index of Read cycle timing register */
@@ -59,11 +59,9 @@ static int optidma_pre_reset(struct ata_port *ap)
59 0x40, 1, 0x08, 0x00 59 0x40, 1, 0x08, 0x00
60 }; 60 };
61 61
62 if (ap->port_no && !pci_test_config_bits(pdev, &optidma_enable_bits)) { 62 if (ap->port_no && !pci_test_config_bits(pdev, &optidma_enable_bits))
63 ata_port_disable(ap); 63 return -ENOENT;
64 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id); 64
65 return 0;
66 }
67 ap->cbl = ATA_CBL_PATA40; 65 ap->cbl = ATA_CBL_PATA40;
68 return ata_std_prereset(ap); 66 return ata_std_prereset(ap);
69} 67}
@@ -388,7 +386,7 @@ static struct ata_port_operations optidma_port_ops = {
388 386
389 .qc_prep = ata_qc_prep, 387 .qc_prep = ata_qc_prep,
390 .qc_issue = ata_qc_issue_prot, 388 .qc_issue = ata_qc_issue_prot,
391 .eng_timeout = ata_eng_timeout, 389
392 .data_xfer = ata_pio_data_xfer, 390 .data_xfer = ata_pio_data_xfer,
393 391
394 .irq_handler = ata_interrupt, 392 .irq_handler = ata_interrupt,
@@ -423,7 +421,7 @@ static struct ata_port_operations optiplus_port_ops = {
423 421
424 .qc_prep = ata_qc_prep, 422 .qc_prep = ata_qc_prep,
425 .qc_issue = ata_qc_issue_prot, 423 .qc_issue = ata_qc_issue_prot,
426 .eng_timeout = ata_eng_timeout, 424
427 .data_xfer = ata_pio_data_xfer, 425 .data_xfer = ata_pio_data_xfer,
428 426
429 .irq_handler = ata_interrupt, 427 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c
index 62b25cda409b..cb501e145a42 100644
--- a/drivers/ata/pata_pcmcia.c
+++ b/drivers/ata/pata_pcmcia.c
@@ -87,7 +87,7 @@ static struct ata_port_operations pcmcia_port_ops = {
87 87
88 .qc_prep = ata_qc_prep, 88 .qc_prep = ata_qc_prep,
89 .qc_issue = ata_qc_issue_prot, 89 .qc_issue = ata_qc_issue_prot,
90 .eng_timeout = ata_eng_timeout, 90
91 .data_xfer = ata_pio_data_xfer_noirq, 91 .data_xfer = ata_pio_data_xfer_noirq,
92 92
93 .irq_handler = ata_interrupt, 93 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c
index 31ab9c886209..bd4ed6734edc 100644
--- a/drivers/ata/pata_pdc2027x.c
+++ b/drivers/ata/pata_pdc2027x.c
@@ -36,7 +36,7 @@
36#include <asm/io.h> 36#include <asm/io.h>
37 37
38#define DRV_NAME "pata_pdc2027x" 38#define DRV_NAME "pata_pdc2027x"
39#define DRV_VERSION "0.74-ac3" 39#define DRV_VERSION "0.74-ac5"
40#undef PDC_DEBUG 40#undef PDC_DEBUG
41 41
42#ifdef PDC_DEBUG 42#ifdef PDC_DEBUG
@@ -311,10 +311,8 @@ static inline int pdc2027x_port_enabled(struct ata_port *ap)
311static int pdc2027x_prereset(struct ata_port *ap) 311static int pdc2027x_prereset(struct ata_port *ap)
312{ 312{
313 /* Check whether port enabled */ 313 /* Check whether port enabled */
314 if (!pdc2027x_port_enabled(ap)) { 314 if (!pdc2027x_port_enabled(ap))
315 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id); 315 return -ENOENT;
316 return 0;
317 }
318 pdc2027x_cbl_detect(ap); 316 pdc2027x_cbl_detect(ap);
319 return ata_std_prereset(ap); 317 return ata_std_prereset(ap);
320} 318}
diff --git a/drivers/ata/pata_qdi.c b/drivers/ata/pata_qdi.c
index 35cfdf0ac3f0..7977f471d5e9 100644
--- a/drivers/ata/pata_qdi.c
+++ b/drivers/ata/pata_qdi.c
@@ -184,7 +184,7 @@ static struct ata_port_operations qdi6500_port_ops = {
184 184
185 .qc_prep = ata_qc_prep, 185 .qc_prep = ata_qc_prep,
186 .qc_issue = qdi_qc_issue_prot, 186 .qc_issue = qdi_qc_issue_prot,
187 .eng_timeout = ata_eng_timeout, 187
188 .data_xfer = qdi_data_xfer, 188 .data_xfer = qdi_data_xfer,
189 189
190 .irq_handler = ata_interrupt, 190 .irq_handler = ata_interrupt,
@@ -212,7 +212,7 @@ static struct ata_port_operations qdi6580_port_ops = {
212 212
213 .qc_prep = ata_qc_prep, 213 .qc_prep = ata_qc_prep,
214 .qc_issue = qdi_qc_issue_prot, 214 .qc_issue = qdi_qc_issue_prot,
215 .eng_timeout = ata_eng_timeout, 215
216 .data_xfer = qdi_data_xfer, 216 .data_xfer = qdi_data_xfer,
217 217
218 .irq_handler = ata_interrupt, 218 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_radisys.c b/drivers/ata/pata_radisys.c
index 277f8411b521..c20bcf43ed6d 100644
--- a/drivers/ata/pata_radisys.c
+++ b/drivers/ata/pata_radisys.c
@@ -255,8 +255,6 @@ static const struct ata_port_operations radisys_pata_ops = {
255 .qc_issue = radisys_qc_issue_prot, 255 .qc_issue = radisys_qc_issue_prot,
256 .data_xfer = ata_pio_data_xfer, 256 .data_xfer = ata_pio_data_xfer,
257 257
258 .eng_timeout = ata_eng_timeout,
259
260 .irq_handler = ata_interrupt, 258 .irq_handler = ata_interrupt,
261 .irq_clear = ata_bmdma_irq_clear, 259 .irq_clear = ata_bmdma_irq_clear,
262 260
diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c
index 3c6d84fd4312..eccc6fd45032 100644
--- a/drivers/ata/pata_rz1000.c
+++ b/drivers/ata/pata_rz1000.c
@@ -112,7 +112,7 @@ static struct ata_port_operations rz1000_port_ops = {
112 112
113 .qc_prep = ata_qc_prep, 113 .qc_prep = ata_qc_prep,
114 .qc_issue = ata_qc_issue_prot, 114 .qc_issue = ata_qc_issue_prot,
115 .eng_timeout = ata_eng_timeout, 115
116 .data_xfer = ata_pio_data_xfer, 116 .data_xfer = ata_pio_data_xfer,
117 117
118 .freeze = ata_bmdma_freeze, 118 .freeze = ata_bmdma_freeze,
diff --git a/drivers/ata/pata_sc1200.c b/drivers/ata/pata_sc1200.c
index 4166c1a8a9e8..107e6cd3dc0d 100644
--- a/drivers/ata/pata_sc1200.c
+++ b/drivers/ata/pata_sc1200.c
@@ -217,7 +217,7 @@ static struct ata_port_operations sc1200_port_ops = {
217 217
218 .qc_prep = ata_qc_prep, 218 .qc_prep = ata_qc_prep,
219 .qc_issue = sc1200_qc_issue_prot, 219 .qc_issue = sc1200_qc_issue_prot,
220 .eng_timeout = ata_eng_timeout, 220
221 .data_xfer = ata_pio_data_xfer, 221 .data_xfer = ata_pio_data_xfer,
222 222
223 .irq_handler = ata_interrupt, 223 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_serverworks.c b/drivers/ata/pata_serverworks.c
index af456113c55d..a5c8d7e121d1 100644
--- a/drivers/ata/pata_serverworks.c
+++ b/drivers/ata/pata_serverworks.c
@@ -41,7 +41,7 @@
41#include <linux/libata.h> 41#include <linux/libata.h>
42 42
43#define DRV_NAME "pata_serverworks" 43#define DRV_NAME "pata_serverworks"
44#define DRV_VERSION "0.3.6" 44#define DRV_VERSION "0.3.7"
45 45
46#define SVWKS_CSB5_REVISION_NEW 0x92 /* min PCI_REVISION_ID for UDMA5 (A2.0) */ 46#define SVWKS_CSB5_REVISION_NEW 0x92 /* min PCI_REVISION_ID for UDMA5 (A2.0) */
47#define SVWKS_CSB6_REVISION 0xa0 /* min PCI_REVISION_ID for UDMA4 (A1.0) */ 47#define SVWKS_CSB6_REVISION 0xa0 /* min PCI_REVISION_ID for UDMA4 (A1.0) */
@@ -128,7 +128,7 @@ static struct sv_cable_table cable_detect[] = {
128 { PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_VENDOR_ID_DELL, dell_cable }, 128 { PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_VENDOR_ID_DELL, dell_cable },
129 { PCI_DEVICE_ID_SERVERWORKS_CSB6IDE, PCI_VENDOR_ID_DELL, dell_cable }, 129 { PCI_DEVICE_ID_SERVERWORKS_CSB6IDE, PCI_VENDOR_ID_DELL, dell_cable },
130 { PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_VENDOR_ID_SUN, sun_cable }, 130 { PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_VENDOR_ID_SUN, sun_cable },
131 { PCI_DEVICE_ID_SERVERWORKS_OSB4, PCI_ANY_ID, osb4_cable }, 131 { PCI_DEVICE_ID_SERVERWORKS_OSB4IDE, PCI_ANY_ID, osb4_cable },
132 { PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_ANY_ID, csb_cable }, 132 { PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_ANY_ID, csb_cable },
133 { PCI_DEVICE_ID_SERVERWORKS_CSB6IDE, PCI_ANY_ID, csb_cable }, 133 { PCI_DEVICE_ID_SERVERWORKS_CSB6IDE, PCI_ANY_ID, csb_cable },
134 { PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2, PCI_ANY_ID, csb_cable }, 134 { PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2, PCI_ANY_ID, csb_cable },
@@ -352,10 +352,12 @@ static struct ata_port_operations serverworks_osb4_port_ops = {
352 352
353 .qc_prep = ata_qc_prep, 353 .qc_prep = ata_qc_prep,
354 .qc_issue = ata_qc_issue_prot, 354 .qc_issue = ata_qc_issue_prot,
355 .eng_timeout = ata_eng_timeout, 355
356 .data_xfer = ata_pio_data_xfer, 356 .data_xfer = ata_pio_data_xfer,
357 357
358 .irq_handler = ata_interrupt, 358 .irq_handler = ata_interrupt,
359 .irq_clear = ata_bmdma_irq_clear,
360
359 .port_start = ata_port_start, 361 .port_start = ata_port_start,
360 .port_stop = ata_port_stop, 362 .port_stop = ata_port_stop,
361 .host_stop = ata_host_stop 363 .host_stop = ata_host_stop
@@ -385,10 +387,12 @@ static struct ata_port_operations serverworks_csb_port_ops = {
385 387
386 .qc_prep = ata_qc_prep, 388 .qc_prep = ata_qc_prep,
387 .qc_issue = ata_qc_issue_prot, 389 .qc_issue = ata_qc_issue_prot,
388 .eng_timeout = ata_eng_timeout, 390
389 .data_xfer = ata_pio_data_xfer, 391 .data_xfer = ata_pio_data_xfer,
390 392
391 .irq_handler = ata_interrupt, 393 .irq_handler = ata_interrupt,
394 .irq_clear = ata_bmdma_irq_clear,
395
392 .port_start = ata_port_start, 396 .port_start = ata_port_start,
393 .port_stop = ata_port_stop, 397 .port_stop = ata_port_stop,
394 .host_stop = ata_host_stop 398 .host_stop = ata_host_stop
diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
index 8f7db9638d0a..c8b2e26db70d 100644
--- a/drivers/ata/pata_sil680.c
+++ b/drivers/ata/pata_sil680.c
@@ -251,7 +251,7 @@ static struct ata_port_operations sil680_port_ops = {
251 251
252 .qc_prep = ata_qc_prep, 252 .qc_prep = ata_qc_prep,
253 .qc_issue = ata_qc_issue_prot, 253 .qc_issue = ata_qc_issue_prot,
254 .eng_timeout = ata_eng_timeout, 254
255 .data_xfer = ata_pio_data_xfer, 255 .data_xfer = ata_pio_data_xfer,
256 256
257 .irq_handler = ata_interrupt, 257 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c
index 2e555168b431..17791e2785f9 100644
--- a/drivers/ata/pata_sis.c
+++ b/drivers/ata/pata_sis.c
@@ -34,7 +34,7 @@
34#include <linux/ata.h> 34#include <linux/ata.h>
35 35
36#define DRV_NAME "pata_sis" 36#define DRV_NAME "pata_sis"
37#define DRV_VERSION "0.4.3" 37#define DRV_VERSION "0.4.4"
38 38
39struct sis_chipset { 39struct sis_chipset {
40 u16 device; /* PCI host ID */ 40 u16 device; /* PCI host ID */
@@ -74,11 +74,9 @@ static int sis_133_pre_reset(struct ata_port *ap)
74 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 74 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
75 u16 tmp; 75 u16 tmp;
76 76
77 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no])) { 77 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no]))
78 ata_port_disable(ap); 78 return -ENOENT;
79 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id); 79
80 return 0;
81 }
82 /* The top bit of this register is the cable detect bit */ 80 /* The top bit of this register is the cable detect bit */
83 pci_read_config_word(pdev, 0x50 + 2 * ap->port_no, &tmp); 81 pci_read_config_word(pdev, 0x50 + 2 * ap->port_no, &tmp);
84 if (tmp & 0x8000) 82 if (tmp & 0x8000)
@@ -575,8 +573,6 @@ static const struct ata_port_operations sis_133_ops = {
575 .qc_issue = ata_qc_issue_prot, 573 .qc_issue = ata_qc_issue_prot,
576 .data_xfer = ata_pio_data_xfer, 574 .data_xfer = ata_pio_data_xfer,
577 575
578 .eng_timeout = ata_eng_timeout,
579
580 .irq_handler = ata_interrupt, 576 .irq_handler = ata_interrupt,
581 .irq_clear = ata_bmdma_irq_clear, 577 .irq_clear = ata_bmdma_irq_clear,
582 578
@@ -610,8 +606,6 @@ static const struct ata_port_operations sis_133_early_ops = {
610 .qc_issue = ata_qc_issue_prot, 606 .qc_issue = ata_qc_issue_prot,
611 .data_xfer = ata_pio_data_xfer, 607 .data_xfer = ata_pio_data_xfer,
612 608
613 .eng_timeout = ata_eng_timeout,
614
615 .irq_handler = ata_interrupt, 609 .irq_handler = ata_interrupt,
616 .irq_clear = ata_bmdma_irq_clear, 610 .irq_clear = ata_bmdma_irq_clear,
617 611
@@ -646,8 +640,6 @@ static const struct ata_port_operations sis_100_ops = {
646 .qc_issue = ata_qc_issue_prot, 640 .qc_issue = ata_qc_issue_prot,
647 .data_xfer = ata_pio_data_xfer, 641 .data_xfer = ata_pio_data_xfer,
648 642
649 .eng_timeout = ata_eng_timeout,
650
651 .irq_handler = ata_interrupt, 643 .irq_handler = ata_interrupt,
652 .irq_clear = ata_bmdma_irq_clear, 644 .irq_clear = ata_bmdma_irq_clear,
653 645
@@ -681,8 +673,6 @@ static const struct ata_port_operations sis_66_ops = {
681 .qc_issue = ata_qc_issue_prot, 673 .qc_issue = ata_qc_issue_prot,
682 .data_xfer = ata_pio_data_xfer, 674 .data_xfer = ata_pio_data_xfer,
683 675
684 .eng_timeout = ata_eng_timeout,
685
686 .irq_handler = ata_interrupt, 676 .irq_handler = ata_interrupt,
687 .irq_clear = ata_bmdma_irq_clear, 677 .irq_clear = ata_bmdma_irq_clear,
688 678
@@ -716,8 +706,6 @@ static const struct ata_port_operations sis_old_ops = {
716 .qc_issue = ata_qc_issue_prot, 706 .qc_issue = ata_qc_issue_prot,
717 .data_xfer = ata_pio_data_xfer, 707 .data_xfer = ata_pio_data_xfer,
718 708
719 .eng_timeout = ata_eng_timeout,
720
721 .irq_handler = ata_interrupt, 709 .irq_handler = ata_interrupt,
722 .irq_clear = ata_bmdma_irq_clear, 710 .irq_clear = ata_bmdma_irq_clear,
723 711
diff --git a/drivers/ata/pata_sl82c105.c b/drivers/ata/pata_sl82c105.c
index f8499786917a..5b762acc5687 100644
--- a/drivers/ata/pata_sl82c105.c
+++ b/drivers/ata/pata_sl82c105.c
@@ -19,7 +19,7 @@
19#include <linux/libata.h> 19#include <linux/libata.h>
20 20
21#define DRV_NAME "pata_sl82c105" 21#define DRV_NAME "pata_sl82c105"
22#define DRV_VERSION "0.2.2" 22#define DRV_VERSION "0.2.3"
23 23
24enum { 24enum {
25 /* 25 /*
@@ -49,11 +49,8 @@ static int sl82c105_pre_reset(struct ata_port *ap)
49 }; 49 };
50 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 50 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
51 51
52 if (ap->port_no && !pci_test_config_bits(pdev, &sl82c105_enable_bits[ap->port_no])) { 52 if (ap->port_no && !pci_test_config_bits(pdev, &sl82c105_enable_bits[ap->port_no]))
53 ata_port_disable(ap); 53 return -ENOENT;
54 dev_printk(KERN_INFO, &pdev->dev, "port disabled. ignoring.\n");
55 return 0;
56 }
57 ap->cbl = ATA_CBL_PATA40; 54 ap->cbl = ATA_CBL_PATA40;
58 return ata_std_prereset(ap); 55 return ata_std_prereset(ap);
59} 56}
@@ -264,7 +261,7 @@ static struct ata_port_operations sl82c105_port_ops = {
264 261
265 .qc_prep = ata_qc_prep, 262 .qc_prep = ata_qc_prep,
266 .qc_issue = ata_qc_issue_prot, 263 .qc_issue = ata_qc_issue_prot,
267 .eng_timeout = ata_eng_timeout, 264
268 .data_xfer = ata_pio_data_xfer, 265 .data_xfer = ata_pio_data_xfer,
269 266
270 .irq_handler = ata_interrupt, 267 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_triflex.c b/drivers/ata/pata_triflex.c
index 36f788728f3f..a954ed93a40c 100644
--- a/drivers/ata/pata_triflex.c
+++ b/drivers/ata/pata_triflex.c
@@ -46,13 +46,13 @@
46#define DRV_VERSION "0.2.5" 46#define DRV_VERSION "0.2.5"
47 47
48/** 48/**
49 * triflex_probe_init - probe begin 49 * triflex_prereset - probe begin
50 * @ap: ATA port 50 * @ap: ATA port
51 * 51 *
52 * Set up cable type and use generic probe init 52 * Set up cable type and use generic probe init
53 */ 53 */
54 54
55static int triflex_probe_init(struct ata_port *ap) 55static int triflex_prereset(struct ata_port *ap)
56{ 56{
57 static const struct pci_bits triflex_enable_bits[] = { 57 static const struct pci_bits triflex_enable_bits[] = {
58 { 0x80, 1, 0x01, 0x01 }, 58 { 0x80, 1, 0x01, 0x01 },
@@ -61,11 +61,8 @@ static int triflex_probe_init(struct ata_port *ap)
61 61
62 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 62 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
63 63
64 if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no])) { 64 if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no]))
65 ata_port_disable(ap); 65 return -ENOENT;
66 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id);
67 return 0;
68 }
69 ap->cbl = ATA_CBL_PATA40; 66 ap->cbl = ATA_CBL_PATA40;
70 return ata_std_prereset(ap); 67 return ata_std_prereset(ap);
71} 68}
@@ -74,7 +71,7 @@ static int triflex_probe_init(struct ata_port *ap)
74 71
75static void triflex_error_handler(struct ata_port *ap) 72static void triflex_error_handler(struct ata_port *ap)
76{ 73{
77 ata_bmdma_drive_eh(ap, triflex_probe_init, ata_std_softreset, NULL, ata_std_postreset); 74 ata_bmdma_drive_eh(ap, triflex_prereset, ata_std_softreset, NULL, ata_std_postreset);
78} 75}
79 76
80/** 77/**
@@ -221,7 +218,7 @@ static struct ata_port_operations triflex_port_ops = {
221 218
222 .qc_prep = ata_qc_prep, 219 .qc_prep = ata_qc_prep,
223 .qc_issue = ata_qc_issue_prot, 220 .qc_issue = ata_qc_issue_prot,
224 .eng_timeout = ata_eng_timeout, 221
225 .data_xfer = ata_pio_data_xfer, 222 .data_xfer = ata_pio_data_xfer,
226 223
227 .irq_handler = ata_interrupt, 224 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
index 1b2ff133b163..7b5dd2343b9a 100644
--- a/drivers/ata/pata_via.c
+++ b/drivers/ata/pata_via.c
@@ -60,7 +60,7 @@
60#include <linux/libata.h> 60#include <linux/libata.h>
61 61
62#define DRV_NAME "pata_via" 62#define DRV_NAME "pata_via"
63#define DRV_VERSION "0.1.13" 63#define DRV_VERSION "0.1.14"
64 64
65/* 65/*
66 * The following comes directly from Vojtech Pavlik's ide/pci/via82cxxx 66 * The following comes directly from Vojtech Pavlik's ide/pci/via82cxxx
@@ -155,11 +155,8 @@ static int via_pre_reset(struct ata_port *ap)
155 155
156 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 156 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
157 157
158 if (!pci_test_config_bits(pdev, &via_enable_bits[ap->port_no])) { 158 if (!pci_test_config_bits(pdev, &via_enable_bits[ap->port_no]))
159 ata_port_disable(ap); 159 return -ENOENT;
160 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id);
161 return 0;
162 }
163 } 160 }
164 161
165 if ((config->flags & VIA_UDMA) >= VIA_UDMA_66) 162 if ((config->flags & VIA_UDMA) >= VIA_UDMA_66)
@@ -325,7 +322,7 @@ static struct ata_port_operations via_port_ops = {
325 322
326 .qc_prep = ata_qc_prep, 323 .qc_prep = ata_qc_prep,
327 .qc_issue = ata_qc_issue_prot, 324 .qc_issue = ata_qc_issue_prot,
328 .eng_timeout = ata_eng_timeout, 325
329 .data_xfer = ata_pio_data_xfer, 326 .data_xfer = ata_pio_data_xfer,
330 327
331 .irq_handler = ata_interrupt, 328 .irq_handler = ata_interrupt,
@@ -360,7 +357,7 @@ static struct ata_port_operations via_port_ops_noirq = {
360 357
361 .qc_prep = ata_qc_prep, 358 .qc_prep = ata_qc_prep,
362 .qc_issue = ata_qc_issue_prot, 359 .qc_issue = ata_qc_issue_prot,
363 .eng_timeout = ata_eng_timeout, 360
364 .data_xfer = ata_pio_data_xfer_noirq, 361 .data_xfer = ata_pio_data_xfer_noirq,
365 362
366 .irq_handler = ata_interrupt, 363 .irq_handler = ata_interrupt,
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index fdce6e07ecd2..c01496df4a99 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -463,6 +463,7 @@ static const struct ata_port_operations mv_iie_ops = {
463 463
464 .qc_prep = mv_qc_prep_iie, 464 .qc_prep = mv_qc_prep_iie,
465 .qc_issue = mv_qc_issue, 465 .qc_issue = mv_qc_issue,
466 .data_xfer = ata_mmio_data_xfer,
466 467
467 .eng_timeout = mv_eng_timeout, 468 .eng_timeout = mv_eng_timeout,
468 469
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index 27c22feebf30..8cd730fe5dd3 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -484,7 +484,7 @@ static void nv_error_handler(struct ata_port *ap)
484static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 484static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
485{ 485{
486 static int printed_version = 0; 486 static int printed_version = 0;
487 struct ata_port_info *ppi; 487 struct ata_port_info *ppi[2];
488 struct ata_probe_ent *probe_ent; 488 struct ata_probe_ent *probe_ent;
489 int pci_dev_busy = 0; 489 int pci_dev_busy = 0;
490 int rc; 490 int rc;
@@ -520,8 +520,8 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
520 520
521 rc = -ENOMEM; 521 rc = -ENOMEM;
522 522
523 ppi = &nv_port_info[ent->driver_data]; 523 ppi[0] = ppi[1] = &nv_port_info[ent->driver_data];
524 probe_ent = ata_pci_init_native_mode(pdev, &ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 524 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
525 if (!probe_ent) 525 if (!probe_ent)
526 goto err_out_regions; 526 goto err_out_regions;
527 527
diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c
index 9b17375d8056..18d49fff8dc4 100644
--- a/drivers/ata/sata_sis.c
+++ b/drivers/ata/sata_sis.c
@@ -240,7 +240,7 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
240 struct ata_probe_ent *probe_ent = NULL; 240 struct ata_probe_ent *probe_ent = NULL;
241 int rc; 241 int rc;
242 u32 genctl; 242 u32 genctl;
243 struct ata_port_info *ppi; 243 struct ata_port_info *ppi[2];
244 int pci_dev_busy = 0; 244 int pci_dev_busy = 0;
245 u8 pmr; 245 u8 pmr;
246 u8 port2_start; 246 u8 port2_start;
@@ -265,8 +265,8 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
265 if (rc) 265 if (rc)
266 goto err_out_regions; 266 goto err_out_regions;
267 267
268 ppi = &sis_port_info; 268 ppi[0] = ppi[1] = &sis_port_info;
269 probe_ent = ata_pci_init_native_mode(pdev, &ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 269 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
270 if (!probe_ent) { 270 if (!probe_ent) {
271 rc = -ENOMEM; 271 rc = -ENOMEM;
272 goto err_out_regions; 272 goto err_out_regions;
diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c
index 8fc6e800011a..dd76f37be182 100644
--- a/drivers/ata/sata_uli.c
+++ b/drivers/ata/sata_uli.c
@@ -185,7 +185,7 @@ static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
185{ 185{
186 static int printed_version; 186 static int printed_version;
187 struct ata_probe_ent *probe_ent; 187 struct ata_probe_ent *probe_ent;
188 struct ata_port_info *ppi; 188 struct ata_port_info *ppi[2];
189 int rc; 189 int rc;
190 unsigned int board_idx = (unsigned int) ent->driver_data; 190 unsigned int board_idx = (unsigned int) ent->driver_data;
191 int pci_dev_busy = 0; 191 int pci_dev_busy = 0;
@@ -211,8 +211,8 @@ static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
211 if (rc) 211 if (rc)
212 goto err_out_regions; 212 goto err_out_regions;
213 213
214 ppi = &uli_port_info; 214 ppi[0] = ppi[1] = &uli_port_info;
215 probe_ent = ata_pci_init_native_mode(pdev, &ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 215 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
216 if (!probe_ent) { 216 if (!probe_ent) {
217 rc = -ENOMEM; 217 rc = -ENOMEM;
218 goto err_out_regions; 218 goto err_out_regions;
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
index 7f087aef99de..a72a2389a11c 100644
--- a/drivers/ata/sata_via.c
+++ b/drivers/ata/sata_via.c
@@ -318,9 +318,10 @@ static void vt6421_init_addrs(struct ata_probe_ent *probe_ent,
318static struct ata_probe_ent *vt6420_init_probe_ent(struct pci_dev *pdev) 318static struct ata_probe_ent *vt6420_init_probe_ent(struct pci_dev *pdev)
319{ 319{
320 struct ata_probe_ent *probe_ent; 320 struct ata_probe_ent *probe_ent;
321 struct ata_port_info *ppi = &vt6420_port_info; 321 struct ata_port_info *ppi[2];
322 322
323 probe_ent = ata_pci_init_native_mode(pdev, &ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 323 ppi[0] = ppi[1] = &vt6420_port_info;
324 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
324 if (!probe_ent) 325 if (!probe_ent)
325 return NULL; 326 return NULL;
326 327
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index b539e5e75b56..7bbb9eeda235 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -8,7 +8,7 @@ obj-y += power/
8obj-$(CONFIG_ISA) += isa.o 8obj-$(CONFIG_ISA) += isa.o
9obj-$(CONFIG_FW_LOADER) += firmware_class.o 9obj-$(CONFIG_FW_LOADER) += firmware_class.o
10obj-$(CONFIG_NUMA) += node.o 10obj-$(CONFIG_NUMA) += node.o
11obj-$(CONFIG_MEMORY_HOTPLUG) += memory.o 11obj-$(CONFIG_MEMORY_HOTPLUG_SPARSE) += memory.o
12obj-$(CONFIG_SMP) += topology.o 12obj-$(CONFIG_SMP) += topology.o
13obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o 13obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o
14 14
diff --git a/drivers/base/base.h b/drivers/base/base.h
index c3b8dc98b8a7..d26644a59537 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -16,7 +16,7 @@ extern int cpu_dev_init(void);
16extern int attribute_container_init(void); 16extern int attribute_container_init(void);
17 17
18extern int bus_add_device(struct device * dev); 18extern int bus_add_device(struct device * dev);
19extern void bus_attach_device(struct device * dev); 19extern int bus_attach_device(struct device * dev);
20extern void bus_remove_device(struct device * dev); 20extern void bus_remove_device(struct device * dev);
21extern struct bus_type *get_bus(struct bus_type * bus); 21extern struct bus_type *get_bus(struct bus_type * bus);
22extern void put_bus(struct bus_type * bus); 22extern void put_bus(struct bus_type * bus);
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 2e954d07175a..12173d16bea7 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -371,12 +371,20 @@ int bus_add_device(struct device * dev)
371 if (bus) { 371 if (bus) {
372 pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); 372 pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id);
373 error = device_add_attrs(bus, dev); 373 error = device_add_attrs(bus, dev);
374 if (!error) { 374 if (error)
375 sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id); 375 goto out;
376 sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "subsystem"); 376 error = sysfs_create_link(&bus->devices.kobj,
377 sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus"); 377 &dev->kobj, dev->bus_id);
378 } 378 if (error)
379 goto out;
380 error = sysfs_create_link(&dev->kobj,
381 &dev->bus->subsys.kset.kobj, "subsystem");
382 if (error)
383 goto out;
384 error = sysfs_create_link(&dev->kobj,
385 &dev->bus->subsys.kset.kobj, "bus");
379 } 386 }
387out:
380 return error; 388 return error;
381} 389}
382 390
@@ -384,16 +392,24 @@ int bus_add_device(struct device * dev)
384 * bus_attach_device - add device to bus 392 * bus_attach_device - add device to bus
385 * @dev: device tried to attach to a driver 393 * @dev: device tried to attach to a driver
386 * 394 *
395 * - Add device to bus's list of devices.
387 * - Try to attach to driver. 396 * - Try to attach to driver.
388 */ 397 */
389void bus_attach_device(struct device * dev) 398int bus_attach_device(struct device * dev)
390{ 399{
391 struct bus_type * bus = dev->bus; 400 struct bus_type *bus = dev->bus;
401 int ret = 0;
392 402
393 if (bus) { 403 if (bus) {
394 device_attach(dev); 404 dev->is_registered = 1;
395 klist_add_tail(&dev->knode_bus, &bus->klist_devices); 405 ret = device_attach(dev);
406 if (ret >= 0) {
407 klist_add_tail(&dev->knode_bus, &bus->klist_devices);
408 ret = 0;
409 } else
410 dev->is_registered = 0;
396 } 411 }
412 return ret;
397} 413}
398 414
399/** 415/**
@@ -412,7 +428,8 @@ void bus_remove_device(struct device * dev)
412 sysfs_remove_link(&dev->kobj, "bus"); 428 sysfs_remove_link(&dev->kobj, "bus");
413 sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id); 429 sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id);
414 device_remove_attrs(dev->bus, dev); 430 device_remove_attrs(dev->bus, dev);
415 klist_remove(&dev->knode_bus); 431 dev->is_registered = 0;
432 klist_del(&dev->knode_bus);
416 pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id); 433 pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id);
417 device_release_driver(dev); 434 device_release_driver(dev);
418 put_bus(dev->bus); 435 put_bus(dev->bus);
@@ -455,10 +472,17 @@ static void driver_remove_attrs(struct bus_type * bus, struct device_driver * dr
455 * Thanks to drivers making their tables __devinit, we can't allow manual 472 * Thanks to drivers making their tables __devinit, we can't allow manual
456 * bind and unbind from userspace unless CONFIG_HOTPLUG is enabled. 473 * bind and unbind from userspace unless CONFIG_HOTPLUG is enabled.
457 */ 474 */
458static void add_bind_files(struct device_driver *drv) 475static int __must_check add_bind_files(struct device_driver *drv)
459{ 476{
460 driver_create_file(drv, &driver_attr_unbind); 477 int ret;
461 driver_create_file(drv, &driver_attr_bind); 478
479 ret = driver_create_file(drv, &driver_attr_unbind);
480 if (ret == 0) {
481 ret = driver_create_file(drv, &driver_attr_bind);
482 if (ret)
483 driver_remove_file(drv, &driver_attr_unbind);
484 }
485 return ret;
462} 486}
463 487
464static void remove_bind_files(struct device_driver *drv) 488static void remove_bind_files(struct device_driver *drv)
@@ -467,7 +491,7 @@ static void remove_bind_files(struct device_driver *drv)
467 driver_remove_file(drv, &driver_attr_unbind); 491 driver_remove_file(drv, &driver_attr_unbind);
468} 492}
469#else 493#else
470static inline void add_bind_files(struct device_driver *drv) {} 494static inline int add_bind_files(struct device_driver *drv) { return 0; }
471static inline void remove_bind_files(struct device_driver *drv) {} 495static inline void remove_bind_files(struct device_driver *drv) {}
472#endif 496#endif
473 497
@@ -476,7 +500,7 @@ static inline void remove_bind_files(struct device_driver *drv) {}
476 * @drv: driver. 500 * @drv: driver.
477 * 501 *
478 */ 502 */
479int bus_add_driver(struct device_driver * drv) 503int bus_add_driver(struct device_driver *drv)
480{ 504{
481 struct bus_type * bus = get_bus(drv->bus); 505 struct bus_type * bus = get_bus(drv->bus);
482 int error = 0; 506 int error = 0;
@@ -484,27 +508,39 @@ int bus_add_driver(struct device_driver * drv)
484 if (bus) { 508 if (bus) {
485 pr_debug("bus %s: add driver %s\n", bus->name, drv->name); 509 pr_debug("bus %s: add driver %s\n", bus->name, drv->name);
486 error = kobject_set_name(&drv->kobj, "%s", drv->name); 510 error = kobject_set_name(&drv->kobj, "%s", drv->name);
487 if (error) { 511 if (error)
488 put_bus(bus); 512 goto out_put_bus;
489 return error;
490 }
491 drv->kobj.kset = &bus->drivers; 513 drv->kobj.kset = &bus->drivers;
492 if ((error = kobject_register(&drv->kobj))) { 514 if ((error = kobject_register(&drv->kobj)))
493 put_bus(bus); 515 goto out_put_bus;
494 return error;
495 }
496 516
497 driver_attach(drv); 517 error = driver_attach(drv);
518 if (error)
519 goto out_unregister;
498 klist_add_tail(&drv->knode_bus, &bus->klist_drivers); 520 klist_add_tail(&drv->knode_bus, &bus->klist_drivers);
499 module_add_driver(drv->owner, drv); 521 module_add_driver(drv->owner, drv);
500 522
501 driver_add_attrs(bus, drv); 523 error = driver_add_attrs(bus, drv);
502 add_bind_files(drv); 524 if (error) {
525 /* How the hell do we get out of this pickle? Give up */
526 printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n",
527 __FUNCTION__, drv->name);
528 }
529 error = add_bind_files(drv);
530 if (error) {
531 /* Ditto */
532 printk(KERN_ERR "%s: add_bind_files(%s) failed\n",
533 __FUNCTION__, drv->name);
534 }
503 } 535 }
504 return error; 536 return error;
537out_unregister:
538 kobject_unregister(&drv->kobj);
539out_put_bus:
540 put_bus(bus);
541 return error;
505} 542}
506 543
507
508/** 544/**
509 * bus_remove_driver - delete driver from bus's knowledge. 545 * bus_remove_driver - delete driver from bus's knowledge.
510 * @drv: driver. 546 * @drv: driver.
@@ -530,16 +566,21 @@ void bus_remove_driver(struct device_driver * drv)
530 566
531 567
532/* Helper for bus_rescan_devices's iter */ 568/* Helper for bus_rescan_devices's iter */
533static int bus_rescan_devices_helper(struct device *dev, void *data) 569static int __must_check bus_rescan_devices_helper(struct device *dev,
570 void *data)
534{ 571{
572 int ret = 0;
573
535 if (!dev->driver) { 574 if (!dev->driver) {
536 if (dev->parent) /* Needed for USB */ 575 if (dev->parent) /* Needed for USB */
537 down(&dev->parent->sem); 576 down(&dev->parent->sem);
538 device_attach(dev); 577 ret = device_attach(dev);
539 if (dev->parent) 578 if (dev->parent)
540 up(&dev->parent->sem); 579 up(&dev->parent->sem);
580 if (ret > 0)
581 ret = 0;
541 } 582 }
542 return 0; 583 return ret < 0 ? ret : 0;
543} 584}
544 585
545/** 586/**
@@ -550,9 +591,9 @@ static int bus_rescan_devices_helper(struct device *dev, void *data)
550 * attached and rescan it against existing drivers to see if it matches 591 * attached and rescan it against existing drivers to see if it matches
551 * any by calling device_attach() for the unbound devices. 592 * any by calling device_attach() for the unbound devices.
552 */ 593 */
553void bus_rescan_devices(struct bus_type * bus) 594int bus_rescan_devices(struct bus_type * bus)
554{ 595{
555 bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper); 596 return bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper);
556} 597}
557 598
558/** 599/**
@@ -564,7 +605,7 @@ void bus_rescan_devices(struct bus_type * bus)
564 * to use if probing criteria changed during a devices lifetime and 605 * to use if probing criteria changed during a devices lifetime and
565 * driver attachment should change accordingly. 606 * driver attachment should change accordingly.
566 */ 607 */
567void device_reprobe(struct device *dev) 608int device_reprobe(struct device *dev)
568{ 609{
569 if (dev->driver) { 610 if (dev->driver) {
570 if (dev->parent) /* Needed for USB */ 611 if (dev->parent) /* Needed for USB */
@@ -573,14 +614,14 @@ void device_reprobe(struct device *dev)
573 if (dev->parent) 614 if (dev->parent)
574 up(&dev->parent->sem); 615 up(&dev->parent->sem);
575 } 616 }
576 617 return bus_rescan_devices_helper(dev, NULL);
577 bus_rescan_devices_helper(dev, NULL);
578} 618}
579EXPORT_SYMBOL_GPL(device_reprobe); 619EXPORT_SYMBOL_GPL(device_reprobe);
580 620
581struct bus_type * get_bus(struct bus_type * bus) 621struct bus_type *get_bus(struct bus_type *bus)
582{ 622{
583 return bus ? container_of(subsys_get(&bus->subsys), struct bus_type, subsys) : NULL; 623 return bus ? container_of(subsys_get(&bus->subsys),
624 struct bus_type, subsys) : NULL;
584} 625}
585 626
586void put_bus(struct bus_type * bus) 627void put_bus(struct bus_type * bus)
@@ -655,22 +696,6 @@ static void klist_devices_put(struct klist_node *n)
655 put_device(dev); 696 put_device(dev);
656} 697}
657 698
658static void klist_drivers_get(struct klist_node *n)
659{
660 struct device_driver *drv = container_of(n, struct device_driver,
661 knode_bus);
662
663 get_driver(drv);
664}
665
666static void klist_drivers_put(struct klist_node *n)
667{
668 struct device_driver *drv = container_of(n, struct device_driver,
669 knode_bus);
670
671 put_driver(drv);
672}
673
674/** 699/**
675 * bus_register - register a bus with the system. 700 * bus_register - register a bus with the system.
676 * @bus: bus. 701 * @bus: bus.
@@ -706,7 +731,7 @@ int bus_register(struct bus_type * bus)
706 goto bus_drivers_fail; 731 goto bus_drivers_fail;
707 732
708 klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); 733 klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put);
709 klist_init(&bus->klist_drivers, klist_drivers_get, klist_drivers_put); 734 klist_init(&bus->klist_drivers, NULL, NULL);
710 bus_add_attrs(bus); 735 bus_add_attrs(bus);
711 736
712 pr_debug("bus type '%s' registered\n", bus->name); 737 pr_debug("bus type '%s' registered\n", bus->name);
diff --git a/drivers/base/class.c b/drivers/base/class.c
index de8908320f23..b32b77ff2dcd 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -19,6 +19,8 @@
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include "base.h" 20#include "base.h"
21 21
22extern struct subsystem devices_subsys;
23
22#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) 24#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr)
23#define to_class(obj) container_of(obj, struct class, subsys.kset.kobj) 25#define to_class(obj) container_of(obj, struct class, subsys.kset.kobj)
24 26
@@ -197,7 +199,7 @@ static int class_device_create_uevent(struct class_device *class_dev,
197 * Note, the pointer created here is to be destroyed when finished by 199 * Note, the pointer created here is to be destroyed when finished by
198 * making a call to class_destroy(). 200 * making a call to class_destroy().
199 */ 201 */
200struct class *class_create(struct module *owner, char *name) 202struct class *class_create(struct module *owner, const char *name)
201{ 203{
202 struct class *cls; 204 struct class *cls;
203 int retval; 205 int retval;
@@ -226,7 +228,7 @@ error:
226 228
227/** 229/**
228 * class_destroy - destroys a struct class structure 230 * class_destroy - destroys a struct class structure
229 * @cs: pointer to the struct class that is to be destroyed 231 * @cls: pointer to the struct class that is to be destroyed
230 * 232 *
231 * Note, the pointer to be destroyed must have been created with a call 233 * Note, the pointer to be destroyed must have been created with a call
232 * to class_create(). 234 * to class_create().
@@ -361,7 +363,7 @@ static int class_uevent(struct kset *kset, struct kobject *kobj, char **envp,
361 pr_debug("%s - name = %s\n", __FUNCTION__, class_dev->class_id); 363 pr_debug("%s - name = %s\n", __FUNCTION__, class_dev->class_id);
362 364
363 if (class_dev->dev) { 365 if (class_dev->dev) {
364 /* add physical device, backing this device */ 366 /* add device, backing this class device (deprecated) */
365 struct device *dev = class_dev->dev; 367 struct device *dev = class_dev->dev;
366 char *path = kobject_get_path(&dev->kobj, GFP_KERNEL); 368 char *path = kobject_get_path(&dev->kobj, GFP_KERNEL);
367 369
@@ -656,9 +658,9 @@ int class_device_register(struct class_device *class_dev)
656 658
657/** 659/**
658 * class_device_create - creates a class device and registers it with sysfs 660 * class_device_create - creates a class device and registers it with sysfs
659 * @cs: pointer to the struct class that this device should be registered to. 661 * @cls: pointer to the struct class that this device should be registered to.
660 * @parent: pointer to the parent struct class_device of this new device, if any. 662 * @parent: pointer to the parent struct class_device of this new device, if any.
661 * @dev: the dev_t for the char device to be added. 663 * @devt: the dev_t for the char device to be added.
662 * @device: a pointer to a struct device that is assiociated with this class device. 664 * @device: a pointer to a struct device that is assiociated with this class device.
663 * @fmt: string for the class device's name 665 * @fmt: string for the class device's name
664 * 666 *
@@ -679,7 +681,8 @@ int class_device_register(struct class_device *class_dev)
679struct class_device *class_device_create(struct class *cls, 681struct class_device *class_device_create(struct class *cls,
680 struct class_device *parent, 682 struct class_device *parent,
681 dev_t devt, 683 dev_t devt,
682 struct device *device, char *fmt, ...) 684 struct device *device,
685 const char *fmt, ...)
683{ 686{
684 va_list args; 687 va_list args;
685 struct class_device *class_dev = NULL; 688 struct class_device *class_dev = NULL;
@@ -763,7 +766,7 @@ void class_device_unregister(struct class_device *class_dev)
763/** 766/**
764 * class_device_destroy - removes a class device that was created with class_device_create() 767 * class_device_destroy - removes a class device that was created with class_device_create()
765 * @cls: the pointer to the struct class that this device was registered * with. 768 * @cls: the pointer to the struct class that this device was registered * with.
766 * @dev: the dev_t of the device that was previously registered. 769 * @devt: the dev_t of the device that was previously registered.
767 * 770 *
768 * This call unregisters and cleans up a class device that was created with a 771 * This call unregisters and cleans up a class device that was created with a
769 * call to class_device_create() 772 * call to class_device_create()
@@ -839,6 +842,7 @@ int class_interface_register(struct class_interface *class_intf)
839{ 842{
840 struct class *parent; 843 struct class *parent;
841 struct class_device *class_dev; 844 struct class_device *class_dev;
845 struct device *dev;
842 846
843 if (!class_intf || !class_intf->class) 847 if (!class_intf || !class_intf->class)
844 return -ENODEV; 848 return -ENODEV;
@@ -853,6 +857,10 @@ int class_interface_register(struct class_interface *class_intf)
853 list_for_each_entry(class_dev, &parent->children, node) 857 list_for_each_entry(class_dev, &parent->children, node)
854 class_intf->add(class_dev, class_intf); 858 class_intf->add(class_dev, class_intf);
855 } 859 }
860 if (class_intf->add_dev) {
861 list_for_each_entry(dev, &parent->devices, node)
862 class_intf->add_dev(dev, class_intf);
863 }
856 up(&parent->sem); 864 up(&parent->sem);
857 865
858 return 0; 866 return 0;
@@ -862,6 +870,7 @@ void class_interface_unregister(struct class_interface *class_intf)
862{ 870{
863 struct class * parent = class_intf->class; 871 struct class * parent = class_intf->class;
864 struct class_device *class_dev; 872 struct class_device *class_dev;
873 struct device *dev;
865 874
866 if (!parent) 875 if (!parent)
867 return; 876 return;
@@ -872,12 +881,31 @@ void class_interface_unregister(struct class_interface *class_intf)
872 list_for_each_entry(class_dev, &parent->children, node) 881 list_for_each_entry(class_dev, &parent->children, node)
873 class_intf->remove(class_dev, class_intf); 882 class_intf->remove(class_dev, class_intf);
874 } 883 }
884 if (class_intf->remove_dev) {
885 list_for_each_entry(dev, &parent->devices, node)
886 class_intf->remove_dev(dev, class_intf);
887 }
875 up(&parent->sem); 888 up(&parent->sem);
876 889
877 class_put(parent); 890 class_put(parent);
878} 891}
879 892
893int virtual_device_parent(struct device *dev)
894{
895 if (!dev->class)
896 return -ENODEV;
897
898 if (!dev->class->virtual_dir) {
899 static struct kobject *virtual_dir = NULL;
900
901 if (!virtual_dir)
902 virtual_dir = kobject_add_dir(&devices_subsys.kset.kobj, "virtual");
903 dev->class->virtual_dir = kobject_add_dir(virtual_dir, dev->class->name);
904 }
880 905
906 dev->kobj.parent = dev->class->virtual_dir;
907 return 0;
908}
881 909
882int __init classes_init(void) 910int __init classes_init(void)
883{ 911{
diff --git a/drivers/base/core.c b/drivers/base/core.c
index be6b5bc0677d..b224bb43ff63 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3,6 +3,8 @@
3 * 3 *
4 * Copyright (c) 2002-3 Patrick Mochel 4 * Copyright (c) 2002-3 Patrick Mochel
5 * Copyright (c) 2002-3 Open Source Development Labs 5 * Copyright (c) 2002-3 Open Source Development Labs
6 * Copyright (c) 2006 Greg Kroah-Hartman <gregkh@suse.de>
7 * Copyright (c) 2006 Novell, Inc.
6 * 8 *
7 * This file is released under the GPLv2 9 * This file is released under the GPLv2
8 * 10 *
@@ -92,6 +94,8 @@ static void device_release(struct kobject * kobj)
92 94
93 if (dev->release) 95 if (dev->release)
94 dev->release(dev); 96 dev->release(dev);
97 else if (dev->class && dev->class->dev_release)
98 dev->class->dev_release(dev);
95 else { 99 else {
96 printk(KERN_ERR "Device '%s' does not have a release() function, " 100 printk(KERN_ERR "Device '%s' does not have a release() function, "
97 "it is broken and must be fixed.\n", 101 "it is broken and must be fixed.\n",
@@ -149,17 +153,21 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp,
149 "MINOR=%u", MINOR(dev->devt)); 153 "MINOR=%u", MINOR(dev->devt));
150 } 154 }
151 155
152 /* add bus name of physical device */ 156 /* add bus name (same as SUBSYSTEM, deprecated) */
153 if (dev->bus) 157 if (dev->bus)
154 add_uevent_var(envp, num_envp, &i, 158 add_uevent_var(envp, num_envp, &i,
155 buffer, buffer_size, &length, 159 buffer, buffer_size, &length,
156 "PHYSDEVBUS=%s", dev->bus->name); 160 "PHYSDEVBUS=%s", dev->bus->name);
157 161
158 /* add driver name of physical device */ 162 /* add driver name (PHYSDEV* values are deprecated)*/
159 if (dev->driver) 163 if (dev->driver) {
164 add_uevent_var(envp, num_envp, &i,
165 buffer, buffer_size, &length,
166 "DRIVER=%s", dev->driver->name);
160 add_uevent_var(envp, num_envp, &i, 167 add_uevent_var(envp, num_envp, &i,
161 buffer, buffer_size, &length, 168 buffer, buffer_size, &length,
162 "PHYSDEVDRIVER=%s", dev->driver->name); 169 "PHYSDEVDRIVER=%s", dev->driver->name);
170 }
163 171
164 /* terminate, set to next free slot, shrink available space */ 172 /* terminate, set to next free slot, shrink available space */
165 envp[i] = NULL; 173 envp[i] = NULL;
@@ -177,6 +185,15 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp,
177 } 185 }
178 } 186 }
179 187
188 if (dev->class && dev->class->dev_uevent) {
189 /* have the class specific function add its stuff */
190 retval = dev->class->dev_uevent(dev, envp, num_envp, buffer, buffer_size);
191 if (retval) {
192 pr_debug("%s - dev_uevent() returned %d\n",
193 __FUNCTION__, retval);
194 }
195 }
196
180 return retval; 197 return retval;
181} 198}
182 199
@@ -193,6 +210,72 @@ static ssize_t store_uevent(struct device *dev, struct device_attribute *attr,
193 return count; 210 return count;
194} 211}
195 212
213static int device_add_groups(struct device *dev)
214{
215 int i;
216 int error = 0;
217
218 if (dev->groups) {
219 for (i = 0; dev->groups[i]; i++) {
220 error = sysfs_create_group(&dev->kobj, dev->groups[i]);
221 if (error) {
222 while (--i >= 0)
223 sysfs_remove_group(&dev->kobj, dev->groups[i]);
224 goto out;
225 }
226 }
227 }
228out:
229 return error;
230}
231
232static void device_remove_groups(struct device *dev)
233{
234 int i;
235 if (dev->groups) {
236 for (i = 0; dev->groups[i]; i++) {
237 sysfs_remove_group(&dev->kobj, dev->groups[i]);
238 }
239 }
240}
241
242static int device_add_attrs(struct device *dev)
243{
244 struct class *class = dev->class;
245 int error = 0;
246 int i;
247
248 if (!class)
249 return 0;
250
251 if (class->dev_attrs) {
252 for (i = 0; attr_name(class->dev_attrs[i]); i++) {
253 error = device_create_file(dev, &class->dev_attrs[i]);
254 if (error)
255 break;
256 }
257 }
258 if (error)
259 while (--i >= 0)
260 device_remove_file(dev, &class->dev_attrs[i]);
261 return error;
262}
263
264static void device_remove_attrs(struct device *dev)
265{
266 struct class *class = dev->class;
267 int i;
268
269 if (!class)
270 return;
271
272 if (class->dev_attrs) {
273 for (i = 0; attr_name(class->dev_attrs[i]); i++)
274 device_remove_file(dev, &class->dev_attrs[i]);
275 }
276}
277
278
196static ssize_t show_dev(struct device *dev, struct device_attribute *attr, 279static ssize_t show_dev(struct device *dev, struct device_attribute *attr,
197 char *buf) 280 char *buf)
198{ 281{
@@ -236,6 +319,32 @@ void device_remove_file(struct device * dev, struct device_attribute * attr)
236 } 319 }
237} 320}
238 321
322/**
323 * device_create_bin_file - create sysfs binary attribute file for device.
324 * @dev: device.
325 * @attr: device binary attribute descriptor.
326 */
327int device_create_bin_file(struct device *dev, struct bin_attribute *attr)
328{
329 int error = -EINVAL;
330 if (dev)
331 error = sysfs_create_bin_file(&dev->kobj, attr);
332 return error;
333}
334EXPORT_SYMBOL_GPL(device_create_bin_file);
335
336/**
337 * device_remove_bin_file - remove sysfs binary attribute file
338 * @dev: device.
339 * @attr: device binary attribute descriptor.
340 */
341void device_remove_bin_file(struct device *dev, struct bin_attribute *attr)
342{
343 if (dev)
344 sysfs_remove_bin_file(&dev->kobj, attr);
345}
346EXPORT_SYMBOL_GPL(device_remove_bin_file);
347
239static void klist_children_get(struct klist_node *n) 348static void klist_children_get(struct klist_node *n)
240{ 349{
241 struct device *dev = container_of(n, struct device, knode_parent); 350 struct device *dev = container_of(n, struct device, knode_parent);
@@ -289,12 +398,20 @@ int device_add(struct device *dev)
289{ 398{
290 struct device *parent = NULL; 399 struct device *parent = NULL;
291 char *class_name = NULL; 400 char *class_name = NULL;
401 struct class_interface *class_intf;
292 int error = -EINVAL; 402 int error = -EINVAL;
293 403
294 dev = get_device(dev); 404 dev = get_device(dev);
295 if (!dev || !strlen(dev->bus_id)) 405 if (!dev || !strlen(dev->bus_id))
296 goto Error; 406 goto Error;
297 407
408 /* if this is a class device, and has no parent, create one */
409 if ((dev->class) && (dev->parent == NULL)) {
410 error = virtual_device_parent(dev);
411 if (error)
412 goto Error;
413 }
414
298 parent = get_device(dev->parent); 415 parent = get_device(dev->parent);
299 416
300 pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id); 417 pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id);
@@ -307,6 +424,10 @@ int device_add(struct device *dev)
307 if ((error = kobject_add(&dev->kobj))) 424 if ((error = kobject_add(&dev->kobj)))
308 goto Error; 425 goto Error;
309 426
427 /* notify platform of device entry */
428 if (platform_notify)
429 platform_notify(dev);
430
310 dev->uevent_attr.attr.name = "uevent"; 431 dev->uevent_attr.attr.name = "uevent";
311 dev->uevent_attr.attr.mode = S_IWUSR; 432 dev->uevent_attr.attr.mode = S_IWUSR;
312 if (dev->driver) 433 if (dev->driver)
@@ -340,12 +461,17 @@ int device_add(struct device *dev)
340 "subsystem"); 461 "subsystem");
341 sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj, 462 sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj,
342 dev->bus_id); 463 dev->bus_id);
343 464 if (parent) {
344 sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device"); 465 sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device");
345 class_name = make_class_name(dev->class->name, &dev->kobj); 466 class_name = make_class_name(dev->class->name, &dev->kobj);
346 sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name); 467 sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name);
468 }
347 } 469 }
348 470
471 if ((error = device_add_attrs(dev)))
472 goto AttrsError;
473 if ((error = device_add_groups(dev)))
474 goto GroupError;
349 if ((error = device_pm_add(dev))) 475 if ((error = device_pm_add(dev)))
350 goto PMError; 476 goto PMError;
351 if ((error = bus_add_device(dev))) 477 if ((error = bus_add_device(dev)))
@@ -356,15 +482,16 @@ int device_add(struct device *dev)
356 klist_add_tail(&dev->knode_parent, &parent->klist_children); 482 klist_add_tail(&dev->knode_parent, &parent->klist_children);
357 483
358 if (dev->class) { 484 if (dev->class) {
359 /* tie the class to the device */
360 down(&dev->class->sem); 485 down(&dev->class->sem);
486 /* tie the class to the device */
361 list_add_tail(&dev->node, &dev->class->devices); 487 list_add_tail(&dev->node, &dev->class->devices);
488
489 /* notify any interfaces that the device is here */
490 list_for_each_entry(class_intf, &dev->class->interfaces, node)
491 if (class_intf->add_dev)
492 class_intf->add_dev(dev, class_intf);
362 up(&dev->class->sem); 493 up(&dev->class->sem);
363 } 494 }
364
365 /* notify platform of device entry */
366 if (platform_notify)
367 platform_notify(dev);
368 Done: 495 Done:
369 kfree(class_name); 496 kfree(class_name);
370 put_device(dev); 497 put_device(dev);
@@ -372,6 +499,10 @@ int device_add(struct device *dev)
372 BusError: 499 BusError:
373 device_pm_remove(dev); 500 device_pm_remove(dev);
374 PMError: 501 PMError:
502 device_remove_groups(dev);
503 GroupError:
504 device_remove_attrs(dev);
505 AttrsError:
375 if (dev->devt_attr) { 506 if (dev->devt_attr) {
376 device_remove_file(dev, dev->devt_attr); 507 device_remove_file(dev, dev->devt_attr);
377 kfree(dev->devt_attr); 508 kfree(dev->devt_attr);
@@ -449,6 +580,7 @@ void device_del(struct device * dev)
449{ 580{
450 struct device * parent = dev->parent; 581 struct device * parent = dev->parent;
451 char *class_name = NULL; 582 char *class_name = NULL;
583 struct class_interface *class_intf;
452 584
453 if (parent) 585 if (parent)
454 klist_del(&dev->knode_parent); 586 klist_del(&dev->knode_parent);
@@ -458,14 +590,23 @@ void device_del(struct device * dev)
458 sysfs_remove_link(&dev->kobj, "subsystem"); 590 sysfs_remove_link(&dev->kobj, "subsystem");
459 sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id); 591 sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id);
460 class_name = make_class_name(dev->class->name, &dev->kobj); 592 class_name = make_class_name(dev->class->name, &dev->kobj);
461 sysfs_remove_link(&dev->kobj, "device"); 593 if (parent) {
462 sysfs_remove_link(&dev->parent->kobj, class_name); 594 sysfs_remove_link(&dev->kobj, "device");
595 sysfs_remove_link(&dev->parent->kobj, class_name);
596 }
463 kfree(class_name); 597 kfree(class_name);
464 down(&dev->class->sem); 598 down(&dev->class->sem);
599 /* notify any interfaces that the device is now gone */
600 list_for_each_entry(class_intf, &dev->class->interfaces, node)
601 if (class_intf->remove_dev)
602 class_intf->remove_dev(dev, class_intf);
603 /* remove the device from the class list */
465 list_del_init(&dev->node); 604 list_del_init(&dev->node);
466 up(&dev->class->sem); 605 up(&dev->class->sem);
467 } 606 }
468 device_remove_file(dev, &dev->uevent_attr); 607 device_remove_file(dev, &dev->uevent_attr);
608 device_remove_groups(dev);
609 device_remove_attrs(dev);
469 610
470 /* Notify the platform of the removal, in case they 611 /* Notify the platform of the removal, in case they
471 * need to do anything... 612 * need to do anything...
@@ -579,7 +720,7 @@ static void device_create_release(struct device *dev)
579 * been created with a call to class_create(). 720 * been created with a call to class_create().
580 */ 721 */
581struct device *device_create(struct class *class, struct device *parent, 722struct device *device_create(struct class *class, struct device *parent,
582 dev_t devt, char *fmt, ...) 723 dev_t devt, const char *fmt, ...)
583{ 724{
584 va_list args; 725 va_list args;
585 struct device *dev = NULL; 726 struct device *dev = NULL;
@@ -587,10 +728,6 @@ struct device *device_create(struct class *class, struct device *parent,
587 728
588 if (class == NULL || IS_ERR(class)) 729 if (class == NULL || IS_ERR(class))
589 goto error; 730 goto error;
590 if (parent == NULL) {
591 printk(KERN_WARNING "%s does not work yet for NULL parents\n", __FUNCTION__);
592 goto error;
593 }
594 731
595 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 732 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
596 if (!dev) { 733 if (!dev) {
@@ -644,3 +781,58 @@ void device_destroy(struct class *class, dev_t devt)
644 device_unregister(dev); 781 device_unregister(dev);
645} 782}
646EXPORT_SYMBOL_GPL(device_destroy); 783EXPORT_SYMBOL_GPL(device_destroy);
784
785/**
786 * device_rename - renames a device
787 * @dev: the pointer to the struct device to be renamed
788 * @new_name: the new name of the device
789 */
790int device_rename(struct device *dev, char *new_name)
791{
792 char *old_class_name = NULL;
793 char *new_class_name = NULL;
794 char *old_symlink_name = NULL;
795 int error;
796
797 dev = get_device(dev);
798 if (!dev)
799 return -EINVAL;
800
801 pr_debug("DEVICE: renaming '%s' to '%s'\n", dev->bus_id, new_name);
802
803 if ((dev->class) && (dev->parent))
804 old_class_name = make_class_name(dev->class->name, &dev->kobj);
805
806 if (dev->class) {
807 old_symlink_name = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
808 if (!old_symlink_name)
809 return -ENOMEM;
810 strlcpy(old_symlink_name, dev->bus_id, BUS_ID_SIZE);
811 }
812
813 strlcpy(dev->bus_id, new_name, BUS_ID_SIZE);
814
815 error = kobject_rename(&dev->kobj, new_name);
816
817 if (old_class_name) {
818 new_class_name = make_class_name(dev->class->name, &dev->kobj);
819 if (new_class_name) {
820 sysfs_create_link(&dev->parent->kobj, &dev->kobj,
821 new_class_name);
822 sysfs_remove_link(&dev->parent->kobj, old_class_name);
823 }
824 }
825 if (dev->class) {
826 sysfs_remove_link(&dev->class->subsys.kset.kobj,
827 old_symlink_name);
828 sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj,
829 dev->bus_id);
830 }
831 put_device(dev);
832
833 kfree(old_class_name);
834 kfree(new_class_name);
835 kfree(old_symlink_name);
836
837 return error;
838}
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 889c71111239..b5f43c3e44fa 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -17,6 +17,7 @@
17 17
18#include <linux/device.h> 18#include <linux/device.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/kthread.h>
20 21
21#include "base.h" 22#include "base.h"
22#include "power/power.h" 23#include "power/power.h"
@@ -38,66 +39,73 @@
38 * 39 *
39 * This function must be called with @dev->sem held. 40 * This function must be called with @dev->sem held.
40 */ 41 */
41void device_bind_driver(struct device * dev) 42int device_bind_driver(struct device *dev)
42{ 43{
43 if (klist_node_attached(&dev->knode_driver)) 44 int ret;
44 return; 45
46 if (klist_node_attached(&dev->knode_driver)) {
47 printk(KERN_WARNING "%s: device %s already bound\n",
48 __FUNCTION__, kobject_name(&dev->kobj));
49 return 0;
50 }
45 51
46 pr_debug("bound device '%s' to driver '%s'\n", 52 pr_debug("bound device '%s' to driver '%s'\n",
47 dev->bus_id, dev->driver->name); 53 dev->bus_id, dev->driver->name);
48 klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices); 54 klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices);
49 sysfs_create_link(&dev->driver->kobj, &dev->kobj, 55 ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj,
50 kobject_name(&dev->kobj)); 56 kobject_name(&dev->kobj));
51 sysfs_create_link(&dev->kobj, &dev->driver->kobj, "driver"); 57 if (ret == 0) {
58 ret = sysfs_create_link(&dev->kobj, &dev->driver->kobj,
59 "driver");
60 if (ret)
61 sysfs_remove_link(&dev->driver->kobj,
62 kobject_name(&dev->kobj));
63 }
64 return ret;
52} 65}
53 66
54/** 67struct stupid_thread_structure {
55 * driver_probe_device - attempt to bind device & driver. 68 struct device_driver *drv;
56 * @drv: driver. 69 struct device *dev;
57 * @dev: device. 70};
58 * 71
59 * First, we call the bus's match function, if one present, which 72static atomic_t probe_count = ATOMIC_INIT(0);
60 * should compare the device IDs the driver supports with the 73static int really_probe(void *void_data)
61 * device IDs of the device. Note we don't do this ourselves
62 * because we don't know the format of the ID structures, nor what
63 * is to be considered a match and what is not.
64 *
65 * This function returns 1 if a match is found, an error if one
66 * occurs (that is not -ENODEV or -ENXIO), and 0 otherwise.
67 *
68 * This function must be called with @dev->sem held. When called
69 * for a USB interface, @dev->parent->sem must be held as well.
70 */
71int driver_probe_device(struct device_driver * drv, struct device * dev)
72{ 74{
75 struct stupid_thread_structure *data = void_data;
76 struct device_driver *drv = data->drv;
77 struct device *dev = data->dev;
73 int ret = 0; 78 int ret = 0;
74 79
75 if (drv->bus->match && !drv->bus->match(dev, drv)) 80 atomic_inc(&probe_count);
76 goto Done; 81 pr_debug("%s: Probing driver %s with device %s\n",
82 drv->bus->name, drv->name, dev->bus_id);
77 83
78 pr_debug("%s: Matched Device %s with Driver %s\n",
79 drv->bus->name, dev->bus_id, drv->name);
80 dev->driver = drv; 84 dev->driver = drv;
81 if (dev->bus->probe) { 85 if (dev->bus->probe) {
82 ret = dev->bus->probe(dev); 86 ret = dev->bus->probe(dev);
83 if (ret) { 87 if (ret) {
84 dev->driver = NULL; 88 dev->driver = NULL;
85 goto ProbeFailed; 89 goto probe_failed;
86 } 90 }
87 } else if (drv->probe) { 91 } else if (drv->probe) {
88 ret = drv->probe(dev); 92 ret = drv->probe(dev);
89 if (ret) { 93 if (ret) {
90 dev->driver = NULL; 94 dev->driver = NULL;
91 goto ProbeFailed; 95 goto probe_failed;
92 } 96 }
93 } 97 }
94 device_bind_driver(dev); 98 if (device_bind_driver(dev)) {
99 printk(KERN_ERR "%s: device_bind_driver(%s) failed\n",
100 __FUNCTION__, dev->bus_id);
101 /* How does undo a ->probe? We're screwed. */
102 }
95 ret = 1; 103 ret = 1;
96 pr_debug("%s: Bound Device %s to Driver %s\n", 104 pr_debug("%s: Bound Device %s to Driver %s\n",
97 drv->bus->name, dev->bus_id, drv->name); 105 drv->bus->name, dev->bus_id, drv->name);
98 goto Done; 106 goto done;
99 107
100 ProbeFailed: 108probe_failed:
101 if (ret == -ENODEV || ret == -ENXIO) { 109 if (ret == -ENODEV || ret == -ENXIO) {
102 /* Driver matched, but didn't support device 110 /* Driver matched, but didn't support device
103 * or device not found. 111 * or device not found.
@@ -110,7 +118,71 @@ int driver_probe_device(struct device_driver * drv, struct device * dev)
110 "%s: probe of %s failed with error %d\n", 118 "%s: probe of %s failed with error %d\n",
111 drv->name, dev->bus_id, ret); 119 drv->name, dev->bus_id, ret);
112 } 120 }
113 Done: 121done:
122 kfree(data);
123 atomic_dec(&probe_count);
124 return ret;
125}
126
127/**
128 * driver_probe_done
129 * Determine if the probe sequence is finished or not.
130 *
131 * Should somehow figure out how to use a semaphore, not an atomic variable...
132 */
133int driver_probe_done(void)
134{
135 pr_debug("%s: probe_count = %d\n", __FUNCTION__,
136 atomic_read(&probe_count));
137 if (atomic_read(&probe_count))
138 return -EBUSY;
139 return 0;
140}
141
142/**
143 * driver_probe_device - attempt to bind device & driver together
144 * @drv: driver to bind a device to
145 * @dev: device to try to bind to the driver
146 *
147 * First, we call the bus's match function, if one present, which should
148 * compare the device IDs the driver supports with the device IDs of the
149 * device. Note we don't do this ourselves because we don't know the
150 * format of the ID structures, nor what is to be considered a match and
151 * what is not.
152 *
153 * This function returns 1 if a match is found, an error if one occurs
154 * (that is not -ENODEV or -ENXIO), and 0 otherwise.
155 *
156 * This function must be called with @dev->sem held. When called for a
157 * USB interface, @dev->parent->sem must be held as well.
158 */
159int driver_probe_device(struct device_driver * drv, struct device * dev)
160{
161 struct stupid_thread_structure *data;
162 struct task_struct *probe_task;
163 int ret = 0;
164
165 if (!device_is_registered(dev))
166 return -ENODEV;
167 if (drv->bus->match && !drv->bus->match(dev, drv))
168 goto done;
169
170 pr_debug("%s: Matched Device %s with Driver %s\n",
171 drv->bus->name, dev->bus_id, drv->name);
172
173 data = kmalloc(sizeof(*data), GFP_KERNEL);
174 data->drv = drv;
175 data->dev = dev;
176
177 if (drv->multithread_probe) {
178 probe_task = kthread_run(really_probe, data,
179 "probe-%s", dev->bus_id);
180 if (IS_ERR(probe_task))
181 ret = PTR_ERR(probe_task);
182 } else
183 ret = really_probe(data);
184
185done:
114 return ret; 186 return ret;
115} 187}
116 188
@@ -139,8 +211,9 @@ int device_attach(struct device * dev)
139 211
140 down(&dev->sem); 212 down(&dev->sem);
141 if (dev->driver) { 213 if (dev->driver) {
142 device_bind_driver(dev); 214 ret = device_bind_driver(dev);
143 ret = 1; 215 if (ret == 0)
216 ret = 1;
144 } else 217 } else
145 ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach); 218 ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach);
146 up(&dev->sem); 219 up(&dev->sem);
@@ -182,9 +255,9 @@ static int __driver_attach(struct device * dev, void * data)
182 * returns 0 and the @dev->driver is set, we've found a 255 * returns 0 and the @dev->driver is set, we've found a
183 * compatible pair. 256 * compatible pair.
184 */ 257 */
185void driver_attach(struct device_driver * drv) 258int driver_attach(struct device_driver * drv)
186{ 259{
187 bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); 260 return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach);
188} 261}
189 262
190/** 263/**
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 562600dd540a..1214cbd17d86 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -142,20 +142,6 @@ void put_driver(struct device_driver * drv)
142 kobject_put(&drv->kobj); 142 kobject_put(&drv->kobj);
143} 143}
144 144
145static void klist_devices_get(struct klist_node *n)
146{
147 struct device *dev = container_of(n, struct device, knode_driver);
148
149 get_device(dev);
150}
151
152static void klist_devices_put(struct klist_node *n)
153{
154 struct device *dev = container_of(n, struct device, knode_driver);
155
156 put_device(dev);
157}
158
159/** 145/**
160 * driver_register - register driver with bus 146 * driver_register - register driver with bus
161 * @drv: driver to register 147 * @drv: driver to register
@@ -175,7 +161,7 @@ int driver_register(struct device_driver * drv)
175 (drv->bus->shutdown && drv->shutdown)) { 161 (drv->bus->shutdown && drv->shutdown)) {
176 printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name); 162 printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name);
177 } 163 }
178 klist_init(&drv->klist_devices, klist_devices_get, klist_devices_put); 164 klist_init(&drv->klist_devices, NULL, NULL);
179 init_completion(&drv->unloaded); 165 init_completion(&drv->unloaded);
180 return bus_add_driver(drv); 166 return bus_add_driver(drv);
181} 167}
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 5d6c011183f5..14615694ae9a 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -16,6 +16,7 @@
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/bitops.h> 17#include <linux/bitops.h>
18#include <linux/mutex.h> 18#include <linux/mutex.h>
19#include <linux/kthread.h>
19 20
20#include <linux/firmware.h> 21#include <linux/firmware.h>
21#include "base.h" 22#include "base.h"
@@ -511,7 +512,6 @@ request_firmware_work_func(void *arg)
511 WARN_ON(1); 512 WARN_ON(1);
512 return 0; 513 return 0;
513 } 514 }
514 daemonize("%s/%s", "firmware", fw_work->name);
515 ret = _request_firmware(&fw, fw_work->name, fw_work->device, 515 ret = _request_firmware(&fw, fw_work->name, fw_work->device,
516 fw_work->uevent); 516 fw_work->uevent);
517 if (ret < 0) 517 if (ret < 0)
@@ -546,9 +546,9 @@ request_firmware_nowait(
546 const char *name, struct device *device, void *context, 546 const char *name, struct device *device, void *context,
547 void (*cont)(const struct firmware *fw, void *context)) 547 void (*cont)(const struct firmware *fw, void *context))
548{ 548{
549 struct task_struct *task;
549 struct firmware_work *fw_work = kmalloc(sizeof (struct firmware_work), 550 struct firmware_work *fw_work = kmalloc(sizeof (struct firmware_work),
550 GFP_ATOMIC); 551 GFP_ATOMIC);
551 int ret;
552 552
553 if (!fw_work) 553 if (!fw_work)
554 return -ENOMEM; 554 return -ENOMEM;
@@ -566,14 +566,14 @@ request_firmware_nowait(
566 .uevent = uevent, 566 .uevent = uevent,
567 }; 567 };
568 568
569 ret = kernel_thread(request_firmware_work_func, fw_work, 569 task = kthread_run(request_firmware_work_func, fw_work,
570 CLONE_FS | CLONE_FILES); 570 "firmware/%s", name);
571 571
572 if (ret < 0) { 572 if (IS_ERR(task)) {
573 fw_work->cont(NULL, fw_work->context); 573 fw_work->cont(NULL, fw_work->context);
574 module_put(fw_work->module); 574 module_put(fw_work->module);
575 kfree(fw_work); 575 kfree(fw_work);
576 return ret; 576 return PTR_ERR(task);
577 } 577 }
578 return 0; 578 return 0;
579} 579}
@@ -602,7 +602,7 @@ firmware_class_exit(void)
602 class_unregister(&firmware_class); 602 class_unregister(&firmware_class);
603} 603}
604 604
605module_init(firmware_class_init); 605fs_initcall(firmware_class_init);
606module_exit(firmware_class_exit); 606module_exit(firmware_class_exit);
607 607
608EXPORT_SYMBOL(release_firmware); 608EXPORT_SYMBOL(release_firmware);
diff --git a/drivers/base/node.c b/drivers/base/node.c
index e9b0957f15d1..001e6f6b9c1b 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -54,10 +54,12 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
54 "Node %d MemUsed: %8lu kB\n" 54 "Node %d MemUsed: %8lu kB\n"
55 "Node %d Active: %8lu kB\n" 55 "Node %d Active: %8lu kB\n"
56 "Node %d Inactive: %8lu kB\n" 56 "Node %d Inactive: %8lu kB\n"
57#ifdef CONFIG_HIGHMEM
57 "Node %d HighTotal: %8lu kB\n" 58 "Node %d HighTotal: %8lu kB\n"
58 "Node %d HighFree: %8lu kB\n" 59 "Node %d HighFree: %8lu kB\n"
59 "Node %d LowTotal: %8lu kB\n" 60 "Node %d LowTotal: %8lu kB\n"
60 "Node %d LowFree: %8lu kB\n" 61 "Node %d LowFree: %8lu kB\n"
62#endif
61 "Node %d Dirty: %8lu kB\n" 63 "Node %d Dirty: %8lu kB\n"
62 "Node %d Writeback: %8lu kB\n" 64 "Node %d Writeback: %8lu kB\n"
63 "Node %d FilePages: %8lu kB\n" 65 "Node %d FilePages: %8lu kB\n"
@@ -66,16 +68,20 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
66 "Node %d PageTables: %8lu kB\n" 68 "Node %d PageTables: %8lu kB\n"
67 "Node %d NFS_Unstable: %8lu kB\n" 69 "Node %d NFS_Unstable: %8lu kB\n"
68 "Node %d Bounce: %8lu kB\n" 70 "Node %d Bounce: %8lu kB\n"
69 "Node %d Slab: %8lu kB\n", 71 "Node %d Slab: %8lu kB\n"
72 "Node %d SReclaimable: %8lu kB\n"
73 "Node %d SUnreclaim: %8lu kB\n",
70 nid, K(i.totalram), 74 nid, K(i.totalram),
71 nid, K(i.freeram), 75 nid, K(i.freeram),
72 nid, K(i.totalram - i.freeram), 76 nid, K(i.totalram - i.freeram),
73 nid, K(active), 77 nid, K(active),
74 nid, K(inactive), 78 nid, K(inactive),
79#ifdef CONFIG_HIGHMEM
75 nid, K(i.totalhigh), 80 nid, K(i.totalhigh),
76 nid, K(i.freehigh), 81 nid, K(i.freehigh),
77 nid, K(i.totalram - i.totalhigh), 82 nid, K(i.totalram - i.totalhigh),
78 nid, K(i.freeram - i.freehigh), 83 nid, K(i.freeram - i.freehigh),
84#endif
79 nid, K(node_page_state(nid, NR_FILE_DIRTY)), 85 nid, K(node_page_state(nid, NR_FILE_DIRTY)),
80 nid, K(node_page_state(nid, NR_WRITEBACK)), 86 nid, K(node_page_state(nid, NR_WRITEBACK)),
81 nid, K(node_page_state(nid, NR_FILE_PAGES)), 87 nid, K(node_page_state(nid, NR_FILE_PAGES)),
@@ -84,7 +90,10 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
84 nid, K(node_page_state(nid, NR_PAGETABLE)), 90 nid, K(node_page_state(nid, NR_PAGETABLE)),
85 nid, K(node_page_state(nid, NR_UNSTABLE_NFS)), 91 nid, K(node_page_state(nid, NR_UNSTABLE_NFS)),
86 nid, K(node_page_state(nid, NR_BOUNCE)), 92 nid, K(node_page_state(nid, NR_BOUNCE)),
87 nid, K(node_page_state(nid, NR_SLAB))); 93 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE) +
94 node_page_state(nid, NR_SLAB_UNRECLAIMABLE)),
95 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE)),
96 nid, K(node_page_state(nid, NR_SLAB_UNRECLAIMABLE)));
88 n += hugetlb_report_node_meminfo(nid, buf + n); 97 n += hugetlb_report_node_meminfo(nid, buf + n);
89 return n; 98 return n;
90} 99}
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 2b8755db76c6..940ce41f1887 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -505,12 +505,36 @@ static int platform_match(struct device * dev, struct device_driver * drv)
505 return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0); 505 return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0);
506} 506}
507 507
508static int platform_suspend(struct device * dev, pm_message_t state) 508static int platform_suspend(struct device *dev, pm_message_t mesg)
509{ 509{
510 int ret = 0; 510 int ret = 0;
511 511
512 if (dev->driver && dev->driver->suspend) 512 if (dev->driver && dev->driver->suspend)
513 ret = dev->driver->suspend(dev, state); 513 ret = dev->driver->suspend(dev, mesg);
514
515 return ret;
516}
517
518static int platform_suspend_late(struct device *dev, pm_message_t mesg)
519{
520 struct platform_driver *drv = to_platform_driver(dev->driver);
521 struct platform_device *pdev = container_of(dev, struct platform_device, dev);
522 int ret = 0;
523
524 if (dev->driver && drv->suspend_late)
525 ret = drv->suspend_late(pdev, mesg);
526
527 return ret;
528}
529
530static int platform_resume_early(struct device *dev)
531{
532 struct platform_driver *drv = to_platform_driver(dev->driver);
533 struct platform_device *pdev = container_of(dev, struct platform_device, dev);
534 int ret = 0;
535
536 if (dev->driver && drv->resume_early)
537 ret = drv->resume_early(pdev);
514 538
515 return ret; 539 return ret;
516} 540}
@@ -531,6 +555,8 @@ struct bus_type platform_bus_type = {
531 .match = platform_match, 555 .match = platform_match,
532 .uevent = platform_uevent, 556 .uevent = platform_uevent,
533 .suspend = platform_suspend, 557 .suspend = platform_suspend,
558 .suspend_late = platform_suspend_late,
559 .resume_early = platform_resume_early,
534 .resume = platform_resume, 560 .resume = platform_resume,
535}; 561};
536EXPORT_SYMBOL_GPL(platform_bus_type); 562EXPORT_SYMBOL_GPL(platform_bus_type);
diff --git a/drivers/base/power/resume.c b/drivers/base/power/resume.c
index 826093ef4c7e..020be36705a6 100644
--- a/drivers/base/power/resume.c
+++ b/drivers/base/power/resume.c
@@ -38,13 +38,35 @@ int resume_device(struct device * dev)
38 dev_dbg(dev,"resuming\n"); 38 dev_dbg(dev,"resuming\n");
39 error = dev->bus->resume(dev); 39 error = dev->bus->resume(dev);
40 } 40 }
41 if (dev->class && dev->class->resume) {
42 dev_dbg(dev,"class resume\n");
43 error = dev->class->resume(dev);
44 }
41 up(&dev->sem); 45 up(&dev->sem);
42 TRACE_RESUME(error); 46 TRACE_RESUME(error);
43 return error; 47 return error;
44} 48}
45 49
46 50
51static int resume_device_early(struct device * dev)
52{
53 int error = 0;
47 54
55 TRACE_DEVICE(dev);
56 TRACE_RESUME(0);
57 if (dev->bus && dev->bus->resume_early) {
58 dev_dbg(dev,"EARLY resume\n");
59 error = dev->bus->resume_early(dev);
60 }
61 TRACE_RESUME(error);
62 return error;
63}
64
65/*
66 * Resume the devices that have either not gone through
67 * the late suspend, or that did go through it but also
68 * went through the early resume
69 */
48void dpm_resume(void) 70void dpm_resume(void)
49{ 71{
50 down(&dpm_list_sem); 72 down(&dpm_list_sem);
@@ -74,6 +96,7 @@ void dpm_resume(void)
74 96
75void device_resume(void) 97void device_resume(void)
76{ 98{
99 might_sleep();
77 down(&dpm_sem); 100 down(&dpm_sem);
78 dpm_resume(); 101 dpm_resume();
79 up(&dpm_sem); 102 up(&dpm_sem);
@@ -83,12 +106,12 @@ EXPORT_SYMBOL_GPL(device_resume);
83 106
84 107
85/** 108/**
86 * device_power_up_irq - Power on some devices. 109 * dpm_power_up - Power on some devices.
87 * 110 *
88 * Walk the dpm_off_irq list and power each device up. This 111 * Walk the dpm_off_irq list and power each device up. This
89 * is used for devices that required they be powered down with 112 * is used for devices that required they be powered down with
90 * interrupts disabled. As devices are powered on, they are moved to 113 * interrupts disabled. As devices are powered on, they are moved
91 * the dpm_suspended list. 114 * to the dpm_active list.
92 * 115 *
93 * Interrupts must be disabled when calling this. 116 * Interrupts must be disabled when calling this.
94 */ 117 */
@@ -99,16 +122,14 @@ void dpm_power_up(void)
99 struct list_head * entry = dpm_off_irq.next; 122 struct list_head * entry = dpm_off_irq.next;
100 struct device * dev = to_device(entry); 123 struct device * dev = to_device(entry);
101 124
102 get_device(dev); 125 list_move_tail(entry, &dpm_off);
103 list_move_tail(entry, &dpm_active); 126 resume_device_early(dev);
104 resume_device(dev);
105 put_device(dev);
106 } 127 }
107} 128}
108 129
109 130
110/** 131/**
111 * device_pm_power_up - Turn on all devices that need special attention. 132 * device_power_up - Turn on all devices that need special attention.
112 * 133 *
113 * Power on system devices then devices that required we shut them down 134 * Power on system devices then devices that required we shut them down
114 * with interrupts disabled. 135 * with interrupts disabled.
diff --git a/drivers/base/power/suspend.c b/drivers/base/power/suspend.c
index 69509e02f703..ece136bf97e3 100644
--- a/drivers/base/power/suspend.c
+++ b/drivers/base/power/suspend.c
@@ -34,6 +34,7 @@ static inline char *suspend_verb(u32 event)
34 switch (event) { 34 switch (event) {
35 case PM_EVENT_SUSPEND: return "suspend"; 35 case PM_EVENT_SUSPEND: return "suspend";
36 case PM_EVENT_FREEZE: return "freeze"; 36 case PM_EVENT_FREEZE: return "freeze";
37 case PM_EVENT_PRETHAW: return "prethaw";
37 default: return "(unknown suspend event)"; 38 default: return "(unknown suspend event)";
38 } 39 }
39} 40}
@@ -65,7 +66,19 @@ int suspend_device(struct device * dev, pm_message_t state)
65 66
66 dev->power.prev_state = dev->power.power_state; 67 dev->power.prev_state = dev->power.power_state;
67 68
68 if (dev->bus && dev->bus->suspend && !dev->power.power_state.event) { 69 if (dev->class && dev->class->suspend && !dev->power.power_state.event) {
70 dev_dbg(dev, "class %s%s\n",
71 suspend_verb(state.event),
72 ((state.event == PM_EVENT_SUSPEND)
73 && device_may_wakeup(dev))
74 ? ", may wakeup"
75 : ""
76 );
77 error = dev->class->suspend(dev, state);
78 suspend_report_result(dev->class->suspend, error);
79 }
80
81 if (!error && dev->bus && dev->bus->suspend && !dev->power.power_state.event) {
69 dev_dbg(dev, "%s%s\n", 82 dev_dbg(dev, "%s%s\n",
70 suspend_verb(state.event), 83 suspend_verb(state.event),
71 ((state.event == PM_EVENT_SUSPEND) 84 ((state.event == PM_EVENT_SUSPEND)
@@ -81,15 +94,42 @@ int suspend_device(struct device * dev, pm_message_t state)
81} 94}
82 95
83 96
97/*
98 * This is called with interrupts off, only a single CPU
99 * running. We can't do down() on a semaphore (and we don't
100 * need the protection)
101 */
102static int suspend_device_late(struct device *dev, pm_message_t state)
103{
104 int error = 0;
105
106 if (dev->bus && dev->bus->suspend_late && !dev->power.power_state.event) {
107 dev_dbg(dev, "LATE %s%s\n",
108 suspend_verb(state.event),
109 ((state.event == PM_EVENT_SUSPEND)
110 && device_may_wakeup(dev))
111 ? ", may wakeup"
112 : ""
113 );
114 error = dev->bus->suspend_late(dev, state);
115 suspend_report_result(dev->bus->suspend_late, error);
116 }
117 return error;
118}
119
84/** 120/**
85 * device_suspend - Save state and stop all devices in system. 121 * device_suspend - Save state and stop all devices in system.
86 * @state: Power state to put each device in. 122 * @state: Power state to put each device in.
87 * 123 *
88 * Walk the dpm_active list, call ->suspend() for each device, and move 124 * Walk the dpm_active list, call ->suspend() for each device, and move
89 * it to dpm_off. 125 * it to the dpm_off list.
90 * Check the return value for each. If it returns 0, then we move the 126 *
91 * the device to the dpm_off list. If it returns -EAGAIN, we move it to 127 * (For historical reasons, if it returns -EAGAIN, that used to mean
92 * the dpm_off_irq list. If we get a different error, try and back out. 128 * that the device would be called again with interrupts disabled.
129 * These days, we use the "suspend_late()" callback for that, so we
130 * print a warning and consider it an error).
131 *
132 * If we get a different error, try and back out.
93 * 133 *
94 * If we hit a failure with any of the devices, call device_resume() 134 * If we hit a failure with any of the devices, call device_resume()
95 * above to bring the suspended devices back to life. 135 * above to bring the suspended devices back to life.
@@ -100,6 +140,7 @@ int device_suspend(pm_message_t state)
100{ 140{
101 int error = 0; 141 int error = 0;
102 142
143 might_sleep();
103 down(&dpm_sem); 144 down(&dpm_sem);
104 down(&dpm_list_sem); 145 down(&dpm_list_sem);
105 while (!list_empty(&dpm_active) && error == 0) { 146 while (!list_empty(&dpm_active) && error == 0) {
@@ -115,39 +156,27 @@ int device_suspend(pm_message_t state)
115 156
116 /* Check if the device got removed */ 157 /* Check if the device got removed */
117 if (!list_empty(&dev->power.entry)) { 158 if (!list_empty(&dev->power.entry)) {
118 /* Move it to the dpm_off or dpm_off_irq list */ 159 /* Move it to the dpm_off list */
119 if (!error) 160 if (!error)
120 list_move(&dev->power.entry, &dpm_off); 161 list_move(&dev->power.entry, &dpm_off);
121 else if (error == -EAGAIN) {
122 list_move(&dev->power.entry, &dpm_off_irq);
123 error = 0;
124 }
125 } 162 }
126 if (error) 163 if (error)
127 printk(KERN_ERR "Could not suspend device %s: " 164 printk(KERN_ERR "Could not suspend device %s: "
128 "error %d\n", kobject_name(&dev->kobj), error); 165 "error %d%s\n",
166 kobject_name(&dev->kobj), error,
167 error == -EAGAIN ? " (please convert to suspend_late)" : "");
129 put_device(dev); 168 put_device(dev);
130 } 169 }
131 up(&dpm_list_sem); 170 up(&dpm_list_sem);
132 if (error) { 171 if (error)
133 /* we failed... before resuming, bring back devices from
134 * dpm_off_irq list back to main dpm_off list, we do want
135 * to call resume() on them, in case they partially suspended
136 * despite returning -EAGAIN
137 */
138 while (!list_empty(&dpm_off_irq)) {
139 struct list_head * entry = dpm_off_irq.next;
140 list_move(entry, &dpm_off);
141 }
142 dpm_resume(); 172 dpm_resume();
143 } 173
144 up(&dpm_sem); 174 up(&dpm_sem);
145 return error; 175 return error;
146} 176}
147 177
148EXPORT_SYMBOL_GPL(device_suspend); 178EXPORT_SYMBOL_GPL(device_suspend);
149 179
150
151/** 180/**
152 * device_power_down - Shut down special devices. 181 * device_power_down - Shut down special devices.
153 * @state: Power state to enter. 182 * @state: Power state to enter.
@@ -162,14 +191,17 @@ int device_power_down(pm_message_t state)
162 int error = 0; 191 int error = 0;
163 struct device * dev; 192 struct device * dev;
164 193
165 list_for_each_entry_reverse(dev, &dpm_off_irq, power.entry) { 194 while (!list_empty(&dpm_off)) {
166 if ((error = suspend_device(dev, state))) 195 struct list_head * entry = dpm_off.prev;
167 break; 196
197 dev = to_device(entry);
198 error = suspend_device_late(dev, state);
199 if (error)
200 goto Error;
201 list_move(&dev->power.entry, &dpm_off_irq);
168 } 202 }
169 if (error) 203
170 goto Error; 204 error = sysdev_suspend(state);
171 if ((error = sysdev_suspend(state)))
172 goto Error;
173 Done: 205 Done:
174 return error; 206 return error;
175 Error: 207 Error:
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index 40d7242a07c1..2d47517dbe32 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -7,22 +7,29 @@
7#include "power.h" 7#include "power.h"
8 8
9 9
10#ifdef CONFIG_PM_SYSFS_DEPRECATED
11
10/** 12/**
11 * state - Control current power state of device 13 * state - Control current power state of device
12 * 14 *
13 * show() returns the current power state of the device. '0' indicates 15 * show() returns the current power state of the device. '0' indicates
14 * the device is on. Other values (1-3) indicate the device is in a low 16 * the device is on. Other values (2) indicate the device is in some low
15 * power state. 17 * power state.
16 * 18 *
17 * store() sets the current power state, which is an integer value 19 * store() sets the current power state, which is an integer valued
18 * between 0-3. If the device is on ('0'), and the value written is 20 * 0, 2, or 3. Devices with bus.suspend_late(), or bus.resume_early()
19 * greater than 0, then the device is placed directly into the low-power 21 * methods fail this operation; those methods couldn't be called.
20 * state (via its driver's ->suspend() method). 22 * Otherwise,
21 * If the device is currently in a low-power state, and the value is 0, 23 *
22 * the device is powered back on (via the ->resume() method). 24 * - If the recorded dev->power.power_state.event matches the
23 * If the device is in a low-power state, and a different low-power state 25 * target value, nothing is done.
24 * is requested, the device is first resumed, then suspended into the new 26 * - If the recorded event code is nonzero, the device is reactivated
25 * low-power state. 27 * by calling bus.resume() and/or class.resume().
28 * - If the target value is nonzero, the device is suspended by
29 * calling class.suspend() and/or bus.suspend() with event code
30 * PM_EVENT_SUSPEND.
31 *
32 * This mechanism is DEPRECATED and should only be used for testing.
26 */ 33 */
27 34
28static ssize_t state_show(struct device * dev, struct device_attribute *attr, char * buf) 35static ssize_t state_show(struct device * dev, struct device_attribute *attr, char * buf)
@@ -38,6 +45,10 @@ static ssize_t state_store(struct device * dev, struct device_attribute *attr, c
38 pm_message_t state; 45 pm_message_t state;
39 int error = -EINVAL; 46 int error = -EINVAL;
40 47
48 /* disallow incomplete suspend sequences */
49 if (dev->bus && (dev->bus->suspend_late || dev->bus->resume_early))
50 return error;
51
41 state.event = PM_EVENT_SUSPEND; 52 state.event = PM_EVENT_SUSPEND;
42 /* Older apps expected to write "3" here - confused with PCI D3 */ 53 /* Older apps expected to write "3" here - confused with PCI D3 */
43 if ((n == 1) && !strcmp(buf, "3")) 54 if ((n == 1) && !strcmp(buf, "3"))
@@ -57,6 +68,8 @@ static ssize_t state_store(struct device * dev, struct device_attribute *attr, c
57static DEVICE_ATTR(state, 0644, state_show, state_store); 68static DEVICE_ATTR(state, 0644, state_show, state_store);
58 69
59 70
71#endif /* CONFIG_PM_SYSFS_DEPRECATED */
72
60/* 73/*
61 * wakeup - Report/change current wakeup option for device 74 * wakeup - Report/change current wakeup option for device
62 * 75 *
@@ -130,7 +143,9 @@ static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store);
130 143
131 144
132static struct attribute * power_attrs[] = { 145static struct attribute * power_attrs[] = {
146#ifdef CONFIG_PM_SYSFS_DEPRECATED
133 &dev_attr_state.attr, 147 &dev_attr_state.attr,
148#endif
134 &dev_attr_wakeup.attr, 149 &dev_attr_wakeup.attr,
135 NULL, 150 NULL,
136}; 151};
diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index a360215dbce7..b3f639fbf220 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -770,7 +770,7 @@ static void DAC960_P_QueueCommand(DAC960_Command_T *Command)
770static void DAC960_ExecuteCommand(DAC960_Command_T *Command) 770static void DAC960_ExecuteCommand(DAC960_Command_T *Command)
771{ 771{
772 DAC960_Controller_T *Controller = Command->Controller; 772 DAC960_Controller_T *Controller = Command->Controller;
773 DECLARE_COMPLETION(Completion); 773 DECLARE_COMPLETION_ONSTACK(Completion);
774 unsigned long flags; 774 unsigned long flags;
775 Command->Completion = &Completion; 775 Command->Completion = &Completion;
776 776
@@ -3331,7 +3331,7 @@ static int DAC960_process_queue(DAC960_Controller_T *Controller, struct request_
3331 Command->DmaDirection = PCI_DMA_TODEVICE; 3331 Command->DmaDirection = PCI_DMA_TODEVICE;
3332 Command->CommandType = DAC960_WriteCommand; 3332 Command->CommandType = DAC960_WriteCommand;
3333 } 3333 }
3334 Command->Completion = Request->waiting; 3334 Command->Completion = Request->end_io_data;
3335 Command->LogicalDriveNumber = (long)Request->rq_disk->private_data; 3335 Command->LogicalDriveNumber = (long)Request->rq_disk->private_data;
3336 Command->BlockNumber = Request->sector; 3336 Command->BlockNumber = Request->sector;
3337 Command->BlockCount = Request->nr_sectors; 3337 Command->BlockCount = Request->nr_sectors;
diff --git a/drivers/block/DAC960.h b/drivers/block/DAC960.h
index a82f37f749a5..f9217c34bc2b 100644
--- a/drivers/block/DAC960.h
+++ b/drivers/block/DAC960.h
@@ -71,7 +71,7 @@
71 Define a Boolean data type. 71 Define a Boolean data type.
72*/ 72*/
73 73
74typedef enum { false, true } __attribute__ ((packed)) boolean; 74typedef bool boolean;
75 75
76 76
77/* 77/*
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index b5382cedf0c0..422e31d5f8e5 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -2,6 +2,8 @@
2# Block device driver configuration 2# Block device driver configuration
3# 3#
4 4
5if BLOCK
6
5menu "Block devices" 7menu "Block devices"
6 8
7config BLK_DEV_FD 9config BLK_DEV_FD
@@ -468,3 +470,5 @@ config ATA_OVER_ETH
468 devices like the Coraid EtherDrive (R) Storage Blade. 470 devices like the Coraid EtherDrive (R) Storage Blade.
469 471
470endmenu 472endmenu
473
474endif
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 2cd3391ff878..99f87efe0f58 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -144,13 +144,13 @@ static int rebuild_lun_table(ctlr_info_t *h, struct gendisk *del_disk);
144static int deregister_disk(struct gendisk *disk, drive_info_struct *drv, 144static int deregister_disk(struct gendisk *disk, drive_info_struct *drv,
145 int clear_all); 145 int clear_all);
146 146
147static void cciss_read_capacity(int ctlr, int logvol, ReadCapdata_struct *buf, 147static void cciss_read_capacity(int ctlr, int logvol, int withirq,
148 int withirq, unsigned int *total_size, 148 sector_t *total_size, unsigned int *block_size);
149 unsigned int *block_size); 149static void cciss_read_capacity_16(int ctlr, int logvol, int withirq,
150static void cciss_geometry_inquiry(int ctlr, int logvol, int withirq, 150 sector_t *total_size, unsigned int *block_size);
151 unsigned int total_size, 151static void cciss_geometry_inquiry(int ctlr, int logvol,
152 unsigned int block_size, 152 int withirq, sector_t total_size,
153 InquiryData_struct *inq_buff, 153 unsigned int block_size, InquiryData_struct *inq_buff,
154 drive_info_struct *drv); 154 drive_info_struct *drv);
155static void cciss_getgeometry(int cntl_num); 155static void cciss_getgeometry(int cntl_num);
156static void __devinit cciss_interrupt_mode(ctlr_info_t *, struct pci_dev *, 156static void __devinit cciss_interrupt_mode(ctlr_info_t *, struct pci_dev *,
@@ -879,7 +879,7 @@ static int cciss_ioctl(struct inode *inode, struct file *filep,
879 char *buff = NULL; 879 char *buff = NULL;
880 u64bit temp64; 880 u64bit temp64;
881 unsigned long flags; 881 unsigned long flags;
882 DECLARE_COMPLETION(wait); 882 DECLARE_COMPLETION_ONSTACK(wait);
883 883
884 if (!arg) 884 if (!arg)
885 return -EINVAL; 885 return -EINVAL;
@@ -997,7 +997,7 @@ static int cciss_ioctl(struct inode *inode, struct file *filep,
997 BYTE sg_used = 0; 997 BYTE sg_used = 0;
998 int status = 0; 998 int status = 0;
999 int i; 999 int i;
1000 DECLARE_COMPLETION(wait); 1000 DECLARE_COMPLETION_ONSTACK(wait);
1001 __u32 left; 1001 __u32 left;
1002 __u32 sz; 1002 __u32 sz;
1003 BYTE __user *data_ptr; 1003 BYTE __user *data_ptr;
@@ -1229,7 +1229,6 @@ static inline void complete_buffers(struct bio *bio, int status)
1229 int nr_sectors = bio_sectors(bio); 1229 int nr_sectors = bio_sectors(bio);
1230 1230
1231 bio->bi_next = NULL; 1231 bio->bi_next = NULL;
1232 blk_finished_io(len);
1233 bio_endio(bio, nr_sectors << 9, status ? 0 : -EIO); 1232 bio_endio(bio, nr_sectors << 9, status ? 0 : -EIO);
1234 bio = xbh; 1233 bio = xbh;
1235 } 1234 }
@@ -1326,10 +1325,9 @@ static void cciss_update_drive_info(int ctlr, int drv_index)
1326{ 1325{
1327 ctlr_info_t *h = hba[ctlr]; 1326 ctlr_info_t *h = hba[ctlr];
1328 struct gendisk *disk; 1327 struct gendisk *disk;
1329 ReadCapdata_struct *size_buff = NULL;
1330 InquiryData_struct *inq_buff = NULL; 1328 InquiryData_struct *inq_buff = NULL;
1331 unsigned int block_size; 1329 unsigned int block_size;
1332 unsigned int total_size; 1330 sector_t total_size;
1333 unsigned long flags = 0; 1331 unsigned long flags = 0;
1334 int ret = 0; 1332 int ret = 0;
1335 1333
@@ -1348,15 +1346,25 @@ static void cciss_update_drive_info(int ctlr, int drv_index)
1348 return; 1346 return;
1349 1347
1350 /* Get information about the disk and modify the driver structure */ 1348 /* Get information about the disk and modify the driver structure */
1351 size_buff = kmalloc(sizeof(ReadCapdata_struct), GFP_KERNEL);
1352 if (size_buff == NULL)
1353 goto mem_msg;
1354 inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL); 1349 inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL);
1355 if (inq_buff == NULL) 1350 if (inq_buff == NULL)
1356 goto mem_msg; 1351 goto mem_msg;
1357 1352
1358 cciss_read_capacity(ctlr, drv_index, size_buff, 1, 1353 cciss_read_capacity(ctlr, drv_index, 1,
1359 &total_size, &block_size); 1354 &total_size, &block_size);
1355
1356 /* total size = last LBA + 1 */
1357 /* FFFFFFFF + 1 = 0, cannot have a logical volume of size 0 */
1358 /* so we assume this volume this must be >2TB in size */
1359 if (total_size == (__u32) 0) {
1360 cciss_read_capacity_16(ctlr, drv_index, 1,
1361 &total_size, &block_size);
1362 h->cciss_read = CCISS_READ_16;
1363 h->cciss_write = CCISS_WRITE_16;
1364 } else {
1365 h->cciss_read = CCISS_READ_10;
1366 h->cciss_write = CCISS_WRITE_10;
1367 }
1360 cciss_geometry_inquiry(ctlr, drv_index, 1, total_size, block_size, 1368 cciss_geometry_inquiry(ctlr, drv_index, 1, total_size, block_size,
1361 inq_buff, &h->drv[drv_index]); 1369 inq_buff, &h->drv[drv_index]);
1362 1370
@@ -1392,7 +1400,6 @@ static void cciss_update_drive_info(int ctlr, int drv_index)
1392 } 1400 }
1393 1401
1394 freeret: 1402 freeret:
1395 kfree(size_buff);
1396 kfree(inq_buff); 1403 kfree(inq_buff);
1397 return; 1404 return;
1398 mem_msg: 1405 mem_msg:
@@ -1717,6 +1724,22 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
1717 c->Request.Timeout = 0; 1724 c->Request.Timeout = 0;
1718 c->Request.CDB[0] = cmd; 1725 c->Request.CDB[0] = cmd;
1719 break; 1726 break;
1727 case CCISS_READ_CAPACITY_16:
1728 c->Header.LUN.LogDev.VolId = h->drv[log_unit].LunID;
1729 c->Header.LUN.LogDev.Mode = 1;
1730 c->Request.CDBLen = 16;
1731 c->Request.Type.Attribute = ATTR_SIMPLE;
1732 c->Request.Type.Direction = XFER_READ;
1733 c->Request.Timeout = 0;
1734 c->Request.CDB[0] = cmd;
1735 c->Request.CDB[1] = 0x10;
1736 c->Request.CDB[10] = (size >> 24) & 0xFF;
1737 c->Request.CDB[11] = (size >> 16) & 0xFF;
1738 c->Request.CDB[12] = (size >> 8) & 0xFF;
1739 c->Request.CDB[13] = size & 0xFF;
1740 c->Request.Timeout = 0;
1741 c->Request.CDB[0] = cmd;
1742 break;
1720 case CCISS_CACHE_FLUSH: 1743 case CCISS_CACHE_FLUSH:
1721 c->Request.CDBLen = 12; 1744 c->Request.CDBLen = 12;
1722 c->Request.Type.Attribute = ATTR_SIMPLE; 1745 c->Request.Type.Attribute = ATTR_SIMPLE;
@@ -1750,6 +1773,7 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
1750 memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB)); 1773 memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB));
1751 c->Request.CDB[0] = cmd; /* reset */ 1774 c->Request.CDB[0] = cmd; /* reset */
1752 c->Request.CDB[1] = 0x04; /* reset a LUN */ 1775 c->Request.CDB[1] = 0x04; /* reset a LUN */
1776 break;
1753 case 3: /* No-Op message */ 1777 case 3: /* No-Op message */
1754 c->Request.CDBLen = 1; 1778 c->Request.CDBLen = 1;
1755 c->Request.Type.Attribute = ATTR_SIMPLE; 1779 c->Request.Type.Attribute = ATTR_SIMPLE;
@@ -1792,7 +1816,7 @@ static int sendcmd_withirq(__u8 cmd,
1792 u64bit buff_dma_handle; 1816 u64bit buff_dma_handle;
1793 unsigned long flags; 1817 unsigned long flags;
1794 int return_status; 1818 int return_status;
1795 DECLARE_COMPLETION(wait); 1819 DECLARE_COMPLETION_ONSTACK(wait);
1796 1820
1797 if ((c = cmd_alloc(h, 0)) == NULL) 1821 if ((c = cmd_alloc(h, 0)) == NULL)
1798 return -ENOMEM; 1822 return -ENOMEM;
@@ -1893,12 +1917,15 @@ static int sendcmd_withirq(__u8 cmd,
1893} 1917}
1894 1918
1895static void cciss_geometry_inquiry(int ctlr, int logvol, 1919static void cciss_geometry_inquiry(int ctlr, int logvol,
1896 int withirq, unsigned int total_size, 1920 int withirq, sector_t total_size,
1897 unsigned int block_size, 1921 unsigned int block_size,
1898 InquiryData_struct *inq_buff, 1922 InquiryData_struct *inq_buff,
1899 drive_info_struct *drv) 1923 drive_info_struct *drv)
1900{ 1924{
1901 int return_code; 1925 int return_code;
1926 unsigned long t;
1927 unsigned long rem;
1928
1902 memset(inq_buff, 0, sizeof(InquiryData_struct)); 1929 memset(inq_buff, 0, sizeof(InquiryData_struct));
1903 if (withirq) 1930 if (withirq)
1904 return_code = sendcmd_withirq(CISS_INQUIRY, ctlr, 1931 return_code = sendcmd_withirq(CISS_INQUIRY, ctlr,
@@ -1917,10 +1944,10 @@ static void cciss_geometry_inquiry(int ctlr, int logvol,
1917 drv->nr_blocks = total_size; 1944 drv->nr_blocks = total_size;
1918 drv->heads = 255; 1945 drv->heads = 255;
1919 drv->sectors = 32; // Sectors per track 1946 drv->sectors = 32; // Sectors per track
1920 drv->cylinders = total_size / 255 / 32; 1947 t = drv->heads * drv->sectors;
1948 drv->cylinders = total_size;
1949 rem = do_div(drv->cylinders, t);
1921 } else { 1950 } else {
1922 unsigned int t;
1923
1924 drv->block_size = block_size; 1951 drv->block_size = block_size;
1925 drv->nr_blocks = total_size; 1952 drv->nr_blocks = total_size;
1926 drv->heads = inq_buff->data_byte[6]; 1953 drv->heads = inq_buff->data_byte[6];
@@ -1930,42 +1957,84 @@ static void cciss_geometry_inquiry(int ctlr, int logvol,
1930 drv->raid_level = inq_buff->data_byte[8]; 1957 drv->raid_level = inq_buff->data_byte[8];
1931 t = drv->heads * drv->sectors; 1958 t = drv->heads * drv->sectors;
1932 if (t > 1) { 1959 if (t > 1) {
1933 drv->cylinders = total_size / t; 1960 drv->cylinders = total_size;
1961 rem = do_div(drv->cylinders, t);
1934 } 1962 }
1935 } 1963 }
1936 } else { /* Get geometry failed */ 1964 } else { /* Get geometry failed */
1937 printk(KERN_WARNING "cciss: reading geometry failed\n"); 1965 printk(KERN_WARNING "cciss: reading geometry failed\n");
1938 } 1966 }
1939 printk(KERN_INFO " heads= %d, sectors= %d, cylinders= %d\n\n", 1967 printk(KERN_INFO " heads=%d, sectors=%d, cylinders=%d\n\n",
1940 drv->heads, drv->sectors, drv->cylinders); 1968 drv->heads, drv->sectors, drv->cylinders);
1941} 1969}
1942 1970
1943static void 1971static void
1944cciss_read_capacity(int ctlr, int logvol, ReadCapdata_struct *buf, 1972cciss_read_capacity(int ctlr, int logvol, int withirq, sector_t *total_size,
1945 int withirq, unsigned int *total_size,
1946 unsigned int *block_size) 1973 unsigned int *block_size)
1947{ 1974{
1975 ReadCapdata_struct *buf;
1948 int return_code; 1976 int return_code;
1949 memset(buf, 0, sizeof(*buf)); 1977 buf = kmalloc(sizeof(ReadCapdata_struct), GFP_KERNEL);
1978 if (buf == NULL) {
1979 printk(KERN_WARNING "cciss: out of memory\n");
1980 return;
1981 }
1982 memset(buf, 0, sizeof(ReadCapdata_struct));
1950 if (withirq) 1983 if (withirq)
1951 return_code = sendcmd_withirq(CCISS_READ_CAPACITY, 1984 return_code = sendcmd_withirq(CCISS_READ_CAPACITY,
1952 ctlr, buf, sizeof(*buf), 1, 1985 ctlr, buf, sizeof(ReadCapdata_struct),
1953 logvol, 0, TYPE_CMD); 1986 1, logvol, 0, TYPE_CMD);
1954 else 1987 else
1955 return_code = sendcmd(CCISS_READ_CAPACITY, 1988 return_code = sendcmd(CCISS_READ_CAPACITY,
1956 ctlr, buf, sizeof(*buf), 1, logvol, 0, 1989 ctlr, buf, sizeof(ReadCapdata_struct),
1957 NULL, TYPE_CMD); 1990 1, logvol, 0, NULL, TYPE_CMD);
1958 if (return_code == IO_OK) { 1991 if (return_code == IO_OK) {
1959 *total_size = 1992 *total_size = be32_to_cpu(*(__u32 *) buf->total_size)+1;
1960 be32_to_cpu(*((__be32 *) & buf->total_size[0])) + 1; 1993 *block_size = be32_to_cpu(*(__u32 *) buf->block_size);
1961 *block_size = be32_to_cpu(*((__be32 *) & buf->block_size[0]));
1962 } else { /* read capacity command failed */ 1994 } else { /* read capacity command failed */
1963 printk(KERN_WARNING "cciss: read capacity failed\n"); 1995 printk(KERN_WARNING "cciss: read capacity failed\n");
1964 *total_size = 0; 1996 *total_size = 0;
1965 *block_size = BLOCK_SIZE; 1997 *block_size = BLOCK_SIZE;
1966 } 1998 }
1967 printk(KERN_INFO " blocks= %u block_size= %d\n", 1999 if (*total_size != (__u32) 0)
2000 printk(KERN_INFO " blocks= %lld block_size= %d\n",
2001 *total_size, *block_size);
2002 kfree(buf);
2003 return;
2004}
2005
2006static void
2007cciss_read_capacity_16(int ctlr, int logvol, int withirq, sector_t *total_size, unsigned int *block_size)
2008{
2009 ReadCapdata_struct_16 *buf;
2010 int return_code;
2011 buf = kmalloc(sizeof(ReadCapdata_struct_16), GFP_KERNEL);
2012 if (buf == NULL) {
2013 printk(KERN_WARNING "cciss: out of memory\n");
2014 return;
2015 }
2016 memset(buf, 0, sizeof(ReadCapdata_struct_16));
2017 if (withirq) {
2018 return_code = sendcmd_withirq(CCISS_READ_CAPACITY_16,
2019 ctlr, buf, sizeof(ReadCapdata_struct_16),
2020 1, logvol, 0, TYPE_CMD);
2021 }
2022 else {
2023 return_code = sendcmd(CCISS_READ_CAPACITY_16,
2024 ctlr, buf, sizeof(ReadCapdata_struct_16),
2025 1, logvol, 0, NULL, TYPE_CMD);
2026 }
2027 if (return_code == IO_OK) {
2028 *total_size = be64_to_cpu(*(__u64 *) buf->total_size)+1;
2029 *block_size = be32_to_cpu(*(__u32 *) buf->block_size);
2030 } else { /* read capacity command failed */
2031 printk(KERN_WARNING "cciss: read capacity failed\n");
2032 *total_size = 0;
2033 *block_size = BLOCK_SIZE;
2034 }
2035 printk(KERN_INFO " blocks= %lld block_size= %d\n",
1968 *total_size, *block_size); 2036 *total_size, *block_size);
2037 kfree(buf);
1969 return; 2038 return;
1970} 2039}
1971 2040
@@ -1976,8 +2045,7 @@ static int cciss_revalidate(struct gendisk *disk)
1976 int logvol; 2045 int logvol;
1977 int FOUND = 0; 2046 int FOUND = 0;
1978 unsigned int block_size; 2047 unsigned int block_size;
1979 unsigned int total_size; 2048 sector_t total_size;
1980 ReadCapdata_struct *size_buff = NULL;
1981 InquiryData_struct *inq_buff = NULL; 2049 InquiryData_struct *inq_buff = NULL;
1982 2050
1983 for (logvol = 0; logvol < CISS_MAX_LUN; logvol++) { 2051 for (logvol = 0; logvol < CISS_MAX_LUN; logvol++) {
@@ -1990,27 +2058,24 @@ static int cciss_revalidate(struct gendisk *disk)
1990 if (!FOUND) 2058 if (!FOUND)
1991 return 1; 2059 return 1;
1992 2060
1993 size_buff = kmalloc(sizeof(ReadCapdata_struct), GFP_KERNEL);
1994 if (size_buff == NULL) {
1995 printk(KERN_WARNING "cciss: out of memory\n");
1996 return 1;
1997 }
1998 inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL); 2061 inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL);
1999 if (inq_buff == NULL) { 2062 if (inq_buff == NULL) {
2000 printk(KERN_WARNING "cciss: out of memory\n"); 2063 printk(KERN_WARNING "cciss: out of memory\n");
2001 kfree(size_buff);
2002 return 1; 2064 return 1;
2003 } 2065 }
2004 2066 if (h->cciss_read == CCISS_READ_10) {
2005 cciss_read_capacity(h->ctlr, logvol, size_buff, 1, &total_size, 2067 cciss_read_capacity(h->ctlr, logvol, 1,
2006 &block_size); 2068 &total_size, &block_size);
2069 } else {
2070 cciss_read_capacity_16(h->ctlr, logvol, 1,
2071 &total_size, &block_size);
2072 }
2007 cciss_geometry_inquiry(h->ctlr, logvol, 1, total_size, block_size, 2073 cciss_geometry_inquiry(h->ctlr, logvol, 1, total_size, block_size,
2008 inq_buff, drv); 2074 inq_buff, drv);
2009 2075
2010 blk_queue_hardsect_size(drv->queue, drv->block_size); 2076 blk_queue_hardsect_size(drv->queue, drv->block_size);
2011 set_capacity(disk, drv->nr_blocks); 2077 set_capacity(disk, drv->nr_blocks);
2012 2078
2013 kfree(size_buff);
2014 kfree(inq_buff); 2079 kfree(inq_buff);
2015 return 0; 2080 return 0;
2016} 2081}
@@ -2419,7 +2484,8 @@ static void do_cciss_request(request_queue_t *q)
2419{ 2484{
2420 ctlr_info_t *h = q->queuedata; 2485 ctlr_info_t *h = q->queuedata;
2421 CommandList_struct *c; 2486 CommandList_struct *c;
2422 int start_blk, seg; 2487 sector_t start_blk;
2488 int seg;
2423 struct request *creq; 2489 struct request *creq;
2424 u64bit temp64; 2490 u64bit temp64;
2425 struct scatterlist tmp_sg[MAXSGENTRIES]; 2491 struct scatterlist tmp_sg[MAXSGENTRIES];
@@ -2463,10 +2529,10 @@ static void do_cciss_request(request_queue_t *q)
2463 c->Request.Type.Type = TYPE_CMD; // It is a command. 2529 c->Request.Type.Type = TYPE_CMD; // It is a command.
2464 c->Request.Type.Attribute = ATTR_SIMPLE; 2530 c->Request.Type.Attribute = ATTR_SIMPLE;
2465 c->Request.Type.Direction = 2531 c->Request.Type.Direction =
2466 (rq_data_dir(creq) == READ) ? XFER_READ : XFER_WRITE; 2532 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write;
2467 c->Request.Timeout = 0; // Don't time out 2533 c->Request.Timeout = 0; // Don't time out
2468 c->Request.CDB[0] = 2534 c->Request.CDB[0] =
2469 (rq_data_dir(creq) == READ) ? CCISS_READ : CCISS_WRITE; 2535 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write;
2470 start_blk = creq->sector; 2536 start_blk = creq->sector;
2471#ifdef CCISS_DEBUG 2537#ifdef CCISS_DEBUG
2472 printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n", (int)creq->sector, 2538 printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n", (int)creq->sector,
@@ -2500,15 +2566,33 @@ static void do_cciss_request(request_queue_t *q)
2500#endif /* CCISS_DEBUG */ 2566#endif /* CCISS_DEBUG */
2501 2567
2502 c->Header.SGList = c->Header.SGTotal = seg; 2568 c->Header.SGList = c->Header.SGTotal = seg;
2503 c->Request.CDB[1] = 0; 2569 if(h->cciss_read == CCISS_READ_10) {
2504 c->Request.CDB[2] = (start_blk >> 24) & 0xff; //MSB 2570 c->Request.CDB[1] = 0;
2505 c->Request.CDB[3] = (start_blk >> 16) & 0xff; 2571 c->Request.CDB[2] = (start_blk >> 24) & 0xff; //MSB
2506 c->Request.CDB[4] = (start_blk >> 8) & 0xff; 2572 c->Request.CDB[3] = (start_blk >> 16) & 0xff;
2507 c->Request.CDB[5] = start_blk & 0xff; 2573 c->Request.CDB[4] = (start_blk >> 8) & 0xff;
2508 c->Request.CDB[6] = 0; // (sect >> 24) & 0xff; MSB 2574 c->Request.CDB[5] = start_blk & 0xff;
2509 c->Request.CDB[7] = (creq->nr_sectors >> 8) & 0xff; 2575 c->Request.CDB[6] = 0; // (sect >> 24) & 0xff; MSB
2510 c->Request.CDB[8] = creq->nr_sectors & 0xff; 2576 c->Request.CDB[7] = (creq->nr_sectors >> 8) & 0xff;
2511 c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0; 2577 c->Request.CDB[8] = creq->nr_sectors & 0xff;
2578 c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0;
2579 } else {
2580 c->Request.CDBLen = 16;
2581 c->Request.CDB[1]= 0;
2582 c->Request.CDB[2]= (start_blk >> 56) & 0xff; //MSB
2583 c->Request.CDB[3]= (start_blk >> 48) & 0xff;
2584 c->Request.CDB[4]= (start_blk >> 40) & 0xff;
2585 c->Request.CDB[5]= (start_blk >> 32) & 0xff;
2586 c->Request.CDB[6]= (start_blk >> 24) & 0xff;
2587 c->Request.CDB[7]= (start_blk >> 16) & 0xff;
2588 c->Request.CDB[8]= (start_blk >> 8) & 0xff;
2589 c->Request.CDB[9]= start_blk & 0xff;
2590 c->Request.CDB[10]= (creq->nr_sectors >> 24) & 0xff;
2591 c->Request.CDB[11]= (creq->nr_sectors >> 16) & 0xff;
2592 c->Request.CDB[12]= (creq->nr_sectors >> 8) & 0xff;
2593 c->Request.CDB[13]= creq->nr_sectors & 0xff;
2594 c->Request.CDB[14] = c->Request.CDB[15] = 0;
2595 }
2512 2596
2513 spin_lock_irq(q->queue_lock); 2597 spin_lock_irq(q->queue_lock);
2514 2598
@@ -2518,9 +2602,9 @@ static void do_cciss_request(request_queue_t *q)
2518 h->maxQsinceinit = h->Qdepth; 2602 h->maxQsinceinit = h->Qdepth;
2519 2603
2520 goto queue; 2604 goto queue;
2521 full: 2605full:
2522 blk_stop_queue(q); 2606 blk_stop_queue(q);
2523 startio: 2607startio:
2524 /* We will already have the driver lock here so not need 2608 /* We will already have the driver lock here so not need
2525 * to lock it. 2609 * to lock it.
2526 */ 2610 */
@@ -2948,31 +3032,23 @@ static int cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
2948static void cciss_getgeometry(int cntl_num) 3032static void cciss_getgeometry(int cntl_num)
2949{ 3033{
2950 ReportLunData_struct *ld_buff; 3034 ReportLunData_struct *ld_buff;
2951 ReadCapdata_struct *size_buff;
2952 InquiryData_struct *inq_buff; 3035 InquiryData_struct *inq_buff;
2953 int return_code; 3036 int return_code;
2954 int i; 3037 int i;
2955 int listlength = 0; 3038 int listlength = 0;
2956 __u32 lunid = 0; 3039 __u32 lunid = 0;
2957 int block_size; 3040 int block_size;
2958 int total_size; 3041 sector_t total_size;
2959 3042
2960 ld_buff = kzalloc(sizeof(ReportLunData_struct), GFP_KERNEL); 3043 ld_buff = kzalloc(sizeof(ReportLunData_struct), GFP_KERNEL);
2961 if (ld_buff == NULL) { 3044 if (ld_buff == NULL) {
2962 printk(KERN_ERR "cciss: out of memory\n"); 3045 printk(KERN_ERR "cciss: out of memory\n");
2963 return; 3046 return;
2964 } 3047 }
2965 size_buff = kmalloc(sizeof(ReadCapdata_struct), GFP_KERNEL);
2966 if (size_buff == NULL) {
2967 printk(KERN_ERR "cciss: out of memory\n");
2968 kfree(ld_buff);
2969 return;
2970 }
2971 inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL); 3048 inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL);
2972 if (inq_buff == NULL) { 3049 if (inq_buff == NULL) {
2973 printk(KERN_ERR "cciss: out of memory\n"); 3050 printk(KERN_ERR "cciss: out of memory\n");
2974 kfree(ld_buff); 3051 kfree(ld_buff);
2975 kfree(size_buff);
2976 return; 3052 return;
2977 } 3053 }
2978 /* Get the firmware version */ 3054 /* Get the firmware version */
@@ -3027,7 +3103,6 @@ static void cciss_getgeometry(int cntl_num)
3027#endif /* CCISS_DEBUG */ 3103#endif /* CCISS_DEBUG */
3028 3104
3029 hba[cntl_num]->highest_lun = hba[cntl_num]->num_luns - 1; 3105 hba[cntl_num]->highest_lun = hba[cntl_num]->num_luns - 1;
3030// for(i=0; i< hba[cntl_num]->num_luns; i++)
3031 for (i = 0; i < CISS_MAX_LUN; i++) { 3106 for (i = 0; i < CISS_MAX_LUN; i++) {
3032 if (i < hba[cntl_num]->num_luns) { 3107 if (i < hba[cntl_num]->num_luns) {
3033 lunid = (0xff & (unsigned int)(ld_buff->LUN[i][3])) 3108 lunid = (0xff & (unsigned int)(ld_buff->LUN[i][3]))
@@ -3046,8 +3121,26 @@ static void cciss_getgeometry(int cntl_num)
3046 ld_buff->LUN[i][2], ld_buff->LUN[i][3], 3121 ld_buff->LUN[i][2], ld_buff->LUN[i][3],
3047 hba[cntl_num]->drv[i].LunID); 3122 hba[cntl_num]->drv[i].LunID);
3048#endif /* CCISS_DEBUG */ 3123#endif /* CCISS_DEBUG */
3049 cciss_read_capacity(cntl_num, i, size_buff, 0, 3124
3125 /* testing to see if 16-byte CDBs are already being used */
3126 if(hba[cntl_num]->cciss_read == CCISS_READ_16) {
3127 cciss_read_capacity_16(cntl_num, i, 0,
3050 &total_size, &block_size); 3128 &total_size, &block_size);
3129 goto geo_inq;
3130 }
3131 cciss_read_capacity(cntl_num, i, 0, &total_size, &block_size);
3132
3133 /* total_size = last LBA + 1 */
3134 if(total_size == (__u32) 0) {
3135 cciss_read_capacity_16(cntl_num, i, 0,
3136 &total_size, &block_size);
3137 hba[cntl_num]->cciss_read = CCISS_READ_16;
3138 hba[cntl_num]->cciss_write = CCISS_WRITE_16;
3139 } else {
3140 hba[cntl_num]->cciss_read = CCISS_READ_10;
3141 hba[cntl_num]->cciss_write = CCISS_WRITE_10;
3142 }
3143geo_inq:
3051 cciss_geometry_inquiry(cntl_num, i, 0, total_size, 3144 cciss_geometry_inquiry(cntl_num, i, 0, total_size,
3052 block_size, inq_buff, 3145 block_size, inq_buff,
3053 &hba[cntl_num]->drv[i]); 3146 &hba[cntl_num]->drv[i]);
@@ -3057,7 +3150,6 @@ static void cciss_getgeometry(int cntl_num)
3057 } 3150 }
3058 } 3151 }
3059 kfree(ld_buff); 3152 kfree(ld_buff);
3060 kfree(size_buff);
3061 kfree(inq_buff); 3153 kfree(inq_buff);
3062} 3154}
3063 3155
diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
index 868e0d862b0d..562235c1445a 100644
--- a/drivers/block/cciss.h
+++ b/drivers/block/cciss.h
@@ -76,6 +76,9 @@ struct ctlr_info
76 unsigned int intr[4]; 76 unsigned int intr[4];
77 unsigned int msix_vector; 77 unsigned int msix_vector;
78 unsigned int msi_vector; 78 unsigned int msi_vector;
79 BYTE cciss_read;
80 BYTE cciss_write;
81 BYTE cciss_read_capacity;
79 82
80 // information about each logical volume 83 // information about each logical volume
81 drive_info_struct drv[CISS_MAX_LUN]; 84 drive_info_struct drv[CISS_MAX_LUN];
diff --git a/drivers/block/cciss_cmd.h b/drivers/block/cciss_cmd.h
index 53fea549ba8b..4af7c4c0c7af 100644
--- a/drivers/block/cciss_cmd.h
+++ b/drivers/block/cciss_cmd.h
@@ -118,11 +118,34 @@ typedef struct _ReadCapdata_struct
118 BYTE block_size[4]; // Size of blocks in bytes 118 BYTE block_size[4]; // Size of blocks in bytes
119} ReadCapdata_struct; 119} ReadCapdata_struct;
120 120
121// 12 byte commands not implemented in firmware yet. 121#define CCISS_READ_CAPACITY_16 0x9e /* Read Capacity 16 */
122// #define CCISS_READ 0xa8 // Read(12) 122
123// #define CCISS_WRITE 0xaa // Write(12) 123/* service action to differentiate a 16 byte read capacity from
124 #define CCISS_READ 0x28 // Read(10) 124 other commands that use the 0x9e SCSI op code */
125 #define CCISS_WRITE 0x2a // Write(10) 125
126#define CCISS_READ_CAPACITY_16_SERVICE_ACT 0x10
127
128typedef struct _ReadCapdata_struct_16
129{
130 BYTE total_size[8]; /* Total size in blocks */
131 BYTE block_size[4]; /* Size of blocks in bytes */
132 BYTE prot_en:1; /* protection enable bit */
133 BYTE rto_en:1; /* reference tag own enable bit */
134 BYTE reserved:6; /* reserved bits */
135 BYTE reserved2[18]; /* reserved bytes per spec */
136} ReadCapdata_struct_16;
137
138/* Define the supported read/write commands for cciss based controllers */
139
140#define CCISS_READ_10 0x28 /* Read(10) */
141#define CCISS_WRITE_10 0x2a /* Write(10) */
142#define CCISS_READ_16 0x88 /* Read(16) */
143#define CCISS_WRITE_16 0x8a /* Write(16) */
144
145/* Define the CDB lengths supported by cciss based controllers */
146
147#define CDB_LEN10 10
148#define CDB_LEN16 16
126 149
127// BMIC commands 150// BMIC commands
128#define BMIC_READ 0x26 151#define BMIC_READ 0x26
diff --git a/drivers/block/cciss_scsi.c b/drivers/block/cciss_scsi.c
index 05f79d7393f7..bb15051ffbe0 100644
--- a/drivers/block/cciss_scsi.c
+++ b/drivers/block/cciss_scsi.c
@@ -766,7 +766,7 @@ cciss_scsi_do_simple_cmd(ctlr_info_t *c,
766 int direction) 766 int direction)
767{ 767{
768 unsigned long flags; 768 unsigned long flags;
769 DECLARE_COMPLETION(wait); 769 DECLARE_COMPLETION_ONSTACK(wait);
770 770
771 cp->cmd_type = CMD_IOCTL_PEND; // treat this like an ioctl 771 cp->cmd_type = CMD_IOCTL_PEND; // treat this like an ioctl
772 cp->scsi_cmd = NULL; 772 cp->scsi_cmd = NULL;
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index 78082edc14b4..4abc193314ee 100644
--- a/drivers/block/cpqarray.c
+++ b/drivers/block/cpqarray.c
@@ -989,7 +989,6 @@ static inline void complete_buffers(struct bio *bio, int ok)
989 xbh = bio->bi_next; 989 xbh = bio->bi_next;
990 bio->bi_next = NULL; 990 bio->bi_next = NULL;
991 991
992 blk_finished_io(nr_sectors);
993 bio_endio(bio, nr_sectors << 9, ok ? 0 : -EIO); 992 bio_endio(bio, nr_sectors << 9, ok ? 0 : -EIO);
994 993
995 bio = xbh; 994 bio = xbh;
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index ad1d7065a1b2..629c5769d994 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -2991,8 +2991,8 @@ static void do_fd_request(request_queue_t * q)
2991 if (usage_count == 0) { 2991 if (usage_count == 0) {
2992 printk("warning: usage count=0, current_req=%p exiting\n", 2992 printk("warning: usage count=0, current_req=%p exiting\n",
2993 current_req); 2993 current_req);
2994 printk("sect=%ld flags=%lx\n", (long)current_req->sector, 2994 printk("sect=%ld type=%x flags=%x\n", (long)current_req->sector,
2995 current_req->flags); 2995 current_req->cmd_type, current_req->cmd_flags);
2996 return; 2996 return;
2997 } 2997 }
2998 if (test_bit(0, &fdc_busy)) { 2998 if (test_bit(0, &fdc_busy)) {
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 7b3b94ddddcc..d6bb8da955a2 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -66,12 +66,14 @@
66#include <linux/swap.h> 66#include <linux/swap.h>
67#include <linux/slab.h> 67#include <linux/slab.h>
68#include <linux/loop.h> 68#include <linux/loop.h>
69#include <linux/compat.h>
69#include <linux/suspend.h> 70#include <linux/suspend.h>
70#include <linux/writeback.h> 71#include <linux/writeback.h>
71#include <linux/buffer_head.h> /* for invalidate_bdev() */ 72#include <linux/buffer_head.h> /* for invalidate_bdev() */
72#include <linux/completion.h> 73#include <linux/completion.h>
73#include <linux/highmem.h> 74#include <linux/highmem.h>
74#include <linux/gfp.h> 75#include <linux/gfp.h>
76#include <linux/kthread.h>
75 77
76#include <asm/uaccess.h> 78#include <asm/uaccess.h>
77 79
@@ -522,15 +524,12 @@ static int loop_make_request(request_queue_t *q, struct bio *old_bio)
522 goto out; 524 goto out;
523 if (unlikely(rw == WRITE && (lo->lo_flags & LO_FLAGS_READ_ONLY))) 525 if (unlikely(rw == WRITE && (lo->lo_flags & LO_FLAGS_READ_ONLY)))
524 goto out; 526 goto out;
525 lo->lo_pending++;
526 loop_add_bio(lo, old_bio); 527 loop_add_bio(lo, old_bio);
528 wake_up(&lo->lo_event);
527 spin_unlock_irq(&lo->lo_lock); 529 spin_unlock_irq(&lo->lo_lock);
528 complete(&lo->lo_bh_done);
529 return 0; 530 return 0;
530 531
531out: 532out:
532 if (lo->lo_pending == 0)
533 complete(&lo->lo_bh_done);
534 spin_unlock_irq(&lo->lo_lock); 533 spin_unlock_irq(&lo->lo_lock);
535 bio_io_error(old_bio, old_bio->bi_size); 534 bio_io_error(old_bio, old_bio->bi_size);
536 return 0; 535 return 0;
@@ -570,14 +569,18 @@ static inline void loop_handle_bio(struct loop_device *lo, struct bio *bio)
570 * to avoid blocking in our make_request_fn. it also does loop decrypting 569 * to avoid blocking in our make_request_fn. it also does loop decrypting
571 * on reads for block backed loop, as that is too heavy to do from 570 * on reads for block backed loop, as that is too heavy to do from
572 * b_end_io context where irqs may be disabled. 571 * b_end_io context where irqs may be disabled.
572 *
573 * Loop explanation: loop_clr_fd() sets lo_state to Lo_rundown before
574 * calling kthread_stop(). Therefore once kthread_should_stop() is
575 * true, make_request will not place any more requests. Therefore
576 * once kthread_should_stop() is true and lo_bio is NULL, we are
577 * done with the loop.
573 */ 578 */
574static int loop_thread(void *data) 579static int loop_thread(void *data)
575{ 580{
576 struct loop_device *lo = data; 581 struct loop_device *lo = data;
577 struct bio *bio; 582 struct bio *bio;
578 583
579 daemonize("loop%d", lo->lo_number);
580
581 /* 584 /*
582 * loop can be used in an encrypted device, 585 * loop can be used in an encrypted device,
583 * hence, it mustn't be stopped at all 586 * hence, it mustn't be stopped at all
@@ -587,47 +590,21 @@ static int loop_thread(void *data)
587 590
588 set_user_nice(current, -20); 591 set_user_nice(current, -20);
589 592
590 lo->lo_state = Lo_bound; 593 while (!kthread_should_stop() || lo->lo_bio) {
591 lo->lo_pending = 1;
592 594
593 /* 595 wait_event_interruptible(lo->lo_event,
594 * complete it, we are running 596 lo->lo_bio || kthread_should_stop());
595 */
596 complete(&lo->lo_done);
597
598 for (;;) {
599 int pending;
600 597
601 if (wait_for_completion_interruptible(&lo->lo_bh_done)) 598 if (!lo->lo_bio)
602 continue; 599 continue;
603
604 spin_lock_irq(&lo->lo_lock); 600 spin_lock_irq(&lo->lo_lock);
605
606 /*
607 * could be completed because of tear-down, not pending work
608 */
609 if (unlikely(!lo->lo_pending)) {
610 spin_unlock_irq(&lo->lo_lock);
611 break;
612 }
613
614 bio = loop_get_bio(lo); 601 bio = loop_get_bio(lo);
615 lo->lo_pending--;
616 pending = lo->lo_pending;
617 spin_unlock_irq(&lo->lo_lock); 602 spin_unlock_irq(&lo->lo_lock);
618 603
619 BUG_ON(!bio); 604 BUG_ON(!bio);
620 loop_handle_bio(lo, bio); 605 loop_handle_bio(lo, bio);
621
622 /*
623 * upped both for pending work and tear-down, lo_pending
624 * will hit zero then
625 */
626 if (unlikely(!pending))
627 break;
628 } 606 }
629 607
630 complete(&lo->lo_done);
631 return 0; 608 return 0;
632} 609}
633 610
@@ -662,7 +639,8 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
662 639
663 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask); 640 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
664 lo->lo_backing_file = file; 641 lo->lo_backing_file = file;
665 lo->lo_blocksize = mapping->host->i_blksize; 642 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
643 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
666 lo->old_gfp_mask = mapping_gfp_mask(mapping); 644 lo->old_gfp_mask = mapping_gfp_mask(mapping);
667 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS)); 645 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
668 complete(&p->wait); 646 complete(&p->wait);
@@ -794,7 +772,9 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file,
794 if (!(lo_flags & LO_FLAGS_USE_AOPS) && !file->f_op->write) 772 if (!(lo_flags & LO_FLAGS_USE_AOPS) && !file->f_op->write)
795 lo_flags |= LO_FLAGS_READ_ONLY; 773 lo_flags |= LO_FLAGS_READ_ONLY;
796 774
797 lo_blocksize = inode->i_blksize; 775 lo_blocksize = S_ISBLK(inode->i_mode) ?
776 inode->i_bdev->bd_block_size : PAGE_SIZE;
777
798 error = 0; 778 error = 0;
799 } else { 779 } else {
800 goto out_putf; 780 goto out_putf;
@@ -837,12 +817,26 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file,
837 817
838 set_blocksize(bdev, lo_blocksize); 818 set_blocksize(bdev, lo_blocksize);
839 819
840 error = kernel_thread(loop_thread, lo, CLONE_KERNEL); 820 lo->lo_thread = kthread_create(loop_thread, lo, "loop%d",
841 if (error < 0) 821 lo->lo_number);
842 goto out_putf; 822 if (IS_ERR(lo->lo_thread)) {
843 wait_for_completion(&lo->lo_done); 823 error = PTR_ERR(lo->lo_thread);
824 goto out_clr;
825 }
826 lo->lo_state = Lo_bound;
827 wake_up_process(lo->lo_thread);
844 return 0; 828 return 0;
845 829
830out_clr:
831 lo->lo_thread = NULL;
832 lo->lo_device = NULL;
833 lo->lo_backing_file = NULL;
834 lo->lo_flags = 0;
835 set_capacity(disks[lo->lo_number], 0);
836 invalidate_bdev(bdev, 0);
837 bd_set_size(bdev, 0);
838 mapping_set_gfp_mask(mapping, lo->old_gfp_mask);
839 lo->lo_state = Lo_unbound;
846 out_putf: 840 out_putf:
847 fput(file); 841 fput(file);
848 out: 842 out:
@@ -904,12 +898,9 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev)
904 898
905 spin_lock_irq(&lo->lo_lock); 899 spin_lock_irq(&lo->lo_lock);
906 lo->lo_state = Lo_rundown; 900 lo->lo_state = Lo_rundown;
907 lo->lo_pending--;
908 if (!lo->lo_pending)
909 complete(&lo->lo_bh_done);
910 spin_unlock_irq(&lo->lo_lock); 901 spin_unlock_irq(&lo->lo_lock);
911 902
912 wait_for_completion(&lo->lo_done); 903 kthread_stop(lo->lo_thread);
913 904
914 lo->lo_backing_file = NULL; 905 lo->lo_backing_file = NULL;
915 906
@@ -922,6 +913,7 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev)
922 lo->lo_sizelimit = 0; 913 lo->lo_sizelimit = 0;
923 lo->lo_encrypt_key_size = 0; 914 lo->lo_encrypt_key_size = 0;
924 lo->lo_flags = 0; 915 lo->lo_flags = 0;
916 lo->lo_thread = NULL;
925 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE); 917 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
926 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE); 918 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
927 memset(lo->lo_file_name, 0, LO_NAME_SIZE); 919 memset(lo->lo_file_name, 0, LO_NAME_SIZE);
@@ -1174,6 +1166,162 @@ static int lo_ioctl(struct inode * inode, struct file * file,
1174 return err; 1166 return err;
1175} 1167}
1176 1168
1169#ifdef CONFIG_COMPAT
1170struct compat_loop_info {
1171 compat_int_t lo_number; /* ioctl r/o */
1172 compat_dev_t lo_device; /* ioctl r/o */
1173 compat_ulong_t lo_inode; /* ioctl r/o */
1174 compat_dev_t lo_rdevice; /* ioctl r/o */
1175 compat_int_t lo_offset;
1176 compat_int_t lo_encrypt_type;
1177 compat_int_t lo_encrypt_key_size; /* ioctl w/o */
1178 compat_int_t lo_flags; /* ioctl r/o */
1179 char lo_name[LO_NAME_SIZE];
1180 unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */
1181 compat_ulong_t lo_init[2];
1182 char reserved[4];
1183};
1184
1185/*
1186 * Transfer 32-bit compatibility structure in userspace to 64-bit loop info
1187 * - noinlined to reduce stack space usage in main part of driver
1188 */
1189static noinline int
1190loop_info64_from_compat(const struct compat_loop_info *arg,
1191 struct loop_info64 *info64)
1192{
1193 struct compat_loop_info info;
1194
1195 if (copy_from_user(&info, arg, sizeof(info)))
1196 return -EFAULT;
1197
1198 memset(info64, 0, sizeof(*info64));
1199 info64->lo_number = info.lo_number;
1200 info64->lo_device = info.lo_device;
1201 info64->lo_inode = info.lo_inode;
1202 info64->lo_rdevice = info.lo_rdevice;
1203 info64->lo_offset = info.lo_offset;
1204 info64->lo_sizelimit = 0;
1205 info64->lo_encrypt_type = info.lo_encrypt_type;
1206 info64->lo_encrypt_key_size = info.lo_encrypt_key_size;
1207 info64->lo_flags = info.lo_flags;
1208 info64->lo_init[0] = info.lo_init[0];
1209 info64->lo_init[1] = info.lo_init[1];
1210 if (info.lo_encrypt_type == LO_CRYPT_CRYPTOAPI)
1211 memcpy(info64->lo_crypt_name, info.lo_name, LO_NAME_SIZE);
1212 else
1213 memcpy(info64->lo_file_name, info.lo_name, LO_NAME_SIZE);
1214 memcpy(info64->lo_encrypt_key, info.lo_encrypt_key, LO_KEY_SIZE);
1215 return 0;
1216}
1217
1218/*
1219 * Transfer 64-bit loop info to 32-bit compatibility structure in userspace
1220 * - noinlined to reduce stack space usage in main part of driver
1221 */
1222static noinline int
1223loop_info64_to_compat(const struct loop_info64 *info64,
1224 struct compat_loop_info __user *arg)
1225{
1226 struct compat_loop_info info;
1227
1228 memset(&info, 0, sizeof(info));
1229 info.lo_number = info64->lo_number;
1230 info.lo_device = info64->lo_device;
1231 info.lo_inode = info64->lo_inode;
1232 info.lo_rdevice = info64->lo_rdevice;
1233 info.lo_offset = info64->lo_offset;
1234 info.lo_encrypt_type = info64->lo_encrypt_type;
1235 info.lo_encrypt_key_size = info64->lo_encrypt_key_size;
1236 info.lo_flags = info64->lo_flags;
1237 info.lo_init[0] = info64->lo_init[0];
1238 info.lo_init[1] = info64->lo_init[1];
1239 if (info.lo_encrypt_type == LO_CRYPT_CRYPTOAPI)
1240 memcpy(info.lo_name, info64->lo_crypt_name, LO_NAME_SIZE);
1241 else
1242 memcpy(info.lo_name, info64->lo_file_name, LO_NAME_SIZE);
1243 memcpy(info.lo_encrypt_key, info64->lo_encrypt_key, LO_KEY_SIZE);
1244
1245 /* error in case values were truncated */
1246 if (info.lo_device != info64->lo_device ||
1247 info.lo_rdevice != info64->lo_rdevice ||
1248 info.lo_inode != info64->lo_inode ||
1249 info.lo_offset != info64->lo_offset ||
1250 info.lo_init[0] != info64->lo_init[0] ||
1251 info.lo_init[1] != info64->lo_init[1])
1252 return -EOVERFLOW;
1253
1254 if (copy_to_user(arg, &info, sizeof(info)))
1255 return -EFAULT;
1256 return 0;
1257}
1258
1259static int
1260loop_set_status_compat(struct loop_device *lo,
1261 const struct compat_loop_info __user *arg)
1262{
1263 struct loop_info64 info64;
1264 int ret;
1265
1266 ret = loop_info64_from_compat(arg, &info64);
1267 if (ret < 0)
1268 return ret;
1269 return loop_set_status(lo, &info64);
1270}
1271
1272static int
1273loop_get_status_compat(struct loop_device *lo,
1274 struct compat_loop_info __user *arg)
1275{
1276 struct loop_info64 info64;
1277 int err = 0;
1278
1279 if (!arg)
1280 err = -EINVAL;
1281 if (!err)
1282 err = loop_get_status(lo, &info64);
1283 if (!err)
1284 err = loop_info64_to_compat(&info64, arg);
1285 return err;
1286}
1287
1288static long lo_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1289{
1290 struct inode *inode = file->f_dentry->d_inode;
1291 struct loop_device *lo = inode->i_bdev->bd_disk->private_data;
1292 int err;
1293
1294 lock_kernel();
1295 switch(cmd) {
1296 case LOOP_SET_STATUS:
1297 mutex_lock(&lo->lo_ctl_mutex);
1298 err = loop_set_status_compat(
1299 lo, (const struct compat_loop_info __user *) arg);
1300 mutex_unlock(&lo->lo_ctl_mutex);
1301 break;
1302 case LOOP_GET_STATUS:
1303 mutex_lock(&lo->lo_ctl_mutex);
1304 err = loop_get_status_compat(
1305 lo, (struct compat_loop_info __user *) arg);
1306 mutex_unlock(&lo->lo_ctl_mutex);
1307 break;
1308 case LOOP_CLR_FD:
1309 case LOOP_GET_STATUS64:
1310 case LOOP_SET_STATUS64:
1311 arg = (unsigned long) compat_ptr(arg);
1312 case LOOP_SET_FD:
1313 case LOOP_CHANGE_FD:
1314 err = lo_ioctl(inode, file, cmd, arg);
1315 break;
1316 default:
1317 err = -ENOIOCTLCMD;
1318 break;
1319 }
1320 unlock_kernel();
1321 return err;
1322}
1323#endif
1324
1177static int lo_open(struct inode *inode, struct file *file) 1325static int lo_open(struct inode *inode, struct file *file)
1178{ 1326{
1179 struct loop_device *lo = inode->i_bdev->bd_disk->private_data; 1327 struct loop_device *lo = inode->i_bdev->bd_disk->private_data;
@@ -1201,6 +1349,9 @@ static struct block_device_operations lo_fops = {
1201 .open = lo_open, 1349 .open = lo_open,
1202 .release = lo_release, 1350 .release = lo_release,
1203 .ioctl = lo_ioctl, 1351 .ioctl = lo_ioctl,
1352#ifdef CONFIG_COMPAT
1353 .compat_ioctl = lo_compat_ioctl,
1354#endif
1204}; 1355};
1205 1356
1206/* 1357/*
@@ -1284,9 +1435,9 @@ static int __init loop_init(void)
1284 if (!lo->lo_queue) 1435 if (!lo->lo_queue)
1285 goto out_mem4; 1436 goto out_mem4;
1286 mutex_init(&lo->lo_ctl_mutex); 1437 mutex_init(&lo->lo_ctl_mutex);
1287 init_completion(&lo->lo_done);
1288 init_completion(&lo->lo_bh_done);
1289 lo->lo_number = i; 1438 lo->lo_number = i;
1439 lo->lo_thread = NULL;
1440 init_waitqueue_head(&lo->lo_event);
1290 spin_lock_init(&lo->lo_lock); 1441 spin_lock_init(&lo->lo_lock);
1291 disk->major = LOOP_MAJOR; 1442 disk->major = LOOP_MAJOR;
1292 disk->first_minor = i; 1443 disk->first_minor = i;
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index bdbade9a5cf5..9d1035e8d9d8 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -407,10 +407,10 @@ static void do_nbd_request(request_queue_t * q)
407 struct nbd_device *lo; 407 struct nbd_device *lo;
408 408
409 blkdev_dequeue_request(req); 409 blkdev_dequeue_request(req);
410 dprintk(DBG_BLKDEV, "%s: request %p: dequeued (flags=%lx)\n", 410 dprintk(DBG_BLKDEV, "%s: request %p: dequeued (flags=%x)\n",
411 req->rq_disk->disk_name, req, req->flags); 411 req->rq_disk->disk_name, req, req->cmd_type);
412 412
413 if (!(req->flags & REQ_CMD)) 413 if (!blk_fs_request(req))
414 goto error_out; 414 goto error_out;
415 415
416 lo = req->rq_disk->private_data; 416 lo = req->rq_disk->private_data;
@@ -489,7 +489,7 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
489 switch (cmd) { 489 switch (cmd) {
490 case NBD_DISCONNECT: 490 case NBD_DISCONNECT:
491 printk(KERN_INFO "%s: NBD_DISCONNECT\n", lo->disk->disk_name); 491 printk(KERN_INFO "%s: NBD_DISCONNECT\n", lo->disk->disk_name);
492 sreq.flags = REQ_SPECIAL; 492 sreq.cmd_type = REQ_TYPE_SPECIAL;
493 nbd_cmd(&sreq) = NBD_CMD_DISC; 493 nbd_cmd(&sreq) = NBD_CMD_DISC;
494 /* 494 /*
495 * Set these to sane values in case server implementation 495 * Set these to sane values in case server implementation
diff --git a/drivers/block/paride/pd.c b/drivers/block/paride/pd.c
index 2403721f9db1..40a11e567970 100644
--- a/drivers/block/paride/pd.c
+++ b/drivers/block/paride/pd.c
@@ -437,7 +437,7 @@ static char *pd_buf; /* buffer for request in progress */
437 437
438static enum action do_pd_io_start(void) 438static enum action do_pd_io_start(void)
439{ 439{
440 if (pd_req->flags & REQ_SPECIAL) { 440 if (blk_special_request(pd_req)) {
441 phase = pd_special; 441 phase = pd_special;
442 return pd_special(); 442 return pd_special();
443 } 443 }
@@ -713,20 +713,18 @@ static void do_pd_request(request_queue_t * q)
713static int pd_special_command(struct pd_unit *disk, 713static int pd_special_command(struct pd_unit *disk,
714 enum action (*func)(struct pd_unit *disk)) 714 enum action (*func)(struct pd_unit *disk))
715{ 715{
716 DECLARE_COMPLETION(wait); 716 DECLARE_COMPLETION_ONSTACK(wait);
717 struct request rq; 717 struct request rq;
718 int err = 0; 718 int err = 0;
719 719
720 memset(&rq, 0, sizeof(rq)); 720 memset(&rq, 0, sizeof(rq));
721 rq.errors = 0; 721 rq.errors = 0;
722 rq.rq_status = RQ_ACTIVE;
723 rq.rq_disk = disk->gd; 722 rq.rq_disk = disk->gd;
724 rq.ref_count = 1; 723 rq.ref_count = 1;
725 rq.waiting = &wait; 724 rq.end_io_data = &wait;
726 rq.end_io = blk_end_sync_rq; 725 rq.end_io = blk_end_sync_rq;
727 blk_insert_request(disk->gd->queue, &rq, 0, func); 726 blk_insert_request(disk->gd->queue, &rq, 0, func);
728 wait_for_completion(&wait); 727 wait_for_completion(&wait);
729 rq.waiting = NULL;
730 if (rq.errors) 728 if (rq.errors)
731 err = -EIO; 729 err = -EIO;
732 blk_put_request(&rq); 730 blk_put_request(&rq);
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 451b996bba91..a6b2aa67c9b2 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -348,7 +348,7 @@ static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *
348 char sense[SCSI_SENSE_BUFFERSIZE]; 348 char sense[SCSI_SENSE_BUFFERSIZE];
349 request_queue_t *q; 349 request_queue_t *q;
350 struct request *rq; 350 struct request *rq;
351 DECLARE_COMPLETION(wait); 351 DECLARE_COMPLETION_ONSTACK(wait);
352 int err = 0; 352 int err = 0;
353 353
354 q = bdev_get_queue(pd->bdev); 354 q = bdev_get_queue(pd->bdev);
@@ -365,17 +365,17 @@ static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *
365 rq->sense = sense; 365 rq->sense = sense;
366 memset(sense, 0, sizeof(sense)); 366 memset(sense, 0, sizeof(sense));
367 rq->sense_len = 0; 367 rq->sense_len = 0;
368 rq->flags |= REQ_BLOCK_PC | REQ_HARDBARRIER; 368 rq->cmd_type = REQ_TYPE_BLOCK_PC;
369 rq->cmd_flags |= REQ_HARDBARRIER;
369 if (cgc->quiet) 370 if (cgc->quiet)
370 rq->flags |= REQ_QUIET; 371 rq->cmd_flags |= REQ_QUIET;
371 memcpy(rq->cmd, cgc->cmd, CDROM_PACKET_SIZE); 372 memcpy(rq->cmd, cgc->cmd, CDROM_PACKET_SIZE);
372 if (sizeof(rq->cmd) > CDROM_PACKET_SIZE) 373 if (sizeof(rq->cmd) > CDROM_PACKET_SIZE)
373 memset(rq->cmd + CDROM_PACKET_SIZE, 0, sizeof(rq->cmd) - CDROM_PACKET_SIZE); 374 memset(rq->cmd + CDROM_PACKET_SIZE, 0, sizeof(rq->cmd) - CDROM_PACKET_SIZE);
374 rq->cmd_len = COMMAND_SIZE(rq->cmd[0]); 375 rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
375 376
376 rq->ref_count++; 377 rq->ref_count++;
377 rq->flags |= REQ_NOMERGE; 378 rq->end_io_data = &wait;
378 rq->waiting = &wait;
379 rq->end_io = blk_end_sync_rq; 379 rq->end_io = blk_end_sync_rq;
380 elv_add_request(q, rq, ELEVATOR_INSERT_BACK, 1); 380 elv_add_request(q, rq, ELEVATOR_INSERT_BACK, 1);
381 generic_unplug_device(q); 381 generic_unplug_device(q);
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index cc42e762396f..f2305ee792a1 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -319,8 +319,8 @@ static void start_request(struct floppy_state *fs)
319 printk("do_fd_req: dev=%s cmd=%d sec=%ld nr_sec=%ld buf=%p\n", 319 printk("do_fd_req: dev=%s cmd=%d sec=%ld nr_sec=%ld buf=%p\n",
320 req->rq_disk->disk_name, req->cmd, 320 req->rq_disk->disk_name, req->cmd,
321 (long)req->sector, req->nr_sectors, req->buffer); 321 (long)req->sector, req->nr_sectors, req->buffer);
322 printk(" rq_status=%d errors=%d current_nr_sectors=%ld\n", 322 printk(" errors=%d current_nr_sectors=%ld\n",
323 req->rq_status, req->errors, req->current_nr_sectors); 323 req->errors, req->current_nr_sectors);
324#endif 324#endif
325 325
326 if (req->sector < 0 || req->sector >= fs->total_secs) { 326 if (req->sector < 0 || req->sector >= fs->total_secs) {
diff --git a/drivers/block/swim_iop.c b/drivers/block/swim_iop.c
index 89e3c2f8b776..dfda796eba56 100644
--- a/drivers/block/swim_iop.c
+++ b/drivers/block/swim_iop.c
@@ -529,8 +529,8 @@ static void start_request(struct floppy_state *fs)
529 printk("do_fd_req: dev=%s cmd=%d sec=%ld nr_sec=%ld buf=%p\n", 529 printk("do_fd_req: dev=%s cmd=%d sec=%ld nr_sec=%ld buf=%p\n",
530 CURRENT->rq_disk->disk_name, CURRENT->cmd, 530 CURRENT->rq_disk->disk_name, CURRENT->cmd,
531 CURRENT->sector, CURRENT->nr_sectors, CURRENT->buffer); 531 CURRENT->sector, CURRENT->nr_sectors, CURRENT->buffer);
532 printk(" rq_status=%d errors=%d current_nr_sectors=%ld\n", 532 printk(" errors=%d current_nr_sectors=%ld\n",
533 CURRENT->rq_status, CURRENT->errors, CURRENT->current_nr_sectors); 533 CURRENT->errors, CURRENT->current_nr_sectors);
534#endif 534#endif
535 535
536 if (CURRENT->sector < 0 || CURRENT->sector >= fs->total_secs) { 536 if (CURRENT->sector < 0 || CURRENT->sector >= fs->total_secs) {
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index d62b49fbf10c..45a8f402b07b 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -358,7 +358,7 @@ static void ub_cmd_build_block(struct ub_dev *sc, struct ub_lun *lun,
358static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun, 358static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun,
359 struct ub_scsi_cmd *cmd, struct ub_request *urq); 359 struct ub_scsi_cmd *cmd, struct ub_request *urq);
360static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd); 360static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd);
361static void ub_end_rq(struct request *rq, int uptodate); 361static void ub_end_rq(struct request *rq, unsigned int status);
362static int ub_rw_cmd_retry(struct ub_dev *sc, struct ub_lun *lun, 362static int ub_rw_cmd_retry(struct ub_dev *sc, struct ub_lun *lun,
363 struct ub_request *urq, struct ub_scsi_cmd *cmd); 363 struct ub_request *urq, struct ub_scsi_cmd *cmd);
364static int ub_submit_scsi(struct ub_dev *sc, struct ub_scsi_cmd *cmd); 364static int ub_submit_scsi(struct ub_dev *sc, struct ub_scsi_cmd *cmd);
@@ -639,9 +639,15 @@ static int ub_request_fn_1(struct ub_lun *lun, struct request *rq)
639 struct ub_request *urq; 639 struct ub_request *urq;
640 int n_elem; 640 int n_elem;
641 641
642 if (atomic_read(&sc->poison) || lun->changed) { 642 if (atomic_read(&sc->poison)) {
643 blkdev_dequeue_request(rq);
644 ub_end_rq(rq, DID_NO_CONNECT << 16);
645 return 0;
646 }
647
648 if (lun->changed && !blk_pc_request(rq)) {
643 blkdev_dequeue_request(rq); 649 blkdev_dequeue_request(rq);
644 ub_end_rq(rq, 0); 650 ub_end_rq(rq, SAM_STAT_CHECK_CONDITION);
645 return 0; 651 return 0;
646 } 652 }
647 653
@@ -693,7 +699,7 @@ static int ub_request_fn_1(struct ub_lun *lun, struct request *rq)
693 699
694drop: 700drop:
695 ub_put_cmd(lun, cmd); 701 ub_put_cmd(lun, cmd);
696 ub_end_rq(rq, 0); 702 ub_end_rq(rq, DID_ERROR << 16);
697 return 0; 703 return 0;
698} 704}
699 705
@@ -761,47 +767,53 @@ static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
761 struct ub_lun *lun = cmd->lun; 767 struct ub_lun *lun = cmd->lun;
762 struct ub_request *urq = cmd->back; 768 struct ub_request *urq = cmd->back;
763 struct request *rq; 769 struct request *rq;
764 int uptodate; 770 unsigned int scsi_status;
765 771
766 rq = urq->rq; 772 rq = urq->rq;
767 773
768 if (cmd->error == 0) { 774 if (cmd->error == 0) {
769 uptodate = 1;
770
771 if (blk_pc_request(rq)) { 775 if (blk_pc_request(rq)) {
772 if (cmd->act_len >= rq->data_len) 776 if (cmd->act_len >= rq->data_len)
773 rq->data_len = 0; 777 rq->data_len = 0;
774 else 778 else
775 rq->data_len -= cmd->act_len; 779 rq->data_len -= cmd->act_len;
776 } 780 }
781 scsi_status = 0;
777 } else { 782 } else {
778 uptodate = 0;
779
780 if (blk_pc_request(rq)) { 783 if (blk_pc_request(rq)) {
781 /* UB_SENSE_SIZE is smaller than SCSI_SENSE_BUFFERSIZE */ 784 /* UB_SENSE_SIZE is smaller than SCSI_SENSE_BUFFERSIZE */
782 memcpy(rq->sense, sc->top_sense, UB_SENSE_SIZE); 785 memcpy(rq->sense, sc->top_sense, UB_SENSE_SIZE);
783 rq->sense_len = UB_SENSE_SIZE; 786 rq->sense_len = UB_SENSE_SIZE;
784 if (sc->top_sense[0] != 0) 787 if (sc->top_sense[0] != 0)
785 rq->errors = SAM_STAT_CHECK_CONDITION; 788 scsi_status = SAM_STAT_CHECK_CONDITION;
786 else 789 else
787 rq->errors = DID_ERROR << 16; 790 scsi_status = DID_ERROR << 16;
788 } else { 791 } else {
789 if (cmd->error == -EIO) { 792 if (cmd->error == -EIO) {
790 if (ub_rw_cmd_retry(sc, lun, urq, cmd) == 0) 793 if (ub_rw_cmd_retry(sc, lun, urq, cmd) == 0)
791 return; 794 return;
792 } 795 }
796 scsi_status = SAM_STAT_CHECK_CONDITION;
793 } 797 }
794 } 798 }
795 799
796 urq->rq = NULL; 800 urq->rq = NULL;
797 801
798 ub_put_cmd(lun, cmd); 802 ub_put_cmd(lun, cmd);
799 ub_end_rq(rq, uptodate); 803 ub_end_rq(rq, scsi_status);
800 blk_start_queue(lun->disk->queue); 804 blk_start_queue(lun->disk->queue);
801} 805}
802 806
803static void ub_end_rq(struct request *rq, int uptodate) 807static void ub_end_rq(struct request *rq, unsigned int scsi_status)
804{ 808{
809 int uptodate;
810
811 if (scsi_status == 0) {
812 uptodate = 1;
813 } else {
814 uptodate = 0;
815 rq->errors = scsi_status;
816 }
805 end_that_request_first(rq, uptodate, rq->hard_nr_sectors); 817 end_that_request_first(rq, uptodate, rq->hard_nr_sectors);
806 end_that_request_last(rq, uptodate); 818 end_that_request_last(rq, uptodate);
807} 819}
diff --git a/drivers/block/umem.c b/drivers/block/umem.c
index 5d8925bd9045..cbb9d0f21acc 100644
--- a/drivers/block/umem.c
+++ b/drivers/block/umem.c
@@ -552,7 +552,8 @@ static void process_page(unsigned long data)
552static int mm_make_request(request_queue_t *q, struct bio *bio) 552static int mm_make_request(request_queue_t *q, struct bio *bio)
553{ 553{
554 struct cardinfo *card = q->queuedata; 554 struct cardinfo *card = q->queuedata;
555 pr_debug("mm_make_request %ld %d\n", bh->b_rsector, bh->b_size); 555 pr_debug("mm_make_request %llu %u\n",
556 (unsigned long long)bio->bi_sector, bio->bi_size);
556 557
557 bio->bi_phys_segments = bio->bi_idx; /* count of completed segments*/ 558 bio->bi_phys_segments = bio->bi_idx; /* count of completed segments*/
558 spin_lock_irq(&card->lock); 559 spin_lock_irq(&card->lock);
diff --git a/drivers/block/xd.c b/drivers/block/xd.c
index e828e4cbd3e1..ebf3025721d1 100644
--- a/drivers/block/xd.c
+++ b/drivers/block/xd.c
@@ -313,7 +313,7 @@ static void do_xd_request (request_queue_t * q)
313 int res = 0; 313 int res = 0;
314 int retry; 314 int retry;
315 315
316 if (!(req->flags & REQ_CMD)) { 316 if (!blk_fs_request(req)) {
317 end_request(req, 0); 317 end_request(req, 0);
318 continue; 318 continue;
319 } 319 }
diff --git a/drivers/bluetooth/bfusb.c b/drivers/bluetooth/bfusb.c
index 23f96213f4ac..efcc28ec9d9a 100644
--- a/drivers/bluetooth/bfusb.c
+++ b/drivers/bluetooth/bfusb.c
@@ -2,7 +2,7 @@
2 * 2 *
3 * AVM BlueFRITZ! USB driver 3 * AVM BlueFRITZ! USB driver
4 * 4 *
5 * Copyright (C) 2003 Marcel Holtmann <marcel@holtmann.org> 5 * Copyright (C) 2003-2006 Marcel Holtmann <marcel@holtmann.org>
6 * 6 *
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
@@ -59,7 +59,6 @@ static struct usb_device_id bfusb_table[] = {
59 59
60MODULE_DEVICE_TABLE(usb, bfusb_table); 60MODULE_DEVICE_TABLE(usb, bfusb_table);
61 61
62
63#define BFUSB_MAX_BLOCK_SIZE 256 62#define BFUSB_MAX_BLOCK_SIZE 256
64 63
65#define BFUSB_BLOCK_TIMEOUT 3000 64#define BFUSB_BLOCK_TIMEOUT 3000
@@ -70,7 +69,7 @@ MODULE_DEVICE_TABLE(usb, bfusb_table);
70#define BFUSB_MAX_BULK_TX 2 69#define BFUSB_MAX_BULK_TX 2
71#define BFUSB_MAX_BULK_RX 2 70#define BFUSB_MAX_BULK_RX 2
72 71
73struct bfusb { 72struct bfusb_data {
74 struct hci_dev *hdev; 73 struct hci_dev *hdev;
75 74
76 unsigned long state; 75 unsigned long state;
@@ -92,137 +91,136 @@ struct bfusb {
92 struct sk_buff_head completed_q; 91 struct sk_buff_head completed_q;
93}; 92};
94 93
95struct bfusb_scb { 94struct bfusb_data_scb {
96 struct urb *urb; 95 struct urb *urb;
97}; 96};
98 97
99static void bfusb_tx_complete(struct urb *urb, struct pt_regs *regs); 98static void bfusb_tx_complete(struct urb *urb, struct pt_regs *regs);
100static void bfusb_rx_complete(struct urb *urb, struct pt_regs *regs); 99static void bfusb_rx_complete(struct urb *urb, struct pt_regs *regs);
101 100
102static struct urb *bfusb_get_completed(struct bfusb *bfusb) 101static struct urb *bfusb_get_completed(struct bfusb_data *data)
103{ 102{
104 struct sk_buff *skb; 103 struct sk_buff *skb;
105 struct urb *urb = NULL; 104 struct urb *urb = NULL;
106 105
107 BT_DBG("bfusb %p", bfusb); 106 BT_DBG("bfusb %p", data);
108 107
109 skb = skb_dequeue(&bfusb->completed_q); 108 skb = skb_dequeue(&data->completed_q);
110 if (skb) { 109 if (skb) {
111 urb = ((struct bfusb_scb *) skb->cb)->urb; 110 urb = ((struct bfusb_data_scb *) skb->cb)->urb;
112 kfree_skb(skb); 111 kfree_skb(skb);
113 } 112 }
114 113
115 return urb; 114 return urb;
116} 115}
117 116
118static void bfusb_unlink_urbs(struct bfusb *bfusb) 117static void bfusb_unlink_urbs(struct bfusb_data *data)
119{ 118{
120 struct sk_buff *skb; 119 struct sk_buff *skb;
121 struct urb *urb; 120 struct urb *urb;
122 121
123 BT_DBG("bfusb %p", bfusb); 122 BT_DBG("bfusb %p", data);
124 123
125 while ((skb = skb_dequeue(&bfusb->pending_q))) { 124 while ((skb = skb_dequeue(&data->pending_q))) {
126 urb = ((struct bfusb_scb *) skb->cb)->urb; 125 urb = ((struct bfusb_data_scb *) skb->cb)->urb;
127 usb_kill_urb(urb); 126 usb_kill_urb(urb);
128 skb_queue_tail(&bfusb->completed_q, skb); 127 skb_queue_tail(&data->completed_q, skb);
129 } 128 }
130 129
131 while ((urb = bfusb_get_completed(bfusb))) 130 while ((urb = bfusb_get_completed(data)))
132 usb_free_urb(urb); 131 usb_free_urb(urb);
133} 132}
134 133
135 134static int bfusb_send_bulk(struct bfusb_data *data, struct sk_buff *skb)
136static int bfusb_send_bulk(struct bfusb *bfusb, struct sk_buff *skb)
137{ 135{
138 struct bfusb_scb *scb = (void *) skb->cb; 136 struct bfusb_data_scb *scb = (void *) skb->cb;
139 struct urb *urb = bfusb_get_completed(bfusb); 137 struct urb *urb = bfusb_get_completed(data);
140 int err, pipe; 138 int err, pipe;
141 139
142 BT_DBG("bfusb %p skb %p len %d", bfusb, skb, skb->len); 140 BT_DBG("bfusb %p skb %p len %d", data, skb, skb->len);
143 141
144 if (!urb && !(urb = usb_alloc_urb(0, GFP_ATOMIC))) 142 if (!urb && !(urb = usb_alloc_urb(0, GFP_ATOMIC)))
145 return -ENOMEM; 143 return -ENOMEM;
146 144
147 pipe = usb_sndbulkpipe(bfusb->udev, bfusb->bulk_out_ep); 145 pipe = usb_sndbulkpipe(data->udev, data->bulk_out_ep);
148 146
149 usb_fill_bulk_urb(urb, bfusb->udev, pipe, skb->data, skb->len, 147 usb_fill_bulk_urb(urb, data->udev, pipe, skb->data, skb->len,
150 bfusb_tx_complete, skb); 148 bfusb_tx_complete, skb);
151 149
152 scb->urb = urb; 150 scb->urb = urb;
153 151
154 skb_queue_tail(&bfusb->pending_q, skb); 152 skb_queue_tail(&data->pending_q, skb);
155 153
156 err = usb_submit_urb(urb, GFP_ATOMIC); 154 err = usb_submit_urb(urb, GFP_ATOMIC);
157 if (err) { 155 if (err) {
158 BT_ERR("%s bulk tx submit failed urb %p err %d", 156 BT_ERR("%s bulk tx submit failed urb %p err %d",
159 bfusb->hdev->name, urb, err); 157 data->hdev->name, urb, err);
160 skb_unlink(skb, &bfusb->pending_q); 158 skb_unlink(skb, &data->pending_q);
161 usb_free_urb(urb); 159 usb_free_urb(urb);
162 } else 160 } else
163 atomic_inc(&bfusb->pending_tx); 161 atomic_inc(&data->pending_tx);
164 162
165 return err; 163 return err;
166} 164}
167 165
168static void bfusb_tx_wakeup(struct bfusb *bfusb) 166static void bfusb_tx_wakeup(struct bfusb_data *data)
169{ 167{
170 struct sk_buff *skb; 168 struct sk_buff *skb;
171 169
172 BT_DBG("bfusb %p", bfusb); 170 BT_DBG("bfusb %p", data);
173 171
174 if (test_and_set_bit(BFUSB_TX_PROCESS, &bfusb->state)) { 172 if (test_and_set_bit(BFUSB_TX_PROCESS, &data->state)) {
175 set_bit(BFUSB_TX_WAKEUP, &bfusb->state); 173 set_bit(BFUSB_TX_WAKEUP, &data->state);
176 return; 174 return;
177 } 175 }
178 176
179 do { 177 do {
180 clear_bit(BFUSB_TX_WAKEUP, &bfusb->state); 178 clear_bit(BFUSB_TX_WAKEUP, &data->state);
181 179
182 while ((atomic_read(&bfusb->pending_tx) < BFUSB_MAX_BULK_TX) && 180 while ((atomic_read(&data->pending_tx) < BFUSB_MAX_BULK_TX) &&
183 (skb = skb_dequeue(&bfusb->transmit_q))) { 181 (skb = skb_dequeue(&data->transmit_q))) {
184 if (bfusb_send_bulk(bfusb, skb) < 0) { 182 if (bfusb_send_bulk(data, skb) < 0) {
185 skb_queue_head(&bfusb->transmit_q, skb); 183 skb_queue_head(&data->transmit_q, skb);
186 break; 184 break;
187 } 185 }
188 } 186 }
189 187
190 } while (test_bit(BFUSB_TX_WAKEUP, &bfusb->state)); 188 } while (test_bit(BFUSB_TX_WAKEUP, &data->state));
191 189
192 clear_bit(BFUSB_TX_PROCESS, &bfusb->state); 190 clear_bit(BFUSB_TX_PROCESS, &data->state);
193} 191}
194 192
195static void bfusb_tx_complete(struct urb *urb, struct pt_regs *regs) 193static void bfusb_tx_complete(struct urb *urb, struct pt_regs *regs)
196{ 194{
197 struct sk_buff *skb = (struct sk_buff *) urb->context; 195 struct sk_buff *skb = (struct sk_buff *) urb->context;
198 struct bfusb *bfusb = (struct bfusb *) skb->dev; 196 struct bfusb_data *data = (struct bfusb_data *) skb->dev;
199 197
200 BT_DBG("bfusb %p urb %p skb %p len %d", bfusb, urb, skb, skb->len); 198 BT_DBG("bfusb %p urb %p skb %p len %d", data, urb, skb, skb->len);
201 199
202 atomic_dec(&bfusb->pending_tx); 200 atomic_dec(&data->pending_tx);
203 201
204 if (!test_bit(HCI_RUNNING, &bfusb->hdev->flags)) 202 if (!test_bit(HCI_RUNNING, &data->hdev->flags))
205 return; 203 return;
206 204
207 if (!urb->status) 205 if (!urb->status)
208 bfusb->hdev->stat.byte_tx += skb->len; 206 data->hdev->stat.byte_tx += skb->len;
209 else 207 else
210 bfusb->hdev->stat.err_tx++; 208 data->hdev->stat.err_tx++;
211 209
212 read_lock(&bfusb->lock); 210 read_lock(&data->lock);
213 211
214 skb_unlink(skb, &bfusb->pending_q); 212 skb_unlink(skb, &data->pending_q);
215 skb_queue_tail(&bfusb->completed_q, skb); 213 skb_queue_tail(&data->completed_q, skb);
216 214
217 bfusb_tx_wakeup(bfusb); 215 bfusb_tx_wakeup(data);
218 216
219 read_unlock(&bfusb->lock); 217 read_unlock(&data->lock);
220} 218}
221 219
222 220
223static int bfusb_rx_submit(struct bfusb *bfusb, struct urb *urb) 221static int bfusb_rx_submit(struct bfusb_data *data, struct urb *urb)
224{ 222{
225 struct bfusb_scb *scb; 223 struct bfusb_data_scb *scb;
226 struct sk_buff *skb; 224 struct sk_buff *skb;
227 int err, pipe, size = HCI_MAX_FRAME_SIZE + 32; 225 int err, pipe, size = HCI_MAX_FRAME_SIZE + 32;
228 226
@@ -231,28 +229,29 @@ static int bfusb_rx_submit(struct bfusb *bfusb, struct urb *urb)
231 if (!urb && !(urb = usb_alloc_urb(0, GFP_ATOMIC))) 229 if (!urb && !(urb = usb_alloc_urb(0, GFP_ATOMIC)))
232 return -ENOMEM; 230 return -ENOMEM;
233 231
234 if (!(skb = bt_skb_alloc(size, GFP_ATOMIC))) { 232 skb = bt_skb_alloc(size, GFP_ATOMIC);
233 if (!skb) {
235 usb_free_urb(urb); 234 usb_free_urb(urb);
236 return -ENOMEM; 235 return -ENOMEM;
237 } 236 }
238 237
239 skb->dev = (void *) bfusb; 238 skb->dev = (void *) data;
240 239
241 scb = (struct bfusb_scb *) skb->cb; 240 scb = (struct bfusb_data_scb *) skb->cb;
242 scb->urb = urb; 241 scb->urb = urb;
243 242
244 pipe = usb_rcvbulkpipe(bfusb->udev, bfusb->bulk_in_ep); 243 pipe = usb_rcvbulkpipe(data->udev, data->bulk_in_ep);
245 244
246 usb_fill_bulk_urb(urb, bfusb->udev, pipe, skb->data, size, 245 usb_fill_bulk_urb(urb, data->udev, pipe, skb->data, size,
247 bfusb_rx_complete, skb); 246 bfusb_rx_complete, skb);
248 247
249 skb_queue_tail(&bfusb->pending_q, skb); 248 skb_queue_tail(&data->pending_q, skb);
250 249
251 err = usb_submit_urb(urb, GFP_ATOMIC); 250 err = usb_submit_urb(urb, GFP_ATOMIC);
252 if (err) { 251 if (err) {
253 BT_ERR("%s bulk rx submit failed urb %p err %d", 252 BT_ERR("%s bulk rx submit failed urb %p err %d",
254 bfusb->hdev->name, urb, err); 253 data->hdev->name, urb, err);
255 skb_unlink(skb, &bfusb->pending_q); 254 skb_unlink(skb, &data->pending_q);
256 kfree_skb(skb); 255 kfree_skb(skb);
257 usb_free_urb(urb); 256 usb_free_urb(urb);
258 } 257 }
@@ -260,15 +259,15 @@ static int bfusb_rx_submit(struct bfusb *bfusb, struct urb *urb)
260 return err; 259 return err;
261} 260}
262 261
263static inline int bfusb_recv_block(struct bfusb *bfusb, int hdr, unsigned char *data, int len) 262static inline int bfusb_recv_block(struct bfusb_data *data, int hdr, unsigned char *buf, int len)
264{ 263{
265 BT_DBG("bfusb %p hdr 0x%02x data %p len %d", bfusb, hdr, data, len); 264 BT_DBG("bfusb %p hdr 0x%02x data %p len %d", data, hdr, buf, len);
266 265
267 if (hdr & 0x10) { 266 if (hdr & 0x10) {
268 BT_ERR("%s error in block", bfusb->hdev->name); 267 BT_ERR("%s error in block", data->hdev->name);
269 if (bfusb->reassembly) 268 if (data->reassembly)
270 kfree_skb(bfusb->reassembly); 269 kfree_skb(data->reassembly);
271 bfusb->reassembly = NULL; 270 data->reassembly = NULL;
272 return -EIO; 271 return -EIO;
273 } 272 }
274 273
@@ -277,46 +276,46 @@ static inline int bfusb_recv_block(struct bfusb *bfusb, int hdr, unsigned char *
277 unsigned char pkt_type; 276 unsigned char pkt_type;
278 int pkt_len = 0; 277 int pkt_len = 0;
279 278
280 if (bfusb->reassembly) { 279 if (data->reassembly) {
281 BT_ERR("%s unexpected start block", bfusb->hdev->name); 280 BT_ERR("%s unexpected start block", data->hdev->name);
282 kfree_skb(bfusb->reassembly); 281 kfree_skb(data->reassembly);
283 bfusb->reassembly = NULL; 282 data->reassembly = NULL;
284 } 283 }
285 284
286 if (len < 1) { 285 if (len < 1) {
287 BT_ERR("%s no packet type found", bfusb->hdev->name); 286 BT_ERR("%s no packet type found", data->hdev->name);
288 return -EPROTO; 287 return -EPROTO;
289 } 288 }
290 289
291 pkt_type = *data++; len--; 290 pkt_type = *buf++; len--;
292 291
293 switch (pkt_type) { 292 switch (pkt_type) {
294 case HCI_EVENT_PKT: 293 case HCI_EVENT_PKT:
295 if (len >= HCI_EVENT_HDR_SIZE) { 294 if (len >= HCI_EVENT_HDR_SIZE) {
296 struct hci_event_hdr *hdr = (struct hci_event_hdr *) data; 295 struct hci_event_hdr *hdr = (struct hci_event_hdr *) buf;
297 pkt_len = HCI_EVENT_HDR_SIZE + hdr->plen; 296 pkt_len = HCI_EVENT_HDR_SIZE + hdr->plen;
298 } else { 297 } else {
299 BT_ERR("%s event block is too short", bfusb->hdev->name); 298 BT_ERR("%s event block is too short", data->hdev->name);
300 return -EILSEQ; 299 return -EILSEQ;
301 } 300 }
302 break; 301 break;
303 302
304 case HCI_ACLDATA_PKT: 303 case HCI_ACLDATA_PKT:
305 if (len >= HCI_ACL_HDR_SIZE) { 304 if (len >= HCI_ACL_HDR_SIZE) {
306 struct hci_acl_hdr *hdr = (struct hci_acl_hdr *) data; 305 struct hci_acl_hdr *hdr = (struct hci_acl_hdr *) buf;
307 pkt_len = HCI_ACL_HDR_SIZE + __le16_to_cpu(hdr->dlen); 306 pkt_len = HCI_ACL_HDR_SIZE + __le16_to_cpu(hdr->dlen);
308 } else { 307 } else {
309 BT_ERR("%s data block is too short", bfusb->hdev->name); 308 BT_ERR("%s data block is too short", data->hdev->name);
310 return -EILSEQ; 309 return -EILSEQ;
311 } 310 }
312 break; 311 break;
313 312
314 case HCI_SCODATA_PKT: 313 case HCI_SCODATA_PKT:
315 if (len >= HCI_SCO_HDR_SIZE) { 314 if (len >= HCI_SCO_HDR_SIZE) {
316 struct hci_sco_hdr *hdr = (struct hci_sco_hdr *) data; 315 struct hci_sco_hdr *hdr = (struct hci_sco_hdr *) buf;
317 pkt_len = HCI_SCO_HDR_SIZE + hdr->dlen; 316 pkt_len = HCI_SCO_HDR_SIZE + hdr->dlen;
318 } else { 317 } else {
319 BT_ERR("%s audio block is too short", bfusb->hdev->name); 318 BT_ERR("%s audio block is too short", data->hdev->name);
320 return -EILSEQ; 319 return -EILSEQ;
321 } 320 }
322 break; 321 break;
@@ -324,27 +323,27 @@ static inline int bfusb_recv_block(struct bfusb *bfusb, int hdr, unsigned char *
324 323
325 skb = bt_skb_alloc(pkt_len, GFP_ATOMIC); 324 skb = bt_skb_alloc(pkt_len, GFP_ATOMIC);
326 if (!skb) { 325 if (!skb) {
327 BT_ERR("%s no memory for the packet", bfusb->hdev->name); 326 BT_ERR("%s no memory for the packet", data->hdev->name);
328 return -ENOMEM; 327 return -ENOMEM;
329 } 328 }
330 329
331 skb->dev = (void *) bfusb->hdev; 330 skb->dev = (void *) data->hdev;
332 bt_cb(skb)->pkt_type = pkt_type; 331 bt_cb(skb)->pkt_type = pkt_type;
333 332
334 bfusb->reassembly = skb; 333 data->reassembly = skb;
335 } else { 334 } else {
336 if (!bfusb->reassembly) { 335 if (!data->reassembly) {
337 BT_ERR("%s unexpected continuation block", bfusb->hdev->name); 336 BT_ERR("%s unexpected continuation block", data->hdev->name);
338 return -EIO; 337 return -EIO;
339 } 338 }
340 } 339 }
341 340
342 if (len > 0) 341 if (len > 0)
343 memcpy(skb_put(bfusb->reassembly, len), data, len); 342 memcpy(skb_put(data->reassembly, len), buf, len);
344 343
345 if (hdr & 0x08) { 344 if (hdr & 0x08) {
346 hci_recv_frame(bfusb->reassembly); 345 hci_recv_frame(data->reassembly);
347 bfusb->reassembly = NULL; 346 data->reassembly = NULL;
348 } 347 }
349 348
350 return 0; 349 return 0;
@@ -353,22 +352,22 @@ static inline int bfusb_recv_block(struct bfusb *bfusb, int hdr, unsigned char *
353static void bfusb_rx_complete(struct urb *urb, struct pt_regs *regs) 352static void bfusb_rx_complete(struct urb *urb, struct pt_regs *regs)
354{ 353{
355 struct sk_buff *skb = (struct sk_buff *) urb->context; 354 struct sk_buff *skb = (struct sk_buff *) urb->context;
356 struct bfusb *bfusb = (struct bfusb *) skb->dev; 355 struct bfusb_data *data = (struct bfusb_data *) skb->dev;
357 unsigned char *buf = urb->transfer_buffer; 356 unsigned char *buf = urb->transfer_buffer;
358 int count = urb->actual_length; 357 int count = urb->actual_length;
359 int err, hdr, len; 358 int err, hdr, len;
360 359
361 BT_DBG("bfusb %p urb %p skb %p len %d", bfusb, urb, skb, skb->len); 360 BT_DBG("bfusb %p urb %p skb %p len %d", bfusb, urb, skb, skb->len);
362 361
363 read_lock(&bfusb->lock); 362 read_lock(&data->lock);
364 363
365 if (!test_bit(HCI_RUNNING, &bfusb->hdev->flags)) 364 if (!test_bit(HCI_RUNNING, &data->hdev->flags))
366 goto unlock; 365 goto unlock;
367 366
368 if (urb->status || !count) 367 if (urb->status || !count)
369 goto resubmit; 368 goto resubmit;
370 369
371 bfusb->hdev->stat.byte_rx += count; 370 data->hdev->stat.byte_rx += count;
372 371
373 skb_put(skb, count); 372 skb_put(skb, count);
374 373
@@ -387,90 +386,89 @@ static void bfusb_rx_complete(struct urb *urb, struct pt_regs *regs)
387 386
388 if (count < len) { 387 if (count < len) {
389 BT_ERR("%s block extends over URB buffer ranges", 388 BT_ERR("%s block extends over URB buffer ranges",
390 bfusb->hdev->name); 389 data->hdev->name);
391 } 390 }
392 391
393 if ((hdr & 0xe1) == 0xc1) 392 if ((hdr & 0xe1) == 0xc1)
394 bfusb_recv_block(bfusb, hdr, buf, len); 393 bfusb_recv_block(data, hdr, buf, len);
395 394
396 count -= len; 395 count -= len;
397 buf += len; 396 buf += len;
398 } 397 }
399 398
400 skb_unlink(skb, &bfusb->pending_q); 399 skb_unlink(skb, &data->pending_q);
401 kfree_skb(skb); 400 kfree_skb(skb);
402 401
403 bfusb_rx_submit(bfusb, urb); 402 bfusb_rx_submit(data, urb);
404 403
405 read_unlock(&bfusb->lock); 404 read_unlock(&data->lock);
406 405
407 return; 406 return;
408 407
409resubmit: 408resubmit:
410 urb->dev = bfusb->udev; 409 urb->dev = data->udev;
411 410
412 err = usb_submit_urb(urb, GFP_ATOMIC); 411 err = usb_submit_urb(urb, GFP_ATOMIC);
413 if (err) { 412 if (err) {
414 BT_ERR("%s bulk resubmit failed urb %p err %d", 413 BT_ERR("%s bulk resubmit failed urb %p err %d",
415 bfusb->hdev->name, urb, err); 414 data->hdev->name, urb, err);
416 } 415 }
417 416
418unlock: 417unlock:
419 read_unlock(&bfusb->lock); 418 read_unlock(&data->lock);
420} 419}
421 420
422
423static int bfusb_open(struct hci_dev *hdev) 421static int bfusb_open(struct hci_dev *hdev)
424{ 422{
425 struct bfusb *bfusb = (struct bfusb *) hdev->driver_data; 423 struct bfusb_data *data = hdev->driver_data;
426 unsigned long flags; 424 unsigned long flags;
427 int i, err; 425 int i, err;
428 426
429 BT_DBG("hdev %p bfusb %p", hdev, bfusb); 427 BT_DBG("hdev %p bfusb %p", hdev, data);
430 428
431 if (test_and_set_bit(HCI_RUNNING, &hdev->flags)) 429 if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
432 return 0; 430 return 0;
433 431
434 write_lock_irqsave(&bfusb->lock, flags); 432 write_lock_irqsave(&data->lock, flags);
435 433
436 err = bfusb_rx_submit(bfusb, NULL); 434 err = bfusb_rx_submit(data, NULL);
437 if (!err) { 435 if (!err) {
438 for (i = 1; i < BFUSB_MAX_BULK_RX; i++) 436 for (i = 1; i < BFUSB_MAX_BULK_RX; i++)
439 bfusb_rx_submit(bfusb, NULL); 437 bfusb_rx_submit(data, NULL);
440 } else { 438 } else {
441 clear_bit(HCI_RUNNING, &hdev->flags); 439 clear_bit(HCI_RUNNING, &hdev->flags);
442 } 440 }
443 441
444 write_unlock_irqrestore(&bfusb->lock, flags); 442 write_unlock_irqrestore(&data->lock, flags);
445 443
446 return err; 444 return err;
447} 445}
448 446
449static int bfusb_flush(struct hci_dev *hdev) 447static int bfusb_flush(struct hci_dev *hdev)
450{ 448{
451 struct bfusb *bfusb = (struct bfusb *) hdev->driver_data; 449 struct bfusb_data *data = hdev->driver_data;
452 450
453 BT_DBG("hdev %p bfusb %p", hdev, bfusb); 451 BT_DBG("hdev %p bfusb %p", hdev, data);
454 452
455 skb_queue_purge(&bfusb->transmit_q); 453 skb_queue_purge(&data->transmit_q);
456 454
457 return 0; 455 return 0;
458} 456}
459 457
460static int bfusb_close(struct hci_dev *hdev) 458static int bfusb_close(struct hci_dev *hdev)
461{ 459{
462 struct bfusb *bfusb = (struct bfusb *) hdev->driver_data; 460 struct bfusb_data *data = hdev->driver_data;
463 unsigned long flags; 461 unsigned long flags;
464 462
465 BT_DBG("hdev %p bfusb %p", hdev, bfusb); 463 BT_DBG("hdev %p bfusb %p", hdev, data);
466 464
467 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) 465 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
468 return 0; 466 return 0;
469 467
470 write_lock_irqsave(&bfusb->lock, flags); 468 write_lock_irqsave(&data->lock, flags);
471 write_unlock_irqrestore(&bfusb->lock, flags); 469 write_unlock_irqrestore(&data->lock, flags);
472 470
473 bfusb_unlink_urbs(bfusb); 471 bfusb_unlink_urbs(data);
474 bfusb_flush(hdev); 472 bfusb_flush(hdev);
475 473
476 return 0; 474 return 0;
@@ -479,7 +477,7 @@ static int bfusb_close(struct hci_dev *hdev)
479static int bfusb_send_frame(struct sk_buff *skb) 477static int bfusb_send_frame(struct sk_buff *skb)
480{ 478{
481 struct hci_dev *hdev = (struct hci_dev *) skb->dev; 479 struct hci_dev *hdev = (struct hci_dev *) skb->dev;
482 struct bfusb *bfusb; 480 struct bfusb_data *data;
483 struct sk_buff *nskb; 481 struct sk_buff *nskb;
484 unsigned char buf[3]; 482 unsigned char buf[3];
485 int sent = 0, size, count; 483 int sent = 0, size, count;
@@ -494,7 +492,7 @@ static int bfusb_send_frame(struct sk_buff *skb)
494 if (!test_bit(HCI_RUNNING, &hdev->flags)) 492 if (!test_bit(HCI_RUNNING, &hdev->flags))
495 return -EBUSY; 493 return -EBUSY;
496 494
497 bfusb = (struct bfusb *) hdev->driver_data; 495 data = hdev->driver_data;
498 496
499 switch (bt_cb(skb)->pkt_type) { 497 switch (bt_cb(skb)->pkt_type) {
500 case HCI_COMMAND_PKT: 498 case HCI_COMMAND_PKT:
@@ -514,12 +512,13 @@ static int bfusb_send_frame(struct sk_buff *skb)
514 count = skb->len; 512 count = skb->len;
515 513
516 /* Max HCI frame size seems to be 1511 + 1 */ 514 /* Max HCI frame size seems to be 1511 + 1 */
517 if (!(nskb = bt_skb_alloc(count + 32, GFP_ATOMIC))) { 515 nskb = bt_skb_alloc(count + 32, GFP_ATOMIC);
516 if (!nskb) {
518 BT_ERR("Can't allocate memory for new packet"); 517 BT_ERR("Can't allocate memory for new packet");
519 return -ENOMEM; 518 return -ENOMEM;
520 } 519 }
521 520
522 nskb->dev = (void *) bfusb; 521 nskb->dev = (void *) data;
523 522
524 while (count) { 523 while (count) {
525 size = min_t(uint, count, BFUSB_MAX_BLOCK_SIZE); 524 size = min_t(uint, count, BFUSB_MAX_BLOCK_SIZE);
@@ -536,18 +535,18 @@ static int bfusb_send_frame(struct sk_buff *skb)
536 } 535 }
537 536
538 /* Don't send frame with multiple size of bulk max packet */ 537 /* Don't send frame with multiple size of bulk max packet */
539 if ((nskb->len % bfusb->bulk_pkt_size) == 0) { 538 if ((nskb->len % data->bulk_pkt_size) == 0) {
540 buf[0] = 0xdd; 539 buf[0] = 0xdd;
541 buf[1] = 0x00; 540 buf[1] = 0x00;
542 memcpy(skb_put(nskb, 2), buf, 2); 541 memcpy(skb_put(nskb, 2), buf, 2);
543 } 542 }
544 543
545 read_lock(&bfusb->lock); 544 read_lock(&data->lock);
546 545
547 skb_queue_tail(&bfusb->transmit_q, nskb); 546 skb_queue_tail(&data->transmit_q, nskb);
548 bfusb_tx_wakeup(bfusb); 547 bfusb_tx_wakeup(data);
549 548
550 read_unlock(&bfusb->lock); 549 read_unlock(&data->lock);
551 550
552 kfree_skb(skb); 551 kfree_skb(skb);
553 552
@@ -556,11 +555,11 @@ static int bfusb_send_frame(struct sk_buff *skb)
556 555
557static void bfusb_destruct(struct hci_dev *hdev) 556static void bfusb_destruct(struct hci_dev *hdev)
558{ 557{
559 struct bfusb *bfusb = (struct bfusb *) hdev->driver_data; 558 struct bfusb_data *data = hdev->driver_data;
560 559
561 BT_DBG("hdev %p bfusb %p", hdev, bfusb); 560 BT_DBG("hdev %p bfusb %p", hdev, data);
562 561
563 kfree(bfusb); 562 kfree(data);
564} 563}
565 564
566static int bfusb_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg) 565static int bfusb_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
@@ -568,25 +567,24 @@ static int bfusb_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg
568 return -ENOIOCTLCMD; 567 return -ENOIOCTLCMD;
569} 568}
570 569
571 570static int bfusb_load_firmware(struct bfusb_data *data, unsigned char *firmware, int count)
572static int bfusb_load_firmware(struct bfusb *bfusb, unsigned char *firmware, int count)
573{ 571{
574 unsigned char *buf; 572 unsigned char *buf;
575 int err, pipe, len, size, sent = 0; 573 int err, pipe, len, size, sent = 0;
576 574
577 BT_DBG("bfusb %p udev %p", bfusb, bfusb->udev); 575 BT_DBG("bfusb %p udev %p", data, data->udev);
578 576
579 BT_INFO("BlueFRITZ! USB loading firmware"); 577 BT_INFO("BlueFRITZ! USB loading firmware");
580 578
581 pipe = usb_sndctrlpipe(bfusb->udev, 0); 579 pipe = usb_sndctrlpipe(data->udev, 0);
582 580
583 if (usb_control_msg(bfusb->udev, pipe, USB_REQ_SET_CONFIGURATION, 581 if (usb_control_msg(data->udev, pipe, USB_REQ_SET_CONFIGURATION,
584 0, 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT) < 0) { 582 0, 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT) < 0) {
585 BT_ERR("Can't change to loading configuration"); 583 BT_ERR("Can't change to loading configuration");
586 return -EBUSY; 584 return -EBUSY;
587 } 585 }
588 586
589 bfusb->udev->toggle[0] = bfusb->udev->toggle[1] = 0; 587 data->udev->toggle[0] = data->udev->toggle[1] = 0;
590 588
591 buf = kmalloc(BFUSB_MAX_BLOCK_SIZE + 3, GFP_ATOMIC); 589 buf = kmalloc(BFUSB_MAX_BLOCK_SIZE + 3, GFP_ATOMIC);
592 if (!buf) { 590 if (!buf) {
@@ -594,14 +592,14 @@ static int bfusb_load_firmware(struct bfusb *bfusb, unsigned char *firmware, int
594 return -ENOMEM; 592 return -ENOMEM;
595 } 593 }
596 594
597 pipe = usb_sndbulkpipe(bfusb->udev, bfusb->bulk_out_ep); 595 pipe = usb_sndbulkpipe(data->udev, data->bulk_out_ep);
598 596
599 while (count) { 597 while (count) {
600 size = min_t(uint, count, BFUSB_MAX_BLOCK_SIZE + 3); 598 size = min_t(uint, count, BFUSB_MAX_BLOCK_SIZE + 3);
601 599
602 memcpy(buf, firmware + sent, size); 600 memcpy(buf, firmware + sent, size);
603 601
604 err = usb_bulk_msg(bfusb->udev, pipe, buf, size, 602 err = usb_bulk_msg(data->udev, pipe, buf, size,
605 &len, BFUSB_BLOCK_TIMEOUT); 603 &len, BFUSB_BLOCK_TIMEOUT);
606 604
607 if (err || (len != size)) { 605 if (err || (len != size)) {
@@ -613,21 +611,23 @@ static int bfusb_load_firmware(struct bfusb *bfusb, unsigned char *firmware, int
613 count -= size; 611 count -= size;
614 } 612 }
615 613
616 if ((err = usb_bulk_msg(bfusb->udev, pipe, NULL, 0, 614 err = usb_bulk_msg(data->udev, pipe, NULL, 0,
617 &len, BFUSB_BLOCK_TIMEOUT)) < 0) { 615 &len, BFUSB_BLOCK_TIMEOUT);
616 if (err < 0) {
618 BT_ERR("Error in null packet request"); 617 BT_ERR("Error in null packet request");
619 goto error; 618 goto error;
620 } 619 }
621 620
622 pipe = usb_sndctrlpipe(bfusb->udev, 0); 621 pipe = usb_sndctrlpipe(data->udev, 0);
623 622
624 if ((err = usb_control_msg(bfusb->udev, pipe, USB_REQ_SET_CONFIGURATION, 623 err = usb_control_msg(data->udev, pipe, USB_REQ_SET_CONFIGURATION,
625 0, 2, 0, NULL, 0, USB_CTRL_SET_TIMEOUT)) < 0) { 624 0, 2, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
625 if (err < 0) {
626 BT_ERR("Can't change to running configuration"); 626 BT_ERR("Can't change to running configuration");
627 goto error; 627 goto error;
628 } 628 }
629 629
630 bfusb->udev->toggle[0] = bfusb->udev->toggle[1] = 0; 630 data->udev->toggle[0] = data->udev->toggle[1] = 0;
631 631
632 BT_INFO("BlueFRITZ! USB device ready"); 632 BT_INFO("BlueFRITZ! USB device ready");
633 633
@@ -637,9 +637,9 @@ static int bfusb_load_firmware(struct bfusb *bfusb, unsigned char *firmware, int
637error: 637error:
638 kfree(buf); 638 kfree(buf);
639 639
640 pipe = usb_sndctrlpipe(bfusb->udev, 0); 640 pipe = usb_sndctrlpipe(data->udev, 0);
641 641
642 usb_control_msg(bfusb->udev, pipe, USB_REQ_SET_CONFIGURATION, 642 usb_control_msg(data->udev, pipe, USB_REQ_SET_CONFIGURATION,
643 0, 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); 643 0, 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
644 644
645 return err; 645 return err;
@@ -652,7 +652,7 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i
652 struct usb_host_endpoint *bulk_out_ep; 652 struct usb_host_endpoint *bulk_out_ep;
653 struct usb_host_endpoint *bulk_in_ep; 653 struct usb_host_endpoint *bulk_in_ep;
654 struct hci_dev *hdev; 654 struct hci_dev *hdev;
655 struct bfusb *bfusb; 655 struct bfusb_data *data;
656 656
657 BT_DBG("intf %p id %p", intf, id); 657 BT_DBG("intf %p id %p", intf, id);
658 658
@@ -672,23 +672,24 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i
672 } 672 }
673 673
674 /* Initialize control structure and load firmware */ 674 /* Initialize control structure and load firmware */
675 if (!(bfusb = kzalloc(sizeof(struct bfusb), GFP_KERNEL))) { 675 data = kzalloc(sizeof(struct bfusb_data), GFP_KERNEL);
676 if (!data) {
676 BT_ERR("Can't allocate memory for control structure"); 677 BT_ERR("Can't allocate memory for control structure");
677 goto done; 678 goto done;
678 } 679 }
679 680
680 bfusb->udev = udev; 681 data->udev = udev;
681 bfusb->bulk_in_ep = bulk_in_ep->desc.bEndpointAddress; 682 data->bulk_in_ep = bulk_in_ep->desc.bEndpointAddress;
682 bfusb->bulk_out_ep = bulk_out_ep->desc.bEndpointAddress; 683 data->bulk_out_ep = bulk_out_ep->desc.bEndpointAddress;
683 bfusb->bulk_pkt_size = le16_to_cpu(bulk_out_ep->desc.wMaxPacketSize); 684 data->bulk_pkt_size = le16_to_cpu(bulk_out_ep->desc.wMaxPacketSize);
684 685
685 rwlock_init(&bfusb->lock); 686 rwlock_init(&data->lock);
686 687
687 bfusb->reassembly = NULL; 688 data->reassembly = NULL;
688 689
689 skb_queue_head_init(&bfusb->transmit_q); 690 skb_queue_head_init(&data->transmit_q);
690 skb_queue_head_init(&bfusb->pending_q); 691 skb_queue_head_init(&data->pending_q);
691 skb_queue_head_init(&bfusb->completed_q); 692 skb_queue_head_init(&data->completed_q);
692 693
693 if (request_firmware(&firmware, "bfubase.frm", &udev->dev) < 0) { 694 if (request_firmware(&firmware, "bfubase.frm", &udev->dev) < 0) {
694 BT_ERR("Firmware request failed"); 695 BT_ERR("Firmware request failed");
@@ -697,7 +698,7 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i
697 698
698 BT_DBG("firmware data %p size %d", firmware->data, firmware->size); 699 BT_DBG("firmware data %p size %d", firmware->data, firmware->size);
699 700
700 if (bfusb_load_firmware(bfusb, firmware->data, firmware->size) < 0) { 701 if (bfusb_load_firmware(data, firmware->data, firmware->size) < 0) {
701 BT_ERR("Firmware loading failed"); 702 BT_ERR("Firmware loading failed");
702 goto release; 703 goto release;
703 } 704 }
@@ -711,10 +712,10 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i
711 goto error; 712 goto error;
712 } 713 }
713 714
714 bfusb->hdev = hdev; 715 data->hdev = hdev;
715 716
716 hdev->type = HCI_USB; 717 hdev->type = HCI_USB;
717 hdev->driver_data = bfusb; 718 hdev->driver_data = data;
718 SET_HCIDEV_DEV(hdev, &intf->dev); 719 SET_HCIDEV_DEV(hdev, &intf->dev);
719 720
720 hdev->open = bfusb_open; 721 hdev->open = bfusb_open;
@@ -732,7 +733,7 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i
732 goto error; 733 goto error;
733 } 734 }
734 735
735 usb_set_intfdata(intf, bfusb); 736 usb_set_intfdata(intf, data);
736 737
737 return 0; 738 return 0;
738 739
@@ -740,7 +741,7 @@ release:
740 release_firmware(firmware); 741 release_firmware(firmware);
741 742
742error: 743error:
743 kfree(bfusb); 744 kfree(data);
744 745
745done: 746done:
746 return -EIO; 747 return -EIO;
@@ -748,8 +749,8 @@ done:
748 749
749static void bfusb_disconnect(struct usb_interface *intf) 750static void bfusb_disconnect(struct usb_interface *intf)
750{ 751{
751 struct bfusb *bfusb = usb_get_intfdata(intf); 752 struct bfusb_data *data = usb_get_intfdata(intf);
752 struct hci_dev *hdev = bfusb->hdev; 753 struct hci_dev *hdev = data->hdev;
753 754
754 BT_DBG("intf %p", intf); 755 BT_DBG("intf %p", intf);
755 756
@@ -779,7 +780,8 @@ static int __init bfusb_init(void)
779 780
780 BT_INFO("BlueFRITZ! USB driver ver %s", VERSION); 781 BT_INFO("BlueFRITZ! USB driver ver %s", VERSION);
781 782
782 if ((err = usb_register(&bfusb_driver)) < 0) 783 err = usb_register(&bfusb_driver);
784 if (err < 0)
783 BT_ERR("Failed to register BlueFRITZ! USB driver"); 785 BT_ERR("Failed to register BlueFRITZ! USB driver");
784 786
785 return err; 787 return err;
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index 93ba25b7ea32..420b645c4c9f 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -241,15 +241,11 @@ static int hci_uart_send_frame(struct sk_buff *skb)
241 241
242static void hci_uart_destruct(struct hci_dev *hdev) 242static void hci_uart_destruct(struct hci_dev *hdev)
243{ 243{
244 struct hci_uart *hu;
245
246 if (!hdev) 244 if (!hdev)
247 return; 245 return;
248 246
249 BT_DBG("%s", hdev->name); 247 BT_DBG("%s", hdev->name);
250 248 kfree(hdev->driver_data);
251 hu = (struct hci_uart *) hdev->driver_data;
252 kfree(hu);
253} 249}
254 250
255/* ------ LDISC part ------ */ 251/* ------ LDISC part ------ */
@@ -272,7 +268,7 @@ static int hci_uart_tty_open(struct tty_struct *tty)
272 return -EEXIST; 268 return -EEXIST;
273 269
274 if (!(hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL))) { 270 if (!(hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL))) {
275 BT_ERR("Can't allocate controll structure"); 271 BT_ERR("Can't allocate control structure");
276 return -ENFILE; 272 return -ENFILE;
277 } 273 }
278 274
@@ -360,7 +356,7 @@ static void hci_uart_tty_wakeup(struct tty_struct *tty)
360 * 356 *
361 * Return Value: None 357 * Return Value: None
362 */ 358 */
363static void hci_uart_tty_receive(struct tty_struct *tty, const __u8 *data, char *flags, int count) 359static void hci_uart_tty_receive(struct tty_struct *tty, const u8 *data, char *flags, int count)
364{ 360{
365 struct hci_uart *hu = (void *)tty->disc_data; 361 struct hci_uart *hu = (void *)tty->disc_data;
366 362
@@ -375,7 +371,8 @@ static void hci_uart_tty_receive(struct tty_struct *tty, const __u8 *data, char
375 hu->hdev->stat.byte_rx += count; 371 hu->hdev->stat.byte_rx += count;
376 spin_unlock(&hu->rx_lock); 372 spin_unlock(&hu->rx_lock);
377 373
378 if (test_and_clear_bit(TTY_THROTTLED,&tty->flags) && tty->driver->unthrottle) 374 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) &&
375 tty->driver->unthrottle)
379 tty->driver->unthrottle(tty); 376 tty->driver->unthrottle(tty);
380} 377}
381 378
diff --git a/drivers/bluetooth/hci_usb.c b/drivers/bluetooth/hci_usb.c
index e2d4beac7420..0801af4ad2b9 100644
--- a/drivers/bluetooth/hci_usb.c
+++ b/drivers/bluetooth/hci_usb.c
@@ -96,6 +96,9 @@ static struct usb_device_id bluetooth_ids[] = {
96 /* Ericsson with non-standard id */ 96 /* Ericsson with non-standard id */
97 { USB_DEVICE(0x0bdb, 0x1002) }, 97 { USB_DEVICE(0x0bdb, 0x1002) },
98 98
99 /* Canyon CN-BTU1 with HID interfaces */
100 { USB_DEVICE(0x0c10, 0x0000), .driver_info = HCI_RESET },
101
99 { } /* Terminating entry */ 102 { } /* Terminating entry */
100}; 103};
101 104
diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index aac67a3a6019..a278d98a9151 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -2,9 +2,9 @@
2 * 2 *
3 * Bluetooth virtual HCI driver 3 * Bluetooth virtual HCI driver
4 * 4 *
5 * Copyright (C) 2000-2001 Qualcomm Incorporated 5 * Copyright (C) 2000-2001 Qualcomm Incorporated
6 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com> 6 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
7 * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org> 7 * Copyright (C) 2004-2006 Marcel Holtmann <marcel@holtmann.org>
8 * 8 *
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
@@ -72,21 +72,21 @@ static int vhci_open_dev(struct hci_dev *hdev)
72 72
73static int vhci_close_dev(struct hci_dev *hdev) 73static int vhci_close_dev(struct hci_dev *hdev)
74{ 74{
75 struct vhci_data *vhci = hdev->driver_data; 75 struct vhci_data *data = hdev->driver_data;
76 76
77 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) 77 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
78 return 0; 78 return 0;
79 79
80 skb_queue_purge(&vhci->readq); 80 skb_queue_purge(&data->readq);
81 81
82 return 0; 82 return 0;
83} 83}
84 84
85static int vhci_flush(struct hci_dev *hdev) 85static int vhci_flush(struct hci_dev *hdev)
86{ 86{
87 struct vhci_data *vhci = hdev->driver_data; 87 struct vhci_data *data = hdev->driver_data;
88 88
89 skb_queue_purge(&vhci->readq); 89 skb_queue_purge(&data->readq);
90 90
91 return 0; 91 return 0;
92} 92}
@@ -94,7 +94,7 @@ static int vhci_flush(struct hci_dev *hdev)
94static int vhci_send_frame(struct sk_buff *skb) 94static int vhci_send_frame(struct sk_buff *skb)
95{ 95{
96 struct hci_dev* hdev = (struct hci_dev *) skb->dev; 96 struct hci_dev* hdev = (struct hci_dev *) skb->dev;
97 struct vhci_data *vhci; 97 struct vhci_data *data;
98 98
99 if (!hdev) { 99 if (!hdev) {
100 BT_ERR("Frame for unknown HCI device (hdev=NULL)"); 100 BT_ERR("Frame for unknown HCI device (hdev=NULL)");
@@ -104,15 +104,15 @@ static int vhci_send_frame(struct sk_buff *skb)
104 if (!test_bit(HCI_RUNNING, &hdev->flags)) 104 if (!test_bit(HCI_RUNNING, &hdev->flags))
105 return -EBUSY; 105 return -EBUSY;
106 106
107 vhci = hdev->driver_data; 107 data = hdev->driver_data;
108 108
109 memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1); 109 memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
110 skb_queue_tail(&vhci->readq, skb); 110 skb_queue_tail(&data->readq, skb);
111 111
112 if (vhci->flags & VHCI_FASYNC) 112 if (data->flags & VHCI_FASYNC)
113 kill_fasync(&vhci->fasync, SIGIO, POLL_IN); 113 kill_fasync(&data->fasync, SIGIO, POLL_IN);
114 114
115 wake_up_interruptible(&vhci->read_wait); 115 wake_up_interruptible(&data->read_wait);
116 116
117 return 0; 117 return 0;
118} 118}
@@ -122,7 +122,7 @@ static void vhci_destruct(struct hci_dev *hdev)
122 kfree(hdev->driver_data); 122 kfree(hdev->driver_data);
123} 123}
124 124
125static inline ssize_t vhci_get_user(struct vhci_data *vhci, 125static inline ssize_t vhci_get_user(struct vhci_data *data,
126 const char __user *buf, size_t count) 126 const char __user *buf, size_t count)
127{ 127{
128 struct sk_buff *skb; 128 struct sk_buff *skb;
@@ -139,7 +139,7 @@ static inline ssize_t vhci_get_user(struct vhci_data *vhci,
139 return -EFAULT; 139 return -EFAULT;
140 } 140 }
141 141
142 skb->dev = (void *) vhci->hdev; 142 skb->dev = (void *) data->hdev;
143 bt_cb(skb)->pkt_type = *((__u8 *) skb->data); 143 bt_cb(skb)->pkt_type = *((__u8 *) skb->data);
144 skb_pull(skb, 1); 144 skb_pull(skb, 1);
145 145
@@ -148,7 +148,7 @@ static inline ssize_t vhci_get_user(struct vhci_data *vhci,
148 return count; 148 return count;
149} 149}
150 150
151static inline ssize_t vhci_put_user(struct vhci_data *vhci, 151static inline ssize_t vhci_put_user(struct vhci_data *data,
152 struct sk_buff *skb, char __user *buf, int count) 152 struct sk_buff *skb, char __user *buf, int count)
153{ 153{
154 char __user *ptr = buf; 154 char __user *ptr = buf;
@@ -161,42 +161,43 @@ static inline ssize_t vhci_put_user(struct vhci_data *vhci,
161 161
162 total += len; 162 total += len;
163 163
164 vhci->hdev->stat.byte_tx += len; 164 data->hdev->stat.byte_tx += len;
165 165
166 switch (bt_cb(skb)->pkt_type) { 166 switch (bt_cb(skb)->pkt_type) {
167 case HCI_COMMAND_PKT: 167 case HCI_COMMAND_PKT:
168 vhci->hdev->stat.cmd_tx++; 168 data->hdev->stat.cmd_tx++;
169 break; 169 break;
170 170
171 case HCI_ACLDATA_PKT: 171 case HCI_ACLDATA_PKT:
172 vhci->hdev->stat.acl_tx++; 172 data->hdev->stat.acl_tx++;
173 break; 173 break;
174 174
175 case HCI_SCODATA_PKT: 175 case HCI_SCODATA_PKT:
176 vhci->hdev->stat.cmd_tx++; 176 data->hdev->stat.cmd_tx++;
177 break; 177 break;
178 }; 178 };
179 179
180 return total; 180 return total;
181} 181}
182 182
183static loff_t vhci_llseek(struct file * file, loff_t offset, int origin) 183static loff_t vhci_llseek(struct file *file, loff_t offset, int origin)
184{ 184{
185 return -ESPIPE; 185 return -ESPIPE;
186} 186}
187 187
188static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, loff_t *pos) 188static ssize_t vhci_read(struct file *file,
189 char __user *buf, size_t count, loff_t *pos)
189{ 190{
190 DECLARE_WAITQUEUE(wait, current); 191 DECLARE_WAITQUEUE(wait, current);
191 struct vhci_data *vhci = file->private_data; 192 struct vhci_data *data = file->private_data;
192 struct sk_buff *skb; 193 struct sk_buff *skb;
193 ssize_t ret = 0; 194 ssize_t ret = 0;
194 195
195 add_wait_queue(&vhci->read_wait, &wait); 196 add_wait_queue(&data->read_wait, &wait);
196 while (count) { 197 while (count) {
197 set_current_state(TASK_INTERRUPTIBLE); 198 set_current_state(TASK_INTERRUPTIBLE);
198 199
199 skb = skb_dequeue(&vhci->readq); 200 skb = skb_dequeue(&data->readq);
200 if (!skb) { 201 if (!skb) {
201 if (file->f_flags & O_NONBLOCK) { 202 if (file->f_flags & O_NONBLOCK) {
202 ret = -EAGAIN; 203 ret = -EAGAIN;
@@ -213,7 +214,7 @@ static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, lo
213 } 214 }
214 215
215 if (access_ok(VERIFY_WRITE, buf, count)) 216 if (access_ok(VERIFY_WRITE, buf, count))
216 ret = vhci_put_user(vhci, skb, buf, count); 217 ret = vhci_put_user(data, skb, buf, count);
217 else 218 else
218 ret = -EFAULT; 219 ret = -EFAULT;
219 220
@@ -221,7 +222,7 @@ static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, lo
221 break; 222 break;
222 } 223 }
223 set_current_state(TASK_RUNNING); 224 set_current_state(TASK_RUNNING);
224 remove_wait_queue(&vhci->read_wait, &wait); 225 remove_wait_queue(&data->read_wait, &wait);
225 226
226 return ret; 227 return ret;
227} 228}
@@ -229,21 +230,21 @@ static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, lo
229static ssize_t vhci_write(struct file *file, 230static ssize_t vhci_write(struct file *file,
230 const char __user *buf, size_t count, loff_t *pos) 231 const char __user *buf, size_t count, loff_t *pos)
231{ 232{
232 struct vhci_data *vhci = file->private_data; 233 struct vhci_data *data = file->private_data;
233 234
234 if (!access_ok(VERIFY_READ, buf, count)) 235 if (!access_ok(VERIFY_READ, buf, count))
235 return -EFAULT; 236 return -EFAULT;
236 237
237 return vhci_get_user(vhci, buf, count); 238 return vhci_get_user(data, buf, count);
238} 239}
239 240
240static unsigned int vhci_poll(struct file *file, poll_table *wait) 241static unsigned int vhci_poll(struct file *file, poll_table *wait)
241{ 242{
242 struct vhci_data *vhci = file->private_data; 243 struct vhci_data *data = file->private_data;
243 244
244 poll_wait(file, &vhci->read_wait, wait); 245 poll_wait(file, &data->read_wait, wait);
245 246
246 if (!skb_queue_empty(&vhci->readq)) 247 if (!skb_queue_empty(&data->readq))
247 return POLLIN | POLLRDNORM; 248 return POLLIN | POLLRDNORM;
248 249
249 return POLLOUT | POLLWRNORM; 250 return POLLOUT | POLLWRNORM;
@@ -257,26 +258,26 @@ static int vhci_ioctl(struct inode *inode, struct file *file,
257 258
258static int vhci_open(struct inode *inode, struct file *file) 259static int vhci_open(struct inode *inode, struct file *file)
259{ 260{
260 struct vhci_data *vhci; 261 struct vhci_data *data;
261 struct hci_dev *hdev; 262 struct hci_dev *hdev;
262 263
263 vhci = kzalloc(sizeof(struct vhci_data), GFP_KERNEL); 264 data = kzalloc(sizeof(struct vhci_data), GFP_KERNEL);
264 if (!vhci) 265 if (!data)
265 return -ENOMEM; 266 return -ENOMEM;
266 267
267 skb_queue_head_init(&vhci->readq); 268 skb_queue_head_init(&data->readq);
268 init_waitqueue_head(&vhci->read_wait); 269 init_waitqueue_head(&data->read_wait);
269 270
270 hdev = hci_alloc_dev(); 271 hdev = hci_alloc_dev();
271 if (!hdev) { 272 if (!hdev) {
272 kfree(vhci); 273 kfree(data);
273 return -ENOMEM; 274 return -ENOMEM;
274 } 275 }
275 276
276 vhci->hdev = hdev; 277 data->hdev = hdev;
277 278
278 hdev->type = HCI_VHCI; 279 hdev->type = HCI_VIRTUAL;
279 hdev->driver_data = vhci; 280 hdev->driver_data = data;
280 281
281 hdev->open = vhci_open_dev; 282 hdev->open = vhci_open_dev;
282 hdev->close = vhci_close_dev; 283 hdev->close = vhci_close_dev;
@@ -288,20 +289,20 @@ static int vhci_open(struct inode *inode, struct file *file)
288 289
289 if (hci_register_dev(hdev) < 0) { 290 if (hci_register_dev(hdev) < 0) {
290 BT_ERR("Can't register HCI device"); 291 BT_ERR("Can't register HCI device");
291 kfree(vhci); 292 kfree(data);
292 hci_free_dev(hdev); 293 hci_free_dev(hdev);
293 return -EBUSY; 294 return -EBUSY;
294 } 295 }
295 296
296 file->private_data = vhci; 297 file->private_data = data;
297 298
298 return nonseekable_open(inode, file); 299 return nonseekable_open(inode, file);
299} 300}
300 301
301static int vhci_release(struct inode *inode, struct file *file) 302static int vhci_release(struct inode *inode, struct file *file)
302{ 303{
303 struct vhci_data *vhci = file->private_data; 304 struct vhci_data *data = file->private_data;
304 struct hci_dev *hdev = vhci->hdev; 305 struct hci_dev *hdev = data->hdev;
305 306
306 if (hci_unregister_dev(hdev) < 0) { 307 if (hci_unregister_dev(hdev) < 0) {
307 BT_ERR("Can't unregister HCI device %s", hdev->name); 308 BT_ERR("Can't unregister HCI device %s", hdev->name);
@@ -316,17 +317,17 @@ static int vhci_release(struct inode *inode, struct file *file)
316 317
317static int vhci_fasync(int fd, struct file *file, int on) 318static int vhci_fasync(int fd, struct file *file, int on)
318{ 319{
319 struct vhci_data *vhci = file->private_data; 320 struct vhci_data *data = file->private_data;
320 int err; 321 int err;
321 322
322 err = fasync_helper(fd, file, on, &vhci->fasync); 323 err = fasync_helper(fd, file, on, &data->fasync);
323 if (err < 0) 324 if (err < 0)
324 return err; 325 return err;
325 326
326 if (on) 327 if (on)
327 vhci->flags |= VHCI_FASYNC; 328 data->flags |= VHCI_FASYNC;
328 else 329 else
329 vhci->flags &= ~VHCI_FASYNC; 330 data->flags &= ~VHCI_FASYNC;
330 331
331 return 0; 332 return 0;
332} 333}
diff --git a/drivers/cdrom/Kconfig b/drivers/cdrom/Kconfig
index ff5652d40619..4b12e9031fb3 100644
--- a/drivers/cdrom/Kconfig
+++ b/drivers/cdrom/Kconfig
@@ -3,7 +3,7 @@
3# 3#
4 4
5menu "Old CD-ROM drivers (not SCSI, not IDE)" 5menu "Old CD-ROM drivers (not SCSI, not IDE)"
6 depends on ISA 6 depends on ISA && BLOCK
7 7
8config CD_NO_IDESCSI 8config CD_NO_IDESCSI
9 bool "Support non-SCSI/IDE/ATAPI CDROM drives" 9 bool "Support non-SCSI/IDE/ATAPI CDROM drives"
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index d239cf8b20bd..b38c84a7a8e3 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -2129,7 +2129,7 @@ static int cdrom_read_cdda_bpc(struct cdrom_device_info *cdi, __u8 __user *ubuf,
2129 rq->cmd[9] = 0xf8; 2129 rq->cmd[9] = 0xf8;
2130 2130
2131 rq->cmd_len = 12; 2131 rq->cmd_len = 12;
2132 rq->flags |= REQ_BLOCK_PC; 2132 rq->cmd_type = REQ_TYPE_BLOCK_PC;
2133 rq->timeout = 60 * HZ; 2133 rq->timeout = 60 * HZ;
2134 bio = rq->bio; 2134 bio = rq->bio;
2135 2135
diff --git a/drivers/cdrom/cdu31a.c b/drivers/cdrom/cdu31a.c
index 37bdb0163f0d..ccd91c1a84bd 100644
--- a/drivers/cdrom/cdu31a.c
+++ b/drivers/cdrom/cdu31a.c
@@ -1338,8 +1338,10 @@ static void do_cdu31a_request(request_queue_t * q)
1338 } 1338 }
1339 1339
1340 /* WTF??? */ 1340 /* WTF??? */
1341 if (!(req->flags & REQ_CMD)) 1341 if (!blk_fs_request(req)) {
1342 end_request(req, 0);
1342 continue; 1343 continue;
1344 }
1343 if (rq_data_dir(req) == WRITE) { 1345 if (rq_data_dir(req) == WRITE) {
1344 end_request(req, 0); 1346 end_request(req, 0);
1345 continue; 1347 continue;
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 52ea94b891f5..bde1c665d9f4 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -439,6 +439,14 @@ config SGI_MBCS
439 If you have an SGI Altix with an attached SABrick 439 If you have an SGI Altix with an attached SABrick
440 say Y or M here, otherwise say N. 440 say Y or M here, otherwise say N.
441 441
442config MSPEC
443 tristate "Memory special operations driver"
444 depends on IA64
445 help
446 If you have an ia64 and you want to enable memory special
447 operations support (formerly known as fetchop), say Y here,
448 otherwise say N.
449
442source "drivers/serial/Kconfig" 450source "drivers/serial/Kconfig"
443 451
444config UNIX98_PTYS 452config UNIX98_PTYS
@@ -739,7 +747,7 @@ config NVRAM
739 747
740config RTC 748config RTC
741 tristate "Enhanced Real Time Clock Support" 749 tristate "Enhanced Real Time Clock Support"
742 depends on !PPC && !PARISC && !IA64 && !M68K && (!SPARC || PCI) && !FRV && !ARM 750 depends on !PPC && !PARISC && !IA64 && !M68K && (!SPARC || PCI) && !FRV && !ARM && !SUPERH
743 ---help--- 751 ---help---
744 If you say Y here and create a character special file /dev/rtc with 752 If you say Y here and create a character special file /dev/rtc with
745 major number 10 and minor number 135 using mknod ("man mknod"), you 753 major number 10 and minor number 135 using mknod ("man mknod"), you
@@ -823,14 +831,6 @@ config DS1302
823 will get access to the real time clock (or hardware clock) built 831 will get access to the real time clock (or hardware clock) built
824 into your computer. 832 into your computer.
825 833
826config S3C2410_RTC
827 bool "S3C2410 RTC Driver"
828 depends on ARCH_S3C2410
829 help
830 RTC (Realtime Clock) driver for the clock inbuilt into the
831 Samsung S3C2410. This can provide periodic interrupt rates
832 from 1Hz to 64Hz for user programs, and wakeup from Alarm.
833
834config COBALT_LCD 834config COBALT_LCD
835 bool "Support for Cobalt LCD" 835 bool "Support for Cobalt LCD"
836 depends on MIPS_COBALT 836 depends on MIPS_COBALT
@@ -1006,6 +1006,7 @@ config GPIO_VR41XX
1006 1006
1007config RAW_DRIVER 1007config RAW_DRIVER
1008 tristate "RAW driver (/dev/raw/rawN) (OBSOLETE)" 1008 tristate "RAW driver (/dev/raw/rawN) (OBSOLETE)"
1009 depends on BLOCK
1009 help 1010 help
1010 The raw driver permits block devices to be bound to /dev/raw/rawN. 1011 The raw driver permits block devices to be bound to /dev/raw/rawN.
1011 Once bound, I/O against /dev/raw/rawN uses efficient zero-copy I/O. 1012 Once bound, I/O against /dev/raw/rawN uses efficient zero-copy I/O.
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 8c6dfc621520..19114df59bbd 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -47,6 +47,7 @@ obj-$(CONFIG_HVC_RTAS) += hvc_rtas.o
47obj-$(CONFIG_HVC_DRIVER) += hvc_console.o 47obj-$(CONFIG_HVC_DRIVER) += hvc_console.o
48obj-$(CONFIG_RAW_DRIVER) += raw.o 48obj-$(CONFIG_RAW_DRIVER) += raw.o
49obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o 49obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o
50obj-$(CONFIG_MSPEC) += mspec.o
50obj-$(CONFIG_MMTIMER) += mmtimer.o 51obj-$(CONFIG_MMTIMER) += mmtimer.o
51obj-$(CONFIG_VIOCONS) += viocons.o 52obj-$(CONFIG_VIOCONS) += viocons.o
52obj-$(CONFIG_VIOTAPE) += viotape.o 53obj-$(CONFIG_VIOTAPE) += viotape.o
@@ -68,7 +69,6 @@ obj-$(CONFIG_EFI_RTC) += efirtc.o
68obj-$(CONFIG_SGI_DS1286) += ds1286.o 69obj-$(CONFIG_SGI_DS1286) += ds1286.o
69obj-$(CONFIG_SGI_IP27_RTC) += ip27-rtc.o 70obj-$(CONFIG_SGI_IP27_RTC) += ip27-rtc.o
70obj-$(CONFIG_DS1302) += ds1302.o 71obj-$(CONFIG_DS1302) += ds1302.o
71obj-$(CONFIG_S3C2410_RTC) += s3c2410-rtc.o
72ifeq ($(CONFIG_GENERIC_NVRAM),y) 72ifeq ($(CONFIG_GENERIC_NVRAM),y)
73 obj-$(CONFIG_NVRAM) += generic_nvram.o 73 obj-$(CONFIG_NVRAM) += generic_nvram.o
74else 74else
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index 8cd52984cda5..00b17ae39736 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -409,7 +409,7 @@ static int __devinit uli_agp_init(struct pci_dev *pdev)
409 int i; 409 int i;
410 unsigned size = amd64_fetch_size(); 410 unsigned size = amd64_fetch_size();
411 printk(KERN_INFO "Setting up ULi AGP.\n"); 411 printk(KERN_INFO "Setting up ULi AGP.\n");
412 dev1 = pci_find_slot ((unsigned int)pdev->bus->number,PCI_DEVFN(0,0)); 412 dev1 = pci_get_slot (pdev->bus,PCI_DEVFN(0,0));
413 if (dev1 == NULL) { 413 if (dev1 == NULL) {
414 printk(KERN_INFO PFX "Detected a ULi chipset, " 414 printk(KERN_INFO PFX "Detected a ULi chipset, "
415 "but could not fine the secondary device.\n"); 415 "but could not fine the secondary device.\n");
@@ -442,6 +442,8 @@ static int __devinit uli_agp_init(struct pci_dev *pdev)
442 enuscr= httfea+ (size * 1024 * 1024) - 1; 442 enuscr= httfea+ (size * 1024 * 1024) - 1;
443 pci_write_config_dword(dev1, ULI_X86_64_HTT_FEA_REG, httfea); 443 pci_write_config_dword(dev1, ULI_X86_64_HTT_FEA_REG, httfea);
444 pci_write_config_dword(dev1, ULI_X86_64_ENU_SCR_REG, enuscr); 444 pci_write_config_dword(dev1, ULI_X86_64_ENU_SCR_REG, enuscr);
445
446 pci_dev_put(dev1);
445 return 0; 447 return 0;
446} 448}
447 449
@@ -466,7 +468,7 @@ static int __devinit nforce3_agp_init(struct pci_dev *pdev)
466 468
467 printk(KERN_INFO PFX "Setting up Nforce3 AGP.\n"); 469 printk(KERN_INFO PFX "Setting up Nforce3 AGP.\n");
468 470
469 dev1 = pci_find_slot((unsigned int)pdev->bus->number, PCI_DEVFN(11, 0)); 471 dev1 = pci_get_slot(pdev->bus, PCI_DEVFN(11, 0));
470 if (dev1 == NULL) { 472 if (dev1 == NULL) {
471 printk(KERN_INFO PFX "agpgart: Detected an NVIDIA " 473 printk(KERN_INFO PFX "agpgart: Detected an NVIDIA "
472 "nForce3 chipset, but could not find " 474 "nForce3 chipset, but could not find "
@@ -510,6 +512,8 @@ static int __devinit nforce3_agp_init(struct pci_dev *pdev)
510 pci_write_config_dword(dev1, NVIDIA_X86_64_1_APBASE2, apbase); 512 pci_write_config_dword(dev1, NVIDIA_X86_64_1_APBASE2, apbase);
511 pci_write_config_dword(dev1, NVIDIA_X86_64_1_APLIMIT2, aplimit); 513 pci_write_config_dword(dev1, NVIDIA_X86_64_1_APLIMIT2, aplimit);
512 514
515 pci_dev_put(dev1);
516
513 return 0; 517 return 0;
514} 518}
515 519
diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
index 0dcdb363923f..c39200161688 100644
--- a/drivers/char/agp/generic.c
+++ b/drivers/char/agp/generic.c
@@ -581,18 +581,21 @@ static void agp_v3_parse_one(u32 *requested_mode, u32 *bridge_agpstat, u32 *vga_
581 * If not, we fall back to x4 mode. 581 * If not, we fall back to x4 mode.
582 */ 582 */
583 if ((*bridge_agpstat & AGPSTAT3_8X) && (*vga_agpstat & AGPSTAT3_8X)) { 583 if ((*bridge_agpstat & AGPSTAT3_8X) && (*vga_agpstat & AGPSTAT3_8X)) {
584 printk(KERN_INFO PFX "No AGP mode specified. Setting to highest mode supported by bridge & card (x8).\n"); 584 printk(KERN_INFO PFX "No AGP mode specified. Setting to highest mode "
585 "supported by bridge & card (x8).\n");
585 *bridge_agpstat &= ~(AGPSTAT3_4X | AGPSTAT3_RSVD); 586 *bridge_agpstat &= ~(AGPSTAT3_4X | AGPSTAT3_RSVD);
586 *vga_agpstat &= ~(AGPSTAT3_4X | AGPSTAT3_RSVD); 587 *vga_agpstat &= ~(AGPSTAT3_4X | AGPSTAT3_RSVD);
587 } else { 588 } else {
588 printk(KERN_INFO PFX "Fell back to AGPx4 mode because"); 589 printk(KERN_INFO PFX "Fell back to AGPx4 mode because");
589 if (!(*bridge_agpstat & AGPSTAT3_8X)) { 590 if (!(*bridge_agpstat & AGPSTAT3_8X)) {
590 printk("bridge couldn't do x8. bridge_agpstat:%x (orig=%x)\n", *bridge_agpstat, origbridge); 591 printk(KERN_INFO PFX "bridge couldn't do x8. bridge_agpstat:%x (orig=%x)\n",
592 *bridge_agpstat, origbridge);
591 *bridge_agpstat &= ~(AGPSTAT3_8X | AGPSTAT3_RSVD); 593 *bridge_agpstat &= ~(AGPSTAT3_8X | AGPSTAT3_RSVD);
592 *bridge_agpstat |= AGPSTAT3_4X; 594 *bridge_agpstat |= AGPSTAT3_4X;
593 } 595 }
594 if (!(*vga_agpstat & AGPSTAT3_8X)) { 596 if (!(*vga_agpstat & AGPSTAT3_8X)) {
595 printk("graphics card couldn't do x8. vga_agpstat:%x (orig=%x)\n", *vga_agpstat, origvga); 597 printk(KERN_INFO PFX "graphics card couldn't do x8. vga_agpstat:%x (orig=%x)\n",
598 *vga_agpstat, origvga);
596 *vga_agpstat &= ~(AGPSTAT3_8X | AGPSTAT3_RSVD); 599 *vga_agpstat &= ~(AGPSTAT3_8X | AGPSTAT3_RSVD);
597 *vga_agpstat |= AGPSTAT3_4X; 600 *vga_agpstat |= AGPSTAT3_4X;
598 } 601 }
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index 9d6713a93ed7..d0e92ed0a367 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -1958,7 +1958,7 @@ static void show_serial_version(void)
1958} 1958}
1959 1959
1960 1960
1961static struct tty_operations serial_ops = { 1961static const struct tty_operations serial_ops = {
1962 .open = rs_open, 1962 .open = rs_open,
1963 .close = rs_close, 1963 .close = rs_close,
1964 .write = rs_write, 1964 .write = rs_write,
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index c1c67281750d..f85b4eb16618 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -5205,7 +5205,7 @@ done:
5205 extra ports are ignored. 5205 extra ports are ignored.
5206 */ 5206 */
5207 5207
5208static struct tty_operations cy_ops = { 5208static const struct tty_operations cy_ops = {
5209 .open = cy_open, 5209 .open = cy_open,
5210 .close = cy_close, 5210 .close = cy_close,
5211 .write = cy_write, 5211 .write = cy_write,
diff --git a/drivers/char/drm/Kconfig b/drivers/char/drm/Kconfig
index 5278c388d3e7..ef833a1c27eb 100644
--- a/drivers/char/drm/Kconfig
+++ b/drivers/char/drm/Kconfig
@@ -60,7 +60,9 @@ config DRM_I830
60 Choose this option if you have a system that has Intel 830M, 845G, 60 Choose this option if you have a system that has Intel 830M, 845G,
61 852GM, 855GM or 865G integrated graphics. If M is selected, the 61 852GM, 855GM or 865G integrated graphics. If M is selected, the
62 module will be called i830. AGP support is required for this driver 62 module will be called i830. AGP support is required for this driver
63 to work. This driver will eventually be replaced by the i915 one. 63 to work. This driver is used by the older X releases X.org 6.7 and
64 XFree86 4.3. If unsure, build this and i915 as modules and the X server
65 will load the correct one.
64 66
65config DRM_I915 67config DRM_I915
66 tristate "i915 driver" 68 tristate "i915 driver"
@@ -68,8 +70,9 @@ config DRM_I915
68 Choose this option if you have a system that has Intel 830M, 845G, 70 Choose this option if you have a system that has Intel 830M, 845G,
69 852GM, 855GM 865G or 915G integrated graphics. If M is selected, the 71 852GM, 855GM 865G or 915G integrated graphics. If M is selected, the
70 module will be called i915. AGP support is required for this driver 72 module will be called i915. AGP support is required for this driver
71 to work. This driver will eventually replace the I830 driver, when 73 to work. This driver is used by the Intel driver in X.org 6.8 and
72 later release of X start to use the new DDX and DRI. 74 XFree86 4.4 and above. If unsure, build this and i830 as modules and
75 the X server will load the correct one.
73 76
74endchoice 77endchoice
75 78
diff --git a/drivers/char/drm/Makefile b/drivers/char/drm/Makefile
index 9d180c42816c..3ad0f648c6b2 100644
--- a/drivers/char/drm/Makefile
+++ b/drivers/char/drm/Makefile
@@ -6,7 +6,7 @@ drm-objs := drm_auth.o drm_bufs.o drm_context.o drm_dma.o drm_drawable.o \
6 drm_drv.o drm_fops.o drm_ioctl.o drm_irq.o \ 6 drm_drv.o drm_fops.o drm_ioctl.o drm_irq.o \
7 drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \ 7 drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \
8 drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \ 8 drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \
9 drm_sysfs.o 9 drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o
10 10
11tdfx-objs := tdfx_drv.o 11tdfx-objs := tdfx_drv.o
12r128-objs := r128_drv.o r128_cce.o r128_state.o r128_irq.o 12r128-objs := r128_drv.o r128_cce.o r128_state.o r128_irq.o
@@ -16,9 +16,9 @@ i830-objs := i830_drv.o i830_dma.o i830_irq.o
16i915-objs := i915_drv.o i915_dma.o i915_irq.o i915_mem.o 16i915-objs := i915_drv.o i915_dma.o i915_irq.o i915_mem.o
17radeon-objs := radeon_drv.o radeon_cp.o radeon_state.o radeon_mem.o radeon_irq.o r300_cmdbuf.o 17radeon-objs := radeon_drv.o radeon_cp.o radeon_state.o radeon_mem.o radeon_irq.o r300_cmdbuf.o
18ffb-objs := ffb_drv.o ffb_context.o 18ffb-objs := ffb_drv.o ffb_context.o
19sis-objs := sis_drv.o sis_ds.o sis_mm.o 19sis-objs := sis_drv.o sis_mm.o
20savage-objs := savage_drv.o savage_bci.o savage_state.o 20savage-objs := savage_drv.o savage_bci.o savage_state.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 via_dmablit.o 21via-objs := via_irq.o via_drv.o via_map.o via_mm.o via_dma.o via_verifier.o via_video.o via_dmablit.o
22 22
23ifeq ($(CONFIG_COMPAT),y) 23ifeq ($(CONFIG_COMPAT),y)
24drm-objs += drm_ioc32.o 24drm-objs += drm_ioc32.o
diff --git a/drivers/char/drm/drmP.h b/drivers/char/drm/drmP.h
index d2a56182bc35..7690a59ace04 100644
--- a/drivers/char/drm/drmP.h
+++ b/drivers/char/drm/drmP.h
@@ -79,6 +79,7 @@
79#define __OS_HAS_MTRR (defined(CONFIG_MTRR)) 79#define __OS_HAS_MTRR (defined(CONFIG_MTRR))
80 80
81#include "drm_os_linux.h" 81#include "drm_os_linux.h"
82#include "drm_hashtab.h"
82 83
83/***********************************************************************/ 84/***********************************************************************/
84/** \name DRM template customization defaults */ 85/** \name DRM template customization defaults */
@@ -104,7 +105,7 @@
104#define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then 105#define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
105 also include looping detection. */ 106 also include looping detection. */
106 107
107#define DRM_HASH_SIZE 16 /**< Size of key hash table. Must be power of 2. */ 108#define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
108#define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */ 109#define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
109#define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */ 110#define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
110#define DRM_LOOPING_LIMIT 5000000 111#define DRM_LOOPING_LIMIT 5000000
@@ -134,19 +135,12 @@
134#define DRM_MEM_CTXBITMAP 18 135#define DRM_MEM_CTXBITMAP 18
135#define DRM_MEM_STUB 19 136#define DRM_MEM_STUB 19
136#define DRM_MEM_SGLISTS 20 137#define DRM_MEM_SGLISTS 20
137#define DRM_MEM_CTXLIST 21 138#define DRM_MEM_CTXLIST 21
139#define DRM_MEM_MM 22
140#define DRM_MEM_HASHTAB 23
138 141
139#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8) 142#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
140 143#define DRM_MAP_HASH_OFFSET 0x10000000
141/*@}*/
142
143/***********************************************************************/
144/** \name Backward compatibility section */
145/*@{*/
146
147#define DRM_RPR_ARG(vma) vma,
148
149#define VM_OFFSET(vma) ((vma)->vm_pgoff << PAGE_SHIFT)
150 144
151/*@}*/ 145/*@}*/
152 146
@@ -211,8 +205,6 @@
211/*@{*/ 205/*@{*/
212 206
213#define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x) 207#define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
214#define DRM_MIN(a,b) min(a,b)
215#define DRM_MAX(a,b) max(a,b)
216 208
217#define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1)) 209#define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
218#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x)) 210#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
@@ -286,7 +278,8 @@ typedef struct drm_devstate {
286} drm_devstate_t; 278} drm_devstate_t;
287 279
288typedef struct drm_magic_entry { 280typedef struct drm_magic_entry {
289 drm_magic_t magic; 281 drm_hash_item_t hash_item;
282 struct list_head head;
290 struct drm_file *priv; 283 struct drm_file *priv;
291 struct drm_magic_entry *next; 284 struct drm_magic_entry *next;
292} drm_magic_entry_t; 285} drm_magic_entry_t;
@@ -493,6 +486,7 @@ typedef struct drm_sigdata {
493 */ 486 */
494typedef struct drm_map_list { 487typedef struct drm_map_list {
495 struct list_head head; /**< list head */ 488 struct list_head head; /**< list head */
489 drm_hash_item_t hash;
496 drm_map_t *map; /**< mapping */ 490 drm_map_t *map; /**< mapping */
497 unsigned int user_token; 491 unsigned int user_token;
498} drm_map_list_t; 492} drm_map_list_t;
@@ -527,6 +521,22 @@ typedef struct ati_pcigart_info {
527 drm_local_map_t mapping; 521 drm_local_map_t mapping;
528} drm_ati_pcigart_info; 522} drm_ati_pcigart_info;
529 523
524/*
525 * Generic memory manager structs
526 */
527typedef struct drm_mm_node {
528 struct list_head fl_entry;
529 struct list_head ml_entry;
530 int free;
531 unsigned long start;
532 unsigned long size;
533 void *private;
534} drm_mm_node_t;
535
536typedef struct drm_mm {
537 drm_mm_node_t root_node;
538} drm_mm_t;
539
530/** 540/**
531 * DRM driver structure. This structure represent the common code for 541 * DRM driver structure. This structure represent the common code for
532 * a family of cards. There will one drm_device for each card present 542 * a family of cards. There will one drm_device for each card present
@@ -646,13 +656,15 @@ typedef struct drm_device {
646 /*@{ */ 656 /*@{ */
647 drm_file_t *file_first; /**< file list head */ 657 drm_file_t *file_first; /**< file list head */
648 drm_file_t *file_last; /**< file list tail */ 658 drm_file_t *file_last; /**< file list tail */
649 drm_magic_head_t magiclist[DRM_HASH_SIZE]; /**< magic hash table */ 659 drm_open_hash_t magiclist; /**< magic hash table */
660 struct list_head magicfree;
650 /*@} */ 661 /*@} */
651 662
652 /** \name Memory management */ 663 /** \name Memory management */
653 /*@{ */ 664 /*@{ */
654 drm_map_list_t *maplist; /**< Linked list of regions */ 665 drm_map_list_t *maplist; /**< Linked list of regions */
655 int map_count; /**< Number of mappable regions */ 666 int map_count; /**< Number of mappable regions */
667 drm_open_hash_t map_hash; /**< User token hash table for maps */
656 668
657 /** \name Context handle management */ 669 /** \name Context handle management */
658 /*@{ */ 670 /*@{ */
@@ -711,10 +723,8 @@ typedef struct drm_device {
711 drm_agp_head_t *agp; /**< AGP data */ 723 drm_agp_head_t *agp; /**< AGP data */
712 724
713 struct pci_dev *pdev; /**< PCI device structure */ 725 struct pci_dev *pdev; /**< PCI device structure */
714 int pci_domain; /**< PCI bus domain number */ 726 int pci_vendor; /**< PCI vendor id */
715 int pci_bus; /**< PCI bus number */ 727 int pci_device; /**< PCI device id */
716 int pci_slot; /**< PCI slot number */
717 int pci_func; /**< PCI function number */
718#ifdef __alpha__ 728#ifdef __alpha__
719 struct pci_controller *hose; 729 struct pci_controller *hose;
720#endif 730#endif
@@ -736,6 +746,12 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev,
736 return ((dev->driver->driver_features & feature) ? 1 : 0); 746 return ((dev->driver->driver_features & feature) ? 1 : 0);
737} 747}
738 748
749#ifdef __alpha__
750#define drm_get_pci_domain(dev) dev->hose->bus->number
751#else
752#define drm_get_pci_domain(dev) 0
753#endif
754
739#if __OS_HAS_AGP 755#if __OS_HAS_AGP
740static inline int drm_core_has_AGP(struct drm_device *dev) 756static inline int drm_core_has_AGP(struct drm_device *dev)
741{ 757{
@@ -1011,6 +1027,18 @@ extern struct class_device *drm_sysfs_device_add(struct class *cs,
1011 drm_head_t *head); 1027 drm_head_t *head);
1012extern void drm_sysfs_device_remove(struct class_device *class_dev); 1028extern void drm_sysfs_device_remove(struct class_device *class_dev);
1013 1029
1030/*
1031 * Basic memory manager support (drm_mm.c)
1032 */
1033extern drm_mm_node_t *drm_mm_get_block(drm_mm_node_t * parent,
1034 unsigned long size,
1035 unsigned alignment);
1036extern void drm_mm_put_block(drm_mm_t *mm, drm_mm_node_t *cur);
1037extern drm_mm_node_t *drm_mm_search_free(const drm_mm_t *mm, unsigned long size,
1038 unsigned alignment, int best_match);
1039extern int drm_mm_init(drm_mm_t *mm, unsigned long start, unsigned long size);
1040extern void drm_mm_takedown(drm_mm_t *mm);
1041
1014/* Inline replacements for DRM_IOREMAP macros */ 1042/* Inline replacements for DRM_IOREMAP macros */
1015static __inline__ void drm_core_ioremap(struct drm_map *map, 1043static __inline__ void drm_core_ioremap(struct drm_map *map,
1016 struct drm_device *dev) 1044 struct drm_device *dev)
diff --git a/drivers/char/drm/drm_auth.c b/drivers/char/drm/drm_auth.c
index 2a37586a7ee8..c7b19d35bcd6 100644
--- a/drivers/char/drm/drm_auth.c
+++ b/drivers/char/drm/drm_auth.c
@@ -36,20 +36,6 @@
36#include "drmP.h" 36#include "drmP.h"
37 37
38/** 38/**
39 * Generate a hash key from a magic.
40 *
41 * \param magic magic.
42 * \return hash key.
43 *
44 * The key is the modulus of the hash table size, #DRM_HASH_SIZE, which must be
45 * a power of 2.
46 */
47static int drm_hash_magic(drm_magic_t magic)
48{
49 return magic & (DRM_HASH_SIZE - 1);
50}
51
52/**
53 * Find the file with the given magic number. 39 * Find the file with the given magic number.
54 * 40 *
55 * \param dev DRM device. 41 * \param dev DRM device.
@@ -63,14 +49,12 @@ static drm_file_t *drm_find_file(drm_device_t * dev, drm_magic_t magic)
63{ 49{
64 drm_file_t *retval = NULL; 50 drm_file_t *retval = NULL;
65 drm_magic_entry_t *pt; 51 drm_magic_entry_t *pt;
66 int hash = drm_hash_magic(magic); 52 drm_hash_item_t *hash;
67 53
68 mutex_lock(&dev->struct_mutex); 54 mutex_lock(&dev->struct_mutex);
69 for (pt = dev->magiclist[hash].head; pt; pt = pt->next) { 55 if (!drm_ht_find_item(&dev->magiclist, (unsigned long)magic, &hash)) {
70 if (pt->magic == magic) { 56 pt = drm_hash_entry(hash, drm_magic_entry_t, hash_item);
71 retval = pt->priv; 57 retval = pt->priv;
72 break;
73 }
74 } 58 }
75 mutex_unlock(&dev->struct_mutex); 59 mutex_unlock(&dev->struct_mutex);
76 return retval; 60 return retval;
@@ -90,28 +74,20 @@ static drm_file_t *drm_find_file(drm_device_t * dev, drm_magic_t magic)
90static int drm_add_magic(drm_device_t * dev, drm_file_t * priv, 74static int drm_add_magic(drm_device_t * dev, drm_file_t * priv,
91 drm_magic_t magic) 75 drm_magic_t magic)
92{ 76{
93 int hash;
94 drm_magic_entry_t *entry; 77 drm_magic_entry_t *entry;
95 78
96 DRM_DEBUG("%d\n", magic); 79 DRM_DEBUG("%d\n", magic);
97 80
98 hash = drm_hash_magic(magic);
99 entry = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC); 81 entry = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC);
100 if (!entry) 82 if (!entry)
101 return -ENOMEM; 83 return -ENOMEM;
102 memset(entry, 0, sizeof(*entry)); 84 memset(entry, 0, sizeof(*entry));
103 entry->magic = magic;
104 entry->priv = priv; 85 entry->priv = priv;
105 entry->next = NULL;
106 86
87 entry->hash_item.key = (unsigned long)magic;
107 mutex_lock(&dev->struct_mutex); 88 mutex_lock(&dev->struct_mutex);
108 if (dev->magiclist[hash].tail) { 89 drm_ht_insert_item(&dev->magiclist, &entry->hash_item);
109 dev->magiclist[hash].tail->next = entry; 90 list_add_tail(&entry->head, &dev->magicfree);
110 dev->magiclist[hash].tail = entry;
111 } else {
112 dev->magiclist[hash].head = entry;
113 dev->magiclist[hash].tail = entry;
114 }
115 mutex_unlock(&dev->struct_mutex); 91 mutex_unlock(&dev->struct_mutex);
116 92
117 return 0; 93 return 0;
@@ -128,34 +104,24 @@ static int drm_add_magic(drm_device_t * dev, drm_file_t * priv,
128 */ 104 */
129static int drm_remove_magic(drm_device_t * dev, drm_magic_t magic) 105static int drm_remove_magic(drm_device_t * dev, drm_magic_t magic)
130{ 106{
131 drm_magic_entry_t *prev = NULL;
132 drm_magic_entry_t *pt; 107 drm_magic_entry_t *pt;
133 int hash; 108 drm_hash_item_t *hash;
134 109
135 DRM_DEBUG("%d\n", magic); 110 DRM_DEBUG("%d\n", magic);
136 hash = drm_hash_magic(magic);
137 111
138 mutex_lock(&dev->struct_mutex); 112 mutex_lock(&dev->struct_mutex);
139 for (pt = dev->magiclist[hash].head; pt; prev = pt, pt = pt->next) { 113 if (drm_ht_find_item(&dev->magiclist, (unsigned long)magic, &hash)) {
140 if (pt->magic == magic) { 114 mutex_unlock(&dev->struct_mutex);
141 if (dev->magiclist[hash].head == pt) { 115 return -EINVAL;
142 dev->magiclist[hash].head = pt->next;
143 }
144 if (dev->magiclist[hash].tail == pt) {
145 dev->magiclist[hash].tail = prev;
146 }
147 if (prev) {
148 prev->next = pt->next;
149 }
150 mutex_unlock(&dev->struct_mutex);
151 return 0;
152 }
153 } 116 }
117 pt = drm_hash_entry(hash, drm_magic_entry_t, hash_item);
118 drm_ht_remove_item(&dev->magiclist, hash);
119 list_del(&pt->head);
154 mutex_unlock(&dev->struct_mutex); 120 mutex_unlock(&dev->struct_mutex);
155 121
156 drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC); 122 drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
157 123
158 return -EINVAL; 124 return 0;
159} 125}
160 126
161/** 127/**
diff --git a/drivers/char/drm/drm_bufs.c b/drivers/char/drm/drm_bufs.c
index 006b06d29727..029baea33b62 100644
--- a/drivers/char/drm/drm_bufs.c
+++ b/drivers/char/drm/drm_bufs.c
@@ -65,43 +65,29 @@ static drm_map_list_t *drm_find_matching_map(drm_device_t *dev,
65 return NULL; 65 return NULL;
66} 66}
67 67
68/* 68static int drm_map_handle(drm_device_t *dev, drm_hash_item_t *hash,
69 * Used to allocate 32-bit handles for mappings. 69 unsigned long user_token, int hashed_handle)
70 */
71#define START_RANGE 0x10000000
72#define END_RANGE 0x40000000
73
74#ifdef _LP64
75static __inline__ unsigned int HandleID(unsigned long lhandle,
76 drm_device_t *dev)
77{ 70{
78 static unsigned int map32_handle = START_RANGE; 71 int use_hashed_handle;
79 unsigned int hash; 72#if (BITS_PER_LONG == 64)
80 73 use_hashed_handle = ((user_token & 0xFFFFFFFF00000000UL) || hashed_handle);
81 if (lhandle & 0xffffffff00000000) { 74#elif (BITS_PER_LONG == 32)
82 hash = map32_handle; 75 use_hashed_handle = hashed_handle;
83 map32_handle += PAGE_SIZE; 76#else
84 if (map32_handle > END_RANGE) 77#error Unsupported long size. Neither 64 nor 32 bits.
85 map32_handle = START_RANGE; 78#endif
86 } else
87 hash = lhandle;
88
89 while (1) {
90 drm_map_list_t *_entry;
91 list_for_each_entry(_entry, &dev->maplist->head, head) {
92 if (_entry->user_token == hash)
93 break;
94 }
95 if (&_entry->head == &dev->maplist->head)
96 return hash;
97 79
98 hash += PAGE_SIZE; 80 if (!use_hashed_handle) {
99 map32_handle += PAGE_SIZE; 81 int ret;
82 hash->key = user_token;
83 ret = drm_ht_insert_item(&dev->map_hash, hash);
84 if (ret != -EINVAL)
85 return ret;
100 } 86 }
87 return drm_ht_just_insert_please(&dev->map_hash, hash,
88 user_token, 32 - PAGE_SHIFT - 3,
89 PAGE_SHIFT, DRM_MAP_HASH_OFFSET);
101} 90}
102#else
103# define HandleID(x,dev) (unsigned int)(x)
104#endif
105 91
106/** 92/**
107 * Ioctl to specify a range of memory that is available for mapping by a non-root process. 93 * Ioctl to specify a range of memory that is available for mapping by a non-root process.
@@ -123,6 +109,8 @@ static int drm_addmap_core(drm_device_t * dev, unsigned int offset,
123 drm_map_t *map; 109 drm_map_t *map;
124 drm_map_list_t *list; 110 drm_map_list_t *list;
125 drm_dma_handle_t *dmah; 111 drm_dma_handle_t *dmah;
112 unsigned long user_token;
113 int ret;
126 114
127 map = drm_alloc(sizeof(*map), DRM_MEM_MAPS); 115 map = drm_alloc(sizeof(*map), DRM_MEM_MAPS);
128 if (!map) 116 if (!map)
@@ -257,11 +245,20 @@ static int drm_addmap_core(drm_device_t * dev, unsigned int offset,
257 245
258 mutex_lock(&dev->struct_mutex); 246 mutex_lock(&dev->struct_mutex);
259 list_add(&list->head, &dev->maplist->head); 247 list_add(&list->head, &dev->maplist->head);
248
260 /* Assign a 32-bit handle */ 249 /* Assign a 32-bit handle */
261 /* We do it here so that dev->struct_mutex protects the increment */ 250 /* We do it here so that dev->struct_mutex protects the increment */
262 list->user_token = HandleID(map->type == _DRM_SHM 251 user_token = (map->type == _DRM_SHM) ? (unsigned long)map->handle :
263 ? (unsigned long)map->handle 252 map->offset;
264 : map->offset, dev); 253 ret = drm_map_handle(dev, &list->hash, user_token, 0);
254 if (ret) {
255 drm_free(map, sizeof(*map), DRM_MEM_MAPS);
256 drm_free(list, sizeof(*list), DRM_MEM_MAPS);
257 mutex_unlock(&dev->struct_mutex);
258 return ret;
259 }
260
261 list->user_token = list->hash.key;
265 mutex_unlock(&dev->struct_mutex); 262 mutex_unlock(&dev->struct_mutex);
266 263
267 *maplist = list; 264 *maplist = list;
@@ -346,6 +343,7 @@ int drm_rmmap_locked(drm_device_t *dev, drm_local_map_t *map)
346 343
347 if (r_list->map == map) { 344 if (r_list->map == map) {
348 list_del(list); 345 list_del(list);
346 drm_ht_remove_key(&dev->map_hash, r_list->user_token);
349 drm_free(list, sizeof(*list), DRM_MEM_MAPS); 347 drm_free(list, sizeof(*list), DRM_MEM_MAPS);
350 break; 348 break;
351 } 349 }
@@ -441,8 +439,10 @@ int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
441 return -EINVAL; 439 return -EINVAL;
442 } 440 }
443 441
444 if (!map) 442 if (!map) {
443 mutex_unlock(&dev->struct_mutex);
445 return -EINVAL; 444 return -EINVAL;
445 }
446 446
447 /* Register and framebuffer maps are permanent */ 447 /* Register and framebuffer maps are permanent */
448 if ((map->type == _DRM_REGISTERS) || (map->type == _DRM_FRAME_BUFFER)) { 448 if ((map->type == _DRM_REGISTERS) || (map->type == _DRM_FRAME_BUFFER)) {
diff --git a/drivers/char/drm/drm_drv.c b/drivers/char/drm/drm_drv.c
index 3c0b882a8e72..b366c5b1bd16 100644
--- a/drivers/char/drm/drm_drv.c
+++ b/drivers/char/drm/drm_drv.c
@@ -118,7 +118,7 @@ static drm_ioctl_desc_t drm_ioctls[] = {
118 [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK)] = {drm_wait_vblank, 0}, 118 [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK)] = {drm_wait_vblank, 0},
119}; 119};
120 120
121#define DRIVER_IOCTL_COUNT DRM_ARRAY_SIZE( drm_ioctls ) 121#define DRIVER_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
122 122
123/** 123/**
124 * Take down the DRM device. 124 * Take down the DRM device.
@@ -155,12 +155,13 @@ int drm_lastclose(drm_device_t * dev)
155 del_timer(&dev->timer); 155 del_timer(&dev->timer);
156 156
157 /* Clear pid list */ 157 /* Clear pid list */
158 for (i = 0; i < DRM_HASH_SIZE; i++) { 158 if (dev->magicfree.next) {
159 for (pt = dev->magiclist[i].head; pt; pt = next) { 159 list_for_each_entry_safe(pt, next, &dev->magicfree, head) {
160 next = pt->next; 160 list_del(&pt->head);
161 drm_ht_remove_item(&dev->magiclist, &pt->hash_item);
161 drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC); 162 drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
162 } 163 }
163 dev->magiclist[i].head = dev->magiclist[i].tail = NULL; 164 drm_ht_remove(&dev->magiclist);
164 } 165 }
165 166
166 /* Clear AGP information */ 167 /* Clear AGP information */
@@ -299,6 +300,7 @@ static void drm_cleanup(drm_device_t * dev)
299 if (dev->maplist) { 300 if (dev->maplist) {
300 drm_free(dev->maplist, sizeof(*dev->maplist), DRM_MEM_MAPS); 301 drm_free(dev->maplist, sizeof(*dev->maplist), DRM_MEM_MAPS);
301 dev->maplist = NULL; 302 dev->maplist = NULL;
303 drm_ht_remove(&dev->map_hash);
302 } 304 }
303 305
304 drm_ctxbitmap_cleanup(dev); 306 drm_ctxbitmap_cleanup(dev);
diff --git a/drivers/char/drm/drm_fops.c b/drivers/char/drm/drm_fops.c
index b7f7951c4587..898f47dafec0 100644
--- a/drivers/char/drm/drm_fops.c
+++ b/drivers/char/drm/drm_fops.c
@@ -53,6 +53,8 @@ static int drm_setup(drm_device_t * dev)
53 return ret; 53 return ret;
54 } 54 }
55 55
56 dev->magicfree.next = NULL;
57
56 /* prebuild the SAREA */ 58 /* prebuild the SAREA */
57 i = drm_addmap(dev, 0, SAREA_MAX, _DRM_SHM, _DRM_CONTAINS_LOCK, &map); 59 i = drm_addmap(dev, 0, SAREA_MAX, _DRM_SHM, _DRM_CONTAINS_LOCK, &map);
58 if (i != 0) 60 if (i != 0)
@@ -69,13 +71,11 @@ static int drm_setup(drm_device_t * dev)
69 return i; 71 return i;
70 } 72 }
71 73
72 for (i = 0; i < DRM_ARRAY_SIZE(dev->counts); i++) 74 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
73 atomic_set(&dev->counts[i], 0); 75 atomic_set(&dev->counts[i], 0);
74 76
75 for (i = 0; i < DRM_HASH_SIZE; i++) { 77 drm_ht_create(&dev->magiclist, DRM_MAGIC_HASH_ORDER);
76 dev->magiclist[i].head = NULL; 78 INIT_LIST_HEAD(&dev->magicfree);
77 dev->magiclist[i].tail = NULL;
78 }
79 79
80 dev->ctxlist = drm_alloc(sizeof(*dev->ctxlist), DRM_MEM_CTXLIST); 80 dev->ctxlist = drm_alloc(sizeof(*dev->ctxlist), DRM_MEM_CTXLIST);
81 if (dev->ctxlist == NULL) 81 if (dev->ctxlist == NULL)
diff --git a/drivers/char/drm/drm_hashtab.c b/drivers/char/drm/drm_hashtab.c
new file mode 100644
index 000000000000..a0b2d6802ae4
--- /dev/null
+++ b/drivers/char/drm/drm_hashtab.c
@@ -0,0 +1,190 @@
1/**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND. USA.
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 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 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 *
27 **************************************************************************/
28/*
29 * Simple open hash tab implementation.
30 *
31 * Authors:
32 * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
33 */
34
35#include "drmP.h"
36#include "drm_hashtab.h"
37#include <linux/hash.h>
38
39int drm_ht_create(drm_open_hash_t *ht, unsigned int order)
40{
41 unsigned int i;
42
43 ht->size = 1 << order;
44 ht->order = order;
45 ht->fill = 0;
46 ht->table = vmalloc(ht->size*sizeof(*ht->table));
47 if (!ht->table) {
48 DRM_ERROR("Out of memory for hash table\n");
49 return -ENOMEM;
50 }
51 for (i=0; i< ht->size; ++i) {
52 INIT_HLIST_HEAD(&ht->table[i]);
53 }
54 return 0;
55}
56
57void drm_ht_verbose_list(drm_open_hash_t *ht, unsigned long key)
58{
59 drm_hash_item_t *entry;
60 struct hlist_head *h_list;
61 struct hlist_node *list;
62 unsigned int hashed_key;
63 int count = 0;
64
65 hashed_key = hash_long(key, ht->order);
66 DRM_DEBUG("Key is 0x%08lx, Hashed key is 0x%08x\n", key, hashed_key);
67 h_list = &ht->table[hashed_key];
68 hlist_for_each(list, h_list) {
69 entry = hlist_entry(list, drm_hash_item_t, head);
70 DRM_DEBUG("count %d, key: 0x%08lx\n", count++, entry->key);
71 }
72}
73
74static struct hlist_node *drm_ht_find_key(drm_open_hash_t *ht,
75 unsigned long key)
76{
77 drm_hash_item_t *entry;
78 struct hlist_head *h_list;
79 struct hlist_node *list;
80 unsigned int hashed_key;
81
82 hashed_key = hash_long(key, ht->order);
83 h_list = &ht->table[hashed_key];
84 hlist_for_each(list, h_list) {
85 entry = hlist_entry(list, drm_hash_item_t, head);
86 if (entry->key == key)
87 return list;
88 if (entry->key > key)
89 break;
90 }
91 return NULL;
92}
93
94
95int drm_ht_insert_item(drm_open_hash_t *ht, drm_hash_item_t *item)
96{
97 drm_hash_item_t *entry;
98 struct hlist_head *h_list;
99 struct hlist_node *list, *parent;
100 unsigned int hashed_key;
101 unsigned long key = item->key;
102
103 hashed_key = hash_long(key, ht->order);
104 h_list = &ht->table[hashed_key];
105 parent = NULL;
106 hlist_for_each(list, h_list) {
107 entry = hlist_entry(list, drm_hash_item_t, head);
108 if (entry->key == key)
109 return -EINVAL;
110 if (entry->key > key)
111 break;
112 parent = list;
113 }
114 if (parent) {
115 hlist_add_after(parent, &item->head);
116 } else {
117 hlist_add_head(&item->head, h_list);
118 }
119 return 0;
120}
121
122/*
123 * Just insert an item and return any "bits" bit key that hasn't been
124 * used before.
125 */
126int drm_ht_just_insert_please(drm_open_hash_t *ht, drm_hash_item_t *item,
127 unsigned long seed, int bits, int shift,
128 unsigned long add)
129{
130 int ret;
131 unsigned long mask = (1 << bits) - 1;
132 unsigned long first, unshifted_key;
133
134 unshifted_key = hash_long(seed, bits);
135 first = unshifted_key;
136 do {
137 item->key = (unshifted_key << shift) + add;
138 ret = drm_ht_insert_item(ht, item);
139 if (ret)
140 unshifted_key = (unshifted_key + 1) & mask;
141 } while(ret && (unshifted_key != first));
142
143 if (ret) {
144 DRM_ERROR("Available key bit space exhausted\n");
145 return -EINVAL;
146 }
147 return 0;
148}
149
150int drm_ht_find_item(drm_open_hash_t *ht, unsigned long key,
151 drm_hash_item_t **item)
152{
153 struct hlist_node *list;
154
155 list = drm_ht_find_key(ht, key);
156 if (!list)
157 return -EINVAL;
158
159 *item = hlist_entry(list, drm_hash_item_t, head);
160 return 0;
161}
162
163int drm_ht_remove_key(drm_open_hash_t *ht, unsigned long key)
164{
165 struct hlist_node *list;
166
167 list = drm_ht_find_key(ht, key);
168 if (list) {
169 hlist_del_init(list);
170 ht->fill--;
171 return 0;
172 }
173 return -EINVAL;
174}
175
176int drm_ht_remove_item(drm_open_hash_t *ht, drm_hash_item_t *item)
177{
178 hlist_del_init(&item->head);
179 ht->fill--;
180 return 0;
181}
182
183void drm_ht_remove(drm_open_hash_t *ht)
184{
185 if (ht->table) {
186 vfree(ht->table);
187 ht->table = NULL;
188 }
189}
190
diff --git a/drivers/char/drm/drm_hashtab.h b/drivers/char/drm/drm_hashtab.h
new file mode 100644
index 000000000000..40afec05bff8
--- /dev/null
+++ b/drivers/char/drm/drm_hashtab.h
@@ -0,0 +1,67 @@
1/**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Bismack, ND. USA.
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 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 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 *
27 **************************************************************************/
28/*
29 * Simple open hash tab implementation.
30 *
31 * Authors:
32 * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
33 */
34
35#ifndef DRM_HASHTAB_H
36#define DRM_HASHTAB_H
37
38#define drm_hash_entry(_ptr, _type, _member) container_of(_ptr, _type, _member)
39
40typedef struct drm_hash_item{
41 struct hlist_node head;
42 unsigned long key;
43} drm_hash_item_t;
44
45typedef struct drm_open_hash{
46 unsigned int size;
47 unsigned int order;
48 unsigned int fill;
49 struct hlist_head *table;
50} drm_open_hash_t;
51
52
53extern int drm_ht_create(drm_open_hash_t *ht, unsigned int order);
54extern int drm_ht_insert_item(drm_open_hash_t *ht, drm_hash_item_t *item);
55extern int drm_ht_just_insert_please(drm_open_hash_t *ht, drm_hash_item_t *item,
56 unsigned long seed, int bits, int shift,
57 unsigned long add);
58extern int drm_ht_find_item(drm_open_hash_t *ht, unsigned long key, drm_hash_item_t **item);
59
60extern void drm_ht_verbose_list(drm_open_hash_t *ht, unsigned long key);
61extern int drm_ht_remove_key(drm_open_hash_t *ht, unsigned long key);
62extern int drm_ht_remove_item(drm_open_hash_t *ht, drm_hash_item_t *item);
63extern void drm_ht_remove(drm_open_hash_t *ht);
64
65
66#endif
67
diff --git a/drivers/char/drm/drm_ioc32.c b/drivers/char/drm/drm_ioc32.c
index e9e2db18952d..d4f874520082 100644
--- a/drivers/char/drm/drm_ioc32.c
+++ b/drivers/char/drm/drm_ioc32.c
@@ -1051,7 +1051,7 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1051 drm_ioctl_compat_t *fn; 1051 drm_ioctl_compat_t *fn;
1052 int ret; 1052 int ret;
1053 1053
1054 if (nr >= DRM_ARRAY_SIZE(drm_compat_ioctls)) 1054 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
1055 return -ENOTTY; 1055 return -ENOTTY;
1056 1056
1057 fn = drm_compat_ioctls[nr]; 1057 fn = drm_compat_ioctls[nr];
diff --git a/drivers/char/drm/drm_ioctl.c b/drivers/char/drm/drm_ioctl.c
index 555f323b8a32..565895547d75 100644
--- a/drivers/char/drm/drm_ioctl.c
+++ b/drivers/char/drm/drm_ioctl.c
@@ -127,9 +127,10 @@ int drm_setunique(struct inode *inode, struct file *filp,
127 domain = bus >> 8; 127 domain = bus >> 8;
128 bus &= 0xff; 128 bus &= 0xff;
129 129
130 if ((domain != dev->pci_domain) || 130 if ((domain != drm_get_pci_domain(dev)) ||
131 (bus != dev->pci_bus) || 131 (bus != dev->pdev->bus->number) ||
132 (slot != dev->pci_slot) || (func != dev->pci_func)) 132 (slot != PCI_SLOT(dev->pdev->devfn)) ||
133 (func != PCI_FUNC(dev->pdev->devfn)))
133 return -EINVAL; 134 return -EINVAL;
134 135
135 return 0; 136 return 0;
@@ -140,15 +141,17 @@ static int drm_set_busid(drm_device_t * dev)
140 int len; 141 int len;
141 142
142 if (dev->unique != NULL) 143 if (dev->unique != NULL)
143 return EBUSY; 144 return 0;
144 145
145 dev->unique_len = 40; 146 dev->unique_len = 40;
146 dev->unique = drm_alloc(dev->unique_len + 1, DRM_MEM_DRIVER); 147 dev->unique = drm_alloc(dev->unique_len + 1, DRM_MEM_DRIVER);
147 if (dev->unique == NULL) 148 if (dev->unique == NULL)
148 return ENOMEM; 149 return -ENOMEM;
149 150
150 len = snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%d", 151 len = snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%d",
151 dev->pci_domain, dev->pci_bus, dev->pci_slot, dev->pci_func); 152 drm_get_pci_domain(dev), dev->pdev->bus->number,
153 PCI_SLOT(dev->pdev->devfn),
154 PCI_FUNC(dev->pdev->devfn));
152 155
153 if (len > dev->unique_len) 156 if (len > dev->unique_len)
154 DRM_ERROR("Unique buffer overflowed\n"); 157 DRM_ERROR("Unique buffer overflowed\n");
@@ -157,7 +160,7 @@ static int drm_set_busid(drm_device_t * dev)
157 drm_alloc(strlen(dev->driver->pci_driver.name) + dev->unique_len + 160 drm_alloc(strlen(dev->driver->pci_driver.name) + dev->unique_len +
158 2, DRM_MEM_DRIVER); 161 2, DRM_MEM_DRIVER);
159 if (dev->devname == NULL) 162 if (dev->devname == NULL)
160 return ENOMEM; 163 return -ENOMEM;
161 164
162 sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name, 165 sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name,
163 dev->unique); 166 dev->unique);
@@ -330,27 +333,32 @@ int drm_setversion(DRM_IOCTL_ARGS)
330 drm_set_version_t retv; 333 drm_set_version_t retv;
331 int if_version; 334 int if_version;
332 drm_set_version_t __user *argp = (void __user *)data; 335 drm_set_version_t __user *argp = (void __user *)data;
336 int ret;
333 337
334 DRM_COPY_FROM_USER_IOCTL(sv, argp, sizeof(sv)); 338 if (copy_from_user(&sv, argp, sizeof(sv)))
339 return -EFAULT;
335 340
336 retv.drm_di_major = DRM_IF_MAJOR; 341 retv.drm_di_major = DRM_IF_MAJOR;
337 retv.drm_di_minor = DRM_IF_MINOR; 342 retv.drm_di_minor = DRM_IF_MINOR;
338 retv.drm_dd_major = dev->driver->major; 343 retv.drm_dd_major = dev->driver->major;
339 retv.drm_dd_minor = dev->driver->minor; 344 retv.drm_dd_minor = dev->driver->minor;
340 345
341 DRM_COPY_TO_USER_IOCTL(argp, retv, sizeof(sv)); 346 if (copy_to_user(argp, &retv, sizeof(retv)))
347 return -EFAULT;
342 348
343 if (sv.drm_di_major != -1) { 349 if (sv.drm_di_major != -1) {
344 if (sv.drm_di_major != DRM_IF_MAJOR || 350 if (sv.drm_di_major != DRM_IF_MAJOR ||
345 sv.drm_di_minor < 0 || sv.drm_di_minor > DRM_IF_MINOR) 351 sv.drm_di_minor < 0 || sv.drm_di_minor > DRM_IF_MINOR)
346 return EINVAL; 352 return -EINVAL;
347 if_version = DRM_IF_VERSION(sv.drm_di_major, sv.drm_di_minor); 353 if_version = DRM_IF_VERSION(sv.drm_di_major, sv.drm_di_minor);
348 dev->if_version = DRM_MAX(if_version, dev->if_version); 354 dev->if_version = max(if_version, dev->if_version);
349 if (sv.drm_di_minor >= 1) { 355 if (sv.drm_di_minor >= 1) {
350 /* 356 /*
351 * Version 1.1 includes tying of DRM to specific device 357 * Version 1.1 includes tying of DRM to specific device
352 */ 358 */
353 drm_set_busid(dev); 359 ret = drm_set_busid(dev);
360 if (ret)
361 return ret;
354 } 362 }
355 } 363 }
356 364
@@ -358,7 +366,7 @@ int drm_setversion(DRM_IOCTL_ARGS)
358 if (sv.drm_dd_major != dev->driver->major || 366 if (sv.drm_dd_major != dev->driver->major ||
359 sv.drm_dd_minor < 0 367 sv.drm_dd_minor < 0
360 || sv.drm_dd_minor > dev->driver->minor) 368 || sv.drm_dd_minor > dev->driver->minor)
361 return EINVAL; 369 return -EINVAL;
362 370
363 if (dev->driver->set_version) 371 if (dev->driver->set_version)
364 dev->driver->set_version(dev, &sv); 372 dev->driver->set_version(dev, &sv);
diff --git a/drivers/char/drm/drm_irq.c b/drivers/char/drm/drm_irq.c
index ebdb7182c4fd..4553a3a1e496 100644
--- a/drivers/char/drm/drm_irq.c
+++ b/drivers/char/drm/drm_irq.c
@@ -64,9 +64,9 @@ int drm_irq_by_busid(struct inode *inode, struct file *filp,
64 if (copy_from_user(&p, argp, sizeof(p))) 64 if (copy_from_user(&p, argp, sizeof(p)))
65 return -EFAULT; 65 return -EFAULT;
66 66
67 if ((p.busnum >> 8) != dev->pci_domain || 67 if ((p.busnum >> 8) != drm_get_pci_domain(dev) ||
68 (p.busnum & 0xff) != dev->pci_bus || 68 (p.busnum & 0xff) != dev->pdev->bus->number ||
69 p.devnum != dev->pci_slot || p.funcnum != dev->pci_func) 69 p.devnum != PCI_SLOT(dev->pdev->devfn) || p.funcnum != PCI_FUNC(dev->pdev->devfn))
70 return -EINVAL; 70 return -EINVAL;
71 71
72 p.irq = dev->irq; 72 p.irq = dev->irq;
@@ -255,7 +255,8 @@ int drm_wait_vblank(DRM_IOCTL_ARGS)
255 if (!dev->irq) 255 if (!dev->irq)
256 return -EINVAL; 256 return -EINVAL;
257 257
258 DRM_COPY_FROM_USER_IOCTL(vblwait, argp, sizeof(vblwait)); 258 if (copy_from_user(&vblwait, argp, sizeof(vblwait)))
259 return -EFAULT;
259 260
260 switch (vblwait.request.type & ~_DRM_VBLANK_FLAGS_MASK) { 261 switch (vblwait.request.type & ~_DRM_VBLANK_FLAGS_MASK) {
261 case _DRM_VBLANK_RELATIVE: 262 case _DRM_VBLANK_RELATIVE:
@@ -329,7 +330,8 @@ int drm_wait_vblank(DRM_IOCTL_ARGS)
329 } 330 }
330 331
331 done: 332 done:
332 DRM_COPY_TO_USER_IOCTL(argp, vblwait, sizeof(vblwait)); 333 if (copy_to_user(argp, &vblwait, sizeof(vblwait)))
334 return -EFAULT;
333 335
334 return ret; 336 return ret;
335} 337}
diff --git a/drivers/char/drm/drm_mm.c b/drivers/char/drm/drm_mm.c
new file mode 100644
index 000000000000..617526bd5b0c
--- /dev/null
+++ b/drivers/char/drm/drm_mm.c
@@ -0,0 +1,201 @@
1/**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA.
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 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 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 *
27 **************************************************************************/
28
29/*
30 * Generic simple memory manager implementation. Intended to be used as a base
31 * class implementation for more advanced memory managers.
32 *
33 * Note that the algorithm used is quite simple and there might be substantial
34 * performance gains if a smarter free list is implemented. Currently it is just an
35 * unordered stack of free regions. This could easily be improved if an RB-tree
36 * is used instead. At least if we expect heavy fragmentation.
37 *
38 * Aligned allocations can also see improvement.
39 *
40 * Authors:
41 * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
42 */
43
44#include "drmP.h"
45
46drm_mm_node_t *drm_mm_get_block(drm_mm_node_t * parent,
47 unsigned long size, unsigned alignment)
48{
49
50 drm_mm_node_t *child;
51
52 if (alignment)
53 size += alignment - 1;
54
55 if (parent->size == size) {
56 list_del_init(&parent->fl_entry);
57 parent->free = 0;
58 return parent;
59 } else {
60 child = (drm_mm_node_t *) drm_alloc(sizeof(*child), DRM_MEM_MM);
61 if (!child)
62 return NULL;
63
64 INIT_LIST_HEAD(&child->ml_entry);
65 INIT_LIST_HEAD(&child->fl_entry);
66
67 child->free = 0;
68 child->size = size;
69 child->start = parent->start;
70
71 list_add_tail(&child->ml_entry, &parent->ml_entry);
72 parent->size -= size;
73 parent->start += size;
74 }
75 return child;
76}
77
78/*
79 * Put a block. Merge with the previous and / or next block if they are free.
80 * Otherwise add to the free stack.
81 */
82
83void drm_mm_put_block(drm_mm_t * mm, drm_mm_node_t * cur)
84{
85
86 drm_mm_node_t *list_root = &mm->root_node;
87 struct list_head *cur_head = &cur->ml_entry;
88 struct list_head *root_head = &list_root->ml_entry;
89 drm_mm_node_t *prev_node = NULL;
90 drm_mm_node_t *next_node;
91
92 int merged = 0;
93
94 if (cur_head->prev != root_head) {
95 prev_node = list_entry(cur_head->prev, drm_mm_node_t, ml_entry);
96 if (prev_node->free) {
97 prev_node->size += cur->size;
98 merged = 1;
99 }
100 }
101 if (cur_head->next != root_head) {
102 next_node = list_entry(cur_head->next, drm_mm_node_t, ml_entry);
103 if (next_node->free) {
104 if (merged) {
105 prev_node->size += next_node->size;
106 list_del(&next_node->ml_entry);
107 list_del(&next_node->fl_entry);
108 drm_free(next_node, sizeof(*next_node),
109 DRM_MEM_MM);
110 } else {
111 next_node->size += cur->size;
112 next_node->start = cur->start;
113 merged = 1;
114 }
115 }
116 }
117 if (!merged) {
118 cur->free = 1;
119 list_add(&cur->fl_entry, &list_root->fl_entry);
120 } else {
121 list_del(&cur->ml_entry);
122 drm_free(cur, sizeof(*cur), DRM_MEM_MM);
123 }
124}
125
126drm_mm_node_t *drm_mm_search_free(const drm_mm_t * mm,
127 unsigned long size,
128 unsigned alignment, int best_match)
129{
130 struct list_head *list;
131 const struct list_head *free_stack = &mm->root_node.fl_entry;
132 drm_mm_node_t *entry;
133 drm_mm_node_t *best;
134 unsigned long best_size;
135
136 best = NULL;
137 best_size = ~0UL;
138
139 if (alignment)
140 size += alignment - 1;
141
142 list_for_each(list, free_stack) {
143 entry = list_entry(list, drm_mm_node_t, fl_entry);
144 if (entry->size >= size) {
145 if (!best_match)
146 return entry;
147 if (size < best_size) {
148 best = entry;
149 best_size = entry->size;
150 }
151 }
152 }
153
154 return best;
155}
156
157int drm_mm_init(drm_mm_t * mm, unsigned long start, unsigned long size)
158{
159 drm_mm_node_t *child;
160
161 INIT_LIST_HEAD(&mm->root_node.ml_entry);
162 INIT_LIST_HEAD(&mm->root_node.fl_entry);
163 child = (drm_mm_node_t *) drm_alloc(sizeof(*child), DRM_MEM_MM);
164 if (!child)
165 return -ENOMEM;
166
167 INIT_LIST_HEAD(&child->ml_entry);
168 INIT_LIST_HEAD(&child->fl_entry);
169
170 child->start = start;
171 child->size = size;
172 child->free = 1;
173
174 list_add(&child->fl_entry, &mm->root_node.fl_entry);
175 list_add(&child->ml_entry, &mm->root_node.ml_entry);
176
177 return 0;
178}
179
180EXPORT_SYMBOL(drm_mm_init);
181
182void drm_mm_takedown(drm_mm_t * mm)
183{
184 struct list_head *bnode = mm->root_node.fl_entry.next;
185 drm_mm_node_t *entry;
186
187 entry = list_entry(bnode, drm_mm_node_t, fl_entry);
188
189 if (entry->ml_entry.next != &mm->root_node.ml_entry ||
190 entry->fl_entry.next != &mm->root_node.fl_entry) {
191 DRM_ERROR("Memory manager not clean. Delaying takedown\n");
192 return;
193 }
194
195 list_del(&entry->fl_entry);
196 list_del(&entry->ml_entry);
197
198 drm_free(entry, sizeof(*entry), DRM_MEM_MM);
199}
200
201EXPORT_SYMBOL(drm_mm_takedown);
diff --git a/drivers/char/drm/drm_pciids.h b/drivers/char/drm/drm_pciids.h
index b1bb3c7b568d..09398d5fbd3f 100644
--- a/drivers/char/drm/drm_pciids.h
+++ b/drivers/char/drm/drm_pciids.h
@@ -3,13 +3,13 @@
3 Please contact dri-devel@lists.sf.net to add new cards to this list 3 Please contact dri-devel@lists.sf.net to add new cards to this list
4*/ 4*/
5#define radeon_PCI_IDS \ 5#define radeon_PCI_IDS \
6 {0x1002, 0x3150, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY}, \ 6 {0x1002, 0x3150, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \
7 {0x1002, 0x3152, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 7 {0x1002, 0x3152, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
8 {0x1002, 0x3154, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 8 {0x1002, 0x3154, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
9 {0x1002, 0x3E50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \ 9 {0x1002, 0x3E50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
10 {0x1002, 0x3E54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \ 10 {0x1002, 0x3E54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
11 {0x1002, 0x4136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|CHIP_IS_IGP}, \ 11 {0x1002, 0x4136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|RADEON_IS_IGP}, \
12 {0x1002, 0x4137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|CHIP_IS_IGP}, \ 12 {0x1002, 0x4137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|RADEON_IS_IGP}, \
13 {0x1002, 0x4144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 13 {0x1002, 0x4144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
14 {0x1002, 0x4145, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 14 {0x1002, 0x4145, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
15 {0x1002, 0x4146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 15 {0x1002, 0x4146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
@@ -25,35 +25,35 @@
25 {0x1002, 0x4154, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \ 25 {0x1002, 0x4154, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
26 {0x1002, 0x4155, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \ 26 {0x1002, 0x4155, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
27 {0x1002, 0x4156, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \ 27 {0x1002, 0x4156, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
28 {0x1002, 0x4237, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|CHIP_IS_IGP}, \ 28 {0x1002, 0x4237, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|RADEON_IS_IGP}, \
29 {0x1002, 0x4242, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 29 {0x1002, 0x4242, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
30 {0x1002, 0x4243, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 30 {0x1002, 0x4243, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
31 {0x1002, 0x4336, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|CHIP_IS_IGP|CHIP_IS_MOBILITY}, \ 31 {0x1002, 0x4336, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \
32 {0x1002, 0x4337, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|CHIP_IS_IGP|CHIP_IS_MOBILITY}, \ 32 {0x1002, 0x4337, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \
33 {0x1002, 0x4437, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|CHIP_IS_IGP|CHIP_IS_MOBILITY}, \ 33 {0x1002, 0x4437, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \
34 {0x1002, 0x4966, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250}, \ 34 {0x1002, 0x4966, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250}, \
35 {0x1002, 0x4967, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250}, \ 35 {0x1002, 0x4967, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250}, \
36 {0x1002, 0x4A48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 36 {0x1002, 0x4A48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
37 {0x1002, 0x4A49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 37 {0x1002, 0x4A49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
38 {0x1002, 0x4A4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 38 {0x1002, 0x4A4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
39 {0x1002, 0x4A4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 39 {0x1002, 0x4A4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
40 {0x1002, 0x4A4C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 40 {0x1002, 0x4A4C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
41 {0x1002, 0x4A4D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 41 {0x1002, 0x4A4D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
42 {0x1002, 0x4A4E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 42 {0x1002, 0x4A4E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
43 {0x1002, 0x4A4F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 43 {0x1002, 0x4A4F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
44 {0x1002, 0x4A50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 44 {0x1002, 0x4A50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
45 {0x1002, 0x4A54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 45 {0x1002, 0x4A54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
46 {0x1002, 0x4B49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 46 {0x1002, 0x4B49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
47 {0x1002, 0x4B4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 47 {0x1002, 0x4B4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
48 {0x1002, 0x4B4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 48 {0x1002, 0x4B4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
49 {0x1002, 0x4B4C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 49 {0x1002, 0x4B4C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
50 {0x1002, 0x4C57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200|CHIP_IS_MOBILITY}, \ 50 {0x1002, 0x4C57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200|RADEON_IS_MOBILITY}, \
51 {0x1002, 0x4C58, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200|CHIP_IS_MOBILITY}, \ 51 {0x1002, 0x4C58, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200|RADEON_IS_MOBILITY}, \
52 {0x1002, 0x4C59, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100|CHIP_IS_MOBILITY}, \ 52 {0x1002, 0x4C59, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100|RADEON_IS_MOBILITY}, \
53 {0x1002, 0x4C5A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100|CHIP_IS_MOBILITY}, \ 53 {0x1002, 0x4C5A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100|RADEON_IS_MOBILITY}, \
54 {0x1002, 0x4C64, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|CHIP_IS_MOBILITY}, \ 54 {0x1002, 0x4C64, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|RADEON_IS_MOBILITY}, \
55 {0x1002, 0x4C66, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|CHIP_IS_MOBILITY}, \ 55 {0x1002, 0x4C66, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|RADEON_IS_MOBILITY}, \
56 {0x1002, 0x4C67, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|CHIP_IS_MOBILITY}, \ 56 {0x1002, 0x4C67, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|RADEON_IS_MOBILITY}, \
57 {0x1002, 0x4E44, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 57 {0x1002, 0x4E44, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
58 {0x1002, 0x4E45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 58 {0x1002, 0x4E45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
59 {0x1002, 0x4E46, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 59 {0x1002, 0x4E46, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
@@ -62,16 +62,16 @@
62 {0x1002, 0x4E49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \ 62 {0x1002, 0x4E49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
63 {0x1002, 0x4E4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \ 63 {0x1002, 0x4E4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
64 {0x1002, 0x4E4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \ 64 {0x1002, 0x4E4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
65 {0x1002, 0x4E50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \ 65 {0x1002, 0x4E50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
66 {0x1002, 0x4E51, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \ 66 {0x1002, 0x4E51, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
67 {0x1002, 0x4E52, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \ 67 {0x1002, 0x4E52, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
68 {0x1002, 0x4E53, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \ 68 {0x1002, 0x4E53, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
69 {0x1002, 0x4E54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \ 69 {0x1002, 0x4E54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
70 {0x1002, 0x4E56, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \ 70 {0x1002, 0x4E56, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
71 {0x1002, 0x5144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|CHIP_SINGLE_CRTC}, \ 71 {0x1002, 0x5144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|RADEON_SINGLE_CRTC}, \
72 {0x1002, 0x5145, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|CHIP_SINGLE_CRTC}, \ 72 {0x1002, 0x5145, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|RADEON_SINGLE_CRTC}, \
73 {0x1002, 0x5146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|CHIP_SINGLE_CRTC}, \ 73 {0x1002, 0x5146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|RADEON_SINGLE_CRTC}, \
74 {0x1002, 0x5147, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|CHIP_SINGLE_CRTC}, \ 74 {0x1002, 0x5147, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|RADEON_SINGLE_CRTC}, \
75 {0x1002, 0x5148, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 75 {0x1002, 0x5148, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
76 {0x1002, 0x514C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 76 {0x1002, 0x514C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
77 {0x1002, 0x514D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 77 {0x1002, 0x514D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
@@ -80,59 +80,59 @@
80 {0x1002, 0x5159, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \ 80 {0x1002, 0x5159, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
81 {0x1002, 0x515A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \ 81 {0x1002, 0x515A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
82 {0x1002, 0x515E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \ 82 {0x1002, 0x515E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
83 {0x1002, 0x5460, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY}, \ 83 {0x1002, 0x5460, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \
84 {0x1002, 0x5462, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY}, \ 84 {0x1002, 0x5462, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \
85 {0x1002, 0x5464, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY}, \ 85 {0x1002, 0x5464, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \
86 {0x1002, 0x5548, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 86 {0x1002, 0x5548, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
87 {0x1002, 0x5549, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 87 {0x1002, 0x5549, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
88 {0x1002, 0x554A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 88 {0x1002, 0x554A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
89 {0x1002, 0x554B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 89 {0x1002, 0x554B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
90 {0x1002, 0x554C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 90 {0x1002, 0x554C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
91 {0x1002, 0x554D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 91 {0x1002, 0x554D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
92 {0x1002, 0x554E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 92 {0x1002, 0x554E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
93 {0x1002, 0x554F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 93 {0x1002, 0x554F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
94 {0x1002, 0x5550, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 94 {0x1002, 0x5550, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
95 {0x1002, 0x5551, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 95 {0x1002, 0x5551, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
96 {0x1002, 0x5552, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 96 {0x1002, 0x5552, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
97 {0x1002, 0x5554, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 97 {0x1002, 0x5554, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
98 {0x1002, 0x564A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 98 {0x1002, 0x564A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
99 {0x1002, 0x564B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 99 {0x1002, 0x564B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
100 {0x1002, 0x564F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 100 {0x1002, 0x564F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
101 {0x1002, 0x5652, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 101 {0x1002, 0x5652, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
102 {0x1002, 0x5653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 102 {0x1002, 0x5653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
103 {0x1002, 0x5834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|CHIP_IS_IGP}, \ 103 {0x1002, 0x5834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP}, \
104 {0x1002, 0x5835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|CHIP_IS_IGP|CHIP_IS_MOBILITY}, \ 104 {0x1002, 0x5835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \
105 {0x1002, 0x5960, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 105 {0x1002, 0x5960, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
106 {0x1002, 0x5961, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 106 {0x1002, 0x5961, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
107 {0x1002, 0x5962, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 107 {0x1002, 0x5962, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
108 {0x1002, 0x5964, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 108 {0x1002, 0x5964, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
109 {0x1002, 0x5965, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 109 {0x1002, 0x5965, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
110 {0x1002, 0x5969, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \ 110 {0x1002, 0x5969, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
111 {0x1002, 0x5b60, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \ 111 {0x1002, 0x5b60, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
112 {0x1002, 0x5b62, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \ 112 {0x1002, 0x5b62, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
113 {0x1002, 0x5b63, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \ 113 {0x1002, 0x5b63, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
114 {0x1002, 0x5b64, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \ 114 {0x1002, 0x5b64, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
115 {0x1002, 0x5b65, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \ 115 {0x1002, 0x5b65, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
116 {0x1002, 0x5c61, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280|CHIP_IS_MOBILITY}, \ 116 {0x1002, 0x5c61, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280|RADEON_IS_MOBILITY}, \
117 {0x1002, 0x5c63, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280|CHIP_IS_MOBILITY}, \ 117 {0x1002, 0x5c63, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280|RADEON_IS_MOBILITY}, \
118 {0x1002, 0x5d48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 118 {0x1002, 0x5d48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
119 {0x1002, 0x5d49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 119 {0x1002, 0x5d49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
120 {0x1002, 0x5d4a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 120 {0x1002, 0x5d4a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
121 {0x1002, 0x5d4c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 121 {0x1002, 0x5d4c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
122 {0x1002, 0x5d4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 122 {0x1002, 0x5d4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
123 {0x1002, 0x5d4e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 123 {0x1002, 0x5d4e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
124 {0x1002, 0x5d4f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 124 {0x1002, 0x5d4f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
125 {0x1002, 0x5d50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 125 {0x1002, 0x5d50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
126 {0x1002, 0x5d52, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 126 {0x1002, 0x5d52, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
127 {0x1002, 0x5d57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 127 {0x1002, 0x5d57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
128 {0x1002, 0x5e48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \ 128 {0x1002, 0x5e48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
129 {0x1002, 0x5e4a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \ 129 {0x1002, 0x5e4a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
130 {0x1002, 0x5e4b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \ 130 {0x1002, 0x5e4b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
131 {0x1002, 0x5e4c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \ 131 {0x1002, 0x5e4c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
132 {0x1002, 0x5e4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \ 132 {0x1002, 0x5e4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
133 {0x1002, 0x5e4f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \ 133 {0x1002, 0x5e4f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
134 {0x1002, 0x7834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|CHIP_IS_IGP|CHIP_NEW_MEMMAP}, \ 134 {0x1002, 0x7834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_NEW_MEMMAP}, \
135 {0x1002, 0x7835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|CHIP_IS_IGP|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 135 {0x1002, 0x7835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
136 {0, 0, 0} 136 {0, 0, 0}
137 137
138#define r128_PCI_IDS \ 138#define r128_PCI_IDS \
@@ -209,6 +209,7 @@
209 {0x1039, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 209 {0x1039, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
210 {0x1039, 0x5300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 210 {0x1039, 0x5300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
211 {0x1039, 0x6300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 211 {0x1039, 0x6300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
212 {0x1039, 0x6330, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
212 {0x1039, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 213 {0x1039, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
213 {0, 0, 0} 214 {0, 0, 0}
214 215
@@ -227,6 +228,10 @@
227 {0x1106, 0x3122, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 228 {0x1106, 0x3122, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
228 {0x1106, 0x7205, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 229 {0x1106, 0x7205, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
229 {0x1106, 0x3108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 230 {0x1106, 0x3108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
231 {0x1106, 0x3304, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
232 {0x1106, 0x3157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
233 {0x1106, 0x3344, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
234 {0x1106, 0x7204, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
230 {0, 0, 0} 235 {0, 0, 0}
231 236
232#define i810_PCI_IDS \ 237#define i810_PCI_IDS \
@@ -285,5 +290,9 @@
285 {0x8086, 0x2592, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 290 {0x8086, 0x2592, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
286 {0x8086, 0x2772, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 291 {0x8086, 0x2772, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
287 {0x8086, 0x27a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 292 {0x8086, 0x27a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
293 {0x8086, 0x2972, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
294 {0x8086, 0x2982, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
295 {0x8086, 0x2992, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
296 {0x8086, 0x29a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
288 {0, 0, 0} 297 {0, 0, 0}
289 298
diff --git a/drivers/char/drm/drm_proc.c b/drivers/char/drm/drm_proc.c
index 362a270af0f1..62d5fe15f046 100644
--- a/drivers/char/drm/drm_proc.c
+++ b/drivers/char/drm/drm_proc.c
@@ -510,7 +510,7 @@ static int drm__vma_info(char *buf, char **start, off_t offset, int request,
510 vma->vm_flags & VM_MAYSHARE ? 's' : 'p', 510 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
511 vma->vm_flags & VM_LOCKED ? 'l' : '-', 511 vma->vm_flags & VM_LOCKED ? 'l' : '-',
512 vma->vm_flags & VM_IO ? 'i' : '-', 512 vma->vm_flags & VM_IO ? 'i' : '-',
513 VM_OFFSET(vma)); 513 vma->vm_pgoff << PAGE_SHIFT);
514 514
515#if defined(__i386__) 515#if defined(__i386__)
516 pgprot = pgprot_val(vma->vm_page_prot); 516 pgprot = pgprot_val(vma->vm_page_prot);
diff --git a/drivers/char/drm/drm_sman.c b/drivers/char/drm/drm_sman.c
new file mode 100644
index 000000000000..425c82336ee0
--- /dev/null
+++ b/drivers/char/drm/drm_sman.c
@@ -0,0 +1,352 @@
1/**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck., ND., USA.
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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 *
26 *
27 **************************************************************************/
28/*
29 * Simple memory manager interface that keeps track on allocate regions on a
30 * per "owner" basis. All regions associated with an "owner" can be released
31 * with a simple call. Typically if the "owner" exists. The owner is any
32 * "unsigned long" identifier. Can typically be a pointer to a file private
33 * struct or a context identifier.
34 *
35 * Authors:
36 * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
37 */
38
39#include "drm_sman.h"
40
41typedef struct drm_owner_item {
42 drm_hash_item_t owner_hash;
43 struct list_head sman_list;
44 struct list_head mem_blocks;
45} drm_owner_item_t;
46
47void drm_sman_takedown(drm_sman_t * sman)
48{
49 drm_ht_remove(&sman->user_hash_tab);
50 drm_ht_remove(&sman->owner_hash_tab);
51 if (sman->mm)
52 drm_free(sman->mm, sman->num_managers * sizeof(*sman->mm),
53 DRM_MEM_MM);
54}
55
56EXPORT_SYMBOL(drm_sman_takedown);
57
58int
59drm_sman_init(drm_sman_t * sman, unsigned int num_managers,
60 unsigned int user_order, unsigned int owner_order)
61{
62 int ret = 0;
63
64 sman->mm = (drm_sman_mm_t *) drm_calloc(num_managers, sizeof(*sman->mm),
65 DRM_MEM_MM);
66 if (!sman->mm) {
67 ret = -ENOMEM;
68 goto out;
69 }
70 sman->num_managers = num_managers;
71 INIT_LIST_HEAD(&sman->owner_items);
72 ret = drm_ht_create(&sman->owner_hash_tab, owner_order);
73 if (ret)
74 goto out1;
75 ret = drm_ht_create(&sman->user_hash_tab, user_order);
76 if (!ret)
77 goto out;
78
79 drm_ht_remove(&sman->owner_hash_tab);
80out1:
81 drm_free(sman->mm, num_managers * sizeof(*sman->mm), DRM_MEM_MM);
82out:
83 return ret;
84}
85
86EXPORT_SYMBOL(drm_sman_init);
87
88static void *drm_sman_mm_allocate(void *private, unsigned long size,
89 unsigned alignment)
90{
91 drm_mm_t *mm = (drm_mm_t *) private;
92 drm_mm_node_t *tmp;
93
94 tmp = drm_mm_search_free(mm, size, alignment, 1);
95 if (!tmp) {
96 return NULL;
97 }
98 tmp = drm_mm_get_block(tmp, size, alignment);
99 return tmp;
100}
101
102static void drm_sman_mm_free(void *private, void *ref)
103{
104 drm_mm_t *mm = (drm_mm_t *) private;
105 drm_mm_node_t *node = (drm_mm_node_t *) ref;
106
107 drm_mm_put_block(mm, node);
108}
109
110static void drm_sman_mm_destroy(void *private)
111{
112 drm_mm_t *mm = (drm_mm_t *) private;
113 drm_mm_takedown(mm);
114 drm_free(mm, sizeof(*mm), DRM_MEM_MM);
115}
116
117static unsigned long drm_sman_mm_offset(void *private, void *ref)
118{
119 drm_mm_node_t *node = (drm_mm_node_t *) ref;
120 return node->start;
121}
122
123int
124drm_sman_set_range(drm_sman_t * sman, unsigned int manager,
125 unsigned long start, unsigned long size)
126{
127 drm_sman_mm_t *sman_mm;
128 drm_mm_t *mm;
129 int ret;
130
131 BUG_ON(manager >= sman->num_managers);
132
133 sman_mm = &sman->mm[manager];
134 mm = drm_calloc(1, sizeof(*mm), DRM_MEM_MM);
135 if (!mm) {
136 return -ENOMEM;
137 }
138 sman_mm->private = mm;
139 ret = drm_mm_init(mm, start, size);
140
141 if (ret) {
142 drm_free(mm, sizeof(*mm), DRM_MEM_MM);
143 return ret;
144 }
145
146 sman_mm->allocate = drm_sman_mm_allocate;
147 sman_mm->free = drm_sman_mm_free;
148 sman_mm->destroy = drm_sman_mm_destroy;
149 sman_mm->offset = drm_sman_mm_offset;
150
151 return 0;
152}
153
154EXPORT_SYMBOL(drm_sman_set_range);
155
156int
157drm_sman_set_manager(drm_sman_t * sman, unsigned int manager,
158 drm_sman_mm_t * allocator)
159{
160 BUG_ON(manager >= sman->num_managers);
161 sman->mm[manager] = *allocator;
162
163 return 0;
164}
165
166static drm_owner_item_t *drm_sman_get_owner_item(drm_sman_t * sman,
167 unsigned long owner)
168{
169 int ret;
170 drm_hash_item_t *owner_hash_item;
171 drm_owner_item_t *owner_item;
172
173 ret = drm_ht_find_item(&sman->owner_hash_tab, owner, &owner_hash_item);
174 if (!ret) {
175 return drm_hash_entry(owner_hash_item, drm_owner_item_t,
176 owner_hash);
177 }
178
179 owner_item = drm_calloc(1, sizeof(*owner_item), DRM_MEM_MM);
180 if (!owner_item)
181 goto out;
182
183 INIT_LIST_HEAD(&owner_item->mem_blocks);
184 owner_item->owner_hash.key = owner;
185 if (drm_ht_insert_item(&sman->owner_hash_tab, &owner_item->owner_hash))
186 goto out1;
187
188 list_add_tail(&owner_item->sman_list, &sman->owner_items);
189 return owner_item;
190
191out1:
192 drm_free(owner_item, sizeof(*owner_item), DRM_MEM_MM);
193out:
194 return NULL;
195}
196
197drm_memblock_item_t *drm_sman_alloc(drm_sman_t *sman, unsigned int manager,
198 unsigned long size, unsigned alignment,
199 unsigned long owner)
200{
201 void *tmp;
202 drm_sman_mm_t *sman_mm;
203 drm_owner_item_t *owner_item;
204 drm_memblock_item_t *memblock;
205
206 BUG_ON(manager >= sman->num_managers);
207
208 sman_mm = &sman->mm[manager];
209 tmp = sman_mm->allocate(sman_mm->private, size, alignment);
210
211 if (!tmp) {
212 return NULL;
213 }
214
215 memblock = drm_calloc(1, sizeof(*memblock), DRM_MEM_MM);
216
217 if (!memblock)
218 goto out;
219
220 memblock->mm_info = tmp;
221 memblock->mm = sman_mm;
222 memblock->sman = sman;
223
224 if (drm_ht_just_insert_please
225 (&sman->user_hash_tab, &memblock->user_hash,
226 (unsigned long)memblock, 32, 0, 0))
227 goto out1;
228
229 owner_item = drm_sman_get_owner_item(sman, owner);
230 if (!owner_item)
231 goto out2;
232
233 list_add_tail(&memblock->owner_list, &owner_item->mem_blocks);
234
235 return memblock;
236
237out2:
238 drm_ht_remove_item(&sman->user_hash_tab, &memblock->user_hash);
239out1:
240 drm_free(memblock, sizeof(*memblock), DRM_MEM_MM);
241out:
242 sman_mm->free(sman_mm->private, tmp);
243
244 return NULL;
245}
246
247EXPORT_SYMBOL(drm_sman_alloc);
248
249static void drm_sman_free(drm_memblock_item_t *item)
250{
251 drm_sman_t *sman = item->sman;
252
253 list_del(&item->owner_list);
254 drm_ht_remove_item(&sman->user_hash_tab, &item->user_hash);
255 item->mm->free(item->mm->private, item->mm_info);
256 drm_free(item, sizeof(*item), DRM_MEM_MM);
257}
258
259int drm_sman_free_key(drm_sman_t *sman, unsigned int key)
260{
261 drm_hash_item_t *hash_item;
262 drm_memblock_item_t *memblock_item;
263
264 if (drm_ht_find_item(&sman->user_hash_tab, key, &hash_item))
265 return -EINVAL;
266
267 memblock_item = drm_hash_entry(hash_item, drm_memblock_item_t, user_hash);
268 drm_sman_free(memblock_item);
269 return 0;
270}
271
272EXPORT_SYMBOL(drm_sman_free_key);
273
274static void drm_sman_remove_owner(drm_sman_t *sman,
275 drm_owner_item_t *owner_item)
276{
277 list_del(&owner_item->sman_list);
278 drm_ht_remove_item(&sman->owner_hash_tab, &owner_item->owner_hash);
279 drm_free(owner_item, sizeof(*owner_item), DRM_MEM_MM);
280}
281
282int drm_sman_owner_clean(drm_sman_t *sman, unsigned long owner)
283{
284
285 drm_hash_item_t *hash_item;
286 drm_owner_item_t *owner_item;
287
288 if (drm_ht_find_item(&sman->owner_hash_tab, owner, &hash_item)) {
289 return -1;
290 }
291
292 owner_item = drm_hash_entry(hash_item, drm_owner_item_t, owner_hash);
293 if (owner_item->mem_blocks.next == &owner_item->mem_blocks) {
294 drm_sman_remove_owner(sman, owner_item);
295 return -1;
296 }
297
298 return 0;
299}
300
301EXPORT_SYMBOL(drm_sman_owner_clean);
302
303static void drm_sman_do_owner_cleanup(drm_sman_t *sman,
304 drm_owner_item_t *owner_item)
305{
306 drm_memblock_item_t *entry, *next;
307
308 list_for_each_entry_safe(entry, next, &owner_item->mem_blocks,
309 owner_list) {
310 drm_sman_free(entry);
311 }
312 drm_sman_remove_owner(sman, owner_item);
313}
314
315void drm_sman_owner_cleanup(drm_sman_t *sman, unsigned long owner)
316{
317
318 drm_hash_item_t *hash_item;
319 drm_owner_item_t *owner_item;
320
321 if (drm_ht_find_item(&sman->owner_hash_tab, owner, &hash_item)) {
322
323 return;
324 }
325
326 owner_item = drm_hash_entry(hash_item, drm_owner_item_t, owner_hash);
327 drm_sman_do_owner_cleanup(sman, owner_item);
328}
329
330EXPORT_SYMBOL(drm_sman_owner_cleanup);
331
332void drm_sman_cleanup(drm_sman_t *sman)
333{
334 drm_owner_item_t *entry, *next;
335 unsigned int i;
336 drm_sman_mm_t *sman_mm;
337
338 list_for_each_entry_safe(entry, next, &sman->owner_items, sman_list) {
339 drm_sman_do_owner_cleanup(sman, entry);
340 }
341 if (sman->mm) {
342 for (i = 0; i < sman->num_managers; ++i) {
343 sman_mm = &sman->mm[i];
344 if (sman_mm->private) {
345 sman_mm->destroy(sman_mm->private);
346 sman_mm->private = NULL;
347 }
348 }
349 }
350}
351
352EXPORT_SYMBOL(drm_sman_cleanup);
diff --git a/drivers/char/drm/drm_sman.h b/drivers/char/drm/drm_sman.h
new file mode 100644
index 000000000000..ddc732a1bf27
--- /dev/null
+++ b/drivers/char/drm/drm_sman.h
@@ -0,0 +1,176 @@
1/**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA.
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 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 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 *
27 **************************************************************************/
28/*
29 * Simple memory MANager interface that keeps track on allocate regions on a
30 * per "owner" basis. All regions associated with an "owner" can be released
31 * with a simple call. Typically if the "owner" exists. The owner is any
32 * "unsigned long" identifier. Can typically be a pointer to a file private
33 * struct or a context identifier.
34 *
35 * Authors:
36 * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
37 */
38
39#ifndef DRM_SMAN_H
40#define DRM_SMAN_H
41
42#include "drmP.h"
43#include "drm_hashtab.h"
44
45/*
46 * A class that is an abstration of a simple memory allocator.
47 * The sman implementation provides a default such allocator
48 * using the drm_mm.c implementation. But the user can replace it.
49 * See the SiS implementation, which may use the SiS FB kernel module
50 * for memory management.
51 */
52
53typedef struct drm_sman_mm {
54 /* private info. If allocated, needs to be destroyed by the destroy
55 function */
56 void *private;
57
58 /* Allocate a memory block with given size and alignment.
59 Return an opaque reference to the memory block */
60
61 void *(*allocate) (void *private, unsigned long size,
62 unsigned alignment);
63
64 /* Free a memory block. "ref" is the opaque reference that we got from
65 the "alloc" function */
66
67 void (*free) (void *private, void *ref);
68
69 /* Free all resources associated with this allocator */
70
71 void (*destroy) (void *private);
72
73 /* Return a memory offset from the opaque reference returned from the
74 "alloc" function */
75
76 unsigned long (*offset) (void *private, void *ref);
77} drm_sman_mm_t;
78
79typedef struct drm_memblock_item {
80 struct list_head owner_list;
81 drm_hash_item_t user_hash;
82 void *mm_info;
83 drm_sman_mm_t *mm;
84 struct drm_sman *sman;
85} drm_memblock_item_t;
86
87typedef struct drm_sman {
88 drm_sman_mm_t *mm;
89 int num_managers;
90 drm_open_hash_t owner_hash_tab;
91 drm_open_hash_t user_hash_tab;
92 struct list_head owner_items;
93} drm_sman_t;
94
95/*
96 * Take down a memory manager. This function should only be called after a
97 * successful init and after a call to drm_sman_cleanup.
98 */
99
100extern void drm_sman_takedown(drm_sman_t * sman);
101
102/*
103 * Allocate structures for a manager.
104 * num_managers are the number of memory pools to manage. (VRAM, AGP, ....)
105 * user_order is the log2 of the number of buckets in the user hash table.
106 * set this to approximately log2 of the max number of memory regions
107 * that will be allocated for _all_ pools together.
108 * owner_order is the log2 of the number of buckets in the owner hash table.
109 * set this to approximately log2 of
110 * the number of client file connections that will
111 * be using the manager.
112 *
113 */
114
115extern int drm_sman_init(drm_sman_t * sman, unsigned int num_managers,
116 unsigned int user_order, unsigned int owner_order);
117
118/*
119 * Initialize a drm_mm.c allocator. Should be called only once for each
120 * manager unless a customized allogator is used.
121 */
122
123extern int drm_sman_set_range(drm_sman_t * sman, unsigned int manager,
124 unsigned long start, unsigned long size);
125
126/*
127 * Initialize a customized allocator for one of the managers.
128 * (See the SiS module). The object pointed to by "allocator" is copied,
129 * so it can be destroyed after this call.
130 */
131
132extern int drm_sman_set_manager(drm_sman_t * sman, unsigned int mananger,
133 drm_sman_mm_t * allocator);
134
135/*
136 * Allocate a memory block. Aligment is not implemented yet.
137 */
138
139extern drm_memblock_item_t *drm_sman_alloc(drm_sman_t * sman,
140 unsigned int manager,
141 unsigned long size,
142 unsigned alignment,
143 unsigned long owner);
144/*
145 * Free a memory block identified by its user hash key.
146 */
147
148extern int drm_sman_free_key(drm_sman_t * sman, unsigned int key);
149
150/*
151 * returns 1 iff there are no stale memory blocks associated with this owner.
152 * Typically called to determine if we need to idle the hardware and call
153 * drm_sman_owner_cleanup. If there are no stale memory blocks, it removes all
154 * resources associated with owner.
155 */
156
157extern int drm_sman_owner_clean(drm_sman_t * sman, unsigned long owner);
158
159/*
160 * Frees all stale memory blocks associated with this owner. Note that this
161 * requires that the hardware is finished with all blocks, so the graphics engine
162 * should be idled before this call is made. This function also frees
163 * any resources associated with "owner" and should be called when owner
164 * is not going to be referenced anymore.
165 */
166
167extern void drm_sman_owner_cleanup(drm_sman_t * sman, unsigned long owner);
168
169/*
170 * Frees all stale memory blocks associated with the memory manager.
171 * See idling above.
172 */
173
174extern void drm_sman_cleanup(drm_sman_t * sman);
175
176#endif
diff --git a/drivers/char/drm/drm_stub.c b/drivers/char/drm/drm_stub.c
index 9a842a36bb27..7b1d4e8659ba 100644
--- a/drivers/char/drm/drm_stub.c
+++ b/drivers/char/drm/drm_stub.c
@@ -65,22 +65,22 @@ static int drm_fill_in_dev(drm_device_t * dev, struct pci_dev *pdev,
65 mutex_init(&dev->ctxlist_mutex); 65 mutex_init(&dev->ctxlist_mutex);
66 66
67 dev->pdev = pdev; 67 dev->pdev = pdev;
68 dev->pci_device = pdev->device;
69 dev->pci_vendor = pdev->vendor;
68 70
69#ifdef __alpha__ 71#ifdef __alpha__
70 dev->hose = pdev->sysdata; 72 dev->hose = pdev->sysdata;
71 dev->pci_domain = dev->hose->bus->number;
72#else
73 dev->pci_domain = 0;
74#endif 73#endif
75 dev->pci_bus = pdev->bus->number;
76 dev->pci_slot = PCI_SLOT(pdev->devfn);
77 dev->pci_func = PCI_FUNC(pdev->devfn);
78 dev->irq = pdev->irq; 74 dev->irq = pdev->irq;
79 75
80 dev->maplist = drm_calloc(1, sizeof(*dev->maplist), DRM_MEM_MAPS); 76 dev->maplist = drm_calloc(1, sizeof(*dev->maplist), DRM_MEM_MAPS);
81 if (dev->maplist == NULL) 77 if (dev->maplist == NULL)
82 return -ENOMEM; 78 return -ENOMEM;
83 INIT_LIST_HEAD(&dev->maplist->head); 79 INIT_LIST_HEAD(&dev->maplist->head);
80 if (drm_ht_create(&dev->map_hash, 12)) {
81 drm_free(dev->maplist, sizeof(*dev->maplist), DRM_MEM_MAPS);
82 return -ENOMEM;
83 }
84 84
85 /* the DRM has 6 basic counters */ 85 /* the DRM has 6 basic counters */
86 dev->counters = 6; 86 dev->counters = 6;
diff --git a/drivers/char/drm/drm_vm.c b/drivers/char/drm/drm_vm.c
index ffd0800ed601..b40ae438f531 100644
--- a/drivers/char/drm/drm_vm.c
+++ b/drivers/char/drm/drm_vm.c
@@ -59,7 +59,7 @@ static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma,
59 drm_device_t *dev = priv->head->dev; 59 drm_device_t *dev = priv->head->dev;
60 drm_map_t *map = NULL; 60 drm_map_t *map = NULL;
61 drm_map_list_t *r_list; 61 drm_map_list_t *r_list;
62 struct list_head *list; 62 drm_hash_item_t *hash;
63 63
64 /* 64 /*
65 * Find the right map 65 * Find the right map
@@ -70,14 +70,11 @@ static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma,
70 if (!dev->agp || !dev->agp->cant_use_aperture) 70 if (!dev->agp || !dev->agp->cant_use_aperture)
71 goto vm_nopage_error; 71 goto vm_nopage_error;
72 72
73 list_for_each(list, &dev->maplist->head) { 73 if (drm_ht_find_item(&dev->map_hash, vma->vm_pgoff << PAGE_SHIFT, &hash))
74 r_list = list_entry(list, drm_map_list_t, head); 74 goto vm_nopage_error;
75 map = r_list->map; 75
76 if (!map) 76 r_list = drm_hash_entry(hash, drm_map_list_t, hash);
77 continue; 77 map = r_list->map;
78 if (r_list->user_token == VM_OFFSET(vma))
79 break;
80 }
81 78
82 if (map && map->type == _DRM_AGP) { 79 if (map && map->type == _DRM_AGP) {
83 unsigned long offset = address - vma->vm_start; 80 unsigned long offset = address - vma->vm_start;
@@ -467,7 +464,7 @@ static int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma)
467 dev = priv->head->dev; 464 dev = priv->head->dev;
468 dma = dev->dma; 465 dma = dev->dma;
469 DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n", 466 DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n",
470 vma->vm_start, vma->vm_end, VM_OFFSET(vma)); 467 vma->vm_start, vma->vm_end, vma->vm_pgoff << PAGE_SHIFT);
471 468
472 /* Length must match exact page count */ 469 /* Length must match exact page count */
473 if (!dma || (length >> PAGE_SHIFT) != dma->page_count) { 470 if (!dma || (length >> PAGE_SHIFT) != dma->page_count) {
@@ -521,12 +518,11 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma)
521 drm_file_t *priv = filp->private_data; 518 drm_file_t *priv = filp->private_data;
522 drm_device_t *dev = priv->head->dev; 519 drm_device_t *dev = priv->head->dev;
523 drm_map_t *map = NULL; 520 drm_map_t *map = NULL;
524 drm_map_list_t *r_list;
525 unsigned long offset = 0; 521 unsigned long offset = 0;
526 struct list_head *list; 522 drm_hash_item_t *hash;
527 523
528 DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n", 524 DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n",
529 vma->vm_start, vma->vm_end, VM_OFFSET(vma)); 525 vma->vm_start, vma->vm_end, vma->vm_pgoff << PAGE_SHIFT);
530 526
531 if (!priv->authenticated) 527 if (!priv->authenticated)
532 return -EACCES; 528 return -EACCES;
@@ -535,7 +531,7 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma)
535 * the AGP mapped at physical address 0 531 * the AGP mapped at physical address 0
536 * --BenH. 532 * --BenH.
537 */ 533 */
538 if (!VM_OFFSET(vma) 534 if (!(vma->vm_pgoff << PAGE_SHIFT)
539#if __OS_HAS_AGP 535#if __OS_HAS_AGP
540 && (!dev->agp 536 && (!dev->agp
541 || dev->agp->agp_info.device->vendor != PCI_VENDOR_ID_APPLE) 537 || dev->agp->agp_info.device->vendor != PCI_VENDOR_ID_APPLE)
@@ -543,23 +539,12 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma)
543 ) 539 )
544 return drm_mmap_dma(filp, vma); 540 return drm_mmap_dma(filp, vma);
545 541
546 /* A sequential search of a linked list is 542 if (drm_ht_find_item(&dev->map_hash, vma->vm_pgoff << PAGE_SHIFT, &hash)) {
547 fine here because: 1) there will only be 543 DRM_ERROR("Could not find map\n");
548 about 5-10 entries in the list and, 2) a 544 return -EINVAL;
549 DRI client only has to do this mapping
550 once, so it doesn't have to be optimized
551 for performance, even if the list was a
552 bit longer. */
553 list_for_each(list, &dev->maplist->head) {
554
555 r_list = list_entry(list, drm_map_list_t, head);
556 map = r_list->map;
557 if (!map)
558 continue;
559 if (r_list->user_token == VM_OFFSET(vma))
560 break;
561 } 545 }
562 546
547 map = drm_hash_entry(hash, drm_map_list_t, hash)->map;
563 if (!map || ((map->flags & _DRM_RESTRICTED) && !capable(CAP_SYS_ADMIN))) 548 if (!map || ((map->flags & _DRM_RESTRICTED) && !capable(CAP_SYS_ADMIN)))
564 return -EPERM; 549 return -EPERM;
565 550
@@ -620,7 +605,7 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma)
620 offset = dev->driver->get_reg_ofs(dev); 605 offset = dev->driver->get_reg_ofs(dev);
621#ifdef __sparc__ 606#ifdef __sparc__
622 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 607 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
623 if (io_remap_pfn_range(DRM_RPR_ARG(vma) vma->vm_start, 608 if (io_remap_pfn_range(vma, vma->vm_start,
624 (map->offset + offset) >> PAGE_SHIFT, 609 (map->offset + offset) >> PAGE_SHIFT,
625 vma->vm_end - vma->vm_start, 610 vma->vm_end - vma->vm_start,
626 vma->vm_page_prot)) 611 vma->vm_page_prot))
diff --git a/drivers/char/drm/i810_dma.c b/drivers/char/drm/i810_dma.c
index c658dde3633b..fa2de70f7401 100644
--- a/drivers/char/drm/i810_dma.c
+++ b/drivers/char/drm/i810_dma.c
@@ -106,7 +106,7 @@ static int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
106 unlock_kernel(); 106 unlock_kernel();
107 107
108 if (io_remap_pfn_range(vma, vma->vm_start, 108 if (io_remap_pfn_range(vma, vma->vm_start,
109 VM_OFFSET(vma) >> PAGE_SHIFT, 109 vma->vm_pgoff,
110 vma->vm_end - vma->vm_start, vma->vm_page_prot)) 110 vma->vm_end - vma->vm_start, vma->vm_page_prot))
111 return -EAGAIN; 111 return -EAGAIN;
112 return 0; 112 return 0;
@@ -141,10 +141,10 @@ static int i810_map_buffer(drm_buf_t * buf, struct file *filp)
141 MAP_SHARED, buf->bus_address); 141 MAP_SHARED, buf->bus_address);
142 dev_priv->mmap_buffer = NULL; 142 dev_priv->mmap_buffer = NULL;
143 filp->f_op = old_fops; 143 filp->f_op = old_fops;
144 if ((unsigned long)buf_priv->virtual > -1024UL) { 144 if (IS_ERR(buf_priv->virtual)) {
145 /* Real error */ 145 /* Real error */
146 DRM_ERROR("mmap error\n"); 146 DRM_ERROR("mmap error\n");
147 retcode = (signed int)buf_priv->virtual; 147 retcode = PTR_ERR(buf_priv->virtual);
148 buf_priv->virtual = NULL; 148 buf_priv->virtual = NULL;
149 } 149 }
150 up_write(&current->mm->mmap_sem); 150 up_write(&current->mm->mmap_sem);
@@ -808,7 +808,7 @@ static void i810_dma_dispatch_vertex(drm_device_t * dev,
808 ((GFX_OP_PRIMITIVE | prim | ((used / 4) - 2))); 808 ((GFX_OP_PRIMITIVE | prim | ((used / 4) - 2)));
809 809
810 if (used & 4) { 810 if (used & 4) {
811 *(u32 *) ((u32) buf_priv->kernel_virtual + used) = 0; 811 *(u32 *) ((char *) buf_priv->kernel_virtual + used) = 0;
812 used += 4; 812 used += 4;
813 } 813 }
814 814
@@ -1166,7 +1166,7 @@ static void i810_dma_dispatch_mc(drm_device_t * dev, drm_buf_t * buf, int used,
1166 1166
1167 if (buf_priv->currently_mapped == I810_BUF_MAPPED) { 1167 if (buf_priv->currently_mapped == I810_BUF_MAPPED) {
1168 if (used & 4) { 1168 if (used & 4) {
1169 *(u32 *) ((u32) buf_priv->virtual + used) = 0; 1169 *(u32 *) ((char *) buf_priv->virtual + used) = 0;
1170 used += 4; 1170 used += 4;
1171 } 1171 }
1172 1172
diff --git a/drivers/char/drm/i830_dma.c b/drivers/char/drm/i830_dma.c
index b0f815d8cea8..4f0e5746ab33 100644
--- a/drivers/char/drm/i830_dma.c
+++ b/drivers/char/drm/i830_dma.c
@@ -108,7 +108,7 @@ static int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
108 unlock_kernel(); 108 unlock_kernel();
109 109
110 if (io_remap_pfn_range(vma, vma->vm_start, 110 if (io_remap_pfn_range(vma, vma->vm_start,
111 VM_OFFSET(vma) >> PAGE_SHIFT, 111 vma->vm_pgoff,
112 vma->vm_end - vma->vm_start, vma->vm_page_prot)) 112 vma->vm_end - vma->vm_start, vma->vm_page_prot))
113 return -EAGAIN; 113 return -EAGAIN;
114 return 0; 114 return 0;
@@ -146,7 +146,7 @@ static int i830_map_buffer(drm_buf_t * buf, struct file *filp)
146 if (IS_ERR((void *)virtual)) { /* ugh */ 146 if (IS_ERR((void *)virtual)) { /* ugh */
147 /* Real error */ 147 /* Real error */
148 DRM_ERROR("mmap error\n"); 148 DRM_ERROR("mmap error\n");
149 retcode = virtual; 149 retcode = PTR_ERR((void *)virtual);
150 buf_priv->virtual = NULL; 150 buf_priv->virtual = NULL;
151 } else { 151 } else {
152 buf_priv->virtual = (void __user *)virtual; 152 buf_priv->virtual = (void __user *)virtual;
diff --git a/drivers/char/drm/i915_dma.c b/drivers/char/drm/i915_dma.c
index a94233bdbc0e..fb7913ff5286 100644
--- a/drivers/char/drm/i915_dma.c
+++ b/drivers/char/drm/i915_dma.c
@@ -31,6 +31,11 @@
31#include "i915_drm.h" 31#include "i915_drm.h"
32#include "i915_drv.h" 32#include "i915_drv.h"
33 33
34#define IS_I965G(dev) (dev->pci_device == 0x2972 || \
35 dev->pci_device == 0x2982 || \
36 dev->pci_device == 0x2992 || \
37 dev->pci_device == 0x29A2)
38
34/* Really want an OS-independent resettable timer. Would like to have 39/* Really want an OS-independent resettable timer. Would like to have
35 * this loop run for (eg) 3 sec, but have the timer reset every time 40 * this loop run for (eg) 3 sec, but have the timer reset every time
36 * the head pointer changes, so that EBUSY only happens if the ring 41 * the head pointer changes, so that EBUSY only happens if the ring
@@ -255,7 +260,7 @@ static int i915_dma_init(DRM_IOCTL_ARGS)
255 retcode = i915_dma_resume(dev); 260 retcode = i915_dma_resume(dev);
256 break; 261 break;
257 default: 262 default:
258 retcode = -EINVAL; 263 retcode = DRM_ERR(EINVAL);
259 break; 264 break;
260 } 265 }
261 266
@@ -347,7 +352,7 @@ static int i915_emit_cmds(drm_device_t * dev, int __user * buffer, int dwords)
347 if ((dwords+1) * sizeof(int) >= dev_priv->ring.Size - 8) 352 if ((dwords+1) * sizeof(int) >= dev_priv->ring.Size - 8)
348 return DRM_ERR(EINVAL); 353 return DRM_ERR(EINVAL);
349 354
350 BEGIN_LP_RING(((dwords+1)&~1)); 355 BEGIN_LP_RING((dwords+1)&~1);
351 356
352 for (i = 0; i < dwords;) { 357 for (i = 0; i < dwords;) {
353 int cmd, sz; 358 int cmd, sz;
@@ -386,7 +391,7 @@ static int i915_emit_box(drm_device_t * dev,
386 RING_LOCALS; 391 RING_LOCALS;
387 392
388 if (DRM_COPY_FROM_USER_UNCHECKED(&box, &boxes[i], sizeof(box))) { 393 if (DRM_COPY_FROM_USER_UNCHECKED(&box, &boxes[i], sizeof(box))) {
389 return EFAULT; 394 return DRM_ERR(EFAULT);
390 } 395 }
391 396
392 if (box.y2 <= box.y1 || box.x2 <= box.x1 || box.y2 <= 0 || box.x2 <= 0) { 397 if (box.y2 <= box.y1 || box.x2 <= box.x1 || box.y2 <= 0 || box.x2 <= 0) {
@@ -395,24 +400,40 @@ static int i915_emit_box(drm_device_t * dev,
395 return DRM_ERR(EINVAL); 400 return DRM_ERR(EINVAL);
396 } 401 }
397 402
398 BEGIN_LP_RING(6); 403 if (IS_I965G(dev)) {
399 OUT_RING(GFX_OP_DRAWRECT_INFO); 404 BEGIN_LP_RING(4);
400 OUT_RING(DR1); 405 OUT_RING(GFX_OP_DRAWRECT_INFO_I965);
401 OUT_RING((box.x1 & 0xffff) | (box.y1 << 16)); 406 OUT_RING((box.x1 & 0xffff) | (box.y1 << 16));
402 OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16)); 407 OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16));
403 OUT_RING(DR4); 408 OUT_RING(DR4);
404 OUT_RING(0); 409 ADVANCE_LP_RING();
405 ADVANCE_LP_RING(); 410 } else {
411 BEGIN_LP_RING(6);
412 OUT_RING(GFX_OP_DRAWRECT_INFO);
413 OUT_RING(DR1);
414 OUT_RING((box.x1 & 0xffff) | (box.y1 << 16));
415 OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16));
416 OUT_RING(DR4);
417 OUT_RING(0);
418 ADVANCE_LP_RING();
419 }
406 420
407 return 0; 421 return 0;
408} 422}
409 423
424/* XXX: Emitting the counter should really be moved to part of the IRQ
425 * emit. For now, do it in both places:
426 */
427
410static void i915_emit_breadcrumb(drm_device_t *dev) 428static void i915_emit_breadcrumb(drm_device_t *dev)
411{ 429{
412 drm_i915_private_t *dev_priv = dev->dev_private; 430 drm_i915_private_t *dev_priv = dev->dev_private;
413 RING_LOCALS; 431 RING_LOCALS;
414 432
415 dev_priv->sarea_priv->last_enqueue = dev_priv->counter++; 433 dev_priv->sarea_priv->last_enqueue = ++dev_priv->counter;
434
435 if (dev_priv->counter > 0x7FFFFFFFUL)
436 dev_priv->sarea_priv->last_enqueue = dev_priv->counter = 1;
416 437
417 BEGIN_LP_RING(4); 438 BEGIN_LP_RING(4);
418 OUT_RING(CMD_STORE_DWORD_IDX); 439 OUT_RING(CMD_STORE_DWORD_IDX);
diff --git a/drivers/char/drm/i915_drm.h b/drivers/char/drm/i915_drm.h
index 5aa3e0e3bb45..6af83e613f27 100644
--- a/drivers/char/drm/i915_drm.h
+++ b/drivers/char/drm/i915_drm.h
@@ -98,6 +98,12 @@ typedef struct _drm_i915_sarea {
98 int rotated_size; 98 int rotated_size;
99 int rotated_pitch; 99 int rotated_pitch;
100 int virtualX, virtualY; 100 int virtualX, virtualY;
101
102 unsigned int front_tiled;
103 unsigned int back_tiled;
104 unsigned int depth_tiled;
105 unsigned int rotated_tiled;
106 unsigned int rotated2_tiled;
101} drm_i915_sarea_t; 107} drm_i915_sarea_t;
102 108
103/* Flags for perf_boxes 109/* Flags for perf_boxes
diff --git a/drivers/char/drm/i915_drv.h b/drivers/char/drm/i915_drv.h
index 2d565031c002..fdc2bf192714 100644
--- a/drivers/char/drm/i915_drv.h
+++ b/drivers/char/drm/i915_drv.h
@@ -146,9 +146,9 @@ extern void i915_mem_release(drm_device_t * dev,
146#define BEGIN_LP_RING(n) do { \ 146#define BEGIN_LP_RING(n) do { \
147 if (I915_VERBOSE) \ 147 if (I915_VERBOSE) \
148 DRM_DEBUG("BEGIN_LP_RING(%d) in %s\n", \ 148 DRM_DEBUG("BEGIN_LP_RING(%d) in %s\n", \
149 n, __FUNCTION__); \ 149 (n), __FUNCTION__); \
150 if (dev_priv->ring.space < n*4) \ 150 if (dev_priv->ring.space < (n)*4) \
151 i915_wait_ring(dev, n*4, __FUNCTION__); \ 151 i915_wait_ring(dev, (n)*4, __FUNCTION__); \
152 outcount = 0; \ 152 outcount = 0; \
153 outring = dev_priv->ring.tail; \ 153 outring = dev_priv->ring.tail; \
154 ringmask = dev_priv->ring.tail_mask; \ 154 ringmask = dev_priv->ring.tail_mask; \
@@ -157,7 +157,7 @@ extern void i915_mem_release(drm_device_t * dev,
157 157
158#define OUT_RING(n) do { \ 158#define OUT_RING(n) do { \
159 if (I915_VERBOSE) DRM_DEBUG(" OUT_RING %x\n", (int)(n)); \ 159 if (I915_VERBOSE) DRM_DEBUG(" OUT_RING %x\n", (int)(n)); \
160 *(volatile unsigned int *)(virt + outring) = n; \ 160 *(volatile unsigned int *)(virt + outring) = (n); \
161 outcount++; \ 161 outcount++; \
162 outring += 4; \ 162 outring += 4; \
163 outring &= ringmask; \ 163 outring &= ringmask; \
@@ -254,6 +254,8 @@ extern int i915_wait_ring(drm_device_t * dev, int n, const char *caller);
254#define GFX_OP_DESTBUFFER_VARS ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0) 254#define GFX_OP_DESTBUFFER_VARS ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
255#define GFX_OP_DRAWRECT_INFO ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3)) 255#define GFX_OP_DRAWRECT_INFO ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
256 256
257#define GFX_OP_DRAWRECT_INFO_I965 ((0x7900<<16)|0x2)
258
257#define MI_BATCH_BUFFER ((0x30<<23)|1) 259#define MI_BATCH_BUFFER ((0x30<<23)|1)
258#define MI_BATCH_BUFFER_START (0x31<<23) 260#define MI_BATCH_BUFFER_START (0x31<<23)
259#define MI_BATCH_BUFFER_END (0xA<<23) 261#define MI_BATCH_BUFFER_END (0xA<<23)
diff --git a/drivers/char/drm/i915_irq.c b/drivers/char/drm/i915_irq.c
index cd96cfa430db..0d4a162aa385 100644
--- a/drivers/char/drm/i915_irq.c
+++ b/drivers/char/drm/i915_irq.c
@@ -71,21 +71,27 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
71static int i915_emit_irq(drm_device_t * dev) 71static int i915_emit_irq(drm_device_t * dev)
72{ 72{
73 drm_i915_private_t *dev_priv = dev->dev_private; 73 drm_i915_private_t *dev_priv = dev->dev_private;
74 u32 ret;
75 RING_LOCALS; 74 RING_LOCALS;
76 75
77 i915_kernel_lost_context(dev); 76 i915_kernel_lost_context(dev);
78 77
79 DRM_DEBUG("%s\n", __FUNCTION__); 78 DRM_DEBUG("%s\n", __FUNCTION__);
80 79
81 ret = dev_priv->counter; 80 dev_priv->sarea_priv->last_enqueue = ++dev_priv->counter;
82 81
83 BEGIN_LP_RING(2); 82 if (dev_priv->counter > 0x7FFFFFFFUL)
83 dev_priv->sarea_priv->last_enqueue = dev_priv->counter = 1;
84
85 BEGIN_LP_RING(6);
86 OUT_RING(CMD_STORE_DWORD_IDX);
87 OUT_RING(20);
88 OUT_RING(dev_priv->counter);
89 OUT_RING(0);
84 OUT_RING(0); 90 OUT_RING(0);
85 OUT_RING(GFX_OP_USER_INTERRUPT); 91 OUT_RING(GFX_OP_USER_INTERRUPT);
86 ADVANCE_LP_RING(); 92 ADVANCE_LP_RING();
87 93
88 return ret; 94 return dev_priv->counter;
89} 95}
90 96
91static int i915_wait_irq(drm_device_t * dev, int irq_nr) 97static int i915_wait_irq(drm_device_t * dev, int irq_nr)
diff --git a/drivers/char/drm/radeon_cp.c b/drivers/char/drm/radeon_cp.c
index 5ad43ba7b5aa..5ed965688293 100644
--- a/drivers/char/drm/radeon_cp.c
+++ b/drivers/char/drm/radeon_cp.c
@@ -864,13 +864,13 @@ static int radeon_do_pixcache_flush(drm_radeon_private_t * dev_priv)
864 864
865 dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE; 865 dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
866 866
867 tmp = RADEON_READ(RADEON_RB2D_DSTCACHE_CTLSTAT); 867 tmp = RADEON_READ(RADEON_RB3D_DSTCACHE_CTLSTAT);
868 tmp |= RADEON_RB2D_DC_FLUSH_ALL; 868 tmp |= RADEON_RB3D_DC_FLUSH_ALL;
869 RADEON_WRITE(RADEON_RB2D_DSTCACHE_CTLSTAT, tmp); 869 RADEON_WRITE(RADEON_RB3D_DSTCACHE_CTLSTAT, tmp);
870 870
871 for (i = 0; i < dev_priv->usec_timeout; i++) { 871 for (i = 0; i < dev_priv->usec_timeout; i++) {
872 if (!(RADEON_READ(RADEON_RB2D_DSTCACHE_CTLSTAT) 872 if (!(RADEON_READ(RADEON_RB3D_DSTCACHE_CTLSTAT)
873 & RADEON_RB2D_DC_BUSY)) { 873 & RADEON_RB3D_DC_BUSY)) {
874 return 0; 874 return 0;
875 } 875 }
876 DRM_UDELAY(1); 876 DRM_UDELAY(1);
@@ -1130,7 +1130,7 @@ static void radeon_cp_init_ring_buffer(drm_device_t * dev,
1130 | (dev_priv->fb_location >> 16)); 1130 | (dev_priv->fb_location >> 16));
1131 1131
1132#if __OS_HAS_AGP 1132#if __OS_HAS_AGP
1133 if (dev_priv->flags & CHIP_IS_AGP) { 1133 if (dev_priv->flags & RADEON_IS_AGP) {
1134 RADEON_WRITE(RADEON_AGP_BASE, (unsigned int)dev->agp->base); 1134 RADEON_WRITE(RADEON_AGP_BASE, (unsigned int)dev->agp->base);
1135 RADEON_WRITE(RADEON_MC_AGP_LOCATION, 1135 RADEON_WRITE(RADEON_MC_AGP_LOCATION,
1136 (((dev_priv->gart_vm_start - 1 + 1136 (((dev_priv->gart_vm_start - 1 +
@@ -1158,7 +1158,7 @@ static void radeon_cp_init_ring_buffer(drm_device_t * dev,
1158 dev_priv->ring.tail = cur_read_ptr; 1158 dev_priv->ring.tail = cur_read_ptr;
1159 1159
1160#if __OS_HAS_AGP 1160#if __OS_HAS_AGP
1161 if (dev_priv->flags & CHIP_IS_AGP) { 1161 if (dev_priv->flags & RADEON_IS_AGP) {
1162 RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR, 1162 RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR,
1163 dev_priv->ring_rptr->offset 1163 dev_priv->ring_rptr->offset
1164 - dev->agp->base + dev_priv->gart_vm_start); 1164 - dev->agp->base + dev_priv->gart_vm_start);
@@ -1258,6 +1258,13 @@ static void radeon_test_writeback(drm_radeon_private_t * dev_priv)
1258 dev_priv->writeback_works = 0; 1258 dev_priv->writeback_works = 0;
1259 DRM_INFO("writeback forced off\n"); 1259 DRM_INFO("writeback forced off\n");
1260 } 1260 }
1261
1262 if (!dev_priv->writeback_works) {
1263 /* Disable writeback to avoid unnecessary bus master transfer */
1264 RADEON_WRITE(RADEON_CP_RB_CNTL, RADEON_READ(RADEON_CP_RB_CNTL) |
1265 RADEON_RB_NO_UPDATE);
1266 RADEON_WRITE(RADEON_SCRATCH_UMSK, 0);
1267 }
1261} 1268}
1262 1269
1263/* Enable or disable PCI-E GART on the chip */ 1270/* Enable or disable PCI-E GART on the chip */
@@ -1295,7 +1302,7 @@ static void radeon_set_pcigart(drm_radeon_private_t * dev_priv, int on)
1295{ 1302{
1296 u32 tmp; 1303 u32 tmp;
1297 1304
1298 if (dev_priv->flags & CHIP_IS_PCIE) { 1305 if (dev_priv->flags & RADEON_IS_PCIE) {
1299 radeon_set_pciegart(dev_priv, on); 1306 radeon_set_pciegart(dev_priv, on);
1300 return; 1307 return;
1301 } 1308 }
@@ -1333,20 +1340,22 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1333 DRM_DEBUG("\n"); 1340 DRM_DEBUG("\n");
1334 1341
1335 /* if we require new memory map but we don't have it fail */ 1342 /* if we require new memory map but we don't have it fail */
1336 if ((dev_priv->flags & CHIP_NEW_MEMMAP) && !dev_priv->new_memmap) 1343 if ((dev_priv->flags & RADEON_NEW_MEMMAP) && !dev_priv->new_memmap) {
1337 { 1344 DRM_ERROR("Cannot initialise DRM on this card\nThis card requires a new X.org DDX for 3D\n");
1338 DRM_ERROR("Cannot initialise DRM on this card\nThis card requires a new X.org DDX\n");
1339 radeon_do_cleanup_cp(dev); 1345 radeon_do_cleanup_cp(dev);
1340 return DRM_ERR(EINVAL); 1346 return DRM_ERR(EINVAL);
1341 } 1347 }
1342 1348
1343 if (init->is_pci && (dev_priv->flags & CHIP_IS_AGP)) 1349 if (init->is_pci && (dev_priv->flags & RADEON_IS_AGP)) {
1344 {
1345 DRM_DEBUG("Forcing AGP card to PCI mode\n"); 1350 DRM_DEBUG("Forcing AGP card to PCI mode\n");
1346 dev_priv->flags &= ~CHIP_IS_AGP; 1351 dev_priv->flags &= ~RADEON_IS_AGP;
1352 } else if (!(dev_priv->flags & (RADEON_IS_AGP | RADEON_IS_PCI | RADEON_IS_PCIE))
1353 && !init->is_pci) {
1354 DRM_DEBUG("Restoring AGP flag\n");
1355 dev_priv->flags |= RADEON_IS_AGP;
1347 } 1356 }
1348 1357
1349 if ((!(dev_priv->flags & CHIP_IS_AGP)) && !dev->sg) { 1358 if ((!(dev_priv->flags & RADEON_IS_AGP)) && !dev->sg) {
1350 DRM_ERROR("PCI GART memory not allocated!\n"); 1359 DRM_ERROR("PCI GART memory not allocated!\n");
1351 radeon_do_cleanup_cp(dev); 1360 radeon_do_cleanup_cp(dev);
1352 return DRM_ERR(EINVAL); 1361 return DRM_ERR(EINVAL);
@@ -1489,7 +1498,7 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1489 init->sarea_priv_offset); 1498 init->sarea_priv_offset);
1490 1499
1491#if __OS_HAS_AGP 1500#if __OS_HAS_AGP
1492 if (dev_priv->flags & CHIP_IS_AGP) { 1501 if (dev_priv->flags & RADEON_IS_AGP) {
1493 drm_core_ioremap(dev_priv->cp_ring, dev); 1502 drm_core_ioremap(dev_priv->cp_ring, dev);
1494 drm_core_ioremap(dev_priv->ring_rptr, dev); 1503 drm_core_ioremap(dev_priv->ring_rptr, dev);
1495 drm_core_ioremap(dev->agp_buffer_map, dev); 1504 drm_core_ioremap(dev->agp_buffer_map, dev);
@@ -1548,7 +1557,7 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1548 * align it down. 1557 * align it down.
1549 */ 1558 */
1550#if __OS_HAS_AGP 1559#if __OS_HAS_AGP
1551 if (dev_priv->flags & CHIP_IS_AGP) { 1560 if (dev_priv->flags & RADEON_IS_AGP) {
1552 base = dev->agp->base; 1561 base = dev->agp->base;
1553 /* Check if valid */ 1562 /* Check if valid */
1554 if ((base + dev_priv->gart_size) > dev_priv->fb_location && 1563 if ((base + dev_priv->gart_size) > dev_priv->fb_location &&
@@ -1578,7 +1587,7 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1578 } 1587 }
1579 1588
1580#if __OS_HAS_AGP 1589#if __OS_HAS_AGP
1581 if (dev_priv->flags & CHIP_IS_AGP) 1590 if (dev_priv->flags & RADEON_IS_AGP)
1582 dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset 1591 dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset
1583 - dev->agp->base 1592 - dev->agp->base
1584 + dev_priv->gart_vm_start); 1593 + dev_priv->gart_vm_start);
@@ -1604,7 +1613,7 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1604 dev_priv->ring.high_mark = RADEON_RING_HIGH_MARK; 1613 dev_priv->ring.high_mark = RADEON_RING_HIGH_MARK;
1605 1614
1606#if __OS_HAS_AGP 1615#if __OS_HAS_AGP
1607 if (dev_priv->flags & CHIP_IS_AGP) { 1616 if (dev_priv->flags & RADEON_IS_AGP) {
1608 /* Turn off PCI GART */ 1617 /* Turn off PCI GART */
1609 radeon_set_pcigart(dev_priv, 0); 1618 radeon_set_pcigart(dev_priv, 0);
1610 } else 1619 } else
@@ -1624,7 +1633,7 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1624 dev_priv->gart_info.mapping.handle; 1633 dev_priv->gart_info.mapping.handle;
1625 1634
1626 dev_priv->gart_info.is_pcie = 1635 dev_priv->gart_info.is_pcie =
1627 !!(dev_priv->flags & CHIP_IS_PCIE); 1636 !!(dev_priv->flags & RADEON_IS_PCIE);
1628 dev_priv->gart_info.gart_table_location = 1637 dev_priv->gart_info.gart_table_location =
1629 DRM_ATI_GART_FB; 1638 DRM_ATI_GART_FB;
1630 1639
@@ -1636,7 +1645,7 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1636 DRM_ATI_GART_MAIN; 1645 DRM_ATI_GART_MAIN;
1637 dev_priv->gart_info.addr = NULL; 1646 dev_priv->gart_info.addr = NULL;
1638 dev_priv->gart_info.bus_addr = 0; 1647 dev_priv->gart_info.bus_addr = 0;
1639 if (dev_priv->flags & CHIP_IS_PCIE) { 1648 if (dev_priv->flags & RADEON_IS_PCIE) {
1640 DRM_ERROR 1649 DRM_ERROR
1641 ("Cannot use PCI Express without GART in FB memory\n"); 1650 ("Cannot use PCI Express without GART in FB memory\n");
1642 radeon_do_cleanup_cp(dev); 1651 radeon_do_cleanup_cp(dev);
@@ -1678,7 +1687,7 @@ static int radeon_do_cleanup_cp(drm_device_t * dev)
1678 drm_irq_uninstall(dev); 1687 drm_irq_uninstall(dev);
1679 1688
1680#if __OS_HAS_AGP 1689#if __OS_HAS_AGP
1681 if (dev_priv->flags & CHIP_IS_AGP) { 1690 if (dev_priv->flags & RADEON_IS_AGP) {
1682 if (dev_priv->cp_ring != NULL) { 1691 if (dev_priv->cp_ring != NULL) {
1683 drm_core_ioremapfree(dev_priv->cp_ring, dev); 1692 drm_core_ioremapfree(dev_priv->cp_ring, dev);
1684 dev_priv->cp_ring = NULL; 1693 dev_priv->cp_ring = NULL;
@@ -1733,7 +1742,7 @@ static int radeon_do_resume_cp(drm_device_t * dev)
1733 DRM_DEBUG("Starting radeon_do_resume_cp()\n"); 1742 DRM_DEBUG("Starting radeon_do_resume_cp()\n");
1734 1743
1735#if __OS_HAS_AGP 1744#if __OS_HAS_AGP
1736 if (dev_priv->flags & CHIP_IS_AGP) { 1745 if (dev_priv->flags & RADEON_IS_AGP) {
1737 /* Turn off PCI GART */ 1746 /* Turn off PCI GART */
1738 radeon_set_pcigart(dev_priv, 0); 1747 radeon_set_pcigart(dev_priv, 0);
1739 } else 1748 } else
@@ -2177,13 +2186,15 @@ int radeon_driver_load(struct drm_device *dev, unsigned long flags)
2177 dev->dev_private = (void *)dev_priv; 2186 dev->dev_private = (void *)dev_priv;
2178 dev_priv->flags = flags; 2187 dev_priv->flags = flags;
2179 2188
2180 switch (flags & CHIP_FAMILY_MASK) { 2189 switch (flags & RADEON_FAMILY_MASK) {
2181 case CHIP_R100: 2190 case CHIP_R100:
2182 case CHIP_RV200: 2191 case CHIP_RV200:
2183 case CHIP_R200: 2192 case CHIP_R200:
2184 case CHIP_R300: 2193 case CHIP_R300:
2194 case CHIP_R350:
2185 case CHIP_R420: 2195 case CHIP_R420:
2186 dev_priv->flags |= CHIP_HAS_HIERZ; 2196 case CHIP_RV410:
2197 dev_priv->flags |= RADEON_HAS_HIERZ;
2187 break; 2198 break;
2188 default: 2199 default:
2189 /* all other chips have no hierarchical z buffer */ 2200 /* all other chips have no hierarchical z buffer */
@@ -2191,13 +2202,14 @@ int radeon_driver_load(struct drm_device *dev, unsigned long flags)
2191 } 2202 }
2192 2203
2193 if (drm_device_is_agp(dev)) 2204 if (drm_device_is_agp(dev))
2194 dev_priv->flags |= CHIP_IS_AGP; 2205 dev_priv->flags |= RADEON_IS_AGP;
2195 2206 else if (drm_device_is_pcie(dev))
2196 if (drm_device_is_pcie(dev)) 2207 dev_priv->flags |= RADEON_IS_PCIE;
2197 dev_priv->flags |= CHIP_IS_PCIE; 2208 else
2209 dev_priv->flags |= RADEON_IS_PCI;
2198 2210
2199 DRM_DEBUG("%s card detected\n", 2211 DRM_DEBUG("%s card detected\n",
2200 ((dev_priv->flags & CHIP_IS_AGP) ? "AGP" : (((dev_priv->flags & CHIP_IS_PCIE) ? "PCIE" : "PCI")))); 2212 ((dev_priv->flags & RADEON_IS_AGP) ? "AGP" : (((dev_priv->flags & RADEON_IS_PCIE) ? "PCIE" : "PCI"))));
2201 return ret; 2213 return ret;
2202} 2214}
2203 2215
diff --git a/drivers/char/drm/radeon_drv.c b/drivers/char/drm/radeon_drv.c
index eb985c2a31e9..2eb652ec6745 100644
--- a/drivers/char/drm/radeon_drv.c
+++ b/drivers/char/drm/radeon_drv.c
@@ -44,7 +44,7 @@ module_param_named(no_wb, radeon_no_wb, int, 0444);
44static int dri_library_name(struct drm_device *dev, char *buf) 44static int dri_library_name(struct drm_device *dev, char *buf)
45{ 45{
46 drm_radeon_private_t *dev_priv = dev->dev_private; 46 drm_radeon_private_t *dev_priv = dev->dev_private;
47 int family = dev_priv->flags & CHIP_FAMILY_MASK; 47 int family = dev_priv->flags & RADEON_FAMILY_MASK;
48 48
49 return snprintf(buf, PAGE_SIZE, "%s\n", 49 return snprintf(buf, PAGE_SIZE, "%s\n",
50 (family < CHIP_R200) ? "radeon" : 50 (family < CHIP_R200) ? "radeon" :
diff --git a/drivers/char/drm/radeon_drv.h b/drivers/char/drm/radeon_drv.h
index e5a256f5429c..f45cd7f147a5 100644
--- a/drivers/char/drm/radeon_drv.h
+++ b/drivers/char/drm/radeon_drv.h
@@ -133,15 +133,16 @@ enum radeon_cp_microcode_version {
133 * Chip flags 133 * Chip flags
134 */ 134 */
135enum radeon_chip_flags { 135enum radeon_chip_flags {
136 CHIP_FAMILY_MASK = 0x0000ffffUL, 136 RADEON_FAMILY_MASK = 0x0000ffffUL,
137 CHIP_FLAGS_MASK = 0xffff0000UL, 137 RADEON_FLAGS_MASK = 0xffff0000UL,
138 CHIP_IS_MOBILITY = 0x00010000UL, 138 RADEON_IS_MOBILITY = 0x00010000UL,
139 CHIP_IS_IGP = 0x00020000UL, 139 RADEON_IS_IGP = 0x00020000UL,
140 CHIP_SINGLE_CRTC = 0x00040000UL, 140 RADEON_SINGLE_CRTC = 0x00040000UL,
141 CHIP_IS_AGP = 0x00080000UL, 141 RADEON_IS_AGP = 0x00080000UL,
142 CHIP_HAS_HIERZ = 0x00100000UL, 142 RADEON_HAS_HIERZ = 0x00100000UL,
143 CHIP_IS_PCIE = 0x00200000UL, 143 RADEON_IS_PCIE = 0x00200000UL,
144 CHIP_NEW_MEMMAP = 0x00400000UL, 144 RADEON_NEW_MEMMAP = 0x00400000UL,
145 RADEON_IS_PCI = 0x00800000UL,
145}; 146};
146 147
147#define GET_RING_HEAD(dev_priv) (dev_priv->writeback_works ? \ 148#define GET_RING_HEAD(dev_priv) (dev_priv->writeback_works ? \
@@ -424,6 +425,8 @@ extern int r300_do_cp_cmdbuf(drm_device_t * dev, DRMFILE filp,
424#define RADEON_RB3D_COLOROFFSET 0x1c40 425#define RADEON_RB3D_COLOROFFSET 0x1c40
425#define RADEON_RB3D_COLORPITCH 0x1c48 426#define RADEON_RB3D_COLORPITCH 0x1c48
426 427
428#define RADEON_SRC_X_Y 0x1590
429
427#define RADEON_DP_GUI_MASTER_CNTL 0x146c 430#define RADEON_DP_GUI_MASTER_CNTL 0x146c
428# define RADEON_GMC_SRC_PITCH_OFFSET_CNTL (1 << 0) 431# define RADEON_GMC_SRC_PITCH_OFFSET_CNTL (1 << 0)
429# define RADEON_GMC_DST_PITCH_OFFSET_CNTL (1 << 1) 432# define RADEON_GMC_DST_PITCH_OFFSET_CNTL (1 << 1)
@@ -441,6 +444,7 @@ extern int r300_do_cp_cmdbuf(drm_device_t * dev, DRMFILE filp,
441# define RADEON_ROP3_S 0x00cc0000 444# define RADEON_ROP3_S 0x00cc0000
442# define RADEON_ROP3_P 0x00f00000 445# define RADEON_ROP3_P 0x00f00000
443#define RADEON_DP_WRITE_MASK 0x16cc 446#define RADEON_DP_WRITE_MASK 0x16cc
447#define RADEON_SRC_PITCH_OFFSET 0x1428
444#define RADEON_DST_PITCH_OFFSET 0x142c 448#define RADEON_DST_PITCH_OFFSET 0x142c
445#define RADEON_DST_PITCH_OFFSET_C 0x1c80 449#define RADEON_DST_PITCH_OFFSET_C 0x1c80
446# define RADEON_DST_TILE_LINEAR (0 << 30) 450# define RADEON_DST_TILE_LINEAR (0 << 30)
@@ -545,6 +549,11 @@ extern int r300_do_cp_cmdbuf(drm_device_t * dev, DRMFILE filp,
545# define RADEON_RB3D_ZC_FREE (1 << 2) 549# define RADEON_RB3D_ZC_FREE (1 << 2)
546# define RADEON_RB3D_ZC_FLUSH_ALL 0x5 550# define RADEON_RB3D_ZC_FLUSH_ALL 0x5
547# define RADEON_RB3D_ZC_BUSY (1 << 31) 551# define RADEON_RB3D_ZC_BUSY (1 << 31)
552#define RADEON_RB3D_DSTCACHE_CTLSTAT 0x325c
553# define RADEON_RB3D_DC_FLUSH (3 << 0)
554# define RADEON_RB3D_DC_FREE (3 << 2)
555# define RADEON_RB3D_DC_FLUSH_ALL 0xf
556# define RADEON_RB3D_DC_BUSY (1 << 31)
548#define RADEON_RB3D_ZSTENCILCNTL 0x1c2c 557#define RADEON_RB3D_ZSTENCILCNTL 0x1c2c
549# define RADEON_Z_TEST_MASK (7 << 4) 558# define RADEON_Z_TEST_MASK (7 << 4)
550# define RADEON_Z_TEST_ALWAYS (7 << 4) 559# define RADEON_Z_TEST_ALWAYS (7 << 4)
@@ -681,6 +690,7 @@ extern int r300_do_cp_cmdbuf(drm_device_t * dev, DRMFILE filp,
681#define RADEON_CP_RB_BASE 0x0700 690#define RADEON_CP_RB_BASE 0x0700
682#define RADEON_CP_RB_CNTL 0x0704 691#define RADEON_CP_RB_CNTL 0x0704
683# define RADEON_BUF_SWAP_32BIT (2 << 16) 692# define RADEON_BUF_SWAP_32BIT (2 << 16)
693# define RADEON_RB_NO_UPDATE (1 << 27)
684#define RADEON_CP_RB_RPTR_ADDR 0x070c 694#define RADEON_CP_RB_RPTR_ADDR 0x070c
685#define RADEON_CP_RB_RPTR 0x0710 695#define RADEON_CP_RB_RPTR 0x0710
686#define RADEON_CP_RB_WPTR 0x0714 696#define RADEON_CP_RB_WPTR 0x0714
@@ -986,13 +996,13 @@ do { \
986} while (0) 996} while (0)
987 997
988#define RADEON_FLUSH_CACHE() do { \ 998#define RADEON_FLUSH_CACHE() do { \
989 OUT_RING( CP_PACKET0( RADEON_RB2D_DSTCACHE_CTLSTAT, 0 ) ); \ 999 OUT_RING( CP_PACKET0( RADEON_RB3D_DSTCACHE_CTLSTAT, 0 ) ); \
990 OUT_RING( RADEON_RB2D_DC_FLUSH ); \ 1000 OUT_RING( RADEON_RB3D_DC_FLUSH ); \
991} while (0) 1001} while (0)
992 1002
993#define RADEON_PURGE_CACHE() do { \ 1003#define RADEON_PURGE_CACHE() do { \
994 OUT_RING( CP_PACKET0( RADEON_RB2D_DSTCACHE_CTLSTAT, 0 ) ); \ 1004 OUT_RING( CP_PACKET0( RADEON_RB3D_DSTCACHE_CTLSTAT, 0 ) ); \
995 OUT_RING( RADEON_RB2D_DC_FLUSH_ALL ); \ 1005 OUT_RING( RADEON_RB3D_DC_FLUSH_ALL ); \
996} while (0) 1006} while (0)
997 1007
998#define RADEON_FLUSH_ZCACHE() do { \ 1008#define RADEON_FLUSH_ZCACHE() do { \
diff --git a/drivers/char/drm/radeon_state.c b/drivers/char/drm/radeon_state.c
index 39a7f685e3fd..feac5f005d47 100644
--- a/drivers/char/drm/radeon_state.c
+++ b/drivers/char/drm/radeon_state.c
@@ -42,7 +42,11 @@ static __inline__ int radeon_check_and_fixup_offset(drm_radeon_private_t *
42 drm_file_t * filp_priv, 42 drm_file_t * filp_priv,
43 u32 *offset) 43 u32 *offset)
44{ 44{
45 u32 off = *offset; 45 u64 off = *offset;
46 u32 fb_start = dev_priv->fb_location;
47 u32 fb_end = fb_start + dev_priv->fb_size - 1;
48 u32 gart_start = dev_priv->gart_vm_start;
49 u32 gart_end = gart_start + dev_priv->gart_size - 1;
46 struct drm_radeon_driver_file_fields *radeon_priv; 50 struct drm_radeon_driver_file_fields *radeon_priv;
47 51
48 /* Hrm ... the story of the offset ... So this function converts 52 /* Hrm ... the story of the offset ... So this function converts
@@ -62,10 +66,8 @@ static __inline__ int radeon_check_and_fixup_offset(drm_radeon_private_t *
62 /* First, the best case, the offset already lands in either the 66 /* First, the best case, the offset already lands in either the
63 * framebuffer or the GART mapped space 67 * framebuffer or the GART mapped space
64 */ 68 */
65 if ((off >= dev_priv->fb_location && 69 if ((off >= fb_start && off <= fb_end) ||
66 off < (dev_priv->fb_location + dev_priv->fb_size)) || 70 (off >= gart_start && off <= gart_end))
67 (off >= dev_priv->gart_vm_start &&
68 off < (dev_priv->gart_vm_start + dev_priv->gart_size)))
69 return 0; 71 return 0;
70 72
71 /* Ok, that didn't happen... now check if we have a zero based 73 /* Ok, that didn't happen... now check if we have a zero based
@@ -78,16 +80,13 @@ static __inline__ int radeon_check_and_fixup_offset(drm_radeon_private_t *
78 } 80 }
79 81
80 /* Finally, assume we aimed at a GART offset if beyond the fb */ 82 /* Finally, assume we aimed at a GART offset if beyond the fb */
81 if (off > (dev_priv->fb_location + dev_priv->fb_size)) 83 if (off > fb_end)
82 off = off - (dev_priv->fb_location + dev_priv->fb_size) + 84 off = off - fb_end - 1 + gart_start;
83 dev_priv->gart_vm_start;
84 85
85 /* Now recheck and fail if out of bounds */ 86 /* Now recheck and fail if out of bounds */
86 if ((off >= dev_priv->fb_location && 87 if ((off >= fb_start && off <= fb_end) ||
87 off < (dev_priv->fb_location + dev_priv->fb_size)) || 88 (off >= gart_start && off <= gart_end)) {
88 (off >= dev_priv->gart_vm_start && 89 DRM_DEBUG("offset fixed up to 0x%x\n", (unsigned int)off);
89 off < (dev_priv->gart_vm_start + dev_priv->gart_size))) {
90 DRM_DEBUG("offset fixed up to 0x%x\n", off);
91 *offset = off; 90 *offset = off;
92 return 0; 91 return 0;
93 } 92 }
@@ -869,7 +868,7 @@ static void radeon_cp_dispatch_clear(drm_device_t * dev,
869 */ 868 */
870 dev_priv->sarea_priv->ctx_owner = 0; 869 dev_priv->sarea_priv->ctx_owner = 0;
871 870
872 if ((dev_priv->flags & CHIP_HAS_HIERZ) 871 if ((dev_priv->flags & RADEON_HAS_HIERZ)
873 && (flags & RADEON_USE_HIERZ)) { 872 && (flags & RADEON_USE_HIERZ)) {
874 /* FIXME : reverse engineer that for Rx00 cards */ 873 /* FIXME : reverse engineer that for Rx00 cards */
875 /* FIXME : the mask supposedly contains low-res z values. So can't set 874 /* FIXME : the mask supposedly contains low-res z values. So can't set
@@ -914,7 +913,7 @@ static void radeon_cp_dispatch_clear(drm_device_t * dev,
914 for (i = 0; i < nbox; i++) { 913 for (i = 0; i < nbox; i++) {
915 int tileoffset, nrtilesx, nrtilesy, j; 914 int tileoffset, nrtilesx, nrtilesy, j;
916 /* it looks like r200 needs rv-style clears, at least if hierz is not enabled? */ 915 /* it looks like r200 needs rv-style clears, at least if hierz is not enabled? */
917 if ((dev_priv->flags & CHIP_HAS_HIERZ) 916 if ((dev_priv->flags & RADEON_HAS_HIERZ)
918 && !(dev_priv->microcode_version == UCODE_R200)) { 917 && !(dev_priv->microcode_version == UCODE_R200)) {
919 /* FIXME : figure this out for r200 (when hierz is enabled). Or 918 /* FIXME : figure this out for r200 (when hierz is enabled). Or
920 maybe r200 actually doesn't need to put the low-res z value into 919 maybe r200 actually doesn't need to put the low-res z value into
@@ -998,7 +997,7 @@ static void radeon_cp_dispatch_clear(drm_device_t * dev,
998 } 997 }
999 998
1000 /* TODO don't always clear all hi-level z tiles */ 999 /* TODO don't always clear all hi-level z tiles */
1001 if ((dev_priv->flags & CHIP_HAS_HIERZ) 1000 if ((dev_priv->flags & RADEON_HAS_HIERZ)
1002 && (dev_priv->microcode_version == UCODE_R200) 1001 && (dev_priv->microcode_version == UCODE_R200)
1003 && (flags & RADEON_USE_HIERZ)) 1002 && (flags & RADEON_USE_HIERZ))
1004 /* r100 and cards without hierarchical z-buffer have no high-level z-buffer */ 1003 /* r100 and cards without hierarchical z-buffer have no high-level z-buffer */
@@ -1270,9 +1269,9 @@ static void radeon_cp_dispatch_swap(drm_device_t * dev)
1270 1269
1271 DRM_DEBUG("dispatch swap %d,%d-%d,%d\n", x, y, w, h); 1270 DRM_DEBUG("dispatch swap %d,%d-%d,%d\n", x, y, w, h);
1272 1271
1273 BEGIN_RING(7); 1272 BEGIN_RING(9);
1274 1273
1275 OUT_RING(CP_PACKET3(RADEON_CNTL_BITBLT_MULTI, 5)); 1274 OUT_RING(CP_PACKET0(RADEON_DP_GUI_MASTER_CNTL, 0));
1276 OUT_RING(RADEON_GMC_SRC_PITCH_OFFSET_CNTL | 1275 OUT_RING(RADEON_GMC_SRC_PITCH_OFFSET_CNTL |
1277 RADEON_GMC_DST_PITCH_OFFSET_CNTL | 1276 RADEON_GMC_DST_PITCH_OFFSET_CNTL |
1278 RADEON_GMC_BRUSH_NONE | 1277 RADEON_GMC_BRUSH_NONE |
@@ -1284,6 +1283,7 @@ static void radeon_cp_dispatch_swap(drm_device_t * dev)
1284 1283
1285 /* Make this work even if front & back are flipped: 1284 /* Make this work even if front & back are flipped:
1286 */ 1285 */
1286 OUT_RING(CP_PACKET0(RADEON_SRC_PITCH_OFFSET, 1));
1287 if (dev_priv->current_page == 0) { 1287 if (dev_priv->current_page == 0) {
1288 OUT_RING(dev_priv->back_pitch_offset); 1288 OUT_RING(dev_priv->back_pitch_offset);
1289 OUT_RING(dev_priv->front_pitch_offset); 1289 OUT_RING(dev_priv->front_pitch_offset);
@@ -1292,6 +1292,7 @@ static void radeon_cp_dispatch_swap(drm_device_t * dev)
1292 OUT_RING(dev_priv->back_pitch_offset); 1292 OUT_RING(dev_priv->back_pitch_offset);
1293 } 1293 }
1294 1294
1295 OUT_RING(CP_PACKET0(RADEON_SRC_X_Y, 2));
1295 OUT_RING((x << 16) | y); 1296 OUT_RING((x << 16) | y);
1296 OUT_RING((x << 16) | y); 1297 OUT_RING((x << 16) | y);
1297 OUT_RING((w << 16) | h); 1298 OUT_RING((w << 16) | h);
@@ -2987,16 +2988,21 @@ static int radeon_cp_getparam(DRM_IOCTL_ARGS)
2987 case RADEON_PARAM_GART_TEX_HANDLE: 2988 case RADEON_PARAM_GART_TEX_HANDLE:
2988 value = dev_priv->gart_textures_offset; 2989 value = dev_priv->gart_textures_offset;
2989 break; 2990 break;
2990 2991 case RADEON_PARAM_SCRATCH_OFFSET:
2992 if (!dev_priv->writeback_works)
2993 return DRM_ERR(EINVAL);
2994 value = RADEON_SCRATCH_REG_OFFSET;
2995 break;
2991 case RADEON_PARAM_CARD_TYPE: 2996 case RADEON_PARAM_CARD_TYPE:
2992 if (dev_priv->flags & CHIP_IS_PCIE) 2997 if (dev_priv->flags & RADEON_IS_PCIE)
2993 value = RADEON_CARD_PCIE; 2998 value = RADEON_CARD_PCIE;
2994 else if (dev_priv->flags & CHIP_IS_AGP) 2999 else if (dev_priv->flags & RADEON_IS_AGP)
2995 value = RADEON_CARD_AGP; 3000 value = RADEON_CARD_AGP;
2996 else 3001 else
2997 value = RADEON_CARD_PCI; 3002 value = RADEON_CARD_PCI;
2998 break; 3003 break;
2999 default: 3004 default:
3005 DRM_DEBUG("Invalid parameter %d\n", param.param);
3000 return DRM_ERR(EINVAL); 3006 return DRM_ERR(EINVAL);
3001 } 3007 }
3002 3008
diff --git a/drivers/char/drm/sis_drv.c b/drivers/char/drm/sis_drv.c
index 5e9dc86f2956..3d5b3218b6ff 100644
--- a/drivers/char/drm/sis_drv.c
+++ b/drivers/char/drm/sis_drv.c
@@ -35,11 +35,44 @@ static struct pci_device_id pciidlist[] = {
35 sisdrv_PCI_IDS 35 sisdrv_PCI_IDS
36}; 36};
37 37
38static int sis_driver_load(drm_device_t *dev, unsigned long chipset)
39{
40 drm_sis_private_t *dev_priv;
41 int ret;
42
43 dev_priv = drm_calloc(1, sizeof(drm_sis_private_t), DRM_MEM_DRIVER);
44 if (dev_priv == NULL)
45 return DRM_ERR(ENOMEM);
46
47 dev->dev_private = (void *)dev_priv;
48 dev_priv->chipset = chipset;
49 ret = drm_sman_init(&dev_priv->sman, 2, 12, 8);
50 if (ret) {
51 drm_free(dev_priv, sizeof(dev_priv), DRM_MEM_DRIVER);
52 }
53
54 return ret;
55}
56
57static int sis_driver_unload(drm_device_t *dev)
58{
59 drm_sis_private_t *dev_priv = dev->dev_private;
60
61 drm_sman_takedown(&dev_priv->sman);
62 drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER);
63
64 return 0;
65}
66
38static struct drm_driver driver = { 67static struct drm_driver driver = {
39 .driver_features = DRIVER_USE_AGP | DRIVER_USE_MTRR, 68 .driver_features = DRIVER_USE_AGP | DRIVER_USE_MTRR,
40 .context_ctor = sis_init_context, 69 .load = sis_driver_load,
41 .context_dtor = sis_final_context, 70 .unload = sis_driver_unload,
42 .reclaim_buffers = drm_core_reclaim_buffers, 71 .context_dtor = NULL,
72 .dma_quiescent = sis_idle,
73 .reclaim_buffers = NULL,
74 .reclaim_buffers_locked = sis_reclaim_buffers_locked,
75 .lastclose = sis_lastclose,
43 .get_map_ofs = drm_core_get_map_ofs, 76 .get_map_ofs = drm_core_get_map_ofs,
44 .get_reg_ofs = drm_core_get_reg_ofs, 77 .get_reg_ofs = drm_core_get_reg_ofs,
45 .ioctls = sis_ioctls, 78 .ioctls = sis_ioctls,
diff --git a/drivers/char/drm/sis_drv.h b/drivers/char/drm/sis_drv.h
index e218e5269503..2b8d6f6ed7c0 100644
--- a/drivers/char/drm/sis_drv.h
+++ b/drivers/char/drm/sis_drv.h
@@ -31,23 +31,39 @@
31/* General customization: 31/* General customization:
32 */ 32 */
33 33
34#define DRIVER_AUTHOR "SIS" 34#define DRIVER_AUTHOR "SIS, Tungsten Graphics"
35#define DRIVER_NAME "sis" 35#define DRIVER_NAME "sis"
36#define DRIVER_DESC "SIS 300/630/540" 36#define DRIVER_DESC "SIS 300/630/540"
37#define DRIVER_DATE "20030826" 37#define DRIVER_DATE "20060704"
38#define DRIVER_MAJOR 1 38#define DRIVER_MAJOR 1
39#define DRIVER_MINOR 1 39#define DRIVER_MINOR 2
40#define DRIVER_PATCHLEVEL 0 40#define DRIVER_PATCHLEVEL 1
41 41
42#include "sis_ds.h" 42enum sis_family {
43 SIS_OTHER = 0,
44 SIS_CHIP_315 = 1,
45};
46
47#include "drm_sman.h"
48
49#define SIS_BASE (dev_priv->mmio)
50#define SIS_READ(reg) DRM_READ32(SIS_BASE, reg);
51#define SIS_WRITE(reg, val) DRM_WRITE32(SIS_BASE, reg, val);
43 52
44typedef struct drm_sis_private { 53typedef struct drm_sis_private {
45 memHeap_t *AGPHeap; 54 drm_local_map_t *mmio;
46 memHeap_t *FBHeap; 55 unsigned int idle_fault;
56 drm_sman_t sman;
57 unsigned int chipset;
58 int vram_initialized;
59 int agp_initialized;
60 unsigned long vram_offset;
61 unsigned long agp_offset;
47} drm_sis_private_t; 62} drm_sis_private_t;
48 63
49extern int sis_init_context(drm_device_t * dev, int context); 64extern int sis_idle(drm_device_t *dev);
50extern int sis_final_context(drm_device_t * dev, int context); 65extern void sis_reclaim_buffers_locked(drm_device_t *dev, struct file *filp);
66extern void sis_lastclose(drm_device_t *dev);
51 67
52extern drm_ioctl_desc_t sis_ioctls[]; 68extern drm_ioctl_desc_t sis_ioctls[];
53extern int sis_max_ioctl; 69extern int sis_max_ioctl;
diff --git a/drivers/char/drm/sis_ds.c b/drivers/char/drm/sis_ds.c
deleted file mode 100644
index 2e485d482943..000000000000
--- a/drivers/char/drm/sis_ds.c
+++ /dev/null
@@ -1,299 +0,0 @@
1/* sis_ds.c -- Private header for Direct Rendering Manager -*- linux-c -*-
2 * Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw
3 *
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, sublicense,
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 next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * 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 NONINFRINGEMENT. IN NO EVENT SHALL
21 * PRECISION INSIGHT 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 * Authors:
27 * Sung-Ching Lin <sclin@sis.com.tw>
28 *
29 */
30
31#include "drmP.h"
32#include "drm.h"
33#include "sis_ds.h"
34
35/* Set Data Structure, not check repeated value
36 * temporarily used
37 */
38
39set_t *setInit(void)
40{
41 int i;
42 set_t *set;
43
44 set = (set_t *) drm_alloc(sizeof(set_t), DRM_MEM_DRIVER);
45 if (set != NULL) {
46 for (i = 0; i < SET_SIZE; i++) {
47 set->list[i].free_next = i + 1;
48 set->list[i].alloc_next = -1;
49 }
50 set->list[SET_SIZE - 1].free_next = -1;
51 set->free = 0;
52 set->alloc = -1;
53 set->trace = -1;
54 }
55 return set;
56}
57
58int setAdd(set_t * set, ITEM_TYPE item)
59{
60 int free = set->free;
61
62 if (free != -1) {
63 set->list[free].val = item;
64 set->free = set->list[free].free_next;
65 } else {
66 return 0;
67 }
68
69 set->list[free].alloc_next = set->alloc;
70 set->alloc = free;
71 set->list[free].free_next = -1;
72
73 return 1;
74}
75
76int setDel(set_t * set, ITEM_TYPE item)
77{
78 int alloc = set->alloc;
79 int prev = -1;
80
81 while (alloc != -1) {
82 if (set->list[alloc].val == item) {
83 if (prev != -1)
84 set->list[prev].alloc_next =
85 set->list[alloc].alloc_next;
86 else
87 set->alloc = set->list[alloc].alloc_next;
88 break;
89 }
90 prev = alloc;
91 alloc = set->list[alloc].alloc_next;
92 }
93
94 if (alloc == -1)
95 return 0;
96
97 set->list[alloc].free_next = set->free;
98 set->free = alloc;
99 set->list[alloc].alloc_next = -1;
100
101 return 1;
102}
103
104/* setFirst -> setAdd -> setNext is wrong */
105
106int setFirst(set_t * set, ITEM_TYPE * item)
107{
108 if (set->alloc == -1)
109 return 0;
110
111 *item = set->list[set->alloc].val;
112 set->trace = set->list[set->alloc].alloc_next;
113
114 return 1;
115}
116
117int setNext(set_t * set, ITEM_TYPE * item)
118{
119 if (set->trace == -1)
120 return 0;
121
122 *item = set->list[set->trace].val;
123 set->trace = set->list[set->trace].alloc_next;
124
125 return 1;
126}
127
128int setDestroy(set_t * set)
129{
130 drm_free(set, sizeof(set_t), DRM_MEM_DRIVER);
131
132 return 1;
133}
134
135/*
136 * GLX Hardware Device Driver common code
137 * Copyright (C) 1999 Wittawat Yamwong
138 *
139 * Permission is hereby granted, free of charge, to any person obtaining a
140 * copy of this software and associated documentation files (the "Software"),
141 * to deal in the Software without restriction, including without limitation
142 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
143 * and/or sell copies of the Software, and to permit persons to whom the
144 * Software is furnished to do so, subject to the following conditions:
145 *
146 * The above copyright notice and this permission notice shall be included
147 * in all copies or substantial portions of the Software.
148 *
149 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
150 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
151 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
152 * WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
153 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
154 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
155 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
156 *
157 */
158
159#define ISFREE(bptr) ((bptr)->free)
160
161memHeap_t *mmInit(int ofs, int size)
162{
163 PMemBlock blocks;
164
165 if (size <= 0)
166 return NULL;
167
168 blocks = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock), DRM_MEM_DRIVER);
169 if (blocks != NULL) {
170 blocks->ofs = ofs;
171 blocks->size = size;
172 blocks->free = 1;
173 return (memHeap_t *) blocks;
174 } else
175 return NULL;
176}
177
178/* Checks if a pointer 'b' is part of the heap 'heap' */
179int mmBlockInHeap(memHeap_t * heap, PMemBlock b)
180{
181 TMemBlock *p;
182
183 if (heap == NULL || b == NULL)
184 return 0;
185
186 p = heap;
187 while (p != NULL && p != b) {
188 p = p->next;
189 }
190 if (p == b)
191 return 1;
192 else
193 return 0;
194}
195
196static TMemBlock *SliceBlock(TMemBlock * p,
197 int startofs, int size,
198 int reserved, int alignment)
199{
200 TMemBlock *newblock;
201
202 /* break left */
203 if (startofs > p->ofs) {
204 newblock = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock),
205 DRM_MEM_DRIVER);
206 newblock->ofs = startofs;
207 newblock->size = p->size - (startofs - p->ofs);
208 newblock->free = 1;
209 newblock->next = p->next;
210 p->size -= newblock->size;
211 p->next = newblock;
212 p = newblock;
213 }
214
215 /* break right */
216 if (size < p->size) {
217 newblock = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock),
218 DRM_MEM_DRIVER);
219 newblock->ofs = startofs + size;
220 newblock->size = p->size - size;
221 newblock->free = 1;
222 newblock->next = p->next;
223 p->size = size;
224 p->next = newblock;
225 }
226
227 /* p = middle block */
228 p->align = alignment;
229 p->free = 0;
230 p->reserved = reserved;
231 return p;
232}
233
234PMemBlock mmAllocMem(memHeap_t * heap, int size, int align2, int startSearch)
235{
236 int mask, startofs, endofs;
237 TMemBlock *p;
238
239 if (heap == NULL || align2 < 0 || size <= 0)
240 return NULL;
241
242 mask = (1 << align2) - 1;
243 startofs = 0;
244 p = (TMemBlock *) heap;
245 while (p != NULL) {
246 if (ISFREE(p)) {
247 startofs = (p->ofs + mask) & ~mask;
248 if (startofs < startSearch) {
249 startofs = startSearch;
250 }
251 endofs = startofs + size;
252 if (endofs <= (p->ofs + p->size))
253 break;
254 }
255 p = p->next;
256 }
257 if (p == NULL)
258 return NULL;
259 p = SliceBlock(p, startofs, size, 0, mask + 1);
260 p->heap = heap;
261 return p;
262}
263
264static __inline__ int Join2Blocks(TMemBlock * p)
265{
266 if (p->free && p->next && p->next->free) {
267 TMemBlock *q = p->next;
268 p->size += q->size;
269 p->next = q->next;
270 drm_free(q, sizeof(TMemBlock), DRM_MEM_DRIVER);
271 return 1;
272 }
273 return 0;
274}
275
276int mmFreeMem(PMemBlock b)
277{
278 TMemBlock *p, *prev;
279
280 if (b == NULL)
281 return 0;
282 if (b->heap == NULL)
283 return -1;
284
285 p = b->heap;
286 prev = NULL;
287 while (p != NULL && p != b) {
288 prev = p;
289 p = p->next;
290 }
291 if (p == NULL || p->free || p->reserved)
292 return -1;
293
294 p->free = 1;
295 Join2Blocks(p);
296 if (prev)
297 Join2Blocks(prev);
298 return 0;
299}
diff --git a/drivers/char/drm/sis_ds.h b/drivers/char/drm/sis_ds.h
deleted file mode 100644
index 94f2b4728b63..000000000000
--- a/drivers/char/drm/sis_ds.h
+++ /dev/null
@@ -1,146 +0,0 @@
1/* sis_ds.h -- Private header for Direct Rendering Manager -*- linux-c -*-
2 * Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw
3 */
4/*
5 * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
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 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 *
27 * Authors:
28 * Sung-Ching Lin <sclin@sis.com.tw>
29 *
30 */
31
32#ifndef __SIS_DS_H__
33#define __SIS_DS_H__
34
35/* Set Data Structure */
36
37#define SET_SIZE 5000
38
39typedef unsigned long ITEM_TYPE;
40
41typedef struct {
42 ITEM_TYPE val;
43 int alloc_next, free_next;
44} list_item_t;
45
46typedef struct {
47 int alloc;
48 int free;
49 int trace;
50 list_item_t list[SET_SIZE];
51} set_t;
52
53set_t *setInit(void);
54int setAdd(set_t * set, ITEM_TYPE item);
55int setDel(set_t * set, ITEM_TYPE item);
56int setFirst(set_t * set, ITEM_TYPE * item);
57int setNext(set_t * set, ITEM_TYPE * item);
58int setDestroy(set_t * set);
59
60/*
61 * GLX Hardware Device Driver common code
62 * Copyright (C) 1999 Wittawat Yamwong
63 *
64 * Permission is hereby granted, free of charge, to any person obtaining a
65 * copy of this software and associated documentation files (the "Software"),
66 * to deal in the Software without restriction, including without limitation
67 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
68 * and/or sell copies of the Software, and to permit persons to whom the
69 * Software is furnished to do so, subject to the following conditions:
70 *
71 * The above copyright notice and this permission notice shall be included
72 * in all copies or substantial portions of the Software.
73 *
74 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
75 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
76 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
77 * WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
78 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
79 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
80 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
81 *
82 */
83
84struct mem_block_t {
85 struct mem_block_t *next;
86 struct mem_block_t *heap;
87 int ofs, size;
88 int align;
89 unsigned int free:1;
90 unsigned int reserved:1;
91};
92typedef struct mem_block_t TMemBlock;
93typedef struct mem_block_t *PMemBlock;
94
95/* a heap is just the first block in a chain */
96typedef struct mem_block_t memHeap_t;
97
98static __inline__ int mmBlockSize(PMemBlock b)
99{
100 return b->size;
101}
102
103static __inline__ int mmOffset(PMemBlock b)
104{
105 return b->ofs;
106}
107
108static __inline__ void mmMarkReserved(PMemBlock b)
109{
110 b->reserved = 1;
111}
112
113/*
114 * input: total size in bytes
115 * return: a heap pointer if OK, NULL if error
116 */
117memHeap_t *mmInit(int ofs, int size);
118
119/*
120 * Allocate 'size' bytes with 2^align2 bytes alignment,
121 * restrict the search to free memory after 'startSearch'
122 * depth and back buffers should be in different 4mb banks
123 * to get better page hits if possible
124 * input: size = size of block
125 * align2 = 2^align2 bytes alignment
126 * startSearch = linear offset from start of heap to begin search
127 * return: pointer to the allocated block, 0 if error
128 */
129PMemBlock mmAllocMem(memHeap_t * heap, int size, int align2, int startSearch);
130
131/*
132 * Returns 1 if the block 'b' is part of the heap 'heap'
133 */
134int mmBlockInHeap(PMemBlock heap, PMemBlock b);
135
136/*
137 * Free block starts at offset
138 * input: pointer to a block
139 * return: 0 if OK, -1 if error
140 */
141int mmFreeMem(PMemBlock b);
142
143/* For debuging purpose. */
144void mmDumpMemInfo(memHeap_t * mmInit);
145
146#endif /* __SIS_DS_H__ */
diff --git a/drivers/char/drm/sis_mm.c b/drivers/char/drm/sis_mm.c
index 5e9936bc307f..d26f5dbb7853 100644
--- a/drivers/char/drm/sis_mm.c
+++ b/drivers/char/drm/sis_mm.c
@@ -1,414 +1,348 @@
1/* sis_mm.c -- Private header for Direct Rendering Manager -*- linux-c -*- 1/**************************************************************************
2 * Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw
3 * 2 *
4 * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan. 3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA.
5 * All rights reserved. 4 * All Rights Reserved.
6 * 5 *
7 * Permission is hereby granted, free of charge, to any person obtaining a 6 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"), 7 * copy of this software and associated documentation files (the
9 * to deal in the Software without restriction, including without limitation 8 * "Software"), to deal in the Software without restriction, including
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * without limitation the rights to use, copy, modify, merge, publish,
11 * and/or sell copies of the Software, and to permit persons to whom the 10 * distribute, sub license, and/or sell copies of the Software, and to
12 * Software is furnished to do so, subject to the following conditions: 11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 * 13 *
14 * The above copyright notice and this permission notice (including the next 14 * The above copyright notice and this permission notice (including the
15 * paragraph) shall be included in all copies or substantial portions of the 15 * next paragraph) shall be included in all copies or substantial portions
16 * Software. 16 * of the Software.
17 * 17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 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, 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * DEALINGS IN THE SOFTWARE. 24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * 25 *
26 * Authors:
27 * Sung-Ching Lin <sclin@sis.com.tw>
28 * 26 *
27 **************************************************************************/
28
29/*
30 * Authors:
31 * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
29 */ 32 */
30 33
31#include "drmP.h" 34#include "drmP.h"
32#include "sis_drm.h" 35#include "sis_drm.h"
33#include "sis_drv.h" 36#include "sis_drv.h"
34#include "sis_ds.h" 37
35#if defined(__linux__) && defined(CONFIG_FB_SIS)
36#include <video/sisfb.h> 38#include <video/sisfb.h>
37#endif
38 39
39#define MAX_CONTEXT 100
40#define VIDEO_TYPE 0 40#define VIDEO_TYPE 0
41#define AGP_TYPE 1 41#define AGP_TYPE 1
42 42
43typedef struct {
44 int used;
45 int context;
46 set_t *sets[2]; /* 0 for video, 1 for AGP */
47} sis_context_t;
48 43
49static sis_context_t global_ppriv[MAX_CONTEXT]; 44#if defined(CONFIG_FB_SIS)
45/* fb management via fb device */
50 46
51static int add_alloc_set(int context, int type, unsigned int val) 47#define SIS_MM_ALIGN_SHIFT 0
52{ 48#define SIS_MM_ALIGN_MASK 0
53 int i, retval = 0;
54 49
55 for (i = 0; i < MAX_CONTEXT; i++) { 50static void *sis_sman_mm_allocate(void *private, unsigned long size,
56 if (global_ppriv[i].used && global_ppriv[i].context == context) { 51 unsigned alignment)
57 retval = setAdd(global_ppriv[i].sets[type], val);
58 break;
59 }
60 }
61 return retval;
62}
63
64static int del_alloc_set(int context, int type, unsigned int val)
65{ 52{
66 int i, retval = 0; 53 struct sis_memreq req;
67 54
68 for (i = 0; i < MAX_CONTEXT; i++) { 55 req.size = size;
69 if (global_ppriv[i].used && global_ppriv[i].context == context) { 56 sis_malloc(&req);
70 retval = setDel(global_ppriv[i].sets[type], val); 57 if (req.size == 0)
71 break; 58 return NULL;
72 } 59 else
73 } 60 return (void *)~req.offset;
74 return retval;
75} 61}
76 62
77/* fb management via fb device */ 63static void sis_sman_mm_free(void *private, void *ref)
78#if defined(__linux__) && defined(CONFIG_FB_SIS)
79
80static int sis_fb_init(DRM_IOCTL_ARGS)
81{ 64{
82 return 0; 65 sis_free(~((unsigned long)ref));
83} 66}
84 67
85static int sis_fb_alloc(DRM_IOCTL_ARGS) 68static void sis_sman_mm_destroy(void *private)
86{ 69{
87 drm_sis_mem_t fb; 70 ;
88 struct sis_memreq req;
89 drm_sis_mem_t __user *argp = (drm_sis_mem_t __user *)data;
90 int retval = 0;
91
92 DRM_COPY_FROM_USER_IOCTL(fb, argp, sizeof(fb));
93
94 req.size = fb.size;
95 sis_malloc(&req);
96 if (req.offset) {
97 /* TODO */
98 fb.offset = req.offset;
99 fb.free = req.offset;
100 if (!add_alloc_set(fb.context, VIDEO_TYPE, fb.free)) {
101 DRM_DEBUG("adding to allocation set fails\n");
102 sis_free(req.offset);
103 retval = DRM_ERR(EINVAL);
104 }
105 } else {
106 fb.offset = 0;
107 fb.size = 0;
108 fb.free = 0;
109 }
110
111 DRM_COPY_TO_USER_IOCTL(argp, fb, sizeof(fb));
112
113 DRM_DEBUG("alloc fb, size = %d, offset = %d\n", fb.size, req.offset);
114
115 return retval;
116} 71}
117 72
118static int sis_fb_free(DRM_IOCTL_ARGS) 73static unsigned long sis_sman_mm_offset(void *private, void *ref)
119{ 74{
120 drm_sis_mem_t fb; 75 return ~((unsigned long)ref);
121 int retval = 0; 76}
122
123 DRM_COPY_FROM_USER_IOCTL(fb, (drm_sis_mem_t __user *) data, sizeof(fb));
124
125 if (!fb.free)
126 return DRM_ERR(EINVAL);
127 77
128 if (!del_alloc_set(fb.context, VIDEO_TYPE, fb.free)) 78#else /* CONFIG_FB_SIS */
129 retval = DRM_ERR(EINVAL);
130 sis_free(fb.free);
131 79
132 DRM_DEBUG("free fb, offset = 0x%lx\n", fb.free); 80#define SIS_MM_ALIGN_SHIFT 4
81#define SIS_MM_ALIGN_MASK ( (1 << SIS_MM_ALIGN_SHIFT) - 1)
133 82
134 return retval; 83#endif /* CONFIG_FB_SIS */
135}
136 84
137#else
138
139/* Called by the X Server to initialize the FB heap. Allocations will fail
140 * unless this is called. Offset is the beginning of the heap from the
141 * framebuffer offset (MaxXFBMem in XFree86).
142 *
143 * Memory layout according to Thomas Winischofer:
144 * |------------------|DDDDDDDDDDDDDDDDDDDDDDDDDDDDD|HHHH|CCCCCCCCCCC|
145 *
146 * X driver/sisfb HW- Command-
147 * framebuffer memory DRI heap Cursor queue
148 */
149static int sis_fb_init(DRM_IOCTL_ARGS) 85static int sis_fb_init(DRM_IOCTL_ARGS)
150{ 86{
151 DRM_DEVICE; 87 DRM_DEVICE;
152 drm_sis_private_t *dev_priv = dev->dev_private; 88 drm_sis_private_t *dev_priv = dev->dev_private;
153 drm_sis_fb_t fb; 89 drm_sis_fb_t fb;
90 int ret;
154 91
155 DRM_COPY_FROM_USER_IOCTL(fb, (drm_sis_fb_t __user *) data, sizeof(fb)); 92 DRM_COPY_FROM_USER_IOCTL(fb, (drm_sis_fb_t __user *) data, sizeof(fb));
156 93
157 if (dev_priv == NULL) { 94 mutex_lock(&dev->struct_mutex);
158 dev->dev_private = drm_calloc(1, sizeof(drm_sis_private_t), 95#if defined(CONFIG_FB_SIS)
159 DRM_MEM_DRIVER); 96 {
160 dev_priv = dev->dev_private; 97 drm_sman_mm_t sman_mm;
161 if (dev_priv == NULL) 98 sman_mm.private = (void *)0xFFFFFFFF;
162 return ENOMEM; 99 sman_mm.allocate = sis_sman_mm_allocate;
100 sman_mm.free = sis_sman_mm_free;
101 sman_mm.destroy = sis_sman_mm_destroy;
102 sman_mm.offset = sis_sman_mm_offset;
103 ret =
104 drm_sman_set_manager(&dev_priv->sman, VIDEO_TYPE, &sman_mm);
163 } 105 }
106#else
107 ret = drm_sman_set_range(&dev_priv->sman, VIDEO_TYPE, 0,
108 fb.size >> SIS_MM_ALIGN_SHIFT);
109#endif
164 110
165 if (dev_priv->FBHeap != NULL) 111 if (ret) {
166 return DRM_ERR(EINVAL); 112 DRM_ERROR("VRAM memory manager initialisation error\n");
113 mutex_unlock(&dev->struct_mutex);
114 return ret;
115 }
167 116
168 dev_priv->FBHeap = mmInit(fb.offset, fb.size); 117 dev_priv->vram_initialized = 1;
118 dev_priv->vram_offset = fb.offset;
169 119
120 mutex_unlock(&dev->struct_mutex);
170 DRM_DEBUG("offset = %u, size = %u", fb.offset, fb.size); 121 DRM_DEBUG("offset = %u, size = %u", fb.offset, fb.size);
171 122
172 return 0; 123 return 0;
173} 124}
174 125
175static int sis_fb_alloc(DRM_IOCTL_ARGS) 126static int sis_drm_alloc(drm_device_t * dev, drm_file_t * priv,
127 unsigned long data, int pool)
176{ 128{
177 DRM_DEVICE;
178 drm_sis_private_t *dev_priv = dev->dev_private; 129 drm_sis_private_t *dev_priv = dev->dev_private;
179 drm_sis_mem_t __user *argp = (drm_sis_mem_t __user *)data; 130 drm_sis_mem_t __user *argp = (drm_sis_mem_t __user *) data;
180 drm_sis_mem_t fb; 131 drm_sis_mem_t mem;
181 PMemBlock block;
182 int retval = 0; 132 int retval = 0;
133 drm_memblock_item_t *item;
134
135 DRM_COPY_FROM_USER_IOCTL(mem, argp, sizeof(mem));
183 136
184 if (dev_priv == NULL || dev_priv->FBHeap == NULL) 137 mutex_lock(&dev->struct_mutex);
138
139 if (0 == ((pool == 0) ? dev_priv->vram_initialized :
140 dev_priv->agp_initialized)) {
141 DRM_ERROR
142 ("Attempt to allocate from uninitialized memory manager.\n");
185 return DRM_ERR(EINVAL); 143 return DRM_ERR(EINVAL);
144 }
186 145
187 DRM_COPY_FROM_USER_IOCTL(fb, argp, sizeof(fb)); 146 mem.size = (mem.size + SIS_MM_ALIGN_MASK) >> SIS_MM_ALIGN_SHIFT;
188 147 item = drm_sman_alloc(&dev_priv->sman, pool, mem.size, 0,
189 block = mmAllocMem(dev_priv->FBHeap, fb.size, 0, 0); 148 (unsigned long)priv);
190 if (block) { 149
191 /* TODO */ 150 mutex_unlock(&dev->struct_mutex);
192 fb.offset = block->ofs; 151 if (item) {
193 fb.free = (unsigned long)block; 152 mem.offset = ((pool == 0) ?
194 if (!add_alloc_set(fb.context, VIDEO_TYPE, fb.free)) { 153 dev_priv->vram_offset : dev_priv->agp_offset) +
195 DRM_DEBUG("adding to allocation set fails\n"); 154 (item->mm->
196 mmFreeMem((PMemBlock) fb.free); 155 offset(item->mm, item->mm_info) << SIS_MM_ALIGN_SHIFT);
197 retval = DRM_ERR(EINVAL); 156 mem.free = item->user_hash.key;
198 } 157 mem.size = mem.size << SIS_MM_ALIGN_SHIFT;
199 } else { 158 } else {
200 fb.offset = 0; 159 mem.offset = 0;
201 fb.size = 0; 160 mem.size = 0;
202 fb.free = 0; 161 mem.free = 0;
162 retval = DRM_ERR(ENOMEM);
203 } 163 }
204 164
205 DRM_COPY_TO_USER_IOCTL(argp, fb, sizeof(fb)); 165 DRM_COPY_TO_USER_IOCTL(argp, mem, sizeof(mem));
206 166
207 DRM_DEBUG("alloc fb, size = %d, offset = %d\n", fb.size, fb.offset); 167 DRM_DEBUG("alloc %d, size = %d, offset = %d\n", pool, mem.size,
168 mem.offset);
208 169
209 return retval; 170 return retval;
210} 171}
211 172
212static int sis_fb_free(DRM_IOCTL_ARGS) 173static int sis_drm_free(DRM_IOCTL_ARGS)
213{ 174{
214 DRM_DEVICE; 175 DRM_DEVICE;
215 drm_sis_private_t *dev_priv = dev->dev_private; 176 drm_sis_private_t *dev_priv = dev->dev_private;
216 drm_sis_mem_t fb; 177 drm_sis_mem_t mem;
178 int ret;
217 179
218 if (dev_priv == NULL || dev_priv->FBHeap == NULL) 180 DRM_COPY_FROM_USER_IOCTL(mem, (drm_sis_mem_t __user *) data,
219 return DRM_ERR(EINVAL); 181 sizeof(mem));
220 182
221 DRM_COPY_FROM_USER_IOCTL(fb, (drm_sis_mem_t __user *) data, sizeof(fb)); 183 mutex_lock(&dev->struct_mutex);
184 ret = drm_sman_free_key(&dev_priv->sman, mem.free);
185 mutex_unlock(&dev->struct_mutex);
186 DRM_DEBUG("free = 0x%lx\n", mem.free);
222 187
223 if (!mmBlockInHeap(dev_priv->FBHeap, (PMemBlock) fb.free)) 188 return ret;
224 return DRM_ERR(EINVAL);
225
226 if (!del_alloc_set(fb.context, VIDEO_TYPE, fb.free))
227 return DRM_ERR(EINVAL);
228 mmFreeMem((PMemBlock) fb.free);
229
230 DRM_DEBUG("free fb, free = 0x%lx\n", fb.free);
231
232 return 0;
233} 189}
234 190
235#endif 191static int sis_fb_alloc(DRM_IOCTL_ARGS)
236 192{
237/* agp memory management */ 193 DRM_DEVICE;
194 return sis_drm_alloc(dev, priv, data, VIDEO_TYPE);
195}
238 196
239static int sis_ioctl_agp_init(DRM_IOCTL_ARGS) 197static int sis_ioctl_agp_init(DRM_IOCTL_ARGS)
240{ 198{
241 DRM_DEVICE; 199 DRM_DEVICE;
242 drm_sis_private_t *dev_priv = dev->dev_private; 200 drm_sis_private_t *dev_priv = dev->dev_private;
243 drm_sis_agp_t agp; 201 drm_sis_agp_t agp;
244 202 int ret;
245 if (dev_priv == NULL) { 203 dev_priv = dev->dev_private;
246 dev->dev_private = drm_calloc(1, sizeof(drm_sis_private_t),
247 DRM_MEM_DRIVER);
248 dev_priv = dev->dev_private;
249 if (dev_priv == NULL)
250 return ENOMEM;
251 }
252
253 if (dev_priv->AGPHeap != NULL)
254 return DRM_ERR(EINVAL);
255 204
256 DRM_COPY_FROM_USER_IOCTL(agp, (drm_sis_agp_t __user *) data, 205 DRM_COPY_FROM_USER_IOCTL(agp, (drm_sis_agp_t __user *) data,
257 sizeof(agp)); 206 sizeof(agp));
207 mutex_lock(&dev->struct_mutex);
208 ret = drm_sman_set_range(&dev_priv->sman, AGP_TYPE, 0,
209 agp.size >> SIS_MM_ALIGN_SHIFT);
210
211 if (ret) {
212 DRM_ERROR("AGP memory manager initialisation error\n");
213 mutex_unlock(&dev->struct_mutex);
214 return ret;
215 }
258 216
259 dev_priv->AGPHeap = mmInit(agp.offset, agp.size); 217 dev_priv->agp_initialized = 1;
218 dev_priv->agp_offset = agp.offset;
219 mutex_unlock(&dev->struct_mutex);
260 220
261 DRM_DEBUG("offset = %u, size = %u", agp.offset, agp.size); 221 DRM_DEBUG("offset = %u, size = %u", agp.offset, agp.size);
262
263 return 0; 222 return 0;
264} 223}
265 224
266static int sis_ioctl_agp_alloc(DRM_IOCTL_ARGS) 225static int sis_ioctl_agp_alloc(DRM_IOCTL_ARGS)
267{ 226{
268 DRM_DEVICE; 227 DRM_DEVICE;
269 drm_sis_private_t *dev_priv = dev->dev_private;
270 drm_sis_mem_t __user *argp = (drm_sis_mem_t __user *)data;
271 drm_sis_mem_t agp;
272 PMemBlock block;
273 int retval = 0;
274 228
275 if (dev_priv == NULL || dev_priv->AGPHeap == NULL) 229 return sis_drm_alloc(dev, priv, data, AGP_TYPE);
276 return DRM_ERR(EINVAL); 230}
277 231
278 DRM_COPY_FROM_USER_IOCTL(agp, argp, sizeof(agp)); 232static drm_local_map_t *sis_reg_init(drm_device_t *dev)
279 233{
280 block = mmAllocMem(dev_priv->AGPHeap, agp.size, 0, 0); 234 drm_map_list_t *entry;
281 if (block) { 235 drm_local_map_t *map;
282 /* TODO */ 236
283 agp.offset = block->ofs; 237 list_for_each_entry(entry, &dev->maplist->head, head) {
284 agp.free = (unsigned long)block; 238 map = entry->map;
285 if (!add_alloc_set(agp.context, AGP_TYPE, agp.free)) { 239 if (!map)
286 DRM_DEBUG("adding to allocation set fails\n"); 240 continue;
287 mmFreeMem((PMemBlock) agp.free); 241 if (map->type == _DRM_REGISTERS) {
288 retval = -1; 242 return map;
289 } 243 }
290 } else {
291 agp.offset = 0;
292 agp.size = 0;
293 agp.free = 0;
294 } 244 }
295 245 return NULL;
296 DRM_COPY_TO_USER_IOCTL(argp, agp, sizeof(agp));
297
298 DRM_DEBUG("alloc agp, size = %d, offset = %d\n", agp.size, agp.offset);
299
300 return retval;
301} 246}
302 247
303static int sis_ioctl_agp_free(DRM_IOCTL_ARGS) 248int sis_idle(drm_device_t *dev)
304{ 249{
305 DRM_DEVICE;
306 drm_sis_private_t *dev_priv = dev->dev_private; 250 drm_sis_private_t *dev_priv = dev->dev_private;
307 drm_sis_mem_t agp; 251 uint32_t idle_reg;
308 252 unsigned long end;
309 if (dev_priv == NULL || dev_priv->AGPHeap == NULL) 253 int i;
310 return DRM_ERR(EINVAL);
311 254
312 DRM_COPY_FROM_USER_IOCTL(agp, (drm_sis_mem_t __user *) data, 255 if (dev_priv->idle_fault)
313 sizeof(agp)); 256 return 0;
314 257
315 if (!mmBlockInHeap(dev_priv->AGPHeap, (PMemBlock) agp.free)) 258 if (dev_priv->mmio == NULL) {
316 return DRM_ERR(EINVAL); 259 dev_priv->mmio = sis_reg_init(dev);
260 if (dev_priv->mmio == NULL) {
261 DRM_ERROR("Could not find register map.\n");
262 return 0;
263 }
264 }
265
266 /*
267 * Implement a device switch here if needed
268 */
269
270 if (dev_priv->chipset != SIS_CHIP_315)
271 return 0;
272
273 /*
274 * Timeout after 3 seconds. We cannot use DRM_WAIT_ON here
275 * because its polling frequency is too low.
276 */
277
278 end = jiffies + (DRM_HZ * 3);
279
280 for (i=0; i<4; ++i) {
281 do {
282 idle_reg = SIS_READ(0x85cc);
283 } while ( !time_after_eq(jiffies, end) &&
284 ((idle_reg & 0x80000000) != 0x80000000));
285 }
317 286
318 mmFreeMem((PMemBlock) agp.free); 287 if (time_after_eq(jiffies, end)) {
319 if (!del_alloc_set(agp.context, AGP_TYPE, agp.free)) 288 DRM_ERROR("Graphics engine idle timeout. "
320 return DRM_ERR(EINVAL); 289 "Disabling idle check\n");
290 dev_priv->idle_fault = 1;
291 }
321 292
322 DRM_DEBUG("free agp, free = 0x%lx\n", agp.free); 293 /*
294 * The caller never sees an error code. It gets trapped
295 * in libdrm.
296 */
323 297
324 return 0; 298 return 0;
325} 299}
326 300
327int sis_init_context(struct drm_device *dev, int context)
328{
329 int i;
330 301
331 for (i = 0; i < MAX_CONTEXT; i++) { 302void sis_lastclose(struct drm_device *dev)
332 if (global_ppriv[i].used && 303{
333 (global_ppriv[i].context == context)) 304 drm_sis_private_t *dev_priv = dev->dev_private;
334 break;
335 }
336 305
337 if (i >= MAX_CONTEXT) { 306 if (!dev_priv)
338 for (i = 0; i < MAX_CONTEXT; i++) { 307 return;
339 if (!global_ppriv[i].used) {
340 global_ppriv[i].context = context;
341 global_ppriv[i].used = 1;
342 global_ppriv[i].sets[0] = setInit();
343 global_ppriv[i].sets[1] = setInit();
344 DRM_DEBUG("init allocation set, socket=%d, "
345 "context = %d\n", i, context);
346 break;
347 }
348 }
349 if ((i >= MAX_CONTEXT) || (global_ppriv[i].sets[0] == NULL) ||
350 (global_ppriv[i].sets[1] == NULL)) {
351 return 0;
352 }
353 }
354 308
355 return 1; 309 mutex_lock(&dev->struct_mutex);
310 drm_sman_cleanup(&dev_priv->sman);
311 dev_priv->vram_initialized = 0;
312 dev_priv->agp_initialized = 0;
313 dev_priv->mmio = NULL;
314 mutex_unlock(&dev->struct_mutex);
356} 315}
357 316
358int sis_final_context(struct drm_device *dev, int context) 317void sis_reclaim_buffers_locked(drm_device_t * dev, struct file *filp)
359{ 318{
360 int i; 319 drm_sis_private_t *dev_priv = dev->dev_private;
320 drm_file_t *priv = filp->private_data;
361 321
362 for (i = 0; i < MAX_CONTEXT; i++) { 322 mutex_lock(&dev->struct_mutex);
363 if (global_ppriv[i].used && 323 if (drm_sman_owner_clean(&dev_priv->sman, (unsigned long)priv)) {
364 (global_ppriv[i].context == context)) 324 mutex_unlock(&dev->struct_mutex);
365 break; 325 return;
366 } 326 }
367 327
368 if (i < MAX_CONTEXT) { 328 if (dev->driver->dma_quiescent) {
369 set_t *set; 329 dev->driver->dma_quiescent(dev);
370 ITEM_TYPE item;
371 int retval;
372
373 DRM_DEBUG("find socket %d, context = %d\n", i, context);
374
375 /* Video Memory */
376 set = global_ppriv[i].sets[0];
377 retval = setFirst(set, &item);
378 while (retval) {
379 DRM_DEBUG("free video memory 0x%lx\n", item);
380#if defined(__linux__) && defined(CONFIG_FB_SIS)
381 sis_free(item);
382#else
383 mmFreeMem((PMemBlock) item);
384#endif
385 retval = setNext(set, &item);
386 }
387 setDestroy(set);
388
389 /* AGP Memory */
390 set = global_ppriv[i].sets[1];
391 retval = setFirst(set, &item);
392 while (retval) {
393 DRM_DEBUG("free agp memory 0x%lx\n", item);
394 mmFreeMem((PMemBlock) item);
395 retval = setNext(set, &item);
396 }
397 setDestroy(set);
398
399 global_ppriv[i].used = 0;
400 } 330 }
401 331
402 return 1; 332 drm_sman_owner_cleanup(&dev_priv->sman, (unsigned long)priv);
333 mutex_unlock(&dev->struct_mutex);
334 return;
403} 335}
404 336
405drm_ioctl_desc_t sis_ioctls[] = { 337drm_ioctl_desc_t sis_ioctls[] = {
406 [DRM_IOCTL_NR(DRM_SIS_FB_ALLOC)] = {sis_fb_alloc, DRM_AUTH}, 338 [DRM_IOCTL_NR(DRM_SIS_FB_ALLOC)] = {sis_fb_alloc, DRM_AUTH},
407 [DRM_IOCTL_NR(DRM_SIS_FB_FREE)] = {sis_fb_free, DRM_AUTH}, 339 [DRM_IOCTL_NR(DRM_SIS_FB_FREE)] = {sis_drm_free, DRM_AUTH},
408 [DRM_IOCTL_NR(DRM_SIS_AGP_INIT)] = {sis_ioctl_agp_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY}, 340 [DRM_IOCTL_NR(DRM_SIS_AGP_INIT)] =
341 {sis_ioctl_agp_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY},
409 [DRM_IOCTL_NR(DRM_SIS_AGP_ALLOC)] = {sis_ioctl_agp_alloc, DRM_AUTH}, 342 [DRM_IOCTL_NR(DRM_SIS_AGP_ALLOC)] = {sis_ioctl_agp_alloc, DRM_AUTH},
410 [DRM_IOCTL_NR(DRM_SIS_AGP_FREE)] = {sis_ioctl_agp_free, DRM_AUTH}, 343 [DRM_IOCTL_NR(DRM_SIS_AGP_FREE)] = {sis_drm_free, DRM_AUTH},
411 [DRM_IOCTL_NR(DRM_SIS_FB_INIT)] = {sis_fb_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY} 344 [DRM_IOCTL_NR(DRM_SIS_FB_INIT)] =
345 {sis_fb_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY}
412}; 346};
413 347
414int sis_max_ioctl = DRM_ARRAY_SIZE(sis_ioctls); 348int sis_max_ioctl = DRM_ARRAY_SIZE(sis_ioctls);
diff --git a/drivers/char/drm/via_dmablit.c b/drivers/char/drm/via_dmablit.c
index 78a81a4a99c5..60c1695db300 100644
--- a/drivers/char/drm/via_dmablit.c
+++ b/drivers/char/drm/via_dmablit.c
@@ -41,9 +41,9 @@
41 41
42#include <linux/pagemap.h> 42#include <linux/pagemap.h>
43 43
44#define VIA_PGDN(x) (((unsigned long)(x)) & PAGE_MASK) 44#define VIA_PGDN(x) (((unsigned long)(x)) & PAGE_MASK)
45#define VIA_PGOFF(x) (((unsigned long)(x)) & ~PAGE_MASK) 45#define VIA_PGOFF(x) (((unsigned long)(x)) & ~PAGE_MASK)
46#define VIA_PFN(x) ((unsigned long)(x) >> PAGE_SHIFT) 46#define VIA_PFN(x) ((unsigned long)(x) >> PAGE_SHIFT)
47 47
48typedef struct _drm_via_descriptor { 48typedef struct _drm_via_descriptor {
49 uint32_t mem_addr; 49 uint32_t mem_addr;
@@ -121,19 +121,19 @@ via_map_blit_for_device(struct pci_dev *pdev,
121 121
122 while (line_len > 0) { 122 while (line_len > 0) {
123 123
124 remaining_len = min(PAGE_SIZE-VIA_PGOFF(cur_mem), line_len); 124 remaining_len = min(PAGE_SIZE-VIA_PGOFF(cur_mem), line_len);
125 line_len -= remaining_len; 125 line_len -= remaining_len;
126 126
127 if (mode == 1) { 127 if (mode == 1) {
128 desc_ptr->mem_addr = 128 desc_ptr->mem_addr =
129 dma_map_page(&pdev->dev, 129 dma_map_page(&pdev->dev,
130 vsg->pages[VIA_PFN(cur_mem) - 130 vsg->pages[VIA_PFN(cur_mem) -
131 VIA_PFN(first_addr)], 131 VIA_PFN(first_addr)],
132 VIA_PGOFF(cur_mem), remaining_len, 132 VIA_PGOFF(cur_mem), remaining_len,
133 vsg->direction); 133 vsg->direction);
134 desc_ptr->dev_addr = cur_fb; 134 desc_ptr->dev_addr = cur_fb;
135 135
136 desc_ptr->size = remaining_len; 136 desc_ptr->size = remaining_len;
137 desc_ptr->next = (uint32_t) next; 137 desc_ptr->next = (uint32_t) next;
138 next = dma_map_single(&pdev->dev, desc_ptr, sizeof(*desc_ptr), 138 next = dma_map_single(&pdev->dev, desc_ptr, sizeof(*desc_ptr),
139 DMA_TO_DEVICE); 139 DMA_TO_DEVICE);
@@ -162,7 +162,7 @@ via_map_blit_for_device(struct pci_dev *pdev,
162 162
163/* 163/*
164 * Function that frees up all resources for a blit. It is usable even if the 164 * Function that frees up all resources for a blit. It is usable even if the
165 * blit info has only be partially built as long as the status enum is consistent 165 * blit info has only been partially built as long as the status enum is consistent
166 * with the actual status of the used resources. 166 * with the actual status of the used resources.
167 */ 167 */
168 168
@@ -238,8 +238,11 @@ via_lock_all_dma_pages(drm_via_sg_info_t *vsg, drm_via_dmablit_t *xfer)
238 return DRM_ERR(ENOMEM); 238 return DRM_ERR(ENOMEM);
239 memset(vsg->pages, 0, sizeof(struct page *) * vsg->num_pages); 239 memset(vsg->pages, 0, sizeof(struct page *) * vsg->num_pages);
240 down_read(&current->mm->mmap_sem); 240 down_read(&current->mm->mmap_sem);
241 ret = get_user_pages(current, current->mm, (unsigned long) xfer->mem_addr, 241 ret = get_user_pages(current, current->mm,
242 vsg->num_pages, vsg->direction, 0, vsg->pages, NULL); 242 (unsigned long)xfer->mem_addr,
243 vsg->num_pages,
244 (vsg->direction == DMA_FROM_DEVICE),
245 0, vsg->pages, NULL);
243 246
244 up_read(&current->mm->mmap_sem); 247 up_read(&current->mm->mmap_sem);
245 if (ret != vsg->num_pages) { 248 if (ret != vsg->num_pages) {
@@ -475,9 +478,15 @@ via_dmablit_timer(unsigned long data)
475 if (!timer_pending(&blitq->poll_timer)) { 478 if (!timer_pending(&blitq->poll_timer)) {
476 blitq->poll_timer.expires = jiffies+1; 479 blitq->poll_timer.expires = jiffies+1;
477 add_timer(&blitq->poll_timer); 480 add_timer(&blitq->poll_timer);
478 }
479 via_dmablit_handler(dev, engine, 0);
480 481
482 /*
483 * Rerun handler to delete timer if engines are off, and
484 * to shorten abort latency. This is a little nasty.
485 */
486
487 via_dmablit_handler(dev, engine, 0);
488
489 }
481} 490}
482 491
483 492
@@ -597,15 +606,27 @@ via_build_sg_info(drm_device_t *dev, drm_via_sg_info_t *vsg, drm_via_dmablit_t *
597 * (Not a big limitation anyway.) 606 * (Not a big limitation anyway.)
598 */ 607 */
599 608
600 if (((xfer->mem_stride - xfer->line_length) >= PAGE_SIZE) || 609 if ((xfer->mem_stride - xfer->line_length) >= PAGE_SIZE) {
601 (xfer->mem_stride > 2048*4)) {
602 DRM_ERROR("Too large system memory stride. Stride: %d, " 610 DRM_ERROR("Too large system memory stride. Stride: %d, "
603 "Length: %d\n", xfer->mem_stride, xfer->line_length); 611 "Length: %d\n", xfer->mem_stride, xfer->line_length);
604 return DRM_ERR(EINVAL); 612 return DRM_ERR(EINVAL);
605 } 613 }
606 614
607 if (xfer->num_lines > 2048) { 615 if ((xfer->mem_stride == xfer->line_length) &&
608 DRM_ERROR("Too many PCI DMA bitblt lines.\n"); 616 (xfer->fb_stride == xfer->line_length)) {
617 xfer->mem_stride *= xfer->num_lines;
618 xfer->line_length = xfer->mem_stride;
619 xfer->fb_stride = xfer->mem_stride;
620 xfer->num_lines = 1;
621 }
622
623 /*
624 * Don't lock an arbitrary large number of pages, since that causes a
625 * DOS security hole.
626 */
627
628 if (xfer->num_lines > 2048 || (xfer->num_lines*xfer->mem_stride > (2048*2048*4))) {
629 DRM_ERROR("Too large PCI DMA bitblt.\n");
609 return DRM_ERR(EINVAL); 630 return DRM_ERR(EINVAL);
610 } 631 }
611 632
@@ -628,16 +649,17 @@ via_build_sg_info(drm_device_t *dev, drm_via_sg_info_t *vsg, drm_via_dmablit_t *
628 649
629#ifdef VIA_BUGFREE 650#ifdef VIA_BUGFREE
630 if ((((unsigned long)xfer->mem_addr & 3) != ((unsigned long)xfer->fb_addr & 3)) || 651 if ((((unsigned long)xfer->mem_addr & 3) != ((unsigned long)xfer->fb_addr & 3)) ||
631 ((xfer->mem_stride & 3) != (xfer->fb_stride & 3))) { 652 ((xfer->num_lines > 1) && ((xfer->mem_stride & 3) != (xfer->fb_stride & 3)))) {
632 DRM_ERROR("Invalid DRM bitblt alignment.\n"); 653 DRM_ERROR("Invalid DRM bitblt alignment.\n");
633 return DRM_ERR(EINVAL); 654 return DRM_ERR(EINVAL);
634 } 655 }
635#else 656#else
636 if ((((unsigned long)xfer->mem_addr & 15) || 657 if ((((unsigned long)xfer->mem_addr & 15) ||
637 ((unsigned long)xfer->fb_addr & 3)) || (xfer->mem_stride & 15) || 658 ((unsigned long)xfer->fb_addr & 3)) ||
638 (xfer->fb_stride & 3)) { 659 ((xfer->num_lines > 1) &&
660 ((xfer->mem_stride & 15) || (xfer->fb_stride & 3)))) {
639 DRM_ERROR("Invalid DRM bitblt alignment.\n"); 661 DRM_ERROR("Invalid DRM bitblt alignment.\n");
640 return DRM_ERR(EINVAL); 662 return DRM_ERR(EINVAL);
641 } 663 }
642#endif 664#endif
643 665
@@ -715,7 +737,7 @@ via_dmablit(drm_device_t *dev, drm_via_dmablit_t *xfer)
715 drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private; 737 drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private;
716 drm_via_sg_info_t *vsg; 738 drm_via_sg_info_t *vsg;
717 drm_via_blitq_t *blitq; 739 drm_via_blitq_t *blitq;
718 int ret; 740 int ret;
719 int engine; 741 int engine;
720 unsigned long irqsave; 742 unsigned long irqsave;
721 743
@@ -756,7 +778,7 @@ via_dmablit(drm_device_t *dev, drm_via_dmablit_t *xfer)
756 778
757/* 779/*
758 * Sync on a previously submitted blit. Note that the X server use signals extensively, and 780 * Sync on a previously submitted blit. Note that the X server use signals extensively, and
759 * that there is a very big proability that this IOCTL will be interrupted by a signal. In that 781 * that there is a very big probability that this IOCTL will be interrupted by a signal. In that
760 * case it returns with -EAGAIN for the signal to be delivered. 782 * case it returns with -EAGAIN for the signal to be delivered.
761 * The caller should then reissue the IOCTL. This is similar to what is being done for drmGetLock(). 783 * The caller should then reissue the IOCTL. This is similar to what is being done for drmGetLock().
762 */ 784 */
diff --git a/drivers/char/drm/via_drm.h b/drivers/char/drm/via_drm.h
index 47f0b5b26379..e4ee97d7156f 100644
--- a/drivers/char/drm/via_drm.h
+++ b/drivers/char/drm/via_drm.h
@@ -250,6 +250,12 @@ typedef struct drm_via_blitsync {
250 unsigned engine; 250 unsigned engine;
251} drm_via_blitsync_t; 251} drm_via_blitsync_t;
252 252
253/* - * Below,"flags" is currently unused but will be used for possible future
254 * extensions like kernel space bounce buffers for bad alignments and
255 * blit engine busy-wait polling for better latency in the absence of
256 * interrupts.
257 */
258
253typedef struct drm_via_dmablit { 259typedef struct drm_via_dmablit {
254 uint32_t num_lines; 260 uint32_t num_lines;
255 uint32_t line_length; 261 uint32_t line_length;
@@ -260,7 +266,7 @@ typedef struct drm_via_dmablit {
260 unsigned char *mem_addr; 266 unsigned char *mem_addr;
261 uint32_t mem_stride; 267 uint32_t mem_stride;
262 268
263 int bounce_buffer; 269 uint32_t flags;
264 int to_fb; 270 int to_fb;
265 271
266 drm_via_blitsync_t sync; 272 drm_via_blitsync_t sync;
diff --git a/drivers/char/drm/via_drv.c b/drivers/char/drm/via_drv.c
index b3d364d793d7..bb9dde8b1911 100644
--- a/drivers/char/drm/via_drv.c
+++ b/drivers/char/drm/via_drv.c
@@ -43,7 +43,6 @@ static struct drm_driver driver = {
43 DRIVER_IRQ_SHARED | DRIVER_IRQ_VBL, 43 DRIVER_IRQ_SHARED | DRIVER_IRQ_VBL,
44 .load = via_driver_load, 44 .load = via_driver_load,
45 .unload = via_driver_unload, 45 .unload = via_driver_unload,
46 .context_ctor = via_init_context,
47 .context_dtor = via_final_context, 46 .context_dtor = via_final_context,
48 .vblank_wait = via_driver_vblank_wait, 47 .vblank_wait = via_driver_vblank_wait,
49 .irq_preinstall = via_driver_irq_preinstall, 48 .irq_preinstall = via_driver_irq_preinstall,
@@ -53,6 +52,8 @@ static struct drm_driver driver = {
53 .dma_quiescent = via_driver_dma_quiescent, 52 .dma_quiescent = via_driver_dma_quiescent,
54 .dri_library_name = dri_library_name, 53 .dri_library_name = dri_library_name,
55 .reclaim_buffers = drm_core_reclaim_buffers, 54 .reclaim_buffers = drm_core_reclaim_buffers,
55 .reclaim_buffers_locked = via_reclaim_buffers_locked,
56 .lastclose = via_lastclose,
56 .get_map_ofs = drm_core_get_map_ofs, 57 .get_map_ofs = drm_core_get_map_ofs,
57 .get_reg_ofs = drm_core_get_reg_ofs, 58 .get_reg_ofs = drm_core_get_reg_ofs,
58 .ioctls = via_ioctls, 59 .ioctls = via_ioctls,
diff --git a/drivers/char/drm/via_drv.h b/drivers/char/drm/via_drv.h
index 52bcc7b1ba45..d21b5b75da0f 100644
--- a/drivers/char/drm/via_drv.h
+++ b/drivers/char/drm/via_drv.h
@@ -24,15 +24,16 @@
24#ifndef _VIA_DRV_H_ 24#ifndef _VIA_DRV_H_
25#define _VIA_DRV_H_ 25#define _VIA_DRV_H_
26 26
27#include "drm_sman.h"
27#define DRIVER_AUTHOR "Various" 28#define DRIVER_AUTHOR "Various"
28 29
29#define DRIVER_NAME "via" 30#define DRIVER_NAME "via"
30#define DRIVER_DESC "VIA Unichrome / Pro" 31#define DRIVER_DESC "VIA Unichrome / Pro"
31#define DRIVER_DATE "20051116" 32#define DRIVER_DATE "20060529"
32 33
33#define DRIVER_MAJOR 2 34#define DRIVER_MAJOR 2
34#define DRIVER_MINOR 7 35#define DRIVER_MINOR 10
35#define DRIVER_PATCHLEVEL 4 36#define DRIVER_PATCHLEVEL 0
36 37
37#include "via_verifier.h" 38#include "via_verifier.h"
38 39
@@ -85,6 +86,12 @@ typedef struct drm_via_private {
85 uint32_t irq_enable_mask; 86 uint32_t irq_enable_mask;
86 uint32_t irq_pending_mask; 87 uint32_t irq_pending_mask;
87 int *irq_map; 88 int *irq_map;
89 unsigned int idle_fault;
90 drm_sman_t sman;
91 int vram_initialized;
92 int agp_initialized;
93 unsigned long vram_offset;
94 unsigned long agp_offset;
88 drm_via_blitq_t blit_queues[VIA_NUM_BLIT_ENGINES]; 95 drm_via_blitq_t blit_queues[VIA_NUM_BLIT_ENGINES];
89} drm_via_private_t; 96} drm_via_private_t;
90 97
@@ -135,6 +142,9 @@ extern void via_init_futex(drm_via_private_t * dev_priv);
135extern void via_cleanup_futex(drm_via_private_t * dev_priv); 142extern void via_cleanup_futex(drm_via_private_t * dev_priv);
136extern void via_release_futex(drm_via_private_t * dev_priv, int context); 143extern void via_release_futex(drm_via_private_t * dev_priv, int context);
137 144
145extern void via_reclaim_buffers_locked(drm_device_t *dev, struct file *filp);
146extern void via_lastclose(drm_device_t *dev);
147
138extern void via_dmablit_handler(drm_device_t *dev, int engine, int from_irq); 148extern void via_dmablit_handler(drm_device_t *dev, int engine, int from_irq);
139extern void via_init_dmablit(drm_device_t *dev); 149extern void via_init_dmablit(drm_device_t *dev);
140 150
diff --git a/drivers/char/drm/via_ds.c b/drivers/char/drm/via_ds.c
deleted file mode 100644
index 9429736b3b96..000000000000
--- a/drivers/char/drm/via_ds.c
+++ /dev/null
@@ -1,273 +0,0 @@
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 "drmP.h"
26
27#include "via_ds.h"
28extern unsigned int VIA_DEBUG;
29
30set_t *via_setInit(void)
31{
32 int i;
33 set_t *set;
34 set = (set_t *) drm_alloc(sizeof(set_t), DRM_MEM_DRIVER);
35 for (i = 0; i < SET_SIZE; i++) {
36 set->list[i].free_next = i + 1;
37 set->list[i].alloc_next = -1;
38 }
39 set->list[SET_SIZE - 1].free_next = -1;
40 set->free = 0;
41 set->alloc = -1;
42 set->trace = -1;
43 return set;
44}
45
46int via_setAdd(set_t * set, ITEM_TYPE item)
47{
48 int free = set->free;
49 if (free != -1) {
50 set->list[free].val = item;
51 set->free = set->list[free].free_next;
52 } else {
53 return 0;
54 }
55 set->list[free].alloc_next = set->alloc;
56 set->alloc = free;
57 set->list[free].free_next = -1;
58 return 1;
59}
60
61int via_setDel(set_t * set, ITEM_TYPE item)
62{
63 int alloc = set->alloc;
64 int prev = -1;
65
66 while (alloc != -1) {
67 if (set->list[alloc].val == item) {
68 if (prev != -1)
69 set->list[prev].alloc_next =
70 set->list[alloc].alloc_next;
71 else
72 set->alloc = set->list[alloc].alloc_next;
73 break;
74 }
75 prev = alloc;
76 alloc = set->list[alloc].alloc_next;
77 }
78
79 if (alloc == -1)
80 return 0;
81
82 set->list[alloc].free_next = set->free;
83 set->free = alloc;
84 set->list[alloc].alloc_next = -1;
85
86 return 1;
87}
88
89/* setFirst -> setAdd -> setNext is wrong */
90
91int via_setFirst(set_t * set, ITEM_TYPE * item)
92{
93 if (set->alloc == -1)
94 return 0;
95
96 *item = set->list[set->alloc].val;
97 set->trace = set->list[set->alloc].alloc_next;
98
99 return 1;
100}
101
102int via_setNext(set_t * set, ITEM_TYPE * item)
103{
104 if (set->trace == -1)
105 return 0;
106
107 *item = set->list[set->trace].val;
108 set->trace = set->list[set->trace].alloc_next;
109
110 return 1;
111}
112
113int via_setDestroy(set_t * set)
114{
115 drm_free(set, sizeof(set_t), DRM_MEM_DRIVER);
116
117 return 1;
118}
119
120#define ISFREE(bptr) ((bptr)->free)
121
122#define fprintf(fmt, arg...) do{}while(0)
123
124memHeap_t *via_mmInit(int ofs, int size)
125{
126 PMemBlock blocks;
127
128 if (size <= 0)
129 return NULL;
130
131 blocks = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock), DRM_MEM_DRIVER);
132
133 if (blocks) {
134 blocks->ofs = ofs;
135 blocks->size = size;
136 blocks->free = 1;
137 return (memHeap_t *) blocks;
138 } else
139 return NULL;
140}
141
142static TMemBlock *SliceBlock(TMemBlock * p,
143 int startofs, int size,
144 int reserved, int alignment)
145{
146 TMemBlock *newblock;
147
148 /* break left */
149 if (startofs > p->ofs) {
150 newblock =
151 (TMemBlock *) drm_calloc(1, sizeof(TMemBlock),
152 DRM_MEM_DRIVER);
153 newblock->ofs = startofs;
154 newblock->size = p->size - (startofs - p->ofs);
155 newblock->free = 1;
156 newblock->next = p->next;
157 p->size -= newblock->size;
158 p->next = newblock;
159 p = newblock;
160 }
161
162 /* break right */
163 if (size < p->size) {
164 newblock =
165 (TMemBlock *) drm_calloc(1, sizeof(TMemBlock),
166 DRM_MEM_DRIVER);
167 newblock->ofs = startofs + size;
168 newblock->size = p->size - size;
169 newblock->free = 1;
170 newblock->next = p->next;
171 p->size = size;
172 p->next = newblock;
173 }
174
175 /* p = middle block */
176 p->align = alignment;
177 p->free = 0;
178 p->reserved = reserved;
179 return p;
180}
181
182PMemBlock via_mmAllocMem(memHeap_t * heap, int size, int align2,
183 int startSearch)
184{
185 int mask, startofs, endofs;
186 TMemBlock *p;
187
188 if (!heap || align2 < 0 || size <= 0)
189 return NULL;
190
191 mask = (1 << align2) - 1;
192 startofs = 0;
193 p = (TMemBlock *) heap;
194
195 while (p) {
196 if (ISFREE(p)) {
197 startofs = (p->ofs + mask) & ~mask;
198
199 if (startofs < startSearch)
200 startofs = startSearch;
201
202 endofs = startofs + size;
203
204 if (endofs <= (p->ofs + p->size))
205 break;
206 }
207
208 p = p->next;
209 }
210
211 if (!p)
212 return NULL;
213
214 p = SliceBlock(p, startofs, size, 0, mask + 1);
215 p->heap = heap;
216
217 return p;
218}
219
220static __inline__ int Join2Blocks(TMemBlock * p)
221{
222 if (p->free && p->next && p->next->free) {
223 TMemBlock *q = p->next;
224 p->size += q->size;
225 p->next = q->next;
226 drm_free(q, sizeof(TMemBlock), DRM_MEM_DRIVER);
227
228 return 1;
229 }
230
231 return 0;
232}
233
234int via_mmFreeMem(PMemBlock b)
235{
236 TMemBlock *p, *prev;
237
238 if (!b)
239 return 0;
240
241 if (!b->heap) {
242 fprintf(stderr, "no heap\n");
243
244 return -1;
245 }
246
247 p = b->heap;
248 prev = NULL;
249
250 while (p && p != b) {
251 prev = p;
252 p = p->next;
253 }
254
255 if (!p || p->free || p->reserved) {
256 if (!p)
257 fprintf(stderr, "block not found in heap\n");
258 else if (p->free)
259 fprintf(stderr, "block already free\n");
260 else
261 fprintf(stderr, "block is reserved\n");
262
263 return -1;
264 }
265
266 p->free = 1;
267 Join2Blocks(p);
268
269 if (prev)
270 Join2Blocks(prev);
271
272 return 0;
273}
diff --git a/drivers/char/drm/via_ds.h b/drivers/char/drm/via_ds.h
deleted file mode 100644
index d2bb9f37ca38..000000000000
--- a/drivers/char/drm/via_ds.h
+++ /dev/null
@@ -1,104 +0,0 @@
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 unsigned int free:1;
65 unsigned 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_map.c b/drivers/char/drm/via_map.c
index c6a08e96285b..782011e0a58d 100644
--- a/drivers/char/drm/via_map.c
+++ b/drivers/char/drm/via_map.c
@@ -98,6 +98,7 @@ int via_map_init(DRM_IOCTL_ARGS)
98int via_driver_load(drm_device_t *dev, unsigned long chipset) 98int via_driver_load(drm_device_t *dev, unsigned long chipset)
99{ 99{
100 drm_via_private_t *dev_priv; 100 drm_via_private_t *dev_priv;
101 int ret = 0;
101 102
102 dev_priv = drm_calloc(1, sizeof(drm_via_private_t), DRM_MEM_DRIVER); 103 dev_priv = drm_calloc(1, sizeof(drm_via_private_t), DRM_MEM_DRIVER);
103 if (dev_priv == NULL) 104 if (dev_priv == NULL)
@@ -108,13 +109,19 @@ int via_driver_load(drm_device_t *dev, unsigned long chipset)
108 if (chipset == VIA_PRO_GROUP_A) 109 if (chipset == VIA_PRO_GROUP_A)
109 dev_priv->pro_group_a = 1; 110 dev_priv->pro_group_a = 1;
110 111
111 return 0; 112 ret = drm_sman_init(&dev_priv->sman, 2, 12, 8);
113 if (ret) {
114 drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER);
115 }
116 return ret;
112} 117}
113 118
114int via_driver_unload(drm_device_t *dev) 119int via_driver_unload(drm_device_t *dev)
115{ 120{
116 drm_via_private_t *dev_priv = dev->dev_private; 121 drm_via_private_t *dev_priv = dev->dev_private;
117 122
123 drm_sman_takedown(&dev_priv->sman);
124
118 drm_free(dev_priv, sizeof(drm_via_private_t), DRM_MEM_DRIVER); 125 drm_free(dev_priv, sizeof(drm_via_private_t), DRM_MEM_DRIVER);
119 126
120 return 0; 127 return 0;
diff --git a/drivers/char/drm/via_mm.c b/drivers/char/drm/via_mm.c
index 33e0cb12e4c3..2fcf0577a7aa 100644
--- a/drivers/char/drm/via_mm.c
+++ b/drivers/char/drm/via_mm.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved. 2 * Copyright 2006 Tungsten Graphics Inc., Bismarck, ND., USA.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved. 3 * All rights reserved.
4 * 4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a 5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"), 6 * copy of this software and associated documentation files (the "Software"),
@@ -16,347 +16,194 @@
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 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, 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 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 19 * THE AUTHORS OR COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 * DAMAGES OR 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 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE. 22 * DEALINGS IN THE SOFTWARE.
23 */ 23 */
24/*
25 * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
26 */
27
24#include "drmP.h" 28#include "drmP.h"
25#include "via_drm.h" 29#include "via_drm.h"
26#include "via_drv.h" 30#include "via_drv.h"
27#include "via_ds.h" 31#include "drm_sman.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 32
40static int via_agp_alloc(drm_via_mem_t * mem); 33#define VIA_MM_ALIGN_SHIFT 4
41static int via_agp_free(drm_via_mem_t * mem); 34#define VIA_MM_ALIGN_MASK ( (1 << VIA_MM_ALIGN_SHIFT) - 1)
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 long 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 long 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 35
75int via_agp_init(DRM_IOCTL_ARGS) 36int via_agp_init(DRM_IOCTL_ARGS)
76{ 37{
38 DRM_DEVICE;
77 drm_via_agp_t agp; 39 drm_via_agp_t agp;
40 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
41 int ret;
78 42
79 DRM_COPY_FROM_USER_IOCTL(agp, (drm_via_agp_t __user *) data, 43 DRM_COPY_FROM_USER_IOCTL(agp, (drm_via_agp_t __user *) data,
80 sizeof(agp)); 44 sizeof(agp));
45 mutex_lock(&dev->struct_mutex);
46 ret = drm_sman_set_range(&dev_priv->sman, VIA_MEM_AGP, 0,
47 agp.size >> VIA_MM_ALIGN_SHIFT);
48
49 if (ret) {
50 DRM_ERROR("AGP memory manager initialisation error\n");
51 mutex_unlock(&dev->struct_mutex);
52 return ret;
53 }
81 54
82 AgpHeap = via_mmInit(agp.offset, agp.size); 55 dev_priv->agp_initialized = 1;
83 56 dev_priv->agp_offset = agp.offset;
84 DRM_DEBUG("offset = %lu, size = %lu", (unsigned long)agp.offset, 57 mutex_unlock(&dev->struct_mutex);
85 (unsigned long)agp.size);
86 58
59 DRM_DEBUG("offset = %u, size = %u", agp.offset, agp.size);
87 return 0; 60 return 0;
88} 61}
89 62
90/* fb memory management */
91static memHeap_t *FBHeap = NULL;
92
93int via_fb_init(DRM_IOCTL_ARGS) 63int via_fb_init(DRM_IOCTL_ARGS)
94{ 64{
65 DRM_DEVICE;
95 drm_via_fb_t fb; 66 drm_via_fb_t fb;
67 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
68 int ret;
96 69
97 DRM_COPY_FROM_USER_IOCTL(fb, (drm_via_fb_t __user *) data, sizeof(fb)); 70 DRM_COPY_FROM_USER_IOCTL(fb, (drm_via_fb_t __user *) data, sizeof(fb));
98 71
99 FBHeap = via_mmInit(fb.offset, fb.size); 72 mutex_lock(&dev->struct_mutex);
73 ret = drm_sman_set_range(&dev_priv->sman, VIA_MEM_VIDEO, 0,
74 fb.size >> VIA_MM_ALIGN_SHIFT);
100 75
101 DRM_DEBUG("offset = %lu, size = %lu", (unsigned long)fb.offset, 76 if (ret) {
102 (unsigned long)fb.size); 77 DRM_ERROR("VRAM memory manager initialisation error\n");
78 mutex_unlock(&dev->struct_mutex);
79 return ret;
80 }
103 81
104 return 0; 82 dev_priv->vram_initialized = 1;
105} 83 dev_priv->vram_offset = fb.offset;
106 84
107int via_init_context(struct drm_device *dev, int context) 85 mutex_unlock(&dev->struct_mutex);
108{ 86 DRM_DEBUG("offset = %u, size = %u", fb.offset, fb.size);
109 int i; 87
110 88 return 0;
111 for (i = 0; i < MAX_CONTEXT; i++)
112 if (global_ppriv[i].used &&
113 (global_ppriv[i].context == context))
114 break;
115
116 if (i >= MAX_CONTEXT) {
117 for (i = 0; i < MAX_CONTEXT; i++) {
118 if (!global_ppriv[i].used) {
119 global_ppriv[i].context = context;
120 global_ppriv[i].used = 1;
121 global_ppriv[i].sets[0] = via_setInit();
122 global_ppriv[i].sets[1] = via_setInit();
123 DRM_DEBUG("init allocation set, socket=%d,"
124 " context = %d\n", i, context);
125 break;
126 }
127 }
128
129 if ((i >= MAX_CONTEXT) || (global_ppriv[i].sets[0] == NULL) ||
130 (global_ppriv[i].sets[1] == NULL)) {
131 return 0;
132 }
133 }
134 89
135 return 1;
136} 90}
137 91
138int via_final_context(struct drm_device *dev, int context) 92int via_final_context(struct drm_device *dev, int context)
139{ 93{
140 int i;
141 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; 94 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
142 95
143 for (i = 0; i < MAX_CONTEXT; i++)
144 if (global_ppriv[i].used &&
145 (global_ppriv[i].context == context))
146 break;
147
148 if (i < MAX_CONTEXT) {
149 set_t *set;
150 ITEM_TYPE item;
151 int retval;
152
153 DRM_DEBUG("find socket %d, context = %d\n", i, context);
154
155 /* Video Memory */
156 set = global_ppriv[i].sets[0];
157 retval = via_setFirst(set, &item);
158 while (retval) {
159 DRM_DEBUG("free video memory 0x%lx\n", item);
160 via_mmFreeMem((PMemBlock) item);
161 retval = via_setNext(set, &item);
162 }
163 via_setDestroy(set);
164
165 /* AGP Memory */
166 set = global_ppriv[i].sets[1];
167 retval = via_setFirst(set, &item);
168 while (retval) {
169 DRM_DEBUG("free agp memory 0x%lx\n", item);
170 via_mmFreeMem((PMemBlock) item);
171 retval = via_setNext(set, &item);
172 }
173 via_setDestroy(set);
174 global_ppriv[i].used = 0;
175 }
176 via_release_futex(dev_priv, context); 96 via_release_futex(dev_priv, context);
177 97
178#if defined(__linux__)
179 /* Linux specific until context tracking code gets ported to BSD */ 98 /* Linux specific until context tracking code gets ported to BSD */
180 /* Last context, perform cleanup */ 99 /* Last context, perform cleanup */
181 if (dev->ctx_count == 1 && dev->dev_private) { 100 if (dev->ctx_count == 1 && dev->dev_private) {
182 DRM_DEBUG("Last Context\n"); 101 DRM_DEBUG("Last Context\n");
183 if (dev->irq) 102 if (dev->irq)
184 drm_irq_uninstall(dev); 103 drm_irq_uninstall(dev);
185
186 via_cleanup_futex(dev_priv); 104 via_cleanup_futex(dev_priv);
187 via_do_cleanup_map(dev); 105 via_do_cleanup_map(dev);
188 } 106 }
189#endif
190
191 return 1; 107 return 1;
192} 108}
193 109
110void via_lastclose(struct drm_device *dev)
111{
112 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
113
114 if (!dev_priv)
115 return;
116
117 mutex_lock(&dev->struct_mutex);
118 drm_sman_cleanup(&dev_priv->sman);
119 dev_priv->vram_initialized = 0;
120 dev_priv->agp_initialized = 0;
121 mutex_unlock(&dev->struct_mutex);
122}
123
194int via_mem_alloc(DRM_IOCTL_ARGS) 124int via_mem_alloc(DRM_IOCTL_ARGS)
195{ 125{
126 DRM_DEVICE;
127
196 drm_via_mem_t mem; 128 drm_via_mem_t mem;
129 int retval = 0;
130 drm_memblock_item_t *item;
131 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
132 unsigned long tmpSize;
197 133
198 DRM_COPY_FROM_USER_IOCTL(mem, (drm_via_mem_t __user *) data, 134 DRM_COPY_FROM_USER_IOCTL(mem, (drm_via_mem_t __user *) data,
199 sizeof(mem)); 135 sizeof(mem));
200 136
201 switch (mem.type) { 137 if (mem.type > VIA_MEM_AGP) {
202 case VIA_MEM_VIDEO: 138 DRM_ERROR("Unknown memory type allocation\n");
203 if (via_fb_alloc(&mem) < 0) 139 return DRM_ERR(EINVAL);
204 return -EFAULT;
205 DRM_COPY_TO_USER_IOCTL((drm_via_mem_t __user *) data, mem,
206 sizeof(mem));
207 return 0;
208 case VIA_MEM_AGP:
209 if (via_agp_alloc(&mem) < 0)
210 return -EFAULT;
211 DRM_COPY_TO_USER_IOCTL((drm_via_mem_t __user *) data, mem,
212 sizeof(mem));
213 return 0;
214 } 140 }
215 141 mutex_lock(&dev->struct_mutex);
216 return -EFAULT; 142 if (0 == ((mem.type == VIA_MEM_VIDEO) ? dev_priv->vram_initialized :
217} 143 dev_priv->agp_initialized)) {
218 144 DRM_ERROR
219static int via_fb_alloc(drm_via_mem_t * mem) 145 ("Attempt to allocate from uninitialized memory manager.\n");
220{ 146 mutex_unlock(&dev->struct_mutex);
221 drm_via_mm_t fb; 147 return DRM_ERR(EINVAL);
222 PMemBlock block;
223 int retval = 0;
224
225 if (!FBHeap)
226 return -1;
227
228 fb.size = mem->size;
229 fb.context = mem->context;
230
231 block = via_mmAllocMem(FBHeap, fb.size, 5, 0);
232 if (block) {
233 fb.offset = block->ofs;
234 fb.free = (unsigned long)block;
235 if (!add_alloc_set(fb.context, VIA_MEM_VIDEO, fb.free)) {
236 DRM_DEBUG("adding to allocation set fails\n");
237 via_mmFreeMem((PMemBlock) fb.free);
238 retval = -1;
239 }
240 } else {
241 fb.offset = 0;
242 fb.size = 0;
243 fb.free = 0;
244 retval = -1;
245 } 148 }
246 149
247 mem->offset = fb.offset; 150 tmpSize = (mem.size + VIA_MM_ALIGN_MASK) >> VIA_MM_ALIGN_SHIFT;
248 mem->index = fb.free; 151 item = drm_sman_alloc(&dev_priv->sman, mem.type, tmpSize, 0,
249 152 (unsigned long)priv);
250 DRM_DEBUG("alloc fb, size = %d, offset = %d\n", fb.size, 153 mutex_unlock(&dev->struct_mutex);
251 (int)fb.offset); 154 if (item) {
252 155 mem.offset = ((mem.type == VIA_MEM_VIDEO) ?
253 return retval; 156 dev_priv->vram_offset : dev_priv->agp_offset) +
254} 157 (item->mm->
255 158 offset(item->mm, item->mm_info) << VIA_MM_ALIGN_SHIFT);
256static int via_agp_alloc(drm_via_mem_t * mem) 159 mem.index = item->user_hash.key;
257{
258 drm_via_mm_t agp;
259 PMemBlock block;
260 int retval = 0;
261
262 if (!AgpHeap)
263 return -1;
264
265 agp.size = mem->size;
266 agp.context = mem->context;
267
268 block = via_mmAllocMem(AgpHeap, agp.size, 5, 0);
269 if (block) {
270 agp.offset = block->ofs;
271 agp.free = (unsigned long)block;
272 if (!add_alloc_set(agp.context, VIA_MEM_AGP, agp.free)) {
273 DRM_DEBUG("adding to allocation set fails\n");
274 via_mmFreeMem((PMemBlock) agp.free);
275 retval = -1;
276 }
277 } else { 160 } else {
278 agp.offset = 0; 161 mem.offset = 0;
279 agp.size = 0; 162 mem.size = 0;
280 agp.free = 0; 163 mem.index = 0;
164 DRM_DEBUG("Video memory allocation failed\n");
165 retval = DRM_ERR(ENOMEM);
281 } 166 }
167 DRM_COPY_TO_USER_IOCTL((drm_via_mem_t __user *) data, mem, sizeof(mem));
282 168
283 mem->offset = agp.offset;
284 mem->index = agp.free;
285
286 DRM_DEBUG("alloc agp, size = %d, offset = %d\n", agp.size,
287 (unsigned int)agp.offset);
288 return retval; 169 return retval;
289} 170}
290 171
291int via_mem_free(DRM_IOCTL_ARGS) 172int via_mem_free(DRM_IOCTL_ARGS)
292{ 173{
174 DRM_DEVICE;
175 drm_via_private_t *dev_priv = dev->dev_private;
293 drm_via_mem_t mem; 176 drm_via_mem_t mem;
177 int ret;
294 178
295 DRM_COPY_FROM_USER_IOCTL(mem, (drm_via_mem_t __user *) data, 179 DRM_COPY_FROM_USER_IOCTL(mem, (drm_via_mem_t __user *) data,
296 sizeof(mem)); 180 sizeof(mem));
297 181
298 switch (mem.type) { 182 mutex_lock(&dev->struct_mutex);
183 ret = drm_sman_free_key(&dev_priv->sman, mem.index);
184 mutex_unlock(&dev->struct_mutex);
185 DRM_DEBUG("free = 0x%lx\n", mem.index);
299 186
300 case VIA_MEM_VIDEO: 187 return ret;
301 if (via_fb_free(&mem) == 0)
302 return 0;
303 break;
304 case VIA_MEM_AGP:
305 if (via_agp_free(&mem) == 0)
306 return 0;
307 break;
308 }
309
310 return -EFAULT;
311} 188}
312 189
313static int via_fb_free(drm_via_mem_t * mem)
314{
315 drm_via_mm_t fb;
316 int retval = 0;
317
318 if (!FBHeap) {
319 return -1;
320 }
321
322 fb.free = mem->index;
323 fb.context = mem->context;
324
325 if (!fb.free) {
326 return -1;
327
328 }
329
330 via_mmFreeMem((PMemBlock) fb.free);
331
332 if (!del_alloc_set(fb.context, VIA_MEM_VIDEO, fb.free)) {
333 retval = -1;
334 }
335
336 DRM_DEBUG("free fb, free = %ld\n", fb.free);
337 190
338 return retval; 191void via_reclaim_buffers_locked(drm_device_t * dev, struct file *filp)
339}
340
341static int via_agp_free(drm_via_mem_t * mem)
342{ 192{
343 drm_via_mm_t agp; 193 drm_via_private_t *dev_priv = dev->dev_private;
344 194 drm_file_t *priv = filp->private_data;
345 int retval = 0;
346 195
347 agp.free = mem->index; 196 mutex_lock(&dev->struct_mutex);
348 agp.context = mem->context; 197 if (drm_sman_owner_clean(&dev_priv->sman, (unsigned long)priv)) {
349 198 mutex_unlock(&dev->struct_mutex);
350 if (!agp.free) 199 return;
351 return -1;
352
353 via_mmFreeMem((PMemBlock) agp.free);
354
355 if (!del_alloc_set(agp.context, VIA_MEM_AGP, agp.free)) {
356 retval = -1;
357 } 200 }
358 201
359 DRM_DEBUG("free agp, free = %ld\n", agp.free); 202 if (dev->driver->dma_quiescent) {
203 dev->driver->dma_quiescent(dev);
204 }
360 205
361 return retval; 206 drm_sman_owner_cleanup(&dev_priv->sman, (unsigned long)priv);
207 mutex_unlock(&dev->struct_mutex);
208 return;
362} 209}
diff --git a/drivers/char/ds1286.c b/drivers/char/ds1286.c
index 21c8229f5443..6d58b0370802 100644
--- a/drivers/char/ds1286.c
+++ b/drivers/char/ds1286.c
@@ -104,7 +104,7 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
104 switch (cmd) { 104 switch (cmd) {
105 case RTC_AIE_OFF: /* Mask alarm int. enab. bit */ 105 case RTC_AIE_OFF: /* Mask alarm int. enab. bit */
106 { 106 {
107 unsigned int flags; 107 unsigned long flags;
108 unsigned char val; 108 unsigned char val;
109 109
110 if (!capable(CAP_SYS_TIME)) 110 if (!capable(CAP_SYS_TIME))
@@ -120,7 +120,7 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
120 } 120 }
121 case RTC_AIE_ON: /* Allow alarm interrupts. */ 121 case RTC_AIE_ON: /* Allow alarm interrupts. */
122 { 122 {
123 unsigned int flags; 123 unsigned long flags;
124 unsigned char val; 124 unsigned char val;
125 125
126 if (!capable(CAP_SYS_TIME)) 126 if (!capable(CAP_SYS_TIME))
@@ -136,7 +136,7 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
136 } 136 }
137 case RTC_WIE_OFF: /* Mask watchdog int. enab. bit */ 137 case RTC_WIE_OFF: /* Mask watchdog int. enab. bit */
138 { 138 {
139 unsigned int flags; 139 unsigned long flags;
140 unsigned char val; 140 unsigned char val;
141 141
142 if (!capable(CAP_SYS_TIME)) 142 if (!capable(CAP_SYS_TIME))
@@ -152,7 +152,7 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
152 } 152 }
153 case RTC_WIE_ON: /* Allow watchdog interrupts. */ 153 case RTC_WIE_ON: /* Allow watchdog interrupts. */
154 { 154 {
155 unsigned int flags; 155 unsigned long flags;
156 unsigned char val; 156 unsigned char val;
157 157
158 if (!capable(CAP_SYS_TIME)) 158 if (!capable(CAP_SYS_TIME))
@@ -434,7 +434,7 @@ static inline unsigned char ds1286_is_updating(void)
434static void ds1286_get_time(struct rtc_time *rtc_tm) 434static void ds1286_get_time(struct rtc_time *rtc_tm)
435{ 435{
436 unsigned char save_control; 436 unsigned char save_control;
437 unsigned int flags; 437 unsigned long flags;
438 unsigned long uip_watchdog = jiffies; 438 unsigned long uip_watchdog = jiffies;
439 439
440 /* 440 /*
@@ -494,7 +494,8 @@ static int ds1286_set_time(struct rtc_time *rtc_tm)
494{ 494{
495 unsigned char mon, day, hrs, min, sec, leap_yr; 495 unsigned char mon, day, hrs, min, sec, leap_yr;
496 unsigned char save_control; 496 unsigned char save_control;
497 unsigned int yrs, flags; 497 unsigned int yrs;
498 unsigned long flags;
498 499
499 500
500 yrs = rtc_tm->tm_year + 1900; 501 yrs = rtc_tm->tm_year + 1900;
@@ -552,7 +553,7 @@ static int ds1286_set_time(struct rtc_time *rtc_tm)
552static void ds1286_get_alm_time(struct rtc_time *alm_tm) 553static void ds1286_get_alm_time(struct rtc_time *alm_tm)
553{ 554{
554 unsigned char cmd; 555 unsigned char cmd;
555 unsigned int flags; 556 unsigned long flags;
556 557
557 /* 558 /*
558 * Only the values that we read from the RTC are set. That 559 * Only the values that we read from the RTC are set. That
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index 86d290e9f307..3baa2ab8cbd4 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -1125,7 +1125,7 @@ static void __exit epca_module_exit(void)
1125 1125
1126module_exit(epca_module_exit); 1126module_exit(epca_module_exit);
1127 1127
1128static struct tty_operations pc_ops = { 1128static const struct tty_operations pc_ops = {
1129 .open = pc_open, 1129 .open = pc_open,
1130 .close = pc_close, 1130 .close = pc_close,
1131 .write = pc_write, 1131 .write = pc_write,
diff --git a/drivers/char/esp.c b/drivers/char/esp.c
index afcd83d9984b..05788c75d7fc 100644
--- a/drivers/char/esp.c
+++ b/drivers/char/esp.c
@@ -2376,7 +2376,7 @@ static inline int autoconfig(struct esp_struct * info)
2376 return (port_detected); 2376 return (port_detected);
2377} 2377}
2378 2378
2379static struct tty_operations esp_ops = { 2379static const struct tty_operations esp_ops = {
2380 .open = esp_open, 2380 .open = esp_open,
2381 .close = rs_close, 2381 .close = rs_close,
2382 .write = rs_write, 2382 .write = rs_write,
diff --git a/drivers/char/generic_serial.c b/drivers/char/generic_serial.c
index 5e59c0b42731..4711d9b3a595 100644
--- a/drivers/char/generic_serial.c
+++ b/drivers/char/generic_serial.c
@@ -746,11 +746,9 @@ void gs_set_termios (struct tty_struct * tty,
746 gs_dprintk (GS_DEBUG_TERMIOS, "termios structure (%p):\n", tiosp); 746 gs_dprintk (GS_DEBUG_TERMIOS, "termios structure (%p):\n", tiosp);
747 } 747 }
748 748
749#if 0
750 /* This is an optimization that is only allowed for dumb cards */ 749 /* This is an optimization that is only allowed for dumb cards */
751 /* Smart cards require knowledge of iflags and oflags too: that 750 /* Smart cards require knowledge of iflags and oflags too: that
752 might change hardware cooking mode.... */ 751 might change hardware cooking mode.... */
753#endif
754 if (old_termios) { 752 if (old_termios) {
755 if( (tiosp->c_iflag == old_termios->c_iflag) 753 if( (tiosp->c_iflag == old_termios->c_iflag)
756 && (tiosp->c_oflag == old_termios->c_oflag) 754 && (tiosp->c_oflag == old_termios->c_oflag)
@@ -774,14 +772,7 @@ void gs_set_termios (struct tty_struct * tty,
774 if(!memcmp(tiosp->c_cc, old_termios->c_cc, NCC)) printk("c_cc changed\n"); 772 if(!memcmp(tiosp->c_cc, old_termios->c_cc, NCC)) printk("c_cc changed\n");
775 } 773 }
776 774
777 baudrate = tiosp->c_cflag & CBAUD; 775 baudrate = tty_get_baud_rate(tty);
778 if (baudrate & CBAUDEX) {
779 baudrate &= ~CBAUDEX;
780 if ((baudrate < 1) || (baudrate > 4))
781 tiosp->c_cflag &= ~CBAUDEX;
782 else
783 baudrate += 15;
784 }
785 776
786 baudrate = gs_baudrates[baudrate]; 777 baudrate = gs_baudrates[baudrate];
787 if ((tiosp->c_cflag & CBAUD) == B38400) { 778 if ((tiosp->c_cflag & CBAUD) == B38400) {
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index 8afba339f05a..58b0eb581114 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -868,8 +868,8 @@ int hpet_alloc(struct hpet_data *hdp)
868 do_div(temp, period); 868 do_div(temp, period);
869 hpetp->hp_tick_freq = temp; /* ticks per second */ 869 hpetp->hp_tick_freq = temp; /* ticks per second */
870 870
871 printk(KERN_INFO "hpet%d: at MMIO 0x%lx (virtual 0x%p), IRQ%s", 871 printk(KERN_INFO "hpet%d: at MMIO 0x%lx, IRQ%s",
872 hpetp->hp_which, hdp->hd_phys_address, hdp->hd_address, 872 hpetp->hp_which, hdp->hd_phys_address,
873 hpetp->hp_ntimer > 1 ? "s" : ""); 873 hpetp->hp_ntimer > 1 ? "s" : "");
874 for (i = 0; i < hpetp->hp_ntimer; i++) 874 for (i = 0; i < hpetp->hp_ntimer; i++)
875 printk("%s %d", i > 0 ? "," : "", hdp->hd_irq[i]); 875 printk("%s %d", i > 0 ? "," : "", hdp->hd_irq[i]);
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index a76d2c40dd5e..4053d1cd393f 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -696,7 +696,7 @@ int khvcd(void *unused)
696 return 0; 696 return 0;
697} 697}
698 698
699static struct tty_operations hvc_ops = { 699static const struct tty_operations hvc_ops = {
700 .open = hvc_open, 700 .open = hvc_open,
701 .close = hvc_close, 701 .close = hvc_close,
702 .write = hvc_write, 702 .write = hvc_write,
diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
index 4589ff302b07..0b89bcde8c52 100644
--- a/drivers/char/hvcs.c
+++ b/drivers/char/hvcs.c
@@ -1306,7 +1306,7 @@ static int hvcs_chars_in_buffer(struct tty_struct *tty)
1306 return hvcsd->chars_in_buffer; 1306 return hvcsd->chars_in_buffer;
1307} 1307}
1308 1308
1309static struct tty_operations hvcs_ops = { 1309static const struct tty_operations hvcs_ops = {
1310 .open = hvcs_open, 1310 .open = hvcs_open,
1311 .close = hvcs_close, 1311 .close = hvcs_close,
1312 .hangup = hvcs_hangup, 1312 .hangup = hvcs_hangup,
diff --git a/drivers/char/hvsi.c b/drivers/char/hvsi.c
index a89a95fb5e40..c07dc58d5c1d 100644
--- a/drivers/char/hvsi.c
+++ b/drivers/char/hvsi.c
@@ -1130,7 +1130,7 @@ static int hvsi_tiocmset(struct tty_struct *tty, struct file *file,
1130} 1130}
1131 1131
1132 1132
1133static struct tty_operations hvsi_ops = { 1133static const struct tty_operations hvsi_ops = {
1134 .open = hvsi_open, 1134 .open = hvsi_open,
1135 .close = hvsi_close, 1135 .close = hvsi_close,
1136 .write = hvsi_write, 1136 .write = hvsi_write,
diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
index ccd7e7102234..8efbc9c0e545 100644
--- a/drivers/char/hw_random/intel-rng.c
+++ b/drivers/char/hw_random/intel-rng.c
@@ -50,6 +50,43 @@
50#define INTEL_RNG_ADDR_LEN 3 50#define INTEL_RNG_ADDR_LEN 3
51 51
52/* 52/*
53 * LPC bridge PCI config space registers
54 */
55#define FWH_DEC_EN1_REG_OLD 0xe3
56#define FWH_DEC_EN1_REG_NEW 0xd9 /* high byte of 16-bit register */
57#define FWH_F8_EN_MASK 0x80
58
59#define BIOS_CNTL_REG_OLD 0x4e
60#define BIOS_CNTL_REG_NEW 0xdc
61#define BIOS_CNTL_WRITE_ENABLE_MASK 0x01
62#define BIOS_CNTL_LOCK_ENABLE_MASK 0x02
63
64/*
65 * Magic address at which Intel Firmware Hubs get accessed
66 */
67#define INTEL_FWH_ADDR 0xffff0000
68#define INTEL_FWH_ADDR_LEN 2
69
70/*
71 * Intel Firmware Hub command codes (write to any address inside the device)
72 */
73#define INTEL_FWH_RESET_CMD 0xff /* aka READ_ARRAY */
74#define INTEL_FWH_READ_ID_CMD 0x90
75
76/*
77 * Intel Firmware Hub Read ID command result addresses
78 */
79#define INTEL_FWH_MANUFACTURER_CODE_ADDRESS 0x000000
80#define INTEL_FWH_DEVICE_CODE_ADDRESS 0x000001
81
82/*
83 * Intel Firmware Hub Read ID command result values
84 */
85#define INTEL_FWH_MANUFACTURER_CODE 0x89
86#define INTEL_FWH_DEVICE_CODE_8M 0xac
87#define INTEL_FWH_DEVICE_CODE_4M 0xad
88
89/*
53 * Data for PCI driver interface 90 * Data for PCI driver interface
54 * 91 *
55 * This data only exists for exporting the supported 92 * This data only exists for exporting the supported
@@ -58,12 +95,50 @@
58 * want to register another driver on the same PCI id. 95 * want to register another driver on the same PCI id.
59 */ 96 */
60static const struct pci_device_id pci_tbl[] = { 97static const struct pci_device_id pci_tbl[] = {
61 { 0x8086, 0x2418, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 98/* AA
62 { 0x8086, 0x2428, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 99 { 0x8086, 0x2418, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
63 { 0x8086, 0x2430, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 100 { 0x8086, 0x2410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* AA */
64 { 0x8086, 0x2448, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 101/* AB
65 { 0x8086, 0x244e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 102 { 0x8086, 0x2428, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
66 { 0x8086, 0x245e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 103 { 0x8086, 0x2420, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* AB */
104/* ??
105 { 0x8086, 0x2430, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
106/* BAM, CAM, DBM, FBM, GxM
107 { 0x8086, 0x2448, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
108 { 0x8086, 0x244c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* BAM */
109 { 0x8086, 0x248c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CAM */
110 { 0x8086, 0x24cc, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* DBM */
111 { 0x8086, 0x2641, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* FBM */
112 { 0x8086, 0x27b9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* GxM */
113 { 0x8086, 0x27bd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* GxM DH */
114/* BA, CA, DB, Ex, 6300, Fx, 631x/632x, Gx
115 { 0x8086, 0x244e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
116 { 0x8086, 0x2440, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* BA */
117 { 0x8086, 0x2480, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CA */
118 { 0x8086, 0x24c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* DB */
119 { 0x8086, 0x24d0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Ex */
120 { 0x8086, 0x25a1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 6300 */
121 { 0x8086, 0x2640, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Fx */
122 { 0x8086, 0x2670, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
123 { 0x8086, 0x2671, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
124 { 0x8086, 0x2672, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
125 { 0x8086, 0x2673, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
126 { 0x8086, 0x2674, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
127 { 0x8086, 0x2675, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
128 { 0x8086, 0x2676, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
129 { 0x8086, 0x2677, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
130 { 0x8086, 0x2678, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
131 { 0x8086, 0x2679, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
132 { 0x8086, 0x267a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
133 { 0x8086, 0x267b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
134 { 0x8086, 0x267c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
135 { 0x8086, 0x267d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
136 { 0x8086, 0x267e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
137 { 0x8086, 0x267f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
138 { 0x8086, 0x27b8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Gx */
139/* E
140 { 0x8086, 0x245e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
141 { 0x8086, 0x2450, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* E */
67 { 0, }, /* terminate list */ 142 { 0, }, /* terminate list */
68}; 143};
69MODULE_DEVICE_TABLE(pci, pci_tbl); 144MODULE_DEVICE_TABLE(pci, pci_tbl);
@@ -138,22 +213,115 @@ static struct hwrng intel_rng = {
138}; 213};
139 214
140 215
216#ifdef CONFIG_SMP
217static char __initdata waitflag;
218
219static void __init intel_init_wait(void *unused)
220{
221 while (waitflag)
222 cpu_relax();
223}
224#endif
225
141static int __init mod_init(void) 226static int __init mod_init(void)
142{ 227{
143 int err = -ENODEV; 228 int err = -ENODEV;
229 unsigned i;
230 struct pci_dev *dev = NULL;
144 void __iomem *mem; 231 void __iomem *mem;
145 u8 hw_status; 232 unsigned long flags;
233 u8 bios_cntl_off, fwh_dec_en1_off;
234 u8 bios_cntl_val = 0xff, fwh_dec_en1_val = 0xff;
235 u8 hw_status, mfc, dvc;
146 236
147 if (!pci_dev_present(pci_tbl)) 237 for (i = 0; !dev && pci_tbl[i].vendor; ++i)
238 dev = pci_get_device(pci_tbl[i].vendor, pci_tbl[i].device, NULL);
239
240 if (!dev)
148 goto out; /* Device not found. */ 241 goto out; /* Device not found. */
149 242
243 /* Check for Intel 82802 */
244 if (dev->device < 0x2640) {
245 fwh_dec_en1_off = FWH_DEC_EN1_REG_OLD;
246 bios_cntl_off = BIOS_CNTL_REG_OLD;
247 } else {
248 fwh_dec_en1_off = FWH_DEC_EN1_REG_NEW;
249 bios_cntl_off = BIOS_CNTL_REG_NEW;
250 }
251
252 pci_read_config_byte(dev, fwh_dec_en1_off, &fwh_dec_en1_val);
253 pci_read_config_byte(dev, bios_cntl_off, &bios_cntl_val);
254
255 mem = ioremap_nocache(INTEL_FWH_ADDR, INTEL_FWH_ADDR_LEN);
256 if (mem == NULL) {
257 pci_dev_put(dev);
258 err = -EBUSY;
259 goto out;
260 }
261
262 /*
263 * Since the BIOS code/data is going to disappear from its normal
264 * location with the Read ID command, all activity on the system
265 * must be stopped until the state is back to normal.
266 */
267#ifdef CONFIG_SMP
268 set_mb(waitflag, 1);
269 if (smp_call_function(intel_init_wait, NULL, 1, 0) != 0) {
270 set_mb(waitflag, 0);
271 pci_dev_put(dev);
272 printk(KERN_ERR PFX "cannot run on all processors\n");
273 err = -EAGAIN;
274 goto err_unmap;
275 }
276#endif
277 local_irq_save(flags);
278
279 if (!(fwh_dec_en1_val & FWH_F8_EN_MASK))
280 pci_write_config_byte(dev,
281 fwh_dec_en1_off,
282 fwh_dec_en1_val | FWH_F8_EN_MASK);
283 if (!(bios_cntl_val &
284 (BIOS_CNTL_LOCK_ENABLE_MASK|BIOS_CNTL_WRITE_ENABLE_MASK)))
285 pci_write_config_byte(dev,
286 bios_cntl_off,
287 bios_cntl_val | BIOS_CNTL_WRITE_ENABLE_MASK);
288
289 writeb(INTEL_FWH_RESET_CMD, mem);
290 writeb(INTEL_FWH_READ_ID_CMD, mem);
291 mfc = readb(mem + INTEL_FWH_MANUFACTURER_CODE_ADDRESS);
292 dvc = readb(mem + INTEL_FWH_DEVICE_CODE_ADDRESS);
293 writeb(INTEL_FWH_RESET_CMD, mem);
294
295 if (!(bios_cntl_val &
296 (BIOS_CNTL_LOCK_ENABLE_MASK|BIOS_CNTL_WRITE_ENABLE_MASK)))
297 pci_write_config_byte(dev, bios_cntl_off, bios_cntl_val);
298 if (!(fwh_dec_en1_val & FWH_F8_EN_MASK))
299 pci_write_config_byte(dev, fwh_dec_en1_off, fwh_dec_en1_val);
300
301 local_irq_restore(flags);
302#ifdef CONFIG_SMP
303 /* Tell other CPUs to resume. */
304 set_mb(waitflag, 0);
305#endif
306
307 iounmap(mem);
308 pci_dev_put(dev);
309
310 if (mfc != INTEL_FWH_MANUFACTURER_CODE ||
311 (dvc != INTEL_FWH_DEVICE_CODE_8M &&
312 dvc != INTEL_FWH_DEVICE_CODE_4M)) {
313 printk(KERN_ERR PFX "FWH not detected\n");
314 err = -ENODEV;
315 goto out;
316 }
317
150 err = -ENOMEM; 318 err = -ENOMEM;
151 mem = ioremap(INTEL_RNG_ADDR, INTEL_RNG_ADDR_LEN); 319 mem = ioremap(INTEL_RNG_ADDR, INTEL_RNG_ADDR_LEN);
152 if (!mem) 320 if (!mem)
153 goto out; 321 goto out;
154 intel_rng.priv = (unsigned long)mem; 322 intel_rng.priv = (unsigned long)mem;
155 323
156 /* Check for Intel 82802 */ 324 /* Check for Random Number Generator */
157 err = -ENODEV; 325 err = -ENODEV;
158 hw_status = hwstatus_get(mem); 326 hw_status = hwstatus_get(mem);
159 if ((hw_status & INTEL_RNG_PRESENT) == 0) 327 if ((hw_status & INTEL_RNG_PRESENT) == 0)
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c
index 7907ae88c2f4..62ef511d143b 100644
--- a/drivers/char/ip2/ip2main.c
+++ b/drivers/char/ip2/ip2main.c
@@ -436,6 +436,7 @@ cleanup_module(void)
436#ifdef CONFIG_PCI 436#ifdef CONFIG_PCI
437 if (ip2config.type[i] == PCI && ip2config.pci_dev[i]) { 437 if (ip2config.type[i] == PCI && ip2config.pci_dev[i]) {
438 pci_disable_device(ip2config.pci_dev[i]); 438 pci_disable_device(ip2config.pci_dev[i]);
439 pci_dev_put(ip2config.pci_dev[i]);
439 ip2config.pci_dev[i] = NULL; 440 ip2config.pci_dev[i] = NULL;
440 } 441 }
441#endif 442#endif
@@ -457,7 +458,7 @@ cleanup_module(void)
457} 458}
458#endif /* MODULE */ 459#endif /* MODULE */
459 460
460static struct tty_operations ip2_ops = { 461static const struct tty_operations ip2_ops = {
461 .open = ip2_open, 462 .open = ip2_open,
462 .close = ip2_close, 463 .close = ip2_close,
463 .write = ip2_write, 464 .write = ip2_write,
@@ -505,6 +506,7 @@ ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
505 static int loaded; 506 static int loaded;
506 i2eBordStrPtr pB = NULL; 507 i2eBordStrPtr pB = NULL;
507 int rc = -1; 508 int rc = -1;
509 static struct pci_dev *pci_dev_i = NULL;
508 510
509 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_ENTER, 0 ); 511 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_ENTER, 0 );
510 512
@@ -588,8 +590,7 @@ ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
588 case PCI: 590 case PCI:
589#ifdef CONFIG_PCI 591#ifdef CONFIG_PCI
590 { 592 {
591 struct pci_dev *pci_dev_i = NULL; 593 pci_dev_i = pci_get_device(PCI_VENDOR_ID_COMPUTONE,
592 pci_dev_i = pci_find_device(PCI_VENDOR_ID_COMPUTONE,
593 PCI_DEVICE_ID_COMPUTONE_IP2EX, pci_dev_i); 594 PCI_DEVICE_ID_COMPUTONE_IP2EX, pci_dev_i);
594 if (pci_dev_i != NULL) { 595 if (pci_dev_i != NULL) {
595 unsigned int addr; 596 unsigned int addr;
@@ -600,7 +601,7 @@ ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
600 break; 601 break;
601 } 602 }
602 ip2config.type[i] = PCI; 603 ip2config.type[i] = PCI;
603 ip2config.pci_dev[i] = pci_dev_i; 604 ip2config.pci_dev[i] = pci_dev_get(pci_dev_i);
604 status = 605 status =
605 pci_read_config_dword(pci_dev_i, PCI_BASE_ADDRESS_1, &addr); 606 pci_read_config_dword(pci_dev_i, PCI_BASE_ADDRESS_1, &addr);
606 if ( addr & 1 ) { 607 if ( addr & 1 ) {
@@ -641,6 +642,9 @@ ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
641 break; 642 break;
642 } /* switch */ 643 } /* switch */
643 } /* for */ 644 } /* for */
645 if (pci_dev_i)
646 pci_dev_put(pci_dev_i);
647
644 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) { 648 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
645 if ( ip2config.addr[i] ) { 649 if ( ip2config.addr[i] ) {
646 pB = kmalloc( sizeof(i2eBordStr), GFP_KERNEL); 650 pB = kmalloc( sizeof(i2eBordStr), GFP_KERNEL);
@@ -775,8 +779,6 @@ retry:
775 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_RETURN, 0 ); 779 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_RETURN, 0 );
776 goto out; 780 goto out;
777 781
778out_class:
779 class_destroy(ip2_class);
780out_chrdev: 782out_chrdev:
781 unregister_chrdev(IP2_IPL_MAJOR, "ip2"); 783 unregister_chrdev(IP2_IPL_MAJOR, "ip2");
782out: 784out:
diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
index 68d7c61a864e..81fcf0ce21d1 100644
--- a/drivers/char/ipmi/ipmi_devintf.c
+++ b/drivers/char/ipmi/ipmi_devintf.c
@@ -377,7 +377,8 @@ static int ipmi_ioctl(struct inode *inode,
377 break; 377 break;
378 } 378 }
379 379
380 rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd); 380 rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd,
381 IPMI_CHAN_ALL);
381 break; 382 break;
382 } 383 }
383 384
@@ -390,7 +391,36 @@ static int ipmi_ioctl(struct inode *inode,
390 break; 391 break;
391 } 392 }
392 393
393 rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd); 394 rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd,
395 IPMI_CHAN_ALL);
396 break;
397 }
398
399 case IPMICTL_REGISTER_FOR_CMD_CHANS:
400 {
401 struct ipmi_cmdspec_chans val;
402
403 if (copy_from_user(&val, arg, sizeof(val))) {
404 rv = -EFAULT;
405 break;
406 }
407
408 rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd,
409 val.chans);
410 break;
411 }
412
413 case IPMICTL_UNREGISTER_FOR_CMD_CHANS:
414 {
415 struct ipmi_cmdspec_chans val;
416
417 if (copy_from_user(&val, arg, sizeof(val))) {
418 rv = -EFAULT;
419 break;
420 }
421
422 rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd,
423 val.chans);
394 break; 424 break;
395 } 425 }
396 426
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 843d34c8627c..2455e8d478ac 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -96,6 +96,7 @@ struct cmd_rcvr
96 ipmi_user_t user; 96 ipmi_user_t user;
97 unsigned char netfn; 97 unsigned char netfn;
98 unsigned char cmd; 98 unsigned char cmd;
99 unsigned int chans;
99 100
100 /* 101 /*
101 * This is used to form a linked lised during mass deletion. 102 * This is used to form a linked lised during mass deletion.
@@ -953,24 +954,41 @@ int ipmi_set_gets_events(ipmi_user_t user, int val)
953 954
954static struct cmd_rcvr *find_cmd_rcvr(ipmi_smi_t intf, 955static struct cmd_rcvr *find_cmd_rcvr(ipmi_smi_t intf,
955 unsigned char netfn, 956 unsigned char netfn,
956 unsigned char cmd) 957 unsigned char cmd,
958 unsigned char chan)
957{ 959{
958 struct cmd_rcvr *rcvr; 960 struct cmd_rcvr *rcvr;
959 961
960 list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { 962 list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) {
961 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)) 963 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)
964 && (rcvr->chans & (1 << chan)))
962 return rcvr; 965 return rcvr;
963 } 966 }
964 return NULL; 967 return NULL;
965} 968}
966 969
970static int is_cmd_rcvr_exclusive(ipmi_smi_t intf,
971 unsigned char netfn,
972 unsigned char cmd,
973 unsigned int chans)
974{
975 struct cmd_rcvr *rcvr;
976
977 list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) {
978 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)
979 && (rcvr->chans & chans))
980 return 0;
981 }
982 return 1;
983}
984
967int ipmi_register_for_cmd(ipmi_user_t user, 985int ipmi_register_for_cmd(ipmi_user_t user,
968 unsigned char netfn, 986 unsigned char netfn,
969 unsigned char cmd) 987 unsigned char cmd,
988 unsigned int chans)
970{ 989{
971 ipmi_smi_t intf = user->intf; 990 ipmi_smi_t intf = user->intf;
972 struct cmd_rcvr *rcvr; 991 struct cmd_rcvr *rcvr;
973 struct cmd_rcvr *entry;
974 int rv = 0; 992 int rv = 0;
975 993
976 994
@@ -979,12 +997,12 @@ int ipmi_register_for_cmd(ipmi_user_t user,
979 return -ENOMEM; 997 return -ENOMEM;
980 rcvr->cmd = cmd; 998 rcvr->cmd = cmd;
981 rcvr->netfn = netfn; 999 rcvr->netfn = netfn;
1000 rcvr->chans = chans;
982 rcvr->user = user; 1001 rcvr->user = user;
983 1002
984 mutex_lock(&intf->cmd_rcvrs_mutex); 1003 mutex_lock(&intf->cmd_rcvrs_mutex);
985 /* Make sure the command/netfn is not already registered. */ 1004 /* Make sure the command/netfn is not already registered. */
986 entry = find_cmd_rcvr(intf, netfn, cmd); 1005 if (!is_cmd_rcvr_exclusive(intf, netfn, cmd, chans)) {
987 if (entry) {
988 rv = -EBUSY; 1006 rv = -EBUSY;
989 goto out_unlock; 1007 goto out_unlock;
990 } 1008 }
@@ -1001,24 +1019,39 @@ int ipmi_register_for_cmd(ipmi_user_t user,
1001 1019
1002int ipmi_unregister_for_cmd(ipmi_user_t user, 1020int ipmi_unregister_for_cmd(ipmi_user_t user,
1003 unsigned char netfn, 1021 unsigned char netfn,
1004 unsigned char cmd) 1022 unsigned char cmd,
1023 unsigned int chans)
1005{ 1024{
1006 ipmi_smi_t intf = user->intf; 1025 ipmi_smi_t intf = user->intf;
1007 struct cmd_rcvr *rcvr; 1026 struct cmd_rcvr *rcvr;
1027 struct cmd_rcvr *rcvrs = NULL;
1028 int i, rv = -ENOENT;
1008 1029
1009 mutex_lock(&intf->cmd_rcvrs_mutex); 1030 mutex_lock(&intf->cmd_rcvrs_mutex);
1010 /* Make sure the command/netfn is not already registered. */ 1031 for (i = 0; i < IPMI_NUM_CHANNELS; i++) {
1011 rcvr = find_cmd_rcvr(intf, netfn, cmd); 1032 if (((1 << i) & chans) == 0)
1012 if ((rcvr) && (rcvr->user == user)) { 1033 continue;
1013 list_del_rcu(&rcvr->link); 1034 rcvr = find_cmd_rcvr(intf, netfn, cmd, i);
1014 mutex_unlock(&intf->cmd_rcvrs_mutex); 1035 if (rcvr == NULL)
1015 synchronize_rcu(); 1036 continue;
1037 if (rcvr->user == user) {
1038 rv = 0;
1039 rcvr->chans &= ~chans;
1040 if (rcvr->chans == 0) {
1041 list_del_rcu(&rcvr->link);
1042 rcvr->next = rcvrs;
1043 rcvrs = rcvr;
1044 }
1045 }
1046 }
1047 mutex_unlock(&intf->cmd_rcvrs_mutex);
1048 synchronize_rcu();
1049 while (rcvrs) {
1050 rcvr = rcvrs;
1051 rcvrs = rcvr->next;
1016 kfree(rcvr); 1052 kfree(rcvr);
1017 return 0;
1018 } else {
1019 mutex_unlock(&intf->cmd_rcvrs_mutex);
1020 return -ENOENT;
1021 } 1053 }
1054 return rv;
1022} 1055}
1023 1056
1024void ipmi_user_set_run_to_completion(ipmi_user_t user, int val) 1057void ipmi_user_set_run_to_completion(ipmi_user_t user, int val)
@@ -2548,6 +2581,7 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
2548 int rv = 0; 2581 int rv = 0;
2549 unsigned char netfn; 2582 unsigned char netfn;
2550 unsigned char cmd; 2583 unsigned char cmd;
2584 unsigned char chan;
2551 ipmi_user_t user = NULL; 2585 ipmi_user_t user = NULL;
2552 struct ipmi_ipmb_addr *ipmb_addr; 2586 struct ipmi_ipmb_addr *ipmb_addr;
2553 struct ipmi_recv_msg *recv_msg; 2587 struct ipmi_recv_msg *recv_msg;
@@ -2568,9 +2602,10 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
2568 2602
2569 netfn = msg->rsp[4] >> 2; 2603 netfn = msg->rsp[4] >> 2;
2570 cmd = msg->rsp[8]; 2604 cmd = msg->rsp[8];
2605 chan = msg->rsp[3] & 0xf;
2571 2606
2572 rcu_read_lock(); 2607 rcu_read_lock();
2573 rcvr = find_cmd_rcvr(intf, netfn, cmd); 2608 rcvr = find_cmd_rcvr(intf, netfn, cmd, chan);
2574 if (rcvr) { 2609 if (rcvr) {
2575 user = rcvr->user; 2610 user = rcvr->user;
2576 kref_get(&user->refcount); 2611 kref_get(&user->refcount);
@@ -2728,6 +2763,7 @@ static int handle_lan_get_msg_cmd(ipmi_smi_t intf,
2728 int rv = 0; 2763 int rv = 0;
2729 unsigned char netfn; 2764 unsigned char netfn;
2730 unsigned char cmd; 2765 unsigned char cmd;
2766 unsigned char chan;
2731 ipmi_user_t user = NULL; 2767 ipmi_user_t user = NULL;
2732 struct ipmi_lan_addr *lan_addr; 2768 struct ipmi_lan_addr *lan_addr;
2733 struct ipmi_recv_msg *recv_msg; 2769 struct ipmi_recv_msg *recv_msg;
@@ -2748,9 +2784,10 @@ static int handle_lan_get_msg_cmd(ipmi_smi_t intf,
2748 2784
2749 netfn = msg->rsp[6] >> 2; 2785 netfn = msg->rsp[6] >> 2;
2750 cmd = msg->rsp[10]; 2786 cmd = msg->rsp[10];
2787 chan = msg->rsp[3] & 0xf;
2751 2788
2752 rcu_read_lock(); 2789 rcu_read_lock();
2753 rcvr = find_cmd_rcvr(intf, netfn, cmd); 2790 rcvr = find_cmd_rcvr(intf, netfn, cmd, chan);
2754 if (rcvr) { 2791 if (rcvr) {
2755 user = rcvr->user; 2792 user = rcvr->user;
2756 kref_get(&user->refcount); 2793 kref_get(&user->refcount);
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index abca98beac14..b106c45abfc9 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -217,6 +217,11 @@ struct smi_info
217 struct list_head link; 217 struct list_head link;
218}; 218};
219 219
220#define SI_MAX_PARMS 4
221
222static int force_kipmid[SI_MAX_PARMS];
223static int num_force_kipmid;
224
220static int try_smi_init(struct smi_info *smi); 225static int try_smi_init(struct smi_info *smi);
221 226
222static ATOMIC_NOTIFIER_HEAD(xaction_notifier_list); 227static ATOMIC_NOTIFIER_HEAD(xaction_notifier_list);
@@ -908,6 +913,7 @@ static int smi_start_processing(void *send_info,
908 ipmi_smi_t intf) 913 ipmi_smi_t intf)
909{ 914{
910 struct smi_info *new_smi = send_info; 915 struct smi_info *new_smi = send_info;
916 int enable = 0;
911 917
912 new_smi->intf = intf; 918 new_smi->intf = intf;
913 919
@@ -916,7 +922,19 @@ static int smi_start_processing(void *send_info,
916 new_smi->last_timeout_jiffies = jiffies; 922 new_smi->last_timeout_jiffies = jiffies;
917 mod_timer(&new_smi->si_timer, jiffies + SI_TIMEOUT_JIFFIES); 923 mod_timer(&new_smi->si_timer, jiffies + SI_TIMEOUT_JIFFIES);
918 924
919 if (new_smi->si_type != SI_BT) { 925 /*
926 * Check if the user forcefully enabled the daemon.
927 */
928 if (new_smi->intf_num < num_force_kipmid)
929 enable = force_kipmid[new_smi->intf_num];
930 /*
931 * The BT interface is efficient enough to not need a thread,
932 * and there is no need for a thread if we have interrupts.
933 */
934 else if ((new_smi->si_type != SI_BT) && (!new_smi->irq))
935 enable = 1;
936
937 if (enable) {
920 new_smi->thread = kthread_run(ipmi_thread, new_smi, 938 new_smi->thread = kthread_run(ipmi_thread, new_smi,
921 "kipmi%d", new_smi->intf_num); 939 "kipmi%d", new_smi->intf_num);
922 if (IS_ERR(new_smi->thread)) { 940 if (IS_ERR(new_smi->thread)) {
@@ -944,7 +962,6 @@ static struct ipmi_smi_handlers handlers =
944/* There can be 4 IO ports passed in (with or without IRQs), 4 addresses, 962/* There can be 4 IO ports passed in (with or without IRQs), 4 addresses,
945 a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS */ 963 a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS */
946 964
947#define SI_MAX_PARMS 4
948static LIST_HEAD(smi_infos); 965static LIST_HEAD(smi_infos);
949static DEFINE_MUTEX(smi_infos_lock); 966static DEFINE_MUTEX(smi_infos_lock);
950static int smi_num; /* Used to sequence the SMIs */ 967static int smi_num; /* Used to sequence the SMIs */
@@ -1017,6 +1034,10 @@ MODULE_PARM_DESC(slave_addrs, "Set the default IPMB slave address for"
1017 " the controller. Normally this is 0x20, but can be" 1034 " the controller. Normally this is 0x20, but can be"
1018 " overridden by this parm. This is an array indexed" 1035 " overridden by this parm. This is an array indexed"
1019 " by interface number."); 1036 " by interface number.");
1037module_param_array(force_kipmid, int, &num_force_kipmid, 0);
1038MODULE_PARM_DESC(force_kipmid, "Force the kipmi daemon to be enabled (1) or"
1039 " disabled(0). Normally the IPMI driver auto-detects"
1040 " this, but the value may be overridden by this parm.");
1020 1041
1021 1042
1022#define IPMI_IO_ADDR_SPACE 0 1043#define IPMI_IO_ADDR_SPACE 0
@@ -1730,6 +1751,7 @@ static void __devinit dmi_find_bmc(void)
1730 int rv; 1751 int rv;
1731 1752
1732 while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) { 1753 while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) {
1754 memset(&data, 0, sizeof(data));
1733 rv = decode_dmi((struct dmi_header *) dev->device_data, &data); 1755 rv = decode_dmi((struct dmi_header *) dev->device_data, &data);
1734 if (!rv) 1756 if (!rv)
1735 try_init_dmi(&data); 1757 try_init_dmi(&data);
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c
index 913be23e0a24..ea2bbf80ad33 100644
--- a/drivers/char/isicom.c
+++ b/drivers/char/isicom.c
@@ -1550,7 +1550,7 @@ static void isicom_unregister_ioregion(struct pci_dev *pdev)
1550 board->base = 0; 1550 board->base = 0;
1551} 1551}
1552 1552
1553static struct tty_operations isicom_ops = { 1553static const struct tty_operations isicom_ops = {
1554 .open = isicom_open, 1554 .open = isicom_open,
1555 .close = isicom_close, 1555 .close = isicom_close,
1556 .write = isicom_write, 1556 .write = isicom_write,
@@ -1756,9 +1756,12 @@ static int __devinit load_firmware(struct pci_dev *pdev,
1756 if (retval) 1756 if (retval)
1757 goto end; 1757 goto end;
1758 1758
1759 retval = -EIO;
1760
1759 for (frame = (struct stframe *)fw->data; 1761 for (frame = (struct stframe *)fw->data;
1760 frame < (struct stframe *)(fw->data + fw->size); 1762 frame < (struct stframe *)(fw->data + fw->size);
1761 frame++) { 1763 frame = (struct stframe *)((u8 *)(frame + 1) +
1764 frame->count)) {
1762 if (WaitTillCardIsFree(base)) 1765 if (WaitTillCardIsFree(base))
1763 goto errrelfw; 1766 goto errrelfw;
1764 1767
@@ -1797,23 +1800,12 @@ static int __devinit load_firmware(struct pci_dev *pdev,
1797 } 1800 }
1798 } 1801 }
1799 1802
1800 retval = -EIO;
1801
1802 if (WaitTillCardIsFree(base))
1803 goto errrelfw;
1804
1805 outw(0xf2, base);
1806 outw(0x800, base);
1807 outw(0x0, base);
1808 outw(0x0, base);
1809 InterruptTheCard(base);
1810 outw(0x0, base + 0x4); /* for ISI4608 cards */
1811
1812/* XXX: should we test it by reading it back and comparing with original like 1803/* XXX: should we test it by reading it back and comparing with original like
1813 * in load firmware package? */ 1804 * in load firmware package? */
1814 for (frame = (struct stframe*)fw->data; 1805 for (frame = (struct stframe *)fw->data;
1815 frame < (struct stframe*)(fw->data + fw->size); 1806 frame < (struct stframe *)(fw->data + fw->size);
1816 frame++) { 1807 frame = (struct stframe *)((u8 *)(frame + 1) +
1808 frame->count)) {
1817 if (WaitTillCardIsFree(base)) 1809 if (WaitTillCardIsFree(base))
1818 goto errrelfw; 1810 goto errrelfw;
1819 1811
@@ -1863,6 +1855,17 @@ static int __devinit load_firmware(struct pci_dev *pdev,
1863 } 1855 }
1864 } 1856 }
1865 1857
1858 /* xfer ctrl */
1859 if (WaitTillCardIsFree(base))
1860 goto errrelfw;
1861
1862 outw(0xf2, base);
1863 outw(0x800, base);
1864 outw(0x0, base);
1865 outw(0x0, base);
1866 InterruptTheCard(base);
1867 outw(0x0, base + 0x4); /* for ISI4608 cards */
1868
1866 board->status |= FIRMWARE_LOADED; 1869 board->status |= FIRMWARE_LOADED;
1867 retval = 0; 1870 retval = 0;
1868 1871
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index 8c09997cc3d6..d6e031542c6b 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -612,16 +612,6 @@ MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
612#define MINOR2BRD(min) (((min) & 0xc0) >> 6) 612#define MINOR2BRD(min) (((min) & 0xc0) >> 6)
613#define MINOR2PORT(min) ((min) & 0x3f) 613#define MINOR2PORT(min) ((min) & 0x3f)
614 614
615/*
616 * Define a baud rate table that converts termios baud rate selector
617 * into the actual baud rate value. All baud rate calculations are based
618 * on the actual baud rate required.
619 */
620static unsigned int stli_baudrates[] = {
621 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
622 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
623};
624
625/*****************************************************************************/ 615/*****************************************************************************/
626 616
627/* 617/*
@@ -2747,15 +2737,7 @@ static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tio
2747/* 2737/*
2748 * Start of by setting the baud, char size, parity and stop bit info. 2738 * Start of by setting the baud, char size, parity and stop bit info.
2749 */ 2739 */
2750 pp->baudout = tiosp->c_cflag & CBAUD; 2740 pp->baudout = tty_get_baud_rate(portp->tty);
2751 if (pp->baudout & CBAUDEX) {
2752 pp->baudout &= ~CBAUDEX;
2753 if ((pp->baudout < 1) || (pp->baudout > 4))
2754 tiosp->c_cflag &= ~CBAUDEX;
2755 else
2756 pp->baudout += 15;
2757 }
2758 pp->baudout = stli_baudrates[pp->baudout];
2759 if ((tiosp->c_cflag & CBAUD) == B38400) { 2741 if ((tiosp->c_cflag & CBAUD) == B38400) {
2760 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 2742 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2761 pp->baudout = 57600; 2743 pp->baudout = 57600;
@@ -4654,7 +4636,7 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
4654 return rc; 4636 return rc;
4655} 4637}
4656 4638
4657static struct tty_operations stli_ops = { 4639static const struct tty_operations stli_ops = {
4658 .open = stli_open, 4640 .open = stli_open,
4659 .close = stli_close, 4641 .close = stli_close,
4660 .write = stli_write, 4642 .write = stli_write,
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index 3e90aac37510..e2011669c7bb 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -108,7 +108,11 @@ const int NR_TYPES = ARRAY_SIZE(max_vals);
108struct kbd_struct kbd_table[MAX_NR_CONSOLES]; 108struct kbd_struct kbd_table[MAX_NR_CONSOLES];
109static struct kbd_struct *kbd = kbd_table; 109static struct kbd_struct *kbd = kbd_table;
110 110
111int spawnpid, spawnsig; 111struct vt_spawn_console vt_spawn_con = {
112 .lock = SPIN_LOCK_UNLOCKED,
113 .pid = NULL,
114 .sig = 0,
115};
112 116
113/* 117/*
114 * Variables exported for vt.c 118 * Variables exported for vt.c
@@ -578,9 +582,13 @@ static void fn_compose(struct vc_data *vc, struct pt_regs *regs)
578 582
579static void fn_spawn_con(struct vc_data *vc, struct pt_regs *regs) 583static void fn_spawn_con(struct vc_data *vc, struct pt_regs *regs)
580{ 584{
581 if (spawnpid) 585 spin_lock(&vt_spawn_con.lock);
582 if (kill_proc(spawnpid, spawnsig, 1)) 586 if (vt_spawn_con.pid)
583 spawnpid = 0; 587 if (kill_pid(vt_spawn_con.pid, vt_spawn_con.sig, 1)) {
588 put_pid(vt_spawn_con.pid);
589 vt_spawn_con.pid = NULL;
590 }
591 spin_unlock(&vt_spawn_con.lock);
584} 592}
585 593
586static void fn_SAK(struct vc_data *vc, struct pt_regs *regs) 594static void fn_SAK(struct vc_data *vc, struct pt_regs *regs)
@@ -1285,7 +1293,7 @@ static void kbd_event(struct input_handle *handle, unsigned int event_type,
1285 */ 1293 */
1286static struct input_handle *kbd_connect(struct input_handler *handler, 1294static struct input_handle *kbd_connect(struct input_handler *handler,
1287 struct input_dev *dev, 1295 struct input_dev *dev,
1288 struct input_device_id *id) 1296 const struct input_device_id *id)
1289{ 1297{
1290 struct input_handle *handle; 1298 struct input_handle *handle;
1291 int i; 1299 int i;
@@ -1334,7 +1342,7 @@ static void kbd_start(struct input_handle *handle)
1334 tasklet_enable(&keyboard_tasklet); 1342 tasklet_enable(&keyboard_tasklet);
1335} 1343}
1336 1344
1337static struct input_device_id kbd_ids[] = { 1345static const struct input_device_id kbd_ids[] = {
1338 { 1346 {
1339 .flags = INPUT_DEVICE_ID_MATCH_EVBIT, 1347 .flags = INPUT_DEVICE_ID_MATCH_EVBIT,
1340 .evbit = { BIT(EV_KEY) }, 1348 .evbit = { BIT(EV_KEY) },
@@ -1362,6 +1370,7 @@ static struct input_handler kbd_handler = {
1362int __init kbd_init(void) 1370int __init kbd_init(void)
1363{ 1371{
1364 int i; 1372 int i;
1373 int error;
1365 1374
1366 for (i = 0; i < MAX_NR_CONSOLES; i++) { 1375 for (i = 0; i < MAX_NR_CONSOLES; i++) {
1367 kbd_table[i].ledflagstate = KBD_DEFLEDS; 1376 kbd_table[i].ledflagstate = KBD_DEFLEDS;
@@ -1373,7 +1382,9 @@ int __init kbd_init(void)
1373 kbd_table[i].kbdmode = VC_XLATE; 1382 kbd_table[i].kbdmode = VC_XLATE;
1374 } 1383 }
1375 1384
1376 input_register_handler(&kbd_handler); 1385 error = input_register_handler(&kbd_handler);
1386 if (error)
1387 return error;
1377 1388
1378 tasklet_enable(&keyboard_tasklet); 1389 tasklet_enable(&keyboard_tasklet);
1379 tasklet_schedule(&keyboard_tasklet); 1390 tasklet_schedule(&keyboard_tasklet);
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index f875fda3b089..1ecea7d448f1 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -906,7 +906,7 @@ static int __init lp_init (void)
906 lp_class = class_create(THIS_MODULE, "printer"); 906 lp_class = class_create(THIS_MODULE, "printer");
907 if (IS_ERR(lp_class)) { 907 if (IS_ERR(lp_class)) {
908 err = PTR_ERR(lp_class); 908 err = PTR_ERR(lp_class);
909 goto out_devfs; 909 goto out_reg;
910 } 910 }
911 911
912 if (parport_register_driver (&lp_driver)) { 912 if (parport_register_driver (&lp_driver)) {
@@ -927,7 +927,7 @@ static int __init lp_init (void)
927 927
928out_class: 928out_class:
929 class_destroy(lp_class); 929 class_destroy(lp_class);
930out_devfs: 930out_reg:
931 unregister_chrdev(LP_MAJOR, "lp"); 931 unregister_chrdev(LP_MAJOR, "lp");
932 return err; 932 return err;
933} 933}
diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
index 0385650f6077..636354722658 100644
--- a/drivers/char/mbcs.c
+++ b/drivers/char/mbcs.c
@@ -22,6 +22,7 @@
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/device.h> 23#include <linux/device.h>
24#include <linux/mm.h> 24#include <linux/mm.h>
25#include <linux/fs.h>
25#include <linux/uio.h> 26#include <linux/uio.h>
26#include <asm/io.h> 27#include <asm/io.h>
27#include <asm/uaccess.h> 28#include <asm/uaccess.h>
@@ -447,15 +448,15 @@ loff_t mbcs_sram_llseek(struct file * filp, loff_t off, int whence)
447 loff_t newpos; 448 loff_t newpos;
448 449
449 switch (whence) { 450 switch (whence) {
450 case 0: /* SEEK_SET */ 451 case SEEK_SET:
451 newpos = off; 452 newpos = off;
452 break; 453 break;
453 454
454 case 1: /* SEEK_CUR */ 455 case SEEK_CUR:
455 newpos = filp->f_pos + off; 456 newpos = filp->f_pos + off;
456 break; 457 break;
457 458
458 case 2: /* SEEK_END */ 459 case SEEK_END:
459 newpos = MBCS_SRAM_SIZE + off; 460 newpos = MBCS_SRAM_SIZE + off;
460 break; 461 break;
461 462
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 917b20402664..6511012cbdcd 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -238,6 +238,32 @@ static pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
238} 238}
239#endif 239#endif
240 240
241#ifndef CONFIG_MMU
242static unsigned long get_unmapped_area_mem(struct file *file,
243 unsigned long addr,
244 unsigned long len,
245 unsigned long pgoff,
246 unsigned long flags)
247{
248 if (!valid_mmap_phys_addr_range(pgoff, len))
249 return (unsigned long) -EINVAL;
250 return pgoff;
251}
252
253/* can't do an in-place private mapping if there's no MMU */
254static inline int private_mapping_ok(struct vm_area_struct *vma)
255{
256 return vma->vm_flags & VM_MAYSHARE;
257}
258#else
259#define get_unmapped_area_mem NULL
260
261static inline int private_mapping_ok(struct vm_area_struct *vma)
262{
263 return 1;
264}
265#endif
266
241static int mmap_mem(struct file * file, struct vm_area_struct * vma) 267static int mmap_mem(struct file * file, struct vm_area_struct * vma)
242{ 268{
243 size_t size = vma->vm_end - vma->vm_start; 269 size_t size = vma->vm_end - vma->vm_start;
@@ -245,6 +271,9 @@ static int mmap_mem(struct file * file, struct vm_area_struct * vma)
245 if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size)) 271 if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size))
246 return -EINVAL; 272 return -EINVAL;
247 273
274 if (!private_mapping_ok(vma))
275 return -ENOSYS;
276
248 vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff, 277 vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
249 size, 278 size,
250 vma->vm_page_prot); 279 vma->vm_page_prot);
@@ -522,7 +551,7 @@ static ssize_t write_kmem(struct file * file, const char __user * buf,
522 return virtr + wrote; 551 return virtr + wrote;
523} 552}
524 553
525#if defined(CONFIG_ISA) || !defined(__mc68000__) 554#if (defined(CONFIG_ISA) || defined(CONFIG_PCI)) && !defined(__mc68000__)
526static ssize_t read_port(struct file * file, char __user * buf, 555static ssize_t read_port(struct file * file, char __user * buf,
527 size_t count, loff_t *ppos) 556 size_t count, loff_t *ppos)
528{ 557{
@@ -782,6 +811,7 @@ static const struct file_operations mem_fops = {
782 .write = write_mem, 811 .write = write_mem,
783 .mmap = mmap_mem, 812 .mmap = mmap_mem,
784 .open = open_mem, 813 .open = open_mem,
814 .get_unmapped_area = get_unmapped_area_mem,
785}; 815};
786 816
787static const struct file_operations kmem_fops = { 817static const struct file_operations kmem_fops = {
@@ -790,6 +820,7 @@ static const struct file_operations kmem_fops = {
790 .write = write_kmem, 820 .write = write_kmem,
791 .mmap = mmap_kmem, 821 .mmap = mmap_kmem,
792 .open = open_kmem, 822 .open = open_kmem,
823 .get_unmapped_area = get_unmapped_area_mem,
793}; 824};
794 825
795static const struct file_operations null_fops = { 826static const struct file_operations null_fops = {
@@ -799,7 +830,7 @@ static const struct file_operations null_fops = {
799 .splice_write = splice_write_null, 830 .splice_write = splice_write_null,
800}; 831};
801 832
802#if defined(CONFIG_ISA) || !defined(__mc68000__) 833#if (defined(CONFIG_ISA) || defined(CONFIG_PCI)) && !defined(__mc68000__)
803static const struct file_operations port_fops = { 834static const struct file_operations port_fops = {
804 .llseek = memory_lseek, 835 .llseek = memory_lseek,
805 .read = read_port, 836 .read = read_port,
@@ -815,6 +846,10 @@ static const struct file_operations zero_fops = {
815 .mmap = mmap_zero, 846 .mmap = mmap_zero,
816}; 847};
817 848
849/*
850 * capabilities for /dev/zero
851 * - permits private mappings, "copies" are taken of the source of zeros
852 */
818static struct backing_dev_info zero_bdi = { 853static struct backing_dev_info zero_bdi = {
819 .capabilities = BDI_CAP_MAP_COPY, 854 .capabilities = BDI_CAP_MAP_COPY,
820}; 855};
@@ -862,14 +897,18 @@ static int memory_open(struct inode * inode, struct file * filp)
862 switch (iminor(inode)) { 897 switch (iminor(inode)) {
863 case 1: 898 case 1:
864 filp->f_op = &mem_fops; 899 filp->f_op = &mem_fops;
900 filp->f_mapping->backing_dev_info =
901 &directly_mappable_cdev_bdi;
865 break; 902 break;
866 case 2: 903 case 2:
867 filp->f_op = &kmem_fops; 904 filp->f_op = &kmem_fops;
905 filp->f_mapping->backing_dev_info =
906 &directly_mappable_cdev_bdi;
868 break; 907 break;
869 case 3: 908 case 3:
870 filp->f_op = &null_fops; 909 filp->f_op = &null_fops;
871 break; 910 break;
872#if defined(CONFIG_ISA) || !defined(__mc68000__) 911#if (defined(CONFIG_ISA) || defined(CONFIG_PCI)) && !defined(__mc68000__)
873 case 4: 912 case 4:
874 filp->f_op = &port_fops; 913 filp->f_op = &port_fops;
875 break; 914 break;
@@ -916,7 +955,7 @@ static const struct {
916 {1, "mem", S_IRUSR | S_IWUSR | S_IRGRP, &mem_fops}, 955 {1, "mem", S_IRUSR | S_IWUSR | S_IRGRP, &mem_fops},
917 {2, "kmem", S_IRUSR | S_IWUSR | S_IRGRP, &kmem_fops}, 956 {2, "kmem", S_IRUSR | S_IWUSR | S_IRGRP, &kmem_fops},
918 {3, "null", S_IRUGO | S_IWUGO, &null_fops}, 957 {3, "null", S_IRUGO | S_IWUGO, &null_fops},
919#if defined(CONFIG_ISA) || !defined(__mc68000__) 958#if (defined(CONFIG_ISA) || defined(CONFIG_PCI)) && !defined(__mc68000__)
920 {4, "port", S_IRUSR | S_IWUSR | S_IRGRP, &port_fops}, 959 {4, "port", S_IRUSR | S_IWUSR | S_IRGRP, &port_fops},
921#endif 960#endif
922 {5, "zero", S_IRUGO | S_IWUGO, &zero_fops}, 961 {5, "zero", S_IRUGO | S_IWUGO, &zero_fops},
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index a369dd6877d8..b401383808c2 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -260,7 +260,7 @@ static void MoxaPortEnable(int);
260static void MoxaPortDisable(int); 260static void MoxaPortDisable(int);
261static long MoxaPortGetMaxBaud(int); 261static long MoxaPortGetMaxBaud(int);
262static long MoxaPortSetBaud(int, long); 262static long MoxaPortSetBaud(int, long);
263static int MoxaPortSetTermio(int, struct termios *); 263static int MoxaPortSetTermio(int, struct termios *, speed_t);
264static int MoxaPortGetLineOut(int, int *, int *); 264static int MoxaPortGetLineOut(int, int *, int *);
265static void MoxaPortLineCtrl(int, int, int); 265static void MoxaPortLineCtrl(int, int, int);
266static void MoxaPortFlowCtrl(int, int, int, int, int, int); 266static void MoxaPortFlowCtrl(int, int, int, int, int, int);
@@ -281,7 +281,7 @@ static int moxa_get_serial_info(struct moxa_str *, struct serial_struct __user *
281static int moxa_set_serial_info(struct moxa_str *, struct serial_struct __user *); 281static int moxa_set_serial_info(struct moxa_str *, struct serial_struct __user *);
282static void MoxaSetFifo(int port, int enable); 282static void MoxaSetFifo(int port, int enable);
283 283
284static struct tty_operations moxa_ops = { 284static const struct tty_operations moxa_ops = {
285 .open = moxa_open, 285 .open = moxa_open,
286 .close = moxa_close, 286 .close = moxa_close,
287 .write = moxa_write, 287 .write = moxa_write,
@@ -986,7 +986,7 @@ static void set_tty_param(struct tty_struct *tty)
986 if (ts->c_iflag & IXANY) 986 if (ts->c_iflag & IXANY)
987 xany = 1; 987 xany = 1;
988 MoxaPortFlowCtrl(ch->port, rts, cts, txflow, rxflow, xany); 988 MoxaPortFlowCtrl(ch->port, rts, cts, txflow, rxflow, xany);
989 MoxaPortSetTermio(ch->port, ts); 989 MoxaPortSetTermio(ch->port, ts, tty_get_baud_rate(tty));
990} 990}
991 991
992static int block_till_ready(struct tty_struct *tty, struct file *filp, 992static int block_till_ready(struct tty_struct *tty, struct file *filp,
@@ -1900,9 +1900,10 @@ int MoxaPortsOfCard(int cardno)
1900 * 1900 *
1901 * Function 12: Configure the port. 1901 * Function 12: Configure the port.
1902 * Syntax: 1902 * Syntax:
1903 * int MoxaPortSetTermio(int port, struct termios *termio); 1903 * int MoxaPortSetTermio(int port, struct termios *termio, speed_t baud);
1904 * int port : port number (0 - 127) 1904 * int port : port number (0 - 127)
1905 * struct termios * termio : termio structure pointer 1905 * struct termios * termio : termio structure pointer
1906 * speed_t baud : baud rate
1906 * 1907 *
1907 * return: -1 : this port is invalid or termio == NULL 1908 * return: -1 : this port is invalid or termio == NULL
1908 * 0 : setting O.K. 1909 * 0 : setting O.K.
@@ -2182,11 +2183,10 @@ long MoxaPortSetBaud(int port, long baud)
2182 return (baud); 2183 return (baud);
2183} 2184}
2184 2185
2185int MoxaPortSetTermio(int port, struct termios *termio) 2186int MoxaPortSetTermio(int port, struct termios *termio, speed_t baud)
2186{ 2187{
2187 void __iomem *ofsAddr; 2188 void __iomem *ofsAddr;
2188 tcflag_t cflag; 2189 tcflag_t cflag;
2189 long baud;
2190 tcflag_t mode = 0; 2190 tcflag_t mode = 0;
2191 2191
2192 if (moxaChkPort[port] == 0 || termio == 0) 2192 if (moxaChkPort[port] == 0 || termio == 0)
@@ -2222,77 +2222,9 @@ int MoxaPortSetTermio(int port, struct termios *termio)
2222 2222
2223 moxafunc(ofsAddr, FC_SetDataMode, (ushort) mode); 2223 moxafunc(ofsAddr, FC_SetDataMode, (ushort) mode);
2224 2224
2225 cflag &= (CBAUD | CBAUDEX);
2226#ifndef B921600
2227#define B921600 (B460800+1)
2228#endif
2229 switch (cflag) {
2230 case B921600:
2231 baud = 921600L;
2232 break;
2233 case B460800:
2234 baud = 460800L;
2235 break;
2236 case B230400:
2237 baud = 230400L;
2238 break;
2239 case B115200:
2240 baud = 115200L;
2241 break;
2242 case B57600:
2243 baud = 57600L;
2244 break;
2245 case B38400:
2246 baud = 38400L;
2247 break;
2248 case B19200:
2249 baud = 19200L;
2250 break;
2251 case B9600:
2252 baud = 9600L;
2253 break;
2254 case B4800:
2255 baud = 4800L;
2256 break;
2257 case B2400:
2258 baud = 2400L;
2259 break;
2260 case B1800:
2261 baud = 1800L;
2262 break;
2263 case B1200:
2264 baud = 1200L;
2265 break;
2266 case B600:
2267 baud = 600L;
2268 break;
2269 case B300:
2270 baud = 300L;
2271 break;
2272 case B200:
2273 baud = 200L;
2274 break;
2275 case B150:
2276 baud = 150L;
2277 break;
2278 case B134:
2279 baud = 134L;
2280 break;
2281 case B110:
2282 baud = 110L;
2283 break;
2284 case B75:
2285 baud = 75L;
2286 break;
2287 case B50:
2288 baud = 50L;
2289 break;
2290 default:
2291 baud = 0;
2292 }
2293 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) || 2225 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) ||
2294 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) { 2226 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) {
2295 if (baud == 921600L) 2227 if (baud >= 921600L)
2296 return (-1); 2228 return (-1);
2297 } 2229 }
2298 MoxaPortSetBaud(port, baud); 2230 MoxaPortSetBaud(port, baud);
diff --git a/drivers/char/mspec.c b/drivers/char/mspec.c
new file mode 100644
index 000000000000..5426b1e5595f
--- /dev/null
+++ b/drivers/char/mspec.c
@@ -0,0 +1,421 @@
1/*
2 * Copyright (C) 2001-2006 Silicon Graphics, Inc. All rights
3 * reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License
7 * as published by the Free Software Foundation.
8 */
9
10/*
11 * SN Platform Special Memory (mspec) Support
12 *
13 * This driver exports the SN special memory (mspec) facility to user
14 * processes.
15 * There are three types of memory made available thru this driver:
16 * fetchops, uncached and cached.
17 *
18 * Fetchops are atomic memory operations that are implemented in the
19 * memory controller on SGI SN hardware.
20 *
21 * Uncached are used for memory write combining feature of the ia64
22 * cpu.
23 *
24 * Cached are used for areas of memory that are used as cached addresses
25 * on our partition and used as uncached addresses from other partitions.
26 * Due to a design constraint of the SN2 Shub, you can not have processors
27 * on the same FSB perform both a cached and uncached reference to the
28 * same cache line. These special memory cached regions prevent the
29 * kernel from ever dropping in a TLB entry and therefore prevent the
30 * processor from ever speculating a cache line from this page.
31 */
32
33#include <linux/config.h>
34#include <linux/types.h>
35#include <linux/kernel.h>
36#include <linux/module.h>
37#include <linux/init.h>
38#include <linux/errno.h>
39#include <linux/miscdevice.h>
40#include <linux/spinlock.h>
41#include <linux/mm.h>
42#include <linux/vmalloc.h>
43#include <linux/string.h>
44#include <linux/slab.h>
45#include <linux/numa.h>
46#include <asm/page.h>
47#include <asm/system.h>
48#include <asm/pgtable.h>
49#include <asm/atomic.h>
50#include <asm/tlbflush.h>
51#include <asm/uncached.h>
52#include <asm/sn/addrs.h>
53#include <asm/sn/arch.h>
54#include <asm/sn/mspec.h>
55#include <asm/sn/sn_cpuid.h>
56#include <asm/sn/io.h>
57#include <asm/sn/bte.h>
58#include <asm/sn/shubio.h>
59
60
61#define FETCHOP_ID "SGI Fetchop,"
62#define CACHED_ID "Cached,"
63#define UNCACHED_ID "Uncached"
64#define REVISION "4.0"
65#define MSPEC_BASENAME "mspec"
66
67/*
68 * Page types allocated by the device.
69 */
70enum {
71 MSPEC_FETCHOP = 1,
72 MSPEC_CACHED,
73 MSPEC_UNCACHED
74};
75
76static int is_sn2;
77
78/*
79 * One of these structures is allocated when an mspec region is mmaped. The
80 * structure is pointed to by the vma->vm_private_data field in the vma struct.
81 * This structure is used to record the addresses of the mspec pages.
82 */
83struct vma_data {
84 atomic_t refcnt; /* Number of vmas sharing the data. */
85 spinlock_t lock; /* Serialize access to the vma. */
86 int count; /* Number of pages allocated. */
87 int type; /* Type of pages allocated. */
88 unsigned long maddr[0]; /* Array of MSPEC addresses. */
89};
90
91/* used on shub2 to clear FOP cache in the HUB */
92static unsigned long scratch_page[MAX_NUMNODES];
93#define SH2_AMO_CACHE_ENTRIES 4
94
95static inline int
96mspec_zero_block(unsigned long addr, int len)
97{
98 int status;
99
100 if (is_sn2) {
101 if (is_shub2()) {
102 int nid;
103 void *p;
104 int i;
105
106 nid = nasid_to_cnodeid(get_node_number(__pa(addr)));
107 p = (void *)TO_AMO(scratch_page[nid]);
108
109 for (i=0; i < SH2_AMO_CACHE_ENTRIES; i++) {
110 FETCHOP_LOAD_OP(p, FETCHOP_LOAD);
111 p += FETCHOP_VAR_SIZE;
112 }
113 }
114
115 status = bte_copy(0, addr & ~__IA64_UNCACHED_OFFSET, len,
116 BTE_WACQUIRE | BTE_ZERO_FILL, NULL);
117 } else {
118 memset((char *) addr, 0, len);
119 status = 0;
120 }
121 return status;
122}
123
124/*
125 * mspec_open
126 *
127 * Called when a device mapping is created by a means other than mmap
128 * (via fork, etc.). Increments the reference count on the underlying
129 * mspec data so it is not freed prematurely.
130 */
131static void
132mspec_open(struct vm_area_struct *vma)
133{
134 struct vma_data *vdata;
135
136 vdata = vma->vm_private_data;
137 atomic_inc(&vdata->refcnt);
138}
139
140/*
141 * mspec_close
142 *
143 * Called when unmapping a device mapping. Frees all mspec pages
144 * belonging to the vma.
145 */
146static void
147mspec_close(struct vm_area_struct *vma)
148{
149 struct vma_data *vdata;
150 int i, pages, result, vdata_size;
151
152 vdata = vma->vm_private_data;
153 if (!atomic_dec_and_test(&vdata->refcnt))
154 return;
155
156 pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
157 vdata_size = sizeof(struct vma_data) + pages * sizeof(long);
158 for (i = 0; i < pages; i++) {
159 if (vdata->maddr[i] == 0)
160 continue;
161 /*
162 * Clear the page before sticking it back
163 * into the pool.
164 */
165 result = mspec_zero_block(vdata->maddr[i], PAGE_SIZE);
166 if (!result)
167 uncached_free_page(vdata->maddr[i]);
168 else
169 printk(KERN_WARNING "mspec_close(): "
170 "failed to zero page %i\n",
171 result);
172 }
173
174 if (vdata_size <= PAGE_SIZE)
175 kfree(vdata);
176 else
177 vfree(vdata);
178}
179
180
181/*
182 * mspec_nopfn
183 *
184 * Creates a mspec page and maps it to user space.
185 */
186static unsigned long
187mspec_nopfn(struct vm_area_struct *vma, unsigned long address)
188{
189 unsigned long paddr, maddr;
190 unsigned long pfn;
191 int index;
192 struct vma_data *vdata = vma->vm_private_data;
193
194 index = (address - vma->vm_start) >> PAGE_SHIFT;
195 maddr = (volatile unsigned long) vdata->maddr[index];
196 if (maddr == 0) {
197 maddr = uncached_alloc_page(numa_node_id());
198 if (maddr == 0)
199 return NOPFN_OOM;
200
201 spin_lock(&vdata->lock);
202 if (vdata->maddr[index] == 0) {
203 vdata->count++;
204 vdata->maddr[index] = maddr;
205 } else {
206 uncached_free_page(maddr);
207 maddr = vdata->maddr[index];
208 }
209 spin_unlock(&vdata->lock);
210 }
211
212 if (vdata->type == MSPEC_FETCHOP)
213 paddr = TO_AMO(maddr);
214 else
215 paddr = __pa(TO_CAC(maddr));
216
217 pfn = paddr >> PAGE_SHIFT;
218
219 return pfn;
220}
221
222static struct vm_operations_struct mspec_vm_ops = {
223 .open = mspec_open,
224 .close = mspec_close,
225 .nopfn = mspec_nopfn
226};
227
228/*
229 * mspec_mmap
230 *
231 * Called when mmaping the device. Initializes the vma with a fault handler
232 * and private data structure necessary to allocate, track, and free the
233 * underlying pages.
234 */
235static int
236mspec_mmap(struct file *file, struct vm_area_struct *vma, int type)
237{
238 struct vma_data *vdata;
239 int pages, vdata_size;
240
241 if (vma->vm_pgoff != 0)
242 return -EINVAL;
243
244 if ((vma->vm_flags & VM_SHARED) == 0)
245 return -EINVAL;
246
247 if ((vma->vm_flags & VM_WRITE) == 0)
248 return -EPERM;
249
250 pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
251 vdata_size = sizeof(struct vma_data) + pages * sizeof(long);
252 if (vdata_size <= PAGE_SIZE)
253 vdata = kmalloc(vdata_size, GFP_KERNEL);
254 else
255 vdata = vmalloc(vdata_size);
256 if (!vdata)
257 return -ENOMEM;
258 memset(vdata, 0, vdata_size);
259
260 vdata->type = type;
261 spin_lock_init(&vdata->lock);
262 vdata->refcnt = ATOMIC_INIT(1);
263 vma->vm_private_data = vdata;
264
265 vma->vm_flags |= (VM_IO | VM_LOCKED | VM_RESERVED | VM_PFNMAP);
266 if (vdata->type == MSPEC_FETCHOP || vdata->type == MSPEC_UNCACHED)
267 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
268 vma->vm_ops = &mspec_vm_ops;
269
270 return 0;
271}
272
273static int
274fetchop_mmap(struct file *file, struct vm_area_struct *vma)
275{
276 return mspec_mmap(file, vma, MSPEC_FETCHOP);
277}
278
279static int
280cached_mmap(struct file *file, struct vm_area_struct *vma)
281{
282 return mspec_mmap(file, vma, MSPEC_CACHED);
283}
284
285static int
286uncached_mmap(struct file *file, struct vm_area_struct *vma)
287{
288 return mspec_mmap(file, vma, MSPEC_UNCACHED);
289}
290
291static struct file_operations fetchop_fops = {
292 .owner = THIS_MODULE,
293 .mmap = fetchop_mmap
294};
295
296static struct miscdevice fetchop_miscdev = {
297 .minor = MISC_DYNAMIC_MINOR,
298 .name = "sgi_fetchop",
299 .fops = &fetchop_fops
300};
301
302static struct file_operations cached_fops = {
303 .owner = THIS_MODULE,
304 .mmap = cached_mmap
305};
306
307static struct miscdevice cached_miscdev = {
308 .minor = MISC_DYNAMIC_MINOR,
309 .name = "mspec_cached",
310 .fops = &cached_fops
311};
312
313static struct file_operations uncached_fops = {
314 .owner = THIS_MODULE,
315 .mmap = uncached_mmap
316};
317
318static struct miscdevice uncached_miscdev = {
319 .minor = MISC_DYNAMIC_MINOR,
320 .name = "mspec_uncached",
321 .fops = &uncached_fops
322};
323
324/*
325 * mspec_init
326 *
327 * Called at boot time to initialize the mspec facility.
328 */
329static int __init
330mspec_init(void)
331{
332 int ret;
333 int nid;
334
335 /*
336 * The fetchop device only works on SN2 hardware, uncached and cached
337 * memory drivers should both be valid on all ia64 hardware
338 */
339 if (ia64_platform_is("sn2")) {
340 is_sn2 = 1;
341 if (is_shub2()) {
342 ret = -ENOMEM;
343 for_each_online_node(nid) {
344 int actual_nid;
345 int nasid;
346 unsigned long phys;
347
348 scratch_page[nid] = uncached_alloc_page(nid);
349 if (scratch_page[nid] == 0)
350 goto free_scratch_pages;
351 phys = __pa(scratch_page[nid]);
352 nasid = get_node_number(phys);
353 actual_nid = nasid_to_cnodeid(nasid);
354 if (actual_nid != nid)
355 goto free_scratch_pages;
356 }
357 }
358
359 ret = misc_register(&fetchop_miscdev);
360 if (ret) {
361 printk(KERN_ERR
362 "%s: failed to register device %i\n",
363 FETCHOP_ID, ret);
364 goto free_scratch_pages;
365 }
366 }
367 ret = misc_register(&cached_miscdev);
368 if (ret) {
369 printk(KERN_ERR "%s: failed to register device %i\n",
370 CACHED_ID, ret);
371 if (is_sn2)
372 misc_deregister(&fetchop_miscdev);
373 goto free_scratch_pages;
374 }
375 ret = misc_register(&uncached_miscdev);
376 if (ret) {
377 printk(KERN_ERR "%s: failed to register device %i\n",
378 UNCACHED_ID, ret);
379 misc_deregister(&cached_miscdev);
380 if (is_sn2)
381 misc_deregister(&fetchop_miscdev);
382 goto free_scratch_pages;
383 }
384
385 printk(KERN_INFO "%s %s initialized devices: %s %s %s\n",
386 MSPEC_BASENAME, REVISION, is_sn2 ? FETCHOP_ID : "",
387 CACHED_ID, UNCACHED_ID);
388
389 return 0;
390
391 free_scratch_pages:
392 for_each_node(nid) {
393 if (scratch_page[nid] != 0)
394 uncached_free_page(scratch_page[nid]);
395 }
396 return ret;
397}
398
399static void __exit
400mspec_exit(void)
401{
402 int nid;
403
404 misc_deregister(&uncached_miscdev);
405 misc_deregister(&cached_miscdev);
406 if (is_sn2) {
407 misc_deregister(&fetchop_miscdev);
408
409 for_each_node(nid) {
410 if (scratch_page[nid] != 0)
411 uncached_free_page(scratch_page[nid]);
412 }
413 }
414}
415
416module_init(mspec_init);
417module_exit(mspec_exit);
418
419MODULE_AUTHOR("Silicon Graphics, Inc. <linux-altix@sgi.com>");
420MODULE_DESCRIPTION("Driver for SGI SN special memory operations");
421MODULE_LICENSE("GPL");
diff --git a/drivers/char/mwave/mwavedd.c b/drivers/char/mwave/mwavedd.c
index 39a2e661ff55..8d14823b0514 100644
--- a/drivers/char/mwave/mwavedd.c
+++ b/drivers/char/mwave/mwavedd.c
@@ -297,7 +297,7 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
297 " ipcnum %x, usIntCount %x\n", 297 " ipcnum %x, usIntCount %x\n",
298 ipcnum, 298 ipcnum,
299 pDrvData->IPCs[ipcnum].usIntCount); 299 pDrvData->IPCs[ipcnum].usIntCount);
300 if (ipcnum > ARRAY_SIZE(pDrvData->IPCs)) { 300 if (ipcnum >= ARRAY_SIZE(pDrvData->IPCs)) {
301 PRINTK_ERROR(KERN_ERR_MWAVE 301 PRINTK_ERROR(KERN_ERR_MWAVE
302 "mwavedd::mwave_ioctl:" 302 "mwavedd::mwave_ioctl:"
303 " IOCTL_MW_GET_IPC: Error:" 303 " IOCTL_MW_GET_IPC: Error:"
@@ -355,7 +355,7 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
355 "mwavedd::mwave_ioctl IOCTL_MW_UNREGISTER_IPC" 355 "mwavedd::mwave_ioctl IOCTL_MW_UNREGISTER_IPC"
356 " ipcnum %x\n", 356 " ipcnum %x\n",
357 ipcnum); 357 ipcnum);
358 if (ipcnum > ARRAY_SIZE(pDrvData->IPCs)) { 358 if (ipcnum >= ARRAY_SIZE(pDrvData->IPCs)) {
359 PRINTK_ERROR(KERN_ERR_MWAVE 359 PRINTK_ERROR(KERN_ERR_MWAVE
360 "mwavedd::mwave_ioctl:" 360 "mwavedd::mwave_ioctl:"
361 " IOCTL_MW_UNREGISTER_IPC:" 361 " IOCTL_MW_UNREGISTER_IPC:"
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 556abd3e0d07..8253fca8efd5 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -453,7 +453,7 @@ static int CheckIsMoxaMust(int io)
453 453
454/* above is modified by Victor Yu. 08-15-2002 */ 454/* above is modified by Victor Yu. 08-15-2002 */
455 455
456static struct tty_operations mxser_ops = { 456static const struct tty_operations mxser_ops = {
457 .open = mxser_open, 457 .open = mxser_open,
458 .close = mxser_close, 458 .close = mxser_close,
459 .write = mxser_write, 459 .write = mxser_write,
@@ -2554,71 +2554,7 @@ static int mxser_change_speed(struct mxser_struct *info, struct termios *old_ter
2554#define B921600 (B460800 +1) 2554#define B921600 (B460800 +1)
2555#endif 2555#endif
2556 if (mxser_set_baud_method[info->port] == 0) { 2556 if (mxser_set_baud_method[info->port] == 0) {
2557 switch (cflag & (CBAUD | CBAUDEX)) { 2557 baud = tty_get_baud_rate(info->tty);
2558 case B921600:
2559 baud = 921600;
2560 break;
2561 case B460800:
2562 baud = 460800;
2563 break;
2564 case B230400:
2565 baud = 230400;
2566 break;
2567 case B115200:
2568 baud = 115200;
2569 break;
2570 case B57600:
2571 baud = 57600;
2572 break;
2573 case B38400:
2574 baud = 38400;
2575 break;
2576 case B19200:
2577 baud = 19200;
2578 break;
2579 case B9600:
2580 baud = 9600;
2581 break;
2582 case B4800:
2583 baud = 4800;
2584 break;
2585 case B2400:
2586 baud = 2400;
2587 break;
2588 case B1800:
2589 baud = 1800;
2590 break;
2591 case B1200:
2592 baud = 1200;
2593 break;
2594 case B600:
2595 baud = 600;
2596 break;
2597 case B300:
2598 baud = 300;
2599 break;
2600 case B200:
2601 baud = 200;
2602 break;
2603 case B150:
2604 baud = 150;
2605 break;
2606 case B134:
2607 baud = 134;
2608 break;
2609 case B110:
2610 baud = 110;
2611 break;
2612 case B75:
2613 baud = 75;
2614 break;
2615 case B50:
2616 baud = 50;
2617 break;
2618 default:
2619 baud = 0;
2620 break;
2621 }
2622 mxser_set_baud(info, baud); 2558 mxser_set_baud(info, baud);
2623 } 2559 }
2624 2560
diff --git a/drivers/char/nwbutton.c b/drivers/char/nwbutton.c
index 7c57ebfa8640..ea1aa7764f8e 100644
--- a/drivers/char/nwbutton.c
+++ b/drivers/char/nwbutton.c
@@ -127,9 +127,8 @@ static void button_consume_callbacks (int bpcount)
127static void button_sequence_finished (unsigned long parameters) 127static void button_sequence_finished (unsigned long parameters)
128{ 128{
129#ifdef CONFIG_NWBUTTON_REBOOT /* Reboot using button is enabled */ 129#ifdef CONFIG_NWBUTTON_REBOOT /* Reboot using button is enabled */
130 if (button_press_count == reboot_count) { 130 if (button_press_count == reboot_count)
131 kill_proc (1, SIGINT, 1); /* Ask init to reboot us */ 131 kill_cad_pid(SIGINT, 1); /* Ask init to reboot us */
132 }
133#endif /* CONFIG_NWBUTTON_REBOOT */ 132#endif /* CONFIG_NWBUTTON_REBOOT */
134 button_consume_callbacks (button_press_count); 133 button_consume_callbacks (button_press_count);
135 bcount = sprintf (button_output_buffer, "%d\n", button_press_count); 134 bcount = sprintf (button_output_buffer, "%d\n", button_press_count);
diff --git a/drivers/char/pc8736x_gpio.c b/drivers/char/pc8736x_gpio.c
index 84e5a68635f1..ecfaf180e5bd 100644
--- a/drivers/char/pc8736x_gpio.c
+++ b/drivers/char/pc8736x_gpio.c
@@ -188,16 +188,6 @@ static void pc8736x_gpio_set(unsigned minor, int val)
188 pc8736x_gpio_shadow[port] = val; 188 pc8736x_gpio_shadow[port] = val;
189} 189}
190 190
191static void pc8736x_gpio_set_high(unsigned index)
192{
193 pc8736x_gpio_set(index, 1);
194}
195
196static void pc8736x_gpio_set_low(unsigned index)
197{
198 pc8736x_gpio_set(index, 0);
199}
200
201static int pc8736x_gpio_current(unsigned minor) 191static int pc8736x_gpio_current(unsigned minor)
202{ 192{
203 int port, bit; 193 int port, bit;
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 00f574cbb0d4..dd845cbefe94 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -3010,7 +3010,7 @@ static struct pcmcia_driver mgslpc_driver = {
3010 .resume = mgslpc_resume, 3010 .resume = mgslpc_resume,
3011}; 3011};
3012 3012
3013static struct tty_operations mgslpc_ops = { 3013static const struct tty_operations mgslpc_ops = {
3014 .open = mgslpc_open, 3014 .open = mgslpc_open,
3015 .close = mgslpc_close, 3015 .close = mgslpc_close,
3016 .write = mgslpc_write, 3016 .write = mgslpc_write,
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index 34dd4c38110e..80d3eedd7f96 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -224,7 +224,7 @@ static void pty_set_termios(struct tty_struct *tty, struct termios *old_termios)
224 tty->termios->c_cflag |= (CS8 | CREAD); 224 tty->termios->c_cflag |= (CS8 | CREAD);
225} 225}
226 226
227static struct tty_operations pty_ops = { 227static const struct tty_operations pty_ops = {
228 .open = pty_open, 228 .open = pty_open,
229 .close = pty_close, 229 .close = pty_close,
230 .write = pty_write, 230 .write = pty_write,
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 4c3a5ca9d8f7..07f47a0208a7 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -655,6 +655,7 @@ void add_interrupt_randomness(int irq)
655 add_timer_randomness(irq_timer_state[irq], 0x100 + irq); 655 add_timer_randomness(irq_timer_state[irq], 0x100 + irq);
656} 656}
657 657
658#ifdef CONFIG_BLOCK
658void add_disk_randomness(struct gendisk *disk) 659void add_disk_randomness(struct gendisk *disk)
659{ 660{
660 if (!disk || !disk->random) 661 if (!disk || !disk->random)
@@ -667,6 +668,7 @@ void add_disk_randomness(struct gendisk *disk)
667} 668}
668 669
669EXPORT_SYMBOL(add_disk_randomness); 670EXPORT_SYMBOL(add_disk_randomness);
671#endif
670 672
671#define EXTRACT_SIZE 10 673#define EXTRACT_SIZE 10
672 674
@@ -887,8 +889,8 @@ static void init_std_data(struct entropy_store *r)
887 889
888 do_gettimeofday(&tv); 890 do_gettimeofday(&tv);
889 add_entropy_words(r, (__u32 *)&tv, sizeof(tv)/4); 891 add_entropy_words(r, (__u32 *)&tv, sizeof(tv)/4);
890 add_entropy_words(r, (__u32 *)&system_utsname, 892 add_entropy_words(r, (__u32 *)utsname(),
891 sizeof(system_utsname)/4); 893 sizeof(*(utsname()))/4);
892} 894}
893 895
894static int __init rand_initialize(void) 896static int __init rand_initialize(void)
@@ -918,6 +920,7 @@ void rand_initialize_irq(int irq)
918 } 920 }
919} 921}
920 922
923#ifdef CONFIG_BLOCK
921void rand_initialize_disk(struct gendisk *disk) 924void rand_initialize_disk(struct gendisk *disk)
922{ 925{
923 struct timer_rand_state *state; 926 struct timer_rand_state *state;
@@ -932,6 +935,7 @@ void rand_initialize_disk(struct gendisk *disk)
932 disk->random = state; 935 disk->random = state;
933 } 936 }
934} 937}
938#endif
935 939
936static ssize_t 940static ssize_t
937random_read(struct file * file, char __user * buf, size_t nbytes, loff_t *ppos) 941random_read(struct file * file, char __user * buf, size_t nbytes, loff_t *ppos)
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 579868af4a54..89b718e326e5 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -238,39 +238,14 @@ out:
238 return err; 238 return err;
239} 239}
240 240
241static ssize_t raw_file_write(struct file *file, const char __user *buf,
242 size_t count, loff_t *ppos)
243{
244 struct iovec local_iov = {
245 .iov_base = (char __user *)buf,
246 .iov_len = count
247 };
248
249 return generic_file_write_nolock(file, &local_iov, 1, ppos);
250}
251
252static ssize_t raw_file_aio_write(struct kiocb *iocb, const char __user *buf,
253 size_t count, loff_t pos)
254{
255 struct iovec local_iov = {
256 .iov_base = (char __user *)buf,
257 .iov_len = count
258 };
259
260 return generic_file_aio_write_nolock(iocb, &local_iov, 1, &iocb->ki_pos);
261}
262
263
264static const struct file_operations raw_fops = { 241static const struct file_operations raw_fops = {
265 .read = generic_file_read, 242 .read = do_sync_read,
266 .aio_read = generic_file_aio_read, 243 .aio_read = generic_file_aio_read,
267 .write = raw_file_write, 244 .write = do_sync_write,
268 .aio_write = raw_file_aio_write, 245 .aio_write = generic_file_aio_write_nolock,
269 .open = raw_open, 246 .open = raw_open,
270 .release= raw_release, 247 .release= raw_release,
271 .ioctl = raw_ioctl, 248 .ioctl = raw_ioctl,
272 .readv = generic_file_readv,
273 .writev = generic_file_writev,
274 .owner = THIS_MODULE, 249 .owner = THIS_MODULE,
275}; 250};
276 251
@@ -288,31 +263,34 @@ static struct cdev raw_cdev = {
288static int __init raw_init(void) 263static int __init raw_init(void)
289{ 264{
290 dev_t dev = MKDEV(RAW_MAJOR, 0); 265 dev_t dev = MKDEV(RAW_MAJOR, 0);
266 int ret;
291 267
292 if (register_chrdev_region(dev, MAX_RAW_MINORS, "raw")) 268 ret = register_chrdev_region(dev, MAX_RAW_MINORS, "raw");
269 if (ret)
293 goto error; 270 goto error;
294 271
295 cdev_init(&raw_cdev, &raw_fops); 272 cdev_init(&raw_cdev, &raw_fops);
296 if (cdev_add(&raw_cdev, dev, MAX_RAW_MINORS)) { 273 ret = cdev_add(&raw_cdev, dev, MAX_RAW_MINORS);
274 if (ret) {
297 kobject_put(&raw_cdev.kobj); 275 kobject_put(&raw_cdev.kobj);
298 unregister_chrdev_region(dev, MAX_RAW_MINORS); 276 goto error_region;
299 goto error;
300 } 277 }
301 278
302 raw_class = class_create(THIS_MODULE, "raw"); 279 raw_class = class_create(THIS_MODULE, "raw");
303 if (IS_ERR(raw_class)) { 280 if (IS_ERR(raw_class)) {
304 printk(KERN_ERR "Error creating raw class.\n"); 281 printk(KERN_ERR "Error creating raw class.\n");
305 cdev_del(&raw_cdev); 282 cdev_del(&raw_cdev);
306 unregister_chrdev_region(dev, MAX_RAW_MINORS); 283 ret = PTR_ERR(raw_class);
307 goto error; 284 goto error_region;
308 } 285 }
309 class_device_create(raw_class, NULL, MKDEV(RAW_MAJOR, 0), NULL, "rawctl"); 286 class_device_create(raw_class, NULL, MKDEV(RAW_MAJOR, 0), NULL, "rawctl");
310 287
311 return 0; 288 return 0;
312 289
290error_region:
291 unregister_chrdev_region(dev, MAX_RAW_MINORS);
313error: 292error:
314 printk(KERN_ERR "error register raw device\n"); 293 return ret;
315 return 1;
316} 294}
317 295
318static void __exit raw_exit(void) 296static void __exit raw_exit(void)
diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c
index 3fa80aaf4527..202a3b0945b7 100644
--- a/drivers/char/rio/rio_linux.c
+++ b/drivers/char/rio/rio_linux.c
@@ -727,7 +727,7 @@ static struct vpd_prom *get_VPD_PROM(struct Host *hp)
727 return &vpdp; 727 return &vpdp;
728} 728}
729 729
730static struct tty_operations rio_ops = { 730static const struct tty_operations rio_ops = {
731 .open = riotopen, 731 .open = riotopen,
732 .close = gs_close, 732 .close = gs_close,
733 .write = gs_write, 733 .write = gs_write,
diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c
index f1c94f771af5..214d850112fd 100644
--- a/drivers/char/riscom8.c
+++ b/drivers/char/riscom8.c
@@ -675,26 +675,12 @@ static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port)
675 port->COR2 = 0; 675 port->COR2 = 0;
676 port->MSVR = MSVR_RTS; 676 port->MSVR = MSVR_RTS;
677 677
678 baud = C_BAUD(tty); 678 baud = tty_get_baud_rate(tty);
679
680 if (baud & CBAUDEX) {
681 baud &= ~CBAUDEX;
682 if (baud < 1 || baud > 2)
683 port->tty->termios->c_cflag &= ~CBAUDEX;
684 else
685 baud += 15;
686 }
687 if (baud == 15) {
688 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
689 baud ++;
690 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
691 baud += 2;
692 }
693 679
694 /* Select port on the board */ 680 /* Select port on the board */
695 rc_out(bp, CD180_CAR, port_No(port)); 681 rc_out(bp, CD180_CAR, port_No(port));
696 682
697 if (!baud_table[baud]) { 683 if (!baud) {
698 /* Drop DTR & exit */ 684 /* Drop DTR & exit */
699 bp->DTR |= (1u << port_No(port)); 685 bp->DTR |= (1u << port_No(port));
700 rc_out(bp, RC_DTR, bp->DTR); 686 rc_out(bp, RC_DTR, bp->DTR);
@@ -710,7 +696,7 @@ static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port)
710 */ 696 */
711 697
712 /* Set baud rate for port */ 698 /* Set baud rate for port */
713 tmp = (((RC_OSCFREQ + baud_table[baud]/2) / baud_table[baud] + 699 tmp = (((RC_OSCFREQ + baud/2) / baud +
714 CD180_TPC/2) / CD180_TPC); 700 CD180_TPC/2) / CD180_TPC);
715 701
716 rc_out(bp, CD180_RBPRH, (tmp >> 8) & 0xff); 702 rc_out(bp, CD180_RBPRH, (tmp >> 8) & 0xff);
@@ -718,7 +704,7 @@ static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port)
718 rc_out(bp, CD180_RBPRL, tmp & 0xff); 704 rc_out(bp, CD180_RBPRL, tmp & 0xff);
719 rc_out(bp, CD180_TBPRL, tmp & 0xff); 705 rc_out(bp, CD180_TBPRL, tmp & 0xff);
720 706
721 baud = (baud_table[baud] + 5) / 10; /* Estimated CPS */ 707 baud = (baud + 5) / 10; /* Estimated CPS */
722 708
723 /* Two timer ticks seems enough to wakeup something like SLIP driver */ 709 /* Two timer ticks seems enough to wakeup something like SLIP driver */
724 tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO; 710 tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO;
@@ -1597,7 +1583,7 @@ static void do_softint(void *private_)
1597 } 1583 }
1598} 1584}
1599 1585
1600static struct tty_operations riscom_ops = { 1586static const struct tty_operations riscom_ops = {
1601 .open = rc_open, 1587 .open = rc_open,
1602 .close = rc_close, 1588 .close = rc_close,
1603 .write = rc_write, 1589 .write = rc_write,
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index 0ac131881322..bac80056f7e0 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -2334,7 +2334,7 @@ static int __init init_ISA(int i)
2334 return (1); 2334 return (1);
2335} 2335}
2336 2336
2337static struct tty_operations rocket_ops = { 2337static const struct tty_operations rocket_ops = {
2338 .open = rp_open, 2338 .open = rp_open,
2339 .close = rp_close, 2339 .close = rp_close,
2340 .write = rp_write, 2340 .write = rp_write,
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index ab6429b4a84e..656f8c0ca52e 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -1262,10 +1262,8 @@ void rtc_get_rtc_time(struct rtc_time *rtc_tm)
1262 * Once the read clears, read the RTC time (again via ioctl). Easy. 1262 * Once the read clears, read the RTC time (again via ioctl). Easy.
1263 */ 1263 */
1264 1264
1265 while (rtc_is_updating() != 0 && jiffies - uip_watchdog < 2*HZ/100) { 1265 while (rtc_is_updating() != 0 && jiffies - uip_watchdog < 2*HZ/100)
1266 barrier();
1267 cpu_relax(); 1266 cpu_relax();
1268 }
1269 1267
1270 /* 1268 /*
1271 * Only the values that we read from the RTC are set. We leave 1269 * Only the values that we read from the RTC are set. We leave
diff --git a/drivers/char/s3c2410-rtc.c b/drivers/char/s3c2410-rtc.c
deleted file mode 100644
index 5458ef1634e5..000000000000
--- a/drivers/char/s3c2410-rtc.c
+++ /dev/null
@@ -1,591 +0,0 @@
1/* drivers/char/s3c2410_rtc.c
2 *
3 * Copyright (c) 2004 Simtec Electronics <linux@simtec.co.uk>
4 * http://www.simtec.co.uk/products/SWLINUX/
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 version 2 as
8 * published by the Free Software Foundation.
9 *
10 * S3C2410 Internal RTC Driver
11 *
12 * Changelog:
13 * 08-Nov-2004 BJD Initial creation
14 * 12-Nov-2004 BJD Added periodic IRQ and PM code
15 * 22-Nov-2004 BJD Sign-test on alarm code to check for <0
16 * 10-Mar-2005 LCVR Changed S3C2410_VA_RTC to S3C24XX_VA_RTC
17*/
18
19#include <linux/module.h>
20#include <linux/fs.h>
21#include <linux/string.h>
22#include <linux/init.h>
23#include <linux/platform_device.h>
24#include <linux/interrupt.h>
25#include <linux/rtc.h>
26#include <linux/bcd.h>
27#include <linux/clk.h>
28
29#include <asm/hardware.h>
30#include <asm/uaccess.h>
31#include <asm/io.h>
32#include <asm/irq.h>
33#include <asm/rtc.h>
34
35#include <asm/mach/time.h>
36
37#include <asm/arch/regs-rtc.h>
38
39/* need this for the RTC_AF definitions */
40#include <linux/mc146818rtc.h>
41
42#undef S3C24XX_VA_RTC
43#define S3C24XX_VA_RTC s3c2410_rtc_base
44
45static struct resource *s3c2410_rtc_mem;
46
47static void __iomem *s3c2410_rtc_base;
48static int s3c2410_rtc_alarmno = NO_IRQ;
49static int s3c2410_rtc_tickno = NO_IRQ;
50static int s3c2410_rtc_freq = 1;
51
52static DEFINE_SPINLOCK(s3c2410_rtc_pie_lock);
53
54/* IRQ Handlers */
55
56static irqreturn_t s3c2410_rtc_alarmirq(int irq, void *id, struct pt_regs *r)
57{
58 rtc_update(1, RTC_AF | RTC_IRQF);
59 return IRQ_HANDLED;
60}
61
62static irqreturn_t s3c2410_rtc_tickirq(int irq, void *id, struct pt_regs *r)
63{
64 rtc_update(1, RTC_PF | RTC_IRQF);
65 return IRQ_HANDLED;
66}
67
68/* Update control registers */
69static void s3c2410_rtc_setaie(int to)
70{
71 unsigned int tmp;
72
73 pr_debug("%s: aie=%d\n", __FUNCTION__, to);
74
75 tmp = readb(S3C2410_RTCALM);
76
77 if (to)
78 tmp |= S3C2410_RTCALM_ALMEN;
79 else
80 tmp &= ~S3C2410_RTCALM_ALMEN;
81
82
83 writeb(tmp, S3C2410_RTCALM);
84}
85
86static void s3c2410_rtc_setpie(int to)
87{
88 unsigned int tmp;
89
90 pr_debug("%s: pie=%d\n", __FUNCTION__, to);
91
92 spin_lock_irq(&s3c2410_rtc_pie_lock);
93 tmp = readb(S3C2410_TICNT) & ~S3C2410_TICNT_ENABLE;
94
95 if (to)
96 tmp |= S3C2410_TICNT_ENABLE;
97
98 writeb(tmp, S3C2410_TICNT);
99 spin_unlock_irq(&s3c2410_rtc_pie_lock);
100}
101
102static void s3c2410_rtc_setfreq(int freq)
103{
104 unsigned int tmp;
105
106 spin_lock_irq(&s3c2410_rtc_pie_lock);
107 tmp = readb(S3C2410_TICNT) & S3C2410_TICNT_ENABLE;
108
109 s3c2410_rtc_freq = freq;
110
111 tmp |= (128 / freq)-1;
112
113 writeb(tmp, S3C2410_TICNT);
114 spin_unlock_irq(&s3c2410_rtc_pie_lock);
115}
116
117/* Time read/write */
118
119static int s3c2410_rtc_gettime(struct rtc_time *rtc_tm)
120{
121 unsigned int have_retried = 0;
122
123 retry_get_time:
124 rtc_tm->tm_min = readb(S3C2410_RTCMIN);
125 rtc_tm->tm_hour = readb(S3C2410_RTCHOUR);
126 rtc_tm->tm_mday = readb(S3C2410_RTCDATE);
127 rtc_tm->tm_mon = readb(S3C2410_RTCMON);
128 rtc_tm->tm_year = readb(S3C2410_RTCYEAR);
129 rtc_tm->tm_sec = readb(S3C2410_RTCSEC);
130
131 /* the only way to work out wether the system was mid-update
132 * when we read it is to check the second counter, and if it
133 * is zero, then we re-try the entire read
134 */
135
136 if (rtc_tm->tm_sec == 0 && !have_retried) {
137 have_retried = 1;
138 goto retry_get_time;
139 }
140
141 pr_debug("read time %02x.%02x.%02x %02x/%02x/%02x\n",
142 rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday,
143 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec);
144
145 BCD_TO_BIN(rtc_tm->tm_sec);
146 BCD_TO_BIN(rtc_tm->tm_min);
147 BCD_TO_BIN(rtc_tm->tm_hour);
148 BCD_TO_BIN(rtc_tm->tm_mday);
149 BCD_TO_BIN(rtc_tm->tm_mon);
150 BCD_TO_BIN(rtc_tm->tm_year);
151
152 rtc_tm->tm_year += 100;
153 rtc_tm->tm_mon -= 1;
154
155 return 0;
156}
157
158
159static int s3c2410_rtc_settime(struct rtc_time *tm)
160{
161 /* the rtc gets round the y2k problem by just not supporting it */
162
163 if (tm->tm_year < 100)
164 return -EINVAL;
165
166 writeb(BIN2BCD(tm->tm_sec), S3C2410_RTCSEC);
167 writeb(BIN2BCD(tm->tm_min), S3C2410_RTCMIN);
168 writeb(BIN2BCD(tm->tm_hour), S3C2410_RTCHOUR);
169 writeb(BIN2BCD(tm->tm_mday), S3C2410_RTCDATE);
170 writeb(BIN2BCD(tm->tm_mon + 1), S3C2410_RTCMON);
171 writeb(BIN2BCD(tm->tm_year - 100), S3C2410_RTCYEAR);
172
173 return 0;
174}
175
176static int s3c2410_rtc_getalarm(struct rtc_wkalrm *alrm)
177{
178 struct rtc_time *alm_tm = &alrm->time;
179 unsigned int alm_en;
180
181 alm_tm->tm_sec = readb(S3C2410_ALMSEC);
182 alm_tm->tm_min = readb(S3C2410_ALMMIN);
183 alm_tm->tm_hour = readb(S3C2410_ALMHOUR);
184 alm_tm->tm_mon = readb(S3C2410_ALMMON);
185 alm_tm->tm_mday = readb(S3C2410_ALMDATE);
186 alm_tm->tm_year = readb(S3C2410_ALMYEAR);
187
188 alm_en = readb(S3C2410_RTCALM);
189
190 pr_debug("read alarm %02x %02x.%02x.%02x %02x/%02x/%02x\n",
191 alm_en,
192 alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday,
193 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec);
194
195
196 /* decode the alarm enable field */
197
198 if (alm_en & S3C2410_RTCALM_SECEN) {
199 BCD_TO_BIN(alm_tm->tm_sec);
200 } else {
201 alm_tm->tm_sec = 0xff;
202 }
203
204 if (alm_en & S3C2410_RTCALM_MINEN) {
205 BCD_TO_BIN(alm_tm->tm_min);
206 } else {
207 alm_tm->tm_min = 0xff;
208 }
209
210 if (alm_en & S3C2410_RTCALM_HOUREN) {
211 BCD_TO_BIN(alm_tm->tm_hour);
212 } else {
213 alm_tm->tm_hour = 0xff;
214 }
215
216 if (alm_en & S3C2410_RTCALM_DAYEN) {
217 BCD_TO_BIN(alm_tm->tm_mday);
218 } else {
219 alm_tm->tm_mday = 0xff;
220 }
221
222 if (alm_en & S3C2410_RTCALM_MONEN) {
223 BCD_TO_BIN(alm_tm->tm_mon);
224 alm_tm->tm_mon -= 1;
225 } else {
226 alm_tm->tm_mon = 0xff;
227 }
228
229 if (alm_en & S3C2410_RTCALM_YEAREN) {
230 BCD_TO_BIN(alm_tm->tm_year);
231 } else {
232 alm_tm->tm_year = 0xffff;
233 }
234
235 /* todo - set alrm->enabled ? */
236
237 return 0;
238}
239
240static int s3c2410_rtc_setalarm(struct rtc_wkalrm *alrm)
241{
242 struct rtc_time *tm = &alrm->time;
243 unsigned int alrm_en;
244
245 pr_debug("s3c2410_rtc_setalarm: %d, %02x/%02x/%02x %02x.%02x.%02x\n",
246 alrm->enabled,
247 tm->tm_mday & 0xff, tm->tm_mon & 0xff, tm->tm_year & 0xff,
248 tm->tm_hour & 0xff, tm->tm_min & 0xff, tm->tm_sec);
249
250 if (alrm->enabled || 1) {
251 alrm_en = readb(S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN;
252 writeb(0x00, S3C2410_RTCALM);
253
254 if (tm->tm_sec < 60 && tm->tm_sec >= 0) {
255 alrm_en |= S3C2410_RTCALM_SECEN;
256 writeb(BIN2BCD(tm->tm_sec), S3C2410_ALMSEC);
257 }
258
259 if (tm->tm_min < 60 && tm->tm_min >= 0) {
260 alrm_en |= S3C2410_RTCALM_MINEN;
261 writeb(BIN2BCD(tm->tm_min), S3C2410_ALMMIN);
262 }
263
264 if (tm->tm_hour < 24 && tm->tm_hour >= 0) {
265 alrm_en |= S3C2410_RTCALM_HOUREN;
266 writeb(BIN2BCD(tm->tm_hour), S3C2410_ALMHOUR);
267 }
268
269 pr_debug("setting S3C2410_RTCALM to %08x\n", alrm_en);
270
271 writeb(alrm_en, S3C2410_RTCALM);
272 enable_irq_wake(s3c2410_rtc_alarmno);
273 } else {
274 alrm_en = readb(S3C2410_RTCALM);
275 alrm_en &= ~S3C2410_RTCALM_ALMEN;
276 writeb(alrm_en, S3C2410_RTCALM);
277 disable_irq_wake(s3c2410_rtc_alarmno);
278 }
279
280 return 0;
281}
282
283static int s3c2410_rtc_ioctl(unsigned int cmd, unsigned long arg)
284{
285 switch (cmd) {
286 case RTC_AIE_OFF:
287 case RTC_AIE_ON:
288 s3c2410_rtc_setaie((cmd == RTC_AIE_ON) ? 1 : 0);
289 return 0;
290
291 case RTC_PIE_OFF:
292 case RTC_PIE_ON:
293 s3c2410_rtc_setpie((cmd == RTC_PIE_ON) ? 1 : 0);
294 return 0;
295
296 case RTC_IRQP_READ:
297 return put_user(s3c2410_rtc_freq, (unsigned long __user *)arg);
298
299 case RTC_IRQP_SET:
300 if (arg < 1 || arg > 64)
301 return -EINVAL;
302
303 if (!capable(CAP_SYS_RESOURCE))
304 return -EACCES;
305
306 /* check for power of 2 */
307
308 if ((arg & (arg-1)) != 0)
309 return -EINVAL;
310
311 pr_debug("s3c2410_rtc: setting frequency %ld\n", arg);
312
313 s3c2410_rtc_setfreq(arg);
314 return 0;
315
316 case RTC_UIE_ON:
317 case RTC_UIE_OFF:
318 return -EINVAL;
319 }
320
321 return -EINVAL;
322}
323
324static int s3c2410_rtc_proc(char *buf)
325{
326 unsigned int rtcalm = readb(S3C2410_RTCALM);
327 unsigned int ticnt = readb (S3C2410_TICNT);
328 char *p = buf;
329
330 p += sprintf(p, "alarm_IRQ\t: %s\n",
331 (rtcalm & S3C2410_RTCALM_ALMEN) ? "yes" : "no" );
332 p += sprintf(p, "periodic_IRQ\t: %s\n",
333 (ticnt & S3C2410_TICNT_ENABLE) ? "yes" : "no" );
334 p += sprintf(p, "periodic_freq\t: %d\n", s3c2410_rtc_freq);
335
336 return p - buf;
337}
338
339static int s3c2410_rtc_open(void)
340{
341 int ret;
342
343 ret = request_irq(s3c2410_rtc_alarmno, s3c2410_rtc_alarmirq,
344 IRQF_DISABLED, "s3c2410-rtc alarm", NULL);
345
346 if (ret)
347 printk(KERN_ERR "IRQ%d already in use\n", s3c2410_rtc_alarmno);
348
349 ret = request_irq(s3c2410_rtc_tickno, s3c2410_rtc_tickirq,
350 IRQF_DISABLED, "s3c2410-rtc tick", NULL);
351
352 if (ret) {
353 printk(KERN_ERR "IRQ%d already in use\n", s3c2410_rtc_tickno);
354 goto tick_err;
355 }
356
357 return ret;
358
359 tick_err:
360 free_irq(s3c2410_rtc_alarmno, NULL);
361 return ret;
362}
363
364static void s3c2410_rtc_release(void)
365{
366 /* do not clear AIE here, it may be needed for wake */
367
368 s3c2410_rtc_setpie(0);
369 free_irq(s3c2410_rtc_alarmno, NULL);
370 free_irq(s3c2410_rtc_tickno, NULL);
371}
372
373static struct rtc_ops s3c2410_rtcops = {
374 .owner = THIS_MODULE,
375 .open = s3c2410_rtc_open,
376 .release = s3c2410_rtc_release,
377 .ioctl = s3c2410_rtc_ioctl,
378 .read_time = s3c2410_rtc_gettime,
379 .set_time = s3c2410_rtc_settime,
380 .read_alarm = s3c2410_rtc_getalarm,
381 .set_alarm = s3c2410_rtc_setalarm,
382 .proc = s3c2410_rtc_proc,
383};
384
385static void s3c2410_rtc_enable(struct platform_device *pdev, int en)
386{
387 unsigned int tmp;
388
389 if (s3c2410_rtc_base == NULL)
390 return;
391
392 if (!en) {
393 tmp = readb(S3C2410_RTCCON);
394 writeb(tmp & ~S3C2410_RTCCON_RTCEN, S3C2410_RTCCON);
395
396 tmp = readb(S3C2410_TICNT);
397 writeb(tmp & ~S3C2410_TICNT_ENABLE, S3C2410_TICNT);
398 } else {
399 /* re-enable the device, and check it is ok */
400
401 if ((readb(S3C2410_RTCCON) & S3C2410_RTCCON_RTCEN) == 0){
402 dev_info(&pdev->dev, "rtc disabled, re-enabling\n");
403
404 tmp = readb(S3C2410_RTCCON);
405 writeb(tmp | S3C2410_RTCCON_RTCEN , S3C2410_RTCCON);
406 }
407
408 if ((readb(S3C2410_RTCCON) & S3C2410_RTCCON_CNTSEL)){
409 dev_info(&pdev->dev, "removing S3C2410_RTCCON_CNTSEL\n");
410
411 tmp = readb(S3C2410_RTCCON);
412 writeb(tmp& ~S3C2410_RTCCON_CNTSEL , S3C2410_RTCCON);
413 }
414
415 if ((readb(S3C2410_RTCCON) & S3C2410_RTCCON_CLKRST)){
416 dev_info(&pdev->dev, "removing S3C2410_RTCCON_CLKRST\n");
417
418 tmp = readb(S3C2410_RTCCON);
419 writeb(tmp & ~S3C2410_RTCCON_CLKRST, S3C2410_RTCCON);
420 }
421 }
422}
423
424static int s3c2410_rtc_remove(struct platform_device *dev)
425{
426 unregister_rtc(&s3c2410_rtcops);
427
428 s3c2410_rtc_setpie(0);
429 s3c2410_rtc_setaie(0);
430
431 if (s3c2410_rtc_mem != NULL) {
432 pr_debug("s3c2410_rtc: releasing s3c2410_rtc_mem\n");
433 iounmap(s3c2410_rtc_base);
434 release_resource(s3c2410_rtc_mem);
435 kfree(s3c2410_rtc_mem);
436 }
437
438 return 0;
439}
440
441static int s3c2410_rtc_probe(struct platform_device *pdev)
442{
443 struct resource *res;
444 int ret;
445
446 pr_debug("%s: probe=%p\n", __FUNCTION__, pdev);
447
448 /* find the IRQs */
449
450 s3c2410_rtc_tickno = platform_get_irq(pdev, 1);
451 if (s3c2410_rtc_tickno < 0) {
452 dev_err(&pdev->dev, "no irq for rtc tick\n");
453 return -ENOENT;
454 }
455
456 s3c2410_rtc_alarmno = platform_get_irq(pdev, 0);
457 if (s3c2410_rtc_alarmno < 0) {
458 dev_err(&pdev->dev, "no irq for alarm\n");
459 return -ENOENT;
460 }
461
462 pr_debug("s3c2410_rtc: tick irq %d, alarm irq %d\n",
463 s3c2410_rtc_tickno, s3c2410_rtc_alarmno);
464
465 /* get the memory region */
466
467 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
468 if (res == NULL) {
469 dev_err(&pdev->dev, "failed to get memory region resource\n");
470 return -ENOENT;
471 }
472
473 s3c2410_rtc_mem = request_mem_region(res->start, res->end-res->start+1,
474 pdev->name);
475
476 if (s3c2410_rtc_mem == NULL) {
477 dev_err(&pdev->dev, "failed to reserve memory region\n");
478 ret = -ENOENT;
479 goto exit_err;
480 }
481
482 s3c2410_rtc_base = ioremap(res->start, res->end - res->start + 1);
483 if (s3c2410_rtc_base == NULL) {
484 dev_err(&pdev->dev, "failed ioremap()\n");
485 ret = -EINVAL;
486 goto exit_err;
487 }
488
489 s3c2410_rtc_mem = res;
490 pr_debug("s3c2410_rtc_base=%p\n", s3c2410_rtc_base);
491
492 pr_debug("s3c2410_rtc: RTCCON=%02x\n", readb(S3C2410_RTCCON));
493
494 /* check to see if everything is setup correctly */
495
496 s3c2410_rtc_enable(pdev, 1);
497
498 pr_debug("s3c2410_rtc: RTCCON=%02x\n", readb(S3C2410_RTCCON));
499
500 s3c2410_rtc_setfreq(s3c2410_rtc_freq);
501
502 /* register RTC and exit */
503
504 register_rtc(&s3c2410_rtcops);
505 return 0;
506
507 exit_err:
508 dev_err(&pdev->dev, "error %d during initialisation\n", ret);
509
510 return ret;
511}
512
513#ifdef CONFIG_PM
514
515/* S3C2410 RTC Power management control */
516
517static struct timespec s3c2410_rtc_delta;
518
519static int ticnt_save;
520
521static int s3c2410_rtc_suspend(struct platform_device *pdev, pm_message_t state)
522{
523 struct rtc_time tm;
524 struct timespec time;
525
526 time.tv_nsec = 0;
527
528 /* save TICNT for anyone using periodic interrupts */
529
530 ticnt_save = readb(S3C2410_TICNT);
531
532 /* calculate time delta for suspend */
533
534 s3c2410_rtc_gettime(&tm);
535 rtc_tm_to_time(&tm, &time.tv_sec);
536 save_time_delta(&s3c2410_rtc_delta, &time);
537 s3c2410_rtc_enable(pdev, 0);
538
539 return 0;
540}
541
542static int s3c2410_rtc_resume(struct platform_device *pdev)
543{
544 struct rtc_time tm;
545 struct timespec time;
546
547 time.tv_nsec = 0;
548
549 s3c2410_rtc_enable(pdev, 1);
550 s3c2410_rtc_gettime(&tm);
551 rtc_tm_to_time(&tm, &time.tv_sec);
552 restore_time_delta(&s3c2410_rtc_delta, &time);
553
554 writeb(ticnt_save, S3C2410_TICNT);
555 return 0;
556}
557#else
558#define s3c2410_rtc_suspend NULL
559#define s3c2410_rtc_resume NULL
560#endif
561
562static struct platform_driver s3c2410_rtcdrv = {
563 .probe = s3c2410_rtc_probe,
564 .remove = s3c2410_rtc_remove,
565 .suspend = s3c2410_rtc_suspend,
566 .resume = s3c2410_rtc_resume,
567 .driver = {
568 .name = "s3c2410-rtc",
569 .owner = THIS_MODULE,
570 },
571};
572
573static char __initdata banner[] = "S3C2410 RTC, (c) 2004 Simtec Electronics\n";
574
575static int __init s3c2410_rtc_init(void)
576{
577 printk(banner);
578 return platform_driver_register(&s3c2410_rtcdrv);
579}
580
581static void __exit s3c2410_rtc_exit(void)
582{
583 platform_driver_unregister(&s3c2410_rtcdrv);
584}
585
586module_init(s3c2410_rtc_init);
587module_exit(s3c2410_rtc_exit);
588
589MODULE_DESCRIPTION("S3C24XX RTC Driver");
590MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
591MODULE_LICENSE("GPL");
diff --git a/drivers/char/scx200_gpio.c b/drivers/char/scx200_gpio.c
index b956c7babd18..99e5272e3c53 100644
--- a/drivers/char/scx200_gpio.c
+++ b/drivers/char/scx200_gpio.c
@@ -44,7 +44,7 @@ struct nsc_gpio_ops scx200_gpio_ops = {
44 .gpio_change = scx200_gpio_change, 44 .gpio_change = scx200_gpio_change,
45 .gpio_current = scx200_gpio_current 45 .gpio_current = scx200_gpio_current
46}; 46};
47EXPORT_SYMBOL(scx200_gpio_ops); 47EXPORT_SYMBOL_GPL(scx200_gpio_ops);
48 48
49static int scx200_gpio_open(struct inode *inode, struct file *file) 49static int scx200_gpio_open(struct inode *inode, struct file *file)
50{ 50{
@@ -69,7 +69,7 @@ static const struct file_operations scx200_gpio_fileops = {
69 .release = scx200_gpio_release, 69 .release = scx200_gpio_release,
70}; 70};
71 71
72struct cdev scx200_gpio_cdev; /* use 1 cdev for all pins */ 72static struct cdev scx200_gpio_cdev; /* use 1 cdev for all pins */
73 73
74static int __init scx200_gpio_init(void) 74static int __init scx200_gpio_init(void)
75{ 75{
diff --git a/drivers/char/selection.c b/drivers/char/selection.c
index 71093a9fc462..74cff839c857 100644
--- a/drivers/char/selection.c
+++ b/drivers/char/selection.c
@@ -33,7 +33,7 @@ extern void poke_blanked_console(void);
33 33
34/* Variables for selection control. */ 34/* Variables for selection control. */
35/* Use a dynamic buffer, instead of static (Dec 1994) */ 35/* Use a dynamic buffer, instead of static (Dec 1994) */
36struct vc_data *sel_cons; /* must not be disallocated */ 36struct vc_data *sel_cons; /* must not be deallocated */
37static volatile int sel_start = -1; /* cleared by clear_selection */ 37static volatile int sel_start = -1; /* cleared by clear_selection */
38static int sel_end; 38static int sel_end;
39static int sel_buffer_lth; 39static int sel_buffer_lth;
diff --git a/drivers/char/ser_a2232.c b/drivers/char/ser_a2232.c
index 510bd3e0e88b..65c751d0d643 100644
--- a/drivers/char/ser_a2232.c
+++ b/drivers/char/ser_a2232.c
@@ -661,7 +661,7 @@ static void a2232_init_portstructs(void)
661 } 661 }
662} 662}
663 663
664static struct tty_operations a2232_ops = { 664static const struct tty_operations a2232_ops = {
665 .open = a2232_open, 665 .open = a2232_open,
666 .close = gs_close, 666 .close = gs_close,
667 .write = gs_write, 667 .write = gs_write,
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c
index 21a710cb4bba..b4ea1266b663 100644
--- a/drivers/char/serial167.c
+++ b/drivers/char/serial167.c
@@ -2158,7 +2158,7 @@ mvme167_serial_console_setup(int cflag)
2158 rcor >> 5, rbpr); 2158 rcor >> 5, rbpr);
2159} /* serial_console_init */ 2159} /* serial_console_init */
2160 2160
2161static struct tty_operations cy_ops = { 2161static const struct tty_operations cy_ops = {
2162 .open = cy_open, 2162 .open = cy_open,
2163 .close = cy_close, 2163 .close = cy_close,
2164 .write = cy_write, 2164 .write = cy_write,
diff --git a/drivers/char/snsc_event.c b/drivers/char/snsc_event.c
index d12d4f629cec..864854c58866 100644
--- a/drivers/char/snsc_event.c
+++ b/drivers/char/snsc_event.c
@@ -220,7 +220,7 @@ scdrv_dispatch_event(char *event, int len)
220 " Sending SIGPWR to init...\n"); 220 " Sending SIGPWR to init...\n");
221 221
222 /* give a SIGPWR signal to init proc */ 222 /* give a SIGPWR signal to init proc */
223 kill_proc(1, SIGPWR, 0); 223 kill_cad_pid(SIGPWR, 0);
224 } else { 224 } else {
225 /* print to system log */ 225 /* print to system log */
226 printk("%s|$(0x%x)%s\n", severity, esp_code, desc); 226 printk("%s|$(0x%x)%s\n", severity, esp_code, desc);
diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c
index a1d303f9a33d..902c48dca3bc 100644
--- a/drivers/char/specialix.c
+++ b/drivers/char/specialix.c
@@ -182,7 +182,6 @@ static int sx_poll = HZ;
182#define RS_EVENT_WRITE_WAKEUP 0 182#define RS_EVENT_WRITE_WAKEUP 0
183 183
184static struct tty_driver *specialix_driver; 184static struct tty_driver *specialix_driver;
185static unsigned char * tmp_buf;
186 185
187static unsigned long baud_table[] = { 186static unsigned long baud_table[] = {
188 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 187 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
@@ -1087,24 +1086,16 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1087 port->MSVR = (sx_in(bp, CD186x_MSVR) & MSVR_RTS); 1086 port->MSVR = (sx_in(bp, CD186x_MSVR) & MSVR_RTS);
1088 spin_unlock_irqrestore(&bp->lock, flags); 1087 spin_unlock_irqrestore(&bp->lock, flags);
1089 dprintk (SX_DEBUG_TERMIOS, "sx: got MSVR=%02x.\n", port->MSVR); 1088 dprintk (SX_DEBUG_TERMIOS, "sx: got MSVR=%02x.\n", port->MSVR);
1090 baud = C_BAUD(tty); 1089 baud = tty_get_baud_rate(tty);
1091 1090
1092 if (baud & CBAUDEX) { 1091 if (baud == 38400) {
1093 baud &= ~CBAUDEX;
1094 if (baud < 1 || baud > 2)
1095 port->tty->termios->c_cflag &= ~CBAUDEX;
1096 else
1097 baud += 15;
1098 }
1099 if (baud == 15) {
1100 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 1092 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
1101 baud ++; 1093 baud ++;
1102 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 1094 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
1103 baud += 2; 1095 baud += 2;
1104 } 1096 }
1105 1097
1106 1098 if (!baud) {
1107 if (!baud_table[baud]) {
1108 /* Drop DTR & exit */ 1099 /* Drop DTR & exit */
1109 dprintk (SX_DEBUG_TERMIOS, "Dropping DTR... Hmm....\n"); 1100 dprintk (SX_DEBUG_TERMIOS, "Dropping DTR... Hmm....\n");
1110 if (!SX_CRTSCTS (tty)) { 1101 if (!SX_CRTSCTS (tty)) {
@@ -1134,7 +1125,7 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1134 "This is an untested option, please be carefull.\n", 1125 "This is an untested option, please be carefull.\n",
1135 port_No (port), tmp); 1126 port_No (port), tmp);
1136 else 1127 else
1137 tmp = (((SX_OSCFREQ + baud_table[baud]/2) / baud_table[baud] + 1128 tmp = (((SX_OSCFREQ + baud/2) / baud +
1138 CD186x_TPC/2) / CD186x_TPC); 1129 CD186x_TPC/2) / CD186x_TPC);
1139 1130
1140 if ((tmp < 0x10) && time_before(again, jiffies)) { 1131 if ((tmp < 0x10) && time_before(again, jiffies)) {
@@ -1682,7 +1673,7 @@ static int sx_write(struct tty_struct * tty,
1682 1673
1683 bp = port_Board(port); 1674 bp = port_Board(port);
1684 1675
1685 if (!port->xmit_buf || !tmp_buf) { 1676 if (!port->xmit_buf) {
1686 func_exit(); 1677 func_exit();
1687 return 0; 1678 return 0;
1688 } 1679 }
@@ -2372,7 +2363,7 @@ static void do_softint(void *private_)
2372 func_exit(); 2363 func_exit();
2373} 2364}
2374 2365
2375static struct tty_operations sx_ops = { 2366static const struct tty_operations sx_ops = {
2376 .open = sx_open, 2367 .open = sx_open,
2377 .close = sx_close, 2368 .close = sx_close,
2378 .write = sx_write, 2369 .write = sx_write,
@@ -2406,12 +2397,6 @@ static int sx_init_drivers(void)
2406 return 1; 2397 return 1;
2407 } 2398 }
2408 2399
2409 if (!(tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL))) {
2410 printk(KERN_ERR "sx: Couldn't get free page.\n");
2411 put_tty_driver(specialix_driver);
2412 func_exit();
2413 return 1;
2414 }
2415 specialix_driver->owner = THIS_MODULE; 2400 specialix_driver->owner = THIS_MODULE;
2416 specialix_driver->name = "ttyW"; 2401 specialix_driver->name = "ttyW";
2417 specialix_driver->major = SPECIALIX_NORMAL_MAJOR; 2402 specialix_driver->major = SPECIALIX_NORMAL_MAJOR;
@@ -2425,7 +2410,6 @@ static int sx_init_drivers(void)
2425 2410
2426 if ((error = tty_register_driver(specialix_driver))) { 2411 if ((error = tty_register_driver(specialix_driver))) {
2427 put_tty_driver(specialix_driver); 2412 put_tty_driver(specialix_driver);
2428 free_page((unsigned long)tmp_buf);
2429 printk(KERN_ERR "sx: Couldn't register specialix IO8+ driver, error = %d\n", 2413 printk(KERN_ERR "sx: Couldn't register specialix IO8+ driver, error = %d\n",
2430 error); 2414 error);
2431 func_exit(); 2415 func_exit();
@@ -2451,7 +2435,6 @@ static void sx_release_drivers(void)
2451{ 2435{
2452 func_enter(); 2436 func_enter();
2453 2437
2454 free_page((unsigned long)tmp_buf);
2455 tty_unregister_driver(specialix_driver); 2438 tty_unregister_driver(specialix_driver);
2456 put_tty_driver(specialix_driver); 2439 put_tty_driver(specialix_driver);
2457 func_exit(); 2440 func_exit();
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 3beb2203d24b..bd711537ec4e 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -2993,7 +2993,7 @@ static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, uns
2993 return(rc); 2993 return(rc);
2994} 2994}
2995 2995
2996static struct tty_operations stl_ops = { 2996static const struct tty_operations stl_ops = {
2997 .open = stl_open, 2997 .open = stl_open,
2998 .close = stl_close, 2998 .close = stl_close,
2999 .write = stl_write, 2999 .write = stl_write,
diff --git a/drivers/char/sx.c b/drivers/char/sx.c
index e1cd2bc4b1e4..57e31e5eaedb 100644
--- a/drivers/char/sx.c
+++ b/drivers/char/sx.c
@@ -2226,7 +2226,7 @@ static int probe_si (struct sx_board *board)
2226 return 1; 2226 return 1;
2227} 2227}
2228 2228
2229static struct tty_operations sx_ops = { 2229static const struct tty_operations sx_ops = {
2230 .break_ctl = sx_break, 2230 .break_ctl = sx_break,
2231 .open = sx_open, 2231 .open = sx_open,
2232 .close = gs_close, 2232 .close = gs_close,
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index 78b1b1a2732b..244dc308c770 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -4360,7 +4360,7 @@ static struct mgsl_struct* mgsl_allocate_device(void)
4360 4360
4361} /* end of mgsl_allocate_device()*/ 4361} /* end of mgsl_allocate_device()*/
4362 4362
4363static struct tty_operations mgsl_ops = { 4363static const struct tty_operations mgsl_ops = {
4364 .open = mgsl_open, 4364 .open = mgsl_open,
4365 .close = mgsl_close, 4365 .close = mgsl_close,
4366 .write = mgsl_write, 4366 .write = mgsl_write,
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index 2f07b085536b..bdc7cb248b8f 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: synclink_gt.c,v 4.25 2006/02/06 21:20:33 paulkf Exp $ 2 * $Id: synclink_gt.c,v 4.36 2006/08/28 20:47:14 paulkf Exp $
3 * 3 *
4 * Device driver for Microgate SyncLink GT serial adapters. 4 * Device driver for Microgate SyncLink GT serial adapters.
5 * 5 *
@@ -91,12 +91,12 @@
91 * module identification 91 * module identification
92 */ 92 */
93static char *driver_name = "SyncLink GT"; 93static char *driver_name = "SyncLink GT";
94static char *driver_version = "$Revision: 4.25 $"; 94static char *driver_version = "$Revision: 4.36 $";
95static char *tty_driver_name = "synclink_gt"; 95static char *tty_driver_name = "synclink_gt";
96static char *tty_dev_prefix = "ttySLG"; 96static char *tty_dev_prefix = "ttySLG";
97MODULE_LICENSE("GPL"); 97MODULE_LICENSE("GPL");
98#define MGSL_MAGIC 0x5401 98#define MGSL_MAGIC 0x5401
99#define MAX_DEVICES 12 99#define MAX_DEVICES 32
100 100
101static struct pci_device_id pci_table[] = { 101static struct pci_device_id pci_table[] = {
102 {PCI_VENDOR_ID_MICROGATE, SYNCLINK_GT_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,}, 102 {PCI_VENDOR_ID_MICROGATE, SYNCLINK_GT_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
@@ -461,7 +461,7 @@ static int adapter_test(struct slgt_info *info);
461static void reset_adapter(struct slgt_info *info); 461static void reset_adapter(struct slgt_info *info);
462static void reset_port(struct slgt_info *info); 462static void reset_port(struct slgt_info *info);
463static void async_mode(struct slgt_info *info); 463static void async_mode(struct slgt_info *info);
464static void hdlc_mode(struct slgt_info *info); 464static void sync_mode(struct slgt_info *info);
465 465
466static void rx_stop(struct slgt_info *info); 466static void rx_stop(struct slgt_info *info);
467static void rx_start(struct slgt_info *info); 467static void rx_start(struct slgt_info *info);
@@ -881,7 +881,9 @@ static int write(struct tty_struct *tty,
881 if (!count) 881 if (!count)
882 goto cleanup; 882 goto cleanup;
883 883
884 if (info->params.mode == MGSL_MODE_RAW) { 884 if (info->params.mode == MGSL_MODE_RAW ||
885 info->params.mode == MGSL_MODE_MONOSYNC ||
886 info->params.mode == MGSL_MODE_BISYNC) {
885 unsigned int bufs_needed = (count/DMABUFSIZE); 887 unsigned int bufs_needed = (count/DMABUFSIZE);
886 unsigned int bufs_free = free_tbuf_count(info); 888 unsigned int bufs_free = free_tbuf_count(info);
887 if (count % DMABUFSIZE) 889 if (count % DMABUFSIZE)
@@ -1897,6 +1899,8 @@ static void bh_handler(void* context)
1897 while(rx_get_frame(info)); 1899 while(rx_get_frame(info));
1898 break; 1900 break;
1899 case MGSL_MODE_RAW: 1901 case MGSL_MODE_RAW:
1902 case MGSL_MODE_MONOSYNC:
1903 case MGSL_MODE_BISYNC:
1900 while(rx_get_buf(info)); 1904 while(rx_get_buf(info));
1901 break; 1905 break;
1902 } 1906 }
@@ -2362,10 +2366,9 @@ static void program_hw(struct slgt_info *info)
2362 rx_stop(info); 2366 rx_stop(info);
2363 tx_stop(info); 2367 tx_stop(info);
2364 2368
2365 if (info->params.mode == MGSL_MODE_HDLC || 2369 if (info->params.mode != MGSL_MODE_ASYNC ||
2366 info->params.mode == MGSL_MODE_RAW ||
2367 info->netcount) 2370 info->netcount)
2368 hdlc_mode(info); 2371 sync_mode(info);
2369 else 2372 else
2370 async_mode(info); 2373 async_mode(info);
2371 2374
@@ -2564,6 +2567,10 @@ static int rx_enable(struct slgt_info *info, int enable)
2564 if (enable) { 2567 if (enable) {
2565 if (!info->rx_enabled) 2568 if (!info->rx_enabled)
2566 rx_start(info); 2569 rx_start(info);
2570 else if (enable == 2) {
2571 /* force hunt mode (write 1 to RCR[3]) */
2572 wr_reg16(info, RCR, rd_reg16(info, RCR) | BIT3);
2573 }
2567 } else { 2574 } else {
2568 if (info->rx_enabled) 2575 if (info->rx_enabled)
2569 rx_stop(info); 2576 rx_stop(info);
@@ -3434,7 +3441,7 @@ static void __devexit remove_one(struct pci_dev *dev)
3434{ 3441{
3435} 3442}
3436 3443
3437static struct tty_operations ops = { 3444static const struct tty_operations ops = {
3438 .open = open, 3445 .open = open,
3439 .close = close, 3446 .close = close,
3440 .write = write, 3447 .write = write,
@@ -3748,7 +3755,7 @@ static void tx_start(struct slgt_info *info)
3748{ 3755{
3749 if (!info->tx_enabled) { 3756 if (!info->tx_enabled) {
3750 wr_reg16(info, TCR, 3757 wr_reg16(info, TCR,
3751 (unsigned short)(rd_reg16(info, TCR) | BIT1)); 3758 (unsigned short)((rd_reg16(info, TCR) | BIT1) & ~BIT2));
3752 info->tx_enabled = TRUE; 3759 info->tx_enabled = TRUE;
3753 } 3760 }
3754 3761
@@ -3775,13 +3782,18 @@ static void tx_start(struct slgt_info *info)
3775 tdma_reset(info); 3782 tdma_reset(info);
3776 /* set 1st descriptor address */ 3783 /* set 1st descriptor address */
3777 wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc); 3784 wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc);
3778 if (info->params.mode == MGSL_MODE_RAW) 3785 switch(info->params.mode) {
3786 case MGSL_MODE_RAW:
3787 case MGSL_MODE_MONOSYNC:
3788 case MGSL_MODE_BISYNC:
3779 wr_reg32(info, TDCSR, BIT2 + BIT0); /* IRQ + DMA enable */ 3789 wr_reg32(info, TDCSR, BIT2 + BIT0); /* IRQ + DMA enable */
3780 else 3790 break;
3791 default:
3781 wr_reg32(info, TDCSR, BIT0); /* DMA enable */ 3792 wr_reg32(info, TDCSR, BIT0); /* DMA enable */
3793 }
3782 } 3794 }
3783 3795
3784 if (info->params.mode != MGSL_MODE_RAW) { 3796 if (info->params.mode == MGSL_MODE_HDLC) {
3785 info->tx_timer.expires = jiffies + msecs_to_jiffies(5000); 3797 info->tx_timer.expires = jiffies + msecs_to_jiffies(5000);
3786 add_timer(&info->tx_timer); 3798 add_timer(&info->tx_timer);
3787 } 3799 }
@@ -3814,7 +3826,6 @@ static void tx_stop(struct slgt_info *info)
3814 /* reset and disable transmitter */ 3826 /* reset and disable transmitter */
3815 val = rd_reg16(info, TCR) & ~BIT1; /* clear enable bit */ 3827 val = rd_reg16(info, TCR) & ~BIT1; /* clear enable bit */
3816 wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */ 3828 wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */
3817 wr_reg16(info, TCR, val); /* clear reset */
3818 3829
3819 slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER); 3830 slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER);
3820 3831
@@ -3982,7 +3993,7 @@ static void async_mode(struct slgt_info *info)
3982 enable_loopback(info); 3993 enable_loopback(info);
3983} 3994}
3984 3995
3985static void hdlc_mode(struct slgt_info *info) 3996static void sync_mode(struct slgt_info *info)
3986{ 3997{
3987 unsigned short val; 3998 unsigned short val;
3988 3999
@@ -3992,7 +4003,7 @@ static void hdlc_mode(struct slgt_info *info)
3992 4003
3993 /* TCR (tx control) 4004 /* TCR (tx control)
3994 * 4005 *
3995 * 15..13 mode, 000=HDLC 001=raw sync 4006 * 15..13 mode, 000=HDLC 001=raw 010=async 011=monosync 100=bisync
3996 * 12..10 encoding 4007 * 12..10 encoding
3997 * 09 CRC enable 4008 * 09 CRC enable
3998 * 08 CRC32 4009 * 08 CRC32
@@ -4006,8 +4017,11 @@ static void hdlc_mode(struct slgt_info *info)
4006 */ 4017 */
4007 val = 0; 4018 val = 0;
4008 4019
4009 if (info->params.mode == MGSL_MODE_RAW) 4020 switch(info->params.mode) {
4010 val |= BIT13; 4021 case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break;
4022 case MGSL_MODE_BISYNC: val |= BIT15; break;
4023 case MGSL_MODE_RAW: val |= BIT13; break;
4024 }
4011 if (info->if_mode & MGSL_INTERFACE_RTS_EN) 4025 if (info->if_mode & MGSL_INTERFACE_RTS_EN)
4012 val |= BIT7; 4026 val |= BIT7;
4013 4027
@@ -4058,7 +4072,7 @@ static void hdlc_mode(struct slgt_info *info)
4058 4072
4059 /* RCR (rx control) 4073 /* RCR (rx control)
4060 * 4074 *
4061 * 15..13 mode, 000=HDLC 001=raw sync 4075 * 15..13 mode, 000=HDLC 001=raw 010=async 011=monosync 100=bisync
4062 * 12..10 encoding 4076 * 12..10 encoding
4063 * 09 CRC enable 4077 * 09 CRC enable
4064 * 08 CRC32 4078 * 08 CRC32
@@ -4069,8 +4083,11 @@ static void hdlc_mode(struct slgt_info *info)
4069 */ 4083 */
4070 val = 0; 4084 val = 0;
4071 4085
4072 if (info->params.mode == MGSL_MODE_RAW) 4086 switch(info->params.mode) {
4073 val |= BIT13; 4087 case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break;
4088 case MGSL_MODE_BISYNC: val |= BIT15; break;
4089 case MGSL_MODE_RAW: val |= BIT13; break;
4090 }
4074 4091
4075 switch(info->params.encoding) 4092 switch(info->params.encoding)
4076 { 4093 {
@@ -4309,10 +4326,15 @@ static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last
4309 while(!done) { 4326 while(!done) {
4310 /* reset current buffer for reuse */ 4327 /* reset current buffer for reuse */
4311 info->rbufs[i].status = 0; 4328 info->rbufs[i].status = 0;
4312 if (info->params.mode == MGSL_MODE_RAW) 4329 switch(info->params.mode) {
4330 case MGSL_MODE_RAW:
4331 case MGSL_MODE_MONOSYNC:
4332 case MGSL_MODE_BISYNC:
4313 set_desc_count(info->rbufs[i], info->raw_rx_size); 4333 set_desc_count(info->rbufs[i], info->raw_rx_size);
4314 else 4334 break;
4335 default:
4315 set_desc_count(info->rbufs[i], DMABUFSIZE); 4336 set_desc_count(info->rbufs[i], DMABUFSIZE);
4337 }
4316 4338
4317 if (i == last) 4339 if (i == last)
4318 done = 1; 4340 done = 1;
@@ -4477,13 +4499,24 @@ cleanup:
4477static int rx_get_buf(struct slgt_info *info) 4499static int rx_get_buf(struct slgt_info *info)
4478{ 4500{
4479 unsigned int i = info->rbuf_current; 4501 unsigned int i = info->rbuf_current;
4502 unsigned int count;
4480 4503
4481 if (!desc_complete(info->rbufs[i])) 4504 if (!desc_complete(info->rbufs[i]))
4482 return 0; 4505 return 0;
4483 DBGDATA(info, info->rbufs[i].buf, desc_count(info->rbufs[i]), "rx"); 4506 count = desc_count(info->rbufs[i]);
4484 DBGINFO(("rx_get_buf size=%d\n", desc_count(info->rbufs[i]))); 4507 switch(info->params.mode) {
4485 ldisc_receive_buf(info->tty, info->rbufs[i].buf, 4508 case MGSL_MODE_MONOSYNC:
4486 info->flag_buf, desc_count(info->rbufs[i])); 4509 case MGSL_MODE_BISYNC:
4510 /* ignore residue in byte synchronous modes */
4511 if (desc_residue(info->rbufs[i]))
4512 count--;
4513 break;
4514 }
4515 DBGDATA(info, info->rbufs[i].buf, count, "rx");
4516 DBGINFO(("rx_get_buf size=%d\n", count));
4517 if (count)
4518 ldisc_receive_buf(info->tty, info->rbufs[i].buf,
4519 info->flag_buf, count);
4487 free_rbufs(info, i, i); 4520 free_rbufs(info, i, i);
4488 return 1; 4521 return 1;
4489} 4522}
@@ -4549,8 +4582,13 @@ static void tx_load(struct slgt_info *info, const char *buf, unsigned int size)
4549 size -= count; 4582 size -= count;
4550 buf += count; 4583 buf += count;
4551 4584
4552 if (!size && info->params.mode != MGSL_MODE_RAW) 4585 /*
4553 set_desc_eof(*d, 1); /* HDLC: set EOF of last desc */ 4586 * set EOF bit for last buffer of HDLC frame or
4587 * for every buffer in raw mode
4588 */
4589 if ((!size && info->params.mode == MGSL_MODE_HDLC) ||
4590 info->params.mode == MGSL_MODE_RAW)
4591 set_desc_eof(*d, 1);
4554 else 4592 else
4555 set_desc_eof(*d, 0); 4593 set_desc_eof(*d, 0);
4556 4594
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index 66f3754fbbdf..6eb75dcd7961 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -3929,7 +3929,7 @@ void device_init(int adapter_num, struct pci_dev *pdev)
3929 } 3929 }
3930} 3930}
3931 3931
3932static struct tty_operations ops = { 3932static const struct tty_operations ops = {
3933 .open = open, 3933 .open = open,
3934 .close = close, 3934 .close = close,
3935 .write = write, 3935 .write = write,
diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c
index ee3ca8f1768e..6b4d4d1e343d 100644
--- a/drivers/char/sysrq.c
+++ b/drivers/char/sysrq.c
@@ -113,6 +113,7 @@ static struct sysrq_key_op sysrq_crashdump_op = {
113static void sysrq_handle_reboot(int key, struct pt_regs *pt_regs, 113static void sysrq_handle_reboot(int key, struct pt_regs *pt_regs,
114 struct tty_struct *tty) 114 struct tty_struct *tty)
115{ 115{
116 lockdep_off();
116 local_irq_enable(); 117 local_irq_enable();
117 emergency_restart(); 118 emergency_restart();
118} 119}
@@ -208,7 +209,7 @@ static void send_sig_all(int sig)
208 struct task_struct *p; 209 struct task_struct *p;
209 210
210 for_each_process(p) { 211 for_each_process(p) {
211 if (p->mm && p->pid != 1) 212 if (p->mm && !is_init(p))
212 /* Not swapper, init nor kernel thread */ 213 /* Not swapper, init nor kernel thread */
213 force_sig(sig, p); 214 force_sig(sig, p);
214 } 215 }
diff --git a/drivers/char/tipar.c b/drivers/char/tipar.c
index d30dc09dbbc9..9df0ca1be0e3 100644
--- a/drivers/char/tipar.c
+++ b/drivers/char/tipar.c
@@ -224,14 +224,16 @@ probe_ti_parallel(int minor)
224{ 224{
225 int i; 225 int i;
226 int seq[] = { 0x00, 0x20, 0x10, 0x30 }; 226 int seq[] = { 0x00, 0x20, 0x10, 0x30 };
227 int data;
227 228
228 for (i = 3; i >= 0; i--) { 229 for (i = 3; i >= 0; i--) {
229 outbyte(3, minor); 230 outbyte(3, minor);
230 outbyte(i, minor); 231 outbyte(i, minor);
231 udelay(delay); 232 udelay(delay);
233 data = inbyte(minor) & 0x30;
232 pr_debug("tipar: Probing -> %i: 0x%02x 0x%02x\n", i, 234 pr_debug("tipar: Probing -> %i: 0x%02x 0x%02x\n", i,
233 data & 0x30, seq[i]); 235 data, seq[i]);
234 if ((inbyte(minor) & 0x30) != seq[i]) { 236 if (data != seq[i]) {
235 outbyte(3, minor); 237 outbyte(3, minor);
236 return -1; 238 return -1;
237 } 239 }
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index bb0d9199e994..e90ea39c7c4b 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -129,6 +129,7 @@ LIST_HEAD(tty_drivers); /* linked list of tty drivers */
129/* Semaphore to protect creating and releasing a tty. This is shared with 129/* Semaphore to protect creating and releasing a tty. This is shared with
130 vt.c for deeply disgusting hack reasons */ 130 vt.c for deeply disgusting hack reasons */
131DEFINE_MUTEX(tty_mutex); 131DEFINE_MUTEX(tty_mutex);
132EXPORT_SYMBOL(tty_mutex);
132 133
133#ifdef CONFIG_UNIX98_PTYS 134#ifdef CONFIG_UNIX98_PTYS
134extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */ 135extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */
@@ -160,17 +161,11 @@ static void release_mem(struct tty_struct *tty, int idx);
160 * been initialized in any way but has been zeroed 161 * been initialized in any way but has been zeroed
161 * 162 *
162 * Locking: none 163 * Locking: none
163 * FIXME: use kzalloc
164 */ 164 */
165 165
166static struct tty_struct *alloc_tty_struct(void) 166static struct tty_struct *alloc_tty_struct(void)
167{ 167{
168 struct tty_struct *tty; 168 return kzalloc(sizeof(struct tty_struct), GFP_KERNEL);
169
170 tty = kmalloc(sizeof(struct tty_struct), GFP_KERNEL);
171 if (tty)
172 memset(tty, 0, sizeof(struct tty_struct));
173 return tty;
174} 169}
175 170
176static void tty_buffer_free_all(struct tty_struct *); 171static void tty_buffer_free_all(struct tty_struct *);
@@ -483,10 +478,9 @@ int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars,
483 tb->used += space; 478 tb->used += space;
484 copied += space; 479 copied += space;
485 chars += space; 480 chars += space;
486 } 481 /* There is a small chance that we need to split the data over
487 /* There is a small chance that we need to split the data over 482 several buffers. If this is the case we must loop */
488 several buffers. If this is the case we must loop */ 483 } while (unlikely(size > copied));
489 while (unlikely(size > copied));
490 return copied; 484 return copied;
491} 485}
492EXPORT_SYMBOL(tty_insert_flip_string); 486EXPORT_SYMBOL(tty_insert_flip_string);
@@ -521,10 +515,9 @@ int tty_insert_flip_string_flags(struct tty_struct *tty,
521 copied += space; 515 copied += space;
522 chars += space; 516 chars += space;
523 flags += space; 517 flags += space;
524 } 518 /* There is a small chance that we need to split the data over
525 /* There is a small chance that we need to split the data over 519 several buffers. If this is the case we must loop */
526 several buffers. If this is the case we must loop */ 520 } while (unlikely(size > copied));
527 while (unlikely(size > copied));
528 return copied; 521 return copied;
529} 522}
530EXPORT_SYMBOL(tty_insert_flip_string_flags); 523EXPORT_SYMBOL(tty_insert_flip_string_flags);
@@ -626,9 +619,9 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
626 619
627static void tty_set_termios_ldisc(struct tty_struct *tty, int num) 620static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
628{ 621{
629 down(&tty->termios_sem); 622 mutex_lock(&tty->termios_mutex);
630 tty->termios->c_line = num; 623 tty->termios->c_line = num;
631 up(&tty->termios_sem); 624 mutex_unlock(&tty->termios_mutex);
632} 625}
633 626
634/* 627/*
@@ -1346,9 +1339,9 @@ static void do_tty_hangup(void *data)
1346 */ 1339 */
1347 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) 1340 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS)
1348 { 1341 {
1349 down(&tty->termios_sem); 1342 mutex_lock(&tty->termios_mutex);
1350 *tty->termios = tty->driver->init_termios; 1343 *tty->termios = tty->driver->init_termios;
1351 up(&tty->termios_sem); 1344 mutex_unlock(&tty->termios_mutex);
1352 } 1345 }
1353 1346
1354 /* Defer ldisc switch */ 1347 /* Defer ldisc switch */
@@ -2072,8 +2065,9 @@ fail_no_mem:
2072 2065
2073 /* call the tty release_mem routine to clean out this slot */ 2066 /* call the tty release_mem routine to clean out this slot */
2074release_mem_out: 2067release_mem_out:
2075 printk(KERN_INFO "init_dev: ldisc open failed, " 2068 if (printk_ratelimit())
2076 "clearing slot %d\n", idx); 2069 printk(KERN_INFO "init_dev: ldisc open failed, "
2070 "clearing slot %d\n", idx);
2077 release_mem(tty, idx); 2071 release_mem(tty, idx);
2078 goto end_init; 2072 goto end_init;
2079} 2073}
@@ -2726,6 +2720,8 @@ static int tty_fasync(int fd, struct file * filp, int on)
2726 * Locking: 2720 * Locking:
2727 * Called functions take tty_ldisc_lock 2721 * Called functions take tty_ldisc_lock
2728 * current->signal->tty check is safe without locks 2722 * current->signal->tty check is safe without locks
2723 *
2724 * FIXME: may race normal receive processing
2729 */ 2725 */
2730 2726
2731static int tiocsti(struct tty_struct *tty, char __user *p) 2727static int tiocsti(struct tty_struct *tty, char __user *p)
@@ -2748,18 +2744,21 @@ static int tiocsti(struct tty_struct *tty, char __user *p)
2748 * @tty; tty 2744 * @tty; tty
2749 * @arg: user buffer for result 2745 * @arg: user buffer for result
2750 * 2746 *
2751 * Copies the kernel idea of the window size into the user buffer. No 2747 * Copies the kernel idea of the window size into the user buffer.
2752 * locking is done.
2753 * 2748 *
2754 * FIXME: Returning random values racing a window size set is wrong 2749 * Locking: tty->termios_sem is taken to ensure the winsize data
2755 * should lock here against that 2750 * is consistent.
2756 */ 2751 */
2757 2752
2758static int tiocgwinsz(struct tty_struct *tty, struct winsize __user * arg) 2753static int tiocgwinsz(struct tty_struct *tty, struct winsize __user * arg)
2759{ 2754{
2760 if (copy_to_user(arg, &tty->winsize, sizeof(*arg))) 2755 int err;
2761 return -EFAULT; 2756
2762 return 0; 2757 mutex_lock(&tty->termios_mutex);
2758 err = copy_to_user(arg, &tty->winsize, sizeof(*arg));
2759 mutex_unlock(&tty->termios_mutex);
2760
2761 return err ? -EFAULT: 0;
2763} 2762}
2764 2763
2765/** 2764/**
@@ -2772,12 +2771,11 @@ static int tiocgwinsz(struct tty_struct *tty, struct winsize __user * arg)
2772 * actually has driver level meaning and triggers a VC resize. 2771 * actually has driver level meaning and triggers a VC resize.
2773 * 2772 *
2774 * Locking: 2773 * Locking:
2775 * The console_sem is used to ensure we do not try and resize 2774 * Called function use the console_sem is used to ensure we do
2776 * the console twice at once. 2775 * not try and resize the console twice at once.
2777 * FIXME: Two racing size sets may leave the console and kernel 2776 * The tty->termios_sem is used to ensure we don't double
2778 * parameters disagreeing. Is this exploitable ? 2777 * resize and get confused. Lock order - tty->termios.sem before
2779 * FIXME: Random values racing a window size get is wrong 2778 * console sem
2780 * should lock here against that
2781 */ 2779 */
2782 2780
2783static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty, 2781static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
@@ -2787,17 +2785,18 @@ static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
2787 2785
2788 if (copy_from_user(&tmp_ws, arg, sizeof(*arg))) 2786 if (copy_from_user(&tmp_ws, arg, sizeof(*arg)))
2789 return -EFAULT; 2787 return -EFAULT;
2788
2789 mutex_lock(&tty->termios_mutex);
2790 if (!memcmp(&tmp_ws, &tty->winsize, sizeof(*arg))) 2790 if (!memcmp(&tmp_ws, &tty->winsize, sizeof(*arg)))
2791 return 0; 2791 goto done;
2792
2792#ifdef CONFIG_VT 2793#ifdef CONFIG_VT
2793 if (tty->driver->type == TTY_DRIVER_TYPE_CONSOLE) { 2794 if (tty->driver->type == TTY_DRIVER_TYPE_CONSOLE) {
2794 int rc; 2795 if (vc_lock_resize(tty->driver_data, tmp_ws.ws_col,
2795 2796 tmp_ws.ws_row)) {
2796 acquire_console_sem(); 2797 mutex_unlock(&tty->termios_mutex);
2797 rc = vc_resize(tty->driver_data, tmp_ws.ws_col, tmp_ws.ws_row); 2798 return -ENXIO;
2798 release_console_sem(); 2799 }
2799 if (rc)
2800 return -ENXIO;
2801 } 2800 }
2802#endif 2801#endif
2803 if (tty->pgrp > 0) 2802 if (tty->pgrp > 0)
@@ -2806,6 +2805,8 @@ static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
2806 kill_pg(real_tty->pgrp, SIGWINCH, 1); 2805 kill_pg(real_tty->pgrp, SIGWINCH, 1);
2807 tty->winsize = tmp_ws; 2806 tty->winsize = tmp_ws;
2808 real_tty->winsize = tmp_ws; 2807 real_tty->winsize = tmp_ws;
2808done:
2809 mutex_unlock(&tty->termios_mutex);
2809 return 0; 2810 return 0;
2810} 2811}
2811 2812
@@ -2880,9 +2881,7 @@ static int fionbio(struct file *file, int __user *p)
2880 * Locking: 2881 * Locking:
2881 * Takes tasklist lock internally to walk sessions 2882 * Takes tasklist lock internally to walk sessions
2882 * Takes task_lock() when updating signal->tty 2883 * Takes task_lock() when updating signal->tty
2883 * 2884 * Takes tty_mutex() to protect tty instance
2884 * FIXME: tty_mutex is needed to protect signal->tty references.
2885 * FIXME: why task_lock on the signal->tty reference ??
2886 * 2885 *
2887 */ 2886 */
2888 2887
@@ -2917,9 +2916,11 @@ static int tiocsctty(struct tty_struct *tty, int arg)
2917 } else 2916 } else
2918 return -EPERM; 2917 return -EPERM;
2919 } 2918 }
2919 mutex_lock(&tty_mutex);
2920 task_lock(current); 2920 task_lock(current);
2921 current->signal->tty = tty; 2921 current->signal->tty = tty;
2922 task_unlock(current); 2922 task_unlock(current);
2923 mutex_unlock(&tty_mutex);
2923 current->signal->tty_old_pgrp = 0; 2924 current->signal->tty_old_pgrp = 0;
2924 tty->session = current->signal->session; 2925 tty->session = current->signal->session;
2925 tty->pgrp = process_group(current); 2926 tty->pgrp = process_group(current);
@@ -2959,8 +2960,6 @@ static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
2959 * permitted where the tty session is our session. 2960 * permitted where the tty session is our session.
2960 * 2961 *
2961 * Locking: None 2962 * Locking: None
2962 *
2963 * FIXME: current->signal->tty referencing is unsafe.
2964 */ 2963 */
2965 2964
2966static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) 2965static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
@@ -3039,19 +3038,20 @@ static int tiocsetd(struct tty_struct *tty, int __user *p)
3039 * timed break functionality. 3038 * timed break functionality.
3040 * 3039 *
3041 * Locking: 3040 * Locking:
3042 * None 3041 * atomic_write_lock serializes
3043 * 3042 *
3044 * FIXME:
3045 * What if two overlap
3046 */ 3043 */
3047 3044
3048static int send_break(struct tty_struct *tty, unsigned int duration) 3045static int send_break(struct tty_struct *tty, unsigned int duration)
3049{ 3046{
3047 if (mutex_lock_interruptible(&tty->atomic_write_lock))
3048 return -EINTR;
3050 tty->driver->break_ctl(tty, -1); 3049 tty->driver->break_ctl(tty, -1);
3051 if (!signal_pending(current)) { 3050 if (!signal_pending(current)) {
3052 msleep_interruptible(duration); 3051 msleep_interruptible(duration);
3053 } 3052 }
3054 tty->driver->break_ctl(tty, 0); 3053 tty->driver->break_ctl(tty, 0);
3054 mutex_unlock(&tty->atomic_write_lock);
3055 if (signal_pending(current)) 3055 if (signal_pending(current))
3056 return -EINTR; 3056 return -EINTR;
3057 return 0; 3057 return 0;
@@ -3144,6 +3144,8 @@ int tty_ioctl(struct inode * inode, struct file * file,
3144 if (tty_paranoia_check(tty, inode, "tty_ioctl")) 3144 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
3145 return -EINVAL; 3145 return -EINVAL;
3146 3146
3147 /* CHECKME: is this safe as one end closes ? */
3148
3147 real_tty = tty; 3149 real_tty = tty;
3148 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && 3150 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
3149 tty->driver->subtype == PTY_TYPE_MASTER) 3151 tty->driver->subtype == PTY_TYPE_MASTER)
@@ -3580,7 +3582,7 @@ static void initialize_tty_struct(struct tty_struct *tty)
3580 tty_buffer_init(tty); 3582 tty_buffer_init(tty);
3581 INIT_WORK(&tty->buf.work, flush_to_ldisc, tty); 3583 INIT_WORK(&tty->buf.work, flush_to_ldisc, tty);
3582 init_MUTEX(&tty->buf.pty_sem); 3584 init_MUTEX(&tty->buf.pty_sem);
3583 init_MUTEX(&tty->termios_sem); 3585 mutex_init(&tty->termios_mutex);
3584 init_waitqueue_head(&tty->write_wait); 3586 init_waitqueue_head(&tty->write_wait);
3585 init_waitqueue_head(&tty->read_wait); 3587 init_waitqueue_head(&tty->read_wait);
3586 INIT_WORK(&tty->hangup_work, do_tty_hangup, tty); 3588 INIT_WORK(&tty->hangup_work, do_tty_hangup, tty);
@@ -3678,7 +3680,8 @@ void put_tty_driver(struct tty_driver *driver)
3678 kfree(driver); 3680 kfree(driver);
3679} 3681}
3680 3682
3681void tty_set_operations(struct tty_driver *driver, struct tty_operations *op) 3683void tty_set_operations(struct tty_driver *driver,
3684 const struct tty_operations *op)
3682{ 3685{
3683 driver->open = op->open; 3686 driver->open = op->open;
3684 driver->close = op->close; 3687 driver->close = op->close;
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
index 4ad47d321bd4..3b6fa7b0be8b 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/char/tty_ioctl.c
@@ -20,6 +20,7 @@
20#include <linux/mm.h> 20#include <linux/mm.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/bitops.h> 22#include <linux/bitops.h>
23#include <linux/mutex.h>
23 24
24#include <asm/io.h> 25#include <asm/io.h>
25#include <asm/uaccess.h> 26#include <asm/uaccess.h>
@@ -131,7 +132,7 @@ static void change_termios(struct tty_struct * tty, struct termios * new_termios
131 132
132 /* FIXME: we need to decide on some locking/ordering semantics 133 /* FIXME: we need to decide on some locking/ordering semantics
133 for the set_termios notification eventually */ 134 for the set_termios notification eventually */
134 down(&tty->termios_sem); 135 mutex_lock(&tty->termios_mutex);
135 136
136 *tty->termios = *new_termios; 137 *tty->termios = *new_termios;
137 unset_locked_termios(tty->termios, &old_termios, tty->termios_locked); 138 unset_locked_termios(tty->termios, &old_termios, tty->termios_locked);
@@ -176,7 +177,7 @@ static void change_termios(struct tty_struct * tty, struct termios * new_termios
176 (ld->set_termios)(tty, &old_termios); 177 (ld->set_termios)(tty, &old_termios);
177 tty_ldisc_deref(ld); 178 tty_ldisc_deref(ld);
178 } 179 }
179 up(&tty->termios_sem); 180 mutex_unlock(&tty->termios_mutex);
180} 181}
181 182
182/** 183/**
@@ -284,13 +285,13 @@ static int get_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb)
284{ 285{
285 struct sgttyb tmp; 286 struct sgttyb tmp;
286 287
287 down(&tty->termios_sem); 288 mutex_lock(&tty->termios_mutex);
288 tmp.sg_ispeed = 0; 289 tmp.sg_ispeed = 0;
289 tmp.sg_ospeed = 0; 290 tmp.sg_ospeed = 0;
290 tmp.sg_erase = tty->termios->c_cc[VERASE]; 291 tmp.sg_erase = tty->termios->c_cc[VERASE];
291 tmp.sg_kill = tty->termios->c_cc[VKILL]; 292 tmp.sg_kill = tty->termios->c_cc[VKILL];
292 tmp.sg_flags = get_sgflags(tty); 293 tmp.sg_flags = get_sgflags(tty);
293 up(&tty->termios_sem); 294 mutex_unlock(&tty->termios_mutex);
294 295
295 return copy_to_user(sgttyb, &tmp, sizeof(tmp)) ? -EFAULT : 0; 296 return copy_to_user(sgttyb, &tmp, sizeof(tmp)) ? -EFAULT : 0;
296} 297}
@@ -345,12 +346,12 @@ static int set_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb)
345 if (copy_from_user(&tmp, sgttyb, sizeof(tmp))) 346 if (copy_from_user(&tmp, sgttyb, sizeof(tmp)))
346 return -EFAULT; 347 return -EFAULT;
347 348
348 down(&tty->termios_sem); 349 mutex_lock(&tty->termios_mutex);
349 termios = *tty->termios; 350 termios = *tty->termios;
350 termios.c_cc[VERASE] = tmp.sg_erase; 351 termios.c_cc[VERASE] = tmp.sg_erase;
351 termios.c_cc[VKILL] = tmp.sg_kill; 352 termios.c_cc[VKILL] = tmp.sg_kill;
352 set_sgflags(&termios, tmp.sg_flags); 353 set_sgflags(&termios, tmp.sg_flags);
353 up(&tty->termios_sem); 354 mutex_unlock(&tty->termios_mutex);
354 change_termios(tty, &termios); 355 change_termios(tty, &termios);
355 return 0; 356 return 0;
356} 357}
@@ -422,24 +423,28 @@ static int set_ltchars(struct tty_struct * tty, struct ltchars __user * ltchars)
422 * 423 *
423 * Send a high priority character to the tty even if stopped 424 * Send a high priority character to the tty even if stopped
424 * 425 *
425 * Locking: none 426 * Locking: none for xchar method, write ordering for write method.
426 *
427 * FIXME: overlapping calls with start/stop tty lose state of tty
428 */ 427 */
429 428
430static void send_prio_char(struct tty_struct *tty, char ch) 429static int send_prio_char(struct tty_struct *tty, char ch)
431{ 430{
432 int was_stopped = tty->stopped; 431 int was_stopped = tty->stopped;
433 432
434 if (tty->driver->send_xchar) { 433 if (tty->driver->send_xchar) {
435 tty->driver->send_xchar(tty, ch); 434 tty->driver->send_xchar(tty, ch);
436 return; 435 return 0;
437 } 436 }
437
438 if (mutex_lock_interruptible(&tty->atomic_write_lock))
439 return -ERESTARTSYS;
440
438 if (was_stopped) 441 if (was_stopped)
439 start_tty(tty); 442 start_tty(tty);
440 tty->driver->write(tty, &ch, 1); 443 tty->driver->write(tty, &ch, 1);
441 if (was_stopped) 444 if (was_stopped)
442 stop_tty(tty); 445 stop_tty(tty);
446 mutex_unlock(&tty->atomic_write_lock);
447 return 0;
443} 448}
444 449
445int n_tty_ioctl(struct tty_struct * tty, struct file * file, 450int n_tty_ioctl(struct tty_struct * tty, struct file * file,
@@ -513,11 +518,11 @@ int n_tty_ioctl(struct tty_struct * tty, struct file * file,
513 break; 518 break;
514 case TCIOFF: 519 case TCIOFF:
515 if (STOP_CHAR(tty) != __DISABLED_CHAR) 520 if (STOP_CHAR(tty) != __DISABLED_CHAR)
516 send_prio_char(tty, STOP_CHAR(tty)); 521 return send_prio_char(tty, STOP_CHAR(tty));
517 break; 522 break;
518 case TCION: 523 case TCION:
519 if (START_CHAR(tty) != __DISABLED_CHAR) 524 if (START_CHAR(tty) != __DISABLED_CHAR)
520 send_prio_char(tty, START_CHAR(tty)); 525 return send_prio_char(tty, START_CHAR(tty));
521 break; 526 break;
522 default: 527 default:
523 return -EINVAL; 528 return -EINVAL;
@@ -592,11 +597,11 @@ int n_tty_ioctl(struct tty_struct * tty, struct file * file,
592 case TIOCSSOFTCAR: 597 case TIOCSSOFTCAR:
593 if (get_user(arg, (unsigned int __user *) arg)) 598 if (get_user(arg, (unsigned int __user *) arg))
594 return -EFAULT; 599 return -EFAULT;
595 down(&tty->termios_sem); 600 mutex_lock(&tty->termios_mutex);
596 tty->termios->c_cflag = 601 tty->termios->c_cflag =
597 ((tty->termios->c_cflag & ~CLOCAL) | 602 ((tty->termios->c_cflag & ~CLOCAL) |
598 (arg ? CLOCAL : 0)); 603 (arg ? CLOCAL : 0));
599 up(&tty->termios_sem); 604 mutex_unlock(&tty->termios_mutex);
600 return 0; 605 return 0;
601 default: 606 default:
602 return -ENOIOCTLCMD; 607 return -ENOIOCTLCMD;
diff --git a/drivers/char/vc_screen.c b/drivers/char/vc_screen.c
index a9247b5213d5..bd7a98c6ea7a 100644
--- a/drivers/char/vc_screen.c
+++ b/drivers/char/vc_screen.c
@@ -474,14 +474,15 @@ static const struct file_operations vcs_fops = {
474 474
475static struct class *vc_class; 475static struct class *vc_class;
476 476
477void vcs_make_devfs(struct tty_struct *tty) 477void vcs_make_sysfs(struct tty_struct *tty)
478{ 478{
479 class_device_create(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 1), 479 class_device_create(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 1),
480 NULL, "vcs%u", tty->index + 1); 480 NULL, "vcs%u", tty->index + 1);
481 class_device_create(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 129), 481 class_device_create(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 129),
482 NULL, "vcsa%u", tty->index + 1); 482 NULL, "vcsa%u", tty->index + 1);
483} 483}
484void vcs_remove_devfs(struct tty_struct *tty) 484
485void vcs_remove_sysfs(struct tty_struct *tty)
485{ 486{
486 class_device_destroy(vc_class, MKDEV(VCS_MAJOR, tty->index + 1)); 487 class_device_destroy(vc_class, MKDEV(VCS_MAJOR, tty->index + 1));
487 class_device_destroy(vc_class, MKDEV(VCS_MAJOR, tty->index + 129)); 488 class_device_destroy(vc_class, MKDEV(VCS_MAJOR, tty->index + 129));
diff --git a/drivers/char/viocons.c b/drivers/char/viocons.c
index f3efeaf2826e..a362ee9c92dd 100644
--- a/drivers/char/viocons.c
+++ b/drivers/char/viocons.c
@@ -1047,7 +1047,7 @@ static int send_open(HvLpIndex remoteLp, void *sem)
1047 0, 0, 0, 0); 1047 0, 0, 0, 0);
1048} 1048}
1049 1049
1050static struct tty_operations serial_ops = { 1050static const struct tty_operations serial_ops = {
1051 .open = viotty_open, 1051 .open = viotty_open,
1052 .close = viotty_close, 1052 .close = viotty_close,
1053 .write = viotty_write, 1053 .write = viotty_write,
diff --git a/drivers/char/vme_scc.c b/drivers/char/vme_scc.c
index bfe5ea948f6a..c2ca31eb850b 100644
--- a/drivers/char/vme_scc.c
+++ b/drivers/char/vme_scc.c
@@ -113,7 +113,7 @@ static struct real_driver scc_real_driver = {
113}; 113};
114 114
115 115
116static struct tty_operations scc_ops = { 116static const struct tty_operations scc_ops = {
117 .open = scc_open, 117 .open = scc_open,
118 .close = gs_close, 118 .close = gs_close,
119 .write = gs_write, 119 .write = gs_write,
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index da7e66a2a38b..8e4413f6fbaf 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -63,6 +63,13 @@
63 * 63 *
64 * Removed console_lock, enabled interrupts across all console operations 64 * Removed console_lock, enabled interrupts across all console operations
65 * 13 March 2001, Andrew Morton 65 * 13 March 2001, Andrew Morton
66 *
67 * Fixed UTF-8 mode so alternate charset modes always work according
68 * to control sequences interpreted in do_con_trol function
69 * preserving backward VT100 semigraphics compatibility,
70 * malformed UTF sequences represented as sequences of replacement glyphs,
71 * original codes or '?' as a last resort if replacement glyph is undefined
72 * by Adam Tla/lka <atlka@pg.gda.pl>, Aug 2006
66 */ 73 */
67 74
68#include <linux/module.h> 75#include <linux/module.h>
@@ -99,7 +106,8 @@
99#define MAX_NR_CON_DRIVER 16 106#define MAX_NR_CON_DRIVER 16
100 107
101#define CON_DRIVER_FLAG_MODULE 1 108#define CON_DRIVER_FLAG_MODULE 1
102#define CON_DRIVER_FLAG_INIT 2 109#define CON_DRIVER_FLAG_INIT 2
110#define CON_DRIVER_FLAG_ATTR 4
103 111
104struct con_driver { 112struct con_driver {
105 const struct consw *con; 113 const struct consw *con;
@@ -128,16 +136,8 @@ const struct consw *conswitchp;
128#define DEFAULT_BELL_PITCH 750 136#define DEFAULT_BELL_PITCH 750
129#define DEFAULT_BELL_DURATION (HZ/8) 137#define DEFAULT_BELL_DURATION (HZ/8)
130 138
131extern void vcs_make_devfs(struct tty_struct *tty); 139extern void vcs_make_sysfs(struct tty_struct *tty);
132extern void vcs_remove_devfs(struct tty_struct *tty); 140extern void vcs_remove_sysfs(struct tty_struct *tty);
133
134extern void console_map_init(void);
135#ifdef CONFIG_PROM_CONSOLE
136extern void prom_con_init(void);
137#endif
138#ifdef CONFIG_MDA_CONSOLE
139extern int mda_console_init(void);
140#endif
141 141
142struct vc vc_cons [MAX_NR_CONSOLES]; 142struct vc vc_cons [MAX_NR_CONSOLES];
143 143
@@ -730,7 +730,8 @@ int vc_allocate(unsigned int currcons) /* return 0 on success */
730 visual_init(vc, currcons, 1); 730 visual_init(vc, currcons, 1);
731 if (!*vc->vc_uni_pagedir_loc) 731 if (!*vc->vc_uni_pagedir_loc)
732 con_set_default_unimap(vc); 732 con_set_default_unimap(vc);
733 vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size, GFP_KERNEL); 733 if (!vc->vc_kmalloced)
734 vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size, GFP_KERNEL);
734 if (!vc->vc_screenbuf) { 735 if (!vc->vc_screenbuf) {
735 kfree(vc); 736 kfree(vc);
736 vc_cons[currcons].d = NULL; 737 vc_cons[currcons].d = NULL;
@@ -878,14 +879,24 @@ int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines)
878 return err; 879 return err;
879} 880}
880 881
882int vc_lock_resize(struct vc_data *vc, unsigned int cols, unsigned int lines)
883{
884 int rc;
885
886 acquire_console_sem();
887 rc = vc_resize(vc, cols, lines);
888 release_console_sem();
889 return rc;
890}
881 891
882void vc_disallocate(unsigned int currcons) 892void vc_deallocate(unsigned int currcons)
883{ 893{
884 WARN_CONSOLE_UNLOCKED(); 894 WARN_CONSOLE_UNLOCKED();
885 895
886 if (vc_cons_allocated(currcons)) { 896 if (vc_cons_allocated(currcons)) {
887 struct vc_data *vc = vc_cons[currcons].d; 897 struct vc_data *vc = vc_cons[currcons].d;
888 vc->vc_sw->con_deinit(vc); 898 vc->vc_sw->con_deinit(vc);
899 put_pid(vc->vt_pid);
889 module_put(vc->vc_sw->owner); 900 module_put(vc->vc_sw->owner);
890 if (vc->vc_kmalloced) 901 if (vc->vc_kmalloced)
891 kfree(vc->vc_screenbuf); 902 kfree(vc->vc_screenbuf);
@@ -2005,17 +2016,23 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
2005 /* Do no translation at all in control states */ 2016 /* Do no translation at all in control states */
2006 if (vc->vc_state != ESnormal) { 2017 if (vc->vc_state != ESnormal) {
2007 tc = c; 2018 tc = c;
2008 } else if (vc->vc_utf) { 2019 } else if (vc->vc_utf && !vc->vc_disp_ctrl) {
2009 /* Combine UTF-8 into Unicode */ 2020 /* Combine UTF-8 into Unicode */
2010 /* Incomplete characters silently ignored */ 2021 /* Malformed sequences as sequences of replacement glyphs */
2022rescan_last_byte:
2011 if(c > 0x7f) { 2023 if(c > 0x7f) {
2012 if (vc->vc_utf_count > 0 && (c & 0xc0) == 0x80) { 2024 if (vc->vc_utf_count) {
2013 vc->vc_utf_char = (vc->vc_utf_char << 6) | (c & 0x3f); 2025 if ((c & 0xc0) == 0x80) {
2014 vc->vc_utf_count--; 2026 vc->vc_utf_char = (vc->vc_utf_char << 6) | (c & 0x3f);
2015 if (vc->vc_utf_count == 0) 2027 if (--vc->vc_utf_count) {
2016 tc = c = vc->vc_utf_char; 2028 vc->vc_npar++;
2017 else continue; 2029 continue;
2030 }
2031 tc = c = vc->vc_utf_char;
2032 } else
2033 goto replacement_glyph;
2018 } else { 2034 } else {
2035 vc->vc_npar = 0;
2019 if ((c & 0xe0) == 0xc0) { 2036 if ((c & 0xe0) == 0xc0) {
2020 vc->vc_utf_count = 1; 2037 vc->vc_utf_count = 1;
2021 vc->vc_utf_char = (c & 0x1f); 2038 vc->vc_utf_char = (c & 0x1f);
@@ -2032,14 +2049,15 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
2032 vc->vc_utf_count = 5; 2049 vc->vc_utf_count = 5;
2033 vc->vc_utf_char = (c & 0x01); 2050 vc->vc_utf_char = (c & 0x01);
2034 } else 2051 } else
2035 vc->vc_utf_count = 0; 2052 goto replacement_glyph;
2036 continue; 2053 continue;
2037 } 2054 }
2038 } else { 2055 } else {
2056 if (vc->vc_utf_count)
2057 goto replacement_glyph;
2039 tc = c; 2058 tc = c;
2040 vc->vc_utf_count = 0;
2041 } 2059 }
2042 } else { /* no utf */ 2060 } else { /* no utf or alternate charset mode */
2043 tc = vc->vc_translate[vc->vc_toggle_meta ? (c | 0x80) : c]; 2061 tc = vc->vc_translate[vc->vc_toggle_meta ? (c | 0x80) : c];
2044 } 2062 }
2045 2063
@@ -2054,31 +2072,33 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
2054 * direct-to-font zone in UTF-8 mode. 2072 * direct-to-font zone in UTF-8 mode.
2055 */ 2073 */
2056 ok = tc && (c >= 32 || 2074 ok = tc && (c >= 32 ||
2057 (!vc->vc_utf && !(((vc->vc_disp_ctrl ? CTRL_ALWAYS 2075 !(vc->vc_disp_ctrl ? (CTRL_ALWAYS >> c) & 1 :
2058 : CTRL_ACTION) >> c) & 1))) 2076 vc->vc_utf || ((CTRL_ACTION >> c) & 1)))
2059 && (c != 127 || vc->vc_disp_ctrl) 2077 && (c != 127 || vc->vc_disp_ctrl)
2060 && (c != 128+27); 2078 && (c != 128+27);
2061 2079
2062 if (vc->vc_state == ESnormal && ok) { 2080 if (vc->vc_state == ESnormal && ok) {
2063 /* Now try to find out how to display it */ 2081 /* Now try to find out how to display it */
2064 tc = conv_uni_to_pc(vc, tc); 2082 tc = conv_uni_to_pc(vc, tc);
2065 if ( tc == -4 ) { 2083 if (tc & ~charmask) {
2084 if ( tc == -4 ) {
2066 /* If we got -4 (not found) then see if we have 2085 /* If we got -4 (not found) then see if we have
2067 defined a replacement character (U+FFFD) */ 2086 defined a replacement character (U+FFFD) */
2068 tc = conv_uni_to_pc(vc, 0xfffd); 2087replacement_glyph:
2069 2088 tc = conv_uni_to_pc(vc, 0xfffd);
2070 /* One reason for the -4 can be that we just 2089 if (!(tc & ~charmask))
2071 did a clear_unimap(); 2090 goto display_glyph;
2072 try at least to show something. */ 2091 } else if ( tc != -3 )
2073 if (tc == -4) 2092 continue; /* nothing to display */
2074 tc = c; 2093 /* no hash table or no replacement --
2075 } else if ( tc == -3 ) { 2094 * hope for the best */
2076 /* Bad hash table -- hope for the best */ 2095 if ( c & ~charmask )
2077 tc = c; 2096 tc = '?';
2078 } 2097 else
2079 if (tc & ~charmask) 2098 tc = c;
2080 continue; /* Conversion failed */ 2099 }
2081 2100
2101display_glyph:
2082 if (vc->vc_need_wrap || vc->vc_decim) 2102 if (vc->vc_need_wrap || vc->vc_decim)
2083 FLUSH 2103 FLUSH
2084 if (vc->vc_need_wrap) { 2104 if (vc->vc_need_wrap) {
@@ -2102,6 +2122,15 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
2102 vc->vc_x++; 2122 vc->vc_x++;
2103 draw_to = (vc->vc_pos += 2); 2123 draw_to = (vc->vc_pos += 2);
2104 } 2124 }
2125 if (vc->vc_utf_count) {
2126 if (vc->vc_npar) {
2127 vc->vc_npar--;
2128 goto display_glyph;
2129 }
2130 vc->vc_utf_count = 0;
2131 c = orig;
2132 goto rescan_last_byte;
2133 }
2105 continue; 2134 continue;
2106 } 2135 }
2107 FLUSH 2136 FLUSH
@@ -2498,7 +2527,7 @@ static int con_open(struct tty_struct *tty, struct file *filp)
2498 tty->winsize.ws_col = vc_cons[currcons].d->vc_cols; 2527 tty->winsize.ws_col = vc_cons[currcons].d->vc_cols;
2499 } 2528 }
2500 release_console_sem(); 2529 release_console_sem();
2501 vcs_make_devfs(tty); 2530 vcs_make_sysfs(tty);
2502 return ret; 2531 return ret;
2503 } 2532 }
2504 } 2533 }
@@ -2511,7 +2540,7 @@ static int con_open(struct tty_struct *tty, struct file *filp)
2511 * and taking a ref against the tty while we're in the process of forgetting 2540 * and taking a ref against the tty while we're in the process of forgetting
2512 * about it and cleaning things up. 2541 * about it and cleaning things up.
2513 * 2542 *
2514 * This is because vcs_remove_devfs() can sleep and will drop the BKL. 2543 * This is because vcs_remove_sysfs() can sleep and will drop the BKL.
2515 */ 2544 */
2516static void con_close(struct tty_struct *tty, struct file *filp) 2545static void con_close(struct tty_struct *tty, struct file *filp)
2517{ 2546{
@@ -2524,7 +2553,7 @@ static void con_close(struct tty_struct *tty, struct file *filp)
2524 vc->vc_tty = NULL; 2553 vc->vc_tty = NULL;
2525 tty->driver_data = NULL; 2554 tty->driver_data = NULL;
2526 release_console_sem(); 2555 release_console_sem();
2527 vcs_remove_devfs(tty); 2556 vcs_remove_sysfs(tty);
2528 mutex_unlock(&tty_mutex); 2557 mutex_unlock(&tty_mutex);
2529 /* 2558 /*
2530 * tty_mutex is released, but we still hold BKL, so there is 2559 * tty_mutex is released, but we still hold BKL, so there is
@@ -2639,7 +2668,7 @@ static int __init con_init(void)
2639} 2668}
2640console_initcall(con_init); 2669console_initcall(con_init);
2641 2670
2642static struct tty_operations con_ops = { 2671static const struct tty_operations con_ops = {
2643 .open = con_open, 2672 .open = con_open,
2644 .close = con_close, 2673 .close = con_close,
2645 .write = con_write, 2674 .write = con_write,
@@ -3034,22 +3063,37 @@ static struct class_device_attribute class_device_attrs[] = {
3034static int vtconsole_init_class_device(struct con_driver *con) 3063static int vtconsole_init_class_device(struct con_driver *con)
3035{ 3064{
3036 int i; 3065 int i;
3066 int error = 0;
3037 3067
3068 con->flag |= CON_DRIVER_FLAG_ATTR;
3038 class_set_devdata(con->class_dev, con); 3069 class_set_devdata(con->class_dev, con);
3039 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) 3070 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) {
3040 class_device_create_file(con->class_dev, 3071 error = class_device_create_file(con->class_dev,
3041 &class_device_attrs[i]); 3072 &class_device_attrs[i]);
3073 if (error)
3074 break;
3075 }
3042 3076
3043 return 0; 3077 if (error) {
3078 while (--i >= 0)
3079 class_device_remove_file(con->class_dev,
3080 &class_device_attrs[i]);
3081 con->flag &= ~CON_DRIVER_FLAG_ATTR;
3082 }
3083
3084 return error;
3044} 3085}
3045 3086
3046static void vtconsole_deinit_class_device(struct con_driver *con) 3087static void vtconsole_deinit_class_device(struct con_driver *con)
3047{ 3088{
3048 int i; 3089 int i;
3049 3090
3050 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) 3091 if (con->flag & CON_DRIVER_FLAG_ATTR) {
3051 class_device_remove_file(con->class_dev, 3092 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
3052 &class_device_attrs[i]); 3093 class_device_remove_file(con->class_dev,
3094 &class_device_attrs[i]);
3095 con->flag &= ~CON_DRIVER_FLAG_ATTR;
3096 }
3053} 3097}
3054 3098
3055/** 3099/**
@@ -3148,6 +3192,7 @@ int register_con_driver(const struct consw *csw, int first, int last)
3148 } else { 3192 } else {
3149 vtconsole_init_class_device(con_driver); 3193 vtconsole_init_class_device(con_driver);
3150 } 3194 }
3195
3151err: 3196err:
3152 release_console_sem(); 3197 release_console_sem();
3153 module_put(owner); 3198 module_put(owner);
@@ -3765,6 +3810,7 @@ EXPORT_SYMBOL(default_blu);
3765EXPORT_SYMBOL(update_region); 3810EXPORT_SYMBOL(update_region);
3766EXPORT_SYMBOL(redraw_screen); 3811EXPORT_SYMBOL(redraw_screen);
3767EXPORT_SYMBOL(vc_resize); 3812EXPORT_SYMBOL(vc_resize);
3813EXPORT_SYMBOL(vc_lock_resize);
3768EXPORT_SYMBOL(fg_console); 3814EXPORT_SYMBOL(fg_console);
3769EXPORT_SYMBOL(console_blank_hook); 3815EXPORT_SYMBOL(console_blank_hook);
3770EXPORT_SYMBOL(console_blanked); 3816EXPORT_SYMBOL(console_blanked);
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index a5628a8b6620..ac5d60edbafa 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -96,7 +96,7 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
96 if (!perm) 96 if (!perm)
97 return -EPERM; 97 return -EPERM;
98 if (!i && v == K_NOSUCHMAP) { 98 if (!i && v == K_NOSUCHMAP) {
99 /* disallocate map */ 99 /* deallocate map */
100 key_map = key_maps[s]; 100 key_map = key_maps[s];
101 if (s && key_map) { 101 if (s && key_map) {
102 key_maps[s] = NULL; 102 key_maps[s] = NULL;
@@ -645,13 +645,16 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
645 */ 645 */
646 case KDSIGACCEPT: 646 case KDSIGACCEPT:
647 { 647 {
648 extern int spawnpid, spawnsig;
649 if (!perm || !capable(CAP_KILL)) 648 if (!perm || !capable(CAP_KILL))
650 return -EPERM; 649 return -EPERM;
651 if (!valid_signal(arg) || arg < 1 || arg == SIGKILL) 650 if (!valid_signal(arg) || arg < 1 || arg == SIGKILL)
652 return -EINVAL; 651 return -EINVAL;
653 spawnpid = current->pid; 652
654 spawnsig = arg; 653 spin_lock_irq(&vt_spawn_con.lock);
654 put_pid(vt_spawn_con.pid);
655 vt_spawn_con.pid = get_pid(task_pid(current));
656 vt_spawn_con.sig = arg;
657 spin_unlock_irq(&vt_spawn_con.lock);
655 return 0; 658 return 0;
656 } 659 }
657 660
@@ -669,7 +672,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
669 vc->vt_mode = tmp; 672 vc->vt_mode = tmp;
670 /* the frsig is ignored, so we set it to 0 */ 673 /* the frsig is ignored, so we set it to 0 */
671 vc->vt_mode.frsig = 0; 674 vc->vt_mode.frsig = 0;
672 vc->vt_pid = current->pid; 675 put_pid(xchg(&vc->vt_pid, get_pid(task_pid(current))));
673 /* no switch is required -- saw@shade.msu.ru */ 676 /* no switch is required -- saw@shade.msu.ru */
674 vc->vt_newvt = -1; 677 vc->vt_newvt = -1;
675 release_console_sem(); 678 release_console_sem();
@@ -819,20 +822,20 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
819 if (arg > MAX_NR_CONSOLES) 822 if (arg > MAX_NR_CONSOLES)
820 return -ENXIO; 823 return -ENXIO;
821 if (arg == 0) { 824 if (arg == 0) {
822 /* disallocate all unused consoles, but leave 0 */ 825 /* deallocate all unused consoles, but leave 0 */
823 acquire_console_sem(); 826 acquire_console_sem();
824 for (i=1; i<MAX_NR_CONSOLES; i++) 827 for (i=1; i<MAX_NR_CONSOLES; i++)
825 if (! VT_BUSY(i)) 828 if (! VT_BUSY(i))
826 vc_disallocate(i); 829 vc_deallocate(i);
827 release_console_sem(); 830 release_console_sem();
828 } else { 831 } else {
829 /* disallocate a single console, if possible */ 832 /* deallocate a single console, if possible */
830 arg--; 833 arg--;
831 if (VT_BUSY(arg)) 834 if (VT_BUSY(arg))
832 return -EBUSY; 835 return -EBUSY;
833 if (arg) { /* leave 0 */ 836 if (arg) { /* leave 0 */
834 acquire_console_sem(); 837 acquire_console_sem();
835 vc_disallocate(arg); 838 vc_deallocate(arg);
836 release_console_sem(); 839 release_console_sem();
837 } 840 }
838 } 841 }
@@ -847,11 +850,8 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
847 if (get_user(ll, &vtsizes->v_rows) || 850 if (get_user(ll, &vtsizes->v_rows) ||
848 get_user(cc, &vtsizes->v_cols)) 851 get_user(cc, &vtsizes->v_cols))
849 return -EFAULT; 852 return -EFAULT;
850 for (i = 0; i < MAX_NR_CONSOLES; i++) { 853 for (i = 0; i < MAX_NR_CONSOLES; i++)
851 acquire_console_sem(); 854 vc_lock_resize(vc_cons[i].d, cc, ll);
852 vc_resize(vc_cons[i].d, cc, ll);
853 release_console_sem();
854 }
855 return 0; 855 return 0;
856 } 856 }
857 857
@@ -1063,7 +1063,7 @@ void reset_vc(struct vc_data *vc)
1063 vc->vt_mode.relsig = 0; 1063 vc->vt_mode.relsig = 0;
1064 vc->vt_mode.acqsig = 0; 1064 vc->vt_mode.acqsig = 0;
1065 vc->vt_mode.frsig = 0; 1065 vc->vt_mode.frsig = 0;
1066 vc->vt_pid = -1; 1066 put_pid(xchg(&vc->vt_pid, NULL));
1067 vc->vt_newvt = -1; 1067 vc->vt_newvt = -1;
1068 if (!in_interrupt()) /* Via keyboard.c:SAK() - akpm */ 1068 if (!in_interrupt()) /* Via keyboard.c:SAK() - akpm */
1069 reset_palette(vc); 1069 reset_palette(vc);
@@ -1114,7 +1114,7 @@ static void complete_change_console(struct vc_data *vc)
1114 * tell us if the process has gone or something else 1114 * tell us if the process has gone or something else
1115 * is awry 1115 * is awry
1116 */ 1116 */
1117 if (kill_proc(vc->vt_pid, vc->vt_mode.acqsig, 1) != 0) { 1117 if (kill_pid(vc->vt_pid, vc->vt_mode.acqsig, 1) != 0) {
1118 /* 1118 /*
1119 * The controlling process has died, so we revert back to 1119 * The controlling process has died, so we revert back to
1120 * normal operation. In this case, we'll also change back 1120 * normal operation. In this case, we'll also change back
@@ -1174,7 +1174,7 @@ void change_console(struct vc_data *new_vc)
1174 * tell us if the process has gone or something else 1174 * tell us if the process has gone or something else
1175 * is awry 1175 * is awry
1176 */ 1176 */
1177 if (kill_proc(vc->vt_pid, vc->vt_mode.relsig, 1) == 0) { 1177 if (kill_pid(vc->vt_pid, vc->vt_mode.relsig, 1) == 0) {
1178 /* 1178 /*
1179 * It worked. Mark the vt to switch to and 1179 * It worked. Mark the vt to switch to and
1180 * return. The process needs to send us a 1180 * return. The process needs to send us a
diff --git a/drivers/char/watchdog/Kconfig b/drivers/char/watchdog/Kconfig
index fff89c2d88fd..06f3fa2fe877 100644
--- a/drivers/char/watchdog/Kconfig
+++ b/drivers/char/watchdog/Kconfig
@@ -165,6 +165,24 @@ config EP93XX_WATCHDOG
165 To compile this driver as a module, choose M here: the 165 To compile this driver as a module, choose M here: the
166 module will be called ep93xx_wdt. 166 module will be called ep93xx_wdt.
167 167
168config OMAP_WATCHDOG
169 tristate "OMAP Watchdog"
170 depends on WATCHDOG && (ARCH_OMAP16XX || ARCH_OMAP24XX)
171 help
172 Support for TI OMAP1610/OMAP1710/OMAP2420 watchdog. Say 'Y' here to
173 enable the OMAP1610/OMAP1710 watchdog timer.
174
175config PNX4008_WATCHDOG
176 tristate "PNX4008 Watchdog"
177 depends on WATCHDOG && ARCH_PNX4008
178 help
179 Say Y here if to include support for the watchdog timer
180 in the PNX4008 processor.
181 This driver can be built as a module by choosing M. The module
182 will be called pnx4008_wdt.
183
184 Say N if you are unsure.
185
168# X86 (i386 + ia64 + x86_64) Architecture 186# X86 (i386 + ia64 + x86_64) Architecture
169 187
170config ACQUIRE_WDT 188config ACQUIRE_WDT
@@ -510,6 +528,14 @@ config SH_WDT
510 To compile this driver as a module, choose M here: the 528 To compile this driver as a module, choose M here: the
511 module will be called shwdt. 529 module will be called shwdt.
512 530
531config SH_WDT_MMAP
532 bool "Allow mmap of SH WDT"
533 default n
534 depends on SH_WDT
535 help
536 If you say Y here, user applications will be able to mmap the
537 WDT/CPG registers.
538#
513# SPARC64 Architecture 539# SPARC64 Architecture
514 540
515config WATCHDOG_CP1XXX 541config WATCHDOG_CP1XXX
diff --git a/drivers/char/watchdog/Makefile b/drivers/char/watchdog/Makefile
index 6ab77b61a643..6ffca7cb56ab 100644
--- a/drivers/char/watchdog/Makefile
+++ b/drivers/char/watchdog/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o
24 24
25# ARM Architecture 25# ARM Architecture
26obj-$(CONFIG_AT91_WATCHDOG) += at91_wdt.o 26obj-$(CONFIG_AT91_WATCHDOG) += at91_wdt.o
27obj-$(CONFIG_OMAP_WATCHDOG) += omap_wdt.o
27obj-$(CONFIG_21285_WATCHDOG) += wdt285.o 28obj-$(CONFIG_21285_WATCHDOG) += wdt285.o
28obj-$(CONFIG_977_WATCHDOG) += wdt977.o 29obj-$(CONFIG_977_WATCHDOG) += wdt977.o
29obj-$(CONFIG_IXP2000_WATCHDOG) += ixp2000_wdt.o 30obj-$(CONFIG_IXP2000_WATCHDOG) += ixp2000_wdt.o
@@ -32,6 +33,7 @@ obj-$(CONFIG_S3C2410_WATCHDOG) += s3c2410_wdt.o
32obj-$(CONFIG_SA1100_WATCHDOG) += sa1100_wdt.o 33obj-$(CONFIG_SA1100_WATCHDOG) += sa1100_wdt.o
33obj-$(CONFIG_MPCORE_WATCHDOG) += mpcore_wdt.o 34obj-$(CONFIG_MPCORE_WATCHDOG) += mpcore_wdt.o
34obj-$(CONFIG_EP93XX_WATCHDOG) += ep93xx_wdt.o 35obj-$(CONFIG_EP93XX_WATCHDOG) += ep93xx_wdt.o
36obj-$(CONFIG_PNX4008_WATCHDOG) += pnx4008_wdt.o
35 37
36# X86 (i386 + ia64 + x86_64) Architecture 38# X86 (i386 + ia64 + x86_64) Architecture
37obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o 39obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
diff --git a/drivers/char/watchdog/acquirewdt.c b/drivers/char/watchdog/acquirewdt.c
index c77fe3cf2852..154d67e591e5 100644
--- a/drivers/char/watchdog/acquirewdt.c
+++ b/drivers/char/watchdog/acquirewdt.c
@@ -183,7 +183,7 @@ static int acq_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
183 } 183 }
184 184
185 default: 185 default:
186 return -ENOIOCTLCMD; 186 return -ENOTTY;
187 } 187 }
188} 188}
189 189
diff --git a/drivers/char/watchdog/advantechwdt.c b/drivers/char/watchdog/advantechwdt.c
index 8069be445edc..9d732769ba01 100644
--- a/drivers/char/watchdog/advantechwdt.c
+++ b/drivers/char/watchdog/advantechwdt.c
@@ -176,7 +176,7 @@ advwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
176 } 176 }
177 177
178 default: 178 default:
179 return -ENOIOCTLCMD; 179 return -ENOTTY;
180 } 180 }
181 return 0; 181 return 0;
182} 182}
diff --git a/drivers/char/watchdog/alim1535_wdt.c b/drivers/char/watchdog/alim1535_wdt.c
index c5c94e4c9495..01b0d132ee41 100644
--- a/drivers/char/watchdog/alim1535_wdt.c
+++ b/drivers/char/watchdog/alim1535_wdt.c
@@ -236,7 +236,7 @@ static int ali_ioctl(struct inode *inode, struct file *file,
236 return put_user(timeout, p); 236 return put_user(timeout, p);
237 237
238 default: 238 default:
239 return -ENOIOCTLCMD; 239 return -ENOTTY;
240 } 240 }
241} 241}
242 242
@@ -330,17 +330,20 @@ static int __init ali_find_watchdog(void)
330 u32 wdog; 330 u32 wdog;
331 331
332 /* Check for a 1535 series bridge */ 332 /* Check for a 1535 series bridge */
333 pdev = pci_find_device(PCI_VENDOR_ID_AL, 0x1535, NULL); 333 pdev = pci_get_device(PCI_VENDOR_ID_AL, 0x1535, NULL);
334 if(pdev == NULL) 334 if(pdev == NULL)
335 return -ENODEV; 335 return -ENODEV;
336 pci_dev_put(pdev);
336 337
337 /* Check for the a 7101 PMU */ 338 /* Check for the a 7101 PMU */
338 pdev = pci_find_device(PCI_VENDOR_ID_AL, 0x7101, NULL); 339 pdev = pci_get_device(PCI_VENDOR_ID_AL, 0x7101, NULL);
339 if(pdev == NULL) 340 if(pdev == NULL)
340 return -ENODEV; 341 return -ENODEV;
341 342
342 if(pci_enable_device(pdev)) 343 if(pci_enable_device(pdev)) {
344 pci_dev_put(pdev);
343 return -EIO; 345 return -EIO;
346 }
344 347
345 ali_pci = pdev; 348 ali_pci = pdev;
346 349
@@ -447,6 +450,7 @@ static void __exit watchdog_exit(void)
447 /* Deregister */ 450 /* Deregister */
448 unregister_reboot_notifier(&ali_notifier); 451 unregister_reboot_notifier(&ali_notifier);
449 misc_deregister(&ali_miscdev); 452 misc_deregister(&ali_miscdev);
453 pci_dev_put(ali_pci);
450} 454}
451 455
452module_init(watchdog_init); 456module_init(watchdog_init);
diff --git a/drivers/char/watchdog/alim7101_wdt.c b/drivers/char/watchdog/alim7101_wdt.c
index ffd7684f999b..5948863b592b 100644
--- a/drivers/char/watchdog/alim7101_wdt.c
+++ b/drivers/char/watchdog/alim7101_wdt.c
@@ -277,7 +277,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u
277 case WDIOC_GETTIMEOUT: 277 case WDIOC_GETTIMEOUT:
278 return put_user(timeout, p); 278 return put_user(timeout, p);
279 default: 279 default:
280 return -ENOIOCTLCMD; 280 return -ENOTTY;
281 } 281 }
282} 282}
283 283
@@ -333,6 +333,7 @@ static void __exit alim7101_wdt_unload(void)
333 /* Deregister */ 333 /* Deregister */
334 misc_deregister(&wdt_miscdev); 334 misc_deregister(&wdt_miscdev);
335 unregister_reboot_notifier(&wdt_notifier); 335 unregister_reboot_notifier(&wdt_notifier);
336 pci_dev_put(alim7101_pmu);
336} 337}
337 338
338static int __init alim7101_wdt_init(void) 339static int __init alim7101_wdt_init(void)
@@ -342,7 +343,8 @@ static int __init alim7101_wdt_init(void)
342 char tmp; 343 char tmp;
343 344
344 printk(KERN_INFO PFX "Steve Hill <steve@navaho.co.uk>.\n"); 345 printk(KERN_INFO PFX "Steve Hill <steve@navaho.co.uk>.\n");
345 alim7101_pmu = pci_find_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101,NULL); 346 alim7101_pmu = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101,
347 NULL);
346 if (!alim7101_pmu) { 348 if (!alim7101_pmu) {
347 printk(KERN_INFO PFX "ALi M7101 PMU not present - WDT not set\n"); 349 printk(KERN_INFO PFX "ALi M7101 PMU not present - WDT not set\n");
348 return -EBUSY; 350 return -EBUSY;
@@ -351,21 +353,23 @@ static int __init alim7101_wdt_init(void)
351 /* Set the WDT in the PMU to 1 second */ 353 /* Set the WDT in the PMU to 1 second */
352 pci_write_config_byte(alim7101_pmu, ALI_7101_WDT, 0x02); 354 pci_write_config_byte(alim7101_pmu, ALI_7101_WDT, 0x02);
353 355
354 ali1543_south = pci_find_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL); 356 ali1543_south = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533,
357 NULL);
355 if (!ali1543_south) { 358 if (!ali1543_south) {
356 printk(KERN_INFO PFX "ALi 1543 South-Bridge not present - WDT not set\n"); 359 printk(KERN_INFO PFX "ALi 1543 South-Bridge not present - WDT not set\n");
357 return -EBUSY; 360 goto err_out;
358 } 361 }
359 pci_read_config_byte(ali1543_south, 0x5e, &tmp); 362 pci_read_config_byte(ali1543_south, 0x5e, &tmp);
363 pci_dev_put(ali1543_south);
360 if ((tmp & 0x1e) == 0x00) { 364 if ((tmp & 0x1e) == 0x00) {
361 if (!use_gpio) { 365 if (!use_gpio) {
362 printk(KERN_INFO PFX "Detected old alim7101 revision 'a1d'. If this is a cobalt board, set the 'use_gpio' module parameter.\n"); 366 printk(KERN_INFO PFX "Detected old alim7101 revision 'a1d'. If this is a cobalt board, set the 'use_gpio' module parameter.\n");
363 return -EBUSY; 367 goto err_out;
364 } 368 }
365 nowayout = 1; 369 nowayout = 1;
366 } else if ((tmp & 0x1e) != 0x12 && (tmp & 0x1e) != 0x00) { 370 } else if ((tmp & 0x1e) != 0x12 && (tmp & 0x1e) != 0x00) {
367 printk(KERN_INFO PFX "ALi 1543 South-Bridge does not have the correct revision number (???1001?) - WDT not set\n"); 371 printk(KERN_INFO PFX "ALi 1543 South-Bridge does not have the correct revision number (???1001?) - WDT not set\n");
368 return -EBUSY; 372 goto err_out;
369 } 373 }
370 374
371 if(timeout < 1 || timeout > 3600) /* arbitrary upper limit */ 375 if(timeout < 1 || timeout > 3600) /* arbitrary upper limit */
@@ -404,6 +408,7 @@ static int __init alim7101_wdt_init(void)
404err_out_miscdev: 408err_out_miscdev:
405 misc_deregister(&wdt_miscdev); 409 misc_deregister(&wdt_miscdev);
406err_out: 410err_out:
411 pci_dev_put(alim7101_pmu);
407 return rc; 412 return rc;
408} 413}
409 414
diff --git a/drivers/char/watchdog/at91_wdt.c b/drivers/char/watchdog/at91_wdt.c
index cc266715ea32..4e7a1145e78f 100644
--- a/drivers/char/watchdog/at91_wdt.c
+++ b/drivers/char/watchdog/at91_wdt.c
@@ -168,7 +168,7 @@ static int at91_wdt_ioctl(struct inode *inode, struct file *file,
168 return 0; 168 return 0;
169 169
170 default: 170 default:
171 return -ENOIOCTLCMD; 171 return -ENOTTY;
172 } 172 }
173} 173}
174 174
diff --git a/drivers/char/watchdog/booke_wdt.c b/drivers/char/watchdog/booke_wdt.c
index e3cefc538b40..488902231cc2 100644
--- a/drivers/char/watchdog/booke_wdt.c
+++ b/drivers/char/watchdog/booke_wdt.c
@@ -125,7 +125,7 @@ static int booke_wdt_ioctl (struct inode *inode, struct file *file,
125 return -EINVAL; 125 return -EINVAL;
126 return 0; 126 return 0;
127 default: 127 default:
128 return -ENOIOCTLCMD; 128 return -ENOTTY;
129 } 129 }
130 130
131 return 0; 131 return 0;
diff --git a/drivers/char/watchdog/cpu5wdt.c b/drivers/char/watchdog/cpu5wdt.c
index 04c7e49918db..00bdabb90f27 100644
--- a/drivers/char/watchdog/cpu5wdt.c
+++ b/drivers/char/watchdog/cpu5wdt.c
@@ -183,7 +183,7 @@ static int cpu5wdt_ioctl(struct inode *inode, struct file *file, unsigned int cm
183 } 183 }
184 break; 184 break;
185 default: 185 default:
186 return -ENOIOCTLCMD; 186 return -ENOTTY;
187 } 187 }
188 return 0; 188 return 0;
189} 189}
diff --git a/drivers/char/watchdog/ep93xx_wdt.c b/drivers/char/watchdog/ep93xx_wdt.c
index 77c8a955ae9e..01cf123b1616 100644
--- a/drivers/char/watchdog/ep93xx_wdt.c
+++ b/drivers/char/watchdog/ep93xx_wdt.c
@@ -144,7 +144,7 @@ static int
144ep93xx_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, 144ep93xx_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
145 unsigned long arg) 145 unsigned long arg)
146{ 146{
147 int ret = -ENOIOCTLCMD; 147 int ret = -ENOTTY;
148 148
149 switch (cmd) { 149 switch (cmd) {
150 case WDIOC_GETSUPPORT: 150 case WDIOC_GETSUPPORT:
diff --git a/drivers/char/watchdog/eurotechwdt.c b/drivers/char/watchdog/eurotechwdt.c
index 62dbccb2f6df..4f4269754c46 100644
--- a/drivers/char/watchdog/eurotechwdt.c
+++ b/drivers/char/watchdog/eurotechwdt.c
@@ -240,7 +240,7 @@ static int eurwdt_ioctl(struct inode *inode, struct file *file,
240 240
241 switch(cmd) { 241 switch(cmd) {
242 default: 242 default:
243 return -ENOIOCTLCMD; 243 return -ENOTTY;
244 244
245 case WDIOC_GETSUPPORT: 245 case WDIOC_GETSUPPORT:
246 return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; 246 return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
diff --git a/drivers/char/watchdog/i6300esb.c b/drivers/char/watchdog/i6300esb.c
index 870539eabbf3..fb64df4d7c87 100644
--- a/drivers/char/watchdog/i6300esb.c
+++ b/drivers/char/watchdog/i6300esb.c
@@ -315,7 +315,7 @@ static int esb_ioctl (struct inode *inode, struct file *file,
315 return put_user(heartbeat, p); 315 return put_user(heartbeat, p);
316 316
317 default: 317 default:
318 return -ENOIOCTLCMD; 318 return -ENOTTY;
319 } 319 }
320} 320}
321 321
diff --git a/drivers/char/watchdog/i8xx_tco.c b/drivers/char/watchdog/i8xx_tco.c
index 8385dd36eefe..e0627d79707b 100644
--- a/drivers/char/watchdog/i8xx_tco.c
+++ b/drivers/char/watchdog/i8xx_tco.c
@@ -356,7 +356,7 @@ static int i8xx_tco_ioctl (struct inode *inode, struct file *file,
356 } 356 }
357 357
358 default: 358 default:
359 return -ENOIOCTLCMD; 359 return -ENOTTY;
360 } 360 }
361} 361}
362 362
@@ -406,18 +406,18 @@ static struct notifier_block i8xx_tco_notifier = {
406 * want to register another driver on the same PCI id. 406 * want to register another driver on the same PCI id.
407 */ 407 */
408static struct pci_device_id i8xx_tco_pci_tbl[] = { 408static struct pci_device_id i8xx_tco_pci_tbl[] = {
409 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, PCI_ANY_ID, PCI_ANY_ID, }, 409 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0) },
410 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_0, PCI_ANY_ID, PCI_ANY_ID, }, 410 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_0) },
411 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, PCI_ANY_ID, PCI_ANY_ID, }, 411 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0) },
412 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_10, PCI_ANY_ID, PCI_ANY_ID, }, 412 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_10) },
413 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, PCI_ANY_ID, PCI_ANY_ID, }, 413 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0) },
414 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, PCI_ANY_ID, PCI_ANY_ID, }, 414 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12) },
415 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, PCI_ANY_ID, PCI_ANY_ID, }, 415 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0) },
416 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, PCI_ANY_ID, PCI_ANY_ID, }, 416 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12) },
417 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801E_0, PCI_ANY_ID, PCI_ANY_ID, }, 417 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801E_0) },
418 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, PCI_ANY_ID, PCI_ANY_ID, }, 418 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0) },
419 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1, PCI_ANY_ID, PCI_ANY_ID, }, 419 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1) },
420 { 0, }, /* End of list */ 420 { }, /* End of list */
421}; 421};
422MODULE_DEVICE_TABLE (pci, i8xx_tco_pci_tbl); 422MODULE_DEVICE_TABLE (pci, i8xx_tco_pci_tbl);
423 423
@@ -434,12 +434,11 @@ static unsigned char __init i8xx_tco_getdevice (void)
434 * Find the PCI device 434 * Find the PCI device
435 */ 435 */
436 436
437 while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { 437 for_each_pci_dev(dev)
438 if (pci_match_id(i8xx_tco_pci_tbl, dev)) { 438 if (pci_match_id(i8xx_tco_pci_tbl, dev)) {
439 i8xx_tco_pci = dev; 439 i8xx_tco_pci = dev;
440 break; 440 break;
441 } 441 }
442 }
443 442
444 if (i8xx_tco_pci) { 443 if (i8xx_tco_pci) {
445 /* 444 /*
@@ -454,6 +453,7 @@ static unsigned char __init i8xx_tco_getdevice (void)
454 /* Something's wrong here, ACPIBASE has to be set */ 453 /* Something's wrong here, ACPIBASE has to be set */
455 if (badr == 0x0001 || badr == 0x0000) { 454 if (badr == 0x0001 || badr == 0x0000) {
456 printk (KERN_ERR PFX "failed to get TCOBASE address\n"); 455 printk (KERN_ERR PFX "failed to get TCOBASE address\n");
456 pci_dev_put(i8xx_tco_pci);
457 return 0; 457 return 0;
458 } 458 }
459 459
@@ -465,6 +465,7 @@ static unsigned char __init i8xx_tco_getdevice (void)
465 pci_read_config_byte (i8xx_tco_pci, 0xd4, &val1); 465 pci_read_config_byte (i8xx_tco_pci, 0xd4, &val1);
466 if (val1 & 0x02) { 466 if (val1 & 0x02) {
467 printk (KERN_ERR PFX "failed to reset NO_REBOOT flag, reboot disabled by hardware\n"); 467 printk (KERN_ERR PFX "failed to reset NO_REBOOT flag, reboot disabled by hardware\n");
468 pci_dev_put(i8xx_tco_pci);
468 return 0; /* Cannot reset NO_REBOOT bit */ 469 return 0; /* Cannot reset NO_REBOOT bit */
469 } 470 }
470 } 471 }
@@ -476,6 +477,7 @@ static unsigned char __init i8xx_tco_getdevice (void)
476 if (!request_region (SMI_EN + 1, 1, "i8xx TCO")) { 477 if (!request_region (SMI_EN + 1, 1, "i8xx TCO")) {
477 printk (KERN_ERR PFX "I/O address 0x%04x already in use\n", 478 printk (KERN_ERR PFX "I/O address 0x%04x already in use\n",
478 SMI_EN + 1); 479 SMI_EN + 1);
480 pci_dev_put(i8xx_tco_pci);
479 return 0; 481 return 0;
480 } 482 }
481 val1 = inb (SMI_EN + 1); 483 val1 = inb (SMI_EN + 1);
@@ -542,6 +544,7 @@ unreg_notifier:
542unreg_region: 544unreg_region:
543 release_region (TCOBASE, 0x10); 545 release_region (TCOBASE, 0x10);
544out: 546out:
547 pci_dev_put(i8xx_tco_pci);
545 return ret; 548 return ret;
546} 549}
547 550
@@ -555,6 +558,8 @@ static void __exit watchdog_cleanup (void)
555 misc_deregister (&i8xx_tco_miscdev); 558 misc_deregister (&i8xx_tco_miscdev);
556 unregister_reboot_notifier(&i8xx_tco_notifier); 559 unregister_reboot_notifier(&i8xx_tco_notifier);
557 release_region (TCOBASE, 0x10); 560 release_region (TCOBASE, 0x10);
561
562 pci_dev_put(i8xx_tco_pci);
558} 563}
559 564
560module_init(watchdog_init); 565module_init(watchdog_init);
diff --git a/drivers/char/watchdog/ib700wdt.c b/drivers/char/watchdog/ib700wdt.c
index fd95f7327798..c1ed209a138c 100644
--- a/drivers/char/watchdog/ib700wdt.c
+++ b/drivers/char/watchdog/ib700wdt.c
@@ -199,7 +199,7 @@ ibwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
199 break; 199 break;
200 200
201 default: 201 default:
202 return -ENOIOCTLCMD; 202 return -ENOTTY;
203 } 203 }
204 return 0; 204 return 0;
205} 205}
diff --git a/drivers/char/watchdog/ibmasr.c b/drivers/char/watchdog/ibmasr.c
index 26ceee7a4df0..dd6760f1a23b 100644
--- a/drivers/char/watchdog/ibmasr.c
+++ b/drivers/char/watchdog/ibmasr.c
@@ -295,7 +295,7 @@ static int asr_ioctl(struct inode *inode, struct file *file,
295 } 295 }
296 } 296 }
297 297
298 return -ENOIOCTLCMD; 298 return -ENOTTY;
299} 299}
300 300
301static int asr_open(struct inode *inode, struct file *file) 301static int asr_open(struct inode *inode, struct file *file)
diff --git a/drivers/char/watchdog/indydog.c b/drivers/char/watchdog/indydog.c
index dacc1c20a310..0bc239308989 100644
--- a/drivers/char/watchdog/indydog.c
+++ b/drivers/char/watchdog/indydog.c
@@ -112,7 +112,7 @@ static int indydog_ioctl(struct inode *inode, struct file *file,
112 112
113 switch (cmd) { 113 switch (cmd) {
114 default: 114 default:
115 return -ENOIOCTLCMD; 115 return -ENOTTY;
116 case WDIOC_GETSUPPORT: 116 case WDIOC_GETSUPPORT:
117 if (copy_to_user((struct watchdog_info *)arg, 117 if (copy_to_user((struct watchdog_info *)arg,
118 &ident, sizeof(ident))) 118 &ident, sizeof(ident)))
diff --git a/drivers/char/watchdog/ixp2000_wdt.c b/drivers/char/watchdog/ixp2000_wdt.c
index 692908819e26..c91d9a660ec0 100644
--- a/drivers/char/watchdog/ixp2000_wdt.c
+++ b/drivers/char/watchdog/ixp2000_wdt.c
@@ -107,7 +107,7 @@ static int
107ixp2000_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, 107ixp2000_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
108 unsigned long arg) 108 unsigned long arg)
109{ 109{
110 int ret = -ENOIOCTLCMD; 110 int ret = -ENOTTY;
111 int time; 111 int time;
112 112
113 switch (cmd) { 113 switch (cmd) {
diff --git a/drivers/char/watchdog/ixp4xx_wdt.c b/drivers/char/watchdog/ixp4xx_wdt.c
index 9db5cf2c38c3..db477f712388 100644
--- a/drivers/char/watchdog/ixp4xx_wdt.c
+++ b/drivers/char/watchdog/ixp4xx_wdt.c
@@ -102,7 +102,7 @@ static int
102ixp4xx_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, 102ixp4xx_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
103 unsigned long arg) 103 unsigned long arg)
104{ 104{
105 int ret = -ENOIOCTLCMD; 105 int ret = -ENOTTY;
106 int time; 106 int time;
107 107
108 switch (cmd) { 108 switch (cmd) {
diff --git a/drivers/char/watchdog/machzwd.c b/drivers/char/watchdog/machzwd.c
index 23734e07fb22..276577d08fba 100644
--- a/drivers/char/watchdog/machzwd.c
+++ b/drivers/char/watchdog/machzwd.c
@@ -329,7 +329,7 @@ static int zf_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
329 break; 329 break;
330 330
331 default: 331 default:
332 return -ENOIOCTLCMD; 332 return -ENOTTY;
333 } 333 }
334 334
335 return 0; 335 return 0;
@@ -426,8 +426,7 @@ static int __init zf_init(void)
426 printk(KERN_INFO PFX ": MachZ ZF-Logic Watchdog driver initializing.\n"); 426 printk(KERN_INFO PFX ": MachZ ZF-Logic Watchdog driver initializing.\n");
427 427
428 ret = zf_get_ZFL_version(); 428 ret = zf_get_ZFL_version();
429 printk("%#x\n", ret); 429 if ((!ret) || (ret == 0xffff)) {
430 if((!ret) || (ret != 0xffff)){
431 printk(KERN_WARNING PFX ": no ZF-Logic found\n"); 430 printk(KERN_WARNING PFX ": no ZF-Logic found\n");
432 return -ENODEV; 431 return -ENODEV;
433 } 432 }
diff --git a/drivers/char/watchdog/mixcomwd.c b/drivers/char/watchdog/mixcomwd.c
index ae943324d251..c2dac0aa1d62 100644
--- a/drivers/char/watchdog/mixcomwd.c
+++ b/drivers/char/watchdog/mixcomwd.c
@@ -185,7 +185,7 @@ static int mixcomwd_ioctl(struct inode *inode, struct file *file,
185 mixcomwd_ping(); 185 mixcomwd_ping();
186 break; 186 break;
187 default: 187 default:
188 return -ENOIOCTLCMD; 188 return -ENOTTY;
189 } 189 }
190 return 0; 190 return 0;
191} 191}
diff --git a/drivers/char/watchdog/mpc83xx_wdt.c b/drivers/char/watchdog/mpc83xx_wdt.c
index a480903ee1a5..18ca752e2f90 100644
--- a/drivers/char/watchdog/mpc83xx_wdt.c
+++ b/drivers/char/watchdog/mpc83xx_wdt.c
@@ -125,7 +125,7 @@ static int mpc83xx_wdt_ioctl(struct inode *inode, struct file *file,
125 case WDIOC_GETTIMEOUT: 125 case WDIOC_GETTIMEOUT:
126 return put_user(timeout_sec, p); 126 return put_user(timeout_sec, p);
127 default: 127 default:
128 return -ENOIOCTLCMD; 128 return -ENOTTY;
129 } 129 }
130} 130}
131 131
diff --git a/drivers/char/watchdog/mpc8xx_wdt.c b/drivers/char/watchdog/mpc8xx_wdt.c
index 35dd9e6e1140..8aaed10dd499 100644
--- a/drivers/char/watchdog/mpc8xx_wdt.c
+++ b/drivers/char/watchdog/mpc8xx_wdt.c
@@ -126,7 +126,7 @@ static int mpc8xx_wdt_ioctl(struct inode *inode, struct file *file,
126 break; 126 break;
127 127
128 default: 128 default:
129 return -ENOIOCTLCMD; 129 return -ENOTTY;
130 } 130 }
131 131
132 return 0; 132 return 0;
diff --git a/drivers/char/watchdog/mpcore_wdt.c b/drivers/char/watchdog/mpcore_wdt.c
index 54b3c56ead0d..02d336ace504 100644
--- a/drivers/char/watchdog/mpcore_wdt.c
+++ b/drivers/char/watchdog/mpcore_wdt.c
@@ -221,7 +221,7 @@ static int mpcore_wdt_ioctl(struct inode *inode, struct file *file,
221 } uarg; 221 } uarg;
222 222
223 if (_IOC_DIR(cmd) && _IOC_SIZE(cmd) > sizeof(uarg)) 223 if (_IOC_DIR(cmd) && _IOC_SIZE(cmd) > sizeof(uarg))
224 return -ENOIOCTLCMD; 224 return -ENOTTY;
225 225
226 if (_IOC_DIR(cmd) & _IOC_WRITE) { 226 if (_IOC_DIR(cmd) & _IOC_WRITE) {
227 ret = copy_from_user(&uarg, (void __user *)arg, _IOC_SIZE(cmd)); 227 ret = copy_from_user(&uarg, (void __user *)arg, _IOC_SIZE(cmd));
@@ -271,7 +271,7 @@ static int mpcore_wdt_ioctl(struct inode *inode, struct file *file,
271 break; 271 break;
272 272
273 default: 273 default:
274 return -ENOIOCTLCMD; 274 return -ENOTTY;
275 } 275 }
276 276
277 if (ret == 0 && _IOC_DIR(cmd) & _IOC_READ) { 277 if (ret == 0 && _IOC_DIR(cmd) & _IOC_READ) {
diff --git a/drivers/char/watchdog/mv64x60_wdt.c b/drivers/char/watchdog/mv64x60_wdt.c
index 5c8fab345b40..b887cdb01334 100644
--- a/drivers/char/watchdog/mv64x60_wdt.c
+++ b/drivers/char/watchdog/mv64x60_wdt.c
@@ -160,7 +160,7 @@ static int mv64x60_wdt_ioctl(struct inode *inode, struct file *file,
160 break; 160 break;
161 161
162 default: 162 default:
163 return -ENOIOCTLCMD; 163 return -ENOTTY;
164 } 164 }
165 165
166 return 0; 166 return 0;
diff --git a/drivers/char/watchdog/omap_wdt.c b/drivers/char/watchdog/omap_wdt.c
new file mode 100644
index 000000000000..8f90b90a5021
--- /dev/null
+++ b/drivers/char/watchdog/omap_wdt.c
@@ -0,0 +1,391 @@
1/*
2 * linux/drivers/char/watchdog/omap_wdt.c
3 *
4 * Watchdog driver for the TI OMAP 16xx & 24xx 32KHz (non-secure) watchdog
5 *
6 * Author: MontaVista Software, Inc.
7 * <gdavis@mvista.com> or <source@mvista.com>
8 *
9 * 2003 (c) MontaVista Software, Inc. This file is licensed under the
10 * terms of the GNU General Public License version 2. This program is
11 * licensed "as is" without any warranty of any kind, whether express
12 * or implied.
13 *
14 * History:
15 *
16 * 20030527: George G. Davis <gdavis@mvista.com>
17 * Initially based on linux-2.4.19-rmk7-pxa1/drivers/char/sa1100_wdt.c
18 * (c) Copyright 2000 Oleg Drokin <green@crimea.edu>
19 * Based on SoftDog driver by Alan Cox <alan@redhat.com>
20 *
21 * Copyright (c) 2004 Texas Instruments.
22 * 1. Modified to support OMAP1610 32-KHz watchdog timer
23 * 2. Ported to 2.6 kernel
24 *
25 * Copyright (c) 2005 David Brownell
26 * Use the driver model and standard identifiers; handle bigger timeouts.
27 */
28
29#include <linux/module.h>
30#include <linux/config.h>
31#include <linux/types.h>
32#include <linux/kernel.h>
33#include <linux/fs.h>
34#include <linux/mm.h>
35#include <linux/miscdevice.h>
36#include <linux/watchdog.h>
37#include <linux/reboot.h>
38#include <linux/smp_lock.h>
39#include <linux/init.h>
40#include <linux/err.h>
41#include <linux/platform_device.h>
42#include <linux/moduleparam.h>
43#include <linux/clk.h>
44
45#include <asm/io.h>
46#include <asm/uaccess.h>
47#include <asm/hardware.h>
48#include <asm/bitops.h>
49
50#include <asm/arch/prcm.h>
51
52#include "omap_wdt.h"
53
54static unsigned timer_margin;
55module_param(timer_margin, uint, 0);
56MODULE_PARM_DESC(timer_margin, "initial watchdog timeout (in seconds)");
57
58static int omap_wdt_users;
59static struct clk *armwdt_ck = NULL;
60static struct clk *mpu_wdt_ick = NULL;
61static struct clk *mpu_wdt_fck = NULL;
62
63static unsigned int wdt_trgr_pattern = 0x1234;
64
65static void omap_wdt_ping(void)
66{
67 /* wait for posted write to complete */
68 while ((omap_readl(OMAP_WATCHDOG_WPS)) & 0x08)
69 cpu_relax();
70 wdt_trgr_pattern = ~wdt_trgr_pattern;
71 omap_writel(wdt_trgr_pattern, (OMAP_WATCHDOG_TGR));
72 /* wait for posted write to complete */
73 while ((omap_readl(OMAP_WATCHDOG_WPS)) & 0x08)
74 cpu_relax();
75 /* reloaded WCRR from WLDR */
76}
77
78static void omap_wdt_enable(void)
79{
80 /* Sequence to enable the watchdog */
81 omap_writel(0xBBBB, OMAP_WATCHDOG_SPR);
82 while ((omap_readl(OMAP_WATCHDOG_WPS)) & 0x10)
83 cpu_relax();
84 omap_writel(0x4444, OMAP_WATCHDOG_SPR);
85 while ((omap_readl(OMAP_WATCHDOG_WPS)) & 0x10)
86 cpu_relax();
87}
88
89static void omap_wdt_disable(void)
90{
91 /* sequence required to disable watchdog */
92 omap_writel(0xAAAA, OMAP_WATCHDOG_SPR); /* TIMER_MODE */
93 while (omap_readl(OMAP_WATCHDOG_WPS) & 0x10)
94 cpu_relax();
95 omap_writel(0x5555, OMAP_WATCHDOG_SPR); /* TIMER_MODE */
96 while (omap_readl(OMAP_WATCHDOG_WPS) & 0x10)
97 cpu_relax();
98}
99
100static void omap_wdt_adjust_timeout(unsigned new_timeout)
101{
102 if (new_timeout < TIMER_MARGIN_MIN)
103 new_timeout = TIMER_MARGIN_DEFAULT;
104 if (new_timeout > TIMER_MARGIN_MAX)
105 new_timeout = TIMER_MARGIN_MAX;
106 timer_margin = new_timeout;
107}
108
109static void omap_wdt_set_timeout(void)
110{
111 u32 pre_margin = GET_WLDR_VAL(timer_margin);
112
113 /* just count up at 32 KHz */
114 while (omap_readl(OMAP_WATCHDOG_WPS) & 0x04)
115 cpu_relax();
116 omap_writel(pre_margin, OMAP_WATCHDOG_LDR);
117 while (omap_readl(OMAP_WATCHDOG_WPS) & 0x04)
118 cpu_relax();
119}
120
121/*
122 * Allow only one task to hold it open
123 */
124
125static int omap_wdt_open(struct inode *inode, struct file *file)
126{
127 if (test_and_set_bit(1, (unsigned long *)&omap_wdt_users))
128 return -EBUSY;
129
130 if (cpu_is_omap16xx())
131 clk_enable(armwdt_ck); /* Enable the clock */
132
133 if (cpu_is_omap24xx()) {
134 clk_enable(mpu_wdt_ick); /* Enable the interface clock */
135 clk_enable(mpu_wdt_fck); /* Enable the functional clock */
136 }
137
138 /* initialize prescaler */
139 while (omap_readl(OMAP_WATCHDOG_WPS) & 0x01)
140 cpu_relax();
141 omap_writel((1 << 5) | (PTV << 2), OMAP_WATCHDOG_CNTRL);
142 while (omap_readl(OMAP_WATCHDOG_WPS) & 0x01)
143 cpu_relax();
144
145 omap_wdt_set_timeout();
146 omap_wdt_enable();
147 return 0;
148}
149
150static int omap_wdt_release(struct inode *inode, struct file *file)
151{
152 /*
153 * Shut off the timer unless NOWAYOUT is defined.
154 */
155#ifndef CONFIG_WATCHDOG_NOWAYOUT
156 omap_wdt_disable();
157
158 if (cpu_is_omap16xx()) {
159 clk_disable(armwdt_ck); /* Disable the clock */
160 clk_put(armwdt_ck);
161 armwdt_ck = NULL;
162 }
163
164 if (cpu_is_omap24xx()) {
165 clk_disable(mpu_wdt_ick); /* Disable the clock */
166 clk_disable(mpu_wdt_fck); /* Disable the clock */
167 clk_put(mpu_wdt_ick);
168 clk_put(mpu_wdt_fck);
169 mpu_wdt_ick = NULL;
170 mpu_wdt_fck = NULL;
171 }
172#else
173 printk(KERN_CRIT "omap_wdt: Unexpected close, not stopping!\n");
174#endif
175 omap_wdt_users = 0;
176 return 0;
177}
178
179static ssize_t
180omap_wdt_write(struct file *file, const char __user *data,
181 size_t len, loff_t *ppos)
182{
183 /* Refresh LOAD_TIME. */
184 if (len)
185 omap_wdt_ping();
186 return len;
187}
188
189static int
190omap_wdt_ioctl(struct inode *inode, struct file *file,
191 unsigned int cmd, unsigned long arg)
192{
193 int new_margin;
194 static struct watchdog_info ident = {
195 .identity = "OMAP Watchdog",
196 .options = WDIOF_SETTIMEOUT,
197 .firmware_version = 0,
198 };
199
200 switch (cmd) {
201 default:
202 return -ENOIOCTLCMD;
203 case WDIOC_GETSUPPORT:
204 return copy_to_user((struct watchdog_info __user *)arg, &ident,
205 sizeof(ident));
206 case WDIOC_GETSTATUS:
207 return put_user(0, (int __user *)arg);
208 case WDIOC_GETBOOTSTATUS:
209 if (cpu_is_omap16xx())
210 return put_user(omap_readw(ARM_SYSST),
211 (int __user *)arg);
212 if (cpu_is_omap24xx())
213 return put_user(omap_prcm_get_reset_sources(),
214 (int __user *)arg);
215 case WDIOC_KEEPALIVE:
216 omap_wdt_ping();
217 return 0;
218 case WDIOC_SETTIMEOUT:
219 if (get_user(new_margin, (int __user *)arg))
220 return -EFAULT;
221 omap_wdt_adjust_timeout(new_margin);
222
223 omap_wdt_disable();
224 omap_wdt_set_timeout();
225 omap_wdt_enable();
226
227 omap_wdt_ping();
228 /* Fall */
229 case WDIOC_GETTIMEOUT:
230 return put_user(timer_margin, (int __user *)arg);
231 }
232}
233
234static struct file_operations omap_wdt_fops = {
235 .owner = THIS_MODULE,
236 .write = omap_wdt_write,
237 .ioctl = omap_wdt_ioctl,
238 .open = omap_wdt_open,
239 .release = omap_wdt_release,
240};
241
242static struct miscdevice omap_wdt_miscdev = {
243 .minor = WATCHDOG_MINOR,
244 .name = "watchdog",
245 .fops = &omap_wdt_fops
246};
247
248static int __init omap_wdt_probe(struct platform_device *pdev)
249{
250 struct resource *res, *mem;
251 int ret;
252
253 /* reserve static register mappings */
254 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
255 if (!res)
256 return -ENOENT;
257
258 mem = request_mem_region(res->start, res->end - res->start + 1,
259 pdev->name);
260 if (mem == NULL)
261 return -EBUSY;
262
263 platform_set_drvdata(pdev, mem);
264
265 omap_wdt_users = 0;
266
267 if (cpu_is_omap16xx()) {
268 armwdt_ck = clk_get(&pdev->dev, "armwdt_ck");
269 if (IS_ERR(armwdt_ck)) {
270 ret = PTR_ERR(armwdt_ck);
271 armwdt_ck = NULL;
272 goto fail;
273 }
274 }
275
276 if (cpu_is_omap24xx()) {
277 mpu_wdt_ick = clk_get(&pdev->dev, "mpu_wdt_ick");
278 if (IS_ERR(mpu_wdt_ick)) {
279 ret = PTR_ERR(mpu_wdt_ick);
280 mpu_wdt_ick = NULL;
281 goto fail;
282 }
283 mpu_wdt_fck = clk_get(&pdev->dev, "mpu_wdt_fck");
284 if (IS_ERR(mpu_wdt_fck)) {
285 ret = PTR_ERR(mpu_wdt_fck);
286 mpu_wdt_fck = NULL;
287 goto fail;
288 }
289 }
290
291 omap_wdt_disable();
292 omap_wdt_adjust_timeout(timer_margin);
293
294 omap_wdt_miscdev.dev = &pdev->dev;
295 ret = misc_register(&omap_wdt_miscdev);
296 if (ret)
297 goto fail;
298
299 pr_info("OMAP Watchdog Timer: initial timeout %d sec\n", timer_margin);
300
301 /* autogate OCP interface clock */
302 omap_writel(0x01, OMAP_WATCHDOG_SYS_CONFIG);
303 return 0;
304
305fail:
306 if (armwdt_ck)
307 clk_put(armwdt_ck);
308 if (mpu_wdt_ick)
309 clk_put(mpu_wdt_ick);
310 if (mpu_wdt_fck)
311 clk_put(mpu_wdt_fck);
312 release_resource(mem);
313 return ret;
314}
315
316static void omap_wdt_shutdown(struct platform_device *pdev)
317{
318 omap_wdt_disable();
319}
320
321static int omap_wdt_remove(struct platform_device *pdev)
322{
323 struct resource *mem = platform_get_drvdata(pdev);
324 misc_deregister(&omap_wdt_miscdev);
325 release_resource(mem);
326 if (armwdt_ck)
327 clk_put(armwdt_ck);
328 if (mpu_wdt_ick)
329 clk_put(mpu_wdt_ick);
330 if (mpu_wdt_fck)
331 clk_put(mpu_wdt_fck);
332 return 0;
333}
334
335#ifdef CONFIG_PM
336
337/* REVISIT ... not clear this is the best way to handle system suspend; and
338 * it's very inappropriate for selective device suspend (e.g. suspending this
339 * through sysfs rather than by stopping the watchdog daemon). Also, this
340 * may not play well enough with NOWAYOUT...
341 */
342
343static int omap_wdt_suspend(struct platform_device *pdev, pm_message_t state)
344{
345 if (omap_wdt_users)
346 omap_wdt_disable();
347 return 0;
348}
349
350static int omap_wdt_resume(struct platform_device *pdev)
351{
352 if (omap_wdt_users) {
353 omap_wdt_enable();
354 omap_wdt_ping();
355 }
356 return 0;
357}
358
359#else
360#define omap_wdt_suspend NULL
361#define omap_wdt_resume NULL
362#endif
363
364static struct platform_driver omap_wdt_driver = {
365 .probe = omap_wdt_probe,
366 .remove = omap_wdt_remove,
367 .shutdown = omap_wdt_shutdown,
368 .suspend = omap_wdt_suspend,
369 .resume = omap_wdt_resume,
370 .driver = {
371 .owner = THIS_MODULE,
372 .name = "omap_wdt",
373 },
374};
375
376static int __init omap_wdt_init(void)
377{
378 return platform_driver_register(&omap_wdt_driver);
379}
380
381static void __exit omap_wdt_exit(void)
382{
383 platform_driver_unregister(&omap_wdt_driver);
384}
385
386module_init(omap_wdt_init);
387module_exit(omap_wdt_exit);
388
389MODULE_AUTHOR("George G. Davis");
390MODULE_LICENSE("GPL");
391MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/char/watchdog/omap_wdt.h b/drivers/char/watchdog/omap_wdt.h
new file mode 100644
index 000000000000..52a532a5114a
--- /dev/null
+++ b/drivers/char/watchdog/omap_wdt.h
@@ -0,0 +1,64 @@
1/*
2 * linux/drivers/char/watchdog/omap_wdt.h
3 *
4 * BRIEF MODULE DESCRIPTION
5 * OMAP Watchdog timer register definitions
6 *
7 * Copyright (C) 2004 Texas Instruments.
8 *
9 * 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
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
20 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 675 Mass Ave, Cambridge, MA 02139, USA.
28 */
29
30#ifndef _OMAP_WATCHDOG_H
31#define _OMAP_WATCHDOG_H
32
33#define OMAP1610_WATCHDOG_BASE 0xfffeb000
34#define OMAP2420_WATCHDOG_BASE 0x48022000 /*WDT Timer 2 */
35
36#ifdef CONFIG_ARCH_OMAP24XX
37#define OMAP_WATCHDOG_BASE OMAP2420_WATCHDOG_BASE
38#else
39#define OMAP_WATCHDOG_BASE OMAP1610_WATCHDOG_BASE
40#define RM_RSTST_WKUP 0
41#endif
42
43#define OMAP_WATCHDOG_REV (OMAP_WATCHDOG_BASE + 0x00)
44#define OMAP_WATCHDOG_SYS_CONFIG (OMAP_WATCHDOG_BASE + 0x10)
45#define OMAP_WATCHDOG_STATUS (OMAP_WATCHDOG_BASE + 0x14)
46#define OMAP_WATCHDOG_CNTRL (OMAP_WATCHDOG_BASE + 0x24)
47#define OMAP_WATCHDOG_CRR (OMAP_WATCHDOG_BASE + 0x28)
48#define OMAP_WATCHDOG_LDR (OMAP_WATCHDOG_BASE + 0x2c)
49#define OMAP_WATCHDOG_TGR (OMAP_WATCHDOG_BASE + 0x30)
50#define OMAP_WATCHDOG_WPS (OMAP_WATCHDOG_BASE + 0x34)
51#define OMAP_WATCHDOG_SPR (OMAP_WATCHDOG_BASE + 0x48)
52
53/* Using the prescaler, the OMAP watchdog could go for many
54 * months before firing. These limits work without scaling,
55 * with the 60 second default assumed by most tools and docs.
56 */
57#define TIMER_MARGIN_MAX (24 * 60 * 60) /* 1 day */
58#define TIMER_MARGIN_DEFAULT 60 /* 60 secs */
59#define TIMER_MARGIN_MIN 1
60
61#define PTV 0 /* prescale */
62#define GET_WLDR_VAL(secs) (0xffffffff - ((secs) * (32768/(1<<PTV))) + 1)
63
64#endif /* _OMAP_WATCHDOG_H */
diff --git a/drivers/char/watchdog/pcwd.c b/drivers/char/watchdog/pcwd.c
index cd7d1b6a5d9f..6f8515db5b07 100644
--- a/drivers/char/watchdog/pcwd.c
+++ b/drivers/char/watchdog/pcwd.c
@@ -572,7 +572,7 @@ static int pcwd_ioctl(struct inode *inode, struct file *file,
572 572
573 switch(cmd) { 573 switch(cmd) {
574 default: 574 default:
575 return -ENOIOCTLCMD; 575 return -ENOTTY;
576 576
577 case WDIOC_GETSUPPORT: 577 case WDIOC_GETSUPPORT:
578 if(copy_to_user(argp, &ident, sizeof(ident))) 578 if(copy_to_user(argp, &ident, sizeof(ident)))
diff --git a/drivers/char/watchdog/pcwd_pci.c b/drivers/char/watchdog/pcwd_pci.c
index c7cfd6dbfe1b..2de6e497c140 100644
--- a/drivers/char/watchdog/pcwd_pci.c
+++ b/drivers/char/watchdog/pcwd_pci.c
@@ -541,7 +541,7 @@ static int pcipcwd_ioctl(struct inode *inode, struct file *file,
541 } 541 }
542 542
543 default: 543 default:
544 return -ENOIOCTLCMD; 544 return -ENOTTY;
545 } 545 }
546} 546}
547 547
diff --git a/drivers/char/watchdog/pcwd_usb.c b/drivers/char/watchdog/pcwd_usb.c
index b7ae73dcdd08..77662cb0ac46 100644
--- a/drivers/char/watchdog/pcwd_usb.c
+++ b/drivers/char/watchdog/pcwd_usb.c
@@ -445,7 +445,7 @@ static int usb_pcwd_ioctl(struct inode *inode, struct file *file,
445 } 445 }
446 446
447 default: 447 default:
448 return -ENOIOCTLCMD; 448 return -ENOTTY;
449 } 449 }
450} 450}
451 451
diff --git a/drivers/char/watchdog/pnx4008_wdt.c b/drivers/char/watchdog/pnx4008_wdt.c
new file mode 100644
index 000000000000..e7f0450a939d
--- /dev/null
+++ b/drivers/char/watchdog/pnx4008_wdt.c
@@ -0,0 +1,362 @@
1/*
2 * drivers/char/watchdog/pnx4008_wdt.c
3 *
4 * Watchdog driver for PNX4008 board
5 *
6 * Authors: Dmitry Chigirev <source@mvista.com>,
7 * Vitaly Wool <vitalywool@gmail.com>
8 * Based on sa1100 driver,
9 * Copyright (C) 2000 Oleg Drokin <green@crimea.edu>
10 *
11 * 2005-2006 (c) MontaVista Software, Inc. This file is licensed under
12 * the terms of the GNU General Public License version 2. This program
13 * is licensed "as is" without any warranty of any kind, whether express
14 * or implied.
15 */
16
17#include <linux/config.h>
18#include <linux/module.h>
19#include <linux/moduleparam.h>
20#include <linux/types.h>
21#include <linux/kernel.h>
22#include <linux/fs.h>
23#include <linux/miscdevice.h>
24#include <linux/watchdog.h>
25#include <linux/init.h>
26#include <linux/bitops.h>
27#include <linux/ioport.h>
28#include <linux/device.h>
29#include <linux/platform_device.h>
30#include <linux/clk.h>
31#include <linux/spinlock.h>
32
33#include <asm/hardware.h>
34#include <asm/uaccess.h>
35#include <asm/io.h>
36
37#define MODULE_NAME "PNX4008-WDT: "
38
39/* WatchDog Timer - Chapter 23 Page 207 */
40
41#define DEFAULT_HEARTBEAT 19
42#define MAX_HEARTBEAT 60
43
44/* Watchdog timer register set definition */
45#define WDTIM_INT(p) ((p) + 0x0)
46#define WDTIM_CTRL(p) ((p) + 0x4)
47#define WDTIM_COUNTER(p) ((p) + 0x8)
48#define WDTIM_MCTRL(p) ((p) + 0xC)
49#define WDTIM_MATCH0(p) ((p) + 0x10)
50#define WDTIM_EMR(p) ((p) + 0x14)
51#define WDTIM_PULSE(p) ((p) + 0x18)
52#define WDTIM_RES(p) ((p) + 0x1C)
53
54/* WDTIM_INT bit definitions */
55#define MATCH_INT 1
56
57/* WDTIM_CTRL bit definitions */
58#define COUNT_ENAB 1
59#define RESET_COUNT (1<<1)
60#define DEBUG_EN (1<<2)
61
62/* WDTIM_MCTRL bit definitions */
63#define MR0_INT 1
64#undef RESET_COUNT0
65#define RESET_COUNT0 (1<<2)
66#define STOP_COUNT0 (1<<2)
67#define M_RES1 (1<<3)
68#define M_RES2 (1<<4)
69#define RESFRC1 (1<<5)
70#define RESFRC2 (1<<6)
71
72/* WDTIM_EMR bit definitions */
73#define EXT_MATCH0 1
74#define MATCH_OUTPUT_HIGH (2<<4) /*a MATCH_CTRL setting */
75
76/* WDTIM_RES bit definitions */
77#define WDOG_RESET 1 /* read only */
78
79#define WDOG_COUNTER_RATE 13000000 /*the counter clock is 13 MHz fixed */
80
81static int nowayout = WATCHDOG_NOWAYOUT;
82static int heartbeat = DEFAULT_HEARTBEAT;
83
84static spinlock_t io_lock;
85static unsigned long wdt_status;
86#define WDT_IN_USE 0
87#define WDT_OK_TO_CLOSE 1
88#define WDT_REGION_INITED 2
89#define WDT_DEVICE_INITED 3
90
91static unsigned long boot_status;
92
93static struct resource *wdt_mem;
94static void __iomem *wdt_base;
95struct clk *wdt_clk;
96
97static void wdt_enable(void)
98{
99 spin_lock(&io_lock);
100
101 if (wdt_clk)
102 clk_set_rate(wdt_clk, 1);
103
104 /* stop counter, initiate counter reset */
105 __raw_writel(RESET_COUNT, WDTIM_CTRL(wdt_base));
106 /*wait for reset to complete. 100% guarantee event */
107 while (__raw_readl(WDTIM_COUNTER(wdt_base)))
108 cpu_relax();
109 /* internal and external reset, stop after that */
110 __raw_writel(M_RES2 | STOP_COUNT0 | RESET_COUNT0,
111 WDTIM_MCTRL(wdt_base));
112 /* configure match output */
113 __raw_writel(MATCH_OUTPUT_HIGH, WDTIM_EMR(wdt_base));
114 /* clear interrupt, just in case */
115 __raw_writel(MATCH_INT, WDTIM_INT(wdt_base));
116 /* the longest pulse period 65541/(13*10^6) seconds ~ 5 ms. */
117 __raw_writel(0xFFFF, WDTIM_PULSE(wdt_base));
118 __raw_writel(heartbeat * WDOG_COUNTER_RATE, WDTIM_MATCH0(wdt_base));
119 /*enable counter, stop when debugger active */
120 __raw_writel(COUNT_ENAB | DEBUG_EN, WDTIM_CTRL(wdt_base));
121
122 spin_unlock(&io_lock);
123}
124
125static void wdt_disable(void)
126{
127 spin_lock(&io_lock);
128
129 __raw_writel(0, WDTIM_CTRL(wdt_base)); /*stop counter */
130 if (wdt_clk)
131 clk_set_rate(wdt_clk, 0);
132
133 spin_unlock(&io_lock);
134}
135
136static int pnx4008_wdt_open(struct inode *inode, struct file *file)
137{
138 if (test_and_set_bit(WDT_IN_USE, &wdt_status))
139 return -EBUSY;
140
141 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
142
143 wdt_enable();
144
145 return nonseekable_open(inode, file);
146}
147
148static ssize_t
149pnx4008_wdt_write(struct file *file, const char *data, size_t len,
150 loff_t * ppos)
151{
152 /* Can't seek (pwrite) on this device */
153 if (ppos != &file->f_pos)
154 return -ESPIPE;
155
156 if (len) {
157 if (!nowayout) {
158 size_t i;
159
160 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
161
162 for (i = 0; i != len; i++) {
163 char c;
164
165 if (get_user(c, data + i))
166 return -EFAULT;
167 if (c == 'V')
168 set_bit(WDT_OK_TO_CLOSE, &wdt_status);
169 }
170 }
171 wdt_enable();
172 }
173
174 return len;
175}
176
177static struct watchdog_info ident = {
178 .options = WDIOF_CARDRESET | WDIOF_MAGICCLOSE |
179 WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
180 .identity = "PNX4008 Watchdog",
181};
182
183static int
184pnx4008_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
185 unsigned long arg)
186{
187 int ret = -ENOIOCTLCMD;
188 int time;
189
190 switch (cmd) {
191 case WDIOC_GETSUPPORT:
192 ret = copy_to_user((struct watchdog_info *)arg, &ident,
193 sizeof(ident)) ? -EFAULT : 0;
194 break;
195
196 case WDIOC_GETSTATUS:
197 ret = put_user(0, (int *)arg);
198 break;
199
200 case WDIOC_GETBOOTSTATUS:
201 ret = put_user(boot_status, (int *)arg);
202 break;
203
204 case WDIOC_SETTIMEOUT:
205 ret = get_user(time, (int *)arg);
206 if (ret)
207 break;
208
209 if (time <= 0 || time > MAX_HEARTBEAT) {
210 ret = -EINVAL;
211 break;
212 }
213
214 heartbeat = time;
215 wdt_enable();
216 /* Fall through */
217
218 case WDIOC_GETTIMEOUT:
219 ret = put_user(heartbeat, (int *)arg);
220 break;
221
222 case WDIOC_KEEPALIVE:
223 wdt_enable();
224 ret = 0;
225 break;
226 }
227 return ret;
228}
229
230static int pnx4008_wdt_release(struct inode *inode, struct file *file)
231{
232 if (!test_bit(WDT_OK_TO_CLOSE, &wdt_status))
233 printk(KERN_WARNING "WATCHDOG: Device closed unexpectdly\n");
234
235 wdt_disable();
236 clear_bit(WDT_IN_USE, &wdt_status);
237 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
238
239 return 0;
240}
241
242static struct file_operations pnx4008_wdt_fops = {
243 .owner = THIS_MODULE,
244 .llseek = no_llseek,
245 .write = pnx4008_wdt_write,
246 .ioctl = pnx4008_wdt_ioctl,
247 .open = pnx4008_wdt_open,
248 .release = pnx4008_wdt_release,
249};
250
251static struct miscdevice pnx4008_wdt_miscdev = {
252 .minor = WATCHDOG_MINOR,
253 .name = "watchdog",
254 .fops = &pnx4008_wdt_fops,
255};
256
257static int pnx4008_wdt_probe(struct platform_device *pdev)
258{
259 int ret = 0, size;
260 struct resource *res;
261
262 spin_lock_init(&io_lock);
263
264 if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT)
265 heartbeat = DEFAULT_HEARTBEAT;
266
267 printk(KERN_INFO MODULE_NAME
268 "PNX4008 Watchdog Timer: heartbeat %d sec\n", heartbeat);
269
270 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
271 if (res == NULL) {
272 printk(KERN_INFO MODULE_NAME
273 "failed to get memory region resouce\n");
274 return -ENOENT;
275 }
276
277 size = res->end - res->start + 1;
278 wdt_mem = request_mem_region(res->start, size, pdev->name);
279
280 if (wdt_mem == NULL) {
281 printk(KERN_INFO MODULE_NAME "failed to get memory region\n");
282 return -ENOENT;
283 }
284 wdt_base = (void __iomem *)IO_ADDRESS(res->start);
285
286 wdt_clk = clk_get(&pdev->dev, "wdt_ck");
287 if (!wdt_clk) {
288 release_resource(wdt_mem);
289 kfree(wdt_mem);
290 goto out;
291 } else
292 clk_set_rate(wdt_clk, 1);
293
294 ret = misc_register(&pnx4008_wdt_miscdev);
295 if (ret < 0) {
296 printk(KERN_ERR MODULE_NAME "cannot register misc device\n");
297 release_resource(wdt_mem);
298 kfree(wdt_mem);
299 clk_set_rate(wdt_clk, 0);
300 } else {
301 boot_status = (__raw_readl(WDTIM_RES(wdt_base)) & WDOG_RESET) ?
302 WDIOF_CARDRESET : 0;
303 wdt_disable(); /*disable for now */
304 set_bit(WDT_DEVICE_INITED, &wdt_status);
305 }
306
307out:
308 return ret;
309}
310
311static int pnx4008_wdt_remove(struct platform_device *pdev)
312{
313 misc_deregister(&pnx4008_wdt_miscdev);
314 if (wdt_clk) {
315 clk_set_rate(wdt_clk, 0);
316 clk_put(wdt_clk);
317 wdt_clk = NULL;
318 }
319 if (wdt_mem) {
320 release_resource(wdt_mem);
321 kfree(wdt_mem);
322 wdt_mem = NULL;
323 }
324 return 0;
325}
326
327static struct platform_driver platform_wdt_driver = {
328 .driver = {
329 .name = "watchdog",
330 },
331 .probe = pnx4008_wdt_probe,
332 .remove = pnx4008_wdt_remove,
333};
334
335static int __init pnx4008_wdt_init(void)
336{
337 return platform_driver_register(&platform_wdt_driver);
338}
339
340static void __exit pnx4008_wdt_exit(void)
341{
342 return platform_driver_unregister(&platform_wdt_driver);
343}
344
345module_init(pnx4008_wdt_init);
346module_exit(pnx4008_wdt_exit);
347
348MODULE_AUTHOR("MontaVista Software, Inc. <source@mvista.com>");
349MODULE_DESCRIPTION("PNX4008 Watchdog Driver");
350
351module_param(heartbeat, int, 0);
352MODULE_PARM_DESC(heartbeat,
353 "Watchdog heartbeat period in seconds from 1 to "
354 __MODULE_STRING(MAX_HEARTBEAT) ", default "
355 __MODULE_STRING(DEFAULT_HEARTBEAT));
356
357module_param(nowayout, int, 0);
358MODULE_PARM_DESC(nowayout,
359 "Set to 1 to keep watchdog running after device release");
360
361MODULE_LICENSE("GPL");
362MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/char/watchdog/s3c2410_wdt.c b/drivers/char/watchdog/s3c2410_wdt.c
index be978e8ed754..b36a04ae9ab8 100644
--- a/drivers/char/watchdog/s3c2410_wdt.c
+++ b/drivers/char/watchdog/s3c2410_wdt.c
@@ -62,7 +62,7 @@
62#define CONFIG_S3C2410_WATCHDOG_ATBOOT (0) 62#define CONFIG_S3C2410_WATCHDOG_ATBOOT (0)
63#define CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME (15) 63#define CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME (15)
64 64
65static int nowayout = WATCHDOG_NOWAYOUT; 65static int nowayout = WATCHDOG_NOWAYOUT;
66static int tmr_margin = CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME; 66static int tmr_margin = CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME;
67static int tmr_atboot = CONFIG_S3C2410_WATCHDOG_ATBOOT; 67static int tmr_atboot = CONFIG_S3C2410_WATCHDOG_ATBOOT;
68static int soft_noboot = 0; 68static int soft_noboot = 0;
@@ -213,11 +213,10 @@ static int s3c2410wdt_open(struct inode *inode, struct file *file)
213 if(down_trylock(&open_lock)) 213 if(down_trylock(&open_lock))
214 return -EBUSY; 214 return -EBUSY;
215 215
216 if (nowayout) { 216 if (nowayout)
217 __module_get(THIS_MODULE); 217 __module_get(THIS_MODULE);
218 } else { 218
219 allow_close = CLOSE_STATE_ALLOW; 219 allow_close = CLOSE_STATE_NOT;
220 }
221 220
222 /* start the timer */ 221 /* start the timer */
223 s3c2410wdt_start(); 222 s3c2410wdt_start();
@@ -230,6 +229,7 @@ static int s3c2410wdt_release(struct inode *inode, struct file *file)
230 * Shut off the timer. 229 * Shut off the timer.
231 * Lock it in if it's a module and we set nowayout 230 * Lock it in if it's a module and we set nowayout
232 */ 231 */
232
233 if (allow_close == CLOSE_STATE_ALLOW) { 233 if (allow_close == CLOSE_STATE_ALLOW) {
234 s3c2410wdt_stop(); 234 s3c2410wdt_stop();
235 } else { 235 } else {
@@ -288,7 +288,7 @@ static int s3c2410wdt_ioctl(struct inode *inode, struct file *file,
288 288
289 switch (cmd) { 289 switch (cmd) {
290 default: 290 default:
291 return -ENOIOCTLCMD; 291 return -ENOTTY;
292 292
293 case WDIOC_GETSUPPORT: 293 case WDIOC_GETSUPPORT:
294 return copy_to_user(argp, &s3c2410_wdt_ident, 294 return copy_to_user(argp, &s3c2410_wdt_ident,
diff --git a/drivers/char/watchdog/sa1100_wdt.c b/drivers/char/watchdog/sa1100_wdt.c
index 1fc16d995788..33c1137f17d6 100644
--- a/drivers/char/watchdog/sa1100_wdt.c
+++ b/drivers/char/watchdog/sa1100_wdt.c
@@ -90,7 +90,7 @@ static struct watchdog_info ident = {
90static int sa1100dog_ioctl(struct inode *inode, struct file *file, 90static int sa1100dog_ioctl(struct inode *inode, struct file *file,
91 unsigned int cmd, unsigned long arg) 91 unsigned int cmd, unsigned long arg)
92{ 92{
93 int ret = -ENOIOCTLCMD; 93 int ret = -ENOTTY;
94 int time; 94 int time;
95 void __user *argp = (void __user *)arg; 95 void __user *argp = (void __user *)arg;
96 int __user *p = argp; 96 int __user *p = argp;
diff --git a/drivers/char/watchdog/sbc60xxwdt.c b/drivers/char/watchdog/sbc60xxwdt.c
index 4663c2fd53cd..c7b2045bc76b 100644
--- a/drivers/char/watchdog/sbc60xxwdt.c
+++ b/drivers/char/watchdog/sbc60xxwdt.c
@@ -235,7 +235,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
235 switch(cmd) 235 switch(cmd)
236 { 236 {
237 default: 237 default:
238 return -ENOIOCTLCMD; 238 return -ENOTTY;
239 case WDIOC_GETSUPPORT: 239 case WDIOC_GETSUPPORT:
240 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0; 240 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0;
241 case WDIOC_GETSTATUS: 241 case WDIOC_GETSTATUS:
diff --git a/drivers/char/watchdog/sbc_epx_c3.c b/drivers/char/watchdog/sbc_epx_c3.c
index bfc475dabe6d..8882b427d24f 100644
--- a/drivers/char/watchdog/sbc_epx_c3.c
+++ b/drivers/char/watchdog/sbc_epx_c3.c
@@ -141,7 +141,7 @@ static int epx_c3_ioctl(struct inode *inode, struct file *file,
141 141
142 return retval; 142 return retval;
143 default: 143 default:
144 return -ENOIOCTLCMD; 144 return -ENOTTY;
145 } 145 }
146} 146}
147 147
diff --git a/drivers/char/watchdog/sc1200wdt.c b/drivers/char/watchdog/sc1200wdt.c
index 7c3cf293a5af..d8d0f28e0acf 100644
--- a/drivers/char/watchdog/sc1200wdt.c
+++ b/drivers/char/watchdog/sc1200wdt.c
@@ -180,7 +180,7 @@ static int sc1200wdt_ioctl(struct inode *inode, struct file *file, unsigned int
180 180
181 switch (cmd) { 181 switch (cmd) {
182 default: 182 default:
183 return -ENOIOCTLCMD; /* Keep Pavel Machek amused ;) */ 183 return -ENOTTY;
184 184
185 case WDIOC_GETSUPPORT: 185 case WDIOC_GETSUPPORT:
186 if (copy_to_user(argp, &ident, sizeof ident)) 186 if (copy_to_user(argp, &ident, sizeof ident))
diff --git a/drivers/char/watchdog/sc520_wdt.c b/drivers/char/watchdog/sc520_wdt.c
index 2c7c9db71be8..caec37ba750a 100644
--- a/drivers/char/watchdog/sc520_wdt.c
+++ b/drivers/char/watchdog/sc520_wdt.c
@@ -290,7 +290,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
290 switch(cmd) 290 switch(cmd)
291 { 291 {
292 default: 292 default:
293 return -ENOIOCTLCMD; 293 return -ENOTTY;
294 case WDIOC_GETSUPPORT: 294 case WDIOC_GETSUPPORT:
295 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0; 295 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0;
296 case WDIOC_GETSTATUS: 296 case WDIOC_GETSTATUS:
diff --git a/drivers/char/watchdog/scx200_wdt.c b/drivers/char/watchdog/scx200_wdt.c
index c561299a5537..fc0e0347f9d2 100644
--- a/drivers/char/watchdog/scx200_wdt.c
+++ b/drivers/char/watchdog/scx200_wdt.c
@@ -166,7 +166,7 @@ static int scx200_wdt_ioctl(struct inode *inode, struct file *file,
166 166
167 switch (cmd) { 167 switch (cmd) {
168 default: 168 default:
169 return -ENOIOCTLCMD; 169 return -ENOTTY;
170 case WDIOC_GETSUPPORT: 170 case WDIOC_GETSUPPORT:
171 if(copy_to_user(argp, &ident, sizeof(ident))) 171 if(copy_to_user(argp, &ident, sizeof(ident)))
172 return -EFAULT; 172 return -EFAULT;
diff --git a/drivers/char/watchdog/shwdt.c b/drivers/char/watchdog/shwdt.c
index 1355038f1044..dc403629aeb3 100644
--- a/drivers/char/watchdog/shwdt.c
+++ b/drivers/char/watchdog/shwdt.c
@@ -27,7 +27,7 @@
27#include <linux/notifier.h> 27#include <linux/notifier.h>
28#include <linux/ioport.h> 28#include <linux/ioport.h>
29#include <linux/fs.h> 29#include <linux/fs.h>
30 30#include <linux/mm.h>
31#include <asm/io.h> 31#include <asm/io.h>
32#include <asm/uaccess.h> 32#include <asm/uaccess.h>
33#include <asm/watchdog.h> 33#include <asm/watchdog.h>
@@ -125,7 +125,6 @@ static void sh_wdt_start(void)
125 125
126/** 126/**
127 * sh_wdt_stop - Stop the Watchdog 127 * sh_wdt_stop - Stop the Watchdog
128 *
129 * Stops the watchdog. 128 * Stops the watchdog.
130 */ 129 */
131static void sh_wdt_stop(void) 130static void sh_wdt_stop(void)
@@ -141,22 +140,20 @@ static void sh_wdt_stop(void)
141 140
142/** 141/**
143 * sh_wdt_keepalive - Keep the Userspace Watchdog Alive 142 * sh_wdt_keepalive - Keep the Userspace Watchdog Alive
144 *
145 * The Userspace watchdog got a KeepAlive: schedule the next heartbeat. 143 * The Userspace watchdog got a KeepAlive: schedule the next heartbeat.
146 */ 144 */
147static void sh_wdt_keepalive(void) 145static inline void sh_wdt_keepalive(void)
148{ 146{
149 next_heartbeat = jiffies + (heartbeat * HZ); 147 next_heartbeat = jiffies + (heartbeat * HZ);
150} 148}
151 149
152/** 150/**
153 * sh_wdt_set_heartbeat - Set the Userspace Watchdog heartbeat 151 * sh_wdt_set_heartbeat - Set the Userspace Watchdog heartbeat
154 *
155 * Set the Userspace Watchdog heartbeat 152 * Set the Userspace Watchdog heartbeat
156 */ 153 */
157static int sh_wdt_set_heartbeat(int t) 154static int sh_wdt_set_heartbeat(int t)
158{ 155{
159 if ((t < 1) || (t > 3600)) /* arbitrary upper limit */ 156 if (unlikely((t < 1) || (t > 3600))) /* arbitrary upper limit */
160 return -EINVAL; 157 return -EINVAL;
161 158
162 heartbeat = t; 159 heartbeat = t;
@@ -165,7 +162,6 @@ static int sh_wdt_set_heartbeat(int t)
165 162
166/** 163/**
167 * sh_wdt_ping - Ping the Watchdog 164 * sh_wdt_ping - Ping the Watchdog
168 *
169 * @data: Unused 165 * @data: Unused
170 * 166 *
171 * Clears overflow bit, resets timer counter. 167 * Clears overflow bit, resets timer counter.
@@ -182,14 +178,13 @@ static void sh_wdt_ping(unsigned long data)
182 sh_wdt_write_cnt(0); 178 sh_wdt_write_cnt(0);
183 179
184 mod_timer(&timer, next_ping_period(clock_division_ratio)); 180 mod_timer(&timer, next_ping_period(clock_division_ratio));
185 } else { 181 } else
186 printk(KERN_WARNING PFX "Heartbeat lost! Will not ping the watchdog\n"); 182 printk(KERN_WARNING PFX "Heartbeat lost! Will not ping "
187 } 183 "the watchdog\n");
188} 184}
189 185
190/** 186/**
191 * sh_wdt_open - Open the Device 187 * sh_wdt_open - Open the Device
192 *
193 * @inode: inode of device 188 * @inode: inode of device
194 * @file: file handle of device 189 * @file: file handle of device
195 * 190 *
@@ -209,7 +204,6 @@ static int sh_wdt_open(struct inode *inode, struct file *file)
209 204
210/** 205/**
211 * sh_wdt_close - Close the Device 206 * sh_wdt_close - Close the Device
212 *
213 * @inode: inode of device 207 * @inode: inode of device
214 * @file: file handle of device 208 * @file: file handle of device
215 * 209 *
@@ -220,7 +214,8 @@ static int sh_wdt_close(struct inode *inode, struct file *file)
220 if (shwdt_expect_close == 42) { 214 if (shwdt_expect_close == 42) {
221 sh_wdt_stop(); 215 sh_wdt_stop();
222 } else { 216 } else {
223 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); 217 printk(KERN_CRIT PFX "Unexpected close, not "
218 "stopping watchdog!\n");
224 sh_wdt_keepalive(); 219 sh_wdt_keepalive();
225 } 220 }
226 221
@@ -232,7 +227,6 @@ static int sh_wdt_close(struct inode *inode, struct file *file)
232 227
233/** 228/**
234 * sh_wdt_write - Write to Device 229 * sh_wdt_write - Write to Device
235 *
236 * @file: file handle of device 230 * @file: file handle of device
237 * @buf: buffer to write 231 * @buf: buffer to write
238 * @count: length of buffer 232 * @count: length of buffer
@@ -264,8 +258,56 @@ static ssize_t sh_wdt_write(struct file *file, const char *buf,
264} 258}
265 259
266/** 260/**
267 * sh_wdt_ioctl - Query Device 261 * sh_wdt_mmap - map WDT/CPG registers into userspace
262 * @file: file structure for the device
263 * @vma: VMA to map the registers into
264 *
265 * A simple mmap() implementation for the corner cases where the counter
266 * needs to be mapped in userspace directly. Due to the relatively small
267 * size of the area, neighbouring registers not necessarily tied to the
268 * CPG will also be accessible through the register page, so this remains
269 * configurable for users that really know what they're doing.
268 * 270 *
271 * Additionaly, the register page maps in the CPG register base relative
272 * to the nearest page-aligned boundary, which requires that userspace do
273 * the appropriate CPU subtype math for calculating the page offset for
274 * the counter value.
275 */
276static int sh_wdt_mmap(struct file *file, struct vm_area_struct *vma)
277{
278 int ret = -ENOSYS;
279
280#ifdef CONFIG_SH_WDT_MMAP
281 unsigned long addr;
282
283 /* Only support the simple cases where we map in a register page. */
284 if (((vma->vm_end - vma->vm_start) != PAGE_SIZE) || vma->vm_pgoff)
285 return -EINVAL;
286
287 /*
288 * Pick WTCNT as the start, it's usually the first register after the
289 * FRQCR, and neither one are generally page-aligned out of the box.
290 */
291 addr = WTCNT & ~(PAGE_SIZE - 1);
292
293 vma->vm_flags |= VM_IO;
294 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
295
296 if (io_remap_pfn_range(vma, vma->vm_start, addr >> PAGE_SHIFT,
297 PAGE_SIZE, vma->vm_page_prot)) {
298 printk(KERN_ERR PFX "%s: io_remap_pfn_range failed\n",
299 __FUNCTION__);
300 return -EAGAIN;
301 }
302
303 ret = 0;
304#endif
305
306 return ret;
307}
308
309/**
310 * sh_wdt_ioctl - Query Device
269 * @inode: inode of device 311 * @inode: inode of device
270 * @file: file handle of device 312 * @file: file handle of device
271 * @cmd: watchdog command 313 * @cmd: watchdog command
@@ -318,7 +360,7 @@ static int sh_wdt_ioctl(struct inode *inode, struct file *file,
318 360
319 return retval; 361 return retval;
320 default: 362 default:
321 return -ENOIOCTLCMD; 363 return -ENOTTY;
322 } 364 }
323 365
324 return 0; 366 return 0;
@@ -326,7 +368,6 @@ static int sh_wdt_ioctl(struct inode *inode, struct file *file,
326 368
327/** 369/**
328 * sh_wdt_notify_sys - Notifier Handler 370 * sh_wdt_notify_sys - Notifier Handler
329 *
330 * @this: notifier block 371 * @this: notifier block
331 * @code: notifier event 372 * @code: notifier event
332 * @unused: unused 373 * @unused: unused
@@ -337,9 +378,8 @@ static int sh_wdt_ioctl(struct inode *inode, struct file *file,
337static int sh_wdt_notify_sys(struct notifier_block *this, 378static int sh_wdt_notify_sys(struct notifier_block *this,
338 unsigned long code, void *unused) 379 unsigned long code, void *unused)
339{ 380{
340 if (code == SYS_DOWN || code == SYS_HALT) { 381 if (code == SYS_DOWN || code == SYS_HALT)
341 sh_wdt_stop(); 382 sh_wdt_stop();
342 }
343 383
344 return NOTIFY_DONE; 384 return NOTIFY_DONE;
345} 385}
@@ -351,10 +391,12 @@ static const struct file_operations sh_wdt_fops = {
351 .ioctl = sh_wdt_ioctl, 391 .ioctl = sh_wdt_ioctl,
352 .open = sh_wdt_open, 392 .open = sh_wdt_open,
353 .release = sh_wdt_close, 393 .release = sh_wdt_close,
394 .mmap = sh_wdt_mmap,
354}; 395};
355 396
356static struct watchdog_info sh_wdt_info = { 397static struct watchdog_info sh_wdt_info = {
357 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, 398 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
399 WDIOF_MAGICCLOSE,
358 .firmware_version = 1, 400 .firmware_version = 1,
359 .identity = "SH WDT", 401 .identity = "SH WDT",
360}; 402};
@@ -371,7 +413,6 @@ static struct miscdevice sh_wdt_miscdev = {
371 413
372/** 414/**
373 * sh_wdt_init - Initialize module 415 * sh_wdt_init - Initialize module
374 *
375 * Registers the device and notifier handler. Actual device 416 * Registers the device and notifier handler. Actual device
376 * initialization is handled by sh_wdt_open(). 417 * initialization is handled by sh_wdt_open().
377 */ 418 */
@@ -381,15 +422,15 @@ static int __init sh_wdt_init(void)
381 422
382 if ((clock_division_ratio < 0x5) || (clock_division_ratio > 0x7)) { 423 if ((clock_division_ratio < 0x5) || (clock_division_ratio > 0x7)) {
383 clock_division_ratio = WTCSR_CKS_4096; 424 clock_division_ratio = WTCSR_CKS_4096;
384 printk(KERN_INFO PFX "clock_division_ratio value must be 0x5<=x<=0x7, using %d\n", 425 printk(KERN_INFO PFX "clock_division_ratio value must "
385 clock_division_ratio); 426 "be 0x5<=x<=0x7, using %d\n", clock_division_ratio);
386 } 427 }
387 428
388 if (sh_wdt_set_heartbeat(heartbeat)) 429 rc = sh_wdt_set_heartbeat(heartbeat);
389 { 430 if (unlikely(rc)) {
390 heartbeat = WATCHDOG_HEARTBEAT; 431 heartbeat = WATCHDOG_HEARTBEAT;
391 printk(KERN_INFO PFX "heartbeat value must be 1<=x<=3600, using %d\n", 432 printk(KERN_INFO PFX "heartbeat value must "
392 heartbeat); 433 "be 1<=x<=3600, using %d\n", heartbeat);
393 } 434 }
394 435
395 init_timer(&timer); 436 init_timer(&timer);
@@ -397,15 +438,16 @@ static int __init sh_wdt_init(void)
397 timer.data = 0; 438 timer.data = 0;
398 439
399 rc = register_reboot_notifier(&sh_wdt_notifier); 440 rc = register_reboot_notifier(&sh_wdt_notifier);
400 if (rc) { 441 if (unlikely(rc)) {
401 printk(KERN_ERR PFX "Can't register reboot notifier (err=%d)\n", rc); 442 printk(KERN_ERR PFX "Can't register reboot notifier (err=%d)\n",
443 rc);
402 return rc; 444 return rc;
403 } 445 }
404 446
405 rc = misc_register(&sh_wdt_miscdev); 447 rc = misc_register(&sh_wdt_miscdev);
406 if (rc) { 448 if (unlikely(rc)) {
407 printk(KERN_ERR PFX "Can't register miscdev on minor=%d (err=%d)\n", 449 printk(KERN_ERR PFX "Can't register miscdev on "
408 sh_wdt_miscdev.minor, rc); 450 "minor=%d (err=%d)\n", sh_wdt_miscdev.minor, rc);
409 unregister_reboot_notifier(&sh_wdt_notifier); 451 unregister_reboot_notifier(&sh_wdt_notifier);
410 return rc; 452 return rc;
411 } 453 }
@@ -418,7 +460,6 @@ static int __init sh_wdt_init(void)
418 460
419/** 461/**
420 * sh_wdt_exit - Deinitialize module 462 * sh_wdt_exit - Deinitialize module
421 *
422 * Unregisters the device and notifier handler. Actual device 463 * Unregisters the device and notifier handler. Actual device
423 * deinitialization is handled by sh_wdt_close(). 464 * deinitialization is handled by sh_wdt_close().
424 */ 465 */
@@ -434,14 +475,13 @@ MODULE_LICENSE("GPL");
434MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); 475MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
435 476
436module_param(clock_division_ratio, int, 0); 477module_param(clock_division_ratio, int, 0);
437MODULE_PARM_DESC(clock_division_ratio, "Clock division ratio. Valid ranges are from 0x5 (1.31ms) to 0x7 (5.25ms). Defaults to 0x7."); 478MODULE_PARM_DESC(clock_division_ratio, "Clock division ratio. Valid ranges are from 0x5 (1.31ms) to 0x7 (5.25ms). (default=" __MODULE_STRING(clock_division_ratio) ")");
438 479
439module_param(heartbeat, int, 0); 480module_param(heartbeat, int, 0);
440MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (1<=heartbeat<=3600, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")"); 481MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (1<=heartbeat<=3600, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
441 482
442module_param(nowayout, int, 0); 483module_param(nowayout, int, 0);
443MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 484MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
444 485
445module_init(sh_wdt_init); 486module_init(sh_wdt_init);
446module_exit(sh_wdt_exit); 487module_exit(sh_wdt_exit);
447
diff --git a/drivers/char/watchdog/softdog.c b/drivers/char/watchdog/softdog.c
index ef8da517545a..4067e1f8a368 100644
--- a/drivers/char/watchdog/softdog.c
+++ b/drivers/char/watchdog/softdog.c
@@ -203,7 +203,7 @@ static int softdog_ioctl(struct inode *inode, struct file *file,
203 }; 203 };
204 switch (cmd) { 204 switch (cmd) {
205 default: 205 default:
206 return -ENOIOCTLCMD; 206 return -ENOTTY;
207 case WDIOC_GETSUPPORT: 207 case WDIOC_GETSUPPORT:
208 return copy_to_user(argp, &ident, 208 return copy_to_user(argp, &ident,
209 sizeof(ident)) ? -EFAULT : 0; 209 sizeof(ident)) ? -EFAULT : 0;
diff --git a/drivers/char/watchdog/w83627hf_wdt.c b/drivers/char/watchdog/w83627hf_wdt.c
index 13f16d41c2fd..b4adc527e687 100644
--- a/drivers/char/watchdog/w83627hf_wdt.c
+++ b/drivers/char/watchdog/w83627hf_wdt.c
@@ -223,7 +223,7 @@ wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
223 } 223 }
224 224
225 default: 225 default:
226 return -ENOIOCTLCMD; 226 return -ENOTTY;
227 } 227 }
228 return 0; 228 return 0;
229} 229}
diff --git a/drivers/char/watchdog/w83877f_wdt.c b/drivers/char/watchdog/w83877f_wdt.c
index ccf6c0915945..b0e5f84d6baf 100644
--- a/drivers/char/watchdog/w83877f_wdt.c
+++ b/drivers/char/watchdog/w83877f_wdt.c
@@ -252,7 +252,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
252 switch(cmd) 252 switch(cmd)
253 { 253 {
254 default: 254 default:
255 return -ENOIOCTLCMD; 255 return -ENOTTY;
256 case WDIOC_GETSUPPORT: 256 case WDIOC_GETSUPPORT:
257 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0; 257 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0;
258 case WDIOC_GETSTATUS: 258 case WDIOC_GETSTATUS:
diff --git a/drivers/char/watchdog/w83977f_wdt.c b/drivers/char/watchdog/w83977f_wdt.c
index 98f4e17db70a..2c8d5d8bd4e8 100644
--- a/drivers/char/watchdog/w83977f_wdt.c
+++ b/drivers/char/watchdog/w83977f_wdt.c
@@ -393,7 +393,7 @@ static int wdt_ioctl(struct inode *inode, struct file *file,
393 switch(cmd) 393 switch(cmd)
394 { 394 {
395 default: 395 default:
396 return -ENOIOCTLCMD; 396 return -ENOTTY;
397 397
398 case WDIOC_GETSUPPORT: 398 case WDIOC_GETSUPPORT:
399 return copy_to_user(uarg.ident, &ident, sizeof(ident)) ? -EFAULT : 0; 399 return copy_to_user(uarg.ident, &ident, sizeof(ident)) ? -EFAULT : 0;
diff --git a/drivers/char/watchdog/wafer5823wdt.c b/drivers/char/watchdog/wafer5823wdt.c
index 2bb6a9d6ad28..163e028ef9ed 100644
--- a/drivers/char/watchdog/wafer5823wdt.c
+++ b/drivers/char/watchdog/wafer5823wdt.c
@@ -174,7 +174,7 @@ static int wafwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd
174 } 174 }
175 175
176 default: 176 default:
177 return -ENOIOCTLCMD; 177 return -ENOTTY;
178 } 178 }
179 return 0; 179 return 0;
180} 180}
diff --git a/drivers/char/watchdog/wdrtas.c b/drivers/char/watchdog/wdrtas.c
index 5c38cdf41731..1d64e277567d 100644
--- a/drivers/char/watchdog/wdrtas.c
+++ b/drivers/char/watchdog/wdrtas.c
@@ -385,7 +385,7 @@ wdrtas_ioctl(struct inode *inode, struct file *file,
385 return put_user(wdrtas_interval, argp); 385 return put_user(wdrtas_interval, argp);
386 386
387 default: 387 default:
388 return -ENOIOCTLCMD; 388 return -ENOTTY;
389 } 389 }
390} 390}
391 391
diff --git a/drivers/char/watchdog/wdt.c b/drivers/char/watchdog/wdt.c
index 70be81e39a61..13f23f4a2233 100644
--- a/drivers/char/watchdog/wdt.c
+++ b/drivers/char/watchdog/wdt.c
@@ -341,7 +341,7 @@ static int wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
341 switch(cmd) 341 switch(cmd)
342 { 342 {
343 default: 343 default:
344 return -ENOIOCTLCMD; 344 return -ENOTTY;
345 case WDIOC_GETSUPPORT: 345 case WDIOC_GETSUPPORT:
346 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0; 346 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0;
347 347
diff --git a/drivers/char/watchdog/wdt285.c b/drivers/char/watchdog/wdt285.c
index 6555fb844f23..89a249e23fde 100644
--- a/drivers/char/watchdog/wdt285.c
+++ b/drivers/char/watchdog/wdt285.c
@@ -137,7 +137,7 @@ watchdog_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
137 unsigned long arg) 137 unsigned long arg)
138{ 138{
139 unsigned int new_margin; 139 unsigned int new_margin;
140 int ret = -ENOIOCTLCMD; 140 int ret = -ENOTTY;
141 141
142 switch(cmd) { 142 switch(cmd) {
143 case WDIOC_GETSUPPORT: 143 case WDIOC_GETSUPPORT:
diff --git a/drivers/char/watchdog/wdt977.c b/drivers/char/watchdog/wdt977.c
index a0935bc775f8..6253041b235b 100644
--- a/drivers/char/watchdog/wdt977.c
+++ b/drivers/char/watchdog/wdt977.c
@@ -361,7 +361,7 @@ static int wdt977_ioctl(struct inode *inode, struct file *file,
361 switch(cmd) 361 switch(cmd)
362 { 362 {
363 default: 363 default:
364 return -ENOIOCTLCMD; 364 return -ENOTTY;
365 365
366 case WDIOC_GETSUPPORT: 366 case WDIOC_GETSUPPORT:
367 return copy_to_user(uarg.ident, &ident, 367 return copy_to_user(uarg.ident, &ident,
diff --git a/drivers/char/watchdog/wdt_pci.c b/drivers/char/watchdog/wdt_pci.c
index 5918ca2c9c35..74d8cf836e13 100644
--- a/drivers/char/watchdog/wdt_pci.c
+++ b/drivers/char/watchdog/wdt_pci.c
@@ -386,7 +386,7 @@ static int wdtpci_ioctl(struct inode *inode, struct file *file, unsigned int cmd
386 switch(cmd) 386 switch(cmd)
387 { 387 {
388 default: 388 default:
389 return -ENOIOCTLCMD; 389 return -ENOTTY;
390 case WDIOC_GETSUPPORT: 390 case WDIOC_GETSUPPORT:
391 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0; 391 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0;
392 392
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index d35a9f06ab7b..2caaf71d80c8 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -994,7 +994,7 @@ static int cpufreq_suspend(struct sys_device * sysdev, pm_message_t pmsg)
994 unsigned int cur_freq = 0; 994 unsigned int cur_freq = 0;
995 struct cpufreq_policy *cpu_policy; 995 struct cpufreq_policy *cpu_policy;
996 996
997 dprintk("resuming cpu %u\n", cpu); 997 dprintk("suspending cpu %u\n", cpu);
998 998
999 if (!cpu_online(cpu)) 999 if (!cpu_online(cpu))
1000 return 0; 1000 return 0;
diff --git a/drivers/eisa/eisa-bus.c b/drivers/eisa/eisa-bus.c
index 6078e2f58817..3a365e159d89 100644
--- a/drivers/eisa/eisa-bus.c
+++ b/drivers/eisa/eisa-bus.c
@@ -128,9 +128,23 @@ static int eisa_bus_match (struct device *dev, struct device_driver *drv)
128 return 0; 128 return 0;
129} 129}
130 130
131static int eisa_bus_uevent(struct device *dev, char **envp, int num_envp,
132 char *buffer, int buffer_size)
133{
134 struct eisa_device *edev = to_eisa_device(dev);
135 int i = 0;
136 int length = 0;
137
138 add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
139 "MODALIAS=" EISA_DEVICE_MODALIAS_FMT, edev->id.sig);
140 envp[i] = NULL;
141 return 0;
142}
143
131struct bus_type eisa_bus_type = { 144struct bus_type eisa_bus_type = {
132 .name = "eisa", 145 .name = "eisa",
133 .match = eisa_bus_match, 146 .match = eisa_bus_match,
147 .uevent = eisa_bus_uevent,
134}; 148};
135 149
136int eisa_driver_register (struct eisa_driver *edrv) 150int eisa_driver_register (struct eisa_driver *edrv)
@@ -160,6 +174,14 @@ static ssize_t eisa_show_state (struct device *dev, struct device_attribute *att
160 174
161static DEVICE_ATTR(enabled, S_IRUGO, eisa_show_state, NULL); 175static DEVICE_ATTR(enabled, S_IRUGO, eisa_show_state, NULL);
162 176
177static ssize_t eisa_show_modalias (struct device *dev, struct device_attribute *attr, char *buf)
178{
179 struct eisa_device *edev = to_eisa_device (dev);
180 return sprintf (buf, EISA_DEVICE_MODALIAS_FMT "\n", edev->id.sig);
181}
182
183static DEVICE_ATTR(modalias, S_IRUGO, eisa_show_modalias, NULL);
184
163static int __init eisa_init_device (struct eisa_root_device *root, 185static int __init eisa_init_device (struct eisa_root_device *root,
164 struct eisa_device *edev, 186 struct eisa_device *edev,
165 int slot) 187 int slot)
@@ -209,6 +231,7 @@ static int __init eisa_register_device (struct eisa_device *edev)
209 231
210 device_create_file (&edev->dev, &dev_attr_signature); 232 device_create_file (&edev->dev, &dev_attr_signature);
211 device_create_file (&edev->dev, &dev_attr_enabled); 233 device_create_file (&edev->dev, &dev_attr_enabled);
234 device_create_file (&edev->dev, &dev_attr_modalias);
212 235
213 return 0; 236 return 0;
214} 237}
diff --git a/drivers/fc4/fc.c b/drivers/fc4/fc.c
index 1a159e8843ca..22d17474755f 100644
--- a/drivers/fc4/fc.c
+++ b/drivers/fc4/fc.c
@@ -974,7 +974,6 @@ int fcp_scsi_dev_reset(Scsi_Cmnd *SCpnt)
974 */ 974 */
975 975
976 fc->rst_pkt->device->host->eh_action = &sem; 976 fc->rst_pkt->device->host->eh_action = &sem;
977 fc->rst_pkt->request->rq_status = RQ_SCSI_BUSY;
978 977
979 fc->rst_pkt->done = fcp_scsi_reset_done; 978 fc->rst_pkt->done = fcp_scsi_reset_done;
980 979
diff --git a/drivers/firmware/dell_rbu.c b/drivers/firmware/dell_rbu.c
index 23b086685453..fc17599c905e 100644
--- a/drivers/firmware/dell_rbu.c
+++ b/drivers/firmware/dell_rbu.c
@@ -227,7 +227,7 @@ static int packetize_data(void *data, size_t length)
227 int packet_length; 227 int packet_length;
228 u8 *temp; 228 u8 *temp;
229 u8 *end = (u8 *) data + length; 229 u8 *end = (u8 *) data + length;
230 pr_debug("packetize_data: data length %d\n", length); 230 pr_debug("packetize_data: data length %zd\n", length);
231 if (!rbu_data.packetsize) { 231 if (!rbu_data.packetsize) {
232 printk(KERN_WARNING 232 printk(KERN_WARNING
233 "dell_rbu: packetsize not specified\n"); 233 "dell_rbu: packetsize not specified\n");
@@ -249,7 +249,7 @@ static int packetize_data(void *data, size_t length)
249 if ((rc = create_packet(temp, packet_length))) 249 if ((rc = create_packet(temp, packet_length)))
250 return rc; 250 return rc;
251 251
252 pr_debug("%lu:%lu\n", temp, (end - temp)); 252 pr_debug("%p:%lu\n", temp, (end - temp));
253 temp += packet_length; 253 temp += packet_length;
254 } 254 }
255 255
diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
index b9e3886d9e16..b8b596d5778d 100644
--- a/drivers/firmware/dmi_scan.c
+++ b/drivers/firmware/dmi_scan.c
@@ -123,6 +123,26 @@ static void __init dmi_save_devices(struct dmi_header *dm)
123 dev->type = *d++ & 0x7f; 123 dev->type = *d++ & 0x7f;
124 dev->name = dmi_string(dm, *d); 124 dev->name = dmi_string(dm, *d);
125 dev->device_data = NULL; 125 dev->device_data = NULL;
126 list_add(&dev->list, &dmi_devices);
127 }
128}
129
130static void __init dmi_save_oem_strings_devices(struct dmi_header *dm)
131{
132 int i, count = *(u8 *)(dm + 1);
133 struct dmi_device *dev;
134
135 for (i = 1; i <= count; i++) {
136 dev = dmi_alloc(sizeof(*dev));
137 if (!dev) {
138 printk(KERN_ERR
139 "dmi_save_oem_strings_devices: out of memory.\n");
140 break;
141 }
142
143 dev->type = DMI_DEV_TYPE_OEM_STRING;
144 dev->name = dmi_string(dm, i);
145 dev->device_data = NULL;
126 146
127 list_add(&dev->list, &dmi_devices); 147 list_add(&dev->list, &dmi_devices);
128 } 148 }
@@ -181,6 +201,9 @@ static void __init dmi_decode(struct dmi_header *dm)
181 case 10: /* Onboard Devices Information */ 201 case 10: /* Onboard Devices Information */
182 dmi_save_devices(dm); 202 dmi_save_devices(dm);
183 break; 203 break;
204 case 11: /* OEM Strings */
205 dmi_save_oem_strings_devices(dm);
206 break;
184 case 38: /* IPMI Device Information */ 207 case 38: /* IPMI Device Information */
185 dmi_save_ipmi_device(dm); 208 dmi_save_ipmi_device(dm);
186 } 209 }
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 0e31a0c496e8..9b88b25b6edb 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -53,7 +53,7 @@ config SENSORS_ADM1021
53 53
54config SENSORS_ADM1025 54config SENSORS_ADM1025
55 tristate "Analog Devices ADM1025 and compatibles" 55 tristate "Analog Devices ADM1025 and compatibles"
56 depends on HWMON && I2C && EXPERIMENTAL 56 depends on HWMON && I2C
57 select HWMON_VID 57 select HWMON_VID
58 help 58 help
59 If you say yes here you get support for Analog Devices ADM1025 59 If you say yes here you get support for Analog Devices ADM1025
@@ -94,6 +94,16 @@ config SENSORS_ADM9240
94 This driver can also be built as a module. If so, the module 94 This driver can also be built as a module. If so, the module
95 will be called adm9240. 95 will be called adm9240.
96 96
97config SENSORS_K8TEMP
98 tristate "AMD K8 processor sensor"
99 depends on HWMON && X86 && PCI && EXPERIMENTAL
100 help
101 If you say yes here you get support for the temperature
102 sensor(s) inside your AMD K8 CPU.
103
104 This driver can also be built as a module. If so, the module
105 will be called k8temp.
106
97config SENSORS_ASB100 107config SENSORS_ASB100
98 tristate "Asus ASB100 Bach" 108 tristate "Asus ASB100 Bach"
99 depends on HWMON && I2C && EXPERIMENTAL 109 depends on HWMON && I2C && EXPERIMENTAL
@@ -121,7 +131,7 @@ config SENSORS_ATXP1
121 131
122config SENSORS_DS1621 132config SENSORS_DS1621
123 tristate "Dallas Semiconductor DS1621 and DS1625" 133 tristate "Dallas Semiconductor DS1621 and DS1625"
124 depends on HWMON && I2C && EXPERIMENTAL 134 depends on HWMON && I2C
125 help 135 help
126 If you say yes here you get support for Dallas Semiconductor 136 If you say yes here you get support for Dallas Semiconductor
127 DS1621 and DS1625 sensor chips. 137 DS1621 and DS1625 sensor chips.
@@ -141,7 +151,7 @@ config SENSORS_F71805F
141 151
142config SENSORS_FSCHER 152config SENSORS_FSCHER
143 tristate "FSC Hermes" 153 tristate "FSC Hermes"
144 depends on HWMON && I2C && EXPERIMENTAL 154 depends on HWMON && I2C
145 help 155 help
146 If you say yes here you get support for Fujitsu Siemens 156 If you say yes here you get support for Fujitsu Siemens
147 Computers Hermes sensor chips. 157 Computers Hermes sensor chips.
@@ -151,7 +161,7 @@ config SENSORS_FSCHER
151 161
152config SENSORS_FSCPOS 162config SENSORS_FSCPOS
153 tristate "FSC Poseidon" 163 tristate "FSC Poseidon"
154 depends on HWMON && I2C && EXPERIMENTAL 164 depends on HWMON && I2C
155 help 165 help
156 If you say yes here you get support for Fujitsu Siemens 166 If you say yes here you get support for Fujitsu Siemens
157 Computers Poseidon sensor chips. 167 Computers Poseidon sensor chips.
@@ -171,7 +181,7 @@ config SENSORS_GL518SM
171 181
172config SENSORS_GL520SM 182config SENSORS_GL520SM
173 tristate "Genesys Logic GL520SM" 183 tristate "Genesys Logic GL520SM"
174 depends on HWMON && I2C && EXPERIMENTAL 184 depends on HWMON && I2C
175 select HWMON_VID 185 select HWMON_VID
176 help 186 help
177 If you say yes here you get support for Genesys Logic GL520SM 187 If you say yes here you get support for Genesys Logic GL520SM
@@ -186,15 +196,15 @@ config SENSORS_IT87
186 select I2C_ISA 196 select I2C_ISA
187 select HWMON_VID 197 select HWMON_VID
188 help 198 help
189 If you say yes here you get support for ITE IT87xx sensor chips 199 If you say yes here you get support for ITE IT8705F, IT8712F,
190 and clones: SiS960. 200 IT8716F and IT8718F sensor chips, and the SiS960 clone.
191 201
192 This driver can also be built as a module. If so, the module 202 This driver can also be built as a module. If so, the module
193 will be called it87. 203 will be called it87.
194 204
195config SENSORS_LM63 205config SENSORS_LM63
196 tristate "National Semiconductor LM63" 206 tristate "National Semiconductor LM63"
197 depends on HWMON && I2C && EXPERIMENTAL 207 depends on HWMON && I2C
198 help 208 help
199 If you say yes here you get support for the National Semiconductor 209 If you say yes here you get support for the National Semiconductor
200 LM63 remote diode digital temperature sensor with integrated fan 210 LM63 remote diode digital temperature sensor with integrated fan
@@ -231,7 +241,7 @@ config SENSORS_LM75
231 241
232config SENSORS_LM77 242config SENSORS_LM77
233 tristate "National Semiconductor LM77" 243 tristate "National Semiconductor LM77"
234 depends on HWMON && I2C && EXPERIMENTAL 244 depends on HWMON && I2C
235 help 245 help
236 If you say yes here you get support for National Semiconductor LM77 246 If you say yes here you get support for National Semiconductor LM77
237 sensor chips. 247 sensor chips.
@@ -241,7 +251,7 @@ config SENSORS_LM77
241 251
242config SENSORS_LM78 252config SENSORS_LM78
243 tristate "National Semiconductor LM78 and compatibles" 253 tristate "National Semiconductor LM78 and compatibles"
244 depends on HWMON && I2C && EXPERIMENTAL 254 depends on HWMON && I2C
245 select I2C_ISA 255 select I2C_ISA
246 select HWMON_VID 256 select HWMON_VID
247 help 257 help
@@ -284,7 +294,7 @@ config SENSORS_LM85
284 294
285config SENSORS_LM87 295config SENSORS_LM87
286 tristate "National Semiconductor LM87" 296 tristate "National Semiconductor LM87"
287 depends on HWMON && I2C && EXPERIMENTAL 297 depends on HWMON && I2C
288 select HWMON_VID 298 select HWMON_VID
289 help 299 help
290 If you say yes here you get support for National Semiconductor LM87 300 If you say yes here you get support for National Semiconductor LM87
@@ -309,7 +319,7 @@ config SENSORS_LM90
309 319
310config SENSORS_LM92 320config SENSORS_LM92
311 tristate "National Semiconductor LM92 and compatibles" 321 tristate "National Semiconductor LM92 and compatibles"
312 depends on HWMON && I2C && EXPERIMENTAL 322 depends on HWMON && I2C
313 help 323 help
314 If you say yes here you get support for National Semiconductor LM92 324 If you say yes here you get support for National Semiconductor LM92
315 and Maxim MAX6635 sensor chips. 325 and Maxim MAX6635 sensor chips.
@@ -319,7 +329,7 @@ config SENSORS_LM92
319 329
320config SENSORS_MAX1619 330config SENSORS_MAX1619
321 tristate "Maxim MAX1619 sensor chip" 331 tristate "Maxim MAX1619 sensor chip"
322 depends on HWMON && I2C && EXPERIMENTAL 332 depends on HWMON && I2C
323 help 333 help
324 If you say yes here you get support for MAX1619 sensor chip. 334 If you say yes here you get support for MAX1619 sensor chip.
325 335
@@ -354,7 +364,7 @@ config SENSORS_SIS5595
354 364
355config SENSORS_SMSC47M1 365config SENSORS_SMSC47M1
356 tristate "SMSC LPC47M10x and compatibles" 366 tristate "SMSC LPC47M10x and compatibles"
357 depends on HWMON && I2C && EXPERIMENTAL 367 depends on HWMON && I2C
358 select I2C_ISA 368 select I2C_ISA
359 help 369 help
360 If you say yes here you get support for the integrated fan 370 If you say yes here you get support for the integrated fan
@@ -407,8 +417,19 @@ config SENSORS_VIA686A
407 This driver can also be built as a module. If so, the module 417 This driver can also be built as a module. If so, the module
408 will be called via686a. 418 will be called via686a.
409 419
420config SENSORS_VT1211
421 tristate "VIA VT1211"
422 depends on HWMON && EXPERIMENTAL
423 select HWMON_VID
424 help
425 If you say yes here then you get support for hardware monitoring
426 features of the VIA VT1211 Super-I/O chip.
427
428 This driver can also be built as a module. If so, the module
429 will be called vt1211.
430
410config SENSORS_VT8231 431config SENSORS_VT8231
411 tristate "VT8231" 432 tristate "VIA VT8231"
412 depends on HWMON && I2C && PCI && EXPERIMENTAL 433 depends on HWMON && I2C && PCI && EXPERIMENTAL
413 select HWMON_VID 434 select HWMON_VID
414 select I2C_ISA 435 select I2C_ISA
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 31415843a91a..af01cc64f7d2 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o
27obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o 27obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o
28obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o 28obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o
29obj-$(CONFIG_SENSORS_IT87) += it87.o 29obj-$(CONFIG_SENSORS_IT87) += it87.o
30obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o
30obj-$(CONFIG_SENSORS_LM63) += lm63.o 31obj-$(CONFIG_SENSORS_LM63) += lm63.o
31obj-$(CONFIG_SENSORS_LM70) += lm70.o 32obj-$(CONFIG_SENSORS_LM70) += lm70.o
32obj-$(CONFIG_SENSORS_LM75) += lm75.o 33obj-$(CONFIG_SENSORS_LM75) += lm75.o
@@ -45,6 +46,7 @@ obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
45obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o 46obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o
46obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o 47obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o
47obj-$(CONFIG_SENSORS_VIA686A) += via686a.o 48obj-$(CONFIG_SENSORS_VIA686A) += via686a.o
49obj-$(CONFIG_SENSORS_VT1211) += vt1211.o
48obj-$(CONFIG_SENSORS_VT8231) += vt8231.o 50obj-$(CONFIG_SENSORS_VT8231) += vt8231.o
49obj-$(CONFIG_SENSORS_W83627EHF) += w83627ehf.o 51obj-$(CONFIG_SENSORS_W83627EHF) += w83627ehf.o
50obj-$(CONFIG_SENSORS_W83L785TS) += w83l785ts.o 52obj-$(CONFIG_SENSORS_W83L785TS) += w83l785ts.o
diff --git a/drivers/hwmon/abituguru.c b/drivers/hwmon/abituguru.c
index 35ad1b032726..e5cb0fdab9b1 100644
--- a/drivers/hwmon/abituguru.c
+++ b/drivers/hwmon/abituguru.c
@@ -1354,13 +1354,39 @@ LEAVE_UPDATE:
1354 return NULL; 1354 return NULL;
1355} 1355}
1356 1356
1357#ifdef CONFIG_PM
1358static int abituguru_suspend(struct platform_device *pdev, pm_message_t state)
1359{
1360 struct abituguru_data *data = platform_get_drvdata(pdev);
1361 /* make sure all communications with the uguru are done and no new
1362 ones are started */
1363 mutex_lock(&data->update_lock);
1364 return 0;
1365}
1366
1367static int abituguru_resume(struct platform_device *pdev)
1368{
1369 struct abituguru_data *data = platform_get_drvdata(pdev);
1370 /* See if the uGuru is still ready */
1371 if (inb_p(data->addr + ABIT_UGURU_DATA) != ABIT_UGURU_STATUS_INPUT)
1372 data->uguru_ready = 0;
1373 mutex_unlock(&data->update_lock);
1374 return 0;
1375}
1376#else
1377#define abituguru_suspend NULL
1378#define abituguru_resume NULL
1379#endif /* CONFIG_PM */
1380
1357static struct platform_driver abituguru_driver = { 1381static struct platform_driver abituguru_driver = {
1358 .driver = { 1382 .driver = {
1359 .owner = THIS_MODULE, 1383 .owner = THIS_MODULE,
1360 .name = ABIT_UGURU_NAME, 1384 .name = ABIT_UGURU_NAME,
1361 }, 1385 },
1362 .probe = abituguru_probe, 1386 .probe = abituguru_probe,
1363 .remove = __devexit_p(abituguru_remove), 1387 .remove = __devexit_p(abituguru_remove),
1388 .suspend = abituguru_suspend,
1389 .resume = abituguru_resume,
1364}; 1390};
1365 1391
1366static int __init abituguru_detect(void) 1392static int __init abituguru_detect(void)
diff --git a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c
index 2b6e74dd4a82..c466329b2ef4 100644
--- a/drivers/hwmon/adm1021.c
+++ b/drivers/hwmon/adm1021.c
@@ -190,6 +190,21 @@ static int adm1021_attach_adapter(struct i2c_adapter *adapter)
190 return i2c_probe(adapter, &addr_data, adm1021_detect); 190 return i2c_probe(adapter, &addr_data, adm1021_detect);
191} 191}
192 192
193static struct attribute *adm1021_attributes[] = {
194 &dev_attr_temp1_max.attr,
195 &dev_attr_temp1_min.attr,
196 &dev_attr_temp1_input.attr,
197 &dev_attr_temp2_max.attr,
198 &dev_attr_temp2_min.attr,
199 &dev_attr_temp2_input.attr,
200 &dev_attr_alarms.attr,
201 NULL
202};
203
204static const struct attribute_group adm1021_group = {
205 .attrs = adm1021_attributes,
206};
207
193static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) 208static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
194{ 209{
195 int i; 210 int i;
@@ -287,22 +302,19 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
287 adm1021_init_client(new_client); 302 adm1021_init_client(new_client);
288 303
289 /* Register sysfs hooks */ 304 /* Register sysfs hooks */
305 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1021_group)))
306 goto error2;
307
290 data->class_dev = hwmon_device_register(&new_client->dev); 308 data->class_dev = hwmon_device_register(&new_client->dev);
291 if (IS_ERR(data->class_dev)) { 309 if (IS_ERR(data->class_dev)) {
292 err = PTR_ERR(data->class_dev); 310 err = PTR_ERR(data->class_dev);
293 goto error2; 311 goto error3;
294 } 312 }
295 313
296 device_create_file(&new_client->dev, &dev_attr_temp1_max);
297 device_create_file(&new_client->dev, &dev_attr_temp1_min);
298 device_create_file(&new_client->dev, &dev_attr_temp1_input);
299 device_create_file(&new_client->dev, &dev_attr_temp2_max);
300 device_create_file(&new_client->dev, &dev_attr_temp2_min);
301 device_create_file(&new_client->dev, &dev_attr_temp2_input);
302 device_create_file(&new_client->dev, &dev_attr_alarms);
303
304 return 0; 314 return 0;
305 315
316error3:
317 sysfs_remove_group(&new_client->dev.kobj, &adm1021_group);
306error2: 318error2:
307 i2c_detach_client(new_client); 319 i2c_detach_client(new_client);
308error1: 320error1:
@@ -326,6 +338,7 @@ static int adm1021_detach_client(struct i2c_client *client)
326 int err; 338 int err;
327 339
328 hwmon_device_unregister(data->class_dev); 340 hwmon_device_unregister(data->class_dev);
341 sysfs_remove_group(&client->dev.kobj, &adm1021_group);
329 342
330 if ((err = i2c_detach_client(client))) 343 if ((err = i2c_detach_client(client)))
331 return err; 344 return err;
diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c
index a4c859c9fbf8..8c562885b54b 100644
--- a/drivers/hwmon/adm1025.c
+++ b/drivers/hwmon/adm1025.c
@@ -315,6 +315,49 @@ static int adm1025_attach_adapter(struct i2c_adapter *adapter)
315 return i2c_probe(adapter, &addr_data, adm1025_detect); 315 return i2c_probe(adapter, &addr_data, adm1025_detect);
316} 316}
317 317
318static struct attribute *adm1025_attributes[] = {
319 &dev_attr_in0_input.attr,
320 &dev_attr_in1_input.attr,
321 &dev_attr_in2_input.attr,
322 &dev_attr_in3_input.attr,
323 &dev_attr_in5_input.attr,
324 &dev_attr_in0_min.attr,
325 &dev_attr_in1_min.attr,
326 &dev_attr_in2_min.attr,
327 &dev_attr_in3_min.attr,
328 &dev_attr_in5_min.attr,
329 &dev_attr_in0_max.attr,
330 &dev_attr_in1_max.attr,
331 &dev_attr_in2_max.attr,
332 &dev_attr_in3_max.attr,
333 &dev_attr_in5_max.attr,
334 &dev_attr_temp1_input.attr,
335 &dev_attr_temp2_input.attr,
336 &dev_attr_temp1_min.attr,
337 &dev_attr_temp2_min.attr,
338 &dev_attr_temp1_max.attr,
339 &dev_attr_temp2_max.attr,
340 &dev_attr_alarms.attr,
341 &dev_attr_cpu0_vid.attr,
342 &dev_attr_vrm.attr,
343 NULL
344};
345
346static const struct attribute_group adm1025_group = {
347 .attrs = adm1025_attributes,
348};
349
350static struct attribute *adm1025_attributes_opt[] = {
351 &dev_attr_in4_input.attr,
352 &dev_attr_in4_min.attr,
353 &dev_attr_in4_max.attr,
354 NULL
355};
356
357static const struct attribute_group adm1025_group_opt = {
358 .attrs = adm1025_attributes_opt,
359};
360
318/* 361/*
319 * The following function does more than just detection. If detection 362 * The following function does more than just detection. If detection
320 * succeeds, it also registers the new chip. 363 * succeeds, it also registers the new chip.
@@ -415,46 +458,31 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
415 adm1025_init_client(new_client); 458 adm1025_init_client(new_client);
416 459
417 /* Register sysfs hooks */ 460 /* Register sysfs hooks */
418 data->class_dev = hwmon_device_register(&new_client->dev); 461 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1025_group)))
419 if (IS_ERR(data->class_dev)) {
420 err = PTR_ERR(data->class_dev);
421 goto exit_detach; 462 goto exit_detach;
422 }
423
424 device_create_file(&new_client->dev, &dev_attr_in0_input);
425 device_create_file(&new_client->dev, &dev_attr_in1_input);
426 device_create_file(&new_client->dev, &dev_attr_in2_input);
427 device_create_file(&new_client->dev, &dev_attr_in3_input);
428 device_create_file(&new_client->dev, &dev_attr_in5_input);
429 device_create_file(&new_client->dev, &dev_attr_in0_min);
430 device_create_file(&new_client->dev, &dev_attr_in1_min);
431 device_create_file(&new_client->dev, &dev_attr_in2_min);
432 device_create_file(&new_client->dev, &dev_attr_in3_min);
433 device_create_file(&new_client->dev, &dev_attr_in5_min);
434 device_create_file(&new_client->dev, &dev_attr_in0_max);
435 device_create_file(&new_client->dev, &dev_attr_in1_max);
436 device_create_file(&new_client->dev, &dev_attr_in2_max);
437 device_create_file(&new_client->dev, &dev_attr_in3_max);
438 device_create_file(&new_client->dev, &dev_attr_in5_max);
439 device_create_file(&new_client->dev, &dev_attr_temp1_input);
440 device_create_file(&new_client->dev, &dev_attr_temp2_input);
441 device_create_file(&new_client->dev, &dev_attr_temp1_min);
442 device_create_file(&new_client->dev, &dev_attr_temp2_min);
443 device_create_file(&new_client->dev, &dev_attr_temp1_max);
444 device_create_file(&new_client->dev, &dev_attr_temp2_max);
445 device_create_file(&new_client->dev, &dev_attr_alarms);
446 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
447 device_create_file(&new_client->dev, &dev_attr_vrm);
448 463
449 /* Pin 11 is either in4 (+12V) or VID4 */ 464 /* Pin 11 is either in4 (+12V) or VID4 */
450 if (!(config & 0x20)) { 465 if (!(config & 0x20)) {
451 device_create_file(&new_client->dev, &dev_attr_in4_input); 466 if ((err = device_create_file(&new_client->dev,
452 device_create_file(&new_client->dev, &dev_attr_in4_min); 467 &dev_attr_in4_input))
453 device_create_file(&new_client->dev, &dev_attr_in4_max); 468 || (err = device_create_file(&new_client->dev,
469 &dev_attr_in4_min))
470 || (err = device_create_file(&new_client->dev,
471 &dev_attr_in4_max)))
472 goto exit_remove;
473 }
474
475 data->class_dev = hwmon_device_register(&new_client->dev);
476 if (IS_ERR(data->class_dev)) {
477 err = PTR_ERR(data->class_dev);
478 goto exit_remove;
454 } 479 }
455 480
456 return 0; 481 return 0;
457 482
483exit_remove:
484 sysfs_remove_group(&new_client->dev.kobj, &adm1025_group);
485 sysfs_remove_group(&new_client->dev.kobj, &adm1025_group_opt);
458exit_detach: 486exit_detach:
459 i2c_detach_client(new_client); 487 i2c_detach_client(new_client);
460exit_free: 488exit_free:
@@ -511,6 +539,8 @@ static int adm1025_detach_client(struct i2c_client *client)
511 int err; 539 int err;
512 540
513 hwmon_device_unregister(data->class_dev); 541 hwmon_device_unregister(data->class_dev);
542 sysfs_remove_group(&client->dev.kobj, &adm1025_group);
543 sysfs_remove_group(&client->dev.kobj, &adm1025_group_opt);
514 544
515 if ((err = i2c_detach_client(client))) 545 if ((err = i2c_detach_client(client)))
516 return err; 546 return err;
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
index 6d4f8b8d358e..b4618b2705f7 100644
--- a/drivers/hwmon/adm1026.c
+++ b/drivers/hwmon/adm1026.c
@@ -323,15 +323,6 @@ static int adm1026_attach_adapter(struct i2c_adapter *adapter)
323 return i2c_probe(adapter, &addr_data, adm1026_detect); 323 return i2c_probe(adapter, &addr_data, adm1026_detect);
324} 324}
325 325
326static int adm1026_detach_client(struct i2c_client *client)
327{
328 struct adm1026_data *data = i2c_get_clientdata(client);
329 hwmon_device_unregister(data->class_dev);
330 i2c_detach_client(client);
331 kfree(data);
332 return 0;
333}
334
335static int adm1026_read_value(struct i2c_client *client, u8 reg) 326static int adm1026_read_value(struct i2c_client *client, u8 reg)
336{ 327{
337 int res; 328 int res;
@@ -1450,6 +1441,135 @@ static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1450static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL); 1441static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1451static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL); 1442static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1452 1443
1444static struct attribute *adm1026_attributes[] = {
1445 &sensor_dev_attr_in0_input.dev_attr.attr,
1446 &sensor_dev_attr_in0_max.dev_attr.attr,
1447 &sensor_dev_attr_in0_min.dev_attr.attr,
1448 &sensor_dev_attr_in1_input.dev_attr.attr,
1449 &sensor_dev_attr_in1_max.dev_attr.attr,
1450 &sensor_dev_attr_in1_min.dev_attr.attr,
1451 &sensor_dev_attr_in2_input.dev_attr.attr,
1452 &sensor_dev_attr_in2_max.dev_attr.attr,
1453 &sensor_dev_attr_in2_min.dev_attr.attr,
1454 &sensor_dev_attr_in3_input.dev_attr.attr,
1455 &sensor_dev_attr_in3_max.dev_attr.attr,
1456 &sensor_dev_attr_in3_min.dev_attr.attr,
1457 &sensor_dev_attr_in4_input.dev_attr.attr,
1458 &sensor_dev_attr_in4_max.dev_attr.attr,
1459 &sensor_dev_attr_in4_min.dev_attr.attr,
1460 &sensor_dev_attr_in5_input.dev_attr.attr,
1461 &sensor_dev_attr_in5_max.dev_attr.attr,
1462 &sensor_dev_attr_in5_min.dev_attr.attr,
1463 &sensor_dev_attr_in6_input.dev_attr.attr,
1464 &sensor_dev_attr_in6_max.dev_attr.attr,
1465 &sensor_dev_attr_in6_min.dev_attr.attr,
1466 &sensor_dev_attr_in7_input.dev_attr.attr,
1467 &sensor_dev_attr_in7_max.dev_attr.attr,
1468 &sensor_dev_attr_in7_min.dev_attr.attr,
1469 &sensor_dev_attr_in8_input.dev_attr.attr,
1470 &sensor_dev_attr_in8_max.dev_attr.attr,
1471 &sensor_dev_attr_in8_min.dev_attr.attr,
1472 &sensor_dev_attr_in9_input.dev_attr.attr,
1473 &sensor_dev_attr_in9_max.dev_attr.attr,
1474 &sensor_dev_attr_in9_min.dev_attr.attr,
1475 &sensor_dev_attr_in10_input.dev_attr.attr,
1476 &sensor_dev_attr_in10_max.dev_attr.attr,
1477 &sensor_dev_attr_in10_min.dev_attr.attr,
1478 &sensor_dev_attr_in11_input.dev_attr.attr,
1479 &sensor_dev_attr_in11_max.dev_attr.attr,
1480 &sensor_dev_attr_in11_min.dev_attr.attr,
1481 &sensor_dev_attr_in12_input.dev_attr.attr,
1482 &sensor_dev_attr_in12_max.dev_attr.attr,
1483 &sensor_dev_attr_in12_min.dev_attr.attr,
1484 &sensor_dev_attr_in13_input.dev_attr.attr,
1485 &sensor_dev_attr_in13_max.dev_attr.attr,
1486 &sensor_dev_attr_in13_min.dev_attr.attr,
1487 &sensor_dev_attr_in14_input.dev_attr.attr,
1488 &sensor_dev_attr_in14_max.dev_attr.attr,
1489 &sensor_dev_attr_in14_min.dev_attr.attr,
1490 &sensor_dev_attr_in15_input.dev_attr.attr,
1491 &sensor_dev_attr_in15_max.dev_attr.attr,
1492 &sensor_dev_attr_in15_min.dev_attr.attr,
1493 &sensor_dev_attr_in16_input.dev_attr.attr,
1494 &sensor_dev_attr_in16_max.dev_attr.attr,
1495 &sensor_dev_attr_in16_min.dev_attr.attr,
1496 &sensor_dev_attr_fan1_input.dev_attr.attr,
1497 &sensor_dev_attr_fan1_div.dev_attr.attr,
1498 &sensor_dev_attr_fan1_min.dev_attr.attr,
1499 &sensor_dev_attr_fan2_input.dev_attr.attr,
1500 &sensor_dev_attr_fan2_div.dev_attr.attr,
1501 &sensor_dev_attr_fan2_min.dev_attr.attr,
1502 &sensor_dev_attr_fan3_input.dev_attr.attr,
1503 &sensor_dev_attr_fan3_div.dev_attr.attr,
1504 &sensor_dev_attr_fan3_min.dev_attr.attr,
1505 &sensor_dev_attr_fan4_input.dev_attr.attr,
1506 &sensor_dev_attr_fan4_div.dev_attr.attr,
1507 &sensor_dev_attr_fan4_min.dev_attr.attr,
1508 &sensor_dev_attr_fan5_input.dev_attr.attr,
1509 &sensor_dev_attr_fan5_div.dev_attr.attr,
1510 &sensor_dev_attr_fan5_min.dev_attr.attr,
1511 &sensor_dev_attr_fan6_input.dev_attr.attr,
1512 &sensor_dev_attr_fan6_div.dev_attr.attr,
1513 &sensor_dev_attr_fan6_min.dev_attr.attr,
1514 &sensor_dev_attr_fan7_input.dev_attr.attr,
1515 &sensor_dev_attr_fan7_div.dev_attr.attr,
1516 &sensor_dev_attr_fan7_min.dev_attr.attr,
1517 &sensor_dev_attr_fan8_input.dev_attr.attr,
1518 &sensor_dev_attr_fan8_div.dev_attr.attr,
1519 &sensor_dev_attr_fan8_min.dev_attr.attr,
1520 &sensor_dev_attr_temp1_input.dev_attr.attr,
1521 &sensor_dev_attr_temp1_max.dev_attr.attr,
1522 &sensor_dev_attr_temp1_min.dev_attr.attr,
1523 &sensor_dev_attr_temp2_input.dev_attr.attr,
1524 &sensor_dev_attr_temp2_max.dev_attr.attr,
1525 &sensor_dev_attr_temp2_min.dev_attr.attr,
1526 &sensor_dev_attr_temp3_input.dev_attr.attr,
1527 &sensor_dev_attr_temp3_max.dev_attr.attr,
1528 &sensor_dev_attr_temp3_min.dev_attr.attr,
1529 &sensor_dev_attr_temp1_offset.dev_attr.attr,
1530 &sensor_dev_attr_temp2_offset.dev_attr.attr,
1531 &sensor_dev_attr_temp3_offset.dev_attr.attr,
1532 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
1533 &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr,
1534 &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr,
1535 &sensor_dev_attr_temp1_auto_point1_temp_hyst.dev_attr.attr,
1536 &sensor_dev_attr_temp2_auto_point1_temp_hyst.dev_attr.attr,
1537 &sensor_dev_attr_temp3_auto_point1_temp_hyst.dev_attr.attr,
1538 &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr,
1539 &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr,
1540 &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr,
1541 &sensor_dev_attr_temp1_crit.dev_attr.attr,
1542 &sensor_dev_attr_temp2_crit.dev_attr.attr,
1543 &sensor_dev_attr_temp3_crit.dev_attr.attr,
1544 &dev_attr_temp1_crit_enable.attr,
1545 &dev_attr_temp2_crit_enable.attr,
1546 &dev_attr_temp3_crit_enable.attr,
1547 &dev_attr_cpu0_vid.attr,
1548 &dev_attr_vrm.attr,
1549 &dev_attr_alarms.attr,
1550 &dev_attr_alarm_mask.attr,
1551 &dev_attr_gpio.attr,
1552 &dev_attr_gpio_mask.attr,
1553 &dev_attr_pwm1.attr,
1554 &dev_attr_pwm2.attr,
1555 &dev_attr_pwm3.attr,
1556 &dev_attr_pwm1_enable.attr,
1557 &dev_attr_pwm2_enable.attr,
1558 &dev_attr_pwm3_enable.attr,
1559 &dev_attr_temp1_auto_point1_pwm.attr,
1560 &dev_attr_temp2_auto_point1_pwm.attr,
1561 &dev_attr_temp3_auto_point1_pwm.attr,
1562 &dev_attr_temp1_auto_point2_pwm.attr,
1563 &dev_attr_temp2_auto_point2_pwm.attr,
1564 &dev_attr_temp3_auto_point2_pwm.attr,
1565 &dev_attr_analog_out.attr,
1566 NULL
1567};
1568
1569static const struct attribute_group adm1026_group = {
1570 .attrs = adm1026_attributes,
1571};
1572
1453static int adm1026_detect(struct i2c_adapter *adapter, int address, 1573static int adm1026_detect(struct i2c_adapter *adapter, int address,
1454 int kind) 1574 int kind)
1455{ 1575{
@@ -1554,145 +1674,20 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address,
1554 adm1026_init_client(new_client); 1674 adm1026_init_client(new_client);
1555 1675
1556 /* Register sysfs hooks */ 1676 /* Register sysfs hooks */
1677 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1026_group)))
1678 goto exitdetach;
1679
1557 data->class_dev = hwmon_device_register(&new_client->dev); 1680 data->class_dev = hwmon_device_register(&new_client->dev);
1558 if (IS_ERR(data->class_dev)) { 1681 if (IS_ERR(data->class_dev)) {
1559 err = PTR_ERR(data->class_dev); 1682 err = PTR_ERR(data->class_dev);
1560 goto exitdetach; 1683 goto exitremove;
1561 } 1684 }
1562 1685
1563 device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr);
1564 device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr);
1565 device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr);
1566 device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr);
1567 device_create_file(&new_client->dev, &sensor_dev_attr_in1_max.dev_attr);
1568 device_create_file(&new_client->dev, &sensor_dev_attr_in1_min.dev_attr);
1569 device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr);
1570 device_create_file(&new_client->dev, &sensor_dev_attr_in2_max.dev_attr);
1571 device_create_file(&new_client->dev, &sensor_dev_attr_in2_min.dev_attr);
1572 device_create_file(&new_client->dev, &sensor_dev_attr_in3_input.dev_attr);
1573 device_create_file(&new_client->dev, &sensor_dev_attr_in3_max.dev_attr);
1574 device_create_file(&new_client->dev, &sensor_dev_attr_in3_min.dev_attr);
1575 device_create_file(&new_client->dev, &sensor_dev_attr_in4_input.dev_attr);
1576 device_create_file(&new_client->dev, &sensor_dev_attr_in4_max.dev_attr);
1577 device_create_file(&new_client->dev, &sensor_dev_attr_in4_min.dev_attr);
1578 device_create_file(&new_client->dev, &sensor_dev_attr_in5_input.dev_attr);
1579 device_create_file(&new_client->dev, &sensor_dev_attr_in5_max.dev_attr);
1580 device_create_file(&new_client->dev, &sensor_dev_attr_in5_min.dev_attr);
1581 device_create_file(&new_client->dev, &sensor_dev_attr_in6_input.dev_attr);
1582 device_create_file(&new_client->dev, &sensor_dev_attr_in6_max.dev_attr);
1583 device_create_file(&new_client->dev, &sensor_dev_attr_in6_min.dev_attr);
1584 device_create_file(&new_client->dev, &sensor_dev_attr_in7_input.dev_attr);
1585 device_create_file(&new_client->dev, &sensor_dev_attr_in7_max.dev_attr);
1586 device_create_file(&new_client->dev, &sensor_dev_attr_in7_min.dev_attr);
1587 device_create_file(&new_client->dev, &sensor_dev_attr_in8_input.dev_attr);
1588 device_create_file(&new_client->dev, &sensor_dev_attr_in8_max.dev_attr);
1589 device_create_file(&new_client->dev, &sensor_dev_attr_in8_min.dev_attr);
1590 device_create_file(&new_client->dev, &sensor_dev_attr_in9_input.dev_attr);
1591 device_create_file(&new_client->dev, &sensor_dev_attr_in9_max.dev_attr);
1592 device_create_file(&new_client->dev, &sensor_dev_attr_in9_min.dev_attr);
1593 device_create_file(&new_client->dev, &sensor_dev_attr_in10_input.dev_attr);
1594 device_create_file(&new_client->dev, &sensor_dev_attr_in10_max.dev_attr);
1595 device_create_file(&new_client->dev, &sensor_dev_attr_in10_min.dev_attr);
1596 device_create_file(&new_client->dev, &sensor_dev_attr_in11_input.dev_attr);
1597 device_create_file(&new_client->dev, &sensor_dev_attr_in11_max.dev_attr);
1598 device_create_file(&new_client->dev, &sensor_dev_attr_in11_min.dev_attr);
1599 device_create_file(&new_client->dev, &sensor_dev_attr_in12_input.dev_attr);
1600 device_create_file(&new_client->dev, &sensor_dev_attr_in12_max.dev_attr);
1601 device_create_file(&new_client->dev, &sensor_dev_attr_in12_min.dev_attr);
1602 device_create_file(&new_client->dev, &sensor_dev_attr_in13_input.dev_attr);
1603 device_create_file(&new_client->dev, &sensor_dev_attr_in13_max.dev_attr);
1604 device_create_file(&new_client->dev, &sensor_dev_attr_in13_min.dev_attr);
1605 device_create_file(&new_client->dev, &sensor_dev_attr_in14_input.dev_attr);
1606 device_create_file(&new_client->dev, &sensor_dev_attr_in14_max.dev_attr);
1607 device_create_file(&new_client->dev, &sensor_dev_attr_in14_min.dev_attr);
1608 device_create_file(&new_client->dev, &sensor_dev_attr_in15_input.dev_attr);
1609 device_create_file(&new_client->dev, &sensor_dev_attr_in15_max.dev_attr);
1610 device_create_file(&new_client->dev, &sensor_dev_attr_in15_min.dev_attr);
1611 device_create_file(&new_client->dev, &sensor_dev_attr_in16_input.dev_attr);
1612 device_create_file(&new_client->dev, &sensor_dev_attr_in16_max.dev_attr);
1613 device_create_file(&new_client->dev, &sensor_dev_attr_in16_min.dev_attr);
1614 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_input.dev_attr);
1615 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_div.dev_attr);
1616 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_min.dev_attr);
1617 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_input.dev_attr);
1618 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_div.dev_attr);
1619 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_min.dev_attr);
1620 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_input.dev_attr);
1621 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_div.dev_attr);
1622 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_min.dev_attr);
1623 device_create_file(&new_client->dev, &sensor_dev_attr_fan4_input.dev_attr);
1624 device_create_file(&new_client->dev, &sensor_dev_attr_fan4_div.dev_attr);
1625 device_create_file(&new_client->dev, &sensor_dev_attr_fan4_min.dev_attr);
1626 device_create_file(&new_client->dev, &sensor_dev_attr_fan5_input.dev_attr);
1627 device_create_file(&new_client->dev, &sensor_dev_attr_fan5_div.dev_attr);
1628 device_create_file(&new_client->dev, &sensor_dev_attr_fan5_min.dev_attr);
1629 device_create_file(&new_client->dev, &sensor_dev_attr_fan6_input.dev_attr);
1630 device_create_file(&new_client->dev, &sensor_dev_attr_fan6_div.dev_attr);
1631 device_create_file(&new_client->dev, &sensor_dev_attr_fan6_min.dev_attr);
1632 device_create_file(&new_client->dev, &sensor_dev_attr_fan7_input.dev_attr);
1633 device_create_file(&new_client->dev, &sensor_dev_attr_fan7_div.dev_attr);
1634 device_create_file(&new_client->dev, &sensor_dev_attr_fan7_min.dev_attr);
1635 device_create_file(&new_client->dev, &sensor_dev_attr_fan8_input.dev_attr);
1636 device_create_file(&new_client->dev, &sensor_dev_attr_fan8_div.dev_attr);
1637 device_create_file(&new_client->dev, &sensor_dev_attr_fan8_min.dev_attr);
1638 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr);
1639 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_max.dev_attr);
1640 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_min.dev_attr);
1641 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_input.dev_attr);
1642 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_max.dev_attr);
1643 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_min.dev_attr);
1644 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_input.dev_attr);
1645 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_max.dev_attr);
1646 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_min.dev_attr);
1647 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_offset.dev_attr);
1648 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_offset.dev_attr);
1649 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_offset.dev_attr);
1650 device_create_file(&new_client->dev,
1651 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr);
1652 device_create_file(&new_client->dev,
1653 &sensor_dev_attr_temp2_auto_point1_temp.dev_attr);
1654 device_create_file(&new_client->dev,
1655 &sensor_dev_attr_temp3_auto_point1_temp.dev_attr);
1656 device_create_file(&new_client->dev,
1657 &sensor_dev_attr_temp1_auto_point1_temp_hyst.dev_attr);
1658 device_create_file(&new_client->dev,
1659 &sensor_dev_attr_temp2_auto_point1_temp_hyst.dev_attr);
1660 device_create_file(&new_client->dev,
1661 &sensor_dev_attr_temp3_auto_point1_temp_hyst.dev_attr);
1662 device_create_file(&new_client->dev,
1663 &sensor_dev_attr_temp1_auto_point2_temp.dev_attr);
1664 device_create_file(&new_client->dev,
1665 &sensor_dev_attr_temp2_auto_point2_temp.dev_attr);
1666 device_create_file(&new_client->dev,
1667 &sensor_dev_attr_temp3_auto_point2_temp.dev_attr);
1668 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_crit.dev_attr);
1669 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_crit.dev_attr);
1670 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_crit.dev_attr);
1671 device_create_file(&new_client->dev, &dev_attr_temp1_crit_enable);
1672 device_create_file(&new_client->dev, &dev_attr_temp2_crit_enable);
1673 device_create_file(&new_client->dev, &dev_attr_temp3_crit_enable);
1674 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
1675 device_create_file(&new_client->dev, &dev_attr_vrm);
1676 device_create_file(&new_client->dev, &dev_attr_alarms);
1677 device_create_file(&new_client->dev, &dev_attr_alarm_mask);
1678 device_create_file(&new_client->dev, &dev_attr_gpio);
1679 device_create_file(&new_client->dev, &dev_attr_gpio_mask);
1680 device_create_file(&new_client->dev, &dev_attr_pwm1);
1681 device_create_file(&new_client->dev, &dev_attr_pwm2);
1682 device_create_file(&new_client->dev, &dev_attr_pwm3);
1683 device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
1684 device_create_file(&new_client->dev, &dev_attr_pwm2_enable);
1685 device_create_file(&new_client->dev, &dev_attr_pwm3_enable);
1686 device_create_file(&new_client->dev, &dev_attr_temp1_auto_point1_pwm);
1687 device_create_file(&new_client->dev, &dev_attr_temp2_auto_point1_pwm);
1688 device_create_file(&new_client->dev, &dev_attr_temp3_auto_point1_pwm);
1689 device_create_file(&new_client->dev, &dev_attr_temp1_auto_point2_pwm);
1690 device_create_file(&new_client->dev, &dev_attr_temp2_auto_point2_pwm);
1691 device_create_file(&new_client->dev, &dev_attr_temp3_auto_point2_pwm);
1692 device_create_file(&new_client->dev, &dev_attr_analog_out);
1693 return 0; 1686 return 0;
1694 1687
1695 /* Error out and cleanup code */ 1688 /* Error out and cleanup code */
1689exitremove:
1690 sysfs_remove_group(&new_client->dev.kobj, &adm1026_group);
1696exitdetach: 1691exitdetach:
1697 i2c_detach_client(new_client); 1692 i2c_detach_client(new_client);
1698exitfree: 1693exitfree:
@@ -1700,6 +1695,17 @@ exitfree:
1700exit: 1695exit:
1701 return err; 1696 return err;
1702} 1697}
1698
1699static int adm1026_detach_client(struct i2c_client *client)
1700{
1701 struct adm1026_data *data = i2c_get_clientdata(client);
1702 hwmon_device_unregister(data->class_dev);
1703 sysfs_remove_group(&client->dev.kobj, &adm1026_group);
1704 i2c_detach_client(client);
1705 kfree(data);
1706 return 0;
1707}
1708
1703static int __init sm_adm1026_init(void) 1709static int __init sm_adm1026_init(void)
1704{ 1710{
1705 return i2c_add_driver(&adm1026_driver); 1711 return i2c_add_driver(&adm1026_driver);
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
index 3bf2da621aed..122683fc91d0 100644
--- a/drivers/hwmon/adm1031.c
+++ b/drivers/hwmon/adm1031.c
@@ -730,6 +730,61 @@ static int adm1031_attach_adapter(struct i2c_adapter *adapter)
730 return i2c_probe(adapter, &addr_data, adm1031_detect); 730 return i2c_probe(adapter, &addr_data, adm1031_detect);
731} 731}
732 732
733static struct attribute *adm1031_attributes[] = {
734 &dev_attr_fan1_input.attr,
735 &dev_attr_fan1_div.attr,
736 &dev_attr_fan1_min.attr,
737 &dev_attr_pwm1.attr,
738 &dev_attr_auto_fan1_channel.attr,
739 &dev_attr_temp1_input.attr,
740 &dev_attr_temp1_min.attr,
741 &dev_attr_temp1_max.attr,
742 &dev_attr_temp1_crit.attr,
743 &dev_attr_temp2_input.attr,
744 &dev_attr_temp2_min.attr,
745 &dev_attr_temp2_max.attr,
746 &dev_attr_temp2_crit.attr,
747
748 &dev_attr_auto_temp1_off.attr,
749 &dev_attr_auto_temp1_min.attr,
750 &dev_attr_auto_temp1_max.attr,
751
752 &dev_attr_auto_temp2_off.attr,
753 &dev_attr_auto_temp2_min.attr,
754 &dev_attr_auto_temp2_max.attr,
755
756 &dev_attr_auto_fan1_min_pwm.attr,
757
758 &dev_attr_alarms.attr,
759
760 NULL
761};
762
763static const struct attribute_group adm1031_group = {
764 .attrs = adm1031_attributes,
765};
766
767static struct attribute *adm1031_attributes_opt[] = {
768 &dev_attr_fan2_input.attr,
769 &dev_attr_fan2_div.attr,
770 &dev_attr_fan2_min.attr,
771 &dev_attr_pwm2.attr,
772 &dev_attr_auto_fan2_channel.attr,
773 &dev_attr_temp3_input.attr,
774 &dev_attr_temp3_min.attr,
775 &dev_attr_temp3_max.attr,
776 &dev_attr_temp3_crit.attr,
777 &dev_attr_auto_temp3_off.attr,
778 &dev_attr_auto_temp3_min.attr,
779 &dev_attr_auto_temp3_max.attr,
780 &dev_attr_auto_fan2_min_pwm.attr,
781 NULL
782};
783
784static const struct attribute_group adm1031_group_opt = {
785 .attrs = adm1031_attributes_opt,
786};
787
733/* This function is called by i2c_probe */ 788/* This function is called by i2c_probe */
734static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) 789static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
735{ 790{
@@ -789,57 +844,26 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
789 adm1031_init_client(new_client); 844 adm1031_init_client(new_client);
790 845
791 /* Register sysfs hooks */ 846 /* Register sysfs hooks */
792 data->class_dev = hwmon_device_register(&new_client->dev); 847 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1031_group)))
793 if (IS_ERR(data->class_dev)) {
794 err = PTR_ERR(data->class_dev);
795 goto exit_detach; 848 goto exit_detach;
796 }
797
798 device_create_file(&new_client->dev, &dev_attr_fan1_input);
799 device_create_file(&new_client->dev, &dev_attr_fan1_div);
800 device_create_file(&new_client->dev, &dev_attr_fan1_min);
801 device_create_file(&new_client->dev, &dev_attr_pwm1);
802 device_create_file(&new_client->dev, &dev_attr_auto_fan1_channel);
803 device_create_file(&new_client->dev, &dev_attr_temp1_input);
804 device_create_file(&new_client->dev, &dev_attr_temp1_min);
805 device_create_file(&new_client->dev, &dev_attr_temp1_max);
806 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
807 device_create_file(&new_client->dev, &dev_attr_temp2_input);
808 device_create_file(&new_client->dev, &dev_attr_temp2_min);
809 device_create_file(&new_client->dev, &dev_attr_temp2_max);
810 device_create_file(&new_client->dev, &dev_attr_temp2_crit);
811
812 device_create_file(&new_client->dev, &dev_attr_auto_temp1_off);
813 device_create_file(&new_client->dev, &dev_attr_auto_temp1_min);
814 device_create_file(&new_client->dev, &dev_attr_auto_temp1_max);
815
816 device_create_file(&new_client->dev, &dev_attr_auto_temp2_off);
817 device_create_file(&new_client->dev, &dev_attr_auto_temp2_min);
818 device_create_file(&new_client->dev, &dev_attr_auto_temp2_max);
819
820 device_create_file(&new_client->dev, &dev_attr_auto_fan1_min_pwm);
821
822 device_create_file(&new_client->dev, &dev_attr_alarms);
823 849
824 if (kind == adm1031) { 850 if (kind == adm1031) {
825 device_create_file(&new_client->dev, &dev_attr_fan2_input); 851 if ((err = sysfs_create_group(&new_client->dev.kobj,
826 device_create_file(&new_client->dev, &dev_attr_fan2_div); 852 &adm1031_group_opt)))
827 device_create_file(&new_client->dev, &dev_attr_fan2_min); 853 goto exit_remove;
828 device_create_file(&new_client->dev, &dev_attr_pwm2); 854 }
829 device_create_file(&new_client->dev, 855
830 &dev_attr_auto_fan2_channel); 856 data->class_dev = hwmon_device_register(&new_client->dev);
831 device_create_file(&new_client->dev, &dev_attr_temp3_input); 857 if (IS_ERR(data->class_dev)) {
832 device_create_file(&new_client->dev, &dev_attr_temp3_min); 858 err = PTR_ERR(data->class_dev);
833 device_create_file(&new_client->dev, &dev_attr_temp3_max); 859 goto exit_remove;
834 device_create_file(&new_client->dev, &dev_attr_temp3_crit);
835 device_create_file(&new_client->dev, &dev_attr_auto_temp3_off);
836 device_create_file(&new_client->dev, &dev_attr_auto_temp3_min);
837 device_create_file(&new_client->dev, &dev_attr_auto_temp3_max);
838 device_create_file(&new_client->dev, &dev_attr_auto_fan2_min_pwm);
839 } 860 }
840 861
841 return 0; 862 return 0;
842 863
864exit_remove:
865 sysfs_remove_group(&new_client->dev.kobj, &adm1031_group);
866 sysfs_remove_group(&new_client->dev.kobj, &adm1031_group_opt);
843exit_detach: 867exit_detach:
844 i2c_detach_client(new_client); 868 i2c_detach_client(new_client);
845exit_free: 869exit_free:
@@ -854,6 +878,8 @@ static int adm1031_detach_client(struct i2c_client *client)
854 int ret; 878 int ret;
855 879
856 hwmon_device_unregister(data->class_dev); 880 hwmon_device_unregister(data->class_dev);
881 sysfs_remove_group(&client->dev.kobj, &adm1031_group);
882 sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt);
857 if ((ret = i2c_detach_client(client)) != 0) { 883 if ((ret = i2c_detach_client(client)) != 0) {
858 return ret; 884 return ret;
859 } 885 }
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
index 43f6991b588c..377961c4a41e 100644
--- a/drivers/hwmon/adm9240.c
+++ b/drivers/hwmon/adm9240.c
@@ -465,6 +465,45 @@ static ssize_t chassis_clear(struct device *dev,
465} 465}
466static DEVICE_ATTR(chassis_clear, S_IWUSR, NULL, chassis_clear); 466static DEVICE_ATTR(chassis_clear, S_IWUSR, NULL, chassis_clear);
467 467
468static struct attribute *adm9240_attributes[] = {
469 &sensor_dev_attr_in0_input.dev_attr.attr,
470 &sensor_dev_attr_in0_min.dev_attr.attr,
471 &sensor_dev_attr_in0_max.dev_attr.attr,
472 &sensor_dev_attr_in1_input.dev_attr.attr,
473 &sensor_dev_attr_in1_min.dev_attr.attr,
474 &sensor_dev_attr_in1_max.dev_attr.attr,
475 &sensor_dev_attr_in2_input.dev_attr.attr,
476 &sensor_dev_attr_in2_min.dev_attr.attr,
477 &sensor_dev_attr_in2_max.dev_attr.attr,
478 &sensor_dev_attr_in3_input.dev_attr.attr,
479 &sensor_dev_attr_in3_min.dev_attr.attr,
480 &sensor_dev_attr_in3_max.dev_attr.attr,
481 &sensor_dev_attr_in4_input.dev_attr.attr,
482 &sensor_dev_attr_in4_min.dev_attr.attr,
483 &sensor_dev_attr_in4_max.dev_attr.attr,
484 &sensor_dev_attr_in5_input.dev_attr.attr,
485 &sensor_dev_attr_in5_min.dev_attr.attr,
486 &sensor_dev_attr_in5_max.dev_attr.attr,
487 &dev_attr_temp1_input.attr,
488 &sensor_dev_attr_temp1_max.dev_attr.attr,
489 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
490 &sensor_dev_attr_fan1_input.dev_attr.attr,
491 &sensor_dev_attr_fan1_div.dev_attr.attr,
492 &sensor_dev_attr_fan1_min.dev_attr.attr,
493 &sensor_dev_attr_fan2_input.dev_attr.attr,
494 &sensor_dev_attr_fan2_div.dev_attr.attr,
495 &sensor_dev_attr_fan2_min.dev_attr.attr,
496 &dev_attr_alarms.attr,
497 &dev_attr_aout_output.attr,
498 &dev_attr_chassis_clear.attr,
499 &dev_attr_cpu0_vid.attr,
500 NULL
501};
502
503static const struct attribute_group adm9240_group = {
504 .attrs = adm9240_attributes,
505};
506
468 507
469/*** sensor chip detect and driver install ***/ 508/*** sensor chip detect and driver install ***/
470 509
@@ -548,72 +587,19 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
548 adm9240_init_client(new_client); 587 adm9240_init_client(new_client);
549 588
550 /* populate sysfs filesystem */ 589 /* populate sysfs filesystem */
590 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm9240_group)))
591 goto exit_detach;
592
551 data->class_dev = hwmon_device_register(&new_client->dev); 593 data->class_dev = hwmon_device_register(&new_client->dev);
552 if (IS_ERR(data->class_dev)) { 594 if (IS_ERR(data->class_dev)) {
553 err = PTR_ERR(data->class_dev); 595 err = PTR_ERR(data->class_dev);
554 goto exit_detach; 596 goto exit_remove;
555 } 597 }
556 598
557 device_create_file(&new_client->dev,
558 &sensor_dev_attr_in0_input.dev_attr);
559 device_create_file(&new_client->dev,
560 &sensor_dev_attr_in0_min.dev_attr);
561 device_create_file(&new_client->dev,
562 &sensor_dev_attr_in0_max.dev_attr);
563 device_create_file(&new_client->dev,
564 &sensor_dev_attr_in1_input.dev_attr);
565 device_create_file(&new_client->dev,
566 &sensor_dev_attr_in1_min.dev_attr);
567 device_create_file(&new_client->dev,
568 &sensor_dev_attr_in1_max.dev_attr);
569 device_create_file(&new_client->dev,
570 &sensor_dev_attr_in2_input.dev_attr);
571 device_create_file(&new_client->dev,
572 &sensor_dev_attr_in2_min.dev_attr);
573 device_create_file(&new_client->dev,
574 &sensor_dev_attr_in2_max.dev_attr);
575 device_create_file(&new_client->dev,
576 &sensor_dev_attr_in3_input.dev_attr);
577 device_create_file(&new_client->dev,
578 &sensor_dev_attr_in3_min.dev_attr);
579 device_create_file(&new_client->dev,
580 &sensor_dev_attr_in3_max.dev_attr);
581 device_create_file(&new_client->dev,
582 &sensor_dev_attr_in4_input.dev_attr);
583 device_create_file(&new_client->dev,
584 &sensor_dev_attr_in4_min.dev_attr);
585 device_create_file(&new_client->dev,
586 &sensor_dev_attr_in4_max.dev_attr);
587 device_create_file(&new_client->dev,
588 &sensor_dev_attr_in5_input.dev_attr);
589 device_create_file(&new_client->dev,
590 &sensor_dev_attr_in5_min.dev_attr);
591 device_create_file(&new_client->dev,
592 &sensor_dev_attr_in5_max.dev_attr);
593 device_create_file(&new_client->dev, &dev_attr_temp1_input);
594 device_create_file(&new_client->dev,
595 &sensor_dev_attr_temp1_max.dev_attr);
596 device_create_file(&new_client->dev,
597 &sensor_dev_attr_temp1_max_hyst.dev_attr);
598 device_create_file(&new_client->dev,
599 &sensor_dev_attr_fan1_input.dev_attr);
600 device_create_file(&new_client->dev,
601 &sensor_dev_attr_fan1_div.dev_attr);
602 device_create_file(&new_client->dev,
603 &sensor_dev_attr_fan1_min.dev_attr);
604 device_create_file(&new_client->dev,
605 &sensor_dev_attr_fan2_input.dev_attr);
606 device_create_file(&new_client->dev,
607 &sensor_dev_attr_fan2_div.dev_attr);
608 device_create_file(&new_client->dev,
609 &sensor_dev_attr_fan2_min.dev_attr);
610 device_create_file(&new_client->dev, &dev_attr_alarms);
611 device_create_file(&new_client->dev, &dev_attr_aout_output);
612 device_create_file(&new_client->dev, &dev_attr_chassis_clear);
613 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
614
615 return 0; 599 return 0;
616 600
601exit_remove:
602 sysfs_remove_group(&new_client->dev.kobj, &adm9240_group);
617exit_detach: 603exit_detach:
618 i2c_detach_client(new_client); 604 i2c_detach_client(new_client);
619exit_free: 605exit_free:
@@ -635,6 +621,7 @@ static int adm9240_detach_client(struct i2c_client *client)
635 int err; 621 int err;
636 622
637 hwmon_device_unregister(data->class_dev); 623 hwmon_device_unregister(data->class_dev);
624 sysfs_remove_group(&client->dev.kobj, &adm9240_group);
638 625
639 if ((err = i2c_detach_client(client))) 626 if ((err = i2c_detach_client(client)))
640 return err; 627 return err;
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c
index facc1ccb8338..57b1c7b7ac3f 100644
--- a/drivers/hwmon/asb100.c
+++ b/drivers/hwmon/asb100.c
@@ -298,12 +298,6 @@ sysfs_in(4);
298sysfs_in(5); 298sysfs_in(5);
299sysfs_in(6); 299sysfs_in(6);
300 300
301#define device_create_file_in(client, offset) do { \
302 device_create_file(&client->dev, &dev_attr_in##offset##_input); \
303 device_create_file(&client->dev, &dev_attr_in##offset##_min); \
304 device_create_file(&client->dev, &dev_attr_in##offset##_max); \
305} while (0)
306
307/* 3 Fans */ 301/* 3 Fans */
308static ssize_t show_fan(struct device *dev, char *buf, int nr) 302static ssize_t show_fan(struct device *dev, char *buf, int nr)
309{ 303{
@@ -421,12 +415,6 @@ sysfs_fan(1);
421sysfs_fan(2); 415sysfs_fan(2);
422sysfs_fan(3); 416sysfs_fan(3);
423 417
424#define device_create_file_fan(client, offset) do { \
425 device_create_file(&client->dev, &dev_attr_fan##offset##_input); \
426 device_create_file(&client->dev, &dev_attr_fan##offset##_min); \
427 device_create_file(&client->dev, &dev_attr_fan##offset##_div); \
428} while (0)
429
430/* 4 Temp. Sensors */ 418/* 4 Temp. Sensors */
431static int sprintf_temp_from_reg(u16 reg, char *buf, int nr) 419static int sprintf_temp_from_reg(u16 reg, char *buf, int nr)
432{ 420{
@@ -515,12 +503,6 @@ sysfs_temp(3);
515sysfs_temp(4); 503sysfs_temp(4);
516 504
517/* VID */ 505/* VID */
518#define device_create_file_temp(client, num) do { \
519 device_create_file(&client->dev, &dev_attr_temp##num##_input); \
520 device_create_file(&client->dev, &dev_attr_temp##num##_max); \
521 device_create_file(&client->dev, &dev_attr_temp##num##_max_hyst); \
522} while (0)
523
524static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 506static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf)
525{ 507{
526 struct asb100_data *data = asb100_update_device(dev); 508 struct asb100_data *data = asb100_update_device(dev);
@@ -528,8 +510,6 @@ static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char
528} 510}
529 511
530static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 512static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
531#define device_create_file_vid(client) \
532device_create_file(&client->dev, &dev_attr_cpu0_vid)
533 513
534/* VRM */ 514/* VRM */
535static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) 515static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
@@ -549,8 +529,6 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const
549 529
550/* Alarms */ 530/* Alarms */
551static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); 531static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
552#define device_create_file_vrm(client) \
553device_create_file(&client->dev, &dev_attr_vrm);
554 532
555static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 533static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
556{ 534{
@@ -559,8 +537,6 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
559} 537}
560 538
561static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 539static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
562#define device_create_file_alarms(client) \
563device_create_file(&client->dev, &dev_attr_alarms)
564 540
565/* 1 PWM */ 541/* 1 PWM */
566static ssize_t show_pwm1(struct device *dev, struct device_attribute *attr, char *buf) 542static ssize_t show_pwm1(struct device *dev, struct device_attribute *attr, char *buf)
@@ -607,10 +583,65 @@ static ssize_t set_pwm_enable1(struct device *dev, struct device_attribute *attr
607static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm1, set_pwm1); 583static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm1, set_pwm1);
608static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, 584static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
609 show_pwm_enable1, set_pwm_enable1); 585 show_pwm_enable1, set_pwm_enable1);
610#define device_create_file_pwm1(client) do { \ 586
611 device_create_file(&new_client->dev, &dev_attr_pwm1); \ 587static struct attribute *asb100_attributes[] = {
612 device_create_file(&new_client->dev, &dev_attr_pwm1_enable); \ 588 &dev_attr_in0_input.attr,
613} while (0) 589 &dev_attr_in0_min.attr,
590 &dev_attr_in0_max.attr,
591 &dev_attr_in1_input.attr,
592 &dev_attr_in1_min.attr,
593 &dev_attr_in1_max.attr,
594 &dev_attr_in2_input.attr,
595 &dev_attr_in2_min.attr,
596 &dev_attr_in2_max.attr,
597 &dev_attr_in3_input.attr,
598 &dev_attr_in3_min.attr,
599 &dev_attr_in3_max.attr,
600 &dev_attr_in4_input.attr,
601 &dev_attr_in4_min.attr,
602 &dev_attr_in4_max.attr,
603 &dev_attr_in5_input.attr,
604 &dev_attr_in5_min.attr,
605 &dev_attr_in5_max.attr,
606 &dev_attr_in6_input.attr,
607 &dev_attr_in6_min.attr,
608 &dev_attr_in6_max.attr,
609
610 &dev_attr_fan1_input.attr,
611 &dev_attr_fan1_min.attr,
612 &dev_attr_fan1_div.attr,
613 &dev_attr_fan2_input.attr,
614 &dev_attr_fan2_min.attr,
615 &dev_attr_fan2_div.attr,
616 &dev_attr_fan3_input.attr,
617 &dev_attr_fan3_min.attr,
618 &dev_attr_fan3_div.attr,
619
620 &dev_attr_temp1_input.attr,
621 &dev_attr_temp1_max.attr,
622 &dev_attr_temp1_max_hyst.attr,
623 &dev_attr_temp2_input.attr,
624 &dev_attr_temp2_max.attr,
625 &dev_attr_temp2_max_hyst.attr,
626 &dev_attr_temp3_input.attr,
627 &dev_attr_temp3_max.attr,
628 &dev_attr_temp3_max_hyst.attr,
629 &dev_attr_temp4_input.attr,
630 &dev_attr_temp4_max.attr,
631 &dev_attr_temp4_max_hyst.attr,
632
633 &dev_attr_cpu0_vid.attr,
634 &dev_attr_vrm.attr,
635 &dev_attr_alarms.attr,
636 &dev_attr_pwm1.attr,
637 &dev_attr_pwm1_enable.attr,
638
639 NULL
640};
641
642static const struct attribute_group asb100_group = {
643 .attrs = asb100_attributes,
644};
614 645
615/* This function is called when: 646/* This function is called when:
616 asb100_driver is inserted (when this module is loaded), for each 647 asb100_driver is inserted (when this module is loaded), for each
@@ -810,38 +841,19 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
810 data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2)); 841 data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2));
811 842
812 /* Register sysfs hooks */ 843 /* Register sysfs hooks */
844 if ((err = sysfs_create_group(&new_client->dev.kobj, &asb100_group)))
845 goto ERROR3;
846
813 data->class_dev = hwmon_device_register(&new_client->dev); 847 data->class_dev = hwmon_device_register(&new_client->dev);
814 if (IS_ERR(data->class_dev)) { 848 if (IS_ERR(data->class_dev)) {
815 err = PTR_ERR(data->class_dev); 849 err = PTR_ERR(data->class_dev);
816 goto ERROR3; 850 goto ERROR4;
817 } 851 }
818 852
819 device_create_file_in(new_client, 0);
820 device_create_file_in(new_client, 1);
821 device_create_file_in(new_client, 2);
822 device_create_file_in(new_client, 3);
823 device_create_file_in(new_client, 4);
824 device_create_file_in(new_client, 5);
825 device_create_file_in(new_client, 6);
826
827 device_create_file_fan(new_client, 1);
828 device_create_file_fan(new_client, 2);
829 device_create_file_fan(new_client, 3);
830
831 device_create_file_temp(new_client, 1);
832 device_create_file_temp(new_client, 2);
833 device_create_file_temp(new_client, 3);
834 device_create_file_temp(new_client, 4);
835
836 device_create_file_vid(new_client);
837 device_create_file_vrm(new_client);
838
839 device_create_file_alarms(new_client);
840
841 device_create_file_pwm1(new_client);
842
843 return 0; 853 return 0;
844 854
855ERROR4:
856 sysfs_remove_group(&new_client->dev.kobj, &asb100_group);
845ERROR3: 857ERROR3:
846 i2c_detach_client(data->lm75[1]); 858 i2c_detach_client(data->lm75[1]);
847 i2c_detach_client(data->lm75[0]); 859 i2c_detach_client(data->lm75[0]);
@@ -861,8 +873,10 @@ static int asb100_detach_client(struct i2c_client *client)
861 int err; 873 int err;
862 874
863 /* main client */ 875 /* main client */
864 if (data) 876 if (data) {
865 hwmon_device_unregister(data->class_dev); 877 hwmon_device_unregister(data->class_dev);
878 sysfs_remove_group(&client->dev.kobj, &asb100_group);
879 }
866 880
867 if ((err = i2c_detach_client(client))) 881 if ((err = i2c_detach_client(client)))
868 return err; 882 return err;
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c
index 728a1e8b9190..0ccdd0750c44 100644
--- a/drivers/hwmon/atxp1.c
+++ b/drivers/hwmon/atxp1.c
@@ -27,6 +27,7 @@
27#include <linux/hwmon-vid.h> 27#include <linux/hwmon-vid.h>
28#include <linux/err.h> 28#include <linux/err.h>
29#include <linux/mutex.h> 29#include <linux/mutex.h>
30#include <linux/sysfs.h>
30 31
31MODULE_LICENSE("GPL"); 32MODULE_LICENSE("GPL");
32MODULE_DESCRIPTION("System voltages control via Attansic ATXP1"); 33MODULE_DESCRIPTION("System voltages control via Attansic ATXP1");
@@ -116,8 +117,7 @@ static ssize_t atxp1_storevcore(struct device *dev, struct device_attribute *att
116{ 117{
117 struct atxp1_data *data; 118 struct atxp1_data *data;
118 struct i2c_client *client; 119 struct i2c_client *client;
119 char vid; 120 int vid, cvid;
120 char cvid;
121 unsigned int vcore; 121 unsigned int vcore;
122 122
123 client = to_i2c_client(dev); 123 client = to_i2c_client(dev);
@@ -251,6 +251,17 @@ static ssize_t atxp1_storegpio2(struct device *dev, struct device_attribute *att
251*/ 251*/
252static DEVICE_ATTR(gpio2, S_IRUGO | S_IWUSR, atxp1_showgpio2, atxp1_storegpio2); 252static DEVICE_ATTR(gpio2, S_IRUGO | S_IWUSR, atxp1_showgpio2, atxp1_storegpio2);
253 253
254static struct attribute *atxp1_attributes[] = {
255 &dev_attr_gpio1.attr,
256 &dev_attr_gpio2.attr,
257 &dev_attr_cpu0_vid.attr,
258 NULL
259};
260
261static const struct attribute_group atxp1_group = {
262 .attrs = atxp1_attributes,
263};
264
254 265
255static int atxp1_attach_adapter(struct i2c_adapter *adapter) 266static int atxp1_attach_adapter(struct i2c_adapter *adapter)
256{ 267{
@@ -320,21 +331,23 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind)
320 goto exit_free; 331 goto exit_free;
321 } 332 }
322 333
334 /* Register sysfs hooks */
335 if ((err = sysfs_create_group(&new_client->dev.kobj, &atxp1_group)))
336 goto exit_detach;
337
323 data->class_dev = hwmon_device_register(&new_client->dev); 338 data->class_dev = hwmon_device_register(&new_client->dev);
324 if (IS_ERR(data->class_dev)) { 339 if (IS_ERR(data->class_dev)) {
325 err = PTR_ERR(data->class_dev); 340 err = PTR_ERR(data->class_dev);
326 goto exit_detach; 341 goto exit_remove_files;
327 } 342 }
328 343
329 device_create_file(&new_client->dev, &dev_attr_gpio1);
330 device_create_file(&new_client->dev, &dev_attr_gpio2);
331 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
332
333 dev_info(&new_client->dev, "Using VRM: %d.%d\n", 344 dev_info(&new_client->dev, "Using VRM: %d.%d\n",
334 data->vrm / 10, data->vrm % 10); 345 data->vrm / 10, data->vrm % 10);
335 346
336 return 0; 347 return 0;
337 348
349exit_remove_files:
350 sysfs_remove_group(&new_client->dev.kobj, &atxp1_group);
338exit_detach: 351exit_detach:
339 i2c_detach_client(new_client); 352 i2c_detach_client(new_client);
340exit_free: 353exit_free:
@@ -349,6 +362,7 @@ static int atxp1_detach_client(struct i2c_client * client)
349 int err; 362 int err;
350 363
351 hwmon_device_unregister(data->class_dev); 364 hwmon_device_unregister(data->class_dev);
365 sysfs_remove_group(&client->dev.kobj, &atxp1_group);
352 366
353 err = i2c_detach_client(client); 367 err = i2c_detach_client(client);
354 368
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c
index 478eb4bb8570..c849c0c6ee9c 100644
--- a/drivers/hwmon/ds1621.c
+++ b/drivers/hwmon/ds1621.c
@@ -29,6 +29,7 @@
29#include <linux/hwmon.h> 29#include <linux/hwmon.h>
30#include <linux/err.h> 30#include <linux/err.h>
31#include <linux/mutex.h> 31#include <linux/mutex.h>
32#include <linux/sysfs.h>
32#include "lm75.h" 33#include "lm75.h"
33 34
34/* Addresses to scan */ 35/* Addresses to scan */
@@ -178,6 +179,18 @@ static DEVICE_ATTR(temp1_input, S_IRUGO , show_temp, NULL);
178static DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO , show_temp_min, set_temp_min); 179static DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO , show_temp_min, set_temp_min);
179static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max); 180static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max);
180 181
182static struct attribute *ds1621_attributes[] = {
183 &dev_attr_temp1_input.attr,
184 &dev_attr_temp1_min.attr,
185 &dev_attr_temp1_max.attr,
186 &dev_attr_alarms.attr,
187 NULL
188};
189
190static const struct attribute_group ds1621_group = {
191 .attrs = ds1621_attributes,
192};
193
181 194
182static int ds1621_attach_adapter(struct i2c_adapter *adapter) 195static int ds1621_attach_adapter(struct i2c_adapter *adapter)
183{ 196{
@@ -253,21 +266,19 @@ static int ds1621_detect(struct i2c_adapter *adapter, int address,
253 ds1621_init_client(new_client); 266 ds1621_init_client(new_client);
254 267
255 /* Register sysfs hooks */ 268 /* Register sysfs hooks */
269 if ((err = sysfs_create_group(&new_client->dev.kobj, &ds1621_group)))
270 goto exit_detach;
271
256 data->class_dev = hwmon_device_register(&new_client->dev); 272 data->class_dev = hwmon_device_register(&new_client->dev);
257 if (IS_ERR(data->class_dev)) { 273 if (IS_ERR(data->class_dev)) {
258 err = PTR_ERR(data->class_dev); 274 err = PTR_ERR(data->class_dev);
259 goto exit_detach; 275 goto exit_remove_files;
260 } 276 }
261 277
262 device_create_file(&new_client->dev, &dev_attr_alarms);
263 device_create_file(&new_client->dev, &dev_attr_temp1_input);
264 device_create_file(&new_client->dev, &dev_attr_temp1_min);
265 device_create_file(&new_client->dev, &dev_attr_temp1_max);
266
267 return 0; 278 return 0;
268 279
269/* OK, this is not exactly good programming practice, usually. But it is 280 exit_remove_files:
270 very code-efficient in this case. */ 281 sysfs_remove_group(&new_client->dev.kobj, &ds1621_group);
271 exit_detach: 282 exit_detach:
272 i2c_detach_client(new_client); 283 i2c_detach_client(new_client);
273 exit_free: 284 exit_free:
@@ -282,6 +293,7 @@ static int ds1621_detach_client(struct i2c_client *client)
282 int err; 293 int err;
283 294
284 hwmon_device_unregister(data->class_dev); 295 hwmon_device_unregister(data->class_dev);
296 sysfs_remove_group(&client->dev.kobj, &ds1621_group);
285 297
286 if ((err = i2c_detach_client(client))) 298 if ((err = i2c_detach_client(client)))
287 return err; 299 return err;
diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c
index fd72440faf76..de17a72149d9 100644
--- a/drivers/hwmon/f71805f.c
+++ b/drivers/hwmon/f71805f.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * f71805f.c - driver for the Fintek F71805F/FG Super-I/O chip integrated 2 * f71805f.c - driver for the Fintek F71805F/FG Super-I/O chip integrated
3 * hardware monitoring features 3 * hardware monitoring features
4 * Copyright (C) 2005 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org>
5 * 5 *
6 * The F71805F/FG is a LPC Super-I/O chip made by Fintek. It integrates 6 * The F71805F/FG is a LPC Super-I/O chip made by Fintek. It integrates
7 * complete hardware monitoring features: voltage, fan and temperature 7 * complete hardware monitoring features: voltage, fan and temperature
@@ -31,6 +31,7 @@
31#include <linux/hwmon-sysfs.h> 31#include <linux/hwmon-sysfs.h>
32#include <linux/err.h> 32#include <linux/err.h>
33#include <linux/mutex.h> 33#include <linux/mutex.h>
34#include <linux/sysfs.h>
34#include <asm/io.h> 35#include <asm/io.h>
35 36
36static struct platform_device *pdev; 37static struct platform_device *pdev;
@@ -147,7 +148,7 @@ struct f71805f_data {
147 u8 temp_high[3]; 148 u8 temp_high[3];
148 u8 temp_hyst[3]; 149 u8 temp_hyst[3];
149 u8 temp_mode; 150 u8 temp_mode;
150 u8 alarms[3]; 151 unsigned long alarms;
151}; 152};
152 153
153static inline long in_from_reg(u8 reg) 154static inline long in_from_reg(u8 reg)
@@ -311,10 +312,9 @@ static struct f71805f_data *f71805f_update_device(struct device *dev)
311 data->temp[nr] = f71805f_read8(data, 312 data->temp[nr] = f71805f_read8(data,
312 F71805F_REG_TEMP(nr)); 313 F71805F_REG_TEMP(nr));
313 } 314 }
314 for (nr = 0; nr < 3; nr++) { 315 data->alarms = f71805f_read8(data, F71805F_REG_STATUS(0))
315 data->alarms[nr] = f71805f_read8(data, 316 + (f71805f_read8(data, F71805F_REG_STATUS(1)) << 8)
316 F71805F_REG_STATUS(nr)); 317 + (f71805f_read8(data, F71805F_REG_STATUS(2)) << 16);
317 }
318 318
319 data->last_updated = jiffies; 319 data->last_updated = jiffies;
320 data->valid = 1; 320 data->valid = 1;
@@ -557,8 +557,7 @@ static ssize_t show_alarms_in(struct device *dev, struct device_attribute
557{ 557{
558 struct f71805f_data *data = f71805f_update_device(dev); 558 struct f71805f_data *data = f71805f_update_device(dev);
559 559
560 return sprintf(buf, "%d\n", data->alarms[0] | 560 return sprintf(buf, "%lu\n", data->alarms & 0x1ff);
561 ((data->alarms[1] & 0x01) << 8));
562} 561}
563 562
564static ssize_t show_alarms_fan(struct device *dev, struct device_attribute 563static ssize_t show_alarms_fan(struct device *dev, struct device_attribute
@@ -566,7 +565,7 @@ static ssize_t show_alarms_fan(struct device *dev, struct device_attribute
566{ 565{
567 struct f71805f_data *data = f71805f_update_device(dev); 566 struct f71805f_data *data = f71805f_update_device(dev);
568 567
569 return sprintf(buf, "%d\n", data->alarms[2] & 0x07); 568 return sprintf(buf, "%lu\n", (data->alarms >> 16) & 0x07);
570} 569}
571 570
572static ssize_t show_alarms_temp(struct device *dev, struct device_attribute 571static ssize_t show_alarms_temp(struct device *dev, struct device_attribute
@@ -574,7 +573,17 @@ static ssize_t show_alarms_temp(struct device *dev, struct device_attribute
574{ 573{
575 struct f71805f_data *data = f71805f_update_device(dev); 574 struct f71805f_data *data = f71805f_update_device(dev);
576 575
577 return sprintf(buf, "%d\n", (data->alarms[1] >> 3) & 0x07); 576 return sprintf(buf, "%lu\n", (data->alarms >> 11) & 0x07);
577}
578
579static ssize_t show_alarm(struct device *dev, struct device_attribute
580 *devattr, char *buf)
581{
582 struct f71805f_data *data = f71805f_update_device(dev);
583 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
584 int bitnr = attr->index;
585
586 return sprintf(buf, "%lu\n", (data->alarms >> bitnr) & 1);
578} 587}
579 588
580static ssize_t show_name(struct device *dev, struct device_attribute 589static ssize_t show_name(struct device *dev, struct device_attribute
@@ -585,88 +594,189 @@ static ssize_t show_name(struct device *dev, struct device_attribute
585 return sprintf(buf, "%s\n", data->name); 594 return sprintf(buf, "%s\n", data->name);
586} 595}
587 596
588static struct device_attribute f71805f_dev_attr[] = { 597static DEVICE_ATTR(in0_input, S_IRUGO, show_in0, NULL);
589 __ATTR(in0_input, S_IRUGO, show_in0, NULL), 598static DEVICE_ATTR(in0_max, S_IRUGO| S_IWUSR, show_in0_max, set_in0_max);
590 __ATTR(in0_max, S_IRUGO| S_IWUSR, show_in0_max, set_in0_max), 599static DEVICE_ATTR(in0_min, S_IRUGO| S_IWUSR, show_in0_min, set_in0_min);
591 __ATTR(in0_min, S_IRUGO| S_IWUSR, show_in0_min, set_in0_min), 600static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 1);
592 __ATTR(alarms_in, S_IRUGO, show_alarms_in, NULL), 601static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S_IWUSR,
593 __ATTR(alarms_fan, S_IRUGO, show_alarms_fan, NULL), 602 show_in_max, set_in_max, 1);
594 __ATTR(alarms_temp, S_IRUGO, show_alarms_temp, NULL), 603static SENSOR_DEVICE_ATTR(in1_min, S_IRUGO | S_IWUSR,
595 __ATTR(name, S_IRUGO, show_name, NULL), 604 show_in_min, set_in_min, 1);
605static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in, NULL, 2);
606static SENSOR_DEVICE_ATTR(in2_max, S_IRUGO | S_IWUSR,
607 show_in_max, set_in_max, 2);
608static SENSOR_DEVICE_ATTR(in2_min, S_IRUGO | S_IWUSR,
609 show_in_min, set_in_min, 2);
610static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in, NULL, 3);
611static SENSOR_DEVICE_ATTR(in3_max, S_IRUGO | S_IWUSR,
612 show_in_max, set_in_max, 3);
613static SENSOR_DEVICE_ATTR(in3_min, S_IRUGO | S_IWUSR,
614 show_in_min, set_in_min, 3);
615static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in, NULL, 4);
616static SENSOR_DEVICE_ATTR(in4_max, S_IRUGO | S_IWUSR,
617 show_in_max, set_in_max, 4);
618static SENSOR_DEVICE_ATTR(in4_min, S_IRUGO | S_IWUSR,
619 show_in_min, set_in_min, 4);
620static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in, NULL, 5);
621static SENSOR_DEVICE_ATTR(in5_max, S_IRUGO | S_IWUSR,
622 show_in_max, set_in_max, 5);
623static SENSOR_DEVICE_ATTR(in5_min, S_IRUGO | S_IWUSR,
624 show_in_min, set_in_min, 5);
625static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in, NULL, 6);
626static SENSOR_DEVICE_ATTR(in6_max, S_IRUGO | S_IWUSR,
627 show_in_max, set_in_max, 6);
628static SENSOR_DEVICE_ATTR(in6_min, S_IRUGO | S_IWUSR,
629 show_in_min, set_in_min, 6);
630static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_in, NULL, 7);
631static SENSOR_DEVICE_ATTR(in7_max, S_IRUGO | S_IWUSR,
632 show_in_max, set_in_max, 7);
633static SENSOR_DEVICE_ATTR(in7_min, S_IRUGO | S_IWUSR,
634 show_in_min, set_in_min, 7);
635static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_in, NULL, 8);
636static SENSOR_DEVICE_ATTR(in8_max, S_IRUGO | S_IWUSR,
637 show_in_max, set_in_max, 8);
638static SENSOR_DEVICE_ATTR(in8_min, S_IRUGO | S_IWUSR,
639 show_in_min, set_in_min, 8);
640
641static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
642static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR,
643 show_fan_min, set_fan_min, 0);
644static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
645static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO | S_IWUSR,
646 show_fan_min, set_fan_min, 1);
647static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
648static SENSOR_DEVICE_ATTR(fan3_min, S_IRUGO | S_IWUSR,
649 show_fan_min, set_fan_min, 2);
650
651static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
652static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR,
653 show_temp_max, set_temp_max, 0);
654static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
655 show_temp_hyst, set_temp_hyst, 0);
656static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0);
657static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
658static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR,
659 show_temp_max, set_temp_max, 1);
660static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR,
661 show_temp_hyst, set_temp_hyst, 1);
662static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1);
663static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
664static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO | S_IWUSR,
665 show_temp_max, set_temp_max, 2);
666static SENSOR_DEVICE_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR,
667 show_temp_hyst, set_temp_hyst, 2);
668static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2);
669
670static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
671static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
672static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
673static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
674static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 4);
675static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 5);
676static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6);
677static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 7);
678static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 8);
679static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 11);
680static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 12);
681static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13);
682static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 16);
683static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 17);
684static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 18);
685static DEVICE_ATTR(alarms_in, S_IRUGO, show_alarms_in, NULL);
686static DEVICE_ATTR(alarms_fan, S_IRUGO, show_alarms_fan, NULL);
687static DEVICE_ATTR(alarms_temp, S_IRUGO, show_alarms_temp, NULL);
688
689static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
690
691static struct attribute *f71805f_attributes[] = {
692 &dev_attr_in0_input.attr,
693 &dev_attr_in0_max.attr,
694 &dev_attr_in0_min.attr,
695 &sensor_dev_attr_in1_input.dev_attr.attr,
696 &sensor_dev_attr_in1_max.dev_attr.attr,
697 &sensor_dev_attr_in1_min.dev_attr.attr,
698 &sensor_dev_attr_in2_input.dev_attr.attr,
699 &sensor_dev_attr_in2_max.dev_attr.attr,
700 &sensor_dev_attr_in2_min.dev_attr.attr,
701 &sensor_dev_attr_in3_input.dev_attr.attr,
702 &sensor_dev_attr_in3_max.dev_attr.attr,
703 &sensor_dev_attr_in3_min.dev_attr.attr,
704 &sensor_dev_attr_in4_input.dev_attr.attr,
705 &sensor_dev_attr_in4_max.dev_attr.attr,
706 &sensor_dev_attr_in4_min.dev_attr.attr,
707 &sensor_dev_attr_in5_input.dev_attr.attr,
708 &sensor_dev_attr_in5_max.dev_attr.attr,
709 &sensor_dev_attr_in5_min.dev_attr.attr,
710 &sensor_dev_attr_in6_input.dev_attr.attr,
711 &sensor_dev_attr_in6_max.dev_attr.attr,
712 &sensor_dev_attr_in6_min.dev_attr.attr,
713 &sensor_dev_attr_in7_input.dev_attr.attr,
714 &sensor_dev_attr_in7_max.dev_attr.attr,
715 &sensor_dev_attr_in7_min.dev_attr.attr,
716 &sensor_dev_attr_in8_input.dev_attr.attr,
717 &sensor_dev_attr_in8_max.dev_attr.attr,
718 &sensor_dev_attr_in8_min.dev_attr.attr,
719
720 &sensor_dev_attr_temp1_input.dev_attr.attr,
721 &sensor_dev_attr_temp1_max.dev_attr.attr,
722 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
723 &sensor_dev_attr_temp1_type.dev_attr.attr,
724 &sensor_dev_attr_temp2_input.dev_attr.attr,
725 &sensor_dev_attr_temp2_max.dev_attr.attr,
726 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
727 &sensor_dev_attr_temp2_type.dev_attr.attr,
728 &sensor_dev_attr_temp3_input.dev_attr.attr,
729 &sensor_dev_attr_temp3_max.dev_attr.attr,
730 &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
731 &sensor_dev_attr_temp3_type.dev_attr.attr,
732
733 &sensor_dev_attr_in0_alarm.dev_attr.attr,
734 &sensor_dev_attr_in1_alarm.dev_attr.attr,
735 &sensor_dev_attr_in2_alarm.dev_attr.attr,
736 &sensor_dev_attr_in3_alarm.dev_attr.attr,
737 &sensor_dev_attr_in4_alarm.dev_attr.attr,
738 &sensor_dev_attr_in5_alarm.dev_attr.attr,
739 &sensor_dev_attr_in6_alarm.dev_attr.attr,
740 &sensor_dev_attr_in7_alarm.dev_attr.attr,
741 &sensor_dev_attr_in8_alarm.dev_attr.attr,
742 &dev_attr_alarms_in.attr,
743 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
744 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
745 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
746 &dev_attr_alarms_temp.attr,
747 &dev_attr_alarms_fan.attr,
748
749 &dev_attr_name.attr,
750 NULL
596}; 751};
597 752
598static struct sensor_device_attribute f71805f_sensor_attr[] = { 753static const struct attribute_group f71805f_group = {
599 SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1), 754 .attrs = f71805f_attributes,
600 SENSOR_ATTR(in1_max, S_IRUGO | S_IWUSR,
601 show_in_max, set_in_max, 1),
602 SENSOR_ATTR(in1_min, S_IRUGO | S_IWUSR,
603 show_in_min, set_in_min, 1),
604 SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2),
605 SENSOR_ATTR(in2_max, S_IRUGO | S_IWUSR,
606 show_in_max, set_in_max, 2),
607 SENSOR_ATTR(in2_min, S_IRUGO | S_IWUSR,
608 show_in_min, set_in_min, 2),
609 SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3),
610 SENSOR_ATTR(in3_max, S_IRUGO | S_IWUSR,
611 show_in_max, set_in_max, 3),
612 SENSOR_ATTR(in3_min, S_IRUGO | S_IWUSR,
613 show_in_min, set_in_min, 3),
614 SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4),
615 SENSOR_ATTR(in4_max, S_IRUGO | S_IWUSR,
616 show_in_max, set_in_max, 4),
617 SENSOR_ATTR(in4_min, S_IRUGO | S_IWUSR,
618 show_in_min, set_in_min, 4),
619 SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5),
620 SENSOR_ATTR(in5_max, S_IRUGO | S_IWUSR,
621 show_in_max, set_in_max, 5),
622 SENSOR_ATTR(in5_min, S_IRUGO | S_IWUSR,
623 show_in_min, set_in_min, 5),
624 SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6),
625 SENSOR_ATTR(in6_max, S_IRUGO | S_IWUSR,
626 show_in_max, set_in_max, 6),
627 SENSOR_ATTR(in6_min, S_IRUGO | S_IWUSR,
628 show_in_min, set_in_min, 6),
629 SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7),
630 SENSOR_ATTR(in7_max, S_IRUGO | S_IWUSR,
631 show_in_max, set_in_max, 7),
632 SENSOR_ATTR(in7_min, S_IRUGO | S_IWUSR,
633 show_in_min, set_in_min, 7),
634 SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8),
635 SENSOR_ATTR(in8_max, S_IRUGO | S_IWUSR,
636 show_in_max, set_in_max, 8),
637 SENSOR_ATTR(in8_min, S_IRUGO | S_IWUSR,
638 show_in_min, set_in_min, 8),
639
640 SENSOR_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0),
641 SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR,
642 show_temp_max, set_temp_max, 0),
643 SENSOR_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
644 show_temp_hyst, set_temp_hyst, 0),
645 SENSOR_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0),
646 SENSOR_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1),
647 SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR,
648 show_temp_max, set_temp_max, 1),
649 SENSOR_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR,
650 show_temp_hyst, set_temp_hyst, 1),
651 SENSOR_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1),
652 SENSOR_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2),
653 SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR,
654 show_temp_max, set_temp_max, 2),
655 SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR,
656 show_temp_hyst, set_temp_hyst, 2),
657 SENSOR_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2),
658}; 755};
659 756
660static struct sensor_device_attribute f71805f_fan_attr[] = { 757static struct attribute *f71805f_attributes_fan[3][4] = {
661 SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0), 758 {
662 SENSOR_ATTR(fan1_min, S_IRUGO | S_IWUSR, 759 &sensor_dev_attr_fan1_input.dev_attr.attr,
663 show_fan_min, set_fan_min, 0), 760 &sensor_dev_attr_fan1_min.dev_attr.attr,
664 SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1), 761 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
665 SENSOR_ATTR(fan2_min, S_IRUGO | S_IWUSR, 762 NULL
666 show_fan_min, set_fan_min, 1), 763 }, {
667 SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2), 764 &sensor_dev_attr_fan2_input.dev_attr.attr,
668 SENSOR_ATTR(fan3_min, S_IRUGO | S_IWUSR, 765 &sensor_dev_attr_fan2_min.dev_attr.attr,
669 show_fan_min, set_fan_min, 2), 766 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
767 NULL
768 }, {
769 &sensor_dev_attr_fan3_input.dev_attr.attr,
770 &sensor_dev_attr_fan3_min.dev_attr.attr,
771 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
772 NULL
773 }
774};
775
776static const struct attribute_group f71805f_group_fan[3] = {
777 { .attrs = f71805f_attributes_fan[0] },
778 { .attrs = f71805f_attributes_fan[1] },
779 { .attrs = f71805f_attributes_fan[2] },
670}; 780};
671 781
672/* 782/*
@@ -714,43 +824,35 @@ static int __devinit f71805f_probe(struct platform_device *pdev)
714 824
715 platform_set_drvdata(pdev, data); 825 platform_set_drvdata(pdev, data);
716 826
717 data->class_dev = hwmon_device_register(&pdev->dev);
718 if (IS_ERR(data->class_dev)) {
719 err = PTR_ERR(data->class_dev);
720 dev_err(&pdev->dev, "Class registration failed (%d)\n", err);
721 goto exit_free;
722 }
723
724 /* Initialize the F71805F chip */ 827 /* Initialize the F71805F chip */
725 f71805f_init_device(data); 828 f71805f_init_device(data);
726 829
727 /* Register sysfs interface files */ 830 /* Register sysfs interface files */
728 for (i = 0; i < ARRAY_SIZE(f71805f_dev_attr); i++) { 831 if ((err = sysfs_create_group(&pdev->dev.kobj, &f71805f_group)))
729 err = device_create_file(&pdev->dev, &f71805f_dev_attr[i]); 832 goto exit_free;
730 if (err) 833 for (i = 0; i < 3; i++) {
731 goto exit_class; 834 if (!(data->fan_enabled & (1 << i)))
732 }
733 for (i = 0; i < ARRAY_SIZE(f71805f_sensor_attr); i++) {
734 err = device_create_file(&pdev->dev,
735 &f71805f_sensor_attr[i].dev_attr);
736 if (err)
737 goto exit_class;
738 }
739 for (i = 0; i < ARRAY_SIZE(f71805f_fan_attr); i++) {
740 if (!(data->fan_enabled & (1 << (i / 2))))
741 continue; 835 continue;
742 err = device_create_file(&pdev->dev, 836 if ((err = sysfs_create_group(&pdev->dev.kobj,
743 &f71805f_fan_attr[i].dev_attr); 837 &f71805f_group_fan[i])))
744 if (err) 838 goto exit_remove_files;
745 goto exit_class; 839 }
840
841 data->class_dev = hwmon_device_register(&pdev->dev);
842 if (IS_ERR(data->class_dev)) {
843 err = PTR_ERR(data->class_dev);
844 dev_err(&pdev->dev, "Class registration failed (%d)\n", err);
845 goto exit_remove_files;
746 } 846 }
747 847
748 return 0; 848 return 0;
749 849
750exit_class: 850exit_remove_files:
751 dev_err(&pdev->dev, "Sysfs interface creation failed\n"); 851 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group);
752 hwmon_device_unregister(data->class_dev); 852 for (i = 0; i < 3; i++)
853 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_fan[i]);
753exit_free: 854exit_free:
855 platform_set_drvdata(pdev, NULL);
754 kfree(data); 856 kfree(data);
755exit: 857exit:
756 return err; 858 return err;
@@ -759,9 +861,13 @@ exit:
759static int __devexit f71805f_remove(struct platform_device *pdev) 861static int __devexit f71805f_remove(struct platform_device *pdev)
760{ 862{
761 struct f71805f_data *data = platform_get_drvdata(pdev); 863 struct f71805f_data *data = platform_get_drvdata(pdev);
864 int i;
762 865
763 platform_set_drvdata(pdev, NULL); 866 platform_set_drvdata(pdev, NULL);
764 hwmon_device_unregister(data->class_dev); 867 hwmon_device_unregister(data->class_dev);
868 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group);
869 for (i = 0; i < 3; i++)
870 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_fan[i]);
765 kfree(data); 871 kfree(data);
766 872
767 return 0; 873 return 0;
diff --git a/drivers/hwmon/fscher.c b/drivers/hwmon/fscher.c
index 6bc76b407636..19717752cfca 100644
--- a/drivers/hwmon/fscher.c
+++ b/drivers/hwmon/fscher.c
@@ -34,6 +34,7 @@
34#include <linux/hwmon.h> 34#include <linux/hwmon.h>
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/sysfs.h>
37 38
38/* 39/*
39 * Addresses to scan 40 * Addresses to scan
@@ -240,47 +241,45 @@ sysfs_alarms(FSCHER_REG_EVENTS)
240sysfs_control(FSCHER_REG_CONTROL) 241sysfs_control(FSCHER_REG_CONTROL)
241sysfs_watchdog(FSCHER_REG_WDOG_CONTROL, FSCHER_REG_WDOG_STATE, FSCHER_REG_WDOG_PRESET) 242sysfs_watchdog(FSCHER_REG_WDOG_CONTROL, FSCHER_REG_WDOG_STATE, FSCHER_REG_WDOG_PRESET)
242 243
243#define device_create_file_fan(client, offset) \ 244static struct attribute *fscher_attributes[] = {
244do { \ 245 &dev_attr_revision.attr,
245 device_create_file(&client->dev, &dev_attr_fan##offset##_status); \ 246 &dev_attr_alarms.attr,
246 device_create_file(&client->dev, &dev_attr_pwm##offset); \ 247 &dev_attr_control.attr,
247 device_create_file(&client->dev, &dev_attr_fan##offset##_div); \ 248
248 device_create_file(&client->dev, &dev_attr_fan##offset##_input); \ 249 &dev_attr_watchdog_status.attr,
249} while (0) 250 &dev_attr_watchdog_control.attr,
250 251 &dev_attr_watchdog_preset.attr,
251#define device_create_file_temp(client, offset) \ 252
252do { \ 253 &dev_attr_in0_input.attr,
253 device_create_file(&client->dev, &dev_attr_temp##offset##_status); \ 254 &dev_attr_in1_input.attr,
254 device_create_file(&client->dev, &dev_attr_temp##offset##_input); \ 255 &dev_attr_in2_input.attr,
255} while (0) 256
256 257 &dev_attr_fan1_status.attr,
257#define device_create_file_in(client, offset) \ 258 &dev_attr_fan1_div.attr,
258do { \ 259 &dev_attr_fan1_input.attr,
259 device_create_file(&client->dev, &dev_attr_in##offset##_input); \ 260 &dev_attr_pwm1.attr,
260} while (0) 261 &dev_attr_fan2_status.attr,
261 262 &dev_attr_fan2_div.attr,
262#define device_create_file_revision(client) \ 263 &dev_attr_fan2_input.attr,
263do { \ 264 &dev_attr_pwm2.attr,
264 device_create_file(&client->dev, &dev_attr_revision); \ 265 &dev_attr_fan3_status.attr,
265} while (0) 266 &dev_attr_fan3_div.attr,
266 267 &dev_attr_fan3_input.attr,
267#define device_create_file_alarms(client) \ 268 &dev_attr_pwm3.attr,
268do { \ 269
269 device_create_file(&client->dev, &dev_attr_alarms); \ 270 &dev_attr_temp1_status.attr,
270} while (0) 271 &dev_attr_temp1_input.attr,
271 272 &dev_attr_temp2_status.attr,
272#define device_create_file_control(client) \ 273 &dev_attr_temp2_input.attr,
273do { \ 274 &dev_attr_temp3_status.attr,
274 device_create_file(&client->dev, &dev_attr_control); \ 275 &dev_attr_temp3_input.attr,
275} while (0) 276 NULL
276 277};
277#define device_create_file_watchdog(client) \ 278
278do { \ 279static const struct attribute_group fscher_group = {
279 device_create_file(&client->dev, &dev_attr_watchdog_status); \ 280 .attrs = fscher_attributes,
280 device_create_file(&client->dev, &dev_attr_watchdog_control); \ 281};
281 device_create_file(&client->dev, &dev_attr_watchdog_preset); \ 282
282} while (0)
283
284/* 283/*
285 * Real code 284 * Real code
286 */ 285 */
@@ -342,31 +341,19 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
342 fscher_init_client(new_client); 341 fscher_init_client(new_client);
343 342
344 /* Register sysfs hooks */ 343 /* Register sysfs hooks */
344 if ((err = sysfs_create_group(&new_client->dev.kobj, &fscher_group)))
345 goto exit_detach;
346
345 data->class_dev = hwmon_device_register(&new_client->dev); 347 data->class_dev = hwmon_device_register(&new_client->dev);
346 if (IS_ERR(data->class_dev)) { 348 if (IS_ERR(data->class_dev)) {
347 err = PTR_ERR(data->class_dev); 349 err = PTR_ERR(data->class_dev);
348 goto exit_detach; 350 goto exit_remove_files;
349 } 351 }
350 352
351 device_create_file_revision(new_client);
352 device_create_file_alarms(new_client);
353 device_create_file_control(new_client);
354 device_create_file_watchdog(new_client);
355
356 device_create_file_in(new_client, 0);
357 device_create_file_in(new_client, 1);
358 device_create_file_in(new_client, 2);
359
360 device_create_file_fan(new_client, 1);
361 device_create_file_fan(new_client, 2);
362 device_create_file_fan(new_client, 3);
363
364 device_create_file_temp(new_client, 1);
365 device_create_file_temp(new_client, 2);
366 device_create_file_temp(new_client, 3);
367
368 return 0; 353 return 0;
369 354
355exit_remove_files:
356 sysfs_remove_group(&new_client->dev.kobj, &fscher_group);
370exit_detach: 357exit_detach:
371 i2c_detach_client(new_client); 358 i2c_detach_client(new_client);
372exit_free: 359exit_free:
@@ -381,6 +368,7 @@ static int fscher_detach_client(struct i2c_client *client)
381 int err; 368 int err;
382 369
383 hwmon_device_unregister(data->class_dev); 370 hwmon_device_unregister(data->class_dev);
371 sysfs_remove_group(&client->dev.kobj, &fscher_group);
384 372
385 if ((err = i2c_detach_client(client))) 373 if ((err = i2c_detach_client(client)))
386 return err; 374 return err;
diff --git a/drivers/hwmon/fscpos.c b/drivers/hwmon/fscpos.c
index 6dc4846b9eeb..ea506a77f9c9 100644
--- a/drivers/hwmon/fscpos.c
+++ b/drivers/hwmon/fscpos.c
@@ -38,6 +38,7 @@
38#include <linux/hwmon.h> 38#include <linux/hwmon.h>
39#include <linux/err.h> 39#include <linux/err.h>
40#include <linux/mutex.h> 40#include <linux/mutex.h>
41#include <linux/sysfs.h>
41 42
42/* 43/*
43 * Addresses to scan 44 * Addresses to scan
@@ -432,6 +433,44 @@ static DEVICE_ATTR(in0_input, S_IRUGO, show_volt_12, NULL);
432static DEVICE_ATTR(in1_input, S_IRUGO, show_volt_5, NULL); 433static DEVICE_ATTR(in1_input, S_IRUGO, show_volt_5, NULL);
433static DEVICE_ATTR(in2_input, S_IRUGO, show_volt_batt, NULL); 434static DEVICE_ATTR(in2_input, S_IRUGO, show_volt_batt, NULL);
434 435
436static struct attribute *fscpos_attributes[] = {
437 &dev_attr_event.attr,
438 &dev_attr_in0_input.attr,
439 &dev_attr_in1_input.attr,
440 &dev_attr_in2_input.attr,
441
442 &dev_attr_wdog_control.attr,
443 &dev_attr_wdog_preset.attr,
444 &dev_attr_wdog_state.attr,
445
446 &dev_attr_temp1_input.attr,
447 &dev_attr_temp1_status.attr,
448 &dev_attr_temp1_reset.attr,
449 &dev_attr_temp2_input.attr,
450 &dev_attr_temp2_status.attr,
451 &dev_attr_temp2_reset.attr,
452 &dev_attr_temp3_input.attr,
453 &dev_attr_temp3_status.attr,
454 &dev_attr_temp3_reset.attr,
455
456 &dev_attr_fan1_input.attr,
457 &dev_attr_fan1_status.attr,
458 &dev_attr_fan1_ripple.attr,
459 &dev_attr_pwm1.attr,
460 &dev_attr_fan2_input.attr,
461 &dev_attr_fan2_status.attr,
462 &dev_attr_fan2_ripple.attr,
463 &dev_attr_pwm2.attr,
464 &dev_attr_fan3_input.attr,
465 &dev_attr_fan3_status.attr,
466 &dev_attr_fan3_ripple.attr,
467 NULL
468};
469
470static const struct attribute_group fscpos_group = {
471 .attrs = fscpos_attributes,
472};
473
435static int fscpos_attach_adapter(struct i2c_adapter *adapter) 474static int fscpos_attach_adapter(struct i2c_adapter *adapter)
436{ 475{
437 if (!(adapter->class & I2C_CLASS_HWMON)) 476 if (!(adapter->class & I2C_CLASS_HWMON))
@@ -497,42 +536,19 @@ static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind)
497 dev_info(&new_client->dev, "Found fscpos chip, rev %u\n", data->revision); 536 dev_info(&new_client->dev, "Found fscpos chip, rev %u\n", data->revision);
498 537
499 /* Register sysfs hooks */ 538 /* Register sysfs hooks */
539 if ((err = sysfs_create_group(&new_client->dev.kobj, &fscpos_group)))
540 goto exit_detach;
541
500 data->class_dev = hwmon_device_register(&new_client->dev); 542 data->class_dev = hwmon_device_register(&new_client->dev);
501 if (IS_ERR(data->class_dev)) { 543 if (IS_ERR(data->class_dev)) {
502 err = PTR_ERR(data->class_dev); 544 err = PTR_ERR(data->class_dev);
503 goto exit_detach; 545 goto exit_remove_files;
504 } 546 }
505 547
506 device_create_file(&new_client->dev, &dev_attr_event);
507 device_create_file(&new_client->dev, &dev_attr_in0_input);
508 device_create_file(&new_client->dev, &dev_attr_in1_input);
509 device_create_file(&new_client->dev, &dev_attr_in2_input);
510 device_create_file(&new_client->dev, &dev_attr_wdog_control);
511 device_create_file(&new_client->dev, &dev_attr_wdog_preset);
512 device_create_file(&new_client->dev, &dev_attr_wdog_state);
513 device_create_file(&new_client->dev, &dev_attr_temp1_input);
514 device_create_file(&new_client->dev, &dev_attr_temp1_status);
515 device_create_file(&new_client->dev, &dev_attr_temp1_reset);
516 device_create_file(&new_client->dev, &dev_attr_temp2_input);
517 device_create_file(&new_client->dev, &dev_attr_temp2_status);
518 device_create_file(&new_client->dev, &dev_attr_temp2_reset);
519 device_create_file(&new_client->dev, &dev_attr_temp3_input);
520 device_create_file(&new_client->dev, &dev_attr_temp3_status);
521 device_create_file(&new_client->dev, &dev_attr_temp3_reset);
522 device_create_file(&new_client->dev, &dev_attr_fan1_input);
523 device_create_file(&new_client->dev, &dev_attr_fan1_status);
524 device_create_file(&new_client->dev, &dev_attr_fan1_ripple);
525 device_create_file(&new_client->dev, &dev_attr_pwm1);
526 device_create_file(&new_client->dev, &dev_attr_fan2_input);
527 device_create_file(&new_client->dev, &dev_attr_fan2_status);
528 device_create_file(&new_client->dev, &dev_attr_fan2_ripple);
529 device_create_file(&new_client->dev, &dev_attr_pwm2);
530 device_create_file(&new_client->dev, &dev_attr_fan3_input);
531 device_create_file(&new_client->dev, &dev_attr_fan3_status);
532 device_create_file(&new_client->dev, &dev_attr_fan3_ripple);
533
534 return 0; 548 return 0;
535 549
550exit_remove_files:
551 sysfs_remove_group(&new_client->dev.kobj, &fscpos_group);
536exit_detach: 552exit_detach:
537 i2c_detach_client(new_client); 553 i2c_detach_client(new_client);
538exit_free: 554exit_free:
@@ -547,6 +563,7 @@ static int fscpos_detach_client(struct i2c_client *client)
547 int err; 563 int err;
548 564
549 hwmon_device_unregister(data->class_dev); 565 hwmon_device_unregister(data->class_dev);
566 sysfs_remove_group(&client->dev.kobj, &fscpos_group);
550 567
551 if ((err = i2c_detach_client(client))) 568 if ((err = i2c_detach_client(client)))
552 return err; 569 return err;
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c
index 6606aabdb49d..c103640455a3 100644
--- a/drivers/hwmon/gl518sm.c
+++ b/drivers/hwmon/gl518sm.c
@@ -44,6 +44,7 @@
44#include <linux/hwmon.h> 44#include <linux/hwmon.h>
45#include <linux/err.h> 45#include <linux/err.h>
46#include <linux/mutex.h> 46#include <linux/mutex.h>
47#include <linux/sysfs.h>
47 48
48/* Addresses to scan */ 49/* Addresses to scan */
49static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; 50static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
@@ -340,6 +341,42 @@ static DEVICE_ATTR(beep_enable, S_IWUSR|S_IRUGO,
340static DEVICE_ATTR(beep_mask, S_IWUSR|S_IRUGO, 341static DEVICE_ATTR(beep_mask, S_IWUSR|S_IRUGO,
341 show_beep_mask, set_beep_mask); 342 show_beep_mask, set_beep_mask);
342 343
344static struct attribute *gl518_attributes[] = {
345 &dev_attr_in0_input.attr,
346 &dev_attr_in1_input.attr,
347 &dev_attr_in2_input.attr,
348 &dev_attr_in3_input.attr,
349 &dev_attr_in0_min.attr,
350 &dev_attr_in1_min.attr,
351 &dev_attr_in2_min.attr,
352 &dev_attr_in3_min.attr,
353 &dev_attr_in0_max.attr,
354 &dev_attr_in1_max.attr,
355 &dev_attr_in2_max.attr,
356 &dev_attr_in3_max.attr,
357
358 &dev_attr_fan1_auto.attr,
359 &dev_attr_fan1_input.attr,
360 &dev_attr_fan2_input.attr,
361 &dev_attr_fan1_min.attr,
362 &dev_attr_fan2_min.attr,
363 &dev_attr_fan1_div.attr,
364 &dev_attr_fan2_div.attr,
365
366 &dev_attr_temp1_input.attr,
367 &dev_attr_temp1_max.attr,
368 &dev_attr_temp1_max_hyst.attr,
369
370 &dev_attr_alarms.attr,
371 &dev_attr_beep_enable.attr,
372 &dev_attr_beep_mask.attr,
373 NULL
374};
375
376static const struct attribute_group gl518_group = {
377 .attrs = gl518_attributes,
378};
379
343/* 380/*
344 * Real code 381 * Real code
345 */ 382 */
@@ -420,43 +457,19 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
420 gl518_init_client((struct i2c_client *) new_client); 457 gl518_init_client((struct i2c_client *) new_client);
421 458
422 /* Register sysfs hooks */ 459 /* Register sysfs hooks */
460 if ((err = sysfs_create_group(&new_client->dev.kobj, &gl518_group)))
461 goto exit_detach;
462
423 data->class_dev = hwmon_device_register(&new_client->dev); 463 data->class_dev = hwmon_device_register(&new_client->dev);
424 if (IS_ERR(data->class_dev)) { 464 if (IS_ERR(data->class_dev)) {
425 err = PTR_ERR(data->class_dev); 465 err = PTR_ERR(data->class_dev);
426 goto exit_detach; 466 goto exit_remove_files;
427 } 467 }
428 468
429 device_create_file(&new_client->dev, &dev_attr_in0_input);
430 device_create_file(&new_client->dev, &dev_attr_in1_input);
431 device_create_file(&new_client->dev, &dev_attr_in2_input);
432 device_create_file(&new_client->dev, &dev_attr_in3_input);
433 device_create_file(&new_client->dev, &dev_attr_in0_min);
434 device_create_file(&new_client->dev, &dev_attr_in1_min);
435 device_create_file(&new_client->dev, &dev_attr_in2_min);
436 device_create_file(&new_client->dev, &dev_attr_in3_min);
437 device_create_file(&new_client->dev, &dev_attr_in0_max);
438 device_create_file(&new_client->dev, &dev_attr_in1_max);
439 device_create_file(&new_client->dev, &dev_attr_in2_max);
440 device_create_file(&new_client->dev, &dev_attr_in3_max);
441 device_create_file(&new_client->dev, &dev_attr_fan1_auto);
442 device_create_file(&new_client->dev, &dev_attr_fan1_input);
443 device_create_file(&new_client->dev, &dev_attr_fan2_input);
444 device_create_file(&new_client->dev, &dev_attr_fan1_min);
445 device_create_file(&new_client->dev, &dev_attr_fan2_min);
446 device_create_file(&new_client->dev, &dev_attr_fan1_div);
447 device_create_file(&new_client->dev, &dev_attr_fan2_div);
448 device_create_file(&new_client->dev, &dev_attr_temp1_input);
449 device_create_file(&new_client->dev, &dev_attr_temp1_max);
450 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
451 device_create_file(&new_client->dev, &dev_attr_alarms);
452 device_create_file(&new_client->dev, &dev_attr_beep_enable);
453 device_create_file(&new_client->dev, &dev_attr_beep_mask);
454
455 return 0; 469 return 0;
456 470
457/* OK, this is not exactly good programming practice, usually. But it is 471exit_remove_files:
458 very code-efficient in this case. */ 472 sysfs_remove_group(&new_client->dev.kobj, &gl518_group);
459
460exit_detach: 473exit_detach:
461 i2c_detach_client(new_client); 474 i2c_detach_client(new_client);
462exit_free: 475exit_free:
@@ -490,6 +503,7 @@ static int gl518_detach_client(struct i2c_client *client)
490 int err; 503 int err;
491 504
492 hwmon_device_unregister(data->class_dev); 505 hwmon_device_unregister(data->class_dev);
506 sysfs_remove_group(&client->dev.kobj, &gl518_group);
493 507
494 if ((err = i2c_detach_client(client))) 508 if ((err = i2c_detach_client(client)))
495 return err; 509 return err;
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c
index 14e810f3c2c0..ebe7b9aaa916 100644
--- a/drivers/hwmon/gl520sm.c
+++ b/drivers/hwmon/gl520sm.c
@@ -30,6 +30,7 @@
30#include <linux/hwmon-vid.h> 30#include <linux/hwmon-vid.h>
31#include <linux/err.h> 31#include <linux/err.h>
32#include <linux/mutex.h> 32#include <linux/mutex.h>
33#include <linux/sysfs.h>
33 34
34/* Type of the extra sensor */ 35/* Type of the extra sensor */
35static unsigned short extra_sensor_type; 36static unsigned short extra_sensor_type;
@@ -190,55 +191,29 @@ static DEVICE_ATTR(type##item, S_IRUGO, get_##type##0##item, NULL);
190#define sysfs_vid(n) \ 191#define sysfs_vid(n) \
191sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT) 192sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT)
192 193
193#define device_create_file_vid(client, n) \
194device_create_file(&client->dev, &dev_attr_cpu##n##_vid)
195
196#define sysfs_in(n) \ 194#define sysfs_in(n) \
197sysfs_ro_n(in, n, _input, GL520_REG_IN##n##INPUT) \ 195sysfs_ro_n(in, n, _input, GL520_REG_IN##n##INPUT) \
198sysfs_rw_n(in, n, _min, GL520_REG_IN##n##_MIN) \ 196sysfs_rw_n(in, n, _min, GL520_REG_IN##n##_MIN) \
199sysfs_rw_n(in, n, _max, GL520_REG_IN##n##_MAX) \ 197sysfs_rw_n(in, n, _max, GL520_REG_IN##n##_MAX) \
200 198
201#define device_create_file_in(client, n) \
202({device_create_file(&client->dev, &dev_attr_in##n##_input); \
203device_create_file(&client->dev, &dev_attr_in##n##_min); \
204device_create_file(&client->dev, &dev_attr_in##n##_max);})
205
206#define sysfs_fan(n) \ 199#define sysfs_fan(n) \
207sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \ 200sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \
208sysfs_rw_n(fan, n, _min, GL520_REG_FAN_MIN) \ 201sysfs_rw_n(fan, n, _min, GL520_REG_FAN_MIN) \
209sysfs_rw_n(fan, n, _div, GL520_REG_FAN_DIV) 202sysfs_rw_n(fan, n, _div, GL520_REG_FAN_DIV)
210 203
211#define device_create_file_fan(client, n) \
212({device_create_file(&client->dev, &dev_attr_fan##n##_input); \
213device_create_file(&client->dev, &dev_attr_fan##n##_min); \
214device_create_file(&client->dev, &dev_attr_fan##n##_div);})
215
216#define sysfs_fan_off(n) \ 204#define sysfs_fan_off(n) \
217sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF) \ 205sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF) \
218 206
219#define device_create_file_fan_off(client, n) \
220device_create_file(&client->dev, &dev_attr_fan##n##_off)
221
222#define sysfs_temp(n) \ 207#define sysfs_temp(n) \
223sysfs_ro_n(temp, n, _input, GL520_REG_TEMP##n##_INPUT) \ 208sysfs_ro_n(temp, n, _input, GL520_REG_TEMP##n##_INPUT) \
224sysfs_rw_n(temp, n, _max, GL520_REG_TEMP##n##_MAX) \ 209sysfs_rw_n(temp, n, _max, GL520_REG_TEMP##n##_MAX) \
225sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP##n##_MAX_HYST) 210sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP##n##_MAX_HYST)
226 211
227#define device_create_file_temp(client, n) \
228({device_create_file(&client->dev, &dev_attr_temp##n##_input); \
229device_create_file(&client->dev, &dev_attr_temp##n##_max); \
230device_create_file(&client->dev, &dev_attr_temp##n##_max_hyst);})
231
232#define sysfs_alarms() \ 212#define sysfs_alarms() \
233sysfs_ro(alarms, , GL520_REG_ALARMS) \ 213sysfs_ro(alarms, , GL520_REG_ALARMS) \
234sysfs_rw(beep_enable, , GL520_REG_BEEP_ENABLE) \ 214sysfs_rw(beep_enable, , GL520_REG_BEEP_ENABLE) \
235sysfs_rw(beep_mask, , GL520_REG_BEEP_MASK) 215sysfs_rw(beep_mask, , GL520_REG_BEEP_MASK)
236 216
237#define device_create_file_alarms(client) \
238({device_create_file(&client->dev, &dev_attr_alarms); \
239device_create_file(&client->dev, &dev_attr_beep_enable); \
240device_create_file(&client->dev, &dev_attr_beep_mask);})
241
242 217
243sysfs_vid(0) 218sysfs_vid(0)
244 219
@@ -511,6 +486,59 @@ static ssize_t set_beep_mask(struct i2c_client *client, struct gl520_data *data,
511 return count; 486 return count;
512} 487}
513 488
489static struct attribute *gl520_attributes[] = {
490 &dev_attr_cpu0_vid.attr,
491
492 &dev_attr_in0_input.attr,
493 &dev_attr_in0_min.attr,
494 &dev_attr_in0_max.attr,
495 &dev_attr_in1_input.attr,
496 &dev_attr_in1_min.attr,
497 &dev_attr_in1_max.attr,
498 &dev_attr_in2_input.attr,
499 &dev_attr_in2_min.attr,
500 &dev_attr_in2_max.attr,
501 &dev_attr_in3_input.attr,
502 &dev_attr_in3_min.attr,
503 &dev_attr_in3_max.attr,
504
505 &dev_attr_fan1_input.attr,
506 &dev_attr_fan1_min.attr,
507 &dev_attr_fan1_div.attr,
508 &dev_attr_fan1_off.attr,
509 &dev_attr_fan2_input.attr,
510 &dev_attr_fan2_min.attr,
511 &dev_attr_fan2_div.attr,
512
513 &dev_attr_temp1_input.attr,
514 &dev_attr_temp1_max.attr,
515 &dev_attr_temp1_max_hyst.attr,
516
517 &dev_attr_alarms.attr,
518 &dev_attr_beep_enable.attr,
519 &dev_attr_beep_mask.attr,
520 NULL
521};
522
523static const struct attribute_group gl520_group = {
524 .attrs = gl520_attributes,
525};
526
527static struct attribute *gl520_attributes_opt[] = {
528 &dev_attr_in4_input.attr,
529 &dev_attr_in4_min.attr,
530 &dev_attr_in4_max.attr,
531
532 &dev_attr_temp2_input.attr,
533 &dev_attr_temp2_max.attr,
534 &dev_attr_temp2_max_hyst.attr,
535 NULL
536};
537
538static const struct attribute_group gl520_group_opt = {
539 .attrs = gl520_attributes_opt,
540};
541
514 542
515/* 543/*
516 * Real code 544 * Real code
@@ -572,33 +600,39 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
572 gl520_init_client(new_client); 600 gl520_init_client(new_client);
573 601
574 /* Register sysfs hooks */ 602 /* Register sysfs hooks */
575 data->class_dev = hwmon_device_register(&new_client->dev); 603 if ((err = sysfs_create_group(&new_client->dev.kobj, &gl520_group)))
576 if (IS_ERR(data->class_dev)) {
577 err = PTR_ERR(data->class_dev);
578 goto exit_detach; 604 goto exit_detach;
579 }
580
581 device_create_file_vid(new_client, 0);
582 605
583 device_create_file_in(new_client, 0); 606 if (data->two_temps) {
584 device_create_file_in(new_client, 1); 607 if ((err = device_create_file(&new_client->dev,
585 device_create_file_in(new_client, 2); 608 &dev_attr_temp2_input))
586 device_create_file_in(new_client, 3); 609 || (err = device_create_file(&new_client->dev,
587 if (!data->two_temps) 610 &dev_attr_temp2_max))
588 device_create_file_in(new_client, 4); 611 || (err = device_create_file(&new_client->dev,
589 612 &dev_attr_temp2_max_hyst)))
590 device_create_file_fan(new_client, 1); 613 goto exit_remove_files;
591 device_create_file_fan(new_client, 2); 614 } else {
592 device_create_file_fan_off(new_client, 1); 615 if ((err = device_create_file(&new_client->dev,
616 &dev_attr_in4_input))
617 || (err = device_create_file(&new_client->dev,
618 &dev_attr_in4_min))
619 || (err = device_create_file(&new_client->dev,
620 &dev_attr_in4_max)))
621 goto exit_remove_files;
622 }
593 623
594 device_create_file_temp(new_client, 1);
595 if (data->two_temps)
596 device_create_file_temp(new_client, 2);
597 624
598 device_create_file_alarms(new_client); 625 data->class_dev = hwmon_device_register(&new_client->dev);
626 if (IS_ERR(data->class_dev)) {
627 err = PTR_ERR(data->class_dev);
628 goto exit_remove_files;
629 }
599 630
600 return 0; 631 return 0;
601 632
633exit_remove_files:
634 sysfs_remove_group(&new_client->dev.kobj, &gl520_group);
635 sysfs_remove_group(&new_client->dev.kobj, &gl520_group_opt);
602exit_detach: 636exit_detach:
603 i2c_detach_client(new_client); 637 i2c_detach_client(new_client);
604exit_free: 638exit_free:
@@ -652,6 +686,8 @@ static int gl520_detach_client(struct i2c_client *client)
652 int err; 686 int err;
653 687
654 hwmon_device_unregister(data->class_dev); 688 hwmon_device_unregister(data->class_dev);
689 sysfs_remove_group(&client->dev.kobj, &gl520_group);
690 sysfs_remove_group(&client->dev.kobj, &gl520_group_opt);
655 691
656 if ((err = i2c_detach_client(client))) 692 if ((err = i2c_detach_client(client)))
657 return err; 693 return err;
diff --git a/drivers/hwmon/hdaps.c b/drivers/hwmon/hdaps.c
index 42b632889dd8..26be4ea8a38a 100644
--- a/drivers/hwmon/hdaps.c
+++ b/drivers/hwmon/hdaps.c
@@ -537,6 +537,7 @@ static int __init hdaps_init(void)
537 HDAPS_DMI_MATCH_NORMAL("ThinkPad T42"), 537 HDAPS_DMI_MATCH_NORMAL("ThinkPad T42"),
538 HDAPS_DMI_MATCH_NORMAL("ThinkPad T43"), 538 HDAPS_DMI_MATCH_NORMAL("ThinkPad T43"),
539 HDAPS_DMI_MATCH_LENOVO("ThinkPad T60p"), 539 HDAPS_DMI_MATCH_LENOVO("ThinkPad T60p"),
540 HDAPS_DMI_MATCH_LENOVO("ThinkPad T60"),
540 HDAPS_DMI_MATCH_NORMAL("ThinkPad X40"), 541 HDAPS_DMI_MATCH_NORMAL("ThinkPad X40"),
541 HDAPS_DMI_MATCH_NORMAL("ThinkPad X41"), 542 HDAPS_DMI_MATCH_NORMAL("ThinkPad X41"),
542 HDAPS_DMI_MATCH_LENOVO("ThinkPad X60"), 543 HDAPS_DMI_MATCH_LENOVO("ThinkPad X60"),
@@ -587,7 +588,9 @@ static int __init hdaps_init(void)
587 input_set_abs_params(hdaps_idev, ABS_Y, 588 input_set_abs_params(hdaps_idev, ABS_Y,
588 -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT); 589 -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT);
589 590
590 input_register_device(hdaps_idev); 591 ret = input_register_device(hdaps_idev);
592 if (ret)
593 goto out_idev;
591 594
592 /* start up our timer for the input device */ 595 /* start up our timer for the input device */
593 init_timer(&hdaps_timer); 596 init_timer(&hdaps_timer);
@@ -598,6 +601,8 @@ static int __init hdaps_init(void)
598 printk(KERN_INFO "hdaps: driver successfully loaded.\n"); 601 printk(KERN_INFO "hdaps: driver successfully loaded.\n");
599 return 0; 602 return 0;
600 603
604out_idev:
605 input_free_device(hdaps_idev);
601out_group: 606out_group:
602 sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group); 607 sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group);
603out_device: 608out_device:
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 06df92b3ee49..323ef06719c1 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -4,10 +4,12 @@
4 4
5 Supports: IT8705F Super I/O chip w/LPC interface 5 Supports: IT8705F Super I/O chip w/LPC interface
6 IT8712F Super I/O chip w/LPC interface & SMBus 6 IT8712F Super I/O chip w/LPC interface & SMBus
7 IT8716F Super I/O chip w/LPC interface
8 IT8718F Super I/O chip w/LPC interface
7 Sis950 A clone of the IT8705F 9 Sis950 A clone of the IT8705F
8 10
9 Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com> 11 Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com>
10 Largely inspired by lm78.c of the same package 12 Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org>
11 13
12 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
13 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
@@ -24,13 +26,6 @@
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25*/ 27*/
26 28
27/*
28 djg@pdp8.net David Gesswein 7/18/01
29 Modified to fix bug with not all alarms enabled.
30 Added ability to read battery voltage and select temperature sensor
31 type at module load time.
32*/
33
34#include <linux/module.h> 29#include <linux/module.h>
35#include <linux/init.h> 30#include <linux/init.h>
36#include <linux/slab.h> 31#include <linux/slab.h>
@@ -42,6 +37,7 @@
42#include <linux/hwmon-vid.h> 37#include <linux/hwmon-vid.h>
43#include <linux/err.h> 38#include <linux/err.h>
44#include <linux/mutex.h> 39#include <linux/mutex.h>
40#include <linux/sysfs.h>
45#include <asm/io.h> 41#include <asm/io.h>
46 42
47 43
@@ -50,12 +46,13 @@ static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END };
50static unsigned short isa_address; 46static unsigned short isa_address;
51 47
52/* Insmod parameters */ 48/* Insmod parameters */
53I2C_CLIENT_INSMOD_2(it87, it8712); 49I2C_CLIENT_INSMOD_4(it87, it8712, it8716, it8718);
54 50
55#define REG 0x2e /* The register to read/write */ 51#define REG 0x2e /* The register to read/write */
56#define DEV 0x07 /* Register: Logical device select */ 52#define DEV 0x07 /* Register: Logical device select */
57#define VAL 0x2f /* The value to read/write */ 53#define VAL 0x2f /* The value to read/write */
58#define PME 0x04 /* The device with the fan registers in it */ 54#define PME 0x04 /* The device with the fan registers in it */
55#define GPIO 0x07 /* The device with the IT8718F VID value in it */
59#define DEVID 0x20 /* Register: Device ID */ 56#define DEVID 0x20 /* Register: Device ID */
60#define DEVREV 0x22 /* Register: Device Revision */ 57#define DEVREV 0x22 /* Register: Device Revision */
61 58
@@ -77,10 +74,10 @@ static int superio_inw(int reg)
77} 74}
78 75
79static inline void 76static inline void
80superio_select(void) 77superio_select(int ldn)
81{ 78{
82 outb(DEV, REG); 79 outb(DEV, REG);
83 outb(PME, VAL); 80 outb(ldn, VAL);
84} 81}
85 82
86static inline void 83static inline void
@@ -99,20 +96,27 @@ superio_exit(void)
99 outb(0x02, VAL); 96 outb(0x02, VAL);
100} 97}
101 98
99/* Logical device 4 registers */
102#define IT8712F_DEVID 0x8712 100#define IT8712F_DEVID 0x8712
103#define IT8705F_DEVID 0x8705 101#define IT8705F_DEVID 0x8705
102#define IT8716F_DEVID 0x8716
103#define IT8718F_DEVID 0x8718
104#define IT87_ACT_REG 0x30 104#define IT87_ACT_REG 0x30
105#define IT87_BASE_REG 0x60 105#define IT87_BASE_REG 0x60
106 106
107/* Logical device 7 registers (IT8712F and later) */
108#define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
109#define IT87_SIO_VID_REG 0xfc /* VID value */
110
107/* Update battery voltage after every reading if true */ 111/* Update battery voltage after every reading if true */
108static int update_vbat; 112static int update_vbat;
109 113
110/* Not all BIOSes properly configure the PWM registers */ 114/* Not all BIOSes properly configure the PWM registers */
111static int fix_pwm_polarity; 115static int fix_pwm_polarity;
112 116
113/* Chip Type */ 117/* Values read from Super-I/O config space */
114
115static u16 chip_type; 118static u16 chip_type;
119static u8 vid_value;
116 120
117/* Many IT87 constants specified below */ 121/* Many IT87 constants specified below */
118 122
@@ -131,13 +135,21 @@ static u16 chip_type;
131#define IT87_REG_ALARM2 0x02 135#define IT87_REG_ALARM2 0x02
132#define IT87_REG_ALARM3 0x03 136#define IT87_REG_ALARM3 0x03
133 137
138/* The IT8718F has the VID value in a different register, in Super-I/O
139 configuration space. */
134#define IT87_REG_VID 0x0a 140#define IT87_REG_VID 0x0a
141/* Warning: register 0x0b is used for something completely different in
142 new chips/revisions. I suspect only 16-bit tachometer mode will work
143 for these. */
135#define IT87_REG_FAN_DIV 0x0b 144#define IT87_REG_FAN_DIV 0x0b
145#define IT87_REG_FAN_16BIT 0x0c
136 146
137/* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */ 147/* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
138 148
139#define IT87_REG_FAN(nr) (0x0d + (nr)) 149#define IT87_REG_FAN(nr) (0x0d + (nr))
140#define IT87_REG_FAN_MIN(nr) (0x10 + (nr)) 150#define IT87_REG_FAN_MIN(nr) (0x10 + (nr))
151#define IT87_REG_FANX(nr) (0x18 + (nr))
152#define IT87_REG_FANX_MIN(nr) (0x1b + (nr))
141#define IT87_REG_FAN_MAIN_CTRL 0x13 153#define IT87_REG_FAN_MAIN_CTRL 0x13
142#define IT87_REG_FAN_CTL 0x14 154#define IT87_REG_FAN_CTL 0x14
143#define IT87_REG_PWM(nr) (0x15 + (nr)) 155#define IT87_REG_PWM(nr) (0x15 + (nr))
@@ -169,7 +181,16 @@ static inline u8 FAN_TO_REG(long rpm, int div)
169 254); 181 254);
170} 182}
171 183
184static inline u16 FAN16_TO_REG(long rpm)
185{
186 if (rpm == 0)
187 return 0xffff;
188 return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
189}
190
172#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) 191#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
192/* The divider is fixed to 2 in 16-bit mode */
193#define FAN16_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:1350000/((val)*2))
173 194
174#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\ 195#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\
175 ((val)+500)/1000),-128,127)) 196 ((val)+500)/1000),-128,127))
@@ -181,7 +202,7 @@ static inline u8 FAN_TO_REG(long rpm, int div)
181static int DIV_TO_REG(int val) 202static int DIV_TO_REG(int val)
182{ 203{
183 int answer = 0; 204 int answer = 0;
184 while ((val >>= 1) != 0) 205 while (answer < 7 && (val >>= 1))
185 answer++; 206 answer++;
186 return answer; 207 return answer;
187} 208}
@@ -203,10 +224,11 @@ struct it87_data {
203 unsigned long last_updated; /* In jiffies */ 224 unsigned long last_updated; /* In jiffies */
204 225
205 u8 in[9]; /* Register value */ 226 u8 in[9]; /* Register value */
206 u8 in_max[9]; /* Register value */ 227 u8 in_max[8]; /* Register value */
207 u8 in_min[9]; /* Register value */ 228 u8 in_min[8]; /* Register value */
208 u8 fan[3]; /* Register value */ 229 u8 has_fan; /* Bitfield, fans enabled */
209 u8 fan_min[3]; /* Register value */ 230 u16 fan[3]; /* Register values, possibly combined */
231 u16 fan_min[3]; /* Register values, possibly combined */
210 u8 temp[3]; /* Register value */ 232 u8 temp[3]; /* Register value */
211 u8 temp_high[3]; /* Register value */ 233 u8 temp_high[3]; /* Register value */
212 u8 temp_low[3]; /* Register value */ 234 u8 temp_low[3]; /* Register value */
@@ -243,6 +265,7 @@ static struct i2c_driver it87_driver = {
243 265
244static struct i2c_driver it87_isa_driver = { 266static struct i2c_driver it87_isa_driver = {
245 .driver = { 267 .driver = {
268 .owner = THIS_MODULE,
246 .name = "it87-isa", 269 .name = "it87-isa",
247 }, 270 },
248 .attach_adapter = it87_isa_attach_adapter, 271 .attach_adapter = it87_isa_attach_adapter,
@@ -544,15 +567,15 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
544 567
545 struct i2c_client *client = to_i2c_client(dev); 568 struct i2c_client *client = to_i2c_client(dev);
546 struct it87_data *data = i2c_get_clientdata(client); 569 struct it87_data *data = i2c_get_clientdata(client);
547 int val = simple_strtol(buf, NULL, 10); 570 unsigned long val = simple_strtoul(buf, NULL, 10);
548 int i, min[3]; 571 int min;
549 u8 old; 572 u8 old;
550 573
551 mutex_lock(&data->update_lock); 574 mutex_lock(&data->update_lock);
552 old = it87_read_value(client, IT87_REG_FAN_DIV); 575 old = it87_read_value(client, IT87_REG_FAN_DIV);
553 576
554 for (i = 0; i < 3; i++) 577 /* Save fan min limit */
555 min[i] = FAN_FROM_REG(data->fan_min[i], DIV_FROM_REG(data->fan_div[i])); 578 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
556 579
557 switch (nr) { 580 switch (nr) {
558 case 0: 581 case 0:
@@ -572,10 +595,10 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
572 val |= 0x1 << 6; 595 val |= 0x1 << 6;
573 it87_write_value(client, IT87_REG_FAN_DIV, val); 596 it87_write_value(client, IT87_REG_FAN_DIV, val);
574 597
575 for (i = 0; i < 3; i++) { 598 /* Restore fan min limit */
576 data->fan_min[i]=FAN_TO_REG(min[i], DIV_FROM_REG(data->fan_div[i])); 599 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
577 it87_write_value(client, IT87_REG_FAN_MIN(i), data->fan_min[i]); 600 it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]);
578 } 601
579 mutex_unlock(&data->update_lock); 602 mutex_unlock(&data->update_lock);
580 return count; 603 return count;
581} 604}
@@ -656,6 +679,59 @@ show_pwm_offset(1);
656show_pwm_offset(2); 679show_pwm_offset(2);
657show_pwm_offset(3); 680show_pwm_offset(3);
658 681
682/* A different set of callbacks for 16-bit fans */
683static ssize_t show_fan16(struct device *dev, struct device_attribute *attr,
684 char *buf)
685{
686 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
687 int nr = sensor_attr->index;
688 struct it87_data *data = it87_update_device(dev);
689 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan[nr]));
690}
691
692static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr,
693 char *buf)
694{
695 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
696 int nr = sensor_attr->index;
697 struct it87_data *data = it87_update_device(dev);
698 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan_min[nr]));
699}
700
701static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
702 const char *buf, size_t count)
703{
704 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
705 int nr = sensor_attr->index;
706 struct i2c_client *client = to_i2c_client(dev);
707 struct it87_data *data = i2c_get_clientdata(client);
708 int val = simple_strtol(buf, NULL, 10);
709
710 mutex_lock(&data->update_lock);
711 data->fan_min[nr] = FAN16_TO_REG(val);
712 it87_write_value(client, IT87_REG_FAN_MIN(nr),
713 data->fan_min[nr] & 0xff);
714 it87_write_value(client, IT87_REG_FANX_MIN(nr),
715 data->fan_min[nr] >> 8);
716 mutex_unlock(&data->update_lock);
717 return count;
718}
719
720/* We want to use the same sysfs file names as 8-bit fans, but we need
721 different variable names, so we have to use SENSOR_ATTR instead of
722 SENSOR_DEVICE_ATTR. */
723#define show_fan16_offset(offset) \
724static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
725 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
726 show_fan16, NULL, offset - 1); \
727static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
728 = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
729 show_fan16_min, set_fan16_min, offset - 1)
730
731show_fan16_offset(1);
732show_fan16_offset(2);
733show_fan16_offset(3);
734
659/* Alarms */ 735/* Alarms */
660static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 736static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
661{ 737{
@@ -683,8 +759,6 @@ store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf
683 return count; 759 return count;
684} 760}
685static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); 761static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
686#define device_create_file_vrm(client) \
687device_create_file(&client->dev, &dev_attr_vrm)
688 762
689static ssize_t 763static ssize_t
690show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) 764show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
@@ -693,8 +767,88 @@ show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
693 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); 767 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
694} 768}
695static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 769static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
696#define device_create_file_vid(client) \ 770
697device_create_file(&client->dev, &dev_attr_cpu0_vid) 771static struct attribute *it87_attributes[] = {
772 &sensor_dev_attr_in0_input.dev_attr.attr,
773 &sensor_dev_attr_in1_input.dev_attr.attr,
774 &sensor_dev_attr_in2_input.dev_attr.attr,
775 &sensor_dev_attr_in3_input.dev_attr.attr,
776 &sensor_dev_attr_in4_input.dev_attr.attr,
777 &sensor_dev_attr_in5_input.dev_attr.attr,
778 &sensor_dev_attr_in6_input.dev_attr.attr,
779 &sensor_dev_attr_in7_input.dev_attr.attr,
780 &sensor_dev_attr_in8_input.dev_attr.attr,
781 &sensor_dev_attr_in0_min.dev_attr.attr,
782 &sensor_dev_attr_in1_min.dev_attr.attr,
783 &sensor_dev_attr_in2_min.dev_attr.attr,
784 &sensor_dev_attr_in3_min.dev_attr.attr,
785 &sensor_dev_attr_in4_min.dev_attr.attr,
786 &sensor_dev_attr_in5_min.dev_attr.attr,
787 &sensor_dev_attr_in6_min.dev_attr.attr,
788 &sensor_dev_attr_in7_min.dev_attr.attr,
789 &sensor_dev_attr_in0_max.dev_attr.attr,
790 &sensor_dev_attr_in1_max.dev_attr.attr,
791 &sensor_dev_attr_in2_max.dev_attr.attr,
792 &sensor_dev_attr_in3_max.dev_attr.attr,
793 &sensor_dev_attr_in4_max.dev_attr.attr,
794 &sensor_dev_attr_in5_max.dev_attr.attr,
795 &sensor_dev_attr_in6_max.dev_attr.attr,
796 &sensor_dev_attr_in7_max.dev_attr.attr,
797
798 &sensor_dev_attr_temp1_input.dev_attr.attr,
799 &sensor_dev_attr_temp2_input.dev_attr.attr,
800 &sensor_dev_attr_temp3_input.dev_attr.attr,
801 &sensor_dev_attr_temp1_max.dev_attr.attr,
802 &sensor_dev_attr_temp2_max.dev_attr.attr,
803 &sensor_dev_attr_temp3_max.dev_attr.attr,
804 &sensor_dev_attr_temp1_min.dev_attr.attr,
805 &sensor_dev_attr_temp2_min.dev_attr.attr,
806 &sensor_dev_attr_temp3_min.dev_attr.attr,
807 &sensor_dev_attr_temp1_type.dev_attr.attr,
808 &sensor_dev_attr_temp2_type.dev_attr.attr,
809 &sensor_dev_attr_temp3_type.dev_attr.attr,
810
811 &dev_attr_alarms.attr,
812 NULL
813};
814
815static const struct attribute_group it87_group = {
816 .attrs = it87_attributes,
817};
818
819static struct attribute *it87_attributes_opt[] = {
820 &sensor_dev_attr_fan1_input16.dev_attr.attr,
821 &sensor_dev_attr_fan1_min16.dev_attr.attr,
822 &sensor_dev_attr_fan2_input16.dev_attr.attr,
823 &sensor_dev_attr_fan2_min16.dev_attr.attr,
824 &sensor_dev_attr_fan3_input16.dev_attr.attr,
825 &sensor_dev_attr_fan3_min16.dev_attr.attr,
826
827 &sensor_dev_attr_fan1_input.dev_attr.attr,
828 &sensor_dev_attr_fan1_min.dev_attr.attr,
829 &sensor_dev_attr_fan1_div.dev_attr.attr,
830 &sensor_dev_attr_fan2_input.dev_attr.attr,
831 &sensor_dev_attr_fan2_min.dev_attr.attr,
832 &sensor_dev_attr_fan2_div.dev_attr.attr,
833 &sensor_dev_attr_fan3_input.dev_attr.attr,
834 &sensor_dev_attr_fan3_min.dev_attr.attr,
835 &sensor_dev_attr_fan3_div.dev_attr.attr,
836
837 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
838 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
839 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
840 &sensor_dev_attr_pwm1.dev_attr.attr,
841 &sensor_dev_attr_pwm2.dev_attr.attr,
842 &sensor_dev_attr_pwm3.dev_attr.attr,
843
844 &dev_attr_vrm.attr,
845 &dev_attr_cpu0_vid.attr,
846 NULL
847};
848
849static const struct attribute_group it87_group_opt = {
850 .attrs = it87_attributes_opt,
851};
698 852
699/* This function is called when: 853/* This function is called when:
700 * it87_driver is inserted (when this module is loaded), for each 854 * it87_driver is inserted (when this module is loaded), for each
@@ -720,10 +874,12 @@ static int __init it87_find(unsigned short *address)
720 superio_enter(); 874 superio_enter();
721 chip_type = superio_inw(DEVID); 875 chip_type = superio_inw(DEVID);
722 if (chip_type != IT8712F_DEVID 876 if (chip_type != IT8712F_DEVID
877 && chip_type != IT8716F_DEVID
878 && chip_type != IT8718F_DEVID
723 && chip_type != IT8705F_DEVID) 879 && chip_type != IT8705F_DEVID)
724 goto exit; 880 goto exit;
725 881
726 superio_select(); 882 superio_select(PME);
727 if (!(superio_inb(IT87_ACT_REG) & 0x01)) { 883 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
728 pr_info("it87: Device not activated, skipping\n"); 884 pr_info("it87: Device not activated, skipping\n");
729 goto exit; 885 goto exit;
@@ -739,6 +895,21 @@ static int __init it87_find(unsigned short *address)
739 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n", 895 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
740 chip_type, *address, superio_inb(DEVREV) & 0x0f); 896 chip_type, *address, superio_inb(DEVREV) & 0x0f);
741 897
898 /* Read GPIO config and VID value from LDN 7 (GPIO) */
899 if (chip_type != IT8705F_DEVID) {
900 int reg;
901
902 superio_select(GPIO);
903 if (chip_type == it8718)
904 vid_value = superio_inb(IT87_SIO_VID_REG);
905
906 reg = superio_inb(IT87_SIO_PINX2_REG);
907 if (reg & (1 << 0))
908 pr_info("it87: in3 is VCC (+5V)\n");
909 if (reg & (1 << 1))
910 pr_info("it87: in7 is VCCH (+5V Stand-By)\n");
911 }
912
742exit: 913exit:
743 superio_exit(); 914 superio_exit();
744 return err; 915 return err;
@@ -799,8 +970,19 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
799 i = it87_read_value(new_client, IT87_REG_CHIPID); 970 i = it87_read_value(new_client, IT87_REG_CHIPID);
800 if (i == 0x90) { 971 if (i == 0x90) {
801 kind = it87; 972 kind = it87;
802 if ((is_isa) && (chip_type == IT8712F_DEVID)) 973 if (is_isa) {
803 kind = it8712; 974 switch (chip_type) {
975 case IT8712F_DEVID:
976 kind = it8712;
977 break;
978 case IT8716F_DEVID:
979 kind = it8716;
980 break;
981 case IT8718F_DEVID:
982 kind = it8718;
983 break;
984 }
985 }
804 } 986 }
805 else { 987 else {
806 if (kind == 0) 988 if (kind == 0)
@@ -817,6 +999,10 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
817 name = "it87"; 999 name = "it87";
818 } else if (kind == it8712) { 1000 } else if (kind == it8712) {
819 name = "it8712"; 1001 name = "it8712";
1002 } else if (kind == it8716) {
1003 name = "it8716";
1004 } else if (kind == it8718) {
1005 name = "it8718";
820 } 1006 }
821 1007
822 /* Fill in the remaining client fields and put it into the global list */ 1008 /* Fill in the remaining client fields and put it into the global list */
@@ -841,76 +1027,103 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
841 it87_init_client(new_client, data); 1027 it87_init_client(new_client, data);
842 1028
843 /* Register sysfs hooks */ 1029 /* Register sysfs hooks */
844 data->class_dev = hwmon_device_register(&new_client->dev); 1030 if ((err = sysfs_create_group(&new_client->dev.kobj, &it87_group)))
845 if (IS_ERR(data->class_dev)) {
846 err = PTR_ERR(data->class_dev);
847 goto ERROR3; 1031 goto ERROR3;
1032
1033 /* Do not create fan files for disabled fans */
1034 if (data->type == it8716 || data->type == it8718) {
1035 /* 16-bit tachometers */
1036 if (data->has_fan & (1 << 0)) {
1037 if ((err = device_create_file(&new_client->dev,
1038 &sensor_dev_attr_fan1_input16.dev_attr))
1039 || (err = device_create_file(&new_client->dev,
1040 &sensor_dev_attr_fan1_min16.dev_attr)))
1041 goto ERROR4;
1042 }
1043 if (data->has_fan & (1 << 1)) {
1044 if ((err = device_create_file(&new_client->dev,
1045 &sensor_dev_attr_fan2_input16.dev_attr))
1046 || (err = device_create_file(&new_client->dev,
1047 &sensor_dev_attr_fan2_min16.dev_attr)))
1048 goto ERROR4;
1049 }
1050 if (data->has_fan & (1 << 2)) {
1051 if ((err = device_create_file(&new_client->dev,
1052 &sensor_dev_attr_fan3_input16.dev_attr))
1053 || (err = device_create_file(&new_client->dev,
1054 &sensor_dev_attr_fan3_min16.dev_attr)))
1055 goto ERROR4;
1056 }
1057 } else {
1058 /* 8-bit tachometers with clock divider */
1059 if (data->has_fan & (1 << 0)) {
1060 if ((err = device_create_file(&new_client->dev,
1061 &sensor_dev_attr_fan1_input.dev_attr))
1062 || (err = device_create_file(&new_client->dev,
1063 &sensor_dev_attr_fan1_min.dev_attr))
1064 || (err = device_create_file(&new_client->dev,
1065 &sensor_dev_attr_fan1_div.dev_attr)))
1066 goto ERROR4;
1067 }
1068 if (data->has_fan & (1 << 1)) {
1069 if ((err = device_create_file(&new_client->dev,
1070 &sensor_dev_attr_fan2_input.dev_attr))
1071 || (err = device_create_file(&new_client->dev,
1072 &sensor_dev_attr_fan2_min.dev_attr))
1073 || (err = device_create_file(&new_client->dev,
1074 &sensor_dev_attr_fan2_div.dev_attr)))
1075 goto ERROR4;
1076 }
1077 if (data->has_fan & (1 << 2)) {
1078 if ((err = device_create_file(&new_client->dev,
1079 &sensor_dev_attr_fan3_input.dev_attr))
1080 || (err = device_create_file(&new_client->dev,
1081 &sensor_dev_attr_fan3_min.dev_attr))
1082 || (err = device_create_file(&new_client->dev,
1083 &sensor_dev_attr_fan3_div.dev_attr)))
1084 goto ERROR4;
1085 }
848 } 1086 }
849 1087
850 device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr);
851 device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr);
852 device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr);
853 device_create_file(&new_client->dev, &sensor_dev_attr_in3_input.dev_attr);
854 device_create_file(&new_client->dev, &sensor_dev_attr_in4_input.dev_attr);
855 device_create_file(&new_client->dev, &sensor_dev_attr_in5_input.dev_attr);
856 device_create_file(&new_client->dev, &sensor_dev_attr_in6_input.dev_attr);
857 device_create_file(&new_client->dev, &sensor_dev_attr_in7_input.dev_attr);
858 device_create_file(&new_client->dev, &sensor_dev_attr_in8_input.dev_attr);
859 device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr);
860 device_create_file(&new_client->dev, &sensor_dev_attr_in1_min.dev_attr);
861 device_create_file(&new_client->dev, &sensor_dev_attr_in2_min.dev_attr);
862 device_create_file(&new_client->dev, &sensor_dev_attr_in3_min.dev_attr);
863 device_create_file(&new_client->dev, &sensor_dev_attr_in4_min.dev_attr);
864 device_create_file(&new_client->dev, &sensor_dev_attr_in5_min.dev_attr);
865 device_create_file(&new_client->dev, &sensor_dev_attr_in6_min.dev_attr);
866 device_create_file(&new_client->dev, &sensor_dev_attr_in7_min.dev_attr);
867 device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr);
868 device_create_file(&new_client->dev, &sensor_dev_attr_in1_max.dev_attr);
869 device_create_file(&new_client->dev, &sensor_dev_attr_in2_max.dev_attr);
870 device_create_file(&new_client->dev, &sensor_dev_attr_in3_max.dev_attr);
871 device_create_file(&new_client->dev, &sensor_dev_attr_in4_max.dev_attr);
872 device_create_file(&new_client->dev, &sensor_dev_attr_in5_max.dev_attr);
873 device_create_file(&new_client->dev, &sensor_dev_attr_in6_max.dev_attr);
874 device_create_file(&new_client->dev, &sensor_dev_attr_in7_max.dev_attr);
875 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr);
876 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_input.dev_attr);
877 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_input.dev_attr);
878 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_max.dev_attr);
879 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_max.dev_attr);
880 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_max.dev_attr);
881 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_min.dev_attr);
882 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_min.dev_attr);
883 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_min.dev_attr);
884 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_type.dev_attr);
885 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_type.dev_attr);
886 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_type.dev_attr);
887 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_input.dev_attr);
888 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_input.dev_attr);
889 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_input.dev_attr);
890 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_min.dev_attr);
891 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_min.dev_attr);
892 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_min.dev_attr);
893 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_div.dev_attr);
894 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_div.dev_attr);
895 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_div.dev_attr);
896 device_create_file(&new_client->dev, &dev_attr_alarms);
897 if (enable_pwm_interface) { 1088 if (enable_pwm_interface) {
898 device_create_file(&new_client->dev, &sensor_dev_attr_pwm1_enable.dev_attr); 1089 if ((err = device_create_file(&new_client->dev,
899 device_create_file(&new_client->dev, &sensor_dev_attr_pwm2_enable.dev_attr); 1090 &sensor_dev_attr_pwm1_enable.dev_attr))
900 device_create_file(&new_client->dev, &sensor_dev_attr_pwm3_enable.dev_attr); 1091 || (err = device_create_file(&new_client->dev,
901 device_create_file(&new_client->dev, &sensor_dev_attr_pwm1.dev_attr); 1092 &sensor_dev_attr_pwm2_enable.dev_attr))
902 device_create_file(&new_client->dev, &sensor_dev_attr_pwm2.dev_attr); 1093 || (err = device_create_file(&new_client->dev,
903 device_create_file(&new_client->dev, &sensor_dev_attr_pwm3.dev_attr); 1094 &sensor_dev_attr_pwm3_enable.dev_attr))
1095 || (err = device_create_file(&new_client->dev,
1096 &sensor_dev_attr_pwm1.dev_attr))
1097 || (err = device_create_file(&new_client->dev,
1098 &sensor_dev_attr_pwm2.dev_attr))
1099 || (err = device_create_file(&new_client->dev,
1100 &sensor_dev_attr_pwm3.dev_attr)))
1101 goto ERROR4;
904 } 1102 }
905 1103
906 if (data->type == it8712) { 1104 if (data->type == it8712 || data->type == it8716
1105 || data->type == it8718) {
907 data->vrm = vid_which_vrm(); 1106 data->vrm = vid_which_vrm();
908 device_create_file_vrm(new_client); 1107 /* VID reading from Super-I/O config space if available */
909 device_create_file_vid(new_client); 1108 data->vid = vid_value;
1109 if ((err = device_create_file(&new_client->dev,
1110 &dev_attr_vrm))
1111 || (err = device_create_file(&new_client->dev,
1112 &dev_attr_cpu0_vid)))
1113 goto ERROR4;
1114 }
1115
1116 data->class_dev = hwmon_device_register(&new_client->dev);
1117 if (IS_ERR(data->class_dev)) {
1118 err = PTR_ERR(data->class_dev);
1119 goto ERROR4;
910 } 1120 }
911 1121
912 return 0; 1122 return 0;
913 1123
1124ERROR4:
1125 sysfs_remove_group(&new_client->dev.kobj, &it87_group);
1126 sysfs_remove_group(&new_client->dev.kobj, &it87_group_opt);
914ERROR3: 1127ERROR3:
915 i2c_detach_client(new_client); 1128 i2c_detach_client(new_client);
916ERROR2: 1129ERROR2:
@@ -928,6 +1141,8 @@ static int it87_detach_client(struct i2c_client *client)
928 int err; 1141 int err;
929 1142
930 hwmon_device_unregister(data->class_dev); 1143 hwmon_device_unregister(data->class_dev);
1144 sysfs_remove_group(&client->dev.kobj, &it87_group);
1145 sysfs_remove_group(&client->dev.kobj, &it87_group_opt);
931 1146
932 if ((err = i2c_detach_client(client))) 1147 if ((err = i2c_detach_client(client)))
933 return err; 1148 return err;
@@ -1044,6 +1259,22 @@ static void it87_init_client(struct i2c_client *client, struct it87_data *data)
1044 data->manual_pwm_ctl[i] = 0xff; 1259 data->manual_pwm_ctl[i] = 0xff;
1045 } 1260 }
1046 1261
1262 /* Some chips seem to have default value 0xff for all limit
1263 * registers. For low voltage limits it makes no sense and triggers
1264 * alarms, so change to 0 instead. For high temperature limits, it
1265 * means -1 degree C, which surprisingly doesn't trigger an alarm,
1266 * but is still confusing, so change to 127 degrees C. */
1267 for (i = 0; i < 8; i++) {
1268 tmp = it87_read_value(client, IT87_REG_VIN_MIN(i));
1269 if (tmp == 0xff)
1270 it87_write_value(client, IT87_REG_VIN_MIN(i), 0);
1271 }
1272 for (i = 0; i < 3; i++) {
1273 tmp = it87_read_value(client, IT87_REG_TEMP_HIGH(i));
1274 if (tmp == 0xff)
1275 it87_write_value(client, IT87_REG_TEMP_HIGH(i), 127);
1276 }
1277
1047 /* Check if temperature channnels are reset manually or by some reason */ 1278 /* Check if temperature channnels are reset manually or by some reason */
1048 tmp = it87_read_value(client, IT87_REG_TEMP_ENABLE); 1279 tmp = it87_read_value(client, IT87_REG_TEMP_ENABLE);
1049 if ((tmp & 0x3f) == 0) { 1280 if ((tmp & 0x3f) == 0) {
@@ -1067,6 +1298,18 @@ static void it87_init_client(struct i2c_client *client, struct it87_data *data)
1067 data->fan_main_ctrl |= 0x70; 1298 data->fan_main_ctrl |= 0x70;
1068 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 1299 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
1069 } 1300 }
1301 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
1302
1303 /* Set tachometers to 16-bit mode if needed */
1304 if (data->type == it8716 || data->type == it8718) {
1305 tmp = it87_read_value(client, IT87_REG_FAN_16BIT);
1306 if (~tmp & 0x07 & data->has_fan) {
1307 dev_dbg(&client->dev,
1308 "Setting fan1-3 to 16-bit mode\n");
1309 it87_write_value(client, IT87_REG_FAN_16BIT,
1310 tmp | 0x07);
1311 }
1312 }
1070 1313
1071 /* Set current fan mode registers and the default settings for the 1314 /* Set current fan mode registers and the default settings for the
1072 * other mode registers */ 1315 * other mode registers */
@@ -1117,18 +1360,26 @@ static struct it87_data *it87_update_device(struct device *dev)
1117 data->in_max[i] = 1360 data->in_max[i] =
1118 it87_read_value(client, IT87_REG_VIN_MAX(i)); 1361 it87_read_value(client, IT87_REG_VIN_MAX(i));
1119 } 1362 }
1363 /* in8 (battery) has no limit registers */
1120 data->in[8] = 1364 data->in[8] =
1121 it87_read_value(client, IT87_REG_VIN(8)); 1365 it87_read_value(client, IT87_REG_VIN(8));
1122 /* Temperature sensor doesn't have limit registers, set
1123 to min and max value */
1124 data->in_min[8] = 0;
1125 data->in_max[8] = 255;
1126 1366
1127 for (i = 0; i < 3; i++) { 1367 for (i = 0; i < 3; i++) {
1128 data->fan[i] = 1368 /* Skip disabled fans */
1129 it87_read_value(client, IT87_REG_FAN(i)); 1369 if (!(data->has_fan & (1 << i)))
1370 continue;
1371
1130 data->fan_min[i] = 1372 data->fan_min[i] =
1131 it87_read_value(client, IT87_REG_FAN_MIN(i)); 1373 it87_read_value(client, IT87_REG_FAN_MIN(i));
1374 data->fan[i] = it87_read_value(client,
1375 IT87_REG_FAN(i));
1376 /* Add high byte if in 16-bit mode */
1377 if (data->type == it8716 || data->type == it8718) {
1378 data->fan[i] |= it87_read_value(client,
1379 IT87_REG_FANX(i)) << 8;
1380 data->fan_min[i] |= it87_read_value(client,
1381 IT87_REG_FANX_MIN(i)) << 8;
1382 }
1132 } 1383 }
1133 for (i = 0; i < 3; i++) { 1384 for (i = 0; i < 3; i++) {
1134 data->temp[i] = 1385 data->temp[i] =
@@ -1139,10 +1390,14 @@ static struct it87_data *it87_update_device(struct device *dev)
1139 it87_read_value(client, IT87_REG_TEMP_LOW(i)); 1390 it87_read_value(client, IT87_REG_TEMP_LOW(i));
1140 } 1391 }
1141 1392
1142 i = it87_read_value(client, IT87_REG_FAN_DIV); 1393 /* Newer chips don't have clock dividers */
1143 data->fan_div[0] = i & 0x07; 1394 if ((data->has_fan & 0x07) && data->type != it8716
1144 data->fan_div[1] = (i >> 3) & 0x07; 1395 && data->type != it8718) {
1145 data->fan_div[2] = (i & 0x40) ? 3 : 1; 1396 i = it87_read_value(client, IT87_REG_FAN_DIV);
1397 data->fan_div[0] = i & 0x07;
1398 data->fan_div[1] = (i >> 3) & 0x07;
1399 data->fan_div[2] = (i & 0x40) ? 3 : 1;
1400 }
1146 1401
1147 data->alarms = 1402 data->alarms =
1148 it87_read_value(client, IT87_REG_ALARM1) | 1403 it87_read_value(client, IT87_REG_ALARM1) |
@@ -1152,9 +1407,11 @@ static struct it87_data *it87_update_device(struct device *dev)
1152 1407
1153 data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE); 1408 data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE);
1154 /* The 8705 does not have VID capability */ 1409 /* The 8705 does not have VID capability */
1155 if (data->type == it8712) { 1410 if (data->type == it8712 || data->type == it8716) {
1156 data->vid = it87_read_value(client, IT87_REG_VID); 1411 data->vid = it87_read_value(client, IT87_REG_VID);
1157 data->vid &= 0x1f; 1412 /* The older IT8712F revisions had only 5 VID pins,
1413 but we assume it is always safe to read 6 bits. */
1414 data->vid &= 0x3f;
1158 } 1415 }
1159 data->last_updated = jiffies; 1416 data->last_updated = jiffies;
1160 data->valid = 1; 1417 data->valid = 1;
@@ -1192,8 +1449,9 @@ static void __exit sm_it87_exit(void)
1192} 1449}
1193 1450
1194 1451
1195MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>"); 1452MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>, "
1196MODULE_DESCRIPTION("IT8705F, IT8712F, Sis950 driver"); 1453 "Jean Delvare <khali@linux-fr.org>");
1454MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F, SiS950 driver");
1197module_param(update_vbat, bool, 0); 1455module_param(update_vbat, bool, 0);
1198MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); 1456MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
1199module_param(fix_pwm_polarity, bool, 0); 1457module_param(fix_pwm_polarity, bool, 0);
diff --git a/drivers/hwmon/k8temp.c b/drivers/hwmon/k8temp.c
new file mode 100644
index 000000000000..f58b64ed09e3
--- /dev/null
+++ b/drivers/hwmon/k8temp.c
@@ -0,0 +1,294 @@
1/*
2 * k8temp.c - Linux kernel module for hardware monitoring
3 *
4 * Copyright (C) 2006 Rudolf Marek <r.marek@sh.cvut.cz>
5 *
6 * Inspired from the w83785 and amd756 drivers.
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., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301 USA.
22 */
23
24#include <linux/module.h>
25#include <linux/delay.h>
26#include <linux/init.h>
27#include <linux/slab.h>
28#include <linux/jiffies.h>
29#include <linux/pci.h>
30#include <linux/hwmon.h>
31#include <linux/hwmon-sysfs.h>
32#include <linux/err.h>
33#include <linux/mutex.h>
34
35#define TEMP_FROM_REG(val) (((((val) >> 16) & 0xff) - 49) * 1000)
36#define REG_TEMP 0xe4
37#define SEL_PLACE 0x40
38#define SEL_CORE 0x04
39
40struct k8temp_data {
41 struct class_device *class_dev;
42 struct mutex update_lock;
43 const char *name;
44 char valid; /* zero until following fields are valid */
45 unsigned long last_updated; /* in jiffies */
46
47 /* registers values */
48 u8 sensorsp; /* sensor presence bits - SEL_CORE & SEL_PLACE */
49 u32 temp[2][2]; /* core, place */
50};
51
52static struct k8temp_data *k8temp_update_device(struct device *dev)
53{
54 struct k8temp_data *data = dev_get_drvdata(dev);
55 struct pci_dev *pdev = to_pci_dev(dev);
56 u8 tmp;
57
58 mutex_lock(&data->update_lock);
59
60 if (!data->valid
61 || time_after(jiffies, data->last_updated + HZ)) {
62 pci_read_config_byte(pdev, REG_TEMP, &tmp);
63 tmp &= ~(SEL_PLACE | SEL_CORE); /* Select sensor 0, core0 */
64 pci_write_config_byte(pdev, REG_TEMP, tmp);
65 pci_read_config_dword(pdev, REG_TEMP, &data->temp[0][0]);
66
67 if (data->sensorsp & SEL_PLACE) {
68 tmp |= SEL_PLACE; /* Select sensor 1, core0 */
69 pci_write_config_byte(pdev, REG_TEMP, tmp);
70 pci_read_config_dword(pdev, REG_TEMP,
71 &data->temp[0][1]);
72 }
73
74 if (data->sensorsp & SEL_CORE) {
75 tmp &= ~SEL_PLACE; /* Select sensor 0, core1 */
76 tmp |= SEL_CORE;
77 pci_write_config_byte(pdev, REG_TEMP, tmp);
78 pci_read_config_dword(pdev, REG_TEMP,
79 &data->temp[1][0]);
80
81 if (data->sensorsp & SEL_PLACE) {
82 tmp |= SEL_PLACE; /* Select sensor 1, core1 */
83 pci_write_config_byte(pdev, REG_TEMP, tmp);
84 pci_read_config_dword(pdev, REG_TEMP,
85 &data->temp[1][1]);
86 }
87 }
88
89 data->last_updated = jiffies;
90 data->valid = 1;
91 }
92
93 mutex_unlock(&data->update_lock);
94 return data;
95}
96
97/*
98 * Sysfs stuff
99 */
100
101static ssize_t show_name(struct device *dev, struct device_attribute
102 *devattr, char *buf)
103{
104 struct k8temp_data *data = dev_get_drvdata(dev);
105
106 return sprintf(buf, "%s\n", data->name);
107}
108
109
110static ssize_t show_temp(struct device *dev,
111 struct device_attribute *devattr, char *buf)
112{
113 struct sensor_device_attribute_2 *attr =
114 to_sensor_dev_attr_2(devattr);
115 int core = attr->nr;
116 int place = attr->index;
117 struct k8temp_data *data = k8temp_update_device(dev);
118
119 return sprintf(buf, "%d\n",
120 TEMP_FROM_REG(data->temp[core][place]));
121}
122
123/* core, place */
124
125static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0);
126static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1);
127static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 1, 0);
128static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 1, 1);
129static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
130
131static struct pci_device_id k8temp_ids[] = {
132 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) },
133 { 0 },
134};
135
136MODULE_DEVICE_TABLE(pci, k8temp_ids);
137
138static int __devinit k8temp_probe(struct pci_dev *pdev,
139 const struct pci_device_id *id)
140{
141 int err;
142 u8 scfg;
143 u32 temp;
144 struct k8temp_data *data;
145 u32 cpuid = cpuid_eax(1);
146
147 /* this feature should be available since SH-C0 core */
148 if ((cpuid == 0xf40) || (cpuid == 0xf50) || (cpuid == 0xf51)) {
149 err = -ENODEV;
150 goto exit;
151 }
152
153 if (!(data = kzalloc(sizeof(struct k8temp_data), GFP_KERNEL))) {
154 err = -ENOMEM;
155 goto exit;
156 }
157
158 pci_read_config_byte(pdev, REG_TEMP, &scfg);
159 scfg &= ~(SEL_PLACE | SEL_CORE); /* Select sensor 0, core0 */
160 pci_write_config_byte(pdev, REG_TEMP, scfg);
161 pci_read_config_byte(pdev, REG_TEMP, &scfg);
162
163 if (scfg & (SEL_PLACE | SEL_CORE)) {
164 dev_err(&pdev->dev, "Configuration bit(s) stuck at 1!\n");
165 err = -ENODEV;
166 goto exit_free;
167 }
168
169 scfg |= (SEL_PLACE | SEL_CORE);
170 pci_write_config_byte(pdev, REG_TEMP, scfg);
171
172 /* now we know if we can change core and/or sensor */
173 pci_read_config_byte(pdev, REG_TEMP, &data->sensorsp);
174
175 if (data->sensorsp & SEL_PLACE) {
176 scfg &= ~SEL_CORE; /* Select sensor 1, core0 */
177 pci_write_config_byte(pdev, REG_TEMP, scfg);
178 pci_read_config_dword(pdev, REG_TEMP, &temp);
179 scfg |= SEL_CORE; /* prepare for next selection */
180 if (!((temp >> 16) & 0xff)) /* if temp is 0 -49C is not likely */
181 data->sensorsp &= ~SEL_PLACE;
182 }
183
184 if (data->sensorsp & SEL_CORE) {
185 scfg &= ~SEL_PLACE; /* Select sensor 0, core1 */
186 pci_write_config_byte(pdev, REG_TEMP, scfg);
187 pci_read_config_dword(pdev, REG_TEMP, &temp);
188 if (!((temp >> 16) & 0xff)) /* if temp is 0 -49C is not likely */
189 data->sensorsp &= ~SEL_CORE;
190 }
191
192 data->name = "k8temp";
193 mutex_init(&data->update_lock);
194 dev_set_drvdata(&pdev->dev, data);
195
196 /* Register sysfs hooks */
197 err = device_create_file(&pdev->dev,
198 &sensor_dev_attr_temp1_input.dev_attr);
199 if (err)
200 goto exit_remove;
201
202 /* sensor can be changed and reports something */
203 if (data->sensorsp & SEL_PLACE) {
204 err = device_create_file(&pdev->dev,
205 &sensor_dev_attr_temp2_input.dev_attr);
206 if (err)
207 goto exit_remove;
208 }
209
210 /* core can be changed and reports something */
211 if (data->sensorsp & SEL_CORE) {
212 err = device_create_file(&pdev->dev,
213 &sensor_dev_attr_temp3_input.dev_attr);
214 if (err)
215 goto exit_remove;
216 if (data->sensorsp & SEL_PLACE)
217 err = device_create_file(&pdev->dev,
218 &sensor_dev_attr_temp4_input.
219 dev_attr);
220 if (err)
221 goto exit_remove;
222 }
223
224 err = device_create_file(&pdev->dev, &dev_attr_name);
225 if (err)
226 goto exit_remove;
227
228 data->class_dev = hwmon_device_register(&pdev->dev);
229
230 if (IS_ERR(data->class_dev)) {
231 err = PTR_ERR(data->class_dev);
232 goto exit_remove;
233 }
234
235 return 0;
236
237exit_remove:
238 device_remove_file(&pdev->dev,
239 &sensor_dev_attr_temp1_input.dev_attr);
240 device_remove_file(&pdev->dev,
241 &sensor_dev_attr_temp2_input.dev_attr);
242 device_remove_file(&pdev->dev,
243 &sensor_dev_attr_temp3_input.dev_attr);
244 device_remove_file(&pdev->dev,
245 &sensor_dev_attr_temp4_input.dev_attr);
246 device_remove_file(&pdev->dev, &dev_attr_name);
247exit_free:
248 dev_set_drvdata(&pdev->dev, NULL);
249 kfree(data);
250exit:
251 return err;
252}
253
254static void __devexit k8temp_remove(struct pci_dev *pdev)
255{
256 struct k8temp_data *data = dev_get_drvdata(&pdev->dev);
257
258 hwmon_device_unregister(data->class_dev);
259 device_remove_file(&pdev->dev,
260 &sensor_dev_attr_temp1_input.dev_attr);
261 device_remove_file(&pdev->dev,
262 &sensor_dev_attr_temp2_input.dev_attr);
263 device_remove_file(&pdev->dev,
264 &sensor_dev_attr_temp3_input.dev_attr);
265 device_remove_file(&pdev->dev,
266 &sensor_dev_attr_temp4_input.dev_attr);
267 device_remove_file(&pdev->dev, &dev_attr_name);
268 dev_set_drvdata(&pdev->dev, NULL);
269 kfree(data);
270}
271
272static struct pci_driver k8temp_driver = {
273 .name = "k8temp",
274 .id_table = k8temp_ids,
275 .probe = k8temp_probe,
276 .remove = __devexit_p(k8temp_remove),
277};
278
279static int __init k8temp_init(void)
280{
281 return pci_register_driver(&k8temp_driver);
282}
283
284static void __exit k8temp_exit(void)
285{
286 pci_unregister_driver(&k8temp_driver);
287}
288
289MODULE_AUTHOR("Rudolf Marek <r.marek@sh.cvut.cz>");
290MODULE_DESCRIPTION("AMD K8 core temperature monitor");
291MODULE_LICENSE("GPL");
292
293module_init(k8temp_init)
294module_exit(k8temp_exit)
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c
index 071f0fc6adec..d69f3cf07122 100644
--- a/drivers/hwmon/lm63.c
+++ b/drivers/hwmon/lm63.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * lm63.c - driver for the National Semiconductor LM63 temperature sensor 2 * lm63.c - driver for the National Semiconductor LM63 temperature sensor
3 * with integrated fan control 3 * with integrated fan control
4 * Copyright (C) 2004-2005 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2004-2006 Jean Delvare <khali@linux-fr.org>
5 * Based on the lm90 driver. 5 * Based on the lm90 driver.
6 * 6 *
7 * The LM63 is a sensor chip made by National Semiconductor. It measures 7 * The LM63 is a sensor chip made by National Semiconductor. It measures
@@ -46,6 +46,7 @@
46#include <linux/hwmon.h> 46#include <linux/hwmon.h>
47#include <linux/err.h> 47#include <linux/err.h>
48#include <linux/mutex.h> 48#include <linux/mutex.h>
49#include <linux/sysfs.h>
49 50
50/* 51/*
51 * Addresses to scan 52 * Addresses to scan
@@ -330,6 +331,16 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy,
330 return sprintf(buf, "%u\n", data->alarms); 331 return sprintf(buf, "%u\n", data->alarms);
331} 332}
332 333
334static ssize_t show_alarm(struct device *dev, struct device_attribute *devattr,
335 char *buf)
336{
337 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
338 struct lm63_data *data = lm63_update_device(dev);
339 int bitnr = attr->index;
340
341 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
342}
343
333static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); 344static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
334static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan, 345static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan,
335 set_fan, 1); 346 set_fan, 1);
@@ -350,8 +361,52 @@ static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp8, NULL, 2);
350static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst, 361static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst,
351 set_temp2_crit_hyst); 362 set_temp2_crit_hyst);
352 363
364/* Individual alarm files */
365static SENSOR_DEVICE_ATTR(fan1_min_alarm, S_IRUGO, show_alarm, NULL, 0);
366static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1);
367static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 2);
368static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3);
369static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4);
370static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
371/* Raw alarm file for compatibility */
353static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 372static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
354 373
374static struct attribute *lm63_attributes[] = {
375 &dev_attr_pwm1.attr,
376 &dev_attr_pwm1_enable.attr,
377 &sensor_dev_attr_temp1_input.dev_attr.attr,
378 &sensor_dev_attr_temp2_input.dev_attr.attr,
379 &sensor_dev_attr_temp2_min.dev_attr.attr,
380 &sensor_dev_attr_temp1_max.dev_attr.attr,
381 &sensor_dev_attr_temp2_max.dev_attr.attr,
382 &sensor_dev_attr_temp2_crit.dev_attr.attr,
383 &dev_attr_temp2_crit_hyst.attr,
384
385 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
386 &sensor_dev_attr_temp2_input_fault.dev_attr.attr,
387 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
388 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
389 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
390 &dev_attr_alarms.attr,
391 NULL
392};
393
394static const struct attribute_group lm63_group = {
395 .attrs = lm63_attributes,
396};
397
398static struct attribute *lm63_attributes_fan1[] = {
399 &sensor_dev_attr_fan1_input.dev_attr.attr,
400 &sensor_dev_attr_fan1_min.dev_attr.attr,
401
402 &sensor_dev_attr_fan1_min_alarm.dev_attr.attr,
403 NULL
404};
405
406static const struct attribute_group lm63_group_fan1 = {
407 .attrs = lm63_attributes_fan1,
408};
409
355/* 410/*
356 * Real code 411 * Real code
357 */ 412 */
@@ -438,37 +493,26 @@ static int lm63_detect(struct i2c_adapter *adapter, int address, int kind)
438 lm63_init_client(new_client); 493 lm63_init_client(new_client);
439 494
440 /* Register sysfs hooks */ 495 /* Register sysfs hooks */
441 data->class_dev = hwmon_device_register(&new_client->dev); 496 if ((err = sysfs_create_group(&new_client->dev.kobj,
442 if (IS_ERR(data->class_dev)) { 497 &lm63_group)))
443 err = PTR_ERR(data->class_dev);
444 goto exit_detach; 498 goto exit_detach;
499 if (data->config & 0x04) { /* tachometer enabled */
500 if ((err = sysfs_create_group(&new_client->dev.kobj,
501 &lm63_group_fan1)))
502 goto exit_remove_files;
445 } 503 }
446 504
447 if (data->config & 0x04) { /* tachometer enabled */ 505 data->class_dev = hwmon_device_register(&new_client->dev);
448 device_create_file(&new_client->dev, 506 if (IS_ERR(data->class_dev)) {
449 &sensor_dev_attr_fan1_input.dev_attr); 507 err = PTR_ERR(data->class_dev);
450 device_create_file(&new_client->dev, 508 goto exit_remove_files;
451 &sensor_dev_attr_fan1_min.dev_attr);
452 } 509 }
453 device_create_file(&new_client->dev, &dev_attr_pwm1);
454 device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
455 device_create_file(&new_client->dev,
456 &sensor_dev_attr_temp1_input.dev_attr);
457 device_create_file(&new_client->dev,
458 &sensor_dev_attr_temp2_input.dev_attr);
459 device_create_file(&new_client->dev,
460 &sensor_dev_attr_temp2_min.dev_attr);
461 device_create_file(&new_client->dev,
462 &sensor_dev_attr_temp1_max.dev_attr);
463 device_create_file(&new_client->dev,
464 &sensor_dev_attr_temp2_max.dev_attr);
465 device_create_file(&new_client->dev,
466 &sensor_dev_attr_temp2_crit.dev_attr);
467 device_create_file(&new_client->dev, &dev_attr_temp2_crit_hyst);
468 device_create_file(&new_client->dev, &dev_attr_alarms);
469 510
470 return 0; 511 return 0;
471 512
513exit_remove_files:
514 sysfs_remove_group(&new_client->dev.kobj, &lm63_group);
515 sysfs_remove_group(&new_client->dev.kobj, &lm63_group_fan1);
472exit_detach: 516exit_detach:
473 i2c_detach_client(new_client); 517 i2c_detach_client(new_client);
474exit_free: 518exit_free:
@@ -518,6 +562,8 @@ static int lm63_detach_client(struct i2c_client *client)
518 int err; 562 int err;
519 563
520 hwmon_device_unregister(data->class_dev); 564 hwmon_device_unregister(data->class_dev);
565 sysfs_remove_group(&client->dev.kobj, &lm63_group);
566 sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1);
521 567
522 if ((err = i2c_detach_client(client))) 568 if ((err = i2c_detach_client(client)))
523 return err; 569 return err;
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index fc25b90ec24a..7c65b8bb6d72 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -112,6 +112,18 @@ static int lm75_attach_adapter(struct i2c_adapter *adapter)
112 return i2c_probe(adapter, &addr_data, lm75_detect); 112 return i2c_probe(adapter, &addr_data, lm75_detect);
113} 113}
114 114
115static struct attribute *lm75_attributes[] = {
116 &dev_attr_temp1_input.attr,
117 &dev_attr_temp1_max.attr,
118 &dev_attr_temp1_max_hyst.attr,
119
120 NULL
121};
122
123static const struct attribute_group lm75_group = {
124 .attrs = lm75_attributes,
125};
126
115/* This function is called by i2c_probe */ 127/* This function is called by i2c_probe */
116static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) 128static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
117{ 129{
@@ -199,18 +211,19 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
199 lm75_init_client(new_client); 211 lm75_init_client(new_client);
200 212
201 /* Register sysfs hooks */ 213 /* Register sysfs hooks */
214 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm75_group)))
215 goto exit_detach;
216
202 data->class_dev = hwmon_device_register(&new_client->dev); 217 data->class_dev = hwmon_device_register(&new_client->dev);
203 if (IS_ERR(data->class_dev)) { 218 if (IS_ERR(data->class_dev)) {
204 err = PTR_ERR(data->class_dev); 219 err = PTR_ERR(data->class_dev);
205 goto exit_detach; 220 goto exit_remove;
206 } 221 }
207 222
208 device_create_file(&new_client->dev, &dev_attr_temp1_max);
209 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
210 device_create_file(&new_client->dev, &dev_attr_temp1_input);
211
212 return 0; 223 return 0;
213 224
225exit_remove:
226 sysfs_remove_group(&new_client->dev.kobj, &lm75_group);
214exit_detach: 227exit_detach:
215 i2c_detach_client(new_client); 228 i2c_detach_client(new_client);
216exit_free: 229exit_free:
@@ -223,6 +236,7 @@ static int lm75_detach_client(struct i2c_client *client)
223{ 236{
224 struct lm75_data *data = i2c_get_clientdata(client); 237 struct lm75_data *data = i2c_get_clientdata(client);
225 hwmon_device_unregister(data->class_dev); 238 hwmon_device_unregister(data->class_dev);
239 sysfs_remove_group(&client->dev.kobj, &lm75_group);
226 i2c_detach_client(client); 240 i2c_detach_client(client);
227 kfree(data); 241 kfree(data);
228 return 0; 242 return 0;
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c
index 459cc977380a..dd969f1e8415 100644
--- a/drivers/hwmon/lm77.c
+++ b/drivers/hwmon/lm77.c
@@ -212,6 +212,23 @@ static int lm77_attach_adapter(struct i2c_adapter *adapter)
212 return i2c_probe(adapter, &addr_data, lm77_detect); 212 return i2c_probe(adapter, &addr_data, lm77_detect);
213} 213}
214 214
215static struct attribute *lm77_attributes[] = {
216 &dev_attr_temp1_input.attr,
217 &dev_attr_temp1_crit.attr,
218 &dev_attr_temp1_min.attr,
219 &dev_attr_temp1_max.attr,
220 &dev_attr_temp1_crit_hyst.attr,
221 &dev_attr_temp1_min_hyst.attr,
222 &dev_attr_temp1_max_hyst.attr,
223 &dev_attr_alarms.attr,
224
225 NULL
226};
227
228static const struct attribute_group lm77_group = {
229 .attrs = lm77_attributes,
230};
231
215/* This function is called by i2c_probe */ 232/* This function is called by i2c_probe */
216static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) 233static int lm77_detect(struct i2c_adapter *adapter, int address, int kind)
217{ 234{
@@ -317,22 +334,19 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind)
317 lm77_init_client(new_client); 334 lm77_init_client(new_client);
318 335
319 /* Register sysfs hooks */ 336 /* Register sysfs hooks */
337 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm77_group)))
338 goto exit_detach;
339
320 data->class_dev = hwmon_device_register(&new_client->dev); 340 data->class_dev = hwmon_device_register(&new_client->dev);
321 if (IS_ERR(data->class_dev)) { 341 if (IS_ERR(data->class_dev)) {
322 err = PTR_ERR(data->class_dev); 342 err = PTR_ERR(data->class_dev);
323 goto exit_detach; 343 goto exit_remove;
324 } 344 }
325 345
326 device_create_file(&new_client->dev, &dev_attr_temp1_input);
327 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
328 device_create_file(&new_client->dev, &dev_attr_temp1_min);
329 device_create_file(&new_client->dev, &dev_attr_temp1_max);
330 device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst);
331 device_create_file(&new_client->dev, &dev_attr_temp1_min_hyst);
332 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
333 device_create_file(&new_client->dev, &dev_attr_alarms);
334 return 0; 346 return 0;
335 347
348exit_remove:
349 sysfs_remove_group(&new_client->dev.kobj, &lm77_group);
336exit_detach: 350exit_detach:
337 i2c_detach_client(new_client); 351 i2c_detach_client(new_client);
338exit_free: 352exit_free:
@@ -345,6 +359,7 @@ static int lm77_detach_client(struct i2c_client *client)
345{ 359{
346 struct lm77_data *data = i2c_get_clientdata(client); 360 struct lm77_data *data = i2c_get_clientdata(client);
347 hwmon_device_unregister(data->class_dev); 361 hwmon_device_unregister(data->class_dev);
362 sysfs_remove_group(&client->dev.kobj, &lm77_group);
348 i2c_detach_client(client); 363 i2c_detach_client(client);
349 kfree(data); 364 kfree(data);
350 return 0; 365 return 0;
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index a6ce7abf8602..ac1b746df6d0 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -175,6 +175,7 @@ static struct i2c_driver lm78_driver = {
175 175
176static struct i2c_driver lm78_isa_driver = { 176static struct i2c_driver lm78_isa_driver = {
177 .driver = { 177 .driver = {
178 .owner = THIS_MODULE,
178 .name = "lm78-isa", 179 .name = "lm78-isa",
179 }, 180 },
180 .attach_adapter = lm78_isa_attach_adapter, 181 .attach_adapter = lm78_isa_attach_adapter,
@@ -481,6 +482,50 @@ static int lm78_isa_attach_adapter(struct i2c_adapter *adapter)
481 return lm78_detect(adapter, isa_address, -1); 482 return lm78_detect(adapter, isa_address, -1);
482} 483}
483 484
485static struct attribute *lm78_attributes[] = {
486 &dev_attr_in0_input.attr,
487 &dev_attr_in0_min.attr,
488 &dev_attr_in0_max.attr,
489 &dev_attr_in1_input.attr,
490 &dev_attr_in1_min.attr,
491 &dev_attr_in1_max.attr,
492 &dev_attr_in2_input.attr,
493 &dev_attr_in2_min.attr,
494 &dev_attr_in2_max.attr,
495 &dev_attr_in3_input.attr,
496 &dev_attr_in3_min.attr,
497 &dev_attr_in3_max.attr,
498 &dev_attr_in4_input.attr,
499 &dev_attr_in4_min.attr,
500 &dev_attr_in4_max.attr,
501 &dev_attr_in5_input.attr,
502 &dev_attr_in5_min.attr,
503 &dev_attr_in5_max.attr,
504 &dev_attr_in6_input.attr,
505 &dev_attr_in6_min.attr,
506 &dev_attr_in6_max.attr,
507 &dev_attr_temp1_input.attr,
508 &dev_attr_temp1_max.attr,
509 &dev_attr_temp1_max_hyst.attr,
510 &dev_attr_fan1_input.attr,
511 &dev_attr_fan1_min.attr,
512 &dev_attr_fan1_div.attr,
513 &dev_attr_fan2_input.attr,
514 &dev_attr_fan2_min.attr,
515 &dev_attr_fan2_div.attr,
516 &dev_attr_fan3_input.attr,
517 &dev_attr_fan3_min.attr,
518 &dev_attr_fan3_div.attr,
519 &dev_attr_alarms.attr,
520 &dev_attr_cpu0_vid.attr,
521
522 NULL
523};
524
525static const struct attribute_group lm78_group = {
526 .attrs = lm78_attributes,
527};
528
484/* This function is called by i2c_probe */ 529/* This function is called by i2c_probe */
485static int lm78_detect(struct i2c_adapter *adapter, int address, int kind) 530static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
486{ 531{
@@ -615,50 +660,19 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
615 } 660 }
616 661
617 /* Register sysfs hooks */ 662 /* Register sysfs hooks */
663 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm78_group)))
664 goto ERROR3;
665
618 data->class_dev = hwmon_device_register(&new_client->dev); 666 data->class_dev = hwmon_device_register(&new_client->dev);
619 if (IS_ERR(data->class_dev)) { 667 if (IS_ERR(data->class_dev)) {
620 err = PTR_ERR(data->class_dev); 668 err = PTR_ERR(data->class_dev);
621 goto ERROR3; 669 goto ERROR4;
622 } 670 }
623 671
624 device_create_file(&new_client->dev, &dev_attr_in0_input);
625 device_create_file(&new_client->dev, &dev_attr_in0_min);
626 device_create_file(&new_client->dev, &dev_attr_in0_max);
627 device_create_file(&new_client->dev, &dev_attr_in1_input);
628 device_create_file(&new_client->dev, &dev_attr_in1_min);
629 device_create_file(&new_client->dev, &dev_attr_in1_max);
630 device_create_file(&new_client->dev, &dev_attr_in2_input);
631 device_create_file(&new_client->dev, &dev_attr_in2_min);
632 device_create_file(&new_client->dev, &dev_attr_in2_max);
633 device_create_file(&new_client->dev, &dev_attr_in3_input);
634 device_create_file(&new_client->dev, &dev_attr_in3_min);
635 device_create_file(&new_client->dev, &dev_attr_in3_max);
636 device_create_file(&new_client->dev, &dev_attr_in4_input);
637 device_create_file(&new_client->dev, &dev_attr_in4_min);
638 device_create_file(&new_client->dev, &dev_attr_in4_max);
639 device_create_file(&new_client->dev, &dev_attr_in5_input);
640 device_create_file(&new_client->dev, &dev_attr_in5_min);
641 device_create_file(&new_client->dev, &dev_attr_in5_max);
642 device_create_file(&new_client->dev, &dev_attr_in6_input);
643 device_create_file(&new_client->dev, &dev_attr_in6_min);
644 device_create_file(&new_client->dev, &dev_attr_in6_max);
645 device_create_file(&new_client->dev, &dev_attr_temp1_input);
646 device_create_file(&new_client->dev, &dev_attr_temp1_max);
647 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
648 device_create_file(&new_client->dev, &dev_attr_fan1_input);
649 device_create_file(&new_client->dev, &dev_attr_fan1_min);
650 device_create_file(&new_client->dev, &dev_attr_fan1_div);
651 device_create_file(&new_client->dev, &dev_attr_fan2_input);
652 device_create_file(&new_client->dev, &dev_attr_fan2_min);
653 device_create_file(&new_client->dev, &dev_attr_fan2_div);
654 device_create_file(&new_client->dev, &dev_attr_fan3_input);
655 device_create_file(&new_client->dev, &dev_attr_fan3_min);
656 device_create_file(&new_client->dev, &dev_attr_fan3_div);
657 device_create_file(&new_client->dev, &dev_attr_alarms);
658 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
659
660 return 0; 672 return 0;
661 673
674ERROR4:
675 sysfs_remove_group(&new_client->dev.kobj, &lm78_group);
662ERROR3: 676ERROR3:
663 i2c_detach_client(new_client); 677 i2c_detach_client(new_client);
664ERROR2: 678ERROR2:
@@ -676,6 +690,7 @@ static int lm78_detach_client(struct i2c_client *client)
676 int err; 690 int err;
677 691
678 hwmon_device_unregister(data->class_dev); 692 hwmon_device_unregister(data->class_dev);
693 sysfs_remove_group(&client->dev.kobj, &lm78_group);
679 694
680 if ((err = i2c_detach_client(client))) 695 if ((err = i2c_detach_client(client)))
681 return err; 696 return err;
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c
index b4ccdfc01203..064516d824ad 100644
--- a/drivers/hwmon/lm80.c
+++ b/drivers/hwmon/lm80.c
@@ -394,6 +394,48 @@ static int lm80_attach_adapter(struct i2c_adapter *adapter)
394 return i2c_probe(adapter, &addr_data, lm80_detect); 394 return i2c_probe(adapter, &addr_data, lm80_detect);
395} 395}
396 396
397static struct attribute *lm80_attributes[] = {
398 &dev_attr_in0_min.attr,
399 &dev_attr_in1_min.attr,
400 &dev_attr_in2_min.attr,
401 &dev_attr_in3_min.attr,
402 &dev_attr_in4_min.attr,
403 &dev_attr_in5_min.attr,
404 &dev_attr_in6_min.attr,
405 &dev_attr_in0_max.attr,
406 &dev_attr_in1_max.attr,
407 &dev_attr_in2_max.attr,
408 &dev_attr_in3_max.attr,
409 &dev_attr_in4_max.attr,
410 &dev_attr_in5_max.attr,
411 &dev_attr_in6_max.attr,
412 &dev_attr_in0_input.attr,
413 &dev_attr_in1_input.attr,
414 &dev_attr_in2_input.attr,
415 &dev_attr_in3_input.attr,
416 &dev_attr_in4_input.attr,
417 &dev_attr_in5_input.attr,
418 &dev_attr_in6_input.attr,
419 &dev_attr_fan1_min.attr,
420 &dev_attr_fan2_min.attr,
421 &dev_attr_fan1_input.attr,
422 &dev_attr_fan2_input.attr,
423 &dev_attr_fan1_div.attr,
424 &dev_attr_fan2_div.attr,
425 &dev_attr_temp1_input.attr,
426 &dev_attr_temp1_max.attr,
427 &dev_attr_temp1_max_hyst.attr,
428 &dev_attr_temp1_crit.attr,
429 &dev_attr_temp1_crit_hyst.attr,
430 &dev_attr_alarms.attr,
431
432 NULL
433};
434
435static const struct attribute_group lm80_group = {
436 .attrs = lm80_attributes,
437};
438
397static int lm80_detect(struct i2c_adapter *adapter, int address, int kind) 439static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
398{ 440{
399 int i, cur; 441 int i, cur;
@@ -452,48 +494,19 @@ static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
452 data->fan_min[1] = lm80_read_value(new_client, LM80_REG_FAN_MIN(2)); 494 data->fan_min[1] = lm80_read_value(new_client, LM80_REG_FAN_MIN(2));
453 495
454 /* Register sysfs hooks */ 496 /* Register sysfs hooks */
497 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm80_group)))
498 goto error_detach;
499
455 data->class_dev = hwmon_device_register(&new_client->dev); 500 data->class_dev = hwmon_device_register(&new_client->dev);
456 if (IS_ERR(data->class_dev)) { 501 if (IS_ERR(data->class_dev)) {
457 err = PTR_ERR(data->class_dev); 502 err = PTR_ERR(data->class_dev);
458 goto error_detach; 503 goto error_remove;
459 } 504 }
460 505
461 device_create_file(&new_client->dev, &dev_attr_in0_min);
462 device_create_file(&new_client->dev, &dev_attr_in1_min);
463 device_create_file(&new_client->dev, &dev_attr_in2_min);
464 device_create_file(&new_client->dev, &dev_attr_in3_min);
465 device_create_file(&new_client->dev, &dev_attr_in4_min);
466 device_create_file(&new_client->dev, &dev_attr_in5_min);
467 device_create_file(&new_client->dev, &dev_attr_in6_min);
468 device_create_file(&new_client->dev, &dev_attr_in0_max);
469 device_create_file(&new_client->dev, &dev_attr_in1_max);
470 device_create_file(&new_client->dev, &dev_attr_in2_max);
471 device_create_file(&new_client->dev, &dev_attr_in3_max);
472 device_create_file(&new_client->dev, &dev_attr_in4_max);
473 device_create_file(&new_client->dev, &dev_attr_in5_max);
474 device_create_file(&new_client->dev, &dev_attr_in6_max);
475 device_create_file(&new_client->dev, &dev_attr_in0_input);
476 device_create_file(&new_client->dev, &dev_attr_in1_input);
477 device_create_file(&new_client->dev, &dev_attr_in2_input);
478 device_create_file(&new_client->dev, &dev_attr_in3_input);
479 device_create_file(&new_client->dev, &dev_attr_in4_input);
480 device_create_file(&new_client->dev, &dev_attr_in5_input);
481 device_create_file(&new_client->dev, &dev_attr_in6_input);
482 device_create_file(&new_client->dev, &dev_attr_fan1_min);
483 device_create_file(&new_client->dev, &dev_attr_fan2_min);
484 device_create_file(&new_client->dev, &dev_attr_fan1_input);
485 device_create_file(&new_client->dev, &dev_attr_fan2_input);
486 device_create_file(&new_client->dev, &dev_attr_fan1_div);
487 device_create_file(&new_client->dev, &dev_attr_fan2_div);
488 device_create_file(&new_client->dev, &dev_attr_temp1_input);
489 device_create_file(&new_client->dev, &dev_attr_temp1_max);
490 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
491 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
492 device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst);
493 device_create_file(&new_client->dev, &dev_attr_alarms);
494
495 return 0; 506 return 0;
496 507
508error_remove:
509 sysfs_remove_group(&new_client->dev.kobj, &lm80_group);
497error_detach: 510error_detach:
498 i2c_detach_client(new_client); 511 i2c_detach_client(new_client);
499error_free: 512error_free:
@@ -508,7 +521,7 @@ static int lm80_detach_client(struct i2c_client *client)
508 int err; 521 int err;
509 522
510 hwmon_device_unregister(data->class_dev); 523 hwmon_device_unregister(data->class_dev);
511 524 sysfs_remove_group(&client->dev.kobj, &lm80_group);
512 if ((err = i2c_detach_client(client))) 525 if ((err = i2c_detach_client(client)))
513 return err; 526 return err;
514 527
diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c
index 2137d7879df6..feb87b41e986 100644
--- a/drivers/hwmon/lm83.c
+++ b/drivers/hwmon/lm83.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * lm83.c - Part of lm_sensors, Linux kernel modules for hardware 2 * lm83.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring 3 * monitoring
4 * Copyright (C) 2003-2005 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2003-2006 Jean Delvare <khali@linux-fr.org>
5 * 5 *
6 * Heavily inspired from the lm78, lm75 and adm1021 drivers. The LM83 is 6 * Heavily inspired from the lm78, lm75 and adm1021 drivers. The LM83 is
7 * a sensor chip made by National Semiconductor. It reports up to four 7 * a sensor chip made by National Semiconductor. It reports up to four
@@ -40,6 +40,7 @@
40#include <linux/hwmon.h> 40#include <linux/hwmon.h>
41#include <linux/err.h> 41#include <linux/err.h>
42#include <linux/mutex.h> 42#include <linux/mutex.h>
43#include <linux/sysfs.h>
43 44
44/* 45/*
45 * Addresses to scan 46 * Addresses to scan
@@ -191,6 +192,16 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy,
191 return sprintf(buf, "%d\n", data->alarms); 192 return sprintf(buf, "%d\n", data->alarms);
192} 193}
193 194
195static ssize_t show_alarm(struct device *dev, struct device_attribute
196 *devattr, char *buf)
197{
198 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
199 struct lm83_data *data = lm83_update_device(dev);
200 int bitnr = attr->index;
201
202 return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1);
203}
204
194static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); 205static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
195static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1); 206static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
196static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2); 207static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
@@ -208,8 +219,64 @@ static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp, NULL, 8);
208static SENSOR_DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_temp, 219static SENSOR_DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_temp,
209 set_temp, 8); 220 set_temp, 8);
210static SENSOR_DEVICE_ATTR(temp4_crit, S_IRUGO, show_temp, NULL, 8); 221static SENSOR_DEVICE_ATTR(temp4_crit, S_IRUGO, show_temp, NULL, 8);
222
223/* Individual alarm files */
224static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0);
225static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 1);
226static SENSOR_DEVICE_ATTR(temp3_input_fault, S_IRUGO, show_alarm, NULL, 2);
227static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 4);
228static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
229static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 8);
230static SENSOR_DEVICE_ATTR(temp4_crit_alarm, S_IRUGO, show_alarm, NULL, 9);
231static SENSOR_DEVICE_ATTR(temp4_input_fault, S_IRUGO, show_alarm, NULL, 10);
232static SENSOR_DEVICE_ATTR(temp4_max_alarm, S_IRUGO, show_alarm, NULL, 12);
233static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 13);
234static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 15);
235/* Raw alarm file for compatibility */
211static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 236static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
212 237
238static struct attribute *lm83_attributes[] = {
239 &sensor_dev_attr_temp1_input.dev_attr.attr,
240 &sensor_dev_attr_temp3_input.dev_attr.attr,
241 &sensor_dev_attr_temp1_max.dev_attr.attr,
242 &sensor_dev_attr_temp3_max.dev_attr.attr,
243 &sensor_dev_attr_temp1_crit.dev_attr.attr,
244 &sensor_dev_attr_temp3_crit.dev_attr.attr,
245
246 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
247 &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr,
248 &sensor_dev_attr_temp3_input_fault.dev_attr.attr,
249 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
250 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
251 &dev_attr_alarms.attr,
252 NULL
253};
254
255static const struct attribute_group lm83_group = {
256 .attrs = lm83_attributes,
257};
258
259static struct attribute *lm83_attributes_opt[] = {
260 &sensor_dev_attr_temp2_input.dev_attr.attr,
261 &sensor_dev_attr_temp4_input.dev_attr.attr,
262 &sensor_dev_attr_temp2_max.dev_attr.attr,
263 &sensor_dev_attr_temp4_max.dev_attr.attr,
264 &sensor_dev_attr_temp2_crit.dev_attr.attr,
265 &sensor_dev_attr_temp4_crit.dev_attr.attr,
266
267 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
268 &sensor_dev_attr_temp4_crit_alarm.dev_attr.attr,
269 &sensor_dev_attr_temp4_input_fault.dev_attr.attr,
270 &sensor_dev_attr_temp4_max_alarm.dev_attr.attr,
271 &sensor_dev_attr_temp2_input_fault.dev_attr.attr,
272 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
273 NULL
274};
275
276static const struct attribute_group lm83_group_opt = {
277 .attrs = lm83_attributes_opt,
278};
279
213/* 280/*
214 * Real code 281 * Real code
215 */ 282 */
@@ -318,59 +385,32 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind)
318 goto exit_free; 385 goto exit_free;
319 386
320 /* 387 /*
321 * Initialize the LM83 chip 388 * Register sysfs hooks
322 * (Nothing to do for this one.)
323 */
324
325 /* Register sysfs hooks */
326 data->class_dev = hwmon_device_register(&new_client->dev);
327 if (IS_ERR(data->class_dev)) {
328 err = PTR_ERR(data->class_dev);
329 goto exit_detach;
330 }
331
332 /*
333 * The LM82 can only monitor one external diode which is 389 * The LM82 can only monitor one external diode which is
334 * at the same register as the LM83 temp3 entry - so we 390 * at the same register as the LM83 temp3 entry - so we
335 * declare 1 and 3 common, and then 2 and 4 only for the LM83. 391 * declare 1 and 3 common, and then 2 and 4 only for the LM83.
336 */ 392 */
337 393
338 device_create_file(&new_client->dev, 394 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm83_group)))
339 &sensor_dev_attr_temp1_input.dev_attr); 395 goto exit_detach;
340 device_create_file(&new_client->dev,
341 &sensor_dev_attr_temp3_input.dev_attr);
342
343 device_create_file(&new_client->dev,
344 &sensor_dev_attr_temp1_max.dev_attr);
345 device_create_file(&new_client->dev,
346 &sensor_dev_attr_temp3_max.dev_attr);
347
348 device_create_file(&new_client->dev,
349 &sensor_dev_attr_temp1_crit.dev_attr);
350 device_create_file(&new_client->dev,
351 &sensor_dev_attr_temp3_crit.dev_attr);
352
353 device_create_file(&new_client->dev, &dev_attr_alarms);
354 396
355 if (kind == lm83) { 397 if (kind == lm83) {
356 device_create_file(&new_client->dev, 398 if ((err = sysfs_create_group(&new_client->dev.kobj,
357 &sensor_dev_attr_temp2_input.dev_attr); 399 &lm83_group_opt)))
358 device_create_file(&new_client->dev, 400 goto exit_remove_files;
359 &sensor_dev_attr_temp4_input.dev_attr); 401 }
360 402
361 device_create_file(&new_client->dev, 403 data->class_dev = hwmon_device_register(&new_client->dev);
362 &sensor_dev_attr_temp2_max.dev_attr); 404 if (IS_ERR(data->class_dev)) {
363 device_create_file(&new_client->dev, 405 err = PTR_ERR(data->class_dev);
364 &sensor_dev_attr_temp4_max.dev_attr); 406 goto exit_remove_files;
365
366 device_create_file(&new_client->dev,
367 &sensor_dev_attr_temp2_crit.dev_attr);
368 device_create_file(&new_client->dev,
369 &sensor_dev_attr_temp4_crit.dev_attr);
370 } 407 }
371 408
372 return 0; 409 return 0;
373 410
411exit_remove_files:
412 sysfs_remove_group(&new_client->dev.kobj, &lm83_group);
413 sysfs_remove_group(&new_client->dev.kobj, &lm83_group_opt);
374exit_detach: 414exit_detach:
375 i2c_detach_client(new_client); 415 i2c_detach_client(new_client);
376exit_free: 416exit_free:
@@ -385,6 +425,8 @@ static int lm83_detach_client(struct i2c_client *client)
385 int err; 425 int err;
386 426
387 hwmon_device_unregister(data->class_dev); 427 hwmon_device_unregister(data->class_dev);
428 sysfs_remove_group(&client->dev.kobj, &lm83_group);
429 sysfs_remove_group(&client->dev.kobj, &lm83_group_opt);
388 430
389 if ((err = i2c_detach_client(client))) 431 if ((err = i2c_detach_client(client)))
390 return err; 432 return err;
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index 342e9663119d..2c3293cf69d1 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -1025,6 +1025,89 @@ static int lm85_attach_adapter(struct i2c_adapter *adapter)
1025 return i2c_probe(adapter, &addr_data, lm85_detect); 1025 return i2c_probe(adapter, &addr_data, lm85_detect);
1026} 1026}
1027 1027
1028static struct attribute *lm85_attributes[] = {
1029 &dev_attr_fan1_input.attr,
1030 &dev_attr_fan2_input.attr,
1031 &dev_attr_fan3_input.attr,
1032 &dev_attr_fan4_input.attr,
1033 &dev_attr_fan1_min.attr,
1034 &dev_attr_fan2_min.attr,
1035 &dev_attr_fan3_min.attr,
1036 &dev_attr_fan4_min.attr,
1037 &dev_attr_pwm1.attr,
1038 &dev_attr_pwm2.attr,
1039 &dev_attr_pwm3.attr,
1040 &dev_attr_pwm1_enable.attr,
1041 &dev_attr_pwm2_enable.attr,
1042 &dev_attr_pwm3_enable.attr,
1043 &dev_attr_in0_input.attr,
1044 &dev_attr_in1_input.attr,
1045 &dev_attr_in2_input.attr,
1046 &dev_attr_in3_input.attr,
1047 &dev_attr_in0_min.attr,
1048 &dev_attr_in1_min.attr,
1049 &dev_attr_in2_min.attr,
1050 &dev_attr_in3_min.attr,
1051 &dev_attr_in0_max.attr,
1052 &dev_attr_in1_max.attr,
1053 &dev_attr_in2_max.attr,
1054 &dev_attr_in3_max.attr,
1055 &dev_attr_temp1_input.attr,
1056 &dev_attr_temp2_input.attr,
1057 &dev_attr_temp3_input.attr,
1058 &dev_attr_temp1_min.attr,
1059 &dev_attr_temp2_min.attr,
1060 &dev_attr_temp3_min.attr,
1061 &dev_attr_temp1_max.attr,
1062 &dev_attr_temp2_max.attr,
1063 &dev_attr_temp3_max.attr,
1064 &dev_attr_vrm.attr,
1065 &dev_attr_cpu0_vid.attr,
1066 &dev_attr_alarms.attr,
1067 &dev_attr_pwm1_auto_channels.attr,
1068 &dev_attr_pwm2_auto_channels.attr,
1069 &dev_attr_pwm3_auto_channels.attr,
1070 &dev_attr_pwm1_auto_pwm_min.attr,
1071 &dev_attr_pwm2_auto_pwm_min.attr,
1072 &dev_attr_pwm3_auto_pwm_min.attr,
1073 &dev_attr_pwm1_auto_pwm_minctl.attr,
1074 &dev_attr_pwm2_auto_pwm_minctl.attr,
1075 &dev_attr_pwm3_auto_pwm_minctl.attr,
1076 &dev_attr_pwm1_auto_pwm_freq.attr,
1077 &dev_attr_pwm2_auto_pwm_freq.attr,
1078 &dev_attr_pwm3_auto_pwm_freq.attr,
1079 &dev_attr_temp1_auto_temp_off.attr,
1080 &dev_attr_temp2_auto_temp_off.attr,
1081 &dev_attr_temp3_auto_temp_off.attr,
1082 &dev_attr_temp1_auto_temp_min.attr,
1083 &dev_attr_temp2_auto_temp_min.attr,
1084 &dev_attr_temp3_auto_temp_min.attr,
1085 &dev_attr_temp1_auto_temp_max.attr,
1086 &dev_attr_temp2_auto_temp_max.attr,
1087 &dev_attr_temp3_auto_temp_max.attr,
1088 &dev_attr_temp1_auto_temp_crit.attr,
1089 &dev_attr_temp2_auto_temp_crit.attr,
1090 &dev_attr_temp3_auto_temp_crit.attr,
1091
1092 NULL
1093};
1094
1095static const struct attribute_group lm85_group = {
1096 .attrs = lm85_attributes,
1097};
1098
1099static struct attribute *lm85_attributes_opt[] = {
1100 &dev_attr_in4_input.attr,
1101 &dev_attr_in4_min.attr,
1102 &dev_attr_in4_max.attr,
1103
1104 NULL
1105};
1106
1107static const struct attribute_group lm85_group_opt = {
1108 .attrs = lm85_attributes_opt,
1109};
1110
1028static int lm85_detect(struct i2c_adapter *adapter, int address, 1111static int lm85_detect(struct i2c_adapter *adapter, int address,
1029 int kind) 1112 int kind)
1030{ 1113{
@@ -1163,87 +1246,33 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1163 lm85_init_client(new_client); 1246 lm85_init_client(new_client);
1164 1247
1165 /* Register sysfs hooks */ 1248 /* Register sysfs hooks */
1166 data->class_dev = hwmon_device_register(&new_client->dev); 1249 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm85_group)))
1167 if (IS_ERR(data->class_dev)) {
1168 err = PTR_ERR(data->class_dev);
1169 goto ERROR2; 1250 goto ERROR2;
1170 }
1171
1172 device_create_file(&new_client->dev, &dev_attr_fan1_input);
1173 device_create_file(&new_client->dev, &dev_attr_fan2_input);
1174 device_create_file(&new_client->dev, &dev_attr_fan3_input);
1175 device_create_file(&new_client->dev, &dev_attr_fan4_input);
1176 device_create_file(&new_client->dev, &dev_attr_fan1_min);
1177 device_create_file(&new_client->dev, &dev_attr_fan2_min);
1178 device_create_file(&new_client->dev, &dev_attr_fan3_min);
1179 device_create_file(&new_client->dev, &dev_attr_fan4_min);
1180 device_create_file(&new_client->dev, &dev_attr_pwm1);
1181 device_create_file(&new_client->dev, &dev_attr_pwm2);
1182 device_create_file(&new_client->dev, &dev_attr_pwm3);
1183 device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
1184 device_create_file(&new_client->dev, &dev_attr_pwm2_enable);
1185 device_create_file(&new_client->dev, &dev_attr_pwm3_enable);
1186 device_create_file(&new_client->dev, &dev_attr_in0_input);
1187 device_create_file(&new_client->dev, &dev_attr_in1_input);
1188 device_create_file(&new_client->dev, &dev_attr_in2_input);
1189 device_create_file(&new_client->dev, &dev_attr_in3_input);
1190 device_create_file(&new_client->dev, &dev_attr_in0_min);
1191 device_create_file(&new_client->dev, &dev_attr_in1_min);
1192 device_create_file(&new_client->dev, &dev_attr_in2_min);
1193 device_create_file(&new_client->dev, &dev_attr_in3_min);
1194 device_create_file(&new_client->dev, &dev_attr_in0_max);
1195 device_create_file(&new_client->dev, &dev_attr_in1_max);
1196 device_create_file(&new_client->dev, &dev_attr_in2_max);
1197 device_create_file(&new_client->dev, &dev_attr_in3_max);
1198 device_create_file(&new_client->dev, &dev_attr_temp1_input);
1199 device_create_file(&new_client->dev, &dev_attr_temp2_input);
1200 device_create_file(&new_client->dev, &dev_attr_temp3_input);
1201 device_create_file(&new_client->dev, &dev_attr_temp1_min);
1202 device_create_file(&new_client->dev, &dev_attr_temp2_min);
1203 device_create_file(&new_client->dev, &dev_attr_temp3_min);
1204 device_create_file(&new_client->dev, &dev_attr_temp1_max);
1205 device_create_file(&new_client->dev, &dev_attr_temp2_max);
1206 device_create_file(&new_client->dev, &dev_attr_temp3_max);
1207 device_create_file(&new_client->dev, &dev_attr_vrm);
1208 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
1209 device_create_file(&new_client->dev, &dev_attr_alarms);
1210 device_create_file(&new_client->dev, &dev_attr_pwm1_auto_channels);
1211 device_create_file(&new_client->dev, &dev_attr_pwm2_auto_channels);
1212 device_create_file(&new_client->dev, &dev_attr_pwm3_auto_channels);
1213 device_create_file(&new_client->dev, &dev_attr_pwm1_auto_pwm_min);
1214 device_create_file(&new_client->dev, &dev_attr_pwm2_auto_pwm_min);
1215 device_create_file(&new_client->dev, &dev_attr_pwm3_auto_pwm_min);
1216 device_create_file(&new_client->dev, &dev_attr_pwm1_auto_pwm_minctl);
1217 device_create_file(&new_client->dev, &dev_attr_pwm2_auto_pwm_minctl);
1218 device_create_file(&new_client->dev, &dev_attr_pwm3_auto_pwm_minctl);
1219 device_create_file(&new_client->dev, &dev_attr_pwm1_auto_pwm_freq);
1220 device_create_file(&new_client->dev, &dev_attr_pwm2_auto_pwm_freq);
1221 device_create_file(&new_client->dev, &dev_attr_pwm3_auto_pwm_freq);
1222 device_create_file(&new_client->dev, &dev_attr_temp1_auto_temp_off);
1223 device_create_file(&new_client->dev, &dev_attr_temp2_auto_temp_off);
1224 device_create_file(&new_client->dev, &dev_attr_temp3_auto_temp_off);
1225 device_create_file(&new_client->dev, &dev_attr_temp1_auto_temp_min);
1226 device_create_file(&new_client->dev, &dev_attr_temp2_auto_temp_min);
1227 device_create_file(&new_client->dev, &dev_attr_temp3_auto_temp_min);
1228 device_create_file(&new_client->dev, &dev_attr_temp1_auto_temp_max);
1229 device_create_file(&new_client->dev, &dev_attr_temp2_auto_temp_max);
1230 device_create_file(&new_client->dev, &dev_attr_temp3_auto_temp_max);
1231 device_create_file(&new_client->dev, &dev_attr_temp1_auto_temp_crit);
1232 device_create_file(&new_client->dev, &dev_attr_temp2_auto_temp_crit);
1233 device_create_file(&new_client->dev, &dev_attr_temp3_auto_temp_crit);
1234 1251
1235 /* The ADT7463 has an optional VRM 10 mode where pin 21 is used 1252 /* The ADT7463 has an optional VRM 10 mode where pin 21 is used
1236 as a sixth digital VID input rather than an analog input. */ 1253 as a sixth digital VID input rather than an analog input. */
1237 data->vid = lm85_read_value(new_client, LM85_REG_VID); 1254 data->vid = lm85_read_value(new_client, LM85_REG_VID);
1238 if (!(kind == adt7463 && (data->vid & 0x80))) { 1255 if (!(kind == adt7463 && (data->vid & 0x80)))
1239 device_create_file(&new_client->dev, &dev_attr_in4_input); 1256 if ((err = device_create_file(&new_client->dev,
1240 device_create_file(&new_client->dev, &dev_attr_in4_min); 1257 &dev_attr_in4_input))
1241 device_create_file(&new_client->dev, &dev_attr_in4_max); 1258 || (err = device_create_file(&new_client->dev,
1259 &dev_attr_in4_min))
1260 || (err = device_create_file(&new_client->dev,
1261 &dev_attr_in4_max)))
1262 goto ERROR3;
1263
1264 data->class_dev = hwmon_device_register(&new_client->dev);
1265 if (IS_ERR(data->class_dev)) {
1266 err = PTR_ERR(data->class_dev);
1267 goto ERROR3;
1242 } 1268 }
1243 1269
1244 return 0; 1270 return 0;
1245 1271
1246 /* Error out and cleanup code */ 1272 /* Error out and cleanup code */
1273 ERROR3:
1274 sysfs_remove_group(&new_client->dev.kobj, &lm85_group);
1275 sysfs_remove_group(&new_client->dev.kobj, &lm85_group_opt);
1247 ERROR2: 1276 ERROR2:
1248 i2c_detach_client(new_client); 1277 i2c_detach_client(new_client);
1249 ERROR1: 1278 ERROR1:
@@ -1256,6 +1285,8 @@ static int lm85_detach_client(struct i2c_client *client)
1256{ 1285{
1257 struct lm85_data *data = i2c_get_clientdata(client); 1286 struct lm85_data *data = i2c_get_clientdata(client);
1258 hwmon_device_unregister(data->class_dev); 1287 hwmon_device_unregister(data->class_dev);
1288 sysfs_remove_group(&client->dev.kobj, &lm85_group);
1289 sysfs_remove_group(&client->dev.kobj, &lm85_group_opt);
1259 i2c_detach_client(client); 1290 i2c_detach_client(client);
1260 kfree(data); 1291 kfree(data);
1261 return 0; 1292 return 0;
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
index e6c1b638c971..3ce825489e34 100644
--- a/drivers/hwmon/lm87.c
+++ b/drivers/hwmon/lm87.c
@@ -542,6 +542,78 @@ static int lm87_attach_adapter(struct i2c_adapter *adapter)
542 return i2c_probe(adapter, &addr_data, lm87_detect); 542 return i2c_probe(adapter, &addr_data, lm87_detect);
543} 543}
544 544
545static struct attribute *lm87_attributes[] = {
546 &dev_attr_in1_input.attr,
547 &dev_attr_in1_min.attr,
548 &dev_attr_in1_max.attr,
549 &dev_attr_in2_input.attr,
550 &dev_attr_in2_min.attr,
551 &dev_attr_in2_max.attr,
552 &dev_attr_in3_input.attr,
553 &dev_attr_in3_min.attr,
554 &dev_attr_in3_max.attr,
555 &dev_attr_in4_input.attr,
556 &dev_attr_in4_min.attr,
557 &dev_attr_in4_max.attr,
558
559 &dev_attr_temp1_input.attr,
560 &dev_attr_temp1_max.attr,
561 &dev_attr_temp1_min.attr,
562 &dev_attr_temp1_crit.attr,
563 &dev_attr_temp2_input.attr,
564 &dev_attr_temp2_max.attr,
565 &dev_attr_temp2_min.attr,
566 &dev_attr_temp2_crit.attr,
567
568 &dev_attr_alarms.attr,
569 &dev_attr_aout_output.attr,
570
571 NULL
572};
573
574static const struct attribute_group lm87_group = {
575 .attrs = lm87_attributes,
576};
577
578static struct attribute *lm87_attributes_opt[] = {
579 &dev_attr_in6_input.attr,
580 &dev_attr_in6_min.attr,
581 &dev_attr_in6_max.attr,
582
583 &dev_attr_fan1_input.attr,
584 &dev_attr_fan1_min.attr,
585 &dev_attr_fan1_div.attr,
586
587 &dev_attr_in7_input.attr,
588 &dev_attr_in7_min.attr,
589 &dev_attr_in7_max.attr,
590
591 &dev_attr_fan2_input.attr,
592 &dev_attr_fan2_min.attr,
593 &dev_attr_fan2_div.attr,
594
595 &dev_attr_temp3_input.attr,
596 &dev_attr_temp3_max.attr,
597 &dev_attr_temp3_min.attr,
598 &dev_attr_temp3_crit.attr,
599
600 &dev_attr_in0_input.attr,
601 &dev_attr_in0_min.attr,
602 &dev_attr_in0_max.attr,
603 &dev_attr_in5_input.attr,
604 &dev_attr_in5_min.attr,
605 &dev_attr_in5_max.attr,
606
607 &dev_attr_cpu0_vid.attr,
608 &dev_attr_vrm.attr,
609
610 NULL
611};
612
613static const struct attribute_group lm87_group_opt = {
614 .attrs = lm87_attributes_opt,
615};
616
545/* 617/*
546 * The following function does more than just detection. If detection 618 * The following function does more than just detection. If detection
547 * succeeds, it also registers the new chip. 619 * succeeds, it also registers the new chip.
@@ -609,77 +681,90 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
609 data->in_scale[7] = 1875; 681 data->in_scale[7] = 1875;
610 682
611 /* Register sysfs hooks */ 683 /* Register sysfs hooks */
612 data->class_dev = hwmon_device_register(&new_client->dev); 684 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm87_group)))
613 if (IS_ERR(data->class_dev)) {
614 err = PTR_ERR(data->class_dev);
615 goto exit_detach; 685 goto exit_detach;
616 }
617
618 device_create_file(&new_client->dev, &dev_attr_in1_input);
619 device_create_file(&new_client->dev, &dev_attr_in1_min);
620 device_create_file(&new_client->dev, &dev_attr_in1_max);
621 device_create_file(&new_client->dev, &dev_attr_in2_input);
622 device_create_file(&new_client->dev, &dev_attr_in2_min);
623 device_create_file(&new_client->dev, &dev_attr_in2_max);
624 device_create_file(&new_client->dev, &dev_attr_in3_input);
625 device_create_file(&new_client->dev, &dev_attr_in3_min);
626 device_create_file(&new_client->dev, &dev_attr_in3_max);
627 device_create_file(&new_client->dev, &dev_attr_in4_input);
628 device_create_file(&new_client->dev, &dev_attr_in4_min);
629 device_create_file(&new_client->dev, &dev_attr_in4_max);
630 686
631 if (data->channel & CHAN_NO_FAN(0)) { 687 if (data->channel & CHAN_NO_FAN(0)) {
632 device_create_file(&new_client->dev, &dev_attr_in6_input); 688 if ((err = device_create_file(&new_client->dev,
633 device_create_file(&new_client->dev, &dev_attr_in6_min); 689 &dev_attr_in6_input))
634 device_create_file(&new_client->dev, &dev_attr_in6_max); 690 || (err = device_create_file(&new_client->dev,
691 &dev_attr_in6_min))
692 || (err = device_create_file(&new_client->dev,
693 &dev_attr_in6_max)))
694 goto exit_remove;
635 } else { 695 } else {
636 device_create_file(&new_client->dev, &dev_attr_fan1_input); 696 if ((err = device_create_file(&new_client->dev,
637 device_create_file(&new_client->dev, &dev_attr_fan1_min); 697 &dev_attr_fan1_input))
638 device_create_file(&new_client->dev, &dev_attr_fan1_div); 698 || (err = device_create_file(&new_client->dev,
699 &dev_attr_fan1_min))
700 || (err = device_create_file(&new_client->dev,
701 &dev_attr_fan1_div)))
702 goto exit_remove;
639 } 703 }
704
640 if (data->channel & CHAN_NO_FAN(1)) { 705 if (data->channel & CHAN_NO_FAN(1)) {
641 device_create_file(&new_client->dev, &dev_attr_in7_input); 706 if ((err = device_create_file(&new_client->dev,
642 device_create_file(&new_client->dev, &dev_attr_in7_min); 707 &dev_attr_in7_input))
643 device_create_file(&new_client->dev, &dev_attr_in7_max); 708 || (err = device_create_file(&new_client->dev,
709 &dev_attr_in7_min))
710 || (err = device_create_file(&new_client->dev,
711 &dev_attr_in7_max)))
712 goto exit_remove;
644 } else { 713 } else {
645 device_create_file(&new_client->dev, &dev_attr_fan2_input); 714 if ((err = device_create_file(&new_client->dev,
646 device_create_file(&new_client->dev, &dev_attr_fan2_min); 715 &dev_attr_fan2_input))
647 device_create_file(&new_client->dev, &dev_attr_fan2_div); 716 || (err = device_create_file(&new_client->dev,
717 &dev_attr_fan2_min))
718 || (err = device_create_file(&new_client->dev,
719 &dev_attr_fan2_div)))
720 goto exit_remove;
648 } 721 }
649 722
650 device_create_file(&new_client->dev, &dev_attr_temp1_input);
651 device_create_file(&new_client->dev, &dev_attr_temp1_max);
652 device_create_file(&new_client->dev, &dev_attr_temp1_min);
653 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
654 device_create_file(&new_client->dev, &dev_attr_temp2_input);
655 device_create_file(&new_client->dev, &dev_attr_temp2_max);
656 device_create_file(&new_client->dev, &dev_attr_temp2_min);
657 device_create_file(&new_client->dev, &dev_attr_temp2_crit);
658
659 if (data->channel & CHAN_TEMP3) { 723 if (data->channel & CHAN_TEMP3) {
660 device_create_file(&new_client->dev, &dev_attr_temp3_input); 724 if ((err = device_create_file(&new_client->dev,
661 device_create_file(&new_client->dev, &dev_attr_temp3_max); 725 &dev_attr_temp3_input))
662 device_create_file(&new_client->dev, &dev_attr_temp3_min); 726 || (err = device_create_file(&new_client->dev,
663 device_create_file(&new_client->dev, &dev_attr_temp3_crit); 727 &dev_attr_temp3_max))
728 || (err = device_create_file(&new_client->dev,
729 &dev_attr_temp3_min))
730 || (err = device_create_file(&new_client->dev,
731 &dev_attr_temp3_crit)))
732 goto exit_remove;
664 } else { 733 } else {
665 device_create_file(&new_client->dev, &dev_attr_in0_input); 734 if ((err = device_create_file(&new_client->dev,
666 device_create_file(&new_client->dev, &dev_attr_in0_min); 735 &dev_attr_in0_input))
667 device_create_file(&new_client->dev, &dev_attr_in0_max); 736 || (err = device_create_file(&new_client->dev,
668 device_create_file(&new_client->dev, &dev_attr_in5_input); 737 &dev_attr_in0_min))
669 device_create_file(&new_client->dev, &dev_attr_in5_min); 738 || (err = device_create_file(&new_client->dev,
670 device_create_file(&new_client->dev, &dev_attr_in5_max); 739 &dev_attr_in0_max))
740 || (err = device_create_file(&new_client->dev,
741 &dev_attr_in5_input))
742 || (err = device_create_file(&new_client->dev,
743 &dev_attr_in5_min))
744 || (err = device_create_file(&new_client->dev,
745 &dev_attr_in5_max)))
746 goto exit_remove;
671 } 747 }
672 748
673 if (!(data->channel & CHAN_NO_VID)) { 749 if (!(data->channel & CHAN_NO_VID)) {
674 device_create_file(&new_client->dev, &dev_attr_cpu0_vid); 750 if ((err = device_create_file(&new_client->dev,
675 device_create_file(&new_client->dev, &dev_attr_vrm); 751 &dev_attr_cpu0_vid))
752 || (err = device_create_file(&new_client->dev,
753 &dev_attr_vrm)))
754 goto exit_remove;
676 } 755 }
677 756
678 device_create_file(&new_client->dev, &dev_attr_alarms); 757 data->class_dev = hwmon_device_register(&new_client->dev);
679 device_create_file(&new_client->dev, &dev_attr_aout_output); 758 if (IS_ERR(data->class_dev)) {
759 err = PTR_ERR(data->class_dev);
760 goto exit_remove;
761 }
680 762
681 return 0; 763 return 0;
682 764
765exit_remove:
766 sysfs_remove_group(&new_client->dev.kobj, &lm87_group);
767 sysfs_remove_group(&new_client->dev.kobj, &lm87_group_opt);
683exit_detach: 768exit_detach:
684 i2c_detach_client(new_client); 769 i2c_detach_client(new_client);
685exit_free: 770exit_free:
@@ -732,6 +817,8 @@ static int lm87_detach_client(struct i2c_client *client)
732 int err; 817 int err;
733 818
734 hwmon_device_unregister(data->class_dev); 819 hwmon_device_unregister(data->class_dev);
820 sysfs_remove_group(&client->dev.kobj, &lm87_group);
821 sysfs_remove_group(&client->dev.kobj, &lm87_group_opt);
735 822
736 if ((err = i2c_detach_client(client))) 823 if ((err = i2c_detach_client(client)))
737 return err; 824 return err;
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index d9eeaf7585bd..6882ce75feee 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * lm90.c - Part of lm_sensors, Linux kernel modules for hardware 2 * lm90.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring 3 * monitoring
4 * Copyright (C) 2003-2005 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2003-2006 Jean Delvare <khali@linux-fr.org>
5 * 5 *
6 * Based on the lm83 driver. The LM90 is a sensor chip made by National 6 * Based on the lm83 driver. The LM90 is a sensor chip made by National
7 * Semiconductor. It reports up to two temperatures (its own plus up to 7 * Semiconductor. It reports up to two temperatures (its own plus up to
@@ -79,6 +79,7 @@
79#include <linux/hwmon.h> 79#include <linux/hwmon.h>
80#include <linux/err.h> 80#include <linux/err.h>
81#include <linux/mutex.h> 81#include <linux/mutex.h>
82#include <linux/sysfs.h>
82 83
83/* 84/*
84 * Addresses to scan 85 * Addresses to scan
@@ -327,6 +328,16 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy,
327 return sprintf(buf, "%d\n", data->alarms); 328 return sprintf(buf, "%d\n", data->alarms);
328} 329}
329 330
331static ssize_t show_alarm(struct device *dev, struct device_attribute
332 *devattr, char *buf)
333{
334 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
335 struct lm90_data *data = lm90_update_device(dev);
336 int bitnr = attr->index;
337
338 return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1);
339}
340
330static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp8, NULL, 0); 341static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp8, NULL, 0);
331static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0); 342static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0);
332static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8, 343static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8,
@@ -344,8 +355,45 @@ static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8,
344static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst, 355static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst,
345 set_temphyst, 3); 356 set_temphyst, 3);
346static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 4); 357static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 4);
358
359/* Individual alarm files */
360static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0);
361static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1);
362static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 2);
363static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3);
364static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4);
365static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 5);
366static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
367/* Raw alarm file for compatibility */
347static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 368static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
348 369
370static struct attribute *lm90_attributes[] = {
371 &sensor_dev_attr_temp1_input.dev_attr.attr,
372 &sensor_dev_attr_temp2_input.dev_attr.attr,
373 &sensor_dev_attr_temp1_min.dev_attr.attr,
374 &sensor_dev_attr_temp2_min.dev_attr.attr,
375 &sensor_dev_attr_temp1_max.dev_attr.attr,
376 &sensor_dev_attr_temp2_max.dev_attr.attr,
377 &sensor_dev_attr_temp1_crit.dev_attr.attr,
378 &sensor_dev_attr_temp2_crit.dev_attr.attr,
379 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
380 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
381
382 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
383 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
384 &sensor_dev_attr_temp2_input_fault.dev_attr.attr,
385 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
386 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
387 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
388 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
389 &dev_attr_alarms.attr,
390 NULL
391};
392
393static const struct attribute_group lm90_group = {
394 .attrs = lm90_attributes,
395};
396
349/* pec used for ADM1032 only */ 397/* pec used for ADM1032 only */
350static ssize_t show_pec(struct device *dev, struct device_attribute *dummy, 398static ssize_t show_pec(struct device *dev, struct device_attribute *dummy,
351 char *buf) 399 char *buf)
@@ -569,39 +617,25 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind)
569 lm90_init_client(new_client); 617 lm90_init_client(new_client);
570 618
571 /* Register sysfs hooks */ 619 /* Register sysfs hooks */
620 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm90_group)))
621 goto exit_detach;
622 if (new_client->flags & I2C_CLIENT_PEC) {
623 if ((err = device_create_file(&new_client->dev,
624 &dev_attr_pec)))
625 goto exit_remove_files;
626 }
627
572 data->class_dev = hwmon_device_register(&new_client->dev); 628 data->class_dev = hwmon_device_register(&new_client->dev);
573 if (IS_ERR(data->class_dev)) { 629 if (IS_ERR(data->class_dev)) {
574 err = PTR_ERR(data->class_dev); 630 err = PTR_ERR(data->class_dev);
575 goto exit_detach; 631 goto exit_remove_files;
576 } 632 }
577 633
578 device_create_file(&new_client->dev,
579 &sensor_dev_attr_temp1_input.dev_attr);
580 device_create_file(&new_client->dev,
581 &sensor_dev_attr_temp2_input.dev_attr);
582 device_create_file(&new_client->dev,
583 &sensor_dev_attr_temp1_min.dev_attr);
584 device_create_file(&new_client->dev,
585 &sensor_dev_attr_temp2_min.dev_attr);
586 device_create_file(&new_client->dev,
587 &sensor_dev_attr_temp1_max.dev_attr);
588 device_create_file(&new_client->dev,
589 &sensor_dev_attr_temp2_max.dev_attr);
590 device_create_file(&new_client->dev,
591 &sensor_dev_attr_temp1_crit.dev_attr);
592 device_create_file(&new_client->dev,
593 &sensor_dev_attr_temp2_crit.dev_attr);
594 device_create_file(&new_client->dev,
595 &sensor_dev_attr_temp1_crit_hyst.dev_attr);
596 device_create_file(&new_client->dev,
597 &sensor_dev_attr_temp2_crit_hyst.dev_attr);
598 device_create_file(&new_client->dev, &dev_attr_alarms);
599
600 if (new_client->flags & I2C_CLIENT_PEC)
601 device_create_file(&new_client->dev, &dev_attr_pec);
602
603 return 0; 634 return 0;
604 635
636exit_remove_files:
637 sysfs_remove_group(&new_client->dev.kobj, &lm90_group);
638 device_remove_file(&new_client->dev, &dev_attr_pec);
605exit_detach: 639exit_detach:
606 i2c_detach_client(new_client); 640 i2c_detach_client(new_client);
607exit_free: 641exit_free:
@@ -634,6 +668,8 @@ static int lm90_detach_client(struct i2c_client *client)
634 int err; 668 int err;
635 669
636 hwmon_device_unregister(data->class_dev); 670 hwmon_device_unregister(data->class_dev);
671 sysfs_remove_group(&client->dev.kobj, &lm90_group);
672 device_remove_file(&client->dev, &dev_attr_pec);
637 673
638 if ((err = i2c_detach_client(client))) 674 if ((err = i2c_detach_client(client)))
639 return err; 675 return err;
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c
index 197f77226dc4..30b536333f14 100644
--- a/drivers/hwmon/lm92.c
+++ b/drivers/hwmon/lm92.c
@@ -288,6 +288,23 @@ static int max6635_check(struct i2c_client *client)
288 return 1; 288 return 1;
289} 289}
290 290
291static struct attribute *lm92_attributes[] = {
292 &dev_attr_temp1_input.attr,
293 &dev_attr_temp1_crit.attr,
294 &dev_attr_temp1_crit_hyst.attr,
295 &dev_attr_temp1_min.attr,
296 &dev_attr_temp1_min_hyst.attr,
297 &dev_attr_temp1_max.attr,
298 &dev_attr_temp1_max_hyst.attr,
299 &dev_attr_alarms.attr,
300
301 NULL
302};
303
304static const struct attribute_group lm92_group = {
305 .attrs = lm92_attributes,
306};
307
291/* The following function does more than just detection. If detection 308/* The following function does more than just detection. If detection
292 succeeds, it also registers the new chip. */ 309 succeeds, it also registers the new chip. */
293static int lm92_detect(struct i2c_adapter *adapter, int address, int kind) 310static int lm92_detect(struct i2c_adapter *adapter, int address, int kind)
@@ -359,23 +376,19 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind)
359 lm92_init_client(new_client); 376 lm92_init_client(new_client);
360 377
361 /* Register sysfs hooks */ 378 /* Register sysfs hooks */
379 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm92_group)))
380 goto exit_detach;
381
362 data->class_dev = hwmon_device_register(&new_client->dev); 382 data->class_dev = hwmon_device_register(&new_client->dev);
363 if (IS_ERR(data->class_dev)) { 383 if (IS_ERR(data->class_dev)) {
364 err = PTR_ERR(data->class_dev); 384 err = PTR_ERR(data->class_dev);
365 goto exit_detach; 385 goto exit_remove;
366 } 386 }
367 387
368 device_create_file(&new_client->dev, &dev_attr_temp1_input);
369 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
370 device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst);
371 device_create_file(&new_client->dev, &dev_attr_temp1_min);
372 device_create_file(&new_client->dev, &dev_attr_temp1_min_hyst);
373 device_create_file(&new_client->dev, &dev_attr_temp1_max);
374 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
375 device_create_file(&new_client->dev, &dev_attr_alarms);
376
377 return 0; 388 return 0;
378 389
390exit_remove:
391 sysfs_remove_group(&new_client->dev.kobj, &lm92_group);
379exit_detach: 392exit_detach:
380 i2c_detach_client(new_client); 393 i2c_detach_client(new_client);
381exit_free: 394exit_free:
@@ -397,6 +410,7 @@ static int lm92_detach_client(struct i2c_client *client)
397 int err; 410 int err;
398 411
399 hwmon_device_unregister(data->class_dev); 412 hwmon_device_unregister(data->class_dev);
413 sysfs_remove_group(&client->dev.kobj, &lm92_group);
400 414
401 if ((err = i2c_detach_client(client))) 415 if ((err = i2c_detach_client(client)))
402 return err; 416 return err;
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c
index b4135b5971f4..2f58f651f03a 100644
--- a/drivers/hwmon/max1619.c
+++ b/drivers/hwmon/max1619.c
@@ -34,6 +34,7 @@
34#include <linux/hwmon.h> 34#include <linux/hwmon.h>
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/sysfs.h>
37 38
38static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a, 39static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a,
39 0x29, 0x2a, 0x2b, 40 0x29, 0x2a, 0x2b,
@@ -172,6 +173,22 @@ static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp_hyst2,
172 set_temp_hyst2); 173 set_temp_hyst2);
173static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 174static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
174 175
176static struct attribute *max1619_attributes[] = {
177 &dev_attr_temp1_input.attr,
178 &dev_attr_temp2_input.attr,
179 &dev_attr_temp2_min.attr,
180 &dev_attr_temp2_max.attr,
181 &dev_attr_temp2_crit.attr,
182 &dev_attr_temp2_crit_hyst.attr,
183
184 &dev_attr_alarms.attr,
185 NULL
186};
187
188static const struct attribute_group max1619_group = {
189 .attrs = max1619_attributes,
190};
191
175/* 192/*
176 * Real code 193 * Real code
177 */ 194 */
@@ -273,22 +290,19 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind)
273 max1619_init_client(new_client); 290 max1619_init_client(new_client);
274 291
275 /* Register sysfs hooks */ 292 /* Register sysfs hooks */
293 if ((err = sysfs_create_group(&new_client->dev.kobj, &max1619_group)))
294 goto exit_detach;
295
276 data->class_dev = hwmon_device_register(&new_client->dev); 296 data->class_dev = hwmon_device_register(&new_client->dev);
277 if (IS_ERR(data->class_dev)) { 297 if (IS_ERR(data->class_dev)) {
278 err = PTR_ERR(data->class_dev); 298 err = PTR_ERR(data->class_dev);
279 goto exit_detach; 299 goto exit_remove_files;
280 } 300 }
281 301
282 device_create_file(&new_client->dev, &dev_attr_temp1_input);
283 device_create_file(&new_client->dev, &dev_attr_temp2_input);
284 device_create_file(&new_client->dev, &dev_attr_temp2_min);
285 device_create_file(&new_client->dev, &dev_attr_temp2_max);
286 device_create_file(&new_client->dev, &dev_attr_temp2_crit);
287 device_create_file(&new_client->dev, &dev_attr_temp2_crit_hyst);
288 device_create_file(&new_client->dev, &dev_attr_alarms);
289
290 return 0; 302 return 0;
291 303
304exit_remove_files:
305 sysfs_remove_group(&new_client->dev.kobj, &max1619_group);
292exit_detach: 306exit_detach:
293 i2c_detach_client(new_client); 307 i2c_detach_client(new_client);
294exit_free: 308exit_free:
@@ -318,6 +332,7 @@ static int max1619_detach_client(struct i2c_client *client)
318 int err; 332 int err;
319 333
320 hwmon_device_unregister(data->class_dev); 334 hwmon_device_unregister(data->class_dev);
335 sysfs_remove_group(&client->dev.kobj, &max1619_group);
321 336
322 if ((err = i2c_detach_client(client))) 337 if ((err = i2c_detach_client(client)))
323 return err; 338 return err;
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c
index ae05e483a778..3b8b81984ad4 100644
--- a/drivers/hwmon/pc87360.c
+++ b/drivers/hwmon/pc87360.c
@@ -238,6 +238,7 @@ static struct pc87360_data *pc87360_update_device(struct device *dev);
238 238
239static struct i2c_driver pc87360_driver = { 239static struct i2c_driver pc87360_driver = {
240 .driver = { 240 .driver = {
241 .owner = THIS_MODULE,
241 .name = "pc87360", 242 .name = "pc87360",
242 }, 243 },
243 .attach_adapter = pc87360_detect, 244 .attach_adapter = pc87360_detect,
@@ -327,6 +328,12 @@ static struct sensor_device_attribute fan_min[] = {
327 SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 2), 328 SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 2),
328}; 329};
329 330
331#define FAN_UNIT_ATTRS(X) \
332 &fan_input[X].dev_attr.attr, \
333 &fan_status[X].dev_attr.attr, \
334 &fan_div[X].dev_attr.attr, \
335 &fan_min[X].dev_attr.attr
336
330static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, char *buf) 337static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, char *buf)
331{ 338{
332 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 339 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
@@ -359,6 +366,19 @@ static struct sensor_device_attribute pwm[] = {
359 SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2), 366 SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2),
360}; 367};
361 368
369static struct attribute * pc8736x_fan_attr_array[] = {
370 FAN_UNIT_ATTRS(0),
371 FAN_UNIT_ATTRS(1),
372 FAN_UNIT_ATTRS(2),
373 &pwm[0].dev_attr.attr,
374 &pwm[1].dev_attr.attr,
375 &pwm[2].dev_attr.attr,
376 NULL
377};
378static const struct attribute_group pc8736x_fan_group = {
379 .attrs = pc8736x_fan_attr_array,
380};
381
362static ssize_t show_in_input(struct device *dev, struct device_attribute *devattr, char *buf) 382static ssize_t show_in_input(struct device *dev, struct device_attribute *devattr, char *buf)
363{ 383{
364 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 384 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
@@ -471,6 +491,61 @@ static struct sensor_device_attribute in_max[] = {
471 SENSOR_ATTR(in10_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 10), 491 SENSOR_ATTR(in10_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 10),
472}; 492};
473 493
494#define VIN_UNIT_ATTRS(X) \
495 &in_input[X].dev_attr.attr, \
496 &in_status[X].dev_attr.attr, \
497 &in_min[X].dev_attr.attr, \
498 &in_max[X].dev_attr.attr
499
500static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf)
501{
502 struct pc87360_data *data = pc87360_update_device(dev);
503 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
504}
505static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
506
507static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
508{
509 struct pc87360_data *data = pc87360_update_device(dev);
510 return sprintf(buf, "%u\n", data->vrm);
511}
512static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
513{
514 struct i2c_client *client = to_i2c_client(dev);
515 struct pc87360_data *data = i2c_get_clientdata(client);
516 data->vrm = simple_strtoul(buf, NULL, 10);
517 return count;
518}
519static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
520
521static ssize_t show_in_alarms(struct device *dev, struct device_attribute *attr, char *buf)
522{
523 struct pc87360_data *data = pc87360_update_device(dev);
524 return sprintf(buf, "%u\n", data->in_alarms);
525}
526static DEVICE_ATTR(alarms_in, S_IRUGO, show_in_alarms, NULL);
527
528static struct attribute *pc8736x_vin_attr_array[] = {
529 VIN_UNIT_ATTRS(0),
530 VIN_UNIT_ATTRS(1),
531 VIN_UNIT_ATTRS(2),
532 VIN_UNIT_ATTRS(3),
533 VIN_UNIT_ATTRS(4),
534 VIN_UNIT_ATTRS(5),
535 VIN_UNIT_ATTRS(6),
536 VIN_UNIT_ATTRS(7),
537 VIN_UNIT_ATTRS(8),
538 VIN_UNIT_ATTRS(9),
539 VIN_UNIT_ATTRS(10),
540 &dev_attr_cpu0_vid.attr,
541 &dev_attr_vrm.attr,
542 &dev_attr_alarms_in.attr,
543 NULL
544};
545static const struct attribute_group pc8736x_vin_group = {
546 .attrs = pc8736x_vin_attr_array,
547};
548
474static ssize_t show_therm_input(struct device *dev, struct device_attribute *devattr, char *buf) 549static ssize_t show_therm_input(struct device *dev, struct device_attribute *devattr, char *buf)
475{ 550{
476 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 551 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
@@ -589,33 +664,22 @@ static struct sensor_device_attribute therm_crit[] = {
589 show_therm_crit, set_therm_crit, 2+11), 664 show_therm_crit, set_therm_crit, 2+11),
590}; 665};
591 666
592static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 667#define THERM_UNIT_ATTRS(X) \
593{ 668 &therm_input[X].dev_attr.attr, \
594 struct pc87360_data *data = pc87360_update_device(dev); 669 &therm_status[X].dev_attr.attr, \
595 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm)); 670 &therm_min[X].dev_attr.attr, \
596} 671 &therm_max[X].dev_attr.attr, \
597static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 672 &therm_crit[X].dev_attr.attr
598 673
599static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) 674static struct attribute * pc8736x_therm_attr_array[] = {
600{ 675 THERM_UNIT_ATTRS(0),
601 struct pc87360_data *data = pc87360_update_device(dev); 676 THERM_UNIT_ATTRS(1),
602 return sprintf(buf, "%u\n", data->vrm); 677 THERM_UNIT_ATTRS(2),
603} 678 NULL
604static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 679};
605{ 680static const struct attribute_group pc8736x_therm_group = {
606 struct i2c_client *client = to_i2c_client(dev); 681 .attrs = pc8736x_therm_attr_array,
607 struct pc87360_data *data = i2c_get_clientdata(client); 682};
608 data->vrm = simple_strtoul(buf, NULL, 10);
609 return count;
610}
611static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
612
613static ssize_t show_in_alarms(struct device *dev, struct device_attribute *attr, char *buf)
614{
615 struct pc87360_data *data = pc87360_update_device(dev);
616 return sprintf(buf, "%u\n", data->in_alarms);
617}
618static DEVICE_ATTR(alarms_in, S_IRUGO, show_in_alarms, NULL);
619 683
620static ssize_t show_temp_input(struct device *dev, struct device_attribute *devattr, char *buf) 684static ssize_t show_temp_input(struct device *dev, struct device_attribute *devattr, char *buf)
621{ 685{
@@ -735,6 +799,25 @@ static ssize_t show_temp_alarms(struct device *dev, struct device_attribute *att
735} 799}
736static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL); 800static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL);
737 801
802#define TEMP_UNIT_ATTRS(X) \
803 &temp_input[X].dev_attr.attr, \
804 &temp_status[X].dev_attr.attr, \
805 &temp_min[X].dev_attr.attr, \
806 &temp_max[X].dev_attr.attr, \
807 &temp_crit[X].dev_attr.attr
808
809static struct attribute * pc8736x_temp_attr_array[] = {
810 TEMP_UNIT_ATTRS(0),
811 TEMP_UNIT_ATTRS(1),
812 TEMP_UNIT_ATTRS(2),
813 /* include the few miscellaneous atts here */
814 &dev_attr_alarms_temp.attr,
815 NULL
816};
817static const struct attribute_group pc8736x_temp_group = {
818 .attrs = pc8736x_temp_attr_array,
819};
820
738/* 821/*
739 * Device detection, registration and update 822 * Device detection, registration and update
740 */ 823 */
@@ -935,60 +1018,69 @@ static int pc87360_detect(struct i2c_adapter *adapter)
935 pc87360_init_client(client, use_thermistors); 1018 pc87360_init_client(client, use_thermistors);
936 } 1019 }
937 1020
938 /* Register sysfs hooks */ 1021 /* Register all-or-nothing sysfs groups */
939 data->class_dev = hwmon_device_register(&client->dev); 1022
940 if (IS_ERR(data->class_dev)) { 1023 if (data->innr &&
941 err = PTR_ERR(data->class_dev); 1024 (err = sysfs_create_group(&client->dev.kobj,
1025 &pc8736x_vin_group)))
942 goto ERROR3; 1026 goto ERROR3;
943 }
944 1027
945 if (data->innr) { 1028 if (data->innr == 14 &&
946 for (i = 0; i < 11; i++) { 1029 (err = sysfs_create_group(&client->dev.kobj,
947 device_create_file(dev, &in_input[i].dev_attr); 1030 &pc8736x_therm_group)))
948 device_create_file(dev, &in_min[i].dev_attr); 1031 goto ERROR3;
949 device_create_file(dev, &in_max[i].dev_attr); 1032
950 device_create_file(dev, &in_status[i].dev_attr); 1033 /* create device attr-files for varying sysfs groups */
951 }
952 device_create_file(dev, &dev_attr_cpu0_vid);
953 device_create_file(dev, &dev_attr_vrm);
954 device_create_file(dev, &dev_attr_alarms_in);
955 }
956 1034
957 if (data->tempnr) { 1035 if (data->tempnr) {
958 for (i = 0; i < data->tempnr; i++) { 1036 for (i = 0; i < data->tempnr; i++) {
959 device_create_file(dev, &temp_input[i].dev_attr); 1037 if ((err = device_create_file(dev,
960 device_create_file(dev, &temp_min[i].dev_attr); 1038 &temp_input[i].dev_attr))
961 device_create_file(dev, &temp_max[i].dev_attr); 1039 || (err = device_create_file(dev,
962 device_create_file(dev, &temp_crit[i].dev_attr); 1040 &temp_min[i].dev_attr))
963 device_create_file(dev, &temp_status[i].dev_attr); 1041 || (err = device_create_file(dev,
964 } 1042 &temp_max[i].dev_attr))
965 device_create_file(dev, &dev_attr_alarms_temp); 1043 || (err = device_create_file(dev,
966 } 1044 &temp_crit[i].dev_attr))
967 1045 || (err = device_create_file(dev,
968 if (data->innr == 14) { 1046 &temp_status[i].dev_attr)))
969 for (i = 0; i < 3; i++) { 1047 goto ERROR3;
970 device_create_file(dev, &therm_input[i].dev_attr);
971 device_create_file(dev, &therm_min[i].dev_attr);
972 device_create_file(dev, &therm_max[i].dev_attr);
973 device_create_file(dev, &therm_crit[i].dev_attr);
974 device_create_file(dev, &therm_status[i].dev_attr);
975 } 1048 }
1049 if ((err = device_create_file(dev, &dev_attr_alarms_temp)))
1050 goto ERROR3;
976 } 1051 }
977 1052
978 for (i = 0; i < data->fannr; i++) { 1053 for (i = 0; i < data->fannr; i++) {
979 if (FAN_CONFIG_MONITOR(data->fan_conf, i)) { 1054 if (FAN_CONFIG_MONITOR(data->fan_conf, i)
980 device_create_file(dev, &fan_input[i].dev_attr); 1055 && ((err = device_create_file(dev,
981 device_create_file(dev, &fan_min[i].dev_attr); 1056 &fan_input[i].dev_attr))
982 device_create_file(dev, &fan_div[i].dev_attr); 1057 || (err = device_create_file(dev,
983 device_create_file(dev, &fan_status[i].dev_attr); 1058 &fan_min[i].dev_attr))
984 } 1059 || (err = device_create_file(dev,
985 if (FAN_CONFIG_CONTROL(data->fan_conf, i)) 1060 &fan_div[i].dev_attr))
986 device_create_file(dev, &pwm[i].dev_attr); 1061 || (err = device_create_file(dev,
1062 &fan_status[i].dev_attr))))
1063 goto ERROR3;
1064
1065 if (FAN_CONFIG_CONTROL(data->fan_conf, i)
1066 && (err = device_create_file(dev, &pwm[i].dev_attr)))
1067 goto ERROR3;
987 } 1068 }
988 1069
1070 data->class_dev = hwmon_device_register(&client->dev);
1071 if (IS_ERR(data->class_dev)) {
1072 err = PTR_ERR(data->class_dev);
1073 goto ERROR3;
1074 }
989 return 0; 1075 return 0;
990 1076
991ERROR3: 1077ERROR3:
1078 /* can still remove groups whose members were added individually */
1079 sysfs_remove_group(&client->dev.kobj, &pc8736x_temp_group);
1080 sysfs_remove_group(&client->dev.kobj, &pc8736x_fan_group);
1081 sysfs_remove_group(&client->dev.kobj, &pc8736x_therm_group);
1082 sysfs_remove_group(&client->dev.kobj, &pc8736x_vin_group);
1083
992 i2c_detach_client(client); 1084 i2c_detach_client(client);
993ERROR2: 1085ERROR2:
994 for (i = 0; i < 3; i++) { 1086 for (i = 0; i < 3; i++) {
@@ -1008,6 +1100,11 @@ static int pc87360_detach_client(struct i2c_client *client)
1008 1100
1009 hwmon_device_unregister(data->class_dev); 1101 hwmon_device_unregister(data->class_dev);
1010 1102
1103 sysfs_remove_group(&client->dev.kobj, &pc8736x_temp_group);
1104 sysfs_remove_group(&client->dev.kobj, &pc8736x_fan_group);
1105 sysfs_remove_group(&client->dev.kobj, &pc8736x_therm_group);
1106 sysfs_remove_group(&client->dev.kobj, &pc8736x_vin_group);
1107
1011 if ((i = i2c_detach_client(client))) 1108 if ((i = i2c_detach_client(client)))
1012 return i; 1109 return i;
1013 1110
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c
index 063f71c5f07e..95a4b5d9eaf2 100644
--- a/drivers/hwmon/sis5595.c
+++ b/drivers/hwmon/sis5595.c
@@ -61,6 +61,7 @@
61#include <linux/init.h> 61#include <linux/init.h>
62#include <linux/jiffies.h> 62#include <linux/jiffies.h>
63#include <linux/mutex.h> 63#include <linux/mutex.h>
64#include <linux/sysfs.h>
64#include <asm/io.h> 65#include <asm/io.h>
65 66
66 67
@@ -200,6 +201,7 @@ static void sis5595_init_client(struct i2c_client *client);
200 201
201static struct i2c_driver sis5595_driver = { 202static struct i2c_driver sis5595_driver = {
202 .driver = { 203 .driver = {
204 .owner = THIS_MODULE,
203 .name = "sis5595", 205 .name = "sis5595",
204 }, 206 },
205 .attach_adapter = sis5595_detect, 207 .attach_adapter = sis5595_detect,
@@ -472,6 +474,50 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
472 return sprintf(buf, "%d\n", data->alarms); 474 return sprintf(buf, "%d\n", data->alarms);
473} 475}
474static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 476static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
477
478static struct attribute *sis5595_attributes[] = {
479 &dev_attr_in0_input.attr,
480 &dev_attr_in0_min.attr,
481 &dev_attr_in0_max.attr,
482 &dev_attr_in1_input.attr,
483 &dev_attr_in1_min.attr,
484 &dev_attr_in1_max.attr,
485 &dev_attr_in2_input.attr,
486 &dev_attr_in2_min.attr,
487 &dev_attr_in2_max.attr,
488 &dev_attr_in3_input.attr,
489 &dev_attr_in3_min.attr,
490 &dev_attr_in3_max.attr,
491
492 &dev_attr_fan1_input.attr,
493 &dev_attr_fan1_min.attr,
494 &dev_attr_fan1_div.attr,
495 &dev_attr_fan2_input.attr,
496 &dev_attr_fan2_min.attr,
497 &dev_attr_fan2_div.attr,
498
499 &dev_attr_alarms.attr,
500 NULL
501};
502
503static const struct attribute_group sis5595_group = {
504 .attrs = sis5595_attributes,
505};
506
507static struct attribute *sis5595_attributes_opt[] = {
508 &dev_attr_in4_input.attr,
509 &dev_attr_in4_min.attr,
510 &dev_attr_in4_max.attr,
511
512 &dev_attr_temp1_input.attr,
513 &dev_attr_temp1_max.attr,
514 &dev_attr_temp1_max_hyst.attr,
515 NULL
516};
517
518static const struct attribute_group sis5595_group_opt = {
519 .attrs = sis5595_attributes_opt,
520};
475 521
476/* This is called when the module is loaded */ 522/* This is called when the module is loaded */
477static int sis5595_detect(struct i2c_adapter *adapter) 523static int sis5595_detect(struct i2c_adapter *adapter)
@@ -565,43 +611,37 @@ static int sis5595_detect(struct i2c_adapter *adapter)
565 } 611 }
566 612
567 /* Register sysfs hooks */ 613 /* Register sysfs hooks */
614 if ((err = sysfs_create_group(&new_client->dev.kobj, &sis5595_group)))
615 goto exit_detach;
616 if (data->maxins == 4) {
617 if ((err = device_create_file(&new_client->dev,
618 &dev_attr_in4_input))
619 || (err = device_create_file(&new_client->dev,
620 &dev_attr_in4_min))
621 || (err = device_create_file(&new_client->dev,
622 &dev_attr_in4_max)))
623 goto exit_remove_files;
624 } else {
625 if ((err = device_create_file(&new_client->dev,
626 &dev_attr_temp1_input))
627 || (err = device_create_file(&new_client->dev,
628 &dev_attr_temp1_max))
629 || (err = device_create_file(&new_client->dev,
630 &dev_attr_temp1_max_hyst)))
631 goto exit_remove_files;
632 }
633
568 data->class_dev = hwmon_device_register(&new_client->dev); 634 data->class_dev = hwmon_device_register(&new_client->dev);
569 if (IS_ERR(data->class_dev)) { 635 if (IS_ERR(data->class_dev)) {
570 err = PTR_ERR(data->class_dev); 636 err = PTR_ERR(data->class_dev);
571 goto exit_detach; 637 goto exit_remove_files;
572 } 638 }
573 639
574 device_create_file(&new_client->dev, &dev_attr_in0_input);
575 device_create_file(&new_client->dev, &dev_attr_in0_min);
576 device_create_file(&new_client->dev, &dev_attr_in0_max);
577 device_create_file(&new_client->dev, &dev_attr_in1_input);
578 device_create_file(&new_client->dev, &dev_attr_in1_min);
579 device_create_file(&new_client->dev, &dev_attr_in1_max);
580 device_create_file(&new_client->dev, &dev_attr_in2_input);
581 device_create_file(&new_client->dev, &dev_attr_in2_min);
582 device_create_file(&new_client->dev, &dev_attr_in2_max);
583 device_create_file(&new_client->dev, &dev_attr_in3_input);
584 device_create_file(&new_client->dev, &dev_attr_in3_min);
585 device_create_file(&new_client->dev, &dev_attr_in3_max);
586 if (data->maxins == 4) {
587 device_create_file(&new_client->dev, &dev_attr_in4_input);
588 device_create_file(&new_client->dev, &dev_attr_in4_min);
589 device_create_file(&new_client->dev, &dev_attr_in4_max);
590 }
591 device_create_file(&new_client->dev, &dev_attr_fan1_input);
592 device_create_file(&new_client->dev, &dev_attr_fan1_min);
593 device_create_file(&new_client->dev, &dev_attr_fan1_div);
594 device_create_file(&new_client->dev, &dev_attr_fan2_input);
595 device_create_file(&new_client->dev, &dev_attr_fan2_min);
596 device_create_file(&new_client->dev, &dev_attr_fan2_div);
597 device_create_file(&new_client->dev, &dev_attr_alarms);
598 if (data->maxins == 3) {
599 device_create_file(&new_client->dev, &dev_attr_temp1_input);
600 device_create_file(&new_client->dev, &dev_attr_temp1_max);
601 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
602 }
603 return 0; 640 return 0;
604 641
642exit_remove_files:
643 sysfs_remove_group(&new_client->dev.kobj, &sis5595_group);
644 sysfs_remove_group(&new_client->dev.kobj, &sis5595_group_opt);
605exit_detach: 645exit_detach:
606 i2c_detach_client(new_client); 646 i2c_detach_client(new_client);
607exit_free: 647exit_free:
@@ -618,6 +658,8 @@ static int sis5595_detach_client(struct i2c_client *client)
618 int err; 658 int err;
619 659
620 hwmon_device_unregister(data->class_dev); 660 hwmon_device_unregister(data->class_dev);
661 sysfs_remove_group(&client->dev.kobj, &sis5595_group);
662 sysfs_remove_group(&client->dev.kobj, &sis5595_group_opt);
621 663
622 if ((err = i2c_detach_client(client))) 664 if ((err = i2c_detach_client(client)))
623 return err; 665 return err;
diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c
index b6086186d225..72b0e2d8650c 100644
--- a/drivers/hwmon/smsc47b397.c
+++ b/drivers/hwmon/smsc47b397.c
@@ -176,9 +176,6 @@ sysfs_temp(2);
176sysfs_temp(3); 176sysfs_temp(3);
177sysfs_temp(4); 177sysfs_temp(4);
178 178
179#define device_create_file_temp(client, num) \
180 device_create_file(&client->dev, &dev_attr_temp##num##_input)
181
182/* FAN: 1 RPM/bit 179/* FAN: 1 RPM/bit
183 REG: count of 90kHz pulses / revolution */ 180 REG: count of 90kHz pulses / revolution */
184static int fan_from_reg(u16 reg) 181static int fan_from_reg(u16 reg)
@@ -205,8 +202,22 @@ sysfs_fan(2);
205sysfs_fan(3); 202sysfs_fan(3);
206sysfs_fan(4); 203sysfs_fan(4);
207 204
208#define device_create_file_fan(client, num) \ 205static struct attribute *smsc47b397_attributes[] = {
209 device_create_file(&client->dev, &dev_attr_fan##num##_input) 206 &dev_attr_temp1_input.attr,
207 &dev_attr_temp2_input.attr,
208 &dev_attr_temp3_input.attr,
209 &dev_attr_temp4_input.attr,
210 &dev_attr_fan1_input.attr,
211 &dev_attr_fan2_input.attr,
212 &dev_attr_fan3_input.attr,
213 &dev_attr_fan4_input.attr,
214
215 NULL
216};
217
218static const struct attribute_group smsc47b397_group = {
219 .attrs = smsc47b397_attributes,
220};
210 221
211static int smsc47b397_detach_client(struct i2c_client *client) 222static int smsc47b397_detach_client(struct i2c_client *client)
212{ 223{
@@ -214,6 +225,7 @@ static int smsc47b397_detach_client(struct i2c_client *client)
214 int err; 225 int err;
215 226
216 hwmon_device_unregister(data->class_dev); 227 hwmon_device_unregister(data->class_dev);
228 sysfs_remove_group(&client->dev.kobj, &smsc47b397_group);
217 229
218 if ((err = i2c_detach_client(client))) 230 if ((err = i2c_detach_client(client)))
219 return err; 231 return err;
@@ -228,6 +240,7 @@ static int smsc47b397_detect(struct i2c_adapter *adapter);
228 240
229static struct i2c_driver smsc47b397_driver = { 241static struct i2c_driver smsc47b397_driver = {
230 .driver = { 242 .driver = {
243 .owner = THIS_MODULE,
231 .name = "smsc47b397", 244 .name = "smsc47b397",
232 }, 245 },
233 .attach_adapter = smsc47b397_detect, 246 .attach_adapter = smsc47b397_detect,
@@ -267,24 +280,19 @@ static int smsc47b397_detect(struct i2c_adapter *adapter)
267 if ((err = i2c_attach_client(new_client))) 280 if ((err = i2c_attach_client(new_client)))
268 goto error_free; 281 goto error_free;
269 282
283 if ((err = sysfs_create_group(&new_client->dev.kobj, &smsc47b397_group)))
284 goto error_detach;
285
270 data->class_dev = hwmon_device_register(&new_client->dev); 286 data->class_dev = hwmon_device_register(&new_client->dev);
271 if (IS_ERR(data->class_dev)) { 287 if (IS_ERR(data->class_dev)) {
272 err = PTR_ERR(data->class_dev); 288 err = PTR_ERR(data->class_dev);
273 goto error_detach; 289 goto error_remove;
274 } 290 }
275 291
276 device_create_file_temp(new_client, 1);
277 device_create_file_temp(new_client, 2);
278 device_create_file_temp(new_client, 3);
279 device_create_file_temp(new_client, 4);
280
281 device_create_file_fan(new_client, 1);
282 device_create_file_fan(new_client, 2);
283 device_create_file_fan(new_client, 3);
284 device_create_file_fan(new_client, 4);
285
286 return 0; 292 return 0;
287 293
294error_remove:
295 sysfs_remove_group(&new_client->dev.kobj, &smsc47b397_group);
288error_detach: 296error_detach:
289 i2c_detach_client(new_client); 297 i2c_detach_client(new_client);
290error_free: 298error_free:
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c
index 825e8f72698f..47132fd26b1b 100644
--- a/drivers/hwmon/smsc47m1.c
+++ b/drivers/hwmon/smsc47m1.c
@@ -35,6 +35,7 @@
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/mutex.h> 37#include <linux/mutex.h>
38#include <linux/sysfs.h>
38#include <asm/io.h> 39#include <asm/io.h>
39 40
40/* Address is autodetected, there is no default value */ 41/* Address is autodetected, there is no default value */
@@ -128,6 +129,7 @@ static struct smsc47m1_data *smsc47m1_update_device(struct device *dev,
128 129
129static struct i2c_driver smsc47m1_driver = { 130static struct i2c_driver smsc47m1_driver = {
130 .driver = { 131 .driver = {
132 .owner = THIS_MODULE,
131 .name = "smsc47m1", 133 .name = "smsc47m1",
132 }, 134 },
133 .attach_adapter = smsc47m1_detect, 135 .attach_adapter = smsc47m1_detect,
@@ -346,6 +348,30 @@ fan_present(2);
346 348
347static DEVICE_ATTR(alarms, S_IRUGO, get_alarms, NULL); 349static DEVICE_ATTR(alarms, S_IRUGO, get_alarms, NULL);
348 350
351/* Almost all sysfs files may or may not be created depending on the chip
352 setup so we create them individually. It is still convenient to define a
353 group to remove them all at once. */
354static struct attribute *smsc47m1_attributes[] = {
355 &dev_attr_fan1_input.attr,
356 &dev_attr_fan1_min.attr,
357 &dev_attr_fan1_div.attr,
358 &dev_attr_fan2_input.attr,
359 &dev_attr_fan2_min.attr,
360 &dev_attr_fan2_div.attr,
361
362 &dev_attr_pwm1.attr,
363 &dev_attr_pwm1_enable.attr,
364 &dev_attr_pwm2.attr,
365 &dev_attr_pwm2_enable.attr,
366
367 &dev_attr_alarms.attr,
368 NULL
369};
370
371static const struct attribute_group smsc47m1_group = {
372 .attrs = smsc47m1_attributes,
373};
374
349static int __init smsc47m1_find(unsigned short *addr) 375static int __init smsc47m1_find(unsigned short *addr)
350{ 376{
351 u8 val; 377 u8 val;
@@ -428,7 +454,8 @@ static int smsc47m1_detect(struct i2c_adapter *adapter)
428 pwm2 = (smsc47m1_read_value(new_client, SMSC47M1_REG_PPIN(1)) & 0x05) 454 pwm2 = (smsc47m1_read_value(new_client, SMSC47M1_REG_PPIN(1)) & 0x05)
429 == 0x04; 455 == 0x04;
430 if (!(fan1 || fan2 || pwm1 || pwm2)) { 456 if (!(fan1 || fan2 || pwm1 || pwm2)) {
431 dev_warn(&new_client->dev, "Device is not configured, will not use\n"); 457 dev_warn(&adapter->dev, "Device at 0x%x is not configured, "
458 "will not use\n", new_client->addr);
432 err = -ENODEV; 459 err = -ENODEV;
433 goto error_free; 460 goto error_free;
434 } 461 }
@@ -445,46 +472,62 @@ static int smsc47m1_detect(struct i2c_adapter *adapter)
445 smsc47m1_update_device(&new_client->dev, 1); 472 smsc47m1_update_device(&new_client->dev, 1);
446 473
447 /* Register sysfs hooks */ 474 /* Register sysfs hooks */
448 data->class_dev = hwmon_device_register(&new_client->dev);
449 if (IS_ERR(data->class_dev)) {
450 err = PTR_ERR(data->class_dev);
451 goto error_detach;
452 }
453
454 if (fan1) { 475 if (fan1) {
455 device_create_file(&new_client->dev, &dev_attr_fan1_input); 476 if ((err = device_create_file(&new_client->dev,
456 device_create_file(&new_client->dev, &dev_attr_fan1_min); 477 &dev_attr_fan1_input))
457 device_create_file(&new_client->dev, &dev_attr_fan1_div); 478 || (err = device_create_file(&new_client->dev,
479 &dev_attr_fan1_min))
480 || (err = device_create_file(&new_client->dev,
481 &dev_attr_fan1_div)))
482 goto error_remove_files;
458 } else 483 } else
459 dev_dbg(&new_client->dev, "Fan 1 not enabled by hardware, " 484 dev_dbg(&new_client->dev, "Fan 1 not enabled by hardware, "
460 "skipping\n"); 485 "skipping\n");
461 486
462 if (fan2) { 487 if (fan2) {
463 device_create_file(&new_client->dev, &dev_attr_fan2_input); 488 if ((err = device_create_file(&new_client->dev,
464 device_create_file(&new_client->dev, &dev_attr_fan2_min); 489 &dev_attr_fan2_input))
465 device_create_file(&new_client->dev, &dev_attr_fan2_div); 490 || (err = device_create_file(&new_client->dev,
491 &dev_attr_fan2_min))
492 || (err = device_create_file(&new_client->dev,
493 &dev_attr_fan2_div)))
494 goto error_remove_files;
466 } else 495 } else
467 dev_dbg(&new_client->dev, "Fan 2 not enabled by hardware, " 496 dev_dbg(&new_client->dev, "Fan 2 not enabled by hardware, "
468 "skipping\n"); 497 "skipping\n");
469 498
470 if (pwm1) { 499 if (pwm1) {
471 device_create_file(&new_client->dev, &dev_attr_pwm1); 500 if ((err = device_create_file(&new_client->dev,
472 device_create_file(&new_client->dev, &dev_attr_pwm1_enable); 501 &dev_attr_pwm1))
502 || (err = device_create_file(&new_client->dev,
503 &dev_attr_pwm1_enable)))
504 goto error_remove_files;
473 } else 505 } else
474 dev_dbg(&new_client->dev, "PWM 1 not enabled by hardware, " 506 dev_dbg(&new_client->dev, "PWM 1 not enabled by hardware, "
475 "skipping\n"); 507 "skipping\n");
476 if (pwm2) { 508 if (pwm2) {
477 device_create_file(&new_client->dev, &dev_attr_pwm2); 509 if ((err = device_create_file(&new_client->dev,
478 device_create_file(&new_client->dev, &dev_attr_pwm2_enable); 510 &dev_attr_pwm2))
511 || (err = device_create_file(&new_client->dev,
512 &dev_attr_pwm2_enable)))
513 goto error_remove_files;
479 } else 514 } else
480 dev_dbg(&new_client->dev, "PWM 2 not enabled by hardware, " 515 dev_dbg(&new_client->dev, "PWM 2 not enabled by hardware, "
481 "skipping\n"); 516 "skipping\n");
482 517
483 device_create_file(&new_client->dev, &dev_attr_alarms); 518 if ((err = device_create_file(&new_client->dev, &dev_attr_alarms)))
519 goto error_remove_files;
520
521 data->class_dev = hwmon_device_register(&new_client->dev);
522 if (IS_ERR(data->class_dev)) {
523 err = PTR_ERR(data->class_dev);
524 goto error_remove_files;
525 }
484 526
485 return 0; 527 return 0;
486 528
487error_detach: 529error_remove_files:
530 sysfs_remove_group(&new_client->dev.kobj, &smsc47m1_group);
488 i2c_detach_client(new_client); 531 i2c_detach_client(new_client);
489error_free: 532error_free:
490 kfree(data); 533 kfree(data);
@@ -499,6 +542,7 @@ static int smsc47m1_detach_client(struct i2c_client *client)
499 int err; 542 int err;
500 543
501 hwmon_device_unregister(data->class_dev); 544 hwmon_device_unregister(data->class_dev);
545 sysfs_remove_group(&client->dev.kobj, &smsc47m1_group);
502 546
503 if ((err = i2c_detach_client(client))) 547 if ((err = i2c_detach_client(client)))
504 return err; 548 return err;
diff --git a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c
index bdc4570acf9a..a6833f437395 100644
--- a/drivers/hwmon/smsc47m192.c
+++ b/drivers/hwmon/smsc47m192.c
@@ -30,6 +30,7 @@
30#include <linux/hwmon-sysfs.h> 30#include <linux/hwmon-sysfs.h>
31#include <linux/hwmon-vid.h> 31#include <linux/hwmon-vid.h>
32#include <linux/err.h> 32#include <linux/err.h>
33#include <linux/sysfs.h>
33 34
34/* Addresses to scan */ 35/* Addresses to scan */
35static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; 36static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
@@ -370,6 +371,75 @@ static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 0x0200);
370static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 0x0400); 371static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 0x0400);
371static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 0x0800); 372static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 0x0800);
372 373
374static struct attribute *smsc47m192_attributes[] = {
375 &sensor_dev_attr_in0_input.dev_attr.attr,
376 &sensor_dev_attr_in0_min.dev_attr.attr,
377 &sensor_dev_attr_in0_max.dev_attr.attr,
378 &sensor_dev_attr_in0_alarm.dev_attr.attr,
379 &sensor_dev_attr_in1_input.dev_attr.attr,
380 &sensor_dev_attr_in1_min.dev_attr.attr,
381 &sensor_dev_attr_in1_max.dev_attr.attr,
382 &sensor_dev_attr_in1_alarm.dev_attr.attr,
383 &sensor_dev_attr_in2_input.dev_attr.attr,
384 &sensor_dev_attr_in2_min.dev_attr.attr,
385 &sensor_dev_attr_in2_max.dev_attr.attr,
386 &sensor_dev_attr_in2_alarm.dev_attr.attr,
387 &sensor_dev_attr_in3_input.dev_attr.attr,
388 &sensor_dev_attr_in3_min.dev_attr.attr,
389 &sensor_dev_attr_in3_max.dev_attr.attr,
390 &sensor_dev_attr_in3_alarm.dev_attr.attr,
391 &sensor_dev_attr_in5_input.dev_attr.attr,
392 &sensor_dev_attr_in5_min.dev_attr.attr,
393 &sensor_dev_attr_in5_max.dev_attr.attr,
394 &sensor_dev_attr_in5_alarm.dev_attr.attr,
395 &sensor_dev_attr_in6_input.dev_attr.attr,
396 &sensor_dev_attr_in6_min.dev_attr.attr,
397 &sensor_dev_attr_in6_max.dev_attr.attr,
398 &sensor_dev_attr_in6_alarm.dev_attr.attr,
399 &sensor_dev_attr_in7_input.dev_attr.attr,
400 &sensor_dev_attr_in7_min.dev_attr.attr,
401 &sensor_dev_attr_in7_max.dev_attr.attr,
402 &sensor_dev_attr_in7_alarm.dev_attr.attr,
403
404 &sensor_dev_attr_temp1_input.dev_attr.attr,
405 &sensor_dev_attr_temp1_max.dev_attr.attr,
406 &sensor_dev_attr_temp1_min.dev_attr.attr,
407 &sensor_dev_attr_temp1_offset.dev_attr.attr,
408 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
409 &sensor_dev_attr_temp2_input.dev_attr.attr,
410 &sensor_dev_attr_temp2_max.dev_attr.attr,
411 &sensor_dev_attr_temp2_min.dev_attr.attr,
412 &sensor_dev_attr_temp2_offset.dev_attr.attr,
413 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
414 &sensor_dev_attr_temp2_input_fault.dev_attr.attr,
415 &sensor_dev_attr_temp3_input.dev_attr.attr,
416 &sensor_dev_attr_temp3_max.dev_attr.attr,
417 &sensor_dev_attr_temp3_min.dev_attr.attr,
418 &sensor_dev_attr_temp3_offset.dev_attr.attr,
419 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
420 &sensor_dev_attr_temp3_input_fault.dev_attr.attr,
421
422 &dev_attr_cpu0_vid.attr,
423 &dev_attr_vrm.attr,
424 NULL
425};
426
427static const struct attribute_group smsc47m192_group = {
428 .attrs = smsc47m192_attributes,
429};
430
431static struct attribute *smsc47m192_attributes_in4[] = {
432 &sensor_dev_attr_in4_input.dev_attr.attr,
433 &sensor_dev_attr_in4_min.dev_attr.attr,
434 &sensor_dev_attr_in4_max.dev_attr.attr,
435 &sensor_dev_attr_in4_alarm.dev_attr.attr,
436 NULL
437};
438
439static const struct attribute_group smsc47m192_group_in4 = {
440 .attrs = smsc47m192_attributes_in4,
441};
442
373/* This function is called when: 443/* This function is called when:
374 * smsc47m192_driver is inserted (when this module is loaded), for each 444 * smsc47m192_driver is inserted (when this module is loaded), for each
375 available adapter 445 available adapter
@@ -471,80 +541,28 @@ static int smsc47m192_detect(struct i2c_adapter *adapter, int address,
471 smsc47m192_init_client(client); 541 smsc47m192_init_client(client);
472 542
473 /* Register sysfs hooks */ 543 /* Register sysfs hooks */
474 data->class_dev = hwmon_device_register(&client->dev); 544 if ((err = sysfs_create_group(&client->dev.kobj, &smsc47m192_group)))
475 if (IS_ERR(data->class_dev)) {
476 err = PTR_ERR(data->class_dev);
477 goto exit_detach; 545 goto exit_detach;
478 }
479
480 device_create_file(&client->dev, &sensor_dev_attr_in0_input.dev_attr);
481 device_create_file(&client->dev, &sensor_dev_attr_in0_min.dev_attr);
482 device_create_file(&client->dev, &sensor_dev_attr_in0_max.dev_attr);
483 device_create_file(&client->dev, &sensor_dev_attr_in0_alarm.dev_attr);
484 device_create_file(&client->dev, &sensor_dev_attr_in1_input.dev_attr);
485 device_create_file(&client->dev, &sensor_dev_attr_in1_min.dev_attr);
486 device_create_file(&client->dev, &sensor_dev_attr_in1_max.dev_attr);
487 device_create_file(&client->dev, &sensor_dev_attr_in1_alarm.dev_attr);
488 device_create_file(&client->dev, &sensor_dev_attr_in2_input.dev_attr);
489 device_create_file(&client->dev, &sensor_dev_attr_in2_min.dev_attr);
490 device_create_file(&client->dev, &sensor_dev_attr_in2_max.dev_attr);
491 device_create_file(&client->dev, &sensor_dev_attr_in2_alarm.dev_attr);
492 device_create_file(&client->dev, &sensor_dev_attr_in3_input.dev_attr);
493 device_create_file(&client->dev, &sensor_dev_attr_in3_min.dev_attr);
494 device_create_file(&client->dev, &sensor_dev_attr_in3_max.dev_attr);
495 device_create_file(&client->dev, &sensor_dev_attr_in3_alarm.dev_attr);
496 546
497 /* Pin 110 is either in4 (+12V) or VID4 */ 547 /* Pin 110 is either in4 (+12V) or VID4 */
498 config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG); 548 config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG);
499 if (!(config & 0x20)) { 549 if (!(config & 0x20)) {
500 device_create_file(&client->dev, 550 if ((err = sysfs_create_group(&client->dev.kobj,
501 &sensor_dev_attr_in4_input.dev_attr); 551 &smsc47m192_group_in4)))
502 device_create_file(&client->dev, 552 goto exit_remove_files;
503 &sensor_dev_attr_in4_min.dev_attr); 553 }
504 device_create_file(&client->dev, 554
505 &sensor_dev_attr_in4_max.dev_attr); 555 data->class_dev = hwmon_device_register(&client->dev);
506 device_create_file(&client->dev, 556 if (IS_ERR(data->class_dev)) {
507 &sensor_dev_attr_in4_alarm.dev_attr); 557 err = PTR_ERR(data->class_dev);
558 goto exit_remove_files;
508 } 559 }
509 device_create_file(&client->dev, &sensor_dev_attr_in5_input.dev_attr);
510 device_create_file(&client->dev, &sensor_dev_attr_in5_min.dev_attr);
511 device_create_file(&client->dev, &sensor_dev_attr_in5_max.dev_attr);
512 device_create_file(&client->dev, &sensor_dev_attr_in5_alarm.dev_attr);
513 device_create_file(&client->dev, &sensor_dev_attr_in6_input.dev_attr);
514 device_create_file(&client->dev, &sensor_dev_attr_in6_min.dev_attr);
515 device_create_file(&client->dev, &sensor_dev_attr_in6_max.dev_attr);
516 device_create_file(&client->dev, &sensor_dev_attr_in6_alarm.dev_attr);
517 device_create_file(&client->dev, &sensor_dev_attr_in7_input.dev_attr);
518 device_create_file(&client->dev, &sensor_dev_attr_in7_min.dev_attr);
519 device_create_file(&client->dev, &sensor_dev_attr_in7_max.dev_attr);
520 device_create_file(&client->dev, &sensor_dev_attr_in7_alarm.dev_attr);
521 device_create_file(&client->dev, &sensor_dev_attr_temp1_input.dev_attr);
522 device_create_file(&client->dev, &sensor_dev_attr_temp1_max.dev_attr);
523 device_create_file(&client->dev, &sensor_dev_attr_temp1_min.dev_attr);
524 device_create_file(&client->dev,
525 &sensor_dev_attr_temp1_offset.dev_attr);
526 device_create_file(&client->dev, &sensor_dev_attr_temp1_alarm.dev_attr);
527 device_create_file(&client->dev, &sensor_dev_attr_temp2_input.dev_attr);
528 device_create_file(&client->dev, &sensor_dev_attr_temp2_max.dev_attr);
529 device_create_file(&client->dev, &sensor_dev_attr_temp2_min.dev_attr);
530 device_create_file(&client->dev,
531 &sensor_dev_attr_temp2_offset.dev_attr);
532 device_create_file(&client->dev, &sensor_dev_attr_temp2_alarm.dev_attr);
533 device_create_file(&client->dev,
534 &sensor_dev_attr_temp2_input_fault.dev_attr);
535 device_create_file(&client->dev, &sensor_dev_attr_temp3_input.dev_attr);
536 device_create_file(&client->dev, &sensor_dev_attr_temp3_max.dev_attr);
537 device_create_file(&client->dev, &sensor_dev_attr_temp3_min.dev_attr);
538 device_create_file(&client->dev,
539 &sensor_dev_attr_temp3_offset.dev_attr);
540 device_create_file(&client->dev, &sensor_dev_attr_temp3_alarm.dev_attr);
541 device_create_file(&client->dev,
542 &sensor_dev_attr_temp3_input_fault.dev_attr);
543 device_create_file(&client->dev, &dev_attr_cpu0_vid);
544 device_create_file(&client->dev, &dev_attr_vrm);
545 560
546 return 0; 561 return 0;
547 562
563exit_remove_files:
564 sysfs_remove_group(&client->dev.kobj, &smsc47m192_group);
565 sysfs_remove_group(&client->dev.kobj, &smsc47m192_group_in4);
548exit_detach: 566exit_detach:
549 i2c_detach_client(client); 567 i2c_detach_client(client);
550exit_free: 568exit_free:
@@ -559,6 +577,8 @@ static int smsc47m192_detach_client(struct i2c_client *client)
559 int err; 577 int err;
560 578
561 hwmon_device_unregister(data->class_dev); 579 hwmon_device_unregister(data->class_dev);
580 sysfs_remove_group(&client->dev.kobj, &smsc47m192_group);
581 sysfs_remove_group(&client->dev.kobj, &smsc47m192_group_in4);
562 582
563 if ((err = i2c_detach_client(client))) 583 if ((err = i2c_detach_client(client)))
564 return err; 584 return err;
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c
index 166298f1f190..f8acada0537a 100644
--- a/drivers/hwmon/via686a.c
+++ b/drivers/hwmon/via686a.c
@@ -40,6 +40,7 @@
40#include <linux/err.h> 40#include <linux/err.h>
41#include <linux/init.h> 41#include <linux/init.h>
42#include <linux/mutex.h> 42#include <linux/mutex.h>
43#include <linux/sysfs.h>
43#include <asm/io.h> 44#include <asm/io.h>
44 45
45 46
@@ -570,10 +571,53 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
570} 571}
571static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 572static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
572 573
574static struct attribute *via686a_attributes[] = {
575 &dev_attr_in0_input.attr,
576 &dev_attr_in1_input.attr,
577 &dev_attr_in2_input.attr,
578 &dev_attr_in3_input.attr,
579 &dev_attr_in4_input.attr,
580 &dev_attr_in0_min.attr,
581 &dev_attr_in1_min.attr,
582 &dev_attr_in2_min.attr,
583 &dev_attr_in3_min.attr,
584 &dev_attr_in4_min.attr,
585 &dev_attr_in0_max.attr,
586 &dev_attr_in1_max.attr,
587 &dev_attr_in2_max.attr,
588 &dev_attr_in3_max.attr,
589 &dev_attr_in4_max.attr,
590
591 &dev_attr_temp1_input.attr,
592 &dev_attr_temp2_input.attr,
593 &dev_attr_temp3_input.attr,
594 &dev_attr_temp1_max.attr,
595 &dev_attr_temp2_max.attr,
596 &dev_attr_temp3_max.attr,
597 &dev_attr_temp1_max_hyst.attr,
598 &dev_attr_temp2_max_hyst.attr,
599 &dev_attr_temp3_max_hyst.attr,
600
601 &dev_attr_fan1_input.attr,
602 &dev_attr_fan2_input.attr,
603 &dev_attr_fan1_min.attr,
604 &dev_attr_fan2_min.attr,
605 &dev_attr_fan1_div.attr,
606 &dev_attr_fan2_div.attr,
607
608 &dev_attr_alarms.attr,
609 NULL
610};
611
612static const struct attribute_group via686a_group = {
613 .attrs = via686a_attributes,
614};
615
573/* The driver. I choose to use type i2c_driver, as at is identical to both 616/* The driver. I choose to use type i2c_driver, as at is identical to both
574 smbus_driver and isa_driver, and clients could be of either kind */ 617 smbus_driver and isa_driver, and clients could be of either kind */
575static struct i2c_driver via686a_driver = { 618static struct i2c_driver via686a_driver = {
576 .driver = { 619 .driver = {
620 .owner = THIS_MODULE,
577 .name = "via686a", 621 .name = "via686a",
578 }, 622 },
579 .attach_adapter = via686a_detect, 623 .attach_adapter = via686a_detect,
@@ -649,46 +693,19 @@ static int via686a_detect(struct i2c_adapter *adapter)
649 via686a_init_client(new_client); 693 via686a_init_client(new_client);
650 694
651 /* Register sysfs hooks */ 695 /* Register sysfs hooks */
696 if ((err = sysfs_create_group(&new_client->dev.kobj, &via686a_group)))
697 goto exit_detach;
698
652 data->class_dev = hwmon_device_register(&new_client->dev); 699 data->class_dev = hwmon_device_register(&new_client->dev);
653 if (IS_ERR(data->class_dev)) { 700 if (IS_ERR(data->class_dev)) {
654 err = PTR_ERR(data->class_dev); 701 err = PTR_ERR(data->class_dev);
655 goto exit_detach; 702 goto exit_remove_files;
656 } 703 }
657 704
658 device_create_file(&new_client->dev, &dev_attr_in0_input);
659 device_create_file(&new_client->dev, &dev_attr_in1_input);
660 device_create_file(&new_client->dev, &dev_attr_in2_input);
661 device_create_file(&new_client->dev, &dev_attr_in3_input);
662 device_create_file(&new_client->dev, &dev_attr_in4_input);
663 device_create_file(&new_client->dev, &dev_attr_in0_min);
664 device_create_file(&new_client->dev, &dev_attr_in1_min);
665 device_create_file(&new_client->dev, &dev_attr_in2_min);
666 device_create_file(&new_client->dev, &dev_attr_in3_min);
667 device_create_file(&new_client->dev, &dev_attr_in4_min);
668 device_create_file(&new_client->dev, &dev_attr_in0_max);
669 device_create_file(&new_client->dev, &dev_attr_in1_max);
670 device_create_file(&new_client->dev, &dev_attr_in2_max);
671 device_create_file(&new_client->dev, &dev_attr_in3_max);
672 device_create_file(&new_client->dev, &dev_attr_in4_max);
673 device_create_file(&new_client->dev, &dev_attr_temp1_input);
674 device_create_file(&new_client->dev, &dev_attr_temp2_input);
675 device_create_file(&new_client->dev, &dev_attr_temp3_input);
676 device_create_file(&new_client->dev, &dev_attr_temp1_max);
677 device_create_file(&new_client->dev, &dev_attr_temp2_max);
678 device_create_file(&new_client->dev, &dev_attr_temp3_max);
679 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
680 device_create_file(&new_client->dev, &dev_attr_temp2_max_hyst);
681 device_create_file(&new_client->dev, &dev_attr_temp3_max_hyst);
682 device_create_file(&new_client->dev, &dev_attr_fan1_input);
683 device_create_file(&new_client->dev, &dev_attr_fan2_input);
684 device_create_file(&new_client->dev, &dev_attr_fan1_min);
685 device_create_file(&new_client->dev, &dev_attr_fan2_min);
686 device_create_file(&new_client->dev, &dev_attr_fan1_div);
687 device_create_file(&new_client->dev, &dev_attr_fan2_div);
688 device_create_file(&new_client->dev, &dev_attr_alarms);
689
690 return 0; 705 return 0;
691 706
707exit_remove_files:
708 sysfs_remove_group(&new_client->dev.kobj, &via686a_group);
692exit_detach: 709exit_detach:
693 i2c_detach_client(new_client); 710 i2c_detach_client(new_client);
694exit_free: 711exit_free:
@@ -704,6 +721,7 @@ static int via686a_detach_client(struct i2c_client *client)
704 int err; 721 int err;
705 722
706 hwmon_device_unregister(data->class_dev); 723 hwmon_device_unregister(data->class_dev);
724 sysfs_remove_group(&client->dev.kobj, &via686a_group);
707 725
708 if ((err = i2c_detach_client(client))) 726 if ((err = i2c_detach_client(client)))
709 return err; 727 return err;
diff --git a/drivers/hwmon/vt1211.c b/drivers/hwmon/vt1211.c
new file mode 100644
index 000000000000..25cc56003d7a
--- /dev/null
+++ b/drivers/hwmon/vt1211.c
@@ -0,0 +1,1355 @@
1/*
2 * vt1211.c - driver for the VIA VT1211 Super-I/O chip integrated hardware
3 * monitoring features
4 * Copyright (C) 2006 Juerg Haefliger <juergh@gmail.com>
5 *
6 * This driver is based on the driver for kernel 2.4 by Mark D. Studebaker
7 * and its port to kernel 2.6 by Lars Ekman.
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#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/slab.h>
27#include <linux/jiffies.h>
28#include <linux/platform_device.h>
29#include <linux/hwmon.h>
30#include <linux/hwmon-sysfs.h>
31#include <linux/hwmon-vid.h>
32#include <linux/err.h>
33#include <linux/mutex.h>
34#include <asm/io.h>
35
36static int uch_config = -1;
37module_param(uch_config, int, 0);
38MODULE_PARM_DESC(uch_config, "Initialize the universal channel configuration");
39
40static int int_mode = -1;
41module_param(int_mode, int, 0);
42MODULE_PARM_DESC(int_mode, "Force the temperature interrupt mode");
43
44static struct platform_device *pdev;
45
46#define DRVNAME "vt1211"
47
48/* ---------------------------------------------------------------------
49 * Registers
50 *
51 * The sensors are defined as follows.
52 *
53 * Sensor Voltage Mode Temp Mode Notes (from the datasheet)
54 * -------- ------------ --------- --------------------------
55 * Reading 1 temp1 Intel thermal diode
56 * Reading 3 temp2 Internal thermal diode
57 * UCH1/Reading2 in0 temp3 NTC type thermistor
58 * UCH2 in1 temp4 +2.5V
59 * UCH3 in2 temp5 VccP
60 * UCH4 in3 temp6 +5V
61 * UCH5 in4 temp7 +12V
62 * 3.3V in5 Internal VDD (+3.3V)
63 *
64 * --------------------------------------------------------------------- */
65
66/* Voltages (in) numbered 0-5 (ix) */
67#define VT1211_REG_IN(ix) (0x21 + (ix))
68#define VT1211_REG_IN_MIN(ix) ((ix) == 0 ? 0x3e : 0x2a + 2 * (ix))
69#define VT1211_REG_IN_MAX(ix) ((ix) == 0 ? 0x3d : 0x29 + 2 * (ix))
70
71/* Temperatures (temp) numbered 0-6 (ix) */
72static u8 regtemp[] = {0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25};
73static u8 regtempmax[] = {0x39, 0x1d, 0x3d, 0x2b, 0x2d, 0x2f, 0x31};
74static u8 regtemphyst[] = {0x3a, 0x1e, 0x3e, 0x2c, 0x2e, 0x30, 0x32};
75
76/* Fans numbered 0-1 (ix) */
77#define VT1211_REG_FAN(ix) (0x29 + (ix))
78#define VT1211_REG_FAN_MIN(ix) (0x3b + (ix))
79#define VT1211_REG_FAN_DIV 0x47
80
81/* PWMs numbered 0-1 (ix) */
82/* Auto points numbered 0-3 (ap) */
83#define VT1211_REG_PWM(ix) (0x60 + (ix))
84#define VT1211_REG_PWM_CLK 0x50
85#define VT1211_REG_PWM_CTL 0x51
86#define VT1211_REG_PWM_AUTO_TEMP(ap) (0x55 - (ap))
87#define VT1211_REG_PWM_AUTO_PWM(ix, ap) (0x58 + 2 * (ix) - (ap))
88
89/* Miscellaneous registers */
90#define VT1211_REG_CONFIG 0x40
91#define VT1211_REG_ALARM1 0x41
92#define VT1211_REG_ALARM2 0x42
93#define VT1211_REG_VID 0x45
94#define VT1211_REG_UCH_CONFIG 0x4a
95#define VT1211_REG_TEMP1_CONFIG 0x4b
96#define VT1211_REG_TEMP2_CONFIG 0x4c
97
98/* In, temp & fan alarm bits */
99static const u8 bitalarmin[] = {11, 0, 1, 3, 8, 2, 9};
100static const u8 bitalarmtemp[] = {4, 15, 11, 0, 1, 3, 8};
101static const u8 bitalarmfan[] = {6, 7};
102
103/* ---------------------------------------------------------------------
104 * Data structures and manipulation thereof
105 * --------------------------------------------------------------------- */
106
107struct vt1211_data {
108 unsigned short addr;
109 const char *name;
110 struct class_device *class_dev;
111
112 struct mutex update_lock;
113 char valid; /* !=0 if following fields are valid */
114 unsigned long last_updated; /* In jiffies */
115
116 /* Register values */
117 u8 in[6];
118 u8 in_max[6];
119 u8 in_min[6];
120 u8 temp[7];
121 u8 temp_max[7];
122 u8 temp_hyst[7];
123 u8 fan[2];
124 u8 fan_min[2];
125 u8 fan_div[2];
126 u8 fan_ctl;
127 u8 pwm[2];
128 u8 pwm_ctl[2];
129 u8 pwm_clk;
130 u8 pwm_auto_temp[4];
131 u8 pwm_auto_pwm[2][4];
132 u8 vid; /* Read once at init time */
133 u8 vrm;
134 u8 uch_config; /* Read once at init time */
135 u16 alarms;
136};
137
138/* ix = [0-5] */
139#define ISVOLT(ix, uch_config) ((ix) > 4 ? 1 : \
140 !(((uch_config) >> ((ix) + 2)) & 1))
141
142/* ix = [0-6] */
143#define ISTEMP(ix, uch_config) ((ix) < 2 ? 1 : \
144 ((uch_config) >> (ix)) & 1)
145
146/* in5 (ix = 5) is special. It's the internal 3.3V so it's scaled in the
147 driver according to the VT1211 BIOS porting guide */
148#define IN_FROM_REG(ix, reg) ((reg) < 3 ? 0 : (ix) == 5 ? \
149 (((reg) - 3) * 15882 + 479) / 958 : \
150 (((reg) - 3) * 10000 + 479) / 958)
151#define IN_TO_REG(ix, val) (SENSORS_LIMIT((ix) == 5 ? \
152 ((val) * 958 + 7941) / 15882 + 3 : \
153 ((val) * 958 + 5000) / 10000 + 3, 0, 255))
154
155/* temp1 (ix = 0) is an intel thermal diode which is scaled in user space.
156 temp2 (ix = 1) is the internal temp diode so it's scaled in the driver
157 according to some measurements that I took on an EPIA M10000.
158 temp3-7 are thermistor based so the driver returns the voltage measured at
159 the pin (range 0V - 2.2V). */
160#define TEMP_FROM_REG(ix, reg) ((ix) == 0 ? (reg) * 1000 : \
161 (ix) == 1 ? (reg) < 51 ? 0 : \
162 ((reg) - 51) * 1000 : \
163 ((253 - (reg)) * 2200 + 105) / 210)
164#define TEMP_TO_REG(ix, val) SENSORS_LIMIT( \
165 ((ix) == 0 ? ((val) + 500) / 1000 : \
166 (ix) == 1 ? ((val) + 500) / 1000 + 51 : \
167 253 - ((val) * 210 + 1100) / 2200), 0, 255)
168
169#define DIV_FROM_REG(reg) (1 << (reg))
170
171#define RPM_FROM_REG(reg, div) (((reg) == 0) || ((reg) == 255) ? 0 : \
172 1310720 / (reg) / DIV_FROM_REG(div))
173#define RPM_TO_REG(val, div) ((val) == 0 ? 255 : \
174 SENSORS_LIMIT((1310720 / (val) / \
175 DIV_FROM_REG(div)), 1, 254))
176
177/* ---------------------------------------------------------------------
178 * Super-I/O constants and functions
179 * --------------------------------------------------------------------- */
180
181/* Configuration & data index port registers */
182#define SIO_REG_CIP 0x2e
183#define SIO_REG_DIP 0x2f
184
185/* Configuration registers */
186#define SIO_VT1211_LDN 0x07 /* logical device number */
187#define SIO_VT1211_DEVID 0x20 /* device ID */
188#define SIO_VT1211_DEVREV 0x21 /* device revision */
189#define SIO_VT1211_ACTIVE 0x30 /* HW monitor active */
190#define SIO_VT1211_BADDR 0x60 /* base I/O address */
191#define SIO_VT1211_ID 0x3c /* VT1211 device ID */
192
193/* VT1211 logical device numbers */
194#define SIO_VT1211_LDN_HWMON 0x0b /* HW monitor */
195
196static inline void superio_outb(int reg, int val)
197{
198 outb(reg, SIO_REG_CIP);
199 outb(val, SIO_REG_DIP);
200}
201
202static inline int superio_inb(int reg)
203{
204 outb(reg, SIO_REG_CIP);
205 return inb(SIO_REG_DIP);
206}
207
208static inline void superio_select(int ldn)
209{
210 outb(SIO_VT1211_LDN, SIO_REG_CIP);
211 outb(ldn, SIO_REG_DIP);
212}
213
214static inline void superio_enter(void)
215{
216 outb(0x87, SIO_REG_CIP);
217 outb(0x87, SIO_REG_CIP);
218}
219
220static inline void superio_exit(void)
221{
222 outb(0xaa, SIO_REG_CIP);
223}
224
225/* ---------------------------------------------------------------------
226 * Device I/O access
227 * --------------------------------------------------------------------- */
228
229static inline u8 vt1211_read8(struct vt1211_data *data, u8 reg)
230{
231 return inb(data->addr + reg);
232}
233
234static inline void vt1211_write8(struct vt1211_data *data, u8 reg, u8 val)
235{
236 outb(val, data->addr + reg);
237}
238
239static struct vt1211_data *vt1211_update_device(struct device *dev)
240{
241 struct vt1211_data *data = dev_get_drvdata(dev);
242 int ix, val;
243
244 mutex_lock(&data->update_lock);
245
246 /* registers cache is refreshed after 1 second */
247 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
248 /* read VID */
249 data->vid = vt1211_read8(data, VT1211_REG_VID) & 0x1f;
250
251 /* voltage (in) registers */
252 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) {
253 if (ISVOLT(ix, data->uch_config)) {
254 data->in[ix] = vt1211_read8(data,
255 VT1211_REG_IN(ix));
256 data->in_min[ix] = vt1211_read8(data,
257 VT1211_REG_IN_MIN(ix));
258 data->in_max[ix] = vt1211_read8(data,
259 VT1211_REG_IN_MAX(ix));
260 }
261 }
262
263 /* temp registers */
264 for (ix = 0; ix < ARRAY_SIZE(data->temp); ix++) {
265 if (ISTEMP(ix, data->uch_config)) {
266 data->temp[ix] = vt1211_read8(data,
267 regtemp[ix]);
268 data->temp_max[ix] = vt1211_read8(data,
269 regtempmax[ix]);
270 data->temp_hyst[ix] = vt1211_read8(data,
271 regtemphyst[ix]);
272 }
273 }
274
275 /* fan & pwm registers */
276 for (ix = 0; ix < ARRAY_SIZE(data->fan); ix++) {
277 data->fan[ix] = vt1211_read8(data,
278 VT1211_REG_FAN(ix));
279 data->fan_min[ix] = vt1211_read8(data,
280 VT1211_REG_FAN_MIN(ix));
281 data->pwm[ix] = vt1211_read8(data,
282 VT1211_REG_PWM(ix));
283 }
284 val = vt1211_read8(data, VT1211_REG_FAN_DIV);
285 data->fan_div[0] = (val >> 4) & 3;
286 data->fan_div[1] = (val >> 6) & 3;
287 data->fan_ctl = val & 0xf;
288
289 val = vt1211_read8(data, VT1211_REG_PWM_CTL);
290 data->pwm_ctl[0] = val & 0xf;
291 data->pwm_ctl[1] = (val >> 4) & 0xf;
292
293 data->pwm_clk = vt1211_read8(data, VT1211_REG_PWM_CLK);
294
295 /* pwm & temp auto point registers */
296 data->pwm_auto_pwm[0][1] = vt1211_read8(data,
297 VT1211_REG_PWM_AUTO_PWM(0, 1));
298 data->pwm_auto_pwm[0][2] = vt1211_read8(data,
299 VT1211_REG_PWM_AUTO_PWM(0, 2));
300 data->pwm_auto_pwm[1][1] = vt1211_read8(data,
301 VT1211_REG_PWM_AUTO_PWM(1, 1));
302 data->pwm_auto_pwm[1][2] = vt1211_read8(data,
303 VT1211_REG_PWM_AUTO_PWM(1, 2));
304 for (ix = 0; ix < ARRAY_SIZE(data->pwm_auto_temp); ix++) {
305 data->pwm_auto_temp[ix] = vt1211_read8(data,
306 VT1211_REG_PWM_AUTO_TEMP(ix));
307 }
308
309 /* alarm registers */
310 data->alarms = (vt1211_read8(data, VT1211_REG_ALARM2) << 8) |
311 vt1211_read8(data, VT1211_REG_ALARM1);
312
313 data->last_updated = jiffies;
314 data->valid = 1;
315 }
316
317 mutex_unlock(&data->update_lock);
318
319 return data;
320}
321
322/* ---------------------------------------------------------------------
323 * Voltage sysfs interfaces
324 * ix = [0-5]
325 * --------------------------------------------------------------------- */
326
327#define SHOW_IN_INPUT 0
328#define SHOW_SET_IN_MIN 1
329#define SHOW_SET_IN_MAX 2
330#define SHOW_IN_ALARM 3
331
332static ssize_t show_in(struct device *dev, struct device_attribute *attr,
333 char *buf)
334{
335 struct vt1211_data *data = vt1211_update_device(dev);
336 struct sensor_device_attribute_2 *sensor_attr_2 =
337 to_sensor_dev_attr_2(attr);
338 int ix = sensor_attr_2->index;
339 int fn = sensor_attr_2->nr;
340 int res;
341
342 switch (fn) {
343 case SHOW_IN_INPUT:
344 res = IN_FROM_REG(ix, data->in[ix]);
345 break;
346 case SHOW_SET_IN_MIN:
347 res = IN_FROM_REG(ix, data->in_min[ix]);
348 break;
349 case SHOW_SET_IN_MAX:
350 res = IN_FROM_REG(ix, data->in_max[ix]);
351 break;
352 case SHOW_IN_ALARM:
353 res = (data->alarms >> bitalarmin[ix]) & 1;
354 break;
355 default:
356 res = 0;
357 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
358 }
359
360 return sprintf(buf, "%d\n", res);
361}
362
363static ssize_t set_in(struct device *dev, struct device_attribute *attr,
364 const char *buf, size_t count)
365{
366 struct vt1211_data *data = dev_get_drvdata(dev);
367 struct sensor_device_attribute_2 *sensor_attr_2 =
368 to_sensor_dev_attr_2(attr);
369 int ix = sensor_attr_2->index;
370 int fn = sensor_attr_2->nr;
371 long val = simple_strtol(buf, NULL, 10);
372
373 mutex_lock(&data->update_lock);
374 switch (fn) {
375 case SHOW_SET_IN_MIN:
376 data->in_min[ix] = IN_TO_REG(ix, val);
377 vt1211_write8(data, VT1211_REG_IN_MIN(ix), data->in_min[ix]);
378 break;
379 case SHOW_SET_IN_MAX:
380 data->in_max[ix] = IN_TO_REG(ix, val);
381 vt1211_write8(data, VT1211_REG_IN_MAX(ix), data->in_max[ix]);
382 break;
383 default:
384 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
385 }
386 mutex_unlock(&data->update_lock);
387
388 return count;
389}
390
391/* ---------------------------------------------------------------------
392 * Temperature sysfs interfaces
393 * ix = [0-6]
394 * --------------------------------------------------------------------- */
395
396#define SHOW_TEMP_INPUT 0
397#define SHOW_SET_TEMP_MAX 1
398#define SHOW_SET_TEMP_MAX_HYST 2
399#define SHOW_TEMP_ALARM 3
400
401static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
402 char *buf)
403{
404 struct vt1211_data *data = vt1211_update_device(dev);
405 struct sensor_device_attribute_2 *sensor_attr_2 =
406 to_sensor_dev_attr_2(attr);
407 int ix = sensor_attr_2->index;
408 int fn = sensor_attr_2->nr;
409 int res;
410
411 switch (fn) {
412 case SHOW_TEMP_INPUT:
413 res = TEMP_FROM_REG(ix, data->temp[ix]);
414 break;
415 case SHOW_SET_TEMP_MAX:
416 res = TEMP_FROM_REG(ix, data->temp_max[ix]);
417 break;
418 case SHOW_SET_TEMP_MAX_HYST:
419 res = TEMP_FROM_REG(ix, data->temp_hyst[ix]);
420 break;
421 case SHOW_TEMP_ALARM:
422 res = (data->alarms >> bitalarmtemp[ix]) & 1;
423 break;
424 default:
425 res = 0;
426 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
427 }
428
429 return sprintf(buf, "%d\n", res);
430}
431
432static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
433 const char *buf, size_t count)
434{
435 struct vt1211_data *data = dev_get_drvdata(dev);
436 struct sensor_device_attribute_2 *sensor_attr_2 =
437 to_sensor_dev_attr_2(attr);
438 int ix = sensor_attr_2->index;
439 int fn = sensor_attr_2->nr;
440 long val = simple_strtol(buf, NULL, 10);
441
442 mutex_lock(&data->update_lock);
443 switch (fn) {
444 case SHOW_SET_TEMP_MAX:
445 data->temp_max[ix] = TEMP_TO_REG(ix, val);
446 vt1211_write8(data, regtempmax[ix],
447 data->temp_max[ix]);
448 break;
449 case SHOW_SET_TEMP_MAX_HYST:
450 data->temp_hyst[ix] = TEMP_TO_REG(ix, val);
451 vt1211_write8(data, regtemphyst[ix],
452 data->temp_hyst[ix]);
453 break;
454 default:
455 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
456 }
457 mutex_unlock(&data->update_lock);
458
459 return count;
460}
461
462/* ---------------------------------------------------------------------
463 * Fan sysfs interfaces
464 * ix = [0-1]
465 * --------------------------------------------------------------------- */
466
467#define SHOW_FAN_INPUT 0
468#define SHOW_SET_FAN_MIN 1
469#define SHOW_SET_FAN_DIV 2
470#define SHOW_FAN_ALARM 3
471
472static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
473 char *buf)
474{
475 struct vt1211_data *data = vt1211_update_device(dev);
476 struct sensor_device_attribute_2 *sensor_attr_2 =
477 to_sensor_dev_attr_2(attr);
478 int ix = sensor_attr_2->index;
479 int fn = sensor_attr_2->nr;
480 int res;
481
482 switch (fn) {
483 case SHOW_FAN_INPUT:
484 res = RPM_FROM_REG(data->fan[ix], data->fan_div[ix]);
485 break;
486 case SHOW_SET_FAN_MIN:
487 res = RPM_FROM_REG(data->fan_min[ix], data->fan_div[ix]);
488 break;
489 case SHOW_SET_FAN_DIV:
490 res = DIV_FROM_REG(data->fan_div[ix]);
491 break;
492 case SHOW_FAN_ALARM:
493 res = (data->alarms >> bitalarmfan[ix]) & 1;
494 break;
495 default:
496 res = 0;
497 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
498 }
499
500 return sprintf(buf, "%d\n", res);
501}
502
503static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
504 const char *buf, size_t count)
505{
506 struct vt1211_data *data = dev_get_drvdata(dev);
507 struct sensor_device_attribute_2 *sensor_attr_2 =
508 to_sensor_dev_attr_2(attr);
509 int ix = sensor_attr_2->index;
510 int fn = sensor_attr_2->nr;
511 long val = simple_strtol(buf, NULL, 10);
512 int reg;
513
514 mutex_lock(&data->update_lock);
515
516 /* sync the data cache */
517 reg = vt1211_read8(data, VT1211_REG_FAN_DIV);
518 data->fan_div[0] = (reg >> 4) & 3;
519 data->fan_div[1] = (reg >> 6) & 3;
520 data->fan_ctl = reg & 0xf;
521
522 switch (fn) {
523 case SHOW_SET_FAN_MIN:
524 data->fan_min[ix] = RPM_TO_REG(val, data->fan_div[ix]);
525 vt1211_write8(data, VT1211_REG_FAN_MIN(ix),
526 data->fan_min[ix]);
527 break;
528 case SHOW_SET_FAN_DIV:
529 switch (val) {
530 case 1: data->fan_div[ix] = 0; break;
531 case 2: data->fan_div[ix] = 1; break;
532 case 4: data->fan_div[ix] = 2; break;
533 case 8: data->fan_div[ix] = 3; break;
534 default:
535 count = -EINVAL;
536 dev_warn(dev, "fan div value %ld not "
537 "supported. Choose one of 1, 2, "
538 "4, or 8.\n", val);
539 goto EXIT;
540 }
541 vt1211_write8(data, VT1211_REG_FAN_DIV,
542 ((data->fan_div[1] << 6) |
543 (data->fan_div[0] << 4) |
544 data->fan_ctl));
545 break;
546 default:
547 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
548 }
549
550EXIT:
551 mutex_unlock(&data->update_lock);
552 return count;
553}
554
555/* ---------------------------------------------------------------------
556 * PWM sysfs interfaces
557 * ix = [0-1]
558 * --------------------------------------------------------------------- */
559
560#define SHOW_PWM 0
561#define SHOW_SET_PWM_ENABLE 1
562#define SHOW_SET_PWM_FREQ 2
563#define SHOW_SET_PWM_AUTO_CHANNELS_TEMP 3
564
565static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
566 char *buf)
567{
568 struct vt1211_data *data = vt1211_update_device(dev);
569 struct sensor_device_attribute_2 *sensor_attr_2 =
570 to_sensor_dev_attr_2(attr);
571 int ix = sensor_attr_2->index;
572 int fn = sensor_attr_2->nr;
573 int res;
574
575 switch (fn) {
576 case SHOW_PWM:
577 res = data->pwm[ix];
578 break;
579 case SHOW_SET_PWM_ENABLE:
580 res = ((data->pwm_ctl[ix] >> 3) & 1) ? 2 : 0;
581 break;
582 case SHOW_SET_PWM_FREQ:
583 res = 90000 >> (data->pwm_clk & 7);
584 break;
585 case SHOW_SET_PWM_AUTO_CHANNELS_TEMP:
586 res = (data->pwm_ctl[ix] & 7) + 1;
587 break;
588 default:
589 res = 0;
590 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
591 }
592
593 return sprintf(buf, "%d\n", res);
594}
595
596static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
597 const char *buf, size_t count)
598{
599 struct vt1211_data *data = dev_get_drvdata(dev);
600 struct sensor_device_attribute_2 *sensor_attr_2 =
601 to_sensor_dev_attr_2(attr);
602 int ix = sensor_attr_2->index;
603 int fn = sensor_attr_2->nr;
604 long val = simple_strtol(buf, NULL, 10);
605 int tmp, reg;
606
607 mutex_lock(&data->update_lock);
608
609 switch (fn) {
610 case SHOW_SET_PWM_ENABLE:
611 /* sync the data cache */
612 reg = vt1211_read8(data, VT1211_REG_FAN_DIV);
613 data->fan_div[0] = (reg >> 4) & 3;
614 data->fan_div[1] = (reg >> 6) & 3;
615 data->fan_ctl = reg & 0xf;
616 reg = vt1211_read8(data, VT1211_REG_PWM_CTL);
617 data->pwm_ctl[0] = reg & 0xf;
618 data->pwm_ctl[1] = (reg >> 4) & 0xf;
619 switch (val) {
620 case 0:
621 data->pwm_ctl[ix] &= 7;
622 /* disable SmartGuardian if both PWM outputs are
623 * disabled */
624 if ((data->pwm_ctl[ix ^ 1] & 1) == 0) {
625 data->fan_ctl &= 0xe;
626 }
627 break;
628 case 2:
629 data->pwm_ctl[ix] |= 8;
630 data->fan_ctl |= 1;
631 break;
632 default:
633 count = -EINVAL;
634 dev_warn(dev, "pwm mode %ld not supported. "
635 "Choose one of 0 or 2.\n", val);
636 goto EXIT;
637 }
638 vt1211_write8(data, VT1211_REG_PWM_CTL,
639 ((data->pwm_ctl[1] << 4) |
640 data->pwm_ctl[0]));
641 vt1211_write8(data, VT1211_REG_FAN_DIV,
642 ((data->fan_div[1] << 6) |
643 (data->fan_div[0] << 4) |
644 data->fan_ctl));
645 break;
646 case SHOW_SET_PWM_FREQ:
647 val = 135000 / SENSORS_LIMIT(val, 135000 >> 7, 135000);
648 /* calculate tmp = log2(val) */
649 tmp = 0;
650 for (val >>= 1; val > 0; val >>= 1) {
651 tmp++;
652 }
653 /* sync the data cache */
654 reg = vt1211_read8(data, VT1211_REG_PWM_CLK);
655 data->pwm_clk = (reg & 0xf8) | tmp;
656 vt1211_write8(data, VT1211_REG_PWM_CLK, data->pwm_clk);
657 break;
658 case SHOW_SET_PWM_AUTO_CHANNELS_TEMP:
659 if ((val < 1) || (val > 7)) {
660 count = -EINVAL;
661 dev_warn(dev, "temp channel %ld not supported. "
662 "Choose a value between 1 and 7.\n", val);
663 goto EXIT;
664 }
665 if (!ISTEMP(val - 1, data->uch_config)) {
666 count = -EINVAL;
667 dev_warn(dev, "temp channel %ld is not available.\n",
668 val);
669 goto EXIT;
670 }
671 /* sync the data cache */
672 reg = vt1211_read8(data, VT1211_REG_PWM_CTL);
673 data->pwm_ctl[0] = reg & 0xf;
674 data->pwm_ctl[1] = (reg >> 4) & 0xf;
675 data->pwm_ctl[ix] = (data->pwm_ctl[ix] & 8) | (val - 1);
676 vt1211_write8(data, VT1211_REG_PWM_CTL,
677 ((data->pwm_ctl[1] << 4) | data->pwm_ctl[0]));
678 break;
679 default:
680 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
681 }
682
683EXIT:
684 mutex_unlock(&data->update_lock);
685 return count;
686}
687
688/* ---------------------------------------------------------------------
689 * PWM auto point definitions
690 * ix = [0-1]
691 * ap = [0-3]
692 * --------------------------------------------------------------------- */
693
694/*
695 * pwm[ix+1]_auto_point[ap+1]_temp mapping table:
696 * Note that there is only a single set of temp auto points that controls both
697 * PWM controllers. We still create 2 sets of sysfs files to make it look
698 * more consistent even though they map to the same registers.
699 *
700 * ix ap : description
701 * -------------------
702 * 0 0 : pwm1/2 off temperature (pwm_auto_temp[0])
703 * 0 1 : pwm1/2 low speed temperature (pwm_auto_temp[1])
704 * 0 2 : pwm1/2 high speed temperature (pwm_auto_temp[2])
705 * 0 3 : pwm1/2 full speed temperature (pwm_auto_temp[3])
706 * 1 0 : pwm1/2 off temperature (pwm_auto_temp[0])
707 * 1 1 : pwm1/2 low speed temperature (pwm_auto_temp[1])
708 * 1 2 : pwm1/2 high speed temperature (pwm_auto_temp[2])
709 * 1 3 : pwm1/2 full speed temperature (pwm_auto_temp[3])
710 */
711
712static ssize_t show_pwm_auto_point_temp(struct device *dev,
713 struct device_attribute *attr,
714 char *buf)
715{
716 struct vt1211_data *data = vt1211_update_device(dev);
717 struct sensor_device_attribute_2 *sensor_attr_2 =
718 to_sensor_dev_attr_2(attr);
719 int ix = sensor_attr_2->index;
720 int ap = sensor_attr_2->nr;
721
722 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->pwm_ctl[ix] & 7,
723 data->pwm_auto_temp[ap]));
724}
725
726static ssize_t set_pwm_auto_point_temp(struct device *dev,
727 struct device_attribute *attr,
728 const char *buf, size_t count)
729{
730 struct vt1211_data *data = dev_get_drvdata(dev);
731 struct sensor_device_attribute_2 *sensor_attr_2 =
732 to_sensor_dev_attr_2(attr);
733 int ix = sensor_attr_2->index;
734 int ap = sensor_attr_2->nr;
735 long val = simple_strtol(buf, NULL, 10);
736 int reg;
737
738 mutex_lock(&data->update_lock);
739
740 /* sync the data cache */
741 reg = vt1211_read8(data, VT1211_REG_PWM_CTL);
742 data->pwm_ctl[0] = reg & 0xf;
743 data->pwm_ctl[1] = (reg >> 4) & 0xf;
744
745 data->pwm_auto_temp[ap] = TEMP_TO_REG(data->pwm_ctl[ix] & 7, val);
746 vt1211_write8(data, VT1211_REG_PWM_AUTO_TEMP(ap),
747 data->pwm_auto_temp[ap]);
748 mutex_unlock(&data->update_lock);
749
750 return count;
751}
752
753/*
754 * pwm[ix+1]_auto_point[ap+1]_pwm mapping table:
755 * Note that the PWM auto points 0 & 3 are hard-wired in the VT1211 and can't
756 * be changed.
757 *
758 * ix ap : description
759 * -------------------
760 * 0 0 : pwm1 off (pwm_auto_pwm[0][0], hard-wired to 0)
761 * 0 1 : pwm1 low speed duty cycle (pwm_auto_pwm[0][1])
762 * 0 2 : pwm1 high speed duty cycle (pwm_auto_pwm[0][2])
763 * 0 3 : pwm1 full speed (pwm_auto_pwm[0][3], hard-wired to 255)
764 * 1 0 : pwm2 off (pwm_auto_pwm[1][0], hard-wired to 0)
765 * 1 1 : pwm2 low speed duty cycle (pwm_auto_pwm[1][1])
766 * 1 2 : pwm2 high speed duty cycle (pwm_auto_pwm[1][2])
767 * 1 3 : pwm2 full speed (pwm_auto_pwm[1][3], hard-wired to 255)
768*/
769
770static ssize_t show_pwm_auto_point_pwm(struct device *dev,
771 struct device_attribute *attr,
772 char *buf)
773{
774 struct vt1211_data *data = vt1211_update_device(dev);
775 struct sensor_device_attribute_2 *sensor_attr_2 =
776 to_sensor_dev_attr_2(attr);
777 int ix = sensor_attr_2->index;
778 int ap = sensor_attr_2->nr;
779
780 return sprintf(buf, "%d\n", data->pwm_auto_pwm[ix][ap]);
781}
782
783static ssize_t set_pwm_auto_point_pwm(struct device *dev,
784 struct device_attribute *attr,
785 const char *buf, size_t count)
786{
787 struct vt1211_data *data = dev_get_drvdata(dev);
788 struct sensor_device_attribute_2 *sensor_attr_2 =
789 to_sensor_dev_attr_2(attr);
790 int ix = sensor_attr_2->index;
791 int ap = sensor_attr_2->nr;
792 long val = simple_strtol(buf, NULL, 10);
793
794 if ((val < 0) || (val > 255)) {
795 dev_err(dev, "pwm value %ld is out of range. "
796 "Choose a value between 0 and 255." , val);
797 return -EINVAL;
798 }
799
800 mutex_lock(&data->update_lock);
801 data->pwm_auto_pwm[ix][ap] = val;
802 vt1211_write8(data, VT1211_REG_PWM_AUTO_PWM(ix, ap),
803 data->pwm_auto_pwm[ix][ap]);
804 mutex_unlock(&data->update_lock);
805
806 return count;
807}
808
809/* ---------------------------------------------------------------------
810 * Miscellaneous sysfs interfaces (VRM, VID, name, and (legacy) alarms)
811 * --------------------------------------------------------------------- */
812
813static ssize_t show_vrm(struct device *dev, struct device_attribute *attr,
814 char *buf)
815{
816 struct vt1211_data *data = dev_get_drvdata(dev);
817
818 return sprintf(buf, "%d\n", data->vrm);
819}
820
821static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
822 const char *buf, size_t count)
823{
824 struct vt1211_data *data = dev_get_drvdata(dev);
825 long val = simple_strtol(buf, NULL, 10);
826
827 data->vrm = val;
828
829 return count;
830}
831
832static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
833 char *buf)
834{
835 struct vt1211_data *data = dev_get_drvdata(dev);
836
837 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
838}
839
840static ssize_t show_name(struct device *dev,
841 struct device_attribute *attr, char *buf)
842{
843 struct vt1211_data *data = dev_get_drvdata(dev);
844
845 return sprintf(buf, "%s\n", data->name);
846}
847
848static ssize_t show_alarms(struct device *dev,
849 struct device_attribute *attr, char *buf)
850{
851 struct vt1211_data *data = vt1211_update_device(dev);
852
853 return sprintf(buf, "%d\n", data->alarms);
854}
855
856/* ---------------------------------------------------------------------
857 * Device attribute structs
858 * --------------------------------------------------------------------- */
859
860#define SENSOR_ATTR_IN_INPUT(ix) \
861 SENSOR_ATTR_2(in##ix##_input, S_IRUGO, \
862 show_in, NULL, SHOW_IN_INPUT, ix)
863
864static struct sensor_device_attribute_2 vt1211_sysfs_in_input[] = {
865 SENSOR_ATTR_IN_INPUT(0),
866 SENSOR_ATTR_IN_INPUT(1),
867 SENSOR_ATTR_IN_INPUT(2),
868 SENSOR_ATTR_IN_INPUT(3),
869 SENSOR_ATTR_IN_INPUT(4),
870 SENSOR_ATTR_IN_INPUT(5),
871};
872
873#define SENSOR_ATTR_IN_MIN(ix) \
874 SENSOR_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \
875 show_in, set_in, SHOW_SET_IN_MIN, ix)
876
877static struct sensor_device_attribute_2 vt1211_sysfs_in_min[] = {
878 SENSOR_ATTR_IN_MIN(0),
879 SENSOR_ATTR_IN_MIN(1),
880 SENSOR_ATTR_IN_MIN(2),
881 SENSOR_ATTR_IN_MIN(3),
882 SENSOR_ATTR_IN_MIN(4),
883 SENSOR_ATTR_IN_MIN(5),
884};
885
886#define SENSOR_ATTR_IN_MAX(ix) \
887 SENSOR_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \
888 show_in, set_in, SHOW_SET_IN_MAX, ix)
889
890static struct sensor_device_attribute_2 vt1211_sysfs_in_max[] = {
891 SENSOR_ATTR_IN_MAX(0),
892 SENSOR_ATTR_IN_MAX(1),
893 SENSOR_ATTR_IN_MAX(2),
894 SENSOR_ATTR_IN_MAX(3),
895 SENSOR_ATTR_IN_MAX(4),
896 SENSOR_ATTR_IN_MAX(5),
897};
898
899#define SENSOR_ATTR_IN_ALARM(ix) \
900 SENSOR_ATTR_2(in##ix##_alarm, S_IRUGO, \
901 show_in, NULL, SHOW_IN_ALARM, ix)
902
903static struct sensor_device_attribute_2 vt1211_sysfs_in_alarm[] = {
904 SENSOR_ATTR_IN_ALARM(0),
905 SENSOR_ATTR_IN_ALARM(1),
906 SENSOR_ATTR_IN_ALARM(2),
907 SENSOR_ATTR_IN_ALARM(3),
908 SENSOR_ATTR_IN_ALARM(4),
909 SENSOR_ATTR_IN_ALARM(5),
910};
911
912#define SENSOR_ATTR_TEMP_INPUT(ix) \
913 SENSOR_ATTR_2(temp##ix##_input, S_IRUGO, \
914 show_temp, NULL, SHOW_TEMP_INPUT, ix-1)
915
916static struct sensor_device_attribute_2 vt1211_sysfs_temp_input[] = {
917 SENSOR_ATTR_TEMP_INPUT(1),
918 SENSOR_ATTR_TEMP_INPUT(2),
919 SENSOR_ATTR_TEMP_INPUT(3),
920 SENSOR_ATTR_TEMP_INPUT(4),
921 SENSOR_ATTR_TEMP_INPUT(5),
922 SENSOR_ATTR_TEMP_INPUT(6),
923 SENSOR_ATTR_TEMP_INPUT(7),
924};
925
926#define SENSOR_ATTR_TEMP_MAX(ix) \
927 SENSOR_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \
928 show_temp, set_temp, SHOW_SET_TEMP_MAX, ix-1)
929
930static struct sensor_device_attribute_2 vt1211_sysfs_temp_max[] = {
931 SENSOR_ATTR_TEMP_MAX(1),
932 SENSOR_ATTR_TEMP_MAX(2),
933 SENSOR_ATTR_TEMP_MAX(3),
934 SENSOR_ATTR_TEMP_MAX(4),
935 SENSOR_ATTR_TEMP_MAX(5),
936 SENSOR_ATTR_TEMP_MAX(6),
937 SENSOR_ATTR_TEMP_MAX(7),
938};
939
940#define SENSOR_ATTR_TEMP_MAX_HYST(ix) \
941 SENSOR_ATTR_2(temp##ix##_max_hyst, S_IRUGO | S_IWUSR, \
942 show_temp, set_temp, SHOW_SET_TEMP_MAX_HYST, ix-1)
943
944static struct sensor_device_attribute_2 vt1211_sysfs_temp_max_hyst[] = {
945 SENSOR_ATTR_TEMP_MAX_HYST(1),
946 SENSOR_ATTR_TEMP_MAX_HYST(2),
947 SENSOR_ATTR_TEMP_MAX_HYST(3),
948 SENSOR_ATTR_TEMP_MAX_HYST(4),
949 SENSOR_ATTR_TEMP_MAX_HYST(5),
950 SENSOR_ATTR_TEMP_MAX_HYST(6),
951 SENSOR_ATTR_TEMP_MAX_HYST(7),
952};
953
954#define SENSOR_ATTR_TEMP_ALARM(ix) \
955 SENSOR_ATTR_2(temp##ix##_alarm, S_IRUGO, \
956 show_temp, NULL, SHOW_TEMP_ALARM, ix-1)
957
958static struct sensor_device_attribute_2 vt1211_sysfs_temp_alarm[] = {
959 SENSOR_ATTR_TEMP_ALARM(1),
960 SENSOR_ATTR_TEMP_ALARM(2),
961 SENSOR_ATTR_TEMP_ALARM(3),
962 SENSOR_ATTR_TEMP_ALARM(4),
963 SENSOR_ATTR_TEMP_ALARM(5),
964 SENSOR_ATTR_TEMP_ALARM(6),
965 SENSOR_ATTR_TEMP_ALARM(7),
966};
967
968#define SENSOR_ATTR_FAN(ix) \
969 SENSOR_ATTR_2(fan##ix##_input, S_IRUGO, \
970 show_fan, NULL, SHOW_FAN_INPUT, ix-1), \
971 SENSOR_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \
972 show_fan, set_fan, SHOW_SET_FAN_MIN, ix-1), \
973 SENSOR_ATTR_2(fan##ix##_div, S_IRUGO | S_IWUSR, \
974 show_fan, set_fan, SHOW_SET_FAN_DIV, ix-1), \
975 SENSOR_ATTR_2(fan##ix##_alarm, S_IRUGO, \
976 show_fan, NULL, SHOW_FAN_ALARM, ix-1)
977
978#define SENSOR_ATTR_PWM(ix) \
979 SENSOR_ATTR_2(pwm##ix, S_IRUGO, \
980 show_pwm, NULL, SHOW_PWM, ix-1), \
981 SENSOR_ATTR_2(pwm##ix##_enable, S_IRUGO | S_IWUSR, \
982 show_pwm, set_pwm, SHOW_SET_PWM_ENABLE, ix-1), \
983 SENSOR_ATTR_2(pwm##ix##_auto_channels_temp, S_IRUGO | S_IWUSR, \
984 show_pwm, set_pwm, SHOW_SET_PWM_AUTO_CHANNELS_TEMP, ix-1)
985
986#define SENSOR_ATTR_PWM_FREQ(ix) \
987 SENSOR_ATTR_2(pwm##ix##_freq, S_IRUGO | S_IWUSR, \
988 show_pwm, set_pwm, SHOW_SET_PWM_FREQ, ix-1)
989
990#define SENSOR_ATTR_PWM_FREQ_RO(ix) \
991 SENSOR_ATTR_2(pwm##ix##_freq, S_IRUGO, \
992 show_pwm, NULL, SHOW_SET_PWM_FREQ, ix-1)
993
994#define SENSOR_ATTR_PWM_AUTO_POINT_TEMP(ix, ap) \
995 SENSOR_ATTR_2(pwm##ix##_auto_point##ap##_temp, S_IRUGO | S_IWUSR, \
996 show_pwm_auto_point_temp, set_pwm_auto_point_temp, \
997 ap-1, ix-1)
998
999#define SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(ix, ap) \
1000 SENSOR_ATTR_2(pwm##ix##_auto_point##ap##_temp, S_IRUGO, \
1001 show_pwm_auto_point_temp, NULL, \
1002 ap-1, ix-1)
1003
1004#define SENSOR_ATTR_PWM_AUTO_POINT_PWM(ix, ap) \
1005 SENSOR_ATTR_2(pwm##ix##_auto_point##ap##_pwm, S_IRUGO | S_IWUSR, \
1006 show_pwm_auto_point_pwm, set_pwm_auto_point_pwm, \
1007 ap-1, ix-1)
1008
1009#define SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(ix, ap) \
1010 SENSOR_ATTR_2(pwm##ix##_auto_point##ap##_pwm, S_IRUGO, \
1011 show_pwm_auto_point_pwm, NULL, \
1012 ap-1, ix-1)
1013
1014static struct sensor_device_attribute_2 vt1211_sysfs_fan_pwm[] = {
1015 SENSOR_ATTR_FAN(1),
1016 SENSOR_ATTR_FAN(2),
1017 SENSOR_ATTR_PWM(1),
1018 SENSOR_ATTR_PWM(2),
1019 SENSOR_ATTR_PWM_FREQ(1),
1020 SENSOR_ATTR_PWM_FREQ_RO(2),
1021 SENSOR_ATTR_PWM_AUTO_POINT_TEMP(1, 1),
1022 SENSOR_ATTR_PWM_AUTO_POINT_TEMP(1, 2),
1023 SENSOR_ATTR_PWM_AUTO_POINT_TEMP(1, 3),
1024 SENSOR_ATTR_PWM_AUTO_POINT_TEMP(1, 4),
1025 SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(2, 1),
1026 SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(2, 2),
1027 SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(2, 3),
1028 SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(2, 4),
1029 SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(1, 1),
1030 SENSOR_ATTR_PWM_AUTO_POINT_PWM(1, 2),
1031 SENSOR_ATTR_PWM_AUTO_POINT_PWM(1, 3),
1032 SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(1, 4),
1033 SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(2, 1),
1034 SENSOR_ATTR_PWM_AUTO_POINT_PWM(2, 2),
1035 SENSOR_ATTR_PWM_AUTO_POINT_PWM(2, 3),
1036 SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(2, 4),
1037};
1038
1039static struct device_attribute vt1211_sysfs_misc[] = {
1040 __ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm),
1041 __ATTR(cpu0_vid, S_IRUGO, show_vid, NULL),
1042 __ATTR(name, S_IRUGO, show_name, NULL),
1043 __ATTR(alarms, S_IRUGO, show_alarms, NULL),
1044};
1045
1046/* ---------------------------------------------------------------------
1047 * Device registration and initialization
1048 * --------------------------------------------------------------------- */
1049
1050static void __devinit vt1211_init_device(struct vt1211_data *data)
1051{
1052 /* set VRM */
1053 data->vrm = vid_which_vrm();
1054
1055 /* Read (and initialize) UCH config */
1056 data->uch_config = vt1211_read8(data, VT1211_REG_UCH_CONFIG);
1057 if (uch_config > -1) {
1058 data->uch_config = (data->uch_config & 0x83) |
1059 (uch_config << 2);
1060 vt1211_write8(data, VT1211_REG_UCH_CONFIG, data->uch_config);
1061 }
1062
1063 /* Initialize the interrupt mode (if request at module load time).
1064 * The VT1211 implements 3 different modes for clearing interrupts:
1065 * 0: Clear INT when status register is read. Regenerate INT as long
1066 * as temp stays above hysteresis limit.
1067 * 1: Clear INT when status register is read. DON'T regenerate INT
1068 * until temp falls below hysteresis limit and exceeds hot limit
1069 * again.
1070 * 2: Clear INT when temp falls below max limit.
1071 *
1072 * The driver only allows to force mode 0 since that's the only one
1073 * that makes sense for 'sensors' */
1074 if (int_mode == 0) {
1075 vt1211_write8(data, VT1211_REG_TEMP1_CONFIG, 0);
1076 vt1211_write8(data, VT1211_REG_TEMP2_CONFIG, 0);
1077 }
1078
1079 /* Fill in some hard wired values into our data struct */
1080 data->pwm_auto_pwm[0][3] = 255;
1081 data->pwm_auto_pwm[1][3] = 255;
1082}
1083
1084static void vt1211_remove_sysfs(struct platform_device *pdev)
1085{
1086 struct device *dev = &pdev->dev;
1087 int i;
1088
1089 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_in_input); i++) {
1090 device_remove_file(dev,
1091 &vt1211_sysfs_in_input[i].dev_attr);
1092 device_remove_file(dev,
1093 &vt1211_sysfs_in_min[i].dev_attr);
1094 device_remove_file(dev,
1095 &vt1211_sysfs_in_max[i].dev_attr);
1096 device_remove_file(dev,
1097 &vt1211_sysfs_in_alarm[i].dev_attr);
1098 }
1099 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_temp_input); i++) {
1100 device_remove_file(dev,
1101 &vt1211_sysfs_temp_input[i].dev_attr);
1102 device_remove_file(dev,
1103 &vt1211_sysfs_temp_max[i].dev_attr);
1104 device_remove_file(dev,
1105 &vt1211_sysfs_temp_max_hyst[i].dev_attr);
1106 device_remove_file(dev,
1107 &vt1211_sysfs_temp_alarm[i].dev_attr);
1108 }
1109 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_fan_pwm); i++) {
1110 device_remove_file(dev,
1111 &vt1211_sysfs_fan_pwm[i].dev_attr);
1112 }
1113 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_misc); i++) {
1114 device_remove_file(dev, &vt1211_sysfs_misc[i]);
1115 }
1116}
1117
1118static int __devinit vt1211_probe(struct platform_device *pdev)
1119{
1120 struct device *dev = &pdev->dev;
1121 struct vt1211_data *data;
1122 struct resource *res;
1123 int i, err;
1124
1125 if (!(data = kzalloc(sizeof(struct vt1211_data), GFP_KERNEL))) {
1126 err = -ENOMEM;
1127 dev_err(dev, "Out of memory\n");
1128 goto EXIT;
1129 }
1130
1131 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1132 data->addr = res->start;
1133 data->name = DRVNAME;
1134 mutex_init(&data->update_lock);
1135
1136 platform_set_drvdata(pdev, data);
1137
1138 /* Initialize the VT1211 chip */
1139 vt1211_init_device(data);
1140
1141 /* Create sysfs interface files */
1142 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_in_input); i++) {
1143 if (ISVOLT(i, data->uch_config)) {
1144 if ((err = device_create_file(dev,
1145 &vt1211_sysfs_in_input[i].dev_attr)) ||
1146 (err = device_create_file(dev,
1147 &vt1211_sysfs_in_min[i].dev_attr)) ||
1148 (err = device_create_file(dev,
1149 &vt1211_sysfs_in_max[i].dev_attr)) ||
1150 (err = device_create_file(dev,
1151 &vt1211_sysfs_in_alarm[i].dev_attr))) {
1152 goto EXIT_DEV_REMOVE;
1153 }
1154 }
1155 }
1156 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_temp_input); i++) {
1157 if (ISTEMP(i, data->uch_config)) {
1158 if ((err = device_create_file(dev,
1159 &vt1211_sysfs_temp_input[i].dev_attr)) ||
1160 (err = device_create_file(dev,
1161 &vt1211_sysfs_temp_max[i].dev_attr)) ||
1162 (err = device_create_file(dev,
1163 &vt1211_sysfs_temp_max_hyst[i].dev_attr)) ||
1164 (err = device_create_file(dev,
1165 &vt1211_sysfs_temp_alarm[i].dev_attr))) {
1166 goto EXIT_DEV_REMOVE;
1167 }
1168 }
1169 }
1170 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_fan_pwm); i++) {
1171 err = device_create_file(dev,
1172 &vt1211_sysfs_fan_pwm[i].dev_attr);
1173 if (err) {
1174 goto EXIT_DEV_REMOVE;
1175 }
1176 }
1177 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_misc); i++) {
1178 err = device_create_file(dev,
1179 &vt1211_sysfs_misc[i]);
1180 if (err) {
1181 goto EXIT_DEV_REMOVE;
1182 }
1183 }
1184
1185 /* Register device */
1186 data->class_dev = hwmon_device_register(dev);
1187 if (IS_ERR(data->class_dev)) {
1188 err = PTR_ERR(data->class_dev);
1189 dev_err(dev, "Class registration failed (%d)\n", err);
1190 goto EXIT_DEV_REMOVE_SILENT;
1191 }
1192
1193 return 0;
1194
1195EXIT_DEV_REMOVE:
1196 dev_err(dev, "Sysfs interface creation failed (%d)\n", err);
1197EXIT_DEV_REMOVE_SILENT:
1198 vt1211_remove_sysfs(pdev);
1199 platform_set_drvdata(pdev, NULL);
1200 kfree(data);
1201EXIT:
1202 return err;
1203}
1204
1205static int __devexit vt1211_remove(struct platform_device *pdev)
1206{
1207 struct vt1211_data *data = platform_get_drvdata(pdev);
1208
1209 hwmon_device_unregister(data->class_dev);
1210 vt1211_remove_sysfs(pdev);
1211 platform_set_drvdata(pdev, NULL);
1212 kfree(data);
1213
1214 return 0;
1215}
1216
1217static struct platform_driver vt1211_driver = {
1218 .driver = {
1219 .owner = THIS_MODULE,
1220 .name = DRVNAME,
1221 },
1222 .probe = vt1211_probe,
1223 .remove = __devexit_p(vt1211_remove),
1224};
1225
1226static int __init vt1211_device_add(unsigned short address)
1227{
1228 struct resource res = {
1229 .start = address,
1230 .end = address + 0x7f,
1231 .flags = IORESOURCE_IO,
1232 };
1233 int err;
1234
1235 pdev = platform_device_alloc(DRVNAME, address);
1236 if (!pdev) {
1237 err = -ENOMEM;
1238 printk(KERN_ERR DRVNAME ": Device allocation failed (%d)\n",
1239 err);
1240 goto EXIT;
1241 }
1242
1243 res.name = pdev->name;
1244 err = platform_device_add_resources(pdev, &res, 1);
1245 if (err) {
1246 printk(KERN_ERR DRVNAME ": Device resource addition failed "
1247 "(%d)\n", err);
1248 goto EXIT_DEV_PUT;
1249 }
1250
1251 err = platform_device_add(pdev);
1252 if (err) {
1253 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
1254 err);
1255 goto EXIT_DEV_PUT;
1256 }
1257
1258 return 0;
1259
1260EXIT_DEV_PUT:
1261 platform_device_put(pdev);
1262EXIT:
1263 return err;
1264}
1265
1266static int __init vt1211_find(unsigned short *address)
1267{
1268 int err = -ENODEV;
1269
1270 superio_enter();
1271
1272 if (superio_inb(SIO_VT1211_DEVID) != SIO_VT1211_ID) {
1273 goto EXIT;
1274 }
1275
1276 superio_select(SIO_VT1211_LDN_HWMON);
1277
1278 if ((superio_inb(SIO_VT1211_ACTIVE) & 1) == 0) {
1279 printk(KERN_WARNING DRVNAME ": HW monitor is disabled, "
1280 "skipping\n");
1281 goto EXIT;
1282 }
1283
1284 *address = ((superio_inb(SIO_VT1211_BADDR) << 8) |
1285 (superio_inb(SIO_VT1211_BADDR + 1))) & 0xff00;
1286 if (*address == 0) {
1287 printk(KERN_WARNING DRVNAME ": Base address is not set, "
1288 "skipping\n");
1289 goto EXIT;
1290 }
1291
1292 err = 0;
1293 printk(KERN_INFO DRVNAME ": Found VT1211 chip at 0x%04x, "
1294 "revision %u\n", *address, superio_inb(SIO_VT1211_DEVREV));
1295
1296EXIT:
1297 superio_exit();
1298 return err;
1299}
1300
1301static int __init vt1211_init(void)
1302{
1303 int err;
1304 unsigned short address = 0;
1305
1306 err = vt1211_find(&address);
1307 if (err) {
1308 goto EXIT;
1309 }
1310
1311 if ((uch_config < -1) || (uch_config > 31)) {
1312 err = -EINVAL;
1313 printk(KERN_WARNING DRVNAME ": Invalid UCH configuration %d. "
1314 "Choose a value between 0 and 31.\n", uch_config);
1315 goto EXIT;
1316 }
1317
1318 if ((int_mode < -1) || (int_mode > 0)) {
1319 err = -EINVAL;
1320 printk(KERN_WARNING DRVNAME ": Invalid interrupt mode %d. "
1321 "Only mode 0 is supported.\n", int_mode);
1322 goto EXIT;
1323 }
1324
1325 err = platform_driver_register(&vt1211_driver);
1326 if (err) {
1327 goto EXIT;
1328 }
1329
1330 /* Sets global pdev as a side effect */
1331 err = vt1211_device_add(address);
1332 if (err) {
1333 goto EXIT_DRV_UNREGISTER;
1334 }
1335
1336 return 0;
1337
1338EXIT_DRV_UNREGISTER:
1339 platform_driver_unregister(&vt1211_driver);
1340EXIT:
1341 return err;
1342}
1343
1344static void __exit vt1211_exit(void)
1345{
1346 platform_device_unregister(pdev);
1347 platform_driver_unregister(&vt1211_driver);
1348}
1349
1350MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>");
1351MODULE_DESCRIPTION("VT1211 sensors");
1352MODULE_LICENSE("GPL");
1353
1354module_init(vt1211_init);
1355module_exit(vt1211_exit);
diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c
index 686f3deb3093..93f93d4fb8ae 100644
--- a/drivers/hwmon/vt8231.c
+++ b/drivers/hwmon/vt8231.c
@@ -451,37 +451,6 @@ define_temperature_sysfs(4);
451define_temperature_sysfs(5); 451define_temperature_sysfs(5);
452define_temperature_sysfs(6); 452define_temperature_sysfs(6);
453 453
454#define CFG_INFO_TEMP(id) { &sensor_dev_attr_temp##id##_input.dev_attr, \
455 &sensor_dev_attr_temp##id##_max_hyst.dev_attr, \
456 &sensor_dev_attr_temp##id##_max.dev_attr }
457#define CFG_INFO_VOLT(id) { &sensor_dev_attr_in##id##_input.dev_attr, \
458 &sensor_dev_attr_in##id##_min.dev_attr, \
459 &sensor_dev_attr_in##id##_max.dev_attr }
460
461struct str_device_attr_table {
462 struct device_attribute *input;
463 struct device_attribute *min;
464 struct device_attribute *max;
465};
466
467static struct str_device_attr_table cfg_info_temp[] = {
468 { &dev_attr_temp1_input, &dev_attr_temp1_max_hyst, &dev_attr_temp1_max },
469 CFG_INFO_TEMP(2),
470 CFG_INFO_TEMP(3),
471 CFG_INFO_TEMP(4),
472 CFG_INFO_TEMP(5),
473 CFG_INFO_TEMP(6)
474};
475
476static struct str_device_attr_table cfg_info_volt[] = {
477 CFG_INFO_VOLT(0),
478 CFG_INFO_VOLT(1),
479 CFG_INFO_VOLT(2),
480 CFG_INFO_VOLT(3),
481 CFG_INFO_VOLT(4),
482 { &dev_attr_in5_input, &dev_attr_in5_min, &dev_attr_in5_max }
483};
484
485/* Fans */ 454/* Fans */
486static ssize_t show_fan(struct device *dev, struct device_attribute *attr, 455static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
487 char *buf) 456 char *buf)
@@ -585,8 +554,110 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
585 554
586static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 555static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
587 556
557static struct attribute *vt8231_attributes_temps[6][4] = {
558 {
559 &dev_attr_temp1_input.attr,
560 &dev_attr_temp1_max_hyst.attr,
561 &dev_attr_temp1_max.attr,
562 NULL
563 }, {
564 &sensor_dev_attr_temp2_input.dev_attr.attr,
565 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
566 &sensor_dev_attr_temp2_max.dev_attr.attr,
567 NULL
568 }, {
569 &sensor_dev_attr_temp3_input.dev_attr.attr,
570 &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
571 &sensor_dev_attr_temp3_max.dev_attr.attr,
572 NULL
573 }, {
574 &sensor_dev_attr_temp4_input.dev_attr.attr,
575 &sensor_dev_attr_temp4_max_hyst.dev_attr.attr,
576 &sensor_dev_attr_temp4_max.dev_attr.attr,
577 NULL
578 }, {
579 &sensor_dev_attr_temp5_input.dev_attr.attr,
580 &sensor_dev_attr_temp5_max_hyst.dev_attr.attr,
581 &sensor_dev_attr_temp5_max.dev_attr.attr,
582 NULL
583 }, {
584 &sensor_dev_attr_temp6_input.dev_attr.attr,
585 &sensor_dev_attr_temp6_max_hyst.dev_attr.attr,
586 &sensor_dev_attr_temp6_max.dev_attr.attr,
587 NULL
588 }
589};
590
591static const struct attribute_group vt8231_group_temps[6] = {
592 { .attrs = vt8231_attributes_temps[0] },
593 { .attrs = vt8231_attributes_temps[1] },
594 { .attrs = vt8231_attributes_temps[2] },
595 { .attrs = vt8231_attributes_temps[3] },
596 { .attrs = vt8231_attributes_temps[4] },
597 { .attrs = vt8231_attributes_temps[5] },
598};
599
600static struct attribute *vt8231_attributes_volts[6][4] = {
601 {
602 &sensor_dev_attr_in0_input.dev_attr.attr,
603 &sensor_dev_attr_in0_min.dev_attr.attr,
604 &sensor_dev_attr_in0_max.dev_attr.attr,
605 NULL
606 }, {
607 &sensor_dev_attr_in1_input.dev_attr.attr,
608 &sensor_dev_attr_in1_min.dev_attr.attr,
609 &sensor_dev_attr_in1_max.dev_attr.attr,
610 NULL
611 }, {
612 &sensor_dev_attr_in2_input.dev_attr.attr,
613 &sensor_dev_attr_in2_min.dev_attr.attr,
614 &sensor_dev_attr_in2_max.dev_attr.attr,
615 NULL
616 }, {
617 &sensor_dev_attr_in3_input.dev_attr.attr,
618 &sensor_dev_attr_in3_min.dev_attr.attr,
619 &sensor_dev_attr_in3_max.dev_attr.attr,
620 NULL
621 }, {
622 &sensor_dev_attr_in4_input.dev_attr.attr,
623 &sensor_dev_attr_in4_min.dev_attr.attr,
624 &sensor_dev_attr_in4_max.dev_attr.attr,
625 NULL
626 }, {
627 &dev_attr_in5_input.attr,
628 &dev_attr_in5_min.attr,
629 &dev_attr_in5_max.attr,
630 NULL
631 }
632};
633
634static const struct attribute_group vt8231_group_volts[6] = {
635 { .attrs = vt8231_attributes_volts[0] },
636 { .attrs = vt8231_attributes_volts[1] },
637 { .attrs = vt8231_attributes_volts[2] },
638 { .attrs = vt8231_attributes_volts[3] },
639 { .attrs = vt8231_attributes_volts[4] },
640 { .attrs = vt8231_attributes_volts[5] },
641};
642
643static struct attribute *vt8231_attributes[] = {
644 &sensor_dev_attr_fan1_input.dev_attr.attr,
645 &sensor_dev_attr_fan2_input.dev_attr.attr,
646 &sensor_dev_attr_fan1_min.dev_attr.attr,
647 &sensor_dev_attr_fan2_min.dev_attr.attr,
648 &sensor_dev_attr_fan1_div.dev_attr.attr,
649 &sensor_dev_attr_fan2_div.dev_attr.attr,
650 &dev_attr_alarms.attr,
651 NULL
652};
653
654static const struct attribute_group vt8231_group = {
655 .attrs = vt8231_attributes,
656};
657
588static struct i2c_driver vt8231_driver = { 658static struct i2c_driver vt8231_driver = {
589 .driver = { 659 .driver = {
660 .owner = THIS_MODULE,
590 .name = "vt8231", 661 .name = "vt8231",
591 }, 662 },
592 .attach_adapter = vt8231_detect, 663 .attach_adapter = vt8231_detect,
@@ -670,43 +741,43 @@ int vt8231_detect(struct i2c_adapter *adapter)
670 vt8231_init_client(client); 741 vt8231_init_client(client);
671 742
672 /* Register sysfs hooks */ 743 /* Register sysfs hooks */
673 data->class_dev = hwmon_device_register(&client->dev); 744 if ((err = sysfs_create_group(&client->dev.kobj, &vt8231_group)))
674 if (IS_ERR(data->class_dev)) {
675 err = PTR_ERR(data->class_dev);
676 goto exit_detach; 745 goto exit_detach;
677 }
678 746
679 /* Must update device information to find out the config field */ 747 /* Must update device information to find out the config field */
680 data->uch_config = vt8231_read_value(client, VT8231_REG_UCH_CONFIG); 748 data->uch_config = vt8231_read_value(client, VT8231_REG_UCH_CONFIG);
681 749
682 for (i = 0; i < ARRAY_SIZE(cfg_info_temp); i++) { 750 for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) {
683 if (ISTEMP(i, data->uch_config)) { 751 if (ISTEMP(i, data->uch_config)) {
684 device_create_file(&client->dev, 752 if ((err = sysfs_create_group(&client->dev.kobj,
685 cfg_info_temp[i].input); 753 &vt8231_group_temps[i])))
686 device_create_file(&client->dev, cfg_info_temp[i].max); 754 goto exit_remove_files;
687 device_create_file(&client->dev, cfg_info_temp[i].min);
688 } 755 }
689 } 756 }
690 757
691 for (i = 0; i < ARRAY_SIZE(cfg_info_volt); i++) { 758 for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) {
692 if (ISVOLT(i, data->uch_config)) { 759 if (ISVOLT(i, data->uch_config)) {
693 device_create_file(&client->dev, 760 if ((err = sysfs_create_group(&client->dev.kobj,
694 cfg_info_volt[i].input); 761 &vt8231_group_volts[i])))
695 device_create_file(&client->dev, cfg_info_volt[i].max); 762 goto exit_remove_files;
696 device_create_file(&client->dev, cfg_info_volt[i].min);
697 } 763 }
698 } 764 }
699 765
700 device_create_file(&client->dev, &sensor_dev_attr_fan1_input.dev_attr); 766 data->class_dev = hwmon_device_register(&client->dev);
701 device_create_file(&client->dev, &sensor_dev_attr_fan2_input.dev_attr); 767 if (IS_ERR(data->class_dev)) {
702 device_create_file(&client->dev, &sensor_dev_attr_fan1_min.dev_attr); 768 err = PTR_ERR(data->class_dev);
703 device_create_file(&client->dev, &sensor_dev_attr_fan2_min.dev_attr); 769 goto exit_remove_files;
704 device_create_file(&client->dev, &sensor_dev_attr_fan1_div.dev_attr); 770 }
705 device_create_file(&client->dev, &sensor_dev_attr_fan2_div.dev_attr);
706
707 device_create_file(&client->dev, &dev_attr_alarms);
708 return 0; 771 return 0;
709 772
773exit_remove_files:
774 for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++)
775 sysfs_remove_group(&client->dev.kobj, &vt8231_group_volts[i]);
776
777 for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++)
778 sysfs_remove_group(&client->dev.kobj, &vt8231_group_temps[i]);
779
780 sysfs_remove_group(&client->dev.kobj, &vt8231_group);
710exit_detach: 781exit_detach:
711 i2c_detach_client(client); 782 i2c_detach_client(client);
712exit_free: 783exit_free:
@@ -719,10 +790,18 @@ exit_release:
719static int vt8231_detach_client(struct i2c_client *client) 790static int vt8231_detach_client(struct i2c_client *client)
720{ 791{
721 struct vt8231_data *data = i2c_get_clientdata(client); 792 struct vt8231_data *data = i2c_get_clientdata(client);
722 int err; 793 int err, i;
723 794
724 hwmon_device_unregister(data->class_dev); 795 hwmon_device_unregister(data->class_dev);
725 796
797 for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++)
798 sysfs_remove_group(&client->dev.kobj, &vt8231_group_volts[i]);
799
800 for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++)
801 sysfs_remove_group(&client->dev.kobj, &vt8231_group_temps[i]);
802
803 sysfs_remove_group(&client->dev.kobj, &vt8231_group);
804
726 if ((err = i2c_detach_client(client))) { 805 if ((err = i2c_detach_client(client))) {
727 return err; 806 return err;
728 } 807 }
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 40301bc6ce18..833faa275ffa 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -2,6 +2,9 @@
2 w83627ehf - Driver for the hardware monitoring functionality of 2 w83627ehf - Driver for the hardware monitoring functionality of
3 the Winbond W83627EHF Super-I/O chip 3 the Winbond W83627EHF Super-I/O chip
4 Copyright (C) 2005 Jean Delvare <khali@linux-fr.org> 4 Copyright (C) 2005 Jean Delvare <khali@linux-fr.org>
5 Copyright (C) 2006 Yuan Mu (Winbond),
6 Rudolf Marek <r.marek@sh.cvut.cz>
7 David Hubbard <david.c.hubbard@gmail.com>
5 8
6 Shamelessly ripped from the w83627hf driver 9 Shamelessly ripped from the w83627hf driver
7 Copyright (C) 2003 Mark Studebaker 10 Copyright (C) 2003 Mark Studebaker
@@ -29,8 +32,8 @@
29 32
30 Supports the following chips: 33 Supports the following chips:
31 34
32 Chip #vin #fan #pwm #temp chip_id man_id 35 Chip #vin #fan #pwm #temp chip_id man_id
33 w83627ehf 10 5 - 3 0x88 0x5ca3 36 w83627ehf 10 5 4 3 0x88,0xa1 0x5ca3
34*/ 37*/
35 38
36#include <linux/module.h> 39#include <linux/module.h>
@@ -145,10 +148,44 @@ static const u16 W83627EHF_REG_TEMP_CONFIG[] = { 0x152, 0x252 };
145#define W83627EHF_REG_ALARM2 0x45A 148#define W83627EHF_REG_ALARM2 0x45A
146#define W83627EHF_REG_ALARM3 0x45B 149#define W83627EHF_REG_ALARM3 0x45B
147 150
151/* SmartFan registers */
152/* DC or PWM output fan configuration */
153static const u8 W83627EHF_REG_PWM_ENABLE[] = {
154 0x04, /* SYS FAN0 output mode and PWM mode */
155 0x04, /* CPU FAN0 output mode and PWM mode */
156 0x12, /* AUX FAN mode */
157 0x62, /* CPU fan1 mode */
158};
159
160static const u8 W83627EHF_PWM_MODE_SHIFT[] = { 0, 1, 0, 6 };
161static const u8 W83627EHF_PWM_ENABLE_SHIFT[] = { 2, 4, 1, 4 };
162
163/* FAN Duty Cycle, be used to control */
164static const u8 W83627EHF_REG_PWM[] = { 0x01, 0x03, 0x11, 0x61 };
165static const u8 W83627EHF_REG_TARGET[] = { 0x05, 0x06, 0x13, 0x63 };
166static const u8 W83627EHF_REG_TOLERANCE[] = { 0x07, 0x07, 0x14, 0x62 };
167
168
169/* Advanced Fan control, some values are common for all fans */
170static const u8 W83627EHF_REG_FAN_MIN_OUTPUT[] = { 0x08, 0x09, 0x15, 0x64 };
171static const u8 W83627EHF_REG_FAN_STOP_TIME[] = { 0x0C, 0x0D, 0x17, 0x66 };
172
148/* 173/*
149 * Conversions 174 * Conversions
150 */ 175 */
151 176
177/* 1 is PWM mode, output in ms */
178static inline unsigned int step_time_from_reg(u8 reg, u8 mode)
179{
180 return mode ? 100 * reg : 400 * reg;
181}
182
183static inline u8 step_time_to_reg(unsigned int msec, u8 mode)
184{
185 return SENSORS_LIMIT((mode ? (msec + 50) / 100 :
186 (msec + 200) / 400), 1, 255);
187}
188
152static inline unsigned int 189static inline unsigned int
153fan_from_reg(u8 reg, unsigned int div) 190fan_from_reg(u8 reg, unsigned int div)
154{ 191{
@@ -170,12 +207,12 @@ temp1_from_reg(s8 reg)
170} 207}
171 208
172static inline s8 209static inline s8
173temp1_to_reg(int temp) 210temp1_to_reg(int temp, int min, int max)
174{ 211{
175 if (temp <= -128000) 212 if (temp <= min)
176 return -128; 213 return min / 1000;
177 if (temp >= 127000) 214 if (temp >= max)
178 return 127; 215 return max / 1000;
179 if (temp < 0) 216 if (temp < 0)
180 return (temp - 500) / 1000; 217 return (temp - 500) / 1000;
181 return (temp + 500) / 1000; 218 return (temp + 500) / 1000;
@@ -223,6 +260,16 @@ struct w83627ehf_data {
223 s16 temp_max[2]; 260 s16 temp_max[2];
224 s16 temp_max_hyst[2]; 261 s16 temp_max_hyst[2];
225 u32 alarms; 262 u32 alarms;
263
264 u8 pwm_mode[4]; /* 0->DC variable voltage, 1->PWM variable duty cycle */
265 u8 pwm_enable[4]; /* 1->manual
266 2->thermal cruise (also called SmartFan I) */
267 u8 pwm[4];
268 u8 target_temp[4];
269 u8 tolerance[4];
270
271 u8 fan_min_output[4]; /* minimum fan speed */
272 u8 fan_stop_time[4];
226}; 273};
227 274
228static inline int is_word_sized(u16 reg) 275static inline int is_word_sized(u16 reg)
@@ -349,6 +396,7 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
349{ 396{
350 struct i2c_client *client = to_i2c_client(dev); 397 struct i2c_client *client = to_i2c_client(dev);
351 struct w83627ehf_data *data = i2c_get_clientdata(client); 398 struct w83627ehf_data *data = i2c_get_clientdata(client);
399 int pwmcfg = 0, tolerance = 0; /* shut up the compiler */
352 int i; 400 int i;
353 401
354 mutex_lock(&data->update_lock); 402 mutex_lock(&data->update_lock);
@@ -416,6 +464,34 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
416 } 464 }
417 } 465 }
418 466
467 for (i = 0; i < 4; i++) {
468 /* pwmcfg, tolarance mapped for i=0, i=1 to same reg */
469 if (i != 1) {
470 pwmcfg = w83627ehf_read_value(client,
471 W83627EHF_REG_PWM_ENABLE[i]);
472 tolerance = w83627ehf_read_value(client,
473 W83627EHF_REG_TOLERANCE[i]);
474 }
475 data->pwm_mode[i] =
476 ((pwmcfg >> W83627EHF_PWM_MODE_SHIFT[i]) & 1)
477 ? 0 : 1;
478 data->pwm_enable[i] =
479 ((pwmcfg >> W83627EHF_PWM_ENABLE_SHIFT[i])
480 & 3) + 1;
481 data->pwm[i] = w83627ehf_read_value(client,
482 W83627EHF_REG_PWM[i]);
483 data->fan_min_output[i] = w83627ehf_read_value(client,
484 W83627EHF_REG_FAN_MIN_OUTPUT[i]);
485 data->fan_stop_time[i] = w83627ehf_read_value(client,
486 W83627EHF_REG_FAN_STOP_TIME[i]);
487 data->target_temp[i] =
488 w83627ehf_read_value(client,
489 W83627EHF_REG_TARGET[i]) &
490 (data->pwm_mode[i] == 1 ? 0x7f : 0xff);
491 data->tolerance[i] = (tolerance >> (i == 1 ? 4 : 0))
492 & 0x0f;
493 }
494
419 /* Measured temperatures and limits */ 495 /* Measured temperatures and limits */
420 data->temp1 = w83627ehf_read_value(client, 496 data->temp1 = w83627ehf_read_value(client,
421 W83627EHF_REG_TEMP1); 497 W83627EHF_REG_TEMP1);
@@ -546,14 +622,6 @@ static struct sensor_device_attribute sda_in_max[] = {
546 SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 9), 622 SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 9),
547}; 623};
548 624
549static void device_create_file_in(struct device *dev, int i)
550{
551 device_create_file(dev, &sda_in_input[i].dev_attr);
552 device_create_file(dev, &sda_in_alarm[i].dev_attr);
553 device_create_file(dev, &sda_in_min[i].dev_attr);
554 device_create_file(dev, &sda_in_max[i].dev_attr);
555}
556
557#define show_fan_reg(reg) \ 625#define show_fan_reg(reg) \
558static ssize_t \ 626static ssize_t \
559show_##reg(struct device *dev, struct device_attribute *attr, \ 627show_##reg(struct device *dev, struct device_attribute *attr, \
@@ -681,14 +749,6 @@ static struct sensor_device_attribute sda_fan_div[] = {
681 SENSOR_ATTR(fan5_div, S_IRUGO, show_fan_div, NULL, 4), 749 SENSOR_ATTR(fan5_div, S_IRUGO, show_fan_div, NULL, 4),
682}; 750};
683 751
684static void device_create_file_fan(struct device *dev, int i)
685{
686 device_create_file(dev, &sda_fan_input[i].dev_attr);
687 device_create_file(dev, &sda_fan_alarm[i].dev_attr);
688 device_create_file(dev, &sda_fan_div[i].dev_attr);
689 device_create_file(dev, &sda_fan_min[i].dev_attr);
690}
691
692#define show_temp1_reg(reg) \ 752#define show_temp1_reg(reg) \
693static ssize_t \ 753static ssize_t \
694show_##reg(struct device *dev, struct device_attribute *attr, \ 754show_##reg(struct device *dev, struct device_attribute *attr, \
@@ -711,7 +771,7 @@ store_temp1_##reg(struct device *dev, struct device_attribute *attr, \
711 u32 val = simple_strtoul(buf, NULL, 10); \ 771 u32 val = simple_strtoul(buf, NULL, 10); \
712 \ 772 \
713 mutex_lock(&data->update_lock); \ 773 mutex_lock(&data->update_lock); \
714 data->temp1_##reg = temp1_to_reg(val); \ 774 data->temp1_##reg = temp1_to_reg(val, -128000, 127000); \
715 w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \ 775 w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \
716 data->temp1_##reg); \ 776 data->temp1_##reg); \
717 mutex_unlock(&data->update_lock); \ 777 mutex_unlock(&data->update_lock); \
@@ -777,10 +837,309 @@ static struct sensor_device_attribute sda_temp[] = {
777 SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13), 837 SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13),
778}; 838};
779 839
840#define show_pwm_reg(reg) \
841static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \
842 char *buf) \
843{ \
844 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
845 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
846 int nr = sensor_attr->index; \
847 return sprintf(buf, "%d\n", data->reg[nr]); \
848}
849
850show_pwm_reg(pwm_mode)
851show_pwm_reg(pwm_enable)
852show_pwm_reg(pwm)
853
854static ssize_t
855store_pwm_mode(struct device *dev, struct device_attribute *attr,
856 const char *buf, size_t count)
857{
858 struct i2c_client *client = to_i2c_client(dev);
859 struct w83627ehf_data *data = i2c_get_clientdata(client);
860 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
861 int nr = sensor_attr->index;
862 u32 val = simple_strtoul(buf, NULL, 10);
863 u16 reg;
864
865 if (val > 1)
866 return -EINVAL;
867 mutex_lock(&data->update_lock);
868 reg = w83627ehf_read_value(client, W83627EHF_REG_PWM_ENABLE[nr]);
869 data->pwm_mode[nr] = val;
870 reg &= ~(1 << W83627EHF_PWM_MODE_SHIFT[nr]);
871 if (!val)
872 reg |= 1 << W83627EHF_PWM_MODE_SHIFT[nr];
873 w83627ehf_write_value(client, W83627EHF_REG_PWM_ENABLE[nr], reg);
874 mutex_unlock(&data->update_lock);
875 return count;
876}
877
878static ssize_t
879store_pwm(struct device *dev, struct device_attribute *attr,
880 const char *buf, size_t count)
881{
882 struct i2c_client *client = to_i2c_client(dev);
883 struct w83627ehf_data *data = i2c_get_clientdata(client);
884 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
885 int nr = sensor_attr->index;
886 u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 255);
887
888 mutex_lock(&data->update_lock);
889 data->pwm[nr] = val;
890 w83627ehf_write_value(client, W83627EHF_REG_PWM[nr], val);
891 mutex_unlock(&data->update_lock);
892 return count;
893}
894
895static ssize_t
896store_pwm_enable(struct device *dev, struct device_attribute *attr,
897 const char *buf, size_t count)
898{
899 struct i2c_client *client = to_i2c_client(dev);
900 struct w83627ehf_data *data = i2c_get_clientdata(client);
901 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
902 int nr = sensor_attr->index;
903 u32 val = simple_strtoul(buf, NULL, 10);
904 u16 reg;
905
906 if (!val || (val > 2)) /* only modes 1 and 2 are supported */
907 return -EINVAL;
908 mutex_lock(&data->update_lock);
909 reg = w83627ehf_read_value(client, W83627EHF_REG_PWM_ENABLE[nr]);
910 data->pwm_enable[nr] = val;
911 reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[nr]);
912 reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[nr];
913 w83627ehf_write_value(client, W83627EHF_REG_PWM_ENABLE[nr], reg);
914 mutex_unlock(&data->update_lock);
915 return count;
916}
917
918
919#define show_tol_temp(reg) \
920static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
921 char *buf) \
922{ \
923 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
924 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
925 int nr = sensor_attr->index; \
926 return sprintf(buf, "%d\n", temp1_from_reg(data->reg[nr])); \
927}
928
929show_tol_temp(tolerance)
930show_tol_temp(target_temp)
931
932static ssize_t
933store_target_temp(struct device *dev, struct device_attribute *attr,
934 const char *buf, size_t count)
935{
936 struct i2c_client *client = to_i2c_client(dev);
937 struct w83627ehf_data *data = i2c_get_clientdata(client);
938 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
939 int nr = sensor_attr->index;
940 u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 127000);
941
942 mutex_lock(&data->update_lock);
943 data->target_temp[nr] = val;
944 w83627ehf_write_value(client, W83627EHF_REG_TARGET[nr], val);
945 mutex_unlock(&data->update_lock);
946 return count;
947}
948
949static ssize_t
950store_tolerance(struct device *dev, struct device_attribute *attr,
951 const char *buf, size_t count)
952{
953 struct i2c_client *client = to_i2c_client(dev);
954 struct w83627ehf_data *data = i2c_get_clientdata(client);
955 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
956 int nr = sensor_attr->index;
957 u16 reg;
958 /* Limit the temp to 0C - 15C */
959 u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 15000);
960
961 mutex_lock(&data->update_lock);
962 reg = w83627ehf_read_value(client, W83627EHF_REG_TOLERANCE[nr]);
963 data->tolerance[nr] = val;
964 if (nr == 1)
965 reg = (reg & 0x0f) | (val << 4);
966 else
967 reg = (reg & 0xf0) | val;
968 w83627ehf_write_value(client, W83627EHF_REG_TOLERANCE[nr], reg);
969 mutex_unlock(&data->update_lock);
970 return count;
971}
972
973static struct sensor_device_attribute sda_pwm[] = {
974 SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0),
975 SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1),
976 SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2),
977 SENSOR_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 3),
978};
979
980static struct sensor_device_attribute sda_pwm_mode[] = {
981 SENSOR_ATTR(pwm1_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
982 store_pwm_mode, 0),
983 SENSOR_ATTR(pwm2_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
984 store_pwm_mode, 1),
985 SENSOR_ATTR(pwm3_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
986 store_pwm_mode, 2),
987 SENSOR_ATTR(pwm4_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
988 store_pwm_mode, 3),
989};
990
991static struct sensor_device_attribute sda_pwm_enable[] = {
992 SENSOR_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
993 store_pwm_enable, 0),
994 SENSOR_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
995 store_pwm_enable, 1),
996 SENSOR_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
997 store_pwm_enable, 2),
998 SENSOR_ATTR(pwm4_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
999 store_pwm_enable, 3),
1000};
1001
1002static struct sensor_device_attribute sda_target_temp[] = {
1003 SENSOR_ATTR(pwm1_target, S_IWUSR | S_IRUGO, show_target_temp,
1004 store_target_temp, 0),
1005 SENSOR_ATTR(pwm2_target, S_IWUSR | S_IRUGO, show_target_temp,
1006 store_target_temp, 1),
1007 SENSOR_ATTR(pwm3_target, S_IWUSR | S_IRUGO, show_target_temp,
1008 store_target_temp, 2),
1009 SENSOR_ATTR(pwm4_target, S_IWUSR | S_IRUGO, show_target_temp,
1010 store_target_temp, 3),
1011};
1012
1013static struct sensor_device_attribute sda_tolerance[] = {
1014 SENSOR_ATTR(pwm1_tolerance, S_IWUSR | S_IRUGO, show_tolerance,
1015 store_tolerance, 0),
1016 SENSOR_ATTR(pwm2_tolerance, S_IWUSR | S_IRUGO, show_tolerance,
1017 store_tolerance, 1),
1018 SENSOR_ATTR(pwm3_tolerance, S_IWUSR | S_IRUGO, show_tolerance,
1019 store_tolerance, 2),
1020 SENSOR_ATTR(pwm4_tolerance, S_IWUSR | S_IRUGO, show_tolerance,
1021 store_tolerance, 3),
1022};
1023
1024/* Smart Fan registers */
1025
1026#define fan_functions(reg, REG) \
1027static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
1028 char *buf) \
1029{ \
1030 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
1031 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
1032 int nr = sensor_attr->index; \
1033 return sprintf(buf, "%d\n", data->reg[nr]); \
1034}\
1035static ssize_t \
1036store_##reg(struct device *dev, struct device_attribute *attr, \
1037 const char *buf, size_t count) \
1038{\
1039 struct i2c_client *client = to_i2c_client(dev); \
1040 struct w83627ehf_data *data = i2c_get_clientdata(client); \
1041 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
1042 int nr = sensor_attr->index; \
1043 u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 1, 255); \
1044 mutex_lock(&data->update_lock); \
1045 data->reg[nr] = val; \
1046 w83627ehf_write_value(client, W83627EHF_REG_##REG[nr], val); \
1047 mutex_unlock(&data->update_lock); \
1048 return count; \
1049}
1050
1051fan_functions(fan_min_output, FAN_MIN_OUTPUT)
1052
1053#define fan_time_functions(reg, REG) \
1054static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
1055 char *buf) \
1056{ \
1057 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
1058 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
1059 int nr = sensor_attr->index; \
1060 return sprintf(buf, "%d\n", \
1061 step_time_from_reg(data->reg[nr], data->pwm_mode[nr])); \
1062} \
1063\
1064static ssize_t \
1065store_##reg(struct device *dev, struct device_attribute *attr, \
1066 const char *buf, size_t count) \
1067{ \
1068 struct i2c_client *client = to_i2c_client(dev); \
1069 struct w83627ehf_data *data = i2c_get_clientdata(client); \
1070 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
1071 int nr = sensor_attr->index; \
1072 u8 val = step_time_to_reg(simple_strtoul(buf, NULL, 10), \
1073 data->pwm_mode[nr]); \
1074 mutex_lock(&data->update_lock); \
1075 data->reg[nr] = val; \
1076 w83627ehf_write_value(client, W83627EHF_REG_##REG[nr], val); \
1077 mutex_unlock(&data->update_lock); \
1078 return count; \
1079} \
1080
1081fan_time_functions(fan_stop_time, FAN_STOP_TIME)
1082
1083
1084static struct sensor_device_attribute sda_sf3_arrays_fan4[] = {
1085 SENSOR_ATTR(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1086 store_fan_stop_time, 3),
1087 SENSOR_ATTR(pwm4_min_output, S_IWUSR | S_IRUGO, show_fan_min_output,
1088 store_fan_min_output, 3),
1089};
1090
1091static struct sensor_device_attribute sda_sf3_arrays[] = {
1092 SENSOR_ATTR(pwm1_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1093 store_fan_stop_time, 0),
1094 SENSOR_ATTR(pwm2_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1095 store_fan_stop_time, 1),
1096 SENSOR_ATTR(pwm3_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1097 store_fan_stop_time, 2),
1098 SENSOR_ATTR(pwm1_min_output, S_IWUSR | S_IRUGO, show_fan_min_output,
1099 store_fan_min_output, 0),
1100 SENSOR_ATTR(pwm2_min_output, S_IWUSR | S_IRUGO, show_fan_min_output,
1101 store_fan_min_output, 1),
1102 SENSOR_ATTR(pwm3_min_output, S_IWUSR | S_IRUGO, show_fan_min_output,
1103 store_fan_min_output, 2),
1104};
1105
780/* 1106/*
781 * Driver and client management 1107 * Driver and client management
782 */ 1108 */
783 1109
1110static void w83627ehf_device_remove_files(struct device *dev)
1111{
1112 /* some entries in the following arrays may not have been used in
1113 * device_create_file(), but device_remove_file() will ignore them */
1114 int i;
1115
1116 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++)
1117 device_remove_file(dev, &sda_sf3_arrays[i].dev_attr);
1118 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++)
1119 device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr);
1120 for (i = 0; i < 10; i++) {
1121 device_remove_file(dev, &sda_in_input[i].dev_attr);
1122 device_remove_file(dev, &sda_in_alarm[i].dev_attr);
1123 device_remove_file(dev, &sda_in_min[i].dev_attr);
1124 device_remove_file(dev, &sda_in_max[i].dev_attr);
1125 }
1126 for (i = 0; i < 5; i++) {
1127 device_remove_file(dev, &sda_fan_input[i].dev_attr);
1128 device_remove_file(dev, &sda_fan_alarm[i].dev_attr);
1129 device_remove_file(dev, &sda_fan_div[i].dev_attr);
1130 device_remove_file(dev, &sda_fan_min[i].dev_attr);
1131 }
1132 for (i = 0; i < 4; i++) {
1133 device_remove_file(dev, &sda_pwm[i].dev_attr);
1134 device_remove_file(dev, &sda_pwm_mode[i].dev_attr);
1135 device_remove_file(dev, &sda_pwm_enable[i].dev_attr);
1136 device_remove_file(dev, &sda_target_temp[i].dev_attr);
1137 device_remove_file(dev, &sda_tolerance[i].dev_attr);
1138 }
1139 for (i = 0; i < ARRAY_SIZE(sda_temp); i++)
1140 device_remove_file(dev, &sda_temp[i].dev_attr);
1141}
1142
784static struct i2c_driver w83627ehf_driver; 1143static struct i2c_driver w83627ehf_driver;
785 1144
786static void w83627ehf_init_client(struct i2c_client *client) 1145static void w83627ehf_init_client(struct i2c_client *client)
@@ -810,6 +1169,7 @@ static int w83627ehf_detect(struct i2c_adapter *adapter)
810 struct i2c_client *client; 1169 struct i2c_client *client;
811 struct w83627ehf_data *data; 1170 struct w83627ehf_data *data;
812 struct device *dev; 1171 struct device *dev;
1172 u8 fan4pin, fan5pin;
813 int i, err = 0; 1173 int i, err = 0;
814 1174
815 if (!request_region(address + REGION_OFFSET, REGION_LENGTH, 1175 if (!request_region(address + REGION_OFFSET, REGION_LENGTH,
@@ -848,35 +1208,87 @@ static int w83627ehf_detect(struct i2c_adapter *adapter)
848 data->fan_min[i] = w83627ehf_read_value(client, 1208 data->fan_min[i] = w83627ehf_read_value(client,
849 W83627EHF_REG_FAN_MIN[i]); 1209 W83627EHF_REG_FAN_MIN[i]);
850 1210
1211 /* fan4 and fan5 share some pins with the GPIO and serial flash */
1212
1213 superio_enter();
1214 fan5pin = superio_inb(0x24) & 0x2;
1215 fan4pin = superio_inb(0x29) & 0x6;
1216 superio_exit();
1217
851 /* It looks like fan4 and fan5 pins can be alternatively used 1218 /* It looks like fan4 and fan5 pins can be alternatively used
852 as fan on/off switches */ 1219 as fan on/off switches */
1220
853 data->has_fan = 0x07; /* fan1, fan2 and fan3 */ 1221 data->has_fan = 0x07; /* fan1, fan2 and fan3 */
854 i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1); 1222 i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1);
855 if (i & (1 << 2)) 1223 if ((i & (1 << 2)) && (!fan4pin))
856 data->has_fan |= (1 << 3); 1224 data->has_fan |= (1 << 3);
857 if (i & (1 << 0)) 1225 if ((i & (1 << 0)) && (!fan5pin))
858 data->has_fan |= (1 << 4); 1226 data->has_fan |= (1 << 4);
859 1227
860 /* Register sysfs hooks */ 1228 /* Register sysfs hooks */
861 data->class_dev = hwmon_device_register(dev); 1229 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++)
862 if (IS_ERR(data->class_dev)) { 1230 if ((err = device_create_file(dev,
863 err = PTR_ERR(data->class_dev); 1231 &sda_sf3_arrays[i].dev_attr)))
864 goto exit_detach; 1232 goto exit_remove;
865 } 1233
1234 /* if fan4 is enabled create the sf3 files for it */
1235 if (data->has_fan & (1 << 3))
1236 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) {
1237 if ((err = device_create_file(dev,
1238 &sda_sf3_arrays_fan4[i].dev_attr)))
1239 goto exit_remove;
1240 }
866 1241
867 for (i = 0; i < 10; i++) 1242 for (i = 0; i < 10; i++)
868 device_create_file_in(dev, i); 1243 if ((err = device_create_file(dev, &sda_in_input[i].dev_attr))
1244 || (err = device_create_file(dev,
1245 &sda_in_alarm[i].dev_attr))
1246 || (err = device_create_file(dev,
1247 &sda_in_min[i].dev_attr))
1248 || (err = device_create_file(dev,
1249 &sda_in_max[i].dev_attr)))
1250 goto exit_remove;
869 1251
870 for (i = 0; i < 5; i++) { 1252 for (i = 0; i < 5; i++) {
871 if (data->has_fan & (1 << i)) 1253 if (data->has_fan & (1 << i)) {
872 device_create_file_fan(dev, i); 1254 if ((err = device_create_file(dev,
1255 &sda_fan_input[i].dev_attr))
1256 || (err = device_create_file(dev,
1257 &sda_fan_alarm[i].dev_attr))
1258 || (err = device_create_file(dev,
1259 &sda_fan_div[i].dev_attr))
1260 || (err = device_create_file(dev,
1261 &sda_fan_min[i].dev_attr)))
1262 goto exit_remove;
1263 if (i < 4 && /* w83627ehf only has 4 pwm */
1264 ((err = device_create_file(dev,
1265 &sda_pwm[i].dev_attr))
1266 || (err = device_create_file(dev,
1267 &sda_pwm_mode[i].dev_attr))
1268 || (err = device_create_file(dev,
1269 &sda_pwm_enable[i].dev_attr))
1270 || (err = device_create_file(dev,
1271 &sda_target_temp[i].dev_attr))
1272 || (err = device_create_file(dev,
1273 &sda_tolerance[i].dev_attr))))
1274 goto exit_remove;
1275 }
873 } 1276 }
1277
874 for (i = 0; i < ARRAY_SIZE(sda_temp); i++) 1278 for (i = 0; i < ARRAY_SIZE(sda_temp); i++)
875 device_create_file(dev, &sda_temp[i].dev_attr); 1279 if ((err = device_create_file(dev, &sda_temp[i].dev_attr)))
1280 goto exit_remove;
1281
1282 data->class_dev = hwmon_device_register(dev);
1283 if (IS_ERR(data->class_dev)) {
1284 err = PTR_ERR(data->class_dev);
1285 goto exit_remove;
1286 }
876 1287
877 return 0; 1288 return 0;
878 1289
879exit_detach: 1290exit_remove:
1291 w83627ehf_device_remove_files(dev);
880 i2c_detach_client(client); 1292 i2c_detach_client(client);
881exit_free: 1293exit_free:
882 kfree(data); 1294 kfree(data);
@@ -892,6 +1304,7 @@ static int w83627ehf_detach_client(struct i2c_client *client)
892 int err; 1304 int err;
893 1305
894 hwmon_device_unregister(data->class_dev); 1306 hwmon_device_unregister(data->class_dev);
1307 w83627ehf_device_remove_files(&client->dev);
895 1308
896 if ((err = i2c_detach_client(client))) 1309 if ((err = i2c_detach_client(client)))
897 return err; 1310 return err;
@@ -903,6 +1316,7 @@ static int w83627ehf_detach_client(struct i2c_client *client)
903 1316
904static struct i2c_driver w83627ehf_driver = { 1317static struct i2c_driver w83627ehf_driver = {
905 .driver = { 1318 .driver = {
1319 .owner = THIS_MODULE,
906 .name = "w83627ehf", 1320 .name = "w83627ehf",
907 }, 1321 },
908 .attach_adapter = w83627ehf_detect, 1322 .attach_adapter = w83627ehf_detect,
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index 79368d53c363..dfdc29c77123 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -339,6 +339,7 @@ static void w83627hf_init_client(struct i2c_client *client);
339 339
340static struct i2c_driver w83627hf_driver = { 340static struct i2c_driver w83627hf_driver = {
341 .driver = { 341 .driver = {
342 .owner = THIS_MODULE,
342 .name = "w83627hf", 343 .name = "w83627hf",
343 }, 344 },
344 .attach_adapter = w83627hf_detect, 345 .attach_adapter = w83627hf_detect,
@@ -511,13 +512,6 @@ static DEVICE_ATTR(in0_min, S_IRUGO | S_IWUSR,
511static DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR, 512static DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR,
512 show_regs_in_max0, store_regs_in_max0); 513 show_regs_in_max0, store_regs_in_max0);
513 514
514#define device_create_file_in(client, offset) \
515do { \
516device_create_file(&client->dev, &dev_attr_in##offset##_input); \
517device_create_file(&client->dev, &dev_attr_in##offset##_min); \
518device_create_file(&client->dev, &dev_attr_in##offset##_max); \
519} while (0)
520
521#define show_fan_reg(reg) \ 515#define show_fan_reg(reg) \
522static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 516static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
523{ \ 517{ \
@@ -575,12 +569,6 @@ sysfs_fan_min_offset(2);
575sysfs_fan_offset(3); 569sysfs_fan_offset(3);
576sysfs_fan_min_offset(3); 570sysfs_fan_min_offset(3);
577 571
578#define device_create_file_fan(client, offset) \
579do { \
580device_create_file(&client->dev, &dev_attr_fan##offset##_input); \
581device_create_file(&client->dev, &dev_attr_fan##offset##_min); \
582} while (0)
583
584#define show_temp_reg(reg) \ 572#define show_temp_reg(reg) \
585static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 573static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
586{ \ 574{ \
@@ -655,13 +643,6 @@ sysfs_temp_offsets(1);
655sysfs_temp_offsets(2); 643sysfs_temp_offsets(2);
656sysfs_temp_offsets(3); 644sysfs_temp_offsets(3);
657 645
658#define device_create_file_temp(client, offset) \
659do { \
660device_create_file(&client->dev, &dev_attr_temp##offset##_input); \
661device_create_file(&client->dev, &dev_attr_temp##offset##_max); \
662device_create_file(&client->dev, &dev_attr_temp##offset##_max_hyst); \
663} while (0)
664
665static ssize_t 646static ssize_t
666show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) 647show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
667{ 648{
@@ -669,8 +650,6 @@ show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
669 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); 650 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
670} 651}
671static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 652static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
672#define device_create_file_vid(client) \
673device_create_file(&client->dev, &dev_attr_cpu0_vid)
674 653
675static ssize_t 654static ssize_t
676show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) 655show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
@@ -691,8 +670,6 @@ store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf
691 return count; 670 return count;
692} 671}
693static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); 672static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
694#define device_create_file_vrm(client) \
695device_create_file(&client->dev, &dev_attr_vrm)
696 673
697static ssize_t 674static ssize_t
698show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) 675show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
@@ -701,8 +678,6 @@ show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
701 return sprintf(buf, "%ld\n", (long) data->alarms); 678 return sprintf(buf, "%ld\n", (long) data->alarms);
702} 679}
703static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); 680static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
704#define device_create_file_alarms(client) \
705device_create_file(&client->dev, &dev_attr_alarms)
706 681
707#define show_beep_reg(REG, reg) \ 682#define show_beep_reg(REG, reg) \
708static ssize_t show_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \ 683static ssize_t show_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \
@@ -765,12 +740,6 @@ static DEVICE_ATTR(beep_##reg, S_IRUGO | S_IWUSR, \
765sysfs_beep(ENABLE, enable); 740sysfs_beep(ENABLE, enable);
766sysfs_beep(MASK, mask); 741sysfs_beep(MASK, mask);
767 742
768#define device_create_file_beep(client) \
769do { \
770device_create_file(&client->dev, &dev_attr_beep_enable); \
771device_create_file(&client->dev, &dev_attr_beep_mask); \
772} while (0)
773
774static ssize_t 743static ssize_t
775show_fan_div_reg(struct device *dev, char *buf, int nr) 744show_fan_div_reg(struct device *dev, char *buf, int nr)
776{ 745{
@@ -836,11 +805,6 @@ sysfs_fan_div(1);
836sysfs_fan_div(2); 805sysfs_fan_div(2);
837sysfs_fan_div(3); 806sysfs_fan_div(3);
838 807
839#define device_create_file_fan_div(client, offset) \
840do { \
841device_create_file(&client->dev, &dev_attr_fan##offset##_div); \
842} while (0)
843
844static ssize_t 808static ssize_t
845show_pwm_reg(struct device *dev, char *buf, int nr) 809show_pwm_reg(struct device *dev, char *buf, int nr)
846{ 810{
@@ -895,11 +859,6 @@ sysfs_pwm(1);
895sysfs_pwm(2); 859sysfs_pwm(2);
896sysfs_pwm(3); 860sysfs_pwm(3);
897 861
898#define device_create_file_pwm(client, offset) \
899do { \
900device_create_file(&client->dev, &dev_attr_pwm##offset); \
901} while (0)
902
903static ssize_t 862static ssize_t
904show_sensor_reg(struct device *dev, char *buf, int nr) 863show_sensor_reg(struct device *dev, char *buf, int nr)
905{ 864{
@@ -971,12 +930,6 @@ sysfs_sensor(1);
971sysfs_sensor(2); 930sysfs_sensor(2);
972sysfs_sensor(3); 931sysfs_sensor(3);
973 932
974#define device_create_file_sensor(client, offset) \
975do { \
976device_create_file(&client->dev, &dev_attr_temp##offset##_type); \
977} while (0)
978
979
980static int __init w83627hf_find(int sioaddr, unsigned short *addr) 933static int __init w83627hf_find(int sioaddr, unsigned short *addr)
981{ 934{
982 u16 val; 935 u16 val;
@@ -1008,6 +961,85 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr)
1008 return 0; 961 return 0;
1009} 962}
1010 963
964static struct attribute *w83627hf_attributes[] = {
965 &dev_attr_in0_input.attr,
966 &dev_attr_in0_min.attr,
967 &dev_attr_in0_max.attr,
968 &dev_attr_in2_input.attr,
969 &dev_attr_in2_min.attr,
970 &dev_attr_in2_max.attr,
971 &dev_attr_in3_input.attr,
972 &dev_attr_in3_min.attr,
973 &dev_attr_in3_max.attr,
974 &dev_attr_in4_input.attr,
975 &dev_attr_in4_min.attr,
976 &dev_attr_in4_max.attr,
977 &dev_attr_in7_input.attr,
978 &dev_attr_in7_min.attr,
979 &dev_attr_in7_max.attr,
980 &dev_attr_in8_input.attr,
981 &dev_attr_in8_min.attr,
982 &dev_attr_in8_max.attr,
983
984 &dev_attr_fan1_input.attr,
985 &dev_attr_fan1_min.attr,
986 &dev_attr_fan1_div.attr,
987 &dev_attr_fan2_input.attr,
988 &dev_attr_fan2_min.attr,
989 &dev_attr_fan2_div.attr,
990
991 &dev_attr_temp1_input.attr,
992 &dev_attr_temp1_max.attr,
993 &dev_attr_temp1_max_hyst.attr,
994 &dev_attr_temp1_type.attr,
995 &dev_attr_temp2_input.attr,
996 &dev_attr_temp2_max.attr,
997 &dev_attr_temp2_max_hyst.attr,
998 &dev_attr_temp2_type.attr,
999
1000 &dev_attr_alarms.attr,
1001 &dev_attr_beep_enable.attr,
1002 &dev_attr_beep_mask.attr,
1003
1004 &dev_attr_pwm1.attr,
1005 &dev_attr_pwm2.attr,
1006
1007 NULL
1008};
1009
1010static const struct attribute_group w83627hf_group = {
1011 .attrs = w83627hf_attributes,
1012};
1013
1014static struct attribute *w83627hf_attributes_opt[] = {
1015 &dev_attr_in1_input.attr,
1016 &dev_attr_in1_min.attr,
1017 &dev_attr_in1_max.attr,
1018 &dev_attr_in5_input.attr,
1019 &dev_attr_in5_min.attr,
1020 &dev_attr_in5_max.attr,
1021 &dev_attr_in6_input.attr,
1022 &dev_attr_in6_min.attr,
1023 &dev_attr_in6_max.attr,
1024
1025 &dev_attr_fan3_input.attr,
1026 &dev_attr_fan3_min.attr,
1027 &dev_attr_fan3_div.attr,
1028
1029 &dev_attr_temp3_input.attr,
1030 &dev_attr_temp3_max.attr,
1031 &dev_attr_temp3_max_hyst.attr,
1032 &dev_attr_temp3_type.attr,
1033
1034 &dev_attr_pwm3.attr,
1035
1036 NULL
1037};
1038
1039static const struct attribute_group w83627hf_group_opt = {
1040 .attrs = w83627hf_attributes_opt,
1041};
1042
1011static int w83627hf_detect(struct i2c_adapter *adapter) 1043static int w83627hf_detect(struct i2c_adapter *adapter)
1012{ 1044{
1013 int val, kind; 1045 int val, kind;
@@ -1107,62 +1139,72 @@ static int w83627hf_detect(struct i2c_adapter *adapter)
1107 data->fan_min[1] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(2)); 1139 data->fan_min[1] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(2));
1108 data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3)); 1140 data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3));
1109 1141
1110 /* Register sysfs hooks */ 1142 /* Register common device attributes */
1111 data->class_dev = hwmon_device_register(&new_client->dev); 1143 if ((err = sysfs_create_group(&new_client->dev.kobj, &w83627hf_group)))
1112 if (IS_ERR(data->class_dev)) {
1113 err = PTR_ERR(data->class_dev);
1114 goto ERROR3; 1144 goto ERROR3;
1115 }
1116
1117 device_create_file_in(new_client, 0);
1118 if (kind != w83697hf)
1119 device_create_file_in(new_client, 1);
1120 device_create_file_in(new_client, 2);
1121 device_create_file_in(new_client, 3);
1122 device_create_file_in(new_client, 4);
1123 if (kind == w83627hf || kind == w83697hf) {
1124 device_create_file_in(new_client, 5);
1125 device_create_file_in(new_client, 6);
1126 }
1127 device_create_file_in(new_client, 7);
1128 device_create_file_in(new_client, 8);
1129
1130 device_create_file_fan(new_client, 1);
1131 device_create_file_fan(new_client, 2);
1132 if (kind != w83697hf)
1133 device_create_file_fan(new_client, 3);
1134
1135 device_create_file_temp(new_client, 1);
1136 device_create_file_temp(new_client, 2);
1137 if (kind != w83697hf)
1138 device_create_file_temp(new_client, 3);
1139 1145
1140 if (kind != w83697hf && data->vid != 0xff) { 1146 /* Register chip-specific device attributes */
1141 device_create_file_vid(new_client); 1147 if (kind == w83627hf || kind == w83697hf)
1142 device_create_file_vrm(new_client); 1148 if ((err = device_create_file(&new_client->dev,
1143 } 1149 &dev_attr_in5_input))
1150 || (err = device_create_file(&new_client->dev,
1151 &dev_attr_in5_min))
1152 || (err = device_create_file(&new_client->dev,
1153 &dev_attr_in5_max))
1154 || (err = device_create_file(&new_client->dev,
1155 &dev_attr_in6_input))
1156 || (err = device_create_file(&new_client->dev,
1157 &dev_attr_in6_min))
1158 || (err = device_create_file(&new_client->dev,
1159 &dev_attr_in6_max)))
1160 goto ERROR4;
1144 1161
1145 device_create_file_fan_div(new_client, 1);
1146 device_create_file_fan_div(new_client, 2);
1147 if (kind != w83697hf) 1162 if (kind != w83697hf)
1148 device_create_file_fan_div(new_client, 3); 1163 if ((err = device_create_file(&new_client->dev,
1149 1164 &dev_attr_in1_input))
1150 device_create_file_alarms(new_client); 1165 || (err = device_create_file(&new_client->dev,
1151 1166 &dev_attr_in1_min))
1152 device_create_file_beep(new_client); 1167 || (err = device_create_file(&new_client->dev,
1168 &dev_attr_in1_max))
1169 || (err = device_create_file(&new_client->dev,
1170 &dev_attr_fan3_input))
1171 || (err = device_create_file(&new_client->dev,
1172 &dev_attr_fan3_min))
1173 || (err = device_create_file(&new_client->dev,
1174 &dev_attr_fan3_div))
1175 || (err = device_create_file(&new_client->dev,
1176 &dev_attr_temp3_input))
1177 || (err = device_create_file(&new_client->dev,
1178 &dev_attr_temp3_max))
1179 || (err = device_create_file(&new_client->dev,
1180 &dev_attr_temp3_max_hyst))
1181 || (err = device_create_file(&new_client->dev,
1182 &dev_attr_temp3_type)))
1183 goto ERROR4;
1184
1185 if (kind != w83697hf && data->vid != 0xff)
1186 if ((err = device_create_file(&new_client->dev,
1187 &dev_attr_cpu0_vid))
1188 || (err = device_create_file(&new_client->dev,
1189 &dev_attr_vrm)))
1190 goto ERROR4;
1153 1191
1154 device_create_file_pwm(new_client, 1);
1155 device_create_file_pwm(new_client, 2);
1156 if (kind == w83627thf || kind == w83637hf || kind == w83687thf) 1192 if (kind == w83627thf || kind == w83637hf || kind == w83687thf)
1157 device_create_file_pwm(new_client, 3); 1193 if ((err = device_create_file(&new_client->dev,
1194 &dev_attr_pwm3)))
1195 goto ERROR4;
1158 1196
1159 device_create_file_sensor(new_client, 1); 1197 data->class_dev = hwmon_device_register(&new_client->dev);
1160 device_create_file_sensor(new_client, 2); 1198 if (IS_ERR(data->class_dev)) {
1161 if (kind != w83697hf) 1199 err = PTR_ERR(data->class_dev);
1162 device_create_file_sensor(new_client, 3); 1200 goto ERROR4;
1201 }
1163 1202
1164 return 0; 1203 return 0;
1165 1204
1205 ERROR4:
1206 sysfs_remove_group(&new_client->dev.kobj, &w83627hf_group);
1207 sysfs_remove_group(&new_client->dev.kobj, &w83627hf_group_opt);
1166 ERROR3: 1208 ERROR3:
1167 i2c_detach_client(new_client); 1209 i2c_detach_client(new_client);
1168 ERROR2: 1210 ERROR2:
@@ -1180,6 +1222,9 @@ static int w83627hf_detach_client(struct i2c_client *client)
1180 1222
1181 hwmon_device_unregister(data->class_dev); 1223 hwmon_device_unregister(data->class_dev);
1182 1224
1225 sysfs_remove_group(&client->dev.kobj, &w83627hf_group);
1226 sysfs_remove_group(&client->dev.kobj, &w83627hf_group_opt);
1227
1183 if ((err = i2c_detach_client(client))) 1228 if ((err = i2c_detach_client(client)))
1184 return err; 1229 return err;
1185 1230
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index 7be469ed0f8f..a4584ec69842 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -41,6 +41,7 @@
41#include <linux/i2c-isa.h> 41#include <linux/i2c-isa.h>
42#include <linux/hwmon.h> 42#include <linux/hwmon.h>
43#include <linux/hwmon-vid.h> 43#include <linux/hwmon-vid.h>
44#include <linux/sysfs.h>
44#include <linux/err.h> 45#include <linux/err.h>
45#include <linux/mutex.h> 46#include <linux/mutex.h>
46#include <asm/io.h> 47#include <asm/io.h>
@@ -288,6 +289,7 @@ static struct i2c_driver w83781d_driver = {
288 289
289static struct i2c_driver w83781d_isa_driver = { 290static struct i2c_driver w83781d_isa_driver = {
290 .driver = { 291 .driver = {
292 .owner = THIS_MODULE,
291 .name = "w83781d-isa", 293 .name = "w83781d-isa",
292 }, 294 },
293 .attach_adapter = w83781d_isa_attach_adapter, 295 .attach_adapter = w83781d_isa_attach_adapter,
@@ -359,13 +361,6 @@ sysfs_in_offsets(6);
359sysfs_in_offsets(7); 361sysfs_in_offsets(7);
360sysfs_in_offsets(8); 362sysfs_in_offsets(8);
361 363
362#define device_create_file_in(client, offset) \
363do { \
364device_create_file(&client->dev, &dev_attr_in##offset##_input); \
365device_create_file(&client->dev, &dev_attr_in##offset##_min); \
366device_create_file(&client->dev, &dev_attr_in##offset##_max); \
367} while (0)
368
369#define show_fan_reg(reg) \ 364#define show_fan_reg(reg) \
370static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 365static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
371{ \ 366{ \
@@ -420,12 +415,6 @@ sysfs_fan_min_offset(2);
420sysfs_fan_offset(3); 415sysfs_fan_offset(3);
421sysfs_fan_min_offset(3); 416sysfs_fan_min_offset(3);
422 417
423#define device_create_file_fan(client, offset) \
424do { \
425device_create_file(&client->dev, &dev_attr_fan##offset##_input); \
426device_create_file(&client->dev, &dev_attr_fan##offset##_min); \
427} while (0)
428
429#define show_temp_reg(reg) \ 418#define show_temp_reg(reg) \
430static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 419static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
431{ \ 420{ \
@@ -496,13 +485,6 @@ sysfs_temp_offsets(1);
496sysfs_temp_offsets(2); 485sysfs_temp_offsets(2);
497sysfs_temp_offsets(3); 486sysfs_temp_offsets(3);
498 487
499#define device_create_file_temp(client, offset) \
500do { \
501device_create_file(&client->dev, &dev_attr_temp##offset##_input); \
502device_create_file(&client->dev, &dev_attr_temp##offset##_max); \
503device_create_file(&client->dev, &dev_attr_temp##offset##_max_hyst); \
504} while (0)
505
506static ssize_t 488static ssize_t
507show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) 489show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
508{ 490{
@@ -510,10 +492,8 @@ show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
510 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); 492 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
511} 493}
512 494
513static 495static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
514DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 496
515#define device_create_file_vid(client) \
516device_create_file(&client->dev, &dev_attr_cpu0_vid);
517static ssize_t 497static ssize_t
518show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) 498show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
519{ 499{
@@ -534,10 +514,8 @@ store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf
534 return count; 514 return count;
535} 515}
536 516
537static 517static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
538DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); 518
539#define device_create_file_vrm(client) \
540device_create_file(&client->dev, &dev_attr_vrm);
541static ssize_t 519static ssize_t
542show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) 520show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
543{ 521{
@@ -545,10 +523,8 @@ show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
545 return sprintf(buf, "%u\n", data->alarms); 523 return sprintf(buf, "%u\n", data->alarms);
546} 524}
547 525
548static 526static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
549DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); 527
550#define device_create_file_alarms(client) \
551device_create_file(&client->dev, &dev_attr_alarms);
552static ssize_t show_beep_mask (struct device *dev, struct device_attribute *attr, char *buf) 528static ssize_t show_beep_mask (struct device *dev, struct device_attribute *attr, char *buf)
553{ 529{
554 struct w83781d_data *data = w83781d_update_device(dev); 530 struct w83781d_data *data = w83781d_update_device(dev);
@@ -614,12 +590,6 @@ static DEVICE_ATTR(beep_##reg, S_IRUGO | S_IWUSR, show_regs_beep_##reg, store_re
614sysfs_beep(ENABLE, enable); 590sysfs_beep(ENABLE, enable);
615sysfs_beep(MASK, mask); 591sysfs_beep(MASK, mask);
616 592
617#define device_create_file_beep(client) \
618do { \
619device_create_file(&client->dev, &dev_attr_beep_enable); \
620device_create_file(&client->dev, &dev_attr_beep_mask); \
621} while (0)
622
623static ssize_t 593static ssize_t
624show_fan_div_reg(struct device *dev, char *buf, int nr) 594show_fan_div_reg(struct device *dev, char *buf, int nr)
625{ 595{
@@ -685,11 +655,6 @@ sysfs_fan_div(1);
685sysfs_fan_div(2); 655sysfs_fan_div(2);
686sysfs_fan_div(3); 656sysfs_fan_div(3);
687 657
688#define device_create_file_fan_div(client, offset) \
689do { \
690device_create_file(&client->dev, &dev_attr_fan##offset##_div); \
691} while (0)
692
693static ssize_t 658static ssize_t
694show_pwm_reg(struct device *dev, char *buf, int nr) 659show_pwm_reg(struct device *dev, char *buf, int nr)
695{ 660{
@@ -786,16 +751,6 @@ sysfs_pwmenable(2); /* only PWM2 can be enabled/disabled */
786sysfs_pwm(3); 751sysfs_pwm(3);
787sysfs_pwm(4); 752sysfs_pwm(4);
788 753
789#define device_create_file_pwm(client, offset) \
790do { \
791device_create_file(&client->dev, &dev_attr_pwm##offset); \
792} while (0)
793
794#define device_create_file_pwmenable(client, offset) \
795do { \
796device_create_file(&client->dev, &dev_attr_pwm##offset##_enable); \
797} while (0)
798
799static ssize_t 754static ssize_t
800show_sensor_reg(struct device *dev, char *buf, int nr) 755show_sensor_reg(struct device *dev, char *buf, int nr)
801{ 756{
@@ -864,11 +819,6 @@ sysfs_sensor(1);
864sysfs_sensor(2); 819sysfs_sensor(2);
865sysfs_sensor(3); 820sysfs_sensor(3);
866 821
867#define device_create_file_sensor(client, offset) \
868do { \
869device_create_file(&client->dev, &dev_attr_temp##offset##_type); \
870} while (0)
871
872/* This function is called when: 822/* This function is called when:
873 * w83781d_driver is inserted (when this module is loaded), for each 823 * w83781d_driver is inserted (when this module is loaded), for each
874 available adapter 824 available adapter
@@ -993,11 +943,69 @@ ERROR_SC_0:
993 return err; 943 return err;
994} 944}
995 945
946#define IN_UNIT_ATTRS(X) \
947 &dev_attr_in##X##_input.attr, \
948 &dev_attr_in##X##_min.attr, \
949 &dev_attr_in##X##_max.attr
950
951#define FAN_UNIT_ATTRS(X) \
952 &dev_attr_fan##X##_input.attr, \
953 &dev_attr_fan##X##_min.attr, \
954 &dev_attr_fan##X##_div.attr
955
956#define TEMP_UNIT_ATTRS(X) \
957 &dev_attr_temp##X##_input.attr, \
958 &dev_attr_temp##X##_max.attr, \
959 &dev_attr_temp##X##_max_hyst.attr
960
961static struct attribute* w83781d_attributes[] = {
962 IN_UNIT_ATTRS(0),
963 IN_UNIT_ATTRS(2),
964 IN_UNIT_ATTRS(3),
965 IN_UNIT_ATTRS(4),
966 IN_UNIT_ATTRS(5),
967 IN_UNIT_ATTRS(6),
968 FAN_UNIT_ATTRS(1),
969 FAN_UNIT_ATTRS(2),
970 FAN_UNIT_ATTRS(3),
971 TEMP_UNIT_ATTRS(1),
972 TEMP_UNIT_ATTRS(2),
973 &dev_attr_cpu0_vid.attr,
974 &dev_attr_vrm.attr,
975 &dev_attr_alarms.attr,
976 &dev_attr_beep_mask.attr,
977 &dev_attr_beep_enable.attr,
978 NULL
979};
980static const struct attribute_group w83781d_group = {
981 .attrs = w83781d_attributes,
982};
983
984static struct attribute *w83781d_attributes_opt[] = {
985 IN_UNIT_ATTRS(1),
986 IN_UNIT_ATTRS(7),
987 IN_UNIT_ATTRS(8),
988 TEMP_UNIT_ATTRS(3),
989 &dev_attr_pwm1.attr,
990 &dev_attr_pwm2.attr,
991 &dev_attr_pwm2_enable.attr,
992 &dev_attr_pwm3.attr,
993 &dev_attr_pwm4.attr,
994 &dev_attr_temp1_type.attr,
995 &dev_attr_temp2_type.attr,
996 &dev_attr_temp3_type.attr,
997 NULL
998};
999static const struct attribute_group w83781d_group_opt = {
1000 .attrs = w83781d_attributes_opt,
1001};
1002
996static int 1003static int
997w83781d_detect(struct i2c_adapter *adapter, int address, int kind) 1004w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
998{ 1005{
999 int i = 0, val1 = 0, val2; 1006 int i = 0, val1 = 0, val2;
1000 struct i2c_client *new_client; 1007 struct i2c_client *client;
1008 struct device *dev;
1001 struct w83781d_data *data; 1009 struct w83781d_data *data;
1002 int err; 1010 int err;
1003 const char *client_name = ""; 1011 const char *client_name = "";
@@ -1074,13 +1082,14 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1074 goto ERROR1; 1082 goto ERROR1;
1075 } 1083 }
1076 1084
1077 new_client = &data->client; 1085 client = &data->client;
1078 i2c_set_clientdata(new_client, data); 1086 i2c_set_clientdata(client, data);
1079 new_client->addr = address; 1087 client->addr = address;
1080 mutex_init(&data->lock); 1088 mutex_init(&data->lock);
1081 new_client->adapter = adapter; 1089 client->adapter = adapter;
1082 new_client->driver = is_isa ? &w83781d_isa_driver : &w83781d_driver; 1090 client->driver = is_isa ? &w83781d_isa_driver : &w83781d_driver;
1083 new_client->flags = 0; 1091 client->flags = 0;
1092 dev = &client->dev;
1084 1093
1085 /* Now, we do the remaining detection. */ 1094 /* Now, we do the remaining detection. */
1086 1095
@@ -1089,20 +1098,18 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1089 force_*=... parameter, and the Winbond will be reset to the right 1098 force_*=... parameter, and the Winbond will be reset to the right
1090 bank. */ 1099 bank. */
1091 if (kind < 0) { 1100 if (kind < 0) {
1092 if (w83781d_read_value(new_client, W83781D_REG_CONFIG) & 0x80) { 1101 if (w83781d_read_value(client, W83781D_REG_CONFIG) & 0x80) {
1093 dev_dbg(&new_client->dev, "Detection failed at step " 1102 dev_dbg(dev, "Detection failed at step 3\n");
1094 "3\n");
1095 err = -ENODEV; 1103 err = -ENODEV;
1096 goto ERROR2; 1104 goto ERROR2;
1097 } 1105 }
1098 val1 = w83781d_read_value(new_client, W83781D_REG_BANK); 1106 val1 = w83781d_read_value(client, W83781D_REG_BANK);
1099 val2 = w83781d_read_value(new_client, W83781D_REG_CHIPMAN); 1107 val2 = w83781d_read_value(client, W83781D_REG_CHIPMAN);
1100 /* Check for Winbond or Asus ID if in bank 0 */ 1108 /* Check for Winbond or Asus ID if in bank 0 */
1101 if ((!(val1 & 0x07)) && 1109 if ((!(val1 & 0x07)) &&
1102 (((!(val1 & 0x80)) && (val2 != 0xa3) && (val2 != 0xc3)) 1110 (((!(val1 & 0x80)) && (val2 != 0xa3) && (val2 != 0xc3))
1103 || ((val1 & 0x80) && (val2 != 0x5c) && (val2 != 0x12)))) { 1111 || ((val1 & 0x80) && (val2 != 0x5c) && (val2 != 0x12)))) {
1104 dev_dbg(&new_client->dev, "Detection failed at step " 1112 dev_dbg(dev, "Detection failed at step 4\n");
1105 "4\n");
1106 err = -ENODEV; 1113 err = -ENODEV;
1107 goto ERROR2; 1114 goto ERROR2;
1108 } 1115 }
@@ -1111,9 +1118,8 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1111 if ((!is_isa) && (((!(val1 & 0x80)) && (val2 == 0xa3)) || 1118 if ((!is_isa) && (((!(val1 & 0x80)) && (val2 == 0xa3)) ||
1112 ((val1 & 0x80) && (val2 == 0x5c)))) { 1119 ((val1 & 0x80) && (val2 == 0x5c)))) {
1113 if (w83781d_read_value 1120 if (w83781d_read_value
1114 (new_client, W83781D_REG_I2C_ADDR) != address) { 1121 (client, W83781D_REG_I2C_ADDR) != address) {
1115 dev_dbg(&new_client->dev, "Detection failed " 1122 dev_dbg(dev, "Detection failed at step 5\n");
1116 "at step 5\n");
1117 err = -ENODEV; 1123 err = -ENODEV;
1118 goto ERROR2; 1124 goto ERROR2;
1119 } 1125 }
@@ -1122,27 +1128,26 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1122 1128
1123 /* We have either had a force parameter, or we have already detected the 1129 /* We have either had a force parameter, or we have already detected the
1124 Winbond. Put it now into bank 0 and Vendor ID High Byte */ 1130 Winbond. Put it now into bank 0 and Vendor ID High Byte */
1125 w83781d_write_value(new_client, W83781D_REG_BANK, 1131 w83781d_write_value(client, W83781D_REG_BANK,
1126 (w83781d_read_value(new_client, 1132 (w83781d_read_value(client, W83781D_REG_BANK)
1127 W83781D_REG_BANK) & 0x78) | 1133 & 0x78) | 0x80);
1128 0x80);
1129 1134
1130 /* Determine the chip type. */ 1135 /* Determine the chip type. */
1131 if (kind <= 0) { 1136 if (kind <= 0) {
1132 /* get vendor ID */ 1137 /* get vendor ID */
1133 val2 = w83781d_read_value(new_client, W83781D_REG_CHIPMAN); 1138 val2 = w83781d_read_value(client, W83781D_REG_CHIPMAN);
1134 if (val2 == 0x5c) 1139 if (val2 == 0x5c)
1135 vendid = winbond; 1140 vendid = winbond;
1136 else if (val2 == 0x12) 1141 else if (val2 == 0x12)
1137 vendid = asus; 1142 vendid = asus;
1138 else { 1143 else {
1139 dev_dbg(&new_client->dev, "Chip was made by neither " 1144 dev_dbg(dev, "Chip was made by neither "
1140 "Winbond nor Asus?\n"); 1145 "Winbond nor Asus?\n");
1141 err = -ENODEV; 1146 err = -ENODEV;
1142 goto ERROR2; 1147 goto ERROR2;
1143 } 1148 }
1144 1149
1145 val1 = w83781d_read_value(new_client, W83781D_REG_WCHIPID); 1150 val1 = w83781d_read_value(client, W83781D_REG_WCHIPID);
1146 if ((val1 == 0x10 || val1 == 0x11) && vendid == winbond) 1151 if ((val1 == 0x10 || val1 == 0x11) && vendid == winbond)
1147 kind = w83781d; 1152 kind = w83781d;
1148 else if (val1 == 0x30 && vendid == winbond) 1153 else if (val1 == 0x30 && vendid == winbond)
@@ -1156,7 +1161,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1156 kind = as99127f; 1161 kind = as99127f;
1157 else { 1162 else {
1158 if (kind == 0) 1163 if (kind == 0)
1159 dev_warn(&new_client->dev, "Ignoring 'force' " 1164 dev_warn(dev, "Ignoring 'force' "
1160 "parameter for unknown chip at " 1165 "parameter for unknown chip at "
1161 "adapter %d, address 0x%02x\n", 1166 "adapter %d, address 0x%02x\n",
1162 i2c_adapter_id(adapter), address); 1167 i2c_adapter_id(adapter), address);
@@ -1178,20 +1183,20 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1178 } 1183 }
1179 1184
1180 /* Fill in the remaining client fields and put into the global list */ 1185 /* Fill in the remaining client fields and put into the global list */
1181 strlcpy(new_client->name, client_name, I2C_NAME_SIZE); 1186 strlcpy(client->name, client_name, I2C_NAME_SIZE);
1182 data->type = kind; 1187 data->type = kind;
1183 1188
1184 data->valid = 0; 1189 data->valid = 0;
1185 mutex_init(&data->update_lock); 1190 mutex_init(&data->update_lock);
1186 1191
1187 /* Tell the I2C layer a new client has arrived */ 1192 /* Tell the I2C layer a new client has arrived */
1188 if ((err = i2c_attach_client(new_client))) 1193 if ((err = i2c_attach_client(client)))
1189 goto ERROR2; 1194 goto ERROR2;
1190 1195
1191 /* attach secondary i2c lm75-like clients */ 1196 /* attach secondary i2c lm75-like clients */
1192 if (!is_isa) { 1197 if (!is_isa) {
1193 if ((err = w83781d_detect_subclients(adapter, address, 1198 if ((err = w83781d_detect_subclients(adapter, address,
1194 kind, new_client))) 1199 kind, client)))
1195 goto ERROR3; 1200 goto ERROR3;
1196 } else { 1201 } else {
1197 data->lm75[0] = NULL; 1202 data->lm75[0] = NULL;
@@ -1199,11 +1204,11 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1199 } 1204 }
1200 1205
1201 /* Initialize the chip */ 1206 /* Initialize the chip */
1202 w83781d_init_client(new_client); 1207 w83781d_init_client(client);
1203 1208
1204 /* A few vars need to be filled upon startup */ 1209 /* A few vars need to be filled upon startup */
1205 for (i = 1; i <= 3; i++) { 1210 for (i = 1; i <= 3; i++) {
1206 data->fan_min[i - 1] = w83781d_read_value(new_client, 1211 data->fan_min[i - 1] = w83781d_read_value(client,
1207 W83781D_REG_FAN_MIN(i)); 1212 W83781D_REG_FAN_MIN(i));
1208 } 1213 }
1209 if (kind != w83781d && kind != as99127f) 1214 if (kind != w83781d && kind != as99127f)
@@ -1211,65 +1216,68 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1211 data->pwmenable[i] = 1; 1216 data->pwmenable[i] = 1;
1212 1217
1213 /* Register sysfs hooks */ 1218 /* Register sysfs hooks */
1214 data->class_dev = hwmon_device_register(&new_client->dev); 1219 if ((err = sysfs_create_group(&dev->kobj, &w83781d_group)))
1215 if (IS_ERR(data->class_dev)) {
1216 err = PTR_ERR(data->class_dev);
1217 goto ERROR4; 1220 goto ERROR4;
1218 }
1219 1221
1220 device_create_file_in(new_client, 0); 1222 if (kind != w83783s) {
1221 if (kind != w83783s) 1223 if ((err = device_create_file(dev, &dev_attr_in1_input))
1222 device_create_file_in(new_client, 1); 1224 || (err = device_create_file(dev, &dev_attr_in1_min))
1223 device_create_file_in(new_client, 2); 1225 || (err = device_create_file(dev, &dev_attr_in1_max)))
1224 device_create_file_in(new_client, 3); 1226 goto ERROR4;
1225 device_create_file_in(new_client, 4); 1227 }
1226 device_create_file_in(new_client, 5);
1227 device_create_file_in(new_client, 6);
1228 if (kind != as99127f && kind != w83781d && kind != w83783s) { 1228 if (kind != as99127f && kind != w83781d && kind != w83783s) {
1229 device_create_file_in(new_client, 7); 1229 if ((err = device_create_file(dev, &dev_attr_in7_input))
1230 device_create_file_in(new_client, 8); 1230 || (err = device_create_file(dev, &dev_attr_in7_min))
1231 || (err = device_create_file(dev, &dev_attr_in7_max))
1232 || (err = device_create_file(dev, &dev_attr_in8_input))
1233 || (err = device_create_file(dev, &dev_attr_in8_min))
1234 || (err = device_create_file(dev, &dev_attr_in8_max)))
1235 goto ERROR4;
1236 }
1237 if (kind != w83783s) {
1238 if ((err = device_create_file(dev, &dev_attr_temp3_input))
1239 || (err = device_create_file(dev, &dev_attr_temp3_max))
1240 || (err = device_create_file(dev,
1241 &dev_attr_temp3_max_hyst)))
1242 goto ERROR4;
1231 } 1243 }
1232
1233 device_create_file_fan(new_client, 1);
1234 device_create_file_fan(new_client, 2);
1235 device_create_file_fan(new_client, 3);
1236
1237 device_create_file_temp(new_client, 1);
1238 device_create_file_temp(new_client, 2);
1239 if (kind != w83783s)
1240 device_create_file_temp(new_client, 3);
1241
1242 device_create_file_vid(new_client);
1243 device_create_file_vrm(new_client);
1244
1245 device_create_file_fan_div(new_client, 1);
1246 device_create_file_fan_div(new_client, 2);
1247 device_create_file_fan_div(new_client, 3);
1248
1249 device_create_file_alarms(new_client);
1250
1251 device_create_file_beep(new_client);
1252 1244
1253 if (kind != w83781d && kind != as99127f) { 1245 if (kind != w83781d && kind != as99127f) {
1254 device_create_file_pwm(new_client, 1); 1246 if ((err = device_create_file(dev, &dev_attr_pwm1))
1255 device_create_file_pwm(new_client, 2); 1247 || (err = device_create_file(dev, &dev_attr_pwm2))
1256 device_create_file_pwmenable(new_client, 2); 1248 || (err = device_create_file(dev, &dev_attr_pwm2_enable)))
1249 goto ERROR4;
1257 } 1250 }
1258 if (kind == w83782d && !is_isa) { 1251 if (kind == w83782d && !is_isa) {
1259 device_create_file_pwm(new_client, 3); 1252 if ((err = device_create_file(dev, &dev_attr_pwm3))
1260 device_create_file_pwm(new_client, 4); 1253 || (err = device_create_file(dev, &dev_attr_pwm4)))
1254 goto ERROR4;
1261 } 1255 }
1262 1256
1263 if (kind != as99127f && kind != w83781d) { 1257 if (kind != as99127f && kind != w83781d) {
1264 device_create_file_sensor(new_client, 1); 1258 if ((err = device_create_file(dev, &dev_attr_temp1_type))
1265 device_create_file_sensor(new_client, 2); 1259 || (err = device_create_file(dev,
1266 if (kind != w83783s) 1260 &dev_attr_temp2_type)))
1267 device_create_file_sensor(new_client, 3); 1261 goto ERROR4;
1262 if (kind != w83783s) {
1263 if ((err = device_create_file(dev,
1264 &dev_attr_temp3_type)))
1265 goto ERROR4;
1266 }
1267 }
1268
1269 data->class_dev = hwmon_device_register(dev);
1270 if (IS_ERR(data->class_dev)) {
1271 err = PTR_ERR(data->class_dev);
1272 goto ERROR4;
1268 } 1273 }
1269 1274
1270 return 0; 1275 return 0;
1271 1276
1272ERROR4: 1277ERROR4:
1278 sysfs_remove_group(&dev->kobj, &w83781d_group);
1279 sysfs_remove_group(&dev->kobj, &w83781d_group_opt);
1280
1273 if (data->lm75[1]) { 1281 if (data->lm75[1]) {
1274 i2c_detach_client(data->lm75[1]); 1282 i2c_detach_client(data->lm75[1]);
1275 kfree(data->lm75[1]); 1283 kfree(data->lm75[1]);
@@ -1279,7 +1287,7 @@ ERROR4:
1279 kfree(data->lm75[0]); 1287 kfree(data->lm75[0]);
1280 } 1288 }
1281ERROR3: 1289ERROR3:
1282 i2c_detach_client(new_client); 1290 i2c_detach_client(client);
1283ERROR2: 1291ERROR2:
1284 kfree(data); 1292 kfree(data);
1285ERROR1: 1293ERROR1:
@@ -1296,9 +1304,11 @@ w83781d_detach_client(struct i2c_client *client)
1296 int err; 1304 int err;
1297 1305
1298 /* main client */ 1306 /* main client */
1299 if (data) 1307 if (data) {
1300 hwmon_device_unregister(data->class_dev); 1308 hwmon_device_unregister(data->class_dev);
1301 1309 sysfs_remove_group(&client->dev.kobj, &w83781d_group);
1310 sysfs_remove_group(&client->dev.kobj, &w83781d_group_opt);
1311 }
1302 if (i2c_is_isa_client(client)) 1312 if (i2c_is_isa_client(client))
1303 release_region(client->addr, W83781D_EXTENT); 1313 release_region(client->addr, W83781D_EXTENT);
1304 1314
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
index eec43abd57fb..d965d074cd61 100644
--- a/drivers/hwmon/w83791d.c
+++ b/drivers/hwmon/w83791d.c
@@ -27,9 +27,9 @@
27 27
28 The w83791d chip appears to be part way between the 83781d and the 28 The w83791d chip appears to be part way between the 83781d and the
29 83792d. Thus, this file is derived from both the w83792d.c and 29 83792d. Thus, this file is derived from both the w83792d.c and
30 w83781d.c files, but its output is more along the lines of the 30 w83781d.c files.
31 83781d (which means there are no changes to the user-mode sensors 31
32 program which treats the 83791d as an 83781d). 32 The w83791g chip is the same as the w83791d but lead-free.
33*/ 33*/
34 34
35#include <linux/config.h> 35#include <linux/config.h>
@@ -1172,6 +1172,7 @@ static struct w83791d_data *w83791d_update_device(struct device *dev)
1172 (w83791d_read(client, W83791D_REG_BEEP_CTRL[1]) << 8) + 1172 (w83791d_read(client, W83791D_REG_BEEP_CTRL[1]) << 8) +
1173 (w83791d_read(client, W83791D_REG_BEEP_CTRL[2]) << 16); 1173 (w83791d_read(client, W83791D_REG_BEEP_CTRL[2]) << 16);
1174 1174
1175 /* Extract global beep enable flag */
1175 data->beep_enable = 1176 data->beep_enable =
1176 (data->beep_mask >> GLOBAL_BEEP_ENABLE_SHIFT) & 0x01; 1177 (data->beep_mask >> GLOBAL_BEEP_ENABLE_SHIFT) & 0x01;
1177 1178
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c
index 7576ec9426a3..4e108262576f 100644
--- a/drivers/hwmon/w83792d.c
+++ b/drivers/hwmon/w83792d.c
@@ -43,6 +43,7 @@
43#include <linux/hwmon-sysfs.h> 43#include <linux/hwmon-sysfs.h>
44#include <linux/err.h> 44#include <linux/err.h>
45#include <linux/mutex.h> 45#include <linux/mutex.h>
46#include <linux/sysfs.h>
46 47
47/* Addresses to scan */ 48/* Addresses to scan */
48static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END }; 49static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
@@ -381,41 +382,6 @@ static ssize_t store_in_##reg (struct device *dev, \
381store_in_reg(MIN, min); 382store_in_reg(MIN, min);
382store_in_reg(MAX, max); 383store_in_reg(MAX, max);
383 384
384static struct sensor_device_attribute sda_in_input[] = {
385 SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0),
386 SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1),
387 SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2),
388 SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3),
389 SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4),
390 SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5),
391 SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6),
392 SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7),
393 SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8),
394};
395static struct sensor_device_attribute sda_in_min[] = {
396 SENSOR_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 0),
397 SENSOR_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 1),
398 SENSOR_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 2),
399 SENSOR_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 3),
400 SENSOR_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 4),
401 SENSOR_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 5),
402 SENSOR_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 6),
403 SENSOR_ATTR(in7_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 7),
404 SENSOR_ATTR(in8_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 8),
405};
406static struct sensor_device_attribute sda_in_max[] = {
407 SENSOR_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 0),
408 SENSOR_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 1),
409 SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 2),
410 SENSOR_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 3),
411 SENSOR_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 4),
412 SENSOR_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 5),
413 SENSOR_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 6),
414 SENSOR_ATTR(in7_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 7),
415 SENSOR_ATTR(in8_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 8),
416};
417
418
419#define show_fan_reg(reg) \ 385#define show_fan_reg(reg) \
420static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \ 386static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \
421 char *buf) \ 387 char *buf) \
@@ -499,35 +465,6 @@ store_fan_div(struct device *dev, struct device_attribute *attr,
499 return count; 465 return count;
500} 466}
501 467
502static struct sensor_device_attribute sda_fan_input[] = {
503 SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 1),
504 SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 2),
505 SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 3),
506 SENSOR_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 4),
507 SENSOR_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 5),
508 SENSOR_ATTR(fan6_input, S_IRUGO, show_fan, NULL, 6),
509 SENSOR_ATTR(fan7_input, S_IRUGO, show_fan, NULL, 7),
510};
511static struct sensor_device_attribute sda_fan_min[] = {
512 SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 1),
513 SENSOR_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 2),
514 SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 3),
515 SENSOR_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 4),
516 SENSOR_ATTR(fan5_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 5),
517 SENSOR_ATTR(fan6_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 6),
518 SENSOR_ATTR(fan7_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 7),
519};
520static struct sensor_device_attribute sda_fan_div[] = {
521 SENSOR_ATTR(fan1_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 1),
522 SENSOR_ATTR(fan2_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 2),
523 SENSOR_ATTR(fan3_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 3),
524 SENSOR_ATTR(fan4_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 4),
525 SENSOR_ATTR(fan5_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 5),
526 SENSOR_ATTR(fan6_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 6),
527 SENSOR_ATTR(fan7_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 7),
528};
529
530
531/* read/write the temperature1, includes measured value and limits */ 468/* read/write the temperature1, includes measured value and limits */
532 469
533static ssize_t show_temp1(struct device *dev, struct device_attribute *attr, 470static ssize_t show_temp1(struct device *dev, struct device_attribute *attr,
@@ -595,24 +532,6 @@ static ssize_t store_temp23(struct device *dev, struct device_attribute *attr,
595 return count; 532 return count;
596} 533}
597 534
598static struct sensor_device_attribute_2 sda_temp_input[] = {
599 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp1, NULL, 0, 0),
600 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp23, NULL, 0, 0),
601 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp23, NULL, 1, 0),
602};
603
604static struct sensor_device_attribute_2 sda_temp_max[] = {
605 SENSOR_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp1, store_temp1, 0, 1),
606 SENSOR_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp23, store_temp23, 0, 2),
607 SENSOR_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp23, store_temp23, 1, 2),
608};
609
610static struct sensor_device_attribute_2 sda_temp_max_hyst[] = {
611 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp1, store_temp1, 0, 2),
612 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO | S_IWUSR, show_temp23, store_temp23, 0, 4),
613 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp23, store_temp23, 1, 4),
614};
615
616/* get reatime status of all sensors items: voltage, temp, fan */ 535/* get reatime status of all sensors items: voltage, temp, fan */
617static ssize_t 536static ssize_t
618show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) 537show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
@@ -621,9 +540,6 @@ show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
621 return sprintf(buf, "%d\n", data->alarms); 540 return sprintf(buf, "%d\n", data->alarms);
622} 541}
623 542
624static
625DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
626
627static ssize_t 543static ssize_t
628show_pwm(struct device *dev, struct device_attribute *attr, 544show_pwm(struct device *dev, struct device_attribute *attr,
629 char *buf) 545 char *buf)
@@ -715,21 +631,6 @@ store_pwmenable(struct device *dev, struct device_attribute *attr,
715 return count; 631 return count;
716} 632}
717 633
718static struct sensor_device_attribute sda_pwm[] = {
719 SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0),
720 SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1),
721 SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2),
722};
723static struct sensor_device_attribute sda_pwm_enable[] = {
724 SENSOR_ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
725 show_pwmenable, store_pwmenable, 1),
726 SENSOR_ATTR(pwm2_enable, S_IWUSR | S_IRUGO,
727 show_pwmenable, store_pwmenable, 2),
728 SENSOR_ATTR(pwm3_enable, S_IWUSR | S_IRUGO,
729 show_pwmenable, store_pwmenable, 3),
730};
731
732
733static ssize_t 634static ssize_t
734show_pwm_mode(struct device *dev, struct device_attribute *attr, 635show_pwm_mode(struct device *dev, struct device_attribute *attr,
735 char *buf) 636 char *buf)
@@ -767,16 +668,6 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr,
767 return count; 668 return count;
768} 669}
769 670
770static struct sensor_device_attribute sda_pwm_mode[] = {
771 SENSOR_ATTR(pwm1_mode, S_IWUSR | S_IRUGO,
772 show_pwm_mode, store_pwm_mode, 0),
773 SENSOR_ATTR(pwm2_mode, S_IWUSR | S_IRUGO,
774 show_pwm_mode, store_pwm_mode, 1),
775 SENSOR_ATTR(pwm3_mode, S_IWUSR | S_IRUGO,
776 show_pwm_mode, store_pwm_mode, 2),
777};
778
779
780static ssize_t 671static ssize_t
781show_regs_chassis(struct device *dev, struct device_attribute *attr, 672show_regs_chassis(struct device *dev, struct device_attribute *attr,
782 char *buf) 673 char *buf)
@@ -785,8 +676,6 @@ show_regs_chassis(struct device *dev, struct device_attribute *attr,
785 return sprintf(buf, "%d\n", data->chassis); 676 return sprintf(buf, "%d\n", data->chassis);
786} 677}
787 678
788static DEVICE_ATTR(chassis, S_IRUGO, show_regs_chassis, NULL);
789
790static ssize_t 679static ssize_t
791show_chassis_clear(struct device *dev, struct device_attribute *attr, char *buf) 680show_chassis_clear(struct device *dev, struct device_attribute *attr, char *buf)
792{ 681{
@@ -815,9 +704,6 @@ store_chassis_clear(struct device *dev, struct device_attribute *attr,
815 return count; 704 return count;
816} 705}
817 706
818static DEVICE_ATTR(chassis_clear, S_IRUGO | S_IWUSR,
819 show_chassis_clear, store_chassis_clear);
820
821/* For Smart Fan I / Thermal Cruise */ 707/* For Smart Fan I / Thermal Cruise */
822static ssize_t 708static ssize_t
823show_thermal_cruise(struct device *dev, struct device_attribute *attr, 709show_thermal_cruise(struct device *dev, struct device_attribute *attr,
@@ -853,15 +739,6 @@ store_thermal_cruise(struct device *dev, struct device_attribute *attr,
853 return count; 739 return count;
854} 740}
855 741
856static struct sensor_device_attribute sda_thermal_cruise[] = {
857 SENSOR_ATTR(thermal_cruise1, S_IWUSR | S_IRUGO,
858 show_thermal_cruise, store_thermal_cruise, 1),
859 SENSOR_ATTR(thermal_cruise2, S_IWUSR | S_IRUGO,
860 show_thermal_cruise, store_thermal_cruise, 2),
861 SENSOR_ATTR(thermal_cruise3, S_IWUSR | S_IRUGO,
862 show_thermal_cruise, store_thermal_cruise, 3),
863};
864
865/* For Smart Fan I/Thermal Cruise and Smart Fan II */ 742/* For Smart Fan I/Thermal Cruise and Smart Fan II */
866static ssize_t 743static ssize_t
867show_tolerance(struct device *dev, struct device_attribute *attr, 744show_tolerance(struct device *dev, struct device_attribute *attr,
@@ -901,15 +778,6 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
901 return count; 778 return count;
902} 779}
903 780
904static struct sensor_device_attribute sda_tolerance[] = {
905 SENSOR_ATTR(tolerance1, S_IWUSR | S_IRUGO,
906 show_tolerance, store_tolerance, 1),
907 SENSOR_ATTR(tolerance2, S_IWUSR | S_IRUGO,
908 show_tolerance, store_tolerance, 2),
909 SENSOR_ATTR(tolerance3, S_IWUSR | S_IRUGO,
910 show_tolerance, store_tolerance, 3),
911};
912
913/* For Smart Fan II */ 781/* For Smart Fan II */
914static ssize_t 782static ssize_t
915show_sf2_point(struct device *dev, struct device_attribute *attr, 783show_sf2_point(struct device *dev, struct device_attribute *attr,
@@ -946,36 +814,6 @@ store_sf2_point(struct device *dev, struct device_attribute *attr,
946 return count; 814 return count;
947} 815}
948 816
949static struct sensor_device_attribute_2 sda_sf2_point[] = {
950 SENSOR_ATTR_2(sf2_point1_fan1, S_IRUGO | S_IWUSR,
951 show_sf2_point, store_sf2_point, 1, 1),
952 SENSOR_ATTR_2(sf2_point2_fan1, S_IRUGO | S_IWUSR,
953 show_sf2_point, store_sf2_point, 2, 1),
954 SENSOR_ATTR_2(sf2_point3_fan1, S_IRUGO | S_IWUSR,
955 show_sf2_point, store_sf2_point, 3, 1),
956 SENSOR_ATTR_2(sf2_point4_fan1, S_IRUGO | S_IWUSR,
957 show_sf2_point, store_sf2_point, 4, 1),
958
959 SENSOR_ATTR_2(sf2_point1_fan2, S_IRUGO | S_IWUSR,
960 show_sf2_point, store_sf2_point, 1, 2),
961 SENSOR_ATTR_2(sf2_point2_fan2, S_IRUGO | S_IWUSR,
962 show_sf2_point, store_sf2_point, 2, 2),
963 SENSOR_ATTR_2(sf2_point3_fan2, S_IRUGO | S_IWUSR,
964 show_sf2_point, store_sf2_point, 3, 2),
965 SENSOR_ATTR_2(sf2_point4_fan2, S_IRUGO | S_IWUSR,
966 show_sf2_point, store_sf2_point, 4, 2),
967
968 SENSOR_ATTR_2(sf2_point1_fan3, S_IRUGO | S_IWUSR,
969 show_sf2_point, store_sf2_point, 1, 3),
970 SENSOR_ATTR_2(sf2_point2_fan3, S_IRUGO | S_IWUSR,
971 show_sf2_point, store_sf2_point, 2, 3),
972 SENSOR_ATTR_2(sf2_point3_fan3, S_IRUGO | S_IWUSR,
973 show_sf2_point, store_sf2_point, 3, 3),
974 SENSOR_ATTR_2(sf2_point4_fan3, S_IRUGO | S_IWUSR,
975 show_sf2_point, store_sf2_point, 4, 3),
976};
977
978
979static ssize_t 817static ssize_t
980show_sf2_level(struct device *dev, struct device_attribute *attr, 818show_sf2_level(struct device *dev, struct device_attribute *attr,
981 char *buf) 819 char *buf)
@@ -1016,29 +854,6 @@ store_sf2_level(struct device *dev, struct device_attribute *attr,
1016 return count; 854 return count;
1017} 855}
1018 856
1019static struct sensor_device_attribute_2 sda_sf2_level[] = {
1020 SENSOR_ATTR_2(sf2_level1_fan1, S_IRUGO | S_IWUSR,
1021 show_sf2_level, store_sf2_level, 1, 1),
1022 SENSOR_ATTR_2(sf2_level2_fan1, S_IRUGO | S_IWUSR,
1023 show_sf2_level, store_sf2_level, 2, 1),
1024 SENSOR_ATTR_2(sf2_level3_fan1, S_IRUGO | S_IWUSR,
1025 show_sf2_level, store_sf2_level, 3, 1),
1026
1027 SENSOR_ATTR_2(sf2_level1_fan2, S_IRUGO | S_IWUSR,
1028 show_sf2_level, store_sf2_level, 1, 2),
1029 SENSOR_ATTR_2(sf2_level2_fan2, S_IRUGO | S_IWUSR,
1030 show_sf2_level, store_sf2_level, 2, 2),
1031 SENSOR_ATTR_2(sf2_level3_fan2, S_IRUGO | S_IWUSR,
1032 show_sf2_level, store_sf2_level, 3, 2),
1033
1034 SENSOR_ATTR_2(sf2_level1_fan3, S_IRUGO | S_IWUSR,
1035 show_sf2_level, store_sf2_level, 1, 3),
1036 SENSOR_ATTR_2(sf2_level2_fan3, S_IRUGO | S_IWUSR,
1037 show_sf2_level, store_sf2_level, 2, 3),
1038 SENSOR_ATTR_2(sf2_level3_fan3, S_IRUGO | S_IWUSR,
1039 show_sf2_level, store_sf2_level, 3, 3),
1040};
1041
1042/* This function is called when: 857/* This function is called when:
1043 * w83792d_driver is inserted (when this module is loaded), for each 858 * w83792d_driver is inserted (when this module is loaded), for each
1044 available adapter 859 available adapter
@@ -1139,12 +954,297 @@ ERROR_SC_0:
1139 return err; 954 return err;
1140} 955}
1141 956
1142static void device_create_file_fan(struct device *dev, int i) 957static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in, NULL, 0);
1143{ 958static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 1);
1144 device_create_file(dev, &sda_fan_input[i].dev_attr); 959static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in, NULL, 2);
1145 device_create_file(dev, &sda_fan_div[i].dev_attr); 960static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in, NULL, 3);
1146 device_create_file(dev, &sda_fan_min[i].dev_attr); 961static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in, NULL, 4);
1147} 962static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in, NULL, 5);
963static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in, NULL, 6);
964static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_in, NULL, 7);
965static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_in, NULL, 8);
966static SENSOR_DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO,
967 show_in_min, store_in_min, 0);
968static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO,
969 show_in_min, store_in_min, 1);
970static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO,
971 show_in_min, store_in_min, 2);
972static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO,
973 show_in_min, store_in_min, 3);
974static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO,
975 show_in_min, store_in_min, 4);
976static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO,
977 show_in_min, store_in_min, 5);
978static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO,
979 show_in_min, store_in_min, 6);
980static SENSOR_DEVICE_ATTR(in7_min, S_IWUSR | S_IRUGO,
981 show_in_min, store_in_min, 7);
982static SENSOR_DEVICE_ATTR(in8_min, S_IWUSR | S_IRUGO,
983 show_in_min, store_in_min, 8);
984static SENSOR_DEVICE_ATTR(in0_max, S_IWUSR | S_IRUGO,
985 show_in_max, store_in_max, 0);
986static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO,
987 show_in_max, store_in_max, 1);
988static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO,
989 show_in_max, store_in_max, 2);
990static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO,
991 show_in_max, store_in_max, 3);
992static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO,
993 show_in_max, store_in_max, 4);
994static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO,
995 show_in_max, store_in_max, 5);
996static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO,
997 show_in_max, store_in_max, 6);
998static SENSOR_DEVICE_ATTR(in7_max, S_IWUSR | S_IRUGO,
999 show_in_max, store_in_max, 7);
1000static SENSOR_DEVICE_ATTR(in8_max, S_IWUSR | S_IRUGO,
1001 show_in_max, store_in_max, 8);
1002static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp1, NULL, 0, 0);
1003static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp23, NULL, 0, 0);
1004static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp23, NULL, 1, 0);
1005static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR,
1006 show_temp1, store_temp1, 0, 1);
1007static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp23,
1008 store_temp23, 0, 2);
1009static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp23,
1010 store_temp23, 1, 2);
1011static SENSOR_DEVICE_ATTR_2(temp1_max_hyst, S_IRUGO | S_IWUSR,
1012 show_temp1, store_temp1, 0, 2);
1013static SENSOR_DEVICE_ATTR_2(temp2_max_hyst, S_IRUGO | S_IWUSR,
1014 show_temp23, store_temp23, 0, 4);
1015static SENSOR_DEVICE_ATTR_2(temp3_max_hyst, S_IRUGO | S_IWUSR,
1016 show_temp23, store_temp23, 1, 4);
1017static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
1018static DEVICE_ATTR(chassis, S_IRUGO, show_regs_chassis, NULL);
1019static DEVICE_ATTR(chassis_clear, S_IRUGO | S_IWUSR,
1020 show_chassis_clear, store_chassis_clear);
1021static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0);
1022static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1);
1023static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2);
1024static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
1025 show_pwmenable, store_pwmenable, 1);
1026static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO,
1027 show_pwmenable, store_pwmenable, 2);
1028static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO,
1029 show_pwmenable, store_pwmenable, 3);
1030static SENSOR_DEVICE_ATTR(pwm1_mode, S_IWUSR | S_IRUGO,
1031 show_pwm_mode, store_pwm_mode, 0);
1032static SENSOR_DEVICE_ATTR(pwm2_mode, S_IWUSR | S_IRUGO,
1033 show_pwm_mode, store_pwm_mode, 1);
1034static SENSOR_DEVICE_ATTR(pwm3_mode, S_IWUSR | S_IRUGO,
1035 show_pwm_mode, store_pwm_mode, 2);
1036static SENSOR_DEVICE_ATTR(tolerance1, S_IWUSR | S_IRUGO,
1037 show_tolerance, store_tolerance, 1);
1038static SENSOR_DEVICE_ATTR(tolerance2, S_IWUSR | S_IRUGO,
1039 show_tolerance, store_tolerance, 2);
1040static SENSOR_DEVICE_ATTR(tolerance3, S_IWUSR | S_IRUGO,
1041 show_tolerance, store_tolerance, 3);
1042static SENSOR_DEVICE_ATTR(thermal_cruise1, S_IWUSR | S_IRUGO,
1043 show_thermal_cruise, store_thermal_cruise, 1);
1044static SENSOR_DEVICE_ATTR(thermal_cruise2, S_IWUSR | S_IRUGO,
1045 show_thermal_cruise, store_thermal_cruise, 2);
1046static SENSOR_DEVICE_ATTR(thermal_cruise3, S_IWUSR | S_IRUGO,
1047 show_thermal_cruise, store_thermal_cruise, 3);
1048static SENSOR_DEVICE_ATTR_2(sf2_point1_fan1, S_IRUGO | S_IWUSR,
1049 show_sf2_point, store_sf2_point, 1, 1);
1050static SENSOR_DEVICE_ATTR_2(sf2_point2_fan1, S_IRUGO | S_IWUSR,
1051 show_sf2_point, store_sf2_point, 2, 1);
1052static SENSOR_DEVICE_ATTR_2(sf2_point3_fan1, S_IRUGO | S_IWUSR,
1053 show_sf2_point, store_sf2_point, 3, 1);
1054static SENSOR_DEVICE_ATTR_2(sf2_point4_fan1, S_IRUGO | S_IWUSR,
1055 show_sf2_point, store_sf2_point, 4, 1);
1056static SENSOR_DEVICE_ATTR_2(sf2_point1_fan2, S_IRUGO | S_IWUSR,
1057 show_sf2_point, store_sf2_point, 1, 2);
1058static SENSOR_DEVICE_ATTR_2(sf2_point2_fan2, S_IRUGO | S_IWUSR,
1059 show_sf2_point, store_sf2_point, 2, 2);
1060static SENSOR_DEVICE_ATTR_2(sf2_point3_fan2, S_IRUGO | S_IWUSR,
1061 show_sf2_point, store_sf2_point, 3, 2);
1062static SENSOR_DEVICE_ATTR_2(sf2_point4_fan2, S_IRUGO | S_IWUSR,
1063 show_sf2_point, store_sf2_point, 4, 2);
1064static SENSOR_DEVICE_ATTR_2(sf2_point1_fan3, S_IRUGO | S_IWUSR,
1065 show_sf2_point, store_sf2_point, 1, 3);
1066static SENSOR_DEVICE_ATTR_2(sf2_point2_fan3, S_IRUGO | S_IWUSR,
1067 show_sf2_point, store_sf2_point, 2, 3);
1068static SENSOR_DEVICE_ATTR_2(sf2_point3_fan3, S_IRUGO | S_IWUSR,
1069 show_sf2_point, store_sf2_point, 3, 3);
1070static SENSOR_DEVICE_ATTR_2(sf2_point4_fan3, S_IRUGO | S_IWUSR,
1071 show_sf2_point, store_sf2_point, 4, 3);
1072static SENSOR_DEVICE_ATTR_2(sf2_level1_fan1, S_IRUGO | S_IWUSR,
1073 show_sf2_level, store_sf2_level, 1, 1);
1074static SENSOR_DEVICE_ATTR_2(sf2_level2_fan1, S_IRUGO | S_IWUSR,
1075 show_sf2_level, store_sf2_level, 2, 1);
1076static SENSOR_DEVICE_ATTR_2(sf2_level3_fan1, S_IRUGO | S_IWUSR,
1077 show_sf2_level, store_sf2_level, 3, 1);
1078static SENSOR_DEVICE_ATTR_2(sf2_level1_fan2, S_IRUGO | S_IWUSR,
1079 show_sf2_level, store_sf2_level, 1, 2);
1080static SENSOR_DEVICE_ATTR_2(sf2_level2_fan2, S_IRUGO | S_IWUSR,
1081 show_sf2_level, store_sf2_level, 2, 2);
1082static SENSOR_DEVICE_ATTR_2(sf2_level3_fan2, S_IRUGO | S_IWUSR,
1083 show_sf2_level, store_sf2_level, 3, 2);
1084static SENSOR_DEVICE_ATTR_2(sf2_level1_fan3, S_IRUGO | S_IWUSR,
1085 show_sf2_level, store_sf2_level, 1, 3);
1086static SENSOR_DEVICE_ATTR_2(sf2_level2_fan3, S_IRUGO | S_IWUSR,
1087 show_sf2_level, store_sf2_level, 2, 3);
1088static SENSOR_DEVICE_ATTR_2(sf2_level3_fan3, S_IRUGO | S_IWUSR,
1089 show_sf2_level, store_sf2_level, 3, 3);
1090static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 1);
1091static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 2);
1092static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 3);
1093static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 4);
1094static SENSOR_DEVICE_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 5);
1095static SENSOR_DEVICE_ATTR(fan6_input, S_IRUGO, show_fan, NULL, 6);
1096static SENSOR_DEVICE_ATTR(fan7_input, S_IRUGO, show_fan, NULL, 7);
1097static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO,
1098 show_fan_min, store_fan_min, 1);
1099static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO,
1100 show_fan_min, store_fan_min, 2);
1101static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO,
1102 show_fan_min, store_fan_min, 3);
1103static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO,
1104 show_fan_min, store_fan_min, 4);
1105static SENSOR_DEVICE_ATTR(fan5_min, S_IWUSR | S_IRUGO,
1106 show_fan_min, store_fan_min, 5);
1107static SENSOR_DEVICE_ATTR(fan6_min, S_IWUSR | S_IRUGO,
1108 show_fan_min, store_fan_min, 6);
1109static SENSOR_DEVICE_ATTR(fan7_min, S_IWUSR | S_IRUGO,
1110 show_fan_min, store_fan_min, 7);
1111static SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO,
1112 show_fan_div, store_fan_div, 1);
1113static SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO,
1114 show_fan_div, store_fan_div, 2);
1115static SENSOR_DEVICE_ATTR(fan3_div, S_IWUSR | S_IRUGO,
1116 show_fan_div, store_fan_div, 3);
1117static SENSOR_DEVICE_ATTR(fan4_div, S_IWUSR | S_IRUGO,
1118 show_fan_div, store_fan_div, 4);
1119static SENSOR_DEVICE_ATTR(fan5_div, S_IWUSR | S_IRUGO,
1120 show_fan_div, store_fan_div, 5);
1121static SENSOR_DEVICE_ATTR(fan6_div, S_IWUSR | S_IRUGO,
1122 show_fan_div, store_fan_div, 6);
1123static SENSOR_DEVICE_ATTR(fan7_div, S_IWUSR | S_IRUGO,
1124 show_fan_div, store_fan_div, 7);
1125
1126static struct attribute *w83792d_attributes_fan[4][4] = {
1127 {
1128 &sensor_dev_attr_fan4_input.dev_attr.attr,
1129 &sensor_dev_attr_fan4_min.dev_attr.attr,
1130 &sensor_dev_attr_fan4_div.dev_attr.attr,
1131 NULL
1132 }, {
1133 &sensor_dev_attr_fan5_input.dev_attr.attr,
1134 &sensor_dev_attr_fan5_min.dev_attr.attr,
1135 &sensor_dev_attr_fan5_div.dev_attr.attr,
1136 NULL
1137 }, {
1138 &sensor_dev_attr_fan6_input.dev_attr.attr,
1139 &sensor_dev_attr_fan6_min.dev_attr.attr,
1140 &sensor_dev_attr_fan6_div.dev_attr.attr,
1141 NULL
1142 }, {
1143 &sensor_dev_attr_fan7_input.dev_attr.attr,
1144 &sensor_dev_attr_fan7_min.dev_attr.attr,
1145 &sensor_dev_attr_fan7_div.dev_attr.attr,
1146 NULL
1147 }
1148};
1149
1150static const struct attribute_group w83792d_group_fan[4] = {
1151 { .attrs = w83792d_attributes_fan[0] },
1152 { .attrs = w83792d_attributes_fan[1] },
1153 { .attrs = w83792d_attributes_fan[2] },
1154 { .attrs = w83792d_attributes_fan[3] },
1155};
1156
1157static struct attribute *w83792d_attributes[] = {
1158 &sensor_dev_attr_in0_input.dev_attr.attr,
1159 &sensor_dev_attr_in0_max.dev_attr.attr,
1160 &sensor_dev_attr_in0_min.dev_attr.attr,
1161 &sensor_dev_attr_in1_input.dev_attr.attr,
1162 &sensor_dev_attr_in1_max.dev_attr.attr,
1163 &sensor_dev_attr_in1_min.dev_attr.attr,
1164 &sensor_dev_attr_in2_input.dev_attr.attr,
1165 &sensor_dev_attr_in2_max.dev_attr.attr,
1166 &sensor_dev_attr_in2_min.dev_attr.attr,
1167 &sensor_dev_attr_in3_input.dev_attr.attr,
1168 &sensor_dev_attr_in3_max.dev_attr.attr,
1169 &sensor_dev_attr_in3_min.dev_attr.attr,
1170 &sensor_dev_attr_in4_input.dev_attr.attr,
1171 &sensor_dev_attr_in4_max.dev_attr.attr,
1172 &sensor_dev_attr_in4_min.dev_attr.attr,
1173 &sensor_dev_attr_in5_input.dev_attr.attr,
1174 &sensor_dev_attr_in5_max.dev_attr.attr,
1175 &sensor_dev_attr_in5_min.dev_attr.attr,
1176 &sensor_dev_attr_in6_input.dev_attr.attr,
1177 &sensor_dev_attr_in6_max.dev_attr.attr,
1178 &sensor_dev_attr_in6_min.dev_attr.attr,
1179 &sensor_dev_attr_in7_input.dev_attr.attr,
1180 &sensor_dev_attr_in7_max.dev_attr.attr,
1181 &sensor_dev_attr_in7_min.dev_attr.attr,
1182 &sensor_dev_attr_in8_input.dev_attr.attr,
1183 &sensor_dev_attr_in8_max.dev_attr.attr,
1184 &sensor_dev_attr_in8_min.dev_attr.attr,
1185 &sensor_dev_attr_temp1_input.dev_attr.attr,
1186 &sensor_dev_attr_temp1_max.dev_attr.attr,
1187 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
1188 &sensor_dev_attr_temp2_input.dev_attr.attr,
1189 &sensor_dev_attr_temp2_max.dev_attr.attr,
1190 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
1191 &sensor_dev_attr_temp3_input.dev_attr.attr,
1192 &sensor_dev_attr_temp3_max.dev_attr.attr,
1193 &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
1194 &sensor_dev_attr_pwm1.dev_attr.attr,
1195 &sensor_dev_attr_pwm1_mode.dev_attr.attr,
1196 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1197 &sensor_dev_attr_pwm2.dev_attr.attr,
1198 &sensor_dev_attr_pwm2_mode.dev_attr.attr,
1199 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1200 &sensor_dev_attr_pwm3.dev_attr.attr,
1201 &sensor_dev_attr_pwm3_mode.dev_attr.attr,
1202 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1203 &dev_attr_alarms.attr,
1204 &dev_attr_chassis.attr,
1205 &dev_attr_chassis_clear.attr,
1206 &sensor_dev_attr_tolerance1.dev_attr.attr,
1207 &sensor_dev_attr_thermal_cruise1.dev_attr.attr,
1208 &sensor_dev_attr_tolerance2.dev_attr.attr,
1209 &sensor_dev_attr_thermal_cruise2.dev_attr.attr,
1210 &sensor_dev_attr_tolerance3.dev_attr.attr,
1211 &sensor_dev_attr_thermal_cruise3.dev_attr.attr,
1212 &sensor_dev_attr_sf2_point1_fan1.dev_attr.attr,
1213 &sensor_dev_attr_sf2_point2_fan1.dev_attr.attr,
1214 &sensor_dev_attr_sf2_point3_fan1.dev_attr.attr,
1215 &sensor_dev_attr_sf2_point4_fan1.dev_attr.attr,
1216 &sensor_dev_attr_sf2_point1_fan2.dev_attr.attr,
1217 &sensor_dev_attr_sf2_point2_fan2.dev_attr.attr,
1218 &sensor_dev_attr_sf2_point3_fan2.dev_attr.attr,
1219 &sensor_dev_attr_sf2_point4_fan2.dev_attr.attr,
1220 &sensor_dev_attr_sf2_point1_fan3.dev_attr.attr,
1221 &sensor_dev_attr_sf2_point2_fan3.dev_attr.attr,
1222 &sensor_dev_attr_sf2_point3_fan3.dev_attr.attr,
1223 &sensor_dev_attr_sf2_point4_fan3.dev_attr.attr,
1224 &sensor_dev_attr_sf2_level1_fan1.dev_attr.attr,
1225 &sensor_dev_attr_sf2_level2_fan1.dev_attr.attr,
1226 &sensor_dev_attr_sf2_level3_fan1.dev_attr.attr,
1227 &sensor_dev_attr_sf2_level1_fan2.dev_attr.attr,
1228 &sensor_dev_attr_sf2_level2_fan2.dev_attr.attr,
1229 &sensor_dev_attr_sf2_level3_fan2.dev_attr.attr,
1230 &sensor_dev_attr_sf2_level1_fan3.dev_attr.attr,
1231 &sensor_dev_attr_sf2_level2_fan3.dev_attr.attr,
1232 &sensor_dev_attr_sf2_level3_fan3.dev_attr.attr,
1233 &sensor_dev_attr_fan1_input.dev_attr.attr,
1234 &sensor_dev_attr_fan1_min.dev_attr.attr,
1235 &sensor_dev_attr_fan1_div.dev_attr.attr,
1236 &sensor_dev_attr_fan2_input.dev_attr.attr,
1237 &sensor_dev_attr_fan2_min.dev_attr.attr,
1238 &sensor_dev_attr_fan2_div.dev_attr.attr,
1239 &sensor_dev_attr_fan3_input.dev_attr.attr,
1240 &sensor_dev_attr_fan3_min.dev_attr.attr,
1241 &sensor_dev_attr_fan3_div.dev_attr.attr,
1242 NULL
1243};
1244
1245static const struct attribute_group w83792d_group = {
1246 .attrs = w83792d_attributes,
1247};
1148 1248
1149static int 1249static int
1150w83792d_detect(struct i2c_adapter *adapter, int address, int kind) 1250w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
@@ -1268,59 +1368,46 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
1268 } 1368 }
1269 1369
1270 /* Register sysfs hooks */ 1370 /* Register sysfs hooks */
1271 data->class_dev = hwmon_device_register(dev); 1371 if ((err = sysfs_create_group(&dev->kobj, &w83792d_group)))
1272 if (IS_ERR(data->class_dev)) {
1273 err = PTR_ERR(data->class_dev);
1274 goto ERROR3; 1372 goto ERROR3;
1275 }
1276 for (i = 0; i < 9; i++) {
1277 device_create_file(dev, &sda_in_input[i].dev_attr);
1278 device_create_file(dev, &sda_in_max[i].dev_attr);
1279 device_create_file(dev, &sda_in_min[i].dev_attr);
1280 }
1281 for (i = 0; i < 3; i++)
1282 device_create_file_fan(dev, i);
1283 1373
1284 /* Read GPIO enable register to check if pins for fan 4,5 are used as 1374 /* Read GPIO enable register to check if pins for fan 4,5 are used as
1285 GPIO */ 1375 GPIO */
1286 val1 = w83792d_read_value(client, W83792D_REG_GPIO_EN); 1376 val1 = w83792d_read_value(client, W83792D_REG_GPIO_EN);
1377
1287 if (!(val1 & 0x40)) 1378 if (!(val1 & 0x40))
1288 device_create_file_fan(dev, 3); 1379 if ((err = sysfs_create_group(&dev->kobj,
1380 &w83792d_group_fan[0])))
1381 goto exit_remove_files;
1382
1289 if (!(val1 & 0x20)) 1383 if (!(val1 & 0x20))
1290 device_create_file_fan(dev, 4); 1384 if ((err = sysfs_create_group(&dev->kobj,
1385 &w83792d_group_fan[1])))
1386 goto exit_remove_files;
1291 1387
1292 val1 = w83792d_read_value(client, W83792D_REG_PIN); 1388 val1 = w83792d_read_value(client, W83792D_REG_PIN);
1293 if (val1 & 0x40) 1389 if (val1 & 0x40)
1294 device_create_file_fan(dev, 5); 1390 if ((err = sysfs_create_group(&dev->kobj,
1391 &w83792d_group_fan[2])))
1392 goto exit_remove_files;
1393
1295 if (val1 & 0x04) 1394 if (val1 & 0x04)
1296 device_create_file_fan(dev, 6); 1395 if ((err = sysfs_create_group(&dev->kobj,
1297 1396 &w83792d_group_fan[3])))
1298 for (i = 0; i < 3; i++) { 1397 goto exit_remove_files;
1299 device_create_file(dev, &sda_temp_input[i].dev_attr);
1300 device_create_file(dev, &sda_temp_max[i].dev_attr);
1301 device_create_file(dev, &sda_temp_max_hyst[i].dev_attr);
1302 device_create_file(dev, &sda_thermal_cruise[i].dev_attr);
1303 device_create_file(dev, &sda_tolerance[i].dev_attr);
1304 }
1305 1398
1306 for (i = 0; i < ARRAY_SIZE(sda_pwm); i++) { 1399 data->class_dev = hwmon_device_register(dev);
1307 device_create_file(dev, &sda_pwm[i].dev_attr); 1400 if (IS_ERR(data->class_dev)) {
1308 device_create_file(dev, &sda_pwm_enable[i].dev_attr); 1401 err = PTR_ERR(data->class_dev);
1309 device_create_file(dev, &sda_pwm_mode[i].dev_attr); 1402 goto exit_remove_files;
1310 } 1403 }
1311 1404
1312 device_create_file(dev, &dev_attr_alarms);
1313 device_create_file(dev, &dev_attr_chassis);
1314 device_create_file(dev, &dev_attr_chassis_clear);
1315
1316 for (i = 0; i < ARRAY_SIZE(sda_sf2_point); i++)
1317 device_create_file(dev, &sda_sf2_point[i].dev_attr);
1318
1319 for (i = 0; i < ARRAY_SIZE(sda_sf2_level); i++)
1320 device_create_file(dev, &sda_sf2_level[i].dev_attr);
1321
1322 return 0; 1405 return 0;
1323 1406
1407exit_remove_files:
1408 sysfs_remove_group(&dev->kobj, &w83792d_group);
1409 for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++)
1410 sysfs_remove_group(&dev->kobj, &w83792d_group_fan[i]);
1324ERROR3: 1411ERROR3:
1325 if (data->lm75[0] != NULL) { 1412 if (data->lm75[0] != NULL) {
1326 i2c_detach_client(data->lm75[0]); 1413 i2c_detach_client(data->lm75[0]);
@@ -1342,11 +1429,16 @@ static int
1342w83792d_detach_client(struct i2c_client *client) 1429w83792d_detach_client(struct i2c_client *client)
1343{ 1430{
1344 struct w83792d_data *data = i2c_get_clientdata(client); 1431 struct w83792d_data *data = i2c_get_clientdata(client);
1345 int err; 1432 int err, i;
1346 1433
1347 /* main client */ 1434 /* main client */
1348 if (data) 1435 if (data) {
1349 hwmon_device_unregister(data->class_dev); 1436 hwmon_device_unregister(data->class_dev);
1437 sysfs_remove_group(&client->dev.kobj, &w83792d_group);
1438 for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++)
1439 sysfs_remove_group(&client->dev.kobj,
1440 &w83792d_group_fan[i]);
1441 }
1350 1442
1351 if ((err = i2c_detach_client(client))) 1443 if ((err = i2c_detach_client(client)))
1352 return err; 1444 return err;
diff --git a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c
index 3f2bac125fb1..a3fcace412f0 100644
--- a/drivers/hwmon/w83l785ts.c
+++ b/drivers/hwmon/w83l785ts.c
@@ -236,21 +236,30 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind)
236 * Nothing yet, assume it is already started. 236 * Nothing yet, assume it is already started.
237 */ 237 */
238 238
239 err = device_create_file(&new_client->dev,
240 &sensor_dev_attr_temp1_input.dev_attr);
241 if (err)
242 goto exit_remove;
243
244 err = device_create_file(&new_client->dev,
245 &sensor_dev_attr_temp1_max.dev_attr);
246 if (err)
247 goto exit_remove;
248
239 /* Register sysfs hooks */ 249 /* Register sysfs hooks */
240 data->class_dev = hwmon_device_register(&new_client->dev); 250 data->class_dev = hwmon_device_register(&new_client->dev);
241 if (IS_ERR(data->class_dev)) { 251 if (IS_ERR(data->class_dev)) {
242 err = PTR_ERR(data->class_dev); 252 err = PTR_ERR(data->class_dev);
243 goto exit_detach; 253 goto exit_remove;
244 } 254 }
245 255
246 device_create_file(&new_client->dev,
247 &sensor_dev_attr_temp1_input.dev_attr);
248 device_create_file(&new_client->dev,
249 &sensor_dev_attr_temp1_max.dev_attr);
250
251 return 0; 256 return 0;
252 257
253exit_detach: 258exit_remove:
259 device_remove_file(&new_client->dev,
260 &sensor_dev_attr_temp1_input.dev_attr);
261 device_remove_file(&new_client->dev,
262 &sensor_dev_attr_temp1_max.dev_attr);
254 i2c_detach_client(new_client); 263 i2c_detach_client(new_client);
255exit_free: 264exit_free:
256 kfree(data); 265 kfree(data);
@@ -264,7 +273,10 @@ static int w83l785ts_detach_client(struct i2c_client *client)
264 int err; 273 int err;
265 274
266 hwmon_device_unregister(data->class_dev); 275 hwmon_device_unregister(data->class_dev);
267 276 device_remove_file(&client->dev,
277 &sensor_dev_attr_temp1_input.dev_attr);
278 device_remove_file(&client->dev,
279 &sensor_dev_attr_temp1_max.dev_attr);
268 if ((err = i2c_detach_client(client))) 280 if ((err = i2c_detach_client(client)))
269 return err; 281 return err;
270 282
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index 24383afdda76..11935f66fcd8 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -1,5 +1,5 @@
1# 1#
2# Character device configuration 2# I2C subsystem configuration
3# 3#
4 4
5menu "I2C support" 5menu "I2C support"
diff --git a/drivers/i2c/algos/Kconfig b/drivers/i2c/algos/Kconfig
index 30408015d231..c034820615bb 100644
--- a/drivers/i2c/algos/Kconfig
+++ b/drivers/i2c/algos/Kconfig
@@ -53,12 +53,6 @@ config I2C_ALGO8XX
53 tristate "MPC8xx CPM I2C interface" 53 tristate "MPC8xx CPM I2C interface"
54 depends on 8xx && I2C 54 depends on 8xx && I2C
55 55
56config I2C_ALGO_SIBYTE
57 tristate "SiByte SMBus interface"
58 depends on SIBYTE_SB1xxx_SOC && I2C
59 help
60 Supports the SiByte SOC on-chip I2C interfaces (2 channels).
61
62config I2C_ALGO_SGI 56config I2C_ALGO_SGI
63 tristate "I2C SGI interfaces" 57 tristate "I2C SGI interfaces"
64 depends on I2C && (SGI_IP22 || SGI_IP32 || X86_VISWS) 58 depends on I2C && (SGI_IP22 || SGI_IP32 || X86_VISWS)
diff --git a/drivers/i2c/algos/Makefile b/drivers/i2c/algos/Makefile
index 867fe1f67401..208be04a3dbd 100644
--- a/drivers/i2c/algos/Makefile
+++ b/drivers/i2c/algos/Makefile
@@ -6,7 +6,6 @@ obj-$(CONFIG_I2C_ALGOBIT) += i2c-algo-bit.o
6obj-$(CONFIG_I2C_ALGOPCF) += i2c-algo-pcf.o 6obj-$(CONFIG_I2C_ALGOPCF) += i2c-algo-pcf.o
7obj-$(CONFIG_I2C_ALGOPCA) += i2c-algo-pca.o 7obj-$(CONFIG_I2C_ALGOPCA) += i2c-algo-pca.o
8obj-$(CONFIG_I2C_ALGOITE) += i2c-algo-ite.o 8obj-$(CONFIG_I2C_ALGOITE) += i2c-algo-ite.o
9obj-$(CONFIG_I2C_ALGO_SIBYTE) += i2c-algo-sibyte.o
10obj-$(CONFIG_I2C_ALGO_SGI) += i2c-algo-sgi.o 9obj-$(CONFIG_I2C_ALGO_SGI) += i2c-algo-sgi.o
11 10
12ifeq ($(CONFIG_I2C_DEBUG_ALGO),y) 11ifeq ($(CONFIG_I2C_DEBUG_ALGO),y)
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index ab230c033f99..21c36bfb5e6b 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -76,17 +76,15 @@ static inline void scllo(struct i2c_algo_bit_data *adap)
76 * Raise scl line, and do checking for delays. This is necessary for slower 76 * Raise scl line, and do checking for delays. This is necessary for slower
77 * devices. 77 * devices.
78 */ 78 */
79static inline int sclhi(struct i2c_algo_bit_data *adap) 79static int sclhi(struct i2c_algo_bit_data *adap)
80{ 80{
81 unsigned long start; 81 unsigned long start;
82 82
83 setscl(adap,1); 83 setscl(adap,1);
84 84
85 /* Not all adapters have scl sense line... */ 85 /* Not all adapters have scl sense line... */
86 if (adap->getscl == NULL ) { 86 if (!adap->getscl)
87 udelay(adap->udelay); 87 goto done;
88 return 0;
89 }
90 88
91 start=jiffies; 89 start=jiffies;
92 while (! getscl(adap) ) { 90 while (! getscl(adap) ) {
@@ -101,6 +99,8 @@ static inline int sclhi(struct i2c_algo_bit_data *adap)
101 cond_resched(); 99 cond_resched();
102 } 100 }
103 DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start)); 101 DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start));
102
103done:
104 udelay(adap->udelay); 104 udelay(adap->udelay);
105 return 0; 105 return 0;
106} 106}
@@ -121,7 +121,6 @@ static void i2c_repstart(struct i2c_algo_bit_data *adap)
121 DEBPROTO(printk(" Sr ")); 121 DEBPROTO(printk(" Sr "));
122 setsda(adap,1); 122 setsda(adap,1);
123 sclhi(adap); 123 sclhi(adap);
124 udelay(adap->udelay);
125 124
126 sdalo(adap); 125 sdalo(adap);
127 scllo(adap); 126 scllo(adap);
@@ -306,7 +305,7 @@ bailout:
306 * 0 chip did not answer 305 * 0 chip did not answer
307 * -x transmission error 306 * -x transmission error
308 */ 307 */
309static inline int try_address(struct i2c_adapter *i2c_adap, 308static int try_address(struct i2c_adapter *i2c_adap,
310 unsigned char addr, int retries) 309 unsigned char addr, int retries)
311{ 310{
312 struct i2c_algo_bit_data *adap = i2c_adap->algo_data; 311 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
@@ -354,15 +353,11 @@ static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
354 return (retval<0)? retval : -EFAULT; 353 return (retval<0)? retval : -EFAULT;
355 /* got a better one ?? */ 354 /* got a better one ?? */
356 } 355 }
357#if 0
358 /* from asm/delay.h */
359 __delay(adap->mdelay * (loops_per_sec / 1000) );
360#endif
361 } 356 }
362 return wrcount; 357 return wrcount;
363} 358}
364 359
365static inline int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) 360static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
366{ 361{
367 int inval; 362 int inval;
368 int rdcount=0; /* counts bytes read */ 363 int rdcount=0; /* counts bytes read */
@@ -412,7 +407,7 @@ static inline int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
412 * -x an error occurred (like: -EREMOTEIO if the device did not answer, or 407 * -x an error occurred (like: -EREMOTEIO if the device did not answer, or
413 * -ETIMEDOUT, for example if the lines are stuck...) 408 * -ETIMEDOUT, for example if the lines are stuck...)
414 */ 409 */
415static inline int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) 410static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
416{ 411{
417 unsigned short flags = msg->flags; 412 unsigned short flags = msg->flags;
418 unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK; 413 unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK;
@@ -517,7 +512,7 @@ static u32 bit_func(struct i2c_adapter *adap)
517 512
518/* -----exported algorithm data: ------------------------------------- */ 513/* -----exported algorithm data: ------------------------------------- */
519 514
520static struct i2c_algorithm i2c_bit_algo = { 515static const struct i2c_algorithm i2c_bit_algo = {
521 .master_xfer = bit_xfer, 516 .master_xfer = bit_xfer,
522 .functionality = bit_func, 517 .functionality = bit_func,
523}; 518};
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c
index b88a6fcf7bd0..9081c9fbcd29 100644
--- a/drivers/i2c/algos/i2c-algo-pca.c
+++ b/drivers/i2c/algos/i2c-algo-pca.c
@@ -355,7 +355,7 @@ static int pca_init(struct i2c_algo_pca_data *adap)
355 return 0; 355 return 0;
356} 356}
357 357
358static struct i2c_algorithm pca_algo = { 358static const struct i2c_algorithm pca_algo = {
359 .master_xfer = pca_xfer, 359 .master_xfer = pca_xfer,
360 .functionality = pca_func, 360 .functionality = pca_func,
361}; 361};
diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c
index 5b24930adb5a..3b2003398966 100644
--- a/drivers/i2c/algos/i2c-algo-pcf.c
+++ b/drivers/i2c/algos/i2c-algo-pcf.c
@@ -458,7 +458,7 @@ static u32 pcf_func(struct i2c_adapter *adap)
458 458
459/* -----exported algorithm data: ------------------------------------- */ 459/* -----exported algorithm data: ------------------------------------- */
460 460
461static struct i2c_algorithm pcf_algo = { 461static const struct i2c_algorithm pcf_algo = {
462 .master_xfer = pcf_xfer, 462 .master_xfer = pcf_xfer,
463 .functionality = pcf_func, 463 .functionality = pcf_func,
464}; 464};
diff --git a/drivers/i2c/algos/i2c-algo-sgi.c b/drivers/i2c/algos/i2c-algo-sgi.c
index 932c4fa86c73..490d99997fd0 100644
--- a/drivers/i2c/algos/i2c-algo-sgi.c
+++ b/drivers/i2c/algos/i2c-algo-sgi.c
@@ -157,7 +157,7 @@ static u32 sgi_func(struct i2c_adapter *adap)
157 return I2C_FUNC_SMBUS_EMUL; 157 return I2C_FUNC_SMBUS_EMUL;
158} 158}
159 159
160static struct i2c_algorithm sgi_algo = { 160static const struct i2c_algorithm sgi_algo = {
161 .master_xfer = sgi_xfer, 161 .master_xfer = sgi_xfer,
162 .functionality = sgi_func, 162 .functionality = sgi_func,
163}; 163};
diff --git a/drivers/i2c/algos/i2c-algo-sibyte.c b/drivers/i2c/algos/i2c-algo-sibyte.c
deleted file mode 100644
index 32d41c6fac0f..000000000000
--- a/drivers/i2c/algos/i2c-algo-sibyte.c
+++ /dev/null
@@ -1,215 +0,0 @@
1/* ------------------------------------------------------------------------- */
2/* i2c-algo-sibyte.c i2c driver algorithms for bit-shift adapters */
3/* ------------------------------------------------------------------------- */
4/* Copyright (C) 2001,2002,2003 Broadcom Corporation
5 Copyright (C) 1995-2000 Simon G. Vogl
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/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
23 Frodo Looijaard <frodol@dds.nl>. */
24
25/* Ported for SiByte SOCs by Broadcom Corporation. */
26
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/init.h>
30
31#include <asm/io.h>
32#include <asm/sibyte/sb1250_regs.h>
33#include <asm/sibyte/sb1250_smbus.h>
34
35#include <linux/i2c.h>
36#include <linux/i2c-algo-sibyte.h>
37
38/* ----- global defines ----------------------------------------------- */
39#define SMB_CSR(a,r) ((long)(a->reg_base + r))
40
41/* ----- global variables --------------------------------------------- */
42
43/* module parameters:
44 */
45static int bit_scan; /* have a look at what's hanging 'round */
46
47
48static int smbus_xfer(struct i2c_adapter *i2c_adap, u16 addr,
49 unsigned short flags, char read_write,
50 u8 command, int size, union i2c_smbus_data * data)
51{
52 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
53 int data_bytes = 0;
54 int error;
55
56 while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY)
57 ;
58
59 switch (size) {
60 case I2C_SMBUS_QUICK:
61 csr_out32((V_SMB_ADDR(addr) | (read_write == I2C_SMBUS_READ ? M_SMB_QDATA : 0) |
62 V_SMB_TT_QUICKCMD), SMB_CSR(adap, R_SMB_START));
63 break;
64 case I2C_SMBUS_BYTE:
65 if (read_write == I2C_SMBUS_READ) {
66 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_RD1BYTE),
67 SMB_CSR(adap, R_SMB_START));
68 data_bytes = 1;
69 } else {
70 csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
71 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR1BYTE),
72 SMB_CSR(adap, R_SMB_START));
73 }
74 break;
75 case I2C_SMBUS_BYTE_DATA:
76 csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
77 if (read_write == I2C_SMBUS_READ) {
78 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD1BYTE),
79 SMB_CSR(adap, R_SMB_START));
80 data_bytes = 1;
81 } else {
82 csr_out32(V_SMB_LB(data->byte), SMB_CSR(adap, R_SMB_DATA));
83 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE),
84 SMB_CSR(adap, R_SMB_START));
85 }
86 break;
87 case I2C_SMBUS_WORD_DATA:
88 csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
89 if (read_write == I2C_SMBUS_READ) {
90 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD2BYTE),
91 SMB_CSR(adap, R_SMB_START));
92 data_bytes = 2;
93 } else {
94 csr_out32(V_SMB_LB(data->word & 0xff), SMB_CSR(adap, R_SMB_DATA));
95 csr_out32(V_SMB_MB(data->word >> 8), SMB_CSR(adap, R_SMB_DATA));
96 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE),
97 SMB_CSR(adap, R_SMB_START));
98 }
99 break;
100 default:
101 return -1; /* XXXKW better error code? */
102 }
103
104 while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY)
105 ;
106
107 error = csr_in32(SMB_CSR(adap, R_SMB_STATUS));
108 if (error & M_SMB_ERROR) {
109 /* Clear error bit by writing a 1 */
110 csr_out32(M_SMB_ERROR, SMB_CSR(adap, R_SMB_STATUS));
111 return -1; /* XXXKW better error code? */
112 }
113
114 if (data_bytes == 1)
115 data->byte = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xff;
116 if (data_bytes == 2)
117 data->word = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xffff;
118
119 return 0;
120}
121
122static int algo_control(struct i2c_adapter *adapter,
123 unsigned int cmd, unsigned long arg)
124{
125 return 0;
126}
127
128static u32 bit_func(struct i2c_adapter *adap)
129{
130 return (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
131 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA);
132}
133
134
135/* -----exported algorithm data: ------------------------------------- */
136
137static struct i2c_algorithm i2c_sibyte_algo = {
138 .smbus_xfer = smbus_xfer,
139 .algo_control = algo_control, /* ioctl */
140 .functionality = bit_func,
141};
142
143/*
144 * registering functions to load algorithms at runtime
145 */
146int i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed)
147{
148 int i;
149 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
150
151 /* register new adapter to i2c module... */
152 i2c_adap->algo = &i2c_sibyte_algo;
153
154 /* Set the frequency to 100 kHz */
155 csr_out32(speed, SMB_CSR(adap,R_SMB_FREQ));
156 csr_out32(0, SMB_CSR(adap,R_SMB_CONTROL));
157
158 /* scan bus */
159 if (bit_scan) {
160 union i2c_smbus_data data;
161 int rc;
162 printk(KERN_INFO " i2c-algo-sibyte.o: scanning bus %s.\n",
163 i2c_adap->name);
164 for (i = 0x00; i < 0x7f; i++) {
165 /* XXXKW is this a realistic probe? */
166 rc = smbus_xfer(i2c_adap, i, 0, I2C_SMBUS_READ, 0,
167 I2C_SMBUS_BYTE_DATA, &data);
168 if (!rc) {
169 printk("(%02x)",i);
170 } else
171 printk(".");
172 }
173 printk("\n");
174 }
175
176 return i2c_add_adapter(i2c_adap);
177}
178
179
180int i2c_sibyte_del_bus(struct i2c_adapter *adap)
181{
182 int res;
183
184 if ((res = i2c_del_adapter(adap)) < 0)
185 return res;
186
187 return 0;
188}
189
190int __init i2c_algo_sibyte_init (void)
191{
192 printk("i2c-algo-sibyte.o: i2c SiByte algorithm module\n");
193 return 0;
194}
195
196
197EXPORT_SYMBOL(i2c_sibyte_add_bus);
198EXPORT_SYMBOL(i2c_sibyte_del_bus);
199
200#ifdef MODULE
201MODULE_AUTHOR("Kip Walker, Broadcom Corp.");
202MODULE_DESCRIPTION("SiByte I2C-Bus algorithm");
203module_param(bit_scan, int, 0);
204MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus");
205MODULE_LICENSE("GPL");
206
207int init_module(void)
208{
209 return i2c_algo_sibyte_init();
210}
211
212void cleanup_module(void)
213{
214}
215#endif
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 884320e70403..0d9667921f61 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -75,11 +75,11 @@ config I2C_AMD8111
75 will be called i2c-amd8111. 75 will be called i2c-amd8111.
76 76
77config I2C_AU1550 77config I2C_AU1550
78 tristate "Au1550 SMBus interface" 78 tristate "Au1550/Au1200 SMBus interface"
79 depends on I2C && SOC_AU1550 79 depends on I2C && (SOC_AU1550 || SOC_AU1200)
80 help 80 help
81 If you say yes to this option, support will be included for the 81 If you say yes to this option, support will be included for the
82 Au1550 SMBus interface. 82 Au1550 and Au1200 SMBus interface.
83 83
84 This driver can also be built as a module. If so, the module 84 This driver can also be built as a module. If so, the module
85 will be called i2c-au1550. 85 will be called i2c-au1550.
@@ -196,7 +196,7 @@ config I2C_IBM_IIC
196 196
197config I2C_IOP3XX 197config I2C_IOP3XX
198 tristate "Intel IOP3xx and IXP4xx on-chip I2C interface" 198 tristate "Intel IOP3xx and IXP4xx on-chip I2C interface"
199 depends on (ARCH_IOP3XX || ARCH_IXP4XX) && I2C 199 depends on (ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX) && I2C
200 help 200 help
201 Say Y here if you want to use the IIC bus controller on 201 Say Y here if you want to use the IIC bus controller on
202 the Intel IOP3xx I/O Processors or IXP4xx Network Processors. 202 the Intel IOP3xx I/O Processors or IXP4xx Network Processors.
@@ -287,6 +287,16 @@ config I2C_OCORES
287 This driver can also be built as a module. If so, the module 287 This driver can also be built as a module. If so, the module
288 will be called i2c-ocores. 288 will be called i2c-ocores.
289 289
290config I2C_OMAP
291 tristate "OMAP I2C adapter"
292 depends on I2C && ARCH_OMAP
293 default y if MACH_OMAP_H3 || MACH_OMAP_OSK
294 help
295 If you say yes to this option, support will be included for the
296 I2C interface on the Texas Instruments OMAP1/2 family of processors.
297 Like OMAP1510/1610/1710/5912 and OMAP242x.
298 For details see http://www.ti.com/omap.
299
290config I2C_PARPORT 300config I2C_PARPORT
291 tristate "Parallel port adapter" 301 tristate "Parallel port adapter"
292 depends on I2C && PARPORT 302 depends on I2C && PARPORT
@@ -482,19 +492,19 @@ config I2C_VIA
482 will be called i2c-via. 492 will be called i2c-via.
483 493
484config I2C_VIAPRO 494config I2C_VIAPRO
485 tristate "VIA 82C596/82C686/823x" 495 tristate "VIA 82C596/82C686/82xx"
486 depends on I2C && PCI 496 depends on I2C && PCI
487 help 497 help
488 If you say yes to this option, support will be included for the VIA 498 If you say yes to this option, support will be included for the VIA
489 82C596/82C686/823x I2C interfaces. Specifically, the following 499 82C596/82C686/82xx I2C interfaces. Specifically, the following
490 chipsets are supported: 500 chipsets are supported:
491 82C596A/B 501 VT82C596A/B
492 82C686A/B 502 VT82C686A/B
493 8231 503 VT8231
494 8233 504 VT8233/A
495 8233A 505 VT8235
496 8235 506 VT8237R/A
497 8237 507 VT8251
498 508
499 This driver can also be built as a module. If so, the module 509 This driver can also be built as a module. If so, the module
500 will be called i2c-viapro. 510 will be called i2c-viapro.
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index ac56df53155b..493c87289b62 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_I2C_MPC) += i2c-mpc.o
24obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o 24obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o
25obj-$(CONFIG_I2C_NFORCE2) += i2c-nforce2.o 25obj-$(CONFIG_I2C_NFORCE2) += i2c-nforce2.o
26obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o 26obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o
27obj-$(CONFIG_I2C_OMAP) += i2c-omap.o
27obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o 28obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o
28obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o 29obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o
29obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o 30obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index d3ef46aeeb3c..e75d339a3481 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -468,7 +468,7 @@ static u32 ali1535_func(struct i2c_adapter *adapter)
468 I2C_FUNC_SMBUS_BLOCK_DATA; 468 I2C_FUNC_SMBUS_BLOCK_DATA;
469} 469}
470 470
471static struct i2c_algorithm smbus_algorithm = { 471static const struct i2c_algorithm smbus_algorithm = {
472 .smbus_xfer = ali1535_access, 472 .smbus_xfer = ali1535_access,
473 .functionality = ali1535_func, 473 .functionality = ali1535_func,
474}; 474};
diff --git a/drivers/i2c/busses/i2c-ali1563.c b/drivers/i2c/busses/i2c-ali1563.c
index e6f63208fc4a..33fbb47100a3 100644
--- a/drivers/i2c/busses/i2c-ali1563.c
+++ b/drivers/i2c/busses/i2c-ali1563.c
@@ -367,7 +367,7 @@ static void ali1563_shutdown(struct pci_dev *dev)
367 release_region(ali1563_smba,ALI1563_SMB_IOSIZE); 367 release_region(ali1563_smba,ALI1563_SMB_IOSIZE);
368} 368}
369 369
370static struct i2c_algorithm ali1563_algorithm = { 370static const struct i2c_algorithm ali1563_algorithm = {
371 .smbus_xfer = ali1563_access, 371 .smbus_xfer = ali1563_access,
372 .functionality = ali1563_func, 372 .functionality = ali1563_func,
373}; 373};
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index 7a5c0941dbc1..3f11b6e1a341 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -463,7 +463,7 @@ static u32 ali15x3_func(struct i2c_adapter *adapter)
463 I2C_FUNC_SMBUS_BLOCK_DATA; 463 I2C_FUNC_SMBUS_BLOCK_DATA;
464} 464}
465 465
466static struct i2c_algorithm smbus_algorithm = { 466static const struct i2c_algorithm smbus_algorithm = {
467 .smbus_xfer = ali15x3_access, 467 .smbus_xfer = ali15x3_access,
468 .functionality = ali15x3_func, 468 .functionality = ali15x3_func,
469}; 469};
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index 1750dedaf4b5..2d21afdc5b1c 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -294,7 +294,7 @@ static u32 amd756_func(struct i2c_adapter *adapter)
294 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL; 294 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL;
295} 295}
296 296
297static struct i2c_algorithm smbus_algorithm = { 297static const struct i2c_algorithm smbus_algorithm = {
298 .smbus_xfer = amd756_access, 298 .smbus_xfer = amd756_access,
299 .functionality = amd756_func, 299 .functionality = amd756_func,
300}; 300};
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c
index e5ef560e686a..0fbc7186c91a 100644
--- a/drivers/i2c/busses/i2c-amd8111.c
+++ b/drivers/i2c/busses/i2c-amd8111.c
@@ -316,7 +316,7 @@ static u32 amd8111_func(struct i2c_adapter *adapter)
316 I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_HWPEC_CALC; 316 I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_HWPEC_CALC;
317} 317}
318 318
319static struct i2c_algorithm smbus_algorithm = { 319static const struct i2c_algorithm smbus_algorithm = {
320 .smbus_xfer = amd8111_access, 320 .smbus_xfer = amd8111_access,
321 .functionality = amd8111_func, 321 .functionality = amd8111_func,
322}; 322};
diff --git a/drivers/i2c/busses/i2c-au1550.c b/drivers/i2c/busses/i2c-au1550.c
index d06edce03bf4..d7e7c359fc36 100644
--- a/drivers/i2c/busses/i2c-au1550.c
+++ b/drivers/i2c/busses/i2c-au1550.c
@@ -34,8 +34,7 @@
34#include <linux/errno.h> 34#include <linux/errno.h>
35#include <linux/i2c.h> 35#include <linux/i2c.h>
36 36
37#include <asm/mach-au1x00/au1000.h> 37#include <asm/mach-au1x00/au1xxx.h>
38#include <asm/mach-pb1x00/pb1550.h>
39#include <asm/mach-au1x00/au1xxx_psc.h> 38#include <asm/mach-au1x00/au1xxx_psc.h>
40 39
41#include "i2c-au1550.h" 40#include "i2c-au1550.h"
@@ -118,13 +117,19 @@ do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd)
118 117
119 /* Reset the FIFOs, clear events. 118 /* Reset the FIFOs, clear events.
120 */ 119 */
121 sp->psc_smbpcr = PSC_SMBPCR_DC; 120 stat = sp->psc_smbstat;
122 sp->psc_smbevnt = PSC_SMBEVNT_ALLCLR; 121 sp->psc_smbevnt = PSC_SMBEVNT_ALLCLR;
123 au_sync(); 122 au_sync();
124 do { 123
125 stat = sp->psc_smbpcr; 124 if (!(stat & PSC_SMBSTAT_TE) || !(stat & PSC_SMBSTAT_RE)) {
125 sp->psc_smbpcr = PSC_SMBPCR_DC;
126 au_sync(); 126 au_sync();
127 } while ((stat & PSC_SMBPCR_DC) != 0); 127 do {
128 stat = sp->psc_smbpcr;
129 au_sync();
130 } while ((stat & PSC_SMBPCR_DC) != 0);
131 udelay(50);
132 }
128 133
129 /* Write out the i2c chip address and specify operation 134 /* Write out the i2c chip address and specify operation
130 */ 135 */
@@ -279,10 +284,10 @@ au1550_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
279static u32 284static u32
280au1550_func(struct i2c_adapter *adap) 285au1550_func(struct i2c_adapter *adap)
281{ 286{
282 return I2C_FUNC_I2C; 287 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
283} 288}
284 289
285static struct i2c_algorithm au1550_algo = { 290static const struct i2c_algorithm au1550_algo = {
286 .master_xfer = au1550_xfer, 291 .master_xfer = au1550_xfer,
287 .functionality = au1550_func, 292 .functionality = au1550_func,
288}; 293};
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c
index 59f8308c2356..caa8e5c8bfbb 100644
--- a/drivers/i2c/busses/i2c-elektor.c
+++ b/drivers/i2c/busses/i2c-elektor.c
@@ -196,7 +196,6 @@ static struct i2c_algo_pcf_data pcf_isa_data = {
196 .getclock = pcf_isa_getclock, 196 .getclock = pcf_isa_getclock,
197 .waitforpin = pcf_isa_waitforpin, 197 .waitforpin = pcf_isa_waitforpin,
198 .udelay = 10, 198 .udelay = 10,
199 .mdelay = 10,
200 .timeout = 100, 199 .timeout = 100,
201}; 200};
202 201
diff --git a/drivers/i2c/busses/i2c-hydra.c b/drivers/i2c/busses/i2c-hydra.c
index e0cb3b0f92fa..457d48a0ab9d 100644
--- a/drivers/i2c/busses/i2c-hydra.c
+++ b/drivers/i2c/busses/i2c-hydra.c
@@ -99,7 +99,6 @@ static struct i2c_algo_bit_data hydra_bit_data = {
99 .getsda = hydra_bit_getsda, 99 .getsda = hydra_bit_getsda,
100 .getscl = hydra_bit_getscl, 100 .getscl = hydra_bit_getscl,
101 .udelay = 5, 101 .udelay = 5,
102 .mdelay = 5,
103 .timeout = HZ 102 .timeout = HZ
104}; 103};
105 104
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 7be1d0a3e8f8..bbb2fbee836f 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -434,7 +434,7 @@ static u32 i801_func(struct i2c_adapter *adapter)
434 | (isich4 ? I2C_FUNC_SMBUS_HWPEC_CALC : 0); 434 | (isich4 ? I2C_FUNC_SMBUS_HWPEC_CALC : 0);
435} 435}
436 436
437static struct i2c_algorithm smbus_algorithm = { 437static const struct i2c_algorithm smbus_algorithm = {
438 .smbus_xfer = i801_access, 438 .smbus_xfer = i801_access,
439 .functionality = i801_func, 439 .functionality = i801_func,
440}; 440};
diff --git a/drivers/i2c/busses/i2c-i810.c b/drivers/i2c/busses/i2c-i810.c
index 748be30f2bae..b66fb6bb1870 100644
--- a/drivers/i2c/busses/i2c-i810.c
+++ b/drivers/i2c/busses/i2c-i810.c
@@ -166,7 +166,6 @@ static struct i2c_algo_bit_data i810_i2c_bit_data = {
166 .getsda = bit_i810i2c_getsda, 166 .getsda = bit_i810i2c_getsda,
167 .getscl = bit_i810i2c_getscl, 167 .getscl = bit_i810i2c_getscl,
168 .udelay = CYCLE_DELAY, 168 .udelay = CYCLE_DELAY,
169 .mdelay = CYCLE_DELAY,
170 .timeout = TIMEOUT, 169 .timeout = TIMEOUT,
171}; 170};
172 171
@@ -182,7 +181,6 @@ static struct i2c_algo_bit_data i810_ddc_bit_data = {
182 .getsda = bit_i810ddc_getsda, 181 .getsda = bit_i810ddc_getsda,
183 .getscl = bit_i810ddc_getscl, 182 .getscl = bit_i810ddc_getscl,
184 .udelay = CYCLE_DELAY, 183 .udelay = CYCLE_DELAY,
185 .mdelay = CYCLE_DELAY,
186 .timeout = TIMEOUT, 184 .timeout = TIMEOUT,
187}; 185};
188 186
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index 0599bbd65d93..5bccb5d68318 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -625,7 +625,7 @@ static u32 iic_func(struct i2c_adapter *adap)
625 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR; 625 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR;
626} 626}
627 627
628static struct i2c_algorithm iic_algo = { 628static const struct i2c_algorithm iic_algo = {
629 .master_xfer = iic_xfer, 629 .master_xfer = iic_xfer,
630 .functionality = iic_func 630 .functionality = iic_func
631}; 631};
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index 48c56939c861..4436c89be58e 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -82,14 +82,16 @@ iop3xx_i2c_enable(struct i2c_algo_iop3xx_data *iop3xx_adap)
82 82
83 /* 83 /*
84 * Every time unit enable is asserted, GPOD needs to be cleared 84 * Every time unit enable is asserted, GPOD needs to be cleared
85 * on IOP321 to avoid data corruption on the bus. 85 * on IOP3XX to avoid data corruption on the bus.
86 */ 86 */
87#ifdef CONFIG_ARCH_IOP321 87#ifdef CONFIG_PLAT_IOP
88#define IOP321_GPOD_I2C0 0x00c0 /* clear these bits to enable ch0 */ 88 if (iop3xx_adap->id == 0) {
89#define IOP321_GPOD_I2C1 0x0030 /* clear these bits to enable ch1 */ 89 gpio_line_set(IOP3XX_GPIO_LINE(7), GPIO_LOW);
90 90 gpio_line_set(IOP3XX_GPIO_LINE(6), GPIO_LOW);
91 *IOP321_GPOD &= (iop3xx_adap->id == 0) ? ~IOP321_GPOD_I2C0 : 91 } else {
92 ~IOP321_GPOD_I2C1; 92 gpio_line_set(IOP3XX_GPIO_LINE(5), GPIO_LOW);
93 gpio_line_set(IOP3XX_GPIO_LINE(4), GPIO_LOW);
94 }
93#endif 95#endif
94 /* NB SR bits not same position as CR IE bits :-( */ 96 /* NB SR bits not same position as CR IE bits :-( */
95 iop3xx_adap->SR_enabled = 97 iop3xx_adap->SR_enabled =
@@ -401,7 +403,7 @@ iop3xx_i2c_func(struct i2c_adapter *adap)
401 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 403 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
402} 404}
403 405
404static struct i2c_algorithm iop3xx_i2c_algo = { 406static const struct i2c_algorithm iop3xx_i2c_algo = {
405 .master_xfer = iop3xx_i2c_master_xfer, 407 .master_xfer = iop3xx_i2c_master_xfer,
406 .algo_control = iop3xx_i2c_algo_control, 408 .algo_control = iop3xx_i2c_algo_control,
407 .functionality = iop3xx_i2c_func, 409 .functionality = iop3xx_i2c_func,
diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c
index c3e1d3e888d7..4380653748a4 100644
--- a/drivers/i2c/busses/i2c-isa.c
+++ b/drivers/i2c/busses/i2c-isa.c
@@ -43,7 +43,7 @@
43static u32 isa_func(struct i2c_adapter *adapter); 43static u32 isa_func(struct i2c_adapter *adapter);
44 44
45/* This is the actual algorithm we define */ 45/* This is the actual algorithm we define */
46static struct i2c_algorithm isa_algorithm = { 46static const struct i2c_algorithm isa_algorithm = {
47 .functionality = isa_func, 47 .functionality = isa_func,
48}; 48};
49 49
@@ -89,9 +89,14 @@ int i2c_isa_add_driver(struct i2c_driver *driver)
89 dev_dbg(&isa_adapter.dev, "Driver %s registered\n", driver->driver.name); 89 dev_dbg(&isa_adapter.dev, "Driver %s registered\n", driver->driver.name);
90 90
91 /* Now look for clients */ 91 /* Now look for clients */
92 driver->attach_adapter(&isa_adapter); 92 res = driver->attach_adapter(&isa_adapter);
93 93 if (res) {
94 return 0; 94 dev_err(&isa_adapter.dev,
95 "Driver %s failed to attach adapter, unregistering\n",
96 driver->driver.name);
97 driver_unregister(&driver->driver);
98 }
99 return res;
95} 100}
96 101
97int i2c_isa_del_driver(struct i2c_driver *driver) 102int i2c_isa_del_driver(struct i2c_driver *driver)
@@ -125,6 +130,8 @@ int i2c_isa_del_driver(struct i2c_driver *driver)
125 130
126static int __init i2c_isa_init(void) 131static int __init i2c_isa_init(void)
127{ 132{
133 int err;
134
128 mutex_init(&isa_adapter.clist_lock); 135 mutex_init(&isa_adapter.clist_lock);
129 INIT_LIST_HEAD(&isa_adapter.clients); 136 INIT_LIST_HEAD(&isa_adapter.clients);
130 137
@@ -133,8 +140,16 @@ static int __init i2c_isa_init(void)
133 sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr); 140 sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr);
134 isa_adapter.dev.driver = &i2c_adapter_driver; 141 isa_adapter.dev.driver = &i2c_adapter_driver;
135 isa_adapter.dev.release = &i2c_adapter_dev_release; 142 isa_adapter.dev.release = &i2c_adapter_dev_release;
136 device_register(&isa_adapter.dev); 143 err = device_register(&isa_adapter.dev);
137 device_create_file(&isa_adapter.dev, &dev_attr_name); 144 if (err) {
145 printk(KERN_ERR "i2c-isa: Failed to register device\n");
146 goto exit;
147 }
148 err = device_create_file(&isa_adapter.dev, &dev_attr_name);
149 if (err) {
150 printk(KERN_ERR "i2c-isa: Failed to create name file\n");
151 goto exit_unregister;
152 }
138 153
139 /* Add this adapter to the i2c_adapter class */ 154 /* Add this adapter to the i2c_adapter class */
140 memset(&isa_adapter.class_dev, 0x00, sizeof(struct class_device)); 155 memset(&isa_adapter.class_dev, 0x00, sizeof(struct class_device));
@@ -142,11 +157,24 @@ static int __init i2c_isa_init(void)
142 isa_adapter.class_dev.class = &i2c_adapter_class; 157 isa_adapter.class_dev.class = &i2c_adapter_class;
143 strlcpy(isa_adapter.class_dev.class_id, isa_adapter.dev.bus_id, 158 strlcpy(isa_adapter.class_dev.class_id, isa_adapter.dev.bus_id,
144 BUS_ID_SIZE); 159 BUS_ID_SIZE);
145 class_device_register(&isa_adapter.class_dev); 160 err = class_device_register(&isa_adapter.class_dev);
161 if (err) {
162 printk(KERN_ERR "i2c-isa: Failed to register class device\n");
163 goto exit_remove_name;
164 }
146 165
147 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name); 166 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name);
148 167
149 return 0; 168 return 0;
169
170exit_remove_name:
171 device_remove_file(&isa_adapter.dev, &dev_attr_name);
172exit_unregister:
173 init_completion(&isa_adapter.dev_released); /* Needed? */
174 device_unregister(&isa_adapter.dev);
175 wait_for_completion(&isa_adapter.dev_released);
176exit:
177 return err;
150} 178}
151 179
152static void __exit i2c_isa_exit(void) 180static void __exit i2c_isa_exit(void)
diff --git a/drivers/i2c/busses/i2c-ite.c b/drivers/i2c/busses/i2c-ite.c
index d82e6dae8407..559a62b04ee9 100644
--- a/drivers/i2c/busses/i2c-ite.c
+++ b/drivers/i2c/busses/i2c-ite.c
@@ -109,7 +109,7 @@ static int iic_ite_getclock(void *data)
109static void iic_ite_waitforpin(void) { 109static void iic_ite_waitforpin(void) {
110 DEFINE_WAIT(wait); 110 DEFINE_WAIT(wait);
111 int timeout = 2; 111 int timeout = 2;
112 long flags; 112 unsigned long flags;
113 113
114 /* If interrupts are enabled (which they are), then put the process to 114 /* If interrupts are enabled (which they are), then put the process to
115 * sleep. This process will be awakened by two events -- either the 115 * sleep. This process will be awakened by two events -- either the
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c
index cd6f45d186ab..dd3f4cd3aa68 100644
--- a/drivers/i2c/busses/i2c-ixp2000.c
+++ b/drivers/i2c/busses/i2c-ixp2000.c
@@ -114,7 +114,6 @@ static int ixp2000_i2c_probe(struct platform_device *plat_dev)
114 drv_data->algo_data.getsda = ixp2000_bit_getsda; 114 drv_data->algo_data.getsda = ixp2000_bit_getsda;
115 drv_data->algo_data.getscl = ixp2000_bit_getscl; 115 drv_data->algo_data.getscl = ixp2000_bit_getscl;
116 drv_data->algo_data.udelay = 6; 116 drv_data->algo_data.udelay = 6;
117 drv_data->algo_data.mdelay = 6;
118 drv_data->algo_data.timeout = 100; 117 drv_data->algo_data.timeout = 100;
119 118
120 drv_data->adapter.id = I2C_HW_B_IXP2000, 119 drv_data->adapter.id = I2C_HW_B_IXP2000,
diff --git a/drivers/i2c/busses/i2c-ixp4xx.c b/drivers/i2c/busses/i2c-ixp4xx.c
index 2ed07112d683..ab573254a8aa 100644
--- a/drivers/i2c/busses/i2c-ixp4xx.c
+++ b/drivers/i2c/busses/i2c-ixp4xx.c
@@ -122,7 +122,6 @@ static int ixp4xx_i2c_probe(struct platform_device *plat_dev)
122 drv_data->algo_data.getsda = ixp4xx_bit_getsda; 122 drv_data->algo_data.getsda = ixp4xx_bit_getsda;
123 drv_data->algo_data.getscl = ixp4xx_bit_getscl; 123 drv_data->algo_data.getscl = ixp4xx_bit_getscl;
124 drv_data->algo_data.udelay = 10; 124 drv_data->algo_data.udelay = 10;
125 drv_data->algo_data.mdelay = 10;
126 drv_data->algo_data.timeout = 100; 125 drv_data->algo_data.timeout = 100;
127 126
128 drv_data->adapter.id = I2C_HW_B_IXP4XX; 127 drv_data->adapter.id = I2C_HW_B_IXP4XX;
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 377ab40944b8..155a986de516 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -272,7 +272,7 @@ static u32 mpc_functionality(struct i2c_adapter *adap)
272 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 272 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
273} 273}
274 274
275static struct i2c_algorithm mpc_algo = { 275static const struct i2c_algorithm mpc_algo = {
276 .master_xfer = mpc_xfer, 276 .master_xfer = mpc_xfer,
277 .functionality = mpc_functionality, 277 .functionality = mpc_functionality,
278}; 278};
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index ac5cde1bbd2b..eacbaf745b64 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -431,7 +431,7 @@ mv64xxx_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
431 return num; 431 return num;
432} 432}
433 433
434static struct i2c_algorithm mv64xxx_i2c_algo = { 434static const struct i2c_algorithm mv64xxx_i2c_algo = {
435 .master_xfer = mv64xxx_i2c_xfer, 435 .master_xfer = mv64xxx_i2c_xfer,
436 .functionality = mv64xxx_i2c_functionality, 436 .functionality = mv64xxx_i2c_functionality,
437}; 437};
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index 604b49e22df1..e0292e414ab2 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -109,7 +109,7 @@ static s32 nforce2_access(struct i2c_adapter *adap, u16 addr,
109static u32 nforce2_func(struct i2c_adapter *adapter); 109static u32 nforce2_func(struct i2c_adapter *adapter);
110 110
111 111
112static struct i2c_algorithm smbus_algorithm = { 112static const struct i2c_algorithm smbus_algorithm = {
113 .smbus_xfer = nforce2_access, 113 .smbus_xfer = nforce2_access,
114 .functionality = nforce2_func, 114 .functionality = nforce2_func,
115}; 115};
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index 592824087c49..952a28d485ce 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -199,7 +199,7 @@ static u32 ocores_func(struct i2c_adapter *adap)
199 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 199 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
200} 200}
201 201
202static struct i2c_algorithm ocores_algorithm = { 202static const struct i2c_algorithm ocores_algorithm = {
203 .master_xfer = ocores_xfer, 203 .master_xfer = ocores_xfer,
204 .functionality = ocores_func, 204 .functionality = ocores_func,
205}; 205};
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
new file mode 100644
index 000000000000..81d87d2c2a2d
--- /dev/null
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -0,0 +1,676 @@
1/*
2 * TI OMAP I2C master mode driver
3 *
4 * Copyright (C) 2003 MontaVista Software, Inc.
5 * Copyright (C) 2004 Texas Instruments.
6 *
7 * Updated to work with multiple I2C interfaces on 24xx by
8 * Tony Lindgren <tony@atomide.com> and Imre Deak <imre.deak@nokia.com>
9 * Copyright (C) 2005 Nokia Corporation
10 *
11 * Cleaned up by Juha Yrjölä <juha.yrjola@nokia.com>
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
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28#include <linux/module.h>
29#include <linux/delay.h>
30#include <linux/i2c.h>
31#include <linux/err.h>
32#include <linux/interrupt.h>
33#include <linux/completion.h>
34#include <linux/platform_device.h>
35#include <linux/clk.h>
36
37#include <asm/io.h>
38
39/* timeout waiting for the controller to respond */
40#define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000))
41
42#define OMAP_I2C_REV_REG 0x00
43#define OMAP_I2C_IE_REG 0x04
44#define OMAP_I2C_STAT_REG 0x08
45#define OMAP_I2C_IV_REG 0x0c
46#define OMAP_I2C_SYSS_REG 0x10
47#define OMAP_I2C_BUF_REG 0x14
48#define OMAP_I2C_CNT_REG 0x18
49#define OMAP_I2C_DATA_REG 0x1c
50#define OMAP_I2C_SYSC_REG 0x20
51#define OMAP_I2C_CON_REG 0x24
52#define OMAP_I2C_OA_REG 0x28
53#define OMAP_I2C_SA_REG 0x2c
54#define OMAP_I2C_PSC_REG 0x30
55#define OMAP_I2C_SCLL_REG 0x34
56#define OMAP_I2C_SCLH_REG 0x38
57#define OMAP_I2C_SYSTEST_REG 0x3c
58
59/* I2C Interrupt Enable Register (OMAP_I2C_IE): */
60#define OMAP_I2C_IE_XRDY (1 << 4) /* TX data ready int enable */
61#define OMAP_I2C_IE_RRDY (1 << 3) /* RX data ready int enable */
62#define OMAP_I2C_IE_ARDY (1 << 2) /* Access ready int enable */
63#define OMAP_I2C_IE_NACK (1 << 1) /* No ack interrupt enable */
64#define OMAP_I2C_IE_AL (1 << 0) /* Arbitration lost int ena */
65
66/* I2C Status Register (OMAP_I2C_STAT): */
67#define OMAP_I2C_STAT_SBD (1 << 15) /* Single byte data */
68#define OMAP_I2C_STAT_BB (1 << 12) /* Bus busy */
69#define OMAP_I2C_STAT_ROVR (1 << 11) /* Receive overrun */
70#define OMAP_I2C_STAT_XUDF (1 << 10) /* Transmit underflow */
71#define OMAP_I2C_STAT_AAS (1 << 9) /* Address as slave */
72#define OMAP_I2C_STAT_AD0 (1 << 8) /* Address zero */
73#define OMAP_I2C_STAT_XRDY (1 << 4) /* Transmit data ready */
74#define OMAP_I2C_STAT_RRDY (1 << 3) /* Receive data ready */
75#define OMAP_I2C_STAT_ARDY (1 << 2) /* Register access ready */
76#define OMAP_I2C_STAT_NACK (1 << 1) /* No ack interrupt enable */
77#define OMAP_I2C_STAT_AL (1 << 0) /* Arbitration lost int ena */
78
79/* I2C Buffer Configuration Register (OMAP_I2C_BUF): */
80#define OMAP_I2C_BUF_RDMA_EN (1 << 15) /* RX DMA channel enable */
81#define OMAP_I2C_BUF_XDMA_EN (1 << 7) /* TX DMA channel enable */
82
83/* I2C Configuration Register (OMAP_I2C_CON): */
84#define OMAP_I2C_CON_EN (1 << 15) /* I2C module enable */
85#define OMAP_I2C_CON_BE (1 << 14) /* Big endian mode */
86#define OMAP_I2C_CON_STB (1 << 11) /* Start byte mode (master) */
87#define OMAP_I2C_CON_MST (1 << 10) /* Master/slave mode */
88#define OMAP_I2C_CON_TRX (1 << 9) /* TX/RX mode (master only) */
89#define OMAP_I2C_CON_XA (1 << 8) /* Expand address */
90#define OMAP_I2C_CON_RM (1 << 2) /* Repeat mode (master only) */
91#define OMAP_I2C_CON_STP (1 << 1) /* Stop cond (master only) */
92#define OMAP_I2C_CON_STT (1 << 0) /* Start condition (master) */
93
94/* I2C System Test Register (OMAP_I2C_SYSTEST): */
95#ifdef DEBUG
96#define OMAP_I2C_SYSTEST_ST_EN (1 << 15) /* System test enable */
97#define OMAP_I2C_SYSTEST_FREE (1 << 14) /* Free running mode */
98#define OMAP_I2C_SYSTEST_TMODE_MASK (3 << 12) /* Test mode select */
99#define OMAP_I2C_SYSTEST_TMODE_SHIFT (12) /* Test mode select */
100#define OMAP_I2C_SYSTEST_SCL_I (1 << 3) /* SCL line sense in */
101#define OMAP_I2C_SYSTEST_SCL_O (1 << 2) /* SCL line drive out */
102#define OMAP_I2C_SYSTEST_SDA_I (1 << 1) /* SDA line sense in */
103#define OMAP_I2C_SYSTEST_SDA_O (1 << 0) /* SDA line drive out */
104#endif
105
106/* I2C System Status register (OMAP_I2C_SYSS): */
107#define OMAP_I2C_SYSS_RDONE (1 << 0) /* Reset Done */
108
109/* I2C System Configuration Register (OMAP_I2C_SYSC): */
110#define OMAP_I2C_SYSC_SRST (1 << 1) /* Soft Reset */
111
112/* REVISIT: Use platform_data instead of module parameters */
113/* Fast Mode = 400 kHz, Standard = 100 kHz */
114static int clock = 100; /* Default: 100 kHz */
115module_param(clock, int, 0);
116MODULE_PARM_DESC(clock, "Set I2C clock in kHz: 400=fast mode (default == 100)");
117
118struct omap_i2c_dev {
119 struct device *dev;
120 void __iomem *base; /* virtual */
121 int irq;
122 struct clk *iclk; /* Interface clock */
123 struct clk *fclk; /* Functional clock */
124 struct completion cmd_complete;
125 struct resource *ioarea;
126 u16 cmd_err;
127 u8 *buf;
128 size_t buf_len;
129 struct i2c_adapter adapter;
130 unsigned rev1:1;
131};
132
133static inline void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev,
134 int reg, u16 val)
135{
136 __raw_writew(val, i2c_dev->base + reg);
137}
138
139static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int reg)
140{
141 return __raw_readw(i2c_dev->base + reg);
142}
143
144static int omap_i2c_get_clocks(struct omap_i2c_dev *dev)
145{
146 if (cpu_is_omap16xx() || cpu_is_omap24xx()) {
147 dev->iclk = clk_get(dev->dev, "i2c_ick");
148 if (IS_ERR(dev->iclk)) {
149 dev->iclk = NULL;
150 return -ENODEV;
151 }
152 }
153
154 dev->fclk = clk_get(dev->dev, "i2c_fck");
155 if (IS_ERR(dev->fclk)) {
156 if (dev->iclk != NULL) {
157 clk_put(dev->iclk);
158 dev->iclk = NULL;
159 }
160 dev->fclk = NULL;
161 return -ENODEV;
162 }
163
164 return 0;
165}
166
167static void omap_i2c_put_clocks(struct omap_i2c_dev *dev)
168{
169 clk_put(dev->fclk);
170 dev->fclk = NULL;
171 if (dev->iclk != NULL) {
172 clk_put(dev->iclk);
173 dev->iclk = NULL;
174 }
175}
176
177static void omap_i2c_enable_clocks(struct omap_i2c_dev *dev)
178{
179 if (dev->iclk != NULL)
180 clk_enable(dev->iclk);
181 clk_enable(dev->fclk);
182}
183
184static void omap_i2c_disable_clocks(struct omap_i2c_dev *dev)
185{
186 if (dev->iclk != NULL)
187 clk_disable(dev->iclk);
188 clk_disable(dev->fclk);
189}
190
191static int omap_i2c_init(struct omap_i2c_dev *dev)
192{
193 u16 psc = 0;
194 unsigned long fclk_rate = 12000000;
195 unsigned long timeout;
196
197 if (!dev->rev1) {
198 omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, OMAP_I2C_SYSC_SRST);
199 /* For some reason we need to set the EN bit before the
200 * reset done bit gets set. */
201 timeout = jiffies + OMAP_I2C_TIMEOUT;
202 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
203 while (!(omap_i2c_read_reg(dev, OMAP_I2C_SYSS_REG) &
204 OMAP_I2C_SYSS_RDONE)) {
205 if (time_after(jiffies, timeout)) {
206 dev_warn(dev->dev, "timeout waiting"
207 "for controller reset\n");
208 return -ETIMEDOUT;
209 }
210 msleep(1);
211 }
212 }
213 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
214
215 if (cpu_class_is_omap1()) {
216 struct clk *armxor_ck;
217
218 armxor_ck = clk_get(NULL, "armxor_ck");
219 if (IS_ERR(armxor_ck))
220 dev_warn(dev->dev, "Could not get armxor_ck\n");
221 else {
222 fclk_rate = clk_get_rate(armxor_ck);
223 clk_put(armxor_ck);
224 }
225 /* TRM for 5912 says the I2C clock must be prescaled to be
226 * between 7 - 12 MHz. The XOR input clock is typically
227 * 12, 13 or 19.2 MHz. So we should have code that produces:
228 *
229 * XOR MHz Divider Prescaler
230 * 12 1 0
231 * 13 2 1
232 * 19.2 2 1
233 */
234 if (fclk_rate > 16000000)
235 psc = (fclk_rate + 8000000) / 12000000;
236 }
237
238 /* Setup clock prescaler to obtain approx 12MHz I2C module clock: */
239 omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, psc);
240
241 /* Program desired operating rate */
242 fclk_rate /= (psc + 1) * 1000;
243 if (psc > 2)
244 psc = 2;
245
246 omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG,
247 fclk_rate / (clock * 2) - 7 + psc);
248 omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG,
249 fclk_rate / (clock * 2) - 7 + psc);
250
251 /* Take the I2C module out of reset: */
252 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
253
254 /* Enable interrupts */
255 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG,
256 (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY |
257 OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK |
258 OMAP_I2C_IE_AL));
259 return 0;
260}
261
262/*
263 * Waiting on Bus Busy
264 */
265static int omap_i2c_wait_for_bb(struct omap_i2c_dev *dev)
266{
267 unsigned long timeout;
268
269 timeout = jiffies + OMAP_I2C_TIMEOUT;
270 while (omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG) & OMAP_I2C_STAT_BB) {
271 if (time_after(jiffies, timeout)) {
272 dev_warn(dev->dev, "timeout waiting for bus ready\n");
273 return -ETIMEDOUT;
274 }
275 msleep(1);
276 }
277
278 return 0;
279}
280
281/*
282 * Low level master read/write transaction.
283 */
284static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
285 struct i2c_msg *msg, int stop)
286{
287 struct omap_i2c_dev *dev = i2c_get_adapdata(adap);
288 int r;
289 u16 w;
290
291 dev_dbg(dev->dev, "addr: 0x%04x, len: %d, flags: 0x%x, stop: %d\n",
292 msg->addr, msg->len, msg->flags, stop);
293
294 if (msg->len == 0)
295 return -EINVAL;
296
297 omap_i2c_write_reg(dev, OMAP_I2C_SA_REG, msg->addr);
298
299 /* REVISIT: Could the STB bit of I2C_CON be used with probing? */
300 dev->buf = msg->buf;
301 dev->buf_len = msg->len;
302
303 omap_i2c_write_reg(dev, OMAP_I2C_CNT_REG, dev->buf_len);
304
305 init_completion(&dev->cmd_complete);
306 dev->cmd_err = 0;
307
308 w = OMAP_I2C_CON_EN | OMAP_I2C_CON_MST | OMAP_I2C_CON_STT;
309 if (msg->flags & I2C_M_TEN)
310 w |= OMAP_I2C_CON_XA;
311 if (!(msg->flags & I2C_M_RD))
312 w |= OMAP_I2C_CON_TRX;
313 if (stop)
314 w |= OMAP_I2C_CON_STP;
315 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w);
316
317 r = wait_for_completion_interruptible_timeout(&dev->cmd_complete,
318 OMAP_I2C_TIMEOUT);
319 dev->buf_len = 0;
320 if (r < 0)
321 return r;
322 if (r == 0) {
323 dev_err(dev->dev, "controller timed out\n");
324 omap_i2c_init(dev);
325 return -ETIMEDOUT;
326 }
327
328 if (likely(!dev->cmd_err))
329 return 0;
330
331 /* We have an error */
332 if (dev->cmd_err & (OMAP_I2C_STAT_AL | OMAP_I2C_STAT_ROVR |
333 OMAP_I2C_STAT_XUDF)) {
334 omap_i2c_init(dev);
335 return -EIO;
336 }
337
338 if (dev->cmd_err & OMAP_I2C_STAT_NACK) {
339 if (msg->flags & I2C_M_IGNORE_NAK)
340 return 0;
341 if (stop) {
342 w = omap_i2c_read_reg(dev, OMAP_I2C_CON_REG);
343 w |= OMAP_I2C_CON_STP;
344 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w);
345 }
346 return -EREMOTEIO;
347 }
348 return -EIO;
349}
350
351
352/*
353 * Prepare controller for a transaction and call omap_i2c_xfer_msg
354 * to do the work during IRQ processing.
355 */
356static int
357omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
358{
359 struct omap_i2c_dev *dev = i2c_get_adapdata(adap);
360 int i;
361 int r;
362
363 omap_i2c_enable_clocks(dev);
364
365 /* REVISIT: initialize and use adap->retries. This is an optional
366 * feature */
367 if ((r = omap_i2c_wait_for_bb(dev)) < 0)
368 goto out;
369
370 for (i = 0; i < num; i++) {
371 r = omap_i2c_xfer_msg(adap, &msgs[i], (i == (num - 1)));
372 if (r != 0)
373 break;
374 }
375
376 if (r == 0)
377 r = num;
378out:
379 omap_i2c_disable_clocks(dev);
380 return r;
381}
382
383static u32
384omap_i2c_func(struct i2c_adapter *adap)
385{
386 return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
387}
388
389static inline void
390omap_i2c_complete_cmd(struct omap_i2c_dev *dev, u16 err)
391{
392 dev->cmd_err |= err;
393 complete(&dev->cmd_complete);
394}
395
396static inline void
397omap_i2c_ack_stat(struct omap_i2c_dev *dev, u16 stat)
398{
399 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat);
400}
401
402static irqreturn_t
403omap_i2c_rev1_isr(int this_irq, void *dev_id, struct pt_regs *regs)
404{
405 struct omap_i2c_dev *dev = dev_id;
406 u16 iv, w;
407
408 iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG);
409 switch (iv) {
410 case 0x00: /* None */
411 break;
412 case 0x01: /* Arbitration lost */
413 dev_err(dev->dev, "Arbitration lost\n");
414 omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_AL);
415 break;
416 case 0x02: /* No acknowledgement */
417 omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_NACK);
418 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_STP);
419 break;
420 case 0x03: /* Register access ready */
421 omap_i2c_complete_cmd(dev, 0);
422 break;
423 case 0x04: /* Receive data ready */
424 if (dev->buf_len) {
425 w = omap_i2c_read_reg(dev, OMAP_I2C_DATA_REG);
426 *dev->buf++ = w;
427 dev->buf_len--;
428 if (dev->buf_len) {
429 *dev->buf++ = w >> 8;
430 dev->buf_len--;
431 }
432 } else
433 dev_err(dev->dev, "RRDY IRQ while no data requested\n");
434 break;
435 case 0x05: /* Transmit data ready */
436 if (dev->buf_len) {
437 w = *dev->buf++;
438 dev->buf_len--;
439 if (dev->buf_len) {
440 w |= *dev->buf++ << 8;
441 dev->buf_len--;
442 }
443 omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w);
444 } else
445 dev_err(dev->dev, "XRDY IRQ while no data to send\n");
446 break;
447 default:
448 return IRQ_NONE;
449 }
450
451 return IRQ_HANDLED;
452}
453
454static irqreturn_t
455omap_i2c_isr(int this_irq, void *dev_id, struct pt_regs *regs)
456{
457 struct omap_i2c_dev *dev = dev_id;
458 u16 bits;
459 u16 stat, w;
460 int count = 0;
461
462 bits = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG);
463 while ((stat = (omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG))) & bits) {
464 dev_dbg(dev->dev, "IRQ (ISR = 0x%04x)\n", stat);
465 if (count++ == 100) {
466 dev_warn(dev->dev, "Too much work in one IRQ\n");
467 break;
468 }
469
470 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat);
471
472 if (stat & OMAP_I2C_STAT_ARDY) {
473 omap_i2c_complete_cmd(dev, 0);
474 continue;
475 }
476 if (stat & OMAP_I2C_STAT_RRDY) {
477 w = omap_i2c_read_reg(dev, OMAP_I2C_DATA_REG);
478 if (dev->buf_len) {
479 *dev->buf++ = w;
480 dev->buf_len--;
481 if (dev->buf_len) {
482 *dev->buf++ = w >> 8;
483 dev->buf_len--;
484 }
485 } else
486 dev_err(dev->dev, "RRDY IRQ while no data"
487 "requested\n");
488 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RRDY);
489 continue;
490 }
491 if (stat & OMAP_I2C_STAT_XRDY) {
492 w = 0;
493 if (dev->buf_len) {
494 w = *dev->buf++;
495 dev->buf_len--;
496 if (dev->buf_len) {
497 w |= *dev->buf++ << 8;
498 dev->buf_len--;
499 }
500 } else
501 dev_err(dev->dev, "XRDY IRQ while no"
502 "data to send\n");
503 omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w);
504 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_XRDY);
505 continue;
506 }
507 if (stat & OMAP_I2C_STAT_ROVR) {
508 dev_err(dev->dev, "Receive overrun\n");
509 dev->cmd_err |= OMAP_I2C_STAT_ROVR;
510 }
511 if (stat & OMAP_I2C_STAT_XUDF) {
512 dev_err(dev->dev, "Transmit overflow\n");
513 dev->cmd_err |= OMAP_I2C_STAT_XUDF;
514 }
515 if (stat & OMAP_I2C_STAT_NACK) {
516 omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_NACK);
517 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG,
518 OMAP_I2C_CON_STP);
519 }
520 if (stat & OMAP_I2C_STAT_AL) {
521 dev_err(dev->dev, "Arbitration lost\n");
522 omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_AL);
523 }
524 }
525
526 return count ? IRQ_HANDLED : IRQ_NONE;
527}
528
529static const struct i2c_algorithm omap_i2c_algo = {
530 .master_xfer = omap_i2c_xfer,
531 .functionality = omap_i2c_func,
532};
533
534static int
535omap_i2c_probe(struct platform_device *pdev)
536{
537 struct omap_i2c_dev *dev;
538 struct i2c_adapter *adap;
539 struct resource *mem, *irq, *ioarea;
540 int r;
541
542 /* NOTE: driver uses the static register mapping */
543 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
544 if (!mem) {
545 dev_err(&pdev->dev, "no mem resource?\n");
546 return -ENODEV;
547 }
548 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
549 if (!irq) {
550 dev_err(&pdev->dev, "no irq resource?\n");
551 return -ENODEV;
552 }
553
554 ioarea = request_mem_region(mem->start, (mem->end - mem->start) + 1,
555 pdev->name);
556 if (!ioarea) {
557 dev_err(&pdev->dev, "I2C region already claimed\n");
558 return -EBUSY;
559 }
560
561 if (clock > 200)
562 clock = 400; /* Fast mode */
563 else
564 clock = 100; /* Standard mode */
565
566 dev = kzalloc(sizeof(struct omap_i2c_dev), GFP_KERNEL);
567 if (!dev) {
568 r = -ENOMEM;
569 goto err_release_region;
570 }
571
572 dev->dev = &pdev->dev;
573 dev->irq = irq->start;
574 dev->base = (void __iomem *) IO_ADDRESS(mem->start);
575 platform_set_drvdata(pdev, dev);
576
577 if ((r = omap_i2c_get_clocks(dev)) != 0)
578 goto err_free_mem;
579
580 omap_i2c_enable_clocks(dev);
581
582 if (cpu_is_omap15xx())
583 dev->rev1 = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) < 0x20;
584
585 /* reset ASAP, clearing any IRQs */
586 omap_i2c_init(dev);
587
588 r = request_irq(dev->irq, dev->rev1 ? omap_i2c_rev1_isr : omap_i2c_isr,
589 0, pdev->name, dev);
590
591 if (r) {
592 dev_err(dev->dev, "failure requesting irq %i\n", dev->irq);
593 goto err_unuse_clocks;
594 }
595 r = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff;
596 dev_info(dev->dev, "bus %d rev%d.%d at %d kHz\n",
597 pdev->id, r >> 4, r & 0xf, clock);
598
599 adap = &dev->adapter;
600 i2c_set_adapdata(adap, dev);
601 adap->owner = THIS_MODULE;
602 adap->class = I2C_CLASS_HWMON;
603 strncpy(adap->name, "OMAP I2C adapter", sizeof(adap->name));
604 adap->algo = &omap_i2c_algo;
605 adap->dev.parent = &pdev->dev;
606
607 /* i2c device drivers may be active on return from add_adapter() */
608 r = i2c_add_adapter(adap);
609 if (r) {
610 dev_err(dev->dev, "failure adding adapter\n");
611 goto err_free_irq;
612 }
613
614 omap_i2c_disable_clocks(dev);
615
616 return 0;
617
618err_free_irq:
619 free_irq(dev->irq, dev);
620err_unuse_clocks:
621 omap_i2c_disable_clocks(dev);
622 omap_i2c_put_clocks(dev);
623err_free_mem:
624 platform_set_drvdata(pdev, NULL);
625 kfree(dev);
626err_release_region:
627 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
628 release_mem_region(mem->start, (mem->end - mem->start) + 1);
629
630 return r;
631}
632
633static int
634omap_i2c_remove(struct platform_device *pdev)
635{
636 struct omap_i2c_dev *dev = platform_get_drvdata(pdev);
637 struct resource *mem;
638
639 platform_set_drvdata(pdev, NULL);
640
641 free_irq(dev->irq, dev);
642 i2c_del_adapter(&dev->adapter);
643 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
644 omap_i2c_put_clocks(dev);
645 kfree(dev);
646 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
647 release_mem_region(mem->start, (mem->end - mem->start) + 1);
648 return 0;
649}
650
651static struct platform_driver omap_i2c_driver = {
652 .probe = omap_i2c_probe,
653 .remove = omap_i2c_remove,
654 .driver = {
655 .name = "i2c_omap",
656 .owner = THIS_MODULE,
657 },
658};
659
660/* I2C may be needed to bring up other drivers */
661static int __init
662omap_i2c_init_driver(void)
663{
664 return platform_driver_register(&omap_i2c_driver);
665}
666subsys_initcall(omap_i2c_init_driver);
667
668static void __exit omap_i2c_exit_driver(void)
669{
670 platform_driver_unregister(&omap_i2c_driver);
671}
672module_exit(omap_i2c_exit_driver);
673
674MODULE_AUTHOR("MontaVista Software, Inc. (and others)");
675MODULE_DESCRIPTION("TI OMAP I2C bus adapter");
676MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c
index e09ebbb2f9f0..5eb2bd294fd9 100644
--- a/drivers/i2c/busses/i2c-parport-light.c
+++ b/drivers/i2c/busses/i2c-parport-light.c
@@ -103,7 +103,6 @@ static struct i2c_algo_bit_data parport_algo_data = {
103 .getsda = parport_getsda, 103 .getsda = parport_getsda,
104 .getscl = parport_getscl, 104 .getscl = parport_getscl,
105 .udelay = 50, 105 .udelay = 50,
106 .mdelay = 50,
107 .timeout = HZ, 106 .timeout = HZ,
108}; 107};
109 108
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c
index 934bd55bae15..48a829431c7b 100644
--- a/drivers/i2c/busses/i2c-parport.c
+++ b/drivers/i2c/busses/i2c-parport.c
@@ -138,7 +138,6 @@ static struct i2c_algo_bit_data parport_algo_data = {
138 .getsda = parport_getsda, 138 .getsda = parport_getsda,
139 .getscl = parport_getscl, 139 .getscl = parport_getscl,
140 .udelay = 60, 140 .udelay = 60,
141 .mdelay = 60,
142 .timeout = HZ, 141 .timeout = HZ,
143}; 142};
144 143
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 8f2f65b793b9..30c7a1b38cbd 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -376,7 +376,7 @@ static u32 piix4_func(struct i2c_adapter *adapter)
376 I2C_FUNC_SMBUS_BLOCK_DATA; 376 I2C_FUNC_SMBUS_BLOCK_DATA;
377} 377}
378 378
379static struct i2c_algorithm smbus_algorithm = { 379static const struct i2c_algorithm smbus_algorithm = {
380 .smbus_xfer = piix4_access, 380 .smbus_xfer = piix4_access,
381 .functionality = piix4_func, 381 .functionality = piix4_func,
382}; 382};
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c
index d658d9107955..a508cb962d24 100644
--- a/drivers/i2c/busses/i2c-powermac.c
+++ b/drivers/i2c/busses/i2c-powermac.c
@@ -175,7 +175,7 @@ static u32 i2c_powermac_func(struct i2c_adapter * adapter)
175} 175}
176 176
177/* For now, we only handle smbus */ 177/* For now, we only handle smbus */
178static struct i2c_algorithm i2c_powermac_algorithm = { 178static const struct i2c_algorithm i2c_powermac_algorithm = {
179 .smbus_xfer = i2c_powermac_smbus_xfer, 179 .smbus_xfer = i2c_powermac_smbus_xfer,
180 .master_xfer = i2c_powermac_master_xfer, 180 .master_xfer = i2c_powermac_master_xfer,
181 .functionality = i2c_powermac_func, 181 .functionality = i2c_powermac_func,
diff --git a/drivers/i2c/busses/i2c-prosavage.c b/drivers/i2c/busses/i2c-prosavage.c
index 9479525892e3..7745e21874a8 100644
--- a/drivers/i2c/busses/i2c-prosavage.c
+++ b/drivers/i2c/busses/i2c-prosavage.c
@@ -180,7 +180,6 @@ static int i2c_register_bus(struct pci_dev *dev, struct s_i2c_bus *p, void __iom
180 p->algo.getsda = bit_s3via_getsda; 180 p->algo.getsda = bit_s3via_getsda;
181 p->algo.getscl = bit_s3via_getscl; 181 p->algo.getscl = bit_s3via_getscl;
182 p->algo.udelay = CYCLE_DELAY; 182 p->algo.udelay = CYCLE_DELAY;
183 p->algo.mdelay = CYCLE_DELAY;
184 p->algo.timeout = TIMEOUT; 183 p->algo.timeout = TIMEOUT;
185 p->algo.data = p; 184 p->algo.data = p;
186 p->mmvga = mmvga; 185 p->mmvga = mmvga;
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index ee114b48face..cd4ad98ad517 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -926,7 +926,7 @@ static u32 i2c_pxa_functionality(struct i2c_adapter *adap)
926 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 926 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
927} 927}
928 928
929static struct i2c_algorithm i2c_pxa_algorithm = { 929static const struct i2c_algorithm i2c_pxa_algorithm = {
930 .master_xfer = i2c_pxa_xfer, 930 .master_xfer = i2c_pxa_xfer,
931 .functionality = i2c_pxa_functionality, 931 .functionality = i2c_pxa_functionality,
932}; 932};
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 5d2950e91fc5..9ebe429a0a0f 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -566,7 +566,7 @@ static u32 s3c24xx_i2c_func(struct i2c_adapter *adap)
566 566
567/* i2c bus registration info */ 567/* i2c bus registration info */
568 568
569static struct i2c_algorithm s3c24xx_i2c_algorithm = { 569static const struct i2c_algorithm s3c24xx_i2c_algorithm = {
570 .master_xfer = s3c24xx_i2c_xfer, 570 .master_xfer = s3c24xx_i2c_xfer,
571 .functionality = s3c24xx_i2c_func, 571 .functionality = s3c24xx_i2c_func,
572}; 572};
diff --git a/drivers/i2c/busses/i2c-savage4.c b/drivers/i2c/busses/i2c-savage4.c
index 0c8518298e4d..209f47ea1750 100644
--- a/drivers/i2c/busses/i2c-savage4.c
+++ b/drivers/i2c/busses/i2c-savage4.c
@@ -140,7 +140,6 @@ static struct i2c_algo_bit_data sav_i2c_bit_data = {
140 .getsda = bit_savi2c_getsda, 140 .getsda = bit_savi2c_getsda,
141 .getscl = bit_savi2c_getscl, 141 .getscl = bit_savi2c_getscl,
142 .udelay = CYCLE_DELAY, 142 .udelay = CYCLE_DELAY,
143 .mdelay = CYCLE_DELAY,
144 .timeout = TIMEOUT 143 .timeout = TIMEOUT
145}; 144};
146 145
diff --git a/drivers/i2c/busses/i2c-sibyte.c b/drivers/i2c/busses/i2c-sibyte.c
index fa503ed9f86d..0ca599d3b402 100644
--- a/drivers/i2c/busses/i2c-sibyte.c
+++ b/drivers/i2c/busses/i2c-sibyte.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * Copyright (C) 2004 Steven J. Hill 2 * Copyright (C) 2004 Steven J. Hill
3 * Copyright (C) 2001,2002,2003 Broadcom Corporation 3 * Copyright (C) 2001,2002,2003 Broadcom Corporation
4 * Copyright (C) 1995-2000 Simon G. Vogl
4 * 5 *
5 * This program is free software; you can redistribute it and/or 6 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License 7 * modify it under the terms of the GNU General Public License
@@ -17,11 +18,162 @@
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */ 19 */
19 20
21#include <linux/kernel.h>
20#include <linux/module.h> 22#include <linux/module.h>
21#include <linux/i2c-algo-sibyte.h> 23#include <linux/init.h>
24#include <linux/i2c.h>
25#include <asm/io.h>
22#include <asm/sibyte/sb1250_regs.h> 26#include <asm/sibyte/sb1250_regs.h>
23#include <asm/sibyte/sb1250_smbus.h> 27#include <asm/sibyte/sb1250_smbus.h>
24 28
29
30struct i2c_algo_sibyte_data {
31 void *data; /* private data */
32 int bus; /* which bus */
33 void *reg_base; /* CSR base */
34};
35
36/* ----- global defines ----------------------------------------------- */
37#define SMB_CSR(a,r) ((long)(a->reg_base + r))
38
39/* ----- global variables --------------------------------------------- */
40
41/* module parameters:
42 */
43static int bit_scan; /* have a look at what's hanging 'round */
44module_param(bit_scan, int, 0);
45MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus");
46
47
48static int smbus_xfer(struct i2c_adapter *i2c_adap, u16 addr,
49 unsigned short flags, char read_write,
50 u8 command, int size, union i2c_smbus_data * data)
51{
52 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
53 int data_bytes = 0;
54 int error;
55
56 while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY)
57 ;
58
59 switch (size) {
60 case I2C_SMBUS_QUICK:
61 csr_out32((V_SMB_ADDR(addr) |
62 (read_write == I2C_SMBUS_READ ? M_SMB_QDATA : 0) |
63 V_SMB_TT_QUICKCMD), SMB_CSR(adap, R_SMB_START));
64 break;
65 case I2C_SMBUS_BYTE:
66 if (read_write == I2C_SMBUS_READ) {
67 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_RD1BYTE),
68 SMB_CSR(adap, R_SMB_START));
69 data_bytes = 1;
70 } else {
71 csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
72 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR1BYTE),
73 SMB_CSR(adap, R_SMB_START));
74 }
75 break;
76 case I2C_SMBUS_BYTE_DATA:
77 csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
78 if (read_write == I2C_SMBUS_READ) {
79 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD1BYTE),
80 SMB_CSR(adap, R_SMB_START));
81 data_bytes = 1;
82 } else {
83 csr_out32(V_SMB_LB(data->byte),
84 SMB_CSR(adap, R_SMB_DATA));
85 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE),
86 SMB_CSR(adap, R_SMB_START));
87 }
88 break;
89 case I2C_SMBUS_WORD_DATA:
90 csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
91 if (read_write == I2C_SMBUS_READ) {
92 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD2BYTE),
93 SMB_CSR(adap, R_SMB_START));
94 data_bytes = 2;
95 } else {
96 csr_out32(V_SMB_LB(data->word & 0xff),
97 SMB_CSR(adap, R_SMB_DATA));
98 csr_out32(V_SMB_MB(data->word >> 8),
99 SMB_CSR(adap, R_SMB_DATA));
100 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE),
101 SMB_CSR(adap, R_SMB_START));
102 }
103 break;
104 default:
105 return -1; /* XXXKW better error code? */
106 }
107
108 while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY)
109 ;
110
111 error = csr_in32(SMB_CSR(adap, R_SMB_STATUS));
112 if (error & M_SMB_ERROR) {
113 /* Clear error bit by writing a 1 */
114 csr_out32(M_SMB_ERROR, SMB_CSR(adap, R_SMB_STATUS));
115 return -1; /* XXXKW better error code? */
116 }
117
118 if (data_bytes == 1)
119 data->byte = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xff;
120 if (data_bytes == 2)
121 data->word = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xffff;
122
123 return 0;
124}
125
126static u32 bit_func(struct i2c_adapter *adap)
127{
128 return (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
129 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA);
130}
131
132
133/* -----exported algorithm data: ------------------------------------- */
134
135static const struct i2c_algorithm i2c_sibyte_algo = {
136 .smbus_xfer = smbus_xfer,
137 .functionality = bit_func,
138};
139
140/*
141 * registering functions to load algorithms at runtime
142 */
143int i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed)
144{
145 int i;
146 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
147
148 /* register new adapter to i2c module... */
149 i2c_adap->algo = &i2c_sibyte_algo;
150
151 /* Set the frequency to 100 kHz */
152 csr_out32(speed, SMB_CSR(adap,R_SMB_FREQ));
153 csr_out32(0, SMB_CSR(adap,R_SMB_CONTROL));
154
155 /* scan bus */
156 if (bit_scan) {
157 union i2c_smbus_data data;
158 int rc;
159 printk(KERN_INFO " i2c-algo-sibyte.o: scanning bus %s.\n",
160 i2c_adap->name);
161 for (i = 0x00; i < 0x7f; i++) {
162 /* XXXKW is this a realistic probe? */
163 rc = smbus_xfer(i2c_adap, i, 0, I2C_SMBUS_READ, 0,
164 I2C_SMBUS_BYTE_DATA, &data);
165 if (!rc) {
166 printk("(%02x)",i);
167 } else
168 printk(".");
169 }
170 printk("\n");
171 }
172
173 return i2c_add_adapter(i2c_adap);
174}
175
176
25static struct i2c_algo_sibyte_data sibyte_board_data[2] = { 177static struct i2c_algo_sibyte_data sibyte_board_data[2] = {
26 { NULL, 0, (void *) (CKSEG1+A_SMB_BASE(0)) }, 178 { NULL, 0, (void *) (CKSEG1+A_SMB_BASE(0)) },
27 { NULL, 1, (void *) (CKSEG1+A_SMB_BASE(1)) } 179 { NULL, 1, (void *) (CKSEG1+A_SMB_BASE(1)) }
@@ -58,13 +210,13 @@ static int __init i2c_sibyte_init(void)
58 210
59static void __exit i2c_sibyte_exit(void) 211static void __exit i2c_sibyte_exit(void)
60{ 212{
61 i2c_sibyte_del_bus(&sibyte_board_adapter[0]); 213 i2c_del_adapter(&sibyte_board_adapter[0]);
62 i2c_sibyte_del_bus(&sibyte_board_adapter[1]); 214 i2c_del_adapter(&sibyte_board_adapter[1]);
63} 215}
64 216
65module_init(i2c_sibyte_init); 217module_init(i2c_sibyte_init);
66module_exit(i2c_sibyte_exit); 218module_exit(i2c_sibyte_exit);
67 219
68MODULE_AUTHOR("Kip Walker <kwalker@broadcom.com>, Steven J. Hill <sjhill@realitydiluted.com>"); 220MODULE_AUTHOR("Kip Walker (Broadcom Corp.), Steven J. Hill <sjhill@realitydiluted.com>");
69MODULE_DESCRIPTION("SMBus adapter routines for SiByte boards"); 221MODULE_DESCRIPTION("SMBus adapter routines for SiByte boards");
70MODULE_LICENSE("GPL"); 222MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index b57ab74d23ec..38bbfd840b6b 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -358,7 +358,7 @@ static u32 sis5595_func(struct i2c_adapter *adapter)
358 I2C_FUNC_SMBUS_PROC_CALL; 358 I2C_FUNC_SMBUS_PROC_CALL;
359} 359}
360 360
361static struct i2c_algorithm smbus_algorithm = { 361static const struct i2c_algorithm smbus_algorithm = {
362 .smbus_xfer = sis5595_access, 362 .smbus_xfer = sis5595_access,
363 .functionality = sis5595_func, 363 .functionality = sis5595_func,
364}; 364};
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index acb75e282414..dec0bafb52ab 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -450,7 +450,7 @@ exit:
450} 450}
451 451
452 452
453static struct i2c_algorithm smbus_algorithm = { 453static const struct i2c_algorithm smbus_algorithm = {
454 .smbus_xfer = sis630_access, 454 .smbus_xfer = sis630_access,
455 .functionality = sis630_func, 455 .functionality = sis630_func,
456}; 456};
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index 1a73c0532fc7..7fd07fbac336 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -242,7 +242,7 @@ static u32 sis96x_func(struct i2c_adapter *adapter)
242 I2C_FUNC_SMBUS_PROC_CALL; 242 I2C_FUNC_SMBUS_PROC_CALL;
243} 243}
244 244
245static struct i2c_algorithm smbus_algorithm = { 245static const struct i2c_algorithm smbus_algorithm = {
246 .smbus_xfer = sis96x_access, 246 .smbus_xfer = sis96x_access,
247 .functionality = sis96x_func, 247 .functionality = sis96x_func,
248}; 248};
diff --git a/drivers/i2c/busses/i2c-stub.c b/drivers/i2c/busses/i2c-stub.c
index 73f481e93a36..a54adc50d162 100644
--- a/drivers/i2c/busses/i2c-stub.c
+++ b/drivers/i2c/busses/i2c-stub.c
@@ -27,6 +27,10 @@
27#include <linux/errno.h> 27#include <linux/errno.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29 29
30static unsigned short chip_addr;
31module_param(chip_addr, ushort, S_IRUGO);
32MODULE_PARM_DESC(chip_addr, "Chip address (between 0x03 and 0x77)\n");
33
30static u8 stub_pointer; 34static u8 stub_pointer;
31static u8 stub_bytes[256]; 35static u8 stub_bytes[256];
32static u16 stub_words[256]; 36static u16 stub_words[256];
@@ -37,6 +41,9 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
37{ 41{
38 s32 ret; 42 s32 ret;
39 43
44 if (addr != chip_addr)
45 return -ENODEV;
46
40 switch (size) { 47 switch (size) {
41 48
42 case I2C_SMBUS_QUICK: 49 case I2C_SMBUS_QUICK:
@@ -108,7 +115,7 @@ static u32 stub_func(struct i2c_adapter *adapter)
108 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA; 115 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA;
109} 116}
110 117
111static struct i2c_algorithm smbus_algorithm = { 118static const struct i2c_algorithm smbus_algorithm = {
112 .functionality = stub_func, 119 .functionality = stub_func,
113 .smbus_xfer = stub_xfer, 120 .smbus_xfer = stub_xfer,
114}; 121};
@@ -122,7 +129,17 @@ static struct i2c_adapter stub_adapter = {
122 129
123static int __init i2c_stub_init(void) 130static int __init i2c_stub_init(void)
124{ 131{
125 printk(KERN_INFO "i2c-stub loaded\n"); 132 if (!chip_addr) {
133 printk(KERN_ERR "i2c-stub: Please specify a chip address\n");
134 return -ENODEV;
135 }
136 if (chip_addr < 0x03 || chip_addr > 0x77) {
137 printk(KERN_ERR "i2c-stub: Invalid chip address 0x%02x\n",
138 chip_addr);
139 return -EINVAL;
140 }
141
142 printk(KERN_INFO "i2c-stub: Virtual chip at 0x%02x\n", chip_addr);
126 return i2c_add_adapter(&stub_adapter); 143 return i2c_add_adapter(&stub_adapter);
127} 144}
128 145
diff --git a/drivers/i2c/busses/i2c-via.c b/drivers/i2c/busses/i2c-via.c
index 484bbacfce6b..910e200ad500 100644
--- a/drivers/i2c/busses/i2c-via.c
+++ b/drivers/i2c/busses/i2c-via.c
@@ -81,7 +81,6 @@ static struct i2c_algo_bit_data bit_data = {
81 .getsda = bit_via_getsda, 81 .getsda = bit_via_getsda,
82 .getscl = bit_via_getscl, 82 .getscl = bit_via_getscl,
83 .udelay = 5, 83 .udelay = 5,
84 .mdelay = 5,
85 .timeout = HZ 84 .timeout = HZ
86}; 85};
87 86
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 47e52bf2c5ec..efc6bbf0cc0a 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -34,6 +34,8 @@
34 VT8233A 0x3147 yes? 34 VT8233A 0x3147 yes?
35 VT8235 0x3177 yes 35 VT8235 0x3177 yes
36 VT8237R 0x3227 yes 36 VT8237R 0x3227 yes
37 VT8237A 0x3337 yes
38 VT8251 0x3287 yes
37 39
38 Note: we assume there can only be one device, with one SMBus interface. 40 Note: we assume there can only be one device, with one SMBus interface.
39*/ 41*/
@@ -297,7 +299,7 @@ static u32 vt596_func(struct i2c_adapter *adapter)
297 return func; 299 return func;
298} 300}
299 301
300static struct i2c_algorithm smbus_algorithm = { 302static const struct i2c_algorithm smbus_algorithm = {
301 .smbus_xfer = vt596_access, 303 .smbus_xfer = vt596_access,
302 .functionality = vt596_func, 304 .functionality = vt596_func,
303}; 305};
@@ -381,7 +383,9 @@ found:
381 dev_dbg(&pdev->dev, "VT596_smba = 0x%X\n", vt596_smba); 383 dev_dbg(&pdev->dev, "VT596_smba = 0x%X\n", vt596_smba);
382 384
383 switch (pdev->device) { 385 switch (pdev->device) {
386 case PCI_DEVICE_ID_VIA_8251:
384 case PCI_DEVICE_ID_VIA_8237: 387 case PCI_DEVICE_ID_VIA_8237:
388 case PCI_DEVICE_ID_VIA_8237A:
385 case PCI_DEVICE_ID_VIA_8235: 389 case PCI_DEVICE_ID_VIA_8235:
386 case PCI_DEVICE_ID_VIA_8233A: 390 case PCI_DEVICE_ID_VIA_8233A:
387 case PCI_DEVICE_ID_VIA_8233_0: 391 case PCI_DEVICE_ID_VIA_8233_0:
@@ -432,8 +436,12 @@ static struct pci_device_id vt596_ids[] = {
432 .driver_data = SMBBA3 }, 436 .driver_data = SMBBA3 },
433 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237), 437 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237),
434 .driver_data = SMBBA3 }, 438 .driver_data = SMBBA3 },
439 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237A),
440 .driver_data = SMBBA3 },
435 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4), 441 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4),
436 .driver_data = SMBBA1 }, 442 .driver_data = SMBBA1 },
443 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8251),
444 .driver_data = SMBBA3 },
437 { 0, } 445 { 0, }
438}; 446};
439 447
diff --git a/drivers/i2c/busses/i2c-voodoo3.c b/drivers/i2c/busses/i2c-voodoo3.c
index b675773b0cc1..6c8d25183382 100644
--- a/drivers/i2c/busses/i2c-voodoo3.c
+++ b/drivers/i2c/busses/i2c-voodoo3.c
@@ -160,7 +160,6 @@ static struct i2c_algo_bit_data voo_i2c_bit_data = {
160 .getsda = bit_vooi2c_getsda, 160 .getsda = bit_vooi2c_getsda,
161 .getscl = bit_vooi2c_getscl, 161 .getscl = bit_vooi2c_getscl,
162 .udelay = CYCLE_DELAY, 162 .udelay = CYCLE_DELAY,
163 .mdelay = CYCLE_DELAY,
164 .timeout = TIMEOUT 163 .timeout = TIMEOUT
165}; 164};
166 165
@@ -177,7 +176,6 @@ static struct i2c_algo_bit_data voo_ddc_bit_data = {
177 .getsda = bit_vooddc_getsda, 176 .getsda = bit_vooddc_getsda,
178 .getscl = bit_vooddc_getscl, 177 .getscl = bit_vooddc_getscl,
179 .udelay = CYCLE_DELAY, 178 .udelay = CYCLE_DELAY,
180 .mdelay = CYCLE_DELAY,
181 .timeout = TIMEOUT 179 .timeout = TIMEOUT
182}; 180};
183 181
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index eae9e81be375..32aab0d34ee9 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -383,7 +383,7 @@ static u32 scx200_acb_func(struct i2c_adapter *adapter)
383} 383}
384 384
385/* For now, we only handle combined mode (smbus) */ 385/* For now, we only handle combined mode (smbus) */
386static struct i2c_algorithm scx200_acb_algorithm = { 386static const struct i2c_algorithm scx200_acb_algorithm = {
387 .smbus_xfer = scx200_acb_smbus_xfer, 387 .smbus_xfer = scx200_acb_smbus_xfer,
388 .functionality = scx200_acb_func, 388 .functionality = scx200_acb_func,
389}; 389};
diff --git a/drivers/i2c/busses/scx200_i2c.c b/drivers/i2c/busses/scx200_i2c.c
index cb3ef5ac99fd..8b65a5cf8251 100644
--- a/drivers/i2c/busses/scx200_i2c.c
+++ b/drivers/i2c/busses/scx200_i2c.c
@@ -71,12 +71,12 @@ static int scx200_i2c_getsda(void *data)
71 */ 71 */
72 72
73static struct i2c_algo_bit_data scx200_i2c_data = { 73static struct i2c_algo_bit_data scx200_i2c_data = {
74 NULL, 74 .setsda = scx200_i2c_setsda,
75 scx200_i2c_setsda, 75 .setscl = scx200_i2c_setscl,
76 scx200_i2c_setscl, 76 .getsda = scx200_i2c_getsda,
77 scx200_i2c_getsda, 77 .getscl = scx200_i2c_getscl,
78 scx200_i2c_getscl, 78 .udelay = 10,
79 10, 10, 100, /* waits, timeout */ 79 .timeout = 100,
80}; 80};
81 81
82static struct i2c_adapter scx200_i2c_ops = { 82static struct i2c_adapter scx200_i2c_ops = {
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c
index 13c108269a6d..cec3a0c3894d 100644
--- a/drivers/i2c/chips/eeprom.c
+++ b/drivers/i2c/chips/eeprom.c
@@ -209,10 +209,14 @@ static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
209 } 209 }
210 210
211 /* create the sysfs eeprom file */ 211 /* create the sysfs eeprom file */
212 sysfs_create_bin_file(&new_client->dev.kobj, &eeprom_attr); 212 err = sysfs_create_bin_file(&new_client->dev.kobj, &eeprom_attr);
213 if (err)
214 goto exit_detach;
213 215
214 return 0; 216 return 0;
215 217
218exit_detach:
219 i2c_detach_client(new_client);
216exit_kfree: 220exit_kfree:
217 kfree(data); 221 kfree(data);
218exit: 222exit:
@@ -223,6 +227,8 @@ static int eeprom_detach_client(struct i2c_client *client)
223{ 227{
224 int err; 228 int err;
225 229
230 sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr);
231
226 err = i2c_detach_client(client); 232 err = i2c_detach_client(client);
227 if (err) 233 if (err)
228 return err; 234 return err;
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c
index f92505b94c61..182f04953466 100644
--- a/drivers/i2c/chips/isp1301_omap.c
+++ b/drivers/i2c/chips/isp1301_omap.c
@@ -30,7 +30,7 @@
30#include <linux/usb_ch9.h> 30#include <linux/usb_ch9.h>
31#include <linux/usb_gadget.h> 31#include <linux/usb_gadget.h>
32#include <linux/usb.h> 32#include <linux/usb.h>
33#include <linux/usb_otg.h> 33#include <linux/usb/otg.h>
34#include <linux/i2c.h> 34#include <linux/i2c.h>
35#include <linux/workqueue.h> 35#include <linux/workqueue.h>
36 36
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c
index 88d2ddee4490..76645c142977 100644
--- a/drivers/i2c/chips/max6875.c
+++ b/drivers/i2c/chips/max6875.c
@@ -199,8 +199,7 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
199 mutex_init(&data->update_lock); 199 mutex_init(&data->update_lock);
200 200
201 /* Init fake client data */ 201 /* Init fake client data */
202 /* set the client data to the i2c_client so that it will get freed */ 202 i2c_set_clientdata(fake_client, NULL);
203 i2c_set_clientdata(fake_client, fake_client);
204 fake_client->addr = address | 1; 203 fake_client->addr = address | 1;
205 fake_client->adapter = adapter; 204 fake_client->adapter = adapter;
206 fake_client->driver = &max6875_driver; 205 fake_client->driver = &max6875_driver;
@@ -214,13 +213,17 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
214 goto exit_kfree2; 213 goto exit_kfree2;
215 214
216 if ((err = i2c_attach_client(fake_client)) != 0) 215 if ((err = i2c_attach_client(fake_client)) != 0)
217 goto exit_detach; 216 goto exit_detach1;
218 217
219 sysfs_create_bin_file(&real_client->dev.kobj, &user_eeprom_attr); 218 err = sysfs_create_bin_file(&real_client->dev.kobj, &user_eeprom_attr);
219 if (err)
220 goto exit_detach2;
220 221
221 return 0; 222 return 0;
222 223
223exit_detach: 224exit_detach2:
225 i2c_detach_client(fake_client);
226exit_detach1:
224 i2c_detach_client(real_client); 227 i2c_detach_client(real_client);
225exit_kfree2: 228exit_kfree2:
226 kfree(fake_client); 229 kfree(fake_client);
@@ -229,14 +232,24 @@ exit_kfree1:
229 return err; 232 return err;
230} 233}
231 234
235/* Will be called for both the real client and the fake client */
232static int max6875_detach_client(struct i2c_client *client) 236static int max6875_detach_client(struct i2c_client *client)
233{ 237{
234 int err; 238 int err;
239 struct max6875_data *data = i2c_get_clientdata(client);
240
241 /* data is NULL for the fake client */
242 if (data)
243 sysfs_remove_bin_file(&client->dev.kobj, &user_eeprom_attr);
235 244
236 err = i2c_detach_client(client); 245 err = i2c_detach_client(client);
237 if (err) 246 if (err)
238 return err; 247 return err;
239 kfree(i2c_get_clientdata(client)); 248
249 if (data) /* real client */
250 kfree(data);
251 else /* fake client */
252 kfree(client);
240 return 0; 253 return 0;
241} 254}
242 255
diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c
index cb22280cdd27..f43c4e79b55e 100644
--- a/drivers/i2c/chips/pca9539.c
+++ b/drivers/i2c/chips/pca9539.c
@@ -148,11 +148,16 @@ static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind)
148 if ((err = i2c_attach_client(new_client))) 148 if ((err = i2c_attach_client(new_client)))
149 goto exit_kfree; 149 goto exit_kfree;
150 150
151 /* Register sysfs hooks (don't care about failure) */ 151 /* Register sysfs hooks */
152 sysfs_create_group(&new_client->dev.kobj, &pca9539_defattr_group); 152 err = sysfs_create_group(&new_client->dev.kobj,
153 &pca9539_defattr_group);
154 if (err)
155 goto exit_detach;
153 156
154 return 0; 157 return 0;
155 158
159exit_detach:
160 i2c_detach_client(new_client);
156exit_kfree: 161exit_kfree:
157 kfree(data); 162 kfree(data);
158exit: 163exit:
@@ -163,6 +168,8 @@ static int pca9539_detach_client(struct i2c_client *client)
163{ 168{
164 int err; 169 int err;
165 170
171 sysfs_remove_group(&client->dev.kobj, &pca9539_defattr_group);
172
166 if ((err = i2c_detach_client(client))) 173 if ((err = i2c_detach_client(client)))
167 return err; 174 return err;
168 175
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c
index c3e6449c4481..32b25427eaba 100644
--- a/drivers/i2c/chips/pcf8574.c
+++ b/drivers/i2c/chips/pcf8574.c
@@ -105,6 +105,16 @@ static ssize_t set_write(struct device *dev, struct device_attribute *attr, cons
105 105
106static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write); 106static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write);
107 107
108static struct attribute *pcf8574_attributes[] = {
109 &dev_attr_read.attr,
110 &dev_attr_write.attr,
111 NULL
112};
113
114static const struct attribute_group pcf8574_attr_group = {
115 .attrs = pcf8574_attributes,
116};
117
108/* 118/*
109 * Real code 119 * Real code
110 */ 120 */
@@ -166,13 +176,13 @@ static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
166 pcf8574_init_client(new_client); 176 pcf8574_init_client(new_client);
167 177
168 /* Register sysfs hooks */ 178 /* Register sysfs hooks */
169 device_create_file(&new_client->dev, &dev_attr_read); 179 err = sysfs_create_group(&new_client->dev.kobj, &pcf8574_attr_group);
170 device_create_file(&new_client->dev, &dev_attr_write); 180 if (err)
181 goto exit_detach;
171 return 0; 182 return 0;
172 183
173/* OK, this is not exactly good programming practice, usually. But it is 184 exit_detach:
174 very code-efficient in this case. */ 185 i2c_detach_client(new_client);
175
176 exit_free: 186 exit_free:
177 kfree(data); 187 kfree(data);
178 exit: 188 exit:
@@ -183,6 +193,8 @@ static int pcf8574_detach_client(struct i2c_client *client)
183{ 193{
184 int err; 194 int err;
185 195
196 sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group);
197
186 if ((err = i2c_detach_client(client))) 198 if ((err = i2c_detach_client(client)))
187 return err; 199 return err;
188 200
diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c
index 925a6b371fd2..4dc36376eb32 100644
--- a/drivers/i2c/chips/pcf8591.c
+++ b/drivers/i2c/chips/pcf8591.c
@@ -158,6 +158,28 @@ static ssize_t set_out0_enable(struct device *dev, struct device_attribute *attr
158static DEVICE_ATTR(out0_enable, S_IWUSR | S_IRUGO, 158static DEVICE_ATTR(out0_enable, S_IWUSR | S_IRUGO,
159 show_out0_enable, set_out0_enable); 159 show_out0_enable, set_out0_enable);
160 160
161static struct attribute *pcf8591_attributes[] = {
162 &dev_attr_out0_enable.attr,
163 &dev_attr_out0_output.attr,
164 &dev_attr_in0_input.attr,
165 &dev_attr_in1_input.attr,
166 NULL
167};
168
169static const struct attribute_group pcf8591_attr_group = {
170 .attrs = pcf8591_attributes,
171};
172
173static struct attribute *pcf8591_attributes_opt[] = {
174 &dev_attr_in2_input.attr,
175 &dev_attr_in3_input.attr,
176 NULL
177};
178
179static const struct attribute_group pcf8591_attr_group_opt = {
180 .attrs = pcf8591_attributes_opt,
181};
182
161/* 183/*
162 * Real code 184 * Real code
163 */ 185 */
@@ -211,24 +233,31 @@ static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind)
211 pcf8591_init_client(new_client); 233 pcf8591_init_client(new_client);
212 234
213 /* Register sysfs hooks */ 235 /* Register sysfs hooks */
214 device_create_file(&new_client->dev, &dev_attr_out0_enable); 236 err = sysfs_create_group(&new_client->dev.kobj, &pcf8591_attr_group);
215 device_create_file(&new_client->dev, &dev_attr_out0_output); 237 if (err)
216 device_create_file(&new_client->dev, &dev_attr_in0_input); 238 goto exit_detach;
217 device_create_file(&new_client->dev, &dev_attr_in1_input);
218 239
219 /* Register input2 if not in "two differential inputs" mode */ 240 /* Register input2 if not in "two differential inputs" mode */
220 if (input_mode != 3 ) 241 if (input_mode != 3) {
221 device_create_file(&new_client->dev, &dev_attr_in2_input); 242 if ((err = device_create_file(&new_client->dev,
222 243 &dev_attr_in2_input)))
244 goto exit_sysfs_remove;
245 }
246
223 /* Register input3 only in "four single ended inputs" mode */ 247 /* Register input3 only in "four single ended inputs" mode */
224 if (input_mode == 0) 248 if (input_mode == 0) {
225 device_create_file(&new_client->dev, &dev_attr_in3_input); 249 if ((err = device_create_file(&new_client->dev,
226 250 &dev_attr_in3_input)))
251 goto exit_sysfs_remove;
252 }
253
227 return 0; 254 return 0;
228
229 /* OK, this is not exactly good programming practice, usually. But it is
230 very code-efficient in this case. */
231 255
256exit_sysfs_remove:
257 sysfs_remove_group(&new_client->dev.kobj, &pcf8591_attr_group_opt);
258 sysfs_remove_group(&new_client->dev.kobj, &pcf8591_attr_group);
259exit_detach:
260 i2c_detach_client(new_client);
232exit_kfree: 261exit_kfree:
233 kfree(data); 262 kfree(data);
234exit: 263exit:
@@ -239,6 +268,9 @@ static int pcf8591_detach_client(struct i2c_client *client)
239{ 268{
240 int err; 269 int err;
241 270
271 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt);
272 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group);
273
242 if ((err = i2c_detach_client(client))) 274 if ((err = i2c_detach_client(client)))
243 return err; 275 return err;
244 276
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index 0be6fd6a267d..6a7578217177 100644
--- a/drivers/i2c/chips/tps65010.c
+++ b/drivers/i2c/chips/tps65010.c
@@ -305,7 +305,7 @@ static int dbg_show(struct seq_file *s, void *_)
305 305
306static int dbg_tps_open(struct inode *inode, struct file *file) 306static int dbg_tps_open(struct inode *inode, struct file *file)
307{ 307{
308 return single_open(file, dbg_show, inode->u.generic_ip); 308 return single_open(file, dbg_show, inode->i_private);
309} 309}
310 310
311static struct file_operations debug_fops = { 311static struct file_operations debug_fops = {
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 9cb277d6aa48..7ca81f42d14b 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -183,15 +183,21 @@ int i2c_add_adapter(struct i2c_adapter *adap)
183 sprintf(adap->dev.bus_id, "i2c-%d", adap->nr); 183 sprintf(adap->dev.bus_id, "i2c-%d", adap->nr);
184 adap->dev.driver = &i2c_adapter_driver; 184 adap->dev.driver = &i2c_adapter_driver;
185 adap->dev.release = &i2c_adapter_dev_release; 185 adap->dev.release = &i2c_adapter_dev_release;
186 device_register(&adap->dev); 186 res = device_register(&adap->dev);
187 device_create_file(&adap->dev, &dev_attr_name); 187 if (res)
188 goto out_list;
189 res = device_create_file(&adap->dev, &dev_attr_name);
190 if (res)
191 goto out_unregister;
188 192
189 /* Add this adapter to the i2c_adapter class */ 193 /* Add this adapter to the i2c_adapter class */
190 memset(&adap->class_dev, 0x00, sizeof(struct class_device)); 194 memset(&adap->class_dev, 0x00, sizeof(struct class_device));
191 adap->class_dev.dev = &adap->dev; 195 adap->class_dev.dev = &adap->dev;
192 adap->class_dev.class = &i2c_adapter_class; 196 adap->class_dev.class = &i2c_adapter_class;
193 strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE); 197 strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE);
194 class_device_register(&adap->class_dev); 198 res = class_device_register(&adap->class_dev);
199 if (res)
200 goto out_remove_name;
195 201
196 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); 202 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
197 203
@@ -206,6 +212,17 @@ int i2c_add_adapter(struct i2c_adapter *adap)
206out_unlock: 212out_unlock:
207 mutex_unlock(&core_lists); 213 mutex_unlock(&core_lists);
208 return res; 214 return res;
215
216out_remove_name:
217 device_remove_file(&adap->dev, &dev_attr_name);
218out_unregister:
219 init_completion(&adap->dev_released); /* Needed? */
220 device_unregister(&adap->dev);
221 wait_for_completion(&adap->dev_released);
222out_list:
223 list_del(&adap->list);
224 idr_remove(&i2c_adapter_idr, adap->nr);
225 goto out_unlock;
209} 226}
210 227
211 228
@@ -394,23 +411,15 @@ int i2c_check_addr(struct i2c_adapter *adapter, int addr)
394int i2c_attach_client(struct i2c_client *client) 411int i2c_attach_client(struct i2c_client *client)
395{ 412{
396 struct i2c_adapter *adapter = client->adapter; 413 struct i2c_adapter *adapter = client->adapter;
414 int res = 0;
397 415
398 mutex_lock(&adapter->clist_lock); 416 mutex_lock(&adapter->clist_lock);
399 if (__i2c_check_addr(client->adapter, client->addr)) { 417 if (__i2c_check_addr(client->adapter, client->addr)) {
400 mutex_unlock(&adapter->clist_lock); 418 res = -EBUSY;
401 return -EBUSY; 419 goto out_unlock;
402 } 420 }
403 list_add_tail(&client->list,&adapter->clients); 421 list_add_tail(&client->list,&adapter->clients);
404 mutex_unlock(&adapter->clist_lock);
405 422
406 if (adapter->client_register) {
407 if (adapter->client_register(client)) {
408 dev_dbg(&adapter->dev, "client_register "
409 "failed for client [%s] at 0x%02x\n",
410 client->name, client->addr);
411 }
412 }
413
414 client->usage_count = 0; 423 client->usage_count = 0;
415 424
416 client->dev.parent = &client->adapter->dev; 425 client->dev.parent = &client->adapter->dev;
@@ -422,10 +431,35 @@ int i2c_attach_client(struct i2c_client *client)
422 "%d-%04x", i2c_adapter_id(adapter), client->addr); 431 "%d-%04x", i2c_adapter_id(adapter), client->addr);
423 dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n", 432 dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n",
424 client->name, client->dev.bus_id); 433 client->name, client->dev.bus_id);
425 device_register(&client->dev); 434 res = device_register(&client->dev);
426 device_create_file(&client->dev, &dev_attr_client_name); 435 if (res)
427 436 goto out_list;
437 res = device_create_file(&client->dev, &dev_attr_client_name);
438 if (res)
439 goto out_unregister;
440 mutex_unlock(&adapter->clist_lock);
441
442 if (adapter->client_register) {
443 if (adapter->client_register(client)) {
444 dev_dbg(&adapter->dev, "client_register "
445 "failed for client [%s] at 0x%02x\n",
446 client->name, client->addr);
447 }
448 }
449
428 return 0; 450 return 0;
451
452out_unregister:
453 init_completion(&client->released); /* Needed? */
454 device_unregister(&client->dev);
455 wait_for_completion(&client->released);
456out_list:
457 list_del(&client->list);
458 dev_err(&adapter->dev, "Failed to attach i2c client %s at 0x%02x "
459 "(%d)\n", client->name, client->addr, res);
460out_unlock:
461 mutex_unlock(&adapter->clist_lock);
462 return res;
429} 463}
430 464
431 465
@@ -674,11 +708,16 @@ static int i2c_probe_address(struct i2c_adapter *adapter, int addr, int kind,
674 708
675 /* Finally call the custom detection function */ 709 /* Finally call the custom detection function */
676 err = found_proc(adapter, addr, kind); 710 err = found_proc(adapter, addr, kind);
677
678 /* -ENODEV can be returned if there is a chip at the given address 711 /* -ENODEV can be returned if there is a chip at the given address
679 but it isn't supported by this chip driver. We catch it here as 712 but it isn't supported by this chip driver. We catch it here as
680 this isn't an error. */ 713 this isn't an error. */
681 return (err == -ENODEV) ? 0 : err; 714 if (err == -ENODEV)
715 err = 0;
716
717 if (err)
718 dev_warn(&adapter->dev, "Client creation failed at 0x%x (%d)\n",
719 addr, err);
720 return err;
682} 721}
683 722
684int i2c_probe(struct i2c_adapter *adapter, 723int i2c_probe(struct i2c_adapter *adapter,
@@ -868,7 +907,7 @@ s32 i2c_smbus_read_byte(struct i2c_client *client)
868 I2C_SMBUS_READ,0,I2C_SMBUS_BYTE, &data)) 907 I2C_SMBUS_READ,0,I2C_SMBUS_BYTE, &data))
869 return -1; 908 return -1;
870 else 909 else
871 return 0x0FF & data.byte; 910 return data.byte;
872} 911}
873 912
874s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) 913s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value)
@@ -884,7 +923,7 @@ s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command)
884 I2C_SMBUS_READ,command, I2C_SMBUS_BYTE_DATA,&data)) 923 I2C_SMBUS_READ,command, I2C_SMBUS_BYTE_DATA,&data))
885 return -1; 924 return -1;
886 else 925 else
887 return 0x0FF & data.byte; 926 return data.byte;
888} 927}
889 928
890s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value) 929s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value)
@@ -903,7 +942,7 @@ s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command)
903 I2C_SMBUS_READ,command, I2C_SMBUS_WORD_DATA, &data)) 942 I2C_SMBUS_READ,command, I2C_SMBUS_WORD_DATA, &data))
904 return -1; 943 return -1;
905 else 944 else
906 return 0x0FFFF & data.word; 945 return data.word;
907} 946}
908 947
909s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) 948s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
@@ -1006,7 +1045,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1006 else { 1045 else {
1007 msg[0].len=3; 1046 msg[0].len=3;
1008 msgbuf0[1] = data->word & 0xff; 1047 msgbuf0[1] = data->word & 0xff;
1009 msgbuf0[2] = (data->word >> 8) & 0xff; 1048 msgbuf0[2] = data->word >> 8;
1010 } 1049 }
1011 break; 1050 break;
1012 case I2C_SMBUS_PROC_CALL: 1051 case I2C_SMBUS_PROC_CALL:
@@ -1015,7 +1054,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1015 msg[0].len = 3; 1054 msg[0].len = 3;
1016 msg[1].len = 2; 1055 msg[1].len = 2;
1017 msgbuf0[1] = data->word & 0xff; 1056 msgbuf0[1] = data->word & 0xff;
1018 msgbuf0[2] = (data->word >> 8) & 0xff; 1057 msgbuf0[2] = data->word >> 8;
1019 break; 1058 break;
1020 case I2C_SMBUS_BLOCK_DATA: 1059 case I2C_SMBUS_BLOCK_DATA:
1021 if (read_write == I2C_SMBUS_READ) { 1060 if (read_write == I2C_SMBUS_READ) {
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 58ccddd5c237..3f869033ed70 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -32,43 +32,35 @@
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/smp_lock.h> 33#include <linux/smp_lock.h>
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/list.h>
35#include <linux/i2c.h> 36#include <linux/i2c.h>
36#include <linux/i2c-dev.h> 37#include <linux/i2c-dev.h>
37#include <linux/platform_device.h>
38#include <asm/uaccess.h> 38#include <asm/uaccess.h>
39 39
40static struct i2c_client i2cdev_client_template; 40static struct i2c_driver i2cdev_driver;
41 41
42struct i2c_dev { 42struct i2c_dev {
43 int minor; 43 struct list_head list;
44 struct i2c_adapter *adap; 44 struct i2c_adapter *adap;
45 struct class_device *class_dev; 45 struct class_device *class_dev;
46}; 46};
47#define to_i2c_dev(d) container_of(d, struct i2c_dev, class_dev)
48 47
49#define I2C_MINORS 256 48#define I2C_MINORS 256
50static struct i2c_dev *i2c_dev_array[I2C_MINORS]; 49static LIST_HEAD(i2c_dev_list);
51static DEFINE_SPINLOCK(i2c_dev_array_lock); 50static DEFINE_SPINLOCK(i2c_dev_list_lock);
52 51
53static struct i2c_dev *i2c_dev_get_by_minor(unsigned index) 52static struct i2c_dev *i2c_dev_get_by_minor(unsigned index)
54{ 53{
55 struct i2c_dev *i2c_dev; 54 struct i2c_dev *i2c_dev;
56 55
57 spin_lock(&i2c_dev_array_lock); 56 spin_lock(&i2c_dev_list_lock);
58 i2c_dev = i2c_dev_array[index]; 57 list_for_each_entry(i2c_dev, &i2c_dev_list, list) {
59 spin_unlock(&i2c_dev_array_lock); 58 if (i2c_dev->adap->nr == index)
60 return i2c_dev; 59 goto found;
61} 60 }
62 61 i2c_dev = NULL;
63static struct i2c_dev *i2c_dev_get_by_adapter(struct i2c_adapter *adap) 62found:
64{ 63 spin_unlock(&i2c_dev_list_lock);
65 struct i2c_dev *i2c_dev = NULL;
66
67 spin_lock(&i2c_dev_array_lock);
68 if ((i2c_dev_array[adap->nr]) &&
69 (i2c_dev_array[adap->nr]->adap == adap))
70 i2c_dev = i2c_dev_array[adap->nr];
71 spin_unlock(&i2c_dev_array_lock);
72 return i2c_dev; 64 return i2c_dev;
73} 65}
74 66
@@ -76,30 +68,28 @@ static struct i2c_dev *get_free_i2c_dev(struct i2c_adapter *adap)
76{ 68{
77 struct i2c_dev *i2c_dev; 69 struct i2c_dev *i2c_dev;
78 70
71 if (adap->nr >= I2C_MINORS) {
72 printk(KERN_ERR "i2c-dev: Out of device minors (%d)\n",
73 adap->nr);
74 return ERR_PTR(-ENODEV);
75 }
76
79 i2c_dev = kzalloc(sizeof(*i2c_dev), GFP_KERNEL); 77 i2c_dev = kzalloc(sizeof(*i2c_dev), GFP_KERNEL);
80 if (!i2c_dev) 78 if (!i2c_dev)
81 return ERR_PTR(-ENOMEM); 79 return ERR_PTR(-ENOMEM);
80 i2c_dev->adap = adap;
82 81
83 spin_lock(&i2c_dev_array_lock); 82 spin_lock(&i2c_dev_list_lock);
84 if (i2c_dev_array[adap->nr]) { 83 list_add_tail(&i2c_dev->list, &i2c_dev_list);
85 spin_unlock(&i2c_dev_array_lock); 84 spin_unlock(&i2c_dev_list_lock);
86 dev_err(&adap->dev, "i2c-dev already has a device assigned to this adapter\n");
87 goto error;
88 }
89 i2c_dev->minor = adap->nr;
90 i2c_dev_array[adap->nr] = i2c_dev;
91 spin_unlock(&i2c_dev_array_lock);
92 return i2c_dev; 85 return i2c_dev;
93error:
94 kfree(i2c_dev);
95 return ERR_PTR(-ENODEV);
96} 86}
97 87
98static void return_i2c_dev(struct i2c_dev *i2c_dev) 88static void return_i2c_dev(struct i2c_dev *i2c_dev)
99{ 89{
100 spin_lock(&i2c_dev_array_lock); 90 spin_lock(&i2c_dev_list_lock);
101 i2c_dev_array[i2c_dev->minor] = NULL; 91 list_del(&i2c_dev->list);
102 spin_unlock(&i2c_dev_array_lock); 92 spin_unlock(&i2c_dev_list_lock);
103} 93}
104 94
105static ssize_t show_adapter_name(struct class_device *class_dev, char *buf) 95static ssize_t show_adapter_name(struct class_device *class_dev, char *buf)
@@ -375,12 +365,13 @@ static int i2cdev_open(struct inode *inode, struct file *file)
375 if (!adap) 365 if (!adap)
376 return -ENODEV; 366 return -ENODEV;
377 367
378 client = kmalloc(sizeof(*client), GFP_KERNEL); 368 client = kzalloc(sizeof(*client), GFP_KERNEL);
379 if (!client) { 369 if (!client) {
380 i2c_put_adapter(adap); 370 i2c_put_adapter(adap);
381 return -ENOMEM; 371 return -ENOMEM;
382 } 372 }
383 memcpy(client, &i2cdev_client_template, sizeof(*client)); 373 snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr);
374 client->driver = &i2cdev_driver;
384 375
385 /* registered with adapter, passed as client to user */ 376 /* registered with adapter, passed as client to user */
386 client->adapter = adap; 377 client->adapter = adap;
@@ -415,41 +406,47 @@ static struct class *i2c_dev_class;
415static int i2cdev_attach_adapter(struct i2c_adapter *adap) 406static int i2cdev_attach_adapter(struct i2c_adapter *adap)
416{ 407{
417 struct i2c_dev *i2c_dev; 408 struct i2c_dev *i2c_dev;
418 struct device *dev; 409 int res;
419 410
420 i2c_dev = get_free_i2c_dev(adap); 411 i2c_dev = get_free_i2c_dev(adap);
421 if (IS_ERR(i2c_dev)) 412 if (IS_ERR(i2c_dev))
422 return PTR_ERR(i2c_dev); 413 return PTR_ERR(i2c_dev);
423 414
424 pr_debug("i2c-dev: adapter [%s] registered as minor %d\n",
425 adap->name, i2c_dev->minor);
426
427 /* register this i2c device with the driver core */ 415 /* register this i2c device with the driver core */
428 i2c_dev->adap = adap;
429 dev = &adap->dev;
430 i2c_dev->class_dev = class_device_create(i2c_dev_class, NULL, 416 i2c_dev->class_dev = class_device_create(i2c_dev_class, NULL,
431 MKDEV(I2C_MAJOR, i2c_dev->minor), 417 MKDEV(I2C_MAJOR, adap->nr),
432 dev, "i2c-%d", i2c_dev->minor); 418 &adap->dev, "i2c-%d",
433 if (!i2c_dev->class_dev) 419 adap->nr);
420 if (!i2c_dev->class_dev) {
421 res = -ENODEV;
434 goto error; 422 goto error;
435 class_device_create_file(i2c_dev->class_dev, &class_device_attr_name); 423 }
424 res = class_device_create_file(i2c_dev->class_dev, &class_device_attr_name);
425 if (res)
426 goto error_destroy;
427
428 pr_debug("i2c-dev: adapter [%s] registered as minor %d\n",
429 adap->name, adap->nr);
436 return 0; 430 return 0;
431error_destroy:
432 class_device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr));
437error: 433error:
438 return_i2c_dev(i2c_dev); 434 return_i2c_dev(i2c_dev);
439 kfree(i2c_dev); 435 kfree(i2c_dev);
440 return -ENODEV; 436 return res;
441} 437}
442 438
443static int i2cdev_detach_adapter(struct i2c_adapter *adap) 439static int i2cdev_detach_adapter(struct i2c_adapter *adap)
444{ 440{
445 struct i2c_dev *i2c_dev; 441 struct i2c_dev *i2c_dev;
446 442
447 i2c_dev = i2c_dev_get_by_adapter(adap); 443 i2c_dev = i2c_dev_get_by_minor(adap->nr);
448 if (!i2c_dev) 444 if (!i2c_dev) /* attach_adapter must have failed */
449 return -ENODEV; 445 return 0;
450 446
447 class_device_remove_file(i2c_dev->class_dev, &class_device_attr_name);
451 return_i2c_dev(i2c_dev); 448 return_i2c_dev(i2c_dev);
452 class_device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, i2c_dev->minor)); 449 class_device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr));
453 kfree(i2c_dev); 450 kfree(i2c_dev);
454 451
455 pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name); 452 pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name);
@@ -471,12 +468,6 @@ static struct i2c_driver i2cdev_driver = {
471 .detach_client = i2cdev_detach_client, 468 .detach_client = i2cdev_detach_client,
472}; 469};
473 470
474static struct i2c_client i2cdev_client_template = {
475 .name = "I2C /dev entry",
476 .addr = -1,
477 .driver = &i2cdev_driver,
478};
479
480static int __init i2c_dev_init(void) 471static int __init i2c_dev_init(void)
481{ 472{
482 int res; 473 int res;
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index b6fb167e20f6..abcabb295592 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -4,6 +4,8 @@
4# Andre Hedrick <andre@linux-ide.org> 4# Andre Hedrick <andre@linux-ide.org>
5# 5#
6 6
7if BLOCK
8
7menu "ATA/ATAPI/MFM/RLL support" 9menu "ATA/ATAPI/MFM/RLL support"
8 10
9config IDE 11config IDE
@@ -54,7 +56,7 @@ if IDE
54 56
55config IDE_MAX_HWIFS 57config IDE_MAX_HWIFS
56 int "Max IDE interfaces" 58 int "Max IDE interfaces"
57 depends on ALPHA || SUPERH || IA64 59 depends on ALPHA || SUPERH || IA64 || EMBEDDED
58 default 4 60 default 4
59 help 61 help
60 This is the maximum number of IDE hardware interfaces that will 62 This is the maximum number of IDE hardware interfaces that will
@@ -592,6 +594,12 @@ config BLK_DEV_HPT366
592 ide-probe at boot. It is reported to support DVD II drives, by the 594 ide-probe at boot. It is reported to support DVD II drives, by the
593 manufacturer. 595 manufacturer.
594 596
597config BLK_DEV_JMICRON
598 tristate "JMicron JMB36x support"
599 help
600 Basic support for the JMicron ATA controllers. For full support
601 use the libata drivers.
602
595config BLK_DEV_SC1200 603config BLK_DEV_SC1200
596 tristate "National SCx200 chipset support" 604 tristate "National SCx200 chipset support"
597 help 605 help
@@ -1082,3 +1090,5 @@ config BLK_DEV_HD
1082endif 1090endif
1083 1091
1084endmenu 1092endmenu
1093
1094endif
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 654d4cd09847..69bbb6206a00 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -372,7 +372,7 @@ static int cdrom_log_sense(ide_drive_t *drive, struct request *rq,
372{ 372{
373 int log = 0; 373 int log = 0;
374 374
375 if (!sense || !rq || (rq->flags & REQ_QUIET)) 375 if (!sense || !rq || (rq->cmd_flags & REQ_QUIET))
376 return 0; 376 return 0;
377 377
378 switch (sense->sense_key) { 378 switch (sense->sense_key) {
@@ -597,7 +597,7 @@ static void cdrom_prepare_request(ide_drive_t *drive, struct request *rq)
597 struct cdrom_info *cd = drive->driver_data; 597 struct cdrom_info *cd = drive->driver_data;
598 598
599 ide_init_drive_cmd(rq); 599 ide_init_drive_cmd(rq);
600 rq->flags = REQ_PC; 600 rq->cmd_type = REQ_TYPE_BLOCK_PC;
601 rq->rq_disk = cd->disk; 601 rq->rq_disk = cd->disk;
602} 602}
603 603
@@ -617,7 +617,7 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
617 rq->cmd[0] = GPCMD_REQUEST_SENSE; 617 rq->cmd[0] = GPCMD_REQUEST_SENSE;
618 rq->cmd[4] = rq->data_len = 18; 618 rq->cmd[4] = rq->data_len = 18;
619 619
620 rq->flags = REQ_SENSE; 620 rq->cmd_type = REQ_TYPE_SENSE;
621 621
622 /* NOTE! Save the failed command in "rq->buffer" */ 622 /* NOTE! Save the failed command in "rq->buffer" */
623 rq->buffer = (void *) failed_command; 623 rq->buffer = (void *) failed_command;
@@ -630,10 +630,10 @@ static void cdrom_end_request (ide_drive_t *drive, int uptodate)
630 struct request *rq = HWGROUP(drive)->rq; 630 struct request *rq = HWGROUP(drive)->rq;
631 int nsectors = rq->hard_cur_sectors; 631 int nsectors = rq->hard_cur_sectors;
632 632
633 if ((rq->flags & REQ_SENSE) && uptodate) { 633 if (blk_sense_request(rq) && uptodate) {
634 /* 634 /*
635 * For REQ_SENSE, "rq->buffer" points to the original failed 635 * For REQ_TYPE_SENSE, "rq->buffer" points to the original
636 * request 636 * failed request
637 */ 637 */
638 struct request *failed = (struct request *) rq->buffer; 638 struct request *failed = (struct request *) rq->buffer;
639 struct cdrom_info *info = drive->driver_data; 639 struct cdrom_info *info = drive->driver_data;
@@ -706,17 +706,17 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
706 return 1; 706 return 1;
707 } 707 }
708 708
709 if (rq->flags & REQ_SENSE) { 709 if (blk_sense_request(rq)) {
710 /* We got an error trying to get sense info 710 /* We got an error trying to get sense info
711 from the drive (probably while trying 711 from the drive (probably while trying
712 to recover from a former error). Just give up. */ 712 to recover from a former error). Just give up. */
713 713
714 rq->flags |= REQ_FAILED; 714 rq->cmd_flags |= REQ_FAILED;
715 cdrom_end_request(drive, 0); 715 cdrom_end_request(drive, 0);
716 ide_error(drive, "request sense failure", stat); 716 ide_error(drive, "request sense failure", stat);
717 return 1; 717 return 1;
718 718
719 } else if (rq->flags & (REQ_PC | REQ_BLOCK_PC)) { 719 } else if (blk_pc_request(rq)) {
720 /* All other functions, except for READ. */ 720 /* All other functions, except for READ. */
721 unsigned long flags; 721 unsigned long flags;
722 722
@@ -724,7 +724,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
724 * if we have an error, pass back CHECK_CONDITION as the 724 * if we have an error, pass back CHECK_CONDITION as the
725 * scsi status byte 725 * scsi status byte
726 */ 726 */
727 if ((rq->flags & REQ_BLOCK_PC) && !rq->errors) 727 if (!rq->errors)
728 rq->errors = SAM_STAT_CHECK_CONDITION; 728 rq->errors = SAM_STAT_CHECK_CONDITION;
729 729
730 /* Check for tray open. */ 730 /* Check for tray open. */
@@ -735,12 +735,12 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
735 cdrom_saw_media_change (drive); 735 cdrom_saw_media_change (drive);
736 /*printk("%s: media changed\n",drive->name);*/ 736 /*printk("%s: media changed\n",drive->name);*/
737 return 0; 737 return 0;
738 } else if (!(rq->flags & REQ_QUIET)) { 738 } else if (!(rq->cmd_flags & REQ_QUIET)) {
739 /* Otherwise, print an error. */ 739 /* Otherwise, print an error. */
740 ide_dump_status(drive, "packet command error", stat); 740 ide_dump_status(drive, "packet command error", stat);
741 } 741 }
742 742
743 rq->flags |= REQ_FAILED; 743 rq->cmd_flags |= REQ_FAILED;
744 744
745 /* 745 /*
746 * instead of playing games with moving completions around, 746 * instead of playing games with moving completions around,
@@ -881,7 +881,7 @@ static int cdrom_timer_expiry(ide_drive_t *drive)
881 wait = ATAPI_WAIT_PC; 881 wait = ATAPI_WAIT_PC;
882 break; 882 break;
883 default: 883 default:
884 if (!(rq->flags & REQ_QUIET)) 884 if (!(rq->cmd_flags & REQ_QUIET))
885 printk(KERN_INFO "ide-cd: cmd 0x%x timed out\n", rq->cmd[0]); 885 printk(KERN_INFO "ide-cd: cmd 0x%x timed out\n", rq->cmd[0]);
886 wait = 0; 886 wait = 0;
887 break; 887 break;
@@ -1124,7 +1124,7 @@ static ide_startstop_t cdrom_read_intr (ide_drive_t *drive)
1124 if (rq->current_nr_sectors > 0) { 1124 if (rq->current_nr_sectors > 0) {
1125 printk (KERN_ERR "%s: cdrom_read_intr: data underrun (%d blocks)\n", 1125 printk (KERN_ERR "%s: cdrom_read_intr: data underrun (%d blocks)\n",
1126 drive->name, rq->current_nr_sectors); 1126 drive->name, rq->current_nr_sectors);
1127 rq->flags |= REQ_FAILED; 1127 rq->cmd_flags |= REQ_FAILED;
1128 cdrom_end_request(drive, 0); 1128 cdrom_end_request(drive, 0);
1129 } else 1129 } else
1130 cdrom_end_request(drive, 1); 1130 cdrom_end_request(drive, 1);
@@ -1456,7 +1456,7 @@ static ide_startstop_t cdrom_pc_intr (ide_drive_t *drive)
1456 printk ("%s: cdrom_pc_intr: data underrun %d\n", 1456 printk ("%s: cdrom_pc_intr: data underrun %d\n",
1457 drive->name, pc->buflen); 1457 drive->name, pc->buflen);
1458 */ 1458 */
1459 rq->flags |= REQ_FAILED; 1459 rq->cmd_flags |= REQ_FAILED;
1460 cdrom_end_request(drive, 0); 1460 cdrom_end_request(drive, 0);
1461 } 1461 }
1462 return ide_stopped; 1462 return ide_stopped;
@@ -1509,7 +1509,7 @@ static ide_startstop_t cdrom_pc_intr (ide_drive_t *drive)
1509 rq->data += thislen; 1509 rq->data += thislen;
1510 rq->data_len -= thislen; 1510 rq->data_len -= thislen;
1511 1511
1512 if (rq->flags & REQ_SENSE) 1512 if (blk_sense_request(rq))
1513 rq->sense_len += thislen; 1513 rq->sense_len += thislen;
1514 } else { 1514 } else {
1515confused: 1515confused:
@@ -1517,7 +1517,7 @@ confused:
1517 "appears confused (ireason = 0x%02x). " 1517 "appears confused (ireason = 0x%02x). "
1518 "Trying to recover by ending request.\n", 1518 "Trying to recover by ending request.\n",
1519 drive->name, ireason); 1519 drive->name, ireason);
1520 rq->flags |= REQ_FAILED; 1520 rq->cmd_flags |= REQ_FAILED;
1521 cdrom_end_request(drive, 0); 1521 cdrom_end_request(drive, 0);
1522 return ide_stopped; 1522 return ide_stopped;
1523 } 1523 }
@@ -1546,7 +1546,7 @@ static ide_startstop_t cdrom_do_packet_command (ide_drive_t *drive)
1546 struct cdrom_info *info = drive->driver_data; 1546 struct cdrom_info *info = drive->driver_data;
1547 1547
1548 info->dma = 0; 1548 info->dma = 0;
1549 rq->flags &= ~REQ_FAILED; 1549 rq->cmd_flags &= ~REQ_FAILED;
1550 len = rq->data_len; 1550 len = rq->data_len;
1551 1551
1552 /* Start sending the command to the drive. */ 1552 /* Start sending the command to the drive. */
@@ -1558,7 +1558,7 @@ static int cdrom_queue_packet_command(ide_drive_t *drive, struct request *rq)
1558{ 1558{
1559 struct request_sense sense; 1559 struct request_sense sense;
1560 int retries = 10; 1560 int retries = 10;
1561 unsigned int flags = rq->flags; 1561 unsigned int flags = rq->cmd_flags;
1562 1562
1563 if (rq->sense == NULL) 1563 if (rq->sense == NULL)
1564 rq->sense = &sense; 1564 rq->sense = &sense;
@@ -1567,14 +1567,14 @@ static int cdrom_queue_packet_command(ide_drive_t *drive, struct request *rq)
1567 do { 1567 do {
1568 int error; 1568 int error;
1569 unsigned long time = jiffies; 1569 unsigned long time = jiffies;
1570 rq->flags = flags; 1570 rq->cmd_flags = flags;
1571 1571
1572 error = ide_do_drive_cmd(drive, rq, ide_wait); 1572 error = ide_do_drive_cmd(drive, rq, ide_wait);
1573 time = jiffies - time; 1573 time = jiffies - time;
1574 1574
1575 /* FIXME: we should probably abort/retry or something 1575 /* FIXME: we should probably abort/retry or something
1576 * in case of failure */ 1576 * in case of failure */
1577 if (rq->flags & REQ_FAILED) { 1577 if (rq->cmd_flags & REQ_FAILED) {
1578 /* The request failed. Retry if it was due to a unit 1578 /* The request failed. Retry if it was due to a unit
1579 attention status 1579 attention status
1580 (usually means media was changed). */ 1580 (usually means media was changed). */
@@ -1596,10 +1596,10 @@ static int cdrom_queue_packet_command(ide_drive_t *drive, struct request *rq)
1596 } 1596 }
1597 1597
1598 /* End of retry loop. */ 1598 /* End of retry loop. */
1599 } while ((rq->flags & REQ_FAILED) && retries >= 0); 1599 } while ((rq->cmd_flags & REQ_FAILED) && retries >= 0);
1600 1600
1601 /* Return an error if the command failed. */ 1601 /* Return an error if the command failed. */
1602 return (rq->flags & REQ_FAILED) ? -EIO : 0; 1602 return (rq->cmd_flags & REQ_FAILED) ? -EIO : 0;
1603} 1603}
1604 1604
1605/* 1605/*
@@ -1963,7 +1963,7 @@ static ide_startstop_t cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
1963{ 1963{
1964 struct cdrom_info *info = drive->driver_data; 1964 struct cdrom_info *info = drive->driver_data;
1965 1965
1966 rq->flags |= REQ_QUIET; 1966 rq->cmd_flags |= REQ_QUIET;
1967 1967
1968 info->dma = 0; 1968 info->dma = 0;
1969 1969
@@ -2023,11 +2023,11 @@ ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, sector_t block)
2023 } 2023 }
2024 info->last_block = block; 2024 info->last_block = block;
2025 return action; 2025 return action;
2026 } else if (rq->flags & (REQ_PC | REQ_SENSE)) { 2026 } else if (rq->cmd_type == REQ_TYPE_SENSE) {
2027 return cdrom_do_packet_command(drive); 2027 return cdrom_do_packet_command(drive);
2028 } else if (rq->flags & REQ_BLOCK_PC) { 2028 } else if (blk_pc_request(rq)) {
2029 return cdrom_do_block_pc(drive, rq); 2029 return cdrom_do_block_pc(drive, rq);
2030 } else if (rq->flags & REQ_SPECIAL) { 2030 } else if (blk_special_request(rq)) {
2031 /* 2031 /*
2032 * right now this can only be a reset... 2032 * right now this can only be a reset...
2033 */ 2033 */
@@ -2105,7 +2105,7 @@ static int cdrom_check_status(ide_drive_t *drive, struct request_sense *sense)
2105 2105
2106 req.sense = sense; 2106 req.sense = sense;
2107 req.cmd[0] = GPCMD_TEST_UNIT_READY; 2107 req.cmd[0] = GPCMD_TEST_UNIT_READY;
2108 req.flags |= REQ_QUIET; 2108 req.cmd_flags |= REQ_QUIET;
2109 2109
2110#if ! STANDARD_ATAPI 2110#if ! STANDARD_ATAPI
2111 /* the Sanyo 3 CD changer uses byte 7 of TEST_UNIT_READY to 2111 /* the Sanyo 3 CD changer uses byte 7 of TEST_UNIT_READY to
@@ -2207,7 +2207,7 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
2207 req.cmd[0] = GPCMD_READ_CDVD_CAPACITY; 2207 req.cmd[0] = GPCMD_READ_CDVD_CAPACITY;
2208 req.data = (char *)&capbuf; 2208 req.data = (char *)&capbuf;
2209 req.data_len = sizeof(capbuf); 2209 req.data_len = sizeof(capbuf);
2210 req.flags |= REQ_QUIET; 2210 req.cmd_flags |= REQ_QUIET;
2211 2211
2212 stat = cdrom_queue_packet_command(drive, &req); 2212 stat = cdrom_queue_packet_command(drive, &req);
2213 if (stat == 0) { 2213 if (stat == 0) {
@@ -2230,7 +2230,7 @@ static int cdrom_read_tocentry(ide_drive_t *drive, int trackno, int msf_flag,
2230 req.sense = sense; 2230 req.sense = sense;
2231 req.data = buf; 2231 req.data = buf;
2232 req.data_len = buflen; 2232 req.data_len = buflen;
2233 req.flags |= REQ_QUIET; 2233 req.cmd_flags |= REQ_QUIET;
2234 req.cmd[0] = GPCMD_READ_TOC_PMA_ATIP; 2234 req.cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
2235 req.cmd[6] = trackno; 2235 req.cmd[6] = trackno;
2236 req.cmd[7] = (buflen >> 8); 2236 req.cmd[7] = (buflen >> 8);
@@ -2531,7 +2531,7 @@ static int ide_cdrom_packet(struct cdrom_device_info *cdi,
2531 req.timeout = cgc->timeout; 2531 req.timeout = cgc->timeout;
2532 2532
2533 if (cgc->quiet) 2533 if (cgc->quiet)
2534 req.flags |= REQ_QUIET; 2534 req.cmd_flags |= REQ_QUIET;
2535 2535
2536 req.sense = cgc->sense; 2536 req.sense = cgc->sense;
2537 cgc->stat = cdrom_queue_packet_command(drive, &req); 2537 cgc->stat = cdrom_queue_packet_command(drive, &req);
@@ -2629,7 +2629,8 @@ int ide_cdrom_reset (struct cdrom_device_info *cdi)
2629 int ret; 2629 int ret;
2630 2630
2631 cdrom_prepare_request(drive, &req); 2631 cdrom_prepare_request(drive, &req);
2632 req.flags = REQ_SPECIAL | REQ_QUIET; 2632 req.cmd_type = REQ_TYPE_SPECIAL;
2633 req.cmd_flags = REQ_QUIET;
2633 ret = ide_do_drive_cmd(drive, &req, ide_wait); 2634 ret = ide_do_drive_cmd(drive, &req, ide_wait);
2634 2635
2635 /* 2636 /*
@@ -3116,9 +3117,9 @@ static int ide_cdrom_prep_pc(struct request *rq)
3116 3117
3117static int ide_cdrom_prep_fn(request_queue_t *q, struct request *rq) 3118static int ide_cdrom_prep_fn(request_queue_t *q, struct request *rq)
3118{ 3119{
3119 if (rq->flags & REQ_CMD) 3120 if (blk_fs_request(rq))
3120 return ide_cdrom_prep_fs(q, rq); 3121 return ide_cdrom_prep_fs(q, rq);
3121 else if (rq->flags & REQ_BLOCK_PC) 3122 else if (blk_pc_request(rq))
3122 return ide_cdrom_prep_pc(rq); 3123 return ide_cdrom_prep_pc(rq);
3123 3124
3124 return 0; 3125 return 0;
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 7cf3eb023521..0a05a377d66a 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -699,7 +699,8 @@ static void idedisk_prepare_flush(request_queue_t *q, struct request *rq)
699 rq->cmd[0] = WIN_FLUSH_CACHE; 699 rq->cmd[0] = WIN_FLUSH_CACHE;
700 700
701 701
702 rq->flags |= REQ_DRIVE_TASK; 702 rq->cmd_type = REQ_TYPE_ATA_TASK;
703 rq->cmd_flags |= REQ_SOFTBARRIER;
703 rq->buffer = rq->cmd; 704 rq->buffer = rq->cmd;
704} 705}
705 706
@@ -740,7 +741,7 @@ static int set_multcount(ide_drive_t *drive, int arg)
740 if (drive->special.b.set_multmode) 741 if (drive->special.b.set_multmode)
741 return -EBUSY; 742 return -EBUSY;
742 ide_init_drive_cmd (&rq); 743 ide_init_drive_cmd (&rq);
743 rq.flags = REQ_DRIVE_CMD; 744 rq.cmd_type = REQ_TYPE_ATA_CMD;
744 drive->mult_req = arg; 745 drive->mult_req = arg;
745 drive->special.b.set_multmode = 1; 746 drive->special.b.set_multmode = 1;
746 (void) ide_do_drive_cmd (drive, &rq, ide_wait); 747 (void) ide_do_drive_cmd (drive, &rq, ide_wait);
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index 7c3a13e1cf64..56efed6742d4 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -145,14 +145,12 @@ int ide_in_drive_list(struct hd_driveid *id, const struct drive_list_entry *driv
145{ 145{
146 for ( ; drive_table->id_model ; drive_table++) 146 for ( ; drive_table->id_model ; drive_table++)
147 if ((!strcmp(drive_table->id_model, id->model)) && 147 if ((!strcmp(drive_table->id_model, id->model)) &&
148 ((strstr(drive_table->id_firmware, id->fw_rev)) || 148 ((strstr(id->fw_rev, drive_table->id_firmware)) ||
149 (!strcmp(drive_table->id_firmware, "ALL")))) 149 (!strcmp(drive_table->id_firmware, "ALL"))))
150 return 1; 150 return 1;
151 return 0; 151 return 0;
152} 152}
153 153
154EXPORT_SYMBOL_GPL(ide_in_drive_list);
155
156/** 154/**
157 * ide_dma_intr - IDE DMA interrupt handler 155 * ide_dma_intr - IDE DMA interrupt handler
158 * @drive: the drive the interrupt is for 156 * @drive: the drive the interrupt is for
@@ -205,7 +203,7 @@ int ide_build_sglist(ide_drive_t *drive, struct request *rq)
205 ide_hwif_t *hwif = HWIF(drive); 203 ide_hwif_t *hwif = HWIF(drive);
206 struct scatterlist *sg = hwif->sg_table; 204 struct scatterlist *sg = hwif->sg_table;
207 205
208 BUG_ON((rq->flags & REQ_DRIVE_TASKFILE) && rq->nr_sectors > 256); 206 BUG_ON((rq->cmd_type == REQ_TYPE_ATA_TASKFILE) && rq->nr_sectors > 256);
209 207
210 ide_map_sg(drive, rq); 208 ide_map_sg(drive, rq);
211 209
@@ -798,26 +796,23 @@ static int ide_release_dma_engine(ide_hwif_t *hwif)
798 796
799static int ide_release_iomio_dma(ide_hwif_t *hwif) 797static int ide_release_iomio_dma(ide_hwif_t *hwif)
800{ 798{
801 if ((hwif->dma_extra) && (hwif->channel == 0))
802 release_region((hwif->dma_base + 16), hwif->dma_extra);
803 release_region(hwif->dma_base, 8); 799 release_region(hwif->dma_base, 8);
804 if (hwif->dma_base2) 800 if (hwif->extra_ports)
805 release_region(hwif->dma_base, 8); 801 release_region(hwif->extra_base, hwif->extra_ports);
806 return 1; 802 return 1;
807} 803}
808 804
809/* 805/*
810 * Needed for allowing full modular support of ide-driver 806 * Needed for allowing full modular support of ide-driver
811 */ 807 */
812int ide_release_dma (ide_hwif_t *hwif) 808int ide_release_dma(ide_hwif_t *hwif)
813{ 809{
810 ide_release_dma_engine(hwif);
811
814 if (hwif->mmio == 2) 812 if (hwif->mmio == 2)
815 return 1; 813 return 1;
816 if (hwif->chipset == ide_etrax100) 814 else
817 return 1; 815 return ide_release_iomio_dma(hwif);
818
819 ide_release_dma_engine(hwif);
820 return ide_release_iomio_dma(hwif);
821} 816}
822 817
823static int ide_allocate_dma_engine(ide_hwif_t *hwif) 818static int ide_allocate_dma_engine(ide_hwif_t *hwif)
@@ -829,10 +824,9 @@ static int ide_allocate_dma_engine(ide_hwif_t *hwif)
829 if (hwif->dmatable_cpu) 824 if (hwif->dmatable_cpu)
830 return 0; 825 return 0;
831 826
832 printk(KERN_ERR "%s: -- Error, unable to allocate%s DMA table(s).\n", 827 printk(KERN_ERR "%s: -- Error, unable to allocate DMA table.\n",
833 hwif->cds->name, !hwif->dmatable_cpu ? " CPU" : ""); 828 hwif->cds->name);
834 829
835 ide_release_dma_engine(hwif);
836 return 1; 830 return 1;
837} 831}
838 832
@@ -840,9 +834,7 @@ static int ide_mapped_mmio_dma(ide_hwif_t *hwif, unsigned long base, unsigned in
840{ 834{
841 printk(KERN_INFO " %s: MMIO-DMA ", hwif->name); 835 printk(KERN_INFO " %s: MMIO-DMA ", hwif->name);
842 836
843 hwif->dma_base = base; 837 hwif->dma_base = base;
844 if (hwif->cds->extra && hwif->channel == 0)
845 hwif->dma_extra = hwif->cds->extra;
846 838
847 if(hwif->mate) 839 if(hwif->mate)
848 hwif->dma_master = (hwif->channel) ? hwif->mate->dma_base : base; 840 hwif->dma_master = (hwif->channel) ? hwif->mate->dma_base : base;
@@ -854,29 +846,33 @@ static int ide_mapped_mmio_dma(ide_hwif_t *hwif, unsigned long base, unsigned in
854static int ide_iomio_dma(ide_hwif_t *hwif, unsigned long base, unsigned int ports) 846static int ide_iomio_dma(ide_hwif_t *hwif, unsigned long base, unsigned int ports)
855{ 847{
856 printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx", 848 printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx",
857 hwif->name, base, base + ports - 1); 849 hwif->name, base, base + ports - 1);
850
858 if (!request_region(base, ports, hwif->name)) { 851 if (!request_region(base, ports, hwif->name)) {
859 printk(" -- Error, ports in use.\n"); 852 printk(" -- Error, ports in use.\n");
860 return 1; 853 return 1;
861 } 854 }
855
862 hwif->dma_base = base; 856 hwif->dma_base = base;
863 if ((hwif->cds->extra) && (hwif->channel == 0)) { 857
864 request_region(base+16, hwif->cds->extra, hwif->cds->name); 858 if (hwif->cds->extra) {
865 hwif->dma_extra = hwif->cds->extra; 859 hwif->extra_base = base + (hwif->channel ? 8 : 16);
860
861 if (!hwif->mate || !hwif->mate->extra_ports) {
862 if (!request_region(hwif->extra_base,
863 hwif->cds->extra, hwif->cds->name)) {
864 printk(" -- Error, extra ports in use.\n");
865 release_region(base, ports);
866 return 1;
867 }
868 hwif->extra_ports = hwif->cds->extra;
869 }
866 } 870 }
867 871
868 if(hwif->mate) 872 if(hwif->mate)
869 hwif->dma_master = (hwif->channel) ? hwif->mate->dma_base : base; 873 hwif->dma_master = (hwif->channel) ? hwif->mate->dma_base:base;
870 else 874 else
871 hwif->dma_master = base; 875 hwif->dma_master = base;
872 if (hwif->dma_base2) {
873 if (!request_region(hwif->dma_base2, ports, hwif->name))
874 {
875 printk(" -- Error, secondary ports in use.\n");
876 release_region(base, ports);
877 return 1;
878 }
879 }
880 return 0; 876 return 0;
881} 877}
882 878
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index adbe9f76a505..8ccee9c769f8 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -588,7 +588,7 @@ static int idefloppy_do_end_request(ide_drive_t *drive, int uptodate, int nsecs)
588 /* Why does this happen? */ 588 /* Why does this happen? */
589 if (!rq) 589 if (!rq)
590 return 0; 590 return 0;
591 if (!(rq->flags & REQ_SPECIAL)) { //if (!IDEFLOPPY_RQ_CMD (rq->cmd)) { 591 if (!blk_special_request(rq)) {
592 /* our real local end request function */ 592 /* our real local end request function */
593 ide_end_request(drive, uptodate, nsecs); 593 ide_end_request(drive, uptodate, nsecs);
594 return 0; 594 return 0;
@@ -689,7 +689,7 @@ static void idefloppy_queue_pc_head (ide_drive_t *drive,idefloppy_pc_t *pc,struc
689 689
690 ide_init_drive_cmd(rq); 690 ide_init_drive_cmd(rq);
691 rq->buffer = (char *) pc; 691 rq->buffer = (char *) pc;
692 rq->flags = REQ_SPECIAL; //rq->cmd = IDEFLOPPY_PC_RQ; 692 rq->cmd_type = REQ_TYPE_SPECIAL;
693 rq->rq_disk = floppy->disk; 693 rq->rq_disk = floppy->disk;
694 (void) ide_do_drive_cmd(drive, rq, ide_preempt); 694 (void) ide_do_drive_cmd(drive, rq, ide_preempt);
695} 695}
@@ -1250,7 +1250,7 @@ static void idefloppy_create_rw_cmd (idefloppy_floppy_t *floppy, idefloppy_pc_t
1250 pc->callback = &idefloppy_rw_callback; 1250 pc->callback = &idefloppy_rw_callback;
1251 pc->rq = rq; 1251 pc->rq = rq;
1252 pc->b_count = cmd == READ ? 0 : rq->bio->bi_size; 1252 pc->b_count = cmd == READ ? 0 : rq->bio->bi_size;
1253 if (rq->flags & REQ_RW) 1253 if (rq->cmd_flags & REQ_RW)
1254 set_bit(PC_WRITING, &pc->flags); 1254 set_bit(PC_WRITING, &pc->flags);
1255 pc->buffer = NULL; 1255 pc->buffer = NULL;
1256 pc->request_transfer = pc->buffer_size = blocks * floppy->block_size; 1256 pc->request_transfer = pc->buffer_size = blocks * floppy->block_size;
@@ -1281,8 +1281,7 @@ static ide_startstop_t idefloppy_do_request (ide_drive_t *drive, struct request
1281 idefloppy_pc_t *pc; 1281 idefloppy_pc_t *pc;
1282 unsigned long block = (unsigned long)block_s; 1282 unsigned long block = (unsigned long)block_s;
1283 1283
1284 debug_log(KERN_INFO "rq_status: %d, dev: %s, flags: %lx, errors: %d\n", 1284 debug_log(KERN_INFO "dev: %s, flags: %lx, errors: %d\n",
1285 rq->rq_status,
1286 rq->rq_disk ? rq->rq_disk->disk_name : "?", 1285 rq->rq_disk ? rq->rq_disk->disk_name : "?",
1287 rq->flags, rq->errors); 1286 rq->flags, rq->errors);
1288 debug_log(KERN_INFO "sector: %ld, nr_sectors: %ld, " 1287 debug_log(KERN_INFO "sector: %ld, nr_sectors: %ld, "
@@ -1303,7 +1302,7 @@ static ide_startstop_t idefloppy_do_request (ide_drive_t *drive, struct request
1303 idefloppy_do_end_request(drive, 0, 0); 1302 idefloppy_do_end_request(drive, 0, 0);
1304 return ide_stopped; 1303 return ide_stopped;
1305 } 1304 }
1306 if (rq->flags & REQ_CMD) { 1305 if (blk_fs_request(rq)) {
1307 if (((long)rq->sector % floppy->bs_factor) || 1306 if (((long)rq->sector % floppy->bs_factor) ||
1308 (rq->nr_sectors % floppy->bs_factor)) { 1307 (rq->nr_sectors % floppy->bs_factor)) {
1309 printk("%s: unsupported r/w request size\n", 1308 printk("%s: unsupported r/w request size\n",
@@ -1313,9 +1312,9 @@ static ide_startstop_t idefloppy_do_request (ide_drive_t *drive, struct request
1313 } 1312 }
1314 pc = idefloppy_next_pc_storage(drive); 1313 pc = idefloppy_next_pc_storage(drive);
1315 idefloppy_create_rw_cmd(floppy, pc, rq, block); 1314 idefloppy_create_rw_cmd(floppy, pc, rq, block);
1316 } else if (rq->flags & REQ_SPECIAL) { 1315 } else if (blk_special_request(rq)) {
1317 pc = (idefloppy_pc_t *) rq->buffer; 1316 pc = (idefloppy_pc_t *) rq->buffer;
1318 } else if (rq->flags & REQ_BLOCK_PC) { 1317 } else if (blk_pc_request(rq)) {
1319 pc = idefloppy_next_pc_storage(drive); 1318 pc = idefloppy_next_pc_storage(drive);
1320 if (idefloppy_blockpc_cmd(floppy, pc, rq)) { 1319 if (idefloppy_blockpc_cmd(floppy, pc, rq)) {
1321 idefloppy_do_end_request(drive, 0, 0); 1320 idefloppy_do_end_request(drive, 0, 0);
@@ -1343,7 +1342,7 @@ static int idefloppy_queue_pc_tail (ide_drive_t *drive,idefloppy_pc_t *pc)
1343 1342
1344 ide_init_drive_cmd (&rq); 1343 ide_init_drive_cmd (&rq);
1345 rq.buffer = (char *) pc; 1344 rq.buffer = (char *) pc;
1346 rq.flags = REQ_SPECIAL; // rq.cmd = IDEFLOPPY_PC_RQ; 1345 rq.cmd_type = REQ_TYPE_SPECIAL;
1347 rq.rq_disk = floppy->disk; 1346 rq.rq_disk = floppy->disk;
1348 1347
1349 return ide_do_drive_cmd(drive, &rq, ide_wait); 1348 return ide_do_drive_cmd(drive, &rq, ide_wait);
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index fb6795236e76..ba6039b55b41 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -59,8 +59,6 @@ static int __ide_end_request(ide_drive_t *drive, struct request *rq,
59{ 59{
60 int ret = 1; 60 int ret = 1;
61 61
62 BUG_ON(!(rq->flags & REQ_STARTED));
63
64 /* 62 /*
65 * if failfast is set on a request, override number of sectors and 63 * if failfast is set on a request, override number of sectors and
66 * complete the whole request right now 64 * complete the whole request right now
@@ -82,7 +80,8 @@ static int __ide_end_request(ide_drive_t *drive, struct request *rq,
82 80
83 if (!end_that_request_first(rq, uptodate, nr_sectors)) { 81 if (!end_that_request_first(rq, uptodate, nr_sectors)) {
84 add_disk_randomness(rq->rq_disk); 82 add_disk_randomness(rq->rq_disk);
85 blkdev_dequeue_request(rq); 83 if (!list_empty(&rq->queuelist))
84 blkdev_dequeue_request(rq);
86 HWGROUP(drive)->rq = NULL; 85 HWGROUP(drive)->rq = NULL;
87 end_that_request_last(rq, uptodate); 86 end_that_request_last(rq, uptodate);
88 ret = 0; 87 ret = 0;
@@ -135,13 +134,14 @@ enum {
135 ide_pm_flush_cache = ide_pm_state_start_suspend, 134 ide_pm_flush_cache = ide_pm_state_start_suspend,
136 idedisk_pm_standby, 135 idedisk_pm_standby,
137 136
138 idedisk_pm_idle = ide_pm_state_start_resume, 137 idedisk_pm_restore_pio = ide_pm_state_start_resume,
138 idedisk_pm_idle,
139 ide_pm_restore_dma, 139 ide_pm_restore_dma,
140}; 140};
141 141
142static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 stat, u8 error) 142static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 stat, u8 error)
143{ 143{
144 struct request_pm_state *pm = rq->end_io_data; 144 struct request_pm_state *pm = rq->data;
145 145
146 if (drive->media != ide_disk) 146 if (drive->media != ide_disk)
147 return; 147 return;
@@ -156,7 +156,10 @@ static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 s
156 case idedisk_pm_standby: /* Suspend step 2 (standby) complete */ 156 case idedisk_pm_standby: /* Suspend step 2 (standby) complete */
157 pm->pm_step = ide_pm_state_completed; 157 pm->pm_step = ide_pm_state_completed;
158 break; 158 break;
159 case idedisk_pm_idle: /* Resume step 1 (idle) complete */ 159 case idedisk_pm_restore_pio: /* Resume step 1 complete */
160 pm->pm_step = idedisk_pm_idle;
161 break;
162 case idedisk_pm_idle: /* Resume step 2 (idle) complete */
160 pm->pm_step = ide_pm_restore_dma; 163 pm->pm_step = ide_pm_restore_dma;
161 break; 164 break;
162 } 165 }
@@ -164,14 +167,17 @@ static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 s
164 167
165static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq) 168static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
166{ 169{
167 struct request_pm_state *pm = rq->end_io_data; 170 struct request_pm_state *pm = rq->data;
168 ide_task_t *args = rq->special; 171 ide_task_t *args = rq->special;
169 172
170 memset(args, 0, sizeof(*args)); 173 memset(args, 0, sizeof(*args));
171 174
172 if (drive->media != ide_disk) { 175 if (drive->media != ide_disk) {
173 /* skip idedisk_pm_idle for ATAPI devices */ 176 /*
174 if (pm->pm_step == idedisk_pm_idle) 177 * skip idedisk_pm_restore_pio and idedisk_pm_idle for ATAPI
178 * devices
179 */
180 if (pm->pm_step == idedisk_pm_restore_pio)
175 pm->pm_step = ide_pm_restore_dma; 181 pm->pm_step = ide_pm_restore_dma;
176 } 182 }
177 183
@@ -198,13 +204,19 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
198 args->handler = &task_no_data_intr; 204 args->handler = &task_no_data_intr;
199 return do_rw_taskfile(drive, args); 205 return do_rw_taskfile(drive, args);
200 206
201 case idedisk_pm_idle: /* Resume step 1 (idle) */ 207 case idedisk_pm_restore_pio: /* Resume step 1 (restore PIO) */
208 if (drive->hwif->tuneproc != NULL)
209 drive->hwif->tuneproc(drive, 255);
210 ide_complete_power_step(drive, rq, 0, 0);
211 return ide_stopped;
212
213 case idedisk_pm_idle: /* Resume step 2 (idle) */
202 args->tfRegister[IDE_COMMAND_OFFSET] = WIN_IDLEIMMEDIATE; 214 args->tfRegister[IDE_COMMAND_OFFSET] = WIN_IDLEIMMEDIATE;
203 args->command_type = IDE_DRIVE_TASK_NO_DATA; 215 args->command_type = IDE_DRIVE_TASK_NO_DATA;
204 args->handler = task_no_data_intr; 216 args->handler = task_no_data_intr;
205 return do_rw_taskfile(drive, args); 217 return do_rw_taskfile(drive, args);
206 218
207 case ide_pm_restore_dma: /* Resume step 2 (restore DMA) */ 219 case ide_pm_restore_dma: /* Resume step 3 (restore DMA) */
208 /* 220 /*
209 * Right now, all we do is call hwif->ide_dma_check(drive), 221 * Right now, all we do is call hwif->ide_dma_check(drive),
210 * we could be smarter and check for current xfer_speed 222 * we could be smarter and check for current xfer_speed
@@ -244,7 +256,7 @@ int ide_end_dequeued_request(ide_drive_t *drive, struct request *rq,
244 256
245 spin_lock_irqsave(&ide_lock, flags); 257 spin_lock_irqsave(&ide_lock, flags);
246 258
247 BUG_ON(!(rq->flags & REQ_STARTED)); 259 BUG_ON(!blk_rq_started(rq));
248 260
249 /* 261 /*
250 * if failfast is set on a request, override number of sectors and 262 * if failfast is set on a request, override number of sectors and
@@ -366,7 +378,7 @@ void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
366 rq = HWGROUP(drive)->rq; 378 rq = HWGROUP(drive)->rq;
367 spin_unlock_irqrestore(&ide_lock, flags); 379 spin_unlock_irqrestore(&ide_lock, flags);
368 380
369 if (rq->flags & REQ_DRIVE_CMD) { 381 if (rq->cmd_type == REQ_TYPE_ATA_CMD) {
370 u8 *args = (u8 *) rq->buffer; 382 u8 *args = (u8 *) rq->buffer;
371 if (rq->errors == 0) 383 if (rq->errors == 0)
372 rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT); 384 rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT);
@@ -376,7 +388,7 @@ void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
376 args[1] = err; 388 args[1] = err;
377 args[2] = hwif->INB(IDE_NSECTOR_REG); 389 args[2] = hwif->INB(IDE_NSECTOR_REG);
378 } 390 }
379 } else if (rq->flags & REQ_DRIVE_TASK) { 391 } else if (rq->cmd_type == REQ_TYPE_ATA_TASK) {
380 u8 *args = (u8 *) rq->buffer; 392 u8 *args = (u8 *) rq->buffer;
381 if (rq->errors == 0) 393 if (rq->errors == 0)
382 rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT); 394 rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT);
@@ -390,7 +402,7 @@ void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
390 args[5] = hwif->INB(IDE_HCYL_REG); 402 args[5] = hwif->INB(IDE_HCYL_REG);
391 args[6] = hwif->INB(IDE_SELECT_REG); 403 args[6] = hwif->INB(IDE_SELECT_REG);
392 } 404 }
393 } else if (rq->flags & REQ_DRIVE_TASKFILE) { 405 } else if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
394 ide_task_t *args = (ide_task_t *) rq->special; 406 ide_task_t *args = (ide_task_t *) rq->special;
395 if (rq->errors == 0) 407 if (rq->errors == 0)
396 rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT); 408 rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT);
@@ -421,7 +433,7 @@ void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
421 } 433 }
422 } 434 }
423 } else if (blk_pm_request(rq)) { 435 } else if (blk_pm_request(rq)) {
424 struct request_pm_state *pm = rq->end_io_data; 436 struct request_pm_state *pm = rq->data;
425#ifdef DEBUG_PM 437#ifdef DEBUG_PM
426 printk("%s: complete_power_step(step: %d, stat: %x, err: %x)\n", 438 printk("%s: complete_power_step(step: %d, stat: %x, err: %x)\n",
427 drive->name, rq->pm->pm_step, stat, err); 439 drive->name, rq->pm->pm_step, stat, err);
@@ -587,7 +599,7 @@ ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, u8 stat)
587 return ide_stopped; 599 return ide_stopped;
588 600
589 /* retry only "normal" I/O: */ 601 /* retry only "normal" I/O: */
590 if (rq->flags & (REQ_DRIVE_CMD | REQ_DRIVE_TASK | REQ_DRIVE_TASKFILE)) { 602 if (!blk_fs_request(rq)) {
591 rq->errors = 1; 603 rq->errors = 1;
592 ide_end_drive_cmd(drive, stat, err); 604 ide_end_drive_cmd(drive, stat, err);
593 return ide_stopped; 605 return ide_stopped;
@@ -638,7 +650,7 @@ ide_startstop_t ide_abort(ide_drive_t *drive, const char *msg)
638 return ide_stopped; 650 return ide_stopped;
639 651
640 /* retry only "normal" I/O: */ 652 /* retry only "normal" I/O: */
641 if (rq->flags & (REQ_DRIVE_CMD | REQ_DRIVE_TASK | REQ_DRIVE_TASKFILE)) { 653 if (!blk_fs_request(rq)) {
642 rq->errors = 1; 654 rq->errors = 1;
643 ide_end_drive_cmd(drive, BUSY_STAT, 0); 655 ide_end_drive_cmd(drive, BUSY_STAT, 0);
644 return ide_stopped; 656 return ide_stopped;
@@ -808,7 +820,7 @@ void ide_map_sg(ide_drive_t *drive, struct request *rq)
808 if (hwif->sg_mapped) /* needed by ide-scsi */ 820 if (hwif->sg_mapped) /* needed by ide-scsi */
809 return; 821 return;
810 822
811 if ((rq->flags & REQ_DRIVE_TASKFILE) == 0) { 823 if (rq->cmd_type != REQ_TYPE_ATA_TASKFILE) {
812 hwif->sg_nents = blk_rq_map_sg(drive->queue, rq, sg); 824 hwif->sg_nents = blk_rq_map_sg(drive->queue, rq, sg);
813 } else { 825 } else {
814 sg_init_one(sg, rq->buffer, rq->nr_sectors * SECTOR_SIZE); 826 sg_init_one(sg, rq->buffer, rq->nr_sectors * SECTOR_SIZE);
@@ -844,7 +856,7 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
844 struct request *rq) 856 struct request *rq)
845{ 857{
846 ide_hwif_t *hwif = HWIF(drive); 858 ide_hwif_t *hwif = HWIF(drive);
847 if (rq->flags & REQ_DRIVE_TASKFILE) { 859 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
848 ide_task_t *args = rq->special; 860 ide_task_t *args = rq->special;
849 861
850 if (!args) 862 if (!args)
@@ -866,7 +878,7 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
866 if (args->tf_out_flags.all != 0) 878 if (args->tf_out_flags.all != 0)
867 return flagged_taskfile(drive, args); 879 return flagged_taskfile(drive, args);
868 return do_rw_taskfile(drive, args); 880 return do_rw_taskfile(drive, args);
869 } else if (rq->flags & REQ_DRIVE_TASK) { 881 } else if (rq->cmd_type == REQ_TYPE_ATA_TASK) {
870 u8 *args = rq->buffer; 882 u8 *args = rq->buffer;
871 u8 sel; 883 u8 sel;
872 884
@@ -892,7 +904,7 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
892 hwif->OUTB(sel, IDE_SELECT_REG); 904 hwif->OUTB(sel, IDE_SELECT_REG);
893 ide_cmd(drive, args[0], args[2], &drive_cmd_intr); 905 ide_cmd(drive, args[0], args[2], &drive_cmd_intr);
894 return ide_started; 906 return ide_started;
895 } else if (rq->flags & REQ_DRIVE_CMD) { 907 } else if (rq->cmd_type == REQ_TYPE_ATA_CMD) {
896 u8 *args = rq->buffer; 908 u8 *args = rq->buffer;
897 909
898 if (!args) 910 if (!args)
@@ -933,7 +945,7 @@ done:
933 945
934static void ide_check_pm_state(ide_drive_t *drive, struct request *rq) 946static void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
935{ 947{
936 struct request_pm_state *pm = rq->end_io_data; 948 struct request_pm_state *pm = rq->data;
937 949
938 if (blk_pm_suspend_request(rq) && 950 if (blk_pm_suspend_request(rq) &&
939 pm->pm_step == ide_pm_state_start_suspend) 951 pm->pm_step == ide_pm_state_start_suspend)
@@ -980,7 +992,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
980 ide_startstop_t startstop; 992 ide_startstop_t startstop;
981 sector_t block; 993 sector_t block;
982 994
983 BUG_ON(!(rq->flags & REQ_STARTED)); 995 BUG_ON(!blk_rq_started(rq));
984 996
985#ifdef DEBUG 997#ifdef DEBUG
986 printk("%s: start_request: current=0x%08lx\n", 998 printk("%s: start_request: current=0x%08lx\n",
@@ -1013,12 +1025,12 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
1013 if (!drive->special.all) { 1025 if (!drive->special.all) {
1014 ide_driver_t *drv; 1026 ide_driver_t *drv;
1015 1027
1016 if (rq->flags & (REQ_DRIVE_CMD | REQ_DRIVE_TASK)) 1028 if (rq->cmd_type == REQ_TYPE_ATA_CMD ||
1017 return execute_drive_cmd(drive, rq); 1029 rq->cmd_type == REQ_TYPE_ATA_TASK ||
1018 else if (rq->flags & REQ_DRIVE_TASKFILE) 1030 rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
1019 return execute_drive_cmd(drive, rq); 1031 return execute_drive_cmd(drive, rq);
1020 else if (blk_pm_request(rq)) { 1032 else if (blk_pm_request(rq)) {
1021 struct request_pm_state *pm = rq->end_io_data; 1033 struct request_pm_state *pm = rq->data;
1022#ifdef DEBUG_PM 1034#ifdef DEBUG_PM
1023 printk("%s: start_power_step(step: %d)\n", 1035 printk("%s: start_power_step(step: %d)\n",
1024 drive->name, rq->pm->pm_step); 1036 drive->name, rq->pm->pm_step);
@@ -1264,7 +1276,7 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
1264 * We count how many times we loop here to make sure we service 1276 * We count how many times we loop here to make sure we service
1265 * all drives in the hwgroup without looping for ever 1277 * all drives in the hwgroup without looping for ever
1266 */ 1278 */
1267 if (drive->blocked && !blk_pm_request(rq) && !(rq->flags & REQ_PREEMPT)) { 1279 if (drive->blocked && !blk_pm_request(rq) && !(rq->cmd_flags & REQ_PREEMPT)) {
1268 drive = drive->next ? drive->next : hwgroup->drive; 1280 drive = drive->next ? drive->next : hwgroup->drive;
1269 if (loops++ < 4 && !blk_queue_plugged(drive->queue)) 1281 if (loops++ < 4 && !blk_queue_plugged(drive->queue))
1270 goto again; 1282 goto again;
@@ -1346,6 +1358,10 @@ static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
1346 * make sure request is sane 1358 * make sure request is sane
1347 */ 1359 */
1348 rq = HWGROUP(drive)->rq; 1360 rq = HWGROUP(drive)->rq;
1361
1362 if (!rq)
1363 goto out;
1364
1349 HWGROUP(drive)->rq = NULL; 1365 HWGROUP(drive)->rq = NULL;
1350 1366
1351 rq->errors = 0; 1367 rq->errors = 0;
@@ -1670,7 +1686,7 @@ irqreturn_t ide_intr (int irq, void *dev_id, struct pt_regs *regs)
1670void ide_init_drive_cmd (struct request *rq) 1686void ide_init_drive_cmd (struct request *rq)
1671{ 1687{
1672 memset(rq, 0, sizeof(*rq)); 1688 memset(rq, 0, sizeof(*rq));
1673 rq->flags = REQ_DRIVE_CMD; 1689 rq->cmd_type = REQ_TYPE_ATA_CMD;
1674 rq->ref_count = 1; 1690 rq->ref_count = 1;
1675} 1691}
1676 1692
@@ -1710,7 +1726,6 @@ int ide_do_drive_cmd (ide_drive_t *drive, struct request *rq, ide_action_t actio
1710 int must_wait = (action == ide_wait || action == ide_head_wait); 1726 int must_wait = (action == ide_wait || action == ide_head_wait);
1711 1727
1712 rq->errors = 0; 1728 rq->errors = 0;
1713 rq->rq_status = RQ_ACTIVE;
1714 1729
1715 /* 1730 /*
1716 * we need to hold an extra reference to request for safe inspection 1731 * we need to hold an extra reference to request for safe inspection
@@ -1718,7 +1733,7 @@ int ide_do_drive_cmd (ide_drive_t *drive, struct request *rq, ide_action_t actio
1718 */ 1733 */
1719 if (must_wait) { 1734 if (must_wait) {
1720 rq->ref_count++; 1735 rq->ref_count++;
1721 rq->waiting = &wait; 1736 rq->end_io_data = &wait;
1722 rq->end_io = blk_end_sync_rq; 1737 rq->end_io = blk_end_sync_rq;
1723 } 1738 }
1724 1739
@@ -1727,7 +1742,7 @@ int ide_do_drive_cmd (ide_drive_t *drive, struct request *rq, ide_action_t actio
1727 hwgroup->rq = NULL; 1742 hwgroup->rq = NULL;
1728 if (action == ide_preempt || action == ide_head_wait) { 1743 if (action == ide_preempt || action == ide_head_wait) {
1729 where = ELEVATOR_INSERT_FRONT; 1744 where = ELEVATOR_INSERT_FRONT;
1730 rq->flags |= REQ_PREEMPT; 1745 rq->cmd_flags |= REQ_PREEMPT;
1731 } 1746 }
1732 __elv_add_request(drive->queue, rq, where, 0); 1747 __elv_add_request(drive->queue, rq, where, 0);
1733 ide_do_request(hwgroup, IDE_NO_IRQ); 1748 ide_do_request(hwgroup, IDE_NO_IRQ);
@@ -1736,7 +1751,6 @@ int ide_do_drive_cmd (ide_drive_t *drive, struct request *rq, ide_action_t actio
1736 err = 0; 1751 err = 0;
1737 if (must_wait) { 1752 if (must_wait) {
1738 wait_for_completion(&wait); 1753 wait_for_completion(&wait);
1739 rq->waiting = NULL;
1740 if (rq->errors) 1754 if (rq->errors)
1741 err = -EIO; 1755 err = -EIO;
1742 1756
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index 77703acaec17..badde6331775 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -998,6 +998,7 @@ static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive)
998 } 998 }
999 /* done polling */ 999 /* done polling */
1000 hwgroup->polling = 0; 1000 hwgroup->polling = 0;
1001 hwgroup->resetting = 0;
1001 return ide_stopped; 1002 return ide_stopped;
1002} 1003}
1003 1004
@@ -1057,6 +1058,7 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive)
1057 } 1058 }
1058 } 1059 }
1059 hwgroup->polling = 0; /* done polling */ 1060 hwgroup->polling = 0; /* done polling */
1061 hwgroup->resetting = 0; /* done reset attempt */
1060 return ide_stopped; 1062 return ide_stopped;
1061} 1063}
1062 1064
@@ -1143,6 +1145,7 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1143 1145
1144 /* For an ATAPI device, first try an ATAPI SRST. */ 1146 /* For an ATAPI device, first try an ATAPI SRST. */
1145 if (drive->media != ide_disk && !do_not_try_atapi) { 1147 if (drive->media != ide_disk && !do_not_try_atapi) {
1148 hwgroup->resetting = 1;
1146 pre_reset(drive); 1149 pre_reset(drive);
1147 SELECT_DRIVE(drive); 1150 SELECT_DRIVE(drive);
1148 udelay (20); 1151 udelay (20);
@@ -1168,6 +1171,7 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1168 return ide_stopped; 1171 return ide_stopped;
1169 } 1172 }
1170 1173
1174 hwgroup->resetting = 1;
1171 /* 1175 /*
1172 * Note that we also set nIEN while resetting the device, 1176 * Note that we also set nIEN while resetting the device,
1173 * to mask unwanted interrupts from the interface during the reset. 1177 * to mask unwanted interrupts from the interface during the reset.
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index 1feff23487d4..8237d89eec6e 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -71,75 +71,96 @@ EXPORT_SYMBOL(ide_xfer_verbose);
71/** 71/**
72 * ide_dma_speed - compute DMA speed 72 * ide_dma_speed - compute DMA speed
73 * @drive: drive 73 * @drive: drive
74 * @mode; intended mode 74 * @mode: modes available
75 * 75 *
76 * Checks the drive capabilities and returns the speed to use 76 * Checks the drive capabilities and returns the speed to use
77 * for the transfer. Returns -1 if the requested mode is unknown 77 * for the DMA transfer. Returns 0 if the drive is incapable
78 * (eg PIO) 78 * of DMA transfers.
79 */ 79 */
80 80
81u8 ide_dma_speed(ide_drive_t *drive, u8 mode) 81u8 ide_dma_speed(ide_drive_t *drive, u8 mode)
82{ 82{
83 struct hd_driveid *id = drive->id; 83 struct hd_driveid *id = drive->id;
84 ide_hwif_t *hwif = HWIF(drive); 84 ide_hwif_t *hwif = HWIF(drive);
85 u8 ultra_mask, mwdma_mask, swdma_mask;
85 u8 speed = 0; 86 u8 speed = 0;
86 87
87 if (drive->media != ide_disk && hwif->atapi_dma == 0) 88 if (drive->media != ide_disk && hwif->atapi_dma == 0)
88 return 0; 89 return 0;
89 90
90 switch(mode) { 91 /* Capable of UltraDMA modes? */
91 case 0x04: 92 ultra_mask = id->dma_ultra & hwif->ultra_mask;
92 if ((id->dma_ultra & 0x0040) && 93
93 (id->dma_ultra & hwif->ultra_mask)) 94 if (!(id->field_valid & 4))
94 { speed = XFER_UDMA_6; break; } 95 mode = 0; /* fallback to MW/SW DMA if no UltraDMA */
95 case 0x03: 96
96 if ((id->dma_ultra & 0x0020) && 97 switch (mode) {
97 (id->dma_ultra & hwif->ultra_mask)) 98 case 4:
98 { speed = XFER_UDMA_5; break; } 99 if (ultra_mask & 0x40) {
99 case 0x02: 100 speed = XFER_UDMA_6;
100 if ((id->dma_ultra & 0x0010) && 101 break;
101 (id->dma_ultra & hwif->ultra_mask)) 102 }
102 { speed = XFER_UDMA_4; break; } 103 case 3:
103 if ((id->dma_ultra & 0x0008) && 104 if (ultra_mask & 0x20) {
104 (id->dma_ultra & hwif->ultra_mask)) 105 speed = XFER_UDMA_5;
105 { speed = XFER_UDMA_3; break; } 106 break;
106 case 0x01: 107 }
107 if ((id->dma_ultra & 0x0004) && 108 case 2:
108 (id->dma_ultra & hwif->ultra_mask)) 109 if (ultra_mask & 0x10) {
109 { speed = XFER_UDMA_2; break; } 110 speed = XFER_UDMA_4;
110 if ((id->dma_ultra & 0x0002) && 111 break;
111 (id->dma_ultra & hwif->ultra_mask)) 112 }
112 { speed = XFER_UDMA_1; break; } 113 if (ultra_mask & 0x08) {
113 if ((id->dma_ultra & 0x0001) && 114 speed = XFER_UDMA_3;
114 (id->dma_ultra & hwif->ultra_mask)) 115 break;
115 { speed = XFER_UDMA_0; break; } 116 }
116 case 0x00: 117 case 1:
117 if ((id->dma_mword & 0x0004) && 118 if (ultra_mask & 0x04) {
118 (id->dma_mword & hwif->mwdma_mask)) 119 speed = XFER_UDMA_2;
119 { speed = XFER_MW_DMA_2; break; } 120 break;
120 if ((id->dma_mword & 0x0002) && 121 }
121 (id->dma_mword & hwif->mwdma_mask)) 122 if (ultra_mask & 0x02) {
122 { speed = XFER_MW_DMA_1; break; } 123 speed = XFER_UDMA_1;
123 if ((id->dma_mword & 0x0001) && 124 break;
124 (id->dma_mword & hwif->mwdma_mask)) 125 }
125 { speed = XFER_MW_DMA_0; break; } 126 if (ultra_mask & 0x01) {
126 if ((id->dma_1word & 0x0004) && 127 speed = XFER_UDMA_0;
127 (id->dma_1word & hwif->swdma_mask)) 128 break;
128 { speed = XFER_SW_DMA_2; break; } 129 }
129 if ((id->dma_1word & 0x0002) && 130 case 0:
130 (id->dma_1word & hwif->swdma_mask)) 131 mwdma_mask = id->dma_mword & hwif->mwdma_mask;
131 { speed = XFER_SW_DMA_1; break; }
132 if ((id->dma_1word & 0x0001) &&
133 (id->dma_1word & hwif->swdma_mask))
134 { speed = XFER_SW_DMA_0; break; }
135 }
136 132
137// printk("%s: %s: mode 0x%02x, speed 0x%02x\n", 133 if (mwdma_mask & 0x04) {
138// __FUNCTION__, drive->name, mode, speed); 134 speed = XFER_MW_DMA_2;
135 break;
136 }
137 if (mwdma_mask & 0x02) {
138 speed = XFER_MW_DMA_1;
139 break;
140 }
141 if (mwdma_mask & 0x01) {
142 speed = XFER_MW_DMA_0;
143 break;
144 }
145
146 swdma_mask = id->dma_1word & hwif->swdma_mask;
147
148 if (swdma_mask & 0x04) {
149 speed = XFER_SW_DMA_2;
150 break;
151 }
152 if (swdma_mask & 0x02) {
153 speed = XFER_SW_DMA_1;
154 break;
155 }
156 if (swdma_mask & 0x01) {
157 speed = XFER_SW_DMA_0;
158 break;
159 }
160 }
139 161
140 return speed; 162 return speed;
141} 163}
142
143EXPORT_SYMBOL(ide_dma_speed); 164EXPORT_SYMBOL(ide_dma_speed);
144 165
145 166
@@ -456,13 +477,14 @@ static void ide_dump_opcode(ide_drive_t *drive)
456 spin_unlock(&ide_lock); 477 spin_unlock(&ide_lock);
457 if (!rq) 478 if (!rq)
458 return; 479 return;
459 if (rq->flags & (REQ_DRIVE_CMD | REQ_DRIVE_TASK)) { 480 if (rq->cmd_type == REQ_TYPE_ATA_CMD ||
481 rq->cmd_type == REQ_TYPE_ATA_TASK) {
460 char *args = rq->buffer; 482 char *args = rq->buffer;
461 if (args) { 483 if (args) {
462 opcode = args[0]; 484 opcode = args[0];
463 found = 1; 485 found = 1;
464 } 486 }
465 } else if (rq->flags & REQ_DRIVE_TASKFILE) { 487 } else if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
466 ide_task_t *args = rq->special; 488 ide_task_t *args = rq->special;
467 if (args) { 489 if (args) {
468 task_struct_t *tf = (task_struct_t *) args->tfRegister; 490 task_struct_t *tf = (task_struct_t *) args->tfRegister;
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 9cadf0106c6c..dad9c47ebb69 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -623,6 +623,8 @@ static void hwif_release_dev (struct device *dev)
623 623
624static void hwif_register (ide_hwif_t *hwif) 624static void hwif_register (ide_hwif_t *hwif)
625{ 625{
626 int ret;
627
626 /* register with global device tree */ 628 /* register with global device tree */
627 strlcpy(hwif->gendev.bus_id,hwif->name,BUS_ID_SIZE); 629 strlcpy(hwif->gendev.bus_id,hwif->name,BUS_ID_SIZE);
628 hwif->gendev.driver_data = hwif; 630 hwif->gendev.driver_data = hwif;
@@ -634,7 +636,10 @@ static void hwif_register (ide_hwif_t *hwif)
634 hwif->gendev.parent = NULL; 636 hwif->gendev.parent = NULL;
635 } 637 }
636 hwif->gendev.release = hwif_release_dev; 638 hwif->gendev.release = hwif_release_dev;
637 device_register(&hwif->gendev); 639 ret = device_register(&hwif->gendev);
640 if (ret < 0)
641 printk(KERN_WARNING "IDE: %s: device_register error: %d\n",
642 __FUNCTION__, ret);
638} 643}
639 644
640static int wait_hwif_ready(ide_hwif_t *hwif) 645static int wait_hwif_ready(ide_hwif_t *hwif)
@@ -884,13 +889,19 @@ int probe_hwif_init_with_fixup(ide_hwif_t *hwif, void (*fixup)(ide_hwif_t *hwif)
884 889
885 if (hwif->present) { 890 if (hwif->present) {
886 u16 unit = 0; 891 u16 unit = 0;
892 int ret;
893
887 for (unit = 0; unit < MAX_DRIVES; ++unit) { 894 for (unit = 0; unit < MAX_DRIVES; ++unit) {
888 ide_drive_t *drive = &hwif->drives[unit]; 895 ide_drive_t *drive = &hwif->drives[unit];
889 /* For now don't attach absent drives, we may 896 /* For now don't attach absent drives, we may
890 want them on default or a new "empty" class 897 want them on default or a new "empty" class
891 for hotplug reprobing ? */ 898 for hotplug reprobing ? */
892 if (drive->present) { 899 if (drive->present) {
893 device_register(&drive->gendev); 900 ret = device_register(&drive->gendev);
901 if (ret < 0)
902 printk(KERN_WARNING "IDE: %s: "
903 "device_register error: %d\n",
904 __FUNCTION__, ret);
894 } 905 }
895 } 906 }
896 } 907 }
@@ -1409,8 +1420,14 @@ int ideprobe_init (void)
1409 if (hwif->chipset == ide_unknown || hwif->chipset == ide_forced) 1420 if (hwif->chipset == ide_unknown || hwif->chipset == ide_forced)
1410 hwif->chipset = ide_generic; 1421 hwif->chipset = ide_generic;
1411 for (unit = 0; unit < MAX_DRIVES; ++unit) 1422 for (unit = 0; unit < MAX_DRIVES; ++unit)
1412 if (hwif->drives[unit].present) 1423 if (hwif->drives[unit].present) {
1413 device_register(&hwif->drives[unit].gendev); 1424 int ret = device_register(
1425 &hwif->drives[unit].gendev);
1426 if (ret < 0)
1427 printk(KERN_WARNING "IDE: %s: "
1428 "device_register error: %d\n",
1429 __FUNCTION__, ret);
1430 }
1414 } 1431 }
1415 } 1432 }
1416 return 0; 1433 return 0;
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index 41b74b13a00c..aa049dab3d95 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -326,15 +326,24 @@ static int ide_replace_subdriver(ide_drive_t *drive, const char *driver)
326{ 326{
327 struct device *dev = &drive->gendev; 327 struct device *dev = &drive->gendev;
328 int ret = 1; 328 int ret = 1;
329 int err;
329 330
330 down_write(&dev->bus->subsys.rwsem); 331 down_write(&dev->bus->subsys.rwsem);
331 device_release_driver(dev); 332 device_release_driver(dev);
332 /* FIXME: device can still be in use by previous driver */ 333 /* FIXME: device can still be in use by previous driver */
333 strlcpy(drive->driver_req, driver, sizeof(drive->driver_req)); 334 strlcpy(drive->driver_req, driver, sizeof(drive->driver_req));
334 device_attach(dev); 335 err = device_attach(dev);
336 if (err < 0)
337 printk(KERN_WARNING "IDE: %s: device_attach error: %d\n",
338 __FUNCTION__, err);
335 drive->driver_req[0] = 0; 339 drive->driver_req[0] = 0;
336 if (dev->driver == NULL) 340 if (dev->driver == NULL) {
337 device_attach(dev); 341 err = device_attach(dev);
342 if (err < 0)
343 printk(KERN_WARNING
344 "IDE: %s: device_attach(2) error: %d\n",
345 __FUNCTION__, err);
346 }
338 if (dev->driver && !strcmp(dev->driver->name, driver)) 347 if (dev->driver && !strcmp(dev->driver->name, driver))
339 ret = 0; 348 ret = 0;
340 up_write(&dev->bus->subsys.rwsem); 349 up_write(&dev->bus->subsys.rwsem);
@@ -526,7 +535,12 @@ static int proc_print_driver(struct device_driver *drv, void *data)
526 535
527static int ide_drivers_show(struct seq_file *s, void *p) 536static int ide_drivers_show(struct seq_file *s, void *p)
528{ 537{
529 bus_for_each_drv(&ide_bus_type, NULL, s, proc_print_driver); 538 int err;
539
540 err = bus_for_each_drv(&ide_bus_type, NULL, s, proc_print_driver);
541 if (err < 0)
542 printk(KERN_WARNING "IDE: %s: bus_for_each_drv error: %d\n",
543 __FUNCTION__, err);
530 return 0; 544 return 0;
531} 545}
532 546
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 7067ab997927..e2f4bb549063 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -1776,7 +1776,7 @@ static void idetape_create_request_sense_cmd (idetape_pc_t *pc)
1776static void idetape_init_rq(struct request *rq, u8 cmd) 1776static void idetape_init_rq(struct request *rq, u8 cmd)
1777{ 1777{
1778 memset(rq, 0, sizeof(*rq)); 1778 memset(rq, 0, sizeof(*rq));
1779 rq->flags = REQ_SPECIAL; 1779 rq->cmd_type = REQ_TYPE_SPECIAL;
1780 rq->cmd[0] = cmd; 1780 rq->cmd[0] = cmd;
1781} 1781}
1782 1782
@@ -2423,8 +2423,8 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
2423#if IDETAPE_DEBUG_LOG 2423#if IDETAPE_DEBUG_LOG
2424#if 0 2424#if 0
2425 if (tape->debug_level >= 5) 2425 if (tape->debug_level >= 5)
2426 printk(KERN_INFO "ide-tape: rq_status: %d, " 2426 printk(KERN_INFO "ide-tape: %d, "
2427 "dev: %s, cmd: %ld, errors: %d\n", rq->rq_status, 2427 "dev: %s, cmd: %ld, errors: %d\n",
2428 rq->rq_disk->disk_name, rq->cmd[0], rq->errors); 2428 rq->rq_disk->disk_name, rq->cmd[0], rq->errors);
2429#endif 2429#endif
2430 if (tape->debug_level >= 2) 2430 if (tape->debug_level >= 2)
@@ -2433,12 +2433,12 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
2433 rq->sector, rq->nr_sectors, rq->current_nr_sectors); 2433 rq->sector, rq->nr_sectors, rq->current_nr_sectors);
2434#endif /* IDETAPE_DEBUG_LOG */ 2434#endif /* IDETAPE_DEBUG_LOG */
2435 2435
2436 if ((rq->flags & REQ_SPECIAL) == 0) { 2436 if (!blk_special_request(rq)) {
2437 /* 2437 /*
2438 * We do not support buffer cache originated requests. 2438 * We do not support buffer cache originated requests.
2439 */ 2439 */
2440 printk(KERN_NOTICE "ide-tape: %s: Unsupported request in " 2440 printk(KERN_NOTICE "ide-tape: %s: Unsupported request in "
2441 "request queue (%ld)\n", drive->name, rq->flags); 2441 "request queue (%d)\n", drive->name, rq->cmd_type);
2442 ide_end_request(drive, 0, 0); 2442 ide_end_request(drive, 0, 0);
2443 return ide_stopped; 2443 return ide_stopped;
2444 } 2444 }
@@ -2764,16 +2764,16 @@ static void idetape_add_stage_tail (ide_drive_t *drive,idetape_stage_t *stage)
2764 */ 2764 */
2765static void idetape_wait_for_request (ide_drive_t *drive, struct request *rq) 2765static void idetape_wait_for_request (ide_drive_t *drive, struct request *rq)
2766{ 2766{
2767 DECLARE_COMPLETION(wait); 2767 DECLARE_COMPLETION_ONSTACK(wait);
2768 idetape_tape_t *tape = drive->driver_data; 2768 idetape_tape_t *tape = drive->driver_data;
2769 2769
2770#if IDETAPE_DEBUG_BUGS 2770#if IDETAPE_DEBUG_BUGS
2771 if (rq == NULL || (rq->flags & REQ_SPECIAL) == 0) { 2771 if (rq == NULL || !blk_special_request(rq)) {
2772 printk (KERN_ERR "ide-tape: bug: Trying to sleep on non-valid request\n"); 2772 printk (KERN_ERR "ide-tape: bug: Trying to sleep on non-valid request\n");
2773 return; 2773 return;
2774 } 2774 }
2775#endif /* IDETAPE_DEBUG_BUGS */ 2775#endif /* IDETAPE_DEBUG_BUGS */
2776 rq->waiting = &wait; 2776 rq->end_io_data = &wait;
2777 rq->end_io = blk_end_sync_rq; 2777 rq->end_io = blk_end_sync_rq;
2778 spin_unlock_irq(&tape->spinlock); 2778 spin_unlock_irq(&tape->spinlock);
2779 wait_for_completion(&wait); 2779 wait_for_completion(&wait);
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 97a9244312fc..1d0470c1f957 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -363,7 +363,7 @@ static ide_startstop_t task_error(ide_drive_t *drive, struct request *rq,
363 363
364static void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat) 364static void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat)
365{ 365{
366 if (rq->flags & REQ_DRIVE_TASKFILE) { 366 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
367 ide_task_t *task = rq->special; 367 ide_task_t *task = rq->special;
368 368
369 if (task->tf_out_flags.all) { 369 if (task->tf_out_flags.all) {
@@ -474,7 +474,7 @@ static int ide_diag_taskfile(ide_drive_t *drive, ide_task_t *args, unsigned long
474 struct request rq; 474 struct request rq;
475 475
476 memset(&rq, 0, sizeof(rq)); 476 memset(&rq, 0, sizeof(rq));
477 rq.flags = REQ_DRIVE_TASKFILE; 477 rq.cmd_type = REQ_TYPE_ATA_TASKFILE;
478 rq.buffer = buf; 478 rq.buffer = buf;
479 479
480 /* 480 /*
@@ -499,7 +499,7 @@ static int ide_diag_taskfile(ide_drive_t *drive, ide_task_t *args, unsigned long
499 rq.hard_cur_sectors = rq.current_nr_sectors = rq.nr_sectors; 499 rq.hard_cur_sectors = rq.current_nr_sectors = rq.nr_sectors;
500 500
501 if (args->command_type == IDE_DRIVE_TASK_RAW_WRITE) 501 if (args->command_type == IDE_DRIVE_TASK_RAW_WRITE)
502 rq.flags |= REQ_RW; 502 rq.cmd_flags |= REQ_RW;
503 } 503 }
504 504
505 rq.special = args; 505 rq.special = args;
@@ -737,7 +737,7 @@ static int ide_wait_cmd_task(ide_drive_t *drive, u8 *buf)
737 struct request rq; 737 struct request rq;
738 738
739 ide_init_drive_cmd(&rq); 739 ide_init_drive_cmd(&rq);
740 rq.flags = REQ_DRIVE_TASK; 740 rq.cmd_type = REQ_TYPE_ATA_TASK;
741 rq.buffer = buf; 741 rq.buffer = buf;
742 return ide_do_drive_cmd(drive, &rq, ide_wait); 742 return ide_do_drive_cmd(drive, &rq, ide_wait);
743} 743}
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index defd4b4bd374..287a66201150 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -450,7 +450,7 @@ void ide_hwif_release_regions(ide_hwif_t *hwif)
450 * @hwif: hwif to update 450 * @hwif: hwif to update
451 * @tmp_hwif: template 451 * @tmp_hwif: template
452 * 452 *
453 * Restore hwif to a previous state by copying most settngs 453 * Restore hwif to a previous state by copying most settings
454 * from the template. 454 * from the template.
455 */ 455 */
456 456
@@ -539,9 +539,10 @@ static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
539 hwif->dma_vendor3 = tmp_hwif->dma_vendor3; 539 hwif->dma_vendor3 = tmp_hwif->dma_vendor3;
540 hwif->dma_prdtable = tmp_hwif->dma_prdtable; 540 hwif->dma_prdtable = tmp_hwif->dma_prdtable;
541 541
542 hwif->dma_extra = tmp_hwif->dma_extra;
543 hwif->config_data = tmp_hwif->config_data; 542 hwif->config_data = tmp_hwif->config_data;
544 hwif->select_data = tmp_hwif->select_data; 543 hwif->select_data = tmp_hwif->select_data;
544 hwif->extra_base = tmp_hwif->extra_base;
545 hwif->extra_ports = tmp_hwif->extra_ports;
545 hwif->autodma = tmp_hwif->autodma; 546 hwif->autodma = tmp_hwif->autodma;
546 hwif->udma_four = tmp_hwif->udma_four; 547 hwif->udma_four = tmp_hwif->udma_four;
547 hwif->no_dsc = tmp_hwif->no_dsc; 548 hwif->no_dsc = tmp_hwif->no_dsc;
@@ -550,7 +551,7 @@ static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
550} 551}
551 552
552/** 553/**
553 * ide_unregister - free an ide interface 554 * ide_unregister - free an IDE interface
554 * @index: index of interface (will change soon to a pointer) 555 * @index: index of interface (will change soon to a pointer)
555 * 556 *
556 * Perform the final unregister of an IDE interface. At the moment 557 * Perform the final unregister of an IDE interface. At the moment
@@ -563,8 +564,8 @@ static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
563 * deadlocking the IDE layer. The shutdown callback is called 564 * deadlocking the IDE layer. The shutdown callback is called
564 * before we take the lock and free resources. It is up to the 565 * before we take the lock and free resources. It is up to the
565 * caller to be sure there is no pending I/O here, and that 566 * caller to be sure there is no pending I/O here, and that
566 * the interfce will not be reopened (present/vanishing locking 567 * the interface will not be reopened (present/vanishing locking
567 * isnt yet done btw). After we commit to the final kill we 568 * isn't yet done BTW). After we commit to the final kill we
568 * call the cleanup callback with the ide locks held. 569 * call the cleanup callback with the ide locks held.
569 * 570 *
570 * Unregister restores the hwif structures to the default state. 571 * Unregister restores the hwif structures to the default state.
@@ -674,6 +675,9 @@ void ide_unregister(unsigned int index)
674 hwif->dma_status = 0; 675 hwif->dma_status = 0;
675 hwif->dma_vendor3 = 0; 676 hwif->dma_vendor3 = 0;
676 hwif->dma_prdtable = 0; 677 hwif->dma_prdtable = 0;
678
679 hwif->extra_base = 0;
680 hwif->extra_ports = 0;
677 } 681 }
678 682
679 /* copy original settings */ 683 /* copy original settings */
@@ -1207,7 +1211,7 @@ int system_bus_clock (void)
1207 1211
1208EXPORT_SYMBOL(system_bus_clock); 1212EXPORT_SYMBOL(system_bus_clock);
1209 1213
1210static int generic_ide_suspend(struct device *dev, pm_message_t state) 1214static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
1211{ 1215{
1212 ide_drive_t *drive = dev->driver_data; 1216 ide_drive_t *drive = dev->driver_data;
1213 struct request rq; 1217 struct request rq;
@@ -1217,11 +1221,13 @@ static int generic_ide_suspend(struct device *dev, pm_message_t state)
1217 memset(&rq, 0, sizeof(rq)); 1221 memset(&rq, 0, sizeof(rq));
1218 memset(&rqpm, 0, sizeof(rqpm)); 1222 memset(&rqpm, 0, sizeof(rqpm));
1219 memset(&args, 0, sizeof(args)); 1223 memset(&args, 0, sizeof(args));
1220 rq.flags = REQ_PM_SUSPEND; 1224 rq.cmd_type = REQ_TYPE_PM_SUSPEND;
1221 rq.special = &args; 1225 rq.special = &args;
1222 rq.end_io_data = &rqpm; 1226 rq.data = &rqpm;
1223 rqpm.pm_step = ide_pm_state_start_suspend; 1227 rqpm.pm_step = ide_pm_state_start_suspend;
1224 rqpm.pm_state = state.event; 1228 if (mesg.event == PM_EVENT_PRETHAW)
1229 mesg.event = PM_EVENT_FREEZE;
1230 rqpm.pm_state = mesg.event;
1225 1231
1226 return ide_do_drive_cmd(drive, &rq, ide_wait); 1232 return ide_do_drive_cmd(drive, &rq, ide_wait);
1227} 1233}
@@ -1236,9 +1242,9 @@ static int generic_ide_resume(struct device *dev)
1236 memset(&rq, 0, sizeof(rq)); 1242 memset(&rq, 0, sizeof(rq));
1237 memset(&rqpm, 0, sizeof(rqpm)); 1243 memset(&rqpm, 0, sizeof(rqpm));
1238 memset(&args, 0, sizeof(args)); 1244 memset(&args, 0, sizeof(args));
1239 rq.flags = REQ_PM_RESUME; 1245 rq.cmd_type = REQ_TYPE_PM_RESUME;
1240 rq.special = &args; 1246 rq.special = &args;
1241 rq.end_io_data = &rqpm; 1247 rq.data = &rqpm;
1242 rqpm.pm_step = ide_pm_state_start_resume; 1248 rqpm.pm_step = ide_pm_state_start_resume;
1243 rqpm.pm_state = PM_EVENT_ON; 1249 rqpm.pm_state = PM_EVENT_ON;
1244 1250
@@ -1358,6 +1364,11 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device
1358 1364
1359 spin_lock_irqsave(&ide_lock, flags); 1365 spin_lock_irqsave(&ide_lock, flags);
1360 1366
1367 if (HWGROUP(drive)->resetting) {
1368 spin_unlock_irqrestore(&ide_lock, flags);
1369 return -EBUSY;
1370 }
1371
1361 ide_abort(drive, "drive reset"); 1372 ide_abort(drive, "drive reset");
1362 1373
1363 BUG_ON(HWGROUP(drive)->handler); 1374 BUG_ON(HWGROUP(drive)->handler);
@@ -1991,10 +2002,16 @@ EXPORT_SYMBOL_GPL(ide_bus_type);
1991 */ 2002 */
1992static int __init ide_init(void) 2003static int __init ide_init(void)
1993{ 2004{
2005 int ret;
2006
1994 printk(KERN_INFO "Uniform Multi-Platform E-IDE driver " REVISION "\n"); 2007 printk(KERN_INFO "Uniform Multi-Platform E-IDE driver " REVISION "\n");
1995 system_bus_speed = ide_system_bus_speed(); 2008 system_bus_speed = ide_system_bus_speed();
1996 2009
1997 bus_register(&ide_bus_type); 2010 ret = bus_register(&ide_bus_type);
2011 if (ret < 0) {
2012 printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
2013 return ret;
2014 }
1998 2015
1999 init_ide_data(); 2016 init_ide_data();
2000 2017
diff --git a/drivers/ide/legacy/hd.c b/drivers/ide/legacy/hd.c
index aebecd8f51cc..4ab931145673 100644
--- a/drivers/ide/legacy/hd.c
+++ b/drivers/ide/legacy/hd.c
@@ -626,7 +626,7 @@ repeat:
626 req->rq_disk->disk_name, (req->cmd == READ)?"read":"writ", 626 req->rq_disk->disk_name, (req->cmd == READ)?"read":"writ",
627 cyl, head, sec, nsect, req->buffer); 627 cyl, head, sec, nsect, req->buffer);
628#endif 628#endif
629 if (req->flags & REQ_CMD) { 629 if (blk_fs_request(req)) {
630 switch (rq_data_dir(req)) { 630 switch (rq_data_dir(req)) {
631 case READ: 631 case READ:
632 hd_out(disk,nsect,sec,head,cyl,WIN_READ,&read_intr); 632 hd_out(disk,nsect,sec,head,cyl,WIN_READ,&read_intr);
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index 602797a44208..bef4759f70e5 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -120,7 +120,7 @@ static int ide_probe(struct pcmcia_device *link)
120 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 120 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
121 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 121 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
122 link->io.IOAddrLines = 3; 122 link->io.IOAddrLines = 3;
123 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 123 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
124 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 124 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
125 link->conf.Attributes = CONF_ENABLE_IRQ; 125 link->conf.Attributes = CONF_ENABLE_IRQ;
126 link->conf.IntType = INT_MEMORY_AND_IO; 126 link->conf.IntType = INT_MEMORY_AND_IO;
@@ -398,12 +398,17 @@ static struct pcmcia_device_id ide_ids[] = {
398 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDE", 0x547e66dc, 0x5c5ab149), 398 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDE", 0x547e66dc, 0x5c5ab149),
399 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDEII", 0x547e66dc, 0xb3662674), 399 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDEII", 0x547e66dc, 0xb3662674),
400 PCMCIA_DEVICE_PROD_ID12("LOOKMEET", "CBIDE2 ", 0xe37be2b5, 0x8671043b), 400 PCMCIA_DEVICE_PROD_ID12("LOOKMEET", "CBIDE2 ", 0xe37be2b5, 0x8671043b),
401 PCMCIA_DEVICE_PROD_ID12("M-Systems", "CF500", 0x7ed2ad87, 0x7a13045c),
401 PCMCIA_DEVICE_PROD_ID2("NinjaATA-", 0xebe0bd79), 402 PCMCIA_DEVICE_PROD_ID2("NinjaATA-", 0xebe0bd79),
402 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "CD-ROM", 0x281f1c5d, 0x66536591), 403 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "CD-ROM", 0x281f1c5d, 0x66536591),
403 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "PnPIDE", 0x281f1c5d, 0x0c694728), 404 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "PnPIDE", 0x281f1c5d, 0x0c694728),
404 PCMCIA_DEVICE_PROD_ID12("SHUTTLE TECHNOLOGY LTD.", "PCCARD-IDE/ATAPI Adapter", 0x4a3f0ba0, 0x322560e1), 405 PCMCIA_DEVICE_PROD_ID12("SHUTTLE TECHNOLOGY LTD.", "PCCARD-IDE/ATAPI Adapter", 0x4a3f0ba0, 0x322560e1),
406 PCMCIA_DEVICE_PROD_ID12("SEAGATE", "ST1", 0x87c1b330, 0xe1f30883),
407 PCMCIA_DEVICE_PROD_ID12("SAMSUNG", "04/05/06", 0x43d74cb4, 0x6a22777d),
408 PCMCIA_DEVICE_PROD_ID12("SMI VENDOR", "SMI PRODUCT", 0x30896c92, 0x703cc5f6),
405 PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "MK2001MPL", 0xb4585a1a, 0x3489e003), 409 PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "MK2001MPL", 0xb4585a1a, 0x3489e003),
406 PCMCIA_DEVICE_PROD_ID1("TRANSCEND 512M ", 0xd0909443), 410 PCMCIA_DEVICE_PROD_ID1("TRANSCEND 512M ", 0xd0909443),
411 PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS4GCF120", 0x709b1bf1, 0xf54a91c8),
407 PCMCIA_DEVICE_PROD_ID12("WIT", "IDE16", 0x244e5994, 0x3e232852), 412 PCMCIA_DEVICE_PROD_ID12("WIT", "IDE16", 0x244e5994, 0x3e232852),
408 PCMCIA_DEVICE_PROD_ID1("STI Flash", 0xe4a13209), 413 PCMCIA_DEVICE_PROD_ID1("STI Flash", 0xe4a13209),
409 PCMCIA_DEVICE_PROD_ID12("STI", "Flash 5.0", 0xbf2df18d, 0x8cb57a0e), 414 PCMCIA_DEVICE_PROD_ID12("STI", "Flash 5.0", 0xbf2df18d, 0x8cb57a0e),
diff --git a/drivers/ide/mips/au1xxx-ide.c b/drivers/ide/mips/au1xxx-ide.c
index 71f27e955d87..c7854ea57b52 100644
--- a/drivers/ide/mips/au1xxx-ide.c
+++ b/drivers/ide/mips/au1xxx-ide.c
@@ -476,13 +476,13 @@ static int auide_dma_lostirq(ide_drive_t *drive)
476 return 0; 476 return 0;
477} 477}
478 478
479static void auide_ddma_tx_callback(int irq, void *param, struct pt_regs *regs) 479static void auide_ddma_tx_callback(int irq, void *param)
480{ 480{
481 _auide_hwif *ahwif = (_auide_hwif*)param; 481 _auide_hwif *ahwif = (_auide_hwif*)param;
482 ahwif->drive->waiting_for_dma = 0; 482 ahwif->drive->waiting_for_dma = 0;
483} 483}
484 484
485static void auide_ddma_rx_callback(int irq, void *param, struct pt_regs *regs) 485static void auide_ddma_rx_callback(int irq, void *param)
486{ 486{
487 _auide_hwif *ahwif = (_auide_hwif*)param; 487 _auide_hwif *ahwif = (_auide_hwif*)param;
488 ahwif->drive->waiting_for_dma = 0; 488 ahwif->drive->waiting_for_dma = 0;
diff --git a/drivers/ide/pci/Makefile b/drivers/ide/pci/Makefile
index f35d684edc25..640a54b09b5a 100644
--- a/drivers/ide/pci/Makefile
+++ b/drivers/ide/pci/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_BLK_DEV_HPT366) += hpt366.o
14#obj-$(CONFIG_BLK_DEV_HPT37X) += hpt37x.o 14#obj-$(CONFIG_BLK_DEV_HPT37X) += hpt37x.o
15obj-$(CONFIG_BLK_DEV_IT8172) += it8172.o 15obj-$(CONFIG_BLK_DEV_IT8172) += it8172.o
16obj-$(CONFIG_BLK_DEV_IT821X) += it821x.o 16obj-$(CONFIG_BLK_DEV_IT821X) += it821x.o
17obj-$(CONFIG_BLK_DEV_JMICRON) += jmicron.o
17obj-$(CONFIG_BLK_DEV_NS87415) += ns87415.o 18obj-$(CONFIG_BLK_DEV_NS87415) += ns87415.o
18obj-$(CONFIG_BLK_DEV_OPTI621) += opti621.o 19obj-$(CONFIG_BLK_DEV_OPTI621) += opti621.o
19obj-$(CONFIG_BLK_DEV_PDC202XX_OLD) += pdc202xx_old.o 20obj-$(CONFIG_BLK_DEV_PDC202XX_OLD) += pdc202xx_old.o
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c
index a574de5f0835..d55b938b1aeb 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/pci/atiixp.c
@@ -318,6 +318,20 @@ static void __devinit init_hwif_atiixp(ide_hwif_t *hwif)
318 hwif->drives[0].autodma = hwif->autodma; 318 hwif->drives[0].autodma = hwif->autodma;
319} 319}
320 320
321static void __devinit init_hwif_sb600_legacy(ide_hwif_t *hwif)
322{
323
324 hwif->atapi_dma = 1;
325 hwif->ultra_mask = 0x7f;
326 hwif->mwdma_mask = 0x07;
327 hwif->swdma_mask = 0x07;
328
329 if (!noautodma)
330 hwif->autodma = 1;
331 hwif->drives[0].autodma = hwif->autodma;
332 hwif->drives[1].autodma = hwif->autodma;
333}
334
321static ide_pci_device_t atiixp_pci_info[] __devinitdata = { 335static ide_pci_device_t atiixp_pci_info[] __devinitdata = {
322 { /* 0 */ 336 { /* 0 */
323 .name = "ATIIXP", 337 .name = "ATIIXP",
@@ -326,6 +340,12 @@ static ide_pci_device_t atiixp_pci_info[] __devinitdata = {
326 .autodma = AUTODMA, 340 .autodma = AUTODMA,
327 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}}, 341 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
328 .bootable = ON_BOARD, 342 .bootable = ON_BOARD,
343 },{ /* 1 */
344 .name = "ATI SB600 SATA Legacy IDE",
345 .init_hwif = init_hwif_sb600_legacy,
346 .channels = 2,
347 .autodma = AUTODMA,
348 .bootable = ON_BOARD,
329 } 349 }
330}; 350};
331 351
@@ -348,6 +368,7 @@ static struct pci_device_id atiixp_pci_tbl[] = {
348 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 368 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
349 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 369 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
350 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 370 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
371 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, PCI_ANY_ID, PCI_ANY_ID, (PCI_CLASS_STORAGE_IDE<<8)|0x8a, 0xffff05, 1},
351 { 0, }, 372 { 0, },
352}; 373};
353MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl); 374MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl);
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/pci/cs5530.c
index 380bb28c7c54..ae405fa32236 100644
--- a/drivers/ide/pci/cs5530.c
+++ b/drivers/ide/pci/cs5530.c
@@ -222,23 +222,23 @@ static unsigned int __devinit init_chipset_cs5530 (struct pci_dev *dev, const ch
222 unsigned long flags; 222 unsigned long flags;
223 223
224 dev = NULL; 224 dev = NULL;
225 while ((dev = pci_find_device(PCI_VENDOR_ID_CYRIX, PCI_ANY_ID, dev)) != NULL) { 225 while ((dev = pci_get_device(PCI_VENDOR_ID_CYRIX, PCI_ANY_ID, dev)) != NULL) {
226 switch (dev->device) { 226 switch (dev->device) {
227 case PCI_DEVICE_ID_CYRIX_PCI_MASTER: 227 case PCI_DEVICE_ID_CYRIX_PCI_MASTER:
228 master_0 = dev; 228 master_0 = pci_dev_get(dev);
229 break; 229 break;
230 case PCI_DEVICE_ID_CYRIX_5530_LEGACY: 230 case PCI_DEVICE_ID_CYRIX_5530_LEGACY:
231 cs5530_0 = dev; 231 cs5530_0 = pci_dev_get(dev);
232 break; 232 break;
233 } 233 }
234 } 234 }
235 if (!master_0) { 235 if (!master_0) {
236 printk(KERN_ERR "%s: unable to locate PCI MASTER function\n", name); 236 printk(KERN_ERR "%s: unable to locate PCI MASTER function\n", name);
237 return 0; 237 goto out;
238 } 238 }
239 if (!cs5530_0) { 239 if (!cs5530_0) {
240 printk(KERN_ERR "%s: unable to locate CS5530 LEGACY function\n", name); 240 printk(KERN_ERR "%s: unable to locate CS5530 LEGACY function\n", name);
241 return 0; 241 goto out;
242 } 242 }
243 243
244 spin_lock_irqsave(&ide_lock, flags); 244 spin_lock_irqsave(&ide_lock, flags);
@@ -296,6 +296,9 @@ static unsigned int __devinit init_chipset_cs5530 (struct pci_dev *dev, const ch
296 296
297 spin_unlock_irqrestore(&ide_lock, flags); 297 spin_unlock_irqrestore(&ide_lock, flags);
298 298
299out:
300 pci_dev_put(master_0);
301 pci_dev_put(cs5530_0);
299 return 0; 302 return 0;
300} 303}
301 304
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/pci/cy82c693.c
index 120929fbe7a3..64330c459bd4 100644
--- a/drivers/ide/pci/cy82c693.c
+++ b/drivers/ide/pci/cy82c693.c
@@ -281,7 +281,7 @@ static void cy82c693_tune_drive (ide_drive_t *drive, u8 pio)
281 281
282 /* select primary or secondary channel */ 282 /* select primary or secondary channel */
283 if (hwif->index > 0) { /* drive is on the secondary channel */ 283 if (hwif->index > 0) { /* drive is on the secondary channel */
284 dev = pci_find_slot(dev->bus->number, dev->devfn+1); 284 dev = pci_get_slot(dev->bus, dev->devfn+1);
285 if (!dev) { 285 if (!dev) {
286 printk(KERN_ERR "%s: tune_drive: " 286 printk(KERN_ERR "%s: tune_drive: "
287 "Cannot find secondary interface!\n", 287 "Cannot find secondary interface!\n",
@@ -500,8 +500,9 @@ static int __devinit cy82c693_init_one(struct pci_dev *dev, const struct pci_dev
500 Function 1 is primary IDE channel, function 2 - secondary. */ 500 Function 1 is primary IDE channel, function 2 - secondary. */
501 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && 501 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE &&
502 PCI_FUNC(dev->devfn) == 1) { 502 PCI_FUNC(dev->devfn) == 1) {
503 dev2 = pci_find_slot(dev->bus->number, dev->devfn + 1); 503 dev2 = pci_get_slot(dev->bus, dev->devfn + 1);
504 ret = ide_setup_pci_devices(dev, dev2, d); 504 ret = ide_setup_pci_devices(dev, dev2, d);
505 /* We leak pci refs here but thats ok - we can't be unloaded */
505 } 506 }
506 return ret; 507 return ret;
507} 508}
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c
index 78810ba982e9..0cb7b9b520ea 100644
--- a/drivers/ide/pci/generic.c
+++ b/drivers/ide/pci/generic.c
@@ -41,15 +41,8 @@
41 41
42static int ide_generic_all; /* Set to claim all devices */ 42static int ide_generic_all; /* Set to claim all devices */
43 43
44#ifndef MODULE 44module_param_named(all_generic_ide, ide_generic_all, bool, 0444);
45static int __init ide_generic_all_on(char *unused) 45MODULE_PARM_DESC(all_generic_ide, "IDE generic will claim all unknown PCI IDE storage controllers.");
46{
47 ide_generic_all = 1;
48 printk(KERN_INFO "IDE generic will claim all unknown PCI IDE storage controllers.\n");
49 return 1;
50}
51__setup("all-generic-ide", ide_generic_all_on);
52#endif
53 46
54static void __devinit init_hwif_generic (ide_hwif_t *hwif) 47static void __devinit init_hwif_generic (ide_hwif_t *hwif)
55{ 48{
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/pci/jmicron.c
new file mode 100644
index 000000000000..68c74bbf8b06
--- /dev/null
+++ b/drivers/ide/pci/jmicron.c
@@ -0,0 +1,269 @@
1
2/*
3 * Copyright (C) 2006 Red Hat <alan@redhat.com>
4 *
5 * May be copied or modified under the terms of the GNU General Public License
6 */
7
8#include <linux/config.h>
9#include <linux/types.h>
10#include <linux/module.h>
11#include <linux/pci.h>
12#include <linux/delay.h>
13#include <linux/hdreg.h>
14#include <linux/ide.h>
15#include <linux/init.h>
16
17#include <asm/io.h>
18
19typedef enum {
20 PORT_PATA0 = 0,
21 PORT_PATA1 = 1,
22 PORT_SATA = 2,
23} port_type;
24
25/**
26 * jmicron_ratemask - Compute available modes
27 * @drive: IDE drive
28 *
29 * Compute the available speeds for the devices on the interface. This
30 * is all modes to ATA133 clipped by drive cable setup.
31 */
32
33static u8 jmicron_ratemask(ide_drive_t *drive)
34{
35 u8 mode = 4;
36 if (!eighty_ninty_three(drive))
37 mode = min(mode, (u8)1);
38 return mode;
39}
40
41/**
42 * ata66_jmicron - Cable check
43 * @hwif: IDE port
44 *
45 * Return 1 if the cable is 80pin
46 */
47
48static int __devinit ata66_jmicron(ide_hwif_t *hwif)
49{
50 struct pci_dev *pdev = hwif->pci_dev;
51
52 u32 control;
53 u32 control5;
54
55 int port = hwif->channel;
56 port_type port_map[2];
57
58 pci_read_config_dword(pdev, 0x40, &control);
59
60 /* There are two basic mappings. One has the two SATA ports merged
61 as master/slave and the secondary as PATA, the other has only the
62 SATA port mapped */
63 if (control & (1 << 23)) {
64 port_map[0] = PORT_SATA;
65 port_map[1] = PORT_PATA0;
66 } else {
67 port_map[0] = PORT_SATA;
68 port_map[1] = PORT_SATA;
69 }
70
71 /* The 365/366 may have this bit set to map the second PATA port
72 as the internal primary channel */
73 pci_read_config_dword(pdev, 0x80, &control5);
74 if (control5 & (1<<24))
75 port_map[0] = PORT_PATA1;
76
77 /* The two ports may then be logically swapped by the firmware */
78 if (control & (1 << 22))
79 port = port ^ 1;
80
81 /*
82 * Now we know which physical port we are talking about we can
83 * actually do our cable checking etc. Thankfully we don't need
84 * to do the plumbing for other cases.
85 */
86 switch (port_map[port])
87 {
88 case PORT_PATA0:
89 if (control & (1 << 3)) /* 40/80 pin primary */
90 return 1;
91 return 0;
92 case PORT_PATA1:
93 if (control5 & (1 << 19)) /* 40/80 pin secondary */
94 return 0;
95 return 1;
96 case PORT_SATA:
97 return 1;
98 }
99}
100
101static void jmicron_tuneproc (ide_drive_t *drive, byte mode_wanted)
102{
103 return;
104}
105
106/**
107 * config_jmicron_chipset_for_pio - set drive timings
108 * @drive: drive to tune
109 * @speed we want
110 *
111 */
112
113static void config_jmicron_chipset_for_pio (ide_drive_t *drive, byte set_speed)
114{
115 u8 speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL);
116 if (set_speed)
117 (void) ide_config_drive_speed(drive, speed);
118}
119
120/**
121 * jmicron_tune_chipset - set controller timings
122 * @drive: Drive to set up
123 * @xferspeed: speed we want to achieve
124 *
125 * As the JMicron snoops for timings all we actually need to do is
126 * make sure we don't set an invalid mode. We do need to honour
127 * the cable detect here.
128 */
129
130static int jmicron_tune_chipset (ide_drive_t *drive, byte xferspeed)
131{
132
133 u8 speed = ide_rate_filter(jmicron_ratemask(drive), xferspeed);
134
135 return ide_config_drive_speed(drive, speed);
136}
137
138/**
139 * config_chipset_for_dma - configure for DMA
140 * @drive: drive to configure
141 *
142 * As the JMicron snoops for timings all we actually need to do is
143 * make sure we don't set an invalid mode.
144 */
145
146static int config_chipset_for_dma (ide_drive_t *drive)
147{
148 u8 speed = ide_dma_speed(drive, jmicron_ratemask(drive));
149
150 config_jmicron_chipset_for_pio(drive, !speed);
151 jmicron_tune_chipset(drive, speed);
152 return ide_dma_enable(drive);
153}
154
155/**
156 * jmicron_configure_drive_for_dma - set up for DMA transfers
157 * @drive: drive we are going to set up
158 *
159 * As the JMicron snoops for timings all we actually need to do is
160 * make sure we don't set an invalid mode.
161 */
162
163static int jmicron_config_drive_for_dma (ide_drive_t *drive)
164{
165 ide_hwif_t *hwif = drive->hwif;
166
167 if (ide_use_dma(drive)) {
168 if (config_chipset_for_dma(drive))
169 return hwif->ide_dma_on(drive);
170 }
171 config_jmicron_chipset_for_pio(drive, 1);
172 return hwif->ide_dma_off_quietly(drive);
173}
174
175/**
176 * init_hwif_jmicron - set up hwif structs
177 * @hwif: interface to set up
178 *
179 * Minimal set up is required for the Jmicron hardware.
180 */
181
182static void __devinit init_hwif_jmicron(ide_hwif_t *hwif)
183{
184 hwif->speedproc = &jmicron_tune_chipset;
185 hwif->tuneproc = &jmicron_tuneproc;
186
187 hwif->drives[0].autotune = 1;
188 hwif->drives[1].autotune = 1;
189
190 if (!hwif->dma_base)
191 goto fallback;
192
193 hwif->atapi_dma = 1;
194 hwif->ultra_mask = 0x7f;
195 hwif->mwdma_mask = 0x07;
196
197 hwif->ide_dma_check = &jmicron_config_drive_for_dma;
198 if (!(hwif->udma_four))
199 hwif->udma_four = ata66_jmicron(hwif);
200
201 hwif->autodma = 1;
202 hwif->drives[0].autodma = hwif->autodma;
203 hwif->drives[1].autodma = hwif->autodma;
204 return;
205fallback:
206 hwif->autodma = 0;
207 return;
208}
209
210#define DECLARE_JMB_DEV(name_str) \
211 { \
212 .name = name_str, \
213 .init_hwif = init_hwif_jmicron, \
214 .channels = 2, \
215 .autodma = AUTODMA, \
216 .bootable = ON_BOARD, \
217 .enablebits = { {0x40, 1, 1}, {0x40, 0x10, 0x10} }, \
218 }
219
220static ide_pci_device_t jmicron_chipsets[] __devinitdata = {
221 /* 0 */ DECLARE_JMB_DEV("JMB361"),
222 /* 1 */ DECLARE_JMB_DEV("JMB363"),
223 /* 2 */ DECLARE_JMB_DEV("JMB365"),
224 /* 3 */ DECLARE_JMB_DEV("JMB366"),
225 /* 4 */ DECLARE_JMB_DEV("JMB368"),
226};
227
228/**
229 * jmicron_init_one - pci layer discovery entry
230 * @dev: PCI device
231 * @id: ident table entry
232 *
233 * Called by the PCI code when it finds a Jmicron controller.
234 * We then use the IDE PCI generic helper to do most of the work.
235 */
236
237static int __devinit jmicron_init_one(struct pci_dev *dev, const struct pci_device_id *id)
238{
239 ide_setup_pci_device(dev, &jmicron_chipsets[id->driver_data]);
240 return 0;
241}
242
243static struct pci_device_id jmicron_pci_tbl[] = {
244 { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361), 0},
245 { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363), 1},
246 { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365), 2},
247 { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366), 3},
248 { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368), 4},
249 { 0, },
250};
251
252MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
253
254static struct pci_driver driver = {
255 .name = "JMicron IDE",
256 .id_table = jmicron_pci_tbl,
257 .probe = jmicron_init_one,
258};
259
260static int __init jmicron_ide_init(void)
261{
262 return ide_pci_register_driver(&driver);
263}
264
265module_init(jmicron_ide_init);
266
267MODULE_AUTHOR("Alan Cox");
268MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes");
269MODULE_LICENSE("GPL");
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pci/pdc202xx_old.c
index b46022a11bef..184cdacddeb6 100644
--- a/drivers/ide/pci/pdc202xx_old.c
+++ b/drivers/ide/pci/pdc202xx_old.c
@@ -154,7 +154,8 @@ static int pdc202xx_tune_chipset (ide_drive_t *drive, u8 xferspeed)
154 u8 AP, BP, CP, DP; 154 u8 AP, BP, CP, DP;
155 u8 TA = 0, TB = 0, TC = 0; 155 u8 TA = 0, TB = 0, TC = 0;
156 156
157 if ((drive->media != ide_disk) && (speed < XFER_SW_DMA_0)) 157 if (drive->media != ide_disk &&
158 drive->media != ide_cdrom && speed < XFER_SW_DMA_0)
158 return -1; 159 return -1;
159 160
160 pci_read_config_dword(dev, drive_pci, &drive_conf); 161 pci_read_config_dword(dev, drive_pci, &drive_conf);
@@ -330,14 +331,12 @@ static int config_chipset_for_dma (ide_drive_t *drive)
330 331
331chipset_is_set: 332chipset_is_set:
332 333
333 if (drive->media == ide_disk) { 334 pci_read_config_byte(dev, (drive_pci), &AP);
334 pci_read_config_byte(dev, (drive_pci), &AP); 335 if (id->capability & 4) /* IORDY_EN */
335 if (id->capability & 4) /* IORDY_EN */ 336 pci_write_config_byte(dev, (drive_pci), AP|IORDY_EN);
336 pci_write_config_byte(dev, (drive_pci), AP|IORDY_EN); 337 pci_read_config_byte(dev, (drive_pci), &AP);
337 pci_read_config_byte(dev, (drive_pci), &AP); 338 if (drive->media == ide_disk) /* PREFETCH_EN */
338 if (drive->media == ide_disk) /* PREFETCH_EN */ 339 pci_write_config_byte(dev, (drive_pci), AP|PREFETCH_EN);
339 pci_write_config_byte(dev, (drive_pci), AP|PREFETCH_EN);
340 }
341 340
342 speed = ide_dma_speed(drive, pdc202xx_ratemask(drive)); 341 speed = ide_dma_speed(drive, pdc202xx_ratemask(drive));
343 342
@@ -385,7 +384,7 @@ static void pdc202xx_old_ide_dma_start(ide_drive_t *drive)
385{ 384{
386 if (drive->current_speed > XFER_UDMA_2) 385 if (drive->current_speed > XFER_UDMA_2)
387 pdc_old_enable_66MHz_clock(drive->hwif); 386 pdc_old_enable_66MHz_clock(drive->hwif);
388 if (drive->addressing == 1) { 387 if (drive->media != ide_disk || drive->addressing == 1) {
389 struct request *rq = HWGROUP(drive)->rq; 388 struct request *rq = HWGROUP(drive)->rq;
390 ide_hwif_t *hwif = HWIF(drive); 389 ide_hwif_t *hwif = HWIF(drive);
391 unsigned long high_16 = hwif->dma_master; 390 unsigned long high_16 = hwif->dma_master;
@@ -405,7 +404,7 @@ static void pdc202xx_old_ide_dma_start(ide_drive_t *drive)
405 404
406static int pdc202xx_old_ide_dma_end(ide_drive_t *drive) 405static int pdc202xx_old_ide_dma_end(ide_drive_t *drive)
407{ 406{
408 if (drive->addressing == 1) { 407 if (drive->media != ide_disk || drive->addressing == 1) {
409 ide_hwif_t *hwif = HWIF(drive); 408 ide_hwif_t *hwif = HWIF(drive);
410 unsigned long high_16 = hwif->dma_master; 409 unsigned long high_16 = hwif->dma_master;
411 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20); 410 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
@@ -519,6 +518,7 @@ static void __devinit init_hwif_pdc202xx(ide_hwif_t *hwif)
519 hwif->ultra_mask = 0x3f; 518 hwif->ultra_mask = 0x3f;
520 hwif->mwdma_mask = 0x07; 519 hwif->mwdma_mask = 0x07;
521 hwif->swdma_mask = 0x07; 520 hwif->swdma_mask = 0x07;
521 hwif->atapi_dma = 1;
522 522
523 hwif->err_stops_fifo = 1; 523 hwif->err_stops_fifo = 1;
524 524
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index 50332ddd5ddb..cdc3aab9ebcb 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -222,13 +222,15 @@ static void piix_tune_drive (ide_drive_t *drive, u8 pio)
222 u16 master_data; 222 u16 master_data;
223 u8 slave_data; 223 u8 slave_data;
224 static DEFINE_SPINLOCK(tune_lock); 224 static DEFINE_SPINLOCK(tune_lock);
225 int control = 0;
225 226
226 /* ISP RTC */ 227 /* ISP RTC */
227 u8 timings[][2] = { { 0, 0 }, 228 static const u8 timings[][2]= {
228 { 0, 0 }, 229 { 0, 0 },
229 { 1, 0 }, 230 { 0, 0 },
230 { 2, 1 }, 231 { 1, 0 },
231 { 2, 3 }, }; 232 { 2, 1 },
233 { 2, 3 }, };
232 234
233 pio = ide_get_best_pio_mode(drive, pio, 5, NULL); 235 pio = ide_get_best_pio_mode(drive, pio, 5, NULL);
234 236
@@ -239,19 +241,30 @@ static void piix_tune_drive (ide_drive_t *drive, u8 pio)
239 */ 241 */
240 spin_lock_irqsave(&tune_lock, flags); 242 spin_lock_irqsave(&tune_lock, flags);
241 pci_read_config_word(dev, master_port, &master_data); 243 pci_read_config_word(dev, master_port, &master_data);
244
245 if (pio >= 2)
246 control |= 1; /* Programmable timing on */
247 if (drive->media == ide_disk)
248 control |= 4; /* Prefetch, post write */
249 if (pio >= 3)
250 control |= 2; /* IORDY */
242 if (is_slave) { 251 if (is_slave) {
243 master_data = master_data | 0x4000; 252 master_data = master_data | 0x4000;
244 if (pio > 1) 253 if (pio > 1) {
245 /* enable PPE, IE and TIME */ 254 /* enable PPE, IE and TIME */
246 master_data = master_data | 0x0070; 255 master_data = master_data | (control << 4);
256 } else {
257 master_data &= ~0x0070;
258 }
247 pci_read_config_byte(dev, slave_port, &slave_data); 259 pci_read_config_byte(dev, slave_port, &slave_data);
248 slave_data = slave_data & (hwif->channel ? 0x0f : 0xf0); 260 slave_data = slave_data & (hwif->channel ? 0x0f : 0xf0);
249 slave_data = slave_data | (((timings[pio][0] << 2) | timings[pio][1]) << (hwif->channel ? 4 : 0)); 261 slave_data = slave_data | (((timings[pio][0] << 2) | timings[pio][1]) << (hwif->channel ? 4 : 0));
250 } else { 262 } else {
251 master_data = master_data & 0xccf8; 263 master_data = master_data & 0xccf8;
252 if (pio > 1) 264 if (pio > 1) {
253 /* enable PPE, IE and TIME */ 265 /* enable PPE, IE and TIME */
254 master_data = master_data | 0x0007; 266 master_data = master_data | control;
267 }
255 master_data = master_data | (timings[pio][0] << 12) | (timings[pio][1] << 8); 268 master_data = master_data | (timings[pio][0] << 12) | (timings[pio][1] << 8);
256 } 269 }
257 pci_write_config_word(dev, master_port, master_data); 270 pci_write_config_word(dev, master_port, master_data);
@@ -615,7 +628,7 @@ static void __devinit piix_check_450nx(void)
615 struct pci_dev *pdev = NULL; 628 struct pci_dev *pdev = NULL;
616 u16 cfg; 629 u16 cfg;
617 u8 rev; 630 u8 rev;
618 while((pdev=pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, pdev))!=NULL) 631 while((pdev=pci_get_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, pdev))!=NULL)
619 { 632 {
620 /* Look for 450NX PXB. Check for problem configurations 633 /* Look for 450NX PXB. Check for problem configurations
621 A PCI quirk checks bit 6 already */ 634 A PCI quirk checks bit 6 already */
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c
index fc2b5496b6d2..ff80937d94dd 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/pci/sc1200.c
@@ -323,6 +323,7 @@ static void sc1200_tuneproc (ide_drive_t *drive, byte pio) /* mode=255 means "au
323 } 323 }
324} 324}
325 325
326#ifdef CONFIG_PM
326static ide_hwif_t *lookup_pci_dev (ide_hwif_t *prev, struct pci_dev *dev) 327static ide_hwif_t *lookup_pci_dev (ide_hwif_t *prev, struct pci_dev *dev)
327{ 328{
328 int h; 329 int h;
@@ -451,6 +452,7 @@ static int sc1200_resume (struct pci_dev *dev)
451 } 452 }
452 return 0; 453 return 0;
453} 454}
455#endif
454 456
455/* 457/*
456 * This gets invoked by the IDE driver once for each channel, 458 * This gets invoked by the IDE driver once for each channel,
@@ -499,8 +501,10 @@ static struct pci_driver driver = {
499 .name = "SC1200_IDE", 501 .name = "SC1200_IDE",
500 .id_table = sc1200_pci_tbl, 502 .id_table = sc1200_pci_tbl,
501 .probe = sc1200_init_one, 503 .probe = sc1200_init_one,
504#ifdef CONFIG_PM
502 .suspend = sc1200_suspend, 505 .suspend = sc1200_suspend,
503 .resume = sc1200_resume, 506 .resume = sc1200_resume,
507#endif
504}; 508};
505 509
506static int sc1200_ide_init(void) 510static int sc1200_ide_init(void)
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index f063d954236c..057548d07205 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -359,7 +359,7 @@ static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const cha
359 359
360 /* OSB4 : South Bridge and IDE */ 360 /* OSB4 : South Bridge and IDE */
361 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) { 361 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
362 isa_dev = pci_find_device(PCI_VENDOR_ID_SERVERWORKS, 362 isa_dev = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
363 PCI_DEVICE_ID_SERVERWORKS_OSB4, NULL); 363 PCI_DEVICE_ID_SERVERWORKS_OSB4, NULL);
364 if (isa_dev) { 364 if (isa_dev) {
365 pci_read_config_dword(isa_dev, 0x64, &reg); 365 pci_read_config_dword(isa_dev, 0x64, &reg);
@@ -380,7 +380,7 @@ static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const cha
380 if (!(PCI_FUNC(dev->devfn) & 1)) { 380 if (!(PCI_FUNC(dev->devfn) & 1)) {
381 struct pci_dev * findev = NULL; 381 struct pci_dev * findev = NULL;
382 u32 reg4c = 0; 382 u32 reg4c = 0;
383 findev = pci_find_device(PCI_VENDOR_ID_SERVERWORKS, 383 findev = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
384 PCI_DEVICE_ID_SERVERWORKS_CSB5, NULL); 384 PCI_DEVICE_ID_SERVERWORKS_CSB5, NULL);
385 if (findev) { 385 if (findev) {
386 pci_read_config_dword(findev, 0x4C, &reg4c); 386 pci_read_config_dword(findev, 0x4C, &reg4c);
@@ -388,6 +388,7 @@ static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const cha
388 reg4c |= 0x00000040; 388 reg4c |= 0x00000040;
389 reg4c |= 0x00000020; 389 reg4c |= 0x00000020;
390 pci_write_config_dword(findev, 0x4C, reg4c); 390 pci_write_config_dword(findev, 0x4C, reg4c);
391 pci_dev_put(findev);
391 } 392 }
392 outb_p(0x06, 0x0c00); 393 outb_p(0x06, 0x0c00);
393 dev->irq = inb_p(0x0c01); 394 dev->irq = inb_p(0x0c01);
@@ -395,12 +396,13 @@ static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const cha
395 struct pci_dev * findev = NULL; 396 struct pci_dev * findev = NULL;
396 u8 reg41 = 0; 397 u8 reg41 = 0;
397 398
398 findev = pci_find_device(PCI_VENDOR_ID_SERVERWORKS, 399 findev = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
399 PCI_DEVICE_ID_SERVERWORKS_CSB6, NULL); 400 PCI_DEVICE_ID_SERVERWORKS_CSB6, NULL);
400 if (findev) { 401 if (findev) {
401 pci_read_config_byte(findev, 0x41, &reg41); 402 pci_read_config_byte(findev, 0x41, &reg41);
402 reg41 &= ~0x40; 403 reg41 &= ~0x40;
403 pci_write_config_byte(findev, 0x41, reg41); 404 pci_write_config_byte(findev, 0x41, reg41);
405 pci_dev_put(findev);
404 } 406 }
405 /* 407 /*
406 * This is a device pin issue on CSB6. 408 * This is a device pin issue on CSB6.
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c
index d8a0d87df734..f3fe287fbd89 100644
--- a/drivers/ide/pci/sgiioc4.c
+++ b/drivers/ide/pci/sgiioc4.c
@@ -220,7 +220,7 @@ sgiioc4_ide_dma_end(ide_drive_t * drive)
220 ide_hwif_t *hwif = HWIF(drive); 220 ide_hwif_t *hwif = HWIF(drive);
221 u64 dma_base = hwif->dma_base; 221 u64 dma_base = hwif->dma_base;
222 int dma_stat = 0; 222 int dma_stat = 0;
223 unsigned long *ending_dma = (unsigned long *) hwif->dma_base2; 223 unsigned long *ending_dma = ide_get_hwifdata(hwif);
224 224
225 hwif->OUTL(IOC4_S_DMA_STOP, dma_base + IOC4_DMA_CTRL * 4); 225 hwif->OUTL(IOC4_S_DMA_STOP, dma_base + IOC4_DMA_CTRL * 4);
226 226
@@ -369,6 +369,7 @@ ide_dma_sgiioc4(ide_hwif_t * hwif, unsigned long dma_base)
369{ 369{
370 void __iomem *virt_dma_base; 370 void __iomem *virt_dma_base;
371 int num_ports = sizeof (ioc4_dma_regs_t); 371 int num_ports = sizeof (ioc4_dma_regs_t);
372 void *pad;
372 373
373 printk(KERN_INFO "%s: BM-DMA at 0x%04lx-0x%04lx\n", hwif->name, 374 printk(KERN_INFO "%s: BM-DMA at 0x%04lx-0x%04lx\n", hwif->name,
374 dma_base, dma_base + num_ports - 1); 375 dma_base, dma_base + num_ports - 1);
@@ -400,17 +401,14 @@ ide_dma_sgiioc4(ide_hwif_t * hwif, unsigned long dma_base)
400 401
401 hwif->sg_max_nents = IOC4_PRD_ENTRIES; 402 hwif->sg_max_nents = IOC4_PRD_ENTRIES;
402 403
403 hwif->dma_base2 = (unsigned long) 404 pad = pci_alloc_consistent(hwif->pci_dev, IOC4_IDE_CACHELINE_SIZE,
404 pci_alloc_consistent(hwif->pci_dev, 405 (dma_addr_t *) &(hwif->dma_status));
405 IOC4_IDE_CACHELINE_SIZE,
406 (dma_addr_t *) &(hwif->dma_status));
407 406
408 if (!hwif->dma_base2) 407 if (pad) {
409 goto dma_base2alloc_failure; 408 ide_set_hwifdata(hwif, pad);
410 409 return;
411 return; 410 }
412 411
413dma_base2alloc_failure:
414 pci_free_consistent(hwif->pci_dev, 412 pci_free_consistent(hwif->pci_dev,
415 IOC4_PRD_ENTRIES * IOC4_PRD_BYTES, 413 IOC4_PRD_ENTRIES * IOC4_PRD_BYTES,
416 hwif->dmatable_cpu, hwif->dmatable_dma); 414 hwif->dmatable_cpu, hwif->dmatable_dma);
@@ -476,7 +474,7 @@ sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive)
476 hwif->OUTL(dma_addr, dma_base + IOC4_DMA_PTR_L * 4); 474 hwif->OUTL(dma_addr, dma_base + IOC4_DMA_PTR_L * 4);
477 475
478 /* Address of the Ending DMA */ 476 /* Address of the Ending DMA */
479 memset((unsigned int *) hwif->dma_base2, 0, IOC4_IDE_CACHELINE_SIZE); 477 memset(ide_get_hwifdata(hwif), 0, IOC4_IDE_CACHELINE_SIZE);
480 ending_dma_addr = cpu_to_le32(hwif->dma_status); 478 ending_dma_addr = cpu_to_le32(hwif->dma_status);
481 hwif->OUTL(ending_dma_addr, dma_base + IOC4_DMA_END_ADDR * 4); 479 hwif->OUTL(ending_dma_addr, dma_base + IOC4_DMA_END_ADDR * 4);
482 480
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index 20b392948f36..697f566fb90a 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -898,7 +898,6 @@ static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif)
898 base = (unsigned long) addr; 898 base = (unsigned long) addr;
899 899
900 hwif->dma_base = base + (ch ? 0x08 : 0x00); 900 hwif->dma_base = base + (ch ? 0x08 : 0x00);
901 hwif->dma_base2 = base + (ch ? 0x18 : 0x10);
902 hwif->mmio = 2; 901 hwif->mmio = 2;
903} 902}
904 903
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index f03196c5db37..92edf76bd7ad 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -739,7 +739,7 @@ static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const c
739 739
740 for (i = 0; i < ARRAY_SIZE(SiSHostChipInfo) && !chipset_family; i++) { 740 for (i = 0; i < ARRAY_SIZE(SiSHostChipInfo) && !chipset_family; i++) {
741 741
742 host = pci_find_device(PCI_VENDOR_ID_SI, SiSHostChipInfo[i].host_id, NULL); 742 host = pci_get_device(PCI_VENDOR_ID_SI, SiSHostChipInfo[i].host_id, NULL);
743 743
744 if (!host) 744 if (!host)
745 continue; 745 continue;
@@ -753,6 +753,7 @@ static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const c
753 if (hostrev >= 0x30) 753 if (hostrev >= 0x30)
754 chipset_family = ATA_100a; 754 chipset_family = ATA_100a;
755 } 755 }
756 pci_dev_put(host);
756 757
757 printk(KERN_INFO "SIS5513: %s %s controller\n", 758 printk(KERN_INFO "SIS5513: %s %s controller\n",
758 SiSHostChipInfo[i].name, chipset_capability[chipset_family]); 759 SiSHostChipInfo[i].name, chipset_capability[chipset_family]);
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index 9b7589e8e93e..2af634d7acf4 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -248,7 +248,7 @@ static struct via_isa_bridge *via_config_find(struct pci_dev **isa)
248 u8 t; 248 u8 t;
249 249
250 for (via_config = via_isa_bridges; via_config->id; via_config++) 250 for (via_config = via_isa_bridges; via_config->id; via_config++)
251 if ((*isa = pci_find_device(PCI_VENDOR_ID_VIA + 251 if ((*isa = pci_get_device(PCI_VENDOR_ID_VIA +
252 !!(via_config->flags & VIA_BAD_ID), 252 !!(via_config->flags & VIA_BAD_ID),
253 via_config->id, NULL))) { 253 via_config->id, NULL))) {
254 254
@@ -256,6 +256,7 @@ static struct via_isa_bridge *via_config_find(struct pci_dev **isa)
256 if (t >= via_config->rev_min && 256 if (t >= via_config->rev_min &&
257 t <= via_config->rev_max) 257 t <= via_config->rev_max)
258 break; 258 break;
259 pci_dev_put(*isa);
259 } 260 }
260 261
261 return via_config; 262 return via_config;
@@ -283,6 +284,7 @@ static unsigned int __devinit init_chipset_via82cxxx(struct pci_dev *dev, const
283 via_config = via_config_find(&isa); 284 via_config = via_config_find(&isa);
284 if (!via_config->id) { 285 if (!via_config->id) {
285 printk(KERN_WARNING "VP_IDE: Unknown VIA SouthBridge, disabling DMA.\n"); 286 printk(KERN_WARNING "VP_IDE: Unknown VIA SouthBridge, disabling DMA.\n");
287 pci_dev_put(isa);
286 return -ENODEV; 288 return -ENODEV;
287 } 289 }
288 290
@@ -361,6 +363,7 @@ static unsigned int __devinit init_chipset_via82cxxx(struct pci_dev *dev, const
361 via_dma[via_config->flags & VIA_UDMA], 363 via_dma[via_config->flags & VIA_UDMA],
362 pci_name(dev)); 364 pci_name(dev));
363 365
366 pci_dev_put(isa);
364 return 0; 367 return 0;
365} 368}
366 369
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index 996c694341bc..31ad79f52df7 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -1369,15 +1369,16 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
1369} 1369}
1370 1370
1371static int 1371static int
1372pmac_ide_macio_suspend(struct macio_dev *mdev, pm_message_t state) 1372pmac_ide_macio_suspend(struct macio_dev *mdev, pm_message_t mesg)
1373{ 1373{
1374 ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev); 1374 ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev);
1375 int rc = 0; 1375 int rc = 0;
1376 1376
1377 if (state.event != mdev->ofdev.dev.power.power_state.event && state.event >= PM_EVENT_SUSPEND) { 1377 if (mesg.event != mdev->ofdev.dev.power.power_state.event
1378 && mesg.event == PM_EVENT_SUSPEND) {
1378 rc = pmac_ide_do_suspend(hwif); 1379 rc = pmac_ide_do_suspend(hwif);
1379 if (rc == 0) 1380 if (rc == 0)
1380 mdev->ofdev.dev.power.power_state = state; 1381 mdev->ofdev.dev.power.power_state = mesg;
1381 } 1382 }
1382 1383
1383 return rc; 1384 return rc;
@@ -1473,15 +1474,16 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1473} 1474}
1474 1475
1475static int 1476static int
1476pmac_ide_pci_suspend(struct pci_dev *pdev, pm_message_t state) 1477pmac_ide_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
1477{ 1478{
1478 ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev); 1479 ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev);
1479 int rc = 0; 1480 int rc = 0;
1480 1481
1481 if (state.event != pdev->dev.power.power_state.event && state.event >= 2) { 1482 if (mesg.event != pdev->dev.power.power_state.event
1483 && mesg.event == PM_EVENT_SUSPEND) {
1482 rc = pmac_ide_do_suspend(hwif); 1484 rc = pmac_ide_do_suspend(hwif);
1483 if (rc == 0) 1485 if (rc == 0)
1484 pdev->dev.power.power_state = state; 1486 pdev->dev.power.power_state = mesg;
1485 } 1487 }
1486 1488
1487 return rc; 1489 return rc;
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index eb0945284acc..0719b6484824 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -101,7 +101,7 @@ static ide_hwif_t *ide_match_hwif(unsigned long io_base, u8 bootable, const char
101 return hwif; /* pick an unused entry */ 101 return hwif; /* pick an unused entry */
102 } 102 }
103 } 103 }
104 for (h = 0; h < 2; ++h) { 104 for (h = 0; h < 2 && h < MAX_HWIFS; ++h) {
105 hwif = ide_hwifs + h; 105 hwif = ide_hwifs + h;
106 if (hwif->chipset == ide_unknown) 106 if (hwif->chipset == ide_unknown)
107 return hwif; /* pick an unused entry */ 107 return hwif; /* pick an unused entry */
@@ -795,24 +795,6 @@ int __ide_pci_register_driver(struct pci_driver *driver, struct module *module)
795EXPORT_SYMBOL_GPL(__ide_pci_register_driver); 795EXPORT_SYMBOL_GPL(__ide_pci_register_driver);
796 796
797/** 797/**
798 * ide_unregister_pci_driver - unregister an IDE driver
799 * @driver: driver to remove
800 *
801 * Unregister a currently installed IDE driver. Returns are the same
802 * as for pci_unregister_driver
803 */
804
805void ide_pci_unregister_driver(struct pci_driver *driver)
806{
807 if(!pre_init)
808 pci_unregister_driver(driver);
809 else
810 list_del(&driver->node);
811}
812
813EXPORT_SYMBOL_GPL(ide_pci_unregister_driver);
814
815/**
816 * ide_scan_pcidev - find an IDE driver for a device 798 * ide_scan_pcidev - find an IDE driver for a device
817 * @dev: PCI device to check 799 * @dev: PCI device to check
818 * 800 *
diff --git a/drivers/ieee1394/Kconfig b/drivers/ieee1394/Kconfig
index 186737539cf5..2769e505f051 100644
--- a/drivers/ieee1394/Kconfig
+++ b/drivers/ieee1394/Kconfig
@@ -120,12 +120,19 @@ config IEEE1394_VIDEO1394
120 this option only if you have an IEEE 1394 video device connected to 120 this option only if you have an IEEE 1394 video device connected to
121 an OHCI-1394 card. 121 an OHCI-1394 card.
122 122
123comment "SBP-2 support (for storage devices) requires SCSI"
124 depends on IEEE1394 && SCSI=n
125
123config IEEE1394_SBP2 126config IEEE1394_SBP2
124 tristate "SBP-2 support (Harddisks etc.)" 127 tristate "SBP-2 support (Harddisks etc.)"
125 depends on IEEE1394 && SCSI && (PCI || BROKEN) 128 depends on IEEE1394 && SCSI && (PCI || BROKEN)
126 help 129 help
127 This option enables you to use SBP-2 devices connected to your IEEE 130 This option enables you to use SBP-2 devices connected to an IEEE
128 1394 bus. SBP-2 devices include harddrives and DVD devices. 131 1394 bus. SBP-2 devices include storage devices like harddisks and
132 DVD drives, also some other FireWire devices like scanners.
133
134 You should also enable support for disks, CD-ROMs, etc. in the SCSI
135 configuration section.
129 136
130config IEEE1394_SBP2_PHYS_DMA 137config IEEE1394_SBP2_PHYS_DMA
131 bool "Enable replacement for physical DMA in SBP2" 138 bool "Enable replacement for physical DMA in SBP2"
diff --git a/drivers/ieee1394/csr.c b/drivers/ieee1394/csr.c
index 149573db91c5..ab0c80f61b9d 100644
--- a/drivers/ieee1394/csr.c
+++ b/drivers/ieee1394/csr.c
@@ -17,11 +17,13 @@
17 * 17 *
18 */ 18 */
19 19
20#include <linux/string.h> 20#include <linux/jiffies.h>
21#include <linux/kernel.h>
21#include <linux/module.h> 22#include <linux/module.h>
22#include <linux/moduleparam.h> 23#include <linux/moduleparam.h>
23#include <linux/param.h> 24#include <linux/param.h>
24#include <linux/spinlock.h> 25#include <linux/spinlock.h>
26#include <linux/string.h>
25 27
26#include "csr1212.h" 28#include "csr1212.h"
27#include "ieee1394_types.h" 29#include "ieee1394_types.h"
@@ -149,31 +151,18 @@ static void host_reset(struct hpsb_host *host)
149 151
150/* 152/*
151 * HI == seconds (bits 0:2) 153 * HI == seconds (bits 0:2)
152 * LO == fraction units of 1/8000 of a second, as per 1394 (bits 19:31) 154 * LO == fractions of a second in units of 125usec (bits 19:31)
153 *
154 * Convert to units and then to HZ, for comparison to jiffies.
155 *
156 * By default this will end up being 800 units, or 100ms (125usec per
157 * unit).
158 * 155 *
159 * NOTE: The spec says 1/8000, but also says we can compute based on 1/8192 156 * Convert SPLIT_TIMEOUT to jiffies.
160 * like CSR specifies. Should make our math less complex. 157 * The default and minimum as per 1394a-2000 clause 8.3.2.2.6 is 100ms.
161 */ 158 */
162static inline void calculate_expire(struct csr_control *csr) 159static inline void calculate_expire(struct csr_control *csr)
163{ 160{
164 unsigned long units; 161 unsigned long usecs =
165 162 (csr->split_timeout_hi & 0x07) * USEC_PER_SEC +
166 /* Take the seconds, and convert to units */ 163 (csr->split_timeout_lo >> 19) * 125L;
167 units = (unsigned long)(csr->split_timeout_hi & 0x07) << 13;
168
169 /* Add in the fractional units */
170 units += (unsigned long)(csr->split_timeout_lo >> 19);
171
172 /* Convert to jiffies */
173 csr->expire = (unsigned long)(units * HZ) >> 13UL;
174 164
175 /* Just to keep from rounding low */ 165 csr->expire = usecs_to_jiffies(usecs > 100000L ? usecs : 100000L);
176 csr->expire++;
177 166
178 HPSB_VERBOSE("CSR: setting expire to %lu, HZ=%u", csr->expire, HZ); 167 HPSB_VERBOSE("CSR: setting expire to %lu, HZ=%u", csr->expire, HZ);
179} 168}
diff --git a/drivers/ieee1394/csr.h b/drivers/ieee1394/csr.h
index ea9aa4f53ab6..f11546550d84 100644
--- a/drivers/ieee1394/csr.h
+++ b/drivers/ieee1394/csr.h
@@ -1,75 +1,73 @@
1
2#ifndef _IEEE1394_CSR_H 1#ifndef _IEEE1394_CSR_H
3#define _IEEE1394_CSR_H 2#define _IEEE1394_CSR_H
4 3
5#ifdef CONFIG_PREEMPT 4#include <linux/spinlock_types.h>
6#include <linux/sched.h>
7#endif
8 5
9#include "csr1212.h" 6#include "csr1212.h"
7#include "ieee1394_types.h"
10 8
11#define CSR_REGISTER_BASE 0xfffff0000000ULL 9#define CSR_REGISTER_BASE 0xfffff0000000ULL
12 10
13/* register offsets relative to CSR_REGISTER_BASE */ 11/* register offsets relative to CSR_REGISTER_BASE */
14#define CSR_STATE_CLEAR 0x0 12#define CSR_STATE_CLEAR 0x0
15#define CSR_STATE_SET 0x4 13#define CSR_STATE_SET 0x4
16#define CSR_NODE_IDS 0x8 14#define CSR_NODE_IDS 0x8
17#define CSR_RESET_START 0xc 15#define CSR_RESET_START 0xc
18#define CSR_SPLIT_TIMEOUT_HI 0x18 16#define CSR_SPLIT_TIMEOUT_HI 0x18
19#define CSR_SPLIT_TIMEOUT_LO 0x1c 17#define CSR_SPLIT_TIMEOUT_LO 0x1c
20#define CSR_CYCLE_TIME 0x200 18#define CSR_CYCLE_TIME 0x200
21#define CSR_BUS_TIME 0x204 19#define CSR_BUS_TIME 0x204
22#define CSR_BUSY_TIMEOUT 0x210 20#define CSR_BUSY_TIMEOUT 0x210
23#define CSR_BUS_MANAGER_ID 0x21c 21#define CSR_BUS_MANAGER_ID 0x21c
24#define CSR_BANDWIDTH_AVAILABLE 0x220 22#define CSR_BANDWIDTH_AVAILABLE 0x220
25#define CSR_CHANNELS_AVAILABLE 0x224 23#define CSR_CHANNELS_AVAILABLE 0x224
26#define CSR_CHANNELS_AVAILABLE_HI 0x224 24#define CSR_CHANNELS_AVAILABLE_HI 0x224
27#define CSR_CHANNELS_AVAILABLE_LO 0x228 25#define CSR_CHANNELS_AVAILABLE_LO 0x228
28#define CSR_BROADCAST_CHANNEL 0x234 26#define CSR_BROADCAST_CHANNEL 0x234
29#define CSR_CONFIG_ROM 0x400 27#define CSR_CONFIG_ROM 0x400
30#define CSR_CONFIG_ROM_END 0x800 28#define CSR_CONFIG_ROM_END 0x800
31#define CSR_FCP_COMMAND 0xB00 29#define CSR_FCP_COMMAND 0xB00
32#define CSR_FCP_RESPONSE 0xD00 30#define CSR_FCP_RESPONSE 0xD00
33#define CSR_FCP_END 0xF00 31#define CSR_FCP_END 0xF00
34#define CSR_TOPOLOGY_MAP 0x1000 32#define CSR_TOPOLOGY_MAP 0x1000
35#define CSR_TOPOLOGY_MAP_END 0x1400 33#define CSR_TOPOLOGY_MAP_END 0x1400
36#define CSR_SPEED_MAP 0x2000 34#define CSR_SPEED_MAP 0x2000
37#define CSR_SPEED_MAP_END 0x3000 35#define CSR_SPEED_MAP_END 0x3000
38 36
39/* IEEE 1394 bus specific Configuration ROM Key IDs */ 37/* IEEE 1394 bus specific Configuration ROM Key IDs */
40#define IEEE1394_KV_ID_POWER_REQUIREMENTS (0x30) 38#define IEEE1394_KV_ID_POWER_REQUIREMENTS (0x30)
41 39
42/* IEEE 1394 Bus Inforamation Block specifics */ 40/* IEEE 1394 Bus Information Block specifics */
43#define CSR_BUS_INFO_SIZE (5 * sizeof(quadlet_t)) 41#define CSR_BUS_INFO_SIZE (5 * sizeof(quadlet_t))
44 42
45#define CSR_IRMC_SHIFT 31 43#define CSR_IRMC_SHIFT 31
46#define CSR_CMC_SHIFT 30 44#define CSR_CMC_SHIFT 30
47#define CSR_ISC_SHIFT 29 45#define CSR_ISC_SHIFT 29
48#define CSR_BMC_SHIFT 28 46#define CSR_BMC_SHIFT 28
49#define CSR_PMC_SHIFT 27 47#define CSR_PMC_SHIFT 27
50#define CSR_CYC_CLK_ACC_SHIFT 16 48#define CSR_CYC_CLK_ACC_SHIFT 16
51#define CSR_MAX_REC_SHIFT 12 49#define CSR_MAX_REC_SHIFT 12
52#define CSR_MAX_ROM_SHIFT 8 50#define CSR_MAX_ROM_SHIFT 8
53#define CSR_GENERATION_SHIFT 4 51#define CSR_GENERATION_SHIFT 4
54 52
55#define CSR_SET_BUS_INFO_GENERATION(csr, gen) \ 53#define CSR_SET_BUS_INFO_GENERATION(csr, gen) \
56 ((csr)->bus_info_data[2] = \ 54 ((csr)->bus_info_data[2] = \
57 cpu_to_be32((be32_to_cpu((csr)->bus_info_data[2]) & \ 55 cpu_to_be32((be32_to_cpu((csr)->bus_info_data[2]) & \
58 ~(0xf << CSR_GENERATION_SHIFT)) | \ 56 ~(0xf << CSR_GENERATION_SHIFT)) | \
59 (gen) << CSR_GENERATION_SHIFT)) 57 (gen) << CSR_GENERATION_SHIFT))
60 58
61struct csr_control { 59struct csr_control {
62 spinlock_t lock; 60 spinlock_t lock;
63 61
64 quadlet_t state; 62 quadlet_t state;
65 quadlet_t node_ids; 63 quadlet_t node_ids;
66 quadlet_t split_timeout_hi, split_timeout_lo; 64 quadlet_t split_timeout_hi, split_timeout_lo;
67 unsigned long expire; // Calculated from split_timeout 65 unsigned long expire; /* Calculated from split_timeout */
68 quadlet_t cycle_time; 66 quadlet_t cycle_time;
69 quadlet_t bus_time; 67 quadlet_t bus_time;
70 quadlet_t bus_manager_id; 68 quadlet_t bus_manager_id;
71 quadlet_t bandwidth_available; 69 quadlet_t bandwidth_available;
72 quadlet_t channels_available_hi, channels_available_lo; 70 quadlet_t channels_available_hi, channels_available_lo;
73 quadlet_t broadcast_channel; 71 quadlet_t broadcast_channel;
74 72
75 /* Bus Info */ 73 /* Bus Info */
@@ -84,8 +82,8 @@ struct csr_control {
84 82
85 struct csr1212_csr *rom; 83 struct csr1212_csr *rom;
86 84
87 quadlet_t topology_map[256]; 85 quadlet_t topology_map[256];
88 quadlet_t speed_map[1024]; 86 quadlet_t speed_map[1024];
89}; 87};
90 88
91extern struct csr1212_bus_ops csr_bus_ops; 89extern struct csr1212_bus_ops csr_bus_ops;
@@ -93,4 +91,9 @@ extern struct csr1212_bus_ops csr_bus_ops;
93int init_csr(void); 91int init_csr(void);
94void cleanup_csr(void); 92void cleanup_csr(void);
95 93
94/* hpsb_update_config_rom() is deprecated */
95struct hpsb_host;
96int hpsb_update_config_rom(struct hpsb_host *host, const quadlet_t *new_rom,
97 size_t size, unsigned char rom_version);
98
96#endif /* _IEEE1394_CSR_H */ 99#endif /* _IEEE1394_CSR_H */
diff --git a/drivers/ieee1394/dma.c b/drivers/ieee1394/dma.c
index ca5167de707d..c68f328e1a29 100644
--- a/drivers/ieee1394/dma.c
+++ b/drivers/ieee1394/dma.c
@@ -7,10 +7,13 @@
7 * directory of the kernel sources for details. 7 * directory of the kernel sources for details.
8 */ 8 */
9 9
10#include <linux/mm.h>
10#include <linux/module.h> 11#include <linux/module.h>
11#include <linux/vmalloc.h> 12#include <linux/pci.h>
12#include <linux/slab.h> 13#include <linux/slab.h>
13#include <linux/mm.h> 14#include <linux/vmalloc.h>
15#include <asm/scatterlist.h>
16
14#include "dma.h" 17#include "dma.h"
15 18
16/* dma_prog_region */ 19/* dma_prog_region */
diff --git a/drivers/ieee1394/dma.h b/drivers/ieee1394/dma.h
index 061550a6fb99..a1682aba71c7 100644
--- a/drivers/ieee1394/dma.h
+++ b/drivers/ieee1394/dma.h
@@ -10,69 +10,91 @@
10#ifndef IEEE1394_DMA_H 10#ifndef IEEE1394_DMA_H
11#define IEEE1394_DMA_H 11#define IEEE1394_DMA_H
12 12
13#include <linux/pci.h> 13#include <asm/types.h>
14#include <asm/scatterlist.h> 14
15 15struct pci_dev;
16/* struct dma_prog_region 16struct scatterlist;
17 17struct vm_area_struct;
18 a small, physically-contiguous DMA buffer with random-access, 18
19 synchronous usage characteristics 19/**
20*/ 20 * struct dma_prog_region - small contiguous DMA buffer
21 21 * @kvirt: kernel virtual address
22 * @dev: PCI device
23 * @n_pages: number of kernel pages
24 * @bus_addr: base bus address
25 *
26 * a small, physically contiguous DMA buffer with random-access, synchronous
27 * usage characteristics
28 */
22struct dma_prog_region { 29struct dma_prog_region {
23 unsigned char *kvirt; /* kernel virtual address */ 30 unsigned char *kvirt;
24 struct pci_dev *dev; /* PCI device */ 31 struct pci_dev *dev;
25 unsigned int n_pages; /* # of kernel pages */ 32 unsigned int n_pages;
26 dma_addr_t bus_addr; /* base bus address */ 33 dma_addr_t bus_addr;
27}; 34};
28 35
29/* clear out all fields but do not allocate any memory */ 36/* clear out all fields but do not allocate any memory */
30void dma_prog_region_init(struct dma_prog_region *prog); 37void dma_prog_region_init(struct dma_prog_region *prog);
31int dma_prog_region_alloc(struct dma_prog_region *prog, unsigned long n_bytes, struct pci_dev *dev); 38int dma_prog_region_alloc(struct dma_prog_region *prog, unsigned long n_bytes,
39 struct pci_dev *dev);
32void dma_prog_region_free(struct dma_prog_region *prog); 40void dma_prog_region_free(struct dma_prog_region *prog);
33 41
34static inline dma_addr_t dma_prog_region_offset_to_bus(struct dma_prog_region *prog, unsigned long offset) 42static inline dma_addr_t dma_prog_region_offset_to_bus(
43 struct dma_prog_region *prog, unsigned long offset)
35{ 44{
36 return prog->bus_addr + offset; 45 return prog->bus_addr + offset;
37} 46}
38 47
39/* struct dma_region 48/**
40 49 * struct dma_region - large non-contiguous DMA buffer
41 a large, non-physically-contiguous DMA buffer with streaming, 50 * @virt: kernel virtual address
42 asynchronous usage characteristics 51 * @dev: PCI device
43*/ 52 * @n_pages: number of kernel pages
44 53 * @n_dma_pages: number of IOMMU pages
54 * @sglist: IOMMU mapping
55 * @direction: PCI_DMA_TODEVICE, etc.
56 *
57 * a large, non-physically-contiguous DMA buffer with streaming, asynchronous
58 * usage characteristics
59 */
45struct dma_region { 60struct dma_region {
46 unsigned char *kvirt; /* kernel virtual address */ 61 unsigned char *kvirt;
47 struct pci_dev *dev; /* PCI device */ 62 struct pci_dev *dev;
48 unsigned int n_pages; /* # of kernel pages */ 63 unsigned int n_pages;
49 unsigned int n_dma_pages; /* # of IOMMU pages */ 64 unsigned int n_dma_pages;
50 struct scatterlist *sglist; /* IOMMU mapping */ 65 struct scatterlist *sglist;
51 int direction; /* PCI_DMA_TODEVICE, etc */ 66 int direction;
52}; 67};
53 68
54/* clear out all fields but do not allocate anything */ 69/* clear out all fields but do not allocate anything */
55void dma_region_init(struct dma_region *dma); 70void dma_region_init(struct dma_region *dma);
56 71
57/* allocate the buffer and map it to the IOMMU */ 72/* allocate the buffer and map it to the IOMMU */
58int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes, struct pci_dev *dev, int direction); 73int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes,
74 struct pci_dev *dev, int direction);
59 75
60/* unmap and free the buffer */ 76/* unmap and free the buffer */
61void dma_region_free(struct dma_region *dma); 77void dma_region_free(struct dma_region *dma);
62 78
63/* sync the CPU's view of the buffer */ 79/* sync the CPU's view of the buffer */
64void dma_region_sync_for_cpu(struct dma_region *dma, unsigned long offset, unsigned long len); 80void dma_region_sync_for_cpu(struct dma_region *dma, unsigned long offset,
81 unsigned long len);
82
65/* sync the IO bus' view of the buffer */ 83/* sync the IO bus' view of the buffer */
66void dma_region_sync_for_device(struct dma_region *dma, unsigned long offset, unsigned long len); 84void dma_region_sync_for_device(struct dma_region *dma, unsigned long offset,
85 unsigned long len);
67 86
68/* map the buffer into a user space process */ 87/* map the buffer into a user space process */
69int dma_region_mmap(struct dma_region *dma, struct file *file, struct vm_area_struct *vma); 88int dma_region_mmap(struct dma_region *dma, struct file *file,
89 struct vm_area_struct *vma);
70 90
71/* macro to index into a DMA region (or dma_prog_region) */ 91/* macro to index into a DMA region (or dma_prog_region) */
72#define dma_region_i(_dma, _type, _index) ( ((_type*) ((_dma)->kvirt)) + (_index) ) 92#define dma_region_i(_dma, _type, _index) \
93 ( ((_type*) ((_dma)->kvirt)) + (_index) )
73 94
74/* return the DMA bus address of the byte with the given offset 95/* return the DMA bus address of the byte with the given offset
75 relative to the beginning of the dma_region */ 96 * relative to the beginning of the dma_region */
76dma_addr_t dma_region_offset_to_bus(struct dma_region *dma, unsigned long offset); 97dma_addr_t dma_region_offset_to_bus(struct dma_region *dma,
98 unsigned long offset);
77 99
78#endif /* IEEE1394_DMA_H */ 100#endif /* IEEE1394_DMA_H */
diff --git a/drivers/ieee1394/dv1394-private.h b/drivers/ieee1394/dv1394-private.h
index 80b5ac7fe383..7d1d2845b420 100644
--- a/drivers/ieee1394/dv1394-private.h
+++ b/drivers/ieee1394/dv1394-private.h
@@ -460,7 +460,7 @@ struct video_card {
460 int dma_running; 460 int dma_running;
461 461
462 /* 462 /*
463 3) the sleeping semaphore 'sem' - this is used from process context only, 463 3) the sleeping mutex 'mtx' - this is used from process context only,
464 to serialize various operations on the video_card. Even though only one 464 to serialize various operations on the video_card. Even though only one
465 open() is allowed, we still need to prevent multiple threads of execution 465 open() is allowed, we still need to prevent multiple threads of execution
466 from entering calls like read, write, ioctl, etc. 466 from entering calls like read, write, ioctl, etc.
@@ -468,9 +468,9 @@ struct video_card {
468 I honestly can't think of a good reason to use dv1394 from several threads 468 I honestly can't think of a good reason to use dv1394 from several threads
469 at once, but we need to serialize anyway to prevent oopses =). 469 at once, but we need to serialize anyway to prevent oopses =).
470 470
471 NOTE: if you need both spinlock and sem, take sem first to avoid deadlock! 471 NOTE: if you need both spinlock and mtx, take mtx first to avoid deadlock!
472 */ 472 */
473 struct semaphore sem; 473 struct mutex mtx;
474 474
475 /* people waiting for buffer space, please form a line here... */ 475 /* people waiting for buffer space, please form a line here... */
476 wait_queue_head_t waitq; 476 wait_queue_head_t waitq;
diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c
index 87532dd43374..6c72f04b2b5d 100644
--- a/drivers/ieee1394/dv1394.c
+++ b/drivers/ieee1394/dv1394.c
@@ -95,6 +95,7 @@
95#include <linux/fs.h> 95#include <linux/fs.h>
96#include <linux/poll.h> 96#include <linux/poll.h>
97#include <linux/smp_lock.h> 97#include <linux/smp_lock.h>
98#include <linux/mutex.h>
98#include <linux/bitops.h> 99#include <linux/bitops.h>
99#include <asm/byteorder.h> 100#include <asm/byteorder.h>
100#include <asm/atomic.h> 101#include <asm/atomic.h>
@@ -110,15 +111,15 @@
110#include <linux/compat.h> 111#include <linux/compat.h>
111#include <linux/cdev.h> 112#include <linux/cdev.h>
112 113
114#include "dv1394.h"
115#include "dv1394-private.h"
116#include "highlevel.h"
117#include "hosts.h"
113#include "ieee1394.h" 118#include "ieee1394.h"
119#include "ieee1394_core.h"
120#include "ieee1394_hotplug.h"
114#include "ieee1394_types.h" 121#include "ieee1394_types.h"
115#include "nodemgr.h" 122#include "nodemgr.h"
116#include "hosts.h"
117#include "ieee1394_core.h"
118#include "highlevel.h"
119#include "dv1394.h"
120#include "dv1394-private.h"
121
122#include "ohci1394.h" 123#include "ohci1394.h"
123 124
124/* DEBUG LEVELS: 125/* DEBUG LEVELS:
@@ -136,13 +137,13 @@
136#if DV1394_DEBUG_LEVEL >= 2 137#if DV1394_DEBUG_LEVEL >= 2
137#define irq_printk( args... ) printk( args ) 138#define irq_printk( args... ) printk( args )
138#else 139#else
139#define irq_printk( args... ) 140#define irq_printk( args... ) do {} while (0)
140#endif 141#endif
141 142
142#if DV1394_DEBUG_LEVEL >= 1 143#if DV1394_DEBUG_LEVEL >= 1
143#define debug_printk( args... ) printk( args) 144#define debug_printk( args... ) printk( args)
144#else 145#else
145#define debug_printk( args... ) 146#define debug_printk( args... ) do {} while (0)
146#endif 147#endif
147 148
148/* issue a dummy PCI read to force the preceding write 149/* issue a dummy PCI read to force the preceding write
@@ -247,7 +248,7 @@ static void frame_delete(struct frame *f)
247 248
248 Frame_prepare() must be called OUTSIDE the video->spinlock. 249 Frame_prepare() must be called OUTSIDE the video->spinlock.
249 However, frame_prepare() must still be serialized, so 250 However, frame_prepare() must still be serialized, so
250 it should be called WITH the video->sem taken. 251 it should be called WITH the video->mtx taken.
251 */ 252 */
252 253
253static void frame_prepare(struct video_card *video, unsigned int this_frame) 254static void frame_prepare(struct video_card *video, unsigned int this_frame)
@@ -1271,7 +1272,7 @@ static int dv1394_mmap(struct file *file, struct vm_area_struct *vma)
1271 int retval = -EINVAL; 1272 int retval = -EINVAL;
1272 1273
1273 /* serialize mmap */ 1274 /* serialize mmap */
1274 down(&video->sem); 1275 mutex_lock(&video->mtx);
1275 1276
1276 if ( ! video_card_initialized(video) ) { 1277 if ( ! video_card_initialized(video) ) {
1277 retval = do_dv1394_init_default(video); 1278 retval = do_dv1394_init_default(video);
@@ -1281,7 +1282,7 @@ static int dv1394_mmap(struct file *file, struct vm_area_struct *vma)
1281 1282
1282 retval = dma_region_mmap(&video->dv_buf, file, vma); 1283 retval = dma_region_mmap(&video->dv_buf, file, vma);
1283out: 1284out:
1284 up(&video->sem); 1285 mutex_unlock(&video->mtx);
1285 return retval; 1286 return retval;
1286} 1287}
1287 1288
@@ -1337,17 +1338,17 @@ static ssize_t dv1394_write(struct file *file, const char __user *buffer, size_t
1337 1338
1338 /* serialize this to prevent multi-threaded mayhem */ 1339 /* serialize this to prevent multi-threaded mayhem */
1339 if (file->f_flags & O_NONBLOCK) { 1340 if (file->f_flags & O_NONBLOCK) {
1340 if (down_trylock(&video->sem)) 1341 if (!mutex_trylock(&video->mtx))
1341 return -EAGAIN; 1342 return -EAGAIN;
1342 } else { 1343 } else {
1343 if (down_interruptible(&video->sem)) 1344 if (mutex_lock_interruptible(&video->mtx))
1344 return -ERESTARTSYS; 1345 return -ERESTARTSYS;
1345 } 1346 }
1346 1347
1347 if ( !video_card_initialized(video) ) { 1348 if ( !video_card_initialized(video) ) {
1348 ret = do_dv1394_init_default(video); 1349 ret = do_dv1394_init_default(video);
1349 if (ret) { 1350 if (ret) {
1350 up(&video->sem); 1351 mutex_unlock(&video->mtx);
1351 return ret; 1352 return ret;
1352 } 1353 }
1353 } 1354 }
@@ -1418,7 +1419,7 @@ static ssize_t dv1394_write(struct file *file, const char __user *buffer, size_t
1418 1419
1419 remove_wait_queue(&video->waitq, &wait); 1420 remove_wait_queue(&video->waitq, &wait);
1420 set_current_state(TASK_RUNNING); 1421 set_current_state(TASK_RUNNING);
1421 up(&video->sem); 1422 mutex_unlock(&video->mtx);
1422 return ret; 1423 return ret;
1423} 1424}
1424 1425
@@ -1434,17 +1435,17 @@ static ssize_t dv1394_read(struct file *file, char __user *buffer, size_t count
1434 1435
1435 /* serialize this to prevent multi-threaded mayhem */ 1436 /* serialize this to prevent multi-threaded mayhem */
1436 if (file->f_flags & O_NONBLOCK) { 1437 if (file->f_flags & O_NONBLOCK) {
1437 if (down_trylock(&video->sem)) 1438 if (!mutex_trylock(&video->mtx))
1438 return -EAGAIN; 1439 return -EAGAIN;
1439 } else { 1440 } else {
1440 if (down_interruptible(&video->sem)) 1441 if (mutex_lock_interruptible(&video->mtx))
1441 return -ERESTARTSYS; 1442 return -ERESTARTSYS;
1442 } 1443 }
1443 1444
1444 if ( !video_card_initialized(video) ) { 1445 if ( !video_card_initialized(video) ) {
1445 ret = do_dv1394_init_default(video); 1446 ret = do_dv1394_init_default(video);
1446 if (ret) { 1447 if (ret) {
1447 up(&video->sem); 1448 mutex_unlock(&video->mtx);
1448 return ret; 1449 return ret;
1449 } 1450 }
1450 video->continuity_counter = -1; 1451 video->continuity_counter = -1;
@@ -1526,7 +1527,7 @@ static ssize_t dv1394_read(struct file *file, char __user *buffer, size_t count
1526 1527
1527 remove_wait_queue(&video->waitq, &wait); 1528 remove_wait_queue(&video->waitq, &wait);
1528 set_current_state(TASK_RUNNING); 1529 set_current_state(TASK_RUNNING);
1529 up(&video->sem); 1530 mutex_unlock(&video->mtx);
1530 return ret; 1531 return ret;
1531} 1532}
1532 1533
@@ -1547,12 +1548,12 @@ static long dv1394_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1547 1548
1548 /* serialize this to prevent multi-threaded mayhem */ 1549 /* serialize this to prevent multi-threaded mayhem */
1549 if (file->f_flags & O_NONBLOCK) { 1550 if (file->f_flags & O_NONBLOCK) {
1550 if (down_trylock(&video->sem)) { 1551 if (!mutex_trylock(&video->mtx)) {
1551 unlock_kernel(); 1552 unlock_kernel();
1552 return -EAGAIN; 1553 return -EAGAIN;
1553 } 1554 }
1554 } else { 1555 } else {
1555 if (down_interruptible(&video->sem)) { 1556 if (mutex_lock_interruptible(&video->mtx)) {
1556 unlock_kernel(); 1557 unlock_kernel();
1557 return -ERESTARTSYS; 1558 return -ERESTARTSYS;
1558 } 1559 }
@@ -1778,7 +1779,7 @@ static long dv1394_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1778 } 1779 }
1779 1780
1780 out: 1781 out:
1781 up(&video->sem); 1782 mutex_unlock(&video->mtx);
1782 unlock_kernel(); 1783 unlock_kernel();
1783 return ret; 1784 return ret;
1784} 1785}
@@ -2253,7 +2254,7 @@ static int dv1394_init(struct ti_ohci *ohci, enum pal_or_ntsc format, enum modes
2253 clear_bit(0, &video->open); 2254 clear_bit(0, &video->open);
2254 spin_lock_init(&video->spinlock); 2255 spin_lock_init(&video->spinlock);
2255 video->dma_running = 0; 2256 video->dma_running = 0;
2256 init_MUTEX(&video->sem); 2257 mutex_init(&video->mtx);
2257 init_waitqueue_head(&video->waitq); 2258 init_waitqueue_head(&video->waitq);
2258 video->fasync = NULL; 2259 video->fasync = NULL;
2259 2260
diff --git a/drivers/ieee1394/eth1394.c b/drivers/ieee1394/eth1394.c
index 2d5b57be98c3..8a7b8fab6238 100644
--- a/drivers/ieee1394/eth1394.c
+++ b/drivers/ieee1394/eth1394.c
@@ -64,19 +64,19 @@
64#include <linux/ethtool.h> 64#include <linux/ethtool.h>
65#include <asm/uaccess.h> 65#include <asm/uaccess.h>
66#include <asm/delay.h> 66#include <asm/delay.h>
67#include <asm/semaphore.h>
68#include <net/arp.h> 67#include <net/arp.h>
69 68
69#include "config_roms.h"
70#include "csr1212.h" 70#include "csr1212.h"
71#include "ieee1394_types.h" 71#include "eth1394.h"
72#include "highlevel.h"
73#include "ieee1394.h"
72#include "ieee1394_core.h" 74#include "ieee1394_core.h"
75#include "ieee1394_hotplug.h"
73#include "ieee1394_transactions.h" 76#include "ieee1394_transactions.h"
74#include "ieee1394.h" 77#include "ieee1394_types.h"
75#include "highlevel.h"
76#include "iso.h" 78#include "iso.h"
77#include "nodemgr.h" 79#include "nodemgr.h"
78#include "eth1394.h"
79#include "config_roms.h"
80 80
81#define ETH1394_PRINT_G(level, fmt, args...) \ 81#define ETH1394_PRINT_G(level, fmt, args...) \
82 printk(level "%s: " fmt, driver_name, ## args) 82 printk(level "%s: " fmt, driver_name, ## args)
diff --git a/drivers/ieee1394/highlevel.h b/drivers/ieee1394/highlevel.h
index e119fb87e5b5..50f2dd2c7e20 100644
--- a/drivers/ieee1394/highlevel.h
+++ b/drivers/ieee1394/highlevel.h
@@ -1,60 +1,61 @@
1
2#ifndef IEEE1394_HIGHLEVEL_H 1#ifndef IEEE1394_HIGHLEVEL_H
3#define IEEE1394_HIGHLEVEL_H 2#define IEEE1394_HIGHLEVEL_H
4 3
4#include <linux/list.h>
5#include <linux/spinlock_types.h>
6#include <linux/types.h>
5 7
6struct hpsb_address_serve { 8struct module;
7 struct list_head host_list; /* per host list */
8 9
9 struct list_head hl_list; /* hpsb_highlevel list */ 10#include "ieee1394_types.h"
10 11
11 struct hpsb_address_ops *op; 12struct hpsb_host;
12 13
14/* internal to ieee1394 core */
15struct hpsb_address_serve {
16 struct list_head host_list; /* per host list */
17 struct list_head hl_list; /* hpsb_highlevel list */
18 struct hpsb_address_ops *op;
13 struct hpsb_host *host; 19 struct hpsb_host *host;
14 20 u64 start; /* first address handled, quadlet aligned */
15 /* first address handled and first address behind, quadlet aligned */ 21 u64 end; /* first address behind, quadlet aligned */
16 u64 start, end;
17}; 22};
18 23
19 24/* Only the following structures are of interest to actual highlevel drivers. */
20/*
21 * The above structs are internal to highlevel driver handling. Only the
22 * following structures are of interest to actual highlevel drivers.
23 */
24 25
25struct hpsb_highlevel { 26struct hpsb_highlevel {
26 struct module *owner; 27 struct module *owner;
27 const char *name; 28 const char *name;
28 29
29 /* Any of the following pointers can legally be NULL, except for 30 /* Any of the following pointers can legally be NULL, except for
30 * iso_receive which can only be NULL when you don't request 31 * iso_receive which can only be NULL when you don't request
31 * channels. */ 32 * channels. */
32 33
33 /* New host initialized. Will also be called during 34 /* New host initialized. Will also be called during
34 * hpsb_register_highlevel for all hosts already installed. */ 35 * hpsb_register_highlevel for all hosts already installed. */
35 void (*add_host) (struct hpsb_host *host); 36 void (*add_host)(struct hpsb_host *host);
36 37
37 /* Host about to be removed. Will also be called during 38 /* Host about to be removed. Will also be called during
38 * hpsb_unregister_highlevel once for each host. */ 39 * hpsb_unregister_highlevel once for each host. */
39 void (*remove_host) (struct hpsb_host *host); 40 void (*remove_host)(struct hpsb_host *host);
40 41
41 /* Host experienced bus reset with possible configuration changes. 42 /* Host experienced bus reset with possible configuration changes.
42 * Note that this one may occur during interrupt/bottom half handling. 43 * Note that this one may occur during interrupt/bottom half handling.
43 * You can not expect to be able to do stock hpsb_reads. */ 44 * You can not expect to be able to do stock hpsb_reads. */
44 void (*host_reset) (struct hpsb_host *host); 45 void (*host_reset)(struct hpsb_host *host);
45 46
46 /* An isochronous packet was received. Channel contains the channel 47 /* An isochronous packet was received. Channel contains the channel
47 * number for your convenience, it is also contained in the included 48 * number for your convenience, it is also contained in the included
48 * packet header (first quadlet, CRCs are missing). You may get called 49 * packet header (first quadlet, CRCs are missing). You may get called
49 * for channel/host combinations you did not request. */ 50 * for channel/host combinations you did not request. */
50 void (*iso_receive) (struct hpsb_host *host, int channel, 51 void (*iso_receive)(struct hpsb_host *host, int channel,
51 quadlet_t *data, size_t length); 52 quadlet_t *data, size_t length);
52 53
53 /* A write request was received on either the FCP_COMMAND (direction = 54 /* A write request was received on either the FCP_COMMAND (direction =
54 * 0) or the FCP_RESPONSE (direction = 1) register. The cts arg 55 * 0) or the FCP_RESPONSE (direction = 1) register. The cts arg
55 * contains the cts field (first byte of data). */ 56 * contains the cts field (first byte of data). */
56 void (*fcp_request) (struct hpsb_host *host, int nodeid, int direction, 57 void (*fcp_request)(struct hpsb_host *host, int nodeid, int direction,
57 int cts, u8 *data, size_t length); 58 int cts, u8 *data, size_t length);
58 59
59 /* These are initialized by the subsystem when the 60 /* These are initialized by the subsystem when the
60 * hpsb_higlevel is registered. */ 61 * hpsb_higlevel is registered. */
@@ -67,61 +68,62 @@ struct hpsb_highlevel {
67}; 68};
68 69
69struct hpsb_address_ops { 70struct hpsb_address_ops {
70 /* 71 /*
71 * Null function pointers will make the respective operation complete 72 * Null function pointers will make the respective operation complete
72 * with RCODE_TYPE_ERROR. Makes for easy to implement read-only 73 * with RCODE_TYPE_ERROR. Makes for easy to implement read-only
73 * registers (just leave everything but read NULL). 74 * registers (just leave everything but read NULL).
74 * 75 *
75 * All functions shall return appropriate IEEE 1394 rcodes. 76 * All functions shall return appropriate IEEE 1394 rcodes.
76 */ 77 */
77 78
78 /* These functions have to implement block reads for themselves. */ 79 /* These functions have to implement block reads for themselves.
79 /* These functions either return a response code 80 *
80 or a negative number. In the first case a response will be generated; in the 81 * These functions either return a response code or a negative number.
81 later case, no response will be sent and the driver, that handled the request 82 * In the first case a response will be generated. In the latter case,
82 will send the response itself 83 * no response will be sent and the driver which handled the request
83 */ 84 * will send the response itself. */
84 int (*read) (struct hpsb_host *host, int nodeid, quadlet_t *buffer, 85 int (*read)(struct hpsb_host *host, int nodeid, quadlet_t *buffer,
85 u64 addr, size_t length, u16 flags); 86 u64 addr, size_t length, u16 flags);
86 int (*write) (struct hpsb_host *host, int nodeid, int destid, 87 int (*write)(struct hpsb_host *host, int nodeid, int destid,
87 quadlet_t *data, u64 addr, size_t length, u16 flags); 88 quadlet_t *data, u64 addr, size_t length, u16 flags);
88 89
89 /* Lock transactions: write results of ext_tcode operation into 90 /* Lock transactions: write results of ext_tcode operation into
90 * *store. */ 91 * *store. */
91 int (*lock) (struct hpsb_host *host, int nodeid, quadlet_t *store, 92 int (*lock)(struct hpsb_host *host, int nodeid, quadlet_t *store,
92 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode, u16 flags); 93 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
93 int (*lock64) (struct hpsb_host *host, int nodeid, octlet_t *store, 94 u16 flags);
94 u64 addr, octlet_t data, octlet_t arg, int ext_tcode, u16 flags); 95 int (*lock64)(struct hpsb_host *host, int nodeid, octlet_t *store,
96 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
97 u16 flags);
95}; 98};
96 99
97
98void highlevel_add_host(struct hpsb_host *host); 100void highlevel_add_host(struct hpsb_host *host);
99void highlevel_remove_host(struct hpsb_host *host); 101void highlevel_remove_host(struct hpsb_host *host);
100void highlevel_host_reset(struct hpsb_host *host); 102void highlevel_host_reset(struct hpsb_host *host);
101 103
102 104/*
103/* these functions are called to handle transactions. They are called, when 105 * These functions are called to handle transactions. They are called when a
104 a packet arrives. The flags argument contains the second word of the first header 106 * packet arrives. The flags argument contains the second word of the first
105 quadlet of the incoming packet (containing transaction label, retry code, 107 * header quadlet of the incoming packet (containing transaction label, retry
106 transaction code and priority). These functions either return a response code 108 * code, transaction code and priority). These functions either return a
107 or a negative number. In the first case a response will be generated; in the 109 * response code or a negative number. In the first case a response will be
108 later case, no response will be sent and the driver, that handled the request 110 * generated. In the latter case, no response will be sent and the driver which
109 will send the response itself. 111 * handled the request will send the response itself.
110*/ 112 */
111int highlevel_read(struct hpsb_host *host, int nodeid, void *data, 113int highlevel_read(struct hpsb_host *host, int nodeid, void *data, u64 addr,
112 u64 addr, unsigned int length, u16 flags); 114 unsigned int length, u16 flags);
113int highlevel_write(struct hpsb_host *host, int nodeid, int destid, 115int highlevel_write(struct hpsb_host *host, int nodeid, int destid, void *data,
114 void *data, u64 addr, unsigned int length, u16 flags); 116 u64 addr, unsigned int length, u16 flags);
115int highlevel_lock(struct hpsb_host *host, int nodeid, quadlet_t *store, 117int highlevel_lock(struct hpsb_host *host, int nodeid, quadlet_t *store,
116 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode, u16 flags); 118 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
119 u16 flags);
117int highlevel_lock64(struct hpsb_host *host, int nodeid, octlet_t *store, 120int highlevel_lock64(struct hpsb_host *host, int nodeid, octlet_t *store,
118 u64 addr, octlet_t data, octlet_t arg, int ext_tcode, u16 flags); 121 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
122 u16 flags);
119 123
120void highlevel_iso_receive(struct hpsb_host *host, void *data, 124void highlevel_iso_receive(struct hpsb_host *host, void *data, size_t length);
121 size_t length);
122void highlevel_fcp_request(struct hpsb_host *host, int nodeid, int direction, 125void highlevel_fcp_request(struct hpsb_host *host, int nodeid, int direction,
123 void *data, size_t length); 126 void *data, size_t length);
124
125 127
126/* 128/*
127 * Register highlevel driver. The name pointer has to stay valid at all times 129 * Register highlevel driver. The name pointer has to stay valid at all times
@@ -132,13 +134,15 @@ void hpsb_unregister_highlevel(struct hpsb_highlevel *hl);
132 134
133/* 135/*
134 * Register handlers for host address spaces. Start and end are 48 bit pointers 136 * Register handlers for host address spaces. Start and end are 48 bit pointers
135 * and have to be quadlet aligned (end points to the first address behind the 137 * and have to be quadlet aligned. Argument "end" points to the first address
136 * handled addresses. This function can be called multiple times for a single 138 * behind the handled addresses. This function can be called multiple times for
137 * hpsb_highlevel to implement sparse register sets. The requested region must 139 * a single hpsb_highlevel to implement sparse register sets. The requested
138 * not overlap any previously allocated region, otherwise registering will fail. 140 * region must not overlap any previously allocated region, otherwise
141 * registering will fail.
139 * 142 *
140 * It returns true for successful allocation. There is no unregister function, 143 * It returns true for successful allocation. Address spaces can be
141 * all address spaces are deallocated together with the hpsb_highlevel. 144 * unregistered with hpsb_unregister_addrspace. All remaining address spaces
145 * are automatically deallocated together with the hpsb_highlevel.
142 */ 146 */
143u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl, 147u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
144 struct hpsb_host *host, 148 struct hpsb_host *host,
@@ -146,20 +150,18 @@ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
146 u64 size, u64 alignment, 150 u64 size, u64 alignment,
147 u64 start, u64 end); 151 u64 start, u64 end);
148int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host, 152int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
149 struct hpsb_address_ops *ops, u64 start, u64 end); 153 struct hpsb_address_ops *ops, u64 start, u64 end);
150
151int hpsb_unregister_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host, 154int hpsb_unregister_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
152 u64 start); 155 u64 start);
153 156
154/* 157/*
155 * Enable or disable receving a certain isochronous channel through the 158 * Enable or disable receving a certain isochronous channel through the
156 * iso_receive op. 159 * iso_receive op.
157 */ 160 */
158int hpsb_listen_channel(struct hpsb_highlevel *hl, struct hpsb_host *host, 161int hpsb_listen_channel(struct hpsb_highlevel *hl, struct hpsb_host *host,
159 unsigned int channel); 162 unsigned int channel);
160void hpsb_unlisten_channel(struct hpsb_highlevel *hl, struct hpsb_host *host, 163void hpsb_unlisten_channel(struct hpsb_highlevel *hl, struct hpsb_host *host,
161 unsigned int channel); 164 unsigned int channel);
162
163 165
164/* Retrieve a hostinfo pointer bound to this driver/host */ 166/* Retrieve a hostinfo pointer bound to this driver/host */
165void *hpsb_get_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host); 167void *hpsb_get_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host);
@@ -172,19 +174,24 @@ void *hpsb_create_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
172void hpsb_destroy_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host); 174void hpsb_destroy_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host);
173 175
174/* Set an alternate lookup key for the hostinfo bound to this driver/host */ 176/* Set an alternate lookup key for the hostinfo bound to this driver/host */
175void hpsb_set_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host, unsigned long key); 177void hpsb_set_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host,
178 unsigned long key);
176 179
177/* Retrieve the alternate lookup key for the hostinfo bound to this driver/host */ 180/* Retrieve the alternate lookup key for the hostinfo bound to this
178unsigned long hpsb_get_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host); 181 * driver/host */
182unsigned long hpsb_get_hostinfo_key(struct hpsb_highlevel *hl,
183 struct hpsb_host *host);
179 184
180/* Retrieve a hostinfo pointer bound to this driver using its alternate key */ 185/* Retrieve a hostinfo pointer bound to this driver using its alternate key */
181void *hpsb_get_hostinfo_bykey(struct hpsb_highlevel *hl, unsigned long key); 186void *hpsb_get_hostinfo_bykey(struct hpsb_highlevel *hl, unsigned long key);
182 187
183/* Set the hostinfo pointer to something useful. Usually follows a call to 188/* Set the hostinfo pointer to something useful. Usually follows a call to
184 * hpsb_create_hostinfo, where the size is 0. */ 189 * hpsb_create_hostinfo, where the size is 0. */
185int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host, void *data); 190int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
191 void *data);
186 192
187/* Retrieve hpsb_host using a highlevel handle and a key */ 193/* Retrieve hpsb_host using a highlevel handle and a key */
188struct hpsb_host *hpsb_get_host_bykey(struct hpsb_highlevel *hl, unsigned long key); 194struct hpsb_host *hpsb_get_host_bykey(struct hpsb_highlevel *hl,
195 unsigned long key);
189 196
190#endif /* IEEE1394_HIGHLEVEL_H */ 197#endif /* IEEE1394_HIGHLEVEL_H */
diff --git a/drivers/ieee1394/hosts.c b/drivers/ieee1394/hosts.c
index 4feead4a35c5..d90a3a1898c0 100644
--- a/drivers/ieee1394/hosts.c
+++ b/drivers/ieee1394/hosts.c
@@ -90,6 +90,16 @@ static int alloc_hostnum_cb(struct hpsb_host *host, void *__data)
90 return 0; 90 return 0;
91} 91}
92 92
93/*
94 * The pending_packet_queue is special in that it's processed
95 * from hardirq context too (such as hpsb_bus_reset()). Hence
96 * split the lock class from the usual networking skb-head
97 * lock class by using a separate key for it:
98 */
99static struct lock_class_key pending_packet_queue_key;
100
101static DEFINE_MUTEX(host_num_alloc);
102
93/** 103/**
94 * hpsb_alloc_host - allocate a new host controller. 104 * hpsb_alloc_host - allocate a new host controller.
95 * @drv: the driver that will manage the host controller 105 * @drv: the driver that will manage the host controller
@@ -105,16 +115,6 @@ static int alloc_hostnum_cb(struct hpsb_host *host, void *__data)
105 * Return Value: a pointer to the &hpsb_host if successful, %NULL if 115 * Return Value: a pointer to the &hpsb_host if successful, %NULL if
106 * no memory was available. 116 * no memory was available.
107 */ 117 */
108static DEFINE_MUTEX(host_num_alloc);
109
110/*
111 * The pending_packet_queue is special in that it's processed
112 * from hardirq context too (such as hpsb_bus_reset()). Hence
113 * split the lock class from the usual networking skb-head
114 * lock class by using a separate key for it:
115 */
116static struct lock_class_key pending_packet_queue_key;
117
118struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra, 118struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra,
119 struct device *dev) 119 struct device *dev)
120{ 120{
@@ -143,9 +143,6 @@ struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra,
143 for (i = 2; i < 16; i++) 143 for (i = 2; i < 16; i++)
144 h->csr.gen_timestamp[i] = jiffies - 60 * HZ; 144 h->csr.gen_timestamp[i] = jiffies - 60 * HZ;
145 145
146 for (i = 0; i < ARRAY_SIZE(h->tpool); i++)
147 HPSB_TPOOL_INIT(&h->tpool[i]);
148
149 atomic_set(&h->generation, 0); 146 atomic_set(&h->generation, 0);
150 147
151 INIT_WORK(&h->delayed_reset, delayed_reset_bus, h); 148 INIT_WORK(&h->delayed_reset, delayed_reset_bus, h);
diff --git a/drivers/ieee1394/hosts.h b/drivers/ieee1394/hosts.h
index 9ad4b2463077..bc6dbfadb891 100644
--- a/drivers/ieee1394/hosts.h
+++ b/drivers/ieee1394/hosts.h
@@ -2,17 +2,19 @@
2#define _IEEE1394_HOSTS_H 2#define _IEEE1394_HOSTS_H
3 3
4#include <linux/device.h> 4#include <linux/device.h>
5#include <linux/wait.h>
6#include <linux/list.h> 5#include <linux/list.h>
7#include <linux/timer.h>
8#include <linux/skbuff.h> 6#include <linux/skbuff.h>
7#include <linux/timer.h>
8#include <linux/types.h>
9#include <linux/workqueue.h>
10#include <asm/atomic.h>
9 11
10#include <asm/semaphore.h> 12struct pci_dev;
13struct module;
11 14
12#include "ieee1394_types.h" 15#include "ieee1394_types.h"
13#include "csr.h" 16#include "csr.h"
14 17
15
16struct hpsb_packet; 18struct hpsb_packet;
17struct hpsb_iso; 19struct hpsb_iso;
18 20
@@ -33,7 +35,6 @@ struct hpsb_host {
33 int node_count; /* number of identified nodes on this bus */ 35 int node_count; /* number of identified nodes on this bus */
34 int selfid_count; /* total number of SelfIDs received */ 36 int selfid_count; /* total number of SelfIDs received */
35 int nodes_active; /* number of nodes with active link layer */ 37 int nodes_active; /* number of nodes with active link layer */
36 u8 speed[ALL_NODES]; /* speed between each node and local node */
37 38
38 nodeid_t node_id; /* node ID of this host */ 39 nodeid_t node_id; /* node ID of this host */
39 nodeid_t irm_id; /* ID of this bus' isochronous resource manager */ 40 nodeid_t irm_id; /* ID of this bus' isochronous resource manager */
@@ -53,31 +54,29 @@ struct hpsb_host {
53 int reset_retries; 54 int reset_retries;
54 quadlet_t *topology_map; 55 quadlet_t *topology_map;
55 u8 *speed_map; 56 u8 *speed_map;
56 struct csr_control csr;
57
58 /* Per node tlabel pool allocation */
59 struct hpsb_tlabel_pool tpool[ALL_NODES];
60 57
58 int id;
61 struct hpsb_host_driver *driver; 59 struct hpsb_host_driver *driver;
62
63 struct pci_dev *pdev; 60 struct pci_dev *pdev;
64
65 int id;
66
67 struct device device; 61 struct device device;
68 struct class_device class_dev; 62 struct class_device class_dev;
69 63
70 int update_config_rom; 64 int update_config_rom;
71 struct work_struct delayed_reset; 65 struct work_struct delayed_reset;
72
73 unsigned int config_roms; 66 unsigned int config_roms;
74 67
75 struct list_head addr_space; 68 struct list_head addr_space;
76 u64 low_addr_space; /* upper bound of physical DMA area */ 69 u64 low_addr_space; /* upper bound of physical DMA area */
77 u64 middle_addr_space; /* upper bound of posted write area */ 70 u64 middle_addr_space; /* upper bound of posted write area */
78};
79 71
72 u8 speed[ALL_NODES]; /* speed between each node and local node */
73
74 /* per node tlabel allocation */
75 u8 next_tl[ALL_NODES];
76 struct { DECLARE_BITMAP(map, 64); } tl_pool[ALL_NODES];
80 77
78 struct csr_control csr;
79};
81 80
82enum devctl_cmd { 81enum devctl_cmd {
83 /* Host is requested to reset its bus and cancel all outstanding async 82 /* Host is requested to reset its bus and cancel all outstanding async
@@ -112,7 +111,7 @@ enum devctl_cmd {
112 111
113enum isoctl_cmd { 112enum isoctl_cmd {
114 /* rawiso API - see iso.h for the meanings of these commands 113 /* rawiso API - see iso.h for the meanings of these commands
115 (they correspond exactly to the hpsb_iso_* API functions) 114 * (they correspond exactly to the hpsb_iso_* API functions)
116 * INIT = allocate resources 115 * INIT = allocate resources
117 * START = begin transmission/reception 116 * START = begin transmission/reception
118 * STOP = halt transmission/reception 117 * STOP = halt transmission/reception
@@ -160,7 +159,8 @@ struct hpsb_host_driver {
160 /* The hardware driver may optionally support a function that is used 159 /* The hardware driver may optionally support a function that is used
161 * to set the hardware ConfigROM if the hardware supports handling 160 * to set the hardware ConfigROM if the hardware supports handling
162 * reads to the ConfigROM on its own. */ 161 * reads to the ConfigROM on its own. */
163 void (*set_hw_config_rom) (struct hpsb_host *host, quadlet_t *config_rom); 162 void (*set_hw_config_rom)(struct hpsb_host *host,
163 quadlet_t *config_rom);
164 164
165 /* This function shall implement packet transmission based on 165 /* This function shall implement packet transmission based on
166 * packet->type. It shall CRC both parts of the packet (unless 166 * packet->type. It shall CRC both parts of the packet (unless
@@ -170,20 +170,21 @@ struct hpsb_host_driver {
170 * called. Return 0 on success, negative errno on failure. 170 * called. Return 0 on success, negative errno on failure.
171 * NOTE: The function must be callable in interrupt context. 171 * NOTE: The function must be callable in interrupt context.
172 */ 172 */
173 int (*transmit_packet) (struct hpsb_host *host, 173 int (*transmit_packet)(struct hpsb_host *host,
174 struct hpsb_packet *packet); 174 struct hpsb_packet *packet);
175 175
176 /* This function requests miscellanous services from the driver, see 176 /* This function requests miscellanous services from the driver, see
177 * above for command codes and expected actions. Return -1 for unknown 177 * above for command codes and expected actions. Return -1 for unknown
178 * command, though that should never happen. 178 * command, though that should never happen.
179 */ 179 */
180 int (*devctl) (struct hpsb_host *host, enum devctl_cmd command, int arg); 180 int (*devctl)(struct hpsb_host *host, enum devctl_cmd command, int arg);
181 181
182 /* ISO transmission/reception functions. Return 0 on success, -1 182 /* ISO transmission/reception functions. Return 0 on success, -1
183 * (or -EXXX errno code) on failure. If the low-level driver does not 183 * (or -EXXX errno code) on failure. If the low-level driver does not
184 * support the new ISO API, set isoctl to NULL. 184 * support the new ISO API, set isoctl to NULL.
185 */ 185 */
186 int (*isoctl) (struct hpsb_iso *iso, enum isoctl_cmd command, unsigned long arg); 186 int (*isoctl)(struct hpsb_iso *iso, enum isoctl_cmd command,
187 unsigned long arg);
187 188
188 /* This function is mainly to redirect local CSR reads/locks to the iso 189 /* This function is mainly to redirect local CSR reads/locks to the iso
189 * management registers (bus manager id, bandwidth available, channels 190 * management registers (bus manager id, bandwidth available, channels
@@ -196,19 +197,11 @@ struct hpsb_host_driver {
196 quadlet_t data, quadlet_t compare); 197 quadlet_t data, quadlet_t compare);
197}; 198};
198 199
199
200struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra, 200struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra,
201 struct device *dev); 201 struct device *dev);
202int hpsb_add_host(struct hpsb_host *host); 202int hpsb_add_host(struct hpsb_host *host);
203void hpsb_remove_host(struct hpsb_host *h); 203void hpsb_remove_host(struct hpsb_host *h);
204 204
205/* The following 2 functions are deprecated and will be removed when the
206 * raw1394/libraw1394 update is complete. */
207int hpsb_update_config_rom(struct hpsb_host *host,
208 const quadlet_t *new_rom, size_t size, unsigned char rom_version);
209int hpsb_get_config_rom(struct hpsb_host *host, quadlet_t *buffer,
210 size_t buffersize, size_t *rom_size, unsigned char *rom_version);
211
212/* Updates the configuration rom image of a host. rom_version must be the 205/* Updates the configuration rom image of a host. rom_version must be the
213 * current version, otherwise it will fail with return value -1. If this 206 * current version, otherwise it will fail with return value -1. If this
214 * host does not support config-rom-update, it will return -EINVAL. 207 * host does not support config-rom-update, it will return -EINVAL.
diff --git a/drivers/ieee1394/ieee1394-ioctl.h b/drivers/ieee1394/ieee1394-ioctl.h
index 156703986348..8f207508ed1d 100644
--- a/drivers/ieee1394/ieee1394-ioctl.h
+++ b/drivers/ieee1394/ieee1394-ioctl.h
@@ -1,5 +1,7 @@
1/* Base file for all ieee1394 ioctl's. Linux-1394 has allocated base '#' 1/*
2 * with a range of 0x00-0x3f. */ 2 * Base file for all ieee1394 ioctl's.
3 * Linux-1394 has allocated base '#' with a range of 0x00-0x3f.
4 */
3 5
4#ifndef __IEEE1394_IOCTL_H 6#ifndef __IEEE1394_IOCTL_H
5#define __IEEE1394_IOCTL_H 7#define __IEEE1394_IOCTL_H
@@ -96,8 +98,7 @@
96 _IOW ('#', 0x27, struct raw1394_iso_packets) 98 _IOW ('#', 0x27, struct raw1394_iso_packets)
97#define RAW1394_IOC_ISO_XMIT_SYNC \ 99#define RAW1394_IOC_ISO_XMIT_SYNC \
98 _IO ('#', 0x28) 100 _IO ('#', 0x28)
99#define RAW1394_IOC_ISO_RECV_FLUSH \ 101#define RAW1394_IOC_ISO_RECV_FLUSH \
100 _IO ('#', 0x29) 102 _IO ('#', 0x29)
101 103
102
103#endif /* __IEEE1394_IOCTL_H */ 104#endif /* __IEEE1394_IOCTL_H */
diff --git a/drivers/ieee1394/ieee1394.h b/drivers/ieee1394/ieee1394.h
index 936d776de00a..40492074c013 100644
--- a/drivers/ieee1394/ieee1394.h
+++ b/drivers/ieee1394/ieee1394.h
@@ -5,77 +5,78 @@
5#ifndef _IEEE1394_IEEE1394_H 5#ifndef _IEEE1394_IEEE1394_H
6#define _IEEE1394_IEEE1394_H 6#define _IEEE1394_IEEE1394_H
7 7
8#define TCODE_WRITEQ 0x0 8#define TCODE_WRITEQ 0x0
9#define TCODE_WRITEB 0x1 9#define TCODE_WRITEB 0x1
10#define TCODE_WRITE_RESPONSE 0x2 10#define TCODE_WRITE_RESPONSE 0x2
11#define TCODE_READQ 0x4 11#define TCODE_READQ 0x4
12#define TCODE_READB 0x5 12#define TCODE_READB 0x5
13#define TCODE_READQ_RESPONSE 0x6 13#define TCODE_READQ_RESPONSE 0x6
14#define TCODE_READB_RESPONSE 0x7 14#define TCODE_READB_RESPONSE 0x7
15#define TCODE_CYCLE_START 0x8 15#define TCODE_CYCLE_START 0x8
16#define TCODE_LOCK_REQUEST 0x9 16#define TCODE_LOCK_REQUEST 0x9
17#define TCODE_ISO_DATA 0xa 17#define TCODE_ISO_DATA 0xa
18#define TCODE_STREAM_DATA 0xa 18#define TCODE_STREAM_DATA 0xa
19#define TCODE_LOCK_RESPONSE 0xb 19#define TCODE_LOCK_RESPONSE 0xb
20 20
21#define RCODE_COMPLETE 0x0 21#define RCODE_COMPLETE 0x0
22#define RCODE_CONFLICT_ERROR 0x4 22#define RCODE_CONFLICT_ERROR 0x4
23#define RCODE_DATA_ERROR 0x5 23#define RCODE_DATA_ERROR 0x5
24#define RCODE_TYPE_ERROR 0x6 24#define RCODE_TYPE_ERROR 0x6
25#define RCODE_ADDRESS_ERROR 0x7 25#define RCODE_ADDRESS_ERROR 0x7
26 26
27#define EXTCODE_MASK_SWAP 0x1 27#define EXTCODE_MASK_SWAP 0x1
28#define EXTCODE_COMPARE_SWAP 0x2 28#define EXTCODE_COMPARE_SWAP 0x2
29#define EXTCODE_FETCH_ADD 0x3 29#define EXTCODE_FETCH_ADD 0x3
30#define EXTCODE_LITTLE_ADD 0x4 30#define EXTCODE_LITTLE_ADD 0x4
31#define EXTCODE_BOUNDED_ADD 0x5 31#define EXTCODE_BOUNDED_ADD 0x5
32#define EXTCODE_WRAP_ADD 0x6 32#define EXTCODE_WRAP_ADD 0x6
33 33
34#define ACK_COMPLETE 0x1 34#define ACK_COMPLETE 0x1
35#define ACK_PENDING 0x2 35#define ACK_PENDING 0x2
36#define ACK_BUSY_X 0x4 36#define ACK_BUSY_X 0x4
37#define ACK_BUSY_A 0x5 37#define ACK_BUSY_A 0x5
38#define ACK_BUSY_B 0x6 38#define ACK_BUSY_B 0x6
39#define ACK_TARDY 0xb 39#define ACK_TARDY 0xb
40#define ACK_CONFLICT_ERROR 0xc 40#define ACK_CONFLICT_ERROR 0xc
41#define ACK_DATA_ERROR 0xd 41#define ACK_DATA_ERROR 0xd
42#define ACK_TYPE_ERROR 0xe 42#define ACK_TYPE_ERROR 0xe
43#define ACK_ADDRESS_ERROR 0xf 43#define ACK_ADDRESS_ERROR 0xf
44 44
45/* Non-standard "ACK codes" for internal use */ 45/* Non-standard "ACK codes" for internal use */
46#define ACKX_NONE (-1) 46#define ACKX_NONE (-1)
47#define ACKX_SEND_ERROR (-2) 47#define ACKX_SEND_ERROR (-2)
48#define ACKX_ABORTED (-3) 48#define ACKX_ABORTED (-3)
49#define ACKX_TIMEOUT (-4) 49#define ACKX_TIMEOUT (-4)
50 50
51 51#define IEEE1394_SPEED_100 0x00
52#define IEEE1394_SPEED_100 0x00 52#define IEEE1394_SPEED_200 0x01
53#define IEEE1394_SPEED_200 0x01 53#define IEEE1394_SPEED_400 0x02
54#define IEEE1394_SPEED_400 0x02 54#define IEEE1394_SPEED_800 0x03
55#define IEEE1394_SPEED_800 0x03 55#define IEEE1394_SPEED_1600 0x04
56#define IEEE1394_SPEED_1600 0x04 56#define IEEE1394_SPEED_3200 0x05
57#define IEEE1394_SPEED_3200 0x05 57
58/* The current highest tested speed supported by the subsystem */ 58/* The current highest tested speed supported by the subsystem */
59#define IEEE1394_SPEED_MAX IEEE1394_SPEED_800 59#define IEEE1394_SPEED_MAX IEEE1394_SPEED_800
60 60
61/* Maps speed values above to a string representation */ 61/* Maps speed values above to a string representation */
62extern const char *hpsb_speedto_str[]; 62extern const char *hpsb_speedto_str[];
63 63
64
65/* 1394a cable PHY packets */ 64/* 1394a cable PHY packets */
66#define SELFID_PWRCL_NO_POWER 0x0 65#define SELFID_PWRCL_NO_POWER 0x0
67#define SELFID_PWRCL_PROVIDE_15W 0x1 66#define SELFID_PWRCL_PROVIDE_15W 0x1
68#define SELFID_PWRCL_PROVIDE_30W 0x2 67#define SELFID_PWRCL_PROVIDE_30W 0x2
69#define SELFID_PWRCL_PROVIDE_45W 0x3 68#define SELFID_PWRCL_PROVIDE_45W 0x3
70#define SELFID_PWRCL_USE_1W 0x4 69#define SELFID_PWRCL_USE_1W 0x4
71#define SELFID_PWRCL_USE_3W 0x5 70#define SELFID_PWRCL_USE_3W 0x5
72#define SELFID_PWRCL_USE_6W 0x6 71#define SELFID_PWRCL_USE_6W 0x6
73#define SELFID_PWRCL_USE_10W 0x7 72#define SELFID_PWRCL_USE_10W 0x7
74 73
75#define SELFID_PORT_CHILD 0x3 74#define SELFID_PORT_CHILD 0x3
76#define SELFID_PORT_PARENT 0x2 75#define SELFID_PORT_PARENT 0x2
77#define SELFID_PORT_NCONN 0x1 76#define SELFID_PORT_NCONN 0x1
78#define SELFID_PORT_NONE 0x0 77#define SELFID_PORT_NONE 0x0
78
79#define SELFID_SPEED_UNKNOWN 0x3 /* 1394b PHY */
79 80
80#define PHYPACKET_LINKON 0x40000000 81#define PHYPACKET_LINKON 0x40000000
81#define PHYPACKET_PHYCONFIG_R 0x00800000 82#define PHYPACKET_PHYCONFIG_R 0x00800000
@@ -91,76 +92,76 @@ extern const char *hpsb_speedto_str[];
91 92
92#define EXTPHYPACKET_TYPEMASK 0xC0FC0000 93#define EXTPHYPACKET_TYPEMASK 0xC0FC0000
93 94
94#define PHYPACKET_PORT_SHIFT 24 95#define PHYPACKET_PORT_SHIFT 24
95#define PHYPACKET_GAPCOUNT_SHIFT 16 96#define PHYPACKET_GAPCOUNT_SHIFT 16
96 97
97/* 1394a PHY register map bitmasks */ 98/* 1394a PHY register map bitmasks */
98#define PHY_00_PHYSICAL_ID 0xFC 99#define PHY_00_PHYSICAL_ID 0xFC
99#define PHY_00_R 0x02 /* Root */ 100#define PHY_00_R 0x02 /* Root */
100#define PHY_00_PS 0x01 /* Power Status*/ 101#define PHY_00_PS 0x01 /* Power Status*/
101#define PHY_01_RHB 0x80 /* Root Hold-Off */ 102#define PHY_01_RHB 0x80 /* Root Hold-Off */
102#define PHY_01_IBR 0x80 /* Initiate Bus Reset */ 103#define PHY_01_IBR 0x80 /* Initiate Bus Reset */
103#define PHY_01_GAP_COUNT 0x3F 104#define PHY_01_GAP_COUNT 0x3F
104#define PHY_02_EXTENDED 0xE0 /* 0x7 for 1394a-compliant PHY */ 105#define PHY_02_EXTENDED 0xE0 /* 0x7 for 1394a-compliant PHY */
105#define PHY_02_TOTAL_PORTS 0x1F 106#define PHY_02_TOTAL_PORTS 0x1F
106#define PHY_03_MAX_SPEED 0xE0 107#define PHY_03_MAX_SPEED 0xE0
107#define PHY_03_DELAY 0x0F 108#define PHY_03_DELAY 0x0F
108#define PHY_04_LCTRL 0x80 /* Link Active Report Control */ 109#define PHY_04_LCTRL 0x80 /* Link Active Report Control */
109#define PHY_04_CONTENDER 0x40 110#define PHY_04_CONTENDER 0x40
110#define PHY_04_JITTER 0x38 111#define PHY_04_JITTER 0x38
111#define PHY_04_PWR_CLASS 0x07 /* Power Class */ 112#define PHY_04_PWR_CLASS 0x07 /* Power Class */
112#define PHY_05_WATCHDOG 0x80 113#define PHY_05_WATCHDOG 0x80
113#define PHY_05_ISBR 0x40 /* Initiate Short Bus Reset */ 114#define PHY_05_ISBR 0x40 /* Initiate Short Bus Reset */
114#define PHY_05_LOOP 0x20 /* Loop Detect */ 115#define PHY_05_LOOP 0x20 /* Loop Detect */
115#define PHY_05_PWR_FAIL 0x10 /* Cable Power Failure Detect */ 116#define PHY_05_PWR_FAIL 0x10 /* Cable Power Failure Detect */
116#define PHY_05_TIMEOUT 0x08 /* Arbitration State Machine Timeout */ 117#define PHY_05_TIMEOUT 0x08 /* Arbitration State Machine Timeout */
117#define PHY_05_PORT_EVENT 0x04 /* Port Event Detect */ 118#define PHY_05_PORT_EVENT 0x04 /* Port Event Detect */
118#define PHY_05_ENAB_ACCEL 0x02 /* Enable Arbitration Acceleration */ 119#define PHY_05_ENAB_ACCEL 0x02 /* Enable Arbitration Acceleration */
119#define PHY_05_ENAB_MULTI 0x01 /* Ena. Multispeed Packet Concatenation */ 120#define PHY_05_ENAB_MULTI 0x01 /* Ena. Multispeed Packet Concatenation */
120 121
121#include <asm/byteorder.h> 122#include <asm/byteorder.h>
122 123
123#ifdef __BIG_ENDIAN_BITFIELD 124#ifdef __BIG_ENDIAN_BITFIELD
124 125
125struct selfid { 126struct selfid {
126 u32 packet_identifier:2; /* always binary 10 */ 127 u32 packet_identifier:2; /* always binary 10 */
127 u32 phy_id:6; 128 u32 phy_id:6;
128 /* byte */ 129 /* byte */
129 u32 extended:1; /* if true is struct ext_selfid */ 130 u32 extended:1; /* if true is struct ext_selfid */
130 u32 link_active:1; 131 u32 link_active:1;
131 u32 gap_count:6; 132 u32 gap_count:6;
132 /* byte */ 133 /* byte */
133 u32 speed:2; 134 u32 speed:2;
134 u32 phy_delay:2; 135 u32 phy_delay:2;
135 u32 contender:1; 136 u32 contender:1;
136 u32 power_class:3; 137 u32 power_class:3;
137 /* byte */ 138 /* byte */
138 u32 port0:2; 139 u32 port0:2;
139 u32 port1:2; 140 u32 port1:2;
140 u32 port2:2; 141 u32 port2:2;
141 u32 initiated_reset:1; 142 u32 initiated_reset:1;
142 u32 more_packets:1; 143 u32 more_packets:1;
143} __attribute__((packed)); 144} __attribute__((packed));
144 145
145struct ext_selfid { 146struct ext_selfid {
146 u32 packet_identifier:2; /* always binary 10 */ 147 u32 packet_identifier:2; /* always binary 10 */
147 u32 phy_id:6; 148 u32 phy_id:6;
148 /* byte */ 149 /* byte */
149 u32 extended:1; /* if false is struct selfid */ 150 u32 extended:1; /* if false is struct selfid */
150 u32 seq_nr:3; 151 u32 seq_nr:3;
151 u32 reserved:2; 152 u32 reserved:2;
152 u32 porta:2; 153 u32 porta:2;
153 /* byte */ 154 /* byte */
154 u32 portb:2; 155 u32 portb:2;
155 u32 portc:2; 156 u32 portc:2;
156 u32 portd:2; 157 u32 portd:2;
157 u32 porte:2; 158 u32 porte:2;
158 /* byte */ 159 /* byte */
159 u32 portf:2; 160 u32 portf:2;
160 u32 portg:2; 161 u32 portg:2;
161 u32 porth:2; 162 u32 porth:2;
162 u32 reserved2:1; 163 u32 reserved2:1;
163 u32 more_packets:1; 164 u32 more_packets:1;
164} __attribute__((packed)); 165} __attribute__((packed));
165 166
166#elif defined __LITTLE_ENDIAN_BITFIELD /* __BIG_ENDIAN_BITFIELD */ 167#elif defined __LITTLE_ENDIAN_BITFIELD /* __BIG_ENDIAN_BITFIELD */
@@ -171,49 +172,48 @@ struct ext_selfid {
171 */ 172 */
172 173
173struct selfid { 174struct selfid {
174 u32 phy_id:6; 175 u32 phy_id:6;
175 u32 packet_identifier:2; /* always binary 10 */ 176 u32 packet_identifier:2; /* always binary 10 */
176 /* byte */ 177 /* byte */
177 u32 gap_count:6; 178 u32 gap_count:6;
178 u32 link_active:1; 179 u32 link_active:1;
179 u32 extended:1; /* if true is struct ext_selfid */ 180 u32 extended:1; /* if true is struct ext_selfid */
180 /* byte */ 181 /* byte */
181 u32 power_class:3; 182 u32 power_class:3;
182 u32 contender:1; 183 u32 contender:1;
183 u32 phy_delay:2; 184 u32 phy_delay:2;
184 u32 speed:2; 185 u32 speed:2;
185 /* byte */ 186 /* byte */
186 u32 more_packets:1; 187 u32 more_packets:1;
187 u32 initiated_reset:1; 188 u32 initiated_reset:1;
188 u32 port2:2; 189 u32 port2:2;
189 u32 port1:2; 190 u32 port1:2;
190 u32 port0:2; 191 u32 port0:2;
191} __attribute__((packed)); 192} __attribute__((packed));
192 193
193struct ext_selfid { 194struct ext_selfid {
194 u32 phy_id:6; 195 u32 phy_id:6;
195 u32 packet_identifier:2; /* always binary 10 */ 196 u32 packet_identifier:2; /* always binary 10 */
196 /* byte */ 197 /* byte */
197 u32 porta:2; 198 u32 porta:2;
198 u32 reserved:2; 199 u32 reserved:2;
199 u32 seq_nr:3; 200 u32 seq_nr:3;
200 u32 extended:1; /* if false is struct selfid */ 201 u32 extended:1; /* if false is struct selfid */
201 /* byte */ 202 /* byte */
202 u32 porte:2; 203 u32 porte:2;
203 u32 portd:2; 204 u32 portd:2;
204 u32 portc:2; 205 u32 portc:2;
205 u32 portb:2; 206 u32 portb:2;
206 /* byte */ 207 /* byte */
207 u32 more_packets:1; 208 u32 more_packets:1;
208 u32 reserved2:1; 209 u32 reserved2:1;
209 u32 porth:2; 210 u32 porth:2;
210 u32 portg:2; 211 u32 portg:2;
211 u32 portf:2; 212 u32 portf:2;
212} __attribute__((packed)); 213} __attribute__((packed));
213 214
214#else 215#else
215#error What? PDP endian? 216#error What? PDP endian?
216#endif /* __BIG_ENDIAN_BITFIELD */ 217#endif /* __BIG_ENDIAN_BITFIELD */
217 218
218
219#endif /* _IEEE1394_IEEE1394_H */ 219#endif /* _IEEE1394_IEEE1394_H */
diff --git a/drivers/ieee1394/ieee1394_core.c b/drivers/ieee1394/ieee1394_core.c
index f43739c5cab2..5fccf9f7a1d2 100644
--- a/drivers/ieee1394/ieee1394_core.c
+++ b/drivers/ieee1394/ieee1394_core.c
@@ -35,7 +35,6 @@
35#include <linux/kthread.h> 35#include <linux/kthread.h>
36 36
37#include <asm/byteorder.h> 37#include <asm/byteorder.h>
38#include <asm/semaphore.h>
39 38
40#include "ieee1394_types.h" 39#include "ieee1394_types.h"
41#include "ieee1394.h" 40#include "ieee1394.h"
@@ -86,7 +85,7 @@ static void dump_packet(const char *text, quadlet_t *data, int size, int speed)
86 printk("\n"); 85 printk("\n");
87} 86}
88#else 87#else
89#define dump_packet(a,b,c,d) 88#define dump_packet(a,b,c,d) do {} while (0)
90#endif 89#endif
91 90
92static void abort_requests(struct hpsb_host *host); 91static void abort_requests(struct hpsb_host *host);
@@ -355,10 +354,12 @@ static void build_speed_map(struct hpsb_host *host, int nodecount)
355 } 354 }
356 } 355 }
357 356
357#if SELFID_SPEED_UNKNOWN != IEEE1394_SPEED_MAX
358 /* assume maximum speed for 1394b PHYs, nodemgr will correct it */ 358 /* assume maximum speed for 1394b PHYs, nodemgr will correct it */
359 for (n = 0; n < nodecount; n++) 359 for (n = 0; n < nodecount; n++)
360 if (speedcap[n] == 3) 360 if (speedcap[n] == SELFID_SPEED_UNKNOWN)
361 speedcap[n] = IEEE1394_SPEED_MAX; 361 speedcap[n] = IEEE1394_SPEED_MAX;
362#endif
362} 363}
363 364
364 365
@@ -1169,7 +1170,7 @@ static void __exit ieee1394_cleanup(void)
1169 unregister_chrdev_region(IEEE1394_CORE_DEV, 256); 1170 unregister_chrdev_region(IEEE1394_CORE_DEV, 256);
1170} 1171}
1171 1172
1172module_init(ieee1394_init); 1173fs_initcall(ieee1394_init); /* same as ohci1394 */
1173module_exit(ieee1394_cleanup); 1174module_exit(ieee1394_cleanup);
1174 1175
1175/* Exported symbols */ 1176/* Exported symbols */
diff --git a/drivers/ieee1394/ieee1394_core.h b/drivers/ieee1394/ieee1394_core.h
index 0ecbf335c64f..af4a78a8ef3b 100644
--- a/drivers/ieee1394/ieee1394_core.h
+++ b/drivers/ieee1394/ieee1394_core.h
@@ -1,12 +1,15 @@
1
2#ifndef _IEEE1394_CORE_H 1#ifndef _IEEE1394_CORE_H
3#define _IEEE1394_CORE_H 2#define _IEEE1394_CORE_H
4 3
5#include <linux/slab.h> 4#include <linux/device.h>
5#include <linux/fs.h>
6#include <linux/list.h>
7#include <linux/skbuff.h>
8#include <linux/types.h>
6#include <asm/atomic.h> 9#include <asm/atomic.h>
7#include <asm/semaphore.h>
8#include "hosts.h"
9 10
11#include "hosts.h"
12#include "ieee1394_types.h"
10 13
11struct hpsb_packet { 14struct hpsb_packet {
12 /* This struct is basically read-only for hosts with the exception of 15 /* This struct is basically read-only for hosts with the exception of
@@ -58,7 +61,6 @@ struct hpsb_packet {
58 size_t header_size; 61 size_t header_size;
59 size_t data_size; 62 size_t data_size;
60 63
61
62 struct hpsb_host *host; 64 struct hpsb_host *host;
63 unsigned int generation; 65 unsigned int generation;
64 66
@@ -80,7 +82,7 @@ struct hpsb_packet {
80 82
81/* Set a task for when a packet completes */ 83/* Set a task for when a packet completes */
82void hpsb_set_packet_complete_task(struct hpsb_packet *packet, 84void hpsb_set_packet_complete_task(struct hpsb_packet *packet,
83 void (*routine)(void *), void *data); 85 void (*routine)(void *), void *data);
84 86
85static inline struct hpsb_packet *driver_packet(struct list_head *l) 87static inline struct hpsb_packet *driver_packet(struct list_head *l)
86{ 88{
@@ -92,7 +94,6 @@ void abort_timedouts(unsigned long __opaque);
92struct hpsb_packet *hpsb_alloc_packet(size_t data_size); 94struct hpsb_packet *hpsb_alloc_packet(size_t data_size);
93void hpsb_free_packet(struct hpsb_packet *packet); 95void hpsb_free_packet(struct hpsb_packet *packet);
94 96
95
96/* 97/*
97 * Generation counter for the complete 1394 subsystem. Generation gets 98 * Generation counter for the complete 1394 subsystem. Generation gets
98 * incremented on every change in the subsystem (e.g. bus reset). 99 * incremented on every change in the subsystem (e.g. bus reset).
@@ -204,10 +205,14 @@ void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
204#define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15 205#define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15
205 206
206#define IEEE1394_CORE_DEV MKDEV(IEEE1394_MAJOR, 0) 207#define IEEE1394_CORE_DEV MKDEV(IEEE1394_MAJOR, 0)
207#define IEEE1394_RAW1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16) 208#define IEEE1394_RAW1394_DEV MKDEV(IEEE1394_MAJOR, \
208#define IEEE1394_VIDEO1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_VIDEO1394 * 16) 209 IEEE1394_MINOR_BLOCK_RAW1394 * 16)
209#define IEEE1394_DV1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_DV1394 * 16) 210#define IEEE1394_VIDEO1394_DEV MKDEV(IEEE1394_MAJOR, \
210#define IEEE1394_EXPERIMENTAL_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_EXPERIMENTAL * 16) 211 IEEE1394_MINOR_BLOCK_VIDEO1394 * 16)
212#define IEEE1394_DV1394_DEV MKDEV(IEEE1394_MAJOR, \
213 IEEE1394_MINOR_BLOCK_DV1394 * 16)
214#define IEEE1394_EXPERIMENTAL_DEV MKDEV(IEEE1394_MAJOR, \
215 IEEE1394_MINOR_BLOCK_EXPERIMENTAL * 16)
211 216
212/* return the index (within a minor number block) of a file */ 217/* return the index (within a minor number block) of a file */
213static inline unsigned char ieee1394_file_to_instance(struct file *file) 218static inline unsigned char ieee1394_file_to_instance(struct file *file)
@@ -223,4 +228,3 @@ extern struct class hpsb_host_class;
223extern struct class *hpsb_protocol_class; 228extern struct class *hpsb_protocol_class;
224 229
225#endif /* _IEEE1394_CORE_H */ 230#endif /* _IEEE1394_CORE_H */
226
diff --git a/drivers/ieee1394/ieee1394_hotplug.h b/drivers/ieee1394/ieee1394_hotplug.h
index 5be70d31b007..dd5500ed8322 100644
--- a/drivers/ieee1394/ieee1394_hotplug.h
+++ b/drivers/ieee1394/ieee1394_hotplug.h
@@ -1,33 +1,19 @@
1#ifndef _IEEE1394_HOTPLUG_H 1#ifndef _IEEE1394_HOTPLUG_H
2#define _IEEE1394_HOTPLUG_H 2#define _IEEE1394_HOTPLUG_H
3 3
4#include <linux/kernel.h>
5#include <linux/types.h>
6#include <linux/mod_devicetable.h>
7
8/* Unit spec id and sw version entry for some protocols */ 4/* Unit spec id and sw version entry for some protocols */
9#define AVC_UNIT_SPEC_ID_ENTRY 0x0000A02D 5#define AVC_UNIT_SPEC_ID_ENTRY 0x0000A02D
10#define AVC_SW_VERSION_ENTRY 0x00010001 6#define AVC_SW_VERSION_ENTRY 0x00010001
11#define CAMERA_UNIT_SPEC_ID_ENTRY 0x0000A02D 7#define CAMERA_UNIT_SPEC_ID_ENTRY 0x0000A02D
12#define CAMERA_SW_VERSION_ENTRY 0x00000100 8#define CAMERA_SW_VERSION_ENTRY 0x00000100
13 9
14/* Check to make sure this all isn't already defined */ 10/* /include/linux/mod_devicetable.h defines:
15#ifndef IEEE1394_MATCH_VENDOR_ID 11 * IEEE1394_MATCH_VENDOR_ID
16 12 * IEEE1394_MATCH_MODEL_ID
17#define IEEE1394_MATCH_VENDOR_ID 0x0001 13 * IEEE1394_MATCH_SPECIFIER_ID
18#define IEEE1394_MATCH_MODEL_ID 0x0002 14 * IEEE1394_MATCH_VERSION
19#define IEEE1394_MATCH_SPECIFIER_ID 0x0004 15 * struct ieee1394_device_id
20#define IEEE1394_MATCH_VERSION 0x0008 16 */
21 17#include <linux/mod_devicetable.h>
22struct ieee1394_device_id {
23 u32 match_flags;
24 u32 vendor_id;
25 u32 model_id;
26 u32 specifier_id;
27 u32 version;
28 void *driver_data;
29};
30
31#endif
32 18
33#endif /* _IEEE1394_HOTPLUG_H */ 19#endif /* _IEEE1394_HOTPLUG_H */
diff --git a/drivers/ieee1394/ieee1394_transactions.c b/drivers/ieee1394/ieee1394_transactions.c
index a114b91d606d..0833fc9f50c4 100644
--- a/drivers/ieee1394/ieee1394_transactions.c
+++ b/drivers/ieee1394/ieee1394_transactions.c
@@ -9,19 +9,17 @@
9 * directory of the kernel sources for details. 9 * directory of the kernel sources for details.
10 */ 10 */
11 11
12#include <linux/sched.h>
13#include <linux/bitops.h> 12#include <linux/bitops.h>
14#include <linux/smp_lock.h> 13#include <linux/spinlock.h>
15#include <linux/interrupt.h> 14#include <linux/wait.h>
16 15
16#include <asm/bug.h>
17#include <asm/errno.h> 17#include <asm/errno.h>
18 18
19#include "ieee1394.h" 19#include "ieee1394.h"
20#include "ieee1394_types.h" 20#include "ieee1394_types.h"
21#include "hosts.h" 21#include "hosts.h"
22#include "ieee1394_core.h" 22#include "ieee1394_core.h"
23#include "highlevel.h"
24#include "nodemgr.h"
25#include "ieee1394_transactions.h" 23#include "ieee1394_transactions.h"
26 24
27#define PREP_ASYNC_HEAD_ADDRESS(tc) \ 25#define PREP_ASYNC_HEAD_ADDRESS(tc) \
@@ -31,6 +29,13 @@
31 packet->header[1] = (packet->host->node_id << 16) | (addr >> 32); \ 29 packet->header[1] = (packet->host->node_id << 16) | (addr >> 32); \
32 packet->header[2] = addr & 0xffffffff 30 packet->header[2] = addr & 0xffffffff
33 31
32#ifndef HPSB_DEBUG_TLABELS
33static
34#endif
35spinlock_t hpsb_tlabel_lock = SPIN_LOCK_UNLOCKED;
36
37static DECLARE_WAIT_QUEUE_HEAD(tlabel_wq);
38
34static void fill_async_readquad(struct hpsb_packet *packet, u64 addr) 39static void fill_async_readquad(struct hpsb_packet *packet, u64 addr)
35{ 40{
36 PREP_ASYNC_HEAD_ADDRESS(TCODE_READQ); 41 PREP_ASYNC_HEAD_ADDRESS(TCODE_READQ);
@@ -114,9 +119,41 @@ static void fill_async_stream_packet(struct hpsb_packet *packet, int length,
114 packet->tcode = TCODE_ISO_DATA; 119 packet->tcode = TCODE_ISO_DATA;
115} 120}
116 121
122/* same as hpsb_get_tlabel, except that it returns immediately */
123static int hpsb_get_tlabel_atomic(struct hpsb_packet *packet)
124{
125 unsigned long flags, *tp;
126 u8 *next;
127 int tlabel, n = NODEID_TO_NODE(packet->node_id);
128
129 /* Broadcast transactions are complete once the request has been sent.
130 * Use the same transaction label for all broadcast transactions. */
131 if (unlikely(n == ALL_NODES)) {
132 packet->tlabel = 0;
133 return 0;
134 }
135 tp = packet->host->tl_pool[n].map;
136 next = &packet->host->next_tl[n];
137
138 spin_lock_irqsave(&hpsb_tlabel_lock, flags);
139 tlabel = find_next_zero_bit(tp, 64, *next);
140 if (tlabel > 63)
141 tlabel = find_first_zero_bit(tp, 64);
142 if (tlabel > 63) {
143 spin_unlock_irqrestore(&hpsb_tlabel_lock, flags);
144 return -EAGAIN;
145 }
146 __set_bit(tlabel, tp);
147 *next = (tlabel + 1) & 63;
148 spin_unlock_irqrestore(&hpsb_tlabel_lock, flags);
149
150 packet->tlabel = tlabel;
151 return 0;
152}
153
117/** 154/**
118 * hpsb_get_tlabel - allocate a transaction label 155 * hpsb_get_tlabel - allocate a transaction label
119 * @packet: the packet who's tlabel/tpool we set 156 * @packet: the packet whose tlabel and tl_pool we set
120 * 157 *
121 * Every asynchronous transaction on the 1394 bus needs a transaction 158 * Every asynchronous transaction on the 1394 bus needs a transaction
122 * label to match the response to the request. This label has to be 159 * label to match the response to the request. This label has to be
@@ -130,42 +167,25 @@ static void fill_async_stream_packet(struct hpsb_packet *packet, int length,
130 * Return value: Zero on success, otherwise non-zero. A non-zero return 167 * Return value: Zero on success, otherwise non-zero. A non-zero return
131 * generally means there are no available tlabels. If this is called out 168 * generally means there are no available tlabels. If this is called out
132 * of interrupt or atomic context, then it will sleep until can return a 169 * of interrupt or atomic context, then it will sleep until can return a
133 * tlabel. 170 * tlabel or a signal is received.
134 */ 171 */
135int hpsb_get_tlabel(struct hpsb_packet *packet) 172int hpsb_get_tlabel(struct hpsb_packet *packet)
136{ 173{
137 unsigned long flags; 174 if (irqs_disabled() || in_atomic())
138 struct hpsb_tlabel_pool *tp; 175 return hpsb_get_tlabel_atomic(packet);
139 int n = NODEID_TO_NODE(packet->node_id); 176
140 177 /* NB: The macro wait_event_interruptible() is called with a condition
141 if (unlikely(n == ALL_NODES)) 178 * argument with side effect. This is only possible because the side
142 return 0; 179 * effect does not occur until the condition became true, and
143 tp = &packet->host->tpool[n]; 180 * wait_event_interruptible() won't evaluate the condition again after
144 181 * that. */
145 if (irqs_disabled() || in_atomic()) { 182 return wait_event_interruptible(tlabel_wq,
146 if (down_trylock(&tp->count)) 183 !hpsb_get_tlabel_atomic(packet));
147 return 1;
148 } else {
149 down(&tp->count);
150 }
151
152 spin_lock_irqsave(&tp->lock, flags);
153
154 packet->tlabel = find_next_zero_bit(tp->pool, 64, tp->next);
155 if (packet->tlabel > 63)
156 packet->tlabel = find_first_zero_bit(tp->pool, 64);
157 tp->next = (packet->tlabel + 1) % 64;
158 /* Should _never_ happen */
159 BUG_ON(test_and_set_bit(packet->tlabel, tp->pool));
160 tp->allocations++;
161 spin_unlock_irqrestore(&tp->lock, flags);
162
163 return 0;
164} 184}
165 185
166/** 186/**
167 * hpsb_free_tlabel - free an allocated transaction label 187 * hpsb_free_tlabel - free an allocated transaction label
168 * @packet: packet whos tlabel/tpool needs to be cleared 188 * @packet: packet whose tlabel and tl_pool needs to be cleared
169 * 189 *
170 * Frees the transaction label allocated with hpsb_get_tlabel(). The 190 * Frees the transaction label allocated with hpsb_get_tlabel(). The
171 * tlabel has to be freed after the transaction is complete (i.e. response 191 * tlabel has to be freed after the transaction is complete (i.e. response
@@ -176,21 +196,20 @@ int hpsb_get_tlabel(struct hpsb_packet *packet)
176 */ 196 */
177void hpsb_free_tlabel(struct hpsb_packet *packet) 197void hpsb_free_tlabel(struct hpsb_packet *packet)
178{ 198{
179 unsigned long flags; 199 unsigned long flags, *tp;
180 struct hpsb_tlabel_pool *tp; 200 int tlabel, n = NODEID_TO_NODE(packet->node_id);
181 int n = NODEID_TO_NODE(packet->node_id);
182 201
183 if (unlikely(n == ALL_NODES)) 202 if (unlikely(n == ALL_NODES))
184 return; 203 return;
185 tp = &packet->host->tpool[n]; 204 tp = packet->host->tl_pool[n].map;
205 tlabel = packet->tlabel;
206 BUG_ON(tlabel > 63 || tlabel < 0);
186 207
187 BUG_ON(packet->tlabel > 63 || packet->tlabel < 0); 208 spin_lock_irqsave(&hpsb_tlabel_lock, flags);
209 BUG_ON(!__test_and_clear_bit(tlabel, tp));
210 spin_unlock_irqrestore(&hpsb_tlabel_lock, flags);
188 211
189 spin_lock_irqsave(&tp->lock, flags); 212 wake_up_interruptible(&tlabel_wq);
190 BUG_ON(!test_and_clear_bit(packet->tlabel, tp->pool));
191 spin_unlock_irqrestore(&tp->lock, flags);
192
193 up(&tp->count);
194} 213}
195 214
196int hpsb_packet_success(struct hpsb_packet *packet) 215int hpsb_packet_success(struct hpsb_packet *packet)
@@ -214,7 +233,7 @@ int hpsb_packet_success(struct hpsb_packet *packet)
214 packet->node_id); 233 packet->node_id);
215 return -EAGAIN; 234 return -EAGAIN;
216 } 235 }
217 HPSB_PANIC("reached unreachable code 1 in %s", __FUNCTION__); 236 BUG();
218 237
219 case ACK_BUSY_X: 238 case ACK_BUSY_X:
220 case ACK_BUSY_A: 239 case ACK_BUSY_A:
@@ -261,8 +280,7 @@ int hpsb_packet_success(struct hpsb_packet *packet)
261 packet->ack_code, packet->node_id, packet->tcode); 280 packet->ack_code, packet->node_id, packet->tcode);
262 return -EAGAIN; 281 return -EAGAIN;
263 } 282 }
264 283 BUG();
265 HPSB_PANIC("reached unreachable code 2 in %s", __FUNCTION__);
266} 284}
267 285
268struct hpsb_packet *hpsb_make_readpacket(struct hpsb_host *host, nodeid_t node, 286struct hpsb_packet *hpsb_make_readpacket(struct hpsb_host *host, nodeid_t node,
diff --git a/drivers/ieee1394/ieee1394_transactions.h b/drivers/ieee1394/ieee1394_transactions.h
index 45ba784fe6da..c1369c41469b 100644
--- a/drivers/ieee1394/ieee1394_transactions.h
+++ b/drivers/ieee1394/ieee1394_transactions.h
@@ -1,32 +1,32 @@
1#ifndef _IEEE1394_TRANSACTIONS_H 1#ifndef _IEEE1394_TRANSACTIONS_H
2#define _IEEE1394_TRANSACTIONS_H 2#define _IEEE1394_TRANSACTIONS_H
3 3
4#include "ieee1394_core.h" 4#include <linux/types.h>
5 5
6#include "ieee1394_types.h"
7
8struct hpsb_packet;
9struct hpsb_host;
6 10
7/*
8 * Get and free transaction labels.
9 */
10int hpsb_get_tlabel(struct hpsb_packet *packet); 11int hpsb_get_tlabel(struct hpsb_packet *packet);
11void hpsb_free_tlabel(struct hpsb_packet *packet); 12void hpsb_free_tlabel(struct hpsb_packet *packet);
12
13struct hpsb_packet *hpsb_make_readpacket(struct hpsb_host *host, nodeid_t node, 13struct hpsb_packet *hpsb_make_readpacket(struct hpsb_host *host, nodeid_t node,
14 u64 addr, size_t length); 14 u64 addr, size_t length);
15struct hpsb_packet *hpsb_make_lockpacket(struct hpsb_host *host, nodeid_t node, 15struct hpsb_packet *hpsb_make_lockpacket(struct hpsb_host *host, nodeid_t node,
16 u64 addr, int extcode, quadlet_t *data, 16 u64 addr, int extcode, quadlet_t *data,
17 quadlet_t arg); 17 quadlet_t arg);
18struct hpsb_packet *hpsb_make_lock64packet(struct hpsb_host *host, nodeid_t node, 18struct hpsb_packet *hpsb_make_lock64packet(struct hpsb_host *host,
19 u64 addr, int extcode, octlet_t *data, 19 nodeid_t node, u64 addr, int extcode,
20 octlet_t arg); 20 octlet_t *data, octlet_t arg);
21struct hpsb_packet *hpsb_make_phypacket(struct hpsb_host *host, 21struct hpsb_packet *hpsb_make_phypacket(struct hpsb_host *host, quadlet_t data);
22 quadlet_t data) ; 22struct hpsb_packet *hpsb_make_isopacket(struct hpsb_host *host, int length,
23struct hpsb_packet *hpsb_make_isopacket(struct hpsb_host *host, 23 int channel, int tag, int sync);
24 int length, int channel, 24struct hpsb_packet *hpsb_make_writepacket(struct hpsb_host *host,
25 int tag, int sync); 25 nodeid_t node, u64 addr,
26struct hpsb_packet *hpsb_make_writepacket (struct hpsb_host *host, nodeid_t node, 26 quadlet_t *buffer, size_t length);
27 u64 addr, quadlet_t *buffer, size_t length);
28struct hpsb_packet *hpsb_make_streampacket(struct hpsb_host *host, u8 *buffer, 27struct hpsb_packet *hpsb_make_streampacket(struct hpsb_host *host, u8 *buffer,
29 int length, int channel, int tag, int sync); 28 int length, int channel, int tag,
29 int sync);
30 30
31/* 31/*
32 * hpsb_packet_success - Make sense of the ack and reply codes and 32 * hpsb_packet_success - Make sense of the ack and reply codes and
@@ -40,9 +40,8 @@ struct hpsb_packet *hpsb_make_streampacket(struct hpsb_host *host, u8 *buffer,
40 */ 40 */
41int hpsb_packet_success(struct hpsb_packet *packet); 41int hpsb_packet_success(struct hpsb_packet *packet);
42 42
43
44/* 43/*
45 * The generic read, write and lock functions. All recognize the local node ID 44 * The generic read and write functions. All recognize the local node ID
46 * and act accordingly. Read and write automatically use quadlet commands if 45 * and act accordingly. Read and write automatically use quadlet commands if
47 * length == 4 and and block commands otherwise (however, they do not yet 46 * length == 4 and and block commands otherwise (however, they do not yet
48 * support lengths that are not a multiple of 4). You must explicitly specifiy 47 * support lengths that are not a multiple of 4). You must explicitly specifiy
@@ -54,4 +53,8 @@ int hpsb_read(struct hpsb_host *host, nodeid_t node, unsigned int generation,
54int hpsb_write(struct hpsb_host *host, nodeid_t node, unsigned int generation, 53int hpsb_write(struct hpsb_host *host, nodeid_t node, unsigned int generation,
55 u64 addr, quadlet_t *buffer, size_t length); 54 u64 addr, quadlet_t *buffer, size_t length);
56 55
56#ifdef HPSB_DEBUG_TLABELS
57extern spinlock_t hpsb_tlabel_lock;
58#endif
59
57#endif /* _IEEE1394_TRANSACTIONS_H */ 60#endif /* _IEEE1394_TRANSACTIONS_H */
diff --git a/drivers/ieee1394/ieee1394_types.h b/drivers/ieee1394/ieee1394_types.h
index 3165609ec1ec..9803aaa15be0 100644
--- a/drivers/ieee1394/ieee1394_types.h
+++ b/drivers/ieee1394/ieee1394_types.h
@@ -1,37 +1,11 @@
1
2#ifndef _IEEE1394_TYPES_H 1#ifndef _IEEE1394_TYPES_H
3#define _IEEE1394_TYPES_H 2#define _IEEE1394_TYPES_H
4 3
5#include <linux/kernel.h> 4#include <linux/kernel.h>
6#include <linux/types.h>
7#include <linux/list.h>
8#include <linux/init.h>
9#include <linux/spinlock.h>
10#include <linux/string.h> 5#include <linux/string.h>
11 6#include <linux/types.h>
12#include <asm/semaphore.h>
13#include <asm/byteorder.h> 7#include <asm/byteorder.h>
14 8
15
16/* Transaction Label handling */
17struct hpsb_tlabel_pool {
18 DECLARE_BITMAP(pool, 64);
19 spinlock_t lock;
20 u8 next;
21 u32 allocations;
22 struct semaphore count;
23};
24
25#define HPSB_TPOOL_INIT(_tp) \
26do { \
27 bitmap_zero((_tp)->pool, 64); \
28 spin_lock_init(&(_tp)->lock); \
29 (_tp)->next = 0; \
30 (_tp)->allocations = 0; \
31 sema_init(&(_tp)->count, 63); \
32} while (0)
33
34
35typedef u32 quadlet_t; 9typedef u32 quadlet_t;
36typedef u64 octlet_t; 10typedef u64 octlet_t;
37typedef u16 nodeid_t; 11typedef u16 nodeid_t;
@@ -54,46 +28,40 @@ typedef u16 arm_length_t;
54#define NODE_BUS_ARGS(__host, __nodeid) \ 28#define NODE_BUS_ARGS(__host, __nodeid) \
55 __host->id, NODEID_TO_NODE(__nodeid), NODEID_TO_BUS(__nodeid) 29 __host->id, NODEID_TO_NODE(__nodeid), NODEID_TO_BUS(__nodeid)
56 30
57#define HPSB_PRINT(level, fmt, args...) printk(level "ieee1394: " fmt "\n" , ## args) 31#define HPSB_PRINT(level, fmt, args...) \
32 printk(level "ieee1394: " fmt "\n" , ## args)
58 33
59#define HPSB_DEBUG(fmt, args...) HPSB_PRINT(KERN_DEBUG, fmt , ## args) 34#define HPSB_DEBUG(fmt, args...) HPSB_PRINT(KERN_DEBUG, fmt , ## args)
60#define HPSB_INFO(fmt, args...) HPSB_PRINT(KERN_INFO, fmt , ## args) 35#define HPSB_INFO(fmt, args...) HPSB_PRINT(KERN_INFO, fmt , ## args)
61#define HPSB_NOTICE(fmt, args...) HPSB_PRINT(KERN_NOTICE, fmt , ## args) 36#define HPSB_NOTICE(fmt, args...) HPSB_PRINT(KERN_NOTICE, fmt , ## args)
62#define HPSB_WARN(fmt, args...) HPSB_PRINT(KERN_WARNING, fmt , ## args) 37#define HPSB_WARN(fmt, args...) HPSB_PRINT(KERN_WARNING, fmt , ## args)
63#define HPSB_ERR(fmt, args...) HPSB_PRINT(KERN_ERR, fmt , ## args) 38#define HPSB_ERR(fmt, args...) HPSB_PRINT(KERN_ERR, fmt , ## args)
64 39
65#ifdef CONFIG_IEEE1394_VERBOSEDEBUG 40#ifdef CONFIG_IEEE1394_VERBOSEDEBUG
66#define HPSB_VERBOSE(fmt, args...) HPSB_PRINT(KERN_DEBUG, fmt , ## args) 41#define HPSB_VERBOSE(fmt, args...) HPSB_PRINT(KERN_DEBUG, fmt , ## args)
42#define HPSB_DEBUG_TLABELS
67#else 43#else
68#define HPSB_VERBOSE(fmt, args...) 44#define HPSB_VERBOSE(fmt, args...) do {} while (0)
69#endif 45#endif
70 46
71#define HPSB_PANIC(fmt, args...) panic("ieee1394: " fmt "\n" , ## args)
72
73#define HPSB_TRACE() HPSB_PRINT(KERN_INFO, "TRACE - %s, %s(), line %d", __FILE__, __FUNCTION__, __LINE__)
74
75
76#ifdef __BIG_ENDIAN 47#ifdef __BIG_ENDIAN
77 48
78static __inline__ void *memcpy_le32(u32 *dest, const u32 *__src, size_t count) 49static inline void *memcpy_le32(u32 *dest, const u32 *__src, size_t count)
79{ 50{
80 void *tmp = dest; 51 void *tmp = dest;
81 u32 *src = (u32 *)__src; 52 u32 *src = (u32 *)__src;
82 53
83 count /= 4; 54 count /= 4;
84 55 while (count--)
85 while (count--) { 56 *dest++ = swab32p(src++);
86 *dest++ = swab32p(src++); 57 return tmp;
87 }
88
89 return tmp;
90} 58}
91 59
92#else 60#else
93 61
94static __inline__ void *memcpy_le32(u32 *dest, const u32 *src, size_t count) 62static __inline__ void *memcpy_le32(u32 *dest, const u32 *src, size_t count)
95{ 63{
96 return memcpy(dest, src, count); 64 return memcpy(dest, src, count);
97} 65}
98 66
99#endif /* __BIG_ENDIAN */ 67#endif /* __BIG_ENDIAN */
diff --git a/drivers/ieee1394/iso.c b/drivers/ieee1394/iso.c
index f26680ebef7c..08bd15d2a7b6 100644
--- a/drivers/ieee1394/iso.c
+++ b/drivers/ieee1394/iso.c
@@ -9,8 +9,11 @@
9 * directory of the kernel sources for details. 9 * directory of the kernel sources for details.
10 */ 10 */
11 11
12#include <linux/slab.h> 12#include <linux/pci.h>
13#include <linux/sched.h> 13#include <linux/sched.h>
14#include <linux/slab.h>
15
16#include "hosts.h"
14#include "iso.h" 17#include "iso.h"
15 18
16void hpsb_iso_stop(struct hpsb_iso *iso) 19void hpsb_iso_stop(struct hpsb_iso *iso)
diff --git a/drivers/ieee1394/iso.h b/drivers/ieee1394/iso.h
index 3efc60b33a88..1210a97e8685 100644
--- a/drivers/ieee1394/iso.h
+++ b/drivers/ieee1394/iso.h
@@ -12,33 +12,40 @@
12#ifndef IEEE1394_ISO_H 12#ifndef IEEE1394_ISO_H
13#define IEEE1394_ISO_H 13#define IEEE1394_ISO_H
14 14
15#include "hosts.h" 15#include <linux/spinlock_types.h>
16#include <asm/atomic.h>
17#include <asm/types.h>
18
16#include "dma.h" 19#include "dma.h"
17 20
18/* high-level ISO interface */ 21struct hpsb_host;
19 22
20/* This API sends and receives isochronous packets on a large, 23/* high-level ISO interface */
21 virtually-contiguous kernel memory buffer. The buffer may be mapped
22 into a user-space process for zero-copy transmission and reception.
23 24
24 There are no explicit boundaries between packets in the buffer. A 25/*
25 packet may be transmitted or received at any location. However, 26 * This API sends and receives isochronous packets on a large,
26 low-level drivers may impose certain restrictions on alignment or 27 * virtually-contiguous kernel memory buffer. The buffer may be mapped
27 size of packets. (e.g. in OHCI no packet may cross a page boundary, 28 * into a user-space process for zero-copy transmission and reception.
28 and packets should be quadlet-aligned) 29 *
29*/ 30 * There are no explicit boundaries between packets in the buffer. A
31 * packet may be transmitted or received at any location. However,
32 * low-level drivers may impose certain restrictions on alignment or
33 * size of packets. (e.g. in OHCI no packet may cross a page boundary,
34 * and packets should be quadlet-aligned)
35 */
30 36
31/* Packet descriptor - the API maintains a ring buffer of these packet 37/* Packet descriptor - the API maintains a ring buffer of these packet
32 descriptors in kernel memory (hpsb_iso.infos[]). */ 38 * descriptors in kernel memory (hpsb_iso.infos[]). */
33
34struct hpsb_iso_packet_info { 39struct hpsb_iso_packet_info {
35 /* offset of data payload relative to the first byte of the buffer */ 40 /* offset of data payload relative to the first byte of the buffer */
36 __u32 offset; 41 __u32 offset;
37 42
38 /* length of the data payload, in bytes (not including the isochronous header) */ 43 /* length of the data payload, in bytes (not including the isochronous
44 * header) */
39 __u16 len; 45 __u16 len;
40 46
41 /* (recv only) the cycle number (mod 8000) on which the packet was received */ 47 /* (recv only) the cycle number (mod 8000) on which the packet was
48 * received */
42 __u16 cycle; 49 __u16 cycle;
43 50
44 /* (recv only) channel on which the packet was received */ 51 /* (recv only) channel on which the packet was received */
@@ -48,12 +55,10 @@ struct hpsb_iso_packet_info {
48 __u8 tag; 55 __u8 tag;
49 __u8 sy; 56 __u8 sy;
50 57
51 /* 58 /* length in bytes of the packet including header/trailer.
52 * length in bytes of the packet including header/trailer. 59 * MUST be at structure end, since the first part of this structure is
53 * MUST be at structure end, since the first part of this structure is also 60 * also defined in raw1394.h (i.e. struct raw1394_iso_packet_info), is
54 * defined in raw1394.h (i.e. struct raw1394_iso_packet_info), is copied to 61 * copied to userspace and is accessed there through libraw1394. */
55 * userspace and is accessed there through libraw1394.
56 */
57 __u16 total_len; 62 __u16 total_len;
58}; 63};
59 64
@@ -75,8 +80,8 @@ struct hpsb_iso {
75 void *hostdata; 80 void *hostdata;
76 81
77 /* a function to be called (from interrupt context) after 82 /* a function to be called (from interrupt context) after
78 outgoing packets have been sent, or incoming packets have 83 * outgoing packets have been sent, or incoming packets have
79 arrived */ 84 * arrived */
80 void (*callback)(struct hpsb_iso*); 85 void (*callback)(struct hpsb_iso*);
81 86
82 /* wait for buffer space */ 87 /* wait for buffer space */
@@ -88,7 +93,7 @@ struct hpsb_iso {
88 93
89 94
90 /* greatest # of packets between interrupts - controls 95 /* greatest # of packets between interrupts - controls
91 the maximum latency of the buffer */ 96 * the maximum latency of the buffer */
92 int irq_interval; 97 int irq_interval;
93 98
94 /* the buffer for packet data payloads */ 99 /* the buffer for packet data payloads */
@@ -112,8 +117,8 @@ struct hpsb_iso {
112 int pkt_dma; 117 int pkt_dma;
113 118
114 /* how many packets, starting at first_packet: 119 /* how many packets, starting at first_packet:
115 (transmit) are ready to be filled with data 120 * (transmit) are ready to be filled with data
116 (receive) contain received data */ 121 * (receive) contain received data */
117 int n_ready_packets; 122 int n_ready_packets;
118 123
119 /* how many times the buffer has overflowed or underflowed */ 124 /* how many times the buffer has overflowed or underflowed */
@@ -134,7 +139,7 @@ struct hpsb_iso {
134 int start_cycle; 139 int start_cycle;
135 140
136 /* cycle at which next packet will be transmitted, 141 /* cycle at which next packet will be transmitted,
137 -1 if not known */ 142 * -1 if not known */
138 int xmit_cycle; 143 int xmit_cycle;
139 144
140 /* ringbuffer of packet descriptors in regular kernel memory 145 /* ringbuffer of packet descriptors in regular kernel memory
@@ -170,25 +175,30 @@ int hpsb_iso_recv_unlisten_channel(struct hpsb_iso *iso, unsigned char channel);
170int hpsb_iso_recv_set_channel_mask(struct hpsb_iso *iso, u64 mask); 175int hpsb_iso_recv_set_channel_mask(struct hpsb_iso *iso, u64 mask);
171 176
172/* start/stop DMA */ 177/* start/stop DMA */
173int hpsb_iso_xmit_start(struct hpsb_iso *iso, int start_on_cycle, int prebuffer); 178int hpsb_iso_xmit_start(struct hpsb_iso *iso, int start_on_cycle,
174int hpsb_iso_recv_start(struct hpsb_iso *iso, int start_on_cycle, int tag_mask, int sync); 179 int prebuffer);
180int hpsb_iso_recv_start(struct hpsb_iso *iso, int start_on_cycle,
181 int tag_mask, int sync);
175void hpsb_iso_stop(struct hpsb_iso *iso); 182void hpsb_iso_stop(struct hpsb_iso *iso);
176 183
177/* deallocate buffer and DMA context */ 184/* deallocate buffer and DMA context */
178void hpsb_iso_shutdown(struct hpsb_iso *iso); 185void hpsb_iso_shutdown(struct hpsb_iso *iso);
179 186
180/* queue a packet for transmission. 'offset' is relative to the beginning of the 187/* queue a packet for transmission.
181 DMA buffer, where the packet's data payload should already have been placed */ 188 * 'offset' is relative to the beginning of the DMA buffer, where the packet's
182int hpsb_iso_xmit_queue_packet(struct hpsb_iso *iso, u32 offset, u16 len, u8 tag, u8 sy); 189 * data payload should already have been placed. */
190int hpsb_iso_xmit_queue_packet(struct hpsb_iso *iso, u32 offset, u16 len,
191 u8 tag, u8 sy);
183 192
184/* wait until all queued packets have been transmitted to the bus */ 193/* wait until all queued packets have been transmitted to the bus */
185int hpsb_iso_xmit_sync(struct hpsb_iso *iso); 194int hpsb_iso_xmit_sync(struct hpsb_iso *iso);
186 195
187/* N packets have been read out of the buffer, re-use the buffer space */ 196/* N packets have been read out of the buffer, re-use the buffer space */
188int hpsb_iso_recv_release_packets(struct hpsb_iso *recv, unsigned int n_packets); 197int hpsb_iso_recv_release_packets(struct hpsb_iso *recv,
198 unsigned int n_packets);
189 199
190/* check for arrival of new packets immediately (even if irq_interval 200/* check for arrival of new packets immediately (even if irq_interval
191 has not yet been reached) */ 201 * has not yet been reached) */
192int hpsb_iso_recv_flush(struct hpsb_iso *iso); 202int hpsb_iso_recv_flush(struct hpsb_iso *iso);
193 203
194/* returns # of packets ready to send or receive */ 204/* returns # of packets ready to send or receive */
@@ -197,14 +207,15 @@ int hpsb_iso_n_ready(struct hpsb_iso *iso);
197/* the following are callbacks available to low-level drivers */ 207/* the following are callbacks available to low-level drivers */
198 208
199/* call after a packet has been transmitted to the bus (interrupt context is OK) 209/* call after a packet has been transmitted to the bus (interrupt context is OK)
200 'cycle' is the _exact_ cycle the packet was sent on 210 * 'cycle' is the _exact_ cycle the packet was sent on
201 'error' should be non-zero if some sort of error occurred when sending the packet 211 * 'error' should be non-zero if some sort of error occurred when sending the
202*/ 212 * packet */
203void hpsb_iso_packet_sent(struct hpsb_iso *iso, int cycle, int error); 213void hpsb_iso_packet_sent(struct hpsb_iso *iso, int cycle, int error);
204 214
205/* call after a packet has been received (interrupt context OK) */ 215/* call after a packet has been received (interrupt context OK) */
206void hpsb_iso_packet_received(struct hpsb_iso *iso, u32 offset, u16 len, 216void hpsb_iso_packet_received(struct hpsb_iso *iso, u32 offset, u16 len,
207 u16 total_len, u16 cycle, u8 channel, u8 tag, u8 sy); 217 u16 total_len, u16 cycle, u8 channel, u8 tag,
218 u8 sy);
208 219
209/* call to wake waiting processes after buffer space has opened up. */ 220/* call to wake waiting processes after buffer space has opened up. */
210void hpsb_iso_wake(struct hpsb_iso *iso); 221void hpsb_iso_wake(struct hpsb_iso *iso);
diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
index d541b508a159..3e7974c57443 100644
--- a/drivers/ieee1394/nodemgr.c
+++ b/drivers/ieee1394/nodemgr.c
@@ -12,26 +12,23 @@
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/list.h> 13#include <linux/list.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/smp_lock.h>
16#include <linux/interrupt.h>
17#include <linux/kmod.h>
18#include <linux/completion.h>
19#include <linux/delay.h> 15#include <linux/delay.h>
20#include <linux/pci.h> 16#include <linux/kthread.h>
21#include <linux/moduleparam.h> 17#include <linux/moduleparam.h>
22#include <asm/atomic.h> 18#include <asm/atomic.h>
23 19
24#include "ieee1394_types.h" 20#include "csr.h"
21#include "highlevel.h"
22#include "hosts.h"
25#include "ieee1394.h" 23#include "ieee1394.h"
26#include "ieee1394_core.h" 24#include "ieee1394_core.h"
27#include "hosts.h" 25#include "ieee1394_hotplug.h"
26#include "ieee1394_types.h"
28#include "ieee1394_transactions.h" 27#include "ieee1394_transactions.h"
29#include "highlevel.h"
30#include "csr.h"
31#include "nodemgr.h" 28#include "nodemgr.h"
32 29
33static int ignore_drivers; 30static int ignore_drivers;
34module_param(ignore_drivers, int, 0444); 31module_param(ignore_drivers, int, S_IRUGO | S_IWUSR);
35MODULE_PARM_DESC(ignore_drivers, "Disable automatic probing for drivers."); 32MODULE_PARM_DESC(ignore_drivers, "Disable automatic probing for drivers.");
36 33
37struct nodemgr_csr_info { 34struct nodemgr_csr_info {
@@ -71,7 +68,7 @@ static int nodemgr_check_speed(struct nodemgr_csr_info *ci, u64 addr,
71 u8 i, *speed, old_speed, good_speed; 68 u8 i, *speed, old_speed, good_speed;
72 int ret; 69 int ret;
73 70
74 speed = ci->host->speed + NODEID_TO_NODE(ci->nodeid); 71 speed = &(ci->host->speed[NODEID_TO_NODE(ci->nodeid)]);
75 old_speed = *speed; 72 old_speed = *speed;
76 good_speed = IEEE1394_SPEED_MAX + 1; 73 good_speed = IEEE1394_SPEED_MAX + 1;
77 74
@@ -161,16 +158,12 @@ static struct csr1212_bus_ops nodemgr_csr_ops = {
161 * but now we are much simpler because of the LDM. 158 * but now we are much simpler because of the LDM.
162 */ 159 */
163 160
164static DECLARE_MUTEX(nodemgr_serialize); 161static DEFINE_MUTEX(nodemgr_serialize);
165 162
166struct host_info { 163struct host_info {
167 struct hpsb_host *host; 164 struct hpsb_host *host;
168 struct list_head list; 165 struct list_head list;
169 struct completion exited; 166 struct task_struct *thread;
170 struct semaphore reset_sem;
171 int pid;
172 char daemon_name[15];
173 int kill_me;
174}; 167};
175 168
176static int nodemgr_bus_match(struct device * dev, struct device_driver * drv); 169static int nodemgr_bus_match(struct device * dev, struct device_driver * drv);
@@ -334,34 +327,44 @@ static ssize_t fw_show_ne_bus_options(struct device *dev, struct device_attribut
334static DEVICE_ATTR(bus_options,S_IRUGO,fw_show_ne_bus_options,NULL); 327static DEVICE_ATTR(bus_options,S_IRUGO,fw_show_ne_bus_options,NULL);
335 328
336 329
337/* tlabels_free, tlabels_allocations, tlabels_mask are read non-atomically 330#ifdef HPSB_DEBUG_TLABELS
338 * here, therefore displayed values may be occasionally wrong. */ 331static ssize_t fw_show_ne_tlabels_free(struct device *dev,
339static ssize_t fw_show_ne_tlabels_free(struct device *dev, struct device_attribute *attr, char *buf) 332 struct device_attribute *attr, char *buf)
340{ 333{
341 struct node_entry *ne = container_of(dev, struct node_entry, device); 334 struct node_entry *ne = container_of(dev, struct node_entry, device);
342 return sprintf(buf, "%d\n", 64 - bitmap_weight(ne->tpool->pool, 64)); 335 unsigned long flags;
343} 336 unsigned long *tp = ne->host->tl_pool[NODEID_TO_NODE(ne->nodeid)].map;
344static DEVICE_ATTR(tlabels_free,S_IRUGO,fw_show_ne_tlabels_free,NULL); 337 int tf;
345 338
339 spin_lock_irqsave(&hpsb_tlabel_lock, flags);
340 tf = 64 - bitmap_weight(tp, 64);
341 spin_unlock_irqrestore(&hpsb_tlabel_lock, flags);
346 342
347static ssize_t fw_show_ne_tlabels_allocations(struct device *dev, struct device_attribute *attr, char *buf) 343 return sprintf(buf, "%d\n", tf);
348{
349 struct node_entry *ne = container_of(dev, struct node_entry, device);
350 return sprintf(buf, "%u\n", ne->tpool->allocations);
351} 344}
352static DEVICE_ATTR(tlabels_allocations,S_IRUGO,fw_show_ne_tlabels_allocations,NULL); 345static DEVICE_ATTR(tlabels_free,S_IRUGO,fw_show_ne_tlabels_free,NULL);
353 346
354 347
355static ssize_t fw_show_ne_tlabels_mask(struct device *dev, struct device_attribute *attr, char *buf) 348static ssize_t fw_show_ne_tlabels_mask(struct device *dev,
349 struct device_attribute *attr, char *buf)
356{ 350{
357 struct node_entry *ne = container_of(dev, struct node_entry, device); 351 struct node_entry *ne = container_of(dev, struct node_entry, device);
352 unsigned long flags;
353 unsigned long *tp = ne->host->tl_pool[NODEID_TO_NODE(ne->nodeid)].map;
354 u64 tm;
355
356 spin_lock_irqsave(&hpsb_tlabel_lock, flags);
358#if (BITS_PER_LONG <= 32) 357#if (BITS_PER_LONG <= 32)
359 return sprintf(buf, "0x%08lx%08lx\n", ne->tpool->pool[0], ne->tpool->pool[1]); 358 tm = ((u64)tp[0] << 32) + tp[1];
360#else 359#else
361 return sprintf(buf, "0x%016lx\n", ne->tpool->pool[0]); 360 tm = tp[0];
362#endif 361#endif
362 spin_unlock_irqrestore(&hpsb_tlabel_lock, flags);
363
364 return sprintf(buf, "0x%016llx\n", tm);
363} 365}
364static DEVICE_ATTR(tlabels_mask, S_IRUGO, fw_show_ne_tlabels_mask, NULL); 366static DEVICE_ATTR(tlabels_mask, S_IRUGO, fw_show_ne_tlabels_mask, NULL);
367#endif /* HPSB_DEBUG_TLABELS */
365 368
366 369
367static ssize_t fw_set_ignore_driver(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 370static ssize_t fw_set_ignore_driver(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
@@ -408,26 +411,11 @@ static ssize_t fw_get_destroy_node(struct bus_type *bus, char *buf)
408} 411}
409static BUS_ATTR(destroy_node, S_IWUSR | S_IRUGO, fw_get_destroy_node, fw_set_destroy_node); 412static BUS_ATTR(destroy_node, S_IWUSR | S_IRUGO, fw_get_destroy_node, fw_set_destroy_node);
410 413
411static int nodemgr_rescan_bus_thread(void *__unused)
412{
413 /* No userlevel access needed */
414 daemonize("kfwrescan");
415
416 bus_rescan_devices(&ieee1394_bus_type);
417
418 return 0;
419}
420 414
421static ssize_t fw_set_rescan(struct bus_type *bus, const char *buf, size_t count) 415static ssize_t fw_set_rescan(struct bus_type *bus, const char *buf, size_t count)
422{ 416{
423 int state = simple_strtoul(buf, NULL, 10); 417 if (simple_strtoul(buf, NULL, 10) == 1)
424 418 bus_rescan_devices(&ieee1394_bus_type);
425 /* Don't wait for this, or care about errors. Root could do
426 * something stupid and spawn this a lot of times, but that's
427 * root's fault. */
428 if (state == 1)
429 kernel_thread(nodemgr_rescan_bus_thread, NULL, CLONE_KERNEL);
430
431 return count; 419 return count;
432} 420}
433static ssize_t fw_get_rescan(struct bus_type *bus, char *buf) 421static ssize_t fw_get_rescan(struct bus_type *bus, char *buf)
@@ -483,9 +471,10 @@ static struct device_attribute *const fw_ne_attrs[] = {
483 &dev_attr_ne_vendor_id, 471 &dev_attr_ne_vendor_id,
484 &dev_attr_ne_nodeid, 472 &dev_attr_ne_nodeid,
485 &dev_attr_bus_options, 473 &dev_attr_bus_options,
474#ifdef HPSB_DEBUG_TLABELS
486 &dev_attr_tlabels_free, 475 &dev_attr_tlabels_free,
487 &dev_attr_tlabels_allocations,
488 &dev_attr_tlabels_mask, 476 &dev_attr_tlabels_mask,
477#endif
489}; 478};
490 479
491 480
@@ -804,8 +793,6 @@ static struct node_entry *nodemgr_create_node(octlet_t guid, struct csr1212_csr
804 if (!ne) 793 if (!ne)
805 return NULL; 794 return NULL;
806 795
807 ne->tpool = &host->tpool[nodeid & NODE_MASK];
808
809 ne->host = host; 796 ne->host = host;
810 ne->nodeid = nodeid; 797 ne->nodeid = nodeid;
811 ne->generation = generation; 798 ne->generation = generation;
@@ -1251,6 +1238,7 @@ static void nodemgr_node_scan_one(struct host_info *hi,
1251 octlet_t guid; 1238 octlet_t guid;
1252 struct csr1212_csr *csr; 1239 struct csr1212_csr *csr;
1253 struct nodemgr_csr_info *ci; 1240 struct nodemgr_csr_info *ci;
1241 u8 *speed;
1254 1242
1255 ci = kmalloc(sizeof(*ci), GFP_KERNEL); 1243 ci = kmalloc(sizeof(*ci), GFP_KERNEL);
1256 if (!ci) 1244 if (!ci)
@@ -1259,8 +1247,12 @@ static void nodemgr_node_scan_one(struct host_info *hi,
1259 ci->host = host; 1247 ci->host = host;
1260 ci->nodeid = nodeid; 1248 ci->nodeid = nodeid;
1261 ci->generation = generation; 1249 ci->generation = generation;
1262 ci->speed_unverified = 1250
1263 host->speed[NODEID_TO_NODE(nodeid)] > IEEE1394_SPEED_100; 1251 /* Prepare for speed probe which occurs when reading the ROM */
1252 speed = &(host->speed[NODEID_TO_NODE(nodeid)]);
1253 if (*speed > host->csr.lnk_spd)
1254 *speed = host->csr.lnk_spd;
1255 ci->speed_unverified = *speed > IEEE1394_SPEED_100;
1264 1256
1265 /* We need to detect when the ConfigROM's generation has changed, 1257 /* We need to detect when the ConfigROM's generation has changed,
1266 * so we only update the node's info when it needs to be. */ 1258 * so we only update the node's info when it needs to be. */
@@ -1300,8 +1292,6 @@ static void nodemgr_node_scan_one(struct host_info *hi,
1300 nodemgr_create_node(guid, csr, hi, nodeid, generation); 1292 nodemgr_create_node(guid, csr, hi, nodeid, generation);
1301 else 1293 else
1302 nodemgr_update_node(ne, csr, hi, nodeid, generation); 1294 nodemgr_update_node(ne, csr, hi, nodeid, generation);
1303
1304 return;
1305} 1295}
1306 1296
1307 1297
@@ -1326,6 +1316,7 @@ static void nodemgr_node_scan(struct host_info *hi, int generation)
1326} 1316}
1327 1317
1328 1318
1319/* Caller needs to hold nodemgr_ud_class.subsys.rwsem as reader. */
1329static void nodemgr_suspend_ne(struct node_entry *ne) 1320static void nodemgr_suspend_ne(struct node_entry *ne)
1330{ 1321{
1331 struct class_device *cdev; 1322 struct class_device *cdev;
@@ -1361,6 +1352,7 @@ static void nodemgr_resume_ne(struct node_entry *ne)
1361 ne->in_limbo = 0; 1352 ne->in_limbo = 0;
1362 device_remove_file(&ne->device, &dev_attr_ne_in_limbo); 1353 device_remove_file(&ne->device, &dev_attr_ne_in_limbo);
1363 1354
1355 down_read(&nodemgr_ud_class.subsys.rwsem);
1364 down_read(&ne->device.bus->subsys.rwsem); 1356 down_read(&ne->device.bus->subsys.rwsem);
1365 list_for_each_entry(cdev, &nodemgr_ud_class.children, node) { 1357 list_for_each_entry(cdev, &nodemgr_ud_class.children, node) {
1366 ud = container_of(cdev, struct unit_directory, class_dev); 1358 ud = container_of(cdev, struct unit_directory, class_dev);
@@ -1372,21 +1364,21 @@ static void nodemgr_resume_ne(struct node_entry *ne)
1372 ud->device.driver->resume(&ud->device); 1364 ud->device.driver->resume(&ud->device);
1373 } 1365 }
1374 up_read(&ne->device.bus->subsys.rwsem); 1366 up_read(&ne->device.bus->subsys.rwsem);
1367 up_read(&nodemgr_ud_class.subsys.rwsem);
1375 1368
1376 HPSB_DEBUG("Node resumed: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]", 1369 HPSB_DEBUG("Node resumed: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
1377 NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid); 1370 NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid);
1378} 1371}
1379 1372
1380 1373
1374/* Caller needs to hold nodemgr_ud_class.subsys.rwsem as reader. */
1381static void nodemgr_update_pdrv(struct node_entry *ne) 1375static void nodemgr_update_pdrv(struct node_entry *ne)
1382{ 1376{
1383 struct unit_directory *ud; 1377 struct unit_directory *ud;
1384 struct hpsb_protocol_driver *pdrv; 1378 struct hpsb_protocol_driver *pdrv;
1385 struct class *class = &nodemgr_ud_class;
1386 struct class_device *cdev; 1379 struct class_device *cdev;
1387 1380
1388 down_read(&class->subsys.rwsem); 1381 list_for_each_entry(cdev, &nodemgr_ud_class.children, node) {
1389 list_for_each_entry(cdev, &class->children, node) {
1390 ud = container_of(cdev, struct unit_directory, class_dev); 1382 ud = container_of(cdev, struct unit_directory, class_dev);
1391 if (ud->ne != ne || !ud->device.driver) 1383 if (ud->ne != ne || !ud->device.driver)
1392 continue; 1384 continue;
@@ -1399,7 +1391,6 @@ static void nodemgr_update_pdrv(struct node_entry *ne)
1399 up_write(&ud->device.bus->subsys.rwsem); 1391 up_write(&ud->device.bus->subsys.rwsem);
1400 } 1392 }
1401 } 1393 }
1402 up_read(&class->subsys.rwsem);
1403} 1394}
1404 1395
1405 1396
@@ -1430,6 +1421,8 @@ static void nodemgr_irm_write_bc(struct node_entry *ne, int generation)
1430} 1421}
1431 1422
1432 1423
1424/* Caller needs to hold nodemgr_ud_class.subsys.rwsem as reader because the
1425 * calls to nodemgr_update_pdrv() and nodemgr_suspend_ne() here require it. */
1433static void nodemgr_probe_ne(struct host_info *hi, struct node_entry *ne, int generation) 1426static void nodemgr_probe_ne(struct host_info *hi, struct node_entry *ne, int generation)
1434{ 1427{
1435 struct device *dev; 1428 struct device *dev;
@@ -1492,9 +1485,8 @@ static void nodemgr_node_probe(struct host_info *hi, int generation)
1492 /* If we had a bus reset while we were scanning the bus, it is 1485 /* If we had a bus reset while we were scanning the bus, it is
1493 * possible that we did not probe all nodes. In that case, we 1486 * possible that we did not probe all nodes. In that case, we
1494 * skip the clean up for now, since we could remove nodes that 1487 * skip the clean up for now, since we could remove nodes that
1495 * were still on the bus. The bus reset increased hi->reset_sem, 1488 * were still on the bus. Another bus scan is pending which will
1496 * so there's a bus scan pending which will do the clean up 1489 * do the clean up eventually.
1497 * eventually.
1498 * 1490 *
1499 * Now let's tell the bus to rescan our devices. This may seem 1491 * Now let's tell the bus to rescan our devices. This may seem
1500 * like overhead, but the driver-model core will only scan a 1492 * like overhead, but the driver-model core will only scan a
@@ -1622,41 +1614,37 @@ static int nodemgr_host_thread(void *__hi)
1622{ 1614{
1623 struct host_info *hi = (struct host_info *)__hi; 1615 struct host_info *hi = (struct host_info *)__hi;
1624 struct hpsb_host *host = hi->host; 1616 struct hpsb_host *host = hi->host;
1625 int reset_cycles = 0; 1617 unsigned int g, generation = get_hpsb_generation(host) - 1;
1626 1618 int i, reset_cycles = 0;
1627 /* No userlevel access needed */
1628 daemonize(hi->daemon_name);
1629 1619
1630 /* Setup our device-model entries */ 1620 /* Setup our device-model entries */
1631 nodemgr_create_host_dev_files(host); 1621 nodemgr_create_host_dev_files(host);
1632 1622
1633 /* Sit and wait for a signal to probe the nodes on the bus. This 1623 for (;;) {
1634 * happens when we get a bus reset. */ 1624 /* Sleep until next bus reset */
1635 while (1) { 1625 set_current_state(TASK_INTERRUPTIBLE);
1636 unsigned int generation = 0; 1626 if (get_hpsb_generation(host) == generation)
1637 int i; 1627 schedule();
1628 __set_current_state(TASK_RUNNING);
1629
1630 /* Thread may have been woken up to freeze or to exit */
1631 if (try_to_freeze())
1632 continue;
1633 if (kthread_should_stop())
1634 goto exit;
1638 1635
1639 if (down_interruptible(&hi->reset_sem) || 1636 if (mutex_lock_interruptible(&nodemgr_serialize)) {
1640 down_interruptible(&nodemgr_serialize)) {
1641 if (try_to_freeze()) 1637 if (try_to_freeze())
1642 continue; 1638 continue;
1643 printk("NodeMgr: received unexpected signal?!\n" ); 1639 goto exit;
1644 break;
1645 }
1646
1647 if (hi->kill_me) {
1648 up(&nodemgr_serialize);
1649 break;
1650 } 1640 }
1651 1641
1652 /* Pause for 1/4 second in 1/16 second intervals, 1642 /* Pause for 1/4 second in 1/16 second intervals,
1653 * to make sure things settle down. */ 1643 * to make sure things settle down. */
1644 g = get_hpsb_generation(host);
1654 for (i = 0; i < 4 ; i++) { 1645 for (i = 0; i < 4 ; i++) {
1655 set_current_state(TASK_INTERRUPTIBLE); 1646 if (msleep_interruptible(63) || kthread_should_stop())
1656 if (msleep_interruptible(63)) { 1647 goto unlock_exit;
1657 up(&nodemgr_serialize);
1658 goto caught_signal;
1659 }
1660 1648
1661 /* Now get the generation in which the node ID's we collect 1649 /* Now get the generation in which the node ID's we collect
1662 * are valid. During the bus scan we will use this generation 1650 * are valid. During the bus scan we will use this generation
@@ -1667,20 +1655,14 @@ static int nodemgr_host_thread(void *__hi)
1667 1655
1668 /* If we get a reset before we are done waiting, then 1656 /* If we get a reset before we are done waiting, then
1669 * start the the waiting over again */ 1657 * start the the waiting over again */
1670 while (!down_trylock(&hi->reset_sem)) 1658 if (generation != g)
1671 i = 0; 1659 g = generation, i = 0;
1672
1673 /* Check the kill_me again */
1674 if (hi->kill_me) {
1675 up(&nodemgr_serialize);
1676 goto caught_signal;
1677 }
1678 } 1660 }
1679 1661
1680 if (!nodemgr_check_irm_capability(host, reset_cycles) || 1662 if (!nodemgr_check_irm_capability(host, reset_cycles) ||
1681 !nodemgr_do_irm_duties(host, reset_cycles)) { 1663 !nodemgr_do_irm_duties(host, reset_cycles)) {
1682 reset_cycles++; 1664 reset_cycles++;
1683 up(&nodemgr_serialize); 1665 mutex_unlock(&nodemgr_serialize);
1684 continue; 1666 continue;
1685 } 1667 }
1686 reset_cycles = 0; 1668 reset_cycles = 0;
@@ -1698,13 +1680,13 @@ static int nodemgr_host_thread(void *__hi)
1698 /* Update some of our sysfs symlinks */ 1680 /* Update some of our sysfs symlinks */
1699 nodemgr_update_host_dev_links(host); 1681 nodemgr_update_host_dev_links(host);
1700 1682
1701 up(&nodemgr_serialize); 1683 mutex_unlock(&nodemgr_serialize);
1702 } 1684 }
1703 1685unlock_exit:
1704caught_signal: 1686 mutex_unlock(&nodemgr_serialize);
1687exit:
1705 HPSB_VERBOSE("NodeMgr: Exiting thread"); 1688 HPSB_VERBOSE("NodeMgr: Exiting thread");
1706 1689 return 0;
1707 complete_and_exit(&hi->exited, 0);
1708} 1690}
1709 1691
1710int nodemgr_for_each_host(void *__data, int (*cb)(struct hpsb_host *, void *)) 1692int nodemgr_for_each_host(void *__data, int (*cb)(struct hpsb_host *, void *))
@@ -1764,41 +1746,27 @@ static void nodemgr_add_host(struct hpsb_host *host)
1764 struct host_info *hi; 1746 struct host_info *hi;
1765 1747
1766 hi = hpsb_create_hostinfo(&nodemgr_highlevel, host, sizeof(*hi)); 1748 hi = hpsb_create_hostinfo(&nodemgr_highlevel, host, sizeof(*hi));
1767
1768 if (!hi) { 1749 if (!hi) {
1769 HPSB_ERR ("NodeMgr: out of memory in add host"); 1750 HPSB_ERR("NodeMgr: out of memory in add host");
1770 return; 1751 return;
1771 } 1752 }
1772
1773 hi->host = host; 1753 hi->host = host;
1774 init_completion(&hi->exited); 1754 hi->thread = kthread_run(nodemgr_host_thread, hi, "knodemgrd_%d",
1775 sema_init(&hi->reset_sem, 0); 1755 host->id);
1776 1756 if (IS_ERR(hi->thread)) {
1777 sprintf(hi->daemon_name, "knodemgrd_%d", host->id); 1757 HPSB_ERR("NodeMgr: cannot start thread for host %d", host->id);
1778
1779 hi->pid = kernel_thread(nodemgr_host_thread, hi, CLONE_KERNEL);
1780
1781 if (hi->pid < 0) {
1782 HPSB_ERR ("NodeMgr: failed to start %s thread for %s",
1783 hi->daemon_name, host->driver->name);
1784 hpsb_destroy_hostinfo(&nodemgr_highlevel, host); 1758 hpsb_destroy_hostinfo(&nodemgr_highlevel, host);
1785 return;
1786 } 1759 }
1787
1788 return;
1789} 1760}
1790 1761
1791static void nodemgr_host_reset(struct hpsb_host *host) 1762static void nodemgr_host_reset(struct hpsb_host *host)
1792{ 1763{
1793 struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host); 1764 struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host);
1794 1765
1795 if (hi != NULL) { 1766 if (hi) {
1796 HPSB_VERBOSE("NodeMgr: Processing host reset for %s", hi->daemon_name); 1767 HPSB_VERBOSE("NodeMgr: Processing reset for host %d", host->id);
1797 up(&hi->reset_sem); 1768 wake_up_process(hi->thread);
1798 } else 1769 }
1799 HPSB_ERR ("NodeMgr: could not process reset of unused host");
1800
1801 return;
1802} 1770}
1803 1771
1804static void nodemgr_remove_host(struct hpsb_host *host) 1772static void nodemgr_remove_host(struct hpsb_host *host)
@@ -1806,18 +1774,9 @@ static void nodemgr_remove_host(struct hpsb_host *host)
1806 struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host); 1774 struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host);
1807 1775
1808 if (hi) { 1776 if (hi) {
1809 if (hi->pid >= 0) { 1777 kthread_stop(hi->thread);
1810 hi->kill_me = 1; 1778 nodemgr_remove_host_dev(&host->device);
1811 mb(); 1779 }
1812 up(&hi->reset_sem);
1813 wait_for_completion(&hi->exited);
1814 nodemgr_remove_host_dev(&host->device);
1815 }
1816 } else
1817 HPSB_ERR("NodeMgr: host %s does not exist, cannot remove",
1818 host->driver->name);
1819
1820 return;
1821} 1780}
1822 1781
1823static struct hpsb_highlevel nodemgr_highlevel = { 1782static struct hpsb_highlevel nodemgr_highlevel = {
diff --git a/drivers/ieee1394/nodemgr.h b/drivers/ieee1394/nodemgr.h
index 0b26616e16c3..0e1e7d930783 100644
--- a/drivers/ieee1394/nodemgr.h
+++ b/drivers/ieee1394/nodemgr.h
@@ -21,9 +21,15 @@
21#define _IEEE1394_NODEMGR_H 21#define _IEEE1394_NODEMGR_H
22 22
23#include <linux/device.h> 23#include <linux/device.h>
24#include "csr1212.h" 24#include <asm/types.h>
25
25#include "ieee1394_core.h" 26#include "ieee1394_core.h"
26#include "ieee1394_hotplug.h" 27#include "ieee1394_types.h"
28
29struct csr1212_csr;
30struct csr1212_keyval;
31struct hpsb_host;
32struct ieee1394_device_id;
27 33
28/* '1' '3' '9' '4' in ASCII */ 34/* '1' '3' '9' '4' in ASCII */
29#define IEEE1394_BUSID_MAGIC __constant_cpu_to_be32(0x31333934) 35#define IEEE1394_BUSID_MAGIC __constant_cpu_to_be32(0x31333934)
@@ -44,7 +50,6 @@ struct bus_options {
44 u16 max_rec; /* Maximum packet size node can receive */ 50 u16 max_rec; /* Maximum packet size node can receive */
45}; 51};
46 52
47
48#define UNIT_DIRECTORY_VENDOR_ID 0x01 53#define UNIT_DIRECTORY_VENDOR_ID 0x01
49#define UNIT_DIRECTORY_MODEL_ID 0x02 54#define UNIT_DIRECTORY_MODEL_ID 0x02
50#define UNIT_DIRECTORY_SPECIFIER_ID 0x04 55#define UNIT_DIRECTORY_SPECIFIER_ID 0x04
@@ -59,8 +64,8 @@ struct bus_options {
59 * unit directory for each of these protocols. 64 * unit directory for each of these protocols.
60 */ 65 */
61struct unit_directory { 66struct unit_directory {
62 struct node_entry *ne; /* The node which this directory belongs to */ 67 struct node_entry *ne; /* The node which this directory belongs to */
63 octlet_t address; /* Address of the unit directory on the node */ 68 octlet_t address; /* Address of the unit directory on the node */
64 u8 flags; /* Indicates which entries were read */ 69 u8 flags; /* Indicates which entries were read */
65 70
66 quadlet_t vendor_id; 71 quadlet_t vendor_id;
@@ -79,11 +84,10 @@ struct unit_directory {
79 int length; /* Number of quadlets */ 84 int length; /* Number of quadlets */
80 85
81 struct device device; 86 struct device device;
82
83 struct class_device class_dev; 87 struct class_device class_dev;
84 88
85 struct csr1212_keyval *ud_kv; 89 struct csr1212_keyval *ud_kv;
86 u32 lun; /* logical unit number immediate value */ 90 u32 lun; /* logical unit number immediate value */
87}; 91};
88 92
89struct node_entry { 93struct node_entry {
@@ -103,10 +107,8 @@ struct node_entry {
103 const char *vendor_oui; 107 const char *vendor_oui;
104 108
105 u32 capabilities; 109 u32 capabilities;
106 struct hpsb_tlabel_pool *tpool;
107 110
108 struct device device; 111 struct device device;
109
110 struct class_device class_dev; 112 struct class_device class_dev;
111 113
112 /* Means this node is not attached anymore */ 114 /* Means this node is not attached anymore */
@@ -153,8 +155,8 @@ static inline int hpsb_node_entry_valid(struct node_entry *ne)
153/* 155/*
154 * This will fill in the given, pre-initialised hpsb_packet with the current 156 * This will fill in the given, pre-initialised hpsb_packet with the current
155 * information from the node entry (host, node ID, generation number). It will 157 * information from the node entry (host, node ID, generation number). It will
156 * return false if the node owning the GUID is not accessible (and not modify the 158 * return false if the node owning the GUID is not accessible (and not modify
157 * hpsb_packet) and return true otherwise. 159 * the hpsb_packet) and return true otherwise.
158 * 160 *
159 * Note that packet sending may still fail in hpsb_send_packet if a bus reset 161 * Note that packet sending may still fail in hpsb_send_packet if a bus reset
160 * happens while you are trying to set up the packet (due to obsolete generation 162 * happens while you are trying to set up the packet (due to obsolete generation
@@ -170,16 +172,13 @@ int hpsb_node_write(struct node_entry *ne, u64 addr,
170int hpsb_node_lock(struct node_entry *ne, u64 addr, 172int hpsb_node_lock(struct node_entry *ne, u64 addr,
171 int extcode, quadlet_t *data, quadlet_t arg); 173 int extcode, quadlet_t *data, quadlet_t arg);
172 174
173
174/* Iterate the hosts, calling a given function with supplied data for each 175/* Iterate the hosts, calling a given function with supplied data for each
175 * host. */ 176 * host. */
176int nodemgr_for_each_host(void *__data, int (*cb)(struct hpsb_host *, void *)); 177int nodemgr_for_each_host(void *__data, int (*cb)(struct hpsb_host *, void *));
177 178
178
179int init_ieee1394_nodemgr(void); 179int init_ieee1394_nodemgr(void);
180void cleanup_ieee1394_nodemgr(void); 180void cleanup_ieee1394_nodemgr(void);
181 181
182
183/* The template for a host device */ 182/* The template for a host device */
184extern struct device nodemgr_dev_template_host; 183extern struct device nodemgr_dev_template_host;
185 184
diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c
index 448df2773377..8fd0030475ba 100644
--- a/drivers/ieee1394/ohci1394.c
+++ b/drivers/ieee1394/ohci1394.c
@@ -136,7 +136,7 @@
136#define DBGMSG(fmt, args...) \ 136#define DBGMSG(fmt, args...) \
137printk(KERN_INFO "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args) 137printk(KERN_INFO "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args)
138#else 138#else
139#define DBGMSG(fmt, args...) 139#define DBGMSG(fmt, args...) do {} while (0)
140#endif 140#endif
141 141
142#ifdef CONFIG_IEEE1394_OHCI_DMA_DEBUG 142#ifdef CONFIG_IEEE1394_OHCI_DMA_DEBUG
@@ -148,8 +148,8 @@ printk(KERN_INFO "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->
148 --global_outstanding_dmas, ## args) 148 --global_outstanding_dmas, ## args)
149static int global_outstanding_dmas = 0; 149static int global_outstanding_dmas = 0;
150#else 150#else
151#define OHCI_DMA_ALLOC(fmt, args...) 151#define OHCI_DMA_ALLOC(fmt, args...) do {} while (0)
152#define OHCI_DMA_FREE(fmt, args...) 152#define OHCI_DMA_FREE(fmt, args...) do {} while (0)
153#endif 153#endif
154 154
155/* print general (card independent) information */ 155/* print general (card independent) information */
@@ -181,36 +181,35 @@ static int alloc_dma_trm_ctx(struct ti_ohci *ohci, struct dma_trm_ctx *d,
181static void ohci1394_pci_remove(struct pci_dev *pdev); 181static void ohci1394_pci_remove(struct pci_dev *pdev);
182 182
183#ifndef __LITTLE_ENDIAN 183#ifndef __LITTLE_ENDIAN
184static unsigned hdr_sizes[] = 184const static size_t hdr_sizes[] = {
185{
186 3, /* TCODE_WRITEQ */ 185 3, /* TCODE_WRITEQ */
187 4, /* TCODE_WRITEB */ 186 4, /* TCODE_WRITEB */
188 3, /* TCODE_WRITE_RESPONSE */ 187 3, /* TCODE_WRITE_RESPONSE */
189 0, /* ??? */ 188 0, /* reserved */
190 3, /* TCODE_READQ */ 189 3, /* TCODE_READQ */
191 4, /* TCODE_READB */ 190 4, /* TCODE_READB */
192 3, /* TCODE_READQ_RESPONSE */ 191 3, /* TCODE_READQ_RESPONSE */
193 4, /* TCODE_READB_RESPONSE */ 192 4, /* TCODE_READB_RESPONSE */
194 1, /* TCODE_CYCLE_START (???) */ 193 1, /* TCODE_CYCLE_START */
195 4, /* TCODE_LOCK_REQUEST */ 194 4, /* TCODE_LOCK_REQUEST */
196 2, /* TCODE_ISO_DATA */ 195 2, /* TCODE_ISO_DATA */
197 4, /* TCODE_LOCK_RESPONSE */ 196 4, /* TCODE_LOCK_RESPONSE */
197 /* rest is reserved or link-internal */
198}; 198};
199 199
200/* Swap headers */ 200static inline void header_le32_to_cpu(quadlet_t *data, unsigned char tcode)
201static inline void packet_swab(quadlet_t *data, int tcode)
202{ 201{
203 size_t size = hdr_sizes[tcode]; 202 size_t size;
204 203
205 if (tcode > TCODE_LOCK_RESPONSE || hdr_sizes[tcode] == 0) 204 if (unlikely(tcode >= ARRAY_SIZE(hdr_sizes)))
206 return; 205 return;
207 206
207 size = hdr_sizes[tcode];
208 while (size--) 208 while (size--)
209 data[size] = swab32(data[size]); 209 data[size] = le32_to_cpu(data[size]);
210} 210}
211#else 211#else
212/* Don't waste cycles on same sex byte swaps */ 212#define header_le32_to_cpu(w,x) do {} while (0)
213#define packet_swab(w,x)
214#endif /* !LITTLE_ENDIAN */ 213#endif /* !LITTLE_ENDIAN */
215 214
216/*********************************** 215/***********************************
@@ -701,7 +700,7 @@ static void insert_packet(struct ti_ohci *ohci,
701 d->prg_cpu[idx]->data[2] = packet->header[2]; 700 d->prg_cpu[idx]->data[2] = packet->header[2];
702 d->prg_cpu[idx]->data[3] = packet->header[3]; 701 d->prg_cpu[idx]->data[3] = packet->header[3];
703 } 702 }
704 packet_swab(d->prg_cpu[idx]->data, packet->tcode); 703 header_le32_to_cpu(d->prg_cpu[idx]->data, packet->tcode);
705 } 704 }
706 705
707 if (packet->data_size) { /* block transmit */ 706 if (packet->data_size) { /* block transmit */
@@ -777,7 +776,7 @@ static void insert_packet(struct ti_ohci *ohci,
777 d->prg_cpu[idx]->data[0] = packet->speed_code<<16 | 776 d->prg_cpu[idx]->data[0] = packet->speed_code<<16 |
778 (packet->header[0] & 0xFFFF); 777 (packet->header[0] & 0xFFFF);
779 d->prg_cpu[idx]->data[1] = packet->header[0] & 0xFFFF0000; 778 d->prg_cpu[idx]->data[1] = packet->header[0] & 0xFFFF0000;
780 packet_swab(d->prg_cpu[idx]->data, packet->tcode); 779 header_le32_to_cpu(d->prg_cpu[idx]->data, packet->tcode);
781 780
782 d->prg_cpu[idx]->begin.control = 781 d->prg_cpu[idx]->begin.control =
783 cpu_to_le32(DMA_CTL_OUTPUT_MORE | 782 cpu_to_le32(DMA_CTL_OUTPUT_MORE |
@@ -2598,8 +2597,9 @@ static const int TCODE_SIZE[16] = {20, 0, 16, -1, 16, 20, 20, 0,
2598 * Determine the length of a packet in the buffer 2597 * Determine the length of a packet in the buffer
2599 * Optimization suggested by Pascal Drolet <pascal.drolet@informission.ca> 2598 * Optimization suggested by Pascal Drolet <pascal.drolet@informission.ca>
2600 */ 2599 */
2601static __inline__ int packet_length(struct dma_rcv_ctx *d, int idx, quadlet_t *buf_ptr, 2600static inline int packet_length(struct dma_rcv_ctx *d, int idx,
2602 int offset, unsigned char tcode, int noswap) 2601 quadlet_t *buf_ptr, int offset,
2602 unsigned char tcode, int noswap)
2603{ 2603{
2604 int length = -1; 2604 int length = -1;
2605 2605
@@ -2730,7 +2730,7 @@ static void dma_rcv_tasklet (unsigned long data)
2730 * bus reset. We always ignore it. */ 2730 * bus reset. We always ignore it. */
2731 if (tcode != OHCI1394_TCODE_PHY) { 2731 if (tcode != OHCI1394_TCODE_PHY) {
2732 if (!ohci->no_swap_incoming) 2732 if (!ohci->no_swap_incoming)
2733 packet_swab(d->spb, tcode); 2733 header_le32_to_cpu(d->spb, tcode);
2734 DBGMSG("Packet received from node" 2734 DBGMSG("Packet received from node"
2735 " %d ack=0x%02X spd=%d tcode=0x%X" 2735 " %d ack=0x%02X spd=%d tcode=0x%X"
2736 " length=%d ctx=%d tlabel=%d", 2736 " length=%d ctx=%d tlabel=%d",
@@ -2738,7 +2738,7 @@ static void dma_rcv_tasklet (unsigned long data)
2738 (cond_le32_to_cpu(d->spb[length/4-1], ohci->no_swap_incoming)>>16)&0x1f, 2738 (cond_le32_to_cpu(d->spb[length/4-1], ohci->no_swap_incoming)>>16)&0x1f,
2739 (cond_le32_to_cpu(d->spb[length/4-1], ohci->no_swap_incoming)>>21)&0x3, 2739 (cond_le32_to_cpu(d->spb[length/4-1], ohci->no_swap_incoming)>>21)&0x3,
2740 tcode, length, d->ctx, 2740 tcode, length, d->ctx,
2741 (cond_le32_to_cpu(d->spb[0], ohci->no_swap_incoming)>>10)&0x3f); 2741 (d->spb[0]>>10)&0x3f);
2742 2742
2743 ack = (((cond_le32_to_cpu(d->spb[length/4-1], ohci->no_swap_incoming)>>16)&0x1f) 2743 ack = (((cond_le32_to_cpu(d->spb[length/4-1], ohci->no_swap_incoming)>>16)&0x1f)
2744 == 0x11) ? 1 : 0; 2744 == 0x11) ? 1 : 0;
@@ -3529,9 +3529,10 @@ static void ohci1394_pci_remove(struct pci_dev *pdev)
3529 put_device(dev); 3529 put_device(dev);
3530} 3530}
3531 3531
3532 3532#ifdef CONFIG_PM
3533static int ohci1394_pci_resume (struct pci_dev *pdev) 3533static int ohci1394_pci_resume (struct pci_dev *pdev)
3534{ 3534{
3535/* PowerMac resume code comes first */
3535#ifdef CONFIG_PPC_PMAC 3536#ifdef CONFIG_PPC_PMAC
3536 if (machine_is(powermac)) { 3537 if (machine_is(powermac)) {
3537 struct device_node *of_node; 3538 struct device_node *of_node;
@@ -3543,17 +3544,23 @@ static int ohci1394_pci_resume (struct pci_dev *pdev)
3543 } 3544 }
3544#endif /* CONFIG_PPC_PMAC */ 3545#endif /* CONFIG_PPC_PMAC */
3545 3546
3547 pci_set_power_state(pdev, PCI_D0);
3546 pci_restore_state(pdev); 3548 pci_restore_state(pdev);
3547 pci_enable_device(pdev); 3549 return pci_enable_device(pdev);
3548
3549 return 0;
3550} 3550}
3551 3551
3552
3553static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state) 3552static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state)
3554{ 3553{
3555 pci_save_state(pdev); 3554 int err;
3555
3556 err = pci_save_state(pdev);
3557 if (err)
3558 goto out;
3559 err = pci_set_power_state(pdev, pci_choose_state(pdev, state));
3560 if (err)
3561 goto out;
3556 3562
3563/* PowerMac suspend code comes last */
3557#ifdef CONFIG_PPC_PMAC 3564#ifdef CONFIG_PPC_PMAC
3558 if (machine_is(powermac)) { 3565 if (machine_is(powermac)) {
3559 struct device_node *of_node; 3566 struct device_node *of_node;
@@ -3563,11 +3570,11 @@ static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state)
3563 if (of_node) 3570 if (of_node)
3564 pmac_call_feature(PMAC_FTR_1394_ENABLE, of_node, 0, 0); 3571 pmac_call_feature(PMAC_FTR_1394_ENABLE, of_node, 0, 0);
3565 } 3572 }
3566#endif 3573#endif /* CONFIG_PPC_PMAC */
3567 3574out:
3568 return 0; 3575 return err;
3569} 3576}
3570 3577#endif /* CONFIG_PM */
3571 3578
3572#define PCI_CLASS_FIREWIRE_OHCI ((PCI_CLASS_SERIAL_FIREWIRE << 8) | 0x10) 3579#define PCI_CLASS_FIREWIRE_OHCI ((PCI_CLASS_SERIAL_FIREWIRE << 8) | 0x10)
3573 3580
@@ -3590,8 +3597,10 @@ static struct pci_driver ohci1394_pci_driver = {
3590 .id_table = ohci1394_pci_tbl, 3597 .id_table = ohci1394_pci_tbl,
3591 .probe = ohci1394_pci_probe, 3598 .probe = ohci1394_pci_probe,
3592 .remove = ohci1394_pci_remove, 3599 .remove = ohci1394_pci_remove,
3600#ifdef CONFIG_PM
3593 .resume = ohci1394_pci_resume, 3601 .resume = ohci1394_pci_resume,
3594 .suspend = ohci1394_pci_suspend, 3602 .suspend = ohci1394_pci_suspend,
3603#endif
3595}; 3604};
3596 3605
3597/*********************************** 3606/***********************************
@@ -3718,5 +3727,7 @@ static int __init ohci1394_init(void)
3718 return pci_register_driver(&ohci1394_pci_driver); 3727 return pci_register_driver(&ohci1394_pci_driver);
3719} 3728}
3720 3729
3721module_init(ohci1394_init); 3730/* Register before most other device drivers.
3731 * Useful for remote debugging via physical DMA, e.g. using firescope. */
3732fs_initcall(ohci1394_init);
3722module_exit(ohci1394_cleanup); 3733module_exit(ohci1394_cleanup);
diff --git a/drivers/ieee1394/pcilynx.c b/drivers/ieee1394/pcilynx.c
index e6f41238f5e8..b4f146f2c951 100644
--- a/drivers/ieee1394/pcilynx.c
+++ b/drivers/ieee1394/pcilynx.c
@@ -137,7 +137,6 @@ static struct i2c_algo_bit_data bit_data = {
137 .getsda = bit_getsda, 137 .getsda = bit_getsda,
138 .getscl = bit_getscl, 138 .getscl = bit_getscl,
139 .udelay = 5, 139 .udelay = 5,
140 .mdelay = 5,
141 .timeout = 100, 140 .timeout = 100,
142}; 141};
143 142
diff --git a/drivers/ieee1394/raw1394-private.h b/drivers/ieee1394/raw1394-private.h
index c93587be9cab..c7731d1bcd89 100644
--- a/drivers/ieee1394/raw1394-private.h
+++ b/drivers/ieee1394/raw1394-private.h
@@ -29,9 +29,8 @@ struct file_info {
29 29
30 struct list_head req_pending; 30 struct list_head req_pending;
31 struct list_head req_complete; 31 struct list_head req_complete;
32 struct semaphore complete_sem;
33 spinlock_t reqlists_lock; 32 spinlock_t reqlists_lock;
34 wait_queue_head_t poll_wait_complete; 33 wait_queue_head_t wait_complete;
35 34
36 struct list_head addr_list; 35 struct list_head addr_list;
37 36
diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c
index 571ea68c0cf2..5ec4f5eb6b19 100644
--- a/drivers/ieee1394/raw1394.c
+++ b/drivers/ieee1394/raw1394.c
@@ -44,14 +44,15 @@
44#include <linux/compat.h> 44#include <linux/compat.h>
45 45
46#include "csr1212.h" 46#include "csr1212.h"
47#include "highlevel.h"
48#include "hosts.h"
47#include "ieee1394.h" 49#include "ieee1394.h"
48#include "ieee1394_types.h"
49#include "ieee1394_core.h" 50#include "ieee1394_core.h"
50#include "nodemgr.h" 51#include "ieee1394_hotplug.h"
51#include "hosts.h"
52#include "highlevel.h"
53#include "iso.h"
54#include "ieee1394_transactions.h" 52#include "ieee1394_transactions.h"
53#include "ieee1394_types.h"
54#include "iso.h"
55#include "nodemgr.h"
55#include "raw1394.h" 56#include "raw1394.h"
56#include "raw1394-private.h" 57#include "raw1394-private.h"
57 58
@@ -66,7 +67,7 @@
66#define DBGMSG(fmt, args...) \ 67#define DBGMSG(fmt, args...) \
67printk(KERN_INFO "raw1394:" fmt "\n" , ## args) 68printk(KERN_INFO "raw1394:" fmt "\n" , ## args)
68#else 69#else
69#define DBGMSG(fmt, args...) 70#define DBGMSG(fmt, args...) do {} while (0)
70#endif 71#endif
71 72
72static LIST_HEAD(host_info_list); 73static LIST_HEAD(host_info_list);
@@ -132,10 +133,9 @@ static void free_pending_request(struct pending_request *req)
132static void __queue_complete_req(struct pending_request *req) 133static void __queue_complete_req(struct pending_request *req)
133{ 134{
134 struct file_info *fi = req->file_info; 135 struct file_info *fi = req->file_info;
135 list_move_tail(&req->list, &fi->req_complete);
136 136
137 up(&fi->complete_sem); 137 list_move_tail(&req->list, &fi->req_complete);
138 wake_up_interruptible(&fi->poll_wait_complete); 138 wake_up(&fi->wait_complete);
139} 139}
140 140
141static void queue_complete_req(struct pending_request *req) 141static void queue_complete_req(struct pending_request *req)
@@ -463,13 +463,36 @@ raw1394_compat_read(const char __user *buf, struct raw1394_request *r)
463 463
464#endif 464#endif
465 465
466/* get next completed request (caller must hold fi->reqlists_lock) */
467static inline struct pending_request *__next_complete_req(struct file_info *fi)
468{
469 struct list_head *lh;
470 struct pending_request *req = NULL;
471
472 if (!list_empty(&fi->req_complete)) {
473 lh = fi->req_complete.next;
474 list_del(lh);
475 req = list_entry(lh, struct pending_request, list);
476 }
477 return req;
478}
479
480/* atomically get next completed request */
481static struct pending_request *next_complete_req(struct file_info *fi)
482{
483 unsigned long flags;
484 struct pending_request *req;
485
486 spin_lock_irqsave(&fi->reqlists_lock, flags);
487 req = __next_complete_req(fi);
488 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
489 return req;
490}
466 491
467static ssize_t raw1394_read(struct file *file, char __user * buffer, 492static ssize_t raw1394_read(struct file *file, char __user * buffer,
468 size_t count, loff_t * offset_is_ignored) 493 size_t count, loff_t * offset_is_ignored)
469{ 494{
470 unsigned long flags;
471 struct file_info *fi = (struct file_info *)file->private_data; 495 struct file_info *fi = (struct file_info *)file->private_data;
472 struct list_head *lh;
473 struct pending_request *req; 496 struct pending_request *req;
474 ssize_t ret; 497 ssize_t ret;
475 498
@@ -487,22 +510,21 @@ static ssize_t raw1394_read(struct file *file, char __user * buffer,
487 } 510 }
488 511
489 if (file->f_flags & O_NONBLOCK) { 512 if (file->f_flags & O_NONBLOCK) {
490 if (down_trylock(&fi->complete_sem)) { 513 if (!(req = next_complete_req(fi)))
491 return -EAGAIN; 514 return -EAGAIN;
492 }
493 } else { 515 } else {
494 if (down_interruptible(&fi->complete_sem)) { 516 /*
517 * NB: We call the macro wait_event_interruptible() with a
518 * condition argument with side effect. This is only possible
519 * because the side effect does not occur until the condition
520 * became true, and wait_event_interruptible() won't evaluate
521 * the condition again after that.
522 */
523 if (wait_event_interruptible(fi->wait_complete,
524 (req = next_complete_req(fi))))
495 return -ERESTARTSYS; 525 return -ERESTARTSYS;
496 }
497 } 526 }
498 527
499 spin_lock_irqsave(&fi->reqlists_lock, flags);
500 lh = fi->req_complete.next;
501 list_del(lh);
502 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
503
504 req = list_entry(lh, struct pending_request, list);
505
506 if (req->req.length) { 528 if (req->req.length) {
507 if (copy_to_user(int2ptr(req->req.recvb), req->data, 529 if (copy_to_user(int2ptr(req->req.recvb), req->data,
508 req->req.length)) { 530 req->req.length)) {
@@ -1752,6 +1774,7 @@ static int arm_register(struct file_info *fi, struct pending_request *req)
1752 addr->notification_options |= addr->client_transactions; 1774 addr->notification_options |= addr->client_transactions;
1753 addr->recvb = req->req.recvb; 1775 addr->recvb = req->req.recvb;
1754 addr->rec_length = (u16) ((req->req.misc >> 16) & 0xFFFF); 1776 addr->rec_length = (u16) ((req->req.misc >> 16) & 0xFFFF);
1777
1755 spin_lock_irqsave(&host_info_lock, flags); 1778 spin_lock_irqsave(&host_info_lock, flags);
1756 hi = find_host_info(fi->host); 1779 hi = find_host_info(fi->host);
1757 same_host = 0; 1780 same_host = 0;
@@ -1777,9 +1800,9 @@ static int arm_register(struct file_info *fi, struct pending_request *req)
1777 } 1800 }
1778 if (same_host) { 1801 if (same_host) {
1779 /* addressrange occupied by same host */ 1802 /* addressrange occupied by same host */
1803 spin_unlock_irqrestore(&host_info_lock, flags);
1780 vfree(addr->addr_space_buffer); 1804 vfree(addr->addr_space_buffer);
1781 kfree(addr); 1805 kfree(addr);
1782 spin_unlock_irqrestore(&host_info_lock, flags);
1783 return (-EALREADY); 1806 return (-EALREADY);
1784 } 1807 }
1785 /* another host with valid address-entry containing same addressrange */ 1808 /* another host with valid address-entry containing same addressrange */
@@ -1807,6 +1830,8 @@ static int arm_register(struct file_info *fi, struct pending_request *req)
1807 } 1830 }
1808 } 1831 }
1809 } 1832 }
1833 spin_unlock_irqrestore(&host_info_lock, flags);
1834
1810 if (another_host) { 1835 if (another_host) {
1811 DBGMSG("another hosts entry is valid -> SUCCESS"); 1836 DBGMSG("another hosts entry is valid -> SUCCESS");
1812 if (copy_to_user(int2ptr(req->req.recvb), 1837 if (copy_to_user(int2ptr(req->req.recvb),
@@ -1815,11 +1840,11 @@ static int arm_register(struct file_info *fi, struct pending_request *req)
1815 " address-range-entry is invalid -> EFAULT !!!\n"); 1840 " address-range-entry is invalid -> EFAULT !!!\n");
1816 vfree(addr->addr_space_buffer); 1841 vfree(addr->addr_space_buffer);
1817 kfree(addr); 1842 kfree(addr);
1818 spin_unlock_irqrestore(&host_info_lock, flags);
1819 return (-EFAULT); 1843 return (-EFAULT);
1820 } 1844 }
1821 free_pending_request(req); /* immediate success or fail */ 1845 free_pending_request(req); /* immediate success or fail */
1822 /* INSERT ENTRY */ 1846 /* INSERT ENTRY */
1847 spin_lock_irqsave(&host_info_lock, flags);
1823 list_add_tail(&addr->addr_list, &fi->addr_list); 1848 list_add_tail(&addr->addr_list, &fi->addr_list);
1824 spin_unlock_irqrestore(&host_info_lock, flags); 1849 spin_unlock_irqrestore(&host_info_lock, flags);
1825 return sizeof(struct raw1394_request); 1850 return sizeof(struct raw1394_request);
@@ -1830,15 +1855,15 @@ static int arm_register(struct file_info *fi, struct pending_request *req)
1830 req->req.address + req->req.length); 1855 req->req.address + req->req.length);
1831 if (retval) { 1856 if (retval) {
1832 /* INSERT ENTRY */ 1857 /* INSERT ENTRY */
1858 spin_lock_irqsave(&host_info_lock, flags);
1833 list_add_tail(&addr->addr_list, &fi->addr_list); 1859 list_add_tail(&addr->addr_list, &fi->addr_list);
1860 spin_unlock_irqrestore(&host_info_lock, flags);
1834 } else { 1861 } else {
1835 DBGMSG("arm_register failed errno: %d \n", retval); 1862 DBGMSG("arm_register failed errno: %d \n", retval);
1836 vfree(addr->addr_space_buffer); 1863 vfree(addr->addr_space_buffer);
1837 kfree(addr); 1864 kfree(addr);
1838 spin_unlock_irqrestore(&host_info_lock, flags);
1839 return (-EALREADY); 1865 return (-EALREADY);
1840 } 1866 }
1841 spin_unlock_irqrestore(&host_info_lock, flags);
1842 free_pending_request(req); /* immediate success or fail */ 1867 free_pending_request(req); /* immediate success or fail */
1843 return sizeof(struct raw1394_request); 1868 return sizeof(struct raw1394_request);
1844} 1869}
@@ -1904,10 +1929,10 @@ static int arm_unregister(struct file_info *fi, struct pending_request *req)
1904 if (another_host) { 1929 if (another_host) {
1905 DBGMSG("delete entry from list -> success"); 1930 DBGMSG("delete entry from list -> success");
1906 list_del(&addr->addr_list); 1931 list_del(&addr->addr_list);
1932 spin_unlock_irqrestore(&host_info_lock, flags);
1907 vfree(addr->addr_space_buffer); 1933 vfree(addr->addr_space_buffer);
1908 kfree(addr); 1934 kfree(addr);
1909 free_pending_request(req); /* immediate success or fail */ 1935 free_pending_request(req); /* immediate success or fail */
1910 spin_unlock_irqrestore(&host_info_lock, flags);
1911 return sizeof(struct raw1394_request); 1936 return sizeof(struct raw1394_request);
1912 } 1937 }
1913 retval = 1938 retval =
@@ -1949,23 +1974,19 @@ static int arm_get_buf(struct file_info *fi, struct pending_request *req)
1949 (arm_addr->end > req->req.address)) { 1974 (arm_addr->end > req->req.address)) {
1950 if (req->req.address + req->req.length <= arm_addr->end) { 1975 if (req->req.address + req->req.length <= arm_addr->end) {
1951 offset = req->req.address - arm_addr->start; 1976 offset = req->req.address - arm_addr->start;
1977 spin_unlock_irqrestore(&host_info_lock, flags);
1952 1978
1953 DBGMSG 1979 DBGMSG
1954 ("arm_get_buf copy_to_user( %08X, %p, %u )", 1980 ("arm_get_buf copy_to_user( %08X, %p, %u )",
1955 (u32) req->req.recvb, 1981 (u32) req->req.recvb,
1956 arm_addr->addr_space_buffer + offset, 1982 arm_addr->addr_space_buffer + offset,
1957 (u32) req->req.length); 1983 (u32) req->req.length);
1958
1959 if (copy_to_user 1984 if (copy_to_user
1960 (int2ptr(req->req.recvb), 1985 (int2ptr(req->req.recvb),
1961 arm_addr->addr_space_buffer + offset, 1986 arm_addr->addr_space_buffer + offset,
1962 req->req.length)) { 1987 req->req.length))
1963 spin_unlock_irqrestore(&host_info_lock,
1964 flags);
1965 return (-EFAULT); 1988 return (-EFAULT);
1966 }
1967 1989
1968 spin_unlock_irqrestore(&host_info_lock, flags);
1969 /* We have to free the request, because we 1990 /* We have to free the request, because we
1970 * queue no response, and therefore nobody 1991 * queue no response, and therefore nobody
1971 * will free it. */ 1992 * will free it. */
@@ -2005,24 +2026,23 @@ static int arm_set_buf(struct file_info *fi, struct pending_request *req)
2005 (arm_addr->end > req->req.address)) { 2026 (arm_addr->end > req->req.address)) {
2006 if (req->req.address + req->req.length <= arm_addr->end) { 2027 if (req->req.address + req->req.length <= arm_addr->end) {
2007 offset = req->req.address - arm_addr->start; 2028 offset = req->req.address - arm_addr->start;
2029 spin_unlock_irqrestore(&host_info_lock, flags);
2008 2030
2009 DBGMSG 2031 DBGMSG
2010 ("arm_set_buf copy_from_user( %p, %08X, %u )", 2032 ("arm_set_buf copy_from_user( %p, %08X, %u )",
2011 arm_addr->addr_space_buffer + offset, 2033 arm_addr->addr_space_buffer + offset,
2012 (u32) req->req.sendb, 2034 (u32) req->req.sendb,
2013 (u32) req->req.length); 2035 (u32) req->req.length);
2014
2015 if (copy_from_user 2036 if (copy_from_user
2016 (arm_addr->addr_space_buffer + offset, 2037 (arm_addr->addr_space_buffer + offset,
2017 int2ptr(req->req.sendb), 2038 int2ptr(req->req.sendb),
2018 req->req.length)) { 2039 req->req.length))
2019 spin_unlock_irqrestore(&host_info_lock,
2020 flags);
2021 return (-EFAULT); 2040 return (-EFAULT);
2022 }
2023 2041
2024 spin_unlock_irqrestore(&host_info_lock, flags); 2042 /* We have to free the request, because we
2025 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */ 2043 * queue no response, and therefore nobody
2044 * will free it. */
2045 free_pending_request(req);
2026 return sizeof(struct raw1394_request); 2046 return sizeof(struct raw1394_request);
2027 } else { 2047 } else {
2028 DBGMSG("arm_set_buf request exceeded mapping"); 2048 DBGMSG("arm_set_buf request exceeded mapping");
@@ -2744,7 +2764,7 @@ static unsigned int raw1394_poll(struct file *file, poll_table * pt)
2744 unsigned int mask = POLLOUT | POLLWRNORM; 2764 unsigned int mask = POLLOUT | POLLWRNORM;
2745 unsigned long flags; 2765 unsigned long flags;
2746 2766
2747 poll_wait(file, &fi->poll_wait_complete, pt); 2767 poll_wait(file, &fi->wait_complete, pt);
2748 2768
2749 spin_lock_irqsave(&fi->reqlists_lock, flags); 2769 spin_lock_irqsave(&fi->reqlists_lock, flags);
2750 if (!list_empty(&fi->req_complete)) { 2770 if (!list_empty(&fi->req_complete)) {
@@ -2769,9 +2789,8 @@ static int raw1394_open(struct inode *inode, struct file *file)
2769 fi->state = opened; 2789 fi->state = opened;
2770 INIT_LIST_HEAD(&fi->req_pending); 2790 INIT_LIST_HEAD(&fi->req_pending);
2771 INIT_LIST_HEAD(&fi->req_complete); 2791 INIT_LIST_HEAD(&fi->req_complete);
2772 sema_init(&fi->complete_sem, 0);
2773 spin_lock_init(&fi->reqlists_lock); 2792 spin_lock_init(&fi->reqlists_lock);
2774 init_waitqueue_head(&fi->poll_wait_complete); 2793 init_waitqueue_head(&fi->wait_complete);
2775 INIT_LIST_HEAD(&fi->addr_list); 2794 INIT_LIST_HEAD(&fi->addr_list);
2776 2795
2777 file->private_data = fi; 2796 file->private_data = fi;
@@ -2784,7 +2803,7 @@ static int raw1394_release(struct inode *inode, struct file *file)
2784 struct file_info *fi = file->private_data; 2803 struct file_info *fi = file->private_data;
2785 struct list_head *lh; 2804 struct list_head *lh;
2786 struct pending_request *req; 2805 struct pending_request *req;
2787 int done = 0, i, fail = 0; 2806 int i, fail;
2788 int retval = 0; 2807 int retval = 0;
2789 struct list_head *entry; 2808 struct list_head *entry;
2790 struct arm_addr *addr = NULL; 2809 struct arm_addr *addr = NULL;
@@ -2864,25 +2883,28 @@ static int raw1394_release(struct inode *inode, struct file *file)
2864 "error(s) occurred \n"); 2883 "error(s) occurred \n");
2865 } 2884 }
2866 2885
2867 while (!done) { 2886 for (;;) {
2887 /* This locked section guarantees that neither
2888 * complete nor pending requests exist once i!=0 */
2868 spin_lock_irqsave(&fi->reqlists_lock, flags); 2889 spin_lock_irqsave(&fi->reqlists_lock, flags);
2869 2890 while ((req = __next_complete_req(fi)))
2870 while (!list_empty(&fi->req_complete)) {
2871 lh = fi->req_complete.next;
2872 list_del(lh);
2873
2874 req = list_entry(lh, struct pending_request, list);
2875
2876 free_pending_request(req); 2891 free_pending_request(req);
2877 }
2878
2879 if (list_empty(&fi->req_pending))
2880 done = 1;
2881 2892
2893 i = list_empty(&fi->req_pending);
2882 spin_unlock_irqrestore(&fi->reqlists_lock, flags); 2894 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2883 2895
2884 if (!done) 2896 if (i)
2885 down_interruptible(&fi->complete_sem); 2897 break;
2898 /*
2899 * Sleep until more requests can be freed.
2900 *
2901 * NB: We call the macro wait_event() with a condition argument
2902 * with side effect. This is only possible because the side
2903 * effect does not occur until the condition became true, and
2904 * wait_event() won't evaluate the condition again after that.
2905 */
2906 wait_event(fi->wait_complete, (req = next_complete_req(fi)));
2907 free_pending_request(req);
2886 } 2908 }
2887 2909
2888 /* Remove any sub-trees left by user space programs */ 2910 /* Remove any sub-trees left by user space programs */
diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
index b08755e2e68f..6986ac188281 100644
--- a/drivers/ieee1394/sbp2.c
+++ b/drivers/ieee1394/sbp2.c
@@ -38,31 +38,36 @@
38 * but the code needs additional debugging. 38 * but the code needs additional debugging.
39 */ 39 */
40 40
41#include <linux/blkdev.h>
42#include <linux/compiler.h>
43#include <linux/delay.h>
44#include <linux/device.h>
45#include <linux/dma-mapping.h>
46#include <linux/gfp.h>
47#include <linux/init.h>
41#include <linux/kernel.h> 48#include <linux/kernel.h>
42#include <linux/list.h> 49#include <linux/list.h>
43#include <linux/string.h>
44#include <linux/stringify.h>
45#include <linux/slab.h>
46#include <linux/interrupt.h>
47#include <linux/fs.h>
48#include <linux/poll.h>
49#include <linux/module.h> 50#include <linux/module.h>
50#include <linux/moduleparam.h> 51#include <linux/moduleparam.h>
51#include <linux/types.h>
52#include <linux/delay.h>
53#include <linux/sched.h>
54#include <linux/blkdev.h>
55#include <linux/smp_lock.h>
56#include <linux/init.h>
57#include <linux/pci.h> 52#include <linux/pci.h>
53#include <linux/slab.h>
54#include <linux/spinlock.h>
55#include <linux/stat.h>
56#include <linux/string.h>
57#include <linux/stringify.h>
58#include <linux/types.h>
59#include <linux/wait.h>
58 60
59#include <asm/current.h>
60#include <asm/uaccess.h>
61#include <asm/io.h>
62#include <asm/byteorder.h> 61#include <asm/byteorder.h>
63#include <asm/atomic.h> 62#include <asm/errno.h>
64#include <asm/system.h> 63#include <asm/param.h>
65#include <asm/scatterlist.h> 64#include <asm/scatterlist.h>
65#include <asm/system.h>
66#include <asm/types.h>
67
68#ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
69#include <asm/io.h> /* for bus_to_virt */
70#endif
66 71
67#include <scsi/scsi.h> 72#include <scsi/scsi.h>
68#include <scsi/scsi_cmnd.h> 73#include <scsi/scsi_cmnd.h>
@@ -71,13 +76,14 @@
71#include <scsi/scsi_host.h> 76#include <scsi/scsi_host.h>
72 77
73#include "csr1212.h" 78#include "csr1212.h"
79#include "highlevel.h"
80#include "hosts.h"
74#include "ieee1394.h" 81#include "ieee1394.h"
75#include "ieee1394_types.h"
76#include "ieee1394_core.h" 82#include "ieee1394_core.h"
77#include "nodemgr.h" 83#include "ieee1394_hotplug.h"
78#include "hosts.h"
79#include "highlevel.h"
80#include "ieee1394_transactions.h" 84#include "ieee1394_transactions.h"
85#include "ieee1394_types.h"
86#include "nodemgr.h"
81#include "sbp2.h" 87#include "sbp2.h"
82 88
83/* 89/*
@@ -173,11 +179,6 @@ MODULE_PARM_DESC(workarounds, "Work around device bugs (default = 0"
173 ", override internal blacklist = " __stringify(SBP2_WORKAROUND_OVERRIDE) 179 ", override internal blacklist = " __stringify(SBP2_WORKAROUND_OVERRIDE)
174 ", or a combination)"); 180 ", or a combination)");
175 181
176/* legacy parameter */
177static int force_inquiry_hack;
178module_param(force_inquiry_hack, int, 0644);
179MODULE_PARM_DESC(force_inquiry_hack, "Deprecated, use 'workarounds'");
180
181/* 182/*
182 * Export information about protocols/devices supported by this driver. 183 * Export information about protocols/devices supported by this driver.
183 */ 184 */
@@ -208,9 +209,9 @@ static u32 global_outstanding_command_orbs = 0;
208#define outstanding_orb_incr global_outstanding_command_orbs++ 209#define outstanding_orb_incr global_outstanding_command_orbs++
209#define outstanding_orb_decr global_outstanding_command_orbs-- 210#define outstanding_orb_decr global_outstanding_command_orbs--
210#else 211#else
211#define SBP2_ORB_DEBUG(fmt, args...) 212#define SBP2_ORB_DEBUG(fmt, args...) do {} while (0)
212#define outstanding_orb_incr 213#define outstanding_orb_incr do {} while (0)
213#define outstanding_orb_decr 214#define outstanding_orb_decr do {} while (0)
214#endif 215#endif
215 216
216#ifdef CONFIG_IEEE1394_SBP2_DEBUG_DMA 217#ifdef CONFIG_IEEE1394_SBP2_DEBUG_DMA
@@ -222,8 +223,8 @@ static u32 global_outstanding_command_orbs = 0;
222 --global_outstanding_dmas, ## args) 223 --global_outstanding_dmas, ## args)
223static u32 global_outstanding_dmas = 0; 224static u32 global_outstanding_dmas = 0;
224#else 225#else
225#define SBP2_DMA_ALLOC(fmt, args...) 226#define SBP2_DMA_ALLOC(fmt, args...) do {} while (0)
226#define SBP2_DMA_FREE(fmt, args...) 227#define SBP2_DMA_FREE(fmt, args...) do {} while (0)
227#endif 228#endif
228 229
229#if CONFIG_IEEE1394_SBP2_DEBUG >= 2 230#if CONFIG_IEEE1394_SBP2_DEBUG >= 2
@@ -237,7 +238,7 @@ static u32 global_outstanding_dmas = 0;
237#define SBP2_NOTICE(fmt, args...) HPSB_NOTICE("sbp2: "fmt, ## args) 238#define SBP2_NOTICE(fmt, args...) HPSB_NOTICE("sbp2: "fmt, ## args)
238#define SBP2_WARN(fmt, args...) HPSB_WARN("sbp2: "fmt, ## args) 239#define SBP2_WARN(fmt, args...) HPSB_WARN("sbp2: "fmt, ## args)
239#else 240#else
240#define SBP2_DEBUG(fmt, args...) 241#define SBP2_DEBUG(fmt, args...) do {} while (0)
241#define SBP2_INFO(fmt, args...) HPSB_INFO("sbp2: "fmt, ## args) 242#define SBP2_INFO(fmt, args...) HPSB_INFO("sbp2: "fmt, ## args)
242#define SBP2_NOTICE(fmt, args...) HPSB_NOTICE("sbp2: "fmt, ## args) 243#define SBP2_NOTICE(fmt, args...) HPSB_NOTICE("sbp2: "fmt, ## args)
243#define SBP2_WARN(fmt, args...) HPSB_WARN("sbp2: "fmt, ## args) 244#define SBP2_WARN(fmt, args...) HPSB_WARN("sbp2: "fmt, ## args)
@@ -356,7 +357,7 @@ static const struct {
356/* 357/*
357 * Converts a buffer from be32 to cpu byte ordering. Length is in bytes. 358 * Converts a buffer from be32 to cpu byte ordering. Length is in bytes.
358 */ 359 */
359static __inline__ void sbp2util_be32_to_cpu_buffer(void *buffer, int length) 360static inline void sbp2util_be32_to_cpu_buffer(void *buffer, int length)
360{ 361{
361 u32 *temp = buffer; 362 u32 *temp = buffer;
362 363
@@ -369,7 +370,7 @@ static __inline__ void sbp2util_be32_to_cpu_buffer(void *buffer, int length)
369/* 370/*
370 * Converts a buffer from cpu to be32 byte ordering. Length is in bytes. 371 * Converts a buffer from cpu to be32 byte ordering. Length is in bytes.
371 */ 372 */
372static __inline__ void sbp2util_cpu_to_be32_buffer(void *buffer, int length) 373static inline void sbp2util_cpu_to_be32_buffer(void *buffer, int length)
373{ 374{
374 u32 *temp = buffer; 375 u32 *temp = buffer;
375 376
@@ -380,8 +381,8 @@ static __inline__ void sbp2util_cpu_to_be32_buffer(void *buffer, int length)
380} 381}
381#else /* BIG_ENDIAN */ 382#else /* BIG_ENDIAN */
382/* Why waste the cpu cycles? */ 383/* Why waste the cpu cycles? */
383#define sbp2util_be32_to_cpu_buffer(x,y) 384#define sbp2util_be32_to_cpu_buffer(x,y) do {} while (0)
384#define sbp2util_cpu_to_be32_buffer(x,y) 385#define sbp2util_cpu_to_be32_buffer(x,y) do {} while (0)
385#endif 386#endif
386 387
387#ifdef CONFIG_IEEE1394_SBP2_PACKET_DUMP 388#ifdef CONFIG_IEEE1394_SBP2_PACKET_DUMP
@@ -417,24 +418,26 @@ static void sbp2util_packet_dump(void *buffer, int length, char *dump_name,
417 return; 418 return;
418} 419}
419#else 420#else
420#define sbp2util_packet_dump(w,x,y,z) 421#define sbp2util_packet_dump(w,x,y,z) do {} while (0)
421#endif 422#endif
422 423
424static DECLARE_WAIT_QUEUE_HEAD(access_wq);
425
423/* 426/*
424 * Goofy routine that basically does a down_timeout function. 427 * Waits for completion of an SBP-2 access request.
428 * Returns nonzero if timed out or prematurely interrupted.
425 */ 429 */
426static int sbp2util_down_timeout(atomic_t *done, int timeout) 430static int sbp2util_access_timeout(struct scsi_id_instance_data *scsi_id,
431 int timeout)
427{ 432{
428 int i; 433 long leftover = wait_event_interruptible_timeout(
434 access_wq, scsi_id->access_complete, timeout);
429 435
430 for (i = timeout; (i > 0 && atomic_read(done) == 0); i-= HZ/10) { 436 scsi_id->access_complete = 0;
431 if (msleep_interruptible(100)) /* 100ms */ 437 return leftover <= 0;
432 return 1;
433 }
434 return (i > 0) ? 0 : 1;
435} 438}
436 439
437/* Free's an allocated packet */ 440/* Frees an allocated packet */
438static void sbp2_free_packet(struct hpsb_packet *packet) 441static void sbp2_free_packet(struct hpsb_packet *packet)
439{ 442{
440 hpsb_free_tlabel(packet); 443 hpsb_free_tlabel(packet);
@@ -468,6 +471,44 @@ static int sbp2util_node_write_no_wait(struct node_entry *ne, u64 addr,
468 return 0; 471 return 0;
469} 472}
470 473
474static void sbp2util_notify_fetch_agent(struct scsi_id_instance_data *scsi_id,
475 u64 offset, quadlet_t *data, size_t len)
476{
477 /*
478 * There is a small window after a bus reset within which the node
479 * entry's generation is current but the reconnect wasn't completed.
480 */
481 if (unlikely(atomic_read(&scsi_id->state) == SBP2LU_STATE_IN_RESET))
482 return;
483
484 if (hpsb_node_write(scsi_id->ne,
485 scsi_id->sbp2_command_block_agent_addr + offset,
486 data, len))
487 SBP2_ERR("sbp2util_notify_fetch_agent failed.");
488 /*
489 * Now accept new SCSI commands, unless a bus reset happended during
490 * hpsb_node_write.
491 */
492 if (likely(atomic_read(&scsi_id->state) != SBP2LU_STATE_IN_RESET))
493 scsi_unblock_requests(scsi_id->scsi_host);
494}
495
496static void sbp2util_write_orb_pointer(void *p)
497{
498 quadlet_t data[2];
499
500 data[0] = ORB_SET_NODE_ID(
501 ((struct scsi_id_instance_data *)p)->hi->host->node_id);
502 data[1] = ((struct scsi_id_instance_data *)p)->last_orb_dma;
503 sbp2util_cpu_to_be32_buffer(data, 8);
504 sbp2util_notify_fetch_agent(p, SBP2_ORB_POINTER_OFFSET, data, 8);
505}
506
507static void sbp2util_write_doorbell(void *p)
508{
509 sbp2util_notify_fetch_agent(p, SBP2_DOORBELL_OFFSET, NULL, 4);
510}
511
471/* 512/*
472 * This function is called to create a pool of command orbs used for 513 * This function is called to create a pool of command orbs used for
473 * command processing. It is called when a new sbp2 device is detected. 514 * command processing. It is called when a new sbp2 device is detected.
@@ -492,7 +533,7 @@ static int sbp2util_create_command_orb_pool(struct scsi_id_instance_data *scsi_i
492 command->command_orb_dma = 533 command->command_orb_dma =
493 pci_map_single(hi->host->pdev, &command->command_orb, 534 pci_map_single(hi->host->pdev, &command->command_orb,
494 sizeof(struct sbp2_command_orb), 535 sizeof(struct sbp2_command_orb),
495 PCI_DMA_BIDIRECTIONAL); 536 PCI_DMA_TODEVICE);
496 SBP2_DMA_ALLOC("single command orb DMA"); 537 SBP2_DMA_ALLOC("single command orb DMA");
497 command->sge_dma = 538 command->sge_dma =
498 pci_map_single(hi->host->pdev, 539 pci_map_single(hi->host->pdev,
@@ -525,7 +566,7 @@ static void sbp2util_remove_command_orb_pool(struct scsi_id_instance_data *scsi_
525 /* Release our generic DMA's */ 566 /* Release our generic DMA's */
526 pci_unmap_single(host->pdev, command->command_orb_dma, 567 pci_unmap_single(host->pdev, command->command_orb_dma,
527 sizeof(struct sbp2_command_orb), 568 sizeof(struct sbp2_command_orb),
528 PCI_DMA_BIDIRECTIONAL); 569 PCI_DMA_TODEVICE);
529 SBP2_DMA_FREE("single command orb DMA"); 570 SBP2_DMA_FREE("single command orb DMA");
530 pci_unmap_single(host->pdev, command->sge_dma, 571 pci_unmap_single(host->pdev, command->sge_dma,
531 sizeof(command->scatter_gather_element), 572 sizeof(command->scatter_gather_element),
@@ -715,6 +756,7 @@ static int sbp2_remove(struct device *dev)
715 sbp2scsi_complete_all_commands(scsi_id, DID_NO_CONNECT); 756 sbp2scsi_complete_all_commands(scsi_id, DID_NO_CONNECT);
716 /* scsi_remove_device() will trigger shutdown functions of SCSI 757 /* scsi_remove_device() will trigger shutdown functions of SCSI
717 * highlevel drivers which would deadlock if blocked. */ 758 * highlevel drivers which would deadlock if blocked. */
759 atomic_set(&scsi_id->state, SBP2LU_STATE_IN_SHUTDOWN);
718 scsi_unblock_requests(scsi_id->scsi_host); 760 scsi_unblock_requests(scsi_id->scsi_host);
719 } 761 }
720 sdev = scsi_id->sdev; 762 sdev = scsi_id->sdev;
@@ -766,10 +808,12 @@ static int sbp2_update(struct unit_directory *ud)
766 */ 808 */
767 sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY); 809 sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY);
768 810
769 /* Make sure we unblock requests (since this is likely after a bus 811 /* Accept new commands unless there was another bus reset in the
770 * reset). */ 812 * meantime. */
771 scsi_unblock_requests(scsi_id->scsi_host); 813 if (hpsb_node_entry_valid(scsi_id->ne)) {
772 814 atomic_set(&scsi_id->state, SBP2LU_STATE_RUNNING);
815 scsi_unblock_requests(scsi_id->scsi_host);
816 }
773 return 0; 817 return 0;
774} 818}
775 819
@@ -794,11 +838,12 @@ static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud
794 scsi_id->speed_code = IEEE1394_SPEED_100; 838 scsi_id->speed_code = IEEE1394_SPEED_100;
795 scsi_id->max_payload_size = sbp2_speedto_max_payload[IEEE1394_SPEED_100]; 839 scsi_id->max_payload_size = sbp2_speedto_max_payload[IEEE1394_SPEED_100];
796 scsi_id->status_fifo_addr = CSR1212_INVALID_ADDR_SPACE; 840 scsi_id->status_fifo_addr = CSR1212_INVALID_ADDR_SPACE;
797 atomic_set(&scsi_id->sbp2_login_complete, 0);
798 INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_inuse); 841 INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_inuse);
799 INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_completed); 842 INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_completed);
800 INIT_LIST_HEAD(&scsi_id->scsi_list); 843 INIT_LIST_HEAD(&scsi_id->scsi_list);
801 spin_lock_init(&scsi_id->sbp2_command_orb_lock); 844 spin_lock_init(&scsi_id->sbp2_command_orb_lock);
845 atomic_set(&scsi_id->state, SBP2LU_STATE_RUNNING);
846 INIT_WORK(&scsi_id->protocol_work, NULL, NULL);
802 847
803 ud->device.driver_data = scsi_id; 848 ud->device.driver_data = scsi_id;
804 849
@@ -881,11 +926,14 @@ static void sbp2_host_reset(struct hpsb_host *host)
881 struct scsi_id_instance_data *scsi_id; 926 struct scsi_id_instance_data *scsi_id;
882 927
883 hi = hpsb_get_hostinfo(&sbp2_highlevel, host); 928 hi = hpsb_get_hostinfo(&sbp2_highlevel, host);
884 929 if (!hi)
885 if (hi) { 930 return;
886 list_for_each_entry(scsi_id, &hi->scsi_ids, scsi_list) 931 list_for_each_entry(scsi_id, &hi->scsi_ids, scsi_list)
932 if (likely(atomic_read(&scsi_id->state) !=
933 SBP2LU_STATE_IN_SHUTDOWN)) {
934 atomic_set(&scsi_id->state, SBP2LU_STATE_IN_RESET);
887 scsi_block_requests(scsi_id->scsi_host); 935 scsi_block_requests(scsi_id->scsi_host);
888 } 936 }
889} 937}
890 938
891/* 939/*
@@ -970,8 +1018,7 @@ static int sbp2_start_device(struct scsi_id_instance_data *scsi_id)
970 * connected to the sbp2 device being removed. That host would 1018 * connected to the sbp2 device being removed. That host would
971 * have a certain amount of time to relogin before the sbp2 device 1019 * have a certain amount of time to relogin before the sbp2 device
972 * allows someone else to login instead. One second makes sense. */ 1020 * allows someone else to login instead. One second makes sense. */
973 msleep_interruptible(1000); 1021 if (msleep_interruptible(1000)) {
974 if (signal_pending(current)) {
975 sbp2_remove_device(scsi_id); 1022 sbp2_remove_device(scsi_id);
976 return -EINTR; 1023 return -EINTR;
977 } 1024 }
@@ -1036,7 +1083,7 @@ static void sbp2_remove_device(struct scsi_id_instance_data *scsi_id)
1036 scsi_remove_host(scsi_id->scsi_host); 1083 scsi_remove_host(scsi_id->scsi_host);
1037 scsi_host_put(scsi_id->scsi_host); 1084 scsi_host_put(scsi_id->scsi_host);
1038 } 1085 }
1039 1086 flush_scheduled_work();
1040 sbp2util_remove_command_orb_pool(scsi_id); 1087 sbp2util_remove_command_orb_pool(scsi_id);
1041 1088
1042 list_del(&scsi_id->scsi_list); 1089 list_del(&scsi_id->scsi_list);
@@ -1182,17 +1229,14 @@ static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id)
1182 "sbp2 query logins orb", scsi_id->query_logins_orb_dma); 1229 "sbp2 query logins orb", scsi_id->query_logins_orb_dma);
1183 1230
1184 memset(scsi_id->query_logins_response, 0, sizeof(struct sbp2_query_logins_response)); 1231 memset(scsi_id->query_logins_response, 0, sizeof(struct sbp2_query_logins_response));
1185 memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block));
1186 1232
1187 data[0] = ORB_SET_NODE_ID(hi->host->node_id); 1233 data[0] = ORB_SET_NODE_ID(hi->host->node_id);
1188 data[1] = scsi_id->query_logins_orb_dma; 1234 data[1] = scsi_id->query_logins_orb_dma;
1189 sbp2util_cpu_to_be32_buffer(data, 8); 1235 sbp2util_cpu_to_be32_buffer(data, 8);
1190 1236
1191 atomic_set(&scsi_id->sbp2_login_complete, 0);
1192
1193 hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8); 1237 hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8);
1194 1238
1195 if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, 2*HZ)) { 1239 if (sbp2util_access_timeout(scsi_id, 2*HZ)) {
1196 SBP2_INFO("Error querying logins to SBP-2 device - timed out"); 1240 SBP2_INFO("Error querying logins to SBP-2 device - timed out");
1197 return -EIO; 1241 return -EIO;
1198 } 1242 }
@@ -1202,11 +1246,8 @@ static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id)
1202 return -EIO; 1246 return -EIO;
1203 } 1247 }
1204 1248
1205 if (STATUS_GET_RESP(scsi_id->status_block.ORB_offset_hi_misc) || 1249 if (STATUS_TEST_RDS(scsi_id->status_block.ORB_offset_hi_misc)) {
1206 STATUS_GET_DEAD_BIT(scsi_id->status_block.ORB_offset_hi_misc) || 1250 SBP2_INFO("Error querying logins to SBP-2 device - failed");
1207 STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) {
1208
1209 SBP2_INFO("Error querying logins to SBP-2 device - timed out");
1210 return -EIO; 1251 return -EIO;
1211 } 1252 }
1212 1253
@@ -1278,21 +1319,18 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id)
1278 "sbp2 login orb", scsi_id->login_orb_dma); 1319 "sbp2 login orb", scsi_id->login_orb_dma);
1279 1320
1280 memset(scsi_id->login_response, 0, sizeof(struct sbp2_login_response)); 1321 memset(scsi_id->login_response, 0, sizeof(struct sbp2_login_response));
1281 memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block));
1282 1322
1283 data[0] = ORB_SET_NODE_ID(hi->host->node_id); 1323 data[0] = ORB_SET_NODE_ID(hi->host->node_id);
1284 data[1] = scsi_id->login_orb_dma; 1324 data[1] = scsi_id->login_orb_dma;
1285 sbp2util_cpu_to_be32_buffer(data, 8); 1325 sbp2util_cpu_to_be32_buffer(data, 8);
1286 1326
1287 atomic_set(&scsi_id->sbp2_login_complete, 0);
1288
1289 hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8); 1327 hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8);
1290 1328
1291 /* 1329 /*
1292 * Wait for login status (up to 20 seconds)... 1330 * Wait for login status (up to 20 seconds)...
1293 */ 1331 */
1294 if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, 20*HZ)) { 1332 if (sbp2util_access_timeout(scsi_id, 20*HZ)) {
1295 SBP2_ERR("Error logging into SBP-2 device - login timed-out"); 1333 SBP2_ERR("Error logging into SBP-2 device - timed out");
1296 return -EIO; 1334 return -EIO;
1297 } 1335 }
1298 1336
@@ -1300,18 +1338,12 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id)
1300 * Sanity. Make sure status returned matches login orb. 1338 * Sanity. Make sure status returned matches login orb.
1301 */ 1339 */
1302 if (scsi_id->status_block.ORB_offset_lo != scsi_id->login_orb_dma) { 1340 if (scsi_id->status_block.ORB_offset_lo != scsi_id->login_orb_dma) {
1303 SBP2_ERR("Error logging into SBP-2 device - login timed-out"); 1341 SBP2_ERR("Error logging into SBP-2 device - timed out");
1304 return -EIO; 1342 return -EIO;
1305 } 1343 }
1306 1344
1307 /* 1345 if (STATUS_TEST_RDS(scsi_id->status_block.ORB_offset_hi_misc)) {
1308 * Check status 1346 SBP2_ERR("Error logging into SBP-2 device - failed");
1309 */
1310 if (STATUS_GET_RESP(scsi_id->status_block.ORB_offset_hi_misc) ||
1311 STATUS_GET_DEAD_BIT(scsi_id->status_block.ORB_offset_hi_misc) ||
1312 STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) {
1313
1314 SBP2_ERR("Error logging into SBP-2 device - login failed");
1315 return -EIO; 1347 return -EIO;
1316 } 1348 }
1317 1349
@@ -1335,9 +1367,7 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id)
1335 scsi_id->sbp2_command_block_agent_addr &= 0x0000ffffffffffffULL; 1367 scsi_id->sbp2_command_block_agent_addr &= 0x0000ffffffffffffULL;
1336 1368
1337 SBP2_INFO("Logged into SBP-2 device"); 1369 SBP2_INFO("Logged into SBP-2 device");
1338
1339 return 0; 1370 return 0;
1340
1341} 1371}
1342 1372
1343/* 1373/*
@@ -1387,21 +1417,17 @@ static int sbp2_logout_device(struct scsi_id_instance_data *scsi_id)
1387 data[1] = scsi_id->logout_orb_dma; 1417 data[1] = scsi_id->logout_orb_dma;
1388 sbp2util_cpu_to_be32_buffer(data, 8); 1418 sbp2util_cpu_to_be32_buffer(data, 8);
1389 1419
1390 atomic_set(&scsi_id->sbp2_login_complete, 0);
1391
1392 error = hpsb_node_write(scsi_id->ne, 1420 error = hpsb_node_write(scsi_id->ne,
1393 scsi_id->sbp2_management_agent_addr, data, 8); 1421 scsi_id->sbp2_management_agent_addr, data, 8);
1394 if (error) 1422 if (error)
1395 return error; 1423 return error;
1396 1424
1397 /* Wait for device to logout...1 second. */ 1425 /* Wait for device to logout...1 second. */
1398 if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, HZ)) 1426 if (sbp2util_access_timeout(scsi_id, HZ))
1399 return -EIO; 1427 return -EIO;
1400 1428
1401 SBP2_INFO("Logged out of SBP-2 device"); 1429 SBP2_INFO("Logged out of SBP-2 device");
1402
1403 return 0; 1430 return 0;
1404
1405} 1431}
1406 1432
1407/* 1433/*
@@ -1445,20 +1471,10 @@ static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id)
1445 sbp2util_packet_dump(scsi_id->reconnect_orb, sizeof(struct sbp2_reconnect_orb), 1471 sbp2util_packet_dump(scsi_id->reconnect_orb, sizeof(struct sbp2_reconnect_orb),
1446 "sbp2 reconnect orb", scsi_id->reconnect_orb_dma); 1472 "sbp2 reconnect orb", scsi_id->reconnect_orb_dma);
1447 1473
1448 /*
1449 * Initialize status fifo
1450 */
1451 memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block));
1452
1453 /*
1454 * Ok, let's write to the target's management agent register
1455 */
1456 data[0] = ORB_SET_NODE_ID(hi->host->node_id); 1474 data[0] = ORB_SET_NODE_ID(hi->host->node_id);
1457 data[1] = scsi_id->reconnect_orb_dma; 1475 data[1] = scsi_id->reconnect_orb_dma;
1458 sbp2util_cpu_to_be32_buffer(data, 8); 1476 sbp2util_cpu_to_be32_buffer(data, 8);
1459 1477
1460 atomic_set(&scsi_id->sbp2_login_complete, 0);
1461
1462 error = hpsb_node_write(scsi_id->ne, 1478 error = hpsb_node_write(scsi_id->ne,
1463 scsi_id->sbp2_management_agent_addr, data, 8); 1479 scsi_id->sbp2_management_agent_addr, data, 8);
1464 if (error) 1480 if (error)
@@ -1467,8 +1483,8 @@ static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id)
1467 /* 1483 /*
1468 * Wait for reconnect status (up to 1 second)... 1484 * Wait for reconnect status (up to 1 second)...
1469 */ 1485 */
1470 if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, HZ)) { 1486 if (sbp2util_access_timeout(scsi_id, HZ)) {
1471 SBP2_ERR("Error reconnecting to SBP-2 device - reconnect timed-out"); 1487 SBP2_ERR("Error reconnecting to SBP-2 device - timed out");
1472 return -EIO; 1488 return -EIO;
1473 } 1489 }
1474 1490
@@ -1476,25 +1492,17 @@ static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id)
1476 * Sanity. Make sure status returned matches reconnect orb. 1492 * Sanity. Make sure status returned matches reconnect orb.
1477 */ 1493 */
1478 if (scsi_id->status_block.ORB_offset_lo != scsi_id->reconnect_orb_dma) { 1494 if (scsi_id->status_block.ORB_offset_lo != scsi_id->reconnect_orb_dma) {
1479 SBP2_ERR("Error reconnecting to SBP-2 device - reconnect timed-out"); 1495 SBP2_ERR("Error reconnecting to SBP-2 device - timed out");
1480 return -EIO; 1496 return -EIO;
1481 } 1497 }
1482 1498
1483 /* 1499 if (STATUS_TEST_RDS(scsi_id->status_block.ORB_offset_hi_misc)) {
1484 * Check status 1500 SBP2_ERR("Error reconnecting to SBP-2 device - failed");
1485 */
1486 if (STATUS_GET_RESP(scsi_id->status_block.ORB_offset_hi_misc) ||
1487 STATUS_GET_DEAD_BIT(scsi_id->status_block.ORB_offset_hi_misc) ||
1488 STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) {
1489
1490 SBP2_ERR("Error reconnecting to SBP-2 device - reconnect failed");
1491 return -EIO; 1501 return -EIO;
1492 } 1502 }
1493 1503
1494 HPSB_DEBUG("Reconnected to SBP-2 device"); 1504 HPSB_DEBUG("Reconnected to SBP-2 device");
1495
1496 return 0; 1505 return 0;
1497
1498} 1506}
1499 1507
1500/* 1508/*
@@ -1592,11 +1600,6 @@ static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id,
1592 } 1600 }
1593 1601
1594 workarounds = sbp2_default_workarounds; 1602 workarounds = sbp2_default_workarounds;
1595 if (force_inquiry_hack) {
1596 SBP2_WARN("force_inquiry_hack is deprecated. "
1597 "Use parameter 'workarounds' instead.");
1598 workarounds |= SBP2_WORKAROUND_INQUIRY_36;
1599 }
1600 1603
1601 if (!(workarounds & SBP2_WORKAROUND_OVERRIDE)) 1604 if (!(workarounds & SBP2_WORKAROUND_OVERRIDE))
1602 for (i = 0; i < ARRAY_SIZE(sbp2_workarounds_table); i++) { 1605 for (i = 0; i < ARRAY_SIZE(sbp2_workarounds_table); i++) {
@@ -1705,9 +1708,14 @@ static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait)
1705 quadlet_t data; 1708 quadlet_t data;
1706 u64 addr; 1709 u64 addr;
1707 int retval; 1710 int retval;
1711 unsigned long flags;
1708 1712
1709 SBP2_DEBUG_ENTER(); 1713 SBP2_DEBUG_ENTER();
1710 1714
1715 cancel_delayed_work(&scsi_id->protocol_work);
1716 if (wait)
1717 flush_scheduled_work();
1718
1711 data = ntohl(SBP2_AGENT_RESET_DATA); 1719 data = ntohl(SBP2_AGENT_RESET_DATA);
1712 addr = scsi_id->sbp2_command_block_agent_addr + SBP2_AGENT_RESET_OFFSET; 1720 addr = scsi_id->sbp2_command_block_agent_addr + SBP2_AGENT_RESET_OFFSET;
1713 1721
@@ -1724,7 +1732,9 @@ static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait)
1724 /* 1732 /*
1725 * Need to make sure orb pointer is written on next command 1733 * Need to make sure orb pointer is written on next command
1726 */ 1734 */
1735 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
1727 scsi_id->last_orb = NULL; 1736 scsi_id->last_orb = NULL;
1737 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
1728 1738
1729 return 0; 1739 return 0;
1730} 1740}
@@ -1961,13 +1971,17 @@ static void sbp2_create_command_orb(struct scsi_id_instance_data *scsi_id,
1961/* 1971/*
1962 * This function is called in order to begin a regular SBP-2 command. 1972 * This function is called in order to begin a regular SBP-2 command.
1963 */ 1973 */
1964static int sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, 1974static void sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id,
1965 struct sbp2_command_info *command) 1975 struct sbp2_command_info *command)
1966{ 1976{
1967 struct sbp2scsi_host_info *hi = scsi_id->hi; 1977 struct sbp2scsi_host_info *hi = scsi_id->hi;
1968 struct sbp2_command_orb *command_orb = &command->command_orb; 1978 struct sbp2_command_orb *command_orb = &command->command_orb;
1969 struct node_entry *ne = scsi_id->ne; 1979 struct sbp2_command_orb *last_orb;
1970 u64 addr; 1980 dma_addr_t last_orb_dma;
1981 u64 addr = scsi_id->sbp2_command_block_agent_addr;
1982 quadlet_t data[2];
1983 size_t length;
1984 unsigned long flags;
1971 1985
1972 outstanding_orb_incr; 1986 outstanding_orb_incr;
1973 SBP2_ORB_DEBUG("sending command orb %p, total orbs = %x", 1987 SBP2_ORB_DEBUG("sending command orb %p, total orbs = %x",
@@ -1975,73 +1989,70 @@ static int sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id,
1975 1989
1976 pci_dma_sync_single_for_device(hi->host->pdev, command->command_orb_dma, 1990 pci_dma_sync_single_for_device(hi->host->pdev, command->command_orb_dma,
1977 sizeof(struct sbp2_command_orb), 1991 sizeof(struct sbp2_command_orb),
1978 PCI_DMA_BIDIRECTIONAL); 1992 PCI_DMA_TODEVICE);
1979 pci_dma_sync_single_for_device(hi->host->pdev, command->sge_dma, 1993 pci_dma_sync_single_for_device(hi->host->pdev, command->sge_dma,
1980 sizeof(command->scatter_gather_element), 1994 sizeof(command->scatter_gather_element),
1981 PCI_DMA_BIDIRECTIONAL); 1995 PCI_DMA_BIDIRECTIONAL);
1982 /* 1996 /*
1983 * Check to see if there are any previous orbs to use 1997 * Check to see if there are any previous orbs to use
1984 */ 1998 */
1985 if (scsi_id->last_orb == NULL) { 1999 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
1986 quadlet_t data[2]; 2000 last_orb = scsi_id->last_orb;
1987 2001 last_orb_dma = scsi_id->last_orb_dma;
2002 if (!last_orb) {
1988 /* 2003 /*
1989 * Ok, let's write to the target's management agent register 2004 * last_orb == NULL means: We know that the target's fetch agent
2005 * is not active right now.
1990 */ 2006 */
1991 addr = scsi_id->sbp2_command_block_agent_addr + SBP2_ORB_POINTER_OFFSET; 2007 addr += SBP2_ORB_POINTER_OFFSET;
1992 data[0] = ORB_SET_NODE_ID(hi->host->node_id); 2008 data[0] = ORB_SET_NODE_ID(hi->host->node_id);
1993 data[1] = command->command_orb_dma; 2009 data[1] = command->command_orb_dma;
1994 sbp2util_cpu_to_be32_buffer(data, 8); 2010 sbp2util_cpu_to_be32_buffer(data, 8);
1995 2011 length = 8;
1996 SBP2_ORB_DEBUG("write command agent, command orb %p", command_orb);
1997
1998 if (sbp2util_node_write_no_wait(ne, addr, data, 8) < 0) {
1999 SBP2_ERR("sbp2util_node_write_no_wait failed.\n");
2000 return -EIO;
2001 }
2002
2003 SBP2_ORB_DEBUG("write command agent complete");
2004
2005 scsi_id->last_orb = command_orb;
2006 scsi_id->last_orb_dma = command->command_orb_dma;
2007
2008 } else { 2012 } else {
2009 quadlet_t data;
2010
2011 /* 2013 /*
2012 * We have an orb already sent (maybe or maybe not 2014 * last_orb != NULL means: We know that the target's fetch agent
2013 * processed) that we can append this orb to. So do so, 2015 * is (very probably) not dead or in reset state right now.
2014 * and ring the doorbell. Have to be very careful 2016 * We have an ORB already sent that we can append a new one to.
2015 * modifying these next orb pointers, as they are accessed 2017 * The target's fetch agent may or may not have read this
2016 * both by the sbp2 device and us. 2018 * previous ORB yet.
2017 */ 2019 */
2018 scsi_id->last_orb->next_ORB_lo = 2020 pci_dma_sync_single_for_cpu(hi->host->pdev, last_orb_dma,
2019 cpu_to_be32(command->command_orb_dma); 2021 sizeof(struct sbp2_command_orb),
2022 PCI_DMA_TODEVICE);
2023 last_orb->next_ORB_lo = cpu_to_be32(command->command_orb_dma);
2024 wmb();
2020 /* Tells hardware that this pointer is valid */ 2025 /* Tells hardware that this pointer is valid */
2021 scsi_id->last_orb->next_ORB_hi = 0x0; 2026 last_orb->next_ORB_hi = 0;
2022 pci_dma_sync_single_for_device(hi->host->pdev, 2027 pci_dma_sync_single_for_device(hi->host->pdev, last_orb_dma,
2023 scsi_id->last_orb_dma,
2024 sizeof(struct sbp2_command_orb), 2028 sizeof(struct sbp2_command_orb),
2025 PCI_DMA_BIDIRECTIONAL); 2029 PCI_DMA_TODEVICE);
2030 addr += SBP2_DOORBELL_OFFSET;
2031 data[0] = 0;
2032 length = 4;
2033 }
2034 scsi_id->last_orb = command_orb;
2035 scsi_id->last_orb_dma = command->command_orb_dma;
2036 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
2026 2037
2038 SBP2_ORB_DEBUG("write to %s register, command orb %p",
2039 last_orb ? "DOORBELL" : "ORB_POINTER", command_orb);
2040 if (sbp2util_node_write_no_wait(scsi_id->ne, addr, data, length)) {
2027 /* 2041 /*
2028 * Ring the doorbell 2042 * sbp2util_node_write_no_wait failed. We certainly ran out
2043 * of transaction labels, perhaps just because there were no
2044 * context switches which gave khpsbpkt a chance to collect
2045 * free tlabels. Try again in non-atomic context. If necessary,
2046 * the workqueue job will sleep to guaranteedly get a tlabel.
2047 * We do not accept new commands until the job is over.
2029 */ 2048 */
2030 data = cpu_to_be32(command->command_orb_dma); 2049 scsi_block_requests(scsi_id->scsi_host);
2031 addr = scsi_id->sbp2_command_block_agent_addr + SBP2_DOORBELL_OFFSET; 2050 PREPARE_WORK(&scsi_id->protocol_work,
2032 2051 last_orb ? sbp2util_write_doorbell:
2033 SBP2_ORB_DEBUG("ring doorbell, command orb %p", command_orb); 2052 sbp2util_write_orb_pointer,
2034 2053 scsi_id);
2035 if (sbp2util_node_write_no_wait(ne, addr, &data, 4) < 0) { 2054 schedule_work(&scsi_id->protocol_work);
2036 SBP2_ERR("sbp2util_node_write_no_wait failed");
2037 return -EIO;
2038 }
2039
2040 scsi_id->last_orb = command_orb;
2041 scsi_id->last_orb_dma = command->command_orb_dma;
2042
2043 } 2055 }
2044 return 0;
2045} 2056}
2046 2057
2047/* 2058/*
@@ -2078,11 +2089,6 @@ static int sbp2_send_command(struct scsi_id_instance_data *scsi_id,
2078 "sbp2 command orb", command->command_orb_dma); 2089 "sbp2 command orb", command->command_orb_dma);
2079 2090
2080 /* 2091 /*
2081 * Initialize status fifo
2082 */
2083 memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block));
2084
2085 /*
2086 * Link up the orb, and ring the doorbell if needed 2092 * Link up the orb, and ring the doorbell if needed
2087 */ 2093 */
2088 sbp2_link_orb_command(scsi_id, command); 2094 sbp2_link_orb_command(scsi_id, command);
@@ -2123,12 +2129,14 @@ static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, unchar *sense
2123/* 2129/*
2124 * This function deals with status writes from the SBP-2 device 2130 * This function deals with status writes from the SBP-2 device
2125 */ 2131 */
2126static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int destid, 2132static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid,
2127 quadlet_t *data, u64 addr, size_t length, u16 fl) 2133 int destid, quadlet_t *data, u64 addr,
2134 size_t length, u16 fl)
2128{ 2135{
2129 struct sbp2scsi_host_info *hi; 2136 struct sbp2scsi_host_info *hi;
2130 struct scsi_id_instance_data *scsi_id = NULL, *scsi_id_tmp; 2137 struct scsi_id_instance_data *scsi_id = NULL, *scsi_id_tmp;
2131 struct scsi_cmnd *SCpnt = NULL; 2138 struct scsi_cmnd *SCpnt = NULL;
2139 struct sbp2_status_block *sb;
2132 u32 scsi_status = SBP2_SCSI_STATUS_GOOD; 2140 u32 scsi_status = SBP2_SCSI_STATUS_GOOD;
2133 struct sbp2_command_info *command; 2141 struct sbp2_command_info *command;
2134 unsigned long flags; 2142 unsigned long flags;
@@ -2137,18 +2145,19 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int dest
2137 2145
2138 sbp2util_packet_dump(data, length, "sbp2 status write by device", (u32)addr); 2146 sbp2util_packet_dump(data, length, "sbp2 status write by device", (u32)addr);
2139 2147
2140 if (!host) { 2148 if (unlikely(length < 8 || length > sizeof(struct sbp2_status_block))) {
2149 SBP2_ERR("Wrong size of status block");
2150 return RCODE_ADDRESS_ERROR;
2151 }
2152 if (unlikely(!host)) {
2141 SBP2_ERR("host is NULL - this is bad!"); 2153 SBP2_ERR("host is NULL - this is bad!");
2142 return RCODE_ADDRESS_ERROR; 2154 return RCODE_ADDRESS_ERROR;
2143 } 2155 }
2144
2145 hi = hpsb_get_hostinfo(&sbp2_highlevel, host); 2156 hi = hpsb_get_hostinfo(&sbp2_highlevel, host);
2146 2157 if (unlikely(!hi)) {
2147 if (!hi) {
2148 SBP2_ERR("host info is NULL - this is bad!"); 2158 SBP2_ERR("host info is NULL - this is bad!");
2149 return RCODE_ADDRESS_ERROR; 2159 return RCODE_ADDRESS_ERROR;
2150 } 2160 }
2151
2152 /* 2161 /*
2153 * Find our scsi_id structure by looking at the status fifo address 2162 * Find our scsi_id structure by looking at the status fifo address
2154 * written to by the sbp2 device. 2163 * written to by the sbp2 device.
@@ -2160,32 +2169,35 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int dest
2160 break; 2169 break;
2161 } 2170 }
2162 } 2171 }
2163 2172 if (unlikely(!scsi_id)) {
2164 if (!scsi_id) {
2165 SBP2_ERR("scsi_id is NULL - device is gone?"); 2173 SBP2_ERR("scsi_id is NULL - device is gone?");
2166 return RCODE_ADDRESS_ERROR; 2174 return RCODE_ADDRESS_ERROR;
2167 } 2175 }
2168 2176
2169 /* 2177 /*
2170 * Put response into scsi_id status fifo... 2178 * Put response into scsi_id status fifo buffer. The first two bytes
2179 * come in big endian bit order. Often the target writes only a
2180 * truncated status block, minimally the first two quadlets. The rest
2181 * is implied to be zeros.
2171 */ 2182 */
2172 memcpy(&scsi_id->status_block, data, length); 2183 sb = &scsi_id->status_block;
2184 memset(sb->command_set_dependent, 0, sizeof(sb->command_set_dependent));
2185 memcpy(sb, data, length);
2186 sbp2util_be32_to_cpu_buffer(sb, 8);
2173 2187
2174 /* 2188 /*
2175 * Byte swap first two quadlets (8 bytes) of status for processing 2189 * Ignore unsolicited status. Handle command ORB status.
2176 */ 2190 */
2177 sbp2util_be32_to_cpu_buffer(&scsi_id->status_block, 8); 2191 if (unlikely(STATUS_GET_SRC(sb->ORB_offset_hi_misc) == 2))
2178 2192 command = NULL;
2179 /* 2193 else
2180 * Handle command ORB status here if necessary. First, need to match status with command. 2194 command = sbp2util_find_command_for_orb(scsi_id,
2181 */ 2195 sb->ORB_offset_lo);
2182 command = sbp2util_find_command_for_orb(scsi_id, scsi_id->status_block.ORB_offset_lo);
2183 if (command) { 2196 if (command) {
2184
2185 SBP2_DEBUG("Found status for command ORB"); 2197 SBP2_DEBUG("Found status for command ORB");
2186 pci_dma_sync_single_for_cpu(hi->host->pdev, command->command_orb_dma, 2198 pci_dma_sync_single_for_cpu(hi->host->pdev, command->command_orb_dma,
2187 sizeof(struct sbp2_command_orb), 2199 sizeof(struct sbp2_command_orb),
2188 PCI_DMA_BIDIRECTIONAL); 2200 PCI_DMA_TODEVICE);
2189 pci_dma_sync_single_for_cpu(hi->host->pdev, command->sge_dma, 2201 pci_dma_sync_single_for_cpu(hi->host->pdev, command->sge_dma,
2190 sizeof(command->scatter_gather_element), 2202 sizeof(command->scatter_gather_element),
2191 PCI_DMA_BIDIRECTIONAL); 2203 PCI_DMA_BIDIRECTIONAL);
@@ -2194,7 +2206,12 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int dest
2194 outstanding_orb_decr; 2206 outstanding_orb_decr;
2195 2207
2196 /* 2208 /*
2197 * Matched status with command, now grab scsi command pointers and check status 2209 * Matched status with command, now grab scsi command pointers
2210 * and check status.
2211 */
2212 /*
2213 * FIXME: If the src field in the status is 1, the ORB DMA must
2214 * not be reused until status for a subsequent ORB is received.
2198 */ 2215 */
2199 SCpnt = command->Current_SCpnt; 2216 SCpnt = command->Current_SCpnt;
2200 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); 2217 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
@@ -2202,61 +2219,64 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int dest
2202 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); 2219 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
2203 2220
2204 if (SCpnt) { 2221 if (SCpnt) {
2205 2222 u32 h = sb->ORB_offset_hi_misc;
2223 u32 r = STATUS_GET_RESP(h);
2224
2225 if (r != RESP_STATUS_REQUEST_COMPLETE) {
2226 SBP2_WARN("resp 0x%x, sbp_status 0x%x",
2227 r, STATUS_GET_SBP_STATUS(h));
2228 scsi_status =
2229 r == RESP_STATUS_TRANSPORT_FAILURE ?
2230 SBP2_SCSI_STATUS_BUSY :
2231 SBP2_SCSI_STATUS_COMMAND_TERMINATED;
2232 }
2206 /* 2233 /*
2207 * See if the target stored any scsi status information 2234 * See if the target stored any scsi status information.
2208 */ 2235 */
2209 if (STATUS_GET_LENGTH(scsi_id->status_block.ORB_offset_hi_misc) > 1) { 2236 if (STATUS_GET_LEN(h) > 1) {
2210 /*
2211 * Translate SBP-2 status to SCSI sense data
2212 */
2213 SBP2_DEBUG("CHECK CONDITION"); 2237 SBP2_DEBUG("CHECK CONDITION");
2214 scsi_status = sbp2_status_to_sense_data((unchar *)&scsi_id->status_block, SCpnt->sense_buffer); 2238 scsi_status = sbp2_status_to_sense_data(
2239 (unchar *)sb, SCpnt->sense_buffer);
2215 } 2240 }
2216
2217 /* 2241 /*
2218 * Check to see if the dead bit is set. If so, we'll have to initiate 2242 * Check to see if the dead bit is set. If so, we'll
2219 * a fetch agent reset. 2243 * have to initiate a fetch agent reset.
2220 */ 2244 */
2221 if (STATUS_GET_DEAD_BIT(scsi_id->status_block.ORB_offset_hi_misc)) { 2245 if (STATUS_TEST_DEAD(h)) {
2222 2246 SBP2_DEBUG("Dead bit set - "
2223 /* 2247 "initiating fetch agent reset");
2224 * Initiate a fetch agent reset.
2225 */
2226 SBP2_DEBUG("Dead bit set - initiating fetch agent reset");
2227 sbp2_agent_reset(scsi_id, 0); 2248 sbp2_agent_reset(scsi_id, 0);
2228 } 2249 }
2229
2230 SBP2_ORB_DEBUG("completing command orb %p", &command->command_orb); 2250 SBP2_ORB_DEBUG("completing command orb %p", &command->command_orb);
2231 } 2251 }
2232 2252
2233 /* 2253 /*
2234 * Check here to see if there are no commands in-use. If there are none, we can 2254 * Check here to see if there are no commands in-use. If there
2235 * null out last orb so that next time around we write directly to the orb pointer... 2255 * are none, we know that the fetch agent left the active state
2236 * Quick start saves one 1394 bus transaction. 2256 * _and_ that we did not reactivate it yet. Therefore clear
2257 * last_orb so that next time we write directly to the
2258 * ORB_POINTER register. That way the fetch agent does not need
2259 * to refetch the next_ORB.
2237 */ 2260 */
2238 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); 2261 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
2239 if (list_empty(&scsi_id->sbp2_command_orb_inuse)) { 2262 if (list_empty(&scsi_id->sbp2_command_orb_inuse))
2240 scsi_id->last_orb = NULL; 2263 scsi_id->last_orb = NULL;
2241 }
2242 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); 2264 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
2243 2265
2244 } else { 2266 } else {
2245
2246 /* 2267 /*
2247 * It's probably a login/logout/reconnect status. 2268 * It's probably a login/logout/reconnect status.
2248 */ 2269 */
2249 if ((scsi_id->login_orb_dma == scsi_id->status_block.ORB_offset_lo) || 2270 if ((sb->ORB_offset_lo == scsi_id->reconnect_orb_dma) ||
2250 (scsi_id->query_logins_orb_dma == scsi_id->status_block.ORB_offset_lo) || 2271 (sb->ORB_offset_lo == scsi_id->login_orb_dma) ||
2251 (scsi_id->reconnect_orb_dma == scsi_id->status_block.ORB_offset_lo) || 2272 (sb->ORB_offset_lo == scsi_id->query_logins_orb_dma) ||
2252 (scsi_id->logout_orb_dma == scsi_id->status_block.ORB_offset_lo)) { 2273 (sb->ORB_offset_lo == scsi_id->logout_orb_dma)) {
2253 atomic_set(&scsi_id->sbp2_login_complete, 1); 2274 scsi_id->access_complete = 1;
2275 wake_up_interruptible(&access_wq);
2254 } 2276 }
2255 } 2277 }
2256 2278
2257 if (SCpnt) { 2279 if (SCpnt) {
2258
2259 /* Complete the SCSI command. */
2260 SBP2_DEBUG("Completing SCSI command"); 2280 SBP2_DEBUG("Completing SCSI command");
2261 sbp2scsi_complete_command(scsi_id, scsi_status, SCpnt, 2281 sbp2scsi_complete_command(scsi_id, scsi_status, SCpnt,
2262 command->Current_done); 2282 command->Current_done);
@@ -2372,7 +2392,7 @@ static void sbp2scsi_complete_all_commands(struct scsi_id_instance_data *scsi_id
2372 command = list_entry(lh, struct sbp2_command_info, list); 2392 command = list_entry(lh, struct sbp2_command_info, list);
2373 pci_dma_sync_single_for_cpu(hi->host->pdev, command->command_orb_dma, 2393 pci_dma_sync_single_for_cpu(hi->host->pdev, command->command_orb_dma,
2374 sizeof(struct sbp2_command_orb), 2394 sizeof(struct sbp2_command_orb),
2375 PCI_DMA_BIDIRECTIONAL); 2395 PCI_DMA_TODEVICE);
2376 pci_dma_sync_single_for_cpu(hi->host->pdev, command->sge_dma, 2396 pci_dma_sync_single_for_cpu(hi->host->pdev, command->sge_dma,
2377 sizeof(command->scatter_gather_element), 2397 sizeof(command->scatter_gather_element),
2378 PCI_DMA_BIDIRECTIONAL); 2398 PCI_DMA_BIDIRECTIONAL);
@@ -2495,6 +2515,7 @@ static int sbp2scsi_slave_alloc(struct scsi_device *sdev)
2495 (struct scsi_id_instance_data *)sdev->host->hostdata[0]; 2515 (struct scsi_id_instance_data *)sdev->host->hostdata[0];
2496 2516
2497 scsi_id->sdev = sdev; 2517 scsi_id->sdev = sdev;
2518 sdev->allow_restart = 1;
2498 2519
2499 if (scsi_id->workarounds & SBP2_WORKAROUND_INQUIRY_36) 2520 if (scsi_id->workarounds & SBP2_WORKAROUND_INQUIRY_36)
2500 sdev->inquiry_len = 36; 2521 sdev->inquiry_len = 36;
@@ -2508,16 +2529,12 @@ static int sbp2scsi_slave_configure(struct scsi_device *sdev)
2508 2529
2509 blk_queue_dma_alignment(sdev->request_queue, (512 - 1)); 2530 blk_queue_dma_alignment(sdev->request_queue, (512 - 1));
2510 sdev->use_10_for_rw = 1; 2531 sdev->use_10_for_rw = 1;
2511 sdev->use_10_for_ms = 1;
2512 2532
2513 if (sdev->type == TYPE_DISK && 2533 if (sdev->type == TYPE_DISK &&
2514 scsi_id->workarounds & SBP2_WORKAROUND_MODE_SENSE_8) 2534 scsi_id->workarounds & SBP2_WORKAROUND_MODE_SENSE_8)
2515 sdev->skip_ms_page_8 = 1; 2535 sdev->skip_ms_page_8 = 1;
2516 if (scsi_id->workarounds & SBP2_WORKAROUND_FIX_CAPACITY) 2536 if (scsi_id->workarounds & SBP2_WORKAROUND_FIX_CAPACITY)
2517 sdev->fix_capacity = 1; 2537 sdev->fix_capacity = 1;
2518 if (scsi_id->ne->guid_vendor_id == 0x0010b9 && /* Maxtor's OUI */
2519 (sdev->type == TYPE_DISK || sdev->type == TYPE_RBC))
2520 sdev->allow_restart = 1;
2521 return 0; 2538 return 0;
2522} 2539}
2523 2540
@@ -2555,7 +2572,7 @@ static int sbp2scsi_abort(struct scsi_cmnd *SCpnt)
2555 pci_dma_sync_single_for_cpu(hi->host->pdev, 2572 pci_dma_sync_single_for_cpu(hi->host->pdev,
2556 command->command_orb_dma, 2573 command->command_orb_dma,
2557 sizeof(struct sbp2_command_orb), 2574 sizeof(struct sbp2_command_orb),
2558 PCI_DMA_BIDIRECTIONAL); 2575 PCI_DMA_TODEVICE);
2559 pci_dma_sync_single_for_cpu(hi->host->pdev, 2576 pci_dma_sync_single_for_cpu(hi->host->pdev,
2560 command->sge_dma, 2577 command->sge_dma,
2561 sizeof(command->scatter_gather_element), 2578 sizeof(command->scatter_gather_element),
@@ -2571,7 +2588,7 @@ static int sbp2scsi_abort(struct scsi_cmnd *SCpnt)
2571 /* 2588 /*
2572 * Initiate a fetch agent reset. 2589 * Initiate a fetch agent reset.
2573 */ 2590 */
2574 sbp2_agent_reset(scsi_id, 0); 2591 sbp2_agent_reset(scsi_id, 1);
2575 sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY); 2592 sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY);
2576 } 2593 }
2577 2594
@@ -2590,7 +2607,7 @@ static int sbp2scsi_reset(struct scsi_cmnd *SCpnt)
2590 2607
2591 if (sbp2util_node_is_available(scsi_id)) { 2608 if (sbp2util_node_is_available(scsi_id)) {
2592 SBP2_ERR("Generating sbp2 fetch agent reset"); 2609 SBP2_ERR("Generating sbp2 fetch agent reset");
2593 sbp2_agent_reset(scsi_id, 0); 2610 sbp2_agent_reset(scsi_id, 1);
2594 } 2611 }
2595 2612
2596 return SUCCESS; 2613 return SUCCESS;
diff --git a/drivers/ieee1394/sbp2.h b/drivers/ieee1394/sbp2.h
index b22ce1aa8fe4..abbe48e646c3 100644
--- a/drivers/ieee1394/sbp2.h
+++ b/drivers/ieee1394/sbp2.h
@@ -46,8 +46,8 @@
46#define ORB_SET_DIRECTION(value) ((value & 0x1) << 27) 46#define ORB_SET_DIRECTION(value) ((value & 0x1) << 27)
47 47
48struct sbp2_command_orb { 48struct sbp2_command_orb {
49 volatile u32 next_ORB_hi; 49 u32 next_ORB_hi;
50 volatile u32 next_ORB_lo; 50 u32 next_ORB_lo;
51 u32 data_descriptor_hi; 51 u32 data_descriptor_hi;
52 u32 data_descriptor_lo; 52 u32 data_descriptor_lo;
53 u32 misc; 53 u32 misc;
@@ -180,12 +180,14 @@ struct sbp2_unrestricted_page_table {
180 180
181#define SBP2_SCSI_STATUS_SELECTION_TIMEOUT 0xff 181#define SBP2_SCSI_STATUS_SELECTION_TIMEOUT 0xff
182 182
183#define STATUS_GET_ORB_OFFSET_HI(value) (value & 0xffff) 183#define STATUS_GET_SRC(value) (((value) >> 30) & 0x3)
184#define STATUS_GET_SBP_STATUS(value) ((value >> 16) & 0xff) 184#define STATUS_GET_RESP(value) (((value) >> 28) & 0x3)
185#define STATUS_GET_LENGTH(value) ((value >> 24) & 0x7) 185#define STATUS_GET_LEN(value) (((value) >> 24) & 0x7)
186#define STATUS_GET_DEAD_BIT(value) ((value >> 27) & 0x1) 186#define STATUS_GET_SBP_STATUS(value) (((value) >> 16) & 0xff)
187#define STATUS_GET_RESP(value) ((value >> 28) & 0x3) 187#define STATUS_GET_ORB_OFFSET_HI(value) ((value) & 0x0000ffff)
188#define STATUS_GET_SRC(value) ((value >> 30) & 0x3) 188#define STATUS_TEST_DEAD(value) ((value) & 0x08000000)
189/* test 'resp' | 'dead' | 'sbp2_status' */
190#define STATUS_TEST_RDS(value) ((value) & 0x38ff0000)
189 191
190struct sbp2_status_block { 192struct sbp2_status_block {
191 u32 ORB_offset_hi_misc; 193 u32 ORB_offset_hi_misc;
@@ -318,9 +320,9 @@ struct scsi_id_instance_data {
318 u64 status_fifo_addr; 320 u64 status_fifo_addr;
319 321
320 /* 322 /*
321 * Variable used for logins, reconnects, logouts, query logins 323 * Waitqueue flag for logins, reconnects, logouts, query logins
322 */ 324 */
323 atomic_t sbp2_login_complete; 325 int access_complete:1;
324 326
325 /* 327 /*
326 * Pool of command orbs, so we can have more than overlapped command per id 328 * Pool of command orbs, so we can have more than overlapped command per id
@@ -344,6 +346,16 @@ struct scsi_id_instance_data {
344 346
345 /* Device specific workarounds/brokeness */ 347 /* Device specific workarounds/brokeness */
346 unsigned workarounds; 348 unsigned workarounds;
349
350 atomic_t state;
351 struct work_struct protocol_work;
352};
353
354/* For use in scsi_id_instance_data.state */
355enum sbp2lu_state_types {
356 SBP2LU_STATE_RUNNING, /* all normal */
357 SBP2LU_STATE_IN_RESET, /* between bus reset and reconnect */
358 SBP2LU_STATE_IN_SHUTDOWN /* when sbp2_remove was called */
347}; 359};
348 360
349/* Sbp2 host data structure (one per IEEE1394 host) */ 361/* Sbp2 host data structure (one per IEEE1394 host) */
@@ -390,11 +402,6 @@ static int sbp2_logout_device(struct scsi_id_instance_data *scsi_id);
390static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int destid, 402static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int destid,
391 quadlet_t *data, u64 addr, size_t length, u16 flags); 403 quadlet_t *data, u64 addr, size_t length, u16 flags);
392static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait); 404static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait);
393static int sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id,
394 struct sbp2_command_info *command);
395static int sbp2_send_command(struct scsi_id_instance_data *scsi_id,
396 struct scsi_cmnd *SCpnt,
397 void (*done)(struct scsi_cmnd *));
398static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, 405static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status,
399 unchar *sense_data); 406 unchar *sense_data);
400static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id, 407static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id,
diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c
index c6e3f02bc6d7..9bc65059cc69 100644
--- a/drivers/ieee1394/video1394.c
+++ b/drivers/ieee1394/video1394.c
@@ -49,16 +49,16 @@
49#include <linux/compat.h> 49#include <linux/compat.h>
50#include <linux/cdev.h> 50#include <linux/cdev.h>
51 51
52#include "ieee1394.h" 52#include "dma.h"
53#include "ieee1394_types.h" 53#include "highlevel.h"
54#include "hosts.h" 54#include "hosts.h"
55#include "ieee1394.h"
55#include "ieee1394_core.h" 56#include "ieee1394_core.h"
56#include "highlevel.h" 57#include "ieee1394_hotplug.h"
57#include "video1394.h" 58#include "ieee1394_types.h"
58#include "nodemgr.h" 59#include "nodemgr.h"
59#include "dma.h"
60
61#include "ohci1394.h" 60#include "ohci1394.h"
61#include "video1394.h"
62 62
63#define ISO_CHANNELS 64 63#define ISO_CHANNELS 64
64 64
@@ -129,7 +129,7 @@ struct file_ctx {
129#define DBGMSG(card, fmt, args...) \ 129#define DBGMSG(card, fmt, args...) \
130printk(KERN_INFO "video1394_%d: " fmt "\n" , card , ## args) 130printk(KERN_INFO "video1394_%d: " fmt "\n" , card , ## args)
131#else 131#else
132#define DBGMSG(card, fmt, args...) 132#define DBGMSG(card, fmt, args...) do {} while (0)
133#endif 133#endif
134 134
135/* print general (card independent) information */ 135/* print general (card independent) information */
@@ -1181,7 +1181,8 @@ static int video1394_mmap(struct file *file, struct vm_area_struct *vma)
1181 1181
1182 lock_kernel(); 1182 lock_kernel();
1183 if (ctx->current_ctx == NULL) { 1183 if (ctx->current_ctx == NULL) {
1184 PRINT(KERN_ERR, ctx->ohci->host->id, "Current iso context not set"); 1184 PRINT(KERN_ERR, ctx->ohci->host->id,
1185 "Current iso context not set");
1185 } else 1186 } else
1186 res = dma_region_mmap(&ctx->current_ctx->dma, file, vma); 1187 res = dma_region_mmap(&ctx->current_ctx->dma, file, vma);
1187 unlock_kernel(); 1188 unlock_kernel();
@@ -1189,6 +1190,40 @@ static int video1394_mmap(struct file *file, struct vm_area_struct *vma)
1189 return res; 1190 return res;
1190} 1191}
1191 1192
1193static unsigned int video1394_poll(struct file *file, poll_table *pt)
1194{
1195 struct file_ctx *ctx;
1196 unsigned int mask = 0;
1197 unsigned long flags;
1198 struct dma_iso_ctx *d;
1199 int i;
1200
1201 lock_kernel();
1202 ctx = file->private_data;
1203 d = ctx->current_ctx;
1204 if (d == NULL) {
1205 PRINT(KERN_ERR, ctx->ohci->host->id,
1206 "Current iso context not set");
1207 mask = POLLERR;
1208 goto done;
1209 }
1210
1211 poll_wait(file, &d->waitq, pt);
1212
1213 spin_lock_irqsave(&d->lock, flags);
1214 for (i = 0; i < d->num_desc; i++) {
1215 if (d->buffer_status[i] == VIDEO1394_BUFFER_READY) {
1216 mask |= POLLIN | POLLRDNORM;
1217 break;
1218 }
1219 }
1220 spin_unlock_irqrestore(&d->lock, flags);
1221done:
1222 unlock_kernel();
1223
1224 return mask;
1225}
1226
1192static int video1394_open(struct inode *inode, struct file *file) 1227static int video1394_open(struct inode *inode, struct file *file)
1193{ 1228{
1194 int i = ieee1394_file_to_instance(file); 1229 int i = ieee1394_file_to_instance(file);
@@ -1257,6 +1292,7 @@ static struct file_operations video1394_fops=
1257#ifdef CONFIG_COMPAT 1292#ifdef CONFIG_COMPAT
1258 .compat_ioctl = video1394_compat_ioctl, 1293 .compat_ioctl = video1394_compat_ioctl,
1259#endif 1294#endif
1295 .poll = video1394_poll,
1260 .mmap = video1394_mmap, 1296 .mmap = video1394_mmap,
1261 .open = video1394_open, 1297 .open = video1394_open,
1262 .release = video1394_release 1298 .release = video1394_release
diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c
index 9cbf09e2052f..60d3fbdd216c 100644
--- a/drivers/infiniband/core/addr.c
+++ b/drivers/infiniband/core/addr.c
@@ -86,7 +86,7 @@ EXPORT_SYMBOL(rdma_copy_addr);
86int rdma_translate_ip(struct sockaddr *addr, struct rdma_dev_addr *dev_addr) 86int rdma_translate_ip(struct sockaddr *addr, struct rdma_dev_addr *dev_addr)
87{ 87{
88 struct net_device *dev; 88 struct net_device *dev;
89 u32 ip = ((struct sockaddr_in *) addr)->sin_addr.s_addr; 89 __be32 ip = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
90 int ret; 90 int ret;
91 91
92 dev = ip_dev_find(ip); 92 dev = ip_dev_find(ip);
@@ -239,7 +239,7 @@ static int addr_resolve_local(struct sockaddr_in *src_in,
239{ 239{
240 struct net_device *dev; 240 struct net_device *dev;
241 u32 src_ip = src_in->sin_addr.s_addr; 241 u32 src_ip = src_in->sin_addr.s_addr;
242 u32 dst_ip = dst_in->sin_addr.s_addr; 242 __be32 dst_ip = dst_in->sin_addr.s_addr;
243 int ret; 243 int ret;
244 244
245 dev = ip_dev_find(dst_ip); 245 dev = ip_dev_find(dst_ip);
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index 1178bd434d1b..9ae4f3a67c70 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -874,23 +874,25 @@ static struct rdma_id_private *cma_new_id(struct rdma_cm_id *listen_id,
874 __u16 port; 874 __u16 port;
875 u8 ip_ver; 875 u8 ip_ver;
876 876
877 if (cma_get_net_info(ib_event->private_data, listen_id->ps,
878 &ip_ver, &port, &src, &dst))
879 goto err;
880
877 id = rdma_create_id(listen_id->event_handler, listen_id->context, 881 id = rdma_create_id(listen_id->event_handler, listen_id->context,
878 listen_id->ps); 882 listen_id->ps);
879 if (IS_ERR(id)) 883 if (IS_ERR(id))
880 return NULL; 884 goto err;
885
886 cma_save_net_info(&id->route.addr, &listen_id->route.addr,
887 ip_ver, port, src, dst);
881 888
882 rt = &id->route; 889 rt = &id->route;
883 rt->num_paths = ib_event->param.req_rcvd.alternate_path ? 2 : 1; 890 rt->num_paths = ib_event->param.req_rcvd.alternate_path ? 2 : 1;
884 rt->path_rec = kmalloc(sizeof *rt->path_rec * rt->num_paths, GFP_KERNEL); 891 rt->path_rec = kmalloc(sizeof *rt->path_rec * rt->num_paths,
892 GFP_KERNEL);
885 if (!rt->path_rec) 893 if (!rt->path_rec)
886 goto err; 894 goto destroy_id;
887 895
888 if (cma_get_net_info(ib_event->private_data, listen_id->ps,
889 &ip_ver, &port, &src, &dst))
890 goto err;
891
892 cma_save_net_info(&id->route.addr, &listen_id->route.addr,
893 ip_ver, port, src, dst);
894 rt->path_rec[0] = *ib_event->param.req_rcvd.primary_path; 896 rt->path_rec[0] = *ib_event->param.req_rcvd.primary_path;
895 if (rt->num_paths == 2) 897 if (rt->num_paths == 2)
896 rt->path_rec[1] = *ib_event->param.req_rcvd.alternate_path; 898 rt->path_rec[1] = *ib_event->param.req_rcvd.alternate_path;
@@ -903,8 +905,10 @@ static struct rdma_id_private *cma_new_id(struct rdma_cm_id *listen_id,
903 id_priv = container_of(id, struct rdma_id_private, id); 905 id_priv = container_of(id, struct rdma_id_private, id);
904 id_priv->state = CMA_CONNECT; 906 id_priv->state = CMA_CONNECT;
905 return id_priv; 907 return id_priv;
906err: 908
909destroy_id:
907 rdma_destroy_id(id); 910 rdma_destroy_id(id);
911err:
908 return NULL; 912 return NULL;
909} 913}
910 914
@@ -932,6 +936,7 @@ static int cma_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event)
932 mutex_unlock(&lock); 936 mutex_unlock(&lock);
933 if (ret) { 937 if (ret) {
934 ret = -ENODEV; 938 ret = -ENODEV;
939 cma_exch(conn_id, CMA_DESTROYING);
935 cma_release_remove(conn_id); 940 cma_release_remove(conn_id);
936 rdma_destroy_id(&conn_id->id); 941 rdma_destroy_id(&conn_id->id);
937 goto out; 942 goto out;
@@ -1307,6 +1312,7 @@ static void cma_query_handler(int status, struct ib_sa_path_rec *path_rec,
1307 work->old_state = CMA_ROUTE_QUERY; 1312 work->old_state = CMA_ROUTE_QUERY;
1308 work->new_state = CMA_ADDR_RESOLVED; 1313 work->new_state = CMA_ADDR_RESOLVED;
1309 work->event.event = RDMA_CM_EVENT_ROUTE_ERROR; 1314 work->event.event = RDMA_CM_EVENT_ROUTE_ERROR;
1315 work->event.status = status;
1310 } 1316 }
1311 1317
1312 queue_work(cma_wq, &work->work); 1318 queue_work(cma_wq, &work->work);
@@ -1862,6 +1868,11 @@ static int cma_connect_ib(struct rdma_id_private *id_priv,
1862 1868
1863 ret = ib_send_cm_req(id_priv->cm_id.ib, &req); 1869 ret = ib_send_cm_req(id_priv->cm_id.ib, &req);
1864out: 1870out:
1871 if (ret && !IS_ERR(id_priv->cm_id.ib)) {
1872 ib_destroy_cm_id(id_priv->cm_id.ib);
1873 id_priv->cm_id.ib = NULL;
1874 }
1875
1865 kfree(private_data); 1876 kfree(private_data);
1866 return ret; 1877 return ret;
1867} 1878}
@@ -1889,10 +1900,8 @@ static int cma_connect_iw(struct rdma_id_private *id_priv,
1889 cm_id->remote_addr = *sin; 1900 cm_id->remote_addr = *sin;
1890 1901
1891 ret = cma_modify_qp_rtr(&id_priv->id); 1902 ret = cma_modify_qp_rtr(&id_priv->id);
1892 if (ret) { 1903 if (ret)
1893 iw_destroy_cm_id(cm_id); 1904 goto out;
1894 return ret;
1895 }
1896 1905
1897 iw_param.ord = conn_param->initiator_depth; 1906 iw_param.ord = conn_param->initiator_depth;
1898 iw_param.ird = conn_param->responder_resources; 1907 iw_param.ird = conn_param->responder_resources;
@@ -1904,6 +1913,10 @@ static int cma_connect_iw(struct rdma_id_private *id_priv,
1904 iw_param.qpn = conn_param->qp_num; 1913 iw_param.qpn = conn_param->qp_num;
1905 ret = iw_cm_connect(cm_id, &iw_param); 1914 ret = iw_cm_connect(cm_id, &iw_param);
1906out: 1915out:
1916 if (ret && !IS_ERR(cm_id)) {
1917 iw_destroy_cm_id(cm_id);
1918 id_priv->cm_id.iw = NULL;
1919 }
1907 return ret; 1920 return ret;
1908} 1921}
1909 1922
@@ -2142,12 +2155,9 @@ static int cma_remove_id_dev(struct rdma_id_private *id_priv)
2142 2155
2143static void cma_process_remove(struct cma_device *cma_dev) 2156static void cma_process_remove(struct cma_device *cma_dev)
2144{ 2157{
2145 struct list_head remove_list;
2146 struct rdma_id_private *id_priv; 2158 struct rdma_id_private *id_priv;
2147 int ret; 2159 int ret;
2148 2160
2149 INIT_LIST_HEAD(&remove_list);
2150
2151 mutex_lock(&lock); 2161 mutex_lock(&lock);
2152 while (!list_empty(&cma_dev->id_list)) { 2162 while (!list_empty(&cma_dev->id_list)) {
2153 id_priv = list_entry(cma_dev->id_list.next, 2163 id_priv = list_entry(cma_dev->id_list.next,
@@ -2158,8 +2168,7 @@ static void cma_process_remove(struct cma_device *cma_dev)
2158 continue; 2168 continue;
2159 } 2169 }
2160 2170
2161 list_del(&id_priv->list); 2171 list_del_init(&id_priv->list);
2162 list_add_tail(&id_priv->list, &remove_list);
2163 atomic_inc(&id_priv->refcount); 2172 atomic_inc(&id_priv->refcount);
2164 mutex_unlock(&lock); 2173 mutex_unlock(&lock);
2165 2174
diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c
index 082f03c158f0..493f4c65c7a2 100644
--- a/drivers/infiniband/core/mad.c
+++ b/drivers/infiniband/core/mad.c
@@ -2987,10 +2987,7 @@ error1:
2987static void __exit ib_mad_cleanup_module(void) 2987static void __exit ib_mad_cleanup_module(void)
2988{ 2988{
2989 ib_unregister_client(&mad_client); 2989 ib_unregister_client(&mad_client);
2990 2990 kmem_cache_destroy(ib_mad_cache);
2991 if (kmem_cache_destroy(ib_mad_cache)) {
2992 printk(KERN_DEBUG PFX "Failed to destroy ib_mad cache\n");
2993 }
2994} 2991}
2995 2992
2996module_init(ib_mad_init_module); 2993module_init(ib_mad_init_module);
diff --git a/drivers/infiniband/hw/amso1100/c2_ae.c b/drivers/infiniband/hw/amso1100/c2_ae.c
index 08f46c83a3a4..3aae4978e1cb 100644
--- a/drivers/infiniband/hw/amso1100/c2_ae.c
+++ b/drivers/infiniband/hw/amso1100/c2_ae.c
@@ -197,7 +197,7 @@ void c2_ae_event(struct c2_dev *c2dev, u32 mq_index)
197 "resource=%x, qp_state=%s\n", 197 "resource=%x, qp_state=%s\n",
198 __FUNCTION__, 198 __FUNCTION__,
199 to_event_str(event_id), 199 to_event_str(event_id),
200 be64_to_cpu(wr->ae.ae_generic.user_context), 200 (unsigned long long) be64_to_cpu(wr->ae.ae_generic.user_context),
201 be32_to_cpu(wr->ae.ae_generic.resource_type), 201 be32_to_cpu(wr->ae.ae_generic.resource_type),
202 be32_to_cpu(wr->ae.ae_generic.resource), 202 be32_to_cpu(wr->ae.ae_generic.resource),
203 to_qp_state_str(be32_to_cpu(wr->ae.ae_generic.qp_state))); 203 to_qp_state_str(be32_to_cpu(wr->ae.ae_generic.qp_state)));
diff --git a/drivers/infiniband/hw/amso1100/c2_alloc.c b/drivers/infiniband/hw/amso1100/c2_alloc.c
index 1d2529992c0c..028a60bbfca9 100644
--- a/drivers/infiniband/hw/amso1100/c2_alloc.c
+++ b/drivers/infiniband/hw/amso1100/c2_alloc.c
@@ -115,7 +115,7 @@ u16 *c2_alloc_mqsp(struct c2_dev *c2dev, struct sp_chunk *head,
115 ((unsigned long) &(head->shared_ptr[mqsp]) - 115 ((unsigned long) &(head->shared_ptr[mqsp]) -
116 (unsigned long) head); 116 (unsigned long) head);
117 pr_debug("%s addr %p dma_addr %llx\n", __FUNCTION__, 117 pr_debug("%s addr %p dma_addr %llx\n", __FUNCTION__,
118 &(head->shared_ptr[mqsp]), (u64)*dma_addr); 118 &(head->shared_ptr[mqsp]), (unsigned long long) *dma_addr);
119 return &(head->shared_ptr[mqsp]); 119 return &(head->shared_ptr[mqsp]);
120 } 120 }
121 return NULL; 121 return NULL;
diff --git a/drivers/infiniband/hw/amso1100/c2_cm.c b/drivers/infiniband/hw/amso1100/c2_cm.c
index 485254efdd1e..75b93e9b8810 100644
--- a/drivers/infiniband/hw/amso1100/c2_cm.c
+++ b/drivers/infiniband/hw/amso1100/c2_cm.c
@@ -302,7 +302,7 @@ int c2_llp_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param)
302 vq_req = vq_req_alloc(c2dev); 302 vq_req = vq_req_alloc(c2dev);
303 if (!vq_req) { 303 if (!vq_req) {
304 err = -ENOMEM; 304 err = -ENOMEM;
305 goto bail1; 305 goto bail0;
306 } 306 }
307 vq_req->qp = qp; 307 vq_req->qp = qp;
308 vq_req->cm_id = cm_id; 308 vq_req->cm_id = cm_id;
@@ -311,7 +311,7 @@ int c2_llp_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param)
311 wr = kmalloc(c2dev->req_vq.msg_size, GFP_KERNEL); 311 wr = kmalloc(c2dev->req_vq.msg_size, GFP_KERNEL);
312 if (!wr) { 312 if (!wr) {
313 err = -ENOMEM; 313 err = -ENOMEM;
314 goto bail2; 314 goto bail1;
315 } 315 }
316 316
317 /* Build the WR */ 317 /* Build the WR */
@@ -331,7 +331,7 @@ int c2_llp_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param)
331 /* Validate private_data length */ 331 /* Validate private_data length */
332 if (iw_param->private_data_len > C2_MAX_PRIVATE_DATA_SIZE) { 332 if (iw_param->private_data_len > C2_MAX_PRIVATE_DATA_SIZE) {
333 err = -EINVAL; 333 err = -EINVAL;
334 goto bail2; 334 goto bail1;
335 } 335 }
336 336
337 if (iw_param->private_data) { 337 if (iw_param->private_data) {
@@ -348,19 +348,19 @@ int c2_llp_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param)
348 err = vq_send_wr(c2dev, (union c2wr *) wr); 348 err = vq_send_wr(c2dev, (union c2wr *) wr);
349 if (err) { 349 if (err) {
350 vq_req_put(c2dev, vq_req); 350 vq_req_put(c2dev, vq_req);
351 goto bail2; 351 goto bail1;
352 } 352 }
353 353
354 /* Wait for reply from adapter */ 354 /* Wait for reply from adapter */
355 err = vq_wait_for_reply(c2dev, vq_req); 355 err = vq_wait_for_reply(c2dev, vq_req);
356 if (err) 356 if (err)
357 goto bail2; 357 goto bail1;
358 358
359 /* Check that reply is present */ 359 /* Check that reply is present */
360 reply = (struct c2wr_cr_accept_rep *) (unsigned long) vq_req->reply_msg; 360 reply = (struct c2wr_cr_accept_rep *) (unsigned long) vq_req->reply_msg;
361 if (!reply) { 361 if (!reply) {
362 err = -ENOMEM; 362 err = -ENOMEM;
363 goto bail2; 363 goto bail1;
364 } 364 }
365 365
366 err = c2_errno(reply); 366 err = c2_errno(reply);
@@ -368,9 +368,8 @@ int c2_llp_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param)
368 368
369 if (!err) 369 if (!err)
370 c2_set_qp_state(qp, C2_QP_STATE_RTS); 370 c2_set_qp_state(qp, C2_QP_STATE_RTS);
371 bail2:
372 kfree(wr);
373 bail1: 371 bail1:
372 kfree(wr);
374 vq_req_free(c2dev, vq_req); 373 vq_req_free(c2dev, vq_req);
375 bail0: 374 bail0:
376 if (err) { 375 if (err) {
diff --git a/drivers/infiniband/hw/amso1100/c2_provider.c b/drivers/infiniband/hw/amso1100/c2_provider.c
index dd6af551108b..da98d9f71429 100644
--- a/drivers/infiniband/hw/amso1100/c2_provider.c
+++ b/drivers/infiniband/hw/amso1100/c2_provider.c
@@ -390,14 +390,18 @@ static struct ib_mr *c2_reg_phys_mr(struct ib_pd *ib_pd,
390 } 390 }
391 391
392 mr = kmalloc(sizeof(*mr), GFP_KERNEL); 392 mr = kmalloc(sizeof(*mr), GFP_KERNEL);
393 if (!mr) 393 if (!mr) {
394 vfree(page_list);
394 return ERR_PTR(-ENOMEM); 395 return ERR_PTR(-ENOMEM);
396 }
395 397
396 mr->pd = to_c2pd(ib_pd); 398 mr->pd = to_c2pd(ib_pd);
397 pr_debug("%s - page shift %d, pbl_depth %d, total_len %u, " 399 pr_debug("%s - page shift %d, pbl_depth %d, total_len %u, "
398 "*iova_start %llx, first pa %llx, last pa %llx\n", 400 "*iova_start %llx, first pa %llx, last pa %llx\n",
399 __FUNCTION__, page_shift, pbl_depth, total_len, 401 __FUNCTION__, page_shift, pbl_depth, total_len,
400 *iova_start, page_list[0], page_list[pbl_depth-1]); 402 (unsigned long long) *iova_start,
403 (unsigned long long) page_list[0],
404 (unsigned long long) page_list[pbl_depth-1]);
401 err = c2_nsmr_register_phys_kern(to_c2dev(ib_pd->device), page_list, 405 err = c2_nsmr_register_phys_kern(to_c2dev(ib_pd->device), page_list,
402 (1 << page_shift), pbl_depth, 406 (1 << page_shift), pbl_depth,
403 total_len, 0, iova_start, 407 total_len, 0, iova_start,
diff --git a/drivers/infiniband/hw/amso1100/c2_rnic.c b/drivers/infiniband/hw/amso1100/c2_rnic.c
index f49a32b7a8f6..e37c5688c214 100644
--- a/drivers/infiniband/hw/amso1100/c2_rnic.c
+++ b/drivers/infiniband/hw/amso1100/c2_rnic.c
@@ -527,7 +527,7 @@ int c2_rnic_init(struct c2_dev *c2dev)
527 DMA_FROM_DEVICE); 527 DMA_FROM_DEVICE);
528 pci_unmap_addr_set(&c2dev->rep_vq, mapping, c2dev->rep_vq.host_dma); 528 pci_unmap_addr_set(&c2dev->rep_vq, mapping, c2dev->rep_vq.host_dma);
529 pr_debug("%s rep_vq va %p dma %llx\n", __FUNCTION__, q1_pages, 529 pr_debug("%s rep_vq va %p dma %llx\n", __FUNCTION__, q1_pages,
530 (u64)c2dev->rep_vq.host_dma); 530 (unsigned long long) c2dev->rep_vq.host_dma);
531 c2_mq_rep_init(&c2dev->rep_vq, 531 c2_mq_rep_init(&c2dev->rep_vq,
532 1, 532 1,
533 qsize, 533 qsize,
@@ -550,7 +550,7 @@ int c2_rnic_init(struct c2_dev *c2dev)
550 DMA_FROM_DEVICE); 550 DMA_FROM_DEVICE);
551 pci_unmap_addr_set(&c2dev->aeq, mapping, c2dev->aeq.host_dma); 551 pci_unmap_addr_set(&c2dev->aeq, mapping, c2dev->aeq.host_dma);
552 pr_debug("%s aeq va %p dma %llx\n", __FUNCTION__, q1_pages, 552 pr_debug("%s aeq va %p dma %llx\n", __FUNCTION__, q1_pages,
553 (u64)c2dev->rep_vq.host_dma); 553 (unsigned long long) c2dev->rep_vq.host_dma);
554 c2_mq_rep_init(&c2dev->aeq, 554 c2_mq_rep_init(&c2dev->aeq,
555 2, 555 2,
556 qsize, 556 qsize,
diff --git a/drivers/infiniband/hw/ehca/ehca_main.c b/drivers/infiniband/hw/ehca/ehca_main.c
index 2380994418a5..024d511c4b58 100644
--- a/drivers/infiniband/hw/ehca/ehca_main.c
+++ b/drivers/infiniband/hw/ehca/ehca_main.c
@@ -49,7 +49,7 @@
49MODULE_LICENSE("Dual BSD/GPL"); 49MODULE_LICENSE("Dual BSD/GPL");
50MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>"); 50MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
51MODULE_DESCRIPTION("IBM eServer HCA InfiniBand Device Driver"); 51MODULE_DESCRIPTION("IBM eServer HCA InfiniBand Device Driver");
52MODULE_VERSION("SVNEHCA_0016"); 52MODULE_VERSION("SVNEHCA_0017");
53 53
54int ehca_open_aqp1 = 0; 54int ehca_open_aqp1 = 0;
55int ehca_debug_level = 0; 55int ehca_debug_level = 0;
@@ -239,7 +239,7 @@ init_node_guid1:
239 return ret; 239 return ret;
240} 240}
241 241
242int ehca_register_device(struct ehca_shca *shca) 242int ehca_init_device(struct ehca_shca *shca)
243{ 243{
244 int ret; 244 int ret;
245 245
@@ -317,11 +317,6 @@ int ehca_register_device(struct ehca_shca *shca)
317 /* shca->ib_device.process_mad = ehca_process_mad; */ 317 /* shca->ib_device.process_mad = ehca_process_mad; */
318 shca->ib_device.mmap = ehca_mmap; 318 shca->ib_device.mmap = ehca_mmap;
319 319
320 ret = ib_register_device(&shca->ib_device);
321 if (ret)
322 ehca_err(&shca->ib_device,
323 "ib_register_device() failed ret=%x", ret);
324
325 return ret; 320 return ret;
326} 321}
327 322
@@ -561,9 +556,9 @@ static int __devinit ehca_probe(struct ibmebus_dev *dev,
561 goto probe1; 556 goto probe1;
562 } 557 }
563 558
564 ret = ehca_register_device(shca); 559 ret = ehca_init_device(shca);
565 if (ret) { 560 if (ret) {
566 ehca_gen_err("Cannot register Infiniband device"); 561 ehca_gen_err("Cannot init ehca device struct");
567 goto probe1; 562 goto probe1;
568 } 563 }
569 564
@@ -571,7 +566,7 @@ static int __devinit ehca_probe(struct ibmebus_dev *dev,
571 ret = ehca_create_eq(shca, &shca->eq, EHCA_EQ, 2048); 566 ret = ehca_create_eq(shca, &shca->eq, EHCA_EQ, 2048);
572 if (ret) { 567 if (ret) {
573 ehca_err(&shca->ib_device, "Cannot create EQ."); 568 ehca_err(&shca->ib_device, "Cannot create EQ.");
574 goto probe2; 569 goto probe1;
575 } 570 }
576 571
577 ret = ehca_create_eq(shca, &shca->neq, EHCA_NEQ, 513); 572 ret = ehca_create_eq(shca, &shca->neq, EHCA_NEQ, 513);
@@ -600,6 +595,13 @@ static int __devinit ehca_probe(struct ibmebus_dev *dev,
600 goto probe5; 595 goto probe5;
601 } 596 }
602 597
598 ret = ib_register_device(&shca->ib_device);
599 if (ret) {
600 ehca_err(&shca->ib_device,
601 "ib_register_device() failed ret=%x", ret);
602 goto probe6;
603 }
604
603 /* create AQP1 for port 1 */ 605 /* create AQP1 for port 1 */
604 if (ehca_open_aqp1 == 1) { 606 if (ehca_open_aqp1 == 1) {
605 shca->sport[0].port_state = IB_PORT_DOWN; 607 shca->sport[0].port_state = IB_PORT_DOWN;
@@ -607,7 +609,7 @@ static int __devinit ehca_probe(struct ibmebus_dev *dev,
607 if (ret) { 609 if (ret) {
608 ehca_err(&shca->ib_device, 610 ehca_err(&shca->ib_device,
609 "Cannot create AQP1 for port 1."); 611 "Cannot create AQP1 for port 1.");
610 goto probe6; 612 goto probe7;
611 } 613 }
612 } 614 }
613 615
@@ -618,7 +620,7 @@ static int __devinit ehca_probe(struct ibmebus_dev *dev,
618 if (ret) { 620 if (ret) {
619 ehca_err(&shca->ib_device, 621 ehca_err(&shca->ib_device,
620 "Cannot create AQP1 for port 2."); 622 "Cannot create AQP1 for port 2.");
621 goto probe7; 623 goto probe8;
622 } 624 }
623 } 625 }
624 626
@@ -630,12 +632,15 @@ static int __devinit ehca_probe(struct ibmebus_dev *dev,
630 632
631 return 0; 633 return 0;
632 634
633probe7: 635probe8:
634 ret = ehca_destroy_aqp1(&shca->sport[0]); 636 ret = ehca_destroy_aqp1(&shca->sport[0]);
635 if (ret) 637 if (ret)
636 ehca_err(&shca->ib_device, 638 ehca_err(&shca->ib_device,
637 "Cannot destroy AQP1 for port 1. ret=%x", ret); 639 "Cannot destroy AQP1 for port 1. ret=%x", ret);
638 640
641probe7:
642 ib_unregister_device(&shca->ib_device);
643
639probe6: 644probe6:
640 ret = ehca_dereg_internal_maxmr(shca); 645 ret = ehca_dereg_internal_maxmr(shca);
641 if (ret) 646 if (ret)
@@ -660,9 +665,6 @@ probe3:
660 ehca_err(&shca->ib_device, 665 ehca_err(&shca->ib_device,
661 "Cannot destroy EQ. ret=%x", ret); 666 "Cannot destroy EQ. ret=%x", ret);
662 667
663probe2:
664 ib_unregister_device(&shca->ib_device);
665
666probe1: 668probe1:
667 ib_dealloc_device(&shca->ib_device); 669 ib_dealloc_device(&shca->ib_device);
668 670
@@ -750,7 +752,7 @@ int __init ehca_module_init(void)
750 int ret; 752 int ret;
751 753
752 printk(KERN_INFO "eHCA Infiniband Device Driver " 754 printk(KERN_INFO "eHCA Infiniband Device Driver "
753 "(Rel.: SVNEHCA_0016)\n"); 755 "(Rel.: SVNEHCA_0017)\n");
754 idr_init(&ehca_qp_idr); 756 idr_init(&ehca_qp_idr);
755 idr_init(&ehca_cq_idr); 757 idr_init(&ehca_cq_idr);
756 spin_lock_init(&ehca_qp_idr_lock); 758 spin_lock_init(&ehca_qp_idr_lock);
diff --git a/drivers/infiniband/hw/ehca/ehca_tools.h b/drivers/infiniband/hw/ehca/ehca_tools.h
index 9f56bb846d93..809da3ef706b 100644
--- a/drivers/infiniband/hw/ehca/ehca_tools.h
+++ b/drivers/infiniband/hw/ehca/ehca_tools.h
@@ -117,7 +117,7 @@ extern int ehca_debug_level;
117 unsigned int l = (unsigned int)(len); \ 117 unsigned int l = (unsigned int)(len); \
118 unsigned char *deb = (unsigned char*)(adr); \ 118 unsigned char *deb = (unsigned char*)(adr); \
119 for (x = 0; x < l; x += 16) { \ 119 for (x = 0; x < l; x += 16) { \
120 printk("EHCA_DMP:%s" format \ 120 printk("EHCA_DMP:%s " format \
121 " adr=%p ofs=%04x %016lx %016lx\n", \ 121 " adr=%p ofs=%04x %016lx %016lx\n", \
122 __FUNCTION__, ##args, deb, x, \ 122 __FUNCTION__, ##args, deb, x, \
123 *((u64 *)&deb[0]), *((u64 *)&deb[8])); \ 123 *((u64 *)&deb[0]), *((u64 *)&deb[8])); \
diff --git a/drivers/infiniband/hw/ipath/ipath_common.h b/drivers/infiniband/hw/ipath/ipath_common.h
index f577905e3aca..54139d398181 100644
--- a/drivers/infiniband/hw/ipath/ipath_common.h
+++ b/drivers/infiniband/hw/ipath/ipath_common.h
@@ -141,8 +141,9 @@ struct infinipath_stats {
141 * packets if ipath not configured, etc.) 141 * packets if ipath not configured, etc.)
142 */ 142 */
143 __u64 sps_krdrops; 143 __u64 sps_krdrops;
144 __u64 sps_txeparity; /* PIO buffer parity error, recovered */
144 /* pad for future growth */ 145 /* pad for future growth */
145 __u64 __sps_pad[46]; 146 __u64 __sps_pad[45];
146}; 147};
147 148
148/* 149/*
@@ -185,6 +186,9 @@ typedef enum _ipath_ureg {
185#define IPATH_RUNTIME_PCIE 0x2 186#define IPATH_RUNTIME_PCIE 0x2
186#define IPATH_RUNTIME_FORCE_WC_ORDER 0x4 187#define IPATH_RUNTIME_FORCE_WC_ORDER 0x4
187#define IPATH_RUNTIME_RCVHDR_COPY 0x8 188#define IPATH_RUNTIME_RCVHDR_COPY 0x8
189#define IPATH_RUNTIME_MASTER 0x10
190#define IPATH_RUNTIME_PBC_REWRITE 0x20
191#define IPATH_RUNTIME_LOOSE_DMA_ALIGN 0x40
188 192
189/* 193/*
190 * This structure is returned by ipath_userinit() immediately after 194 * This structure is returned by ipath_userinit() immediately after
@@ -202,7 +206,8 @@ struct ipath_base_info {
202 /* version of software, for feature checking. */ 206 /* version of software, for feature checking. */
203 __u32 spi_sw_version; 207 __u32 spi_sw_version;
204 /* InfiniPath port assigned, goes into sent packets */ 208 /* InfiniPath port assigned, goes into sent packets */
205 __u32 spi_port; 209 __u16 spi_port;
210 __u16 spi_subport;
206 /* 211 /*
207 * IB MTU, packets IB data must be less than this. 212 * IB MTU, packets IB data must be less than this.
208 * The MTU is in bytes, and will be a multiple of 4 bytes. 213 * The MTU is in bytes, and will be a multiple of 4 bytes.
@@ -218,7 +223,7 @@ struct ipath_base_info {
218 __u32 spi_tidcnt; 223 __u32 spi_tidcnt;
219 /* size of the TID Eager list in infinipath, in entries */ 224 /* size of the TID Eager list in infinipath, in entries */
220 __u32 spi_tidegrcnt; 225 __u32 spi_tidegrcnt;
221 /* size of a single receive header queue entry. */ 226 /* size of a single receive header queue entry in words. */
222 __u32 spi_rcvhdrent_size; 227 __u32 spi_rcvhdrent_size;
223 /* 228 /*
224 * Count of receive header queue entries allocated. 229 * Count of receive header queue entries allocated.
@@ -310,6 +315,12 @@ struct ipath_base_info {
310 __u32 spi_filler_for_align; 315 __u32 spi_filler_for_align;
311 /* address of readonly memory copy of the rcvhdrq tail register. */ 316 /* address of readonly memory copy of the rcvhdrq tail register. */
312 __u64 spi_rcvhdr_tailaddr; 317 __u64 spi_rcvhdr_tailaddr;
318
319 /* shared memory pages for subports if IPATH_RUNTIME_MASTER is set */
320 __u64 spi_subport_uregbase;
321 __u64 spi_subport_rcvegrbuf;
322 __u64 spi_subport_rcvhdr_base;
323
313} __attribute__ ((aligned(8))); 324} __attribute__ ((aligned(8)));
314 325
315 326
@@ -328,12 +339,12 @@ struct ipath_base_info {
328 339
329/* 340/*
330 * Minor version differences are always compatible 341 * Minor version differences are always compatible
331 * a within a major version, however if if user software is larger 342 * a within a major version, however if user software is larger
332 * than driver software, some new features and/or structure fields 343 * than driver software, some new features and/or structure fields
333 * may not be implemented; the user code must deal with this if it 344 * may not be implemented; the user code must deal with this if it
334 * cares, or it must abort after initialization reports the difference 345 * cares, or it must abort after initialization reports the difference.
335 */ 346 */
336#define IPATH_USER_SWMINOR 2 347#define IPATH_USER_SWMINOR 3
337 348
338#define IPATH_USER_SWVERSION ((IPATH_USER_SWMAJOR<<16) | IPATH_USER_SWMINOR) 349#define IPATH_USER_SWVERSION ((IPATH_USER_SWMAJOR<<16) | IPATH_USER_SWMINOR)
339 350
@@ -379,7 +390,16 @@ struct ipath_user_info {
379 */ 390 */
380 __u32 spu_rcvhdrsize; 391 __u32 spu_rcvhdrsize;
381 392
382 __u64 spu_unused; /* kept for compatible layout */ 393 /*
394 * If two or more processes wish to share a port, each process
395 * must set the spu_subport_cnt and spu_subport_id to the same
396 * values. The only restriction on the spu_subport_id is that
397 * it be unique for a given node.
398 */
399 __u16 spu_subport_cnt;
400 __u16 spu_subport_id;
401
402 __u32 spu_unused; /* kept for compatible layout */
383 403
384 /* 404 /*
385 * address of struct base_info to write to 405 * address of struct base_info to write to
@@ -392,19 +412,25 @@ struct ipath_user_info {
392 412
393#define IPATH_CMD_MIN 16 413#define IPATH_CMD_MIN 16
394 414
395#define IPATH_CMD_USER_INIT 16 /* set up userspace */ 415#define __IPATH_CMD_USER_INIT 16 /* old set up userspace (for old user code) */
396#define IPATH_CMD_PORT_INFO 17 /* find out what resources we got */ 416#define IPATH_CMD_PORT_INFO 17 /* find out what resources we got */
397#define IPATH_CMD_RECV_CTRL 18 /* control receipt of packets */ 417#define IPATH_CMD_RECV_CTRL 18 /* control receipt of packets */
398#define IPATH_CMD_TID_UPDATE 19 /* update expected TID entries */ 418#define IPATH_CMD_TID_UPDATE 19 /* update expected TID entries */
399#define IPATH_CMD_TID_FREE 20 /* free expected TID entries */ 419#define IPATH_CMD_TID_FREE 20 /* free expected TID entries */
400#define IPATH_CMD_SET_PART_KEY 21 /* add partition key */ 420#define IPATH_CMD_SET_PART_KEY 21 /* add partition key */
421#define IPATH_CMD_SLAVE_INFO 22 /* return info on slave processes */
422#define IPATH_CMD_ASSIGN_PORT 23 /* allocate HCA and port */
423#define IPATH_CMD_USER_INIT 24 /* set up userspace */
401 424
402#define IPATH_CMD_MAX 21 425#define IPATH_CMD_MAX 24
403 426
404struct ipath_port_info { 427struct ipath_port_info {
405 __u32 num_active; /* number of active units */ 428 __u32 num_active; /* number of active units */
406 __u32 unit; /* unit (chip) assigned to caller */ 429 __u32 unit; /* unit (chip) assigned to caller */
407 __u32 port; /* port on unit assigned to caller */ 430 __u16 port; /* port on unit assigned to caller */
431 __u16 subport; /* subport on unit assigned to caller */
432 __u16 num_ports; /* number of ports available on unit */
433 __u16 num_subports; /* number of subport slaves opened on port */
408}; 434};
409 435
410struct ipath_tid_info { 436struct ipath_tid_info {
@@ -435,6 +461,8 @@ struct ipath_cmd {
435 __u32 recv_ctrl; 461 __u32 recv_ctrl;
436 /* partition key to set */ 462 /* partition key to set */
437 __u16 part_key; 463 __u16 part_key;
464 /* user address of __u32 bitmask of active slaves */
465 __u64 slave_mask_addr;
438 } cmd; 466 } cmd;
439}; 467};
440 468
@@ -596,6 +624,10 @@ struct infinipath_counters {
596 624
597/* K_PktFlags bits */ 625/* K_PktFlags bits */
598#define INFINIPATH_KPF_INTR 0x1 626#define INFINIPATH_KPF_INTR 0x1
627#define INFINIPATH_KPF_SUBPORT_MASK 0x3
628#define INFINIPATH_KPF_SUBPORT_SHIFT 1
629
630#define INFINIPATH_MAX_SUBPORT 4
599 631
600/* SendPIO per-buffer control */ 632/* SendPIO per-buffer control */
601#define INFINIPATH_SP_TEST 0x40 633#define INFINIPATH_SP_TEST 0x40
@@ -610,7 +642,7 @@ struct ipath_header {
610 /* 642 /*
611 * Version - 4 bits, Port - 4 bits, TID - 10 bits and Offset - 643 * Version - 4 bits, Port - 4 bits, TID - 10 bits and Offset -
612 * 14 bits before ECO change ~28 Dec 03. After that, Vers 4, 644 * 14 bits before ECO change ~28 Dec 03. After that, Vers 4,
613 * Port 3, TID 11, offset 14. 645 * Port 4, TID 11, offset 13.
614 */ 646 */
615 __le32 ver_port_tid_offset; 647 __le32 ver_port_tid_offset;
616 __le16 chksum; 648 __le16 chksum;
diff --git a/drivers/infiniband/hw/ipath/ipath_cq.c b/drivers/infiniband/hw/ipath/ipath_cq.c
index 049221bc590e..87462e0cb4d2 100644
--- a/drivers/infiniband/hw/ipath/ipath_cq.c
+++ b/drivers/infiniband/hw/ipath/ipath_cq.c
@@ -46,7 +46,7 @@
46 */ 46 */
47void ipath_cq_enter(struct ipath_cq *cq, struct ib_wc *entry, int solicited) 47void ipath_cq_enter(struct ipath_cq *cq, struct ib_wc *entry, int solicited)
48{ 48{
49 struct ipath_cq_wc *wc = cq->queue; 49 struct ipath_cq_wc *wc;
50 unsigned long flags; 50 unsigned long flags;
51 u32 head; 51 u32 head;
52 u32 next; 52 u32 next;
@@ -57,6 +57,7 @@ void ipath_cq_enter(struct ipath_cq *cq, struct ib_wc *entry, int solicited)
57 * Note that the head pointer might be writable by user processes. 57 * Note that the head pointer might be writable by user processes.
58 * Take care to verify it is a sane value. 58 * Take care to verify it is a sane value.
59 */ 59 */
60 wc = cq->queue;
60 head = wc->head; 61 head = wc->head;
61 if (head >= (unsigned) cq->ibcq.cqe) { 62 if (head >= (unsigned) cq->ibcq.cqe) {
62 head = cq->ibcq.cqe; 63 head = cq->ibcq.cqe;
@@ -109,21 +110,27 @@ void ipath_cq_enter(struct ipath_cq *cq, struct ib_wc *entry, int solicited)
109int ipath_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry) 110int ipath_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry)
110{ 111{
111 struct ipath_cq *cq = to_icq(ibcq); 112 struct ipath_cq *cq = to_icq(ibcq);
112 struct ipath_cq_wc *wc = cq->queue; 113 struct ipath_cq_wc *wc;
113 unsigned long flags; 114 unsigned long flags;
114 int npolled; 115 int npolled;
116 u32 tail;
115 117
116 spin_lock_irqsave(&cq->lock, flags); 118 spin_lock_irqsave(&cq->lock, flags);
117 119
120 wc = cq->queue;
121 tail = wc->tail;
122 if (tail > (u32) cq->ibcq.cqe)
123 tail = (u32) cq->ibcq.cqe;
118 for (npolled = 0; npolled < num_entries; ++npolled, ++entry) { 124 for (npolled = 0; npolled < num_entries; ++npolled, ++entry) {
119 if (wc->tail == wc->head) 125 if (tail == wc->head)
120 break; 126 break;
121 *entry = wc->queue[wc->tail]; 127 *entry = wc->queue[tail];
122 if (wc->tail >= cq->ibcq.cqe) 128 if (tail >= cq->ibcq.cqe)
123 wc->tail = 0; 129 tail = 0;
124 else 130 else
125 wc->tail++; 131 tail++;
126 } 132 }
133 wc->tail = tail;
127 134
128 spin_unlock_irqrestore(&cq->lock, flags); 135 spin_unlock_irqrestore(&cq->lock, flags);
129 136
@@ -177,11 +184,6 @@ struct ib_cq *ipath_create_cq(struct ib_device *ibdev, int entries,
177 goto done; 184 goto done;
178 } 185 }
179 186
180 if (dev->n_cqs_allocated == ib_ipath_max_cqs) {
181 ret = ERR_PTR(-ENOMEM);
182 goto done;
183 }
184
185 /* Allocate the completion queue structure. */ 187 /* Allocate the completion queue structure. */
186 cq = kmalloc(sizeof(*cq), GFP_KERNEL); 188 cq = kmalloc(sizeof(*cq), GFP_KERNEL);
187 if (!cq) { 189 if (!cq) {
@@ -237,6 +239,16 @@ struct ib_cq *ipath_create_cq(struct ib_device *ibdev, int entries,
237 } else 239 } else
238 cq->ip = NULL; 240 cq->ip = NULL;
239 241
242 spin_lock(&dev->n_cqs_lock);
243 if (dev->n_cqs_allocated == ib_ipath_max_cqs) {
244 spin_unlock(&dev->n_cqs_lock);
245 ret = ERR_PTR(-ENOMEM);
246 goto bail_wc;
247 }
248
249 dev->n_cqs_allocated++;
250 spin_unlock(&dev->n_cqs_lock);
251
240 /* 252 /*
241 * ib_create_cq() will initialize cq->ibcq except for cq->ibcq.cqe. 253 * ib_create_cq() will initialize cq->ibcq except for cq->ibcq.cqe.
242 * The number of entries should be >= the number requested or return 254 * The number of entries should be >= the number requested or return
@@ -253,7 +265,6 @@ struct ib_cq *ipath_create_cq(struct ib_device *ibdev, int entries,
253 265
254 ret = &cq->ibcq; 266 ret = &cq->ibcq;
255 267
256 dev->n_cqs_allocated++;
257 goto done; 268 goto done;
258 269
259bail_wc: 270bail_wc:
@@ -280,7 +291,9 @@ int ipath_destroy_cq(struct ib_cq *ibcq)
280 struct ipath_cq *cq = to_icq(ibcq); 291 struct ipath_cq *cq = to_icq(ibcq);
281 292
282 tasklet_kill(&cq->comptask); 293 tasklet_kill(&cq->comptask);
294 spin_lock(&dev->n_cqs_lock);
283 dev->n_cqs_allocated--; 295 dev->n_cqs_allocated--;
296 spin_unlock(&dev->n_cqs_lock);
284 if (cq->ip) 297 if (cq->ip)
285 kref_put(&cq->ip->ref, ipath_release_mmap_info); 298 kref_put(&cq->ip->ref, ipath_release_mmap_info);
286 else 299 else
@@ -316,10 +329,16 @@ int ipath_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify notify)
316 return 0; 329 return 0;
317} 330}
318 331
332/**
333 * ipath_resize_cq - change the size of the CQ
334 * @ibcq: the completion queue
335 *
336 * Returns 0 for success.
337 */
319int ipath_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata) 338int ipath_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
320{ 339{
321 struct ipath_cq *cq = to_icq(ibcq); 340 struct ipath_cq *cq = to_icq(ibcq);
322 struct ipath_cq_wc *old_wc = cq->queue; 341 struct ipath_cq_wc *old_wc;
323 struct ipath_cq_wc *wc; 342 struct ipath_cq_wc *wc;
324 u32 head, tail, n; 343 u32 head, tail, n;
325 int ret; 344 int ret;
@@ -355,6 +374,7 @@ int ipath_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
355 * Make sure head and tail are sane since they 374 * Make sure head and tail are sane since they
356 * might be user writable. 375 * might be user writable.
357 */ 376 */
377 old_wc = cq->queue;
358 head = old_wc->head; 378 head = old_wc->head;
359 if (head > (u32) cq->ibcq.cqe) 379 if (head > (u32) cq->ibcq.cqe)
360 head = (u32) cq->ibcq.cqe; 380 head = (u32) cq->ibcq.cqe;
diff --git a/drivers/infiniband/hw/ipath/ipath_driver.c b/drivers/infiniband/hw/ipath/ipath_driver.c
index 2108466c7e33..12cefa658f3b 100644
--- a/drivers/infiniband/hw/ipath/ipath_driver.c
+++ b/drivers/infiniband/hw/ipath/ipath_driver.c
@@ -95,16 +95,6 @@ const char *ipath_ibcstatus_str[] = {
95 "RecovIdle", 95 "RecovIdle",
96}; 96};
97 97
98/*
99 * These variables are initialized in the chip-specific files
100 * but are defined here.
101 */
102u16 ipath_gpio_sda_num, ipath_gpio_scl_num;
103u64 ipath_gpio_sda, ipath_gpio_scl;
104u64 infinipath_i_bitsextant;
105ipath_err_t infinipath_e_bitsextant, infinipath_hwe_bitsextant;
106u32 infinipath_i_rcvavail_mask, infinipath_i_rcvurg_mask;
107
108static void __devexit ipath_remove_one(struct pci_dev *); 98static void __devexit ipath_remove_one(struct pci_dev *);
109static int __devinit ipath_init_one(struct pci_dev *, 99static int __devinit ipath_init_one(struct pci_dev *,
110 const struct pci_device_id *); 100 const struct pci_device_id *);
@@ -527,28 +517,146 @@ bail:
527 return ret; 517 return ret;
528} 518}
529 519
520static void __devexit cleanup_device(struct ipath_devdata *dd)
521{
522 int port;
523
524 ipath_shutdown_device(dd);
525
526 if (*dd->ipath_statusp & IPATH_STATUS_CHIP_PRESENT) {
527 /* can't do anything more with chip; needs re-init */
528 *dd->ipath_statusp &= ~IPATH_STATUS_CHIP_PRESENT;
529 if (dd->ipath_kregbase) {
530 /*
531 * if we haven't already cleaned up before these are
532 * to ensure any register reads/writes "fail" until
533 * re-init
534 */
535 dd->ipath_kregbase = NULL;
536 dd->ipath_uregbase = 0;
537 dd->ipath_sregbase = 0;
538 dd->ipath_cregbase = 0;
539 dd->ipath_kregsize = 0;
540 }
541 ipath_disable_wc(dd);
542 }
543
544 if (dd->ipath_pioavailregs_dma) {
545 dma_free_coherent(&dd->pcidev->dev, PAGE_SIZE,
546 (void *) dd->ipath_pioavailregs_dma,
547 dd->ipath_pioavailregs_phys);
548 dd->ipath_pioavailregs_dma = NULL;
549 }
550 if (dd->ipath_dummy_hdrq) {
551 dma_free_coherent(&dd->pcidev->dev,
552 dd->ipath_pd[0]->port_rcvhdrq_size,
553 dd->ipath_dummy_hdrq, dd->ipath_dummy_hdrq_phys);
554 dd->ipath_dummy_hdrq = NULL;
555 }
556
557 if (dd->ipath_pageshadow) {
558 struct page **tmpp = dd->ipath_pageshadow;
559 dma_addr_t *tmpd = dd->ipath_physshadow;
560 int i, cnt = 0;
561
562 ipath_cdbg(VERBOSE, "Unlocking any expTID pages still "
563 "locked\n");
564 for (port = 0; port < dd->ipath_cfgports; port++) {
565 int port_tidbase = port * dd->ipath_rcvtidcnt;
566 int maxtid = port_tidbase + dd->ipath_rcvtidcnt;
567 for (i = port_tidbase; i < maxtid; i++) {
568 if (!tmpp[i])
569 continue;
570 pci_unmap_page(dd->pcidev, tmpd[i],
571 PAGE_SIZE, PCI_DMA_FROMDEVICE);
572 ipath_release_user_pages(&tmpp[i], 1);
573 tmpp[i] = NULL;
574 cnt++;
575 }
576 }
577 if (cnt) {
578 ipath_stats.sps_pageunlocks += cnt;
579 ipath_cdbg(VERBOSE, "There were still %u expTID "
580 "entries locked\n", cnt);
581 }
582 if (ipath_stats.sps_pagelocks ||
583 ipath_stats.sps_pageunlocks)
584 ipath_cdbg(VERBOSE, "%llu pages locked, %llu "
585 "unlocked via ipath_m{un}lock\n",
586 (unsigned long long)
587 ipath_stats.sps_pagelocks,
588 (unsigned long long)
589 ipath_stats.sps_pageunlocks);
590
591 ipath_cdbg(VERBOSE, "Free shadow page tid array at %p\n",
592 dd->ipath_pageshadow);
593 vfree(dd->ipath_pageshadow);
594 dd->ipath_pageshadow = NULL;
595 }
596
597 /*
598 * free any resources still in use (usually just kernel ports)
599 * at unload; we do for portcnt, not cfgports, because cfgports
600 * could have changed while we were loaded.
601 */
602 for (port = 0; port < dd->ipath_portcnt; port++) {
603 struct ipath_portdata *pd = dd->ipath_pd[port];
604 dd->ipath_pd[port] = NULL;
605 ipath_free_pddata(dd, pd);
606 }
607 kfree(dd->ipath_pd);
608 /*
609 * debuggability, in case some cleanup path tries to use it
610 * after this
611 */
612 dd->ipath_pd = NULL;
613}
614
530static void __devexit ipath_remove_one(struct pci_dev *pdev) 615static void __devexit ipath_remove_one(struct pci_dev *pdev)
531{ 616{
532 struct ipath_devdata *dd; 617 struct ipath_devdata *dd = pci_get_drvdata(pdev);
533 618
534 ipath_cdbg(VERBOSE, "removing, pdev=%p\n", pdev); 619 ipath_cdbg(VERBOSE, "removing, pdev=%p, dd=%p\n", pdev, dd);
535 if (!pdev) 620
536 return; 621 if (dd->verbs_dev)
622 ipath_unregister_ib_device(dd->verbs_dev);
537 623
538 dd = pci_get_drvdata(pdev);
539 ipath_unregister_ib_device(dd->verbs_dev);
540 ipath_diag_remove(dd); 624 ipath_diag_remove(dd);
541 ipath_user_remove(dd); 625 ipath_user_remove(dd);
542 ipathfs_remove_device(dd); 626 ipathfs_remove_device(dd);
543 ipath_device_remove_group(&pdev->dev, dd); 627 ipath_device_remove_group(&pdev->dev, dd);
628
544 ipath_cdbg(VERBOSE, "Releasing pci memory regions, dd %p, " 629 ipath_cdbg(VERBOSE, "Releasing pci memory regions, dd %p, "
545 "unit %u\n", dd, (u32) dd->ipath_unit); 630 "unit %u\n", dd, (u32) dd->ipath_unit);
546 if (dd->ipath_kregbase) { 631
547 ipath_cdbg(VERBOSE, "Unmapping kregbase %p\n", 632 cleanup_device(dd);
548 dd->ipath_kregbase); 633
549 iounmap((volatile void __iomem *) dd->ipath_kregbase); 634 /*
550 dd->ipath_kregbase = NULL; 635 * turn off rcv, send, and interrupts for all ports, all drivers
551 } 636 * should also hard reset the chip here?
637 * free up port 0 (kernel) rcvhdr, egr bufs, and eventually tid bufs
638 * for all versions of the driver, if they were allocated
639 */
640 if (pdev->irq) {
641 ipath_cdbg(VERBOSE,
642 "unit %u free_irq of irq %x\n",
643 dd->ipath_unit, pdev->irq);
644 free_irq(pdev->irq, dd);
645 } else
646 ipath_dbg("irq is 0, not doing free_irq "
647 "for unit %u\n", dd->ipath_unit);
648 /*
649 * we check for NULL here, because it's outside
650 * the kregbase check, and we need to call it
651 * after the free_irq. Thus it's possible that
652 * the function pointers were never initialized.
653 */
654 if (dd->ipath_f_cleanup)
655 /* clean up chip-specific stuff */
656 dd->ipath_f_cleanup(dd);
657
658 ipath_cdbg(VERBOSE, "Unmapping kregbase %p\n", dd->ipath_kregbase);
659 iounmap((volatile void __iomem *) dd->ipath_kregbase);
552 pci_release_regions(pdev); 660 pci_release_regions(pdev);
553 ipath_cdbg(VERBOSE, "calling pci_disable_device\n"); 661 ipath_cdbg(VERBOSE, "calling pci_disable_device\n");
554 pci_disable_device(pdev); 662 pci_disable_device(pdev);
@@ -760,8 +868,8 @@ static void get_rhf_errstring(u32 err, char *msg, size_t len)
760static inline void *ipath_get_egrbuf(struct ipath_devdata *dd, u32 bufnum, 868static inline void *ipath_get_egrbuf(struct ipath_devdata *dd, u32 bufnum,
761 int err) 869 int err)
762{ 870{
763 return dd->ipath_port0_skbs ? 871 return dd->ipath_port0_skbinfo ?
764 (void *)dd->ipath_port0_skbs[bufnum]->data : NULL; 872 (void *) dd->ipath_port0_skbinfo[bufnum].skb->data : NULL;
765} 873}
766 874
767/** 875/**
@@ -783,31 +891,34 @@ struct sk_buff *ipath_alloc_skb(struct ipath_devdata *dd,
783 */ 891 */
784 892
785 /* 893 /*
786 * We need 4 extra bytes for unaligned transfer copying 894 * We need 2 extra bytes for ipath_ether data sent in the
895 * key header. In order to keep everything dword aligned,
896 * we'll reserve 4 bytes.
787 */ 897 */
898 len = dd->ipath_ibmaxlen + 4;
899
788 if (dd->ipath_flags & IPATH_4BYTE_TID) { 900 if (dd->ipath_flags & IPATH_4BYTE_TID) {
789 /* we need a 4KB multiple alignment, and there is no way 901 /* We need a 2KB multiple alignment, and there is no way
790 * to do it except to allocate extra and then skb_reserve 902 * to do it except to allocate extra and then skb_reserve
791 * enough to bring it up to the right alignment. 903 * enough to bring it up to the right alignment.
792 */ 904 */
793 len = dd->ipath_ibmaxlen + 4 + (1 << 11) - 1; 905 len += 2047;
794 } 906 }
795 else 907
796 len = dd->ipath_ibmaxlen + 4;
797 skb = __dev_alloc_skb(len, gfp_mask); 908 skb = __dev_alloc_skb(len, gfp_mask);
798 if (!skb) { 909 if (!skb) {
799 ipath_dev_err(dd, "Failed to allocate skbuff, length %u\n", 910 ipath_dev_err(dd, "Failed to allocate skbuff, length %u\n",
800 len); 911 len);
801 goto bail; 912 goto bail;
802 } 913 }
914
915 skb_reserve(skb, 4);
916
803 if (dd->ipath_flags & IPATH_4BYTE_TID) { 917 if (dd->ipath_flags & IPATH_4BYTE_TID) {
804 u32 una = ((1 << 11) - 1) & (unsigned long)(skb->data + 4); 918 u32 una = (unsigned long)skb->data & 2047;
805 if (una) 919 if (una)
806 skb_reserve(skb, 4 + (1 << 11) - una); 920 skb_reserve(skb, 2048 - una);
807 else 921 }
808 skb_reserve(skb, 4);
809 } else
810 skb_reserve(skb, 4);
811 922
812bail: 923bail:
813 return skb; 924 return skb;
@@ -1326,6 +1437,9 @@ int ipath_create_rcvhdrq(struct ipath_devdata *dd,
1326 "for port %u rcvhdrqtailaddr failed\n", 1437 "for port %u rcvhdrqtailaddr failed\n",
1327 pd->port_port); 1438 pd->port_port);
1328 ret = -ENOMEM; 1439 ret = -ENOMEM;
1440 dma_free_coherent(&dd->pcidev->dev, amt,
1441 pd->port_rcvhdrq, pd->port_rcvhdrq_phys);
1442 pd->port_rcvhdrq = NULL;
1329 goto bail; 1443 goto bail;
1330 } 1444 }
1331 pd->port_rcvhdrqtailaddr_phys = phys_hdrqtail; 1445 pd->port_rcvhdrqtailaddr_phys = phys_hdrqtail;
@@ -1347,12 +1461,13 @@ int ipath_create_rcvhdrq(struct ipath_devdata *dd,
1347 ipath_cdbg(VERBOSE, "reuse port %d rcvhdrq @%p %llx phys; " 1461 ipath_cdbg(VERBOSE, "reuse port %d rcvhdrq @%p %llx phys; "
1348 "hdrtailaddr@%p %llx physical\n", 1462 "hdrtailaddr@%p %llx physical\n",
1349 pd->port_port, pd->port_rcvhdrq, 1463 pd->port_port, pd->port_rcvhdrq,
1350 pd->port_rcvhdrq_phys, pd->port_rcvhdrtail_kvaddr, 1464 (unsigned long long) pd->port_rcvhdrq_phys,
1351 (unsigned long long)pd->port_rcvhdrqtailaddr_phys); 1465 pd->port_rcvhdrtail_kvaddr, (unsigned long long)
1466 pd->port_rcvhdrqtailaddr_phys);
1352 1467
1353 /* clear for security and sanity on each use */ 1468 /* clear for security and sanity on each use */
1354 memset(pd->port_rcvhdrq, 0, pd->port_rcvhdrq_size); 1469 memset(pd->port_rcvhdrq, 0, pd->port_rcvhdrq_size);
1355 memset((void *)pd->port_rcvhdrtail_kvaddr, 0, PAGE_SIZE); 1470 memset(pd->port_rcvhdrtail_kvaddr, 0, PAGE_SIZE);
1356 1471
1357 /* 1472 /*
1358 * tell chip each time we init it, even if we are re-using previous 1473 * tell chip each time we init it, even if we are re-using previous
@@ -1805,7 +1920,7 @@ void ipath_free_pddata(struct ipath_devdata *dd, struct ipath_portdata *pd)
1805 pd->port_rcvhdrq = NULL; 1920 pd->port_rcvhdrq = NULL;
1806 if (pd->port_rcvhdrtail_kvaddr) { 1921 if (pd->port_rcvhdrtail_kvaddr) {
1807 dma_free_coherent(&dd->pcidev->dev, PAGE_SIZE, 1922 dma_free_coherent(&dd->pcidev->dev, PAGE_SIZE,
1808 (void *)pd->port_rcvhdrtail_kvaddr, 1923 pd->port_rcvhdrtail_kvaddr,
1809 pd->port_rcvhdrqtailaddr_phys); 1924 pd->port_rcvhdrqtailaddr_phys);
1810 pd->port_rcvhdrtail_kvaddr = NULL; 1925 pd->port_rcvhdrtail_kvaddr = NULL;
1811 } 1926 }
@@ -1824,24 +1939,32 @@ void ipath_free_pddata(struct ipath_devdata *dd, struct ipath_portdata *pd)
1824 dma_free_coherent(&dd->pcidev->dev, size, 1939 dma_free_coherent(&dd->pcidev->dev, size,
1825 base, pd->port_rcvegrbuf_phys[e]); 1940 base, pd->port_rcvegrbuf_phys[e]);
1826 } 1941 }
1827 vfree(pd->port_rcvegrbuf); 1942 kfree(pd->port_rcvegrbuf);
1828 pd->port_rcvegrbuf = NULL; 1943 pd->port_rcvegrbuf = NULL;
1829 vfree(pd->port_rcvegrbuf_phys); 1944 kfree(pd->port_rcvegrbuf_phys);
1830 pd->port_rcvegrbuf_phys = NULL; 1945 pd->port_rcvegrbuf_phys = NULL;
1831 pd->port_rcvegrbuf_chunks = 0; 1946 pd->port_rcvegrbuf_chunks = 0;
1832 } else if (pd->port_port == 0 && dd->ipath_port0_skbs) { 1947 } else if (pd->port_port == 0 && dd->ipath_port0_skbinfo) {
1833 unsigned e; 1948 unsigned e;
1834 struct sk_buff **skbs = dd->ipath_port0_skbs; 1949 struct ipath_skbinfo *skbinfo = dd->ipath_port0_skbinfo;
1835 1950
1836 dd->ipath_port0_skbs = NULL; 1951 dd->ipath_port0_skbinfo = NULL;
1837 ipath_cdbg(VERBOSE, "free closed port %d ipath_port0_skbs " 1952 ipath_cdbg(VERBOSE, "free closed port %d "
1838 "@ %p\n", pd->port_port, skbs); 1953 "ipath_port0_skbinfo @ %p\n", pd->port_port,
1954 skbinfo);
1839 for (e = 0; e < dd->ipath_rcvegrcnt; e++) 1955 for (e = 0; e < dd->ipath_rcvegrcnt; e++)
1840 if (skbs[e]) 1956 if (skbinfo[e].skb) {
1841 dev_kfree_skb(skbs[e]); 1957 pci_unmap_single(dd->pcidev, skbinfo[e].phys,
1842 vfree(skbs); 1958 dd->ipath_ibmaxlen,
1959 PCI_DMA_FROMDEVICE);
1960 dev_kfree_skb(skbinfo[e].skb);
1961 }
1962 vfree(skbinfo);
1843 } 1963 }
1844 kfree(pd->port_tid_pg_list); 1964 kfree(pd->port_tid_pg_list);
1965 vfree(pd->subport_uregbase);
1966 vfree(pd->subport_rcvegrbuf);
1967 vfree(pd->subport_rcvhdr_base);
1845 kfree(pd); 1968 kfree(pd);
1846} 1969}
1847 1970
@@ -1907,150 +2030,12 @@ bail:
1907 return ret; 2030 return ret;
1908} 2031}
1909 2032
1910static void cleanup_device(struct ipath_devdata *dd)
1911{
1912 int port;
1913
1914 ipath_shutdown_device(dd);
1915
1916 if (*dd->ipath_statusp & IPATH_STATUS_CHIP_PRESENT) {
1917 /* can't do anything more with chip; needs re-init */
1918 *dd->ipath_statusp &= ~IPATH_STATUS_CHIP_PRESENT;
1919 if (dd->ipath_kregbase) {
1920 /*
1921 * if we haven't already cleaned up before these are
1922 * to ensure any register reads/writes "fail" until
1923 * re-init
1924 */
1925 dd->ipath_kregbase = NULL;
1926 dd->ipath_uregbase = 0;
1927 dd->ipath_sregbase = 0;
1928 dd->ipath_cregbase = 0;
1929 dd->ipath_kregsize = 0;
1930 }
1931 ipath_disable_wc(dd);
1932 }
1933
1934 if (dd->ipath_pioavailregs_dma) {
1935 dma_free_coherent(&dd->pcidev->dev, PAGE_SIZE,
1936 (void *) dd->ipath_pioavailregs_dma,
1937 dd->ipath_pioavailregs_phys);
1938 dd->ipath_pioavailregs_dma = NULL;
1939 }
1940 if (dd->ipath_dummy_hdrq) {
1941 dma_free_coherent(&dd->pcidev->dev,
1942 dd->ipath_pd[0]->port_rcvhdrq_size,
1943 dd->ipath_dummy_hdrq, dd->ipath_dummy_hdrq_phys);
1944 dd->ipath_dummy_hdrq = NULL;
1945 }
1946
1947 if (dd->ipath_pageshadow) {
1948 struct page **tmpp = dd->ipath_pageshadow;
1949 int i, cnt = 0;
1950
1951 ipath_cdbg(VERBOSE, "Unlocking any expTID pages still "
1952 "locked\n");
1953 for (port = 0; port < dd->ipath_cfgports; port++) {
1954 int port_tidbase = port * dd->ipath_rcvtidcnt;
1955 int maxtid = port_tidbase + dd->ipath_rcvtidcnt;
1956 for (i = port_tidbase; i < maxtid; i++) {
1957 if (!tmpp[i])
1958 continue;
1959 ipath_release_user_pages(&tmpp[i], 1);
1960 tmpp[i] = NULL;
1961 cnt++;
1962 }
1963 }
1964 if (cnt) {
1965 ipath_stats.sps_pageunlocks += cnt;
1966 ipath_cdbg(VERBOSE, "There were still %u expTID "
1967 "entries locked\n", cnt);
1968 }
1969 if (ipath_stats.sps_pagelocks ||
1970 ipath_stats.sps_pageunlocks)
1971 ipath_cdbg(VERBOSE, "%llu pages locked, %llu "
1972 "unlocked via ipath_m{un}lock\n",
1973 (unsigned long long)
1974 ipath_stats.sps_pagelocks,
1975 (unsigned long long)
1976 ipath_stats.sps_pageunlocks);
1977
1978 ipath_cdbg(VERBOSE, "Free shadow page tid array at %p\n",
1979 dd->ipath_pageshadow);
1980 vfree(dd->ipath_pageshadow);
1981 dd->ipath_pageshadow = NULL;
1982 }
1983
1984 /*
1985 * free any resources still in use (usually just kernel ports)
1986 * at unload; we do for portcnt, not cfgports, because cfgports
1987 * could have changed while we were loaded.
1988 */
1989 for (port = 0; port < dd->ipath_portcnt; port++) {
1990 struct ipath_portdata *pd = dd->ipath_pd[port];
1991 dd->ipath_pd[port] = NULL;
1992 ipath_free_pddata(dd, pd);
1993 }
1994 kfree(dd->ipath_pd);
1995 /*
1996 * debuggability, in case some cleanup path tries to use it
1997 * after this
1998 */
1999 dd->ipath_pd = NULL;
2000}
2001
2002static void __exit infinipath_cleanup(void) 2033static void __exit infinipath_cleanup(void)
2003{ 2034{
2004 struct ipath_devdata *dd, *tmp;
2005 unsigned long flags;
2006
2007 ipath_diagpkt_remove();
2008
2009 ipath_exit_ipathfs(); 2035 ipath_exit_ipathfs();
2010 2036
2011 ipath_driver_remove_group(&ipath_driver.driver); 2037 ipath_driver_remove_group(&ipath_driver.driver);
2012 2038
2013 spin_lock_irqsave(&ipath_devs_lock, flags);
2014
2015 /*
2016 * turn off rcv, send, and interrupts for all ports, all drivers
2017 * should also hard reset the chip here?
2018 * free up port 0 (kernel) rcvhdr, egr bufs, and eventually tid bufs
2019 * for all versions of the driver, if they were allocated
2020 */
2021 list_for_each_entry_safe(dd, tmp, &ipath_dev_list, ipath_list) {
2022 spin_unlock_irqrestore(&ipath_devs_lock, flags);
2023
2024 if (dd->ipath_kregbase)
2025 cleanup_device(dd);
2026
2027 if (dd->pcidev) {
2028 if (dd->pcidev->irq) {
2029 ipath_cdbg(VERBOSE,
2030 "unit %u free_irq of irq %x\n",
2031 dd->ipath_unit, dd->pcidev->irq);
2032 free_irq(dd->pcidev->irq, dd);
2033 } else
2034 ipath_dbg("irq is 0, not doing free_irq "
2035 "for unit %u\n", dd->ipath_unit);
2036
2037 /*
2038 * we check for NULL here, because it's outside
2039 * the kregbase check, and we need to call it
2040 * after the free_irq. Thus it's possible that
2041 * the function pointers were never initialized.
2042 */
2043 if (dd->ipath_f_cleanup)
2044 /* clean up chip-specific stuff */
2045 dd->ipath_f_cleanup(dd);
2046
2047 dd->pcidev = NULL;
2048 }
2049 spin_lock_irqsave(&ipath_devs_lock, flags);
2050 }
2051
2052 spin_unlock_irqrestore(&ipath_devs_lock, flags);
2053
2054 ipath_cdbg(VERBOSE, "Unregistering pci driver\n"); 2039 ipath_cdbg(VERBOSE, "Unregistering pci driver\n");
2055 pci_unregister_driver(&ipath_driver); 2040 pci_unregister_driver(&ipath_driver);
2056 2041
diff --git a/drivers/infiniband/hw/ipath/ipath_eeprom.c b/drivers/infiniband/hw/ipath/ipath_eeprom.c
index 3313356ab93a..a4019a6b7560 100644
--- a/drivers/infiniband/hw/ipath/ipath_eeprom.c
+++ b/drivers/infiniband/hw/ipath/ipath_eeprom.c
@@ -100,9 +100,9 @@ static int i2c_gpio_set(struct ipath_devdata *dd,
100 gpioval = &dd->ipath_gpio_out; 100 gpioval = &dd->ipath_gpio_out;
101 read_val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extctrl); 101 read_val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extctrl);
102 if (line == i2c_line_scl) 102 if (line == i2c_line_scl)
103 mask = ipath_gpio_scl; 103 mask = dd->ipath_gpio_scl;
104 else 104 else
105 mask = ipath_gpio_sda; 105 mask = dd->ipath_gpio_sda;
106 106
107 if (new_line_state == i2c_line_high) 107 if (new_line_state == i2c_line_high)
108 /* tri-state the output rather than force high */ 108 /* tri-state the output rather than force high */
@@ -119,12 +119,12 @@ static int i2c_gpio_set(struct ipath_devdata *dd,
119 write_val = 0x0UL; 119 write_val = 0x0UL;
120 120
121 if (line == i2c_line_scl) { 121 if (line == i2c_line_scl) {
122 write_val <<= ipath_gpio_scl_num; 122 write_val <<= dd->ipath_gpio_scl_num;
123 *gpioval = *gpioval & ~(1UL << ipath_gpio_scl_num); 123 *gpioval = *gpioval & ~(1UL << dd->ipath_gpio_scl_num);
124 *gpioval |= write_val; 124 *gpioval |= write_val;
125 } else { 125 } else {
126 write_val <<= ipath_gpio_sda_num; 126 write_val <<= dd->ipath_gpio_sda_num;
127 *gpioval = *gpioval & ~(1UL << ipath_gpio_sda_num); 127 *gpioval = *gpioval & ~(1UL << dd->ipath_gpio_sda_num);
128 *gpioval |= write_val; 128 *gpioval |= write_val;
129 } 129 }
130 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_out, *gpioval); 130 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_out, *gpioval);
@@ -157,9 +157,9 @@ static int i2c_gpio_get(struct ipath_devdata *dd,
157 read_val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extctrl); 157 read_val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extctrl);
158 /* config line to be an input */ 158 /* config line to be an input */
159 if (line == i2c_line_scl) 159 if (line == i2c_line_scl)
160 mask = ipath_gpio_scl; 160 mask = dd->ipath_gpio_scl;
161 else 161 else
162 mask = ipath_gpio_sda; 162 mask = dd->ipath_gpio_sda;
163 write_val = read_val & ~mask; 163 write_val = read_val & ~mask;
164 ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, write_val); 164 ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, write_val);
165 read_val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus); 165 read_val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
@@ -187,6 +187,7 @@ bail:
187static void i2c_wait_for_writes(struct ipath_devdata *dd) 187static void i2c_wait_for_writes(struct ipath_devdata *dd)
188{ 188{
189 (void)ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch); 189 (void)ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
190 rmb();
190} 191}
191 192
192static void scl_out(struct ipath_devdata *dd, u8 bit) 193static void scl_out(struct ipath_devdata *dd, u8 bit)
diff --git a/drivers/infiniband/hw/ipath/ipath_file_ops.c b/drivers/infiniband/hw/ipath/ipath_file_ops.c
index 29930e22318e..a9ddc6911f66 100644
--- a/drivers/infiniband/hw/ipath/ipath_file_ops.c
+++ b/drivers/infiniband/hw/ipath/ipath_file_ops.c
@@ -41,6 +41,12 @@
41#include "ipath_kernel.h" 41#include "ipath_kernel.h"
42#include "ipath_common.h" 42#include "ipath_common.h"
43 43
44/*
45 * mmap64 doesn't allow all 64 bits for 32-bit applications
46 * so only use the low 43 bits.
47 */
48#define MMAP64_MASK 0x7FFFFFFFFFFUL
49
44static int ipath_open(struct inode *, struct file *); 50static int ipath_open(struct inode *, struct file *);
45static int ipath_close(struct inode *, struct file *); 51static int ipath_close(struct inode *, struct file *);
46static ssize_t ipath_write(struct file *, const char __user *, size_t, 52static ssize_t ipath_write(struct file *, const char __user *, size_t,
@@ -57,18 +63,35 @@ static struct file_operations ipath_file_ops = {
57 .mmap = ipath_mmap 63 .mmap = ipath_mmap
58}; 64};
59 65
60static int ipath_get_base_info(struct ipath_portdata *pd, 66static int ipath_get_base_info(struct file *fp,
61 void __user *ubase, size_t ubase_size) 67 void __user *ubase, size_t ubase_size)
62{ 68{
69 struct ipath_portdata *pd = port_fp(fp);
63 int ret = 0; 70 int ret = 0;
64 struct ipath_base_info *kinfo = NULL; 71 struct ipath_base_info *kinfo = NULL;
65 struct ipath_devdata *dd = pd->port_dd; 72 struct ipath_devdata *dd = pd->port_dd;
73 unsigned subport_cnt;
74 int shared, master;
75 size_t sz;
76
77 subport_cnt = pd->port_subport_cnt;
78 if (!subport_cnt) {
79 shared = 0;
80 master = 0;
81 subport_cnt = 1;
82 } else {
83 shared = 1;
84 master = !subport_fp(fp);
85 }
66 86
67 if (ubase_size < sizeof(*kinfo)) { 87 sz = sizeof(*kinfo);
88 /* If port sharing is not requested, allow the old size structure */
89 if (!shared)
90 sz -= 3 * sizeof(u64);
91 if (ubase_size < sz) {
68 ipath_cdbg(PROC, 92 ipath_cdbg(PROC,
69 "Base size %lu, need %lu (version mismatch?)\n", 93 "Base size %zu, need %zu (version mismatch?)\n",
70 (unsigned long) ubase_size, 94 ubase_size, sz);
71 (unsigned long) sizeof(*kinfo));
72 ret = -EINVAL; 95 ret = -EINVAL;
73 goto bail; 96 goto bail;
74 } 97 }
@@ -95,7 +118,9 @@ static int ipath_get_base_info(struct ipath_portdata *pd,
95 kinfo->spi_rcv_egrperchunk = pd->port_rcvegrbufs_perchunk; 118 kinfo->spi_rcv_egrperchunk = pd->port_rcvegrbufs_perchunk;
96 kinfo->spi_rcv_egrchunksize = kinfo->spi_rcv_egrbuftotlen / 119 kinfo->spi_rcv_egrchunksize = kinfo->spi_rcv_egrbuftotlen /
97 pd->port_rcvegrbuf_chunks; 120 pd->port_rcvegrbuf_chunks;
98 kinfo->spi_tidcnt = dd->ipath_rcvtidcnt; 121 kinfo->spi_tidcnt = dd->ipath_rcvtidcnt / subport_cnt;
122 if (master)
123 kinfo->spi_tidcnt += dd->ipath_rcvtidcnt % subport_cnt;
99 /* 124 /*
100 * for this use, may be ipath_cfgports summed over all chips that 125 * for this use, may be ipath_cfgports summed over all chips that
101 * are are configured and present 126 * are are configured and present
@@ -118,31 +143,75 @@ static int ipath_get_base_info(struct ipath_portdata *pd,
118 * page_address() macro worked, but in 2.6.11, even that returns the 143 * page_address() macro worked, but in 2.6.11, even that returns the
119 * full 64 bit address (upper bits all 1's). So far, using the 144 * full 64 bit address (upper bits all 1's). So far, using the
120 * physical addresses (or chip offsets, for chip mapping) works, but 145 * physical addresses (or chip offsets, for chip mapping) works, but
121 * no doubt some future kernel release will chang that, and we'll be 146 * no doubt some future kernel release will change that, and we'll be
122 * on to yet another method of dealing with this 147 * on to yet another method of dealing with this.
123 */ 148 */
124 kinfo->spi_rcvhdr_base = (u64) pd->port_rcvhdrq_phys; 149 kinfo->spi_rcvhdr_base = (u64) pd->port_rcvhdrq_phys;
125 kinfo->spi_rcvhdr_tailaddr = (u64)pd->port_rcvhdrqtailaddr_phys; 150 kinfo->spi_rcvhdr_tailaddr = (u64) pd->port_rcvhdrqtailaddr_phys;
126 kinfo->spi_rcv_egrbufs = (u64) pd->port_rcvegr_phys; 151 kinfo->spi_rcv_egrbufs = (u64) pd->port_rcvegr_phys;
127 kinfo->spi_pioavailaddr = (u64) dd->ipath_pioavailregs_phys; 152 kinfo->spi_pioavailaddr = (u64) dd->ipath_pioavailregs_phys;
128 kinfo->spi_status = (u64) kinfo->spi_pioavailaddr + 153 kinfo->spi_status = (u64) kinfo->spi_pioavailaddr +
129 (void *) dd->ipath_statusp - 154 (void *) dd->ipath_statusp -
130 (void *) dd->ipath_pioavailregs_dma; 155 (void *) dd->ipath_pioavailregs_dma;
131 kinfo->spi_piobufbase = (u64) pd->port_piobufs; 156 if (!shared) {
132 kinfo->__spi_uregbase = 157 kinfo->spi_piocnt = dd->ipath_pbufsport;
133 dd->ipath_uregbase + dd->ipath_palign * pd->port_port; 158 kinfo->spi_piobufbase = (u64) pd->port_piobufs;
159 kinfo->__spi_uregbase = (u64) dd->ipath_uregbase +
160 dd->ipath_palign * pd->port_port;
161 } else if (master) {
162 kinfo->spi_piocnt = (dd->ipath_pbufsport / subport_cnt) +
163 (dd->ipath_pbufsport % subport_cnt);
164 /* Master's PIO buffers are after all the slave's */
165 kinfo->spi_piobufbase = (u64) pd->port_piobufs +
166 dd->ipath_palign *
167 (dd->ipath_pbufsport - kinfo->spi_piocnt);
168 kinfo->__spi_uregbase = (u64) dd->ipath_uregbase +
169 dd->ipath_palign * pd->port_port;
170 } else {
171 unsigned slave = subport_fp(fp) - 1;
172
173 kinfo->spi_piocnt = dd->ipath_pbufsport / subport_cnt;
174 kinfo->spi_piobufbase = (u64) pd->port_piobufs +
175 dd->ipath_palign * kinfo->spi_piocnt * slave;
176 kinfo->__spi_uregbase = ((u64) pd->subport_uregbase +
177 PAGE_SIZE * slave) & MMAP64_MASK;
134 178
135 kinfo->spi_pioindex = dd->ipath_pbufsport * (pd->port_port - 1); 179 kinfo->spi_rcvhdr_base = ((u64) pd->subport_rcvhdr_base +
136 kinfo->spi_piocnt = dd->ipath_pbufsport; 180 pd->port_rcvhdrq_size * slave) & MMAP64_MASK;
181 kinfo->spi_rcvhdr_tailaddr =
182 (u64) pd->port_rcvhdrqtailaddr_phys & MMAP64_MASK;
183 kinfo->spi_rcv_egrbufs = ((u64) pd->subport_rcvegrbuf +
184 dd->ipath_rcvegrcnt * dd->ipath_rcvegrbufsize * slave) &
185 MMAP64_MASK;
186 }
187
188 kinfo->spi_pioindex = (kinfo->spi_piobufbase - dd->ipath_piobufbase) /
189 dd->ipath_palign;
137 kinfo->spi_pioalign = dd->ipath_palign; 190 kinfo->spi_pioalign = dd->ipath_palign;
138 191
139 kinfo->spi_qpair = IPATH_KD_QP; 192 kinfo->spi_qpair = IPATH_KD_QP;
140 kinfo->spi_piosize = dd->ipath_ibmaxlen; 193 kinfo->spi_piosize = dd->ipath_ibmaxlen;
141 kinfo->spi_mtu = dd->ipath_ibmaxlen; /* maxlen, not ibmtu */ 194 kinfo->spi_mtu = dd->ipath_ibmaxlen; /* maxlen, not ibmtu */
142 kinfo->spi_port = pd->port_port; 195 kinfo->spi_port = pd->port_port;
196 kinfo->spi_subport = subport_fp(fp);
143 kinfo->spi_sw_version = IPATH_KERN_SWVERSION; 197 kinfo->spi_sw_version = IPATH_KERN_SWVERSION;
144 kinfo->spi_hw_version = dd->ipath_revision; 198 kinfo->spi_hw_version = dd->ipath_revision;
145 199
200 if (master) {
201 kinfo->spi_runtime_flags |= IPATH_RUNTIME_MASTER;
202 kinfo->spi_subport_uregbase =
203 (u64) pd->subport_uregbase & MMAP64_MASK;
204 kinfo->spi_subport_rcvegrbuf =
205 (u64) pd->subport_rcvegrbuf & MMAP64_MASK;
206 kinfo->spi_subport_rcvhdr_base =
207 (u64) pd->subport_rcvhdr_base & MMAP64_MASK;
208 ipath_cdbg(PROC, "port %u flags %x %llx %llx %llx\n",
209 kinfo->spi_port, kinfo->spi_runtime_flags,
210 (unsigned long long) kinfo->spi_subport_uregbase,
211 (unsigned long long) kinfo->spi_subport_rcvegrbuf,
212 (unsigned long long) kinfo->spi_subport_rcvhdr_base);
213 }
214
146 if (copy_to_user(ubase, kinfo, sizeof(*kinfo))) 215 if (copy_to_user(ubase, kinfo, sizeof(*kinfo)))
147 ret = -EFAULT; 216 ret = -EFAULT;
148 217
@@ -154,6 +223,7 @@ bail:
154/** 223/**
155 * ipath_tid_update - update a port TID 224 * ipath_tid_update - update a port TID
156 * @pd: the port 225 * @pd: the port
226 * @fp: the ipath device file
157 * @ti: the TID information 227 * @ti: the TID information
158 * 228 *
159 * The new implementation as of Oct 2004 is that the driver assigns 229 * The new implementation as of Oct 2004 is that the driver assigns
@@ -176,11 +246,11 @@ bail:
176 * virtually contiguous pages, that should change to improve 246 * virtually contiguous pages, that should change to improve
177 * performance. 247 * performance.
178 */ 248 */
179static int ipath_tid_update(struct ipath_portdata *pd, 249static int ipath_tid_update(struct ipath_portdata *pd, struct file *fp,
180 const struct ipath_tid_info *ti) 250 const struct ipath_tid_info *ti)
181{ 251{
182 int ret = 0, ntids; 252 int ret = 0, ntids;
183 u32 tid, porttid, cnt, i, tidcnt; 253 u32 tid, porttid, cnt, i, tidcnt, tidoff;
184 u16 *tidlist; 254 u16 *tidlist;
185 struct ipath_devdata *dd = pd->port_dd; 255 struct ipath_devdata *dd = pd->port_dd;
186 u64 physaddr; 256 u64 physaddr;
@@ -188,6 +258,7 @@ static int ipath_tid_update(struct ipath_portdata *pd,
188 u64 __iomem *tidbase; 258 u64 __iomem *tidbase;
189 unsigned long tidmap[8]; 259 unsigned long tidmap[8];
190 struct page **pagep = NULL; 260 struct page **pagep = NULL;
261 unsigned subport = subport_fp(fp);
191 262
192 if (!dd->ipath_pageshadow) { 263 if (!dd->ipath_pageshadow) {
193 ret = -ENOMEM; 264 ret = -ENOMEM;
@@ -204,20 +275,34 @@ static int ipath_tid_update(struct ipath_portdata *pd,
204 ret = -EFAULT; 275 ret = -EFAULT;
205 goto done; 276 goto done;
206 } 277 }
207 tidcnt = dd->ipath_rcvtidcnt; 278 porttid = pd->port_port * dd->ipath_rcvtidcnt;
208 if (cnt >= tidcnt) { 279 if (!pd->port_subport_cnt) {
280 tidcnt = dd->ipath_rcvtidcnt;
281 tid = pd->port_tidcursor;
282 tidoff = 0;
283 } else if (!subport) {
284 tidcnt = (dd->ipath_rcvtidcnt / pd->port_subport_cnt) +
285 (dd->ipath_rcvtidcnt % pd->port_subport_cnt);
286 tidoff = dd->ipath_rcvtidcnt - tidcnt;
287 porttid += tidoff;
288 tid = tidcursor_fp(fp);
289 } else {
290 tidcnt = dd->ipath_rcvtidcnt / pd->port_subport_cnt;
291 tidoff = tidcnt * (subport - 1);
292 porttid += tidoff;
293 tid = tidcursor_fp(fp);
294 }
295 if (cnt > tidcnt) {
209 /* make sure it all fits in port_tid_pg_list */ 296 /* make sure it all fits in port_tid_pg_list */
210 dev_info(&dd->pcidev->dev, "Process tried to allocate %u " 297 dev_info(&dd->pcidev->dev, "Process tried to allocate %u "
211 "TIDs, only trying max (%u)\n", cnt, tidcnt); 298 "TIDs, only trying max (%u)\n", cnt, tidcnt);
212 cnt = tidcnt; 299 cnt = tidcnt;
213 } 300 }
214 pagep = (struct page **)pd->port_tid_pg_list; 301 pagep = &((struct page **) pd->port_tid_pg_list)[tidoff];
215 tidlist = (u16 *) (&pagep[cnt]); 302 tidlist = &((u16 *) &pagep[dd->ipath_rcvtidcnt])[tidoff];
216 303
217 memset(tidmap, 0, sizeof(tidmap)); 304 memset(tidmap, 0, sizeof(tidmap));
218 tid = pd->port_tidcursor;
219 /* before decrement; chip actual # */ 305 /* before decrement; chip actual # */
220 porttid = pd->port_port * tidcnt;
221 ntids = tidcnt; 306 ntids = tidcnt;
222 tidbase = (u64 __iomem *) (((char __iomem *) dd->ipath_kregbase) + 307 tidbase = (u64 __iomem *) (((char __iomem *) dd->ipath_kregbase) +
223 dd->ipath_rcvtidbase + 308 dd->ipath_rcvtidbase +
@@ -274,16 +359,19 @@ static int ipath_tid_update(struct ipath_portdata *pd,
274 ret = -ENOMEM; 359 ret = -ENOMEM;
275 break; 360 break;
276 } 361 }
277 tidlist[i] = tid; 362 tidlist[i] = tid + tidoff;
278 ipath_cdbg(VERBOSE, "Updating idx %u to TID %u, " 363 ipath_cdbg(VERBOSE, "Updating idx %u to TID %u, "
279 "vaddr %lx\n", i, tid, vaddr); 364 "vaddr %lx\n", i, tid + tidoff, vaddr);
280 /* we "know" system pages and TID pages are same size */ 365 /* we "know" system pages and TID pages are same size */
281 dd->ipath_pageshadow[porttid + tid] = pagep[i]; 366 dd->ipath_pageshadow[porttid + tid] = pagep[i];
367 dd->ipath_physshadow[porttid + tid] = ipath_map_page(
368 dd->pcidev, pagep[i], 0, PAGE_SIZE,
369 PCI_DMA_FROMDEVICE);
282 /* 370 /*
283 * don't need atomic or it's overhead 371 * don't need atomic or it's overhead
284 */ 372 */
285 __set_bit(tid, tidmap); 373 __set_bit(tid, tidmap);
286 physaddr = page_to_phys(pagep[i]); 374 physaddr = dd->ipath_physshadow[porttid + tid];
287 ipath_stats.sps_pagelocks++; 375 ipath_stats.sps_pagelocks++;
288 ipath_cdbg(VERBOSE, 376 ipath_cdbg(VERBOSE,
289 "TID %u, vaddr %lx, physaddr %llx pgp %p\n", 377 "TID %u, vaddr %lx, physaddr %llx pgp %p\n",
@@ -317,6 +405,9 @@ static int ipath_tid_update(struct ipath_portdata *pd,
317 tid); 405 tid);
318 dd->ipath_f_put_tid(dd, &tidbase[tid], 1, 406 dd->ipath_f_put_tid(dd, &tidbase[tid], 1,
319 dd->ipath_tidinvalid); 407 dd->ipath_tidinvalid);
408 pci_unmap_page(dd->pcidev,
409 dd->ipath_physshadow[porttid + tid],
410 PAGE_SIZE, PCI_DMA_FROMDEVICE);
320 dd->ipath_pageshadow[porttid + tid] = NULL; 411 dd->ipath_pageshadow[porttid + tid] = NULL;
321 ipath_stats.sps_pageunlocks++; 412 ipath_stats.sps_pageunlocks++;
322 } 413 }
@@ -341,7 +432,10 @@ static int ipath_tid_update(struct ipath_portdata *pd,
341 } 432 }
342 if (tid == tidcnt) 433 if (tid == tidcnt)
343 tid = 0; 434 tid = 0;
344 pd->port_tidcursor = tid; 435 if (!pd->port_subport_cnt)
436 pd->port_tidcursor = tid;
437 else
438 tidcursor_fp(fp) = tid;
345 } 439 }
346 440
347done: 441done:
@@ -354,6 +448,7 @@ done:
354/** 448/**
355 * ipath_tid_free - free a port TID 449 * ipath_tid_free - free a port TID
356 * @pd: the port 450 * @pd: the port
451 * @subport: the subport
357 * @ti: the TID info 452 * @ti: the TID info
358 * 453 *
359 * right now we are unlocking one page at a time, but since 454 * right now we are unlocking one page at a time, but since
@@ -367,7 +462,7 @@ done:
367 * they pass in to us. 462 * they pass in to us.
368 */ 463 */
369 464
370static int ipath_tid_free(struct ipath_portdata *pd, 465static int ipath_tid_free(struct ipath_portdata *pd, unsigned subport,
371 const struct ipath_tid_info *ti) 466 const struct ipath_tid_info *ti)
372{ 467{
373 int ret = 0; 468 int ret = 0;
@@ -388,11 +483,20 @@ static int ipath_tid_free(struct ipath_portdata *pd,
388 } 483 }
389 484
390 porttid = pd->port_port * dd->ipath_rcvtidcnt; 485 porttid = pd->port_port * dd->ipath_rcvtidcnt;
486 if (!pd->port_subport_cnt)
487 tidcnt = dd->ipath_rcvtidcnt;
488 else if (!subport) {
489 tidcnt = (dd->ipath_rcvtidcnt / pd->port_subport_cnt) +
490 (dd->ipath_rcvtidcnt % pd->port_subport_cnt);
491 porttid += dd->ipath_rcvtidcnt - tidcnt;
492 } else {
493 tidcnt = dd->ipath_rcvtidcnt / pd->port_subport_cnt;
494 porttid += tidcnt * (subport - 1);
495 }
391 tidbase = (u64 __iomem *) ((char __iomem *)(dd->ipath_kregbase) + 496 tidbase = (u64 __iomem *) ((char __iomem *)(dd->ipath_kregbase) +
392 dd->ipath_rcvtidbase + 497 dd->ipath_rcvtidbase +
393 porttid * sizeof(*tidbase)); 498 porttid * sizeof(*tidbase));
394 499
395 tidcnt = dd->ipath_rcvtidcnt;
396 limit = sizeof(tidmap) * BITS_PER_BYTE; 500 limit = sizeof(tidmap) * BITS_PER_BYTE;
397 if (limit > tidcnt) 501 if (limit > tidcnt)
398 /* just in case size changes in future */ 502 /* just in case size changes in future */
@@ -417,6 +521,9 @@ static int ipath_tid_free(struct ipath_portdata *pd,
417 pd->port_pid, tid); 521 pd->port_pid, tid);
418 dd->ipath_f_put_tid(dd, &tidbase[tid], 1, 522 dd->ipath_f_put_tid(dd, &tidbase[tid], 1,
419 dd->ipath_tidinvalid); 523 dd->ipath_tidinvalid);
524 pci_unmap_page(dd->pcidev,
525 dd->ipath_physshadow[porttid + tid],
526 PAGE_SIZE, PCI_DMA_FROMDEVICE);
420 ipath_release_user_pages( 527 ipath_release_user_pages(
421 &dd->ipath_pageshadow[porttid + tid], 1); 528 &dd->ipath_pageshadow[porttid + tid], 1);
422 dd->ipath_pageshadow[porttid + tid] = NULL; 529 dd->ipath_pageshadow[porttid + tid] = NULL;
@@ -581,20 +688,24 @@ bail:
581/** 688/**
582 * ipath_manage_rcvq - manage a port's receive queue 689 * ipath_manage_rcvq - manage a port's receive queue
583 * @pd: the port 690 * @pd: the port
691 * @subport: the subport
584 * @start_stop: action to carry out 692 * @start_stop: action to carry out
585 * 693 *
586 * start_stop == 0 disables receive on the port, for use in queue 694 * start_stop == 0 disables receive on the port, for use in queue
587 * overflow conditions. start_stop==1 re-enables, to be used to 695 * overflow conditions. start_stop==1 re-enables, to be used to
588 * re-init the software copy of the head register 696 * re-init the software copy of the head register
589 */ 697 */
590static int ipath_manage_rcvq(struct ipath_portdata *pd, int start_stop) 698static int ipath_manage_rcvq(struct ipath_portdata *pd, unsigned subport,
699 int start_stop)
591{ 700{
592 struct ipath_devdata *dd = pd->port_dd; 701 struct ipath_devdata *dd = pd->port_dd;
593 u64 tval; 702 u64 tval;
594 703
595 ipath_cdbg(PROC, "%sabling rcv for unit %u port %u\n", 704 ipath_cdbg(PROC, "%sabling rcv for unit %u port %u:%u\n",
596 start_stop ? "en" : "dis", dd->ipath_unit, 705 start_stop ? "en" : "dis", dd->ipath_unit,
597 pd->port_port); 706 pd->port_port, subport);
707 if (subport)
708 goto bail;
598 /* atomically clear receive enable port. */ 709 /* atomically clear receive enable port. */
599 if (start_stop) { 710 if (start_stop) {
600 /* 711 /*
@@ -609,7 +720,7 @@ static int ipath_manage_rcvq(struct ipath_portdata *pd, int start_stop)
609 * updated and correct itself, even in the face of software 720 * updated and correct itself, even in the face of software
610 * bugs. 721 * bugs.
611 */ 722 */
612 *pd->port_rcvhdrtail_kvaddr = 0; 723 *(volatile u64 *)pd->port_rcvhdrtail_kvaddr = 0;
613 set_bit(INFINIPATH_R_PORTENABLE_SHIFT + pd->port_port, 724 set_bit(INFINIPATH_R_PORTENABLE_SHIFT + pd->port_port,
614 &dd->ipath_rcvctrl); 725 &dd->ipath_rcvctrl);
615 } else 726 } else
@@ -630,6 +741,7 @@ static int ipath_manage_rcvq(struct ipath_portdata *pd, int start_stop)
630 tval = ipath_read_ureg32(dd, ur_rcvhdrtail, pd->port_port); 741 tval = ipath_read_ureg32(dd, ur_rcvhdrtail, pd->port_port);
631 } 742 }
632 /* always; new head should be equal to new tail; see above */ 743 /* always; new head should be equal to new tail; see above */
744bail:
633 return 0; 745 return 0;
634} 746}
635 747
@@ -687,6 +799,36 @@ static void ipath_clean_part_key(struct ipath_portdata *pd,
687 } 799 }
688} 800}
689 801
802/*
803 * Initialize the port data with the receive buffer sizes
804 * so this can be done while the master port is locked.
805 * Otherwise, there is a race with a slave opening the port
806 * and seeing these fields uninitialized.
807 */
808static void init_user_egr_sizes(struct ipath_portdata *pd)
809{
810 struct ipath_devdata *dd = pd->port_dd;
811 unsigned egrperchunk, egrcnt, size;
812
813 /*
814 * to avoid wasting a lot of memory, we allocate 32KB chunks of
815 * physically contiguous memory, advance through it until used up
816 * and then allocate more. Of course, we need memory to store those
817 * extra pointers, now. Started out with 256KB, but under heavy
818 * memory pressure (creating large files and then copying them over
819 * NFS while doing lots of MPI jobs), we hit some allocation
820 * failures, even though we can sleep... (2.6.10) Still get
821 * failures at 64K. 32K is the lowest we can go without wasting
822 * additional memory.
823 */
824 size = 0x8000;
825 egrperchunk = size / dd->ipath_rcvegrbufsize;
826 egrcnt = dd->ipath_rcvegrcnt;
827 pd->port_rcvegrbuf_chunks = (egrcnt + egrperchunk - 1) / egrperchunk;
828 pd->port_rcvegrbufs_perchunk = egrperchunk;
829 pd->port_rcvegrbuf_size = size;
830}
831
690/** 832/**
691 * ipath_create_user_egr - allocate eager TID buffers 833 * ipath_create_user_egr - allocate eager TID buffers
692 * @pd: the port to allocate TID buffers for 834 * @pd: the port to allocate TID buffers for
@@ -702,7 +844,7 @@ static void ipath_clean_part_key(struct ipath_portdata *pd,
702static int ipath_create_user_egr(struct ipath_portdata *pd) 844static int ipath_create_user_egr(struct ipath_portdata *pd)
703{ 845{
704 struct ipath_devdata *dd = pd->port_dd; 846 struct ipath_devdata *dd = pd->port_dd;
705 unsigned e, egrcnt, alloced, egrperchunk, chunk, egrsize, egroff; 847 unsigned e, egrcnt, egrperchunk, chunk, egrsize, egroff;
706 size_t size; 848 size_t size;
707 int ret; 849 int ret;
708 gfp_t gfp_flags; 850 gfp_t gfp_flags;
@@ -722,31 +864,18 @@ static int ipath_create_user_egr(struct ipath_portdata *pd)
722 ipath_cdbg(VERBOSE, "Allocating %d egr buffers, at egrtid " 864 ipath_cdbg(VERBOSE, "Allocating %d egr buffers, at egrtid "
723 "offset %x, egrsize %u\n", egrcnt, egroff, egrsize); 865 "offset %x, egrsize %u\n", egrcnt, egroff, egrsize);
724 866
725 /* 867 chunk = pd->port_rcvegrbuf_chunks;
726 * to avoid wasting a lot of memory, we allocate 32KB chunks of 868 egrperchunk = pd->port_rcvegrbufs_perchunk;
727 * physically contiguous memory, advance through it until used up 869 size = pd->port_rcvegrbuf_size;
728 * and then allocate more. Of course, we need memory to store those 870 pd->port_rcvegrbuf = kmalloc(chunk * sizeof(pd->port_rcvegrbuf[0]),
729 * extra pointers, now. Started out with 256KB, but under heavy 871 GFP_KERNEL);
730 * memory pressure (creating large files and then copying them over
731 * NFS while doing lots of MPI jobs), we hit some allocation
732 * failures, even though we can sleep... (2.6.10) Still get
733 * failures at 64K. 32K is the lowest we can go without wasting
734 * additional memory.
735 */
736 size = 0x8000;
737 alloced = ALIGN(egrsize * egrcnt, size);
738 egrperchunk = size / egrsize;
739 chunk = (egrcnt + egrperchunk - 1) / egrperchunk;
740 pd->port_rcvegrbuf_chunks = chunk;
741 pd->port_rcvegrbufs_perchunk = egrperchunk;
742 pd->port_rcvegrbuf_size = size;
743 pd->port_rcvegrbuf = vmalloc(chunk * sizeof(pd->port_rcvegrbuf[0]));
744 if (!pd->port_rcvegrbuf) { 872 if (!pd->port_rcvegrbuf) {
745 ret = -ENOMEM; 873 ret = -ENOMEM;
746 goto bail; 874 goto bail;
747 } 875 }
748 pd->port_rcvegrbuf_phys = 876 pd->port_rcvegrbuf_phys =
749 vmalloc(chunk * sizeof(pd->port_rcvegrbuf_phys[0])); 877 kmalloc(chunk * sizeof(pd->port_rcvegrbuf_phys[0]),
878 GFP_KERNEL);
750 if (!pd->port_rcvegrbuf_phys) { 879 if (!pd->port_rcvegrbuf_phys) {
751 ret = -ENOMEM; 880 ret = -ENOMEM;
752 goto bail_rcvegrbuf; 881 goto bail_rcvegrbuf;
@@ -791,105 +920,23 @@ bail_rcvegrbuf_phys:
791 pd->port_rcvegrbuf_phys[e]); 920 pd->port_rcvegrbuf_phys[e]);
792 921
793 } 922 }
794 vfree(pd->port_rcvegrbuf_phys); 923 kfree(pd->port_rcvegrbuf_phys);
795 pd->port_rcvegrbuf_phys = NULL; 924 pd->port_rcvegrbuf_phys = NULL;
796bail_rcvegrbuf: 925bail_rcvegrbuf:
797 vfree(pd->port_rcvegrbuf); 926 kfree(pd->port_rcvegrbuf);
798 pd->port_rcvegrbuf = NULL; 927 pd->port_rcvegrbuf = NULL;
799bail: 928bail:
800 return ret; 929 return ret;
801} 930}
802 931
803static int ipath_do_user_init(struct ipath_portdata *pd,
804 const struct ipath_user_info *uinfo)
805{
806 int ret = 0;
807 struct ipath_devdata *dd = pd->port_dd;
808 u32 head32;
809
810 /* for now, if major version is different, bail */
811 if ((uinfo->spu_userversion >> 16) != IPATH_USER_SWMAJOR) {
812 dev_info(&dd->pcidev->dev,
813 "User major version %d not same as driver "
814 "major %d\n", uinfo->spu_userversion >> 16,
815 IPATH_USER_SWMAJOR);
816 ret = -ENODEV;
817 goto done;
818 }
819
820 if ((uinfo->spu_userversion & 0xffff) != IPATH_USER_SWMINOR)
821 ipath_dbg("User minor version %d not same as driver "
822 "minor %d\n", uinfo->spu_userversion & 0xffff,
823 IPATH_USER_SWMINOR);
824
825 if (uinfo->spu_rcvhdrsize) {
826 ret = ipath_setrcvhdrsize(dd, uinfo->spu_rcvhdrsize);
827 if (ret)
828 goto done;
829 }
830
831 /* for now we do nothing with rcvhdrcnt: uinfo->spu_rcvhdrcnt */
832
833 /* for right now, kernel piobufs are at end, so port 1 is at 0 */
834 pd->port_piobufs = dd->ipath_piobufbase +
835 dd->ipath_pbufsport * (pd->port_port -
836 1) * dd->ipath_palign;
837 ipath_cdbg(VERBOSE, "Set base of piobufs for port %u to 0x%x\n",
838 pd->port_port, pd->port_piobufs);
839
840 /*
841 * Now allocate the rcvhdr Q and eager TIDs; skip the TID
842 * array for time being. If pd->port_port > chip-supported,
843 * we need to do extra stuff here to handle by handling overflow
844 * through port 0, someday
845 */
846 ret = ipath_create_rcvhdrq(dd, pd);
847 if (!ret)
848 ret = ipath_create_user_egr(pd);
849 if (ret)
850 goto done;
851
852 /*
853 * set the eager head register for this port to the current values
854 * of the tail pointers, since we don't know if they were
855 * updated on last use of the port.
856 */
857 head32 = ipath_read_ureg32(dd, ur_rcvegrindextail, pd->port_port);
858 ipath_write_ureg(dd, ur_rcvegrindexhead, head32, pd->port_port);
859 dd->ipath_lastegrheads[pd->port_port] = -1;
860 dd->ipath_lastrcvhdrqtails[pd->port_port] = -1;
861 ipath_cdbg(VERBOSE, "Wrote port%d egrhead %x from tail regs\n",
862 pd->port_port, head32);
863 pd->port_tidcursor = 0; /* start at beginning after open */
864 /*
865 * now enable the port; the tail registers will be written to memory
866 * by the chip as soon as it sees the write to
867 * dd->ipath_kregs->kr_rcvctrl. The update only happens on
868 * transition from 0 to 1, so clear it first, then set it as part of
869 * enabling the port. This will (very briefly) affect any other
870 * open ports, but it shouldn't be long enough to be an issue.
871 * We explictly set the in-memory copy to 0 beforehand, so we don't
872 * have to wait to be sure the DMA update has happened.
873 */
874 *pd->port_rcvhdrtail_kvaddr = 0ULL;
875 set_bit(INFINIPATH_R_PORTENABLE_SHIFT + pd->port_port,
876 &dd->ipath_rcvctrl);
877 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
878 dd->ipath_rcvctrl & ~INFINIPATH_R_TAILUPD);
879 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
880 dd->ipath_rcvctrl);
881done:
882 return ret;
883}
884
885 932
886/* common code for the mappings on dma_alloc_coherent mem */ 933/* common code for the mappings on dma_alloc_coherent mem */
887static int ipath_mmap_mem(struct vm_area_struct *vma, 934static int ipath_mmap_mem(struct vm_area_struct *vma,
888 struct ipath_portdata *pd, unsigned len, 935 struct ipath_portdata *pd, unsigned len, int write_ok,
889 int write_ok, dma_addr_t addr, char *what) 936 void *kvaddr, char *what)
890{ 937{
891 struct ipath_devdata *dd = pd->port_dd; 938 struct ipath_devdata *dd = pd->port_dd;
892 unsigned pfn = (unsigned long)addr >> PAGE_SHIFT; 939 unsigned long pfn;
893 int ret; 940 int ret;
894 941
895 if ((vma->vm_end - vma->vm_start) > len) { 942 if ((vma->vm_end - vma->vm_start) > len) {
@@ -912,17 +959,17 @@ static int ipath_mmap_mem(struct vm_area_struct *vma,
912 vma->vm_flags &= ~VM_MAYWRITE; 959 vma->vm_flags &= ~VM_MAYWRITE;
913 } 960 }
914 961
962 pfn = virt_to_phys(kvaddr) >> PAGE_SHIFT;
915 ret = remap_pfn_range(vma, vma->vm_start, pfn, 963 ret = remap_pfn_range(vma, vma->vm_start, pfn,
916 len, vma->vm_page_prot); 964 len, vma->vm_page_prot);
917 if (ret) 965 if (ret)
918 dev_info(&dd->pcidev->dev, 966 dev_info(&dd->pcidev->dev, "%s port%u mmap of %lx, %x "
919 "%s port%u mmap of %lx, %x bytes r%c failed: %d\n", 967 "bytes r%c failed: %d\n", what, pd->port_port,
920 what, pd->port_port, (unsigned long)addr, len, 968 pfn, len, write_ok?'w':'o', ret);
921 write_ok?'w':'o', ret);
922 else 969 else
923 ipath_cdbg(VERBOSE, "%s port%u mmaped %lx, %x bytes r%c\n", 970 ipath_cdbg(VERBOSE, "%s port%u mmaped %lx, %x bytes "
924 what, pd->port_port, (unsigned long)addr, len, 971 "r%c\n", what, pd->port_port, pfn, len,
925 write_ok?'w':'o'); 972 write_ok?'w':'o');
926bail: 973bail:
927 return ret; 974 return ret;
928} 975}
@@ -957,7 +1004,8 @@ static int mmap_ureg(struct vm_area_struct *vma, struct ipath_devdata *dd,
957 1004
958static int mmap_piobufs(struct vm_area_struct *vma, 1005static int mmap_piobufs(struct vm_area_struct *vma,
959 struct ipath_devdata *dd, 1006 struct ipath_devdata *dd,
960 struct ipath_portdata *pd) 1007 struct ipath_portdata *pd,
1008 unsigned piobufs, unsigned piocnt)
961{ 1009{
962 unsigned long phys; 1010 unsigned long phys;
963 int ret; 1011 int ret;
@@ -968,16 +1016,15 @@ static int mmap_piobufs(struct vm_area_struct *vma,
968 * process data, and catches users who might try to read the i/o 1016 * process data, and catches users who might try to read the i/o
969 * space due to a bug. 1017 * space due to a bug.
970 */ 1018 */
971 if ((vma->vm_end - vma->vm_start) > 1019 if ((vma->vm_end - vma->vm_start) > (piocnt * dd->ipath_palign)) {
972 (dd->ipath_pbufsport * dd->ipath_palign)) {
973 dev_info(&dd->pcidev->dev, "FAIL mmap piobufs: " 1020 dev_info(&dd->pcidev->dev, "FAIL mmap piobufs: "
974 "reqlen %lx > PAGE\n", 1021 "reqlen %lx > PAGE\n",
975 vma->vm_end - vma->vm_start); 1022 vma->vm_end - vma->vm_start);
976 ret = -EFAULT; 1023 ret = -EINVAL;
977 goto bail; 1024 goto bail;
978 } 1025 }
979 1026
980 phys = dd->ipath_physaddr + pd->port_piobufs; 1027 phys = dd->ipath_physaddr + piobufs;
981 1028
982 /* 1029 /*
983 * Don't mark this as non-cached, or we don't get the 1030 * Don't mark this as non-cached, or we don't get the
@@ -1011,7 +1058,7 @@ static int mmap_rcvegrbufs(struct vm_area_struct *vma,
1011 struct ipath_devdata *dd = pd->port_dd; 1058 struct ipath_devdata *dd = pd->port_dd;
1012 unsigned long start, size; 1059 unsigned long start, size;
1013 size_t total_size, i; 1060 size_t total_size, i;
1014 dma_addr_t *phys; 1061 unsigned long pfn;
1015 int ret; 1062 int ret;
1016 1063
1017 size = pd->port_rcvegrbuf_size; 1064 size = pd->port_rcvegrbuf_size;
@@ -1021,7 +1068,7 @@ static int mmap_rcvegrbufs(struct vm_area_struct *vma,
1021 "reqlen %lx > actual %lx\n", 1068 "reqlen %lx > actual %lx\n",
1022 vma->vm_end - vma->vm_start, 1069 vma->vm_end - vma->vm_start,
1023 (unsigned long) total_size); 1070 (unsigned long) total_size);
1024 ret = -EFAULT; 1071 ret = -EINVAL;
1025 goto bail; 1072 goto bail;
1026 } 1073 }
1027 1074
@@ -1035,11 +1082,11 @@ static int mmap_rcvegrbufs(struct vm_area_struct *vma,
1035 vma->vm_flags &= ~VM_MAYWRITE; 1082 vma->vm_flags &= ~VM_MAYWRITE;
1036 1083
1037 start = vma->vm_start; 1084 start = vma->vm_start;
1038 phys = pd->port_rcvegrbuf_phys;
1039 1085
1040 for (i = 0; i < pd->port_rcvegrbuf_chunks; i++, start += size) { 1086 for (i = 0; i < pd->port_rcvegrbuf_chunks; i++, start += size) {
1041 ret = remap_pfn_range(vma, start, phys[i] >> PAGE_SHIFT, 1087 pfn = virt_to_phys(pd->port_rcvegrbuf[i]) >> PAGE_SHIFT;
1042 size, vma->vm_page_prot); 1088 ret = remap_pfn_range(vma, start, pfn, size,
1089 vma->vm_page_prot);
1043 if (ret < 0) 1090 if (ret < 0)
1044 goto bail; 1091 goto bail;
1045 } 1092 }
@@ -1049,6 +1096,122 @@ bail:
1049 return ret; 1096 return ret;
1050} 1097}
1051 1098
1099/*
1100 * ipath_file_vma_nopage - handle a VMA page fault.
1101 */
1102static struct page *ipath_file_vma_nopage(struct vm_area_struct *vma,
1103 unsigned long address, int *type)
1104{
1105 unsigned long offset = address - vma->vm_start;
1106 struct page *page = NOPAGE_SIGBUS;
1107 void *pageptr;
1108
1109 /*
1110 * Convert the vmalloc address into a struct page.
1111 */
1112 pageptr = (void *)(offset + (vma->vm_pgoff << PAGE_SHIFT));
1113 page = vmalloc_to_page(pageptr);
1114 if (!page)
1115 goto out;
1116
1117 /* Increment the reference count. */
1118 get_page(page);
1119 if (type)
1120 *type = VM_FAULT_MINOR;
1121out:
1122 return page;
1123}
1124
1125static struct vm_operations_struct ipath_file_vm_ops = {
1126 .nopage = ipath_file_vma_nopage,
1127};
1128
1129static int mmap_kvaddr(struct vm_area_struct *vma, u64 pgaddr,
1130 struct ipath_portdata *pd, unsigned subport)
1131{
1132 unsigned long len;
1133 struct ipath_devdata *dd;
1134 void *addr;
1135 size_t size;
1136 int ret;
1137
1138 /* If the port is not shared, all addresses should be physical */
1139 if (!pd->port_subport_cnt) {
1140 ret = -EINVAL;
1141 goto bail;
1142 }
1143
1144 dd = pd->port_dd;
1145 size = pd->port_rcvegrbuf_chunks * pd->port_rcvegrbuf_size;
1146
1147 /*
1148 * Master has all the slave uregbase, rcvhdrq, and
1149 * rcvegrbufs mmapped.
1150 */
1151 if (subport == 0) {
1152 unsigned num_slaves = pd->port_subport_cnt - 1;
1153
1154 if (pgaddr == ((u64) pd->subport_uregbase & MMAP64_MASK)) {
1155 addr = pd->subport_uregbase;
1156 size = PAGE_SIZE * num_slaves;
1157 } else if (pgaddr == ((u64) pd->subport_rcvhdr_base &
1158 MMAP64_MASK)) {
1159 addr = pd->subport_rcvhdr_base;
1160 size = pd->port_rcvhdrq_size * num_slaves;
1161 } else if (pgaddr == ((u64) pd->subport_rcvegrbuf &
1162 MMAP64_MASK)) {
1163 addr = pd->subport_rcvegrbuf;
1164 size *= num_slaves;
1165 } else {
1166 ret = -EINVAL;
1167 goto bail;
1168 }
1169 } else if (pgaddr == (((u64) pd->subport_uregbase +
1170 PAGE_SIZE * (subport - 1)) & MMAP64_MASK)) {
1171 addr = pd->subport_uregbase + PAGE_SIZE * (subport - 1);
1172 size = PAGE_SIZE;
1173 } else if (pgaddr == (((u64) pd->subport_rcvhdr_base +
1174 pd->port_rcvhdrq_size * (subport - 1)) &
1175 MMAP64_MASK)) {
1176 addr = pd->subport_rcvhdr_base +
1177 pd->port_rcvhdrq_size * (subport - 1);
1178 size = pd->port_rcvhdrq_size;
1179 } else if (pgaddr == (((u64) pd->subport_rcvegrbuf +
1180 size * (subport - 1)) & MMAP64_MASK)) {
1181 addr = pd->subport_rcvegrbuf + size * (subport - 1);
1182 /* rcvegrbufs are read-only on the slave */
1183 if (vma->vm_flags & VM_WRITE) {
1184 dev_info(&dd->pcidev->dev,
1185 "Can't map eager buffers as "
1186 "writable (flags=%lx)\n", vma->vm_flags);
1187 ret = -EPERM;
1188 goto bail;
1189 }
1190 /*
1191 * Don't allow permission to later change to writeable
1192 * with mprotect.
1193 */
1194 vma->vm_flags &= ~VM_MAYWRITE;
1195 } else {
1196 ret = -EINVAL;
1197 goto bail;
1198 }
1199 len = vma->vm_end - vma->vm_start;
1200 if (len > size) {
1201 ipath_cdbg(MM, "FAIL: reqlen %lx > %zx\n", len, size);
1202 ret = -EINVAL;
1203 goto bail;
1204 }
1205
1206 vma->vm_pgoff = (unsigned long) addr >> PAGE_SHIFT;
1207 vma->vm_ops = &ipath_file_vm_ops;
1208 vma->vm_flags |= VM_RESERVED | VM_DONTEXPAND;
1209 ret = 0;
1210
1211bail:
1212 return ret;
1213}
1214
1052/** 1215/**
1053 * ipath_mmap - mmap various structures into user space 1216 * ipath_mmap - mmap various structures into user space
1054 * @fp: the file pointer 1217 * @fp: the file pointer
@@ -1064,73 +1227,99 @@ static int ipath_mmap(struct file *fp, struct vm_area_struct *vma)
1064 struct ipath_portdata *pd; 1227 struct ipath_portdata *pd;
1065 struct ipath_devdata *dd; 1228 struct ipath_devdata *dd;
1066 u64 pgaddr, ureg; 1229 u64 pgaddr, ureg;
1230 unsigned piobufs, piocnt;
1067 int ret; 1231 int ret;
1068 1232
1069 pd = port_fp(fp); 1233 pd = port_fp(fp);
1234 if (!pd) {
1235 ret = -EINVAL;
1236 goto bail;
1237 }
1070 dd = pd->port_dd; 1238 dd = pd->port_dd;
1071 1239
1072 /* 1240 /*
1073 * This is the ipath_do_user_init() code, mapping the shared buffers 1241 * This is the ipath_do_user_init() code, mapping the shared buffers
1074 * into the user process. The address referred to by vm_pgoff is the 1242 * into the user process. The address referred to by vm_pgoff is the
1075 * virtual, not physical, address; we only do one mmap for each 1243 * file offset passed via mmap(). For shared ports, this is the
1076 * space mapped. 1244 * kernel vmalloc() address of the pages to share with the master.
1245 * For non-shared or master ports, this is a physical address.
1246 * We only do one mmap for each space mapped.
1077 */ 1247 */
1078 pgaddr = vma->vm_pgoff << PAGE_SHIFT; 1248 pgaddr = vma->vm_pgoff << PAGE_SHIFT;
1079 1249
1080 /* 1250 /*
1081 * Must fit in 40 bits for our hardware; some checked elsewhere, 1251 * Check for 0 in case one of the allocations failed, but user
1082 * but we'll be paranoid. Check for 0 is mostly in case one of the 1252 * called mmap anyway.
1083 * allocations failed, but user called mmap anyway. We want to catch
1084 * that before it can match.
1085 */ 1253 */
1086 if (!pgaddr || pgaddr >= (1ULL<<40)) { 1254 if (!pgaddr) {
1087 ipath_dev_err(dd, "Bad phys addr %llx, start %lx, end %lx\n", 1255 ret = -EINVAL;
1088 (unsigned long long)pgaddr, vma->vm_start, vma->vm_end); 1256 goto bail;
1089 return -EINVAL;
1090 } 1257 }
1091 1258
1092 /* just the offset of the port user registers, not physical addr */ 1259 ipath_cdbg(MM, "pgaddr %llx vm_start=%lx len %lx port %u:%u:%u\n",
1093 ureg = dd->ipath_uregbase + dd->ipath_palign * pd->port_port;
1094
1095 ipath_cdbg(MM, "ushare: pgaddr %llx vm_start=%lx, vmlen %lx\n",
1096 (unsigned long long) pgaddr, vma->vm_start, 1260 (unsigned long long) pgaddr, vma->vm_start,
1097 vma->vm_end - vma->vm_start); 1261 vma->vm_end - vma->vm_start, dd->ipath_unit,
1262 pd->port_port, subport_fp(fp));
1098 1263
1099 if (vma->vm_start & (PAGE_SIZE-1)) { 1264 /*
1100 ipath_dev_err(dd, 1265 * Physical addresses must fit in 40 bits for our hardware.
1101 "vm_start not aligned: %lx, end=%lx phys %lx\n", 1266 * Check for kernel virtual addresses first, anything else must
1102 vma->vm_start, vma->vm_end, (unsigned long)pgaddr); 1267 * match a HW or memory address.
1103 ret = -EINVAL; 1268 */
1269 if (pgaddr >= (1ULL<<40)) {
1270 ret = mmap_kvaddr(vma, pgaddr, pd, subport_fp(fp));
1271 goto bail;
1104 } 1272 }
1105 else if (pgaddr == ureg) 1273
1274 if (!pd->port_subport_cnt) {
1275 /* port is not shared */
1276 ureg = dd->ipath_uregbase + dd->ipath_palign * pd->port_port;
1277 piocnt = dd->ipath_pbufsport;
1278 piobufs = pd->port_piobufs;
1279 } else if (!subport_fp(fp)) {
1280 /* caller is the master */
1281 ureg = dd->ipath_uregbase + dd->ipath_palign * pd->port_port;
1282 piocnt = (dd->ipath_pbufsport / pd->port_subport_cnt) +
1283 (dd->ipath_pbufsport % pd->port_subport_cnt);
1284 piobufs = pd->port_piobufs +
1285 dd->ipath_palign * (dd->ipath_pbufsport - piocnt);
1286 } else {
1287 unsigned slave = subport_fp(fp) - 1;
1288
1289 /* caller is a slave */
1290 ureg = 0;
1291 piocnt = dd->ipath_pbufsport / pd->port_subport_cnt;
1292 piobufs = pd->port_piobufs + dd->ipath_palign * piocnt * slave;
1293 }
1294
1295 if (pgaddr == ureg)
1106 ret = mmap_ureg(vma, dd, ureg); 1296 ret = mmap_ureg(vma, dd, ureg);
1107 else if (pgaddr == pd->port_piobufs) 1297 else if (pgaddr == piobufs)
1108 ret = mmap_piobufs(vma, dd, pd); 1298 ret = mmap_piobufs(vma, dd, pd, piobufs, piocnt);
1109 else if (pgaddr == (u64) pd->port_rcvegr_phys) 1299 else if (pgaddr == dd->ipath_pioavailregs_phys)
1300 /* in-memory copy of pioavail registers */
1301 ret = ipath_mmap_mem(vma, pd, PAGE_SIZE, 0,
1302 (void *) dd->ipath_pioavailregs_dma,
1303 "pioavail registers");
1304 else if (subport_fp(fp))
1305 /* Subports don't mmap the physical receive buffers */
1306 ret = -EINVAL;
1307 else if (pgaddr == pd->port_rcvegr_phys)
1110 ret = mmap_rcvegrbufs(vma, pd); 1308 ret = mmap_rcvegrbufs(vma, pd);
1111 else if (pgaddr == (u64) pd->port_rcvhdrq_phys) { 1309 else if (pgaddr == (u64) pd->port_rcvhdrq_phys)
1112 /* 1310 /*
1113 * The rcvhdrq itself; readonly except on HT (so have 1311 * The rcvhdrq itself; readonly except on HT (so have
1114 * to allow writable mapping), multiple pages, contiguous 1312 * to allow writable mapping), multiple pages, contiguous
1115 * from an i/o perspective. 1313 * from an i/o perspective.
1116 */ 1314 */
1117 unsigned total_size = 1315 ret = ipath_mmap_mem(vma, pd, pd->port_rcvhdrq_size, 1,
1118 ALIGN(dd->ipath_rcvhdrcnt * dd->ipath_rcvhdrentsize 1316 pd->port_rcvhdrq,
1119 * sizeof(u32), PAGE_SIZE);
1120 ret = ipath_mmap_mem(vma, pd, total_size, 1,
1121 pd->port_rcvhdrq_phys,
1122 "rcvhdrq"); 1317 "rcvhdrq");
1123 } 1318 else if (pgaddr == (u64) pd->port_rcvhdrqtailaddr_phys)
1124 else if (pgaddr == (u64)pd->port_rcvhdrqtailaddr_phys)
1125 /* in-memory copy of rcvhdrq tail register */ 1319 /* in-memory copy of rcvhdrq tail register */
1126 ret = ipath_mmap_mem(vma, pd, PAGE_SIZE, 0, 1320 ret = ipath_mmap_mem(vma, pd, PAGE_SIZE, 0,
1127 pd->port_rcvhdrqtailaddr_phys, 1321 pd->port_rcvhdrtail_kvaddr,
1128 "rcvhdrq tail"); 1322 "rcvhdrq tail");
1129 else if (pgaddr == dd->ipath_pioavailregs_phys)
1130 /* in-memory copy of pioavail registers */
1131 ret = ipath_mmap_mem(vma, pd, PAGE_SIZE, 0,
1132 dd->ipath_pioavailregs_phys,
1133 "pioavail registers");
1134 else 1323 else
1135 ret = -EINVAL; 1324 ret = -EINVAL;
1136 1325
@@ -1138,9 +1327,10 @@ static int ipath_mmap(struct file *fp, struct vm_area_struct *vma)
1138 1327
1139 if (ret < 0) 1328 if (ret < 0)
1140 dev_info(&dd->pcidev->dev, 1329 dev_info(&dd->pcidev->dev,
1141 "Failure %d on addr %lx, off %lx\n", 1330 "Failure %d on off %llx len %lx\n",
1142 -ret, vma->vm_start, vma->vm_pgoff); 1331 -ret, (unsigned long long)pgaddr,
1143 1332 vma->vm_end - vma->vm_start);
1333bail:
1144 return ret; 1334 return ret;
1145} 1335}
1146 1336
@@ -1154,6 +1344,8 @@ static unsigned int ipath_poll(struct file *fp,
1154 struct ipath_devdata *dd; 1344 struct ipath_devdata *dd;
1155 1345
1156 pd = port_fp(fp); 1346 pd = port_fp(fp);
1347 if (!pd)
1348 goto bail;
1157 dd = pd->port_dd; 1349 dd = pd->port_dd;
1158 1350
1159 bit = pd->port_port + INFINIPATH_R_INTRAVAIL_SHIFT; 1351 bit = pd->port_port + INFINIPATH_R_INTRAVAIL_SHIFT;
@@ -1176,7 +1368,7 @@ static unsigned int ipath_poll(struct file *fp,
1176 1368
1177 if (tail == head) { 1369 if (tail == head) {
1178 set_bit(IPATH_PORT_WAITING_RCV, &pd->port_flag); 1370 set_bit(IPATH_PORT_WAITING_RCV, &pd->port_flag);
1179 if(dd->ipath_rhdrhead_intr_off) /* arm rcv interrupt */ 1371 if (dd->ipath_rhdrhead_intr_off) /* arm rcv interrupt */
1180 (void)ipath_write_ureg(dd, ur_rcvhdrhead, 1372 (void)ipath_write_ureg(dd, ur_rcvhdrhead,
1181 dd->ipath_rhdrhead_intr_off 1373 dd->ipath_rhdrhead_intr_off
1182 | head, pd->port_port); 1374 | head, pd->port_port);
@@ -1200,18 +1392,80 @@ static unsigned int ipath_poll(struct file *fp,
1200 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl, 1392 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
1201 dd->ipath_rcvctrl); 1393 dd->ipath_rcvctrl);
1202 1394
1395bail:
1203 return pollflag; 1396 return pollflag;
1204} 1397}
1205 1398
1399static int init_subports(struct ipath_devdata *dd,
1400 struct ipath_portdata *pd,
1401 const struct ipath_user_info *uinfo)
1402{
1403 int ret = 0;
1404 unsigned num_slaves;
1405 size_t size;
1406
1407 /* Old user binaries don't know about subports */
1408 if ((uinfo->spu_userversion & 0xffff) != IPATH_USER_SWMINOR)
1409 goto bail;
1410 /*
1411 * If the user is requesting zero or one port,
1412 * skip the subport allocation.
1413 */
1414 if (uinfo->spu_subport_cnt <= 1)
1415 goto bail;
1416 if (uinfo->spu_subport_cnt > 4) {
1417 ret = -EINVAL;
1418 goto bail;
1419 }
1420
1421 num_slaves = uinfo->spu_subport_cnt - 1;
1422 pd->subport_uregbase = vmalloc(PAGE_SIZE * num_slaves);
1423 if (!pd->subport_uregbase) {
1424 ret = -ENOMEM;
1425 goto bail;
1426 }
1427 /* Note: pd->port_rcvhdrq_size isn't initialized yet. */
1428 size = ALIGN(dd->ipath_rcvhdrcnt * dd->ipath_rcvhdrentsize *
1429 sizeof(u32), PAGE_SIZE) * num_slaves;
1430 pd->subport_rcvhdr_base = vmalloc(size);
1431 if (!pd->subport_rcvhdr_base) {
1432 ret = -ENOMEM;
1433 goto bail_ureg;
1434 }
1435
1436 pd->subport_rcvegrbuf = vmalloc(pd->port_rcvegrbuf_chunks *
1437 pd->port_rcvegrbuf_size *
1438 num_slaves);
1439 if (!pd->subport_rcvegrbuf) {
1440 ret = -ENOMEM;
1441 goto bail_rhdr;
1442 }
1443
1444 pd->port_subport_cnt = uinfo->spu_subport_cnt;
1445 pd->port_subport_id = uinfo->spu_subport_id;
1446 pd->active_slaves = 1;
1447 goto bail;
1448
1449bail_rhdr:
1450 vfree(pd->subport_rcvhdr_base);
1451bail_ureg:
1452 vfree(pd->subport_uregbase);
1453 pd->subport_uregbase = NULL;
1454bail:
1455 return ret;
1456}
1457
1206static int try_alloc_port(struct ipath_devdata *dd, int port, 1458static int try_alloc_port(struct ipath_devdata *dd, int port,
1207 struct file *fp) 1459 struct file *fp,
1460 const struct ipath_user_info *uinfo)
1208{ 1461{
1462 struct ipath_portdata *pd;
1209 int ret; 1463 int ret;
1210 1464
1211 if (!dd->ipath_pd[port]) { 1465 if (!(pd = dd->ipath_pd[port])) {
1212 void *p, *ptmp; 1466 void *ptmp;
1213 1467
1214 p = kzalloc(sizeof(struct ipath_portdata), GFP_KERNEL); 1468 pd = kzalloc(sizeof(struct ipath_portdata), GFP_KERNEL);
1215 1469
1216 /* 1470 /*
1217 * Allocate memory for use in ipath_tid_update() just once 1471 * Allocate memory for use in ipath_tid_update() just once
@@ -1221,34 +1475,36 @@ static int try_alloc_port(struct ipath_devdata *dd, int port,
1221 ptmp = kmalloc(dd->ipath_rcvtidcnt * sizeof(u16) + 1475 ptmp = kmalloc(dd->ipath_rcvtidcnt * sizeof(u16) +
1222 dd->ipath_rcvtidcnt * sizeof(struct page **), 1476 dd->ipath_rcvtidcnt * sizeof(struct page **),
1223 GFP_KERNEL); 1477 GFP_KERNEL);
1224 if (!p || !ptmp) { 1478 if (!pd || !ptmp) {
1225 ipath_dev_err(dd, "Unable to allocate portdata " 1479 ipath_dev_err(dd, "Unable to allocate portdata "
1226 "memory, failing open\n"); 1480 "memory, failing open\n");
1227 ret = -ENOMEM; 1481 ret = -ENOMEM;
1228 kfree(p); 1482 kfree(pd);
1229 kfree(ptmp); 1483 kfree(ptmp);
1230 goto bail; 1484 goto bail;
1231 } 1485 }
1232 dd->ipath_pd[port] = p; 1486 dd->ipath_pd[port] = pd;
1233 dd->ipath_pd[port]->port_port = port; 1487 dd->ipath_pd[port]->port_port = port;
1234 dd->ipath_pd[port]->port_dd = dd; 1488 dd->ipath_pd[port]->port_dd = dd;
1235 dd->ipath_pd[port]->port_tid_pg_list = ptmp; 1489 dd->ipath_pd[port]->port_tid_pg_list = ptmp;
1236 init_waitqueue_head(&dd->ipath_pd[port]->port_wait); 1490 init_waitqueue_head(&dd->ipath_pd[port]->port_wait);
1237 } 1491 }
1238 if (!dd->ipath_pd[port]->port_cnt) { 1492 if (!pd->port_cnt) {
1239 dd->ipath_pd[port]->port_cnt = 1; 1493 pd->userversion = uinfo->spu_userversion;
1240 fp->private_data = (void *) dd->ipath_pd[port]; 1494 init_user_egr_sizes(pd);
1495 if ((ret = init_subports(dd, pd, uinfo)) != 0)
1496 goto bail;
1241 ipath_cdbg(PROC, "%s[%u] opened unit:port %u:%u\n", 1497 ipath_cdbg(PROC, "%s[%u] opened unit:port %u:%u\n",
1242 current->comm, current->pid, dd->ipath_unit, 1498 current->comm, current->pid, dd->ipath_unit,
1243 port); 1499 port);
1244 dd->ipath_pd[port]->port_pid = current->pid; 1500 pd->port_cnt = 1;
1245 strncpy(dd->ipath_pd[port]->port_comm, current->comm, 1501 port_fp(fp) = pd;
1246 sizeof(dd->ipath_pd[port]->port_comm)); 1502 pd->port_pid = current->pid;
1503 strncpy(pd->port_comm, current->comm, sizeof(pd->port_comm));
1247 ipath_stats.sps_ports++; 1504 ipath_stats.sps_ports++;
1248 ret = 0; 1505 ret = 0;
1249 goto bail; 1506 } else
1250 } 1507 ret = -EBUSY;
1251 ret = -EBUSY;
1252 1508
1253bail: 1509bail:
1254 return ret; 1510 return ret;
@@ -1264,7 +1520,8 @@ static inline int usable(struct ipath_devdata *dd)
1264 | IPATH_LINKUNK)); 1520 | IPATH_LINKUNK));
1265} 1521}
1266 1522
1267static int find_free_port(int unit, struct file *fp) 1523static int find_free_port(int unit, struct file *fp,
1524 const struct ipath_user_info *uinfo)
1268{ 1525{
1269 struct ipath_devdata *dd = ipath_lookup(unit); 1526 struct ipath_devdata *dd = ipath_lookup(unit);
1270 int ret, i; 1527 int ret, i;
@@ -1279,8 +1536,8 @@ static int find_free_port(int unit, struct file *fp)
1279 goto bail; 1536 goto bail;
1280 } 1537 }
1281 1538
1282 for (i = 0; i < dd->ipath_cfgports; i++) { 1539 for (i = 1; i < dd->ipath_cfgports; i++) {
1283 ret = try_alloc_port(dd, i, fp); 1540 ret = try_alloc_port(dd, i, fp, uinfo);
1284 if (ret != -EBUSY) 1541 if (ret != -EBUSY)
1285 goto bail; 1542 goto bail;
1286 } 1543 }
@@ -1290,13 +1547,14 @@ bail:
1290 return ret; 1547 return ret;
1291} 1548}
1292 1549
1293static int find_best_unit(struct file *fp) 1550static int find_best_unit(struct file *fp,
1551 const struct ipath_user_info *uinfo)
1294{ 1552{
1295 int ret = 0, i, prefunit = -1, devmax; 1553 int ret = 0, i, prefunit = -1, devmax;
1296 int maxofallports, npresent, nup; 1554 int maxofallports, npresent, nup;
1297 int ndev; 1555 int ndev;
1298 1556
1299 (void) ipath_count_units(&npresent, &nup, &maxofallports); 1557 devmax = ipath_count_units(&npresent, &nup, &maxofallports);
1300 1558
1301 /* 1559 /*
1302 * This code is present to allow a knowledgeable person to 1560 * This code is present to allow a knowledgeable person to
@@ -1343,8 +1601,6 @@ static int find_best_unit(struct file *fp)
1343 1601
1344 if (prefunit != -1) 1602 if (prefunit != -1)
1345 devmax = prefunit + 1; 1603 devmax = prefunit + 1;
1346 else
1347 devmax = ipath_count_units(NULL, NULL, NULL);
1348recheck: 1604recheck:
1349 for (i = 1; i < maxofallports; i++) { 1605 for (i = 1; i < maxofallports; i++) {
1350 for (ndev = prefunit != -1 ? prefunit : 0; ndev < devmax; 1606 for (ndev = prefunit != -1 ? prefunit : 0; ndev < devmax;
@@ -1359,7 +1615,7 @@ recheck:
1359 * next. 1615 * next.
1360 */ 1616 */
1361 continue; 1617 continue;
1362 ret = try_alloc_port(dd, i, fp); 1618 ret = try_alloc_port(dd, i, fp, uinfo);
1363 if (!ret) 1619 if (!ret)
1364 goto done; 1620 goto done;
1365 } 1621 }
@@ -1395,22 +1651,183 @@ done:
1395 return ret; 1651 return ret;
1396} 1652}
1397 1653
1654static int find_shared_port(struct file *fp,
1655 const struct ipath_user_info *uinfo)
1656{
1657 int devmax, ndev, i;
1658 int ret = 0;
1659
1660 devmax = ipath_count_units(NULL, NULL, NULL);
1661
1662 for (ndev = 0; ndev < devmax; ndev++) {
1663 struct ipath_devdata *dd = ipath_lookup(ndev);
1664
1665 if (!dd)
1666 continue;
1667 for (i = 1; i < dd->ipath_cfgports; i++) {
1668 struct ipath_portdata *pd = dd->ipath_pd[i];
1669
1670 /* Skip ports which are not yet open */
1671 if (!pd || !pd->port_cnt)
1672 continue;
1673 /* Skip port if it doesn't match the requested one */
1674 if (pd->port_subport_id != uinfo->spu_subport_id)
1675 continue;
1676 /* Verify the sharing process matches the master */
1677 if (pd->port_subport_cnt != uinfo->spu_subport_cnt ||
1678 pd->userversion != uinfo->spu_userversion ||
1679 pd->port_cnt >= pd->port_subport_cnt) {
1680 ret = -EINVAL;
1681 goto done;
1682 }
1683 port_fp(fp) = pd;
1684 subport_fp(fp) = pd->port_cnt++;
1685 tidcursor_fp(fp) = 0;
1686 pd->active_slaves |= 1 << subport_fp(fp);
1687 ipath_cdbg(PROC,
1688 "%s[%u] %u sharing %s[%u] unit:port %u:%u\n",
1689 current->comm, current->pid,
1690 subport_fp(fp),
1691 pd->port_comm, pd->port_pid,
1692 dd->ipath_unit, pd->port_port);
1693 ret = 1;
1694 goto done;
1695 }
1696 }
1697
1698done:
1699 return ret;
1700}
1701
1398static int ipath_open(struct inode *in, struct file *fp) 1702static int ipath_open(struct inode *in, struct file *fp)
1399{ 1703{
1400 int ret, user_minor; 1704 /* The real work is performed later in ipath_assign_port() */
1705 fp->private_data = kzalloc(sizeof(struct ipath_filedata), GFP_KERNEL);
1706 return fp->private_data ? 0 : -ENOMEM;
1707}
1708
1709
1710/* Get port early, so can set affinity prior to memory allocation */
1711static int ipath_assign_port(struct file *fp,
1712 const struct ipath_user_info *uinfo)
1713{
1714 int ret;
1715 int i_minor;
1716 unsigned swminor;
1717
1718 /* Check to be sure we haven't already initialized this file */
1719 if (port_fp(fp)) {
1720 ret = -EINVAL;
1721 goto done;
1722 }
1723
1724 /* for now, if major version is different, bail */
1725 if ((uinfo->spu_userversion >> 16) != IPATH_USER_SWMAJOR) {
1726 ipath_dbg("User major version %d not same as driver "
1727 "major %d\n", uinfo->spu_userversion >> 16,
1728 IPATH_USER_SWMAJOR);
1729 ret = -ENODEV;
1730 goto done;
1731 }
1732
1733 swminor = uinfo->spu_userversion & 0xffff;
1734 if (swminor != IPATH_USER_SWMINOR)
1735 ipath_dbg("User minor version %d not same as driver "
1736 "minor %d\n", swminor, IPATH_USER_SWMINOR);
1401 1737
1402 mutex_lock(&ipath_mutex); 1738 mutex_lock(&ipath_mutex);
1403 1739
1404 user_minor = iminor(in) - IPATH_USER_MINOR_BASE; 1740 if (swminor == IPATH_USER_SWMINOR && uinfo->spu_subport_cnt &&
1741 (ret = find_shared_port(fp, uinfo))) {
1742 mutex_unlock(&ipath_mutex);
1743 if (ret > 0)
1744 ret = 0;
1745 goto done;
1746 }
1747
1748 i_minor = iminor(fp->f_dentry->d_inode) - IPATH_USER_MINOR_BASE;
1405 ipath_cdbg(VERBOSE, "open on dev %lx (minor %d)\n", 1749 ipath_cdbg(VERBOSE, "open on dev %lx (minor %d)\n",
1406 (long)in->i_rdev, user_minor); 1750 (long)fp->f_dentry->d_inode->i_rdev, i_minor);
1407 1751
1408 if (user_minor) 1752 if (i_minor)
1409 ret = find_free_port(user_minor - 1, fp); 1753 ret = find_free_port(i_minor - 1, fp, uinfo);
1410 else 1754 else
1411 ret = find_best_unit(fp); 1755 ret = find_best_unit(fp, uinfo);
1412 1756
1413 mutex_unlock(&ipath_mutex); 1757 mutex_unlock(&ipath_mutex);
1758
1759done:
1760 return ret;
1761}
1762
1763
1764static int ipath_do_user_init(struct file *fp,
1765 const struct ipath_user_info *uinfo)
1766{
1767 int ret;
1768 struct ipath_portdata *pd;
1769 struct ipath_devdata *dd;
1770 u32 head32;
1771
1772 pd = port_fp(fp);
1773 dd = pd->port_dd;
1774
1775 if (uinfo->spu_rcvhdrsize) {
1776 ret = ipath_setrcvhdrsize(dd, uinfo->spu_rcvhdrsize);
1777 if (ret)
1778 goto done;
1779 }
1780
1781 /* for now we do nothing with rcvhdrcnt: uinfo->spu_rcvhdrcnt */
1782
1783 /* for right now, kernel piobufs are at end, so port 1 is at 0 */
1784 pd->port_piobufs = dd->ipath_piobufbase +
1785 dd->ipath_pbufsport * (pd->port_port - 1) * dd->ipath_palign;
1786 ipath_cdbg(VERBOSE, "Set base of piobufs for port %u to 0x%x\n",
1787 pd->port_port, pd->port_piobufs);
1788
1789 /*
1790 * Now allocate the rcvhdr Q and eager TIDs; skip the TID
1791 * array for time being. If pd->port_port > chip-supported,
1792 * we need to do extra stuff here to handle by handling overflow
1793 * through port 0, someday
1794 */
1795 ret = ipath_create_rcvhdrq(dd, pd);
1796 if (!ret)
1797 ret = ipath_create_user_egr(pd);
1798 if (ret)
1799 goto done;
1800
1801 /*
1802 * set the eager head register for this port to the current values
1803 * of the tail pointers, since we don't know if they were
1804 * updated on last use of the port.
1805 */
1806 head32 = ipath_read_ureg32(dd, ur_rcvegrindextail, pd->port_port);
1807 ipath_write_ureg(dd, ur_rcvegrindexhead, head32, pd->port_port);
1808 dd->ipath_lastegrheads[pd->port_port] = -1;
1809 dd->ipath_lastrcvhdrqtails[pd->port_port] = -1;
1810 ipath_cdbg(VERBOSE, "Wrote port%d egrhead %x from tail regs\n",
1811 pd->port_port, head32);
1812 pd->port_tidcursor = 0; /* start at beginning after open */
1813 /*
1814 * now enable the port; the tail registers will be written to memory
1815 * by the chip as soon as it sees the write to
1816 * dd->ipath_kregs->kr_rcvctrl. The update only happens on
1817 * transition from 0 to 1, so clear it first, then set it as part of
1818 * enabling the port. This will (very briefly) affect any other
1819 * open ports, but it shouldn't be long enough to be an issue.
1820 * We explictly set the in-memory copy to 0 beforehand, so we don't
1821 * have to wait to be sure the DMA update has happened.
1822 */
1823 *(volatile u64 *)pd->port_rcvhdrtail_kvaddr = 0ULL;
1824 set_bit(INFINIPATH_R_PORTENABLE_SHIFT + pd->port_port,
1825 &dd->ipath_rcvctrl);
1826 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
1827 dd->ipath_rcvctrl & ~INFINIPATH_R_TAILUPD);
1828 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
1829 dd->ipath_rcvctrl);
1830done:
1414 return ret; 1831 return ret;
1415} 1832}
1416 1833
@@ -1433,6 +1850,8 @@ static void unlock_expected_tids(struct ipath_portdata *pd)
1433 if (!dd->ipath_pageshadow[i]) 1850 if (!dd->ipath_pageshadow[i])
1434 continue; 1851 continue;
1435 1852
1853 pci_unmap_page(dd->pcidev, dd->ipath_physshadow[i],
1854 PAGE_SIZE, PCI_DMA_FROMDEVICE);
1436 ipath_release_user_pages_on_close(&dd->ipath_pageshadow[i], 1855 ipath_release_user_pages_on_close(&dd->ipath_pageshadow[i],
1437 1); 1856 1);
1438 dd->ipath_pageshadow[i] = NULL; 1857 dd->ipath_pageshadow[i] = NULL;
@@ -1453,6 +1872,7 @@ static void unlock_expected_tids(struct ipath_portdata *pd)
1453static int ipath_close(struct inode *in, struct file *fp) 1872static int ipath_close(struct inode *in, struct file *fp)
1454{ 1873{
1455 int ret = 0; 1874 int ret = 0;
1875 struct ipath_filedata *fd;
1456 struct ipath_portdata *pd; 1876 struct ipath_portdata *pd;
1457 struct ipath_devdata *dd; 1877 struct ipath_devdata *dd;
1458 unsigned port; 1878 unsigned port;
@@ -1462,9 +1882,24 @@ static int ipath_close(struct inode *in, struct file *fp)
1462 1882
1463 mutex_lock(&ipath_mutex); 1883 mutex_lock(&ipath_mutex);
1464 1884
1465 pd = port_fp(fp); 1885 fd = (struct ipath_filedata *) fp->private_data;
1466 port = pd->port_port;
1467 fp->private_data = NULL; 1886 fp->private_data = NULL;
1887 pd = fd->pd;
1888 if (!pd) {
1889 mutex_unlock(&ipath_mutex);
1890 goto bail;
1891 }
1892 if (--pd->port_cnt) {
1893 /*
1894 * XXX If the master closes the port before the slave(s),
1895 * revoke the mmap for the eager receive queue so
1896 * the slave(s) don't wait for receive data forever.
1897 */
1898 pd->active_slaves &= ~(1 << fd->subport);
1899 mutex_unlock(&ipath_mutex);
1900 goto bail;
1901 }
1902 port = pd->port_port;
1468 dd = pd->port_dd; 1903 dd = pd->port_dd;
1469 1904
1470 if (pd->port_hdrqfull) { 1905 if (pd->port_hdrqfull) {
@@ -1503,8 +1938,6 @@ static int ipath_close(struct inode *in, struct file *fp)
1503 1938
1504 /* clean up the pkeys for this port user */ 1939 /* clean up the pkeys for this port user */
1505 ipath_clean_part_key(pd, dd); 1940 ipath_clean_part_key(pd, dd);
1506
1507
1508 /* 1941 /*
1509 * be paranoid, and never write 0's to these, just use an 1942 * be paranoid, and never write 0's to these, just use an
1510 * unused part of the port 0 tail page. Of course, 1943 * unused part of the port 0 tail page. Of course,
@@ -1523,39 +1956,49 @@ static int ipath_close(struct inode *in, struct file *fp)
1523 i = dd->ipath_pbufsport * (port - 1); 1956 i = dd->ipath_pbufsport * (port - 1);
1524 ipath_disarm_piobufs(dd, i, dd->ipath_pbufsport); 1957 ipath_disarm_piobufs(dd, i, dd->ipath_pbufsport);
1525 1958
1959 dd->ipath_f_clear_tids(dd, pd->port_port);
1960
1526 if (dd->ipath_pageshadow) 1961 if (dd->ipath_pageshadow)
1527 unlock_expected_tids(pd); 1962 unlock_expected_tids(pd);
1528 ipath_stats.sps_ports--; 1963 ipath_stats.sps_ports--;
1529 ipath_cdbg(PROC, "%s[%u] closed port %u:%u\n", 1964 ipath_cdbg(PROC, "%s[%u] closed port %u:%u\n",
1530 pd->port_comm, pd->port_pid, 1965 pd->port_comm, pd->port_pid,
1531 dd->ipath_unit, port); 1966 dd->ipath_unit, port);
1532
1533 dd->ipath_f_clear_tids(dd, pd->port_port);
1534 } 1967 }
1535 1968
1536 pd->port_cnt = 0;
1537 pd->port_pid = 0; 1969 pd->port_pid = 0;
1538
1539 dd->ipath_pd[pd->port_port] = NULL; /* before releasing mutex */ 1970 dd->ipath_pd[pd->port_port] = NULL; /* before releasing mutex */
1540 mutex_unlock(&ipath_mutex); 1971 mutex_unlock(&ipath_mutex);
1541 ipath_free_pddata(dd, pd); /* after releasing the mutex */ 1972 ipath_free_pddata(dd, pd); /* after releasing the mutex */
1542 1973
1974bail:
1975 kfree(fd);
1543 return ret; 1976 return ret;
1544} 1977}
1545 1978
1546static int ipath_port_info(struct ipath_portdata *pd, 1979static int ipath_port_info(struct ipath_portdata *pd, u16 subport,
1547 struct ipath_port_info __user *uinfo) 1980 struct ipath_port_info __user *uinfo)
1548{ 1981{
1549 struct ipath_port_info info; 1982 struct ipath_port_info info;
1550 int nup; 1983 int nup;
1551 int ret; 1984 int ret;
1985 size_t sz;
1552 1986
1553 (void) ipath_count_units(NULL, &nup, NULL); 1987 (void) ipath_count_units(NULL, &nup, NULL);
1554 info.num_active = nup; 1988 info.num_active = nup;
1555 info.unit = pd->port_dd->ipath_unit; 1989 info.unit = pd->port_dd->ipath_unit;
1556 info.port = pd->port_port; 1990 info.port = pd->port_port;
1991 info.subport = subport;
1992 /* Don't return new fields if old library opened the port. */
1993 if ((pd->userversion & 0xffff) == IPATH_USER_SWMINOR) {
1994 /* Number of user ports available for this device. */
1995 info.num_ports = pd->port_dd->ipath_cfgports - 1;
1996 info.num_subports = pd->port_subport_cnt;
1997 sz = sizeof(info);
1998 } else
1999 sz = sizeof(info) - 2 * sizeof(u16);
1557 2000
1558 if (copy_to_user(uinfo, &info, sizeof(info))) { 2001 if (copy_to_user(uinfo, &info, sz)) {
1559 ret = -EFAULT; 2002 ret = -EFAULT;
1560 goto bail; 2003 goto bail;
1561 } 2004 }
@@ -1565,6 +2008,16 @@ bail:
1565 return ret; 2008 return ret;
1566} 2009}
1567 2010
2011static int ipath_get_slave_info(struct ipath_portdata *pd,
2012 void __user *slave_mask_addr)
2013{
2014 int ret = 0;
2015
2016 if (copy_to_user(slave_mask_addr, &pd->active_slaves, sizeof(u32)))
2017 ret = -EFAULT;
2018 return ret;
2019}
2020
1568static ssize_t ipath_write(struct file *fp, const char __user *data, 2021static ssize_t ipath_write(struct file *fp, const char __user *data,
1569 size_t count, loff_t *off) 2022 size_t count, loff_t *off)
1570{ 2023{
@@ -1591,6 +2044,8 @@ static ssize_t ipath_write(struct file *fp, const char __user *data,
1591 consumed = sizeof(cmd.type); 2044 consumed = sizeof(cmd.type);
1592 2045
1593 switch (cmd.type) { 2046 switch (cmd.type) {
2047 case IPATH_CMD_ASSIGN_PORT:
2048 case __IPATH_CMD_USER_INIT:
1594 case IPATH_CMD_USER_INIT: 2049 case IPATH_CMD_USER_INIT:
1595 copy = sizeof(cmd.cmd.user_info); 2050 copy = sizeof(cmd.cmd.user_info);
1596 dest = &cmd.cmd.user_info; 2051 dest = &cmd.cmd.user_info;
@@ -1617,6 +2072,11 @@ static ssize_t ipath_write(struct file *fp, const char __user *data,
1617 dest = &cmd.cmd.part_key; 2072 dest = &cmd.cmd.part_key;
1618 src = &ucmd->cmd.part_key; 2073 src = &ucmd->cmd.part_key;
1619 break; 2074 break;
2075 case IPATH_CMD_SLAVE_INFO:
2076 copy = sizeof(cmd.cmd.slave_mask_addr);
2077 dest = &cmd.cmd.slave_mask_addr;
2078 src = &ucmd->cmd.slave_mask_addr;
2079 break;
1620 default: 2080 default:
1621 ret = -EINVAL; 2081 ret = -EINVAL;
1622 goto bail; 2082 goto bail;
@@ -1634,34 +2094,55 @@ static ssize_t ipath_write(struct file *fp, const char __user *data,
1634 2094
1635 consumed += copy; 2095 consumed += copy;
1636 pd = port_fp(fp); 2096 pd = port_fp(fp);
2097 if (!pd && cmd.type != __IPATH_CMD_USER_INIT &&
2098 cmd.type != IPATH_CMD_ASSIGN_PORT) {
2099 ret = -EINVAL;
2100 goto bail;
2101 }
1637 2102
1638 switch (cmd.type) { 2103 switch (cmd.type) {
2104 case IPATH_CMD_ASSIGN_PORT:
2105 ret = ipath_assign_port(fp, &cmd.cmd.user_info);
2106 if (ret)
2107 goto bail;
2108 break;
2109 case __IPATH_CMD_USER_INIT:
2110 /* backwards compatibility, get port first */
2111 ret = ipath_assign_port(fp, &cmd.cmd.user_info);
2112 if (ret)
2113 goto bail;
2114 /* and fall through to current version. */
1639 case IPATH_CMD_USER_INIT: 2115 case IPATH_CMD_USER_INIT:
1640 ret = ipath_do_user_init(pd, &cmd.cmd.user_info); 2116 ret = ipath_do_user_init(fp, &cmd.cmd.user_info);
1641 if (ret < 0) 2117 if (ret)
1642 goto bail; 2118 goto bail;
1643 ret = ipath_get_base_info( 2119 ret = ipath_get_base_info(
1644 pd, (void __user *) (unsigned long) 2120 fp, (void __user *) (unsigned long)
1645 cmd.cmd.user_info.spu_base_info, 2121 cmd.cmd.user_info.spu_base_info,
1646 cmd.cmd.user_info.spu_base_info_size); 2122 cmd.cmd.user_info.spu_base_info_size);
1647 break; 2123 break;
1648 case IPATH_CMD_RECV_CTRL: 2124 case IPATH_CMD_RECV_CTRL:
1649 ret = ipath_manage_rcvq(pd, cmd.cmd.recv_ctrl); 2125 ret = ipath_manage_rcvq(pd, subport_fp(fp), cmd.cmd.recv_ctrl);
1650 break; 2126 break;
1651 case IPATH_CMD_PORT_INFO: 2127 case IPATH_CMD_PORT_INFO:
1652 ret = ipath_port_info(pd, 2128 ret = ipath_port_info(pd, subport_fp(fp),
1653 (struct ipath_port_info __user *) 2129 (struct ipath_port_info __user *)
1654 (unsigned long) cmd.cmd.port_info); 2130 (unsigned long) cmd.cmd.port_info);
1655 break; 2131 break;
1656 case IPATH_CMD_TID_UPDATE: 2132 case IPATH_CMD_TID_UPDATE:
1657 ret = ipath_tid_update(pd, &cmd.cmd.tid_info); 2133 ret = ipath_tid_update(pd, fp, &cmd.cmd.tid_info);
1658 break; 2134 break;
1659 case IPATH_CMD_TID_FREE: 2135 case IPATH_CMD_TID_FREE:
1660 ret = ipath_tid_free(pd, &cmd.cmd.tid_info); 2136 ret = ipath_tid_free(pd, subport_fp(fp), &cmd.cmd.tid_info);
1661 break; 2137 break;
1662 case IPATH_CMD_SET_PART_KEY: 2138 case IPATH_CMD_SET_PART_KEY:
1663 ret = ipath_set_part_key(pd, cmd.cmd.part_key); 2139 ret = ipath_set_part_key(pd, cmd.cmd.part_key);
1664 break; 2140 break;
2141 case IPATH_CMD_SLAVE_INFO:
2142 ret = ipath_get_slave_info(pd,
2143 (void __user *) (unsigned long)
2144 cmd.cmd.slave_mask_addr);
2145 break;
1665 } 2146 }
1666 2147
1667 if (ret >= 0) 2148 if (ret >= 0)
@@ -1858,4 +2339,3 @@ void ipath_user_remove(struct ipath_devdata *dd)
1858bail: 2339bail:
1859 return; 2340 return;
1860} 2341}
1861
diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
index a5eb30a06a5c..d9ff283f725e 100644
--- a/drivers/infiniband/hw/ipath/ipath_fs.c
+++ b/drivers/infiniband/hw/ipath/ipath_fs.c
@@ -61,14 +61,13 @@ static int ipathfs_mknod(struct inode *dir, struct dentry *dentry,
61 inode->i_mode = mode; 61 inode->i_mode = mode;
62 inode->i_uid = 0; 62 inode->i_uid = 0;
63 inode->i_gid = 0; 63 inode->i_gid = 0;
64 inode->i_blksize = PAGE_CACHE_SIZE;
65 inode->i_blocks = 0; 64 inode->i_blocks = 0;
66 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; 65 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
67 inode->u.generic_ip = data; 66 inode->i_private = data;
68 if ((mode & S_IFMT) == S_IFDIR) { 67 if ((mode & S_IFMT) == S_IFDIR) {
69 inode->i_op = &simple_dir_inode_operations; 68 inode->i_op = &simple_dir_inode_operations;
70 inode->i_nlink++; 69 inc_nlink(inode);
71 dir->i_nlink++; 70 inc_nlink(dir);
72 } 71 }
73 72
74 inode->i_fop = fops; 73 inode->i_fop = fops;
@@ -119,7 +118,7 @@ static ssize_t atomic_counters_read(struct file *file, char __user *buf,
119 u16 i; 118 u16 i;
120 struct ipath_devdata *dd; 119 struct ipath_devdata *dd;
121 120
122 dd = file->f_dentry->d_inode->u.generic_ip; 121 dd = file->f_dentry->d_inode->i_private;
123 122
124 for (i = 0; i < NUM_COUNTERS; i++) 123 for (i = 0; i < NUM_COUNTERS; i++)
125 counters[i] = ipath_snap_cntr(dd, i); 124 counters[i] = ipath_snap_cntr(dd, i);
@@ -139,7 +138,7 @@ static ssize_t atomic_node_info_read(struct file *file, char __user *buf,
139 struct ipath_devdata *dd; 138 struct ipath_devdata *dd;
140 u64 guid; 139 u64 guid;
141 140
142 dd = file->f_dentry->d_inode->u.generic_ip; 141 dd = file->f_dentry->d_inode->i_private;
143 142
144 guid = be64_to_cpu(dd->ipath_guid); 143 guid = be64_to_cpu(dd->ipath_guid);
145 144
@@ -178,7 +177,7 @@ static ssize_t atomic_port_info_read(struct file *file, char __user *buf,
178 u32 tmp, tmp2; 177 u32 tmp, tmp2;
179 struct ipath_devdata *dd; 178 struct ipath_devdata *dd;
180 179
181 dd = file->f_dentry->d_inode->u.generic_ip; 180 dd = file->f_dentry->d_inode->i_private;
182 181
183 /* so we only initialize non-zero fields. */ 182 /* so we only initialize non-zero fields. */
184 memset(portinfo, 0, sizeof portinfo); 183 memset(portinfo, 0, sizeof portinfo);
@@ -325,7 +324,7 @@ static ssize_t flash_read(struct file *file, char __user *buf,
325 goto bail; 324 goto bail;
326 } 325 }
327 326
328 dd = file->f_dentry->d_inode->u.generic_ip; 327 dd = file->f_dentry->d_inode->i_private;
329 if (ipath_eeprom_read(dd, pos, tmp, count)) { 328 if (ipath_eeprom_read(dd, pos, tmp, count)) {
330 ipath_dev_err(dd, "failed to read from flash\n"); 329 ipath_dev_err(dd, "failed to read from flash\n");
331 ret = -ENXIO; 330 ret = -ENXIO;
@@ -357,19 +356,16 @@ static ssize_t flash_write(struct file *file, const char __user *buf,
357 356
358 pos = *ppos; 357 pos = *ppos;
359 358
360 if ( pos < 0) { 359 if (pos != 0) {
361 ret = -EINVAL; 360 ret = -EINVAL;
362 goto bail; 361 goto bail;
363 } 362 }
364 363
365 if (pos >= sizeof(struct ipath_flash)) { 364 if (count != sizeof(struct ipath_flash)) {
366 ret = 0; 365 ret = -EINVAL;
367 goto bail; 366 goto bail;
368 } 367 }
369 368
370 if (count > sizeof(struct ipath_flash) - pos)
371 count = sizeof(struct ipath_flash) - pos;
372
373 tmp = kmalloc(count, GFP_KERNEL); 369 tmp = kmalloc(count, GFP_KERNEL);
374 if (!tmp) { 370 if (!tmp) {
375 ret = -ENOMEM; 371 ret = -ENOMEM;
@@ -381,7 +377,7 @@ static ssize_t flash_write(struct file *file, const char __user *buf,
381 goto bail_tmp; 377 goto bail_tmp;
382 } 378 }
383 379
384 dd = file->f_dentry->d_inode->u.generic_ip; 380 dd = file->f_dentry->d_inode->i_private;
385 if (ipath_eeprom_write(dd, pos, tmp, count)) { 381 if (ipath_eeprom_write(dd, pos, tmp, count)) {
386 ret = -ENXIO; 382 ret = -ENXIO;
387 ipath_dev_err(dd, "failed to write to flash\n"); 383 ipath_dev_err(dd, "failed to write to flash\n");
diff --git a/drivers/infiniband/hw/ipath/ipath_iba6110.c b/drivers/infiniband/hw/ipath/ipath_iba6110.c
index bf2455a6d562..9e4e8d4c6e20 100644
--- a/drivers/infiniband/hw/ipath/ipath_iba6110.c
+++ b/drivers/infiniband/hw/ipath/ipath_iba6110.c
@@ -252,8 +252,8 @@ static const struct ipath_cregs ipath_ht_cregs = {
252}; 252};
253 253
254/* kr_intstatus, kr_intclear, kr_intmask bits */ 254/* kr_intstatus, kr_intclear, kr_intmask bits */
255#define INFINIPATH_I_RCVURG_MASK 0x1FF 255#define INFINIPATH_I_RCVURG_MASK ((1U<<9)-1)
256#define INFINIPATH_I_RCVAVAIL_MASK 0x1FF 256#define INFINIPATH_I_RCVAVAIL_MASK ((1U<<9)-1)
257 257
258/* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */ 258/* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
259#define INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT 0 259#define INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT 0
@@ -338,7 +338,7 @@ static void hwerr_crcbits(struct ipath_devdata *dd, ipath_err_t hwerrs,
338 if (crcbits) { 338 if (crcbits) {
339 u16 ctrl0, ctrl1; 339 u16 ctrl0, ctrl1;
340 snprintf(bitsmsg, sizeof bitsmsg, 340 snprintf(bitsmsg, sizeof bitsmsg,
341 "[HT%s lane %s CRC (%llx); ignore till reload]", 341 "[HT%s lane %s CRC (%llx); powercycle to completely clear]",
342 !(crcbits & _IPATH_HTLINK1_CRCBITS) ? 342 !(crcbits & _IPATH_HTLINK1_CRCBITS) ?
343 "0 (A)" : (!(crcbits & _IPATH_HTLINK0_CRCBITS) 343 "0 (A)" : (!(crcbits & _IPATH_HTLINK0_CRCBITS)
344 ? "1 (B)" : "0+1 (A+B)"), 344 ? "1 (B)" : "0+1 (A+B)"),
@@ -389,17 +389,28 @@ static void hwerr_crcbits(struct ipath_devdata *dd, ipath_err_t hwerrs,
389 _IPATH_HTLINK1_CRCBITS))); 389 _IPATH_HTLINK1_CRCBITS)));
390} 390}
391 391
392/* 6110 specific hardware errors... */
393static const struct ipath_hwerror_msgs ipath_6110_hwerror_msgs[] = {
394 INFINIPATH_HWE_MSG(HTCBUSIREQPARITYERR, "HTC Ireq Parity"),
395 INFINIPATH_HWE_MSG(HTCBUSTREQPARITYERR, "HTC Treq Parity"),
396 INFINIPATH_HWE_MSG(HTCBUSTRESPPARITYERR, "HTC Tresp Parity"),
397 INFINIPATH_HWE_MSG(HTCMISCERR5, "HT core Misc5"),
398 INFINIPATH_HWE_MSG(HTCMISCERR6, "HT core Misc6"),
399 INFINIPATH_HWE_MSG(HTCMISCERR7, "HT core Misc7"),
400 INFINIPATH_HWE_MSG(RXDSYNCMEMPARITYERR, "Rx Dsync"),
401 INFINIPATH_HWE_MSG(SERDESPLLFAILED, "SerDes PLL"),
402};
403
392/** 404/**
393 * ipath_ht_handle_hwerrors - display hardware errors 405 * ipath_ht_handle_hwerrors - display hardware errors.
394 * @dd: the infinipath device 406 * @dd: the infinipath device
395 * @msg: the output buffer 407 * @msg: the output buffer
396 * @msgl: the size of the output buffer 408 * @msgl: the size of the output buffer
397 * 409 *
398 * Use same msg buffer as regular errors to avoid 410 * Use same msg buffer as regular errors to avoid excessive stack
399 * excessive stack use. Most hardware errors are catastrophic, but for 411 * use. Most hardware errors are catastrophic, but for right now,
400 * right now, we'll print them and continue. 412 * we'll print them and continue. We reuse the same message buffer as
401 * We reuse the same message buffer as ipath_handle_errors() to avoid 413 * ipath_handle_errors() to avoid excessive stack usage.
402 * excessive stack usage.
403 */ 414 */
404static void ipath_ht_handle_hwerrors(struct ipath_devdata *dd, char *msg, 415static void ipath_ht_handle_hwerrors(struct ipath_devdata *dd, char *msg,
405 size_t msgl) 416 size_t msgl)
@@ -440,19 +451,49 @@ static void ipath_ht_handle_hwerrors(struct ipath_devdata *dd, char *msg,
440 * make sure we get this much out, unless told to be quiet, 451 * make sure we get this much out, unless told to be quiet,
441 * or it's occurred within the last 5 seconds 452 * or it's occurred within the last 5 seconds
442 */ 453 */
443 if ((hwerrs & ~dd->ipath_lasthwerror) || 454 if ((hwerrs & ~(dd->ipath_lasthwerror |
455 ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF |
456 INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC)
457 << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT))) ||
444 (ipath_debug & __IPATH_VERBDBG)) 458 (ipath_debug & __IPATH_VERBDBG))
445 dev_info(&dd->pcidev->dev, "Hardware error: hwerr=0x%llx " 459 dev_info(&dd->pcidev->dev, "Hardware error: hwerr=0x%llx "
446 "(cleared)\n", (unsigned long long) hwerrs); 460 "(cleared)\n", (unsigned long long) hwerrs);
447 dd->ipath_lasthwerror |= hwerrs; 461 dd->ipath_lasthwerror |= hwerrs;
448 462
449 if (hwerrs & ~infinipath_hwe_bitsextant) 463 if (hwerrs & ~dd->ipath_hwe_bitsextant)
450 ipath_dev_err(dd, "hwerror interrupt with unknown errors " 464 ipath_dev_err(dd, "hwerror interrupt with unknown errors "
451 "%llx set\n", (unsigned long long) 465 "%llx set\n", (unsigned long long)
452 (hwerrs & ~infinipath_hwe_bitsextant)); 466 (hwerrs & ~dd->ipath_hwe_bitsextant));
453 467
454 ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control); 468 ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);
455 if (ctrl & INFINIPATH_C_FREEZEMODE) { 469 if (ctrl & INFINIPATH_C_FREEZEMODE) {
470 /*
471 * parity errors in send memory are recoverable,
472 * just cancel the send (if indicated in * sendbuffererror),
473 * count the occurrence, unfreeze (if no other handled
474 * hardware error bits are set), and continue. They can
475 * occur if a processor speculative read is done to the PIO
476 * buffer while we are sending a packet, for example.
477 */
478 if (hwerrs & ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF |
479 INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC)
480 << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT)) {
481 ipath_stats.sps_txeparity++;
482 ipath_dbg("Recovering from TXE parity error (%llu), "
483 "hwerrstatus=%llx\n",
484 (unsigned long long) ipath_stats.sps_txeparity,
485 (unsigned long long) hwerrs);
486 ipath_disarm_senderrbufs(dd);
487 hwerrs &= ~((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF |
488 INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC)
489 << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT);
490 if (!hwerrs) { /* else leave in freeze mode */
491 ipath_write_kreg(dd,
492 dd->ipath_kregs->kr_control,
493 dd->ipath_control);
494 return;
495 }
496 }
456 if (hwerrs) { 497 if (hwerrs) {
457 /* 498 /*
458 * if any set that we aren't ignoring; only 499 * if any set that we aren't ignoring; only
@@ -499,44 +540,16 @@ static void ipath_ht_handle_hwerrors(struct ipath_devdata *dd, char *msg,
499 bits); 540 bits);
500 strlcat(msg, bitsmsg, msgl); 541 strlcat(msg, bitsmsg, msgl);
501 } 542 }
502 if (hwerrs & (INFINIPATH_HWE_RXEMEMPARITYERR_MASK 543
503 << INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT)) { 544 ipath_format_hwerrors(hwerrs,
504 bits = (u32) ((hwerrs >> 545 ipath_6110_hwerror_msgs,
505 INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) & 546 sizeof(ipath_6110_hwerror_msgs) /
506 INFINIPATH_HWE_RXEMEMPARITYERR_MASK); 547 sizeof(ipath_6110_hwerror_msgs[0]),
507 snprintf(bitsmsg, sizeof bitsmsg, "[RXE Parity Errs %x] ", 548 msg, msgl);
508 bits);
509 strlcat(msg, bitsmsg, msgl);
510 }
511 if (hwerrs & (INFINIPATH_HWE_TXEMEMPARITYERR_MASK
512 << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT)) {
513 bits = (u32) ((hwerrs >>
514 INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) &
515 INFINIPATH_HWE_TXEMEMPARITYERR_MASK);
516 snprintf(bitsmsg, sizeof bitsmsg, "[TXE Parity Errs %x] ",
517 bits);
518 strlcat(msg, bitsmsg, msgl);
519 }
520 if (hwerrs & INFINIPATH_HWE_IBCBUSTOSPCPARITYERR)
521 strlcat(msg, "[IB2IPATH Parity]", msgl);
522 if (hwerrs & INFINIPATH_HWE_IBCBUSFRSPCPARITYERR)
523 strlcat(msg, "[IPATH2IB Parity]", msgl);
524 if (hwerrs & INFINIPATH_HWE_HTCBUSIREQPARITYERR)
525 strlcat(msg, "[HTC Ireq Parity]", msgl);
526 if (hwerrs & INFINIPATH_HWE_HTCBUSTREQPARITYERR)
527 strlcat(msg, "[HTC Treq Parity]", msgl);
528 if (hwerrs & INFINIPATH_HWE_HTCBUSTRESPPARITYERR)
529 strlcat(msg, "[HTC Tresp Parity]", msgl);
530 549
531 if (hwerrs & (_IPATH_HTLINK0_CRCBITS | _IPATH_HTLINK1_CRCBITS)) 550 if (hwerrs & (_IPATH_HTLINK0_CRCBITS | _IPATH_HTLINK1_CRCBITS))
532 hwerr_crcbits(dd, hwerrs, msg, msgl); 551 hwerr_crcbits(dd, hwerrs, msg, msgl);
533 552
534 if (hwerrs & INFINIPATH_HWE_HTCMISCERR5)
535 strlcat(msg, "[HT core Misc5]", msgl);
536 if (hwerrs & INFINIPATH_HWE_HTCMISCERR6)
537 strlcat(msg, "[HT core Misc6]", msgl);
538 if (hwerrs & INFINIPATH_HWE_HTCMISCERR7)
539 strlcat(msg, "[HT core Misc7]", msgl);
540 if (hwerrs & INFINIPATH_HWE_MEMBISTFAILED) { 553 if (hwerrs & INFINIPATH_HWE_MEMBISTFAILED) {
541 strlcat(msg, "[Memory BIST test failed, InfiniPath hardware unusable]", 554 strlcat(msg, "[Memory BIST test failed, InfiniPath hardware unusable]",
542 msgl); 555 msgl);
@@ -573,11 +586,6 @@ static void ipath_ht_handle_hwerrors(struct ipath_devdata *dd, char *msg,
573 dd->ipath_hwerrmask); 586 dd->ipath_hwerrmask);
574 } 587 }
575 588
576 if (hwerrs & INFINIPATH_HWE_RXDSYNCMEMPARITYERR)
577 strlcat(msg, "[Rx Dsync]", msgl);
578 if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED)
579 strlcat(msg, "[SerDes PLL]", msgl);
580
581 ipath_dev_err(dd, "%s hardware error\n", msg); 589 ipath_dev_err(dd, "%s hardware error\n", msg);
582 if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg) 590 if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg)
583 /* 591 /*
@@ -742,7 +750,6 @@ static int ipath_setup_ht_reset(struct ipath_devdata *dd)
742 return 0; 750 return 0;
743} 751}
744 752
745#define HT_CAPABILITY_ID 0x08 /* HT capabilities not defined in kernel */
746#define HT_INTR_DISC_CONFIG 0x80 /* HT interrupt and discovery cap */ 753#define HT_INTR_DISC_CONFIG 0x80 /* HT interrupt and discovery cap */
747#define HT_INTR_REG_INDEX 2 /* intconfig requires indirect accesses */ 754#define HT_INTR_REG_INDEX 2 /* intconfig requires indirect accesses */
748 755
@@ -973,7 +980,7 @@ static int ipath_setup_ht_config(struct ipath_devdata *dd,
973 * do this early, before we ever enable errors or hardware errors, 980 * do this early, before we ever enable errors or hardware errors,
974 * mostly to avoid causing the chip to enter freeze mode. 981 * mostly to avoid causing the chip to enter freeze mode.
975 */ 982 */
976 pos = pci_find_capability(pdev, HT_CAPABILITY_ID); 983 pos = pci_find_capability(pdev, PCI_CAP_ID_HT);
977 if (!pos) { 984 if (!pos) {
978 ipath_dev_err(dd, "Couldn't find HyperTransport " 985 ipath_dev_err(dd, "Couldn't find HyperTransport "
979 "capability; no interrupts\n"); 986 "capability; no interrupts\n");
@@ -996,7 +1003,7 @@ static int ipath_setup_ht_config(struct ipath_devdata *dd,
996 else if (cap_type == HT_INTR_DISC_CONFIG) 1003 else if (cap_type == HT_INTR_DISC_CONFIG)
997 ihandler = set_int_handler(dd, pdev, pos); 1004 ihandler = set_int_handler(dd, pdev, pos);
998 } while ((pos = pci_find_next_capability(pdev, pos, 1005 } while ((pos = pci_find_next_capability(pdev, pos,
999 HT_CAPABILITY_ID))); 1006 PCI_CAP_ID_HT)));
1000 1007
1001 if (!ihandler) { 1008 if (!ihandler) {
1002 ipath_dev_err(dd, "Couldn't find interrupt handler in " 1009 ipath_dev_err(dd, "Couldn't find interrupt handler in "
@@ -1081,21 +1088,21 @@ static void ipath_setup_ht_setextled(struct ipath_devdata *dd,
1081 ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, extctl); 1088 ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, extctl);
1082} 1089}
1083 1090
1084static void ipath_init_ht_variables(void) 1091static void ipath_init_ht_variables(struct ipath_devdata *dd)
1085{ 1092{
1086 ipath_gpio_sda_num = _IPATH_GPIO_SDA_NUM; 1093 dd->ipath_gpio_sda_num = _IPATH_GPIO_SDA_NUM;
1087 ipath_gpio_scl_num = _IPATH_GPIO_SCL_NUM; 1094 dd->ipath_gpio_scl_num = _IPATH_GPIO_SCL_NUM;
1088 ipath_gpio_sda = IPATH_GPIO_SDA; 1095 dd->ipath_gpio_sda = IPATH_GPIO_SDA;
1089 ipath_gpio_scl = IPATH_GPIO_SCL; 1096 dd->ipath_gpio_scl = IPATH_GPIO_SCL;
1090 1097
1091 infinipath_i_bitsextant = 1098 dd->ipath_i_bitsextant =
1092 (INFINIPATH_I_RCVURG_MASK << INFINIPATH_I_RCVURG_SHIFT) | 1099 (INFINIPATH_I_RCVURG_MASK << INFINIPATH_I_RCVURG_SHIFT) |
1093 (INFINIPATH_I_RCVAVAIL_MASK << 1100 (INFINIPATH_I_RCVAVAIL_MASK <<
1094 INFINIPATH_I_RCVAVAIL_SHIFT) | 1101 INFINIPATH_I_RCVAVAIL_SHIFT) |
1095 INFINIPATH_I_ERROR | INFINIPATH_I_SPIOSENT | 1102 INFINIPATH_I_ERROR | INFINIPATH_I_SPIOSENT |
1096 INFINIPATH_I_SPIOBUFAVAIL | INFINIPATH_I_GPIO; 1103 INFINIPATH_I_SPIOBUFAVAIL | INFINIPATH_I_GPIO;
1097 1104
1098 infinipath_e_bitsextant = 1105 dd->ipath_e_bitsextant =
1099 INFINIPATH_E_RFORMATERR | INFINIPATH_E_RVCRC | 1106 INFINIPATH_E_RFORMATERR | INFINIPATH_E_RVCRC |
1100 INFINIPATH_E_RICRC | INFINIPATH_E_RMINPKTLEN | 1107 INFINIPATH_E_RICRC | INFINIPATH_E_RMINPKTLEN |
1101 INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RLONGPKTLEN | 1108 INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RLONGPKTLEN |
@@ -1113,7 +1120,7 @@ static void ipath_init_ht_variables(void)
1113 INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET | 1120 INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET |
1114 INFINIPATH_E_HARDWARE; 1121 INFINIPATH_E_HARDWARE;
1115 1122
1116 infinipath_hwe_bitsextant = 1123 dd->ipath_hwe_bitsextant =
1117 (INFINIPATH_HWE_HTCMEMPARITYERR_MASK << 1124 (INFINIPATH_HWE_HTCMEMPARITYERR_MASK <<
1118 INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT) | 1125 INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT) |
1119 (INFINIPATH_HWE_TXEMEMPARITYERR_MASK << 1126 (INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
@@ -1142,8 +1149,8 @@ static void ipath_init_ht_variables(void)
1142 INFINIPATH_HWE_IBCBUSTOSPCPARITYERR | 1149 INFINIPATH_HWE_IBCBUSTOSPCPARITYERR |
1143 INFINIPATH_HWE_IBCBUSFRSPCPARITYERR; 1150 INFINIPATH_HWE_IBCBUSFRSPCPARITYERR;
1144 1151
1145 infinipath_i_rcvavail_mask = INFINIPATH_I_RCVAVAIL_MASK; 1152 dd->ipath_i_rcvavail_mask = INFINIPATH_I_RCVAVAIL_MASK;
1146 infinipath_i_rcvurg_mask = INFINIPATH_I_RCVURG_MASK; 1153 dd->ipath_i_rcvurg_mask = INFINIPATH_I_RCVURG_MASK;
1147} 1154}
1148 1155
1149/** 1156/**
@@ -1608,5 +1615,5 @@ void ipath_init_iba6110_funcs(struct ipath_devdata *dd)
1608 * do very early init that is needed before ipath_f_bus is 1615 * do very early init that is needed before ipath_f_bus is
1609 * called 1616 * called
1610 */ 1617 */
1611 ipath_init_ht_variables(); 1618 ipath_init_ht_variables(dd);
1612} 1619}
diff --git a/drivers/infiniband/hw/ipath/ipath_iba6120.c b/drivers/infiniband/hw/ipath/ipath_iba6120.c
index d86516d23df6..a72ab9de386a 100644
--- a/drivers/infiniband/hw/ipath/ipath_iba6120.c
+++ b/drivers/infiniband/hw/ipath/ipath_iba6120.c
@@ -263,8 +263,8 @@ static const struct ipath_cregs ipath_pe_cregs = {
263}; 263};
264 264
265/* kr_intstatus, kr_intclear, kr_intmask bits */ 265/* kr_intstatus, kr_intclear, kr_intmask bits */
266#define INFINIPATH_I_RCVURG_MASK 0x1F 266#define INFINIPATH_I_RCVURG_MASK ((1U<<5)-1)
267#define INFINIPATH_I_RCVAVAIL_MASK 0x1F 267#define INFINIPATH_I_RCVAVAIL_MASK ((1U<<5)-1)
268 268
269/* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */ 269/* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
270#define INFINIPATH_HWE_PCIEMEMPARITYERR_MASK 0x000000000000003fULL 270#define INFINIPATH_HWE_PCIEMEMPARITYERR_MASK 0x000000000000003fULL
@@ -294,6 +294,33 @@ static const struct ipath_cregs ipath_pe_cregs = {
294#define IPATH_GPIO_SCL (1ULL << \ 294#define IPATH_GPIO_SCL (1ULL << \
295 (_IPATH_GPIO_SCL_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT)) 295 (_IPATH_GPIO_SCL_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
296 296
297/*
298 * Rev2 silicon allows suppressing check for ArmLaunch errors.
299 * this can speed up short packet sends on systems that do
300 * not guaranteee write-order.
301 */
302#define INFINIPATH_XGXS_SUPPRESS_ARMLAUNCH_ERR (1ULL<<63)
303
304/* 6120 specific hardware errors... */
305static const struct ipath_hwerror_msgs ipath_6120_hwerror_msgs[] = {
306 INFINIPATH_HWE_MSG(PCIEPOISONEDTLP, "PCIe Poisoned TLP"),
307 INFINIPATH_HWE_MSG(PCIECPLTIMEOUT, "PCIe completion timeout"),
308 /*
309 * In practice, it's unlikely wthat we'll see PCIe PLL, or bus
310 * parity or memory parity error failures, because most likely we
311 * won't be able to talk to the core of the chip. Nonetheless, we
312 * might see them, if they are in parts of the PCIe core that aren't
313 * essential.
314 */
315 INFINIPATH_HWE_MSG(PCIE1PLLFAILED, "PCIePLL1"),
316 INFINIPATH_HWE_MSG(PCIE0PLLFAILED, "PCIePLL0"),
317 INFINIPATH_HWE_MSG(PCIEBUSPARITYXTLH, "PCIe XTLH core parity"),
318 INFINIPATH_HWE_MSG(PCIEBUSPARITYXADM, "PCIe ADM TX core parity"),
319 INFINIPATH_HWE_MSG(PCIEBUSPARITYRADM, "PCIe ADM RX core parity"),
320 INFINIPATH_HWE_MSG(RXDSYNCMEMPARITYERR, "Rx Dsync"),
321 INFINIPATH_HWE_MSG(SERDESPLLFAILED, "SerDes PLL"),
322};
323
297/** 324/**
298 * ipath_pe_handle_hwerrors - display hardware errors. 325 * ipath_pe_handle_hwerrors - display hardware errors.
299 * @dd: the infinipath device 326 * @dd: the infinipath device
@@ -343,19 +370,49 @@ static void ipath_pe_handle_hwerrors(struct ipath_devdata *dd, char *msg,
343 * make sure we get this much out, unless told to be quiet, 370 * make sure we get this much out, unless told to be quiet,
344 * or it's occurred within the last 5 seconds 371 * or it's occurred within the last 5 seconds
345 */ 372 */
346 if ((hwerrs & ~dd->ipath_lasthwerror) || 373 if ((hwerrs & ~(dd->ipath_lasthwerror |
374 ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF |
375 INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC)
376 << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT))) ||
347 (ipath_debug & __IPATH_VERBDBG)) 377 (ipath_debug & __IPATH_VERBDBG))
348 dev_info(&dd->pcidev->dev, "Hardware error: hwerr=0x%llx " 378 dev_info(&dd->pcidev->dev, "Hardware error: hwerr=0x%llx "
349 "(cleared)\n", (unsigned long long) hwerrs); 379 "(cleared)\n", (unsigned long long) hwerrs);
350 dd->ipath_lasthwerror |= hwerrs; 380 dd->ipath_lasthwerror |= hwerrs;
351 381
352 if (hwerrs & ~infinipath_hwe_bitsextant) 382 if (hwerrs & ~dd->ipath_hwe_bitsextant)
353 ipath_dev_err(dd, "hwerror interrupt with unknown errors " 383 ipath_dev_err(dd, "hwerror interrupt with unknown errors "
354 "%llx set\n", (unsigned long long) 384 "%llx set\n", (unsigned long long)
355 (hwerrs & ~infinipath_hwe_bitsextant)); 385 (hwerrs & ~dd->ipath_hwe_bitsextant));
356 386
357 ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control); 387 ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);
358 if (ctrl & INFINIPATH_C_FREEZEMODE) { 388 if (ctrl & INFINIPATH_C_FREEZEMODE) {
389 /*
390 * parity errors in send memory are recoverable,
391 * just cancel the send (if indicated in * sendbuffererror),
392 * count the occurrence, unfreeze (if no other handled
393 * hardware error bits are set), and continue. They can
394 * occur if a processor speculative read is done to the PIO
395 * buffer while we are sending a packet, for example.
396 */
397 if (hwerrs & ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF |
398 INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC)
399 << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT)) {
400 ipath_stats.sps_txeparity++;
401 ipath_dbg("Recovering from TXE parity error (%llu), "
402 "hwerrstatus=%llx\n",
403 (unsigned long long) ipath_stats.sps_txeparity,
404 (unsigned long long) hwerrs);
405 ipath_disarm_senderrbufs(dd);
406 hwerrs &= ~((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF |
407 INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC)
408 << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT);
409 if (!hwerrs) { /* else leave in freeze mode */
410 ipath_write_kreg(dd,
411 dd->ipath_kregs->kr_control,
412 dd->ipath_control);
413 return;
414 }
415 }
359 if (hwerrs) { 416 if (hwerrs) {
360 /* 417 /*
361 * if any set that we aren't ignoring only make the 418 * if any set that we aren't ignoring only make the
@@ -379,9 +436,8 @@ static void ipath_pe_handle_hwerrors(struct ipath_devdata *dd, char *msg,
379 } else { 436 } else {
380 ipath_dbg("Clearing freezemode on ignored hardware " 437 ipath_dbg("Clearing freezemode on ignored hardware "
381 "error\n"); 438 "error\n");
382 ctrl &= ~INFINIPATH_C_FREEZEMODE;
383 ipath_write_kreg(dd, dd->ipath_kregs->kr_control, 439 ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
384 ctrl); 440 dd->ipath_control);
385 } 441 }
386 } 442 }
387 443
@@ -396,24 +452,13 @@ static void ipath_pe_handle_hwerrors(struct ipath_devdata *dd, char *msg,
396 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask, 452 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
397 dd->ipath_hwerrmask); 453 dd->ipath_hwerrmask);
398 } 454 }
399 if (hwerrs & (INFINIPATH_HWE_RXEMEMPARITYERR_MASK 455
400 << INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT)) { 456 ipath_format_hwerrors(hwerrs,
401 bits = (u32) ((hwerrs >> 457 ipath_6120_hwerror_msgs,
402 INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) & 458 sizeof(ipath_6120_hwerror_msgs)/
403 INFINIPATH_HWE_RXEMEMPARITYERR_MASK); 459 sizeof(ipath_6120_hwerror_msgs[0]),
404 snprintf(bitsmsg, sizeof bitsmsg, "[RXE Parity Errs %x] ", 460 msg, msgl);
405 bits); 461
406 strlcat(msg, bitsmsg, msgl);
407 }
408 if (hwerrs & (INFINIPATH_HWE_TXEMEMPARITYERR_MASK
409 << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT)) {
410 bits = (u32) ((hwerrs >>
411 INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) &
412 INFINIPATH_HWE_TXEMEMPARITYERR_MASK);
413 snprintf(bitsmsg, sizeof bitsmsg, "[TXE Parity Errs %x] ",
414 bits);
415 strlcat(msg, bitsmsg, msgl);
416 }
417 if (hwerrs & (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK 462 if (hwerrs & (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK
418 << INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT)) { 463 << INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT)) {
419 bits = (u32) ((hwerrs >> 464 bits = (u32) ((hwerrs >>
@@ -423,10 +468,6 @@ static void ipath_pe_handle_hwerrors(struct ipath_devdata *dd, char *msg,
423 "[PCIe Mem Parity Errs %x] ", bits); 468 "[PCIe Mem Parity Errs %x] ", bits);
424 strlcat(msg, bitsmsg, msgl); 469 strlcat(msg, bitsmsg, msgl);
425 } 470 }
426 if (hwerrs & INFINIPATH_HWE_IBCBUSTOSPCPARITYERR)
427 strlcat(msg, "[IB2IPATH Parity]", msgl);
428 if (hwerrs & INFINIPATH_HWE_IBCBUSFRSPCPARITYERR)
429 strlcat(msg, "[IPATH2IB Parity]", msgl);
430 471
431#define _IPATH_PLL_FAIL (INFINIPATH_HWE_COREPLL_FBSLIP | \ 472#define _IPATH_PLL_FAIL (INFINIPATH_HWE_COREPLL_FBSLIP | \
432 INFINIPATH_HWE_COREPLL_RFSLIP ) 473 INFINIPATH_HWE_COREPLL_RFSLIP )
@@ -452,34 +493,6 @@ static void ipath_pe_handle_hwerrors(struct ipath_devdata *dd, char *msg,
452 dd->ipath_hwerrmask); 493 dd->ipath_hwerrmask);
453 } 494 }
454 495
455 if (hwerrs & INFINIPATH_HWE_PCIEPOISONEDTLP)
456 strlcat(msg, "[PCIe Poisoned TLP]", msgl);
457 if (hwerrs & INFINIPATH_HWE_PCIECPLTIMEOUT)
458 strlcat(msg, "[PCIe completion timeout]", msgl);
459
460 /*
461 * In practice, it's unlikely wthat we'll see PCIe PLL, or bus
462 * parity or memory parity error failures, because most likely we
463 * won't be able to talk to the core of the chip. Nonetheless, we
464 * might see them, if they are in parts of the PCIe core that aren't
465 * essential.
466 */
467 if (hwerrs & INFINIPATH_HWE_PCIE1PLLFAILED)
468 strlcat(msg, "[PCIePLL1]", msgl);
469 if (hwerrs & INFINIPATH_HWE_PCIE0PLLFAILED)
470 strlcat(msg, "[PCIePLL0]", msgl);
471 if (hwerrs & INFINIPATH_HWE_PCIEBUSPARITYXTLH)
472 strlcat(msg, "[PCIe XTLH core parity]", msgl);
473 if (hwerrs & INFINIPATH_HWE_PCIEBUSPARITYXADM)
474 strlcat(msg, "[PCIe ADM TX core parity]", msgl);
475 if (hwerrs & INFINIPATH_HWE_PCIEBUSPARITYRADM)
476 strlcat(msg, "[PCIe ADM RX core parity]", msgl);
477
478 if (hwerrs & INFINIPATH_HWE_RXDSYNCMEMPARITYERR)
479 strlcat(msg, "[Rx Dsync]", msgl);
480 if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED)
481 strlcat(msg, "[SerDes PLL]", msgl);
482
483 ipath_dev_err(dd, "%s hardware error\n", msg); 496 ipath_dev_err(dd, "%s hardware error\n", msg);
484 if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg) { 497 if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg) {
485 /* 498 /*
@@ -525,6 +538,9 @@ static int ipath_pe_boardname(struct ipath_devdata *dd, char *name,
525 case 5: 538 case 5:
526 n = "InfiniPath_QMH7140"; 539 n = "InfiniPath_QMH7140";
527 break; 540 break;
541 case 6:
542 n = "InfiniPath_QLE7142";
543 break;
528 default: 544 default:
529 ipath_dev_err(dd, 545 ipath_dev_err(dd,
530 "Don't yet know about board with ID %u\n", 546 "Don't yet know about board with ID %u\n",
@@ -571,9 +587,12 @@ static void ipath_pe_init_hwerrors(struct ipath_devdata *dd)
571 if (!dd->ipath_boardrev) // no PLL for Emulator 587 if (!dd->ipath_boardrev) // no PLL for Emulator
572 val &= ~INFINIPATH_HWE_SERDESPLLFAILED; 588 val &= ~INFINIPATH_HWE_SERDESPLLFAILED;
573 589
574 /* workaround bug 9460 in internal interface bus parity checking */ 590 if (dd->ipath_minrev < 2) {
575 val &= ~INFINIPATH_HWE_PCIEBUSPARITYRADM; 591 /* workaround bug 9460 in internal interface bus parity
576 592 * checking. Fixed (HW bug 9490) in Rev2.
593 */
594 val &= ~INFINIPATH_HWE_PCIEBUSPARITYRADM;
595 }
577 dd->ipath_hwerrmask = val; 596 dd->ipath_hwerrmask = val;
578} 597}
579 598
@@ -583,8 +602,8 @@ static void ipath_pe_init_hwerrors(struct ipath_devdata *dd)
583 */ 602 */
584static int ipath_pe_bringup_serdes(struct ipath_devdata *dd) 603static int ipath_pe_bringup_serdes(struct ipath_devdata *dd)
585{ 604{
586 u64 val, tmp, config1; 605 u64 val, tmp, config1, prev_val;
587 int ret = 0, change = 0; 606 int ret = 0;
588 607
589 ipath_dbg("Trying to bringup serdes\n"); 608 ipath_dbg("Trying to bringup serdes\n");
590 609
@@ -641,6 +660,7 @@ static int ipath_pe_bringup_serdes(struct ipath_devdata *dd)
641 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch); 660 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
642 661
643 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig); 662 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
663 prev_val = val;
644 if (((val >> INFINIPATH_XGXS_MDIOADDR_SHIFT) & 664 if (((val >> INFINIPATH_XGXS_MDIOADDR_SHIFT) &
645 INFINIPATH_XGXS_MDIOADDR_MASK) != 3) { 665 INFINIPATH_XGXS_MDIOADDR_MASK) != 3) {
646 val &= 666 val &=
@@ -648,11 +668,9 @@ static int ipath_pe_bringup_serdes(struct ipath_devdata *dd)
648 INFINIPATH_XGXS_MDIOADDR_SHIFT); 668 INFINIPATH_XGXS_MDIOADDR_SHIFT);
649 /* MDIO address 3 */ 669 /* MDIO address 3 */
650 val |= 3ULL << INFINIPATH_XGXS_MDIOADDR_SHIFT; 670 val |= 3ULL << INFINIPATH_XGXS_MDIOADDR_SHIFT;
651 change = 1;
652 } 671 }
653 if (val & INFINIPATH_XGXS_RESET) { 672 if (val & INFINIPATH_XGXS_RESET) {
654 val &= ~INFINIPATH_XGXS_RESET; 673 val &= ~INFINIPATH_XGXS_RESET;
655 change = 1;
656 } 674 }
657 if (((val >> INFINIPATH_XGXS_RX_POL_SHIFT) & 675 if (((val >> INFINIPATH_XGXS_RX_POL_SHIFT) &
658 INFINIPATH_XGXS_RX_POL_MASK) != dd->ipath_rx_pol_inv ) { 676 INFINIPATH_XGXS_RX_POL_MASK) != dd->ipath_rx_pol_inv ) {
@@ -661,9 +679,19 @@ static int ipath_pe_bringup_serdes(struct ipath_devdata *dd)
661 INFINIPATH_XGXS_RX_POL_SHIFT); 679 INFINIPATH_XGXS_RX_POL_SHIFT);
662 val |= dd->ipath_rx_pol_inv << 680 val |= dd->ipath_rx_pol_inv <<
663 INFINIPATH_XGXS_RX_POL_SHIFT; 681 INFINIPATH_XGXS_RX_POL_SHIFT;
664 change = 1;
665 } 682 }
666 if (change) 683 if (dd->ipath_minrev >= 2) {
684 /* Rev 2. can tolerate multiple writes to PBC, and
685 * allowing them can provide lower latency on some
686 * CPUs, but this feature is off by default, only
687 * turned on by setting D63 of XGXSconfig reg.
688 * May want to make this conditional more
689 * fine-grained in future. This is not exactly
690 * related to XGXS, but where the bit ended up.
691 */
692 val |= INFINIPATH_XGXS_SUPPRESS_ARMLAUNCH_ERR;
693 }
694 if (val != prev_val)
667 ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val); 695 ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
668 696
669 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0); 697 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
@@ -717,9 +745,25 @@ static void ipath_pe_quiet_serdes(struct ipath_devdata *dd)
717 ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val); 745 ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
718} 746}
719 747
720/* this is not yet needed on this chip, so just return 0. */
721static int ipath_pe_intconfig(struct ipath_devdata *dd) 748static int ipath_pe_intconfig(struct ipath_devdata *dd)
722{ 749{
750 u64 val;
751 u32 chiprev;
752
753 /*
754 * If the chip supports added error indication via GPIO pins,
755 * enable interrupts on those bits so the interrupt routine
756 * can count the events. Also set flag so interrupt routine
757 * can know they are expected.
758 */
759 chiprev = dd->ipath_revision >> INFINIPATH_R_CHIPREVMINOR_SHIFT;
760 if ((chiprev & INFINIPATH_R_CHIPREVMINOR_MASK) > 1) {
761 /* Rev2+ reports extra errors via internal GPIO pins */
762 dd->ipath_flags |= IPATH_GPIO_ERRINTRS;
763 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_gpio_mask);
764 val |= IPATH_GPIO_ERRINTR_MASK;
765 ipath_write_kreg( dd, dd->ipath_kregs->kr_gpio_mask, val);
766 }
723 return 0; 767 return 0;
724} 768}
725 769
@@ -853,21 +897,23 @@ static int ipath_setup_pe_config(struct ipath_devdata *dd,
853 return 0; 897 return 0;
854} 898}
855 899
856static void ipath_init_pe_variables(void) 900static void ipath_init_pe_variables(struct ipath_devdata *dd)
857{ 901{
858 /* 902 /*
859 * bits for selecting i2c direction and values, 903 * bits for selecting i2c direction and values,
860 * used for I2C serial flash 904 * used for I2C serial flash
861 */ 905 */
862 ipath_gpio_sda_num = _IPATH_GPIO_SDA_NUM; 906 dd->ipath_gpio_sda_num = _IPATH_GPIO_SDA_NUM;
863 ipath_gpio_scl_num = _IPATH_GPIO_SCL_NUM; 907 dd->ipath_gpio_scl_num = _IPATH_GPIO_SCL_NUM;
864 ipath_gpio_sda = IPATH_GPIO_SDA; 908 dd->ipath_gpio_sda = IPATH_GPIO_SDA;
865 ipath_gpio_scl = IPATH_GPIO_SCL; 909 dd->ipath_gpio_scl = IPATH_GPIO_SCL;
866 910
867 /* variables for sanity checking interrupt and errors */ 911 /* variables for sanity checking interrupt and errors */
868 infinipath_hwe_bitsextant = 912 dd->ipath_hwe_bitsextant =
869 (INFINIPATH_HWE_RXEMEMPARITYERR_MASK << 913 (INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
870 INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) | 914 INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) |
915 (INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
916 INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) |
871 (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK << 917 (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK <<
872 INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) | 918 INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) |
873 INFINIPATH_HWE_PCIE1PLLFAILED | 919 INFINIPATH_HWE_PCIE1PLLFAILED |
@@ -883,13 +929,13 @@ static void ipath_init_pe_variables(void)
883 INFINIPATH_HWE_SERDESPLLFAILED | 929 INFINIPATH_HWE_SERDESPLLFAILED |
884 INFINIPATH_HWE_IBCBUSTOSPCPARITYERR | 930 INFINIPATH_HWE_IBCBUSTOSPCPARITYERR |
885 INFINIPATH_HWE_IBCBUSFRSPCPARITYERR; 931 INFINIPATH_HWE_IBCBUSFRSPCPARITYERR;
886 infinipath_i_bitsextant = 932 dd->ipath_i_bitsextant =
887 (INFINIPATH_I_RCVURG_MASK << INFINIPATH_I_RCVURG_SHIFT) | 933 (INFINIPATH_I_RCVURG_MASK << INFINIPATH_I_RCVURG_SHIFT) |
888 (INFINIPATH_I_RCVAVAIL_MASK << 934 (INFINIPATH_I_RCVAVAIL_MASK <<
889 INFINIPATH_I_RCVAVAIL_SHIFT) | 935 INFINIPATH_I_RCVAVAIL_SHIFT) |
890 INFINIPATH_I_ERROR | INFINIPATH_I_SPIOSENT | 936 INFINIPATH_I_ERROR | INFINIPATH_I_SPIOSENT |
891 INFINIPATH_I_SPIOBUFAVAIL | INFINIPATH_I_GPIO; 937 INFINIPATH_I_SPIOBUFAVAIL | INFINIPATH_I_GPIO;
892 infinipath_e_bitsextant = 938 dd->ipath_e_bitsextant =
893 INFINIPATH_E_RFORMATERR | INFINIPATH_E_RVCRC | 939 INFINIPATH_E_RFORMATERR | INFINIPATH_E_RVCRC |
894 INFINIPATH_E_RICRC | INFINIPATH_E_RMINPKTLEN | 940 INFINIPATH_E_RICRC | INFINIPATH_E_RMINPKTLEN |
895 INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RLONGPKTLEN | 941 INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RLONGPKTLEN |
@@ -907,8 +953,8 @@ static void ipath_init_pe_variables(void)
907 INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET | 953 INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET |
908 INFINIPATH_E_HARDWARE; 954 INFINIPATH_E_HARDWARE;
909 955
910 infinipath_i_rcvavail_mask = INFINIPATH_I_RCVAVAIL_MASK; 956 dd->ipath_i_rcvavail_mask = INFINIPATH_I_RCVAVAIL_MASK;
911 infinipath_i_rcvurg_mask = INFINIPATH_I_RCVURG_MASK; 957 dd->ipath_i_rcvurg_mask = INFINIPATH_I_RCVURG_MASK;
912} 958}
913 959
914/* setup the MSI stuff again after a reset. I'd like to just call 960/* setup the MSI stuff again after a reset. I'd like to just call
@@ -1082,6 +1128,45 @@ static void ipath_pe_put_tid(struct ipath_devdata *dd, u64 __iomem *tidptr,
1082 mmiowb(); 1128 mmiowb();
1083 spin_unlock_irqrestore(&dd->ipath_tid_lock, flags); 1129 spin_unlock_irqrestore(&dd->ipath_tid_lock, flags);
1084} 1130}
1131/**
1132 * ipath_pe_put_tid_2 - write a TID in chip, Revision 2 or higher
1133 * @dd: the infinipath device
1134 * @tidptr: pointer to the expected TID (in chip) to udpate
1135 * @tidtype: 0 for eager, 1 for expected
1136 * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
1137 *
1138 * This exists as a separate routine to allow for selection of the
1139 * appropriate "flavor". The static calls in cleanup just use the
1140 * revision-agnostic form, as they are not performance critical.
1141 */
1142static void ipath_pe_put_tid_2(struct ipath_devdata *dd, u64 __iomem *tidptr,
1143 u32 type, unsigned long pa)
1144{
1145 u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
1146
1147 if (pa != dd->ipath_tidinvalid) {
1148 if (pa & ((1U << 11) - 1)) {
1149 dev_info(&dd->pcidev->dev, "BUG: physaddr %lx "
1150 "not 2KB aligned!\n", pa);
1151 return;
1152 }
1153 pa >>= 11;
1154 /* paranoia check */
1155 if (pa & (7<<29))
1156 ipath_dev_err(dd,
1157 "BUG: Physical page address 0x%lx "
1158 "has bits set in 31-29\n", pa);
1159
1160 if (type == 0)
1161 pa |= dd->ipath_tidtemplate;
1162 else /* for now, always full 4KB page */
1163 pa |= 2 << 29;
1164 }
1165 if (dd->ipath_kregbase)
1166 writel(pa, tidp32);
1167 mmiowb();
1168}
1169
1085 1170
1086/** 1171/**
1087 * ipath_pe_clear_tid - clear all TID entries for a port, expected and eager 1172 * ipath_pe_clear_tid - clear all TID entries for a port, expected and eager
@@ -1203,7 +1288,7 @@ int __attribute__((weak)) ipath_unordered_wc(void)
1203 1288
1204/** 1289/**
1205 * ipath_init_pe_get_base_info - set chip-specific flags for user code 1290 * ipath_init_pe_get_base_info - set chip-specific flags for user code
1206 * @dd: the infinipath device 1291 * @pd: the infinipath port
1207 * @kbase: ipath_base_info pointer 1292 * @kbase: ipath_base_info pointer
1208 * 1293 *
1209 * We set the PCIE flag because the lower bandwidth on PCIe vs 1294 * We set the PCIE flag because the lower bandwidth on PCIe vs
@@ -1212,6 +1297,7 @@ int __attribute__((weak)) ipath_unordered_wc(void)
1212static int ipath_pe_get_base_info(struct ipath_portdata *pd, void *kbase) 1297static int ipath_pe_get_base_info(struct ipath_portdata *pd, void *kbase)
1213{ 1298{
1214 struct ipath_base_info *kinfo = kbase; 1299 struct ipath_base_info *kinfo = kbase;
1300 struct ipath_devdata *dd;
1215 1301
1216 if (ipath_unordered_wc()) { 1302 if (ipath_unordered_wc()) {
1217 kinfo->spi_runtime_flags |= IPATH_RUNTIME_FORCE_WC_ORDER; 1303 kinfo->spi_runtime_flags |= IPATH_RUNTIME_FORCE_WC_ORDER;
@@ -1220,8 +1306,20 @@ static int ipath_pe_get_base_info(struct ipath_portdata *pd, void *kbase)
1220 else 1306 else
1221 ipath_cdbg(PROC, "Not Intel processor, WC ordered\n"); 1307 ipath_cdbg(PROC, "Not Intel processor, WC ordered\n");
1222 1308
1223 kinfo->spi_runtime_flags |= IPATH_RUNTIME_PCIE; 1309 if (pd == NULL)
1310 goto done;
1224 1311
1312 dd = pd->port_dd;
1313
1314 if (dd != NULL && dd->ipath_minrev >= 2) {
1315 ipath_cdbg(PROC, "IBA6120 Rev2, allow multiple PBC write\n");
1316 kinfo->spi_runtime_flags |= IPATH_RUNTIME_PBC_REWRITE;
1317 ipath_cdbg(PROC, "IBA6120 Rev2, allow loose DMA alignment\n");
1318 kinfo->spi_runtime_flags |= IPATH_RUNTIME_LOOSE_DMA_ALIGN;
1319 }
1320
1321done:
1322 kinfo->spi_runtime_flags |= IPATH_RUNTIME_PCIE;
1225 return 0; 1323 return 0;
1226} 1324}
1227 1325
@@ -1244,7 +1342,10 @@ void ipath_init_iba6120_funcs(struct ipath_devdata *dd)
1244 dd->ipath_f_quiet_serdes = ipath_pe_quiet_serdes; 1342 dd->ipath_f_quiet_serdes = ipath_pe_quiet_serdes;
1245 dd->ipath_f_bringup_serdes = ipath_pe_bringup_serdes; 1343 dd->ipath_f_bringup_serdes = ipath_pe_bringup_serdes;
1246 dd->ipath_f_clear_tids = ipath_pe_clear_tids; 1344 dd->ipath_f_clear_tids = ipath_pe_clear_tids;
1247 dd->ipath_f_put_tid = ipath_pe_put_tid; 1345 if (dd->ipath_minrev >= 2)
1346 dd->ipath_f_put_tid = ipath_pe_put_tid_2;
1347 else
1348 dd->ipath_f_put_tid = ipath_pe_put_tid;
1248 dd->ipath_f_cleanup = ipath_setup_pe_cleanup; 1349 dd->ipath_f_cleanup = ipath_setup_pe_cleanup;
1249 dd->ipath_f_setextled = ipath_setup_pe_setextled; 1350 dd->ipath_f_setextled = ipath_setup_pe_setextled;
1250 dd->ipath_f_get_base_info = ipath_pe_get_base_info; 1351 dd->ipath_f_get_base_info = ipath_pe_get_base_info;
@@ -1259,6 +1360,6 @@ void ipath_init_iba6120_funcs(struct ipath_devdata *dd)
1259 dd->ipath_kregs = &ipath_pe_kregs; 1360 dd->ipath_kregs = &ipath_pe_kregs;
1260 dd->ipath_cregs = &ipath_pe_cregs; 1361 dd->ipath_cregs = &ipath_pe_cregs;
1261 1362
1262 ipath_init_pe_variables(); 1363 ipath_init_pe_variables(dd);
1263} 1364}
1264 1365
diff --git a/drivers/infiniband/hw/ipath/ipath_init_chip.c b/drivers/infiniband/hw/ipath/ipath_init_chip.c
index 44669dc2e22d..d819cca524cd 100644
--- a/drivers/infiniband/hw/ipath/ipath_init_chip.c
+++ b/drivers/infiniband/hw/ipath/ipath_init_chip.c
@@ -88,13 +88,13 @@ MODULE_PARM_DESC(kpiobufs, "Set number of PIO buffers for driver");
88static int create_port0_egr(struct ipath_devdata *dd) 88static int create_port0_egr(struct ipath_devdata *dd)
89{ 89{
90 unsigned e, egrcnt; 90 unsigned e, egrcnt;
91 struct sk_buff **skbs; 91 struct ipath_skbinfo *skbinfo;
92 int ret; 92 int ret;
93 93
94 egrcnt = dd->ipath_rcvegrcnt; 94 egrcnt = dd->ipath_rcvegrcnt;
95 95
96 skbs = vmalloc(sizeof(*dd->ipath_port0_skbs) * egrcnt); 96 skbinfo = vmalloc(sizeof(*dd->ipath_port0_skbinfo) * egrcnt);
97 if (skbs == NULL) { 97 if (skbinfo == NULL) {
98 ipath_dev_err(dd, "allocation error for eager TID " 98 ipath_dev_err(dd, "allocation error for eager TID "
99 "skb array\n"); 99 "skb array\n");
100 ret = -ENOMEM; 100 ret = -ENOMEM;
@@ -109,13 +109,13 @@ static int create_port0_egr(struct ipath_devdata *dd)
109 * 4 bytes so that the data buffer stays word aligned. 109 * 4 bytes so that the data buffer stays word aligned.
110 * See ipath_kreceive() for more details. 110 * See ipath_kreceive() for more details.
111 */ 111 */
112 skbs[e] = ipath_alloc_skb(dd, GFP_KERNEL); 112 skbinfo[e].skb = ipath_alloc_skb(dd, GFP_KERNEL);
113 if (!skbs[e]) { 113 if (!skbinfo[e].skb) {
114 ipath_dev_err(dd, "SKB allocation error for " 114 ipath_dev_err(dd, "SKB allocation error for "
115 "eager TID %u\n", e); 115 "eager TID %u\n", e);
116 while (e != 0) 116 while (e != 0)
117 dev_kfree_skb(skbs[--e]); 117 dev_kfree_skb(skbinfo[--e].skb);
118 vfree(skbs); 118 vfree(skbinfo);
119 ret = -ENOMEM; 119 ret = -ENOMEM;
120 goto bail; 120 goto bail;
121 } 121 }
@@ -124,14 +124,17 @@ static int create_port0_egr(struct ipath_devdata *dd)
124 * After loop above, so we can test non-NULL to see if ready 124 * After loop above, so we can test non-NULL to see if ready
125 * to use at receive, etc. 125 * to use at receive, etc.
126 */ 126 */
127 dd->ipath_port0_skbs = skbs; 127 dd->ipath_port0_skbinfo = skbinfo;
128 128
129 for (e = 0; e < egrcnt; e++) { 129 for (e = 0; e < egrcnt; e++) {
130 unsigned long phys = 130 dd->ipath_port0_skbinfo[e].phys =
131 virt_to_phys(dd->ipath_port0_skbs[e]->data); 131 ipath_map_single(dd->pcidev,
132 dd->ipath_port0_skbinfo[e].skb->data,
133 dd->ipath_ibmaxlen, PCI_DMA_FROMDEVICE);
132 dd->ipath_f_put_tid(dd, e + (u64 __iomem *) 134 dd->ipath_f_put_tid(dd, e + (u64 __iomem *)
133 ((char __iomem *) dd->ipath_kregbase + 135 ((char __iomem *) dd->ipath_kregbase +
134 dd->ipath_rcvegrbase), 0, phys); 136 dd->ipath_rcvegrbase), 0,
137 dd->ipath_port0_skbinfo[e].phys);
135 } 138 }
136 139
137 ret = 0; 140 ret = 0;
@@ -432,16 +435,33 @@ done:
432 */ 435 */
433static void init_shadow_tids(struct ipath_devdata *dd) 436static void init_shadow_tids(struct ipath_devdata *dd)
434{ 437{
435 dd->ipath_pageshadow = (struct page **) 438 struct page **pages;
436 vmalloc(dd->ipath_cfgports * dd->ipath_rcvtidcnt * 439 dma_addr_t *addrs;
440
441 pages = vmalloc(dd->ipath_cfgports * dd->ipath_rcvtidcnt *
437 sizeof(struct page *)); 442 sizeof(struct page *));
438 if (!dd->ipath_pageshadow) 443 if (!pages) {
439 ipath_dev_err(dd, "failed to allocate shadow page * " 444 ipath_dev_err(dd, "failed to allocate shadow page * "
440 "array, no expected sends!\n"); 445 "array, no expected sends!\n");
441 else 446 dd->ipath_pageshadow = NULL;
442 memset(dd->ipath_pageshadow, 0, 447 return;
443 dd->ipath_cfgports * dd->ipath_rcvtidcnt * 448 }
444 sizeof(struct page *)); 449
450 addrs = vmalloc(dd->ipath_cfgports * dd->ipath_rcvtidcnt *
451 sizeof(dma_addr_t));
452 if (!addrs) {
453 ipath_dev_err(dd, "failed to allocate shadow dma handle "
454 "array, no expected sends!\n");
455 vfree(dd->ipath_pageshadow);
456 dd->ipath_pageshadow = NULL;
457 return;
458 }
459
460 memset(pages, 0, dd->ipath_cfgports * dd->ipath_rcvtidcnt *
461 sizeof(struct page *));
462
463 dd->ipath_pageshadow = pages;
464 dd->ipath_physshadow = addrs;
445} 465}
446 466
447static void enable_chip(struct ipath_devdata *dd, 467static void enable_chip(struct ipath_devdata *dd,
diff --git a/drivers/infiniband/hw/ipath/ipath_intr.c b/drivers/infiniband/hw/ipath/ipath_intr.c
index 49bf7bb15b04..6bee53ce5f33 100644
--- a/drivers/infiniband/hw/ipath/ipath_intr.c
+++ b/drivers/infiniband/hw/ipath/ipath_intr.c
@@ -37,6 +37,50 @@
37#include "ipath_verbs.h" 37#include "ipath_verbs.h"
38#include "ipath_common.h" 38#include "ipath_common.h"
39 39
40/*
41 * Called when we might have an error that is specific to a particular
42 * PIO buffer, and may need to cancel that buffer, so it can be re-used.
43 */
44void ipath_disarm_senderrbufs(struct ipath_devdata *dd)
45{
46 u32 piobcnt;
47 unsigned long sbuf[4];
48 /*
49 * it's possible that sendbuffererror could have bits set; might
50 * have already done this as a result of hardware error handling
51 */
52 piobcnt = dd->ipath_piobcnt2k + dd->ipath_piobcnt4k;
53 /* read these before writing errorclear */
54 sbuf[0] = ipath_read_kreg64(
55 dd, dd->ipath_kregs->kr_sendbuffererror);
56 sbuf[1] = ipath_read_kreg64(
57 dd, dd->ipath_kregs->kr_sendbuffererror + 1);
58 if (piobcnt > 128) {
59 sbuf[2] = ipath_read_kreg64(
60 dd, dd->ipath_kregs->kr_sendbuffererror + 2);
61 sbuf[3] = ipath_read_kreg64(
62 dd, dd->ipath_kregs->kr_sendbuffererror + 3);
63 }
64
65 if (sbuf[0] || sbuf[1] || (piobcnt > 128 && (sbuf[2] || sbuf[3]))) {
66 int i;
67 if (ipath_debug & (__IPATH_PKTDBG|__IPATH_DBG)) {
68 __IPATH_DBG_WHICH(__IPATH_PKTDBG|__IPATH_DBG,
69 "SendbufErrs %lx %lx", sbuf[0],
70 sbuf[1]);
71 if (ipath_debug & __IPATH_PKTDBG && piobcnt > 128)
72 printk(" %lx %lx ", sbuf[2], sbuf[3]);
73 printk("\n");
74 }
75
76 for (i = 0; i < piobcnt; i++)
77 if (test_bit(i, sbuf))
78 ipath_disarm_piobufs(dd, i, 1);
79 dd->ipath_lastcancel = jiffies+3; /* no armlaunch for a bit */
80 }
81}
82
83
40/* These are all rcv-related errors which we want to count for stats */ 84/* These are all rcv-related errors which we want to count for stats */
41#define E_SUM_PKTERRS \ 85#define E_SUM_PKTERRS \
42 (INFINIPATH_E_RHDRLEN | INFINIPATH_E_RBADTID | \ 86 (INFINIPATH_E_RHDRLEN | INFINIPATH_E_RBADTID | \
@@ -68,53 +112,9 @@
68 112
69static u64 handle_e_sum_errs(struct ipath_devdata *dd, ipath_err_t errs) 113static u64 handle_e_sum_errs(struct ipath_devdata *dd, ipath_err_t errs)
70{ 114{
71 unsigned long sbuf[4];
72 u64 ignore_this_time = 0; 115 u64 ignore_this_time = 0;
73 u32 piobcnt;
74 116
75 /* if possible that sendbuffererror could be valid */ 117 ipath_disarm_senderrbufs(dd);
76 piobcnt = dd->ipath_piobcnt2k + dd->ipath_piobcnt4k;
77 /* read these before writing errorclear */
78 sbuf[0] = ipath_read_kreg64(
79 dd, dd->ipath_kregs->kr_sendbuffererror);
80 sbuf[1] = ipath_read_kreg64(
81 dd, dd->ipath_kregs->kr_sendbuffererror + 1);
82 if (piobcnt > 128) {
83 sbuf[2] = ipath_read_kreg64(
84 dd, dd->ipath_kregs->kr_sendbuffererror + 2);
85 sbuf[3] = ipath_read_kreg64(
86 dd, dd->ipath_kregs->kr_sendbuffererror + 3);
87 }
88
89 if (sbuf[0] || sbuf[1] || (piobcnt > 128 && (sbuf[2] || sbuf[3]))) {
90 int i;
91
92 ipath_cdbg(PKT, "SendbufErrs %lx %lx ", sbuf[0], sbuf[1]);
93 if (ipath_debug & __IPATH_PKTDBG && piobcnt > 128)
94 printk("%lx %lx ", sbuf[2], sbuf[3]);
95 for (i = 0; i < piobcnt; i++) {
96 if (test_bit(i, sbuf)) {
97 u32 __iomem *piobuf;
98 if (i < dd->ipath_piobcnt2k)
99 piobuf = (u32 __iomem *)
100 (dd->ipath_pio2kbase +
101 i * dd->ipath_palign);
102 else
103 piobuf = (u32 __iomem *)
104 (dd->ipath_pio4kbase +
105 (i - dd->ipath_piobcnt2k) *
106 dd->ipath_4kalign);
107
108 ipath_cdbg(PKT,
109 "PIObuf[%u] @%p pbc is %x; ",
110 i, piobuf, readl(piobuf));
111
112 ipath_disarm_piobufs(dd, i, 1);
113 }
114 }
115 if (ipath_debug & __IPATH_PKTDBG)
116 printk("\n");
117 }
118 if ((errs & E_SUM_LINK_PKTERRS) && 118 if ((errs & E_SUM_LINK_PKTERRS) &&
119 !(dd->ipath_flags & IPATH_LINKACTIVE)) { 119 !(dd->ipath_flags & IPATH_LINKACTIVE)) {
120 /* 120 /*
@@ -132,6 +132,82 @@ static u64 handle_e_sum_errs(struct ipath_devdata *dd, ipath_err_t errs)
132 return ignore_this_time; 132 return ignore_this_time;
133} 133}
134 134
135/* generic hw error messages... */
136#define INFINIPATH_HWE_TXEMEMPARITYERR_MSG(a) \
137 { \
138 .mask = ( INFINIPATH_HWE_TXEMEMPARITYERR_##a << \
139 INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT ), \
140 .msg = "TXE " #a " Memory Parity" \
141 }
142#define INFINIPATH_HWE_RXEMEMPARITYERR_MSG(a) \
143 { \
144 .mask = ( INFINIPATH_HWE_RXEMEMPARITYERR_##a << \
145 INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT ), \
146 .msg = "RXE " #a " Memory Parity" \
147 }
148
149static const struct ipath_hwerror_msgs ipath_generic_hwerror_msgs[] = {
150 INFINIPATH_HWE_MSG(IBCBUSFRSPCPARITYERR, "IPATH2IB Parity"),
151 INFINIPATH_HWE_MSG(IBCBUSTOSPCPARITYERR, "IB2IPATH Parity"),
152
153 INFINIPATH_HWE_TXEMEMPARITYERR_MSG(PIOBUF),
154 INFINIPATH_HWE_TXEMEMPARITYERR_MSG(PIOPBC),
155 INFINIPATH_HWE_TXEMEMPARITYERR_MSG(PIOLAUNCHFIFO),
156
157 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(RCVBUF),
158 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(LOOKUPQ),
159 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(EAGERTID),
160 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(EXPTID),
161 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(FLAGBUF),
162 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(DATAINFO),
163 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(HDRINFO),
164};
165
166/**
167 * ipath_format_hwmsg - format a single hwerror message
168 * @msg message buffer
169 * @msgl length of message buffer
170 * @hwmsg message to add to message buffer
171 */
172static void ipath_format_hwmsg(char *msg, size_t msgl, const char *hwmsg)
173{
174 strlcat(msg, "[", msgl);
175 strlcat(msg, hwmsg, msgl);
176 strlcat(msg, "]", msgl);
177}
178
179/**
180 * ipath_format_hwerrors - format hardware error messages for display
181 * @hwerrs hardware errors bit vector
182 * @hwerrmsgs hardware error descriptions
183 * @nhwerrmsgs number of hwerrmsgs
184 * @msg message buffer
185 * @msgl message buffer length
186 */
187void ipath_format_hwerrors(u64 hwerrs,
188 const struct ipath_hwerror_msgs *hwerrmsgs,
189 size_t nhwerrmsgs,
190 char *msg, size_t msgl)
191{
192 int i;
193 const int glen =
194 sizeof(ipath_generic_hwerror_msgs) /
195 sizeof(ipath_generic_hwerror_msgs[0]);
196
197 for (i=0; i<glen; i++) {
198 if (hwerrs & ipath_generic_hwerror_msgs[i].mask) {
199 ipath_format_hwmsg(msg, msgl,
200 ipath_generic_hwerror_msgs[i].msg);
201 }
202 }
203
204 for (i=0; i<nhwerrmsgs; i++) {
205 if (hwerrs & hwerrmsgs[i].mask) {
206 ipath_format_hwmsg(msg, msgl, hwerrmsgs[i].msg);
207 }
208 }
209}
210
135/* return the strings for the most common link states */ 211/* return the strings for the most common link states */
136static char *ib_linkstate(u32 linkstate) 212static char *ib_linkstate(u32 linkstate)
137{ 213{
@@ -404,10 +480,10 @@ static int handle_errors(struct ipath_devdata *dd, ipath_err_t errs)
404 dd->ipath_f_handle_hwerrors(dd, msg, sizeof msg); 480 dd->ipath_f_handle_hwerrors(dd, msg, sizeof msg);
405 } 481 }
406 482
407 if (!noprint && (errs & ~infinipath_e_bitsextant)) 483 if (!noprint && (errs & ~dd->ipath_e_bitsextant))
408 ipath_dev_err(dd, "error interrupt with unknown errors " 484 ipath_dev_err(dd, "error interrupt with unknown errors "
409 "%llx set\n", (unsigned long long) 485 "%llx set\n", (unsigned long long)
410 (errs & ~infinipath_e_bitsextant)); 486 (errs & ~dd->ipath_e_bitsextant));
411 487
412 if (errs & E_SUM_ERRS) 488 if (errs & E_SUM_ERRS)
413 ignore_this_time = handle_e_sum_errs(dd, errs); 489 ignore_this_time = handle_e_sum_errs(dd, errs);
@@ -478,6 +554,14 @@ static int handle_errors(struct ipath_devdata *dd, ipath_err_t errs)
478 ~(INFINIPATH_E_HARDWARE | 554 ~(INFINIPATH_E_HARDWARE |
479 INFINIPATH_E_IBSTATUSCHANGED); 555 INFINIPATH_E_IBSTATUSCHANGED);
480 } 556 }
557
558 /* likely due to cancel, so suppress */
559 if ((errs & (INFINIPATH_E_SPKTLEN | INFINIPATH_E_SPIOARMLAUNCH)) &&
560 dd->ipath_lastcancel > jiffies) {
561 ipath_dbg("Suppressed armlaunch/spktlen after error send cancel\n");
562 errs &= ~(INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SPKTLEN);
563 }
564
481 if (!errs) 565 if (!errs)
482 return 0; 566 return 0;
483 567
@@ -529,7 +613,7 @@ static int handle_errors(struct ipath_devdata *dd, ipath_err_t errs)
529 * don't report same point multiple times, 613 * don't report same point multiple times,
530 * except kernel 614 * except kernel
531 */ 615 */
532 tl = (u32) * pd->port_rcvhdrtail_kvaddr; 616 tl = *(u64 *) pd->port_rcvhdrtail_kvaddr;
533 if (tl == dd->ipath_lastrcvhdrqtails[i]) 617 if (tl == dd->ipath_lastrcvhdrqtails[i])
534 continue; 618 continue;
535 hd = ipath_read_ureg32(dd, ur_rcvhdrhead, 619 hd = ipath_read_ureg32(dd, ur_rcvhdrhead,
@@ -729,9 +813,9 @@ static void handle_urcv(struct ipath_devdata *dd, u32 istat)
729 int rcvdint = 0; 813 int rcvdint = 0;
730 814
731 portr = ((istat >> INFINIPATH_I_RCVAVAIL_SHIFT) & 815 portr = ((istat >> INFINIPATH_I_RCVAVAIL_SHIFT) &
732 infinipath_i_rcvavail_mask) 816 dd->ipath_i_rcvavail_mask)
733 | ((istat >> INFINIPATH_I_RCVURG_SHIFT) & 817 | ((istat >> INFINIPATH_I_RCVURG_SHIFT) &
734 infinipath_i_rcvurg_mask); 818 dd->ipath_i_rcvurg_mask);
735 for (i = 1; i < dd->ipath_cfgports; i++) { 819 for (i = 1; i < dd->ipath_cfgports; i++) {
736 struct ipath_portdata *pd = dd->ipath_pd[i]; 820 struct ipath_portdata *pd = dd->ipath_pd[i];
737 if (portr & (1 << i) && pd && pd->port_cnt && 821 if (portr & (1 << i) && pd && pd->port_cnt &&
@@ -808,7 +892,7 @@ irqreturn_t ipath_intr(int irq, void *data, struct pt_regs *regs)
808 if (oldhead != curtail) { 892 if (oldhead != curtail) {
809 if (dd->ipath_flags & IPATH_GPIO_INTR) { 893 if (dd->ipath_flags & IPATH_GPIO_INTR) {
810 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_clear, 894 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_clear,
811 (u64) (1 << 2)); 895 (u64) (1 << IPATH_GPIO_PORT0_BIT));
812 istat = port0rbits | INFINIPATH_I_GPIO; 896 istat = port0rbits | INFINIPATH_I_GPIO;
813 } 897 }
814 else 898 else
@@ -838,10 +922,10 @@ irqreturn_t ipath_intr(int irq, void *data, struct pt_regs *regs)
838 if (unexpected) 922 if (unexpected)
839 unexpected = 0; 923 unexpected = 0;
840 924
841 if (unlikely(istat & ~infinipath_i_bitsextant)) 925 if (unlikely(istat & ~dd->ipath_i_bitsextant))
842 ipath_dev_err(dd, 926 ipath_dev_err(dd,
843 "interrupt with unknown interrupts %x set\n", 927 "interrupt with unknown interrupts %x set\n",
844 istat & (u32) ~ infinipath_i_bitsextant); 928 istat & (u32) ~ dd->ipath_i_bitsextant);
845 else 929 else
846 ipath_cdbg(VERBOSE, "intr stat=0x%x\n", istat); 930 ipath_cdbg(VERBOSE, "intr stat=0x%x\n", istat);
847 931
@@ -867,26 +951,80 @@ irqreturn_t ipath_intr(int irq, void *data, struct pt_regs *regs)
867 951
868 if (istat & INFINIPATH_I_GPIO) { 952 if (istat & INFINIPATH_I_GPIO) {
869 /* 953 /*
870 * Packets are available in the port 0 rcv queue. 954 * GPIO interrupts fall in two broad classes:
871 * Eventually this needs to be generalized to check 955 * GPIO_2 indicates (on some HT4xx boards) that a packet
872 * IPATH_GPIO_INTR, and the specific GPIO bit, if 956 * has arrived for Port 0. Checking for this
873 * GPIO interrupts are used for anything else. 957 * is controlled by flag IPATH_GPIO_INTR.
958 * GPIO_3..5 on IBA6120 Rev2 chips indicate errors
959 * that we need to count. Checking for this
960 * is controlled by flag IPATH_GPIO_ERRINTRS.
874 */ 961 */
875 if (unlikely(!(dd->ipath_flags & IPATH_GPIO_INTR))) { 962 u32 gpiostatus;
876 u32 gpiostatus; 963 u32 to_clear = 0;
877 gpiostatus = ipath_read_kreg32( 964
878 dd, dd->ipath_kregs->kr_gpio_status); 965 gpiostatus = ipath_read_kreg32(
879 ipath_dbg("Unexpected GPIO interrupt bits %x\n", 966 dd, dd->ipath_kregs->kr_gpio_status);
880 gpiostatus); 967 /* First the error-counter case.
881 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_clear, 968 */
882 gpiostatus); 969 if ((gpiostatus & IPATH_GPIO_ERRINTR_MASK) &&
970 (dd->ipath_flags & IPATH_GPIO_ERRINTRS)) {
971 /* want to clear the bits we see asserted. */
972 to_clear |= (gpiostatus & IPATH_GPIO_ERRINTR_MASK);
973
974 /*
975 * Count appropriately, clear bits out of our copy,
976 * as they have been "handled".
977 */
978 if (gpiostatus & (1 << IPATH_GPIO_RXUVL_BIT)) {
979 ipath_dbg("FlowCtl on UnsupVL\n");
980 dd->ipath_rxfc_unsupvl_errs++;
981 }
982 if (gpiostatus & (1 << IPATH_GPIO_OVRUN_BIT)) {
983 ipath_dbg("Overrun Threshold exceeded\n");
984 dd->ipath_overrun_thresh_errs++;
985 }
986 if (gpiostatus & (1 << IPATH_GPIO_LLI_BIT)) {
987 ipath_dbg("Local Link Integrity error\n");
988 dd->ipath_lli_errs++;
989 }
990 gpiostatus &= ~IPATH_GPIO_ERRINTR_MASK;
883 } 991 }
884 else { 992 /* Now the Port0 Receive case */
885 /* Clear GPIO status bit 2 */ 993 if ((gpiostatus & (1 << IPATH_GPIO_PORT0_BIT)) &&
886 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_clear, 994 (dd->ipath_flags & IPATH_GPIO_INTR)) {
887 (u64) (1 << 2)); 995 /*
996 * GPIO status bit 2 is set, and we expected it.
997 * clear it and indicate in p0bits.
998 * This probably only happens if a Port0 pkt
999 * arrives at _just_ the wrong time, and we
1000 * handle that by seting chk0rcv;
1001 */
1002 to_clear |= (1 << IPATH_GPIO_PORT0_BIT);
1003 gpiostatus &= ~(1 << IPATH_GPIO_PORT0_BIT);
888 chk0rcv = 1; 1004 chk0rcv = 1;
889 } 1005 }
1006 if (unlikely(gpiostatus)) {
1007 /*
1008 * Some unexpected bits remain. If they could have
1009 * caused the interrupt, complain and clear.
1010 * MEA: this is almost certainly non-ideal.
1011 * we should look into auto-disable of unexpected
1012 * GPIO interrupts, possibly on a "three strikes"
1013 * basis.
1014 */
1015 u32 mask;
1016 mask = ipath_read_kreg32(
1017 dd, dd->ipath_kregs->kr_gpio_mask);
1018 if (mask & gpiostatus) {
1019 ipath_dbg("Unexpected GPIO IRQ bits %x\n",
1020 gpiostatus & mask);
1021 to_clear |= (gpiostatus & mask);
1022 }
1023 }
1024 if (to_clear) {
1025 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_clear,
1026 (u64) to_clear);
1027 }
890 } 1028 }
891 chk0rcv |= istat & port0rbits; 1029 chk0rcv |= istat & port0rbits;
892 1030
@@ -911,9 +1049,9 @@ irqreturn_t ipath_intr(int irq, void *data, struct pt_regs *regs)
911 istat &= ~port0rbits; 1049 istat &= ~port0rbits;
912 } 1050 }
913 1051
914 if (istat & ((infinipath_i_rcvavail_mask << 1052 if (istat & ((dd->ipath_i_rcvavail_mask <<
915 INFINIPATH_I_RCVAVAIL_SHIFT) 1053 INFINIPATH_I_RCVAVAIL_SHIFT)
916 | (infinipath_i_rcvurg_mask << 1054 | (dd->ipath_i_rcvurg_mask <<
917 INFINIPATH_I_RCVURG_SHIFT))) 1055 INFINIPATH_I_RCVURG_SHIFT)))
918 handle_urcv(dd, istat); 1056 handle_urcv(dd, istat);
919 1057
diff --git a/drivers/infiniband/hw/ipath/ipath_kernel.h b/drivers/infiniband/hw/ipath/ipath_kernel.h
index a8a56276ff1d..d7540b71b451 100644
--- a/drivers/infiniband/hw/ipath/ipath_kernel.h
+++ b/drivers/infiniband/hw/ipath/ipath_kernel.h
@@ -39,6 +39,8 @@
39 */ 39 */
40 40
41#include <linux/interrupt.h> 41#include <linux/interrupt.h>
42#include <linux/pci.h>
43#include <linux/dma-mapping.h>
42#include <asm/io.h> 44#include <asm/io.h>
43 45
44#include "ipath_common.h" 46#include "ipath_common.h"
@@ -62,7 +64,7 @@ struct ipath_portdata {
62 /* rcvhdrq base, needs mmap before useful */ 64 /* rcvhdrq base, needs mmap before useful */
63 void *port_rcvhdrq; 65 void *port_rcvhdrq;
64 /* kernel virtual address where hdrqtail is updated */ 66 /* kernel virtual address where hdrqtail is updated */
65 volatile __le64 *port_rcvhdrtail_kvaddr; 67 void *port_rcvhdrtail_kvaddr;
66 /* 68 /*
67 * temp buffer for expected send setup, allocated at open, instead 69 * temp buffer for expected send setup, allocated at open, instead
68 * of each setup call 70 * of each setup call
@@ -79,8 +81,8 @@ struct ipath_portdata {
79 dma_addr_t port_rcvhdrq_phys; 81 dma_addr_t port_rcvhdrq_phys;
80 dma_addr_t port_rcvhdrqtailaddr_phys; 82 dma_addr_t port_rcvhdrqtailaddr_phys;
81 /* 83 /*
82 * number of opens on this instance (0 or 1; ignoring forks, dup, 84 * number of opens (including slave subports) on this instance
83 * etc. for now) 85 * (ignoring forks, dup, etc. for now)
84 */ 86 */
85 int port_cnt; 87 int port_cnt;
86 /* 88 /*
@@ -89,6 +91,10 @@ struct ipath_portdata {
89 */ 91 */
90 /* instead of calculating it */ 92 /* instead of calculating it */
91 unsigned port_port; 93 unsigned port_port;
94 /* non-zero if port is being shared. */
95 u16 port_subport_cnt;
96 /* non-zero if port is being shared. */
97 u16 port_subport_id;
92 /* chip offset of PIO buffers for this port */ 98 /* chip offset of PIO buffers for this port */
93 u32 port_piobufs; 99 u32 port_piobufs;
94 /* how many alloc_pages() chunks in port_rcvegrbuf_pages */ 100 /* how many alloc_pages() chunks in port_rcvegrbuf_pages */
@@ -121,6 +127,16 @@ struct ipath_portdata {
121 u16 port_pkeys[4]; 127 u16 port_pkeys[4];
122 /* so file ops can get at unit */ 128 /* so file ops can get at unit */
123 struct ipath_devdata *port_dd; 129 struct ipath_devdata *port_dd;
130 /* A page of memory for rcvhdrhead, rcvegrhead, rcvegrtail * N */
131 void *subport_uregbase;
132 /* An array of pages for the eager receive buffers * N */
133 void *subport_rcvegrbuf;
134 /* An array of pages for the eager header queue entries * N */
135 void *subport_rcvhdr_base;
136 /* The version of the library which opened this port */
137 u32 userversion;
138 /* Bitmask of active slaves */
139 u32 active_slaves;
124}; 140};
125 141
126struct sk_buff; 142struct sk_buff;
@@ -132,6 +148,11 @@ struct _ipath_layer {
132 void *l_arg; 148 void *l_arg;
133}; 149};
134 150
151struct ipath_skbinfo {
152 struct sk_buff *skb;
153 dma_addr_t phys;
154};
155
135struct ipath_devdata { 156struct ipath_devdata {
136 struct list_head ipath_list; 157 struct list_head ipath_list;
137 158
@@ -154,7 +175,7 @@ struct ipath_devdata {
154 /* ipath_cfgports pointers */ 175 /* ipath_cfgports pointers */
155 struct ipath_portdata **ipath_pd; 176 struct ipath_portdata **ipath_pd;
156 /* sk_buffs used by port 0 eager receive queue */ 177 /* sk_buffs used by port 0 eager receive queue */
157 struct sk_buff **ipath_port0_skbs; 178 struct ipath_skbinfo *ipath_port0_skbinfo;
158 /* kvirt address of 1st 2k pio buffer */ 179 /* kvirt address of 1st 2k pio buffer */
159 void __iomem *ipath_pio2kbase; 180 void __iomem *ipath_pio2kbase;
160 /* kvirt address of 1st 4k pio buffer */ 181 /* kvirt address of 1st 4k pio buffer */
@@ -315,12 +336,16 @@ struct ipath_devdata {
315 u8 ipath_ht_slave_off; 336 u8 ipath_ht_slave_off;
316 /* for write combining settings */ 337 /* for write combining settings */
317 unsigned long ipath_wc_cookie; 338 unsigned long ipath_wc_cookie;
339 unsigned long ipath_wc_base;
340 unsigned long ipath_wc_len;
318 /* ref count for each pkey */ 341 /* ref count for each pkey */
319 atomic_t ipath_pkeyrefs[4]; 342 atomic_t ipath_pkeyrefs[4];
320 /* shadow copy of all exptids physaddr; used only by funcsim */ 343 /* shadow copy of all exptids physaddr; used only by funcsim */
321 u64 *ipath_tidsimshadow; 344 u64 *ipath_tidsimshadow;
322 /* shadow copy of struct page *'s for exp tid pages */ 345 /* shadow copy of struct page *'s for exp tid pages */
323 struct page **ipath_pageshadow; 346 struct page **ipath_pageshadow;
347 /* shadow copy of dma handles for exp tid pages */
348 dma_addr_t *ipath_physshadow;
324 /* lock to workaround chip bug 9437 */ 349 /* lock to workaround chip bug 9437 */
325 spinlock_t ipath_tid_lock; 350 spinlock_t ipath_tid_lock;
326 351
@@ -402,6 +427,9 @@ struct ipath_devdata {
402 unsigned long ipath_rcvctrl; 427 unsigned long ipath_rcvctrl;
403 /* shadow kr_sendctrl */ 428 /* shadow kr_sendctrl */
404 unsigned long ipath_sendctrl; 429 unsigned long ipath_sendctrl;
430 /* ports waiting for PIOavail intr */
431 unsigned long ipath_portpiowait;
432 unsigned long ipath_lastcancel; /* to not count armlaunch after cancel */
405 433
406 /* value we put in kr_rcvhdrcnt */ 434 /* value we put in kr_rcvhdrcnt */
407 u32 ipath_rcvhdrcnt; 435 u32 ipath_rcvhdrcnt;
@@ -465,8 +493,6 @@ struct ipath_devdata {
465 u32 ipath_htwidth; 493 u32 ipath_htwidth;
466 /* HT speed (200,400,800,1000) from HT config */ 494 /* HT speed (200,400,800,1000) from HT config */
467 u32 ipath_htspeed; 495 u32 ipath_htspeed;
468 /* ports waiting for PIOavail intr */
469 unsigned long ipath_portpiowait;
470 /* 496 /*
471 * number of sequential ibcstatus change for polling active/quiet 497 * number of sequential ibcstatus change for polling active/quiet
472 * (i.e., link not coming up). 498 * (i.e., link not coming up).
@@ -510,8 +536,47 @@ struct ipath_devdata {
510 u32 ipath_lli_counter; 536 u32 ipath_lli_counter;
511 /* local link integrity errors */ 537 /* local link integrity errors */
512 u32 ipath_lli_errors; 538 u32 ipath_lli_errors;
539 /*
540 * Above counts only cases where _successive_ LocalLinkIntegrity
541 * errors were seen in the receive headers of kern-packets.
542 * Below are the three (monotonically increasing) counters
543 * maintained via GPIO interrupts on iba6120-rev2.
544 */
545 u32 ipath_rxfc_unsupvl_errs;
546 u32 ipath_overrun_thresh_errs;
547 u32 ipath_lli_errs;
548
549 /*
550 * Not all devices managed by a driver instance are the same
551 * type, so these fields must be per-device.
552 */
553 u64 ipath_i_bitsextant;
554 ipath_err_t ipath_e_bitsextant;
555 ipath_err_t ipath_hwe_bitsextant;
556
557 /*
558 * Below should be computable from number of ports,
559 * since they are never modified.
560 */
561 u32 ipath_i_rcvavail_mask;
562 u32 ipath_i_rcvurg_mask;
563
564 /*
565 * Register bits for selecting i2c direction and values, used for
566 * I2C serial flash.
567 */
568 u16 ipath_gpio_sda_num;
569 u16 ipath_gpio_scl_num;
570 u64 ipath_gpio_sda;
571 u64 ipath_gpio_scl;
513}; 572};
514 573
574/* Private data for file operations */
575struct ipath_filedata {
576 struct ipath_portdata *pd;
577 unsigned subport;
578 unsigned tidcursor;
579};
515extern struct list_head ipath_dev_list; 580extern struct list_head ipath_dev_list;
516extern spinlock_t ipath_devs_lock; 581extern spinlock_t ipath_devs_lock;
517extern struct ipath_devdata *ipath_lookup(int unit); 582extern struct ipath_devdata *ipath_lookup(int unit);
@@ -521,6 +586,7 @@ int ipath_enable_wc(struct ipath_devdata *dd);
521void ipath_disable_wc(struct ipath_devdata *dd); 586void ipath_disable_wc(struct ipath_devdata *dd);
522int ipath_count_units(int *npresentp, int *nupp, u32 *maxportsp); 587int ipath_count_units(int *npresentp, int *nupp, u32 *maxportsp);
523void ipath_shutdown_device(struct ipath_devdata *); 588void ipath_shutdown_device(struct ipath_devdata *);
589void ipath_disarm_senderrbufs(struct ipath_devdata *);
524 590
525struct file_operations; 591struct file_operations;
526int ipath_cdev_init(int minor, char *name, struct file_operations *fops, 592int ipath_cdev_init(int minor, char *name, struct file_operations *fops,
@@ -572,7 +638,11 @@ int ipath_set_lid(struct ipath_devdata *, u32, u8);
572int ipath_set_rx_pol_inv(struct ipath_devdata *dd, u8 new_pol_inv); 638int ipath_set_rx_pol_inv(struct ipath_devdata *dd, u8 new_pol_inv);
573 639
574/* for use in system calls, where we want to know device type, etc. */ 640/* for use in system calls, where we want to know device type, etc. */
575#define port_fp(fp) ((struct ipath_portdata *) (fp)->private_data) 641#define port_fp(fp) ((struct ipath_filedata *)(fp)->private_data)->pd
642#define subport_fp(fp) \
643 ((struct ipath_filedata *)(fp)->private_data)->subport
644#define tidcursor_fp(fp) \
645 ((struct ipath_filedata *)(fp)->private_data)->tidcursor
576 646
577/* 647/*
578 * values for ipath_flags 648 * values for ipath_flags
@@ -612,6 +682,15 @@ int ipath_set_rx_pol_inv(struct ipath_devdata *dd, u8 new_pol_inv);
612 /* can miss port0 rx interrupts */ 682 /* can miss port0 rx interrupts */
613#define IPATH_POLL_RX_INTR 0x40000 683#define IPATH_POLL_RX_INTR 0x40000
614#define IPATH_DISABLED 0x80000 /* administratively disabled */ 684#define IPATH_DISABLED 0x80000 /* administratively disabled */
685 /* Use GPIO interrupts for new counters */
686#define IPATH_GPIO_ERRINTRS 0x100000
687
688/* Bits in GPIO for the added interrupts */
689#define IPATH_GPIO_PORT0_BIT 2
690#define IPATH_GPIO_RXUVL_BIT 3
691#define IPATH_GPIO_OVRUN_BIT 4
692#define IPATH_GPIO_LLI_BIT 5
693#define IPATH_GPIO_ERRINTR_MASK 0x38
615 694
616/* portdata flag bit offsets */ 695/* portdata flag bit offsets */
617 /* waiting for a packet to arrive */ 696 /* waiting for a packet to arrive */
@@ -799,6 +878,13 @@ int ipathfs_add_device(struct ipath_devdata *);
799int ipathfs_remove_device(struct ipath_devdata *); 878int ipathfs_remove_device(struct ipath_devdata *);
800 879
801/* 880/*
881 * dma_addr wrappers - all 0's invalid for hw
882 */
883dma_addr_t ipath_map_page(struct pci_dev *, struct page *, unsigned long,
884 size_t, int);
885dma_addr_t ipath_map_single(struct pci_dev *, void *, size_t, int);
886
887/*
802 * Flush write combining store buffers (if present) and perform a write 888 * Flush write combining store buffers (if present) and perform a write
803 * barrier. 889 * barrier.
804 */ 890 */
@@ -855,4 +941,20 @@ extern struct mutex ipath_mutex;
855 941
856#endif /* _IPATH_DEBUGGING */ 942#endif /* _IPATH_DEBUGGING */
857 943
944/*
945 * this is used for formatting hw error messages...
946 */
947struct ipath_hwerror_msgs {
948 u64 mask;
949 const char *msg;
950};
951
952#define INFINIPATH_HWE_MSG(a, b) { .mask = INFINIPATH_HWE_##a, .msg = b }
953
954/* in ipath_intr.c... */
955void ipath_format_hwerrors(u64 hwerrs,
956 const struct ipath_hwerror_msgs *hwerrmsgs,
957 size_t nhwerrmsgs,
958 char *msg, size_t lmsg);
959
858#endif /* _IPATH_KERNEL_H */ 960#endif /* _IPATH_KERNEL_H */
diff --git a/drivers/infiniband/hw/ipath/ipath_keys.c b/drivers/infiniband/hw/ipath/ipath_keys.c
index ba1b93226caa..9a6cbd05adcd 100644
--- a/drivers/infiniband/hw/ipath/ipath_keys.c
+++ b/drivers/infiniband/hw/ipath/ipath_keys.c
@@ -118,9 +118,10 @@ void ipath_free_lkey(struct ipath_lkey_table *rkt, u32 lkey)
118 * Check the IB SGE for validity and initialize our internal version 118 * Check the IB SGE for validity and initialize our internal version
119 * of it. 119 * of it.
120 */ 120 */
121int ipath_lkey_ok(struct ipath_lkey_table *rkt, struct ipath_sge *isge, 121int ipath_lkey_ok(struct ipath_qp *qp, struct ipath_sge *isge,
122 struct ib_sge *sge, int acc) 122 struct ib_sge *sge, int acc)
123{ 123{
124 struct ipath_lkey_table *rkt = &to_idev(qp->ibqp.device)->lk_table;
124 struct ipath_mregion *mr; 125 struct ipath_mregion *mr;
125 unsigned n, m; 126 unsigned n, m;
126 size_t off; 127 size_t off;
@@ -140,7 +141,8 @@ int ipath_lkey_ok(struct ipath_lkey_table *rkt, struct ipath_sge *isge,
140 goto bail; 141 goto bail;
141 } 142 }
142 mr = rkt->table[(sge->lkey >> (32 - ib_ipath_lkey_table_size))]; 143 mr = rkt->table[(sge->lkey >> (32 - ib_ipath_lkey_table_size))];
143 if (unlikely(mr == NULL || mr->lkey != sge->lkey)) { 144 if (unlikely(mr == NULL || mr->lkey != sge->lkey ||
145 qp->ibqp.pd != mr->pd)) {
144 ret = 0; 146 ret = 0;
145 goto bail; 147 goto bail;
146 } 148 }
@@ -188,9 +190,10 @@ bail:
188 * 190 *
189 * Return 1 if successful, otherwise 0. 191 * Return 1 if successful, otherwise 0.
190 */ 192 */
191int ipath_rkey_ok(struct ipath_ibdev *dev, struct ipath_sge_state *ss, 193int ipath_rkey_ok(struct ipath_qp *qp, struct ipath_sge_state *ss,
192 u32 len, u64 vaddr, u32 rkey, int acc) 194 u32 len, u64 vaddr, u32 rkey, int acc)
193{ 195{
196 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
194 struct ipath_lkey_table *rkt = &dev->lk_table; 197 struct ipath_lkey_table *rkt = &dev->lk_table;
195 struct ipath_sge *sge = &ss->sge; 198 struct ipath_sge *sge = &ss->sge;
196 struct ipath_mregion *mr; 199 struct ipath_mregion *mr;
@@ -214,7 +217,8 @@ int ipath_rkey_ok(struct ipath_ibdev *dev, struct ipath_sge_state *ss,
214 } 217 }
215 218
216 mr = rkt->table[(rkey >> (32 - ib_ipath_lkey_table_size))]; 219 mr = rkt->table[(rkey >> (32 - ib_ipath_lkey_table_size))];
217 if (unlikely(mr == NULL || mr->lkey != rkey)) { 220 if (unlikely(mr == NULL || mr->lkey != rkey ||
221 qp->ibqp.pd != mr->pd)) {
218 ret = 0; 222 ret = 0;
219 goto bail; 223 goto bail;
220 } 224 }
diff --git a/drivers/infiniband/hw/ipath/ipath_mad.c b/drivers/infiniband/hw/ipath/ipath_mad.c
index 72d1db89db8f..25908b02fbe5 100644
--- a/drivers/infiniband/hw/ipath/ipath_mad.c
+++ b/drivers/infiniband/hw/ipath/ipath_mad.c
@@ -87,7 +87,8 @@ static int recv_subn_get_nodeinfo(struct ib_smp *smp,
87 struct ipath_devdata *dd = to_idev(ibdev)->dd; 87 struct ipath_devdata *dd = to_idev(ibdev)->dd;
88 u32 vendor, majrev, minrev; 88 u32 vendor, majrev, minrev;
89 89
90 if (smp->attr_mod) 90 /* GUID 0 is illegal */
91 if (smp->attr_mod || (dd->ipath_guid == 0))
91 smp->status |= IB_SMP_INVALID_FIELD; 92 smp->status |= IB_SMP_INVALID_FIELD;
92 93
93 nip->base_version = 1; 94 nip->base_version = 1;
@@ -131,10 +132,15 @@ static int recv_subn_get_guidinfo(struct ib_smp *smp,
131 * We only support one GUID for now. If this changes, the 132 * We only support one GUID for now. If this changes, the
132 * portinfo.guid_cap field needs to be updated too. 133 * portinfo.guid_cap field needs to be updated too.
133 */ 134 */
134 if (startgx == 0) 135 if (startgx == 0) {
135 /* The first is a copy of the read-only HW GUID. */ 136 __be64 g = to_idev(ibdev)->dd->ipath_guid;
136 *p = to_idev(ibdev)->dd->ipath_guid; 137 if (g == 0)
137 else 138 /* GUID 0 is illegal */
139 smp->status |= IB_SMP_INVALID_FIELD;
140 else
141 /* The first is a copy of the read-only HW GUID. */
142 *p = g;
143 } else
138 smp->status |= IB_SMP_INVALID_FIELD; 144 smp->status |= IB_SMP_INVALID_FIELD;
139 145
140 return reply(smp); 146 return reply(smp);
diff --git a/drivers/infiniband/hw/ipath/ipath_mr.c b/drivers/infiniband/hw/ipath/ipath_mr.c
index b36f6fb3e37a..a0673c1eef71 100644
--- a/drivers/infiniband/hw/ipath/ipath_mr.c
+++ b/drivers/infiniband/hw/ipath/ipath_mr.c
@@ -138,6 +138,7 @@ struct ib_mr *ipath_reg_phys_mr(struct ib_pd *pd,
138 goto bail; 138 goto bail;
139 } 139 }
140 140
141 mr->mr.pd = pd;
141 mr->mr.user_base = *iova_start; 142 mr->mr.user_base = *iova_start;
142 mr->mr.iova = *iova_start; 143 mr->mr.iova = *iova_start;
143 mr->mr.length = 0; 144 mr->mr.length = 0;
@@ -197,6 +198,7 @@ struct ib_mr *ipath_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
197 goto bail; 198 goto bail;
198 } 199 }
199 200
201 mr->mr.pd = pd;
200 mr->mr.user_base = region->user_base; 202 mr->mr.user_base = region->user_base;
201 mr->mr.iova = region->virt_base; 203 mr->mr.iova = region->virt_base;
202 mr->mr.length = region->length; 204 mr->mr.length = region->length;
@@ -289,6 +291,7 @@ struct ib_fmr *ipath_alloc_fmr(struct ib_pd *pd, int mr_access_flags,
289 * Resources are allocated but no valid mapping (RKEY can't be 291 * Resources are allocated but no valid mapping (RKEY can't be
290 * used). 292 * used).
291 */ 293 */
294 fmr->mr.pd = pd;
292 fmr->mr.user_base = 0; 295 fmr->mr.user_base = 0;
293 fmr->mr.iova = 0; 296 fmr->mr.iova = 0;
294 fmr->mr.length = 0; 297 fmr->mr.length = 0;
diff --git a/drivers/infiniband/hw/ipath/ipath_qp.c b/drivers/infiniband/hw/ipath/ipath_qp.c
index 224b0f40767f..46c1c89bf6ae 100644
--- a/drivers/infiniband/hw/ipath/ipath_qp.c
+++ b/drivers/infiniband/hw/ipath/ipath_qp.c
@@ -335,6 +335,7 @@ static void ipath_reset_qp(struct ipath_qp *qp)
335 qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE; 335 qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE;
336 qp->r_ack_state = IB_OPCODE_RC_ACKNOWLEDGE; 336 qp->r_ack_state = IB_OPCODE_RC_ACKNOWLEDGE;
337 qp->r_nak_state = 0; 337 qp->r_nak_state = 0;
338 qp->r_wrid_valid = 0;
338 qp->s_rnr_timeout = 0; 339 qp->s_rnr_timeout = 0;
339 qp->s_head = 0; 340 qp->s_head = 0;
340 qp->s_tail = 0; 341 qp->s_tail = 0;
@@ -342,6 +343,7 @@ static void ipath_reset_qp(struct ipath_qp *qp)
342 qp->s_last = 0; 343 qp->s_last = 0;
343 qp->s_ssn = 1; 344 qp->s_ssn = 1;
344 qp->s_lsn = 0; 345 qp->s_lsn = 0;
346 qp->s_wait_credit = 0;
345 if (qp->r_rq.wq) { 347 if (qp->r_rq.wq) {
346 qp->r_rq.wq->head = 0; 348 qp->r_rq.wq->head = 0;
347 qp->r_rq.wq->tail = 0; 349 qp->r_rq.wq->tail = 0;
@@ -352,12 +354,13 @@ static void ipath_reset_qp(struct ipath_qp *qp)
352/** 354/**
353 * ipath_error_qp - put a QP into an error state 355 * ipath_error_qp - put a QP into an error state
354 * @qp: the QP to put into an error state 356 * @qp: the QP to put into an error state
357 * @err: the receive completion error to signal if a RWQE is active
355 * 358 *
356 * Flushes both send and receive work queues. 359 * Flushes both send and receive work queues.
357 * QP s_lock should be held and interrupts disabled. 360 * QP s_lock should be held and interrupts disabled.
358 */ 361 */
359 362
360void ipath_error_qp(struct ipath_qp *qp) 363void ipath_error_qp(struct ipath_qp *qp, enum ib_wc_status err)
361{ 364{
362 struct ipath_ibdev *dev = to_idev(qp->ibqp.device); 365 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
363 struct ib_wc wc; 366 struct ib_wc wc;
@@ -373,7 +376,6 @@ void ipath_error_qp(struct ipath_qp *qp)
373 list_del_init(&qp->piowait); 376 list_del_init(&qp->piowait);
374 spin_unlock(&dev->pending_lock); 377 spin_unlock(&dev->pending_lock);
375 378
376 wc.status = IB_WC_WR_FLUSH_ERR;
377 wc.vendor_err = 0; 379 wc.vendor_err = 0;
378 wc.byte_len = 0; 380 wc.byte_len = 0;
379 wc.imm_data = 0; 381 wc.imm_data = 0;
@@ -385,6 +387,12 @@ void ipath_error_qp(struct ipath_qp *qp)
385 wc.sl = 0; 387 wc.sl = 0;
386 wc.dlid_path_bits = 0; 388 wc.dlid_path_bits = 0;
387 wc.port_num = 0; 389 wc.port_num = 0;
390 if (qp->r_wrid_valid) {
391 qp->r_wrid_valid = 0;
392 wc.status = err;
393 ipath_cq_enter(to_icq(qp->ibqp.send_cq), &wc, 1);
394 }
395 wc.status = IB_WC_WR_FLUSH_ERR;
388 396
389 while (qp->s_last != qp->s_head) { 397 while (qp->s_last != qp->s_head) {
390 struct ipath_swqe *wqe = get_swqe_ptr(qp, qp->s_last); 398 struct ipath_swqe *wqe = get_swqe_ptr(qp, qp->s_last);
@@ -501,7 +509,7 @@ int ipath_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
501 break; 509 break;
502 510
503 case IB_QPS_ERR: 511 case IB_QPS_ERR:
504 ipath_error_qp(qp); 512 ipath_error_qp(qp, IB_WC_GENERAL_ERR);
505 break; 513 break;
506 514
507 default: 515 default:
@@ -516,7 +524,7 @@ int ipath_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
516 qp->remote_qpn = attr->dest_qp_num; 524 qp->remote_qpn = attr->dest_qp_num;
517 525
518 if (attr_mask & IB_QP_SQ_PSN) { 526 if (attr_mask & IB_QP_SQ_PSN) {
519 qp->s_next_psn = attr->sq_psn; 527 qp->s_psn = qp->s_next_psn = attr->sq_psn;
520 qp->s_last_psn = qp->s_next_psn - 1; 528 qp->s_last_psn = qp->s_next_psn - 1;
521 } 529 }
522 530
diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
index a08654042c03..ce6038743c5c 100644
--- a/drivers/infiniband/hw/ipath/ipath_rc.c
+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
@@ -201,6 +201,18 @@ int ipath_make_rc_req(struct ipath_qp *qp,
201 qp->s_rnr_timeout) 201 qp->s_rnr_timeout)
202 goto done; 202 goto done;
203 203
204 /* Limit the number of packets sent without an ACK. */
205 if (ipath_cmp24(qp->s_psn, qp->s_last_psn + IPATH_PSN_CREDIT) > 0) {
206 qp->s_wait_credit = 1;
207 dev->n_rc_stalls++;
208 spin_lock(&dev->pending_lock);
209 if (list_empty(&qp->timerwait))
210 list_add_tail(&qp->timerwait,
211 &dev->pending[dev->pending_index]);
212 spin_unlock(&dev->pending_lock);
213 goto done;
214 }
215
204 /* header size in 32-bit words LRH+BTH = (8+12)/4. */ 216 /* header size in 32-bit words LRH+BTH = (8+12)/4. */
205 hwords = 5; 217 hwords = 5;
206 bth0 = 0; 218 bth0 = 0;
@@ -221,7 +233,7 @@ int ipath_make_rc_req(struct ipath_qp *qp,
221 /* Check if send work queue is empty. */ 233 /* Check if send work queue is empty. */
222 if (qp->s_tail == qp->s_head) 234 if (qp->s_tail == qp->s_head)
223 goto done; 235 goto done;
224 qp->s_psn = wqe->psn = qp->s_next_psn; 236 wqe->psn = qp->s_next_psn;
225 newreq = 1; 237 newreq = 1;
226 } 238 }
227 /* 239 /*
@@ -229,10 +241,7 @@ int ipath_make_rc_req(struct ipath_qp *qp,
229 * original work request since we may need to resend 241 * original work request since we may need to resend
230 * it. 242 * it.
231 */ 243 */
232 qp->s_sge.sge = wqe->sg_list[0]; 244 len = wqe->length;
233 qp->s_sge.sg_list = wqe->sg_list + 1;
234 qp->s_sge.num_sge = wqe->wr.num_sge;
235 qp->s_len = len = wqe->length;
236 ss = &qp->s_sge; 245 ss = &qp->s_sge;
237 bth2 = 0; 246 bth2 = 0;
238 switch (wqe->wr.opcode) { 247 switch (wqe->wr.opcode) {
@@ -356,14 +365,23 @@ int ipath_make_rc_req(struct ipath_qp *qp,
356 default: 365 default:
357 goto done; 366 goto done;
358 } 367 }
368 qp->s_sge.sge = wqe->sg_list[0];
369 qp->s_sge.sg_list = wqe->sg_list + 1;
370 qp->s_sge.num_sge = wqe->wr.num_sge;
371 qp->s_len = wqe->length;
359 if (newreq) { 372 if (newreq) {
360 qp->s_tail++; 373 qp->s_tail++;
361 if (qp->s_tail >= qp->s_size) 374 if (qp->s_tail >= qp->s_size)
362 qp->s_tail = 0; 375 qp->s_tail = 0;
363 } 376 }
364 bth2 |= qp->s_psn++ & IPATH_PSN_MASK; 377 bth2 |= qp->s_psn & IPATH_PSN_MASK;
365 if ((int)(qp->s_psn - qp->s_next_psn) > 0) 378 if (wqe->wr.opcode == IB_WR_RDMA_READ)
366 qp->s_next_psn = qp->s_psn; 379 qp->s_psn = wqe->lpsn + 1;
380 else {
381 qp->s_psn++;
382 if ((int)(qp->s_psn - qp->s_next_psn) > 0)
383 qp->s_next_psn = qp->s_psn;
384 }
367 /* 385 /*
368 * Put the QP on the pending list so lost ACKs will cause 386 * Put the QP on the pending list so lost ACKs will cause
369 * a retry. More than one request can be pending so the 387 * a retry. More than one request can be pending so the
@@ -393,12 +411,6 @@ int ipath_make_rc_req(struct ipath_qp *qp,
393 ss = &qp->s_sge; 411 ss = &qp->s_sge;
394 len = qp->s_len; 412 len = qp->s_len;
395 if (len > pmtu) { 413 if (len > pmtu) {
396 /*
397 * Request an ACK every 1/2 MB to avoid retransmit
398 * timeouts.
399 */
400 if (((wqe->length - len) % (512 * 1024)) == 0)
401 bth2 |= 1 << 31;
402 len = pmtu; 414 len = pmtu;
403 break; 415 break;
404 } 416 }
@@ -435,12 +447,6 @@ int ipath_make_rc_req(struct ipath_qp *qp,
435 ss = &qp->s_sge; 447 ss = &qp->s_sge;
436 len = qp->s_len; 448 len = qp->s_len;
437 if (len > pmtu) { 449 if (len > pmtu) {
438 /*
439 * Request an ACK every 1/2 MB to avoid retransmit
440 * timeouts.
441 */
442 if (((wqe->length - len) % (512 * 1024)) == 0)
443 bth2 |= 1 << 31;
444 len = pmtu; 450 len = pmtu;
445 break; 451 break;
446 } 452 }
@@ -498,6 +504,8 @@ int ipath_make_rc_req(struct ipath_qp *qp,
498 */ 504 */
499 goto done; 505 goto done;
500 } 506 }
507 if (ipath_cmp24(qp->s_psn, qp->s_last_psn + IPATH_PSN_CREDIT - 1) >= 0)
508 bth2 |= 1 << 31; /* Request ACK. */
501 qp->s_len -= len; 509 qp->s_len -= len;
502 qp->s_hdrwords = hwords; 510 qp->s_hdrwords = hwords;
503 qp->s_cur_sge = ss; 511 qp->s_cur_sge = ss;
@@ -688,13 +696,6 @@ void ipath_restart_rc(struct ipath_qp *qp, u32 psn, struct ib_wc *wc)
688 struct ipath_swqe *wqe = get_swqe_ptr(qp, qp->s_last); 696 struct ipath_swqe *wqe = get_swqe_ptr(qp, qp->s_last);
689 struct ipath_ibdev *dev; 697 struct ipath_ibdev *dev;
690 698
691 /*
692 * If there are no requests pending, we are done.
693 */
694 if (ipath_cmp24(psn, qp->s_next_psn) >= 0 ||
695 qp->s_last == qp->s_tail)
696 goto done;
697
698 if (qp->s_retry == 0) { 699 if (qp->s_retry == 0) {
699 wc->wr_id = wqe->wr.wr_id; 700 wc->wr_id = wqe->wr.wr_id;
700 wc->status = IB_WC_RETRY_EXC_ERR; 701 wc->status = IB_WC_RETRY_EXC_ERR;
@@ -729,14 +730,21 @@ void ipath_restart_rc(struct ipath_qp *qp, u32 psn, struct ib_wc *wc)
729 dev->n_rc_resends += (int)qp->s_psn - (int)psn; 730 dev->n_rc_resends += (int)qp->s_psn - (int)psn;
730 731
731 reset_psn(qp, psn); 732 reset_psn(qp, psn);
732
733done:
734 tasklet_hi_schedule(&qp->s_task); 733 tasklet_hi_schedule(&qp->s_task);
735 734
736bail: 735bail:
737 return; 736 return;
738} 737}
739 738
739static inline void update_last_psn(struct ipath_qp *qp, u32 psn)
740{
741 if (qp->s_wait_credit) {
742 qp->s_wait_credit = 0;
743 tasklet_hi_schedule(&qp->s_task);
744 }
745 qp->s_last_psn = psn;
746}
747
740/** 748/**
741 * do_rc_ack - process an incoming RC ACK 749 * do_rc_ack - process an incoming RC ACK
742 * @qp: the QP the ACK came in on 750 * @qp: the QP the ACK came in on
@@ -754,6 +762,7 @@ static int do_rc_ack(struct ipath_qp *qp, u32 aeth, u32 psn, int opcode)
754 struct ib_wc wc; 762 struct ib_wc wc;
755 struct ipath_swqe *wqe; 763 struct ipath_swqe *wqe;
756 int ret = 0; 764 int ret = 0;
765 u32 ack_psn;
757 766
758 /* 767 /*
759 * Remove the QP from the timeout queue (or RNR timeout queue). 768 * Remove the QP from the timeout queue (or RNR timeout queue).
@@ -766,26 +775,26 @@ static int do_rc_ack(struct ipath_qp *qp, u32 aeth, u32 psn, int opcode)
766 list_del_init(&qp->timerwait); 775 list_del_init(&qp->timerwait);
767 spin_unlock(&dev->pending_lock); 776 spin_unlock(&dev->pending_lock);
768 777
778 /* Nothing is pending to ACK/NAK. */
779 if (unlikely(qp->s_last == qp->s_tail))
780 goto bail;
781
769 /* 782 /*
770 * Note that NAKs implicitly ACK outstanding SEND and RDMA write 783 * Note that NAKs implicitly ACK outstanding SEND and RDMA write
771 * requests and implicitly NAK RDMA read and atomic requests issued 784 * requests and implicitly NAK RDMA read and atomic requests issued
772 * before the NAK'ed request. The MSN won't include the NAK'ed 785 * before the NAK'ed request. The MSN won't include the NAK'ed
773 * request but will include an ACK'ed request(s). 786 * request but will include an ACK'ed request(s).
774 */ 787 */
788 ack_psn = psn;
789 if (aeth >> 29)
790 ack_psn--;
775 wqe = get_swqe_ptr(qp, qp->s_last); 791 wqe = get_swqe_ptr(qp, qp->s_last);
776 792
777 /* Nothing is pending to ACK/NAK. */
778 if (qp->s_last == qp->s_tail)
779 goto bail;
780
781 /* 793 /*
782 * The MSN might be for a later WQE than the PSN indicates so 794 * The MSN might be for a later WQE than the PSN indicates so
783 * only complete WQEs that the PSN finishes. 795 * only complete WQEs that the PSN finishes.
784 */ 796 */
785 while (ipath_cmp24(psn, wqe->lpsn) >= 0) { 797 while (ipath_cmp24(ack_psn, wqe->lpsn) >= 0) {
786 /* If we are ACKing a WQE, the MSN should be >= the SSN. */
787 if (ipath_cmp24(aeth, wqe->ssn) < 0)
788 break;
789 /* 798 /*
790 * If this request is a RDMA read or atomic, and the ACK is 799 * If this request is a RDMA read or atomic, and the ACK is
791 * for a later operation, this ACK NAKs the RDMA read or 800 * for a later operation, this ACK NAKs the RDMA read or
@@ -796,7 +805,8 @@ static int do_rc_ack(struct ipath_qp *qp, u32 aeth, u32 psn, int opcode)
796 * is sent but before the response is received. 805 * is sent but before the response is received.
797 */ 806 */
798 if ((wqe->wr.opcode == IB_WR_RDMA_READ && 807 if ((wqe->wr.opcode == IB_WR_RDMA_READ &&
799 opcode != OP(RDMA_READ_RESPONSE_LAST)) || 808 (opcode != OP(RDMA_READ_RESPONSE_LAST) ||
809 ipath_cmp24(ack_psn, wqe->lpsn) != 0)) ||
800 ((wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP || 810 ((wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
801 wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) && 811 wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) &&
802 (opcode != OP(ATOMIC_ACKNOWLEDGE) || 812 (opcode != OP(ATOMIC_ACKNOWLEDGE) ||
@@ -805,7 +815,7 @@ static int do_rc_ack(struct ipath_qp *qp, u32 aeth, u32 psn, int opcode)
805 * The last valid PSN seen is the previous 815 * The last valid PSN seen is the previous
806 * request's. 816 * request's.
807 */ 817 */
808 qp->s_last_psn = wqe->psn - 1; 818 update_last_psn(qp, wqe->psn - 1);
809 /* Retry this request. */ 819 /* Retry this request. */
810 ipath_restart_rc(qp, wqe->psn, &wc); 820 ipath_restart_rc(qp, wqe->psn, &wc);
811 /* 821 /*
@@ -814,6 +824,10 @@ static int do_rc_ack(struct ipath_qp *qp, u32 aeth, u32 psn, int opcode)
814 */ 824 */
815 goto bail; 825 goto bail;
816 } 826 }
827 if (wqe->wr.opcode == IB_WR_RDMA_READ ||
828 wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
829 wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD)
830 tasklet_hi_schedule(&qp->s_task);
817 /* Post a send completion queue entry if requested. */ 831 /* Post a send completion queue entry if requested. */
818 if (!test_bit(IPATH_S_SIGNAL_REQ_WR, &qp->s_flags) || 832 if (!test_bit(IPATH_S_SIGNAL_REQ_WR, &qp->s_flags) ||
819 (wqe->wr.send_flags & IB_SEND_SIGNALED)) { 833 (wqe->wr.send_flags & IB_SEND_SIGNALED)) {
@@ -864,7 +878,7 @@ static int do_rc_ack(struct ipath_qp *qp, u32 aeth, u32 psn, int opcode)
864 ipath_get_credit(qp, aeth); 878 ipath_get_credit(qp, aeth);
865 qp->s_rnr_retry = qp->s_rnr_retry_cnt; 879 qp->s_rnr_retry = qp->s_rnr_retry_cnt;
866 qp->s_retry = qp->s_retry_cnt; 880 qp->s_retry = qp->s_retry_cnt;
867 qp->s_last_psn = psn; 881 update_last_psn(qp, psn);
868 ret = 1; 882 ret = 1;
869 goto bail; 883 goto bail;
870 884
@@ -883,7 +897,7 @@ static int do_rc_ack(struct ipath_qp *qp, u32 aeth, u32 psn, int opcode)
883 goto bail; 897 goto bail;
884 898
885 /* The last valid PSN is the previous PSN. */ 899 /* The last valid PSN is the previous PSN. */
886 qp->s_last_psn = psn - 1; 900 update_last_psn(qp, psn - 1);
887 901
888 dev->n_rc_resends += (int)qp->s_psn - (int)psn; 902 dev->n_rc_resends += (int)qp->s_psn - (int)psn;
889 903
@@ -898,7 +912,7 @@ static int do_rc_ack(struct ipath_qp *qp, u32 aeth, u32 psn, int opcode)
898 case 3: /* NAK */ 912 case 3: /* NAK */
899 /* The last valid PSN seen is the previous request's. */ 913 /* The last valid PSN seen is the previous request's. */
900 if (qp->s_last != qp->s_tail) 914 if (qp->s_last != qp->s_tail)
901 qp->s_last_psn = wqe->psn - 1; 915 update_last_psn(qp, wqe->psn - 1);
902 switch ((aeth >> IPATH_AETH_CREDIT_SHIFT) & 916 switch ((aeth >> IPATH_AETH_CREDIT_SHIFT) &
903 IPATH_AETH_CREDIT_MASK) { 917 IPATH_AETH_CREDIT_MASK) {
904 case 0: /* PSN sequence error */ 918 case 0: /* PSN sequence error */
@@ -1044,7 +1058,8 @@ static inline void ipath_rc_rcv_resp(struct ipath_ibdev *dev,
1044 /* no AETH, no ACK */ 1058 /* no AETH, no ACK */
1045 if (unlikely(ipath_cmp24(psn, qp->s_last_psn + 1))) { 1059 if (unlikely(ipath_cmp24(psn, qp->s_last_psn + 1))) {
1046 dev->n_rdma_seq++; 1060 dev->n_rdma_seq++;
1047 ipath_restart_rc(qp, qp->s_last_psn + 1, &wc); 1061 if (qp->s_last != qp->s_tail)
1062 ipath_restart_rc(qp, qp->s_last_psn + 1, &wc);
1048 goto ack_done; 1063 goto ack_done;
1049 } 1064 }
1050 rdma_read: 1065 rdma_read:
@@ -1071,7 +1086,7 @@ static inline void ipath_rc_rcv_resp(struct ipath_ibdev *dev,
1071 * since we don't want s_sge modified. 1086 * since we don't want s_sge modified.
1072 */ 1087 */
1073 qp->s_len -= pmtu; 1088 qp->s_len -= pmtu;
1074 qp->s_last_psn = psn; 1089 update_last_psn(qp, psn);
1075 spin_unlock_irqrestore(&qp->s_lock, flags); 1090 spin_unlock_irqrestore(&qp->s_lock, flags);
1076 ipath_copy_sge(&qp->s_sge, data, pmtu); 1091 ipath_copy_sge(&qp->s_sge, data, pmtu);
1077 goto bail; 1092 goto bail;
@@ -1080,7 +1095,8 @@ static inline void ipath_rc_rcv_resp(struct ipath_ibdev *dev,
1080 /* ACKs READ req. */ 1095 /* ACKs READ req. */
1081 if (unlikely(ipath_cmp24(psn, qp->s_last_psn + 1))) { 1096 if (unlikely(ipath_cmp24(psn, qp->s_last_psn + 1))) {
1082 dev->n_rdma_seq++; 1097 dev->n_rdma_seq++;
1083 ipath_restart_rc(qp, qp->s_last_psn + 1, &wc); 1098 if (qp->s_last != qp->s_tail)
1099 ipath_restart_rc(qp, qp->s_last_psn + 1, &wc);
1084 goto ack_done; 1100 goto ack_done;
1085 } 1101 }
1086 /* FALLTHROUGH */ 1102 /* FALLTHROUGH */
@@ -1223,7 +1239,7 @@ static inline int ipath_rc_rcv_error(struct ipath_ibdev *dev,
1223 * Address range must be a subset of the original 1239 * Address range must be a subset of the original
1224 * request and start on pmtu boundaries. 1240 * request and start on pmtu boundaries.
1225 */ 1241 */
1226 ok = ipath_rkey_ok(dev, &qp->s_rdma_sge, 1242 ok = ipath_rkey_ok(qp, &qp->s_rdma_sge,
1227 qp->s_rdma_len, vaddr, rkey, 1243 qp->s_rdma_len, vaddr, rkey,
1228 IB_ACCESS_REMOTE_READ); 1244 IB_ACCESS_REMOTE_READ);
1229 if (unlikely(!ok)) { 1245 if (unlikely(!ok)) {
@@ -1282,6 +1298,14 @@ done:
1282 return 1; 1298 return 1;
1283} 1299}
1284 1300
1301static void ipath_rc_error(struct ipath_qp *qp, enum ib_wc_status err)
1302{
1303 spin_lock_irq(&qp->s_lock);
1304 qp->state = IB_QPS_ERR;
1305 ipath_error_qp(qp, err);
1306 spin_unlock_irq(&qp->s_lock);
1307}
1308
1285/** 1309/**
1286 * ipath_rc_rcv - process an incoming RC packet 1310 * ipath_rc_rcv - process an incoming RC packet
1287 * @dev: the device this packet came in on 1311 * @dev: the device this packet came in on
@@ -1309,6 +1333,10 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
1309 struct ib_reth *reth; 1333 struct ib_reth *reth;
1310 int header_in_data; 1334 int header_in_data;
1311 1335
1336 /* Validate the SLID. See Ch. 9.6.1.5 */
1337 if (unlikely(be16_to_cpu(hdr->lrh[3]) != qp->remote_ah_attr.dlid))
1338 goto done;
1339
1312 /* Check for GRH */ 1340 /* Check for GRH */
1313 if (!has_grh) { 1341 if (!has_grh) {
1314 ohdr = &hdr->u.oth; 1342 ohdr = &hdr->u.oth;
@@ -1370,8 +1398,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
1370 */ 1398 */
1371 if (qp->r_ack_state >= OP(COMPARE_SWAP)) 1399 if (qp->r_ack_state >= OP(COMPARE_SWAP))
1372 goto send_ack; 1400 goto send_ack;
1373 /* XXX Flush WQEs */ 1401 ipath_rc_error(qp, IB_WC_REM_INV_REQ_ERR);
1374 qp->state = IB_QPS_ERR;
1375 qp->r_ack_state = OP(SEND_ONLY); 1402 qp->r_ack_state = OP(SEND_ONLY);
1376 qp->r_nak_state = IB_NAK_INVALID_REQUEST; 1403 qp->r_nak_state = IB_NAK_INVALID_REQUEST;
1377 qp->r_ack_psn = qp->r_psn; 1404 qp->r_ack_psn = qp->r_psn;
@@ -1477,9 +1504,9 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
1477 goto nack_inv; 1504 goto nack_inv;
1478 ipath_copy_sge(&qp->r_sge, data, tlen); 1505 ipath_copy_sge(&qp->r_sge, data, tlen);
1479 qp->r_msn++; 1506 qp->r_msn++;
1480 if (opcode == OP(RDMA_WRITE_LAST) || 1507 if (!qp->r_wrid_valid)
1481 opcode == OP(RDMA_WRITE_ONLY))
1482 break; 1508 break;
1509 qp->r_wrid_valid = 0;
1483 wc.wr_id = qp->r_wr_id; 1510 wc.wr_id = qp->r_wr_id;
1484 wc.status = IB_WC_SUCCESS; 1511 wc.status = IB_WC_SUCCESS;
1485 wc.opcode = IB_WC_RECV; 1512 wc.opcode = IB_WC_RECV;
@@ -1517,7 +1544,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
1517 int ok; 1544 int ok;
1518 1545
1519 /* Check rkey & NAK */ 1546 /* Check rkey & NAK */
1520 ok = ipath_rkey_ok(dev, &qp->r_sge, 1547 ok = ipath_rkey_ok(qp, &qp->r_sge,
1521 qp->r_len, vaddr, rkey, 1548 qp->r_len, vaddr, rkey,
1522 IB_ACCESS_REMOTE_WRITE); 1549 IB_ACCESS_REMOTE_WRITE);
1523 if (unlikely(!ok)) 1550 if (unlikely(!ok))
@@ -1559,7 +1586,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
1559 int ok; 1586 int ok;
1560 1587
1561 /* Check rkey & NAK */ 1588 /* Check rkey & NAK */
1562 ok = ipath_rkey_ok(dev, &qp->s_rdma_sge, 1589 ok = ipath_rkey_ok(qp, &qp->s_rdma_sge,
1563 qp->s_rdma_len, vaddr, rkey, 1590 qp->s_rdma_len, vaddr, rkey,
1564 IB_ACCESS_REMOTE_READ); 1591 IB_ACCESS_REMOTE_READ);
1565 if (unlikely(!ok)) { 1592 if (unlikely(!ok)) {
@@ -1618,7 +1645,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
1618 goto nack_inv; 1645 goto nack_inv;
1619 rkey = be32_to_cpu(ateth->rkey); 1646 rkey = be32_to_cpu(ateth->rkey);
1620 /* Check rkey & NAK */ 1647 /* Check rkey & NAK */
1621 if (unlikely(!ipath_rkey_ok(dev, &qp->r_sge, 1648 if (unlikely(!ipath_rkey_ok(qp, &qp->r_sge,
1622 sizeof(u64), vaddr, rkey, 1649 sizeof(u64), vaddr, rkey,
1623 IB_ACCESS_REMOTE_ATOMIC))) 1650 IB_ACCESS_REMOTE_ATOMIC)))
1624 goto nack_acc; 1651 goto nack_acc;
@@ -1670,8 +1697,7 @@ nack_acc:
1670 * is pending though. 1697 * is pending though.
1671 */ 1698 */
1672 if (qp->r_ack_state < OP(COMPARE_SWAP)) { 1699 if (qp->r_ack_state < OP(COMPARE_SWAP)) {
1673 /* XXX Flush WQEs */ 1700 ipath_rc_error(qp, IB_WC_REM_ACCESS_ERR);
1674 qp->state = IB_QPS_ERR;
1675 qp->r_ack_state = OP(RDMA_WRITE_ONLY); 1701 qp->r_ack_state = OP(RDMA_WRITE_ONLY);
1676 qp->r_nak_state = IB_NAK_REMOTE_ACCESS_ERROR; 1702 qp->r_nak_state = IB_NAK_REMOTE_ACCESS_ERROR;
1677 qp->r_ack_psn = qp->r_psn; 1703 qp->r_ack_psn = qp->r_psn;
diff --git a/drivers/infiniband/hw/ipath/ipath_registers.h b/drivers/infiniband/hw/ipath/ipath_registers.h
index 6e23b3d632b8..dffc76016d3c 100644
--- a/drivers/infiniband/hw/ipath/ipath_registers.h
+++ b/drivers/infiniband/hw/ipath/ipath_registers.h
@@ -134,10 +134,24 @@
134#define INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT 40 134#define INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT 40
135#define INFINIPATH_HWE_RXEMEMPARITYERR_MASK 0x7FULL 135#define INFINIPATH_HWE_RXEMEMPARITYERR_MASK 0x7FULL
136#define INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT 44 136#define INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT 44
137#define INFINIPATH_HWE_RXDSYNCMEMPARITYERR 0x0000000400000000ULL
138#define INFINIPATH_HWE_MEMBISTFAILED 0x0040000000000000ULL
139#define INFINIPATH_HWE_IBCBUSTOSPCPARITYERR 0x4000000000000000ULL 137#define INFINIPATH_HWE_IBCBUSTOSPCPARITYERR 0x4000000000000000ULL
140#define INFINIPATH_HWE_IBCBUSFRSPCPARITYERR 0x8000000000000000ULL 138#define INFINIPATH_HWE_IBCBUSFRSPCPARITYERR 0x8000000000000000ULL
139/* txe mem parity errors (shift by INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) */
140#define INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF 0x1ULL
141#define INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC 0x2ULL
142#define INFINIPATH_HWE_TXEMEMPARITYERR_PIOLAUNCHFIFO 0x4ULL
143/* rxe mem parity errors (shift by INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) */
144#define INFINIPATH_HWE_RXEMEMPARITYERR_RCVBUF 0x01ULL
145#define INFINIPATH_HWE_RXEMEMPARITYERR_LOOKUPQ 0x02ULL
146#define INFINIPATH_HWE_RXEMEMPARITYERR_EAGERTID 0x04ULL
147#define INFINIPATH_HWE_RXEMEMPARITYERR_EXPTID 0x08ULL
148#define INFINIPATH_HWE_RXEMEMPARITYERR_FLAGBUF 0x10ULL
149#define INFINIPATH_HWE_RXEMEMPARITYERR_DATAINFO 0x20ULL
150#define INFINIPATH_HWE_RXEMEMPARITYERR_HDRINFO 0x40ULL
151/* waldo specific -- find the rest in ipath_6110.c */
152#define INFINIPATH_HWE_RXDSYNCMEMPARITYERR 0x0000000400000000ULL
153/* monty specific -- find the rest in ipath_6120.c */
154#define INFINIPATH_HWE_MEMBISTFAILED 0x0040000000000000ULL
141 155
142/* kr_hwdiagctrl bits */ 156/* kr_hwdiagctrl bits */
143#define INFINIPATH_DC_FORCETXEMEMPARITYERR_MASK 0xFULL 157#define INFINIPATH_DC_FORCETXEMEMPARITYERR_MASK 0xFULL
@@ -209,9 +223,9 @@
209 223
210/* combination link status states that we use with some frequency */ 224/* combination link status states that we use with some frequency */
211#define IPATH_IBSTATE_MASK ((INFINIPATH_IBCS_LINKTRAININGSTATE_MASK \ 225#define IPATH_IBSTATE_MASK ((INFINIPATH_IBCS_LINKTRAININGSTATE_MASK \
212 << INFINIPATH_IBCS_LINKSTATE_SHIFT) | \ 226 << INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) | \
213 (INFINIPATH_IBCS_LINKSTATE_MASK \ 227 (INFINIPATH_IBCS_LINKSTATE_MASK \
214 <<INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT)) 228 <<INFINIPATH_IBCS_LINKSTATE_SHIFT))
215#define IPATH_IBSTATE_INIT ((INFINIPATH_IBCS_L_STATE_INIT \ 229#define IPATH_IBSTATE_INIT ((INFINIPATH_IBCS_L_STATE_INIT \
216 << INFINIPATH_IBCS_LINKSTATE_SHIFT) | \ 230 << INFINIPATH_IBCS_LINKSTATE_SHIFT) | \
217 (INFINIPATH_IBCS_LT_STATE_LINKUP \ 231 (INFINIPATH_IBCS_LT_STATE_LINKUP \
@@ -302,6 +316,17 @@
302 316
303typedef u64 ipath_err_t; 317typedef u64 ipath_err_t;
304 318
319/* The following change with the type of device, so
320 * need to be part of the ipath_devdata struct, or
321 * we could have problems plugging in devices of
322 * different types (e.g. one HT, one PCIE)
323 * in one system, to be managed by one driver.
324 * On the other hand, this file is may also be included
325 * by other code, so leave the declarations here
326 * temporarily. Minor footprint issue if common-model
327 * linker used, none if C89+ linker used.
328 */
329
305/* mask of defined bits for various registers */ 330/* mask of defined bits for various registers */
306extern u64 infinipath_i_bitsextant; 331extern u64 infinipath_i_bitsextant;
307extern ipath_err_t infinipath_e_bitsextant, infinipath_hwe_bitsextant; 332extern ipath_err_t infinipath_e_bitsextant, infinipath_hwe_bitsextant;
@@ -310,13 +335,6 @@ extern ipath_err_t infinipath_e_bitsextant, infinipath_hwe_bitsextant;
310extern u32 infinipath_i_rcvavail_mask, infinipath_i_rcvurg_mask; 335extern u32 infinipath_i_rcvavail_mask, infinipath_i_rcvurg_mask;
311 336
312/* 337/*
313 * register bits for selecting i2c direction and values, used for I2C serial
314 * flash
315 */
316extern u16 ipath_gpio_sda_num, ipath_gpio_scl_num;
317extern u64 ipath_gpio_sda, ipath_gpio_scl;
318
319/*
320 * These are the infinipath general register numbers (not offsets). 338 * These are the infinipath general register numbers (not offsets).
321 * The kernel registers are used directly, those beyond the kernel 339 * The kernel registers are used directly, those beyond the kernel
322 * registers are calculated from one of the base registers. The use of 340 * registers are calculated from one of the base registers. The use of
diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
index 5c1da2d25e03..f7530512045d 100644
--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
@@ -108,7 +108,6 @@ void ipath_insert_rnr_queue(struct ipath_qp *qp)
108 108
109static int init_sge(struct ipath_qp *qp, struct ipath_rwqe *wqe) 109static int init_sge(struct ipath_qp *qp, struct ipath_rwqe *wqe)
110{ 110{
111 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
112 int user = to_ipd(qp->ibqp.pd)->user; 111 int user = to_ipd(qp->ibqp.pd)->user;
113 int i, j, ret; 112 int i, j, ret;
114 struct ib_wc wc; 113 struct ib_wc wc;
@@ -119,8 +118,7 @@ static int init_sge(struct ipath_qp *qp, struct ipath_rwqe *wqe)
119 continue; 118 continue;
120 /* Check LKEY */ 119 /* Check LKEY */
121 if ((user && wqe->sg_list[i].lkey == 0) || 120 if ((user && wqe->sg_list[i].lkey == 0) ||
122 !ipath_lkey_ok(&dev->lk_table, 121 !ipath_lkey_ok(qp, &qp->r_sg_list[j], &wqe->sg_list[i],
123 &qp->r_sg_list[j], &wqe->sg_list[i],
124 IB_ACCESS_LOCAL_WRITE)) 122 IB_ACCESS_LOCAL_WRITE))
125 goto bad_lkey; 123 goto bad_lkey;
126 qp->r_len += wqe->sg_list[i].length; 124 qp->r_len += wqe->sg_list[i].length;
@@ -231,6 +229,7 @@ int ipath_get_rwqe(struct ipath_qp *qp, int wr_id_only)
231 } 229 }
232 } 230 }
233 spin_unlock_irqrestore(&rq->lock, flags); 231 spin_unlock_irqrestore(&rq->lock, flags);
232 qp->r_wrid_valid = 1;
234 233
235bail: 234bail:
236 return ret; 235 return ret;
@@ -326,7 +325,7 @@ again:
326 case IB_WR_RDMA_WRITE: 325 case IB_WR_RDMA_WRITE:
327 if (wqe->length == 0) 326 if (wqe->length == 0)
328 break; 327 break;
329 if (unlikely(!ipath_rkey_ok(dev, &qp->r_sge, wqe->length, 328 if (unlikely(!ipath_rkey_ok(qp, &qp->r_sge, wqe->length,
330 wqe->wr.wr.rdma.remote_addr, 329 wqe->wr.wr.rdma.remote_addr,
331 wqe->wr.wr.rdma.rkey, 330 wqe->wr.wr.rdma.rkey,
332 IB_ACCESS_REMOTE_WRITE))) { 331 IB_ACCESS_REMOTE_WRITE))) {
@@ -350,7 +349,7 @@ again:
350 break; 349 break;
351 350
352 case IB_WR_RDMA_READ: 351 case IB_WR_RDMA_READ:
353 if (unlikely(!ipath_rkey_ok(dev, &sqp->s_sge, wqe->length, 352 if (unlikely(!ipath_rkey_ok(qp, &sqp->s_sge, wqe->length,
354 wqe->wr.wr.rdma.remote_addr, 353 wqe->wr.wr.rdma.remote_addr,
355 wqe->wr.wr.rdma.rkey, 354 wqe->wr.wr.rdma.rkey,
356 IB_ACCESS_REMOTE_READ))) 355 IB_ACCESS_REMOTE_READ)))
@@ -365,7 +364,7 @@ again:
365 364
366 case IB_WR_ATOMIC_CMP_AND_SWP: 365 case IB_WR_ATOMIC_CMP_AND_SWP:
367 case IB_WR_ATOMIC_FETCH_AND_ADD: 366 case IB_WR_ATOMIC_FETCH_AND_ADD:
368 if (unlikely(!ipath_rkey_ok(dev, &qp->r_sge, sizeof(u64), 367 if (unlikely(!ipath_rkey_ok(qp, &qp->r_sge, sizeof(u64),
369 wqe->wr.wr.rdma.remote_addr, 368 wqe->wr.wr.rdma.remote_addr,
370 wqe->wr.wr.rdma.rkey, 369 wqe->wr.wr.rdma.rkey,
371 IB_ACCESS_REMOTE_ATOMIC))) 370 IB_ACCESS_REMOTE_ATOMIC)))
@@ -575,8 +574,7 @@ int ipath_post_ruc_send(struct ipath_qp *qp, struct ib_send_wr *wr)
575 } 574 }
576 if (wr->sg_list[i].length == 0) 575 if (wr->sg_list[i].length == 0)
577 continue; 576 continue;
578 if (!ipath_lkey_ok(&to_idev(qp->ibqp.device)->lk_table, 577 if (!ipath_lkey_ok(qp, &wqe->sg_list[j], &wr->sg_list[i],
579 &wqe->sg_list[j], &wr->sg_list[i],
580 acc)) { 578 acc)) {
581 spin_unlock_irqrestore(&qp->s_lock, flags); 579 spin_unlock_irqrestore(&qp->s_lock, flags);
582 ret = -EINVAL; 580 ret = -EINVAL;
diff --git a/drivers/infiniband/hw/ipath/ipath_srq.c b/drivers/infiniband/hw/ipath/ipath_srq.c
index 941e866d9517..94033503400c 100644
--- a/drivers/infiniband/hw/ipath/ipath_srq.c
+++ b/drivers/infiniband/hw/ipath/ipath_srq.c
@@ -104,11 +104,6 @@ struct ib_srq *ipath_create_srq(struct ib_pd *ibpd,
104 u32 sz; 104 u32 sz;
105 struct ib_srq *ret; 105 struct ib_srq *ret;
106 106
107 if (dev->n_srqs_allocated == ib_ipath_max_srqs) {
108 ret = ERR_PTR(-ENOMEM);
109 goto done;
110 }
111
112 if (srq_init_attr->attr.max_wr == 0) { 107 if (srq_init_attr->attr.max_wr == 0) {
113 ret = ERR_PTR(-EINVAL); 108 ret = ERR_PTR(-EINVAL);
114 goto done; 109 goto done;
@@ -180,10 +175,17 @@ struct ib_srq *ipath_create_srq(struct ib_pd *ibpd,
180 spin_lock_init(&srq->rq.lock); 175 spin_lock_init(&srq->rq.lock);
181 srq->rq.wq->head = 0; 176 srq->rq.wq->head = 0;
182 srq->rq.wq->tail = 0; 177 srq->rq.wq->tail = 0;
183 srq->rq.max_sge = srq_init_attr->attr.max_sge;
184 srq->limit = srq_init_attr->attr.srq_limit; 178 srq->limit = srq_init_attr->attr.srq_limit;
185 179
186 dev->n_srqs_allocated++; 180 spin_lock(&dev->n_srqs_lock);
181 if (dev->n_srqs_allocated == ib_ipath_max_srqs) {
182 spin_unlock(&dev->n_srqs_lock);
183 ret = ERR_PTR(-ENOMEM);
184 goto bail_wq;
185 }
186
187 dev->n_srqs_allocated++;
188 spin_unlock(&dev->n_srqs_lock);
187 189
188 ret = &srq->ibsrq; 190 ret = &srq->ibsrq;
189 goto done; 191 goto done;
@@ -351,8 +353,13 @@ int ipath_destroy_srq(struct ib_srq *ibsrq)
351 struct ipath_srq *srq = to_isrq(ibsrq); 353 struct ipath_srq *srq = to_isrq(ibsrq);
352 struct ipath_ibdev *dev = to_idev(ibsrq->device); 354 struct ipath_ibdev *dev = to_idev(ibsrq->device);
353 355
356 spin_lock(&dev->n_srqs_lock);
354 dev->n_srqs_allocated--; 357 dev->n_srqs_allocated--;
355 vfree(srq->rq.wq); 358 spin_unlock(&dev->n_srqs_lock);
359 if (srq->ip)
360 kref_put(&srq->ip->ref, ipath_release_mmap_info);
361 else
362 vfree(srq->rq.wq);
356 kfree(srq); 363 kfree(srq);
357 364
358 return 0; 365 return 0;
diff --git a/drivers/infiniband/hw/ipath/ipath_sysfs.c b/drivers/infiniband/hw/ipath/ipath_sysfs.c
index e299148c4b68..182de34f9f47 100644
--- a/drivers/infiniband/hw/ipath/ipath_sysfs.c
+++ b/drivers/infiniband/hw/ipath/ipath_sysfs.c
@@ -257,7 +257,7 @@ static ssize_t store_guid(struct device *dev,
257 struct ipath_devdata *dd = dev_get_drvdata(dev); 257 struct ipath_devdata *dd = dev_get_drvdata(dev);
258 ssize_t ret; 258 ssize_t ret;
259 unsigned short guid[8]; 259 unsigned short guid[8];
260 __be64 nguid; 260 __be64 new_guid;
261 u8 *ng; 261 u8 *ng;
262 int i; 262 int i;
263 263
@@ -266,7 +266,7 @@ static ssize_t store_guid(struct device *dev,
266 &guid[4], &guid[5], &guid[6], &guid[7]) != 8) 266 &guid[4], &guid[5], &guid[6], &guid[7]) != 8)
267 goto invalid; 267 goto invalid;
268 268
269 ng = (u8 *) &nguid; 269 ng = (u8 *) &new_guid;
270 270
271 for (i = 0; i < 8; i++) { 271 for (i = 0; i < 8; i++) {
272 if (guid[i] > 0xff) 272 if (guid[i] > 0xff)
@@ -274,7 +274,10 @@ static ssize_t store_guid(struct device *dev,
274 ng[i] = guid[i]; 274 ng[i] = guid[i];
275 } 275 }
276 276
277 dd->ipath_guid = nguid; 277 if (new_guid == 0)
278 goto invalid;
279
280 dd->ipath_guid = new_guid;
278 dd->ipath_nguid = 1; 281 dd->ipath_nguid = 1;
279 282
280 ret = strlen(buf); 283 ret = strlen(buf);
@@ -297,6 +300,16 @@ static ssize_t show_nguid(struct device *dev,
297 return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_nguid); 300 return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_nguid);
298} 301}
299 302
303static ssize_t show_nports(struct device *dev,
304 struct device_attribute *attr,
305 char *buf)
306{
307 struct ipath_devdata *dd = dev_get_drvdata(dev);
308
309 /* Return the number of user ports available. */
310 return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_cfgports - 1);
311}
312
300static ssize_t show_serial(struct device *dev, 313static ssize_t show_serial(struct device *dev,
301 struct device_attribute *attr, 314 struct device_attribute *attr,
302 char *buf) 315 char *buf)
@@ -608,6 +621,7 @@ static DEVICE_ATTR(mlid, S_IWUSR | S_IRUGO, show_mlid, store_mlid);
608static DEVICE_ATTR(mtu, S_IWUSR | S_IRUGO, show_mtu, store_mtu); 621static DEVICE_ATTR(mtu, S_IWUSR | S_IRUGO, show_mtu, store_mtu);
609static DEVICE_ATTR(enabled, S_IWUSR | S_IRUGO, show_enabled, store_enabled); 622static DEVICE_ATTR(enabled, S_IWUSR | S_IRUGO, show_enabled, store_enabled);
610static DEVICE_ATTR(nguid, S_IRUGO, show_nguid, NULL); 623static DEVICE_ATTR(nguid, S_IRUGO, show_nguid, NULL);
624static DEVICE_ATTR(nports, S_IRUGO, show_nports, NULL);
611static DEVICE_ATTR(reset, S_IWUSR, NULL, store_reset); 625static DEVICE_ATTR(reset, S_IWUSR, NULL, store_reset);
612static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL); 626static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
613static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); 627static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
@@ -623,6 +637,7 @@ static struct attribute *dev_attributes[] = {
623 &dev_attr_mlid.attr, 637 &dev_attr_mlid.attr,
624 &dev_attr_mtu.attr, 638 &dev_attr_mtu.attr,
625 &dev_attr_nguid.attr, 639 &dev_attr_nguid.attr,
640 &dev_attr_nports.attr,
626 &dev_attr_serial.attr, 641 &dev_attr_serial.attr,
627 &dev_attr_status.attr, 642 &dev_attr_status.attr,
628 &dev_attr_status_str.attr, 643 &dev_attr_status_str.attr,
diff --git a/drivers/infiniband/hw/ipath/ipath_uc.c b/drivers/infiniband/hw/ipath/ipath_uc.c
index 0fd3cded16ba..e636cfd67a82 100644
--- a/drivers/infiniband/hw/ipath/ipath_uc.c
+++ b/drivers/infiniband/hw/ipath/ipath_uc.c
@@ -246,6 +246,10 @@ void ipath_uc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
246 struct ib_reth *reth; 246 struct ib_reth *reth;
247 int header_in_data; 247 int header_in_data;
248 248
249 /* Validate the SLID. See Ch. 9.6.1.5 */
250 if (unlikely(be16_to_cpu(hdr->lrh[3]) != qp->remote_ah_attr.dlid))
251 goto done;
252
249 /* Check for GRH */ 253 /* Check for GRH */
250 if (!has_grh) { 254 if (!has_grh) {
251 ohdr = &hdr->u.oth; 255 ohdr = &hdr->u.oth;
@@ -440,7 +444,7 @@ void ipath_uc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
440 int ok; 444 int ok;
441 445
442 /* Check rkey */ 446 /* Check rkey */
443 ok = ipath_rkey_ok(dev, &qp->r_sge, qp->r_len, 447 ok = ipath_rkey_ok(qp, &qp->r_sge, qp->r_len,
444 vaddr, rkey, 448 vaddr, rkey,
445 IB_ACCESS_REMOTE_WRITE); 449 IB_ACCESS_REMOTE_WRITE);
446 if (unlikely(!ok)) { 450 if (unlikely(!ok)) {
diff --git a/drivers/infiniband/hw/ipath/ipath_ud.c b/drivers/infiniband/hw/ipath/ipath_ud.c
index 6991d1d74e3c..49f1102af8b3 100644
--- a/drivers/infiniband/hw/ipath/ipath_ud.c
+++ b/drivers/infiniband/hw/ipath/ipath_ud.c
@@ -39,7 +39,6 @@
39static int init_sge(struct ipath_qp *qp, struct ipath_rwqe *wqe, 39static int init_sge(struct ipath_qp *qp, struct ipath_rwqe *wqe,
40 u32 *lengthp, struct ipath_sge_state *ss) 40 u32 *lengthp, struct ipath_sge_state *ss)
41{ 41{
42 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
43 int user = to_ipd(qp->ibqp.pd)->user; 42 int user = to_ipd(qp->ibqp.pd)->user;
44 int i, j, ret; 43 int i, j, ret;
45 struct ib_wc wc; 44 struct ib_wc wc;
@@ -50,8 +49,7 @@ static int init_sge(struct ipath_qp *qp, struct ipath_rwqe *wqe,
50 continue; 49 continue;
51 /* Check LKEY */ 50 /* Check LKEY */
52 if ((user && wqe->sg_list[i].lkey == 0) || 51 if ((user && wqe->sg_list[i].lkey == 0) ||
53 !ipath_lkey_ok(&dev->lk_table, 52 !ipath_lkey_ok(qp, j ? &ss->sg_list[j - 1] : &ss->sge,
54 j ? &ss->sg_list[j - 1] : &ss->sge,
55 &wqe->sg_list[i], IB_ACCESS_LOCAL_WRITE)) 53 &wqe->sg_list[i], IB_ACCESS_LOCAL_WRITE))
56 goto bad_lkey; 54 goto bad_lkey;
57 *lengthp += wqe->sg_list[i].length; 55 *lengthp += wqe->sg_list[i].length;
@@ -343,7 +341,7 @@ int ipath_post_ud_send(struct ipath_qp *qp, struct ib_send_wr *wr)
343 341
344 if (wr->sg_list[i].length == 0) 342 if (wr->sg_list[i].length == 0)
345 continue; 343 continue;
346 if (!ipath_lkey_ok(&dev->lk_table, ss.num_sge ? 344 if (!ipath_lkey_ok(qp, ss.num_sge ?
347 sg_list + ss.num_sge - 1 : &ss.sge, 345 sg_list + ss.num_sge - 1 : &ss.sge,
348 &wr->sg_list[i], 0)) { 346 &wr->sg_list[i], 0)) {
349 ret = -EINVAL; 347 ret = -EINVAL;
diff --git a/drivers/infiniband/hw/ipath/ipath_user_pages.c b/drivers/infiniband/hw/ipath/ipath_user_pages.c
index e32fca9faf80..413754b1d8a2 100644
--- a/drivers/infiniband/hw/ipath/ipath_user_pages.c
+++ b/drivers/infiniband/hw/ipath/ipath_user_pages.c
@@ -90,6 +90,62 @@ bail:
90} 90}
91 91
92/** 92/**
93 * ipath_map_page - a safety wrapper around pci_map_page()
94 *
95 * A dma_addr of all 0's is interpreted by the chip as "disabled".
96 * Unfortunately, it can also be a valid dma_addr returned on some
97 * architectures.
98 *
99 * The powerpc iommu assigns dma_addrs in ascending order, so we don't
100 * have to bother with retries or mapping a dummy page to insure we
101 * don't just get the same mapping again.
102 *
103 * I'm sure we won't be so lucky with other iommu's, so FIXME.
104 */
105dma_addr_t ipath_map_page(struct pci_dev *hwdev, struct page *page,
106 unsigned long offset, size_t size, int direction)
107{
108 dma_addr_t phys;
109
110 phys = pci_map_page(hwdev, page, offset, size, direction);
111
112 if (phys == 0) {
113 pci_unmap_page(hwdev, phys, size, direction);
114 phys = pci_map_page(hwdev, page, offset, size, direction);
115 /*
116 * FIXME: If we get 0 again, we should keep this page,
117 * map another, then free the 0 page.
118 */
119 }
120
121 return phys;
122}
123
124/**
125 * ipath_map_single - a safety wrapper around pci_map_single()
126 *
127 * Same idea as ipath_map_page().
128 */
129dma_addr_t ipath_map_single(struct pci_dev *hwdev, void *ptr, size_t size,
130 int direction)
131{
132 dma_addr_t phys;
133
134 phys = pci_map_single(hwdev, ptr, size, direction);
135
136 if (phys == 0) {
137 pci_unmap_single(hwdev, phys, size, direction);
138 phys = pci_map_single(hwdev, ptr, size, direction);
139 /*
140 * FIXME: If we get 0 again, we should keep this page,
141 * map another, then free the 0 page.
142 */
143 }
144
145 return phys;
146}
147
148/**
93 * ipath_get_user_pages - lock user pages into memory 149 * ipath_get_user_pages - lock user pages into memory
94 * @start_page: the start page 150 * @start_page: the start page
95 * @num_pages: the number of pages 151 * @num_pages: the number of pages
diff --git a/drivers/infiniband/hw/ipath/ipath_verbs.c b/drivers/infiniband/hw/ipath/ipath_verbs.c
index b8381c5e72bd..a5456108dbad 100644
--- a/drivers/infiniband/hw/ipath/ipath_verbs.c
+++ b/drivers/infiniband/hw/ipath/ipath_verbs.c
@@ -898,7 +898,8 @@ int ipath_get_counters(struct ipath_devdata *dd,
898 ipath_snap_cntr(dd, dd->ipath_cregs->cr_erricrccnt) + 898 ipath_snap_cntr(dd, dd->ipath_cregs->cr_erricrccnt) +
899 ipath_snap_cntr(dd, dd->ipath_cregs->cr_errvcrccnt) + 899 ipath_snap_cntr(dd, dd->ipath_cregs->cr_errvcrccnt) +
900 ipath_snap_cntr(dd, dd->ipath_cregs->cr_errlpcrccnt) + 900 ipath_snap_cntr(dd, dd->ipath_cregs->cr_errlpcrccnt) +
901 ipath_snap_cntr(dd, dd->ipath_cregs->cr_badformatcnt); 901 ipath_snap_cntr(dd, dd->ipath_cregs->cr_badformatcnt) +
902 dd->ipath_rxfc_unsupvl_errs;
902 cntrs->port_rcv_remphys_errors = 903 cntrs->port_rcv_remphys_errors =
903 ipath_snap_cntr(dd, dd->ipath_cregs->cr_rcvebpcnt); 904 ipath_snap_cntr(dd, dd->ipath_cregs->cr_rcvebpcnt);
904 cntrs->port_xmit_discards = 905 cntrs->port_xmit_discards =
@@ -911,8 +912,10 @@ int ipath_get_counters(struct ipath_devdata *dd,
911 ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt); 912 ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
912 cntrs->port_rcv_packets = 913 cntrs->port_rcv_packets =
913 ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt); 914 ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
914 cntrs->local_link_integrity_errors = dd->ipath_lli_errors; 915 cntrs->local_link_integrity_errors =
915 cntrs->excessive_buffer_overrun_errors = 0; /* XXX */ 916 (dd->ipath_flags & IPATH_GPIO_ERRINTRS) ?
917 dd->ipath_lli_errs : dd->ipath_lli_errors;
918 cntrs->excessive_buffer_overrun_errors = dd->ipath_overrun_thresh_errs;
916 919
917 ret = 0; 920 ret = 0;
918 921
@@ -1199,6 +1202,7 @@ static struct ib_ah *ipath_create_ah(struct ib_pd *pd,
1199 struct ipath_ah *ah; 1202 struct ipath_ah *ah;
1200 struct ib_ah *ret; 1203 struct ib_ah *ret;
1201 struct ipath_ibdev *dev = to_idev(pd->device); 1204 struct ipath_ibdev *dev = to_idev(pd->device);
1205 unsigned long flags;
1202 1206
1203 /* A multicast address requires a GRH (see ch. 8.4.1). */ 1207 /* A multicast address requires a GRH (see ch. 8.4.1). */
1204 if (ah_attr->dlid >= IPATH_MULTICAST_LID_BASE && 1208 if (ah_attr->dlid >= IPATH_MULTICAST_LID_BASE &&
@@ -1225,16 +1229,16 @@ static struct ib_ah *ipath_create_ah(struct ib_pd *pd,
1225 goto bail; 1229 goto bail;
1226 } 1230 }
1227 1231
1228 spin_lock(&dev->n_ahs_lock); 1232 spin_lock_irqsave(&dev->n_ahs_lock, flags);
1229 if (dev->n_ahs_allocated == ib_ipath_max_ahs) { 1233 if (dev->n_ahs_allocated == ib_ipath_max_ahs) {
1230 spin_unlock(&dev->n_ahs_lock); 1234 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
1231 kfree(ah); 1235 kfree(ah);
1232 ret = ERR_PTR(-ENOMEM); 1236 ret = ERR_PTR(-ENOMEM);
1233 goto bail; 1237 goto bail;
1234 } 1238 }
1235 1239
1236 dev->n_ahs_allocated++; 1240 dev->n_ahs_allocated++;
1237 spin_unlock(&dev->n_ahs_lock); 1241 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
1238 1242
1239 /* ib_create_ah() will initialize ah->ibah. */ 1243 /* ib_create_ah() will initialize ah->ibah. */
1240 ah->attr = *ah_attr; 1244 ah->attr = *ah_attr;
@@ -1255,10 +1259,11 @@ static int ipath_destroy_ah(struct ib_ah *ibah)
1255{ 1259{
1256 struct ipath_ibdev *dev = to_idev(ibah->device); 1260 struct ipath_ibdev *dev = to_idev(ibah->device);
1257 struct ipath_ah *ah = to_iah(ibah); 1261 struct ipath_ah *ah = to_iah(ibah);
1262 unsigned long flags;
1258 1263
1259 spin_lock(&dev->n_ahs_lock); 1264 spin_lock_irqsave(&dev->n_ahs_lock, flags);
1260 dev->n_ahs_allocated--; 1265 dev->n_ahs_allocated--;
1261 spin_unlock(&dev->n_ahs_lock); 1266 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
1262 1267
1263 kfree(ah); 1268 kfree(ah);
1264 1269
@@ -1380,11 +1385,13 @@ static int enable_timer(struct ipath_devdata *dd)
1380 * processing. 1385 * processing.
1381 */ 1386 */
1382 if (dd->ipath_flags & IPATH_GPIO_INTR) { 1387 if (dd->ipath_flags & IPATH_GPIO_INTR) {
1388 u64 val;
1383 ipath_write_kreg(dd, dd->ipath_kregs->kr_debugportselect, 1389 ipath_write_kreg(dd, dd->ipath_kregs->kr_debugportselect,
1384 0x2074076542310ULL); 1390 0x2074076542310ULL);
1385 /* Enable GPIO bit 2 interrupt */ 1391 /* Enable GPIO bit 2 interrupt */
1386 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask, 1392 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_gpio_mask);
1387 (u64) (1 << 2)); 1393 val |= (u64) (1 << IPATH_GPIO_PORT0_BIT);
1394 ipath_write_kreg( dd, dd->ipath_kregs->kr_gpio_mask, val);
1388 } 1395 }
1389 1396
1390 init_timer(&dd->verbs_timer); 1397 init_timer(&dd->verbs_timer);
@@ -1399,8 +1406,17 @@ static int enable_timer(struct ipath_devdata *dd)
1399static int disable_timer(struct ipath_devdata *dd) 1406static int disable_timer(struct ipath_devdata *dd)
1400{ 1407{
1401 /* Disable GPIO bit 2 interrupt */ 1408 /* Disable GPIO bit 2 interrupt */
1402 if (dd->ipath_flags & IPATH_GPIO_INTR) 1409 if (dd->ipath_flags & IPATH_GPIO_INTR) {
1403 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask, 0); 1410 u64 val;
1411 /* Disable GPIO bit 2 interrupt */
1412 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_gpio_mask);
1413 val &= ~((u64) (1 << IPATH_GPIO_PORT0_BIT));
1414 ipath_write_kreg( dd, dd->ipath_kregs->kr_gpio_mask, val);
1415 /*
1416 * We might want to undo changes to debugportselect,
1417 * but how?
1418 */
1419 }
1404 1420
1405 del_timer_sync(&dd->verbs_timer); 1421 del_timer_sync(&dd->verbs_timer);
1406 1422
@@ -1585,7 +1601,7 @@ int ipath_register_ib_device(struct ipath_devdata *dd)
1585 dev->mmap = ipath_mmap; 1601 dev->mmap = ipath_mmap;
1586 1602
1587 snprintf(dev->node_desc, sizeof(dev->node_desc), 1603 snprintf(dev->node_desc, sizeof(dev->node_desc),
1588 IPATH_IDSTR " %s", system_utsname.nodename); 1604 IPATH_IDSTR " %s", init_utsname()->nodename);
1589 1605
1590 ret = ib_register_device(dev); 1606 ret = ib_register_device(dev);
1591 if (ret) 1607 if (ret)
@@ -1683,6 +1699,7 @@ static ssize_t show_stats(struct class_device *cdev, char *buf)
1683 "RC OTH NAKs %d\n" 1699 "RC OTH NAKs %d\n"
1684 "RC timeouts %d\n" 1700 "RC timeouts %d\n"
1685 "RC RDMA dup %d\n" 1701 "RC RDMA dup %d\n"
1702 "RC stalls %d\n"
1686 "piobuf wait %d\n" 1703 "piobuf wait %d\n"
1687 "no piobuf %d\n" 1704 "no piobuf %d\n"
1688 "PKT drops %d\n" 1705 "PKT drops %d\n"
@@ -1690,7 +1707,7 @@ static ssize_t show_stats(struct class_device *cdev, char *buf)
1690 dev->n_rc_resends, dev->n_rc_qacks, dev->n_rc_acks, 1707 dev->n_rc_resends, dev->n_rc_qacks, dev->n_rc_acks,
1691 dev->n_seq_naks, dev->n_rdma_seq, dev->n_rnr_naks, 1708 dev->n_seq_naks, dev->n_rdma_seq, dev->n_rnr_naks,
1692 dev->n_other_naks, dev->n_timeouts, 1709 dev->n_other_naks, dev->n_timeouts,
1693 dev->n_rdma_dup_busy, dev->n_piowait, 1710 dev->n_rdma_dup_busy, dev->n_rc_stalls, dev->n_piowait,
1694 dev->n_no_piobuf, dev->n_pkt_drops, dev->n_wqe_errs); 1711 dev->n_no_piobuf, dev->n_pkt_drops, dev->n_wqe_errs);
1695 for (i = 0; i < ARRAY_SIZE(dev->opstats); i++) { 1712 for (i = 0; i < ARRAY_SIZE(dev->opstats); i++) {
1696 const struct ipath_opcode_stats *si = &dev->opstats[i]; 1713 const struct ipath_opcode_stats *si = &dev->opstats[i];
diff --git a/drivers/infiniband/hw/ipath/ipath_verbs.h b/drivers/infiniband/hw/ipath/ipath_verbs.h
index 09bbb3f9a217..8039f6e5f0c8 100644
--- a/drivers/infiniband/hw/ipath/ipath_verbs.h
+++ b/drivers/infiniband/hw/ipath/ipath_verbs.h
@@ -220,6 +220,7 @@ struct ipath_segarray {
220}; 220};
221 221
222struct ipath_mregion { 222struct ipath_mregion {
223 struct ib_pd *pd; /* shares refcnt of ibmr.pd */
223 u64 user_base; /* User's address for this region */ 224 u64 user_base; /* User's address for this region */
224 u64 iova; /* IB start address of this region */ 225 u64 iova; /* IB start address of this region */
225 size_t length; 226 size_t length;
@@ -364,12 +365,14 @@ struct ipath_qp {
364 u8 r_min_rnr_timer; /* retry timeout value for RNR NAKs */ 365 u8 r_min_rnr_timer; /* retry timeout value for RNR NAKs */
365 u8 r_reuse_sge; /* for UC receive errors */ 366 u8 r_reuse_sge; /* for UC receive errors */
366 u8 r_sge_inx; /* current index into sg_list */ 367 u8 r_sge_inx; /* current index into sg_list */
368 u8 r_wrid_valid; /* r_wrid set but CQ entry not yet made */
367 u8 qp_access_flags; 369 u8 qp_access_flags;
368 u8 s_max_sge; /* size of s_wq->sg_list */ 370 u8 s_max_sge; /* size of s_wq->sg_list */
369 u8 s_retry_cnt; /* number of times to retry */ 371 u8 s_retry_cnt; /* number of times to retry */
370 u8 s_rnr_retry_cnt; 372 u8 s_rnr_retry_cnt;
371 u8 s_retry; /* requester retry counter */ 373 u8 s_retry; /* requester retry counter */
372 u8 s_rnr_retry; /* requester RNR retry counter */ 374 u8 s_rnr_retry; /* requester RNR retry counter */
375 u8 s_wait_credit; /* limit number of unacked packets sent */
373 u8 s_pkey_index; /* PKEY index to use */ 376 u8 s_pkey_index; /* PKEY index to use */
374 u8 timeout; /* Timeout for this QP */ 377 u8 timeout; /* Timeout for this QP */
375 enum ib_mtu path_mtu; 378 enum ib_mtu path_mtu;
@@ -393,6 +396,8 @@ struct ipath_qp {
393#define IPATH_S_BUSY 0 396#define IPATH_S_BUSY 0
394#define IPATH_S_SIGNAL_REQ_WR 1 397#define IPATH_S_SIGNAL_REQ_WR 1
395 398
399#define IPATH_PSN_CREDIT 2048
400
396/* 401/*
397 * Since struct ipath_swqe is not a fixed size, we can't simply index into 402 * Since struct ipath_swqe is not a fixed size, we can't simply index into
398 * struct ipath_qp.s_wq. This function does the array index computation. 403 * struct ipath_qp.s_wq. This function does the array index computation.
@@ -521,6 +526,7 @@ struct ipath_ibdev {
521 u32 n_rnr_naks; 526 u32 n_rnr_naks;
522 u32 n_other_naks; 527 u32 n_other_naks;
523 u32 n_timeouts; 528 u32 n_timeouts;
529 u32 n_rc_stalls;
524 u32 n_pkt_drops; 530 u32 n_pkt_drops;
525 u32 n_vl15_dropped; 531 u32 n_vl15_dropped;
526 u32 n_wqe_errs; 532 u32 n_wqe_errs;
@@ -634,6 +640,8 @@ struct ib_qp *ipath_create_qp(struct ib_pd *ibpd,
634 640
635int ipath_destroy_qp(struct ib_qp *ibqp); 641int ipath_destroy_qp(struct ib_qp *ibqp);
636 642
643void ipath_error_qp(struct ipath_qp *qp, enum ib_wc_status err);
644
637int ipath_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, 645int ipath_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
638 int attr_mask, struct ib_udata *udata); 646 int attr_mask, struct ib_udata *udata);
639 647
@@ -653,12 +661,6 @@ int ipath_verbs_send(struct ipath_devdata *dd, u32 hdrwords,
653 661
654void ipath_cq_enter(struct ipath_cq *cq, struct ib_wc *entry, int sig); 662void ipath_cq_enter(struct ipath_cq *cq, struct ib_wc *entry, int sig);
655 663
656int ipath_rkey_ok(struct ipath_ibdev *dev, struct ipath_sge_state *ss,
657 u32 len, u64 vaddr, u32 rkey, int acc);
658
659int ipath_lkey_ok(struct ipath_lkey_table *rkt, struct ipath_sge *isge,
660 struct ib_sge *sge, int acc);
661
662void ipath_copy_sge(struct ipath_sge_state *ss, void *data, u32 length); 664void ipath_copy_sge(struct ipath_sge_state *ss, void *data, u32 length);
663 665
664void ipath_skip_sge(struct ipath_sge_state *ss, u32 length); 666void ipath_skip_sge(struct ipath_sge_state *ss, u32 length);
@@ -683,10 +685,10 @@ int ipath_alloc_lkey(struct ipath_lkey_table *rkt,
683 685
684void ipath_free_lkey(struct ipath_lkey_table *rkt, u32 lkey); 686void ipath_free_lkey(struct ipath_lkey_table *rkt, u32 lkey);
685 687
686int ipath_lkey_ok(struct ipath_lkey_table *rkt, struct ipath_sge *isge, 688int ipath_lkey_ok(struct ipath_qp *qp, struct ipath_sge *isge,
687 struct ib_sge *sge, int acc); 689 struct ib_sge *sge, int acc);
688 690
689int ipath_rkey_ok(struct ipath_ibdev *dev, struct ipath_sge_state *ss, 691int ipath_rkey_ok(struct ipath_qp *qp, struct ipath_sge_state *ss,
690 u32 len, u64 vaddr, u32 rkey, int acc); 692 u32 len, u64 vaddr, u32 rkey, int acc);
691 693
692int ipath_post_srq_receive(struct ib_srq *ibsrq, struct ib_recv_wr *wr, 694int ipath_post_srq_receive(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
diff --git a/drivers/infiniband/hw/ipath/ipath_wc_ppc64.c b/drivers/infiniband/hw/ipath/ipath_wc_ppc64.c
index 036fde662aa9..0095bb70f34e 100644
--- a/drivers/infiniband/hw/ipath/ipath_wc_ppc64.c
+++ b/drivers/infiniband/hw/ipath/ipath_wc_ppc64.c
@@ -38,13 +38,23 @@
38#include "ipath_kernel.h" 38#include "ipath_kernel.h"
39 39
40/** 40/**
41 * ipath_unordered_wc - indicate whether write combining is ordered 41 * ipath_enable_wc - enable write combining for MMIO writes to the device
42 * @dd: infinipath device
42 * 43 *
43 * PowerPC systems (at least those in the 970 processor family) 44 * Nothing to do on PowerPC, so just return without error.
44 * write partially filled store buffers in address order, but will write 45 */
45 * completely filled store buffers in "random" order, and therefore must 46int ipath_enable_wc(struct ipath_devdata *dd)
46 * have serialization for correctness with current InfiniPath chips. 47{
48 return 0;
49}
50
51/**
52 * ipath_unordered_wc - indicate whether write combining is unordered
47 * 53 *
54 * Because our performance depends on our ability to do write
55 * combining mmio writes in the most efficient way, we need to
56 * know if we are on a processor that may reorder stores when
57 * write combining.
48 */ 58 */
49int ipath_unordered_wc(void) 59int ipath_unordered_wc(void)
50{ 60{
diff --git a/drivers/infiniband/hw/ipath/ipath_wc_x86_64.c b/drivers/infiniband/hw/ipath/ipath_wc_x86_64.c
index f8f9e2e8cbdd..04696e62da87 100644
--- a/drivers/infiniband/hw/ipath/ipath_wc_x86_64.c
+++ b/drivers/infiniband/hw/ipath/ipath_wc_x86_64.c
@@ -123,6 +123,8 @@ int ipath_enable_wc(struct ipath_devdata *dd)
123 ipath_cdbg(VERBOSE, "Set mtrr for chip to WC, " 123 ipath_cdbg(VERBOSE, "Set mtrr for chip to WC, "
124 "cookie is %d\n", cookie); 124 "cookie is %d\n", cookie);
125 dd->ipath_wc_cookie = cookie; 125 dd->ipath_wc_cookie = cookie;
126 dd->ipath_wc_base = (unsigned long) pioaddr;
127 dd->ipath_wc_len = (unsigned long) piolen;
126 } 128 }
127 } 129 }
128 130
@@ -136,9 +138,16 @@ int ipath_enable_wc(struct ipath_devdata *dd)
136void ipath_disable_wc(struct ipath_devdata *dd) 138void ipath_disable_wc(struct ipath_devdata *dd)
137{ 139{
138 if (dd->ipath_wc_cookie) { 140 if (dd->ipath_wc_cookie) {
141 int r;
139 ipath_cdbg(VERBOSE, "undoing WCCOMB on pio buffers\n"); 142 ipath_cdbg(VERBOSE, "undoing WCCOMB on pio buffers\n");
140 mtrr_del(dd->ipath_wc_cookie, 0, 0); 143 r = mtrr_del(dd->ipath_wc_cookie, dd->ipath_wc_base,
141 dd->ipath_wc_cookie = 0; 144 dd->ipath_wc_len);
145 if (r < 0)
146 dev_info(&dd->pcidev->dev,
147 "mtrr_del(%lx, %lx, %lx) failed: %d\n",
148 dd->ipath_wc_cookie, dd->ipath_wc_base,
149 dd->ipath_wc_len, r);
150 dd->ipath_wc_cookie = 0; /* even on failure */
142 } 151 }
143} 152}
144 153
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_fs.c b/drivers/infiniband/ulp/ipoib/ipoib_fs.c
index 5dde380e8dbe..f1cb83688b31 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_fs.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_fs.c
@@ -141,7 +141,7 @@ static int ipoib_mcg_open(struct inode *inode, struct file *file)
141 return ret; 141 return ret;
142 142
143 seq = file->private_data; 143 seq = file->private_data;
144 seq->private = inode->u.generic_ip; 144 seq->private = inode->i_private;
145 145
146 return 0; 146 return 0;
147} 147}
@@ -247,7 +247,7 @@ static int ipoib_path_open(struct inode *inode, struct file *file)
247 return ret; 247 return ret;
248 248
249 seq = file->private_data; 249 seq = file->private_data;
250 seq->private = inode->u.generic_ip; 250 seq->private = inode->i_private;
251 251
252 return 0; 252 return 0;
253} 253}
diff --git a/drivers/infiniband/ulp/iser/Kconfig b/drivers/infiniband/ulp/iser/Kconfig
index 365a1b5f19e0..aecbb9083f0c 100644
--- a/drivers/infiniband/ulp/iser/Kconfig
+++ b/drivers/infiniband/ulp/iser/Kconfig
@@ -1,11 +1,12 @@
1config INFINIBAND_ISER 1config INFINIBAND_ISER
2 tristate "ISCSI RDMA Protocol" 2 tristate "iSCSI Extensions for RDMA (iSER)"
3 depends on INFINIBAND && SCSI && INET 3 depends on INFINIBAND && SCSI && INET
4 select SCSI_ISCSI_ATTRS 4 select SCSI_ISCSI_ATTRS
5 ---help--- 5 ---help---
6 Support for the ISCSI RDMA Protocol over InfiniBand. This 6 Support for the iSCSI Extensions for RDMA (iSER) Protocol
7 allows you to access storage devices that speak ISER/ISCSI 7 over InfiniBand. This allows you to access storage devices
8 over InfiniBand. 8 that speak iSCSI over iSER over InfiniBand.
9 9
10 The ISER protocol is defined by IETF. 10 The iSER protocol is defined by IETF.
11 See <http://www.ietf.org/>. 11 See <http://www.ietf.org/internet-drafts/draft-ietf-ips-iser-05.txt>
12 and <http://www.infinibandta.org/members/spec/iser_annex_060418.pdf>
diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c
index 2a14fe2e3226..eb6f98d82289 100644
--- a/drivers/infiniband/ulp/iser/iscsi_iser.c
+++ b/drivers/infiniband/ulp/iser/iscsi_iser.c
@@ -317,6 +317,8 @@ iscsi_iser_conn_destroy(struct iscsi_cls_conn *cls_conn)
317 struct iscsi_iser_conn *iser_conn = conn->dd_data; 317 struct iscsi_iser_conn *iser_conn = conn->dd_data;
318 318
319 iscsi_conn_teardown(cls_conn); 319 iscsi_conn_teardown(cls_conn);
320 if (iser_conn->ib_conn)
321 iser_conn->ib_conn->iser_conn = NULL;
320 kfree(iser_conn); 322 kfree(iser_conn);
321} 323}
322 324
diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.h b/drivers/infiniband/ulp/iser/iscsi_iser.h
index 2cf9ae0def1c..9c53916f28c2 100644
--- a/drivers/infiniband/ulp/iser/iscsi_iser.h
+++ b/drivers/infiniband/ulp/iser/iscsi_iser.h
@@ -192,7 +192,7 @@ struct iser_regd_buf {
192 192
193struct iser_dto { 193struct iser_dto {
194 struct iscsi_iser_cmd_task *ctask; 194 struct iscsi_iser_cmd_task *ctask;
195 struct iscsi_iser_conn *conn; 195 struct iser_conn *ib_conn;
196 int notify_enable; 196 int notify_enable;
197 197
198 /* vector of registered buffers */ 198 /* vector of registered buffers */
@@ -355,4 +355,11 @@ int iser_post_send(struct iser_desc *tx_desc);
355 355
356int iser_conn_state_comp(struct iser_conn *ib_conn, 356int iser_conn_state_comp(struct iser_conn *ib_conn,
357 enum iser_ib_conn_state comp); 357 enum iser_ib_conn_state comp);
358
359int iser_dma_map_task_data(struct iscsi_iser_cmd_task *iser_ctask,
360 struct iser_data_buf *data,
361 enum iser_data_dir iser_dir,
362 enum dma_data_direction dma_dir);
363
364void iser_dma_unmap_task_data(struct iscsi_iser_cmd_task *iser_ctask);
358#endif 365#endif
diff --git a/drivers/infiniband/ulp/iser/iser_initiator.c b/drivers/infiniband/ulp/iser/iser_initiator.c
index ccf56f6f7236..9b3d79c796c8 100644
--- a/drivers/infiniband/ulp/iser/iser_initiator.c
+++ b/drivers/infiniband/ulp/iser/iser_initiator.c
@@ -66,42 +66,6 @@ static void iser_dto_add_regd_buff(struct iser_dto *dto,
66 dto->regd_vector_len++; 66 dto->regd_vector_len++;
67} 67}
68 68
69static int iser_dma_map_task_data(struct iscsi_iser_cmd_task *iser_ctask,
70 struct iser_data_buf *data,
71 enum iser_data_dir iser_dir,
72 enum dma_data_direction dma_dir)
73{
74 struct device *dma_device;
75
76 iser_ctask->dir[iser_dir] = 1;
77 dma_device = iser_ctask->iser_conn->ib_conn->device->ib_device->dma_device;
78
79 data->dma_nents = dma_map_sg(dma_device, data->buf, data->size, dma_dir);
80 if (data->dma_nents == 0) {
81 iser_err("dma_map_sg failed!!!\n");
82 return -EINVAL;
83 }
84 return 0;
85}
86
87static void iser_dma_unmap_task_data(struct iscsi_iser_cmd_task *iser_ctask)
88{
89 struct device *dma_device;
90 struct iser_data_buf *data;
91
92 dma_device = iser_ctask->iser_conn->ib_conn->device->ib_device->dma_device;
93
94 if (iser_ctask->dir[ISER_DIR_IN]) {
95 data = &iser_ctask->data[ISER_DIR_IN];
96 dma_unmap_sg(dma_device, data->buf, data->size, DMA_FROM_DEVICE);
97 }
98
99 if (iser_ctask->dir[ISER_DIR_OUT]) {
100 data = &iser_ctask->data[ISER_DIR_OUT];
101 dma_unmap_sg(dma_device, data->buf, data->size, DMA_TO_DEVICE);
102 }
103}
104
105/* Register user buffer memory and initialize passive rdma 69/* Register user buffer memory and initialize passive rdma
106 * dto descriptor. Total data size is stored in 70 * dto descriptor. Total data size is stored in
107 * iser_ctask->data[ISER_DIR_IN].data_len 71 * iser_ctask->data[ISER_DIR_IN].data_len
@@ -249,7 +213,7 @@ static int iser_post_receive_control(struct iscsi_conn *conn)
249 } 213 }
250 214
251 recv_dto = &rx_desc->dto; 215 recv_dto = &rx_desc->dto;
252 recv_dto->conn = iser_conn; 216 recv_dto->ib_conn = iser_conn->ib_conn;
253 recv_dto->regd_vector_len = 0; 217 recv_dto->regd_vector_len = 0;
254 218
255 regd_hdr = &rx_desc->hdr_regd_buf; 219 regd_hdr = &rx_desc->hdr_regd_buf;
@@ -296,7 +260,7 @@ static void iser_create_send_desc(struct iscsi_iser_conn *iser_conn,
296 regd_hdr->virt_addr = tx_desc; /* == &tx_desc->iser_header */ 260 regd_hdr->virt_addr = tx_desc; /* == &tx_desc->iser_header */
297 regd_hdr->data_size = ISER_TOTAL_HEADERS_LEN; 261 regd_hdr->data_size = ISER_TOTAL_HEADERS_LEN;
298 262
299 send_dto->conn = iser_conn; 263 send_dto->ib_conn = iser_conn->ib_conn;
300 send_dto->notify_enable = 1; 264 send_dto->notify_enable = 1;
301 send_dto->regd_vector_len = 0; 265 send_dto->regd_vector_len = 0;
302 266
@@ -588,7 +552,7 @@ void iser_rcv_completion(struct iser_desc *rx_desc,
588 unsigned long dto_xfer_len) 552 unsigned long dto_xfer_len)
589{ 553{
590 struct iser_dto *dto = &rx_desc->dto; 554 struct iser_dto *dto = &rx_desc->dto;
591 struct iscsi_iser_conn *conn = dto->conn; 555 struct iscsi_iser_conn *conn = dto->ib_conn->iser_conn;
592 struct iscsi_session *session = conn->iscsi_conn->session; 556 struct iscsi_session *session = conn->iscsi_conn->session;
593 struct iscsi_cmd_task *ctask; 557 struct iscsi_cmd_task *ctask;
594 struct iscsi_iser_cmd_task *iser_ctask; 558 struct iscsi_iser_cmd_task *iser_ctask;
@@ -641,7 +605,8 @@ void iser_rcv_completion(struct iser_desc *rx_desc,
641void iser_snd_completion(struct iser_desc *tx_desc) 605void iser_snd_completion(struct iser_desc *tx_desc)
642{ 606{
643 struct iser_dto *dto = &tx_desc->dto; 607 struct iser_dto *dto = &tx_desc->dto;
644 struct iscsi_iser_conn *iser_conn = dto->conn; 608 struct iser_conn *ib_conn = dto->ib_conn;
609 struct iscsi_iser_conn *iser_conn = ib_conn->iser_conn;
645 struct iscsi_conn *conn = iser_conn->iscsi_conn; 610 struct iscsi_conn *conn = iser_conn->iscsi_conn;
646 struct iscsi_mgmt_task *mtask; 611 struct iscsi_mgmt_task *mtask;
647 612
@@ -652,7 +617,7 @@ void iser_snd_completion(struct iser_desc *tx_desc)
652 if (tx_desc->type == ISCSI_TX_DATAOUT) 617 if (tx_desc->type == ISCSI_TX_DATAOUT)
653 kmem_cache_free(ig.desc_cache, tx_desc); 618 kmem_cache_free(ig.desc_cache, tx_desc);
654 619
655 atomic_dec(&iser_conn->ib_conn->post_send_buf_count); 620 atomic_dec(&ib_conn->post_send_buf_count);
656 621
657 write_lock(conn->recv_lock); 622 write_lock(conn->recv_lock);
658 if (conn->suspend_tx) { 623 if (conn->suspend_tx) {
@@ -698,14 +663,19 @@ void iser_ctask_rdma_init(struct iscsi_iser_cmd_task *iser_ctask)
698void iser_ctask_rdma_finalize(struct iscsi_iser_cmd_task *iser_ctask) 663void iser_ctask_rdma_finalize(struct iscsi_iser_cmd_task *iser_ctask)
699{ 664{
700 int deferred; 665 int deferred;
666 int is_rdma_aligned = 1;
701 667
702 /* if we were reading, copy back to unaligned sglist, 668 /* if we were reading, copy back to unaligned sglist,
703 * anyway dma_unmap and free the copy 669 * anyway dma_unmap and free the copy
704 */ 670 */
705 if (iser_ctask->data_copy[ISER_DIR_IN].copy_buf != NULL) 671 if (iser_ctask->data_copy[ISER_DIR_IN].copy_buf != NULL) {
672 is_rdma_aligned = 0;
706 iser_finalize_rdma_unaligned_sg(iser_ctask, ISER_DIR_IN); 673 iser_finalize_rdma_unaligned_sg(iser_ctask, ISER_DIR_IN);
707 if (iser_ctask->data_copy[ISER_DIR_OUT].copy_buf != NULL) 674 }
675 if (iser_ctask->data_copy[ISER_DIR_OUT].copy_buf != NULL) {
676 is_rdma_aligned = 0;
708 iser_finalize_rdma_unaligned_sg(iser_ctask, ISER_DIR_OUT); 677 iser_finalize_rdma_unaligned_sg(iser_ctask, ISER_DIR_OUT);
678 }
709 679
710 if (iser_ctask->dir[ISER_DIR_IN]) { 680 if (iser_ctask->dir[ISER_DIR_IN]) {
711 deferred = iser_regd_buff_release 681 deferred = iser_regd_buff_release
@@ -725,7 +695,9 @@ void iser_ctask_rdma_finalize(struct iscsi_iser_cmd_task *iser_ctask)
725 } 695 }
726 } 696 }
727 697
728 iser_dma_unmap_task_data(iser_ctask); 698 /* if the data was unaligned, it was already unmapped and then copied */
699 if (is_rdma_aligned)
700 iser_dma_unmap_task_data(iser_ctask);
729} 701}
730 702
731void iser_dto_buffs_release(struct iser_dto *dto) 703void iser_dto_buffs_release(struct iser_dto *dto)
diff --git a/drivers/infiniband/ulp/iser/iser_memory.c b/drivers/infiniband/ulp/iser/iser_memory.c
index d0b03f426581..0606744c3f84 100644
--- a/drivers/infiniband/ulp/iser/iser_memory.c
+++ b/drivers/infiniband/ulp/iser/iser_memory.c
@@ -369,6 +369,44 @@ static void iser_page_vec_build(struct iser_data_buf *data,
369 } 369 }
370} 370}
371 371
372int iser_dma_map_task_data(struct iscsi_iser_cmd_task *iser_ctask,
373 struct iser_data_buf *data,
374 enum iser_data_dir iser_dir,
375 enum dma_data_direction dma_dir)
376{
377 struct device *dma_device;
378
379 iser_ctask->dir[iser_dir] = 1;
380 dma_device =
381 iser_ctask->iser_conn->ib_conn->device->ib_device->dma_device;
382
383 data->dma_nents = dma_map_sg(dma_device, data->buf, data->size, dma_dir);
384 if (data->dma_nents == 0) {
385 iser_err("dma_map_sg failed!!!\n");
386 return -EINVAL;
387 }
388 return 0;
389}
390
391void iser_dma_unmap_task_data(struct iscsi_iser_cmd_task *iser_ctask)
392{
393 struct device *dma_device;
394 struct iser_data_buf *data;
395
396 dma_device =
397 iser_ctask->iser_conn->ib_conn->device->ib_device->dma_device;
398
399 if (iser_ctask->dir[ISER_DIR_IN]) {
400 data = &iser_ctask->data[ISER_DIR_IN];
401 dma_unmap_sg(dma_device, data->buf, data->size, DMA_FROM_DEVICE);
402 }
403
404 if (iser_ctask->dir[ISER_DIR_OUT]) {
405 data = &iser_ctask->data[ISER_DIR_OUT];
406 dma_unmap_sg(dma_device, data->buf, data->size, DMA_TO_DEVICE);
407 }
408}
409
372/** 410/**
373 * iser_reg_rdma_mem - Registers memory intended for RDMA, 411 * iser_reg_rdma_mem - Registers memory intended for RDMA,
374 * obtaining rkey and va 412 * obtaining rkey and va
@@ -394,6 +432,10 @@ int iser_reg_rdma_mem(struct iscsi_iser_cmd_task *iser_ctask,
394 iser_err("rdma alignment violation %d/%d aligned\n", 432 iser_err("rdma alignment violation %d/%d aligned\n",
395 aligned_len, mem->size); 433 aligned_len, mem->size);
396 iser_data_buf_dump(mem); 434 iser_data_buf_dump(mem);
435
436 /* unmap the command data before accessing it */
437 iser_dma_unmap_task_data(iser_ctask);
438
397 /* allocate copy buf, if we are writing, copy the */ 439 /* allocate copy buf, if we are writing, copy the */
398 /* unaligned scatterlist, dma map the copy */ 440 /* unaligned scatterlist, dma map the copy */
399 if (iser_start_rdma_unaligned_sg(iser_ctask, cmd_dir) != 0) 441 if (iser_start_rdma_unaligned_sg(iser_ctask, cmd_dir) != 0)
diff --git a/drivers/infiniband/ulp/iser/iser_verbs.c b/drivers/infiniband/ulp/iser/iser_verbs.c
index ecdca7fc1e4c..18a000034996 100644
--- a/drivers/infiniband/ulp/iser/iser_verbs.c
+++ b/drivers/infiniband/ulp/iser/iser_verbs.c
@@ -571,6 +571,8 @@ void iser_conn_release(struct iser_conn *ib_conn)
571 /* on EVENT_ADDR_ERROR there's no device yet for this conn */ 571 /* on EVENT_ADDR_ERROR there's no device yet for this conn */
572 if (device != NULL) 572 if (device != NULL)
573 iser_device_try_release(device); 573 iser_device_try_release(device);
574 if (ib_conn->iser_conn)
575 ib_conn->iser_conn->ib_conn = NULL;
574 kfree(ib_conn); 576 kfree(ib_conn);
575} 577}
576 578
@@ -694,7 +696,7 @@ int iser_post_recv(struct iser_desc *rx_desc)
694 struct iser_dto *recv_dto = &rx_desc->dto; 696 struct iser_dto *recv_dto = &rx_desc->dto;
695 697
696 /* Retrieve conn */ 698 /* Retrieve conn */
697 ib_conn = recv_dto->conn->ib_conn; 699 ib_conn = recv_dto->ib_conn;
698 700
699 iser_dto_to_iov(recv_dto, iov, 2); 701 iser_dto_to_iov(recv_dto, iov, 2);
700 702
@@ -727,7 +729,7 @@ int iser_post_send(struct iser_desc *tx_desc)
727 struct iser_conn *ib_conn; 729 struct iser_conn *ib_conn;
728 struct iser_dto *dto = &tx_desc->dto; 730 struct iser_dto *dto = &tx_desc->dto;
729 731
730 ib_conn = dto->conn->ib_conn; 732 ib_conn = dto->ib_conn;
731 733
732 iser_dto_to_iov(dto, iov, MAX_REGD_BUF_VECTOR_LEN); 734 iser_dto_to_iov(dto, iov, MAX_REGD_BUF_VECTOR_LEN);
733 735
@@ -774,7 +776,7 @@ static void iser_comp_error_worker(void *data)
774static void iser_handle_comp_error(struct iser_desc *desc) 776static void iser_handle_comp_error(struct iser_desc *desc)
775{ 777{
776 struct iser_dto *dto = &desc->dto; 778 struct iser_dto *dto = &desc->dto;
777 struct iser_conn *ib_conn = dto->conn->ib_conn; 779 struct iser_conn *ib_conn = dto->ib_conn;
778 780
779 iser_dto_buffs_release(dto); 781 iser_dto_buffs_release(dto);
780 782
diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 58223b5d842a..96232313b1b9 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -24,6 +24,20 @@ config INPUT
24 24
25if INPUT 25if INPUT
26 26
27config INPUT_FF_MEMLESS
28 tristate "Support for memoryless force-feedback devices"
29 default n
30 ---help---
31 Say Y here if you have memoryless force-feedback input device
32 such as Logitech WingMan Force 3D, ThrustMaster FireStorm Dual
33 Power 2, or similar. You will also need to enable hardware-specific
34 driver.
35
36 If unsure, say N.
37
38 To compile this driver as a module, choose M here: the
39 module will be called ff-memless.
40
27comment "Userland interfaces" 41comment "Userland interfaces"
28 42
29config INPUT_MOUSEDEV 43config INPUT_MOUSEDEV
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index 1a6ff4982f30..a005b1df5f1a 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -4,7 +4,11 @@
4 4
5# Each configuration option enables a list of files. 5# Each configuration option enables a list of files.
6 6
7obj-$(CONFIG_INPUT) += input.o 7obj-$(CONFIG_INPUT) += input-core.o
8input-core-objs := input.o ff-core.o
9
10obj-$(CONFIG_INPUT_FF_MEMLESS) += ff-memless.o
11
8obj-$(CONFIG_INPUT_MOUSEDEV) += mousedev.o 12obj-$(CONFIG_INPUT_MOUSEDEV) += mousedev.o
9obj-$(CONFIG_INPUT_JOYDEV) += joydev.o 13obj-$(CONFIG_INPUT_JOYDEV) += joydev.o
10obj-$(CONFIG_INPUT_EVDEV) += evdev.o 14obj-$(CONFIG_INPUT_EVDEV) += evdev.o
diff --git a/drivers/input/evbug.c b/drivers/input/evbug.c
index 07358fb51b82..5a9653c3128a 100644
--- a/drivers/input/evbug.c
+++ b/drivers/input/evbug.c
@@ -42,10 +42,12 @@ static char evbug_name[] = "evbug";
42 42
43static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value) 43static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
44{ 44{
45 printk(KERN_DEBUG "evbug.c: Event. Dev: %s, Type: %d, Code: %d, Value: %d\n", handle->dev->phys, type, code, value); 45 printk(KERN_DEBUG "evbug.c: Event. Dev: %s, Type: %d, Code: %d, Value: %d\n",
46 handle->dev->phys, type, code, value);
46} 47}
47 48
48static struct input_handle *evbug_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id) 49static struct input_handle *evbug_connect(struct input_handler *handler, struct input_dev *dev,
50 const struct input_device_id *id)
49{ 51{
50 struct input_handle *handle; 52 struct input_handle *handle;
51 53
@@ -72,7 +74,7 @@ static void evbug_disconnect(struct input_handle *handle)
72 kfree(handle); 74 kfree(handle);
73} 75}
74 76
75static struct input_device_id evbug_ids[] = { 77static const struct input_device_id evbug_ids[] = {
76 { .driver_info = 1 }, /* Matches all devices */ 78 { .driver_info = 1 }, /* Matches all devices */
77 { }, /* Terminating zero entry */ 79 { }, /* Terminating zero entry */
78}; 80};
@@ -89,8 +91,7 @@ static struct input_handler evbug_handler = {
89 91
90static int __init evbug_init(void) 92static int __init evbug_init(void)
91{ 93{
92 input_register_handler(&evbug_handler); 94 return input_register_handler(&evbug_handler);
93 return 0;
94} 95}
95 96
96static void __exit evbug_exit(void) 97static void __exit evbug_exit(void)
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 4bf48188cc91..6439f378f6cc 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -391,8 +391,10 @@ static long evdev_ioctl_handler(struct file *file, unsigned int cmd,
391 struct evdev *evdev = list->evdev; 391 struct evdev *evdev = list->evdev;
392 struct input_dev *dev = evdev->handle.dev; 392 struct input_dev *dev = evdev->handle.dev;
393 struct input_absinfo abs; 393 struct input_absinfo abs;
394 struct ff_effect effect;
394 int __user *ip = (int __user *)p; 395 int __user *ip = (int __user *)p;
395 int i, t, u, v; 396 int i, t, u, v;
397 int error;
396 398
397 if (!evdev->exist) 399 if (!evdev->exist)
398 return -ENODEV; 400 return -ENODEV;
@@ -460,27 +462,22 @@ static long evdev_ioctl_handler(struct file *file, unsigned int cmd,
460 return 0; 462 return 0;
461 463
462 case EVIOCSFF: 464 case EVIOCSFF:
463 if (dev->upload_effect) { 465 if (copy_from_user(&effect, p, sizeof(effect)))
464 struct ff_effect effect; 466 return -EFAULT;
465 int err;
466
467 if (copy_from_user(&effect, p, sizeof(effect)))
468 return -EFAULT;
469 err = dev->upload_effect(dev, &effect);
470 if (put_user(effect.id, &(((struct ff_effect __user *)p)->id)))
471 return -EFAULT;
472 return err;
473 } else
474 return -ENOSYS;
475 467
476 case EVIOCRMFF: 468 error = input_ff_upload(dev, &effect, file);
477 if (!dev->erase_effect)
478 return -ENOSYS;
479 469
480 return dev->erase_effect(dev, (int)(unsigned long) p); 470 if (put_user(effect.id, &(((struct ff_effect __user *)p)->id)))
471 return -EFAULT;
472
473 return error;
474
475 case EVIOCRMFF:
476 return input_ff_erase(dev, (int)(unsigned long) p, file);
481 477
482 case EVIOCGEFFECTS: 478 case EVIOCGEFFECTS:
483 if (put_user(dev->ff_effects_max, ip)) 479 i = test_bit(EV_FF, dev->evbit) ? dev->ff->max_effects : 0;
480 if (put_user(i, ip))
484 return -EFAULT; 481 return -EFAULT;
485 return 0; 482 return 0;
486 483
@@ -604,7 +601,7 @@ static long evdev_ioctl_compat(struct file *file, unsigned int cmd, unsigned lon
604} 601}
605#endif 602#endif
606 603
607static struct file_operations evdev_fops = { 604static const struct file_operations evdev_fops = {
608 .owner = THIS_MODULE, 605 .owner = THIS_MODULE,
609 .read = evdev_read, 606 .read = evdev_read,
610 .write = evdev_write, 607 .write = evdev_write,
@@ -619,7 +616,8 @@ static struct file_operations evdev_fops = {
619 .flush = evdev_flush 616 .flush = evdev_flush
620}; 617};
621 618
622static struct input_handle *evdev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id) 619static struct input_handle *evdev_connect(struct input_handler *handler, struct input_dev *dev,
620 const struct input_device_id *id)
623{ 621{
624 struct evdev *evdev; 622 struct evdev *evdev;
625 struct class_device *cdev; 623 struct class_device *cdev;
@@ -669,6 +667,7 @@ static void evdev_disconnect(struct input_handle *handle)
669 evdev->exist = 0; 667 evdev->exist = 0;
670 668
671 if (evdev->open) { 669 if (evdev->open) {
670 input_flush_device(handle, NULL);
672 input_close_device(handle); 671 input_close_device(handle);
673 wake_up_interruptible(&evdev->wait); 672 wake_up_interruptible(&evdev->wait);
674 list_for_each_entry(list, &evdev->list, node) 673 list_for_each_entry(list, &evdev->list, node)
@@ -677,7 +676,7 @@ static void evdev_disconnect(struct input_handle *handle)
677 evdev_free(evdev); 676 evdev_free(evdev);
678} 677}
679 678
680static struct input_device_id evdev_ids[] = { 679static const struct input_device_id evdev_ids[] = {
681 { .driver_info = 1 }, /* Matches all devices */ 680 { .driver_info = 1 }, /* Matches all devices */
682 { }, /* Terminating zero entry */ 681 { }, /* Terminating zero entry */
683}; 682};
@@ -696,8 +695,7 @@ static struct input_handler evdev_handler = {
696 695
697static int __init evdev_init(void) 696static int __init evdev_init(void)
698{ 697{
699 input_register_handler(&evdev_handler); 698 return input_register_handler(&evdev_handler);
700 return 0;
701} 699}
702 700
703static void __exit evdev_exit(void) 701static void __exit evdev_exit(void)
diff --git a/drivers/input/ff-core.c b/drivers/input/ff-core.c
new file mode 100644
index 000000000000..35656cadc914
--- /dev/null
+++ b/drivers/input/ff-core.c
@@ -0,0 +1,367 @@
1/*
2 * Force feedback support for Linux input subsystem
3 *
4 * Copyright (c) 2006 Anssi Hannula <anssi.hannula@gmail.com>
5 * Copyright (c) 2006 Dmitry Torokhov <dtor@mail.ru>
6 */
7
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24/* #define DEBUG */
25
26#define debug(format, arg...) pr_debug("ff-core: " format "\n", ## arg)
27
28#include <linux/input.h>
29#include <linux/module.h>
30#include <linux/mutex.h>
31
32/*
33 * Check that the effect_id is a valid effect and whether the user
34 * is the owner
35 */
36static int check_effect_access(struct ff_device *ff, int effect_id,
37 struct file *file)
38{
39 if (effect_id < 0 || effect_id >= ff->max_effects ||
40 !ff->effect_owners[effect_id])
41 return -EINVAL;
42
43 if (file && ff->effect_owners[effect_id] != file)
44 return -EACCES;
45
46 return 0;
47}
48
49/*
50 * Checks whether 2 effects can be combined together
51 */
52static inline int check_effects_compatible(struct ff_effect *e1,
53 struct ff_effect *e2)
54{
55 return e1->type == e2->type &&
56 (e1->type != FF_PERIODIC ||
57 e1->u.periodic.waveform == e2->u.periodic.waveform);
58}
59
60/*
61 * Convert an effect into compatible one
62 */
63static int compat_effect(struct ff_device *ff, struct ff_effect *effect)
64{
65 int magnitude;
66
67 switch (effect->type) {
68 case FF_RUMBLE:
69 if (!test_bit(FF_PERIODIC, ff->ffbit))
70 return -EINVAL;
71
72 /*
73 * calculate manginude of sine wave as average of rumble's
74 * 2/3 of strong magnitude and 1/3 of weak magnitude
75 */
76 magnitude = effect->u.rumble.strong_magnitude / 3 +
77 effect->u.rumble.weak_magnitude / 6;
78
79 effect->type = FF_PERIODIC;
80 effect->u.periodic.waveform = FF_SINE;
81 effect->u.periodic.period = 50;
82 effect->u.periodic.magnitude = max(magnitude, 0x7fff);
83 effect->u.periodic.offset = 0;
84 effect->u.periodic.phase = 0;
85 effect->u.periodic.envelope.attack_length = 0;
86 effect->u.periodic.envelope.attack_level = 0;
87 effect->u.periodic.envelope.fade_length = 0;
88 effect->u.periodic.envelope.fade_level = 0;
89
90 return 0;
91
92 default:
93 /* Let driver handle conversion */
94 return 0;
95 }
96}
97
98/**
99 * input_ff_upload() - upload effect into force-feedback device
100 * @dev: input device
101 * @effect: effect to be uploaded
102 * @file: owner of the effect
103 */
104int input_ff_upload(struct input_dev *dev, struct ff_effect *effect,
105 struct file *file)
106{
107 struct ff_device *ff = dev->ff;
108 struct ff_effect *old;
109 int ret = 0;
110 int id;
111
112 if (!test_bit(EV_FF, dev->evbit))
113 return -ENOSYS;
114
115 if (effect->type < FF_EFFECT_MIN || effect->type > FF_EFFECT_MAX ||
116 !test_bit(effect->type, dev->ffbit)) {
117 debug("invalid or not supported effect type in upload");
118 return -EINVAL;
119 }
120
121 if (effect->type == FF_PERIODIC &&
122 (effect->u.periodic.waveform < FF_WAVEFORM_MIN ||
123 effect->u.periodic.waveform > FF_WAVEFORM_MAX ||
124 !test_bit(effect->u.periodic.waveform, dev->ffbit))) {
125 debug("invalid or not supported wave form in upload");
126 return -EINVAL;
127 }
128
129 if (!test_bit(effect->type, ff->ffbit)) {
130 ret = compat_effect(ff, effect);
131 if (ret)
132 return ret;
133 }
134
135 mutex_lock(&ff->mutex);
136
137 if (effect->id == -1) {
138 for (id = 0; id < ff->max_effects; id++)
139 if (!ff->effect_owners[id])
140 break;
141
142 if (id >= ff->max_effects) {
143 ret = -ENOSPC;
144 goto out;
145 }
146
147 effect->id = id;
148 old = NULL;
149
150 } else {
151 id = effect->id;
152
153 ret = check_effect_access(ff, id, file);
154 if (ret)
155 goto out;
156
157 old = &ff->effects[id];
158
159 if (!check_effects_compatible(effect, old)) {
160 ret = -EINVAL;
161 goto out;
162 }
163 }
164
165 ret = ff->upload(dev, effect, old);
166 if (ret)
167 goto out;
168
169 ff->effects[id] = *effect;
170 ff->effect_owners[id] = file;
171
172 out:
173 mutex_unlock(&ff->mutex);
174 return ret;
175}
176EXPORT_SYMBOL_GPL(input_ff_upload);
177
178/*
179 * Erases the effect if the requester is also the effect owner. The mutex
180 * should already be locked before calling this function.
181 */
182static int erase_effect(struct input_dev *dev, int effect_id,
183 struct file *file)
184{
185 struct ff_device *ff = dev->ff;
186 int error;
187
188 error = check_effect_access(ff, effect_id, file);
189 if (error)
190 return error;
191
192 ff->playback(dev, effect_id, 0);
193
194 if (ff->erase) {
195 error = ff->erase(dev, effect_id);
196 if (error)
197 return error;
198 }
199
200 ff->effect_owners[effect_id] = NULL;
201
202 return 0;
203}
204
205/**
206 * input_ff_erase - erase an effect from device
207 * @dev: input device to erase effect from
208 * @effect_id: id of the ffect to be erased
209 * @file: purported owner of the request
210 *
211 * This function erases a force-feedback effect from specified device.
212 * The effect will only be erased if it was uploaded through the same
213 * file handle that is requesting erase.
214 */
215int input_ff_erase(struct input_dev *dev, int effect_id, struct file *file)
216{
217 struct ff_device *ff = dev->ff;
218 int ret;
219
220 if (!test_bit(EV_FF, dev->evbit))
221 return -ENOSYS;
222
223 mutex_lock(&ff->mutex);
224 ret = erase_effect(dev, effect_id, file);
225 mutex_unlock(&ff->mutex);
226
227 return ret;
228}
229EXPORT_SYMBOL_GPL(input_ff_erase);
230
231/*
232 * flush_effects - erase all effects owned by a file handle
233 */
234static int flush_effects(struct input_dev *dev, struct file *file)
235{
236 struct ff_device *ff = dev->ff;
237 int i;
238
239 debug("flushing now");
240
241 mutex_lock(&ff->mutex);
242
243 for (i = 0; i < ff->max_effects; i++)
244 erase_effect(dev, i, file);
245
246 mutex_unlock(&ff->mutex);
247
248 return 0;
249}
250
251/**
252 * input_ff_event() - generic handler for force-feedback events
253 * @dev: input device to send the effect to
254 * @type: event type (anything but EV_FF is ignored)
255 * @code: event code
256 * @value: event value
257 */
258int input_ff_event(struct input_dev *dev, unsigned int type,
259 unsigned int code, int value)
260{
261 struct ff_device *ff = dev->ff;
262
263 if (type != EV_FF)
264 return 0;
265
266 mutex_lock(&ff->mutex);
267
268 switch (code) {
269 case FF_GAIN:
270 if (!test_bit(FF_GAIN, dev->ffbit) || value > 0xffff)
271 break;
272
273 ff->set_gain(dev, value);
274 break;
275
276 case FF_AUTOCENTER:
277 if (!test_bit(FF_AUTOCENTER, dev->ffbit) || value > 0xffff)
278 break;
279
280 ff->set_autocenter(dev, value);
281 break;
282
283 default:
284 ff->playback(dev, code, value);
285 break;
286 }
287
288 mutex_unlock(&ff->mutex);
289 return 0;
290}
291EXPORT_SYMBOL_GPL(input_ff_event);
292
293/**
294 * input_ff_create() - create force-feedback device
295 * @dev: input device supporting force-feedback
296 * @max_effects: maximum number of effects supported by the device
297 *
298 * This function allocates all necessary memory for a force feedback
299 * portion of an input device and installs all default handlers.
300 * @dev->ffbit should be already set up before calling this function.
301 * Once ff device is created you need to setup its upload, erase,
302 * playback and other handlers before registering input device
303 */
304int input_ff_create(struct input_dev *dev, int max_effects)
305{
306 struct ff_device *ff;
307 int i;
308
309 if (!max_effects) {
310 printk(KERN_ERR
311 "ff-core: cannot allocate device without any effects\n");
312 return -EINVAL;
313 }
314
315 ff = kzalloc(sizeof(struct ff_device) +
316 max_effects * sizeof(struct file *), GFP_KERNEL);
317 if (!ff)
318 return -ENOMEM;
319
320 ff->effects = kcalloc(max_effects, sizeof(struct ff_effect),
321 GFP_KERNEL);
322 if (!ff->effects) {
323 kfree(ff);
324 return -ENOMEM;
325 }
326
327 ff->max_effects = max_effects;
328 mutex_init(&ff->mutex);
329
330 dev->ff = ff;
331 dev->flush = flush_effects;
332 dev->event = input_ff_event;
333 set_bit(EV_FF, dev->evbit);
334
335 /* Copy "true" bits into ff device bitmap */
336 for (i = 0; i <= FF_MAX; i++)
337 if (test_bit(i, dev->ffbit))
338 set_bit(i, ff->ffbit);
339
340 /* we can emulate RUMBLE with periodic effects */
341 if (test_bit(FF_PERIODIC, ff->ffbit))
342 set_bit(FF_RUMBLE, dev->ffbit);
343
344 return 0;
345}
346EXPORT_SYMBOL_GPL(input_ff_create);
347
348/**
349 * input_ff_free() - frees force feedback portion of input device
350 * @dev: input device supporintg force feedback
351 *
352 * This function is only needed in error path as input core will
353 * automatically free force feedback structures when device is
354 * destroyed.
355 */
356void input_ff_destroy(struct input_dev *dev)
357{
358 clear_bit(EV_FF, dev->evbit);
359 if (dev->ff) {
360 if (dev->ff->destroy)
361 dev->ff->destroy(dev->ff);
362 kfree(dev->ff->private);
363 kfree(dev->ff);
364 dev->ff = NULL;
365 }
366}
367EXPORT_SYMBOL_GPL(input_ff_destroy);
diff --git a/drivers/input/ff-memless.c b/drivers/input/ff-memless.c
new file mode 100644
index 000000000000..cd8b7297e6df
--- /dev/null
+++ b/drivers/input/ff-memless.c
@@ -0,0 +1,515 @@
1/*
2 * Force feedback support for memoryless devices
3 *
4 * Copyright (c) 2006 Anssi Hannula <anssi.hannula@gmail.com>
5 * Copyright (c) 2006 Dmitry Torokhov <dtor@mail.ru>
6 */
7
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24/* #define DEBUG */
25
26#define debug(format, arg...) pr_debug("ff-memless: " format "\n", ## arg)
27
28#include <linux/input.h>
29#include <linux/module.h>
30#include <linux/mutex.h>
31#include <linux/spinlock.h>
32#include <linux/sched.h>
33
34#include "fixp-arith.h"
35
36MODULE_LICENSE("GPL");
37MODULE_AUTHOR("Anssi Hannula <anssi.hannula@gmail.com>");
38MODULE_DESCRIPTION("Force feedback support for memoryless devices");
39
40/* Number of effects handled with memoryless devices */
41#define FF_MEMLESS_EFFECTS 16
42
43/* Envelope update interval in ms */
44#define FF_ENVELOPE_INTERVAL 50
45
46#define FF_EFFECT_STARTED 0
47#define FF_EFFECT_PLAYING 1
48#define FF_EFFECT_ABORTING 2
49
50struct ml_effect_state {
51 struct ff_effect *effect;
52 unsigned long flags; /* effect state (STARTED, PLAYING, etc) */
53 int count; /* loop count of the effect */
54 unsigned long play_at; /* start time */
55 unsigned long stop_at; /* stop time */
56 unsigned long adj_at; /* last time the effect was sent */
57};
58
59struct ml_device {
60 void *private;
61 struct ml_effect_state states[FF_MEMLESS_EFFECTS];
62 int gain;
63 struct timer_list timer;
64 spinlock_t timer_lock;
65 struct input_dev *dev;
66
67 int (*play_effect)(struct input_dev *dev, void *data,
68 struct ff_effect *effect);
69};
70
71static const struct ff_envelope *get_envelope(const struct ff_effect *effect)
72{
73 static const struct ff_envelope empty_envelope;
74
75 switch (effect->type) {
76 case FF_PERIODIC:
77 return &effect->u.periodic.envelope;
78 case FF_CONSTANT:
79 return &effect->u.constant.envelope;
80 default:
81 return &empty_envelope;
82 }
83}
84
85/*
86 * Check for the next time envelope requires an update on memoryless devices
87 */
88static unsigned long calculate_next_time(struct ml_effect_state *state)
89{
90 const struct ff_envelope *envelope = get_envelope(state->effect);
91 unsigned long attack_stop, fade_start, next_fade;
92
93 if (envelope->attack_length) {
94 attack_stop = state->play_at +
95 msecs_to_jiffies(envelope->attack_length);
96 if (time_before(state->adj_at, attack_stop))
97 return state->adj_at +
98 msecs_to_jiffies(FF_ENVELOPE_INTERVAL);
99 }
100
101 if (state->effect->replay.length) {
102 if (envelope->fade_length) {
103 /* check when fading should start */
104 fade_start = state->stop_at -
105 msecs_to_jiffies(envelope->fade_length);
106
107 if (time_before(state->adj_at, fade_start))
108 return fade_start;
109
110 /* already fading, advance to next checkpoint */
111 next_fade = state->adj_at +
112 msecs_to_jiffies(FF_ENVELOPE_INTERVAL);
113 if (time_before(next_fade, state->stop_at))
114 return next_fade;
115 }
116
117 return state->stop_at;
118 }
119
120 return state->play_at;
121}
122
123static void ml_schedule_timer(struct ml_device *ml)
124{
125 struct ml_effect_state *state;
126 unsigned long now = jiffies;
127 unsigned long earliest = 0;
128 unsigned long next_at;
129 int events = 0;
130 int i;
131
132 debug("calculating next timer");
133
134 for (i = 0; i < FF_MEMLESS_EFFECTS; i++) {
135
136 state = &ml->states[i];
137
138 if (!test_bit(FF_EFFECT_STARTED, &state->flags))
139 continue;
140
141 if (test_bit(FF_EFFECT_PLAYING, &state->flags))
142 next_at = calculate_next_time(state);
143 else
144 next_at = state->play_at;
145
146 if (time_before_eq(now, next_at) &&
147 (++events == 1 || time_before(next_at, earliest)))
148 earliest = next_at;
149 }
150
151 if (!events) {
152 debug("no actions");
153 del_timer(&ml->timer);
154 } else {
155 debug("timer set");
156 mod_timer(&ml->timer, earliest);
157 }
158}
159
160/*
161 * Apply an envelope to a value
162 */
163static int apply_envelope(struct ml_effect_state *state, int value,
164 struct ff_envelope *envelope)
165{
166 struct ff_effect *effect = state->effect;
167 unsigned long now = jiffies;
168 int time_from_level;
169 int time_of_envelope;
170 int envelope_level;
171 int difference;
172
173 if (envelope->attack_length &&
174 time_before(now,
175 state->play_at + msecs_to_jiffies(envelope->attack_length))) {
176 debug("value = 0x%x, attack_level = 0x%x", value,
177 envelope->attack_level);
178 time_from_level = jiffies_to_msecs(now - state->play_at);
179 time_of_envelope = envelope->attack_length;
180 envelope_level = min_t(__s16, envelope->attack_level, 0x7fff);
181
182 } else if (envelope->fade_length && effect->replay.length &&
183 time_after(now,
184 state->stop_at - msecs_to_jiffies(envelope->fade_length)) &&
185 time_before(now, state->stop_at)) {
186 time_from_level = jiffies_to_msecs(state->stop_at - now);
187 time_of_envelope = envelope->fade_length;
188 envelope_level = min_t(__s16, envelope->fade_level, 0x7fff);
189 } else
190 return value;
191
192 difference = abs(value) - envelope_level;
193
194 debug("difference = %d", difference);
195 debug("time_from_level = 0x%x", time_from_level);
196 debug("time_of_envelope = 0x%x", time_of_envelope);
197
198 difference = difference * time_from_level / time_of_envelope;
199
200 debug("difference = %d", difference);
201
202 return value < 0 ?
203 -(difference + envelope_level) : (difference + envelope_level);
204}
205
206/*
207 * Return the type the effect has to be converted into (memless devices)
208 */
209static int get_compatible_type(struct ff_device *ff, int effect_type)
210{
211
212 if (test_bit(effect_type, ff->ffbit))
213 return effect_type;
214
215 if (effect_type == FF_PERIODIC && test_bit(FF_RUMBLE, ff->ffbit))
216 return FF_RUMBLE;
217
218 printk(KERN_ERR
219 "ff-memless: invalid type in get_compatible_type()\n");
220
221 return 0;
222}
223
224/*
225 * Combine two effects and apply gain.
226 */
227static void ml_combine_effects(struct ff_effect *effect,
228 struct ml_effect_state *state,
229 int gain)
230{
231 struct ff_effect *new = state->effect;
232 unsigned int strong, weak, i;
233 int x, y;
234 fixp_t level;
235
236 switch (new->type) {
237 case FF_CONSTANT:
238 i = new->direction * 360 / 0xffff;
239 level = fixp_new16(apply_envelope(state,
240 new->u.constant.level,
241 &new->u.constant.envelope));
242 x = fixp_mult(fixp_sin(i), level) * gain / 0xffff;
243 y = fixp_mult(-fixp_cos(i), level) * gain / 0xffff;
244 /*
245 * here we abuse ff_ramp to hold x and y of constant force
246 * If in future any driver wants something else than x and y
247 * in s8, this should be changed to something more generic
248 */
249 effect->u.ramp.start_level =
250 max(min(effect->u.ramp.start_level + x, 0x7f), -0x80);
251 effect->u.ramp.end_level =
252 max(min(effect->u.ramp.end_level + y, 0x7f), -0x80);
253 break;
254
255 case FF_RUMBLE:
256 strong = new->u.rumble.strong_magnitude * gain / 0xffff;
257 weak = new->u.rumble.weak_magnitude * gain / 0xffff;
258 effect->u.rumble.strong_magnitude =
259 min(strong + effect->u.rumble.strong_magnitude,
260 0xffffU);
261 effect->u.rumble.weak_magnitude =
262 min(weak + effect->u.rumble.weak_magnitude, 0xffffU);
263 break;
264
265 case FF_PERIODIC:
266 i = apply_envelope(state, abs(new->u.periodic.magnitude),
267 &new->u.periodic.envelope);
268
269 /* here we also scale it 0x7fff => 0xffff */
270 i = i * gain / 0x7fff;
271
272 effect->u.rumble.strong_magnitude =
273 min(i + effect->u.rumble.strong_magnitude, 0xffffU);
274 effect->u.rumble.weak_magnitude =
275 min(i + effect->u.rumble.weak_magnitude, 0xffffU);
276 break;
277
278 default:
279 printk(KERN_ERR "ff-memless: invalid type in ml_combine_effects()\n");
280 break;
281 }
282
283}
284
285
286/*
287 * Because memoryless devices have only one effect per effect type active
288 * at one time we have to combine multiple effects into one
289 */
290static int ml_get_combo_effect(struct ml_device *ml,
291 unsigned long *effect_handled,
292 struct ff_effect *combo_effect)
293{
294 struct ff_effect *effect;
295 struct ml_effect_state *state;
296 int effect_type;
297 int i;
298
299 memset(combo_effect, 0, sizeof(struct ff_effect));
300
301 for (i = 0; i < FF_MEMLESS_EFFECTS; i++) {
302 if (__test_and_set_bit(i, effect_handled))
303 continue;
304
305 state = &ml->states[i];
306 effect = state->effect;
307
308 if (!test_bit(FF_EFFECT_STARTED, &state->flags))
309 continue;
310
311 if (time_before(jiffies, state->play_at))
312 continue;
313
314 /*
315 * here we have started effects that are either
316 * currently playing (and may need be aborted)
317 * or need to start playing.
318 */
319 effect_type = get_compatible_type(ml->dev->ff, effect->type);
320 if (combo_effect->type != effect_type) {
321 if (combo_effect->type != 0) {
322 __clear_bit(i, effect_handled);
323 continue;
324 }
325 combo_effect->type = effect_type;
326 }
327
328 if (__test_and_clear_bit(FF_EFFECT_ABORTING, &state->flags)) {
329 __clear_bit(FF_EFFECT_PLAYING, &state->flags);
330 __clear_bit(FF_EFFECT_STARTED, &state->flags);
331 } else if (effect->replay.length &&
332 time_after_eq(jiffies, state->stop_at)) {
333
334 __clear_bit(FF_EFFECT_PLAYING, &state->flags);
335
336 if (--state->count <= 0) {
337 __clear_bit(FF_EFFECT_STARTED, &state->flags);
338 } else {
339 state->play_at = jiffies +
340 msecs_to_jiffies(effect->replay.delay);
341 state->stop_at = state->play_at +
342 msecs_to_jiffies(effect->replay.length);
343 }
344 } else {
345 __set_bit(FF_EFFECT_PLAYING, &state->flags);
346 state->adj_at = jiffies;
347 ml_combine_effects(combo_effect, state, ml->gain);
348 }
349 }
350
351 return combo_effect->type != 0;
352}
353
354static void ml_play_effects(struct ml_device *ml)
355{
356 struct ff_effect effect;
357 DECLARE_BITMAP(handled_bm, FF_MEMLESS_EFFECTS);
358
359 memset(handled_bm, 0, sizeof(handled_bm));
360
361 while (ml_get_combo_effect(ml, handled_bm, &effect))
362 ml->play_effect(ml->dev, ml->private, &effect);
363
364 ml_schedule_timer(ml);
365}
366
367static void ml_effect_timer(unsigned long timer_data)
368{
369 struct input_dev *dev = (struct input_dev *)timer_data;
370 struct ml_device *ml = dev->ff->private;
371
372 debug("timer: updating effects");
373
374 spin_lock(&ml->timer_lock);
375 ml_play_effects(ml);
376 spin_unlock(&ml->timer_lock);
377}
378
379static void ml_ff_set_gain(struct input_dev *dev, u16 gain)
380{
381 struct ml_device *ml = dev->ff->private;
382 int i;
383
384 spin_lock_bh(&ml->timer_lock);
385
386 ml->gain = gain;
387
388 for (i = 0; i < FF_MEMLESS_EFFECTS; i++)
389 __clear_bit(FF_EFFECT_PLAYING, &ml->states[i].flags);
390
391 ml_play_effects(ml);
392
393 spin_unlock_bh(&ml->timer_lock);
394}
395
396static int ml_ff_playback(struct input_dev *dev, int effect_id, int value)
397{
398 struct ml_device *ml = dev->ff->private;
399 struct ml_effect_state *state = &ml->states[effect_id];
400
401 spin_lock_bh(&ml->timer_lock);
402
403 if (value > 0) {
404 debug("initiated play");
405
406 __set_bit(FF_EFFECT_STARTED, &state->flags);
407 state->count = value;
408 state->play_at = jiffies +
409 msecs_to_jiffies(state->effect->replay.delay);
410 state->stop_at = state->play_at +
411 msecs_to_jiffies(state->effect->replay.length);
412 state->adj_at = state->play_at;
413
414 ml_schedule_timer(ml);
415
416 } else {
417 debug("initiated stop");
418
419 if (test_bit(FF_EFFECT_PLAYING, &state->flags))
420 __set_bit(FF_EFFECT_ABORTING, &state->flags);
421 else
422 __clear_bit(FF_EFFECT_STARTED, &state->flags);
423
424 ml_play_effects(ml);
425 }
426
427 spin_unlock_bh(&ml->timer_lock);
428
429 return 0;
430}
431
432static int ml_ff_upload(struct input_dev *dev,
433 struct ff_effect *effect, struct ff_effect *old)
434{
435 struct ml_device *ml = dev->ff->private;
436 struct ml_effect_state *state = &ml->states[effect->id];
437
438 spin_lock_bh(&ml->timer_lock);
439
440 if (test_bit(FF_EFFECT_STARTED, &state->flags)) {
441 __clear_bit(FF_EFFECT_PLAYING, &state->flags);
442 state->play_at = jiffies +
443 msecs_to_jiffies(state->effect->replay.delay);
444 state->stop_at = state->play_at +
445 msecs_to_jiffies(state->effect->replay.length);
446 state->adj_at = state->play_at;
447 ml_schedule_timer(ml);
448 }
449
450 spin_unlock_bh(&ml->timer_lock);
451
452 return 0;
453}
454
455static void ml_ff_destroy(struct ff_device *ff)
456{
457 struct ml_device *ml = ff->private;
458
459 kfree(ml->private);
460}
461
462/**
463 * input_ff_create_memless() - create memoryless FF device
464 * @dev: input device supporting force-feedback
465 * @data: driver-specific data to be passed into @play_effect
466 * @play_effect: driver-specific method for playing FF effect
467 */
468int input_ff_create_memless(struct input_dev *dev, void *data,
469 int (*play_effect)(struct input_dev *, void *, struct ff_effect *))
470{
471 struct ml_device *ml;
472 struct ff_device *ff;
473 int error;
474 int i;
475
476 ml = kzalloc(sizeof(struct ml_device), GFP_KERNEL);
477 if (!ml)
478 return -ENOMEM;
479
480 ml->dev = dev;
481 ml->private = data;
482 ml->play_effect = play_effect;
483 ml->gain = 0xffff;
484 spin_lock_init(&ml->timer_lock);
485 setup_timer(&ml->timer, ml_effect_timer, (unsigned long)dev);
486
487 set_bit(FF_GAIN, dev->ffbit);
488
489 error = input_ff_create(dev, FF_MEMLESS_EFFECTS);
490 if (error) {
491 kfree(ml);
492 return error;
493 }
494
495 ff = dev->ff;
496 ff->private = ml;
497 ff->upload = ml_ff_upload;
498 ff->playback = ml_ff_playback;
499 ff->set_gain = ml_ff_set_gain;
500 ff->destroy = ml_ff_destroy;
501
502 /* we can emulate periodic effects with RUMBLE */
503 if (test_bit(FF_RUMBLE, ff->ffbit)) {
504 set_bit(FF_PERIODIC, dev->ffbit);
505 set_bit(FF_SINE, dev->ffbit);
506 set_bit(FF_TRIANGLE, dev->ffbit);
507 set_bit(FF_SQUARE, dev->ffbit);
508 }
509
510 for (i = 0; i < FF_MEMLESS_EFFECTS; i++)
511 ml->states[i].effect = &ff->effects[i];
512
513 return 0;
514}
515EXPORT_SYMBOL_GPL(input_ff_create_memless);
diff --git a/drivers/usb/input/fixp-arith.h b/drivers/input/fixp-arith.h
index ed3d2da0c485..ed3d2da0c485 100644
--- a/drivers/usb/input/fixp-arith.h
+++ b/drivers/input/fixp-arith.h
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 9cb4b9a54f01..1c8c8a5bc4a9 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -176,6 +176,10 @@ void input_event(struct input_dev *dev, unsigned int type, unsigned int code, in
176 break; 176 break;
177 177
178 case EV_FF: 178 case EV_FF:
179
180 if (value < 0)
181 return;
182
179 if (dev->event) 183 if (dev->event)
180 dev->event(dev, type, code, value); 184 dev->event(dev, type, code, value);
181 break; 185 break;
@@ -309,7 +313,8 @@ static void input_link_handle(struct input_handle *handle)
309 if (i != NBITS(max)) \ 313 if (i != NBITS(max)) \
310 continue; 314 continue;
311 315
312static struct input_device_id *input_match_device(struct input_device_id *id, struct input_dev *dev) 316static const struct input_device_id *input_match_device(const struct input_device_id *id,
317 struct input_dev *dev)
313{ 318{
314 int i; 319 int i;
315 320
@@ -762,7 +767,9 @@ static void input_dev_release(struct class_device *class_dev)
762{ 767{
763 struct input_dev *dev = to_input_dev(class_dev); 768 struct input_dev *dev = to_input_dev(class_dev);
764 769
770 input_ff_destroy(dev);
765 kfree(dev); 771 kfree(dev);
772
766 module_put(THIS_MODULE); 773 module_put(THIS_MODULE);
767} 774}
768 775
@@ -899,12 +906,13 @@ struct input_dev *input_allocate_device(void)
899 906
900 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL); 907 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
901 if (dev) { 908 if (dev) {
902 dev->dynalloc = 1;
903 dev->cdev.class = &input_class; 909 dev->cdev.class = &input_class;
904 class_device_initialize(&dev->cdev); 910 class_device_initialize(&dev->cdev);
905 mutex_init(&dev->mutex); 911 mutex_init(&dev->mutex);
906 INIT_LIST_HEAD(&dev->h_list); 912 INIT_LIST_HEAD(&dev->h_list);
907 INIT_LIST_HEAD(&dev->node); 913 INIT_LIST_HEAD(&dev->node);
914
915 __module_get(THIS_MODULE);
908 } 916 }
909 917
910 return dev; 918 return dev;
@@ -929,17 +937,10 @@ int input_register_device(struct input_dev *dev)
929 static atomic_t input_no = ATOMIC_INIT(0); 937 static atomic_t input_no = ATOMIC_INIT(0);
930 struct input_handle *handle; 938 struct input_handle *handle;
931 struct input_handler *handler; 939 struct input_handler *handler;
932 struct input_device_id *id; 940 const struct input_device_id *id;
933 const char *path; 941 const char *path;
934 int error; 942 int error;
935 943
936 if (!dev->dynalloc) {
937 printk(KERN_WARNING "input: device %s is statically allocated, will not register\n"
938 "Please convert to input_allocate_device() or contact dtor_core@ameritech.net\n",
939 dev->name ? dev->name : "<Unknown>");
940 return -EINVAL;
941 }
942
943 set_bit(EV_SYN, dev->evbit); 944 set_bit(EV_SYN, dev->evbit);
944 945
945 /* 946 /*
@@ -955,10 +956,8 @@ int input_register_device(struct input_dev *dev)
955 dev->rep[REP_PERIOD] = 33; 956 dev->rep[REP_PERIOD] = 33;
956 } 957 }
957 958
958 INIT_LIST_HEAD(&dev->h_list);
959 list_add_tail(&dev->node, &input_dev_list); 959 list_add_tail(&dev->node, &input_dev_list);
960 960
961 dev->cdev.class = &input_class;
962 snprintf(dev->cdev.class_id, sizeof(dev->cdev.class_id), 961 snprintf(dev->cdev.class_id, sizeof(dev->cdev.class_id),
963 "input%ld", (unsigned long) atomic_inc_return(&input_no) - 1); 962 "input%ld", (unsigned long) atomic_inc_return(&input_no) - 1);
964 963
@@ -978,8 +977,6 @@ int input_register_device(struct input_dev *dev)
978 if (error) 977 if (error)
979 goto fail3; 978 goto fail3;
980 979
981 __module_get(THIS_MODULE);
982
983 path = kobject_get_path(&dev->cdev.kobj, GFP_KERNEL); 980 path = kobject_get_path(&dev->cdev.kobj, GFP_KERNEL);
984 printk(KERN_INFO "input: %s as %s\n", 981 printk(KERN_INFO "input: %s as %s\n",
985 dev->name ? dev->name : "Unspecified device", path ? path : "N/A"); 982 dev->name ? dev->name : "Unspecified device", path ? path : "N/A");
@@ -1008,9 +1005,12 @@ EXPORT_SYMBOL(input_register_device);
1008void input_unregister_device(struct input_dev *dev) 1005void input_unregister_device(struct input_dev *dev)
1009{ 1006{
1010 struct list_head *node, *next; 1007 struct list_head *node, *next;
1008 int code;
1011 1009
1012 if (!dev) 1010 for (code = 0; code <= KEY_MAX; code++)
1013 return; 1011 if (test_bit(code, dev->key))
1012 input_report_key(dev, code, 0);
1013 input_sync(dev);
1014 1014
1015 del_timer_sync(&dev->timer); 1015 del_timer_sync(&dev->timer);
1016 1016
@@ -1037,19 +1037,20 @@ void input_unregister_device(struct input_dev *dev)
1037} 1037}
1038EXPORT_SYMBOL(input_unregister_device); 1038EXPORT_SYMBOL(input_unregister_device);
1039 1039
1040void input_register_handler(struct input_handler *handler) 1040int input_register_handler(struct input_handler *handler)
1041{ 1041{
1042 struct input_dev *dev; 1042 struct input_dev *dev;
1043 struct input_handle *handle; 1043 struct input_handle *handle;
1044 struct input_device_id *id; 1044 const struct input_device_id *id;
1045
1046 if (!handler)
1047 return;
1048 1045
1049 INIT_LIST_HEAD(&handler->h_list); 1046 INIT_LIST_HEAD(&handler->h_list);
1050 1047
1051 if (handler->fops != NULL) 1048 if (handler->fops != NULL) {
1049 if (input_table[handler->minor >> 5])
1050 return -EBUSY;
1051
1052 input_table[handler->minor >> 5] = handler; 1052 input_table[handler->minor >> 5] = handler;
1053 }
1053 1054
1054 list_add_tail(&handler->node, &input_handler_list); 1055 list_add_tail(&handler->node, &input_handler_list);
1055 1056
@@ -1063,6 +1064,7 @@ void input_register_handler(struct input_handler *handler)
1063 } 1064 }
1064 1065
1065 input_wakeup_procfs_readers(); 1066 input_wakeup_procfs_readers();
1067 return 0;
1066} 1068}
1067EXPORT_SYMBOL(input_register_handler); 1069EXPORT_SYMBOL(input_register_handler);
1068 1070
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index d67157513bf7..9f3529ad3fda 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -451,7 +451,7 @@ static int joydev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
451 } 451 }
452} 452}
453 453
454static struct file_operations joydev_fops = { 454static const struct file_operations joydev_fops = {
455 .owner = THIS_MODULE, 455 .owner = THIS_MODULE,
456 .read = joydev_read, 456 .read = joydev_read,
457 .write = joydev_write, 457 .write = joydev_write,
@@ -465,7 +465,8 @@ static struct file_operations joydev_fops = {
465 .fasync = joydev_fasync, 465 .fasync = joydev_fasync,
466}; 466};
467 467
468static struct input_handle *joydev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id) 468static struct input_handle *joydev_connect(struct input_handler *handler, struct input_dev *dev,
469 const struct input_device_id *id)
469{ 470{
470 struct joydev *joydev; 471 struct joydev *joydev;
471 struct class_device *cdev; 472 struct class_device *cdev;
@@ -562,7 +563,7 @@ static void joydev_disconnect(struct input_handle *handle)
562 joydev_free(joydev); 563 joydev_free(joydev);
563} 564}
564 565
565static struct input_device_id joydev_blacklist[] = { 566static const struct input_device_id joydev_blacklist[] = {
566 { 567 {
567 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT, 568 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT,
568 .evbit = { BIT(EV_KEY) }, 569 .evbit = { BIT(EV_KEY) },
@@ -571,7 +572,7 @@ static struct input_device_id joydev_blacklist[] = {
571 { } /* Terminating entry */ 572 { } /* Terminating entry */
572}; 573};
573 574
574static struct input_device_id joydev_ids[] = { 575static const struct input_device_id joydev_ids[] = {
575 { 576 {
576 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT, 577 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT,
577 .evbit = { BIT(EV_ABS) }, 578 .evbit = { BIT(EV_ABS) },
@@ -605,8 +606,7 @@ static struct input_handler joydev_handler = {
605 606
606static int __init joydev_init(void) 607static int __init joydev_init(void)
607{ 608{
608 input_register_handler(&joydev_handler); 609 return input_register_handler(&joydev_handler);
609 return 0;
610} 610}
611 611
612static void __exit joydev_exit(void) 612static void __exit joydev_exit(void)
diff --git a/drivers/input/joystick/iforce/iforce-ff.c b/drivers/input/joystick/iforce/iforce-ff.c
index 50c90765aee1..8fb0c19cc60e 100644
--- a/drivers/input/joystick/iforce/iforce-ff.c
+++ b/drivers/input/joystick/iforce/iforce-ff.c
@@ -165,19 +165,19 @@ static int make_condition_modifier(struct iforce* iforce,
165 data[0] = LO(mod_chunk->start); 165 data[0] = LO(mod_chunk->start);
166 data[1] = HI(mod_chunk->start); 166 data[1] = HI(mod_chunk->start);
167 167
168 data[2] = (100*rk)>>15; /* Dangerous: the sign is extended by gcc on plateforms providing an arith shift */ 168 data[2] = (100 * rk) >> 15; /* Dangerous: the sign is extended by gcc on plateforms providing an arith shift */
169 data[3] = (100*lk)>>15; /* This code is incorrect on cpus lacking arith shift */ 169 data[3] = (100 * lk) >> 15; /* This code is incorrect on cpus lacking arith shift */
170 170
171 center = (500*center)>>15; 171 center = (500 * center) >> 15;
172 data[4] = LO(center); 172 data[4] = LO(center);
173 data[5] = HI(center); 173 data[5] = HI(center);
174 174
175 db = (1000*db)>>16; 175 db = (1000 * db) >> 16;
176 data[6] = LO(db); 176 data[6] = LO(db);
177 data[7] = HI(db); 177 data[7] = HI(db);
178 178
179 data[8] = (100*rsat)>>16; 179 data[8] = (100 * rsat) >> 16;
180 data[9] = (100*lsat)>>16; 180 data[9] = (100 * lsat) >> 16;
181 181
182 iforce_send_packet(iforce, FF_CMD_CONDITION, data); 182 iforce_send_packet(iforce, FF_CMD_CONDITION, data);
183 iforce_dump_packet("condition", FF_CMD_CONDITION, data); 183 iforce_dump_packet("condition", FF_CMD_CONDITION, data);
@@ -188,6 +188,7 @@ static int make_condition_modifier(struct iforce* iforce,
188static unsigned char find_button(struct iforce *iforce, signed short button) 188static unsigned char find_button(struct iforce *iforce, signed short button)
189{ 189{
190 int i; 190 int i;
191
191 for (i = 1; iforce->type->btn[i] >= 0; i++) 192 for (i = 1; iforce->type->btn[i] >= 0; i++)
192 if (iforce->type->btn[i] == button) 193 if (iforce->type->btn[i] == button)
193 return i + 1; 194 return i + 1;
@@ -198,19 +199,17 @@ static unsigned char find_button(struct iforce *iforce, signed short button)
198 * Analyse the changes in an effect, and tell if we need to send an condition 199 * Analyse the changes in an effect, and tell if we need to send an condition
199 * parameter packet 200 * parameter packet
200 */ 201 */
201static int need_condition_modifier(struct iforce* iforce, struct ff_effect* new) 202static int need_condition_modifier(struct ff_effect *old, struct ff_effect *new)
202{ 203{
203 int id = new->id; 204 int ret = 0;
204 struct ff_effect* old = &iforce->core_effects[id].effect;
205 int ret=0;
206 int i; 205 int i;
207 206
208 if (new->type != FF_SPRING && new->type != FF_FRICTION) { 207 if (new->type != FF_SPRING && new->type != FF_FRICTION) {
209 printk(KERN_WARNING "iforce.c: bad effect type in need_condition_modifier\n"); 208 printk(KERN_WARNING "iforce.c: bad effect type in need_condition_modifier\n");
210 return FALSE; 209 return 0;
211 } 210 }
212 211
213 for(i=0; i<2; i++) { 212 for (i = 0; i < 2; i++) {
214 ret |= old->u.condition[i].right_saturation != new->u.condition[i].right_saturation 213 ret |= old->u.condition[i].right_saturation != new->u.condition[i].right_saturation
215 || old->u.condition[i].left_saturation != new->u.condition[i].left_saturation 214 || old->u.condition[i].left_saturation != new->u.condition[i].left_saturation
216 || old->u.condition[i].right_coeff != new->u.condition[i].right_coeff 215 || old->u.condition[i].right_coeff != new->u.condition[i].right_coeff
@@ -225,35 +224,29 @@ static int need_condition_modifier(struct iforce* iforce, struct ff_effect* new)
225 * Analyse the changes in an effect, and tell if we need to send a magnitude 224 * Analyse the changes in an effect, and tell if we need to send a magnitude
226 * parameter packet 225 * parameter packet
227 */ 226 */
228static int need_magnitude_modifier(struct iforce* iforce, struct ff_effect* effect) 227static int need_magnitude_modifier(struct ff_effect *old, struct ff_effect *effect)
229{ 228{
230 int id = effect->id;
231 struct ff_effect* old = &iforce->core_effects[id].effect;
232
233 if (effect->type != FF_CONSTANT) { 229 if (effect->type != FF_CONSTANT) {
234 printk(KERN_WARNING "iforce.c: bad effect type in need_envelope_modifier\n"); 230 printk(KERN_WARNING "iforce.c: bad effect type in need_envelope_modifier\n");
235 return FALSE; 231 return 0;
236 } 232 }
237 233
238 return (old->u.constant.level != effect->u.constant.level); 234 return old->u.constant.level != effect->u.constant.level;
239} 235}
240 236
241/* 237/*
242 * Analyse the changes in an effect, and tell if we need to send an envelope 238 * Analyse the changes in an effect, and tell if we need to send an envelope
243 * parameter packet 239 * parameter packet
244 */ 240 */
245static int need_envelope_modifier(struct iforce* iforce, struct ff_effect* effect) 241static int need_envelope_modifier(struct ff_effect *old, struct ff_effect *effect)
246{ 242{
247 int id = effect->id;
248 struct ff_effect* old = &iforce->core_effects[id].effect;
249
250 switch (effect->type) { 243 switch (effect->type) {
251 case FF_CONSTANT: 244 case FF_CONSTANT:
252 if (old->u.constant.envelope.attack_length != effect->u.constant.envelope.attack_length 245 if (old->u.constant.envelope.attack_length != effect->u.constant.envelope.attack_length
253 || old->u.constant.envelope.attack_level != effect->u.constant.envelope.attack_level 246 || old->u.constant.envelope.attack_level != effect->u.constant.envelope.attack_level
254 || old->u.constant.envelope.fade_length != effect->u.constant.envelope.fade_length 247 || old->u.constant.envelope.fade_length != effect->u.constant.envelope.fade_length
255 || old->u.constant.envelope.fade_level != effect->u.constant.envelope.fade_level) 248 || old->u.constant.envelope.fade_level != effect->u.constant.envelope.fade_level)
256 return TRUE; 249 return 1;
257 break; 250 break;
258 251
259 case FF_PERIODIC: 252 case FF_PERIODIC:
@@ -261,30 +254,26 @@ static int need_envelope_modifier(struct iforce* iforce, struct ff_effect* effec
261 || old->u.periodic.envelope.attack_level != effect->u.periodic.envelope.attack_level 254 || old->u.periodic.envelope.attack_level != effect->u.periodic.envelope.attack_level
262 || old->u.periodic.envelope.fade_length != effect->u.periodic.envelope.fade_length 255 || old->u.periodic.envelope.fade_length != effect->u.periodic.envelope.fade_length
263 || old->u.periodic.envelope.fade_level != effect->u.periodic.envelope.fade_level) 256 || old->u.periodic.envelope.fade_level != effect->u.periodic.envelope.fade_level)
264 return TRUE; 257 return 1;
265 break; 258 break;
266 259
267 default: 260 default:
268 printk(KERN_WARNING "iforce.c: bad effect type in need_envelope_modifier\n"); 261 printk(KERN_WARNING "iforce.c: bad effect type in need_envelope_modifier\n");
269 } 262 }
270 263
271 return FALSE; 264 return 0;
272} 265}
273 266
274/* 267/*
275 * Analyse the changes in an effect, and tell if we need to send a periodic 268 * Analyse the changes in an effect, and tell if we need to send a periodic
276 * parameter effect 269 * parameter effect
277 */ 270 */
278static int need_period_modifier(struct iforce* iforce, struct ff_effect* new) 271static int need_period_modifier(struct ff_effect *old, struct ff_effect *new)
279{ 272{
280 int id = new->id;
281 struct ff_effect* old = &iforce->core_effects[id].effect;
282
283 if (new->type != FF_PERIODIC) { 273 if (new->type != FF_PERIODIC) {
284 printk(KERN_WARNING "iforce.c: bad effect type in need_periodic_modifier\n"); 274 printk(KERN_WARNING "iforce.c: bad effect type in need_period_modifier\n");
285 return FALSE; 275 return 0;
286 } 276 }
287
288 return (old->u.periodic.period != new->u.periodic.period 277 return (old->u.periodic.period != new->u.periodic.period
289 || old->u.periodic.magnitude != new->u.periodic.magnitude 278 || old->u.periodic.magnitude != new->u.periodic.magnitude
290 || old->u.periodic.offset != new->u.periodic.offset 279 || old->u.periodic.offset != new->u.periodic.offset
@@ -295,19 +284,16 @@ static int need_period_modifier(struct iforce* iforce, struct ff_effect* new)
295 * Analyse the changes in an effect, and tell if we need to send an effect 284 * Analyse the changes in an effect, and tell if we need to send an effect
296 * packet 285 * packet
297 */ 286 */
298static int need_core(struct iforce* iforce, struct ff_effect* new) 287static int need_core(struct ff_effect *old, struct ff_effect *new)
299{ 288{
300 int id = new->id;
301 struct ff_effect* old = &iforce->core_effects[id].effect;
302
303 if (old->direction != new->direction 289 if (old->direction != new->direction
304 || old->trigger.button != new->trigger.button 290 || old->trigger.button != new->trigger.button
305 || old->trigger.interval != new->trigger.interval 291 || old->trigger.interval != new->trigger.interval
306 || old->replay.length != new->replay.length 292 || old->replay.length != new->replay.length
307 || old->replay.delay != new->replay.delay) 293 || old->replay.delay != new->replay.delay)
308 return TRUE; 294 return 1;
309 295
310 return FALSE; 296 return 0;
311} 297}
312/* 298/*
313 * Send the part common to all effects to the device 299 * Send the part common to all effects to the device
@@ -360,7 +346,7 @@ static int make_core(struct iforce* iforce, u16 id, u16 mod_id1, u16 mod_id2,
360 * Upload a periodic effect to the device 346 * Upload a periodic effect to the device
361 * See also iforce_upload_constant. 347 * See also iforce_upload_constant.
362 */ 348 */
363int iforce_upload_periodic(struct iforce* iforce, struct ff_effect* effect, int is_update) 349int iforce_upload_periodic(struct iforce *iforce, struct ff_effect *effect, struct ff_effect *old)
364{ 350{
365 u8 wave_code; 351 u8 wave_code;
366 int core_id = effect->id; 352 int core_id = effect->id;
@@ -371,23 +357,25 @@ int iforce_upload_periodic(struct iforce* iforce, struct ff_effect* effect, int
371 int param2_err = 1; 357 int param2_err = 1;
372 int core_err = 0; 358 int core_err = 0;
373 359
374 if (!is_update || need_period_modifier(iforce, effect)) { 360 if (!old || need_period_modifier(old, effect)) {
375 param1_err = make_period_modifier(iforce, mod1_chunk, 361 param1_err = make_period_modifier(iforce, mod1_chunk,
376 is_update, 362 old != NULL,
377 effect->u.periodic.magnitude, effect->u.periodic.offset, 363 effect->u.periodic.magnitude, effect->u.periodic.offset,
378 effect->u.periodic.period, effect->u.periodic.phase); 364 effect->u.periodic.period, effect->u.periodic.phase);
379 if (param1_err) return param1_err; 365 if (param1_err)
366 return param1_err;
380 set_bit(FF_MOD1_IS_USED, core_effect->flags); 367 set_bit(FF_MOD1_IS_USED, core_effect->flags);
381 } 368 }
382 369
383 if (!is_update || need_envelope_modifier(iforce, effect)) { 370 if (!old || need_envelope_modifier(old, effect)) {
384 param2_err = make_envelope_modifier(iforce, mod2_chunk, 371 param2_err = make_envelope_modifier(iforce, mod2_chunk,
385 is_update, 372 old !=NULL,
386 effect->u.periodic.envelope.attack_length, 373 effect->u.periodic.envelope.attack_length,
387 effect->u.periodic.envelope.attack_level, 374 effect->u.periodic.envelope.attack_level,
388 effect->u.periodic.envelope.fade_length, 375 effect->u.periodic.envelope.fade_length,
389 effect->u.periodic.envelope.fade_level); 376 effect->u.periodic.envelope.fade_level);
390 if (param2_err) return param2_err; 377 if (param2_err)
378 return param2_err;
391 set_bit(FF_MOD2_IS_USED, core_effect->flags); 379 set_bit(FF_MOD2_IS_USED, core_effect->flags);
392 } 380 }
393 381
@@ -400,7 +388,7 @@ int iforce_upload_periodic(struct iforce* iforce, struct ff_effect* effect, int
400 default: wave_code = 0x20; break; 388 default: wave_code = 0x20; break;
401 } 389 }
402 390
403 if (!is_update || need_core(iforce, effect)) { 391 if (!old || need_core(old, effect)) {
404 core_err = make_core(iforce, effect->id, 392 core_err = make_core(iforce, effect->id,
405 mod1_chunk->start, 393 mod1_chunk->start,
406 mod2_chunk->start, 394 mod2_chunk->start,
@@ -429,7 +417,7 @@ int iforce_upload_periodic(struct iforce* iforce, struct ff_effect* effect, int
429 * 0 Ok, effect created or updated 417 * 0 Ok, effect created or updated
430 * 1 effect did not change since last upload, and no packet was therefore sent 418 * 1 effect did not change since last upload, and no packet was therefore sent
431 */ 419 */
432int iforce_upload_constant(struct iforce* iforce, struct ff_effect* effect, int is_update) 420int iforce_upload_constant(struct iforce *iforce, struct ff_effect *effect, struct ff_effect *old)
433{ 421{
434 int core_id = effect->id; 422 int core_id = effect->id;
435 struct iforce_core_effect* core_effect = iforce->core_effects + core_id; 423 struct iforce_core_effect* core_effect = iforce->core_effects + core_id;
@@ -439,26 +427,28 @@ int iforce_upload_constant(struct iforce* iforce, struct ff_effect* effect, int
439 int param2_err = 1; 427 int param2_err = 1;
440 int core_err = 0; 428 int core_err = 0;
441 429
442 if (!is_update || need_magnitude_modifier(iforce, effect)) { 430 if (!old || need_magnitude_modifier(old, effect)) {
443 param1_err = make_magnitude_modifier(iforce, mod1_chunk, 431 param1_err = make_magnitude_modifier(iforce, mod1_chunk,
444 is_update, 432 old != NULL,
445 effect->u.constant.level); 433 effect->u.constant.level);
446 if (param1_err) return param1_err; 434 if (param1_err)
435 return param1_err;
447 set_bit(FF_MOD1_IS_USED, core_effect->flags); 436 set_bit(FF_MOD1_IS_USED, core_effect->flags);
448 } 437 }
449 438
450 if (!is_update || need_envelope_modifier(iforce, effect)) { 439 if (!old || need_envelope_modifier(old, effect)) {
451 param2_err = make_envelope_modifier(iforce, mod2_chunk, 440 param2_err = make_envelope_modifier(iforce, mod2_chunk,
452 is_update, 441 old != NULL,
453 effect->u.constant.envelope.attack_length, 442 effect->u.constant.envelope.attack_length,
454 effect->u.constant.envelope.attack_level, 443 effect->u.constant.envelope.attack_level,
455 effect->u.constant.envelope.fade_length, 444 effect->u.constant.envelope.fade_length,
456 effect->u.constant.envelope.fade_level); 445 effect->u.constant.envelope.fade_level);
457 if (param2_err) return param2_err; 446 if (param2_err)
447 return param2_err;
458 set_bit(FF_MOD2_IS_USED, core_effect->flags); 448 set_bit(FF_MOD2_IS_USED, core_effect->flags);
459 } 449 }
460 450
461 if (!is_update || need_core(iforce, effect)) { 451 if (!old || need_core(old, effect)) {
462 core_err = make_core(iforce, effect->id, 452 core_err = make_core(iforce, effect->id,
463 mod1_chunk->start, 453 mod1_chunk->start,
464 mod2_chunk->start, 454 mod2_chunk->start,
@@ -483,7 +473,7 @@ int iforce_upload_constant(struct iforce* iforce, struct ff_effect* effect, int
483/* 473/*
484 * Upload an condition effect. Those are for example friction, inertia, springs... 474 * Upload an condition effect. Those are for example friction, inertia, springs...
485 */ 475 */
486int iforce_upload_condition(struct iforce* iforce, struct ff_effect* effect, int is_update) 476int iforce_upload_condition(struct iforce *iforce, struct ff_effect *effect, struct ff_effect *old)
487{ 477{
488 int core_id = effect->id; 478 int core_id = effect->id;
489 struct iforce_core_effect* core_effect = iforce->core_effects + core_id; 479 struct iforce_core_effect* core_effect = iforce->core_effects + core_id;
@@ -494,37 +484,39 @@ int iforce_upload_condition(struct iforce* iforce, struct ff_effect* effect, int
494 int core_err = 0; 484 int core_err = 0;
495 485
496 switch (effect->type) { 486 switch (effect->type) {
497 case FF_SPRING: type = 0x40; break; 487 case FF_SPRING: type = 0x40; break;
498 case FF_DAMPER: type = 0x41; break; 488 case FF_DAMPER: type = 0x41; break;
499 default: return -1; 489 default: return -1;
500 } 490 }
501 491
502 if (!is_update || need_condition_modifier(iforce, effect)) { 492 if (!old || need_condition_modifier(old, effect)) {
503 param_err = make_condition_modifier(iforce, mod1_chunk, 493 param_err = make_condition_modifier(iforce, mod1_chunk,
504 is_update, 494 old != NULL,
505 effect->u.condition[0].right_saturation, 495 effect->u.condition[0].right_saturation,
506 effect->u.condition[0].left_saturation, 496 effect->u.condition[0].left_saturation,
507 effect->u.condition[0].right_coeff, 497 effect->u.condition[0].right_coeff,
508 effect->u.condition[0].left_coeff, 498 effect->u.condition[0].left_coeff,
509 effect->u.condition[0].deadband, 499 effect->u.condition[0].deadband,
510 effect->u.condition[0].center); 500 effect->u.condition[0].center);
511 if (param_err) return param_err; 501 if (param_err)
502 return param_err;
512 set_bit(FF_MOD1_IS_USED, core_effect->flags); 503 set_bit(FF_MOD1_IS_USED, core_effect->flags);
513 504
514 param_err = make_condition_modifier(iforce, mod2_chunk, 505 param_err = make_condition_modifier(iforce, mod2_chunk,
515 is_update, 506 old != NULL,
516 effect->u.condition[1].right_saturation, 507 effect->u.condition[1].right_saturation,
517 effect->u.condition[1].left_saturation, 508 effect->u.condition[1].left_saturation,
518 effect->u.condition[1].right_coeff, 509 effect->u.condition[1].right_coeff,
519 effect->u.condition[1].left_coeff, 510 effect->u.condition[1].left_coeff,
520 effect->u.condition[1].deadband, 511 effect->u.condition[1].deadband,
521 effect->u.condition[1].center); 512 effect->u.condition[1].center);
522 if (param_err) return param_err; 513 if (param_err)
514 return param_err;
523 set_bit(FF_MOD2_IS_USED, core_effect->flags); 515 set_bit(FF_MOD2_IS_USED, core_effect->flags);
524 516
525 } 517 }
526 518
527 if (!is_update || need_core(iforce, effect)) { 519 if (!old || need_core(old, effect)) {
528 core_err = make_core(iforce, effect->id, 520 core_err = make_core(iforce, effect->id,
529 mod1_chunk->start, mod2_chunk->start, 521 mod1_chunk->start, mod2_chunk->start,
530 type, 0xc0, 522 type, 0xc0,
diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c
index b4914e7231f8..24c684bc6337 100644
--- a/drivers/input/joystick/iforce/iforce-main.c
+++ b/drivers/input/joystick/iforce/iforce-main.c
@@ -83,103 +83,57 @@ static struct iforce_device iforce_device[] = {
83 { 0x0000, 0x0000, "Unknown I-Force Device [%04x:%04x]", btn_joystick, abs_joystick, ff_iforce } 83 { 0x0000, 0x0000, "Unknown I-Force Device [%04x:%04x]", btn_joystick, abs_joystick, ff_iforce }
84}; 84};
85 85
86 86static int iforce_playback(struct input_dev *dev, int effect_id, int value)
87
88static int iforce_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
89{ 87{
90 struct iforce* iforce = dev->private; 88 struct iforce* iforce = dev->private;
91 unsigned char data[3]; 89 struct iforce_core_effect *core_effect = &iforce->core_effects[effect_id];
92
93 if (type != EV_FF)
94 return -1;
95
96 switch (code) {
97
98 case FF_GAIN:
99
100 data[0] = value >> 9;
101 iforce_send_packet(iforce, FF_CMD_GAIN, data);
102
103 return 0;
104
105 case FF_AUTOCENTER:
106 90
107 data[0] = 0x03; 91 if (value > 0)
108 data[1] = value >> 9; 92 set_bit(FF_CORE_SHOULD_PLAY, core_effect->flags);
109 iforce_send_packet(iforce, FF_CMD_AUTOCENTER, data); 93 else
94 clear_bit(FF_CORE_SHOULD_PLAY, core_effect->flags);
110 95
111 data[0] = 0x04; 96 iforce_control_playback(iforce, effect_id, value);
112 data[1] = 0x01; 97 return 0;
113 iforce_send_packet(iforce, FF_CMD_AUTOCENTER, data); 98}
114 99
115 return 0; 100static void iforce_set_gain(struct input_dev *dev, u16 gain)
101{
102 struct iforce* iforce = dev->private;
103 unsigned char data[3];
116 104
117 default: /* Play or stop an effect */ 105 data[0] = gain >> 9;
106 iforce_send_packet(iforce, FF_CMD_GAIN, data);
107}
118 108
119 if (!CHECK_OWNERSHIP(code, iforce)) { 109static void iforce_set_autocenter(struct input_dev *dev, u16 magnitude)
120 return -1; 110{
121 } 111 struct iforce* iforce = dev->private;
122 if (value > 0) { 112 unsigned char data[3];
123 set_bit(FF_CORE_SHOULD_PLAY, iforce->core_effects[code].flags);
124 }
125 else {
126 clear_bit(FF_CORE_SHOULD_PLAY, iforce->core_effects[code].flags);
127 }
128 113
129 iforce_control_playback(iforce, code, value); 114 data[0] = 0x03;
130 return 0; 115 data[1] = magnitude >> 9;
131 } 116 iforce_send_packet(iforce, FF_CMD_AUTOCENTER, data);
132 117
133 return -1; 118 data[0] = 0x04;
119 data[1] = 0x01;
120 iforce_send_packet(iforce, FF_CMD_AUTOCENTER, data);
134} 121}
135 122
136/* 123/*
137 * Function called when an ioctl is performed on the event dev entry. 124 * Function called when an ioctl is performed on the event dev entry.
138 * It uploads an effect to the device 125 * It uploads an effect to the device
139 */ 126 */
140static int iforce_upload_effect(struct input_dev *dev, struct ff_effect *effect) 127static int iforce_upload_effect(struct input_dev *dev, struct ff_effect *effect, struct ff_effect *old)
141{ 128{
142 struct iforce* iforce = dev->private; 129 struct iforce* iforce = dev->private;
143 int id; 130 struct iforce_core_effect *core_effect = &iforce->core_effects[effect->id];
144 int ret; 131 int ret;
145 int is_update;
146
147/* Check this effect type is supported by this device */
148 if (!test_bit(effect->type, iforce->dev->ffbit))
149 return -EINVAL;
150
151/*
152 * If we want to create a new effect, get a free id
153 */
154 if (effect->id == -1) {
155
156 for (id = 0; id < FF_EFFECTS_MAX; ++id)
157 if (!test_and_set_bit(FF_CORE_IS_USED, iforce->core_effects[id].flags))
158 break;
159
160 if (id == FF_EFFECTS_MAX || id >= iforce->dev->ff_effects_max)
161 return -ENOMEM;
162
163 effect->id = id;
164 iforce->core_effects[id].owner = current->pid;
165 iforce->core_effects[id].flags[0] = (1 << FF_CORE_IS_USED); /* Only IS_USED bit must be set */
166
167 is_update = FALSE;
168 }
169 else {
170 /* We want to update an effect */
171 if (!CHECK_OWNERSHIP(effect->id, iforce))
172 return -EACCES;
173
174 /* Parameter type cannot be updated */
175 if (effect->type != iforce->core_effects[effect->id].effect.type)
176 return -EINVAL;
177 132
133 if (__test_and_set_bit(FF_CORE_IS_USED, core_effect->flags)) {
178 /* Check the effect is not already being updated */ 134 /* Check the effect is not already being updated */
179 if (test_bit(FF_CORE_UPDATE, iforce->core_effects[effect->id].flags)) 135 if (test_bit(FF_CORE_UPDATE, core_effect->flags))
180 return -EAGAIN; 136 return -EAGAIN;
181
182 is_update = TRUE;
183 } 137 }
184 138
185/* 139/*
@@ -188,28 +142,28 @@ static int iforce_upload_effect(struct input_dev *dev, struct ff_effect *effect)
188 switch (effect->type) { 142 switch (effect->type) {
189 143
190 case FF_PERIODIC: 144 case FF_PERIODIC:
191 ret = iforce_upload_periodic(iforce, effect, is_update); 145 ret = iforce_upload_periodic(iforce, effect, old);
192 break; 146 break;
193 147
194 case FF_CONSTANT: 148 case FF_CONSTANT:
195 ret = iforce_upload_constant(iforce, effect, is_update); 149 ret = iforce_upload_constant(iforce, effect, old);
196 break; 150 break;
197 151
198 case FF_SPRING: 152 case FF_SPRING:
199 case FF_DAMPER: 153 case FF_DAMPER:
200 ret = iforce_upload_condition(iforce, effect, is_update); 154 ret = iforce_upload_condition(iforce, effect, old);
201 break; 155 break;
202 156
203 default: 157 default:
204 return -EINVAL; 158 return -EINVAL;
205 } 159 }
160
206 if (ret == 0) { 161 if (ret == 0) {
207 /* A packet was sent, forbid new updates until we are notified 162 /* A packet was sent, forbid new updates until we are notified
208 * that the packet was updated 163 * that the packet was updated
209 */ 164 */
210 set_bit(FF_CORE_UPDATE, iforce->core_effects[effect->id].flags); 165 set_bit(FF_CORE_UPDATE, core_effect->flags);
211 } 166 }
212 iforce->core_effects[effect->id].effect = *effect;
213 return ret; 167 return ret;
214} 168}
215 169
@@ -219,20 +173,9 @@ static int iforce_upload_effect(struct input_dev *dev, struct ff_effect *effect)
219 */ 173 */
220static int iforce_erase_effect(struct input_dev *dev, int effect_id) 174static int iforce_erase_effect(struct input_dev *dev, int effect_id)
221{ 175{
222 struct iforce* iforce = dev->private; 176 struct iforce *iforce = dev->private;
177 struct iforce_core_effect *core_effect = &iforce->core_effects[effect_id];
223 int err = 0; 178 int err = 0;
224 struct iforce_core_effect* core_effect;
225
226 if (effect_id < 0 || effect_id >= FF_EFFECTS_MAX)
227 return -EINVAL;
228
229 core_effect = &iforce->core_effects[effect_id];
230
231 /* Check who is trying to erase this effect */
232 if (core_effect->owner != current->pid) {
233 printk(KERN_WARNING "iforce-main.c: %d tried to erase an effect belonging to %d\n", current->pid, core_effect->owner);
234 return -EACCES;
235 }
236 179
237 if (test_bit(FF_MOD1_IS_USED, core_effect->flags)) 180 if (test_bit(FF_MOD1_IS_USED, core_effect->flags))
238 err = release_resource(&core_effect->mod1_chunk); 181 err = release_resource(&core_effect->mod1_chunk);
@@ -240,7 +183,7 @@ static int iforce_erase_effect(struct input_dev *dev, int effect_id)
240 if (!err && test_bit(FF_MOD2_IS_USED, core_effect->flags)) 183 if (!err && test_bit(FF_MOD2_IS_USED, core_effect->flags))
241 err = release_resource(&core_effect->mod2_chunk); 184 err = release_resource(&core_effect->mod2_chunk);
242 185
243 /*TODO: remember to change that if more FF_MOD* bits are added */ 186 /* TODO: remember to change that if more FF_MOD* bits are added */
244 core_effect->flags[0] = 0; 187 core_effect->flags[0] = 0;
245 188
246 return err; 189 return err;
@@ -260,52 +203,31 @@ static int iforce_open(struct input_dev *dev)
260#endif 203#endif
261 } 204 }
262 205
263 /* Enable force feedback */ 206 if (test_bit(EV_FF, dev->evbit)) {
264 iforce_send_packet(iforce, FF_CMD_ENABLE, "\004"); 207 /* Enable force feedback */
208 iforce_send_packet(iforce, FF_CMD_ENABLE, "\004");
209 }
265 210
266 return 0; 211 return 0;
267} 212}
268 213
269static int iforce_flush(struct input_dev *dev, struct file *file) 214static void iforce_release(struct input_dev *dev)
270{ 215{
271 struct iforce *iforce = dev->private; 216 struct iforce *iforce = dev->private;
272 int i; 217 int i;
273 218
274 /* Erase all effects this process owns */ 219 if (test_bit(EV_FF, dev->evbit)) {
275 for (i=0; i<dev->ff_effects_max; ++i) { 220 /* Check: no effects should be present in memory */
276 221 for (i = 0; i < dev->ff->max_effects; i++) {
277 if (test_bit(FF_CORE_IS_USED, iforce->core_effects[i].flags) && 222 if (test_bit(FF_CORE_IS_USED, iforce->core_effects[i].flags)) {
278 current->pid == iforce->core_effects[i].owner) { 223 printk(KERN_WARNING "iforce_release: Device still owns effects\n");
279 224 break;
280 /* Stop effect */
281 input_report_ff(dev, i, 0);
282
283 /* Free ressources assigned to effect */
284 if (iforce_erase_effect(dev, i)) {
285 printk(KERN_WARNING "iforce_flush: erase effect %d failed\n", i);
286 } 225 }
287 } 226 }
288 227
228 /* Disable force feedback playback */
229 iforce_send_packet(iforce, FF_CMD_ENABLE, "\001");
289 } 230 }
290 return 0;
291}
292
293static void iforce_release(struct input_dev *dev)
294{
295 struct iforce *iforce = dev->private;
296 int i;
297
298 /* Check: no effect should be present in memory */
299 for (i=0; i<dev->ff_effects_max; ++i) {
300 if (test_bit(FF_CORE_IS_USED, iforce->core_effects[i].flags))
301 break;
302 }
303 if (i<dev->ff_effects_max) {
304 printk(KERN_WARNING "iforce_release: Device still owns effects\n");
305 }
306
307 /* Disable force feedback playback */
308 iforce_send_packet(iforce, FF_CMD_ENABLE, "\001");
309 231
310 switch (iforce->bus) { 232 switch (iforce->bus) {
311#ifdef CONFIG_JOYSTICK_IFORCE_USB 233#ifdef CONFIG_JOYSTICK_IFORCE_USB
@@ -342,8 +264,10 @@ void iforce_delete_device(struct iforce *iforce)
342int iforce_init_device(struct iforce *iforce) 264int iforce_init_device(struct iforce *iforce)
343{ 265{
344 struct input_dev *input_dev; 266 struct input_dev *input_dev;
267 struct ff_device *ff;
345 unsigned char c[] = "CEOV"; 268 unsigned char c[] = "CEOV";
346 int i; 269 int i, error;
270 int ff_effects = 0;
347 271
348 input_dev = input_allocate_device(); 272 input_dev = input_allocate_device();
349 if (!input_dev) 273 if (!input_dev)
@@ -378,11 +302,6 @@ int iforce_init_device(struct iforce *iforce)
378 input_dev->name = "Unknown I-Force device"; 302 input_dev->name = "Unknown I-Force device";
379 input_dev->open = iforce_open; 303 input_dev->open = iforce_open;
380 input_dev->close = iforce_release; 304 input_dev->close = iforce_release;
381 input_dev->flush = iforce_flush;
382 input_dev->event = iforce_input_event;
383 input_dev->upload_effect = iforce_upload_effect;
384 input_dev->erase_effect = iforce_erase_effect;
385 input_dev->ff_effects_max = 10;
386 305
387/* 306/*
388 * On-device memory allocation. 307 * On-device memory allocation.
@@ -430,15 +349,15 @@ int iforce_init_device(struct iforce *iforce)
430 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet B\n"); 349 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet B\n");
431 350
432 if (!iforce_get_id_packet(iforce, "N")) 351 if (!iforce_get_id_packet(iforce, "N"))
433 iforce->dev->ff_effects_max = iforce->edata[1]; 352 ff_effects = iforce->edata[1];
434 else 353 else
435 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet N\n"); 354 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet N\n");
436 355
437 /* Check if the device can store more effects than the driver can really handle */ 356 /* Check if the device can store more effects than the driver can really handle */
438 if (iforce->dev->ff_effects_max > FF_EFFECTS_MAX) { 357 if (ff_effects > IFORCE_EFFECTS_MAX) {
439 printk(KERN_WARNING "input??: Device can handle %d effects, but N_EFFECTS_MAX is set to %d in iforce.h\n", 358 printk(KERN_WARNING "iforce: Limiting number of effects to %d (device reports %d)\n",
440 iforce->dev->ff_effects_max, FF_EFFECTS_MAX); 359 IFORCE_EFFECTS_MAX, ff_effects);
441 iforce->dev->ff_effects_max = FF_EFFECTS_MAX; 360 ff_effects = IFORCE_EFFECTS_MAX;
442 } 361 }
443 362
444/* 363/*
@@ -472,12 +391,10 @@ int iforce_init_device(struct iforce *iforce)
472 * Set input device bitfields and ranges. 391 * Set input device bitfields and ranges.
473 */ 392 */
474 393
475 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_FF) | BIT(EV_FF_STATUS); 394 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_FF_STATUS);
476 395
477 for (i = 0; iforce->type->btn[i] >= 0; i++) { 396 for (i = 0; iforce->type->btn[i] >= 0; i++)
478 signed short t = iforce->type->btn[i]; 397 set_bit(iforce->type->btn[i], input_dev->keybit);
479 set_bit(t, input_dev->keybit);
480 }
481 set_bit(BTN_DEAD, input_dev->keybit); 398 set_bit(BTN_DEAD, input_dev->keybit);
482 399
483 for (i = 0; iforce->type->abs[i] >= 0; i++) { 400 for (i = 0; iforce->type->abs[i] >= 0; i++) {
@@ -516,9 +433,24 @@ int iforce_init_device(struct iforce *iforce)
516 } 433 }
517 } 434 }
518 435
519 for (i = 0; iforce->type->ff[i] >= 0; i++) 436 if (ff_effects) {
520 set_bit(iforce->type->ff[i], input_dev->ffbit);
521 437
438 for (i = 0; iforce->type->ff[i] >= 0; i++)
439 set_bit(iforce->type->ff[i], input_dev->ffbit);
440
441 error = input_ff_create(input_dev, ff_effects);
442 if (error) {
443 input_free_device(input_dev);
444 return error;
445 }
446
447 ff = input_dev->ff;
448 ff->upload = iforce_upload_effect;
449 ff->erase = iforce_erase_effect;
450 ff->set_gain = iforce_set_gain;
451 ff->set_autocenter = iforce_set_autocenter;
452 ff->playback = iforce_playback;
453 }
522/* 454/*
523 * Register input device. 455 * Register input device.
524 */ 456 */
diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c
index 76cb1f88f4e8..8632d47a7fbe 100644
--- a/drivers/input/joystick/iforce/iforce-packets.c
+++ b/drivers/input/joystick/iforce/iforce-packets.c
@@ -140,7 +140,10 @@ static int mark_core_as_ready(struct iforce *iforce, unsigned short addr)
140{ 140{
141 int i; 141 int i;
142 142
143 for (i = 0; i < iforce->dev->ff_effects_max; ++i) { 143 if (!iforce->dev->ff)
144 return 0;
145
146 for (i = 0; i < iforce->dev->ff->max_effects; ++i) {
144 if (test_bit(FF_CORE_IS_USED, iforce->core_effects[i].flags) && 147 if (test_bit(FF_CORE_IS_USED, iforce->core_effects[i].flags) &&
145 (iforce->core_effects[i].mod1_chunk.start == addr || 148 (iforce->core_effects[i].mod1_chunk.start == addr ||
146 iforce->core_effects[i].mod2_chunk.start == addr)) { 149 iforce->core_effects[i].mod2_chunk.start == addr)) {
@@ -229,19 +232,17 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data,
229 i = data[1] & 0x7f; 232 i = data[1] & 0x7f;
230 if (data[1] & 0x80) { 233 if (data[1] & 0x80) {
231 if (!test_and_set_bit(FF_CORE_IS_PLAYED, iforce->core_effects[i].flags)) { 234 if (!test_and_set_bit(FF_CORE_IS_PLAYED, iforce->core_effects[i].flags)) {
232 /* Report play event */ 235 /* Report play event */
233 input_report_ff_status(dev, i, FF_STATUS_PLAYING); 236 input_report_ff_status(dev, i, FF_STATUS_PLAYING);
234 } 237 }
235 } 238 } else if (test_and_clear_bit(FF_CORE_IS_PLAYED, iforce->core_effects[i].flags)) {
236 else if (test_and_clear_bit(FF_CORE_IS_PLAYED, iforce->core_effects[i].flags)) {
237 /* Report stop event */ 239 /* Report stop event */
238 input_report_ff_status(dev, i, FF_STATUS_STOPPED); 240 input_report_ff_status(dev, i, FF_STATUS_STOPPED);
239 } 241 }
240 if (LO(cmd) > 3) { 242 if (LO(cmd) > 3) {
241 int j; 243 int j;
242 for (j=3; j<LO(cmd); j+=2) { 244 for (j = 3; j < LO(cmd); j += 2)
243 mark_core_as_ready(iforce, data[j] | (data[j+1]<<8)); 245 mark_core_as_ready(iforce, data[j] | (data[j+1]<<8));
244 }
245 } 246 }
246 break; 247 break;
247 } 248 }
diff --git a/drivers/input/joystick/iforce/iforce.h b/drivers/input/joystick/iforce/iforce.h
index e9924d6f01b3..947df2739843 100644
--- a/drivers/input/joystick/iforce/iforce.h
+++ b/drivers/input/joystick/iforce/iforce.h
@@ -51,10 +51,7 @@
51#define IFORCE_232 1 51#define IFORCE_232 1
52#define IFORCE_USB 2 52#define IFORCE_USB 2
53 53
54#define FALSE 0 54#define IFORCE_EFFECTS_MAX 32
55#define TRUE 1
56
57#define FF_EFFECTS_MAX 32
58 55
59/* Each force feedback effect is made of one core effect, which can be 56/* Each force feedback effect is made of one core effect, which can be
60 * associated to at most to effect modifiers 57 * associated to at most to effect modifiers
@@ -67,24 +64,11 @@
67#define FF_CORE_UPDATE 5 /* Effect is being updated */ 64#define FF_CORE_UPDATE 5 /* Effect is being updated */
68#define FF_MODCORE_MAX 5 65#define FF_MODCORE_MAX 5
69 66
70#define CHECK_OWNERSHIP(i, iforce) \
71 ((i) < FF_EFFECTS_MAX && i >= 0 && \
72 test_bit(FF_CORE_IS_USED, (iforce)->core_effects[(i)].flags) && \
73 (current->pid == 0 || \
74 (iforce)->core_effects[(i)].owner == current->pid))
75
76struct iforce_core_effect { 67struct iforce_core_effect {
77 /* Information about where modifiers are stored in the device's memory */ 68 /* Information about where modifiers are stored in the device's memory */
78 struct resource mod1_chunk; 69 struct resource mod1_chunk;
79 struct resource mod2_chunk; 70 struct resource mod2_chunk;
80 unsigned long flags[NBITS(FF_MODCORE_MAX)]; 71 unsigned long flags[NBITS(FF_MODCORE_MAX)];
81 pid_t owner;
82 /* Used to keep track of parameters of an effect. They are needed
83 * to know what parts of an effect changed in an update operation.
84 * We try to send only parameter packets if possible, as sending
85 * effect parameter requires the effect to be stoped and restarted
86 */
87 struct ff_effect effect;
88}; 72};
89 73
90#define FF_CMD_EFFECT 0x010e 74#define FF_CMD_EFFECT 0x010e
@@ -145,7 +129,7 @@ struct iforce {
145 /* Force Feedback */ 129 /* Force Feedback */
146 wait_queue_head_t wait; 130 wait_queue_head_t wait;
147 struct resource device_memory; 131 struct resource device_memory;
148 struct iforce_core_effect core_effects[FF_EFFECTS_MAX]; 132 struct iforce_core_effect core_effects[IFORCE_EFFECTS_MAX];
149 struct mutex mem_mutex; 133 struct mutex mem_mutex;
150}; 134};
151 135
@@ -182,9 +166,9 @@ void iforce_dump_packet(char *msg, u16 cmd, unsigned char *data) ;
182int iforce_get_id_packet(struct iforce *iforce, char *packet); 166int iforce_get_id_packet(struct iforce *iforce, char *packet);
183 167
184/* iforce-ff.c */ 168/* iforce-ff.c */
185int iforce_upload_periodic(struct iforce*, struct ff_effect*, int is_update); 169int iforce_upload_periodic(struct iforce *, struct ff_effect *, struct ff_effect *);
186int iforce_upload_constant(struct iforce*, struct ff_effect*, int is_update); 170int iforce_upload_constant(struct iforce *, struct ff_effect *, struct ff_effect *);
187int iforce_upload_condition(struct iforce*, struct ff_effect*, int is_update); 171int iforce_upload_condition(struct iforce *, struct ff_effect *, struct ff_effect *);
188 172
189/* Public variables */ 173/* Public variables */
190extern struct serio_driver iforce_serio_drv; 174extern struct serio_driver iforce_serio_drv;
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index a9dda56f62c4..c62e00c79dec 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -121,6 +121,17 @@ config KEYBOARD_NEWTON
121 To compile this driver as a module, choose M here: the 121 To compile this driver as a module, choose M here: the
122 module will be called newtonkbd. 122 module will be called newtonkbd.
123 123
124config KEYBOARD_STOWAWAY
125 tristate "Stowaway keyboard"
126 select SERIO
127 help
128 Say Y here if you have a Stowaway keyboard on a serial port.
129 Stowaway compatible keyboards like Dicota Input-PDA keyboard
130 are also supported by this driver.
131
132 To compile this driver as a module, choose M here: the
133 module will be called stowaway.
134
124config KEYBOARD_CORGI 135config KEYBOARD_CORGI
125 tristate "Corgi keyboard" 136 tristate "Corgi keyboard"
126 depends on PXA_SHARPSL 137 depends on PXA_SHARPSL
@@ -183,4 +194,13 @@ config KEYBOARD_HIL
183 This driver implements support for HIL-keyboards attached 194 This driver implements support for HIL-keyboards attached
184 to your machine, so normally you should say Y here. 195 to your machine, so normally you should say Y here.
185 196
197config KEYBOARD_OMAP
198 tristate "TI OMAP keypad support"
199 depends on (ARCH_OMAP1 || ARCH_OMAP2)
200 help
201 Say Y here if you want to use the OMAP keypad.
202
203 To compile this driver as a module, choose M here: the
204 module will be called omap-keypad.
205
186endif 206endif
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 2708167ba175..4c79e7bc9d06 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -11,8 +11,10 @@ obj-$(CONFIG_KEYBOARD_XTKBD) += xtkbd.o
11obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o 11obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o
12obj-$(CONFIG_KEYBOARD_LOCOMO) += locomokbd.o 12obj-$(CONFIG_KEYBOARD_LOCOMO) += locomokbd.o
13obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o 13obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o
14obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o
14obj-$(CONFIG_KEYBOARD_CORGI) += corgikbd.o 15obj-$(CONFIG_KEYBOARD_CORGI) += corgikbd.o
15obj-$(CONFIG_KEYBOARD_SPITZ) += spitzkbd.o 16obj-$(CONFIG_KEYBOARD_SPITZ) += spitzkbd.o
16obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o 17obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o
17obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o 18obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o
19obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o
18 20
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index a86afd0a5ef1..40244d4ce0f1 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -652,9 +652,7 @@ static int atkbd_probe(struct atkbd *atkbd)
652 return 0; 652 return 0;
653 } 653 }
654 654
655 if (param[0] != 0xab && param[0] != 0xac && /* Regular and NCD Sun keyboards */ 655 if (!ps2_is_keyboard_id(param[0]))
656 param[0] != 0x2b && param[0] != 0x5d && /* Trust keyboard, raw and translated */
657 param[0] != 0x60 && param[0] != 0x47) /* NMB SGI keyboard, raw and translated */
658 return -1; 656 return -1;
659 657
660 atkbd->id = (param[0] << 8) | param[1]; 658 atkbd->id = (param[0] << 8) | param[1];
diff --git a/drivers/input/keyboard/omap-keypad.c b/drivers/input/keyboard/omap-keypad.c
new file mode 100644
index 000000000000..d436287d1d2e
--- /dev/null
+++ b/drivers/input/keyboard/omap-keypad.c
@@ -0,0 +1,492 @@
1/*
2 * linux/drivers/input/keyboard/omap-keypad.c
3 *
4 * OMAP Keypad Driver
5 *
6 * Copyright (C) 2003 Nokia Corporation
7 * Written by Timo Teräs <ext-timo.teras@nokia.com>
8 *
9 * Added support for H2 & H3 Keypad
10 * Copyright (C) 2004 Texas Instruments
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#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/interrupt.h>
30#include <linux/types.h>
31#include <linux/input.h>
32#include <linux/kernel.h>
33#include <linux/delay.h>
34#include <linux/platform_device.h>
35#include <linux/mutex.h>
36#include <linux/errno.h>
37#include <asm/arch/gpio.h>
38#include <asm/arch/keypad.h>
39#include <asm/arch/menelaus.h>
40#include <asm/irq.h>
41#include <asm/hardware.h>
42#include <asm/io.h>
43#include <asm/mach-types.h>
44#include <asm/arch/mux.h>
45
46#undef NEW_BOARD_LEARNING_MODE
47
48static void omap_kp_tasklet(unsigned long);
49static void omap_kp_timer(unsigned long);
50
51static unsigned char keypad_state[8];
52static DEFINE_MUTEX(kp_enable_mutex);
53static int kp_enable = 1;
54static int kp_cur_group = -1;
55
56struct omap_kp {
57 struct input_dev *input;
58 struct timer_list timer;
59 int irq;
60 unsigned int rows;
61 unsigned int cols;
62 unsigned long delay;
63 unsigned int debounce;
64};
65
66DECLARE_TASKLET_DISABLED(kp_tasklet, omap_kp_tasklet, 0);
67
68static int *keymap;
69static unsigned int *row_gpios;
70static unsigned int *col_gpios;
71
72#ifdef CONFIG_ARCH_OMAP2
73static void set_col_gpio_val(struct omap_kp *omap_kp, u8 value)
74{
75 int col;
76 for (col = 0; col < omap_kp->cols; col++) {
77 if (value & (1 << col))
78 omap_set_gpio_dataout(col_gpios[col], 1);
79 else
80 omap_set_gpio_dataout(col_gpios[col], 0);
81 }
82}
83
84static u8 get_row_gpio_val(struct omap_kp *omap_kp)
85{
86 int row;
87 u8 value = 0;
88
89 for (row = 0; row < omap_kp->rows; row++) {
90 if (omap_get_gpio_datain(row_gpios[row]))
91 value |= (1 << row);
92 }
93 return value;
94}
95#else
96#define set_col_gpio_val(x, y) do {} while (0)
97#define get_row_gpio_val(x) 0
98#endif
99
100static irqreturn_t omap_kp_interrupt(int irq, void *dev_id,
101 struct pt_regs *regs)
102{
103 struct omap_kp *omap_kp = dev_id;
104
105 /* disable keyboard interrupt and schedule for handling */
106 if (cpu_is_omap24xx()) {
107 int i;
108 for (i = 0; i < omap_kp->rows; i++)
109 disable_irq(OMAP_GPIO_IRQ(row_gpios[i]));
110 } else
111 /* disable keyboard interrupt and schedule for handling */
112 omap_writew(1, OMAP_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
113
114 tasklet_schedule(&kp_tasklet);
115
116 return IRQ_HANDLED;
117}
118
119static void omap_kp_timer(unsigned long data)
120{
121 tasklet_schedule(&kp_tasklet);
122}
123
124static void omap_kp_scan_keypad(struct omap_kp *omap_kp, unsigned char *state)
125{
126 int col = 0;
127
128 /* read the keypad status */
129 if (cpu_is_omap24xx()) {
130 int i;
131 for (i = 0; i < omap_kp->rows; i++)
132 disable_irq(OMAP_GPIO_IRQ(row_gpios[i]));
133
134 /* read the keypad status */
135 for (col = 0; col < omap_kp->cols; col++) {
136 set_col_gpio_val(omap_kp, ~(1 << col));
137 state[col] = ~(get_row_gpio_val(omap_kp)) & 0x3f;
138 }
139 set_col_gpio_val(omap_kp, 0);
140
141 } else {
142 /* disable keyboard interrupt and schedule for handling */
143 omap_writew(1, OMAP_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
144
145 /* read the keypad status */
146 omap_writew(0xff, OMAP_MPUIO_BASE + OMAP_MPUIO_KBC);
147 for (col = 0; col < omap_kp->cols; col++) {
148 omap_writew(~(1 << col) & 0xff,
149 OMAP_MPUIO_BASE + OMAP_MPUIO_KBC);
150
151 udelay(omap_kp->delay);
152
153 state[col] = ~omap_readw(OMAP_MPUIO_BASE +
154 OMAP_MPUIO_KBR_LATCH) & 0xff;
155 }
156 omap_writew(0x00, OMAP_MPUIO_BASE + OMAP_MPUIO_KBC);
157 udelay(2);
158 }
159}
160
161static inline int omap_kp_find_key(int col, int row)
162{
163 int i, key;
164
165 key = KEY(col, row, 0);
166 for (i = 0; keymap[i] != 0; i++)
167 if ((keymap[i] & 0xff000000) == key)
168 return keymap[i] & 0x00ffffff;
169 return -1;
170}
171
172static void omap_kp_tasklet(unsigned long data)
173{
174 struct omap_kp *omap_kp_data = (struct omap_kp *) data;
175 unsigned char new_state[8], changed, key_down = 0;
176 int col, row;
177 int spurious = 0;
178
179 /* check for any changes */
180 omap_kp_scan_keypad(omap_kp_data, new_state);
181
182 /* check for changes and print those */
183 for (col = 0; col < omap_kp_data->cols; col++) {
184 changed = new_state[col] ^ keypad_state[col];
185 key_down |= new_state[col];
186 if (changed == 0)
187 continue;
188
189 for (row = 0; row < omap_kp_data->rows; row++) {
190 int key;
191 if (!(changed & (1 << row)))
192 continue;
193#ifdef NEW_BOARD_LEARNING_MODE
194 printk(KERN_INFO "omap-keypad: key %d-%d %s\n", col,
195 row, (new_state[col] & (1 << row)) ?
196 "pressed" : "released");
197#else
198 key = omap_kp_find_key(col, row);
199 if (key < 0) {
200 printk(KERN_WARNING
201 "omap-keypad: Spurious key event %d-%d\n",
202 col, row);
203 /* We scan again after a couple of seconds */
204 spurious = 1;
205 continue;
206 }
207
208 if (!(kp_cur_group == (key & GROUP_MASK) ||
209 kp_cur_group == -1))
210 continue;
211
212 kp_cur_group = key & GROUP_MASK;
213 input_report_key(omap_kp_data->input, key & ~GROUP_MASK,
214 new_state[col] & (1 << row));
215#endif
216 }
217 }
218 memcpy(keypad_state, new_state, sizeof(keypad_state));
219
220 if (key_down) {
221 int delay = HZ / 20;
222 /* some key is pressed - keep irq disabled and use timer
223 * to poll the keypad */
224 if (spurious)
225 delay = 2 * HZ;
226 mod_timer(&omap_kp_data->timer, jiffies + delay);
227 } else {
228 /* enable interrupts */
229 if (cpu_is_omap24xx()) {
230 int i;
231 for (i = 0; i < omap_kp_data->rows; i++)
232 enable_irq(OMAP_GPIO_IRQ(row_gpios[i]));
233 } else {
234 omap_writew(0, OMAP_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
235 kp_cur_group = -1;
236 }
237 }
238}
239
240static ssize_t omap_kp_enable_show(struct device *dev,
241 struct device_attribute *attr, char *buf)
242{
243 return sprintf(buf, "%u\n", kp_enable);
244}
245
246static ssize_t omap_kp_enable_store(struct device *dev, struct device_attribute *attr,
247 const char *buf, size_t count)
248{
249 int state;
250
251 if (sscanf(buf, "%u", &state) != 1)
252 return -EINVAL;
253
254 if ((state != 1) && (state != 0))
255 return -EINVAL;
256
257 mutex_lock(&kp_enable_mutex);
258 if (state != kp_enable) {
259 if (state)
260 enable_irq(INT_KEYBOARD);
261 else
262 disable_irq(INT_KEYBOARD);
263 kp_enable = state;
264 }
265 mutex_unlock(&kp_enable_mutex);
266
267 return strnlen(buf, count);
268}
269
270static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, omap_kp_enable_show, omap_kp_enable_store);
271
272#ifdef CONFIG_PM
273static int omap_kp_suspend(struct platform_device *dev, pm_message_t state)
274{
275 /* Nothing yet */
276
277 return 0;
278}
279
280static int omap_kp_resume(struct platform_device *dev)
281{
282 /* Nothing yet */
283
284 return 0;
285}
286#else
287#define omap_kp_suspend NULL
288#define omap_kp_resume NULL
289#endif
290
291static int __init omap_kp_probe(struct platform_device *pdev)
292{
293 struct omap_kp *omap_kp;
294 struct input_dev *input_dev;
295 struct omap_kp_platform_data *pdata = pdev->dev.platform_data;
296 int i, col_idx, row_idx, irq_idx, ret;
297
298 if (!pdata->rows || !pdata->cols || !pdata->keymap) {
299 printk(KERN_ERR "No rows, cols or keymap from pdata\n");
300 return -EINVAL;
301 }
302
303 omap_kp = kzalloc(sizeof(struct omap_kp), GFP_KERNEL);
304 input_dev = input_allocate_device();
305 if (!omap_kp || !input_dev) {
306 kfree(omap_kp);
307 input_free_device(input_dev);
308 return -ENOMEM;
309 }
310
311 platform_set_drvdata(pdev, omap_kp);
312
313 omap_kp->input = input_dev;
314
315 /* Disable the interrupt for the MPUIO keyboard */
316 if (!cpu_is_omap24xx())
317 omap_writew(1, OMAP_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
318
319 keymap = pdata->keymap;
320
321 if (pdata->rep)
322 set_bit(EV_REP, input_dev->evbit);
323
324 if (pdata->delay)
325 omap_kp->delay = pdata->delay;
326
327 if (pdata->row_gpios && pdata->col_gpios) {
328 row_gpios = pdata->row_gpios;
329 col_gpios = pdata->col_gpios;
330 }
331
332 omap_kp->rows = pdata->rows;
333 omap_kp->cols = pdata->cols;
334
335 if (cpu_is_omap24xx()) {
336 /* Cols: outputs */
337 for (col_idx = 0; col_idx < omap_kp->cols; col_idx++) {
338 if (omap_request_gpio(col_gpios[col_idx]) < 0) {
339 printk(KERN_ERR "Failed to request"
340 "GPIO%d for keypad\n",
341 col_gpios[col_idx]);
342 goto err1;
343 }
344 omap_set_gpio_direction(col_gpios[col_idx], 0);
345 }
346 /* Rows: inputs */
347 for (row_idx = 0; row_idx < omap_kp->rows; row_idx++) {
348 if (omap_request_gpio(row_gpios[row_idx]) < 0) {
349 printk(KERN_ERR "Failed to request"
350 "GPIO%d for keypad\n",
351 row_gpios[row_idx]);
352 goto err2;
353 }
354 omap_set_gpio_direction(row_gpios[row_idx], 1);
355 }
356 }
357
358 setup_timer(&omap_kp->timer, omap_kp_timer, (unsigned long)omap_kp);
359
360 /* get the irq and init timer*/
361 tasklet_enable(&kp_tasklet);
362 kp_tasklet.data = (unsigned long) omap_kp;
363
364 ret = device_create_file(&pdev->dev, &dev_attr_enable);
365 if (ret < 0)
366 goto err2;
367
368 /* setup input device */
369 set_bit(EV_KEY, input_dev->evbit);
370 for (i = 0; keymap[i] != 0; i++)
371 set_bit(keymap[i] & KEY_MAX, input_dev->keybit);
372 input_dev->name = "omap-keypad";
373 input_dev->phys = "omap-keypad/input0";
374 input_dev->cdev.dev = &pdev->dev;
375 input_dev->private = omap_kp;
376
377 input_dev->id.bustype = BUS_HOST;
378 input_dev->id.vendor = 0x0001;
379 input_dev->id.product = 0x0001;
380 input_dev->id.version = 0x0100;
381
382 input_dev->keycode = keymap;
383 input_dev->keycodesize = sizeof(unsigned int);
384 input_dev->keycodemax = pdata->keymapsize;
385
386 ret = input_register_device(omap_kp->input);
387 if (ret < 0) {
388 printk(KERN_ERR "Unable to register omap-keypad input device\n");
389 goto err3;
390 }
391
392 if (pdata->dbounce)
393 omap_writew(0xff, OMAP_MPUIO_BASE + OMAP_MPUIO_GPIO_DEBOUNCING);
394
395 /* scan current status and enable interrupt */
396 omap_kp_scan_keypad(omap_kp, keypad_state);
397 if (!cpu_is_omap24xx()) {
398 omap_kp->irq = platform_get_irq(pdev, 0);
399 if (omap_kp->irq >= 0) {
400 if (request_irq(omap_kp->irq, omap_kp_interrupt, 0,
401 "omap-keypad", omap_kp) < 0)
402 goto err4;
403 }
404 omap_writew(0, OMAP_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
405 } else {
406 for (irq_idx = 0; irq_idx < omap_kp->rows; irq_idx++) {
407 if (request_irq(OMAP_GPIO_IRQ(row_gpios[irq_idx]),
408 omap_kp_interrupt,
409 IRQF_TRIGGER_FALLING,
410 "omap-keypad", omap_kp) < 0)
411 goto err5;
412 }
413 }
414 return 0;
415err5:
416 for (i = irq_idx-1; i >=0; i--)
417 free_irq(row_gpios[i], 0);
418err4:
419 input_unregister_device(omap_kp->input);
420 input_dev = NULL;
421err3:
422 device_remove_file(&pdev->dev, &dev_attr_enable);
423err2:
424 for (i = row_idx-1; i >=0; i--)
425 omap_free_gpio(row_gpios[i]);
426err1:
427 for (i = col_idx-1; i >=0; i--)
428 omap_free_gpio(col_gpios[i]);
429
430 kfree(omap_kp);
431 input_free_device(input_dev);
432
433 return -EINVAL;
434}
435
436static int omap_kp_remove(struct platform_device *pdev)
437{
438 struct omap_kp *omap_kp = platform_get_drvdata(pdev);
439
440 /* disable keypad interrupt handling */
441 tasklet_disable(&kp_tasklet);
442 if (cpu_is_omap24xx()) {
443 int i;
444 for (i = 0; i < omap_kp->cols; i++)
445 omap_free_gpio(col_gpios[i]);
446 for (i = 0; i < omap_kp->rows; i++) {
447 omap_free_gpio(row_gpios[i]);
448 free_irq(OMAP_GPIO_IRQ(row_gpios[i]), 0);
449 }
450 } else {
451 omap_writew(1, OMAP_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
452 free_irq(omap_kp->irq, 0);
453 }
454
455 del_timer_sync(&omap_kp->timer);
456 tasklet_kill(&kp_tasklet);
457
458 /* unregister everything */
459 input_unregister_device(omap_kp->input);
460
461 kfree(omap_kp);
462
463 return 0;
464}
465
466static struct platform_driver omap_kp_driver = {
467 .probe = omap_kp_probe,
468 .remove = omap_kp_remove,
469 .suspend = omap_kp_suspend,
470 .resume = omap_kp_resume,
471 .driver = {
472 .name = "omap-keypad",
473 },
474};
475
476static int __devinit omap_kp_init(void)
477{
478 printk(KERN_INFO "OMAP Keypad Driver\n");
479 return platform_driver_register(&omap_kp_driver);
480}
481
482static void __exit omap_kp_exit(void)
483{
484 platform_driver_unregister(&omap_kp_driver);
485}
486
487module_init(omap_kp_init);
488module_exit(omap_kp_exit);
489
490MODULE_AUTHOR("Timo Teräs");
491MODULE_DESCRIPTION("OMAP Keypad Driver");
492MODULE_LICENSE("GPL");
diff --git a/drivers/input/keyboard/stowaway.c b/drivers/input/keyboard/stowaway.c
new file mode 100644
index 000000000000..04c54c57f25c
--- /dev/null
+++ b/drivers/input/keyboard/stowaway.c
@@ -0,0 +1,187 @@
1/*
2 * Stowaway keyboard driver for Linux
3 */
4
5/*
6 * Copyright (c) 2006 Marek Vasut
7 *
8 * Based on Newton keyboard driver for Linux
9 * by Justin Cormack
10 */
11
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
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 *
27 * Should you need to contact me, the author, you can do so either by
28 * e-mail - mail your message to <marek.vasut@gmail.com>, or by paper mail:
29 * Marek Vasut, Liskovecka 559, Frydek-Mistek, 738 01 Czech Republic
30 */
31
32#include <linux/slab.h>
33#include <linux/module.h>
34#include <linux/input.h>
35#include <linux/init.h>
36#include <linux/serio.h>
37
38#define DRIVER_DESC "Stowaway keyboard driver"
39
40MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
41MODULE_DESCRIPTION(DRIVER_DESC);
42MODULE_LICENSE("GPL");
43
44#define SKBD_KEY_MASK 0x7f
45#define SKBD_RELEASE 0x80
46
47static unsigned char skbd_keycode[128] = {
48 KEY_1, KEY_2, KEY_3, KEY_Z, KEY_4, KEY_5, KEY_6, KEY_7,
49 0, KEY_Q, KEY_W, KEY_E, KEY_R, KEY_T, KEY_Y, KEY_GRAVE,
50 KEY_X, KEY_A, KEY_S, KEY_D, KEY_F, KEY_G, KEY_H, KEY_SPACE,
51 KEY_CAPSLOCK, KEY_TAB, KEY_LEFTCTRL, 0, 0, 0, 0, 0,
52 0, 0, 0, KEY_LEFTALT, 0, 0, 0, 0,
53 0, 0, 0, 0, KEY_C, KEY_V, KEY_B, KEY_N,
54 KEY_MINUS, KEY_EQUAL, KEY_BACKSPACE, KEY_HOME, KEY_8, KEY_9, KEY_0, KEY_ESC,
55 KEY_LEFTBRACE, KEY_RIGHTBRACE, KEY_BACKSLASH, KEY_END, KEY_U, KEY_I, KEY_O, KEY_P,
56 KEY_APOSTROPHE, KEY_ENTER, KEY_PAGEUP,0, KEY_J, KEY_K, KEY_L, KEY_SEMICOLON,
57 KEY_SLASH, KEY_UP, KEY_PAGEDOWN, 0,KEY_M, KEY_COMMA, KEY_DOT, KEY_INSERT,
58 KEY_DELETE, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0,
59 KEY_LEFTSHIFT, KEY_RIGHTSHIFT, 0, 0, 0, 0, 0,
60 0, 0, 0, 0, 0, 0, 0, 0,
61 0, 0, 0, 0, 0, 0, 0, 0,
62 0, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7,
63 KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12, 0, 0, 0
64};
65
66struct skbd {
67 unsigned char keycode[128];
68 struct input_dev *dev;
69 struct serio *serio;
70 char phys[32];
71};
72
73static irqreturn_t skbd_interrupt(struct serio *serio, unsigned char data,
74 unsigned int flags, struct pt_regs *regs)
75{
76 struct skbd *skbd = serio_get_drvdata(serio);
77 struct input_dev *dev = skbd->dev;
78
79 if (skbd->keycode[data & SKBD_KEY_MASK]) {
80 input_regs(dev, regs);
81 input_report_key(dev, skbd->keycode[data & SKBD_KEY_MASK],
82 !(data & SKBD_RELEASE));
83 input_sync(dev);
84 }
85
86 return IRQ_HANDLED;
87}
88
89static int skbd_connect(struct serio *serio, struct serio_driver *drv)
90{
91 struct skbd *skbd;
92 struct input_dev *input_dev;
93 int err = -ENOMEM;
94 int i;
95
96 skbd = kzalloc(sizeof(struct skbd), GFP_KERNEL);
97 input_dev = input_allocate_device();
98 if (!skbd || !input_dev)
99 goto fail1;
100
101 skbd->serio = serio;
102 skbd->dev = input_dev;
103 snprintf(skbd->phys, sizeof(skbd->phys), "%s/input0", serio->phys);
104 memcpy(skbd->keycode, skbd_keycode, sizeof(skbd->keycode));
105
106 input_dev->name = "Stowaway Keyboard";
107 input_dev->phys = skbd->phys;
108 input_dev->id.bustype = BUS_RS232;
109 input_dev->id.vendor = SERIO_STOWAWAY;
110 input_dev->id.product = 0x0001;
111 input_dev->id.version = 0x0100;
112 input_dev->cdev.dev = &serio->dev;
113 input_dev->private = skbd;
114
115 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
116 input_dev->keycode = skbd->keycode;
117 input_dev->keycodesize = sizeof(unsigned char);
118 input_dev->keycodemax = ARRAY_SIZE(skbd_keycode);
119 for (i = 0; i < ARRAY_SIZE(skbd_keycode); i++)
120 set_bit(skbd_keycode[i], input_dev->keybit);
121 clear_bit(0, input_dev->keybit);
122
123 serio_set_drvdata(serio, skbd);
124
125 err = serio_open(serio, drv);
126 if (err)
127 goto fail2;
128
129 err = input_register_device(skbd->dev);
130 if (err)
131 goto fail3;
132
133 return 0;
134
135 fail3: serio_close(serio);
136 fail2: serio_set_drvdata(serio, NULL);
137 fail1: input_free_device(input_dev);
138 kfree(skbd);
139 return err;
140}
141
142static void skbd_disconnect(struct serio *serio)
143{
144 struct skbd *skbd = serio_get_drvdata(serio);
145
146 serio_close(serio);
147 serio_set_drvdata(serio, NULL);
148 input_unregister_device(skbd->dev);
149 kfree(skbd);
150}
151
152static struct serio_device_id skbd_serio_ids[] = {
153 {
154 .type = SERIO_RS232,
155 .proto = SERIO_STOWAWAY,
156 .id = SERIO_ANY,
157 .extra = SERIO_ANY,
158 },
159 { 0 }
160};
161
162MODULE_DEVICE_TABLE(serio, skbd_serio_ids);
163
164static struct serio_driver skbd_drv = {
165 .driver = {
166 .name = "stowaway",
167 },
168 .description = DRIVER_DESC,
169 .id_table = skbd_serio_ids,
170 .interrupt = skbd_interrupt,
171 .connect = skbd_connect,
172 .disconnect = skbd_disconnect,
173};
174
175static int __init skbd_init(void)
176{
177 serio_register_driver(&skbd_drv);
178 return 0;
179}
180
181static void __exit skbd_exit(void)
182{
183 serio_unregister_driver(&skbd_drv);
184}
185
186module_init(skbd_init);
187module_exit(skbd_exit);
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index d723e9ad7c41..9516439b7c78 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -20,6 +20,9 @@
20 * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org> 20 * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org>
21 * 21 *
22 * Changes/Revisions: 22 * Changes/Revisions:
23 * 0.3 09/04/2006 (Anssi Hannula <anssi.hannula@gmail.com>)
24 * - updated ff support for the changes in kernel interface
25 * - added MODULE_VERSION
23 * 0.2 16/10/2004 (Micah Dowty <micah@navi.cx>) 26 * 0.2 16/10/2004 (Micah Dowty <micah@navi.cx>)
24 * - added force feedback support 27 * - added force feedback support
25 * - added UI_SET_PHYS 28 * - added UI_SET_PHYS
@@ -107,18 +110,31 @@ static int uinput_request_submit(struct input_dev *dev, struct uinput_request *r
107 return request->retval; 110 return request->retval;
108} 111}
109 112
110static int uinput_dev_upload_effect(struct input_dev *dev, struct ff_effect *effect) 113static void uinput_dev_set_gain(struct input_dev *dev, u16 gain)
114{
115 uinput_dev_event(dev, EV_FF, FF_GAIN, gain);
116}
117
118static void uinput_dev_set_autocenter(struct input_dev *dev, u16 magnitude)
119{
120 uinput_dev_event(dev, EV_FF, FF_AUTOCENTER, magnitude);
121}
122
123static int uinput_dev_playback(struct input_dev *dev, int effect_id, int value)
124{
125 return uinput_dev_event(dev, EV_FF, effect_id, value);
126}
127
128static int uinput_dev_upload_effect(struct input_dev *dev, struct ff_effect *effect, struct ff_effect *old)
111{ 129{
112 struct uinput_request request; 130 struct uinput_request request;
113 int retval; 131 int retval;
114 132
115 if (!test_bit(EV_FF, dev->evbit))
116 return -ENOSYS;
117
118 request.id = -1; 133 request.id = -1;
119 init_completion(&request.done); 134 init_completion(&request.done);
120 request.code = UI_FF_UPLOAD; 135 request.code = UI_FF_UPLOAD;
121 request.u.effect = effect; 136 request.u.upload.effect = effect;
137 request.u.upload.old = old;
122 138
123 retval = uinput_request_reserve_slot(dev->private, &request); 139 retval = uinput_request_reserve_slot(dev->private, &request);
124 if (!retval) 140 if (!retval)
@@ -168,6 +184,7 @@ static void uinput_destroy_device(struct uinput_device *udev)
168 184
169static int uinput_create_device(struct uinput_device *udev) 185static int uinput_create_device(struct uinput_device *udev)
170{ 186{
187 struct input_dev *dev = udev->dev;
171 int error; 188 int error;
172 189
173 if (udev->state != UIST_SETUP_COMPLETE) { 190 if (udev->state != UIST_SETUP_COMPLETE) {
@@ -175,15 +192,29 @@ static int uinput_create_device(struct uinput_device *udev)
175 return -EINVAL; 192 return -EINVAL;
176 } 193 }
177 194
178 error = input_register_device(udev->dev); 195 if (udev->ff_effects_max) {
179 if (error) { 196 error = input_ff_create(dev, udev->ff_effects_max);
180 uinput_destroy_device(udev); 197 if (error)
181 return error; 198 goto fail1;
199
200 dev->ff->upload = uinput_dev_upload_effect;
201 dev->ff->erase = uinput_dev_erase_effect;
202 dev->ff->playback = uinput_dev_playback;
203 dev->ff->set_gain = uinput_dev_set_gain;
204 dev->ff->set_autocenter = uinput_dev_set_autocenter;
182 } 205 }
183 206
207 error = input_register_device(udev->dev);
208 if (error)
209 goto fail2;
210
184 udev->state = UIST_CREATED; 211 udev->state = UIST_CREATED;
185 212
186 return 0; 213 return 0;
214
215 fail2: input_ff_destroy(dev);
216 fail1: uinput_destroy_device(udev);
217 return error;
187} 218}
188 219
189static int uinput_open(struct inode *inode, struct file *file) 220static int uinput_open(struct inode *inode, struct file *file)
@@ -243,8 +274,6 @@ static int uinput_allocate_device(struct uinput_device *udev)
243 return -ENOMEM; 274 return -ENOMEM;
244 275
245 udev->dev->event = uinput_dev_event; 276 udev->dev->event = uinput_dev_event;
246 udev->dev->upload_effect = uinput_dev_upload_effect;
247 udev->dev->erase_effect = uinput_dev_erase_effect;
248 udev->dev->private = udev; 277 udev->dev->private = udev;
249 278
250 return 0; 279 return 0;
@@ -278,6 +307,8 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
278 goto exit; 307 goto exit;
279 } 308 }
280 309
310 udev->ff_effects_max = user_dev->ff_effects_max;
311
281 size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1; 312 size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1;
282 if (!size) { 313 if (!size) {
283 retval = -EINVAL; 314 retval = -EINVAL;
@@ -296,7 +327,6 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
296 dev->id.vendor = user_dev->id.vendor; 327 dev->id.vendor = user_dev->id.vendor;
297 dev->id.product = user_dev->id.product; 328 dev->id.product = user_dev->id.product;
298 dev->id.version = user_dev->id.version; 329 dev->id.version = user_dev->id.version;
299 dev->ff_effects_max = user_dev->ff_effects_max;
300 330
301 size = sizeof(int) * (ABS_MAX + 1); 331 size = sizeof(int) * (ABS_MAX + 1);
302 memcpy(dev->absmax, user_dev->absmax, size); 332 memcpy(dev->absmax, user_dev->absmax, size);
@@ -525,12 +555,17 @@ static long uinput_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
525 break; 555 break;
526 } 556 }
527 req = uinput_request_find(udev, ff_up.request_id); 557 req = uinput_request_find(udev, ff_up.request_id);
528 if (!(req && req->code == UI_FF_UPLOAD && req->u.effect)) { 558 if (!(req && req->code == UI_FF_UPLOAD && req->u.upload.effect)) {
529 retval = -EINVAL; 559 retval = -EINVAL;
530 break; 560 break;
531 } 561 }
532 ff_up.retval = 0; 562 ff_up.retval = 0;
533 memcpy(&ff_up.effect, req->u.effect, sizeof(struct ff_effect)); 563 memcpy(&ff_up.effect, req->u.upload.effect, sizeof(struct ff_effect));
564 if (req->u.upload.old)
565 memcpy(&ff_up.old, req->u.upload.old, sizeof(struct ff_effect));
566 else
567 memset(&ff_up.old, 0, sizeof(struct ff_effect));
568
534 if (copy_to_user(p, &ff_up, sizeof(ff_up))) { 569 if (copy_to_user(p, &ff_up, sizeof(ff_up))) {
535 retval = -EFAULT; 570 retval = -EFAULT;
536 break; 571 break;
@@ -561,12 +596,11 @@ static long uinput_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
561 break; 596 break;
562 } 597 }
563 req = uinput_request_find(udev, ff_up.request_id); 598 req = uinput_request_find(udev, ff_up.request_id);
564 if (!(req && req->code == UI_FF_UPLOAD && req->u.effect)) { 599 if (!(req && req->code == UI_FF_UPLOAD && req->u.upload.effect)) {
565 retval = -EINVAL; 600 retval = -EINVAL;
566 break; 601 break;
567 } 602 }
568 req->retval = ff_up.retval; 603 req->retval = ff_up.retval;
569 memcpy(req->u.effect, &ff_up.effect, sizeof(struct ff_effect));
570 uinput_request_done(udev, req); 604 uinput_request_done(udev, req);
571 break; 605 break;
572 606
@@ -622,6 +656,7 @@ static void __exit uinput_exit(void)
622MODULE_AUTHOR("Aristeu Sergio Rozanski Filho"); 656MODULE_AUTHOR("Aristeu Sergio Rozanski Filho");
623MODULE_DESCRIPTION("User level driver support for input subsystem"); 657MODULE_DESCRIPTION("User level driver support for input subsystem");
624MODULE_LICENSE("GPL"); 658MODULE_LICENSE("GPL");
659MODULE_VERSION("0.3");
625 660
626module_init(uinput_init); 661module_init(uinput_init);
627module_exit(uinput_exit); 662module_exit(uinput_exit);
diff --git a/drivers/input/misc/wistron_btns.c b/drivers/input/misc/wistron_btns.c
index de0f46dd9692..4639537336fc 100644
--- a/drivers/input/misc/wistron_btns.c
+++ b/drivers/input/misc/wistron_btns.c
@@ -248,13 +248,10 @@ static int __init dmi_matched(struct dmi_system_id *dmi)
248 248
249 keymap = dmi->driver_data; 249 keymap = dmi->driver_data;
250 for (key = keymap; key->type != KE_END; key++) { 250 for (key = keymap; key->type != KE_END; key++) {
251 if (key->type == KE_WIFI) { 251 if (key->type == KE_WIFI)
252 have_wifi = 1; 252 have_wifi = 1;
253 break; 253 else if (key->type == KE_BLUETOOTH)
254 } else if (key->type == KE_BLUETOOTH) {
255 have_bluetooth = 1; 254 have_bluetooth = 1;
256 break;
257 }
258 } 255 }
259 return 1; 256 return 1;
260} 257}
@@ -389,7 +386,16 @@ static struct dmi_system_id dmi_ids[] __initdata = {
389 }, 386 },
390 .driver_data = keymap_acer_travelmate_240 387 .driver_data = keymap_acer_travelmate_240
391 }, 388 },
392 { 389 {
390 .callback = dmi_matched,
391 .ident = "Acer TravelMate 2424NWXCi",
392 .matches = {
393 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
394 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2420"),
395 },
396 .driver_data = keymap_acer_travelmate_240
397 },
398 {
393 .callback = dmi_matched, 399 .callback = dmi_matched,
394 .ident = "AOpen 1559AS", 400 .ident = "AOpen 1559AS",
395 .matches = { 401 .matches = {
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 070d75330afd..450b68a619fd 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -36,7 +36,7 @@
36#define ALPS_PASS 0x20 36#define ALPS_PASS 0x20
37#define ALPS_FW_BK_2 0x40 37#define ALPS_FW_BK_2 0x40
38 38
39static struct alps_model_info alps_model_data[] = { 39static const struct alps_model_info alps_model_data[] = {
40 { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T */ 40 { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T */
41 { { 0x53, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, 41 { { 0x53, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
42 { { 0x53, 0x02, 0x14 }, 0xf8, 0xf8, 0 }, 42 { { 0x53, 0x02, 0x14 }, 0xf8, 0xf8, 0 },
@@ -209,10 +209,10 @@ static psmouse_ret_t alps_process_byte(struct psmouse *psmouse, struct pt_regs *
209 return PSMOUSE_GOOD_DATA; 209 return PSMOUSE_GOOD_DATA;
210} 210}
211 211
212static struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version) 212static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version)
213{ 213{
214 struct ps2dev *ps2dev = &psmouse->ps2dev; 214 struct ps2dev *ps2dev = &psmouse->ps2dev;
215 unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 }; 215 static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 };
216 unsigned char param[4]; 216 unsigned char param[4];
217 int i; 217 int i;
218 218
@@ -504,7 +504,7 @@ init_fail:
504int alps_detect(struct psmouse *psmouse, int set_properties) 504int alps_detect(struct psmouse *psmouse, int set_properties)
505{ 505{
506 int version; 506 int version;
507 struct alps_model_info *model; 507 const struct alps_model_info *model;
508 508
509 if (!(model = alps_get_model(psmouse, &version))) 509 if (!(model = alps_get_model(psmouse, &version)))
510 return -1; 510 return -1;
diff --git a/drivers/input/mouse/alps.h b/drivers/input/mouse/alps.h
index e428f8d5d12e..69db7325a494 100644
--- a/drivers/input/mouse/alps.h
+++ b/drivers/input/mouse/alps.h
@@ -25,7 +25,7 @@ struct alps_data {
25 struct input_dev *dev2; /* Relative device */ 25 struct input_dev *dev2; /* Relative device */
26 char name[32]; /* Name */ 26 char name[32]; /* Name */
27 char phys[32]; /* Phys */ 27 char phys[32]; /* Phys */
28 struct alps_model_info *i; /* Info */ 28 const struct alps_model_info *i;/* Info */
29 int prev_fin; /* Finger bit from previous packet */ 29 int prev_fin; /* Finger bit from previous packet */
30}; 30};
31 31
diff --git a/drivers/input/mouse/lifebook.c b/drivers/input/mouse/lifebook.c
index c14395ba7980..5e9d25067513 100644
--- a/drivers/input/mouse/lifebook.c
+++ b/drivers/input/mouse/lifebook.c
@@ -115,13 +115,15 @@ static int lifebook_absolute_mode(struct psmouse *psmouse)
115 115
116static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution) 116static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution)
117{ 117{
118 unsigned char params[] = { 0, 1, 2, 2, 3 }; 118 static const unsigned char params[] = { 0, 1, 2, 2, 3 };
119 unsigned char p;
119 120
120 if (resolution == 0 || resolution > 400) 121 if (resolution == 0 || resolution > 400)
121 resolution = 400; 122 resolution = 400;
122 123
123 ps2_command(&psmouse->ps2dev, &params[resolution / 100], PSMOUSE_CMD_SETRES); 124 p = params[resolution / 100];
124 psmouse->resolution = 50 << params[resolution / 100]; 125 ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
126 psmouse->resolution = 50 << p;
125} 127}
126 128
127static void lifebook_disconnect(struct psmouse *psmouse) 129static void lifebook_disconnect(struct psmouse *psmouse)
diff --git a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
index 54b696cfe1e3..7972eecbcfe4 100644
--- a/drivers/input/mouse/logips2pp.c
+++ b/drivers/input/mouse/logips2pp.c
@@ -30,9 +30,9 @@
30#define PS2PP_NAV_BTN 0x20 30#define PS2PP_NAV_BTN 0x20
31 31
32struct ps2pp_info { 32struct ps2pp_info {
33 const int model; 33 u8 model;
34 unsigned const int kind; 34 u8 kind;
35 unsigned const int features; 35 u16 features;
36}; 36};
37 37
38/* 38/*
@@ -199,9 +199,9 @@ static void ps2pp_disconnect(struct psmouse *psmouse)
199 device_remove_file(&psmouse->ps2dev.serio->dev, &psmouse_attr_smartscroll.dattr); 199 device_remove_file(&psmouse->ps2dev.serio->dev, &psmouse_attr_smartscroll.dattr);
200} 200}
201 201
202static struct ps2pp_info *get_model_info(unsigned char model) 202static const struct ps2pp_info *get_model_info(unsigned char model)
203{ 203{
204 static struct ps2pp_info ps2pp_list[] = { 204 static const struct ps2pp_info ps2pp_list[] = {
205 { 12, 0, PS2PP_SIDE_BTN}, 205 { 12, 0, PS2PP_SIDE_BTN},
206 { 13, 0, 0 }, 206 { 13, 0, 0 },
207 { 15, PS2PP_KIND_MX, /* MX1000 */ 207 { 15, PS2PP_KIND_MX, /* MX1000 */
@@ -215,6 +215,7 @@ static struct ps2pp_info *get_model_info(unsigned char model)
215 { 51, 0, 0 }, 215 { 51, 0, 0 },
216 { 52, PS2PP_KIND_WHEEL, PS2PP_SIDE_BTN | PS2PP_WHEEL }, 216 { 52, PS2PP_KIND_WHEEL, PS2PP_SIDE_BTN | PS2PP_WHEEL },
217 { 53, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, 217 { 53, PS2PP_KIND_WHEEL, PS2PP_WHEEL },
218 { 56, PS2PP_KIND_WHEEL, PS2PP_SIDE_BTN | PS2PP_WHEEL }, /* Cordless MouseMan Wheel */
218 { 61, PS2PP_KIND_MX, /* MX700 */ 219 { 61, PS2PP_KIND_MX, /* MX700 */
219 PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN | 220 PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN |
220 PS2PP_EXTRA_BTN | PS2PP_NAV_BTN }, 221 PS2PP_EXTRA_BTN | PS2PP_NAV_BTN },
@@ -244,12 +245,11 @@ static struct ps2pp_info *get_model_info(unsigned char model)
244 PS2PP_EXTRA_BTN | PS2PP_NAV_BTN }, 245 PS2PP_EXTRA_BTN | PS2PP_NAV_BTN },
245 { 114, PS2PP_KIND_MX, /* MX310 */ 246 { 114, PS2PP_KIND_MX, /* MX310 */
246 PS2PP_WHEEL | PS2PP_SIDE_BTN | 247 PS2PP_WHEEL | PS2PP_SIDE_BTN |
247 PS2PP_TASK_BTN | PS2PP_EXTRA_BTN }, 248 PS2PP_TASK_BTN | PS2PP_EXTRA_BTN }
248 { }
249 }; 249 };
250 int i; 250 int i;
251 251
252 for (i = 0; ps2pp_list[i].model; i++) 252 for (i = 0; i < ARRAY_SIZE(ps2pp_list); i++)
253 if (model == ps2pp_list[i].model) 253 if (model == ps2pp_list[i].model)
254 return &ps2pp_list[i]; 254 return &ps2pp_list[i];
255 255
@@ -261,7 +261,8 @@ static struct ps2pp_info *get_model_info(unsigned char model)
261 * Set up input device's properties based on the detected mouse model. 261 * Set up input device's properties based on the detected mouse model.
262 */ 262 */
263 263
264static void ps2pp_set_model_properties(struct psmouse *psmouse, struct ps2pp_info *model_info, 264static void ps2pp_set_model_properties(struct psmouse *psmouse,
265 const struct ps2pp_info *model_info,
265 int using_ps2pp) 266 int using_ps2pp)
266{ 267{
267 struct input_dev *input_dev = psmouse->dev; 268 struct input_dev *input_dev = psmouse->dev;
@@ -327,7 +328,7 @@ int ps2pp_init(struct psmouse *psmouse, int set_properties)
327 struct ps2dev *ps2dev = &psmouse->ps2dev; 328 struct ps2dev *ps2dev = &psmouse->ps2dev;
328 unsigned char param[4]; 329 unsigned char param[4];
329 unsigned char model, buttons; 330 unsigned char model, buttons;
330 struct ps2pp_info *model_info; 331 const struct ps2pp_info *model_info;
331 int use_ps2pp = 0; 332 int use_ps2pp = 0;
332 333
333 param[0] = 0; 334 param[0] = 0;
@@ -349,7 +350,7 @@ int ps2pp_init(struct psmouse *psmouse, int set_properties)
349/* 350/*
350 * Do Logitech PS2++ / PS2T++ magic init. 351 * Do Logitech PS2++ / PS2T++ magic init.
351 */ 352 */
352 if (model == 97) { /* Touch Pad 3 */ 353 if (model_info->kind == PS2PP_KIND_TP3) { /* Touch Pad 3 */
353 354
354 /* Unprotect RAM */ 355 /* Unprotect RAM */
355 param[0] = 0x11; param[1] = 0x04; param[2] = 0x68; 356 param[0] = 0x11; param[1] = 0x04; param[2] = 0x68;
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 343afa38f4c2..9fb7eb6b0f71 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -112,8 +112,8 @@ static struct workqueue_struct *kpsmoused_wq;
112 112
113struct psmouse_protocol { 113struct psmouse_protocol {
114 enum psmouse_type type; 114 enum psmouse_type type;
115 char *name; 115 const char *name;
116 char *alias; 116 const char *alias;
117 int maxproto; 117 int maxproto;
118 int (*detect)(struct psmouse *, int); 118 int (*detect)(struct psmouse *, int);
119 int (*init)(struct psmouse *); 119 int (*init)(struct psmouse *);
@@ -507,15 +507,17 @@ static int thinking_detect(struct psmouse *psmouse, int set_properties)
507{ 507{
508 struct ps2dev *ps2dev = &psmouse->ps2dev; 508 struct ps2dev *ps2dev = &psmouse->ps2dev;
509 unsigned char param[2]; 509 unsigned char param[2];
510 unsigned char seq[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20, 0 }; 510 static const unsigned char seq[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20 };
511 int i; 511 int i;
512 512
513 param[0] = 10; 513 param[0] = 10;
514 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); 514 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
515 param[0] = 0; 515 param[0] = 0;
516 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); 516 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
517 for (i = 0; seq[i]; i++) 517 for (i = 0; i < ARRAY_SIZE(seq); i++) {
518 ps2_command(ps2dev, seq + i, PSMOUSE_CMD_SETRATE); 518 param[0] = seq[i];
519 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
520 }
519 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID); 521 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
520 522
521 if (param[0] != 2) 523 if (param[0] != 2)
@@ -652,7 +654,7 @@ static int psmouse_extensions(struct psmouse *psmouse,
652 return PSMOUSE_PS2; 654 return PSMOUSE_PS2;
653} 655}
654 656
655static struct psmouse_protocol psmouse_protocols[] = { 657static const struct psmouse_protocol psmouse_protocols[] = {
656 { 658 {
657 .type = PSMOUSE_PS2, 659 .type = PSMOUSE_PS2,
658 .name = "PS/2", 660 .name = "PS/2",
@@ -726,7 +728,7 @@ static struct psmouse_protocol psmouse_protocols[] = {
726 }, 728 },
727}; 729};
728 730
729static struct psmouse_protocol *psmouse_protocol_by_type(enum psmouse_type type) 731static const struct psmouse_protocol *psmouse_protocol_by_type(enum psmouse_type type)
730{ 732{
731 int i; 733 int i;
732 734
@@ -738,9 +740,9 @@ static struct psmouse_protocol *psmouse_protocol_by_type(enum psmouse_type type)
738 return &psmouse_protocols[0]; 740 return &psmouse_protocols[0];
739} 741}
740 742
741static struct psmouse_protocol *psmouse_protocol_by_name(const char *name, size_t len) 743static const struct psmouse_protocol *psmouse_protocol_by_name(const char *name, size_t len)
742{ 744{
743 struct psmouse_protocol *p; 745 const struct psmouse_protocol *p;
744 int i; 746 int i;
745 747
746 for (i = 0; i < ARRAY_SIZE(psmouse_protocols); i++) { 748 for (i = 0; i < ARRAY_SIZE(psmouse_protocols); i++) {
@@ -795,13 +797,15 @@ static int psmouse_probe(struct psmouse *psmouse)
795 797
796void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution) 798void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution)
797{ 799{
798 unsigned char params[] = { 0, 1, 2, 2, 3 }; 800 static const unsigned char params[] = { 0, 1, 2, 2, 3 };
801 unsigned char p;
799 802
800 if (resolution == 0 || resolution > 200) 803 if (resolution == 0 || resolution > 200)
801 resolution = 200; 804 resolution = 200;
802 805
803 ps2_command(&psmouse->ps2dev, &params[resolution / 50], PSMOUSE_CMD_SETRES); 806 p = params[resolution / 50];
804 psmouse->resolution = 25 << params[resolution / 50]; 807 ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
808 psmouse->resolution = 25 << p;
805} 809}
806 810
807/* 811/*
@@ -810,12 +814,14 @@ void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution)
810 814
811static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate) 815static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate)
812{ 816{
813 unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 }; 817 static const unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 };
818 unsigned char r;
814 int i = 0; 819 int i = 0;
815 820
816 while (rates[i] > rate) i++; 821 while (rates[i] > rate) i++;
817 ps2_command(&psmouse->ps2dev, &rates[i], PSMOUSE_CMD_SETRATE); 822 r = rates[i];
818 psmouse->rate = rates[i]; 823 ps2_command(&psmouse->ps2dev, &r, PSMOUSE_CMD_SETRATE);
824 psmouse->rate = r;
819} 825}
820 826
821/* 827/*
@@ -1031,7 +1037,7 @@ static void psmouse_disconnect(struct serio *serio)
1031 mutex_unlock(&psmouse_mutex); 1037 mutex_unlock(&psmouse_mutex);
1032} 1038}
1033 1039
1034static int psmouse_switch_protocol(struct psmouse *psmouse, struct psmouse_protocol *proto) 1040static int psmouse_switch_protocol(struct psmouse *psmouse, const struct psmouse_protocol *proto)
1035{ 1041{
1036 struct input_dev *input_dev = psmouse->dev; 1042 struct input_dev *input_dev = psmouse->dev;
1037 1043
@@ -1362,7 +1368,7 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1362 struct serio *serio = psmouse->ps2dev.serio; 1368 struct serio *serio = psmouse->ps2dev.serio;
1363 struct psmouse *parent = NULL; 1369 struct psmouse *parent = NULL;
1364 struct input_dev *new_dev; 1370 struct input_dev *new_dev;
1365 struct psmouse_protocol *proto; 1371 const struct psmouse_protocol *proto;
1366 int retry = 0; 1372 int retry = 0;
1367 1373
1368 if (!(proto = psmouse_protocol_by_name(buf, count))) 1374 if (!(proto = psmouse_protocol_by_name(buf, count)))
@@ -1459,7 +1465,7 @@ static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data,
1459 1465
1460static int psmouse_set_maxproto(const char *val, struct kernel_param *kp) 1466static int psmouse_set_maxproto(const char *val, struct kernel_param *kp)
1461{ 1467{
1462 struct psmouse_protocol *proto; 1468 const struct psmouse_protocol *proto;
1463 1469
1464 if (!val) 1470 if (!val)
1465 return -EINVAL; 1471 return -EINVAL;
diff --git a/drivers/input/mouse/sermouse.c b/drivers/input/mouse/sermouse.c
index 0023501a5b63..680b32353884 100644
--- a/drivers/input/mouse/sermouse.c
+++ b/drivers/input/mouse/sermouse.c
@@ -42,7 +42,7 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
42MODULE_DESCRIPTION(DRIVER_DESC); 42MODULE_DESCRIPTION(DRIVER_DESC);
43MODULE_LICENSE("GPL"); 43MODULE_LICENSE("GPL");
44 44
45static char *sermouse_protocols[] = { "None", "Mouse Systems Mouse", "Sun Mouse", "Microsoft Mouse", 45static const char *sermouse_protocols[] = { "None", "Mouse Systems Mouse", "Sun Mouse", "Microsoft Mouse",
46 "Logitech M+ Mouse", "Microsoft MZ Mouse", "Logitech MZ+ Mouse", 46 "Logitech M+ Mouse", "Microsoft MZ Mouse", "Logitech MZ+ Mouse",
47 "Logitech MZ++ Mouse"}; 47 "Logitech MZ++ Mouse"};
48 48
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index ad5d0a85e960..392108c436ba 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -430,11 +430,11 @@ static void synaptics_process_packet(struct psmouse *psmouse)
430 430
431static int synaptics_validate_byte(unsigned char packet[], int idx, unsigned char pkt_type) 431static int synaptics_validate_byte(unsigned char packet[], int idx, unsigned char pkt_type)
432{ 432{
433 static unsigned char newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 }; 433 static const unsigned char newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 };
434 static unsigned char newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 }; 434 static const unsigned char newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 };
435 static unsigned char newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 }; 435 static const unsigned char newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 };
436 static unsigned char oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 }; 436 static const unsigned char oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 };
437 static unsigned char oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 }; 437 static const unsigned char oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 };
438 438
439 if (idx < 0 || idx > 4) 439 if (idx < 0 || idx > 4)
440 return 0; 440 return 0;
diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index 1f851acab30d..a22a74a2a3dc 100644
--- a/drivers/input/mousedev.c
+++ b/drivers/input/mousedev.c
@@ -614,7 +614,7 @@ static unsigned int mousedev_poll(struct file *file, poll_table *wait)
614 (list->mousedev->exist ? 0 : (POLLHUP | POLLERR)); 614 (list->mousedev->exist ? 0 : (POLLHUP | POLLERR));
615} 615}
616 616
617static struct file_operations mousedev_fops = { 617static const struct file_operations mousedev_fops = {
618 .owner = THIS_MODULE, 618 .owner = THIS_MODULE,
619 .read = mousedev_read, 619 .read = mousedev_read,
620 .write = mousedev_write, 620 .write = mousedev_write,
@@ -624,7 +624,8 @@ static struct file_operations mousedev_fops = {
624 .fasync = mousedev_fasync, 624 .fasync = mousedev_fasync,
625}; 625};
626 626
627static struct input_handle *mousedev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id) 627static struct input_handle *mousedev_connect(struct input_handler *handler, struct input_dev *dev,
628 const struct input_device_id *id)
628{ 629{
629 struct mousedev *mousedev; 630 struct mousedev *mousedev;
630 struct class_device *cdev; 631 struct class_device *cdev;
@@ -688,7 +689,7 @@ static void mousedev_disconnect(struct input_handle *handle)
688 } 689 }
689} 690}
690 691
691static struct input_device_id mousedev_ids[] = { 692static const struct input_device_id mousedev_ids[] = {
692 { 693 {
693 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT | INPUT_DEVICE_ID_MATCH_RELBIT, 694 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT | INPUT_DEVICE_ID_MATCH_RELBIT,
694 .evbit = { BIT(EV_KEY) | BIT(EV_REL) }, 695 .evbit = { BIT(EV_KEY) | BIT(EV_REL) },
@@ -737,7 +738,12 @@ static int psaux_registered;
737 738
738static int __init mousedev_init(void) 739static int __init mousedev_init(void)
739{ 740{
740 input_register_handler(&mousedev_handler); 741 struct class_device *cdev;
742 int error;
743
744 error = input_register_handler(&mousedev_handler);
745 if (error)
746 return error;
741 747
742 memset(&mousedev_mix, 0, sizeof(struct mousedev)); 748 memset(&mousedev_mix, 0, sizeof(struct mousedev));
743 INIT_LIST_HEAD(&mousedev_mix.list); 749 INIT_LIST_HEAD(&mousedev_mix.list);
@@ -746,12 +752,20 @@ static int __init mousedev_init(void)
746 mousedev_mix.exist = 1; 752 mousedev_mix.exist = 1;
747 mousedev_mix.minor = MOUSEDEV_MIX; 753 mousedev_mix.minor = MOUSEDEV_MIX;
748 754
749 class_device_create(&input_class, NULL, 755 cdev = class_device_create(&input_class, NULL,
750 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX), NULL, "mice"); 756 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX), NULL, "mice");
757 if (IS_ERR(cdev)) {
758 input_unregister_handler(&mousedev_handler);
759 return PTR_ERR(cdev);
760 }
751 761
752#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX 762#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
753 if (!(psaux_registered = !misc_register(&psaux_mouse))) 763 error = misc_register(&psaux_mouse);
754 printk(KERN_WARNING "mice: could not misc_register the device\n"); 764 if (error)
765 printk(KERN_WARNING "mice: could not register psaux device, "
766 "error: %d\n", error);
767 else
768 psaux_registered = 1;
755#endif 769#endif
756 770
757 printk(KERN_INFO "mice: PS/2 mouse device common for all mice\n"); 771 printk(KERN_INFO "mice: PS/2 mouse device common for all mice\n");
diff --git a/drivers/input/power.c b/drivers/input/power.c
index 51a519e24b6d..ee82464a2fa7 100644
--- a/drivers/input/power.c
+++ b/drivers/input/power.c
@@ -98,7 +98,7 @@ static void power_event(struct input_handle *handle, unsigned int type,
98 98
99static struct input_handle *power_connect(struct input_handler *handler, 99static struct input_handle *power_connect(struct input_handler *handler,
100 struct input_dev *dev, 100 struct input_dev *dev,
101 struct input_device_id *id) 101 const struct input_device_id *id)
102{ 102{
103 struct input_handle *handle; 103 struct input_handle *handle;
104 104
@@ -120,7 +120,7 @@ static void power_disconnect(struct input_handle *handle)
120 kfree(handle); 120 kfree(handle);
121} 121}
122 122
123static struct input_device_id power_ids[] = { 123static const struct input_device_id power_ids[] = {
124 { 124 {
125 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT, 125 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT,
126 .evbit = { BIT(EV_KEY) }, 126 .evbit = { BIT(EV_KEY) },
@@ -150,8 +150,7 @@ static struct input_handler power_handler = {
150 150
151static int __init power_init(void) 151static int __init power_init(void)
152{ 152{
153 input_register_handler(&power_handler); 153 return input_register_handler(&power_handler);
154 return 0;
155} 154}
156 155
157static void __exit power_exit(void) 156static void __exit power_exit(void)
diff --git a/drivers/input/serio/i8042-io.h b/drivers/input/serio/i8042-io.h
index cc21914fbc72..3b4e13b9ce1b 100644
--- a/drivers/input/serio/i8042-io.h
+++ b/drivers/input/serio/i8042-io.h
@@ -67,25 +67,22 @@ static inline int i8042_platform_init(void)
67 * On some platforms touching the i8042 data register region can do really 67 * On some platforms touching the i8042 data register region can do really
68 * bad things. Because of this the region is always reserved on such boxes. 68 * bad things. Because of this the region is always reserved on such boxes.
69 */ 69 */
70#if !defined(__sh__) && !defined(__alpha__) && !defined(__mips__) && !defined(CONFIG_PPC_MERGE)
71 if (!request_region(I8042_DATA_REG, 16, "i8042"))
72 return -EBUSY;
73#endif
74
75 i8042_reset = 1;
76
77#if defined(CONFIG_PPC_MERGE) 70#if defined(CONFIG_PPC_MERGE)
78 if (check_legacy_ioport(I8042_DATA_REG)) 71 if (check_legacy_ioport(I8042_DATA_REG))
79 return -EBUSY; 72 return -ENODEV;
73#endif
74#if !defined(__sh__) && !defined(__alpha__) && !defined(__mips__)
80 if (!request_region(I8042_DATA_REG, 16, "i8042")) 75 if (!request_region(I8042_DATA_REG, 16, "i8042"))
81 return -EBUSY; 76 return -EBUSY;
82#endif 77#endif
78
79 i8042_reset = 1;
83 return 0; 80 return 0;
84} 81}
85 82
86static inline void i8042_platform_exit(void) 83static inline void i8042_platform_exit(void)
87{ 84{
88#if !defined(__sh__) && !defined(__alpha__) && !defined(CONFIG_PPC64) 85#if !defined(__sh__) && !defined(__alpha__)
89 release_region(I8042_DATA_REG, 16); 86 release_region(I8042_DATA_REG, 16);
90#endif 87#endif
91} 88}
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index f606e96bc2f4..8738edda6610 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -160,6 +160,13 @@ static struct dmi_system_id __initdata i8042_dmi_nomux_table[] = {
160 }, 160 },
161 }, 161 },
162 { 162 {
163 .ident = "Toshiba Equium A110",
164 .matches = {
165 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
166 DMI_MATCH(DMI_PRODUCT_NAME, "EQUIUM A110"),
167 },
168 },
169 {
163 .ident = "Alienware Sentia", 170 .ident = "Alienware Sentia",
164 .matches = { 171 .matches = {
165 DMI_MATCH(DMI_SYS_VENDOR, "ALIENWARE"), 172 DMI_MATCH(DMI_SYS_VENDOR, "ALIENWARE"),
@@ -180,6 +187,13 @@ static struct dmi_system_id __initdata i8042_dmi_nomux_table[] = {
180 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FS115B"), 187 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FS115B"),
181 }, 188 },
182 }, 189 },
190 {
191 .ident = "Amoi M636/A737",
192 .matches = {
193 DMI_MATCH(DMI_SYS_VENDOR, "Amoi Electronics CO.,LTD."),
194 DMI_MATCH(DMI_PRODUCT_NAME, "M636/A737 platform"),
195 },
196 },
183 { } 197 { }
184}; 198};
185 199
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index 06a3f25657dd..1bb0c76a9259 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -90,46 +90,24 @@ static DEFINE_SPINLOCK(i8042_lock);
90struct i8042_port { 90struct i8042_port {
91 struct serio *serio; 91 struct serio *serio;
92 int irq; 92 int irq;
93 unsigned char disable;
94 unsigned char irqen;
95 unsigned char exists; 93 unsigned char exists;
96 signed char mux; 94 signed char mux;
97 char name[8];
98}; 95};
99 96
100#define I8042_KBD_PORT_NO 0 97#define I8042_KBD_PORT_NO 0
101#define I8042_AUX_PORT_NO 1 98#define I8042_AUX_PORT_NO 1
102#define I8042_MUX_PORT_NO 2 99#define I8042_MUX_PORT_NO 2
103#define I8042_NUM_PORTS (I8042_NUM_MUX_PORTS + 2) 100#define I8042_NUM_PORTS (I8042_NUM_MUX_PORTS + 2)
104static struct i8042_port i8042_ports[I8042_NUM_PORTS] = { 101
105 { 102static struct i8042_port i8042_ports[I8042_NUM_PORTS];
106 .disable = I8042_CTR_KBDDIS,
107 .irqen = I8042_CTR_KBDINT,
108 .mux = -1,
109 .name = "KBD",
110 },
111 {
112 .disable = I8042_CTR_AUXDIS,
113 .irqen = I8042_CTR_AUXINT,
114 .mux = -1,
115 .name = "AUX",
116 }
117};
118 103
119static unsigned char i8042_initial_ctr; 104static unsigned char i8042_initial_ctr;
120static unsigned char i8042_ctr; 105static unsigned char i8042_ctr;
121static unsigned char i8042_mux_open;
122static unsigned char i8042_mux_present; 106static unsigned char i8042_mux_present;
123static struct timer_list i8042_timer; 107static unsigned char i8042_kbd_irq_registered;
108static unsigned char i8042_aux_irq_registered;
124static struct platform_device *i8042_platform_device; 109static struct platform_device *i8042_platform_device;
125 110
126
127/*
128 * Shared IRQ's require a device pointer, but this driver doesn't support
129 * multiple devices
130 */
131#define i8042_request_irq_cookie (&i8042_timer)
132
133static irqreturn_t i8042_interrupt(int irq, void *dev_id, struct pt_regs *regs); 111static irqreturn_t i8042_interrupt(int irq, void *dev_id, struct pt_regs *regs);
134 112
135/* 113/*
@@ -141,6 +119,7 @@ static irqreturn_t i8042_interrupt(int irq, void *dev_id, struct pt_regs *regs);
141static int i8042_wait_read(void) 119static int i8042_wait_read(void)
142{ 120{
143 int i = 0; 121 int i = 0;
122
144 while ((~i8042_read_status() & I8042_STR_OBF) && (i < I8042_CTL_TIMEOUT)) { 123 while ((~i8042_read_status() & I8042_STR_OBF) && (i < I8042_CTL_TIMEOUT)) {
145 udelay(50); 124 udelay(50);
146 i++; 125 i++;
@@ -151,6 +130,7 @@ static int i8042_wait_read(void)
151static int i8042_wait_write(void) 130static int i8042_wait_write(void)
152{ 131{
153 int i = 0; 132 int i = 0;
133
154 while ((i8042_read_status() & I8042_STR_IBF) && (i < I8042_CTL_TIMEOUT)) { 134 while ((i8042_read_status() & I8042_STR_IBF) && (i < I8042_CTL_TIMEOUT)) {
155 udelay(50); 135 udelay(50);
156 i++; 136 i++;
@@ -192,48 +172,57 @@ static int i8042_flush(void)
192 * encoded in bits 8-11 of the command number. 172 * encoded in bits 8-11 of the command number.
193 */ 173 */
194 174
195static int i8042_command(unsigned char *param, int command) 175static int __i8042_command(unsigned char *param, int command)
196{ 176{
197 unsigned long flags; 177 int i, error;
198 int i, retval, auxerr = 0;
199 178
200 if (i8042_noloop && command == I8042_CMD_AUX_LOOP) 179 if (i8042_noloop && command == I8042_CMD_AUX_LOOP)
201 return -1; 180 return -1;
202 181
203 spin_lock_irqsave(&i8042_lock, flags); 182 error = i8042_wait_write();
204 183 if (error)
205 if ((retval = i8042_wait_write())) 184 return error;
206 goto out;
207 185
208 dbg("%02x -> i8042 (command)", command & 0xff); 186 dbg("%02x -> i8042 (command)", command & 0xff);
209 i8042_write_command(command & 0xff); 187 i8042_write_command(command & 0xff);
210 188
211 for (i = 0; i < ((command >> 12) & 0xf); i++) { 189 for (i = 0; i < ((command >> 12) & 0xf); i++) {
212 if ((retval = i8042_wait_write())) 190 error = i8042_wait_write();
213 goto out; 191 if (error)
192 return error;
214 dbg("%02x -> i8042 (parameter)", param[i]); 193 dbg("%02x -> i8042 (parameter)", param[i]);
215 i8042_write_data(param[i]); 194 i8042_write_data(param[i]);
216 } 195 }
217 196
218 for (i = 0; i < ((command >> 8) & 0xf); i++) { 197 for (i = 0; i < ((command >> 8) & 0xf); i++) {
219 if ((retval = i8042_wait_read())) 198 error = i8042_wait_read();
220 goto out; 199 if (error) {
200 dbg(" -- i8042 (timeout)");
201 return error;
202 }
221 203
222 if (command == I8042_CMD_AUX_LOOP && 204 if (command == I8042_CMD_AUX_LOOP &&
223 !(i8042_read_status() & I8042_STR_AUXDATA)) { 205 !(i8042_read_status() & I8042_STR_AUXDATA)) {
224 retval = auxerr = -1; 206 dbg(" -- i8042 (auxerr)");
225 goto out; 207 return -1;
226 } 208 }
227 209
228 param[i] = i8042_read_data(); 210 param[i] = i8042_read_data();
229 dbg("%02x <- i8042 (return)", param[i]); 211 dbg("%02x <- i8042 (return)", param[i]);
230 } 212 }
231 213
232 if (retval) 214 return 0;
233 dbg(" -- i8042 (%s)", auxerr ? "auxerr" : "timeout"); 215}
234 216
235 out: 217static int i8042_command(unsigned char *param, int command)
218{
219 unsigned long flags;
220 int retval;
221
222 spin_lock_irqsave(&i8042_lock, flags);
223 retval = __i8042_command(param, command);
236 spin_unlock_irqrestore(&i8042_lock, flags); 224 spin_unlock_irqrestore(&i8042_lock, flags);
225
237 return retval; 226 return retval;
238} 227}
239 228
@@ -248,7 +237,7 @@ static int i8042_kbd_write(struct serio *port, unsigned char c)
248 237
249 spin_lock_irqsave(&i8042_lock, flags); 238 spin_lock_irqsave(&i8042_lock, flags);
250 239
251 if(!(retval = i8042_wait_write())) { 240 if (!(retval = i8042_wait_write())) {
252 dbg("%02x -> i8042 (kbd-data)", c); 241 dbg("%02x -> i8042 (kbd-data)", c);
253 i8042_write_data(c); 242 i8042_write_data(c);
254 } 243 }
@@ -287,100 +276,6 @@ static int i8042_aux_write(struct serio *serio, unsigned char c)
287} 276}
288 277
289/* 278/*
290 * i8042_activate_port() enables port on a chip.
291 */
292
293static int i8042_activate_port(struct i8042_port *port)
294{
295 if (!port->serio)
296 return -1;
297
298 i8042_flush();
299
300 /*
301 * Enable port again here because it is disabled if we are
302 * resuming (normally it is enabled already).
303 */
304 i8042_ctr &= ~port->disable;
305
306 i8042_ctr |= port->irqen;
307
308 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) {
309 i8042_ctr &= ~port->irqen;
310 return -1;
311 }
312
313 return 0;
314}
315
316
317/*
318 * i8042_open() is called when a port is open by the higher layer.
319 * It allocates the interrupt and calls i8042_enable_port.
320 */
321
322static int i8042_open(struct serio *serio)
323{
324 struct i8042_port *port = serio->port_data;
325
326 if (port->mux != -1)
327 if (i8042_mux_open++)
328 return 0;
329
330 if (request_irq(port->irq, i8042_interrupt,
331 IRQF_SHARED, "i8042", i8042_request_irq_cookie)) {
332 printk(KERN_ERR "i8042.c: Can't get irq %d for %s, unregistering the port.\n", port->irq, port->name);
333 goto irq_fail;
334 }
335
336 if (i8042_activate_port(port)) {
337 printk(KERN_ERR "i8042.c: Can't activate %s, unregistering the port\n", port->name);
338 goto activate_fail;
339 }
340
341 i8042_interrupt(0, NULL, NULL);
342
343 return 0;
344
345 activate_fail:
346 free_irq(port->irq, i8042_request_irq_cookie);
347
348 irq_fail:
349 serio_unregister_port_delayed(serio);
350
351 return -1;
352}
353
354/*
355 * i8042_close() frees the interrupt, so that it can possibly be used
356 * by another driver. We never know - if the user doesn't have a mouse,
357 * the BIOS could have used the AUX interrupt for PCI.
358 */
359
360static void i8042_close(struct serio *serio)
361{
362 struct i8042_port *port = serio->port_data;
363
364 if (port->mux != -1)
365 if (--i8042_mux_open)
366 return;
367
368 i8042_ctr &= ~port->irqen;
369
370 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) {
371 printk(KERN_WARNING "i8042.c: Can't write CTR while closing %s.\n", port->name);
372/*
373 * We still want to continue and free IRQ so if more data keeps coming in
374 * kernel will just ignore the irq.
375 */
376 }
377
378 free_irq(port->irq, i8042_request_irq_cookie);
379
380 i8042_flush();
381}
382
383/*
384 * i8042_start() is called by serio core when port is about to finish 279 * i8042_start() is called by serio core when port is about to finish
385 * registering. It will mark port as existing so i8042_interrupt can 280 * registering. It will mark port as existing so i8042_interrupt can
386 * start sending data through it. 281 * start sending data through it.
@@ -423,8 +318,6 @@ static irqreturn_t i8042_interrupt(int irq, void *dev_id, struct pt_regs *regs)
423 unsigned int port_no; 318 unsigned int port_no;
424 int ret; 319 int ret;
425 320
426 mod_timer(&i8042_timer, jiffies + I8042_POLL_PERIOD);
427
428 spin_lock_irqsave(&i8042_lock, flags); 321 spin_lock_irqsave(&i8042_lock, flags);
429 str = i8042_read_status(); 322 str = i8042_read_status();
430 if (unlikely(~str & I8042_STR_OBF)) { 323 if (unlikely(~str & I8042_STR_OBF)) {
@@ -480,8 +373,8 @@ static irqreturn_t i8042_interrupt(int irq, void *dev_id, struct pt_regs *regs)
480 373
481 port = &i8042_ports[port_no]; 374 port = &i8042_ports[port_no];
482 375
483 dbg("%02x <- i8042 (interrupt, %s, %d%s%s)", 376 dbg("%02x <- i8042 (interrupt, %d, %d%s%s)",
484 data, port->name, irq, 377 data, port_no, irq,
485 dfl & SERIO_PARITY ? ", bad parity" : "", 378 dfl & SERIO_PARITY ? ", bad parity" : "",
486 dfl & SERIO_TIMEOUT ? ", timeout" : ""); 379 dfl & SERIO_TIMEOUT ? ", timeout" : "");
487 380
@@ -494,6 +387,58 @@ static irqreturn_t i8042_interrupt(int irq, void *dev_id, struct pt_regs *regs)
494} 387}
495 388
496/* 389/*
390 * i8042_enable_kbd_port enables keybaord port on chip
391 */
392
393static int i8042_enable_kbd_port(void)
394{
395 i8042_ctr &= ~I8042_CTR_KBDDIS;
396 i8042_ctr |= I8042_CTR_KBDINT;
397
398 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) {
399 printk(KERN_ERR "i8042.c: Failed to enable KBD port.\n");
400 return -EIO;
401 }
402
403 return 0;
404}
405
406/*
407 * i8042_enable_aux_port enables AUX (mouse) port on chip
408 */
409
410static int i8042_enable_aux_port(void)
411{
412 i8042_ctr &= ~I8042_CTR_AUXDIS;
413 i8042_ctr |= I8042_CTR_AUXINT;
414
415 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) {
416 printk(KERN_ERR "i8042.c: Failed to enable AUX port.\n");
417 return -EIO;
418 }
419
420 return 0;
421}
422
423/*
424 * i8042_enable_mux_ports enables 4 individual AUX ports after
425 * the controller has been switched into Multiplexed mode
426 */
427
428static int i8042_enable_mux_ports(void)
429{
430 unsigned char param;
431 int i;
432
433 for (i = 0; i < I8042_NUM_MUX_PORTS; i++) {
434 i8042_command(&param, I8042_CMD_MUX_PFX + i);
435 i8042_command(&param, I8042_CMD_AUX_ENABLE);
436 }
437
438 return i8042_enable_aux_port();
439}
440
441/*
497 * i8042_set_mux_mode checks whether the controller has an active 442 * i8042_set_mux_mode checks whether the controller has an active
498 * multiplexor and puts the chip into Multiplexed (1) or Legacy (0) mode. 443 * multiplexor and puts the chip into Multiplexed (1) or Legacy (0) mode.
499 */ 444 */
@@ -510,8 +455,7 @@ static int i8042_set_mux_mode(unsigned int mode, unsigned char *mux_version)
510 455
511/* 456/*
512 * Internal loopback test - send three bytes, they should come back from the 457 * Internal loopback test - send three bytes, they should come back from the
513 * mouse interface, the last should be version. Note that we negate mouseport 458 * mouse interface, the last should be version.
514 * command responses for the i8042_check_aux() routine.
515 */ 459 */
516 460
517 param = 0xf0; 461 param = 0xf0;
@@ -530,67 +474,67 @@ static int i8042_set_mux_mode(unsigned int mode, unsigned char *mux_version)
530 return 0; 474 return 0;
531} 475}
532 476
533
534/* 477/*
535 * i8042_enable_mux_ports enables 4 individual AUX ports after 478 * i8042_check_mux() checks whether the controller supports the PS/2 Active
536 * the controller has been switched into Multiplexed mode 479 * Multiplexing specification by Synaptics, Phoenix, Insyde and
480 * LCS/Telegraphics.
537 */ 481 */
538 482
539static int i8042_enable_mux_ports(void) 483static int __devinit i8042_check_mux(void)
540{ 484{
541 unsigned char param; 485 unsigned char mux_version;
542 int i; 486
487 if (i8042_set_mux_mode(1, &mux_version))
488 return -1;
489
543/* 490/*
544 * Disable all muxed ports by disabling AUX. 491 * Workaround for interference with USB Legacy emulation
492 * that causes a v10.12 MUX to be found.
545 */ 493 */
494 if (mux_version == 0xAC)
495 return -1;
496
497 printk(KERN_INFO "i8042.c: Detected active multiplexing controller, rev %d.%d.\n",
498 (mux_version >> 4) & 0xf, mux_version & 0xf);
546 499
500/*
501 * Disable all muxed ports by disabling AUX.
502 */
547 i8042_ctr |= I8042_CTR_AUXDIS; 503 i8042_ctr |= I8042_CTR_AUXDIS;
548 i8042_ctr &= ~I8042_CTR_AUXINT; 504 i8042_ctr &= ~I8042_CTR_AUXINT;
549 505
550 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) { 506 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) {
551 printk(KERN_ERR "i8042.c: Failed to disable AUX port, can't use MUX.\n"); 507 printk(KERN_ERR "i8042.c: Failed to disable AUX port, can't use MUX.\n");
552 return -1; 508 return -EIO;
553 } 509 }
554 510
555/* 511 i8042_mux_present = 1;
556 * Enable all muxed ports.
557 */
558
559 for (i = 0; i < I8042_NUM_MUX_PORTS; i++) {
560 i8042_command(&param, I8042_CMD_MUX_PFX + i);
561 i8042_command(&param, I8042_CMD_AUX_ENABLE);
562 }
563 512
564 return 0; 513 return 0;
565} 514}
566 515
567
568/* 516/*
569 * i8042_check_mux() checks whether the controller supports the PS/2 Active 517 * The following is used to test AUX IRQ delivery.
570 * Multiplexing specification by Synaptics, Phoenix, Insyde and
571 * LCS/Telegraphics.
572 */ 518 */
519static struct completion i8042_aux_irq_delivered __devinitdata;
520static int i8042_irq_being_tested __devinitdata;
573 521
574static int __devinit i8042_check_mux(void) 522static irqreturn_t __devinit i8042_aux_test_irq(int irq, void *dev_id, struct pt_regs *regs)
575{ 523{
576 unsigned char mux_version; 524 unsigned long flags;
577 525 unsigned char str, data;
578 if (i8042_set_mux_mode(1, &mux_version))
579 return -1;
580
581 /* Workaround for interference with USB Legacy emulation */
582 /* that causes a v10.12 MUX to be found. */
583 if (mux_version == 0xAC)
584 return -1;
585
586 printk(KERN_INFO "i8042.c: Detected active multiplexing controller, rev %d.%d.\n",
587 (mux_version >> 4) & 0xf, mux_version & 0xf);
588 526
589 if (i8042_enable_mux_ports()) 527 spin_lock_irqsave(&i8042_lock, flags);
590 return -1; 528 str = i8042_read_status();
529 if (str & I8042_STR_OBF) {
530 data = i8042_read_data();
531 if (i8042_irq_being_tested &&
532 data == 0xa5 && (str & I8042_STR_AUXDATA))
533 complete(&i8042_aux_irq_delivered);
534 }
535 spin_unlock_irqrestore(&i8042_lock, flags);
591 536
592 i8042_mux_present = 1; 537 return IRQ_HANDLED;
593 return 0;
594} 538}
595 539
596 540
@@ -601,18 +545,10 @@ static int __devinit i8042_check_mux(void)
601 545
602static int __devinit i8042_check_aux(void) 546static int __devinit i8042_check_aux(void)
603{ 547{
548 int retval = -1;
549 int irq_registered = 0;
550 unsigned long flags;
604 unsigned char param; 551 unsigned char param;
605 static int i8042_check_aux_cookie;
606
607/*
608 * Check if AUX irq is available. If it isn't, then there is no point
609 * in trying to detect AUX presence.
610 */
611
612 if (request_irq(i8042_ports[I8042_AUX_PORT_NO].irq, i8042_interrupt,
613 IRQF_SHARED, "i8042", &i8042_check_aux_cookie))
614 return -1;
615 free_irq(i8042_ports[I8042_AUX_PORT_NO].irq, &i8042_check_aux_cookie);
616 552
617/* 553/*
618 * Get rid of bytes in the queue. 554 * Get rid of bytes in the queue.
@@ -637,9 +573,9 @@ static int __devinit i8042_check_aux(void)
637 * AUX ports, we test for this only when the LOOP command failed. 573 * AUX ports, we test for this only when the LOOP command failed.
638 */ 574 */
639 575
640 if (i8042_command(&param, I8042_CMD_AUX_TEST) 576 if (i8042_command(&param, I8042_CMD_AUX_TEST) ||
641 || (param && param != 0xfa && param != 0xff)) 577 (param && param != 0xfa && param != 0xff))
642 return -1; 578 return -1;
643 } 579 }
644 580
645/* 581/*
@@ -659,54 +595,80 @@ static int __devinit i8042_check_aux(void)
659 return -1; 595 return -1;
660 596
661/* 597/*
662 * Disable the interface. 598 * Test AUX IRQ delivery to make sure BIOS did not grab the IRQ and
599 * used it for a PCI card or somethig else.
663 */ 600 */
664 601
665 i8042_ctr |= I8042_CTR_AUXDIS; 602 if (i8042_noloop) {
666 i8042_ctr &= ~I8042_CTR_AUXINT; 603/*
604 * Without LOOP command we can't test AUX IRQ delivery. Assume the port
605 * is working and hope we are right.
606 */
607 retval = 0;
608 goto out;
609 }
667 610
668 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) 611 if (request_irq(I8042_AUX_IRQ, i8042_aux_test_irq, IRQF_SHARED,
669 return -1; 612 "i8042", i8042_platform_device))
613 goto out;
670 614
671 return 0; 615 irq_registered = 1;
672} 616
617 if (i8042_enable_aux_port())
618 goto out;
619
620 spin_lock_irqsave(&i8042_lock, flags);
673 621
622 init_completion(&i8042_aux_irq_delivered);
623 i8042_irq_being_tested = 1;
624
625 param = 0xa5;
626 retval = __i8042_command(&param, I8042_CMD_AUX_LOOP & 0xf0ff);
627
628 spin_unlock_irqrestore(&i8042_lock, flags);
629
630 if (retval)
631 goto out;
674 632
633 if (wait_for_completion_timeout(&i8042_aux_irq_delivered,
634 msecs_to_jiffies(250)) == 0) {
675/* 635/*
676 * i8042_port_register() marks the device as existing, 636 * AUX IRQ was never delivered so we need to flush the controller to
677 * registers it, and reports to the user. 637 * get rid of the byte we put there; otherwise keyboard may not work.
678 */ 638 */
639 i8042_flush();
640 retval = -1;
641 }
679 642
680static int __devinit i8042_port_register(struct i8042_port *port) 643 out:
681{
682 i8042_ctr &= ~port->disable;
683 644
684 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) { 645/*
685 printk(KERN_WARNING "i8042.c: Can't write CTR while registering.\n"); 646 * Disable the interface.
686 kfree(port->serio); 647 */
687 port->serio = NULL;
688 i8042_ctr |= port->disable;
689 return -EIO;
690 }
691 648
692 printk(KERN_INFO "serio: i8042 %s port at %#lx,%#lx irq %d\n", 649 i8042_ctr |= I8042_CTR_AUXDIS;
693 port->name, 650 i8042_ctr &= ~I8042_CTR_AUXINT;
694 (unsigned long) I8042_DATA_REG,
695 (unsigned long) I8042_COMMAND_REG,
696 port->irq);
697 651
698 serio_register_port(port->serio); 652 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR))
653 retval = -1;
699 654
700 return 0; 655 if (irq_registered)
701} 656 free_irq(I8042_AUX_IRQ, i8042_platform_device);
702 657
658 return retval;
659}
703 660
704static void i8042_timer_func(unsigned long data) 661static int i8042_controller_check(void)
705{ 662{
706 i8042_interrupt(0, NULL, NULL); 663 if (i8042_flush() == I8042_BUFFER_SIZE) {
664 printk(KERN_ERR "i8042.c: No controller found.\n");
665 return -ENODEV;
666 }
667
668 return 0;
707} 669}
708 670
709static int i8042_ctl_test(void) 671static int i8042_controller_selftest(void)
710{ 672{
711 unsigned char param; 673 unsigned char param;
712 674
@@ -715,13 +677,13 @@ static int i8042_ctl_test(void)
715 677
716 if (i8042_command(&param, I8042_CMD_CTL_TEST)) { 678 if (i8042_command(&param, I8042_CMD_CTL_TEST)) {
717 printk(KERN_ERR "i8042.c: i8042 controller self test timeout.\n"); 679 printk(KERN_ERR "i8042.c: i8042 controller self test timeout.\n");
718 return -1; 680 return -ENODEV;
719 } 681 }
720 682
721 if (param != I8042_RET_CTL_TEST) { 683 if (param != I8042_RET_CTL_TEST) {
722 printk(KERN_ERR "i8042.c: i8042 controller selftest failed. (%#x != %#x)\n", 684 printk(KERN_ERR "i8042.c: i8042 controller selftest failed. (%#x != %#x)\n",
723 param, I8042_RET_CTL_TEST); 685 param, I8042_RET_CTL_TEST);
724 return -1; 686 return -EIO;
725 } 687 }
726 688
727 return 0; 689 return 0;
@@ -738,25 +700,12 @@ static int i8042_controller_init(void)
738 unsigned long flags; 700 unsigned long flags;
739 701
740/* 702/*
741 * Test the i8042. We need to know if it thinks it's working correctly
742 * before doing anything else.
743 */
744
745 if (i8042_flush() == I8042_BUFFER_SIZE) {
746 printk(KERN_ERR "i8042.c: No controller found.\n");
747 return -1;
748 }
749
750 if (i8042_ctl_test())
751 return -1;
752
753/*
754 * Save the CTR for restoral on unload / reboot. 703 * Save the CTR for restoral on unload / reboot.
755 */ 704 */
756 705
757 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_RCTR)) { 706 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_RCTR)) {
758 printk(KERN_ERR "i8042.c: Can't read CTR while initializing i8042.\n"); 707 printk(KERN_ERR "i8042.c: Can't read CTR while initializing i8042.\n");
759 return -1; 708 return -EIO;
760 } 709 }
761 710
762 i8042_initial_ctr = i8042_ctr; 711 i8042_initial_ctr = i8042_ctr;
@@ -805,7 +754,7 @@ static int i8042_controller_init(void)
805 754
806 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) { 755 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) {
807 printk(KERN_ERR "i8042.c: Can't write CTR while initializing i8042.\n"); 756 printk(KERN_ERR "i8042.c: Can't write CTR while initializing i8042.\n");
808 return -1; 757 return -EIO;
809 } 758 }
810 759
811 return 0; 760 return 0;
@@ -813,15 +762,12 @@ static int i8042_controller_init(void)
813 762
814 763
815/* 764/*
816 * Reset the controller. 765 * Reset the controller and reset CRT to the original value set by BIOS.
817 */ 766 */
767
818static void i8042_controller_reset(void) 768static void i8042_controller_reset(void)
819{ 769{
820/* 770 i8042_flush();
821 * Reset the controller if requested.
822 */
823
824 i8042_ctl_test();
825 771
826/* 772/*
827 * Disable MUX mode if present. 773 * Disable MUX mode if present.
@@ -831,12 +777,16 @@ static void i8042_controller_reset(void)
831 i8042_set_mux_mode(0, NULL); 777 i8042_set_mux_mode(0, NULL);
832 778
833/* 779/*
834 * Restore the original control register setting. 780 * Reset the controller if requested.
835 */ 781 */
836 782
837 i8042_ctr = i8042_initial_ctr; 783 i8042_controller_selftest();
838 784
839 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) 785/*
786 * Restore the original control register setting.
787 */
788
789 if (i8042_command(&i8042_initial_ctr, I8042_CMD_CTL_WCTR))
840 printk(KERN_WARNING "i8042.c: Can't restore CTR.\n"); 790 printk(KERN_WARNING "i8042.c: Can't restore CTR.\n");
841} 791}
842 792
@@ -850,14 +800,12 @@ static void i8042_controller_cleanup(void)
850{ 800{
851 int i; 801 int i;
852 802
853 i8042_flush();
854
855/* 803/*
856 * Reset anything that is connected to the ports. 804 * Reset anything that is connected to the ports.
857 */ 805 */
858 806
859 for (i = 0; i < I8042_NUM_PORTS; i++) 807 for (i = 0; i < I8042_NUM_PORTS; i++)
860 if (i8042_ports[i].exists) 808 if (i8042_ports[i].serio)
861 serio_cleanup(i8042_ports[i].serio); 809 serio_cleanup(i8042_ports[i].serio);
862 810
863 i8042_controller_reset(); 811 i8042_controller_reset();
@@ -913,8 +861,7 @@ static long i8042_panic_blink(long count)
913 861
914static int i8042_suspend(struct platform_device *dev, pm_message_t state) 862static int i8042_suspend(struct platform_device *dev, pm_message_t state)
915{ 863{
916 del_timer_sync(&i8042_timer); 864 i8042_controller_cleanup();
917 i8042_controller_reset();
918 865
919 return 0; 866 return 0;
920} 867}
@@ -926,33 +873,39 @@ static int i8042_suspend(struct platform_device *dev, pm_message_t state)
926 873
927static int i8042_resume(struct platform_device *dev) 874static int i8042_resume(struct platform_device *dev)
928{ 875{
929 int i; 876 int error;
930 877
931 if (i8042_ctl_test()) 878 error = i8042_controller_check();
932 return -1; 879 if (error)
880 return error;
933 881
934 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) { 882 error = i8042_controller_selftest();
935 printk(KERN_ERR "i8042: Can't write CTR\n"); 883 if (error)
936 return -1; 884 return error;
937 }
938
939 if (i8042_mux_present)
940 if (i8042_set_mux_mode(1, NULL) || i8042_enable_mux_ports())
941 printk(KERN_WARNING "i8042: failed to resume active multiplexor, mouse won't work.\n");
942 885
943/* 886/*
944 * Activate all ports. 887 * Restore pre-resume CTR value and disable all ports
945 */ 888 */
946 889
947 for (i = 0; i < I8042_NUM_PORTS; i++) 890 i8042_ctr |= I8042_CTR_AUXDIS | I8042_CTR_KBDDIS;
948 i8042_activate_port(&i8042_ports[i]); 891 i8042_ctr &= ~(I8042_CTR_AUXINT | I8042_CTR_KBDINT);
892 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) {
893 printk(KERN_ERR "i8042: Can't write CTR to resume\n");
894 return -EIO;
895 }
949 896
950/* 897 if (i8042_mux_present) {
951 * Restart timer (for polling "stuck" data) 898 if (i8042_set_mux_mode(1, NULL) || i8042_enable_mux_ports())
952 */ 899 printk(KERN_WARNING
953 mod_timer(&i8042_timer, jiffies + I8042_POLL_PERIOD); 900 "i8042: failed to resume active multiplexor, "
901 "mouse won't work.\n");
902 } else if (i8042_ports[I8042_AUX_PORT_NO].serio)
903 i8042_enable_aux_port();
954 904
955 panic_blink = i8042_panic_blink; 905 if (i8042_ports[I8042_KBD_PORT_NO].serio)
906 i8042_enable_kbd_port();
907
908 i8042_interrupt(0, NULL, NULL);
956 909
957 return 0; 910 return 0;
958} 911}
@@ -978,24 +931,24 @@ static int __devinit i8042_create_kbd_port(void)
978 931
979 serio->id.type = i8042_direct ? SERIO_8042 : SERIO_8042_XL; 932 serio->id.type = i8042_direct ? SERIO_8042 : SERIO_8042_XL;
980 serio->write = i8042_dumbkbd ? NULL : i8042_kbd_write; 933 serio->write = i8042_dumbkbd ? NULL : i8042_kbd_write;
981 serio->open = i8042_open;
982 serio->close = i8042_close;
983 serio->start = i8042_start; 934 serio->start = i8042_start;
984 serio->stop = i8042_stop; 935 serio->stop = i8042_stop;
985 serio->port_data = port; 936 serio->port_data = port;
986 serio->dev.parent = &i8042_platform_device->dev; 937 serio->dev.parent = &i8042_platform_device->dev;
987 strlcpy(serio->name, "i8042 Kbd Port", sizeof(serio->name)); 938 strlcpy(serio->name, "i8042 KBD port", sizeof(serio->name));
988 strlcpy(serio->phys, I8042_KBD_PHYS_DESC, sizeof(serio->phys)); 939 strlcpy(serio->phys, I8042_KBD_PHYS_DESC, sizeof(serio->phys));
989 940
990 port->serio = serio; 941 port->serio = serio;
942 port->irq = I8042_KBD_IRQ;
991 943
992 return i8042_port_register(port); 944 return 0;
993} 945}
994 946
995static int __devinit i8042_create_aux_port(void) 947static int __devinit i8042_create_aux_port(int idx)
996{ 948{
997 struct serio *serio; 949 struct serio *serio;
998 struct i8042_port *port = &i8042_ports[I8042_AUX_PORT_NO]; 950 int port_no = idx < 0 ? I8042_AUX_PORT_NO : I8042_MUX_PORT_NO + idx;
951 struct i8042_port *port = &i8042_ports[port_no];
999 952
1000 serio = kzalloc(sizeof(struct serio), GFP_KERNEL); 953 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
1001 if (!serio) 954 if (!serio)
@@ -1003,111 +956,191 @@ static int __devinit i8042_create_aux_port(void)
1003 956
1004 serio->id.type = SERIO_8042; 957 serio->id.type = SERIO_8042;
1005 serio->write = i8042_aux_write; 958 serio->write = i8042_aux_write;
1006 serio->open = i8042_open;
1007 serio->close = i8042_close;
1008 serio->start = i8042_start; 959 serio->start = i8042_start;
1009 serio->stop = i8042_stop; 960 serio->stop = i8042_stop;
1010 serio->port_data = port; 961 serio->port_data = port;
1011 serio->dev.parent = &i8042_platform_device->dev; 962 serio->dev.parent = &i8042_platform_device->dev;
1012 strlcpy(serio->name, "i8042 Aux Port", sizeof(serio->name)); 963 if (idx < 0) {
1013 strlcpy(serio->phys, I8042_AUX_PHYS_DESC, sizeof(serio->phys)); 964 strlcpy(serio->name, "i8042 AUX port", sizeof(serio->name));
965 strlcpy(serio->phys, I8042_AUX_PHYS_DESC, sizeof(serio->phys));
966 } else {
967 snprintf(serio->name, sizeof(serio->name), "i8042 AUX%d port", idx);
968 snprintf(serio->phys, sizeof(serio->phys), I8042_MUX_PHYS_DESC, idx + 1);
969 }
1014 970
1015 port->serio = serio; 971 port->serio = serio;
972 port->mux = idx;
973 port->irq = I8042_AUX_IRQ;
1016 974
1017 return i8042_port_register(port); 975 return 0;
1018} 976}
1019 977
1020static int __devinit i8042_create_mux_port(int index) 978static void __devinit i8042_free_kbd_port(void)
1021{ 979{
1022 struct serio *serio; 980 kfree(i8042_ports[I8042_KBD_PORT_NO].serio);
1023 struct i8042_port *port = &i8042_ports[I8042_MUX_PORT_NO + index]; 981 i8042_ports[I8042_KBD_PORT_NO].serio = NULL;
982}
1024 983
1025 serio = kzalloc(sizeof(struct serio), GFP_KERNEL); 984static void __devinit i8042_free_aux_ports(void)
1026 if (!serio) 985{
1027 return -ENOMEM; 986 int i;
1028 987
1029 serio->id.type = SERIO_8042; 988 for (i = I8042_AUX_PORT_NO; i < I8042_NUM_PORTS; i++) {
1030 serio->write = i8042_aux_write; 989 kfree(i8042_ports[i].serio);
1031 serio->open = i8042_open; 990 i8042_ports[i].serio = NULL;
1032 serio->close = i8042_close; 991 }
1033 serio->start = i8042_start; 992}
1034 serio->stop = i8042_stop;
1035 serio->port_data = port;
1036 serio->dev.parent = &i8042_platform_device->dev;
1037 snprintf(serio->name, sizeof(serio->name), "i8042 Aux-%d Port", index);
1038 snprintf(serio->phys, sizeof(serio->phys), I8042_MUX_PHYS_DESC, index + 1);
1039 993
1040 *port = i8042_ports[I8042_AUX_PORT_NO]; 994static void __devinit i8042_register_ports(void)
1041 port->exists = 0; 995{
1042 snprintf(port->name, sizeof(port->name), "AUX%d", index); 996 int i;
1043 port->mux = index;
1044 port->serio = serio;
1045 997
1046 return i8042_port_register(port); 998 for (i = 0; i < I8042_NUM_PORTS; i++) {
999 if (i8042_ports[i].serio) {
1000 printk(KERN_INFO "serio: %s at %#lx,%#lx irq %d\n",
1001 i8042_ports[i].serio->name,
1002 (unsigned long) I8042_DATA_REG,
1003 (unsigned long) I8042_COMMAND_REG,
1004 i8042_ports[i].irq);
1005 serio_register_port(i8042_ports[i].serio);
1006 }
1007 }
1047} 1008}
1048 1009
1049static int __devinit i8042_probe(struct platform_device *dev) 1010static void __devinit i8042_unregister_ports(void)
1050{ 1011{
1051 int i, have_ports = 0; 1012 int i;
1052 int err;
1053 1013
1054 init_timer(&i8042_timer); 1014 for (i = 0; i < I8042_NUM_PORTS; i++) {
1055 i8042_timer.function = i8042_timer_func; 1015 if (i8042_ports[i].serio) {
1016 serio_unregister_port(i8042_ports[i].serio);
1017 i8042_ports[i].serio = NULL;
1018 }
1019 }
1020}
1021
1022static void i8042_free_irqs(void)
1023{
1024 if (i8042_aux_irq_registered)
1025 free_irq(I8042_AUX_IRQ, i8042_platform_device);
1026 if (i8042_kbd_irq_registered)
1027 free_irq(I8042_KBD_IRQ, i8042_platform_device);
1028
1029 i8042_aux_irq_registered = i8042_kbd_irq_registered = 0;
1030}
1031
1032static int __devinit i8042_setup_aux(void)
1033{
1034 int (*aux_enable)(void);
1035 int error;
1036 int i;
1056 1037
1057 if (i8042_controller_init()) 1038 if (i8042_check_aux())
1058 return -ENODEV; 1039 return -ENODEV;
1059 1040
1060 if (!i8042_noaux && !i8042_check_aux()) { 1041 if (i8042_nomux || i8042_check_mux()) {
1061 if (!i8042_nomux && !i8042_check_mux()) { 1042 error = i8042_create_aux_port(-1);
1062 for (i = 0; i < I8042_NUM_MUX_PORTS; i++) { 1043 if (error)
1063 err = i8042_create_mux_port(i); 1044 goto err_free_ports;
1064 if (err) 1045 aux_enable = i8042_enable_aux_port;
1065 goto err_unregister_ports; 1046 } else {
1066 } 1047 for (i = 0; i < I8042_NUM_MUX_PORTS; i++) {
1067 } else { 1048 error = i8042_create_aux_port(i);
1068 err = i8042_create_aux_port(); 1049 if (error)
1069 if (err) 1050 goto err_free_ports;
1070 goto err_unregister_ports;
1071 } 1051 }
1072 have_ports = 1; 1052 aux_enable = i8042_enable_mux_ports;
1073 } 1053 }
1074 1054
1075 if (!i8042_nokbd) { 1055 error = request_irq(I8042_AUX_IRQ, i8042_interrupt, IRQF_SHARED,
1076 err = i8042_create_kbd_port(); 1056 "i8042", i8042_platform_device);
1077 if (err) 1057 if (error)
1078 goto err_unregister_ports; 1058 goto err_free_ports;
1079 have_ports = 1;
1080 }
1081 1059
1082 if (!have_ports) { 1060 if (aux_enable())
1083 err = -ENODEV; 1061 goto err_free_irq;
1084 goto err_controller_cleanup;
1085 }
1086 1062
1087 mod_timer(&i8042_timer, jiffies + I8042_POLL_PERIOD); 1063 i8042_aux_irq_registered = 1;
1088 return 0; 1064 return 0;
1089 1065
1090 err_unregister_ports: 1066 err_free_irq:
1091 for (i = 0; i < I8042_NUM_PORTS; i++) 1067 free_irq(I8042_AUX_IRQ, i8042_platform_device);
1092 if (i8042_ports[i].serio) 1068 err_free_ports:
1093 serio_unregister_port(i8042_ports[i].serio); 1069 i8042_free_aux_ports();
1094 err_controller_cleanup: 1070 return error;
1095 i8042_controller_cleanup(); 1071}
1096 1072
1097 return err; 1073static int __devinit i8042_setup_kbd(void)
1074{
1075 int error;
1076
1077 error = i8042_create_kbd_port();
1078 if (error)
1079 return error;
1080
1081 error = request_irq(I8042_KBD_IRQ, i8042_interrupt, IRQF_SHARED,
1082 "i8042", i8042_platform_device);
1083 if (error)
1084 goto err_free_port;
1085
1086 error = i8042_enable_kbd_port();
1087 if (error)
1088 goto err_free_irq;
1089
1090 i8042_kbd_irq_registered = 1;
1091 return 0;
1092
1093 err_free_irq:
1094 free_irq(I8042_KBD_IRQ, i8042_platform_device);
1095 err_free_port:
1096 i8042_free_kbd_port();
1097 return error;
1098} 1098}
1099 1099
1100static int __devexit i8042_remove(struct platform_device *dev) 1100static int __devinit i8042_probe(struct platform_device *dev)
1101{ 1101{
1102 int i; 1102 int error;
1103 1103
1104 i8042_controller_cleanup(); 1104 error = i8042_controller_selftest();
1105 if (error)
1106 return error;
1105 1107
1106 for (i = 0; i < I8042_NUM_PORTS; i++) 1108 error = i8042_controller_init();
1107 if (i8042_ports[i].exists) 1109 if (error)
1108 serio_unregister_port(i8042_ports[i].serio); 1110 return error;
1111
1112 if (!i8042_noaux) {
1113 error = i8042_setup_aux();
1114 if (error && error != -ENODEV && error != -EBUSY)
1115 goto out_fail;
1116 }
1117
1118 if (!i8042_nokbd) {
1119 error = i8042_setup_kbd();
1120 if (error)
1121 goto out_fail;
1122 }
1109 1123
1110 del_timer_sync(&i8042_timer); 1124/*
1125 * Ok, everything is ready, let's register all serio ports
1126 */
1127 i8042_register_ports();
1128
1129 return 0;
1130
1131 out_fail:
1132 i8042_free_aux_ports(); /* in case KBD failed but AUX not */
1133 i8042_free_irqs();
1134 i8042_controller_reset();
1135
1136 return error;
1137}
1138
1139static int __devexit i8042_remove(struct platform_device *dev)
1140{
1141 i8042_unregister_ports();
1142 i8042_free_irqs();
1143 i8042_controller_reset();
1111 1144
1112 return 0; 1145 return 0;
1113} 1146}
@@ -1134,8 +1167,9 @@ static int __init i8042_init(void)
1134 if (err) 1167 if (err)
1135 return err; 1168 return err;
1136 1169
1137 i8042_ports[I8042_AUX_PORT_NO].irq = I8042_AUX_IRQ; 1170 err = i8042_controller_check();
1138 i8042_ports[I8042_KBD_PORT_NO].irq = I8042_KBD_IRQ; 1171 if (err)
1172 goto err_platform_exit;
1139 1173
1140 err = platform_driver_register(&i8042_driver); 1174 err = platform_driver_register(&i8042_driver);
1141 if (err) 1175 if (err)
@@ -1151,6 +1185,8 @@ static int __init i8042_init(void)
1151 if (err) 1185 if (err)
1152 goto err_free_device; 1186 goto err_free_device;
1153 1187
1188 panic_blink = i8042_panic_blink;
1189
1154 return 0; 1190 return 0;
1155 1191
1156 err_free_device: 1192 err_free_device:
@@ -1167,7 +1203,6 @@ static void __exit i8042_exit(void)
1167{ 1203{
1168 platform_device_unregister(i8042_platform_device); 1204 platform_device_unregister(i8042_platform_device);
1169 platform_driver_unregister(&i8042_driver); 1205 platform_driver_unregister(&i8042_driver);
1170
1171 i8042_platform_exit(); 1206 i8042_platform_exit();
1172 1207
1173 panic_blink = NULL; 1208 panic_blink = NULL;
diff --git a/drivers/input/serio/i8042.h b/drivers/input/serio/i8042.h
index af526ab9ec04..b3eb7a72d961 100644
--- a/drivers/input/serio/i8042.h
+++ b/drivers/input/serio/i8042.h
@@ -37,15 +37,6 @@
37#define I8042_CTL_TIMEOUT 10000 37#define I8042_CTL_TIMEOUT 10000
38 38
39/* 39/*
40 * When the device isn't opened and it's interrupts aren't used, we poll it at
41 * regular intervals to see if any characters arrived. If yes, we can start
42 * probing for any mouse / keyboard connected. This is the period of the
43 * polling.
44 */
45
46#define I8042_POLL_PERIOD HZ/20
47
48/*
49 * Status register bits. 40 * Status register bits.
50 */ 41 */
51 42
diff --git a/drivers/input/serio/libps2.c b/drivers/input/serio/libps2.c
index ed202f2f251a..dcb16b5cbec0 100644
--- a/drivers/input/serio/libps2.c
+++ b/drivers/input/serio/libps2.c
@@ -27,15 +27,6 @@ MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>");
27MODULE_DESCRIPTION("PS/2 driver library"); 27MODULE_DESCRIPTION("PS/2 driver library");
28MODULE_LICENSE("GPL"); 28MODULE_LICENSE("GPL");
29 29
30EXPORT_SYMBOL(ps2_init);
31EXPORT_SYMBOL(ps2_sendbyte);
32EXPORT_SYMBOL(ps2_drain);
33EXPORT_SYMBOL(ps2_command);
34EXPORT_SYMBOL(ps2_schedule_command);
35EXPORT_SYMBOL(ps2_handle_ack);
36EXPORT_SYMBOL(ps2_handle_response);
37EXPORT_SYMBOL(ps2_cmd_aborted);
38
39/* Work structure to schedule execution of a command */ 30/* Work structure to schedule execution of a command */
40struct ps2work { 31struct ps2work {
41 struct work_struct work; 32 struct work_struct work;
@@ -71,6 +62,7 @@ int ps2_sendbyte(struct ps2dev *ps2dev, unsigned char byte, int timeout)
71 62
72 return -ps2dev->nak; 63 return -ps2dev->nak;
73} 64}
65EXPORT_SYMBOL(ps2_sendbyte);
74 66
75/* 67/*
76 * ps2_drain() waits for device to transmit requested number of bytes 68 * ps2_drain() waits for device to transmit requested number of bytes
@@ -96,15 +88,16 @@ void ps2_drain(struct ps2dev *ps2dev, int maxbytes, int timeout)
96 msecs_to_jiffies(timeout)); 88 msecs_to_jiffies(timeout));
97 mutex_unlock(&ps2dev->cmd_mutex); 89 mutex_unlock(&ps2dev->cmd_mutex);
98} 90}
91EXPORT_SYMBOL(ps2_drain);
99 92
100/* 93/*
101 * ps2_is_keyboard_id() checks received ID byte against the list of 94 * ps2_is_keyboard_id() checks received ID byte against the list of
102 * known keyboard IDs. 95 * known keyboard IDs.
103 */ 96 */
104 97
105static inline int ps2_is_keyboard_id(char id_byte) 98int ps2_is_keyboard_id(char id_byte)
106{ 99{
107 static char keyboard_ids[] = { 100 const static char keyboard_ids[] = {
108 0xab, /* Regular keyboards */ 101 0xab, /* Regular keyboards */
109 0xac, /* NCD Sun keyboard */ 102 0xac, /* NCD Sun keyboard */
110 0x2b, /* Trust keyboard, translated */ 103 0x2b, /* Trust keyboard, translated */
@@ -115,6 +108,7 @@ static inline int ps2_is_keyboard_id(char id_byte)
115 108
116 return memchr(keyboard_ids, id_byte, sizeof(keyboard_ids)) != NULL; 109 return memchr(keyboard_ids, id_byte, sizeof(keyboard_ids)) != NULL;
117} 110}
111EXPORT_SYMBOL(ps2_is_keyboard_id);
118 112
119/* 113/*
120 * ps2_adjust_timeout() is called after receiving 1st byte of command 114 * ps2_adjust_timeout() is called after receiving 1st byte of command
@@ -139,6 +133,19 @@ static int ps2_adjust_timeout(struct ps2dev *ps2dev, int command, int timeout)
139 133
140 case PS2_CMD_GETID: 134 case PS2_CMD_GETID:
141 /* 135 /*
136 * Microsoft Natural Elite keyboard responds to
137 * the GET ID command as it were a mouse, with
138 * a single byte. Fail the command so atkbd will
139 * use alternative probe to detect it.
140 */
141 if (ps2dev->cmdbuf[1] == 0xaa) {
142 serio_pause_rx(ps2dev->serio);
143 ps2dev->flags = 0;
144 serio_continue_rx(ps2dev->serio);
145 timeout = 0;
146 }
147
148 /*
142 * If device behind the port is not a keyboard there 149 * If device behind the port is not a keyboard there
143 * won't be 2nd byte of ID response. 150 * won't be 2nd byte of ID response.
144 */ 151 */
@@ -237,6 +244,7 @@ int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command)
237 mutex_unlock(&ps2dev->cmd_mutex); 244 mutex_unlock(&ps2dev->cmd_mutex);
238 return rc; 245 return rc;
239} 246}
247EXPORT_SYMBOL(ps2_command);
240 248
241/* 249/*
242 * ps2_execute_scheduled_command() sends a command, previously scheduled by 250 * ps2_execute_scheduled_command() sends a command, previously scheduled by
@@ -279,6 +287,7 @@ int ps2_schedule_command(struct ps2dev *ps2dev, unsigned char *param, int comman
279 287
280 return 0; 288 return 0;
281} 289}
290EXPORT_SYMBOL(ps2_schedule_command);
282 291
283/* 292/*
284 * ps2_init() initializes ps2dev structure 293 * ps2_init() initializes ps2dev structure
@@ -290,6 +299,7 @@ void ps2_init(struct ps2dev *ps2dev, struct serio *serio)
290 init_waitqueue_head(&ps2dev->wait); 299 init_waitqueue_head(&ps2dev->wait);
291 ps2dev->serio = serio; 300 ps2dev->serio = serio;
292} 301}
302EXPORT_SYMBOL(ps2_init);
293 303
294/* 304/*
295 * ps2_handle_ack() is supposed to be used in interrupt handler 305 * ps2_handle_ack() is supposed to be used in interrupt handler
@@ -335,6 +345,7 @@ int ps2_handle_ack(struct ps2dev *ps2dev, unsigned char data)
335 345
336 return 1; 346 return 1;
337} 347}
348EXPORT_SYMBOL(ps2_handle_ack);
338 349
339/* 350/*
340 * ps2_handle_response() is supposed to be used in interrupt handler 351 * ps2_handle_response() is supposed to be used in interrupt handler
@@ -360,6 +371,7 @@ int ps2_handle_response(struct ps2dev *ps2dev, unsigned char data)
360 371
361 return 1; 372 return 1;
362} 373}
374EXPORT_SYMBOL(ps2_handle_response);
363 375
364void ps2_cmd_aborted(struct ps2dev *ps2dev) 376void ps2_cmd_aborted(struct ps2dev *ps2dev)
365{ 377{
@@ -371,4 +383,4 @@ void ps2_cmd_aborted(struct ps2dev *ps2dev)
371 383
372 ps2dev->flags = 0; 384 ps2dev->flags = 0;
373} 385}
374 386EXPORT_SYMBOL(ps2_cmd_aborted);
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index b1b14f8d4dd6..9418bbe47072 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -108,4 +108,40 @@ config TOUCHSCREEN_HP600
108 To compile this driver as a module, choose M here: the 108 To compile this driver as a module, choose M here: the
109 module will be called hp680_ts_input. 109 module will be called hp680_ts_input.
110 110
111config TOUCHSCREEN_PENMOUNT
112 tristate "Penmount serial touchscreen"
113 select SERIO
114 help
115 Say Y here if you have a Penmount serial touchscreen connected to
116 your system.
117
118 If unsure, say N.
119
120 To compile this driver as a module, choose M here: the
121 module will be called penmount.
122
123config TOUCHSCREEN_TOUCHRIGHT
124 tristate "Touchright serial touchscreen"
125 select SERIO
126 help
127 Say Y here if you have a Touchright serial touchscreen connected to
128 your system.
129
130 If unsure, say N.
131
132 To compile this driver as a module, choose M here: the
133 module will be called touchright.
134
135config TOUCHSCREEN_TOUCHWIN
136 tristate "Touchwin serial touchscreen"
137 select SERIO
138 help
139 Say Y here if you have a Touchwin serial touchscreen connected to
140 your system.
141
142 If unsure, say N.
143
144 To compile this driver as a module, choose M here: the
145 module will be called touchwin.
146
111endif 147endif
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 5e5557c43121..1abb8f10d608 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -12,3 +12,6 @@ obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o
12obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o 12obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o
13obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o 13obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o
14obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o 14obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o
15obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o
16obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
17obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o
diff --git a/drivers/input/touchscreen/elo.c b/drivers/input/touchscreen/elo.c
index c86a2eb310fd..ab565335ee44 100644
--- a/drivers/input/touchscreen/elo.c
+++ b/drivers/input/touchscreen/elo.c
@@ -23,6 +23,7 @@
23#include <linux/input.h> 23#include <linux/input.h>
24#include <linux/serio.h> 24#include <linux/serio.h>
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/ctype.h>
26 27
27#define DRIVER_DESC "Elo serial touchscreen driver" 28#define DRIVER_DESC "Elo serial touchscreen driver"
28 29
@@ -34,7 +35,19 @@ MODULE_LICENSE("GPL");
34 * Definitions & global arrays. 35 * Definitions & global arrays.
35 */ 36 */
36 37
37#define ELO_MAX_LENGTH 10 38#define ELO_MAX_LENGTH 10
39
40#define ELO10_PACKET_LEN 8
41#define ELO10_TOUCH 0x03
42#define ELO10_PRESSURE 0x80
43
44#define ELO10_LEAD_BYTE 'U'
45
46#define ELO10_ID_CMD 'i'
47
48#define ELO10_TOUCH_PACKET 'T'
49#define ELO10_ACK_PACKET 'A'
50#define ELI10_ID_PACKET 'I'
38 51
39/* 52/*
40 * Per-touchscreen data. 53 * Per-touchscreen data.
@@ -43,51 +56,67 @@ MODULE_LICENSE("GPL");
43struct elo { 56struct elo {
44 struct input_dev *dev; 57 struct input_dev *dev;
45 struct serio *serio; 58 struct serio *serio;
59 struct mutex cmd_mutex;
60 struct completion cmd_done;
46 int id; 61 int id;
47 int idx; 62 int idx;
63 unsigned char expected_packet;
48 unsigned char csum; 64 unsigned char csum;
49 unsigned char data[ELO_MAX_LENGTH]; 65 unsigned char data[ELO_MAX_LENGTH];
66 unsigned char response[ELO10_PACKET_LEN];
50 char phys[32]; 67 char phys[32];
51}; 68};
52 69
53static void elo_process_data_10(struct elo* elo, unsigned char data, struct pt_regs *regs) 70static void elo_process_data_10(struct elo *elo, unsigned char data, struct pt_regs *regs)
54{ 71{
55 struct input_dev *dev = elo->dev; 72 struct input_dev *dev = elo->dev;
56 73
57 elo->csum += elo->data[elo->idx] = data; 74 elo->data[elo->idx] = data;
58
59 switch (elo->idx++) { 75 switch (elo->idx++) {
60
61 case 0: 76 case 0:
62 if (data != 'U') { 77 elo->csum = 0xaa;
78 if (data != ELO10_LEAD_BYTE) {
79 pr_debug("elo: unsynchronized data: 0x%02x\n", data);
63 elo->idx = 0; 80 elo->idx = 0;
64 elo->csum = 0;
65 }
66 break;
67
68 case 1:
69 if (data != 'T') {
70 elo->idx = 0;
71 elo->csum = 0;
72 } 81 }
73 break; 82 break;
74 83
75 case 9: 84 case 9:
76 if (elo->csum) { 85 elo->idx = 0;
86 if (data != elo->csum) {
87 pr_debug("elo: bad checksum: 0x%02x, expected 0x%02x\n",
88 data, elo->csum);
89 break;
90 }
91 if (elo->data[1] != elo->expected_packet) {
92 if (elo->data[1] != ELO10_TOUCH_PACKET)
93 pr_debug("elo: unexpected packet: 0x%02x\n",
94 elo->data[1]);
95 break;
96 }
97 if (likely(elo->data[1] == ELO10_TOUCH_PACKET)) {
77 input_regs(dev, regs); 98 input_regs(dev, regs);
78 input_report_abs(dev, ABS_X, (elo->data[4] << 8) | elo->data[3]); 99 input_report_abs(dev, ABS_X, (elo->data[4] << 8) | elo->data[3]);
79 input_report_abs(dev, ABS_Y, (elo->data[6] << 8) | elo->data[5]); 100 input_report_abs(dev, ABS_Y, (elo->data[6] << 8) | elo->data[5]);
80 input_report_abs(dev, ABS_PRESSURE, (elo->data[8] << 8) | elo->data[7]); 101 if (elo->data[2] & ELO10_PRESSURE)
81 input_report_key(dev, BTN_TOUCH, elo->data[8] || elo->data[7]); 102 input_report_abs(dev, ABS_PRESSURE,
103 (elo->data[8] << 8) | elo->data[7]);
104 input_report_key(dev, BTN_TOUCH, elo->data[2] & ELO10_TOUCH);
82 input_sync(dev); 105 input_sync(dev);
106 } else if (elo->data[1] == ELO10_ACK_PACKET) {
107 if (elo->data[2] == '0')
108 elo->expected_packet = ELO10_TOUCH_PACKET;
109 complete(&elo->cmd_done);
110 } else {
111 memcpy(elo->response, &elo->data[1], ELO10_PACKET_LEN);
112 elo->expected_packet = ELO10_ACK_PACKET;
83 } 113 }
84 elo->idx = 0;
85 elo->csum = 0;
86 break; 114 break;
87 } 115 }
116 elo->csum += data;
88} 117}
89 118
90static void elo_process_data_6(struct elo* elo, unsigned char data, struct pt_regs *regs) 119static void elo_process_data_6(struct elo *elo, unsigned char data, struct pt_regs *regs)
91{ 120{
92 struct input_dev *dev = elo->dev; 121 struct input_dev *dev = elo->dev;
93 122
@@ -135,7 +164,7 @@ static void elo_process_data_6(struct elo* elo, unsigned char data, struct pt_re
135 } 164 }
136} 165}
137 166
138static void elo_process_data_3(struct elo* elo, unsigned char data, struct pt_regs *regs) 167static void elo_process_data_3(struct elo *elo, unsigned char data, struct pt_regs *regs)
139{ 168{
140 struct input_dev *dev = elo->dev; 169 struct input_dev *dev = elo->dev;
141 170
@@ -161,7 +190,7 @@ static void elo_process_data_3(struct elo* elo, unsigned char data, struct pt_re
161static irqreturn_t elo_interrupt(struct serio *serio, 190static irqreturn_t elo_interrupt(struct serio *serio,
162 unsigned char data, unsigned int flags, struct pt_regs *regs) 191 unsigned char data, unsigned int flags, struct pt_regs *regs)
163{ 192{
164 struct elo* elo = serio_get_drvdata(serio); 193 struct elo *elo = serio_get_drvdata(serio);
165 194
166 switch(elo->id) { 195 switch(elo->id) {
167 case 0: 196 case 0:
@@ -181,17 +210,81 @@ static irqreturn_t elo_interrupt(struct serio *serio,
181 return IRQ_HANDLED; 210 return IRQ_HANDLED;
182} 211}
183 212
213static int elo_command_10(struct elo *elo, unsigned char *packet)
214{
215 int rc = -1;
216 int i;
217 unsigned char csum = 0xaa + ELO10_LEAD_BYTE;
218
219 mutex_lock(&elo->cmd_mutex);
220
221 serio_pause_rx(elo->serio);
222 elo->expected_packet = toupper(packet[0]);
223 init_completion(&elo->cmd_done);
224 serio_continue_rx(elo->serio);
225
226 if (serio_write(elo->serio, ELO10_LEAD_BYTE))
227 goto out;
228
229 for (i = 0; i < ELO10_PACKET_LEN; i++) {
230 csum += packet[i];
231 if (serio_write(elo->serio, packet[i]))
232 goto out;
233 }
234
235 if (serio_write(elo->serio, csum))
236 goto out;
237
238 wait_for_completion_timeout(&elo->cmd_done, HZ);
239
240 if (elo->expected_packet == ELO10_TOUCH_PACKET) {
241 /* We are back in reporting mode, the command was ACKed */
242 memcpy(packet, elo->response, ELO10_PACKET_LEN);
243 rc = 0;
244 }
245
246 out:
247 mutex_unlock(&elo->cmd_mutex);
248 return rc;
249}
250
251static int elo_setup_10(struct elo *elo)
252{
253 static const char *elo_types[] = { "Accu", "Dura", "Intelli", "Carroll" };
254 struct input_dev *dev = elo->dev;
255 unsigned char packet[ELO10_PACKET_LEN] = { ELO10_ID_CMD };
256
257 if (elo_command_10(elo, packet))
258 return -1;
259
260 dev->id.version = (packet[5] << 8) | packet[4];
261
262 input_set_abs_params(dev, ABS_X, 96, 4000, 0, 0);
263 input_set_abs_params(dev, ABS_Y, 96, 4000, 0, 0);
264 if (packet[3] & ELO10_PRESSURE)
265 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
266
267 printk(KERN_INFO "elo: %sTouch touchscreen, fw: %02x.%02x, "
268 "features: %x02x, controller: 0x%02x\n",
269 elo_types[(packet[1] -'0') & 0x03],
270 packet[5], packet[4], packet[3], packet[7]);
271
272 return 0;
273}
274
184/* 275/*
185 * elo_disconnect() is the opposite of elo_connect() 276 * elo_disconnect() is the opposite of elo_connect()
186 */ 277 */
187 278
188static void elo_disconnect(struct serio *serio) 279static void elo_disconnect(struct serio *serio)
189{ 280{
190 struct elo* elo = serio_get_drvdata(serio); 281 struct elo *elo = serio_get_drvdata(serio);
191 282
283 input_get_device(elo->dev);
192 input_unregister_device(elo->dev); 284 input_unregister_device(elo->dev);
193 serio_close(serio); 285 serio_close(serio);
194 serio_set_drvdata(serio, NULL); 286 serio_set_drvdata(serio, NULL);
287 input_put_device(elo->dev);
195 kfree(elo); 288 kfree(elo);
196} 289}
197 290
@@ -211,12 +304,15 @@ static int elo_connect(struct serio *serio, struct serio_driver *drv)
211 input_dev = input_allocate_device(); 304 input_dev = input_allocate_device();
212 if (!elo || !input_dev) { 305 if (!elo || !input_dev) {
213 err = -ENOMEM; 306 err = -ENOMEM;
214 goto fail; 307 goto fail1;
215 } 308 }
216 309
217 elo->serio = serio; 310 elo->serio = serio;
218 elo->id = serio->id.id; 311 elo->id = serio->id.id;
219 elo->dev = input_dev; 312 elo->dev = input_dev;
313 elo->expected_packet = ELO10_TOUCH_PACKET;
314 mutex_init(&elo->cmd_mutex);
315 init_completion(&elo->cmd_done);
220 snprintf(elo->phys, sizeof(elo->phys), "%s/input0", serio->phys); 316 snprintf(elo->phys, sizeof(elo->phys), "%s/input0", serio->phys);
221 317
222 input_dev->private = elo; 318 input_dev->private = elo;
@@ -231,12 +327,17 @@ static int elo_connect(struct serio *serio, struct serio_driver *drv)
231 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 327 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
232 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 328 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
233 329
330 serio_set_drvdata(serio, elo);
331 err = serio_open(serio, drv);
332 if (err)
333 goto fail2;
334
234 switch (elo->id) { 335 switch (elo->id) {
235 336
236 case 0: /* 10-byte protocol */ 337 case 0: /* 10-byte protocol */
237 input_set_abs_params(input_dev, ABS_X, 96, 4000, 0, 0); 338 if (elo_setup_10(elo))
238 input_set_abs_params(input_dev, ABS_Y, 96, 4000, 0, 0); 339 goto fail3;
239 input_set_abs_params(input_dev, ABS_PRESSURE, 0, 255, 0, 0); 340
240 break; 341 break;
241 342
242 case 1: /* 6-byte protocol */ 343 case 1: /* 6-byte protocol */
@@ -253,17 +354,15 @@ static int elo_connect(struct serio *serio, struct serio_driver *drv)
253 break; 354 break;
254 } 355 }
255 356
256 serio_set_drvdata(serio, elo); 357 err = input_register_device(elo->dev);
257
258 err = serio_open(serio, drv);
259 if (err) 358 if (err)
260 goto fail; 359 goto fail3;
261 360
262 input_register_device(elo->dev);
263 return 0; 361 return 0;
264 362
265 fail: serio_set_drvdata(serio, NULL); 363 fail3: serio_close(serio);
266 input_free_device(input_dev); 364 fail2: serio_set_drvdata(serio, NULL);
365 fail1: input_free_device(input_dev);
267 kfree(elo); 366 kfree(elo);
268 return err; 367 return err;
269} 368}
diff --git a/drivers/input/touchscreen/hp680_ts_input.c b/drivers/input/touchscreen/hp680_ts_input.c
index fa97e0f79e7e..ee6c2f40cdf6 100644
--- a/drivers/input/touchscreen/hp680_ts_input.c
+++ b/drivers/input/touchscreen/hp680_ts_input.c
@@ -15,7 +15,6 @@
15#define HP680_TS_ABS_Y_MIN 80 15#define HP680_TS_ABS_Y_MIN 80
16#define HP680_TS_ABS_Y_MAX 910 16#define HP680_TS_ABS_Y_MAX 910
17 17
18#define SCPCR 0xa4000116
19#define PHDR 0xa400012e 18#define PHDR 0xa400012e
20#define SCPDR 0xa4000136 19#define SCPDR 0xa4000136
21 20
@@ -77,19 +76,6 @@ static irqreturn_t hp680_ts_interrupt(int irq, void *dev, struct pt_regs *regs)
77 76
78static int __init hp680_ts_init(void) 77static int __init hp680_ts_init(void)
79{ 78{
80 u8 scpdr;
81 u16 scpcr;
82
83 scpdr = ctrl_inb(SCPDR);
84 scpdr |= SCPDR_TS_SCAN_X | SCPDR_TS_SCAN_Y;
85 scpdr &= ~SCPDR_TS_SCAN_ENABLE;
86 ctrl_outb(scpdr, SCPDR);
87
88 scpcr = ctrl_inw(SCPCR);
89 scpcr &= ~SCPCR_TS_MASK;
90 scpcr |= SCPCR_TS_ENABLE;
91 ctrl_outw(scpcr, SCPCR);
92
93 hp680_ts_dev = input_allocate_device(); 79 hp680_ts_dev = input_allocate_device();
94 if (!hp680_ts_dev) 80 if (!hp680_ts_dev)
95 return -ENOMEM; 81 return -ENOMEM;
diff --git a/drivers/input/touchscreen/penmount.c b/drivers/input/touchscreen/penmount.c
new file mode 100644
index 000000000000..f7370109d43e
--- /dev/null
+++ b/drivers/input/touchscreen/penmount.c
@@ -0,0 +1,185 @@
1/*
2 * Penmount serial touchscreen driver
3 *
4 * Copyright (c) 2006 Rick Koch <n1gp@hotmail.com>
5 *
6 * Based on ELO driver (drivers/input/touchscreen/elo.c)
7 * Copyright (c) 2004 Vojtech Pavlik
8 */
9
10/*
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 as published
13 * by the Free Software Foundation.
14 */
15
16#include <linux/errno.h>
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/slab.h>
20#include <linux/input.h>
21#include <linux/serio.h>
22#include <linux/init.h>
23
24#define DRIVER_DESC "Penmount serial touchscreen driver"
25
26MODULE_AUTHOR("Rick Koch <n1gp@hotmail.com>");
27MODULE_DESCRIPTION(DRIVER_DESC);
28MODULE_LICENSE("GPL");
29
30/*
31 * Definitions & global arrays.
32 */
33
34#define PM_MAX_LENGTH 5
35
36/*
37 * Per-touchscreen data.
38 */
39
40struct pm {
41 struct input_dev *dev;
42 struct serio *serio;
43 int idx;
44 unsigned char data[PM_MAX_LENGTH];
45 char phys[32];
46};
47
48static irqreturn_t pm_interrupt(struct serio *serio,
49 unsigned char data, unsigned int flags, struct pt_regs *regs)
50{
51 struct pm *pm = serio_get_drvdata(serio);
52 struct input_dev *dev = pm->dev;
53
54 pm->data[pm->idx] = data;
55
56 if (pm->data[0] & 0x80) {
57 if (PM_MAX_LENGTH == ++pm->idx) {
58 input_regs(dev, regs);
59 input_report_abs(dev, ABS_X, pm->data[2] * 128 + pm->data[1]);
60 input_report_abs(dev, ABS_Y, pm->data[4] * 128 + pm->data[3]);
61 input_report_key(dev, BTN_TOUCH, !!(pm->data[0] & 0x40));
62 input_sync(dev);
63 pm->idx = 0;
64 }
65 }
66
67 return IRQ_HANDLED;
68}
69
70/*
71 * pm_disconnect() is the opposite of pm_connect()
72 */
73
74static void pm_disconnect(struct serio *serio)
75{
76 struct pm *pm = serio_get_drvdata(serio);
77
78 input_get_device(pm->dev);
79 input_unregister_device(pm->dev);
80 serio_close(serio);
81 serio_set_drvdata(serio, NULL);
82 input_put_device(pm->dev);
83 kfree(pm);
84}
85
86/*
87 * pm_connect() is the routine that is called when someone adds a
88 * new serio device that supports Gunze protocol and registers it as
89 * an input device.
90 */
91
92static int pm_connect(struct serio *serio, struct serio_driver *drv)
93{
94 struct pm *pm;
95 struct input_dev *input_dev;
96 int err;
97
98 pm = kzalloc(sizeof(struct pm), GFP_KERNEL);
99 input_dev = input_allocate_device();
100 if (!pm || !input_dev) {
101 err = -ENOMEM;
102 goto fail1;
103 }
104
105 pm->serio = serio;
106 pm->dev = input_dev;
107 snprintf(pm->phys, sizeof(pm->phys), "%s/input0", serio->phys);
108
109 input_dev->private = pm;
110 input_dev->name = "Penmount Serial TouchScreen";
111 input_dev->phys = pm->phys;
112 input_dev->id.bustype = BUS_RS232;
113 input_dev->id.vendor = SERIO_PENMOUNT;
114 input_dev->id.product = 0;
115 input_dev->id.version = 0x0100;
116 input_dev->cdev.dev = &serio->dev;
117
118 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
119 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
120 input_set_abs_params(pm->dev, ABS_X, 0, 0x3ff, 0, 0);
121 input_set_abs_params(pm->dev, ABS_Y, 0, 0x3ff, 0, 0);
122
123 serio_set_drvdata(serio, pm);
124
125 err = serio_open(serio, drv);
126 if (err)
127 goto fail2;
128
129 err = input_register_device(pm->dev);
130 if (err)
131 goto fail3;
132
133 return 0;
134
135 fail3: serio_close(serio);
136 fail2: serio_set_drvdata(serio, NULL);
137 fail1: input_free_device(input_dev);
138 kfree(pm);
139 return err;
140}
141
142/*
143 * The serio driver structure.
144 */
145
146static struct serio_device_id pm_serio_ids[] = {
147 {
148 .type = SERIO_RS232,
149 .proto = SERIO_PENMOUNT,
150 .id = SERIO_ANY,
151 .extra = SERIO_ANY,
152 },
153 { 0 }
154};
155
156MODULE_DEVICE_TABLE(serio, pm_serio_ids);
157
158static struct serio_driver pm_drv = {
159 .driver = {
160 .name = "penmountlpc",
161 },
162 .description = DRIVER_DESC,
163 .id_table = pm_serio_ids,
164 .interrupt = pm_interrupt,
165 .connect = pm_connect,
166 .disconnect = pm_disconnect,
167};
168
169/*
170 * The functions for inserting/removing us as a module.
171 */
172
173static int __init pm_init(void)
174{
175 serio_register_driver(&pm_drv);
176 return 0;
177}
178
179static void __exit pm_exit(void)
180{
181 serio_unregister_driver(&pm_drv);
182}
183
184module_init(pm_init);
185module_exit(pm_exit);
diff --git a/drivers/input/touchscreen/touchright.c b/drivers/input/touchscreen/touchright.c
new file mode 100644
index 000000000000..1c89fa538651
--- /dev/null
+++ b/drivers/input/touchscreen/touchright.c
@@ -0,0 +1,196 @@
1/*
2 * Touchright serial touchscreen driver
3 *
4 * Copyright (c) 2006 Rick Koch <n1gp@hotmail.com>
5 *
6 * Based on MicroTouch driver (drivers/input/touchscreen/mtouch.c)
7 * Copyright (c) 2004 Vojtech Pavlik
8 * and Dan Streetman <ddstreet@ieee.org>
9 */
10
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 version 2 as published
14 * by the Free Software Foundation.
15 */
16
17#include <linux/errno.h>
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/slab.h>
21#include <linux/input.h>
22#include <linux/serio.h>
23#include <linux/init.h>
24
25#define DRIVER_DESC "Touchright serial touchscreen driver"
26
27MODULE_AUTHOR("Rick Koch <n1gp@hotmail.com>");
28MODULE_DESCRIPTION(DRIVER_DESC);
29MODULE_LICENSE("GPL");
30
31/*
32 * Definitions & global arrays.
33 */
34
35#define TR_FORMAT_TOUCH_BIT 0x01
36#define TR_FORMAT_STATUS_BYTE 0x40
37#define TR_FORMAT_STATUS_MASK ~TR_FORMAT_TOUCH_BIT
38
39#define TR_LENGTH 5
40
41#define TR_MIN_XC 0
42#define TR_MAX_XC 0x1ff
43#define TR_MIN_YC 0
44#define TR_MAX_YC 0x1ff
45
46/*
47 * Per-touchscreen data.
48 */
49
50struct tr {
51 struct input_dev *dev;
52 struct serio *serio;
53 int idx;
54 unsigned char data[TR_LENGTH];
55 char phys[32];
56};
57
58static irqreturn_t tr_interrupt(struct serio *serio,
59 unsigned char data, unsigned int flags, struct pt_regs *regs)
60{
61 struct tr *tr = serio_get_drvdata(serio);
62 struct input_dev *dev = tr->dev;
63
64 tr->data[tr->idx] = data;
65
66 if ((tr->data[0] & TR_FORMAT_STATUS_MASK) == TR_FORMAT_STATUS_BYTE) {
67 if (++tr->idx == TR_LENGTH) {
68 input_regs(dev, regs);
69 input_report_abs(dev, ABS_X,
70 (tr->data[1] << 5) | (tr->data[2] >> 1));
71 input_report_abs(dev, ABS_Y,
72 (tr->data[3] << 5) | (tr->data[4] >> 1));
73 input_report_key(dev, BTN_TOUCH,
74 tr->data[0] & TR_FORMAT_TOUCH_BIT);
75 input_sync(dev);
76 tr->idx = 0;
77 }
78 }
79
80 return IRQ_HANDLED;
81}
82
83/*
84 * tr_disconnect() is the opposite of tr_connect()
85 */
86
87static void tr_disconnect(struct serio *serio)
88{
89 struct tr *tr = serio_get_drvdata(serio);
90
91 input_get_device(tr->dev);
92 input_unregister_device(tr->dev);
93 serio_close(serio);
94 serio_set_drvdata(serio, NULL);
95 input_put_device(tr->dev);
96 kfree(tr);
97}
98
99/*
100 * tr_connect() is the routine that is called when someone adds a
101 * new serio device that supports the Touchright protocol and registers it as
102 * an input device.
103 */
104
105static int tr_connect(struct serio *serio, struct serio_driver *drv)
106{
107 struct tr *tr;
108 struct input_dev *input_dev;
109 int err;
110
111 tr = kzalloc(sizeof(struct tr), GFP_KERNEL);
112 input_dev = input_allocate_device();
113 if (!tr || !input_dev) {
114 err = -ENOMEM;
115 goto fail1;
116 }
117
118 tr->serio = serio;
119 tr->dev = input_dev;
120 snprintf(tr->phys, sizeof(tr->phys), "%s/input0", serio->phys);
121
122 input_dev->private = tr;
123 input_dev->name = "Touchright Serial TouchScreen";
124 input_dev->phys = tr->phys;
125 input_dev->id.bustype = BUS_RS232;
126 input_dev->id.vendor = SERIO_TOUCHRIGHT;
127 input_dev->id.product = 0;
128 input_dev->id.version = 0x0100;
129 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
130 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
131 input_set_abs_params(tr->dev, ABS_X, TR_MIN_XC, TR_MAX_XC, 0, 0);
132 input_set_abs_params(tr->dev, ABS_Y, TR_MIN_YC, TR_MAX_YC, 0, 0);
133
134 serio_set_drvdata(serio, tr);
135
136 err = serio_open(serio, drv);
137 if (err)
138 goto fail2;
139
140 err = input_register_device(tr->dev);
141 if (err)
142 goto fail3;
143
144 return 0;
145
146 fail3: serio_close(serio);
147 fail2: serio_set_drvdata(serio, NULL);
148 fail1: input_free_device(input_dev);
149 kfree(tr);
150 return err;
151}
152
153/*
154 * The serio driver structure.
155 */
156
157static struct serio_device_id tr_serio_ids[] = {
158 {
159 .type = SERIO_RS232,
160 .proto = SERIO_TOUCHRIGHT,
161 .id = SERIO_ANY,
162 .extra = SERIO_ANY,
163 },
164 { 0 }
165};
166
167MODULE_DEVICE_TABLE(serio, tr_serio_ids);
168
169static struct serio_driver tr_drv = {
170 .driver = {
171 .name = "touchright",
172 },
173 .description = DRIVER_DESC,
174 .id_table = tr_serio_ids,
175 .interrupt = tr_interrupt,
176 .connect = tr_connect,
177 .disconnect = tr_disconnect,
178};
179
180/*
181 * The functions for inserting/removing us as a module.
182 */
183
184static int __init tr_init(void)
185{
186 serio_register_driver(&tr_drv);
187 return 0;
188}
189
190static void __exit tr_exit(void)
191{
192 serio_unregister_driver(&tr_drv);
193}
194
195module_init(tr_init);
196module_exit(tr_exit);
diff --git a/drivers/input/touchscreen/touchwin.c b/drivers/input/touchscreen/touchwin.c
new file mode 100644
index 000000000000..a7b4c755958e
--- /dev/null
+++ b/drivers/input/touchscreen/touchwin.c
@@ -0,0 +1,203 @@
1/*
2 * Touchwindow serial touchscreen driver
3 *
4 * Copyright (c) 2006 Rick Koch <n1gp@hotmail.com>
5 *
6 * Based on MicroTouch driver (drivers/input/touchscreen/mtouch.c)
7 * Copyright (c) 2004 Vojtech Pavlik
8 * and Dan Streetman <ddstreet@ieee.org>
9 */
10
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 version 2 as published
14 * by the Free Software Foundation.
15 */
16
17/*
18 * 2005/02/19 Rick Koch:
19 * The Touchwindow I used is made by Edmark Corp. and
20 * constantly outputs a stream of 0's unless it is touched.
21 * It then outputs 3 bytes: X, Y, and a copy of Y.
22 */
23
24#include <linux/errno.h>
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/slab.h>
28#include <linux/input.h>
29#include <linux/serio.h>
30#include <linux/init.h>
31
32#define DRIVER_DESC "Touchwindow serial touchscreen driver"
33
34MODULE_AUTHOR("Rick Koch <n1gp@hotmail.com>");
35MODULE_DESCRIPTION(DRIVER_DESC);
36MODULE_LICENSE("GPL");
37
38/*
39 * Definitions & global arrays.
40 */
41
42#define TW_LENGTH 3
43
44#define TW_MIN_XC 0
45#define TW_MAX_XC 0xff
46#define TW_MIN_YC 0
47#define TW_MAX_YC 0xff
48
49/*
50 * Per-touchscreen data.
51 */
52
53struct tw {
54 struct input_dev *dev;
55 struct serio *serio;
56 int idx;
57 int touched;
58 unsigned char data[TW_LENGTH];
59 char phys[32];
60};
61
62static irqreturn_t tw_interrupt(struct serio *serio,
63 unsigned char data, unsigned int flags, struct pt_regs *regs)
64{
65 struct tw *tw = serio_get_drvdata(serio);
66 struct input_dev *dev = tw->dev;
67
68 if (data) { /* touch */
69 tw->touched = 1;
70 tw->data[tw->idx++] = data;
71 /* verify length and that the two Y's are the same */
72 if (tw->idx == TW_LENGTH && tw->data[1] == tw->data[2]) {
73 input_regs(dev, regs);
74 input_report_abs(dev, ABS_X, tw->data[0]);
75 input_report_abs(dev, ABS_Y, tw->data[1]);
76 input_report_key(dev, BTN_TOUCH, 1);
77 input_sync(dev);
78 tw->idx = 0;
79 }
80 } else if (tw->touched) { /* untouch */
81 input_report_key(dev, BTN_TOUCH, 0);
82 input_sync(dev);
83 tw->idx = 0;
84 tw->touched = 0;
85 }
86
87 return IRQ_HANDLED;
88}
89
90/*
91 * tw_disconnect() is the opposite of tw_connect()
92 */
93
94static void tw_disconnect(struct serio *serio)
95{
96 struct tw *tw = serio_get_drvdata(serio);
97
98 input_get_device(tw->dev);
99 input_unregister_device(tw->dev);
100 serio_close(serio);
101 serio_set_drvdata(serio, NULL);
102 input_put_device(tw->dev);
103 kfree(tw);
104}
105
106/*
107 * tw_connect() is the routine that is called when someone adds a
108 * new serio device that supports the Touchwin protocol and registers it as
109 * an input device.
110 */
111
112static int tw_connect(struct serio *serio, struct serio_driver *drv)
113{
114 struct tw *tw;
115 struct input_dev *input_dev;
116 int err;
117
118 tw = kzalloc(sizeof(struct tw), GFP_KERNEL);
119 input_dev = input_allocate_device();
120 if (!tw || !input_dev) {
121 err = -ENOMEM;
122 goto fail1;
123 }
124
125 tw->serio = serio;
126 tw->dev = input_dev;
127 snprintf(tw->phys, sizeof(tw->phys), "%s/input0", serio->phys);
128
129 input_dev->private = tw;
130 input_dev->name = "Touchwindow Serial TouchScreen";
131 input_dev->phys = tw->phys;
132 input_dev->id.bustype = BUS_RS232;
133 input_dev->id.vendor = SERIO_TOUCHWIN;
134 input_dev->id.product = 0;
135 input_dev->id.version = 0x0100;
136 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
137 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
138 input_set_abs_params(tw->dev, ABS_X, TW_MIN_XC, TW_MAX_XC, 0, 0);
139 input_set_abs_params(tw->dev, ABS_Y, TW_MIN_YC, TW_MAX_YC, 0, 0);
140
141 serio_set_drvdata(serio, tw);
142
143 err = serio_open(serio, drv);
144 if (err)
145 goto fail2;
146
147 err = input_register_device(tw->dev);
148 if (err)
149 goto fail3;
150
151 return 0;
152
153 fail3: serio_close(serio);
154 fail2: serio_set_drvdata(serio, NULL);
155 fail1: input_free_device(input_dev);
156 kfree(tw);
157 return err;
158}
159
160/*
161 * The serio driver structure.
162 */
163
164static struct serio_device_id tw_serio_ids[] = {
165 {
166 .type = SERIO_RS232,
167 .proto = SERIO_TOUCHWIN,
168 .id = SERIO_ANY,
169 .extra = SERIO_ANY,
170 },
171 { 0 }
172};
173
174MODULE_DEVICE_TABLE(serio, tw_serio_ids);
175
176static struct serio_driver tw_drv = {
177 .driver = {
178 .name = "touchwin",
179 },
180 .description = DRIVER_DESC,
181 .id_table = tw_serio_ids,
182 .interrupt = tw_interrupt,
183 .connect = tw_connect,
184 .disconnect = tw_disconnect,
185};
186
187/*
188 * The functions for inserting/removing us as a module.
189 */
190
191static int __init tw_init(void)
192{
193 serio_register_driver(&tw_drv);
194 return 0;
195}
196
197static void __exit tw_exit(void)
198{
199 serio_unregister_driver(&tw_drv);
200}
201
202module_init(tw_init);
203module_exit(tw_exit);
diff --git a/drivers/input/tsdev.c b/drivers/input/tsdev.c
index 00e3929c6288..a730c461227f 100644
--- a/drivers/input/tsdev.c
+++ b/drivers/input/tsdev.c
@@ -135,8 +135,6 @@ struct tsdev_list {
135#define TS_GET_CAL _IOR(IOC_H3600_TS_MAGIC, 10, struct ts_calibration) 135#define TS_GET_CAL _IOR(IOC_H3600_TS_MAGIC, 10, struct ts_calibration)
136#define TS_SET_CAL _IOW(IOC_H3600_TS_MAGIC, 11, struct ts_calibration) 136#define TS_SET_CAL _IOW(IOC_H3600_TS_MAGIC, 11, struct ts_calibration)
137 137
138static struct input_handler tsdev_handler;
139
140static struct tsdev *tsdev_table[TSDEV_MINORS/2]; 138static struct tsdev *tsdev_table[TSDEV_MINORS/2];
141 139
142static int tsdev_fasync(int fd, struct file *file, int on) 140static int tsdev_fasync(int fd, struct file *file, int on)
@@ -263,7 +261,7 @@ static int tsdev_ioctl(struct inode *inode, struct file *file,
263 return retval; 261 return retval;
264} 262}
265 263
266static struct file_operations tsdev_fops = { 264static const struct file_operations tsdev_fops = {
267 .owner = THIS_MODULE, 265 .owner = THIS_MODULE,
268 .open = tsdev_open, 266 .open = tsdev_open,
269 .release = tsdev_release, 267 .release = tsdev_release,
@@ -370,7 +368,7 @@ static void tsdev_event(struct input_handle *handle, unsigned int type,
370 368
371static struct input_handle *tsdev_connect(struct input_handler *handler, 369static struct input_handle *tsdev_connect(struct input_handler *handler,
372 struct input_dev *dev, 370 struct input_dev *dev,
373 struct input_device_id *id) 371 const struct input_device_id *id)
374{ 372{
375 struct tsdev *tsdev; 373 struct tsdev *tsdev;
376 struct class_device *cdev; 374 struct class_device *cdev;
@@ -443,7 +441,7 @@ static void tsdev_disconnect(struct input_handle *handle)
443 tsdev_free(tsdev); 441 tsdev_free(tsdev);
444} 442}
445 443
446static struct input_device_id tsdev_ids[] = { 444static const struct input_device_id tsdev_ids[] = {
447 { 445 {
448 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT | INPUT_DEVICE_ID_MATCH_RELBIT, 446 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT | INPUT_DEVICE_ID_MATCH_RELBIT,
449 .evbit = { BIT(EV_KEY) | BIT(EV_REL) }, 447 .evbit = { BIT(EV_KEY) | BIT(EV_REL) },
@@ -481,9 +479,7 @@ static struct input_handler tsdev_handler = {
481 479
482static int __init tsdev_init(void) 480static int __init tsdev_init(void)
483{ 481{
484 input_register_handler(&tsdev_handler); 482 return input_register_handler(&tsdev_handler);
485 printk(KERN_INFO "ts: Compaq touchscreen protocol output\n");
486 return 0;
487} 483}
488 484
489static void __exit tsdev_exit(void) 485static void __exit tsdev_exit(void)
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index 669f76393b5a..11844bbfe933 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1298,7 +1298,7 @@ static int capinc_tty_read_proc(char *page, char **start, off_t off,
1298 1298
1299static struct tty_driver *capinc_tty_driver; 1299static struct tty_driver *capinc_tty_driver;
1300 1300
1301static struct tty_operations capinc_ops = { 1301static const struct tty_operations capinc_ops = {
1302 .open = capinc_tty_open, 1302 .open = capinc_tty_open,
1303 .close = capinc_tty_close, 1303 .close = capinc_tty_close,
1304 .write = capinc_tty_write, 1304 .write = capinc_tty_write,
diff --git a/drivers/isdn/capi/capifs.c b/drivers/isdn/capi/capifs.c
index 9ea6bd0ddc35..2dd1b57b0ba4 100644
--- a/drivers/isdn/capi/capifs.c
+++ b/drivers/isdn/capi/capifs.c
@@ -104,7 +104,6 @@ capifs_fill_super(struct super_block *s, void *data, int silent)
104 inode->i_ino = 1; 104 inode->i_ino = 1;
105 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 105 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
106 inode->i_blocks = 0; 106 inode->i_blocks = 0;
107 inode->i_blksize = 1024;
108 inode->i_uid = inode->i_gid = 0; 107 inode->i_uid = inode->i_gid = 0;
109 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR; 108 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
110 inode->i_op = &simple_dir_inode_operations; 109 inode->i_op = &simple_dir_inode_operations;
@@ -149,7 +148,6 @@ void capifs_new_ncci(unsigned int number, dev_t device)
149 if (!inode) 148 if (!inode)
150 return; 149 return;
151 inode->i_ino = number+2; 150 inode->i_ino = number+2;
152 inode->i_blksize = 1024;
153 inode->i_uid = config.setuid ? config.uid : current->fsuid; 151 inode->i_uid = config.setuid ? config.uid : current->fsuid;
154 inode->i_gid = config.setgid ? config.gid : current->fsgid; 152 inode->i_gid = config.setgid ? config.gid : current->fsgid;
155 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 153 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
index 3845defd4901..5cfbe6a38010 100644
--- a/drivers/isdn/gigaset/bas-gigaset.c
+++ b/drivers/isdn/gigaset/bas-gigaset.c
@@ -192,7 +192,7 @@ static char *get_usb_statmsg(int status)
192 return "bit stuffing error, timeout, or unknown USB error"; 192 return "bit stuffing error, timeout, or unknown USB error";
193 case -EILSEQ: 193 case -EILSEQ:
194 return "CRC mismatch, timeout, or unknown USB error"; 194 return "CRC mismatch, timeout, or unknown USB error";
195 case -ETIMEDOUT: 195 case -ETIME:
196 return "timed out"; 196 return "timed out";
197 case -EPIPE: 197 case -EPIPE:
198 return "endpoint stalled"; 198 return "endpoint stalled";
diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
index bd2e4267528e..596f3aebe2f7 100644
--- a/drivers/isdn/gigaset/interface.c
+++ b/drivers/isdn/gigaset/interface.c
@@ -134,7 +134,7 @@ static int if_tiocmset(struct tty_struct *tty, struct file *file,
134static int if_write(struct tty_struct *tty, 134static int if_write(struct tty_struct *tty,
135 const unsigned char *buf, int count); 135 const unsigned char *buf, int count);
136 136
137static struct tty_operations if_ops = { 137static const struct tty_operations if_ops = {
138 .open = if_open, 138 .open = if_open,
139 .close = if_close, 139 .close = if_close,
140 .ioctl = if_ioctl, 140 .ioctl = if_ioctl,
diff --git a/drivers/isdn/gigaset/proc.c b/drivers/isdn/gigaset/proc.c
index 9ae3a7f3e7b3..9ad840e95dbe 100644
--- a/drivers/isdn/gigaset/proc.c
+++ b/drivers/isdn/gigaset/proc.c
@@ -83,5 +83,6 @@ void gigaset_init_dev_sysfs(struct cardstate *cs)
83 return; 83 return;
84 84
85 gig_dbg(DEBUG_INIT, "setting up sysfs"); 85 gig_dbg(DEBUG_INIT, "setting up sysfs");
86 class_device_create_file(cs->class, &class_device_attr_cidmode); 86 if (class_device_create_file(cs->class, &class_device_attr_cidmode))
87 dev_err(cs->dev, "could not create sysfs attribute\n");
87} 88}
diff --git a/drivers/isdn/hardware/eicon/dsp_defs.h b/drivers/isdn/hardware/eicon/dsp_defs.h
index b44950e06f32..fec1e381a688 100644
--- a/drivers/isdn/hardware/eicon/dsp_defs.h
+++ b/drivers/isdn/hardware/eicon/dsp_defs.h
@@ -34,9 +34,6 @@
34 * 34 *
35 * I/O functions returns -1 on error, 0 on EOF 35 * I/O functions returns -1 on error, 0 on EOF
36 */ 36 */
37#define OS_SEEK_SET 0
38#define OS_SEEK_CUR 1
39#define OS_SEEK_END 2
40struct _OsFileHandle_; 37struct _OsFileHandle_;
41typedef long ( * OsFileIo) (struct _OsFileHandle_ *handle, 38typedef long ( * OsFileIo) (struct _OsFileHandle_ *handle,
42 void *buffer, 39 void *buffer,
diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
index e10350360f2f..e4823ab2b127 100644
--- a/drivers/isdn/hisax/config.c
+++ b/drivers/isdn/hisax/config.c
@@ -1721,11 +1721,11 @@ static void hisax_b_l1l2(struct hisax_if *ifc, int pr, void *arg)
1721 hisax_b_sched_event(bcs, B_RCVBUFREADY); 1721 hisax_b_sched_event(bcs, B_RCVBUFREADY);
1722 break; 1722 break;
1723 case PH_DATA | CONFIRM: 1723 case PH_DATA | CONFIRM:
1724 bcs->tx_cnt -= (int) arg; 1724 bcs->tx_cnt -= (long)arg;
1725 if (test_bit(FLG_LLI_L1WAKEUP,&bcs->st->lli.flag)) { 1725 if (test_bit(FLG_LLI_L1WAKEUP,&bcs->st->lli.flag)) {
1726 u_long flags; 1726 u_long flags;
1727 spin_lock_irqsave(&bcs->aclock, flags); 1727 spin_lock_irqsave(&bcs->aclock, flags);
1728 bcs->ackcnt += (int) arg; 1728 bcs->ackcnt += (long)arg;
1729 spin_unlock_irqrestore(&bcs->aclock, flags); 1729 spin_unlock_irqrestore(&bcs->aclock, flags);
1730 schedule_event(bcs, B_ACKPENDING); 1730 schedule_event(bcs, B_ACKPENDING);
1731 } 1731 }
@@ -1789,7 +1789,7 @@ static void hisax_b_l2l1(struct PStack *st, int pr, void *arg)
1789 1789
1790 switch (pr) { 1790 switch (pr) {
1791 case PH_ACTIVATE | REQUEST: 1791 case PH_ACTIVATE | REQUEST:
1792 B_L2L1(b_if, pr, (void *) st->l1.mode); 1792 B_L2L1(b_if, pr, (void *)(unsigned long)st->l1.mode);
1793 break; 1793 break;
1794 case PH_DATA | REQUEST: 1794 case PH_DATA | REQUEST:
1795 case PH_PULL | INDICATION: 1795 case PH_PULL | INDICATION:
diff --git a/drivers/isdn/hisax/hfc4s8s_l1.c b/drivers/isdn/hisax/hfc4s8s_l1.c
index 3a5ca8a68fc4..0ca5e66d2f5a 100644
--- a/drivers/isdn/hisax/hfc4s8s_l1.c
+++ b/drivers/isdn/hisax/hfc4s8s_l1.c
@@ -424,7 +424,7 @@ bch_l2l1(struct hisax_if *ifc, int pr, void *arg)
424 struct hfc4s8s_btype *bch = ifc->priv; 424 struct hfc4s8s_btype *bch = ifc->priv;
425 struct hfc4s8s_l1 *l1 = bch->l1p; 425 struct hfc4s8s_l1 *l1 = bch->l1p;
426 struct sk_buff *skb = (struct sk_buff *) arg; 426 struct sk_buff *skb = (struct sk_buff *) arg;
427 int mode = (int) arg; 427 long mode = (long) arg;
428 u_long flags; 428 u_long flags;
429 429
430 switch (pr) { 430 switch (pr) {
@@ -914,7 +914,7 @@ tx_d_frame(struct hfc4s8s_l1 *l1p)
914 struct sk_buff *skb; 914 struct sk_buff *skb;
915 u_char f1, f2; 915 u_char f1, f2;
916 u_char *cp; 916 u_char *cp;
917 int cnt; 917 long cnt;
918 918
919 if (l1p->l1_state != 7) 919 if (l1p->l1_state != 7)
920 return; 920 return;
@@ -980,7 +980,8 @@ tx_b_frame(struct hfc4s8s_btype *bch)
980 struct sk_buff *skb; 980 struct sk_buff *skb;
981 struct hfc4s8s_l1 *l1 = bch->l1p; 981 struct hfc4s8s_l1 *l1 = bch->l1p;
982 u_char *cp; 982 u_char *cp;
983 int cnt, max, hdlc_num, ack_len = 0; 983 int cnt, max, hdlc_num;
984 long ack_len = 0;
984 985
985 if (!l1->enabled || (bch->mode == L1_MODE_NULL)) 986 if (!l1->enabled || (bch->mode == L1_MODE_NULL))
986 return; 987 return;
diff --git a/drivers/isdn/hisax/hfc_sx.c b/drivers/isdn/hisax/hfc_sx.c
index f27c1608a3a7..b7e8e23be337 100644
--- a/drivers/isdn/hisax/hfc_sx.c
+++ b/drivers/isdn/hisax/hfc_sx.c
@@ -970,7 +970,7 @@ HFCSX_l1hw(struct PStack *st, int pr, void *arg)
970 break; 970 break;
971 case (HW_TESTLOOP | REQUEST): 971 case (HW_TESTLOOP | REQUEST):
972 spin_lock_irqsave(&cs->lock, flags); 972 spin_lock_irqsave(&cs->lock, flags);
973 switch ((int) arg) { 973 switch ((long) arg) {
974 case (1): 974 case (1):
975 Write_hfc(cs, HFCSX_B1_SSL, 0x80); /* tx slot */ 975 Write_hfc(cs, HFCSX_B1_SSL, 0x80); /* tx slot */
976 Write_hfc(cs, HFCSX_B1_RSL, 0x80); /* rx slot */ 976 Write_hfc(cs, HFCSX_B1_RSL, 0x80); /* rx slot */
@@ -986,7 +986,7 @@ HFCSX_l1hw(struct PStack *st, int pr, void *arg)
986 default: 986 default:
987 spin_unlock_irqrestore(&cs->lock, flags); 987 spin_unlock_irqrestore(&cs->lock, flags);
988 if (cs->debug & L1_DEB_WARN) 988 if (cs->debug & L1_DEB_WARN)
989 debugl1(cs, "hfcsx_l1hw loop invalid %4x", (int) arg); 989 debugl1(cs, "hfcsx_l1hw loop invalid %4lx", arg);
990 return; 990 return;
991 } 991 }
992 cs->hw.hfcsx.trm |= 0x80; /* enable IOM-loop */ 992 cs->hw.hfcsx.trm |= 0x80; /* enable IOM-loop */
diff --git a/drivers/isdn/hisax/hfc_usb.c b/drivers/isdn/hisax/hfc_usb.c
index b5e571a52694..6b88ecb5047d 100644
--- a/drivers/isdn/hisax/hfc_usb.c
+++ b/drivers/isdn/hisax/hfc_usb.c
@@ -696,7 +696,7 @@ tx_iso_complete(struct urb *urb, struct pt_regs *regs)
696 fifo->delete_flg = TRUE; 696 fifo->delete_flg = TRUE;
697 fifo->hif->l1l2(fifo->hif, 697 fifo->hif->l1l2(fifo->hif,
698 PH_DATA | CONFIRM, 698 PH_DATA | CONFIRM,
699 (void *) fifo->skbuff-> 699 (void *) (unsigned long) fifo->skbuff->
700 truesize); 700 truesize);
701 if (fifo->skbuff && fifo->delete_flg) { 701 if (fifo->skbuff && fifo->delete_flg) {
702 dev_kfree_skb_any(fifo->skbuff); 702 dev_kfree_skb_any(fifo->skbuff);
@@ -1144,7 +1144,7 @@ hfc_usb_l2l1(struct hisax_if *my_hisax_if, int pr, void *arg)
1144 set_hfcmode(hfc, 1144 set_hfcmode(hfc,
1145 (fifo->fifonum == 1145 (fifo->fifonum ==
1146 HFCUSB_B1_TX) ? 0 : 1, 1146 HFCUSB_B1_TX) ? 0 : 1,
1147 (int) arg); 1147 (long) arg);
1148 fifo->hif->l1l2(fifo->hif, 1148 fifo->hif->l1l2(fifo->hif,
1149 PH_ACTIVATE | INDICATION, 1149 PH_ACTIVATE | INDICATION,
1150 NULL); 1150 NULL);
diff --git a/drivers/isdn/hisax/hfc_usb.h b/drivers/isdn/hisax/hfc_usb.h
index ec52c1a7c22a..6349367ed480 100644
--- a/drivers/isdn/hisax/hfc_usb.h
+++ b/drivers/isdn/hisax/hfc_usb.h
@@ -137,11 +137,11 @@ static struct hfcusb_symbolic_list urb_errlist[] = {
137 {-ENXIO, "URB already queued"}, 137 {-ENXIO, "URB already queued"},
138 {-EFBIG, "Too much ISO frames requested"}, 138 {-EFBIG, "Too much ISO frames requested"},
139 {-ENOSR, "Buffer error (overrun)"}, 139 {-ENOSR, "Buffer error (overrun)"},
140 {-EPIPE, "Specified endpoint is stalled (device not responding)"}, 140 {-EPIPE, "Specified endpoint is stalled"},
141 {-EOVERFLOW, "Babble (bad cable?)"}, 141 {-EOVERFLOW, "Babble (bad cable?)"},
142 {-EPROTO, "Bit-stuff error (bad cable?)"}, 142 {-EPROTO, "Bit-stuff error (bad cable?)"},
143 {-EILSEQ, "CRC/Timeout"}, 143 {-EILSEQ, "CRC or missing token"},
144 {-ETIMEDOUT, "NAK (device does not respond)"}, 144 {-ETIME, "Device did not respond"},
145 {-ESHUTDOWN, "Device unplugged"}, 145 {-ESHUTDOWN, "Device unplugged"},
146 {-1, NULL} 146 {-1, NULL}
147}; 147};
diff --git a/drivers/isdn/hisax/hisax.h b/drivers/isdn/hisax/hisax.h
index 75920aa0a3c5..2f9d5118ceaf 100644
--- a/drivers/isdn/hisax/hisax.h
+++ b/drivers/isdn/hisax/hisax.h
@@ -1316,7 +1316,18 @@ void dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir);
1316void iecpy(u_char * dest, u_char * iestart, int ieoffset); 1316void iecpy(u_char * dest, u_char * iestart, int ieoffset);
1317#endif /* __KERNEL__ */ 1317#endif /* __KERNEL__ */
1318 1318
1319#define HZDELAY(jiffs) {int tout = jiffs; while (tout--) udelay(1000000/HZ);} 1319/*
1320 * Busywait delay for `jiffs' jiffies
1321 */
1322#define HZDELAY(jiffs) do { \
1323 int tout = jiffs; \
1324 \
1325 while (tout--) { \
1326 int loops = USEC_PER_SEC / HZ; \
1327 while (loops--) \
1328 udelay(1); \
1329 } \
1330 } while (0)
1320 1331
1321int ll_run(struct IsdnCardState *cs, int addfeatures); 1332int ll_run(struct IsdnCardState *cs, int addfeatures);
1322int CallcNew(void); 1333int CallcNew(void);
diff --git a/drivers/isdn/hisax/hisax_fcpcipnp.c b/drivers/isdn/hisax/hisax_fcpcipnp.c
index 1d7cf3bd6aa3..881a4165cfb4 100644
--- a/drivers/isdn/hisax/hisax_fcpcipnp.c
+++ b/drivers/isdn/hisax/hisax_fcpcipnp.c
@@ -546,7 +546,7 @@ static inline void hdlc_xpr_irq(struct fritz_bcs *bcs)
546 } 546 }
547 bcs->tx_cnt = 0; 547 bcs->tx_cnt = 0;
548 bcs->tx_skb = NULL; 548 bcs->tx_skb = NULL;
549 B_L1L2(bcs, PH_DATA | CONFIRM, (void *) skb->truesize); 549 B_L1L2(bcs, PH_DATA | CONFIRM, (void *)(unsigned long)skb->truesize);
550 dev_kfree_skb_irq(skb); 550 dev_kfree_skb_irq(skb);
551} 551}
552 552
@@ -635,7 +635,7 @@ static void fritz_b_l2l1(struct hisax_if *ifc, int pr, void *arg)
635 hdlc_fill_fifo(bcs); 635 hdlc_fill_fifo(bcs);
636 break; 636 break;
637 case PH_ACTIVATE | REQUEST: 637 case PH_ACTIVATE | REQUEST:
638 mode = (int) arg; 638 mode = (long) arg;
639 DBG(4,"B%d,PH_ACTIVATE_REQUEST %d", bcs->channel + 1, mode); 639 DBG(4,"B%d,PH_ACTIVATE_REQUEST %d", bcs->channel + 1, mode);
640 modehdlc(bcs, mode); 640 modehdlc(bcs, mode);
641 B_L1L2(bcs, PH_ACTIVATE | INDICATION, NULL); 641 B_L1L2(bcs, PH_ACTIVATE | INDICATION, NULL);
@@ -998,18 +998,15 @@ static int __init hisax_fcpcipnp_init(void)
998 998
999 retval = pci_register_driver(&fcpci_driver); 999 retval = pci_register_driver(&fcpci_driver);
1000 if (retval) 1000 if (retval)
1001 goto out; 1001 return retval;
1002#ifdef __ISAPNP__ 1002#ifdef __ISAPNP__
1003 retval = pnp_register_driver(&fcpnp_driver); 1003 retval = pnp_register_driver(&fcpnp_driver);
1004 if (retval < 0) 1004 if (retval < 0) {
1005 goto out_unregister_pci; 1005 pci_unregister_driver(&fcpci_driver);
1006 return retval;
1007 }
1006#endif 1008#endif
1007 return 0; 1009 return 0;
1008
1009 out_unregister_pci:
1010 pci_unregister_driver(&fcpci_driver);
1011 out:
1012 return retval;
1013} 1010}
1014 1011
1015static void __exit hisax_fcpcipnp_exit(void) 1012static void __exit hisax_fcpcipnp_exit(void)
diff --git a/drivers/isdn/hisax/st5481_b.c b/drivers/isdn/hisax/st5481_b.c
index 22fd5db18d48..aca2a3954b14 100644
--- a/drivers/isdn/hisax/st5481_b.c
+++ b/drivers/isdn/hisax/st5481_b.c
@@ -86,7 +86,7 @@ static void usb_b_out(struct st5481_bcs *bcs,int buf_nr)
86 if (!skb->len) { 86 if (!skb->len) {
87 // Frame sent 87 // Frame sent
88 b_out->tx_skb = NULL; 88 b_out->tx_skb = NULL;
89 B_L1L2(bcs, PH_DATA | CONFIRM, (void *) skb->truesize); 89 B_L1L2(bcs, PH_DATA | CONFIRM, (void *)(unsigned long) skb->truesize);
90 dev_kfree_skb_any(skb); 90 dev_kfree_skb_any(skb);
91 91
92/* if (!(bcs->tx_skb = skb_dequeue(&bcs->sq))) { */ 92/* if (!(bcs->tx_skb = skb_dequeue(&bcs->sq))) { */
@@ -350,7 +350,7 @@ void st5481_b_l2l1(struct hisax_if *ifc, int pr, void *arg)
350{ 350{
351 struct st5481_bcs *bcs = ifc->priv; 351 struct st5481_bcs *bcs = ifc->priv;
352 struct sk_buff *skb = arg; 352 struct sk_buff *skb = arg;
353 int mode; 353 long mode;
354 354
355 DBG(4, ""); 355 DBG(4, "");
356 356
@@ -360,8 +360,8 @@ void st5481_b_l2l1(struct hisax_if *ifc, int pr, void *arg)
360 bcs->b_out.tx_skb = skb; 360 bcs->b_out.tx_skb = skb;
361 break; 361 break;
362 case PH_ACTIVATE | REQUEST: 362 case PH_ACTIVATE | REQUEST:
363 mode = (int) arg; 363 mode = (long) arg;
364 DBG(4,"B%d,PH_ACTIVATE_REQUEST %d", bcs->channel + 1, mode); 364 DBG(4,"B%d,PH_ACTIVATE_REQUEST %ld", bcs->channel + 1, mode);
365 st5481B_mode(bcs, mode); 365 st5481B_mode(bcs, mode);
366 B_L1L2(bcs, PH_ACTIVATE | INDICATION, NULL); 366 B_L1L2(bcs, PH_ACTIVATE | INDICATION, NULL);
367 break; 367 break;
diff --git a/drivers/isdn/hisax/st5481_d.c b/drivers/isdn/hisax/st5481_d.c
index 493dc94992e5..98adec440590 100644
--- a/drivers/isdn/hisax/st5481_d.c
+++ b/drivers/isdn/hisax/st5481_d.c
@@ -374,7 +374,7 @@ static void usb_d_out_complete(struct urb *urb, struct pt_regs *regs)
374{ 374{
375 struct st5481_adapter *adapter = urb->context; 375 struct st5481_adapter *adapter = urb->context;
376 struct st5481_d_out *d_out = &adapter->d_out; 376 struct st5481_d_out *d_out = &adapter->d_out;
377 int buf_nr; 377 long buf_nr;
378 378
379 DBG(2, ""); 379 DBG(2, "");
380 380
@@ -546,7 +546,7 @@ static void dout_reseted(struct FsmInst *fsm, int event, void *arg)
546static void dout_complete(struct FsmInst *fsm, int event, void *arg) 546static void dout_complete(struct FsmInst *fsm, int event, void *arg)
547{ 547{
548 struct st5481_adapter *adapter = fsm->userdata; 548 struct st5481_adapter *adapter = fsm->userdata;
549 int buf_nr = (int) arg; 549 long buf_nr = (long) arg;
550 550
551 usb_d_out(adapter, buf_nr); 551 usb_d_out(adapter, buf_nr);
552} 552}
diff --git a/drivers/isdn/i4l/isdn_net.c b/drivers/isdn/i4l/isdn_net.c
index 43da8ae1b2ad..1f8d6ae66b41 100644
--- a/drivers/isdn/i4l/isdn_net.c
+++ b/drivers/isdn/i4l/isdn_net.c
@@ -1614,8 +1614,8 @@ isdn_net_ciscohdlck_slarp_send_reply(isdn_net_local *lp)
1614 struct sk_buff *skb; 1614 struct sk_buff *skb;
1615 unsigned char *p; 1615 unsigned char *p;
1616 struct in_device *in_dev = NULL; 1616 struct in_device *in_dev = NULL;
1617 u32 addr = 0; /* local ipv4 address */ 1617 __be32 addr = 0; /* local ipv4 address */
1618 u32 mask = 0; /* local netmask */ 1618 __be32 mask = 0; /* local netmask */
1619 1619
1620 if ((in_dev = lp->netdev->dev.ip_ptr) != NULL) { 1620 if ((in_dev = lp->netdev->dev.ip_ptr) != NULL) {
1621 /* take primary(first) address of interface */ 1621 /* take primary(first) address of interface */
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index 9ab66e8960d5..2b91bb07fc7f 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -1860,7 +1860,7 @@ modem_write_profile(atemu * m)
1860 send_sig(SIGIO, dev->profd, 1); 1860 send_sig(SIGIO, dev->profd, 1);
1861} 1861}
1862 1862
1863static struct tty_operations modem_ops = { 1863static const struct tty_operations modem_ops = {
1864 .open = isdn_tty_open, 1864 .open = isdn_tty_open,
1865 .close = isdn_tty_close, 1865 .close = isdn_tty_close,
1866 .write = isdn_tty_write, 1866 .write = isdn_tty_write,
diff --git a/drivers/isdn/sc/command.c b/drivers/isdn/sc/command.c
index b4b24335f716..04b8a58f03b5 100644
--- a/drivers/isdn/sc/command.c
+++ b/drivers/isdn/sc/command.c
@@ -103,9 +103,6 @@ int command(isdn_ctrl *cmd)
103 return -ENODEV; 103 return -ENODEV;
104 } 104 }
105 105
106 pr_debug("%s: Received %s command from Link Layer\n",
107 sc_adapter[card]->devicename, commands[cmd->command]);
108
109 /* 106 /*
110 * Dispatch the command 107 * Dispatch the command
111 */ 108 */
@@ -118,7 +115,7 @@ int command(isdn_ctrl *cmd)
118 memcpy(&cmdptr, cmd->parm.num, sizeof(unsigned long)); 115 memcpy(&cmdptr, cmd->parm.num, sizeof(unsigned long));
119 if (copy_from_user(&ioc, (scs_ioctl __user *)cmdptr, 116 if (copy_from_user(&ioc, (scs_ioctl __user *)cmdptr,
120 sizeof(scs_ioctl))) { 117 sizeof(scs_ioctl))) {
121 pr_debug("%s: Failed to verify user space 0x%x\n", 118 pr_debug("%s: Failed to verify user space 0x%lx\n",
122 sc_adapter[card]->devicename, cmdptr); 119 sc_adapter[card]->devicename, cmdptr);
123 return -EFAULT; 120 return -EFAULT;
124 } 121 }
@@ -195,7 +192,7 @@ static int dial(int card, unsigned long channel, setup_parm setup)
195 strlen(Phone), 192 strlen(Phone),
196 (unsigned int *) Phone); 193 (unsigned int *) Phone);
197 194
198 pr_debug("%s: Dialing %s on channel %d\n", 195 pr_debug("%s: Dialing %s on channel %lu\n",
199 sc_adapter[card]->devicename, Phone, channel+1); 196 sc_adapter[card]->devicename, Phone, channel+1);
200 197
201 return status; 198 return status;
@@ -217,7 +214,7 @@ static int answer(int card, unsigned long channel)
217 } 214 }
218 215
219 indicate_status(card, ISDN_STAT_BCONN,channel,NULL); 216 indicate_status(card, ISDN_STAT_BCONN,channel,NULL);
220 pr_debug("%s: Answered incoming call on channel %s\n", 217 pr_debug("%s: Answered incoming call on channel %lu\n",
221 sc_adapter[card]->devicename, channel+1); 218 sc_adapter[card]->devicename, channel+1);
222 return 0; 219 return 0;
223} 220}
@@ -240,7 +237,7 @@ static int hangup(int card, unsigned long channel)
240 (unsigned char) channel+1, 237 (unsigned char) channel+1,
241 0, 238 0,
242 NULL); 239 NULL);
243 pr_debug("%s: Sent HANGUP message to channel %d\n", 240 pr_debug("%s: Sent HANGUP message to channel %lu\n",
244 sc_adapter[card]->devicename, channel+1); 241 sc_adapter[card]->devicename, channel+1);
245 return status; 242 return status;
246} 243}
@@ -260,9 +257,6 @@ static int setl2(int card, unsigned long arg)
260 protocol = arg >> 8; 257 protocol = arg >> 8;
261 channel = arg & 0xff; 258 channel = arg & 0xff;
262 sc_adapter[card]->channel[channel].l2_proto = protocol; 259 sc_adapter[card]->channel[channel].l2_proto = protocol;
263 pr_debug("%s: Level 2 protocol for channel %d set to %s from %d\n",
264 sc_adapter[card]->devicename, channel+1,
265 l2protos[sc_adapter[card]->channel[channel].l2_proto],protocol);
266 260
267 /* 261 /*
268 * check that the adapter is also set to the correct protocol 262 * check that the adapter is also set to the correct protocol
@@ -293,8 +287,6 @@ static int setl3(int card, unsigned long channel)
293 } 287 }
294 288
295 sc_adapter[card]->channel[channel].l3_proto = protocol; 289 sc_adapter[card]->channel[channel].l3_proto = protocol;
296 pr_debug("%s: Level 3 protocol for channel %d set to %s\n",
297 sc_adapter[card]->devicename, channel+1, l3protos[protocol]);
298 return 0; 290 return 0;
299} 291}
300 292
@@ -311,7 +303,7 @@ static int acceptb(int card, unsigned long channel)
311 return -ENOBUFS; 303 return -ENOBUFS;
312 } 304 }
313 305
314 pr_debug("%s: B-Channel connection accepted on channel %d\n", 306 pr_debug("%s: B-Channel connection accepted on channel %lu\n",
315 sc_adapter[card]->devicename, channel+1); 307 sc_adapter[card]->devicename, channel+1);
316 indicate_status(card, ISDN_STAT_BCONN, channel, NULL); 308 indicate_status(card, ISDN_STAT_BCONN, channel, NULL);
317 return 0; 309 return 0;
@@ -326,7 +318,7 @@ static int clreaz(int card, unsigned long arg)
326 318
327 strcpy(sc_adapter[card]->channel[arg].eazlist, ""); 319 strcpy(sc_adapter[card]->channel[arg].eazlist, "");
328 sc_adapter[card]->channel[arg].eazclear = 1; 320 sc_adapter[card]->channel[arg].eazclear = 1;
329 pr_debug("%s: EAZ List cleared for channel %d\n", 321 pr_debug("%s: EAZ List cleared for channel %lu\n",
330 sc_adapter[card]->devicename, arg+1); 322 sc_adapter[card]->devicename, arg+1);
331 return 0; 323 return 0;
332} 324}
@@ -340,7 +332,7 @@ static int seteaz(int card, unsigned long arg, char *num)
340 332
341 strcpy(sc_adapter[card]->channel[arg].eazlist, num); 333 strcpy(sc_adapter[card]->channel[arg].eazlist, num);
342 sc_adapter[card]->channel[arg].eazclear = 0; 334 sc_adapter[card]->channel[arg].eazclear = 0;
343 pr_debug("%s: EAZ list for channel %d set to: %s\n", 335 pr_debug("%s: EAZ list for channel %lu set to: %s\n",
344 sc_adapter[card]->devicename, arg+1, 336 sc_adapter[card]->devicename, arg+1,
345 sc_adapter[card]->channel[arg].eazlist); 337 sc_adapter[card]->channel[arg].eazlist);
346 return 0; 338 return 0;
diff --git a/drivers/isdn/sc/event.c b/drivers/isdn/sc/event.c
index 5b8c7c1a7663..57367325ef04 100644
--- a/drivers/isdn/sc/event.c
+++ b/drivers/isdn/sc/event.c
@@ -45,8 +45,10 @@ int indicate_status(int card, int event,ulong Channel,char *Data)
45{ 45{
46 isdn_ctrl cmd; 46 isdn_ctrl cmd;
47 47
48#ifdef DEBUG
48 pr_debug("%s: Indicating event %s on Channel %d\n", 49 pr_debug("%s: Indicating event %s on Channel %d\n",
49 sc_adapter[card]->devicename, events[event-256], Channel); 50 sc_adapter[card]->devicename, events[event-256], Channel);
51#endif
50 if (Data != NULL){ 52 if (Data != NULL){
51 pr_debug("%s: Event data: %s\n", sc_adapter[card]->devicename, 53 pr_debug("%s: Event data: %s\n", sc_adapter[card]->devicename,
52 Data); 54 Data);
diff --git a/drivers/isdn/sc/interrupt.c b/drivers/isdn/sc/interrupt.c
index 8631d338d69a..ae6263125ac2 100644
--- a/drivers/isdn/sc/interrupt.c
+++ b/drivers/isdn/sc/interrupt.c
@@ -91,7 +91,7 @@ irqreturn_t interrupt_handler(int interrupt, void *cardptr, struct pt_regs *regs
91 */ 91 */
92 if (IS_CE_MESSAGE(rcvmsg, Lnk, 1, Read)) 92 if (IS_CE_MESSAGE(rcvmsg, Lnk, 1, Read))
93 { 93 {
94 pr_debug("%s: Received packet 0x%x bytes long at 0x%x\n", 94 pr_debug("%s: Received packet 0x%x bytes long at 0x%lx\n",
95 sc_adapter[card]->devicename, 95 sc_adapter[card]->devicename,
96 rcvmsg.msg_data.response.msg_len, 96 rcvmsg.msg_data.response.msg_len,
97 rcvmsg.msg_data.response.buff_offset); 97 rcvmsg.msg_data.response.buff_offset);
diff --git a/drivers/isdn/sc/timer.c b/drivers/isdn/sc/timer.c
index aced19aac5a2..f43282be0ada 100644
--- a/drivers/isdn/sc/timer.c
+++ b/drivers/isdn/sc/timer.c
@@ -76,7 +76,7 @@ void check_reset(unsigned long data)
76 if (sc_adapter[card]->StartOnReset) 76 if (sc_adapter[card]->StartOnReset)
77 startproc(card); 77 startproc(card);
78 } else { 78 } else {
79 pr_debug("%s: No signature yet, waiting another %d jiffies.\n", 79 pr_debug("%s: No signature yet, waiting another %lu jiffies.\n",
80 sc_adapter[card]->devicename, CHECKRESET_TIME); 80 sc_adapter[card]->devicename, CHECKRESET_TIME);
81 mod_timer(&sc_adapter[card]->reset_timer, jiffies+CHECKRESET_TIME); 81 mod_timer(&sc_adapter[card]->reset_timer, jiffies+CHECKRESET_TIME);
82 spin_unlock_irqrestore(&sc_adapter[card]->lock, flags); 82 spin_unlock_irqrestore(&sc_adapter[card]->lock, flags);
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index 47f0ff196328..454fb0901f82 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -125,6 +125,7 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger)
125 write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock, flags); 125 write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock, flags);
126 if (led_cdev->trigger->deactivate) 126 if (led_cdev->trigger->deactivate)
127 led_cdev->trigger->deactivate(led_cdev); 127 led_cdev->trigger->deactivate(led_cdev);
128 led_set_brightness(led_cdev, LED_OFF);
128 } 129 }
129 if (trigger) { 130 if (trigger) {
130 write_lock_irqsave(&trigger->leddev_list_lock, flags); 131 write_lock_irqsave(&trigger->leddev_list_lock, flags);
diff --git a/drivers/leds/leds-net48xx.c b/drivers/leds/leds-net48xx.c
index 713c4a8aa77d..45ba3d45bcb8 100644
--- a/drivers/leds/leds-net48xx.c
+++ b/drivers/leds/leds-net48xx.c
@@ -16,6 +16,7 @@
16#include <linux/leds.h> 16#include <linux/leds.h>
17#include <linux/err.h> 17#include <linux/err.h>
18#include <asm/io.h> 18#include <asm/io.h>
19#include <linux/nsc_gpio.h>
19#include <linux/scx200_gpio.h> 20#include <linux/scx200_gpio.h>
20 21
21#define DRVNAME "net48xx-led" 22#define DRVNAME "net48xx-led"
@@ -26,10 +27,7 @@ static struct platform_device *pdev;
26static void net48xx_error_led_set(struct led_classdev *led_cdev, 27static void net48xx_error_led_set(struct led_classdev *led_cdev,
27 enum led_brightness value) 28 enum led_brightness value)
28{ 29{
29 if (value) 30 scx200_gpio_ops.gpio_set(NET48XX_ERROR_LED_GPIO, value ? 1 : 0);
30 scx200_gpio_set_high(NET48XX_ERROR_LED_GPIO);
31 else
32 scx200_gpio_set_low(NET48XX_ERROR_LED_GPIO);
33} 31}
34 32
35static struct led_classdev net48xx_error_led = { 33static struct led_classdev net48xx_error_led = {
@@ -81,7 +79,8 @@ static int __init net48xx_led_init(void)
81{ 79{
82 int ret; 80 int ret;
83 81
84 if (!scx200_gpio_present()) { 82 /* small hack, but scx200_gpio doesn't set .dev if the probe fails */
83 if (!scx200_gpio_ops.dev) {
85 ret = -ENODEV; 84 ret = -ENODEV;
86 goto out; 85 goto out;
87 } 86 }
diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
index 090e40fc5013..c0f9d82e4662 100644
--- a/drivers/macintosh/smu.c
+++ b/drivers/macintosh/smu.c
@@ -870,7 +870,7 @@ int smu_queue_i2c(struct smu_i2c_cmd *cmd)
870 870
871static int smu_read_datablock(u8 *dest, unsigned int addr, unsigned int len) 871static int smu_read_datablock(u8 *dest, unsigned int addr, unsigned int len)
872{ 872{
873 DECLARE_COMPLETION(comp); 873 DECLARE_COMPLETION_ONSTACK(comp);
874 unsigned int chunk; 874 unsigned int chunk;
875 struct smu_cmd cmd; 875 struct smu_cmd cmd;
876 int rc; 876 int rc;
@@ -917,7 +917,7 @@ static int smu_read_datablock(u8 *dest, unsigned int addr, unsigned int len)
917 917
918static struct smu_sdbp_header *smu_create_sdb_partition(int id) 918static struct smu_sdbp_header *smu_create_sdb_partition(int id)
919{ 919{
920 DECLARE_COMPLETION(comp); 920 DECLARE_COMPLETION_ONSTACK(comp);
921 struct smu_simple_cmd cmd; 921 struct smu_simple_cmd cmd;
922 unsigned int addr, len, tlen; 922 unsigned int addr, len, tlen;
923 struct smu_sdbp_header *hdr; 923 struct smu_sdbp_header *hdr;
diff --git a/drivers/macintosh/via-pmu-backlight.c b/drivers/macintosh/via-pmu-backlight.c
index a82f313d9dc9..6c29fe727c0f 100644
--- a/drivers/macintosh/via-pmu-backlight.c
+++ b/drivers/macintosh/via-pmu-backlight.c
@@ -16,7 +16,7 @@
16#define MAX_PMU_LEVEL 0xFF 16#define MAX_PMU_LEVEL 0xFF
17 17
18static struct backlight_properties pmu_backlight_data; 18static struct backlight_properties pmu_backlight_data;
19static spinlock_t pmu_backlight_lock; 19static DEFINE_SPINLOCK(pmu_backlight_lock);
20static int sleeping; 20static int sleeping;
21static u8 bl_curve[FB_BACKLIGHT_LEVELS]; 21static u8 bl_curve[FB_BACKLIGHT_LEVELS];
22 22
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index 5710e01cef10..4f04fd0956a0 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -1832,7 +1832,7 @@ pbook_alloc_pci_save(void)
1832 struct pci_dev *pd = NULL; 1832 struct pci_dev *pd = NULL;
1833 1833
1834 npci = 0; 1834 npci = 0;
1835 while ((pd = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) { 1835 while ((pd = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) {
1836 ++npci; 1836 ++npci;
1837 } 1837 }
1838 if (npci == 0) 1838 if (npci == 0)
@@ -1862,9 +1862,11 @@ pbook_pci_save(void)
1862 if (ps == NULL) 1862 if (ps == NULL)
1863 return; 1863 return;
1864 1864
1865 while ((pd = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) { 1865 while ((pd = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) {
1866 if (npci-- == 0) 1866 if (npci-- == 0) {
1867 pci_dev_put(pd);
1867 return; 1868 return;
1869 }
1868#ifndef HACKED_PCI_SAVE 1870#ifndef HACKED_PCI_SAVE
1869 pci_read_config_word(pd, PCI_COMMAND, &ps->command); 1871 pci_read_config_word(pd, PCI_COMMAND, &ps->command);
1870 pci_read_config_word(pd, PCI_CACHE_LINE_SIZE, &ps->cache_lat); 1872 pci_read_config_word(pd, PCI_CACHE_LINE_SIZE, &ps->cache_lat);
@@ -1892,11 +1894,13 @@ pbook_pci_restore(void)
1892 int npci = pbook_npci_saves; 1894 int npci = pbook_npci_saves;
1893 int j; 1895 int j;
1894 1896
1895 while ((pd = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) { 1897 while ((pd = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) {
1896#ifdef HACKED_PCI_SAVE 1898#ifdef HACKED_PCI_SAVE
1897 int i; 1899 int i;
1898 if (npci-- == 0) 1900 if (npci-- == 0) {
1901 pci_dev_put(pd);
1899 return; 1902 return;
1903 }
1900 ps++; 1904 ps++;
1901 for (i=2;i<16;i++) 1905 for (i=2;i<16;i++)
1902 pci_write_config_dword(pd, i<<4, ps->config[i]); 1906 pci_write_config_dword(pd, i<<4, ps->config[i]);
diff --git a/drivers/macintosh/via-pmu68k.c b/drivers/macintosh/via-pmu68k.c
index 35b70323e7e3..9f4eff1d1a0f 100644
--- a/drivers/macintosh/via-pmu68k.c
+++ b/drivers/macintosh/via-pmu68k.c
@@ -843,7 +843,7 @@ pbook_pci_save(void)
843 struct pci_save *ps; 843 struct pci_save *ps;
844 844
845 npci = 0; 845 npci = 0;
846 while ((pd = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) 846 while ((pd = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL)
847 ++npci; 847 ++npci;
848 n_pbook_pci_saves = npci; 848 n_pbook_pci_saves = npci;
849 if (npci == 0) 849 if (npci == 0)
@@ -854,7 +854,7 @@ pbook_pci_save(void)
854 return; 854 return;
855 855
856 pd = NULL; 856 pd = NULL;
857 while ((pd = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) { 857 while ((pd = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) {
858 pci_read_config_word(pd, PCI_COMMAND, &ps->command); 858 pci_read_config_word(pd, PCI_COMMAND, &ps->command);
859 pci_read_config_word(pd, PCI_CACHE_LINE_SIZE, &ps->cache_lat); 859 pci_read_config_word(pd, PCI_CACHE_LINE_SIZE, &ps->cache_lat);
860 pci_read_config_word(pd, PCI_INTERRUPT_LINE, &ps->intr); 860 pci_read_config_word(pd, PCI_INTERRUPT_LINE, &ps->intr);
@@ -871,7 +871,7 @@ pbook_pci_restore(void)
871 struct pci_dev *pd = NULL; 871 struct pci_dev *pd = NULL;
872 int j; 872 int j;
873 873
874 while ((pd = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) { 874 while ((pd = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) {
875 if (ps->command == 0) 875 if (ps->command == 0)
876 continue; 876 continue;
877 pci_read_config_word(pd, PCI_COMMAND, &cmd); 877 pci_read_config_word(pd, PCI_COMMAND, &cmd);
diff --git a/drivers/macintosh/windfarm_smu_controls.c b/drivers/macintosh/windfarm_smu_controls.c
index bff1f372f188..31b750d61206 100644
--- a/drivers/macintosh/windfarm_smu_controls.c
+++ b/drivers/macintosh/windfarm_smu_controls.c
@@ -56,7 +56,7 @@ static int smu_set_fan(int pwm, u8 id, u16 value)
56{ 56{
57 struct smu_cmd cmd; 57 struct smu_cmd cmd;
58 u8 buffer[16]; 58 u8 buffer[16];
59 DECLARE_COMPLETION(comp); 59 DECLARE_COMPLETION_ONSTACK(comp);
60 int rc; 60 int rc;
61 61
62 /* Fill SMU command structure */ 62 /* Fill SMU command structure */
diff --git a/drivers/macintosh/windfarm_smu_sat.c b/drivers/macintosh/windfarm_smu_sat.c
index aceb61d9fbc8..83f79de7174b 100644
--- a/drivers/macintosh/windfarm_smu_sat.c
+++ b/drivers/macintosh/windfarm_smu_sat.c
@@ -397,12 +397,7 @@ static int wf_sat_detach(struct i2c_client *client)
397 397
398static int __init sat_sensors_init(void) 398static int __init sat_sensors_init(void)
399{ 399{
400 int err; 400 return i2c_add_driver(&wf_sat_driver);
401
402 err = i2c_add_driver(&wf_sat_driver);
403 if (err < 0)
404 return err;
405 return 0;
406} 401}
407 402
408static void __exit sat_sensors_exit(void) 403static void __exit sat_sensors_exit(void)
diff --git a/drivers/macintosh/windfarm_smu_sensors.c b/drivers/macintosh/windfarm_smu_sensors.c
index defe9922ebd1..01b4c50143dd 100644
--- a/drivers/macintosh/windfarm_smu_sensors.c
+++ b/drivers/macintosh/windfarm_smu_sensors.c
@@ -67,7 +67,7 @@ static void smu_ads_release(struct wf_sensor *sr)
67static int smu_read_adc(u8 id, s32 *value) 67static int smu_read_adc(u8 id, s32 *value)
68{ 68{
69 struct smu_simple_cmd cmd; 69 struct smu_simple_cmd cmd;
70 DECLARE_COMPLETION(comp); 70 DECLARE_COMPLETION_ONSTACK(comp);
71 int rc; 71 int rc;
72 72
73 rc = smu_queue_simple(&cmd, SMU_CMD_READ_ADC, 1, 73 rc = smu_queue_simple(&cmd, SMU_CMD_READ_ADC, 1,
diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig
index bf869ed03eed..c92c1521546d 100644
--- a/drivers/md/Kconfig
+++ b/drivers/md/Kconfig
@@ -2,6 +2,8 @@
2# Block device driver configuration 2# Block device driver configuration
3# 3#
4 4
5if BLOCK
6
5menu "Multi-device support (RAID and LVM)" 7menu "Multi-device support (RAID and LVM)"
6 8
7config MD 9config MD
@@ -136,16 +138,16 @@ config MD_RAID456
136 If unsure, say Y. 138 If unsure, say Y.
137 139
138config MD_RAID5_RESHAPE 140config MD_RAID5_RESHAPE
139 bool "Support adding drives to a raid-5 array (experimental)" 141 bool "Support adding drives to a raid-5 array"
140 depends on MD_RAID456 && EXPERIMENTAL 142 depends on MD_RAID456
143 default y
141 ---help--- 144 ---help---
142 A RAID-5 set can be expanded by adding extra drives. This 145 A RAID-5 set can be expanded by adding extra drives. This
143 requires "restriping" the array which means (almost) every 146 requires "restriping" the array which means (almost) every
144 block must be written to a different place. 147 block must be written to a different place.
145 148
146 This option allows such restriping to be done while the array 149 This option allows such restriping to be done while the array
147 is online. However it is still EXPERIMENTAL code. It should 150 is online.
148 work, but please be sure that you have backups.
149 151
150 You will need mdadm version 2.4.1 or later to use this 152 You will need mdadm version 2.4.1 or later to use this
151 feature safely. During the early stage of reshape there is 153 feature safely. During the early stage of reshape there is
@@ -162,6 +164,8 @@ config MD_RAID5_RESHAPE
162 There should be enough spares already present to make the new 164 There should be enough spares already present to make the new
163 array workable. 165 array workable.
164 166
167 If unsure, say Y.
168
165config MD_MULTIPATH 169config MD_MULTIPATH
166 tristate "Multipath I/O support" 170 tristate "Multipath I/O support"
167 depends on BLK_DEV_MD 171 depends on BLK_DEV_MD
@@ -199,6 +203,14 @@ config BLK_DEV_DM
199 203
200 If unsure, say N. 204 If unsure, say N.
201 205
206config DM_DEBUG
207 boolean "Device mapper debugging support"
208 depends on BLK_DEV_DM && EXPERIMENTAL
209 ---help---
210 Enable this for messages that may help debug device-mapper problems.
211
212 If unsure, say N.
213
202config DM_CRYPT 214config DM_CRYPT
203 tristate "Crypt target support" 215 tristate "Crypt target support"
204 depends on BLK_DEV_DM && EXPERIMENTAL 216 depends on BLK_DEV_DM && EXPERIMENTAL
@@ -251,3 +263,4 @@ config DM_MULTIPATH_EMC
251 263
252endmenu 264endmenu
253 265
266endif
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index ecc56765d949..8e67634e79a0 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -613,6 +613,7 @@ static inline unsigned long file_page_offset(unsigned long chunk)
613static inline struct page *filemap_get_page(struct bitmap *bitmap, 613static inline struct page *filemap_get_page(struct bitmap *bitmap,
614 unsigned long chunk) 614 unsigned long chunk)
615{ 615{
616 if (file_page_index(chunk) >= bitmap->file_pages) return NULL;
616 return bitmap->filemap[file_page_index(chunk) - file_page_index(0)]; 617 return bitmap->filemap[file_page_index(chunk) - file_page_index(0)];
617} 618}
618 619
@@ -739,6 +740,7 @@ static void bitmap_file_set_bit(struct bitmap *bitmap, sector_t block)
739 } 740 }
740 741
741 page = filemap_get_page(bitmap, chunk); 742 page = filemap_get_page(bitmap, chunk);
743 if (!page) return;
742 bit = file_page_offset(chunk); 744 bit = file_page_offset(chunk);
743 745
744 /* set the bit */ 746 /* set the bit */
@@ -1322,6 +1324,18 @@ static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int n
1322 1324
1323} 1325}
1324 1326
1327/* dirty the memory and file bits for bitmap chunks "s" to "e" */
1328void bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s, unsigned long e)
1329{
1330 unsigned long chunk;
1331
1332 for (chunk = s; chunk <= e; chunk++) {
1333 sector_t sec = chunk << CHUNK_BLOCK_SHIFT(bitmap);
1334 bitmap_set_memory_bits(bitmap, sec, 1);
1335 bitmap_file_set_bit(bitmap, sec);
1336 }
1337}
1338
1325/* 1339/*
1326 * flush out any pending updates 1340 * flush out any pending updates
1327 */ 1341 */
@@ -1430,8 +1444,7 @@ int bitmap_create(mddev_t *mddev)
1430 if (err) 1444 if (err)
1431 goto error; 1445 goto error;
1432 1446
1433 bitmap->chunkshift = find_first_bit(&bitmap->chunksize, 1447 bitmap->chunkshift = ffz(~bitmap->chunksize);
1434 sizeof(bitmap->chunksize));
1435 1448
1436 /* now that chunksize and chunkshift are set, we can use these macros */ 1449 /* now that chunksize and chunkshift are set, we can use these macros */
1437 chunks = (blocks + CHUNK_BLOCK_RATIO(bitmap) - 1) / 1450 chunks = (blocks + CHUNK_BLOCK_RATIO(bitmap) - 1) /
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index bdbd34993a80..655d816760e5 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * Copyright (C) 2003 Christophe Saout <christophe@saout.de> 2 * Copyright (C) 2003 Christophe Saout <christophe@saout.de>
3 * Copyright (C) 2004 Clemens Fruhwirth <clemens@endorphin.org> 3 * Copyright (C) 2004 Clemens Fruhwirth <clemens@endorphin.org>
4 * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
4 * 5 *
5 * This file is released under the GPL. 6 * This file is released under the GPL.
6 */ 7 */
@@ -22,17 +23,19 @@
22#include "dm.h" 23#include "dm.h"
23 24
24#define DM_MSG_PREFIX "crypt" 25#define DM_MSG_PREFIX "crypt"
26#define MESG_STR(x) x, sizeof(x)
25 27
26/* 28/*
27 * per bio private data 29 * per bio private data
28 */ 30 */
29struct crypt_io { 31struct crypt_io {
30 struct dm_target *target; 32 struct dm_target *target;
31 struct bio *bio; 33 struct bio *base_bio;
32 struct bio *first_clone; 34 struct bio *first_clone;
33 struct work_struct work; 35 struct work_struct work;
34 atomic_t pending; 36 atomic_t pending;
35 int error; 37 int error;
38 int post_process;
36}; 39};
37 40
38/* 41/*
@@ -63,6 +66,7 @@ struct crypt_iv_operations {
63 * Crypt: maps a linear range of a block device 66 * Crypt: maps a linear range of a block device
64 * and encrypts / decrypts at the same time. 67 * and encrypts / decrypts at the same time.
65 */ 68 */
69enum flags { DM_CRYPT_SUSPENDED, DM_CRYPT_KEY_VALID };
66struct crypt_config { 70struct crypt_config {
67 struct dm_dev *dev; 71 struct dm_dev *dev;
68 sector_t start; 72 sector_t start;
@@ -73,6 +77,7 @@ struct crypt_config {
73 */ 77 */
74 mempool_t *io_pool; 78 mempool_t *io_pool;
75 mempool_t *page_pool; 79 mempool_t *page_pool;
80 struct bio_set *bs;
76 81
77 /* 82 /*
78 * crypto related data 83 * crypto related data
@@ -86,11 +91,12 @@ struct crypt_config {
86 char cipher[CRYPTO_MAX_ALG_NAME]; 91 char cipher[CRYPTO_MAX_ALG_NAME];
87 char chainmode[CRYPTO_MAX_ALG_NAME]; 92 char chainmode[CRYPTO_MAX_ALG_NAME];
88 struct crypto_blkcipher *tfm; 93 struct crypto_blkcipher *tfm;
94 unsigned long flags;
89 unsigned int key_size; 95 unsigned int key_size;
90 u8 key[0]; 96 u8 key[0];
91}; 97};
92 98
93#define MIN_IOS 256 99#define MIN_IOS 16
94#define MIN_POOL_PAGES 32 100#define MIN_POOL_PAGES 32
95#define MIN_BIO_PAGES 8 101#define MIN_BIO_PAGES 8
96 102
@@ -306,6 +312,14 @@ static int crypt_convert(struct crypt_config *cc,
306 return r; 312 return r;
307} 313}
308 314
315 static void dm_crypt_bio_destructor(struct bio *bio)
316 {
317 struct crypt_io *io = bio->bi_private;
318 struct crypt_config *cc = io->target->private;
319
320 bio_free(bio, cc->bs);
321 }
322
309/* 323/*
310 * Generate a new unfragmented bio with the given size 324 * Generate a new unfragmented bio with the given size
311 * This should never violate the device limitations 325 * This should never violate the device limitations
@@ -315,34 +329,33 @@ static struct bio *
315crypt_alloc_buffer(struct crypt_config *cc, unsigned int size, 329crypt_alloc_buffer(struct crypt_config *cc, unsigned int size,
316 struct bio *base_bio, unsigned int *bio_vec_idx) 330 struct bio *base_bio, unsigned int *bio_vec_idx)
317{ 331{
318 struct bio *bio; 332 struct bio *clone;
319 unsigned int nr_iovecs = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; 333 unsigned int nr_iovecs = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
320 gfp_t gfp_mask = GFP_NOIO | __GFP_HIGHMEM; 334 gfp_t gfp_mask = GFP_NOIO | __GFP_HIGHMEM;
321 unsigned int i; 335 unsigned int i;
322 336
323 /* 337 if (base_bio) {
324 * Use __GFP_NOMEMALLOC to tell the VM to act less aggressively and 338 clone = bio_alloc_bioset(GFP_NOIO, base_bio->bi_max_vecs, cc->bs);
325 * to fail earlier. This is not necessary but increases throughput. 339 __bio_clone(clone, base_bio);
326 * FIXME: Is this really intelligent? 340 } else
327 */ 341 clone = bio_alloc_bioset(GFP_NOIO, nr_iovecs, cc->bs);
328 if (base_bio) 342
329 bio = bio_clone(base_bio, GFP_NOIO|__GFP_NOMEMALLOC); 343 if (!clone)
330 else
331 bio = bio_alloc(GFP_NOIO|__GFP_NOMEMALLOC, nr_iovecs);
332 if (!bio)
333 return NULL; 344 return NULL;
334 345
346 clone->bi_destructor = dm_crypt_bio_destructor;
347
335 /* if the last bio was not complete, continue where that one ended */ 348 /* if the last bio was not complete, continue where that one ended */
336 bio->bi_idx = *bio_vec_idx; 349 clone->bi_idx = *bio_vec_idx;
337 bio->bi_vcnt = *bio_vec_idx; 350 clone->bi_vcnt = *bio_vec_idx;
338 bio->bi_size = 0; 351 clone->bi_size = 0;
339 bio->bi_flags &= ~(1 << BIO_SEG_VALID); 352 clone->bi_flags &= ~(1 << BIO_SEG_VALID);
340 353
341 /* bio->bi_idx pages have already been allocated */ 354 /* clone->bi_idx pages have already been allocated */
342 size -= bio->bi_idx * PAGE_SIZE; 355 size -= clone->bi_idx * PAGE_SIZE;
343 356
344 for(i = bio->bi_idx; i < nr_iovecs; i++) { 357 for (i = clone->bi_idx; i < nr_iovecs; i++) {
345 struct bio_vec *bv = bio_iovec_idx(bio, i); 358 struct bio_vec *bv = bio_iovec_idx(clone, i);
346 359
347 bv->bv_page = mempool_alloc(cc->page_pool, gfp_mask); 360 bv->bv_page = mempool_alloc(cc->page_pool, gfp_mask);
348 if (!bv->bv_page) 361 if (!bv->bv_page)
@@ -353,7 +366,7 @@ crypt_alloc_buffer(struct crypt_config *cc, unsigned int size,
353 * return a partially allocated bio, the caller will then try 366 * return a partially allocated bio, the caller will then try
354 * to allocate additional bios while submitting this partial bio 367 * to allocate additional bios while submitting this partial bio
355 */ 368 */
356 if ((i - bio->bi_idx) == (MIN_BIO_PAGES - 1)) 369 if ((i - clone->bi_idx) == (MIN_BIO_PAGES - 1))
357 gfp_mask = (gfp_mask | __GFP_NOWARN) & ~__GFP_WAIT; 370 gfp_mask = (gfp_mask | __GFP_NOWARN) & ~__GFP_WAIT;
358 371
359 bv->bv_offset = 0; 372 bv->bv_offset = 0;
@@ -362,13 +375,13 @@ crypt_alloc_buffer(struct crypt_config *cc, unsigned int size,
362 else 375 else
363 bv->bv_len = size; 376 bv->bv_len = size;
364 377
365 bio->bi_size += bv->bv_len; 378 clone->bi_size += bv->bv_len;
366 bio->bi_vcnt++; 379 clone->bi_vcnt++;
367 size -= bv->bv_len; 380 size -= bv->bv_len;
368 } 381 }
369 382
370 if (!bio->bi_size) { 383 if (!clone->bi_size) {
371 bio_put(bio); 384 bio_put(clone);
372 return NULL; 385 return NULL;
373 } 386 }
374 387
@@ -376,13 +389,13 @@ crypt_alloc_buffer(struct crypt_config *cc, unsigned int size,
376 * Remember the last bio_vec allocated to be able 389 * Remember the last bio_vec allocated to be able
377 * to correctly continue after the splitting. 390 * to correctly continue after the splitting.
378 */ 391 */
379 *bio_vec_idx = bio->bi_vcnt; 392 *bio_vec_idx = clone->bi_vcnt;
380 393
381 return bio; 394 return clone;
382} 395}
383 396
384static void crypt_free_buffer_pages(struct crypt_config *cc, 397static void crypt_free_buffer_pages(struct crypt_config *cc,
385 struct bio *bio, unsigned int bytes) 398 struct bio *clone, unsigned int bytes)
386{ 399{
387 unsigned int i, start, end; 400 unsigned int i, start, end;
388 struct bio_vec *bv; 401 struct bio_vec *bv;
@@ -396,19 +409,19 @@ static void crypt_free_buffer_pages(struct crypt_config *cc,
396 * A fix to the bi_idx issue in the kernel is in the works, so 409 * A fix to the bi_idx issue in the kernel is in the works, so
397 * we will hopefully be able to revert to the cleaner solution soon. 410 * we will hopefully be able to revert to the cleaner solution soon.
398 */ 411 */
399 i = bio->bi_vcnt - 1; 412 i = clone->bi_vcnt - 1;
400 bv = bio_iovec_idx(bio, i); 413 bv = bio_iovec_idx(clone, i);
401 end = (i << PAGE_SHIFT) + (bv->bv_offset + bv->bv_len) - bio->bi_size; 414 end = (i << PAGE_SHIFT) + (bv->bv_offset + bv->bv_len) - clone->bi_size;
402 start = end - bytes; 415 start = end - bytes;
403 416
404 start >>= PAGE_SHIFT; 417 start >>= PAGE_SHIFT;
405 if (!bio->bi_size) 418 if (!clone->bi_size)
406 end = bio->bi_vcnt; 419 end = clone->bi_vcnt;
407 else 420 else
408 end >>= PAGE_SHIFT; 421 end >>= PAGE_SHIFT;
409 422
410 for(i = start; i < end; i++) { 423 for (i = start; i < end; i++) {
411 bv = bio_iovec_idx(bio, i); 424 bv = bio_iovec_idx(clone, i);
412 BUG_ON(!bv->bv_page); 425 BUG_ON(!bv->bv_page);
413 mempool_free(bv->bv_page, cc->page_pool); 426 mempool_free(bv->bv_page, cc->page_pool);
414 bv->bv_page = NULL; 427 bv->bv_page = NULL;
@@ -432,7 +445,7 @@ static void dec_pending(struct crypt_io *io, int error)
432 if (io->first_clone) 445 if (io->first_clone)
433 bio_put(io->first_clone); 446 bio_put(io->first_clone);
434 447
435 bio_endio(io->bio, io->bio->bi_size, io->error); 448 bio_endio(io->base_bio, io->base_bio->bi_size, io->error);
436 449
437 mempool_free(io, cc->io_pool); 450 mempool_free(io, cc->io_pool);
438} 451}
@@ -441,29 +454,179 @@ static void dec_pending(struct crypt_io *io, int error)
441 * kcryptd: 454 * kcryptd:
442 * 455 *
443 * Needed because it would be very unwise to do decryption in an 456 * Needed because it would be very unwise to do decryption in an
444 * interrupt context, so bios returning from read requests get 457 * interrupt context.
445 * queued here.
446 */ 458 */
447static struct workqueue_struct *_kcryptd_workqueue; 459static struct workqueue_struct *_kcryptd_workqueue;
460static void kcryptd_do_work(void *data);
448 461
449static void kcryptd_do_work(void *data) 462static void kcryptd_queue_io(struct crypt_io *io)
450{ 463{
451 struct crypt_io *io = (struct crypt_io *) data; 464 INIT_WORK(&io->work, kcryptd_do_work, io);
452 struct crypt_config *cc = (struct crypt_config *) io->target->private; 465 queue_work(_kcryptd_workqueue, &io->work);
466}
467
468static int crypt_endio(struct bio *clone, unsigned int done, int error)
469{
470 struct crypt_io *io = clone->bi_private;
471 struct crypt_config *cc = io->target->private;
472 unsigned read_io = bio_data_dir(clone) == READ;
473
474 /*
475 * free the processed pages, even if
476 * it's only a partially completed write
477 */
478 if (!read_io)
479 crypt_free_buffer_pages(cc, clone, done);
480
481 /* keep going - not finished yet */
482 if (unlikely(clone->bi_size))
483 return 1;
484
485 if (!read_io)
486 goto out;
487
488 if (unlikely(!bio_flagged(clone, BIO_UPTODATE))) {
489 error = -EIO;
490 goto out;
491 }
492
493 bio_put(clone);
494 io->post_process = 1;
495 kcryptd_queue_io(io);
496 return 0;
497
498out:
499 bio_put(clone);
500 dec_pending(io, error);
501 return error;
502}
503
504static void clone_init(struct crypt_io *io, struct bio *clone)
505{
506 struct crypt_config *cc = io->target->private;
507
508 clone->bi_private = io;
509 clone->bi_end_io = crypt_endio;
510 clone->bi_bdev = cc->dev->bdev;
511 clone->bi_rw = io->base_bio->bi_rw;
512}
513
514static void process_read(struct crypt_io *io)
515{
516 struct crypt_config *cc = io->target->private;
517 struct bio *base_bio = io->base_bio;
518 struct bio *clone;
519 sector_t sector = base_bio->bi_sector - io->target->begin;
520
521 atomic_inc(&io->pending);
522
523 /*
524 * The block layer might modify the bvec array, so always
525 * copy the required bvecs because we need the original
526 * one in order to decrypt the whole bio data *afterwards*.
527 */
528 clone = bio_alloc_bioset(GFP_NOIO, bio_segments(base_bio), cc->bs);
529 if (unlikely(!clone)) {
530 dec_pending(io, -ENOMEM);
531 return;
532 }
533
534 clone_init(io, clone);
535 clone->bi_destructor = dm_crypt_bio_destructor;
536 clone->bi_idx = 0;
537 clone->bi_vcnt = bio_segments(base_bio);
538 clone->bi_size = base_bio->bi_size;
539 clone->bi_sector = cc->start + sector;
540 memcpy(clone->bi_io_vec, bio_iovec(base_bio),
541 sizeof(struct bio_vec) * clone->bi_vcnt);
542
543 generic_make_request(clone);
544}
545
546static void process_write(struct crypt_io *io)
547{
548 struct crypt_config *cc = io->target->private;
549 struct bio *base_bio = io->base_bio;
550 struct bio *clone;
453 struct convert_context ctx; 551 struct convert_context ctx;
454 int r; 552 unsigned remaining = base_bio->bi_size;
553 sector_t sector = base_bio->bi_sector - io->target->begin;
554 unsigned bvec_idx = 0;
555
556 atomic_inc(&io->pending);
557
558 crypt_convert_init(cc, &ctx, NULL, base_bio, sector, 1);
559
560 /*
561 * The allocated buffers can be smaller than the whole bio,
562 * so repeat the whole process until all the data can be handled.
563 */
564 while (remaining) {
565 clone = crypt_alloc_buffer(cc, base_bio->bi_size,
566 io->first_clone, &bvec_idx);
567 if (unlikely(!clone)) {
568 dec_pending(io, -ENOMEM);
569 return;
570 }
571
572 ctx.bio_out = clone;
573
574 if (unlikely(crypt_convert(cc, &ctx) < 0)) {
575 crypt_free_buffer_pages(cc, clone, clone->bi_size);
576 bio_put(clone);
577 dec_pending(io, -EIO);
578 return;
579 }
580
581 clone_init(io, clone);
582 clone->bi_sector = cc->start + sector;
583
584 if (!io->first_clone) {
585 /*
586 * hold a reference to the first clone, because it
587 * holds the bio_vec array and that can't be freed
588 * before all other clones are released
589 */
590 bio_get(clone);
591 io->first_clone = clone;
592 }
593
594 remaining -= clone->bi_size;
595 sector += bio_sectors(clone);
596
597 /* prevent bio_put of first_clone */
598 if (remaining)
599 atomic_inc(&io->pending);
455 600
456 crypt_convert_init(cc, &ctx, io->bio, io->bio, 601 generic_make_request(clone);
457 io->bio->bi_sector - io->target->begin, 0);
458 r = crypt_convert(cc, &ctx);
459 602
460 dec_pending(io, r); 603 /* out of memory -> run queues */
604 if (remaining)
605 blk_congestion_wait(bio_data_dir(clone), HZ/100);
606 }
461} 607}
462 608
463static void kcryptd_queue_io(struct crypt_io *io) 609static void process_read_endio(struct crypt_io *io)
464{ 610{
465 INIT_WORK(&io->work, kcryptd_do_work, io); 611 struct crypt_config *cc = io->target->private;
466 queue_work(_kcryptd_workqueue, &io->work); 612 struct convert_context ctx;
613
614 crypt_convert_init(cc, &ctx, io->base_bio, io->base_bio,
615 io->base_bio->bi_sector - io->target->begin, 0);
616
617 dec_pending(io, crypt_convert(cc, &ctx));
618}
619
620static void kcryptd_do_work(void *data)
621{
622 struct crypt_io *io = data;
623
624 if (io->post_process)
625 process_read_endio(io);
626 else if (bio_data_dir(io->base_bio) == READ)
627 process_read(io);
628 else
629 process_write(io);
467} 630}
468 631
469/* 632/*
@@ -477,7 +640,7 @@ static int crypt_decode_key(u8 *key, char *hex, unsigned int size)
477 640
478 buffer[2] = '\0'; 641 buffer[2] = '\0';
479 642
480 for(i = 0; i < size; i++) { 643 for (i = 0; i < size; i++) {
481 buffer[0] = *hex++; 644 buffer[0] = *hex++;
482 buffer[1] = *hex++; 645 buffer[1] = *hex++;
483 646
@@ -500,13 +663,38 @@ static void crypt_encode_key(char *hex, u8 *key, unsigned int size)
500{ 663{
501 unsigned int i; 664 unsigned int i;
502 665
503 for(i = 0; i < size; i++) { 666 for (i = 0; i < size; i++) {
504 sprintf(hex, "%02x", *key); 667 sprintf(hex, "%02x", *key);
505 hex += 2; 668 hex += 2;
506 key++; 669 key++;
507 } 670 }
508} 671}
509 672
673static int crypt_set_key(struct crypt_config *cc, char *key)
674{
675 unsigned key_size = strlen(key) >> 1;
676
677 if (cc->key_size && cc->key_size != key_size)
678 return -EINVAL;
679
680 cc->key_size = key_size; /* initial settings */
681
682 if ((!key_size && strcmp(key, "-")) ||
683 (key_size && crypt_decode_key(cc->key, key, key_size) < 0))
684 return -EINVAL;
685
686 set_bit(DM_CRYPT_KEY_VALID, &cc->flags);
687
688 return 0;
689}
690
691static int crypt_wipe_key(struct crypt_config *cc)
692{
693 clear_bit(DM_CRYPT_KEY_VALID, &cc->flags);
694 memset(&cc->key, 0, cc->key_size * sizeof(u8));
695 return 0;
696}
697
510/* 698/*
511 * Construct an encryption mapping: 699 * Construct an encryption mapping:
512 * <cipher> <key> <iv_offset> <dev_path> <start> 700 * <cipher> <key> <iv_offset> <dev_path> <start>
@@ -539,16 +727,14 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
539 727
540 key_size = strlen(argv[1]) >> 1; 728 key_size = strlen(argv[1]) >> 1;
541 729
542 cc = kmalloc(sizeof(*cc) + key_size * sizeof(u8), GFP_KERNEL); 730 cc = kzalloc(sizeof(*cc) + key_size * sizeof(u8), GFP_KERNEL);
543 if (cc == NULL) { 731 if (cc == NULL) {
544 ti->error = 732 ti->error =
545 "Cannot allocate transparent encryption context"; 733 "Cannot allocate transparent encryption context";
546 return -ENOMEM; 734 return -ENOMEM;
547 } 735 }
548 736
549 cc->key_size = key_size; 737 if (crypt_set_key(cc, argv[1])) {
550 if ((!key_size && strcmp(argv[1], "-") != 0) ||
551 (key_size && crypt_decode_key(cc->key, argv[1], key_size) < 0)) {
552 ti->error = "Error decoding key"; 738 ti->error = "Error decoding key";
553 goto bad1; 739 goto bad1;
554 } 740 }
@@ -626,6 +812,12 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
626 goto bad4; 812 goto bad4;
627 } 813 }
628 814
815 cc->bs = bioset_create(MIN_IOS, MIN_IOS, 4);
816 if (!cc->bs) {
817 ti->error = "Cannot allocate crypt bioset";
818 goto bad_bs;
819 }
820
629 if (crypto_blkcipher_setkey(tfm, cc->key, key_size) < 0) { 821 if (crypto_blkcipher_setkey(tfm, cc->key, key_size) < 0) {
630 ti->error = "Error setting key"; 822 ti->error = "Error setting key";
631 goto bad5; 823 goto bad5;
@@ -665,6 +857,8 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
665 return 0; 857 return 0;
666 858
667bad5: 859bad5:
860 bioset_free(cc->bs);
861bad_bs:
668 mempool_destroy(cc->page_pool); 862 mempool_destroy(cc->page_pool);
669bad4: 863bad4:
670 mempool_destroy(cc->io_pool); 864 mempool_destroy(cc->io_pool);
@@ -684,6 +878,7 @@ static void crypt_dtr(struct dm_target *ti)
684{ 878{
685 struct crypt_config *cc = (struct crypt_config *) ti->private; 879 struct crypt_config *cc = (struct crypt_config *) ti->private;
686 880
881 bioset_free(cc->bs);
687 mempool_destroy(cc->page_pool); 882 mempool_destroy(cc->page_pool);
688 mempool_destroy(cc->io_pool); 883 mempool_destroy(cc->io_pool);
689 884
@@ -698,147 +893,21 @@ static void crypt_dtr(struct dm_target *ti)
698 kfree(cc); 893 kfree(cc);
699} 894}
700 895
701static int crypt_endio(struct bio *bio, unsigned int done, int error)
702{
703 struct crypt_io *io = (struct crypt_io *) bio->bi_private;
704 struct crypt_config *cc = (struct crypt_config *) io->target->private;
705
706 if (bio_data_dir(bio) == WRITE) {
707 /*
708 * free the processed pages, even if
709 * it's only a partially completed write
710 */
711 crypt_free_buffer_pages(cc, bio, done);
712 }
713
714 if (bio->bi_size)
715 return 1;
716
717 bio_put(bio);
718
719 /*
720 * successful reads are decrypted by the worker thread
721 */
722 if ((bio_data_dir(bio) == READ)
723 && bio_flagged(bio, BIO_UPTODATE)) {
724 kcryptd_queue_io(io);
725 return 0;
726 }
727
728 dec_pending(io, error);
729 return error;
730}
731
732static inline struct bio *
733crypt_clone(struct crypt_config *cc, struct crypt_io *io, struct bio *bio,
734 sector_t sector, unsigned int *bvec_idx,
735 struct convert_context *ctx)
736{
737 struct bio *clone;
738
739 if (bio_data_dir(bio) == WRITE) {
740 clone = crypt_alloc_buffer(cc, bio->bi_size,
741 io->first_clone, bvec_idx);
742 if (clone) {
743 ctx->bio_out = clone;
744 if (crypt_convert(cc, ctx) < 0) {
745 crypt_free_buffer_pages(cc, clone,
746 clone->bi_size);
747 bio_put(clone);
748 return NULL;
749 }
750 }
751 } else {
752 /*
753 * The block layer might modify the bvec array, so always
754 * copy the required bvecs because we need the original
755 * one in order to decrypt the whole bio data *afterwards*.
756 */
757 clone = bio_alloc(GFP_NOIO, bio_segments(bio));
758 if (clone) {
759 clone->bi_idx = 0;
760 clone->bi_vcnt = bio_segments(bio);
761 clone->bi_size = bio->bi_size;
762 memcpy(clone->bi_io_vec, bio_iovec(bio),
763 sizeof(struct bio_vec) * clone->bi_vcnt);
764 }
765 }
766
767 if (!clone)
768 return NULL;
769
770 clone->bi_private = io;
771 clone->bi_end_io = crypt_endio;
772 clone->bi_bdev = cc->dev->bdev;
773 clone->bi_sector = cc->start + sector;
774 clone->bi_rw = bio->bi_rw;
775
776 return clone;
777}
778
779static int crypt_map(struct dm_target *ti, struct bio *bio, 896static int crypt_map(struct dm_target *ti, struct bio *bio,
780 union map_info *map_context) 897 union map_info *map_context)
781{ 898{
782 struct crypt_config *cc = (struct crypt_config *) ti->private; 899 struct crypt_config *cc = ti->private;
783 struct crypt_io *io = mempool_alloc(cc->io_pool, GFP_NOIO); 900 struct crypt_io *io;
784 struct convert_context ctx;
785 struct bio *clone;
786 unsigned int remaining = bio->bi_size;
787 sector_t sector = bio->bi_sector - ti->begin;
788 unsigned int bvec_idx = 0;
789 901
902 io = mempool_alloc(cc->io_pool, GFP_NOIO);
790 io->target = ti; 903 io->target = ti;
791 io->bio = bio; 904 io->base_bio = bio;
792 io->first_clone = NULL; 905 io->first_clone = NULL;
793 io->error = 0; 906 io->error = io->post_process = 0;
794 atomic_set(&io->pending, 1); /* hold a reference */ 907 atomic_set(&io->pending, 0);
795 908 kcryptd_queue_io(io);
796 if (bio_data_dir(bio) == WRITE)
797 crypt_convert_init(cc, &ctx, NULL, bio, sector, 1);
798
799 /*
800 * The allocated buffers can be smaller than the whole bio,
801 * so repeat the whole process until all the data can be handled.
802 */
803 while (remaining) {
804 clone = crypt_clone(cc, io, bio, sector, &bvec_idx, &ctx);
805 if (!clone)
806 goto cleanup;
807
808 if (!io->first_clone) {
809 /*
810 * hold a reference to the first clone, because it
811 * holds the bio_vec array and that can't be freed
812 * before all other clones are released
813 */
814 bio_get(clone);
815 io->first_clone = clone;
816 }
817 atomic_inc(&io->pending);
818 909
819 remaining -= clone->bi_size;
820 sector += bio_sectors(clone);
821
822 generic_make_request(clone);
823
824 /* out of memory -> run queues */
825 if (remaining)
826 blk_congestion_wait(bio_data_dir(clone), HZ/100);
827 }
828
829 /* drop reference, clones could have returned before we reach this */
830 dec_pending(io, 0);
831 return 0; 910 return 0;
832
833cleanup:
834 if (io->first_clone) {
835 dec_pending(io, -ENOMEM);
836 return 0;
837 }
838
839 /* if no bio has been dispatched yet, we can directly return the error */
840 mempool_free(io, cc->io_pool);
841 return -ENOMEM;
842} 911}
843 912
844static int crypt_status(struct dm_target *ti, status_type_t type, 913static int crypt_status(struct dm_target *ti, status_type_t type,
@@ -883,14 +952,71 @@ static int crypt_status(struct dm_target *ti, status_type_t type,
883 return 0; 952 return 0;
884} 953}
885 954
955static void crypt_postsuspend(struct dm_target *ti)
956{
957 struct crypt_config *cc = ti->private;
958
959 set_bit(DM_CRYPT_SUSPENDED, &cc->flags);
960}
961
962static int crypt_preresume(struct dm_target *ti)
963{
964 struct crypt_config *cc = ti->private;
965
966 if (!test_bit(DM_CRYPT_KEY_VALID, &cc->flags)) {
967 DMERR("aborting resume - crypt key is not set.");
968 return -EAGAIN;
969 }
970
971 return 0;
972}
973
974static void crypt_resume(struct dm_target *ti)
975{
976 struct crypt_config *cc = ti->private;
977
978 clear_bit(DM_CRYPT_SUSPENDED, &cc->flags);
979}
980
981/* Message interface
982 * key set <key>
983 * key wipe
984 */
985static int crypt_message(struct dm_target *ti, unsigned argc, char **argv)
986{
987 struct crypt_config *cc = ti->private;
988
989 if (argc < 2)
990 goto error;
991
992 if (!strnicmp(argv[0], MESG_STR("key"))) {
993 if (!test_bit(DM_CRYPT_SUSPENDED, &cc->flags)) {
994 DMWARN("not suspended during key manipulation.");
995 return -EINVAL;
996 }
997 if (argc == 3 && !strnicmp(argv[1], MESG_STR("set")))
998 return crypt_set_key(cc, argv[2]);
999 if (argc == 2 && !strnicmp(argv[1], MESG_STR("wipe")))
1000 return crypt_wipe_key(cc);
1001 }
1002
1003error:
1004 DMWARN("unrecognised message received.");
1005 return -EINVAL;
1006}
1007
886static struct target_type crypt_target = { 1008static struct target_type crypt_target = {
887 .name = "crypt", 1009 .name = "crypt",
888 .version= {1, 1, 0}, 1010 .version= {1, 3, 0},
889 .module = THIS_MODULE, 1011 .module = THIS_MODULE,
890 .ctr = crypt_ctr, 1012 .ctr = crypt_ctr,
891 .dtr = crypt_dtr, 1013 .dtr = crypt_dtr,
892 .map = crypt_map, 1014 .map = crypt_map,
893 .status = crypt_status, 1015 .status = crypt_status,
1016 .postsuspend = crypt_postsuspend,
1017 .preresume = crypt_preresume,
1018 .resume = crypt_resume,
1019 .message = crypt_message,
894}; 1020};
895 1021
896static int __init dm_crypt_init(void) 1022static int __init dm_crypt_init(void)
diff --git a/drivers/md/dm-emc.c b/drivers/md/dm-emc.c
index 2a374ccb30dd..2b2d45d7baaa 100644
--- a/drivers/md/dm-emc.c
+++ b/drivers/md/dm-emc.c
@@ -126,7 +126,8 @@ static struct request *get_failover_req(struct emc_handler *h,
126 memset(&rq->cmd, 0, BLK_MAX_CDB); 126 memset(&rq->cmd, 0, BLK_MAX_CDB);
127 127
128 rq->timeout = EMC_FAILOVER_TIMEOUT; 128 rq->timeout = EMC_FAILOVER_TIMEOUT;
129 rq->flags |= (REQ_BLOCK_PC | REQ_FAILFAST | REQ_NOMERGE); 129 rq->cmd_type = REQ_TYPE_BLOCK_PC;
130 rq->cmd_flags |= REQ_FAILFAST | REQ_NOMERGE;
130 131
131 return rq; 132 return rq;
132} 133}
diff --git a/drivers/md/dm-exception-store.c b/drivers/md/dm-exception-store.c
index d12379b5cdb5..99cdffa7fbfe 100644
--- a/drivers/md/dm-exception-store.c
+++ b/drivers/md/dm-exception-store.c
@@ -17,6 +17,7 @@
17#include <linux/slab.h> 17#include <linux/slab.h>
18 18
19#define DM_MSG_PREFIX "snapshots" 19#define DM_MSG_PREFIX "snapshots"
20#define DM_CHUNK_SIZE_DEFAULT_SECTORS 32 /* 16KB */
20 21
21/*----------------------------------------------------------------- 22/*-----------------------------------------------------------------
22 * Persistent snapshots, by persistent we mean that the snapshot 23 * Persistent snapshots, by persistent we mean that the snapshot
@@ -150,6 +151,7 @@ static int alloc_area(struct pstore *ps)
150static void free_area(struct pstore *ps) 151static void free_area(struct pstore *ps)
151{ 152{
152 vfree(ps->area); 153 vfree(ps->area);
154 ps->area = NULL;
153} 155}
154 156
155/* 157/*
@@ -198,48 +200,79 @@ static int read_header(struct pstore *ps, int *new_snapshot)
198 int r; 200 int r;
199 struct disk_header *dh; 201 struct disk_header *dh;
200 chunk_t chunk_size; 202 chunk_t chunk_size;
203 int chunk_size_supplied = 1;
201 204
202 r = chunk_io(ps, 0, READ); 205 /*
206 * Use default chunk size (or hardsect_size, if larger) if none supplied
207 */
208 if (!ps->snap->chunk_size) {
209 ps->snap->chunk_size = max(DM_CHUNK_SIZE_DEFAULT_SECTORS,
210 bdev_hardsect_size(ps->snap->cow->bdev) >> 9);
211 ps->snap->chunk_mask = ps->snap->chunk_size - 1;
212 ps->snap->chunk_shift = ffs(ps->snap->chunk_size) - 1;
213 chunk_size_supplied = 0;
214 }
215
216 r = dm_io_get(sectors_to_pages(ps->snap->chunk_size));
203 if (r) 217 if (r)
204 return r; 218 return r;
205 219
220 r = alloc_area(ps);
221 if (r)
222 goto bad1;
223
224 r = chunk_io(ps, 0, READ);
225 if (r)
226 goto bad2;
227
206 dh = (struct disk_header *) ps->area; 228 dh = (struct disk_header *) ps->area;
207 229
208 if (le32_to_cpu(dh->magic) == 0) { 230 if (le32_to_cpu(dh->magic) == 0) {
209 *new_snapshot = 1; 231 *new_snapshot = 1;
232 return 0;
233 }
210 234
211 } else if (le32_to_cpu(dh->magic) == SNAP_MAGIC) { 235 if (le32_to_cpu(dh->magic) != SNAP_MAGIC) {
212 *new_snapshot = 0; 236 DMWARN("Invalid or corrupt snapshot");
213 ps->valid = le32_to_cpu(dh->valid);
214 ps->version = le32_to_cpu(dh->version);
215 chunk_size = le32_to_cpu(dh->chunk_size);
216 if (ps->snap->chunk_size != chunk_size) {
217 DMWARN("chunk size %llu in device metadata overrides "
218 "table chunk size of %llu.",
219 (unsigned long long)chunk_size,
220 (unsigned long long)ps->snap->chunk_size);
221
222 /* We had a bogus chunk_size. Fix stuff up. */
223 dm_io_put(sectors_to_pages(ps->snap->chunk_size));
224 free_area(ps);
225
226 ps->snap->chunk_size = chunk_size;
227 ps->snap->chunk_mask = chunk_size - 1;
228 ps->snap->chunk_shift = ffs(chunk_size) - 1;
229
230 r = alloc_area(ps);
231 if (r)
232 return r;
233
234 r = dm_io_get(sectors_to_pages(chunk_size));
235 if (r)
236 return r;
237 }
238 } else {
239 DMWARN("Invalid/corrupt snapshot");
240 r = -ENXIO; 237 r = -ENXIO;
238 goto bad2;
241 } 239 }
242 240
241 *new_snapshot = 0;
242 ps->valid = le32_to_cpu(dh->valid);
243 ps->version = le32_to_cpu(dh->version);
244 chunk_size = le32_to_cpu(dh->chunk_size);
245
246 if (!chunk_size_supplied || ps->snap->chunk_size == chunk_size)
247 return 0;
248
249 DMWARN("chunk size %llu in device metadata overrides "
250 "table chunk size of %llu.",
251 (unsigned long long)chunk_size,
252 (unsigned long long)ps->snap->chunk_size);
253
254 /* We had a bogus chunk_size. Fix stuff up. */
255 dm_io_put(sectors_to_pages(ps->snap->chunk_size));
256 free_area(ps);
257
258 ps->snap->chunk_size = chunk_size;
259 ps->snap->chunk_mask = chunk_size - 1;
260 ps->snap->chunk_shift = ffs(chunk_size) - 1;
261
262 r = dm_io_get(sectors_to_pages(chunk_size));
263 if (r)
264 return r;
265
266 r = alloc_area(ps);
267 if (r)
268 goto bad1;
269
270 return 0;
271
272bad2:
273 free_area(ps);
274bad1:
275 dm_io_put(sectors_to_pages(ps->snap->chunk_size));
243 return r; 276 return r;
244} 277}
245 278
@@ -263,42 +296,29 @@ static int write_header(struct pstore *ps)
263 */ 296 */
264static struct disk_exception *get_exception(struct pstore *ps, uint32_t index) 297static struct disk_exception *get_exception(struct pstore *ps, uint32_t index)
265{ 298{
266 if (index >= ps->exceptions_per_area) 299 BUG_ON(index >= ps->exceptions_per_area);
267 return NULL;
268 300
269 return ((struct disk_exception *) ps->area) + index; 301 return ((struct disk_exception *) ps->area) + index;
270} 302}
271 303
272static int read_exception(struct pstore *ps, 304static void read_exception(struct pstore *ps,
273 uint32_t index, struct disk_exception *result) 305 uint32_t index, struct disk_exception *result)
274{ 306{
275 struct disk_exception *e; 307 struct disk_exception *e = get_exception(ps, index);
276
277 e = get_exception(ps, index);
278 if (!e)
279 return -EINVAL;
280 308
281 /* copy it */ 309 /* copy it */
282 result->old_chunk = le64_to_cpu(e->old_chunk); 310 result->old_chunk = le64_to_cpu(e->old_chunk);
283 result->new_chunk = le64_to_cpu(e->new_chunk); 311 result->new_chunk = le64_to_cpu(e->new_chunk);
284
285 return 0;
286} 312}
287 313
288static int write_exception(struct pstore *ps, 314static void write_exception(struct pstore *ps,
289 uint32_t index, struct disk_exception *de) 315 uint32_t index, struct disk_exception *de)
290{ 316{
291 struct disk_exception *e; 317 struct disk_exception *e = get_exception(ps, index);
292
293 e = get_exception(ps, index);
294 if (!e)
295 return -EINVAL;
296 318
297 /* copy it */ 319 /* copy it */
298 e->old_chunk = cpu_to_le64(de->old_chunk); 320 e->old_chunk = cpu_to_le64(de->old_chunk);
299 e->new_chunk = cpu_to_le64(de->new_chunk); 321 e->new_chunk = cpu_to_le64(de->new_chunk);
300
301 return 0;
302} 322}
303 323
304/* 324/*
@@ -316,10 +336,7 @@ static int insert_exceptions(struct pstore *ps, int *full)
316 *full = 1; 336 *full = 1;
317 337
318 for (i = 0; i < ps->exceptions_per_area; i++) { 338 for (i = 0; i < ps->exceptions_per_area; i++) {
319 r = read_exception(ps, i, &de); 339 read_exception(ps, i, &de);
320
321 if (r)
322 return r;
323 340
324 /* 341 /*
325 * If the new_chunk is pointing at the start of 342 * If the new_chunk is pointing at the start of
@@ -519,6 +536,16 @@ static void persistent_commit(struct exception_store *store,
519 if (r) 536 if (r)
520 ps->valid = 0; 537 ps->valid = 0;
521 538
539 /*
540 * Have we completely filled the current area ?
541 */
542 if (ps->current_committed == ps->exceptions_per_area) {
543 ps->current_committed = 0;
544 r = zero_area(ps, ps->current_area + 1);
545 if (r)
546 ps->valid = 0;
547 }
548
522 for (i = 0; i < ps->callback_count; i++) { 549 for (i = 0; i < ps->callback_count; i++) {
523 cb = ps->callbacks + i; 550 cb = ps->callbacks + i;
524 cb->callback(cb->context, r == 0 ? 1 : 0); 551 cb->callback(cb->context, r == 0 ? 1 : 0);
@@ -526,16 +553,6 @@ static void persistent_commit(struct exception_store *store,
526 553
527 ps->callback_count = 0; 554 ps->callback_count = 0;
528 } 555 }
529
530 /*
531 * Have we completely filled the current area ?
532 */
533 if (ps->current_committed == ps->exceptions_per_area) {
534 ps->current_committed = 0;
535 r = zero_area(ps, ps->current_area + 1);
536 if (r)
537 ps->valid = 0;
538 }
539} 556}
540 557
541static void persistent_drop(struct exception_store *store) 558static void persistent_drop(struct exception_store *store)
@@ -547,32 +564,22 @@ static void persistent_drop(struct exception_store *store)
547 DMWARN("write header failed"); 564 DMWARN("write header failed");
548} 565}
549 566
550int dm_create_persistent(struct exception_store *store, uint32_t chunk_size) 567int dm_create_persistent(struct exception_store *store)
551{ 568{
552 int r;
553 struct pstore *ps; 569 struct pstore *ps;
554 570
555 r = dm_io_get(sectors_to_pages(chunk_size));
556 if (r)
557 return r;
558
559 /* allocate the pstore */ 571 /* allocate the pstore */
560 ps = kmalloc(sizeof(*ps), GFP_KERNEL); 572 ps = kmalloc(sizeof(*ps), GFP_KERNEL);
561 if (!ps) { 573 if (!ps)
562 r = -ENOMEM; 574 return -ENOMEM;
563 goto bad;
564 }
565 575
566 ps->snap = store->snap; 576 ps->snap = store->snap;
567 ps->valid = 1; 577 ps->valid = 1;
568 ps->version = SNAPSHOT_DISK_VERSION; 578 ps->version = SNAPSHOT_DISK_VERSION;
579 ps->area = NULL;
569 ps->next_free = 2; /* skipping the header and first area */ 580 ps->next_free = 2; /* skipping the header and first area */
570 ps->current_committed = 0; 581 ps->current_committed = 0;
571 582
572 r = alloc_area(ps);
573 if (r)
574 goto bad;
575
576 ps->callback_count = 0; 583 ps->callback_count = 0;
577 atomic_set(&ps->pending_count, 0); 584 atomic_set(&ps->pending_count, 0);
578 ps->callbacks = NULL; 585 ps->callbacks = NULL;
@@ -586,13 +593,6 @@ int dm_create_persistent(struct exception_store *store, uint32_t chunk_size)
586 store->context = ps; 593 store->context = ps;
587 594
588 return 0; 595 return 0;
589
590 bad:
591 dm_io_put(sectors_to_pages(chunk_size));
592 if (ps && ps->area)
593 free_area(ps);
594 kfree(ps);
595 return r;
596} 596}
597 597
598/*----------------------------------------------------------------- 598/*-----------------------------------------------------------------
@@ -642,18 +642,16 @@ static void transient_fraction_full(struct exception_store *store,
642 *denominator = get_dev_size(store->snap->cow->bdev); 642 *denominator = get_dev_size(store->snap->cow->bdev);
643} 643}
644 644
645int dm_create_transient(struct exception_store *store, 645int dm_create_transient(struct exception_store *store)
646 struct dm_snapshot *s, int blocksize)
647{ 646{
648 struct transient_c *tc; 647 struct transient_c *tc;
649 648
650 memset(store, 0, sizeof(*store));
651 store->destroy = transient_destroy; 649 store->destroy = transient_destroy;
652 store->read_metadata = transient_read_metadata; 650 store->read_metadata = transient_read_metadata;
653 store->prepare_exception = transient_prepare; 651 store->prepare_exception = transient_prepare;
654 store->commit_exception = transient_commit; 652 store->commit_exception = transient_commit;
653 store->drop_snapshot = NULL;
655 store->fraction_full = transient_fraction_full; 654 store->fraction_full = transient_fraction_full;
656 store->snap = s;
657 655
658 tc = kmalloc(sizeof(struct transient_c), GFP_KERNEL); 656 tc = kmalloc(sizeof(struct transient_c), GFP_KERNEL);
659 if (!tc) 657 if (!tc)
diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c
index 47b3c62bbdb8..00234909b3db 100644
--- a/drivers/md/dm-linear.c
+++ b/drivers/md/dm-linear.c
@@ -98,14 +98,31 @@ static int linear_status(struct dm_target *ti, status_type_t type,
98 return 0; 98 return 0;
99} 99}
100 100
101static int linear_ioctl(struct dm_target *ti, struct inode *inode,
102 struct file *filp, unsigned int cmd,
103 unsigned long arg)
104{
105 struct linear_c *lc = (struct linear_c *) ti->private;
106 struct block_device *bdev = lc->dev->bdev;
107 struct file fake_file = {};
108 struct dentry fake_dentry = {};
109
110 fake_file.f_mode = lc->dev->mode;
111 fake_file.f_dentry = &fake_dentry;
112 fake_dentry.d_inode = bdev->bd_inode;
113
114 return blkdev_driver_ioctl(bdev->bd_inode, &fake_file, bdev->bd_disk, cmd, arg);
115}
116
101static struct target_type linear_target = { 117static struct target_type linear_target = {
102 .name = "linear", 118 .name = "linear",
103 .version= {1, 0, 1}, 119 .version= {1, 0, 2},
104 .module = THIS_MODULE, 120 .module = THIS_MODULE,
105 .ctr = linear_ctr, 121 .ctr = linear_ctr,
106 .dtr = linear_dtr, 122 .dtr = linear_dtr,
107 .map = linear_map, 123 .map = linear_map,
108 .status = linear_status, 124 .status = linear_status,
125 .ioctl = linear_ioctl,
109}; 126};
110 127
111int __init dm_linear_init(void) 128int __init dm_linear_init(void)
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 93f701ea87bc..d754e0bc6e90 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -114,12 +114,10 @@ static void trigger_event(void *data);
114 114
115static struct pgpath *alloc_pgpath(void) 115static struct pgpath *alloc_pgpath(void)
116{ 116{
117 struct pgpath *pgpath = kmalloc(sizeof(*pgpath), GFP_KERNEL); 117 struct pgpath *pgpath = kzalloc(sizeof(*pgpath), GFP_KERNEL);
118 118
119 if (pgpath) { 119 if (pgpath)
120 memset(pgpath, 0, sizeof(*pgpath));
121 pgpath->path.is_active = 1; 120 pgpath->path.is_active = 1;
122 }
123 121
124 return pgpath; 122 return pgpath;
125} 123}
@@ -133,12 +131,10 @@ static struct priority_group *alloc_priority_group(void)
133{ 131{
134 struct priority_group *pg; 132 struct priority_group *pg;
135 133
136 pg = kmalloc(sizeof(*pg), GFP_KERNEL); 134 pg = kzalloc(sizeof(*pg), GFP_KERNEL);
137 if (!pg)
138 return NULL;
139 135
140 memset(pg, 0, sizeof(*pg)); 136 if (pg)
141 INIT_LIST_HEAD(&pg->pgpaths); 137 INIT_LIST_HEAD(&pg->pgpaths);
142 138
143 return pg; 139 return pg;
144} 140}
@@ -168,13 +164,12 @@ static void free_priority_group(struct priority_group *pg,
168 kfree(pg); 164 kfree(pg);
169} 165}
170 166
171static struct multipath *alloc_multipath(void) 167static struct multipath *alloc_multipath(struct dm_target *ti)
172{ 168{
173 struct multipath *m; 169 struct multipath *m;
174 170
175 m = kmalloc(sizeof(*m), GFP_KERNEL); 171 m = kzalloc(sizeof(*m), GFP_KERNEL);
176 if (m) { 172 if (m) {
177 memset(m, 0, sizeof(*m));
178 INIT_LIST_HEAD(&m->priority_groups); 173 INIT_LIST_HEAD(&m->priority_groups);
179 spin_lock_init(&m->lock); 174 spin_lock_init(&m->lock);
180 m->queue_io = 1; 175 m->queue_io = 1;
@@ -185,6 +180,8 @@ static struct multipath *alloc_multipath(void)
185 kfree(m); 180 kfree(m);
186 return NULL; 181 return NULL;
187 } 182 }
183 m->ti = ti;
184 ti->private = m;
188 } 185 }
189 186
190 return m; 187 return m;
@@ -557,8 +554,7 @@ static struct pgpath *parse_path(struct arg_set *as, struct path_selector *ps,
557} 554}
558 555
559static struct priority_group *parse_priority_group(struct arg_set *as, 556static struct priority_group *parse_priority_group(struct arg_set *as,
560 struct multipath *m, 557 struct multipath *m)
561 struct dm_target *ti)
562{ 558{
563 static struct param _params[] = { 559 static struct param _params[] = {
564 {1, 1024, "invalid number of paths"}, 560 {1, 1024, "invalid number of paths"},
@@ -568,6 +564,7 @@ static struct priority_group *parse_priority_group(struct arg_set *as,
568 int r; 564 int r;
569 unsigned i, nr_selector_args, nr_params; 565 unsigned i, nr_selector_args, nr_params;
570 struct priority_group *pg; 566 struct priority_group *pg;
567 struct dm_target *ti = m->ti;
571 568
572 if (as->argc < 2) { 569 if (as->argc < 2) {
573 as->argc = 0; 570 as->argc = 0;
@@ -624,12 +621,12 @@ static struct priority_group *parse_priority_group(struct arg_set *as,
624 return NULL; 621 return NULL;
625} 622}
626 623
627static int parse_hw_handler(struct arg_set *as, struct multipath *m, 624static int parse_hw_handler(struct arg_set *as, struct multipath *m)
628 struct dm_target *ti)
629{ 625{
630 int r; 626 int r;
631 struct hw_handler_type *hwht; 627 struct hw_handler_type *hwht;
632 unsigned hw_argc; 628 unsigned hw_argc;
629 struct dm_target *ti = m->ti;
633 630
634 static struct param _params[] = { 631 static struct param _params[] = {
635 {0, 1024, "invalid number of hardware handler args"}, 632 {0, 1024, "invalid number of hardware handler args"},
@@ -661,11 +658,11 @@ static int parse_hw_handler(struct arg_set *as, struct multipath *m,
661 return 0; 658 return 0;
662} 659}
663 660
664static int parse_features(struct arg_set *as, struct multipath *m, 661static int parse_features(struct arg_set *as, struct multipath *m)
665 struct dm_target *ti)
666{ 662{
667 int r; 663 int r;
668 unsigned argc; 664 unsigned argc;
665 struct dm_target *ti = m->ti;
669 666
670 static struct param _params[] = { 667 static struct param _params[] = {
671 {0, 1, "invalid number of feature args"}, 668 {0, 1, "invalid number of feature args"},
@@ -704,19 +701,17 @@ static int multipath_ctr(struct dm_target *ti, unsigned int argc,
704 as.argc = argc; 701 as.argc = argc;
705 as.argv = argv; 702 as.argv = argv;
706 703
707 m = alloc_multipath(); 704 m = alloc_multipath(ti);
708 if (!m) { 705 if (!m) {
709 ti->error = "can't allocate multipath"; 706 ti->error = "can't allocate multipath";
710 return -EINVAL; 707 return -EINVAL;
711 } 708 }
712 709
713 m->ti = ti; 710 r = parse_features(&as, m);
714
715 r = parse_features(&as, m, ti);
716 if (r) 711 if (r)
717 goto bad; 712 goto bad;
718 713
719 r = parse_hw_handler(&as, m, ti); 714 r = parse_hw_handler(&as, m);
720 if (r) 715 if (r)
721 goto bad; 716 goto bad;
722 717
@@ -732,7 +727,7 @@ static int multipath_ctr(struct dm_target *ti, unsigned int argc,
732 while (as.argc) { 727 while (as.argc) {
733 struct priority_group *pg; 728 struct priority_group *pg;
734 729
735 pg = parse_priority_group(&as, m, ti); 730 pg = parse_priority_group(&as, m);
736 if (!pg) { 731 if (!pg) {
737 r = -EINVAL; 732 r = -EINVAL;
738 goto bad; 733 goto bad;
@@ -752,8 +747,6 @@ static int multipath_ctr(struct dm_target *ti, unsigned int argc,
752 goto bad; 747 goto bad;
753 } 748 }
754 749
755 ti->private = m;
756
757 return 0; 750 return 0;
758 751
759 bad: 752 bad:
@@ -1266,12 +1259,47 @@ error:
1266 return -EINVAL; 1259 return -EINVAL;
1267} 1260}
1268 1261
1262static int multipath_ioctl(struct dm_target *ti, struct inode *inode,
1263 struct file *filp, unsigned int cmd,
1264 unsigned long arg)
1265{
1266 struct multipath *m = (struct multipath *) ti->private;
1267 struct block_device *bdev = NULL;
1268 unsigned long flags;
1269 struct file fake_file = {};
1270 struct dentry fake_dentry = {};
1271 int r = 0;
1272
1273 fake_file.f_dentry = &fake_dentry;
1274
1275 spin_lock_irqsave(&m->lock, flags);
1276
1277 if (!m->current_pgpath)
1278 __choose_pgpath(m);
1279
1280 if (m->current_pgpath) {
1281 bdev = m->current_pgpath->path.dev->bdev;
1282 fake_dentry.d_inode = bdev->bd_inode;
1283 fake_file.f_mode = m->current_pgpath->path.dev->mode;
1284 }
1285
1286 if (m->queue_io)
1287 r = -EAGAIN;
1288 else if (!bdev)
1289 r = -EIO;
1290
1291 spin_unlock_irqrestore(&m->lock, flags);
1292
1293 return r ? : blkdev_driver_ioctl(bdev->bd_inode, &fake_file,
1294 bdev->bd_disk, cmd, arg);
1295}
1296
1269/*----------------------------------------------------------------- 1297/*-----------------------------------------------------------------
1270 * Module setup 1298 * Module setup
1271 *---------------------------------------------------------------*/ 1299 *---------------------------------------------------------------*/
1272static struct target_type multipath_target = { 1300static struct target_type multipath_target = {
1273 .name = "multipath", 1301 .name = "multipath",
1274 .version = {1, 0, 4}, 1302 .version = {1, 0, 5},
1275 .module = THIS_MODULE, 1303 .module = THIS_MODULE,
1276 .ctr = multipath_ctr, 1304 .ctr = multipath_ctr,
1277 .dtr = multipath_dtr, 1305 .dtr = multipath_dtr,
@@ -1281,6 +1309,7 @@ static struct target_type multipath_target = {
1281 .resume = multipath_resume, 1309 .resume = multipath_resume,
1282 .status = multipath_status, 1310 .status = multipath_status,
1283 .message = multipath_message, 1311 .message = multipath_message,
1312 .ioctl = multipath_ioctl,
1284}; 1313};
1285 1314
1286static int __init dm_multipath_init(void) 1315static int __init dm_multipath_init(void)
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index c54de989eb00..659224cb7c53 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -1213,9 +1213,9 @@ static int mirror_status(struct dm_target *ti, status_type_t type,
1213 break; 1213 break;
1214 1214
1215 case STATUSTYPE_TABLE: 1215 case STATUSTYPE_TABLE:
1216 DMEMIT("%d ", ms->nr_mirrors); 1216 DMEMIT("%d", ms->nr_mirrors);
1217 for (m = 0; m < ms->nr_mirrors; m++) 1217 for (m = 0; m < ms->nr_mirrors; m++)
1218 DMEMIT("%s %llu ", ms->mirror[m].dev->name, 1218 DMEMIT(" %s %llu", ms->mirror[m].dev->name,
1219 (unsigned long long)ms->mirror[m].offset); 1219 (unsigned long long)ms->mirror[m].offset);
1220 } 1220 }
1221 1221
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index 1d0fafda0f76..5281e0094072 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -39,6 +39,9 @@
39 */ 39 */
40#define SNAPSHOT_PAGES 256 40#define SNAPSHOT_PAGES 256
41 41
42struct workqueue_struct *ksnapd;
43static void flush_queued_bios(void *data);
44
42struct pending_exception { 45struct pending_exception {
43 struct exception e; 46 struct exception e;
44 47
@@ -56,7 +59,7 @@ struct pending_exception {
56 59
57 /* 60 /*
58 * The primary pending_exception is the one that holds 61 * The primary pending_exception is the one that holds
59 * the sibling_count and the list of origin_bios for a 62 * the ref_count and the list of origin_bios for a
60 * group of pending_exceptions. It is always last to get freed. 63 * group of pending_exceptions. It is always last to get freed.
61 * These fields get set up when writing to the origin. 64 * These fields get set up when writing to the origin.
62 */ 65 */
@@ -69,7 +72,7 @@ struct pending_exception {
69 * the sibling concerned and not pe->primary_pe->snap->lock unless 72 * the sibling concerned and not pe->primary_pe->snap->lock unless
70 * they are the same. 73 * they are the same.
71 */ 74 */
72 atomic_t sibling_count; 75 atomic_t ref_count;
73 76
74 /* Pointer back to snapshot context */ 77 /* Pointer back to snapshot context */
75 struct dm_snapshot *snap; 78 struct dm_snapshot *snap;
@@ -387,15 +390,46 @@ static inline ulong round_up(ulong n, ulong size)
387 return (n + size) & ~size; 390 return (n + size) & ~size;
388} 391}
389 392
390static void read_snapshot_metadata(struct dm_snapshot *s) 393static int set_chunk_size(struct dm_snapshot *s, const char *chunk_size_arg,
394 char **error)
391{ 395{
392 if (s->store.read_metadata(&s->store)) { 396 unsigned long chunk_size;
393 down_write(&s->lock); 397 char *value;
394 s->valid = 0; 398
395 up_write(&s->lock); 399 chunk_size = simple_strtoul(chunk_size_arg, &value, 10);
400 if (*chunk_size_arg == '\0' || *value != '\0') {
401 *error = "Invalid chunk size";
402 return -EINVAL;
403 }
404
405 if (!chunk_size) {
406 s->chunk_size = s->chunk_mask = s->chunk_shift = 0;
407 return 0;
408 }
409
410 /*
411 * Chunk size must be multiple of page size. Silently
412 * round up if it's not.
413 */
414 chunk_size = round_up(chunk_size, PAGE_SIZE >> 9);
415
416 /* Check chunk_size is a power of 2 */
417 if (chunk_size & (chunk_size - 1)) {
418 *error = "Chunk size is not a power of 2";
419 return -EINVAL;
420 }
396 421
397 dm_table_event(s->table); 422 /* Validate the chunk size against the device block size */
423 if (chunk_size % (bdev_hardsect_size(s->cow->bdev) >> 9)) {
424 *error = "Chunk size is not a multiple of device blocksize";
425 return -EINVAL;
398 } 426 }
427
428 s->chunk_size = chunk_size;
429 s->chunk_mask = chunk_size - 1;
430 s->chunk_shift = ffs(chunk_size) - 1;
431
432 return 0;
399} 433}
400 434
401/* 435/*
@@ -404,15 +438,12 @@ static void read_snapshot_metadata(struct dm_snapshot *s)
404static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) 438static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
405{ 439{
406 struct dm_snapshot *s; 440 struct dm_snapshot *s;
407 unsigned long chunk_size;
408 int r = -EINVAL; 441 int r = -EINVAL;
409 char persistent; 442 char persistent;
410 char *origin_path; 443 char *origin_path;
411 char *cow_path; 444 char *cow_path;
412 char *value;
413 int blocksize;
414 445
415 if (argc < 4) { 446 if (argc != 4) {
416 ti->error = "requires exactly 4 arguments"; 447 ti->error = "requires exactly 4 arguments";
417 r = -EINVAL; 448 r = -EINVAL;
418 goto bad1; 449 goto bad1;
@@ -428,13 +459,6 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
428 goto bad1; 459 goto bad1;
429 } 460 }
430 461
431 chunk_size = simple_strtoul(argv[3], &value, 10);
432 if (chunk_size == 0 || value == NULL) {
433 ti->error = "Invalid chunk size";
434 r = -EINVAL;
435 goto bad1;
436 }
437
438 s = kmalloc(sizeof(*s), GFP_KERNEL); 462 s = kmalloc(sizeof(*s), GFP_KERNEL);
439 if (s == NULL) { 463 if (s == NULL) {
440 ti->error = "Cannot allocate snapshot context private " 464 ti->error = "Cannot allocate snapshot context private "
@@ -457,36 +481,17 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
457 goto bad2; 481 goto bad2;
458 } 482 }
459 483
460 /* 484 r = set_chunk_size(s, argv[3], &ti->error);
461 * Chunk size must be multiple of page size. Silently 485 if (r)
462 * round up if it's not.
463 */
464 chunk_size = round_up(chunk_size, PAGE_SIZE >> 9);
465
466 /* Validate the chunk size against the device block size */
467 blocksize = s->cow->bdev->bd_disk->queue->hardsect_size;
468 if (chunk_size % (blocksize >> 9)) {
469 ti->error = "Chunk size is not a multiple of device blocksize";
470 r = -EINVAL;
471 goto bad3;
472 }
473
474 /* Check chunk_size is a power of 2 */
475 if (chunk_size & (chunk_size - 1)) {
476 ti->error = "Chunk size is not a power of 2";
477 r = -EINVAL;
478 goto bad3; 486 goto bad3;
479 }
480 487
481 s->chunk_size = chunk_size;
482 s->chunk_mask = chunk_size - 1;
483 s->type = persistent; 488 s->type = persistent;
484 s->chunk_shift = ffs(chunk_size) - 1;
485 489
486 s->valid = 1; 490 s->valid = 1;
487 s->active = 0; 491 s->active = 0;
488 s->last_percent = 0; 492 s->last_percent = 0;
489 init_rwsem(&s->lock); 493 init_rwsem(&s->lock);
494 spin_lock_init(&s->pe_lock);
490 s->table = ti->table; 495 s->table = ti->table;
491 496
492 /* Allocate hash table for COW data */ 497 /* Allocate hash table for COW data */
@@ -496,16 +501,12 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
496 goto bad3; 501 goto bad3;
497 } 502 }
498 503
499 /*
500 * Check the persistent flag - done here because we need the iobuf
501 * to check the LV header
502 */
503 s->store.snap = s; 504 s->store.snap = s;
504 505
505 if (persistent == 'P') 506 if (persistent == 'P')
506 r = dm_create_persistent(&s->store, chunk_size); 507 r = dm_create_persistent(&s->store);
507 else 508 else
508 r = dm_create_transient(&s->store, s, blocksize); 509 r = dm_create_transient(&s->store);
509 510
510 if (r) { 511 if (r) {
511 ti->error = "Couldn't create exception store"; 512 ti->error = "Couldn't create exception store";
@@ -520,7 +521,14 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
520 } 521 }
521 522
522 /* Metadata must only be loaded into one table at once */ 523 /* Metadata must only be loaded into one table at once */
523 read_snapshot_metadata(s); 524 r = s->store.read_metadata(&s->store);
525 if (r) {
526 ti->error = "Failed to read snapshot metadata";
527 goto bad6;
528 }
529
530 bio_list_init(&s->queued_bios);
531 INIT_WORK(&s->queued_bios_work, flush_queued_bios, s);
524 532
525 /* Add snapshot to the list of snapshots for this origin */ 533 /* Add snapshot to the list of snapshots for this origin */
526 /* Exceptions aren't triggered till snapshot_resume() is called */ 534 /* Exceptions aren't triggered till snapshot_resume() is called */
@@ -560,6 +568,8 @@ static void snapshot_dtr(struct dm_target *ti)
560{ 568{
561 struct dm_snapshot *s = (struct dm_snapshot *) ti->private; 569 struct dm_snapshot *s = (struct dm_snapshot *) ti->private;
562 570
571 flush_workqueue(ksnapd);
572
563 /* Prevent further origin writes from using this snapshot. */ 573 /* Prevent further origin writes from using this snapshot. */
564 /* After this returns there can be no new kcopyd jobs. */ 574 /* After this returns there can be no new kcopyd jobs. */
565 unregister_snapshot(s); 575 unregister_snapshot(s);
@@ -593,6 +603,19 @@ static void flush_bios(struct bio *bio)
593 } 603 }
594} 604}
595 605
606static void flush_queued_bios(void *data)
607{
608 struct dm_snapshot *s = (struct dm_snapshot *) data;
609 struct bio *queued_bios;
610 unsigned long flags;
611
612 spin_lock_irqsave(&s->pe_lock, flags);
613 queued_bios = bio_list_get(&s->queued_bios);
614 spin_unlock_irqrestore(&s->pe_lock, flags);
615
616 flush_bios(queued_bios);
617}
618
596/* 619/*
597 * Error a list of buffers. 620 * Error a list of buffers.
598 */ 621 */
@@ -608,28 +631,7 @@ static void error_bios(struct bio *bio)
608 } 631 }
609} 632}
610 633
611static inline void error_snapshot_bios(struct pending_exception *pe) 634static void __invalidate_snapshot(struct dm_snapshot *s, int err)
612{
613 error_bios(bio_list_get(&pe->snapshot_bios));
614}
615
616static struct bio *__flush_bios(struct pending_exception *pe)
617{
618 /*
619 * If this pe is involved in a write to the origin and
620 * it is the last sibling to complete then release
621 * the bios for the original write to the origin.
622 */
623
624 if (pe->primary_pe &&
625 atomic_dec_and_test(&pe->primary_pe->sibling_count))
626 return bio_list_get(&pe->primary_pe->origin_bios);
627
628 return NULL;
629}
630
631static void __invalidate_snapshot(struct dm_snapshot *s,
632 struct pending_exception *pe, int err)
633{ 635{
634 if (!s->valid) 636 if (!s->valid)
635 return; 637 return;
@@ -639,9 +641,6 @@ static void __invalidate_snapshot(struct dm_snapshot *s,
639 else if (err == -ENOMEM) 641 else if (err == -ENOMEM)
640 DMERR("Invalidating snapshot: Unable to allocate exception."); 642 DMERR("Invalidating snapshot: Unable to allocate exception.");
641 643
642 if (pe)
643 remove_exception(&pe->e);
644
645 if (s->store.drop_snapshot) 644 if (s->store.drop_snapshot)
646 s->store.drop_snapshot(&s->store); 645 s->store.drop_snapshot(&s->store);
647 646
@@ -650,78 +649,95 @@ static void __invalidate_snapshot(struct dm_snapshot *s,
650 dm_table_event(s->table); 649 dm_table_event(s->table);
651} 650}
652 651
652static void get_pending_exception(struct pending_exception *pe)
653{
654 atomic_inc(&pe->ref_count);
655}
656
657static struct bio *put_pending_exception(struct pending_exception *pe)
658{
659 struct pending_exception *primary_pe;
660 struct bio *origin_bios = NULL;
661
662 primary_pe = pe->primary_pe;
663
664 /*
665 * If this pe is involved in a write to the origin and
666 * it is the last sibling to complete then release
667 * the bios for the original write to the origin.
668 */
669 if (primary_pe &&
670 atomic_dec_and_test(&primary_pe->ref_count))
671 origin_bios = bio_list_get(&primary_pe->origin_bios);
672
673 /*
674 * Free the pe if it's not linked to an origin write or if
675 * it's not itself a primary pe.
676 */
677 if (!primary_pe || primary_pe != pe)
678 free_pending_exception(pe);
679
680 /*
681 * Free the primary pe if nothing references it.
682 */
683 if (primary_pe && !atomic_read(&primary_pe->ref_count))
684 free_pending_exception(primary_pe);
685
686 return origin_bios;
687}
688
653static void pending_complete(struct pending_exception *pe, int success) 689static void pending_complete(struct pending_exception *pe, int success)
654{ 690{
655 struct exception *e; 691 struct exception *e;
656 struct pending_exception *primary_pe;
657 struct dm_snapshot *s = pe->snap; 692 struct dm_snapshot *s = pe->snap;
658 struct bio *flush = NULL; 693 struct bio *origin_bios = NULL;
694 struct bio *snapshot_bios = NULL;
695 int error = 0;
659 696
660 if (!success) { 697 if (!success) {
661 /* Read/write error - snapshot is unusable */ 698 /* Read/write error - snapshot is unusable */
662 down_write(&s->lock); 699 down_write(&s->lock);
663 __invalidate_snapshot(s, pe, -EIO); 700 __invalidate_snapshot(s, -EIO);
664 flush = __flush_bios(pe); 701 error = 1;
665 up_write(&s->lock);
666
667 error_snapshot_bios(pe);
668 goto out; 702 goto out;
669 } 703 }
670 704
671 e = alloc_exception(); 705 e = alloc_exception();
672 if (!e) { 706 if (!e) {
673 down_write(&s->lock); 707 down_write(&s->lock);
674 __invalidate_snapshot(s, pe, -ENOMEM); 708 __invalidate_snapshot(s, -ENOMEM);
675 flush = __flush_bios(pe); 709 error = 1;
676 up_write(&s->lock);
677
678 error_snapshot_bios(pe);
679 goto out; 710 goto out;
680 } 711 }
681 *e = pe->e; 712 *e = pe->e;
682 713
683 /*
684 * Add a proper exception, and remove the
685 * in-flight exception from the list.
686 */
687 down_write(&s->lock); 714 down_write(&s->lock);
688 if (!s->valid) { 715 if (!s->valid) {
689 flush = __flush_bios(pe);
690 up_write(&s->lock);
691
692 free_exception(e); 716 free_exception(e);
693 717 error = 1;
694 error_snapshot_bios(pe);
695 goto out; 718 goto out;
696 } 719 }
697 720
721 /*
722 * Add a proper exception, and remove the
723 * in-flight exception from the list.
724 */
698 insert_exception(&s->complete, e); 725 insert_exception(&s->complete, e);
726
727 out:
699 remove_exception(&pe->e); 728 remove_exception(&pe->e);
700 flush = __flush_bios(pe); 729 snapshot_bios = bio_list_get(&pe->snapshot_bios);
730 origin_bios = put_pending_exception(pe);
701 731
702 up_write(&s->lock); 732 up_write(&s->lock);
703 733
704 /* Submit any pending write bios */ 734 /* Submit any pending write bios */
705 flush_bios(bio_list_get(&pe->snapshot_bios)); 735 if (error)
706 736 error_bios(snapshot_bios);
707 out: 737 else
708 primary_pe = pe->primary_pe; 738 flush_bios(snapshot_bios);
709
710 /*
711 * Free the pe if it's not linked to an origin write or if
712 * it's not itself a primary pe.
713 */
714 if (!primary_pe || primary_pe != pe)
715 free_pending_exception(pe);
716
717 /*
718 * Free the primary pe if nothing references it.
719 */
720 if (primary_pe && !atomic_read(&primary_pe->sibling_count))
721 free_pending_exception(primary_pe);
722 739
723 if (flush) 740 flush_bios(origin_bios);
724 flush_bios(flush);
725} 741}
726 742
727static void commit_callback(void *context, int success) 743static void commit_callback(void *context, int success)
@@ -822,7 +838,7 @@ __find_pending_exception(struct dm_snapshot *s, struct bio *bio)
822 bio_list_init(&pe->origin_bios); 838 bio_list_init(&pe->origin_bios);
823 bio_list_init(&pe->snapshot_bios); 839 bio_list_init(&pe->snapshot_bios);
824 pe->primary_pe = NULL; 840 pe->primary_pe = NULL;
825 atomic_set(&pe->sibling_count, 1); 841 atomic_set(&pe->ref_count, 0);
826 pe->snap = s; 842 pe->snap = s;
827 pe->started = 0; 843 pe->started = 0;
828 844
@@ -831,6 +847,7 @@ __find_pending_exception(struct dm_snapshot *s, struct bio *bio)
831 return NULL; 847 return NULL;
832 } 848 }
833 849
850 get_pending_exception(pe);
834 insert_exception(&s->pending, &pe->e); 851 insert_exception(&s->pending, &pe->e);
835 852
836 out: 853 out:
@@ -850,7 +867,6 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
850{ 867{
851 struct exception *e; 868 struct exception *e;
852 struct dm_snapshot *s = (struct dm_snapshot *) ti->private; 869 struct dm_snapshot *s = (struct dm_snapshot *) ti->private;
853 int copy_needed = 0;
854 int r = 1; 870 int r = 1;
855 chunk_t chunk; 871 chunk_t chunk;
856 struct pending_exception *pe = NULL; 872 struct pending_exception *pe = NULL;
@@ -865,32 +881,31 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
865 if (unlikely(bio_barrier(bio))) 881 if (unlikely(bio_barrier(bio)))
866 return -EOPNOTSUPP; 882 return -EOPNOTSUPP;
867 883
884 /* FIXME: should only take write lock if we need
885 * to copy an exception */
886 down_write(&s->lock);
887
888 if (!s->valid) {
889 r = -EIO;
890 goto out_unlock;
891 }
892
893 /* If the block is already remapped - use that, else remap it */
894 e = lookup_exception(&s->complete, chunk);
895 if (e) {
896 remap_exception(s, e, bio);
897 goto out_unlock;
898 }
899
868 /* 900 /*
869 * Write to snapshot - higher level takes care of RW/RO 901 * Write to snapshot - higher level takes care of RW/RO
870 * flags so we should only get this if we are 902 * flags so we should only get this if we are
871 * writeable. 903 * writeable.
872 */ 904 */
873 if (bio_rw(bio) == WRITE) { 905 if (bio_rw(bio) == WRITE) {
874
875 /* FIXME: should only take write lock if we need
876 * to copy an exception */
877 down_write(&s->lock);
878
879 if (!s->valid) {
880 r = -EIO;
881 goto out_unlock;
882 }
883
884 /* If the block is already remapped - use that, else remap it */
885 e = lookup_exception(&s->complete, chunk);
886 if (e) {
887 remap_exception(s, e, bio);
888 goto out_unlock;
889 }
890
891 pe = __find_pending_exception(s, bio); 906 pe = __find_pending_exception(s, bio);
892 if (!pe) { 907 if (!pe) {
893 __invalidate_snapshot(s, pe, -ENOMEM); 908 __invalidate_snapshot(s, -ENOMEM);
894 r = -EIO; 909 r = -EIO;
895 goto out_unlock; 910 goto out_unlock;
896 } 911 }
@@ -898,45 +913,27 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
898 remap_exception(s, &pe->e, bio); 913 remap_exception(s, &pe->e, bio);
899 bio_list_add(&pe->snapshot_bios, bio); 914 bio_list_add(&pe->snapshot_bios, bio);
900 915
916 r = 0;
917
901 if (!pe->started) { 918 if (!pe->started) {
902 /* this is protected by snap->lock */ 919 /* this is protected by snap->lock */
903 pe->started = 1; 920 pe->started = 1;
904 copy_needed = 1; 921 up_write(&s->lock);
905 }
906
907 r = 0;
908
909 out_unlock:
910 up_write(&s->lock);
911
912 if (copy_needed)
913 start_copy(pe); 922 start_copy(pe);
914 } else { 923 goto out;
924 }
925 } else
915 /* 926 /*
916 * FIXME: this read path scares me because we 927 * FIXME: this read path scares me because we
917 * always use the origin when we have a pending 928 * always use the origin when we have a pending
918 * exception. However I can't think of a 929 * exception. However I can't think of a
919 * situation where this is wrong - ejt. 930 * situation where this is wrong - ejt.
920 */ 931 */
932 bio->bi_bdev = s->origin->bdev;
921 933
922 /* Do reads */ 934 out_unlock:
923 down_read(&s->lock); 935 up_write(&s->lock);
924 936 out:
925 if (!s->valid) {
926 up_read(&s->lock);
927 return -EIO;
928 }
929
930 /* See if it it has been remapped */
931 e = lookup_exception(&s->complete, chunk);
932 if (e)
933 remap_exception(s, e, bio);
934 else
935 bio->bi_bdev = s->origin->bdev;
936
937 up_read(&s->lock);
938 }
939
940 return r; 937 return r;
941} 938}
942 939
@@ -1025,7 +1022,7 @@ static int __origin_write(struct list_head *snapshots, struct bio *bio)
1025 * is already remapped in this snapshot 1022 * is already remapped in this snapshot
1026 * and trigger an exception if not. 1023 * and trigger an exception if not.
1027 * 1024 *
1028 * sibling_count is initialised to 1 so pending_complete() 1025 * ref_count is initialised to 1 so pending_complete()
1029 * won't destroy the primary_pe while we're inside this loop. 1026 * won't destroy the primary_pe while we're inside this loop.
1030 */ 1027 */
1031 e = lookup_exception(&snap->complete, chunk); 1028 e = lookup_exception(&snap->complete, chunk);
@@ -1034,7 +1031,7 @@ static int __origin_write(struct list_head *snapshots, struct bio *bio)
1034 1031
1035 pe = __find_pending_exception(snap, bio); 1032 pe = __find_pending_exception(snap, bio);
1036 if (!pe) { 1033 if (!pe) {
1037 __invalidate_snapshot(snap, pe, ENOMEM); 1034 __invalidate_snapshot(snap, -ENOMEM);
1038 goto next_snapshot; 1035 goto next_snapshot;
1039 } 1036 }
1040 1037
@@ -1056,8 +1053,8 @@ static int __origin_write(struct list_head *snapshots, struct bio *bio)
1056 } 1053 }
1057 1054
1058 if (!pe->primary_pe) { 1055 if (!pe->primary_pe) {
1059 atomic_inc(&primary_pe->sibling_count);
1060 pe->primary_pe = primary_pe; 1056 pe->primary_pe = primary_pe;
1057 get_pending_exception(primary_pe);
1061 } 1058 }
1062 1059
1063 if (!pe->started) { 1060 if (!pe->started) {
@@ -1070,20 +1067,20 @@ static int __origin_write(struct list_head *snapshots, struct bio *bio)
1070 } 1067 }
1071 1068
1072 if (!primary_pe) 1069 if (!primary_pe)
1073 goto out; 1070 return r;
1074 1071
1075 /* 1072 /*
1076 * If this is the first time we're processing this chunk and 1073 * If this is the first time we're processing this chunk and
1077 * sibling_count is now 1 it means all the pending exceptions 1074 * ref_count is now 1 it means all the pending exceptions
1078 * got completed while we were in the loop above, so it falls to 1075 * got completed while we were in the loop above, so it falls to
1079 * us here to remove the primary_pe and submit any origin_bios. 1076 * us here to remove the primary_pe and submit any origin_bios.
1080 */ 1077 */
1081 1078
1082 if (first && atomic_dec_and_test(&primary_pe->sibling_count)) { 1079 if (first && atomic_dec_and_test(&primary_pe->ref_count)) {
1083 flush_bios(bio_list_get(&primary_pe->origin_bios)); 1080 flush_bios(bio_list_get(&primary_pe->origin_bios));
1084 free_pending_exception(primary_pe); 1081 free_pending_exception(primary_pe);
1085 /* If we got here, pe_queue is necessarily empty. */ 1082 /* If we got here, pe_queue is necessarily empty. */
1086 goto out; 1083 return r;
1087 } 1084 }
1088 1085
1089 /* 1086 /*
@@ -1092,7 +1089,6 @@ static int __origin_write(struct list_head *snapshots, struct bio *bio)
1092 list_for_each_entry_safe(pe, next_pe, &pe_queue, list) 1089 list_for_each_entry_safe(pe, next_pe, &pe_queue, list)
1093 start_copy(pe); 1090 start_copy(pe);
1094 1091
1095 out:
1096 return r; 1092 return r;
1097} 1093}
1098 1094
@@ -1205,7 +1201,7 @@ static int origin_status(struct dm_target *ti, status_type_t type, char *result,
1205 1201
1206static struct target_type origin_target = { 1202static struct target_type origin_target = {
1207 .name = "snapshot-origin", 1203 .name = "snapshot-origin",
1208 .version = {1, 4, 0}, 1204 .version = {1, 5, 0},
1209 .module = THIS_MODULE, 1205 .module = THIS_MODULE,
1210 .ctr = origin_ctr, 1206 .ctr = origin_ctr,
1211 .dtr = origin_dtr, 1207 .dtr = origin_dtr,
@@ -1216,7 +1212,7 @@ static struct target_type origin_target = {
1216 1212
1217static struct target_type snapshot_target = { 1213static struct target_type snapshot_target = {
1218 .name = "snapshot", 1214 .name = "snapshot",
1219 .version = {1, 4, 0}, 1215 .version = {1, 5, 0},
1220 .module = THIS_MODULE, 1216 .module = THIS_MODULE,
1221 .ctr = snapshot_ctr, 1217 .ctr = snapshot_ctr,
1222 .dtr = snapshot_dtr, 1218 .dtr = snapshot_dtr,
@@ -1275,8 +1271,17 @@ static int __init dm_snapshot_init(void)
1275 goto bad5; 1271 goto bad5;
1276 } 1272 }
1277 1273
1274 ksnapd = create_singlethread_workqueue("ksnapd");
1275 if (!ksnapd) {
1276 DMERR("Failed to create ksnapd workqueue.");
1277 r = -ENOMEM;
1278 goto bad6;
1279 }
1280
1278 return 0; 1281 return 0;
1279 1282
1283 bad6:
1284 mempool_destroy(pending_pool);
1280 bad5: 1285 bad5:
1281 kmem_cache_destroy(pending_cache); 1286 kmem_cache_destroy(pending_cache);
1282 bad4: 1287 bad4:
@@ -1294,6 +1299,8 @@ static void __exit dm_snapshot_exit(void)
1294{ 1299{
1295 int r; 1300 int r;
1296 1301
1302 destroy_workqueue(ksnapd);
1303
1297 r = dm_unregister_target(&snapshot_target); 1304 r = dm_unregister_target(&snapshot_target);
1298 if (r) 1305 if (r)
1299 DMERR("snapshot unregister failed %d", r); 1306 DMERR("snapshot unregister failed %d", r);
diff --git a/drivers/md/dm-snap.h b/drivers/md/dm-snap.h
index fdec1e2dc871..15fa2ae6cdc2 100644
--- a/drivers/md/dm-snap.h
+++ b/drivers/md/dm-snap.h
@@ -10,7 +10,9 @@
10#define DM_SNAPSHOT_H 10#define DM_SNAPSHOT_H
11 11
12#include "dm.h" 12#include "dm.h"
13#include "dm-bio-list.h"
13#include <linux/blkdev.h> 14#include <linux/blkdev.h>
15#include <linux/workqueue.h>
14 16
15struct exception_table { 17struct exception_table {
16 uint32_t hash_mask; 18 uint32_t hash_mask;
@@ -112,10 +114,20 @@ struct dm_snapshot {
112 struct exception_table pending; 114 struct exception_table pending;
113 struct exception_table complete; 115 struct exception_table complete;
114 116
117 /*
118 * pe_lock protects all pending_exception operations and access
119 * as well as the snapshot_bios list.
120 */
121 spinlock_t pe_lock;
122
115 /* The on disk metadata handler */ 123 /* The on disk metadata handler */
116 struct exception_store store; 124 struct exception_store store;
117 125
118 struct kcopyd_client *kcopyd_client; 126 struct kcopyd_client *kcopyd_client;
127
128 /* Queue of snapshot writes for ksnapd to flush */
129 struct bio_list queued_bios;
130 struct work_struct queued_bios_work;
119}; 131};
120 132
121/* 133/*
@@ -128,10 +140,9 @@ int dm_add_exception(struct dm_snapshot *s, chunk_t old, chunk_t new);
128 * Constructor and destructor for the default persistent 140 * Constructor and destructor for the default persistent
129 * store. 141 * store.
130 */ 142 */
131int dm_create_persistent(struct exception_store *store, uint32_t chunk_size); 143int dm_create_persistent(struct exception_store *store);
132 144
133int dm_create_transient(struct exception_store *store, 145int dm_create_transient(struct exception_store *store);
134 struct dm_snapshot *s, int blocksize);
135 146
136/* 147/*
137 * Return the number of sectors in the device. 148 * Return the number of sectors in the device.
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 75fe9493e6af..05befa91807a 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -522,56 +522,61 @@ static int __table_get_device(struct dm_table *t, struct dm_target *ti,
522 return 0; 522 return 0;
523} 523}
524 524
525 525void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev)
526int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
527 sector_t len, int mode, struct dm_dev **result)
528{ 526{
529 int r = __table_get_device(ti->table, ti, path, 527 request_queue_t *q = bdev_get_queue(bdev);
530 start, len, mode, result); 528 struct io_restrictions *rs = &ti->limits;
531 if (!r) { 529
532 request_queue_t *q = bdev_get_queue((*result)->bdev); 530 /*
533 struct io_restrictions *rs = &ti->limits; 531 * Combine the device limits low.
534 532 *
535 /* 533 * FIXME: if we move an io_restriction struct
536 * Combine the device limits low. 534 * into q this would just be a call to
537 * 535 * combine_restrictions_low()
538 * FIXME: if we move an io_restriction struct 536 */
539 * into q this would just be a call to 537 rs->max_sectors =
540 * combine_restrictions_low() 538 min_not_zero(rs->max_sectors, q->max_sectors);
541 */ 539
540 /* FIXME: Device-Mapper on top of RAID-0 breaks because DM
541 * currently doesn't honor MD's merge_bvec_fn routine.
542 * In this case, we'll force DM to use PAGE_SIZE or
543 * smaller I/O, just to be safe. A better fix is in the
544 * works, but add this for the time being so it will at
545 * least operate correctly.
546 */
547 if (q->merge_bvec_fn)
542 rs->max_sectors = 548 rs->max_sectors =
543 min_not_zero(rs->max_sectors, q->max_sectors); 549 min_not_zero(rs->max_sectors,
550 (unsigned int) (PAGE_SIZE >> 9));
544 551
545 /* FIXME: Device-Mapper on top of RAID-0 breaks because DM 552 rs->max_phys_segments =
546 * currently doesn't honor MD's merge_bvec_fn routine. 553 min_not_zero(rs->max_phys_segments,
547 * In this case, we'll force DM to use PAGE_SIZE or 554 q->max_phys_segments);
548 * smaller I/O, just to be safe. A better fix is in the
549 * works, but add this for the time being so it will at
550 * least operate correctly.
551 */
552 if (q->merge_bvec_fn)
553 rs->max_sectors =
554 min_not_zero(rs->max_sectors,
555 (unsigned int) (PAGE_SIZE >> 9));
556 555
557 rs->max_phys_segments = 556 rs->max_hw_segments =
558 min_not_zero(rs->max_phys_segments, 557 min_not_zero(rs->max_hw_segments, q->max_hw_segments);
559 q->max_phys_segments);
560 558
561 rs->max_hw_segments = 559 rs->hardsect_size = max(rs->hardsect_size, q->hardsect_size);
562 min_not_zero(rs->max_hw_segments, q->max_hw_segments);
563 560
564 rs->hardsect_size = max(rs->hardsect_size, q->hardsect_size); 561 rs->max_segment_size =
562 min_not_zero(rs->max_segment_size, q->max_segment_size);
565 563
566 rs->max_segment_size = 564 rs->seg_boundary_mask =
567 min_not_zero(rs->max_segment_size, q->max_segment_size); 565 min_not_zero(rs->seg_boundary_mask,
566 q->seg_boundary_mask);
568 567
569 rs->seg_boundary_mask = 568 rs->no_cluster |= !test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags);
570 min_not_zero(rs->seg_boundary_mask, 569}
571 q->seg_boundary_mask); 570EXPORT_SYMBOL_GPL(dm_set_device_limits);
572 571
573 rs->no_cluster |= !test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags); 572int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
574 } 573 sector_t len, int mode, struct dm_dev **result)
574{
575 int r = __table_get_device(ti->table, ti, path,
576 start, len, mode, result);
577
578 if (!r)
579 dm_set_device_limits(ti, (*result)->bdev);
575 580
576 return r; 581 return r;
577} 582}
@@ -939,9 +944,20 @@ void dm_table_postsuspend_targets(struct dm_table *t)
939 return suspend_targets(t, 1); 944 return suspend_targets(t, 1);
940} 945}
941 946
942void dm_table_resume_targets(struct dm_table *t) 947int dm_table_resume_targets(struct dm_table *t)
943{ 948{
944 int i; 949 int i, r = 0;
950
951 for (i = 0; i < t->num_targets; i++) {
952 struct dm_target *ti = t->targets + i;
953
954 if (!ti->type->preresume)
955 continue;
956
957 r = ti->type->preresume(ti);
958 if (r)
959 return r;
960 }
945 961
946 for (i = 0; i < t->num_targets; i++) { 962 for (i = 0; i < t->num_targets; i++) {
947 struct dm_target *ti = t->targets + i; 963 struct dm_target *ti = t->targets + i;
@@ -949,6 +965,8 @@ void dm_table_resume_targets(struct dm_table *t)
949 if (ti->type->resume) 965 if (ti->type->resume)
950 ti->type->resume(ti); 966 ti->type->resume(ti);
951 } 967 }
968
969 return 0;
952} 970}
953 971
954int dm_table_any_congested(struct dm_table *t, int bdi_bits) 972int dm_table_any_congested(struct dm_table *t, int bdi_bits)
@@ -983,6 +1001,11 @@ int dm_table_flush_all(struct dm_table *t)
983{ 1001{
984 struct list_head *d, *devices = dm_table_get_devices(t); 1002 struct list_head *d, *devices = dm_table_get_devices(t);
985 int ret = 0; 1003 int ret = 0;
1004 unsigned i;
1005
1006 for (i = 0; i < t->num_targets; i++)
1007 if (t->targets[i].type->flush)
1008 t->targets[i].type->flush(&t->targets[i]);
986 1009
987 for (d = devices->next; d != devices; d = d->next) { 1010 for (d = devices->next; d != devices; d = d->next) {
988 struct dm_dev *dd = list_entry(d, struct dm_dev, list); 1011 struct dm_dev *dd = list_entry(d, struct dm_dev, list);
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index c99bf9f01759..b5764a86c8b5 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -20,6 +20,7 @@
20#include <linux/idr.h> 20#include <linux/idr.h>
21#include <linux/hdreg.h> 21#include <linux/hdreg.h>
22#include <linux/blktrace_api.h> 22#include <linux/blktrace_api.h>
23#include <linux/smp_lock.h>
23 24
24#define DM_MSG_PREFIX "core" 25#define DM_MSG_PREFIX "core"
25 26
@@ -101,6 +102,8 @@ struct mapped_device {
101 mempool_t *io_pool; 102 mempool_t *io_pool;
102 mempool_t *tio_pool; 103 mempool_t *tio_pool;
103 104
105 struct bio_set *bs;
106
104 /* 107 /*
105 * Event handling. 108 * Event handling.
106 */ 109 */
@@ -121,16 +124,10 @@ struct mapped_device {
121static kmem_cache_t *_io_cache; 124static kmem_cache_t *_io_cache;
122static kmem_cache_t *_tio_cache; 125static kmem_cache_t *_tio_cache;
123 126
124static struct bio_set *dm_set;
125
126static int __init local_init(void) 127static int __init local_init(void)
127{ 128{
128 int r; 129 int r;
129 130
130 dm_set = bioset_create(16, 16, 4);
131 if (!dm_set)
132 return -ENOMEM;
133
134 /* allocate a slab for the dm_ios */ 131 /* allocate a slab for the dm_ios */
135 _io_cache = kmem_cache_create("dm_io", 132 _io_cache = kmem_cache_create("dm_io",
136 sizeof(struct dm_io), 0, 0, NULL, NULL); 133 sizeof(struct dm_io), 0, 0, NULL, NULL);
@@ -164,8 +161,6 @@ static void local_exit(void)
164 kmem_cache_destroy(_tio_cache); 161 kmem_cache_destroy(_tio_cache);
165 kmem_cache_destroy(_io_cache); 162 kmem_cache_destroy(_io_cache);
166 163
167 bioset_free(dm_set);
168
169 if (unregister_blkdev(_major, _name) < 0) 164 if (unregister_blkdev(_major, _name) < 0)
170 DMERR("unregister_blkdev failed"); 165 DMERR("unregister_blkdev failed");
171 166
@@ -288,6 +283,45 @@ static int dm_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
288 return dm_get_geometry(md, geo); 283 return dm_get_geometry(md, geo);
289} 284}
290 285
286static int dm_blk_ioctl(struct inode *inode, struct file *file,
287 unsigned int cmd, unsigned long arg)
288{
289 struct mapped_device *md;
290 struct dm_table *map;
291 struct dm_target *tgt;
292 int r = -ENOTTY;
293
294 /* We don't really need this lock, but we do need 'inode'. */
295 unlock_kernel();
296
297 md = inode->i_bdev->bd_disk->private_data;
298
299 map = dm_get_table(md);
300
301 if (!map || !dm_table_get_size(map))
302 goto out;
303
304 /* We only support devices that have a single target */
305 if (dm_table_get_num_targets(map) != 1)
306 goto out;
307
308 tgt = dm_table_get_target(map, 0);
309
310 if (dm_suspended(md)) {
311 r = -EAGAIN;
312 goto out;
313 }
314
315 if (tgt->type->ioctl)
316 r = tgt->type->ioctl(tgt, inode, file, cmd, arg);
317
318out:
319 dm_table_put(map);
320
321 lock_kernel();
322 return r;
323}
324
291static inline struct dm_io *alloc_io(struct mapped_device *md) 325static inline struct dm_io *alloc_io(struct mapped_device *md)
292{ 326{
293 return mempool_alloc(md->io_pool, GFP_NOIO); 327 return mempool_alloc(md->io_pool, GFP_NOIO);
@@ -435,7 +469,7 @@ static int clone_endio(struct bio *bio, unsigned int done, int error)
435{ 469{
436 int r = 0; 470 int r = 0;
437 struct target_io *tio = bio->bi_private; 471 struct target_io *tio = bio->bi_private;
438 struct dm_io *io = tio->io; 472 struct mapped_device *md = tio->io->md;
439 dm_endio_fn endio = tio->ti->type->end_io; 473 dm_endio_fn endio = tio->ti->type->end_io;
440 474
441 if (bio->bi_size) 475 if (bio->bi_size)
@@ -454,9 +488,15 @@ static int clone_endio(struct bio *bio, unsigned int done, int error)
454 return 1; 488 return 1;
455 } 489 }
456 490
457 free_tio(io->md, tio); 491 dec_pending(tio->io, error);
458 dec_pending(io, error); 492
493 /*
494 * Store md for cleanup instead of tio which is about to get freed.
495 */
496 bio->bi_private = md->bs;
497
459 bio_put(bio); 498 bio_put(bio);
499 free_tio(md, tio);
460 return r; 500 return r;
461} 501}
462 502
@@ -485,6 +525,7 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
485{ 525{
486 int r; 526 int r;
487 sector_t sector; 527 sector_t sector;
528 struct mapped_device *md;
488 529
489 /* 530 /*
490 * Sanity checks. 531 * Sanity checks.
@@ -514,10 +555,14 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
514 555
515 else if (r < 0) { 556 else if (r < 0) {
516 /* error the io and bail out */ 557 /* error the io and bail out */
517 struct dm_io *io = tio->io; 558 md = tio->io->md;
518 free_tio(tio->io->md, tio); 559 dec_pending(tio->io, r);
519 dec_pending(io, r); 560 /*
561 * Store bio_set for cleanup.
562 */
563 clone->bi_private = md->bs;
520 bio_put(clone); 564 bio_put(clone);
565 free_tio(md, tio);
521 } 566 }
522} 567}
523 568
@@ -533,7 +578,9 @@ struct clone_info {
533 578
534static void dm_bio_destructor(struct bio *bio) 579static void dm_bio_destructor(struct bio *bio)
535{ 580{
536 bio_free(bio, dm_set); 581 struct bio_set *bs = bio->bi_private;
582
583 bio_free(bio, bs);
537} 584}
538 585
539/* 586/*
@@ -541,12 +588,12 @@ static void dm_bio_destructor(struct bio *bio)
541 */ 588 */
542static struct bio *split_bvec(struct bio *bio, sector_t sector, 589static struct bio *split_bvec(struct bio *bio, sector_t sector,
543 unsigned short idx, unsigned int offset, 590 unsigned short idx, unsigned int offset,
544 unsigned int len) 591 unsigned int len, struct bio_set *bs)
545{ 592{
546 struct bio *clone; 593 struct bio *clone;
547 struct bio_vec *bv = bio->bi_io_vec + idx; 594 struct bio_vec *bv = bio->bi_io_vec + idx;
548 595
549 clone = bio_alloc_bioset(GFP_NOIO, 1, dm_set); 596 clone = bio_alloc_bioset(GFP_NOIO, 1, bs);
550 clone->bi_destructor = dm_bio_destructor; 597 clone->bi_destructor = dm_bio_destructor;
551 *clone->bi_io_vec = *bv; 598 *clone->bi_io_vec = *bv;
552 599
@@ -566,11 +613,13 @@ static struct bio *split_bvec(struct bio *bio, sector_t sector,
566 */ 613 */
567static struct bio *clone_bio(struct bio *bio, sector_t sector, 614static struct bio *clone_bio(struct bio *bio, sector_t sector,
568 unsigned short idx, unsigned short bv_count, 615 unsigned short idx, unsigned short bv_count,
569 unsigned int len) 616 unsigned int len, struct bio_set *bs)
570{ 617{
571 struct bio *clone; 618 struct bio *clone;
572 619
573 clone = bio_clone(bio, GFP_NOIO); 620 clone = bio_alloc_bioset(GFP_NOIO, bio->bi_max_vecs, bs);
621 __bio_clone(clone, bio);
622 clone->bi_destructor = dm_bio_destructor;
574 clone->bi_sector = sector; 623 clone->bi_sector = sector;
575 clone->bi_idx = idx; 624 clone->bi_idx = idx;
576 clone->bi_vcnt = idx + bv_count; 625 clone->bi_vcnt = idx + bv_count;
@@ -601,7 +650,8 @@ static void __clone_and_map(struct clone_info *ci)
601 * the remaining io with a single clone. 650 * the remaining io with a single clone.
602 */ 651 */
603 clone = clone_bio(bio, ci->sector, ci->idx, 652 clone = clone_bio(bio, ci->sector, ci->idx,
604 bio->bi_vcnt - ci->idx, ci->sector_count); 653 bio->bi_vcnt - ci->idx, ci->sector_count,
654 ci->md->bs);
605 __map_bio(ti, clone, tio); 655 __map_bio(ti, clone, tio);
606 ci->sector_count = 0; 656 ci->sector_count = 0;
607 657
@@ -624,7 +674,8 @@ static void __clone_and_map(struct clone_info *ci)
624 len += bv_len; 674 len += bv_len;
625 } 675 }
626 676
627 clone = clone_bio(bio, ci->sector, ci->idx, i - ci->idx, len); 677 clone = clone_bio(bio, ci->sector, ci->idx, i - ci->idx, len,
678 ci->md->bs);
628 __map_bio(ti, clone, tio); 679 __map_bio(ti, clone, tio);
629 680
630 ci->sector += len; 681 ci->sector += len;
@@ -653,7 +704,8 @@ static void __clone_and_map(struct clone_info *ci)
653 len = min(remaining, max); 704 len = min(remaining, max);
654 705
655 clone = split_bvec(bio, ci->sector, ci->idx, 706 clone = split_bvec(bio, ci->sector, ci->idx,
656 bv->bv_offset + offset, len); 707 bv->bv_offset + offset, len,
708 ci->md->bs);
657 709
658 __map_bio(ti, clone, tio); 710 __map_bio(ti, clone, tio);
659 711
@@ -903,7 +955,7 @@ static struct mapped_device *alloc_dev(int minor)
903 955
904 md->queue = blk_alloc_queue(GFP_KERNEL); 956 md->queue = blk_alloc_queue(GFP_KERNEL);
905 if (!md->queue) 957 if (!md->queue)
906 goto bad1; 958 goto bad1_free_minor;
907 959
908 md->queue->queuedata = md; 960 md->queue->queuedata = md;
909 md->queue->backing_dev_info.congested_fn = dm_any_congested; 961 md->queue->backing_dev_info.congested_fn = dm_any_congested;
@@ -921,6 +973,10 @@ static struct mapped_device *alloc_dev(int minor)
921 if (!md->tio_pool) 973 if (!md->tio_pool)
922 goto bad3; 974 goto bad3;
923 975
976 md->bs = bioset_create(16, 16, 4);
977 if (!md->bs)
978 goto bad_no_bioset;
979
924 md->disk = alloc_disk(1); 980 md->disk = alloc_disk(1);
925 if (!md->disk) 981 if (!md->disk)
926 goto bad4; 982 goto bad4;
@@ -948,11 +1004,14 @@ static struct mapped_device *alloc_dev(int minor)
948 return md; 1004 return md;
949 1005
950 bad4: 1006 bad4:
1007 bioset_free(md->bs);
1008 bad_no_bioset:
951 mempool_destroy(md->tio_pool); 1009 mempool_destroy(md->tio_pool);
952 bad3: 1010 bad3:
953 mempool_destroy(md->io_pool); 1011 mempool_destroy(md->io_pool);
954 bad2: 1012 bad2:
955 blk_cleanup_queue(md->queue); 1013 blk_cleanup_queue(md->queue);
1014 bad1_free_minor:
956 free_minor(minor); 1015 free_minor(minor);
957 bad1: 1016 bad1:
958 module_put(THIS_MODULE); 1017 module_put(THIS_MODULE);
@@ -971,6 +1030,7 @@ static void free_dev(struct mapped_device *md)
971 } 1030 }
972 mempool_destroy(md->tio_pool); 1031 mempool_destroy(md->tio_pool);
973 mempool_destroy(md->io_pool); 1032 mempool_destroy(md->io_pool);
1033 bioset_free(md->bs);
974 del_gendisk(md->disk); 1034 del_gendisk(md->disk);
975 free_minor(minor); 1035 free_minor(minor);
976 1036
@@ -1319,7 +1379,9 @@ int dm_resume(struct mapped_device *md)
1319 if (!map || !dm_table_get_size(map)) 1379 if (!map || !dm_table_get_size(map))
1320 goto out; 1380 goto out;
1321 1381
1322 dm_table_resume_targets(map); 1382 r = dm_table_resume_targets(map);
1383 if (r)
1384 goto out;
1323 1385
1324 down_write(&md->io_lock); 1386 down_write(&md->io_lock);
1325 clear_bit(DMF_BLOCK_IO, &md->flags); 1387 clear_bit(DMF_BLOCK_IO, &md->flags);
@@ -1337,6 +1399,8 @@ int dm_resume(struct mapped_device *md)
1337 1399
1338 dm_table_unplug_all(map); 1400 dm_table_unplug_all(map);
1339 1401
1402 kobject_uevent(&md->disk->kobj, KOBJ_CHANGE);
1403
1340 r = 0; 1404 r = 0;
1341 1405
1342out: 1406out:
@@ -1377,6 +1441,7 @@ int dm_suspended(struct mapped_device *md)
1377static struct block_device_operations dm_blk_dops = { 1441static struct block_device_operations dm_blk_dops = {
1378 .open = dm_blk_open, 1442 .open = dm_blk_open,
1379 .release = dm_blk_close, 1443 .release = dm_blk_close,
1444 .ioctl = dm_blk_ioctl,
1380 .getgeo = dm_blk_getgeo, 1445 .getgeo = dm_blk_getgeo,
1381 .owner = THIS_MODULE 1446 .owner = THIS_MODULE
1382}; 1447};
diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index 3c03c0ecab7e..a48ec5e3c1f4 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -21,6 +21,11 @@
21#define DMERR(f, arg...) printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg) 21#define DMERR(f, arg...) printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
22#define DMWARN(f, arg...) printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg) 22#define DMWARN(f, arg...) printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
23#define DMINFO(f, arg...) printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg) 23#define DMINFO(f, arg...) printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
24#ifdef CONFIG_DM_DEBUG
25# define DMDEBUG(f, arg...) printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX " DEBUG: " f "\n", ## arg)
26#else
27# define DMDEBUG(f, arg...) do {} while (0)
28#endif
24 29
25#define DMEMIT(x...) sz += ((sz >= maxlen) ? \ 30#define DMEMIT(x...) sz += ((sz >= maxlen) ? \
26 0 : scnprintf(result + sz, maxlen - sz, x)) 31 0 : scnprintf(result + sz, maxlen - sz, x))
@@ -52,7 +57,7 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q);
52struct list_head *dm_table_get_devices(struct dm_table *t); 57struct list_head *dm_table_get_devices(struct dm_table *t);
53void dm_table_presuspend_targets(struct dm_table *t); 58void dm_table_presuspend_targets(struct dm_table *t);
54void dm_table_postsuspend_targets(struct dm_table *t); 59void dm_table_postsuspend_targets(struct dm_table *t);
55void dm_table_resume_targets(struct dm_table *t); 60int dm_table_resume_targets(struct dm_table *t);
56int dm_table_any_congested(struct dm_table *t, int bdi_bits); 61int dm_table_any_congested(struct dm_table *t, int bdi_bits);
57void dm_table_unplug_all(struct dm_table *t); 62void dm_table_unplug_all(struct dm_table *t);
58int dm_table_flush_all(struct dm_table *t); 63int dm_table_flush_all(struct dm_table *t);
diff --git a/drivers/md/linear.c b/drivers/md/linear.c
index b99c19c7eb22..c625ddb8833d 100644
--- a/drivers/md/linear.c
+++ b/drivers/md/linear.c
@@ -111,6 +111,19 @@ static int linear_issue_flush(request_queue_t *q, struct gendisk *disk,
111 return ret; 111 return ret;
112} 112}
113 113
114static int linear_congested(void *data, int bits)
115{
116 mddev_t *mddev = data;
117 linear_conf_t *conf = mddev_to_conf(mddev);
118 int i, ret = 0;
119
120 for (i = 0; i < mddev->raid_disks && !ret ; i++) {
121 request_queue_t *q = bdev_get_queue(conf->disks[i].rdev->bdev);
122 ret |= bdi_congested(&q->backing_dev_info, bits);
123 }
124 return ret;
125}
126
114static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks) 127static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
115{ 128{
116 linear_conf_t *conf; 129 linear_conf_t *conf;
@@ -269,6 +282,8 @@ static int linear_run (mddev_t *mddev)
269 blk_queue_merge_bvec(mddev->queue, linear_mergeable_bvec); 282 blk_queue_merge_bvec(mddev->queue, linear_mergeable_bvec);
270 mddev->queue->unplug_fn = linear_unplug; 283 mddev->queue->unplug_fn = linear_unplug;
271 mddev->queue->issue_flush_fn = linear_issue_flush; 284 mddev->queue->issue_flush_fn = linear_issue_flush;
285 mddev->queue->backing_dev_info.congested_fn = linear_congested;
286 mddev->queue->backing_dev_info.congested_data = mddev;
272 return 0; 287 return 0;
273} 288}
274 289
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 8dbab2ef3885..38a0a5741d52 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -389,8 +389,12 @@ static int super_written(struct bio *bio, unsigned int bytes_done, int error)
389 if (bio->bi_size) 389 if (bio->bi_size)
390 return 1; 390 return 1;
391 391
392 if (error || !test_bit(BIO_UPTODATE, &bio->bi_flags)) 392 if (error || !test_bit(BIO_UPTODATE, &bio->bi_flags)) {
393 printk("md: super_written gets error=%d, uptodate=%d\n",
394 error, test_bit(BIO_UPTODATE, &bio->bi_flags));
395 WARN_ON(test_bit(BIO_UPTODATE, &bio->bi_flags));
393 md_error(mddev, rdev); 396 md_error(mddev, rdev);
397 }
394 398
395 if (atomic_dec_and_test(&mddev->pending_writes)) 399 if (atomic_dec_and_test(&mddev->pending_writes))
396 wake_up(&mddev->sb_wait); 400 wake_up(&mddev->sb_wait);
@@ -1587,7 +1591,7 @@ static void sync_sbs(mddev_t * mddev, int nospares)
1587 } 1591 }
1588} 1592}
1589 1593
1590void md_update_sb(mddev_t * mddev) 1594static void md_update_sb(mddev_t * mddev, int force_change)
1591{ 1595{
1592 int err; 1596 int err;
1593 struct list_head *tmp; 1597 struct list_head *tmp;
@@ -1598,7 +1602,18 @@ void md_update_sb(mddev_t * mddev)
1598repeat: 1602repeat:
1599 spin_lock_irq(&mddev->write_lock); 1603 spin_lock_irq(&mddev->write_lock);
1600 1604
1601 if (mddev->degraded && mddev->sb_dirty == 3) 1605 set_bit(MD_CHANGE_PENDING, &mddev->flags);
1606 if (test_and_clear_bit(MD_CHANGE_DEVS, &mddev->flags))
1607 force_change = 1;
1608 if (test_and_clear_bit(MD_CHANGE_CLEAN, &mddev->flags))
1609 /* just a clean<-> dirty transition, possibly leave spares alone,
1610 * though if events isn't the right even/odd, we will have to do
1611 * spares after all
1612 */
1613 nospares = 1;
1614 if (force_change)
1615 nospares = 0;
1616 if (mddev->degraded)
1602 /* If the array is degraded, then skipping spares is both 1617 /* If the array is degraded, then skipping spares is both
1603 * dangerous and fairly pointless. 1618 * dangerous and fairly pointless.
1604 * Dangerous because a device that was removed from the array 1619 * Dangerous because a device that was removed from the array
@@ -1608,20 +1623,14 @@ repeat:
1608 * then a recovery will happen and soon that array won't 1623 * then a recovery will happen and soon that array won't
1609 * be degraded any more and the spare can go back to sleep then. 1624 * be degraded any more and the spare can go back to sleep then.
1610 */ 1625 */
1611 mddev->sb_dirty = 1; 1626 nospares = 0;
1612 1627
1613 sync_req = mddev->in_sync; 1628 sync_req = mddev->in_sync;
1614 mddev->utime = get_seconds(); 1629 mddev->utime = get_seconds();
1615 if (mddev->sb_dirty == 3)
1616 /* just a clean<-> dirty transition, possibly leave spares alone,
1617 * though if events isn't the right even/odd, we will have to do
1618 * spares after all
1619 */
1620 nospares = 1;
1621 1630
1622 /* If this is just a dirty<->clean transition, and the array is clean 1631 /* If this is just a dirty<->clean transition, and the array is clean
1623 * and 'events' is odd, we can roll back to the previous clean state */ 1632 * and 'events' is odd, we can roll back to the previous clean state */
1624 if (mddev->sb_dirty == 3 1633 if (nospares
1625 && (mddev->in_sync && mddev->recovery_cp == MaxSector) 1634 && (mddev->in_sync && mddev->recovery_cp == MaxSector)
1626 && (mddev->events & 1)) 1635 && (mddev->events & 1))
1627 mddev->events--; 1636 mddev->events--;
@@ -1652,7 +1661,6 @@ repeat:
1652 MD_BUG(); 1661 MD_BUG();
1653 mddev->events --; 1662 mddev->events --;
1654 } 1663 }
1655 mddev->sb_dirty = 2;
1656 sync_sbs(mddev, nospares); 1664 sync_sbs(mddev, nospares);
1657 1665
1658 /* 1666 /*
@@ -1660,7 +1668,7 @@ repeat:
1660 * nonpersistent superblocks 1668 * nonpersistent superblocks
1661 */ 1669 */
1662 if (!mddev->persistent) { 1670 if (!mddev->persistent) {
1663 mddev->sb_dirty = 0; 1671 clear_bit(MD_CHANGE_PENDING, &mddev->flags);
1664 spin_unlock_irq(&mddev->write_lock); 1672 spin_unlock_irq(&mddev->write_lock);
1665 wake_up(&mddev->sb_wait); 1673 wake_up(&mddev->sb_wait);
1666 return; 1674 return;
@@ -1697,20 +1705,20 @@ repeat:
1697 break; 1705 break;
1698 } 1706 }
1699 md_super_wait(mddev); 1707 md_super_wait(mddev);
1700 /* if there was a failure, sb_dirty was set to 1, and we re-write super */ 1708 /* if there was a failure, MD_CHANGE_DEVS was set, and we re-write super */
1701 1709
1702 spin_lock_irq(&mddev->write_lock); 1710 spin_lock_irq(&mddev->write_lock);
1703 if (mddev->in_sync != sync_req|| mddev->sb_dirty == 1) { 1711 if (mddev->in_sync != sync_req ||
1712 test_bit(MD_CHANGE_DEVS, &mddev->flags)) {
1704 /* have to write it out again */ 1713 /* have to write it out again */
1705 spin_unlock_irq(&mddev->write_lock); 1714 spin_unlock_irq(&mddev->write_lock);
1706 goto repeat; 1715 goto repeat;
1707 } 1716 }
1708 mddev->sb_dirty = 0; 1717 clear_bit(MD_CHANGE_PENDING, &mddev->flags);
1709 spin_unlock_irq(&mddev->write_lock); 1718 spin_unlock_irq(&mddev->write_lock);
1710 wake_up(&mddev->sb_wait); 1719 wake_up(&mddev->sb_wait);
1711 1720
1712} 1721}
1713EXPORT_SYMBOL_GPL(md_update_sb);
1714 1722
1715/* words written to sysfs files may, or my not, be \n terminated. 1723/* words written to sysfs files may, or my not, be \n terminated.
1716 * We want to accept with case. For this we use cmd_match. 1724 * We want to accept with case. For this we use cmd_match.
@@ -1783,7 +1791,7 @@ state_store(mdk_rdev_t *rdev, const char *buf, size_t len)
1783 else { 1791 else {
1784 mddev_t *mddev = rdev->mddev; 1792 mddev_t *mddev = rdev->mddev;
1785 kick_rdev_from_array(rdev); 1793 kick_rdev_from_array(rdev);
1786 md_update_sb(mddev); 1794 md_update_sb(mddev, 1);
1787 md_new_event(mddev); 1795 md_new_event(mddev);
1788 err = 0; 1796 err = 0;
1789 } 1797 }
@@ -2426,7 +2434,7 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
2426 spin_lock_irq(&mddev->write_lock); 2434 spin_lock_irq(&mddev->write_lock);
2427 if (atomic_read(&mddev->writes_pending) == 0) { 2435 if (atomic_read(&mddev->writes_pending) == 0) {
2428 mddev->in_sync = 1; 2436 mddev->in_sync = 1;
2429 mddev->sb_dirty = 1; 2437 set_bit(MD_CHANGE_CLEAN, &mddev->flags);
2430 } 2438 }
2431 spin_unlock_irq(&mddev->write_lock); 2439 spin_unlock_irq(&mddev->write_lock);
2432 } else { 2440 } else {
@@ -2438,7 +2446,7 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
2438 case active: 2446 case active:
2439 if (mddev->pers) { 2447 if (mddev->pers) {
2440 restart_array(mddev); 2448 restart_array(mddev);
2441 mddev->sb_dirty = 0; 2449 clear_bit(MD_CHANGE_CLEAN, &mddev->flags);
2442 wake_up(&mddev->sb_wait); 2450 wake_up(&mddev->sb_wait);
2443 err = 0; 2451 err = 0;
2444 } else { 2452 } else {
@@ -2520,6 +2528,36 @@ static struct md_sysfs_entry md_new_device =
2520__ATTR(new_dev, S_IWUSR, null_show, new_dev_store); 2528__ATTR(new_dev, S_IWUSR, null_show, new_dev_store);
2521 2529
2522static ssize_t 2530static ssize_t
2531bitmap_store(mddev_t *mddev, const char *buf, size_t len)
2532{
2533 char *end;
2534 unsigned long chunk, end_chunk;
2535
2536 if (!mddev->bitmap)
2537 goto out;
2538 /* buf should be <chunk> <chunk> ... or <chunk>-<chunk> ... (range) */
2539 while (*buf) {
2540 chunk = end_chunk = simple_strtoul(buf, &end, 0);
2541 if (buf == end) break;
2542 if (*end == '-') { /* range */
2543 buf = end + 1;
2544 end_chunk = simple_strtoul(buf, &end, 0);
2545 if (buf == end) break;
2546 }
2547 if (*end && !isspace(*end)) break;
2548 bitmap_dirty_bits(mddev->bitmap, chunk, end_chunk);
2549 buf = end;
2550 while (isspace(*buf)) buf++;
2551 }
2552 bitmap_unplug(mddev->bitmap); /* flush the bits to disk */
2553out:
2554 return len;
2555}
2556
2557static struct md_sysfs_entry md_bitmap =
2558__ATTR(bitmap_set_bits, S_IWUSR, null_show, bitmap_store);
2559
2560static ssize_t
2523size_show(mddev_t *mddev, char *page) 2561size_show(mddev_t *mddev, char *page)
2524{ 2562{
2525 return sprintf(page, "%llu\n", (unsigned long long)mddev->size); 2563 return sprintf(page, "%llu\n", (unsigned long long)mddev->size);
@@ -2543,7 +2581,7 @@ size_store(mddev_t *mddev, const char *buf, size_t len)
2543 2581
2544 if (mddev->pers) { 2582 if (mddev->pers) {
2545 err = update_size(mddev, size); 2583 err = update_size(mddev, size);
2546 md_update_sb(mddev); 2584 md_update_sb(mddev, 1);
2547 } else { 2585 } else {
2548 if (mddev->size == 0 || 2586 if (mddev->size == 0 ||
2549 mddev->size > size) 2587 mddev->size > size)
@@ -2839,6 +2877,7 @@ static struct attribute *md_redundancy_attrs[] = {
2839 &md_sync_completed.attr, 2877 &md_sync_completed.attr,
2840 &md_suspend_lo.attr, 2878 &md_suspend_lo.attr,
2841 &md_suspend_hi.attr, 2879 &md_suspend_hi.attr,
2880 &md_bitmap.attr,
2842 NULL, 2881 NULL,
2843}; 2882};
2844static struct attribute_group md_redundancy_group = { 2883static struct attribute_group md_redundancy_group = {
@@ -3111,8 +3150,8 @@ static int do_md_run(mddev_t * mddev)
3111 3150
3112 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 3151 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
3113 3152
3114 if (mddev->sb_dirty) 3153 if (mddev->flags)
3115 md_update_sb(mddev); 3154 md_update_sb(mddev, 0);
3116 3155
3117 set_capacity(disk, mddev->array_size<<1); 3156 set_capacity(disk, mddev->array_size<<1);
3118 3157
@@ -3275,10 +3314,10 @@ static int do_md_stop(mddev_t * mddev, int mode)
3275 if (mddev->ro) 3314 if (mddev->ro)
3276 mddev->ro = 0; 3315 mddev->ro = 0;
3277 } 3316 }
3278 if (!mddev->in_sync || mddev->sb_dirty) { 3317 if (!mddev->in_sync || mddev->flags) {
3279 /* mark array as shutdown cleanly */ 3318 /* mark array as shutdown cleanly */
3280 mddev->in_sync = 1; 3319 mddev->in_sync = 1;
3281 md_update_sb(mddev); 3320 md_update_sb(mddev, 1);
3282 } 3321 }
3283 if (mode == 1) 3322 if (mode == 1)
3284 set_disk_ro(disk, 1); 3323 set_disk_ro(disk, 1);
@@ -3374,6 +3413,7 @@ static void autorun_devices(int part)
3374 3413
3375 printk(KERN_INFO "md: autorun ...\n"); 3414 printk(KERN_INFO "md: autorun ...\n");
3376 while (!list_empty(&pending_raid_disks)) { 3415 while (!list_empty(&pending_raid_disks)) {
3416 int unit;
3377 dev_t dev; 3417 dev_t dev;
3378 LIST_HEAD(candidates); 3418 LIST_HEAD(candidates);
3379 rdev0 = list_entry(pending_raid_disks.next, 3419 rdev0 = list_entry(pending_raid_disks.next,
@@ -3393,16 +3433,19 @@ static void autorun_devices(int part)
3393 * mostly sane superblocks. It's time to allocate the 3433 * mostly sane superblocks. It's time to allocate the
3394 * mddev. 3434 * mddev.
3395 */ 3435 */
3396 if (rdev0->preferred_minor < 0 || rdev0->preferred_minor >= MAX_MD_DEVS) { 3436 if (part) {
3437 dev = MKDEV(mdp_major,
3438 rdev0->preferred_minor << MdpMinorShift);
3439 unit = MINOR(dev) >> MdpMinorShift;
3440 } else {
3441 dev = MKDEV(MD_MAJOR, rdev0->preferred_minor);
3442 unit = MINOR(dev);
3443 }
3444 if (rdev0->preferred_minor != unit) {
3397 printk(KERN_INFO "md: unit number in %s is bad: %d\n", 3445 printk(KERN_INFO "md: unit number in %s is bad: %d\n",
3398 bdevname(rdev0->bdev, b), rdev0->preferred_minor); 3446 bdevname(rdev0->bdev, b), rdev0->preferred_minor);
3399 break; 3447 break;
3400 } 3448 }
3401 if (part)
3402 dev = MKDEV(mdp_major,
3403 rdev0->preferred_minor << MdpMinorShift);
3404 else
3405 dev = MKDEV(MD_MAJOR, rdev0->preferred_minor);
3406 3449
3407 md_probe(dev, NULL, NULL); 3450 md_probe(dev, NULL, NULL);
3408 mddev = mddev_find(dev); 3451 mddev = mddev_find(dev);
@@ -3440,67 +3483,6 @@ static void autorun_devices(int part)
3440 printk(KERN_INFO "md: ... autorun DONE.\n"); 3483 printk(KERN_INFO "md: ... autorun DONE.\n");
3441} 3484}
3442 3485
3443/*
3444 * import RAID devices based on one partition
3445 * if possible, the array gets run as well.
3446 */
3447
3448static int autostart_array(dev_t startdev)
3449{
3450 char b[BDEVNAME_SIZE];
3451 int err = -EINVAL, i;
3452 mdp_super_t *sb = NULL;
3453 mdk_rdev_t *start_rdev = NULL, *rdev;
3454
3455 start_rdev = md_import_device(startdev, 0, 0);
3456 if (IS_ERR(start_rdev))
3457 return err;
3458
3459
3460 /* NOTE: this can only work for 0.90.0 superblocks */
3461 sb = (mdp_super_t*)page_address(start_rdev->sb_page);
3462 if (sb->major_version != 0 ||
3463 sb->minor_version != 90 ) {
3464 printk(KERN_WARNING "md: can only autostart 0.90.0 arrays\n");
3465 export_rdev(start_rdev);
3466 return err;
3467 }
3468
3469 if (test_bit(Faulty, &start_rdev->flags)) {
3470 printk(KERN_WARNING
3471 "md: can not autostart based on faulty %s!\n",
3472 bdevname(start_rdev->bdev,b));
3473 export_rdev(start_rdev);
3474 return err;
3475 }
3476 list_add(&start_rdev->same_set, &pending_raid_disks);
3477
3478 for (i = 0; i < MD_SB_DISKS; i++) {
3479 mdp_disk_t *desc = sb->disks + i;
3480 dev_t dev = MKDEV(desc->major, desc->minor);
3481
3482 if (!dev)
3483 continue;
3484 if (dev == startdev)
3485 continue;
3486 if (MAJOR(dev) != desc->major || MINOR(dev) != desc->minor)
3487 continue;
3488 rdev = md_import_device(dev, 0, 0);
3489 if (IS_ERR(rdev))
3490 continue;
3491
3492 list_add(&rdev->same_set, &pending_raid_disks);
3493 }
3494
3495 /*
3496 * possibly return codes
3497 */
3498 autorun_devices(0);
3499 return 0;
3500
3501}
3502
3503
3504static int get_version(void __user * arg) 3486static int get_version(void __user * arg)
3505{ 3487{
3506 mdu_version_t ver; 3488 mdu_version_t ver;
@@ -3808,7 +3790,7 @@ static int hot_remove_disk(mddev_t * mddev, dev_t dev)
3808 goto busy; 3790 goto busy;
3809 3791
3810 kick_rdev_from_array(rdev); 3792 kick_rdev_from_array(rdev);
3811 md_update_sb(mddev); 3793 md_update_sb(mddev, 1);
3812 md_new_event(mddev); 3794 md_new_event(mddev);
3813 3795
3814 return 0; 3796 return 0;
@@ -3885,7 +3867,7 @@ static int hot_add_disk(mddev_t * mddev, dev_t dev)
3885 3867
3886 rdev->raid_disk = -1; 3868 rdev->raid_disk = -1;
3887 3869
3888 md_update_sb(mddev); 3870 md_update_sb(mddev, 1);
3889 3871
3890 /* 3872 /*
3891 * Kick recovery, maybe this spare has to be added to the 3873 * Kick recovery, maybe this spare has to be added to the
@@ -4016,7 +3998,8 @@ static int set_array_info(mddev_t * mddev, mdu_array_info_t *info)
4016 3998
4017 mddev->max_disks = MD_SB_DISKS; 3999 mddev->max_disks = MD_SB_DISKS;
4018 4000
4019 mddev->sb_dirty = 1; 4001 mddev->flags = 0;
4002 set_bit(MD_CHANGE_DEVS, &mddev->flags);
4020 4003
4021 mddev->default_bitmap_offset = MD_SB_BYTES >> 9; 4004 mddev->default_bitmap_offset = MD_SB_BYTES >> 9;
4022 mddev->bitmap_offset = 0; 4005 mddev->bitmap_offset = 0;
@@ -4185,7 +4168,7 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info)
4185 mddev->bitmap_offset = 0; 4168 mddev->bitmap_offset = 0;
4186 } 4169 }
4187 } 4170 }
4188 md_update_sb(mddev); 4171 md_update_sb(mddev, 1);
4189 return rv; 4172 return rv;
4190} 4173}
4191 4174
@@ -4259,27 +4242,6 @@ static int md_ioctl(struct inode *inode, struct file *file,
4259 goto abort; 4242 goto abort;
4260 } 4243 }
4261 4244
4262
4263 if (cmd == START_ARRAY) {
4264 /* START_ARRAY doesn't need to lock the array as autostart_array
4265 * does the locking, and it could even be a different array
4266 */
4267 static int cnt = 3;
4268 if (cnt > 0 ) {
4269 printk(KERN_WARNING
4270 "md: %s(pid %d) used deprecated START_ARRAY ioctl. "
4271 "This will not be supported beyond July 2006\n",
4272 current->comm, current->pid);
4273 cnt--;
4274 }
4275 err = autostart_array(new_decode_dev(arg));
4276 if (err) {
4277 printk(KERN_WARNING "md: autostart failed!\n");
4278 goto abort;
4279 }
4280 goto done;
4281 }
4282
4283 err = mddev_lock(mddev); 4245 err = mddev_lock(mddev);
4284 if (err) { 4246 if (err) {
4285 printk(KERN_INFO 4247 printk(KERN_INFO
@@ -4687,9 +4649,11 @@ static void status_resync(struct seq_file *seq, mddev_t * mddev)
4687 seq_printf(seq, " %s =%3u.%u%% (%llu/%llu)", 4649 seq_printf(seq, " %s =%3u.%u%% (%llu/%llu)",
4688 (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)? 4650 (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)?
4689 "reshape" : 4651 "reshape" :
4690 (test_bit(MD_RECOVERY_SYNC, &mddev->recovery) ? 4652 (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)?
4691 "resync" : "recovery")), 4653 "check" :
4692 per_milli/10, per_milli % 10, 4654 (test_bit(MD_RECOVERY_SYNC, &mddev->recovery) ?
4655 "resync" : "recovery"))),
4656 per_milli/10, per_milli % 10,
4693 (unsigned long long) resync, 4657 (unsigned long long) resync,
4694 (unsigned long long) max_blocks); 4658 (unsigned long long) max_blocks);
4695 4659
@@ -5042,12 +5006,12 @@ void md_write_start(mddev_t *mddev, struct bio *bi)
5042 spin_lock_irq(&mddev->write_lock); 5006 spin_lock_irq(&mddev->write_lock);
5043 if (mddev->in_sync) { 5007 if (mddev->in_sync) {
5044 mddev->in_sync = 0; 5008 mddev->in_sync = 0;
5045 mddev->sb_dirty = 3; 5009 set_bit(MD_CHANGE_CLEAN, &mddev->flags);
5046 md_wakeup_thread(mddev->thread); 5010 md_wakeup_thread(mddev->thread);
5047 } 5011 }
5048 spin_unlock_irq(&mddev->write_lock); 5012 spin_unlock_irq(&mddev->write_lock);
5049 } 5013 }
5050 wait_event(mddev->sb_wait, mddev->sb_dirty==0); 5014 wait_event(mddev->sb_wait, mddev->flags==0);
5051} 5015}
5052 5016
5053void md_write_end(mddev_t *mddev) 5017void md_write_end(mddev_t *mddev)
@@ -5078,6 +5042,7 @@ void md_do_sync(mddev_t *mddev)
5078 int skipped = 0; 5042 int skipped = 0;
5079 struct list_head *rtmp; 5043 struct list_head *rtmp;
5080 mdk_rdev_t *rdev; 5044 mdk_rdev_t *rdev;
5045 char *desc;
5081 5046
5082 /* just incase thread restarts... */ 5047 /* just incase thread restarts... */
5083 if (test_bit(MD_RECOVERY_DONE, &mddev->recovery)) 5048 if (test_bit(MD_RECOVERY_DONE, &mddev->recovery))
@@ -5085,6 +5050,18 @@ void md_do_sync(mddev_t *mddev)
5085 if (mddev->ro) /* never try to sync a read-only array */ 5050 if (mddev->ro) /* never try to sync a read-only array */
5086 return; 5051 return;
5087 5052
5053 if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) {
5054 if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery))
5055 desc = "data-check";
5056 else if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
5057 desc = "requested-resync";
5058 else
5059 desc = "resync";
5060 } else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery))
5061 desc = "reshape";
5062 else
5063 desc = "recovery";
5064
5088 /* we overload curr_resync somewhat here. 5065 /* we overload curr_resync somewhat here.
5089 * 0 == not engaged in resync at all 5066 * 0 == not engaged in resync at all
5090 * 2 == checking that there is no conflict with another sync 5067 * 2 == checking that there is no conflict with another sync
@@ -5128,10 +5105,10 @@ void md_do_sync(mddev_t *mddev)
5128 prepare_to_wait(&resync_wait, &wq, TASK_UNINTERRUPTIBLE); 5105 prepare_to_wait(&resync_wait, &wq, TASK_UNINTERRUPTIBLE);
5129 if (!kthread_should_stop() && 5106 if (!kthread_should_stop() &&
5130 mddev2->curr_resync >= mddev->curr_resync) { 5107 mddev2->curr_resync >= mddev->curr_resync) {
5131 printk(KERN_INFO "md: delaying resync of %s" 5108 printk(KERN_INFO "md: delaying %s of %s"
5132 " until %s has finished resync (they" 5109 " until %s has finished (they"
5133 " share one or more physical units)\n", 5110 " share one or more physical units)\n",
5134 mdname(mddev), mdname(mddev2)); 5111 desc, mdname(mddev), mdname(mddev2));
5135 mddev_put(mddev2); 5112 mddev_put(mddev2);
5136 schedule(); 5113 schedule();
5137 finish_wait(&resync_wait, &wq); 5114 finish_wait(&resync_wait, &wq);
@@ -5167,12 +5144,12 @@ void md_do_sync(mddev_t *mddev)
5167 j = rdev->recovery_offset; 5144 j = rdev->recovery_offset;
5168 } 5145 }
5169 5146
5170 printk(KERN_INFO "md: syncing RAID array %s\n", mdname(mddev)); 5147 printk(KERN_INFO "md: %s of RAID array %s\n", desc, mdname(mddev));
5171 printk(KERN_INFO "md: minimum _guaranteed_ reconstruction speed:" 5148 printk(KERN_INFO "md: minimum _guaranteed_ speed:"
5172 " %d KB/sec/disc.\n", speed_min(mddev)); 5149 " %d KB/sec/disk.\n", speed_min(mddev));
5173 printk(KERN_INFO "md: using maximum available idle IO bandwidth " 5150 printk(KERN_INFO "md: using maximum available idle IO bandwidth "
5174 "(but not more than %d KB/sec) for reconstruction.\n", 5151 "(but not more than %d KB/sec) for %s.\n",
5175 speed_max(mddev)); 5152 speed_max(mddev), desc);
5176 5153
5177 is_mddev_idle(mddev); /* this also initializes IO event counters */ 5154 is_mddev_idle(mddev); /* this also initializes IO event counters */
5178 5155
@@ -5198,8 +5175,8 @@ void md_do_sync(mddev_t *mddev)
5198 5175
5199 if (j>2) { 5176 if (j>2) {
5200 printk(KERN_INFO 5177 printk(KERN_INFO
5201 "md: resuming recovery of %s from checkpoint.\n", 5178 "md: resuming %s of %s from checkpoint.\n",
5202 mdname(mddev)); 5179 desc, mdname(mddev));
5203 mddev->curr_resync = j; 5180 mddev->curr_resync = j;
5204 } 5181 }
5205 5182
@@ -5282,7 +5259,7 @@ void md_do_sync(mddev_t *mddev)
5282 } 5259 }
5283 } 5260 }
5284 } 5261 }
5285 printk(KERN_INFO "md: %s: sync done.\n",mdname(mddev)); 5262 printk(KERN_INFO "md: %s: %s done.\n",mdname(mddev), desc);
5286 /* 5263 /*
5287 * this also signals 'finished resyncing' to md_stop 5264 * this also signals 'finished resyncing' to md_stop
5288 */ 5265 */
@@ -5302,8 +5279,8 @@ void md_do_sync(mddev_t *mddev)
5302 if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { 5279 if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) {
5303 if (mddev->curr_resync >= mddev->recovery_cp) { 5280 if (mddev->curr_resync >= mddev->recovery_cp) {
5304 printk(KERN_INFO 5281 printk(KERN_INFO
5305 "md: checkpointing recovery of %s.\n", 5282 "md: checkpointing %s of %s.\n",
5306 mdname(mddev)); 5283 desc, mdname(mddev));
5307 mddev->recovery_cp = mddev->curr_resync; 5284 mddev->recovery_cp = mddev->curr_resync;
5308 } 5285 }
5309 } else 5286 } else
@@ -5317,7 +5294,6 @@ void md_do_sync(mddev_t *mddev)
5317 !test_bit(In_sync, &rdev->flags) && 5294 !test_bit(In_sync, &rdev->flags) &&
5318 rdev->recovery_offset < mddev->curr_resync) 5295 rdev->recovery_offset < mddev->curr_resync)
5319 rdev->recovery_offset = mddev->curr_resync; 5296 rdev->recovery_offset = mddev->curr_resync;
5320 mddev->sb_dirty = 1;
5321 } 5297 }
5322 } 5298 }
5323 5299
@@ -5374,7 +5350,7 @@ void md_check_recovery(mddev_t *mddev)
5374 } 5350 }
5375 5351
5376 if ( ! ( 5352 if ( ! (
5377 mddev->sb_dirty || 5353 mddev->flags ||
5378 test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) || 5354 test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) ||
5379 test_bit(MD_RECOVERY_DONE, &mddev->recovery) || 5355 test_bit(MD_RECOVERY_DONE, &mddev->recovery) ||
5380 (mddev->safemode == 1) || 5356 (mddev->safemode == 1) ||
@@ -5390,14 +5366,14 @@ void md_check_recovery(mddev_t *mddev)
5390 if (mddev->safemode && !atomic_read(&mddev->writes_pending) && 5366 if (mddev->safemode && !atomic_read(&mddev->writes_pending) &&
5391 !mddev->in_sync && mddev->recovery_cp == MaxSector) { 5367 !mddev->in_sync && mddev->recovery_cp == MaxSector) {
5392 mddev->in_sync = 1; 5368 mddev->in_sync = 1;
5393 mddev->sb_dirty = 3; 5369 set_bit(MD_CHANGE_CLEAN, &mddev->flags);
5394 } 5370 }
5395 if (mddev->safemode == 1) 5371 if (mddev->safemode == 1)
5396 mddev->safemode = 0; 5372 mddev->safemode = 0;
5397 spin_unlock_irq(&mddev->write_lock); 5373 spin_unlock_irq(&mddev->write_lock);
5398 5374
5399 if (mddev->sb_dirty) 5375 if (mddev->flags)
5400 md_update_sb(mddev); 5376 md_update_sb(mddev, 0);
5401 5377
5402 5378
5403 if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) && 5379 if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) &&
@@ -5416,7 +5392,7 @@ void md_check_recovery(mddev_t *mddev)
5416 /* activate any spares */ 5392 /* activate any spares */
5417 mddev->pers->spare_active(mddev); 5393 mddev->pers->spare_active(mddev);
5418 } 5394 }
5419 md_update_sb(mddev); 5395 md_update_sb(mddev, 1);
5420 5396
5421 /* if array is no-longer degraded, then any saved_raid_disk 5397 /* if array is no-longer degraded, then any saved_raid_disk
5422 * information must be scrapped 5398 * information must be scrapped
@@ -5556,22 +5532,15 @@ static void md_geninit(void)
5556 5532
5557static int __init md_init(void) 5533static int __init md_init(void)
5558{ 5534{
5559 printk(KERN_INFO "md: md driver %d.%d.%d MAX_MD_DEVS=%d,"
5560 " MD_SB_DISKS=%d\n",
5561 MD_MAJOR_VERSION, MD_MINOR_VERSION,
5562 MD_PATCHLEVEL_VERSION, MAX_MD_DEVS, MD_SB_DISKS);
5563 printk(KERN_INFO "md: bitmap version %d.%d\n", BITMAP_MAJOR_HI,
5564 BITMAP_MINOR);
5565
5566 if (register_blkdev(MAJOR_NR, "md")) 5535 if (register_blkdev(MAJOR_NR, "md"))
5567 return -1; 5536 return -1;
5568 if ((mdp_major=register_blkdev(0, "mdp"))<=0) { 5537 if ((mdp_major=register_blkdev(0, "mdp"))<=0) {
5569 unregister_blkdev(MAJOR_NR, "md"); 5538 unregister_blkdev(MAJOR_NR, "md");
5570 return -1; 5539 return -1;
5571 } 5540 }
5572 blk_register_region(MKDEV(MAJOR_NR, 0), MAX_MD_DEVS, THIS_MODULE, 5541 blk_register_region(MKDEV(MAJOR_NR, 0), 1UL<<MINORBITS, THIS_MODULE,
5573 md_probe, NULL, NULL); 5542 md_probe, NULL, NULL);
5574 blk_register_region(MKDEV(mdp_major, 0), MAX_MD_DEVS<<MdpMinorShift, THIS_MODULE, 5543 blk_register_region(MKDEV(mdp_major, 0), 1UL<<MINORBITS, THIS_MODULE,
5575 md_probe, NULL, NULL); 5544 md_probe, NULL, NULL);
5576 5545
5577 register_reboot_notifier(&md_notifier); 5546 register_reboot_notifier(&md_notifier);
@@ -5630,8 +5599,8 @@ static __exit void md_exit(void)
5630 mddev_t *mddev; 5599 mddev_t *mddev;
5631 struct list_head *tmp; 5600 struct list_head *tmp;
5632 5601
5633 blk_unregister_region(MKDEV(MAJOR_NR,0), MAX_MD_DEVS); 5602 blk_unregister_region(MKDEV(MAJOR_NR,0), 1U << MINORBITS);
5634 blk_unregister_region(MKDEV(mdp_major,0), MAX_MD_DEVS << MdpMinorShift); 5603 blk_unregister_region(MKDEV(mdp_major,0), 1U << MINORBITS);
5635 5604
5636 unregister_blkdev(MAJOR_NR,"md"); 5605 unregister_blkdev(MAJOR_NR,"md");
5637 unregister_blkdev(mdp_major, "mdp"); 5606 unregister_blkdev(mdp_major, "mdp");
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 1cc9de44ce86..171ff41b52b0 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -228,6 +228,28 @@ static int multipath_issue_flush(request_queue_t *q, struct gendisk *disk,
228 rcu_read_unlock(); 228 rcu_read_unlock();
229 return ret; 229 return ret;
230} 230}
231static int multipath_congested(void *data, int bits)
232{
233 mddev_t *mddev = data;
234 multipath_conf_t *conf = mddev_to_conf(mddev);
235 int i, ret = 0;
236
237 rcu_read_lock();
238 for (i = 0; i < mddev->raid_disks ; i++) {
239 mdk_rdev_t *rdev = rcu_dereference(conf->multipaths[i].rdev);
240 if (rdev && !test_bit(Faulty, &rdev->flags)) {
241 request_queue_t *q = bdev_get_queue(rdev->bdev);
242
243 ret |= bdi_congested(&q->backing_dev_info, bits);
244 /* Just like multipath_map, we just check the
245 * first available device
246 */
247 break;
248 }
249 }
250 rcu_read_unlock();
251 return ret;
252}
231 253
232/* 254/*
233 * Careful, this can execute in IRQ contexts as well! 255 * Careful, this can execute in IRQ contexts as well!
@@ -253,7 +275,7 @@ static void multipath_error (mddev_t *mddev, mdk_rdev_t *rdev)
253 char b[BDEVNAME_SIZE]; 275 char b[BDEVNAME_SIZE];
254 clear_bit(In_sync, &rdev->flags); 276 clear_bit(In_sync, &rdev->flags);
255 set_bit(Faulty, &rdev->flags); 277 set_bit(Faulty, &rdev->flags);
256 mddev->sb_dirty = 1; 278 set_bit(MD_CHANGE_DEVS, &mddev->flags);
257 conf->working_disks--; 279 conf->working_disks--;
258 printk(KERN_ALERT "multipath: IO failure on %s," 280 printk(KERN_ALERT "multipath: IO failure on %s,"
259 " disabling IO path. \n Operation continuing" 281 " disabling IO path. \n Operation continuing"
@@ -470,7 +492,6 @@ static int multipath_run (mddev_t *mddev)
470 } 492 }
471 493
472 conf->raid_disks = mddev->raid_disks; 494 conf->raid_disks = mddev->raid_disks;
473 mddev->sb_dirty = 1;
474 conf->mddev = mddev; 495 conf->mddev = mddev;
475 spin_lock_init(&conf->device_lock); 496 spin_lock_init(&conf->device_lock);
476 INIT_LIST_HEAD(&conf->retry_list); 497 INIT_LIST_HEAD(&conf->retry_list);
@@ -510,6 +531,8 @@ static int multipath_run (mddev_t *mddev)
510 531
511 mddev->queue->unplug_fn = multipath_unplug; 532 mddev->queue->unplug_fn = multipath_unplug;
512 mddev->queue->issue_flush_fn = multipath_issue_flush; 533 mddev->queue->issue_flush_fn = multipath_issue_flush;
534 mddev->queue->backing_dev_info.congested_fn = multipath_congested;
535 mddev->queue->backing_dev_info.congested_data = mddev;
513 536
514 return 0; 537 return 0;
515 538
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index cb8c6317e4e5..dfe32149ad3a 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -60,6 +60,21 @@ static int raid0_issue_flush(request_queue_t *q, struct gendisk *disk,
60 return ret; 60 return ret;
61} 61}
62 62
63static int raid0_congested(void *data, int bits)
64{
65 mddev_t *mddev = data;
66 raid0_conf_t *conf = mddev_to_conf(mddev);
67 mdk_rdev_t **devlist = conf->strip_zone[0].dev;
68 int i, ret = 0;
69
70 for (i = 0; i < mddev->raid_disks && !ret ; i++) {
71 request_queue_t *q = bdev_get_queue(devlist[i]->bdev);
72
73 ret |= bdi_congested(&q->backing_dev_info, bits);
74 }
75 return ret;
76}
77
63 78
64static int create_strip_zones (mddev_t *mddev) 79static int create_strip_zones (mddev_t *mddev)
65{ 80{
@@ -236,6 +251,8 @@ static int create_strip_zones (mddev_t *mddev)
236 mddev->queue->unplug_fn = raid0_unplug; 251 mddev->queue->unplug_fn = raid0_unplug;
237 252
238 mddev->queue->issue_flush_fn = raid0_issue_flush; 253 mddev->queue->issue_flush_fn = raid0_issue_flush;
254 mddev->queue->backing_dev_info.congested_fn = raid0_congested;
255 mddev->queue->backing_dev_info.congested_data = mddev;
239 256
240 printk("raid0: done.\n"); 257 printk("raid0: done.\n");
241 return 0; 258 return 0;
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 3b4d69c05623..dc9d2def0270 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -271,7 +271,7 @@ static int raid1_end_read_request(struct bio *bio, unsigned int bytes_done, int
271 */ 271 */
272 update_head_pos(mirror, r1_bio); 272 update_head_pos(mirror, r1_bio);
273 273
274 if (uptodate || conf->working_disks <= 1) { 274 if (uptodate || (conf->raid_disks - conf->mddev->degraded) <= 1) {
275 /* 275 /*
276 * Set R1BIO_Uptodate in our master bio, so that 276 * Set R1BIO_Uptodate in our master bio, so that
277 * we will return a good error code for to the higher 277 * we will return a good error code for to the higher
@@ -601,6 +601,32 @@ static int raid1_issue_flush(request_queue_t *q, struct gendisk *disk,
601 return ret; 601 return ret;
602} 602}
603 603
604static int raid1_congested(void *data, int bits)
605{
606 mddev_t *mddev = data;
607 conf_t *conf = mddev_to_conf(mddev);
608 int i, ret = 0;
609
610 rcu_read_lock();
611 for (i = 0; i < mddev->raid_disks; i++) {
612 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
613 if (rdev && !test_bit(Faulty, &rdev->flags)) {
614 request_queue_t *q = bdev_get_queue(rdev->bdev);
615
616 /* Note the '|| 1' - when read_balance prefers
617 * non-congested targets, it can be removed
618 */
619 if ((bits & (1<<BDI_write_congested)) || 1)
620 ret |= bdi_congested(&q->backing_dev_info, bits);
621 else
622 ret &= bdi_congested(&q->backing_dev_info, bits);
623 }
624 }
625 rcu_read_unlock();
626 return ret;
627}
628
629
604/* Barriers.... 630/* Barriers....
605 * Sometimes we need to suspend IO while we do something else, 631 * Sometimes we need to suspend IO while we do something else,
606 * either some resync/recovery, or reconfigure the array. 632 * either some resync/recovery, or reconfigure the array.
@@ -929,7 +955,7 @@ static void status(struct seq_file *seq, mddev_t *mddev)
929 int i; 955 int i;
930 956
931 seq_printf(seq, " [%d/%d] [", conf->raid_disks, 957 seq_printf(seq, " [%d/%d] [", conf->raid_disks,
932 conf->working_disks); 958 conf->raid_disks - mddev->degraded);
933 rcu_read_lock(); 959 rcu_read_lock();
934 for (i = 0; i < conf->raid_disks; i++) { 960 for (i = 0; i < conf->raid_disks; i++) {
935 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev); 961 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
@@ -953,26 +979,27 @@ static void error(mddev_t *mddev, mdk_rdev_t *rdev)
953 * else mark the drive as failed 979 * else mark the drive as failed
954 */ 980 */
955 if (test_bit(In_sync, &rdev->flags) 981 if (test_bit(In_sync, &rdev->flags)
956 && conf->working_disks == 1) 982 && (conf->raid_disks - mddev->degraded) == 1)
957 /* 983 /*
958 * Don't fail the drive, act as though we were just a 984 * Don't fail the drive, act as though we were just a
959 * normal single drive 985 * normal single drive
960 */ 986 */
961 return; 987 return;
962 if (test_bit(In_sync, &rdev->flags)) { 988 if (test_and_clear_bit(In_sync, &rdev->flags)) {
989 unsigned long flags;
990 spin_lock_irqsave(&conf->device_lock, flags);
963 mddev->degraded++; 991 mddev->degraded++;
964 conf->working_disks--; 992 spin_unlock_irqrestore(&conf->device_lock, flags);
965 /* 993 /*
966 * if recovery is running, make sure it aborts. 994 * if recovery is running, make sure it aborts.
967 */ 995 */
968 set_bit(MD_RECOVERY_ERR, &mddev->recovery); 996 set_bit(MD_RECOVERY_ERR, &mddev->recovery);
969 } 997 }
970 clear_bit(In_sync, &rdev->flags);
971 set_bit(Faulty, &rdev->flags); 998 set_bit(Faulty, &rdev->flags);
972 mddev->sb_dirty = 1; 999 set_bit(MD_CHANGE_DEVS, &mddev->flags);
973 printk(KERN_ALERT "raid1: Disk failure on %s, disabling device. \n" 1000 printk(KERN_ALERT "raid1: Disk failure on %s, disabling device. \n"
974 " Operation continuing on %d devices\n", 1001 " Operation continuing on %d devices\n",
975 bdevname(rdev->bdev,b), conf->working_disks); 1002 bdevname(rdev->bdev,b), conf->raid_disks - mddev->degraded);
976} 1003}
977 1004
978static void print_conf(conf_t *conf) 1005static void print_conf(conf_t *conf)
@@ -984,7 +1011,7 @@ static void print_conf(conf_t *conf)
984 printk("(!conf)\n"); 1011 printk("(!conf)\n");
985 return; 1012 return;
986 } 1013 }
987 printk(" --- wd:%d rd:%d\n", conf->working_disks, 1014 printk(" --- wd:%d rd:%d\n", conf->raid_disks - conf->mddev->degraded,
988 conf->raid_disks); 1015 conf->raid_disks);
989 1016
990 rcu_read_lock(); 1017 rcu_read_lock();
@@ -1023,10 +1050,11 @@ static int raid1_spare_active(mddev_t *mddev)
1023 mdk_rdev_t *rdev = conf->mirrors[i].rdev; 1050 mdk_rdev_t *rdev = conf->mirrors[i].rdev;
1024 if (rdev 1051 if (rdev
1025 && !test_bit(Faulty, &rdev->flags) 1052 && !test_bit(Faulty, &rdev->flags)
1026 && !test_bit(In_sync, &rdev->flags)) { 1053 && !test_and_set_bit(In_sync, &rdev->flags)) {
1027 conf->working_disks++; 1054 unsigned long flags;
1055 spin_lock_irqsave(&conf->device_lock, flags);
1028 mddev->degraded--; 1056 mddev->degraded--;
1029 set_bit(In_sync, &rdev->flags); 1057 spin_unlock_irqrestore(&conf->device_lock, flags);
1030 } 1058 }
1031 } 1059 }
1032 1060
@@ -1368,6 +1396,95 @@ static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio)
1368 * 3. Performs writes following reads for array syncronising. 1396 * 3. Performs writes following reads for array syncronising.
1369 */ 1397 */
1370 1398
1399static void fix_read_error(conf_t *conf, int read_disk,
1400 sector_t sect, int sectors)
1401{
1402 mddev_t *mddev = conf->mddev;
1403 while(sectors) {
1404 int s = sectors;
1405 int d = read_disk;
1406 int success = 0;
1407 int start;
1408 mdk_rdev_t *rdev;
1409
1410 if (s > (PAGE_SIZE>>9))
1411 s = PAGE_SIZE >> 9;
1412
1413 do {
1414 /* Note: no rcu protection needed here
1415 * as this is synchronous in the raid1d thread
1416 * which is the thread that might remove
1417 * a device. If raid1d ever becomes multi-threaded....
1418 */
1419 rdev = conf->mirrors[d].rdev;
1420 if (rdev &&
1421 test_bit(In_sync, &rdev->flags) &&
1422 sync_page_io(rdev->bdev,
1423 sect + rdev->data_offset,
1424 s<<9,
1425 conf->tmppage, READ))
1426 success = 1;
1427 else {
1428 d++;
1429 if (d == conf->raid_disks)
1430 d = 0;
1431 }
1432 } while (!success && d != read_disk);
1433
1434 if (!success) {
1435 /* Cannot read from anywhere -- bye bye array */
1436 md_error(mddev, conf->mirrors[read_disk].rdev);
1437 break;
1438 }
1439 /* write it back and re-read */
1440 start = d;
1441 while (d != read_disk) {
1442 if (d==0)
1443 d = conf->raid_disks;
1444 d--;
1445 rdev = conf->mirrors[d].rdev;
1446 if (rdev &&
1447 test_bit(In_sync, &rdev->flags)) {
1448 if (sync_page_io(rdev->bdev,
1449 sect + rdev->data_offset,
1450 s<<9, conf->tmppage, WRITE)
1451 == 0)
1452 /* Well, this device is dead */
1453 md_error(mddev, rdev);
1454 }
1455 }
1456 d = start;
1457 while (d != read_disk) {
1458 char b[BDEVNAME_SIZE];
1459 if (d==0)
1460 d = conf->raid_disks;
1461 d--;
1462 rdev = conf->mirrors[d].rdev;
1463 if (rdev &&
1464 test_bit(In_sync, &rdev->flags)) {
1465 if (sync_page_io(rdev->bdev,
1466 sect + rdev->data_offset,
1467 s<<9, conf->tmppage, READ)
1468 == 0)
1469 /* Well, this device is dead */
1470 md_error(mddev, rdev);
1471 else {
1472 atomic_add(s, &rdev->corrected_errors);
1473 printk(KERN_INFO
1474 "raid1:%s: read error corrected "
1475 "(%d sectors at %llu on %s)\n",
1476 mdname(mddev), s,
1477 (unsigned long long)sect +
1478 rdev->data_offset,
1479 bdevname(rdev->bdev, b));
1480 }
1481 }
1482 }
1483 sectors -= s;
1484 sect += s;
1485 }
1486}
1487
1371static void raid1d(mddev_t *mddev) 1488static void raid1d(mddev_t *mddev)
1372{ 1489{
1373 r1bio_t *r1_bio; 1490 r1bio_t *r1_bio;
@@ -1460,86 +1577,14 @@ static void raid1d(mddev_t *mddev)
1460 * This is all done synchronously while the array is 1577 * This is all done synchronously while the array is
1461 * frozen 1578 * frozen
1462 */ 1579 */
1463 sector_t sect = r1_bio->sector; 1580 if (mddev->ro == 0) {
1464 int sectors = r1_bio->sectors; 1581 freeze_array(conf);
1465 freeze_array(conf); 1582 fix_read_error(conf, r1_bio->read_disk,
1466 if (mddev->ro == 0) while(sectors) { 1583 r1_bio->sector,
1467 int s = sectors; 1584 r1_bio->sectors);
1468 int d = r1_bio->read_disk; 1585 unfreeze_array(conf);
1469 int success = 0;
1470
1471 if (s > (PAGE_SIZE>>9))
1472 s = PAGE_SIZE >> 9;
1473
1474 do {
1475 /* Note: no rcu protection needed here
1476 * as this is synchronous in the raid1d thread
1477 * which is the thread that might remove
1478 * a device. If raid1d ever becomes multi-threaded....
1479 */
1480 rdev = conf->mirrors[d].rdev;
1481 if (rdev &&
1482 test_bit(In_sync, &rdev->flags) &&
1483 sync_page_io(rdev->bdev,
1484 sect + rdev->data_offset,
1485 s<<9,
1486 conf->tmppage, READ))
1487 success = 1;
1488 else {
1489 d++;
1490 if (d == conf->raid_disks)
1491 d = 0;
1492 }
1493 } while (!success && d != r1_bio->read_disk);
1494
1495 if (success) {
1496 /* write it back and re-read */
1497 int start = d;
1498 while (d != r1_bio->read_disk) {
1499 if (d==0)
1500 d = conf->raid_disks;
1501 d--;
1502 rdev = conf->mirrors[d].rdev;
1503 if (rdev &&
1504 test_bit(In_sync, &rdev->flags)) {
1505 if (sync_page_io(rdev->bdev,
1506 sect + rdev->data_offset,
1507 s<<9, conf->tmppage, WRITE) == 0)
1508 /* Well, this device is dead */
1509 md_error(mddev, rdev);
1510 }
1511 }
1512 d = start;
1513 while (d != r1_bio->read_disk) {
1514 if (d==0)
1515 d = conf->raid_disks;
1516 d--;
1517 rdev = conf->mirrors[d].rdev;
1518 if (rdev &&
1519 test_bit(In_sync, &rdev->flags)) {
1520 if (sync_page_io(rdev->bdev,
1521 sect + rdev->data_offset,
1522 s<<9, conf->tmppage, READ) == 0)
1523 /* Well, this device is dead */
1524 md_error(mddev, rdev);
1525 else {
1526 atomic_add(s, &rdev->corrected_errors);
1527 printk(KERN_INFO "raid1:%s: read error corrected (%d sectors at %llu on %s)\n",
1528 mdname(mddev), s, (unsigned long long)(sect + rdev->data_offset), bdevname(rdev->bdev, b));
1529 }
1530 }
1531 }
1532 } else {
1533 /* Cannot read from anywhere -- bye bye array */
1534 md_error(mddev, conf->mirrors[r1_bio->read_disk].rdev);
1535 break;
1536 }
1537 sectors -= s;
1538 sect += s;
1539 } 1586 }
1540 1587
1541 unfreeze_array(conf);
1542
1543 bio = r1_bio->bios[r1_bio->read_disk]; 1588 bio = r1_bio->bios[r1_bio->read_disk];
1544 if ((disk=read_balance(conf, r1_bio)) == -1) { 1589 if ((disk=read_balance(conf, r1_bio)) == -1) {
1545 printk(KERN_ALERT "raid1: %s: unrecoverable I/O" 1590 printk(KERN_ALERT "raid1: %s: unrecoverable I/O"
@@ -1884,15 +1929,11 @@ static int run(mddev_t *mddev)
1884 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); 1929 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
1885 1930
1886 disk->head_position = 0; 1931 disk->head_position = 0;
1887 if (!test_bit(Faulty, &rdev->flags) && test_bit(In_sync, &rdev->flags))
1888 conf->working_disks++;
1889 } 1932 }
1890 conf->raid_disks = mddev->raid_disks; 1933 conf->raid_disks = mddev->raid_disks;
1891 conf->mddev = mddev; 1934 conf->mddev = mddev;
1892 spin_lock_init(&conf->device_lock); 1935 spin_lock_init(&conf->device_lock);
1893 INIT_LIST_HEAD(&conf->retry_list); 1936 INIT_LIST_HEAD(&conf->retry_list);
1894 if (conf->working_disks == 1)
1895 mddev->recovery_cp = MaxSector;
1896 1937
1897 spin_lock_init(&conf->resync_lock); 1938 spin_lock_init(&conf->resync_lock);
1898 init_waitqueue_head(&conf->wait_barrier); 1939 init_waitqueue_head(&conf->wait_barrier);
@@ -1900,11 +1941,6 @@ static int run(mddev_t *mddev)
1900 bio_list_init(&conf->pending_bio_list); 1941 bio_list_init(&conf->pending_bio_list);
1901 bio_list_init(&conf->flushing_bio_list); 1942 bio_list_init(&conf->flushing_bio_list);
1902 1943
1903 if (!conf->working_disks) {
1904 printk(KERN_ERR "raid1: no operational mirrors for %s\n",
1905 mdname(mddev));
1906 goto out_free_conf;
1907 }
1908 1944
1909 mddev->degraded = 0; 1945 mddev->degraded = 0;
1910 for (i = 0; i < conf->raid_disks; i++) { 1946 for (i = 0; i < conf->raid_disks; i++) {
@@ -1917,6 +1953,13 @@ static int run(mddev_t *mddev)
1917 mddev->degraded++; 1953 mddev->degraded++;
1918 } 1954 }
1919 } 1955 }
1956 if (mddev->degraded == conf->raid_disks) {
1957 printk(KERN_ERR "raid1: no operational mirrors for %s\n",
1958 mdname(mddev));
1959 goto out_free_conf;
1960 }
1961 if (conf->raid_disks - mddev->degraded == 1)
1962 mddev->recovery_cp = MaxSector;
1920 1963
1921 /* 1964 /*
1922 * find the first working one and use it as a starting point 1965 * find the first working one and use it as a starting point
@@ -1948,6 +1991,8 @@ static int run(mddev_t *mddev)
1948 1991
1949 mddev->queue->unplug_fn = raid1_unplug; 1992 mddev->queue->unplug_fn = raid1_unplug;
1950 mddev->queue->issue_flush_fn = raid1_issue_flush; 1993 mddev->queue->issue_flush_fn = raid1_issue_flush;
1994 mddev->queue->backing_dev_info.congested_fn = raid1_congested;
1995 mddev->queue->backing_dev_info.congested_data = mddev;
1951 1996
1952 return 0; 1997 return 0;
1953 1998
@@ -2035,7 +2080,7 @@ static int raid1_reshape(mddev_t *mddev)
2035 mirror_info_t *newmirrors; 2080 mirror_info_t *newmirrors;
2036 conf_t *conf = mddev_to_conf(mddev); 2081 conf_t *conf = mddev_to_conf(mddev);
2037 int cnt, raid_disks; 2082 int cnt, raid_disks;
2038 2083 unsigned long flags;
2039 int d, d2; 2084 int d, d2;
2040 2085
2041 /* Cannot change chunk_size, layout, or level */ 2086 /* Cannot change chunk_size, layout, or level */
@@ -2094,7 +2139,9 @@ static int raid1_reshape(mddev_t *mddev)
2094 kfree(conf->poolinfo); 2139 kfree(conf->poolinfo);
2095 conf->poolinfo = newpoolinfo; 2140 conf->poolinfo = newpoolinfo;
2096 2141
2142 spin_lock_irqsave(&conf->device_lock, flags);
2097 mddev->degraded += (raid_disks - conf->raid_disks); 2143 mddev->degraded += (raid_disks - conf->raid_disks);
2144 spin_unlock_irqrestore(&conf->device_lock, flags);
2098 conf->raid_disks = mddev->raid_disks = raid_disks; 2145 conf->raid_disks = mddev->raid_disks = raid_disks;
2099 mddev->delta_disks = 0; 2146 mddev->delta_disks = 0;
2100 2147
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 016ddb831c9b..1250f0eab4af 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -648,6 +648,26 @@ static int raid10_issue_flush(request_queue_t *q, struct gendisk *disk,
648 return ret; 648 return ret;
649} 649}
650 650
651static int raid10_congested(void *data, int bits)
652{
653 mddev_t *mddev = data;
654 conf_t *conf = mddev_to_conf(mddev);
655 int i, ret = 0;
656
657 rcu_read_lock();
658 for (i = 0; i < mddev->raid_disks && ret == 0; i++) {
659 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
660 if (rdev && !test_bit(Faulty, &rdev->flags)) {
661 request_queue_t *q = bdev_get_queue(rdev->bdev);
662
663 ret |= bdi_congested(&q->backing_dev_info, bits);
664 }
665 }
666 rcu_read_unlock();
667 return ret;
668}
669
670
651/* Barriers.... 671/* Barriers....
652 * Sometimes we need to suspend IO while we do something else, 672 * Sometimes we need to suspend IO while we do something else,
653 * either some resync/recovery, or reconfigure the array. 673 * either some resync/recovery, or reconfigure the array.
@@ -921,7 +941,7 @@ static void status(struct seq_file *seq, mddev_t *mddev)
921 seq_printf(seq, " %d far-copies", conf->far_copies); 941 seq_printf(seq, " %d far-copies", conf->far_copies);
922 } 942 }
923 seq_printf(seq, " [%d/%d] [", conf->raid_disks, 943 seq_printf(seq, " [%d/%d] [", conf->raid_disks,
924 conf->working_disks); 944 conf->raid_disks - mddev->degraded);
925 for (i = 0; i < conf->raid_disks; i++) 945 for (i = 0; i < conf->raid_disks; i++)
926 seq_printf(seq, "%s", 946 seq_printf(seq, "%s",
927 conf->mirrors[i].rdev && 947 conf->mirrors[i].rdev &&
@@ -941,7 +961,7 @@ static void error(mddev_t *mddev, mdk_rdev_t *rdev)
941 * else mark the drive as failed 961 * else mark the drive as failed
942 */ 962 */
943 if (test_bit(In_sync, &rdev->flags) 963 if (test_bit(In_sync, &rdev->flags)
944 && conf->working_disks == 1) 964 && conf->raid_disks-mddev->degraded == 1)
945 /* 965 /*
946 * Don't fail the drive, just return an IO error. 966 * Don't fail the drive, just return an IO error.
947 * The test should really be more sophisticated than 967 * The test should really be more sophisticated than
@@ -950,20 +970,21 @@ static void error(mddev_t *mddev, mdk_rdev_t *rdev)
950 * really dead" tests... 970 * really dead" tests...
951 */ 971 */
952 return; 972 return;
953 if (test_bit(In_sync, &rdev->flags)) { 973 if (test_and_clear_bit(In_sync, &rdev->flags)) {
974 unsigned long flags;
975 spin_lock_irqsave(&conf->device_lock, flags);
954 mddev->degraded++; 976 mddev->degraded++;
955 conf->working_disks--; 977 spin_unlock_irqrestore(&conf->device_lock, flags);
956 /* 978 /*
957 * if recovery is running, make sure it aborts. 979 * if recovery is running, make sure it aborts.
958 */ 980 */
959 set_bit(MD_RECOVERY_ERR, &mddev->recovery); 981 set_bit(MD_RECOVERY_ERR, &mddev->recovery);
960 } 982 }
961 clear_bit(In_sync, &rdev->flags);
962 set_bit(Faulty, &rdev->flags); 983 set_bit(Faulty, &rdev->flags);
963 mddev->sb_dirty = 1; 984 set_bit(MD_CHANGE_DEVS, &mddev->flags);
964 printk(KERN_ALERT "raid10: Disk failure on %s, disabling device. \n" 985 printk(KERN_ALERT "raid10: Disk failure on %s, disabling device. \n"
965 " Operation continuing on %d devices\n", 986 " Operation continuing on %d devices\n",
966 bdevname(rdev->bdev,b), conf->working_disks); 987 bdevname(rdev->bdev,b), conf->raid_disks - mddev->degraded);
967} 988}
968 989
969static void print_conf(conf_t *conf) 990static void print_conf(conf_t *conf)
@@ -976,7 +997,7 @@ static void print_conf(conf_t *conf)
976 printk("(!conf)\n"); 997 printk("(!conf)\n");
977 return; 998 return;
978 } 999 }
979 printk(" --- wd:%d rd:%d\n", conf->working_disks, 1000 printk(" --- wd:%d rd:%d\n", conf->raid_disks - conf->mddev->degraded,
980 conf->raid_disks); 1001 conf->raid_disks);
981 1002
982 for (i = 0; i < conf->raid_disks; i++) { 1003 for (i = 0; i < conf->raid_disks; i++) {
@@ -1034,10 +1055,11 @@ static int raid10_spare_active(mddev_t *mddev)
1034 tmp = conf->mirrors + i; 1055 tmp = conf->mirrors + i;
1035 if (tmp->rdev 1056 if (tmp->rdev
1036 && !test_bit(Faulty, &tmp->rdev->flags) 1057 && !test_bit(Faulty, &tmp->rdev->flags)
1037 && !test_bit(In_sync, &tmp->rdev->flags)) { 1058 && !test_and_set_bit(In_sync, &tmp->rdev->flags)) {
1038 conf->working_disks++; 1059 unsigned long flags;
1060 spin_lock_irqsave(&conf->device_lock, flags);
1039 mddev->degraded--; 1061 mddev->degraded--;
1040 set_bit(In_sync, &tmp->rdev->flags); 1062 spin_unlock_irqrestore(&conf->device_lock, flags);
1041 } 1063 }
1042 } 1064 }
1043 1065
@@ -1350,9 +1372,119 @@ static void recovery_request_write(mddev_t *mddev, r10bio_t *r10_bio)
1350 * 1372 *
1351 * 1. Retries failed read operations on working mirrors. 1373 * 1. Retries failed read operations on working mirrors.
1352 * 2. Updates the raid superblock when problems encounter. 1374 * 2. Updates the raid superblock when problems encounter.
1353 * 3. Performs writes following reads for array syncronising. 1375 * 3. Performs writes following reads for array synchronising.
1354 */ 1376 */
1355 1377
1378static void fix_read_error(conf_t *conf, mddev_t *mddev, r10bio_t *r10_bio)
1379{
1380 int sect = 0; /* Offset from r10_bio->sector */
1381 int sectors = r10_bio->sectors;
1382 mdk_rdev_t*rdev;
1383 while(sectors) {
1384 int s = sectors;
1385 int sl = r10_bio->read_slot;
1386 int success = 0;
1387 int start;
1388
1389 if (s > (PAGE_SIZE>>9))
1390 s = PAGE_SIZE >> 9;
1391
1392 rcu_read_lock();
1393 do {
1394 int d = r10_bio->devs[sl].devnum;
1395 rdev = rcu_dereference(conf->mirrors[d].rdev);
1396 if (rdev &&
1397 test_bit(In_sync, &rdev->flags)) {
1398 atomic_inc(&rdev->nr_pending);
1399 rcu_read_unlock();
1400 success = sync_page_io(rdev->bdev,
1401 r10_bio->devs[sl].addr +
1402 sect + rdev->data_offset,
1403 s<<9,
1404 conf->tmppage, READ);
1405 rdev_dec_pending(rdev, mddev);
1406 rcu_read_lock();
1407 if (success)
1408 break;
1409 }
1410 sl++;
1411 if (sl == conf->copies)
1412 sl = 0;
1413 } while (!success && sl != r10_bio->read_slot);
1414 rcu_read_unlock();
1415
1416 if (!success) {
1417 /* Cannot read from anywhere -- bye bye array */
1418 int dn = r10_bio->devs[r10_bio->read_slot].devnum;
1419 md_error(mddev, conf->mirrors[dn].rdev);
1420 break;
1421 }
1422
1423 start = sl;
1424 /* write it back and re-read */
1425 rcu_read_lock();
1426 while (sl != r10_bio->read_slot) {
1427 int d;
1428 if (sl==0)
1429 sl = conf->copies;
1430 sl--;
1431 d = r10_bio->devs[sl].devnum;
1432 rdev = rcu_dereference(conf->mirrors[d].rdev);
1433 if (rdev &&
1434 test_bit(In_sync, &rdev->flags)) {
1435 atomic_inc(&rdev->nr_pending);
1436 rcu_read_unlock();
1437 atomic_add(s, &rdev->corrected_errors);
1438 if (sync_page_io(rdev->bdev,
1439 r10_bio->devs[sl].addr +
1440 sect + rdev->data_offset,
1441 s<<9, conf->tmppage, WRITE)
1442 == 0)
1443 /* Well, this device is dead */
1444 md_error(mddev, rdev);
1445 rdev_dec_pending(rdev, mddev);
1446 rcu_read_lock();
1447 }
1448 }
1449 sl = start;
1450 while (sl != r10_bio->read_slot) {
1451 int d;
1452 if (sl==0)
1453 sl = conf->copies;
1454 sl--;
1455 d = r10_bio->devs[sl].devnum;
1456 rdev = rcu_dereference(conf->mirrors[d].rdev);
1457 if (rdev &&
1458 test_bit(In_sync, &rdev->flags)) {
1459 char b[BDEVNAME_SIZE];
1460 atomic_inc(&rdev->nr_pending);
1461 rcu_read_unlock();
1462 if (sync_page_io(rdev->bdev,
1463 r10_bio->devs[sl].addr +
1464 sect + rdev->data_offset,
1465 s<<9, conf->tmppage, READ) == 0)
1466 /* Well, this device is dead */
1467 md_error(mddev, rdev);
1468 else
1469 printk(KERN_INFO
1470 "raid10:%s: read error corrected"
1471 " (%d sectors at %llu on %s)\n",
1472 mdname(mddev), s,
1473 (unsigned long long)sect+
1474 rdev->data_offset,
1475 bdevname(rdev->bdev, b));
1476
1477 rdev_dec_pending(rdev, mddev);
1478 rcu_read_lock();
1479 }
1480 }
1481 rcu_read_unlock();
1482
1483 sectors -= s;
1484 sect += s;
1485 }
1486}
1487
1356static void raid10d(mddev_t *mddev) 1488static void raid10d(mddev_t *mddev)
1357{ 1489{
1358 r10bio_t *r10_bio; 1490 r10bio_t *r10_bio;
@@ -1413,105 +1545,12 @@ static void raid10d(mddev_t *mddev)
1413 * This is all done synchronously while the array is 1545 * This is all done synchronously while the array is
1414 * frozen. 1546 * frozen.
1415 */ 1547 */
1416 int sect = 0; /* Offset from r10_bio->sector */ 1548 if (mddev->ro == 0) {
1417 int sectors = r10_bio->sectors; 1549 freeze_array(conf);
1418 freeze_array(conf); 1550 fix_read_error(conf, mddev, r10_bio);
1419 if (mddev->ro == 0) while(sectors) { 1551 unfreeze_array(conf);
1420 int s = sectors;
1421 int sl = r10_bio->read_slot;
1422 int success = 0;
1423
1424 if (s > (PAGE_SIZE>>9))
1425 s = PAGE_SIZE >> 9;
1426
1427 rcu_read_lock();
1428 do {
1429 int d = r10_bio->devs[sl].devnum;
1430 rdev = rcu_dereference(conf->mirrors[d].rdev);
1431 if (rdev &&
1432 test_bit(In_sync, &rdev->flags)) {
1433 atomic_inc(&rdev->nr_pending);
1434 rcu_read_unlock();
1435 success = sync_page_io(rdev->bdev,
1436 r10_bio->devs[sl].addr +
1437 sect + rdev->data_offset,
1438 s<<9,
1439 conf->tmppage, READ);
1440 rdev_dec_pending(rdev, mddev);
1441 rcu_read_lock();
1442 if (success)
1443 break;
1444 }
1445 sl++;
1446 if (sl == conf->copies)
1447 sl = 0;
1448 } while (!success && sl != r10_bio->read_slot);
1449 rcu_read_unlock();
1450
1451 if (success) {
1452 int start = sl;
1453 /* write it back and re-read */
1454 rcu_read_lock();
1455 while (sl != r10_bio->read_slot) {
1456 int d;
1457 if (sl==0)
1458 sl = conf->copies;
1459 sl--;
1460 d = r10_bio->devs[sl].devnum;
1461 rdev = rcu_dereference(conf->mirrors[d].rdev);
1462 if (rdev &&
1463 test_bit(In_sync, &rdev->flags)) {
1464 atomic_inc(&rdev->nr_pending);
1465 rcu_read_unlock();
1466 atomic_add(s, &rdev->corrected_errors);
1467 if (sync_page_io(rdev->bdev,
1468 r10_bio->devs[sl].addr +
1469 sect + rdev->data_offset,
1470 s<<9, conf->tmppage, WRITE) == 0)
1471 /* Well, this device is dead */
1472 md_error(mddev, rdev);
1473 rdev_dec_pending(rdev, mddev);
1474 rcu_read_lock();
1475 }
1476 }
1477 sl = start;
1478 while (sl != r10_bio->read_slot) {
1479 int d;
1480 if (sl==0)
1481 sl = conf->copies;
1482 sl--;
1483 d = r10_bio->devs[sl].devnum;
1484 rdev = rcu_dereference(conf->mirrors[d].rdev);
1485 if (rdev &&
1486 test_bit(In_sync, &rdev->flags)) {
1487 atomic_inc(&rdev->nr_pending);
1488 rcu_read_unlock();
1489 if (sync_page_io(rdev->bdev,
1490 r10_bio->devs[sl].addr +
1491 sect + rdev->data_offset,
1492 s<<9, conf->tmppage, READ) == 0)
1493 /* Well, this device is dead */
1494 md_error(mddev, rdev);
1495 else
1496 printk(KERN_INFO "raid10:%s: read error corrected (%d sectors at %llu on %s)\n",
1497 mdname(mddev), s, (unsigned long long)(sect+rdev->data_offset), bdevname(rdev->bdev, b));
1498
1499 rdev_dec_pending(rdev, mddev);
1500 rcu_read_lock();
1501 }
1502 }
1503 rcu_read_unlock();
1504 } else {
1505 /* Cannot read from anywhere -- bye bye array */
1506 md_error(mddev, conf->mirrors[r10_bio->devs[r10_bio->read_slot].devnum].rdev);
1507 break;
1508 }
1509 sectors -= s;
1510 sect += s;
1511 } 1552 }
1512 1553
1513 unfreeze_array(conf);
1514
1515 bio = r10_bio->devs[r10_bio->read_slot].bio; 1554 bio = r10_bio->devs[r10_bio->read_slot].bio;
1516 r10_bio->devs[r10_bio->read_slot].bio = 1555 r10_bio->devs[r10_bio->read_slot].bio =
1517 mddev->ro ? IO_BLOCKED : NULL; 1556 mddev->ro ? IO_BLOCKED : NULL;
@@ -2018,8 +2057,6 @@ static int run(mddev_t *mddev)
2018 mddev->queue->max_sectors = (PAGE_SIZE>>9); 2057 mddev->queue->max_sectors = (PAGE_SIZE>>9);
2019 2058
2020 disk->head_position = 0; 2059 disk->head_position = 0;
2021 if (!test_bit(Faulty, &rdev->flags) && test_bit(In_sync, &rdev->flags))
2022 conf->working_disks++;
2023 } 2060 }
2024 conf->raid_disks = mddev->raid_disks; 2061 conf->raid_disks = mddev->raid_disks;
2025 conf->mddev = mddev; 2062 conf->mddev = mddev;
@@ -2077,6 +2114,8 @@ static int run(mddev_t *mddev)
2077 2114
2078 mddev->queue->unplug_fn = raid10_unplug; 2115 mddev->queue->unplug_fn = raid10_unplug;
2079 mddev->queue->issue_flush_fn = raid10_issue_flush; 2116 mddev->queue->issue_flush_fn = raid10_issue_flush;
2117 mddev->queue->backing_dev_info.congested_fn = raid10_congested;
2118 mddev->queue->backing_dev_info.congested_data = mddev;
2080 2119
2081 /* Calculate max read-ahead size. 2120 /* Calculate max read-ahead size.
2082 * We need to readahead at least twice a whole stripe.... 2121 * We need to readahead at least twice a whole stripe....
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 450066007160..37e4ff661b6c 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -636,7 +636,6 @@ static int raid5_end_write_request (struct bio *bi, unsigned int bytes_done,
636 struct stripe_head *sh = bi->bi_private; 636 struct stripe_head *sh = bi->bi_private;
637 raid5_conf_t *conf = sh->raid_conf; 637 raid5_conf_t *conf = sh->raid_conf;
638 int disks = sh->disks, i; 638 int disks = sh->disks, i;
639 unsigned long flags;
640 int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); 639 int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags);
641 640
642 if (bi->bi_size) 641 if (bi->bi_size)
@@ -654,7 +653,6 @@ static int raid5_end_write_request (struct bio *bi, unsigned int bytes_done,
654 return 0; 653 return 0;
655 } 654 }
656 655
657 spin_lock_irqsave(&conf->device_lock, flags);
658 if (!uptodate) 656 if (!uptodate)
659 md_error(conf->mddev, conf->disks[i].rdev); 657 md_error(conf->mddev, conf->disks[i].rdev);
660 658
@@ -662,8 +660,7 @@ static int raid5_end_write_request (struct bio *bi, unsigned int bytes_done,
662 660
663 clear_bit(R5_LOCKED, &sh->dev[i].flags); 661 clear_bit(R5_LOCKED, &sh->dev[i].flags);
664 set_bit(STRIPE_HANDLE, &sh->state); 662 set_bit(STRIPE_HANDLE, &sh->state);
665 __release_stripe(conf, sh); 663 release_stripe(sh);
666 spin_unlock_irqrestore(&conf->device_lock, flags);
667 return 0; 664 return 0;
668} 665}
669 666
@@ -696,12 +693,12 @@ static void error(mddev_t *mddev, mdk_rdev_t *rdev)
696 PRINTK("raid5: error called\n"); 693 PRINTK("raid5: error called\n");
697 694
698 if (!test_bit(Faulty, &rdev->flags)) { 695 if (!test_bit(Faulty, &rdev->flags)) {
699 mddev->sb_dirty = 1; 696 set_bit(MD_CHANGE_DEVS, &mddev->flags);
700 if (test_bit(In_sync, &rdev->flags)) { 697 if (test_and_clear_bit(In_sync, &rdev->flags)) {
701 conf->working_disks--; 698 unsigned long flags;
699 spin_lock_irqsave(&conf->device_lock, flags);
702 mddev->degraded++; 700 mddev->degraded++;
703 conf->failed_disks++; 701 spin_unlock_irqrestore(&conf->device_lock, flags);
704 clear_bit(In_sync, &rdev->flags);
705 /* 702 /*
706 * if recovery was running, make sure it aborts. 703 * if recovery was running, make sure it aborts.
707 */ 704 */
@@ -711,7 +708,7 @@ static void error(mddev_t *mddev, mdk_rdev_t *rdev)
711 printk (KERN_ALERT 708 printk (KERN_ALERT
712 "raid5: Disk failure on %s, disabling device." 709 "raid5: Disk failure on %s, disabling device."
713 " Operation continuing on %d devices\n", 710 " Operation continuing on %d devices\n",
714 bdevname(rdev->bdev,b), conf->working_disks); 711 bdevname(rdev->bdev,b), conf->raid_disks - mddev->degraded);
715 } 712 }
716} 713}
717 714
@@ -1353,10 +1350,9 @@ static int page_is_zero(struct page *p)
1353static int stripe_to_pdidx(sector_t stripe, raid5_conf_t *conf, int disks) 1350static int stripe_to_pdidx(sector_t stripe, raid5_conf_t *conf, int disks)
1354{ 1351{
1355 int sectors_per_chunk = conf->chunk_size >> 9; 1352 int sectors_per_chunk = conf->chunk_size >> 9;
1356 sector_t x = stripe;
1357 int pd_idx, dd_idx; 1353 int pd_idx, dd_idx;
1358 int chunk_offset = sector_div(x, sectors_per_chunk); 1354 int chunk_offset = sector_div(stripe, sectors_per_chunk);
1359 stripe = x; 1355
1360 raid5_compute_sector(stripe*(disks-1)*sectors_per_chunk 1356 raid5_compute_sector(stripe*(disks-1)*sectors_per_chunk
1361 + chunk_offset, disks, disks-1, &dd_idx, &pd_idx, conf); 1357 + chunk_offset, disks, disks-1, &dd_idx, &pd_idx, conf);
1362 return pd_idx; 1358 return pd_idx;
@@ -2597,6 +2593,24 @@ static int raid5_issue_flush(request_queue_t *q, struct gendisk *disk,
2597 return ret; 2593 return ret;
2598} 2594}
2599 2595
2596static int raid5_congested(void *data, int bits)
2597{
2598 mddev_t *mddev = data;
2599 raid5_conf_t *conf = mddev_to_conf(mddev);
2600
2601 /* No difference between reads and writes. Just check
2602 * how busy the stripe_cache is
2603 */
2604 if (conf->inactive_blocked)
2605 return 1;
2606 if (conf->quiesce)
2607 return 1;
2608 if (list_empty_careful(&conf->inactive_list))
2609 return 1;
2610
2611 return 0;
2612}
2613
2600static int make_request(request_queue_t *q, struct bio * bi) 2614static int make_request(request_queue_t *q, struct bio * bi)
2601{ 2615{
2602 mddev_t *mddev = q->queuedata; 2616 mddev_t *mddev = q->queuedata;
@@ -2781,9 +2795,9 @@ static sector_t reshape_request(mddev_t *mddev, sector_t sector_nr, int *skipped
2781 wait_event(conf->wait_for_overlap, 2795 wait_event(conf->wait_for_overlap,
2782 atomic_read(&conf->reshape_stripes)==0); 2796 atomic_read(&conf->reshape_stripes)==0);
2783 mddev->reshape_position = conf->expand_progress; 2797 mddev->reshape_position = conf->expand_progress;
2784 mddev->sb_dirty = 1; 2798 set_bit(MD_CHANGE_DEVS, &mddev->flags);
2785 md_wakeup_thread(mddev->thread); 2799 md_wakeup_thread(mddev->thread);
2786 wait_event(mddev->sb_wait, mddev->sb_dirty == 0 || 2800 wait_event(mddev->sb_wait, mddev->flags == 0 ||
2787 kthread_should_stop()); 2801 kthread_should_stop());
2788 spin_lock_irq(&conf->device_lock); 2802 spin_lock_irq(&conf->device_lock);
2789 conf->expand_lo = mddev->reshape_position; 2803 conf->expand_lo = mddev->reshape_position;
@@ -3074,6 +3088,7 @@ static int run(mddev_t *mddev)
3074 mdk_rdev_t *rdev; 3088 mdk_rdev_t *rdev;
3075 struct disk_info *disk; 3089 struct disk_info *disk;
3076 struct list_head *tmp; 3090 struct list_head *tmp;
3091 int working_disks = 0;
3077 3092
3078 if (mddev->level != 5 && mddev->level != 4 && mddev->level != 6) { 3093 if (mddev->level != 5 && mddev->level != 4 && mddev->level != 6) {
3079 printk(KERN_ERR "raid5: %s: raid level not set to 4/5/6 (%d)\n", 3094 printk(KERN_ERR "raid5: %s: raid level not set to 4/5/6 (%d)\n",
@@ -3176,14 +3191,14 @@ static int run(mddev_t *mddev)
3176 printk(KERN_INFO "raid5: device %s operational as raid" 3191 printk(KERN_INFO "raid5: device %s operational as raid"
3177 " disk %d\n", bdevname(rdev->bdev,b), 3192 " disk %d\n", bdevname(rdev->bdev,b),
3178 raid_disk); 3193 raid_disk);
3179 conf->working_disks++; 3194 working_disks++;
3180 } 3195 }
3181 } 3196 }
3182 3197
3183 /* 3198 /*
3184 * 0 for a fully functional array, 1 or 2 for a degraded array. 3199 * 0 for a fully functional array, 1 or 2 for a degraded array.
3185 */ 3200 */
3186 mddev->degraded = conf->failed_disks = conf->raid_disks - conf->working_disks; 3201 mddev->degraded = conf->raid_disks - working_disks;
3187 conf->mddev = mddev; 3202 conf->mddev = mddev;
3188 conf->chunk_size = mddev->chunk_size; 3203 conf->chunk_size = mddev->chunk_size;
3189 conf->level = mddev->level; 3204 conf->level = mddev->level;
@@ -3218,7 +3233,7 @@ static int run(mddev_t *mddev)
3218 if (mddev->degraded > conf->max_degraded) { 3233 if (mddev->degraded > conf->max_degraded) {
3219 printk(KERN_ERR "raid5: not enough operational devices for %s" 3234 printk(KERN_ERR "raid5: not enough operational devices for %s"
3220 " (%d/%d failed)\n", 3235 " (%d/%d failed)\n",
3221 mdname(mddev), conf->failed_disks, conf->raid_disks); 3236 mdname(mddev), mddev->degraded, conf->raid_disks);
3222 goto abort; 3237 goto abort;
3223 } 3238 }
3224 3239
@@ -3299,6 +3314,9 @@ static int run(mddev_t *mddev)
3299 3314
3300 mddev->queue->unplug_fn = raid5_unplug_device; 3315 mddev->queue->unplug_fn = raid5_unplug_device;
3301 mddev->queue->issue_flush_fn = raid5_issue_flush; 3316 mddev->queue->issue_flush_fn = raid5_issue_flush;
3317 mddev->queue->backing_dev_info.congested_fn = raid5_congested;
3318 mddev->queue->backing_dev_info.congested_data = mddev;
3319
3302 mddev->array_size = mddev->size * (conf->previous_raid_disks - 3320 mddev->array_size = mddev->size * (conf->previous_raid_disks -
3303 conf->max_degraded); 3321 conf->max_degraded);
3304 3322
@@ -3375,7 +3393,7 @@ static void status (struct seq_file *seq, mddev_t *mddev)
3375 int i; 3393 int i;
3376 3394
3377 seq_printf (seq, " level %d, %dk chunk, algorithm %d", mddev->level, mddev->chunk_size >> 10, mddev->layout); 3395 seq_printf (seq, " level %d, %dk chunk, algorithm %d", mddev->level, mddev->chunk_size >> 10, mddev->layout);
3378 seq_printf (seq, " [%d/%d] [", conf->raid_disks, conf->working_disks); 3396 seq_printf (seq, " [%d/%d] [", conf->raid_disks, conf->raid_disks - mddev->degraded);
3379 for (i = 0; i < conf->raid_disks; i++) 3397 for (i = 0; i < conf->raid_disks; i++)
3380 seq_printf (seq, "%s", 3398 seq_printf (seq, "%s",
3381 conf->disks[i].rdev && 3399 conf->disks[i].rdev &&
@@ -3397,8 +3415,8 @@ static void print_raid5_conf (raid5_conf_t *conf)
3397 printk("(conf==NULL)\n"); 3415 printk("(conf==NULL)\n");
3398 return; 3416 return;
3399 } 3417 }
3400 printk(" --- rd:%d wd:%d fd:%d\n", conf->raid_disks, 3418 printk(" --- rd:%d wd:%d\n", conf->raid_disks,
3401 conf->working_disks, conf->failed_disks); 3419 conf->raid_disks - conf->mddev->degraded);
3402 3420
3403 for (i = 0; i < conf->raid_disks; i++) { 3421 for (i = 0; i < conf->raid_disks; i++) {
3404 char b[BDEVNAME_SIZE]; 3422 char b[BDEVNAME_SIZE];
@@ -3420,11 +3438,11 @@ static int raid5_spare_active(mddev_t *mddev)
3420 tmp = conf->disks + i; 3438 tmp = conf->disks + i;
3421 if (tmp->rdev 3439 if (tmp->rdev
3422 && !test_bit(Faulty, &tmp->rdev->flags) 3440 && !test_bit(Faulty, &tmp->rdev->flags)
3423 && !test_bit(In_sync, &tmp->rdev->flags)) { 3441 && !test_and_set_bit(In_sync, &tmp->rdev->flags)) {
3442 unsigned long flags;
3443 spin_lock_irqsave(&conf->device_lock, flags);
3424 mddev->degraded--; 3444 mddev->degraded--;
3425 conf->failed_disks--; 3445 spin_unlock_irqrestore(&conf->device_lock, flags);
3426 conf->working_disks++;
3427 set_bit(In_sync, &tmp->rdev->flags);
3428 } 3446 }
3429 } 3447 }
3430 print_raid5_conf(conf); 3448 print_raid5_conf(conf);
@@ -3560,6 +3578,7 @@ static int raid5_start_reshape(mddev_t *mddev)
3560 struct list_head *rtmp; 3578 struct list_head *rtmp;
3561 int spares = 0; 3579 int spares = 0;
3562 int added_devices = 0; 3580 int added_devices = 0;
3581 unsigned long flags;
3563 3582
3564 if (mddev->degraded || 3583 if (mddev->degraded ||
3565 test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) 3584 test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
@@ -3593,7 +3612,6 @@ static int raid5_start_reshape(mddev_t *mddev)
3593 if (raid5_add_disk(mddev, rdev)) { 3612 if (raid5_add_disk(mddev, rdev)) {
3594 char nm[20]; 3613 char nm[20];
3595 set_bit(In_sync, &rdev->flags); 3614 set_bit(In_sync, &rdev->flags);
3596 conf->working_disks++;
3597 added_devices++; 3615 added_devices++;
3598 rdev->recovery_offset = 0; 3616 rdev->recovery_offset = 0;
3599 sprintf(nm, "rd%d", rdev->raid_disk); 3617 sprintf(nm, "rd%d", rdev->raid_disk);
@@ -3602,10 +3620,12 @@ static int raid5_start_reshape(mddev_t *mddev)
3602 break; 3620 break;
3603 } 3621 }
3604 3622
3623 spin_lock_irqsave(&conf->device_lock, flags);
3605 mddev->degraded = (conf->raid_disks - conf->previous_raid_disks) - added_devices; 3624 mddev->degraded = (conf->raid_disks - conf->previous_raid_disks) - added_devices;
3625 spin_unlock_irqrestore(&conf->device_lock, flags);
3606 mddev->raid_disks = conf->raid_disks; 3626 mddev->raid_disks = conf->raid_disks;
3607 mddev->reshape_position = 0; 3627 mddev->reshape_position = 0;
3608 mddev->sb_dirty = 1; 3628 set_bit(MD_CHANGE_DEVS, &mddev->flags);
3609 3629
3610 clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); 3630 clear_bit(MD_RECOVERY_SYNC, &mddev->recovery);
3611 clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); 3631 clear_bit(MD_RECOVERY_CHECK, &mddev->recovery);
diff --git a/drivers/media/common/Kconfig b/drivers/media/common/Kconfig
index 1a04db4552da..f33e5d973413 100644
--- a/drivers/media/common/Kconfig
+++ b/drivers/media/common/Kconfig
@@ -4,7 +4,6 @@ config VIDEO_SAA7146
4 4
5config VIDEO_SAA7146_VV 5config VIDEO_SAA7146_VV
6 tristate 6 tristate
7 select VIDEO_V4L2
8 select VIDEO_BUF 7 select VIDEO_BUF
9 select VIDEO_VIDEOBUF 8 select VIDEO_VIDEOBUF
10 select VIDEO_SAA7146 9 select VIDEO_SAA7146
diff --git a/drivers/media/common/ir-keymaps.c b/drivers/media/common/ir-keymaps.c
index ca98d9478947..db753443587a 100644
--- a/drivers/media/common/ir-keymaps.c
+++ b/drivers/media/common/ir-keymaps.c
@@ -32,6 +32,37 @@ IR_KEYTAB_TYPE ir_codes_empty[IR_KEYTAB_SIZE] = {
32 32
33EXPORT_SYMBOL_GPL(ir_codes_empty); 33EXPORT_SYMBOL_GPL(ir_codes_empty);
34 34
35/* Michal Majchrowicz <mmajchrowicz@gmail.com> */
36IR_KEYTAB_TYPE ir_codes_proteus_2309[IR_KEYTAB_SIZE] = {
37 /* numeric */
38 [ 0x00 ] = KEY_0,
39 [ 0x01 ] = KEY_1,
40 [ 0x02 ] = KEY_2,
41 [ 0x03 ] = KEY_3,
42 [ 0x04 ] = KEY_4,
43 [ 0x05 ] = KEY_5,
44 [ 0x06 ] = KEY_6,
45 [ 0x07 ] = KEY_7,
46 [ 0x08 ] = KEY_8,
47 [ 0x09 ] = KEY_9,
48
49 [ 0x5c ] = KEY_POWER, /* power */
50 [ 0x20 ] = KEY_F, /* full screen */
51 [ 0x0f ] = KEY_BACKSPACE, /* recall */
52 [ 0x1b ] = KEY_ENTER, /* mute */
53 [ 0x41 ] = KEY_RECORD, /* record */
54 [ 0x43 ] = KEY_STOP, /* stop */
55 [ 0x16 ] = KEY_S,
56 [ 0x1a ] = KEY_Q, /* off */
57 [ 0x2e ] = KEY_RED,
58 [ 0x1f ] = KEY_DOWN, /* channel - */
59 [ 0x1c ] = KEY_UP, /* channel + */
60 [ 0x10 ] = KEY_LEFT, /* volume - */
61 [ 0x1e ] = KEY_RIGHT, /* volume + */
62 [ 0x14 ] = KEY_F1,
63};
64
65EXPORT_SYMBOL_GPL(ir_codes_proteus_2309);
35/* Matt Jesson <dvb@jesson.eclipse.co.uk */ 66/* Matt Jesson <dvb@jesson.eclipse.co.uk */
36IR_KEYTAB_TYPE ir_codes_avermedia_dvbt[IR_KEYTAB_SIZE] = { 67IR_KEYTAB_TYPE ir_codes_avermedia_dvbt[IR_KEYTAB_SIZE] = {
37 [ 0x28 ] = KEY_0, //'0' / 'enter' 68 [ 0x28 ] = KEY_0, //'0' / 'enter'
@@ -1473,3 +1504,51 @@ IR_KEYTAB_TYPE ir_codes_npgtech[IR_KEYTAB_SIZE] = {
1473}; 1504};
1474 1505
1475EXPORT_SYMBOL_GPL(ir_codes_npgtech); 1506EXPORT_SYMBOL_GPL(ir_codes_npgtech);
1507
1508/* Norwood Micro (non-Pro) TV Tuner
1509 By Peter Naulls <peter@chocky.org>
1510 Key comments are the functions given in the manual */
1511IR_KEYTAB_TYPE ir_codes_norwood[IR_KEYTAB_SIZE] = {
1512 /* Keys 0 to 9 */
1513 [ 0x20 ] = KEY_0,
1514 [ 0x21 ] = KEY_1,
1515 [ 0x22 ] = KEY_2,
1516 [ 0x23 ] = KEY_3,
1517 [ 0x24 ] = KEY_4,
1518 [ 0x25 ] = KEY_5,
1519 [ 0x26 ] = KEY_6,
1520 [ 0x27 ] = KEY_7,
1521 [ 0x28 ] = KEY_8,
1522 [ 0x29 ] = KEY_9,
1523
1524 [ 0x78 ] = KEY_TUNER, /* Video Source */
1525 [ 0x2c ] = KEY_EXIT, /* Open/Close software */
1526 [ 0x2a ] = KEY_SELECT, /* 2 Digit Select */
1527 [ 0x69 ] = KEY_AGAIN, /* Recall */
1528
1529 [ 0x32 ] = KEY_BRIGHTNESSUP, /* Brightness increase */
1530 [ 0x33 ] = KEY_BRIGHTNESSDOWN, /* Brightness decrease */
1531 [ 0x6b ] = KEY_KPPLUS, /* (not named >>>>>) */
1532 [ 0x6c ] = KEY_KPMINUS, /* (not named <<<<<) */
1533
1534 [ 0x2d ] = KEY_MUTE, /* Mute */
1535 [ 0x30 ] = KEY_VOLUMEUP, /* Volume up */
1536 [ 0x31 ] = KEY_VOLUMEDOWN, /* Volume down */
1537 [ 0x60 ] = KEY_CHANNELUP, /* Channel up */
1538 [ 0x61 ] = KEY_CHANNELDOWN, /* Channel down */
1539
1540 [ 0x3f ] = KEY_RECORD, /* Record */
1541 [ 0x37 ] = KEY_PLAY, /* Play */
1542 [ 0x36 ] = KEY_PAUSE, /* Pause */
1543 [ 0x2b ] = KEY_STOP, /* Stop */
1544 [ 0x67 ] = KEY_FASTFORWARD, /* Foward */
1545 [ 0x66 ] = KEY_REWIND, /* Rewind */
1546 [ 0x3e ] = KEY_SEARCH, /* Auto Scan */
1547 [ 0x2e ] = KEY_CAMERA, /* Capture Video */
1548 [ 0x6d ] = KEY_MENU, /* Show/Hide Control */
1549 [ 0x2f ] = KEY_ZOOM, /* Full Screen */
1550 [ 0x34 ] = KEY_RADIO, /* FM */
1551 [ 0x65 ] = KEY_POWER, /* Computer power */
1552};
1553
1554EXPORT_SYMBOL_GPL(ir_codes_norwood);
diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c
index 0027acc5b8e9..d867a6a9e430 100644
--- a/drivers/media/common/saa7146_fops.c
+++ b/drivers/media/common/saa7146_fops.c
@@ -455,7 +455,6 @@ static void vv_callback(struct saa7146_dev *dev, unsigned long status)
455 455
456static struct video_device device_template = 456static struct video_device device_template =
457{ 457{
458 .hardware = VID_HARDWARE_SAA7146,
459 .fops = &video_fops, 458 .fops = &video_fops,
460 .minor = -1, 459 .minor = -1,
461}; 460};
diff --git a/drivers/media/dvb/b2c2/Kconfig b/drivers/media/dvb/b2c2/Kconfig
index 49a06fc54c51..a0dcd59da76e 100644
--- a/drivers/media/dvb/b2c2/Kconfig
+++ b/drivers/media/dvb/b2c2/Kconfig
@@ -2,13 +2,13 @@ config DVB_B2C2_FLEXCOP
2 tristate "Technisat/B2C2 FlexCopII(b) and FlexCopIII adapters" 2 tristate "Technisat/B2C2 FlexCopII(b) and FlexCopIII adapters"
3 depends on DVB_CORE && I2C 3 depends on DVB_CORE && I2C
4 select DVB_PLL 4 select DVB_PLL
5 select DVB_STV0299 5 select DVB_STV0299 if !DVB_FE_CUSTOMISE
6 select DVB_MT352 6 select DVB_MT352 if !DVB_FE_CUSTOMISE
7 select DVB_MT312 7 select DVB_MT312 if !DVB_FE_CUSTOMISE
8 select DVB_NXT200X 8 select DVB_NXT200X if !DVB_FE_CUSTOMISE
9 select DVB_STV0297 9 select DVB_STV0297 if !DVB_FE_CUSTOMISE
10 select DVB_BCM3510 10 select DVB_BCM3510 if !DVB_FE_CUSTOMISE
11 select DVB_LGDT330X 11 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
12 help 12 help
13 Support for the digital TV receiver chip made by B2C2 Inc. included in 13 Support for the digital TV receiver chip made by B2C2 Inc. included in
14 Technisats PCI cards and USB boxes. 14 Technisats PCI cards and USB boxes.
diff --git a/drivers/media/dvb/b2c2/flexcop-fe-tuner.c b/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
index 3be87c72e37b..b8ba87863457 100644
--- a/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
+++ b/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
@@ -505,7 +505,7 @@ int flexcop_frontend_init(struct flexcop_device *fc)
505 struct dvb_frontend_ops *ops; 505 struct dvb_frontend_ops *ops;
506 506
507 /* try the sky v2.6 (stv0299/Samsung tbmu24112(sl1935)) */ 507 /* try the sky v2.6 (stv0299/Samsung tbmu24112(sl1935)) */
508 if ((fc->fe = stv0299_attach(&samsung_tbmu24112_config, &fc->i2c_adap)) != NULL) { 508 if ((fc->fe = dvb_attach(stv0299_attach, &samsung_tbmu24112_config, &fc->i2c_adap)) != NULL) {
509 ops = &fc->fe->ops; 509 ops = &fc->fe->ops;
510 510
511 ops->tuner_ops.set_params = samsung_tbmu24112_tuner_set_params; 511 ops->tuner_ops.set_params = samsung_tbmu24112_tuner_set_params;
@@ -519,36 +519,36 @@ int flexcop_frontend_init(struct flexcop_device *fc)
519 info("found the stv0299 at i2c address: 0x%02x",samsung_tbmu24112_config.demod_address); 519 info("found the stv0299 at i2c address: 0x%02x",samsung_tbmu24112_config.demod_address);
520 } else 520 } else
521 /* try the air dvb-t (mt352/Samsung tdtc9251dh0(??)) */ 521 /* try the air dvb-t (mt352/Samsung tdtc9251dh0(??)) */
522 if ((fc->fe = mt352_attach(&samsung_tdtc9251dh0_config, &fc->i2c_adap)) != NULL ) { 522 if ((fc->fe = dvb_attach(mt352_attach, &samsung_tdtc9251dh0_config, &fc->i2c_adap)) != NULL ) {
523 fc->dev_type = FC_AIR_DVB; 523 fc->dev_type = FC_AIR_DVB;
524 fc->fe->ops.tuner_ops.calc_regs = samsung_tdtc9251dh0_calc_regs; 524 fc->fe->ops.tuner_ops.calc_regs = samsung_tdtc9251dh0_calc_regs;
525 info("found the mt352 at i2c address: 0x%02x",samsung_tdtc9251dh0_config.demod_address); 525 info("found the mt352 at i2c address: 0x%02x",samsung_tdtc9251dh0_config.demod_address);
526 } else 526 } else
527 /* try the air atsc 2nd generation (nxt2002) */ 527 /* try the air atsc 2nd generation (nxt2002) */
528 if ((fc->fe = nxt200x_attach(&samsung_tbmv_config, &fc->i2c_adap)) != NULL) { 528 if ((fc->fe = dvb_attach(nxt200x_attach, &samsung_tbmv_config, &fc->i2c_adap)) != NULL) {
529 fc->dev_type = FC_AIR_ATSC2; 529 fc->dev_type = FC_AIR_ATSC2;
530 dvb_pll_attach(fc->fe, 0x61, &fc->i2c_adap, &dvb_pll_samsung_tbmv); 530 dvb_attach(dvb_pll_attach, fc->fe, 0x61, NULL, &dvb_pll_samsung_tbmv);
531 info("found the nxt2002 at i2c address: 0x%02x",samsung_tbmv_config.demod_address); 531 info("found the nxt2002 at i2c address: 0x%02x",samsung_tbmv_config.demod_address);
532 } else 532 } else
533 /* try the air atsc 3nd generation (lgdt3303) */ 533 /* try the air atsc 3nd generation (lgdt3303) */
534 if ((fc->fe = lgdt330x_attach(&air2pc_atsc_hd5000_config, &fc->i2c_adap)) != NULL) { 534 if ((fc->fe = dvb_attach(lgdt330x_attach, &air2pc_atsc_hd5000_config, &fc->i2c_adap)) != NULL) {
535 fc->dev_type = FC_AIR_ATSC3; 535 fc->dev_type = FC_AIR_ATSC3;
536 fc->fe->ops.tuner_ops.set_params = lgdt3303_tuner_set_params; 536 fc->fe->ops.tuner_ops.set_params = lgdt3303_tuner_set_params;
537 info("found the lgdt3303 at i2c address: 0x%02x",air2pc_atsc_hd5000_config.demod_address); 537 info("found the lgdt3303 at i2c address: 0x%02x",air2pc_atsc_hd5000_config.demod_address);
538 } else 538 } else
539 /* try the air atsc 1nd generation (bcm3510)/panasonic ct10s */ 539 /* try the air atsc 1nd generation (bcm3510)/panasonic ct10s */
540 if ((fc->fe = bcm3510_attach(&air2pc_atsc_first_gen_config, &fc->i2c_adap)) != NULL) { 540 if ((fc->fe = dvb_attach(bcm3510_attach, &air2pc_atsc_first_gen_config, &fc->i2c_adap)) != NULL) {
541 fc->dev_type = FC_AIR_ATSC1; 541 fc->dev_type = FC_AIR_ATSC1;
542 info("found the bcm3510 at i2c address: 0x%02x",air2pc_atsc_first_gen_config.demod_address); 542 info("found the bcm3510 at i2c address: 0x%02x",air2pc_atsc_first_gen_config.demod_address);
543 } else 543 } else
544 /* try the cable dvb (stv0297) */ 544 /* try the cable dvb (stv0297) */
545 if ((fc->fe = stv0297_attach(&alps_tdee4_stv0297_config, &fc->i2c_adap)) != NULL) { 545 if ((fc->fe = dvb_attach(stv0297_attach, &alps_tdee4_stv0297_config, &fc->i2c_adap)) != NULL) {
546 fc->dev_type = FC_CABLE; 546 fc->dev_type = FC_CABLE;
547 fc->fe->ops.tuner_ops.set_params = alps_tdee4_stv0297_tuner_set_params; 547 fc->fe->ops.tuner_ops.set_params = alps_tdee4_stv0297_tuner_set_params;
548 info("found the stv0297 at i2c address: 0x%02x",alps_tdee4_stv0297_config.demod_address); 548 info("found the stv0297 at i2c address: 0x%02x",alps_tdee4_stv0297_config.demod_address);
549 } else 549 } else
550 /* try the sky v2.3 (vp310/Samsung tbdu18132(tsa5059)) */ 550 /* try the sky v2.3 (vp310/Samsung tbdu18132(tsa5059)) */
551 if ((fc->fe = vp310_mt312_attach(&skystar23_samsung_tbdu18132_config, &fc->i2c_adap)) != NULL) { 551 if ((fc->fe = dvb_attach(vp310_mt312_attach, &skystar23_samsung_tbdu18132_config, &fc->i2c_adap)) != NULL) {
552 ops = &fc->fe->ops; 552 ops = &fc->fe->ops;
553 553
554 ops->tuner_ops.set_params = skystar23_samsung_tbdu18132_tuner_set_params; 554 ops->tuner_ops.set_params = skystar23_samsung_tbdu18132_tuner_set_params;
@@ -571,9 +571,7 @@ int flexcop_frontend_init(struct flexcop_device *fc)
571 } else { 571 } else {
572 if (dvb_register_frontend(&fc->dvb_adapter, fc->fe)) { 572 if (dvb_register_frontend(&fc->dvb_adapter, fc->fe)) {
573 err("frontend registration failed!"); 573 err("frontend registration failed!");
574 ops = &fc->fe->ops; 574 dvb_frontend_detach(fc->fe);
575 if (ops->release != NULL)
576 ops->release(fc->fe);
577 fc->fe = NULL; 575 fc->fe = NULL;
578 return -EINVAL; 576 return -EINVAL;
579 } 577 }
@@ -584,8 +582,10 @@ int flexcop_frontend_init(struct flexcop_device *fc)
584 582
585void flexcop_frontend_exit(struct flexcop_device *fc) 583void flexcop_frontend_exit(struct flexcop_device *fc)
586{ 584{
587 if (fc->init_state & FC_STATE_FE_INIT) 585 if (fc->init_state & FC_STATE_FE_INIT) {
588 dvb_unregister_frontend(fc->fe); 586 dvb_unregister_frontend(fc->fe);
587 dvb_frontend_detach(fc->fe);
588 }
589 589
590 fc->init_state &= ~FC_STATE_FE_INIT; 590 fc->init_state &= ~FC_STATE_FE_INIT;
591} 591}
diff --git a/drivers/media/dvb/bt8xx/Kconfig b/drivers/media/dvb/bt8xx/Kconfig
index 7d0ee1ab2903..ae2ff5dc238d 100644
--- a/drivers/media/dvb/bt8xx/Kconfig
+++ b/drivers/media/dvb/bt8xx/Kconfig
@@ -2,13 +2,13 @@ config DVB_BT8XX
2 tristate "BT8xx based PCI cards" 2 tristate "BT8xx based PCI cards"
3 depends on DVB_CORE && PCI && I2C && VIDEO_BT848 3 depends on DVB_CORE && PCI && I2C && VIDEO_BT848
4 select DVB_PLL 4 select DVB_PLL
5 select DVB_MT352 5 select DVB_MT352 if !DVB_FE_CUSTOMISE
6 select DVB_SP887X 6 select DVB_SP887X if !DVB_FE_CUSTOMISE
7 select DVB_NXT6000 7 select DVB_NXT6000 if !DVB_FE_CUSTOMISE
8 select DVB_CX24110 8 select DVB_CX24110 if !DVB_FE_CUSTOMISE
9 select DVB_OR51211 9 select DVB_OR51211 if !DVB_FE_CUSTOMISE
10 select DVB_LGDT330X 10 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
11 select DVB_ZL10353 11 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
12 select FW_LOADER 12 select FW_LOADER
13 help 13 help
14 Support for PCI cards based on the Bt8xx PCI bridge. Examples are 14 Support for PCI cards based on the Bt8xx PCI bridge. Examples are
diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index 06ac899a9a26..9f72b7000c08 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -1715,6 +1715,15 @@ static int dst_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_paramet
1715static void dst_release(struct dvb_frontend *fe) 1715static void dst_release(struct dvb_frontend *fe)
1716{ 1716{
1717 struct dst_state *state = fe->demodulator_priv; 1717 struct dst_state *state = fe->demodulator_priv;
1718 if (state->dst_ca) {
1719 dvb_unregister_device(state->dst_ca);
1720#ifdef CONFIG_DVB_CORE_ATTACH
1721 symbol_put(dst_ca_attach);
1722#endif
1723 }
1724#ifdef CONFIG_DVB_CORE_ATTACH
1725 symbol_put(dst_attach);
1726#endif
1718 kfree(state); 1727 kfree(state);
1719} 1728}
1720 1729
diff --git a/drivers/media/dvb/bt8xx/dst_ca.c b/drivers/media/dvb/bt8xx/dst_ca.c
index fa923b9b346e..240ad084fa78 100644
--- a/drivers/media/dvb/bt8xx/dst_ca.c
+++ b/drivers/media/dvb/bt8xx/dst_ca.c
@@ -699,12 +699,17 @@ static struct dvb_device dvbdev_ca = {
699 .fops = &dst_ca_fops 699 .fops = &dst_ca_fops
700}; 700};
701 701
702int dst_ca_attach(struct dst_state *dst, struct dvb_adapter *dvb_adapter) 702struct dvb_device *dst_ca_attach(struct dst_state *dst, struct dvb_adapter *dvb_adapter)
703{ 703{
704 struct dvb_device *dvbdev; 704 struct dvb_device *dvbdev;
705
705 dprintk(verbose, DST_CA_ERROR, 1, "registering DST-CA device"); 706 dprintk(verbose, DST_CA_ERROR, 1, "registering DST-CA device");
706 dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst, DVB_DEVICE_CA); 707 if (dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst, DVB_DEVICE_CA) == 0) {
707 return 0; 708 dst->dst_ca = dvbdev;
709 return dst->dst_ca;
710 }
711
712 return NULL;
708} 713}
709 714
710EXPORT_SYMBOL(dst_ca_attach); 715EXPORT_SYMBOL(dst_ca_attach);
diff --git a/drivers/media/dvb/bt8xx/dst_common.h b/drivers/media/dvb/bt8xx/dst_common.h
index 0677b047b3a7..3bf084f2e522 100644
--- a/drivers/media/dvb/bt8xx/dst_common.h
+++ b/drivers/media/dvb/bt8xx/dst_common.h
@@ -140,6 +140,7 @@ struct dst_state {
140 char *tuner_name; 140 char *tuner_name;
141 struct mutex dst_mutex; 141 struct mutex dst_mutex;
142 u8 fw_name[8]; 142 u8 fw_name[8];
143 struct dvb_device *dst_ca;
143}; 144};
144 145
145struct tuner_types { 146struct tuner_types {
@@ -178,7 +179,7 @@ int write_dst(struct dst_state *state, u8 * data, u8 len);
178int read_dst(struct dst_state *state, u8 * ret, u8 len); 179int read_dst(struct dst_state *state, u8 * ret, u8 len);
179u8 dst_check_sum(u8 * buf, u32 len); 180u8 dst_check_sum(u8 * buf, u32 len);
180struct dst_state* dst_attach(struct dst_state* state, struct dvb_adapter *dvb_adapter); 181struct dst_state* dst_attach(struct dst_state* state, struct dvb_adapter *dvb_adapter);
181int dst_ca_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter); 182struct dvb_device *dst_ca_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter);
182int dst_gpio_outb(struct dst_state* state, u32 mask, u32 enbb, u32 outhigh, int delay); 183int dst_gpio_outb(struct dst_state* state, u32 mask, u32 enbb, u32 outhigh, int delay);
183 184
184int dst_command(struct dst_state* state, u8 * data, u8 len); 185int dst_command(struct dst_state* state, u8 * data, u8 len);
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
index b715b972d2fc..fb6c4cc8477d 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
@@ -67,7 +67,7 @@ static void dvb_bt8xx_task(unsigned long data)
67 67
68static int dvb_bt8xx_start_feed(struct dvb_demux_feed *dvbdmxfeed) 68static int dvb_bt8xx_start_feed(struct dvb_demux_feed *dvbdmxfeed)
69{ 69{
70 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 70 struct dvb_demux*dvbdmx = dvbdmxfeed->demux;
71 struct dvb_bt8xx_card *card = dvbdmx->priv; 71 struct dvb_bt8xx_card *card = dvbdmx->priv;
72 int rc; 72 int rc;
73 73
@@ -595,15 +595,14 @@ static void lgdt330x_reset(struct dvb_bt8xx_card *bt)
595 595
596static void frontend_init(struct dvb_bt8xx_card *card, u32 type) 596static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
597{ 597{
598 int ret;
599 struct dst_state* state = NULL; 598 struct dst_state* state = NULL;
600 599
601 switch(type) { 600 switch(type) {
602 case BTTV_BOARD_DVICO_DVBT_LITE: 601 case BTTV_BOARD_DVICO_DVBT_LITE:
603 card->fe = mt352_attach(&thomson_dtt7579_config, card->i2c_adapter); 602 card->fe = dvb_attach(mt352_attach, &thomson_dtt7579_config, card->i2c_adapter);
604 603
605 if (card->fe == NULL) 604 if (card->fe == NULL)
606 card->fe = zl10353_attach(&thomson_dtt7579_zl10353_config, 605 card->fe = dvb_attach(zl10353_attach, &thomson_dtt7579_zl10353_config,
607 card->i2c_adapter); 606 card->i2c_adapter);
608 607
609 if (card->fe != NULL) { 608 if (card->fe != NULL) {
@@ -615,7 +614,7 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
615 614
616 case BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE: 615 case BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE:
617 lgdt330x_reset(card); 616 lgdt330x_reset(card);
618 card->fe = lgdt330x_attach(&tdvs_tua6034_config, card->i2c_adapter); 617 card->fe = dvb_attach(lgdt330x_attach, &tdvs_tua6034_config, card->i2c_adapter);
619 if (card->fe != NULL) { 618 if (card->fe != NULL) {
620 card->fe->ops.tuner_ops.set_params = tdvs_tua6034_tuner_set_params; 619 card->fe->ops.tuner_ops.set_params = tdvs_tua6034_tuner_set_params;
621 dprintk ("dvb_bt8xx: lgdt330x detected\n"); 620 dprintk ("dvb_bt8xx: lgdt330x detected\n");
@@ -630,7 +629,7 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
630 629
631 /* Old Nebula (marked (c)2003 on high profile pci card) has nxt6000 demod */ 630 /* Old Nebula (marked (c)2003 on high profile pci card) has nxt6000 demod */
632 digitv_alps_tded4_reset(card); 631 digitv_alps_tded4_reset(card);
633 card->fe = nxt6000_attach(&vp3021_alps_tded4_config, card->i2c_adapter); 632 card->fe = dvb_attach(nxt6000_attach, &vp3021_alps_tded4_config, card->i2c_adapter);
634 if (card->fe != NULL) { 633 if (card->fe != NULL) {
635 card->fe->ops.tuner_ops.set_params = vp3021_alps_tded4_tuner_set_params; 634 card->fe->ops.tuner_ops.set_params = vp3021_alps_tded4_tuner_set_params;
636 dprintk ("dvb_bt8xx: an nxt6000 was detected on your digitv card\n"); 635 dprintk ("dvb_bt8xx: an nxt6000 was detected on your digitv card\n");
@@ -639,7 +638,7 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
639 638
640 /* New Nebula (marked (c)2005 on low profile pci card) has mt352 demod */ 639 /* New Nebula (marked (c)2005 on low profile pci card) has mt352 demod */
641 digitv_alps_tded4_reset(card); 640 digitv_alps_tded4_reset(card);
642 card->fe = mt352_attach(&digitv_alps_tded4_config, card->i2c_adapter); 641 card->fe = dvb_attach(mt352_attach, &digitv_alps_tded4_config, card->i2c_adapter);
643 642
644 if (card->fe != NULL) { 643 if (card->fe != NULL) {
645 card->fe->ops.tuner_ops.calc_regs = digitv_alps_tded4_tuner_calc_regs; 644 card->fe->ops.tuner_ops.calc_regs = digitv_alps_tded4_tuner_calc_regs;
@@ -648,14 +647,14 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
648 break; 647 break;
649 648
650 case BTTV_BOARD_AVDVBT_761: 649 case BTTV_BOARD_AVDVBT_761:
651 card->fe = sp887x_attach(&microtune_mt7202dtf_config, card->i2c_adapter); 650 card->fe = dvb_attach(sp887x_attach, &microtune_mt7202dtf_config, card->i2c_adapter);
652 if (card->fe) { 651 if (card->fe) {
653 card->fe->ops.tuner_ops.set_params = microtune_mt7202dtf_tuner_set_params; 652 card->fe->ops.tuner_ops.set_params = microtune_mt7202dtf_tuner_set_params;
654 } 653 }
655 break; 654 break;
656 655
657 case BTTV_BOARD_AVDVBT_771: 656 case BTTV_BOARD_AVDVBT_771:
658 card->fe = mt352_attach(&advbt771_samsung_tdtc9251dh0_config, card->i2c_adapter); 657 card->fe = dvb_attach(mt352_attach, &advbt771_samsung_tdtc9251dh0_config, card->i2c_adapter);
659 if (card->fe != NULL) { 658 if (card->fe != NULL) {
660 card->fe->ops.tuner_ops.calc_regs = advbt771_samsung_tdtc9251dh0_tuner_calc_regs; 659 card->fe->ops.tuner_ops.calc_regs = advbt771_samsung_tdtc9251dh0_tuner_calc_regs;
661 card->fe->ops.info.frequency_min = 174000000; 660 card->fe->ops.info.frequency_min = 174000000;
@@ -670,22 +669,21 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
670 state->config = &dst_config; 669 state->config = &dst_config;
671 state->i2c = card->i2c_adapter; 670 state->i2c = card->i2c_adapter;
672 state->bt = card->bt; 671 state->bt = card->bt;
673 672 state->dst_ca = NULL;
674 /* DST is not a frontend, attaching the ASIC */ 673 /* DST is not a frontend, attaching the ASIC */
675 if ((dst_attach(state, &card->dvb_adapter)) == NULL) { 674 if (dvb_attach(dst_attach, state, &card->dvb_adapter) == NULL) {
676 printk("%s: Could not find a Twinhan DST.\n", __FUNCTION__); 675 printk("%s: Could not find a Twinhan DST.\n", __FUNCTION__);
677 break; 676 break;
678 } 677 }
679 card->fe = &state->frontend;
680
681 /* Attach other DST peripherals if any */ 678 /* Attach other DST peripherals if any */
682 /* Conditional Access device */ 679 /* Conditional Access device */
680 card->fe = &state->frontend;
683 if (state->dst_hw_cap & DST_TYPE_HAS_CA) 681 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
684 ret = dst_ca_attach(state, &card->dvb_adapter); 682 dvb_attach(dst_ca_attach, state, &card->dvb_adapter);
685 break; 683 break;
686 684
687 case BTTV_BOARD_PINNACLESAT: 685 case BTTV_BOARD_PINNACLESAT:
688 card->fe = cx24110_attach(&pctvsat_config, card->i2c_adapter); 686 card->fe = dvb_attach(cx24110_attach, &pctvsat_config, card->i2c_adapter);
689 if (card->fe) { 687 if (card->fe) {
690 card->fe->ops.tuner_ops.init = pinnsat_tuner_init; 688 card->fe->ops.tuner_ops.init = pinnsat_tuner_init;
691 card->fe->ops.tuner_ops.sleep = pinnsat_tuner_sleep; 689 card->fe->ops.tuner_ops.sleep = pinnsat_tuner_sleep;
@@ -694,7 +692,7 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
694 break; 692 break;
695 693
696 case BTTV_BOARD_PC_HDTV: 694 case BTTV_BOARD_PC_HDTV:
697 card->fe = or51211_attach(&or51211_config, card->i2c_adapter); 695 card->fe = dvb_attach(or51211_attach, &or51211_config, card->i2c_adapter);
698 break; 696 break;
699 } 697 }
700 698
@@ -707,8 +705,7 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
707 else 705 else
708 if (dvb_register_frontend(&card->dvb_adapter, card->fe)) { 706 if (dvb_register_frontend(&card->dvb_adapter, card->fe)) {
709 printk("dvb-bt8xx: Frontend registration failed!\n"); 707 printk("dvb-bt8xx: Frontend registration failed!\n");
710 if (card->fe->ops.release) 708 dvb_frontend_detach(card->fe);
711 card->fe->ops.release(card->fe);
712 card->fe = NULL; 709 card->fe = NULL;
713 } 710 }
714} 711}
@@ -925,8 +922,10 @@ static void dvb_bt8xx_remove(struct bttv_sub_device *sub)
925 card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw); 922 card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw);
926 dvb_dmxdev_release(&card->dmxdev); 923 dvb_dmxdev_release(&card->dmxdev);
927 dvb_dmx_release(&card->demux); 924 dvb_dmx_release(&card->demux);
928 if (card->fe) 925 if (card->fe) {
929 dvb_unregister_frontend(card->fe); 926 dvb_unregister_frontend(card->fe);
927 dvb_frontend_detach(card->fe);
928 }
930 dvb_unregister_adapter(&card->dvb_adapter); 929 dvb_unregister_adapter(&card->dvb_adapter);
931 930
932 kfree(card); 931 kfree(card);
diff --git a/drivers/media/dvb/cinergyT2/cinergyT2.c b/drivers/media/dvb/cinergyT2/cinergyT2.c
index 001c71b6be61..410fa6d620ff 100644
--- a/drivers/media/dvb/cinergyT2/cinergyT2.c
+++ b/drivers/media/dvb/cinergyT2/cinergyT2.c
@@ -981,7 +981,7 @@ static int cinergyt2_suspend (struct usb_interface *intf, pm_message_t state)
981 if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem)) 981 if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem))
982 return -ERESTARTSYS; 982 return -ERESTARTSYS;
983 983
984 if (state.event > PM_EVENT_ON) { 984 if (1) {
985 struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf); 985 struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf);
986 986
987 cinergyt2_suspend_rc(cinergyt2); 987 cinergyt2_suspend_rc(cinergyt2);
diff --git a/drivers/media/dvb/dvb-core/Kconfig b/drivers/media/dvb/dvb-core/Kconfig
index 12ee912a5705..e46eae3b9be2 100644
--- a/drivers/media/dvb/dvb-core/Kconfig
+++ b/drivers/media/dvb/dvb-core/Kconfig
@@ -9,3 +9,16 @@ config DVB_CORE
9 in-kernel drivers will select this automatically if needed. 9 in-kernel drivers will select this automatically if needed.
10 If unsure say N. 10 If unsure say N.
11 11
12config DVB_CORE_ATTACH
13 bool "Load and attach frontend modules as needed"
14 depends on DVB_CORE
15 depends on MODULES
16 help
17 Remove the static dependency of DVB card drivers on all
18 frontend modules for all possible card variants. Instead,
19 allow the card drivers to only load the frontend modules
20 they require. This saves several KBytes of memory.
21
22 Note: You will need moudule-init-tools v3.2 or later for this feature.
23
24 If unsure say Y.
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index 57b34cda99f5..3dd5dbafb330 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -1105,18 +1105,42 @@ int dvb_unregister_frontend(struct dvb_frontend* fe)
1105 mutex_lock(&frontend_mutex); 1105 mutex_lock(&frontend_mutex);
1106 dvb_unregister_device (fepriv->dvbdev); 1106 dvb_unregister_device (fepriv->dvbdev);
1107 dvb_frontend_stop (fe); 1107 dvb_frontend_stop (fe);
1108 if (fe->ops.tuner_ops.release) { 1108
1109 fe->ops.tuner_ops.release(fe);
1110 if (fe->ops.i2c_gate_ctrl)
1111 fe->ops.i2c_gate_ctrl(fe, 0);
1112 }
1113 if (fe->ops.release)
1114 fe->ops.release(fe);
1115 else
1116 printk("dvb_frontend: Demodulator (%s) does not have a release callback!\n", fe->ops.info.name);
1117 /* fe is invalid now */ 1109 /* fe is invalid now */
1118 kfree(fepriv); 1110 kfree(fepriv);
1119 mutex_unlock(&frontend_mutex); 1111 mutex_unlock(&frontend_mutex);
1120 return 0; 1112 return 0;
1121} 1113}
1122EXPORT_SYMBOL(dvb_unregister_frontend); 1114EXPORT_SYMBOL(dvb_unregister_frontend);
1115
1116#ifdef CONFIG_DVB_CORE_ATTACH
1117void dvb_frontend_detach(struct dvb_frontend* fe)
1118{
1119 void *ptr;
1120
1121 if (fe->ops.release_sec) {
1122 fe->ops.release_sec(fe);
1123 symbol_put_addr(fe->ops.release_sec);
1124 }
1125 if (fe->ops.tuner_ops.release) {
1126 fe->ops.tuner_ops.release(fe);
1127 symbol_put_addr(fe->ops.tuner_ops.release);
1128 }
1129 ptr = (void*)fe->ops.release;
1130 if (ptr) {
1131 fe->ops.release(fe);
1132 symbol_put_addr(ptr);
1133 }
1134}
1135#else
1136void dvb_frontend_detach(struct dvb_frontend* fe)
1137{
1138 if (fe->ops.release_sec)
1139 fe->ops.release_sec(fe);
1140 if (fe->ops.tuner_ops.release)
1141 fe->ops.tuner_ops.release(fe);
1142 if (fe->ops.release)
1143 fe->ops.release(fe);
1144}
1145#endif
1146EXPORT_SYMBOL(dvb_frontend_detach);
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.h b/drivers/media/dvb/dvb-core/dvb_frontend.h
index 2887e2b862a4..e5d5028b3694 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.h
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.h
@@ -92,10 +92,13 @@ struct dvb_frontend_ops {
92 struct dvb_frontend_info info; 92 struct dvb_frontend_info info;
93 93
94 void (*release)(struct dvb_frontend* fe); 94 void (*release)(struct dvb_frontend* fe);
95 void (*release_sec)(struct dvb_frontend* fe);
95 96
96 int (*init)(struct dvb_frontend* fe); 97 int (*init)(struct dvb_frontend* fe);
97 int (*sleep)(struct dvb_frontend* fe); 98 int (*sleep)(struct dvb_frontend* fe);
98 99
100 int (*write)(struct dvb_frontend* fe, u8* buf, int len);
101
99 /* if this is set, it overrides the default swzigzag */ 102 /* if this is set, it overrides the default swzigzag */
100 int (*tune)(struct dvb_frontend* fe, 103 int (*tune)(struct dvb_frontend* fe,
101 struct dvb_frontend_parameters* params, 104 struct dvb_frontend_parameters* params,
@@ -147,7 +150,7 @@ struct dvb_frontend {
147 void* demodulator_priv; 150 void* demodulator_priv;
148 void* tuner_priv; 151 void* tuner_priv;
149 void* frontend_priv; 152 void* frontend_priv;
150 void* misc_priv; 153 void* sec_priv;
151}; 154};
152 155
153extern int dvb_register_frontend(struct dvb_adapter* dvb, 156extern int dvb_register_frontend(struct dvb_adapter* dvb,
@@ -155,6 +158,8 @@ extern int dvb_register_frontend(struct dvb_adapter* dvb,
155 158
156extern int dvb_unregister_frontend(struct dvb_frontend* fe); 159extern int dvb_unregister_frontend(struct dvb_frontend* fe);
157 160
161extern void dvb_frontend_detach(struct dvb_frontend* fe);
162
158extern void dvb_frontend_reinitialise(struct dvb_frontend *fe); 163extern void dvb_frontend_reinitialise(struct dvb_frontend *fe);
159 164
160extern void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec); 165extern void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec);
diff --git a/drivers/media/dvb/dvb-core/dvb_ringbuffer.c b/drivers/media/dvb/dvb-core/dvb_ringbuffer.c
index c972fe014c58..9878183ba3f0 100644
--- a/drivers/media/dvb/dvb-core/dvb_ringbuffer.c
+++ b/drivers/media/dvb/dvb-core/dvb_ringbuffer.c
@@ -26,7 +26,6 @@
26 26
27 27
28 28
29#define __KERNEL_SYSCALLS__
30#include <linux/errno.h> 29#include <linux/errno.h>
31#include <linux/kernel.h> 30#include <linux/kernel.h>
32#include <linux/module.h> 31#include <linux/module.h>
diff --git a/drivers/media/dvb/dvb-core/dvbdev.h b/drivers/media/dvb/dvb-core/dvbdev.h
index 7a7f75fd168c..620e7887b3d3 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.h
+++ b/drivers/media/dvb/dvb-core/dvbdev.h
@@ -102,4 +102,26 @@ extern int dvb_usercopy(struct inode *inode, struct file *file,
102 int (*func)(struct inode *inode, struct file *file, 102 int (*func)(struct inode *inode, struct file *file,
103 unsigned int cmd, void *arg)); 103 unsigned int cmd, void *arg));
104 104
105/** generic DVB attach function. */
106#ifdef CONFIG_DVB_CORE_ATTACH
107#define dvb_attach(FUNCTION, ARGS...) ({ \
108 void *__r = NULL; \
109 typeof(&FUNCTION) __a = symbol_request(FUNCTION); \
110 if (__a) { \
111 __r = (void *) __a(ARGS); \
112 if (__r == NULL) \
113 symbol_put(FUNCTION); \
114 } else { \
115 printk(KERN_ERR "DVB: Unable to find symbol "#FUNCTION"()\n"); \
116 } \
117 __r; \
118})
119
120#else
121#define dvb_attach(FUNCTION, ARGS...) ({ \
122 FUNCTION(ARGS); \
123})
124
125#endif
126
105#endif /* #ifndef _DVBDEV_H_ */ 127#endif /* #ifndef _DVBDEV_H_ */
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index 75824b77198a..0a3c35399bea 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -26,6 +26,7 @@ config DVB_USB_A800
26 tristate "AVerMedia AverTV DVB-T USB 2.0 (A800)" 26 tristate "AVerMedia AverTV DVB-T USB 2.0 (A800)"
27 depends on DVB_USB 27 depends on DVB_USB
28 select DVB_DIB3000MC 28 select DVB_DIB3000MC
29 select DVB_TUNER_MT2060
29 help 30 help
30 Say Y here to support the AVerMedia AverTV DVB-T USB 2.0 (A800) receiver. 31 Say Y here to support the AVerMedia AverTV DVB-T USB 2.0 (A800) receiver.
31 32
@@ -33,6 +34,7 @@ config DVB_USB_DIBUSB_MB
33 tristate "DiBcom USB DVB-T devices (based on the DiB3000M-B) (see help for device list)" 34 tristate "DiBcom USB DVB-T devices (based on the DiB3000M-B) (see help for device list)"
34 depends on DVB_USB 35 depends on DVB_USB
35 select DVB_DIB3000MB 36 select DVB_DIB3000MB
37 select DVB_TUNER_MT2060
36 help 38 help
37 Support for USB 1.1 and 2.0 DVB-T receivers based on reference designs made by 39 Support for USB 1.1 and 2.0 DVB-T receivers based on reference designs made by
38 DiBcom (<http://www.dibcom.fr>) equipped with a DiB3000M-B demodulator. 40 DiBcom (<http://www.dibcom.fr>) equipped with a DiB3000M-B demodulator.
@@ -65,6 +67,7 @@ config DVB_USB_DIBUSB_MC
65 tristate "DiBcom USB DVB-T devices (based on the DiB3000M-C/P) (see help for device list)" 67 tristate "DiBcom USB DVB-T devices (based on the DiB3000M-C/P) (see help for device list)"
66 depends on DVB_USB 68 depends on DVB_USB
67 select DVB_DIB3000MC 69 select DVB_DIB3000MC
70 select DVB_TUNER_MT2060
68 help 71 help
69 Support for 2.0 DVB-T receivers based on reference designs made by 72 Support for 2.0 DVB-T receivers based on reference designs made by
70 DiBcom (<http://www.dibcom.fr>) equipped with a DiB3000M-C/P demodulator. 73 DiBcom (<http://www.dibcom.fr>) equipped with a DiB3000M-C/P demodulator.
@@ -80,16 +83,17 @@ config DVB_USB_UMT_010
80 tristate "HanfTek UMT-010 DVB-T USB2.0 support" 83 tristate "HanfTek UMT-010 DVB-T USB2.0 support"
81 depends on DVB_USB 84 depends on DVB_USB
82 select DVB_DIB3000MC 85 select DVB_DIB3000MC
86 select DVB_TUNER_MT2060
83 help 87 help
84 Say Y here to support the HanfTek UMT-010 USB2.0 stick-sized DVB-T receiver. 88 Say Y here to support the HanfTek UMT-010 USB2.0 stick-sized DVB-T receiver.
85 89
86config DVB_USB_CXUSB 90config DVB_USB_CXUSB
87 tristate "Conexant USB2.0 hybrid reference design support" 91 tristate "Conexant USB2.0 hybrid reference design support"
88 depends on DVB_USB 92 depends on DVB_USB
89 select DVB_CX22702 93 select DVB_CX22702 if !DVB_FE_CUSTOMISE
90 select DVB_LGDT330X 94 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
91 select DVB_MT352 95 select DVB_MT352 if !DVB_FE_CUSTOMISE
92 select DVB_ZL10353 96 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
93 help 97 help
94 Say Y here to support the Conexant USB2.0 hybrid reference design. 98 Say Y here to support the Conexant USB2.0 hybrid reference design.
95 Currently, only DVB and ATSC modes are supported, analog mode 99 Currently, only DVB and ATSC modes are supported, analog mode
@@ -101,8 +105,8 @@ config DVB_USB_CXUSB
101config DVB_USB_DIGITV 105config DVB_USB_DIGITV
102 tristate "Nebula Electronics uDigiTV DVB-T USB2.0 support" 106 tristate "Nebula Electronics uDigiTV DVB-T USB2.0 support"
103 depends on DVB_USB 107 depends on DVB_USB
104 select DVB_NXT6000 108 select DVB_NXT6000 if !DVB_FE_CUSTOMISE
105 select DVB_MT352 109 select DVB_MT352 if !DVB_FE_CUSTOMISE
106 help 110 help
107 Say Y here to support the Nebula Electronics uDigitV USB2.0 DVB-T receiver. 111 Say Y here to support the Nebula Electronics uDigitV USB2.0 DVB-T receiver.
108 112
@@ -145,6 +149,7 @@ config DVB_USB_NOVA_T_USB2
145 tristate "Hauppauge WinTV-NOVA-T usb2 DVB-T USB2.0 support" 149 tristate "Hauppauge WinTV-NOVA-T usb2 DVB-T USB2.0 support"
146 depends on DVB_USB 150 depends on DVB_USB
147 select DVB_DIB3000MC 151 select DVB_DIB3000MC
152 select DVB_TUNER_MT2060
148 help 153 help
149 Say Y here to support the Hauppauge WinTV-NOVA-T usb2 DVB-T USB2.0 receiver. 154 Say Y here to support the Hauppauge WinTV-NOVA-T usb2 DVB-T USB2.0 receiver.
150 155
diff --git a/drivers/media/dvb/dvb-usb/a800.c b/drivers/media/dvb/dvb-usb/a800.c
index ce44aa6bbb83..df0c384bd4ca 100644
--- a/drivers/media/dvb/dvb-usb/a800.c
+++ b/drivers/media/dvb/dvb-usb/a800.c
@@ -26,6 +26,13 @@ static int a800_power_ctrl(struct dvb_usb_device *d, int onoff)
26 return 0; 26 return 0;
27} 27}
28 28
29/* assure to put cold to 0 for iManufacturer == 1 */
30static int a800_identify_state(struct usb_device *udev, struct dvb_usb_properties *props,struct dvb_usb_device_description **desc, int *cold)
31{
32 *cold = udev->descriptor.iManufacturer != 1;
33 return 0;
34}
35
29static struct dvb_usb_rc_key a800_rc_keys[] = { 36static struct dvb_usb_rc_key a800_rc_keys[] = {
30 { 0x02, 0x01, KEY_PROG1 }, /* SOURCE */ 37 { 0x02, 0x01, KEY_PROG1 }, /* SOURCE */
31 { 0x02, 0x00, KEY_POWER }, /* POWER */ 38 { 0x02, 0x00, KEY_POWER }, /* POWER */
@@ -113,6 +120,7 @@ static struct dvb_usb_properties a800_properties = {
113 .power_ctrl = a800_power_ctrl, 120 .power_ctrl = a800_power_ctrl,
114 .frontend_attach = dibusb_dib3000mc_frontend_attach, 121 .frontend_attach = dibusb_dib3000mc_frontend_attach,
115 .tuner_attach = dibusb_dib3000mc_tuner_attach, 122 .tuner_attach = dibusb_dib3000mc_tuner_attach,
123 .identify_state = a800_identify_state,
116 124
117 .rc_interval = DEFAULT_RC_INTERVAL, 125 .rc_interval = DEFAULT_RC_INTERVAL,
118 .rc_key_map = a800_rc_keys, 126 .rc_key_map = a800_rc_keys,
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
index ae23bdde42a8..c710c0176e07 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.c
+++ b/drivers/media/dvb/dvb-usb/cxusb.c
@@ -349,6 +349,7 @@ static struct mt352_config cxusb_dee1601_config = {
349 349
350static struct zl10353_config cxusb_zl10353_dee1601_config = { 350static struct zl10353_config cxusb_zl10353_dee1601_config = {
351 .demod_address = 0x0f, 351 .demod_address = 0x0f,
352 .parallel_ts = 1,
352}; 353};
353 354
354static struct mt352_config cxusb_mt352_config = { 355static struct mt352_config cxusb_mt352_config = {
@@ -409,7 +410,7 @@ static int cxusb_cx22702_frontend_attach(struct dvb_usb_device *d)
409 410
410 cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, &b, 1); 411 cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, &b, 1);
411 412
412 if ((d->fe = cx22702_attach(&cxusb_cx22702_config, &d->i2c_adap)) != NULL) 413 if ((d->fe = dvb_attach(cx22702_attach, &cxusb_cx22702_config, &d->i2c_adap)) != NULL)
413 return 0; 414 return 0;
414 415
415 return -EIO; 416 return -EIO;
@@ -422,7 +423,7 @@ static int cxusb_lgdt3303_frontend_attach(struct dvb_usb_device *d)
422 423
423 cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, NULL, 0); 424 cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, NULL, 0);
424 425
425 if ((d->fe = lgdt330x_attach(&cxusb_lgdt3303_config, &d->i2c_adap)) != NULL) 426 if ((d->fe = dvb_attach(lgdt330x_attach, &cxusb_lgdt3303_config, &d->i2c_adap)) != NULL)
426 return 0; 427 return 0;
427 428
428 return -EIO; 429 return -EIO;
@@ -435,7 +436,7 @@ static int cxusb_mt352_frontend_attach(struct dvb_usb_device *d)
435 436
436 cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, NULL, 0); 437 cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, NULL, 0);
437 438
438 if ((d->fe = mt352_attach(&cxusb_mt352_config, &d->i2c_adap)) != NULL) 439 if ((d->fe = dvb_attach(mt352_attach, &cxusb_mt352_config, &d->i2c_adap)) != NULL)
439 return 0; 440 return 0;
440 441
441 return -EIO; 442 return -EIO;
@@ -448,8 +449,8 @@ static int cxusb_dee1601_frontend_attach(struct dvb_usb_device *d)
448 449
449 cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, NULL, 0); 450 cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, NULL, 0);
450 451
451 if (((d->fe = mt352_attach(&cxusb_dee1601_config, &d->i2c_adap)) != NULL) || 452 if (((d->fe = dvb_attach(mt352_attach, &cxusb_dee1601_config, &d->i2c_adap)) != NULL) ||
452 ((d->fe = zl10353_attach(&cxusb_zl10353_dee1601_config, &d->i2c_adap)) != NULL)) 453 ((d->fe = dvb_attach(zl10353_attach, &cxusb_zl10353_dee1601_config, &d->i2c_adap)) != NULL))
453 return 0; 454 return 0;
454 455
455 return -EIO; 456 return -EIO;
diff --git a/drivers/media/dvb/dvb-usb/dibusb-common.c b/drivers/media/dvb/dvb-usb/dibusb-common.c
index abd75b4a350d..124e25ac53b3 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-common.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-common.c
@@ -131,9 +131,6 @@ static int dibusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num
131 if (mutex_lock_interruptible(&d->i2c_mutex) < 0) 131 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
132 return -EAGAIN; 132 return -EAGAIN;
133 133
134 if (num > 2)
135 warn("more than 2 i2c messages at a time is not handled yet. TODO.");
136
137 for (i = 0; i < num; i++) { 134 for (i = 0; i < num; i++) {
138 /* write/read request */ 135 /* write/read request */
139 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) { 136 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
@@ -168,31 +165,137 @@ int dibusb_read_eeprom_byte(struct dvb_usb_device *d, u8 offs, u8 *val)
168} 165}
169EXPORT_SYMBOL(dibusb_read_eeprom_byte); 166EXPORT_SYMBOL(dibusb_read_eeprom_byte);
170 167
168/* 3000MC/P stuff */
169// Config Adjacent channels Perf -cal22
170static struct dibx000_agc_config dib3000p_mt2060_agc_config = {
171 .band_caps = BAND_VHF | BAND_UHF,
172 .setup = (0 << 15) | (0 << 14) | (1 << 13) | (1 << 12) | (29 << 0),
173
174 .agc1_max = 48497,
175 .agc1_min = 23593,
176 .agc2_max = 46531,
177 .agc2_min = 24904,
178
179 .agc1_pt1 = 0x65,
180 .agc1_pt2 = 0x69,
181
182 .agc1_slope1 = 0x51,
183 .agc1_slope2 = 0x27,
184
185 .agc2_pt1 = 0,
186 .agc2_pt2 = 0x33,
187
188 .agc2_slope1 = 0x35,
189 .agc2_slope2 = 0x37,
190};
191
192static struct dib3000mc_config stk3000p_dib3000p_config = {
193 &dib3000p_mt2060_agc_config,
194
195 .max_time = 0x196,
196 .ln_adc_level = 0x1cc7,
197
198 .output_mpeg2_in_188_bytes = 1,
199};
200
201static struct dibx000_agc_config dib3000p_panasonic_agc_config = {
202 .setup = (0 << 15) | (0 << 14) | (1 << 13) | (1 << 12) | (29 << 0),
203
204 .agc1_max = 56361,
205 .agc1_min = 22282,
206 .agc2_max = 47841,
207 .agc2_min = 36045,
208
209 .agc1_pt1 = 0x3b,
210 .agc1_pt2 = 0x6b,
211
212 .agc1_slope1 = 0x55,
213 .agc1_slope2 = 0x1d,
214
215 .agc2_pt1 = 0,
216 .agc2_pt2 = 0x0a,
217
218 .agc2_slope1 = 0x95,
219 .agc2_slope2 = 0x1e,
220};
221
222static struct dib3000mc_config mod3000p_dib3000p_config = {
223 &dib3000p_panasonic_agc_config,
224
225 .max_time = 0x51,
226 .ln_adc_level = 0x1cc7,
227
228 .output_mpeg2_in_188_bytes = 1,
229};
230
171int dibusb_dib3000mc_frontend_attach(struct dvb_usb_device *d) 231int dibusb_dib3000mc_frontend_attach(struct dvb_usb_device *d)
172{ 232{
173 struct dib3000_config demod_cfg; 233 if (dib3000mc_attach(&d->i2c_adap, 1, DEFAULT_DIB3000P_I2C_ADDRESS, 0, &mod3000p_dib3000p_config, &d->fe) == 0 ||
174 struct dibusb_state *st = d->priv; 234 dib3000mc_attach(&d->i2c_adap, 1, DEFAULT_DIB3000MC_I2C_ADDRESS, 0, &mod3000p_dib3000p_config, &d->fe) == 0) {
175 235 if (d->priv != NULL) {
176 for (demod_cfg.demod_address = 0x8; demod_cfg.demod_address < 0xd; demod_cfg.demod_address++) 236 struct dibusb_state *st = d->priv;
177 if ((d->fe = dib3000mc_attach(&demod_cfg,&d->i2c_adap,&st->ops)) != NULL) { 237 st->ops.pid_parse = dib3000mc_pid_parse;
178 d->fe->ops.tuner_ops.init = dvb_usb_tuner_init_i2c; 238 st->ops.pid_ctrl = dib3000mc_pid_control;
179 d->fe->ops.tuner_ops.set_params = dvb_usb_tuner_set_params_i2c;
180 d->tuner_pass_ctrl = st->ops.tuner_pass_ctrl;
181 return 0;
182 } 239 }
183 240 return 0;
241 }
184 return -ENODEV; 242 return -ENODEV;
185} 243}
186EXPORT_SYMBOL(dibusb_dib3000mc_frontend_attach); 244EXPORT_SYMBOL(dibusb_dib3000mc_frontend_attach);
187 245
246static struct mt2060_config stk3000p_mt2060_config = {
247 0x60
248};
249
188int dibusb_dib3000mc_tuner_attach (struct dvb_usb_device *d) 250int dibusb_dib3000mc_tuner_attach (struct dvb_usb_device *d)
189{ 251{
190 d->pll_addr = 0x60; 252 struct dibusb_state *st = d->priv;
191 d->pll_desc = &dvb_pll_env57h1xd5; 253 int ret;
192 254 u8 a,b;
193 d->fe->ops.tuner_ops.init = dvb_usb_tuner_init_i2c; 255 u16 if1 = 1220;
194 d->fe->ops.tuner_ops.set_params = dvb_usb_tuner_set_params_i2c; 256 struct i2c_adapter *tun_i2c;
257
258 // First IF calibration for Liteon Sticks
259 if (d->udev->descriptor.idVendor == USB_VID_LITEON &&
260 d->udev->descriptor.idProduct == USB_PID_LITEON_DVB_T_WARM) {
261
262 dibusb_read_eeprom_byte(d,0x7E,&a);
263 dibusb_read_eeprom_byte(d,0x7F,&b);
264
265 if (a == 0x00)
266 if1 += b;
267 else if (a == 0x80)
268 if1 -= b;
269 else
270 warn("LITE-ON DVB-T: Strange IF1 calibration :%2X %2X\n", a, b);
271
272 } else if (d->udev->descriptor.idVendor == USB_VID_DIBCOM &&
273 d->udev->descriptor.idProduct == USB_PID_DIBCOM_MOD3001_WARM) {
274 u8 desc;
275 dibusb_read_eeprom_byte(d, 7, &desc);
276 if (desc == 2) {
277 a = 127;
278 do {
279 dibusb_read_eeprom_byte(d, a, &desc);
280 a--;
281 } while (a > 7 && (desc == 0xff || desc == 0x00));
282 if (desc & 0x80)
283 if1 -= (0xff - desc);
284 else
285 if1 += desc;
286 }
287 }
195 288
289 tun_i2c = dib3000mc_get_tuner_i2c_master(d->fe, 1);
290 if ((ret = mt2060_attach(d->fe, tun_i2c, &stk3000p_mt2060_config, if1)) != 0) {
291 /* not found - use panasonic pll parameters */
292 if (dvb_pll_attach(d->fe, 0x60, tun_i2c, &dvb_pll_env57h1xd5) == NULL)
293 return -ENOMEM;
294 } else {
295 st->mt2060_present = 1;
296 /* set the correct parameters for the dib3000p */
297 dib3000mc_set_config(d->fe, &stk3000p_dib3000p_config);
298 }
196 return 0; 299 return 0;
197} 300}
198EXPORT_SYMBOL(dibusb_dib3000mc_tuner_attach); 301EXPORT_SYMBOL(dibusb_dib3000mc_tuner_attach);
@@ -267,6 +370,67 @@ struct dvb_usb_rc_key dibusb_rc_keys[] = {
267 { 0x86, 0x1e, KEY_DOWN }, 370 { 0x86, 0x1e, KEY_DOWN },
268 { 0x86, 0x1f, KEY_LEFT }, 371 { 0x86, 0x1f, KEY_LEFT },
269 { 0x86, 0x1b, KEY_RIGHT }, 372 { 0x86, 0x1b, KEY_RIGHT },
373
374 /* Key codes for the DiBcom MOD3000 remote. */
375 { 0x80, 0x00, KEY_MUTE },
376 { 0x80, 0x01, KEY_TEXT },
377 { 0x80, 0x02, KEY_HOME },
378 { 0x80, 0x03, KEY_POWER },
379
380 { 0x80, 0x04, KEY_RED },
381 { 0x80, 0x05, KEY_GREEN },
382 { 0x80, 0x06, KEY_YELLOW },
383 { 0x80, 0x07, KEY_BLUE },
384
385 { 0x80, 0x08, KEY_DVD },
386 { 0x80, 0x09, KEY_AUDIO },
387 { 0x80, 0x0a, KEY_MEDIA }, /* Pictures */
388 { 0x80, 0x0b, KEY_VIDEO },
389
390 { 0x80, 0x0c, KEY_BACK },
391 { 0x80, 0x0d, KEY_UP },
392 { 0x80, 0x0e, KEY_RADIO },
393 { 0x80, 0x0f, KEY_EPG },
394
395 { 0x80, 0x10, KEY_LEFT },
396 { 0x80, 0x11, KEY_OK },
397 { 0x80, 0x12, KEY_RIGHT },
398 { 0x80, 0x13, KEY_UNKNOWN }, /* SAP */
399
400 { 0x80, 0x14, KEY_TV },
401 { 0x80, 0x15, KEY_DOWN },
402 { 0x80, 0x16, KEY_MENU }, /* DVD Menu */
403 { 0x80, 0x17, KEY_LAST },
404
405 { 0x80, 0x18, KEY_RECORD },
406 { 0x80, 0x19, KEY_STOP },
407 { 0x80, 0x1a, KEY_PAUSE },
408 { 0x80, 0x1b, KEY_PLAY },
409
410 { 0x80, 0x1c, KEY_PREVIOUS },
411 { 0x80, 0x1d, KEY_REWIND },
412 { 0x80, 0x1e, KEY_FASTFORWARD },
413 { 0x80, 0x1f, KEY_NEXT},
414
415 { 0x80, 0x40, KEY_1 },
416 { 0x80, 0x41, KEY_2 },
417 { 0x80, 0x42, KEY_3 },
418 { 0x80, 0x43, KEY_CHANNELUP },
419
420 { 0x80, 0x44, KEY_4 },
421 { 0x80, 0x45, KEY_5 },
422 { 0x80, 0x46, KEY_6 },
423 { 0x80, 0x47, KEY_CHANNELDOWN },
424
425 { 0x80, 0x48, KEY_7 },
426 { 0x80, 0x49, KEY_8 },
427 { 0x80, 0x4a, KEY_9 },
428 { 0x80, 0x4b, KEY_VOLUMEUP },
429
430 { 0x80, 0x4c, KEY_CLEAR },
431 { 0x80, 0x4d, KEY_0 },
432 { 0x80, 0x4e, KEY_ENTER },
433 { 0x80, 0x4f, KEY_VOLUMEDOWN },
270}; 434};
271EXPORT_SYMBOL(dibusb_rc_keys); 435EXPORT_SYMBOL(dibusb_rc_keys);
272 436
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mb.c b/drivers/media/dvb/dvb-usb/dibusb-mb.c
index f4c45f386ebc..effd34cc4b02 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-mb.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-mb.c
@@ -21,11 +21,11 @@ static int dibusb_dib3000mb_frontend_attach(struct dvb_usb_device *d)
21 21
22 demod_cfg.demod_address = 0x8; 22 demod_cfg.demod_address = 0x8;
23 23
24 if ((d->fe = dib3000mb_attach(&demod_cfg,&d->i2c_adap,&st->ops)) == NULL) { 24 if ((d->fe = dib3000mb_attach(&demod_cfg,&d->i2c_adap,&st->ops)) == NULL)
25 d->fe->ops.tuner_ops.init = dvb_usb_tuner_init_i2c;
26 d->fe->ops.tuner_ops.set_params = dvb_usb_tuner_set_params_i2c;
27 return -ENODEV; 25 return -ENODEV;
28 } 26
27 d->fe->ops.tuner_ops.init = dvb_usb_tuner_init_i2c;
28 d->fe->ops.tuner_ops.set_params = dvb_usb_tuner_set_params_i2c;
29 29
30 d->tuner_pass_ctrl = st->ops.tuner_pass_ctrl; 30 d->tuner_pass_ctrl = st->ops.tuner_pass_ctrl;
31 31
@@ -169,7 +169,7 @@ static struct dvb_usb_properties dibusb1_1_properties = {
169 169
170 .rc_interval = DEFAULT_RC_INTERVAL, 170 .rc_interval = DEFAULT_RC_INTERVAL,
171 .rc_key_map = dibusb_rc_keys, 171 .rc_key_map = dibusb_rc_keys,
172 .rc_key_map_size = 63, /* wow, that is ugly ... I want to load it to the driver dynamically */ 172 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
173 .rc_query = dibusb_rc_query, 173 .rc_query = dibusb_rc_query,
174 174
175 .i2c_algo = &dibusb_i2c_algo, 175 .i2c_algo = &dibusb_i2c_algo,
@@ -247,7 +247,7 @@ static struct dvb_usb_properties dibusb1_1_an2235_properties = {
247 247
248 .rc_interval = DEFAULT_RC_INTERVAL, 248 .rc_interval = DEFAULT_RC_INTERVAL,
249 .rc_key_map = dibusb_rc_keys, 249 .rc_key_map = dibusb_rc_keys,
250 .rc_key_map_size = 63, /* wow, that is ugly ... I want to load it to the driver dynamically */ 250 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
251 .rc_query = dibusb_rc_query, 251 .rc_query = dibusb_rc_query,
252 252
253 .i2c_algo = &dibusb_i2c_algo, 253 .i2c_algo = &dibusb_i2c_algo,
@@ -272,8 +272,8 @@ static struct dvb_usb_properties dibusb1_1_an2235_properties = {
272#endif 272#endif
273 .devices = { 273 .devices = {
274 { "Artec T1 USB1.1 TVBOX with AN2235", 274 { "Artec T1 USB1.1 TVBOX with AN2235",
275 { &dibusb_dib3000mb_table[20], NULL },
276 { &dibusb_dib3000mb_table[21], NULL }, 275 { &dibusb_dib3000mb_table[21], NULL },
276 { &dibusb_dib3000mb_table[22], NULL },
277 }, 277 },
278#ifdef CONFIG_DVB_USB_DIBUSB_MB_FAULTY 278#ifdef CONFIG_DVB_USB_DIBUSB_MB_FAULTY
279 { "Artec T1 USB1.1 TVBOX with AN2235 (faulty USB IDs)", 279 { "Artec T1 USB1.1 TVBOX with AN2235 (faulty USB IDs)",
@@ -304,7 +304,7 @@ static struct dvb_usb_properties dibusb2_0b_properties = {
304 304
305 .rc_interval = DEFAULT_RC_INTERVAL, 305 .rc_interval = DEFAULT_RC_INTERVAL,
306 .rc_key_map = dibusb_rc_keys, 306 .rc_key_map = dibusb_rc_keys,
307 .rc_key_map_size = 63, /* wow, that is ugly ... I want to load it to the driver dynamically */ 307 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
308 .rc_query = dibusb_rc_query, 308 .rc_query = dibusb_rc_query,
309 309
310 .i2c_algo = &dibusb_i2c_algo, 310 .i2c_algo = &dibusb_i2c_algo,
@@ -355,7 +355,7 @@ static struct dvb_usb_properties artec_t1_usb2_properties = {
355 355
356 .rc_interval = DEFAULT_RC_INTERVAL, 356 .rc_interval = DEFAULT_RC_INTERVAL,
357 .rc_key_map = dibusb_rc_keys, 357 .rc_key_map = dibusb_rc_keys,
358 .rc_key_map_size = 63, /* wow, that is ugly ... I want to load it to the driver dynamically */ 358 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
359 .rc_query = dibusb_rc_query, 359 .rc_query = dibusb_rc_query,
360 360
361 .i2c_algo = &dibusb_i2c_algo, 361 .i2c_algo = &dibusb_i2c_algo,
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mc.c b/drivers/media/dvb/dvb-usb/dibusb-mc.c
index 55802fba3c29..eca4082a61ae 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-mc.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-mc.c
@@ -28,6 +28,17 @@ static struct usb_device_id dibusb_dib3000mc_table [] = {
28/* 00 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_MOD3001_COLD) }, 28/* 00 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_MOD3001_COLD) },
29/* 01 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_MOD3001_WARM) }, 29/* 01 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_MOD3001_WARM) },
30/* 02 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_USB2_COLD) }, 30/* 02 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_USB2_COLD) },
31/* 03 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_USB2_WARM) }, // ( ? )
32/* 04 */ { USB_DEVICE(USB_VID_LITEON, USB_PID_LITEON_DVB_T_COLD) },
33/* 05 */ { USB_DEVICE(USB_VID_LITEON, USB_PID_LITEON_DVB_T_WARM) },
34/* 06 */ { USB_DEVICE(USB_VID_EMPIA, USB_PID_DIGIVOX_MINI_SL_COLD) },
35/* 07 */ { USB_DEVICE(USB_VID_EMPIA, USB_PID_DIGIVOX_MINI_SL_WARM) },
36/* 08 */ { USB_DEVICE(USB_VID_GRANDTEC, USB_PID_GRANDTEC_DVBT_USB2_COLD) },
37/* 09 */ { USB_DEVICE(USB_VID_GRANDTEC, USB_PID_GRANDTEC_DVBT_USB2_WARM) },
38/* 10 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ARTEC_T14_COLD) },
39/* 11 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ARTEC_T14_WARM) },
40/* 12 */ { USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_COLD) },
41/* 13 */ { USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_WARM) },
31 { } /* Terminating entry */ 42 { } /* Terminating entry */
32}; 43};
33MODULE_DEVICE_TABLE (usb, dibusb_dib3000mc_table); 44MODULE_DEVICE_TABLE (usb, dibusb_dib3000mc_table);
@@ -50,7 +61,7 @@ static struct dvb_usb_properties dibusb_mc_properties = {
50 61
51 .rc_interval = DEFAULT_RC_INTERVAL, 62 .rc_interval = DEFAULT_RC_INTERVAL,
52 .rc_key_map = dibusb_rc_keys, 63 .rc_key_map = dibusb_rc_keys,
53 .rc_key_map_size = 63, /* FIXME */ 64 .rc_key_map_size = 111, /* FIXME */
54 .rc_query = dibusb_rc_query, 65 .rc_query = dibusb_rc_query,
55 66
56 .i2c_algo = &dibusb_i2c_algo, 67 .i2c_algo = &dibusb_i2c_algo,
@@ -68,16 +79,38 @@ static struct dvb_usb_properties dibusb_mc_properties = {
68 } 79 }
69 }, 80 },
70 81
71 .num_device_descs = 2, 82 .num_device_descs = 7,
72 .devices = { 83 .devices = {
73 { "DiBcom USB2.0 DVB-T reference design (MOD3000P)", 84 { "DiBcom USB2.0 DVB-T reference design (MOD3000P)",
74 { &dibusb_dib3000mc_table[0], NULL }, 85 { &dibusb_dib3000mc_table[0], NULL },
75 { &dibusb_dib3000mc_table[1], NULL }, 86 { &dibusb_dib3000mc_table[1], NULL },
76 }, 87 },
77 { "Artec T1 USB2.0 TVBOX (please report the warm ID)", 88 { "Artec T1 USB2.0 TVBOX (please check the warm ID)",
78 { &dibusb_dib3000mc_table[2], NULL }, 89 { &dibusb_dib3000mc_table[2], NULL },
79 { NULL }, 90 { &dibusb_dib3000mc_table[3], NULL },
80 }, 91 },
92 { "LITE-ON USB2.0 DVB-T Tuner",
93 /* Also rebranded as Intuix S800, Toshiba */
94 { &dibusb_dib3000mc_table[4], NULL },
95 { &dibusb_dib3000mc_table[5], NULL },
96 },
97 { "MSI Digivox Mini SL",
98 { &dibusb_dib3000mc_table[6], NULL },
99 { &dibusb_dib3000mc_table[7], NULL },
100 },
101 { "GRAND - USB2.0 DVB-T adapter",
102 { &dibusb_dib3000mc_table[8], NULL },
103 { &dibusb_dib3000mc_table[9], NULL },
104 },
105 { "Artec T14 - USB2.0 DVB-T",
106 { &dibusb_dib3000mc_table[10], NULL },
107 { &dibusb_dib3000mc_table[11], NULL },
108 },
109 { "Leadtek - USB2.0 Winfast DTV dongle",
110 { &dibusb_dib3000mc_table[12], NULL },
111 { &dibusb_dib3000mc_table[13], NULL },
112 },
113 { NULL },
81 } 114 }
82}; 115};
83 116
diff --git a/drivers/media/dvb/dvb-usb/dibusb.h b/drivers/media/dvb/dvb-usb/dibusb.h
index 2d99d05c7eab..a43f87480cf6 100644
--- a/drivers/media/dvb/dvb-usb/dibusb.h
+++ b/drivers/media/dvb/dvb-usb/dibusb.h
@@ -17,6 +17,8 @@
17#include "dvb-usb.h" 17#include "dvb-usb.h"
18 18
19#include "dib3000.h" 19#include "dib3000.h"
20#include "dib3000mc.h"
21#include "mt2060.h"
20 22
21/* 23/*
22 * protocol of all dibusb related devices 24 * protocol of all dibusb related devices
@@ -96,6 +98,7 @@
96 98
97struct dibusb_state { 99struct dibusb_state {
98 struct dib_fe_xfer_ops ops; 100 struct dib_fe_xfer_ops ops;
101 int mt2060_present;
99 102
100 /* for RC5 remote control */ 103 /* for RC5 remote control */
101 int old_toggle; 104 int old_toggle;
diff --git a/drivers/media/dvb/dvb-usb/digitv.c b/drivers/media/dvb/dvb-usb/digitv.c
index c14d9efb48fd..015854487308 100644
--- a/drivers/media/dvb/dvb-usb/digitv.c
+++ b/drivers/media/dvb/dvb-usb/digitv.c
@@ -128,11 +128,11 @@ static struct nxt6000_config digitv_nxt6000_config = {
128 128
129static int digitv_frontend_attach(struct dvb_usb_device *d) 129static int digitv_frontend_attach(struct dvb_usb_device *d)
130{ 130{
131 if ((d->fe = mt352_attach(&digitv_mt352_config, &d->i2c_adap)) != NULL) { 131 if ((d->fe = dvb_attach(mt352_attach, &digitv_mt352_config, &d->i2c_adap)) != NULL) {
132 d->fe->ops.tuner_ops.calc_regs = dvb_usb_tuner_calc_regs; 132 d->fe->ops.tuner_ops.calc_regs = dvb_usb_tuner_calc_regs;
133 return 0; 133 return 0;
134 } 134 }
135 if ((d->fe = nxt6000_attach(&digitv_nxt6000_config, &d->i2c_adap)) != NULL) { 135 if ((d->fe = dvb_attach(nxt6000_attach, &digitv_nxt6000_config, &d->i2c_adap)) != NULL) {
136 d->fe->ops.tuner_ops.set_params = digitv_nxt6000_tuner_set_params; 136 d->fe->ops.tuner_ops.set_params = digitv_nxt6000_tuner_set_params;
137 return 0; 137 return 0;
138 } 138 }
@@ -147,21 +147,91 @@ static int digitv_tuner_attach(struct dvb_usb_device *d)
147} 147}
148 148
149static struct dvb_usb_rc_key digitv_rc_keys[] = { 149static struct dvb_usb_rc_key digitv_rc_keys[] = {
150 { 0x00, 0x16, KEY_POWER }, /* dummy key */ 150 { 0x5f, 0x55, KEY_0 },
151 { 0x6f, 0x55, KEY_1 },
152 { 0x9f, 0x55, KEY_2 },
153 { 0xaf, 0x55, KEY_3 },
154 { 0x5f, 0x56, KEY_4 },
155 { 0x6f, 0x56, KEY_5 },
156 { 0x9f, 0x56, KEY_6 },
157 { 0xaf, 0x56, KEY_7 },
158 { 0x5f, 0x59, KEY_8 },
159 { 0x6f, 0x59, KEY_9 },
160 { 0x9f, 0x59, KEY_TV },
161 { 0xaf, 0x59, KEY_AUX },
162 { 0x5f, 0x5a, KEY_DVD },
163 { 0x6f, 0x5a, KEY_POWER },
164 { 0x9f, 0x5a, KEY_MHP }, /* labelled 'Picture' */
165 { 0xaf, 0x5a, KEY_AUDIO },
166 { 0x5f, 0x65, KEY_INFO },
167 { 0x6f, 0x65, KEY_F13 }, /* 16:9 */
168 { 0x9f, 0x65, KEY_F14 }, /* 14:9 */
169 { 0xaf, 0x65, KEY_EPG },
170 { 0x5f, 0x66, KEY_EXIT },
171 { 0x6f, 0x66, KEY_MENU },
172 { 0x9f, 0x66, KEY_UP },
173 { 0xaf, 0x66, KEY_DOWN },
174 { 0x5f, 0x69, KEY_LEFT },
175 { 0x6f, 0x69, KEY_RIGHT },
176 { 0x9f, 0x69, KEY_ENTER },
177 { 0xaf, 0x69, KEY_CHANNELUP },
178 { 0x5f, 0x6a, KEY_CHANNELDOWN },
179 { 0x6f, 0x6a, KEY_VOLUMEUP },
180 { 0x9f, 0x6a, KEY_VOLUMEDOWN },
181 { 0xaf, 0x6a, KEY_RED },
182 { 0x5f, 0x95, KEY_GREEN },
183 { 0x6f, 0x95, KEY_YELLOW },
184 { 0x9f, 0x95, KEY_BLUE },
185 { 0xaf, 0x95, KEY_SUBTITLE },
186 { 0x5f, 0x96, KEY_F15 }, /* AD */
187 { 0x6f, 0x96, KEY_TEXT },
188 { 0x9f, 0x96, KEY_MUTE },
189 { 0xaf, 0x96, KEY_REWIND },
190 { 0x5f, 0x99, KEY_STOP },
191 { 0x6f, 0x99, KEY_PLAY },
192 { 0x9f, 0x99, KEY_FASTFORWARD },
193 { 0xaf, 0x99, KEY_F16 }, /* chapter */
194 { 0x5f, 0x9a, KEY_PAUSE },
195 { 0x6f, 0x9a, KEY_PLAY },
196 { 0x9f, 0x9a, KEY_RECORD },
197 { 0xaf, 0x9a, KEY_F17 }, /* picture in picture */
198 { 0x5f, 0xa5, KEY_KPPLUS }, /* zoom in */
199 { 0x6f, 0xa5, KEY_KPMINUS }, /* zoom out */
200 { 0x9f, 0xa5, KEY_F18 }, /* capture */
201 { 0xaf, 0xa5, KEY_F19 }, /* web */
202 { 0x5f, 0xa6, KEY_EMAIL },
203 { 0x6f, 0xa6, KEY_PHONE },
204 { 0x9f, 0xa6, KEY_PC },
151}; 205};
152 206
153/* TODO is it really the NEC protocol ? */
154static int digitv_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 207static int digitv_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
155{ 208{
209 int i;
156 u8 key[5]; 210 u8 key[5];
211 u8 b[4] = { 0 };
212
213 *event = 0;
214 *state = REMOTE_NO_KEY_PRESSED;
157 215
158 digitv_ctrl_msg(d,USB_READ_REMOTE,0,NULL,0,&key[1],4); 216 digitv_ctrl_msg(d,USB_READ_REMOTE,0,NULL,0,&key[1],4);
159 /* TODO state, maybe it is VV ? */ 217
218 /* Tell the device we've read the remote. Not sure how necessary
219 this is, but the Nebula SDK does it. */
220 digitv_ctrl_msg(d,USB_WRITE_REMOTE,0,b,4,NULL,0);
221
222 /* if something is inside the buffer, simulate key press */
160 if (key[1] != 0) 223 if (key[1] != 0)
161 key[0] = 0x01; /* if something is inside the buffer, simulate key press */ 224 {
225 for (i = 0; i < d->props.rc_key_map_size; i++) {
226 if (d->props.rc_key_map[i].custom == key[1] &&
227 d->props.rc_key_map[i].data == key[2]) {
228 *event = d->props.rc_key_map[i].event;
229 *state = REMOTE_KEY_PRESSED;
230 return 0;
231 }
232 }
233 }
162 234
163 /* call the universal NEC remote processor, to find out the key's state and event */
164 dvb_usb_nec_rc_key_to_event(d,key,event,state);
165 if (key[0] != 0) 235 if (key[0] != 0)
166 deb_rc("key: %x %x %x %x %x\n",key[0],key[1],key[2],key[3],key[4]); 236 deb_rc("key: %x %x %x %x %x\n",key[0],key[1],key[2],key[3],key[4]);
167 return 0; 237 return 0;
diff --git a/drivers/media/dvb/dvb-usb/dtt200u.c b/drivers/media/dvb/dvb-usb/dtt200u.c
index 70afcfd141ca..27af4e436479 100644
--- a/drivers/media/dvb/dvb-usb/dtt200u.c
+++ b/drivers/media/dvb/dvb-usb/dtt200u.c
@@ -93,6 +93,7 @@ static int dtt200u_frontend_attach(struct dvb_usb_device *d)
93} 93}
94 94
95static struct dvb_usb_properties dtt200u_properties; 95static struct dvb_usb_properties dtt200u_properties;
96static struct dvb_usb_properties wt220u_fc_properties;
96static struct dvb_usb_properties wt220u_properties; 97static struct dvb_usb_properties wt220u_properties;
97static struct dvb_usb_properties wt220u_zl0353_properties; 98static struct dvb_usb_properties wt220u_zl0353_properties;
98 99
@@ -101,6 +102,7 @@ static int dtt200u_usb_probe(struct usb_interface *intf,
101{ 102{
102 if (dvb_usb_device_init(intf,&dtt200u_properties,THIS_MODULE,NULL) == 0 || 103 if (dvb_usb_device_init(intf,&dtt200u_properties,THIS_MODULE,NULL) == 0 ||
103 dvb_usb_device_init(intf,&wt220u_properties,THIS_MODULE,NULL) == 0 || 104 dvb_usb_device_init(intf,&wt220u_properties,THIS_MODULE,NULL) == 0 ||
105 dvb_usb_device_init(intf,&wt220u_fc_properties,THIS_MODULE,NULL) == 0 ||
104 dvb_usb_device_init(intf,&wt220u_zl0353_properties,THIS_MODULE,NULL) == 0) 106 dvb_usb_device_init(intf,&wt220u_zl0353_properties,THIS_MODULE,NULL) == 0)
105 return 0; 107 return 0;
106 108
@@ -114,6 +116,9 @@ static struct usb_device_id dtt200u_usb_table [] = {
114 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_WARM) }, 116 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_WARM) },
115 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_ZL0353_COLD) }, 117 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_ZL0353_COLD) },
116 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_ZL0353_WARM) }, 118 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_ZL0353_WARM) },
119 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_FC_COLD) },
120 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_FC_WARM) },
121 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_ZAP250_COLD) },
117 { 0 }, 122 { 0 },
118}; 123};
119MODULE_DEVICE_TABLE(usb, dtt200u_usb_table); 124MODULE_DEVICE_TABLE(usb, dtt200u_usb_table);
@@ -193,13 +198,54 @@ static struct dvb_usb_properties wt220u_properties = {
193 .num_device_descs = 1, 198 .num_device_descs = 1,
194 .devices = { 199 .devices = {
195 { .name = "WideView WT-220U PenType Receiver (Typhoon/Freecom)", 200 { .name = "WideView WT-220U PenType Receiver (Typhoon/Freecom)",
196 .cold_ids = { &dtt200u_usb_table[2], NULL }, 201 .cold_ids = { &dtt200u_usb_table[2], &dtt200u_usb_table[8], NULL },
197 .warm_ids = { &dtt200u_usb_table[3], NULL }, 202 .warm_ids = { &dtt200u_usb_table[3], NULL },
198 }, 203 },
199 { NULL }, 204 { NULL },
200 } 205 }
201}; 206};
202 207
208static struct dvb_usb_properties wt220u_fc_properties = {
209 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_NEED_PID_FILTERING,
210 .pid_filter_count = 15,
211
212 .usb_ctrl = CYPRESS_FX2,
213 .firmware = "dvb-usb-wt220u-fc03.fw",
214
215 .power_ctrl = dtt200u_power_ctrl,
216 .streaming_ctrl = dtt200u_streaming_ctrl,
217 .pid_filter = dtt200u_pid_filter,
218 .frontend_attach = dtt200u_frontend_attach,
219
220 .rc_interval = 300,
221 .rc_key_map = dtt200u_rc_keys,
222 .rc_key_map_size = ARRAY_SIZE(dtt200u_rc_keys),
223 .rc_query = dtt200u_rc_query,
224
225 .generic_bulk_ctrl_endpoint = 0x01,
226
227 /* parameter for the MPEG2-data transfer */
228 .urb = {
229 .type = DVB_USB_BULK,
230 .count = 7,
231 .endpoint = 0x86,
232 .u = {
233 .bulk = {
234 .buffersize = 4096,
235 }
236 }
237 },
238
239 .num_device_descs = 1,
240 .devices = {
241 { .name = "WideView WT-220U PenType Receiver (Typhoon/Freecom)",
242 .cold_ids = { &dtt200u_usb_table[6], NULL },
243 .warm_ids = { &dtt200u_usb_table[7], NULL },
244 },
245 { NULL },
246 }
247};
248
203static struct dvb_usb_properties wt220u_zl0353_properties = { 249static struct dvb_usb_properties wt220u_zl0353_properties = {
204 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_NEED_PID_FILTERING, 250 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_NEED_PID_FILTERING,
205 .pid_filter_count = 15, 251 .pid_filter_count = 15,
@@ -271,6 +317,6 @@ module_init(dtt200u_usb_module_init);
271module_exit(dtt200u_usb_module_exit); 317module_exit(dtt200u_usb_module_exit);
272 318
273MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>"); 319MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
274MODULE_DESCRIPTION("Driver for the WideView/Yakumo/Hama/Typhoon DVB-T USB2.0 devices"); 320MODULE_DESCRIPTION("Driver for the WideView/Yakumo/Hama/Typhoon/Club3D DVB-T USB2.0 devices");
275MODULE_VERSION("1.0"); 321MODULE_VERSION("1.0");
276MODULE_LICENSE("GPL"); 322MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c b/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
index ec631708c394..fe6208ada903 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
@@ -175,36 +175,36 @@ 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' doesn'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
182 d->props.frontend_attach(d);
183
184 /* re-assign sleep and wakeup functions */ 182 /* re-assign sleep and wakeup functions */
185 if (d->fe != NULL) { 183 if (d->props.frontend_attach(d) == 0 && d->fe != NULL) {
186 d->fe_init = d->fe->ops.init; d->fe->ops.init = dvb_usb_fe_wakeup; 184 d->fe_init = d->fe->ops.init; d->fe->ops.init = dvb_usb_fe_wakeup;
187 d->fe_sleep = d->fe->ops.sleep; d->fe->ops.sleep = dvb_usb_fe_sleep; 185 d->fe_sleep = d->fe->ops.sleep; d->fe->ops.sleep = dvb_usb_fe_sleep;
188 186
189 if (dvb_register_frontend(&d->dvb_adap, d->fe)) { 187 if (dvb_register_frontend(&d->dvb_adap, d->fe)) {
190 err("Frontend registration failed."); 188 err("Frontend registration failed.");
191 if (d->fe->ops.release) 189 dvb_frontend_detach(d->fe);
192 d->fe->ops.release(d->fe);
193 d->fe = NULL; 190 d->fe = NULL;
194 return -ENODEV; 191 return -ENODEV;
195 } 192 }
193
194 /* only attach the tuner if the demod is there */
195 if (d->props.tuner_attach != NULL)
196 d->props.tuner_attach(d);
196 } else 197 } else
197 err("no frontend was attached by '%s'",d->desc->name); 198 err("no frontend was attached by '%s'",d->desc->name);
198 199
199 if (d->props.tuner_attach != NULL)
200 d->props.tuner_attach(d);
201
202 return 0; 200 return 0;
203} 201}
204 202
205int dvb_usb_fe_exit(struct dvb_usb_device *d) 203int dvb_usb_fe_exit(struct dvb_usb_device *d)
206{ 204{
207 if (d->fe != NULL) 205 if (d->fe != NULL) {
208 dvb_unregister_frontend(d->fe); 206 dvb_unregister_frontend(d->fe);
207 dvb_frontend_detach(d->fe);
208 }
209 return 0; 209 return 0;
210} 210}
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index 95698918bc11..57a10de1d3dd 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -10,51 +10,53 @@
10#define _DVB_USB_IDS_H_ 10#define _DVB_USB_IDS_H_
11 11
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_WIDEVIEW 0x14aa 15#define USB_VID_AVERMEDIA 0x07ca
16#define USB_VID_AVERMEDIA 0x07ca 16#define USB_VID_COMPRO 0x185b
17#define USB_VID_COMPRO 0x185b 17#define USB_VID_COMPRO_UNK 0x145f
18#define USB_VID_COMPRO_UNK 0x145f 18#define USB_VID_CYPRESS 0x04b4
19#define USB_VID_CYPRESS 0x04b4 19#define USB_VID_DIBCOM 0x10b8
20#define USB_VID_DIBCOM 0x10b8 20#define USB_VID_DVICO 0x0fe9
21#define USB_VID_DVICO 0x0fe9 21#define USB_VID_EMPIA 0xeb1a
22#define USB_VID_EMPIA 0xeb1a 22#define USB_VID_GENPIX 0x09c0
23#define USB_VID_GRANDTEC 0x5032 23#define USB_VID_GRANDTEC 0x5032
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_KWORLD 0xeb2a 27#define USB_VID_KWORLD 0xeb2a
28#define USB_VID_KYE 0x0458 28#define USB_VID_KYE 0x0458
29#define USB_VID_MEDION 0x1660 29#define USB_VID_LEADTEK 0x0413
30#define USB_VID_PINNACLE 0x2304 30#define USB_VID_LITEON 0x04ca
31#define USB_VID_VISIONPLUS 0x13d3 31#define USB_VID_MEDION 0x1660
32#define USB_VID_TWINHAN 0x1822 32#define USB_VID_PINNACLE 0x2304
33#define USB_VID_ULTIMA_ELECTRONIC 0x05d8 33#define USB_VID_VISIONPLUS 0x13d3
34#define USB_VID_GENPIX 0x09c0 34#define USB_VID_TWINHAN 0x1822
35#define USB_VID_ULTIMA_ELECTRONIC 0x05d8
36#define USB_VID_WIDEVIEW 0x14aa
35 37
36/* Product IDs */ 38/* Product IDs */
37#define USB_PID_ADSTECH_USB2_COLD 0xa333 39#define USB_PID_ADSTECH_USB2_COLD 0xa333
38#define USB_PID_ADSTECH_USB2_WARM 0xa334 40#define USB_PID_ADSTECH_USB2_WARM 0xa334
39#define USB_PID_AVERMEDIA_DVBT_USB_COLD 0x0001 41#define USB_PID_AVERMEDIA_DVBT_USB_COLD 0x0001
40#define USB_PID_AVERMEDIA_DVBT_USB_WARM 0x0002 42#define USB_PID_AVERMEDIA_DVBT_USB_WARM 0x0002
41#define USB_PID_AVERMEDIA_DVBT_USB2_COLD 0xa800 43#define USB_PID_AVERMEDIA_DVBT_USB2_COLD 0xa800
42#define USB_PID_AVERMEDIA_DVBT_USB2_WARM 0xa801 44#define USB_PID_AVERMEDIA_DVBT_USB2_WARM 0xa801
43#define USB_PID_COMPRO_DVBU2000_COLD 0xd000 45#define USB_PID_COMPRO_DVBU2000_COLD 0xd000
44#define USB_PID_COMPRO_DVBU2000_WARM 0xd001 46#define USB_PID_COMPRO_DVBU2000_WARM 0xd001
45#define USB_PID_COMPRO_DVBU2000_UNK_COLD 0x010c 47#define USB_PID_COMPRO_DVBU2000_UNK_COLD 0x010c
46#define USB_PID_COMPRO_DVBU2000_UNK_WARM 0x010d 48#define USB_PID_COMPRO_DVBU2000_UNK_WARM 0x010d
47#define USB_PID_DIBCOM_HOOK_DEFAULT 0x0064 49#define USB_PID_DIBCOM_HOOK_DEFAULT 0x0064
48#define USB_PID_DIBCOM_HOOK_DEFAULT_REENUM 0x0065 50#define USB_PID_DIBCOM_HOOK_DEFAULT_REENUM 0x0065
49#define USB_PID_DIBCOM_MOD3000_COLD 0x0bb8 51#define USB_PID_DIBCOM_MOD3000_COLD 0x0bb8
50#define USB_PID_DIBCOM_MOD3000_WARM 0x0bb9 52#define USB_PID_DIBCOM_MOD3000_WARM 0x0bb9
51#define USB_PID_DIBCOM_MOD3001_COLD 0x0bc6 53#define USB_PID_DIBCOM_MOD3001_COLD 0x0bc6
52#define USB_PID_DIBCOM_MOD3001_WARM 0x0bc7 54#define USB_PID_DIBCOM_MOD3001_WARM 0x0bc7
53#define USB_PID_DIBCOM_STK7700 0x1e14 55#define USB_PID_DIBCOM_STK7700 0x1e14
54#define USB_PID_DIBCOM_STK7700_REENUM 0x1e15 56#define USB_PID_DIBCOM_STK7700_REENUM 0x1e15
55#define USB_PID_DIBCOM_ANCHOR_2135_COLD 0x2131 57#define USB_PID_DIBCOM_ANCHOR_2135_COLD 0x2131
56#define USB_PID_GRANDTEC_DVBT_USB_COLD 0x0fa0 58#define USB_PID_GRANDTEC_DVBT_USB_COLD 0x0fa0
57#define USB_PID_GRANDTEC_DVBT_USB_WARM 0x0fa1 59#define USB_PID_GRANDTEC_DVBT_USB_WARM 0x0fa1
58#define USB_PID_KWORLD_VSTREAM_COLD 0x17de 60#define USB_PID_KWORLD_VSTREAM_COLD 0x17de
59#define USB_PID_KWORLD_VSTREAM_WARM 0x17df 61#define USB_PID_KWORLD_VSTREAM_WARM 0x17df
60#define USB_PID_TWINHAN_VP7041_COLD 0x3201 62#define USB_PID_TWINHAN_VP7041_COLD 0x3201
@@ -69,25 +71,30 @@
69#define USB_PID_DNTV_TINYUSB2_WARM 0x3224 71#define USB_PID_DNTV_TINYUSB2_WARM 0x3224
70#define USB_PID_ULTIMA_TVBOX_COLD 0x8105 72#define USB_PID_ULTIMA_TVBOX_COLD 0x8105
71#define USB_PID_ULTIMA_TVBOX_WARM 0x8106 73#define USB_PID_ULTIMA_TVBOX_WARM 0x8106
72#define USB_PID_ULTIMA_TVBOX_AN2235_COLD 0x8107 74#define USB_PID_ULTIMA_TVBOX_AN2235_COLD 0x8107
73#define USB_PID_ULTIMA_TVBOX_AN2235_WARM 0x8108 75#define USB_PID_ULTIMA_TVBOX_AN2235_WARM 0x8108
74#define USB_PID_ULTIMA_TVBOX_ANCHOR_COLD 0x2235 76#define USB_PID_ULTIMA_TVBOX_ANCHOR_COLD 0x2235
75#define USB_PID_ULTIMA_TVBOX_USB2_COLD 0x8109 77#define USB_PID_ULTIMA_TVBOX_USB2_COLD 0x8109
76#define USB_PID_ULTIMA_TVBOX_USB2_WARM 0x810a 78#define USB_PID_ULTIMA_TVBOX_USB2_WARM 0x810a
77#define USB_PID_ULTIMA_TVBOX_USB2_FX_COLD 0x8613 79#define USB_PID_ARTEC_T14_COLD 0x810b
78#define USB_PID_ULTIMA_TVBOX_USB2_FX_WARM 0x1002 80#define USB_PID_ARTEC_T14_WARM 0x810c
79#define USB_PID_UNK_HYPER_PALTEK_COLD 0x005e 81#define USB_PID_ULTIMA_TVBOX_USB2_FX_COLD 0x8613
80#define USB_PID_UNK_HYPER_PALTEK_WARM 0x005f 82#define USB_PID_ULTIMA_TVBOX_USB2_FX_WARM 0x1002
81#define USB_PID_HANFTEK_UMT_010_COLD 0x0001 83#define USB_PID_UNK_HYPER_PALTEK_COLD 0x005e
82#define USB_PID_HANFTEK_UMT_010_WARM 0x0015 84#define USB_PID_UNK_HYPER_PALTEK_WARM 0x005f
85#define USB_PID_HANFTEK_UMT_010_COLD 0x0001
86#define USB_PID_HANFTEK_UMT_010_WARM 0x0015
83#define USB_PID_DTT200U_COLD 0x0201 87#define USB_PID_DTT200U_COLD 0x0201
84#define USB_PID_DTT200U_WARM 0x0301 88#define USB_PID_DTT200U_WARM 0x0301
85#define USB_PID_WT220U_COLD 0x0222 89#define USB_PID_WT220U_ZAP250_COLD 0x0220
86#define USB_PID_WT220U_WARM 0x0221 90#define USB_PID_WT220U_COLD 0x0222
91#define USB_PID_WT220U_WARM 0x0221
92#define USB_PID_WT220U_FC_COLD 0x0225
93#define USB_PID_WT220U_FC_WARM 0x0226
87#define USB_PID_WT220U_ZL0353_COLD 0x022a 94#define USB_PID_WT220U_ZL0353_COLD 0x022a
88#define USB_PID_WT220U_ZL0353_WARM 0x022b 95#define USB_PID_WT220U_ZL0353_WARM 0x022b
89#define USB_PID_WINTV_NOVA_T_USB2_COLD 0x9300 96#define USB_PID_WINTV_NOVA_T_USB2_COLD 0x9300
90#define USB_PID_WINTV_NOVA_T_USB2_WARM 0x9301 97#define USB_PID_WINTV_NOVA_T_USB2_WARM 0x9301
91#define USB_PID_NEBULA_DIGITV 0x0201 98#define USB_PID_NEBULA_DIGITV 0x0201
92#define USB_PID_DVICO_BLUEBIRD_LGDT 0xd820 99#define USB_PID_DVICO_BLUEBIRD_LGDT 0xd820
93#define USB_PID_DVICO_BLUEBIRD_LG064F_COLD 0xd500 100#define USB_PID_DVICO_BLUEBIRD_LG064F_COLD 0xd500
@@ -103,8 +110,17 @@
103#define USB_PID_MEDION_MD95700 0x0932 110#define USB_PID_MEDION_MD95700 0x0932
104#define USB_PID_KYE_DVB_T_COLD 0x701e 111#define USB_PID_KYE_DVB_T_COLD 0x701e
105#define USB_PID_KYE_DVB_T_WARM 0x701f 112#define USB_PID_KYE_DVB_T_WARM 0x701f
106#define USB_PID_PCTV_200E 0x020e 113#define USB_PID_PCTV_200E 0x020e
107#define USB_PID_PCTV_400E 0x020f 114#define USB_PID_PCTV_400E 0x020f
108#define USB_PID_GENPIX_8PSK_COLD 0x0200 115#define USB_PID_LITEON_DVB_T_COLD 0xf000
109#define USB_PID_GENPIX_8PSK_WARM 0x0201 116#define USB_PID_LITEON_DVB_T_WARM 0xf001
117#define USB_PID_DIGIVOX_MINI_SL_COLD 0xe360
118#define USB_PID_DIGIVOX_MINI_SL_WARM 0xe361
119#define USB_PID_GRANDTEC_DVBT_USB2_COLD 0x0bc6
120#define USB_PID_GRANDTEC_DVBT_USB2_WARM 0x0bc7
121#define USB_PID_WINFAST_DTV_DONGLE_COLD 0x6025
122#define USB_PID_WINFAST_DTV_DONGLE_WARM 0x6026
123#define USB_PID_GENPIX_8PSK_COLD 0x0200
124#define USB_PID_GENPIX_8PSK_WARM 0x0201
125
110#endif 126#endif
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
index e5c6d9835e06..380b2a45ee4c 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
@@ -6,6 +6,7 @@
6 * This file contains functions for initializing the the input-device and for handling remote-control-queries. 6 * This file contains functions for initializing the the input-device and for handling remote-control-queries.
7 */ 7 */
8#include "dvb-usb-common.h" 8#include "dvb-usb-common.h"
9#include <linux/usb/input.h>
9 10
10/* Remote-control poll function - called every dib->rc_query_interval ms to see 11/* Remote-control poll function - called every dib->rc_query_interval ms to see
11 * whether the remote control has received anything. 12 * whether the remote control has received anything.
@@ -96,7 +97,7 @@ int dvb_usb_remote_init(struct dvb_usb_device *d)
96 return 0; 97 return 0;
97 98
98 usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys)); 99 usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys));
99 strlcpy(d->rc_phys, "/ir0", sizeof(d->rc_phys)); 100 strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys));
100 101
101 d->rc_input_dev = input_allocate_device(); 102 d->rc_input_dev = input_allocate_device();
102 if (!d->rc_input_dev) 103 if (!d->rc_input_dev)
@@ -107,6 +108,8 @@ int dvb_usb_remote_init(struct dvb_usb_device *d)
107 d->rc_input_dev->keycodemax = KEY_MAX; 108 d->rc_input_dev->keycodemax = KEY_MAX;
108 d->rc_input_dev->name = "IR-receiver inside an USB DVB receiver"; 109 d->rc_input_dev->name = "IR-receiver inside an USB DVB receiver";
109 d->rc_input_dev->phys = d->rc_phys; 110 d->rc_input_dev->phys = d->rc_phys;
111 usb_to_input_id(d->udev, &d->rc_input_dev->id);
112 d->rc_input_dev->cdev.dev = &d->udev->dev;
110 113
111 /* set the bits for the keys */ 114 /* set the bits for the keys */
112 deb_rc("key map size: %d\n", d->props.rc_key_map_size); 115 deb_rc("key map size: %d\n", d->props.rc_key_map_size);
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-urb.c b/drivers/media/dvb/dvb-usb/dvb-usb-urb.c
index 9002f35aa952..88b283731bb8 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-urb.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-urb.c
@@ -80,7 +80,6 @@ static void dvb_usb_urb_complete(struct urb *urb, struct pt_regs *ptregs)
80 80
81 switch (urb->status) { 81 switch (urb->status) {
82 case 0: /* success */ 82 case 0: /* success */
83 case -ETIMEDOUT: /* NAK */
84 break; 83 break;
85 case -ECONNRESET: /* kill */ 84 case -ECONNRESET: /* kill */
86 case -ENOENT: 85 case -ENOENT:
diff --git a/drivers/media/dvb/dvb-usb/nova-t-usb2.c b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
index 412039d8dbae..79f0a02ce987 100644
--- a/drivers/media/dvb/dvb-usb/nova-t-usb2.c
+++ b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
@@ -156,7 +156,7 @@ static struct dvb_usb_properties nova_t_properties = {
156 .pid_filter_count = 32, 156 .pid_filter_count = 32,
157 157
158 .usb_ctrl = CYPRESS_FX2, 158 .usb_ctrl = CYPRESS_FX2,
159 .firmware = "dvb-usb-nova-t-usb2-01.fw", 159 .firmware = "dvb-usb-nova-t-usb2-02.fw",
160 160
161 .size_of_priv = sizeof(struct dibusb_state), 161 .size_of_priv = sizeof(struct dibusb_state),
162 162
diff --git a/drivers/media/dvb/dvb-usb/umt-010.c b/drivers/media/dvb/dvb-usb/umt-010.c
index 97d74da0dad8..418a0b707151 100644
--- a/drivers/media/dvb/dvb-usb/umt-010.c
+++ b/drivers/media/dvb/dvb-usb/umt-010.c
@@ -58,7 +58,7 @@ static int umt_mt352_frontend_attach(struct dvb_usb_device *d)
58 umt_config.demod_init = umt_mt352_demod_init; 58 umt_config.demod_init = umt_mt352_demod_init;
59 umt_config.demod_address = 0xf; 59 umt_config.demod_address = 0xf;
60 60
61 d->fe = mt352_attach(&umt_config, &d->i2c_adap); 61 d->fe = dvb_attach(mt352_attach, &umt_config, &d->i2c_adap);
62 62
63 return 0; 63 return 0;
64} 64}
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index db978555b1eb..080fa257a0bc 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -1,48 +1,73 @@
1menu "Customise DVB Frontends" 1menu "Customise DVB Frontends"
2 depends on DVB_CORE 2 depends on DVB_CORE
3 3
4config DVB_FE_CUSTOMISE
5 bool "Customise the frontend modules to build"
6 default N
7 help
8 This allows the user to deselect frontend drivers unnecessary
9 for their hardware from the build. Use this option with care
10 as deselecting frontends which are in fact necessary will result
11 in DVB devices which cannot be tuned due to lack of driver support.
12
13 If unsure say N.
14
4comment "DVB-S (satellite) frontends" 15comment "DVB-S (satellite) frontends"
5 depends on DVB_CORE 16 depends on DVB_CORE
6 17
7config DVB_STV0299 18config DVB_STV0299
8 tristate "ST STV0299 based" 19 tristate "ST STV0299 based"
9 depends on DVB_CORE && I2C 20 depends on DVB_CORE && I2C
21 default m if DVB_FE_CUSTOMISE
10 help 22 help
11 A DVB-S tuner module. Say Y when you want to support this frontend. 23 A DVB-S tuner module. Say Y when you want to support this frontend.
12 24
13config DVB_CX24110 25config DVB_CX24110
14 tristate "Conexant CX24110 based" 26 tristate "Conexant CX24110 based"
15 depends on DVB_CORE && I2C 27 depends on DVB_CORE && I2C
28 default m if DVB_FE_CUSTOMISE
16 help 29 help
17 A DVB-S tuner module. Say Y when you want to support this frontend. 30 A DVB-S tuner module. Say Y when you want to support this frontend.
18 31
19config DVB_CX24123 32config DVB_CX24123
20 tristate "Conexant CX24123 based" 33 tristate "Conexant CX24123 based"
21 depends on DVB_CORE && I2C 34 depends on DVB_CORE && I2C
35 default m if DVB_FE_CUSTOMISE
22 help 36 help
23 A DVB-S tuner module. Say Y when you want to support this frontend. 37 A DVB-S tuner module. Say Y when you want to support this frontend.
24 38
25config DVB_TDA8083 39config DVB_TDA8083
26 tristate "Philips TDA8083 based" 40 tristate "Philips TDA8083 based"
27 depends on DVB_CORE && I2C 41 depends on DVB_CORE && I2C
42 default m if DVB_FE_CUSTOMISE
28 help 43 help
29 A DVB-S tuner module. Say Y when you want to support this frontend. 44 A DVB-S tuner module. Say Y when you want to support this frontend.
30 45
31config DVB_MT312 46config DVB_MT312
32 tristate "Zarlink VP310/MT312 based" 47 tristate "Zarlink VP310/MT312 based"
33 depends on DVB_CORE && I2C 48 depends on DVB_CORE && I2C
49 default m if DVB_FE_CUSTOMISE
34 help 50 help
35 A DVB-S tuner module. Say Y when you want to support this frontend. 51 A DVB-S tuner module. Say Y when you want to support this frontend.
36 52
37config DVB_VES1X93 53config DVB_VES1X93
38 tristate "VLSI VES1893 or VES1993 based" 54 tristate "VLSI VES1893 or VES1993 based"
39 depends on DVB_CORE && I2C 55 depends on DVB_CORE && I2C
56 default m if DVB_FE_CUSTOMISE
40 help 57 help
41 A DVB-S tuner module. Say Y when you want to support this frontend. 58 A DVB-S tuner module. Say Y when you want to support this frontend.
42 59
43config DVB_S5H1420 60config DVB_S5H1420
44 tristate "Samsung S5H1420 based" 61 tristate "Samsung S5H1420 based"
45 depends on DVB_CORE && I2C 62 depends on DVB_CORE && I2C
63 default m if DVB_FE_CUSTOMISE
64 help
65 A DVB-S tuner module. Say Y when you want to support this frontend.
66
67config DVB_TDA10086
68 tristate "Philips TDA10086 based"
69 depends on DVB_CORE && I2C
70 default m if DVB_FE_CUSTOMISE
46 help 71 help
47 A DVB-S tuner module. Say Y when you want to support this frontend. 72 A DVB-S tuner module. Say Y when you want to support this frontend.
48 73
@@ -52,6 +77,7 @@ comment "DVB-T (terrestrial) frontends"
52config DVB_SP8870 77config DVB_SP8870
53 tristate "Spase sp8870 based" 78 tristate "Spase sp8870 based"
54 depends on DVB_CORE && I2C 79 depends on DVB_CORE && I2C
80 default m if DVB_FE_CUSTOMISE
55 select FW_LOADER 81 select FW_LOADER
56 help 82 help
57 A DVB-T tuner module. Say Y when you want to support this frontend. 83 A DVB-T tuner module. Say Y when you want to support this frontend.
@@ -64,6 +90,7 @@ config DVB_SP8870
64config DVB_SP887X 90config DVB_SP887X
65 tristate "Spase sp887x based" 91 tristate "Spase sp887x based"
66 depends on DVB_CORE && I2C 92 depends on DVB_CORE && I2C
93 default m if DVB_FE_CUSTOMISE
67 select FW_LOADER 94 select FW_LOADER
68 help 95 help
69 A DVB-T tuner module. Say Y when you want to support this frontend. 96 A DVB-T tuner module. Say Y when you want to support this frontend.
@@ -76,24 +103,28 @@ config DVB_SP887X
76config DVB_CX22700 103config DVB_CX22700
77 tristate "Conexant CX22700 based" 104 tristate "Conexant CX22700 based"
78 depends on DVB_CORE && I2C 105 depends on DVB_CORE && I2C
106 default m if DVB_FE_CUSTOMISE
79 help 107 help
80 A DVB-T tuner module. Say Y when you want to support this frontend. 108 A DVB-T tuner module. Say Y when you want to support this frontend.
81 109
82config DVB_CX22702 110config DVB_CX22702
83 tristate "Conexant cx22702 demodulator (OFDM)" 111 tristate "Conexant cx22702 demodulator (OFDM)"
84 depends on DVB_CORE && I2C 112 depends on DVB_CORE && I2C
113 default m if DVB_FE_CUSTOMISE
85 help 114 help
86 A DVB-T tuner module. Say Y when you want to support this frontend. 115 A DVB-T tuner module. Say Y when you want to support this frontend.
87 116
88config DVB_L64781 117config DVB_L64781
89 tristate "LSI L64781" 118 tristate "LSI L64781"
90 depends on DVB_CORE && I2C 119 depends on DVB_CORE && I2C
120 default m if DVB_FE_CUSTOMISE
91 help 121 help
92 A DVB-T tuner module. Say Y when you want to support this frontend. 122 A DVB-T tuner module. Say Y when you want to support this frontend.
93 123
94config DVB_TDA1004X 124config DVB_TDA1004X
95 tristate "Philips TDA10045H/TDA10046H based" 125 tristate "Philips TDA10045H/TDA10046H based"
96 depends on DVB_CORE && I2C 126 depends on DVB_CORE && I2C
127 default m if DVB_FE_CUSTOMISE
97 select FW_LOADER 128 select FW_LOADER
98 help 129 help
99 A DVB-T tuner module. Say Y when you want to support this frontend. 130 A DVB-T tuner module. Say Y when you want to support this frontend.
@@ -107,24 +138,28 @@ config DVB_TDA1004X
107config DVB_NXT6000 138config DVB_NXT6000
108 tristate "NxtWave Communications NXT6000 based" 139 tristate "NxtWave Communications NXT6000 based"
109 depends on DVB_CORE && I2C 140 depends on DVB_CORE && I2C
141 default m if DVB_FE_CUSTOMISE
110 help 142 help
111 A DVB-T tuner module. Say Y when you want to support this frontend. 143 A DVB-T tuner module. Say Y when you want to support this frontend.
112 144
113config DVB_MT352 145config DVB_MT352
114 tristate "Zarlink MT352 based" 146 tristate "Zarlink MT352 based"
115 depends on DVB_CORE && I2C 147 depends on DVB_CORE && I2C
148 default m if DVB_FE_CUSTOMISE
116 help 149 help
117 A DVB-T tuner module. Say Y when you want to support this frontend. 150 A DVB-T tuner module. Say Y when you want to support this frontend.
118 151
119config DVB_ZL10353 152config DVB_ZL10353
120 tristate "Zarlink ZL10353 based" 153 tristate "Zarlink ZL10353 based"
121 depends on DVB_CORE && I2C 154 depends on DVB_CORE && I2C
155 default m if DVB_FE_CUSTOMISE
122 help 156 help
123 A DVB-T tuner module. Say Y when you want to support this frontend. 157 A DVB-T tuner module. Say Y when you want to support this frontend.
124 158
125config DVB_DIB3000MB 159config DVB_DIB3000MB
126 tristate "DiBcom 3000M-B" 160 tristate "DiBcom 3000M-B"
127 depends on DVB_CORE && I2C 161 depends on DVB_CORE && I2C
162 default m if DVB_FE_CUSTOMISE
128 help 163 help
129 A DVB-T tuner module. Designed for mobile usage. Say Y when you want 164 A DVB-T tuner module. Designed for mobile usage. Say Y when you want
130 to support this frontend. 165 to support this frontend.
@@ -132,6 +167,7 @@ config DVB_DIB3000MB
132config DVB_DIB3000MC 167config DVB_DIB3000MC
133 tristate "DiBcom 3000P/M-C" 168 tristate "DiBcom 3000P/M-C"
134 depends on DVB_CORE && I2C 169 depends on DVB_CORE && I2C
170 default m if DVB_FE_CUSTOMISE
135 help 171 help
136 A DVB-T tuner module. Designed for mobile usage. Say Y when you want 172 A DVB-T tuner module. Designed for mobile usage. Say Y when you want
137 to support this frontend. 173 to support this frontend.
@@ -142,18 +178,21 @@ comment "DVB-C (cable) frontends"
142config DVB_VES1820 178config DVB_VES1820
143 tristate "VLSI VES1820 based" 179 tristate "VLSI VES1820 based"
144 depends on DVB_CORE && I2C 180 depends on DVB_CORE && I2C
181 default m if DVB_FE_CUSTOMISE
145 help 182 help
146 A DVB-C tuner module. Say Y when you want to support this frontend. 183 A DVB-C tuner module. Say Y when you want to support this frontend.
147 184
148config DVB_TDA10021 185config DVB_TDA10021
149 tristate "Philips TDA10021 based" 186 tristate "Philips TDA10021 based"
150 depends on DVB_CORE && I2C 187 depends on DVB_CORE && I2C
188 default m if DVB_FE_CUSTOMISE
151 help 189 help
152 A DVB-C tuner module. Say Y when you want to support this frontend. 190 A DVB-C tuner module. Say Y when you want to support this frontend.
153 191
154config DVB_STV0297 192config DVB_STV0297
155 tristate "ST STV0297 based" 193 tristate "ST STV0297 based"
156 depends on DVB_CORE && I2C 194 depends on DVB_CORE && I2C
195 default m if DVB_FE_CUSTOMISE
157 help 196 help
158 A DVB-C tuner module. Say Y when you want to support this frontend. 197 A DVB-C tuner module. Say Y when you want to support this frontend.
159 198
@@ -163,6 +202,7 @@ comment "ATSC (North American/Korean Terrestrial/Cable DTV) frontends"
163config DVB_NXT200X 202config DVB_NXT200X
164 tristate "NxtWave Communications NXT2002/NXT2004 based" 203 tristate "NxtWave Communications NXT2002/NXT2004 based"
165 depends on DVB_CORE && I2C 204 depends on DVB_CORE && I2C
205 default m if DVB_FE_CUSTOMISE
166 select FW_LOADER 206 select FW_LOADER
167 help 207 help
168 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want 208 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
@@ -177,6 +217,7 @@ config DVB_NXT200X
177config DVB_OR51211 217config DVB_OR51211
178 tristate "Oren OR51211 based" 218 tristate "Oren OR51211 based"
179 depends on DVB_CORE && I2C 219 depends on DVB_CORE && I2C
220 default m if DVB_FE_CUSTOMISE
180 select FW_LOADER 221 select FW_LOADER
181 help 222 help
182 An ATSC 8VSB tuner module. Say Y when you want to support this frontend. 223 An ATSC 8VSB tuner module. Say Y when you want to support this frontend.
@@ -189,6 +230,7 @@ config DVB_OR51211
189config DVB_OR51132 230config DVB_OR51132
190 tristate "Oren OR51132 based" 231 tristate "Oren OR51132 based"
191 depends on DVB_CORE && I2C 232 depends on DVB_CORE && I2C
233 default m if DVB_FE_CUSTOMISE
192 select FW_LOADER 234 select FW_LOADER
193 help 235 help
194 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want 236 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
@@ -204,6 +246,7 @@ config DVB_OR51132
204config DVB_BCM3510 246config DVB_BCM3510
205 tristate "Broadcom BCM3510" 247 tristate "Broadcom BCM3510"
206 depends on DVB_CORE && I2C 248 depends on DVB_CORE && I2C
249 default m if DVB_FE_CUSTOMISE
207 select FW_LOADER 250 select FW_LOADER
208 help 251 help
209 An ATSC 8VSB/16VSB and QAM64/256 tuner module. Say Y when you want to 252 An ATSC 8VSB/16VSB and QAM64/256 tuner module. Say Y when you want to
@@ -212,28 +255,52 @@ config DVB_BCM3510
212config DVB_LGDT330X 255config DVB_LGDT330X
213 tristate "LG Electronics LGDT3302/LGDT3303 based" 256 tristate "LG Electronics LGDT3302/LGDT3303 based"
214 depends on DVB_CORE && I2C 257 depends on DVB_CORE && I2C
258 default m if DVB_FE_CUSTOMISE
215 help 259 help
216 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want 260 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
217 to support this frontend. 261 to support this frontend.
218 262
219 263comment "Tuners/PLL support"
220comment "Miscellaneous devices"
221 depends on DVB_CORE 264 depends on DVB_CORE
222 265
223config DVB_PLL 266config DVB_PLL
224 tristate 267 tristate
225 depends on DVB_CORE && I2C 268 depends on DVB_CORE && I2C
226 269
270config DVB_TDA826X
271 tristate "Philips TDA826X silicon tuner"
272 depends on DVB_CORE && I2C
273 default m if DVB_FE_CUSTOMISE
274 help
275 A DVB-S silicon tuner module. Say Y when you want to support this tuner.
276
277config DVB_TUNER_MT2060
278 tristate "Microtune MT2060 silicon IF tuner"
279 help
280 A driver for the silicon IF tuner MT2060 from Microtune.
281
282comment "Miscellaneous devices"
283 depends on DVB_CORE
284
227config DVB_LNBP21 285config DVB_LNBP21
228 tristate "LNBP21 SEC controller" 286 tristate "LNBP21 SEC controller"
229 depends on DVB_CORE && I2C 287 depends on DVB_CORE && I2C
288 default m if DVB_FE_CUSTOMISE
230 help 289 help
231 An SEC control chip. 290 An SEC control chip.
232 291
233config DVB_ISL6421 292config DVB_ISL6421
234 tristate "ISL6421 SEC controller" 293 tristate "ISL6421 SEC controller"
235 depends on DVB_CORE && I2C 294 depends on DVB_CORE && I2C
295 default m if DVB_FE_CUSTOMISE
236 help 296 help
237 An SEC control chip. 297 An SEC control chip.
238 298
299config DVB_TUA6100
300 tristate "TUA6100 PLL"
301 depends on DVB_CORE && I2C
302 default m if DVB_FE_CUSTOMISE
303 help
304 A DVBS PLL chip.
305
239endmenu 306endmenu
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index 0e4880b6db14..dce9cf0c75c0 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -11,8 +11,8 @@ obj-$(CONFIG_DVB_CX22700) += cx22700.o
11obj-$(CONFIG_DVB_CX24110) += cx24110.o 11obj-$(CONFIG_DVB_CX24110) += cx24110.o
12obj-$(CONFIG_DVB_TDA8083) += tda8083.o 12obj-$(CONFIG_DVB_TDA8083) += tda8083.o
13obj-$(CONFIG_DVB_L64781) += l64781.o 13obj-$(CONFIG_DVB_L64781) += l64781.o
14obj-$(CONFIG_DVB_DIB3000MB) += dib3000mb.o dib3000-common.o 14obj-$(CONFIG_DVB_DIB3000MB) += dib3000mb.o
15obj-$(CONFIG_DVB_DIB3000MC) += dib3000mc.o dib3000-common.o 15obj-$(CONFIG_DVB_DIB3000MC) += dib3000mc.o dibx000_common.o
16obj-$(CONFIG_DVB_MT312) += mt312.o 16obj-$(CONFIG_DVB_MT312) += mt312.o
17obj-$(CONFIG_DVB_VES1820) += ves1820.o 17obj-$(CONFIG_DVB_VES1820) += ves1820.o
18obj-$(CONFIG_DVB_VES1X93) += ves1x93.o 18obj-$(CONFIG_DVB_VES1X93) += ves1x93.o
@@ -33,3 +33,7 @@ obj-$(CONFIG_DVB_LGDT330X) += lgdt330x.o
33obj-$(CONFIG_DVB_CX24123) += cx24123.o 33obj-$(CONFIG_DVB_CX24123) += cx24123.o
34obj-$(CONFIG_DVB_LNBP21) += lnbp21.o 34obj-$(CONFIG_DVB_LNBP21) += lnbp21.o
35obj-$(CONFIG_DVB_ISL6421) += isl6421.o 35obj-$(CONFIG_DVB_ISL6421) += isl6421.o
36obj-$(CONFIG_DVB_TDA10086) += tda10086.o
37obj-$(CONFIG_DVB_TDA826X) += tda826x.o
38obj-$(CONFIG_DVB_TUNER_MT2060) += mt2060.o
39obj-$(CONFIG_DVB_TUA6100) += tua6100.o
diff --git a/drivers/media/dvb/frontends/bcm3510.h b/drivers/media/dvb/frontends/bcm3510.h
index 80f5d0953d02..6dfa839a7022 100644
--- a/drivers/media/dvb/frontends/bcm3510.h
+++ b/drivers/media/dvb/frontends/bcm3510.h
@@ -34,7 +34,16 @@ struct bcm3510_config
34 int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name); 34 int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name);
35}; 35};
36 36
37#if defined(CONFIG_DVB_BCM3510) || defined(CONFIG_DVB_BCM3510_MODULE)
37extern struct dvb_frontend* bcm3510_attach(const struct bcm3510_config* config, 38extern struct dvb_frontend* bcm3510_attach(const struct bcm3510_config* config,
38 struct i2c_adapter* i2c); 39 struct i2c_adapter* i2c);
40#else
41static inline struct dvb_frontend* bcm3510_attach(const struct bcm3510_config* config,
42 struct i2c_adapter* i2c)
43{
44 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
45 return NULL;
46}
47#endif // CONFIG_DVB_BCM3510
39 48
40#endif 49#endif
diff --git a/drivers/media/dvb/frontends/cx22700.h b/drivers/media/dvb/frontends/cx22700.h
index dcd8979c1a15..10286cc29fb4 100644
--- a/drivers/media/dvb/frontends/cx22700.h
+++ b/drivers/media/dvb/frontends/cx22700.h
@@ -31,7 +31,16 @@ struct cx22700_config
31 u8 demod_address; 31 u8 demod_address;
32}; 32};
33 33
34#if defined(CONFIG_DVB_CX22700) || defined(CONFIG_DVB_CX22700_MODULE)
34extern struct dvb_frontend* cx22700_attach(const struct cx22700_config* config, 35extern struct dvb_frontend* cx22700_attach(const struct cx22700_config* config,
35 struct i2c_adapter* i2c); 36 struct i2c_adapter* i2c);
37#else
38static inline struct dvb_frontend* cx22700_attach(const struct cx22700_config* config,
39 struct i2c_adapter* i2c)
40{
41 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
42 return NULL;
43}
44#endif // CONFIG_DVB_CX22700
36 45
37#endif // CX22700_H 46#endif // CX22700_H
diff --git a/drivers/media/dvb/frontends/cx22702.c b/drivers/media/dvb/frontends/cx22702.c
index 4106d46c957f..335219ebce2d 100644
--- a/drivers/media/dvb/frontends/cx22702.c
+++ b/drivers/media/dvb/frontends/cx22702.c
@@ -399,7 +399,9 @@ static int cx22702_read_signal_strength(struct dvb_frontend* fe, u16* signal_str
399{ 399{
400 struct cx22702_state* state = fe->demodulator_priv; 400 struct cx22702_state* state = fe->demodulator_priv;
401 401
402 *signal_strength = cx22702_readreg (state, 0x23); 402 u16 rs_ber = 0;
403 rs_ber = cx22702_readreg (state, 0x23);
404 *signal_strength = (rs_ber << 8) | rs_ber;
403 405
404 return 0; 406 return 0;
405} 407}
diff --git a/drivers/media/dvb/frontends/cx22702.h b/drivers/media/dvb/frontends/cx22702.h
index 7f2f241e5d44..bc217ddf02c0 100644
--- a/drivers/media/dvb/frontends/cx22702.h
+++ b/drivers/media/dvb/frontends/cx22702.h
@@ -41,7 +41,16 @@ struct cx22702_config
41 u8 output_mode; 41 u8 output_mode;
42}; 42};
43 43
44#if defined(CONFIG_DVB_CX22702) || defined(CONFIG_DVB_CX22702_MODULE)
44extern struct dvb_frontend* cx22702_attach(const struct cx22702_config* config, 45extern struct dvb_frontend* cx22702_attach(const struct cx22702_config* config,
45 struct i2c_adapter* i2c); 46 struct i2c_adapter* i2c);
47#else
48static inline struct dvb_frontend* cx22702_attach(const struct cx22702_config* config,
49 struct i2c_adapter* i2c)
50{
51 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
52 return NULL;
53}
54#endif // CONFIG_DVB_CX22702
46 55
47#endif // CX22702_H 56#endif // CX22702_H
diff --git a/drivers/media/dvb/frontends/cx24110.c b/drivers/media/dvb/frontends/cx24110.c
index ce3c7398bac9..ae96395217a2 100644
--- a/drivers/media/dvb/frontends/cx24110.c
+++ b/drivers/media/dvb/frontends/cx24110.c
@@ -1,4 +1,4 @@
1/* 1 /*
2 cx24110 - Single Chip Satellite Channel Receiver driver module 2 cx24110 - Single Chip Satellite Channel Receiver driver module
3 3
4 Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@htp-tel.de> based on 4 Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@htp-tel.de> based on
@@ -311,16 +311,17 @@ static int cx24110_set_symbolrate (struct cx24110_state* state, u32 srate)
311 311
312} 312}
313 313
314int cx24110_pll_write (struct dvb_frontend* fe, u32 data) 314static int _cx24110_pll_write (struct dvb_frontend* fe, u8 *buf, int len)
315{ 315{
316 struct cx24110_state *state = fe->demodulator_priv; 316 struct cx24110_state *state = fe->demodulator_priv;
317 317
318 if (len != 3)
319 return -EINVAL;
320
318/* tuner data is 21 bits long, must be left-aligned in data */ 321/* tuner data is 21 bits long, must be left-aligned in data */
319/* tuner cx24108 is written through a dedicated 3wire interface on the demod chip */ 322/* tuner cx24108 is written through a dedicated 3wire interface on the demod chip */
320/* FIXME (low): add error handling, avoid infinite loops if HW fails... */ 323/* FIXME (low): add error handling, avoid infinite loops if HW fails... */
321 324
322 dprintk("cx24110 debug: cx24108_write(%8.8x)\n",data);
323
324 cx24110_writereg(state,0x6d,0x30); /* auto mode at 62kHz */ 325 cx24110_writereg(state,0x6d,0x30); /* auto mode at 62kHz */
325 cx24110_writereg(state,0x70,0x15); /* auto mode 21 bits */ 326 cx24110_writereg(state,0x70,0x15); /* auto mode 21 bits */
326 327
@@ -329,19 +330,19 @@ int cx24110_pll_write (struct dvb_frontend* fe, u32 data)
329 cx24110_writereg(state,0x72,0); 330 cx24110_writereg(state,0x72,0);
330 331
331 /* write the topmost 8 bits */ 332 /* write the topmost 8 bits */
332 cx24110_writereg(state,0x72,(data>>24)&0xff); 333 cx24110_writereg(state,0x72,buf[0]);
333 334
334 /* wait for the send to be completed */ 335 /* wait for the send to be completed */
335 while ((cx24110_readreg(state,0x6d)&0xc0)==0x80) 336 while ((cx24110_readreg(state,0x6d)&0xc0)==0x80)
336 ; 337 ;
337 338
338 /* send another 8 bytes */ 339 /* send another 8 bytes */
339 cx24110_writereg(state,0x72,(data>>16)&0xff); 340 cx24110_writereg(state,0x72,buf[1]);
340 while ((cx24110_readreg(state,0x6d)&0xc0)==0x80) 341 while ((cx24110_readreg(state,0x6d)&0xc0)==0x80)
341 ; 342 ;
342 343
343 /* and the topmost 5 bits of this byte */ 344 /* and the topmost 5 bits of this byte */
344 cx24110_writereg(state,0x72,(data>>8)&0xff); 345 cx24110_writereg(state,0x72,buf[2]);
345 while ((cx24110_readreg(state,0x6d)&0xc0)==0x80) 346 while ((cx24110_readreg(state,0x6d)&0xc0)==0x80)
346 ; 347 ;
347 348
@@ -642,6 +643,7 @@ static struct dvb_frontend_ops cx24110_ops = {
642 .release = cx24110_release, 643 .release = cx24110_release,
643 644
644 .init = cx24110_initfe, 645 .init = cx24110_initfe,
646 .write = _cx24110_pll_write,
645 .set_frontend = cx24110_set_frontend, 647 .set_frontend = cx24110_set_frontend,
646 .get_frontend = cx24110_get_frontend, 648 .get_frontend = cx24110_get_frontend,
647 .read_status = cx24110_read_status, 649 .read_status = cx24110_read_status,
@@ -664,4 +666,3 @@ MODULE_AUTHOR("Peter Hettkamp");
664MODULE_LICENSE("GPL"); 666MODULE_LICENSE("GPL");
665 667
666EXPORT_SYMBOL(cx24110_attach); 668EXPORT_SYMBOL(cx24110_attach);
667EXPORT_SYMBOL(cx24110_pll_write);
diff --git a/drivers/media/dvb/frontends/cx24110.h b/drivers/media/dvb/frontends/cx24110.h
index b354a64e0e74..c9d5ae250ebb 100644
--- a/drivers/media/dvb/frontends/cx24110.h
+++ b/drivers/media/dvb/frontends/cx24110.h
@@ -33,9 +33,24 @@ struct cx24110_config
33 u8 demod_address; 33 u8 demod_address;
34}; 34};
35 35
36static inline int cx24110_pll_write(struct dvb_frontend *fe, u32 val) {
37 int r = 0;
38 u8 buf[] = {(u8) (val>>24), (u8) (val>>16), (u8) (val>>8)};
39 if (fe->ops.write)
40 r = fe->ops.write(fe, buf, 3);
41 return r;
42}
43
44#if defined(CONFIG_DVB_CX24110) || defined(CONFIG_DVB_CX24110_MODULE)
36extern struct dvb_frontend* cx24110_attach(const struct cx24110_config* config, 45extern struct dvb_frontend* cx24110_attach(const struct cx24110_config* config,
37 struct i2c_adapter* i2c); 46 struct i2c_adapter* i2c);
38 47#else
39extern int cx24110_pll_write(struct dvb_frontend* fe, u32 data); 48static inline struct dvb_frontend* cx24110_attach(const struct cx24110_config* config,
49 struct i2c_adapter* i2c)
50{
51 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
52 return NULL;
53}
54#endif // CONFIG_DVB_CX24110
40 55
41#endif // CX24110_H 56#endif // CX24110_H
diff --git a/drivers/media/dvb/frontends/cx24123.c b/drivers/media/dvb/frontends/cx24123.c
index 274a87b7a5d5..62d69a6ea699 100644
--- a/drivers/media/dvb/frontends/cx24123.c
+++ b/drivers/media/dvb/frontends/cx24123.c
@@ -45,9 +45,6 @@ struct cx24123_state
45 45
46 struct dvb_frontend frontend; 46 struct dvb_frontend frontend;
47 47
48 u32 lastber;
49 u16 snr;
50
51 /* Some PLL specifics for tuning */ 48 /* Some PLL specifics for tuning */
52 u32 VCAarg; 49 u32 VCAarg;
53 u32 VGAarg; 50 u32 VGAarg;
@@ -194,7 +191,7 @@ static struct {
194 {0x06, 0x31}, /* MPEG (default) */ 191 {0x06, 0x31}, /* MPEG (default) */
195 {0x0b, 0x00}, /* Freq search start point (default) */ 192 {0x0b, 0x00}, /* Freq search start point (default) */
196 {0x0c, 0x00}, /* Demodulator sample gain (default) */ 193 {0x0c, 0x00}, /* Demodulator sample gain (default) */
197 {0x0d, 0x02}, /* Frequency search range = Fsymbol / 4 (default) */ 194 {0x0d, 0x7f}, /* Force driver to shift until the maximum (+-10 MHz) */
198 {0x0e, 0x03}, /* Default non-inverted, FEC 3/4 (default) */ 195 {0x0e, 0x03}, /* Default non-inverted, FEC 3/4 (default) */
199 {0x0f, 0xfe}, /* FEC search mask (all supported codes) */ 196 {0x0f, 0xfe}, /* FEC search mask (all supported codes) */
200 {0x10, 0x01}, /* Default search inversion, no repeat (default) */ 197 {0x10, 0x01}, /* Default search inversion, no repeat (default) */
@@ -223,8 +220,9 @@ static struct {
223 {0x44, 0x00}, /* Constellation (default) */ 220 {0x44, 0x00}, /* Constellation (default) */
224 {0x45, 0x00}, /* Symbol count (default) */ 221 {0x45, 0x00}, /* Symbol count (default) */
225 {0x46, 0x0d}, /* Symbol rate estimator on (default) */ 222 {0x46, 0x0d}, /* Symbol rate estimator on (default) */
226 {0x56, 0x41}, /* Various (default) */ 223 {0x56, 0xc1}, /* Error Counter = Viterbi BER */
227 {0x57, 0xff}, /* Error Counter Window (default) */ 224 {0x57, 0xff}, /* Error Counter Window (default) */
225 {0x5c, 0x20}, /* Acquisition AFC Expiration window (default is 0x10) */
228 {0x67, 0x83}, /* Non-DCII symbol clock */ 226 {0x67, 0x83}, /* Non-DCII symbol clock */
229}; 227};
230 228
@@ -321,6 +319,12 @@ static int cx24123_set_fec(struct cx24123_state* state, fe_code_rate_t fec)
321 if ( (fec < FEC_NONE) || (fec > FEC_AUTO) ) 319 if ( (fec < FEC_NONE) || (fec > FEC_AUTO) )
322 fec = FEC_AUTO; 320 fec = FEC_AUTO;
323 321
322 /* Set the soft decision threshold */
323 if(fec == FEC_1_2)
324 cx24123_writereg(state, 0x43, cx24123_readreg(state, 0x43) | 0x01);
325 else
326 cx24123_writereg(state, 0x43, cx24123_readreg(state, 0x43) & ~0x01);
327
324 switch (fec) { 328 switch (fec) {
325 case FEC_1_2: 329 case FEC_1_2:
326 dprintk("%s: set FEC to 1/2\n",__FUNCTION__); 330 dprintk("%s: set FEC to 1/2\n",__FUNCTION__);
@@ -657,6 +661,10 @@ static int cx24123_initfe(struct dvb_frontend* fe)
657 for (i = 0; i < sizeof(cx24123_regdata) / sizeof(cx24123_regdata[0]); i++) 661 for (i = 0; i < sizeof(cx24123_regdata) / sizeof(cx24123_regdata[0]); i++)
658 cx24123_writereg(state, cx24123_regdata[i].reg, cx24123_regdata[i].data); 662 cx24123_writereg(state, cx24123_regdata[i].reg, cx24123_regdata[i].data);
659 663
664 /* Set the LNB polarity */
665 if(state->config->lnb_polarity)
666 cx24123_writereg(state, 0x32, cx24123_readreg(state, 0x32) | 0x02);
667
660 return 0; 668 return 0;
661} 669}
662 670
@@ -674,6 +682,9 @@ static int cx24123_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage
674 case SEC_VOLTAGE_18: 682 case SEC_VOLTAGE_18:
675 dprintk("%s: setting voltage 18V\n", __FUNCTION__); 683 dprintk("%s: setting voltage 18V\n", __FUNCTION__);
676 return cx24123_writereg(state, 0x29, val | 0x80); 684 return cx24123_writereg(state, 0x29, val | 0x80);
685 case SEC_VOLTAGE_OFF:
686 /* already handled in cx88-dvb */
687 return 0;
677 default: 688 default:
678 return -EINVAL; 689 return -EINVAL;
679 }; 690 };
@@ -776,13 +787,15 @@ static int cx24123_read_status(struct dvb_frontend* fe, fe_status_t* status)
776 if (lock & 0x01) 787 if (lock & 0x01)
777 *status |= FE_HAS_SIGNAL; 788 *status |= FE_HAS_SIGNAL;
778 if (sync & 0x02) 789 if (sync & 0x02)
779 *status |= FE_HAS_CARRIER; 790 *status |= FE_HAS_CARRIER; /* Phase locked */
780 if (sync & 0x04) 791 if (sync & 0x04)
781 *status |= FE_HAS_VITERBI; 792 *status |= FE_HAS_VITERBI;
793
794 /* Reed-Solomon Status */
782 if (sync & 0x08) 795 if (sync & 0x08)
783 *status |= FE_HAS_SYNC; 796 *status |= FE_HAS_SYNC;
784 if (sync & 0x80) 797 if (sync & 0x80)
785 *status |= FE_HAS_LOCK; 798 *status |= FE_HAS_LOCK; /*Full Sync */
786 799
787 return 0; 800 return 0;
788} 801}
@@ -795,29 +808,13 @@ static int cx24123_read_ber(struct dvb_frontend* fe, u32* ber)
795{ 808{
796 struct cx24123_state *state = fe->demodulator_priv; 809 struct cx24123_state *state = fe->demodulator_priv;
797 810
798 state->lastber = 811 /* The true bit error rate is this value divided by
799 ((cx24123_readreg(state, 0x1c) & 0x3f) << 16) | 812 the window size (set as 256 * 255) */
813 *ber = ((cx24123_readreg(state, 0x1c) & 0x3f) << 16) |
800 (cx24123_readreg(state, 0x1d) << 8 | 814 (cx24123_readreg(state, 0x1d) << 8 |
801 cx24123_readreg(state, 0x1e)); 815 cx24123_readreg(state, 0x1e));
802
803 /* Do the signal quality processing here, it's derived from the BER. */
804 /* Scale the BER from a 24bit to a SNR 16 bit where higher = better */
805 if (state->lastber < 5000)
806 state->snr = 655*100;
807 else if ( (state->lastber >= 5000) && (state->lastber < 55000) )
808 state->snr = 655*90;
809 else if ( (state->lastber >= 55000) && (state->lastber < 150000) )
810 state->snr = 655*80;
811 else if ( (state->lastber >= 150000) && (state->lastber < 250000) )
812 state->snr = 655*70;
813 else if ( (state->lastber >= 250000) && (state->lastber < 450000) )
814 state->snr = 655*65;
815 else
816 state->snr = 0;
817
818 dprintk("%s: BER = %d, S/N index = %d\n",__FUNCTION__,state->lastber, state->snr);
819 816
820 *ber = state->lastber; 817 dprintk("%s: BER = %d\n",__FUNCTION__,*ber);
821 818
822 return 0; 819 return 0;
823} 820}
@@ -825,6 +822,7 @@ static int cx24123_read_ber(struct dvb_frontend* fe, u32* ber)
825static int cx24123_read_signal_strength(struct dvb_frontend* fe, u16* signal_strength) 822static int cx24123_read_signal_strength(struct dvb_frontend* fe, u16* signal_strength)
826{ 823{
827 struct cx24123_state *state = fe->demodulator_priv; 824 struct cx24123_state *state = fe->demodulator_priv;
825
828 *signal_strength = cx24123_readreg(state, 0x3b) << 8; /* larger = better */ 826 *signal_strength = cx24123_readreg(state, 0x3b) << 8; /* larger = better */
829 827
830 dprintk("%s: Signal strength = %d\n",__FUNCTION__,*signal_strength); 828 dprintk("%s: Signal strength = %d\n",__FUNCTION__,*signal_strength);
@@ -835,19 +833,13 @@ static int cx24123_read_signal_strength(struct dvb_frontend* fe, u16* signal_str
835static int cx24123_read_snr(struct dvb_frontend* fe, u16* snr) 833static int cx24123_read_snr(struct dvb_frontend* fe, u16* snr)
836{ 834{
837 struct cx24123_state *state = fe->demodulator_priv; 835 struct cx24123_state *state = fe->demodulator_priv;
838 *snr = state->snr;
839
840 dprintk("%s: read S/N index = %d\n",__FUNCTION__,*snr);
841 836
842 return 0; 837 /* Inverted raw Es/N0 count, totally bogus but better than the
843} 838 BER threshold. */
839 *snr = 65535 - (((u16)cx24123_readreg(state, 0x18) << 8) |
840 (u16)cx24123_readreg(state, 0x19));
844 841
845static int cx24123_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) 842 dprintk("%s: read S/N index = %d\n",__FUNCTION__,*snr);
846{
847 struct cx24123_state *state = fe->demodulator_priv;
848 *ucblocks = state->lastber;
849
850 dprintk("%s: ucblocks (ber) = %d\n",__FUNCTION__,*ucblocks);
851 843
852 return 0; 844 return 0;
853} 845}
@@ -922,6 +914,29 @@ static int cx24123_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
922 return 0; 914 return 0;
923} 915}
924 916
917static int cx24123_tune(struct dvb_frontend* fe,
918 struct dvb_frontend_parameters* params,
919 unsigned int mode_flags,
920 int *delay,
921 fe_status_t *status)
922{
923 int retval = 0;
924
925 if (params != NULL)
926 retval = cx24123_set_frontend(fe, params);
927
928 if (!(mode_flags & FE_TUNE_MODE_ONESHOT))
929 cx24123_read_status(fe, status);
930 *delay = HZ/10;
931
932 return retval;
933}
934
935static int cx24123_get_algo(struct dvb_frontend *fe)
936{
937 return 1; //FE_ALGO_HW
938}
939
925static void cx24123_release(struct dvb_frontend* fe) 940static void cx24123_release(struct dvb_frontend* fe)
926{ 941{
927 struct cx24123_state* state = fe->demodulator_priv; 942 struct cx24123_state* state = fe->demodulator_priv;
@@ -949,8 +964,6 @@ struct dvb_frontend* cx24123_attach(const struct cx24123_config* config,
949 /* setup the state */ 964 /* setup the state */
950 state->config = config; 965 state->config = config;
951 state->i2c = i2c; 966 state->i2c = i2c;
952 state->lastber = 0;
953 state->snr = 0;
954 state->VCAarg = 0; 967 state->VCAarg = 0;
955 state->VGAarg = 0; 968 state->VGAarg = 0;
956 state->bandselectarg = 0; 969 state->bandselectarg = 0;
@@ -1003,11 +1016,12 @@ static struct dvb_frontend_ops cx24123_ops = {
1003 .read_ber = cx24123_read_ber, 1016 .read_ber = cx24123_read_ber,
1004 .read_signal_strength = cx24123_read_signal_strength, 1017 .read_signal_strength = cx24123_read_signal_strength,
1005 .read_snr = cx24123_read_snr, 1018 .read_snr = cx24123_read_snr,
1006 .read_ucblocks = cx24123_read_ucblocks,
1007 .diseqc_send_master_cmd = cx24123_send_diseqc_msg, 1019 .diseqc_send_master_cmd = cx24123_send_diseqc_msg,
1008 .diseqc_send_burst = cx24123_diseqc_send_burst, 1020 .diseqc_send_burst = cx24123_diseqc_send_burst,
1009 .set_tone = cx24123_set_tone, 1021 .set_tone = cx24123_set_tone,
1010 .set_voltage = cx24123_set_voltage, 1022 .set_voltage = cx24123_set_voltage,
1023 .tune = cx24123_tune,
1024 .get_frontend_algo = cx24123_get_algo,
1011}; 1025};
1012 1026
1013module_param(debug, int, 0644); 1027module_param(debug, int, 0644);
diff --git a/drivers/media/dvb/frontends/cx24123.h b/drivers/media/dvb/frontends/cx24123.h
index 9606f825935c..57a1dae1dc40 100644
--- a/drivers/media/dvb/frontends/cx24123.h
+++ b/drivers/media/dvb/frontends/cx24123.h
@@ -30,9 +30,21 @@ struct cx24123_config
30 30
31 /* Need to set device param for start_dma */ 31 /* Need to set device param for start_dma */
32 int (*set_ts_params)(struct dvb_frontend* fe, int is_punctured); 32 int (*set_ts_params)(struct dvb_frontend* fe, int is_punctured);
33
34 /* 0 = LNB voltage normal, 1 = LNB voltage inverted */
35 int lnb_polarity;
33}; 36};
34 37
38#if defined(CONFIG_DVB_CX24123) || defined(CONFIG_DVB_CX24123_MODULE)
35extern struct dvb_frontend* cx24123_attach(const struct cx24123_config* config, 39extern struct dvb_frontend* cx24123_attach(const struct cx24123_config* config,
36 struct i2c_adapter* i2c); 40 struct i2c_adapter* i2c);
41#else
42static inline struct dvb_frontend* cx24123_attach(const struct cx24123_config* config,
43 struct i2c_adapter* i2c)
44{
45 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
46 return NULL;
47}
48#endif // CONFIG_DVB_CX24123
37 49
38#endif /* CX24123_H */ 50#endif /* CX24123_H */
diff --git a/drivers/media/dvb/frontends/dib3000-common.c b/drivers/media/dvb/frontends/dib3000-common.c
deleted file mode 100644
index 1a4f1f7c228a..000000000000
--- a/drivers/media/dvb/frontends/dib3000-common.c
+++ /dev/null
@@ -1,83 +0,0 @@
1#include "dib3000-common.h"
2
3#ifdef CONFIG_DVB_DIBCOM_DEBUG
4static int debug;
5module_param(debug, int, 0644);
6MODULE_PARM_DESC(debug, "set debugging level (1=info,2=i2c,4=srch (|-able)).");
7#endif
8#define deb_info(args...) dprintk(0x01,args)
9#define deb_i2c(args...) dprintk(0x02,args)
10#define deb_srch(args...) dprintk(0x04,args)
11
12
13int dib3000_read_reg(struct dib3000_state *state, u16 reg)
14{
15 u8 wb[] = { ((reg >> 8) | 0x80) & 0xff, reg & 0xff };
16 u8 rb[2];
17 struct i2c_msg msg[] = {
18 { .addr = state->config.demod_address, .flags = 0, .buf = wb, .len = 2 },
19 { .addr = state->config.demod_address, .flags = I2C_M_RD, .buf = rb, .len = 2 },
20 };
21
22 if (i2c_transfer(state->i2c, msg, 2) != 2)
23 deb_i2c("i2c read error\n");
24
25 deb_i2c("reading i2c bus (reg: %5d 0x%04x, val: %5d 0x%04x)\n",reg,reg,
26 (rb[0] << 8) | rb[1],(rb[0] << 8) | rb[1]);
27
28 return (rb[0] << 8) | rb[1];
29}
30
31int dib3000_write_reg(struct dib3000_state *state, u16 reg, u16 val)
32{
33 u8 b[] = {
34 (reg >> 8) & 0xff, reg & 0xff,
35 (val >> 8) & 0xff, val & 0xff,
36 };
37 struct i2c_msg msg[] = {
38 { .addr = state->config.demod_address, .flags = 0, .buf = b, .len = 4 }
39 };
40 deb_i2c("writing i2c bus (reg: %5d 0x%04x, val: %5d 0x%04x)\n",reg,reg,val,val);
41
42 return i2c_transfer(state->i2c,msg, 1) != 1 ? -EREMOTEIO : 0;
43}
44
45int dib3000_search_status(u16 irq,u16 lock)
46{
47 if (irq & 0x02) {
48 if (lock & 0x01) {
49 deb_srch("auto search succeeded\n");
50 return 1; // auto search succeeded
51 } else {
52 deb_srch("auto search not successful\n");
53 return 0; // auto search failed
54 }
55 } else if (irq & 0x01) {
56 deb_srch("auto search failed\n");
57 return 0; // auto search failed
58 }
59 return -1; // try again
60}
61
62/* for auto search */
63u16 dib3000_seq[2][2][2] = /* fft,gua, inv */
64 { /* fft */
65 { /* gua */
66 { 0, 1 }, /* 0 0 { 0,1 } */
67 { 3, 9 }, /* 0 1 { 0,1 } */
68 },
69 {
70 { 2, 5 }, /* 1 0 { 0,1 } */
71 { 6, 11 }, /* 1 1 { 0,1 } */
72 }
73 };
74
75MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de");
76MODULE_DESCRIPTION("Common functions for the dib3000mb/dib3000mc dvb frontend drivers");
77MODULE_LICENSE("GPL");
78
79EXPORT_SYMBOL(dib3000_seq);
80
81EXPORT_SYMBOL(dib3000_read_reg);
82EXPORT_SYMBOL(dib3000_write_reg);
83EXPORT_SYMBOL(dib3000_search_status);
diff --git a/drivers/media/dvb/frontends/dib3000-common.h b/drivers/media/dvb/frontends/dib3000-common.h
deleted file mode 100644
index be1c0d3e1389..000000000000
--- a/drivers/media/dvb/frontends/dib3000-common.h
+++ /dev/null
@@ -1,135 +0,0 @@
1/*
2 * .h-files for the common use of the frontend drivers made by DiBcom
3 * DiBcom 3000M-B/C, 3000P
4 *
5 * DiBcom (http://www.dibcom.fr/)
6 *
7 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
8 *
9 * based on GPL code from DibCom, which has
10 *
11 * Copyright (C) 2004 Amaury Demol for DiBcom (ademol@dibcom.fr)
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation, version 2.
16 *
17 * Acknowledgements
18 *
19 * Amaury Demol (ademol@dibcom.fr) from DiBcom for providing specs and driver
20 * sources, on which this driver (and the dvb-dibusb) are based.
21 *
22 * see Documentation/dvb/README.dibusb for more information
23 *
24 */
25
26#ifndef DIB3000_COMMON_H
27#define DIB3000_COMMON_H
28
29#include "dvb_frontend.h"
30#include "dib3000.h"
31
32/* info and err, taken from usb.h, if there is anything available like by default. */
33#define err(format, arg...) printk(KERN_ERR "dib3000: " format "\n" , ## arg)
34#define info(format, arg...) printk(KERN_INFO "dib3000: " format "\n" , ## arg)
35#define warn(format, arg...) printk(KERN_WARNING "dib3000: " format "\n" , ## arg)
36
37/* frontend state */
38struct dib3000_state {
39 struct i2c_adapter* i2c;
40
41/* configuration settings */
42 struct dib3000_config config;
43
44 struct dvb_frontend frontend;
45 int timing_offset;
46 int timing_offset_comp_done;
47
48 fe_bandwidth_t last_tuned_bw;
49 u32 last_tuned_freq;
50};
51
52/* commonly used methods by the dib3000mb/mc/p frontend */
53extern int dib3000_read_reg(struct dib3000_state *state, u16 reg);
54extern int dib3000_write_reg(struct dib3000_state *state, u16 reg, u16 val);
55
56extern int dib3000_search_status(u16 irq,u16 lock);
57
58/* handy shortcuts */
59#define rd(reg) dib3000_read_reg(state,reg)
60
61#define wr(reg,val) if (dib3000_write_reg(state,reg,val)) \
62 { err("while sending 0x%04x to 0x%04x.",val,reg); return -EREMOTEIO; }
63
64#define wr_foreach(a,v) { int i; \
65 if (sizeof(a) != sizeof(v)) \
66 err("sizeof: %zu %zu is different",sizeof(a),sizeof(v));\
67 for (i=0; i < sizeof(a)/sizeof(u16); i++) \
68 wr(a[i],v[i]); \
69 }
70
71#define set_or(reg,val) wr(reg,rd(reg) | val)
72
73#define set_and(reg,val) wr(reg,rd(reg) & val)
74
75
76/* debug */
77
78#ifdef CONFIG_DVB_DIBCOM_DEBUG
79#define dprintk(level,args...) \
80 do { if ((debug & level)) { printk(args); } } while (0)
81#else
82#define dprintk(args...) do { } while (0)
83#endif
84
85/* mask for enabling a specific pid for the pid_filter */
86#define DIB3000_ACTIVATE_PID_FILTERING (0x2000)
87
88/* common values for tuning */
89#define DIB3000_ALPHA_0 ( 0)
90#define DIB3000_ALPHA_1 ( 1)
91#define DIB3000_ALPHA_2 ( 2)
92#define DIB3000_ALPHA_4 ( 4)
93
94#define DIB3000_CONSTELLATION_QPSK ( 0)
95#define DIB3000_CONSTELLATION_16QAM ( 1)
96#define DIB3000_CONSTELLATION_64QAM ( 2)
97
98#define DIB3000_GUARD_TIME_1_32 ( 0)
99#define DIB3000_GUARD_TIME_1_16 ( 1)
100#define DIB3000_GUARD_TIME_1_8 ( 2)
101#define DIB3000_GUARD_TIME_1_4 ( 3)
102
103#define DIB3000_TRANSMISSION_MODE_2K ( 0)
104#define DIB3000_TRANSMISSION_MODE_8K ( 1)
105
106#define DIB3000_SELECT_LP ( 0)
107#define DIB3000_SELECT_HP ( 1)
108
109#define DIB3000_FEC_1_2 ( 1)
110#define DIB3000_FEC_2_3 ( 2)
111#define DIB3000_FEC_3_4 ( 3)
112#define DIB3000_FEC_5_6 ( 5)
113#define DIB3000_FEC_7_8 ( 7)
114
115#define DIB3000_HRCH_OFF ( 0)
116#define DIB3000_HRCH_ON ( 1)
117
118#define DIB3000_DDS_INVERSION_OFF ( 0)
119#define DIB3000_DDS_INVERSION_ON ( 1)
120
121#define DIB3000_TUNER_WRITE_ENABLE(a) (0xffff & (a << 8))
122#define DIB3000_TUNER_WRITE_DISABLE(a) (0xffff & ((a << 8) | (1 << 7)))
123
124/* for auto search */
125extern u16 dib3000_seq[2][2][2];
126
127#define DIB3000_REG_MANUFACTOR_ID ( 1025)
128#define DIB3000_I2C_ID_DIBCOM (0x01b3)
129
130#define DIB3000_REG_DEVICE_ID ( 1026)
131#define DIB3000MB_DEVICE_ID (0x3000)
132#define DIB3000MC_DEVICE_ID (0x3001)
133#define DIB3000P_DEVICE_ID (0x3002)
134
135#endif // DIB3000_COMMON_H
diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
index ec927628d273..0caac3f0f279 100644
--- a/drivers/media/dvb/frontends/dib3000.h
+++ b/drivers/media/dvb/frontends/dib3000.h
@@ -41,9 +41,16 @@ struct dib_fe_xfer_ops
41 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl); 41 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42}; 42};
43 43
44#if defined(CONFIG_DVB_DIB3000MB) || defined(CONFIG_DVB_DIB3000MB_MODULE)
44extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config, 45extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
45 struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops); 46 struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops);
47#else
48static inline struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
49 struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops)
50{
51 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
52 return NULL;
53}
54#endif // CONFIG_DVB_DIB3000MB
46 55
47extern struct dvb_frontend* dib3000mc_attach(const struct dib3000_config* config,
48 struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops);
49#endif // DIB3000_H 56#endif // DIB3000_H
diff --git a/drivers/media/dvb/frontends/dib3000mb.c b/drivers/media/dvb/frontends/dib3000mb.c
index 5302e11883a2..adbabfdb04a9 100644
--- a/drivers/media/dvb/frontends/dib3000mb.c
+++ b/drivers/media/dvb/frontends/dib3000mb.c
@@ -29,9 +29,10 @@
29#include <linux/string.h> 29#include <linux/string.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31 31
32#include "dib3000-common.h" 32#include "dvb_frontend.h"
33#include "dib3000mb_priv.h" 33
34#include "dib3000.h" 34#include "dib3000.h"
35#include "dib3000mb_priv.h"
35 36
36/* Version information */ 37/* Version information */
37#define DRIVER_VERSION "0.1" 38#define DRIVER_VERSION "0.1"
@@ -44,10 +45,81 @@ module_param(debug, int, 0644);
44MODULE_PARM_DESC(debug, "set debugging level (1=info,2=xfer,4=setfe,8=getfe (|-able))."); 45MODULE_PARM_DESC(debug, "set debugging level (1=info,2=xfer,4=setfe,8=getfe (|-able)).");
45#endif 46#endif
46#define deb_info(args...) dprintk(0x01,args) 47#define deb_info(args...) dprintk(0x01,args)
48#define deb_i2c(args...) dprintk(0x02,args)
49#define deb_srch(args...) dprintk(0x04,args)
50#define deb_info(args...) dprintk(0x01,args)
47#define deb_xfer(args...) dprintk(0x02,args) 51#define deb_xfer(args...) dprintk(0x02,args)
48#define deb_setf(args...) dprintk(0x04,args) 52#define deb_setf(args...) dprintk(0x04,args)
49#define deb_getf(args...) dprintk(0x08,args) 53#define deb_getf(args...) dprintk(0x08,args)
50 54
55#ifdef CONFIG_DVB_DIBCOM_DEBUG
56static int debug;
57module_param(debug, int, 0644);
58MODULE_PARM_DESC(debug, "set debugging level (1=info,2=i2c,4=srch (|-able)).");
59#endif
60
61static int dib3000_read_reg(struct dib3000_state *state, u16 reg)
62{
63 u8 wb[] = { ((reg >> 8) | 0x80) & 0xff, reg & 0xff };
64 u8 rb[2];
65 struct i2c_msg msg[] = {
66 { .addr = state->config.demod_address, .flags = 0, .buf = wb, .len = 2 },
67 { .addr = state->config.demod_address, .flags = I2C_M_RD, .buf = rb, .len = 2 },
68 };
69
70 if (i2c_transfer(state->i2c, msg, 2) != 2)
71 deb_i2c("i2c read error\n");
72
73 deb_i2c("reading i2c bus (reg: %5d 0x%04x, val: %5d 0x%04x)\n",reg,reg,
74 (rb[0] << 8) | rb[1],(rb[0] << 8) | rb[1]);
75
76 return (rb[0] << 8) | rb[1];
77}
78
79static int dib3000_write_reg(struct dib3000_state *state, u16 reg, u16 val)
80{
81 u8 b[] = {
82 (reg >> 8) & 0xff, reg & 0xff,
83 (val >> 8) & 0xff, val & 0xff,
84 };
85 struct i2c_msg msg[] = {
86 { .addr = state->config.demod_address, .flags = 0, .buf = b, .len = 4 }
87 };
88 deb_i2c("writing i2c bus (reg: %5d 0x%04x, val: %5d 0x%04x)\n",reg,reg,val,val);
89
90 return i2c_transfer(state->i2c,msg, 1) != 1 ? -EREMOTEIO : 0;
91}
92
93static int dib3000_search_status(u16 irq,u16 lock)
94{
95 if (irq & 0x02) {
96 if (lock & 0x01) {
97 deb_srch("auto search succeeded\n");
98 return 1; // auto search succeeded
99 } else {
100 deb_srch("auto search not successful\n");
101 return 0; // auto search failed
102 }
103 } else if (irq & 0x01) {
104 deb_srch("auto search failed\n");
105 return 0; // auto search failed
106 }
107 return -1; // try again
108}
109
110/* for auto search */
111static u16 dib3000_seq[2][2][2] = /* fft,gua, inv */
112 { /* fft */
113 { /* gua */
114 { 0, 1 }, /* 0 0 { 0,1 } */
115 { 3, 9 }, /* 0 1 { 0,1 } */
116 },
117 {
118 { 2, 5 }, /* 1 0 { 0,1 } */
119 { 6, 11 }, /* 1 1 { 0,1 } */
120 }
121 };
122
51static int dib3000mb_get_frontend(struct dvb_frontend* fe, 123static int dib3000mb_get_frontend(struct dvb_frontend* fe,
52 struct dvb_frontend_parameters *fep); 124 struct dvb_frontend_parameters *fep);
53 125
diff --git a/drivers/media/dvb/frontends/dib3000mb_priv.h b/drivers/media/dvb/frontends/dib3000mb_priv.h
index 999b19047816..1a12747fdc91 100644
--- a/drivers/media/dvb/frontends/dib3000mb_priv.h
+++ b/drivers/media/dvb/frontends/dib3000mb_priv.h
@@ -13,6 +13,99 @@
13#ifndef __DIB3000MB_PRIV_H_INCLUDED__ 13#ifndef __DIB3000MB_PRIV_H_INCLUDED__
14#define __DIB3000MB_PRIV_H_INCLUDED__ 14#define __DIB3000MB_PRIV_H_INCLUDED__
15 15
16/* info and err, taken from usb.h, if there is anything available like by default. */
17#define err(format, arg...) printk(KERN_ERR "dib3000: " format "\n" , ## arg)
18#define info(format, arg...) printk(KERN_INFO "dib3000: " format "\n" , ## arg)
19#define warn(format, arg...) printk(KERN_WARNING "dib3000: " format "\n" , ## arg)
20
21/* handy shortcuts */
22#define rd(reg) dib3000_read_reg(state,reg)
23
24#define wr(reg,val) if (dib3000_write_reg(state,reg,val)) \
25 { err("while sending 0x%04x to 0x%04x.",val,reg); return -EREMOTEIO; }
26
27#define wr_foreach(a,v) { int i; \
28 if (sizeof(a) != sizeof(v)) \
29 err("sizeof: %zu %zu is different",sizeof(a),sizeof(v));\
30 for (i=0; i < sizeof(a)/sizeof(u16); i++) \
31 wr(a[i],v[i]); \
32 }
33
34#define set_or(reg,val) wr(reg,rd(reg) | val)
35
36#define set_and(reg,val) wr(reg,rd(reg) & val)
37
38/* debug */
39
40#ifdef CONFIG_DVB_DIBCOM_DEBUG
41#define dprintk(level,args...) \
42 do { if ((debug & level)) { printk(args); } } while (0)
43#else
44#define dprintk(args...) do { } while (0)
45#endif
46
47/* mask for enabling a specific pid for the pid_filter */
48#define DIB3000_ACTIVATE_PID_FILTERING (0x2000)
49
50/* common values for tuning */
51#define DIB3000_ALPHA_0 ( 0)
52#define DIB3000_ALPHA_1 ( 1)
53#define DIB3000_ALPHA_2 ( 2)
54#define DIB3000_ALPHA_4 ( 4)
55
56#define DIB3000_CONSTELLATION_QPSK ( 0)
57#define DIB3000_CONSTELLATION_16QAM ( 1)
58#define DIB3000_CONSTELLATION_64QAM ( 2)
59
60#define DIB3000_GUARD_TIME_1_32 ( 0)
61#define DIB3000_GUARD_TIME_1_16 ( 1)
62#define DIB3000_GUARD_TIME_1_8 ( 2)
63#define DIB3000_GUARD_TIME_1_4 ( 3)
64
65#define DIB3000_TRANSMISSION_MODE_2K ( 0)
66#define DIB3000_TRANSMISSION_MODE_8K ( 1)
67
68#define DIB3000_SELECT_LP ( 0)
69#define DIB3000_SELECT_HP ( 1)
70
71#define DIB3000_FEC_1_2 ( 1)
72#define DIB3000_FEC_2_3 ( 2)
73#define DIB3000_FEC_3_4 ( 3)
74#define DIB3000_FEC_5_6 ( 5)
75#define DIB3000_FEC_7_8 ( 7)
76
77#define DIB3000_HRCH_OFF ( 0)
78#define DIB3000_HRCH_ON ( 1)
79
80#define DIB3000_DDS_INVERSION_OFF ( 0)
81#define DIB3000_DDS_INVERSION_ON ( 1)
82
83#define DIB3000_TUNER_WRITE_ENABLE(a) (0xffff & (a << 8))
84#define DIB3000_TUNER_WRITE_DISABLE(a) (0xffff & ((a << 8) | (1 << 7)))
85
86#define DIB3000_REG_MANUFACTOR_ID ( 1025)
87#define DIB3000_I2C_ID_DIBCOM (0x01b3)
88
89#define DIB3000_REG_DEVICE_ID ( 1026)
90#define DIB3000MB_DEVICE_ID (0x3000)
91#define DIB3000MC_DEVICE_ID (0x3001)
92#define DIB3000P_DEVICE_ID (0x3002)
93
94/* frontend state */
95struct dib3000_state {
96 struct i2c_adapter* i2c;
97
98/* configuration settings */
99 struct dib3000_config config;
100
101 struct dvb_frontend frontend;
102 int timing_offset;
103 int timing_offset_comp_done;
104
105 fe_bandwidth_t last_tuned_bw;
106 u32 last_tuned_freq;
107};
108
16/* register addresses and some of their default values */ 109/* register addresses and some of their default values */
17 110
18/* restart subsystems */ 111/* restart subsystems */
diff --git a/drivers/media/dvb/frontends/dib3000mc.c b/drivers/media/dvb/frontends/dib3000mc.c
index 98673474a140..cc28417fa33a 100644
--- a/drivers/media/dvb/frontends/dib3000mc.c
+++ b/drivers/media/dvb/frontends/dib3000mc.c
@@ -1,913 +1,921 @@
1/* 1/*
2 * Frontend driver for mobile DVB-T demodulator DiBcom 3000P/M-C 2 * Driver for DiBcom DiB3000MC/P-demodulator.
3 * DiBcom (http://www.dibcom.fr/)
4 * 3 *
4 * Copyright (C) 2004-6 DiBcom (http://www.dibcom.fr/)
5 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de) 5 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
6 * 6 *
7 * based on GPL code from DiBCom, which has 7 * This code is partially based on the previous dib3000mc.c .
8 * 8 *
9 * Copyright (C) 2004 Amaury Demol for DiBcom (ademol@dibcom.fr) 9 * This program is free software; you can redistribute it and/or
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as 10 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation, version 2. 11 * published by the Free Software Foundation, version 2.
14 *
15 * Acknowledgements
16 *
17 * Amaury Demol (ademol@dibcom.fr) from DiBcom for providing specs and driver
18 * sources, on which this driver (and the dvb-dibusb) are based.
19 *
20 * see Documentation/dvb/README.dibusb for more information
21 *
22 */ 12 */
13
23#include <linux/kernel.h> 14#include <linux/kernel.h>
24#include <linux/module.h> 15#include <linux/i2c.h>
25#include <linux/moduleparam.h> 16//#include <linux/init.h>
26#include <linux/init.h> 17//#include <linux/delay.h>
27#include <linux/delay.h> 18//#include <linux/string.h>
28#include <linux/string.h> 19//#include <linux/slab.h>
29#include <linux/slab.h> 20
30 21#include "dvb_frontend.h"
31#include "dib3000-common.h" 22
32#include "dib3000mc_priv.h" 23#include "dib3000mc.h"
33#include "dib3000.h" 24
34
35/* Version information */
36#define DRIVER_VERSION "0.1"
37#define DRIVER_DESC "DiBcom 3000M-C DVB-T demodulator"
38#define DRIVER_AUTHOR "Patrick Boettcher, patrick.boettcher@desy.de"
39
40#ifdef CONFIG_DVB_DIBCOM_DEBUG
41static int debug; 25static int debug;
42module_param(debug, int, 0644); 26module_param(debug, int, 0644);
43MODULE_PARM_DESC(debug, "set debugging level (1=info,2=xfer,4=setfe,8=getfe,16=stat (|-able))."); 27MODULE_PARM_DESC(debug, "turn on debugging (default: 0)");
44#endif
45#define deb_info(args...) dprintk(0x01,args)
46#define deb_xfer(args...) dprintk(0x02,args)
47#define deb_setf(args...) dprintk(0x04,args)
48#define deb_getf(args...) dprintk(0x08,args)
49#define deb_stat(args...) dprintk(0x10,args)
50
51static int dib3000mc_set_impulse_noise(struct dib3000_state * state, int mode,
52 fe_transmit_mode_t transmission_mode, fe_bandwidth_t bandwidth)
53{
54 switch (transmission_mode) {
55 case TRANSMISSION_MODE_2K:
56 wr_foreach(dib3000mc_reg_fft,dib3000mc_fft_modes[0]);
57 break;
58 case TRANSMISSION_MODE_8K:
59 wr_foreach(dib3000mc_reg_fft,dib3000mc_fft_modes[1]);
60 break;
61 default:
62 break;
63 }
64 28
65 switch (bandwidth) { 29#define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB3000MC/P:"); printk(args); } } while (0)
66/* case BANDWIDTH_5_MHZ: 30
67 wr_foreach(dib3000mc_reg_impulse_noise,dib3000mc_impluse_noise[0]); 31struct dib3000mc_state {
68 break; */ 32 struct dvb_frontend demod;
69 case BANDWIDTH_6_MHZ: 33 struct dib3000mc_config *cfg;
70 wr_foreach(dib3000mc_reg_impulse_noise,dib3000mc_impluse_noise[1]); 34
71 break; 35 u8 i2c_addr;
72 case BANDWIDTH_7_MHZ: 36 struct i2c_adapter *i2c_adap;
73 wr_foreach(dib3000mc_reg_impulse_noise,dib3000mc_impluse_noise[2]); 37
74 break; 38 struct dibx000_i2c_master i2c_master;
75 case BANDWIDTH_8_MHZ: 39
76 wr_foreach(dib3000mc_reg_impulse_noise,dib3000mc_impluse_noise[3]); 40 fe_bandwidth_t current_bandwidth;
77 break; 41
78 default: 42 u16 dev_id;
79 break; 43};
44
45static u16 dib3000mc_read_word(struct dib3000mc_state *state, u16 reg)
46{
47 u8 wb[2] = { (reg >> 8) | 0x80, reg & 0xff };
48 u8 rb[2];
49 struct i2c_msg msg[2] = {
50 { .addr = state->i2c_addr >> 1, .flags = 0, .buf = wb, .len = 2 },
51 { .addr = state->i2c_addr >> 1, .flags = I2C_M_RD, .buf = rb, .len = 2 },
52 };
53
54 if (i2c_transfer(state->i2c_adap, msg, 2) != 2)
55 dprintk("i2c read error on %d\n",reg);
56
57 return (rb[0] << 8) | rb[1];
58}
59
60static int dib3000mc_write_word(struct dib3000mc_state *state, u16 reg, u16 val)
61{
62 u8 b[4] = {
63 (reg >> 8) & 0xff, reg & 0xff,
64 (val >> 8) & 0xff, val & 0xff,
65 };
66 struct i2c_msg msg = {
67 .addr = state->i2c_addr >> 1, .flags = 0, .buf = b, .len = 4
68 };
69 return i2c_transfer(state->i2c_adap, &msg, 1) != 1 ? -EREMOTEIO : 0;
70}
71
72
73static int dib3000mc_identify(struct dib3000mc_state *state)
74{
75 u16 value;
76 if ((value = dib3000mc_read_word(state, 1025)) != 0x01b3) {
77 dprintk("-E- DiB3000MC/P: wrong Vendor ID (read=0x%x)\n",value);
78 return -EREMOTEIO;
80 } 79 }
81 80
82 switch (mode) { 81 value = dib3000mc_read_word(state, 1026);
83 case 0: /* no impulse */ /* fall through */ 82 if (value != 0x3001 && value != 0x3002) {
84 wr_foreach(dib3000mc_reg_imp_noise_ctl,dib3000mc_imp_noise_ctl[0]); 83 dprintk("-E- DiB3000MC/P: wrong Device ID (%x)\n",value);
85 break; 84 return -EREMOTEIO;
86 case 1: /* new algo */
87 wr_foreach(dib3000mc_reg_imp_noise_ctl,dib3000mc_imp_noise_ctl[1]);
88 set_or(DIB3000MC_REG_IMP_NOISE_55,DIB3000MC_IMP_NEW_ALGO(0)); /* gives 1<<10 */
89 break;
90 default: /* old algo */
91 wr_foreach(dib3000mc_reg_imp_noise_ctl,dib3000mc_imp_noise_ctl[3]);
92 break;
93 } 85 }
86 state->dev_id = value;
87
88 dprintk("-I- found DiB3000MC/P: %x\n",state->dev_id);
89
94 return 0; 90 return 0;
95} 91}
96 92
97static int dib3000mc_set_timing(struct dib3000_state *state, int upd_offset, 93static int dib3000mc_set_timing(struct dib3000mc_state *state, s16 nfft, u8 bw, u8 update_offset)
98 fe_transmit_mode_t fft, fe_bandwidth_t bw)
99{ 94{
100 u16 timf_msb,timf_lsb; 95/*
101 s32 tim_offset,tim_sgn; 96 u32 timf_msb, timf_lsb, i;
102 u64 comp1,comp2,comp=0; 97 int tim_sgn ;
103 98 LUInt comp1, comp2, comp ;
104 switch (bw) { 99// u32 tim_offset ;
105 case BANDWIDTH_8_MHZ: comp = DIB3000MC_CLOCK_REF*8; break; 100 comp = 27700 * BW_INDEX_TO_KHZ(bw) / 1000;
106 case BANDWIDTH_7_MHZ: comp = DIB3000MC_CLOCK_REF*7; break; 101 timf_msb = (comp >> 16) & 0x00FF;
107 case BANDWIDTH_6_MHZ: comp = DIB3000MC_CLOCK_REF*6; break; 102 timf_lsb = comp & 0xFFFF;
108 default: err("unknown bandwidth (%d)",bw); break;
109 }
110 timf_msb = (comp >> 16) & 0xff;
111 timf_lsb = (comp & 0xffff);
112 103
113 // Update the timing offset ; 104 // Update the timing offset ;
114 if (upd_offset > 0) { 105 if (update_offset) {
115 if (!state->timing_offset_comp_done) { 106 if (state->timing_offset_comp_done == 0) {
116 msleep(200); 107 usleep(200000);
117 state->timing_offset_comp_done = 1; 108 state->timing_offset_comp_done = 1;
118 } 109 }
119 tim_offset = rd(DIB3000MC_REG_TIMING_OFFS_MSB); 110 tim_offset = dib3000mc_read_word(state, 416);
120 if ((tim_offset & 0x2000) == 0x2000) 111 if ((tim_offset & 0x2000) == 0x2000)
121 tim_offset |= 0xC000; 112 tim_offset |= 0xC000; // PB: This only works if tim_offset is s16 - weird
122 if (fft == TRANSMISSION_MODE_2K) 113
123 tim_offset <<= 2; 114 if (nfft == 0)
115 tim_offset = tim_offset << 2; // PB: Do not store the offset for different things in one variable
124 state->timing_offset += tim_offset; 116 state->timing_offset += tim_offset;
125 } 117 }
126
127 tim_offset = state->timing_offset; 118 tim_offset = state->timing_offset;
119
128 if (tim_offset < 0) { 120 if (tim_offset < 0) {
129 tim_sgn = 1; 121 tim_sgn = 1;
130 tim_offset = -tim_offset; 122 tim_offset = -tim_offset;
131 } else 123 } else
132 tim_sgn = 0; 124 tim_sgn = 0;
133 125
134 comp1 = (u32)tim_offset * (u32)timf_lsb ; 126 comp1 = tim_offset * timf_lsb;
135 comp2 = (u32)tim_offset * (u32)timf_msb ; 127 comp2 = tim_offset * timf_msb;
136 comp = ((comp1 >> 16) + comp2) >> 7; 128 comp = ((comp1 >> 16) + comp2) >> 7;
137 129
138 if (tim_sgn == 0) 130 if (tim_sgn == 0)
139 comp = (u32)(timf_msb << 16) + (u32) timf_lsb + comp; 131 comp = timf_msb * (1<<16) + timf_lsb + comp;
140 else 132 else
141 comp = (u32)(timf_msb << 16) + (u32) timf_lsb - comp ; 133 comp = timf_msb * (1<<16) + timf_lsb - comp;
134
135 timf_msb = (comp>>16)&0xFF ;
136 timf_lsb = comp&0xFFFF;
137*/
138 u32 timf = 1384402 * (BW_INDEX_TO_KHZ(bw) / 1000);
142 139
143 timf_msb = (comp >> 16) & 0xff; 140 dib3000mc_write_word(state, 23, timf >> 16);
144 timf_lsb = comp & 0xffff; 141 dib3000mc_write_word(state, 24, timf & 0xffff);
145 142
146 wr(DIB3000MC_REG_TIMING_FREQ_MSB,timf_msb);
147 wr(DIB3000MC_REG_TIMING_FREQ_LSB,timf_lsb);
148 return 0; 143 return 0;
149} 144}
150 145
151static int dib3000mc_init_auto_scan(struct dib3000_state *state, fe_bandwidth_t bw, int boost) 146static int dib3000mc_setup_pwm3_state(struct dib3000mc_state *state)
152{ 147{
153 if (boost) { 148 if (state->cfg->pwm3_inversion) {
154 wr(DIB3000MC_REG_SCAN_BOOST,DIB3000MC_SCAN_BOOST_ON); 149 dib3000mc_write_word(state, 51, (2 << 14) | (0 << 10) | (7 << 6) | (2 << 2) | (2 << 0));
150 dib3000mc_write_word(state, 52, (0 << 8) | (5 << 5) | (1 << 4) | (1 << 3) | (1 << 2) | (2 << 0));
155 } else { 151 } else {
156 wr(DIB3000MC_REG_SCAN_BOOST,DIB3000MC_SCAN_BOOST_OFF); 152 dib3000mc_write_word(state, 51, (2 << 14) | (4 << 10) | (7 << 6) | (2 << 2) | (2 << 0));
157 } 153 dib3000mc_write_word(state, 52, (1 << 8) | (5 << 5) | (1 << 4) | (1 << 3) | (0 << 2) | (2 << 0));
158 switch (bw) {
159 case BANDWIDTH_8_MHZ:
160 wr_foreach(dib3000mc_reg_bandwidth,dib3000mc_bandwidth_8mhz);
161 break;
162 case BANDWIDTH_7_MHZ:
163 wr_foreach(dib3000mc_reg_bandwidth,dib3000mc_bandwidth_7mhz);
164 break;
165 case BANDWIDTH_6_MHZ:
166 wr_foreach(dib3000mc_reg_bandwidth,dib3000mc_bandwidth_6mhz);
167 break;
168/* case BANDWIDTH_5_MHZ:
169 wr_foreach(dib3000mc_reg_bandwidth,dib3000mc_bandwidth_5mhz);
170 break;*/
171 case BANDWIDTH_AUTO:
172 return -EOPNOTSUPP;
173 default:
174 err("unknown bandwidth value (%d).",bw);
175 return -EINVAL;
176 }
177 if (boost) {
178 u32 timeout = (rd(DIB3000MC_REG_BW_TIMOUT_MSB) << 16) +
179 rd(DIB3000MC_REG_BW_TIMOUT_LSB);
180 timeout *= 85; timeout >>= 7;
181 wr(DIB3000MC_REG_BW_TIMOUT_MSB,(timeout >> 16) & 0xffff);
182 wr(DIB3000MC_REG_BW_TIMOUT_LSB,timeout & 0xffff);
183 } 154 }
155
156 if (state->cfg->use_pwm3)
157 dib3000mc_write_word(state, 245, (1 << 3) | (1 << 0));
158 else
159 dib3000mc_write_word(state, 245, 0);
160
161 dib3000mc_write_word(state, 1040, 0x3);
184 return 0; 162 return 0;
185} 163}
186 164
187static int dib3000mc_set_adp_cfg(struct dib3000_state *state, fe_modulation_t con) 165static int dib3000mc_set_output_mode(struct dib3000mc_state *state, int mode)
188{ 166{
189 switch (con) { 167 int ret = 0;
190 case QAM_64: 168 u16 fifo_threshold = 1792;
191 wr_foreach(dib3000mc_reg_adp_cfg,dib3000mc_adp_cfg[2]); 169 u16 outreg = 0;
192 break; 170 u16 outmode = 0;
193 case QAM_16: 171 u16 elecout = 1;
194 wr_foreach(dib3000mc_reg_adp_cfg,dib3000mc_adp_cfg[1]); 172 u16 smo_reg = dib3000mc_read_word(state, 206) & 0x0010; /* keep the pid_parse bit */
195 break; 173
196 case QPSK: 174 dprintk("-I- Setting output mode for demod %p to %d\n",
197 wr_foreach(dib3000mc_reg_adp_cfg,dib3000mc_adp_cfg[0]); 175 &state->demod, mode);
198 break; 176
199 case QAM_AUTO: 177 switch (mode) {
178 case OUTMODE_HIGH_Z: // disable
179 elecout = 0;
180 break;
181 case OUTMODE_MPEG2_PAR_GATED_CLK: // STBs with parallel gated clock
182 outmode = 0;
183 break;
184 case OUTMODE_MPEG2_PAR_CONT_CLK: // STBs with parallel continues clock
185 outmode = 1;
186 break;
187 case OUTMODE_MPEG2_SERIAL: // STBs with serial input
188 outmode = 2;
189 break;
190 case OUTMODE_MPEG2_FIFO: // e.g. USB feeding
191 elecout = 3;
192 /*ADDR @ 206 :
193 P_smo_error_discard [1;6:6] = 0
194 P_smo_rs_discard [1;5:5] = 0
195 P_smo_pid_parse [1;4:4] = 0
196 P_smo_fifo_flush [1;3:3] = 0
197 P_smo_mode [2;2:1] = 11
198 P_smo_ovf_prot [1;0:0] = 0
199 */
200 smo_reg |= 3 << 1;
201 fifo_threshold = 512;
202 outmode = 5;
203 break;
204 case OUTMODE_DIVERSITY:
205 outmode = 4;
206 elecout = 1;
200 break; 207 break;
201 default: 208 default:
202 warn("unkown constellation."); 209 dprintk("Unhandled output_mode passed to be set for demod %p\n",&state->demod);
210 outmode = 0;
203 break; 211 break;
204 } 212 }
205 return 0; 213
214 if ((state->cfg->output_mpeg2_in_188_bytes))
215 smo_reg |= (1 << 5); // P_smo_rs_discard [1;5:5] = 1
216
217 outreg = dib3000mc_read_word(state, 244) & 0x07FF;
218 outreg |= (outmode << 11);
219 ret |= dib3000mc_write_word(state, 244, outreg);
220 ret |= dib3000mc_write_word(state, 206, smo_reg); /*smo_ mode*/
221 ret |= dib3000mc_write_word(state, 207, fifo_threshold); /* synchronous fread */
222 ret |= dib3000mc_write_word(state, 1040, elecout); /* P_out_cfg */
223 return ret;
206} 224}
207 225
208static int dib3000mc_set_general_cfg(struct dib3000_state *state, struct dvb_frontend_parameters *fep, int *auto_val) 226static int dib3000mc_set_bandwidth(struct dvb_frontend *demod, u8 bw)
209{ 227{
210 struct dvb_ofdm_parameters *ofdm = &fep->u.ofdm; 228 struct dib3000mc_state *state = demod->demodulator_priv;
211 fe_code_rate_t fe_cr = FEC_NONE; 229 u16 bw_cfg[6] = { 0 };
212 u8 fft=0, guard=0, qam=0, alpha=0, sel_hp=0, cr=0, hrch=0; 230 u16 imp_bw_cfg[3] = { 0 };
213 int seq; 231 u16 reg;
214 232
215 switch (ofdm->transmission_mode) { 233/* settings here are for 27.7MHz */
216 case TRANSMISSION_MODE_2K: fft = DIB3000_TRANSMISSION_MODE_2K; break; 234 switch (bw) {
217 case TRANSMISSION_MODE_8K: fft = DIB3000_TRANSMISSION_MODE_8K; break; 235 case BANDWIDTH_8_MHZ:
218 case TRANSMISSION_MODE_AUTO: break; 236 bw_cfg[0] = 0x0019; bw_cfg[1] = 0x5c30; bw_cfg[2] = 0x0054; bw_cfg[3] = 0x88a0; bw_cfg[4] = 0x01a6; bw_cfg[5] = 0xab20;
219 default: return -EINVAL; 237 imp_bw_cfg[0] = 0x04db; imp_bw_cfg[1] = 0x00db; imp_bw_cfg[2] = 0x00b7;
220 } 238 break;
221 switch (ofdm->guard_interval) {
222 case GUARD_INTERVAL_1_32: guard = DIB3000_GUARD_TIME_1_32; break;
223 case GUARD_INTERVAL_1_16: guard = DIB3000_GUARD_TIME_1_16; break;
224 case GUARD_INTERVAL_1_8: guard = DIB3000_GUARD_TIME_1_8; break;
225 case GUARD_INTERVAL_1_4: guard = DIB3000_GUARD_TIME_1_4; break;
226 case GUARD_INTERVAL_AUTO: break;
227 default: return -EINVAL;
228 }
229 switch (ofdm->constellation) {
230 case QPSK: qam = DIB3000_CONSTELLATION_QPSK; break;
231 case QAM_16: qam = DIB3000_CONSTELLATION_16QAM; break;
232 case QAM_64: qam = DIB3000_CONSTELLATION_64QAM; break;
233 case QAM_AUTO: break;
234 default: return -EINVAL;
235 }
236 switch (ofdm->hierarchy_information) {
237 case HIERARCHY_NONE: /* fall through */
238 case HIERARCHY_1: alpha = DIB3000_ALPHA_1; break;
239 case HIERARCHY_2: alpha = DIB3000_ALPHA_2; break;
240 case HIERARCHY_4: alpha = DIB3000_ALPHA_4; break;
241 case HIERARCHY_AUTO: break;
242 default: return -EINVAL;
243 }
244 if (ofdm->hierarchy_information == HIERARCHY_NONE) {
245 hrch = DIB3000_HRCH_OFF;
246 sel_hp = DIB3000_SELECT_HP;
247 fe_cr = ofdm->code_rate_HP;
248 } else if (ofdm->hierarchy_information != HIERARCHY_AUTO) {
249 hrch = DIB3000_HRCH_ON;
250 sel_hp = DIB3000_SELECT_LP;
251 fe_cr = ofdm->code_rate_LP;
252 }
253 switch (fe_cr) {
254 case FEC_1_2: cr = DIB3000_FEC_1_2; break;
255 case FEC_2_3: cr = DIB3000_FEC_2_3; break;
256 case FEC_3_4: cr = DIB3000_FEC_3_4; break;
257 case FEC_5_6: cr = DIB3000_FEC_5_6; break;
258 case FEC_7_8: cr = DIB3000_FEC_7_8; break;
259 case FEC_NONE: break;
260 case FEC_AUTO: break;
261 default: return -EINVAL;
262 }
263 239
264 wr(DIB3000MC_REG_DEMOD_PARM,DIB3000MC_DEMOD_PARM(alpha,qam,guard,fft)); 240 case BANDWIDTH_7_MHZ:
265 wr(DIB3000MC_REG_HRCH_PARM,DIB3000MC_HRCH_PARM(sel_hp,cr,hrch)); 241 bw_cfg[0] = 0x001c; bw_cfg[1] = 0xfba5; bw_cfg[2] = 0x0060; bw_cfg[3] = 0x9c25; bw_cfg[4] = 0x01e3; bw_cfg[5] = 0x0cb7;
242 imp_bw_cfg[0] = 0x04c0; imp_bw_cfg[1] = 0x00c0; imp_bw_cfg[2] = 0x00a0;
243 break;
266 244
267 switch (fep->inversion) { 245 case BANDWIDTH_6_MHZ:
268 case INVERSION_OFF: 246 bw_cfg[0] = 0x0021; bw_cfg[1] = 0xd040; bw_cfg[2] = 0x0070; bw_cfg[3] = 0xb62b; bw_cfg[4] = 0x0233; bw_cfg[5] = 0x8ed5;
269 wr(DIB3000MC_REG_SET_DDS_FREQ_MSB,DIB3000MC_DDS_FREQ_MSB_INV_OFF); 247 imp_bw_cfg[0] = 0x04a5; imp_bw_cfg[1] = 0x00a5; imp_bw_cfg[2] = 0x0089;
270 break; 248 break;
271 case INVERSION_AUTO: /* fall through */ 249
272 case INVERSION_ON: 250 case 255 /* BANDWIDTH_5_MHZ */:
273 wr(DIB3000MC_REG_SET_DDS_FREQ_MSB,DIB3000MC_DDS_FREQ_MSB_INV_ON); 251 bw_cfg[0] = 0x0028; bw_cfg[1] = 0x9380; bw_cfg[2] = 0x0087; bw_cfg[3] = 0x4100; bw_cfg[4] = 0x02a4; bw_cfg[5] = 0x4500;
252 imp_bw_cfg[0] = 0x0489; imp_bw_cfg[1] = 0x0089; imp_bw_cfg[2] = 0x0072;
274 break; 253 break;
275 default: 254
276 return -EINVAL; 255 default: return -EINVAL;
277 } 256 }
278 257
279 seq = dib3000_seq 258 for (reg = 6; reg < 12; reg++)
280 [ofdm->transmission_mode == TRANSMISSION_MODE_AUTO] 259 dib3000mc_write_word(state, reg, bw_cfg[reg - 6]);
281 [ofdm->guard_interval == GUARD_INTERVAL_AUTO] 260 dib3000mc_write_word(state, 12, 0x0000);
282 [fep->inversion == INVERSION_AUTO]; 261 dib3000mc_write_word(state, 13, 0x03e8);
283 262 dib3000mc_write_word(state, 14, 0x0000);
284 deb_setf("seq? %d\n", seq); 263 dib3000mc_write_word(state, 15, 0x03f2);
285 wr(DIB3000MC_REG_SEQ_TPS,DIB3000MC_SEQ_TPS(seq,1)); 264 dib3000mc_write_word(state, 16, 0x0001);
286 *auto_val = ofdm->constellation == QAM_AUTO || 265 dib3000mc_write_word(state, 17, 0xb0d0);
287 ofdm->hierarchy_information == HIERARCHY_AUTO || 266 // P_sec_len
288 ofdm->guard_interval == GUARD_INTERVAL_AUTO || 267 dib3000mc_write_word(state, 18, 0x0393);
289 ofdm->transmission_mode == TRANSMISSION_MODE_AUTO || 268 dib3000mc_write_word(state, 19, 0x8700);
290 fe_cr == FEC_AUTO ||
291 fep->inversion == INVERSION_AUTO;
292 return 0;
293}
294 269
295static int dib3000mc_get_frontend(struct dvb_frontend* fe, 270 for (reg = 55; reg < 58; reg++)
296 struct dvb_frontend_parameters *fep) 271 dib3000mc_write_word(state, reg, imp_bw_cfg[reg - 55]);
297{
298 struct dib3000_state* state = fe->demodulator_priv;
299 struct dvb_ofdm_parameters *ofdm = &fep->u.ofdm;
300 fe_code_rate_t *cr;
301 u16 tps_val,cr_val;
302 int inv_test1,inv_test2;
303 u32 dds_val, threshold = 0x1000000;
304
305 if (!(rd(DIB3000MC_REG_LOCK_507) & DIB3000MC_LOCK_507))
306 return 0;
307
308 dds_val = (rd(DIB3000MC_REG_DDS_FREQ_MSB) << 16) + rd(DIB3000MC_REG_DDS_FREQ_LSB);
309 deb_getf("DDS_FREQ: %6x\n",dds_val);
310 if (dds_val < threshold)
311 inv_test1 = 0;
312 else if (dds_val == threshold)
313 inv_test1 = 1;
314 else
315 inv_test1 = 2;
316
317 dds_val = (rd(DIB3000MC_REG_SET_DDS_FREQ_MSB) << 16) + rd(DIB3000MC_REG_SET_DDS_FREQ_LSB);
318 deb_getf("DDS_SET_FREQ: %6x\n",dds_val);
319 if (dds_val < threshold)
320 inv_test2 = 0;
321 else if (dds_val == threshold)
322 inv_test2 = 1;
323 else
324 inv_test2 = 2;
325 272
326 fep->inversion = 273 // Timing configuration
327 ((inv_test2 == 2) && (inv_test1==1 || inv_test1==0)) || 274 dib3000mc_set_timing(state, 0, bw, 0);
328 ((inv_test2 == 0) && (inv_test1==1 || inv_test1==2)) ?
329 INVERSION_ON : INVERSION_OFF;
330 275
331 deb_getf("inversion %d %d, %d\n", inv_test2, inv_test1, fep->inversion); 276 return 0;
277}
332 278
333 fep->frequency = state->last_tuned_freq; 279static u16 impulse_noise_val[29] =
334 fep->u.ofdm.bandwidth= state->last_tuned_bw;
335 280
336 tps_val = rd(DIB3000MC_REG_TUNING_PARM); 281{
282 0x38, 0x6d9, 0x3f28, 0x7a7, 0x3a74, 0x196, 0x32a, 0x48c, 0x3ffe, 0x7f3,
283 0x2d94, 0x76, 0x53d, 0x3ff8, 0x7e3, 0x3320, 0x76, 0x5b3, 0x3feb, 0x7d2,
284 0x365e, 0x76, 0x48c, 0x3ffe, 0x5b3, 0x3feb, 0x76, 0x0000, 0xd
285};
337 286
338 switch (DIB3000MC_TP_QAM(tps_val)) { 287static void dib3000mc_set_impulse_noise(struct dib3000mc_state *state, u8 mode, s16 nfft)
339 case DIB3000_CONSTELLATION_QPSK: 288{
340 deb_getf("QPSK "); 289 u16 i;
341 ofdm->constellation = QPSK; 290 for (i = 58; i < 87; i++)
342 break; 291 dib3000mc_write_word(state, i, impulse_noise_val[i-58]);
343 case DIB3000_CONSTELLATION_16QAM: 292
344 deb_getf("QAM16 "); 293 if (nfft == 1) {
345 ofdm->constellation = QAM_16; 294 dib3000mc_write_word(state, 58, 0x3b);
346 break; 295 dib3000mc_write_word(state, 84, 0x00);
347 case DIB3000_CONSTELLATION_64QAM: 296 dib3000mc_write_word(state, 85, 0x8200);
348 deb_getf("QAM64 ");
349 ofdm->constellation = QAM_64;
350 break;
351 default:
352 err("Unexpected constellation returned by TPS (%d)", tps_val);
353 break;
354 } 297 }
355 298
356 if (DIB3000MC_TP_HRCH(tps_val)) { 299 dib3000mc_write_word(state, 34, 0x1294);
357 deb_getf("HRCH ON "); 300 dib3000mc_write_word(state, 35, 0x1ff8);
358 cr = &ofdm->code_rate_LP; 301 if (mode == 1)
359 ofdm->code_rate_HP = FEC_NONE; 302 dib3000mc_write_word(state, 55, dib3000mc_read_word(state, 55) | (1 << 10));
360 switch (DIB3000MC_TP_ALPHA(tps_val)) { 303}
361 case DIB3000_ALPHA_0: 304
362 deb_getf("HIERARCHY_NONE "); 305static int dib3000mc_init(struct dvb_frontend *demod)
363 ofdm->hierarchy_information = HIERARCHY_NONE; 306{
364 break; 307 struct dib3000mc_state *state = demod->demodulator_priv;
365 case DIB3000_ALPHA_1: 308 struct dibx000_agc_config *agc = state->cfg->agc;
366 deb_getf("HIERARCHY_1 "); 309
367 ofdm->hierarchy_information = HIERARCHY_1; 310 // Restart Configuration
368 break; 311 dib3000mc_write_word(state, 1027, 0x8000);
369 case DIB3000_ALPHA_2: 312 dib3000mc_write_word(state, 1027, 0x0000);
370 deb_getf("HIERARCHY_2 "); 313
371 ofdm->hierarchy_information = HIERARCHY_2; 314 // power up the demod + mobility configuration
372 break; 315 dib3000mc_write_word(state, 140, 0x0000);
373 case DIB3000_ALPHA_4: 316 dib3000mc_write_word(state, 1031, 0);
374 deb_getf("HIERARCHY_4 "); 317
375 ofdm->hierarchy_information = HIERARCHY_4; 318 if (state->cfg->mobile_mode) {
376 break; 319 dib3000mc_write_word(state, 139, 0x0000);
377 default: 320 dib3000mc_write_word(state, 141, 0x0000);
378 err("Unexpected ALPHA value returned by TPS (%d)", tps_val); 321 dib3000mc_write_word(state, 175, 0x0002);
379 break; 322 dib3000mc_write_word(state, 1032, 0x0000);
380 }
381 cr_val = DIB3000MC_TP_FEC_CR_LP(tps_val);
382 } else { 323 } else {
383 deb_getf("HRCH OFF "); 324 dib3000mc_write_word(state, 139, 0x0001);
384 cr = &ofdm->code_rate_HP; 325 dib3000mc_write_word(state, 141, 0x0000);
385 ofdm->code_rate_LP = FEC_NONE; 326 dib3000mc_write_word(state, 175, 0x0000);
386 ofdm->hierarchy_information = HIERARCHY_NONE; 327 dib3000mc_write_word(state, 1032, 0x012C);
387 cr_val = DIB3000MC_TP_FEC_CR_HP(tps_val);
388 } 328 }
329 dib3000mc_write_word(state, 1033, 0);
389 330
390 switch (cr_val) { 331 // P_clk_cfg
391 case DIB3000_FEC_1_2: 332 dib3000mc_write_word(state, 1037, 12592);
392 deb_getf("FEC_1_2 ");
393 *cr = FEC_1_2;
394 break;
395 case DIB3000_FEC_2_3:
396 deb_getf("FEC_2_3 ");
397 *cr = FEC_2_3;
398 break;
399 case DIB3000_FEC_3_4:
400 deb_getf("FEC_3_4 ");
401 *cr = FEC_3_4;
402 break;
403 case DIB3000_FEC_5_6:
404 deb_getf("FEC_5_6 ");
405 *cr = FEC_4_5;
406 break;
407 case DIB3000_FEC_7_8:
408 deb_getf("FEC_7_8 ");
409 *cr = FEC_7_8;
410 break;
411 default:
412 err("Unexpected FEC returned by TPS (%d)", tps_val);
413 break;
414 }
415 333
416 switch (DIB3000MC_TP_GUARD(tps_val)) { 334 // other configurations
417 case DIB3000_GUARD_TIME_1_32:
418 deb_getf("GUARD_INTERVAL_1_32 ");
419 ofdm->guard_interval = GUARD_INTERVAL_1_32;
420 break;
421 case DIB3000_GUARD_TIME_1_16:
422 deb_getf("GUARD_INTERVAL_1_16 ");
423 ofdm->guard_interval = GUARD_INTERVAL_1_16;
424 break;
425 case DIB3000_GUARD_TIME_1_8:
426 deb_getf("GUARD_INTERVAL_1_8 ");
427 ofdm->guard_interval = GUARD_INTERVAL_1_8;
428 break;
429 case DIB3000_GUARD_TIME_1_4:
430 deb_getf("GUARD_INTERVAL_1_4 ");
431 ofdm->guard_interval = GUARD_INTERVAL_1_4;
432 break;
433 default:
434 err("Unexpected Guard Time returned by TPS (%d)", tps_val);
435 break;
436 }
437 335
438 switch (DIB3000MC_TP_FFT(tps_val)) { 336 // P_ctrl_sfreq
439 case DIB3000_TRANSMISSION_MODE_2K: 337 dib3000mc_write_word(state, 33, (5 << 0));
440 deb_getf("TRANSMISSION_MODE_2K "); 338 dib3000mc_write_word(state, 88, (1 << 10) | (0x10 << 0));
441 ofdm->transmission_mode = TRANSMISSION_MODE_2K; 339
442 break; 340 // Phase noise control
443 case DIB3000_TRANSMISSION_MODE_8K: 341 // P_fft_phacor_inh, P_fft_phacor_cpe, P_fft_powrange
444 deb_getf("TRANSMISSION_MODE_8K "); 342 dib3000mc_write_word(state, 99, (1 << 9) | (0x20 << 0));
445 ofdm->transmission_mode = TRANSMISSION_MODE_8K; 343
446 break; 344 if (state->cfg->phase_noise_mode == 0)
447 default: 345 dib3000mc_write_word(state, 111, 0x00);
448 err("unexpected transmission mode return by TPS (%d)", tps_val); 346 else
449 break; 347 dib3000mc_write_word(state, 111, 0x02);
450 } 348
451 deb_getf("\n"); 349 // P_agc_global
350 dib3000mc_write_word(state, 50, 0x8000);
351
352 // agc setup misc
353 dib3000mc_setup_pwm3_state(state);
354
355 // P_agc_counter_lock
356 dib3000mc_write_word(state, 53, 0x87);
357 // P_agc_counter_unlock
358 dib3000mc_write_word(state, 54, 0x87);
359
360 /* agc */
361 dib3000mc_write_word(state, 36, state->cfg->max_time);
362 dib3000mc_write_word(state, 37, agc->setup);
363 dib3000mc_write_word(state, 38, state->cfg->pwm3_value);
364 dib3000mc_write_word(state, 39, state->cfg->ln_adc_level);
365
366 // set_agc_loop_Bw
367 dib3000mc_write_word(state, 40, 0x0179);
368 dib3000mc_write_word(state, 41, 0x03f0);
369
370 dib3000mc_write_word(state, 42, agc->agc1_max);
371 dib3000mc_write_word(state, 43, agc->agc1_min);
372 dib3000mc_write_word(state, 44, agc->agc2_max);
373 dib3000mc_write_word(state, 45, agc->agc2_min);
374 dib3000mc_write_word(state, 46, (agc->agc1_pt1 << 8) | agc->agc1_pt2);
375 dib3000mc_write_word(state, 47, (agc->agc1_slope1 << 8) | agc->agc1_slope2);
376 dib3000mc_write_word(state, 48, (agc->agc2_pt1 << 8) | agc->agc2_pt2);
377 dib3000mc_write_word(state, 49, (agc->agc2_slope1 << 8) | agc->agc2_slope2);
378
379// Begin: TimeOut registers
380 // P_pha3_thres
381 dib3000mc_write_word(state, 110, 3277);
382 // P_timf_alpha = 6, P_corm_alpha = 6, P_corm_thres = 0x80
383 dib3000mc_write_word(state, 26, 0x6680);
384 // lock_mask0
385 dib3000mc_write_word(state, 1, 4);
386 // lock_mask1
387 dib3000mc_write_word(state, 2, 4);
388 // lock_mask2
389 dib3000mc_write_word(state, 3, 0x1000);
390 // P_search_maxtrial=1
391 dib3000mc_write_word(state, 5, 1);
392
393 dib3000mc_set_bandwidth(&state->demod, BANDWIDTH_8_MHZ);
394
395 // div_lock_mask
396 dib3000mc_write_word(state, 4, 0x814);
397
398 dib3000mc_write_word(state, 21, (1 << 9) | 0x164);
399 dib3000mc_write_word(state, 22, 0x463d);
400
401 // Spurious rm cfg
402 // P_cspu_regul, P_cspu_win_cut
403 dib3000mc_write_word(state, 120, 0x200f);
404 // P_adp_selec_monit
405 dib3000mc_write_word(state, 134, 0);
406
407 // Fec cfg
408 dib3000mc_write_word(state, 195, 0x10);
409
410 // diversity register: P_dvsy_sync_wait..
411 dib3000mc_write_word(state, 180, 0x2FF0);
412
413 // Impulse noise configuration
414 dib3000mc_set_impulse_noise(state, 0, 1);
415
416 // output mode set-up
417 dib3000mc_set_output_mode(state, OUTMODE_HIGH_Z);
418
419 /* close the i2c-gate */
420 dib3000mc_write_word(state, 769, (1 << 7) );
452 421
453 return 0; 422 return 0;
454} 423}
455 424
456static int dib3000mc_set_frontend(struct dvb_frontend* fe, 425static int dib3000mc_sleep(struct dvb_frontend *demod)
457 struct dvb_frontend_parameters *fep, int tuner)
458{ 426{
459 struct dib3000_state* state = fe->demodulator_priv; 427 struct dib3000mc_state *state = demod->demodulator_priv;
460 struct dvb_ofdm_parameters *ofdm = &fep->u.ofdm;
461 int search_state,auto_val;
462 u16 val;
463 428
464 if (tuner && fe->ops.tuner_ops.set_params) { /* initial call from dvb */ 429 dib3000mc_write_word(state, 1037, dib3000mc_read_word(state, 1037) | 0x0003);
465 fe->ops.tuner_ops.set_params(fe, fep); 430 dib3000mc_write_word(state, 1031, 0xFFFF);
466 if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0); 431 dib3000mc_write_word(state, 1032, 0xFFFF);
467 432 dib3000mc_write_word(state, 1033, 0xFFF4); // **** Bin2
468 state->last_tuned_freq = fep->frequency;
469 // if (!scanboost) {
470 dib3000mc_set_timing(state,0,ofdm->transmission_mode,ofdm->bandwidth);
471 dib3000mc_init_auto_scan(state, ofdm->bandwidth, 0);
472 state->last_tuned_bw = ofdm->bandwidth;
473
474 wr_foreach(dib3000mc_reg_agc_bandwidth,dib3000mc_agc_bandwidth);
475 wr(DIB3000MC_REG_RESTART,DIB3000MC_RESTART_AGC);
476 wr(DIB3000MC_REG_RESTART,DIB3000MC_RESTART_OFF);
477
478 /* Default cfg isi offset adp */
479 wr_foreach(dib3000mc_reg_offset,dib3000mc_offset[0]);
480
481 wr(DIB3000MC_REG_ISI,DIB3000MC_ISI_DEFAULT | DIB3000MC_ISI_INHIBIT);
482 dib3000mc_set_adp_cfg(state,ofdm->constellation);
483 wr(DIB3000MC_REG_UNK_133,DIB3000MC_UNK_133);
484
485 wr_foreach(dib3000mc_reg_bandwidth_general,dib3000mc_bandwidth_general);
486 /* power smoothing */
487 if (ofdm->bandwidth != BANDWIDTH_8_MHZ) {
488 wr_foreach(dib3000mc_reg_bw,dib3000mc_bw[0]);
489 } else {
490 wr_foreach(dib3000mc_reg_bw,dib3000mc_bw[3]);
491 }
492 auto_val = 0;
493 dib3000mc_set_general_cfg(state,fep,&auto_val);
494 dib3000mc_set_impulse_noise(state,0,ofdm->constellation,ofdm->bandwidth);
495
496 val = rd(DIB3000MC_REG_DEMOD_PARM);
497 wr(DIB3000MC_REG_DEMOD_PARM,val|DIB3000MC_DEMOD_RST_DEMOD_ON);
498 wr(DIB3000MC_REG_DEMOD_PARM,val);
499 // }
500 msleep(70);
501
502 /* something has to be auto searched */
503 if (auto_val) {
504 int as_count=0;
505
506 deb_setf("autosearch enabled.\n");
507
508 val = rd(DIB3000MC_REG_DEMOD_PARM);
509 wr(DIB3000MC_REG_DEMOD_PARM,val | DIB3000MC_DEMOD_RST_AUTO_SRCH_ON);
510 wr(DIB3000MC_REG_DEMOD_PARM,val);
511
512 while ((search_state = dib3000_search_status(
513 rd(DIB3000MC_REG_AS_IRQ),1)) < 0 && as_count++ < 100)
514 msleep(10);
515
516 deb_info("search_state after autosearch %d after %d checks\n",search_state,as_count);
517
518 if (search_state == 1) {
519 struct dvb_frontend_parameters feps;
520 if (dib3000mc_get_frontend(fe, &feps) == 0) {
521 deb_setf("reading tuning data from frontend succeeded.\n");
522 return dib3000mc_set_frontend(fe, &feps, 0);
523 }
524 }
525 } else {
526 dib3000mc_set_impulse_noise(state,0,ofdm->transmission_mode,ofdm->bandwidth);
527 wr(DIB3000MC_REG_ISI,DIB3000MC_ISI_DEFAULT|DIB3000MC_ISI_ACTIVATE);
528 dib3000mc_set_adp_cfg(state,ofdm->constellation);
529
530 /* set_offset_cfg */
531 wr_foreach(dib3000mc_reg_offset,
532 dib3000mc_offset[(ofdm->transmission_mode == TRANSMISSION_MODE_8K)+1]);
533 }
534 } else { /* second call, after autosearch (fka: set_WithKnownParams) */
535// dib3000mc_set_timing(state,1,ofdm->transmission_mode,ofdm->bandwidth);
536
537 auto_val = 0;
538 dib3000mc_set_general_cfg(state,fep,&auto_val);
539 if (auto_val)
540 deb_info("auto_val is true, even though an auto search was already performed.\n");
541
542 dib3000mc_set_impulse_noise(state,0,ofdm->constellation,ofdm->bandwidth);
543
544 val = rd(DIB3000MC_REG_DEMOD_PARM);
545 wr(DIB3000MC_REG_DEMOD_PARM,val | DIB3000MC_DEMOD_RST_AUTO_SRCH_ON);
546 wr(DIB3000MC_REG_DEMOD_PARM,val);
547 433
548 msleep(30); 434 return 0;
435}
549 436
550 wr(DIB3000MC_REG_ISI,DIB3000MC_ISI_DEFAULT|DIB3000MC_ISI_ACTIVATE); 437static void dib3000mc_set_adp_cfg(struct dib3000mc_state *state, s16 qam)
551 dib3000mc_set_adp_cfg(state,ofdm->constellation); 438{
552 wr_foreach(dib3000mc_reg_offset, 439 u16 cfg[4] = { 0 },reg;
553 dib3000mc_offset[(ofdm->transmission_mode == TRANSMISSION_MODE_8K)+1]); 440 switch (qam) {
441 case 0:
442 cfg[0] = 0x099a; cfg[1] = 0x7fae; cfg[2] = 0x0333; cfg[3] = 0x7ff0;
443 break;
444 case 1:
445 cfg[0] = 0x023d; cfg[1] = 0x7fdf; cfg[2] = 0x00a4; cfg[3] = 0x7ff0;
446 break;
447 case 2:
448 cfg[0] = 0x0148; cfg[1] = 0x7ff0; cfg[2] = 0x00a4; cfg[3] = 0x7ff8;
449 break;
554 } 450 }
555 return 0; 451 for (reg = 129; reg < 133; reg++)
452 dib3000mc_write_word(state, reg, cfg[reg - 129]);
556} 453}
557 454
558static int dib3000mc_fe_init(struct dvb_frontend* fe, int mobile_mode) 455static void dib3000mc_set_channel_cfg(struct dib3000mc_state *state, struct dibx000_ofdm_channel *chan, u16 seq)
559{ 456{
560 struct dib3000_state *state = fe->demodulator_priv; 457 u16 tmp;
561 deb_info("init start\n");
562
563 state->timing_offset = 0;
564 state->timing_offset_comp_done = 0;
565 458
566 wr(DIB3000MC_REG_RESTART,DIB3000MC_RESTART_CONFIG); 459 dib3000mc_set_timing(state, chan->nfft, chan->Bw, 0);
567 wr(DIB3000MC_REG_RESTART,DIB3000MC_RESTART_OFF);
568 wr(DIB3000MC_REG_CLK_CFG_1,DIB3000MC_CLK_CFG_1_POWER_UP);
569 wr(DIB3000MC_REG_CLK_CFG_2,DIB3000MC_CLK_CFG_2_PUP_MOBILE);
570 wr(DIB3000MC_REG_CLK_CFG_3,DIB3000MC_CLK_CFG_3_POWER_UP);
571 wr(DIB3000MC_REG_CLK_CFG_7,DIB3000MC_CLK_CFG_7_INIT);
572 460
573 wr(DIB3000MC_REG_RST_UNC,DIB3000MC_RST_UNC_OFF); 461// if (boost)
574 wr(DIB3000MC_REG_UNK_19,DIB3000MC_UNK_19); 462// dib3000mc_write_word(state, 100, (11 << 6) + 6);
463// else
464 dib3000mc_write_word(state, 100, (16 << 6) + 9);
575 465
576 wr(33,5); 466 dib3000mc_write_word(state, 1027, 0x0800);
577 wr(36,81); 467 dib3000mc_write_word(state, 1027, 0x0000);
578 wr(DIB3000MC_REG_UNK_88,DIB3000MC_UNK_88);
579 468
580 wr(DIB3000MC_REG_UNK_99,DIB3000MC_UNK_99); 469 //Default cfg isi offset adp
581 wr(DIB3000MC_REG_UNK_111,DIB3000MC_UNK_111_PH_N_MODE_0); /* phase noise algo off */ 470 dib3000mc_write_word(state, 26, 0x6680);
471 dib3000mc_write_word(state, 29, 0x1273);
472 dib3000mc_write_word(state, 33, 5);
473 dib3000mc_set_adp_cfg(state, 1);
474 dib3000mc_write_word(state, 133, 15564);
582 475
583 /* mobile mode - portable reception */ 476 dib3000mc_write_word(state, 12 , 0x0);
584 wr_foreach(dib3000mc_reg_mobile_mode,dib3000mc_mobile_mode[1]); 477 dib3000mc_write_word(state, 13 , 0x3e8);
478 dib3000mc_write_word(state, 14 , 0x0);
479 dib3000mc_write_word(state, 15 , 0x3f2);
585 480
586/* TUNER_PANASONIC_ENV57H12D5: */ 481 dib3000mc_write_word(state, 93,0);
587 wr_foreach(dib3000mc_reg_agc_bandwidth,dib3000mc_agc_bandwidth); 482 dib3000mc_write_word(state, 94,0);
588 wr_foreach(dib3000mc_reg_agc_bandwidth_general,dib3000mc_agc_bandwidth_general); 483 dib3000mc_write_word(state, 95,0);
589 wr_foreach(dib3000mc_reg_agc,dib3000mc_agc_tuner[1]); 484 dib3000mc_write_word(state, 96,0);
485 dib3000mc_write_word(state, 97,0);
486 dib3000mc_write_word(state, 98,0);
590 487
591 wr(DIB3000MC_REG_UNK_110,DIB3000MC_UNK_110); 488 dib3000mc_set_impulse_noise(state, 0, chan->nfft);
592 wr(26,0x6680);
593 wr(DIB3000MC_REG_UNK_1,DIB3000MC_UNK_1);
594 wr(DIB3000MC_REG_UNK_2,DIB3000MC_UNK_2);
595 wr(DIB3000MC_REG_UNK_3,DIB3000MC_UNK_3);
596 wr(DIB3000MC_REG_SEQ_TPS,DIB3000MC_SEQ_TPS_DEFAULT);
597 489
598 wr_foreach(dib3000mc_reg_bandwidth,dib3000mc_bandwidth_8mhz); 490 tmp = ((chan->nfft & 0x1) << 7) | (chan->guard << 5) | (chan->nqam << 3) | chan->vit_alpha;
599 wr_foreach(dib3000mc_reg_bandwidth_general,dib3000mc_bandwidth_general); 491 dib3000mc_write_word(state, 0, tmp);
600 492
601 wr(DIB3000MC_REG_UNK_4,DIB3000MC_UNK_4); 493 dib3000mc_write_word(state, 5, seq);
602 494
603 wr(DIB3000MC_REG_SET_DDS_FREQ_MSB,DIB3000MC_DDS_FREQ_MSB_INV_OFF); 495 tmp = (chan->vit_hrch << 4) | (chan->vit_select_hp);
604 wr(DIB3000MC_REG_SET_DDS_FREQ_LSB,DIB3000MC_DDS_FREQ_LSB); 496 if (!chan->vit_hrch || (chan->vit_hrch && chan->vit_select_hp))
497 tmp |= chan->vit_code_rate_hp << 1;
498 else
499 tmp |= chan->vit_code_rate_lp << 1;
500 dib3000mc_write_word(state, 181, tmp);
605 501
606 dib3000mc_set_timing(state,0,TRANSMISSION_MODE_8K,BANDWIDTH_8_MHZ); 502 // diversity synchro delay
607// wr_foreach(dib3000mc_reg_timing_freq,dib3000mc_timing_freq[3]); 503 tmp = dib3000mc_read_word(state, 180) & 0x000f;
504 tmp |= ((chan->nfft == 0) ? 64 : 256) * ((1 << (chan->guard)) * 3 / 2) << 4; // add 50% SFN margin
505 dib3000mc_write_word(state, 180, tmp);
608 506
609 wr(DIB3000MC_REG_UNK_120,DIB3000MC_UNK_120); 507 // restart demod
610 wr(DIB3000MC_REG_UNK_134,DIB3000MC_UNK_134); 508 tmp = dib3000mc_read_word(state, 0);
611 wr(DIB3000MC_REG_FEC_CFG,DIB3000MC_FEC_CFG); 509 dib3000mc_write_word(state, 0, tmp | (1 << 9));
510 dib3000mc_write_word(state, 0, tmp);
612 511
613 wr(DIB3000MC_REG_DIVERSITY3,DIB3000MC_DIVERSITY3_IN_OFF); 512 msleep(30);
614 513
615 dib3000mc_set_impulse_noise(state,0,TRANSMISSION_MODE_8K,BANDWIDTH_8_MHZ); 514 dib3000mc_set_impulse_noise(state, state->cfg->impulse_noise_mode, chan->nfft);
515}
616 516
617/* output mode control, just the MPEG2_SLAVE */ 517static int dib3000mc_autosearch_start(struct dvb_frontend *demod, struct dibx000_ofdm_channel *chan)
618// set_or(DIB3000MC_REG_OUTMODE,DIB3000MC_OM_SLAVE); 518{
619 wr(DIB3000MC_REG_OUTMODE,DIB3000MC_OM_SLAVE); 519 struct dib3000mc_state *state = demod->demodulator_priv;
620 wr(DIB3000MC_REG_SMO_MODE,DIB3000MC_SMO_MODE_SLAVE); 520 u16 reg;
621 wr(DIB3000MC_REG_FIFO_THRESHOLD,DIB3000MC_FIFO_THRESHOLD_SLAVE); 521// u32 val;
622 wr(DIB3000MC_REG_ELEC_OUT,DIB3000MC_ELEC_OUT_SLAVE); 522 struct dibx000_ofdm_channel fchan;
623 523
624/* MPEG2_PARALLEL_CONTINUOUS_CLOCK 524 INIT_OFDM_CHANNEL(&fchan);
625 wr(DIB3000MC_REG_OUTMODE, 525 fchan = *chan;
626 DIB3000MC_SET_OUTMODE(DIB3000MC_OM_PAR_CONT_CLK,
627 rd(DIB3000MC_REG_OUTMODE)));
628 526
629 wr(DIB3000MC_REG_SMO_MODE,
630 DIB3000MC_SMO_MODE_DEFAULT |
631 DIB3000MC_SMO_MODE_188);
632 527
633 wr(DIB3000MC_REG_FIFO_THRESHOLD,DIB3000MC_FIFO_THRESHOLD_DEFAULT); 528 /* a channel for autosearch */
634 wr(DIB3000MC_REG_ELEC_OUT,DIB3000MC_ELEC_OUT_DIV_OUT_ON); 529 reg = 0;
635*/ 530 if (chan->nfft == -1 && chan->guard == -1) reg = 7;
531 if (chan->nfft == -1 && chan->guard != -1) reg = 2;
532 if (chan->nfft != -1 && chan->guard == -1) reg = 3;
636 533
637/* diversity */ 534 fchan.nfft = 1; fchan.guard = 0; fchan.nqam = 2;
638 wr(DIB3000MC_REG_DIVERSITY1,DIB3000MC_DIVERSITY1_DEFAULT); 535 fchan.vit_alpha = 1; fchan.vit_code_rate_hp = 2; fchan.vit_code_rate_lp = 2;
639 wr(DIB3000MC_REG_DIVERSITY2,DIB3000MC_DIVERSITY2_DEFAULT); 536 fchan.vit_hrch = 0; fchan.vit_select_hp = 1;
640 537
641 set_and(DIB3000MC_REG_DIVERSITY3,DIB3000MC_DIVERSITY3_IN_OFF); 538 dib3000mc_set_channel_cfg(state, &fchan, reg);
642 539
643 set_or(DIB3000MC_REG_CLK_CFG_7,DIB3000MC_CLK_CFG_7_DIV_IN_OFF); 540 reg = dib3000mc_read_word(state, 0);
541 dib3000mc_write_word(state, 0, reg | (1 << 8));
542 dib3000mc_write_word(state, 0, reg);
644 543
645 deb_info("init end\n");
646 return 0; 544 return 0;
647} 545}
648static int dib3000mc_read_status(struct dvb_frontend* fe, fe_status_t *stat) 546
547static int dib3000mc_autosearch_is_irq(struct dvb_frontend *demod)
649{ 548{
650 struct dib3000_state* state = fe->demodulator_priv; 549 struct dib3000mc_state *state = demod->demodulator_priv;
651 u16 lock = rd(DIB3000MC_REG_LOCKING); 550 u16 irq_pending = dib3000mc_read_word(state, 511);
652 551
653 *stat = 0; 552 if (irq_pending & 0x1) // failed
654 if (DIB3000MC_AGC_LOCK(lock)) 553 return 1;
655 *stat |= FE_HAS_SIGNAL;
656 if (DIB3000MC_CARRIER_LOCK(lock))
657 *stat |= FE_HAS_CARRIER;
658 if (DIB3000MC_TPS_LOCK(lock))
659 *stat |= FE_HAS_VITERBI;
660 if (DIB3000MC_MPEG_SYNC_LOCK(lock))
661 *stat |= (FE_HAS_SYNC | FE_HAS_LOCK);
662 554
663 deb_stat("actual status is %2x fifo_level: %x,244: %x, 206: %x, 207: %x, 1040: %x\n",*stat,rd(510),rd(244),rd(206),rd(207),rd(1040)); 555 if (irq_pending & 0x2) // succeeded
556 return 2;
664 557
665 return 0; 558 return 0; // still pending
666} 559}
667 560
668static int dib3000mc_read_ber(struct dvb_frontend* fe, u32 *ber) 561static int dib3000mc_tune(struct dvb_frontend *demod, struct dibx000_ofdm_channel *ch)
669{ 562{
670 struct dib3000_state* state = fe->demodulator_priv; 563 struct dib3000mc_state *state = demod->demodulator_priv;
671 *ber = ((rd(DIB3000MC_REG_BER_MSB) << 16) | rd(DIB3000MC_REG_BER_LSB)); 564
565 // ** configure demod **
566 dib3000mc_set_channel_cfg(state, ch, 0);
567
568 // activates isi
569 dib3000mc_write_word(state, 29, 0x1073);
570
571 dib3000mc_set_adp_cfg(state, (u8)ch->nqam);
572
573 if (ch->nfft == 1) {
574 dib3000mc_write_word(state, 26, 38528);
575 dib3000mc_write_word(state, 33, 8);
576 } else {
577 dib3000mc_write_word(state, 26, 30336);
578 dib3000mc_write_word(state, 33, 6);
579 }
580
581 // if (lock)
582 // dib3000mc_set_timing(state, ch->nfft, ch->Bw, 1);
583
672 return 0; 584 return 0;
673} 585}
674 586
675static int dib3000mc_read_unc_blocks(struct dvb_frontend* fe, u32 *unc) 587static int dib3000mc_demod_output_mode(struct dvb_frontend *demod, int mode)
676{ 588{
677 struct dib3000_state* state = fe->demodulator_priv; 589 struct dib3000mc_state *state = demod->demodulator_priv;
678 590 return dib3000mc_set_output_mode(state, mode);
679 *unc = rd(DIB3000MC_REG_PACKET_ERRORS);
680 return 0;
681} 591}
682 592
683/* see dib3000mb.c for calculation comments */ 593static int dib3000mc_i2c_enumeration(struct dvb_frontend *demod[], int no_of_demods, u8 default_addr)
684static int dib3000mc_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
685{ 594{
686 struct dib3000_state* state = fe->demodulator_priv; 595 struct dib3000mc_state *st;
687 u16 val = rd(DIB3000MC_REG_SIGNAL_NOISE_LSB); 596 int k,ret=0;
688 *strength = (((val >> 6) & 0xff) << 8) + (val & 0x3f); 597 u8 new_addr;
598
599 static u8 DIB3000MC_I2C_ADDRESS[] = {20,22,24,26};
600
601 for (k = no_of_demods-1; k >= 0; k--) {
602 st = demod[k]->demodulator_priv;
603
604 /* designated i2c address */
605 new_addr = DIB3000MC_I2C_ADDRESS[k];
606
607 st->i2c_addr = new_addr;
608 if (dib3000mc_identify(st) != 0) {
609 st->i2c_addr = default_addr;
610 if (dib3000mc_identify(st) != 0) {
611 dprintk("-E- DiB3000P/MC #%d: not identified\n", k);
612 return -EINVAL;
613 }
614 }
615
616 /* turn on div_out */
617 dib3000mc_demod_output_mode(demod[k], OUTMODE_MPEG2_PAR_CONT_CLK);
618
619 // set new i2c address and force divstr (Bit 1) to value 0 (Bit 0)
620 ret |= dib3000mc_write_word(st, 1024, (new_addr << 3) | 0x1);
621 st->i2c_addr = new_addr;
622 }
623
624 for (k = 0; k < no_of_demods; k++) {
625 st = demod[k]->demodulator_priv;
626
627 ret |= dib3000mc_write_word(st, 1024, st->i2c_addr << 3);
689 628
690 deb_stat("signal: mantisse = %d, exponent = %d\n",(*strength >> 8) & 0xff, *strength & 0xff); 629 /* turn off data output */
630 dib3000mc_demod_output_mode(demod[k],OUTMODE_HIGH_Z);
631 dib3000mc_write_word(st, 769, (1 << 7) );
632
633 }
691 return 0; 634 return 0;
692} 635}
693 636
694/* see dib3000mb.c for calculation comments */ 637struct i2c_adapter * dib3000mc_get_tuner_i2c_master(struct dvb_frontend *demod, int gating)
695static int dib3000mc_read_snr(struct dvb_frontend* fe, u16 *snr)
696{ 638{
697 struct dib3000_state* state = fe->demodulator_priv; 639 struct dib3000mc_state *st = demod->demodulator_priv;
698 u16 val = rd(DIB3000MC_REG_SIGNAL_NOISE_LSB), 640 return dibx000_get_i2c_adapter(&st->i2c_master, DIBX000_I2C_INTERFACE_TUNER, gating);
699 val2 = rd(DIB3000MC_REG_SIGNAL_NOISE_MSB); 641}
700 u16 sig,noise;
701 642
702 sig = (((val >> 6) & 0xff) << 8) + (val & 0x3f); 643EXPORT_SYMBOL(dib3000mc_get_tuner_i2c_master);
703 noise = (((val >> 4) & 0xff) << 8) + ((val & 0xf) << 2) + ((val2 >> 14) & 0x3); 644
704 if (noise == 0) 645static int dib3000mc_get_frontend(struct dvb_frontend* fe,
705 *snr = 0xffff; 646 struct dvb_frontend_parameters *fep)
706 else 647{
707 *snr = (u16) sig/noise; 648 struct dib3000mc_state *state = fe->demodulator_priv;
649 u16 tps = dib3000mc_read_word(state,458);
650
651 fep->inversion = INVERSION_AUTO;
652
653 fep->u.ofdm.bandwidth = state->current_bandwidth;
654
655 switch ((tps >> 8) & 0x1) {
656 case 0: fep->u.ofdm.transmission_mode = TRANSMISSION_MODE_2K; break;
657 case 1: fep->u.ofdm.transmission_mode = TRANSMISSION_MODE_8K; break;
658 }
659
660 switch (tps & 0x3) {
661 case 0: fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_32; break;
662 case 1: fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_16; break;
663 case 2: fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_8; break;
664 case 3: fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_4; break;
665 }
666
667 switch ((tps >> 13) & 0x3) {
668 case 0: fep->u.ofdm.constellation = QPSK; break;
669 case 1: fep->u.ofdm.constellation = QAM_16; break;
670 case 2:
671 default: fep->u.ofdm.constellation = QAM_64; break;
672 }
673
674 /* as long as the frontend_param structure is fixed for hierarchical transmission I refuse to use it */
675 /* (tps >> 12) & 0x1 == hrch is used, (tps >> 9) & 0x7 == alpha */
676
677 fep->u.ofdm.hierarchy_information = HIERARCHY_NONE;
678 switch ((tps >> 5) & 0x7) {
679 case 1: fep->u.ofdm.code_rate_HP = FEC_1_2; break;
680 case 2: fep->u.ofdm.code_rate_HP = FEC_2_3; break;
681 case 3: fep->u.ofdm.code_rate_HP = FEC_3_4; break;
682 case 5: fep->u.ofdm.code_rate_HP = FEC_5_6; break;
683 case 7:
684 default: fep->u.ofdm.code_rate_HP = FEC_7_8; break;
685
686 }
687
688 switch ((tps >> 2) & 0x7) {
689 case 1: fep->u.ofdm.code_rate_LP = FEC_1_2; break;
690 case 2: fep->u.ofdm.code_rate_LP = FEC_2_3; break;
691 case 3: fep->u.ofdm.code_rate_LP = FEC_3_4; break;
692 case 5: fep->u.ofdm.code_rate_LP = FEC_5_6; break;
693 case 7:
694 default: fep->u.ofdm.code_rate_LP = FEC_7_8; break;
695 }
708 696
709 deb_stat("signal: mantisse = %d, exponent = %d\n",(sig >> 8) & 0xff, sig & 0xff);
710 deb_stat("noise: mantisse = %d, exponent = %d\n",(noise >> 8) & 0xff, noise & 0xff);
711 deb_stat("snr: %d\n",*snr);
712 return 0; 697 return 0;
713} 698}
714 699
715static int dib3000mc_sleep(struct dvb_frontend* fe) 700static int dib3000mc_set_frontend(struct dvb_frontend* fe,
701 struct dvb_frontend_parameters *fep)
716{ 702{
717 struct dib3000_state* state = fe->demodulator_priv; 703 struct dib3000mc_state *state = fe->demodulator_priv;
704 struct dibx000_ofdm_channel ch;
718 705
719 set_or(DIB3000MC_REG_CLK_CFG_7,DIB3000MC_CLK_CFG_7_PWR_DOWN); 706 INIT_OFDM_CHANNEL(&ch);
720 wr(DIB3000MC_REG_CLK_CFG_1,DIB3000MC_CLK_CFG_1_POWER_DOWN); 707 FEP2DIB(fep,&ch);
721 wr(DIB3000MC_REG_CLK_CFG_2,DIB3000MC_CLK_CFG_2_POWER_DOWN); 708
722 wr(DIB3000MC_REG_CLK_CFG_3,DIB3000MC_CLK_CFG_3_POWER_DOWN); 709 state->current_bandwidth = fep->u.ofdm.bandwidth;
723 return 0; 710 dib3000mc_set_bandwidth(fe, fep->u.ofdm.bandwidth);
711
712 if (fe->ops.tuner_ops.set_params) {
713 fe->ops.tuner_ops.set_params(fe, fep);
714 msleep(100);
715 }
716
717 if (fep->u.ofdm.transmission_mode == TRANSMISSION_MODE_AUTO ||
718 fep->u.ofdm.guard_interval == GUARD_INTERVAL_AUTO ||
719 fep->u.ofdm.constellation == QAM_AUTO ||
720 fep->u.ofdm.code_rate_HP == FEC_AUTO) {
721 int i = 100, found;
722
723 dib3000mc_autosearch_start(fe, &ch);
724 do {
725 msleep(1);
726 found = dib3000mc_autosearch_is_irq(fe);
727 } while (found == 0 && i--);
728
729 dprintk("autosearch returns: %d\n",found);
730 if (found == 0 || found == 1)
731 return 0; // no channel found
732
733 dib3000mc_get_frontend(fe, fep);
734 FEP2DIB(fep,&ch);
735 }
736
737 /* make this a config parameter */
738 dib3000mc_set_output_mode(state, OUTMODE_MPEG2_FIFO);
739
740 return dib3000mc_tune(fe, &ch);
724} 741}
725 742
726static int dib3000mc_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune) 743static int dib3000mc_read_status(struct dvb_frontend *fe, fe_status_t *stat)
727{ 744{
728 tune->min_delay_ms = 1000; 745 struct dib3000mc_state *state = fe->demodulator_priv;
746 u16 lock = dib3000mc_read_word(state, 509);
747
748 *stat = 0;
749
750 if (lock & 0x8000)
751 *stat |= FE_HAS_SIGNAL;
752 if (lock & 0x3000)
753 *stat |= FE_HAS_CARRIER;
754 if (lock & 0x0100)
755 *stat |= FE_HAS_VITERBI;
756 if (lock & 0x0010)
757 *stat |= FE_HAS_SYNC;
758 if (lock & 0x0008)
759 *stat |= FE_HAS_LOCK;
760
729 return 0; 761 return 0;
730} 762}
731 763
732static int dib3000mc_fe_init_nonmobile(struct dvb_frontend* fe) 764static int dib3000mc_read_ber(struct dvb_frontend *fe, u32 *ber)
733{ 765{
734 return dib3000mc_fe_init(fe, 0); 766 struct dib3000mc_state *state = fe->demodulator_priv;
767 *ber = (dib3000mc_read_word(state, 500) << 16) | dib3000mc_read_word(state, 501);
768 return 0;
735} 769}
736 770
737static int dib3000mc_set_frontend_and_tuner(struct dvb_frontend* fe, struct dvb_frontend_parameters *fep) 771static int dib3000mc_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
738{ 772{
739 return dib3000mc_set_frontend(fe, fep, 1); 773 struct dib3000mc_state *state = fe->demodulator_priv;
774 *unc = dib3000mc_read_word(state, 508);
775 return 0;
740} 776}
741 777
742static void dib3000mc_release(struct dvb_frontend* fe) 778static int dib3000mc_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
743{ 779{
744 struct dib3000_state *state = fe->demodulator_priv; 780 struct dib3000mc_state *state = fe->demodulator_priv;
745 kfree(state); 781 u16 val = dib3000mc_read_word(state, 392);
782 *strength = 65535 - val;
783 return 0;
746} 784}
747 785
748/* pid filter and transfer stuff */ 786static int dib3000mc_read_snr(struct dvb_frontend* fe, u16 *snr)
749static int dib3000mc_pid_control(struct dvb_frontend *fe,int index, int pid,int onoff)
750{ 787{
751 struct dib3000_state *state = fe->demodulator_priv; 788 *snr = 0x0000;
752 pid = (onoff ? pid | DIB3000_ACTIVATE_PID_FILTERING : 0);
753 wr(index+DIB3000MC_REG_FIRST_PID,pid);
754 return 0; 789 return 0;
755} 790}
756 791
757static int dib3000mc_fifo_control(struct dvb_frontend *fe, int onoff) 792static int dib3000mc_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
758{ 793{
759 struct dib3000_state *state = fe->demodulator_priv; 794 tune->min_delay_ms = 1000;
760 u16 tmp = rd(DIB3000MC_REG_SMO_MODE);
761
762 deb_xfer("%s fifo\n",onoff ? "enabling" : "disabling");
763
764 if (onoff) {
765 deb_xfer("%d %x\n",tmp & DIB3000MC_SMO_MODE_FIFO_UNFLUSH,tmp & DIB3000MC_SMO_MODE_FIFO_UNFLUSH);
766 wr(DIB3000MC_REG_SMO_MODE,tmp & DIB3000MC_SMO_MODE_FIFO_UNFLUSH);
767 } else {
768 deb_xfer("%d %x\n",tmp | DIB3000MC_SMO_MODE_FIFO_FLUSH,tmp | DIB3000MC_SMO_MODE_FIFO_FLUSH);
769 wr(DIB3000MC_REG_SMO_MODE,tmp | DIB3000MC_SMO_MODE_FIFO_FLUSH);
770 }
771 return 0; 795 return 0;
772} 796}
773 797
774static int dib3000mc_pid_parse(struct dvb_frontend *fe, int onoff) 798static void dib3000mc_release(struct dvb_frontend *fe)
775{ 799{
776 struct dib3000_state *state = fe->demodulator_priv; 800 struct dib3000mc_state *state = fe->demodulator_priv;
777 u16 tmp = rd(DIB3000MC_REG_SMO_MODE); 801 dibx000_exit_i2c_master(&state->i2c_master);
778 802 kfree(state);
779 deb_xfer("%s pid parsing\n",onoff ? "enabling" : "disabling");
780
781 if (onoff) {
782 wr(DIB3000MC_REG_SMO_MODE,tmp | DIB3000MC_SMO_MODE_PID_PARSE);
783 } else {
784 wr(DIB3000MC_REG_SMO_MODE,tmp & DIB3000MC_SMO_MODE_NO_PID_PARSE);
785 }
786 return 0;
787} 803}
788 804
789static int dib3000mc_tuner_pass_ctrl(struct dvb_frontend *fe, int onoff, u8 pll_addr) 805int dib3000mc_pid_control(struct dvb_frontend *fe, int index, int pid,int onoff)
790{ 806{
791 struct dib3000_state *state = fe->demodulator_priv; 807 struct dib3000mc_state *state = fe->demodulator_priv;
792 if (onoff) { 808 dib3000mc_write_word(state, 212 + index, onoff ? (1 << 13) | pid : 0);
793 wr(DIB3000MC_REG_TUNER, DIB3000_TUNER_WRITE_ENABLE(pll_addr));
794 } else {
795 wr(DIB3000MC_REG_TUNER, DIB3000_TUNER_WRITE_DISABLE(pll_addr));
796 }
797 return 0; 809 return 0;
798} 810}
811EXPORT_SYMBOL(dib3000mc_pid_control);
799 812
800static int dib3000mc_demod_init(struct dib3000_state *state) 813int dib3000mc_pid_parse(struct dvb_frontend *fe, int onoff)
801{ 814{
802 u16 default_addr = 0x0a; 815 struct dib3000mc_state *state = fe->demodulator_priv;
803 /* first init */ 816 u16 tmp = dib3000mc_read_word(state, 206) & ~(1 << 4);
804 if (state->config.demod_address != default_addr) { 817 tmp |= (onoff << 4);
805 deb_info("initializing the demod the first time. Setting demod addr to 0x%x\n",default_addr); 818 return dib3000mc_write_word(state, 206, tmp);
806 wr(DIB3000MC_REG_ELEC_OUT,DIB3000MC_ELEC_OUT_DIV_OUT_ON);
807 wr(DIB3000MC_REG_OUTMODE,DIB3000MC_OM_PAR_CONT_CLK);
808
809 wr(DIB3000MC_REG_RST_I2C_ADDR,
810 DIB3000MC_DEMOD_ADDR(default_addr) |
811 DIB3000MC_DEMOD_ADDR_ON);
812
813 state->config.demod_address = default_addr;
814
815 wr(DIB3000MC_REG_RST_I2C_ADDR,
816 DIB3000MC_DEMOD_ADDR(default_addr));
817 } else
818 deb_info("demod is already initialized. Demod addr: 0x%x\n",state->config.demod_address);
819 return 0;
820} 819}
820EXPORT_SYMBOL(dib3000mc_pid_parse);
821 821
822void dib3000mc_set_config(struct dvb_frontend *fe, struct dib3000mc_config *cfg)
823{
824 struct dib3000mc_state *state = fe->demodulator_priv;
825 state->cfg = cfg;
826}
827EXPORT_SYMBOL(dib3000mc_set_config);
822 828
823static struct dvb_frontend_ops dib3000mc_ops; 829static struct dvb_frontend_ops dib3000mc_ops;
824 830
825struct dvb_frontend* dib3000mc_attach(const struct dib3000_config* config, 831int dib3000mc_attach(struct i2c_adapter *i2c_adap, int no_of_demods, u8 default_addr, u8 do_i2c_enum, struct dib3000mc_config cfg[], struct dvb_frontend *demod[])
826 struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops)
827{ 832{
828 struct dib3000_state* state = NULL; 833 struct dib3000mc_state *st;
829 u16 devid; 834 int k, num=0;
830 835
831 /* allocate memory for the internal state */ 836 if (no_of_demods < 1)
832 state = kzalloc(sizeof(struct dib3000_state), GFP_KERNEL); 837 return -EINVAL;
833 if (state == NULL)
834 goto error;
835 838
836 /* setup the state */ 839 for (k = 0; k < no_of_demods; k++) {
837 state->i2c = i2c; 840 st = kzalloc(sizeof(struct dib3000mc_state), GFP_KERNEL);
838 memcpy(&state->config,config,sizeof(struct dib3000_config)); 841 if (st == NULL)
842 goto error;
839 843
840 /* check for the correct demod */ 844 num++;
841 if (rd(DIB3000_REG_MANUFACTOR_ID) != DIB3000_I2C_ID_DIBCOM)
842 goto error;
843 845
844 devid = rd(DIB3000_REG_DEVICE_ID); 846 st->cfg = &cfg[k];
845 if (devid != DIB3000MC_DEVICE_ID && devid != DIB3000P_DEVICE_ID) 847 // st->gpio_val = cfg[k].gpio_val;
846 goto error; 848 // st->gpio_dir = cfg[k].gpio_dir;
849 st->i2c_adap = i2c_adap;
847 850
848 switch (devid) { 851 demod[k] = &st->demod;
849 case DIB3000MC_DEVICE_ID: 852 demod[k]->demodulator_priv = st;
850 info("Found a DiBcom 3000M-C, interesting..."); 853 memcpy(&st->demod.ops, &dib3000mc_ops, sizeof(struct dvb_frontend_ops));
851 break;
852 case DIB3000P_DEVICE_ID:
853 info("Found a DiBcom 3000P.");
854 break;
855 }
856 854
857 /* create dvb_frontend */ 855// INIT_COMPONENT_REGISTER_ACCESS(&st->register_access, 12, 16, dib7000p_register_read, dib7000p_register_write, st);
858 memcpy(&state->frontend.ops, &dib3000mc_ops, sizeof(struct dvb_frontend_ops)); 856// demod[k]->register_access = &st->register_access;
859 state->frontend.demodulator_priv = state; 857 }
860 858
861 /* set the xfer operations */ 859 if (do_i2c_enum) {
862 xfer_ops->pid_parse = dib3000mc_pid_parse; 860 if (dib3000mc_i2c_enumeration(demod,no_of_demods,default_addr) != 0)
863 xfer_ops->fifo_ctrl = dib3000mc_fifo_control; 861 goto error;
864 xfer_ops->pid_ctrl = dib3000mc_pid_control; 862 } else {
865 xfer_ops->tuner_pass_ctrl = dib3000mc_tuner_pass_ctrl; 863 st = demod[0]->demodulator_priv;
864 st->i2c_addr = default_addr;
865 if (dib3000mc_identify(st) != 0)
866 goto error;
867 }
866 868
867 dib3000mc_demod_init(state); 869 for (k = 0; k < num; k++) {
870 st = demod[k]->demodulator_priv;
871 dibx000_init_i2c_master(&st->i2c_master, DIB3000MC, st->i2c_adap, st->i2c_addr);
872 }
868 873
869 return &state->frontend; 874 return 0;
870 875
871error: 876error:
872 kfree(state); 877 for (k = 0; k < num; k++) {
873 return NULL; 878 kfree(demod[k]->demodulator_priv);
879 demod[k] = NULL;
880 }
881 return -EINVAL;
874} 882}
883
875EXPORT_SYMBOL(dib3000mc_attach); 884EXPORT_SYMBOL(dib3000mc_attach);
876 885
877static struct dvb_frontend_ops dib3000mc_ops = { 886static struct dvb_frontend_ops dib3000mc_ops = {
878
879 .info = { 887 .info = {
880 .name = "DiBcom 3000P/M-C DVB-T", 888 .name = "DiBcom 3000MC/P",
881 .type = FE_OFDM, 889 .type = FE_OFDM,
882 .frequency_min = 44250000, 890 .frequency_min = 44250000,
883 .frequency_max = 867250000, 891 .frequency_max = 867250000,
884 .frequency_stepsize = 62500, 892 .frequency_stepsize = 62500,
885 .caps = FE_CAN_INVERSION_AUTO | 893 .caps = FE_CAN_INVERSION_AUTO |
886 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | 894 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
887 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO | 895 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
888 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO | 896 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
889 FE_CAN_TRANSMISSION_MODE_AUTO | 897 FE_CAN_TRANSMISSION_MODE_AUTO |
890 FE_CAN_GUARD_INTERVAL_AUTO | 898 FE_CAN_GUARD_INTERVAL_AUTO |
891 FE_CAN_RECOVER | 899 FE_CAN_RECOVER |
892 FE_CAN_HIERARCHY_AUTO, 900 FE_CAN_HIERARCHY_AUTO,
893 }, 901 },
894 902
895 .release = dib3000mc_release, 903 .release = dib3000mc_release,
896 904
897 .init = dib3000mc_fe_init_nonmobile, 905 .init = dib3000mc_init,
898 .sleep = dib3000mc_sleep, 906 .sleep = dib3000mc_sleep,
899 907
900 .set_frontend = dib3000mc_set_frontend_and_tuner, 908 .set_frontend = dib3000mc_set_frontend,
901 .get_frontend = dib3000mc_get_frontend, 909 .get_tune_settings = dib3000mc_fe_get_tune_settings,
902 .get_tune_settings = dib3000mc_fe_get_tune_settings, 910 .get_frontend = dib3000mc_get_frontend,
903 911
904 .read_status = dib3000mc_read_status, 912 .read_status = dib3000mc_read_status,
905 .read_ber = dib3000mc_read_ber, 913 .read_ber = dib3000mc_read_ber,
906 .read_signal_strength = dib3000mc_read_signal_strength, 914 .read_signal_strength = dib3000mc_read_signal_strength,
907 .read_snr = dib3000mc_read_snr, 915 .read_snr = dib3000mc_read_snr,
908 .read_ucblocks = dib3000mc_read_unc_blocks, 916 .read_ucblocks = dib3000mc_read_unc_blocks,
909}; 917};
910 918
911MODULE_AUTHOR(DRIVER_AUTHOR); 919MODULE_AUTHOR("Patrick Boettcher <pboettcher@dibcom.fr>");
912MODULE_DESCRIPTION(DRIVER_DESC); 920MODULE_DESCRIPTION("Driver for the DiBcom 3000MC/P COFDM demodulator");
913MODULE_LICENSE("GPL"); 921MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/dib3000mc.h b/drivers/media/dvb/frontends/dib3000mc.h
new file mode 100644
index 000000000000..fd0b2e755993
--- /dev/null
+++ b/drivers/media/dvb/frontends/dib3000mc.h
@@ -0,0 +1,58 @@
1/*
2 * Driver for DiBcom DiB3000MC/P-demodulator.
3 *
4 * Copyright (C) 2004-6 DiBcom (http://www.dibcom.fr/)
5 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher\@desy.de)
6 *
7 * This code is partially based on the previous dib3000mc.c .
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation, version 2.
12 */
13#ifndef DIB3000MC_H
14#define DIB3000MC_H
15
16#include "dibx000_common.h"
17
18struct dib3000mc_config {
19 struct dibx000_agc_config *agc;
20
21 u8 phase_noise_mode;
22 u8 impulse_noise_mode;
23
24 u8 pwm3_inversion;
25 u8 use_pwm3;
26 u16 pwm3_value;
27
28 u16 max_time;
29 u16 ln_adc_level;
30
31 u8 mobile_mode;
32
33 u8 output_mpeg2_in_188_bytes;
34};
35
36#define DEFAULT_DIB3000MC_I2C_ADDRESS 16
37#define DEFAULT_DIB3000P_I2C_ADDRESS 24
38
39#if defined(CONFIG_DVB_DIB3000MC) || defined(CONFIG_DVB_DIB3000MC_MODULE)
40extern int dib3000mc_attach(struct i2c_adapter *i2c_adap, int no_of_demods, u8 default_addr,
41 u8 do_i2c_enum, struct dib3000mc_config cfg[], struct dvb_frontend *demod[]);
42#else
43static inline struct dvb_frontend* dib3000mc_attach(const struct dib3000_config* config,
44 struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops)
45{
46 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
47 return NULL;
48}
49#endif // CONFIG_DVB_DIB3000MC
50
51extern struct i2c_adapter * dib3000mc_get_tuner_i2c_master(struct dvb_frontend *demod, int gating);
52
53extern int dib3000mc_pid_control(struct dvb_frontend *fe, int index, int pid,int onoff);
54extern int dib3000mc_pid_parse(struct dvb_frontend *fe, int onoff);
55
56extern void dib3000mc_set_config(struct dvb_frontend *, struct dib3000mc_config *);
57
58#endif
diff --git a/drivers/media/dvb/frontends/dib3000mc_priv.h b/drivers/media/dvb/frontends/dib3000mc_priv.h
deleted file mode 100644
index 2930aac7591b..000000000000
--- a/drivers/media/dvb/frontends/dib3000mc_priv.h
+++ /dev/null
@@ -1,428 +0,0 @@
1/*
2 * dib3000mc_priv.h
3 *
4 * Copyright (C) 2004 Patrick Boettcher (patrick.boettcher@desy.de)
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 * for more information see dib3000mc.c .
11 */
12
13#ifndef __DIB3000MC_PRIV_H__
14#define __DIB3000MC_PRIV_H__
15
16/*
17 * Demodulator parameters
18 * reg: 0 1 1 1 11 11 111
19 * | | | | | |
20 * | | | | | +-- alpha (000=0, 001=1, 010=2, 100=4)
21 * | | | | +----- constellation (00=QPSK, 01=16QAM, 10=64QAM)
22 * | | | +-------- guard (00=1/32, 01=1/16, 10=1/8, 11=1/4)
23 * | | +----------- transmission mode (0=2k, 1=8k)
24 * | |
25 * | +-------------- restart autosearch for parameters
26 * +---------------- restart the demodulator
27 * reg: 181 1 111 1
28 * | | |
29 * | | +- FEC applies for HP or LP (0=LP, 1=HP)
30 * | +---- FEC rate (001=1/2, 010=2/3, 011=3/4, 101=5/6, 111=7/8)
31 * +------- hierarchy on (0=no, 1=yes)
32 */
33
34/* demodulator tuning parameter and restart options */
35#define DIB3000MC_REG_DEMOD_PARM ( 0)
36#define DIB3000MC_DEMOD_PARM(a,c,g,t) ( \
37 (0x7 & a) | \
38 ((0x3 & c) << 3) | \
39 ((0x3 & g) << 5) | \
40 ((0x1 & t) << 7) )
41#define DIB3000MC_DEMOD_RST_AUTO_SRCH_ON (1 << 8)
42#define DIB3000MC_DEMOD_RST_AUTO_SRCH_OFF (0 << 8)
43#define DIB3000MC_DEMOD_RST_DEMOD_ON (1 << 9)
44#define DIB3000MC_DEMOD_RST_DEMOD_OFF (0 << 9)
45
46/* register for hierarchy parameters */
47#define DIB3000MC_REG_HRCH_PARM ( 181)
48#define DIB3000MC_HRCH_PARM(s,f,h) ( \
49 (0x1 & s) | \
50 ((0x7 & f) << 1) | \
51 ((0x1 & h) << 4) )
52
53/* timeout ??? */
54#define DIB3000MC_REG_UNK_1 ( 1)
55#define DIB3000MC_UNK_1 ( 0x04)
56
57/* timeout ??? */
58#define DIB3000MC_REG_UNK_2 ( 2)
59#define DIB3000MC_UNK_2 ( 0x04)
60
61/* timeout ??? */
62#define DIB3000MC_REG_UNK_3 ( 3)
63#define DIB3000MC_UNK_3 (0x1000)
64
65#define DIB3000MC_REG_UNK_4 ( 4)
66#define DIB3000MC_UNK_4 (0x0814)
67
68/* timeout ??? */
69#define DIB3000MC_REG_SEQ_TPS ( 5)
70#define DIB3000MC_SEQ_TPS_DEFAULT ( 1)
71#define DIB3000MC_SEQ_TPS(s,t) ( \
72 ((s & 0x0f) << 4) | \
73 ((t & 0x01) << 8) )
74#define DIB3000MC_IS_TPS(v) ((v << 8) & 0x1)
75#define DIB3000MC_IS_AS(v) ((v >> 4) & 0xf)
76
77/* parameters for the bandwidth */
78#define DIB3000MC_REG_BW_TIMOUT_MSB ( 6)
79#define DIB3000MC_REG_BW_TIMOUT_LSB ( 7)
80
81static u16 dib3000mc_reg_bandwidth[] = { 6,7,8,9,10,11,16,17 };
82
83/*static u16 dib3000mc_bandwidth_5mhz[] =
84 { 0x28, 0x9380, 0x87, 0x4100, 0x2a4, 0x4500, 0x1, 0xb0d0 };*/
85
86static u16 dib3000mc_bandwidth_6mhz[] =
87 { 0x21, 0xd040, 0x70, 0xb62b, 0x233, 0x8ed5, 0x1, 0xb0d0 };
88
89static u16 dib3000mc_bandwidth_7mhz[] =
90 { 0x1c, 0xfba5, 0x60, 0x9c25, 0x1e3, 0x0cb7, 0x1, 0xb0d0 };
91
92static u16 dib3000mc_bandwidth_8mhz[] =
93 { 0x19, 0x5c30, 0x54, 0x88a0, 0x1a6, 0xab20, 0x1, 0xb0d0 };
94
95static u16 dib3000mc_reg_bandwidth_general[] = { 12,13,14,15 };
96static u16 dib3000mc_bandwidth_general[] = { 0x0000, 0x03e8, 0x0000, 0x03f2 };
97
98/* lock mask */
99#define DIB3000MC_REG_LOCK_MASK ( 15)
100#define DIB3000MC_ACTIVATE_LOCK_MASK (0x0800)
101
102/* reset the uncorrected packet count (??? do it 5 times) */
103#define DIB3000MC_REG_RST_UNC ( 18)
104#define DIB3000MC_RST_UNC_ON ( 1)
105#define DIB3000MC_RST_UNC_OFF ( 0)
106
107#define DIB3000MC_REG_UNK_19 ( 19)
108#define DIB3000MC_UNK_19 ( 0)
109
110/* DDS frequency value (IF position) and inversion bit */
111#define DIB3000MC_REG_INVERSION ( 21)
112#define DIB3000MC_REG_SET_DDS_FREQ_MSB ( 21)
113#define DIB3000MC_DDS_FREQ_MSB_INV_OFF (0x0164)
114#define DIB3000MC_DDS_FREQ_MSB_INV_ON (0x0364)
115
116#define DIB3000MC_REG_SET_DDS_FREQ_LSB ( 22)
117#define DIB3000MC_DDS_FREQ_LSB (0x463d)
118
119/* timing frequencies setting */
120#define DIB3000MC_REG_TIMING_FREQ_MSB ( 23)
121#define DIB3000MC_REG_TIMING_FREQ_LSB ( 24)
122#define DIB3000MC_CLOCK_REF (0x151fd1)
123
124//static u16 dib3000mc_reg_timing_freq[] = { 23,24 };
125
126//static u16 dib3000mc_timing_freq[][2] = {
127// { 0x69, 0x9f18 }, /* 5 MHz */
128// { 0x7e ,0xbee9 }, /* 6 MHz */
129// { 0x93 ,0xdebb }, /* 7 MHz */
130// { 0xa8 ,0xfe8c }, /* 8 MHz */
131//};
132
133/* timeout ??? */
134static u16 dib3000mc_reg_offset[] = { 26,33 };
135
136static u16 dib3000mc_offset[][2] = {
137 { 26240, 5 }, /* default */
138 { 30336, 6 }, /* 8K */
139 { 38528, 8 }, /* 2K */
140};
141
142#define DIB3000MC_REG_ISI ( 29)
143#define DIB3000MC_ISI_DEFAULT (0x1073)
144#define DIB3000MC_ISI_ACTIVATE (0x0000)
145#define DIB3000MC_ISI_INHIBIT (0x0200)
146
147/* impulse noise control */
148static u16 dib3000mc_reg_imp_noise_ctl[] = { 34,35 };
149
150static u16 dib3000mc_imp_noise_ctl[][2] = {
151 { 0x1294, 0x1ff8 }, /* mode 0 */
152 { 0x1294, 0x1ff8 }, /* mode 1 */
153 { 0x1294, 0x1ff8 }, /* mode 2 */
154 { 0x1294, 0x1ff8 }, /* mode 3 */
155 { 0x1294, 0x1ff8 }, /* mode 4 */
156};
157
158/* AGC registers */
159static u16 dib3000mc_reg_agc[] = {
160 36,37,38,39,42,43,44,45,46,47,48,49
161};
162
163static u16 dib3000mc_agc_tuner[][12] = {
164 { 0x0051, 0x301d, 0x0000, 0x1cc7, 0xcf5c, 0x6666,
165 0xbae1, 0xa148, 0x3b5e, 0x3c1c, 0x001a, 0x2019
166 }, /* TUNER_PANASONIC_ENV77H04D5, */
167
168 { 0x0051, 0x301d, 0x0000, 0x1cc7, 0xdc29, 0x570a,
169 0xbae1, 0x8ccd, 0x3b6d, 0x551d, 0x000a, 0x951e
170 }, /* TUNER_PANASONIC_ENV57H13D5, TUNER_PANASONIC_ENV57H12D5 */
171
172 { 0x0051, 0x301d, 0x0000, 0x1cc7, 0xffff, 0xffff,
173 0xffff, 0x0000, 0xfdfd, 0x4040, 0x00fd, 0x4040
174 }, /* TUNER_SAMSUNG_DTOS333IH102, TUNER_RFAGCIN_UNKNOWN */
175
176 { 0x0196, 0x301d, 0x0000, 0x1cc7, 0xbd71, 0x5c29,
177 0xb5c3, 0x6148, 0x6569, 0x5127, 0x0033, 0x3537
178 }, /* TUNER_PROVIDER_X */
179 /* TODO TUNER_PANASONIC_ENV57H10D8, TUNER_PANASONIC_ENV57H11D8 */
180};
181
182/* AGC loop bandwidth */
183static u16 dib3000mc_reg_agc_bandwidth[] = { 40,41 };
184static u16 dib3000mc_agc_bandwidth[] = { 0x119,0x330 };
185
186static u16 dib3000mc_reg_agc_bandwidth_general[] = { 50,51,52,53,54 };
187static u16 dib3000mc_agc_bandwidth_general[] =
188 { 0x8000, 0x91ca, 0x01ba, 0x0087, 0x0087 };
189
190#define DIB3000MC_REG_IMP_NOISE_55 ( 55)
191#define DIB3000MC_IMP_NEW_ALGO(w) (w | (1<<10))
192
193/* Impulse noise params */
194static u16 dib3000mc_reg_impulse_noise[] = { 55,56,57 };
195static u16 dib3000mc_impluse_noise[][3] = {
196 { 0x489, 0x89, 0x72 }, /* 5 MHz */
197 { 0x4a5, 0xa5, 0x89 }, /* 6 MHz */
198 { 0x4c0, 0xc0, 0xa0 }, /* 7 MHz */
199 { 0x4db, 0xdb, 0xb7 }, /* 8 Mhz */
200};
201
202static u16 dib3000mc_reg_fft[] = {
203 58,59,60,61,62,63,64,65,66,67,68,69,
204 70,71,72,73,74,75,76,77,78,79,80,81,
205 82,83,84,85,86
206};
207
208static u16 dib3000mc_fft_modes[][29] = {
209 { 0x38, 0x6d9, 0x3f28, 0x7a7, 0x3a74, 0x196, 0x32a, 0x48c,
210 0x3ffe, 0x7f3, 0x2d94, 0x76, 0x53d,
211 0x3ff8, 0x7e3, 0x3320, 0x76, 0x5b3,
212 0x3feb, 0x7d2, 0x365e, 0x76, 0x48c,
213 0x3ffe, 0x5b3, 0x3feb, 0x76, 0x0, 0xd
214 }, /* fft mode 0 */
215 { 0x3b, 0x6d9, 0x3f28, 0x7a7, 0x3a74, 0x196, 0x32a, 0x48c,
216 0x3ffe, 0x7f3, 0x2d94, 0x76, 0x53d,
217 0x3ff8, 0x7e3, 0x3320, 0x76, 0x5b3,
218 0x3feb, 0x7d2, 0x365e, 0x76, 0x48c,
219 0x3ffe, 0x5b3, 0x3feb, 0x0, 0x8200, 0xd
220 }, /* fft mode 1 */
221};
222
223#define DIB3000MC_REG_UNK_88 ( 88)
224#define DIB3000MC_UNK_88 (0x0410)
225
226static u16 dib3000mc_reg_bw[] = { 93,94,95,96,97,98 };
227static u16 dib3000mc_bw[][6] = {
228 { 0,0,0,0,0,0 }, /* 5 MHz */
229 { 0,0,0,0,0,0 }, /* 6 MHz */
230 { 0,0,0,0,0,0 }, /* 7 MHz */
231 { 0x20, 0x21, 0x20, 0x23, 0x20, 0x27 }, /* 8 MHz */
232};
233
234
235/* phase noise control */
236#define DIB3000MC_REG_UNK_99 ( 99)
237#define DIB3000MC_UNK_99 (0x0220)
238
239#define DIB3000MC_REG_SCAN_BOOST ( 100)
240#define DIB3000MC_SCAN_BOOST_ON ((11 << 6) + 6)
241#define DIB3000MC_SCAN_BOOST_OFF ((16 << 6) + 9)
242
243/* timeout ??? */
244#define DIB3000MC_REG_UNK_110 ( 110)
245#define DIB3000MC_UNK_110 ( 3277)
246
247#define DIB3000MC_REG_UNK_111 ( 111)
248#define DIB3000MC_UNK_111_PH_N_MODE_0 ( 0)
249#define DIB3000MC_UNK_111_PH_N_MODE_1 (1 << 1)
250
251/* superious rm config */
252#define DIB3000MC_REG_UNK_120 ( 120)
253#define DIB3000MC_UNK_120 ( 8207)
254
255#define DIB3000MC_REG_UNK_133 ( 133)
256#define DIB3000MC_UNK_133 ( 15564)
257
258#define DIB3000MC_REG_UNK_134 ( 134)
259#define DIB3000MC_UNK_134 ( 0)
260
261/* adapter config for constellation */
262static u16 dib3000mc_reg_adp_cfg[] = { 129, 130, 131, 132 };
263
264static u16 dib3000mc_adp_cfg[][4] = {
265 { 0x99a, 0x7fae, 0x333, 0x7ff0 }, /* QPSK */
266 { 0x23d, 0x7fdf, 0x0a4, 0x7ff0 }, /* 16-QAM */
267 { 0x148, 0x7ff0, 0x0a4, 0x7ff8 }, /* 64-QAM */
268};
269
270static u16 dib3000mc_reg_mobile_mode[] = { 139, 140, 141, 175, 1032 };
271
272static u16 dib3000mc_mobile_mode[][5] = {
273 { 0x01, 0x0, 0x0, 0x00, 0x12c }, /* fixed */
274 { 0x01, 0x0, 0x0, 0x00, 0x12c }, /* portable */
275 { 0x00, 0x0, 0x0, 0x02, 0x000 }, /* mobile */
276 { 0x00, 0x0, 0x0, 0x02, 0x000 }, /* auto */
277};
278
279#define DIB3000MC_REG_DIVERSITY1 ( 177)
280#define DIB3000MC_DIVERSITY1_DEFAULT ( 1)
281
282#define DIB3000MC_REG_DIVERSITY2 ( 178)
283#define DIB3000MC_DIVERSITY2_DEFAULT ( 1)
284
285#define DIB3000MC_REG_DIVERSITY3 ( 180)
286#define DIB3000MC_DIVERSITY3_IN_OFF (0xfff0)
287#define DIB3000MC_DIVERSITY3_IN_ON (0xfff6)
288
289#define DIB3000MC_REG_FEC_CFG ( 195)
290#define DIB3000MC_FEC_CFG ( 0x10)
291
292/*
293 * reg 206, output mode
294 * 1111 1111
295 * |||| ||||
296 * |||| |||+- unk
297 * |||| ||+-- unk
298 * |||| |+--- unk (on by default)
299 * |||| +---- fifo_ctrl (1 = inhibit (flushed), 0 = active (unflushed))
300 * |||+------ pid_parse (1 = enabled, 0 = disabled)
301 * ||+------- outp_188 (1 = TS packet size 188, 0 = packet size 204)
302 * |+-------- unk
303 * +--------- unk
304 */
305
306#define DIB3000MC_REG_SMO_MODE ( 206)
307#define DIB3000MC_SMO_MODE_DEFAULT (1 << 2)
308#define DIB3000MC_SMO_MODE_FIFO_FLUSH (1 << 3)
309#define DIB3000MC_SMO_MODE_FIFO_UNFLUSH (0xfff7)
310#define DIB3000MC_SMO_MODE_PID_PARSE (1 << 4)
311#define DIB3000MC_SMO_MODE_NO_PID_PARSE (0xffef)
312#define DIB3000MC_SMO_MODE_188 (1 << 5)
313#define DIB3000MC_SMO_MODE_SLAVE (DIB3000MC_SMO_MODE_DEFAULT | \
314 DIB3000MC_SMO_MODE_188 | DIB3000MC_SMO_MODE_PID_PARSE | (1<<1))
315
316#define DIB3000MC_REG_FIFO_THRESHOLD ( 207)
317#define DIB3000MC_FIFO_THRESHOLD_DEFAULT ( 1792)
318#define DIB3000MC_FIFO_THRESHOLD_SLAVE ( 512)
319/*
320 * pidfilter
321 * it is not a hardware pidfilter but a filter which drops all pids
322 * except the ones set. When connected to USB1.1 bandwidth this is important.
323 * DiB3000P/M-C can filter up to 32 PIDs
324 */
325#define DIB3000MC_REG_FIRST_PID ( 212)
326#define DIB3000MC_NUM_PIDS ( 32)
327
328#define DIB3000MC_REG_OUTMODE ( 244)
329#define DIB3000MC_OM_PARALLEL_GATED_CLK ( 0)
330#define DIB3000MC_OM_PAR_CONT_CLK (1 << 11)
331#define DIB3000MC_OM_SERIAL (2 << 11)
332#define DIB3000MC_OM_DIVOUT_ON (4 << 11)
333#define DIB3000MC_OM_SLAVE (DIB3000MC_OM_DIVOUT_ON | DIB3000MC_OM_PAR_CONT_CLK)
334
335#define DIB3000MC_REG_RF_POWER ( 392)
336
337#define DIB3000MC_REG_FFT_POSITION ( 407)
338
339#define DIB3000MC_REG_DDS_FREQ_MSB ( 414)
340#define DIB3000MC_REG_DDS_FREQ_LSB ( 415)
341
342#define DIB3000MC_REG_TIMING_OFFS_MSB ( 416)
343#define DIB3000MC_REG_TIMING_OFFS_LSB ( 417)
344
345#define DIB3000MC_REG_TUNING_PARM ( 458)
346#define DIB3000MC_TP_QAM(v) ((v >> 13) & 0x03)
347#define DIB3000MC_TP_HRCH(v) ((v >> 12) & 0x01)
348#define DIB3000MC_TP_ALPHA(v) ((v >> 9) & 0x07)
349#define DIB3000MC_TP_FFT(v) ((v >> 8) & 0x01)
350#define DIB3000MC_TP_FEC_CR_HP(v) ((v >> 5) & 0x07)
351#define DIB3000MC_TP_FEC_CR_LP(v) ((v >> 2) & 0x07)
352#define DIB3000MC_TP_GUARD(v) (v & 0x03)
353
354#define DIB3000MC_REG_SIGNAL_NOISE_MSB ( 483)
355#define DIB3000MC_REG_SIGNAL_NOISE_LSB ( 484)
356
357#define DIB3000MC_REG_MER ( 485)
358
359#define DIB3000MC_REG_BER_MSB ( 500)
360#define DIB3000MC_REG_BER_LSB ( 501)
361
362#define DIB3000MC_REG_PACKET_ERRORS ( 503)
363
364#define DIB3000MC_REG_PACKET_ERROR_COUNT ( 506)
365
366#define DIB3000MC_REG_LOCK_507 ( 507)
367#define DIB3000MC_LOCK_507 (0x0002) // ? name correct ?
368
369#define DIB3000MC_REG_LOCKING ( 509)
370#define DIB3000MC_AGC_LOCK(v) (v & 0x8000)
371#define DIB3000MC_CARRIER_LOCK(v) (v & 0x2000)
372#define DIB3000MC_MPEG_SYNC_LOCK(v) (v & 0x0080)
373#define DIB3000MC_MPEG_DATA_LOCK(v) (v & 0x0040)
374#define DIB3000MC_TPS_LOCK(v) (v & 0x0004)
375
376#define DIB3000MC_REG_AS_IRQ ( 511)
377#define DIB3000MC_AS_IRQ_SUCCESS (1 << 1)
378#define DIB3000MC_AS_IRQ_FAIL ( 1)
379
380#define DIB3000MC_REG_TUNER ( 769)
381
382#define DIB3000MC_REG_RST_I2C_ADDR ( 1024)
383#define DIB3000MC_DEMOD_ADDR_ON ( 1)
384#define DIB3000MC_DEMOD_ADDR(a) ((a << 4) & 0x03F0)
385
386#define DIB3000MC_REG_RESTART ( 1027)
387#define DIB3000MC_RESTART_OFF (0x0000)
388#define DIB3000MC_RESTART_AGC (0x0800)
389#define DIB3000MC_RESTART_CONFIG (0x8000)
390
391#define DIB3000MC_REG_RESTART_VIT ( 1028)
392#define DIB3000MC_RESTART_VIT_OFF ( 0)
393#define DIB3000MC_RESTART_VIT_ON ( 1)
394
395#define DIB3000MC_REG_CLK_CFG_1 ( 1031)
396#define DIB3000MC_CLK_CFG_1_POWER_UP ( 0)
397#define DIB3000MC_CLK_CFG_1_POWER_DOWN (0xffff)
398
399#define DIB3000MC_REG_CLK_CFG_2 ( 1032)
400#define DIB3000MC_CLK_CFG_2_PUP_FIXED (0x012c)
401#define DIB3000MC_CLK_CFG_2_PUP_PORT (0x0104)
402#define DIB3000MC_CLK_CFG_2_PUP_MOBILE (0x0000)
403#define DIB3000MC_CLK_CFG_2_POWER_DOWN (0xffff)
404
405#define DIB3000MC_REG_CLK_CFG_3 ( 1033)
406#define DIB3000MC_CLK_CFG_3_POWER_UP ( 0)
407#define DIB3000MC_CLK_CFG_3_POWER_DOWN (0xfff5)
408
409#define DIB3000MC_REG_CLK_CFG_7 ( 1037)
410#define DIB3000MC_CLK_CFG_7_INIT ( 12592)
411#define DIB3000MC_CLK_CFG_7_POWER_UP (~0x0003)
412#define DIB3000MC_CLK_CFG_7_PWR_DOWN (0x0003)
413#define DIB3000MC_CLK_CFG_7_DIV_IN_OFF (1 << 8)
414
415/* was commented out ??? */
416#define DIB3000MC_REG_CLK_CFG_8 ( 1038)
417#define DIB3000MC_CLK_CFG_8_POWER_UP (0x160c)
418
419#define DIB3000MC_REG_CLK_CFG_9 ( 1039)
420#define DIB3000MC_CLK_CFG_9_POWER_UP ( 0)
421
422/* also clock ??? */
423#define DIB3000MC_REG_ELEC_OUT ( 1040)
424#define DIB3000MC_ELEC_OUT_HIGH_Z ( 0)
425#define DIB3000MC_ELEC_OUT_DIV_OUT_ON ( 1)
426#define DIB3000MC_ELEC_OUT_SLAVE ( 3)
427
428#endif
diff --git a/drivers/media/dvb/frontends/dibx000_common.c b/drivers/media/dvb/frontends/dibx000_common.c
new file mode 100644
index 000000000000..a18c8f45a2ee
--- /dev/null
+++ b/drivers/media/dvb/frontends/dibx000_common.c
@@ -0,0 +1,152 @@
1#include <linux/i2c.h>
2
3#include "dibx000_common.h"
4
5static int debug;
6module_param(debug, int, 0644);
7MODULE_PARM_DESC(debug, "turn on debugging (default: 0)");
8
9#define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiBX000: "); printk(args); } } while (0)
10
11static int dibx000_write_word(struct dibx000_i2c_master *mst, u16 reg, u16 val)
12{
13 u8 b[4] = {
14 (reg >> 8) & 0xff, reg & 0xff,
15 (val >> 8) & 0xff, val & 0xff,
16 };
17 struct i2c_msg msg = {
18 .addr = mst->i2c_addr, .flags = 0, .buf = b, .len = 4
19 };
20 return i2c_transfer(mst->i2c_adap, &msg, 1) != 1 ? -EREMOTEIO : 0;
21}
22
23
24static int dibx000_i2c_select_interface(struct dibx000_i2c_master *mst, enum dibx000_i2c_interface intf)
25{
26 if (mst->device_rev > DIB3000MC && mst->selected_interface != intf) {
27 dprintk("selecting interface: %d\n",intf);
28 mst->selected_interface = intf;
29 return dibx000_write_word(mst, mst->base_reg + 4, intf);
30 }
31 return 0;
32}
33
34static int dibx000_i2c_gate_ctrl(struct dibx000_i2c_master *mst, u8 tx[4], u8 addr, int onoff)
35{
36 u16 val;
37
38
39 if (onoff)
40 val = addr << 8; // bit 7 = use master or not, if 0, the gate is open
41 else
42 val = 1 << 7;
43
44 if (mst->device_rev > DIB7000)
45 val <<= 1;
46
47 tx[0] = (((mst->base_reg + 1) >> 8) & 0xff);
48 tx[1] = ( (mst->base_reg + 1) & 0xff);
49 tx[2] = val >> 8;
50 tx[3] = val & 0xff;
51
52 return 0;
53}
54
55static u32 dibx000_i2c_func(struct i2c_adapter *adapter)
56{
57 return I2C_FUNC_I2C;
58}
59
60static int dibx000_i2c_gated_tuner_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
61{
62 struct dibx000_i2c_master *mst = i2c_get_adapdata(i2c_adap);
63 struct i2c_msg m[2 + num];
64 u8 tx_open[4], tx_close[4];
65
66 memset(m,0, sizeof(struct i2c_msg) * (2 + num));
67
68 dibx000_i2c_select_interface(mst, DIBX000_I2C_INTERFACE_TUNER);
69
70 dibx000_i2c_gate_ctrl(mst, tx_open, msg[0].addr, 1);
71 m[0].addr = mst->i2c_addr;
72 m[0].buf = tx_open;
73 m[0].len = 4;
74
75 memcpy(&m[1], msg, sizeof(struct i2c_msg) * num);
76
77 dibx000_i2c_gate_ctrl(mst, tx_close, 0, 0);
78 m[num+1].addr = mst->i2c_addr;
79 m[num+1].buf = tx_close;
80 m[num+1].len = 4;
81
82 return i2c_transfer(mst->i2c_adap, m, 2+num) == 2 + num ? num : -EIO;
83}
84
85static struct i2c_algorithm dibx000_i2c_gated_tuner_algo = {
86 .master_xfer = dibx000_i2c_gated_tuner_xfer,
87 .functionality = dibx000_i2c_func,
88};
89
90struct i2c_adapter * dibx000_get_i2c_adapter(struct dibx000_i2c_master *mst, enum dibx000_i2c_interface intf, int gating)
91{
92 struct i2c_adapter *i2c = NULL;
93
94 switch (intf) {
95 case DIBX000_I2C_INTERFACE_TUNER:
96 if (gating)
97 i2c = &mst->gated_tuner_i2c_adap;
98 break;
99 default:
100 printk(KERN_ERR "DiBX000: incorrect I2C interface selected\n");
101 break;
102 }
103
104 return i2c;
105}
106EXPORT_SYMBOL(dibx000_get_i2c_adapter);
107
108static int i2c_adapter_init(struct i2c_adapter *i2c_adap, struct i2c_algorithm *algo, const char name[I2C_NAME_SIZE], struct dibx000_i2c_master *mst)
109{
110 strncpy(i2c_adap->name, name, I2C_NAME_SIZE);
111 i2c_adap->class = I2C_CLASS_TV_DIGITAL,
112 i2c_adap->algo = algo;
113 i2c_adap->algo_data = NULL;
114 i2c_set_adapdata(i2c_adap, mst);
115 if (i2c_add_adapter(i2c_adap) < 0)
116 return -ENODEV;
117 return 0;
118}
119
120int dibx000_init_i2c_master(struct dibx000_i2c_master *mst, u16 device_rev, struct i2c_adapter *i2c_adap, u8 i2c_addr)
121{
122 u8 tx[4];
123 struct i2c_msg m = { .addr = i2c_addr >> 1, .buf = tx, .len = 4 };
124
125 mst->device_rev = device_rev;
126 mst->i2c_adap = i2c_adap;
127 mst->i2c_addr = i2c_addr >> 1;
128
129 if (device_rev == DIB7000P)
130 mst->base_reg = 1024;
131 else
132 mst->base_reg = 768;
133
134 if (i2c_adapter_init(&mst->gated_tuner_i2c_adap, &dibx000_i2c_gated_tuner_algo, "DiBX000 tuner I2C bus", mst) != 0)
135 printk(KERN_ERR "DiBX000: could not initialize the tuner i2c_adapter\n");
136
137 /* initialize the i2c-master by closing the gate */
138 dibx000_i2c_gate_ctrl(mst, tx, 0, 0);
139
140 return i2c_transfer(i2c_adap, &m, 1) == 1;
141}
142EXPORT_SYMBOL(dibx000_init_i2c_master);
143
144void dibx000_exit_i2c_master(struct dibx000_i2c_master *mst)
145{
146 i2c_del_adapter(&mst->gated_tuner_i2c_adap);
147}
148EXPORT_SYMBOL(dibx000_exit_i2c_master);
149
150MODULE_AUTHOR("Patrick Boettcher <pboettcher@dibcom.fr>");
151MODULE_DESCRIPTION("Common function the DiBcom demodulator family");
152MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/dibx000_common.h b/drivers/media/dvb/frontends/dibx000_common.h
new file mode 100644
index 000000000000..bb0c65f8aee8
--- /dev/null
+++ b/drivers/media/dvb/frontends/dibx000_common.h
@@ -0,0 +1,166 @@
1#ifndef DIBX000_COMMON_H
2#define DIBX000_COMMON_H
3
4enum dibx000_i2c_interface {
5 DIBX000_I2C_INTERFACE_TUNER = 0,
6 DIBX000_I2C_INTERFACE_GPIO_1_2 = 1,
7 DIBX000_I2C_INTERFACE_GPIO_3_4 = 2
8};
9
10struct dibx000_i2c_master {
11#define DIB3000MC 1
12#define DIB7000 2
13#define DIB7000P 11
14#define DIB7000MC 12
15 u16 device_rev;
16
17 enum dibx000_i2c_interface selected_interface;
18
19// struct i2c_adapter tuner_i2c_adap;
20 struct i2c_adapter gated_tuner_i2c_adap;
21
22 struct i2c_adapter *i2c_adap;
23 u8 i2c_addr;
24
25 u16 base_reg;
26};
27
28extern int dibx000_init_i2c_master(struct dibx000_i2c_master *mst, u16 device_rev, struct i2c_adapter *i2c_adap, u8 i2c_addr);
29extern struct i2c_adapter * dibx000_get_i2c_adapter(struct dibx000_i2c_master *mst, enum dibx000_i2c_interface intf, int gating);
30extern void dibx000_exit_i2c_master(struct dibx000_i2c_master *mst);
31
32#define BAND_LBAND 0x01
33#define BAND_UHF 0x02
34#define BAND_VHF 0x04
35
36struct dibx000_agc_config {
37 /* defines the capabilities of this AGC-setting - using the BAND_-defines*/
38 u8 band_caps;
39
40 u16 setup;
41
42 u16 inv_gain;
43 u16 time_stabiliz;
44
45 u8 alpha_level;
46 u16 thlock;
47
48 u8 wbd_inv;
49 u16 wbd_ref;
50 u8 wbd_sel;
51 u8 wbd_alpha;
52
53 u16 agc1_max;
54 u16 agc1_min;
55 u16 agc2_max;
56 u16 agc2_min;
57
58 u8 agc1_pt1;
59 u8 agc1_pt2;
60 u8 agc1_pt3;
61
62 u8 agc1_slope1;
63 u8 agc1_slope2;
64
65 u8 agc2_pt1;
66 u8 agc2_pt2;
67
68 u8 agc2_slope1;
69 u8 agc2_slope2;
70
71 u8 alpha_mant;
72 u8 alpha_exp;
73
74 u8 beta_mant;
75 u8 beta_exp;
76
77 u8 perform_agc_softsplit;
78
79 struct {
80 u16 min;
81 u16 max;
82 u16 min_thres;
83 u16 max_thres;
84 } split;
85};
86
87struct dibx000_bandwidth_config {
88 u32 internal;
89 u32 sampling;
90
91 u8 pll_prediv;
92 u8 pll_ratio;
93 u8 pll_range;
94 u8 pll_reset;
95 u8 pll_bypass;
96
97 u8 enable_refdiv;
98 u8 bypclk_div;
99 u8 IO_CLK_en_core;
100 u8 ADClkSrc;
101 u8 modulo;
102
103 u16 sad_cfg;
104
105 u32 ifreq;
106 u32 timf;
107};
108
109enum dibx000_adc_states {
110 DIBX000_SLOW_ADC_ON = 0,
111 DIBX000_SLOW_ADC_OFF,
112 DIBX000_ADC_ON,
113 DIBX000_ADC_OFF,
114 DIBX000_VBG_ENABLE,
115 DIBX000_VBG_DISABLE,
116};
117
118#define BW_INDEX_TO_KHZ(v) ( (v) == BANDWIDTH_8_MHZ ? 8000 : \
119 (v) == BANDWIDTH_7_MHZ ? 7000 : \
120 (v) == BANDWIDTH_6_MHZ ? 6000 : 8000 )
121
122/* Chip output mode. */
123#define OUTMODE_HIGH_Z 0
124#define OUTMODE_MPEG2_PAR_GATED_CLK 1
125#define OUTMODE_MPEG2_PAR_CONT_CLK 2
126#define OUTMODE_MPEG2_SERIAL 7
127#define OUTMODE_DIVERSITY 4
128#define OUTMODE_MPEG2_FIFO 5
129
130/* I hope I can get rid of the following kludge in the near future */
131struct dibx000_ofdm_channel {
132 u8 Bw;
133 s16 nfft;
134 s16 guard;
135 s16 nqam;
136 s16 vit_hrch;
137 s16 vit_select_hp;
138 s16 vit_alpha;
139 s16 vit_code_rate_hp;
140 s16 vit_code_rate_lp;
141};
142
143#define FEP2DIB(fep,ch) \
144 (ch)->Bw = (fep)->u.ofdm.bandwidth; \
145 (ch)->nfft = (fep)->u.ofdm.transmission_mode == TRANSMISSION_MODE_AUTO ? -1 : (fep)->u.ofdm.transmission_mode; \
146 (ch)->guard = (fep)->u.ofdm.guard_interval == GUARD_INTERVAL_AUTO ? -1 : (fep)->u.ofdm.guard_interval; \
147 (ch)->nqam = (fep)->u.ofdm.constellation == QAM_AUTO ? -1 : (fep)->u.ofdm.constellation == QAM_64 ? 2 : (fep)->u.ofdm.constellation; \
148 (ch)->vit_hrch = 0; /* linux-dvb is not prepared for HIERARCHICAL TRANSMISSION */ \
149 (ch)->vit_select_hp = 1; \
150 (ch)->vit_alpha = 1; \
151 (ch)->vit_code_rate_hp = (fep)->u.ofdm.code_rate_HP == FEC_AUTO ? -1 : (fep)->u.ofdm.code_rate_HP; \
152 (ch)->vit_code_rate_lp = (fep)->u.ofdm.code_rate_LP == FEC_AUTO ? -1 : (fep)->u.ofdm.code_rate_LP;
153
154#define INIT_OFDM_CHANNEL(ch) do {\
155 (ch)->Bw = 0; \
156 (ch)->nfft = -1; \
157 (ch)->guard = -1; \
158 (ch)->nqam = -1; \
159 (ch)->vit_hrch = -1; \
160 (ch)->vit_select_hp = -1; \
161 (ch)->vit_alpha = -1; \
162 (ch)->vit_code_rate_hp = -1; \
163 (ch)->vit_code_rate_lp = -1; \
164} while (0)
165
166#endif
diff --git a/drivers/media/dvb/frontends/dvb-pll.c b/drivers/media/dvb/frontends/dvb-pll.c
index 2be33f27c69f..b7e7108ee5b3 100644
--- a/drivers/media/dvb/frontends/dvb-pll.c
+++ b/drivers/media/dvb/frontends/dvb-pll.c
@@ -493,6 +493,9 @@ static int dvb_pll_sleep(struct dvb_frontend *fe)
493 int i; 493 int i;
494 int result; 494 int result;
495 495
496 if (priv->i2c == NULL)
497 return -EINVAL;
498
496 for (i = 0; i < priv->pll_desc->count; i++) { 499 for (i = 0; i < priv->pll_desc->count; i++) {
497 if (priv->pll_desc->entries[i].limit == 0) 500 if (priv->pll_desc->entries[i].limit == 0)
498 break; 501 break;
@@ -611,7 +614,7 @@ static struct dvb_tuner_ops dvb_pll_tuner_ops = {
611 .get_bandwidth = dvb_pll_get_bandwidth, 614 .get_bandwidth = dvb_pll_get_bandwidth,
612}; 615};
613 616
614int dvb_pll_attach(struct dvb_frontend *fe, int pll_addr, struct i2c_adapter *i2c, struct dvb_pll_desc *desc) 617struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr, struct i2c_adapter *i2c, struct dvb_pll_desc *desc)
615{ 618{
616 u8 b1 [] = { 0 }; 619 u8 b1 [] = { 0 };
617 struct i2c_msg msg = { .addr = pll_addr, .flags = I2C_M_RD, .buf = b1, .len = 1 }; 620 struct i2c_msg msg = { .addr = pll_addr, .flags = I2C_M_RD, .buf = b1, .len = 1 };
@@ -624,14 +627,14 @@ int dvb_pll_attach(struct dvb_frontend *fe, int pll_addr, struct i2c_adapter *i2
624 627
625 ret = i2c_transfer (i2c, &msg, 1); 628 ret = i2c_transfer (i2c, &msg, 1);
626 if (ret != 1) 629 if (ret != 1)
627 return -1; 630 return NULL;
628 if (fe->ops.i2c_gate_ctrl) 631 if (fe->ops.i2c_gate_ctrl)
629 fe->ops.i2c_gate_ctrl(fe, 0); 632 fe->ops.i2c_gate_ctrl(fe, 0);
630 } 633 }
631 634
632 priv = kzalloc(sizeof(struct dvb_pll_priv), GFP_KERNEL); 635 priv = kzalloc(sizeof(struct dvb_pll_priv), GFP_KERNEL);
633 if (priv == NULL) 636 if (priv == NULL)
634 return -ENOMEM; 637 return NULL;
635 638
636 priv->pll_i2c_address = pll_addr; 639 priv->pll_i2c_address = pll_addr;
637 priv->i2c = i2c; 640 priv->i2c = i2c;
@@ -643,7 +646,7 @@ int dvb_pll_attach(struct dvb_frontend *fe, int pll_addr, struct i2c_adapter *i2
643 fe->ops.tuner_ops.info.frequency_min = desc->max; 646 fe->ops.tuner_ops.info.frequency_min = desc->max;
644 647
645 fe->tuner_priv = priv; 648 fe->tuner_priv = priv;
646 return 0; 649 return fe;
647} 650}
648EXPORT_SYMBOL(dvb_pll_attach); 651EXPORT_SYMBOL(dvb_pll_attach);
649 652
diff --git a/drivers/media/dvb/frontends/dvb-pll.h b/drivers/media/dvb/frontends/dvb-pll.h
index 66361cd18807..ed5ac5a361ae 100644
--- a/drivers/media/dvb/frontends/dvb-pll.h
+++ b/drivers/media/dvb/frontends/dvb-pll.h
@@ -57,8 +57,8 @@ extern int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf,
57 * @param pll_addr i2c address of the PLL (if used). 57 * @param pll_addr i2c address of the PLL (if used).
58 * @param i2c i2c adapter to use (set to NULL if not used). 58 * @param i2c i2c adapter to use (set to NULL if not used).
59 * @param desc dvb_pll_desc to use. 59 * @param desc dvb_pll_desc to use.
60 * @return 0 on success, nonzero on failure. 60 * @return Frontend pointer on success, NULL on failure
61 */ 61 */
62extern int dvb_pll_attach(struct dvb_frontend *fe, int pll_addr, struct i2c_adapter *i2c, struct dvb_pll_desc *desc); 62extern struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr, struct i2c_adapter *i2c, struct dvb_pll_desc *desc);
63 63
64#endif 64#endif
diff --git a/drivers/media/dvb/frontends/isl6421.c b/drivers/media/dvb/frontends/isl6421.c
index 58c34db31071..ef319369ec26 100644
--- a/drivers/media/dvb/frontends/isl6421.c
+++ b/drivers/media/dvb/frontends/isl6421.c
@@ -42,12 +42,11 @@ struct isl6421 {
42 u8 override_and; 42 u8 override_and;
43 struct i2c_adapter *i2c; 43 struct i2c_adapter *i2c;
44 u8 i2c_addr; 44 u8 i2c_addr;
45 void (*release_chain)(struct dvb_frontend* fe);
46}; 45};
47 46
48static int isl6421_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 47static int isl6421_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
49{ 48{
50 struct isl6421 *isl6421 = (struct isl6421 *) fe->misc_priv; 49 struct isl6421 *isl6421 = (struct isl6421 *) fe->sec_priv;
51 struct i2c_msg msg = { .addr = isl6421->i2c_addr, .flags = 0, 50 struct i2c_msg msg = { .addr = isl6421->i2c_addr, .flags = 0,
52 .buf = &isl6421->config, 51 .buf = &isl6421->config,
53 .len = sizeof(isl6421->config) }; 52 .len = sizeof(isl6421->config) };
@@ -75,7 +74,7 @@ static int isl6421_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage
75 74
76static int isl6421_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg) 75static int isl6421_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
77{ 76{
78 struct isl6421 *isl6421 = (struct isl6421 *) fe->misc_priv; 77 struct isl6421 *isl6421 = (struct isl6421 *) fe->sec_priv;
79 struct i2c_msg msg = { .addr = isl6421->i2c_addr, .flags = 0, 78 struct i2c_msg msg = { .addr = isl6421->i2c_addr, .flags = 0,
80 .buf = &isl6421->config, 79 .buf = &isl6421->config,
81 .len = sizeof(isl6421->config) }; 80 .len = sizeof(isl6421->config) };
@@ -93,31 +92,26 @@ static int isl6421_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
93 92
94static void isl6421_release(struct dvb_frontend *fe) 93static void isl6421_release(struct dvb_frontend *fe)
95{ 94{
96 struct isl6421 *isl6421 = (struct isl6421 *) fe->misc_priv;
97
98 /* power off */ 95 /* power off */
99 isl6421_set_voltage(fe, SEC_VOLTAGE_OFF); 96 isl6421_set_voltage(fe, SEC_VOLTAGE_OFF);
100 97
101 /* free data & call next release routine */ 98 /* free */
102 fe->ops.release = isl6421->release_chain; 99 kfree(fe->sec_priv);
103 kfree(fe->misc_priv); 100 fe->sec_priv = NULL;
104 fe->misc_priv = NULL;
105 if (fe->ops.release)
106 fe->ops.release(fe);
107} 101}
108 102
109int isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 i2c_addr, 103struct dvb_frontend *isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 i2c_addr,
110 u8 override_set, u8 override_clear) 104 u8 override_set, u8 override_clear)
111{ 105{
112 struct isl6421 *isl6421 = kmalloc(sizeof(struct isl6421), GFP_KERNEL); 106 struct isl6421 *isl6421 = kmalloc(sizeof(struct isl6421), GFP_KERNEL);
113 if (!isl6421) 107 if (!isl6421)
114 return -ENOMEM; 108 return NULL;
115 109
116 /* default configuration */ 110 /* default configuration */
117 isl6421->config = ISL6421_ISEL1; 111 isl6421->config = ISL6421_ISEL1;
118 isl6421->i2c = i2c; 112 isl6421->i2c = i2c;
119 isl6421->i2c_addr = i2c_addr; 113 isl6421->i2c_addr = i2c_addr;
120 fe->misc_priv = isl6421; 114 fe->sec_priv = isl6421;
121 115
122 /* bits which should be forced to '1' */ 116 /* bits which should be forced to '1' */
123 isl6421->override_or = override_set; 117 isl6421->override_or = override_set;
@@ -128,19 +122,17 @@ int isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 i2c_addr
128 /* detect if it is present or not */ 122 /* detect if it is present or not */
129 if (isl6421_set_voltage(fe, SEC_VOLTAGE_OFF)) { 123 if (isl6421_set_voltage(fe, SEC_VOLTAGE_OFF)) {
130 kfree(isl6421); 124 kfree(isl6421);
131 fe->misc_priv = NULL; 125 return NULL;
132 return -EIO;
133 } 126 }
134 127
135 /* install release callback */ 128 /* install release callback */
136 isl6421->release_chain = fe->ops.release; 129 fe->ops.release_sec = isl6421_release;
137 fe->ops.release = isl6421_release;
138 130
139 /* override frontend ops */ 131 /* override frontend ops */
140 fe->ops.set_voltage = isl6421_set_voltage; 132 fe->ops.set_voltage = isl6421_set_voltage;
141 fe->ops.enable_high_lnb_voltage = isl6421_enable_high_lnb_voltage; 133 fe->ops.enable_high_lnb_voltage = isl6421_enable_high_lnb_voltage;
142 134
143 return 0; 135 return fe;
144} 136}
145EXPORT_SYMBOL(isl6421_attach); 137EXPORT_SYMBOL(isl6421_attach);
146 138
diff --git a/drivers/media/dvb/frontends/isl6421.h b/drivers/media/dvb/frontends/isl6421.h
index 675f80a19b99..1916e3eb2df3 100644
--- a/drivers/media/dvb/frontends/isl6421.h
+++ b/drivers/media/dvb/frontends/isl6421.h
@@ -39,8 +39,17 @@
39#define ISL6421_ISEL1 0x20 39#define ISL6421_ISEL1 0x20
40#define ISL6421_DCL 0x40 40#define ISL6421_DCL 0x40
41 41
42#if defined(CONFIG_DVB_ISL6421) || defined(CONFIG_DVB_ISL6421_MODULE)
42/* override_set and override_clear control which system register bits (above) to always set & clear */ 43/* override_set and override_clear control which system register bits (above) to always set & clear */
43extern int isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 i2c_addr, 44extern struct dvb_frontend *isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 i2c_addr,
44 u8 override_set, u8 override_clear); 45 u8 override_set, u8 override_clear);
46#else
47static inline struct dvb_frontend *isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 i2c_addr,
48 u8 override_set, u8 override_clear)
49{
50 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
51 return NULL;
52}
53#endif // CONFIG_DVB_ISL6421
45 54
46#endif 55#endif
diff --git a/drivers/media/dvb/frontends/l64781.h b/drivers/media/dvb/frontends/l64781.h
index 83b8bc210274..21ba4a230760 100644
--- a/drivers/media/dvb/frontends/l64781.h
+++ b/drivers/media/dvb/frontends/l64781.h
@@ -31,8 +31,16 @@ struct l64781_config
31 u8 demod_address; 31 u8 demod_address;
32}; 32};
33 33
34 34#if defined(CONFIG_DVB_L64781) || defined(CONFIG_DVB_L64781_MODULE)
35extern struct dvb_frontend* l64781_attach(const struct l64781_config* config, 35extern struct dvb_frontend* l64781_attach(const struct l64781_config* config,
36 struct i2c_adapter* i2c); 36 struct i2c_adapter* i2c);
37#else
38static inline struct dvb_frontend* l64781_attach(const struct l64781_config* config,
39 struct i2c_adapter* i2c)
40{
41 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
42 return NULL;
43}
44#endif // CONFIG_DVB_L64781
37 45
38#endif // L64781_H 46#endif // L64781_H
diff --git a/drivers/media/dvb/frontends/lgdt330x.h b/drivers/media/dvb/frontends/lgdt330x.h
index bad903c6f0f8..3f96b485584c 100644
--- a/drivers/media/dvb/frontends/lgdt330x.h
+++ b/drivers/media/dvb/frontends/lgdt330x.h
@@ -52,8 +52,17 @@ struct lgdt330x_config
52 int clock_polarity_flip; 52 int clock_polarity_flip;
53}; 53};
54 54
55#if defined(CONFIG_DVB_LGDT330X) || defined(CONFIG_DVB_LGDT330X_MODULE)
55extern struct dvb_frontend* lgdt330x_attach(const struct lgdt330x_config* config, 56extern struct dvb_frontend* lgdt330x_attach(const struct lgdt330x_config* config,
56 struct i2c_adapter* i2c); 57 struct i2c_adapter* i2c);
58#else
59static inline struct dvb_frontend* lgdt330x_attach(const struct lgdt330x_config* config,
60 struct i2c_adapter* i2c)
61{
62 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
63 return NULL;
64}
65#endif // CONFIG_DVB_LGDT330X
57 66
58#endif /* LGDT330X_H */ 67#endif /* LGDT330X_H */
59 68
diff --git a/drivers/media/dvb/frontends/lnbp21.c b/drivers/media/dvb/frontends/lnbp21.c
index e933edc8dd29..2d2f58c26226 100644
--- a/drivers/media/dvb/frontends/lnbp21.c
+++ b/drivers/media/dvb/frontends/lnbp21.c
@@ -40,12 +40,11 @@ struct lnbp21 {
40 u8 override_or; 40 u8 override_or;
41 u8 override_and; 41 u8 override_and;
42 struct i2c_adapter *i2c; 42 struct i2c_adapter *i2c;
43 void (*release_chain)(struct dvb_frontend* fe);
44}; 43};
45 44
46static int lnbp21_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 45static int lnbp21_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
47{ 46{
48 struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->misc_priv; 47 struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv;
49 struct i2c_msg msg = { .addr = 0x08, .flags = 0, 48 struct i2c_msg msg = { .addr = 0x08, .flags = 0,
50 .buf = &lnbp21->config, 49 .buf = &lnbp21->config,
51 .len = sizeof(lnbp21->config) }; 50 .len = sizeof(lnbp21->config) };
@@ -73,7 +72,7 @@ static int lnbp21_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
73 72
74static int lnbp21_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg) 73static int lnbp21_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
75{ 74{
76 struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->misc_priv; 75 struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv;
77 struct i2c_msg msg = { .addr = 0x08, .flags = 0, 76 struct i2c_msg msg = { .addr = 0x08, .flags = 0,
78 .buf = &lnbp21->config, 77 .buf = &lnbp21->config,
79 .len = sizeof(lnbp21->config) }; 78 .len = sizeof(lnbp21->config) };
@@ -91,29 +90,24 @@ static int lnbp21_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
91 90
92static void lnbp21_release(struct dvb_frontend *fe) 91static void lnbp21_release(struct dvb_frontend *fe)
93{ 92{
94 struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->misc_priv;
95
96 /* LNBP power off */ 93 /* LNBP power off */
97 lnbp21_set_voltage(fe, SEC_VOLTAGE_OFF); 94 lnbp21_set_voltage(fe, SEC_VOLTAGE_OFF);
98 95
99 /* free data & call next release routine */ 96 /* free data */
100 fe->ops.release = lnbp21->release_chain; 97 kfree(fe->sec_priv);
101 kfree(fe->misc_priv); 98 fe->sec_priv = NULL;
102 fe->misc_priv = NULL;
103 if (fe->ops.release)
104 fe->ops.release(fe);
105} 99}
106 100
107int lnbp21_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 override_set, u8 override_clear) 101struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 override_set, u8 override_clear)
108{ 102{
109 struct lnbp21 *lnbp21 = kmalloc(sizeof(struct lnbp21), GFP_KERNEL); 103 struct lnbp21 *lnbp21 = kmalloc(sizeof(struct lnbp21), GFP_KERNEL);
110 if (!lnbp21) 104 if (!lnbp21)
111 return -ENOMEM; 105 return NULL;
112 106
113 /* default configuration */ 107 /* default configuration */
114 lnbp21->config = LNBP21_ISEL; 108 lnbp21->config = LNBP21_ISEL;
115 lnbp21->i2c = i2c; 109 lnbp21->i2c = i2c;
116 fe->misc_priv = lnbp21; 110 fe->sec_priv = lnbp21;
117 111
118 /* bits which should be forced to '1' */ 112 /* bits which should be forced to '1' */
119 lnbp21->override_or = override_set; 113 lnbp21->override_or = override_set;
@@ -124,19 +118,17 @@ int lnbp21_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 override_
124 /* detect if it is present or not */ 118 /* detect if it is present or not */
125 if (lnbp21_set_voltage(fe, SEC_VOLTAGE_OFF)) { 119 if (lnbp21_set_voltage(fe, SEC_VOLTAGE_OFF)) {
126 kfree(lnbp21); 120 kfree(lnbp21);
127 fe->misc_priv = NULL; 121 return NULL;
128 return -EIO;
129 } 122 }
130 123
131 /* install release callback */ 124 /* install release callback */
132 lnbp21->release_chain = fe->ops.release; 125 fe->ops.release_sec = lnbp21_release;
133 fe->ops.release = lnbp21_release;
134 126
135 /* override frontend ops */ 127 /* override frontend ops */
136 fe->ops.set_voltage = lnbp21_set_voltage; 128 fe->ops.set_voltage = lnbp21_set_voltage;
137 fe->ops.enable_high_lnb_voltage = lnbp21_enable_high_lnb_voltage; 129 fe->ops.enable_high_lnb_voltage = lnbp21_enable_high_lnb_voltage;
138 130
139 return 0; 131 return fe;
140} 132}
141EXPORT_SYMBOL(lnbp21_attach); 133EXPORT_SYMBOL(lnbp21_attach);
142 134
diff --git a/drivers/media/dvb/frontends/lnbp21.h b/drivers/media/dvb/frontends/lnbp21.h
index 047a4ab68c01..1fe1dd179312 100644
--- a/drivers/media/dvb/frontends/lnbp21.h
+++ b/drivers/media/dvb/frontends/lnbp21.h
@@ -39,7 +39,15 @@
39 39
40#include <linux/dvb/frontend.h> 40#include <linux/dvb/frontend.h>
41 41
42#if defined(CONFIG_DVB_LNBP21) || defined(CONFIG_DVB_LNBP21_MODULE)
42/* override_set and override_clear control which system register bits (above) to always set & clear */ 43/* override_set and override_clear control which system register bits (above) to always set & clear */
43extern int lnbp21_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 override_set, u8 override_clear); 44extern struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 override_set, u8 override_clear);
45#else
46static inline struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 override_set, u8 override_clear)
47{
48 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
49 return NULL;
50}
51#endif // CONFIG_DVB_LNBP21
44 52
45#endif 53#endif // _LNBP21_H
diff --git a/drivers/media/dvb/frontends/mt2060.c b/drivers/media/dvb/frontends/mt2060.c
new file mode 100644
index 000000000000..508ec1b6d1fb
--- /dev/null
+++ b/drivers/media/dvb/frontends/mt2060.c
@@ -0,0 +1,367 @@
1/*
2 * Driver for Microtune MT2060 "Single chip dual conversion broadband tuner"
3 *
4 * Copyright (c) 2006 Olivier DANET <odanet@caramail.com>
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/* In that file, frequencies are expressed in kiloHertz to avoid 32 bits overflows */
23
24#include <linux/module.h>
25#include <linux/moduleparam.h>
26#include <linux/delay.h>
27#include <linux/dvb/frontend.h>
28#include <linux/i2c.h>
29
30#include "dvb_frontend.h"
31
32#include "mt2060.h"
33#include "mt2060_priv.h"
34
35static int debug;
36module_param(debug, int, 0644);
37MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
38
39#define dprintk(args...) do { if (debug) {printk(KERN_DEBUG "MT2060: " args); printk("\n"); }} while (0)
40
41// Reads a single register
42static int mt2060_readreg(struct mt2060_priv *priv, u8 reg, u8 *val)
43{
44 struct i2c_msg msg[2] = {
45 { .addr = priv->cfg->i2c_address, .flags = 0, .buf = &reg, .len = 1 },
46 { .addr = priv->cfg->i2c_address, .flags = I2C_M_RD, .buf = val, .len = 1 },
47 };
48
49 if (i2c_transfer(priv->i2c, msg, 2) != 2) {
50 printk(KERN_WARNING "mt2060 I2C read failed\n");
51 return -EREMOTEIO;
52 }
53 return 0;
54}
55
56// Writes a single register
57static int mt2060_writereg(struct mt2060_priv *priv, u8 reg, u8 val)
58{
59 u8 buf[2] = { reg, val };
60 struct i2c_msg msg = {
61 .addr = priv->cfg->i2c_address, .flags = 0, .buf = buf, .len = 2
62 };
63
64 if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
65 printk(KERN_WARNING "mt2060 I2C write failed\n");
66 return -EREMOTEIO;
67 }
68 return 0;
69}
70
71// Writes a set of consecutive registers
72static int mt2060_writeregs(struct mt2060_priv *priv,u8 *buf, u8 len)
73{
74 struct i2c_msg msg = {
75 .addr = priv->cfg->i2c_address, .flags = 0, .buf = buf, .len = len
76 };
77 if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
78 printk(KERN_WARNING "mt2060 I2C write failed (len=%i)\n",(int)len);
79 return -EREMOTEIO;
80 }
81 return 0;
82}
83
84// Initialisation sequences
85// LNABAND=3, NUM1=0x3C, DIV1=0x74, NUM2=0x1080, DIV2=0x49
86static u8 mt2060_config1[] = {
87 REG_LO1C1,
88 0x3F, 0x74, 0x00, 0x08, 0x93
89};
90
91// FMCG=2, GP2=0, GP1=0
92static u8 mt2060_config2[] = {
93 REG_MISC_CTRL,
94 0x20, 0x1E, 0x30, 0xff, 0x80, 0xff, 0x00, 0x2c, 0x42
95};
96
97// VGAG=3, V1CSE=1
98
99#ifdef MT2060_SPURCHECK
100/* The function below calculates the frequency offset between the output frequency if2
101 and the closer cross modulation subcarrier between lo1 and lo2 up to the tenth harmonic */
102static int mt2060_spurcalc(u32 lo1,u32 lo2,u32 if2)
103{
104 int I,J;
105 int dia,diamin,diff;
106 diamin=1000000;
107 for (I = 1; I < 10; I++) {
108 J = ((2*I*lo1)/lo2+1)/2;
109 diff = I*(int)lo1-J*(int)lo2;
110 if (diff < 0) diff=-diff;
111 dia = (diff-(int)if2);
112 if (dia < 0) dia=-dia;
113 if (diamin > dia) diamin=dia;
114 }
115 return diamin;
116}
117
118#define BANDWIDTH 4000 // kHz
119
120/* Calculates the frequency offset to add to avoid spurs. Returns 0 if no offset is needed */
121static int mt2060_spurcheck(u32 lo1,u32 lo2,u32 if2)
122{
123 u32 Spur,Sp1,Sp2;
124 int I,J;
125 I=0;
126 J=1000;
127
128 Spur=mt2060_spurcalc(lo1,lo2,if2);
129 if (Spur < BANDWIDTH) {
130 /* Potential spurs detected */
131 dprintk("Spurs before : f_lo1: %d f_lo2: %d (kHz)",
132 (int)lo1,(int)lo2);
133 I=1000;
134 Sp1 = mt2060_spurcalc(lo1+I,lo2+I,if2);
135 Sp2 = mt2060_spurcalc(lo1-I,lo2-I,if2);
136
137 if (Sp1 < Sp2) {
138 J=-J; I=-I; Spur=Sp2;
139 } else
140 Spur=Sp1;
141
142 while (Spur < BANDWIDTH) {
143 I += J;
144 Spur = mt2060_spurcalc(lo1+I,lo2+I,if2);
145 }
146 dprintk("Spurs after : f_lo1: %d f_lo2: %d (kHz)",
147 (int)(lo1+I),(int)(lo2+I));
148 }
149 return I;
150}
151#endif
152
153#define IF2 36150 // IF2 frequency = 36.150 MHz
154#define FREF 16000 // Quartz oscillator 16 MHz
155
156static int mt2060_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
157{
158 struct mt2060_priv *priv;
159 int ret=0;
160 int i=0;
161 u32 freq;
162 u8 lnaband;
163 u32 f_lo1,f_lo2;
164 u32 div1,num1,div2,num2;
165 u8 b[8];
166 u32 if1;
167
168 priv = fe->tuner_priv;
169
170 if1 = priv->if1_freq;
171 b[0] = REG_LO1B1;
172 b[1] = 0xFF;
173
174 mt2060_writeregs(priv,b,2);
175
176 freq = params->frequency / 1000; // Hz -> kHz
177 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
178
179 f_lo1 = freq + if1 * 1000;
180 f_lo1 = (f_lo1 / 250) * 250;
181 f_lo2 = f_lo1 - freq - IF2;
182 // From the Comtech datasheet, the step used is 50kHz. The tuner chip could be more precise
183 f_lo2 = ((f_lo2 + 25) / 50) * 50;
184 priv->frequency = (f_lo1 - f_lo2 - IF2) * 1000,
185
186#ifdef MT2060_SPURCHECK
187 // LO-related spurs detection and correction
188 num1 = mt2060_spurcheck(f_lo1,f_lo2,IF2);
189 f_lo1 += num1;
190 f_lo2 += num1;
191#endif
192 //Frequency LO1 = 16MHz * (DIV1 + NUM1/64 )
193 num1 = f_lo1 / (FREF / 64);
194 div1 = num1 / 64;
195 num1 &= 0x3f;
196
197 // Frequency LO2 = 16MHz * (DIV2 + NUM2/8192 )
198 num2 = f_lo2 * 64 / (FREF / 128);
199 div2 = num2 / 8192;
200 num2 &= 0x1fff;
201
202 if (freq <= 95000) lnaband = 0xB0; else
203 if (freq <= 180000) lnaband = 0xA0; else
204 if (freq <= 260000) lnaband = 0x90; else
205 if (freq <= 335000) lnaband = 0x80; else
206 if (freq <= 425000) lnaband = 0x70; else
207 if (freq <= 480000) lnaband = 0x60; else
208 if (freq <= 570000) lnaband = 0x50; else
209 if (freq <= 645000) lnaband = 0x40; else
210 if (freq <= 730000) lnaband = 0x30; else
211 if (freq <= 810000) lnaband = 0x20; else lnaband = 0x10;
212
213 b[0] = REG_LO1C1;
214 b[1] = lnaband | ((num1 >>2) & 0x0F);
215 b[2] = div1;
216 b[3] = (num2 & 0x0F) | ((num1 & 3) << 4);
217 b[4] = num2 >> 4;
218 b[5] = ((num2 >>12) & 1) | (div2 << 1);
219
220 dprintk("IF1: %dMHz",(int)if1);
221 dprintk("PLL freq=%dkHz f_lo1=%dkHz f_lo2=%dkHz",(int)freq,(int)f_lo1,(int)f_lo2);
222 dprintk("PLL div1=%d num1=%d div2=%d num2=%d",(int)div1,(int)num1,(int)div2,(int)num2);
223 dprintk("PLL [1..5]: %2x %2x %2x %2x %2x",(int)b[1],(int)b[2],(int)b[3],(int)b[4],(int)b[5]);
224
225 mt2060_writeregs(priv,b,6);
226
227 //Waits for pll lock or timeout
228 i = 0;
229 do {
230 mt2060_readreg(priv,REG_LO_STATUS,b);
231 if ((b[0] & 0x88)==0x88)
232 break;
233 msleep(4);
234 i++;
235 } while (i<10);
236
237 return ret;
238}
239
240static void mt2060_calibrate(struct mt2060_priv *priv)
241{
242 u8 b = 0;
243 int i = 0;
244
245 if (mt2060_writeregs(priv,mt2060_config1,sizeof(mt2060_config1)))
246 return;
247 if (mt2060_writeregs(priv,mt2060_config2,sizeof(mt2060_config2)))
248 return;
249
250 do {
251 b |= (1 << 6); // FM1SS;
252 mt2060_writereg(priv, REG_LO2C1,b);
253 msleep(20);
254
255 if (i == 0) {
256 b |= (1 << 7); // FM1CA;
257 mt2060_writereg(priv, REG_LO2C1,b);
258 b &= ~(1 << 7); // FM1CA;
259 msleep(20);
260 }
261
262 b &= ~(1 << 6); // FM1SS
263 mt2060_writereg(priv, REG_LO2C1,b);
264
265 msleep(20);
266 i++;
267 } while (i < 9);
268
269 i = 0;
270 while (i++ < 10 && mt2060_readreg(priv, REG_MISC_STAT, &b) == 0 && (b & (1 << 6)) == 0)
271 msleep(20);
272
273 if (i < 10) {
274 mt2060_readreg(priv, REG_FM_FREQ, &priv->fmfreq); // now find out, what is fmreq used for :)
275 dprintk("calibration was successful: %d", (int)priv->fmfreq);
276 } else
277 dprintk("FMCAL timed out");
278}
279
280static int mt2060_get_frequency(struct dvb_frontend *fe, u32 *frequency)
281{
282 struct mt2060_priv *priv = fe->tuner_priv;
283 *frequency = priv->frequency;
284 return 0;
285}
286
287static int mt2060_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
288{
289 struct mt2060_priv *priv = fe->tuner_priv;
290 *bandwidth = priv->bandwidth;
291 return 0;
292}
293
294static int mt2060_init(struct dvb_frontend *fe)
295{
296 struct mt2060_priv *priv = fe->tuner_priv;
297 return mt2060_writereg(priv, REG_VGAG,0x33);
298}
299
300static int mt2060_sleep(struct dvb_frontend *fe)
301{
302 struct mt2060_priv *priv = fe->tuner_priv;
303 return mt2060_writereg(priv, REG_VGAG,0x30);
304}
305
306static int mt2060_release(struct dvb_frontend *fe)
307{
308 kfree(fe->tuner_priv);
309 fe->tuner_priv = NULL;
310 return 0;
311}
312
313static const struct dvb_tuner_ops mt2060_tuner_ops = {
314 .info = {
315 .name = "Microtune MT2060",
316 .frequency_min = 48000000,
317 .frequency_max = 860000000,
318 .frequency_step = 50000,
319 },
320
321 .release = mt2060_release,
322
323 .init = mt2060_init,
324 .sleep = mt2060_sleep,
325
326 .set_params = mt2060_set_params,
327 .get_frequency = mt2060_get_frequency,
328 .get_bandwidth = mt2060_get_bandwidth
329};
330
331/* This functions tries to identify a MT2060 tuner by reading the PART/REV register. This is hasty. */
332int mt2060_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct mt2060_config *cfg, u16 if1)
333{
334 struct mt2060_priv *priv = NULL;
335 u8 id = 0;
336
337 priv = kzalloc(sizeof(struct mt2060_priv), GFP_KERNEL);
338 if (priv == NULL)
339 return -ENOMEM;
340
341 priv->cfg = cfg;
342 priv->i2c = i2c;
343 priv->if1_freq = if1;
344
345 if (mt2060_readreg(priv,REG_PART_REV,&id) != 0) {
346 kfree(priv);
347 return -ENODEV;
348 }
349
350 if (id != PART_REV) {
351 kfree(priv);
352 return -ENODEV;
353 }
354 printk(KERN_INFO "MT2060: successfully identified (IF1 = %d)\n", if1);
355 memcpy(&fe->ops.tuner_ops, &mt2060_tuner_ops, sizeof(struct dvb_tuner_ops));
356
357 fe->tuner_priv = priv;
358
359 mt2060_calibrate(priv);
360
361 return 0;
362}
363EXPORT_SYMBOL(mt2060_attach);
364
365MODULE_AUTHOR("Olivier DANET");
366MODULE_DESCRIPTION("Microtune MT2060 silicon tuner driver");
367MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/mt2060.h b/drivers/media/dvb/frontends/mt2060.h
new file mode 100644
index 000000000000..c58b03e82345
--- /dev/null
+++ b/drivers/media/dvb/frontends/mt2060.h
@@ -0,0 +1,35 @@
1/*
2 * Driver for Microtune MT2060 "Single chip dual conversion broadband tuner"
3 *
4 * Copyright (c) 2006 Olivier DANET <odanet@caramail.com>
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#ifndef MT2060_H
23#define MT2060_H
24
25struct dvb_frontend;
26struct i2c_adapter;
27
28struct mt2060_config {
29 u8 i2c_address;
30 /* Shall we add settings for the discrete outputs ? */
31};
32
33extern int mt2060_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct mt2060_config *cfg, u16 if1);
34
35#endif
diff --git a/drivers/media/dvb/frontends/mt2060_priv.h b/drivers/media/dvb/frontends/mt2060_priv.h
new file mode 100644
index 000000000000..5eaccdefd0b0
--- /dev/null
+++ b/drivers/media/dvb/frontends/mt2060_priv.h
@@ -0,0 +1,105 @@
1/*
2 * Driver for Microtune MT2060 "Single chip dual conversion broadband tuner"
3 *
4 * Copyright (c) 2006 Olivier DANET <odanet@caramail.com>
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#ifndef MT2060_PRIV_H
23#define MT2060_PRIV_H
24
25// Uncomment the #define below to enable spurs checking. The results where quite unconvincing.
26// #define MT2060_SPURCHECK
27
28/* This driver is based on the information available in the datasheet of the
29 "Comtech SDVBT-3K6M" tuner ( K1000737843.pdf ) which features the MT2060 register map :
30
31 I2C Address : 0x60
32
33 Reg.No | B7 | B6 | B5 | B4 | B3 | B2 | B1 | B0 | ( defaults )
34 --------------------------------------------------------------------------------
35 00 | [ PART ] | [ REV ] | R = 0x63
36 01 | [ LNABAND ] | [ NUM1(5:2) ] | RW = 0x3F
37 02 | [ DIV1 ] | RW = 0x74
38 03 | FM1CA | FM1SS | [ NUM1(1:0) ] | [ NUM2(3:0) ] | RW = 0x00
39 04 | NUM2(11:4) ] | RW = 0x08
40 05 | [ DIV2 ] |NUM2(12)| RW = 0x93
41 06 | L1LK | [ TAD1 ] | L2LK | [ TAD2 ] | R
42 07 | [ FMF ] | R
43 08 | ? | FMCAL | ? | ? | ? | ? | ? | TEMP | R
44 09 | 0 | 0 | [ FMGC ] | 0 | GP02 | GP01 | 0 | RW = 0x20
45 0A | ??
46 0B | 0 | 0 | 1 | 1 | 0 | 0 | [ VGAG ] | RW = 0x30
47 0C | V1CSE | 1 | 1 | 1 | 1 | 1 | 1 | 1 | RW = 0xFF
48 0D | 1 | 0 | [ V1CS ] | RW = 0xB0
49 0E | ??
50 0F | ??
51 10 | ??
52 11 | [ LOTO ] | 0 | 0 | 1 | 0 | RW = 0x42
53
54 PART : Part code : 6 for MT2060
55 REV : Revision code : 3 for current revision
56 LNABAND : Input frequency range : ( See code for details )
57 NUM1 / DIV1 / NUM2 / DIV2 : Frequencies programming ( See code for details )
58 FM1CA : Calibration Start Bit
59 FM1SS : Calibration Single Step bit
60 L1LK : LO1 Lock Detect
61 TAD1 : Tune Line ADC ( ? )
62 L2LK : LO2 Lock Detect
63 TAD2 : Tune Line ADC ( ? )
64 FMF : Estimated first IF Center frequency Offset ( ? )
65 FM1CAL : Calibration done bit
66 TEMP : On chip temperature sensor
67 FMCG : Mixer 1 Cap Gain ( ? )
68 GP01 / GP02 : Programmable digital outputs. Unconnected pins ?
69 V1CSE : LO1 VCO Automatic Capacitor Select Enable ( ? )
70 V1CS : LO1 Capacitor Selection Value ( ? )
71 LOTO : LO Timeout ( ? )
72 VGAG : Tuner Output gain
73*/
74
75#define I2C_ADDRESS 0x60
76
77#define REG_PART_REV 0
78#define REG_LO1C1 1
79#define REG_LO1C2 2
80#define REG_LO2C1 3
81#define REG_LO2C2 4
82#define REG_LO2C3 5
83#define REG_LO_STATUS 6
84#define REG_FM_FREQ 7
85#define REG_MISC_STAT 8
86#define REG_MISC_CTRL 9
87#define REG_RESERVED_A 0x0A
88#define REG_VGAG 0x0B
89#define REG_LO1B1 0x0C
90#define REG_LO1B2 0x0D
91#define REG_LOTO 0x11
92
93#define PART_REV 0x63 // The current driver works only with PART=6 and REV=3 chips
94
95struct mt2060_priv {
96 struct mt2060_config *cfg;
97 struct i2c_adapter *i2c;
98
99 u32 frequency;
100 u32 bandwidth;
101 u16 if1_freq;
102 u8 fmfreq;
103};
104
105#endif
diff --git a/drivers/media/dvb/frontends/mt312.h b/drivers/media/dvb/frontends/mt312.h
index 666a1bd1c244..7112fb4d58ac 100644
--- a/drivers/media/dvb/frontends/mt312.h
+++ b/drivers/media/dvb/frontends/mt312.h
@@ -34,8 +34,16 @@ struct mt312_config
34 u8 demod_address; 34 u8 demod_address;
35}; 35};
36 36
37#if defined(CONFIG_DVB_MT312) || defined(CONFIG_DVB_MT312_MODULE)
37struct dvb_frontend* vp310_mt312_attach(const struct mt312_config* config, 38struct dvb_frontend* vp310_mt312_attach(const struct mt312_config* config,
38 struct i2c_adapter* i2c); 39 struct i2c_adapter* i2c);
39 40#else
41static inline struct dvb_frontend* vp310_mt312_attach(const struct mt312_config* config,
42 struct i2c_adapter* i2c)
43{
44 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
45 return NULL;
46}
47#endif // CONFIG_DVB_MT312
40 48
41#endif // MT312_H 49#endif // MT312_H
diff --git a/drivers/media/dvb/frontends/mt352.c b/drivers/media/dvb/frontends/mt352.c
index 5de7376c94ce..87e31ca7e108 100644
--- a/drivers/media/dvb/frontends/mt352.c
+++ b/drivers/media/dvb/frontends/mt352.c
@@ -70,7 +70,7 @@ static int mt352_single_write(struct dvb_frontend *fe, u8 reg, u8 val)
70 return 0; 70 return 0;
71} 71}
72 72
73int mt352_write(struct dvb_frontend* fe, u8* ibuf, int ilen) 73static int _mt352_write(struct dvb_frontend* fe, u8* ibuf, int ilen)
74{ 74{
75 int err,i; 75 int err,i;
76 for (i=0; i < ilen-1; i++) 76 for (i=0; i < ilen-1; i++)
@@ -107,7 +107,7 @@ static int mt352_sleep(struct dvb_frontend* fe)
107{ 107{
108 static u8 mt352_softdown[] = { CLOCK_CTL, 0x20, 0x08 }; 108 static u8 mt352_softdown[] = { CLOCK_CTL, 0x20, 0x08 };
109 109
110 mt352_write(fe, mt352_softdown, sizeof(mt352_softdown)); 110 _mt352_write(fe, mt352_softdown, sizeof(mt352_softdown));
111 return 0; 111 return 0;
112} 112}
113 113
@@ -293,14 +293,14 @@ static int mt352_set_parameters(struct dvb_frontend* fe,
293 fe->ops.i2c_gate_ctrl(fe, 0); 293 fe->ops.i2c_gate_ctrl(fe, 0);
294 } 294 }
295 295
296 mt352_write(fe, buf, 8); 296 _mt352_write(fe, buf, 8);
297 mt352_write(fe, fsm_go, 2); 297 _mt352_write(fe, fsm_go, 2);
298 } else { 298 } else {
299 if (fe->ops.tuner_ops.calc_regs) { 299 if (fe->ops.tuner_ops.calc_regs) {
300 fe->ops.tuner_ops.calc_regs(fe, param, buf+8, 5); 300 fe->ops.tuner_ops.calc_regs(fe, param, buf+8, 5);
301 buf[8] <<= 1; 301 buf[8] <<= 1;
302 mt352_write(fe, buf, sizeof(buf)); 302 _mt352_write(fe, buf, sizeof(buf));
303 mt352_write(fe, tuner_go, 2); 303 _mt352_write(fe, tuner_go, 2);
304 } 304 }
305 } 305 }
306 306
@@ -522,7 +522,7 @@ static int mt352_init(struct dvb_frontend* fe)
522 (mt352_read_register(state, CONFIG) & 0x20) == 0) { 522 (mt352_read_register(state, CONFIG) & 0x20) == 0) {
523 523
524 /* Do a "hard" reset */ 524 /* Do a "hard" reset */
525 mt352_write(fe, mt352_reset_attach, sizeof(mt352_reset_attach)); 525 _mt352_write(fe, mt352_reset_attach, sizeof(mt352_reset_attach));
526 return state->config.demod_init(fe); 526 return state->config.demod_init(fe);
527 } 527 }
528 528
@@ -585,6 +585,7 @@ static struct dvb_frontend_ops mt352_ops = {
585 585
586 .init = mt352_init, 586 .init = mt352_init,
587 .sleep = mt352_sleep, 587 .sleep = mt352_sleep,
588 .write = _mt352_write,
588 589
589 .set_frontend = mt352_set_parameters, 590 .set_frontend = mt352_set_parameters,
590 .get_frontend = mt352_get_parameters, 591 .get_frontend = mt352_get_parameters,
@@ -605,4 +606,3 @@ MODULE_AUTHOR("Holger Waechtler, Daniel Mack, Antonio Mancuso");
605MODULE_LICENSE("GPL"); 606MODULE_LICENSE("GPL");
606 607
607EXPORT_SYMBOL(mt352_attach); 608EXPORT_SYMBOL(mt352_attach);
608EXPORT_SYMBOL(mt352_write);
diff --git a/drivers/media/dvb/frontends/mt352.h b/drivers/media/dvb/frontends/mt352.h
index 9e7ff4b8fe5f..0035c2e2d7c2 100644
--- a/drivers/media/dvb/frontends/mt352.h
+++ b/drivers/media/dvb/frontends/mt352.h
@@ -51,9 +51,23 @@ struct mt352_config
51 int (*demod_init)(struct dvb_frontend* fe); 51 int (*demod_init)(struct dvb_frontend* fe);
52}; 52};
53 53
54#if defined(CONFIG_DVB_MT352) || defined(CONFIG_DVB_MT352_MODULE)
54extern struct dvb_frontend* mt352_attach(const struct mt352_config* config, 55extern struct dvb_frontend* mt352_attach(const struct mt352_config* config,
55 struct i2c_adapter* i2c); 56 struct i2c_adapter* i2c);
57#else
58static inline struct dvb_frontend* mt352_attach(const struct mt352_config* config,
59 struct i2c_adapter* i2c)
60{
61 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
62 return NULL;
63}
64#endif // CONFIG_DVB_MT352
56 65
57extern int mt352_write(struct dvb_frontend* fe, u8* ibuf, int ilen); 66static inline int mt352_write(struct dvb_frontend *fe, u8 *buf, int len) {
67 int r = 0;
68 if (fe->ops.write)
69 r = fe->ops.write(fe, buf, len);
70 return r;
71}
58 72
59#endif // MT352_H 73#endif // MT352_H
diff --git a/drivers/media/dvb/frontends/nxt200x.h b/drivers/media/dvb/frontends/nxt200x.h
index 34d61735845b..2eb220e98062 100644
--- a/drivers/media/dvb/frontends/nxt200x.h
+++ b/drivers/media/dvb/frontends/nxt200x.h
@@ -45,8 +45,17 @@ struct nxt200x_config
45 int (*set_ts_params)(struct dvb_frontend* fe, int is_punctured); 45 int (*set_ts_params)(struct dvb_frontend* fe, int is_punctured);
46}; 46};
47 47
48#if defined(CONFIG_DVB_NXT200X) || defined(CONFIG_DVB_NXT200X_MODULE)
48extern struct dvb_frontend* nxt200x_attach(const struct nxt200x_config* config, 49extern struct dvb_frontend* nxt200x_attach(const struct nxt200x_config* config,
49 struct i2c_adapter* i2c); 50 struct i2c_adapter* i2c);
51#else
52static inline struct dvb_frontend* nxt200x_attach(const struct nxt200x_config* config,
53 struct i2c_adapter* i2c)
54{
55 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
56 return NULL;
57}
58#endif // CONFIG_DVB_NXT200X
50 59
51#endif /* NXT200X_H */ 60#endif /* NXT200X_H */
52 61
diff --git a/drivers/media/dvb/frontends/nxt6000.h b/drivers/media/dvb/frontends/nxt6000.h
index 117031d11708..9397393a6bd1 100644
--- a/drivers/media/dvb/frontends/nxt6000.h
+++ b/drivers/media/dvb/frontends/nxt6000.h
@@ -33,7 +33,16 @@ struct nxt6000_config
33 u8 clock_inversion:1; 33 u8 clock_inversion:1;
34}; 34};
35 35
36#if defined(CONFIG_DVB_NXT6000) || defined(CONFIG_DVB_NXT6000_MODULE)
36extern struct dvb_frontend* nxt6000_attach(const struct nxt6000_config* config, 37extern struct dvb_frontend* nxt6000_attach(const struct nxt6000_config* config,
37 struct i2c_adapter* i2c); 38 struct i2c_adapter* i2c);
39#else
40static inline struct dvb_frontend* nxt6000_attach(const struct nxt6000_config* config,
41 struct i2c_adapter* i2c)
42{
43 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
44 return NULL;
45}
46#endif // CONFIG_DVB_NXT6000
38 47
39#endif // NXT6000_H 48#endif // NXT6000_H
diff --git a/drivers/media/dvb/frontends/or51132.h b/drivers/media/dvb/frontends/or51132.h
index 89658883abf5..9718be4fb835 100644
--- a/drivers/media/dvb/frontends/or51132.h
+++ b/drivers/media/dvb/frontends/or51132.h
@@ -34,8 +34,17 @@ struct or51132_config
34 int (*set_ts_params)(struct dvb_frontend* fe, int is_punctured); 34 int (*set_ts_params)(struct dvb_frontend* fe, int is_punctured);
35}; 35};
36 36
37#if defined(CONFIG_DVB_OR51132) || defined(CONFIG_DVB_OR51132_MODULE)
37extern struct dvb_frontend* or51132_attach(const struct or51132_config* config, 38extern struct dvb_frontend* or51132_attach(const struct or51132_config* config,
38 struct i2c_adapter* i2c); 39 struct i2c_adapter* i2c);
40#else
41static inline struct dvb_frontend* or51132_attach(const struct or51132_config* config,
42 struct i2c_adapter* i2c)
43{
44 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
45 return NULL;
46}
47#endif // CONFIG_DVB_OR51132
39 48
40#endif // OR51132_H 49#endif // OR51132_H
41 50
diff --git a/drivers/media/dvb/frontends/or51211.h b/drivers/media/dvb/frontends/or51211.h
index 13a5a3afbf8b..10a5419f9e00 100644
--- a/drivers/media/dvb/frontends/or51211.h
+++ b/drivers/media/dvb/frontends/or51211.h
@@ -37,8 +37,17 @@ struct or51211_config
37 void (*sleep)(struct dvb_frontend * fe); 37 void (*sleep)(struct dvb_frontend * fe);
38}; 38};
39 39
40#if defined(CONFIG_DVB_OR51211) || defined(CONFIG_DVB_OR51211_MODULE)
40extern struct dvb_frontend* or51211_attach(const struct or51211_config* config, 41extern struct dvb_frontend* or51211_attach(const struct or51211_config* config,
41 struct i2c_adapter* i2c); 42 struct i2c_adapter* i2c);
43#else
44static inline struct dvb_frontend* or51211_attach(const struct or51211_config* config,
45 struct i2c_adapter* i2c)
46{
47 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
48 return NULL;
49}
50#endif // CONFIG_DVB_OR51211
42 51
43#endif // OR51211_H 52#endif // OR51211_H
44 53
diff --git a/drivers/media/dvb/frontends/s5h1420.h b/drivers/media/dvb/frontends/s5h1420.h
index 4e39015fa67e..efc54d7f3c55 100644
--- a/drivers/media/dvb/frontends/s5h1420.h
+++ b/drivers/media/dvb/frontends/s5h1420.h
@@ -34,7 +34,16 @@ struct s5h1420_config
34 u8 invert:1; 34 u8 invert:1;
35}; 35};
36 36
37#if defined(CONFIG_DVB_S5H1420) || defined(CONFIG_DVB_S5H1420_MODULE)
37extern struct dvb_frontend* s5h1420_attach(const struct s5h1420_config* config, 38extern struct dvb_frontend* s5h1420_attach(const struct s5h1420_config* config,
38 struct i2c_adapter* i2c); 39 struct i2c_adapter* i2c);
40#else
41static inline struct dvb_frontend* s5h1420_attach(const struct s5h1420_config* config,
42 struct i2c_adapter* i2c)
43{
44 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
45 return NULL;
46}
47#endif // CONFIG_DVB_S5H1420
39 48
40#endif // S5H1420_H 49#endif // S5H1420_H
diff --git a/drivers/media/dvb/frontends/sp8870.h b/drivers/media/dvb/frontends/sp8870.h
index 93afbb969d6b..4cf27d3b10f2 100644
--- a/drivers/media/dvb/frontends/sp8870.h
+++ b/drivers/media/dvb/frontends/sp8870.h
@@ -35,7 +35,16 @@ struct sp8870_config
35 int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name); 35 int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name);
36}; 36};
37 37
38#if defined(CONFIG_DVB_SP8870) || defined(CONFIG_DVB_SP8870_MODULE)
38extern struct dvb_frontend* sp8870_attach(const struct sp8870_config* config, 39extern struct dvb_frontend* sp8870_attach(const struct sp8870_config* config,
39 struct i2c_adapter* i2c); 40 struct i2c_adapter* i2c);
41#else
42static inline struct dvb_frontend* sp8870_attach(const struct sp8870_config* config,
43 struct i2c_adapter* i2c)
44{
45 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
46 return NULL;
47}
48#endif // CONFIG_DVB_SP8870
40 49
41#endif // SP8870_H 50#endif // SP8870_H
diff --git a/drivers/media/dvb/frontends/sp887x.h b/drivers/media/dvb/frontends/sp887x.h
index c44b0ebdf1e2..cab7ea644dfa 100644
--- a/drivers/media/dvb/frontends/sp887x.h
+++ b/drivers/media/dvb/frontends/sp887x.h
@@ -17,7 +17,16 @@ struct sp887x_config
17 int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name); 17 int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name);
18}; 18};
19 19
20#if defined(CONFIG_DVB_SP887X) || defined(CONFIG_DVB_SP887X_MODULE)
20extern struct dvb_frontend* sp887x_attach(const struct sp887x_config* config, 21extern struct dvb_frontend* sp887x_attach(const struct sp887x_config* config,
21 struct i2c_adapter* i2c); 22 struct i2c_adapter* i2c);
23#else
24static inline struct dvb_frontend* sp887x_attach(const struct sp887x_config* config,
25 struct i2c_adapter* i2c)
26{
27 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
28 return NULL;
29}
30#endif // CONFIG_DVB_SP887X
22 31
23#endif // SP887X_H 32#endif // SP887X_H
diff --git a/drivers/media/dvb/frontends/stv0297.h b/drivers/media/dvb/frontends/stv0297.h
index 1da5384fb985..760b80db43a5 100644
--- a/drivers/media/dvb/frontends/stv0297.h
+++ b/drivers/media/dvb/frontends/stv0297.h
@@ -42,7 +42,16 @@ struct stv0297_config
42 u8 stop_during_read:1; 42 u8 stop_during_read:1;
43}; 43};
44 44
45#if defined(CONFIG_DVB_STV0297) || defined(CONFIG_DVB_STV0297_MODULE)
45extern struct dvb_frontend* stv0297_attach(const struct stv0297_config* config, 46extern struct dvb_frontend* stv0297_attach(const struct stv0297_config* config,
46 struct i2c_adapter* i2c); 47 struct i2c_adapter* i2c);
48#else
49static inline struct dvb_frontend* stv0297_attach(const struct stv0297_config* config,
50 struct i2c_adapter* i2c)
51{
52 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
53 return NULL;
54}
55#endif // CONFIG_DVB_STV0297
47 56
48#endif // STV0297_H 57#endif // STV0297_H
diff --git a/drivers/media/dvb/frontends/stv0299.c b/drivers/media/dvb/frontends/stv0299.c
index 96648a75440d..93483769eca8 100644
--- a/drivers/media/dvb/frontends/stv0299.c
+++ b/drivers/media/dvb/frontends/stv0299.c
@@ -92,11 +92,14 @@ static int stv0299_writeregI (struct stv0299_state* state, u8 reg, u8 data)
92 return (ret != 1) ? -EREMOTEIO : 0; 92 return (ret != 1) ? -EREMOTEIO : 0;
93} 93}
94 94
95int stv0299_writereg (struct dvb_frontend* fe, u8 reg, u8 data) 95int stv0299_write(struct dvb_frontend* fe, u8 *buf, int len)
96{ 96{
97 struct stv0299_state* state = fe->demodulator_priv; 97 struct stv0299_state* state = fe->demodulator_priv;
98 98
99 return stv0299_writeregI(state, reg, data); 99 if (len != 2)
100 return -EINVAL;
101
102 return stv0299_writeregI(state, buf[0], buf[1]);
100} 103}
101 104
102static u8 stv0299_readreg (struct stv0299_state* state, u8 reg) 105static u8 stv0299_readreg (struct stv0299_state* state, u8 reg)
@@ -694,6 +697,7 @@ static struct dvb_frontend_ops stv0299_ops = {
694 697
695 .init = stv0299_init, 698 .init = stv0299_init,
696 .sleep = stv0299_sleep, 699 .sleep = stv0299_sleep,
700 .write = stv0299_write,
697 .i2c_gate_ctrl = stv0299_i2c_gate_ctrl, 701 .i2c_gate_ctrl = stv0299_i2c_gate_ctrl,
698 702
699 .set_frontend = stv0299_set_frontend, 703 .set_frontend = stv0299_set_frontend,
@@ -724,5 +728,4 @@ MODULE_AUTHOR("Ralph Metzler, Holger Waechtler, Peter Schildmann, Felix Domke, "
724 "Andreas Oberritter, Andrew de Quincey, Kenneth Aafly"); 728 "Andreas Oberritter, Andrew de Quincey, Kenneth Aafly");
725MODULE_LICENSE("GPL"); 729MODULE_LICENSE("GPL");
726 730
727EXPORT_SYMBOL(stv0299_writereg);
728EXPORT_SYMBOL(stv0299_attach); 731EXPORT_SYMBOL(stv0299_attach);
diff --git a/drivers/media/dvb/frontends/stv0299.h b/drivers/media/dvb/frontends/stv0299.h
index 1504828e4232..7ef25207081d 100644
--- a/drivers/media/dvb/frontends/stv0299.h
+++ b/drivers/media/dvb/frontends/stv0299.h
@@ -89,9 +89,24 @@ struct stv0299_config
89 int (*set_symbol_rate)(struct dvb_frontend* fe, u32 srate, u32 ratio); 89 int (*set_symbol_rate)(struct dvb_frontend* fe, u32 srate, u32 ratio);
90}; 90};
91 91
92extern int stv0299_writereg (struct dvb_frontend* fe, u8 reg, u8 data); 92#if defined(CONFIG_DVB_STV0299) || defined(CONFIG_DVB_STV0299_MODULE)
93
94extern struct dvb_frontend* stv0299_attach(const struct stv0299_config* config, 93extern struct dvb_frontend* stv0299_attach(const struct stv0299_config* config,
95 struct i2c_adapter* i2c); 94 struct i2c_adapter* i2c);
95#else
96static inline struct dvb_frontend* stv0299_attach(const struct stv0299_config* config,
97 struct i2c_adapter* i2c)
98{
99 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
100 return NULL;
101}
102#endif // CONFIG_DVB_STV0299
103
104static inline int stv0299_writereg(struct dvb_frontend *fe, u8 reg, u8 val) {
105 int r = 0;
106 u8 buf[] = {reg, val};
107 if (fe->ops.write)
108 r = fe->ops.write(fe, buf, 2);
109 return r;
110}
96 111
97#endif // STV0299_H 112#endif // STV0299_H
diff --git a/drivers/media/dvb/frontends/tda10021.c b/drivers/media/dvb/frontends/tda10021.c
index 9cbd164aa281..dca89171be1f 100644
--- a/drivers/media/dvb/frontends/tda10021.c
+++ b/drivers/media/dvb/frontends/tda10021.c
@@ -72,7 +72,7 @@ static u8 tda10021_inittab[0x40]=
72 0x04, 0x2d, 0x2f, 0xff, 0x00, 0x00, 0x00, 0x00, 72 0x04, 0x2d, 0x2f, 0xff, 0x00, 0x00, 0x00, 0x00,
73}; 73};
74 74
75static int tda10021_writereg (struct tda10021_state* state, u8 reg, u8 data) 75static int _tda10021_writereg (struct tda10021_state* state, u8 reg, u8 data)
76{ 76{
77 u8 buf[] = { reg, data }; 77 u8 buf[] = { reg, data };
78 struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 2 }; 78 struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 2 };
@@ -88,14 +88,6 @@ static int tda10021_writereg (struct tda10021_state* state, u8 reg, u8 data)
88 return (ret != 1) ? -EREMOTEIO : 0; 88 return (ret != 1) ? -EREMOTEIO : 0;
89} 89}
90 90
91int tda10021_write_byte(struct dvb_frontend* fe, int reg, int data)
92{
93 struct tda10021_state* state = fe->demodulator_priv;
94
95 return tda10021_writereg(state, reg, data);
96}
97EXPORT_SYMBOL(tda10021_write_byte);
98
99static u8 tda10021_readreg (struct tda10021_state* state, u8 reg) 91static u8 tda10021_readreg (struct tda10021_state* state, u8 reg)
100{ 92{
101 u8 b0 [] = { reg }; 93 u8 b0 [] = { reg };
@@ -149,8 +141,8 @@ static int tda10021_setup_reg0 (struct tda10021_state* state, u8 reg0,
149 else if (INVERSION_OFF == inversion) 141 else if (INVERSION_OFF == inversion)
150 DISABLE_INVERSION(reg0); 142 DISABLE_INVERSION(reg0);
151 143
152 tda10021_writereg (state, 0x00, reg0 & 0xfe); 144 _tda10021_writereg (state, 0x00, reg0 & 0xfe);
153 tda10021_writereg (state, 0x00, reg0 | 0x01); 145 _tda10021_writereg (state, 0x00, reg0 | 0x01);
154 146
155 state->reg0 = reg0; 147 state->reg0 = reg0;
156 return 0; 148 return 0;
@@ -198,17 +190,27 @@ static int tda10021_set_symbolrate (struct tda10021_state* state, u32 symbolrate
198 190
199 NDEC = (NDEC << 6) | tda10021_inittab[0x03]; 191 NDEC = (NDEC << 6) | tda10021_inittab[0x03];
200 192
201 tda10021_writereg (state, 0x03, NDEC); 193 _tda10021_writereg (state, 0x03, NDEC);
202 tda10021_writereg (state, 0x0a, BDR&0xff); 194 _tda10021_writereg (state, 0x0a, BDR&0xff);
203 tda10021_writereg (state, 0x0b, (BDR>> 8)&0xff); 195 _tda10021_writereg (state, 0x0b, (BDR>> 8)&0xff);
204 tda10021_writereg (state, 0x0c, (BDR>>16)&0x3f); 196 _tda10021_writereg (state, 0x0c, (BDR>>16)&0x3f);
205 197
206 tda10021_writereg (state, 0x0d, BDRI); 198 _tda10021_writereg (state, 0x0d, BDRI);
207 tda10021_writereg (state, 0x0e, SFIL); 199 _tda10021_writereg (state, 0x0e, SFIL);
208 200
209 return 0; 201 return 0;
210} 202}
211 203
204int tda10021_write(struct dvb_frontend* fe, u8 *buf, int len)
205{
206 struct tda10021_state* state = fe->demodulator_priv;
207
208 if (len != 2)
209 return -EINVAL;
210
211 return _tda10021_writereg(state, buf[0], buf[1]);
212}
213
212static int tda10021_init (struct dvb_frontend *fe) 214static int tda10021_init (struct dvb_frontend *fe)
213{ 215{
214 struct tda10021_state* state = fe->demodulator_priv; 216 struct tda10021_state* state = fe->demodulator_priv;
@@ -216,12 +218,12 @@ static int tda10021_init (struct dvb_frontend *fe)
216 218
217 dprintk("DVB: TDA10021(%d): init chip\n", fe->adapter->num); 219 dprintk("DVB: TDA10021(%d): init chip\n", fe->adapter->num);
218 220
219 //tda10021_writereg (fe, 0, 0); 221 //_tda10021_writereg (fe, 0, 0);
220 222
221 for (i=0; i<tda10021_inittab_size; i++) 223 for (i=0; i<tda10021_inittab_size; i++)
222 tda10021_writereg (state, i, tda10021_inittab[i]); 224 _tda10021_writereg (state, i, tda10021_inittab[i]);
223 225
224 tda10021_writereg (state, 0x34, state->pwm); 226 _tda10021_writereg (state, 0x34, state->pwm);
225 227
226 //Comment by markus 228 //Comment by markus
227 //0x2A[3-0] == PDIV -> P multiplaying factor (P=PDIV+1)(default 0) 229 //0x2A[3-0] == PDIV -> P multiplaying factor (P=PDIV+1)(default 0)
@@ -230,7 +232,7 @@ static int tda10021_init (struct dvb_frontend *fe)
230 //0x2A[6] == POLAXIN -> Polarity of the input reference clock (default 0) 232 //0x2A[6] == POLAXIN -> Polarity of the input reference clock (default 0)
231 233
232 //Activate PLL 234 //Activate PLL
233 tda10021_writereg(state, 0x2a, tda10021_inittab[0x2a] & 0xef); 235 _tda10021_writereg(state, 0x2a, tda10021_inittab[0x2a] & 0xef);
234 return 0; 236 return 0;
235} 237}
236 238
@@ -264,12 +266,12 @@ static int tda10021_set_parameters (struct dvb_frontend *fe,
264 } 266 }
265 267
266 tda10021_set_symbolrate (state, p->u.qam.symbol_rate); 268 tda10021_set_symbolrate (state, p->u.qam.symbol_rate);
267 tda10021_writereg (state, 0x34, state->pwm); 269 _tda10021_writereg (state, 0x34, state->pwm);
268 270
269 tda10021_writereg (state, 0x01, reg0x01[qam]); 271 _tda10021_writereg (state, 0x01, reg0x01[qam]);
270 tda10021_writereg (state, 0x05, reg0x05[qam]); 272 _tda10021_writereg (state, 0x05, reg0x05[qam]);
271 tda10021_writereg (state, 0x08, reg0x08[qam]); 273 _tda10021_writereg (state, 0x08, reg0x08[qam]);
272 tda10021_writereg (state, 0x09, reg0x09[qam]); 274 _tda10021_writereg (state, 0x09, reg0x09[qam]);
273 275
274 tda10021_setup_reg0 (state, reg0x00[qam], p->inversion); 276 tda10021_setup_reg0 (state, reg0x00[qam], p->inversion);
275 277
@@ -342,8 +344,8 @@ static int tda10021_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
342 *ucblocks = 0xffffffff; 344 *ucblocks = 0xffffffff;
343 345
344 /* reset uncorrected block counter */ 346 /* reset uncorrected block counter */
345 tda10021_writereg (state, 0x10, tda10021_inittab[0x10] & 0xdf); 347 _tda10021_writereg (state, 0x10, tda10021_inittab[0x10] & 0xdf);
346 tda10021_writereg (state, 0x10, tda10021_inittab[0x10]); 348 _tda10021_writereg (state, 0x10, tda10021_inittab[0x10]);
347 349
348 return 0; 350 return 0;
349} 351}
@@ -392,8 +394,8 @@ static int tda10021_sleep(struct dvb_frontend* fe)
392{ 394{
393 struct tda10021_state* state = fe->demodulator_priv; 395 struct tda10021_state* state = fe->demodulator_priv;
394 396
395 tda10021_writereg (state, 0x1b, 0x02); /* pdown ADC */ 397 _tda10021_writereg (state, 0x1b, 0x02); /* pdown ADC */
396 tda10021_writereg (state, 0x00, 0x80); /* standby */ 398 _tda10021_writereg (state, 0x00, 0x80); /* standby */
397 399
398 return 0; 400 return 0;
399} 401}
@@ -459,6 +461,7 @@ static struct dvb_frontend_ops tda10021_ops = {
459 461
460 .init = tda10021_init, 462 .init = tda10021_init,
461 .sleep = tda10021_sleep, 463 .sleep = tda10021_sleep,
464 .write = tda10021_write,
462 .i2c_gate_ctrl = tda10021_i2c_gate_ctrl, 465 .i2c_gate_ctrl = tda10021_i2c_gate_ctrl,
463 466
464 .set_frontend = tda10021_set_parameters, 467 .set_frontend = tda10021_set_parameters,
diff --git a/drivers/media/dvb/frontends/tda10021.h b/drivers/media/dvb/frontends/tda10021.h
index b1df4259bee9..d68ae20c8412 100644
--- a/drivers/media/dvb/frontends/tda10021.h
+++ b/drivers/media/dvb/frontends/tda10021.h
@@ -32,9 +32,24 @@ struct tda10021_config
32 u8 demod_address; 32 u8 demod_address;
33}; 33};
34 34
35#if defined(CONFIG_DVB_TDA10021) || defined(CONFIG_DVB_TDA10021_MODULE)
35extern struct dvb_frontend* tda10021_attach(const struct tda10021_config* config, 36extern struct dvb_frontend* tda10021_attach(const struct tda10021_config* config,
36 struct i2c_adapter* i2c, u8 pwm); 37 struct i2c_adapter* i2c, u8 pwm);
37 38#else
38extern int tda10021_write_byte(struct dvb_frontend* fe, int reg, int data); 39static inline struct dvb_frontend* tda10021_attach(const struct tda10021_config* config,
40 struct i2c_adapter* i2c, u8 pwm)
41{
42 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
43 return NULL;
44}
45#endif // CONFIG_DVB_TDA10021
46
47static inline int tda10021_writereg(struct dvb_frontend *fe, u8 reg, u8 val) {
48 int r = 0;
49 u8 buf[] = {reg, val};
50 if (fe->ops.write)
51 r = fe->ops.write(fe, buf, 2);
52 return r;
53}
39 54
40#endif // TDA10021_H 55#endif // TDA10021_H
diff --git a/drivers/media/dvb/frontends/tda1004x.c b/drivers/media/dvb/frontends/tda1004x.c
index 59a2ed614fca..11e0dca9a2d7 100644
--- a/drivers/media/dvb/frontends/tda1004x.c
+++ b/drivers/media/dvb/frontends/tda1004x.c
@@ -579,11 +579,14 @@ static int tda1004x_decode_fec(int tdafec)
579 return -1; 579 return -1;
580} 580}
581 581
582int tda1004x_write_byte(struct dvb_frontend* fe, int reg, int data) 582int tda1004x_write(struct dvb_frontend* fe, u8 *buf, int len)
583{ 583{
584 struct tda1004x_state* state = fe->demodulator_priv; 584 struct tda1004x_state* state = fe->demodulator_priv;
585 585
586 return tda1004x_write_byteI(state, reg, data); 586 if (len != 2)
587 return -EINVAL;
588
589 return tda1004x_write_byteI(state, buf[0], buf[1]);
587} 590}
588 591
589static int tda10045_init(struct dvb_frontend* fe) 592static int tda10045_init(struct dvb_frontend* fe)
@@ -1216,6 +1219,7 @@ static struct dvb_frontend_ops tda10045_ops = {
1216 1219
1217 .init = tda10045_init, 1220 .init = tda10045_init,
1218 .sleep = tda1004x_sleep, 1221 .sleep = tda1004x_sleep,
1222 .write = tda1004x_write,
1219 .i2c_gate_ctrl = tda1004x_i2c_gate_ctrl, 1223 .i2c_gate_ctrl = tda1004x_i2c_gate_ctrl,
1220 1224
1221 .set_frontend = tda1004x_set_fe, 1225 .set_frontend = tda1004x_set_fe,
@@ -1274,6 +1278,7 @@ static struct dvb_frontend_ops tda10046_ops = {
1274 1278
1275 .init = tda10046_init, 1279 .init = tda10046_init,
1276 .sleep = tda1004x_sleep, 1280 .sleep = tda1004x_sleep,
1281 .write = tda1004x_write,
1277 .i2c_gate_ctrl = tda1004x_i2c_gate_ctrl, 1282 .i2c_gate_ctrl = tda1004x_i2c_gate_ctrl,
1278 1283
1279 .set_frontend = tda1004x_set_fe, 1284 .set_frontend = tda1004x_set_fe,
@@ -1323,4 +1328,3 @@ MODULE_LICENSE("GPL");
1323 1328
1324EXPORT_SYMBOL(tda10045_attach); 1329EXPORT_SYMBOL(tda10045_attach);
1325EXPORT_SYMBOL(tda10046_attach); 1330EXPORT_SYMBOL(tda10046_attach);
1326EXPORT_SYMBOL(tda1004x_write_byte);
diff --git a/drivers/media/dvb/frontends/tda1004x.h b/drivers/media/dvb/frontends/tda1004x.h
index b877b23ed734..e28fca05734c 100644
--- a/drivers/media/dvb/frontends/tda1004x.h
+++ b/drivers/media/dvb/frontends/tda1004x.h
@@ -71,12 +71,33 @@ struct tda1004x_config
71 int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name); 71 int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name);
72}; 72};
73 73
74#if defined(CONFIG_DVB_TDA1004X) || defined(CONFIG_DVB_TDA1004X_MODULE)
74extern struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config, 75extern struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config,
75 struct i2c_adapter* i2c); 76 struct i2c_adapter* i2c);
76 77
77extern struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config, 78extern struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config,
78 struct i2c_adapter* i2c); 79 struct i2c_adapter* i2c);
79 80#else
80extern int tda1004x_write_byte(struct dvb_frontend* fe, int reg, int data); 81static inline struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config,
82 struct i2c_adapter* i2c)
83{
84 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
85 return NULL;
86}
87static inline struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config,
88 struct i2c_adapter* i2c)
89{
90 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
91 return NULL;
92}
93#endif // CONFIG_DVB_TDA1004X
94
95static inline int tda1004x_writereg(struct dvb_frontend *fe, u8 reg, u8 val) {
96 int r = 0;
97 u8 buf[] = {reg, val};
98 if (fe->ops.write)
99 r = fe->ops.write(fe, buf, 2);
100 return r;
101}
81 102
82#endif // TDA1004X_H 103#endif // TDA1004X_H
diff --git a/drivers/media/dvb/frontends/tda10086.c b/drivers/media/dvb/frontends/tda10086.c
new file mode 100644
index 000000000000..7456b0b9976b
--- /dev/null
+++ b/drivers/media/dvb/frontends/tda10086.c
@@ -0,0 +1,740 @@
1 /*
2 Driver for Philips tda10086 DVBS Demodulator
3
4 (c) 2006 Andrew de Quincey
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#include <linux/init.h>
24#include <linux/module.h>
25#include <linux/moduleparam.h>
26#include <linux/device.h>
27#include <linux/jiffies.h>
28#include <linux/string.h>
29#include <linux/slab.h>
30
31#include "dvb_frontend.h"
32#include "tda10086.h"
33
34#define SACLK 96000000
35
36struct tda10086_state {
37 struct i2c_adapter* i2c;
38 const struct tda10086_config* config;
39 struct dvb_frontend frontend;
40
41 /* private demod data */
42 u32 frequency;
43 u32 symbol_rate;
44};
45
46static int debug = 0;
47#define dprintk(args...) \
48 do { \
49 if (debug) printk(KERN_DEBUG "tda10086: " args); \
50 } while (0)
51
52static int tda10086_write_byte(struct tda10086_state *state, int reg, int data)
53{
54 int ret;
55 u8 b0[] = { reg, data };
56 struct i2c_msg msg = { .flags = 0, .buf = b0, .len = 2 };
57
58 msg.addr = state->config->demod_address;
59 ret = i2c_transfer(state->i2c, &msg, 1);
60
61 if (ret != 1)
62 dprintk("%s: error reg=0x%x, data=0x%x, ret=%i\n",
63 __FUNCTION__, reg, data, ret);
64
65 return (ret != 1) ? ret : 0;
66}
67
68static int tda10086_read_byte(struct tda10086_state *state, int reg)
69{
70 int ret;
71 u8 b0[] = { reg };
72 u8 b1[] = { 0 };
73 struct i2c_msg msg[] = {{ .flags = 0, .buf = b0, .len = 1 },
74 { .flags = I2C_M_RD, .buf = b1, .len = 1 }};
75
76 msg[0].addr = state->config->demod_address;
77 msg[1].addr = state->config->demod_address;
78 ret = i2c_transfer(state->i2c, msg, 2);
79
80 if (ret != 2) {
81 dprintk("%s: error reg=0x%x, ret=%i\n", __FUNCTION__, reg,
82 ret);
83 return ret;
84 }
85
86 return b1[0];
87}
88
89static int tda10086_write_mask(struct tda10086_state *state, int reg, int mask, int data)
90{
91 int val;
92
93 // read a byte and check
94 val = tda10086_read_byte(state, reg);
95 if (val < 0)
96 return val;
97
98 // mask if off
99 val = val & ~mask;
100 val |= data & 0xff;
101
102 // write it out again
103 return tda10086_write_byte(state, reg, val);
104}
105
106static int tda10086_init(struct dvb_frontend* fe)
107{
108 struct tda10086_state* state = fe->demodulator_priv;
109
110 dprintk ("%s\n", __FUNCTION__);
111
112 // reset
113 tda10086_write_byte(state, 0x00, 0x00);
114 msleep(10);
115
116 // misc setup
117 tda10086_write_byte(state, 0x01, 0x94);
118 tda10086_write_byte(state, 0x02, 0x35); // NOTE: TT drivers appear to disable CSWP
119 tda10086_write_byte(state, 0x03, 0x64);
120 tda10086_write_byte(state, 0x04, 0x43);
121 tda10086_write_byte(state, 0x0c, 0x0c);
122 tda10086_write_byte(state, 0x1b, 0xb0); // noise threshold
123 tda10086_write_byte(state, 0x20, 0x89); // misc
124 tda10086_write_byte(state, 0x30, 0x04); // acquisition period length
125 tda10086_write_byte(state, 0x32, 0x00); // irq off
126 tda10086_write_byte(state, 0x31, 0x56); // setup AFC
127
128 // setup PLL (assumes 16Mhz XIN)
129 tda10086_write_byte(state, 0x55, 0x2c); // misc PLL setup
130 tda10086_write_byte(state, 0x3a, 0x0b); // M=12
131 tda10086_write_byte(state, 0x3b, 0x01); // P=2
132 tda10086_write_mask(state, 0x55, 0x20, 0x00); // powerup PLL
133
134 // setup TS interface
135 tda10086_write_byte(state, 0x11, 0x81);
136 tda10086_write_byte(state, 0x12, 0x81);
137 tda10086_write_byte(state, 0x19, 0x40); // parallel mode A + MSBFIRST
138 tda10086_write_byte(state, 0x56, 0x80); // powerdown WPLL - unused in the mode we use
139 tda10086_write_byte(state, 0x57, 0x08); // bypass WPLL - unused in the mode we use
140 tda10086_write_byte(state, 0x10, 0x2a);
141
142 // setup ADC
143 tda10086_write_byte(state, 0x58, 0x61); // ADC setup
144 tda10086_write_mask(state, 0x58, 0x01, 0x00); // powerup ADC
145
146 // setup AGC
147 tda10086_write_byte(state, 0x05, 0x0B);
148 tda10086_write_byte(state, 0x37, 0x63);
149 tda10086_write_byte(state, 0x3f, 0x03); // NOTE: flydvb uses 0x0a and varies it
150 tda10086_write_byte(state, 0x40, 0x64);
151 tda10086_write_byte(state, 0x41, 0x4f);
152 tda10086_write_byte(state, 0x42, 0x43);
153
154 // setup viterbi
155 tda10086_write_byte(state, 0x1a, 0x11); // VBER 10^6, DVB, QPSK
156
157 // setup carrier recovery
158 tda10086_write_byte(state, 0x3d, 0x80);
159
160 // setup SEC
161 tda10086_write_byte(state, 0x36, 0x00); // all SEC off
162 tda10086_write_byte(state, 0x34, (((1<<19) * (22000/1000)) / (SACLK/1000))); // } tone frequency
163 tda10086_write_byte(state, 0x35, (((1<<19) * (22000/1000)) / (SACLK/1000)) >> 8); // }
164
165 return 0;
166}
167
168static void tda10086_diseqc_wait(struct tda10086_state *state)
169{
170 unsigned long timeout = jiffies + msecs_to_jiffies(200);
171 while (!(tda10086_read_byte(state, 0x50) & 0x01)) {
172 if(time_after(jiffies, timeout)) {
173 printk("%s: diseqc queue not ready, command may be lost.\n", __FUNCTION__);
174 break;
175 }
176 msleep(10);
177 }
178}
179
180static int tda10086_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
181{
182 struct tda10086_state* state = fe->demodulator_priv;
183
184 dprintk ("%s\n", __FUNCTION__);
185
186 switch(tone) {
187 case SEC_TONE_OFF:
188 tda10086_write_byte(state, 0x36, 0x00);
189 break;
190
191 case SEC_TONE_ON:
192 tda10086_write_byte(state, 0x36, 0x01);
193 break;
194 }
195
196 return 0;
197}
198
199static int tda10086_send_master_cmd (struct dvb_frontend* fe,
200 struct dvb_diseqc_master_cmd* cmd)
201{
202 struct tda10086_state* state = fe->demodulator_priv;
203 int i;
204 u8 oldval;
205
206 dprintk ("%s\n", __FUNCTION__);
207
208 if (cmd->msg_len > 6)
209 return -EINVAL;
210 oldval = tda10086_read_byte(state, 0x36);
211
212 for(i=0; i< cmd->msg_len; i++) {
213 tda10086_write_byte(state, 0x48+i, cmd->msg[i]);
214 }
215 tda10086_write_byte(state, 0x36, 0x08 | ((cmd->msg_len + 1) << 4));
216
217 tda10086_diseqc_wait(state);
218
219 tda10086_write_byte(state, 0x36, oldval);
220
221 return 0;
222}
223
224static int tda10086_send_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd)
225{
226 struct tda10086_state* state = fe->demodulator_priv;
227 u8 oldval = tda10086_read_byte(state, 0x36);
228
229 dprintk ("%s\n", __FUNCTION__);
230
231 switch(minicmd) {
232 case SEC_MINI_A:
233 tda10086_write_byte(state, 0x36, 0x04);
234 break;
235
236 case SEC_MINI_B:
237 tda10086_write_byte(state, 0x36, 0x06);
238 break;
239 }
240
241 tda10086_diseqc_wait(state);
242
243 tda10086_write_byte(state, 0x36, oldval);
244
245 return 0;
246}
247
248static int tda10086_set_inversion(struct tda10086_state *state,
249 struct dvb_frontend_parameters *fe_params)
250{
251 u8 invval = 0x80;
252
253 dprintk ("%s %i %i\n", __FUNCTION__, fe_params->inversion, state->config->invert);
254
255 switch(fe_params->inversion) {
256 case INVERSION_OFF:
257 if (state->config->invert)
258 invval = 0x40;
259 break;
260 case INVERSION_ON:
261 if (!state->config->invert)
262 invval = 0x40;
263 break;
264 case INVERSION_AUTO:
265 invval = 0x00;
266 break;
267 }
268 tda10086_write_mask(state, 0x0c, 0xc0, invval);
269
270 return 0;
271}
272
273static int tda10086_set_symbol_rate(struct tda10086_state *state,
274 struct dvb_frontend_parameters *fe_params)
275{
276 u8 dfn = 0;
277 u8 afs = 0;
278 u8 byp = 0;
279 u8 reg37 = 0x43;
280 u8 reg42 = 0x43;
281 u64 big;
282 u32 tmp;
283 u32 bdr;
284 u32 bdri;
285 u32 symbol_rate = fe_params->u.qpsk.symbol_rate;
286
287 dprintk ("%s %i\n", __FUNCTION__, symbol_rate);
288
289 // setup the decimation and anti-aliasing filters..
290 if (symbol_rate < (u32) (SACLK * 0.0137)) {
291 dfn=4;
292 afs=1;
293 } else if (symbol_rate < (u32) (SACLK * 0.0208)) {
294 dfn=4;
295 afs=0;
296 } else if (symbol_rate < (u32) (SACLK * 0.0270)) {
297 dfn=3;
298 afs=1;
299 } else if (symbol_rate < (u32) (SACLK * 0.0416)) {
300 dfn=3;
301 afs=0;
302 } else if (symbol_rate < (u32) (SACLK * 0.0550)) {
303 dfn=2;
304 afs=1;
305 } else if (symbol_rate < (u32) (SACLK * 0.0833)) {
306 dfn=2;
307 afs=0;
308 } else if (symbol_rate < (u32) (SACLK * 0.1100)) {
309 dfn=1;
310 afs=1;
311 } else if (symbol_rate < (u32) (SACLK * 0.1666)) {
312 dfn=1;
313 afs=0;
314 } else if (symbol_rate < (u32) (SACLK * 0.2200)) {
315 dfn=0;
316 afs=1;
317 } else if (symbol_rate < (u32) (SACLK * 0.3333)) {
318 dfn=0;
319 afs=0;
320 } else {
321 reg37 = 0x63;
322 reg42 = 0x4f;
323 byp=1;
324 }
325
326 // calculate BDR
327 big = (1ULL<<21) * ((u64) symbol_rate/1000ULL) * (1ULL<<dfn);
328 big += ((SACLK/1000ULL)-1ULL);
329 do_div(big, (SACLK/1000ULL));
330 bdr = big & 0xfffff;
331
332 // calculate BDRI
333 tmp = (1<<dfn)*(symbol_rate/1000);
334 bdri = ((32 * (SACLK/1000)) + (tmp-1)) / tmp;
335
336 tda10086_write_byte(state, 0x21, (afs << 7) | dfn);
337 tda10086_write_mask(state, 0x20, 0x08, byp << 3);
338 tda10086_write_byte(state, 0x06, bdr);
339 tda10086_write_byte(state, 0x07, bdr >> 8);
340 tda10086_write_byte(state, 0x08, bdr >> 16);
341 tda10086_write_byte(state, 0x09, bdri);
342 tda10086_write_byte(state, 0x37, reg37);
343 tda10086_write_byte(state, 0x42, reg42);
344
345 return 0;
346}
347
348static int tda10086_set_fec(struct tda10086_state *state,
349 struct dvb_frontend_parameters *fe_params)
350{
351 u8 fecval;
352
353 dprintk ("%s %i\n", __FUNCTION__, fe_params->u.qpsk.fec_inner);
354
355 switch(fe_params->u.qpsk.fec_inner) {
356 case FEC_1_2:
357 fecval = 0x00;
358 break;
359 case FEC_2_3:
360 fecval = 0x01;
361 break;
362 case FEC_3_4:
363 fecval = 0x02;
364 break;
365 case FEC_4_5:
366 fecval = 0x03;
367 break;
368 case FEC_5_6:
369 fecval = 0x04;
370 break;
371 case FEC_6_7:
372 fecval = 0x05;
373 break;
374 case FEC_7_8:
375 fecval = 0x06;
376 break;
377 case FEC_8_9:
378 fecval = 0x07;
379 break;
380 case FEC_AUTO:
381 fecval = 0x08;
382 break;
383 default:
384 return -1;
385 }
386 tda10086_write_byte(state, 0x0d, fecval);
387
388 return 0;
389}
390
391static int tda10086_set_frontend(struct dvb_frontend* fe,
392 struct dvb_frontend_parameters *fe_params)
393{
394 struct tda10086_state *state = fe->demodulator_priv;
395 int ret;
396 u32 freq = 0;
397 int freqoff;
398
399 dprintk ("%s\n", __FUNCTION__);
400
401 // set params
402 if (fe->ops.tuner_ops.set_params) {
403 fe->ops.tuner_ops.set_params(fe, fe_params);
404 if (fe->ops.i2c_gate_ctrl)
405 fe->ops.i2c_gate_ctrl(fe, 0);
406
407 if (fe->ops.tuner_ops.get_frequency)
408 fe->ops.tuner_ops.get_frequency(fe, &freq);
409 if (fe->ops.i2c_gate_ctrl)
410 fe->ops.i2c_gate_ctrl(fe, 0);
411 }
412
413 // calcluate the frequency offset (in *Hz* not kHz)
414 freqoff = fe_params->frequency - freq;
415 freqoff = ((1<<16) * freqoff) / (SACLK/1000);
416 tda10086_write_byte(state, 0x3d, 0x80 | ((freqoff >> 8) & 0x7f));
417 tda10086_write_byte(state, 0x3e, freqoff);
418
419 if ((ret = tda10086_set_inversion(state, fe_params)) < 0)
420 return ret;
421 if ((ret = tda10086_set_symbol_rate(state, fe_params)) < 0)
422 return ret;
423 if ((ret = tda10086_set_fec(state, fe_params)) < 0)
424 return ret;
425
426 // soft reset + disable TS output until lock
427 tda10086_write_mask(state, 0x10, 0x40, 0x40);
428 tda10086_write_mask(state, 0x00, 0x01, 0x00);
429
430 state->symbol_rate = fe_params->u.qpsk.symbol_rate;
431 state->frequency = fe_params->frequency;
432 return 0;
433}
434
435static int tda10086_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *fe_params)
436{
437 struct tda10086_state* state = fe->demodulator_priv;
438 u8 val;
439 int tmp;
440 u64 tmp64;
441
442 dprintk ("%s\n", __FUNCTION__);
443
444 // calculate the updated frequency (note: we convert from Hz->kHz)
445 tmp64 = tda10086_read_byte(state, 0x52);
446 tmp64 |= (tda10086_read_byte(state, 0x51) << 8);
447 if (tmp64 & 0x8000)
448 tmp64 |= 0xffffffffffff0000ULL;
449 tmp64 = (tmp64 * (SACLK/1000ULL));
450 do_div(tmp64, (1ULL<<15) * (1ULL<<1));
451 fe_params->frequency = (int) state->frequency + (int) tmp64;
452
453 // the inversion
454 val = tda10086_read_byte(state, 0x0c);
455 if (val & 0x80) {
456 switch(val & 0x40) {
457 case 0x00:
458 fe_params->inversion = INVERSION_OFF;
459 if (state->config->invert)
460 fe_params->inversion = INVERSION_ON;
461 break;
462 default:
463 fe_params->inversion = INVERSION_ON;
464 if (state->config->invert)
465 fe_params->inversion = INVERSION_OFF;
466 break;
467 }
468 } else {
469 tda10086_read_byte(state, 0x0f);
470 switch(val & 0x02) {
471 case 0x00:
472 fe_params->inversion = INVERSION_OFF;
473 if (state->config->invert)
474 fe_params->inversion = INVERSION_ON;
475 break;
476 default:
477 fe_params->inversion = INVERSION_ON;
478 if (state->config->invert)
479 fe_params->inversion = INVERSION_OFF;
480 break;
481 }
482 }
483
484 // calculate the updated symbol rate
485 tmp = tda10086_read_byte(state, 0x1d);
486 if (tmp & 0x80)
487 tmp |= 0xffffff00;
488 tmp = (tmp * 480 * (1<<1)) / 128;
489 tmp = ((state->symbol_rate/1000) * tmp) / (1000000/1000);
490 fe_params->u.qpsk.symbol_rate = state->symbol_rate + tmp;
491
492 // the FEC
493 val = (tda10086_read_byte(state, 0x0d) & 0x70) >> 4;
494 switch(val) {
495 case 0x00:
496 fe_params->u.qpsk.fec_inner = FEC_1_2;
497 break;
498 case 0x01:
499 fe_params->u.qpsk.fec_inner = FEC_2_3;
500 break;
501 case 0x02:
502 fe_params->u.qpsk.fec_inner = FEC_3_4;
503 break;
504 case 0x03:
505 fe_params->u.qpsk.fec_inner = FEC_4_5;
506 break;
507 case 0x04:
508 fe_params->u.qpsk.fec_inner = FEC_5_6;
509 break;
510 case 0x05:
511 fe_params->u.qpsk.fec_inner = FEC_6_7;
512 break;
513 case 0x06:
514 fe_params->u.qpsk.fec_inner = FEC_7_8;
515 break;
516 case 0x07:
517 fe_params->u.qpsk.fec_inner = FEC_8_9;
518 break;
519 }
520
521 return 0;
522}
523
524static int tda10086_read_status(struct dvb_frontend* fe, fe_status_t *fe_status)
525{
526 struct tda10086_state* state = fe->demodulator_priv;
527 u8 val;
528
529 dprintk ("%s\n", __FUNCTION__);
530
531 val = tda10086_read_byte(state, 0x0e);
532 *fe_status = 0;
533 if (val & 0x01)
534 *fe_status |= FE_HAS_SIGNAL;
535 if (val & 0x02)
536 *fe_status |= FE_HAS_CARRIER;
537 if (val & 0x04)
538 *fe_status |= FE_HAS_VITERBI;
539 if (val & 0x08)
540 *fe_status |= FE_HAS_SYNC;
541 if (val & 0x10)
542 *fe_status |= FE_HAS_LOCK;
543
544 return 0;
545}
546
547static int tda10086_read_signal_strength(struct dvb_frontend* fe, u16 * signal)
548{
549 struct tda10086_state* state = fe->demodulator_priv;
550 u8 _str;
551
552 dprintk ("%s\n", __FUNCTION__);
553
554 _str = tda10086_read_byte(state, 0x43);
555 *signal = (_str << 8) | _str;
556
557 return 0;
558}
559
560static int tda10086_read_snr(struct dvb_frontend* fe, u16 * snr)
561{
562 struct tda10086_state* state = fe->demodulator_priv;
563 u8 _snr;
564
565 dprintk ("%s\n", __FUNCTION__);
566
567 _snr = tda10086_read_byte(state, 0x1c);
568 *snr = (_snr << 8) | _snr;
569
570 return 0;
571}
572
573static int tda10086_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
574{
575 struct tda10086_state* state = fe->demodulator_priv;
576
577 dprintk ("%s\n", __FUNCTION__);
578
579 // read it
580 *ucblocks = tda10086_read_byte(state, 0x18) & 0x7f;
581
582 // reset counter
583 tda10086_write_byte(state, 0x18, 0x00);
584 tda10086_write_byte(state, 0x18, 0x80);
585
586 return 0;
587}
588
589static int tda10086_read_ber(struct dvb_frontend* fe, u32* ber)
590{
591 struct tda10086_state* state = fe->demodulator_priv;
592
593 dprintk ("%s\n", __FUNCTION__);
594
595 // read it
596 *ber = 0;
597 *ber |= tda10086_read_byte(state, 0x15);
598 *ber |= tda10086_read_byte(state, 0x16) << 8;
599 *ber |= (tda10086_read_byte(state, 0x17) & 0xf) << 16;
600
601 return 0;
602}
603
604static int tda10086_sleep(struct dvb_frontend* fe)
605{
606 struct tda10086_state* state = fe->demodulator_priv;
607
608 dprintk ("%s\n", __FUNCTION__);
609
610 tda10086_write_mask(state, 0x00, 0x08, 0x08);
611
612 return 0;
613}
614
615static int tda10086_i2c_gate_ctrl(struct dvb_frontend* fe, int enable)
616{
617 struct tda10086_state* state = fe->demodulator_priv;
618
619 dprintk ("%s\n", __FUNCTION__);
620
621 if (enable) {
622 tda10086_write_mask(state, 0x00, 0x10, 0x10);
623 } else {
624 tda10086_write_mask(state, 0x00, 0x10, 0x00);
625 }
626
627 return 0;
628}
629
630static int tda10086_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings)
631{
632 if (fesettings->parameters.u.qpsk.symbol_rate > 20000000) {
633 fesettings->min_delay_ms = 50;
634 fesettings->step_size = 2000;
635 fesettings->max_drift = 8000;
636 } else if (fesettings->parameters.u.qpsk.symbol_rate > 12000000) {
637 fesettings->min_delay_ms = 100;
638 fesettings->step_size = 1500;
639 fesettings->max_drift = 9000;
640 } else if (fesettings->parameters.u.qpsk.symbol_rate > 8000000) {
641 fesettings->min_delay_ms = 100;
642 fesettings->step_size = 1000;
643 fesettings->max_drift = 8000;
644 } else if (fesettings->parameters.u.qpsk.symbol_rate > 4000000) {
645 fesettings->min_delay_ms = 100;
646 fesettings->step_size = 500;
647 fesettings->max_drift = 7000;
648 } else if (fesettings->parameters.u.qpsk.symbol_rate > 2000000) {
649 fesettings->min_delay_ms = 200;
650 fesettings->step_size = (fesettings->parameters.u.qpsk.symbol_rate / 8000);
651 fesettings->max_drift = 14 * fesettings->step_size;
652 } else {
653 fesettings->min_delay_ms = 200;
654 fesettings->step_size = (fesettings->parameters.u.qpsk.symbol_rate / 8000);
655 fesettings->max_drift = 18 * fesettings->step_size;
656 }
657
658 return 0;
659}
660
661static void tda10086_release(struct dvb_frontend* fe)
662{
663 struct tda10086_state *state = fe->demodulator_priv;
664 tda10086_sleep(fe);
665 kfree(state);
666}
667
668static struct dvb_frontend_ops tda10086_ops = {
669
670 .info = {
671 .name = "Philips TDA10086 DVB-S",
672 .type = FE_QPSK,
673 .frequency_min = 950000,
674 .frequency_max = 2150000,
675 .frequency_stepsize = 125, /* kHz for QPSK frontends */
676 .symbol_rate_min = 1000000,
677 .symbol_rate_max = 45000000,
678 .caps = FE_CAN_INVERSION_AUTO |
679 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
680 FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
681 FE_CAN_QPSK
682 },
683
684 .release = tda10086_release,
685
686 .init = tda10086_init,
687 .sleep = tda10086_sleep,
688 .i2c_gate_ctrl = tda10086_i2c_gate_ctrl,
689
690 .set_frontend = tda10086_set_frontend,
691 .get_frontend = tda10086_get_frontend,
692 .get_tune_settings = tda10086_get_tune_settings,
693
694 .read_status = tda10086_read_status,
695 .read_ber = tda10086_read_ber,
696 .read_signal_strength = tda10086_read_signal_strength,
697 .read_snr = tda10086_read_snr,
698 .read_ucblocks = tda10086_read_ucblocks,
699
700 .diseqc_send_master_cmd = tda10086_send_master_cmd,
701 .diseqc_send_burst = tda10086_send_burst,
702 .set_tone = tda10086_set_tone,
703};
704
705struct dvb_frontend* tda10086_attach(const struct tda10086_config* config,
706 struct i2c_adapter* i2c)
707{
708 struct tda10086_state *state;
709
710 dprintk ("%s\n", __FUNCTION__);
711
712 /* allocate memory for the internal state */
713 state = kmalloc(sizeof(struct tda10086_state), GFP_KERNEL);
714 if (!state)
715 return NULL;
716
717 /* setup the state */
718 state->config = config;
719 state->i2c = i2c;
720
721 /* check if the demod is there */
722 if (tda10086_read_byte(state, 0x1e) != 0xe1) {
723 kfree(state);
724 return NULL;
725 }
726
727 /* create dvb_frontend */
728 memcpy(&state->frontend.ops, &tda10086_ops, sizeof(struct dvb_frontend_ops));
729 state->frontend.demodulator_priv = state;
730 return &state->frontend;
731}
732
733module_param(debug, int, 0644);
734MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
735
736MODULE_DESCRIPTION("Philips TDA10086 DVB-S Demodulator");
737MODULE_AUTHOR("Andrew de Quincey");
738MODULE_LICENSE("GPL");
739
740EXPORT_SYMBOL(tda10086_attach);
diff --git a/drivers/media/dvb/frontends/tda10086.h b/drivers/media/dvb/frontends/tda10086.h
new file mode 100644
index 000000000000..e8061db11123
--- /dev/null
+++ b/drivers/media/dvb/frontends/tda10086.h
@@ -0,0 +1,41 @@
1 /*
2 Driver for Philips tda10086 DVBS Frontend
3
4 (c) 2006 Andrew de Quincey
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 TDA10086_H
24#define TDA10086_H
25
26#include <linux/dvb/frontend.h>
27#include <linux/firmware.h>
28
29struct tda10086_config
30{
31 /* the demodulator's i2c address */
32 u8 demod_address;
33
34 /* does the "inversion" need inverted? */
35 u8 invert;
36};
37
38extern struct dvb_frontend* tda10086_attach(const struct tda10086_config* config,
39 struct i2c_adapter* i2c);
40
41#endif // TDA10086_H
diff --git a/drivers/media/dvb/frontends/tda8083.h b/drivers/media/dvb/frontends/tda8083.h
index e7a48f61ea2c..aae15bdce6eb 100644
--- a/drivers/media/dvb/frontends/tda8083.h
+++ b/drivers/media/dvb/frontends/tda8083.h
@@ -35,7 +35,16 @@ struct tda8083_config
35 u8 demod_address; 35 u8 demod_address;
36}; 36};
37 37
38#if defined(CONFIG_DVB_TDA8083) || defined(CONFIG_DVB_TDA8083_MODULE)
38extern struct dvb_frontend* tda8083_attach(const struct tda8083_config* config, 39extern struct dvb_frontend* tda8083_attach(const struct tda8083_config* config,
39 struct i2c_adapter* i2c); 40 struct i2c_adapter* i2c);
41#else
42static inline struct dvb_frontend* tda8083_attach(const struct tda8083_config* config,
43 struct i2c_adapter* i2c)
44{
45 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
46 return NULL;
47}
48#endif // CONFIG_DVB_TDA8083
40 49
41#endif // TDA8083_H 50#endif // TDA8083_H
diff --git a/drivers/media/dvb/frontends/tda826x.c b/drivers/media/dvb/frontends/tda826x.c
new file mode 100644
index 000000000000..eeab26bd36ed
--- /dev/null
+++ b/drivers/media/dvb/frontends/tda826x.c
@@ -0,0 +1,173 @@
1 /*
2 Driver for Philips tda8262/tda8263 DVBS Silicon tuners
3
4 (c) 2006 Andrew de Quincey
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#include <linux/module.h>
24#include <linux/dvb/frontend.h>
25#include <asm/types.h>
26
27#include "tda826x.h"
28
29static int debug = 0;
30#define dprintk(args...) \
31 do { \
32 if (debug) printk(KERN_DEBUG "tda826x: " args); \
33 } while (0)
34
35struct tda826x_priv {
36 /* i2c details */
37 int i2c_address;
38 struct i2c_adapter *i2c;
39 u8 has_loopthrough:1;
40 u32 frequency;
41};
42
43static int tda826x_release(struct dvb_frontend *fe)
44{
45 if (fe->tuner_priv)
46 kfree(fe->tuner_priv);
47 fe->tuner_priv = NULL;
48 return 0;
49}
50
51static int tda826x_sleep(struct dvb_frontend *fe)
52{
53 struct tda826x_priv *priv = fe->tuner_priv;
54 int ret;
55 u8 buf [] = { 0x00, 0x8d };
56 struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 2 };
57
58 dprintk("%s:\n", __FUNCTION__);
59
60 if (!priv->has_loopthrough)
61 buf[1] = 0xad;
62
63 if (fe->ops.i2c_gate_ctrl)
64 fe->ops.i2c_gate_ctrl(fe, 1);
65 if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) {
66 dprintk("%s: i2c error\n", __FUNCTION__);
67 }
68 if (fe->ops.i2c_gate_ctrl)
69 fe->ops.i2c_gate_ctrl(fe, 0);
70
71 return (ret == 1) ? 0 : ret;
72}
73
74static int tda826x_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
75{
76 struct tda826x_priv *priv = fe->tuner_priv;
77 int ret;
78 u32 div;
79 u8 buf [11];
80 struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 11 };
81
82 dprintk("%s:\n", __FUNCTION__);
83
84 div = (params->frequency + (1000-1)) / 1000;
85
86 buf[0] = 0x00; // subaddress
87 buf[1] = 0x09; // powerdown RSSI + the magic value 1
88 if (!priv->has_loopthrough)
89 buf[1] |= 0x20; // power down loopthrough if not needed
90 buf[2] = (1<<5) | 0x0b; // 1Mhz + 0.45 VCO
91 buf[3] = div >> 7;
92 buf[4] = div << 1;
93 buf[5] = 0xff; // basedband filter to max
94 buf[6] = 0xfe; // gains at max + no RF attenuation
95 buf[7] = 0x83; // charge pumps at high, tests off
96 buf[8] = 0x80; // recommended value 4 for AMPVCO + disable ports.
97 buf[9] = 0x1a; // normal caltime + recommended values for SELTH + SELVTL
98 buf[10] = 0xd4; // recommended value 13 for BBIAS + unknown bit set on
99
100 if (fe->ops.i2c_gate_ctrl)
101 fe->ops.i2c_gate_ctrl(fe, 1);
102 if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) {
103 dprintk("%s: i2c error\n", __FUNCTION__);
104 }
105 if (fe->ops.i2c_gate_ctrl)
106 fe->ops.i2c_gate_ctrl(fe, 0);
107
108 priv->frequency = div * 1000;
109
110 return (ret == 1) ? 0 : ret;
111}
112
113static int tda826x_get_frequency(struct dvb_frontend *fe, u32 *frequency)
114{
115 struct tda826x_priv *priv = fe->tuner_priv;
116 *frequency = priv->frequency;
117 return 0;
118}
119
120static struct dvb_tuner_ops tda826x_tuner_ops = {
121 .info = {
122 .name = "Philips TDA826X",
123 .frequency_min = 950000,
124 .frequency_min = 2175000
125 },
126 .release = tda826x_release,
127 .sleep = tda826x_sleep,
128 .set_params = tda826x_set_params,
129 .get_frequency = tda826x_get_frequency,
130};
131
132struct dvb_frontend *tda826x_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c, int has_loopthrough)
133{
134 struct tda826x_priv *priv = NULL;
135 u8 b1 [] = { 0, 0 };
136 struct i2c_msg msg = { .addr = addr, .flags = I2C_M_RD, .buf = b1, .len = 2 };
137 int ret;
138
139 dprintk("%s:\n", __FUNCTION__);
140
141 if (fe->ops.i2c_gate_ctrl)
142 fe->ops.i2c_gate_ctrl(fe, 1);
143 ret = i2c_transfer (i2c, &msg, 1);
144 if (fe->ops.i2c_gate_ctrl)
145 fe->ops.i2c_gate_ctrl(fe, 0);
146
147 if (ret != 1)
148 return NULL;
149 if (!(b1[1] & 0x80))
150 return NULL;
151
152 priv = kzalloc(sizeof(struct tda826x_priv), GFP_KERNEL);
153 if (priv == NULL)
154 return NULL;
155
156 priv->i2c_address = addr;
157 priv->i2c = i2c;
158 priv->has_loopthrough = has_loopthrough;
159
160 memcpy(&fe->ops.tuner_ops, &tda826x_tuner_ops, sizeof(struct dvb_tuner_ops));
161
162 fe->tuner_priv = priv;
163
164 return fe;
165}
166EXPORT_SYMBOL(tda826x_attach);
167
168module_param(debug, int, 0644);
169MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
170
171MODULE_DESCRIPTION("DVB TDA826x driver");
172MODULE_AUTHOR("Andrew de Quincey");
173MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/tda826x.h b/drivers/media/dvb/frontends/tda826x.h
new file mode 100644
index 000000000000..3307607632b0
--- /dev/null
+++ b/drivers/media/dvb/frontends/tda826x.h
@@ -0,0 +1,40 @@
1 /*
2 Driver for Philips tda8262/tda8263 DVBS Silicon tuners
3
4 (c) 2006 Andrew de Quincey
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 __DVB_TDA826X_H__
24#define __DVB_TDA826X_H__
25
26#include <linux/i2c.h>
27#include "dvb_frontend.h"
28
29/**
30 * Attach a tda826x tuner to the supplied frontend structure.
31 *
32 * @param fe Frontend to attach to.
33 * @param addr i2c address of the tuner.
34 * @param i2c i2c adapter to use.
35 * @param has_loopthrough Set to 1 if the card has a loopthrough RF connector.
36 * @return FE pointer on success, NULL on failure.
37 */
38extern struct dvb_frontend *tda826x_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c, int has_loopthrough);
39
40#endif
diff --git a/drivers/media/dvb/frontends/tua6100.c b/drivers/media/dvb/frontends/tua6100.c
new file mode 100644
index 000000000000..88554393a9bf
--- /dev/null
+++ b/drivers/media/dvb/frontends/tua6100.c
@@ -0,0 +1,205 @@
1/**
2 * Driver for Infineon tua6100 pll.
3 *
4 * (c) 2006 Andrew de Quincey
5 *
6 * Based on code found in budget-av.c, which has the following:
7 * Compiled from various sources by Michael Hunold <michael@mihu.de>
8 *
9 * CI interface support (c) 2004 Olivier Gournet <ogournet@anevia.com> &
10 * Andrew de Quincey <adq_dvb@lidskialf.net>
11 *
12 * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de>
13 *
14 * Copyright (C) 1999-2002 Ralph Metzler
15 * & Marcus Metzler for convergence integrated media GmbH
16 * 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
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 */
30
31#include <linux/module.h>
32#include <linux/dvb/frontend.h>
33#include <asm/types.h>
34
35#include "tua6100.h"
36
37struct tua6100_priv {
38 /* i2c details */
39 int i2c_address;
40 struct i2c_adapter *i2c;
41 u32 frequency;
42};
43
44static int tua6100_release(struct dvb_frontend *fe)
45{
46 if (fe->tuner_priv)
47 kfree(fe->tuner_priv);
48 fe->tuner_priv = NULL;
49 return 0;
50}
51
52static int tua6100_sleep(struct dvb_frontend *fe)
53{
54 struct tua6100_priv *priv = fe->tuner_priv;
55 int ret;
56 u8 reg0[] = { 0x00, 0x00 };
57 struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = reg0, .len = 2 };
58
59 if (fe->ops.i2c_gate_ctrl)
60 fe->ops.i2c_gate_ctrl(fe, 1);
61 if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) {
62 printk("%s: i2c error\n", __FUNCTION__);
63 }
64 if (fe->ops.i2c_gate_ctrl)
65 fe->ops.i2c_gate_ctrl(fe, 0);
66
67 return (ret == 1) ? 0 : ret;
68}
69
70static int tua6100_set_params(struct dvb_frontend *fe,
71 struct dvb_frontend_parameters *params)
72{
73 struct tua6100_priv *priv = fe->tuner_priv;
74 u32 div;
75 u32 prediv;
76 u8 reg0[] = { 0x00, 0x00 };
77 u8 reg1[] = { 0x01, 0x00, 0x00, 0x00 };
78 u8 reg2[] = { 0x02, 0x00, 0x00 };
79 struct i2c_msg msg0 = { .addr = priv->i2c_address, .flags = 0, .buf = reg0, .len = 2 };
80 struct i2c_msg msg1 = { .addr = priv->i2c_address, .flags = 0, .buf = reg1, .len = 4 };
81 struct i2c_msg msg2 = { .addr = priv->i2c_address, .flags = 0, .buf = reg2, .len = 3 };
82
83#define _R 4
84#define _P 32
85#define _ri 4000000
86
87 // setup register 0
88 if (params->frequency < 2000000) {
89 reg0[1] = 0x03;
90 } else {
91 reg0[1] = 0x07;
92 }
93
94 // setup register 1
95 if (params->frequency < 1630000) {
96 reg1[1] = 0x2c;
97 } else {
98 reg1[1] = 0x0c;
99 }
100 if (_P == 64)
101 reg1[1] |= 0x40;
102 if (params->frequency >= 1525000)
103 reg1[1] |= 0x80;
104
105 // register 2
106 reg2[1] = (_R >> 8) & 0x03;
107 reg2[2] = _R;
108 if (params->frequency < 1455000) {
109 reg2[1] |= 0x1c;
110 } else if (params->frequency < 1630000) {
111 reg2[1] |= 0x0c;
112 } else {
113 reg2[1] |= 0x1c;
114 }
115
116 // The N divisor ratio (note: params->frequency is in kHz, but we need it in Hz)
117 prediv = (params->frequency * _R) / (_ri / 1000);
118 div = prediv / _P;
119 reg1[1] |= (div >> 9) & 0x03;
120 reg1[2] = div >> 1;
121 reg1[3] = (div << 7);
122 priv->frequency = ((div * _P) * (_ri / 1000)) / _R;
123
124 // Finally, calculate and store the value for A
125 reg1[3] |= (prediv - (div*_P)) & 0x7f;
126
127#undef _R
128#undef _P
129#undef _ri
130
131 if (fe->ops.i2c_gate_ctrl)
132 fe->ops.i2c_gate_ctrl(fe, 1);
133 if (i2c_transfer(priv->i2c, &msg0, 1) != 1)
134 return -EIO;
135
136 if (fe->ops.i2c_gate_ctrl)
137 fe->ops.i2c_gate_ctrl(fe, 1);
138 if (i2c_transfer(priv->i2c, &msg2, 1) != 1)
139 return -EIO;
140
141 if (fe->ops.i2c_gate_ctrl)
142 fe->ops.i2c_gate_ctrl(fe, 1);
143 if (i2c_transfer(priv->i2c, &msg1, 1) != 1)
144 return -EIO;
145
146 if (fe->ops.i2c_gate_ctrl)
147 fe->ops.i2c_gate_ctrl(fe, 0);
148
149 return 0;
150}
151
152static int tua6100_get_frequency(struct dvb_frontend *fe, u32 *frequency)
153{
154 struct tua6100_priv *priv = fe->tuner_priv;
155 *frequency = priv->frequency;
156 return 0;
157}
158
159static struct dvb_tuner_ops tua6100_tuner_ops = {
160 .info = {
161 .name = "Infineon TUA6100",
162 .frequency_min = 950000,
163 .frequency_max = 2150000,
164 .frequency_step = 1000,
165 },
166 .release = tua6100_release,
167 .sleep = tua6100_sleep,
168 .set_params = tua6100_set_params,
169 .get_frequency = tua6100_get_frequency,
170};
171
172struct dvb_frontend *tua6100_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c)
173{
174 struct tua6100_priv *priv = NULL;
175 u8 b1 [] = { 0x80 };
176 u8 b2 [] = { 0x00 };
177 struct i2c_msg msg [] = { { .addr = addr, .flags = 0, .buf = b1, .len = 1 },
178 { .addr = addr, .flags = I2C_M_RD, .buf = b2, .len = 1 } };
179 int ret;
180
181 if (fe->ops.i2c_gate_ctrl)
182 fe->ops.i2c_gate_ctrl(fe, 1);
183 ret = i2c_transfer (i2c, msg, 2);
184 if (fe->ops.i2c_gate_ctrl)
185 fe->ops.i2c_gate_ctrl(fe, 0);
186
187 if (ret != 2)
188 return NULL;
189
190 priv = kzalloc(sizeof(struct tua6100_priv), GFP_KERNEL);
191 if (priv == NULL)
192 return NULL;
193
194 priv->i2c_address = addr;
195 priv->i2c = i2c;
196
197 memcpy(&fe->ops.tuner_ops, &tua6100_tuner_ops, sizeof(struct dvb_tuner_ops));
198 fe->tuner_priv = priv;
199 return fe;
200}
201EXPORT_SYMBOL(tua6100_attach);
202
203MODULE_DESCRIPTION("DVB tua6100 driver");
204MODULE_AUTHOR("Andrew de Quincey");
205MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/tua6100.h b/drivers/media/dvb/frontends/tua6100.h
new file mode 100644
index 000000000000..8f98033ffa7b
--- /dev/null
+++ b/drivers/media/dvb/frontends/tua6100.h
@@ -0,0 +1,47 @@
1/**
2 * Driver for Infineon tua6100 PLL.
3 *
4 * (c) 2006 Andrew de Quincey
5 *
6 * Based on code found in budget-av.c, which has the following:
7 * Compiled from various sources by Michael Hunold <michael@mihu.de>
8 *
9 * CI interface support (c) 2004 Olivier Gournet <ogournet@anevia.com> &
10 * Andrew de Quincey <adq_dvb@lidskialf.net>
11 *
12 * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de>
13 *
14 * Copyright (C) 1999-2002 Ralph Metzler
15 * & Marcus Metzler for convergence integrated media GmbH
16 * 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
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 */
30
31#ifndef __DVB_TUA6100_H__
32#define __DVB_TUA6100_H__
33
34#include <linux/i2c.h>
35#include "dvb_frontend.h"
36
37#if defined(CONFIG_DVB_TUA6100) || defined(CONFIG_DVB_TUA6100_MODULE)
38extern struct dvb_frontend *tua6100_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c);
39#else
40static inline struct dvb_frontend* tua6100_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c)
41{
42 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
43 return NULL;
44}
45#endif // CONFIG_DVB_TUA6100
46
47#endif
diff --git a/drivers/media/dvb/frontends/ves1820.h b/drivers/media/dvb/frontends/ves1820.h
index 520f09522fbb..f0c9dded39d7 100644
--- a/drivers/media/dvb/frontends/ves1820.h
+++ b/drivers/media/dvb/frontends/ves1820.h
@@ -41,7 +41,16 @@ struct ves1820_config
41 u8 selagc:1; 41 u8 selagc:1;
42}; 42};
43 43
44#if defined(CONFIG_DVB_VES1820) || defined(CONFIG_DVB_VES1820_MODULE)
44extern struct dvb_frontend* ves1820_attach(const struct ves1820_config* config, 45extern struct dvb_frontend* ves1820_attach(const struct ves1820_config* config,
45 struct i2c_adapter* i2c, u8 pwm); 46 struct i2c_adapter* i2c, u8 pwm);
47#else
48static inline struct dvb_frontend* ves1820_attach(const struct ves1820_config* config,
49 struct i2c_adapter* i2c, u8 pwm)
50{
51 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
52 return NULL;
53}
54#endif // CONFIG_DVB_VES1820
46 55
47#endif // VES1820_H 56#endif // VES1820_H
diff --git a/drivers/media/dvb/frontends/ves1x93.h b/drivers/media/dvb/frontends/ves1x93.h
index ba88ae0855c9..395fed39b286 100644
--- a/drivers/media/dvb/frontends/ves1x93.h
+++ b/drivers/media/dvb/frontends/ves1x93.h
@@ -40,7 +40,16 @@ struct ves1x93_config
40 u8 invert_pwm:1; 40 u8 invert_pwm:1;
41}; 41};
42 42
43#if defined(CONFIG_DVB_VES1X93) || defined(CONFIG_DVB_VES1X93_MODULE)
43extern struct dvb_frontend* ves1x93_attach(const struct ves1x93_config* config, 44extern struct dvb_frontend* ves1x93_attach(const struct ves1x93_config* config,
44 struct i2c_adapter* i2c); 45 struct i2c_adapter* i2c);
46#else
47static inline struct dvb_frontend* ves1x93_attach(const struct ves1x93_config* config,
48 struct i2c_adapter* i2c)
49{
50 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
51 return NULL;
52}
53#endif // CONFIG_DVB_VES1X93
45 54
46#endif // VES1X93_H 55#endif // VES1X93_H
diff --git a/drivers/media/dvb/frontends/zl10353.c b/drivers/media/dvb/frontends/zl10353.c
index 2b95e8b6cd39..0e9b59af271e 100644
--- a/drivers/media/dvb/frontends/zl10353.c
+++ b/drivers/media/dvb/frontends/zl10353.c
@@ -140,6 +140,8 @@ static int zl10353_set_parameters(struct dvb_frontend *fe,
140 zl10353_single_write(fe, 0x5E, 0x00); 140 zl10353_single_write(fe, 0x5E, 0x00);
141 zl10353_single_write(fe, 0x65, 0x5A); 141 zl10353_single_write(fe, 0x65, 0x5A);
142 zl10353_single_write(fe, 0x66, 0xE9); 142 zl10353_single_write(fe, 0x66, 0xE9);
143 zl10353_single_write(fe, 0x6C, 0xCD);
144 zl10353_single_write(fe, 0x6D, 0x7E);
143 zl10353_single_write(fe, 0x62, 0x0A); 145 zl10353_single_write(fe, 0x62, 0x0A);
144 146
145 // if there is no attached secondary tuner, we call set_params to program 147 // if there is no attached secondary tuner, we call set_params to program
@@ -168,6 +170,7 @@ static int zl10353_set_parameters(struct dvb_frontend *fe,
168 // even if there isn't a PLL attached to the secondary bus 170 // even if there isn't a PLL attached to the secondary bus
169 zl10353_write(fe, pllbuf, sizeof(pllbuf)); 171 zl10353_write(fe, pllbuf, sizeof(pllbuf));
170 172
173 zl10353_single_write(fe, 0x5F, 0x13);
171 zl10353_single_write(fe, 0x70, 0x01); 174 zl10353_single_write(fe, 0x70, 0x01);
172 udelay(250); 175 udelay(250);
173 zl10353_single_write(fe, 0xE4, 0x00); 176 zl10353_single_write(fe, 0xE4, 0x00);
@@ -243,9 +246,12 @@ static int zl10353_init(struct dvb_frontend *fe)
243 246
244 if (debug_regs) 247 if (debug_regs)
245 zl10353_dump_regs(fe); 248 zl10353_dump_regs(fe);
249 if (state->config.parallel_ts)
250 zl10353_reset_attach[2] &= ~0x20;
246 251
247 /* Do a "hard" reset if not already done */ 252 /* Do a "hard" reset if not already done */
248 if (zl10353_read_register(state, 0x50) != 0x03) { 253 if (zl10353_read_register(state, 0x50) != zl10353_reset_attach[1] ||
254 zl10353_read_register(state, 0x51) != zl10353_reset_attach[2]) {
249 rc = zl10353_write(fe, zl10353_reset_attach, 255 rc = zl10353_write(fe, zl10353_reset_attach,
250 sizeof(zl10353_reset_attach)); 256 sizeof(zl10353_reset_attach));
251 if (debug_regs) 257 if (debug_regs)
@@ -258,7 +264,6 @@ static int zl10353_init(struct dvb_frontend *fe)
258static void zl10353_release(struct dvb_frontend *fe) 264static void zl10353_release(struct dvb_frontend *fe)
259{ 265{
260 struct zl10353_state *state = fe->demodulator_priv; 266 struct zl10353_state *state = fe->demodulator_priv;
261
262 kfree(state); 267 kfree(state);
263} 268}
264 269
@@ -314,6 +319,7 @@ static struct dvb_frontend_ops zl10353_ops = {
314 319
315 .init = zl10353_init, 320 .init = zl10353_init,
316 .sleep = zl10353_sleep, 321 .sleep = zl10353_sleep,
322 .write = zl10353_write,
317 323
318 .set_frontend = zl10353_set_parameters, 324 .set_frontend = zl10353_set_parameters,
319 .get_tune_settings = zl10353_get_tune_settings, 325 .get_tune_settings = zl10353_get_tune_settings,
@@ -330,4 +336,3 @@ MODULE_AUTHOR("Chris Pascoe");
330MODULE_LICENSE("GPL"); 336MODULE_LICENSE("GPL");
331 337
332EXPORT_SYMBOL(zl10353_attach); 338EXPORT_SYMBOL(zl10353_attach);
333EXPORT_SYMBOL(zl10353_write);
diff --git a/drivers/media/dvb/frontends/zl10353.h b/drivers/media/dvb/frontends/zl10353.h
index 9770cb840cfc..79a947215c4d 100644
--- a/drivers/media/dvb/frontends/zl10353.h
+++ b/drivers/media/dvb/frontends/zl10353.h
@@ -31,11 +31,21 @@ struct zl10353_config
31 31
32 /* set if no pll is connected to the secondary i2c bus */ 32 /* set if no pll is connected to the secondary i2c bus */
33 int no_tuner; 33 int no_tuner;
34
35 /* set if parallel ts output is required */
36 int parallel_ts;
34}; 37};
35 38
39#if defined(CONFIG_DVB_ZL10353) || defined(CONFIG_DVB_ZL10353_MODULE)
36extern struct dvb_frontend* zl10353_attach(const struct zl10353_config *config, 40extern struct dvb_frontend* zl10353_attach(const struct zl10353_config *config,
37 struct i2c_adapter *i2c); 41 struct i2c_adapter *i2c);
38 42#else
39extern int zl10353_write(struct dvb_frontend *fe, u8 *ibuf, int ilen); 43static inline struct dvb_frontend* zl10353_attach(const struct zl10353_config *config,
44 struct i2c_adapter *i2c)
45{
46 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
47 return NULL;
48}
49#endif // CONFIG_DVB_ZL10353
40 50
41#endif /* ZL10353_H */ 51#endif /* ZL10353_H */
diff --git a/drivers/media/dvb/ttpci/Kconfig b/drivers/media/dvb/ttpci/Kconfig
index 5fb097595cfb..95531a624991 100644
--- a/drivers/media/dvb/ttpci/Kconfig
+++ b/drivers/media/dvb/ttpci/Kconfig
@@ -1,17 +1,17 @@
1config DVB_AV7110 1config DVB_AV7110
2 tristate "AV7110 cards" 2 tristate "AV7110 cards"
3 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1 3 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1
4 select FW_LOADER 4 select FW_LOADER if !DVB_AV7110_FIRMWARE
5 select VIDEO_SAA7146_VV 5 select VIDEO_SAA7146_VV
6 select DVB_PLL 6 select DVB_PLL
7 select DVB_VES1820 7 select DVB_VES1820 if !DVB_FE_CUSTOMISE
8 select DVB_VES1X93 8 select DVB_VES1X93 if !DVB_FE_CUSTOMISE
9 select DVB_STV0299 9 select DVB_STV0299 if !DVB_FE_CUSTOMISE
10 select DVB_TDA8083 10 select DVB_TDA8083 if !DVB_FE_CUSTOMISE
11 select DVB_SP8870 11 select DVB_SP8870 if !DVB_FE_CUSTOMISE
12 select DVB_STV0297 12 select DVB_STV0297 if !DVB_FE_CUSTOMISE
13 select DVB_L64781 13 select DVB_L64781 if !DVB_FE_CUSTOMISE
14 select DVB_LNBP21 14 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
15 help 15 help
16 Support for SAA7146 and AV7110 based DVB cards as produced 16 Support for SAA7146 and AV7110 based DVB cards as produced
17 by Fujitsu-Siemens, Technotrend, Hauppauge and others. 17 by Fujitsu-Siemens, Technotrend, Hauppauge and others.
@@ -63,14 +63,16 @@ config DVB_BUDGET
63 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1 63 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1
64 select VIDEO_SAA7146 64 select VIDEO_SAA7146
65 select DVB_PLL 65 select DVB_PLL
66 select DVB_STV0299 66 select DVB_STV0299 if !DVB_FE_CUSTOMISE
67 select DVB_VES1X93 67 select DVB_VES1X93 if !DVB_FE_CUSTOMISE
68 select DVB_VES1820 68 select DVB_VES1820 if !DVB_FE_CUSTOMISE
69 select DVB_L64781 69 select DVB_L64781 if !DVB_FE_CUSTOMISE
70 select DVB_TDA8083 70 select DVB_TDA8083 if !DVB_FE_CUSTOMISE
71 select DVB_TDA10021 71 select DVB_TDA10021 if !DVB_FE_CUSTOMISE
72 select DVB_S5H1420 72 select DVB_S5H1420 if !DVB_FE_CUSTOMISE
73 select DVB_LNBP21 73 select DVB_TDA10086 if !DVB_FE_CUSTOMISE
74 select DVB_TDA826X if !DVB_FE_CUSTOMISE
75 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
74 help 76 help
75 Support for simple SAA7146 based DVB cards 77 Support for simple SAA7146 based DVB cards
76 (so called Budget- or Nova-PCI cards) without onboard 78 (so called Budget- or Nova-PCI cards) without onboard
@@ -86,10 +88,10 @@ config DVB_BUDGET_CI
86 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1 88 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1
87 select VIDEO_SAA7146 89 select VIDEO_SAA7146
88 select DVB_PLL 90 select DVB_PLL
89 select DVB_STV0297 91 select DVB_STV0297 if !DVB_FE_CUSTOMISE
90 select DVB_STV0299 92 select DVB_STV0299 if !DVB_FE_CUSTOMISE
91 select DVB_TDA1004X 93 select DVB_TDA1004X if !DVB_FE_CUSTOMISE
92 select DVB_LNBP21 94 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
93 help 95 help
94 Support for simple SAA7146 based DVB cards 96 Support for simple SAA7146 based DVB cards
95 (so called Budget- or Nova-PCI cards) without onboard 97 (so called Budget- or Nova-PCI cards) without onboard
@@ -108,9 +110,10 @@ config DVB_BUDGET_AV
108 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1 110 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1
109 select VIDEO_SAA7146_VV 111 select VIDEO_SAA7146_VV
110 select DVB_PLL 112 select DVB_PLL
111 select DVB_STV0299 113 select DVB_STV0299 if !DVB_FE_CUSTOMISE
112 select DVB_TDA1004X 114 select DVB_TDA1004X if !DVB_FE_CUSTOMISE
113 select DVB_TDA10021 115 select DVB_TDA10021 if !DVB_FE_CUSTOMISE
116 select DVB_TUA6100 if !DVB_FE_CUSTOMISE
114 select FW_LOADER 117 select FW_LOADER
115 help 118 help
116 Support for simple SAA7146 based DVB cards 119 Support for simple SAA7146 based DVB cards
@@ -127,9 +130,9 @@ config DVB_BUDGET_PATCH
127 depends on DVB_CORE && DVB_BUDGET && VIDEO_V4L1 130 depends on DVB_CORE && DVB_BUDGET && VIDEO_V4L1
128 select DVB_AV7110 131 select DVB_AV7110
129 select DVB_PLL 132 select DVB_PLL
130 select DVB_STV0299 133 select DVB_STV0299 if !DVB_FE_CUSTOMISE
131 select DVB_VES1X93 134 select DVB_VES1X93 if !DVB_FE_CUSTOMISE
132 select DVB_TDA8083 135 select DVB_TDA8083 if !DVB_FE_CUSTOMISE
133 help 136 help
134 Support for Budget Patch (full TS) modification on 137 Support for Budget Patch (full TS) modification on
135 SAA7146+AV7110 based cards (DVB-S cards). This 138 SAA7146+AV7110 based cards (DVB-S cards). This
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index 4506165c5de2..bba23bcd1b11 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -1383,8 +1383,10 @@ static void dvb_unregister(struct av7110 *av7110)
1383 dvb_dmxdev_release(&av7110->dmxdev); 1383 dvb_dmxdev_release(&av7110->dmxdev);
1384 dvb_dmx_release(&av7110->demux); 1384 dvb_dmx_release(&av7110->demux);
1385 1385
1386 if (av7110->fe != NULL) 1386 if (av7110->fe != NULL) {
1387 dvb_unregister_frontend(av7110->fe); 1387 dvb_unregister_frontend(av7110->fe);
1388 dvb_frontend_detach(av7110->fe);
1389 }
1388 dvb_unregister_device(av7110->osd_dev); 1390 dvb_unregister_device(av7110->osd_dev);
1389 av7110_av_unregister(av7110); 1391 av7110_av_unregister(av7110);
1390 av7110_ca_unregister(av7110); 1392 av7110_ca_unregister(av7110);
@@ -1699,9 +1701,13 @@ static int alps_tdlb7_tuner_set_params(struct dvb_frontend* fe, struct dvb_front
1699 1701
1700static int alps_tdlb7_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name) 1702static int alps_tdlb7_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name)
1701{ 1703{
1704#if defined(CONFIG_DVB_SP8870) || defined(CONFIG_DVB_SP8870_MODULE)
1702 struct av7110* av7110 = (struct av7110*) fe->dvb->priv; 1705 struct av7110* av7110 = (struct av7110*) fe->dvb->priv;
1703 1706
1704 return request_firmware(fw, name, &av7110->dev->pci->dev); 1707 return request_firmware(fw, name, &av7110->dev->pci->dev);
1708#else
1709 return -EINVAL;
1710#endif
1705} 1711}
1706 1712
1707static struct sp8870_config alps_tdlb7_config = { 1713static struct sp8870_config alps_tdlb7_config = {
@@ -2077,7 +2083,7 @@ static int frontend_init(struct av7110 *av7110)
2077 if (av7110->dev->pci->subsystem_vendor == 0x110a) { 2083 if (av7110->dev->pci->subsystem_vendor == 0x110a) {
2078 switch(av7110->dev->pci->subsystem_device) { 2084 switch(av7110->dev->pci->subsystem_device) {
2079 case 0x0000: // Fujitsu/Siemens DVB-Cable (ves1820/Philips CD1516(??)) 2085 case 0x0000: // Fujitsu/Siemens DVB-Cable (ves1820/Philips CD1516(??))
2080 av7110->fe = ves1820_attach(&philips_cd1516_config, 2086 av7110->fe = dvb_attach(ves1820_attach, &philips_cd1516_config,
2081 &av7110->i2c_adap, read_pwm(av7110)); 2087 &av7110->i2c_adap, read_pwm(av7110));
2082 if (av7110->fe) { 2088 if (av7110->fe) {
2083 av7110->fe->ops.tuner_ops.set_params = philips_cd1516_tuner_set_params; 2089 av7110->fe->ops.tuner_ops.set_params = philips_cd1516_tuner_set_params;
@@ -2092,7 +2098,7 @@ static int frontend_init(struct av7110 *av7110)
2092 case 0x1002: // Hauppauge/TT WinTV DVB-S rev1.3SE 2098 case 0x1002: // Hauppauge/TT WinTV DVB-S rev1.3SE
2093 2099
2094 // try the ALPS BSRV2 first of all 2100 // try the ALPS BSRV2 first of all
2095 av7110->fe = ves1x93_attach(&alps_bsrv2_config, &av7110->i2c_adap); 2101 av7110->fe = dvb_attach(ves1x93_attach, &alps_bsrv2_config, &av7110->i2c_adap);
2096 if (av7110->fe) { 2102 if (av7110->fe) {
2097 av7110->fe->ops.tuner_ops.set_params = alps_bsrv2_tuner_set_params; 2103 av7110->fe->ops.tuner_ops.set_params = alps_bsrv2_tuner_set_params;
2098 av7110->fe->ops.diseqc_send_master_cmd = av7110_diseqc_send_master_cmd; 2104 av7110->fe->ops.diseqc_send_master_cmd = av7110_diseqc_send_master_cmd;
@@ -2103,7 +2109,7 @@ static int frontend_init(struct av7110 *av7110)
2103 } 2109 }
2104 2110
2105 // try the ALPS BSRU6 now 2111 // try the ALPS BSRU6 now
2106 av7110->fe = stv0299_attach(&alps_bsru6_config, &av7110->i2c_adap); 2112 av7110->fe = dvb_attach(stv0299_attach, &alps_bsru6_config, &av7110->i2c_adap);
2107 if (av7110->fe) { 2113 if (av7110->fe) {
2108 av7110->fe->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params; 2114 av7110->fe->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
2109 av7110->fe->tuner_priv = &av7110->i2c_adap; 2115 av7110->fe->tuner_priv = &av7110->i2c_adap;
@@ -2116,7 +2122,7 @@ static int frontend_init(struct av7110 *av7110)
2116 } 2122 }
2117 2123
2118 // Try the grundig 29504-451 2124 // Try the grundig 29504-451
2119 av7110->fe = tda8083_attach(&grundig_29504_451_config, &av7110->i2c_adap); 2125 av7110->fe = dvb_attach(tda8083_attach, &grundig_29504_451_config, &av7110->i2c_adap);
2120 if (av7110->fe) { 2126 if (av7110->fe) {
2121 av7110->fe->ops.tuner_ops.set_params = grundig_29504_451_tuner_set_params; 2127 av7110->fe->ops.tuner_ops.set_params = grundig_29504_451_tuner_set_params;
2122 av7110->fe->ops.diseqc_send_master_cmd = av7110_diseqc_send_master_cmd; 2128 av7110->fe->ops.diseqc_send_master_cmd = av7110_diseqc_send_master_cmd;
@@ -2130,7 +2136,7 @@ static int frontend_init(struct av7110 *av7110)
2130 switch(av7110->dev->pci->subsystem_device) { 2136 switch(av7110->dev->pci->subsystem_device) {
2131 case 0x0000: 2137 case 0x0000:
2132 /* Siemens DVB-C (full-length card) VES1820/Philips CD1516 */ 2138 /* Siemens DVB-C (full-length card) VES1820/Philips CD1516 */
2133 av7110->fe = ves1820_attach(&philips_cd1516_config, &av7110->i2c_adap, 2139 av7110->fe = dvb_attach(ves1820_attach, &philips_cd1516_config, &av7110->i2c_adap,
2134 read_pwm(av7110)); 2140 read_pwm(av7110));
2135 if (av7110->fe) { 2141 if (av7110->fe) {
2136 av7110->fe->ops.tuner_ops.set_params = philips_cd1516_tuner_set_params; 2142 av7110->fe->ops.tuner_ops.set_params = philips_cd1516_tuner_set_params;
@@ -2138,7 +2144,7 @@ static int frontend_init(struct av7110 *av7110)
2138 break; 2144 break;
2139 case 0x0003: 2145 case 0x0003:
2140 /* Hauppauge DVB-C 2.1 VES1820/ALPS TDBE2 */ 2146 /* Hauppauge DVB-C 2.1 VES1820/ALPS TDBE2 */
2141 av7110->fe = ves1820_attach(&alps_tdbe2_config, &av7110->i2c_adap, 2147 av7110->fe = dvb_attach(ves1820_attach, &alps_tdbe2_config, &av7110->i2c_adap,
2142 read_pwm(av7110)); 2148 read_pwm(av7110));
2143 if (av7110->fe) { 2149 if (av7110->fe) {
2144 av7110->fe->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params; 2150 av7110->fe->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params;
@@ -2148,17 +2154,24 @@ static int frontend_init(struct av7110 *av7110)
2148 break; 2154 break;
2149 2155
2150 case 0x0001: // Hauppauge/TT Nexus-T premium rev1.X 2156 case 0x0001: // Hauppauge/TT Nexus-T premium rev1.X
2151 2157 // try ALPS TDLB7 first, then Grundig 29504-401
2152 // ALPS TDLB7 2158 av7110->fe = dvb_attach(sp8870_attach, &alps_tdlb7_config, &av7110->i2c_adap);
2153 av7110->fe = sp8870_attach(&alps_tdlb7_config, &av7110->i2c_adap);
2154 if (av7110->fe) { 2159 if (av7110->fe) {
2155 av7110->fe->ops.tuner_ops.set_params = alps_tdlb7_tuner_set_params; 2160 av7110->fe->ops.tuner_ops.set_params = alps_tdlb7_tuner_set_params;
2161 break;
2156 } 2162 }
2163 /* fall-thru */
2164
2165 case 0x0008: // Hauppauge/TT DVB-T
2166 // Grundig 29504-401
2167 av7110->fe = dvb_attach(l64781_attach, &grundig_29504_401_config, &av7110->i2c_adap);
2168 if (av7110->fe)
2169 av7110->fe->ops.tuner_ops.set_params = grundig_29504_401_tuner_set_params;
2157 break; 2170 break;
2158 2171
2159 case 0x0002: // Hauppauge/TT DVB-C premium rev2.X 2172 case 0x0002: // Hauppauge/TT DVB-C premium rev2.X
2160 2173
2161 av7110->fe = ves1820_attach(&alps_tdbe2_config, &av7110->i2c_adap, read_pwm(av7110)); 2174 av7110->fe = dvb_attach(ves1820_attach, &alps_tdbe2_config, &av7110->i2c_adap, read_pwm(av7110));
2162 if (av7110->fe) { 2175 if (av7110->fe) {
2163 av7110->fe->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params; 2176 av7110->fe->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params;
2164 } 2177 }
@@ -2166,7 +2179,7 @@ static int frontend_init(struct av7110 *av7110)
2166 2179
2167 case 0x0004: // Galaxis DVB-S rev1.3 2180 case 0x0004: // Galaxis DVB-S rev1.3
2168 /* ALPS BSRV2 */ 2181 /* ALPS BSRV2 */
2169 av7110->fe = ves1x93_attach(&alps_bsrv2_config, &av7110->i2c_adap); 2182 av7110->fe = dvb_attach(ves1x93_attach, &alps_bsrv2_config, &av7110->i2c_adap);
2170 if (av7110->fe) { 2183 if (av7110->fe) {
2171 av7110->fe->ops.tuner_ops.set_params = alps_bsrv2_tuner_set_params; 2184 av7110->fe->ops.tuner_ops.set_params = alps_bsrv2_tuner_set_params;
2172 av7110->fe->ops.diseqc_send_master_cmd = av7110_diseqc_send_master_cmd; 2185 av7110->fe->ops.diseqc_send_master_cmd = av7110_diseqc_send_master_cmd;
@@ -2178,7 +2191,7 @@ static int frontend_init(struct av7110 *av7110)
2178 2191
2179 case 0x0006: /* Fujitsu-Siemens DVB-S rev 1.6 */ 2192 case 0x0006: /* Fujitsu-Siemens DVB-S rev 1.6 */
2180 /* Grundig 29504-451 */ 2193 /* Grundig 29504-451 */
2181 av7110->fe = tda8083_attach(&grundig_29504_451_config, &av7110->i2c_adap); 2194 av7110->fe = dvb_attach(tda8083_attach, &grundig_29504_451_config, &av7110->i2c_adap);
2182 if (av7110->fe) { 2195 if (av7110->fe) {
2183 av7110->fe->ops.tuner_ops.set_params = grundig_29504_451_tuner_set_params; 2196 av7110->fe->ops.tuner_ops.set_params = grundig_29504_451_tuner_set_params;
2184 av7110->fe->ops.diseqc_send_master_cmd = av7110_diseqc_send_master_cmd; 2197 av7110->fe->ops.diseqc_send_master_cmd = av7110_diseqc_send_master_cmd;
@@ -2188,17 +2201,9 @@ static int frontend_init(struct av7110 *av7110)
2188 } 2201 }
2189 break; 2202 break;
2190 2203
2191 case 0x0008: // Hauppauge/TT DVB-T
2192
2193 av7110->fe = l64781_attach(&grundig_29504_401_config, &av7110->i2c_adap);
2194 if (av7110->fe) {
2195 av7110->fe->ops.tuner_ops.set_params = grundig_29504_401_tuner_set_params;
2196 }
2197 break;
2198
2199 case 0x000A: // Hauppauge/TT Nexus-CA rev1.X 2204 case 0x000A: // Hauppauge/TT Nexus-CA rev1.X
2200 2205
2201 av7110->fe = stv0297_attach(&nexusca_stv0297_config, &av7110->i2c_adap); 2206 av7110->fe = dvb_attach(stv0297_attach, &nexusca_stv0297_config, &av7110->i2c_adap);
2202 if (av7110->fe) { 2207 if (av7110->fe) {
2203 av7110->fe->ops.tuner_ops.set_params = nexusca_stv0297_tuner_set_params; 2208 av7110->fe->ops.tuner_ops.set_params = nexusca_stv0297_tuner_set_params;
2204 2209
@@ -2214,12 +2219,12 @@ static int frontend_init(struct av7110 *av7110)
2214 2219
2215 case 0x000E: /* Hauppauge/TT Nexus-S rev 2.3 */ 2220 case 0x000E: /* Hauppauge/TT Nexus-S rev 2.3 */
2216 /* ALPS BSBE1 */ 2221 /* ALPS BSBE1 */
2217 av7110->fe = stv0299_attach(&alps_bsbe1_config, &av7110->i2c_adap); 2222 av7110->fe = dvb_attach(stv0299_attach, &alps_bsbe1_config, &av7110->i2c_adap);
2218 if (av7110->fe) { 2223 if (av7110->fe) {
2219 av7110->fe->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params; 2224 av7110->fe->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
2220 av7110->fe->tuner_priv = &av7110->i2c_adap; 2225 av7110->fe->tuner_priv = &av7110->i2c_adap;
2221 2226
2222 if (lnbp21_attach(av7110->fe, &av7110->i2c_adap, 0, 0)) { 2227 if (dvb_attach(lnbp21_attach, av7110->fe, &av7110->i2c_adap, 0, 0) == NULL) {
2223 printk("dvb-ttpci: LNBP21 not found!\n"); 2228 printk("dvb-ttpci: LNBP21 not found!\n");
2224 if (av7110->fe->ops.release) 2229 if (av7110->fe->ops.release)
2225 av7110->fe->ops.release(av7110->fe); 2230 av7110->fe->ops.release(av7110->fe);
@@ -2255,8 +2260,7 @@ static int frontend_init(struct av7110 *av7110)
2255 ret = dvb_register_frontend(&av7110->dvb_adapter, av7110->fe); 2260 ret = dvb_register_frontend(&av7110->dvb_adapter, av7110->fe);
2256 if (ret < 0) { 2261 if (ret < 0) {
2257 printk("av7110: Frontend registration failed!\n"); 2262 printk("av7110: Frontend registration failed!\n");
2258 if (av7110->fe->ops.release) 2263 dvb_frontend_detach(av7110->fe);
2259 av7110->fe->ops.release(av7110->fe);
2260 av7110->fe = NULL; 2264 av7110->fe = NULL;
2261 } 2265 }
2262 } 2266 }
@@ -2823,7 +2827,7 @@ MODULE_DEVICE_TABLE(pci, pci_tbl);
2823 2827
2824 2828
2825static struct saa7146_extension av7110_extension = { 2829static struct saa7146_extension av7110_extension = {
2826 .name = "dvb\0", 2830 .name = "dvb",
2827 .flags = SAA7146_I2C_SHORT_DELAY, 2831 .flags = SAA7146_I2C_SHORT_DELAY,
2828 2832
2829 .module = THIS_MODULE, 2833 .module = THIS_MODULE,
diff --git a/drivers/media/dvb/ttpci/av7110_av.c b/drivers/media/dvb/ttpci/av7110_av.c
index 0f3a044aeb17..8c577cf30fb3 100644
--- a/drivers/media/dvb/ttpci/av7110_av.c
+++ b/drivers/media/dvb/ttpci/av7110_av.c
@@ -33,7 +33,6 @@
33#include <linux/string.h> 33#include <linux/string.h>
34#include <linux/sched.h> 34#include <linux/sched.h>
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/byteorder/swabb.h>
37#include <linux/smp_lock.h> 36#include <linux/smp_lock.h>
38#include <linux/fs.h> 37#include <linux/fs.h>
39 38
diff --git a/drivers/media/dvb/ttpci/av7110_ca.c b/drivers/media/dvb/ttpci/av7110_ca.c
index 6079e8865d5b..dd9aee314e0a 100644
--- a/drivers/media/dvb/ttpci/av7110_ca.c
+++ b/drivers/media/dvb/ttpci/av7110_ca.c
@@ -35,7 +35,6 @@
35#include <linux/fs.h> 35#include <linux/fs.h>
36#include <linux/timer.h> 36#include <linux/timer.h>
37#include <linux/poll.h> 37#include <linux/poll.h>
38#include <linux/byteorder/swabb.h>
39#include <linux/smp_lock.h> 38#include <linux/smp_lock.h>
40 39
41#include "av7110.h" 40#include "av7110.h"
diff --git a/drivers/media/dvb/ttpci/av7110_hw.c b/drivers/media/dvb/ttpci/av7110_hw.c
index 75736f2fe838..37de2e88a273 100644
--- a/drivers/media/dvb/ttpci/av7110_hw.c
+++ b/drivers/media/dvb/ttpci/av7110_hw.c
@@ -34,7 +34,6 @@
34#include <linux/string.h> 34#include <linux/string.h>
35#include <linux/sched.h> 35#include <linux/sched.h>
36#include <linux/delay.h> 36#include <linux/delay.h>
37#include <linux/byteorder/swabb.h>
38#include <linux/smp_lock.h> 37#include <linux/smp_lock.h>
39#include <linux/fs.h> 38#include <linux/fs.h>
40 39
diff --git a/drivers/media/dvb/ttpci/av7110_v4l.c b/drivers/media/dvb/ttpci/av7110_v4l.c
index 6ffe53fdcf57..10cfe3131e72 100644
--- a/drivers/media/dvb/ttpci/av7110_v4l.c
+++ b/drivers/media/dvb/ttpci/av7110_v4l.c
@@ -32,7 +32,6 @@
32#include <linux/fs.h> 32#include <linux/fs.h>
33#include <linux/timer.h> 33#include <linux/timer.h>
34#include <linux/poll.h> 34#include <linux/poll.h>
35#include <linux/byteorder/swabb.h>
36#include <linux/smp_lock.h> 35#include <linux/smp_lock.h>
37 36
38#include "av7110.h" 37#include "av7110.h"
@@ -922,7 +921,7 @@ static struct saa7146_ext_vv av7110_vv_data_st = {
922static struct saa7146_ext_vv av7110_vv_data_c = { 921static struct saa7146_ext_vv av7110_vv_data_c = {
923 .inputs = 1, 922 .inputs = 1,
924 .audios = 1, 923 .audios = 1,
925 .capabilities = V4L2_CAP_TUNER | V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_OUTPUT, 924 .capabilities = V4L2_CAP_TUNER | V4L2_CAP_SLICED_VBI_OUTPUT,
926 .flags = SAA7146_USE_PORT_B_FOR_VBI, 925 .flags = SAA7146_USE_PORT_B_FOR_VBI,
927 926
928 .stds = &standard[0], 927 .stds = &standard[0],
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
index 2d21fec23b4d..2235ff8b8a1d 100644
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ b/drivers/media/dvb/ttpci/budget-av.c
@@ -37,6 +37,7 @@
37#include "stv0299.h" 37#include "stv0299.h"
38#include "tda10021.h" 38#include "tda10021.h"
39#include "tda1004x.h" 39#include "tda1004x.h"
40#include "tua6100.h"
40#include "dvb-pll.h" 41#include "dvb-pll.h"
41#include <media/saa7146_vv.h> 42#include <media/saa7146_vv.h>
42#include <linux/module.h> 43#include <linux/module.h>
@@ -235,7 +236,7 @@ static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot)
235 236
236 /* set tda10021 back to original clock configuration on reset */ 237 /* set tda10021 back to original clock configuration on reset */
237 if (budget_av->tda10021_poclkp) { 238 if (budget_av->tda10021_poclkp) {
238 tda10021_write_byte(budget_av->budget.dvb_frontend, 0x12, 0xa0); 239 tda10021_writereg(budget_av->budget.dvb_frontend, 0x12, 0xa0);
239 budget_av->tda10021_ts_enabled = 0; 240 budget_av->tda10021_ts_enabled = 0;
240 } 241 }
241 242
@@ -257,7 +258,7 @@ static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
257 258
258 /* set tda10021 back to original clock configuration when cam removed */ 259 /* set tda10021 back to original clock configuration when cam removed */
259 if (budget_av->tda10021_poclkp) { 260 if (budget_av->tda10021_poclkp) {
260 tda10021_write_byte(budget_av->budget.dvb_frontend, 0x12, 0xa0); 261 tda10021_writereg(budget_av->budget.dvb_frontend, 0x12, 0xa0);
261 budget_av->tda10021_ts_enabled = 0; 262 budget_av->tda10021_ts_enabled = 0;
262 } 263 }
263 return 0; 264 return 0;
@@ -277,7 +278,7 @@ static int ciintf_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
277 278
278 /* tda10021 seems to need a different TS clock config when data is routed to the CAM */ 279 /* tda10021 seems to need a different TS clock config when data is routed to the CAM */
279 if (budget_av->tda10021_poclkp) { 280 if (budget_av->tda10021_poclkp) {
280 tda10021_write_byte(budget_av->budget.dvb_frontend, 0x12, 0xa1); 281 tda10021_writereg(budget_av->budget.dvb_frontend, 0x12, 0xa1);
281 budget_av->tda10021_ts_enabled = 1; 282 budget_av->tda10021_ts_enabled = 1;
282 } 283 }
283 284
@@ -548,144 +549,6 @@ static int philips_su1278_ty_ci_tuner_set_params(struct dvb_frontend *fe,
548 return 0; 549 return 0;
549} 550}
550 551
551#define MIN2(a,b) ((a) < (b) ? (a) : (b))
552#define MIN3(a,b,c) MIN2(MIN2(a,b),c)
553
554static int philips_su1278sh2_tua6100_tuner_set_params(struct dvb_frontend *fe,
555 struct dvb_frontend_parameters *params)
556{
557 u8 reg0 [2] = { 0x00, 0x00 };
558 u8 reg1 [4] = { 0x01, 0x00, 0x00, 0x00 };
559 u8 reg2 [3] = { 0x02, 0x00, 0x00 };
560 int _fband;
561 int first_ZF;
562 int R, A, N, P, M;
563 struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = NULL,.len = 0 };
564 int freq = params->frequency;
565 struct budget *budget = (struct budget *) fe->dvb->priv;
566
567 first_ZF = (freq) / 1000;
568
569 if (abs(MIN2(abs(first_ZF-1190),abs(first_ZF-1790))) <
570 abs(MIN3(abs(first_ZF-1202),abs(first_ZF-1542),abs(first_ZF-1890))))
571 _fband = 2;
572 else
573 _fband = 3;
574
575 if (_fband == 2) {
576 if (((first_ZF >= 950) && (first_ZF < 1350)) ||
577 ((first_ZF >= 1430) && (first_ZF < 1950)))
578 reg0[1] = 0x07;
579 else if (((first_ZF >= 1350) && (first_ZF < 1430)) ||
580 ((first_ZF >= 1950) && (first_ZF < 2150)))
581 reg0[1] = 0x0B;
582 }
583
584 if(_fband == 3) {
585 if (((first_ZF >= 950) && (first_ZF < 1350)) ||
586 ((first_ZF >= 1455) && (first_ZF < 1950)))
587 reg0[1] = 0x07;
588 else if (((first_ZF >= 1350) && (first_ZF < 1420)) ||
589 ((first_ZF >= 1950) && (first_ZF < 2150)))
590 reg0[1] = 0x0B;
591 else if ((first_ZF >= 1420) && (first_ZF < 1455))
592 reg0[1] = 0x0F;
593 }
594
595 if (first_ZF > 1525)
596 reg1[1] |= 0x80;
597 else
598 reg1[1] &= 0x7F;
599
600 if (_fband == 2) {
601 if (first_ZF > 1430) { /* 1430MHZ */
602 reg1[1] &= 0xCF; /* N2 */
603 reg2[1] &= 0xCF; /* R2 */
604 reg2[1] |= 0x10;
605 } else {
606 reg1[1] &= 0xCF; /* N2 */
607 reg1[1] |= 0x20;
608 reg2[1] &= 0xCF; /* R2 */
609 reg2[1] |= 0x10;
610 }
611 }
612
613 if (_fband == 3) {
614 if ((first_ZF >= 1455) &&
615 (first_ZF < 1630)) {
616 reg1[1] &= 0xCF; /* N2 */
617 reg1[1] |= 0x20;
618 reg2[1] &= 0xCF; /* R2 */
619 } else {
620 if (first_ZF < 1455) {
621 reg1[1] &= 0xCF; /* N2 */
622 reg1[1] |= 0x20;
623 reg2[1] &= 0xCF; /* R2 */
624 reg2[1] |= 0x10;
625 } else {
626 if (first_ZF >= 1630) {
627 reg1[1] &= 0xCF; /* N2 */
628 reg2[1] &= 0xCF; /* R2 */
629 reg2[1] |= 0x10;
630 }
631 }
632 }
633 }
634
635 /* set ports, enable P0 for symbol rates > 4Ms/s */
636 if (params->u.qpsk.symbol_rate >= 4000000)
637 reg1[1] |= 0x0c;
638 else
639 reg1[1] |= 0x04;
640
641 reg2[1] |= 0x0c;
642
643 R = 64;
644 A = 64;
645 P = 64; //32
646
647 M = (freq * R) / 4; /* in Mhz */
648 N = (M - A * 1000) / (P * 1000);
649
650 reg1[1] |= (N >> 9) & 0x03;
651 reg1[2] = (N >> 1) & 0xff;
652 reg1[3] = (N << 7) & 0x80;
653
654 reg2[1] |= (R >> 8) & 0x03;
655 reg2[2] = R & 0xFF; /* R */
656
657 reg1[3] |= A & 0x7f; /* A */
658
659 if (P == 64)
660 reg1[1] |= 0x40; /* Prescaler 64/65 */
661
662 reg0[1] |= 0x03;
663
664 /* already enabled - do not reenable i2c repeater or TX fails */
665 if (fe->ops.i2c_gate_ctrl)
666 fe->ops.i2c_gate_ctrl(fe, 1);
667 msg.buf = reg0;
668 msg.len = sizeof(reg0);
669 if (i2c_transfer(&budget->i2c_adap, &msg, 1) != 1)
670 return -EIO;
671
672 if (fe->ops.i2c_gate_ctrl)
673 fe->ops.i2c_gate_ctrl(fe, 1);
674 msg.buf = reg1;
675 msg.len = sizeof(reg1);
676 if (i2c_transfer(&budget->i2c_adap, &msg, 1) != 1)
677 return -EIO;
678
679 if (fe->ops.i2c_gate_ctrl)
680 fe->ops.i2c_gate_ctrl(fe, 1);
681 msg.buf = reg2;
682 msg.len = sizeof(reg2);
683 if (i2c_transfer(&budget->i2c_adap, &msg, 1) != 1)
684 return -EIO;
685
686 return 0;
687}
688
689static u8 typhoon_cinergy1200s_inittab[] = { 552static u8 typhoon_cinergy1200s_inittab[] = {
690 0x01, 0x15, 553 0x01, 0x15,
691 0x02, 0x30, 554 0x02, 0x30,
@@ -1068,9 +931,9 @@ static int tda10021_set_frontend(struct dvb_frontend *fe,
1068 931
1069 result = budget_av->tda10021_set_frontend(fe, p); 932 result = budget_av->tda10021_set_frontend(fe, p);
1070 if (budget_av->tda10021_ts_enabled) { 933 if (budget_av->tda10021_ts_enabled) {
1071 tda10021_write_byte(budget_av->budget.dvb_frontend, 0x12, 0xa1); 934 tda10021_writereg(budget_av->budget.dvb_frontend, 0x12, 0xa1);
1072 } else { 935 } else {
1073 tda10021_write_byte(budget_av->budget.dvb_frontend, 0x12, 0xa0); 936 tda10021_writereg(budget_av->budget.dvb_frontend, 0x12, 0xa0);
1074 } 937 }
1075 938
1076 return result; 939 return result;
@@ -1096,15 +959,16 @@ static void frontend_init(struct budget_av *budget_av)
1096 switch (saa->pci->subsystem_device) { 959 switch (saa->pci->subsystem_device) {
1097 960
1098 case SUBID_DVBS_KNC1: 961 case SUBID_DVBS_KNC1:
962 case SUBID_DVBS_KNC1_PLUS:
1099 case SUBID_DVBS_EASYWATCH_1: 963 case SUBID_DVBS_EASYWATCH_1:
1100 if (saa->pci->subsystem_vendor == 0x1894) { 964 if (saa->pci->subsystem_vendor == 0x1894) {
1101 fe = stv0299_attach(&cinergy_1200s_1894_0010_config, 965 fe = dvb_attach(stv0299_attach, &cinergy_1200s_1894_0010_config,
1102 &budget_av->budget.i2c_adap); 966 &budget_av->budget.i2c_adap);
1103 if (fe) { 967 if (fe) {
1104 fe->ops.tuner_ops.set_params = philips_su1278sh2_tua6100_tuner_set_params; 968 dvb_attach(tua6100_attach, fe, 0x60, &budget_av->budget.i2c_adap);
1105 } 969 }
1106 } else { 970 } else {
1107 fe = stv0299_attach(&typhoon_config, 971 fe = dvb_attach(stv0299_attach, &typhoon_config,
1108 &budget_av->budget.i2c_adap); 972 &budget_av->budget.i2c_adap);
1109 if (fe) { 973 if (fe) {
1110 fe->ops.tuner_ops.set_params = philips_su1278_ty_ci_tuner_set_params; 974 fe->ops.tuner_ops.set_params = philips_su1278_ty_ci_tuner_set_params;
@@ -1116,16 +980,15 @@ static void frontend_init(struct budget_av *budget_av)
1116 case SUBID_DVBS_TV_STAR_CI: 980 case SUBID_DVBS_TV_STAR_CI:
1117 case SUBID_DVBS_CYNERGY1200N: 981 case SUBID_DVBS_CYNERGY1200N:
1118 case SUBID_DVBS_EASYWATCH: 982 case SUBID_DVBS_EASYWATCH:
1119 fe = stv0299_attach(&philips_sd1878_config, 983 fe = dvb_attach(stv0299_attach, &philips_sd1878_config,
1120 &budget_av->budget.i2c_adap); 984 &budget_av->budget.i2c_adap);
1121 if (fe) { 985 if (fe) {
1122 fe->ops.tuner_ops.set_params = philips_sd1878_tda8261_tuner_set_params; 986 fe->ops.tuner_ops.set_params = philips_sd1878_tda8261_tuner_set_params;
1123 } 987 }
1124 break; 988 break;
1125 989
1126 case SUBID_DVBS_KNC1_PLUS:
1127 case SUBID_DVBS_TYPHOON: 990 case SUBID_DVBS_TYPHOON:
1128 fe = stv0299_attach(&typhoon_config, 991 fe = dvb_attach(stv0299_attach, &typhoon_config,
1129 &budget_av->budget.i2c_adap); 992 &budget_av->budget.i2c_adap);
1130 if (fe) { 993 if (fe) {
1131 fe->ops.tuner_ops.set_params = philips_su1278_ty_ci_tuner_set_params; 994 fe->ops.tuner_ops.set_params = philips_su1278_ty_ci_tuner_set_params;
@@ -1133,7 +996,7 @@ static void frontend_init(struct budget_av *budget_av)
1133 break; 996 break;
1134 997
1135 case SUBID_DVBS_CINERGY1200: 998 case SUBID_DVBS_CINERGY1200:
1136 fe = stv0299_attach(&cinergy_1200s_config, 999 fe = dvb_attach(stv0299_attach, &cinergy_1200s_config,
1137 &budget_av->budget.i2c_adap); 1000 &budget_av->budget.i2c_adap);
1138 if (fe) { 1001 if (fe) {
1139 fe->ops.tuner_ops.set_params = philips_su1278_ty_ci_tuner_set_params; 1002 fe->ops.tuner_ops.set_params = philips_su1278_ty_ci_tuner_set_params;
@@ -1141,19 +1004,10 @@ static void frontend_init(struct budget_av *budget_av)
1141 break; 1004 break;
1142 1005
1143 case SUBID_DVBC_KNC1: 1006 case SUBID_DVBC_KNC1:
1144 budget_av->reinitialise_demod = 1;
1145 fe = tda10021_attach(&philips_cu1216_config,
1146 &budget_av->budget.i2c_adap,
1147 read_pwm(budget_av));
1148 if (fe) {
1149 fe->ops.tuner_ops.set_params = philips_cu1216_tuner_set_params;
1150 }
1151 break;
1152
1153 case SUBID_DVBC_KNC1_PLUS: 1007 case SUBID_DVBC_KNC1_PLUS:
1154 case SUBID_DVBC_CINERGY1200: 1008 case SUBID_DVBC_CINERGY1200:
1155 budget_av->reinitialise_demod = 1; 1009 budget_av->reinitialise_demod = 1;
1156 fe = tda10021_attach(&philips_cu1216_config, 1010 fe = dvb_attach(tda10021_attach, &philips_cu1216_config,
1157 &budget_av->budget.i2c_adap, 1011 &budget_av->budget.i2c_adap,
1158 read_pwm(budget_av)); 1012 read_pwm(budget_av));
1159 if (fe) { 1013 if (fe) {
@@ -1168,7 +1022,7 @@ static void frontend_init(struct budget_av *budget_av)
1168 case SUBID_DVBT_KNC1_PLUS: 1022 case SUBID_DVBT_KNC1_PLUS:
1169 case SUBID_DVBT_CINERGY1200: 1023 case SUBID_DVBT_CINERGY1200:
1170 budget_av->reinitialise_demod = 1; 1024 budget_av->reinitialise_demod = 1;
1171 fe = tda10046_attach(&philips_tu1216_config, 1025 fe = dvb_attach(tda10046_attach, &philips_tu1216_config,
1172 &budget_av->budget.i2c_adap); 1026 &budget_av->budget.i2c_adap);
1173 if (fe) { 1027 if (fe) {
1174 fe->ops.tuner_ops.init = philips_tu1216_tuner_init; 1028 fe->ops.tuner_ops.init = philips_tu1216_tuner_init;
@@ -1192,8 +1046,7 @@ static void frontend_init(struct budget_av *budget_av)
1192 if (dvb_register_frontend(&budget_av->budget.dvb_adapter, 1046 if (dvb_register_frontend(&budget_av->budget.dvb_adapter,
1193 budget_av->budget.dvb_frontend)) { 1047 budget_av->budget.dvb_frontend)) {
1194 printk(KERN_ERR "budget-av: Frontend registration failed!\n"); 1048 printk(KERN_ERR "budget-av: Frontend registration failed!\n");
1195 if (budget_av->budget.dvb_frontend->ops.release) 1049 dvb_frontend_detach(budget_av->budget.dvb_frontend);
1196 budget_av->budget.dvb_frontend->ops.release(budget_av->budget.dvb_frontend);
1197 budget_av->budget.dvb_frontend = NULL; 1050 budget_av->budget.dvb_frontend = NULL;
1198 } 1051 }
1199} 1052}
@@ -1227,8 +1080,10 @@ static int budget_av_detach(struct saa7146_dev *dev)
1227 if (budget_av->budget.ci_present) 1080 if (budget_av->budget.ci_present)
1228 ciintf_deinit(budget_av); 1081 ciintf_deinit(budget_av);
1229 1082
1230 if (budget_av->budget.dvb_frontend != NULL) 1083 if (budget_av->budget.dvb_frontend != NULL) {
1231 dvb_unregister_frontend(budget_av->budget.dvb_frontend); 1084 dvb_unregister_frontend(budget_av->budget.dvb_frontend);
1085 dvb_frontend_detach(budget_av->budget.dvb_frontend);
1086 }
1232 err = ttpci_budget_deinit(&budget_av->budget); 1087 err = ttpci_budget_deinit(&budget_av->budget);
1233 1088
1234 kfree(budget_av); 1089 kfree(budget_av);
@@ -1400,6 +1255,7 @@ static struct pci_device_id pci_tbl[] = {
1400 MAKE_EXTENSION_PCI(knc1s, 0x1131, 0x0010), 1255 MAKE_EXTENSION_PCI(knc1s, 0x1131, 0x0010),
1401 MAKE_EXTENSION_PCI(knc1s, 0x1894, 0x0010), 1256 MAKE_EXTENSION_PCI(knc1s, 0x1894, 0x0010),
1402 MAKE_EXTENSION_PCI(knc1sp, 0x1131, 0x0011), 1257 MAKE_EXTENSION_PCI(knc1sp, 0x1131, 0x0011),
1258 MAKE_EXTENSION_PCI(knc1sp, 0x1894, 0x0011),
1403 MAKE_EXTENSION_PCI(kncxs, 0x1894, 0x0014), 1259 MAKE_EXTENSION_PCI(kncxs, 0x1894, 0x0014),
1404 MAKE_EXTENSION_PCI(kncxs, 0x1894, 0x0016), 1260 MAKE_EXTENSION_PCI(kncxs, 0x1894, 0x0016),
1405 MAKE_EXTENSION_PCI(satewpls, 0x1894, 0x001e), 1261 MAKE_EXTENSION_PCI(satewpls, 0x1894, 0x001e),
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
index ffbbb3e34be4..2a2e9b400613 100644
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ b/drivers/media/dvb/ttpci/budget-ci.c
@@ -749,17 +749,17 @@ static int philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb
749 // setup PLL filter and TDA9889 749 // setup PLL filter and TDA9889
750 switch (params->u.ofdm.bandwidth) { 750 switch (params->u.ofdm.bandwidth) {
751 case BANDWIDTH_6_MHZ: 751 case BANDWIDTH_6_MHZ:
752 tda1004x_write_byte(fe, 0x0C, 0x14); 752 tda1004x_writereg(fe, 0x0C, 0x14);
753 filter = 0; 753 filter = 0;
754 break; 754 break;
755 755
756 case BANDWIDTH_7_MHZ: 756 case BANDWIDTH_7_MHZ:
757 tda1004x_write_byte(fe, 0x0C, 0x80); 757 tda1004x_writereg(fe, 0x0C, 0x80);
758 filter = 0; 758 filter = 0;
759 break; 759 break;
760 760
761 case BANDWIDTH_8_MHZ: 761 case BANDWIDTH_8_MHZ:
762 tda1004x_write_byte(fe, 0x0C, 0x14); 762 tda1004x_writereg(fe, 0x0C, 0x14);
763 filter = 1; 763 filter = 1;
764 break; 764 break;
765 765
@@ -988,7 +988,7 @@ static void frontend_init(struct budget_ci *budget_ci)
988 switch (budget_ci->budget.dev->pci->subsystem_device) { 988 switch (budget_ci->budget.dev->pci->subsystem_device) {
989 case 0x100c: // Hauppauge/TT Nova-CI budget (stv0299/ALPS BSRU6(tsa5059)) 989 case 0x100c: // Hauppauge/TT Nova-CI budget (stv0299/ALPS BSRU6(tsa5059))
990 budget_ci->budget.dvb_frontend = 990 budget_ci->budget.dvb_frontend =
991 stv0299_attach(&alps_bsru6_config, &budget_ci->budget.i2c_adap); 991 dvb_attach(stv0299_attach, &alps_bsru6_config, &budget_ci->budget.i2c_adap);
992 if (budget_ci->budget.dvb_frontend) { 992 if (budget_ci->budget.dvb_frontend) {
993 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params; 993 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
994 budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap; 994 budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
@@ -998,7 +998,7 @@ static void frontend_init(struct budget_ci *budget_ci)
998 998
999 case 0x100f: // Hauppauge/TT Nova-CI budget (stv0299b/Philips su1278(tsa5059)) 999 case 0x100f: // Hauppauge/TT Nova-CI budget (stv0299b/Philips su1278(tsa5059))
1000 budget_ci->budget.dvb_frontend = 1000 budget_ci->budget.dvb_frontend =
1001 stv0299_attach(&philips_su1278_tt_config, &budget_ci->budget.i2c_adap); 1001 dvb_attach(stv0299_attach, &philips_su1278_tt_config, &budget_ci->budget.i2c_adap);
1002 if (budget_ci->budget.dvb_frontend) { 1002 if (budget_ci->budget.dvb_frontend) {
1003 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_su1278_tt_tuner_set_params; 1003 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_su1278_tt_tuner_set_params;
1004 break; 1004 break;
@@ -1008,7 +1008,7 @@ static void frontend_init(struct budget_ci *budget_ci)
1008 case 0x1010: // TT DVB-C CI budget (stv0297/Philips tdm1316l(tda6651tt)) 1008 case 0x1010: // TT DVB-C CI budget (stv0297/Philips tdm1316l(tda6651tt))
1009 budget_ci->tuner_pll_address = 0x61; 1009 budget_ci->tuner_pll_address = 0x61;
1010 budget_ci->budget.dvb_frontend = 1010 budget_ci->budget.dvb_frontend =
1011 stv0297_attach(&dvbc_philips_tdm1316l_config, &budget_ci->budget.i2c_adap); 1011 dvb_attach(stv0297_attach, &dvbc_philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
1012 if (budget_ci->budget.dvb_frontend) { 1012 if (budget_ci->budget.dvb_frontend) {
1013 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params; 1013 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params;
1014 break; 1014 break;
@@ -1018,7 +1018,7 @@ static void frontend_init(struct budget_ci *budget_ci)
1018 case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889) 1018 case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889)
1019 budget_ci->tuner_pll_address = 0x63; 1019 budget_ci->tuner_pll_address = 0x63;
1020 budget_ci->budget.dvb_frontend = 1020 budget_ci->budget.dvb_frontend =
1021 tda10045_attach(&philips_tdm1316l_config, &budget_ci->budget.i2c_adap); 1021 dvb_attach(tda10045_attach, &philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
1022 if (budget_ci->budget.dvb_frontend) { 1022 if (budget_ci->budget.dvb_frontend) {
1023 budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init; 1023 budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
1024 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params; 1024 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
@@ -1029,7 +1029,7 @@ static void frontend_init(struct budget_ci *budget_ci)
1029 case 0x1012: // TT DVB-T CI budget (tda10046/Philips tdm1316l(tda6651tt)) 1029 case 0x1012: // TT DVB-T CI budget (tda10046/Philips tdm1316l(tda6651tt))
1030 budget_ci->tuner_pll_address = 0x60; 1030 budget_ci->tuner_pll_address = 0x60;
1031 budget_ci->budget.dvb_frontend = 1031 budget_ci->budget.dvb_frontend =
1032 tda10046_attach(&philips_tdm1316l_config, &budget_ci->budget.i2c_adap); 1032 dvb_attach(tda10046_attach, &philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
1033 if (budget_ci->budget.dvb_frontend) { 1033 if (budget_ci->budget.dvb_frontend) {
1034 budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init; 1034 budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
1035 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params; 1035 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
@@ -1038,16 +1038,15 @@ static void frontend_init(struct budget_ci *budget_ci)
1038 break; 1038 break;
1039 1039
1040 case 0x1017: // TT S-1500 PCI 1040 case 0x1017: // TT S-1500 PCI
1041 budget_ci->budget.dvb_frontend = stv0299_attach(&alps_bsbe1_config, &budget_ci->budget.i2c_adap); 1041 budget_ci->budget.dvb_frontend = dvb_attach(stv0299_attach, &alps_bsbe1_config, &budget_ci->budget.i2c_adap);
1042 if (budget_ci->budget.dvb_frontend) { 1042 if (budget_ci->budget.dvb_frontend) {
1043 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params; 1043 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
1044 budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap; 1044 budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
1045 1045
1046 budget_ci->budget.dvb_frontend->ops.dishnetwork_send_legacy_command = NULL; 1046 budget_ci->budget.dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
1047 if (lnbp21_attach(budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, LNBP21_LLC, 0)) { 1047 if (dvb_attach(lnbp21_attach, budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, LNBP21_LLC, 0) == NULL) {
1048 printk("%s: No LNBP21 found!\n", __FUNCTION__); 1048 printk("%s: No LNBP21 found!\n", __FUNCTION__);
1049 if (budget_ci->budget.dvb_frontend->ops.release) 1049 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1050 budget_ci->budget.dvb_frontend->ops.release(budget_ci->budget.dvb_frontend);
1051 budget_ci->budget.dvb_frontend = NULL; 1050 budget_ci->budget.dvb_frontend = NULL;
1052 } 1051 }
1053 } 1052 }
@@ -1065,8 +1064,7 @@ static void frontend_init(struct budget_ci *budget_ci)
1065 if (dvb_register_frontend 1064 if (dvb_register_frontend
1066 (&budget_ci->budget.dvb_adapter, budget_ci->budget.dvb_frontend)) { 1065 (&budget_ci->budget.dvb_adapter, budget_ci->budget.dvb_frontend)) {
1067 printk("budget-ci: Frontend registration failed!\n"); 1066 printk("budget-ci: Frontend registration failed!\n");
1068 if (budget_ci->budget.dvb_frontend->ops.release) 1067 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1069 budget_ci->budget.dvb_frontend->ops.release(budget_ci->budget.dvb_frontend);
1070 budget_ci->budget.dvb_frontend = NULL; 1068 budget_ci->budget.dvb_frontend = NULL;
1071 } 1069 }
1072 } 1070 }
@@ -1114,8 +1112,10 @@ static int budget_ci_detach(struct saa7146_dev *dev)
1114 1112
1115 if (budget_ci->budget.ci_present) 1113 if (budget_ci->budget.ci_present)
1116 ciintf_deinit(budget_ci); 1114 ciintf_deinit(budget_ci);
1117 if (budget_ci->budget.dvb_frontend) 1115 if (budget_ci->budget.dvb_frontend) {
1118 dvb_unregister_frontend(budget_ci->budget.dvb_frontend); 1116 dvb_unregister_frontend(budget_ci->budget.dvb_frontend);
1117 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1118 }
1119 err = ttpci_budget_deinit(&budget_ci->budget); 1119 err = ttpci_budget_deinit(&budget_ci->budget);
1120 1120
1121 tasklet_kill(&budget_ci->msp430_irq_tasklet); 1121 tasklet_kill(&budget_ci->msp430_irq_tasklet);
@@ -1153,7 +1153,7 @@ static struct pci_device_id pci_tbl[] = {
1153MODULE_DEVICE_TABLE(pci, pci_tbl); 1153MODULE_DEVICE_TABLE(pci, pci_tbl);
1154 1154
1155static struct saa7146_extension budget_extension = { 1155static struct saa7146_extension budget_extension = {
1156 .name = "budget_ci dvb\0", 1156 .name = "budget_ci dvb",
1157 .flags = SAA7146_I2C_SHORT_DELAY, 1157 .flags = SAA7146_I2C_SHORT_DELAY,
1158 1158
1159 .module = THIS_MODULE, 1159 .module = THIS_MODULE,
diff --git a/drivers/media/dvb/ttpci/budget-patch.c b/drivers/media/dvb/ttpci/budget-patch.c
index 57227441891e..fc1267b8c892 100644
--- a/drivers/media/dvb/ttpci/budget-patch.c
+++ b/drivers/media/dvb/ttpci/budget-patch.c
@@ -325,7 +325,7 @@ static void frontend_init(struct budget_patch* budget)
325 case 0x1013: // SATELCO Multimedia PCI 325 case 0x1013: // SATELCO Multimedia PCI
326 326
327 // try the ALPS BSRV2 first of all 327 // try the ALPS BSRV2 first of all
328 budget->dvb_frontend = ves1x93_attach(&alps_bsrv2_config, &budget->i2c_adap); 328 budget->dvb_frontend = dvb_attach(ves1x93_attach, &alps_bsrv2_config, &budget->i2c_adap);
329 if (budget->dvb_frontend) { 329 if (budget->dvb_frontend) {
330 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsrv2_tuner_set_params; 330 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsrv2_tuner_set_params;
331 budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_patch_diseqc_send_master_cmd; 331 budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_patch_diseqc_send_master_cmd;
@@ -335,7 +335,7 @@ static void frontend_init(struct budget_patch* budget)
335 } 335 }
336 336
337 // try the ALPS BSRU6 now 337 // try the ALPS BSRU6 now
338 budget->dvb_frontend = stv0299_attach(&alps_bsru6_config, &budget->i2c_adap); 338 budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config, &budget->i2c_adap);
339 if (budget->dvb_frontend) { 339 if (budget->dvb_frontend) {
340 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params; 340 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
341 budget->dvb_frontend->tuner_priv = &budget->i2c_adap; 341 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
@@ -347,7 +347,7 @@ static void frontend_init(struct budget_patch* budget)
347 } 347 }
348 348
349 // Try the grundig 29504-451 349 // Try the grundig 29504-451
350 budget->dvb_frontend = tda8083_attach(&grundig_29504_451_config, &budget->i2c_adap); 350 budget->dvb_frontend = dvb_attach(tda8083_attach, &grundig_29504_451_config, &budget->i2c_adap);
351 if (budget->dvb_frontend) { 351 if (budget->dvb_frontend) {
352 budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_451_tuner_set_params; 352 budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_451_tuner_set_params;
353 budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd; 353 budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
@@ -367,8 +367,7 @@ static void frontend_init(struct budget_patch* budget)
367 } else { 367 } else {
368 if (dvb_register_frontend(&budget->dvb_adapter, budget->dvb_frontend)) { 368 if (dvb_register_frontend(&budget->dvb_adapter, budget->dvb_frontend)) {
369 printk("budget-av: Frontend registration failed!\n"); 369 printk("budget-av: Frontend registration failed!\n");
370 if (budget->dvb_frontend->ops.release) 370 dvb_frontend_detach(budget->dvb_frontend);
371 budget->dvb_frontend->ops.release(budget->dvb_frontend);
372 budget->dvb_frontend = NULL; 371 budget->dvb_frontend = NULL;
373 } 372 }
374 } 373 }
@@ -627,8 +626,10 @@ static int budget_patch_detach (struct saa7146_dev* dev)
627 struct budget_patch *budget = (struct budget_patch*) dev->ext_priv; 626 struct budget_patch *budget = (struct budget_patch*) dev->ext_priv;
628 int err; 627 int err;
629 628
630 if (budget->dvb_frontend) dvb_unregister_frontend(budget->dvb_frontend); 629 if (budget->dvb_frontend) {
631 630 dvb_unregister_frontend(budget->dvb_frontend);
631 dvb_frontend_detach(budget->dvb_frontend);
632 }
632 err = ttpci_budget_deinit (budget); 633 err = ttpci_budget_deinit (budget);
633 634
634 kfree (budget); 635 kfree (budget);
@@ -647,7 +648,7 @@ static void __exit budget_patch_exit(void)
647} 648}
648 649
649static struct saa7146_extension budget_extension = { 650static struct saa7146_extension budget_extension = {
650 .name = "budget_patch dvb\0", 651 .name = "budget_patch dvb",
651 .flags = 0, 652 .flags = 0,
652 653
653 .module = THIS_MODULE, 654 .module = THIS_MODULE,
diff --git a/drivers/media/dvb/ttpci/budget.c b/drivers/media/dvb/ttpci/budget.c
index 863dffb4ed8e..e58f0391e9d1 100644
--- a/drivers/media/dvb/ttpci/budget.c
+++ b/drivers/media/dvb/ttpci/budget.c
@@ -41,6 +41,8 @@
41#include "l64781.h" 41#include "l64781.h"
42#include "tda8083.h" 42#include "tda8083.h"
43#include "s5h1420.h" 43#include "s5h1420.h"
44#include "tda10086.h"
45#include "tda826x.h"
44#include "lnbp21.h" 46#include "lnbp21.h"
45#include "bsru6.h" 47#include "bsru6.h"
46 48
@@ -342,6 +344,11 @@ static struct s5h1420_config s5h1420_config = {
342 .invert = 1, 344 .invert = 1,
343}; 345};
344 346
347static struct tda10086_config tda10086_config = {
348 .demod_address = 0x0e,
349 .invert = 0,
350};
351
345static u8 read_pwm(struct budget* budget) 352static u8 read_pwm(struct budget* budget)
346{ 353{
347 u8 b = 0xff; 354 u8 b = 0xff;
@@ -361,7 +368,7 @@ static void frontend_init(struct budget *budget)
361 case 0x1003: // Hauppauge/TT Nova budget (stv0299/ALPS BSRU6(tsa5059) OR ves1893/ALPS BSRV2(sp5659)) 368 case 0x1003: // Hauppauge/TT Nova budget (stv0299/ALPS BSRU6(tsa5059) OR ves1893/ALPS BSRV2(sp5659))
362 case 0x1013: 369 case 0x1013:
363 // try the ALPS BSRV2 first of all 370 // try the ALPS BSRV2 first of all
364 budget->dvb_frontend = ves1x93_attach(&alps_bsrv2_config, &budget->i2c_adap); 371 budget->dvb_frontend = dvb_attach(ves1x93_attach, &alps_bsrv2_config, &budget->i2c_adap);
365 if (budget->dvb_frontend) { 372 if (budget->dvb_frontend) {
366 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsrv2_tuner_set_params; 373 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsrv2_tuner_set_params;
367 budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd; 374 budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
@@ -371,7 +378,7 @@ static void frontend_init(struct budget *budget)
371 } 378 }
372 379
373 // try the ALPS BSRU6 now 380 // try the ALPS BSRU6 now
374 budget->dvb_frontend = stv0299_attach(&alps_bsru6_config, &budget->i2c_adap); 381 budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config, &budget->i2c_adap);
375 if (budget->dvb_frontend) { 382 if (budget->dvb_frontend) {
376 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params; 383 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
377 budget->dvb_frontend->tuner_priv = &budget->i2c_adap; 384 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
@@ -381,7 +388,7 @@ static void frontend_init(struct budget *budget)
381 388
382 case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659)) 389 case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659))
383 390
384 budget->dvb_frontend = ves1820_attach(&alps_tdbe2_config, &budget->i2c_adap, read_pwm(budget)); 391 budget->dvb_frontend = dvb_attach(ves1820_attach, &alps_tdbe2_config, &budget->i2c_adap, read_pwm(budget));
385 if (budget->dvb_frontend) { 392 if (budget->dvb_frontend) {
386 budget->dvb_frontend->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params; 393 budget->dvb_frontend->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params;
387 break; 394 break;
@@ -390,7 +397,7 @@ static void frontend_init(struct budget *budget)
390 397
391 case 0x1005: // Hauppauge/TT Nova-T budget (L64781/Grundig 29504-401(tsa5060)) 398 case 0x1005: // Hauppauge/TT Nova-T budget (L64781/Grundig 29504-401(tsa5060))
392 399
393 budget->dvb_frontend = l64781_attach(&grundig_29504_401_config, &budget->i2c_adap); 400 budget->dvb_frontend = dvb_attach(l64781_attach, &grundig_29504_401_config, &budget->i2c_adap);
394 if (budget->dvb_frontend) { 401 if (budget->dvb_frontend) {
395 budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_401_tuner_set_params; 402 budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_401_tuner_set_params;
396 break; 403 break;
@@ -398,7 +405,7 @@ static void frontend_init(struct budget *budget)
398 break; 405 break;
399 406
400 case 0x4f60: // Fujitsu Siemens Activy Budget-S PCI rev AL (stv0299/ALPS BSRU6(tsa5059)) 407 case 0x4f60: // Fujitsu Siemens Activy Budget-S PCI rev AL (stv0299/ALPS BSRU6(tsa5059))
401 budget->dvb_frontend = stv0299_attach(&alps_bsru6_config, &budget->i2c_adap); 408 budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config, &budget->i2c_adap);
402 if (budget->dvb_frontend) { 409 if (budget->dvb_frontend) {
403 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params; 410 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
404 budget->dvb_frontend->tuner_priv = &budget->i2c_adap; 411 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
@@ -408,7 +415,7 @@ static void frontend_init(struct budget *budget)
408 break; 415 break;
409 416
410 case 0x4f61: // Fujitsu Siemens Activy Budget-S PCI rev GR (tda8083/Grundig 29504-451(tsa5522)) 417 case 0x4f61: // Fujitsu Siemens Activy Budget-S PCI rev GR (tda8083/Grundig 29504-451(tsa5522))
411 budget->dvb_frontend = tda8083_attach(&grundig_29504_451_config, &budget->i2c_adap); 418 budget->dvb_frontend = dvb_attach(tda8083_attach, &grundig_29504_451_config, &budget->i2c_adap);
412 if (budget->dvb_frontend) { 419 if (budget->dvb_frontend) {
413 budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_451_tuner_set_params; 420 budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_451_tuner_set_params;
414 budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage; 421 budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage;
@@ -417,10 +424,28 @@ static void frontend_init(struct budget *budget)
417 break; 424 break;
418 425
419 case 0x1016: // Hauppauge/TT Nova-S SE (samsung s5h1420/????(tda8260)) 426 case 0x1016: // Hauppauge/TT Nova-S SE (samsung s5h1420/????(tda8260))
420 budget->dvb_frontend = s5h1420_attach(&s5h1420_config, &budget->i2c_adap); 427 budget->dvb_frontend = dvb_attach(s5h1420_attach, &s5h1420_config, &budget->i2c_adap);
421 if (budget->dvb_frontend) { 428 if (budget->dvb_frontend) {
422 budget->dvb_frontend->ops.tuner_ops.set_params = s5h1420_tuner_set_params; 429 budget->dvb_frontend->ops.tuner_ops.set_params = s5h1420_tuner_set_params;
423 if (lnbp21_attach(budget->dvb_frontend, &budget->i2c_adap, 0, 0)) { 430 if (dvb_attach(lnbp21_attach, budget->dvb_frontend, &budget->i2c_adap, 0, 0) == NULL) {
431 printk("%s: No LNBP21 found!\n", __FUNCTION__);
432 goto error_out;
433 }
434 break;
435 }
436
437 case 0x1018: // TT Budget-S-1401 (philips tda10086/philips tda8262)
438 // gpio2 is connected to CLB - reset it + leave it high
439 saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTLO);
440 msleep(1);
441 saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTHI);
442 msleep(1);
443
444 budget->dvb_frontend = dvb_attach(tda10086_attach, &tda10086_config, &budget->i2c_adap);
445 if (budget->dvb_frontend) {
446 if (dvb_attach(tda826x_attach, budget->dvb_frontend, 0x60, &budget->i2c_adap, 0) == NULL)
447 printk("%s: No tda826x found!\n", __FUNCTION__);
448 if (dvb_attach(lnbp21_attach, budget->dvb_frontend, &budget->i2c_adap, 0, 0) == NULL) {
424 printk("%s: No LNBP21 found!\n", __FUNCTION__); 449 printk("%s: No LNBP21 found!\n", __FUNCTION__);
425 goto error_out; 450 goto error_out;
426 } 451 }
@@ -442,8 +467,7 @@ static void frontend_init(struct budget *budget)
442 467
443error_out: 468error_out:
444 printk("budget: Frontend registration failed!\n"); 469 printk("budget: Frontend registration failed!\n");
445 if (budget->dvb_frontend->ops.release) 470 dvb_frontend_detach(budget->dvb_frontend);
446 budget->dvb_frontend->ops.release(budget->dvb_frontend);
447 budget->dvb_frontend = NULL; 471 budget->dvb_frontend = NULL;
448 return; 472 return;
449} 473}
@@ -481,7 +505,10 @@ static int budget_detach (struct saa7146_dev* dev)
481 struct budget *budget = (struct budget*) dev->ext_priv; 505 struct budget *budget = (struct budget*) dev->ext_priv;
482 int err; 506 int err;
483 507
484 if (budget->dvb_frontend) dvb_unregister_frontend(budget->dvb_frontend); 508 if (budget->dvb_frontend) {
509 dvb_unregister_frontend(budget->dvb_frontend);
510 dvb_frontend_detach(budget->dvb_frontend);
511 }
485 512
486 err = ttpci_budget_deinit (budget); 513 err = ttpci_budget_deinit (budget);
487 514
@@ -497,6 +524,7 @@ MAKE_BUDGET_INFO(ttbs, "TT-Budget/WinTV-NOVA-S PCI", BUDGET_TT);
497MAKE_BUDGET_INFO(ttbc, "TT-Budget/WinTV-NOVA-C PCI", BUDGET_TT); 524MAKE_BUDGET_INFO(ttbc, "TT-Budget/WinTV-NOVA-C PCI", BUDGET_TT);
498MAKE_BUDGET_INFO(ttbt, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT); 525MAKE_BUDGET_INFO(ttbt, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
499MAKE_BUDGET_INFO(satel, "SATELCO Multimedia PCI", BUDGET_TT_HW_DISEQC); 526MAKE_BUDGET_INFO(satel, "SATELCO Multimedia PCI", BUDGET_TT_HW_DISEQC);
527MAKE_BUDGET_INFO(ttbs1401, "TT-Budget-S-1401 PCI", BUDGET_TT);
500MAKE_BUDGET_INFO(fsacs0, "Fujitsu Siemens Activy Budget-S PCI (rev GR/grundig frontend)", BUDGET_FS_ACTIVY); 528MAKE_BUDGET_INFO(fsacs0, "Fujitsu Siemens Activy Budget-S PCI (rev GR/grundig frontend)", BUDGET_FS_ACTIVY);
501MAKE_BUDGET_INFO(fsacs1, "Fujitsu Siemens Activy Budget-S PCI (rev AL/alps frontend)", BUDGET_FS_ACTIVY); 529MAKE_BUDGET_INFO(fsacs1, "Fujitsu Siemens Activy Budget-S PCI (rev AL/alps frontend)", BUDGET_FS_ACTIVY);
502 530
@@ -506,6 +534,7 @@ static struct pci_device_id pci_tbl[] = {
506 MAKE_EXTENSION_PCI(ttbt, 0x13c2, 0x1005), 534 MAKE_EXTENSION_PCI(ttbt, 0x13c2, 0x1005),
507 MAKE_EXTENSION_PCI(satel, 0x13c2, 0x1013), 535 MAKE_EXTENSION_PCI(satel, 0x13c2, 0x1013),
508 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1016), 536 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1016),
537 MAKE_EXTENSION_PCI(ttbs1401, 0x13c2, 0x1018),
509 MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60), 538 MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60),
510 MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61), 539 MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61),
511 { 540 {
@@ -516,7 +545,7 @@ static struct pci_device_id pci_tbl[] = {
516MODULE_DEVICE_TABLE(pci, pci_tbl); 545MODULE_DEVICE_TABLE(pci, pci_tbl);
517 546
518static struct saa7146_extension budget_extension = { 547static struct saa7146_extension budget_extension = {
519 .name = "budget dvb\0", 548 .name = "budget dvb",
520 .flags = SAA7146_I2C_SHORT_DELAY, 549 .flags = SAA7146_I2C_SHORT_DELAY,
521 550
522 .module = THIS_MODULE, 551 .module = THIS_MODULE,
diff --git a/drivers/media/dvb/ttusb-budget/Kconfig b/drivers/media/dvb/ttusb-budget/Kconfig
index 46a6a60d2ab9..e78ea9227b0e 100644
--- a/drivers/media/dvb/ttusb-budget/Kconfig
+++ b/drivers/media/dvb/ttusb-budget/Kconfig
@@ -2,13 +2,13 @@ config DVB_TTUSB_BUDGET
2 tristate "Technotrend/Hauppauge Nova-USB devices" 2 tristate "Technotrend/Hauppauge Nova-USB devices"
3 depends on DVB_CORE && USB && I2C 3 depends on DVB_CORE && USB && I2C
4 select DVB_PLL 4 select DVB_PLL
5 select DVB_CX22700 5 select DVB_CX22700 if !DVB_FE_CUSTOMISE
6 select DVB_TDA1004X 6 select DVB_TDA1004X if !DVB_FE_CUSTOMISE
7 select DVB_VES1820 7 select DVB_VES1820 if !DVB_FE_CUSTOMISE
8 select DVB_TDA8083 8 select DVB_TDA8083 if !DVB_FE_CUSTOMISE
9 select DVB_STV0299 9 select DVB_STV0299 if !DVB_FE_CUSTOMISE
10 select DVB_STV0297 10 select DVB_STV0297 if !DVB_FE_CUSTOMISE
11 select DVB_LNBP21 11 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
12 help 12 help
13 Support for external USB adapters designed by Technotrend and 13 Support for external USB adapters designed by Technotrend and
14 produced by Hauppauge, shipped under the brand name 'Nova-USB'. 14 produced by Hauppauge, shipped under the brand name 'Nova-USB'.
diff --git a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
index 04cef3023457..234199875f53 100644
--- a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
@@ -1107,17 +1107,17 @@ static int philips_tdm1316l_tuner_set_params(struct dvb_frontend* fe, struct dvb
1107 // setup PLL filter 1107 // setup PLL filter
1108 switch (params->u.ofdm.bandwidth) { 1108 switch (params->u.ofdm.bandwidth) {
1109 case BANDWIDTH_6_MHZ: 1109 case BANDWIDTH_6_MHZ:
1110 tda1004x_write_byte(fe, 0x0C, 0); 1110 tda1004x_writereg(fe, 0x0C, 0);
1111 filter = 0; 1111 filter = 0;
1112 break; 1112 break;
1113 1113
1114 case BANDWIDTH_7_MHZ: 1114 case BANDWIDTH_7_MHZ:
1115 tda1004x_write_byte(fe, 0x0C, 0); 1115 tda1004x_writereg(fe, 0x0C, 0);
1116 filter = 0; 1116 filter = 0;
1117 break; 1117 break;
1118 1118
1119 case BANDWIDTH_8_MHZ: 1119 case BANDWIDTH_8_MHZ:
1120 tda1004x_write_byte(fe, 0x0C, 0xFF); 1120 tda1004x_writereg(fe, 0x0C, 0xFF);
1121 filter = 1; 1121 filter = 1;
1122 break; 1122 break;
1123 1123
@@ -1564,13 +1564,13 @@ static void frontend_init(struct ttusb* ttusb)
1564 switch(le16_to_cpu(ttusb->dev->descriptor.idProduct)) { 1564 switch(le16_to_cpu(ttusb->dev->descriptor.idProduct)) {
1565 case 0x1003: // Hauppauge/TT Nova-USB-S budget (stv0299/ALPS BSRU6|BSBE1(tsa5059)) 1565 case 0x1003: // Hauppauge/TT Nova-USB-S budget (stv0299/ALPS BSRU6|BSBE1(tsa5059))
1566 // try the stv0299 based first 1566 // try the stv0299 based first
1567 ttusb->fe = stv0299_attach(&alps_stv0299_config, &ttusb->i2c_adap); 1567 ttusb->fe = dvb_attach(stv0299_attach, &alps_stv0299_config, &ttusb->i2c_adap);
1568 if (ttusb->fe != NULL) { 1568 if (ttusb->fe != NULL) {
1569 ttusb->fe->ops.tuner_ops.set_params = philips_tsa5059_tuner_set_params; 1569 ttusb->fe->ops.tuner_ops.set_params = philips_tsa5059_tuner_set_params;
1570 1570
1571 if(ttusb->revision == TTUSB_REV_2_2) { // ALPS BSBE1 1571 if(ttusb->revision == TTUSB_REV_2_2) { // ALPS BSBE1
1572 alps_stv0299_config.inittab = alps_bsbe1_inittab; 1572 alps_stv0299_config.inittab = alps_bsbe1_inittab;
1573 lnbp21_attach(ttusb->fe, &ttusb->i2c_adap, 0, 0); 1573 dvb_attach(lnbp21_attach, ttusb->fe, &ttusb->i2c_adap, 0, 0);
1574 } else { // ALPS BSRU6 1574 } else { // ALPS BSRU6
1575 ttusb->fe->ops.set_voltage = ttusb_set_voltage; 1575 ttusb->fe->ops.set_voltage = ttusb_set_voltage;
1576 } 1576 }
@@ -1578,7 +1578,7 @@ static void frontend_init(struct ttusb* ttusb)
1578 } 1578 }
1579 1579
1580 // Grundig 29504-491 1580 // Grundig 29504-491
1581 ttusb->fe = tda8083_attach(&ttusb_novas_grundig_29504_491_config, &ttusb->i2c_adap); 1581 ttusb->fe = dvb_attach(tda8083_attach, &ttusb_novas_grundig_29504_491_config, &ttusb->i2c_adap);
1582 if (ttusb->fe != NULL) { 1582 if (ttusb->fe != NULL) {
1583 ttusb->fe->ops.tuner_ops.set_params = ttusb_novas_grundig_29504_491_tuner_set_params; 1583 ttusb->fe->ops.tuner_ops.set_params = ttusb_novas_grundig_29504_491_tuner_set_params;
1584 ttusb->fe->ops.set_voltage = ttusb_set_voltage; 1584 ttusb->fe->ops.set_voltage = ttusb_set_voltage;
@@ -1587,13 +1587,13 @@ static void frontend_init(struct ttusb* ttusb)
1587 break; 1587 break;
1588 1588
1589 case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659)) 1589 case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659))
1590 ttusb->fe = ves1820_attach(&alps_tdbe2_config, &ttusb->i2c_adap, read_pwm(ttusb)); 1590 ttusb->fe = dvb_attach(ves1820_attach, &alps_tdbe2_config, &ttusb->i2c_adap, read_pwm(ttusb));
1591 if (ttusb->fe != NULL) { 1591 if (ttusb->fe != NULL) {
1592 ttusb->fe->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params; 1592 ttusb->fe->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params;
1593 break; 1593 break;
1594 } 1594 }
1595 1595
1596 ttusb->fe = stv0297_attach(&dvbc_philips_tdm1316l_config, &ttusb->i2c_adap); 1596 ttusb->fe = dvb_attach(stv0297_attach, &dvbc_philips_tdm1316l_config, &ttusb->i2c_adap);
1597 if (ttusb->fe != NULL) { 1597 if (ttusb->fe != NULL) {
1598 ttusb->fe->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params; 1598 ttusb->fe->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params;
1599 break; 1599 break;
@@ -1602,14 +1602,14 @@ static void frontend_init(struct ttusb* ttusb)
1602 1602
1603 case 0x1005: // Hauppauge/TT Nova-USB-t budget (tda10046/Philips td1316(tda6651tt) OR cx22700/ALPS TDMB7(??)) 1603 case 0x1005: // Hauppauge/TT Nova-USB-t budget (tda10046/Philips td1316(tda6651tt) OR cx22700/ALPS TDMB7(??))
1604 // try the ALPS TDMB7 first 1604 // try the ALPS TDMB7 first
1605 ttusb->fe = cx22700_attach(&alps_tdmb7_config, &ttusb->i2c_adap); 1605 ttusb->fe = dvb_attach(cx22700_attach, &alps_tdmb7_config, &ttusb->i2c_adap);
1606 if (ttusb->fe != NULL) { 1606 if (ttusb->fe != NULL) {
1607 ttusb->fe->ops.tuner_ops.set_params = alps_tdmb7_tuner_set_params; 1607 ttusb->fe->ops.tuner_ops.set_params = alps_tdmb7_tuner_set_params;
1608 break; 1608 break;
1609 } 1609 }
1610 1610
1611 // Philips td1316 1611 // Philips td1316
1612 ttusb->fe = tda10046_attach(&philips_tdm1316l_config, &ttusb->i2c_adap); 1612 ttusb->fe = dvb_attach(tda10046_attach, &philips_tdm1316l_config, &ttusb->i2c_adap);
1613 if (ttusb->fe != NULL) { 1613 if (ttusb->fe != NULL) {
1614 ttusb->fe->ops.tuner_ops.init = philips_tdm1316l_tuner_init; 1614 ttusb->fe->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
1615 ttusb->fe->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params; 1615 ttusb->fe->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
@@ -1625,8 +1625,7 @@ static void frontend_init(struct ttusb* ttusb)
1625 } else { 1625 } else {
1626 if (dvb_register_frontend(&ttusb->adapter, ttusb->fe)) { 1626 if (dvb_register_frontend(&ttusb->adapter, ttusb->fe)) {
1627 printk("dvb-ttusb-budget: Frontend registration failed!\n"); 1627 printk("dvb-ttusb-budget: Frontend registration failed!\n");
1628 if (ttusb->fe->ops.release) 1628 dvb_frontend_detach(ttusb->fe);
1629 ttusb->fe->ops.release(ttusb->fe);
1630 ttusb->fe = NULL; 1629 ttusb->fe = NULL;
1631 } 1630 }
1632 } 1631 }
@@ -1763,7 +1762,10 @@ static void ttusb_disconnect(struct usb_interface *intf)
1763 dvb_net_release(&ttusb->dvbnet); 1762 dvb_net_release(&ttusb->dvbnet);
1764 dvb_dmxdev_release(&ttusb->dmxdev); 1763 dvb_dmxdev_release(&ttusb->dmxdev);
1765 dvb_dmx_release(&ttusb->dvb_demux); 1764 dvb_dmx_release(&ttusb->dvb_demux);
1766 if (ttusb->fe != NULL) dvb_unregister_frontend(ttusb->fe); 1765 if (ttusb->fe != NULL) {
1766 dvb_unregister_frontend(ttusb->fe);
1767 dvb_frontend_detach(ttusb->fe);
1768 }
1767 i2c_del_adapter(&ttusb->i2c_adap); 1769 i2c_del_adapter(&ttusb->i2c_adap);
1768 dvb_unregister_adapter(&ttusb->adapter); 1770 dvb_unregister_adapter(&ttusb->adapter);
1769 1771
diff --git a/drivers/media/dvb/ttusb-dec/ttusb_dec.c b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
index 6c1cb770bcf5..de077a757192 100644
--- a/drivers/media/dvb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
@@ -215,7 +215,7 @@ static void ttusb_dec_handle_irq( struct urb *urb, struct pt_regs *regs)
215 case -ECONNRESET: 215 case -ECONNRESET:
216 case -ENOENT: 216 case -ENOENT:
217 case -ESHUTDOWN: 217 case -ESHUTDOWN:
218 case -ETIMEDOUT: 218 case -ETIME:
219 /* this urb is dead, cleanup */ 219 /* this urb is dead, cleanup */
220 dprintk("%s:urb shutting down with status: %d\n", 220 dprintk("%s:urb shutting down with status: %d\n",
221 __FUNCTION__, urb->status); 221 __FUNCTION__, urb->status);
@@ -1512,7 +1512,11 @@ static void ttusb_dec_exit_dvb(struct ttusb_dec *dec)
1512 dec->demux.dmx.remove_frontend(&dec->demux.dmx, &dec->frontend); 1512 dec->demux.dmx.remove_frontend(&dec->demux.dmx, &dec->frontend);
1513 dvb_dmxdev_release(&dec->dmxdev); 1513 dvb_dmxdev_release(&dec->dmxdev);
1514 dvb_dmx_release(&dec->demux); 1514 dvb_dmx_release(&dec->demux);
1515 if (dec->fe) dvb_unregister_frontend(dec->fe); 1515 if (dec->fe) {
1516 dvb_unregister_frontend(dec->fe);
1517 if (dec->fe->ops.release)
1518 dec->fe->ops.release(dec->fe);
1519 }
1516 dvb_unregister_adapter(&dec->adapter); 1520 dvb_unregister_adapter(&dec->adapter);
1517} 1521}
1518 1522
diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig
index 220076b1b956..7015517e2c1b 100644
--- a/drivers/media/radio/Kconfig
+++ b/drivers/media/radio/Kconfig
@@ -7,7 +7,7 @@ menu "Radio Adapters"
7 7
8config RADIO_CADET 8config RADIO_CADET
9 tristate "ADS Cadet AM/FM Tuner" 9 tristate "ADS Cadet AM/FM Tuner"
10 depends on ISA && VIDEO_V4L1 10 depends on ISA && VIDEO_V4L2
11 ---help--- 11 ---help---
12 Choose Y here if you have one of these AM/FM radio cards, and then 12 Choose Y here if you have one of these AM/FM radio cards, and then
13 fill in the port address below. 13 fill in the port address below.
@@ -25,7 +25,7 @@ config RADIO_CADET
25 25
26config RADIO_RTRACK 26config RADIO_RTRACK
27 tristate "AIMSlab RadioTrack (aka RadioReveal) support" 27 tristate "AIMSlab RadioTrack (aka RadioReveal) support"
28 depends on ISA && VIDEO_V4L1 28 depends on ISA && VIDEO_V4L2
29 ---help--- 29 ---help---
30 Choose Y here if you have one of these FM radio cards, and then fill 30 Choose Y here if you have one of these FM radio cards, and then fill
31 in the port address below. 31 in the port address below.
@@ -59,7 +59,7 @@ config RADIO_RTRACK_PORT
59 59
60config RADIO_RTRACK2 60config RADIO_RTRACK2
61 tristate "AIMSlab RadioTrack II support" 61 tristate "AIMSlab RadioTrack II support"
62 depends on ISA && VIDEO_V4L1 62 depends on ISA && VIDEO_V4L2
63 ---help--- 63 ---help---
64 Choose Y here if you have this FM radio card, and then fill in the 64 Choose Y here if you have this FM radio card, and then fill in the
65 port address below. 65 port address below.
@@ -82,7 +82,7 @@ config RADIO_RTRACK2_PORT
82 82
83config RADIO_AZTECH 83config RADIO_AZTECH
84 tristate "Aztech/Packard Bell Radio" 84 tristate "Aztech/Packard Bell Radio"
85 depends on ISA && VIDEO_V4L1 85 depends on ISA && VIDEO_V4L2
86 ---help--- 86 ---help---
87 Choose Y here if you have one of these FM radio cards, and then fill 87 Choose Y here if you have one of these FM radio cards, and then fill
88 in the port address below. 88 in the port address below.
@@ -106,7 +106,7 @@ config RADIO_AZTECH_PORT
106 106
107config RADIO_GEMTEK 107config RADIO_GEMTEK
108 tristate "GemTek Radio Card support" 108 tristate "GemTek Radio Card support"
109 depends on ISA && VIDEO_V4L1 109 depends on ISA && VIDEO_V4L2
110 ---help--- 110 ---help---
111 Choose Y here if you have this FM radio card, and then fill in the 111 Choose Y here if you have this FM radio card, and then fill in the
112 port address below. 112 port address below.
@@ -131,7 +131,7 @@ config RADIO_GEMTEK_PORT
131 131
132config RADIO_GEMTEK_PCI 132config RADIO_GEMTEK_PCI
133 tristate "GemTek PCI Radio Card support" 133 tristate "GemTek PCI Radio Card support"
134 depends on VIDEO_V4L1 && PCI 134 depends on VIDEO_V4L2 && PCI
135 ---help--- 135 ---help---
136 Choose Y here if you have this PCI FM radio card. 136 Choose Y here if you have this PCI FM radio card.
137 137
@@ -145,7 +145,7 @@ config RADIO_GEMTEK_PCI
145 145
146config RADIO_MAXIRADIO 146config RADIO_MAXIRADIO
147 tristate "Guillemot MAXI Radio FM 2000 radio" 147 tristate "Guillemot MAXI Radio FM 2000 radio"
148 depends on VIDEO_V4L1 && PCI 148 depends on VIDEO_V4L2 && PCI
149 ---help--- 149 ---help---
150 Choose Y here if you have this radio card. This card may also be 150 Choose Y here if you have this radio card. This card may also be
151 found as Gemtek PCI FM. 151 found as Gemtek PCI FM.
@@ -160,7 +160,7 @@ config RADIO_MAXIRADIO
160 160
161config RADIO_MAESTRO 161config RADIO_MAESTRO
162 tristate "Maestro on board radio" 162 tristate "Maestro on board radio"
163 depends on VIDEO_V4L1 163 depends on VIDEO_V4L2 && PCI
164 ---help--- 164 ---help---
165 Say Y here to directly support the on-board radio tuner on the 165 Say Y here to directly support the on-board radio tuner on the
166 Maestro 2 or 2E sound card. 166 Maestro 2 or 2E sound card.
@@ -208,7 +208,7 @@ config RADIO_MIROPCM20_RDS
208 208
209config RADIO_SF16FMI 209config RADIO_SF16FMI
210 tristate "SF16FMI Radio" 210 tristate "SF16FMI Radio"
211 depends on ISA && VIDEO_V4L1 211 depends on ISA && VIDEO_V4L2
212 ---help--- 212 ---help---
213 Choose Y here if you have one of these FM radio cards. If you 213 Choose Y here if you have one of these FM radio cards. If you
214 compile the driver into the kernel and your card is not PnP one, you 214 compile the driver into the kernel and your card is not PnP one, you
@@ -225,7 +225,7 @@ config RADIO_SF16FMI
225 225
226config RADIO_SF16FMR2 226config RADIO_SF16FMR2
227 tristate "SF16FMR2 Radio" 227 tristate "SF16FMR2 Radio"
228 depends on ISA && VIDEO_V4L1 228 depends on ISA && VIDEO_V4L2
229 ---help--- 229 ---help---
230 Choose Y here if you have one of these FM radio cards. 230 Choose Y here if you have one of these FM radio cards.
231 231
@@ -239,7 +239,7 @@ config RADIO_SF16FMR2
239 239
240config RADIO_TERRATEC 240config RADIO_TERRATEC
241 tristate "TerraTec ActiveRadio ISA Standalone" 241 tristate "TerraTec ActiveRadio ISA Standalone"
242 depends on ISA && VIDEO_V4L1 242 depends on ISA && VIDEO_V4L2
243 ---help--- 243 ---help---
244 Choose Y here if you have this FM radio card, and then fill in the 244 Choose Y here if you have this FM radio card, and then fill in the
245 port address below. (TODO) 245 port address below. (TODO)
@@ -268,7 +268,7 @@ config RADIO_TERRATEC_PORT
268 268
269config RADIO_TRUST 269config RADIO_TRUST
270 tristate "Trust FM radio card" 270 tristate "Trust FM radio card"
271 depends on ISA && VIDEO_V4L1 271 depends on ISA && VIDEO_V4L2
272 help 272 help
273 This is a driver for the Trust FM radio cards. Say Y if you have 273 This is a driver for the Trust FM radio cards. Say Y if you have
274 such a card and want to use it under Linux. 274 such a card and want to use it under Linux.
@@ -286,7 +286,7 @@ config RADIO_TRUST_PORT
286 286
287config RADIO_TYPHOON 287config RADIO_TYPHOON
288 tristate "Typhoon Radio (a.k.a. EcoRadio)" 288 tristate "Typhoon Radio (a.k.a. EcoRadio)"
289 depends on ISA && VIDEO_V4L1 289 depends on ISA && VIDEO_V4L2
290 ---help--- 290 ---help---
291 Choose Y here if you have one of these FM radio cards, and then fill 291 Choose Y here if you have one of these FM radio cards, and then fill
292 in the port address and the frequency used for muting below. 292 in the port address and the frequency used for muting below.
@@ -330,7 +330,7 @@ config RADIO_TYPHOON_MUTEFREQ
330 330
331config RADIO_ZOLTRIX 331config RADIO_ZOLTRIX
332 tristate "Zoltrix Radio" 332 tristate "Zoltrix Radio"
333 depends on ISA && VIDEO_V4L1 333 depends on ISA && VIDEO_V4L2
334 ---help--- 334 ---help---
335 Choose Y here if you have one of these FM radio cards, and then fill 335 Choose Y here if you have one of these FM radio cards, and then fill
336 in the port address below. 336 in the port address below.
@@ -352,7 +352,7 @@ config RADIO_ZOLTRIX_PORT
352 352
353config USB_DSBR 353config USB_DSBR
354 tristate "D-Link USB FM radio support (EXPERIMENTAL)" 354 tristate "D-Link USB FM radio support (EXPERIMENTAL)"
355 depends on USB && VIDEO_V4L1 && EXPERIMENTAL 355 depends on USB && VIDEO_V4L2 && EXPERIMENTAL
356 ---help--- 356 ---help---
357 Say Y here if you want to connect this type of radio to your 357 Say Y here if you want to connect this type of radio to your
358 computer's USB port. Note that the audio is not digital, and 358 computer's USB port. Note that the audio is not digital, and
diff --git a/drivers/media/radio/dsbr100.c b/drivers/media/radio/dsbr100.c
index f7e33f9ee8e9..db865a0667e5 100644
--- a/drivers/media/radio/dsbr100.c
+++ b/drivers/media/radio/dsbr100.c
@@ -33,8 +33,14 @@
33 33
34 History: 34 History:
35 35
36 Version 0.41-ac1:
37 Alan Cox: Some cleanups and fixes
38
39 Version 0.41:
40 Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
41
36 Version 0.40: 42 Version 0.40:
37 Markus: Updates for 2.6.x kernels, code layout changes, name sanitizing 43 Markus: Updates for 2.6.x kernels, code layout changes, name sanitizing
38 44
39 Version 0.30: 45 Version 0.30:
40 Markus: Updates for 2.5.x kernel and more ISO compliant source 46 Markus: Updates for 2.5.x kernel and more ISO compliant source
@@ -65,13 +71,12 @@
65 71
66*/ 72*/
67 73
68
69#include <linux/kernel.h> 74#include <linux/kernel.h>
70#include <linux/module.h> 75#include <linux/module.h>
71#include <linux/init.h> 76#include <linux/init.h>
72#include <linux/slab.h> 77#include <linux/slab.h>
73#include <linux/input.h> 78#include <linux/input.h>
74#include <linux/videodev.h> 79#include <linux/videodev2.h>
75#include <media/v4l2-common.h> 80#include <media/v4l2-common.h>
76#include <linux/usb.h> 81#include <linux/usb.h>
77#include <linux/smp_lock.h> 82#include <linux/smp_lock.h>
@@ -79,7 +84,22 @@
79/* 84/*
80 * Version Information 85 * Version Information
81 */ 86 */
82#define DRIVER_VERSION "v0.40" 87#include <linux/version.h> /* for KERNEL_VERSION MACRO */
88
89#define DRIVER_VERSION "v0.41"
90#define RADIO_VERSION KERNEL_VERSION(0,4,1)
91
92static struct v4l2_queryctrl radio_qctrl[] = {
93 {
94 .id = V4L2_CID_AUDIO_MUTE,
95 .name = "Mute",
96 .minimum = 0,
97 .maximum = 1,
98 .default_value = 1,
99 .type = V4L2_CTRL_TYPE_BOOLEAN,
100 }
101};
102
83#define DRIVER_AUTHOR "Markus Demleitner <msdemlei@tucana.harvard.edu>" 103#define DRIVER_AUTHOR "Markus Demleitner <msdemlei@tucana.harvard.edu>"
84#define DRIVER_DESC "D-Link DSB-R100 USB FM radio driver" 104#define DRIVER_DESC "D-Link DSB-R100 USB FM radio driver"
85 105
@@ -111,7 +131,7 @@ static int radio_nr = -1;
111module_param(radio_nr, int, 0); 131module_param(radio_nr, int, 0);
112 132
113/* Data for one (physical) device */ 133/* Data for one (physical) device */
114typedef struct { 134struct dsbr100_device {
115 struct usb_device *usbdev; 135 struct usb_device *usbdev;
116 struct video_device *videodev; 136 struct video_device *videodev;
117 unsigned char transfer_buffer[TB_LEN]; 137 unsigned char transfer_buffer[TB_LEN];
@@ -119,7 +139,8 @@ typedef struct {
119 int stereo; 139 int stereo;
120 int users; 140 int users;
121 int removed; 141 int removed;
122} dsbr100_device; 142 int muted;
143};
123 144
124 145
125/* File system interface */ 146/* File system interface */
@@ -138,7 +159,6 @@ static struct video_device dsbr100_videodev_template=
138 .owner = THIS_MODULE, 159 .owner = THIS_MODULE,
139 .name = "D-Link DSB-R 100", 160 .name = "D-Link DSB-R 100",
140 .type = VID_TYPE_TUNER, 161 .type = VID_TYPE_TUNER,
141 .hardware = VID_HARDWARE_AZTECH,
142 .fops = &usb_dsbr100_fops, 162 .fops = &usb_dsbr100_fops,
143 .release = video_device_release, 163 .release = video_device_release,
144}; 164};
@@ -161,7 +181,7 @@ static struct usb_driver usb_dsbr100_driver = {
161/* Low-level device interface begins here */ 181/* Low-level device interface begins here */
162 182
163/* switch on radio */ 183/* switch on radio */
164static int dsbr100_start(dsbr100_device *radio) 184static int dsbr100_start(struct dsbr100_device *radio)
165{ 185{
166 if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), 186 if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0),
167 USB_REQ_GET_STATUS, 187 USB_REQ_GET_STATUS,
@@ -172,12 +192,13 @@ static int dsbr100_start(dsbr100_device *radio)
172 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 192 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
173 0x01, 0x00, radio->transfer_buffer, 8, 300)<0) 193 0x01, 0x00, radio->transfer_buffer, 8, 300)<0)
174 return -1; 194 return -1;
195 radio->muted=0;
175 return (radio->transfer_buffer)[0]; 196 return (radio->transfer_buffer)[0];
176} 197}
177 198
178 199
179/* switch off radio */ 200/* switch off radio */
180static int dsbr100_stop(dsbr100_device *radio) 201static int dsbr100_stop(struct dsbr100_device *radio)
181{ 202{
182 if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), 203 if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0),
183 USB_REQ_GET_STATUS, 204 USB_REQ_GET_STATUS,
@@ -188,11 +209,12 @@ static int dsbr100_stop(dsbr100_device *radio)
188 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 209 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
189 0x00, 0x00, radio->transfer_buffer, 8, 300)<0) 210 0x00, 0x00, radio->transfer_buffer, 8, 300)<0)
190 return -1; 211 return -1;
212 radio->muted=1;
191 return (radio->transfer_buffer)[0]; 213 return (radio->transfer_buffer)[0];
192} 214}
193 215
194/* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */ 216/* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */
195static int dsbr100_setfreq(dsbr100_device *radio, int freq) 217static int dsbr100_setfreq(struct dsbr100_device *radio, int freq)
196{ 218{
197 freq = (freq/16*80)/1000+856; 219 freq = (freq/16*80)/1000+856;
198 if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), 220 if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0),
@@ -217,7 +239,7 @@ static int dsbr100_setfreq(dsbr100_device *radio, int freq)
217 239
218/* return the device status. This is, in effect, just whether it 240/* return the device status. This is, in effect, just whether it
219sees a stereo signal or not. Pity. */ 241sees a stereo signal or not. Pity. */
220static void dsbr100_getstat(dsbr100_device *radio) 242static void dsbr100_getstat(struct dsbr100_device *radio)
221{ 243{
222 if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), 244 if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0),
223 USB_REQ_GET_STATUS, 245 USB_REQ_GET_STATUS,
@@ -236,9 +258,9 @@ usb if it is */
236static int usb_dsbr100_probe(struct usb_interface *intf, 258static int usb_dsbr100_probe(struct usb_interface *intf,
237 const struct usb_device_id *id) 259 const struct usb_device_id *id)
238{ 260{
239 dsbr100_device *radio; 261 struct dsbr100_device *radio;
240 262
241 if (!(radio = kmalloc(sizeof(dsbr100_device), GFP_KERNEL))) 263 if (!(radio = kmalloc(sizeof(struct dsbr100_device), GFP_KERNEL)))
242 return -ENOMEM; 264 return -ENOMEM;
243 if (!(radio->videodev = video_device_alloc())) { 265 if (!(radio->videodev = video_device_alloc())) {
244 kfree(radio); 266 kfree(radio);
@@ -271,7 +293,7 @@ code I'd expect I better did that, but if there's a memory
271leak here it's tiny (~50 bytes per disconnect) */ 293leak here it's tiny (~50 bytes per disconnect) */
272static void usb_dsbr100_disconnect(struct usb_interface *intf) 294static void usb_dsbr100_disconnect(struct usb_interface *intf)
273{ 295{
274 dsbr100_device *radio = usb_get_intfdata(intf); 296 struct dsbr100_device *radio = usb_get_intfdata(intf);
275 297
276 usb_set_intfdata (intf, NULL); 298 usb_set_intfdata (intf, NULL);
277 if (radio) { 299 if (radio) {
@@ -291,89 +313,121 @@ static void usb_dsbr100_disconnect(struct usb_interface *intf)
291static int usb_dsbr100_do_ioctl(struct inode *inode, struct file *file, 313static int usb_dsbr100_do_ioctl(struct inode *inode, struct file *file,
292 unsigned int cmd, void *arg) 314 unsigned int cmd, void *arg)
293{ 315{
294 dsbr100_device *radio=video_get_drvdata(video_devdata(file)); 316 struct dsbr100_device *radio=video_get_drvdata(video_devdata(file));
295 317
296 if (!radio) 318 if (!radio)
297 return -EIO; 319 return -EIO;
298 320
299 switch(cmd) { 321 switch(cmd) {
300 case VIDIOCGCAP: { 322 case VIDIOC_QUERYCAP:
301 struct video_capability *v = arg; 323 {
302 324 struct v4l2_capability *v = arg;
303 memset(v, 0, sizeof(*v)); 325 memset(v,0,sizeof(*v));
304 v->type = VID_TYPE_TUNER; 326 strlcpy(v->driver, "dsbr100", sizeof (v->driver));
305 v->channels = 1; 327 strlcpy(v->card, "D-Link R-100 USB FM Radio", sizeof (v->card));
306 v->audios = 1; 328 sprintf(v->bus_info,"ISA");
307 strcpy(v->name, "D-Link R-100 USB FM Radio"); 329 v->version = RADIO_VERSION;
330 v->capabilities = V4L2_CAP_TUNER;
331
308 return 0; 332 return 0;
309 } 333 }
310 case VIDIOCGTUNER: { 334 case VIDIOC_G_TUNER:
311 struct video_tuner *v = arg; 335 {
336 struct v4l2_tuner *v = arg;
312 337
313 dsbr100_getstat(radio); 338 if (v->index > 0)
314 if(v->tuner) /* Only 1 tuner */
315 return -EINVAL; 339 return -EINVAL;
340
341 dsbr100_getstat(radio);
342
343 memset(v,0,sizeof(*v));
344 strcpy(v->name, "FM");
345 v->type = V4L2_TUNER_RADIO;
346
316 v->rangelow = FREQ_MIN*FREQ_MUL; 347 v->rangelow = FREQ_MIN*FREQ_MUL;
317 v->rangehigh = FREQ_MAX*FREQ_MUL; 348 v->rangehigh = FREQ_MAX*FREQ_MUL;
318 v->flags = VIDEO_TUNER_LOW; 349 v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
319 v->mode = VIDEO_MODE_AUTO; 350 v->capability=V4L2_TUNER_CAP_LOW;
320 v->signal = radio->stereo*0x7000; 351 if(radio->stereo)
321 /* Don't know how to get signal strength */ 352 v->audmode = V4L2_TUNER_MODE_STEREO;
322 v->flags |= VIDEO_TUNER_STEREO_ON*radio->stereo; 353 else
323 strcpy(v->name, "DSB R-100"); 354 v->audmode = V4L2_TUNER_MODE_MONO;
324 return 0; 355 v->signal = 0xFFFF; /* We can't get the signal strength */
325 }
326 case VIDIOCSTUNER: {
327 struct video_tuner *v = arg;
328 356
329 if(v->tuner!=0)
330 return -EINVAL;
331 /* Only 1 tuner so no setting needed ! */
332 return 0; 357 return 0;
333 } 358 }
334 case VIDIOCGFREQ: { 359 case VIDIOC_S_TUNER:
335 int *freq = arg; 360 {
361 struct v4l2_tuner *v = arg;
336 362
337 if (radio->curfreq==-1) 363 if (v->index > 0)
338 return -EINVAL; 364 return -EINVAL;
339 *freq = radio->curfreq; 365
340 return 0; 366 return 0;
341 } 367 }
342 case VIDIOCSFREQ: { 368 case VIDIOC_S_FREQUENCY:
343 int *freq = arg; 369 {
370 struct v4l2_frequency *f = arg;
344 371
345 radio->curfreq = *freq; 372 radio->curfreq = f->frequency;
346 if (dsbr100_setfreq(radio, radio->curfreq)==-1) 373 if (dsbr100_setfreq(radio, radio->curfreq)==-1)
347 warn("Set frequency failed"); 374 warn("Set frequency failed");
348 return 0; 375 return 0;
349 } 376 }
350 case VIDIOCGAUDIO: { 377 case VIDIOC_G_FREQUENCY:
351 struct video_audio *v = arg; 378 {
352 379 struct v4l2_frequency *f = arg;
353 memset(v, 0, sizeof(*v)); 380
354 v->flags |= VIDEO_AUDIO_MUTABLE; 381 f->type = V4L2_TUNER_RADIO;
355 v->mode = VIDEO_SOUND_STEREO; 382 f->frequency = radio->curfreq;
356 v->volume = 1; 383
357 v->step = 1;
358 strcpy(v->name, "Radio");
359 return 0; 384 return 0;
360 } 385 }
361 case VIDIOCSAUDIO: { 386 case VIDIOC_QUERYCTRL:
362 struct video_audio *v = arg; 387 {
363 388 struct v4l2_queryctrl *qc = arg;
364 if (v->audio) 389 int i;
365 return -EINVAL; 390
366 if (v->flags&VIDEO_AUDIO_MUTE) { 391 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
367 if (dsbr100_stop(radio)==-1) 392 if (qc->id && qc->id == radio_qctrl[i].id) {
368 warn("Radio did not respond properly"); 393 memcpy(qc, &(radio_qctrl[i]),
394 sizeof(*qc));
395 return 0;
396 }
369 } 397 }
370 else 398 return -EINVAL;
371 if (dsbr100_start(radio)==-1) 399 }
372 warn("Radio did not respond properly"); 400 case VIDIOC_G_CTRL:
373 return 0; 401 {
402 struct v4l2_control *ctrl= arg;
403
404 switch (ctrl->id) {
405 case V4L2_CID_AUDIO_MUTE:
406 ctrl->value=radio->muted;
407 return 0;
408 }
409 return -EINVAL;
410 }
411 case VIDIOC_S_CTRL:
412 {
413 struct v4l2_control *ctrl= arg;
414
415 switch (ctrl->id) {
416 case V4L2_CID_AUDIO_MUTE:
417 if (ctrl->value) {
418 if (dsbr100_stop(radio)==-1)
419 warn("Radio did not respond properly");
420 } else {
421 if (dsbr100_start(radio)==-1)
422 warn("Radio did not respond properly");
423 }
424 return 0;
425 }
426 return -EINVAL;
374 } 427 }
375 default: 428 default:
376 return -ENOIOCTLCMD; 429 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
430 usb_dsbr100_do_ioctl);
377 } 431 }
378} 432}
379 433
@@ -385,9 +439,11 @@ static int usb_dsbr100_ioctl(struct inode *inode, struct file *file,
385 439
386static int usb_dsbr100_open(struct inode *inode, struct file *file) 440static int usb_dsbr100_open(struct inode *inode, struct file *file)
387{ 441{
388 dsbr100_device *radio=video_get_drvdata(video_devdata(file)); 442 struct dsbr100_device *radio=video_get_drvdata(video_devdata(file));
389 443
390 radio->users = 1; 444 radio->users = 1;
445 radio->muted = 1;
446
391 if (dsbr100_start(radio)<0) { 447 if (dsbr100_start(radio)<0) {
392 warn("Radio did not start up properly"); 448 warn("Radio did not start up properly");
393 radio->users = 0; 449 radio->users = 0;
@@ -399,7 +455,7 @@ static int usb_dsbr100_open(struct inode *inode, struct file *file)
399 455
400static int usb_dsbr100_close(struct inode *inode, struct file *file) 456static int usb_dsbr100_close(struct inode *inode, struct file *file)
401{ 457{
402 dsbr100_device *radio=video_get_drvdata(video_devdata(file)); 458 struct dsbr100_device *radio=video_get_drvdata(video_devdata(file));
403 459
404 if (!radio) 460 if (!radio)
405 return -ENODEV; 461 return -ENODEV;
diff --git a/drivers/media/radio/radio-aimslab.c b/drivers/media/radio/radio-aimslab.c
index df22a582e7a2..3368a89bfadb 100644
--- a/drivers/media/radio/radio-aimslab.c
+++ b/drivers/media/radio/radio-aimslab.c
@@ -1,5 +1,6 @@
1/* radiotrack (radioreveal) driver for Linux radio support 1/* radiotrack (radioreveal) driver for Linux radio support
2 * (c) 1997 M. Kirkwood 2 * (c) 1997 M. Kirkwood
3 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
3 * Converted to new API by Alan Cox <Alan.Cox@linux.org> 4 * Converted to new API by Alan Cox <Alan.Cox@linux.org>
4 * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org> 5 * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
5 * 6 *
@@ -33,11 +34,13 @@
33#include <linux/delay.h> /* udelay */ 34#include <linux/delay.h> /* udelay */
34#include <asm/io.h> /* outb, outb_p */ 35#include <asm/io.h> /* outb, outb_p */
35#include <asm/uaccess.h> /* copy to/from user */ 36#include <asm/uaccess.h> /* copy to/from user */
36#include <linux/videodev.h> /* kernel radio structs */ 37#include <linux/videodev2.h> /* kernel radio structs */
37#include <media/v4l2-common.h> 38#include <media/v4l2-common.h>
38#include <linux/config.h> /* CONFIG_RADIO_RTRACK_PORT */
39#include <asm/semaphore.h> /* Lock for the I/O */ 39#include <asm/semaphore.h> /* Lock for the I/O */
40 40
41#include <linux/version.h> /* for KERNEL_VERSION MACRO */
42#define RADIO_VERSION KERNEL_VERSION(0,0,2)
43
41#ifndef CONFIG_RADIO_RTRACK_PORT 44#ifndef CONFIG_RADIO_RTRACK_PORT
42#define CONFIG_RADIO_RTRACK_PORT -1 45#define CONFIG_RADIO_RTRACK_PORT -1
43#endif 46#endif
@@ -209,6 +212,25 @@ static int rt_getsigstr(struct rt_device *dev)
209 return 1; /* signal present */ 212 return 1; /* signal present */
210} 213}
211 214
215static struct v4l2_queryctrl radio_qctrl[] = {
216 {
217 .id = V4L2_CID_AUDIO_MUTE,
218 .name = "Mute",
219 .minimum = 0,
220 .maximum = 1,
221 .default_value = 1,
222 .type = V4L2_CTRL_TYPE_BOOLEAN,
223 },{
224 .id = V4L2_CID_AUDIO_VOLUME,
225 .name = "Volume",
226 .minimum = 0,
227 .maximum = 0xff,
228 .step = 1,
229 .default_value = 0xff,
230 .type = V4L2_CTRL_TYPE_INTEGER,
231 }
232};
233
212static int rt_do_ioctl(struct inode *inode, struct file *file, 234static int rt_do_ioctl(struct inode *inode, struct file *file,
213 unsigned int cmd, void *arg) 235 unsigned int cmd, void *arg)
214{ 236{
@@ -217,73 +239,114 @@ static int rt_do_ioctl(struct inode *inode, struct file *file,
217 239
218 switch(cmd) 240 switch(cmd)
219 { 241 {
220 case VIDIOCGCAP: 242 case VIDIOC_QUERYCAP:
221 { 243 {
222 struct video_capability *v = arg; 244 struct v4l2_capability *v = arg;
223 memset(v,0,sizeof(*v)); 245 memset(v,0,sizeof(*v));
224 v->type=VID_TYPE_TUNER; 246 strlcpy(v->driver, "radio-aimslab", sizeof (v->driver));
225 v->channels=1; 247 strlcpy(v->card, "RadioTrack", sizeof (v->card));
226 v->audios=1; 248 sprintf(v->bus_info,"ISA");
227 strcpy(v->name, "RadioTrack"); 249 v->version = RADIO_VERSION;
250 v->capabilities = V4L2_CAP_TUNER;
251
228 return 0; 252 return 0;
229 } 253 }
230 case VIDIOCGTUNER: 254 case VIDIOC_G_TUNER:
231 { 255 {
232 struct video_tuner *v = arg; 256 struct v4l2_tuner *v = arg;
233 if(v->tuner) /* Only 1 tuner */ 257
258 if (v->index > 0)
234 return -EINVAL; 259 return -EINVAL;
260
261 memset(v,0,sizeof(*v));
262 strcpy(v->name, "FM");
263 v->type = V4L2_TUNER_RADIO;
264
235 v->rangelow=(87*16000); 265 v->rangelow=(87*16000);
236 v->rangehigh=(108*16000); 266 v->rangehigh=(108*16000);
237 v->flags=VIDEO_TUNER_LOW; 267 v->rxsubchans =V4L2_TUNER_SUB_MONO;
238 v->mode=VIDEO_MODE_AUTO; 268 v->capability=V4L2_TUNER_CAP_LOW;
239 strcpy(v->name, "FM"); 269 v->audmode = V4L2_TUNER_MODE_MONO;
240 v->signal=0xFFFF*rt_getsigstr(rt); 270 v->signal=0xFFFF*rt_getsigstr(rt);
271
241 return 0; 272 return 0;
242 } 273 }
243 case VIDIOCSTUNER: 274 case VIDIOC_S_TUNER:
244 { 275 {
245 struct video_tuner *v = arg; 276 struct v4l2_tuner *v = arg;
246 if(v->tuner!=0) 277
278 if (v->index > 0)
247 return -EINVAL; 279 return -EINVAL;
248 /* Only 1 tuner so no setting needed ! */ 280
249 return 0; 281 return 0;
250 } 282 }
251 case VIDIOCGFREQ: 283 case VIDIOC_S_FREQUENCY:
252 { 284 {
253 unsigned long *freq = arg; 285 struct v4l2_frequency *f = arg;
254 *freq = rt->curfreq; 286
287 rt->curfreq = f->frequency;
288 rt_setfreq(rt, rt->curfreq);
255 return 0; 289 return 0;
256 } 290 }
257 case VIDIOCSFREQ: 291 case VIDIOC_G_FREQUENCY:
258 { 292 {
259 unsigned long *freq = arg; 293 struct v4l2_frequency *f = arg;
260 rt->curfreq = *freq; 294
261 rt_setfreq(rt, rt->curfreq); 295 f->type = V4L2_TUNER_RADIO;
296 f->frequency = rt->curfreq;
297
262 return 0; 298 return 0;
263 } 299 }
264 case VIDIOCGAUDIO: 300 case VIDIOC_QUERYCTRL:
265 { 301 {
266 struct video_audio *v = arg; 302 struct v4l2_queryctrl *qc = arg;
267 memset(v,0, sizeof(*v)); 303 int i;
268 v->flags|=VIDEO_AUDIO_MUTABLE|VIDEO_AUDIO_VOLUME; 304
269 v->volume=rt->curvol * 6554; 305 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
270 v->step=6554; 306 if (qc->id && qc->id == radio_qctrl[i].id) {
271 strcpy(v->name, "Radio"); 307 memcpy(qc, &(radio_qctrl[i]),
272 return 0; 308 sizeof(*qc));
309 return (0);
310 }
311 }
312 return -EINVAL;
273 } 313 }
274 case VIDIOCSAUDIO: 314 case VIDIOC_G_CTRL:
275 { 315 {
276 struct video_audio *v = arg; 316 struct v4l2_control *ctrl= arg;
277 if(v->audio) 317
278 return -EINVAL; 318 switch (ctrl->id) {
279 if(v->flags&VIDEO_AUDIO_MUTE) 319 case V4L2_CID_AUDIO_MUTE:
280 rt_mute(rt); 320 ctrl->value=rt->muted;
281 else 321 return (0);
282 rt_setvol(rt,v->volume/6554); 322 case V4L2_CID_AUDIO_VOLUME:
283 return 0; 323 ctrl->value=rt->curvol * 6554;
324 return (0);
325 }
326 return -EINVAL;
284 } 327 }
328 case VIDIOC_S_CTRL:
329 {
330 struct v4l2_control *ctrl= arg;
331
332 switch (ctrl->id) {
333 case V4L2_CID_AUDIO_MUTE:
334 if (ctrl->value) {
335 rt_mute(rt);
336 } else {
337 rt_setvol(rt,rt->curvol);
338 }
339 return (0);
340 case V4L2_CID_AUDIO_VOLUME:
341 rt_setvol(rt,ctrl->value);
342 return (0);
343 }
344 return -EINVAL;
345 }
346
285 default: 347 default:
286 return -ENOIOCTLCMD; 348 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
349 rt_do_ioctl);
287 } 350 }
288} 351}
289 352
@@ -309,7 +372,7 @@ static struct video_device rtrack_radio=
309 .owner = THIS_MODULE, 372 .owner = THIS_MODULE,
310 .name = "RadioTrack radio", 373 .name = "RadioTrack radio",
311 .type = VID_TYPE_TUNER, 374 .type = VID_TYPE_TUNER,
312 .hardware = VID_HARDWARE_RTRACK, 375 .hardware = 0,
313 .fops = &rtrack_fops, 376 .fops = &rtrack_fops,
314}; 377};
315 378
diff --git a/drivers/media/radio/radio-aztech.c b/drivers/media/radio/radio-aztech.c
index 95e6322133ee..3ba5fa8cf7e6 100644
--- a/drivers/media/radio/radio-aztech.c
+++ b/drivers/media/radio/radio-aztech.c
@@ -1,5 +1,6 @@
1/* radio-aztech.c - Aztech radio card driver for Linux 2.2 1/* radio-aztech.c - Aztech radio card driver for Linux 2.2
2 * 2 *
3 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
3 * Adapted to support the Video for Linux API by 4 * Adapted to support the Video for Linux API by
4 * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by: 5 * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by:
5 * 6 *
@@ -30,9 +31,30 @@
30#include <linux/delay.h> /* udelay */ 31#include <linux/delay.h> /* udelay */
31#include <asm/io.h> /* outb, outb_p */ 32#include <asm/io.h> /* outb, outb_p */
32#include <asm/uaccess.h> /* copy to/from user */ 33#include <asm/uaccess.h> /* copy to/from user */
33#include <linux/videodev.h> /* kernel radio structs */ 34#include <linux/videodev2.h> /* kernel radio structs */
34#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
35#include <linux/config.h> /* CONFIG_RADIO_AZTECH_PORT */ 36
37#include <linux/version.h> /* for KERNEL_VERSION MACRO */
38#define RADIO_VERSION KERNEL_VERSION(0,0,2)
39
40static struct v4l2_queryctrl radio_qctrl[] = {
41 {
42 .id = V4L2_CID_AUDIO_MUTE,
43 .name = "Mute",
44 .minimum = 0,
45 .maximum = 1,
46 .default_value = 1,
47 .type = V4L2_CTRL_TYPE_BOOLEAN,
48 },{
49 .id = V4L2_CID_AUDIO_VOLUME,
50 .name = "Volume",
51 .minimum = 0,
52 .maximum = 0xff,
53 .step = 1,
54 .default_value = 0xff,
55 .type = V4L2_CTRL_TYPE_INTEGER,
56 }
57};
36 58
37/* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */ 59/* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */
38 60
@@ -166,81 +188,121 @@ static int az_do_ioctl(struct inode *inode, struct file *file,
166 188
167 switch(cmd) 189 switch(cmd)
168 { 190 {
169 case VIDIOCGCAP: 191 case VIDIOC_QUERYCAP:
170 { 192 {
171 struct video_capability *v = arg; 193 struct v4l2_capability *v = arg;
172 memset(v,0,sizeof(*v)); 194 memset(v,0,sizeof(*v));
173 v->type=VID_TYPE_TUNER; 195 strlcpy(v->driver, "radio-aztech", sizeof (v->driver));
174 v->channels=1; 196 strlcpy(v->card, "Aztech Radio", sizeof (v->card));
175 v->audios=1; 197 sprintf(v->bus_info,"ISA");
176 strcpy(v->name, "Aztech Radio"); 198 v->version = RADIO_VERSION;
199 v->capabilities = V4L2_CAP_TUNER;
200
177 return 0; 201 return 0;
178 } 202 }
179 case VIDIOCGTUNER: 203 case VIDIOC_G_TUNER:
180 { 204 {
181 struct video_tuner *v = arg; 205 struct v4l2_tuner *v = arg;
182 if(v->tuner) /* Only 1 tuner */ 206
207 if (v->index > 0)
183 return -EINVAL; 208 return -EINVAL;
209
210 memset(v,0,sizeof(*v));
211 strcpy(v->name, "FM");
212 v->type = V4L2_TUNER_RADIO;
213
184 v->rangelow=(87*16000); 214 v->rangelow=(87*16000);
185 v->rangehigh=(108*16000); 215 v->rangehigh=(108*16000);
186 v->flags=VIDEO_TUNER_LOW; 216 v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
187 v->mode=VIDEO_MODE_AUTO; 217 v->capability=V4L2_TUNER_CAP_LOW;
188 v->signal=0xFFFF*az_getsigstr(az);
189 if(az_getstereo(az)) 218 if(az_getstereo(az))
190 v->flags|=VIDEO_TUNER_STEREO_ON; 219 v->audmode = V4L2_TUNER_MODE_STEREO;
191 strcpy(v->name, "FM"); 220 else
221 v->audmode = V4L2_TUNER_MODE_MONO;
222 v->signal=0xFFFF*az_getsigstr(az);
223
192 return 0; 224 return 0;
193 } 225 }
194 case VIDIOCSTUNER: 226 case VIDIOC_S_TUNER:
195 { 227 {
196 struct video_tuner *v = arg; 228 struct v4l2_tuner *v = arg;
197 if(v->tuner!=0) 229
230 if (v->index > 0)
198 return -EINVAL; 231 return -EINVAL;
232
199 return 0; 233 return 0;
200 } 234 }
201 case VIDIOCGFREQ: 235 case VIDIOC_S_FREQUENCY:
202 { 236 {
203 unsigned long *freq = arg; 237 struct v4l2_frequency *f = arg;
204 *freq = az->curfreq; 238
239 az->curfreq = f->frequency;
240 az_setfreq(az, az->curfreq);
205 return 0; 241 return 0;
206 } 242 }
207 case VIDIOCSFREQ: 243 case VIDIOC_G_FREQUENCY:
208 { 244 {
209 unsigned long *freq = arg; 245 struct v4l2_frequency *f = arg;
210 az->curfreq = *freq; 246
211 az_setfreq(az, az->curfreq); 247 f->type = V4L2_TUNER_RADIO;
248 f->frequency = az->curfreq;
249
212 return 0; 250 return 0;
213 } 251 }
214 case VIDIOCGAUDIO: 252
253 case VIDIOC_QUERYCTRL:
215 { 254 {
216 struct video_audio *v = arg; 255 struct v4l2_queryctrl *qc = arg;
217 memset(v,0, sizeof(*v)); 256 int i;
218 v->flags|=VIDEO_AUDIO_MUTABLE|VIDEO_AUDIO_VOLUME; 257
219 if(az->stereo) 258 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
220 v->mode=VIDEO_SOUND_STEREO; 259 if (qc->id && qc->id == radio_qctrl[i].id) {
221 else 260 memcpy(qc, &(radio_qctrl[i]),
222 v->mode=VIDEO_SOUND_MONO; 261 sizeof(*qc));
223 v->volume=az->curvol; 262 return (0);
224 v->step=16384; 263 }
225 strcpy(v->name, "Radio"); 264 }
226 return 0; 265 return -EINVAL;
227 } 266 }
228 case VIDIOCSAUDIO: 267 case VIDIOC_G_CTRL:
229 { 268 {
230 struct video_audio *v = arg; 269 struct v4l2_control *ctrl= arg;
231 if(v->audio) 270
232 return -EINVAL; 271 switch (ctrl->id) {
233 az->curvol=v->volume; 272 case V4L2_CID_AUDIO_MUTE:
234 273 if (az->curvol==0)
235 az->stereo=(v->mode&VIDEO_SOUND_STEREO)?1:0; 274 ctrl->value=1;
236 if(v->flags&VIDEO_AUDIO_MUTE) 275 else
237 az_setvol(az,0); 276 ctrl->value=0;
238 else 277 return (0);
239 az_setvol(az,az->curvol); 278 case V4L2_CID_AUDIO_VOLUME:
240 return 0; 279 ctrl->value=az->curvol * 6554;
280 return (0);
281 }
282 return -EINVAL;
283 }
284 case VIDIOC_S_CTRL:
285 {
286 struct v4l2_control *ctrl= arg;
287
288 switch (ctrl->id) {
289 case V4L2_CID_AUDIO_MUTE:
290 if (ctrl->value) {
291 az_setvol(az,0);
292 } else {
293 az_setvol(az,az->curvol);
294 }
295 return (0);
296 case V4L2_CID_AUDIO_VOLUME:
297 az_setvol(az,ctrl->value);
298 return (0);
299 }
300 return -EINVAL;
241 } 301 }
302
242 default: 303 default:
243 return -ENOIOCTLCMD; 304 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
305 az_do_ioctl);
244 } 306 }
245} 307}
246 308
@@ -266,7 +328,7 @@ static struct video_device aztech_radio=
266 .owner = THIS_MODULE, 328 .owner = THIS_MODULE,
267 .name = "Aztech radio", 329 .name = "Aztech radio",
268 .type = VID_TYPE_TUNER, 330 .type = VID_TYPE_TUNER,
269 .hardware = VID_HARDWARE_AZTECH, 331 .hardware = 0,
270 .fops = &aztech_fops, 332 .fops = &aztech_fops,
271}; 333};
272 334
diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
index 8641aec7baf8..69d4b7919c5a 100644
--- a/drivers/media/radio/radio-cadet.c
+++ b/drivers/media/radio/radio-cadet.c
@@ -25,20 +25,28 @@
25 * 25 *
26 * 2003-01-31 Alan Cox <alan@redhat.com> 26 * 2003-01-31 Alan Cox <alan@redhat.com>
27 * Cleaned up locking, delay code, general odds and ends 27 * Cleaned up locking, delay code, general odds and ends
28 *
29 * 2006-07-30 Hans J. Koch <koch@hjk-az.de>
30 * Changed API to V4L2
28 */ 31 */
29 32
33#include <linux/version.h>
30#include <linux/module.h> /* Modules */ 34#include <linux/module.h> /* Modules */
31#include <linux/init.h> /* Initdata */ 35#include <linux/init.h> /* Initdata */
32#include <linux/ioport.h> /* request_region */ 36#include <linux/ioport.h> /* request_region */
33#include <linux/delay.h> /* udelay */ 37#include <linux/delay.h> /* udelay */
34#include <asm/io.h> /* outb, outb_p */ 38#include <asm/io.h> /* outb, outb_p */
35#include <asm/uaccess.h> /* copy to/from user */ 39#include <asm/uaccess.h> /* copy to/from user */
36#include <linux/videodev.h> /* kernel radio structs */ 40#include <linux/videodev2.h> /* V4L2 API defs */
37#include <media/v4l2-common.h> 41#include <media/v4l2-common.h>
38#include <linux/param.h> 42#include <linux/param.h>
39#include <linux/pnp.h> 43#include <linux/pnp.h>
40 44
41#define RDS_BUFFER 256 45#define RDS_BUFFER 256
46#define RDS_RX_FLAG 1
47#define MBS_RX_FLAG 2
48
49#define CADET_VERSION KERNEL_VERSION(0,3,3)
42 50
43static int io=-1; /* default to isapnp activation */ 51static int io=-1; /* default to isapnp activation */
44static int radio_nr = -1; 52static int radio_nr = -1;
@@ -61,44 +69,24 @@ static int cadet_probe(void);
61 */ 69 */
62static __u16 sigtable[2][4]={{5,10,30,150},{28,40,63,1000}}; 70static __u16 sigtable[2][4]={{5,10,30,150},{28,40,63,1000}};
63 71
64static int cadet_getrds(void)
65{
66 int rdsstat=0;
67
68 spin_lock(&cadet_io_lock);
69 outb(3,io); /* Select Decoder Control/Status */
70 outb(inb(io+1)&0x7f,io+1); /* Reset RDS detection */
71 spin_unlock(&cadet_io_lock);
72
73 msleep(100);
74
75 spin_lock(&cadet_io_lock);
76 outb(3,io); /* Select Decoder Control/Status */
77 if((inb(io+1)&0x80)!=0) {
78 rdsstat|=VIDEO_TUNER_RDS_ON;
79 }
80 if((inb(io+1)&0x10)!=0) {
81 rdsstat|=VIDEO_TUNER_MBS_ON;
82 }
83 spin_unlock(&cadet_io_lock);
84 return rdsstat;
85}
86 72
87static int cadet_getstereo(void) 73static int
74cadet_getstereo(void)
88{ 75{
89 int ret = 0; 76 int ret = V4L2_TUNER_SUB_MONO;
90 if(curtuner != 0) /* Only FM has stereo capability! */ 77 if(curtuner != 0) /* Only FM has stereo capability! */
91 return 0; 78 return V4L2_TUNER_SUB_MONO;
92 79
93 spin_lock(&cadet_io_lock); 80 spin_lock(&cadet_io_lock);
94 outb(7,io); /* Select tuner control */ 81 outb(7,io); /* Select tuner control */
95 if( (inb(io+1) & 0x40) == 0) 82 if( (inb(io+1) & 0x40) == 0)
96 ret = 1; 83 ret = V4L2_TUNER_SUB_STEREO;
97 spin_unlock(&cadet_io_lock); 84 spin_unlock(&cadet_io_lock);
98 return ret; 85 return ret;
99} 86}
100 87
101static unsigned cadet_gettune(void) 88static unsigned
89cadet_gettune(void)
102{ 90{
103 int curvol,i; 91 int curvol,i;
104 unsigned fifo=0; 92 unsigned fifo=0;
@@ -135,7 +123,8 @@ static unsigned cadet_gettune(void)
135 return fifo; 123 return fifo;
136} 124}
137 125
138static unsigned cadet_getfreq(void) 126static unsigned
127cadet_getfreq(void)
139{ 128{
140 int i; 129 int i;
141 unsigned freq=0,test,fifo=0; 130 unsigned freq=0,test,fifo=0;
@@ -167,7 +156,8 @@ static unsigned cadet_getfreq(void)
167 return freq; 156 return freq;
168} 157}
169 158
170static void cadet_settune(unsigned fifo) 159static void
160cadet_settune(unsigned fifo)
171{ 161{
172 int i; 162 int i;
173 unsigned test; 163 unsigned test;
@@ -195,7 +185,8 @@ static void cadet_settune(unsigned fifo)
195 spin_unlock(&cadet_io_lock); 185 spin_unlock(&cadet_io_lock);
196} 186}
197 187
198static void cadet_setfreq(unsigned freq) 188static void
189cadet_setfreq(unsigned freq)
199{ 190{
200 unsigned fifo; 191 unsigned fifo;
201 int i,j,test; 192 int i,j,test;
@@ -255,7 +246,8 @@ static void cadet_setfreq(unsigned freq)
255} 246}
256 247
257 248
258static int cadet_getvol(void) 249static int
250cadet_getvol(void)
259{ 251{
260 int ret = 0; 252 int ret = 0;
261 253
@@ -270,7 +262,8 @@ static int cadet_getvol(void)
270} 262}
271 263
272 264
273static void cadet_setvol(int vol) 265static void
266cadet_setvol(int vol)
274{ 267{
275 spin_lock(&cadet_io_lock); 268 spin_lock(&cadet_io_lock);
276 outb(7,io); /* Select tuner control */ 269 outb(7,io); /* Select tuner control */
@@ -281,7 +274,8 @@ static void cadet_setvol(int vol)
281 spin_unlock(&cadet_io_lock); 274 spin_unlock(&cadet_io_lock);
282} 275}
283 276
284static void cadet_handler(unsigned long data) 277static void
278cadet_handler(unsigned long data)
285{ 279{
286 /* 280 /*
287 * Service the RDS fifo 281 * Service the RDS fifo
@@ -322,8 +316,8 @@ static void cadet_handler(unsigned long data)
322 316
323 317
324 318
325static ssize_t cadet_read(struct file *file, char __user *data, 319static ssize_t
326 size_t count, loff_t *ppos) 320cadet_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
327{ 321{
328 int i=0; 322 int i=0;
329 unsigned char readbuf[RDS_BUFFER]; 323 unsigned char readbuf[RDS_BUFFER];
@@ -359,128 +353,156 @@ static int cadet_do_ioctl(struct inode *inode, struct file *file,
359{ 353{
360 switch(cmd) 354 switch(cmd)
361 { 355 {
362 case VIDIOCGCAP: 356 case VIDIOC_QUERYCAP:
363 { 357 {
364 struct video_capability *v = arg; 358 struct v4l2_capability *cap = arg;
365 memset(v,0,sizeof(*v)); 359 memset(cap,0,sizeof(*cap));
366 v->type=VID_TYPE_TUNER; 360 cap->capabilities =
367 v->channels=2; 361 V4L2_CAP_TUNER |
368 v->audios=1; 362 V4L2_CAP_READWRITE;
369 strcpy(v->name, "ADS Cadet"); 363 cap->version = CADET_VERSION;
364 strcpy(cap->driver, "ADS Cadet");
365 strcpy(cap->card, "ADS Cadet");
370 return 0; 366 return 0;
371 } 367 }
372 case VIDIOCGTUNER: 368 case VIDIOC_G_TUNER:
373 { 369 {
374 struct video_tuner *v = arg; 370 struct v4l2_tuner *t = arg;
375 if((v->tuner<0)||(v->tuner>1)) { 371 memset(t,0,sizeof(*t));
376 return -EINVAL; 372 t->type = V4L2_TUNER_RADIO;
377 } 373 switch (t->index)
378 switch(v->tuner) { 374 {
379 case 0: 375 case 0: strcpy(t->name, "FM");
380 strcpy(v->name,"FM"); 376 t->capability = V4L2_TUNER_CAP_STEREO;
381 v->rangelow=1400; /* 87.5 MHz */ 377 t->rangelow = 1400; /* 87.5 MHz */
382 v->rangehigh=1728; /* 108.0 MHz */ 378 t->rangehigh = 1728; /* 108.0 MHz */
383 v->flags=0; 379 t->rxsubchans=cadet_getstereo();
384 v->mode=0; 380 switch (t->rxsubchans){
385 v->mode|=VIDEO_MODE_AUTO; 381 case V4L2_TUNER_SUB_MONO:
386 v->signal=sigstrength; 382 t->audmode = V4L2_TUNER_MODE_MONO;
387 if(cadet_getstereo()==1) { 383 break;
388 v->flags|=VIDEO_TUNER_STEREO_ON; 384 case V4L2_TUNER_SUB_STEREO:
389 } 385 t->audmode = V4L2_TUNER_MODE_STEREO;
390 v->flags|=cadet_getrds(); 386 break;
391 break; 387 default: ;
392 case 1: 388 }
393 strcpy(v->name,"AM"); 389 break;
394 v->rangelow=8320; /* 520 kHz */ 390 case 1: strcpy(t->name, "AM");
395 v->rangehigh=26400; /* 1650 kHz */ 391 t->capability = V4L2_TUNER_CAP_LOW;
396 v->flags=0; 392 t->rangelow = 8320; /* 520 kHz */
397 v->flags|=VIDEO_TUNER_LOW; 393 t->rangehigh = 26400; /* 1650 kHz */
398 v->mode=0; 394 t->rxsubchans = V4L2_TUNER_SUB_MONO;
399 v->mode|=VIDEO_MODE_AUTO; 395 t->audmode = V4L2_TUNER_MODE_MONO;
400 v->signal=sigstrength; 396 break;
401 break; 397 default:
398 return -EINVAL;
402 } 399 }
400
401 t->signal = sigstrength; /* We might need to modify scaling of this */
403 return 0; 402 return 0;
404 } 403 }
405 case VIDIOCSTUNER: 404 case VIDIOC_S_TUNER:
406 { 405 {
407 struct video_tuner *v = arg; 406 struct v4l2_tuner *t = arg;
408 if((v->tuner<0)||(v->tuner>1)) { 407 if((t->index != 0)&&(t->index != 1))
409 return -EINVAL; 408 return -EINVAL;
410 } 409
411 curtuner=v->tuner; 410 curtuner = t->index;
412 return 0; 411 return 0;
413 } 412 }
414 case VIDIOCGFREQ: 413 case VIDIOC_G_FREQUENCY:
415 { 414 {
416 unsigned long *freq = arg; 415 struct v4l2_frequency *f = arg;
417 *freq = cadet_getfreq(); 416 memset(f,0,sizeof(*f));
417 f->tuner = curtuner;
418 f->type = V4L2_TUNER_RADIO;
419 f->frequency = cadet_getfreq();
418 return 0; 420 return 0;
419 } 421 }
420 case VIDIOCSFREQ: 422 case VIDIOC_S_FREQUENCY:
421 { 423 {
422 unsigned long *freq = arg; 424 struct v4l2_frequency *f = arg;
423 if((curtuner==0)&&((*freq<1400)||(*freq>1728))) { 425 if (f->type != V4L2_TUNER_RADIO){
426 return -EINVAL;
427 }
428 if((curtuner==0)&&((f->frequency<1400)||(f->frequency>1728))) {
424 return -EINVAL; 429 return -EINVAL;
425 } 430 }
426 if((curtuner==1)&&((*freq<8320)||(*freq>26400))) { 431 if((curtuner==1)&&((f->frequency<8320)||(f->frequency>26400))) {
427 return -EINVAL; 432 return -EINVAL;
428 } 433 }
429 cadet_setfreq(*freq); 434 cadet_setfreq(f->frequency);
430 return 0; 435 return 0;
431 } 436 }
432 case VIDIOCGAUDIO: 437 case VIDIOC_G_CTRL:
433 { 438 {
434 struct video_audio *v = arg; 439 struct v4l2_control *c = arg;
435 memset(v,0, sizeof(*v)); 440 switch (c->id){
436 v->flags=VIDEO_AUDIO_MUTABLE|VIDEO_AUDIO_VOLUME; 441 case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */
437 if(cadet_getstereo()==0) { 442 c->value = (cadet_getvol() == 0);
438 v->mode=VIDEO_SOUND_MONO; 443 break;
439 } else { 444 case V4L2_CID_AUDIO_VOLUME:
440 v->mode=VIDEO_SOUND_STEREO; 445 c->value = cadet_getvol();
446 break;
447 default:
448 return -EINVAL;
441 } 449 }
442 v->volume=cadet_getvol();
443 v->step=0xffff;
444 strcpy(v->name, "Radio");
445 return 0; 450 return 0;
446 } 451 }
447 case VIDIOCSAUDIO: 452 case VIDIOC_S_CTRL:
448 { 453 {
449 struct video_audio *v = arg; 454 struct v4l2_control *c = arg;
450 if(v->audio) 455 switch (c->id){
451 return -EINVAL; 456 case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */
452 cadet_setvol(v->volume); 457 if (c->value) cadet_setvol(0);
453 if(v->flags&VIDEO_AUDIO_MUTE) 458 else cadet_setvol(0xffff);
454 cadet_setvol(0); 459 break;
455 else 460 case V4L2_CID_AUDIO_VOLUME:
456 cadet_setvol(0xffff); 461 cadet_setvol(c->value);
462 break;
463 default:
464 return -EINVAL;
465 }
457 return 0; 466 return 0;
458 } 467 }
468
459 default: 469 default:
460 return -ENOIOCTLCMD; 470 return -ENOIOCTLCMD;
461 } 471 }
462} 472}
463 473
464static int cadet_ioctl(struct inode *inode, struct file *file, 474static int
475cadet_ioctl(struct inode *inode, struct file *file,
465 unsigned int cmd, unsigned long arg) 476 unsigned int cmd, unsigned long arg)
466{ 477{
467 return video_usercopy(inode, file, cmd, arg, cadet_do_ioctl); 478 return video_usercopy(inode, file, cmd, arg, cadet_do_ioctl);
468} 479}
469 480
470static int cadet_open(struct inode *inode, struct file *file) 481static int
482cadet_open(struct inode *inode, struct file *file)
471{ 483{
472 if(users)
473 return -EBUSY;
474 users++; 484 users++;
475 init_waitqueue_head(&read_queue); 485 if (1 == users) init_waitqueue_head(&read_queue);
476 return 0; 486 return 0;
477} 487}
478 488
479static int cadet_release(struct inode *inode, struct file *file) 489static int
490cadet_release(struct inode *inode, struct file *file)
480{ 491{
481 del_timer_sync(&readtimer);
482 rdsstat=0;
483 users--; 492 users--;
493 if (0 == users){
494 del_timer_sync(&readtimer);
495 rdsstat=0;
496 }
497 return 0;
498}
499
500static unsigned int
501cadet_poll(struct file *file, struct poll_table_struct *wait)
502{
503 poll_wait(file,&read_queue,wait);
504 if(rdsin != rdsout)
505 return POLLIN | POLLRDNORM;
484 return 0; 506 return 0;
485} 507}
486 508
@@ -491,6 +513,7 @@ static struct file_operations cadet_fops = {
491 .release = cadet_release, 513 .release = cadet_release,
492 .read = cadet_read, 514 .read = cadet_read,
493 .ioctl = cadet_ioctl, 515 .ioctl = cadet_ioctl,
516 .poll = cadet_poll,
494 .compat_ioctl = v4l_compat_ioctl32, 517 .compat_ioctl = v4l_compat_ioctl32,
495 .llseek = no_llseek, 518 .llseek = no_llseek,
496}; 519};
@@ -500,7 +523,6 @@ static struct video_device cadet_radio=
500 .owner = THIS_MODULE, 523 .owner = THIS_MODULE,
501 .name = "Cadet radio", 524 .name = "Cadet radio",
502 .type = VID_TYPE_TUNER, 525 .type = VID_TYPE_TUNER,
503 .hardware = VID_HARDWARE_CADET,
504 .fops = &cadet_fops, 526 .fops = &cadet_fops,
505}; 527};
506 528
diff --git a/drivers/media/radio/radio-gemtek-pci.c b/drivers/media/radio/radio-gemtek-pci.c
index 4c82956390c1..cfab57d6bc4a 100644
--- a/drivers/media/radio/radio-gemtek-pci.c
+++ b/drivers/media/radio/radio-gemtek-pci.c
@@ -34,6 +34,8 @@
34 * 34 *
35 * TODO: multiple device support and portability were not tested 35 * TODO: multiple device support and portability were not tested
36 * 36 *
37 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
38 *
37 *************************************************************************** 39 ***************************************************************************
38 */ 40 */
39 41
@@ -42,10 +44,32 @@
42#include <linux/module.h> 44#include <linux/module.h>
43#include <linux/init.h> 45#include <linux/init.h>
44#include <linux/pci.h> 46#include <linux/pci.h>
45#include <linux/videodev.h> 47#include <linux/videodev2.h>
46#include <media/v4l2-common.h> 48#include <media/v4l2-common.h>
47#include <linux/errno.h> 49#include <linux/errno.h>
48 50
51#include <linux/version.h> /* for KERNEL_VERSION MACRO */
52#define RADIO_VERSION KERNEL_VERSION(0,0,2)
53
54static struct v4l2_queryctrl radio_qctrl[] = {
55 {
56 .id = V4L2_CID_AUDIO_MUTE,
57 .name = "Mute",
58 .minimum = 0,
59 .maximum = 1,
60 .default_value = 1,
61 .type = V4L2_CTRL_TYPE_BOOLEAN,
62 },{
63 .id = V4L2_CID_AUDIO_VOLUME,
64 .name = "Volume",
65 .minimum = 0,
66 .maximum = 65535,
67 .step = 65535,
68 .default_value = 0xff,
69 .type = V4L2_CTRL_TYPE_INTEGER,
70 }
71};
72
49#include <asm/io.h> 73#include <asm/io.h>
50#include <asm/uaccess.h> 74#include <asm/uaccess.h>
51 75
@@ -183,91 +207,117 @@ static int gemtek_pci_do_ioctl(struct inode *inode, struct file *file,
183 struct gemtek_pci_card *card = dev->priv; 207 struct gemtek_pci_card *card = dev->priv;
184 208
185 switch ( cmd ) { 209 switch ( cmd ) {
186 case VIDIOCGCAP: 210 case VIDIOC_QUERYCAP:
187 { 211 {
188 struct video_capability *c = arg; 212 struct v4l2_capability *v = arg;
213 memset(v,0,sizeof(*v));
214 strlcpy(v->driver, "radio-gemtek-pci", sizeof (v->driver));
215 strlcpy(v->card, "GemTek PCI Radio", sizeof (v->card));
216 sprintf(v->bus_info,"ISA");
217 v->version = RADIO_VERSION;
218 v->capabilities = V4L2_CAP_TUNER;
189 219
190 memset(c,0,sizeof(*c));
191 c->type = VID_TYPE_TUNER;
192 c->channels = 1;
193 c->audios = 1;
194 strcpy( c->name, "Gemtek PCI Radio" );
195 return 0; 220 return 0;
196 } 221 }
197 222 case VIDIOC_G_TUNER:
198 case VIDIOCGTUNER:
199 { 223 {
200 struct video_tuner *t = arg; 224 struct v4l2_tuner *v = arg;
201 225
202 if ( t->tuner ) 226 if (v->index > 0)
203 return -EINVAL; 227 return -EINVAL;
204 228
205 t->rangelow = GEMTEK_PCI_RANGE_LOW; 229 memset(v,0,sizeof(*v));
206 t->rangehigh = GEMTEK_PCI_RANGE_HIGH; 230 strcpy(v->name, "FM");
207 t->flags = VIDEO_TUNER_LOW; 231 v->type = V4L2_TUNER_RADIO;
208 t->mode = VIDEO_MODE_AUTO; 232
209 t->signal = 0xFFFF * gemtek_pci_getsignal( card ); 233 v->rangelow = GEMTEK_PCI_RANGE_LOW;
210 strcpy( t->name, "FM" ); 234 v->rangehigh = GEMTEK_PCI_RANGE_HIGH;
235 v->rxsubchans =V4L2_TUNER_SUB_MONO;
236 v->capability=V4L2_TUNER_CAP_LOW;
237 v->audmode = V4L2_TUNER_MODE_MONO;
238 v->signal=0xFFFF*gemtek_pci_getsignal( card );
239
211 return 0; 240 return 0;
212 } 241 }
213 242 case VIDIOC_S_TUNER:
214 case VIDIOCSTUNER:
215 { 243 {
216 struct video_tuner *t = arg; 244 struct v4l2_tuner *v = arg;
217 if ( t->tuner ) 245
246 if (v->index > 0)
218 return -EINVAL; 247 return -EINVAL;
219 return 0;
220 }
221 248
222 case VIDIOCGFREQ:
223 {
224 unsigned long *freq = arg;
225 *freq = card->current_frequency;
226 return 0; 249 return 0;
227 } 250 }
228 case VIDIOCSFREQ: 251 case VIDIOC_S_FREQUENCY:
229 { 252 {
230 unsigned long *freq = arg; 253 struct v4l2_frequency *f = arg;
231 254
232 if ( (*freq < GEMTEK_PCI_RANGE_LOW) || 255 if ( (f->frequency < GEMTEK_PCI_RANGE_LOW) ||
233 (*freq > GEMTEK_PCI_RANGE_HIGH) ) 256 (f->frequency > GEMTEK_PCI_RANGE_HIGH) )
234 return -EINVAL; 257 return -EINVAL;
235 258
236 gemtek_pci_setfrequency( card, *freq );
237 card->current_frequency = *freq;
238 card->mute = FALSE;
239 259
260 gemtek_pci_setfrequency( card, f->frequency );
261 card->current_frequency = f->frequency;
262 card->mute = FALSE;
240 return 0; 263 return 0;
241 } 264 }
242 265 case VIDIOC_QUERYCTRL:
243 case VIDIOCGAUDIO:
244 { 266 {
245 struct video_audio *a = arg; 267 struct v4l2_queryctrl *qc = arg;
246 268 int i;
247 memset( a, 0, sizeof( *a ) ); 269
248 a->flags |= VIDEO_AUDIO_MUTABLE; 270 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
249 a->volume = 1; 271 if (qc->id && qc->id == radio_qctrl[i].id) {
250 a->step = 65535; 272 memcpy(qc, &(radio_qctrl[i]),
251 strcpy( a->name, "Radio" ); 273 sizeof(*qc));
252 return 0; 274 return (0);
275 }
276 }
277 return -EINVAL;
253 } 278 }
254 279 case VIDIOC_G_CTRL:
255 case VIDIOCSAUDIO:
256 { 280 {
257 struct video_audio *a = arg; 281 struct v4l2_control *ctrl= arg;
258 282
259 if ( a->audio ) 283 switch (ctrl->id) {
260 return -EINVAL; 284 case V4L2_CID_AUDIO_MUTE:
261 285 ctrl->value=card->mute;
262 if ( a->flags & VIDEO_AUDIO_MUTE ) 286 return (0);
263 gemtek_pci_mute( card ); 287 case V4L2_CID_AUDIO_VOLUME:
264 else 288 if (card->mute)
265 gemtek_pci_unmute( card ); 289 ctrl->value=0;
266 return 0; 290 else
291 ctrl->value=65535;
292 return (0);
293 }
294 return -EINVAL;
295 }
296 case VIDIOC_S_CTRL:
297 {
298 struct v4l2_control *ctrl= arg;
299
300 switch (ctrl->id) {
301 case V4L2_CID_AUDIO_MUTE:
302 if (ctrl->value) {
303 gemtek_pci_mute(card);
304 } else {
305 gemtek_pci_unmute(card);
306 }
307 return (0);
308 case V4L2_CID_AUDIO_VOLUME:
309 if (ctrl->value) {
310 gemtek_pci_unmute(card);
311 } else {
312 gemtek_pci_mute(card);
313 }
314 return (0);
315 }
316 return -EINVAL;
267 } 317 }
268
269 default: 318 default:
270 return -ENOIOCTLCMD; 319 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
320 gemtek_pci_do_ioctl);
271 } 321 }
272} 322}
273 323
@@ -309,7 +359,7 @@ static struct video_device vdev_template = {
309 .owner = THIS_MODULE, 359 .owner = THIS_MODULE,
310 .name = "Gemtek PCI Radio", 360 .name = "Gemtek PCI Radio",
311 .type = VID_TYPE_TUNER, 361 .type = VID_TYPE_TUNER,
312 .hardware = VID_HARDWARE_GEMTEK, 362 .hardware = 0,
313 .fops = &gemtek_pci_fops, 363 .fops = &gemtek_pci_fops,
314}; 364};
315 365
diff --git a/drivers/media/radio/radio-gemtek.c b/drivers/media/radio/radio-gemtek.c
index 162f37d8bf96..730fe16126cb 100644
--- a/drivers/media/radio/radio-gemtek.c
+++ b/drivers/media/radio/radio-gemtek.c
@@ -13,6 +13,7 @@
13 * 13 *
14 * TODO: Allow for more than one of these foolish entities :-) 14 * TODO: Allow for more than one of these foolish entities :-)
15 * 15 *
16 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
16 */ 17 */
17 18
18#include <linux/module.h> /* Modules */ 19#include <linux/module.h> /* Modules */
@@ -21,11 +22,32 @@
21#include <linux/delay.h> /* udelay */ 22#include <linux/delay.h> /* udelay */
22#include <asm/io.h> /* outb, outb_p */ 23#include <asm/io.h> /* outb, outb_p */
23#include <asm/uaccess.h> /* copy to/from user */ 24#include <asm/uaccess.h> /* copy to/from user */
24#include <linux/videodev.h> /* kernel radio structs */ 25#include <linux/videodev2.h> /* kernel radio structs */
25#include <media/v4l2-common.h> 26#include <media/v4l2-common.h>
26#include <linux/config.h> /* CONFIG_RADIO_GEMTEK_PORT */
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28 28
29#include <linux/version.h> /* for KERNEL_VERSION MACRO */
30#define RADIO_VERSION KERNEL_VERSION(0,0,2)
31
32static struct v4l2_queryctrl radio_qctrl[] = {
33 {
34 .id = V4L2_CID_AUDIO_MUTE,
35 .name = "Mute",
36 .minimum = 0,
37 .maximum = 1,
38 .default_value = 1,
39 .type = V4L2_CTRL_TYPE_BOOLEAN,
40 },{
41 .id = V4L2_CID_AUDIO_VOLUME,
42 .name = "Volume",
43 .minimum = 0,
44 .maximum = 65535,
45 .step = 65535,
46 .default_value = 0xff,
47 .type = V4L2_CTRL_TYPE_INTEGER,
48 }
49};
50
29#ifndef CONFIG_RADIO_GEMTEK_PORT 51#ifndef CONFIG_RADIO_GEMTEK_PORT
30#define CONFIG_RADIO_GEMTEK_PORT -1 52#define CONFIG_RADIO_GEMTEK_PORT -1
31#endif 53#endif
@@ -147,77 +169,122 @@ static int gemtek_do_ioctl(struct inode *inode, struct file *file,
147 169
148 switch(cmd) 170 switch(cmd)
149 { 171 {
150 case VIDIOCGCAP: 172 case VIDIOC_QUERYCAP:
151 { 173 {
152 struct video_capability *v = arg; 174 struct v4l2_capability *v = arg;
153 memset(v,0,sizeof(*v)); 175 memset(v,0,sizeof(*v));
154 v->type=VID_TYPE_TUNER; 176 strlcpy(v->driver, "radio-gemtek", sizeof (v->driver));
155 v->channels=1; 177 strlcpy(v->card, "GemTek", sizeof (v->card));
156 v->audios=1; 178 sprintf(v->bus_info,"ISA");
157 strcpy(v->name, "GemTek"); 179 v->version = RADIO_VERSION;
180 v->capabilities = V4L2_CAP_TUNER;
181
158 return 0; 182 return 0;
159 } 183 }
160 case VIDIOCGTUNER: 184 case VIDIOC_G_TUNER:
161 { 185 {
162 struct video_tuner *v = arg; 186 struct v4l2_tuner *v = arg;
163 if(v->tuner) /* Only 1 tuner */ 187
188 if (v->index > 0)
164 return -EINVAL; 189 return -EINVAL;
165 v->rangelow=87*16000; 190
166 v->rangehigh=108*16000; 191 memset(v,0,sizeof(*v));
167 v->flags=VIDEO_TUNER_LOW;
168 v->mode=VIDEO_MODE_AUTO;
169 v->signal=0xFFFF*gemtek_getsigstr(rt);
170 strcpy(v->name, "FM"); 192 strcpy(v->name, "FM");
193 v->type = V4L2_TUNER_RADIO;
194
195 v->rangelow=(87*16000);
196 v->rangehigh=(108*16000);
197 v->rxsubchans =V4L2_TUNER_SUB_MONO;
198 v->capability=V4L2_TUNER_CAP_LOW;
199 v->audmode = V4L2_TUNER_MODE_MONO;
200 v->signal=0xFFFF*gemtek_getsigstr(rt);
201
171 return 0; 202 return 0;
172 } 203 }
173 case VIDIOCSTUNER: 204 case VIDIOC_S_TUNER:
174 { 205 {
175 struct video_tuner *v = arg; 206 struct v4l2_tuner *v = arg;
176 if(v->tuner!=0) 207
208 if (v->index > 0)
177 return -EINVAL; 209 return -EINVAL;
178 /* Only 1 tuner so no setting needed ! */ 210
179 return 0;
180 }
181 case VIDIOCGFREQ:
182 {
183 unsigned long *freq = arg;
184 *freq = rt->curfreq;
185 return 0; 211 return 0;
186 } 212 }
187 case VIDIOCSFREQ: 213 case VIDIOC_S_FREQUENCY:
188 { 214 {
189 unsigned long *freq = arg; 215 struct v4l2_frequency *f = arg;
190 rt->curfreq = *freq; 216
217 rt->curfreq = f->frequency;
191 /* needs to be called twice in order for getsigstr to work */ 218 /* needs to be called twice in order for getsigstr to work */
192 gemtek_setfreq(rt, rt->curfreq); 219 gemtek_setfreq(rt, rt->curfreq);
193 gemtek_setfreq(rt, rt->curfreq); 220 gemtek_setfreq(rt, rt->curfreq);
194 return 0; 221 return 0;
195 } 222 }
196 case VIDIOCGAUDIO: 223 case VIDIOC_G_FREQUENCY:
197 {
198 struct video_audio *v = arg;
199 memset(v,0, sizeof(*v));
200 v->flags|=VIDEO_AUDIO_MUTABLE;
201 v->volume=1;
202 v->step=65535;
203 strcpy(v->name, "Radio");
204 return 0;
205 }
206 case VIDIOCSAUDIO:
207 { 224 {
208 struct video_audio *v = arg; 225 struct v4l2_frequency *f = arg;
209 if(v->audio)
210 return -EINVAL;
211 226
212 if(v->flags&VIDEO_AUDIO_MUTE) 227 f->type = V4L2_TUNER_RADIO;
213 gemtek_mute(rt); 228 f->frequency = rt->curfreq;
214 else
215 gemtek_unmute(rt);
216 229
217 return 0; 230 return 0;
218 } 231 }
232 case VIDIOC_QUERYCTRL:
233 {
234 struct v4l2_queryctrl *qc = arg;
235 int i;
236
237 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
238 if (qc->id && qc->id == radio_qctrl[i].id) {
239 memcpy(qc, &(radio_qctrl[i]),
240 sizeof(*qc));
241 return (0);
242 }
243 }
244 return -EINVAL;
245 }
246 case VIDIOC_G_CTRL:
247 {
248 struct v4l2_control *ctrl= arg;
249
250 switch (ctrl->id) {
251 case V4L2_CID_AUDIO_MUTE:
252 ctrl->value=rt->muted;
253 return (0);
254 case V4L2_CID_AUDIO_VOLUME:
255 if (rt->muted)
256 ctrl->value=0;
257 else
258 ctrl->value=65535;
259 return (0);
260 }
261 return -EINVAL;
262 }
263 case VIDIOC_S_CTRL:
264 {
265 struct v4l2_control *ctrl= arg;
266
267 switch (ctrl->id) {
268 case V4L2_CID_AUDIO_MUTE:
269 if (ctrl->value) {
270 gemtek_mute(rt);
271 } else {
272 gemtek_unmute(rt);
273 }
274 return (0);
275 case V4L2_CID_AUDIO_VOLUME:
276 if (ctrl->value) {
277 gemtek_unmute(rt);
278 } else {
279 gemtek_mute(rt);
280 }
281 return (0);
282 }
283 return -EINVAL;
284 }
219 default: 285 default:
220 return -ENOIOCTLCMD; 286 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
287 gemtek_do_ioctl);
221 } 288 }
222} 289}
223 290
@@ -243,7 +310,7 @@ static struct video_device gemtek_radio=
243 .owner = THIS_MODULE, 310 .owner = THIS_MODULE,
244 .name = "GemTek radio", 311 .name = "GemTek radio",
245 .type = VID_TYPE_TUNER, 312 .type = VID_TYPE_TUNER,
246 .hardware = VID_HARDWARE_GEMTEK, 313 .hardware = 0,
247 .fops = &gemtek_fops, 314 .fops = &gemtek_fops,
248}; 315};
249 316
diff --git a/drivers/media/radio/radio-maestro.c b/drivers/media/radio/radio-maestro.c
index fcfa6c9fe225..e8ce5f75cf12 100644
--- a/drivers/media/radio/radio-maestro.c
+++ b/drivers/media/radio/radio-maestro.c
@@ -14,6 +14,8 @@
14 * version 0.04 14 * version 0.04
15 * + code improvements 15 * + code improvements
16 * + VIDEO_TUNER_LOW is permanent 16 * + VIDEO_TUNER_LOW is permanent
17 *
18 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
17 */ 19 */
18 20
19#include <linux/module.h> 21#include <linux/module.h>
@@ -25,10 +27,23 @@
25#include <asm/uaccess.h> 27#include <asm/uaccess.h>
26#include <linux/mutex.h> 28#include <linux/mutex.h>
27#include <linux/pci.h> 29#include <linux/pci.h>
28#include <linux/videodev.h> 30#include <linux/videodev2.h>
29#include <media/v4l2-common.h> 31#include <media/v4l2-common.h>
30 32
31#define DRIVER_VERSION "0.05" 33#include <linux/version.h> /* for KERNEL_VERSION MACRO */
34#define RADIO_VERSION KERNEL_VERSION(0,0,6)
35#define DRIVER_VERSION "0.06"
36
37static struct v4l2_queryctrl radio_qctrl[] = {
38 {
39 .id = V4L2_CID_AUDIO_MUTE,
40 .name = "Mute",
41 .minimum = 0,
42 .maximum = 1,
43 .default_value = 1,
44 .type = V4L2_CTRL_TYPE_BOOLEAN,
45 }
46};
32 47
33#define GPIO_DATA 0x60 /* port offset from ESS_IO_BASE */ 48#define GPIO_DATA 0x60 /* port offset from ESS_IO_BASE */
34 49
@@ -96,7 +111,7 @@ static struct file_operations maestro_fops = {
96static struct video_device maestro_radio = { 111static struct video_device maestro_radio = {
97 .name = "Maestro radio", 112 .name = "Maestro radio",
98 .type = VID_TYPE_TUNER, 113 .type = VID_TYPE_TUNER,
99 .hardware = VID_HARDWARE_SF16MI, 114 .hardware = 0,
100 .fops = &maestro_fops, 115 .fops = &maestro_fops,
101}; 116};
102 117
@@ -130,7 +145,7 @@ static u32 radio_bits_get(struct radio_device *dev)
130 rdata = inw(io); 145 rdata = inw(io);
131 if(!l) 146 if(!l)
132 dev->stereo = rdata & STR_MOST ? 147 dev->stereo = rdata & STR_MOST ?
133 0 : VIDEO_TUNER_STEREO_ON; 148 0 : 1;
134 else 149 else
135 if(rdata & STR_DATA) 150 if(rdata & STR_DATA)
136 data++; 151 data++;
@@ -183,72 +198,120 @@ static inline int radio_function(struct inode *inode, struct file *file,
183 struct radio_device *card = video_get_drvdata(dev); 198 struct radio_device *card = video_get_drvdata(dev);
184 199
185 switch (cmd) { 200 switch (cmd) {
186 case VIDIOCGCAP: { 201 case VIDIOC_QUERYCAP:
187 struct video_capability *v = arg; 202 {
188 memset(v, 0, sizeof(*v)); 203 struct v4l2_capability *v = arg;
189 strcpy(v->name, "Maestro radio"); 204 memset(v,0,sizeof(*v));
190 v->type = VID_TYPE_TUNER; 205 strlcpy(v->driver, "radio-maestro", sizeof (v->driver));
191 v->channels = v->audios = 1; 206 strlcpy(v->card, "Maestro Radio", sizeof (v->card));
192 return 0; 207 sprintf(v->bus_info,"PCI");
193 } case VIDIOCGTUNER: { 208 v->version = RADIO_VERSION;
194 struct video_tuner *v = arg; 209 v->capabilities = V4L2_CAP_TUNER;
195 if (v->tuner) 210
196 return -EINVAL; 211 return 0;
197 (void)radio_bits_get(card); 212 }
198 v->flags = VIDEO_TUNER_LOW | card->stereo; 213 case VIDIOC_G_TUNER:
199 v->signal = card->tuned; 214 {
200 strcpy(v->name, "FM"); 215 struct v4l2_tuner *v = arg;
201 v->rangelow = FREQ_LO; 216
202 v->rangehigh = FREQ_HI; 217 if (v->index > 0)
203 v->mode = VIDEO_MODE_AUTO; 218 return -EINVAL;
204 return 0; 219
205 } case VIDIOCSTUNER: { 220 (void)radio_bits_get(card);
206 struct video_tuner *v = arg; 221
207 if (v->tuner != 0) 222 memset(v,0,sizeof(*v));
208 return -EINVAL; 223 strcpy(v->name, "FM");
209 return 0; 224 v->type = V4L2_TUNER_RADIO;
210 } case VIDIOCGFREQ: { 225
211 unsigned long *freq = arg; 226 v->rangelow = FREQ_LO;
212 *freq = BITS2FREQ(radio_bits_get(card)); 227 v->rangehigh = FREQ_HI;
213 return 0; 228 v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
214 } case VIDIOCSFREQ: { 229 v->capability=V4L2_TUNER_CAP_LOW;
215 unsigned long *freq = arg; 230 if(card->stereo)
216 if (*freq < FREQ_LO || *freq > FREQ_HI) 231 v->audmode = V4L2_TUNER_MODE_STEREO;
232 else
233 v->audmode = V4L2_TUNER_MODE_MONO;
234 v->signal=card->tuned;
235
236 return 0;
237 }
238 case VIDIOC_S_TUNER:
239 {
240 struct v4l2_tuner *v = arg;
241
242 if (v->index > 0)
243 return -EINVAL;
244
245 return 0;
246 }
247 case VIDIOC_S_FREQUENCY:
248 {
249 struct v4l2_frequency *f = arg;
250
251 if (f->frequency < FREQ_LO || f->frequency > FREQ_HI)
252 return -EINVAL;
253 radio_bits_set(card, FREQ2BITS(f->frequency));
254
255 return 0;
256 }
257 case VIDIOC_G_FREQUENCY:
258 {
259 struct v4l2_frequency *f = arg;
260
261 f->type = V4L2_TUNER_RADIO;
262 f->frequency = BITS2FREQ(radio_bits_get(card));
263
264 return 0;
265 }
266 case VIDIOC_QUERYCTRL:
267 {
268 struct v4l2_queryctrl *qc = arg;
269 int i;
270
271 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
272 if (qc->id && qc->id == radio_qctrl[i].id) {
273 memcpy(qc, &(radio_qctrl[i]),
274 sizeof(*qc));
275 return (0);
276 }
277 }
217 return -EINVAL; 278 return -EINVAL;
218 radio_bits_set(card, FREQ2BITS(*freq)); 279 }
219 return 0; 280 case VIDIOC_G_CTRL:
220 } case VIDIOCGAUDIO: { 281 {
221 struct video_audio *v = arg; 282 struct v4l2_control *ctrl= arg;
222 memset(v, 0, sizeof(*v)); 283
223 strcpy(v->name, "Radio"); 284 switch (ctrl->id) {
224 v->flags = VIDEO_AUDIO_MUTABLE | card->muted; 285 case V4L2_CID_AUDIO_MUTE:
225 v->mode = VIDEO_SOUND_STEREO; 286 ctrl->value=card->muted;
226 return 0; 287 return (0);
227 } case VIDIOCSAUDIO: { 288 }
228 struct video_audio *v = arg;
229 if (v->audio)
230 return -EINVAL; 289 return -EINVAL;
290 }
291 case VIDIOC_S_CTRL:
231 { 292 {
232 register u16 io = card->io; 293 struct v4l2_control *ctrl= arg;
233 register u16 omask = inw(io + IO_MASK); 294
234 outw(~STR_WREN, io + IO_MASK); 295 switch (ctrl->id) {
235 outw((card->muted = v->flags & VIDEO_AUDIO_MUTE) ? 296 case V4L2_CID_AUDIO_MUTE:
236 STR_WREN : 0, io); 297 {
237 udelay(4); 298 register u16 io = card->io;
238 outw(omask, io + IO_MASK); 299 register u16 omask = inw(io + IO_MASK);
239 msleep(125); 300 outw(~STR_WREN, io + IO_MASK);
240 return 0; 301 outw((card->muted = ctrl->value ) ?
302 STR_WREN : 0, io);
303 udelay(4);
304 outw(omask, io + IO_MASK);
305 msleep(125);
306
307 return (0);
308 }
309 }
310 return -EINVAL;
241 } 311 }
242 } case VIDIOCGUNIT: { 312 default:
243 struct video_unit *v = arg; 313 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
244 v->video = VIDEO_NO_UNIT; 314 radio_function);
245 v->vbi = VIDEO_NO_UNIT;
246 v->radio = dev->minor;
247 v->audio = 0;
248 v->teletext = VIDEO_NO_UNIT;
249 return 0;
250 } default:
251 return -ENOIOCTLCMD;
252 } 315 }
253} 316}
254 317
@@ -275,7 +338,7 @@ static u16 __devinit radio_power_on(struct radio_device *dev)
275 omask = inw(io + IO_MASK); 338 omask = inw(io + IO_MASK);
276 odir = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN); 339 odir = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN);
277 outw(odir & ~STR_WREN, io + IO_DIR); 340 outw(odir & ~STR_WREN, io + IO_DIR);
278 dev->muted = inw(io) & STR_WREN ? 0 : VIDEO_AUDIO_MUTE; 341 dev->muted = inw(io) & STR_WREN ? 0 : 1;
279 outw(odir, io + IO_DIR); 342 outw(odir, io + IO_DIR);
280 outw(~(STR_WREN | STR_CLK), io + IO_MASK); 343 outw(~(STR_WREN | STR_CLK), io + IO_MASK);
281 outw(dev->muted ? 0 : STR_WREN, io); 344 outw(dev->muted ? 0 : STR_WREN, io);
diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
index f93d7afe7304..c2eeae7a10d0 100644
--- a/drivers/media/radio/radio-maxiradio.c
+++ b/drivers/media/radio/radio-maxiradio.c
@@ -20,13 +20,14 @@
20 * 0.75b 20 * 0.75b
21 * - better pci interface thanks to Francois Romieu <romieu@cogenit.fr> 21 * - better pci interface thanks to Francois Romieu <romieu@cogenit.fr>
22 * 22 *
23 * 0.75 23 * 0.75 Sun Feb 4 22:51:27 EET 2001
24 * - tiding up 24 * - tiding up
25 * - removed support for multiple devices as it didn't work anyway 25 * - removed support for multiple devices as it didn't work anyway
26 * 26 *
27 * BUGS: 27 * BUGS:
28 * - card unmutes if you change frequency 28 * - card unmutes if you change frequency
29 * 29 *
30 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
30 */ 31 */
31 32
32 33
@@ -40,11 +41,24 @@
40#include <linux/mutex.h> 41#include <linux/mutex.h>
41 42
42#include <linux/pci.h> 43#include <linux/pci.h>
43#include <linux/videodev.h> 44#include <linux/videodev2.h>
44#include <media/v4l2-common.h> 45#include <media/v4l2-common.h>
45 46
46/* version 0.75 Sun Feb 4 22:51:27 EET 2001 */ 47#define DRIVER_VERSION "0.76"
47#define DRIVER_VERSION "0.75" 48
49#include <linux/version.h> /* for KERNEL_VERSION MACRO */
50#define RADIO_VERSION KERNEL_VERSION(0,7,6)
51
52static struct v4l2_queryctrl radio_qctrl[] = {
53 {
54 .id = V4L2_CID_AUDIO_MUTE,
55 .name = "Mute",
56 .minimum = 0,
57 .maximum = 1,
58 .default_value = 1,
59 .type = V4L2_CTRL_TYPE_BOOLEAN,
60 }
61};
48 62
49#ifndef PCI_VENDOR_ID_GUILLEMOT 63#ifndef PCI_VENDOR_ID_GUILLEMOT
50#define PCI_VENDOR_ID_GUILLEMOT 0x5046 64#define PCI_VENDOR_ID_GUILLEMOT 0x5046
@@ -90,7 +104,6 @@ static struct video_device maxiradio_radio =
90 .owner = THIS_MODULE, 104 .owner = THIS_MODULE,
91 .name = "Maxi Radio FM2000 radio", 105 .name = "Maxi Radio FM2000 radio",
92 .type = VID_TYPE_TUNER, 106 .type = VID_TYPE_TUNER,
93 .hardware = VID_HARDWARE_SF16MI,
94 .fops = &maxiradio_fops, 107 .fops = &maxiradio_fops,
95}; 108};
96 109
@@ -176,89 +189,116 @@ static inline int radio_function(struct inode *inode, struct file *file,
176 struct radio_device *card=dev->priv; 189 struct radio_device *card=dev->priv;
177 190
178 switch(cmd) { 191 switch(cmd) {
179 case VIDIOCGCAP: { 192 case VIDIOC_QUERYCAP:
180 struct video_capability *v = arg; 193 {
181 194 struct v4l2_capability *v = arg;
182 memset(v,0,sizeof(*v)); 195 memset(v,0,sizeof(*v));
183 strcpy(v->name, "Maxi Radio FM2000 radio"); 196 strlcpy(v->driver, "radio-maxiradio", sizeof (v->driver));
184 v->type=VID_TYPE_TUNER; 197 strlcpy(v->card, "Maxi Radio FM2000 radio", sizeof (v->card));
185 v->channels=v->audios=1; 198 sprintf(v->bus_info,"ISA");
199 v->version = RADIO_VERSION;
200 v->capabilities = V4L2_CAP_TUNER;
201
186 return 0; 202 return 0;
187 } 203 }
188 case VIDIOCGTUNER: { 204 case VIDIOC_G_TUNER:
189 struct video_tuner *v = arg; 205 {
206 struct v4l2_tuner *v = arg;
190 207
191 if(v->tuner) 208 if (v->index > 0)
192 return -EINVAL; 209 return -EINVAL;
193 210
194 card->stereo = 0xffff * get_stereo(card->io); 211 memset(v,0,sizeof(*v));
195 card->tuned = 0xffff * get_tune(card->io);
196
197 v->flags = VIDEO_TUNER_LOW | card->stereo;
198 v->signal = card->tuned;
199
200 strcpy(v->name, "FM"); 212 strcpy(v->name, "FM");
201 213 v->type = V4L2_TUNER_RADIO;
202 v->rangelow = FREQ_LO; 214
203 v->rangehigh = FREQ_HI; 215 v->rangelow=FREQ_LO;
204 v->mode = VIDEO_MODE_AUTO; 216 v->rangehigh=FREQ_HI;
217 v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
218 v->capability=V4L2_TUNER_CAP_LOW;
219 if(get_stereo(card->io))
220 v->audmode = V4L2_TUNER_MODE_STEREO;
221 else
222 v->audmode = V4L2_TUNER_MODE_MONO;
223 v->signal=0xffff*get_tune(card->io);
205 224
206 return 0; 225 return 0;
207 } 226 }
208 case VIDIOCSTUNER: { 227 case VIDIOC_S_TUNER:
209 struct video_tuner *v = arg; 228 {
210 if(v->tuner!=0) 229 struct v4l2_tuner *v = arg;
230
231 if (v->index > 0)
211 return -EINVAL; 232 return -EINVAL;
212 return 0;
213 }
214 case VIDIOCGFREQ: {
215 unsigned long *freq = arg;
216 233
217 *freq = card->freq;
218 return 0; 234 return 0;
219 } 235 }
220 case VIDIOCSFREQ: { 236 case VIDIOC_S_FREQUENCY:
221 unsigned long *freq = arg; 237 {
238 struct v4l2_frequency *f = arg;
222 239
223 if (*freq < FREQ_LO || *freq > FREQ_HI) 240 if (f->frequency < FREQ_LO || f->frequency > FREQ_HI)
224 return -EINVAL; 241 return -EINVAL;
225 card->freq = *freq; 242
243 card->freq = f->frequency;
226 set_freq(card->io, FREQ2BITS(card->freq)); 244 set_freq(card->io, FREQ2BITS(card->freq));
227 msleep(125); 245 msleep(125);
228 return 0; 246 return 0;
229 } 247 }
230 case VIDIOCGAUDIO: { 248 case VIDIOC_G_FREQUENCY:
231 struct video_audio *v = arg; 249 {
232 memset(v,0,sizeof(*v)); 250 struct v4l2_frequency *f = arg;
233 strcpy(v->name, "Radio");
234 v->flags=VIDEO_AUDIO_MUTABLE | card->muted;
235 v->mode=VIDEO_SOUND_STEREO;
236 return 0;
237 }
238 251
239 case VIDIOCSAUDIO: { 252 f->type = V4L2_TUNER_RADIO;
240 struct video_audio *v = arg; 253 f->frequency = card->freq;
241 254
242 if(v->audio)
243 return -EINVAL;
244 card->muted = v->flags & VIDEO_AUDIO_MUTE;
245 if(card->muted)
246 turn_power(card->io, 0);
247 else
248 set_freq(card->io, FREQ2BITS(card->freq));
249 return 0; 255 return 0;
250 } 256 }
251 case VIDIOCGUNIT: { 257 case VIDIOC_QUERYCTRL:
252 struct video_unit *v = arg; 258 {
253 259 struct v4l2_queryctrl *qc = arg;
254 v->video=VIDEO_NO_UNIT; 260 int i;
255 v->vbi=VIDEO_NO_UNIT; 261
256 v->radio=dev->minor; 262 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
257 v->audio=0; 263 if (qc->id && qc->id == radio_qctrl[i].id) {
258 v->teletext=VIDEO_NO_UNIT; 264 memcpy(qc, &(radio_qctrl[i]),
259 return 0; 265 sizeof(*qc));
266 return (0);
267 }
268 }
269 return -EINVAL;
270 }
271 case VIDIOC_G_CTRL:
272 {
273 struct v4l2_control *ctrl= arg;
274
275 switch (ctrl->id) {
276 case V4L2_CID_AUDIO_MUTE:
277 ctrl->value=card->muted;
278 return (0);
279 }
280 return -EINVAL;
260 } 281 }
261 default: return -ENOIOCTLCMD; 282 case VIDIOC_S_CTRL:
283 {
284 struct v4l2_control *ctrl= arg;
285
286 switch (ctrl->id) {
287 case V4L2_CID_AUDIO_MUTE:
288 card->muted = ctrl->value;
289 if(card->muted)
290 turn_power(card->io, 0);
291 else
292 set_freq(card->io, FREQ2BITS(card->freq));
293 return 0;
294 }
295 return -EINVAL;
296 }
297
298 default:
299 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
300 radio_function);
301
262 } 302 }
263} 303}
264 304
diff --git a/drivers/media/radio/radio-rtrack2.c b/drivers/media/radio/radio-rtrack2.c
index 5b68ac4c7322..b9e98483e58d 100644
--- a/drivers/media/radio/radio-rtrack2.c
+++ b/drivers/media/radio/radio-rtrack2.c
@@ -6,6 +6,7 @@
6 * 6 *
7 * TODO: Allow for more than one of these foolish entities :-) 7 * TODO: Allow for more than one of these foolish entities :-)
8 * 8 *
9 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
9 */ 10 */
10 11
11#include <linux/module.h> /* Modules */ 12#include <linux/module.h> /* Modules */
@@ -14,11 +15,32 @@
14#include <linux/delay.h> /* udelay */ 15#include <linux/delay.h> /* udelay */
15#include <asm/io.h> /* outb, outb_p */ 16#include <asm/io.h> /* outb, outb_p */
16#include <asm/uaccess.h> /* copy to/from user */ 17#include <asm/uaccess.h> /* copy to/from user */
17#include <linux/videodev.h> /* kernel radio structs */ 18#include <linux/videodev2.h> /* kernel radio structs */
18#include <media/v4l2-common.h> 19#include <media/v4l2-common.h>
19#include <linux/config.h> /* CONFIG_RADIO_RTRACK2_PORT */
20#include <linux/spinlock.h> 20#include <linux/spinlock.h>
21 21
22#include <linux/version.h> /* for KERNEL_VERSION MACRO */
23#define RADIO_VERSION KERNEL_VERSION(0,0,2)
24
25static struct v4l2_queryctrl radio_qctrl[] = {
26 {
27 .id = V4L2_CID_AUDIO_MUTE,
28 .name = "Mute",
29 .minimum = 0,
30 .maximum = 1,
31 .default_value = 1,
32 .type = V4L2_CTRL_TYPE_BOOLEAN,
33 },{
34 .id = V4L2_CID_AUDIO_VOLUME,
35 .name = "Volume",
36 .minimum = 0,
37 .maximum = 65535,
38 .step = 65535,
39 .default_value = 0xff,
40 .type = V4L2_CTRL_TYPE_INTEGER,
41 }
42};
43
22#ifndef CONFIG_RADIO_RTRACK2_PORT 44#ifndef CONFIG_RADIO_RTRACK2_PORT
23#define CONFIG_RADIO_RTRACK2_PORT -1 45#define CONFIG_RADIO_RTRACK2_PORT -1
24#endif 46#endif
@@ -115,75 +137,120 @@ static int rt_do_ioctl(struct inode *inode, struct file *file,
115 137
116 switch(cmd) 138 switch(cmd)
117 { 139 {
118 case VIDIOCGCAP: 140 case VIDIOC_QUERYCAP:
119 { 141 {
120 struct video_capability *v = arg; 142 struct v4l2_capability *v = arg;
121 memset(v,0,sizeof(*v)); 143 memset(v,0,sizeof(*v));
122 v->type=VID_TYPE_TUNER; 144 strlcpy(v->driver, "radio-rtrack2", sizeof (v->driver));
123 v->channels=1; 145 strlcpy(v->card, "RadioTrack II", sizeof (v->card));
124 v->audios=1; 146 sprintf(v->bus_info,"ISA");
125 strcpy(v->name, "RadioTrack II"); 147 v->version = RADIO_VERSION;
148 v->capabilities = V4L2_CAP_TUNER;
149
126 return 0; 150 return 0;
127 } 151 }
128 case VIDIOCGTUNER: 152 case VIDIOC_G_TUNER:
129 { 153 {
130 struct video_tuner *v = arg; 154 struct v4l2_tuner *v = arg;
131 if(v->tuner) /* Only 1 tuner */ 155
156 if (v->index > 0)
132 return -EINVAL; 157 return -EINVAL;
133 v->rangelow=88*16000; 158
134 v->rangehigh=108*16000; 159 memset(v,0,sizeof(*v));
135 v->flags=VIDEO_TUNER_LOW;
136 v->mode=VIDEO_MODE_AUTO;
137 v->signal=0xFFFF*rt_getsigstr(rt);
138 strcpy(v->name, "FM"); 160 strcpy(v->name, "FM");
161 v->type = V4L2_TUNER_RADIO;
162
163 v->rangelow=(88*16000);
164 v->rangehigh=(108*16000);
165 v->rxsubchans =V4L2_TUNER_SUB_MONO;
166 v->capability=V4L2_TUNER_CAP_LOW;
167 v->audmode = V4L2_TUNER_MODE_MONO;
168 v->signal=0xFFFF*rt_getsigstr(rt);
169
139 return 0; 170 return 0;
140 } 171 }
141 case VIDIOCSTUNER: 172 case VIDIOC_S_TUNER:
142 { 173 {
143 struct video_tuner *v = arg; 174 struct v4l2_tuner *v = arg;
144 if(v->tuner!=0) 175
176 if (v->index > 0)
145 return -EINVAL; 177 return -EINVAL;
146 /* Only 1 tuner so no setting needed ! */ 178
147 return 0; 179 return 0;
148 } 180 }
149 case VIDIOCGFREQ: 181 case VIDIOC_S_FREQUENCY:
150 { 182 {
151 unsigned long *freq = arg; 183 struct v4l2_frequency *f = arg;
152 *freq = rt->curfreq; 184
185 rt->curfreq = f->frequency;
186 rt_setfreq(rt, rt->curfreq);
153 return 0; 187 return 0;
154 } 188 }
155 case VIDIOCSFREQ: 189 case VIDIOC_G_FREQUENCY:
156 { 190 {
157 unsigned long *freq = arg; 191 struct v4l2_frequency *f = arg;
158 rt->curfreq = *freq; 192
159 rt_setfreq(rt, rt->curfreq); 193 f->type = V4L2_TUNER_RADIO;
194 f->frequency = rt->curfreq;
195
160 return 0; 196 return 0;
161 } 197 }
162 case VIDIOCGAUDIO: 198 case VIDIOC_QUERYCTRL:
163 { 199 {
164 struct video_audio *v = arg; 200 struct v4l2_queryctrl *qc = arg;
165 memset(v,0, sizeof(*v)); 201 int i;
166 v->flags|=VIDEO_AUDIO_MUTABLE; 202
167 v->volume=1; 203 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
168 v->step=65535; 204 if (qc->id && qc->id == radio_qctrl[i].id) {
169 strcpy(v->name, "Radio"); 205 memcpy(qc, &(radio_qctrl[i]),
170 return 0; 206 sizeof(*qc));
207 return (0);
208 }
209 }
210 return -EINVAL;
171 } 211 }
172 case VIDIOCSAUDIO: 212 case VIDIOC_G_CTRL:
173 { 213 {
174 struct video_audio *v = arg; 214 struct v4l2_control *ctrl= arg;
175 if(v->audio) 215
176 return -EINVAL; 216 switch (ctrl->id) {
177 217 case V4L2_CID_AUDIO_MUTE:
178 if(v->flags&VIDEO_AUDIO_MUTE) 218 ctrl->value=rt->muted;
179 rt_mute(rt); 219 return (0);
180 else 220 case V4L2_CID_AUDIO_VOLUME:
181 rt_unmute(rt); 221 if (rt->muted)
182 222 ctrl->value=0;
183 return 0; 223 else
224 ctrl->value=65535;
225 return (0);
226 }
227 return -EINVAL;
228 }
229 case VIDIOC_S_CTRL:
230 {
231 struct v4l2_control *ctrl= arg;
232
233 switch (ctrl->id) {
234 case V4L2_CID_AUDIO_MUTE:
235 if (ctrl->value) {
236 rt_mute(rt);
237 } else {
238 rt_unmute(rt);
239 }
240 return (0);
241 case V4L2_CID_AUDIO_VOLUME:
242 if (ctrl->value) {
243 rt_unmute(rt);
244 } else {
245 rt_mute(rt);
246 }
247 return (0);
248 }
249 return -EINVAL;
184 } 250 }
185 default: 251 default:
186 return -ENOIOCTLCMD; 252 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
253 rt_do_ioctl);
187 } 254 }
188} 255}
189 256
@@ -209,7 +276,7 @@ static struct video_device rtrack2_radio=
209 .owner = THIS_MODULE, 276 .owner = THIS_MODULE,
210 .name = "RadioTrack II radio", 277 .name = "RadioTrack II radio",
211 .type = VID_TYPE_TUNER, 278 .type = VID_TYPE_TUNER,
212 .hardware = VID_HARDWARE_RTRACK2, 279 .hardware = 0,
213 .fops = &rtrack2_fops, 280 .fops = &rtrack2_fops,
214}; 281};
215 282
diff --git a/drivers/media/radio/radio-sf16fmi.c b/drivers/media/radio/radio-sf16fmi.c
index efee6e339d15..ecc854b4ba38 100644
--- a/drivers/media/radio/radio-sf16fmi.c
+++ b/drivers/media/radio/radio-sf16fmi.c
@@ -13,20 +13,35 @@
13 * No volume control - only mute/unmute - you have to use line volume 13 * No volume control - only mute/unmute - you have to use line volume
14 * control on SB-part of SF16FMI 14 * control on SB-part of SF16FMI
15 * 15 *
16 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
16 */ 17 */
17 18
19#include <linux/version.h>
18#include <linux/kernel.h> /* __setup */ 20#include <linux/kernel.h> /* __setup */
19#include <linux/module.h> /* Modules */ 21#include <linux/module.h> /* Modules */
20#include <linux/init.h> /* Initdata */ 22#include <linux/init.h> /* Initdata */
21#include <linux/ioport.h> /* request_region */ 23#include <linux/ioport.h> /* request_region */
22#include <linux/delay.h> /* udelay */ 24#include <linux/delay.h> /* udelay */
23#include <linux/videodev.h> /* kernel radio structs */ 25#include <linux/videodev2.h> /* kernel radio structs */
24#include <media/v4l2-common.h> 26#include <media/v4l2-common.h>
25#include <linux/isapnp.h> 27#include <linux/isapnp.h>
26#include <asm/io.h> /* outb, outb_p */ 28#include <asm/io.h> /* outb, outb_p */
27#include <asm/uaccess.h> /* copy to/from user */ 29#include <asm/uaccess.h> /* copy to/from user */
28#include <linux/mutex.h> 30#include <linux/mutex.h>
29 31
32#define RADIO_VERSION KERNEL_VERSION(0,0,2)
33
34static struct v4l2_queryctrl radio_qctrl[] = {
35 {
36 .id = V4L2_CID_AUDIO_MUTE,
37 .name = "Mute",
38 .minimum = 0,
39 .maximum = 1,
40 .default_value = 1,
41 .type = V4L2_CTRL_TYPE_BOOLEAN,
42 }
43};
44
30struct fmi_device 45struct fmi_device
31{ 46{
32 int port; 47 int port;
@@ -123,93 +138,122 @@ static int fmi_do_ioctl(struct inode *inode, struct file *file,
123 138
124 switch(cmd) 139 switch(cmd)
125 { 140 {
126 case VIDIOCGCAP: 141 case VIDIOC_QUERYCAP:
127 { 142 {
128 struct video_capability *v = arg; 143 struct v4l2_capability *v = arg;
129 memset(v,0,sizeof(*v)); 144 memset(v,0,sizeof(*v));
130 strcpy(v->name, "SF16-FMx radio"); 145 strlcpy(v->driver, "radio-sf16fmi", sizeof (v->driver));
131 v->type=VID_TYPE_TUNER; 146 strlcpy(v->card, "SF16-FMx radio", sizeof (v->card));
132 v->channels=1; 147 sprintf(v->bus_info,"ISA");
133 v->audios=1; 148 v->version = RADIO_VERSION;
149 v->capabilities = V4L2_CAP_TUNER;
150
134 return 0; 151 return 0;
135 } 152 }
136 case VIDIOCGTUNER: 153 case VIDIOC_G_TUNER:
137 { 154 {
138 struct video_tuner *v = arg; 155 struct v4l2_tuner *v = arg;
139 int mult; 156 int mult;
140 157
141 if(v->tuner) /* Only 1 tuner */ 158 if (v->index > 0)
142 return -EINVAL; 159 return -EINVAL;
160
161 memset(v,0,sizeof(*v));
143 strcpy(v->name, "FM"); 162 strcpy(v->name, "FM");
144 mult = (fmi->flags & VIDEO_TUNER_LOW) ? 1 : 1000; 163 v->type = V4L2_TUNER_RADIO;
164
165 mult = (fmi->flags & V4L2_TUNER_CAP_LOW) ? 1 : 1000;
145 v->rangelow = RSF16_MINFREQ/mult; 166 v->rangelow = RSF16_MINFREQ/mult;
146 v->rangehigh = RSF16_MAXFREQ/mult; 167 v->rangehigh = RSF16_MAXFREQ/mult;
147 v->flags=fmi->flags; 168 v->rxsubchans =V4L2_TUNER_SUB_MONO | V4L2_TUNER_MODE_STEREO;
148 v->mode=VIDEO_MODE_AUTO; 169 v->capability=fmi->flags&V4L2_TUNER_CAP_LOW;
170 v->audmode = V4L2_TUNER_MODE_STEREO;
149 v->signal = fmi_getsigstr(fmi); 171 v->signal = fmi_getsigstr(fmi);
172
150 return 0; 173 return 0;
151 } 174 }
152 case VIDIOCSTUNER: 175 case VIDIOC_S_TUNER:
153 { 176 {
154 struct video_tuner *v = arg; 177 struct v4l2_tuner *v = arg;
155 if(v->tuner!=0) 178
179 if (v->index > 0)
156 return -EINVAL; 180 return -EINVAL;
157 fmi->flags = v->flags & VIDEO_TUNER_LOW; 181
158 /* Only 1 tuner so no setting needed ! */
159 return 0;
160 }
161 case VIDIOCGFREQ:
162 {
163 unsigned long *freq = arg;
164 *freq = fmi->curfreq;
165 if (!(fmi->flags & VIDEO_TUNER_LOW))
166 *freq /= 1000;
167 return 0; 182 return 0;
168 } 183 }
169 case VIDIOCSFREQ: 184 case VIDIOC_S_FREQUENCY:
170 { 185 {
171 unsigned long *freq = arg; 186 struct v4l2_frequency *f = arg;
172 if (!(fmi->flags & VIDEO_TUNER_LOW)) 187
173 *freq *= 1000; 188 if (!(fmi->flags & V4L2_TUNER_CAP_LOW))
174 if (*freq < RSF16_MINFREQ || *freq > RSF16_MAXFREQ ) 189 f->frequency *= 1000;
190 if (f->frequency < RSF16_MINFREQ ||
191 f->frequency > RSF16_MAXFREQ )
175 return -EINVAL; 192 return -EINVAL;
176 /*rounding in steps of 800 to match th freq 193 /*rounding in steps of 800 to match th freq
177 that will be used */ 194 that will be used */
178 fmi->curfreq = (*freq/800)*800; 195 fmi->curfreq = (f->frequency/800)*800;
179 fmi_setfreq(fmi); 196 fmi_setfreq(fmi);
197
180 return 0; 198 return 0;
181 } 199 }
182 case VIDIOCGAUDIO: 200 case VIDIOC_G_FREQUENCY:
183 { 201 {
184 struct video_audio *v = arg; 202 struct v4l2_frequency *f = arg;
185 memset(v,0,sizeof(*v)); 203
186 v->flags=( (!fmi->curvol)*VIDEO_AUDIO_MUTE | VIDEO_AUDIO_MUTABLE); 204 f->type = V4L2_TUNER_RADIO;
187 strcpy(v->name, "Radio"); 205 f->frequency = fmi->curfreq;
188 v->mode=VIDEO_SOUND_STEREO; 206 if (!(fmi->flags & V4L2_TUNER_CAP_LOW))
207 f->frequency /= 1000;
208
189 return 0; 209 return 0;
190 } 210 }
191 case VIDIOCSAUDIO: 211 case VIDIOC_QUERYCTRL:
192 { 212 {
193 struct video_audio *v = arg; 213 struct v4l2_queryctrl *qc = arg;
194 if(v->audio) 214 int i;
195 return -EINVAL; 215
196 fmi->curvol= v->flags&VIDEO_AUDIO_MUTE ? 0 : 1; 216 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
197 fmi->curvol ? 217 if (qc->id && qc->id == radio_qctrl[i].id) {
198 fmi_unmute(fmi->port) : fmi_mute(fmi->port); 218 memcpy(qc, &(radio_qctrl[i]),
199 return 0; 219 sizeof(*qc));
220 return (0);
221 }
222 }
223 return -EINVAL;
200 } 224 }
201 case VIDIOCGUNIT: 225 case VIDIOC_G_CTRL:
202 { 226 {
203 struct video_unit *v = arg; 227 struct v4l2_control *ctrl= arg;
204 v->video=VIDEO_NO_UNIT; 228
205 v->vbi=VIDEO_NO_UNIT; 229 switch (ctrl->id) {
206 v->radio=dev->minor; 230 case V4L2_CID_AUDIO_MUTE:
207 v->audio=0; /* How do we find out this??? */ 231 ctrl->value=fmi->curvol;
208 v->teletext=VIDEO_NO_UNIT; 232 return (0);
209 return 0; 233 }
234 return -EINVAL;
235 }
236 case VIDIOC_S_CTRL:
237 {
238 struct v4l2_control *ctrl= arg;
239
240 switch (ctrl->id) {
241 case V4L2_CID_AUDIO_MUTE:
242 {
243 if (ctrl->value)
244 fmi_mute(fmi->port);
245 else
246 fmi_unmute(fmi->port);
247
248 fmi->curvol=ctrl->value;
249 return (0);
250 }
251 }
252 return -EINVAL;
210 } 253 }
211 default: 254 default:
212 return -ENOIOCTLCMD; 255 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
256 fmi_do_ioctl);
213 } 257 }
214} 258}
215 259
@@ -235,7 +279,7 @@ static struct video_device fmi_radio=
235 .owner = THIS_MODULE, 279 .owner = THIS_MODULE,
236 .name = "SF16FMx radio", 280 .name = "SF16FMx radio",
237 .type = VID_TYPE_TUNER, 281 .type = VID_TYPE_TUNER,
238 .hardware = VID_HARDWARE_SF16MI, 282 .hardware = 0,
239 .fops = &fmi_fops, 283 .fops = &fmi_fops,
240}; 284};
241 285
@@ -294,7 +338,7 @@ static int __init fmi_init(void)
294 fmi_unit.port = io; 338 fmi_unit.port = io;
295 fmi_unit.curvol = 0; 339 fmi_unit.curvol = 0;
296 fmi_unit.curfreq = 0; 340 fmi_unit.curfreq = 0;
297 fmi_unit.flags = VIDEO_TUNER_LOW; 341 fmi_unit.flags = V4L2_TUNER_CAP_LOW;
298 fmi_radio.priv = &fmi_unit; 342 fmi_radio.priv = &fmi_unit;
299 343
300 mutex_init(&lock); 344 mutex_init(&lock);
diff --git a/drivers/media/radio/radio-sf16fmr2.c b/drivers/media/radio/radio-sf16fmr2.c
index 3483b2c7bc9d..4444dce864a9 100644
--- a/drivers/media/radio/radio-sf16fmr2.c
+++ b/drivers/media/radio/radio-sf16fmr2.c
@@ -10,6 +10,8 @@
10 * For read stereo/mono you must wait 0.1 sec after set frequency and 10 * For read stereo/mono you must wait 0.1 sec after set frequency and
11 * card unmuted so I set frequency on unmute 11 * card unmuted so I set frequency on unmute
12 * Signal handling seem to work only on autoscanning (not implemented) 12 * Signal handling seem to work only on autoscanning (not implemented)
13 *
14 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
13 */ 15 */
14 16
15#include <linux/module.h> /* Modules */ 17#include <linux/module.h> /* Modules */
@@ -18,12 +20,34 @@
18#include <linux/delay.h> /* udelay */ 20#include <linux/delay.h> /* udelay */
19#include <asm/io.h> /* outb, outb_p */ 21#include <asm/io.h> /* outb, outb_p */
20#include <asm/uaccess.h> /* copy to/from user */ 22#include <asm/uaccess.h> /* copy to/from user */
21#include <linux/videodev.h> /* kernel radio structs */ 23#include <linux/videodev2.h> /* kernel radio structs */
22#include <media/v4l2-common.h> 24#include <media/v4l2-common.h>
23#include <linux/mutex.h> 25#include <linux/mutex.h>
24 26
25static struct mutex lock; 27static struct mutex lock;
26 28
29#include <linux/version.h> /* for KERNEL_VERSION MACRO */
30#define RADIO_VERSION KERNEL_VERSION(0,0,2)
31
32static struct v4l2_queryctrl radio_qctrl[] = {
33 {
34 .id = V4L2_CID_AUDIO_MUTE,
35 .name = "Mute",
36 .minimum = 0,
37 .maximum = 1,
38 .default_value = 1,
39 .type = V4L2_CTRL_TYPE_BOOLEAN,
40 },{
41 .id = V4L2_CID_AUDIO_VOLUME,
42 .name = "Volume",
43 .minimum = 0,
44 .maximum = 65535,
45 .step = 1<<12,
46 .default_value = 0xff,
47 .type = V4L2_CTRL_TYPE_INTEGER,
48 }
49};
50
27#undef DEBUG 51#undef DEBUG
28//#define DEBUG 1 52//#define DEBUG 1
29 53
@@ -214,63 +238,65 @@ static int fmr2_do_ioctl(struct inode *inode, struct file *file,
214 238
215 switch(cmd) 239 switch(cmd)
216 { 240 {
217 case VIDIOCGCAP: 241 case VIDIOC_QUERYCAP:
218 { 242 {
219 struct video_capability *v = arg; 243 struct v4l2_capability *v = arg;
220 memset(v,0,sizeof(*v)); 244 memset(v,0,sizeof(*v));
221 strcpy(v->name, "SF16-FMR2 radio"); 245 strlcpy(v->driver, "radio-sf16fmr2", sizeof (v->driver));
222 v->type=VID_TYPE_TUNER; 246 strlcpy(v->card, "SF16-FMR2 radio", sizeof (v->card));
223 v->channels=1; 247 sprintf(v->bus_info,"ISA");
224 v->audios=1; 248 v->version = RADIO_VERSION;
249 v->capabilities = V4L2_CAP_TUNER;
250
225 return 0; 251 return 0;
226 } 252 }
227 case VIDIOCGTUNER: 253 case VIDIOC_G_TUNER:
228 { 254 {
229 struct video_tuner *v = arg; 255 struct v4l2_tuner *v = arg;
230 int mult; 256 int mult;
231 257
232 if(v->tuner) /* Only 1 tuner */ 258 if (v->index > 0)
233 return -EINVAL; 259 return -EINVAL;
260
261 memset(v,0,sizeof(*v));
234 strcpy(v->name, "FM"); 262 strcpy(v->name, "FM");
235 mult = (fmr2->flags & VIDEO_TUNER_LOW) ? 1 : 1000; 263 v->type = V4L2_TUNER_RADIO;
264
265 mult = (fmr2->flags & V4L2_TUNER_CAP_LOW) ? 1 : 1000;
236 v->rangelow = RSF16_MINFREQ/mult; 266 v->rangelow = RSF16_MINFREQ/mult;
237 v->rangehigh = RSF16_MAXFREQ/mult; 267 v->rangehigh = RSF16_MAXFREQ/mult;
238 v->flags = fmr2->flags | VIDEO_AUDIO_MUTABLE; 268 v->rxsubchans =V4L2_TUNER_SUB_MONO | V4L2_TUNER_MODE_STEREO;
239 if (fmr2->mute) 269 v->capability=fmr2->flags&V4L2_TUNER_CAP_LOW;
240 v->flags |= VIDEO_AUDIO_MUTE; 270
241 v->mode=VIDEO_MODE_AUTO; 271 v->audmode = fmr2->stereo ? V4L2_TUNER_MODE_STEREO:
272 V4L2_TUNER_MODE_MONO;
242 mutex_lock(&lock); 273 mutex_lock(&lock);
243 v->signal = fmr2_getsigstr(fmr2); 274 v->signal = fmr2_getsigstr(fmr2);
244 mutex_unlock(&lock); 275 mutex_unlock(&lock);
276
245 return 0; 277 return 0;
246 } 278 }
247 case VIDIOCSTUNER: 279 case VIDIOC_S_TUNER:
248 { 280 {
249 struct video_tuner *v = arg; 281 struct v4l2_tuner *v = arg;
250 if (v->tuner!=0) 282
283 if (v->index > 0)
251 return -EINVAL; 284 return -EINVAL;
252 fmr2->flags = v->flags & VIDEO_TUNER_LOW; 285
253 return 0;
254 }
255 case VIDIOCGFREQ:
256 {
257 unsigned long *freq = arg;
258 *freq = fmr2->curfreq;
259 if (!(fmr2->flags & VIDEO_TUNER_LOW))
260 *freq /= 1000;
261 return 0; 286 return 0;
262 } 287 }
263 case VIDIOCSFREQ: 288 case VIDIOC_S_FREQUENCY:
264 { 289 {
265 unsigned long *freq = arg; 290 struct v4l2_frequency *f = arg;
266 if (!(fmr2->flags & VIDEO_TUNER_LOW)) 291
267 *freq *= 1000; 292 if (!(fmr2->flags & V4L2_TUNER_CAP_LOW))
268 if ( *freq < RSF16_MINFREQ || *freq > RSF16_MAXFREQ ) 293 f->frequency *= 1000;
294 if (f->frequency < RSF16_MINFREQ ||
295 f->frequency > RSF16_MAXFREQ )
269 return -EINVAL; 296 return -EINVAL;
270 /* rounding in steps of 200 to match th freq 297 /*rounding in steps of 200 to match th freq
271 * that will be used 298 that will be used */
272 */ 299 fmr2->curfreq = (f->frequency/200)*200;
273 fmr2->curfreq = (*freq/200)*200;
274 300
275 /* set card freq (if not muted) */ 301 /* set card freq (if not muted) */
276 if (fmr2->curvol && !fmr2->mute) 302 if (fmr2->curvol && !fmr2->mute)
@@ -279,40 +305,81 @@ static int fmr2_do_ioctl(struct inode *inode, struct file *file,
279 fmr2_setfreq(fmr2); 305 fmr2_setfreq(fmr2);
280 mutex_unlock(&lock); 306 mutex_unlock(&lock);
281 } 307 }
308
282 return 0; 309 return 0;
283 } 310 }
284 case VIDIOCGAUDIO: 311 case VIDIOC_G_FREQUENCY:
285 { 312 {
286 struct video_audio *v = arg; 313 struct v4l2_frequency *f = arg;
287 memset(v,0,sizeof(*v)); 314
288 /* !!! do not return VIDEO_AUDIO_MUTE */ 315 f->type = V4L2_TUNER_RADIO;
289 v->flags = VIDEO_AUDIO_MUTABLE; 316 f->frequency = fmr2->curfreq;
290 strcpy(v->name, "Radio"); 317 if (!(fmr2->flags & V4L2_TUNER_CAP_LOW))
291 /* get current stereo mode */ 318 f->frequency /= 1000;
292 v->mode = fmr2->stereo ? VIDEO_SOUND_STEREO: VIDEO_SOUND_MONO; 319
293 /* volume supported ? */
294 if (fmr2->card_type == 11)
295 {
296 v->flags |= VIDEO_AUDIO_VOLUME;
297 v->step = 1 << 12;
298 v->volume = fmr2->curvol;
299 }
300 debug_print((KERN_DEBUG "Get flags %d vol %d\n", v->flags, v->volume));
301 return 0; 320 return 0;
302 } 321 }
303 case VIDIOCSAUDIO: 322 case VIDIOC_QUERYCTRL:
304 { 323 {
305 struct video_audio *v = arg; 324 struct v4l2_queryctrl *qc = arg;
306 if(v->audio) 325 int i;
307 return -EINVAL; 326
308 debug_print((KERN_DEBUG "Set flags %d vol %d\n", v->flags, v->volume)); 327 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
309 /* set volume */ 328 if ((fmr2->card_type != 11)
310 if (v->flags & VIDEO_AUDIO_VOLUME) 329 && V4L2_CID_AUDIO_VOLUME)
311 fmr2->curvol = v->volume; /* !!! set with precision */ 330 radio_qctrl[i].step=65535;
312 if (fmr2->card_type != 11) fmr2->curvol = 65535; 331 if (qc->id && qc->id == radio_qctrl[i].id) {
313 fmr2->mute = 0; 332 memcpy(qc, &(radio_qctrl[i]),
314 if (v->flags & VIDEO_AUDIO_MUTE) 333 sizeof(*qc));
315 fmr2->mute = 1; 334 return (0);
335 }
336 }
337 return -EINVAL;
338 }
339 case VIDIOC_G_CTRL:
340 {
341 struct v4l2_control *ctrl= arg;
342
343 switch (ctrl->id) {
344 case V4L2_CID_AUDIO_MUTE:
345 ctrl->value=fmr2->mute;
346 return (0);
347 case V4L2_CID_AUDIO_VOLUME:
348 ctrl->value=fmr2->curvol;
349 return (0);
350 }
351 return -EINVAL;
352 }
353 case VIDIOC_S_CTRL:
354 {
355 struct v4l2_control *ctrl= arg;
356
357 switch (ctrl->id) {
358 case V4L2_CID_AUDIO_MUTE:
359 fmr2->mute=ctrl->value;
360 if (fmr2->card_type != 11) {
361 if (!fmr2->mute) {
362 fmr2->curvol = 65535;
363 } else {
364 fmr2->curvol = 0;
365 }
366 }
367 break;
368 case V4L2_CID_AUDIO_VOLUME:
369 fmr2->curvol = ctrl->value;
370 if (fmr2->card_type != 11) {
371 if (fmr2->curvol) {
372 fmr2->curvol = 65535;
373 fmr2->mute = 0;
374 } else {
375 fmr2->curvol = 0;
376 fmr2->mute = 1;
377 }
378 }
379 break;
380 default:
381 return -EINVAL;
382 }
316#ifdef DEBUG 383#ifdef DEBUG
317 if (fmr2->curvol && !fmr2->mute) 384 if (fmr2->curvol && !fmr2->mute)
318 printk(KERN_DEBUG "unmute\n"); 385 printk(KERN_DEBUG "unmute\n");
@@ -320,27 +387,18 @@ static int fmr2_do_ioctl(struct inode *inode, struct file *file,
320 printk(KERN_DEBUG "mute\n"); 387 printk(KERN_DEBUG "mute\n");
321#endif 388#endif
322 mutex_lock(&lock); 389 mutex_lock(&lock);
323 if (fmr2->curvol && !fmr2->mute) 390 if (fmr2->curvol && !fmr2->mute) {
324 {
325 fmr2_setvolume(fmr2); 391 fmr2_setvolume(fmr2);
326 fmr2_setfreq(fmr2); 392 fmr2_setfreq(fmr2);
327 } 393 } else
328 else fmr2_mute(fmr2->port); 394 fmr2_mute(fmr2->port);
329 mutex_unlock(&lock); 395 mutex_unlock(&lock);
330 return 0; 396 return (0);
331 }
332 case VIDIOCGUNIT:
333 {
334 struct video_unit *v = arg;
335 v->video=VIDEO_NO_UNIT;
336 v->vbi=VIDEO_NO_UNIT;
337 v->radio=dev->minor;
338 v->audio=0; /* How do we find out this??? */
339 v->teletext=VIDEO_NO_UNIT;
340 return 0;
341 } 397 }
342 default: 398 default:
343 return -ENOIOCTLCMD; 399 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
400 fmr2_do_ioctl);
401
344 } 402 }
345} 403}
346 404
@@ -366,7 +424,7 @@ static struct video_device fmr2_radio=
366 .owner = THIS_MODULE, 424 .owner = THIS_MODULE,
367 .name = "SF16FMR2 radio", 425 .name = "SF16FMR2 radio",
368 . type = VID_TYPE_TUNER, 426 . type = VID_TYPE_TUNER,
369 .hardware = VID_HARDWARE_SF16FMR2, 427 .hardware = 0,
370 .fops = &fmr2_fops, 428 .fops = &fmr2_fops,
371}; 429};
372 430
@@ -377,7 +435,7 @@ static int __init fmr2_init(void)
377 fmr2_unit.mute = 0; 435 fmr2_unit.mute = 0;
378 fmr2_unit.curfreq = 0; 436 fmr2_unit.curfreq = 0;
379 fmr2_unit.stereo = 1; 437 fmr2_unit.stereo = 1;
380 fmr2_unit.flags = VIDEO_TUNER_LOW; 438 fmr2_unit.flags = V4L2_TUNER_CAP_LOW;
381 fmr2_unit.card_type = 0; 439 fmr2_unit.card_type = 0;
382 fmr2_radio.priv = &fmr2_unit; 440 fmr2_radio.priv = &fmr2_unit;
383 441
@@ -396,7 +454,6 @@ static int __init fmr2_init(void)
396 } 454 }
397 455
398 printk(KERN_INFO "SF16FMR2 radio card driver at 0x%x.\n", io); 456 printk(KERN_INFO "SF16FMR2 radio card driver at 0x%x.\n", io);
399 debug_print((KERN_DEBUG "Mute %d Low %d\n",VIDEO_AUDIO_MUTE,VIDEO_TUNER_LOW));
400 /* mute card - prevents noisy bootups */ 457 /* mute card - prevents noisy bootups */
401 mutex_lock(&lock); 458 mutex_lock(&lock);
402 fmr2_mute(io); 459 fmr2_mute(io);
diff --git a/drivers/media/radio/radio-terratec.c b/drivers/media/radio/radio-terratec.c
index dfba4ae596cd..f539491a0d76 100644
--- a/drivers/media/radio/radio-terratec.c
+++ b/drivers/media/radio/radio-terratec.c
@@ -21,6 +21,7 @@
21 * If you can help me out with that, please contact me!! 21 * If you can help me out with that, please contact me!!
22 * 22 *
23 * 23 *
24 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
24 */ 25 */
25 26
26#include <linux/module.h> /* Modules */ 27#include <linux/module.h> /* Modules */
@@ -29,11 +30,32 @@
29#include <linux/delay.h> /* udelay */ 30#include <linux/delay.h> /* udelay */
30#include <asm/io.h> /* outb, outb_p */ 31#include <asm/io.h> /* outb, outb_p */
31#include <asm/uaccess.h> /* copy to/from user */ 32#include <asm/uaccess.h> /* copy to/from user */
32#include <linux/videodev.h> /* kernel radio structs */ 33#include <linux/videodev2.h> /* kernel radio structs */
33#include <media/v4l2-common.h> 34#include <media/v4l2-common.h>
34#include <linux/config.h> /* CONFIG_RADIO_TERRATEC_PORT */
35#include <linux/spinlock.h> 35#include <linux/spinlock.h>
36 36
37#include <linux/version.h> /* for KERNEL_VERSION MACRO */
38#define RADIO_VERSION KERNEL_VERSION(0,0,2)
39
40static struct v4l2_queryctrl radio_qctrl[] = {
41 {
42 .id = V4L2_CID_AUDIO_MUTE,
43 .name = "Mute",
44 .minimum = 0,
45 .maximum = 1,
46 .default_value = 1,
47 .type = V4L2_CTRL_TYPE_BOOLEAN,
48 },{
49 .id = V4L2_CID_AUDIO_VOLUME,
50 .name = "Volume",
51 .minimum = 0,
52 .maximum = 0xff,
53 .step = 1,
54 .default_value = 0xff,
55 .type = V4L2_CTRL_TYPE_INTEGER,
56 }
57};
58
37#ifndef CONFIG_RADIO_TERRATEC_PORT 59#ifndef CONFIG_RADIO_TERRATEC_PORT
38#define CONFIG_RADIO_TERRATEC_PORT 0x590 60#define CONFIG_RADIO_TERRATEC_PORT 0x590
39#endif 61#endif
@@ -194,73 +216,117 @@ static int tt_do_ioctl(struct inode *inode, struct file *file,
194 216
195 switch(cmd) 217 switch(cmd)
196 { 218 {
197 case VIDIOCGCAP: 219 case VIDIOC_QUERYCAP:
198 { 220 {
199 struct video_capability *v = arg; 221 struct v4l2_capability *v = arg;
200 memset(v,0,sizeof(*v)); 222 memset(v,0,sizeof(*v));
201 v->type=VID_TYPE_TUNER; 223 strlcpy(v->driver, "radio-terratec", sizeof (v->driver));
202 v->channels=1; 224 strlcpy(v->card, "ActiveRadio", sizeof (v->card));
203 v->audios=1; 225 sprintf(v->bus_info,"ISA");
204 strcpy(v->name, "ActiveRadio"); 226 v->version = RADIO_VERSION;
227 v->capabilities = V4L2_CAP_TUNER;
228
205 return 0; 229 return 0;
206 } 230 }
207 case VIDIOCGTUNER: 231 case VIDIOC_G_TUNER:
208 { 232 {
209 struct video_tuner *v = arg; 233 struct v4l2_tuner *v = arg;
210 if(v->tuner) /* Only 1 tuner */ 234
235 if (v->index > 0)
211 return -EINVAL; 236 return -EINVAL;
237
238 memset(v,0,sizeof(*v));
239 strcpy(v->name, "FM");
240 v->type = V4L2_TUNER_RADIO;
241
212 v->rangelow=(87*16000); 242 v->rangelow=(87*16000);
213 v->rangehigh=(108*16000); 243 v->rangehigh=(108*16000);
214 v->flags=VIDEO_TUNER_LOW; 244 v->rxsubchans =V4L2_TUNER_SUB_MONO;
215 v->mode=VIDEO_MODE_AUTO; 245 v->capability=V4L2_TUNER_CAP_LOW;
216 strcpy(v->name, "FM"); 246 v->audmode = V4L2_TUNER_MODE_MONO;
217 v->signal=0xFFFF*tt_getsigstr(tt); 247 v->signal=0xFFFF*tt_getsigstr(tt);
248
218 return 0; 249 return 0;
219 } 250 }
220 case VIDIOCSTUNER: 251 case VIDIOC_S_TUNER:
221 { 252 {
222 struct video_tuner *v = arg; 253 struct v4l2_tuner *v = arg;
223 if(v->tuner!=0) 254
255 if (v->index > 0)
224 return -EINVAL; 256 return -EINVAL;
225 /* Only 1 tuner so no setting needed ! */ 257
226 return 0; 258 return 0;
227 } 259 }
228 case VIDIOCGFREQ: 260 case VIDIOC_S_FREQUENCY:
229 { 261 {
230 unsigned long *freq = arg; 262 struct v4l2_frequency *f = arg;
231 *freq = tt->curfreq; 263
264 tt->curfreq = f->frequency;
265 tt_setfreq(tt, tt->curfreq);
232 return 0; 266 return 0;
233 } 267 }
234 case VIDIOCSFREQ: 268 case VIDIOC_G_FREQUENCY:
235 { 269 {
236 unsigned long *freq = arg; 270 struct v4l2_frequency *f = arg;
237 tt->curfreq = *freq; 271
238 tt_setfreq(tt, tt->curfreq); 272 f->type = V4L2_TUNER_RADIO;
273 f->frequency = tt->curfreq;
274
239 return 0; 275 return 0;
240 } 276 }
241 case VIDIOCGAUDIO: 277 case VIDIOC_QUERYCTRL:
242 { 278 {
243 struct video_audio *v = arg; 279 struct v4l2_queryctrl *qc = arg;
244 memset(v,0, sizeof(*v)); 280 int i;
245 v->flags|=VIDEO_AUDIO_MUTABLE|VIDEO_AUDIO_VOLUME; 281
246 v->volume=tt->curvol * 6554; 282 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
247 v->step=6554; 283 if (qc->id && qc->id == radio_qctrl[i].id) {
248 strcpy(v->name, "Radio"); 284 memcpy(qc, &(radio_qctrl[i]),
249 return 0; 285 sizeof(*qc));
286 return (0);
287 }
288 }
289 return -EINVAL;
250 } 290 }
251 case VIDIOCSAUDIO: 291 case VIDIOC_G_CTRL:
252 { 292 {
253 struct video_audio *v = arg; 293 struct v4l2_control *ctrl= arg;
254 if(v->audio) 294
255 return -EINVAL; 295 switch (ctrl->id) {
256 if(v->flags&VIDEO_AUDIO_MUTE) 296 case V4L2_CID_AUDIO_MUTE:
257 tt_mute(tt); 297 if (tt->muted)
258 else 298 ctrl->value=1;
259 tt_setvol(tt,v->volume/6554); 299 else
260 return 0; 300 ctrl->value=0;
301 return (0);
302 case V4L2_CID_AUDIO_VOLUME:
303 ctrl->value=tt->curvol * 6554;
304 return (0);
305 }
306 return -EINVAL;
261 } 307 }
308 case VIDIOC_S_CTRL:
309 {
310 struct v4l2_control *ctrl= arg;
311
312 switch (ctrl->id) {
313 case V4L2_CID_AUDIO_MUTE:
314 if (ctrl->value) {
315 tt_mute(tt);
316 } else {
317 tt_setvol(tt,tt->curvol);
318 }
319 return (0);
320 case V4L2_CID_AUDIO_VOLUME:
321 tt_setvol(tt,ctrl->value);
322 return (0);
323 }
324 return -EINVAL;
325 }
326
262 default: 327 default:
263 return -ENOIOCTLCMD; 328 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
329 tt_do_ioctl);
264 } 330 }
265} 331}
266 332
@@ -286,7 +352,7 @@ static struct video_device terratec_radio=
286 .owner = THIS_MODULE, 352 .owner = THIS_MODULE,
287 .name = "TerraTec ActiveRadio", 353 .name = "TerraTec ActiveRadio",
288 .type = VID_TYPE_TUNER, 354 .type = VID_TYPE_TUNER,
289 .hardware = VID_HARDWARE_TERRATEC, 355 .hardware = 0,
290 .fops = &terratec_fops, 356 .fops = &terratec_fops,
291}; 357};
292 358
diff --git a/drivers/media/radio/radio-trust.c b/drivers/media/radio/radio-trust.c
index 8da4badc22b4..bb03ad5a2033 100644
--- a/drivers/media/radio/radio-trust.c
+++ b/drivers/media/radio/radio-trust.c
@@ -12,7 +12,7 @@
12 * Scott McGrath (smcgrath@twilight.vtc.vsc.edu) 12 * Scott McGrath (smcgrath@twilight.vtc.vsc.edu)
13 * William McGrath (wmcgrath@twilight.vtc.vsc.edu) 13 * William McGrath (wmcgrath@twilight.vtc.vsc.edu)
14 * 14 *
15 * The basis for this code may be found at http://bigbang.vtc.vsc.edu/fmradio/ 15 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
16 */ 16 */
17 17
18#include <stdarg.h> 18#include <stdarg.h>
@@ -21,9 +21,46 @@
21#include <linux/ioport.h> 21#include <linux/ioport.h>
22#include <asm/io.h> 22#include <asm/io.h>
23#include <asm/uaccess.h> 23#include <asm/uaccess.h>
24#include <linux/videodev.h> 24#include <linux/videodev2.h>
25#include <media/v4l2-common.h> 25#include <media/v4l2-common.h>
26#include <linux/config.h> /* CONFIG_RADIO_TRUST_PORT */ 26
27#include <linux/version.h> /* for KERNEL_VERSION MACRO */
28#define RADIO_VERSION KERNEL_VERSION(0,0,2)
29
30static struct v4l2_queryctrl radio_qctrl[] = {
31 {
32 .id = V4L2_CID_AUDIO_MUTE,
33 .name = "Mute",
34 .minimum = 0,
35 .maximum = 1,
36 .default_value = 1,
37 .type = V4L2_CTRL_TYPE_BOOLEAN,
38 },{
39 .id = V4L2_CID_AUDIO_VOLUME,
40 .name = "Volume",
41 .minimum = 0,
42 .maximum = 65535,
43 .step = 2048,
44 .default_value = 65535,
45 .type = V4L2_CTRL_TYPE_INTEGER,
46 },{
47 .id = V4L2_CID_AUDIO_BASS,
48 .name = "Bass",
49 .minimum = 0,
50 .maximum = 65535,
51 .step = 4370,
52 .default_value = 32768,
53 .type = V4L2_CTRL_TYPE_INTEGER,
54 },{
55 .id = V4L2_CID_AUDIO_TREBLE,
56 .name = "Treble",
57 .minimum = 0,
58 .maximum = 65535,
59 .step = 4370,
60 .default_value = 32768,
61 .type = V4L2_CTRL_TYPE_INTEGER,
62 },
63};
27 64
28/* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */ 65/* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */
29 66
@@ -160,88 +197,125 @@ static int tr_do_ioctl(struct inode *inode, struct file *file,
160{ 197{
161 switch(cmd) 198 switch(cmd)
162 { 199 {
163 case VIDIOCGCAP: 200 case VIDIOC_QUERYCAP:
164 { 201 {
165 struct video_capability *v = arg; 202 struct v4l2_capability *v = arg;
166
167 memset(v,0,sizeof(*v)); 203 memset(v,0,sizeof(*v));
168 v->type=VID_TYPE_TUNER; 204 strlcpy(v->driver, "radio-trust", sizeof (v->driver));
169 v->channels=1; 205 strlcpy(v->card, "Trust FM Radio", sizeof (v->card));
170 v->audios=1; 206 sprintf(v->bus_info,"ISA");
171 strcpy(v->name, "Trust FM Radio"); 207 v->version = RADIO_VERSION;
208 v->capabilities = V4L2_CAP_TUNER;
172 209
173 return 0; 210 return 0;
174 } 211 }
175 case VIDIOCGTUNER: 212 case VIDIOC_G_TUNER:
176 { 213 {
177 struct video_tuner *v = arg; 214 struct v4l2_tuner *v = arg;
178 215
179 if(v->tuner) /* Only 1 tuner */ 216 if (v->index > 0)
180 return -EINVAL; 217 return -EINVAL;
181 218
182 v->rangelow = 87500 * 16; 219 memset(v,0,sizeof(*v));
183 v->rangehigh = 108000 * 16; 220 strcpy(v->name, "FM");
184 v->flags = VIDEO_TUNER_LOW; 221 v->type = V4L2_TUNER_RADIO;
185 v->mode = VIDEO_MODE_AUTO;
186 222
187 v->signal = tr_getsigstr(); 223 v->rangelow=(87.5*16000);
224 v->rangehigh=(108*16000);
225 v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
226 v->capability=V4L2_TUNER_CAP_LOW;
188 if(tr_getstereo()) 227 if(tr_getstereo())
189 v->flags |= VIDEO_TUNER_STEREO_ON; 228 v->audmode = V4L2_TUNER_MODE_STEREO;
190 229 else
191 strcpy(v->name, "FM"); 230 v->audmode = V4L2_TUNER_MODE_MONO;
231 v->signal=tr_getsigstr();
192 232
193 return 0; 233 return 0;
194 } 234 }
195 case VIDIOCSTUNER: 235 case VIDIOC_S_TUNER:
196 { 236 {
197 struct video_tuner *v = arg; 237 struct v4l2_tuner *v = arg;
198 if(v->tuner != 0) 238
239 if (v->index > 0)
199 return -EINVAL; 240 return -EINVAL;
241
200 return 0; 242 return 0;
201 } 243 }
202 case VIDIOCGFREQ: 244 case VIDIOC_S_FREQUENCY:
203 { 245 {
204 unsigned long *freq = arg; 246 struct v4l2_frequency *f = arg;
205 *freq = curfreq; 247
248 curfreq = f->frequency;
249 tr_setfreq(curfreq);
206 return 0; 250 return 0;
207 } 251 }
208 case VIDIOCSFREQ: 252 case VIDIOC_G_FREQUENCY:
209 { 253 {
210 unsigned long *freq = arg; 254 struct v4l2_frequency *f = arg;
211 tr_setfreq(*freq); 255
256 f->type = V4L2_TUNER_RADIO;
257 f->frequency = curfreq;
258
212 return 0; 259 return 0;
213 } 260 }
214 case VIDIOCGAUDIO: 261 case VIDIOC_QUERYCTRL:
215 { 262 {
216 struct video_audio *v = arg; 263 struct v4l2_queryctrl *qc = arg;
217 264 int i;
218 memset(v,0, sizeof(*v)); 265
219 v->flags = VIDEO_AUDIO_MUTABLE | VIDEO_AUDIO_VOLUME | 266 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
220 VIDEO_AUDIO_BASS | VIDEO_AUDIO_TREBLE; 267 if (qc->id && qc->id == radio_qctrl[i].id) {
221 v->mode = curstereo? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO; 268 memcpy(qc, &(radio_qctrl[i]),
222 v->volume = curvol * 2048; 269 sizeof(*qc));
223 v->step = 2048; 270 return (0);
224 v->bass = curbass * 4370; 271 }
225 v->treble = curtreble * 4370; 272 }
226 273 return -EINVAL;
227 strcpy(v->name, "Trust FM Radio");
228 return 0;
229 } 274 }
230 case VIDIOCSAUDIO: 275 case VIDIOC_G_CTRL:
231 { 276 {
232 struct video_audio *v = arg; 277 struct v4l2_control *ctrl= arg;
233 278
234 if(v->audio) 279 switch (ctrl->id) {
235 return -EINVAL; 280 case V4L2_CID_AUDIO_MUTE:
236 tr_setvol(v->volume); 281 ctrl->value=curmute;
237 tr_setbass(v->bass); 282 return (0);
238 tr_settreble(v->treble); 283 case V4L2_CID_AUDIO_VOLUME:
239 tr_setstereo(v->mode & VIDEO_SOUND_STEREO); 284 ctrl->value= curvol * 2048;
240 tr_setmute(v->flags & VIDEO_AUDIO_MUTE); 285 return (0);
241 return 0; 286 case V4L2_CID_AUDIO_BASS:
287 ctrl->value= curbass * 4370;
288 return (0);
289 case V4L2_CID_AUDIO_TREBLE:
290 ctrl->value= curtreble * 4370;
291 return (0);
292 }
293 return -EINVAL;
242 } 294 }
295 case VIDIOC_S_CTRL:
296 {
297 struct v4l2_control *ctrl= arg;
298
299 switch (ctrl->id) {
300 case V4L2_CID_AUDIO_MUTE:
301 tr_setmute(ctrl->value);
302 return 0;
303 case V4L2_CID_AUDIO_VOLUME:
304 tr_setvol(ctrl->value);
305 return 0;
306 case V4L2_CID_AUDIO_BASS:
307 tr_setbass(ctrl->value);
308 return 0;
309 case V4L2_CID_AUDIO_TREBLE:
310 tr_settreble(ctrl->value);
311 return (0);
312 }
313 return -EINVAL;
314 }
315
243 default: 316 default:
244 return -ENOIOCTLCMD; 317 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
318 tr_do_ioctl);
245 } 319 }
246} 320}
247 321
@@ -265,7 +339,7 @@ static struct video_device trust_radio=
265 .owner = THIS_MODULE, 339 .owner = THIS_MODULE,
266 .name = "Trust FM Radio", 340 .name = "Trust FM Radio",
267 .type = VID_TYPE_TUNER, 341 .type = VID_TYPE_TUNER,
268 .hardware = VID_HARDWARE_TRUST, 342 .hardware = 0,
269 .fops = &trust_fops, 343 .fops = &trust_fops,
270}; 344};
271 345
diff --git a/drivers/media/radio/radio-typhoon.c b/drivers/media/radio/radio-typhoon.c
index edd012288669..4a72b4d4e62a 100644
--- a/drivers/media/radio/radio-typhoon.c
+++ b/drivers/media/radio/radio-typhoon.c
@@ -27,6 +27,8 @@
27 * value where I do expect just noise and turn the speaker volume down. 27 * value where I do expect just noise and turn the speaker volume down.
28 * The frequency change is necessary since the card never seems to be 28 * The frequency change is necessary since the card never seems to be
29 * completely silent. 29 * completely silent.
30 *
31 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
30 */ 32 */
31 33
32#include <linux/module.h> /* Modules */ 34#include <linux/module.h> /* Modules */
@@ -35,11 +37,32 @@
35#include <linux/proc_fs.h> /* radio card status report */ 37#include <linux/proc_fs.h> /* radio card status report */
36#include <asm/io.h> /* outb, outb_p */ 38#include <asm/io.h> /* outb, outb_p */
37#include <asm/uaccess.h> /* copy to/from user */ 39#include <asm/uaccess.h> /* copy to/from user */
38#include <linux/videodev.h> /* kernel radio structs */ 40#include <linux/videodev2.h> /* kernel radio structs */
39#include <media/v4l2-common.h> 41#include <media/v4l2-common.h>
40#include <linux/config.h> /* CONFIG_RADIO_TYPHOON_* */
41 42
42#define BANNER "Typhoon Radio Card driver v0.1\n" 43#include <linux/version.h> /* for KERNEL_VERSION MACRO */
44#define RADIO_VERSION KERNEL_VERSION(0,1,1)
45#define BANNER "Typhoon Radio Card driver v0.1.1\n"
46
47static struct v4l2_queryctrl radio_qctrl[] = {
48 {
49 .id = V4L2_CID_AUDIO_MUTE,
50 .name = "Mute",
51 .minimum = 0,
52 .maximum = 1,
53 .default_value = 1,
54 .type = V4L2_CTRL_TYPE_BOOLEAN,
55 },{
56 .id = V4L2_CID_AUDIO_VOLUME,
57 .name = "Volume",
58 .minimum = 0,
59 .maximum = 65535,
60 .step = 1<<14,
61 .default_value = 0xff,
62 .type = V4L2_CTRL_TYPE_INTEGER,
63 }
64};
65
43 66
44#ifndef CONFIG_RADIO_TYPHOON_PORT 67#ifndef CONFIG_RADIO_TYPHOON_PORT
45#define CONFIG_RADIO_TYPHOON_PORT -1 68#define CONFIG_RADIO_TYPHOON_PORT -1
@@ -171,76 +194,114 @@ static int typhoon_do_ioctl(struct inode *inode, struct file *file,
171 struct typhoon_device *typhoon = dev->priv; 194 struct typhoon_device *typhoon = dev->priv;
172 195
173 switch (cmd) { 196 switch (cmd) {
174 case VIDIOCGCAP: 197 case VIDIOC_QUERYCAP:
175 { 198 {
176 struct video_capability *v = arg; 199 struct v4l2_capability *v = arg;
177 memset(v,0,sizeof(*v)); 200 memset(v,0,sizeof(*v));
178 v->type = VID_TYPE_TUNER; 201 strlcpy(v->driver, "radio-typhoon", sizeof (v->driver));
179 v->channels = 1; 202 strlcpy(v->card, "Typhoon Radio", sizeof (v->card));
180 v->audios = 1; 203 sprintf(v->bus_info,"ISA");
181 strcpy(v->name, "Typhoon Radio"); 204 v->version = RADIO_VERSION;
205 v->capabilities = V4L2_CAP_TUNER;
206
182 return 0; 207 return 0;
183 } 208 }
184 case VIDIOCGTUNER: 209 case VIDIOC_G_TUNER:
185 { 210 {
186 struct video_tuner *v = arg; 211 struct v4l2_tuner *v = arg;
187 if (v->tuner) /* Only 1 tuner */ 212
213 if (v->index > 0)
188 return -EINVAL; 214 return -EINVAL;
189 v->rangelow = 875 * 1600; 215
190 v->rangehigh = 1080 * 1600; 216 memset(v,0,sizeof(*v));
191 v->flags = VIDEO_TUNER_LOW;
192 v->mode = VIDEO_MODE_AUTO;
193 v->signal = 0xFFFF; /* We can't get the signal strength */
194 strcpy(v->name, "FM"); 217 strcpy(v->name, "FM");
218 v->type = V4L2_TUNER_RADIO;
219
220 v->rangelow=(87.5*16000);
221 v->rangehigh=(108*16000);
222 v->rxsubchans =V4L2_TUNER_SUB_MONO;
223 v->capability=V4L2_TUNER_CAP_LOW;
224 v->audmode = V4L2_TUNER_MODE_MONO;
225 v->signal = 0xFFFF; /* We can't get the signal strength */
226
195 return 0; 227 return 0;
196 } 228 }
197 case VIDIOCSTUNER: 229 case VIDIOC_S_TUNER:
198 { 230 {
199 struct video_tuner *v = arg; 231 struct v4l2_tuner *v = arg;
200 if (v->tuner != 0) 232
233 if (v->index > 0)
201 return -EINVAL; 234 return -EINVAL;
202 /* Only 1 tuner so no setting needed ! */ 235
203 return 0; 236 return 0;
204 } 237 }
205 case VIDIOCGFREQ: 238 case VIDIOC_S_FREQUENCY:
206 {
207 unsigned long *freq = arg;
208 *freq = typhoon->curfreq;
209 return 0;
210 }
211 case VIDIOCSFREQ:
212 {
213 unsigned long *freq = arg;
214 typhoon->curfreq = *freq;
215 typhoon_setfreq(typhoon, typhoon->curfreq);
216 return 0;
217 }
218 case VIDIOCGAUDIO:
219 { 239 {
220 struct video_audio *v = arg; 240 struct v4l2_frequency *f = arg;
221 memset(v, 0, sizeof(*v)); 241
222 v->flags |= VIDEO_AUDIO_MUTABLE | VIDEO_AUDIO_VOLUME; 242 typhoon->curfreq = f->frequency;
223 v->mode |= VIDEO_SOUND_MONO; 243 typhoon_setfreq(typhoon, typhoon->curfreq);
224 v->volume = typhoon->curvol;
225 v->step = 1 << 14;
226 strcpy(v->name, "Typhoon Radio");
227 return 0; 244 return 0;
228 } 245 }
229 case VIDIOCSAUDIO: 246 case VIDIOC_G_FREQUENCY:
230 { 247 {
231 struct video_audio *v = arg; 248 struct v4l2_frequency *f = arg;
232 if (v->audio) 249
233 return -EINVAL; 250 f->type = V4L2_TUNER_RADIO;
234 if (v->flags & VIDEO_AUDIO_MUTE) 251 f->frequency = typhoon->curfreq;
235 typhoon_mute(typhoon); 252
236 else
237 typhoon_unmute(typhoon);
238 if (v->flags & VIDEO_AUDIO_VOLUME)
239 typhoon_setvol(typhoon, v->volume);
240 return 0; 253 return 0;
241 } 254 }
242 default: 255 case VIDIOC_QUERYCTRL:
243 return -ENOIOCTLCMD; 256 {
257 struct v4l2_queryctrl *qc = arg;
258 int i;
259
260 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
261 if (qc->id && qc->id == radio_qctrl[i].id) {
262 memcpy(qc, &(radio_qctrl[i]),
263 sizeof(*qc));
264 return (0);
265 }
266 }
267 return -EINVAL;
268 }
269 case VIDIOC_G_CTRL:
270 {
271 struct v4l2_control *ctrl= arg;
272
273 switch (ctrl->id) {
274 case V4L2_CID_AUDIO_MUTE:
275 ctrl->value=typhoon->muted;
276 return (0);
277 case V4L2_CID_AUDIO_VOLUME:
278 ctrl->value=typhoon->curvol;
279 return (0);
280 }
281 return -EINVAL;
282 }
283 case VIDIOC_S_CTRL:
284 {
285 struct v4l2_control *ctrl= arg;
286
287 switch (ctrl->id) {
288 case V4L2_CID_AUDIO_MUTE:
289 if (ctrl->value) {
290 typhoon_mute(typhoon);
291 } else {
292 typhoon_unmute(typhoon);
293 }
294 return (0);
295 case V4L2_CID_AUDIO_VOLUME:
296 typhoon_setvol(typhoon, ctrl->value);
297 return (0);
298 }
299 return -EINVAL;
300 }
301
302 default:
303 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
304 typhoon_do_ioctl);
244 } 305 }
245} 306}
246 307
@@ -271,7 +332,7 @@ static struct video_device typhoon_radio =
271 .owner = THIS_MODULE, 332 .owner = THIS_MODULE,
272 .name = "Typhoon Radio", 333 .name = "Typhoon Radio",
273 .type = VID_TYPE_TUNER, 334 .type = VID_TYPE_TUNER,
274 .hardware = VID_HARDWARE_TYPHOON, 335 .hardware = 0,
275 .fops = &typhoon_fops, 336 .fops = &typhoon_fops,
276}; 337};
277 338
diff --git a/drivers/media/radio/radio-zoltrix.c b/drivers/media/radio/radio-zoltrix.c
index 59b86a6b4b0e..671fe1b1e5bc 100644
--- a/drivers/media/radio/radio-zoltrix.c
+++ b/drivers/media/radio/radio-zoltrix.c
@@ -24,6 +24,9 @@
24 * - Added unmute function 24 * - Added unmute function
25 * - Reworked ioctl functions 25 * - Reworked ioctl functions
26 * 2002-07-15 - Fix Stereo typo 26 * 2002-07-15 - Fix Stereo typo
27 *
28 * 2006-07-24 - Converted to V4L2 API
29 * by Mauro Carvalho Chehab <mchehab@infradead.org>
27 */ 30 */
28 31
29#include <linux/module.h> /* Modules */ 32#include <linux/module.h> /* Modules */
@@ -32,9 +35,30 @@
32#include <linux/delay.h> /* udelay, msleep */ 35#include <linux/delay.h> /* udelay, msleep */
33#include <asm/io.h> /* outb, outb_p */ 36#include <asm/io.h> /* outb, outb_p */
34#include <asm/uaccess.h> /* copy to/from user */ 37#include <asm/uaccess.h> /* copy to/from user */
35#include <linux/videodev.h> /* kernel radio structs */ 38#include <linux/videodev2.h> /* kernel radio structs */
36#include <media/v4l2-common.h> 39#include <media/v4l2-common.h>
37#include <linux/config.h> /* CONFIG_RADIO_ZOLTRIX_PORT */ 40
41#include <linux/version.h> /* for KERNEL_VERSION MACRO */
42#define RADIO_VERSION KERNEL_VERSION(0,0,2)
43
44static struct v4l2_queryctrl radio_qctrl[] = {
45 {
46 .id = V4L2_CID_AUDIO_MUTE,
47 .name = "Mute",
48 .minimum = 0,
49 .maximum = 1,
50 .default_value = 1,
51 .type = V4L2_CTRL_TYPE_BOOLEAN,
52 },{
53 .id = V4L2_CID_AUDIO_VOLUME,
54 .name = "Volume",
55 .minimum = 0,
56 .maximum = 65535,
57 .step = 4096,
58 .default_value = 0xff,
59 .type = V4L2_CTRL_TYPE_INTEGER,
60 }
61};
38 62
39#ifndef CONFIG_RADIO_ZOLTRIX_PORT 63#ifndef CONFIG_RADIO_ZOLTRIX_PORT
40#define CONFIG_RADIO_ZOLTRIX_PORT -1 64#define CONFIG_RADIO_ZOLTRIX_PORT -1
@@ -213,78 +237,116 @@ static int zol_do_ioctl(struct inode *inode, struct file *file,
213 struct zol_device *zol = dev->priv; 237 struct zol_device *zol = dev->priv;
214 238
215 switch (cmd) { 239 switch (cmd) {
216 case VIDIOCGCAP: 240 case VIDIOC_QUERYCAP:
217 { 241 {
218 struct video_capability *v = arg; 242 struct v4l2_capability *v = arg;
219
220 memset(v,0,sizeof(*v)); 243 memset(v,0,sizeof(*v));
221 v->type = VID_TYPE_TUNER; 244 strlcpy(v->driver, "radio-zoltrix", sizeof (v->driver));
222 v->channels = 1 + zol->stereo; 245 strlcpy(v->card, "Zoltrix Radio", sizeof (v->card));
223 v->audios = 1; 246 sprintf(v->bus_info,"ISA");
224 strcpy(v->name, "Zoltrix Radio"); 247 v->version = RADIO_VERSION;
248 v->capabilities = V4L2_CAP_TUNER;
249
225 return 0; 250 return 0;
226 } 251 }
227 case VIDIOCGTUNER: 252 case VIDIOC_G_TUNER:
228 { 253 {
229 struct video_tuner *v = arg; 254 struct v4l2_tuner *v = arg;
230 if (v->tuner) 255
256 if (v->index > 0)
231 return -EINVAL; 257 return -EINVAL;
258
259 memset(v,0,sizeof(*v));
232 strcpy(v->name, "FM"); 260 strcpy(v->name, "FM");
233 v->rangelow = (int) (88.0 * 16000); 261 v->type = V4L2_TUNER_RADIO;
234 v->rangehigh = (int) (108.0 * 16000); 262
235 v->flags = zol_is_stereo(zol) 263 v->rangelow=(88*16000);
236 ? VIDEO_TUNER_STEREO_ON : 0; 264 v->rangehigh=(108*16000);
237 v->flags |= VIDEO_TUNER_LOW; 265 v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
238 v->mode = VIDEO_MODE_AUTO; 266 v->capability=V4L2_TUNER_CAP_LOW;
239 v->signal = 0xFFFF * zol_getsigstr(zol); 267 if(zol_is_stereo(zol))
268 v->audmode = V4L2_TUNER_MODE_STEREO;
269 else
270 v->audmode = V4L2_TUNER_MODE_MONO;
271 v->signal=0xFFFF*zol_getsigstr(zol);
272
240 return 0; 273 return 0;
241 } 274 }
242 case VIDIOCSTUNER: 275 case VIDIOC_S_TUNER:
243 { 276 {
244 struct video_tuner *v = arg; 277 struct v4l2_tuner *v = arg;
245 if (v->tuner != 0) 278
279 if (v->index > 0)
246 return -EINVAL; 280 return -EINVAL;
247 /* Only 1 tuner so no setting needed ! */ 281
248 return 0; 282 return 0;
249 } 283 }
250 case VIDIOCGFREQ: 284 case VIDIOC_S_FREQUENCY:
251 {
252 unsigned long *freq = arg;
253 *freq = zol->curfreq;
254 return 0;
255 }
256 case VIDIOCSFREQ:
257 {
258 unsigned long *freq = arg;
259 zol->curfreq = *freq;
260 zol_setfreq(zol, zol->curfreq);
261 return 0;
262 }
263 case VIDIOCGAUDIO:
264 { 285 {
265 struct video_audio *v = arg; 286 struct v4l2_frequency *f = arg;
266 memset(v, 0, sizeof(*v)); 287
267 v->flags |= VIDEO_AUDIO_MUTABLE | VIDEO_AUDIO_VOLUME; 288 zol->curfreq = f->frequency;
268 v->mode |= zol_is_stereo(zol) 289 zol_setfreq(zol, zol->curfreq);
269 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
270 v->volume = zol->curvol * 4096;
271 v->step = 4096;
272 strcpy(v->name, "Zoltrix Radio");
273 return 0; 290 return 0;
274 } 291 }
275 case VIDIOCSAUDIO: 292 case VIDIOC_G_FREQUENCY:
276 { 293 {
277 struct video_audio *v = arg; 294 struct v4l2_frequency *f = arg;
278 if (v->audio)
279 return -EINVAL;
280 295
281 if (v->flags & VIDEO_AUDIO_MUTE) 296 f->type = V4L2_TUNER_RADIO;
282 zol_mute(zol); 297 f->frequency = zol->curfreq;
283 else {
284 zol_unmute(zol);
285 zol_setvol(zol, v->volume / 4096);
286 }
287 298
299 return 0;
300 }
301 case VIDIOC_QUERYCTRL:
302 {
303 struct v4l2_queryctrl *qc = arg;
304 int i;
305
306 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
307 if (qc->id && qc->id == radio_qctrl[i].id) {
308 memcpy(qc, &(radio_qctrl[i]),
309 sizeof(*qc));
310 return (0);
311 }
312 }
313 return -EINVAL;
314 }
315 case VIDIOC_G_CTRL:
316 {
317 struct v4l2_control *ctrl= arg;
318
319 switch (ctrl->id) {
320 case V4L2_CID_AUDIO_MUTE:
321 ctrl->value=zol->muted;
322 return (0);
323 case V4L2_CID_AUDIO_VOLUME:
324 ctrl->value=zol->curvol * 4096;
325 return (0);
326 }
327 return -EINVAL;
328 }
329 case VIDIOC_S_CTRL:
330 {
331 struct v4l2_control *ctrl= arg;
332
333 switch (ctrl->id) {
334 case V4L2_CID_AUDIO_MUTE:
335 if (ctrl->value) {
336 zol_mute(zol);
337 } else {
338 zol_unmute(zol);
339 zol_setvol(zol,zol->curvol);
340 }
341 return (0);
342 case V4L2_CID_AUDIO_VOLUME:
343 zol_setvol(zol,ctrl->value/4096);
344 return (0);
345 }
346 zol->stereo = 1;
347 zol_setfreq(zol, zol->curfreq);
348#if 0
349/* FIXME: Implement stereo/mono switch on V4L2 */
288 if (v->mode & VIDEO_SOUND_STEREO) { 350 if (v->mode & VIDEO_SOUND_STEREO) {
289 zol->stereo = 1; 351 zol->stereo = 1;
290 zol_setfreq(zol, zol->curfreq); 352 zol_setfreq(zol, zol->curfreq);
@@ -293,10 +355,13 @@ static int zol_do_ioctl(struct inode *inode, struct file *file,
293 zol->stereo = 0; 355 zol->stereo = 0;
294 zol_setfreq(zol, zol->curfreq); 356 zol_setfreq(zol, zol->curfreq);
295 } 357 }
296 return 0; 358#endif
359 return -EINVAL;
297 } 360 }
298 default: 361
299 return -ENOIOCTLCMD; 362 default:
363 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
364 zol_do_ioctl);
300 } 365 }
301} 366}
302 367
@@ -323,7 +388,7 @@ static struct video_device zoltrix_radio =
323 .owner = THIS_MODULE, 388 .owner = THIS_MODULE,
324 .name = "Zoltrix Radio Plus", 389 .name = "Zoltrix Radio Plus",
325 .type = VID_TYPE_TUNER, 390 .type = VID_TYPE_TUNER,
326 .hardware = VID_HARDWARE_ZOLTRIX, 391 .hardware = 0,
327 .fops = &zoltrix_fops, 392 .fops = &zoltrix_fops,
328}; 393};
329 394
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 94d078b77bab..d1183c939221 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -16,6 +16,320 @@ config VIDEO_ADV_DEBUG
16 V4L devices. 16 V4L devices.
17 In doubt, say N. 17 In doubt, say N.
18 18
19config VIDEO_HELPER_CHIPS_AUTO
20 bool "Autoselect pertinent encoders/decoders and other helper chips"
21 default y
22 ---help---
23 Most video cards may require additional modules to encode or
24 decode audio/video standards. This option will autoselect
25 all pertinent modules to each selected video module.
26
27 Unselect this only if you know exaclty what you are doing, since
28 it may break support on some boards.
29
30 In doubt, say Y.
31
32#
33# Encoder / Decoder module configuration
34#
35
36menu "Encoders/decoders and other helper chips"
37 depends on VIDEO_DEV && !VIDEO_HELPER_CHIPS_AUTO
38
39comment "Audio Decoders"
40
41config VIDEO_TVAUDIO
42 tristate "Simple audio decoder chips"
43 depends on VIDEO_V4L1 && I2C
44 ---help---
45 Support for several audio decoder chips found on some bt8xx boards:
46 Philips: tda9840, tda9873h, tda9874h/a, tda9850, tda985x, tea6300,
47 tea6320, tea6420, tda8425, ta8874z.
48 Microchip: pic16c54 based design on ProVideo PV951 board.
49
50 To compile this driver as a module, choose M here: the
51 module will be called tvaudio.
52
53config VIDEO_TDA7432
54 tristate "Philips TDA7432 audio processor chip"
55 depends on VIDEO_V4L1 && I2C
56 ---help---
57 Support for tda7432 audio decoder chip found on some bt8xx boards.
58
59 To compile this driver as a module, choose M here: the
60 module will be called tda7432.
61
62config VIDEO_TDA9840
63 tristate "Philips TDA9840 audio processor chip"
64 depends on VIDEO_DEV && I2C
65 ---help---
66 Support for tda9840 audio decoder chip found on some Zoran boards.
67
68 To compile this driver as a module, choose M here: the
69 module will be called tda9840.
70
71config VIDEO_TDA9875
72 tristate "Philips TDA9875 audio processor chip"
73 depends on VIDEO_V4L1 && I2C
74 ---help---
75 Support for tda9875 audio decoder chip found on some bt8xx boards.
76
77 To compile this driver as a module, choose M here: the
78 module will be called tda9875.
79
80config VIDEO_TEA6415C
81 tristate "Philips TEA6415C audio processor chip"
82 depends on VIDEO_DEV && I2C
83 ---help---
84 Support for tea6415c audio decoder chip found on some bt8xx boards.
85
86 To compile this driver as a module, choose M here: the
87 module will be called tea6415c.
88
89config VIDEO_TEA6420
90 tristate "Philips TEA6420 audio processor chip"
91 depends on VIDEO_DEV && I2C
92 ---help---
93 Support for tea6420 audio decoder chip found on some bt8xx boards.
94
95 To compile this driver as a module, choose M here: the
96 module will be called tea6420.
97
98config VIDEO_MSP3400
99 tristate "Micronas MSP34xx audio decoders"
100 depends on VIDEO_V4L2 && I2C
101 ---help---
102 Support for the Micronas MSP34xx series of audio decoders.
103
104 To compile this driver as a module, choose M here: the
105 module will be called msp3400.
106
107config VIDEO_CS53L32A
108 tristate "Cirrus Logic CS53L32A audio ADC"
109 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
110 ---help---
111 Support for the Cirrus Logic CS53L32A low voltage
112 stereo A/D converter.
113
114 To compile this driver as a module, choose M here: the
115 module will be called cs53l32a.
116
117config VIDEO_TLV320AIC23B
118 tristate "Texas Instruments TLV320AIC23B audio codec"
119 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
120 ---help---
121 Support for the Texas Instruments TLV320AIC23B audio codec.
122
123 To compile this driver as a module, choose M here: the
124 module will be called tlv320aic23b.
125
126config VIDEO_WM8775
127 tristate "Wolfson Microelectronics WM8775 audio ADC with input mixer"
128 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
129 ---help---
130 Support for the Wolfson Microelectronics WM8775 high
131 performance stereo A/D Converter with a 4 channel input mixer.
132
133 To compile this driver as a module, choose M here: the
134 module will be called wm8775.
135
136config VIDEO_WM8739
137 tristate "Wolfson Microelectronics WM8739 stereo audio ADC"
138 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
139 ---help---
140 Support for the Wolfson Microelectronics WM8739
141 stereo A/D Converter.
142
143 To compile this driver as a module, choose M here: the
144 module will be called wm8739.
145
146comment "MPEG video encoders"
147
148config VIDEO_CX2341X
149 tristate "Conexant CX2341x MPEG encoders"
150 depends on VIDEO_V4L2 && EXPERIMENTAL
151 ---help---
152 Support for the Conexant CX23416 MPEG encoders
153 and CX23415 MPEG encoder/decoders.
154
155 This module currently supports the encoding functions only.
156
157 To compile this driver as a module, choose M here: the
158 module will be called cx2341x.
159
160source "drivers/media/video/cx25840/Kconfig"
161
162comment "Video encoders"
163
164config VIDEO_SAA7127
165 tristate "Philips SAA7127/9 digital video encoders"
166 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
167 ---help---
168 Support for the Philips SAA7127/9 digital video encoders.
169
170 To compile this driver as a module, choose M here: the
171 module will be called saa7127.
172
173config VIDEO_SAA7185
174 tristate "Philips SAA7185 video encoder"
175 depends on VIDEO_V4L1 && I2C
176 ---help---
177 Support for the Philips SAA7185 video encoder.
178
179 To compile this driver as a module, choose M here: the
180 module will be called saa7185.
181
182config VIDEO_ADV7170
183 tristate "Analog Devices ADV7170 video encoder driver"
184 depends on VIDEO_V4L1 && I2C
185 ---help---
186 Support for the Analog Devices ADV7170 video encoder driver
187
188 To compile this driver as a module, choose M here: the
189 module will be called adv7170.
190
191config VIDEO_ADV7175
192 tristate "Analog Devices ADV7175 video encoder driver"
193 depends on VIDEO_V4L1 && I2C
194 ---help---
195 Support for the Analog Devices ADV7175 video encoder driver
196
197 To compile this driver as a module, choose M here: the
198 module will be called adv7175.
199
200comment "Video decoders"
201
202config VIDEO_BT819
203 tristate "BT819A VideoStream Decoder"
204 depends on VIDEO_V4L1 && I2C
205 ---help---
206 Support for BT819A video decoder.
207
208 To compile this driver as a module, choose M here: the
209 module will be called bt819.
210
211config VIDEO_BT856
212 tristate "BT856 VideoStream Decoder"
213 depends on VIDEO_V4L1 && I2C
214 ---help---
215 Support for BT856 video decoder.
216
217 To compile this driver as a module, choose M here: the
218 module will be called bt856.
219
220config VIDEO_BT866
221 tristate "BT866 VideoStream Decoder"
222 depends on VIDEO_V4L1 && I2C
223 ---help---
224 Support for BT866 video decoder.
225
226 To compile this driver as a module, choose M here: the
227 module will be called bt866.
228
229config VIDEO_KS0127
230 tristate "KS0127 video decoder"
231 depends on VIDEO_V4L1 && I2C
232 ---help---
233 Support for KS0127 video decoder.
234
235 This chip is used on AverMedia AVS6EYES Zoran-based MJPEG
236 cards.
237
238 To compile this driver as a module, choose M here: the
239 module will be called ks0127.
240
241config VIDEO_SAA7110
242 tristate "Philips SAA7110 video decoder"
243 depends on VIDEO_V4L1
244 ---help---
245 Support for the Philips SAA7110 video decoders.
246
247 To compile this driver as a module, choose M here: the
248 module will be called saa7110.
249
250config VIDEO_SAA7111
251 tristate "Philips SAA7111 video decoder"
252 depends on VIDEO_V4L1 && I2C
253 ---help---
254 Support for the Philips SAA711 video decoder.
255
256 To compile this driver as a module, choose M here: the
257 module will be called saa7111.
258
259config VIDEO_SAA7114
260 tristate "Philips SAA7114 video decoder"
261 depends on VIDEO_V4L1 && I2C
262 ---help---
263 Support for the Philips SAA7114 video decoder. This driver
264 is used only on Zoran driver and should be moved soon to
265 SAA711x module.
266
267 To compile this driver as a module, choose M here: the
268 module will be called saa7114.
269
270config VIDEO_SAA711X
271 tristate "Philips SAA7113/4/5 video decoders"
272 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
273 ---help---
274 Support for the Philips SAA7113/4/5 video decoders.
275
276 To compile this driver as a module, choose M here: the
277 module will be called saa7115.
278
279config VIDEO_SAA7191
280 tristate "Philips SAA7191 video decoder"
281 depends on VIDEO_V4L1 && I2C
282 ---help---
283 Support for the Philips SAA7191 video decoder.
284
285 To compile this driver as a module, choose M here: the
286 module will be called saa7191.
287
288config VIDEO_TVP5150
289 tristate "Texas Instruments TVP5150 video decoder"
290 depends on VIDEO_V4L2 && I2C
291 ---help---
292 Support for the Texas Instruments TVP5150 video decoder.
293
294 To compile this driver as a module, choose M here: the
295 module will be called tvp5150.
296
297config VIDEO_VPX3220
298 tristate "vpx3220a, vpx3216b & vpx3214c video decoder driver"
299 depends on VIDEO_V4L1 && I2C
300 ---help---
301 Support for VPX322x video decoders.
302
303 To compile this driver as a module, choose M here: the
304 module will be called vpx3220.
305
306comment "Video improvement chips"
307
308config VIDEO_UPD64031A
309 tristate "NEC Electronics uPD64031A Ghost Reduction"
310 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
311 ---help---
312 Support for the NEC Electronics uPD64031A Ghost Reduction
313 video chip. It is most often found in NTSC TV cards made for
314 Japan and is used to reduce the 'ghosting' effect that can
315 be present in analog TV broadcasts.
316
317 To compile this driver as a module, choose M here: the
318 module will be called upd64031a.
319
320config VIDEO_UPD64083
321 tristate "NEC Electronics uPD64083 3-Dimensional Y/C separation"
322 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
323 ---help---
324 Support for the NEC Electronics uPD64083 3-Dimensional Y/C
325 separation video chip. It is used to improve the quality of
326 the colors of a composite signal.
327
328 To compile this driver as a module, choose M here: the
329 module will be called upd64083.
330
331endmenu # encoder / decoder chips
332
19config VIDEO_VIVI 333config VIDEO_VIVI
20 tristate "Virtual Video Driver" 334 tristate "Virtual Video Driver"
21 depends on VIDEO_V4L2 && !SPARC32 && !SPARC64 335 depends on VIDEO_V4L2 && !SPARC32 && !SPARC64
@@ -135,7 +449,7 @@ source "drivers/media/video/cpia2/Kconfig"
135 449
136config VIDEO_SAA5246A 450config VIDEO_SAA5246A
137 tristate "SAA5246A, SAA5281 Teletext processor" 451 tristate "SAA5246A, SAA5281 Teletext processor"
138 depends on I2C && VIDEO_V4L1 452 depends on I2C && VIDEO_V4L2
139 help 453 help
140 Support for I2C bus based teletext using the SAA5246A or SAA5281 454 Support for I2C bus based teletext using the SAA5246A or SAA5281
141 chip. Useful only if you live in Europe. 455 chip. Useful only if you live in Europe.
@@ -145,7 +459,7 @@ config VIDEO_SAA5246A
145 459
146config VIDEO_SAA5249 460config VIDEO_SAA5249
147 tristate "SAA5249 Teletext processor" 461 tristate "SAA5249 Teletext processor"
148 depends on VIDEO_DEV && I2C && VIDEO_V4L1 462 depends on VIDEO_DEV && I2C && VIDEO_V4L2
149 help 463 help
150 Support for I2C bus based teletext using the SAA5249 chip. At the 464 Support for I2C bus based teletext using the SAA5249 chip. At the
151 moment this is only useful on some European WinTV cards. 465 moment this is only useful on some European WinTV cards.
@@ -162,8 +476,9 @@ config TUNER_3036
162 476
163config VIDEO_VINO 477config VIDEO_VINO
164 tristate "SGI Vino Video For Linux (EXPERIMENTAL)" 478 tristate "SGI Vino Video For Linux (EXPERIMENTAL)"
165 depends on I2C && SGI_IP22 && EXPERIMENTAL && VIDEO_V4L1 479 depends on I2C && SGI_IP22 && EXPERIMENTAL && VIDEO_V4L2
166 select I2C_ALGO_SGI 480 select I2C_ALGO_SGI
481 select VIDEO_SAA7191 if VIDEO_HELPER_CHIPS_AUTO
167 help 482 help
168 Say Y here to build in support for the Vino video input system found 483 Say Y here to build in support for the Vino video input system found
169 on SGI Indy machines. 484 on SGI Indy machines.
@@ -176,6 +491,9 @@ config VIDEO_STRADIS
176 driver for PCI. There is a product page at 491 driver for PCI. There is a product page at
177 <http://www.stradis.com/>. 492 <http://www.stradis.com/>.
178 493
494config VIDEO_ZORAN_ZR36060
495 tristate
496
179config VIDEO_ZORAN 497config VIDEO_ZORAN
180 tristate "Zoran ZR36057/36067 Video For Linux" 498 tristate "Zoran ZR36057/36067 Video For Linux"
181 depends on PCI && I2C_ALGOBIT && VIDEO_V4L1 && !PPC64 499 depends on PCI && I2C_ALGOBIT && VIDEO_V4L1 && !PPC64
@@ -192,12 +510,18 @@ config VIDEO_ZORAN
192config VIDEO_ZORAN_BUZ 510config VIDEO_ZORAN_BUZ
193 tristate "Iomega Buz support" 511 tristate "Iomega Buz support"
194 depends on VIDEO_ZORAN 512 depends on VIDEO_ZORAN
513 select VIDEO_SAA7111 if VIDEO_HELPER_CHIPS_AUTO
514 select VIDEO_SAA7185 if VIDEO_HELPER_CHIPS_AUTO
515 select VIDEO_ZORAN_ZR36060
195 help 516 help
196 Support for the Iomega Buz MJPEG capture/playback card. 517 Support for the Iomega Buz MJPEG capture/playback card.
197 518
198config VIDEO_ZORAN_DC10 519config VIDEO_ZORAN_DC10
199 tristate "Pinnacle/Miro DC10(+) support" 520 tristate "Pinnacle/Miro DC10(+) support"
200 depends on VIDEO_ZORAN 521 depends on VIDEO_ZORAN
522 select VIDEO_SAA7110
523 select VIDEO_ADV7175 if VIDEO_HELPER_CHIPS_AUTO
524 select VIDEO_ZORAN_ZR36060
201 help 525 help
202 Support for the Pinnacle/Miro DC10(+) MJPEG capture/playback 526 Support for the Pinnacle/Miro DC10(+) MJPEG capture/playback
203 card. 527 card.
@@ -205,6 +529,8 @@ config VIDEO_ZORAN_DC10
205config VIDEO_ZORAN_DC30 529config VIDEO_ZORAN_DC30
206 tristate "Pinnacle/Miro DC30(+) support" 530 tristate "Pinnacle/Miro DC30(+) support"
207 depends on VIDEO_ZORAN 531 depends on VIDEO_ZORAN
532 select VIDEO_ADV7175 if VIDEO_HELPER_CHIPS_AUTO
533 select VIDEO_VPX3220 if VIDEO_HELPER_CHIPS_AUTO
208 help 534 help
209 Support for the Pinnacle/Miro DC30(+) MJPEG capture/playback 535 Support for the Pinnacle/Miro DC30(+) MJPEG capture/playback
210 card. This also supports really old DC10 cards based on the 536 card. This also supports really old DC10 cards based on the
@@ -213,6 +539,9 @@ config VIDEO_ZORAN_DC30
213config VIDEO_ZORAN_LML33 539config VIDEO_ZORAN_LML33
214 tristate "Linux Media Labs LML33 support" 540 tristate "Linux Media Labs LML33 support"
215 depends on VIDEO_ZORAN 541 depends on VIDEO_ZORAN
542 select VIDEO_BT819 if VIDEO_HELPER_CHIPS_AUTO
543 select VIDEO_BT856 if VIDEO_HELPER_CHIPS_AUTO
544 select VIDEO_ZORAN_ZR36060
216 help 545 help
217 Support for the Linux Media Labs LML33 MJPEG capture/playback 546 Support for the Linux Media Labs LML33 MJPEG capture/playback
218 card. 547 card.
@@ -220,6 +549,9 @@ config VIDEO_ZORAN_LML33
220config VIDEO_ZORAN_LML33R10 549config VIDEO_ZORAN_LML33R10
221 tristate "Linux Media Labs LML33R10 support" 550 tristate "Linux Media Labs LML33R10 support"
222 depends on VIDEO_ZORAN 551 depends on VIDEO_ZORAN
552 select VIDEO_SAA7114 if VIDEO_HELPER_CHIPS_AUTO
553 select VIDEO_ADV7170 if VIDEO_HELPER_CHIPS_AUTO
554 select VIDEO_ZORAN_ZR36060
223 help 555 help
224 support for the Linux Media Labs LML33R10 MJPEG capture/playback 556 support for the Linux Media Labs LML33R10 MJPEG capture/playback
225 card. 557 card.
@@ -227,6 +559,9 @@ config VIDEO_ZORAN_LML33R10
227config VIDEO_ZORAN_AVS6EYES 559config VIDEO_ZORAN_AVS6EYES
228 tristate "AverMedia 6 Eyes support (EXPERIMENTAL)" 560 tristate "AverMedia 6 Eyes support (EXPERIMENTAL)"
229 depends on VIDEO_ZORAN && EXPERIMENTAL && VIDEO_V4L1 561 depends on VIDEO_ZORAN && EXPERIMENTAL && VIDEO_V4L1
562 select VIDEO_BT856 if VIDEO_HELPER_CHIPS_AUTO
563 select VIDEO_KS0127 if VIDEO_HELPER_CHIPS_AUTO
564 select VIDEO_ZORAN_ZR36060
230 help 565 help
231 Support for the AverMedia 6 Eyes video surveillance card. 566 Support for the AverMedia 6 Eyes video surveillance card.
232 567
@@ -263,6 +598,10 @@ config VIDEO_MXB
263 depends on PCI && VIDEO_V4L1 && I2C 598 depends on PCI && VIDEO_V4L1 && I2C
264 select VIDEO_SAA7146_VV 599 select VIDEO_SAA7146_VV
265 select VIDEO_TUNER 600 select VIDEO_TUNER
601 select VIDEO_SAA7111 if VIDEO_HELPER_CHIPS_AUTO
602 select VIDEO_TDA9840 if VIDEO_HELPER_CHIPS_AUTO
603 select VIDEO_TEA6415C if VIDEO_HELPER_CHIPS_AUTO
604 select VIDEO_TEA6420 if VIDEO_HELPER_CHIPS_AUTO
266 ---help--- 605 ---help---
267 This is a video4linux driver for the 'Multimedia eXtension Board' 606 This is a video4linux driver for the 'Multimedia eXtension Board'
268 TV card by Siemens-Nixdorf. 607 TV card by Siemens-Nixdorf.
@@ -274,7 +613,7 @@ config VIDEO_DPC
274 tristate "Philips-Semiconductors 'dpc7146 demonstration board'" 613 tristate "Philips-Semiconductors 'dpc7146 demonstration board'"
275 depends on PCI && VIDEO_V4L1 && I2C 614 depends on PCI && VIDEO_V4L1 && I2C
276 select VIDEO_SAA7146_VV 615 select VIDEO_SAA7146_VV
277 select VIDEO_V4L2 616 select VIDEO_SAA7111 if VIDEO_HELPER_CHIPS_AUTO
278 ---help--- 617 ---help---
279 This is a video4linux driver for the 'dpc7146 demonstration 618 This is a video4linux driver for the 'dpc7146 demonstration
280 board' by Philips-Semiconductors. It's the reference design 619 board' by Philips-Semiconductors. It's the reference design
@@ -287,9 +626,8 @@ config VIDEO_DPC
287 626
288config VIDEO_HEXIUM_ORION 627config VIDEO_HEXIUM_ORION
289 tristate "Hexium HV-PCI6 and Orion frame grabber" 628 tristate "Hexium HV-PCI6 and Orion frame grabber"
290 depends on PCI && VIDEO_V4L1 && I2C 629 depends on PCI && VIDEO_V4L2 && I2C
291 select VIDEO_SAA7146_VV 630 select VIDEO_SAA7146_VV
292 select VIDEO_V4L2
293 ---help--- 631 ---help---
294 This is a video4linux driver for the Hexium HV-PCI6 and 632 This is a video4linux driver for the Hexium HV-PCI6 and
295 Orion frame grabber cards by Hexium. 633 Orion frame grabber cards by Hexium.
@@ -299,9 +637,8 @@ config VIDEO_HEXIUM_ORION
299 637
300config VIDEO_HEXIUM_GEMINI 638config VIDEO_HEXIUM_GEMINI
301 tristate "Hexium Gemini frame grabber" 639 tristate "Hexium Gemini frame grabber"
302 depends on PCI && VIDEO_V4L1 && I2C 640 depends on PCI && VIDEO_V4L2 && I2C
303 select VIDEO_SAA7146_VV 641 select VIDEO_SAA7146_VV
304 select VIDEO_V4L2
305 ---help--- 642 ---help---
306 This is a video4linux driver for the Hexium Gemini frame 643 This is a video4linux driver for the Hexium Gemini frame
307 grabber card by Hexium. Please note that the Gemini Dual 644 grabber card by Hexium. Please note that the Gemini Dual
@@ -320,123 +657,16 @@ config VIDEO_M32R_AR
320 camera module. 657 camera module.
321 658
322config VIDEO_M32R_AR_M64278 659config VIDEO_M32R_AR_M64278
323 tristate "Use Colour AR module M64278(VGA)" 660 tristate "AR device with color module M64278(VGA)"
324 depends on VIDEO_M32R_AR && PLAT_M32700UT 661 depends on PLAT_M32700UT
325 ---help--- 662 select VIDEO_M32R_AR
326 Say Y here to use the Renesas M64278E-800 camera module,
327 which supports VGA(640x480 pixcels) size of images.
328
329#
330# Encoder / Decoder module configuration
331#
332
333menu "Encoders and Decoders"
334 depends on VIDEO_DEV
335
336config VIDEO_MSP3400
337 tristate "Micronas MSP34xx audio decoders"
338 depends on VIDEO_DEV && I2C
339 ---help---
340 Support for the Micronas MSP34xx series of audio decoders.
341
342 To compile this driver as a module, choose M here: the
343 module will be called msp3400.
344
345config VIDEO_CS53L32A
346 tristate "Cirrus Logic CS53L32A audio ADC"
347 depends on VIDEO_DEV && I2C && EXPERIMENTAL
348 ---help---
349 Support for the Cirrus Logic CS53L32A low voltage
350 stereo A/D converter.
351
352 To compile this driver as a module, choose M here: the
353 module will be called cs53l32a.
354
355config VIDEO_TLV320AIC23B
356 tristate "Texas Instruments TLV320AIC23B audio codec"
357 depends on VIDEO_DEV && I2C && EXPERIMENTAL
358 ---help--- 663 ---help---
359 Support for the Texas Instruments TLV320AIC23B audio codec. 664 This is a video4linux driver for the Renesas AR (Artificial
360 665 Retina) with M64278E-800 camera module.
361 To compile this driver as a module, choose M here: the 666 This module supports VGA(640x480 pixels) resolutions.
362 module will be called tlv320aic23b.
363
364config VIDEO_WM8775
365 tristate "Wolfson Microelectronics WM8775 audio ADC with input mixer"
366 depends on VIDEO_DEV && I2C && EXPERIMENTAL
367 ---help---
368 Support for the Wolfson Microelectronics WM8775 high
369 performance stereo A/D Converter with a 4 channel input mixer.
370 667
371 To compile this driver as a module, choose M here: the 668 To compile this driver as a module, choose M here: the
372 module will be called wm8775. 669 module will be called arv.
373
374config VIDEO_WM8739
375 tristate "Wolfson Microelectronics WM8739 stereo audio ADC"
376 depends on VIDEO_DEV && I2C && EXPERIMENTAL
377 ---help---
378 Support for the Wolfson Microelectronics WM8739
379 stereo A/D Converter.
380
381 To compile this driver as a module, choose M here: the
382 module will be called wm8739.
383
384config VIDEO_CX2341X
385 tristate "Conexant CX2341x MPEG encoders"
386 depends on VIDEO_V4L2 && EXPERIMENTAL
387 ---help---
388 Support for the Conexant CX23416 MPEG encoders
389 and CX23415 MPEG encoder/decoders.
390
391 This module currently supports the encoding functions only.
392
393 To compile this driver as a module, choose M here: the
394 module will be called cx2341x.
395
396source "drivers/media/video/cx25840/Kconfig"
397
398config VIDEO_SAA711X
399 tristate "Philips SAA7113/4/5 video decoders"
400 depends on VIDEO_DEV && I2C && EXPERIMENTAL
401 ---help---
402 Support for the Philips SAA7113/4/5 video decoders.
403
404 To compile this driver as a module, choose M here: the
405 module will be called saa7115.
406
407config VIDEO_SAA7127
408 tristate "Philips SAA7127/9 digital video encoders"
409 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
410 ---help---
411 Support for the Philips SAA7127/9 digital video encoders.
412
413 To compile this driver as a module, choose M here: the
414 module will be called saa7127.
415
416config VIDEO_UPD64031A
417 tristate "NEC Electronics uPD64031A Ghost Reduction"
418 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
419 ---help---
420 Support for the NEC Electronics uPD64031A Ghost Reduction
421 video chip. It is most often found in NTSC TV cards made for
422 Japan and is used to reduce the 'ghosting' effect that can
423 be present in analog TV broadcasts.
424
425 To compile this driver as a module, choose M here: the
426 module will be called upd64031a.
427
428config VIDEO_UPD64083
429 tristate "NEC Electronics uPD64083 3-Dimensional Y/C separation"
430 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
431 ---help---
432 Support for the NEC Electronics uPD64083 3-Dimensional Y/C
433 separation video chip. It is used to improve the quality of
434 the colors of a composite signal.
435
436 To compile this driver as a module, choose M here: the
437 module will be called upd64083.
438
439endmenu # encoder / decoder chips
440 670
441# 671#
442# USB Multimedia device configuration 672# USB Multimedia device configuration
@@ -445,8 +675,6 @@ endmenu # encoder / decoder chips
445menu "V4L USB devices" 675menu "V4L USB devices"
446 depends on USB && VIDEO_DEV 676 depends on USB && VIDEO_DEV
447 677
448source "drivers/media/video/pvrusb2/Kconfig"
449
450source "drivers/media/video/em28xx/Kconfig" 678source "drivers/media/video/em28xx/Kconfig"
451 679
452source "drivers/media/video/usbvideo/Kconfig" 680source "drivers/media/video/usbvideo/Kconfig"
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index e82e511f2a72..af57abce8a6e 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -17,7 +17,10 @@ ifeq ($(CONFIG_VIDEO_V4L1_COMPAT),y)
17endif 17endif
18 18
19obj-$(CONFIG_VIDEO_BT848) += bt8xx/ 19obj-$(CONFIG_VIDEO_BT848) += bt8xx/
20obj-$(CONFIG_VIDEO_BT848) += tvaudio.o tda7432.o tda9875.o ir-kbd-i2c.o 20obj-$(CONFIG_VIDEO_BT848) += ir-kbd-i2c.o
21obj-$(CONFIG_VIDEO_TVAUDIO) += tvaudio.o
22obj-$(CONFIG_VIDEO_TDA7432) += tda7432.o
23obj-$(CONFIG_VIDEO_TDA9875) += tda9875.o
21obj-$(CONFIG_SOUND_TVMIXER) += tvmixer.o 24obj-$(CONFIG_SOUND_TVMIXER) += tvmixer.o
22 25
23obj-$(CONFIG_VIDEO_ZR36120) += zoran.o 26obj-$(CONFIG_VIDEO_ZR36120) += zoran.o
@@ -27,17 +30,32 @@ obj-$(CONFIG_VIDEO_SAA5249) += saa5249.o
27obj-$(CONFIG_VIDEO_CQCAM) += c-qcam.o 30obj-$(CONFIG_VIDEO_CQCAM) += c-qcam.o
28obj-$(CONFIG_VIDEO_BWQCAM) += bw-qcam.o 31obj-$(CONFIG_VIDEO_BWQCAM) += bw-qcam.o
29obj-$(CONFIG_VIDEO_W9966) += w9966.o 32obj-$(CONFIG_VIDEO_W9966) += w9966.o
30obj-$(CONFIG_VIDEO_ZORAN_BUZ) += saa7111.o saa7185.o zr36060.o 33
31obj-$(CONFIG_VIDEO_ZORAN_DC10) += saa7110.o adv7175.o zr36060.o 34obj-$(CONFIG_VIDEO_TDA9840) += tda9840.o
32obj-$(CONFIG_VIDEO_ZORAN_DC30) += adv7175.o vpx3220.o zr36050.o \ 35obj-$(CONFIG_VIDEO_TEA6415C) += tea6415c.o
33 zr36016.o 36obj-$(CONFIG_VIDEO_TEA6420) += tea6420.o
34obj-$(CONFIG_VIDEO_ZORAN_LML33) += bt819.o bt856.o zr36060.o 37obj-$(CONFIG_VIDEO_SAA7110) += saa7110.o
35obj-$(CONFIG_VIDEO_ZORAN_LML33R10) += saa7114.o adv7170.o zr36060.o 38obj-$(CONFIG_VIDEO_SAA7111) += saa7111.o
36obj-$(CONFIG_VIDEO_ZORAN_AVS6EYES) += bt866.o ks0127.o zr36060.o 39obj-$(CONFIG_VIDEO_SAA7114) += saa7114.o
40obj-$(CONFIG_VIDEO_SAA711X) += saa7115.o
41obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o
42obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o
43obj-$(CONFIG_VIDEO_SAA7191) += saa7191.o
44obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o
45obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o
46obj-$(CONFIG_VIDEO_VPX3220) += vpx3220.o
47obj-$(CONFIG_VIDEO_BT819) += bt819.o
48obj-$(CONFIG_VIDEO_BT856) += bt856.o
49obj-$(CONFIG_VIDEO_BT866) += bt866.o
50obj-$(CONFIG_VIDEO_KS0127) += ks0127.o
51
37obj-$(CONFIG_VIDEO_ZORAN) += zr36067.o videocodec.o 52obj-$(CONFIG_VIDEO_ZORAN) += zr36067.o videocodec.o
53obj-$(CONFIG_VIDEO_ZORAN_DC30) += zr36050.o zr36016.o
54obj-$(CONFIG_VIDEO_ZORAN_ZR36060) += zr36060.o
55
38obj-$(CONFIG_VIDEO_PMS) += pms.o 56obj-$(CONFIG_VIDEO_PMS) += pms.o
39obj-$(CONFIG_VIDEO_PLANB) += planb.o 57obj-$(CONFIG_VIDEO_PLANB) += planb.o
40obj-$(CONFIG_VIDEO_VINO) += vino.o saa7191.o indycam.o 58obj-$(CONFIG_VIDEO_VINO) += vino.o indycam.o
41obj-$(CONFIG_VIDEO_STRADIS) += stradis.o 59obj-$(CONFIG_VIDEO_STRADIS) += stradis.o
42obj-$(CONFIG_VIDEO_CPIA) += cpia.o 60obj-$(CONFIG_VIDEO_CPIA) += cpia.o
43obj-$(CONFIG_VIDEO_CPIA_PP) += cpia_pp.o 61obj-$(CONFIG_VIDEO_CPIA_PP) += cpia_pp.o
@@ -46,7 +64,7 @@ obj-$(CONFIG_VIDEO_MEYE) += meye.o
46obj-$(CONFIG_VIDEO_SAA7134) += ir-kbd-i2c.o saa7134/ 64obj-$(CONFIG_VIDEO_SAA7134) += ir-kbd-i2c.o saa7134/
47obj-$(CONFIG_VIDEO_CX88) += cx88/ 65obj-$(CONFIG_VIDEO_CX88) += cx88/
48obj-$(CONFIG_VIDEO_EM28XX) += em28xx/ 66obj-$(CONFIG_VIDEO_EM28XX) += em28xx/
49obj-$(CONFIG_VIDEO_EM28XX) += tvp5150.o 67obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o
50obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/ 68obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/
51obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o 69obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o
52obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o 70obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o
@@ -55,10 +73,10 @@ obj-$(CONFIG_VIDEO_WM8775) += wm8775.o
55obj-$(CONFIG_VIDEO_WM8739) += wm8739.o 73obj-$(CONFIG_VIDEO_WM8739) += wm8739.o
56obj-$(CONFIG_VIDEO_OVCAMCHIP) += ovcamchip/ 74obj-$(CONFIG_VIDEO_OVCAMCHIP) += ovcamchip/
57obj-$(CONFIG_VIDEO_CPIA2) += cpia2/ 75obj-$(CONFIG_VIDEO_CPIA2) += cpia2/
58obj-$(CONFIG_VIDEO_MXB) += saa7111.o tda9840.o tea6415c.o tea6420.o mxb.o 76obj-$(CONFIG_VIDEO_MXB) += mxb.o
59obj-$(CONFIG_VIDEO_HEXIUM_ORION) += hexium_orion.o 77obj-$(CONFIG_VIDEO_HEXIUM_ORION) += hexium_orion.o
60obj-$(CONFIG_VIDEO_HEXIUM_GEMINI) += hexium_gemini.o 78obj-$(CONFIG_VIDEO_HEXIUM_GEMINI) += hexium_gemini.o
61obj-$(CONFIG_VIDEO_DPC) += saa7111.o dpc7146.o 79obj-$(CONFIG_VIDEO_DPC) += dpc7146.o
62obj-$(CONFIG_TUNER_3036) += tuner-3036.o 80obj-$(CONFIG_TUNER_3036) += tuner-3036.o
63 81
64obj-$(CONFIG_VIDEO_TUNER) += tuner.o 82obj-$(CONFIG_VIDEO_TUNER) += tuner.o
@@ -70,8 +88,6 @@ obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o
70obj-$(CONFIG_VIDEO_M32R_AR_M64278) += arv.o 88obj-$(CONFIG_VIDEO_M32R_AR_M64278) += arv.o
71 89
72obj-$(CONFIG_VIDEO_CX25840) += cx25840/ 90obj-$(CONFIG_VIDEO_CX25840) += cx25840/
73obj-$(CONFIG_VIDEO_SAA711X) += saa7115.o
74obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o
75obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o 91obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o
76obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o 92obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o
77obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o 93obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o
@@ -96,4 +112,3 @@ obj-$(CONFIG_VIDEO_VIVI) += vivi.o
96 112
97EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core 113EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
98extra-cflags-$(CONFIG_VIDEO_V4L1_COMPAT) += -DCONFIG_VIDEO_V4L1_COMPAT 114extra-cflags-$(CONFIG_VIDEO_V4L1_COMPAT) += -DCONFIG_VIDEO_V4L1_COMPAT
99
diff --git a/drivers/media/video/bt866.c b/drivers/media/video/bt866.c
index 05e42bbcfc3d..772fd52d551a 100644
--- a/drivers/media/video/bt866.c
+++ b/drivers/media/video/bt866.c
@@ -65,7 +65,7 @@ MODULE_LICENSE("GPL");
65struct bt866 { 65struct bt866 {
66 struct i2c_client *i2c; 66 struct i2c_client *i2c;
67 int addr; 67 int addr;
68 unsigned char reg[128]; 68 unsigned char reg[256];
69 69
70 int norm; 70 int norm;
71 int enable; 71 int enable;
diff --git a/drivers/media/video/bt8xx/Kconfig b/drivers/media/video/bt8xx/Kconfig
index cdcf55650714..58eae887a629 100644
--- a/drivers/media/video/bt8xx/Kconfig
+++ b/drivers/media/video/bt8xx/Kconfig
@@ -8,7 +8,10 @@ config VIDEO_BT848
8 select VIDEO_IR 8 select VIDEO_IR
9 select VIDEO_TUNER 9 select VIDEO_TUNER
10 select VIDEO_TVEEPROM 10 select VIDEO_TVEEPROM
11 select VIDEO_MSP3400 11 select VIDEO_MSP3400 if VIDEO_HELPER_CHIPS_AUTO
12 select VIDEO_TVAUDIO if VIDEO_HELPER_CHIPS_AUTO
13 select VIDEO_TDA7432 if VIDEO_HELPER_CHIPS_AUTO
14 select VIDEO_TDA9875 if VIDEO_HELPER_CHIPS_AUTO
12 ---help--- 15 ---help---
13 Support for BT848 based frame grabber/overlay boards. This includes 16 Support for BT848 based frame grabber/overlay boards. This includes
14 the Miro, Hauppauge and STB boards. Please read the material in 17 the Miro, Hauppauge and STB boards. Please read the material in
diff --git a/drivers/media/video/bt8xx/bttv-cards.c b/drivers/media/video/bt8xx/bttv-cards.c
index de14818d5cc4..d23a42b1504f 100644
--- a/drivers/media/video/bt8xx/bttv-cards.c
+++ b/drivers/media/video/bt8xx/bttv-cards.c
@@ -4991,7 +4991,7 @@ void __devinit bttv_check_chipset(void)
4991 int pcipci_fail = 0; 4991 int pcipci_fail = 0;
4992 struct pci_dev *dev = NULL; 4992 struct pci_dev *dev = NULL;
4993 4993
4994 if (pci_pci_problems & PCIPCI_FAIL) 4994 if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL)) /* should check if target is AGP */
4995 pcipci_fail = 1; 4995 pcipci_fail = 1;
4996 if (pci_pci_problems & (PCIPCI_TRITON|PCIPCI_NATOMA|PCIPCI_VIAETBF)) 4996 if (pci_pci_problems & (PCIPCI_TRITON|PCIPCI_NATOMA|PCIPCI_VIAETBF))
4997 triton1 = 1; 4997 triton1 = 1;
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index 20dff7c316eb..50dde82844ec 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -2431,6 +2431,14 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2431 fbuf->bytesperline = btv->fbuf.fmt.bytesperline; 2431 fbuf->bytesperline = btv->fbuf.fmt.bytesperline;
2432 if (fh->ovfmt) 2432 if (fh->ovfmt)
2433 fbuf->depth = fh->ovfmt->depth; 2433 fbuf->depth = fh->ovfmt->depth;
2434 else {
2435 if (fbuf->width)
2436 fbuf->depth = ((fbuf->bytesperline<<3)
2437 + (fbuf->width-1) )
2438 /fbuf->width;
2439 else
2440 fbuf->depth = 0;
2441 }
2434 return 0; 2442 return 0;
2435 } 2443 }
2436 case VIDIOCSFBUF: 2444 case VIDIOCSFBUF:
@@ -4186,6 +4194,7 @@ static void __devexit bttv_remove(struct pci_dev *pci_dev)
4186 return; 4194 return;
4187} 4195}
4188 4196
4197#ifdef CONFIG_PM
4189static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state) 4198static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state)
4190{ 4199{
4191 struct bttv *btv = pci_get_drvdata(pci_dev); 4200 struct bttv *btv = pci_get_drvdata(pci_dev);
@@ -4266,6 +4275,7 @@ static int bttv_resume(struct pci_dev *pci_dev)
4266 spin_unlock_irqrestore(&btv->s_lock,flags); 4275 spin_unlock_irqrestore(&btv->s_lock,flags);
4267 return 0; 4276 return 0;
4268} 4277}
4278#endif
4269 4279
4270static struct pci_device_id bttv_pci_tbl[] = { 4280static struct pci_device_id bttv_pci_tbl[] = {
4271 {PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT848, 4281 {PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT848,
@@ -4286,8 +4296,10 @@ static struct pci_driver bttv_pci_driver = {
4286 .id_table = bttv_pci_tbl, 4296 .id_table = bttv_pci_tbl,
4287 .probe = bttv_probe, 4297 .probe = bttv_probe,
4288 .remove = __devexit_p(bttv_remove), 4298 .remove = __devexit_p(bttv_remove),
4299#ifdef CONFIG_PM
4289 .suspend = bttv_suspend, 4300 .suspend = bttv_suspend,
4290 .resume = bttv_resume, 4301 .resume = bttv_resume,
4302#endif
4291}; 4303};
4292 4304
4293static int bttv_init_module(void) 4305static int bttv_init_module(void)
diff --git a/drivers/media/video/bt8xx/bttv-i2c.c b/drivers/media/video/bt8xx/bttv-i2c.c
index 4b562b386fcf..70de6c96e201 100644
--- a/drivers/media/video/bt8xx/bttv-i2c.c
+++ b/drivers/media/video/bt8xx/bttv-i2c.c
@@ -8,6 +8,9 @@
8 & Marcus Metzler (mocm@thp.uni-koeln.de) 8 & Marcus Metzler (mocm@thp.uni-koeln.de)
9 (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org> 9 (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org>
10 10
11 (c) 2005 Mauro Carvalho Chehab <mchehab@infradead.org>
12 - Multituner support and i2c address binding
13
11 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
12 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
13 the Free Software Foundation; either version 2 of the License, or 16 the Free Software Foundation; either version 2 of the License, or
@@ -45,10 +48,18 @@ static int i2c_debug;
45static int i2c_hw; 48static int i2c_hw;
46static int i2c_scan; 49static int i2c_scan;
47module_param(i2c_debug, int, 0644); 50module_param(i2c_debug, int, 0644);
51MODULE_PARM_DESC(i2c_hw,"configure i2c debug level");
48module_param(i2c_hw, int, 0444); 52module_param(i2c_hw, int, 0444);
53MODULE_PARM_DESC(i2c_hw,"force use of hardware i2c support, "
54 "instead of software bitbang");
49module_param(i2c_scan, int, 0444); 55module_param(i2c_scan, int, 0444);
50MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time"); 56MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time");
51 57
58static unsigned int i2c_udelay = 5;
59module_param(i2c_udelay, int, 0444);
60MODULE_PARM_DESC(i2c_udelay,"soft i2c delay at insmod time, in usecs "
61 "(should be 5 or higher). Lower value means higher bus speed.");
62
52/* ----------------------------------------------------------------------- */ 63/* ----------------------------------------------------------------------- */
53/* I2C functions - bitbanging adapter (software i2c) */ 64/* I2C functions - bitbanging adapter (software i2c) */
54 65
@@ -100,7 +111,6 @@ static struct i2c_algo_bit_data bttv_i2c_algo_bit_template = {
100 .getsda = bttv_bit_getsda, 111 .getsda = bttv_bit_getsda,
101 .getscl = bttv_bit_getscl, 112 .getscl = bttv_bit_getscl,
102 .udelay = 16, 113 .udelay = 16,
103 .mdelay = 10,
104 .timeout = 200, 114 .timeout = 200,
105}; 115};
106 116
@@ -426,6 +436,11 @@ int __devinit init_bttv_i2c(struct bttv *btv)
426 sizeof(bttv_i2c_adap_hw_template)); 436 sizeof(bttv_i2c_adap_hw_template));
427 } else { 437 } else {
428 /* bt848 */ 438 /* bt848 */
439 /* Prevents usage of invalid delay values */
440 if (i2c_udelay<5)
441 i2c_udelay=5;
442 bttv_i2c_algo_bit_template.udelay=i2c_udelay;
443
429 memcpy(&btv->c.i2c_adap, &bttv_i2c_adap_sw_template, 444 memcpy(&btv->c.i2c_adap, &bttv_i2c_adap_sw_template,
430 sizeof(bttv_i2c_adap_sw_template)); 445 sizeof(bttv_i2c_adap_sw_template));
431 memcpy(&btv->i2c_algo, &bttv_i2c_algo_bit_template, 446 memcpy(&btv->i2c_algo, &bttv_i2c_algo_bit_template,
diff --git a/drivers/media/video/compat_ioctl32.c b/drivers/media/video/compat_ioctl32.c
index b69ee1194815..d82a488f12a6 100644
--- a/drivers/media/video/compat_ioctl32.c
+++ b/drivers/media/video/compat_ioctl32.c
@@ -58,6 +58,7 @@ static int put_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user
58 return 0; 58 return 0;
59} 59}
60 60
61
61struct video_buffer32 { 62struct video_buffer32 {
62 compat_caddr_t base; 63 compat_caddr_t base;
63 compat_int_t height, width, depth, bytesperline; 64 compat_int_t height, width, depth, bytesperline;
@@ -618,6 +619,7 @@ static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg
618 struct video_buffer vb; 619 struct video_buffer vb;
619 struct video_window vw; 620 struct video_window vw;
620 struct video_code vc; 621 struct video_code vc;
622 struct video_audio va;
621#endif 623#endif
622 struct v4l2_format v2f; 624 struct v4l2_format v2f;
623 struct v4l2_buffer v2b; 625 struct v4l2_buffer v2b;
@@ -635,31 +637,31 @@ static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg
635 /* First, convert the command. */ 637 /* First, convert the command. */
636 switch(cmd) { 638 switch(cmd) {
637#ifdef CONFIG_VIDEO_V4L1_COMPAT 639#ifdef CONFIG_VIDEO_V4L1_COMPAT
638 case VIDIOCGTUNER32: cmd = VIDIOCGTUNER; break; 640 case VIDIOCGTUNER32: realcmd = cmd = VIDIOCGTUNER; break;
639 case VIDIOCSTUNER32: cmd = VIDIOCSTUNER; break; 641 case VIDIOCSTUNER32: realcmd = cmd = VIDIOCSTUNER; break;
640 case VIDIOCGWIN32: cmd = VIDIOCGWIN; break; 642 case VIDIOCGWIN32: realcmd = cmd = VIDIOCGWIN; break;
641 case VIDIOCGFBUF32: cmd = VIDIOCGFBUF; break; 643 case VIDIOCGFBUF32: realcmd = cmd = VIDIOCGFBUF; break;
642 case VIDIOCSFBUF32: cmd = VIDIOCSFBUF; break; 644 case VIDIOCSFBUF32: realcmd = cmd = VIDIOCSFBUF; break;
643 case VIDIOCGFREQ32: cmd = VIDIOCGFREQ; break; 645 case VIDIOCGFREQ32: realcmd = cmd = VIDIOCGFREQ; break;
644 case VIDIOCSFREQ32: cmd = VIDIOCSFREQ; break; 646 case VIDIOCSFREQ32: realcmd = cmd = VIDIOCSFREQ; break;
645 case VIDIOCSMICROCODE32: cmd = VIDIOCSMICROCODE; break; 647 case VIDIOCSMICROCODE32: realcmd = cmd = VIDIOCSMICROCODE; break;
646#endif 648#endif
647 case VIDIOC_G_FMT32: cmd = VIDIOC_G_FMT; break; 649 case VIDIOC_G_FMT32: realcmd = cmd = VIDIOC_G_FMT; break;
648 case VIDIOC_S_FMT32: cmd = VIDIOC_S_FMT; break; 650 case VIDIOC_S_FMT32: realcmd = cmd = VIDIOC_S_FMT; break;
649 case VIDIOC_QUERYBUF32: cmd = VIDIOC_QUERYBUF; break; 651 case VIDIOC_QUERYBUF32: realcmd = cmd = VIDIOC_QUERYBUF; break;
650 case VIDIOC_QBUF32: cmd = VIDIOC_QBUF; break; 652 case VIDIOC_QBUF32: realcmd = cmd = VIDIOC_QBUF; break;
651 case VIDIOC_DQBUF32: cmd = VIDIOC_DQBUF; break; 653 case VIDIOC_DQBUF32: realcmd = cmd = VIDIOC_DQBUF; break;
652 case VIDIOC_STREAMON32: cmd = VIDIOC_STREAMON; break; 654 case VIDIOC_STREAMON32: realcmd = cmd = VIDIOC_STREAMON; break;
653 case VIDIOC_STREAMOFF32: cmd = VIDIOC_STREAMOFF; break; 655 case VIDIOC_STREAMOFF32: realcmd = cmd = VIDIOC_STREAMOFF; break;
654 case VIDIOC_G_FBUF32: cmd = VIDIOC_G_FBUF; break; 656 case VIDIOC_G_FBUF32: realcmd = cmd = VIDIOC_G_FBUF; break;
655 case VIDIOC_S_FBUF32: cmd = VIDIOC_S_FBUF; break; 657 case VIDIOC_S_FBUF32: realcmd = cmd = VIDIOC_S_FBUF; break;
656 case VIDIOC_OVERLAY32: cmd = VIDIOC_OVERLAY; break; 658 case VIDIOC_OVERLAY32: realcmd = cmd = VIDIOC_OVERLAY; break;
657 case VIDIOC_ENUMSTD32: realcmd = VIDIOC_ENUMSTD; break; 659 case VIDIOC_ENUMSTD32: realcmd = VIDIOC_ENUMSTD; break;
658 case VIDIOC_ENUMINPUT32: realcmd = VIDIOC_ENUMINPUT; break; 660 case VIDIOC_ENUMINPUT32: realcmd = VIDIOC_ENUMINPUT; break;
659 case VIDIOC_S_CTRL32: cmd = VIDIOC_S_CTRL; break; 661 case VIDIOC_S_CTRL32: realcmd = cmd = VIDIOC_S_CTRL; break;
660 case VIDIOC_G_INPUT32: cmd = VIDIOC_G_INPUT; break; 662 case VIDIOC_G_INPUT32: realcmd = cmd = VIDIOC_G_INPUT; break;
661 case VIDIOC_S_INPUT32: cmd = VIDIOC_S_INPUT; break; 663 case VIDIOC_S_INPUT32: realcmd = cmd = VIDIOC_S_INPUT; break;
662 case VIDIOC_TRY_FMT32: cmd = VIDIOC_TRY_FMT; break; 664 case VIDIOC_TRY_FMT32: realcmd = cmd = VIDIOC_TRY_FMT; break;
663 }; 665 };
664 666
665 switch(cmd) { 667 switch(cmd) {
@@ -676,6 +678,7 @@ static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg
676 compatible_arg = 0; 678 compatible_arg = 0;
677 break; 679 break;
678 680
681
679 case VIDIOCSFREQ: 682 case VIDIOCSFREQ:
680#endif 683#endif
681 case VIDIOC_S_INPUT: 684 case VIDIOC_S_INPUT:
@@ -683,7 +686,7 @@ static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg
683 case VIDIOC_STREAMON: 686 case VIDIOC_STREAMON:
684 case VIDIOC_STREAMOFF: 687 case VIDIOC_STREAMOFF:
685 err = get_user(karg.vx, (u32 __user *)up); 688 err = get_user(karg.vx, (u32 __user *)up);
686 compatible_arg = 0; 689 compatible_arg = 1;
687 break; 690 break;
688 691
689 case VIDIOC_S_FBUF: 692 case VIDIOC_S_FBUF:
@@ -739,6 +742,7 @@ static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg
739 case VIDIOC_G_FBUF: 742 case VIDIOC_G_FBUF:
740 case VIDIOC_G_INPUT: 743 case VIDIOC_G_INPUT:
741 compatible_arg = 0; 744 compatible_arg = 0;
745 break;
742#ifdef CONFIG_VIDEO_V4L1_COMPAT 746#ifdef CONFIG_VIDEO_V4L1_COMPAT
743 case VIDIOCSMICROCODE: 747 case VIDIOCSMICROCODE:
744 err = microcode32(&karg.vc, up); 748 err = microcode32(&karg.vc, up);
@@ -755,7 +759,7 @@ static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg
755 mm_segment_t old_fs = get_fs(); 759 mm_segment_t old_fs = get_fs();
756 760
757 set_fs(KERNEL_DS); 761 set_fs(KERNEL_DS);
758 err = native_ioctl(file, realcmd, (unsigned long)&karg); 762 err = native_ioctl(file, realcmd, (unsigned long) &karg);
759 set_fs(old_fs); 763 set_fs(old_fs);
760 } 764 }
761 if(err == 0) { 765 if(err == 0) {
@@ -772,6 +776,7 @@ static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg
772 case VIDIOCGFBUF: 776 case VIDIOCGFBUF:
773 err = put_video_buffer32(&karg.vb, up); 777 err = put_video_buffer32(&karg.vb, up);
774 break; 778 break;
779
775#endif 780#endif
776 case VIDIOC_G_FBUF: 781 case VIDIOC_G_FBUF:
777 err = put_v4l2_framebuffer32(&karg.v2fb, up); 782 err = put_v4l2_framebuffer32(&karg.v2fb, up);
@@ -841,10 +846,14 @@ long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
841 case VIDIOCSFBUF32: 846 case VIDIOCSFBUF32:
842 case VIDIOCGFREQ32: 847 case VIDIOCGFREQ32:
843 case VIDIOCSFREQ32: 848 case VIDIOCSFREQ32:
849 case VIDIOCGAUDIO:
850 case VIDIOCSAUDIO:
844#endif 851#endif
845 case VIDIOC_QUERYCAP: 852 case VIDIOC_QUERYCAP:
846 case VIDIOC_ENUM_FMT: 853 case VIDIOC_ENUM_FMT:
847 case VIDIOC_G_FMT32: 854 case VIDIOC_G_FMT32:
855 case VIDIOC_CROPCAP:
856 case VIDIOC_S_CROP:
848 case VIDIOC_S_FMT32: 857 case VIDIOC_S_FMT32:
849 case VIDIOC_REQBUFS: 858 case VIDIOC_REQBUFS:
850 case VIDIOC_QUERYBUF32: 859 case VIDIOC_QUERYBUF32:
@@ -882,8 +891,6 @@ long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
882 case VIDIOCSPICT: 891 case VIDIOCSPICT:
883 case VIDIOCCAPTURE: 892 case VIDIOCCAPTURE:
884 case VIDIOCKEY: 893 case VIDIOCKEY:
885 case VIDIOCGAUDIO:
886 case VIDIOCSAUDIO:
887 case VIDIOCSYNC: 894 case VIDIOCSYNC:
888 case VIDIOCMCAPTURE: 895 case VIDIOCMCAPTURE:
889 case VIDIOCGMBUF: 896 case VIDIOCGMBUF:
diff --git a/drivers/media/video/cpia2/cpia2.h b/drivers/media/video/cpia2/cpia2.h
index c5ecb2be5f93..8d2dfc128821 100644
--- a/drivers/media/video/cpia2/cpia2.h
+++ b/drivers/media/video/cpia2/cpia2.h
@@ -50,10 +50,6 @@
50/*** 50/***
51 * Image defines 51 * Image defines
52 ***/ 52 ***/
53#ifndef true
54#define true 1
55#define false 0
56#endif
57 53
58/* Misc constants */ 54/* Misc constants */
59#define ALLOW_CORRUPT 0 /* Causes collater to discard checksum */ 55#define ALLOW_CORRUPT 0 /* Causes collater to discard checksum */
diff --git a/drivers/media/video/cx2341x.c b/drivers/media/video/cx2341x.c
index 65f00fc08fa9..657e0b969145 100644
--- a/drivers/media/video/cx2341x.c
+++ b/drivers/media/video/cx2341x.c
@@ -691,7 +691,7 @@ void cx2341x_fill_defaults(struct cx2341x_mpeg_params *p)
691 .video_luma_spatial_filter_type = V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR, 691 .video_luma_spatial_filter_type = V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR,
692 .video_chroma_spatial_filter_type = V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR, 692 .video_chroma_spatial_filter_type = V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR,
693 .video_temporal_filter_mode = V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL, 693 .video_temporal_filter_mode = V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL,
694 .video_temporal_filter = 0, 694 .video_temporal_filter = 8,
695 .video_median_filter_type = V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF, 695 .video_median_filter_type = V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF,
696 .video_luma_median_filter_top = 255, 696 .video_luma_median_filter_top = 255,
697 .video_luma_median_filter_bottom = 0, 697 .video_luma_median_filter_bottom = 0,
@@ -731,6 +731,7 @@ int cx2341x_update(void *priv, cx2341x_mbox_func func,
731 }; 731 };
732 732
733 int err = 0; 733 int err = 0;
734 u16 temporal = new->video_temporal_filter;
734 735
735 cx2341x_api(priv, func, CX2341X_ENC_SET_OUTPUT_PORT, 2, new->port, 0); 736 cx2341x_api(priv, func, CX2341X_ENC_SET_OUTPUT_PORT, 2, new->port, 0);
736 737
@@ -741,6 +742,7 @@ int cx2341x_update(void *priv, cx2341x_mbox_func func,
741 742
742 if (old == NULL || old->width != new->width || old->height != new->height || 743 if (old == NULL || old->width != new->width || old->height != new->height ||
743 old->video_encoding != new->video_encoding) { 744 old->video_encoding != new->video_encoding) {
745 int is_scaling;
744 u16 w = new->width; 746 u16 w = new->width;
745 u16 h = new->height; 747 u16 h = new->height;
746 748
@@ -750,6 +752,20 @@ int cx2341x_update(void *priv, cx2341x_mbox_func func,
750 } 752 }
751 err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_SIZE, 2, h, w); 753 err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_SIZE, 2, h, w);
752 if (err) return err; 754 if (err) return err;
755
756 /* Adjust temporal filter if necessary. The problem with the temporal
757 filter is that it works well with full resolution capturing, but
758 not when the capture window is scaled (the filter introduces
759 a ghosting effect). So if the capture window changed, and there is
760 no updated filter value, then the filter is set depending on whether
761 the new window is full resolution or not.
762
763 For full resolution a setting of 8 really improves the video
764 quality, especially if the original video quality is suboptimal. */
765 is_scaling = new->width != 720 || new->height != (new->is_50hz ? 576 : 480);
766 if (old && old->video_temporal_filter == temporal) {
767 temporal = is_scaling ? 0 : 8;
768 }
753 } 769 }
754 770
755 if (old == NULL || old->stream_type != new->stream_type) { 771 if (old == NULL || old->stream_type != new->stream_type) {
@@ -815,9 +831,9 @@ int cx2341x_update(void *priv, cx2341x_mbox_func func,
815 } 831 }
816 if (old == NULL || 832 if (old == NULL ||
817 old->video_spatial_filter != new->video_spatial_filter || 833 old->video_spatial_filter != new->video_spatial_filter ||
818 old->video_temporal_filter != new->video_temporal_filter) { 834 old->video_temporal_filter != temporal) {
819 err = cx2341x_api(priv, func, CX2341X_ENC_SET_DNR_FILTER_PROPS, 2, 835 err = cx2341x_api(priv, func, CX2341X_ENC_SET_DNR_FILTER_PROPS, 2,
820 new->video_spatial_filter, new->video_temporal_filter); 836 new->video_spatial_filter, temporal);
821 if (err) return err; 837 if (err) return err;
822 } 838 }
823 if (old == NULL || old->video_temporal_decimation != new->video_temporal_decimation) { 839 if (old == NULL || old->video_temporal_decimation != new->video_temporal_decimation) {
@@ -855,6 +871,9 @@ void cx2341x_log_status(struct cx2341x_mpeg_params *p, const char *prefix)
855 printk(KERN_INFO "%s: Stream: %s\n", 871 printk(KERN_INFO "%s: Stream: %s\n",
856 prefix, 872 prefix,
857 cx2341x_menu_item(p, V4L2_CID_MPEG_STREAM_TYPE)); 873 cx2341x_menu_item(p, V4L2_CID_MPEG_STREAM_TYPE));
874 printk(KERN_INFO "%s: VBI Format: %s\n",
875 prefix,
876 cx2341x_menu_item(p, V4L2_CID_MPEG_STREAM_VBI_FMT));
858 877
859 /* Video */ 878 /* Video */
860 printk(KERN_INFO "%s: Video: %dx%d, %d fps\n", 879 printk(KERN_INFO "%s: Video: %dx%d, %d fps\n",
diff --git a/drivers/media/video/cx25840/Kconfig b/drivers/media/video/cx25840/Kconfig
index 854264e42ec0..7cf29a03ed63 100644
--- a/drivers/media/video/cx25840/Kconfig
+++ b/drivers/media/video/cx25840/Kconfig
@@ -1,6 +1,6 @@
1config VIDEO_CX25840 1config VIDEO_CX25840
2 tristate "Conexant CX2584x audio/video decoders" 2 tristate "Conexant CX2584x audio/video decoders"
3 depends on VIDEO_DEV && I2C && EXPERIMENTAL 3 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
4 select FW_LOADER 4 select FW_LOADER
5 ---help--- 5 ---help---
6 Support for the Conexant CX2584x audio/video decoders. 6 Support for the Conexant CX2584x audio/video decoders.
diff --git a/drivers/media/video/cx25840/cx25840-vbi.c b/drivers/media/video/cx25840/cx25840-vbi.c
index 6cc8bf215e85..48014a254e15 100644
--- a/drivers/media/video/cx25840/cx25840-vbi.c
+++ b/drivers/media/video/cx25840/cx25840-vbi.c
@@ -111,6 +111,10 @@ void cx25840_vbi_setup(struct i2c_client *client)
111 uv_lpf=0; 111 uv_lpf=0;
112 comb=0; 112 comb=0;
113 sc=0x0a425f; 113 sc=0x0a425f;
114 } else if (std == V4L2_STD_PAL_Nc) {
115 uv_lpf=1;
116 comb=0x20;
117 sc=556453;
114 } else { 118 } else {
115 uv_lpf=1; 119 uv_lpf=1;
116 comb=0x20; 120 comb=0x20;
diff --git a/drivers/media/video/cx88/Kconfig b/drivers/media/video/cx88/Kconfig
index 7a94e6a11927..51d68f32aa06 100644
--- a/drivers/media/video/cx88/Kconfig
+++ b/drivers/media/video/cx88/Kconfig
@@ -1,7 +1,3 @@
1config VIDEO_CX88_VP3054
2 tristate
3 depends on VIDEO_CX88_DVB && DVB_MT352
4
5config VIDEO_CX88 1config VIDEO_CX88
6 tristate "Conexant 2388x (bt878 successor) support" 2 tristate "Conexant 2388x (bt878 successor) support"
7 depends on VIDEO_DEV && PCI && I2C 3 depends on VIDEO_DEV && PCI && I2C
@@ -52,6 +48,14 @@ config VIDEO_CX88_DVB
52 depends on VIDEO_CX88 && DVB_CORE 48 depends on VIDEO_CX88 && DVB_CORE
53 select VIDEO_BUF_DVB 49 select VIDEO_BUF_DVB
54 select DVB_PLL 50 select DVB_PLL
51 select DVB_MT352 if !DVB_FE_CUSTOMISE
52 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
53 select DVB_OR51132 if !DVB_FE_CUSTOMISE
54 select DVB_CX22702 if !DVB_FE_CUSTOMISE
55 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
56 select DVB_NXT200X if !DVB_FE_CUSTOMISE
57 select DVB_CX24123 if !DVB_FE_CUSTOMISE
58 select DVB_ISL6421 if !DVB_FE_CUSTOMISE
55 ---help--- 59 ---help---
56 This adds support for DVB/ATSC cards based on the 60 This adds support for DVB/ATSC cards based on the
57 Conexant 2388x chip. 61 Conexant 2388x chip.
@@ -59,101 +63,12 @@ config VIDEO_CX88_DVB
59 To compile this driver as a module, choose M here: the 63 To compile this driver as a module, choose M here: the
60 module will be called cx88-dvb. 64 module will be called cx88-dvb.
61 65
62 You must also select one or more DVB/ATSC demodulators. 66config VIDEO_CX88_VP3054
63 If you are unsure which you need, choose all of them. 67 tristate "VP-3054 Secondary I2C Bus Support"
64 68 default m
65config VIDEO_CX88_DVB_ALL_FRONTENDS 69 depends on VIDEO_CX88_DVB && DVB_MT352
66 bool "Build all supported frontends for cx2388x based TV cards"
67 default y
68 depends on VIDEO_CX88_DVB
69 select DVB_MT352
70 select VIDEO_CX88_VP3054
71 select DVB_ZL10353
72 select DVB_OR51132
73 select DVB_CX22702
74 select DVB_LGDT330X
75 select DVB_NXT200X
76 select DVB_CX24123
77 select DVB_ISL6421
78 ---help---
79 This builds cx88-dvb with all currently supported frontend
80 demodulators. If you wish to tweak your configuration, and
81 only include support for the hardware that you need, choose N here.
82
83 If you are unsure, choose Y.
84
85config VIDEO_CX88_DVB_MT352
86 bool "Zarlink MT352 DVB-T Support"
87 default y
88 depends on VIDEO_CX88_DVB && !VIDEO_CX88_DVB_ALL_FRONTENDS
89 select DVB_MT352
90 ---help---
91 This adds DVB-T support for cards based on the
92 Connexant 2388x chip and the MT352 demodulator.
93
94config VIDEO_CX88_DVB_VP3054
95 bool "VP-3054 Secondary I2C Bus Support"
96 default y
97 depends on VIDEO_CX88_DVB_MT352
98 select VIDEO_CX88_VP3054
99 ---help--- 70 ---help---
100 This adds DVB-T support for cards based on the 71 This adds DVB-T support for cards based on the
101 Connexant 2388x chip and the MT352 demodulator, 72 Connexant 2388x chip and the MT352 demodulator,
102 which also require support for the VP-3054 73 which also require support for the VP-3054
103 Secondary I2C bus, such at DNTV Live! DVB-T Pro. 74 Secondary I2C bus, such at DNTV Live! DVB-T Pro.
104
105config VIDEO_CX88_DVB_ZL10353
106 bool "Zarlink ZL10353 DVB-T Support"
107 default y
108 depends on VIDEO_CX88_DVB && !VIDEO_CX88_DVB_ALL_FRONTENDS
109 select DVB_ZL10353
110 ---help---
111 This adds DVB-T support for cards based on the
112 Connexant 2388x chip and the ZL10353 demodulator,
113 successor to the Zarlink MT352.
114
115config VIDEO_CX88_DVB_OR51132
116 bool "OR51132 ATSC Support"
117 default y
118 depends on VIDEO_CX88_DVB && !VIDEO_CX88_DVB_ALL_FRONTENDS
119 select DVB_OR51132
120 ---help---
121 This adds ATSC 8VSB and QAM64/256 support for cards based on the
122 Connexant 2388x chip and the OR51132 demodulator.
123
124config VIDEO_CX88_DVB_CX22702
125 bool "Conexant CX22702 DVB-T Support"
126 default y
127 depends on VIDEO_CX88_DVB && !VIDEO_CX88_DVB_ALL_FRONTENDS
128 select DVB_CX22702
129 ---help---
130 This adds DVB-T support for cards based on the
131 Connexant 2388x chip and the CX22702 demodulator.
132
133config VIDEO_CX88_DVB_LGDT330X
134 bool "LG Electronics DT3302/DT3303 ATSC Support"
135 default y
136 depends on VIDEO_CX88_DVB && !VIDEO_CX88_DVB_ALL_FRONTENDS
137 select DVB_LGDT330X
138 ---help---
139 This adds ATSC 8VSB and QAM64/256 support for cards based on the
140 Connexant 2388x chip and the LGDT3302/LGDT3303 demodulator.
141
142config VIDEO_CX88_DVB_NXT200X
143 bool "NXT2002/NXT2004 ATSC Support"
144 default y
145 depends on VIDEO_CX88_DVB && !VIDEO_CX88_DVB_ALL_FRONTENDS
146 select DVB_NXT200X
147 ---help---
148 This adds ATSC 8VSB and QAM64/256 support for cards based on the
149 Connexant 2388x chip and the NXT2002/NXT2004 demodulator.
150
151config VIDEO_CX88_DVB_CX24123
152 bool "Conexant CX24123 DVB-S Support"
153 default y
154 depends on VIDEO_CX88_DVB && !VIDEO_CX88_DVB_ALL_FRONTENDS
155 select DVB_CX24123
156 select DVB_ISL6421
157 ---help---
158 This adds DVB-S support for cards based on the
159 Connexant 2388x chip and the CX24123 demodulator.
diff --git a/drivers/media/video/cx88/Makefile b/drivers/media/video/cx88/Makefile
index 352b919f30c4..639c3b659d0e 100644
--- a/drivers/media/video/cx88/Makefile
+++ b/drivers/media/video/cx88/Makefile
@@ -14,13 +14,6 @@ EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
14EXTRA_CFLAGS += -Idrivers/media/dvb/frontends 14EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
15 15
16extra-cflags-$(CONFIG_VIDEO_BUF_DVB) += -DHAVE_VIDEO_BUF_DVB=1 16extra-cflags-$(CONFIG_VIDEO_BUF_DVB) += -DHAVE_VIDEO_BUF_DVB=1
17extra-cflags-$(CONFIG_DVB_CX22702) += -DHAVE_CX22702=1
18extra-cflags-$(CONFIG_DVB_OR51132) += -DHAVE_OR51132=1
19extra-cflags-$(CONFIG_DVB_LGDT330X) += -DHAVE_LGDT330X=1
20extra-cflags-$(CONFIG_DVB_MT352) += -DHAVE_MT352=1
21extra-cflags-$(CONFIG_DVB_ZL10353) += -DHAVE_ZL10353=1
22extra-cflags-$(CONFIG_DVB_NXT200X) += -DHAVE_NXT200X=1
23extra-cflags-$(CONFIG_DVB_CX24123) += -DHAVE_CX24123=1
24extra-cflags-$(CONFIG_VIDEO_CX88_VP3054)+= -DHAVE_VP3054_I2C=1 17extra-cflags-$(CONFIG_VIDEO_CX88_VP3054)+= -DHAVE_VP3054_I2C=1
25 18
26EXTRA_CFLAGS += $(extra-cflags-y) $(extra-cflags-m) 19EXTRA_CFLAGS += $(extra-cflags-y) $(extra-cflags-m)
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index b60177f173c3..a7921f9d45d8 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -1160,8 +1160,10 @@ static struct pci_driver blackbird_pci_driver = {
1160 .id_table = cx8802_pci_tbl, 1160 .id_table = cx8802_pci_tbl,
1161 .probe = blackbird_probe, 1161 .probe = blackbird_probe,
1162 .remove = __devexit_p(blackbird_remove), 1162 .remove = __devexit_p(blackbird_remove),
1163#ifdef CONFIG_PM
1163 .suspend = cx8802_suspend_common, 1164 .suspend = cx8802_suspend_common,
1164 .resume = cx8802_resume_common, 1165 .resume = cx8802_resume_common,
1166#endif
1165}; 1167};
1166 1168
1167static int blackbird_init(void) 1169static int blackbird_init(void)
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index 14bd4863d157..6214eb823b29 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -1041,11 +1041,11 @@ struct cx88_board cx88_boards[] = {
1041 .input = {{ 1041 .input = {{
1042 .type = CX88_VMUX_COMPOSITE1, 1042 .type = CX88_VMUX_COMPOSITE1,
1043 .vmux = 1, 1043 .vmux = 1,
1044 .gpio0 = 0x000027df, 1044 .gpio0 = 0x000067df,
1045 },{ 1045 },{
1046 .type = CX88_VMUX_SVIDEO, 1046 .type = CX88_VMUX_SVIDEO,
1047 .vmux = 2, 1047 .vmux = 2,
1048 .gpio0 = 0x000027df, 1048 .gpio0 = 0x000067df,
1049 }}, 1049 }},
1050 .dvb = 1, 1050 .dvb = 1,
1051 }, 1051 },
@@ -1209,6 +1209,100 @@ struct cx88_board cx88_boards[] = {
1209 }}, 1209 }},
1210 .dvb = 1, 1210 .dvb = 1,
1211 }, 1211 },
1212 [CX88_BOARD_HAUPPAUGE_HVR3000] = {
1213 /* FIXME: Add dvb & radio support */
1214 .name = "Hauppauge WinTV-HVR3000 TriMode Analog/DVB-S/DVB-T",
1215 .tuner_type = TUNER_PHILIPS_FMD1216ME_MK3,
1216 .radio_type = UNSET,
1217 .tuner_addr = ADDR_UNSET,
1218 .radio_addr = ADDR_UNSET,
1219 .tda9887_conf = TDA9887_PRESENT,
1220 .input = {{
1221 .type = CX88_VMUX_TELEVISION,
1222 .vmux = 0,
1223 .gpio0 = 0x84bf,
1224 },{
1225 .type = CX88_VMUX_COMPOSITE1,
1226 .vmux = 1,
1227 .gpio0 = 0x84bf,
1228 },{
1229 .type = CX88_VMUX_SVIDEO,
1230 .vmux = 2,
1231 .gpio0 = 0x84bf,
1232 }},
1233 },
1234 [CX88_BOARD_NORWOOD_MICRO] = {
1235 .name = "Norwood Micro TV Tuner",
1236 .tuner_type = TUNER_TNF_5335MF,
1237 .radio_type = UNSET,
1238 .tuner_addr = ADDR_UNSET,
1239 .radio_addr = ADDR_UNSET,
1240 .input = {{
1241 .type = CX88_VMUX_TELEVISION,
1242 .vmux = 0,
1243 .gpio0 = 0x0709,
1244 },{
1245 .type = CX88_VMUX_COMPOSITE1,
1246 .vmux = 1,
1247 .gpio0 = 0x070b,
1248 },{
1249 .type = CX88_VMUX_SVIDEO,
1250 .vmux = 2,
1251 .gpio0 = 0x070b,
1252 }},
1253 },
1254 [CX88_BOARD_TE_DTV_250_OEM_SWANN] = {
1255 .name = "Shenzhen Tungsten Ages Tech TE-DTV-250 / Swann OEM",
1256 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
1257 .radio_type = UNSET,
1258 .tuner_addr = ADDR_UNSET,
1259 .radio_addr = ADDR_UNSET,
1260 .input = {{
1261 .type = CX88_VMUX_TELEVISION,
1262 .vmux = 0,
1263 .gpio0 = 0x003fffff,
1264 .gpio1 = 0x00e00000,
1265 .gpio2 = 0x003fffff,
1266 .gpio3 = 0x02000000,
1267 },{
1268 .type = CX88_VMUX_COMPOSITE1,
1269 .vmux = 1,
1270 .gpio0 = 0x003fffff,
1271 .gpio1 = 0x00e00000,
1272 .gpio2 = 0x003fffff,
1273 .gpio3 = 0x02000000,
1274 },{
1275 .type = CX88_VMUX_SVIDEO,
1276 .vmux = 2,
1277 .gpio0 = 0x003fffff,
1278 .gpio1 = 0x00e00000,
1279 .gpio2 = 0x003fffff,
1280 .gpio3 = 0x02000000,
1281 }},
1282 },
1283 [CX88_BOARD_HAUPPAUGE_HVR1300] = {
1284 .name = "Hauppauge WinTV-HVR1300 DVB-T/Hybrid MPEG Encoder",
1285 .tuner_type = TUNER_PHILIPS_FMD1216ME_MK3,
1286 .radio_type = UNSET,
1287 .tuner_addr = ADDR_UNSET,
1288 .radio_addr = ADDR_UNSET,
1289 .tda9887_conf = TDA9887_PRESENT,
1290 .input = {{
1291 .type = CX88_VMUX_TELEVISION,
1292 .vmux = 0,
1293 .gpio0 = 0xe780,
1294 },{
1295 .type = CX88_VMUX_COMPOSITE1,
1296 .vmux = 1,
1297 .gpio0 = 0xe780,
1298 },{
1299 .type = CX88_VMUX_SVIDEO,
1300 .vmux = 2,
1301 .gpio0 = 0xe780,
1302 }},
1303 /* fixme: Add radio support */
1304 .dvb = 1,
1305 },
1212}; 1306};
1213const unsigned int cx88_bcount = ARRAY_SIZE(cx88_boards); 1307const unsigned int cx88_bcount = ARRAY_SIZE(cx88_boards);
1214 1308
@@ -1254,7 +1348,7 @@ struct cx88_subid cx88_subids[] = {
1254 .card = CX88_BOARD_LEADTEK_PVR2000, 1348 .card = CX88_BOARD_LEADTEK_PVR2000,
1255 },{ 1349 },{
1256 .subvendor = 0x107d, 1350 .subvendor = 0x107d,
1257 .subdevice = 0x663C, 1351 .subdevice = 0x663c,
1258 .card = CX88_BOARD_LEADTEK_PVR2000, 1352 .card = CX88_BOARD_LEADTEK_PVR2000,
1259 },{ 1353 },{
1260 .subvendor = 0x1461, 1354 .subvendor = 0x1461,
@@ -1458,6 +1552,35 @@ struct cx88_subid cx88_subids[] = {
1458 .subvendor = 0x14f1, 1552 .subvendor = 0x14f1,
1459 .subdevice = 0x0084, 1553 .subdevice = 0x0084,
1460 .card = CX88_BOARD_GENIATECH_DVBS, 1554 .card = CX88_BOARD_GENIATECH_DVBS,
1555 },{
1556 .subvendor = 0x0070,
1557 .subdevice = 0x1404,
1558 .card = CX88_BOARD_HAUPPAUGE_HVR3000,
1559 },{
1560 .subvendor = 0x1461,
1561 .subdevice = 0xc111, /* AverMedia M150-D */
1562 /* This board is known to work with the ASUS PVR416 config */
1563 .card = CX88_BOARD_ASUS_PVR_416,
1564 },{
1565 .subvendor = 0xc180,
1566 .subdevice = 0xc980,
1567 .card = CX88_BOARD_TE_DTV_250_OEM_SWANN,
1568 },{
1569 .subvendor = 0x0070,
1570 .subdevice = 0x9600,
1571 .card = CX88_BOARD_HAUPPAUGE_HVR1300,
1572 },{
1573 .subvendor = 0x0070,
1574 .subdevice = 0x9601,
1575 .card = CX88_BOARD_HAUPPAUGE_HVR1300,
1576 },{
1577 .subvendor = 0x0070,
1578 .subdevice = 0x9602,
1579 .card = CX88_BOARD_HAUPPAUGE_HVR1300,
1580 },{
1581 .subvendor = 0x107d,
1582 .subdevice = 0x6632,
1583 .card = CX88_BOARD_LEADTEK_PVR2000,
1461 }, 1584 },
1462}; 1585};
1463const unsigned int cx88_idcount = ARRAY_SIZE(cx88_subids); 1586const unsigned int cx88_idcount = ARRAY_SIZE(cx88_subids);
@@ -1501,6 +1624,7 @@ static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data)
1501 /* Make sure we support the board model */ 1624 /* Make sure we support the board model */
1502 switch (tv.model) 1625 switch (tv.model)
1503 { 1626 {
1627 case 14569: /* WinTV-HVR3000 (OEM, no IR, no back panel video) */
1504 case 28552: /* WinTV-PVR 'Roslyn' (No IR) */ 1628 case 28552: /* WinTV-PVR 'Roslyn' (No IR) */
1505 case 34519: /* WinTV-PCI-FM */ 1629 case 34519: /* WinTV-PCI-FM */
1506 case 90002: /* Nova-T-PCI (9002) */ 1630 case 90002: /* Nova-T-PCI (9002) */
@@ -1512,6 +1636,11 @@ static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data)
1512 case 92000: /* Nova-SE2 (OEM, No Video or IR) */ 1636 case 92000: /* Nova-SE2 (OEM, No Video or IR) */
1513 case 94009: /* WinTV-HVR1100 (Video and IR Retail) */ 1637 case 94009: /* WinTV-HVR1100 (Video and IR Retail) */
1514 case 94501: /* WinTV-HVR1100 (Video and IR OEM) */ 1638 case 94501: /* WinTV-HVR1100 (Video and IR OEM) */
1639 case 96009: /* WinTV-HVR1300 (PAL Video, MPEG Video and IR RX) */
1640 case 96019: /* WinTV-HVR1300 (PAL Video, MPEG Video and IR RX/TX) */
1641 case 96559: /* WinTV-HVR1300 (PAL Video, MPEG Video no IR) */
1642 case 96569: /* WinTV-HVR1300 () */
1643 case 96659: /* WinTV-HVR1300 () */
1515 case 98559: /* WinTV-HVR1100LP (Video no IR, Retail - Low Profile) */ 1644 case 98559: /* WinTV-HVR1100LP (Video no IR, Retail - Low Profile) */
1516 /* known */ 1645 /* known */
1517 break; 1646 break;
@@ -1638,6 +1767,22 @@ void cx88_card_list(struct cx88_core *core, struct pci_dev *pci)
1638 core->name, i, cx88_boards[i].name); 1767 core->name, i, cx88_boards[i].name);
1639} 1768}
1640 1769
1770void cx88_card_setup_pre_i2c(struct cx88_core *core)
1771{
1772 switch (core->board) {
1773 case CX88_BOARD_HAUPPAUGE_HVR1300:
1774 /* Bring the 702 demod up before i2c scanning/attach or devices are hidden */
1775 /* We leave here with the 702 on the bus */
1776 cx_write(MO_GP0_IO, 0x0000e780);
1777 udelay(1000);
1778 cx_clear(MO_GP0_IO, 0x00000080);
1779 udelay(50);
1780 cx_set(MO_GP0_IO, 0x00000080); /* 702 out of reset */
1781 udelay(1000);
1782 break;
1783 }
1784}
1785
1641void cx88_card_setup(struct cx88_core *core) 1786void cx88_card_setup(struct cx88_core *core)
1642{ 1787{
1643 static u8 eeprom[256]; 1788 static u8 eeprom[256];
@@ -1666,6 +1811,8 @@ void cx88_card_setup(struct cx88_core *core)
1666 case CX88_BOARD_HAUPPAUGE_DVB_T1: 1811 case CX88_BOARD_HAUPPAUGE_DVB_T1:
1667 case CX88_BOARD_HAUPPAUGE_HVR1100: 1812 case CX88_BOARD_HAUPPAUGE_HVR1100:
1668 case CX88_BOARD_HAUPPAUGE_HVR1100LP: 1813 case CX88_BOARD_HAUPPAUGE_HVR1100LP:
1814 case CX88_BOARD_HAUPPAUGE_HVR3000:
1815 case CX88_BOARD_HAUPPAUGE_HVR1300:
1669 if (0 == core->i2c_rc) 1816 if (0 == core->i2c_rc)
1670 hauppauge_eeprom(core,eeprom); 1817 hauppauge_eeprom(core,eeprom);
1671 break; 1818 break;
@@ -1673,9 +1820,15 @@ void cx88_card_setup(struct cx88_core *core)
1673 cx_write(MO_GP0_IO, 0x000007f8); 1820 cx_write(MO_GP0_IO, 0x000007f8);
1674 cx_write(MO_GP1_IO, 0x00000001); 1821 cx_write(MO_GP1_IO, 0x00000001);
1675 break; 1822 break;
1823 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL:
1824 /* GPIO0:6 is hooked to FX2 reset pin */
1825 cx_set(MO_GP0_IO, 0x00004040);
1826 cx_clear(MO_GP0_IO, 0x00000040);
1827 msleep(1000);
1828 cx_set(MO_GP0_IO, 0x00004040);
1829 /* FALLTHROUGH */
1676 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1: 1830 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
1677 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS: 1831 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
1678 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL:
1679 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID: 1832 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID:
1680 /* GPIO0:0 is hooked to mt352 reset pin */ 1833 /* GPIO0:0 is hooked to mt352 reset pin */
1681 cx_set(MO_GP0_IO, 0x00000101); 1834 cx_set(MO_GP0_IO, 0x00000101);
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index 973d3f39b2d5..f379ede3049a 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -105,7 +105,7 @@ static u32* cx88_risc_field(u32 *rp, struct scatterlist *sglist,
105 *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset); 105 *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset);
106 offset+=bpl; 106 offset+=bpl;
107 } else { 107 } else {
108 /* scanline needs to be splitted */ 108 /* scanline needs to be split */
109 todo = bpl; 109 todo = bpl;
110 *(rp++)=cpu_to_le32(RISC_WRITE|RISC_SOL| 110 *(rp++)=cpu_to_le32(RISC_WRITE|RISC_SOL|
111 (sg_dma_len(sg)-offset)); 111 (sg_dma_len(sg)-offset));
@@ -792,6 +792,11 @@ int cx88_start_audio_dma(struct cx88_core *core)
792{ 792{
793 /* constant 128 made buzz in analog Nicam-stereo for bigger fifo_size */ 793 /* constant 128 made buzz in analog Nicam-stereo for bigger fifo_size */
794 int bpl = cx88_sram_channels[SRAM_CH25].fifo_size/4; 794 int bpl = cx88_sram_channels[SRAM_CH25].fifo_size/4;
795
796 /* If downstream RISC is enabled, bail out; ALSA is managing DMA */
797 if (cx_read(MO_AUD_DMACNTRL) & 0x10)
798 return 0;
799
795 /* setup fifo + format */ 800 /* setup fifo + format */
796 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH25], bpl, 0); 801 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH25], bpl, 0);
797 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH26], bpl, 0); 802 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH26], bpl, 0);
@@ -801,11 +806,16 @@ int cx88_start_audio_dma(struct cx88_core *core)
801 806
802 /* start dma */ 807 /* start dma */
803 cx_write(MO_AUD_DMACNTRL, 0x0003); /* Up and Down fifo enable */ 808 cx_write(MO_AUD_DMACNTRL, 0x0003); /* Up and Down fifo enable */
809
804 return 0; 810 return 0;
805} 811}
806 812
807int cx88_stop_audio_dma(struct cx88_core *core) 813int cx88_stop_audio_dma(struct cx88_core *core)
808{ 814{
815 /* If downstream RISC is enabled, bail out; ALSA is managing DMA */
816 if (cx_read(MO_AUD_DMACNTRL) & 0x10)
817 return 0;
818
809 /* stop dma */ 819 /* stop dma */
810 cx_write(MO_AUD_DMACNTRL, 0x0000); 820 cx_write(MO_AUD_DMACNTRL, 0x0000);
811 821
@@ -1123,6 +1133,7 @@ struct cx88_core* cx88_core_get(struct pci_dev *pci)
1123 1133
1124 /* init hardware */ 1134 /* init hardware */
1125 cx88_reset(core); 1135 cx88_reset(core);
1136 cx88_card_setup_pre_i2c(core);
1126 cx88_i2c_init(core,pci); 1137 cx88_i2c_init(core,pci);
1127 cx88_call_i2c_clients (core, TUNER_SET_STANDBY, NULL); 1138 cx88_call_i2c_clients (core, TUNER_SET_STANDBY, NULL);
1128 cx88_card_setup(core); 1139 cx88_card_setup(core);
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index afde3789d702..c87041dee21e 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -33,32 +33,18 @@
33#include "dvb-pll.h" 33#include "dvb-pll.h"
34#include <media/v4l2-common.h> 34#include <media/v4l2-common.h>
35 35
36#ifdef HAVE_MT352 36#include "mt352.h"
37# include "mt352.h" 37#include "mt352_priv.h"
38# include "mt352_priv.h" 38#ifdef HAVE_VP3054_I2C
39# ifdef HAVE_VP3054_I2C 39# include "cx88-vp3054-i2c.h"
40# include "cx88-vp3054-i2c.h"
41# endif
42#endif
43#ifdef HAVE_ZL10353
44# include "zl10353.h"
45#endif
46#ifdef HAVE_CX22702
47# include "cx22702.h"
48#endif
49#ifdef HAVE_OR51132
50# include "or51132.h"
51#endif
52#ifdef HAVE_LGDT330X
53# include "lgdt330x.h"
54# include "lg_h06xf.h"
55#endif
56#ifdef HAVE_NXT200X
57# include "nxt200x.h"
58#endif
59#ifdef HAVE_CX24123
60# include "cx24123.h"
61#endif 40#endif
41#include "zl10353.h"
42#include "cx22702.h"
43#include "or51132.h"
44#include "lgdt330x.h"
45#include "lg_h06xf.h"
46#include "nxt200x.h"
47#include "cx24123.h"
62#include "isl6421.h" 48#include "isl6421.h"
63 49
64MODULE_DESCRIPTION("driver for cx2388x based DVB cards"); 50MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
@@ -114,8 +100,6 @@ static struct videobuf_queue_ops dvb_qops = {
114}; 100};
115 101
116/* ------------------------------------------------------------------ */ 102/* ------------------------------------------------------------------ */
117
118#ifdef HAVE_MT352
119static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe) 103static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe)
120{ 104{
121 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 }; 105 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 };
@@ -181,7 +165,7 @@ static int dntv_live_dvbt_demod_init(struct dvb_frontend* fe)
181} 165}
182 166
183static struct mt352_config dvico_fusionhdtv = { 167static struct mt352_config dvico_fusionhdtv = {
184 .demod_address = 0x0F, 168 .demod_address = 0x0f,
185 .demod_init = dvico_fusionhdtv_demod_init, 169 .demod_init = dvico_fusionhdtv_demod_init,
186}; 170};
187 171
@@ -191,7 +175,7 @@ static struct mt352_config dntv_live_dvbt_config = {
191}; 175};
192 176
193static struct mt352_config dvico_fusionhdtv_dual = { 177static struct mt352_config dvico_fusionhdtv_dual = {
194 .demod_address = 0x0F, 178 .demod_address = 0x0f,
195 .demod_init = dvico_dual_demod_init, 179 .demod_init = dvico_dual_demod_init,
196}; 180};
197 181
@@ -266,8 +250,8 @@ static int dntv_live_dvbt_pro_tuner_set_params(struct dvb_frontend* fe,
266 if ((err = i2c_transfer(&dev->core->i2c_adap, &msg, 1)) != 1) { 250 if ((err = i2c_transfer(&dev->core->i2c_adap, &msg, 1)) != 1) {
267 251
268 printk(KERN_WARNING "cx88-dvb: %s error " 252 printk(KERN_WARNING "cx88-dvb: %s error "
269 "(addr %02x <- %02x, err = %i)\n", 253 "(addr %02x <- %02x, err = %i)\n",
270 __FUNCTION__, dev->core->pll_addr, buf[0], err); 254 __FUNCTION__, dev->core->pll_addr, buf[0], err);
271 if (err < 0) 255 if (err < 0)
272 return err; 256 return err;
273 else 257 else
@@ -283,9 +267,7 @@ static struct mt352_config dntv_live_dvbt_pro_config = {
283 .demod_init = dntv_live_dvbt_pro_demod_init, 267 .demod_init = dntv_live_dvbt_pro_demod_init,
284}; 268};
285#endif 269#endif
286#endif
287 270
288#ifdef HAVE_ZL10353
289static int dvico_hybrid_tuner_set_params(struct dvb_frontend *fe, 271static int dvico_hybrid_tuner_set_params(struct dvb_frontend *fe,
290 struct dvb_frontend_parameters *params) 272 struct dvb_frontend_parameters *params)
291{ 273{
@@ -304,8 +286,8 @@ static int dvico_hybrid_tuner_set_params(struct dvb_frontend *fe,
304 fe->ops.i2c_gate_ctrl(fe, 1); 286 fe->ops.i2c_gate_ctrl(fe, 1);
305 if ((err = i2c_transfer(&dev->core->i2c_adap, &msg, 1)) != 1) { 287 if ((err = i2c_transfer(&dev->core->i2c_adap, &msg, 1)) != 1) {
306 printk(KERN_WARNING "cx88-dvb: %s error " 288 printk(KERN_WARNING "cx88-dvb: %s error "
307 "(addr %02x <- %02x, err = %i)\n", 289 "(addr %02x <- %02x, err = %i)\n",
308 __FUNCTION__, pllbuf[0], pllbuf[1], err); 290 __FUNCTION__, pllbuf[0], pllbuf[1], err);
309 if (err < 0) 291 if (err < 0)
310 return err; 292 return err;
311 else 293 else
@@ -316,16 +298,14 @@ static int dvico_hybrid_tuner_set_params(struct dvb_frontend *fe,
316} 298}
317 299
318static struct zl10353_config dvico_fusionhdtv_hybrid = { 300static struct zl10353_config dvico_fusionhdtv_hybrid = {
319 .demod_address = 0x0F, 301 .demod_address = 0x0f,
320 .no_tuner = 1, 302 .no_tuner = 1,
321}; 303};
322 304
323static struct zl10353_config dvico_fusionhdtv_plus_v1_1 = { 305static struct zl10353_config dvico_fusionhdtv_plus_v1_1 = {
324 .demod_address = 0x0F, 306 .demod_address = 0x0f,
325}; 307};
326#endif
327 308
328#ifdef HAVE_CX22702
329static struct cx22702_config connexant_refboard_config = { 309static struct cx22702_config connexant_refboard_config = {
330 .demod_address = 0x43, 310 .demod_address = 0x43,
331 .output_mode = CX22702_SERIAL_OUTPUT, 311 .output_mode = CX22702_SERIAL_OUTPUT,
@@ -339,9 +319,11 @@ static struct cx22702_config hauppauge_hvr1100_config = {
339 .demod_address = 0x63, 319 .demod_address = 0x63,
340 .output_mode = CX22702_SERIAL_OUTPUT, 320 .output_mode = CX22702_SERIAL_OUTPUT,
341}; 321};
342#endif 322static struct cx22702_config hauppauge_hvr1300_config = {
323 .demod_address = 0x63,
324 .output_mode = CX22702_SERIAL_OUTPUT,
325};
343 326
344#ifdef HAVE_OR51132
345static int or51132_set_ts_param(struct dvb_frontend* fe, 327static int or51132_set_ts_param(struct dvb_frontend* fe,
346 int is_punctured) 328 int is_punctured)
347{ 329{
@@ -351,12 +333,10 @@ static int or51132_set_ts_param(struct dvb_frontend* fe,
351} 333}
352 334
353static struct or51132_config pchdtv_hd3000 = { 335static struct or51132_config pchdtv_hd3000 = {
354 .demod_address = 0x15, 336 .demod_address = 0x15,
355 .set_ts_params = or51132_set_ts_param, 337 .set_ts_params = or51132_set_ts_param,
356}; 338};
357#endif
358 339
359#ifdef HAVE_LGDT330X
360static int lgdt3302_tuner_set_params(struct dvb_frontend* fe, 340static int lgdt3302_tuner_set_params(struct dvb_frontend* fe,
361 struct dvb_frontend_parameters* params) 341 struct dvb_frontend_parameters* params)
362{ 342{
@@ -373,14 +353,14 @@ static int lgdt3302_tuner_set_params(struct dvb_frontend* fe,
373 353
374 dvb_pll_configure(core->pll_desc, buf, params->frequency, 0); 354 dvb_pll_configure(core->pll_desc, buf, params->frequency, 0);
375 dprintk(1, "%s: tuner at 0x%02x bytes: 0x%02x 0x%02x 0x%02x 0x%02x\n", 355 dprintk(1, "%s: tuner at 0x%02x bytes: 0x%02x 0x%02x 0x%02x 0x%02x\n",
376 __FUNCTION__, msg.addr, buf[0],buf[1],buf[2],buf[3]); 356 __FUNCTION__, msg.addr, buf[0],buf[1],buf[2],buf[3]);
377 357
378 if (fe->ops.i2c_gate_ctrl) 358 if (fe->ops.i2c_gate_ctrl)
379 fe->ops.i2c_gate_ctrl(fe, 1); 359 fe->ops.i2c_gate_ctrl(fe, 1);
380 if ((err = i2c_transfer(&core->i2c_adap, &msg, 1)) != 1) { 360 if ((err = i2c_transfer(&core->i2c_adap, &msg, 1)) != 1) {
381 printk(KERN_WARNING "cx88-dvb: %s error " 361 printk(KERN_WARNING "cx88-dvb: %s error "
382 "(addr %02x <- %02x, err = %i)\n", 362 "(addr %02x <- %02x, err = %i)\n",
383 __FUNCTION__, buf[0], buf[1], err); 363 __FUNCTION__, buf[0], buf[1], err);
384 if (err < 0) 364 if (err < 0)
385 return err; 365 return err;
386 else 366 else
@@ -425,28 +405,26 @@ static int lgdt330x_set_ts_param(struct dvb_frontend* fe, int is_punctured)
425} 405}
426 406
427static struct lgdt330x_config fusionhdtv_3_gold = { 407static struct lgdt330x_config fusionhdtv_3_gold = {
428 .demod_address = 0x0e, 408 .demod_address = 0x0e,
429 .demod_chip = LGDT3302, 409 .demod_chip = LGDT3302,
430 .serial_mpeg = 0x04, /* TPSERIAL for 3302 in TOP_CONTROL */ 410 .serial_mpeg = 0x04, /* TPSERIAL for 3302 in TOP_CONTROL */
431 .set_ts_params = lgdt330x_set_ts_param, 411 .set_ts_params = lgdt330x_set_ts_param,
432}; 412};
433 413
434static struct lgdt330x_config fusionhdtv_5_gold = { 414static struct lgdt330x_config fusionhdtv_5_gold = {
435 .demod_address = 0x0e, 415 .demod_address = 0x0e,
436 .demod_chip = LGDT3303, 416 .demod_chip = LGDT3303,
437 .serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */ 417 .serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
438 .set_ts_params = lgdt330x_set_ts_param, 418 .set_ts_params = lgdt330x_set_ts_param,
439}; 419};
440 420
441static struct lgdt330x_config pchdtv_hd5500 = { 421static struct lgdt330x_config pchdtv_hd5500 = {
442 .demod_address = 0x59, 422 .demod_address = 0x59,
443 .demod_chip = LGDT3303, 423 .demod_chip = LGDT3303,
444 .serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */ 424 .serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
445 .set_ts_params = lgdt330x_set_ts_param, 425 .set_ts_params = lgdt330x_set_ts_param,
446}; 426};
447#endif
448 427
449#ifdef HAVE_NXT200X
450static int nxt200x_set_ts_param(struct dvb_frontend* fe, 428static int nxt200x_set_ts_param(struct dvb_frontend* fe,
451 int is_punctured) 429 int is_punctured)
452{ 430{
@@ -465,28 +443,27 @@ static int nxt200x_set_pll_input(u8* buf, int input)
465} 443}
466 444
467static struct nxt200x_config ati_hdtvwonder = { 445static struct nxt200x_config ati_hdtvwonder = {
468 .demod_address = 0x0a, 446 .demod_address = 0x0a,
469 .set_pll_input = nxt200x_set_pll_input, 447 .set_pll_input = nxt200x_set_pll_input,
470 .set_ts_params = nxt200x_set_ts_param, 448 .set_ts_params = nxt200x_set_ts_param,
471}; 449};
472#endif
473 450
474#ifdef HAVE_CX24123
475static int cx24123_set_ts_param(struct dvb_frontend* fe, 451static int cx24123_set_ts_param(struct dvb_frontend* fe,
476 int is_punctured) 452 int is_punctured)
477{ 453{
478 struct cx8802_dev *dev= fe->dvb->priv; 454 struct cx8802_dev *dev= fe->dvb->priv;
479 dev->ts_gen_cntrl = 0x2; 455 dev->ts_gen_cntrl = 0x02;
480 return 0; 456 return 0;
481} 457}
482 458
483static int kworld_dvbs_100_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) 459static int kworld_dvbs_100_set_voltage(struct dvb_frontend* fe,
460 fe_sec_voltage_t voltage)
484{ 461{
485 struct cx8802_dev *dev= fe->dvb->priv; 462 struct cx8802_dev *dev= fe->dvb->priv;
486 struct cx88_core *core = dev->core; 463 struct cx88_core *core = dev->core;
487 464
488 if (voltage == SEC_VOLTAGE_OFF) { 465 if (voltage == SEC_VOLTAGE_OFF) {
489 cx_write(MO_GP0_IO, 0x000006fB); 466 cx_write(MO_GP0_IO, 0x000006fb);
490 } else { 467 } else {
491 cx_write(MO_GP0_IO, 0x000006f9); 468 cx_write(MO_GP0_IO, 0x000006f9);
492 } 469 }
@@ -496,7 +473,8 @@ static int kworld_dvbs_100_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t
496 return 0; 473 return 0;
497} 474}
498 475
499static int geniatech_dvbs_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 476static int geniatech_dvbs_set_voltage(struct dvb_frontend *fe,
477 fe_sec_voltage_t voltage)
500{ 478{
501 struct cx8802_dev *dev= fe->dvb->priv; 479 struct cx8802_dev *dev= fe->dvb->priv;
502 struct cx88_core *core = dev->core; 480 struct cx88_core *core = dev->core;
@@ -512,20 +490,20 @@ static int geniatech_dvbs_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t
512} 490}
513 491
514static struct cx24123_config geniatech_dvbs_config = { 492static struct cx24123_config geniatech_dvbs_config = {
515 .demod_address = 0x55, 493 .demod_address = 0x55,
516 .set_ts_params = cx24123_set_ts_param, 494 .set_ts_params = cx24123_set_ts_param,
517}; 495};
518 496
519static struct cx24123_config hauppauge_novas_config = { 497static struct cx24123_config hauppauge_novas_config = {
520 .demod_address = 0x55, 498 .demod_address = 0x55,
521 .set_ts_params = cx24123_set_ts_param, 499 .set_ts_params = cx24123_set_ts_param,
522}; 500};
523 501
524static struct cx24123_config kworld_dvbs_100_config = { 502static struct cx24123_config kworld_dvbs_100_config = {
525 .demod_address = 0x15, 503 .demod_address = 0x15,
526 .set_ts_params = cx24123_set_ts_param, 504 .set_ts_params = cx24123_set_ts_param,
505 .lnb_polarity = 1,
527}; 506};
528#endif
529 507
530static int dvb_register(struct cx8802_dev *dev) 508static int dvb_register(struct cx8802_dev *dev)
531{ 509{
@@ -535,114 +513,114 @@ static int dvb_register(struct cx8802_dev *dev)
535 513
536 /* init frontend */ 514 /* init frontend */
537 switch (dev->core->board) { 515 switch (dev->core->board) {
538#ifdef HAVE_CX22702
539 case CX88_BOARD_HAUPPAUGE_DVB_T1: 516 case CX88_BOARD_HAUPPAUGE_DVB_T1:
540 dev->dvb.frontend = cx22702_attach(&hauppauge_novat_config, 517 dev->dvb.frontend = dvb_attach(cx22702_attach,
541 &dev->core->i2c_adap); 518 &hauppauge_novat_config,
519 &dev->core->i2c_adap);
542 if (dev->dvb.frontend != NULL) { 520 if (dev->dvb.frontend != NULL) {
543 dvb_pll_attach(dev->dvb.frontend, 0x61, 521 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
544 &dev->core->i2c_adap, 522 &dev->core->i2c_adap,
545 &dvb_pll_thomson_dtt759x); 523 &dvb_pll_thomson_dtt759x);
546 } 524 }
547 break; 525 break;
548 case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1: 526 case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
549 case CX88_BOARD_CONEXANT_DVB_T1: 527 case CX88_BOARD_CONEXANT_DVB_T1:
550 case CX88_BOARD_KWORLD_DVB_T_CX22702: 528 case CX88_BOARD_KWORLD_DVB_T_CX22702:
551 case CX88_BOARD_WINFAST_DTV1000: 529 case CX88_BOARD_WINFAST_DTV1000:
552 dev->dvb.frontend = cx22702_attach(&connexant_refboard_config, 530 dev->dvb.frontend = dvb_attach(cx22702_attach,
553 &dev->core->i2c_adap); 531 &connexant_refboard_config,
532 &dev->core->i2c_adap);
554 if (dev->dvb.frontend != NULL) { 533 if (dev->dvb.frontend != NULL) {
555 dvb_pll_attach(dev->dvb.frontend, 0x60, 534 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
556 &dev->core->i2c_adap, 535 &dev->core->i2c_adap,
557 &dvb_pll_thomson_dtt7579); 536 &dvb_pll_thomson_dtt7579);
558 } 537 }
559 break; 538 break;
560 case CX88_BOARD_WINFAST_DTV2000H: 539 case CX88_BOARD_WINFAST_DTV2000H:
561 case CX88_BOARD_HAUPPAUGE_HVR1100: 540 case CX88_BOARD_HAUPPAUGE_HVR1100:
562 case CX88_BOARD_HAUPPAUGE_HVR1100LP: 541 case CX88_BOARD_HAUPPAUGE_HVR1100LP:
563 dev->dvb.frontend = cx22702_attach(&hauppauge_hvr1100_config, 542 dev->dvb.frontend = dvb_attach(cx22702_attach,
564 &dev->core->i2c_adap); 543 &hauppauge_hvr1100_config,
544 &dev->core->i2c_adap);
565 if (dev->dvb.frontend != NULL) { 545 if (dev->dvb.frontend != NULL) {
566 dvb_pll_attach(dev->dvb.frontend, 0x61, 546 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
567 &dev->core->i2c_adap, 547 &dev->core->i2c_adap,
568 &dvb_pll_fmd1216me); 548 &dvb_pll_fmd1216me);
549 }
550 break;
551 case CX88_BOARD_HAUPPAUGE_HVR1300:
552 dev->dvb.frontend = dvb_attach(cx22702_attach,
553 &hauppauge_hvr1300_config,
554 &dev->core->i2c_adap);
555 if (dev->dvb.frontend != NULL) {
556 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
557 &dev->core->i2c_adap,
558 &dvb_pll_fmd1216me);
569 } 559 }
570 break; 560 break;
571#endif
572#if defined(HAVE_MT352) || defined(HAVE_ZL10353)
573 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS: 561 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
574#ifdef HAVE_MT352 562 dev->dvb.frontend = dvb_attach(mt352_attach,
575 dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv, 563 &dvico_fusionhdtv,
576 &dev->core->i2c_adap); 564 &dev->core->i2c_adap);
577 if (dev->dvb.frontend != NULL) { 565 if (dev->dvb.frontend != NULL) {
578 dvb_pll_attach(dev->dvb.frontend, 0x60, 566 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
579 &dev->core->i2c_adap, 567 NULL, &dvb_pll_thomson_dtt7579);
580 &dvb_pll_thomson_dtt7579);
581 break; 568 break;
582 } 569 }
583#endif
584#ifdef HAVE_ZL10353
585 /* ZL10353 replaces MT352 on later cards */ 570 /* ZL10353 replaces MT352 on later cards */
586 dev->dvb.frontend = zl10353_attach(&dvico_fusionhdtv_plus_v1_1, 571 dev->dvb.frontend = dvb_attach(zl10353_attach,
587 &dev->core->i2c_adap); 572 &dvico_fusionhdtv_plus_v1_1,
573 &dev->core->i2c_adap);
588 if (dev->dvb.frontend != NULL) { 574 if (dev->dvb.frontend != NULL) {
589 dvb_pll_attach(dev->dvb.frontend, 0x60, 575 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
590 &dev->core->i2c_adap, 576 NULL, &dvb_pll_thomson_dtt7579);
591 &dvb_pll_thomson_dtt7579);
592 } 577 }
593#endif
594 break; 578 break;
595 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL: 579 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL:
596#ifdef HAVE_MT352
597 /* The tin box says DEE1601, but it seems to be DTT7579 580 /* The tin box says DEE1601, but it seems to be DTT7579
598 * compatible, with a slightly different MT352 AGC gain. */ 581 * compatible, with a slightly different MT352 AGC gain. */
599 dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv_dual, 582 dev->dvb.frontend = dvb_attach(mt352_attach,
600 &dev->core->i2c_adap); 583 &dvico_fusionhdtv_dual,
584 &dev->core->i2c_adap);
601 if (dev->dvb.frontend != NULL) { 585 if (dev->dvb.frontend != NULL) {
602 dvb_pll_attach(dev->dvb.frontend, 0x61, 586 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
603 &dev->core->i2c_adap, 587 NULL, &dvb_pll_thomson_dtt7579);
604 &dvb_pll_thomson_dtt7579);
605 break; 588 break;
606 } 589 }
607#endif
608#ifdef HAVE_ZL10353
609 /* ZL10353 replaces MT352 on later cards */ 590 /* ZL10353 replaces MT352 on later cards */
610 dev->dvb.frontend = zl10353_attach(&dvico_fusionhdtv_plus_v1_1, 591 dev->dvb.frontend = dvb_attach(zl10353_attach,
611 &dev->core->i2c_adap); 592 &dvico_fusionhdtv_plus_v1_1,
593 &dev->core->i2c_adap);
612 if (dev->dvb.frontend != NULL) { 594 if (dev->dvb.frontend != NULL) {
613 dvb_pll_attach(dev->dvb.frontend, 0x61, 595 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
614 &dev->core->i2c_adap, 596 NULL, &dvb_pll_thomson_dtt7579);
615 &dvb_pll_thomson_dtt7579);
616 } 597 }
617#endif
618 break; 598 break;
619#endif /* HAVE_MT352 || HAVE_ZL10353 */
620#ifdef HAVE_MT352
621 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1: 599 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
622 dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv, 600 dev->dvb.frontend = dvb_attach(mt352_attach,
623 &dev->core->i2c_adap); 601 &dvico_fusionhdtv,
602 &dev->core->i2c_adap);
624 if (dev->dvb.frontend != NULL) { 603 if (dev->dvb.frontend != NULL) {
625 dvb_pll_attach(dev->dvb.frontend, 0x61, 604 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
626 &dev->core->i2c_adap, 605 NULL, &dvb_pll_lg_z201);
627 &dvb_pll_lg_z201);
628 } 606 }
629 break; 607 break;
630 case CX88_BOARD_KWORLD_DVB_T: 608 case CX88_BOARD_KWORLD_DVB_T:
631 case CX88_BOARD_DNTV_LIVE_DVB_T: 609 case CX88_BOARD_DNTV_LIVE_DVB_T:
632 case CX88_BOARD_ADSTECH_DVB_T_PCI: 610 case CX88_BOARD_ADSTECH_DVB_T_PCI:
633 dev->dvb.frontend = mt352_attach(&dntv_live_dvbt_config, 611 dev->dvb.frontend = dvb_attach(mt352_attach,
634 &dev->core->i2c_adap); 612 &dntv_live_dvbt_config,
613 &dev->core->i2c_adap);
635 if (dev->dvb.frontend != NULL) { 614 if (dev->dvb.frontend != NULL) {
636 dvb_pll_attach(dev->dvb.frontend, 0x61, 615 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
637 &dev->core->i2c_adap, 616 NULL, &dvb_pll_unknown_1);
638 &dvb_pll_unknown_1);
639 } 617 }
640 break; 618 break;
641 case CX88_BOARD_DNTV_LIVE_DVB_T_PRO: 619 case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
642#ifdef HAVE_VP3054_I2C 620#ifdef HAVE_VP3054_I2C
643 dev->core->pll_addr = 0x61; 621 dev->core->pll_addr = 0x61;
644 dev->core->pll_desc = &dvb_pll_fmd1216me; 622 dev->core->pll_desc = &dvb_pll_fmd1216me;
645 dev->dvb.frontend = mt352_attach(&dntv_live_dvbt_pro_config, 623 dev->dvb.frontend = dvb_attach(mt352_attach, &dntv_live_dvbt_pro_config,
646 &((struct vp3054_i2c_state *)dev->card_priv)->adap); 624 &((struct vp3054_i2c_state *)dev->card_priv)->adap);
647 if (dev->dvb.frontend != NULL) { 625 if (dev->dvb.frontend != NULL) {
648 dev->dvb.frontend->ops.tuner_ops.set_params = dntv_live_dvbt_pro_tuner_set_params; 626 dev->dvb.frontend->ops.tuner_ops.set_params = dntv_live_dvbt_pro_tuner_set_params;
@@ -651,30 +629,26 @@ static int dvb_register(struct cx8802_dev *dev)
651 printk("%s: built without vp3054 support\n", dev->core->name); 629 printk("%s: built without vp3054 support\n", dev->core->name);
652#endif 630#endif
653 break; 631 break;
654#endif
655#ifdef HAVE_ZL10353
656 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID: 632 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID:
657 dev->core->pll_addr = 0x61; 633 dev->core->pll_addr = 0x61;
658 dev->core->pll_desc = &dvb_pll_thomson_fe6600; 634 dev->core->pll_desc = &dvb_pll_thomson_fe6600;
659 dev->dvb.frontend = zl10353_attach(&dvico_fusionhdtv_hybrid, 635 dev->dvb.frontend = dvb_attach(zl10353_attach,
660 &dev->core->i2c_adap); 636 &dvico_fusionhdtv_hybrid,
637 &dev->core->i2c_adap);
661 if (dev->dvb.frontend != NULL) { 638 if (dev->dvb.frontend != NULL) {
662 dev->dvb.frontend->ops.tuner_ops.set_params = dvico_hybrid_tuner_set_params; 639 dev->dvb.frontend->ops.tuner_ops.set_params = dvico_hybrid_tuner_set_params;
663 } 640 }
664 break; 641 break;
665#endif
666#ifdef HAVE_OR51132
667 case CX88_BOARD_PCHDTV_HD3000: 642 case CX88_BOARD_PCHDTV_HD3000:
668 dev->dvb.frontend = or51132_attach(&pchdtv_hd3000, 643 dev->dvb.frontend = dvb_attach(or51132_attach,
669 &dev->core->i2c_adap); 644 &pchdtv_hd3000,
645 &dev->core->i2c_adap);
670 if (dev->dvb.frontend != NULL) { 646 if (dev->dvb.frontend != NULL) {
671 dvb_pll_attach(dev->dvb.frontend, 0x61, 647 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
672 &dev->core->i2c_adap, 648 &dev->core->i2c_adap,
673 &dvb_pll_thomson_dtt761x); 649 &dvb_pll_thomson_dtt761x);
674 } 650 }
675 break; 651 break;
676#endif
677#ifdef HAVE_LGDT330X
678 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q: 652 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
679 dev->ts_gen_cntrl = 0x08; 653 dev->ts_gen_cntrl = 0x08;
680 { 654 {
@@ -690,8 +664,9 @@ static int dvb_register(struct cx8802_dev *dev)
690 fusionhdtv_3_gold.pll_rf_set = lgdt330x_pll_rf_set; 664 fusionhdtv_3_gold.pll_rf_set = lgdt330x_pll_rf_set;
691 dev->core->pll_addr = 0x61; 665 dev->core->pll_addr = 0x61;
692 dev->core->pll_desc = &dvb_pll_microtune_4042; 666 dev->core->pll_desc = &dvb_pll_microtune_4042;
693 dev->dvb.frontend = lgdt330x_attach(&fusionhdtv_3_gold, 667 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
694 &dev->core->i2c_adap); 668 &fusionhdtv_3_gold,
669 &dev->core->i2c_adap);
695 if (dev->dvb.frontend != NULL) { 670 if (dev->dvb.frontend != NULL) {
696 dev->dvb.frontend->ops.tuner_ops.set_params = lgdt3302_tuner_set_params; 671 dev->dvb.frontend->ops.tuner_ops.set_params = lgdt3302_tuner_set_params;
697 } 672 }
@@ -709,8 +684,9 @@ static int dvb_register(struct cx8802_dev *dev)
709 mdelay(200); 684 mdelay(200);
710 dev->core->pll_addr = 0x61; 685 dev->core->pll_addr = 0x61;
711 dev->core->pll_desc = &dvb_pll_thomson_dtt761x; 686 dev->core->pll_desc = &dvb_pll_thomson_dtt761x;
712 dev->dvb.frontend = lgdt330x_attach(&fusionhdtv_3_gold, 687 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
713 &dev->core->i2c_adap); 688 &fusionhdtv_3_gold,
689 &dev->core->i2c_adap);
714 if (dev->dvb.frontend != NULL) { 690 if (dev->dvb.frontend != NULL) {
715 dev->dvb.frontend->ops.tuner_ops.set_params = lgdt3302_tuner_set_params; 691 dev->dvb.frontend->ops.tuner_ops.set_params = lgdt3302_tuner_set_params;
716 } 692 }
@@ -726,8 +702,9 @@ static int dvb_register(struct cx8802_dev *dev)
726 mdelay(100); 702 mdelay(100);
727 cx_set(MO_GP0_IO, 1); 703 cx_set(MO_GP0_IO, 1);
728 mdelay(200); 704 mdelay(200);
729 dev->dvb.frontend = lgdt330x_attach(&fusionhdtv_5_gold, 705 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
730 &dev->core->i2c_adap); 706 &fusionhdtv_5_gold,
707 &dev->core->i2c_adap);
731 if (dev->dvb.frontend != NULL) { 708 if (dev->dvb.frontend != NULL) {
732 dev->dvb.frontend->ops.tuner_ops.set_params = lgdt3303_tuner_set_params; 709 dev->dvb.frontend->ops.tuner_ops.set_params = lgdt3303_tuner_set_params;
733 } 710 }
@@ -743,52 +720,51 @@ static int dvb_register(struct cx8802_dev *dev)
743 mdelay(100); 720 mdelay(100);
744 cx_set(MO_GP0_IO, 1); 721 cx_set(MO_GP0_IO, 1);
745 mdelay(200); 722 mdelay(200);
746 dev->dvb.frontend = lgdt330x_attach(&pchdtv_hd5500, 723 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
747 &dev->core->i2c_adap); 724 &pchdtv_hd5500,
725 &dev->core->i2c_adap);
748 if (dev->dvb.frontend != NULL) { 726 if (dev->dvb.frontend != NULL) {
749 dev->dvb.frontend->ops.tuner_ops.set_params = lgdt3303_tuner_set_params; 727 dev->dvb.frontend->ops.tuner_ops.set_params = lgdt3303_tuner_set_params;
750 } 728 }
751 } 729 }
752 break; 730 break;
753#endif
754#ifdef HAVE_NXT200X
755 case CX88_BOARD_ATI_HDTVWONDER: 731 case CX88_BOARD_ATI_HDTVWONDER:
756 dev->dvb.frontend = nxt200x_attach(&ati_hdtvwonder, 732 dev->dvb.frontend = dvb_attach(nxt200x_attach,
757 &dev->core->i2c_adap); 733 &ati_hdtvwonder,
734 &dev->core->i2c_adap);
758 if (dev->dvb.frontend != NULL) { 735 if (dev->dvb.frontend != NULL) {
759 dvb_pll_attach(dev->dvb.frontend, 0x61, 736 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
760 &dev->core->i2c_adap, 737 NULL, &dvb_pll_tuv1236d);
761 &dvb_pll_tuv1236d);
762 } 738 }
763 break; 739 break;
764#endif
765#ifdef HAVE_CX24123
766 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1: 740 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
767 case CX88_BOARD_HAUPPAUGE_NOVASE2_S1: 741 case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
768 dev->dvb.frontend = cx24123_attach(&hauppauge_novas_config, 742 dev->dvb.frontend = dvb_attach(cx24123_attach,
769 &dev->core->i2c_adap); 743 &hauppauge_novas_config,
744 &dev->core->i2c_adap);
770 if (dev->dvb.frontend) { 745 if (dev->dvb.frontend) {
771 isl6421_attach(dev->dvb.frontend, &dev->core->i2c_adap, 746 dvb_attach(isl6421_attach, dev->dvb.frontend,
772 0x08, 0x00, 0x00); 747 &dev->core->i2c_adap, 0x08, 0x00, 0x00);
773 } 748 }
774 break; 749 break;
775 case CX88_BOARD_KWORLD_DVBS_100: 750 case CX88_BOARD_KWORLD_DVBS_100:
776 dev->dvb.frontend = cx24123_attach(&kworld_dvbs_100_config, 751 dev->dvb.frontend = dvb_attach(cx24123_attach,
777 &dev->core->i2c_adap); 752 &kworld_dvbs_100_config,
753 &dev->core->i2c_adap);
778 if (dev->dvb.frontend) { 754 if (dev->dvb.frontend) {
779 dev->core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage; 755 dev->core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
780 dev->dvb.frontend->ops.set_voltage = kworld_dvbs_100_set_voltage; 756 dev->dvb.frontend->ops.set_voltage = kworld_dvbs_100_set_voltage;
781 } 757 }
782 break; 758 break;
783 case CX88_BOARD_GENIATECH_DVBS: 759 case CX88_BOARD_GENIATECH_DVBS:
784 dev->dvb.frontend = cx24123_attach(&geniatech_dvbs_config, 760 dev->dvb.frontend = dvb_attach(cx24123_attach,
785 &dev->core->i2c_adap); 761 &geniatech_dvbs_config,
762 &dev->core->i2c_adap);
786 if (dev->dvb.frontend) { 763 if (dev->dvb.frontend) {
787 dev->core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage; 764 dev->core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
788 dev->dvb.frontend->ops.set_voltage = geniatech_dvbs_set_voltage; 765 dev->dvb.frontend->ops.set_voltage = geniatech_dvbs_set_voltage;
789 } 766 }
790 break; 767 break;
791#endif
792 default: 768 default:
793 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n", 769 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
794 dev->core->name); 770 dev->core->name);
@@ -908,8 +884,10 @@ static struct pci_driver dvb_pci_driver = {
908 .id_table = cx8802_pci_tbl, 884 .id_table = cx8802_pci_tbl,
909 .probe = dvb_probe, 885 .probe = dvb_probe,
910 .remove = __devexit_p(dvb_remove), 886 .remove = __devexit_p(dvb_remove),
887#ifdef CONFIG_PM
911 .suspend = cx8802_suspend_common, 888 .suspend = cx8802_suspend_common,
912 .resume = cx8802_resume_common, 889 .resume = cx8802_resume_common,
890#endif
913}; 891};
914 892
915static int dvb_init(void) 893static int dvb_init(void)
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index 70663805cc30..27b5dbb2ca1a 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -7,6 +7,9 @@
7 (c) 2002 Yurij Sysoev <yurij@naturesoft.net> 7 (c) 2002 Yurij Sysoev <yurij@naturesoft.net>
8 (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org> 8 (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org>
9 9
10 (c) 2005 Mauro Carvalho Chehab <mchehab@infradead.org>
11 - Multituner support and i2c address binding
12
10 This program is free software; you can redistribute it and/or modify 13 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 14 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 15 the Free Software Foundation; either version 2 of the License, or
@@ -40,6 +43,11 @@ static unsigned int i2c_scan = 0;
40module_param(i2c_scan, int, 0444); 43module_param(i2c_scan, int, 0444);
41MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time"); 44MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time");
42 45
46static unsigned int i2c_udelay = 5;
47module_param(i2c_udelay, int, 0644);
48MODULE_PARM_DESC(i2c_udelay,"i2c delay at insmod time, in usecs "
49 "(should be 5 or higher). Lower value means higher bus speed.");
50
43#define dprintk(level,fmt, arg...) if (i2c_debug >= level) \ 51#define dprintk(level,fmt, arg...) if (i2c_debug >= level) \
44 printk(KERN_DEBUG "%s: " fmt, core->name , ## arg) 52 printk(KERN_DEBUG "%s: " fmt, core->name , ## arg)
45 53
@@ -155,7 +163,6 @@ static struct i2c_algo_bit_data cx8800_i2c_algo_template = {
155 .getsda = cx8800_bit_getsda, 163 .getsda = cx8800_bit_getsda,
156 .getscl = cx8800_bit_getscl, 164 .getscl = cx8800_bit_getscl,
157 .udelay = 16, 165 .udelay = 16,
158 .mdelay = 10,
159 .timeout = 200, 166 .timeout = 200,
160}; 167};
161 168
@@ -199,6 +206,11 @@ static void do_i2c_scan(char *name, struct i2c_client *c)
199/* init + register i2c algo-bit adapter */ 206/* init + register i2c algo-bit adapter */
200int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci) 207int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci)
201{ 208{
209 /* Prevents usage of invalid delay values */
210 if (i2c_udelay<5)
211 i2c_udelay=5;
212 cx8800_i2c_algo_template.udelay=i2c_udelay;
213
202 memcpy(&core->i2c_adap, &cx8800_i2c_adap_template, 214 memcpy(&core->i2c_adap, &cx8800_i2c_adap_template,
203 sizeof(core->i2c_adap)); 215 sizeof(core->i2c_adap));
204 memcpy(&core->i2c_algo, &cx8800_i2c_algo_template, 216 memcpy(&core->i2c_algo, &cx8800_i2c_algo_template,
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index c25564648993..83ebf7a3c054 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -107,7 +107,15 @@ static void cx88_ir_handle_key(struct cx88_IR *ir)
107 (gpio & ir->mask_keydown) ? " down" : "", 107 (gpio & ir->mask_keydown) ? " down" : "",
108 (gpio & ir->mask_keyup) ? " up" : ""); 108 (gpio & ir->mask_keyup) ? " up" : "");
109 109
110 if (ir->mask_keydown) { 110 if (ir->core->board == CX88_BOARD_NORWOOD_MICRO) {
111 u32 gpio_key = cx_read(MO_GP0_IO);
112
113 data = (data << 4) | ((gpio_key & 0xf0) >> 4);
114
115 ir_input_keydown(ir->input, &ir->ir, data, data);
116 ir_input_nokey(ir->input, &ir->ir);
117
118 } else if (ir->mask_keydown) {
111 /* bit set on keydown */ 119 /* bit set on keydown */
112 if (gpio & ir->mask_keydown) { 120 if (gpio & ir->mask_keydown) {
113 ir_input_keydown(ir->input, &ir->ir, data, data); 121 ir_input_keydown(ir->input, &ir->ir, data, data);
@@ -187,6 +195,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
187 case CX88_BOARD_HAUPPAUGE_NOVASE2_S1: 195 case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
188 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1: 196 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
189 case CX88_BOARD_HAUPPAUGE_HVR1100: 197 case CX88_BOARD_HAUPPAUGE_HVR1100:
198 case CX88_BOARD_HAUPPAUGE_HVR1300:
190 ir_codes = ir_codes_hauppauge_new; 199 ir_codes = ir_codes_hauppauge_new;
191 ir_type = IR_TYPE_RC5; 200 ir_type = IR_TYPE_RC5;
192 ir->sampling = 1; 201 ir->sampling = 1;
@@ -248,6 +257,13 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
248 ir_type = IR_TYPE_PD; 257 ir_type = IR_TYPE_PD;
249 ir->sampling = 0xff00; /* address */ 258 ir->sampling = 0xff00; /* address */
250 break; 259 break;
260 case CX88_BOARD_NORWOOD_MICRO:
261 ir_codes = ir_codes_norwood;
262 ir->gpio_addr = MO_GP1_IO;
263 ir->mask_keycode = 0x0e;
264 ir->mask_keyup = 0x80;
265 ir->polling = 50; /* ms */
266 break;
251 case CX88_BOARD_NPGTECH_REALTV_TOP10FM: 267 case CX88_BOARD_NPGTECH_REALTV_TOP10FM:
252 ir_codes = ir_codes_npgtech; 268 ir_codes = ir_codes_npgtech;
253 ir->gpio_addr = MO_GP0_IO; 269 ir->gpio_addr = MO_GP0_IO;
@@ -402,6 +418,7 @@ void cx88_ir_irq(struct cx88_core *core)
402 case CX88_BOARD_HAUPPAUGE_NOVASE2_S1: 418 case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
403 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1: 419 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
404 case CX88_BOARD_HAUPPAUGE_HVR1100: 420 case CX88_BOARD_HAUPPAUGE_HVR1100:
421 case CX88_BOARD_HAUPPAUGE_HVR1300:
405 ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7); 422 ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
406 ir_dprintk("biphase decoded: %x\n", ircode); 423 ir_dprintk("biphase decoded: %x\n", ircode);
407 if ((ircode & 0xfffff000) != 0x3000) 424 if ((ircode & 0xfffff000) != 0x3000)
diff --git a/drivers/media/video/cx88/cx88-tvaudio.c b/drivers/media/video/cx88/cx88-tvaudio.c
index 5785c3481579..741e7c5e69ec 100644
--- a/drivers/media/video/cx88/cx88-tvaudio.c
+++ b/drivers/media/video/cx88/cx88-tvaudio.c
@@ -52,7 +52,6 @@
52#include <linux/init.h> 52#include <linux/init.h>
53#include <linux/smp_lock.h> 53#include <linux/smp_lock.h>
54#include <linux/delay.h> 54#include <linux/delay.h>
55#include <linux/config.h>
56#include <linux/kthread.h> 55#include <linux/kthread.h>
57 56
58#include "cx88.h" 57#include "cx88.h"
@@ -138,14 +137,10 @@ static void set_audio_finish(struct cx88_core *core, u32 ctl)
138{ 137{
139 u32 volume; 138 u32 volume;
140 139
141#ifndef CONFIG_VIDEO_CX88_ALSA
142 /* restart dma; This avoids buzz in NICAM and is good in others */ 140 /* restart dma; This avoids buzz in NICAM and is good in others */
143 cx88_stop_audio_dma(core); 141 cx88_stop_audio_dma(core);
144#endif
145 cx_write(AUD_RATE_THRES_DMD, 0x000000C0); 142 cx_write(AUD_RATE_THRES_DMD, 0x000000C0);
146#ifndef CONFIG_VIDEO_CX88_ALSA
147 cx88_start_audio_dma(core); 143 cx88_start_audio_dma(core);
148#endif
149 144
150 if (cx88_boards[core->board].blackbird) { 145 if (cx88_boards[core->board].blackbird) {
151 /* sets sound input from external adc */ 146 /* sets sound input from external adc */
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index 94c92bacc342..fbc79e9842aa 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -497,6 +497,7 @@ static int start_video_dma(struct cx8800_dev *dev,
497 return 0; 497 return 0;
498} 498}
499 499
500#ifdef CONFIG_PM
500static int stop_video_dma(struct cx8800_dev *dev) 501static int stop_video_dma(struct cx8800_dev *dev)
501{ 502{
502 struct cx88_core *core = dev->core; 503 struct cx88_core *core = dev->core;
@@ -512,6 +513,7 @@ static int stop_video_dma(struct cx8800_dev *dev)
512 cx_clear(MO_VID_INTMSK, 0x0f0011); 513 cx_clear(MO_VID_INTMSK, 0x0f0011);
513 return 0; 514 return 0;
514} 515}
516#endif
515 517
516static int restart_video_queue(struct cx8800_dev *dev, 518static int restart_video_queue(struct cx8800_dev *dev,
517 struct cx88_dmaqueue *q) 519 struct cx88_dmaqueue *q)
@@ -2017,6 +2019,7 @@ static void __devexit cx8800_finidev(struct pci_dev *pci_dev)
2017 kfree(dev); 2019 kfree(dev);
2018} 2020}
2019 2021
2022#ifdef CONFIG_PM
2020static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state) 2023static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
2021{ 2024{
2022 struct cx8800_dev *dev = pci_get_drvdata(pci_dev); 2025 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
@@ -2092,6 +2095,7 @@ static int cx8800_resume(struct pci_dev *pci_dev)
2092 2095
2093 return 0; 2096 return 0;
2094} 2097}
2098#endif
2095 2099
2096/* ----------------------------------------------------------- */ 2100/* ----------------------------------------------------------- */
2097 2101
@@ -2112,9 +2116,10 @@ static struct pci_driver cx8800_pci_driver = {
2112 .id_table = cx8800_pci_tbl, 2116 .id_table = cx8800_pci_tbl,
2113 .probe = cx8800_initdev, 2117 .probe = cx8800_initdev,
2114 .remove = __devexit_p(cx8800_finidev), 2118 .remove = __devexit_p(cx8800_finidev),
2115 2119#ifdef CONFIG_PM
2116 .suspend = cx8800_suspend, 2120 .suspend = cx8800_suspend,
2117 .resume = cx8800_resume, 2121 .resume = cx8800_resume,
2122#endif
2118}; 2123};
2119 2124
2120static int cx8800_init(void) 2125static int cx8800_init(void)
diff --git a/drivers/media/video/cx88/cx88-vp3054-i2c.c b/drivers/media/video/cx88/cx88-vp3054-i2c.c
index 751a754a45e9..2b4f1970c7df 100644
--- a/drivers/media/video/cx88/cx88-vp3054-i2c.c
+++ b/drivers/media/video/cx88/cx88-vp3054-i2c.c
@@ -100,7 +100,6 @@ static struct i2c_algo_bit_data vp3054_i2c_algo_template = {
100 .getsda = vp3054_bit_getsda, 100 .getsda = vp3054_bit_getsda,
101 .getscl = vp3054_bit_getscl, 101 .getscl = vp3054_bit_getscl,
102 .udelay = 16, 102 .udelay = 16,
103 .mdelay = 10,
104 .timeout = 200, 103 .timeout = 200,
105}; 104};
106 105
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index e7810955dd4f..89f12e273b7f 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -197,6 +197,10 @@ extern struct sram_channel cx88_sram_channels[];
197#define CX88_BOARD_NPGTECH_REALTV_TOP10FM 50 197#define CX88_BOARD_NPGTECH_REALTV_TOP10FM 50
198#define CX88_BOARD_WINFAST_DTV2000H 51 198#define CX88_BOARD_WINFAST_DTV2000H 51
199#define CX88_BOARD_GENIATECH_DVBS 52 199#define CX88_BOARD_GENIATECH_DVBS 52
200#define CX88_BOARD_HAUPPAUGE_HVR3000 53
201#define CX88_BOARD_NORWOOD_MICRO 54
202#define CX88_BOARD_TE_DTV_250_OEM_SWANN 55
203#define CX88_BOARD_HAUPPAUGE_HVR1300 56
200 204
201enum cx88_itype { 205enum cx88_itype {
202 CX88_VMUX_COMPOSITE1 = 1, 206 CX88_VMUX_COMPOSITE1 = 1,
@@ -545,6 +549,7 @@ extern const unsigned int cx88_idcount;
545 549
546extern void cx88_card_list(struct cx88_core *core, struct pci_dev *pci); 550extern void cx88_card_list(struct cx88_core *core, struct pci_dev *pci);
547extern void cx88_card_setup(struct cx88_core *core); 551extern void cx88_card_setup(struct cx88_core *core);
552extern void cx88_card_setup_pre_i2c(struct cx88_core *core);
548 553
549/* ----------------------------------------------------------- */ 554/* ----------------------------------------------------------- */
550/* cx88-tvaudio.c */ 555/* cx88-tvaudio.c */
diff --git a/drivers/media/video/em28xx/Kconfig b/drivers/media/video/em28xx/Kconfig
index dfb15bfb83dc..9285a58e47aa 100644
--- a/drivers/media/video/em28xx/Kconfig
+++ b/drivers/media/video/em28xx/Kconfig
@@ -5,7 +5,8 @@ config VIDEO_EM28XX
5 select VIDEO_TUNER 5 select VIDEO_TUNER
6 select VIDEO_TVEEPROM 6 select VIDEO_TVEEPROM
7 select VIDEO_IR 7 select VIDEO_IR
8 select VIDEO_SAA711X 8 select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO
9 select VIDEO_TVP5150 if VIDEO_HELPER_CHIPS_AUTO
9 ---help--- 10 ---help---
10 This is a video4linux driver for Empia 28xx based TV cards. 11 This is a video4linux driver for Empia 28xx based TV cards.
11 12
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 2a461dde480c..20df657b70c8 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -174,7 +174,7 @@ static void em28xx_config_i2c(struct em28xx *dev)
174 174
175 route.input = INPUT(dev->ctl_input)->vmux; 175 route.input = INPUT(dev->ctl_input)->vmux;
176 route.output = 0; 176 route.output = 0;
177 em28xx_i2c_call_clients(dev, VIDIOC_INT_RESET, NULL); 177 em28xx_i2c_call_clients(dev, VIDIOC_INT_RESET, 0);
178 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route); 178 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route);
179 em28xx_i2c_call_clients(dev, VIDIOC_STREAMON, NULL); 179 em28xx_i2c_call_clients(dev, VIDIOC_STREAMON, NULL);
180 180
diff --git a/drivers/media/video/ks0127.c b/drivers/media/video/ks0127.c
index 3bf7ac4f5288..c1a377f797d9 100644
--- a/drivers/media/video/ks0127.c
+++ b/drivers/media/video/ks0127.c
@@ -832,8 +832,7 @@ static int ks0127_detach(struct i2c_client *client)
832static int __devinit ks0127_init_module(void) 832static int __devinit ks0127_init_module(void)
833{ 833{
834 init_reg_defaults(); 834 init_reg_defaults();
835 i2c_add_driver(&i2c_driver_ks0127); 835 return i2c_add_driver(&i2c_driver_ks0127);
836 return 0;
837} 836}
838 837
839static void __devexit ks0127_cleanup_module(void) 838static void __devexit ks0127_cleanup_module(void)
diff --git a/drivers/media/video/ov511.c b/drivers/media/video/ov511.c
index 1b07a61c2ebb..5d8cd283fcd8 100644
--- a/drivers/media/video/ov511.c
+++ b/drivers/media/video/ov511.c
@@ -301,10 +301,11 @@ static struct symbolic_list senlist[] = {
301static struct symbolic_list urb_errlist[] = { 301static struct symbolic_list urb_errlist[] = {
302 { -ENOSR, "Buffer error (overrun)" }, 302 { -ENOSR, "Buffer error (overrun)" },
303 { -EPIPE, "Stalled (device not responding)" }, 303 { -EPIPE, "Stalled (device not responding)" },
304 { -EOVERFLOW, "Babble (bad cable?)" }, 304 { -EOVERFLOW, "Babble (device sends too much data)" },
305 { -EPROTO, "Bit-stuff error (bad cable?)" }, 305 { -EPROTO, "Bit-stuff error (bad cable?)" },
306 { -EILSEQ, "CRC/Timeout" }, 306 { -EILSEQ, "CRC/Timeout (bad cable?)" },
307 { -ETIMEDOUT, "NAK (device does not respond)" }, 307 { -ETIME, "Device does not respond to token" },
308 { -ETIMEDOUT, "Device does not respond to command" },
308 { -1, NULL } 309 { -1, NULL }
309}; 310};
310 311
diff --git a/drivers/media/video/pvrusb2/Kconfig b/drivers/media/video/pvrusb2/Kconfig
index 7e727fe14b32..a52171ef6134 100644
--- a/drivers/media/video/pvrusb2/Kconfig
+++ b/drivers/media/video/pvrusb2/Kconfig
@@ -5,8 +5,6 @@ config VIDEO_PVRUSB2
5 select VIDEO_TUNER 5 select VIDEO_TUNER
6 select VIDEO_TVEEPROM 6 select VIDEO_TVEEPROM
7 select VIDEO_CX2341X 7 select VIDEO_CX2341X
8 select VIDEO_SAA711X
9 select VIDEO_MSP3400
10 ---help--- 8 ---help---
11 This is a video4linux driver for Conexant 23416 based 9 This is a video4linux driver for Conexant 23416 based
12 usb2 personal video recorder devices. 10 usb2 personal video recorder devices.
@@ -14,6 +12,20 @@ config VIDEO_PVRUSB2
14 To compile this driver as a module, choose M here: the 12 To compile this driver as a module, choose M here: the
15 module will be called pvrusb2 13 module will be called pvrusb2
16 14
15config VIDEO_PVRUSB2_29XXX
16 bool "Hauppauge WinTV-PVR USB2 support for 29xxx model series"
17 depends on VIDEO_PVRUSB2 && EXPERIMENTAL
18 select VIDEO_SAA711X
19 select VIDEO_MSP3400
20 ---help---
21 This option enables support for WinTV-PVR USB2 devices whose
22 model number is of the form "29xxx" (leading prefix of "29"
23 followed by 3 digits).
24 To see if you may need this option, examine the white
25 sticker on the underside of your device.
26
27 If you are in doubt, say Y.
28
17config VIDEO_PVRUSB2_24XXX 29config VIDEO_PVRUSB2_24XXX
18 bool "Hauppauge WinTV-PVR USB2 support for 24xxx model series" 30 bool "Hauppauge WinTV-PVR USB2 support for 24xxx model series"
19 depends on VIDEO_PVRUSB2 && EXPERIMENTAL 31 depends on VIDEO_PVRUSB2 && EXPERIMENTAL
@@ -60,3 +72,5 @@ config VIDEO_PVRUSB2_DEBUGIFC
60 You do not need to select this option unless you plan 72 You do not need to select this option unless you plan
61 on debugging the driver or performing a manual firmware 73 on debugging the driver or performing a manual firmware
62 extraction. 74 extraction.
75
76 If you are in doubt, say N.
diff --git a/drivers/media/video/pvrusb2/Makefile b/drivers/media/video/pvrusb2/Makefile
index 02e414210dac..69b3e43cd0eb 100644
--- a/drivers/media/video/pvrusb2/Makefile
+++ b/drivers/media/video/pvrusb2/Makefile
@@ -1,10 +1,6 @@
1obj-pvrusb2-sysfs-$(CONFIG_VIDEO_PVRUSB2_SYSFS) := pvrusb2-sysfs.o 1obj-pvrusb2-sysfs-$(CONFIG_VIDEO_PVRUSB2_SYSFS) := pvrusb2-sysfs.o
2obj-pvrusb2-debugifc-$(CONFIG_VIDEO_PVRUSB2_DEBUGIFC) := pvrusb2-debugifc.o 2obj-pvrusb2-debugifc-$(CONFIG_VIDEO_PVRUSB2_DEBUGIFC) := pvrusb2-debugifc.o
3 3
4obj-pvrusb2-24xxx-$(CONFIG_VIDEO_PVRUSB2_24XXX) := \
5 pvrusb2-cx2584x-v4l.o \
6 pvrusb2-wm8775.o
7
8pvrusb2-objs := pvrusb2-i2c-core.o pvrusb2-i2c-cmd-v4l2.o \ 4pvrusb2-objs := pvrusb2-i2c-core.o pvrusb2-i2c-cmd-v4l2.o \
9 pvrusb2-audio.o pvrusb2-i2c-chips-v4l2.o \ 5 pvrusb2-audio.o pvrusb2-i2c-chips-v4l2.o \
10 pvrusb2-encoder.o pvrusb2-video-v4l.o \ 6 pvrusb2-encoder.o pvrusb2-video-v4l.o \
@@ -12,7 +8,7 @@ pvrusb2-objs := pvrusb2-i2c-core.o pvrusb2-i2c-cmd-v4l2.o \
12 pvrusb2-main.o pvrusb2-hdw.o pvrusb2-v4l2.o \ 8 pvrusb2-main.o pvrusb2-hdw.o pvrusb2-v4l2.o \
13 pvrusb2-ctrl.o pvrusb2-std.o \ 9 pvrusb2-ctrl.o pvrusb2-std.o \
14 pvrusb2-context.o pvrusb2-io.o pvrusb2-ioread.o \ 10 pvrusb2-context.o pvrusb2-io.o pvrusb2-ioread.o \
15 $(obj-pvrusb2-24xxx-y) \ 11 pvrusb2-cx2584x-v4l.o pvrusb2-wm8775.o \
16 $(obj-pvrusb2-sysfs-y) $(obj-pvrusb2-debugifc-y) 12 $(obj-pvrusb2-sysfs-y) $(obj-pvrusb2-debugifc-y)
17 13
18obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2.o 14obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2.o
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
index fb6198f1df98..c77de859cc8e 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
@@ -43,12 +43,17 @@ int pvr2_ctrl_set_mask_value(struct pvr2_ctrl *cptr,int mask,int val)
43 if (cptr->info->type == pvr2_ctl_bitmask) { 43 if (cptr->info->type == pvr2_ctl_bitmask) {
44 mask &= cptr->info->def.type_bitmask.valid_bits; 44 mask &= cptr->info->def.type_bitmask.valid_bits;
45 } else if (cptr->info->type == pvr2_ctl_int) { 45 } else if (cptr->info->type == pvr2_ctl_int) {
46 if (val < cptr->info->def.type_int.min_value) { 46 int lim;
47 break; 47 lim = cptr->info->def.type_int.min_value;
48 if (cptr->info->get_min_value) {
49 cptr->info->get_min_value(cptr,&lim);
48 } 50 }
49 if (val > cptr->info->def.type_int.max_value) { 51 if (val < lim) break;
50 break; 52 lim = cptr->info->def.type_int.max_value;
53 if (cptr->info->get_max_value) {
54 cptr->info->get_max_value(cptr,&lim);
51 } 55 }
56 if (val > lim) break;
52 } else if (cptr->info->type == pvr2_ctl_enum) { 57 } else if (cptr->info->type == pvr2_ctl_enum) {
53 if (val >= cptr->info->def.type_enum.count) { 58 if (val >= cptr->info->def.type_enum.count) {
54 break; 59 break;
@@ -91,7 +96,9 @@ int pvr2_ctrl_get_max(struct pvr2_ctrl *cptr)
91 int ret = 0; 96 int ret = 0;
92 if (!cptr) return 0; 97 if (!cptr) return 0;
93 LOCK_TAKE(cptr->hdw->big_lock); do { 98 LOCK_TAKE(cptr->hdw->big_lock); do {
94 if (cptr->info->type == pvr2_ctl_int) { 99 if (cptr->info->get_max_value) {
100 cptr->info->get_max_value(cptr,&ret);
101 } else if (cptr->info->type == pvr2_ctl_int) {
95 ret = cptr->info->def.type_int.max_value; 102 ret = cptr->info->def.type_int.max_value;
96 } 103 }
97 } while(0); LOCK_GIVE(cptr->hdw->big_lock); 104 } while(0); LOCK_GIVE(cptr->hdw->big_lock);
@@ -105,7 +112,9 @@ int pvr2_ctrl_get_min(struct pvr2_ctrl *cptr)
105 int ret = 0; 112 int ret = 0;
106 if (!cptr) return 0; 113 if (!cptr) return 0;
107 LOCK_TAKE(cptr->hdw->big_lock); do { 114 LOCK_TAKE(cptr->hdw->big_lock); do {
108 if (cptr->info->type == pvr2_ctl_int) { 115 if (cptr->info->get_min_value) {
116 cptr->info->get_min_value(cptr,&ret);
117 } else if (cptr->info->type == pvr2_ctl_int) {
109 ret = cptr->info->def.type_int.min_value; 118 ret = cptr->info->def.type_int.min_value;
110 } 119 }
111 } while(0); LOCK_GIVE(cptr->hdw->big_lock); 120 } while(0); LOCK_GIVE(cptr->hdw->big_lock);
diff --git a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
index c80c26be6e4d..df8feac16aee 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
@@ -221,7 +221,7 @@ static unsigned int decoder_describe(struct pvr2_v4l_cx2584x *ctxt,
221static void decoder_reset(struct pvr2_v4l_cx2584x *ctxt) 221static void decoder_reset(struct pvr2_v4l_cx2584x *ctxt)
222{ 222{
223 int ret; 223 int ret;
224 ret = pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_RESET,NULL); 224 ret = pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_RESET,0);
225 pvr2_trace(PVR2_TRACE_CHIPS,"i2c cx25840 decoder_reset (ret=%d)",ret); 225 pvr2_trace(PVR2_TRACE_CHIPS,"i2c cx25840 decoder_reset (ret=%d)",ret);
226} 226}
227 227
diff --git a/drivers/media/video/pvrusb2/pvrusb2-encoder.c b/drivers/media/video/pvrusb2/pvrusb2-encoder.c
index 18a7073501c6..c94f97b79392 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-encoder.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-encoder.c
@@ -317,7 +317,7 @@ int pvr2_encoder_configure(struct pvr2_hdw *hdw)
317 317
318 if (ret) { 318 if (ret) {
319 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 319 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
320 "Failed to configure cx32416"); 320 "Failed to configure cx23416");
321 return ret; 321 return ret;
322 } 322 }
323 323
@@ -337,7 +337,7 @@ int pvr2_encoder_configure(struct pvr2_hdw *hdw)
337 337
338 if (ret) { 338 if (ret) {
339 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 339 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
340 "Failed to initialize cx32416 video input"); 340 "Failed to initialize cx23416 video input");
341 return ret; 341 return ret;
342 } 342 }
343 343
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
index 0d6dc33ca320..34b08fbcc6ea 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
@@ -33,7 +33,6 @@
33 33
34*/ 34*/
35 35
36#include <linux/config.h>
37#include <linux/videodev2.h> 36#include <linux/videodev2.h>
38#include <linux/i2c.h> 37#include <linux/i2c.h>
39#include <linux/mutex.h> 38#include <linux/mutex.h>
@@ -41,32 +40,6 @@
41#include "pvrusb2-io.h" 40#include "pvrusb2-io.h"
42#include <media/cx2341x.h> 41#include <media/cx2341x.h>
43 42
44/* Legal values for the SRATE state variable */
45#define PVR2_CVAL_SRATE_48 0
46#define PVR2_CVAL_SRATE_44_1 1
47
48/* Legal values for the AUDIOBITRATE state variable */
49#define PVR2_CVAL_AUDIOBITRATE_384 0
50#define PVR2_CVAL_AUDIOBITRATE_320 1
51#define PVR2_CVAL_AUDIOBITRATE_256 2
52#define PVR2_CVAL_AUDIOBITRATE_224 3
53#define PVR2_CVAL_AUDIOBITRATE_192 4
54#define PVR2_CVAL_AUDIOBITRATE_160 5
55#define PVR2_CVAL_AUDIOBITRATE_128 6
56#define PVR2_CVAL_AUDIOBITRATE_112 7
57#define PVR2_CVAL_AUDIOBITRATE_96 8
58#define PVR2_CVAL_AUDIOBITRATE_80 9
59#define PVR2_CVAL_AUDIOBITRATE_64 10
60#define PVR2_CVAL_AUDIOBITRATE_56 11
61#define PVR2_CVAL_AUDIOBITRATE_48 12
62#define PVR2_CVAL_AUDIOBITRATE_32 13
63#define PVR2_CVAL_AUDIOBITRATE_VBR 14
64
65/* Legal values for the AUDIOEMPHASIS state variable */
66#define PVR2_CVAL_AUDIOEMPHASIS_NONE 0
67#define PVR2_CVAL_AUDIOEMPHASIS_50_15 1
68#define PVR2_CVAL_AUDIOEMPHASIS_CCITT 2
69
70/* Legal values for PVR2_CID_HSM */ 43/* Legal values for PVR2_CID_HSM */
71#define PVR2_CVAL_HSM_FAIL 0 44#define PVR2_CVAL_HSM_FAIL 0
72#define PVR2_CVAL_HSM_FULL 1 45#define PVR2_CVAL_HSM_FULL 1
@@ -107,6 +80,8 @@ struct pvr2_ctl_info {
107 80
108 /* Control's implementation */ 81 /* Control's implementation */
109 pvr2_ctlf_get_value get_value; /* Get its value */ 82 pvr2_ctlf_get_value get_value; /* Get its value */
83 pvr2_ctlf_get_value get_min_value; /* Get minimum allowed value */
84 pvr2_ctlf_get_value get_max_value; /* Get maximum allowed value */
110 pvr2_ctlf_set_value set_value; /* Set its value */ 85 pvr2_ctlf_set_value set_value; /* Set its value */
111 pvr2_ctlf_val_to_sym val_to_sym; /* Custom convert value->symbol */ 86 pvr2_ctlf_val_to_sym val_to_sym; /* Custom convert value->symbol */
112 pvr2_ctlf_sym_to_val sym_to_val; /* Custom convert symbol->value */ 87 pvr2_ctlf_sym_to_val sym_to_val; /* Custom convert symbol->value */
@@ -193,9 +168,7 @@ struct pvr2_decoder_ctrl {
193 168
194/* Known major hardware variants, keyed from device ID */ 169/* Known major hardware variants, keyed from device ID */
195#define PVR2_HDW_TYPE_29XXX 0 170#define PVR2_HDW_TYPE_29XXX 0
196#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
197#define PVR2_HDW_TYPE_24XXX 1 171#define PVR2_HDW_TYPE_24XXX 1
198#endif
199 172
200typedef int (*pvr2_i2c_func)(struct pvr2_hdw *,u8,u8 *,u16,u8 *, u16); 173typedef int (*pvr2_i2c_func)(struct pvr2_hdw *,u8,u8 *,u16,u8 *, u16);
201#define PVR2_I2C_FUNC_CNT 128 174#define PVR2_I2C_FUNC_CNT 128
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index be1e5cc78081..88604365777c 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -38,9 +38,7 @@
38 38
39struct usb_device_id pvr2_device_table[] = { 39struct usb_device_id pvr2_device_table[] = {
40 [PVR2_HDW_TYPE_29XXX] = { USB_DEVICE(0x2040, 0x2900) }, 40 [PVR2_HDW_TYPE_29XXX] = { USB_DEVICE(0x2040, 0x2900) },
41#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
42 [PVR2_HDW_TYPE_24XXX] = { USB_DEVICE(0x2040, 0x2400) }, 41 [PVR2_HDW_TYPE_24XXX] = { USB_DEVICE(0x2040, 0x2400) },
43#endif
44 { } 42 { }
45}; 43};
46 44
@@ -48,9 +46,7 @@ MODULE_DEVICE_TABLE(usb, pvr2_device_table);
48 46
49static const char *pvr2_device_names[] = { 47static const char *pvr2_device_names[] = {
50 [PVR2_HDW_TYPE_29XXX] = "WinTV PVR USB2 Model Category 29xxxx", 48 [PVR2_HDW_TYPE_29XXX] = "WinTV PVR USB2 Model Category 29xxxx",
51#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
52 [PVR2_HDW_TYPE_24XXX] = "WinTV PVR USB2 Model Category 24xxxx", 49 [PVR2_HDW_TYPE_24XXX] = "WinTV PVR USB2 Model Category 24xxxx",
53#endif
54}; 50};
55 51
56struct pvr2_string_table { 52struct pvr2_string_table {
@@ -58,14 +54,12 @@ struct pvr2_string_table {
58 unsigned int cnt; 54 unsigned int cnt;
59}; 55};
60 56
61#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
62// Names of other client modules to request for 24xxx model hardware 57// Names of other client modules to request for 24xxx model hardware
63static const char *pvr2_client_24xxx[] = { 58static const char *pvr2_client_24xxx[] = {
64 "cx25840", 59 "cx25840",
65 "tuner", 60 "tuner",
66 "wm8775", 61 "wm8775",
67}; 62};
68#endif
69 63
70// Names of other client modules to request for 29xxx model hardware 64// Names of other client modules to request for 29xxx model hardware
71static const char *pvr2_client_29xxx[] = { 65static const char *pvr2_client_29xxx[] = {
@@ -79,12 +73,10 @@ static struct pvr2_string_table pvr2_client_lists[] = {
79 pvr2_client_29xxx, 73 pvr2_client_29xxx,
80 sizeof(pvr2_client_29xxx)/sizeof(pvr2_client_29xxx[0]), 74 sizeof(pvr2_client_29xxx)/sizeof(pvr2_client_29xxx[0]),
81 }, 75 },
82#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
83 [PVR2_HDW_TYPE_24XXX] = { 76 [PVR2_HDW_TYPE_24XXX] = {
84 pvr2_client_24xxx, 77 pvr2_client_24xxx,
85 sizeof(pvr2_client_24xxx)/sizeof(pvr2_client_24xxx[0]), 78 sizeof(pvr2_client_24xxx)/sizeof(pvr2_client_24xxx[0]),
86 }, 79 },
87#endif
88}; 80};
89 81
90static struct pvr2_hdw *unit_pointers[PVR_NUM] = {[ 0 ... PVR_NUM-1 ] = NULL}; 82static struct pvr2_hdw *unit_pointers[PVR_NUM] = {[ 0 ... PVR_NUM-1 ] = NULL};
@@ -221,14 +213,15 @@ static const struct pvr2_mpeg_ids mpeg_ids[] = {
221}; 213};
222#define MPEGDEF_COUNT (sizeof(mpeg_ids)/sizeof(mpeg_ids[0])) 214#define MPEGDEF_COUNT (sizeof(mpeg_ids)/sizeof(mpeg_ids[0]))
223 215
216
224static const char *control_values_srate[] = { 217static const char *control_values_srate[] = {
225 [PVR2_CVAL_SRATE_48] = "48KHz", 218 [V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100] = "44.1 kHz",
226 [PVR2_CVAL_SRATE_44_1] = "44.1KHz", 219 [V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000] = "48 kHz",
220 [V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000] = "32 kHz",
227}; 221};
228 222
229 223
230 224
231
232static const char *control_values_input[] = { 225static const char *control_values_input[] = {
233 [PVR2_CVAL_INPUT_TV] = "television", /*xawtv needs this name*/ 226 [PVR2_CVAL_INPUT_TV] = "television", /*xawtv needs this name*/
234 [PVR2_CVAL_INPUT_RADIO] = "radio", 227 [PVR2_CVAL_INPUT_RADIO] = "radio",
@@ -362,6 +355,50 @@ static int ctrl_freq_set(struct pvr2_ctrl *cptr,int m,int v)
362 return 0; 355 return 0;
363} 356}
364 357
358static int ctrl_hres_max_get(struct pvr2_ctrl *cptr,int *vp)
359{
360 /* If we're dealing with a 24xxx device, force the horizontal
361 maximum to be 720 no matter what, since we can't get the device
362 to work properly with any other value. Otherwise just return
363 the normal value. */
364 *vp = cptr->info->def.type_int.max_value;
365 if (cptr->hdw->hdw_type == PVR2_HDW_TYPE_24XXX) *vp = 720;
366 return 0;
367}
368
369static int ctrl_hres_min_get(struct pvr2_ctrl *cptr,int *vp)
370{
371 /* If we're dealing with a 24xxx device, force the horizontal
372 minimum to be 720 no matter what, since we can't get the device
373 to work properly with any other value. Otherwise just return
374 the normal value. */
375 *vp = cptr->info->def.type_int.min_value;
376 if (cptr->hdw->hdw_type == PVR2_HDW_TYPE_24XXX) *vp = 720;
377 return 0;
378}
379
380static int ctrl_vres_max_get(struct pvr2_ctrl *cptr,int *vp)
381{
382 /* Actual maximum depends on the video standard in effect. */
383 if (cptr->hdw->std_mask_cur & V4L2_STD_525_60) {
384 *vp = 480;
385 } else {
386 *vp = 576;
387 }
388 return 0;
389}
390
391static int ctrl_vres_min_get(struct pvr2_ctrl *cptr,int *vp)
392{
393 /* Actual minimum depends on device type. */
394 if (cptr->hdw->hdw_type == PVR2_HDW_TYPE_24XXX) {
395 *vp = 75;
396 } else {
397 *vp = 17;
398 }
399 return 0;
400}
401
365static int ctrl_cx2341x_is_dirty(struct pvr2_ctrl *cptr) 402static int ctrl_cx2341x_is_dirty(struct pvr2_ctrl *cptr)
366{ 403{
367 return cptr->hdw->enc_stale != 0; 404 return cptr->hdw->enc_stale != 0;
@@ -719,19 +756,27 @@ static const struct pvr2_ctl_info control_defs[] = {
719 .internal_id = PVR2_CID_HRES, 756 .internal_id = PVR2_CID_HRES,
720 .default_value = 720, 757 .default_value = 720,
721 DEFREF(res_hor), 758 DEFREF(res_hor),
722 DEFINT(320,720), 759 DEFINT(19,720),
760 /* Hook in check for clamp on horizontal resolution in
761 order to avoid unsolved problem involving cx25840. */
762 .get_max_value = ctrl_hres_max_get,
763 .get_min_value = ctrl_hres_min_get,
723 },{ 764 },{
724 .desc = "Vertical capture resolution", 765 .desc = "Vertical capture resolution",
725 .name = "resolution_ver", 766 .name = "resolution_ver",
726 .internal_id = PVR2_CID_VRES, 767 .internal_id = PVR2_CID_VRES,
727 .default_value = 480, 768 .default_value = 480,
728 DEFREF(res_ver), 769 DEFREF(res_ver),
729 DEFINT(200,625), 770 DEFINT(17,576),
771 /* Hook in check for video standard and adjust maximum
772 depending on the standard. */
773 .get_max_value = ctrl_vres_max_get,
774 .get_min_value = ctrl_vres_min_get,
730 },{ 775 },{
731 .v4l_id = V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ, 776 .v4l_id = V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ,
732 .desc = "Sample rate", 777 .default_value = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000,
778 .desc = "Audio Sampling Frequency",
733 .name = "srate", 779 .name = "srate",
734 .default_value = PVR2_CVAL_SRATE_48,
735 DEFREF(srate), 780 DEFREF(srate),
736 DEFENUM(control_values_srate), 781 DEFENUM(control_values_srate),
737 },{ 782 },{
@@ -935,22 +980,18 @@ static int pvr2_upload_firmware1(struct pvr2_hdw *hdw)
935 static const char *fw_files_29xxx[] = { 980 static const char *fw_files_29xxx[] = {
936 "v4l-pvrusb2-29xxx-01.fw", 981 "v4l-pvrusb2-29xxx-01.fw",
937 }; 982 };
938#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
939 static const char *fw_files_24xxx[] = { 983 static const char *fw_files_24xxx[] = {
940 "v4l-pvrusb2-24xxx-01.fw", 984 "v4l-pvrusb2-24xxx-01.fw",
941 }; 985 };
942#endif
943 static const struct pvr2_string_table fw_file_defs[] = { 986 static const struct pvr2_string_table fw_file_defs[] = {
944 [PVR2_HDW_TYPE_29XXX] = { 987 [PVR2_HDW_TYPE_29XXX] = {
945 fw_files_29xxx, 988 fw_files_29xxx,
946 sizeof(fw_files_29xxx)/sizeof(fw_files_29xxx[0]), 989 sizeof(fw_files_29xxx)/sizeof(fw_files_29xxx[0]),
947 }, 990 },
948#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
949 [PVR2_HDW_TYPE_24XXX] = { 991 [PVR2_HDW_TYPE_24XXX] = {
950 fw_files_24xxx, 992 fw_files_24xxx,
951 sizeof(fw_files_24xxx)/sizeof(fw_files_24xxx[0]), 993 sizeof(fw_files_24xxx)/sizeof(fw_files_24xxx[0]),
952 }, 994 },
953#endif
954 }; 995 };
955 hdw->fw1_state = FW1_STATE_FAILED; // default result 996 hdw->fw1_state = FW1_STATE_FAILED; // default result
956 997
@@ -2237,11 +2278,14 @@ static int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw)
2237 } 2278 }
2238 2279
2239 if (hdw->std_dirty || 2280 if (hdw->std_dirty ||
2281 hdw->enc_stale ||
2282 hdw->srate_dirty ||
2283 hdw->res_ver_dirty ||
2284 hdw->res_hor_dirty ||
2240 0) { 2285 0) {
2241 /* If any of this changes, then the encoder needs to be 2286 /* If any of this changes, then the encoder needs to be
2242 reconfigured, and we need to reset the stream. */ 2287 reconfigured, and we need to reset the stream. */
2243 stale_subsys_mask |= (1<<PVR2_SUBSYS_B_ENC_CFG); 2288 stale_subsys_mask |= (1<<PVR2_SUBSYS_B_ENC_CFG);
2244 stale_subsys_mask |= hdw->subsys_stream_mask;
2245 } 2289 }
2246 2290
2247 if (hdw->srate_dirty) { 2291 if (hdw->srate_dirty) {
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c
index fbe6039aeb6a..ed3e8105292a 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c
@@ -26,10 +26,8 @@
26#include "pvrusb2-audio.h" 26#include "pvrusb2-audio.h"
27#include "pvrusb2-tuner.h" 27#include "pvrusb2-tuner.h"
28#include "pvrusb2-video-v4l.h" 28#include "pvrusb2-video-v4l.h"
29#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
30#include "pvrusb2-cx2584x-v4l.h" 29#include "pvrusb2-cx2584x-v4l.h"
31#include "pvrusb2-wm8775.h" 30#include "pvrusb2-wm8775.h"
32#endif
33 31
34#define trace_i2c(...) pvr2_trace(PVR2_TRACE_I2C,__VA_ARGS__) 32#define trace_i2c(...) pvr2_trace(PVR2_TRACE_I2C,__VA_ARGS__)
35 33
@@ -71,7 +69,6 @@ void pvr2_i2c_probe(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
71 return; 69 return;
72 } 70 }
73 } 71 }
74#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
75 if (id == I2C_DRIVERID_CX25840) { 72 if (id == I2C_DRIVERID_CX25840) {
76 if (pvr2_i2c_cx2584x_v4l_setup(hdw,cp)) { 73 if (pvr2_i2c_cx2584x_v4l_setup(hdw,cp)) {
77 return; 74 return;
@@ -82,7 +79,6 @@ void pvr2_i2c_probe(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
82 return; 79 return;
83 } 80 }
84 } 81 }
85#endif
86 if (id == I2C_DRIVERID_SAA711X) { 82 if (id == I2C_DRIVERID_SAA711X) {
87 if (pvr2_i2c_decoder_v4l_setup(hdw,cp)) { 83 if (pvr2_i2c_decoder_v4l_setup(hdw,cp)) {
88 return; 84 return;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c
index 8a9933dec912..05ea17afe903 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c
@@ -31,7 +31,7 @@ static void set_standard(struct pvr2_hdw *hdw)
31 v4l2_std_id vs; 31 v4l2_std_id vs;
32 vs = hdw->std_mask_cur; 32 vs = hdw->std_mask_cur;
33 pvr2_trace(PVR2_TRACE_CHIPS, 33 pvr2_trace(PVR2_TRACE_CHIPS,
34 "i2c v4l2 set_standard(0x%llx)",(__u64)vs); 34 "i2c v4l2 set_standard(0x%llx)",(long long unsigned)vs);
35 35
36 pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs); 36 pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs);
37} 37}
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
index 7fca47982277..3b9012f8e380 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
@@ -185,8 +185,6 @@ static int pvr2_i2c_basic_op(struct pvr2_hdw *hdw,
185 } 185 }
186} 186}
187 187
188#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
189
190/* This is a special entry point that is entered if an I2C operation is 188/* This is a special entry point that is entered if an I2C operation is
191 attempted to a wm8775 chip on model 24xxx hardware. Autodetect of this 189 attempted to a wm8775 chip on model 24xxx hardware. Autodetect of this
192 part doesn't work, but we know it is really there. So let's look for 190 part doesn't work, but we know it is really there. So let's look for
@@ -289,8 +287,6 @@ static int i2c_hack_cx25840(struct pvr2_hdw *hdw,
289 return -EIO; 287 return -EIO;
290} 288}
291 289
292#endif /* CONFIG_VIDEO_PVRUSB2_24XXX */
293
294/* This is a very, very limited I2C adapter implementation. We can only 290/* This is a very, very limited I2C adapter implementation. We can only
295 support what we actually know will work on the device... */ 291 support what we actually know will work on the device... */
296static int pvr2_i2c_xfer(struct i2c_adapter *i2c_adap, 292static int pvr2_i2c_xfer(struct i2c_adapter *i2c_adap,
@@ -897,14 +893,12 @@ void pvr2_i2c_core_init(struct pvr2_hdw *hdw)
897 hdw->i2c_func[idx] = pvr2_i2c_basic_op; 893 hdw->i2c_func[idx] = pvr2_i2c_basic_op;
898 } 894 }
899 895
900#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
901 // If however we're dealing with new hardware, insert some hacks in 896 // If however we're dealing with new hardware, insert some hacks in
902 // the I2C transfer stack to let things work better. 897 // the I2C transfer stack to let things work better.
903 if (hdw->hdw_type == PVR2_HDW_TYPE_24XXX) { 898 if (hdw->hdw_type == PVR2_HDW_TYPE_24XXX) {
904 hdw->i2c_func[0x1b] = i2c_hack_wm8775; 899 hdw->i2c_func[0x1b] = i2c_hack_wm8775;
905 hdw->i2c_func[0x44] = i2c_hack_cx25840; 900 hdw->i2c_func[0x44] = i2c_hack_cx25840;
906 } 901 }
907#endif
908 902
909 // Configure the adapter and set up everything else related to it. 903 // Configure the adapter and set up everything else related to it.
910 memcpy(&hdw->i2c_adap,&pvr2_i2c_adap_template,sizeof(hdw->i2c_adap)); 904 memcpy(&hdw->i2c_adap,&pvr2_i2c_adap_template,sizeof(hdw->i2c_adap));
diff --git a/drivers/media/video/pvrusb2/pvrusb2-main.c b/drivers/media/video/pvrusb2/pvrusb2-main.c
index 8f1a5afdd34e..e976c484c058 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-main.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-main.c
@@ -20,7 +20,6 @@
20 * 20 *
21 */ 21 */
22 22
23#include <linux/config.h>
24#include <linux/kernel.h> 23#include <linux/kernel.h>
25#include <linux/errno.h> 24#include <linux/errno.h>
26#include <linux/slab.h> 25#include <linux/slab.h>
diff --git a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
index d1dda5caf406..c294f46db9b9 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
@@ -19,7 +19,6 @@
19 * 19 *
20 */ 20 */
21 21
22#include <linux/config.h>
23#include <linux/string.h> 22#include <linux/string.h>
24#include <linux/slab.h> 23#include <linux/slab.h>
25#include <asm/semaphore.h> 24#include <asm/semaphore.h>
@@ -40,8 +39,6 @@ struct pvr2_sysfs {
40#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ 39#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
41 struct pvr2_sysfs_ctl_item *item_first; 40 struct pvr2_sysfs_ctl_item *item_first;
42 struct pvr2_sysfs_ctl_item *item_last; 41 struct pvr2_sysfs_ctl_item *item_last;
43 struct sysfs_ops kops;
44 struct kobj_type ktype;
45 struct class_device_attribute attr_v4l_minor_number; 42 struct class_device_attribute attr_v4l_minor_number;
46 struct class_device_attribute attr_unit_number; 43 struct class_device_attribute attr_unit_number;
47 int v4l_minor_number_created_ok; 44 int v4l_minor_number_created_ok;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
index 0caf70b8c0de..3608c2f81df9 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
@@ -459,18 +459,26 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
459 ret = 0; 459 ret = 0;
460 switch(vf->type) { 460 switch(vf->type) {
461 case V4L2_BUF_TYPE_VIDEO_CAPTURE: { 461 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
462 int lmin,lmax;
463 struct pvr2_ctrl *hcp,*vcp;
462 int h = vf->fmt.pix.height; 464 int h = vf->fmt.pix.height;
463 int w = vf->fmt.pix.width; 465 int w = vf->fmt.pix.width;
464 466 hcp = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_HRES);
465 if (h < 200) { 467 vcp = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_VRES);
466 h = 200; 468
467 } else if (h > 625) { 469 lmin = pvr2_ctrl_get_min(hcp);
468 h = 625; 470 lmax = pvr2_ctrl_get_max(hcp);
471 if (w < lmin) {
472 w = lmin;
473 } else if (w > lmax) {
474 w = lmax;
469 } 475 }
470 if (w < 320) { 476 lmin = pvr2_ctrl_get_min(vcp);
471 w = 320; 477 lmax = pvr2_ctrl_get_max(vcp);
472 } else if (w > 720) { 478 if (h < lmin) {
473 w = 720; 479 h = lmin;
480 } else if (h > lmax) {
481 h = lmax;
474 } 482 }
475 483
476 memcpy(vf, &pvr_format[PVR_FORMAT_PIX], 484 memcpy(vf, &pvr_format[PVR_FORMAT_PIX],
@@ -479,14 +487,8 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
479 vf->fmt.pix.height = h; 487 vf->fmt.pix.height = h;
480 488
481 if (cmd == VIDIOC_S_FMT) { 489 if (cmd == VIDIOC_S_FMT) {
482 pvr2_ctrl_set_value( 490 pvr2_ctrl_set_value(hcp,vf->fmt.pix.width);
483 pvr2_hdw_get_ctrl_by_id(hdw, 491 pvr2_ctrl_set_value(vcp,vf->fmt.pix.height);
484 PVR2_CID_HRES),
485 vf->fmt.pix.width);
486 pvr2_ctrl_set_value(
487 pvr2_hdw_get_ctrl_by_id(hdw,
488 PVR2_CID_VRES),
489 vf->fmt.pix.height);
490 } 492 }
491 } break; 493 } break;
492 case V4L2_BUF_TYPE_VBI_CAPTURE: 494 case V4L2_BUF_TYPE_VBI_CAPTURE:
diff --git a/drivers/media/video/pwc/pwc-if.c b/drivers/media/video/pwc/pwc-if.c
index d4703944df9c..53c4b5790d5c 100644
--- a/drivers/media/video/pwc/pwc-if.c
+++ b/drivers/media/video/pwc/pwc-if.c
@@ -711,7 +711,7 @@ static void pwc_isoc_handler(struct urb *urb, struct pt_regs *regs)
711 case -EOVERFLOW: errmsg = "Babble (bad cable?)"; break; 711 case -EOVERFLOW: errmsg = "Babble (bad cable?)"; break;
712 case -EPROTO: errmsg = "Bit-stuff error (bad cable?)"; break; 712 case -EPROTO: errmsg = "Bit-stuff error (bad cable?)"; break;
713 case -EILSEQ: errmsg = "CRC/Timeout (could be anything)"; break; 713 case -EILSEQ: errmsg = "CRC/Timeout (could be anything)"; break;
714 case -ETIMEDOUT: errmsg = "NAK (device does not respond)"; break; 714 case -ETIME: errmsg = "Device does not respond"; break;
715 } 715 }
716 PWC_DEBUG_FLOW("pwc_isoc_handler() called with status %d [%s].\n", urb->status, errmsg); 716 PWC_DEBUG_FLOW("pwc_isoc_handler() called with status %d [%s].\n", urb->status, errmsg);
717 /* Give up after a number of contiguous errors on the USB bus. 717 /* Give up after a number of contiguous errors on the USB bus.
diff --git a/drivers/media/video/saa5246a.c b/drivers/media/video/saa5246a.c
index 59a187272c83..77bb940a1a4f 100644
--- a/drivers/media/video/saa5246a.c
+++ b/drivers/media/video/saa5246a.c
@@ -830,7 +830,6 @@ static struct video_device saa_template =
830 .owner = THIS_MODULE, 830 .owner = THIS_MODULE,
831 .name = IF_NAME, 831 .name = IF_NAME,
832 .type = VID_TYPE_TELETEXT, 832 .type = VID_TYPE_TELETEXT,
833 .hardware = VID_HARDWARE_SAA5249,
834 .fops = &saa_fops, 833 .fops = &saa_fops,
835 .release = video_device_release, 834 .release = video_device_release,
836 .minor = -1, 835 .minor = -1,
diff --git a/drivers/media/video/saa5249.c b/drivers/media/video/saa5249.c
index 19a8d65699f8..bb3fb4387f65 100644
--- a/drivers/media/video/saa5249.c
+++ b/drivers/media/video/saa5249.c
@@ -713,7 +713,6 @@ static struct video_device saa_template =
713 .owner = THIS_MODULE, 713 .owner = THIS_MODULE,
714 .name = IF_NAME, 714 .name = IF_NAME,
715 .type = VID_TYPE_TELETEXT, /*| VID_TYPE_TUNER ?? */ 715 .type = VID_TYPE_TELETEXT, /*| VID_TYPE_TUNER ?? */
716 .hardware = VID_HARDWARE_SAA5249,
717 .fops = &saa_fops, 716 .fops = &saa_fops,
718}; 717};
719 718
diff --git a/drivers/media/video/saa7115.c b/drivers/media/video/saa7115.c
index b59c11717273..974179d4d389 100644
--- a/drivers/media/video/saa7115.c
+++ b/drivers/media/video/saa7115.c
@@ -1,4 +1,6 @@
1/* saa7115 - Philips SAA7113/SAA7114/SAA7115 video decoder driver 1/* saa711x - Philips SAA711x video decoder driver
2 * This driver can work with saa7111, saa7111a, saa7113, saa7114,
3 * saa7115 and saa7118.
2 * 4 *
3 * Based on saa7114 driver by Maxim Yevtyushkin, which is based on 5 * Based on saa7114 driver by Maxim Yevtyushkin, which is based on
4 * the saa7111 driver by Dave Perks. 6 * the saa7111 driver by Dave Perks.
@@ -16,7 +18,9 @@
16 * (2/17/2003) 18 * (2/17/2003)
17 * 19 *
18 * VBI support (2004) and cleanups (2005) by Hans Verkuil <hverkuil@xs4all.nl> 20 * VBI support (2004) and cleanups (2005) by Hans Verkuil <hverkuil@xs4all.nl>
19 * SAA7113 support by Mauro Carvalho Chehab <mchehab@infradead.org> 21 *
22 * Copyright (c) 2005-2006 Mauro Carvalho Chehab <mchehab@infradead.org>
23 * SAA7111, SAA7113 and SAA7118 support
20 * 24 *
21 * This program is free software; you can redistribute it and/or 25 * This program is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU General Public License 26 * modify it under the terms of the GNU General Public License
@@ -33,6 +37,7 @@
33 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 37 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
34 */ 38 */
35 39
40#include "saa711x_regs.h"
36 41
37#include <linux/kernel.h> 42#include <linux/kernel.h>
38#include <linux/module.h> 43#include <linux/module.h>
@@ -43,7 +48,9 @@
43#include <media/saa7115.h> 48#include <media/saa7115.h>
44#include <asm/div64.h> 49#include <asm/div64.h>
45 50
46MODULE_DESCRIPTION("Philips SAA7113/SAA7114/SAA7115 video decoder driver"); 51#define VRES_60HZ (480+16)
52
53MODULE_DESCRIPTION("Philips SAA7111/SAA7113/SAA7114/SAA7115/SAA7118 video decoder driver");
47MODULE_AUTHOR( "Maxim Yevtyushkin, Kevin Thayer, Chris Kennedy, " 54MODULE_AUTHOR( "Maxim Yevtyushkin, Kevin Thayer, Chris Kennedy, "
48 "Hans Verkuil, Mauro Carvalho Chehab"); 55 "Hans Verkuil, Mauro Carvalho Chehab");
49MODULE_LICENSE("GPL"); 56MODULE_LICENSE("GPL");
@@ -54,14 +61,14 @@ module_param(debug, bool, 0644);
54MODULE_PARM_DESC(debug, "Debug level (0-1)"); 61MODULE_PARM_DESC(debug, "Debug level (0-1)");
55 62
56static unsigned short normal_i2c[] = { 63static unsigned short normal_i2c[] = {
57 0x4a >> 1, 0x48 >> 1, /* SAA7113 */ 64 0x4a >> 1, 0x48 >> 1, /* SAA7111, SAA7111A and SAA7113 */
58 0x42 >> 1, 0x40 >> 1, /* SAA7114 and SAA7115 */ 65 0x42 >> 1, 0x40 >> 1, /* SAA7114, SAA7115 and SAA7118 */
59 I2C_CLIENT_END }; 66 I2C_CLIENT_END };
60 67
61 68
62I2C_CLIENT_INSMOD; 69I2C_CLIENT_INSMOD;
63 70
64struct saa7115_state { 71struct saa711x_state {
65 v4l2_std_id std; 72 v4l2_std_id std;
66 int input; 73 int input;
67 int enable; 74 int enable;
@@ -70,6 +77,8 @@ struct saa7115_state {
70 int contrast; 77 int contrast;
71 int hue; 78 int hue;
72 int sat; 79 int sat;
80 int width;
81 int height;
73 enum v4l2_chip_ident ident; 82 enum v4l2_chip_ident ident;
74 u32 audclk_freq; 83 u32 audclk_freq;
75 u32 crystal_freq; 84 u32 crystal_freq;
@@ -80,420 +89,508 @@ struct saa7115_state {
80 89
81/* ----------------------------------------------------------------------- */ 90/* ----------------------------------------------------------------------- */
82 91
83static inline int saa7115_write(struct i2c_client *client, u8 reg, u8 value) 92static inline int saa711x_write(struct i2c_client *client, u8 reg, u8 value)
84{ 93{
85 return i2c_smbus_write_byte_data(client, reg, value); 94 return i2c_smbus_write_byte_data(client, reg, value);
86} 95}
87 96
88static int saa7115_writeregs(struct i2c_client *client, const unsigned char *regs) 97/* Sanity routine to check if a register is present */
98static int saa711x_has_reg(const int id, const u8 reg)
89{ 99{
100 if (id == V4L2_IDENT_SAA7111)
101 return reg < 0x20 && reg != 0x01 && reg != 0x0f &&
102 (reg < 0x13 || reg > 0x19) && reg != 0x1d && reg != 0x1e;
103
104 /* common for saa7113/4/5/8 */
105 if (unlikely((reg >= 0x3b && reg <= 0x3f) || reg == 0x5c || reg == 0x5f ||
106 reg == 0xa3 || reg == 0xa7 || reg == 0xab || reg == 0xaf || (reg >= 0xb5 && reg <= 0xb7) ||
107 reg == 0xd3 || reg == 0xd7 || reg == 0xdb || reg == 0xdf || (reg >= 0xe5 && reg <= 0xe7) ||
108 reg == 0x82 || (reg >= 0x89 && reg <= 0x8e)))
109 return 0;
110
111 switch (id) {
112 case V4L2_IDENT_SAA7113:
113 return reg != 0x14 && (reg < 0x18 || reg > 0x1e) && (reg < 0x20 || reg > 0x3f) &&
114 reg != 0x5d && reg < 0x63;
115 case V4L2_IDENT_SAA7114:
116 return (reg < 0x1a || reg > 0x1e) && (reg < 0x20 || reg > 0x2f) &&
117 (reg < 0x63 || reg > 0x7f) && reg != 0x33 && reg != 0x37 &&
118 reg != 0x81 && reg < 0xf0;
119 case V4L2_IDENT_SAA7115:
120 return (reg < 0x20 || reg > 0x2f) && reg != 0x65 && (reg < 0xfc || reg > 0xfe);
121 case V4L2_IDENT_SAA7118:
122 return (reg < 0x1a || reg > 0x1d) && (reg < 0x20 || reg > 0x22) &&
123 (reg < 0x26 || reg > 0x28) && reg != 0x33 && reg != 0x37 &&
124 (reg < 0x63 || reg > 0x7f) && reg != 0x81 && reg < 0xf0;
125 }
126 return 1;
127}
128
129static int saa711x_writeregs(struct i2c_client *client, const unsigned char *regs)
130{
131 struct saa711x_state *state = i2c_get_clientdata(client);
90 unsigned char reg, data; 132 unsigned char reg, data;
91 133
92 while (*regs != 0x00) { 134 while (*regs != 0x00) {
93 reg = *(regs++); 135 reg = *(regs++);
94 data = *(regs++); 136 data = *(regs++);
95 if (saa7115_write(client, reg, data) < 0) 137
96 return -1; 138 /* According with datasheets, reserved regs should be
139 filled with 0 - seems better not to touch on they */
140 if (saa711x_has_reg(state->ident,reg)) {
141 if (saa711x_write(client, reg, data) < 0)
142 return -1;
143 } else {
144 v4l_dbg(1, debug, client, "tried to access reserved reg 0x%02x\n", reg);
145 }
97 } 146 }
98 return 0; 147 return 0;
99} 148}
100 149
101static inline int saa7115_read(struct i2c_client *client, u8 reg) 150static inline int saa711x_read(struct i2c_client *client, u8 reg)
102{ 151{
103 return i2c_smbus_read_byte_data(client, reg); 152 return i2c_smbus_read_byte_data(client, reg);
104} 153}
105 154
106/* ----------------------------------------------------------------------- */ 155/* ----------------------------------------------------------------------- */
107 156
157/* SAA7111 initialization table */
158static const unsigned char saa7111_init[] = {
159 R_01_INC_DELAY, 0x00, /* reserved */
160
161 /*front end */
162 R_02_INPUT_CNTL_1, 0xd0, /* FUSE=3, GUDL=2, MODE=0 */
163 R_03_INPUT_CNTL_2, 0x23, /* HLNRS=0, VBSL=1, WPOFF=0, HOLDG=0,
164 * GAFIX=0, GAI1=256, GAI2=256 */
165 R_04_INPUT_CNTL_3, 0x00, /* GAI1=256 */
166 R_05_INPUT_CNTL_4, 0x00, /* GAI2=256 */
167
168 /* decoder */
169 R_06_H_SYNC_START, 0xf3, /* HSB at 13(50Hz) / 17(60Hz)
170 * pixels after end of last line */
171 R_07_H_SYNC_STOP, 0xe8, /* HSS seems to be needed to
172 * work with NTSC, too */
173 R_08_SYNC_CNTL, 0xc8, /* AUFD=1, FSEL=1, EXFIL=0,
174 * VTRC=1, HPLL=0, VNOI=0 */
175 R_09_LUMA_CNTL, 0x01, /* BYPS=0, PREF=0, BPSS=0,
176 * VBLB=0, UPTCV=0, APER=1 */
177 R_0A_LUMA_BRIGHT_CNTL, 0x80,
178 R_0B_LUMA_CONTRAST_CNTL, 0x47, /* 0b - CONT=1.109 */
179 R_0C_CHROMA_SAT_CNTL, 0x40,
180 R_0D_CHROMA_HUE_CNTL, 0x00,
181 R_0E_CHROMA_CNTL_1, 0x01, /* 0e - CDTO=0, CSTD=0, DCCF=0,
182 * FCTC=0, CHBW=1 */
183 R_0F_CHROMA_GAIN_CNTL, 0x00, /* reserved */
184 R_10_CHROMA_CNTL_2, 0x48, /* 10 - OFTS=1, HDEL=0, VRLN=1, YDEL=0 */
185 R_11_MODE_DELAY_CNTL, 0x1c, /* 11 - GPSW=0, CM99=0, FECO=0, COMPO=1,
186 * OEYC=1, OEHV=1, VIPB=0, COLO=0 */
187 R_12_RT_SIGNAL_CNTL, 0x00, /* 12 - output control 2 */
188 R_13_RT_X_PORT_OUT_CNTL, 0x00, /* 13 - output control 3 */
189 R_14_ANAL_ADC_COMPAT_CNTL, 0x00,
190 R_15_VGATE_START_FID_CHG, 0x00,
191 R_16_VGATE_STOP, 0x00,
192 R_17_MISC_VGATE_CONF_AND_MSB, 0x00,
193
194 0x00, 0x00
195};
196
197/* SAA7113 init codes */
198static const unsigned char saa7113_init[] = {
199 R_01_INC_DELAY, 0x08,
200 R_02_INPUT_CNTL_1, 0xc2,
201 R_03_INPUT_CNTL_2, 0x30,
202 R_04_INPUT_CNTL_3, 0x00,
203 R_05_INPUT_CNTL_4, 0x00,
204 R_06_H_SYNC_START, 0x89,
205 R_07_H_SYNC_STOP, 0x0d,
206 R_08_SYNC_CNTL, 0x88,
207 R_09_LUMA_CNTL, 0x01,
208 R_0A_LUMA_BRIGHT_CNTL, 0x80,
209 R_0B_LUMA_CONTRAST_CNTL, 0x47,
210 R_0C_CHROMA_SAT_CNTL, 0x40,
211 R_0D_CHROMA_HUE_CNTL, 0x00,
212 R_0E_CHROMA_CNTL_1, 0x01,
213 R_0F_CHROMA_GAIN_CNTL, 0x2a,
214 R_10_CHROMA_CNTL_2, 0x08,
215 R_11_MODE_DELAY_CNTL, 0x0c,
216 R_12_RT_SIGNAL_CNTL, 0x07,
217 R_13_RT_X_PORT_OUT_CNTL, 0x00,
218 R_14_ANAL_ADC_COMPAT_CNTL, 0x00,
219 R_15_VGATE_START_FID_CHG, 0x00,
220 R_16_VGATE_STOP, 0x00,
221 R_17_MISC_VGATE_CONF_AND_MSB, 0x00,
222
223 0x00, 0x00
224};
225
108/* If a value differs from the Hauppauge driver values, then the comment starts with 226/* If a value differs from the Hauppauge driver values, then the comment starts with
109 'was 0xXX' to denote the Hauppauge value. Otherwise the value is identical to what the 227 'was 0xXX' to denote the Hauppauge value. Otherwise the value is identical to what the
110 Hauppauge driver sets. */ 228 Hauppauge driver sets. */
111 229
230/* SAA7114 and SAA7115 initialization table */
112static const unsigned char saa7115_init_auto_input[] = { 231static const unsigned char saa7115_init_auto_input[] = {
113 /* Front-End Part */ 232 /* Front-End Part */
114 0x01, 0x48, /* white peak control disabled */ 233 R_01_INC_DELAY, 0x48, /* white peak control disabled */
115 0x03, 0x20, /* was 0x30. 0x20: long vertical blanking */ 234 R_03_INPUT_CNTL_2, 0x20, /* was 0x30. 0x20: long vertical blanking */
116 0x04, 0x90, /* analog gain set to 0 */ 235 R_04_INPUT_CNTL_3, 0x90, /* analog gain set to 0 */
117 0x05, 0x90, /* analog gain set to 0 */ 236 R_05_INPUT_CNTL_4, 0x90, /* analog gain set to 0 */
118 /* Decoder Part */ 237 /* Decoder Part */
119 0x06, 0xeb, /* horiz sync begin = -21 */ 238 R_06_H_SYNC_START, 0xeb, /* horiz sync begin = -21 */
120 0x07, 0xe0, /* horiz sync stop = -17 */ 239 R_07_H_SYNC_STOP, 0xe0, /* horiz sync stop = -17 */
121 0x0a, 0x80, /* was 0x88. decoder brightness, 0x80 is itu standard */ 240 R_09_LUMA_CNTL, 0x53, /* 0x53, was 0x56 for 60hz. luminance control */
122 0x0b, 0x44, /* was 0x48. decoder contrast, 0x44 is itu standard */ 241 R_0A_LUMA_BRIGHT_CNTL, 0x80, /* was 0x88. decoder brightness, 0x80 is itu standard */
123 0x0c, 0x40, /* was 0x47. decoder saturation, 0x40 is itu standard */ 242 R_0B_LUMA_CONTRAST_CNTL, 0x44, /* was 0x48. decoder contrast, 0x44 is itu standard */
124 0x0d, 0x00, /* chrominance hue control */ 243 R_0C_CHROMA_SAT_CNTL, 0x40, /* was 0x47. decoder saturation, 0x40 is itu standard */
125 0x0f, 0x00, /* chrominance gain control: use automicatic mode */ 244 R_0D_CHROMA_HUE_CNTL, 0x00,
126 0x10, 0x06, /* chrominance/luminance control: active adaptive combfilter */ 245 R_0F_CHROMA_GAIN_CNTL, 0x00, /* use automatic gain */
127 0x11, 0x00, /* delay control */ 246 R_10_CHROMA_CNTL_2, 0x06, /* chroma: active adaptive combfilter */
128 0x12, 0x9d, /* RTS0 output control: VGATE */ 247 R_11_MODE_DELAY_CNTL, 0x00,
129 0x13, 0x80, /* X-port output control: ITU656 standard mode, RTCO output enable RTCE */ 248 R_12_RT_SIGNAL_CNTL, 0x9d, /* RTS0 output control: VGATE */
130 0x14, 0x00, /* analog/ADC/auto compatibility control */ 249 R_13_RT_X_PORT_OUT_CNTL, 0x80, /* ITU656 standard mode, RTCO output enable RTCE */
131 0x18, 0x40, /* raw data gain 0x00 = nominal */ 250 R_14_ANAL_ADC_COMPAT_CNTL, 0x00,
132 0x19, 0x80, /* raw data offset 0x80 = 0 LSB */ 251 R_18_RAW_DATA_GAIN_CNTL, 0x40, /* gain 0x00 = nominal */
133 0x1a, 0x77, /* color killer level control 0x77 = recommended */ 252 R_19_RAW_DATA_OFF_CNTL, 0x80,
134 0x1b, 0x42, /* misc chroma control 0x42 = recommended */ 253 R_1A_COLOR_KILL_LVL_CNTL, 0x77, /* recommended value */
135 0x1c, 0xa9, /* combfilter control 0xA9 = recommended */ 254 R_1B_MISC_TVVCRDET, 0x42, /* recommended value */
136 0x1d, 0x01, /* combfilter control 0x01 = recommended */ 255 R_1C_ENHAN_COMB_CTRL1, 0xa9, /* recommended value */
256 R_1D_ENHAN_COMB_CTRL2, 0x01, /* recommended value */
257
258
259 R_80_GLOBAL_CNTL_1, 0x0, /* No tasks enabled at init */
137 260
138 /* Power Device Control */ 261 /* Power Device Control */
139 0x88, 0xd0, /* reset device */ 262 R_88_POWER_SAVE_ADC_PORT_CNTL, 0xd0, /* reset device */
140 0x88, 0xf0, /* set device programmed, all in operational mode */ 263 R_88_POWER_SAVE_ADC_PORT_CNTL, 0xf0, /* set device programmed, all in operational mode */
141 0x00, 0x00 264 0x00, 0x00
142}; 265};
143 266
267/* Used to reset saa7113, saa7114 and saa7115 */
144static const unsigned char saa7115_cfg_reset_scaler[] = { 268static const unsigned char saa7115_cfg_reset_scaler[] = {
145 0x87, 0x00, /* disable I-port output */ 269 R_87_I_PORT_I_O_ENA_OUT_CLK_AND_GATED, 0x00, /* disable I-port output */
146 0x88, 0xd0, /* reset scaler */ 270 R_88_POWER_SAVE_ADC_PORT_CNTL, 0xd0, /* reset scaler */
147 0x88, 0xf0, /* activate scaler */ 271 R_88_POWER_SAVE_ADC_PORT_CNTL, 0xf0, /* activate scaler */
148 0x87, 0x01, /* enable I-port output */ 272 R_87_I_PORT_I_O_ENA_OUT_CLK_AND_GATED, 0x01, /* enable I-port output */
149 0x00, 0x00 273 0x00, 0x00
150}; 274};
151 275
152/* ============== SAA7715 VIDEO templates ============= */ 276/* ============== SAA7715 VIDEO templates ============= */
153 277
154static const unsigned char saa7115_cfg_60hz_fullres_x[] = { 278static const unsigned char saa7115_cfg_60hz_video[] = {
155 0xcc, 0xd0, /* hsize low (output), hor. output window size = 0x2d0 = 720 */ 279 R_80_GLOBAL_CNTL_1, 0x00, /* reset tasks */
156 0xcd, 0x02, /* hsize hi (output) */ 280 R_88_POWER_SAVE_ADC_PORT_CNTL, 0xd0, /* reset scaler */
157 281
158 /* Why not in 60hz-Land, too? */ 282 R_15_VGATE_START_FID_CHG, 0x03,
159 0xd0, 0x01, /* downscale = 1 */ 283 R_16_VGATE_STOP, 0x11,
160 0xd8, 0x00, /* hor lum scaling 0x0400 = 1 */ 284 R_17_MISC_VGATE_CONF_AND_MSB, 0x9c,
161 0xd9, 0x04,
162 0xdc, 0x00, /* hor chrom scaling 0x0200. must be hor lum scaling / 2 */
163 0xdd, 0x02, /* H-scaling incr chroma */
164 285
165 0x00, 0x00 286 R_08_SYNC_CNTL, 0x68, /* 0xBO: auto detection, 0x68 = NTSC */
166}; 287 R_0E_CHROMA_CNTL_1, 0x07, /* video autodetection is on */
167static const unsigned char saa7115_cfg_60hz_fullres_y[] = {
168 0xce, 0xf8, /* vsize low (output), ver. output window size = 248 (but 60hz is 240?) */
169 0xcf, 0x00, /* vsize hi (output) */
170 288
171 /* Why not in 60hz-Land, too? */ 289 R_5A_V_OFF_FOR_SLICER, 0x06, /* standard 60hz value for ITU656 line counting */
172 0xd5, 0x40, /* Lum contrast, nominal value = 0x40 */
173 0xd6, 0x40, /* Chroma satur. nominal value = 0x80 */
174 290
175 0xe0, 0x00, /* V-scaling incr luma low */ 291 /* Task A */
176 0xe1, 0x04, /* " hi */ 292 R_90_A_TASK_HANDLING_CNTL, 0x80,
177 0xe2, 0x00, /* V-scaling incr chroma low */ 293 R_91_A_X_PORT_FORMATS_AND_CONF, 0x48,
178 0xe3, 0x04, /* " hi */ 294 R_92_A_X_PORT_INPUT_REFERENCE_SIGNAL, 0x40,
295 R_93_A_I_PORT_OUTPUT_FORMATS_AND_CONF, 0x84,
179 296
180 0x00, 0x00 297 /* hoffset low (input), 0x0002 is minimum */
181}; 298 R_94_A_HORIZ_INPUT_WINDOW_START, 0x01,
299 R_95_A_HORIZ_INPUT_WINDOW_START_MSB, 0x00,
182 300
183static const unsigned char saa7115_cfg_60hz_video[] = { 301 /* hsize low (input), 0x02d0 = 720 */
184 0x80, 0x00, /* reset tasks */ 302 R_96_A_HORIZ_INPUT_WINDOW_LENGTH, 0xd0,
185 0x88, 0xd0, /* reset scaler */ 303 R_97_A_HORIZ_INPUT_WINDOW_LENGTH_MSB, 0x02,
186 304
187 0x15, 0x03, /* VGATE pulse start */ 305 R_98_A_VERT_INPUT_WINDOW_START, 0x05,
188 0x16, 0x11, /* VGATE pulse stop */ 306 R_99_A_VERT_INPUT_WINDOW_START_MSB, 0x00,
189 0x17, 0x9c, /* VGATE MSB and other values */
190 307
191 0x08, 0x68, /* 0xBO: auto detection, 0x68 = NTSC */ 308 R_9A_A_VERT_INPUT_WINDOW_LENGTH, 0x0c,
192 0x0e, 0x07, /* lots of different stuff... video autodetection is on */ 309 R_9B_A_VERT_INPUT_WINDOW_LENGTH_MSB, 0x00,
193 310
194 0x5a, 0x06, /* Vertical offset, standard 60hz value for ITU656 line counting */ 311 R_9C_A_HORIZ_OUTPUT_WINDOW_LENGTH, 0xa0,
312 R_9D_A_HORIZ_OUTPUT_WINDOW_LENGTH_MSB, 0x05,
195 313
196 /* Task A */ 314 R_9E_A_VERT_OUTPUT_WINDOW_LENGTH, 0x0c,
197 0x90, 0x80, /* Task Handling Control */ 315 R_9F_A_VERT_OUTPUT_WINDOW_LENGTH_MSB, 0x00,
198 0x91, 0x48, /* X-port formats/config */
199 0x92, 0x40, /* Input Ref. signal Def. */
200 0x93, 0x84, /* I-port config */
201 0x94, 0x01, /* hoffset low (input), 0x0002 is minimum */
202 0x95, 0x00, /* hoffset hi (input) */
203 0x96, 0xd0, /* hsize low (input), 0x02d0 = 720 */
204 0x97, 0x02, /* hsize hi (input) */
205 0x98, 0x05, /* voffset low (input) */
206 0x99, 0x00, /* voffset hi (input) */
207 0x9a, 0x0c, /* vsize low (input), 0x0c = 12 */
208 0x9b, 0x00, /* vsize hi (input) */
209 0x9c, 0xa0, /* hsize low (output), 0x05a0 = 1440 */
210 0x9d, 0x05, /* hsize hi (output) */
211 0x9e, 0x0c, /* vsize low (output), 0x0c = 12 */
212 0x9f, 0x00, /* vsize hi (output) */
213 316
214 /* Task B */ 317 /* Task B */
215 0xc0, 0x00, /* Task Handling Control */ 318 R_C0_B_TASK_HANDLING_CNTL, 0x00,
216 0xc1, 0x08, /* X-port formats/config */ 319 R_C1_B_X_PORT_FORMATS_AND_CONF, 0x08,
217 0xc2, 0x00, /* Input Ref. signal Def. */ 320 R_C2_B_INPUT_REFERENCE_SIGNAL_DEFINITION, 0x00,
218 0xc3, 0x80, /* I-port config */ 321 R_C3_B_I_PORT_FORMATS_AND_CONF, 0x80,
219 0xc4, 0x02, /* hoffset low (input), 0x0002 is minimum */
220 0xc5, 0x00, /* hoffset hi (input) */
221 0xc6, 0xd0, /* hsize low (input), 0x02d0 = 720 */
222 0xc7, 0x02, /* hsize hi (input) */
223 0xc8, 0x12, /* voffset low (input), 0x12 = 18 */
224 0xc9, 0x00, /* voffset hi (input) */
225 0xca, 0xf8, /* vsize low (input), 0xf8 = 248 */
226 0xcb, 0x00, /* vsize hi (input) */
227 0xcc, 0xd0, /* hsize low (output), 0x02d0 = 720 */
228 0xcd, 0x02, /* hsize hi (output) */
229
230 0xf0, 0xad, /* Set PLL Register. 60hz 525 lines per frame, 27 MHz */
231 0xf1, 0x05, /* low bit with 0xF0 */
232 0xf5, 0xad, /* Set pulse generator register */
233 0xf6, 0x01,
234
235 0x87, 0x00, /* Disable I-port output */
236 0x88, 0xd0, /* reset scaler */
237 0x80, 0x20, /* Activate only task "B", continuous mode (was 0xA0) */
238 0x88, 0xf0, /* activate scaler */
239 0x87, 0x01, /* Enable I-port output */
240 0x00, 0x00
241};
242 322
243static const unsigned char saa7115_cfg_50hz_fullres_x[] = { 323 /* 0x0002 is minimum */
244 0xcc, 0xd0, /* hsize low (output), 720 same as 60hz */ 324 R_C4_B_HORIZ_INPUT_WINDOW_START, 0x02,
245 0xcd, 0x02, /* hsize hi (output) */ 325 R_C5_B_HORIZ_INPUT_WINDOW_START_MSB, 0x00,
246 326
247 0xd0, 0x01, /* down scale = 1 */ 327 /* 0x02d0 = 720 */
248 0xd8, 0x00, /* hor lum scaling 0x0400 = 1 */ 328 R_C6_B_HORIZ_INPUT_WINDOW_LENGTH, 0xd0,
249 0xd9, 0x04, 329 R_C7_B_HORIZ_INPUT_WINDOW_LENGTH_MSB, 0x02,
250 0xdc, 0x00, /* hor chrom scaling 0x0200. must be hor lum scaling / 2 */
251 0xdd, 0x02, /* H-scaling incr chroma */
252 330
253 0x00, 0x00 331 /* vwindow start 0x12 = 18 */
254}; 332 R_C8_B_VERT_INPUT_WINDOW_START, 0x12,
255static const unsigned char saa7115_cfg_50hz_fullres_y[] = { 333 R_C9_B_VERT_INPUT_WINDOW_START_MSB, 0x00,
256 0xce, 0x20, /* vsize low (output), 0x0120 = 288 */ 334
257 0xcf, 0x01, /* vsize hi (output) */ 335 /* vwindow length 0xf8 = 248 */
336 R_CA_B_VERT_INPUT_WINDOW_LENGTH, VRES_60HZ>>1,
337 R_CB_B_VERT_INPUT_WINDOW_LENGTH_MSB, VRES_60HZ>>9,
258 338
259 0xd5, 0x40, /* Lum contrast, nominal value = 0x40 */ 339 /* hwindow 0x02d0 = 720 */
260 0xd6, 0x40, /* Chroma satur. nominal value = 0x80 */ 340 R_CC_B_HORIZ_OUTPUT_WINDOW_LENGTH, 0xd0,
341 R_CD_B_HORIZ_OUTPUT_WINDOW_LENGTH_MSB, 0x02,
261 342
262 0xe0, 0x00, /* V-scaling incr luma low */ 343 R_F0_LFCO_PER_LINE, 0xad, /* Set PLL Register. 60hz 525 lines per frame, 27 MHz */
263 0xe1, 0x04, /* " hi */ 344 R_F1_P_I_PARAM_SELECT, 0x05, /* low bit with 0xF0 */
264 0xe2, 0x00, /* V-scaling incr chroma low */ 345 R_F5_PULSGEN_LINE_LENGTH, 0xad,
265 0xe3, 0x04, /* " hi */ 346 R_F6_PULSE_A_POS_LSB_AND_PULSEGEN_CONFIG, 0x01,
266 347
267 0x00, 0x00 348 0x00, 0x00
268}; 349};
269 350
270static const unsigned char saa7115_cfg_50hz_video[] = { 351static const unsigned char saa7115_cfg_50hz_video[] = {
271 0x80, 0x00, /* reset tasks */ 352 R_80_GLOBAL_CNTL_1, 0x00,
272 0x88, 0xd0, /* reset scaler */ 353 R_88_POWER_SAVE_ADC_PORT_CNTL, 0xd0, /* reset scaler */
273 354
274 0x15, 0x37, /* VGATE start */ 355 R_15_VGATE_START_FID_CHG, 0x37, /* VGATE start */
275 0x16, 0x16, /* VGATE stop */ 356 R_16_VGATE_STOP, 0x16,
276 0x17, 0x99, /* VGATE MSB and other values */ 357 R_17_MISC_VGATE_CONF_AND_MSB, 0x99,
277 358
278 0x08, 0x28, /* 0x28 = PAL */ 359 R_08_SYNC_CNTL, 0x28, /* 0x28 = PAL */
279 0x0e, 0x07, /* chrominance control 1 */ 360 R_0E_CHROMA_CNTL_1, 0x07,
280 361
281 0x5a, 0x03, /* Vertical offset, standard 50hz value */ 362 R_5A_V_OFF_FOR_SLICER, 0x03, /* standard 50hz value */
282 363
283 /* Task A */ 364 /* Task A */
284 0x90, 0x81, /* Task Handling Control */ 365 R_90_A_TASK_HANDLING_CNTL, 0x81,
285 0x91, 0x48, /* X-port formats/config */ 366 R_91_A_X_PORT_FORMATS_AND_CONF, 0x48,
286 0x92, 0x40, /* Input Ref. signal Def. */ 367 R_92_A_X_PORT_INPUT_REFERENCE_SIGNAL, 0x40,
287 0x93, 0x84, /* I-port config */ 368 R_93_A_I_PORT_OUTPUT_FORMATS_AND_CONF, 0x84,
369
288 /* This is weird: the datasheet says that you should use 2 as the minimum value, */ 370 /* This is weird: the datasheet says that you should use 2 as the minimum value, */
289 /* but Hauppauge uses 0, and changing that to 2 causes indeed problems (for 50hz) */ 371 /* but Hauppauge uses 0, and changing that to 2 causes indeed problems (for 50hz) */
290 0x94, 0x00, /* hoffset low (input), 0x0002 is minimum */ 372 /* hoffset low (input), 0x0002 is minimum */
291 0x95, 0x00, /* hoffset hi (input) */ 373 R_94_A_HORIZ_INPUT_WINDOW_START, 0x00,
292 0x96, 0xd0, /* hsize low (input), 0x02d0 = 720 */ 374 R_95_A_HORIZ_INPUT_WINDOW_START_MSB, 0x00,
293 0x97, 0x02, /* hsize hi (input) */ 375
294 0x98, 0x03, /* voffset low (input) */ 376 /* hsize low (input), 0x02d0 = 720 */
295 0x99, 0x00, /* voffset hi (input) */ 377 R_96_A_HORIZ_INPUT_WINDOW_LENGTH, 0xd0,
296 0x9a, 0x12, /* vsize low (input), 0x12 = 18 */ 378 R_97_A_HORIZ_INPUT_WINDOW_LENGTH_MSB, 0x02,
297 0x9b, 0x00, /* vsize hi (input) */ 379
298 0x9c, 0xa0, /* hsize low (output), 0x05a0 = 1440 */ 380 R_98_A_VERT_INPUT_WINDOW_START, 0x03,
299 0x9d, 0x05, /* hsize hi (output) */ 381 R_99_A_VERT_INPUT_WINDOW_START_MSB, 0x00,
300 0x9e, 0x12, /* vsize low (output), 0x12 = 18 */ 382
301 0x9f, 0x00, /* vsize hi (output) */ 383 /* vsize 0x12 = 18 */
384 R_9A_A_VERT_INPUT_WINDOW_LENGTH, 0x12,
385 R_9B_A_VERT_INPUT_WINDOW_LENGTH_MSB, 0x00,
386
387 /* hsize 0x05a0 = 1440 */
388 R_9C_A_HORIZ_OUTPUT_WINDOW_LENGTH, 0xa0,
389 R_9D_A_HORIZ_OUTPUT_WINDOW_LENGTH_MSB, 0x05, /* hsize hi (output) */
390 R_9E_A_VERT_OUTPUT_WINDOW_LENGTH, 0x12, /* vsize low (output), 0x12 = 18 */
391 R_9F_A_VERT_OUTPUT_WINDOW_LENGTH_MSB, 0x00, /* vsize hi (output) */
302 392
303 /* Task B */ 393 /* Task B */
304 0xc0, 0x00, /* Task Handling Control */ 394 R_C0_B_TASK_HANDLING_CNTL, 0x00,
305 0xc1, 0x08, /* X-port formats/config */ 395 R_C1_B_X_PORT_FORMATS_AND_CONF, 0x08,
306 0xc2, 0x00, /* Input Ref. signal Def. */ 396 R_C2_B_INPUT_REFERENCE_SIGNAL_DEFINITION, 0x00,
307 0xc3, 0x80, /* I-port config */ 397 R_C3_B_I_PORT_FORMATS_AND_CONF, 0x80,
308 0xc4, 0x00, /* hoffset low (input), 0x0002 is minimum. See comment at 0x94 above. */ 398
309 0xc5, 0x00, /* hoffset hi (input) */ 399 /* This is weird: the datasheet says that you should use 2 as the minimum value, */
310 0xc6, 0xd0, /* hsize low (input), 0x02d0 = 720 */ 400 /* but Hauppauge uses 0, and changing that to 2 causes indeed problems (for 50hz) */
311 0xc7, 0x02, /* hsize hi (input) */ 401 /* hoffset low (input), 0x0002 is minimum. See comment above. */
312 0xc8, 0x16, /* voffset low (input), 0x16 = 22 */ 402 R_C4_B_HORIZ_INPUT_WINDOW_START, 0x00,
313 0xc9, 0x00, /* voffset hi (input) */ 403 R_C5_B_HORIZ_INPUT_WINDOW_START_MSB, 0x00,
314 0xca, 0x20, /* vsize low (input), 0x0120 = 288 */ 404
315 0xcb, 0x01, /* vsize hi (input) */ 405 /* hsize 0x02d0 = 720 */
316 0xcc, 0xd0, /* hsize low (output), 0x02d0 = 720 */ 406 R_C6_B_HORIZ_INPUT_WINDOW_LENGTH, 0xd0,
317 0xcd, 0x02, /* hsize hi (output) */ 407 R_C7_B_HORIZ_INPUT_WINDOW_LENGTH_MSB, 0x02,
318 0xce, 0x20, /* vsize low (output), 0x0120 = 288 */ 408
319 0xcf, 0x01, /* vsize hi (output) */ 409 /* voffset 0x16 = 22 */
320 410 R_C8_B_VERT_INPUT_WINDOW_START, 0x16,
321 0xf0, 0xb0, /* Set PLL Register. 50hz 625 lines per frame, 27 MHz */ 411 R_C9_B_VERT_INPUT_WINDOW_START_MSB, 0x00,
322 0xf1, 0x05, /* low bit with 0xF0, (was 0x05) */ 412
323 0xf5, 0xb0, /* Set pulse generator register */ 413 /* vsize 0x0120 = 288 */
324 0xf6, 0x01, 414 R_CA_B_VERT_INPUT_WINDOW_LENGTH, 0x20,
325 415 R_CB_B_VERT_INPUT_WINDOW_LENGTH_MSB, 0x01,
326 0x87, 0x00, /* Disable I-port output */ 416
327 0x88, 0xd0, /* reset scaler (was 0xD0) */ 417 /* hsize 0x02d0 = 720 */
328 0x80, 0x20, /* Activate only task "B" */ 418 R_CC_B_HORIZ_OUTPUT_WINDOW_LENGTH, 0xd0,
329 0x88, 0xf0, /* activate scaler */ 419 R_CD_B_HORIZ_OUTPUT_WINDOW_LENGTH_MSB, 0x02,
330 0x87, 0x01, /* Enable I-port output */ 420
421 R_F0_LFCO_PER_LINE, 0xb0, /* Set PLL Register. 50hz 625 lines per frame, 27 MHz */
422 R_F1_P_I_PARAM_SELECT, 0x05, /* low bit with 0xF0, (was 0x05) */
423 R_F5_PULSGEN_LINE_LENGTH, 0xb0,
424 R_F6_PULSE_A_POS_LSB_AND_PULSEGEN_CONFIG, 0x01,
425
331 0x00, 0x00 426 0x00, 0x00
332}; 427};
333 428
334/* ============== SAA7715 VIDEO templates (end) ======= */ 429/* ============== SAA7715 VIDEO templates (end) ======= */
335 430
336static const unsigned char saa7115_cfg_vbi_on[] = { 431static const unsigned char saa7115_cfg_vbi_on[] = {
337 0x80, 0x00, /* reset tasks */ 432 R_80_GLOBAL_CNTL_1, 0x00, /* reset tasks */
338 0x88, 0xd0, /* reset scaler */ 433 R_88_POWER_SAVE_ADC_PORT_CNTL, 0xd0, /* reset scaler */
339 0x80, 0x30, /* Activate both tasks */ 434 R_80_GLOBAL_CNTL_1, 0x30, /* Activate both tasks */
340 0x88, 0xf0, /* activate scaler */ 435 R_88_POWER_SAVE_ADC_PORT_CNTL, 0xf0, /* activate scaler */
341 0x87, 0x01, /* Enable I-port output */ 436 R_87_I_PORT_I_O_ENA_OUT_CLK_AND_GATED, 0x01, /* Enable I-port output */
437
342 0x00, 0x00 438 0x00, 0x00
343}; 439};
344 440
345static const unsigned char saa7115_cfg_vbi_off[] = { 441static const unsigned char saa7115_cfg_vbi_off[] = {
346 0x80, 0x00, /* reset tasks */ 442 R_80_GLOBAL_CNTL_1, 0x00, /* reset tasks */
347 0x88, 0xd0, /* reset scaler */ 443 R_88_POWER_SAVE_ADC_PORT_CNTL, 0xd0, /* reset scaler */
348 0x80, 0x20, /* Activate only task "B" */ 444 R_80_GLOBAL_CNTL_1, 0x20, /* Activate only task "B" */
349 0x88, 0xf0, /* activate scaler */ 445 R_88_POWER_SAVE_ADC_PORT_CNTL, 0xf0, /* activate scaler */
350 0x87, 0x01, /* Enable I-port output */ 446 R_87_I_PORT_I_O_ENA_OUT_CLK_AND_GATED, 0x01, /* Enable I-port output */
351 0x00, 0x00
352};
353 447
354static const unsigned char saa7113_init_auto_input[] = {
355 0x01, 0x08, /* PH7113_INCREMENT_DELAY - (1) (1) (1) (1) IDEL3 IDEL2 IDELL1 IDEL0 */
356 0x02, 0xc2, /* PH7113_ANALOG_INPUT_CONTR_1 - FUSE1 FUSE0 GUDL1 GUDL0 MODE3 MODE2 MODE1 MODE0 */
357 0x03, 0x30, /* PH7113_ANALOG_INPUT_CONTR_2 - (1) HLNRS VBSL WPOFF HOLDG GAFIX GAI28 GAI18 */
358 0x04, 0x00, /* PH7113_ANALOG_INPUT_CONTR_3 - GAI17 GAI16 GAI15 GAI14 GAI13 GAI12 GAI11 GAI10 */
359 0x05, 0x00, /* PH7113_ANALOG_INPUT_CONTR_4 - GAI27 GAI26 GAI25 GAI24 GAI23 GAI22 GAI21 GAI20 */
360 0x06, 0x89, /* PH7113_HORIZONTAL_SYNC_START - HSB7 HSB6 HSB5 HSB4 HSB3 HSB2 HSB1 HSB0 */
361 0x07, 0x0d, /* PH7113_HORIZONTAL_SYNC_STOP - HSS7 HSS6 HSS5 HSS4 HSS3 HSS2 HSS1 HSS0 */
362 0x08, 0x88, /* PH7113_SYNC_CONTROL - AUFD FSEL FOET HTC1 HTC0 HPLL VNOI1 VNOI0 */
363 0x09, 0x01, /* PH7113_LUMINANCE_CONTROL - BYPS PREF BPSS1 BPSS0 VBLB UPTCV APER1 APER0 */
364 0x0a, 0x80, /* PH7113_LUMINANCE_BRIGHTNESS - BRIG7 BRIG6 BRIG5 BRIG4 BRIG3 BRIG2 BRIG1 BRIG0 */
365 0x0b, 0x47, /* PH7113_LUMINANCE_CONTRAST - CONT7 CONT6 CONT5 CONT4 CONT3 CONT2 CONT1 CONT0 */
366 0x0c, 0x40, /* PH7113_CHROMA_SATURATION - SATN7 SATN6 SATN5 SATN4 SATN3 SATN2 SATN1 SATN0 */
367 0x0d, 0x00, /* PH7113_CHROMA_HUE_CONTROL - HUEC7 HUEC6 HUEC5 HUEC4 HUEC3 HUEC2 HUEC1 HUEC0 */
368 0x0e, 0x01, /* PH7113_CHROMA_CONTROL - CDTO CSTD2 CSTD1 CSTD0 DCCF FCTC CHBW1 CHBW0 */
369 0x0f, 0x2a, /* PH7113_CHROMA_GAIN_CONTROL - ACGC CGAIN6 CGAIN5 CGAIN4 CGAIN3 CGAIN2 CGAIN1 CGAIN0 */
370 0x10, 0x08, /* PH7113_FORMAT_DELAY_CONTROL - OFTS1 OFTS0 HDEL1 HDEL0 VRLN YDEL2 YDEL1 YDEL0 */
371 0x11, 0x0c, /* PH7113_OUTPUT_CONTROL_1 - GPSW1 CM99 GPSW0 HLSEL OEYC OERT VIPB COLO */
372 0x12, 0x07, /* PH7113_OUTPUT_CONTROL_2 - RTSE13 RTSE12 RTSE11 RTSE10 RTSE03 RTSE02 RTSE01 RTSE00 */
373 0x13, 0x00, /* PH7113_OUTPUT_CONTROL_3 - ADLSB (1) (1) OLDSB FIDP (1) AOSL1 AOSL0 */
374 0x14, 0x00, /* RESERVED 14 - (1) (1) (1) (1) (1) (1) (1) (1) */
375 0x15, 0x00, /* PH7113_V_GATE1_START - VSTA7 VSTA6 VSTA5 VSTA4 VSTA3 VSTA2 VSTA1 VSTA0 */
376 0x16, 0x00, /* PH7113_V_GATE1_STOP - VSTO7 VSTO6 VSTO5 VSTO4 VSTO3 VSTO2 VSTO1 VSTO0 */
377 0x17, 0x00, /* PH7113_V_GATE1_MSB - (1) (1) (1) (1) (1) (1) VSTO8 VSTA8 */
378 0x00, 0x00 448 0x00, 0x00
379}; 449};
380 450
451
381static const unsigned char saa7115_init_misc[] = { 452static const unsigned char saa7115_init_misc[] = {
382 0x81, 0x01, /* reg 0x15,0x16 define blanking window */ 453 R_81_V_SYNC_FLD_ID_SRC_SEL_AND_RETIMED_V_F, 0x01,
383 0x82, 0x00, 454 R_83_X_PORT_I_O_ENA_AND_OUT_CLK, 0x01,
384 0x83, 0x01, /* I port settings */ 455 R_84_I_PORT_SIGNAL_DEF, 0x20,
385 0x84, 0x20, 456 R_85_I_PORT_SIGNAL_POLAR, 0x21,
386 0x85, 0x21, 457 R_86_I_PORT_FIFO_FLAG_CNTL_AND_ARBIT, 0xc5,
387 0x86, 0xc5, 458 R_87_I_PORT_I_O_ENA_OUT_CLK_AND_GATED, 0x01,
388 0x87, 0x01,
389 459
390 /* Task A */ 460 /* Task A */
391 0xa0, 0x01, /* down scale = 1 */ 461 R_A0_A_HORIZ_PRESCALING, 0x01,
392 0xa1, 0x00, /* prescale accumulation length = 1 */ 462 R_A1_A_ACCUMULATION_LENGTH, 0x00,
393 0xa2, 0x00, /* dc gain and fir prefilter control */ 463 R_A2_A_PRESCALER_DC_GAIN_AND_FIR_PREFILTER, 0x00,
394 0xa4, 0x80, /* Lum Brightness, nominal value = 0x80 */ 464
395 0xa5, 0x40, /* Lum contrast, nominal value = 0x40 */ 465 /* Configure controls at nominal value*/
396 0xa6, 0x40, /* Chroma satur. nominal value = 0x80 */ 466 R_A4_A_LUMA_BRIGHTNESS_CNTL, 0x80,
397 0xa8, 0x00, /* hor lum scaling 0x0200 = 2 zoom */ 467 R_A5_A_LUMA_CONTRAST_CNTL, 0x40,
398 0xa9, 0x02, /* note: 2 x zoom ensures that VBI lines have same length as video lines. */ 468 R_A6_A_CHROMA_SATURATION_CNTL, 0x40,
399 0xaa, 0x00, /* H-phase offset Luma = 0 */ 469
400 0xac, 0x00, /* hor chrom scaling 0x0200. must be hor lum scaling / 2 */ 470 /* note: 2 x zoom ensures that VBI lines have same length as video lines. */
401 0xad, 0x01, /* H-scaling incr chroma */ 471 R_A8_A_HORIZ_LUMA_SCALING_INC, 0x00,
402 0xae, 0x00, /* H-phase offset chroma. must be offset luma / 2 */ 472 R_A9_A_HORIZ_LUMA_SCALING_INC_MSB, 0x02,
403 473
404 0xb0, 0x00, /* V-scaling incr luma low */ 474 R_AA_A_HORIZ_LUMA_PHASE_OFF, 0x00,
405 0xb1, 0x04, /* " hi */ 475
406 0xb2, 0x00, /* V-scaling incr chroma low */ 476 /* must be horiz lum scaling / 2 */
407 0xb3, 0x04, /* " hi */ 477 R_AC_A_HORIZ_CHROMA_SCALING_INC, 0x00,
408 0xb4, 0x01, /* V-scaling mode control */ 478 R_AD_A_HORIZ_CHROMA_SCALING_INC_MSB, 0x01,
409 0xb8, 0x00, /* V-phase offset chroma 00 */ 479
410 0xb9, 0x00, /* V-phase offset chroma 01 */ 480 /* must be offset luma / 2 */
411 0xba, 0x00, /* V-phase offset chroma 10 */ 481 R_AE_A_HORIZ_CHROMA_PHASE_OFF, 0x00,
412 0xbb, 0x00, /* V-phase offset chroma 11 */ 482
413 0xbc, 0x00, /* V-phase offset luma 00 */ 483 R_B0_A_VERT_LUMA_SCALING_INC, 0x00,
414 0xbd, 0x00, /* V-phase offset luma 01 */ 484 R_B1_A_VERT_LUMA_SCALING_INC_MSB, 0x04,
415 0xbe, 0x00, /* V-phase offset luma 10 */ 485
416 0xbf, 0x00, /* V-phase offset luma 11 */ 486 R_B2_A_VERT_CHROMA_SCALING_INC, 0x00,
487 R_B3_A_VERT_CHROMA_SCALING_INC_MSB, 0x04,
488
489 R_B4_A_VERT_SCALING_MODE_CNTL, 0x01,
490
491 R_B8_A_VERT_CHROMA_PHASE_OFF_00, 0x00,
492 R_B9_A_VERT_CHROMA_PHASE_OFF_01, 0x00,
493 R_BA_A_VERT_CHROMA_PHASE_OFF_10, 0x00,
494 R_BB_A_VERT_CHROMA_PHASE_OFF_11, 0x00,
495
496 R_BC_A_VERT_LUMA_PHASE_OFF_00, 0x00,
497 R_BD_A_VERT_LUMA_PHASE_OFF_01, 0x00,
498 R_BE_A_VERT_LUMA_PHASE_OFF_10, 0x00,
499 R_BF_A_VERT_LUMA_PHASE_OFF_11, 0x00,
417 500
418 /* Task B */ 501 /* Task B */
419 0xd0, 0x01, /* down scale = 1 */ 502 R_D0_B_HORIZ_PRESCALING, 0x01,
420 0xd1, 0x00, /* prescale accumulation length = 1 */ 503 R_D1_B_ACCUMULATION_LENGTH, 0x00,
421 0xd2, 0x00, /* dc gain and fir prefilter control */ 504 R_D2_B_PRESCALER_DC_GAIN_AND_FIR_PREFILTER, 0x00,
422 0xd4, 0x80, /* Lum Brightness, nominal value = 0x80 */ 505
423 0xd5, 0x40, /* Lum contrast, nominal value = 0x40 */ 506 /* Configure controls at nominal value*/
424 0xd6, 0x40, /* Chroma satur. nominal value = 0x80 */ 507 R_D4_B_LUMA_BRIGHTNESS_CNTL, 0x80,
425 0xd8, 0x00, /* hor lum scaling 0x0400 = 1 */ 508 R_D5_B_LUMA_CONTRAST_CNTL, 0x40,
426 0xd9, 0x04, 509 R_D6_B_CHROMA_SATURATION_CNTL, 0x40,
427 0xda, 0x00, /* H-phase offset Luma = 0 */ 510
428 0xdc, 0x00, /* hor chrom scaling 0x0200. must be hor lum scaling / 2 */ 511 /* hor lum scaling 0x0400 = 1 */
429 0xdd, 0x02, /* H-scaling incr chroma */ 512 R_D8_B_HORIZ_LUMA_SCALING_INC, 0x00,
430 0xde, 0x00, /* H-phase offset chroma. must be offset luma / 2 */ 513 R_D9_B_HORIZ_LUMA_SCALING_INC_MSB, 0x04,
431 514
432 0xe0, 0x00, /* V-scaling incr luma low */ 515 R_DA_B_HORIZ_LUMA_PHASE_OFF, 0x00,
433 0xe1, 0x04, /* " hi */ 516
434 0xe2, 0x00, /* V-scaling incr chroma low */ 517 /* must be hor lum scaling / 2 */
435 0xe3, 0x04, /* " hi */ 518 R_DC_B_HORIZ_CHROMA_SCALING, 0x00,
436 0xe4, 0x01, /* V-scaling mode control */ 519 R_DD_B_HORIZ_CHROMA_SCALING_MSB, 0x02,
437 0xe8, 0x00, /* V-phase offset chroma 00 */ 520
438 0xe9, 0x00, /* V-phase offset chroma 01 */ 521 /* must be offset luma / 2 */
439 0xea, 0x00, /* V-phase offset chroma 10 */ 522 R_DE_B_HORIZ_PHASE_OFFSET_CRHOMA, 0x00,
440 0xeb, 0x00, /* V-phase offset chroma 11 */ 523
441 0xec, 0x00, /* V-phase offset luma 00 */ 524 R_E0_B_VERT_LUMA_SCALING_INC, 0x00,
442 0xed, 0x00, /* V-phase offset luma 01 */ 525 R_E1_B_VERT_LUMA_SCALING_INC_MSB, 0x04,
443 0xee, 0x00, /* V-phase offset luma 10 */ 526
444 0xef, 0x00, /* V-phase offset luma 11 */ 527 R_E2_B_VERT_CHROMA_SCALING_INC, 0x00,
445 528 R_E3_B_VERT_CHROMA_SCALING_INC_MSB, 0x04,
446 0xf2, 0x50, /* crystal clock = 24.576 MHz, target = 27MHz */ 529
447 0xf3, 0x46, 530 R_E4_B_VERT_SCALING_MODE_CNTL, 0x01,
448 0xf4, 0x00, 531
449 0xf7, 0x4b, /* not the recommended settings! */ 532 R_E8_B_VERT_CHROMA_PHASE_OFF_00, 0x00,
450 0xf8, 0x00, 533 R_E9_B_VERT_CHROMA_PHASE_OFF_01, 0x00,
451 0xf9, 0x4b, 534 R_EA_B_VERT_CHROMA_PHASE_OFF_10, 0x00,
452 0xfa, 0x00, 535 R_EB_B_VERT_CHROMA_PHASE_OFF_11, 0x00,
453 0xfb, 0x4b, 536
454 0xff, 0x88, /* PLL2 lock detection settings: 71 lines 50% phase error */ 537 R_EC_B_VERT_LUMA_PHASE_OFF_00, 0x00,
538 R_ED_B_VERT_LUMA_PHASE_OFF_01, 0x00,
539 R_EE_B_VERT_LUMA_PHASE_OFF_10, 0x00,
540 R_EF_B_VERT_LUMA_PHASE_OFF_11, 0x00,
541
542 R_F2_NOMINAL_PLL2_DTO, 0x50, /* crystal clock = 24.576 MHz, target = 27MHz */
543 R_F3_PLL_INCREMENT, 0x46,
544 R_F4_PLL2_STATUS, 0x00,
545 R_F7_PULSE_A_POS_MSB, 0x4b, /* not the recommended settings! */
546 R_F8_PULSE_B_POS, 0x00,
547 R_F9_PULSE_B_POS_MSB, 0x4b,
548 R_FA_PULSE_C_POS, 0x00,
549 R_FB_PULSE_C_POS_MSB, 0x4b,
550
551 /* PLL2 lock detection settings: 71 lines 50% phase error */
552 R_FF_S_PLL_MAX_PHASE_ERR_THRESH_NUM_LINES, 0x88,
455 553
456 /* Turn off VBI */ 554 /* Turn off VBI */
457 0x40, 0x20, /* No framing code errors allowed. */ 555 R_40_SLICER_CNTL_1, 0x20, /* No framing code errors allowed. */
458 0x41, 0xff, 556 R_41_LCR_BASE, 0xff,
459 0x42, 0xff, 557 R_41_LCR_BASE+1, 0xff,
460 0x43, 0xff, 558 R_41_LCR_BASE+2, 0xff,
461 0x44, 0xff, 559 R_41_LCR_BASE+3, 0xff,
462 0x45, 0xff, 560 R_41_LCR_BASE+4, 0xff,
463 0x46, 0xff, 561 R_41_LCR_BASE+5, 0xff,
464 0x47, 0xff, 562 R_41_LCR_BASE+6, 0xff,
465 0x48, 0xff, 563 R_41_LCR_BASE+7, 0xff,
466 0x49, 0xff, 564 R_41_LCR_BASE+8, 0xff,
467 0x4a, 0xff, 565 R_41_LCR_BASE+9, 0xff,
468 0x4b, 0xff, 566 R_41_LCR_BASE+10, 0xff,
469 0x4c, 0xff, 567 R_41_LCR_BASE+11, 0xff,
470 0x4d, 0xff, 568 R_41_LCR_BASE+12, 0xff,
471 0x4e, 0xff, 569 R_41_LCR_BASE+13, 0xff,
472 0x4f, 0xff, 570 R_41_LCR_BASE+14, 0xff,
473 0x50, 0xff, 571 R_41_LCR_BASE+15, 0xff,
474 0x51, 0xff, 572 R_41_LCR_BASE+16, 0xff,
475 0x52, 0xff, 573 R_41_LCR_BASE+17, 0xff,
476 0x53, 0xff, 574 R_41_LCR_BASE+18, 0xff,
477 0x54, 0xff, 575 R_41_LCR_BASE+19, 0xff,
478 0x55, 0xff, 576 R_41_LCR_BASE+20, 0xff,
479 0x56, 0xff, 577 R_41_LCR_BASE+21, 0xff,
480 0x57, 0xff, 578 R_41_LCR_BASE+22, 0xff,
481 0x58, 0x40, 579 R_58_PROGRAM_FRAMING_CODE, 0x40,
482 0x59, 0x47, 580 R_59_H_OFF_FOR_SLICER, 0x47,
483 0x5b, 0x83, 581 R_5B_FLD_OFF_AND_MSB_FOR_H_AND_V_OFF, 0x83,
484 0x5d, 0xbd, 582 R_5D_DID, 0xbd,
485 0x5e, 0x35, 583 R_5E_SDID, 0x35,
486 584
487 0x02, 0x84, /* input tuner -> input 4, amplifier active */ 585 R_02_INPUT_CNTL_1, 0x84, /* input tuner -> input 4, amplifier active */
488 0x09, 0x53, /* 0x53, was 0x56 for 60hz. luminance control */ 586
489 587 R_80_GLOBAL_CNTL_1, 0x20, /* enable task B */
490 0x80, 0x20, /* enable task B */ 588 R_88_POWER_SAVE_ADC_PORT_CNTL, 0xd0,
491 0x88, 0xd0, 589 R_88_POWER_SAVE_ADC_PORT_CNTL, 0xf0,
492 0x88, 0xf0,
493 0x00, 0x00 590 0x00, 0x00
494}; 591};
495 592
496static int saa7115_odd_parity(u8 c) 593static int saa711x_odd_parity(u8 c)
497{ 594{
498 c ^= (c >> 4); 595 c ^= (c >> 4);
499 c ^= (c >> 2); 596 c ^= (c >> 2);
@@ -502,7 +599,7 @@ static int saa7115_odd_parity(u8 c)
502 return c & 1; 599 return c & 1;
503} 600}
504 601
505static int saa7115_decode_vps(u8 * dst, u8 * p) 602static int saa711x_decode_vps(u8 * dst, u8 * p)
506{ 603{
507 static const u8 biphase_tbl[] = { 604 static const u8 biphase_tbl[] = {
508 0xf0, 0x78, 0x70, 0xf0, 0xb4, 0x3c, 0x34, 0xb4, 605 0xf0, 0x78, 0x70, 0xf0, 0xb4, 0x3c, 0x34, 0xb4,
@@ -549,7 +646,7 @@ static int saa7115_decode_vps(u8 * dst, u8 * p)
549 return err & 0xf0; 646 return err & 0xf0;
550} 647}
551 648
552static int saa7115_decode_wss(u8 * p) 649static int saa711x_decode_wss(u8 * p)
553{ 650{
554 static const int wss_bits[8] = { 651 static const int wss_bits[8] = {
555 0, 0, 0, 1, 0, 1, 1, 1 652 0, 0, 0, 1, 0, 1, 1, 1
@@ -576,26 +673,25 @@ static int saa7115_decode_wss(u8 * p)
576 return wss; 673 return wss;
577} 674}
578 675
579 676static int saa711x_set_audio_clock_freq(struct i2c_client *client, u32 freq)
580static int saa7115_set_audio_clock_freq(struct i2c_client *client, u32 freq)
581{ 677{
582 struct saa7115_state *state = i2c_get_clientdata(client); 678 struct saa711x_state *state = i2c_get_clientdata(client);
583 u32 acpf; 679 u32 acpf;
584 u32 acni; 680 u32 acni;
585 u32 hz; 681 u32 hz;
586 u64 f; 682 u64 f;
587 u8 acc = 0; /* reg 0x3a, audio clock control */ 683 u8 acc = 0; /* reg 0x3a, audio clock control */
588 684
685 /* Checks for chips that don't have audio clock (saa7111, saa7113) */
686 if (!saa711x_has_reg(state->ident,R_30_AUD_MAST_CLK_CYCLES_PER_FIELD))
687 return 0;
688
589 v4l_dbg(1, debug, client, "set audio clock freq: %d\n", freq); 689 v4l_dbg(1, debug, client, "set audio clock freq: %d\n", freq);
590 690
591 /* sanity check */ 691 /* sanity check */
592 if (freq < 32000 || freq > 48000) 692 if (freq < 32000 || freq > 48000)
593 return -EINVAL; 693 return -EINVAL;
594 694
595 /* The saa7113 has no audio clock */
596 if (state->ident == V4L2_IDENT_SAA7113)
597 return 0;
598
599 /* hz is the refresh rate times 100 */ 695 /* hz is the refresh rate times 100 */
600 hz = (state->std & V4L2_STD_525_60) ? 5994 : 5000; 696 hz = (state->std & V4L2_STD_525_60) ? 5994 : 5000;
601 /* acpf = (256 * freq) / field_frequency == (256 * 100 * freq) / hz */ 697 /* acpf = (256 * freq) / field_frequency == (256 * 100 * freq) / hz */
@@ -617,22 +713,26 @@ static int saa7115_set_audio_clock_freq(struct i2c_client *client, u32 freq)
617 if (state->apll) 713 if (state->apll)
618 acc |= 0x08; 714 acc |= 0x08;
619 715
620 saa7115_write(client, 0x38, 0x03); 716 saa711x_write(client, R_38_CLK_RATIO_AMXCLK_TO_ASCLK, 0x03);
621 saa7115_write(client, 0x39, 0x10); 717 saa711x_write(client, R_39_CLK_RATIO_ASCLK_TO_ALRCLK, 0x10);
622 saa7115_write(client, 0x3a, acc); 718 saa711x_write(client, R_3A_AUD_CLK_GEN_BASIC_SETUP, acc);
623 saa7115_write(client, 0x30, acpf & 0xff); 719
624 saa7115_write(client, 0x31, (acpf >> 8) & 0xff); 720 saa711x_write(client, R_30_AUD_MAST_CLK_CYCLES_PER_FIELD, acpf & 0xff);
625 saa7115_write(client, 0x32, (acpf >> 16) & 0x03); 721 saa711x_write(client, R_30_AUD_MAST_CLK_CYCLES_PER_FIELD+1,
626 saa7115_write(client, 0x34, acni & 0xff); 722 (acpf >> 8) & 0xff);
627 saa7115_write(client, 0x35, (acni >> 8) & 0xff); 723 saa711x_write(client, R_30_AUD_MAST_CLK_CYCLES_PER_FIELD+2,
628 saa7115_write(client, 0x36, (acni >> 16) & 0x3f); 724 (acpf >> 16) & 0x03);
725
726 saa711x_write(client, R_34_AUD_MAST_CLK_NOMINAL_INC, acni & 0xff);
727 saa711x_write(client, R_34_AUD_MAST_CLK_NOMINAL_INC+1, (acni >> 8) & 0xff);
728 saa711x_write(client, R_34_AUD_MAST_CLK_NOMINAL_INC+2, (acni >> 16) & 0x3f);
629 state->audclk_freq = freq; 729 state->audclk_freq = freq;
630 return 0; 730 return 0;
631} 731}
632 732
633static int saa7115_set_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl) 733static int saa711x_set_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl)
634{ 734{
635 struct saa7115_state *state = i2c_get_clientdata(client); 735 struct saa711x_state *state = i2c_get_clientdata(client);
636 736
637 switch (ctrl->id) { 737 switch (ctrl->id) {
638 case V4L2_CID_BRIGHTNESS: 738 case V4L2_CID_BRIGHTNESS:
@@ -642,7 +742,7 @@ static int saa7115_set_v4lctrl(struct i2c_client *client, struct v4l2_control *c
642 } 742 }
643 743
644 state->bright = ctrl->value; 744 state->bright = ctrl->value;
645 saa7115_write(client, 0x0a, state->bright); 745 saa711x_write(client, R_0A_LUMA_BRIGHT_CNTL, state->bright);
646 break; 746 break;
647 747
648 case V4L2_CID_CONTRAST: 748 case V4L2_CID_CONTRAST:
@@ -652,7 +752,7 @@ static int saa7115_set_v4lctrl(struct i2c_client *client, struct v4l2_control *c
652 } 752 }
653 753
654 state->contrast = ctrl->value; 754 state->contrast = ctrl->value;
655 saa7115_write(client, 0x0b, state->contrast); 755 saa711x_write(client, R_0B_LUMA_CONTRAST_CNTL, state->contrast);
656 break; 756 break;
657 757
658 case V4L2_CID_SATURATION: 758 case V4L2_CID_SATURATION:
@@ -662,7 +762,7 @@ static int saa7115_set_v4lctrl(struct i2c_client *client, struct v4l2_control *c
662 } 762 }
663 763
664 state->sat = ctrl->value; 764 state->sat = ctrl->value;
665 saa7115_write(client, 0x0c, state->sat); 765 saa711x_write(client, R_0C_CHROMA_SAT_CNTL, state->sat);
666 break; 766 break;
667 767
668 case V4L2_CID_HUE: 768 case V4L2_CID_HUE:
@@ -672,7 +772,7 @@ static int saa7115_set_v4lctrl(struct i2c_client *client, struct v4l2_control *c
672 } 772 }
673 773
674 state->hue = ctrl->value; 774 state->hue = ctrl->value;
675 saa7115_write(client, 0x0d, state->hue); 775 saa711x_write(client, R_0D_CHROMA_HUE_CNTL, state->hue);
676 break; 776 break;
677 777
678 default: 778 default:
@@ -682,9 +782,9 @@ static int saa7115_set_v4lctrl(struct i2c_client *client, struct v4l2_control *c
682 return 0; 782 return 0;
683} 783}
684 784
685static int saa7115_get_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl) 785static int saa711x_get_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl)
686{ 786{
687 struct saa7115_state *state = i2c_get_clientdata(client); 787 struct saa711x_state *state = i2c_get_clientdata(client);
688 788
689 switch (ctrl->id) { 789 switch (ctrl->id) {
690 case V4L2_CID_BRIGHTNESS: 790 case V4L2_CID_BRIGHTNESS:
@@ -706,10 +806,115 @@ static int saa7115_get_v4lctrl(struct i2c_client *client, struct v4l2_control *c
706 return 0; 806 return 0;
707} 807}
708 808
709static void saa7115_set_v4lstd(struct i2c_client *client, v4l2_std_id std) 809static int saa711x_set_size(struct i2c_client *client, int width, int height)
810{
811 struct saa711x_state *state = i2c_get_clientdata(client);
812 int HPSC, HFSC;
813 int VSCY;
814 int res;
815 int is_50hz = state->std & V4L2_STD_625_50;
816 int Vsrc = is_50hz ? 576 : 480;
817
818 v4l_dbg(1, debug, client, "decoder set size to %ix%i\n",width,height);
819
820 /* FIXME need better bounds checking here */
821 if ((width < 1) || (width > 1440))
822 return -EINVAL;
823 if ((height < 1) || (height > Vsrc))
824 return -EINVAL;
825
826 if (!saa711x_has_reg(state->ident,R_D0_B_HORIZ_PRESCALING)) {
827 /* Decoder only supports 720 columns and 480 or 576 lines */
828 if (width != 720)
829 return -EINVAL;
830 if (height != Vsrc)
831 return -EINVAL;
832 }
833
834 state->width = width;
835 state->height = height;
836
837 if (!saa711x_has_reg(state->ident, R_CC_B_HORIZ_OUTPUT_WINDOW_LENGTH))
838 return 0;
839
840 /* probably have a valid size, let's set it */
841 /* Set output width/height */
842 /* width */
843
844 saa711x_write(client, R_CC_B_HORIZ_OUTPUT_WINDOW_LENGTH,
845 (u8) (width & 0xff));
846 saa711x_write(client, R_CD_B_HORIZ_OUTPUT_WINDOW_LENGTH_MSB,
847 (u8) ((width >> 8) & 0xff));
848
849 /* Vertical Scaling uses height/2 */
850 res=height/2;
851
852 /* On 60Hz, it is using a higher Vertical Output Size */
853 if (!is_50hz)
854 res+=(VRES_60HZ-480)>>1;
855
856 /* height */
857 saa711x_write(client, R_CE_B_VERT_OUTPUT_WINDOW_LENGTH,
858 (u8) (res & 0xff));
859 saa711x_write(client, R_CF_B_VERT_OUTPUT_WINDOW_LENGTH_MSB,
860 (u8) ((res >> 8) & 0xff));
861
862 /* Scaling settings */
863 /* Hprescaler is floor(inres/outres) */
864 HPSC = (int)(720 / width);
865 /* 0 is not allowed (div. by zero) */
866 HPSC = HPSC ? HPSC : 1;
867 HFSC = (int)((1024 * 720) / (HPSC * width));
868 /* FIXME hardcodes to "Task B"
869 * write H prescaler integer */
870 saa711x_write(client, R_D0_B_HORIZ_PRESCALING,
871 (u8) (HPSC & 0x3f));
872
873 v4l_dbg(1, debug, client, "Hpsc: 0x%05x, Hfsc: 0x%05x\n", HPSC, HFSC);
874 /* write H fine-scaling (luminance) */
875 saa711x_write(client, R_D8_B_HORIZ_LUMA_SCALING_INC,
876 (u8) (HFSC & 0xff));
877 saa711x_write(client, R_D9_B_HORIZ_LUMA_SCALING_INC_MSB,
878 (u8) ((HFSC >> 8) & 0xff));
879 /* write H fine-scaling (chrominance)
880 * must be lum/2, so i'll just bitshift :) */
881 saa711x_write(client, R_DC_B_HORIZ_CHROMA_SCALING,
882 (u8) ((HFSC >> 1) & 0xff));
883 saa711x_write(client, R_DD_B_HORIZ_CHROMA_SCALING_MSB,
884 (u8) ((HFSC >> 9) & 0xff));
885
886 VSCY = (int)((1024 * Vsrc) / height);
887 v4l_dbg(1, debug, client, "Vsrc: %d, Vscy: 0x%05x\n", Vsrc, VSCY);
888
889 /* Correct Contrast and Luminance */
890 saa711x_write(client, R_D5_B_LUMA_CONTRAST_CNTL,
891 (u8) (64 * 1024 / VSCY));
892 saa711x_write(client, R_D6_B_CHROMA_SATURATION_CNTL,
893 (u8) (64 * 1024 / VSCY));
894
895 /* write V fine-scaling (luminance) */
896 saa711x_write(client, R_E0_B_VERT_LUMA_SCALING_INC,
897 (u8) (VSCY & 0xff));
898 saa711x_write(client, R_E1_B_VERT_LUMA_SCALING_INC_MSB,
899 (u8) ((VSCY >> 8) & 0xff));
900 /* write V fine-scaling (chrominance) */
901 saa711x_write(client, R_E2_B_VERT_CHROMA_SCALING_INC,
902 (u8) (VSCY & 0xff));
903 saa711x_write(client, R_E3_B_VERT_CHROMA_SCALING_INC_MSB,
904 (u8) ((VSCY >> 8) & 0xff));
905
906 saa711x_writeregs(client, saa7115_cfg_reset_scaler);
907
908 /* Activates task "B" */
909 saa711x_write(client, R_80_GLOBAL_CNTL_1,
910 saa711x_read(client,R_80_GLOBAL_CNTL_1)|0x20);
911
912 return 0;
913}
914
915static void saa711x_set_v4lstd(struct i2c_client *client, v4l2_std_id std)
710{ 916{
711 struct saa7115_state *state = i2c_get_clientdata(client); 917 struct saa711x_state *state = i2c_get_clientdata(client);
712 int taskb = saa7115_read(client, 0x80) & 0x10;
713 918
714 /* Prevent unnecessary standard changes. During a standard 919 /* Prevent unnecessary standard changes. During a standard
715 change the I-Port is temporarily disabled. Any devices 920 change the I-Port is temporarily disabled. Any devices
@@ -721,17 +926,21 @@ static void saa7115_set_v4lstd(struct i2c_client *client, v4l2_std_id std)
721 if (std == state->std) 926 if (std == state->std)
722 return; 927 return;
723 928
929 state->std = std;
930
724 // This works for NTSC-M, SECAM-L and the 50Hz PAL variants. 931 // This works for NTSC-M, SECAM-L and the 50Hz PAL variants.
725 if (std & V4L2_STD_525_60) { 932 if (std & V4L2_STD_525_60) {
726 v4l_dbg(1, debug, client, "decoder set standard 60 Hz\n"); 933 v4l_dbg(1, debug, client, "decoder set standard 60 Hz\n");
727 saa7115_writeregs(client, saa7115_cfg_60hz_video); 934 saa711x_writeregs(client, saa7115_cfg_60hz_video);
935 saa711x_set_size(client,720,480);
728 } else { 936 } else {
729 v4l_dbg(1, debug, client, "decoder set standard 50 Hz\n"); 937 v4l_dbg(1, debug, client, "decoder set standard 50 Hz\n");
730 saa7115_writeregs(client, saa7115_cfg_50hz_video); 938 saa711x_writeregs(client, saa7115_cfg_50hz_video);
939 saa711x_set_size(client,720,576);
731 } 940 }
732 941
733 /* Register 0E - Bits D6-D4 on NO-AUTO mode 942 /* Register 0E - Bits D6-D4 on NO-AUTO mode
734 (SAA7113 doesn't have auto mode) 943 (SAA7111 and SAA7113 doesn't have auto mode)
735 50 Hz / 625 lines 60 Hz / 525 lines 944 50 Hz / 625 lines 60 Hz / 525 lines
736 000 PAL BGDHI (4.43Mhz) NTSC M (3.58MHz) 945 000 PAL BGDHI (4.43Mhz) NTSC M (3.58MHz)
737 001 NTSC 4.43 (50 Hz) PAL 4.43 (60 Hz) 946 001 NTSC 4.43 (50 Hz) PAL 4.43 (60 Hz)
@@ -739,8 +948,9 @@ static void saa7115_set_v4lstd(struct i2c_client *client, v4l2_std_id std)
739 011 NTSC N (3.58MHz) PAL M (3.58MHz) 948 011 NTSC N (3.58MHz) PAL M (3.58MHz)
740 100 reserved NTSC-Japan (3.58MHz) 949 100 reserved NTSC-Japan (3.58MHz)
741 */ 950 */
742 if (state->ident == V4L2_IDENT_SAA7113) { 951 if (state->ident == V4L2_IDENT_SAA7111 ||
743 u8 reg = saa7115_read(client, 0x0e) & 0x8f; 952 state->ident == V4L2_IDENT_SAA7113) {
953 u8 reg = saa711x_read(client, R_0E_CHROMA_CNTL_1) & 0x8f;
744 954
745 if (std == V4L2_STD_PAL_M) { 955 if (std == V4L2_STD_PAL_M) {
746 reg |= 0x30; 956 reg |= 0x30;
@@ -751,31 +961,30 @@ static void saa7115_set_v4lstd(struct i2c_client *client, v4l2_std_id std)
751 } else if (std == V4L2_STD_NTSC_M_JP) { 961 } else if (std == V4L2_STD_NTSC_M_JP) {
752 reg |= 0x40; 962 reg |= 0x40;
753 } 963 }
754 saa7115_write(client, 0x0e, reg); 964 saa711x_write(client, R_0E_CHROMA_CNTL_1, reg);
755 } 965 } else {
756 966 /* restart task B if needed */
967 int taskb = saa711x_read(client, R_80_GLOBAL_CNTL_1) & 0x10;
757 968
758 state->std = std; 969 if (taskb && state->ident == V4L2_IDENT_SAA7114) {
970 saa711x_writeregs(client, saa7115_cfg_vbi_on);
971 }
759 972
760 /* restart task B if needed */ 973 /* switch audio mode too! */
761 if (taskb && state->ident != V4L2_IDENT_SAA7115) { 974 saa711x_set_audio_clock_freq(client, state->audclk_freq);
762 saa7115_writeregs(client, saa7115_cfg_vbi_on);
763 } 975 }
764
765 /* switch audio mode too! */
766 saa7115_set_audio_clock_freq(client, state->audclk_freq);
767} 976}
768 977
769static v4l2_std_id saa7115_get_v4lstd(struct i2c_client *client) 978static v4l2_std_id saa711x_get_v4lstd(struct i2c_client *client)
770{ 979{
771 struct saa7115_state *state = i2c_get_clientdata(client); 980 struct saa711x_state *state = i2c_get_clientdata(client);
772 981
773 return state->std; 982 return state->std;
774} 983}
775 984
776static void saa7115_log_status(struct i2c_client *client) 985static void saa711x_log_status(struct i2c_client *client)
777{ 986{
778 struct saa7115_state *state = i2c_get_clientdata(client); 987 struct saa711x_state *state = i2c_get_clientdata(client);
779 int reg1e, reg1f; 988 int reg1e, reg1f;
780 int signalOk; 989 int signalOk;
781 int vcr; 990 int vcr;
@@ -783,7 +992,7 @@ static void saa7115_log_status(struct i2c_client *client)
783 v4l_info(client, "Audio frequency: %d Hz\n", state->audclk_freq); 992 v4l_info(client, "Audio frequency: %d Hz\n", state->audclk_freq);
784 if (state->ident != V4L2_IDENT_SAA7115) { 993 if (state->ident != V4L2_IDENT_SAA7115) {
785 /* status for the saa7114 */ 994 /* status for the saa7114 */
786 reg1f = saa7115_read(client, 0x1f); 995 reg1f = saa711x_read(client, R_1F_STATUS_BYTE_2_VD_DEC);
787 signalOk = (reg1f & 0xc1) == 0x81; 996 signalOk = (reg1f & 0xc1) == 0x81;
788 v4l_info(client, "Video signal: %s\n", signalOk ? "ok" : "bad"); 997 v4l_info(client, "Video signal: %s\n", signalOk ? "ok" : "bad");
789 v4l_info(client, "Frequency: %s\n", (reg1f & 0x20) ? "60 Hz" : "50 Hz"); 998 v4l_info(client, "Frequency: %s\n", (reg1f & 0x20) ? "60 Hz" : "50 Hz");
@@ -791,8 +1000,8 @@ static void saa7115_log_status(struct i2c_client *client)
791 } 1000 }
792 1001
793 /* status for the saa7115 */ 1002 /* status for the saa7115 */
794 reg1e = saa7115_read(client, 0x1e); 1003 reg1e = saa711x_read(client, R_1E_STATUS_BYTE_1_VD_DEC);
795 reg1f = saa7115_read(client, 0x1f); 1004 reg1f = saa711x_read(client, R_1F_STATUS_BYTE_2_VD_DEC);
796 1005
797 signalOk = (reg1f & 0xc1) == 0x81 && (reg1e & 0xc0) == 0x80; 1006 signalOk = (reg1f & 0xc1) == 0x81 && (reg1e & 0xc0) == 0x80;
798 vcr = !(reg1f & 0x10); 1007 vcr = !(reg1f & 0x10);
@@ -819,19 +1028,27 @@ static void saa7115_log_status(struct i2c_client *client)
819 v4l_info(client, "Detected format: BW/No color\n"); 1028 v4l_info(client, "Detected format: BW/No color\n");
820 break; 1029 break;
821 } 1030 }
1031 v4l_info(client, "Width, Height: %d, %d\n", state->width, state->height);
822} 1032}
823 1033
824/* setup the sliced VBI lcr registers according to the sliced VBI format */ 1034/* setup the sliced VBI lcr registers according to the sliced VBI format */
825static void saa7115_set_lcr(struct i2c_client *client, struct v4l2_sliced_vbi_format *fmt) 1035static void saa711x_set_lcr(struct i2c_client *client, struct v4l2_sliced_vbi_format *fmt)
826{ 1036{
827 struct saa7115_state *state = i2c_get_clientdata(client); 1037 struct saa711x_state *state = i2c_get_clientdata(client);
828 int is_50hz = (state->std & V4L2_STD_625_50); 1038 int is_50hz = (state->std & V4L2_STD_625_50);
829 u8 lcr[24]; 1039 u8 lcr[24];
830 int i, x; 1040 int i, x;
831 1041
832 /* saa7113/7114 doesn't yet support VBI */ 1042#if 1
1043 /* saa7113/7114/7118 VBI support are experimental */
1044 if (!saa711x_has_reg(state->ident,R_41_LCR_BASE))
1045 return;
1046
1047#else
1048 /* SAA7113 and SAA7118 also should support VBI - Need testing */
833 if (state->ident != V4L2_IDENT_SAA7115) 1049 if (state->ident != V4L2_IDENT_SAA7115)
834 return; 1050 return;
1051#endif
835 1052
836 for (i = 0; i <= 23; i++) 1053 for (i = 0; i <= 23; i++)
837 lcr[i] = 0xff; 1054 lcr[i] = 0xff;
@@ -888,14 +1105,16 @@ static void saa7115_set_lcr(struct i2c_client *client, struct v4l2_sliced_vbi_fo
888 1105
889 /* write the lcr registers */ 1106 /* write the lcr registers */
890 for (i = 2; i <= 23; i++) { 1107 for (i = 2; i <= 23; i++) {
891 saa7115_write(client, i - 2 + 0x41, lcr[i]); 1108 saa711x_write(client, i - 2 + R_41_LCR_BASE, lcr[i]);
892 } 1109 }
893 1110
894 /* enable/disable raw VBI capturing */ 1111 /* enable/disable raw VBI capturing */
895 saa7115_writeregs(client, fmt->service_set == 0 ? saa7115_cfg_vbi_on : saa7115_cfg_vbi_off); 1112 saa711x_writeregs(client, fmt->service_set == 0 ?
1113 saa7115_cfg_vbi_on :
1114 saa7115_cfg_vbi_off);
896} 1115}
897 1116
898static int saa7115_get_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt) 1117static int saa711x_get_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt)
899{ 1118{
900 static u16 lcr2vbi[] = { 1119 static u16 lcr2vbi[] = {
901 0, V4L2_SLICED_TELETEXT_B, 0, /* 1 */ 1120 0, V4L2_SLICED_TELETEXT_B, 0, /* 1 */
@@ -911,10 +1130,10 @@ static int saa7115_get_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt
911 return -EINVAL; 1130 return -EINVAL;
912 memset(sliced, 0, sizeof(*sliced)); 1131 memset(sliced, 0, sizeof(*sliced));
913 /* done if using raw VBI */ 1132 /* done if using raw VBI */
914 if (saa7115_read(client, 0x80) & 0x10) 1133 if (saa711x_read(client, R_80_GLOBAL_CNTL_1) & 0x10)
915 return 0; 1134 return 0;
916 for (i = 2; i <= 23; i++) { 1135 for (i = 2; i <= 23; i++) {
917 u8 v = saa7115_read(client, i - 2 + 0x41); 1136 u8 v = saa711x_read(client, i - 2 + R_41_LCR_BASE);
918 1137
919 sliced->service_lines[0][i] = lcr2vbi[v >> 4]; 1138 sliced->service_lines[0][i] = lcr2vbi[v >> 4];
920 sliced->service_lines[1][i] = lcr2vbi[v & 0xf]; 1139 sliced->service_lines[1][i] = lcr2vbi[v & 0xf];
@@ -924,114 +1143,31 @@ static int saa7115_get_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt
924 return 0; 1143 return 0;
925} 1144}
926 1145
927static int saa7115_set_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt) 1146static int saa711x_set_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt)
928{ 1147{
929 struct saa7115_state *state = i2c_get_clientdata(client);
930 struct v4l2_pix_format *pix;
931 int HPSC, HFSC;
932 int VSCY, Vsrc;
933 int is_50hz = state->std & V4L2_STD_625_50;
934
935 if (fmt->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) { 1148 if (fmt->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) {
936 saa7115_set_lcr(client, &fmt->fmt.sliced); 1149 saa711x_set_lcr(client, &fmt->fmt.sliced);
937 return 0; 1150 return 0;
938 } 1151 }
939 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1152 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
940 return -EINVAL; 1153 return -EINVAL;
941 1154
942 pix = &(fmt->fmt.pix); 1155 return saa711x_set_size(client,fmt->fmt.pix.width,fmt->fmt.pix.height);
943
944 v4l_dbg(1, debug, client, "decoder set size\n");
945
946 /* FIXME need better bounds checking here */
947 if ((pix->width < 1) || (pix->width > 1440))
948 return -EINVAL;
949 if ((pix->height < 1) || (pix->height > 960))
950 return -EINVAL;
951
952 /* probably have a valid size, let's set it */
953 /* Set output width/height */
954 /* width */
955 saa7115_write(client, 0xcc, (u8) (pix->width & 0xff));
956 saa7115_write(client, 0xcd, (u8) ((pix->width >> 8) & 0xff));
957 /* height */
958 saa7115_write(client, 0xce, (u8) (pix->height & 0xff));
959 saa7115_write(client, 0xcf, (u8) ((pix->height >> 8) & 0xff));
960
961 /* Scaling settings */
962 /* Hprescaler is floor(inres/outres) */
963 /* FIXME hardcoding input res */
964 if (pix->width != 720) {
965 HPSC = (int)(720 / pix->width);
966 /* 0 is not allowed (div. by zero) */
967 HPSC = HPSC ? HPSC : 1;
968 HFSC = (int)((1024 * 720) / (HPSC * pix->width));
969
970 v4l_dbg(1, debug, client, "Hpsc: 0x%05x, Hfsc: 0x%05x\n", HPSC, HFSC);
971 /* FIXME hardcodes to "Task B"
972 * write H prescaler integer */
973 saa7115_write(client, 0xd0, (u8) (HPSC & 0x3f));
974
975 /* write H fine-scaling (luminance) */
976 saa7115_write(client, 0xd8, (u8) (HFSC & 0xff));
977 saa7115_write(client, 0xd9, (u8) ((HFSC >> 8) & 0xff));
978 /* write H fine-scaling (chrominance)
979 * must be lum/2, so i'll just bitshift :) */
980 saa7115_write(client, 0xDC, (u8) ((HFSC >> 1) & 0xff));
981 saa7115_write(client, 0xDD, (u8) ((HFSC >> 9) & 0xff));
982 } else {
983 if (is_50hz) {
984 v4l_dbg(1, debug, client, "Setting full 50hz width\n");
985 saa7115_writeregs(client, saa7115_cfg_50hz_fullres_x);
986 } else {
987 v4l_dbg(1, debug, client, "Setting full 60hz width\n");
988 saa7115_writeregs(client, saa7115_cfg_60hz_fullres_x);
989 }
990 }
991
992 Vsrc = is_50hz ? 576 : 480;
993
994 if (pix->height != Vsrc) {
995 VSCY = (int)((1024 * Vsrc) / pix->height);
996 v4l_dbg(1, debug, client, "Vsrc: %d, Vscy: 0x%05x\n", Vsrc, VSCY);
997
998 /* Correct Contrast and Luminance */
999 saa7115_write(client, 0xd5, (u8) (64 * 1024 / VSCY));
1000 saa7115_write(client, 0xd6, (u8) (64 * 1024 / VSCY));
1001
1002 /* write V fine-scaling (luminance) */
1003 saa7115_write(client, 0xe0, (u8) (VSCY & 0xff));
1004 saa7115_write(client, 0xe1, (u8) ((VSCY >> 8) & 0xff));
1005 /* write V fine-scaling (chrominance) */
1006 saa7115_write(client, 0xe2, (u8) (VSCY & 0xff));
1007 saa7115_write(client, 0xe3, (u8) ((VSCY >> 8) & 0xff));
1008 } else {
1009 if (is_50hz) {
1010 v4l_dbg(1, debug, client, "Setting full 50Hz height\n");
1011 saa7115_writeregs(client, saa7115_cfg_50hz_fullres_y);
1012 } else {
1013 v4l_dbg(1, debug, client, "Setting full 60hz height\n");
1014 saa7115_writeregs(client, saa7115_cfg_60hz_fullres_y);
1015 }
1016 }
1017
1018 saa7115_writeregs(client, saa7115_cfg_reset_scaler);
1019 return 0;
1020} 1156}
1021 1157
1022/* Decode the sliced VBI data stream as created by the saa7115. 1158/* Decode the sliced VBI data stream as created by the saa7115.
1023 The format is described in the saa7115 datasheet in Tables 25 and 26 1159 The format is described in the saa7115 datasheet in Tables 25 and 26
1024 and in Figure 33. 1160 and in Figure 33.
1025 The current implementation uses SAV/EAV codes and not the ancillary data 1161 The current implementation uses SAV/EAV codes and not the ancillary data
1026 headers. The vbi->p pointer points to the SDID byte right after the SAV 1162 headers. The vbi->p pointer points to the R_5E_SDID byte right after the SAV
1027 code. */ 1163 code. */
1028static void saa7115_decode_vbi_line(struct i2c_client *client, 1164static void saa711x_decode_vbi_line(struct i2c_client *client,
1029 struct v4l2_decode_vbi_line *vbi) 1165 struct v4l2_decode_vbi_line *vbi)
1030{ 1166{
1031 static const char vbi_no_data_pattern[] = { 1167 static const char vbi_no_data_pattern[] = {
1032 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0 1168 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0
1033 }; 1169 };
1034 struct saa7115_state *state = i2c_get_clientdata(client); 1170 struct saa711x_state *state = i2c_get_clientdata(client);
1035 u8 *p = vbi->p; 1171 u8 *p = vbi->p;
1036 u32 wss; 1172 u32 wss;
1037 int id1, id2; /* the ID1 and ID2 bytes from the internal header */ 1173 int id1, id2; /* the ID1 and ID2 bytes from the internal header */
@@ -1066,12 +1202,12 @@ static void saa7115_decode_vbi_line(struct i2c_client *client,
1066 vbi->type = V4L2_SLICED_TELETEXT_B; 1202 vbi->type = V4L2_SLICED_TELETEXT_B;
1067 break; 1203 break;
1068 case 4: 1204 case 4:
1069 if (!saa7115_odd_parity(p[0]) || !saa7115_odd_parity(p[1])) 1205 if (!saa711x_odd_parity(p[0]) || !saa711x_odd_parity(p[1]))
1070 return; 1206 return;
1071 vbi->type = V4L2_SLICED_CAPTION_525; 1207 vbi->type = V4L2_SLICED_CAPTION_525;
1072 break; 1208 break;
1073 case 5: 1209 case 5:
1074 wss = saa7115_decode_wss(p); 1210 wss = saa711x_decode_wss(p);
1075 if (wss == -1) 1211 if (wss == -1)
1076 return; 1212 return;
1077 p[0] = wss & 0xff; 1213 p[0] = wss & 0xff;
@@ -1079,7 +1215,7 @@ static void saa7115_decode_vbi_line(struct i2c_client *client,
1079 vbi->type = V4L2_SLICED_WSS_625; 1215 vbi->type = V4L2_SLICED_WSS_625;
1080 break; 1216 break;
1081 case 7: 1217 case 7:
1082 if (saa7115_decode_vps(p, p) != 0) 1218 if (saa711x_decode_vps(p, p) != 0)
1083 return; 1219 return;
1084 vbi->type = V4L2_SLICED_VPS; 1220 vbi->type = V4L2_SLICED_VPS;
1085 break; 1221 break;
@@ -1090,21 +1226,21 @@ static void saa7115_decode_vbi_line(struct i2c_client *client,
1090 1226
1091/* ============ SAA7115 AUDIO settings (end) ============= */ 1227/* ============ SAA7115 AUDIO settings (end) ============= */
1092 1228
1093static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *arg) 1229static int saa711x_command(struct i2c_client *client, unsigned int cmd, void *arg)
1094{ 1230{
1095 struct saa7115_state *state = i2c_get_clientdata(client); 1231 struct saa711x_state *state = i2c_get_clientdata(client);
1096 int *iarg = arg; 1232 int *iarg = arg;
1097 1233
1098 /* ioctls to allow direct access to the saa7115 registers for testing */ 1234 /* ioctls to allow direct access to the saa7115 registers for testing */
1099 switch (cmd) { 1235 switch (cmd) {
1100 case VIDIOC_S_FMT: 1236 case VIDIOC_S_FMT:
1101 return saa7115_set_v4lfmt(client, (struct v4l2_format *)arg); 1237 return saa711x_set_v4lfmt(client, (struct v4l2_format *)arg);
1102 1238
1103 case VIDIOC_G_FMT: 1239 case VIDIOC_G_FMT:
1104 return saa7115_get_v4lfmt(client, (struct v4l2_format *)arg); 1240 return saa711x_get_v4lfmt(client, (struct v4l2_format *)arg);
1105 1241
1106 case VIDIOC_INT_AUDIO_CLOCK_FREQ: 1242 case VIDIOC_INT_AUDIO_CLOCK_FREQ:
1107 return saa7115_set_audio_clock_freq(client, *(u32 *)arg); 1243 return saa711x_set_audio_clock_freq(client, *(u32 *)arg);
1108 1244
1109 case VIDIOC_G_TUNER: 1245 case VIDIOC_G_TUNER:
1110 { 1246 {
@@ -1113,7 +1249,7 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
1113 1249
1114 if (state->radio) 1250 if (state->radio)
1115 break; 1251 break;
1116 status = saa7115_read(client, 0x1f); 1252 status = saa711x_read(client, R_1F_STATUS_BYTE_2_VD_DEC);
1117 1253
1118 v4l_dbg(1, debug, client, "status: 0x%02x\n", status); 1254 v4l_dbg(1, debug, client, "status: 0x%02x\n", status);
1119 vt->signal = ((status & (1 << 6)) == 0) ? 0xffff : 0x0; 1255 vt->signal = ((status & (1 << 6)) == 0) ? 0xffff : 0x0;
@@ -1121,14 +1257,14 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
1121 } 1257 }
1122 1258
1123 case VIDIOC_LOG_STATUS: 1259 case VIDIOC_LOG_STATUS:
1124 saa7115_log_status(client); 1260 saa711x_log_status(client);
1125 break; 1261 break;
1126 1262
1127 case VIDIOC_G_CTRL: 1263 case VIDIOC_G_CTRL:
1128 return saa7115_get_v4lctrl(client, (struct v4l2_control *)arg); 1264 return saa711x_get_v4lctrl(client, (struct v4l2_control *)arg);
1129 1265
1130 case VIDIOC_S_CTRL: 1266 case VIDIOC_S_CTRL:
1131 return saa7115_set_v4lctrl(client, (struct v4l2_control *)arg); 1267 return saa711x_set_v4lctrl(client, (struct v4l2_control *)arg);
1132 1268
1133 case VIDIOC_QUERYCTRL: 1269 case VIDIOC_QUERYCTRL:
1134 { 1270 {
@@ -1146,12 +1282,12 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
1146 } 1282 }
1147 1283
1148 case VIDIOC_G_STD: 1284 case VIDIOC_G_STD:
1149 *(v4l2_std_id *)arg = saa7115_get_v4lstd(client); 1285 *(v4l2_std_id *)arg = saa711x_get_v4lstd(client);
1150 break; 1286 break;
1151 1287
1152 case VIDIOC_S_STD: 1288 case VIDIOC_S_STD:
1153 state->radio = 0; 1289 state->radio = 0;
1154 saa7115_set_v4lstd(client, *(v4l2_std_id *)arg); 1290 saa711x_set_v4lstd(client, *(v4l2_std_id *)arg);
1155 break; 1291 break;
1156 1292
1157 case AUDC_SET_RADIO: 1293 case AUDC_SET_RADIO:
@@ -1187,13 +1323,13 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
1187 state->input = route->input; 1323 state->input = route->input;
1188 1324
1189 /* select mode */ 1325 /* select mode */
1190 saa7115_write(client, 0x02, 1326 saa711x_write(client, R_02_INPUT_CNTL_1,
1191 (saa7115_read(client, 0x02) & 0xf0) | 1327 (saa711x_read(client, R_02_INPUT_CNTL_1) & 0xf0) |
1192 state->input); 1328 state->input);
1193 1329
1194 /* bypass chrominance trap for S-Video modes */ 1330 /* bypass chrominance trap for S-Video modes */
1195 saa7115_write(client, 0x09, 1331 saa711x_write(client, R_09_LUMA_CNTL,
1196 (saa7115_read(client, 0x09) & 0x7f) | 1332 (saa711x_read(client, R_09_LUMA_CNTL) & 0x7f) |
1197 (state->input >= SAA7115_SVIDEO0 ? 0x80 : 0x0)); 1333 (state->input >= SAA7115_SVIDEO0 ? 0x80 : 0x0));
1198 break; 1334 break;
1199 } 1335 }
@@ -1205,7 +1341,9 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
1205 1341
1206 if (state->enable != (cmd == VIDIOC_STREAMON)) { 1342 if (state->enable != (cmd == VIDIOC_STREAMON)) {
1207 state->enable = (cmd == VIDIOC_STREAMON); 1343 state->enable = (cmd == VIDIOC_STREAMON);
1208 saa7115_write(client, 0x87, state->enable); 1344 saa711x_write(client,
1345 R_87_I_PORT_I_O_ENA_OUT_CLK_AND_GATED,
1346 state->enable);
1209 } 1347 }
1210 break; 1348 break;
1211 1349
@@ -1220,17 +1358,17 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
1220 state->cgcdiv = (freq->flags & SAA7115_FREQ_FL_CGCDIV) ? 3 : 4; 1358 state->cgcdiv = (freq->flags & SAA7115_FREQ_FL_CGCDIV) ? 3 : 4;
1221 state->ucgc = (freq->flags & SAA7115_FREQ_FL_UCGC) ? 1 : 0; 1359 state->ucgc = (freq->flags & SAA7115_FREQ_FL_UCGC) ? 1 : 0;
1222 state->apll = (freq->flags & SAA7115_FREQ_FL_APLL) ? 1 : 0; 1360 state->apll = (freq->flags & SAA7115_FREQ_FL_APLL) ? 1 : 0;
1223 saa7115_set_audio_clock_freq(client, state->audclk_freq); 1361 saa711x_set_audio_clock_freq(client, state->audclk_freq);
1224 break; 1362 break;
1225 } 1363 }
1226 1364
1227 case VIDIOC_INT_DECODE_VBI_LINE: 1365 case VIDIOC_INT_DECODE_VBI_LINE:
1228 saa7115_decode_vbi_line(client, arg); 1366 saa711x_decode_vbi_line(client, arg);
1229 break; 1367 break;
1230 1368
1231 case VIDIOC_INT_RESET: 1369 case VIDIOC_INT_RESET:
1232 v4l_dbg(1, debug, client, "decoder RESET\n"); 1370 v4l_dbg(1, debug, client, "decoder RESET\n");
1233 saa7115_writeregs(client, saa7115_cfg_reset_scaler); 1371 saa711x_writeregs(client, saa7115_cfg_reset_scaler);
1234 break; 1372 break;
1235 1373
1236 case VIDIOC_INT_G_VBI_DATA: 1374 case VIDIOC_INT_G_VBI_DATA:
@@ -1239,25 +1377,25 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
1239 1377
1240 switch (data->id) { 1378 switch (data->id) {
1241 case V4L2_SLICED_WSS_625: 1379 case V4L2_SLICED_WSS_625:
1242 if (saa7115_read(client, 0x6b) & 0xc0) 1380 if (saa711x_read(client, 0x6b) & 0xc0)
1243 return -EIO; 1381 return -EIO;
1244 data->data[0] = saa7115_read(client, 0x6c); 1382 data->data[0] = saa711x_read(client, 0x6c);
1245 data->data[1] = saa7115_read(client, 0x6d); 1383 data->data[1] = saa711x_read(client, 0x6d);
1246 return 0; 1384 return 0;
1247 case V4L2_SLICED_CAPTION_525: 1385 case V4L2_SLICED_CAPTION_525:
1248 if (data->field == 0) { 1386 if (data->field == 0) {
1249 /* CC */ 1387 /* CC */
1250 if (saa7115_read(client, 0x66) & 0xc0) 1388 if (saa711x_read(client, 0x66) & 0xc0)
1251 return -EIO; 1389 return -EIO;
1252 data->data[0] = saa7115_read(client, 0x67); 1390 data->data[0] = saa711x_read(client, 0x67);
1253 data->data[1] = saa7115_read(client, 0x68); 1391 data->data[1] = saa711x_read(client, 0x68);
1254 return 0; 1392 return 0;
1255 } 1393 }
1256 /* XDS */ 1394 /* XDS */
1257 if (saa7115_read(client, 0x66) & 0x30) 1395 if (saa711x_read(client, 0x66) & 0x30)
1258 return -EIO; 1396 return -EIO;
1259 data->data[0] = saa7115_read(client, 0x69); 1397 data->data[0] = saa711x_read(client, 0x69);
1260 data->data[1] = saa7115_read(client, 0x6a); 1398 data->data[1] = saa711x_read(client, 0x6a);
1261 return 0; 1399 return 0;
1262 default: 1400 default:
1263 return -EINVAL; 1401 return -EINVAL;
@@ -1272,7 +1410,7 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
1272 1410
1273 if (reg->i2c_id != I2C_DRIVERID_SAA711X) 1411 if (reg->i2c_id != I2C_DRIVERID_SAA711X)
1274 return -EINVAL; 1412 return -EINVAL;
1275 reg->val = saa7115_read(client, reg->reg & 0xff); 1413 reg->val = saa711x_read(client, reg->reg & 0xff);
1276 break; 1414 break;
1277 } 1415 }
1278 1416
@@ -1284,7 +1422,7 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
1284 return -EINVAL; 1422 return -EINVAL;
1285 if (!capable(CAP_SYS_ADMIN)) 1423 if (!capable(CAP_SYS_ADMIN))
1286 return -EPERM; 1424 return -EPERM;
1287 saa7115_write(client, reg->reg & 0xff, reg->val & 0xff); 1425 saa711x_write(client, reg->reg & 0xff, reg->val & 0xff);
1288 break; 1426 break;
1289 } 1427 }
1290#endif 1428#endif
@@ -1302,12 +1440,14 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
1302 1440
1303/* ----------------------------------------------------------------------- */ 1441/* ----------------------------------------------------------------------- */
1304 1442
1305static struct i2c_driver i2c_driver_saa7115; 1443static struct i2c_driver i2c_driver_saa711x;
1306 1444
1307static int saa7115_attach(struct i2c_adapter *adapter, int address, int kind) 1445static int saa711x_attach(struct i2c_adapter *adapter, int address, int kind)
1308{ 1446{
1309 struct i2c_client *client; 1447 struct i2c_client *client;
1310 struct saa7115_state *state; 1448 struct saa711x_state *state;
1449 int i;
1450 char name[17];
1311 u8 chip_id; 1451 u8 chip_id;
1312 1452
1313 /* Check if the adapter supports the needed features */ 1453 /* Check if the adapter supports the needed features */
@@ -1319,28 +1459,31 @@ static int saa7115_attach(struct i2c_adapter *adapter, int address, int kind)
1319 return -ENOMEM; 1459 return -ENOMEM;
1320 client->addr = address; 1460 client->addr = address;
1321 client->adapter = adapter; 1461 client->adapter = adapter;
1322 client->driver = &i2c_driver_saa7115; 1462 client->driver = &i2c_driver_saa711x;
1323 snprintf(client->name, sizeof(client->name) - 1, "saa7115"); 1463 snprintf(client->name, sizeof(client->name) - 1, "saa7115");
1324 1464
1325 v4l_dbg(1, debug, client, "detecting saa7115 client on address 0x%x\n", address << 1); 1465 v4l_dbg(1, debug, client, "detecting saa7115 client on address 0x%x\n", address << 1);
1326 1466
1327 saa7115_write(client, 0, 5); 1467 for (i=0;i<0x0f;i++) {
1328 chip_id = saa7115_read(client, 0) & 0x0f; 1468 saa711x_write(client, 0, i);
1329 if (chip_id < 3 && chip_id > 5) { 1469 name[i] = (saa711x_read(client, 0) &0x0f) +'0';
1330 v4l_dbg(1, debug, client, "saa7115 not found\n"); 1470 if (name[i]>'9')
1331 kfree(client); 1471 name[i]+='a'-'9'-1;
1332 return 0;
1333 } 1472 }
1473 name[i]='\0';
1474
1475 saa711x_write(client, 0, 5);
1476 chip_id = saa711x_read(client, 0) & 0x0f;
1477
1334 snprintf(client->name, sizeof(client->name) - 1, "saa711%d",chip_id); 1478 snprintf(client->name, sizeof(client->name) - 1, "saa711%d",chip_id);
1335 v4l_info(client, "saa711%d found @ 0x%x (%s)\n", chip_id, address << 1, adapter->name); 1479 v4l_info(client, "saa711%d found (%s) @ 0x%x (%s)\n", chip_id, name, address << 1, adapter->name);
1336 1480
1337 state = kzalloc(sizeof(struct saa7115_state), GFP_KERNEL); 1481 state = kzalloc(sizeof(struct saa711x_state), GFP_KERNEL);
1338 i2c_set_clientdata(client, state); 1482 i2c_set_clientdata(client, state);
1339 if (state == NULL) { 1483 if (state == NULL) {
1340 kfree(client); 1484 kfree(client);
1341 return -ENOMEM; 1485 return -ENOMEM;
1342 } 1486 }
1343 state->std = V4L2_STD_NTSC;
1344 state->input = -1; 1487 state->input = -1;
1345 state->enable = 1; 1488 state->enable = 1;
1346 state->radio = 0; 1489 state->radio = 0;
@@ -1349,15 +1492,25 @@ static int saa7115_attach(struct i2c_adapter *adapter, int address, int kind)
1349 state->hue = 0; 1492 state->hue = 0;
1350 state->sat = 64; 1493 state->sat = 64;
1351 switch (chip_id) { 1494 switch (chip_id) {
1495 case 1:
1496 state->ident = V4L2_IDENT_SAA7111;
1497 break;
1352 case 3: 1498 case 3:
1353 state->ident = V4L2_IDENT_SAA7113; 1499 state->ident = V4L2_IDENT_SAA7113;
1354 break; 1500 break;
1355 case 4: 1501 case 4:
1356 state->ident = V4L2_IDENT_SAA7114; 1502 state->ident = V4L2_IDENT_SAA7114;
1357 break; 1503 break;
1358 default: 1504 case 5:
1359 state->ident = V4L2_IDENT_SAA7115; 1505 state->ident = V4L2_IDENT_SAA7115;
1360 break; 1506 break;
1507 case 8:
1508 state->ident = V4L2_IDENT_SAA7118;
1509 break;
1510 default:
1511 state->ident = V4L2_IDENT_SAA7111;
1512 v4l_info(client, "WARNING: Chip is not known - Falling back to saa7111\n");
1513
1361 } 1514 }
1362 1515
1363 state->audclk_freq = 48000; 1516 state->audclk_freq = 48000;
@@ -1365,38 +1518,39 @@ static int saa7115_attach(struct i2c_adapter *adapter, int address, int kind)
1365 v4l_dbg(1, debug, client, "writing init values\n"); 1518 v4l_dbg(1, debug, client, "writing init values\n");
1366 1519
1367 /* init to 60hz/48khz */ 1520 /* init to 60hz/48khz */
1368 if (state->ident == V4L2_IDENT_SAA7113) { 1521 state->crystal_freq = SAA7115_FREQ_24_576_MHZ;
1369 state->crystal_freq = SAA7115_FREQ_24_576_MHZ; 1522 switch (state->ident) {
1370 saa7115_writeregs(client, saa7113_init_auto_input); 1523 case V4L2_IDENT_SAA7111:
1371 } else { 1524 saa711x_writeregs(client, saa7111_init);
1525 break;
1526 case V4L2_IDENT_SAA7113:
1527 saa711x_writeregs(client, saa7113_init);
1528 break;
1529 default:
1372 state->crystal_freq = SAA7115_FREQ_32_11_MHZ; 1530 state->crystal_freq = SAA7115_FREQ_32_11_MHZ;
1373 saa7115_writeregs(client, saa7115_init_auto_input); 1531 saa711x_writeregs(client, saa7115_init_auto_input);
1374 } 1532 }
1375 saa7115_writeregs(client, saa7115_init_misc); 1533 saa711x_writeregs(client, saa7115_init_misc);
1376 saa7115_writeregs(client, saa7115_cfg_60hz_fullres_x); 1534 saa711x_set_v4lstd(client, V4L2_STD_NTSC);
1377 saa7115_writeregs(client, saa7115_cfg_60hz_fullres_y);
1378 saa7115_writeregs(client, saa7115_cfg_60hz_video);
1379 saa7115_set_audio_clock_freq(client, state->audclk_freq);
1380 saa7115_writeregs(client, saa7115_cfg_reset_scaler);
1381 1535
1382 i2c_attach_client(client); 1536 i2c_attach_client(client);
1383 1537
1384 v4l_dbg(1, debug, client, "status: (1E) 0x%02x, (1F) 0x%02x\n", 1538 v4l_dbg(1, debug, client, "status: (1E) 0x%02x, (1F) 0x%02x\n",
1385 saa7115_read(client, 0x1e), saa7115_read(client, 0x1f)); 1539 saa711x_read(client, R_1E_STATUS_BYTE_1_VD_DEC), saa711x_read(client, R_1F_STATUS_BYTE_2_VD_DEC));
1386 1540
1387 return 0; 1541 return 0;
1388} 1542}
1389 1543
1390static int saa7115_probe(struct i2c_adapter *adapter) 1544static int saa711x_probe(struct i2c_adapter *adapter)
1391{ 1545{
1392 if (adapter->class & I2C_CLASS_TV_ANALOG) 1546 if (adapter->class & I2C_CLASS_TV_ANALOG)
1393 return i2c_probe(adapter, &addr_data, &saa7115_attach); 1547 return i2c_probe(adapter, &addr_data, &saa711x_attach);
1394 return 0; 1548 return 0;
1395} 1549}
1396 1550
1397static int saa7115_detach(struct i2c_client *client) 1551static int saa711x_detach(struct i2c_client *client)
1398{ 1552{
1399 struct saa7115_state *state = i2c_get_clientdata(client); 1553 struct saa711x_state *state = i2c_get_clientdata(client);
1400 int err; 1554 int err;
1401 1555
1402 err = i2c_detach_client(client); 1556 err = i2c_detach_client(client);
@@ -1412,26 +1566,26 @@ static int saa7115_detach(struct i2c_client *client)
1412/* ----------------------------------------------------------------------- */ 1566/* ----------------------------------------------------------------------- */
1413 1567
1414/* i2c implementation */ 1568/* i2c implementation */
1415static struct i2c_driver i2c_driver_saa7115 = { 1569static struct i2c_driver i2c_driver_saa711x = {
1416 .driver = { 1570 .driver = {
1417 .name = "saa7115", 1571 .name = "saa7115",
1418 }, 1572 },
1419 .id = I2C_DRIVERID_SAA711X, 1573 .id = I2C_DRIVERID_SAA711X,
1420 .attach_adapter = saa7115_probe, 1574 .attach_adapter = saa711x_probe,
1421 .detach_client = saa7115_detach, 1575 .detach_client = saa711x_detach,
1422 .command = saa7115_command, 1576 .command = saa711x_command,
1423}; 1577};
1424 1578
1425 1579
1426static int __init saa7115_init_module(void) 1580static int __init saa711x_init_module(void)
1427{ 1581{
1428 return i2c_add_driver(&i2c_driver_saa7115); 1582 return i2c_add_driver(&i2c_driver_saa711x);
1429} 1583}
1430 1584
1431static void __exit saa7115_cleanup_module(void) 1585static void __exit saa711x_cleanup_module(void)
1432{ 1586{
1433 i2c_del_driver(&i2c_driver_saa7115); 1587 i2c_del_driver(&i2c_driver_saa711x);
1434} 1588}
1435 1589
1436module_init(saa7115_init_module); 1590module_init(saa711x_init_module);
1437module_exit(saa7115_cleanup_module); 1591module_exit(saa711x_cleanup_module);
diff --git a/drivers/media/video/saa711x_regs.h b/drivers/media/video/saa711x_regs.h
new file mode 100644
index 000000000000..4e5f2eb0a2c1
--- /dev/null
+++ b/drivers/media/video/saa711x_regs.h
@@ -0,0 +1,549 @@
1/* saa711x - Philips SAA711x video decoder register specifications
2 *
3 * Copyright (c) 2006 Mauro Carvalho Chehab <mchehab@infradead.org>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (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
16#define R_00_CHIP_VERSION 0x00
17/* Video Decoder */
18 /* Video Decoder - Frontend part */
19#define R_01_INC_DELAY 0x01
20#define R_02_INPUT_CNTL_1 0x02
21#define R_03_INPUT_CNTL_2 0x03
22#define R_04_INPUT_CNTL_3 0x04
23#define R_05_INPUT_CNTL_4 0x05
24 /* Video Decoder - Decoder part */
25#define R_06_H_SYNC_START 0x06
26#define R_07_H_SYNC_STOP 0x07
27#define R_08_SYNC_CNTL 0x08
28#define R_09_LUMA_CNTL 0x09
29#define R_0A_LUMA_BRIGHT_CNTL 0x0a
30#define R_0B_LUMA_CONTRAST_CNTL 0x0b
31#define R_0C_CHROMA_SAT_CNTL 0x0c
32#define R_0D_CHROMA_HUE_CNTL 0x0d
33#define R_0E_CHROMA_CNTL_1 0x0e
34#define R_0F_CHROMA_GAIN_CNTL 0x0f
35#define R_10_CHROMA_CNTL_2 0x10
36#define R_11_MODE_DELAY_CNTL 0x11
37#define R_12_RT_SIGNAL_CNTL 0x12
38#define R_13_RT_X_PORT_OUT_CNTL 0x13
39#define R_14_ANAL_ADC_COMPAT_CNTL 0x14
40#define R_15_VGATE_START_FID_CHG 0x15
41#define R_16_VGATE_STOP 0x16
42#define R_17_MISC_VGATE_CONF_AND_MSB 0x17
43#define R_18_RAW_DATA_GAIN_CNTL 0x18
44#define R_19_RAW_DATA_OFF_CNTL 0x19
45#define R_1A_COLOR_KILL_LVL_CNTL 0x1a
46#define R_1B_MISC_TVVCRDET 0x1b
47#define R_1C_ENHAN_COMB_CTRL1 0x1c
48#define R_1D_ENHAN_COMB_CTRL2 0x1d
49#define R_1E_STATUS_BYTE_1_VD_DEC 0x1e
50#define R_1F_STATUS_BYTE_2_VD_DEC 0x1f
51
52/* Component processing and interrupt masking part */
53#define R_23_INPUT_CNTL_5 0x23
54#define R_24_INPUT_CNTL_6 0x24
55#define R_25_INPUT_CNTL_7 0x25
56#define R_29_COMP_DELAY 0x29
57#define R_2A_COMP_BRIGHT_CNTL 0x2a
58#define R_2B_COMP_CONTRAST_CNTL 0x2b
59#define R_2C_COMP_SAT_CNTL 0x2c
60#define R_2D_INTERRUPT_MASK_1 0x2d
61#define R_2E_INTERRUPT_MASK_2 0x2e
62#define R_2F_INTERRUPT_MASK_3 0x2f
63
64/* Audio clock generator part */
65#define R_30_AUD_MAST_CLK_CYCLES_PER_FIELD 0x30
66#define R_34_AUD_MAST_CLK_NOMINAL_INC 0x34
67#define R_38_CLK_RATIO_AMXCLK_TO_ASCLK 0x38
68#define R_39_CLK_RATIO_ASCLK_TO_ALRCLK 0x39
69#define R_3A_AUD_CLK_GEN_BASIC_SETUP 0x3a
70
71/* General purpose VBI data slicer part */
72#define R_40_SLICER_CNTL_1 0x40
73#define R_41_LCR_BASE 0x41
74#define R_58_PROGRAM_FRAMING_CODE 0x58
75#define R_59_H_OFF_FOR_SLICER 0x59
76#define R_5A_V_OFF_FOR_SLICER 0x5a
77#define R_5B_FLD_OFF_AND_MSB_FOR_H_AND_V_OFF 0x5b
78#define R_5D_DID 0x5d
79#define R_5E_SDID 0x5e
80#define R_60_SLICER_STATUS_BYTE_0 0x60
81#define R_61_SLICER_STATUS_BYTE_1 0x61
82#define R_62_SLICER_STATUS_BYTE_2 0x62
83
84/* X port, I port and the scaler part */
85 /* Task independent global settings */
86#define R_80_GLOBAL_CNTL_1 0x80
87#define R_81_V_SYNC_FLD_ID_SRC_SEL_AND_RETIMED_V_F 0x81
88#define R_83_X_PORT_I_O_ENA_AND_OUT_CLK 0x83
89#define R_84_I_PORT_SIGNAL_DEF 0x84
90#define R_85_I_PORT_SIGNAL_POLAR 0x85
91#define R_86_I_PORT_FIFO_FLAG_CNTL_AND_ARBIT 0x86
92#define R_87_I_PORT_I_O_ENA_OUT_CLK_AND_GATED 0x87
93#define R_88_POWER_SAVE_ADC_PORT_CNTL 0x88
94#define R_8F_STATUS_INFO_SCALER 0x8f
95 /* Task A definition */
96 /* Basic settings and acquisition window definition */
97#define R_90_A_TASK_HANDLING_CNTL 0x90
98#define R_91_A_X_PORT_FORMATS_AND_CONF 0x91
99#define R_92_A_X_PORT_INPUT_REFERENCE_SIGNAL 0x92
100#define R_93_A_I_PORT_OUTPUT_FORMATS_AND_CONF 0x93
101#define R_94_A_HORIZ_INPUT_WINDOW_START 0x94
102#define R_95_A_HORIZ_INPUT_WINDOW_START_MSB 0x95
103#define R_96_A_HORIZ_INPUT_WINDOW_LENGTH 0x96
104#define R_97_A_HORIZ_INPUT_WINDOW_LENGTH_MSB 0x97
105#define R_98_A_VERT_INPUT_WINDOW_START 0x98
106#define R_99_A_VERT_INPUT_WINDOW_START_MSB 0x99
107#define R_9A_A_VERT_INPUT_WINDOW_LENGTH 0x9a
108#define R_9B_A_VERT_INPUT_WINDOW_LENGTH_MSB 0x9b
109#define R_9C_A_HORIZ_OUTPUT_WINDOW_LENGTH 0x9c
110#define R_9D_A_HORIZ_OUTPUT_WINDOW_LENGTH_MSB 0x9d
111#define R_9E_A_VERT_OUTPUT_WINDOW_LENGTH 0x9e
112#define R_9F_A_VERT_OUTPUT_WINDOW_LENGTH_MSB 0x9f
113 /* FIR filtering and prescaling */
114#define R_A0_A_HORIZ_PRESCALING 0xa0
115#define R_A1_A_ACCUMULATION_LENGTH 0xa1
116#define R_A2_A_PRESCALER_DC_GAIN_AND_FIR_PREFILTER 0xa2
117#define R_A4_A_LUMA_BRIGHTNESS_CNTL 0xa4
118#define R_A5_A_LUMA_CONTRAST_CNTL 0xa5
119#define R_A6_A_CHROMA_SATURATION_CNTL 0xa6
120 /* Horizontal phase scaling */
121#define R_A8_A_HORIZ_LUMA_SCALING_INC 0xa8
122#define R_A9_A_HORIZ_LUMA_SCALING_INC_MSB 0xa9
123#define R_AA_A_HORIZ_LUMA_PHASE_OFF 0xaa
124#define R_AC_A_HORIZ_CHROMA_SCALING_INC 0xac
125#define R_AD_A_HORIZ_CHROMA_SCALING_INC_MSB 0xad
126#define R_AE_A_HORIZ_CHROMA_PHASE_OFF 0xae
127#define R_AF_A_HORIZ_CHROMA_PHASE_OFF_MSB 0xaf
128 /* Vertical scaling */
129#define R_B0_A_VERT_LUMA_SCALING_INC 0xb0
130#define R_B1_A_VERT_LUMA_SCALING_INC_MSB 0xb1
131#define R_B2_A_VERT_CHROMA_SCALING_INC 0xb2
132#define R_B3_A_VERT_CHROMA_SCALING_INC_MSB 0xb3
133#define R_B4_A_VERT_SCALING_MODE_CNTL 0xb4
134#define R_B8_A_VERT_CHROMA_PHASE_OFF_00 0xb8
135#define R_B9_A_VERT_CHROMA_PHASE_OFF_01 0xb9
136#define R_BA_A_VERT_CHROMA_PHASE_OFF_10 0xba
137#define R_BB_A_VERT_CHROMA_PHASE_OFF_11 0xbb
138#define R_BC_A_VERT_LUMA_PHASE_OFF_00 0xbc
139#define R_BD_A_VERT_LUMA_PHASE_OFF_01 0xbd
140#define R_BE_A_VERT_LUMA_PHASE_OFF_10 0xbe
141#define R_BF_A_VERT_LUMA_PHASE_OFF_11 0xbf
142 /* Task B definition */
143 /* Basic settings and acquisition window definition */
144#define R_C0_B_TASK_HANDLING_CNTL 0xc0
145#define R_C1_B_X_PORT_FORMATS_AND_CONF 0xc1
146#define R_C2_B_INPUT_REFERENCE_SIGNAL_DEFINITION 0xc2
147#define R_C3_B_I_PORT_FORMATS_AND_CONF 0xc3
148#define R_C4_B_HORIZ_INPUT_WINDOW_START 0xc4
149#define R_C5_B_HORIZ_INPUT_WINDOW_START_MSB 0xc5
150#define R_C6_B_HORIZ_INPUT_WINDOW_LENGTH 0xc6
151#define R_C7_B_HORIZ_INPUT_WINDOW_LENGTH_MSB 0xc7
152#define R_C8_B_VERT_INPUT_WINDOW_START 0xc8
153#define R_C9_B_VERT_INPUT_WINDOW_START_MSB 0xc9
154#define R_CA_B_VERT_INPUT_WINDOW_LENGTH 0xca
155#define R_CB_B_VERT_INPUT_WINDOW_LENGTH_MSB 0xcb
156#define R_CC_B_HORIZ_OUTPUT_WINDOW_LENGTH 0xcc
157#define R_CD_B_HORIZ_OUTPUT_WINDOW_LENGTH_MSB 0xcd
158#define R_CE_B_VERT_OUTPUT_WINDOW_LENGTH 0xce
159#define R_CF_B_VERT_OUTPUT_WINDOW_LENGTH_MSB 0xcf
160 /* FIR filtering and prescaling */
161#define R_D0_B_HORIZ_PRESCALING 0xd0
162#define R_D1_B_ACCUMULATION_LENGTH 0xd1
163#define R_D2_B_PRESCALER_DC_GAIN_AND_FIR_PREFILTER 0xd2
164#define R_D4_B_LUMA_BRIGHTNESS_CNTL 0xd4
165#define R_D5_B_LUMA_CONTRAST_CNTL 0xd5
166#define R_D6_B_CHROMA_SATURATION_CNTL 0xd6
167 /* Horizontal phase scaling */
168#define R_D8_B_HORIZ_LUMA_SCALING_INC 0xd8
169#define R_D9_B_HORIZ_LUMA_SCALING_INC_MSB 0xd9
170#define R_DA_B_HORIZ_LUMA_PHASE_OFF 0xda
171#define R_DC_B_HORIZ_CHROMA_SCALING 0xdc
172#define R_DD_B_HORIZ_CHROMA_SCALING_MSB 0xdd
173#define R_DE_B_HORIZ_PHASE_OFFSET_CRHOMA 0xde
174 /* Vertical scaling */
175#define R_E0_B_VERT_LUMA_SCALING_INC 0xe0
176#define R_E1_B_VERT_LUMA_SCALING_INC_MSB 0xe1
177#define R_E2_B_VERT_CHROMA_SCALING_INC 0xe2
178#define R_E3_B_VERT_CHROMA_SCALING_INC_MSB 0xe3
179#define R_E4_B_VERT_SCALING_MODE_CNTL 0xe4
180#define R_E8_B_VERT_CHROMA_PHASE_OFF_00 0xe8
181#define R_E9_B_VERT_CHROMA_PHASE_OFF_01 0xe9
182#define R_EA_B_VERT_CHROMA_PHASE_OFF_10 0xea
183#define R_EB_B_VERT_CHROMA_PHASE_OFF_11 0xeb
184#define R_EC_B_VERT_LUMA_PHASE_OFF_00 0xec
185#define R_ED_B_VERT_LUMA_PHASE_OFF_01 0xed
186#define R_EE_B_VERT_LUMA_PHASE_OFF_10 0xee
187#define R_EF_B_VERT_LUMA_PHASE_OFF_11 0xef
188
189/* second PLL (PLL2) and Pulsegenerator Programming */
190#define R_F0_LFCO_PER_LINE 0xf0
191#define R_F1_P_I_PARAM_SELECT 0xf1
192#define R_F2_NOMINAL_PLL2_DTO 0xf2
193#define R_F3_PLL_INCREMENT 0xf3
194#define R_F4_PLL2_STATUS 0xf4
195#define R_F5_PULSGEN_LINE_LENGTH 0xf5
196#define R_F6_PULSE_A_POS_LSB_AND_PULSEGEN_CONFIG 0xf6
197#define R_F7_PULSE_A_POS_MSB 0xf7
198#define R_F8_PULSE_B_POS 0xf8
199#define R_F9_PULSE_B_POS_MSB 0xf9
200#define R_FA_PULSE_C_POS 0xfa
201#define R_FB_PULSE_C_POS_MSB 0xfb
202#define R_FF_S_PLL_MAX_PHASE_ERR_THRESH_NUM_LINES 0xff
203
204#if 0
205/* Those structs will be used in the future for debug purposes */
206struct saa711x_reg_descr {
207 u8 reg;
208 int count;
209 char *name;
210};
211
212struct saa711x_reg_descr saa711x_regs[] = {
213 /* REG COUNT NAME */
214 {R_00_CHIP_VERSION,1,
215 "Chip version"},
216
217 /* Video Decoder: R_01_INC_DELAY to R_1F_STATUS_BYTE_2_VD_DEC */
218
219 /* Video Decoder - Frontend part: R_01_INC_DELAY to R_05_INPUT_CNTL_4 */
220 {R_01_INC_DELAY,1,
221 "Increment delay"},
222 {R_02_INPUT_CNTL_1,1,
223 "Analog input control 1"},
224 {R_03_INPUT_CNTL_2,1,
225 "Analog input control 2"},
226 {R_04_INPUT_CNTL_3,1,
227 "Analog input control 3"},
228 {R_05_INPUT_CNTL_4,1,
229 "Analog input control 4"},
230
231 /* Video Decoder - Decoder part: R_06_H_SYNC_START to R_1F_STATUS_BYTE_2_VD_DEC */
232 {R_06_H_SYNC_START,1,
233 "Horizontal sync start"},
234 {R_07_H_SYNC_STOP,1,
235 "Horizontal sync stop"},
236 {R_08_SYNC_CNTL,1,
237 "Sync control"},
238 {R_09_LUMA_CNTL,1,
239 "Luminance control"},
240 {R_0A_LUMA_BRIGHT_CNTL,1,
241 "Luminance brightness control"},
242 {R_0B_LUMA_CONTRAST_CNTL,1,
243 "Luminance contrast control"},
244 {R_0C_CHROMA_SAT_CNTL,1,
245 "Chrominance saturation control"},
246 {R_0D_CHROMA_HUE_CNTL,1,
247 "Chrominance hue control"},
248 {R_0E_CHROMA_CNTL_1,1,
249 "Chrominance control 1"},
250 {R_0F_CHROMA_GAIN_CNTL,1,
251 "Chrominance gain control"},
252 {R_10_CHROMA_CNTL_2,1,
253 "Chrominance control 2"},
254 {R_11_MODE_DELAY_CNTL,1,
255 "Mode/delay control"},
256 {R_12_RT_SIGNAL_CNTL,1,
257 "RT signal control"},
258 {R_13_RT_X_PORT_OUT_CNTL,1,
259 "RT/X port output control"},
260 {R_14_ANAL_ADC_COMPAT_CNTL,1,
261 "Analog/ADC/compatibility control"},
262 {R_15_VGATE_START_FID_CHG, 1,
263 "VGATE start FID change"},
264 {R_16_VGATE_STOP,1,
265 "VGATE stop"},
266 {R_17_MISC_VGATE_CONF_AND_MSB, 1,
267 "Miscellaneous VGATE configuration and MSBs"},
268 {R_18_RAW_DATA_GAIN_CNTL,1,
269 "Raw data gain control",},
270 {R_19_RAW_DATA_OFF_CNTL,1,
271 "Raw data offset control",},
272 {R_1A_COLOR_KILL_LVL_CNTL,1,
273 "Color Killer Level Control"},
274 { R_1B_MISC_TVVCRDET, 1,
275 "MISC /TVVCRDET"},
276 { R_1C_ENHAN_COMB_CTRL1, 1,
277 "Enhanced comb ctrl1"},
278 { R_1D_ENHAN_COMB_CTRL2, 1,
279 "Enhanced comb ctrl1"},
280 {R_1E_STATUS_BYTE_1_VD_DEC,1,
281 "Status byte 1 video decoder"},
282 {R_1F_STATUS_BYTE_2_VD_DEC,1,
283 "Status byte 2 video decoder"},
284
285 /* Component processing and interrupt masking part: 0x20h to R_2F_INTERRUPT_MASK_3 */
286 /* 0x20 to 0x22 - Reserved */
287 {R_23_INPUT_CNTL_5,1,
288 "Analog input control 5"},
289 {R_24_INPUT_CNTL_6,1,
290 "Analog input control 6"},
291 {R_25_INPUT_CNTL_7,1,
292 "Analog input control 7"},
293 /* 0x26 to 0x28 - Reserved */
294 {R_29_COMP_DELAY,1,
295 "Component delay"},
296 {R_2A_COMP_BRIGHT_CNTL,1,
297 "Component brightness control"},
298 {R_2B_COMP_CONTRAST_CNTL,1,
299 "Component contrast control"},
300 {R_2C_COMP_SAT_CNTL,1,
301 "Component saturation control"},
302 {R_2D_INTERRUPT_MASK_1,1,
303 "Interrupt mask 1"},
304 {R_2E_INTERRUPT_MASK_2,1,
305 "Interrupt mask 2"},
306 {R_2F_INTERRUPT_MASK_3,1,
307 "Interrupt mask 3"},
308
309 /* Audio clock generator part: R_30_AUD_MAST_CLK_CYCLES_PER_FIELD to 0x3f */
310 {R_30_AUD_MAST_CLK_CYCLES_PER_FIELD,3,
311 "Audio master clock cycles per field"},
312 /* 0x33 - Reserved */
313 {R_34_AUD_MAST_CLK_NOMINAL_INC,3,
314 "Audio master clock nominal increment"},
315 /* 0x37 - Reserved */
316 {R_38_CLK_RATIO_AMXCLK_TO_ASCLK,1,
317 "Clock ratio AMXCLK to ASCLK"},
318 {R_39_CLK_RATIO_ASCLK_TO_ALRCLK,1,
319 "Clock ratio ASCLK to ALRCLK"},
320 {R_3A_AUD_CLK_GEN_BASIC_SETUP,1,
321 "Audio clock generator basic setup"},
322 /* 0x3b-0x3f - Reserved */
323
324 /* General purpose VBI data slicer part: R_40_SLICER_CNTL_1 to 0x7f */
325 {R_40_SLICER_CNTL_1,1,
326 "Slicer control 1"},
327 {R_41_LCR,23,
328 "R_41_LCR"},
329 {R_58_PROGRAM_FRAMING_CODE,1,
330 "Programmable framing code"},
331 {R_59_H_OFF_FOR_SLICER,1,
332 "Horizontal offset for slicer"},
333 {R_5A_V_OFF_FOR_SLICER,1,
334 "Vertical offset for slicer"},
335 {R_5B_FLD_OFF_AND_MSB_FOR_H_AND_V_OFF,1,
336 "Field offset and MSBs for horizontal and vertical offset"},
337 {R_5D_DID,1,
338 "Header and data identification (R_5D_DID)"},
339 {R_5E_SDID,1,
340 "Sliced data identification (R_5E_SDID) code"},
341 {R_60_SLICER_STATUS_BYTE_0,1,
342 "Slicer status byte 0"},
343 {R_61_SLICER_STATUS_BYTE_1,1,
344 "Slicer status byte 1"},
345 {R_62_SLICER_STATUS_BYTE_2,1,
346 "Slicer status byte 2"},
347 /* 0x63-0x7f - Reserved */
348
349 /* X port, I port and the scaler part: R_80_GLOBAL_CNTL_1 to R_EF_B_VERT_LUMA_PHASE_OFF_11 */
350 /* Task independent global settings: R_80_GLOBAL_CNTL_1 to R_8F_STATUS_INFO_SCALER */
351 {R_80_GLOBAL_CNTL_1,1,
352 "Global control 1"},
353 {R_81_V_SYNC_FLD_ID_SRC_SEL_AND_RETIMED_V_F,1,
354 "Vertical sync and Field ID source selection, retimed V and F signals"},
355 /* 0x82 - Reserved */
356 {R_83_X_PORT_I_O_ENA_AND_OUT_CLK,1,
357 "X port I/O enable and output clock"},
358 {R_84_I_PORT_SIGNAL_DEF,1,
359 "I port signal definitions"},
360 {R_85_I_PORT_SIGNAL_POLAR,1,
361 "I port signal polarities"},
362 {R_86_I_PORT_FIFO_FLAG_CNTL_AND_ARBIT,1,
363 "I port FIFO flag control and arbitration"},
364 {R_87_I_PORT_I_O_ENA_OUT_CLK_AND_GATED, 1,
365 "I port I/O enable output clock and gated"},
366 {R_88_POWER_SAVE_ADC_PORT_CNTL,1,
367 "Power save/ADC port control"},
368 /* 089-0x8e - Reserved */
369 {R_8F_STATUS_INFO_SCALER,1,
370 "Status information scaler part"},
371
372 /* Task A definition: R_90_A_TASK_HANDLING_CNTL to R_BF_A_VERT_LUMA_PHASE_OFF_11 */
373 /* Task A: Basic settings and acquisition window definition */
374 {R_90_A_TASK_HANDLING_CNTL,1,
375 "Task A: Task handling control"},
376 {R_91_A_X_PORT_FORMATS_AND_CONF,1,
377 "Task A: X port formats and configuration"},
378 {R_92_A_X_PORT_INPUT_REFERENCE_SIGNAL,1,
379 "Task A: X port input reference signal definition"},
380 {R_93_A_I_PORT_OUTPUT_FORMATS_AND_CONF,1,
381 "Task A: I port output formats and configuration"},
382 {R_94_A_HORIZ_INPUT_WINDOW_START,2,
383 "Task A: Horizontal input window start"},
384 {R_96_A_HORIZ_INPUT_WINDOW_LENGTH,2,
385 "Task A: Horizontal input window length"},
386 {R_98_A_VERT_INPUT_WINDOW_START,2,
387 "Task A: Vertical input window start"},
388 {R_9A_A_VERT_INPUT_WINDOW_LENGTH,2,
389 "Task A: Vertical input window length"},
390 {R_9C_A_HORIZ_OUTPUT_WINDOW_LENGTH,2,
391 "Task A: Horizontal output window length"},
392 {R_9E_A_VERT_OUTPUT_WINDOW_LENGTH,2,
393 "Task A: Vertical output window length"},
394
395 /* Task A: FIR filtering and prescaling */
396 {R_A0_A_HORIZ_PRESCALING,1,
397 "Task A: Horizontal prescaling"},
398 {R_A1_A_ACCUMULATION_LENGTH,1,
399 "Task A: Accumulation length"},
400 {R_A2_A_PRESCALER_DC_GAIN_AND_FIR_PREFILTER,1,
401 "Task A: Prescaler DC gain and FIR prefilter"},
402 /* 0xa3 - Reserved */
403 {R_A4_A_LUMA_BRIGHTNESS_CNTL,1,
404 "Task A: Luminance brightness control"},
405 {R_A5_A_LUMA_CONTRAST_CNTL,1,
406 "Task A: Luminance contrast control"},
407 {R_A6_A_CHROMA_SATURATION_CNTL,1,
408 "Task A: Chrominance saturation control"},
409 /* 0xa7 - Reserved */
410
411 /* Task A: Horizontal phase scaling */
412 {R_A8_A_HORIZ_LUMA_SCALING_INC,2,
413 "Task A: Horizontal luminance scaling increment"},
414 {R_AA_A_HORIZ_LUMA_PHASE_OFF,1,
415 "Task A: Horizontal luminance phase offset"},
416 /* 0xab - Reserved */
417 {R_AC_A_HORIZ_CHROMA_SCALING_INC,2,
418 "Task A: Horizontal chrominance scaling increment"},
419 {R_AE_A_HORIZ_CHROMA_PHASE_OFF,1,
420 "Task A: Horizontal chrominance phase offset"},
421 /* 0xaf - Reserved */
422
423 /* Task A: Vertical scaling */
424 {R_B0_A_VERT_LUMA_SCALING_INC,2,
425 "Task A: Vertical luminance scaling increment"},
426 {R_B2_A_VERT_CHROMA_SCALING_INC,2,
427 "Task A: Vertical chrominance scaling increment"},
428 {R_B4_A_VERT_SCALING_MODE_CNTL,1,
429 "Task A: Vertical scaling mode control"},
430 /* 0xb5-0xb7 - Reserved */
431 {R_B8_A_VERT_CHROMA_PHASE_OFF_00,1,
432 "Task A: Vertical chrominance phase offset '00'"},
433 {R_B9_A_VERT_CHROMA_PHASE_OFF_01,1,
434 "Task A: Vertical chrominance phase offset '01'"},
435 {R_BA_A_VERT_CHROMA_PHASE_OFF_10,1,
436 "Task A: Vertical chrominance phase offset '10'"},
437 {R_BB_A_VERT_CHROMA_PHASE_OFF_11,1,
438 "Task A: Vertical chrominance phase offset '11'"},
439 {R_BC_A_VERT_LUMA_PHASE_OFF_00,1,
440 "Task A: Vertical luminance phase offset '00'"},
441 {R_BD_A_VERT_LUMA_PHASE_OFF_01,1,
442 "Task A: Vertical luminance phase offset '01'"},
443 {R_BE_A_VERT_LUMA_PHASE_OFF_10,1,
444 "Task A: Vertical luminance phase offset '10'"},
445 {R_BF_A_VERT_LUMA_PHASE_OFF_11,1,
446 "Task A: Vertical luminance phase offset '11'"},
447
448 /* Task B definition: R_C0_B_TASK_HANDLING_CNTL to R_EF_B_VERT_LUMA_PHASE_OFF_11 */
449 /* Task B: Basic settings and acquisition window definition */
450 {R_C0_B_TASK_HANDLING_CNTL,1,
451 "Task B: Task handling control"},
452 {R_C1_B_X_PORT_FORMATS_AND_CONF,1,
453 "Task B: X port formats and configuration"},
454 {R_C2_B_INPUT_REFERENCE_SIGNAL_DEFINITION,1,
455 "Task B: Input reference signal definition"},
456 {R_C3_B_I_PORT_FORMATS_AND_CONF,1,
457 "Task B: I port formats and configuration"},
458 {R_C4_B_HORIZ_INPUT_WINDOW_START,2,
459 "Task B: Horizontal input window start"},
460 {R_C6_B_HORIZ_INPUT_WINDOW_LENGTH,2,
461 "Task B: Horizontal input window length"},
462 {R_C8_B_VERT_INPUT_WINDOW_START,2,
463 "Task B: Vertical input window start"},
464 {R_CA_B_VERT_INPUT_WINDOW_LENGTH,2,
465 "Task B: Vertical input window length"},
466 {R_CC_B_HORIZ_OUTPUT_WINDOW_LENGTH,2,
467 "Task B: Horizontal output window length"},
468 {R_CE_B_VERT_OUTPUT_WINDOW_LENGTH,2,
469 "Task B: Vertical output window length"},
470
471 /* Task B: FIR filtering and prescaling */
472 {R_D0_B_HORIZ_PRESCALING,1,
473 "Task B: Horizontal prescaling"},
474 {R_D1_B_ACCUMULATION_LENGTH,1,
475 "Task B: Accumulation length"},
476 {R_D2_B_PRESCALER_DC_GAIN_AND_FIR_PREFILTER,1,
477 "Task B: Prescaler DC gain and FIR prefilter"},
478 /* 0xd3 - Reserved */
479 {R_D4_B_LUMA_BRIGHTNESS_CNTL,1,
480 "Task B: Luminance brightness control"},
481 {R_D5_B_LUMA_CONTRAST_CNTL,1,
482 "Task B: Luminance contrast control"},
483 {R_D6_B_CHROMA_SATURATION_CNTL,1,
484 "Task B: Chrominance saturation control"},
485 /* 0xd7 - Reserved */
486
487 /* Task B: Horizontal phase scaling */
488 {R_D8_B_HORIZ_LUMA_SCALING_INC,2,
489 "Task B: Horizontal luminance scaling increment"},
490 {R_DA_B_HORIZ_LUMA_PHASE_OFF,1,
491 "Task B: Horizontal luminance phase offset"},
492 /* 0xdb - Reserved */
493 {R_DC_B_HORIZ_CHROMA_SCALING,2,
494 "Task B: Horizontal chrominance scaling"},
495 {R_DE_B_HORIZ_PHASE_OFFSET_CRHOMA,1,
496 "Task B: Horizontal Phase Offset Chroma"},
497 /* 0xdf - Reserved */
498
499 /* Task B: Vertical scaling */
500 {R_E0_B_VERT_LUMA_SCALING_INC,2,
501 "Task B: Vertical luminance scaling increment"},
502 {R_E2_B_VERT_CHROMA_SCALING_INC,2,
503 "Task B: Vertical chrominance scaling increment"},
504 {R_E4_B_VERT_SCALING_MODE_CNTL,1,
505 "Task B: Vertical scaling mode control"},
506 /* 0xe5-0xe7 - Reserved */
507 {R_E8_B_VERT_CHROMA_PHASE_OFF_00,1,
508 "Task B: Vertical chrominance phase offset '00'"},
509 {R_E9_B_VERT_CHROMA_PHASE_OFF_01,1,
510 "Task B: Vertical chrominance phase offset '01'"},
511 {R_EA_B_VERT_CHROMA_PHASE_OFF_10,1,
512 "Task B: Vertical chrominance phase offset '10'"},
513 {R_EB_B_VERT_CHROMA_PHASE_OFF_11,1,
514 "Task B: Vertical chrominance phase offset '11'"},
515 {R_EC_B_VERT_LUMA_PHASE_OFF_00,1,
516 "Task B: Vertical luminance phase offset '00'"},
517 {R_ED_B_VERT_LUMA_PHASE_OFF_01,1,
518 "Task B: Vertical luminance phase offset '01'"},
519 {R_EE_B_VERT_LUMA_PHASE_OFF_10,1,
520 "Task B: Vertical luminance phase offset '10'"},
521 {R_EF_B_VERT_LUMA_PHASE_OFF_11,1,
522 "Task B: Vertical luminance phase offset '11'"},
523
524 /* second PLL (PLL2) and Pulsegenerator Programming */
525 { R_F0_LFCO_PER_LINE, 1,
526 "LFCO's per line"},
527 { R_F1_P_I_PARAM_SELECT,1,
528 "P-/I- Param. Select., PLL Mode, PLL H-Src., LFCO's per line"},
529 { R_F2_NOMINAL_PLL2_DTO,1,
530 "Nominal PLL2 DTO"},
531 {R_F3_PLL_INCREMENT,1,
532 "PLL2 Increment"},
533 {R_F4_PLL2_STATUS,1,
534 "PLL2 Status"},
535 {R_F5_PULSGEN_LINE_LENGTH,1,
536 "Pulsgen. line length"},
537 {R_F6_PULSE_A_POS_LSB_AND_PULSEGEN_CONFIG,1,
538 "Pulse A Position, Pulsgen Resync., Pulsgen. H-Src., Pulsgen. line length"},
539 {R_F7_PULSE_A_POS_MSB,1,
540 "Pulse A Position"},
541 {R_F8_PULSE_B_POS,2,
542 "Pulse B Position"},
543 {R_FA_PULSE_C_POS,2,
544 "Pulse C Position"},
545 /* 0xfc to 0xfe - Reserved */
546 {R_FF_S_PLL_MAX_PHASE_ERR_THRESH_NUM_LINES,1,
547 "S_PLL max. phase, error threshold, PLL2 no. of lines, threshold"},
548};
549#endif
diff --git a/drivers/media/video/saa7134/Kconfig b/drivers/media/video/saa7134/Kconfig
index f5543166d193..59da79ce2efd 100644
--- a/drivers/media/video/saa7134/Kconfig
+++ b/drivers/media/video/saa7134/Kconfig
@@ -41,53 +41,15 @@ config VIDEO_SAA7134_DVB
41 select VIDEO_BUF_DVB 41 select VIDEO_BUF_DVB
42 select FW_LOADER 42 select FW_LOADER
43 select DVB_PLL 43 select DVB_PLL
44 select DVB_MT352 if !DVB_FE_CUSTOMISE
45 select DVB_TDA1004X if !DVB_FE_CUSTOMISE
46 select DVB_NXT200X if !DVB_FE_CUSTOMISE
47 select DVB_TDA10086 if !DVB_FE_CUSTOMISE
48 select DVB_TDA826X if !DVB_FE_CUSTOMISE
49 select DVB_ISL6421 if !DVB_FE_CUSTOMISE
44 ---help--- 50 ---help---
45 This adds support for DVB cards based on the 51 This adds support for DVB cards based on the
46 Philips saa7134 chip. 52 Philips saa7134 chip.
47 53
48 To compile this driver as a module, choose M here: the 54 To compile this driver as a module, choose M here: the
49 module will be called saa7134-dvb. 55 module will be called saa7134-dvb.
50
51 You must also select one or more DVB demodulators.
52 If you are unsure which you need, choose all of them.
53
54config VIDEO_SAA7134_DVB_ALL_FRONTENDS
55 bool "Build all supported frontends for saa7134 based TV cards"
56 default y
57 depends on VIDEO_SAA7134_DVB
58 select DVB_MT352
59 select DVB_TDA1004X
60 select DVB_NXT200X
61 ---help---
62 This builds saa7134-dvb with all currently supported frontend
63 demodulators. If you wish to tweak your configuration, and
64 only include support for the hardware that you need, choose N here.
65
66 If you are unsure, choose Y.
67
68config VIDEO_SAA7134_DVB_MT352
69 bool "Zarlink MT352 DVB-T Support"
70 default y
71 depends on VIDEO_SAA7134_DVB && !VIDEO_SAA7134_DVB_ALL_FRONTENDS
72 select DVB_MT352
73 ---help---
74 This adds DVB-T support for cards based on the
75 Philips saa7134 chip and the MT352 demodulator.
76
77config VIDEO_SAA7134_DVB_TDA1004X
78 bool "Phillips TDA10045H/TDA10046H DVB-T Support"
79 default y
80 depends on VIDEO_SAA7134_DVB && !VIDEO_SAA7134_DVB_ALL_FRONTENDS
81 select DVB_TDA1004X
82 ---help---
83 This adds DVB-T support for cards based on the
84 Philips saa7134 chip and the TDA10045H/TDA10046H demodulator.
85
86config VIDEO_SAA7134_DVB_NXT200X
87 bool "NXT2002/NXT2004 ATSC Support"
88 default y
89 depends on VIDEO_SAA7134_DVB && !VIDEO_SAA7134_DVB_ALL_FRONTENDS
90 select DVB_NXT200X
91 ---help---
92 This adds ATSC 8VSB and QAM64/256 support for cards based on the
93 Philips saa7134 chip and the NXT2002/NXT2004 demodulator.
diff --git a/drivers/media/video/saa7134/Makefile b/drivers/media/video/saa7134/Makefile
index be7b9ee697d6..89a1565b4256 100644
--- a/drivers/media/video/saa7134/Makefile
+++ b/drivers/media/video/saa7134/Makefile
@@ -16,8 +16,5 @@ EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
16EXTRA_CFLAGS += -Idrivers/media/dvb/frontends 16EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
17 17
18extra-cflags-$(CONFIG_VIDEO_BUF_DVB) += -DHAVE_VIDEO_BUF_DVB=1 18extra-cflags-$(CONFIG_VIDEO_BUF_DVB) += -DHAVE_VIDEO_BUF_DVB=1
19extra-cflags-$(CONFIG_DVB_MT352) += -DHAVE_MT352=1
20extra-cflags-$(CONFIG_DVB_TDA1004X) += -DHAVE_TDA1004X=1
21extra-cflags-$(CONFIG_DVB_NXT200X) += -DHAVE_NXT200X=1
22 19
23EXTRA_CFLAGS += $(extra-cflags-y) $(extra-cflags-m) 20EXTRA_CFLAGS += $(extra-cflags-y) $(extra-cflags-m)
diff --git a/drivers/media/video/saa7134/saa7134-alsa.c b/drivers/media/video/saa7134/saa7134-alsa.c
index d73cff1970ae..a39e0136ce3b 100644
--- a/drivers/media/video/saa7134/saa7134-alsa.c
+++ b/drivers/media/video/saa7134/saa7134-alsa.c
@@ -590,6 +590,11 @@ static int snd_card_saa7134_hw_free(struct snd_pcm_substream * substream)
590 590
591static int snd_card_saa7134_capture_close(struct snd_pcm_substream * substream) 591static int snd_card_saa7134_capture_close(struct snd_pcm_substream * substream)
592{ 592{
593 snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream);
594 struct saa7134_dev *dev = saa7134->dev;
595
596 dev->ctl_mute = 1;
597 saa7134_tvaudio_setmute(dev);
593 return 0; 598 return 0;
594} 599}
595 600
@@ -631,6 +636,9 @@ static int snd_card_saa7134_capture_open(struct snd_pcm_substream * substream)
631 runtime->private_free = snd_card_saa7134_runtime_free; 636 runtime->private_free = snd_card_saa7134_runtime_free;
632 runtime->hw = snd_card_saa7134_capture; 637 runtime->hw = snd_card_saa7134_capture;
633 638
639 dev->ctl_mute = 0;
640 saa7134_tvaudio_setmute(dev);
641
634 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) 642 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
635 return err; 643 return err;
636 644
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 927413aded10..aa1db509f3d4 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -1911,7 +1911,7 @@ struct saa7134_board saa7134_boards[] = {
1911 }, 1911 },
1912 }, 1912 },
1913 [SAA7134_BOARD_FLYDVBT_DUO_CARDBUS] = { 1913 [SAA7134_BOARD_FLYDVBT_DUO_CARDBUS] = {
1914 .name = "LifeView/Typhoon FlyDVB-T Duo Cardbus", 1914 .name = "LifeView/Typhoon/Genius FlyDVB-T Duo Cardbus",
1915 .audio_clock = 0x00200000, 1915 .audio_clock = 0x00200000,
1916 .tuner_type = TUNER_PHILIPS_TDA8290, 1916 .tuner_type = TUNER_PHILIPS_TDA8290,
1917 .radio_type = UNSET, 1917 .radio_type = UNSET,
@@ -2891,6 +2891,80 @@ struct saa7134_board saa7134_boards[] = {
2891 .gpio = 0x8000, 2891 .gpio = 0x8000,
2892 }, 2892 },
2893 }, 2893 },
2894 [SAA7134_BOARD_MEDION_MD8800_QUADRO] = {
2895 .name = "Medion Md8800 Quadro",
2896 .audio_clock = 0x00187de7,
2897 .tuner_type = TUNER_PHILIPS_TDA8290,
2898 .radio_type = UNSET,
2899 .tuner_addr = ADDR_UNSET,
2900 .radio_addr = ADDR_UNSET,
2901 .mpeg = SAA7134_MPEG_DVB,
2902 .inputs = {{
2903 .name = name_tv,
2904 .vmux = 1,
2905 .amux = TV,
2906 .tv = 1,
2907 },{
2908 .name = name_comp1,
2909 .vmux = 0,
2910 .amux = LINE2,
2911 },{
2912 .name = name_svideo,
2913 .vmux = 8,
2914 .amux = LINE2,
2915 }},
2916 },
2917 [SAA7134_BOARD_FLYDVBS_LR300] = {
2918 /* LifeView FlyDVB-s */
2919 /* Igor M. Liplianin <liplianin@tut.by> */
2920 .name = "LifeView FlyDVB-S /Acorp TV134DS",
2921 .audio_clock = 0x00200000,
2922 .tuner_type = TUNER_ABSENT,
2923 .radio_type = UNSET,
2924 .tuner_addr = ADDR_UNSET,
2925 .radio_addr = ADDR_UNSET,
2926 .mpeg = SAA7134_MPEG_DVB,
2927 .inputs = {{
2928 .name = name_comp1, /* Composite input */
2929 .vmux = 3,
2930 .amux = LINE1,
2931 },{
2932 .name = name_svideo, /* S-Video signal on S-Video input */
2933 .vmux = 8,
2934 .amux = LINE1,
2935 }},
2936 },
2937 [SAA7134_BOARD_PROTEUS_2309] = {
2938 .name = "Proteus Pro 2309",
2939 .audio_clock = 0x00187de7,
2940 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
2941 .radio_type = UNSET,
2942 .tuner_addr = ADDR_UNSET,
2943 .radio_addr = ADDR_UNSET,
2944 .tda9887_conf = TDA9887_PRESENT,
2945 .inputs = {{
2946 .name = name_tv,
2947 .vmux = 1,
2948 .amux = LINE2,
2949 .tv = 1,
2950 },{
2951 .name = name_comp1,
2952 .vmux = 0,
2953 .amux = LINE2,
2954 },{
2955 .name = name_comp2,
2956 .vmux = 3,
2957 .amux = LINE2,
2958 },{
2959 .name = name_svideo,
2960 .vmux = 8,
2961 .amux = LINE2,
2962 }},
2963 .mute = {
2964 .name = name_mute,
2965 .amux = LINE1,
2966 },
2967 },
2894}; 2968};
2895 2969
2896const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards); 2970const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
@@ -3375,7 +3449,7 @@ struct pci_device_id saa7134_pci_tbl[] = {
3375 .driver_data = SAA7134_BOARD_FLYDVB_TRIO, 3449 .driver_data = SAA7134_BOARD_FLYDVB_TRIO,
3376 },{ 3450 },{
3377 .vendor = PCI_VENDOR_ID_PHILIPS, 3451 .vendor = PCI_VENDOR_ID_PHILIPS,
3378 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, /* SAA 7131E */ 3452 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
3379 .subvendor = 0x1461, 3453 .subvendor = 0x1461,
3380 .subdevice = 0x2c05, 3454 .subdevice = 0x2c05,
3381 .driver_data = SAA7134_BOARD_AVERMEDIA_777, 3455 .driver_data = SAA7134_BOARD_AVERMEDIA_777,
@@ -3422,6 +3496,18 @@ struct pci_device_id saa7134_pci_tbl[] = {
3422 .subdevice = 0x0005, 3496 .subdevice = 0x0005,
3423 .driver_data = SAA7134_BOARD_MD7134_BRIDGE_2, 3497 .driver_data = SAA7134_BOARD_MD7134_BRIDGE_2,
3424 },{ 3498 },{
3499 .vendor = PCI_VENDOR_ID_PHILIPS,
3500 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
3501 .subvendor = 0x5168,
3502 .subdevice = 0x0300,
3503 .driver_data = SAA7134_BOARD_FLYDVBS_LR300,
3504 },{
3505 .vendor = PCI_VENDOR_ID_PHILIPS,
3506 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
3507 .subvendor = 0x4e42,
3508 .subdevice = 0x0300,/* LR300 */
3509 .driver_data = SAA7134_BOARD_FLYDVBS_LR300,
3510 },{
3425 .vendor = PCI_VENDOR_ID_PHILIPS, 3511 .vendor = PCI_VENDOR_ID_PHILIPS,
3426 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 3512 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
3427 .subvendor = 0x1489, 3513 .subvendor = 0x1489,
@@ -3446,6 +3532,36 @@ struct pci_device_id saa7134_pci_tbl[] = {
3446 .subdevice = 0x3502, /* whats the difference to 0x3306 ?*/ 3532 .subdevice = 0x3502, /* whats the difference to 0x3306 ?*/
3447 .driver_data = SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS, 3533 .driver_data = SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS,
3448 },{ 3534 },{
3535 .vendor = PCI_VENDOR_ID_PHILIPS,
3536 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3537 .subvendor = 0x16be,
3538 .subdevice = 0x0007,
3539 .driver_data = SAA7134_BOARD_MEDION_MD8800_QUADRO,
3540 },{
3541 .vendor = PCI_VENDOR_ID_PHILIPS,
3542 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3543 .subvendor = 0x16be,
3544 .subdevice = 0x0008,
3545 .driver_data = SAA7134_BOARD_MEDION_MD8800_QUADRO,
3546 },{
3547 .vendor = PCI_VENDOR_ID_PHILIPS,
3548 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3549 .subvendor = 0x1461,
3550 .subdevice = 0x2c05,
3551 .driver_data = SAA7134_BOARD_AVERMEDIA_777,
3552 },{
3553 .vendor = PCI_VENDOR_ID_PHILIPS,
3554 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3555 .subvendor = 0x1489,
3556 .subdevice = 0x0502, /* Cardbus version */
3557 .driver_data = SAA7134_BOARD_FLYDVBT_DUO_CARDBUS,
3558 },{
3559 .vendor = PCI_VENDOR_ID_PHILIPS,
3560 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
3561 .subvendor = 0x0919, /* Philips Proteus PRO 2309 */
3562 .subdevice = 0x2003,
3563 .driver_data = SAA7134_BOARD_PROTEUS_2309,
3564 },{
3449 /* --- boards without eeprom + subsystem ID --- */ 3565 /* --- boards without eeprom + subsystem ID --- */
3450 .vendor = PCI_VENDOR_ID_PHILIPS, 3566 .vendor = PCI_VENDOR_ID_PHILIPS,
3451 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 3567 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -3548,6 +3664,12 @@ int saa7134_board_init1(struct saa7134_dev *dev)
3548 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS: 3664 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
3549 case SAA7134_BOARD_FLYDVBT_LR301: 3665 case SAA7134_BOARD_FLYDVBT_LR301:
3550 case SAA7134_BOARD_FLYDVBTDUO: 3666 case SAA7134_BOARD_FLYDVBTDUO:
3667 case SAA7134_BOARD_PROTEUS_2309:
3668 dev->has_remote = SAA7134_REMOTE_GPIO;
3669 break;
3670 case SAA7134_BOARD_FLYDVBS_LR300:
3671 saa_writeb(SAA7134_GPIO_GPMODE3, 0x80);
3672 saa_writeb(SAA7134_GPIO_GPSTATUS2, 0x40);
3551 dev->has_remote = SAA7134_REMOTE_GPIO; 3673 dev->has_remote = SAA7134_REMOTE_GPIO;
3552 break; 3674 break;
3553 case SAA7134_BOARD_MD5044: 3675 case SAA7134_BOARD_MD5044:
@@ -3732,6 +3854,7 @@ int saa7134_board_init2(struct saa7134_dev *dev)
3732 case SAA7134_BOARD_PHILIPS_TIGER: 3854 case SAA7134_BOARD_PHILIPS_TIGER:
3733 case SAA7134_BOARD_TEVION_DVBT_220RF: 3855 case SAA7134_BOARD_TEVION_DVBT_220RF:
3734 case SAA7134_BOARD_ASUSTeK_P7131_DUAL: 3856 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
3857 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
3735 /* this is a hybrid board, initialize to analog mode 3858 /* this is a hybrid board, initialize to analog mode
3736 * and configure firmware eeprom address 3859 * and configure firmware eeprom address
3737 */ 3860 */
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index be3a81fc90a2..09aa62f61af7 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -843,7 +843,7 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
843 latency = 0x0A; 843 latency = 0x0A;
844 } 844 }
845#endif 845#endif
846 if (pci_pci_problems & PCIPCI_FAIL) { 846 if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL)) {
847 printk(KERN_INFO "%s: quirk: this driver and your " 847 printk(KERN_INFO "%s: quirk: this driver and your "
848 "chipset may not work together" 848 "chipset may not work together"
849 " in overlay mode.\n",dev->name); 849 " in overlay mode.\n",dev->name);
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index 279828b8f299..b6881541e704 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -34,17 +34,14 @@
34#include <media/v4l2-common.h> 34#include <media/v4l2-common.h>
35#include "dvb-pll.h" 35#include "dvb-pll.h"
36 36
37#ifdef HAVE_MT352 37#include "mt352.h"
38# include "mt352.h" 38#include "mt352_priv.h" /* FIXME */
39# include "mt352_priv.h" /* FIXME */ 39#include "tda1004x.h"
40#endif 40#include "nxt200x.h"
41#ifdef HAVE_TDA1004X 41
42# include "tda1004x.h" 42#include "tda10086.h"
43#endif 43#include "tda826x.h"
44#ifdef HAVE_NXT200X 44#include "isl6421.h"
45# include "nxt200x.h"
46#endif
47
48MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); 45MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
49MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
50 47
@@ -54,8 +51,6 @@ module_param(antenna_pwr, int, 0444);
54MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)"); 51MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
55 52
56/* ------------------------------------------------------------------ */ 53/* ------------------------------------------------------------------ */
57
58#ifdef HAVE_MT352
59static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on) 54static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
60{ 55{
61 u32 ok; 56 u32 ok;
@@ -185,12 +180,8 @@ static struct mt352_config avermedia_777 = {
185 .demod_address = 0xf, 180 .demod_address = 0xf,
186 .demod_init = mt352_aver777_init, 181 .demod_init = mt352_aver777_init,
187}; 182};
188#endif
189 183
190/* ------------------------------------------------------------------ */ 184/* ------------------------------------------------------------------ */
191
192#ifdef HAVE_TDA1004X
193
194static int philips_tda6651_pll_set(u8 addr, struct dvb_frontend *fe, struct dvb_frontend_parameters *params) 185static int philips_tda6651_pll_set(u8 addr, struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
195{ 186{
196 struct saa7134_dev *dev = fe->dvb->priv; 187 struct saa7134_dev *dev = fe->dvb->priv;
@@ -969,11 +960,58 @@ static struct tda1004x_config tevion_dvbt220rf_config = {
969 .request_firmware = NULL, 960 .request_firmware = NULL,
970}; 961};
971 962
972#endif 963/* ------------------------------------------------------------------ */
964
965static int md8800_dvbt_analog_mode(struct dvb_frontend *fe)
966{
967 struct saa7134_dev *dev = fe->dvb->priv;
968 static u8 data[] = { 0x3c, 0x33, 0x68};
969 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
970
971 i2c_transfer(&dev->i2c_adap, &msg, 1);
972 philips_tda827xa_tuner_sleep( 0x61, fe);
973 return 0;
974}
975
976static int md8800_dvbt_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
977{
978 int ret;
979 struct saa7134_dev *dev = fe->dvb->priv;
980 static u8 tda8290_close[] = { 0x21, 0xc0};
981 static u8 tda8290_open[] = { 0x21, 0x80};
982 struct i2c_msg tda8290_msg = {.addr = 0x4b,.flags = 0, .len = 2};
983 /* close tda8290 i2c bridge */
984 tda8290_msg.buf = tda8290_close;
985 ret = i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1);
986 if (ret != 1)
987 return -EIO;
988 msleep(20);
989 ret = philips_tda827xa_pll_set(0x60, fe, params);
990 if (ret != 0)
991 return ret;
992 /* open tda8290 i2c bridge */
993 tda8290_msg.buf = tda8290_open;
994 i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1);
995 return ret;
996}
997
998static struct tda1004x_config md8800_dvbt_config = {
999 .demod_address = 0x08,
1000 .invert = 1,
1001 .invert_oclk = 0,
1002 .xtal_freq = TDA10046_XTAL_16M,
1003 .agc_config = TDA10046_AGC_TDA827X,
1004 .if_freq = TDA10046_FREQ_045,
1005 .request_firmware = NULL,
1006};
1007
1008static struct tda10086_config flydvbs = {
1009 .demod_address = 0x0e,
1010 .invert = 0,
1011};
973 1012
974/* ------------------------------------------------------------------ */ 1013/* ------------------------------------------------------------------ */
975 1014
976#ifdef HAVE_NXT200X
977static struct nxt200x_config avertvhda180 = { 1015static struct nxt200x_config avertvhda180 = {
978 .demod_address = 0x0a, 1016 .demod_address = 0x0a,
979}; 1017};
@@ -991,7 +1029,6 @@ static struct nxt200x_config kworldatsc110 = {
991 .demod_address = 0x0a, 1029 .demod_address = 0x0a,
992 .set_pll_input = nxt200x_set_pll_input, 1030 .set_pll_input = nxt200x_set_pll_input,
993}; 1031};
994#endif
995 1032
996/* ------------------------------------------------------------------ */ 1033/* ------------------------------------------------------------------ */
997 1034
@@ -1009,29 +1046,26 @@ static int dvb_init(struct saa7134_dev *dev)
1009 dev); 1046 dev);
1010 1047
1011 switch (dev->board) { 1048 switch (dev->board) {
1012#ifdef HAVE_MT352
1013 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL: 1049 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1014 printk("%s: pinnacle 300i dvb setup\n",dev->name); 1050 printk("%s: pinnacle 300i dvb setup\n",dev->name);
1015 dev->dvb.frontend = mt352_attach(&pinnacle_300i, 1051 dev->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
1016 &dev->i2c_adap); 1052 &dev->i2c_adap);
1017 if (dev->dvb.frontend) { 1053 if (dev->dvb.frontend) {
1018 dev->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params; 1054 dev->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
1019 } 1055 }
1020 break; 1056 break;
1021
1022 case SAA7134_BOARD_AVERMEDIA_777: 1057 case SAA7134_BOARD_AVERMEDIA_777:
1023 printk("%s: avertv 777 dvb setup\n",dev->name); 1058 printk("%s: avertv 777 dvb setup\n",dev->name);
1024 dev->dvb.frontend = mt352_attach(&avermedia_777, 1059 dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
1025 &dev->i2c_adap); 1060 &dev->i2c_adap);
1026 if (dev->dvb.frontend) { 1061 if (dev->dvb.frontend) {
1027 dev->dvb.frontend->ops.tuner_ops.calc_regs = mt352_aver777_tuner_calc_regs; 1062 dev->dvb.frontend->ops.tuner_ops.calc_regs = mt352_aver777_tuner_calc_regs;
1028 } 1063 }
1029 break; 1064 break;
1030#endif
1031#ifdef HAVE_TDA1004X
1032 case SAA7134_BOARD_MD7134: 1065 case SAA7134_BOARD_MD7134:
1033 dev->dvb.frontend = tda10046_attach(&medion_cardbus, 1066 dev->dvb.frontend = dvb_attach(tda10046_attach,
1034 &dev->i2c_adap); 1067 &medion_cardbus,
1068 &dev->i2c_adap);
1035 if (dev->dvb.frontend) { 1069 if (dev->dvb.frontend) {
1036 dev->dvb.frontend->ops.tuner_ops.init = philips_fmd1216_tuner_init; 1070 dev->dvb.frontend->ops.tuner_ops.init = philips_fmd1216_tuner_init;
1037 dev->dvb.frontend->ops.tuner_ops.sleep = philips_fmd1216_tuner_sleep; 1071 dev->dvb.frontend->ops.tuner_ops.sleep = philips_fmd1216_tuner_sleep;
@@ -1039,16 +1073,18 @@ static int dvb_init(struct saa7134_dev *dev)
1039 } 1073 }
1040 break; 1074 break;
1041 case SAA7134_BOARD_PHILIPS_TOUGH: 1075 case SAA7134_BOARD_PHILIPS_TOUGH:
1042 dev->dvb.frontend = tda10046_attach(&philips_tu1216_60_config, 1076 dev->dvb.frontend = dvb_attach(tda10046_attach,
1043 &dev->i2c_adap); 1077 &philips_tu1216_60_config,
1078 &dev->i2c_adap);
1044 if (dev->dvb.frontend) { 1079 if (dev->dvb.frontend) {
1045 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_tuner_60_init; 1080 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_tuner_60_init;
1046 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tu1216_tuner_60_set_params; 1081 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tu1216_tuner_60_set_params;
1047 } 1082 }
1048 break; 1083 break;
1049 case SAA7134_BOARD_FLYDVBTDUO: 1084 case SAA7134_BOARD_FLYDVBTDUO:
1050 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config, 1085 dev->dvb.frontend = dvb_attach(tda10046_attach,
1051 &dev->i2c_adap); 1086 &tda827x_lifeview_config,
1087 &dev->i2c_adap);
1052 if (dev->dvb.frontend) { 1088 if (dev->dvb.frontend) {
1053 dev->dvb.frontend->ops.tuner_ops.init = philips_tda827x_tuner_init; 1089 dev->dvb.frontend->ops.tuner_ops.init = philips_tda827x_tuner_init;
1054 dev->dvb.frontend->ops.tuner_ops.sleep = philips_tda827x_tuner_sleep; 1090 dev->dvb.frontend->ops.tuner_ops.sleep = philips_tda827x_tuner_sleep;
@@ -1056,8 +1092,9 @@ static int dvb_init(struct saa7134_dev *dev)
1056 } 1092 }
1057 break; 1093 break;
1058 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS: 1094 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
1059 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config, 1095 dev->dvb.frontend = dvb_attach(tda10046_attach,
1060 &dev->i2c_adap); 1096 &tda827x_lifeview_config,
1097 &dev->i2c_adap);
1061 if (dev->dvb.frontend) { 1098 if (dev->dvb.frontend) {
1062 dev->dvb.frontend->ops.tuner_ops.init = philips_tda827x_tuner_init; 1099 dev->dvb.frontend->ops.tuner_ops.init = philips_tda827x_tuner_init;
1063 dev->dvb.frontend->ops.tuner_ops.sleep = philips_tda827x_tuner_sleep; 1100 dev->dvb.frontend->ops.tuner_ops.sleep = philips_tda827x_tuner_sleep;
@@ -1065,8 +1102,9 @@ static int dvb_init(struct saa7134_dev *dev)
1065 } 1102 }
1066 break; 1103 break;
1067 case SAA7134_BOARD_PHILIPS_EUROPA: 1104 case SAA7134_BOARD_PHILIPS_EUROPA:
1068 dev->dvb.frontend = tda10046_attach(&philips_europa_config, 1105 dev->dvb.frontend = dvb_attach(tda10046_attach,
1069 &dev->i2c_adap); 1106 &philips_europa_config,
1107 &dev->i2c_adap);
1070 if (dev->dvb.frontend) { 1108 if (dev->dvb.frontend) {
1071 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep; 1109 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
1072 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep; 1110 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
@@ -1076,8 +1114,9 @@ static int dvb_init(struct saa7134_dev *dev)
1076 } 1114 }
1077 break; 1115 break;
1078 case SAA7134_BOARD_VIDEOMATE_DVBT_300: 1116 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
1079 dev->dvb.frontend = tda10046_attach(&philips_europa_config, 1117 dev->dvb.frontend = dvb_attach(tda10046_attach,
1080 &dev->i2c_adap); 1118 &philips_europa_config,
1119 &dev->i2c_adap);
1081 if (dev->dvb.frontend) { 1120 if (dev->dvb.frontend) {
1082 dev->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init; 1121 dev->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
1083 dev->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep; 1122 dev->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
@@ -1085,16 +1124,18 @@ static int dvb_init(struct saa7134_dev *dev)
1085 } 1124 }
1086 break; 1125 break;
1087 case SAA7134_BOARD_VIDEOMATE_DVBT_200: 1126 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
1088 dev->dvb.frontend = tda10046_attach(&philips_tu1216_61_config, 1127 dev->dvb.frontend = dvb_attach(tda10046_attach,
1089 &dev->i2c_adap); 1128 &philips_tu1216_61_config,
1129 &dev->i2c_adap);
1090 if (dev->dvb.frontend) { 1130 if (dev->dvb.frontend) {
1091 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_tuner_61_init; 1131 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_tuner_61_init;
1092 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tu1216_tuner_61_set_params; 1132 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tu1216_tuner_61_set_params;
1093 } 1133 }
1094 break; 1134 break;
1095 case SAA7134_BOARD_PHILIPS_TIGER: 1135 case SAA7134_BOARD_PHILIPS_TIGER:
1096 dev->dvb.frontend = tda10046_attach(&philips_tiger_config, 1136 dev->dvb.frontend = dvb_attach(tda10046_attach,
1097 &dev->i2c_adap); 1137 &philips_tiger_config,
1138 &dev->i2c_adap);
1098 if (dev->dvb.frontend) { 1139 if (dev->dvb.frontend) {
1099 dev->dvb.frontend->ops.tuner_ops.init = philips_tiger_tuner_init; 1140 dev->dvb.frontend->ops.tuner_ops.init = philips_tiger_tuner_init;
1100 dev->dvb.frontend->ops.tuner_ops.sleep = philips_tiger_tuner_sleep; 1141 dev->dvb.frontend->ops.tuner_ops.sleep = philips_tiger_tuner_sleep;
@@ -1102,8 +1143,9 @@ static int dvb_init(struct saa7134_dev *dev)
1102 } 1143 }
1103 break; 1144 break;
1104 case SAA7134_BOARD_ASUSTeK_P7131_DUAL: 1145 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
1105 dev->dvb.frontend = tda10046_attach(&philips_tiger_config, 1146 dev->dvb.frontend = dvb_attach(tda10046_attach,
1106 &dev->i2c_adap); 1147 &philips_tiger_config,
1148 &dev->i2c_adap);
1107 if (dev->dvb.frontend) { 1149 if (dev->dvb.frontend) {
1108 dev->dvb.frontend->ops.tuner_ops.init = philips_tiger_tuner_init; 1150 dev->dvb.frontend->ops.tuner_ops.init = philips_tiger_tuner_init;
1109 dev->dvb.frontend->ops.tuner_ops.sleep = philips_tiger_tuner_sleep; 1151 dev->dvb.frontend->ops.tuner_ops.sleep = philips_tiger_tuner_sleep;
@@ -1111,8 +1153,9 @@ static int dvb_init(struct saa7134_dev *dev)
1111 } 1153 }
1112 break; 1154 break;
1113 case SAA7134_BOARD_FLYDVBT_LR301: 1155 case SAA7134_BOARD_FLYDVBT_LR301:
1114 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config, 1156 dev->dvb.frontend = dvb_attach(tda10046_attach,
1115 &dev->i2c_adap); 1157 &tda827x_lifeview_config,
1158 &dev->i2c_adap);
1116 if (dev->dvb.frontend) { 1159 if (dev->dvb.frontend) {
1117 dev->dvb.frontend->ops.tuner_ops.init = philips_tda827x_tuner_init; 1160 dev->dvb.frontend->ops.tuner_ops.init = philips_tda827x_tuner_init;
1118 dev->dvb.frontend->ops.tuner_ops.sleep = philips_tda827x_tuner_sleep; 1161 dev->dvb.frontend->ops.tuner_ops.sleep = philips_tda827x_tuner_sleep;
@@ -1120,16 +1163,18 @@ static int dvb_init(struct saa7134_dev *dev)
1120 } 1163 }
1121 break; 1164 break;
1122 case SAA7134_BOARD_FLYDVB_TRIO: 1165 case SAA7134_BOARD_FLYDVB_TRIO:
1123 dev->dvb.frontend = tda10046_attach(&lifeview_trio_config, 1166 dev->dvb.frontend = dvb_attach(tda10046_attach,
1124 &dev->i2c_adap); 1167 &lifeview_trio_config,
1168 &dev->i2c_adap);
1125 if (dev->dvb.frontend) { 1169 if (dev->dvb.frontend) {
1126 dev->dvb.frontend->ops.tuner_ops.sleep = lifeview_trio_tuner_sleep; 1170 dev->dvb.frontend->ops.tuner_ops.sleep = lifeview_trio_tuner_sleep;
1127 dev->dvb.frontend->ops.tuner_ops.set_params = lifeview_trio_tuner_set_params; 1171 dev->dvb.frontend->ops.tuner_ops.set_params = lifeview_trio_tuner_set_params;
1128 } 1172 }
1129 break; 1173 break;
1130 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331: 1174 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
1131 dev->dvb.frontend = tda10046_attach(&ads_tech_duo_config, 1175 dev->dvb.frontend = dvb_attach(tda10046_attach,
1132 &dev->i2c_adap); 1176 &ads_tech_duo_config,
1177 &dev->i2c_adap);
1133 if (dev->dvb.frontend) { 1178 if (dev->dvb.frontend) {
1134 dev->dvb.frontend->ops.tuner_ops.init = ads_duo_tuner_init; 1179 dev->dvb.frontend->ops.tuner_ops.init = ads_duo_tuner_init;
1135 dev->dvb.frontend->ops.tuner_ops.sleep = ads_duo_tuner_sleep; 1180 dev->dvb.frontend->ops.tuner_ops.sleep = ads_duo_tuner_sleep;
@@ -1137,37 +1182,63 @@ static int dvb_init(struct saa7134_dev *dev)
1137 } 1182 }
1138 break; 1183 break;
1139 case SAA7134_BOARD_TEVION_DVBT_220RF: 1184 case SAA7134_BOARD_TEVION_DVBT_220RF:
1140 dev->dvb.frontend = tda10046_attach(&tevion_dvbt220rf_config, 1185 dev->dvb.frontend = dvb_attach(tda10046_attach,
1141 &dev->i2c_adap); 1186 &tevion_dvbt220rf_config,
1187 &dev->i2c_adap);
1142 if (dev->dvb.frontend) { 1188 if (dev->dvb.frontend) {
1143 dev->dvb.frontend->ops.tuner_ops.sleep = tevion_dvb220rf_tuner_sleep; 1189 dev->dvb.frontend->ops.tuner_ops.sleep = tevion_dvb220rf_tuner_sleep;
1144 dev->dvb.frontend->ops.tuner_ops.set_params = tevion_dvb220rf_tuner_set_params; 1190 dev->dvb.frontend->ops.tuner_ops.set_params = tevion_dvb220rf_tuner_set_params;
1145 } 1191 }
1146 break; 1192 break;
1147 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS: 1193 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1148 dev->dvb.frontend = tda10046_attach(&ads_tech_duo_config, 1194 dev->dvb.frontend = dvb_attach(tda10046_attach,
1149 &dev->i2c_adap); 1195 &ads_tech_duo_config,
1196 &dev->i2c_adap);
1150 if (dev->dvb.frontend) { 1197 if (dev->dvb.frontend) {
1151 dev->dvb.frontend->ops.tuner_ops.init = ads_duo_tuner_init; 1198 dev->dvb.frontend->ops.tuner_ops.init = ads_duo_tuner_init;
1152 dev->dvb.frontend->ops.tuner_ops.sleep = ads_duo_tuner_sleep; 1199 dev->dvb.frontend->ops.tuner_ops.sleep = ads_duo_tuner_sleep;
1153 dev->dvb.frontend->ops.tuner_ops.set_params = ads_duo_tuner_set_params; 1200 dev->dvb.frontend->ops.tuner_ops.set_params = ads_duo_tuner_set_params;
1154 } 1201 }
1155 break; 1202 break;
1156#endif 1203 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
1157#ifdef HAVE_NXT200X 1204 dev->dvb.frontend = tda10046_attach(&md8800_dvbt_config,
1205 &dev->i2c_adap);
1206 if (dev->dvb.frontend) {
1207 dev->dvb.frontend->ops.tuner_ops.init = philips_tiger_tuner_init;
1208 dev->dvb.frontend->ops.tuner_ops.sleep = md8800_dvbt_analog_mode;
1209 dev->dvb.frontend->ops.tuner_ops.set_params = md8800_dvbt_pll_set;
1210 }
1211 break;
1158 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180: 1212 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
1159 dev->dvb.frontend = nxt200x_attach(&avertvhda180, &dev->i2c_adap); 1213 dev->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
1214 &dev->i2c_adap);
1160 if (dev->dvb.frontend) { 1215 if (dev->dvb.frontend) {
1161 dvb_pll_attach(dev->dvb.frontend, 0x61, &dev->i2c_adap, &dvb_pll_tdhu2); 1216 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1217 NULL, &dvb_pll_tdhu2);
1162 } 1218 }
1163 break; 1219 break;
1164 case SAA7134_BOARD_KWORLD_ATSC110: 1220 case SAA7134_BOARD_KWORLD_ATSC110:
1165 dev->dvb.frontend = nxt200x_attach(&kworldatsc110, &dev->i2c_adap); 1221 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1222 &dev->i2c_adap);
1223 if (dev->dvb.frontend) {
1224 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1225 NULL, &dvb_pll_tuv1236d);
1226 }
1227 break;
1228 case SAA7134_BOARD_FLYDVBS_LR300:
1229 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1230 &dev->i2c_adap);
1166 if (dev->dvb.frontend) { 1231 if (dev->dvb.frontend) {
1167 dvb_pll_attach(dev->dvb.frontend, 0x61, &dev->i2c_adap, &dvb_pll_tuv1236d); 1232 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1233 &dev->i2c_adap, 0) == NULL) {
1234 printk("%s: No tda826x found!\n", __FUNCTION__);
1235 }
1236 if (dvb_attach(isl6421_attach, dev->dvb.frontend,
1237 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1238 printk("%s: No ISL6421 found!\n", __FUNCTION__);
1239 }
1168 } 1240 }
1169 break; 1241 break;
1170#endif
1171 default: 1242 default:
1172 printk("%s: Huh? unknown DVB card?\n",dev->name); 1243 printk("%s: Huh? unknown DVB card?\n",dev->name);
1173 break; 1244 break;
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index 7c595492c56b..f7ea857d5d73 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -228,6 +228,12 @@ int saa7134_input_init1(struct saa7134_dev *dev)
228 mask_keyup = 0x400000; 228 mask_keyup = 0x400000;
229 polling = 50; // ms 229 polling = 50; // ms
230 break; 230 break;
231 case SAA7134_BOARD_PROTEUS_2309:
232 ir_codes = ir_codes_proteus_2309;
233 mask_keycode = 0x00007F;
234 mask_keyup = 0x000080;
235 polling = 50; // ms
236 break;
231 case SAA7134_BOARD_VIDEOMATE_DVBT_300: 237 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
232 case SAA7134_BOARD_VIDEOMATE_DVBT_200: 238 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
233 ir_codes = ir_codes_videomate_tv_pvr; 239 ir_codes = ir_codes_videomate_tv_pvr;
diff --git a/drivers/media/video/saa7134/saa7134-tvaudio.c b/drivers/media/video/saa7134/saa7134-tvaudio.c
index 0db53d192b2a..d31220d20495 100644
--- a/drivers/media/video/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/video/saa7134/saa7134-tvaudio.c
@@ -1046,6 +1046,7 @@ int saa7134_tvaudio_do_scan(struct saa7134_dev *dev)
1046} 1046}
1047 1047
1048EXPORT_SYMBOL(saa_dsp_writel); 1048EXPORT_SYMBOL(saa_dsp_writel);
1049EXPORT_SYMBOL(saa7134_tvaudio_setmute);
1049 1050
1050/* ----------------------------------------------------------- */ 1051/* ----------------------------------------------------------- */
1051/* 1052/*
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index c04ce6152fd5..7db7b9705953 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -223,6 +223,9 @@ struct saa7134_format {
223#define SAA7134_BOARD_MD7134_BRIDGE_2 93 223#define SAA7134_BOARD_MD7134_BRIDGE_2 93
224#define SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS 94 224#define SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS 94
225#define SAA7134_BOARD_FLYVIDEO3000_NTSC 95 225#define SAA7134_BOARD_FLYVIDEO3000_NTSC 95
226#define SAA7134_BOARD_MEDION_MD8800_QUADRO 96
227#define SAA7134_BOARD_FLYDVBS_LR300 97
228#define SAA7134_BOARD_PROTEUS_2309 98
226 229
227#define SAA7134_MAXBOARDS 8 230#define SAA7134_MAXBOARDS 8
228#define SAA7134_INPUT_MAX 8 231#define SAA7134_INPUT_MAX 8
diff --git a/drivers/media/video/tda9887.c b/drivers/media/video/tda9887.c
index 8dab481d384a..87ffb0e84a7a 100644
--- a/drivers/media/video/tda9887.c
+++ b/drivers/media/video/tda9887.c
@@ -480,6 +480,8 @@ static int tda9887_set_config(struct tuner *t, char *buf)
480 } 480 }
481 if ((t->tda9887_config & TDA9887_INTERCARRIER_NTSC) && (t->std & V4L2_STD_NTSC)) 481 if ((t->tda9887_config & TDA9887_INTERCARRIER_NTSC) && (t->std & V4L2_STD_NTSC))
482 buf[1] &= ~cQSS; 482 buf[1] &= ~cQSS;
483 if (t->tda9887_config & TDA9887_GATING_18)
484 buf[3] &= ~cGating_36;
483 return 0; 485 return 0;
484} 486}
485 487
diff --git a/drivers/media/video/tuner-simple.c b/drivers/media/video/tuner-simple.c
index abe37cf632c6..63db4e97ae6c 100644
--- a/drivers/media/video/tuner-simple.c
+++ b/drivers/media/video/tuner-simple.c
@@ -10,7 +10,7 @@
10#include <media/v4l2-common.h> 10#include <media/v4l2-common.h>
11 11
12static int offset = 0; 12static int offset = 0;
13module_param(offset, int, 0666); 13module_param(offset, int, 0664);
14MODULE_PARM_DESC(offset,"Allows to specify an offset for tuner"); 14MODULE_PARM_DESC(offset,"Allows to specify an offset for tuner");
15 15
16/* ---------------------------------------------------------------------- */ 16/* ---------------------------------------------------------------------- */
@@ -331,6 +331,8 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
331 else if (params->default_top_high) 331 else if (params->default_top_high)
332 config |= TDA9887_TOP(params->default_top_high); 332 config |= TDA9887_TOP(params->default_top_high);
333 } 333 }
334 if (params->default_pll_gating_18)
335 config |= TDA9887_GATING_18;
334 i2c_clients_command(c->adapter, TDA9887_SET_CONFIG, &config); 336 i2c_clients_command(c->adapter, TDA9887_SET_CONFIG, &config);
335 } 337 }
336 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n", 338 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
@@ -439,8 +441,6 @@ static void default_set_radio_freq(struct i2c_client *c, unsigned int freq)
439 buffer[3] = 0xa4; 441 buffer[3] = 0xa4;
440 break; 442 break;
441 } 443 }
442 buffer[0] = (div>>8) & 0x7f;
443 buffer[1] = div & 0xff;
444 if (params->cb_first_if_lower_freq && div < t->last_div) { 444 if (params->cb_first_if_lower_freq && div < t->last_div) {
445 buffer[0] = buffer[2]; 445 buffer[0] = buffer[2];
446 buffer[1] = buffer[3]; 446 buffer[1] = buffer[3];
diff --git a/drivers/media/video/tuner-types.c b/drivers/media/video/tuner-types.c
index 8b542599ed47..8fff642fad56 100644
--- a/drivers/media/video/tuner-types.c
+++ b/drivers/media/video/tuner-types.c
@@ -650,6 +650,7 @@ static struct tuner_params tuner_microtune_4049_fm5_params[] = {
650 .count = ARRAY_SIZE(tuner_temic_4009f_5_pal_ranges), 650 .count = ARRAY_SIZE(tuner_temic_4009f_5_pal_ranges),
651 .has_tda9887 = 1, 651 .has_tda9887 = 1,
652 .port1_invert_for_secam_lc = 1, 652 .port1_invert_for_secam_lc = 1,
653 .default_pll_gating_18 = 1,
653 }, 654 },
654}; 655};
655 656
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index 936e3f746fba..fcaef4bf8289 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -28,6 +28,7 @@
28#include <linux/i2c-algo-bit.h> 28#include <linux/i2c-algo-bit.h>
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/smp_lock.h> 30#include <linux/smp_lock.h>
31#include <linux/kthread.h>
31 32
32#include <media/tvaudio.h> 33#include <media/tvaudio.h>
33#include <media/v4l2-common.h> 34#include <media/v4l2-common.h>
@@ -124,11 +125,8 @@ struct CHIPSTATE {
124 int input; 125 int input;
125 126
126 /* thread */ 127 /* thread */
127 pid_t tpid; 128 struct task_struct *thread;
128 struct completion texit;
129 wait_queue_head_t wq;
130 struct timer_list wt; 129 struct timer_list wt;
131 int done;
132 int watch_stereo; 130 int watch_stereo;
133 int audmode; 131 int audmode;
134}; 132};
@@ -264,28 +262,23 @@ static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd)
264static void chip_thread_wake(unsigned long data) 262static void chip_thread_wake(unsigned long data)
265{ 263{
266 struct CHIPSTATE *chip = (struct CHIPSTATE*)data; 264 struct CHIPSTATE *chip = (struct CHIPSTATE*)data;
267 wake_up_interruptible(&chip->wq); 265 wake_up_process(chip->thread);
268} 266}
269 267
270static int chip_thread(void *data) 268static int chip_thread(void *data)
271{ 269{
272 DECLARE_WAITQUEUE(wait, current);
273 struct CHIPSTATE *chip = data; 270 struct CHIPSTATE *chip = data;
274 struct CHIPDESC *desc = chiplist + chip->type; 271 struct CHIPDESC *desc = chiplist + chip->type;
275 272
276 daemonize("%s", chip->c.name);
277 allow_signal(SIGTERM);
278 v4l_dbg(1, debug, &chip->c, "%s: thread started\n", chip->c.name); 273 v4l_dbg(1, debug, &chip->c, "%s: thread started\n", chip->c.name);
279 274
280 for (;;) { 275 for (;;) {
281 add_wait_queue(&chip->wq, &wait); 276 set_current_state(TASK_INTERRUPTIBLE);
282 if (!chip->done) { 277 if (!kthread_should_stop())
283 set_current_state(TASK_INTERRUPTIBLE);
284 schedule(); 278 schedule();
285 } 279 set_current_state(TASK_RUNNING);
286 remove_wait_queue(&chip->wq, &wait);
287 try_to_freeze(); 280 try_to_freeze();
288 if (chip->done || signal_pending(current)) 281 if (kthread_should_stop())
289 break; 282 break;
290 v4l_dbg(1, debug, &chip->c, "%s: thread wakeup\n", chip->c.name); 283 v4l_dbg(1, debug, &chip->c, "%s: thread wakeup\n", chip->c.name);
291 284
@@ -301,7 +294,6 @@ static int chip_thread(void *data)
301 } 294 }
302 295
303 v4l_dbg(1, debug, &chip->c, "%s: thread exiting\n", chip->c.name); 296 v4l_dbg(1, debug, &chip->c, "%s: thread exiting\n", chip->c.name);
304 complete_and_exit(&chip->texit, 0);
305 return 0; 297 return 0;
306} 298}
307 299
@@ -1536,19 +1528,18 @@ static int chip_attach(struct i2c_adapter *adap, int addr, int kind)
1536 chip_write(chip,desc->treblereg,desc->treblefunc(chip->treble)); 1528 chip_write(chip,desc->treblereg,desc->treblefunc(chip->treble));
1537 } 1529 }
1538 1530
1539 chip->tpid = -1; 1531 chip->thread = NULL;
1540 if (desc->checkmode) { 1532 if (desc->checkmode) {
1541 /* start async thread */ 1533 /* start async thread */
1542 init_timer(&chip->wt); 1534 init_timer(&chip->wt);
1543 chip->wt.function = chip_thread_wake; 1535 chip->wt.function = chip_thread_wake;
1544 chip->wt.data = (unsigned long)chip; 1536 chip->wt.data = (unsigned long)chip;
1545 init_waitqueue_head(&chip->wq); 1537 chip->thread = kthread_run(chip_thread, chip, chip->c.name);
1546 init_completion(&chip->texit); 1538 if (IS_ERR(chip->thread)) {
1547 chip->tpid = kernel_thread(chip_thread,(void *)chip,0); 1539 v4l_warn(&chip->c, "%s: failed to create kthread\n",
1548 if (chip->tpid < 0)
1549 v4l_warn(&chip->c, "%s: kernel_thread() failed\n",
1550 chip->c.name); 1540 chip->c.name);
1551 wake_up_interruptible(&chip->wq); 1541 chip->thread = NULL;
1542 }
1552 } 1543 }
1553 return 0; 1544 return 0;
1554} 1545}
@@ -1569,11 +1560,10 @@ static int chip_detach(struct i2c_client *client)
1569 struct CHIPSTATE *chip = i2c_get_clientdata(client); 1560 struct CHIPSTATE *chip = i2c_get_clientdata(client);
1570 1561
1571 del_timer_sync(&chip->wt); 1562 del_timer_sync(&chip->wt);
1572 if (chip->tpid >= 0) { 1563 if (chip->thread) {
1573 /* shutdown async thread */ 1564 /* shutdown async thread */
1574 chip->done = 1; 1565 kthread_stop(chip->thread);
1575 wake_up_interruptible(&chip->wq); 1566 chip->thread = NULL;
1576 wait_for_completion(&chip->texit);
1577 } 1567 }
1578 1568
1579 i2c_detach_client(&chip->c); 1569 i2c_detach_client(&chip->c);
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index d95529e8e513..cd1502ac9560 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -605,6 +605,8 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
605 tvee->tuner_formats |= hauppauge_tuner_fmt[i].id; 605 tvee->tuner_formats |= hauppauge_tuner_fmt[i].id;
606 t_fmt_name1[j++] = hauppauge_tuner_fmt[i].name; 606 t_fmt_name1[j++] = hauppauge_tuner_fmt[i].name;
607 } 607 }
608 }
609 for (i = j = 0; i < 8; i++) {
608 if (t_format2 & (1 << i)) { 610 if (t_format2 & (1 << i)) {
609 tvee->tuner2_formats |= hauppauge_tuner_fmt[i].id; 611 tvee->tuner2_formats |= hauppauge_tuner_fmt[i].id;
610 t_fmt_name2[j++] = hauppauge_tuner_fmt[i].name; 612 t_fmt_name2[j++] = hauppauge_tuner_fmt[i].name;
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c
index b167ffab2520..bc0a4fc27b24 100644
--- a/drivers/media/video/tvp5150.c
+++ b/drivers/media/video/tvp5150.c
@@ -294,7 +294,7 @@ static inline void tvp5150_selmux(struct i2c_client *c)
294 if ((decoder->route.output & TVP5150_BLACK_SCREEN) || !decoder->enable) 294 if ((decoder->route.output & TVP5150_BLACK_SCREEN) || !decoder->enable)
295 input = 8; 295 input = 8;
296 296
297 switch (input) { 297 switch (decoder->route.input) {
298 case TVP5150_COMPOSITE1: 298 case TVP5150_COMPOSITE1:
299 input |= 2; 299 input |= 2;
300 /* fall through */ 300 /* fall through */
@@ -308,6 +308,11 @@ static inline void tvp5150_selmux(struct i2c_client *c)
308 break; 308 break;
309 } 309 }
310 310
311 tvp5150_dbg( 1, "Selecting video route: route input=%i, output=%i "
312 "=> tvp5150 input=%i, opmode=%i\n",
313 decoder->route.input,decoder->route.output,
314 input, opmode );
315
311 tvp5150_write(c, TVP5150_OP_MODE_CTL, opmode); 316 tvp5150_write(c, TVP5150_OP_MODE_CTL, opmode);
312 tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, input); 317 tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, input);
313}; 318};
diff --git a/drivers/media/video/usbvideo/konicawc.c b/drivers/media/video/usbvideo/konicawc.c
index 6f31ecc88843..4eee8be88314 100644
--- a/drivers/media/video/usbvideo/konicawc.c
+++ b/drivers/media/video/usbvideo/konicawc.c
@@ -222,6 +222,7 @@ static void konicawc_adjust_picture(struct uvd *uvd)
222static void konicawc_register_input(struct konicawc *cam, struct usb_device *dev) 222static void konicawc_register_input(struct konicawc *cam, struct usb_device *dev)
223{ 223{
224 struct input_dev *input_dev; 224 struct input_dev *input_dev;
225 int error;
225 226
226 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname)); 227 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
227 strncat(cam->input_physname, "/input0", sizeof(cam->input_physname)); 228 strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
@@ -242,7 +243,13 @@ static void konicawc_register_input(struct konicawc *cam, struct usb_device *dev
242 243
243 input_dev->private = cam; 244 input_dev->private = cam;
244 245
245 input_register_device(cam->input); 246 error = input_register_device(cam->input);
247 if (error) {
248 warn("Failed to register camera's input device, err: %d\n",
249 error);
250 input_free_device(cam->input);
251 cam->input = NULL;
252 }
246} 253}
247 254
248static void konicawc_unregister_input(struct konicawc *cam) 255static void konicawc_unregister_input(struct konicawc *cam)
diff --git a/drivers/media/video/usbvideo/vicam.c b/drivers/media/video/usbvideo/vicam.c
index 90d48e8510ba..08f9559a6bfa 100644
--- a/drivers/media/video/usbvideo/vicam.c
+++ b/drivers/media/video/usbvideo/vicam.c
@@ -7,6 +7,7 @@
7 * Monroe Williams (monroe@pobox.com) 7 * Monroe Williams (monroe@pobox.com)
8 * 8 *
9 * Supports 3COM HomeConnect PC Digital WebCam 9 * Supports 3COM HomeConnect PC Digital WebCam
10 * Supports Compro PS39U WebCam
10 * 11 *
11 * 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
12 * 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
@@ -60,6 +61,8 @@
60/* Define these values to match your device */ 61/* Define these values to match your device */
61#define USB_VICAM_VENDOR_ID 0x04c1 62#define USB_VICAM_VENDOR_ID 0x04c1
62#define USB_VICAM_PRODUCT_ID 0x009d 63#define USB_VICAM_PRODUCT_ID 0x009d
64#define USB_COMPRO_VENDOR_ID 0x0602
65#define USB_COMPRO_PRODUCT_ID 0x1001
63 66
64#define VICAM_BYTES_PER_PIXEL 3 67#define VICAM_BYTES_PER_PIXEL 3
65#define VICAM_MAX_READ_SIZE (512*242+128) 68#define VICAM_MAX_READ_SIZE (512*242+128)
@@ -1254,6 +1257,7 @@ static struct video_device vicam_template = {
1254/* table of devices that work with this driver */ 1257/* table of devices that work with this driver */
1255static struct usb_device_id vicam_table[] = { 1258static struct usb_device_id vicam_table[] = {
1256 {USB_DEVICE(USB_VICAM_VENDOR_ID, USB_VICAM_PRODUCT_ID)}, 1259 {USB_DEVICE(USB_VICAM_VENDOR_ID, USB_VICAM_PRODUCT_ID)},
1260 {USB_DEVICE(USB_COMPRO_VENDOR_ID, USB_COMPRO_PRODUCT_ID)},
1257 {} /* Terminating entry */ 1261 {} /* Terminating entry */
1258}; 1262};
1259 1263
diff --git a/drivers/media/video/v4l1-compat.c b/drivers/media/video/v4l1-compat.c
index d7c3fcbc80f7..1d899e2db394 100644
--- a/drivers/media/video/v4l1-compat.c
+++ b/drivers/media/video/v4l1-compat.c
@@ -349,6 +349,8 @@ v4l_compat_translate_ioctl(struct inode *inode,
349 { 349 {
350 struct video_buffer *buffer = arg; 350 struct video_buffer *buffer = arg;
351 351
352 memset(buffer, 0, sizeof(*buffer));
353
352 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2); 354 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
353 if (err < 0) { 355 if (err < 0) {
354 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %d\n",err); 356 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %d\n",err);
@@ -361,7 +363,7 @@ v4l_compat_translate_ioctl(struct inode *inode,
361 switch (fbuf2.fmt.pixelformat) { 363 switch (fbuf2.fmt.pixelformat) {
362 case V4L2_PIX_FMT_RGB332: 364 case V4L2_PIX_FMT_RGB332:
363 buffer->depth = 8; 365 buffer->depth = 8;
364 break; 366 break;
365 case V4L2_PIX_FMT_RGB555: 367 case V4L2_PIX_FMT_RGB555:
366 buffer->depth = 15; 368 buffer->depth = 15;
367 break; 369 break;
@@ -377,9 +379,13 @@ v4l_compat_translate_ioctl(struct inode *inode,
377 default: 379 default:
378 buffer->depth = 0; 380 buffer->depth = 0;
379 } 381 }
380 if (0 != fbuf2.fmt.bytesperline) 382 if (fbuf2.fmt.bytesperline) {
381 buffer->bytesperline = fbuf2.fmt.bytesperline; 383 buffer->bytesperline = fbuf2.fmt.bytesperline;
382 else { 384 if (!buffer->depth && buffer->width)
385 buffer->depth = ((fbuf2.fmt.bytesperline<<3)
386 + (buffer->width-1) )
387 /buffer->width;
388 } else {
383 buffer->bytesperline = 389 buffer->bytesperline =
384 (buffer->width * buffer->depth + 7) & 7; 390 (buffer->width * buffer->depth + 7) & 7;
385 buffer->bytesperline >>= 3; 391 buffer->bytesperline >>= 3;
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index 8d972ffdaf98..78d28b03ec93 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -938,6 +938,7 @@ void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
938 case VIDIOC_INT_AUDIO_CLOCK_FREQ: 938 case VIDIOC_INT_AUDIO_CLOCK_FREQ:
939 case VIDIOC_INT_I2S_CLOCK_FREQ: 939 case VIDIOC_INT_I2S_CLOCK_FREQ:
940 case VIDIOC_INT_S_STANDBY: 940 case VIDIOC_INT_S_STANDBY:
941 case VIDIOC_INT_RESET:
941 { 942 {
942 u32 *p=arg; 943 u32 *p=arg;
943 944
diff --git a/drivers/media/video/video-buf-dvb.c b/drivers/media/video/video-buf-dvb.c
index 7ee8a53cd336..f53edf1923b7 100644
--- a/drivers/media/video/video-buf-dvb.c
+++ b/drivers/media/video/video-buf-dvb.c
@@ -223,6 +223,7 @@ fail_dmxdev:
223fail_dmx: 223fail_dmx:
224 dvb_unregister_frontend(dvb->frontend); 224 dvb_unregister_frontend(dvb->frontend);
225fail_frontend: 225fail_frontend:
226 dvb_frontend_detach(dvb->frontend);
226 dvb_unregister_adapter(&dvb->adapter); 227 dvb_unregister_adapter(&dvb->adapter);
227fail_adapter: 228fail_adapter:
228 return result; 229 return result;
@@ -236,6 +237,7 @@ void videobuf_dvb_unregister(struct videobuf_dvb *dvb)
236 dvb_dmxdev_release(&dvb->dmxdev); 237 dvb_dmxdev_release(&dvb->dmxdev);
237 dvb_dmx_release(&dvb->demux); 238 dvb_dmx_release(&dvb->demux);
238 dvb_unregister_frontend(dvb->frontend); 239 dvb_unregister_frontend(dvb->frontend);
240 dvb_frontend_detach(dvb->frontend);
239 dvb_unregister_adapter(&dvb->adapter); 241 dvb_unregister_adapter(&dvb->adapter);
240} 242}
241 243
diff --git a/drivers/media/video/videodev.c b/drivers/media/video/videodev.c
index edd7b83c3464..479a0675cf60 100644
--- a/drivers/media/video/videodev.c
+++ b/drivers/media/video/videodev.c
@@ -739,13 +739,13 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
739 case VIDIOC_DQBUF: 739 case VIDIOC_DQBUF:
740 { 740 {
741 struct v4l2_buffer *p=arg; 741 struct v4l2_buffer *p=arg;
742 if (!vfd->vidioc_qbuf) 742 if (!vfd->vidioc_dqbuf)
743 break; 743 break;
744 ret = check_fmt (vfd, p->type); 744 ret = check_fmt (vfd, p->type);
745 if (ret) 745 if (ret)
746 break; 746 break;
747 747
748 ret=vfd->vidioc_qbuf(file, fh, p); 748 ret=vfd->vidioc_dqbuf(file, fh, p);
749 if (!ret) 749 if (!ret)
750 dbgbuf(cmd,vfd,p); 750 dbgbuf(cmd,vfd,p);
751 break; 751 break;
@@ -836,7 +836,7 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
836 break; 836 break;
837 } 837 }
838 838
839 if (index < 0 || index >= vfd->tvnormsize) { 839 if (index<0 || index >= vfd->tvnormsize) {
840 ret=-EINVAL; 840 ret=-EINVAL;
841 break; 841 break;
842 } 842 }
@@ -1283,9 +1283,29 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
1283 case VIDIOC_G_PARM: 1283 case VIDIOC_G_PARM:
1284 { 1284 {
1285 struct v4l2_streamparm *p=arg; 1285 struct v4l2_streamparm *p=arg;
1286 if (!vfd->vidioc_g_parm) 1286 if (vfd->vidioc_g_parm) {
1287 break; 1287 ret=vfd->vidioc_g_parm(file, fh, p);
1288 ret=vfd->vidioc_g_parm(file, fh, p); 1288 } else {
1289 struct v4l2_standard s;
1290
1291 if (!vfd->tvnormsize) {
1292 printk (KERN_WARNING "%s: no TV norms defined!\n",
1293 vfd->name);
1294 break;
1295 }
1296
1297 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1298 return -EINVAL;
1299
1300 v4l2_video_std_construct(&s, vfd->tvnorms[vfd->current_norm].id,
1301 vfd->tvnorms[vfd->current_norm].name);
1302
1303 memset(p,0,sizeof(*p));
1304
1305 p->parm.capture.timeperframe = s.frameperiod;
1306 ret=0;
1307 }
1308
1289 dbgarg (cmd, "type=%d\n", p->type); 1309 dbgarg (cmd, "type=%d\n", p->type);
1290 break; 1310 break;
1291 } 1311 }
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index 268e69fdefc6..d1e04f7c530b 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -4404,7 +4404,6 @@ static struct video_device v4l_device_template = {
4404 .name = "NOT SET", 4404 .name = "NOT SET",
4405 //.type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE | 4405 //.type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE |
4406 // VID_TYPE_CLIPPING | VID_TYPE_SCALES, VID_TYPE_OVERLAY 4406 // VID_TYPE_CLIPPING | VID_TYPE_SCALES, VID_TYPE_OVERLAY
4407 .hardware = VID_HARDWARE_VINO,
4408 .fops = &vino_fops, 4407 .fops = &vino_fops,
4409 .minor = -1, 4408 .minor = -1,
4410}; 4409};
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 841884af0cc0..e7c01d560b64 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -992,7 +992,8 @@ static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf)
992 struct vivi_fh *fh=priv; 992 struct vivi_fh *fh=priv;
993 struct videobuf_queue *q=&fh->vb_vidq; 993 struct videobuf_queue *q=&fh->vb_vidq;
994 struct v4l2_requestbuffers req; 994 struct v4l2_requestbuffers req;
995 unsigned int i, ret; 995 unsigned int i;
996 int ret;
996 997
997 req.type = q->type; 998 req.type = q->type;
998 req.count = 8; 999 req.count = 8;
@@ -1359,6 +1360,8 @@ static int __init vivi_init(void)
1359 dev->vidq.timeout.data = (unsigned long)dev; 1360 dev->vidq.timeout.data = (unsigned long)dev;
1360 init_timer(&dev->vidq.timeout); 1361 init_timer(&dev->vidq.timeout);
1361 1362
1363 vivi.current_norm = tvnorms[0].id;
1364
1362 ret = video_register_device(&vivi, VFL_TYPE_GRABBER, video_nr); 1365 ret = video_register_device(&vivi, VFL_TYPE_GRABBER, video_nr);
1363 printk(KERN_INFO "Video Technology Magazine Virtual Video Capture Board (Load status: %d)\n", ret); 1366 printk(KERN_INFO "Video Technology Magazine Virtual Video Capture Board (Load status: %d)\n", ret);
1364 return ret; 1367 return ret;
diff --git a/drivers/media/video/vpx3220.c b/drivers/media/video/vpx3220.c
index 1eca7e65d235..8ef31ed7d3f1 100644
--- a/drivers/media/video/vpx3220.c
+++ b/drivers/media/video/vpx3220.c
@@ -744,6 +744,6 @@ vpx3220_cleanup (void)
744module_init(vpx3220_init); 744module_init(vpx3220_init);
745module_exit(vpx3220_cleanup); 745module_exit(vpx3220_cleanup);
746 746
747MODULE_DESCRIPTION("vpx3220a/vpx3216b/vpx3214c video encoder driver"); 747MODULE_DESCRIPTION("vpx3220a/vpx3216b/vpx3214c video decoder driver");
748MODULE_AUTHOR("Laurent Pinchart"); 748MODULE_AUTHOR("Laurent Pinchart");
749MODULE_LICENSE("GPL"); 749MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/w9968cf.c b/drivers/media/video/w9968cf.c
index 20f211b55ad4..2912326a5aef 100644
--- a/drivers/media/video/w9968cf.c
+++ b/drivers/media/video/w9968cf.c
@@ -586,15 +586,14 @@ static struct w9968cf_symbolic_list urb_errlist[] = {
586 { -EFBIG, "Too much ISO frames requested" }, 586 { -EFBIG, "Too much ISO frames requested" },
587 { -ENOSR, "Buffer error (overrun)" }, 587 { -ENOSR, "Buffer error (overrun)" },
588 { -EPIPE, "Specified endpoint is stalled (device not responding)"}, 588 { -EPIPE, "Specified endpoint is stalled (device not responding)"},
589 { -EOVERFLOW, "Babble (bad cable?)" }, 589 { -EOVERFLOW, "Babble (too much data)" },
590 { -EPROTO, "Bit-stuff error (bad cable?)" }, 590 { -EPROTO, "Bit-stuff error (bad cable?)" },
591 { -EILSEQ, "CRC/Timeout" }, 591 { -EILSEQ, "CRC/Timeout" },
592 { -ETIMEDOUT, "NAK (device does not respond)" }, 592 { -ETIME, "Device does not respond to token" },
593 { -ETIMEDOUT, "Device does not respond to command" },
593 { -1, NULL } 594 { -1, NULL }
594}; 595};
595 596
596
597
598/**************************************************************************** 597/****************************************************************************
599 * Memory management functions * 598 * Memory management functions *
600 ****************************************************************************/ 599 ****************************************************************************/
diff --git a/drivers/media/video/zoran_card.c b/drivers/media/video/zoran_card.c
index f2249ed25273..9f21d0ba0f0f 100644
--- a/drivers/media/video/zoran_card.c
+++ b/drivers/media/video/zoran_card.c
@@ -820,7 +820,6 @@ static struct i2c_algo_bit_data zoran_i2c_bit_data_template = {
820 .getsda = zoran_i2c_getsda, 820 .getsda = zoran_i2c_getsda,
821 .getscl = zoran_i2c_getscl, 821 .getscl = zoran_i2c_getscl,
822 .udelay = 10, 822 .udelay = 10,
823 .mdelay = 0,
824 .timeout = 100, 823 .timeout = 100,
825}; 824};
826 825
@@ -1621,10 +1620,10 @@ init_dc10_cards (void)
1621 dprintk(5, KERN_DEBUG "Jotti is een held!\n"); 1620 dprintk(5, KERN_DEBUG "Jotti is een held!\n");
1622 1621
1623 /* some mainboards might not do PCI-PCI data transfer well */ 1622 /* some mainboards might not do PCI-PCI data transfer well */
1624 if (pci_pci_problems & PCIPCI_FAIL) { 1623 if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL|PCIPCI_ALIMAGIK)) {
1625 dprintk(1, 1624 dprintk(1,
1626 KERN_WARNING 1625 KERN_WARNING
1627 "%s: chipset may not support reliable PCI-PCI DMA\n", 1626 "%s: chipset does not support reliable PCI-PCI DMA\n",
1628 ZORAN_NAME); 1627 ZORAN_NAME);
1629 } 1628 }
1630 1629
@@ -1632,7 +1631,7 @@ init_dc10_cards (void)
1632 for (i = 0; i < zoran_num; i++) { 1631 for (i = 0; i < zoran_num; i++) {
1633 struct zoran *zr = &zoran[i]; 1632 struct zoran *zr = &zoran[i];
1634 1633
1635 if (pci_pci_problems & PCIPCI_NATOMA && zr->revision <= 1) { 1634 if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) {
1636 zr->jpg_buffers.need_contiguous = 1; 1635 zr->jpg_buffers.need_contiguous = 1;
1637 dprintk(1, 1636 dprintk(1,
1638 KERN_INFO 1637 KERN_INFO
diff --git a/drivers/media/video/zoran_driver.c b/drivers/media/video/zoran_driver.c
index 5f90db27892b..862a984c2155 100644
--- a/drivers/media/video/zoran_driver.c
+++ b/drivers/media/video/zoran_driver.c
@@ -1512,6 +1512,13 @@ setup_fbuffer (struct file *file,
1512 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO)) 1512 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
1513 return -EPERM; 1513 return -EPERM;
1514 1514
1515 /* Don't allow frame buffer overlay if PCI or AGP is buggy, or on
1516 ALi Magik (that needs very low latency while the card needs a
1517 higher value always) */
1518
1519 if (pci_pci_problems & (PCIPCI_FAIL | PCIAGP_FAIL | PCIPCI_ALIMAGIK))
1520 return -ENXIO;
1521
1515 /* we need a bytesperline value, even if not given */ 1522 /* we need a bytesperline value, even if not given */
1516 if (!bytesperline) 1523 if (!bytesperline)
1517 bytesperline = width * ((fmt->depth + 7) & ~7) / 8; 1524 bytesperline = width * ((fmt->depth + 7) & ~7) / 8;
diff --git a/drivers/media/video/zr36120.c b/drivers/media/video/zr36120.c
index 50437383ed62..9240638a0134 100644
--- a/drivers/media/video/zr36120.c
+++ b/drivers/media/video/zr36120.c
@@ -987,6 +987,8 @@ int zoran_ioctl(struct video_device* dev, unsigned int cmd, void *arg)
987 VID_TYPE_SCALES; 987 VID_TYPE_SCALES;
988 if (ztv->have_tuner) 988 if (ztv->have_tuner)
989 c.type |= VID_TYPE_TUNER; 989 c.type |= VID_TYPE_TUNER;
990 if (pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL))
991 c.type &= ~VID_TYPE_OVERLAY;
990 if (ztv->have_decoder) { 992 if (ztv->have_decoder) {
991 c.channels = ztv->card->video_inputs; 993 c.channels = ztv->card->video_inputs;
992 c.audios = ztv->card->audio_inputs; 994 c.audios = ztv->card->audio_inputs;
@@ -1284,6 +1286,8 @@ int zoran_ioctl(struct video_device* dev, unsigned int cmd, void *arg)
1284 struct video_buffer v; 1286 struct video_buffer v;
1285 if(!capable(CAP_SYS_ADMIN)) 1287 if(!capable(CAP_SYS_ADMIN))
1286 return -EPERM; 1288 return -EPERM;
1289 if (pcipci_problems & (PCIPCI_FAIL|PCIAGP_FAIL))
1290 return -ENXIO;
1287 if (copy_from_user(&v, arg,sizeof(v))) 1291 if (copy_from_user(&v, arg,sizeof(v)))
1288 return -EFAULT; 1292 return -EFAULT;
1289 DEBUG(printk(CARD_DEBUG "VIDIOCSFBUF(%p,%d,%d,%d,%d)\n",CARD,v.base, v.width,v.height,v.depth,v.bytesperline)); 1293 DEBUG(printk(CARD_DEBUG "VIDIOCSFBUF(%p,%d,%d,%d,%d)\n",CARD,v.base, v.width,v.height,v.depth,v.bytesperline));
@@ -2030,7 +2034,7 @@ void release_zoran(int max)
2030 /* free it */ 2034 /* free it */
2031 free_irq(ztv->dev->irq,ztv); 2035 free_irq(ztv->dev->irq,ztv);
2032 2036
2033 /* unregister i2c_bus */ 2037 /* unregister i2c_bus */
2034 i2c_unregister_bus((&ztv->i2c)); 2038 i2c_unregister_bus((&ztv->i2c));
2035 2039
2036 /* unmap and free memory */ 2040 /* unmap and free memory */
diff --git a/drivers/message/i2o/Kconfig b/drivers/message/i2o/Kconfig
index fef677103880..6443392bffff 100644
--- a/drivers/message/i2o/Kconfig
+++ b/drivers/message/i2o/Kconfig
@@ -88,7 +88,7 @@ config I2O_BUS
88 88
89config I2O_BLOCK 89config I2O_BLOCK
90 tristate "I2O Block OSM" 90 tristate "I2O Block OSM"
91 depends on I2O 91 depends on I2O && BLOCK
92 ---help--- 92 ---help---
93 Include support for the I2O Block OSM. The Block OSM presents disk 93 Include support for the I2O Block OSM. The Block OSM presents disk
94 and other structured block devices to the operating system. If you 94 and other structured block devices to the operating system. If you
diff --git a/drivers/message/i2o/i2o_block.c b/drivers/message/i2o/i2o_block.c
index 1ddc2fb429d5..eaba81bf2eca 100644
--- a/drivers/message/i2o/i2o_block.c
+++ b/drivers/message/i2o/i2o_block.c
@@ -390,9 +390,9 @@ static int i2o_block_prep_req_fn(struct request_queue *q, struct request *req)
390 } 390 }
391 391
392 /* request is already processed by us, so return */ 392 /* request is already processed by us, so return */
393 if (req->flags & REQ_SPECIAL) { 393 if (blk_special_request(req)) {
394 osm_debug("REQ_SPECIAL already set!\n"); 394 osm_debug("REQ_SPECIAL already set!\n");
395 req->flags |= REQ_DONTPREP; 395 req->cmd_flags |= REQ_DONTPREP;
396 return BLKPREP_OK; 396 return BLKPREP_OK;
397 } 397 }
398 398
@@ -411,7 +411,8 @@ static int i2o_block_prep_req_fn(struct request_queue *q, struct request *req)
411 ireq = req->special; 411 ireq = req->special;
412 412
413 /* do not come back here */ 413 /* do not come back here */
414 req->flags |= REQ_DONTPREP | REQ_SPECIAL; 414 req->cmd_type = REQ_TYPE_SPECIAL;
415 req->cmd_flags |= REQ_DONTPREP;
415 416
416 return BLKPREP_OK; 417 return BLKPREP_OK;
417}; 418};
diff --git a/drivers/message/i2o/pci.c b/drivers/message/i2o/pci.c
index 1b58444d5aaf..dec41cc89937 100644
--- a/drivers/message/i2o/pci.c
+++ b/drivers/message/i2o/pci.c
@@ -372,12 +372,13 @@ static int __devinit i2o_pci_probe(struct pci_dev *pdev,
372 * Expose the ship behind i960 for initialization, or it will 372 * Expose the ship behind i960 for initialization, or it will
373 * failed 373 * failed
374 */ 374 */
375 i960 = 375 i960 = pci_get_slot(c->pdev->bus,
376 pci_find_slot(c->pdev->bus->number,
377 PCI_DEVFN(PCI_SLOT(c->pdev->devfn), 0)); 376 PCI_DEVFN(PCI_SLOT(c->pdev->devfn), 0));
378 377
379 if (i960) 378 if (i960) {
380 pci_write_config_word(i960, 0x42, 0); 379 pci_write_config_word(i960, 0x42, 0);
380 pci_dev_put(i960);
381 }
381 382
382 c->promise = 1; 383 c->promise = 1;
383 c->limit_sectors = 1; 384 c->limit_sectors = 1;
diff --git a/drivers/mfd/ucb1x00-ts.c b/drivers/mfd/ucb1x00-ts.c
index 02776814443e..82938ad6ddbd 100644
--- a/drivers/mfd/ucb1x00-ts.c
+++ b/drivers/mfd/ucb1x00-ts.c
@@ -58,6 +58,7 @@ static int adcsync;
58static inline void ucb1x00_ts_evt_add(struct ucb1x00_ts *ts, u16 pressure, u16 x, u16 y) 58static inline void ucb1x00_ts_evt_add(struct ucb1x00_ts *ts, u16 pressure, u16 x, u16 y)
59{ 59{
60 struct input_dev *idev = ts->idev; 60 struct input_dev *idev = ts->idev;
61
61 input_report_abs(idev, ABS_X, x); 62 input_report_abs(idev, ABS_X, x);
62 input_report_abs(idev, ABS_Y, y); 63 input_report_abs(idev, ABS_Y, y);
63 input_report_abs(idev, ABS_PRESSURE, pressure); 64 input_report_abs(idev, ABS_PRESSURE, pressure);
@@ -67,6 +68,7 @@ static inline void ucb1x00_ts_evt_add(struct ucb1x00_ts *ts, u16 pressure, u16 x
67static inline void ucb1x00_ts_event_release(struct ucb1x00_ts *ts) 68static inline void ucb1x00_ts_event_release(struct ucb1x00_ts *ts)
68{ 69{
69 struct input_dev *idev = ts->idev; 70 struct input_dev *idev = ts->idev;
71
70 input_report_abs(idev, ABS_PRESSURE, 0); 72 input_report_abs(idev, ABS_PRESSURE, 0);
71 input_sync(idev); 73 input_sync(idev);
72} 74}
@@ -189,6 +191,7 @@ static inline unsigned int ucb1x00_ts_read_yres(struct ucb1x00_ts *ts)
189static inline int ucb1x00_ts_pen_down(struct ucb1x00_ts *ts) 191static inline int ucb1x00_ts_pen_down(struct ucb1x00_ts *ts)
190{ 192{
191 unsigned int val = ucb1x00_reg_read(ts->ucb, UCB_TS_CR); 193 unsigned int val = ucb1x00_reg_read(ts->ucb, UCB_TS_CR);
194
192 if (machine_is_collie()) 195 if (machine_is_collie())
193 return (!(val & (UCB_TS_CR_TSPX_LOW))); 196 return (!(val & (UCB_TS_CR_TSPX_LOW)));
194 else 197 else
@@ -291,6 +294,7 @@ static int ucb1x00_thread(void *_ts)
291static void ucb1x00_ts_irq(int idx, void *id) 294static void ucb1x00_ts_irq(int idx, void *id)
292{ 295{
293 struct ucb1x00_ts *ts = id; 296 struct ucb1x00_ts *ts = id;
297
294 ucb1x00_disable_irq(ts->ucb, UCB_IRQ_TSPX, UCB_FALLING); 298 ucb1x00_disable_irq(ts->ucb, UCB_IRQ_TSPX, UCB_FALLING);
295 wake_up(&ts->irq_wait); 299 wake_up(&ts->irq_wait);
296} 300}
@@ -372,36 +376,43 @@ static int ucb1x00_ts_resume(struct ucb1x00_dev *dev)
372static int ucb1x00_ts_add(struct ucb1x00_dev *dev) 376static int ucb1x00_ts_add(struct ucb1x00_dev *dev)
373{ 377{
374 struct ucb1x00_ts *ts; 378 struct ucb1x00_ts *ts;
379 struct input_dev *idev;
380 int err;
375 381
376 ts = kzalloc(sizeof(struct ucb1x00_ts), GFP_KERNEL); 382 ts = kzalloc(sizeof(struct ucb1x00_ts), GFP_KERNEL);
377 if (!ts) 383 idev = input_allocate_device();
378 return -ENOMEM; 384 if (!ts || !idev) {
379 385 err = -ENOMEM;
380 ts->idev = input_allocate_device(); 386 goto fail;
381 if (!ts->idev) {
382 kfree(ts);
383 return -ENOMEM;
384 } 387 }
385 388
386 ts->ucb = dev->ucb; 389 ts->ucb = dev->ucb;
390 ts->idev = idev;
387 ts->adcsync = adcsync ? UCB_SYNC : UCB_NOSYNC; 391 ts->adcsync = adcsync ? UCB_SYNC : UCB_NOSYNC;
388 392
389 ts->idev->private = ts; 393 idev->private = ts;
390 ts->idev->name = "Touchscreen panel"; 394 idev->name = "Touchscreen panel";
391 ts->idev->id.product = ts->ucb->id; 395 idev->id.product = ts->ucb->id;
392 ts->idev->open = ucb1x00_ts_open; 396 idev->open = ucb1x00_ts_open;
393 ts->idev->close = ucb1x00_ts_close; 397 idev->close = ucb1x00_ts_close;
394 398
395 __set_bit(EV_ABS, ts->idev->evbit); 399 __set_bit(EV_ABS, idev->evbit);
396 __set_bit(ABS_X, ts->idev->absbit); 400 __set_bit(ABS_X, idev->absbit);
397 __set_bit(ABS_Y, ts->idev->absbit); 401 __set_bit(ABS_Y, idev->absbit);
398 __set_bit(ABS_PRESSURE, ts->idev->absbit); 402 __set_bit(ABS_PRESSURE, idev->absbit);
399 403
400 input_register_device(ts->idev); 404 err = input_register_device(idev);
405 if (err)
406 goto fail;
401 407
402 dev->priv = ts; 408 dev->priv = ts;
403 409
404 return 0; 410 return 0;
411
412 fail:
413 input_free_device(idev);
414 kfree(ts);
415 return err;
405} 416}
406 417
407static void ucb1x00_ts_remove(struct ucb1x00_dev *dev) 418static void ucb1x00_ts_remove(struct ucb1x00_dev *dev)
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 19c2b85249c3..c1bf1fb04c5c 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -3,5 +3,6 @@
3# 3#
4obj- := misc.o # Dummy rule to force built-in.o to be made 4obj- := misc.o # Dummy rule to force built-in.o to be made
5 5
6obj-$(CONFIG_IBM_ASM) += ibmasm/ 6obj-$(CONFIG_IBM_ASM) += ibmasm/
7obj-$(CONFIG_HDPU_FEATURES) += hdpuftrs/ 7obj-$(CONFIG_HDPU_FEATURES) += hdpuftrs/
8obj-$(CONFIG_LKDTM) += lkdtm.o
diff --git a/drivers/misc/ibmasm/ibmasmfs.c b/drivers/misc/ibmasm/ibmasmfs.c
index 4a35caff5d02..b99dc507de2e 100644
--- a/drivers/misc/ibmasm/ibmasmfs.c
+++ b/drivers/misc/ibmasm/ibmasmfs.c
@@ -147,7 +147,6 @@ static struct inode *ibmasmfs_make_inode(struct super_block *sb, int mode)
147 if (ret) { 147 if (ret) {
148 ret->i_mode = mode; 148 ret->i_mode = mode;
149 ret->i_uid = ret->i_gid = 0; 149 ret->i_uid = ret->i_gid = 0;
150 ret->i_blksize = PAGE_CACHE_SIZE;
151 ret->i_blocks = 0; 150 ret->i_blocks = 0;
152 ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME; 151 ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
153 } 152 }
@@ -175,7 +174,7 @@ static struct dentry *ibmasmfs_create_file (struct super_block *sb,
175 } 174 }
176 175
177 inode->i_fop = fops; 176 inode->i_fop = fops;
178 inode->u.generic_ip = data; 177 inode->i_private = data;
179 178
180 d_add(dentry, inode); 179 d_add(dentry, inode);
181 return dentry; 180 return dentry;
@@ -244,7 +243,7 @@ static int command_file_open(struct inode *inode, struct file *file)
244{ 243{
245 struct ibmasmfs_command_data *command_data; 244 struct ibmasmfs_command_data *command_data;
246 245
247 if (!inode->u.generic_ip) 246 if (!inode->i_private)
248 return -ENODEV; 247 return -ENODEV;
249 248
250 command_data = kmalloc(sizeof(struct ibmasmfs_command_data), GFP_KERNEL); 249 command_data = kmalloc(sizeof(struct ibmasmfs_command_data), GFP_KERNEL);
@@ -252,7 +251,7 @@ static int command_file_open(struct inode *inode, struct file *file)
252 return -ENOMEM; 251 return -ENOMEM;
253 252
254 command_data->command = NULL; 253 command_data->command = NULL;
255 command_data->sp = inode->u.generic_ip; 254 command_data->sp = inode->i_private;
256 file->private_data = command_data; 255 file->private_data = command_data;
257 return 0; 256 return 0;
258} 257}
@@ -351,10 +350,10 @@ static int event_file_open(struct inode *inode, struct file *file)
351 struct ibmasmfs_event_data *event_data; 350 struct ibmasmfs_event_data *event_data;
352 struct service_processor *sp; 351 struct service_processor *sp;
353 352
354 if (!inode->u.generic_ip) 353 if (!inode->i_private)
355 return -ENODEV; 354 return -ENODEV;
356 355
357 sp = inode->u.generic_ip; 356 sp = inode->i_private;
358 357
359 event_data = kmalloc(sizeof(struct ibmasmfs_event_data), GFP_KERNEL); 358 event_data = kmalloc(sizeof(struct ibmasmfs_event_data), GFP_KERNEL);
360 if (!event_data) 359 if (!event_data)
@@ -439,14 +438,14 @@ static int r_heartbeat_file_open(struct inode *inode, struct file *file)
439{ 438{
440 struct ibmasmfs_heartbeat_data *rhbeat; 439 struct ibmasmfs_heartbeat_data *rhbeat;
441 440
442 if (!inode->u.generic_ip) 441 if (!inode->i_private)
443 return -ENODEV; 442 return -ENODEV;
444 443
445 rhbeat = kmalloc(sizeof(struct ibmasmfs_heartbeat_data), GFP_KERNEL); 444 rhbeat = kmalloc(sizeof(struct ibmasmfs_heartbeat_data), GFP_KERNEL);
446 if (!rhbeat) 445 if (!rhbeat)
447 return -ENOMEM; 446 return -ENOMEM;
448 447
449 rhbeat->sp = (struct service_processor *)inode->u.generic_ip; 448 rhbeat->sp = inode->i_private;
450 rhbeat->active = 0; 449 rhbeat->active = 0;
451 ibmasm_init_reverse_heartbeat(rhbeat->sp, &rhbeat->heartbeat); 450 ibmasm_init_reverse_heartbeat(rhbeat->sp, &rhbeat->heartbeat);
452 file->private_data = rhbeat; 451 file->private_data = rhbeat;
@@ -508,7 +507,7 @@ static ssize_t r_heartbeat_file_write(struct file *file, const char __user *buf,
508 507
509static int remote_settings_file_open(struct inode *inode, struct file *file) 508static int remote_settings_file_open(struct inode *inode, struct file *file)
510{ 509{
511 file->private_data = inode->u.generic_ip; 510 file->private_data = inode->i_private;
512 return 0; 511 return 0;
513} 512}
514 513
diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
new file mode 100644
index 000000000000..e689ee94ac3d
--- /dev/null
+++ b/drivers/misc/lkdtm.c
@@ -0,0 +1,342 @@
1/*
2 * Kprobe module for testing crash dumps
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * Copyright (C) IBM Corporation, 2006
19 *
20 * Author: Ankita Garg <ankita@in.ibm.com>
21 *
22 * This module induces system failures at predefined crashpoints to
23 * evaluate the reliability of crash dumps obtained using different dumping
24 * solutions.
25 *
26 * It is adapted from the Linux Kernel Dump Test Tool by
27 * Fernando Luis Vazquez Cao <http://lkdtt.sourceforge.net>
28 *
29 * Usage : insmod lkdtm.ko [recur_count={>0}] cpoint_name=<> cpoint_type=<>
30 * [cpoint_count={>0}]
31 *
32 * recur_count : Recursion level for the stack overflow test. Default is 10.
33 *
34 * cpoint_name : Crash point where the kernel is to be crashed. It can be
35 * one of INT_HARDWARE_ENTRY, INT_HW_IRQ_EN, INT_TASKLET_ENTRY,
36 * FS_DEVRW, MEM_SWAPOUT, TIMERADD, SCSI_DISPATCH_CMD,
37 * IDE_CORE_CP
38 *
39 * cpoint_type : Indicates the action to be taken on hitting the crash point.
40 * It can be one of PANIC, BUG, EXCEPTION, LOOP, OVERFLOW
41 *
42 * cpoint_count : Indicates the number of times the crash point is to be hit
43 * to trigger an action. The default is 10.
44 */
45
46#include <linux/kernel.h>
47#include <linux/module.h>
48#include <linux/kprobes.h>
49#include <linux/kallsyms.h>
50#include <linux/init.h>
51#include <linux/irq.h>
52#include <linux/interrupt.h>
53#include <scsi/scsi_cmnd.h>
54
55#ifdef CONFIG_IDE
56#include <linux/ide.h>
57#endif
58
59#define NUM_CPOINTS 8
60#define NUM_CPOINT_TYPES 5
61#define DEFAULT_COUNT 10
62#define REC_NUM_DEFAULT 10
63
64enum cname {
65 INVALID,
66 INT_HARDWARE_ENTRY,
67 INT_HW_IRQ_EN,
68 INT_TASKLET_ENTRY,
69 FS_DEVRW,
70 MEM_SWAPOUT,
71 TIMERADD,
72 SCSI_DISPATCH_CMD,
73 IDE_CORE_CP
74};
75
76enum ctype {
77 NONE,
78 PANIC,
79 BUG,
80 EXCEPTION,
81 LOOP,
82 OVERFLOW
83};
84
85static char* cp_name[] = {
86 "INT_HARDWARE_ENTRY",
87 "INT_HW_IRQ_EN",
88 "INT_TASKLET_ENTRY",
89 "FS_DEVRW",
90 "MEM_SWAPOUT",
91 "TIMERADD",
92 "SCSI_DISPATCH_CMD",
93 "IDE_CORE_CP"
94};
95
96static char* cp_type[] = {
97 "PANIC",
98 "BUG",
99 "EXCEPTION",
100 "LOOP",
101 "OVERFLOW"
102};
103
104static struct jprobe lkdtm;
105
106static int lkdtm_parse_commandline(void);
107static void lkdtm_handler(void);
108
109static char* cpoint_name = INVALID;
110static char* cpoint_type = NONE;
111static int cpoint_count = DEFAULT_COUNT;
112static int recur_count = REC_NUM_DEFAULT;
113
114static enum cname cpoint = INVALID;
115static enum ctype cptype = NONE;
116static int count = DEFAULT_COUNT;
117
118module_param(recur_count, int, 0644);
119MODULE_PARM_DESC(recur_count, "Recurcion level for the stack overflow test,\
120 default is 10");
121module_param(cpoint_name, charp, 0644);
122MODULE_PARM_DESC(cpoint_name, "Crash Point, where kernel is to be crashed");
123module_param(cpoint_type, charp, 06444);
124MODULE_PARM_DESC(cpoint_type, "Crash Point Type, action to be taken on\
125 hitting the crash point");
126module_param(cpoint_count, int, 06444);
127MODULE_PARM_DESC(cpoint_count, "Crash Point Count, number of times the \
128 crash point is to be hit to trigger action");
129
130unsigned int jp_do_irq(unsigned int irq, struct pt_regs *regs)
131{
132 lkdtm_handler();
133 jprobe_return();
134 return 0;
135}
136
137irqreturn_t jp_handle_irq_event(unsigned int irq, struct pt_regs *regs,
138 struct irqaction *action)
139{
140 lkdtm_handler();
141 jprobe_return();
142 return 0;
143}
144
145void jp_tasklet_action(struct softirq_action *a)
146{
147 lkdtm_handler();
148 jprobe_return();
149}
150
151void jp_ll_rw_block(int rw, int nr, struct buffer_head *bhs[])
152{
153 lkdtm_handler();
154 jprobe_return();
155}
156
157struct scan_control;
158
159unsigned long jp_shrink_page_list(struct list_head *page_list,
160 struct scan_control *sc)
161{
162 lkdtm_handler();
163 jprobe_return();
164 return 0;
165}
166
167int jp_hrtimer_start(struct hrtimer *timer, ktime_t tim,
168 const enum hrtimer_mode mode)
169{
170 lkdtm_handler();
171 jprobe_return();
172 return 0;
173}
174
175int jp_scsi_dispatch_cmd(struct scsi_cmnd *cmd)
176{
177 lkdtm_handler();
178 jprobe_return();
179 return 0;
180}
181
182#ifdef CONFIG_IDE
183int jp_generic_ide_ioctl(ide_drive_t *drive, struct file *file,
184 struct block_device *bdev, unsigned int cmd,
185 unsigned long arg)
186{
187 lkdtm_handler();
188 jprobe_return();
189 return 0;
190}
191#endif
192
193static int lkdtm_parse_commandline(void)
194{
195 int i;
196
197 if (cpoint_name == INVALID || cpoint_type == NONE ||
198 cpoint_count < 1 || recur_count < 1)
199 return -EINVAL;
200
201 for (i = 0; i < NUM_CPOINTS; ++i) {
202 if (!strcmp(cpoint_name, cp_name[i])) {
203 cpoint = i + 1;
204 break;
205 }
206 }
207
208 for (i = 0; i < NUM_CPOINT_TYPES; ++i) {
209 if (!strcmp(cpoint_type, cp_type[i])) {
210 cptype = i + 1;
211 break;
212 }
213 }
214
215 if (cpoint == INVALID || cptype == NONE)
216 return -EINVAL;
217
218 count = cpoint_count;
219
220 return 0;
221}
222
223static int recursive_loop(int a)
224{
225 char buf[1024];
226
227 memset(buf,0xFF,1024);
228 recur_count--;
229 if (!recur_count)
230 return 0;
231 else
232 return recursive_loop(a);
233}
234
235void lkdtm_handler(void)
236{
237 printk(KERN_INFO "lkdtm : Crash point %s of type %s hit\n",
238 cpoint_name, cpoint_type);
239 --count;
240
241 if (count == 0) {
242 switch (cptype) {
243 case NONE:
244 break;
245 case PANIC:
246 printk(KERN_INFO "lkdtm : PANIC\n");
247 panic("dumptest");
248 break;
249 case BUG:
250 printk(KERN_INFO "lkdtm : BUG\n");
251 BUG();
252 break;
253 case EXCEPTION:
254 printk(KERN_INFO "lkdtm : EXCEPTION\n");
255 *((int *) 0) = 0;
256 break;
257 case LOOP:
258 printk(KERN_INFO "lkdtm : LOOP\n");
259 for (;;);
260 break;
261 case OVERFLOW:
262 printk(KERN_INFO "lkdtm : OVERFLOW\n");
263 (void) recursive_loop(0);
264 break;
265 default:
266 break;
267 }
268 count = cpoint_count;
269 }
270}
271
272int lkdtm_module_init(void)
273{
274 int ret;
275
276 if (lkdtm_parse_commandline() == -EINVAL) {
277 printk(KERN_INFO "lkdtm : Invalid command\n");
278 return -EINVAL;
279 }
280
281 switch (cpoint) {
282 case INT_HARDWARE_ENTRY:
283 lkdtm.kp.symbol_name = "__do_IRQ";
284 lkdtm.entry = (kprobe_opcode_t*) jp_do_irq;
285 break;
286 case INT_HW_IRQ_EN:
287 lkdtm.kp.symbol_name = "handle_IRQ_event";
288 lkdtm.entry = (kprobe_opcode_t*) jp_handle_irq_event;
289 break;
290 case INT_TASKLET_ENTRY:
291 lkdtm.kp.symbol_name = "tasklet_action";
292 lkdtm.entry = (kprobe_opcode_t*) jp_tasklet_action;
293 break;
294 case FS_DEVRW:
295 lkdtm.kp.symbol_name = "ll_rw_block";
296 lkdtm.entry = (kprobe_opcode_t*) jp_ll_rw_block;
297 break;
298 case MEM_SWAPOUT:
299 lkdtm.kp.symbol_name = "shrink_page_list";
300 lkdtm.entry = (kprobe_opcode_t*) jp_shrink_page_list;
301 break;
302 case TIMERADD:
303 lkdtm.kp.symbol_name = "hrtimer_start";
304 lkdtm.entry = (kprobe_opcode_t*) jp_hrtimer_start;
305 break;
306 case SCSI_DISPATCH_CMD:
307 lkdtm.kp.symbol_name = "scsi_dispatch_cmd";
308 lkdtm.entry = (kprobe_opcode_t*) jp_scsi_dispatch_cmd;
309 break;
310 case IDE_CORE_CP:
311#ifdef CONFIG_IDE
312 lkdtm.kp.symbol_name = "generic_ide_ioctl";
313 lkdtm.entry = (kprobe_opcode_t*) jp_generic_ide_ioctl;
314#else
315 printk(KERN_INFO "lkdtm : Crash point not available\n");
316#endif
317 break;
318 default:
319 printk(KERN_INFO "lkdtm : Invalid Crash Point\n");
320 break;
321 }
322
323 if ((ret = register_jprobe(&lkdtm)) < 0) {
324 printk(KERN_INFO "lkdtm : Couldn't register jprobe\n");
325 return ret;
326 }
327
328 printk(KERN_INFO "lkdtm : Crash point %s of type %s registered\n",
329 cpoint_name, cpoint_type);
330 return 0;
331}
332
333void lkdtm_module_exit(void)
334{
335 unregister_jprobe(&lkdtm);
336 printk(KERN_INFO "lkdtm : Crash point unregistered\n");
337}
338
339module_init(lkdtm_module_init);
340module_exit(lkdtm_module_exit);
341
342MODULE_LICENSE("GPL");
diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
index 45bcf098e762..f540bd88dc5a 100644
--- a/drivers/mmc/Kconfig
+++ b/drivers/mmc/Kconfig
@@ -21,7 +21,7 @@ config MMC_DEBUG
21 21
22config MMC_BLOCK 22config MMC_BLOCK
23 tristate "MMC block device driver" 23 tristate "MMC block device driver"
24 depends on MMC 24 depends on MMC && BLOCK
25 default y 25 default y
26 help 26 help
27 Say Y here to enable the MMC block device driver support. 27 Say Y here to enable the MMC block device driver support.
diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
index d2957e35cc6f..b1f6e03e7aa9 100644
--- a/drivers/mmc/Makefile
+++ b/drivers/mmc/Makefile
@@ -24,7 +24,8 @@ obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
24obj-$(CONFIG_MMC_OMAP) += omap.o 24obj-$(CONFIG_MMC_OMAP) += omap.o
25obj-$(CONFIG_MMC_AT91RM9200) += at91_mci.o 25obj-$(CONFIG_MMC_AT91RM9200) += at91_mci.o
26 26
27mmc_core-y := mmc.o mmc_queue.o mmc_sysfs.o 27mmc_core-y := mmc.o mmc_sysfs.o
28mmc_core-$(CONFIG_BLOCK) += mmc_queue.o
28 29
29ifeq ($(CONFIG_MMC_DEBUG),y) 30ifeq ($(CONFIG_MMC_DEBUG),y)
30EXTRA_CFLAGS += -DDEBUG 31EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/mmc/at91_mci.c b/drivers/mmc/at91_mci.c
index 6b7638b84290..cb142a66098c 100644
--- a/drivers/mmc/at91_mci.c
+++ b/drivers/mmc/at91_mci.c
@@ -822,6 +822,7 @@ static int at91_mci_probe(struct platform_device *pdev)
822 mmc->f_min = 375000; 822 mmc->f_min = 375000;
823 mmc->f_max = 25000000; 823 mmc->f_max = 25000000;
824 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; 824 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
825 mmc->caps = MMC_CAP_BYTEBLOCK;
825 826
826 host = mmc_priv(mmc); 827 host = mmc_priv(mmc);
827 host->mmc = mmc; 828 host->mmc = mmc;
@@ -850,7 +851,7 @@ static int at91_mci_probe(struct platform_device *pdev)
850 /* 851 /*
851 * Allocate the MCI interrupt 852 * Allocate the MCI interrupt
852 */ 853 */
853 ret = request_irq(AT91_ID_MCI, at91_mci_irq, IRQF_SHARED, DRIVER_NAME, host); 854 ret = request_irq(AT91RM9200_ID_MCI, at91_mci_irq, IRQF_SHARED, DRIVER_NAME, host);
854 if (ret) { 855 if (ret) {
855 printk(KERN_ERR "Failed to request MCI interrupt\n"); 856 printk(KERN_ERR "Failed to request MCI interrupt\n");
856 clk_disable(mci_clk); 857 clk_disable(mci_clk);
@@ -906,7 +907,7 @@ static int at91_mci_remove(struct platform_device *pdev)
906 907
907 mmc_remove_host(mmc); 908 mmc_remove_host(mmc);
908 at91_mci_disable(); 909 at91_mci_disable();
909 free_irq(AT91_ID_MCI, host); 910 free_irq(AT91RM9200_ID_MCI, host);
910 mmc_free_host(mmc); 911 mmc_free_host(mmc);
911 912
912 clk_disable(mci_clk); /* Disable the peripheral clock */ 913 clk_disable(mci_clk); /* Disable the peripheral clock */
diff --git a/drivers/mmc/au1xmmc.c b/drivers/mmc/au1xmmc.c
index fb606165af3b..61268da13957 100644
--- a/drivers/mmc/au1xmmc.c
+++ b/drivers/mmc/au1xmmc.c
@@ -731,7 +731,7 @@ static void au1xmmc_set_ios(struct mmc_host* mmc, struct mmc_ios* ios)
731 } 731 }
732} 732}
733 733
734static void au1xmmc_dma_callback(int irq, void *dev_id, struct pt_regs *regs) 734static void au1xmmc_dma_callback(int irq, void *dev_id)
735{ 735{
736 struct au1xmmc_host *host = (struct au1xmmc_host *) dev_id; 736 struct au1xmmc_host *host = (struct au1xmmc_host *) dev_id;
737 737
diff --git a/drivers/mmc/imxmmc.c b/drivers/mmc/imxmmc.c
index fb6565b98f32..1b79dd271aae 100644
--- a/drivers/mmc/imxmmc.c
+++ b/drivers/mmc/imxmmc.c
@@ -956,7 +956,7 @@ static int imxmci_probe(struct platform_device *pdev)
956 mmc->f_min = 150000; 956 mmc->f_min = 150000;
957 mmc->f_max = CLK_RATE/2; 957 mmc->f_max = CLK_RATE/2;
958 mmc->ocr_avail = MMC_VDD_32_33; 958 mmc->ocr_avail = MMC_VDD_32_33;
959 mmc->caps |= MMC_CAP_4_BIT_DATA; 959 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_BYTEBLOCK;
960 960
961 /* MMC core transfer sizes tunable parameters */ 961 /* MMC core transfer sizes tunable parameters */
962 mmc->max_hw_segs = 64; 962 mmc->max_hw_segs = 64;
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 74eaaee66de0..5b9caa7978d3 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -996,7 +996,6 @@ static void mmc_read_scrs(struct mmc_host *host)
996 996
997 mmc_set_data_timeout(&data, card, 0); 997 mmc_set_data_timeout(&data, card, 0);
998 998
999 data.blksz_bits = 3;
1000 data.blksz = 1 << 3; 999 data.blksz = 1 << 3;
1001 data.blocks = 1; 1000 data.blocks = 1;
1002 data.flags = MMC_DATA_READ; 1001 data.flags = MMC_DATA_READ;
diff --git a/drivers/mmc/mmc_block.c b/drivers/mmc/mmc_block.c
index a0e0dad1b419..db0e8ad439a5 100644
--- a/drivers/mmc/mmc_block.c
+++ b/drivers/mmc/mmc_block.c
@@ -32,6 +32,7 @@
32#include <linux/mmc/card.h> 32#include <linux/mmc/card.h>
33#include <linux/mmc/host.h> 33#include <linux/mmc/host.h>
34#include <linux/mmc/protocol.h> 34#include <linux/mmc/protocol.h>
35#include <linux/mmc/host.h>
35 36
36#include <asm/system.h> 37#include <asm/system.h>
37#include <asm/uaccess.h> 38#include <asm/uaccess.h>
@@ -165,6 +166,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
165 do { 166 do {
166 struct mmc_blk_request brq; 167 struct mmc_blk_request brq;
167 struct mmc_command cmd; 168 struct mmc_command cmd;
169 u32 readcmd, writecmd;
168 170
169 memset(&brq, 0, sizeof(struct mmc_blk_request)); 171 memset(&brq, 0, sizeof(struct mmc_blk_request));
170 brq.mrq.cmd = &brq.cmd; 172 brq.mrq.cmd = &brq.cmd;
@@ -172,7 +174,6 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
172 174
173 brq.cmd.arg = req->sector << 9; 175 brq.cmd.arg = req->sector << 9;
174 brq.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; 176 brq.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
175 brq.data.blksz_bits = md->block_bits;
176 brq.data.blksz = 1 << md->block_bits; 177 brq.data.blksz = 1 << md->block_bits;
177 brq.data.blocks = req->nr_sectors >> (md->block_bits - 9); 178 brq.data.blocks = req->nr_sectors >> (md->block_bits - 9);
178 brq.stop.opcode = MMC_STOP_TRANSMISSION; 179 brq.stop.opcode = MMC_STOP_TRANSMISSION;
@@ -181,20 +182,31 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
181 182
182 mmc_set_data_timeout(&brq.data, card, rq_data_dir(req) != READ); 183 mmc_set_data_timeout(&brq.data, card, rq_data_dir(req) != READ);
183 184
184 if (rq_data_dir(req) == READ) { 185 /*
185 brq.cmd.opcode = brq.data.blocks > 1 ? MMC_READ_MULTIPLE_BLOCK : MMC_READ_SINGLE_BLOCK; 186 * If the host doesn't support multiple block writes, force
186 brq.data.flags |= MMC_DATA_READ; 187 * block writes to single block.
187 } else { 188 */
188 brq.cmd.opcode = MMC_WRITE_BLOCK; 189 if (rq_data_dir(req) != READ &&
189 brq.data.flags |= MMC_DATA_WRITE; 190 !(card->host->caps & MMC_CAP_MULTIWRITE))
190 brq.data.blocks = 1; 191 brq.data.blocks = 1;
191 }
192 192
193 if (brq.data.blocks > 1) { 193 if (brq.data.blocks > 1) {
194 brq.data.flags |= MMC_DATA_MULTI; 194 brq.data.flags |= MMC_DATA_MULTI;
195 brq.mrq.stop = &brq.stop; 195 brq.mrq.stop = &brq.stop;
196 readcmd = MMC_READ_MULTIPLE_BLOCK;
197 writecmd = MMC_WRITE_MULTIPLE_BLOCK;
196 } else { 198 } else {
197 brq.mrq.stop = NULL; 199 brq.mrq.stop = NULL;
200 readcmd = MMC_READ_SINGLE_BLOCK;
201 writecmd = MMC_WRITE_BLOCK;
202 }
203
204 if (rq_data_dir(req) == READ) {
205 brq.cmd.opcode = readcmd;
206 brq.data.flags |= MMC_DATA_READ;
207 } else {
208 brq.cmd.opcode = writecmd;
209 brq.data.flags |= MMC_DATA_WRITE;
198 } 210 }
199 211
200 brq.data.sg = mq->sg; 212 brq.data.sg = mq->sg;
@@ -219,27 +231,29 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
219 goto cmd_err; 231 goto cmd_err;
220 } 232 }
221 233
222 do { 234 if (rq_data_dir(req) != READ) {
223 int err; 235 do {
224 236 int err;
225 cmd.opcode = MMC_SEND_STATUS; 237
226 cmd.arg = card->rca << 16; 238 cmd.opcode = MMC_SEND_STATUS;
227 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 239 cmd.arg = card->rca << 16;
228 err = mmc_wait_for_cmd(card->host, &cmd, 5); 240 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
229 if (err) { 241 err = mmc_wait_for_cmd(card->host, &cmd, 5);
230 printk(KERN_ERR "%s: error %d requesting status\n", 242 if (err) {
231 req->rq_disk->disk_name, err); 243 printk(KERN_ERR "%s: error %d requesting status\n",
232 goto cmd_err; 244 req->rq_disk->disk_name, err);
233 } 245 goto cmd_err;
234 } while (!(cmd.resp[0] & R1_READY_FOR_DATA)); 246 }
247 } while (!(cmd.resp[0] & R1_READY_FOR_DATA));
235 248
236#if 0 249#if 0
237 if (cmd.resp[0] & ~0x00000900) 250 if (cmd.resp[0] & ~0x00000900)
238 printk(KERN_ERR "%s: status = %08x\n", 251 printk(KERN_ERR "%s: status = %08x\n",
239 req->rq_disk->disk_name, cmd.resp[0]); 252 req->rq_disk->disk_name, cmd.resp[0]);
240 if (mmc_decode_status(cmd.resp)) 253 if (mmc_decode_status(cmd.resp))
241 goto cmd_err; 254 goto cmd_err;
242#endif 255#endif
256 }
243 257
244 /* 258 /*
245 * A block was successfully transferred. 259 * A block was successfully transferred.
diff --git a/drivers/mmc/mmc_queue.c b/drivers/mmc/mmc_queue.c
index 74f8cdeeff0f..4ccdd82b680f 100644
--- a/drivers/mmc/mmc_queue.c
+++ b/drivers/mmc/mmc_queue.c
@@ -28,7 +28,7 @@ static int mmc_prep_request(struct request_queue *q, struct request *req)
28 struct mmc_queue *mq = q->queuedata; 28 struct mmc_queue *mq = q->queuedata;
29 int ret = BLKPREP_KILL; 29 int ret = BLKPREP_KILL;
30 30
31 if (req->flags & REQ_SPECIAL) { 31 if (blk_special_request(req)) {
32 /* 32 /*
33 * Special commands already have the command 33 * Special commands already have the command
34 * blocks already setup in req->special. 34 * blocks already setup in req->special.
@@ -36,7 +36,7 @@ static int mmc_prep_request(struct request_queue *q, struct request *req)
36 BUG_ON(!req->special); 36 BUG_ON(!req->special);
37 37
38 ret = BLKPREP_OK; 38 ret = BLKPREP_OK;
39 } else if (req->flags & (REQ_CMD | REQ_BLOCK_PC)) { 39 } else if (blk_fs_request(req) || blk_pc_request(req)) {
40 /* 40 /*
41 * Block I/O requests need translating according 41 * Block I/O requests need translating according
42 * to the protocol. 42 * to the protocol.
@@ -50,7 +50,7 @@ static int mmc_prep_request(struct request_queue *q, struct request *req)
50 } 50 }
51 51
52 if (ret == BLKPREP_OK) 52 if (ret == BLKPREP_OK)
53 req->flags |= REQ_DONTPREP; 53 req->cmd_flags |= REQ_DONTPREP;
54 54
55 return ret; 55 return ret;
56} 56}
diff --git a/drivers/mmc/mmci.c b/drivers/mmc/mmci.c
index 1886562abdd4..2b5a0cc9ea56 100644
--- a/drivers/mmc/mmci.c
+++ b/drivers/mmc/mmci.c
@@ -69,12 +69,13 @@ static void mmci_start_data(struct mmci_host *host, struct mmc_data *data)
69 unsigned int datactrl, timeout, irqmask; 69 unsigned int datactrl, timeout, irqmask;
70 unsigned long long clks; 70 unsigned long long clks;
71 void __iomem *base; 71 void __iomem *base;
72 int blksz_bits;
72 73
73 DBG(host, "blksz %04x blks %04x flags %08x\n", 74 DBG(host, "blksz %04x blks %04x flags %08x\n",
74 1 << data->blksz_bits, data->blocks, data->flags); 75 data->blksz, data->blocks, data->flags);
75 76
76 host->data = data; 77 host->data = data;
77 host->size = data->blocks << data->blksz_bits; 78 host->size = data->blksz;
78 host->data_xfered = 0; 79 host->data_xfered = 0;
79 80
80 mmci_init_sg(host, data); 81 mmci_init_sg(host, data);
@@ -88,7 +89,10 @@ static void mmci_start_data(struct mmci_host *host, struct mmc_data *data)
88 writel(timeout, base + MMCIDATATIMER); 89 writel(timeout, base + MMCIDATATIMER);
89 writel(host->size, base + MMCIDATALENGTH); 90 writel(host->size, base + MMCIDATALENGTH);
90 91
91 datactrl = MCI_DPSM_ENABLE | data->blksz_bits << 4; 92 blksz_bits = ffs(data->blksz) - 1;
93 BUG_ON(1 << blksz_bits != data->blksz);
94
95 datactrl = MCI_DPSM_ENABLE | blksz_bits << 4;
92 if (data->flags & MMC_DATA_READ) { 96 if (data->flags & MMC_DATA_READ) {
93 datactrl |= MCI_DPSM_DIRECTION; 97 datactrl |= MCI_DPSM_DIRECTION;
94 irqmask = MCI_RXFIFOHALFFULLMASK; 98 irqmask = MCI_RXFIFOHALFFULLMASK;
@@ -145,7 +149,7 @@ mmci_data_irq(struct mmci_host *host, struct mmc_data *data,
145 unsigned int status) 149 unsigned int status)
146{ 150{
147 if (status & MCI_DATABLOCKEND) { 151 if (status & MCI_DATABLOCKEND) {
148 host->data_xfered += 1 << data->blksz_bits; 152 host->data_xfered += data->blksz;
149 } 153 }
150 if (status & (MCI_DATACRCFAIL|MCI_DATATIMEOUT|MCI_TXUNDERRUN|MCI_RXOVERRUN)) { 154 if (status & (MCI_DATACRCFAIL|MCI_DATATIMEOUT|MCI_TXUNDERRUN|MCI_RXOVERRUN)) {
151 if (status & MCI_DATACRCFAIL) 155 if (status & MCI_DATACRCFAIL)
@@ -505,6 +509,7 @@ static int mmci_probe(struct amba_device *dev, void *id)
505 mmc->f_min = (host->mclk + 511) / 512; 509 mmc->f_min = (host->mclk + 511) / 512;
506 mmc->f_max = min(host->mclk, fmax); 510 mmc->f_max = min(host->mclk, fmax);
507 mmc->ocr_avail = plat->ocr_mask; 511 mmc->ocr_avail = plat->ocr_mask;
512 mmc->caps = MMC_CAP_MULTIWRITE;
508 513
509 /* 514 /*
510 * We can do SGIO 515 * We can do SGIO
diff --git a/drivers/mmc/omap.c b/drivers/mmc/omap.c
index ddf06b32c159..52c9e52e6b78 100644
--- a/drivers/mmc/omap.c
+++ b/drivers/mmc/omap.c
@@ -1034,13 +1034,14 @@ static int __init mmc_omap_probe(struct platform_device *pdev)
1034 host->irq = pdev->resource[1].start; 1034 host->irq = pdev->resource[1].start;
1035 host->base = (void __iomem*)IO_ADDRESS(r->start); 1035 host->base = (void __iomem*)IO_ADDRESS(r->start);
1036 1036
1037 if (minfo->wire4)
1038 mmc->caps |= MMC_CAP_4_BIT_DATA;
1039
1040 mmc->ops = &mmc_omap_ops; 1037 mmc->ops = &mmc_omap_ops;
1041 mmc->f_min = 400000; 1038 mmc->f_min = 400000;
1042 mmc->f_max = 24000000; 1039 mmc->f_max = 24000000;
1043 mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34; 1040 mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34;
1041 mmc->caps = MMC_CAP_BYTEBLOCK;
1042
1043 if (minfo->wire4)
1044 mmc->caps |= MMC_CAP_4_BIT_DATA;
1044 1045
1045 /* Use scatterlist DMA to reduce per-transfer costs. 1046 /* Use scatterlist DMA to reduce per-transfer costs.
1046 * NOTE max_seg_size assumption that small blocks aren't 1047 * NOTE max_seg_size assumption that small blocks aren't
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
index 4e21b3b9d330..4dab5ec392ea 100644
--- a/drivers/mmc/sdhci.c
+++ b/drivers/mmc/sdhci.c
@@ -4,8 +4,9 @@
4 * Copyright (C) 2005-2006 Pierre Ossman, All Rights Reserved. 4 * Copyright (C) 2005-2006 Pierre Ossman, All Rights Reserved.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
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 as published by
8 * published by the Free Software Foundation. 8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
9 */ 10 */
10 11
11#include <linux/delay.h> 12#include <linux/delay.h>
@@ -1262,7 +1263,7 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot)
1262 mmc->ops = &sdhci_ops; 1263 mmc->ops = &sdhci_ops;
1263 mmc->f_min = host->max_clk / 256; 1264 mmc->f_min = host->max_clk / 256;
1264 mmc->f_max = host->max_clk; 1265 mmc->f_max = host->max_clk;
1265 mmc->caps = MMC_CAP_4_BIT_DATA; 1266 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE | MMC_CAP_BYTEBLOCK;
1266 1267
1267 mmc->ocr_avail = 0; 1268 mmc->ocr_avail = 0;
1268 if (caps & SDHCI_CAN_VDD_330) 1269 if (caps & SDHCI_CAN_VDD_330)
diff --git a/drivers/mmc/sdhci.h b/drivers/mmc/sdhci.h
index f2453343f783..72a67937afe0 100644
--- a/drivers/mmc/sdhci.h
+++ b/drivers/mmc/sdhci.h
@@ -4,8 +4,9 @@
4 * Copyright (C) 2005 Pierre Ossman, All Rights Reserved. 4 * Copyright (C) 2005 Pierre Ossman, All Rights Reserved.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
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 as published by
8 * published by the Free Software Foundation. 8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
9 */ 10 */
10 11
11/* 12/*
diff --git a/drivers/mmc/wbsd.c b/drivers/mmc/wbsd.c
index c351c6d1a18a..88c6f0b129f5 100644
--- a/drivers/mmc/wbsd.c
+++ b/drivers/mmc/wbsd.c
@@ -4,8 +4,9 @@
4 * Copyright (C) 2004-2005 Pierre Ossman, All Rights Reserved. 4 * Copyright (C) 2004-2005 Pierre Ossman, All Rights Reserved.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
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 as published by
8 * published by the Free Software Foundation. 8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
9 * 10 *
10 * 11 *
11 * Warning! 12 * Warning!
@@ -1323,7 +1324,7 @@ static int __devinit wbsd_alloc_mmc(struct device *dev)
1323 mmc->f_min = 375000; 1324 mmc->f_min = 375000;
1324 mmc->f_max = 24000000; 1325 mmc->f_max = 24000000;
1325 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; 1326 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
1326 mmc->caps = MMC_CAP_4_BIT_DATA; 1327 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE | MMC_CAP_BYTEBLOCK;
1327 1328
1328 spin_lock_init(&host->lock); 1329 spin_lock_init(&host->lock);
1329 1330
diff --git a/drivers/mmc/wbsd.h b/drivers/mmc/wbsd.h
index 249baa701cb0..6072993f01e3 100644
--- a/drivers/mmc/wbsd.h
+++ b/drivers/mmc/wbsd.h
@@ -4,8 +4,9 @@
4 * Copyright (C) 2004-2005 Pierre Ossman, All Rights Reserved. 4 * Copyright (C) 2004-2005 Pierre Ossman, All Rights Reserved.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
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 as published by
8 * published by the Free Software Foundation. 8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
9 */ 10 */
10 11
11#define LOCK_CODE 0xAA 12#define LOCK_CODE 0xAA
diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index a03e862851db..a304b34c2632 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -166,7 +166,7 @@ config MTD_CHAR
166 166
167config MTD_BLOCK 167config MTD_BLOCK
168 tristate "Caching block device access to MTD devices" 168 tristate "Caching block device access to MTD devices"
169 depends on MTD 169 depends on MTD && BLOCK
170 ---help--- 170 ---help---
171 Although most flash chips have an erase size too large to be useful 171 Although most flash chips have an erase size too large to be useful
172 as block devices, it is possible to use MTD devices which are based 172 as block devices, it is possible to use MTD devices which are based
@@ -188,7 +188,7 @@ config MTD_BLOCK
188 188
189config MTD_BLOCK_RO 189config MTD_BLOCK_RO
190 tristate "Readonly block device access to MTD devices" 190 tristate "Readonly block device access to MTD devices"
191 depends on MTD_BLOCK!=y && MTD 191 depends on MTD_BLOCK!=y && MTD && BLOCK
192 help 192 help
193 This allows you to mount read-only file systems (such as cramfs) 193 This allows you to mount read-only file systems (such as cramfs)
194 from an MTD device, without the overhead (and danger) of the caching 194 from an MTD device, without the overhead (and danger) of the caching
@@ -199,7 +199,7 @@ config MTD_BLOCK_RO
199 199
200config FTL 200config FTL
201 tristate "FTL (Flash Translation Layer) support" 201 tristate "FTL (Flash Translation Layer) support"
202 depends on MTD 202 depends on MTD && BLOCK
203 ---help--- 203 ---help---
204 This provides support for the original Flash Translation Layer which 204 This provides support for the original Flash Translation Layer which
205 is part of the PCMCIA specification. It uses a kind of pseudo- 205 is part of the PCMCIA specification. It uses a kind of pseudo-
@@ -215,7 +215,7 @@ config FTL
215 215
216config NFTL 216config NFTL
217 tristate "NFTL (NAND Flash Translation Layer) support" 217 tristate "NFTL (NAND Flash Translation Layer) support"
218 depends on MTD 218 depends on MTD && BLOCK
219 ---help--- 219 ---help---
220 This provides support for the NAND Flash Translation Layer which is 220 This provides support for the NAND Flash Translation Layer which is
221 used on M-Systems' DiskOnChip devices. It uses a kind of pseudo- 221 used on M-Systems' DiskOnChip devices. It uses a kind of pseudo-
@@ -238,7 +238,7 @@ config NFTL_RW
238 238
239config INFTL 239config INFTL
240 tristate "INFTL (Inverse NAND Flash Translation Layer) support" 240 tristate "INFTL (Inverse NAND Flash Translation Layer) support"
241 depends on MTD 241 depends on MTD && BLOCK
242 ---help--- 242 ---help---
243 This provides support for the Inverse NAND Flash Translation 243 This provides support for the Inverse NAND Flash Translation
244 Layer which is used on M-Systems' newer DiskOnChip devices. It 244 Layer which is used on M-Systems' newer DiskOnChip devices. It
@@ -255,7 +255,7 @@ config INFTL
255 255
256config RFD_FTL 256config RFD_FTL
257 tristate "Resident Flash Disk (Flash Translation Layer) support" 257 tristate "Resident Flash Disk (Flash Translation Layer) support"
258 depends on MTD 258 depends on MTD && BLOCK
259 ---help--- 259 ---help---
260 This provides support for the flash translation layer known 260 This provides support for the flash translation layer known
261 as the Resident Flash Disk (RFD), as used by the Embedded BIOS 261 as the Resident Flash Disk (RFD), as used by the Embedded BIOS
diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig
index 16c02b5ccf7e..440f6851da69 100644
--- a/drivers/mtd/devices/Kconfig
+++ b/drivers/mtd/devices/Kconfig
@@ -136,7 +136,7 @@ config MTDRAM_ABS_POS
136 136
137config MTD_BLOCK2MTD 137config MTD_BLOCK2MTD
138 tristate "MTD using block device" 138 tristate "MTD using block device"
139 depends on MTD 139 depends on MTD && BLOCK
140 help 140 help
141 This driver allows a block device to appear as an MTD. It would 141 This driver allows a block device to appear as an MTD. It would
142 generally be used in the following cases: 142 generally be used in the following cases:
diff --git a/drivers/mtd/maps/arctic-mtd.c b/drivers/mtd/maps/arctic-mtd.c
index 642d96bc8919..2cc902436275 100644
--- a/drivers/mtd/maps/arctic-mtd.c
+++ b/drivers/mtd/maps/arctic-mtd.c
@@ -96,7 +96,7 @@ static struct mtd_partition arctic_partitions[PARTITIONS] = {
96static int __init 96static int __init
97init_arctic_mtd(void) 97init_arctic_mtd(void)
98{ 98{
99 int err = 0; 99 int err;
100 100
101 printk("%s: 0x%08x at 0x%08x\n", NAME, SIZE, PADDR); 101 printk("%s: 0x%08x at 0x%08x\n", NAME, SIZE, PADDR);
102 102
@@ -112,7 +112,7 @@ init_arctic_mtd(void)
112 arctic_mtd = do_map_probe("cfi_probe", &arctic_mtd_map); 112 arctic_mtd = do_map_probe("cfi_probe", &arctic_mtd_map);
113 113
114 if (!arctic_mtd) { 114 if (!arctic_mtd) {
115 iounmap((void *) arctic_mtd_map.virt); 115 iounmap(arctic_mtd_map.virt);
116 return -ENXIO; 116 return -ENXIO;
117 } 117 }
118 118
@@ -121,7 +121,7 @@ init_arctic_mtd(void)
121 err = add_mtd_partitions(arctic_mtd, arctic_partitions, PARTITIONS); 121 err = add_mtd_partitions(arctic_mtd, arctic_partitions, PARTITIONS);
122 if (err) { 122 if (err) {
123 printk("%s: add_mtd_partitions failed\n", NAME); 123 printk("%s: add_mtd_partitions failed\n", NAME);
124 iounmap((void *) arctic_mtd_map.virt); 124 iounmap(arctic_mtd_map.virt);
125 } 125 }
126 126
127 return err; 127 return err;
diff --git a/drivers/mtd/maps/beech-mtd.c b/drivers/mtd/maps/beech-mtd.c
index a64b1a5ab316..d76d5981b863 100644
--- a/drivers/mtd/maps/beech-mtd.c
+++ b/drivers/mtd/maps/beech-mtd.c
@@ -72,7 +72,7 @@ static struct mtd_partition beech_partitions[2] = {
72static int __init 72static int __init
73init_beech_mtd(void) 73init_beech_mtd(void)
74{ 74{
75 int err = 0; 75 int err;
76 76
77 printk("%s: 0x%08x at 0x%08x\n", NAME, SIZE, PADDR); 77 printk("%s: 0x%08x at 0x%08x\n", NAME, SIZE, PADDR);
78 78
@@ -89,7 +89,7 @@ init_beech_mtd(void)
89 beech_mtd = do_map_probe("cfi_probe", &beech_mtd_map); 89 beech_mtd = do_map_probe("cfi_probe", &beech_mtd_map);
90 90
91 if (!beech_mtd) { 91 if (!beech_mtd) {
92 iounmap((void *) beech_mtd_map.virt); 92 iounmap(beech_mtd_map.virt);
93 return -ENXIO; 93 return -ENXIO;
94 } 94 }
95 95
@@ -98,7 +98,7 @@ init_beech_mtd(void)
98 err = add_mtd_partitions(beech_mtd, beech_partitions, 2); 98 err = add_mtd_partitions(beech_mtd, beech_partitions, 2);
99 if (err) { 99 if (err) {
100 printk("%s: add_mtd_partitions failed\n", NAME); 100 printk("%s: add_mtd_partitions failed\n", NAME);
101 iounmap((void *) beech_mtd_map.virt); 101 iounmap(beech_mtd_map.virt);
102 } 102 }
103 103
104 return err; 104 return err;
diff --git a/drivers/mtd/maps/cstm_mips_ixx.c b/drivers/mtd/maps/cstm_mips_ixx.c
index d6bef100d69a..df2c38ef105a 100644
--- a/drivers/mtd/maps/cstm_mips_ixx.c
+++ b/drivers/mtd/maps/cstm_mips_ixx.c
@@ -175,8 +175,8 @@ int __init init_cstm_mips_ixx(void)
175 printk(KERN_WARNING "Failed to ioremap\n"); 175 printk(KERN_WARNING "Failed to ioremap\n");
176 for (j = 0; j < i; j++) { 176 for (j = 0; j < i; j++) {
177 if (cstm_mips_ixx_map[j].virt) { 177 if (cstm_mips_ixx_map[j].virt) {
178 iounmap((void *)cstm_mips_ixx_map[j].virt); 178 iounmap(cstm_mips_ixx_map[j].virt);
179 cstm_mips_ixx_map[j].virt = 0; 179 cstm_mips_ixx_map[j].virt = NULL;
180 } 180 }
181 } 181 }
182 return -EIO; 182 return -EIO;
@@ -214,8 +214,8 @@ int __init init_cstm_mips_ixx(void)
214 else { 214 else {
215 for (i = 0; i < PHYSMAP_NUMBER; i++) { 215 for (i = 0; i < PHYSMAP_NUMBER; i++) {
216 if (cstm_mips_ixx_map[i].virt) { 216 if (cstm_mips_ixx_map[i].virt) {
217 iounmap((void *)cstm_mips_ixx_map[i].virt); 217 iounmap(cstm_mips_ixx_map[i].virt);
218 cstm_mips_ixx_map[i].virt = 0; 218 cstm_mips_ixx_map[i].virt = NULL;
219 } 219 }
220 } 220 }
221 return -ENXIO; 221 return -ENXIO;
diff --git a/drivers/mtd/maps/nettel.c b/drivers/mtd/maps/nettel.c
index 198e840ff6db..f9e8e5bcbc33 100644
--- a/drivers/mtd/maps/nettel.c
+++ b/drivers/mtd/maps/nettel.c
@@ -463,7 +463,7 @@ int __init nettel_init(void)
463 463
464#ifdef CONFIG_MTD_CFI_INTELEXT 464#ifdef CONFIG_MTD_CFI_INTELEXT
465out_unmap1: 465out_unmap1:
466 iounmap((void *) nettel_intel_map.virt); 466 iounmap(nettel_intel_map.virt);
467#endif 467#endif
468 468
469out_unmap2: 469out_unmap2:
diff --git a/drivers/mtd/maps/redwood.c b/drivers/mtd/maps/redwood.c
index 2257d2b500c0..4d858b3d5f82 100644
--- a/drivers/mtd/maps/redwood.c
+++ b/drivers/mtd/maps/redwood.c
@@ -126,7 +126,7 @@ static struct mtd_info *redwood_mtd;
126 126
127int __init init_redwood_flash(void) 127int __init init_redwood_flash(void)
128{ 128{
129 int err = 0; 129 int err;
130 130
131 printk(KERN_NOTICE "redwood: flash mapping: %x at %x\n", 131 printk(KERN_NOTICE "redwood: flash mapping: %x at %x\n",
132 WINDOW_SIZE, WINDOW_ADDR); 132 WINDOW_SIZE, WINDOW_ADDR);
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 458d3c8ae1ee..178b53b56be9 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -46,7 +46,7 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
46 nsect = req->current_nr_sectors; 46 nsect = req->current_nr_sectors;
47 buf = req->buffer; 47 buf = req->buffer;
48 48
49 if (!(req->flags & REQ_CMD)) 49 if (!blk_fs_request(req))
50 return 0; 50 return 0;
51 51
52 if (block + nsect > get_capacity(req->rq_disk)) 52 if (block + nsect > get_capacity(req->rq_disk))
@@ -69,7 +69,7 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
69 return 1; 69 return 1;
70 70
71 default: 71 default:
72 printk(KERN_NOTICE "Unknown request %ld\n", rq_data_dir(req)); 72 printk(KERN_NOTICE "Unknown request %u\n", rq_data_dir(req));
73 return 0; 73 return 0;
74 } 74 }
75} 75}
diff --git a/drivers/mtd/nand/edb7312.c b/drivers/mtd/nand/edb7312.c
index 12017f3c6bd6..1daf8231aaef 100644
--- a/drivers/mtd/nand/edb7312.c
+++ b/drivers/mtd/nand/edb7312.c
@@ -199,7 +199,7 @@ static void __exit ep7312_cleanup(void)
199 nand_release(ap7312_mtd); 199 nand_release(ap7312_mtd);
200 200
201 /* Release io resource */ 201 /* Release io resource */
202 iounmap((void *)this->IO_ADDR_R); 202 iounmap(this->IO_ADDR_R);
203 203
204 /* Free the MTD device structure */ 204 /* Free the MTD device structure */
205 kfree(ep7312_mtd); 205 kfree(ep7312_mtd);
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 975b2ef61121..baece61169f4 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -415,7 +415,7 @@ static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip,
415 * Wait for the ready pin, after a command 415 * Wait for the ready pin, after a command
416 * The timeout is catched later. 416 * The timeout is catched later.
417 */ 417 */
418static void nand_wait_ready(struct mtd_info *mtd) 418void nand_wait_ready(struct mtd_info *mtd)
419{ 419{
420 struct nand_chip *chip = mtd->priv; 420 struct nand_chip *chip = mtd->priv;
421 unsigned long timeo = jiffies + 2; 421 unsigned long timeo = jiffies + 2;
@@ -429,6 +429,7 @@ static void nand_wait_ready(struct mtd_info *mtd)
429 } while (time_before(jiffies, timeo)); 429 } while (time_before(jiffies, timeo));
430 led_trigger_event(nand_led_trigger, LED_OFF); 430 led_trigger_event(nand_led_trigger, LED_OFF);
431} 431}
432EXPORT_SYMBOL_GPL(nand_wait_ready);
432 433
433/** 434/**
434 * nand_command - [DEFAULT] Send command to NAND device 435 * nand_command - [DEFAULT] Send command to NAND device
@@ -766,8 +767,8 @@ static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
766 int eccbytes = chip->ecc.bytes; 767 int eccbytes = chip->ecc.bytes;
767 int eccsteps = chip->ecc.steps; 768 int eccsteps = chip->ecc.steps;
768 uint8_t *p = buf; 769 uint8_t *p = buf;
769 uint8_t *ecc_calc = chip->buffers.ecccalc; 770 uint8_t *ecc_calc = chip->buffers->ecccalc;
770 uint8_t *ecc_code = chip->buffers.ecccode; 771 uint8_t *ecc_code = chip->buffers->ecccode;
771 int *eccpos = chip->ecc.layout->eccpos; 772 int *eccpos = chip->ecc.layout->eccpos;
772 773
773 nand_read_page_raw(mtd, chip, buf); 774 nand_read_page_raw(mtd, chip, buf);
@@ -808,8 +809,8 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
808 int eccbytes = chip->ecc.bytes; 809 int eccbytes = chip->ecc.bytes;
809 int eccsteps = chip->ecc.steps; 810 int eccsteps = chip->ecc.steps;
810 uint8_t *p = buf; 811 uint8_t *p = buf;
811 uint8_t *ecc_calc = chip->buffers.ecccalc; 812 uint8_t *ecc_calc = chip->buffers->ecccalc;
812 uint8_t *ecc_code = chip->buffers.ecccode; 813 uint8_t *ecc_code = chip->buffers->ecccode;
813 int *eccpos = chip->ecc.layout->eccpos; 814 int *eccpos = chip->ecc.layout->eccpos;
814 815
815 for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) { 816 for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
@@ -970,7 +971,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
970 page = realpage & chip->pagemask; 971 page = realpage & chip->pagemask;
971 972
972 col = (int)(from & (mtd->writesize - 1)); 973 col = (int)(from & (mtd->writesize - 1));
973 chip->oob_poi = chip->buffers.oobrbuf; 974 chip->oob_poi = chip->buffers->oobrbuf;
974 975
975 buf = ops->datbuf; 976 buf = ops->datbuf;
976 oob = ops->oobbuf; 977 oob = ops->oobbuf;
@@ -981,7 +982,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
981 982
982 /* Is the current page in the buffer ? */ 983 /* Is the current page in the buffer ? */
983 if (realpage != chip->pagebuf || oob) { 984 if (realpage != chip->pagebuf || oob) {
984 bufpoi = aligned ? buf : chip->buffers.databuf; 985 bufpoi = aligned ? buf : chip->buffers->databuf;
985 986
986 if (likely(sndcmd)) { 987 if (likely(sndcmd)) {
987 chip->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page); 988 chip->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page);
@@ -989,14 +990,17 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
989 } 990 }
990 991
991 /* Now read the page into the buffer */ 992 /* Now read the page into the buffer */
992 ret = chip->ecc.read_page(mtd, chip, bufpoi); 993 if (unlikely(ops->mode == MTD_OOB_RAW))
994 ret = chip->ecc.read_page_raw(mtd, chip, bufpoi);
995 else
996 ret = chip->ecc.read_page(mtd, chip, bufpoi);
993 if (ret < 0) 997 if (ret < 0)
994 break; 998 break;
995 999
996 /* Transfer not aligned data */ 1000 /* Transfer not aligned data */
997 if (!aligned) { 1001 if (!aligned) {
998 chip->pagebuf = realpage; 1002 chip->pagebuf = realpage;
999 memcpy(buf, chip->buffers.databuf + col, bytes); 1003 memcpy(buf, chip->buffers->databuf + col, bytes);
1000 } 1004 }
1001 1005
1002 buf += bytes; 1006 buf += bytes;
@@ -1023,7 +1027,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1023 nand_wait_ready(mtd); 1027 nand_wait_ready(mtd);
1024 } 1028 }
1025 } else { 1029 } else {
1026 memcpy(buf, chip->buffers.databuf + col, bytes); 1030 memcpy(buf, chip->buffers->databuf + col, bytes);
1027 buf += bytes; 1031 buf += bytes;
1028 } 1032 }
1029 1033
@@ -1266,7 +1270,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1266 realpage = (int)(from >> chip->page_shift); 1270 realpage = (int)(from >> chip->page_shift);
1267 page = realpage & chip->pagemask; 1271 page = realpage & chip->pagemask;
1268 1272
1269 chip->oob_poi = chip->buffers.oobrbuf; 1273 chip->oob_poi = chip->buffers->oobrbuf;
1270 1274
1271 while(1) { 1275 while(1) {
1272 sndcmd = chip->ecc.read_oob(mtd, chip, page, sndcmd); 1276 sndcmd = chip->ecc.read_oob(mtd, chip, page, sndcmd);
@@ -1322,8 +1326,6 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1322static int nand_read_oob(struct mtd_info *mtd, loff_t from, 1326static int nand_read_oob(struct mtd_info *mtd, loff_t from,
1323 struct mtd_oob_ops *ops) 1327 struct mtd_oob_ops *ops)
1324{ 1328{
1325 int (*read_page)(struct mtd_info *mtd, struct nand_chip *chip,
1326 uint8_t *buf) = NULL;
1327 struct nand_chip *chip = mtd->priv; 1329 struct nand_chip *chip = mtd->priv;
1328 int ret = -ENOTSUPP; 1330 int ret = -ENOTSUPP;
1329 1331
@@ -1341,12 +1343,7 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from,
1341 switch(ops->mode) { 1343 switch(ops->mode) {
1342 case MTD_OOB_PLACE: 1344 case MTD_OOB_PLACE:
1343 case MTD_OOB_AUTO: 1345 case MTD_OOB_AUTO:
1344 break;
1345
1346 case MTD_OOB_RAW: 1346 case MTD_OOB_RAW:
1347 /* Replace the read_page algorithm temporary */
1348 read_page = chip->ecc.read_page;
1349 chip->ecc.read_page = nand_read_page_raw;
1350 break; 1347 break;
1351 1348
1352 default: 1349 default:
@@ -1358,8 +1355,6 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from,
1358 else 1355 else
1359 ret = nand_do_read_ops(mtd, from, ops); 1356 ret = nand_do_read_ops(mtd, from, ops);
1360 1357
1361 if (unlikely(ops->mode == MTD_OOB_RAW))
1362 chip->ecc.read_page = read_page;
1363 out: 1358 out:
1364 nand_release_device(mtd); 1359 nand_release_device(mtd);
1365 return ret; 1360 return ret;
@@ -1391,7 +1386,7 @@ static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
1391 int i, eccsize = chip->ecc.size; 1386 int i, eccsize = chip->ecc.size;
1392 int eccbytes = chip->ecc.bytes; 1387 int eccbytes = chip->ecc.bytes;
1393 int eccsteps = chip->ecc.steps; 1388 int eccsteps = chip->ecc.steps;
1394 uint8_t *ecc_calc = chip->buffers.ecccalc; 1389 uint8_t *ecc_calc = chip->buffers->ecccalc;
1395 const uint8_t *p = buf; 1390 const uint8_t *p = buf;
1396 int *eccpos = chip->ecc.layout->eccpos; 1391 int *eccpos = chip->ecc.layout->eccpos;
1397 1392
@@ -1417,7 +1412,7 @@ static void nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
1417 int i, eccsize = chip->ecc.size; 1412 int i, eccsize = chip->ecc.size;
1418 int eccbytes = chip->ecc.bytes; 1413 int eccbytes = chip->ecc.bytes;
1419 int eccsteps = chip->ecc.steps; 1414 int eccsteps = chip->ecc.steps;
1420 uint8_t *ecc_calc = chip->buffers.ecccalc; 1415 uint8_t *ecc_calc = chip->buffers->ecccalc;
1421 const uint8_t *p = buf; 1416 const uint8_t *p = buf;
1422 int *eccpos = chip->ecc.layout->eccpos; 1417 int *eccpos = chip->ecc.layout->eccpos;
1423 1418
@@ -1478,7 +1473,7 @@ static void nand_write_page_syndrome(struct mtd_info *mtd,
1478} 1473}
1479 1474
1480/** 1475/**
1481 * nand_write_page - [INTERNAL] write one page 1476 * nand_write_page - [REPLACEABLE] write one page
1482 * @mtd: MTD device structure 1477 * @mtd: MTD device structure
1483 * @chip: NAND chip descriptor 1478 * @chip: NAND chip descriptor
1484 * @buf: the data to write 1479 * @buf: the data to write
@@ -1486,13 +1481,16 @@ static void nand_write_page_syndrome(struct mtd_info *mtd,
1486 * @cached: cached programming 1481 * @cached: cached programming
1487 */ 1482 */
1488static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, 1483static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
1489 const uint8_t *buf, int page, int cached) 1484 const uint8_t *buf, int page, int cached, int raw)
1490{ 1485{
1491 int status; 1486 int status;
1492 1487
1493 chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page); 1488 chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
1494 1489
1495 chip->ecc.write_page(mtd, chip, buf); 1490 if (unlikely(raw))
1491 chip->ecc.write_page_raw(mtd, chip, buf);
1492 else
1493 chip->ecc.write_page(mtd, chip, buf);
1496 1494
1497 /* 1495 /*
1498 * Cached progamming disabled for now, Not sure if its worth the 1496 * Cached progamming disabled for now, Not sure if its worth the
@@ -1627,7 +1625,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
1627 (chip->pagebuf << chip->page_shift) < (to + ops->len)) 1625 (chip->pagebuf << chip->page_shift) < (to + ops->len))
1628 chip->pagebuf = -1; 1626 chip->pagebuf = -1;
1629 1627
1630 chip->oob_poi = chip->buffers.oobwbuf; 1628 chip->oob_poi = chip->buffers->oobwbuf;
1631 1629
1632 while(1) { 1630 while(1) {
1633 int cached = writelen > bytes && page != blockmask; 1631 int cached = writelen > bytes && page != blockmask;
@@ -1635,7 +1633,8 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
1635 if (unlikely(oob)) 1633 if (unlikely(oob))
1636 oob = nand_fill_oob(chip, oob, ops); 1634 oob = nand_fill_oob(chip, oob, ops);
1637 1635
1638 ret = nand_write_page(mtd, chip, buf, page, cached); 1636 ret = chip->write_page(mtd, chip, buf, page, cached,
1637 (ops->mode == MTD_OOB_RAW));
1639 if (ret) 1638 if (ret)
1640 break; 1639 break;
1641 1640
@@ -1745,7 +1744,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
1745 if (page == chip->pagebuf) 1744 if (page == chip->pagebuf)
1746 chip->pagebuf = -1; 1745 chip->pagebuf = -1;
1747 1746
1748 chip->oob_poi = chip->buffers.oobwbuf; 1747 chip->oob_poi = chip->buffers->oobwbuf;
1749 memset(chip->oob_poi, 0xff, mtd->oobsize); 1748 memset(chip->oob_poi, 0xff, mtd->oobsize);
1750 nand_fill_oob(chip, ops->oobbuf, ops); 1749 nand_fill_oob(chip, ops->oobbuf, ops);
1751 status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask); 1750 status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask);
@@ -1768,8 +1767,6 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
1768static int nand_write_oob(struct mtd_info *mtd, loff_t to, 1767static int nand_write_oob(struct mtd_info *mtd, loff_t to,
1769 struct mtd_oob_ops *ops) 1768 struct mtd_oob_ops *ops)
1770{ 1769{
1771 void (*write_page)(struct mtd_info *mtd, struct nand_chip *chip,
1772 const uint8_t *buf) = NULL;
1773 struct nand_chip *chip = mtd->priv; 1770 struct nand_chip *chip = mtd->priv;
1774 int ret = -ENOTSUPP; 1771 int ret = -ENOTSUPP;
1775 1772
@@ -1787,12 +1784,7 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to,
1787 switch(ops->mode) { 1784 switch(ops->mode) {
1788 case MTD_OOB_PLACE: 1785 case MTD_OOB_PLACE:
1789 case MTD_OOB_AUTO: 1786 case MTD_OOB_AUTO:
1790 break;
1791
1792 case MTD_OOB_RAW: 1787 case MTD_OOB_RAW:
1793 /* Replace the write_page algorithm temporary */
1794 write_page = chip->ecc.write_page;
1795 chip->ecc.write_page = nand_write_page_raw;
1796 break; 1788 break;
1797 1789
1798 default: 1790 default:
@@ -1804,8 +1796,6 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to,
1804 else 1796 else
1805 ret = nand_do_write_ops(mtd, to, ops); 1797 ret = nand_do_write_ops(mtd, to, ops);
1806 1798
1807 if (unlikely(ops->mode == MTD_OOB_RAW))
1808 chip->ecc.write_page = write_page;
1809 out: 1799 out:
1810 nand_release_device(mtd); 1800 nand_release_device(mtd);
1811 return ret; 1801 return ret;
@@ -2288,40 +2278,22 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2288 return type; 2278 return type;
2289} 2279}
2290 2280
2291/* module_text_address() isn't exported, and it's mostly a pointless
2292 test if this is a module _anyway_ -- they'd have to try _really_ hard
2293 to call us from in-kernel code if the core NAND support is modular. */
2294#ifdef MODULE
2295#define caller_is_module() (1)
2296#else
2297#define caller_is_module() \
2298 module_text_address((unsigned long)__builtin_return_address(0))
2299#endif
2300
2301/** 2281/**
2302 * nand_scan - [NAND Interface] Scan for the NAND device 2282 * nand_scan_ident - [NAND Interface] Scan for the NAND device
2303 * @mtd: MTD device structure 2283 * @mtd: MTD device structure
2304 * @maxchips: Number of chips to scan for 2284 * @maxchips: Number of chips to scan for
2305 * 2285 *
2306 * This fills out all the uninitialized function pointers 2286 * This is the first phase of the normal nand_scan() function. It
2307 * with the defaults. 2287 * reads the flash ID and sets up MTD fields accordingly.
2308 * The flash ID is read and the mtd/chip structures are
2309 * filled with the appropriate values.
2310 * The mtd->owner field must be set to the module of the caller
2311 * 2288 *
2289 * The mtd->owner field must be set to the module of the caller.
2312 */ 2290 */
2313int nand_scan(struct mtd_info *mtd, int maxchips) 2291int nand_scan_ident(struct mtd_info *mtd, int maxchips)
2314{ 2292{
2315 int i, busw, nand_maf_id; 2293 int i, busw, nand_maf_id;
2316 struct nand_chip *chip = mtd->priv; 2294 struct nand_chip *chip = mtd->priv;
2317 struct nand_flash_dev *type; 2295 struct nand_flash_dev *type;
2318 2296
2319 /* Many callers got this wrong, so check for it for a while... */
2320 if (!mtd->owner && caller_is_module()) {
2321 printk(KERN_CRIT "nand_scan() called with NULL mtd->owner!\n");
2322 BUG();
2323 }
2324
2325 /* Get buswidth to select the correct functions */ 2297 /* Get buswidth to select the correct functions */
2326 busw = chip->options & NAND_BUSWIDTH_16; 2298 busw = chip->options & NAND_BUSWIDTH_16;
2327 /* Set the default functions */ 2299 /* Set the default functions */
@@ -2353,8 +2325,31 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
2353 chip->numchips = i; 2325 chip->numchips = i;
2354 mtd->size = i * chip->chipsize; 2326 mtd->size = i * chip->chipsize;
2355 2327
2328 return 0;
2329}
2330
2331
2332/**
2333 * nand_scan_tail - [NAND Interface] Scan for the NAND device
2334 * @mtd: MTD device structure
2335 * @maxchips: Number of chips to scan for
2336 *
2337 * This is the second phase of the normal nand_scan() function. It
2338 * fills out all the uninitialized function pointers with the defaults
2339 * and scans for a bad block table if appropriate.
2340 */
2341int nand_scan_tail(struct mtd_info *mtd)
2342{
2343 int i;
2344 struct nand_chip *chip = mtd->priv;
2345
2346 if (!(chip->options & NAND_OWN_BUFFERS))
2347 chip->buffers = kmalloc(sizeof(*chip->buffers), GFP_KERNEL);
2348 if (!chip->buffers)
2349 return -ENOMEM;
2350
2356 /* Preset the internal oob write buffer */ 2351 /* Preset the internal oob write buffer */
2357 memset(chip->buffers.oobwbuf, 0xff, mtd->oobsize); 2352 memset(chip->buffers->oobwbuf, 0xff, mtd->oobsize);
2358 2353
2359 /* 2354 /*
2360 * If no default placement scheme is given, select an appropriate one 2355 * If no default placement scheme is given, select an appropriate one
@@ -2377,10 +2372,18 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
2377 } 2372 }
2378 } 2373 }
2379 2374
2375 if (!chip->write_page)
2376 chip->write_page = nand_write_page;
2377
2380 /* 2378 /*
2381 * check ECC mode, default to software if 3byte/512byte hardware ECC is 2379 * check ECC mode, default to software if 3byte/512byte hardware ECC is
2382 * selected and we have 256 byte pagesize fallback to software ECC 2380 * selected and we have 256 byte pagesize fallback to software ECC
2383 */ 2381 */
2382 if (!chip->ecc.read_page_raw)
2383 chip->ecc.read_page_raw = nand_read_page_raw;
2384 if (!chip->ecc.write_page_raw)
2385 chip->ecc.write_page_raw = nand_write_page_raw;
2386
2384 switch (chip->ecc.mode) { 2387 switch (chip->ecc.mode) {
2385 case NAND_ECC_HW: 2388 case NAND_ECC_HW:
2386 /* Use standard hwecc read page function ? */ 2389 /* Use standard hwecc read page function ? */
@@ -2438,6 +2441,7 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
2438 chip->ecc.size = mtd->writesize; 2441 chip->ecc.size = mtd->writesize;
2439 chip->ecc.bytes = 0; 2442 chip->ecc.bytes = 0;
2440 break; 2443 break;
2444
2441 default: 2445 default:
2442 printk(KERN_WARNING "Invalid NAND_ECC_MODE %d\n", 2446 printk(KERN_WARNING "Invalid NAND_ECC_MODE %d\n",
2443 chip->ecc.mode); 2447 chip->ecc.mode);
@@ -2503,6 +2507,44 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
2503 return chip->scan_bbt(mtd); 2507 return chip->scan_bbt(mtd);
2504} 2508}
2505 2509
2510/* module_text_address() isn't exported, and it's mostly a pointless
2511 test if this is a module _anyway_ -- they'd have to try _really_ hard
2512 to call us from in-kernel code if the core NAND support is modular. */
2513#ifdef MODULE
2514#define caller_is_module() (1)
2515#else
2516#define caller_is_module() \
2517 module_text_address((unsigned long)__builtin_return_address(0))
2518#endif
2519
2520/**
2521 * nand_scan - [NAND Interface] Scan for the NAND device
2522 * @mtd: MTD device structure
2523 * @maxchips: Number of chips to scan for
2524 *
2525 * This fills out all the uninitialized function pointers
2526 * with the defaults.
2527 * The flash ID is read and the mtd/chip structures are
2528 * filled with the appropriate values.
2529 * The mtd->owner field must be set to the module of the caller
2530 *
2531 */
2532int nand_scan(struct mtd_info *mtd, int maxchips)
2533{
2534 int ret;
2535
2536 /* Many callers got this wrong, so check for it for a while... */
2537 if (!mtd->owner && caller_is_module()) {
2538 printk(KERN_CRIT "nand_scan() called with NULL mtd->owner!\n");
2539 BUG();
2540 }
2541
2542 ret = nand_scan_ident(mtd, maxchips);
2543 if (!ret)
2544 ret = nand_scan_tail(mtd);
2545 return ret;
2546}
2547
2506/** 2548/**
2507 * nand_release - [NAND Interface] Free resources held by the NAND device 2549 * nand_release - [NAND Interface] Free resources held by the NAND device
2508 * @mtd: MTD device structure 2550 * @mtd: MTD device structure
@@ -2520,9 +2562,13 @@ void nand_release(struct mtd_info *mtd)
2520 2562
2521 /* Free bad block table memory */ 2563 /* Free bad block table memory */
2522 kfree(chip->bbt); 2564 kfree(chip->bbt);
2565 if (!(chip->options & NAND_OWN_BUFFERS))
2566 kfree(chip->buffers);
2523} 2567}
2524 2568
2525EXPORT_SYMBOL_GPL(nand_scan); 2569EXPORT_SYMBOL_GPL(nand_scan);
2570EXPORT_SYMBOL_GPL(nand_scan_ident);
2571EXPORT_SYMBOL_GPL(nand_scan_tail);
2526EXPORT_SYMBOL_GPL(nand_release); 2572EXPORT_SYMBOL_GPL(nand_release);
2527 2573
2528static int __init nand_base_init(void) 2574static int __init nand_base_init(void)
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index a612c4ea8194..9402653eb09b 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -759,7 +759,7 @@ static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *b
759 struct nand_chip *this = mtd->priv; 759 struct nand_chip *this = mtd->priv;
760 760
761 bd->options &= ~NAND_BBT_SCANEMPTY; 761 bd->options &= ~NAND_BBT_SCANEMPTY;
762 return create_bbt(mtd, this->buffers.databuf, bd, -1); 762 return create_bbt(mtd, this->buffers->databuf, bd, -1);
763} 763}
764 764
765/** 765/**
diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
index dd5cea8b4a7a..b5a5f8da4722 100644
--- a/drivers/mtd/nftlcore.c
+++ b/drivers/mtd/nftlcore.c
@@ -175,6 +175,8 @@ int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
175 return res; 175 return res;
176} 176}
177 177
178#ifdef CONFIG_NFTL_RW
179
178/* 180/*
179 * Write data and oob to flash 181 * Write data and oob to flash
180 */ 182 */
@@ -196,8 +198,6 @@ static int nftl_write(struct mtd_info *mtd, loff_t offs, size_t len,
196 return res; 198 return res;
197} 199}
198 200
199#ifdef CONFIG_NFTL_RW
200
201/* Actual NFTL access routines */ 201/* Actual NFTL access routines */
202/* NFTL_findfreeblock: Find a free Erase Unit on the NFTL partition. This function is used 202/* NFTL_findfreeblock: Find a free Erase Unit on the NFTL partition. This function is used
203 * when the give Virtual Unit Chain 203 * when the give Virtual Unit Chain
diff --git a/drivers/mtd/onenand/Kconfig b/drivers/mtd/onenand/Kconfig
index 5930a03736d7..465961b8bcd1 100644
--- a/drivers/mtd/onenand/Kconfig
+++ b/drivers/mtd/onenand/Kconfig
@@ -43,10 +43,4 @@ config MTD_ONENAND_OTP
43 43
44 OTP block is fully-guaranteed to be a valid block. 44 OTP block is fully-guaranteed to be a valid block.
45 45
46config MTD_ONENAND_SYNC_READ
47 bool "OneNAND Sync. Burst Read Support"
48 depends on ARCH_OMAP
49 help
50 This enables support for Sync. Burst Read.
51
52endmenu 46endmenu
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index 84ec40d25438..8ed68b28afe3 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * linux/drivers/mtd/onenand/onenand_base.c 2 * linux/drivers/mtd/onenand/onenand_base.c
3 * 3 *
4 * Copyright (C) 2005 Samsung Electronics 4 * Copyright (C) 2005-2006 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com> 5 * Kyungmin Park <kyungmin.park@samsung.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
@@ -199,6 +199,7 @@ static int onenand_command(struct mtd_info *mtd, int cmd, loff_t addr, size_t le
199 case ONENAND_CMD_UNLOCK: 199 case ONENAND_CMD_UNLOCK:
200 case ONENAND_CMD_LOCK: 200 case ONENAND_CMD_LOCK:
201 case ONENAND_CMD_LOCK_TIGHT: 201 case ONENAND_CMD_LOCK_TIGHT:
202 case ONENAND_CMD_UNLOCK_ALL:
202 block = -1; 203 block = -1;
203 page = -1; 204 page = -1;
204 break; 205 break;
@@ -1211,11 +1212,11 @@ static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1211 end = len >> this->erase_shift; 1212 end = len >> this->erase_shift;
1212 1213
1213 /* Continuous lock scheme */ 1214 /* Continuous lock scheme */
1214 if (this->options & ONENAND_CONT_LOCK) { 1215 if (this->options & ONENAND_HAS_CONT_LOCK) {
1215 /* Set start block address */ 1216 /* Set start block address */
1216 this->write_word(start, this->base + ONENAND_REG_START_BLOCK_ADDRESS); 1217 this->write_word(start, this->base + ONENAND_REG_START_BLOCK_ADDRESS);
1217 /* Set end block address */ 1218 /* Set end block address */
1218 this->write_word(end - 1, this->base + ONENAND_REG_END_BLOCK_ADDRESS); 1219 this->write_word(start + end - 1, this->base + ONENAND_REG_END_BLOCK_ADDRESS);
1219 /* Write unlock command */ 1220 /* Write unlock command */
1220 this->command(mtd, ONENAND_CMD_UNLOCK, 0, 0); 1221 this->command(mtd, ONENAND_CMD_UNLOCK, 0, 0);
1221 1222
@@ -1236,7 +1237,7 @@ static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1236 } 1237 }
1237 1238
1238 /* Block lock scheme */ 1239 /* Block lock scheme */
1239 for (block = start; block < end; block++) { 1240 for (block = start; block < start + end; block++) {
1240 /* Set block address */ 1241 /* Set block address */
1241 value = onenand_block_address(this, block); 1242 value = onenand_block_address(this, block);
1242 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS1); 1243 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS1);
@@ -1265,6 +1266,79 @@ static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1265 return 0; 1266 return 0;
1266} 1267}
1267 1268
1269/**
1270 * onenand_check_lock_status - [OneNAND Interface] Check lock status
1271 * @param this onenand chip data structure
1272 *
1273 * Check lock status
1274 */
1275static void onenand_check_lock_status(struct onenand_chip *this)
1276{
1277 unsigned int value, block, status;
1278 unsigned int end;
1279
1280 end = this->chipsize >> this->erase_shift;
1281 for (block = 0; block < end; block++) {
1282 /* Set block address */
1283 value = onenand_block_address(this, block);
1284 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS1);
1285 /* Select DataRAM for DDP */
1286 value = onenand_bufferram_address(this, block);
1287 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2);
1288 /* Set start block address */
1289 this->write_word(block, this->base + ONENAND_REG_START_BLOCK_ADDRESS);
1290
1291 /* Check lock status */
1292 status = this->read_word(this->base + ONENAND_REG_WP_STATUS);
1293 if (!(status & ONENAND_WP_US))
1294 printk(KERN_ERR "block = %d, wp status = 0x%x\n", block, status);
1295 }
1296}
1297
1298/**
1299 * onenand_unlock_all - [OneNAND Interface] unlock all blocks
1300 * @param mtd MTD device structure
1301 *
1302 * Unlock all blocks
1303 */
1304static int onenand_unlock_all(struct mtd_info *mtd)
1305{
1306 struct onenand_chip *this = mtd->priv;
1307
1308 if (this->options & ONENAND_HAS_UNLOCK_ALL) {
1309 /* Write unlock command */
1310 this->command(mtd, ONENAND_CMD_UNLOCK_ALL, 0, 0);
1311
1312 /* There's no return value */
1313 this->wait(mtd, FL_UNLOCKING);
1314
1315 /* Sanity check */
1316 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS)
1317 & ONENAND_CTRL_ONGO)
1318 continue;
1319
1320 /* Workaround for all block unlock in DDP */
1321 if (this->device_id & ONENAND_DEVICE_IS_DDP) {
1322 loff_t ofs;
1323 size_t len;
1324
1325 /* 1st block on another chip */
1326 ofs = this->chipsize >> 1;
1327 len = 1 << this->erase_shift;
1328
1329 onenand_unlock(mtd, ofs, len);
1330 }
1331
1332 onenand_check_lock_status(this);
1333
1334 return 0;
1335 }
1336
1337 mtd->unlock(mtd, 0x0, this->chipsize);
1338
1339 return 0;
1340}
1341
1268#ifdef CONFIG_MTD_ONENAND_OTP 1342#ifdef CONFIG_MTD_ONENAND_OTP
1269 1343
1270/* Interal OTP operation */ 1344/* Interal OTP operation */
@@ -1564,12 +1638,43 @@ static int onenand_lock_user_prot_reg(struct mtd_info *mtd, loff_t from,
1564#endif /* CONFIG_MTD_ONENAND_OTP */ 1638#endif /* CONFIG_MTD_ONENAND_OTP */
1565 1639
1566/** 1640/**
1641 * onenand_lock_scheme - Check and set OneNAND lock scheme
1642 * @param mtd MTD data structure
1643 *
1644 * Check and set OneNAND lock scheme
1645 */
1646static void onenand_lock_scheme(struct mtd_info *mtd)
1647{
1648 struct onenand_chip *this = mtd->priv;
1649 unsigned int density, process;
1650
1651 /* Lock scheme depends on density and process */
1652 density = this->device_id >> ONENAND_DEVICE_DENSITY_SHIFT;
1653 process = this->version_id >> ONENAND_VERSION_PROCESS_SHIFT;
1654
1655 /* Lock scheme */
1656 if (density >= ONENAND_DEVICE_DENSITY_1Gb) {
1657 /* A-Die has all block unlock */
1658 if (process) {
1659 printk(KERN_DEBUG "Chip support all block unlock\n");
1660 this->options |= ONENAND_HAS_UNLOCK_ALL;
1661 }
1662 } else {
1663 /* Some OneNAND has continues lock scheme */
1664 if (!process) {
1665 printk(KERN_DEBUG "Lock scheme is Continues Lock\n");
1666 this->options |= ONENAND_HAS_CONT_LOCK;
1667 }
1668 }
1669}
1670
1671/**
1567 * onenand_print_device_info - Print device ID 1672 * onenand_print_device_info - Print device ID
1568 * @param device device ID 1673 * @param device device ID
1569 * 1674 *
1570 * Print device ID 1675 * Print device ID
1571 */ 1676 */
1572static void onenand_print_device_info(int device) 1677static void onenand_print_device_info(int device, int version)
1573{ 1678{
1574 int vcc, demuxed, ddp, density; 1679 int vcc, demuxed, ddp, density;
1575 1680
@@ -1583,6 +1688,7 @@ static void onenand_print_device_info(int device)
1583 (16 << density), 1688 (16 << density),
1584 vcc ? "2.65/3.3" : "1.8", 1689 vcc ? "2.65/3.3" : "1.8",
1585 device); 1690 device);
1691 printk(KERN_DEBUG "OneNAND version = 0x%04x\n", version);
1586} 1692}
1587 1693
1588static const struct onenand_manufacturers onenand_manuf_ids[] = { 1694static const struct onenand_manufacturers onenand_manuf_ids[] = {
@@ -1625,9 +1731,14 @@ static int onenand_check_maf(int manuf)
1625static int onenand_probe(struct mtd_info *mtd) 1731static int onenand_probe(struct mtd_info *mtd)
1626{ 1732{
1627 struct onenand_chip *this = mtd->priv; 1733 struct onenand_chip *this = mtd->priv;
1628 int bram_maf_id, bram_dev_id, maf_id, dev_id; 1734 int bram_maf_id, bram_dev_id, maf_id, dev_id, ver_id;
1629 int version_id;
1630 int density; 1735 int density;
1736 int syscfg;
1737
1738 /* Save system configuration 1 */
1739 syscfg = this->read_word(this->base + ONENAND_REG_SYS_CFG1);
1740 /* Clear Sync. Burst Read mode to read BootRAM */
1741 this->write_word((syscfg & ~ONENAND_SYS_CFG1_SYNC_READ), this->base + ONENAND_REG_SYS_CFG1);
1631 1742
1632 /* Send the command for reading device ID from BootRAM */ 1743 /* Send the command for reading device ID from BootRAM */
1633 this->write_word(ONENAND_CMD_READID, this->base + ONENAND_BOOTRAM); 1744 this->write_word(ONENAND_CMD_READID, this->base + ONENAND_BOOTRAM);
@@ -1636,24 +1747,31 @@ static int onenand_probe(struct mtd_info *mtd)
1636 bram_maf_id = this->read_word(this->base + ONENAND_BOOTRAM + 0x0); 1747 bram_maf_id = this->read_word(this->base + ONENAND_BOOTRAM + 0x0);
1637 bram_dev_id = this->read_word(this->base + ONENAND_BOOTRAM + 0x2); 1748 bram_dev_id = this->read_word(this->base + ONENAND_BOOTRAM + 0x2);
1638 1749
1750 /* Reset OneNAND to read default register values */
1751 this->write_word(ONENAND_CMD_RESET, this->base + ONENAND_BOOTRAM);
1752 /* Wait reset */
1753 this->wait(mtd, FL_RESETING);
1754
1755 /* Restore system configuration 1 */
1756 this->write_word(syscfg, this->base + ONENAND_REG_SYS_CFG1);
1757
1639 /* Check manufacturer ID */ 1758 /* Check manufacturer ID */
1640 if (onenand_check_maf(bram_maf_id)) 1759 if (onenand_check_maf(bram_maf_id))
1641 return -ENXIO; 1760 return -ENXIO;
1642 1761
1643 /* Reset OneNAND to read default register values */
1644 this->write_word(ONENAND_CMD_RESET, this->base + ONENAND_BOOTRAM);
1645
1646 /* Read manufacturer and device IDs from Register */ 1762 /* Read manufacturer and device IDs from Register */
1647 maf_id = this->read_word(this->base + ONENAND_REG_MANUFACTURER_ID); 1763 maf_id = this->read_word(this->base + ONENAND_REG_MANUFACTURER_ID);
1648 dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID); 1764 dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID);
1765 ver_id= this->read_word(this->base + ONENAND_REG_VERSION_ID);
1649 1766
1650 /* Check OneNAND device */ 1767 /* Check OneNAND device */
1651 if (maf_id != bram_maf_id || dev_id != bram_dev_id) 1768 if (maf_id != bram_maf_id || dev_id != bram_dev_id)
1652 return -ENXIO; 1769 return -ENXIO;
1653 1770
1654 /* Flash device information */ 1771 /* Flash device information */
1655 onenand_print_device_info(dev_id); 1772 onenand_print_device_info(dev_id, ver_id);
1656 this->device_id = dev_id; 1773 this->device_id = dev_id;
1774 this->version_id = ver_id;
1657 1775
1658 density = dev_id >> ONENAND_DEVICE_DENSITY_SHIFT; 1776 density = dev_id >> ONENAND_DEVICE_DENSITY_SHIFT;
1659 this->chipsize = (16 << density) << 20; 1777 this->chipsize = (16 << density) << 20;
@@ -1676,16 +1794,8 @@ static int onenand_probe(struct mtd_info *mtd)
1676 1794
1677 mtd->size = this->chipsize; 1795 mtd->size = this->chipsize;
1678 1796
1679 /* Version ID */ 1797 /* Check OneNAND lock scheme */
1680 version_id = this->read_word(this->base + ONENAND_REG_VERSION_ID); 1798 onenand_lock_scheme(mtd);
1681 printk(KERN_DEBUG "OneNAND version = 0x%04x\n", version_id);
1682
1683 /* Lock scheme */
1684 if (density <= ONENAND_DEVICE_DENSITY_512Mb &&
1685 !(version_id >> ONENAND_VERSION_PROCESS_SHIFT)) {
1686 printk(KERN_INFO "Lock scheme is Continues Lock\n");
1687 this->options |= ONENAND_CONT_LOCK;
1688 }
1689 1799
1690 return 0; 1800 return 0;
1691} 1801}
@@ -1821,7 +1931,7 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
1821 mtd->owner = THIS_MODULE; 1931 mtd->owner = THIS_MODULE;
1822 1932
1823 /* Unlock whole block */ 1933 /* Unlock whole block */
1824 mtd->unlock(mtd, 0x0, this->chipsize); 1934 onenand_unlock_all(mtd);
1825 1935
1826 return this->scan_bbt(mtd); 1936 return this->scan_bbt(mtd);
1827} 1937}
diff --git a/drivers/net/3c509.c b/drivers/net/3c509.c
index 59c33925be62..b936373ab2a5 100644
--- a/drivers/net/3c509.c
+++ b/drivers/net/3c509.c
@@ -225,6 +225,7 @@ static struct eisa_device_id el3_eisa_ids[] = {
225 { "TCM5095" }, 225 { "TCM5095" },
226 { "" } 226 { "" }
227}; 227};
228MODULE_DEVICE_TABLE(eisa, el3_eisa_ids);
228 229
229static int el3_eisa_probe (struct device *device); 230static int el3_eisa_probe (struct device *device);
230 231
diff --git a/drivers/net/3c59x.c b/drivers/net/3c59x.c
index af301f09d674..df42e28cc80f 100644
--- a/drivers/net/3c59x.c
+++ b/drivers/net/3c59x.c
@@ -851,6 +851,7 @@ static struct eisa_device_id vortex_eisa_ids[] = {
851 { "TCM5970", CH_3C597 }, 851 { "TCM5970", CH_3C597 },
852 { "" } 852 { "" }
853}; 853};
854MODULE_DEVICE_TABLE(eisa, vortex_eisa_ids);
854 855
855static int vortex_eisa_probe(struct device *device); 856static int vortex_eisa_probe(struct device *device);
856static int vortex_eisa_remove(struct device *device); 857static int vortex_eisa_remove(struct device *device);
diff --git a/drivers/net/8390.c b/drivers/net/8390.c
index 5b6b05ed8f3c..9d34056147ad 100644
--- a/drivers/net/8390.c
+++ b/drivers/net/8390.c
@@ -299,7 +299,7 @@ static int ei_start_xmit(struct sk_buff *skb, struct net_device *dev)
299 * Slow phase with lock held. 299 * Slow phase with lock held.
300 */ 300 */
301 301
302 disable_irq_nosync_lockdep(dev->irq); 302 disable_irq_nosync_lockdep_irqsave(dev->irq, &flags);
303 303
304 spin_lock(&ei_local->page_lock); 304 spin_lock(&ei_local->page_lock);
305 305
@@ -338,7 +338,7 @@ static int ei_start_xmit(struct sk_buff *skb, struct net_device *dev)
338 netif_stop_queue(dev); 338 netif_stop_queue(dev);
339 outb_p(ENISR_ALL, e8390_base + EN0_IMR); 339 outb_p(ENISR_ALL, e8390_base + EN0_IMR);
340 spin_unlock(&ei_local->page_lock); 340 spin_unlock(&ei_local->page_lock);
341 enable_irq_lockdep(dev->irq); 341 enable_irq_lockdep_irqrestore(dev->irq, &flags);
342 ei_local->stat.tx_errors++; 342 ei_local->stat.tx_errors++;
343 return 1; 343 return 1;
344 } 344 }
@@ -379,7 +379,7 @@ static int ei_start_xmit(struct sk_buff *skb, struct net_device *dev)
379 outb_p(ENISR_ALL, e8390_base + EN0_IMR); 379 outb_p(ENISR_ALL, e8390_base + EN0_IMR);
380 380
381 spin_unlock(&ei_local->page_lock); 381 spin_unlock(&ei_local->page_lock);
382 enable_irq_lockdep(dev->irq); 382 enable_irq_lockdep_irqrestore(dev->irq, &flags);
383 383
384 dev_kfree_skb (skb); 384 dev_kfree_skb (skb);
385 ei_local->stat.tx_bytes += send_length; 385 ei_local->stat.tx_bytes += send_length;
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 63154774c257..ff8a8c0a26d5 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -24,6 +24,9 @@ config NETDEVICES
24 24
25 If unsure, say Y. 25 If unsure, say Y.
26 26
27# All the following symbols are dependent on NETDEVICES - do not repeat
28# that for each of the symbols.
29if NETDEVICES
27 30
28config IFB 31config IFB
29 tristate "Intermediate Functional Block support" 32 tristate "Intermediate Functional Block support"
@@ -2852,6 +2855,8 @@ config NETCONSOLE
2852 If you want to log kernel messages over the network, enable this. 2855 If you want to log kernel messages over the network, enable this.
2853 See <file:Documentation/networking/netconsole.txt> for details. 2856 See <file:Documentation/networking/netconsole.txt> for details.
2854 2857
2858endif #NETDEVICES
2859
2855config NETPOLL 2860config NETPOLL
2856 def_bool NETCONSOLE 2861 def_bool NETCONSOLE
2857 2862
diff --git a/drivers/net/Space.c b/drivers/net/Space.c
index 9953201c670d..a67f5efc983f 100644
--- a/drivers/net/Space.c
+++ b/drivers/net/Space.c
@@ -165,7 +165,7 @@ static struct devprobe2 mca_probes[] __initdata = {
165 * look for EISA/PCI/MCA cards in addition to ISA cards). 165 * look for EISA/PCI/MCA cards in addition to ISA cards).
166 */ 166 */
167static struct devprobe2 isa_probes[] __initdata = { 167static struct devprobe2 isa_probes[] __initdata = {
168#ifdef CONFIG_HP100 /* ISA, EISA & PCI */ 168#if defined(CONFIG_HP100) && defined(CONFIG_ISA) /* ISA, EISA */
169 {hp100_probe, 0}, 169 {hp100_probe, 0},
170#endif 170#endif
171#ifdef CONFIG_3C515 171#ifdef CONFIG_3C515
diff --git a/drivers/net/acenic.c b/drivers/net/acenic.c
index a075246f6f43..71a4f60f7325 100644
--- a/drivers/net/acenic.c
+++ b/drivers/net/acenic.c
@@ -163,11 +163,7 @@ MODULE_DEVICE_TABLE(pci, acenic_pci_tbl);
163#define SET_NETDEV_DEV(net, pdev) do{} while(0) 163#define SET_NETDEV_DEV(net, pdev) do{} while(0)
164#endif 164#endif
165 165
166#if LINUX_VERSION_CODE >= 0x2051c
167#define ace_sync_irq(irq) synchronize_irq(irq) 166#define ace_sync_irq(irq) synchronize_irq(irq)
168#else
169#define ace_sync_irq(irq) synchronize_irq()
170#endif
171 167
172#ifndef offset_in_page 168#ifndef offset_in_page
173#define offset_in_page(ptr) ((unsigned long)(ptr) & ~PAGE_MASK) 169#define offset_in_page(ptr) ((unsigned long)(ptr) & ~PAGE_MASK)
diff --git a/drivers/net/appletalk/ipddp.c b/drivers/net/appletalk/ipddp.c
index 7f7dd450226a..b98592a8bac8 100644
--- a/drivers/net/appletalk/ipddp.c
+++ b/drivers/net/appletalk/ipddp.c
@@ -145,9 +145,7 @@ static int ipddp_xmit(struct sk_buff *skb, struct net_device *dev)
145 145
146 /* Create the Extended DDP header */ 146 /* Create the Extended DDP header */
147 ddp = (struct ddpehdr *)skb->data; 147 ddp = (struct ddpehdr *)skb->data;
148 ddp->deh_len = skb->len; 148 ddp->deh_len_hops = htons(skb->len + (1<<10));
149 ddp->deh_hops = 1;
150 ddp->deh_pad = 0;
151 ddp->deh_sum = 0; 149 ddp->deh_sum = 0;
152 150
153 /* 151 /*
@@ -170,7 +168,6 @@ static int ipddp_xmit(struct sk_buff *skb, struct net_device *dev)
170 ddp->deh_sport = 72; 168 ddp->deh_sport = 72;
171 169
172 *((__u8 *)(ddp+1)) = 22; /* ddp type = IP */ 170 *((__u8 *)(ddp+1)) = 22; /* ddp type = IP */
173 *((__u16 *)ddp)=ntohs(*((__u16 *)ddp)); /* fix up length field */
174 171
175 skb->protocol = htons(ETH_P_ATALK); /* Protocol has changed */ 172 skb->protocol = htons(ETH_P_ATALK); /* Protocol has changed */
176 173
diff --git a/drivers/net/arm/at91_ether.c b/drivers/net/arm/at91_ether.c
index 95b28aa01f4f..3ecf2cc53a7c 100644
--- a/drivers/net/arm/at91_ether.c
+++ b/drivers/net/arm/at91_ether.c
@@ -947,7 +947,7 @@ static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_add
947 return -ENOMEM; 947 return -ENOMEM;
948 948
949 dev->base_addr = AT91_VA_BASE_EMAC; 949 dev->base_addr = AT91_VA_BASE_EMAC;
950 dev->irq = AT91_ID_EMAC; 950 dev->irq = AT91RM9200_ID_EMAC;
951 SET_MODULE_OWNER(dev); 951 SET_MODULE_OWNER(dev);
952 952
953 /* Install the interrupt handler */ 953 /* Install the interrupt handler */
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 7fcf015021ec..6b4edb63c4c4 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -56,8 +56,8 @@
56 56
57#define DRV_MODULE_NAME "bnx2" 57#define DRV_MODULE_NAME "bnx2"
58#define PFX DRV_MODULE_NAME ": " 58#define PFX DRV_MODULE_NAME ": "
59#define DRV_MODULE_VERSION "1.4.44" 59#define DRV_MODULE_VERSION "1.4.45"
60#define DRV_MODULE_RELDATE "August 10, 2006" 60#define DRV_MODULE_RELDATE "September 29, 2006"
61 61
62#define RUN_AT(x) (jiffies + (x)) 62#define RUN_AT(x) (jiffies + (x))
63 63
@@ -5805,6 +5805,34 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
5805 bp->cmd_ticks_int = bp->cmd_ticks; 5805 bp->cmd_ticks_int = bp->cmd_ticks;
5806 } 5806 }
5807 5807
5808 /* Disable MSI on 5706 if AMD 8132 bridge is found.
5809 *
5810 * MSI is defined to be 32-bit write. The 5706 does 64-bit MSI writes
5811 * with byte enables disabled on the unused 32-bit word. This is legal
5812 * but causes problems on the AMD 8132 which will eventually stop
5813 * responding after a while.
5814 *
5815 * AMD believes this incompatibility is unique to the 5706, and
5816 * prefers to locally disable MSI rather than globally disabling it
5817 * using pci_msi_quirk.
5818 */
5819 if (CHIP_NUM(bp) == CHIP_NUM_5706 && disable_msi == 0) {
5820 struct pci_dev *amd_8132 = NULL;
5821
5822 while ((amd_8132 = pci_get_device(PCI_VENDOR_ID_AMD,
5823 PCI_DEVICE_ID_AMD_8132_BRIDGE,
5824 amd_8132))) {
5825 u8 rev;
5826
5827 pci_read_config_byte(amd_8132, PCI_REVISION_ID, &rev);
5828 if (rev >= 0x10 && rev <= 0x13) {
5829 disable_msi = 1;
5830 pci_dev_put(amd_8132);
5831 break;
5832 }
5833 }
5834 }
5835
5808 bp->autoneg = AUTONEG_SPEED | AUTONEG_FLOW_CTRL; 5836 bp->autoneg = AUTONEG_SPEED | AUTONEG_FLOW_CTRL;
5809 bp->req_line_speed = 0; 5837 bp->req_line_speed = 0;
5810 if (bp->phy_flags & PHY_SERDES_FLAG) { 5838 if (bp->phy_flags & PHY_SERDES_FLAG) {
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index 6a407070c2e8..3fb354d9c515 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -85,6 +85,7 @@
85#define AD_LINK_SPEED_BITMASK_10MBPS 0x2 85#define AD_LINK_SPEED_BITMASK_10MBPS 0x2
86#define AD_LINK_SPEED_BITMASK_100MBPS 0x4 86#define AD_LINK_SPEED_BITMASK_100MBPS 0x4
87#define AD_LINK_SPEED_BITMASK_1000MBPS 0x8 87#define AD_LINK_SPEED_BITMASK_1000MBPS 0x8
88#define AD_LINK_SPEED_BITMASK_10000MBPS 0x10
88//endalloun 89//endalloun
89 90
90// compare MAC addresses 91// compare MAC addresses
@@ -99,7 +100,7 @@ static u16 __get_link_speed(struct port *port);
99static u8 __get_duplex(struct port *port); 100static u8 __get_duplex(struct port *port);
100static inline void __initialize_port_locks(struct port *port); 101static inline void __initialize_port_locks(struct port *port);
101//conversions 102//conversions
102static void __ntohs_lacpdu(struct lacpdu *lacpdu); 103static void __htons_lacpdu(struct lacpdu *lacpdu);
103static u16 __ad_timer_to_ticks(u16 timer_type, u16 Par); 104static u16 __ad_timer_to_ticks(u16 timer_type, u16 Par);
104 105
105 106
@@ -330,7 +331,8 @@ static inline void __release_rx_machine_lock(struct port *port)
330 * 0, 331 * 0,
331 * %AD_LINK_SPEED_BITMASK_10MBPS, 332 * %AD_LINK_SPEED_BITMASK_10MBPS,
332 * %AD_LINK_SPEED_BITMASK_100MBPS, 333 * %AD_LINK_SPEED_BITMASK_100MBPS,
333 * %AD_LINK_SPEED_BITMASK_1000MBPS 334 * %AD_LINK_SPEED_BITMASK_1000MBPS,
335 * %AD_LINK_SPEED_BITMASK_10000MBPS
334 */ 336 */
335static u16 __get_link_speed(struct port *port) 337static u16 __get_link_speed(struct port *port)
336{ 338{
@@ -357,6 +359,10 @@ static u16 __get_link_speed(struct port *port)
357 speed = AD_LINK_SPEED_BITMASK_1000MBPS; 359 speed = AD_LINK_SPEED_BITMASK_1000MBPS;
358 break; 360 break;
359 361
362 case SPEED_10000:
363 speed = AD_LINK_SPEED_BITMASK_10000MBPS;
364 break;
365
360 default: 366 default:
361 speed = 0; // unknown speed value from ethtool. shouldn't happen 367 speed = 0; // unknown speed value from ethtool. shouldn't happen
362 break; 368 break;
@@ -414,23 +420,23 @@ static inline void __initialize_port_locks(struct port *port)
414 420
415//conversions 421//conversions
416/** 422/**
417 * __ntohs_lacpdu - convert the contents of a LACPDU to host byte order 423 * __htons_lacpdu - convert the contents of a LACPDU to network byte order
418 * @lacpdu: the speicifed lacpdu 424 * @lacpdu: the speicifed lacpdu
419 * 425 *
420 * For each multi-byte field in the lacpdu, convert its content 426 * For each multi-byte field in the lacpdu, convert its content
421 */ 427 */
422static void __ntohs_lacpdu(struct lacpdu *lacpdu) 428static void __htons_lacpdu(struct lacpdu *lacpdu)
423{ 429{
424 if (lacpdu) { 430 if (lacpdu) {
425 lacpdu->actor_system_priority = ntohs(lacpdu->actor_system_priority); 431 lacpdu->actor_system_priority = htons(lacpdu->actor_system_priority);
426 lacpdu->actor_key = ntohs(lacpdu->actor_key); 432 lacpdu->actor_key = htons(lacpdu->actor_key);
427 lacpdu->actor_port_priority = ntohs(lacpdu->actor_port_priority); 433 lacpdu->actor_port_priority = htons(lacpdu->actor_port_priority);
428 lacpdu->actor_port = ntohs(lacpdu->actor_port); 434 lacpdu->actor_port = htons(lacpdu->actor_port);
429 lacpdu->partner_system_priority = ntohs(lacpdu->partner_system_priority); 435 lacpdu->partner_system_priority = htons(lacpdu->partner_system_priority);
430 lacpdu->partner_key = ntohs(lacpdu->partner_key); 436 lacpdu->partner_key = htons(lacpdu->partner_key);
431 lacpdu->partner_port_priority = ntohs(lacpdu->partner_port_priority); 437 lacpdu->partner_port_priority = htons(lacpdu->partner_port_priority);
432 lacpdu->partner_port = ntohs(lacpdu->partner_port); 438 lacpdu->partner_port = htons(lacpdu->partner_port);
433 lacpdu->collector_max_delay = ntohs(lacpdu->collector_max_delay); 439 lacpdu->collector_max_delay = htons(lacpdu->collector_max_delay);
434 } 440 }
435} 441}
436 442
@@ -490,11 +496,11 @@ static void __record_pdu(struct lacpdu *lacpdu, struct port *port)
490 // validate lacpdu and port 496 // validate lacpdu and port
491 if (lacpdu && port) { 497 if (lacpdu && port) {
492 // record the new parameter values for the partner operational 498 // record the new parameter values for the partner operational
493 port->partner_oper_port_number = lacpdu->actor_port; 499 port->partner_oper_port_number = ntohs(lacpdu->actor_port);
494 port->partner_oper_port_priority = lacpdu->actor_port_priority; 500 port->partner_oper_port_priority = ntohs(lacpdu->actor_port_priority);
495 port->partner_oper_system = lacpdu->actor_system; 501 port->partner_oper_system = lacpdu->actor_system;
496 port->partner_oper_system_priority = lacpdu->actor_system_priority; 502 port->partner_oper_system_priority = ntohs(lacpdu->actor_system_priority);
497 port->partner_oper_key = lacpdu->actor_key; 503 port->partner_oper_key = ntohs(lacpdu->actor_key);
498 // zero partener's lase states 504 // zero partener's lase states
499 port->partner_oper_port_state = 0; 505 port->partner_oper_port_state = 0;
500 port->partner_oper_port_state |= (lacpdu->actor_state & AD_STATE_LACP_ACTIVITY); 506 port->partner_oper_port_state |= (lacpdu->actor_state & AD_STATE_LACP_ACTIVITY);
@@ -561,11 +567,11 @@ static void __update_selected(struct lacpdu *lacpdu, struct port *port)
561 // validate lacpdu and port 567 // validate lacpdu and port
562 if (lacpdu && port) { 568 if (lacpdu && port) {
563 // check if any parameter is different 569 // check if any parameter is different
564 if ((lacpdu->actor_port != port->partner_oper_port_number) || 570 if ((ntohs(lacpdu->actor_port) != port->partner_oper_port_number) ||
565 (lacpdu->actor_port_priority != port->partner_oper_port_priority) || 571 (ntohs(lacpdu->actor_port_priority) != port->partner_oper_port_priority) ||
566 MAC_ADDRESS_COMPARE(&(lacpdu->actor_system), &(port->partner_oper_system)) || 572 MAC_ADDRESS_COMPARE(&(lacpdu->actor_system), &(port->partner_oper_system)) ||
567 (lacpdu->actor_system_priority != port->partner_oper_system_priority) || 573 (ntohs(lacpdu->actor_system_priority) != port->partner_oper_system_priority) ||
568 (lacpdu->actor_key != port->partner_oper_key) || 574 (ntohs(lacpdu->actor_key) != port->partner_oper_key) ||
569 ((lacpdu->actor_state & AD_STATE_AGGREGATION) != (port->partner_oper_port_state & AD_STATE_AGGREGATION)) 575 ((lacpdu->actor_state & AD_STATE_AGGREGATION) != (port->partner_oper_port_state & AD_STATE_AGGREGATION))
570 ) { 576 ) {
571 // update the state machine Selected variable 577 // update the state machine Selected variable
@@ -628,11 +634,11 @@ static void __choose_matched(struct lacpdu *lacpdu, struct port *port)
628 // validate lacpdu and port 634 // validate lacpdu and port
629 if (lacpdu && port) { 635 if (lacpdu && port) {
630 // check if all parameters are alike 636 // check if all parameters are alike
631 if (((lacpdu->partner_port == port->actor_port_number) && 637 if (((ntohs(lacpdu->partner_port) == port->actor_port_number) &&
632 (lacpdu->partner_port_priority == port->actor_port_priority) && 638 (ntohs(lacpdu->partner_port_priority) == port->actor_port_priority) &&
633 !MAC_ADDRESS_COMPARE(&(lacpdu->partner_system), &(port->actor_system)) && 639 !MAC_ADDRESS_COMPARE(&(lacpdu->partner_system), &(port->actor_system)) &&
634 (lacpdu->partner_system_priority == port->actor_system_priority) && 640 (ntohs(lacpdu->partner_system_priority) == port->actor_system_priority) &&
635 (lacpdu->partner_key == port->actor_oper_port_key) && 641 (ntohs(lacpdu->partner_key) == port->actor_oper_port_key) &&
636 ((lacpdu->partner_state & AD_STATE_AGGREGATION) == (port->actor_oper_port_state & AD_STATE_AGGREGATION))) || 642 ((lacpdu->partner_state & AD_STATE_AGGREGATION) == (port->actor_oper_port_state & AD_STATE_AGGREGATION))) ||
637 // or this is individual link(aggregation == FALSE) 643 // or this is individual link(aggregation == FALSE)
638 ((lacpdu->actor_state & AD_STATE_AGGREGATION) == 0) 644 ((lacpdu->actor_state & AD_STATE_AGGREGATION) == 0)
@@ -662,11 +668,11 @@ static void __update_ntt(struct lacpdu *lacpdu, struct port *port)
662 // validate lacpdu and port 668 // validate lacpdu and port
663 if (lacpdu && port) { 669 if (lacpdu && port) {
664 // check if any parameter is different 670 // check if any parameter is different
665 if ((lacpdu->partner_port != port->actor_port_number) || 671 if ((ntohs(lacpdu->partner_port) != port->actor_port_number) ||
666 (lacpdu->partner_port_priority != port->actor_port_priority) || 672 (ntohs(lacpdu->partner_port_priority) != port->actor_port_priority) ||
667 MAC_ADDRESS_COMPARE(&(lacpdu->partner_system), &(port->actor_system)) || 673 MAC_ADDRESS_COMPARE(&(lacpdu->partner_system), &(port->actor_system)) ||
668 (lacpdu->partner_system_priority != port->actor_system_priority) || 674 (ntohs(lacpdu->partner_system_priority) != port->actor_system_priority) ||
669 (lacpdu->partner_key != port->actor_oper_port_key) || 675 (ntohs(lacpdu->partner_key) != port->actor_oper_port_key) ||
670 ((lacpdu->partner_state & AD_STATE_LACP_ACTIVITY) != (port->actor_oper_port_state & AD_STATE_LACP_ACTIVITY)) || 676 ((lacpdu->partner_state & AD_STATE_LACP_ACTIVITY) != (port->actor_oper_port_state & AD_STATE_LACP_ACTIVITY)) ||
671 ((lacpdu->partner_state & AD_STATE_LACP_TIMEOUT) != (port->actor_oper_port_state & AD_STATE_LACP_TIMEOUT)) || 677 ((lacpdu->partner_state & AD_STATE_LACP_TIMEOUT) != (port->actor_oper_port_state & AD_STATE_LACP_TIMEOUT)) ||
672 ((lacpdu->partner_state & AD_STATE_SYNCHRONIZATION) != (port->actor_oper_port_state & AD_STATE_SYNCHRONIZATION)) || 678 ((lacpdu->partner_state & AD_STATE_SYNCHRONIZATION) != (port->actor_oper_port_state & AD_STATE_SYNCHRONIZATION)) ||
@@ -775,6 +781,9 @@ static u32 __get_agg_bandwidth(struct aggregator *aggregator)
775 case AD_LINK_SPEED_BITMASK_1000MBPS: 781 case AD_LINK_SPEED_BITMASK_1000MBPS:
776 bandwidth = aggregator->num_of_ports * 1000; 782 bandwidth = aggregator->num_of_ports * 1000;
777 break; 783 break;
784 case AD_LINK_SPEED_BITMASK_10000MBPS:
785 bandwidth = aggregator->num_of_ports * 10000;
786 break;
778 default: 787 default:
779 bandwidth=0; // to silent the compilor .... 788 bandwidth=0; // to silent the compilor ....
780 } 789 }
@@ -847,7 +856,7 @@ static inline void __update_lacpdu_from_port(struct port *port)
847 */ 856 */
848 857
849 /* Convert all non u8 parameters to Big Endian for transmit */ 858 /* Convert all non u8 parameters to Big Endian for transmit */
850 __ntohs_lacpdu(lacpdu); 859 __htons_lacpdu(lacpdu);
851} 860}
852 861
853////////////////////////////////////////////////////////////////////////////////////// 862//////////////////////////////////////////////////////////////////////////////////////
@@ -2171,7 +2180,6 @@ static void bond_3ad_rx_indication(struct lacpdu *lacpdu, struct slave *slave, u
2171 2180
2172 switch (lacpdu->subtype) { 2181 switch (lacpdu->subtype) {
2173 case AD_TYPE_LACPDU: 2182 case AD_TYPE_LACPDU:
2174 __ntohs_lacpdu(lacpdu);
2175 dprintk("Received LACPDU on port %d\n", port->actor_port_number); 2183 dprintk("Received LACPDU on port %d\n", port->actor_port_number);
2176 ad_rx_machine(lacpdu, port); 2184 ad_rx_machine(lacpdu, port);
2177 break; 2185 break;
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 850aae21a2fe..c0bbddae4ec4 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -96,6 +96,7 @@ static char *lacp_rate = NULL;
96static char *xmit_hash_policy = NULL; 96static char *xmit_hash_policy = NULL;
97static int arp_interval = BOND_LINK_ARP_INTERV; 97static int arp_interval = BOND_LINK_ARP_INTERV;
98static char *arp_ip_target[BOND_MAX_ARP_TARGETS] = { NULL, }; 98static char *arp_ip_target[BOND_MAX_ARP_TARGETS] = { NULL, };
99static char *arp_validate = NULL;
99struct bond_params bonding_defaults; 100struct bond_params bonding_defaults;
100 101
101module_param(max_bonds, int, 0); 102module_param(max_bonds, int, 0);
@@ -127,6 +128,8 @@ module_param(arp_interval, int, 0);
127MODULE_PARM_DESC(arp_interval, "arp interval in milliseconds"); 128MODULE_PARM_DESC(arp_interval, "arp interval in milliseconds");
128module_param_array(arp_ip_target, charp, NULL, 0); 129module_param_array(arp_ip_target, charp, NULL, 0);
129MODULE_PARM_DESC(arp_ip_target, "arp targets in n.n.n.n form"); 130MODULE_PARM_DESC(arp_ip_target, "arp targets in n.n.n.n form");
131module_param(arp_validate, charp, 0);
132MODULE_PARM_DESC(arp_validate, "validate src/dst of ARP probes: none (default), active, backup or all");
130 133
131/*----------------------------- Global variables ----------------------------*/ 134/*----------------------------- Global variables ----------------------------*/
132 135
@@ -170,6 +173,14 @@ struct bond_parm_tbl xmit_hashtype_tbl[] = {
170{ NULL, -1}, 173{ NULL, -1},
171}; 174};
172 175
176struct bond_parm_tbl arp_validate_tbl[] = {
177{ "none", BOND_ARP_VALIDATE_NONE},
178{ "active", BOND_ARP_VALIDATE_ACTIVE},
179{ "backup", BOND_ARP_VALIDATE_BACKUP},
180{ "all", BOND_ARP_VALIDATE_ALL},
181{ NULL, -1},
182};
183
173/*-------------------------- Forward declarations ---------------------------*/ 184/*-------------------------- Forward declarations ---------------------------*/
174 185
175static void bond_send_gratuitous_arp(struct bonding *bond); 186static void bond_send_gratuitous_arp(struct bonding *bond);
@@ -638,6 +649,7 @@ verify:
638 case SPEED_10: 649 case SPEED_10:
639 case SPEED_100: 650 case SPEED_100:
640 case SPEED_1000: 651 case SPEED_1000:
652 case SPEED_10000:
641 break; 653 break;
642 default: 654 default:
643 return -1; 655 return -1;
@@ -1210,10 +1222,14 @@ static int bond_compute_features(struct bonding *bond)
1210 unsigned long features = BOND_INTERSECT_FEATURES; 1222 unsigned long features = BOND_INTERSECT_FEATURES;
1211 struct slave *slave; 1223 struct slave *slave;
1212 struct net_device *bond_dev = bond->dev; 1224 struct net_device *bond_dev = bond->dev;
1225 unsigned short max_hard_header_len = ETH_HLEN;
1213 int i; 1226 int i;
1214 1227
1215 bond_for_each_slave(bond, slave, i) 1228 bond_for_each_slave(bond, slave, i) {
1216 features &= (slave->dev->features & BOND_INTERSECT_FEATURES); 1229 features &= (slave->dev->features & BOND_INTERSECT_FEATURES);
1230 if (slave->dev->hard_header_len > max_hard_header_len)
1231 max_hard_header_len = slave->dev->hard_header_len;
1232 }
1217 1233
1218 if ((features & NETIF_F_SG) && 1234 if ((features & NETIF_F_SG) &&
1219 !(features & NETIF_F_ALL_CSUM)) 1235 !(features & NETIF_F_ALL_CSUM))
@@ -1231,6 +1247,7 @@ static int bond_compute_features(struct bonding *bond)
1231 1247
1232 features |= (bond_dev->features & ~BOND_INTERSECT_FEATURES); 1248 features |= (bond_dev->features & ~BOND_INTERSECT_FEATURES);
1233 bond_dev->features = features; 1249 bond_dev->features = features;
1250 bond_dev->hard_header_len = max_hard_header_len;
1234 1251
1235 return 0; 1252 return 0;
1236} 1253}
@@ -1365,6 +1382,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1365 } 1382 }
1366 1383
1367 new_slave->dev = slave_dev; 1384 new_slave->dev = slave_dev;
1385 slave_dev->priv_flags |= IFF_BONDING;
1368 1386
1369 if ((bond->params.mode == BOND_MODE_TLB) || 1387 if ((bond->params.mode == BOND_MODE_TLB) ||
1370 (bond->params.mode == BOND_MODE_ALB)) { 1388 (bond->params.mode == BOND_MODE_ALB)) {
@@ -1417,6 +1435,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1417 1435
1418 bond_compute_features(bond); 1436 bond_compute_features(bond);
1419 1437
1438 new_slave->last_arp_rx = jiffies;
1439
1420 if (bond->params.miimon && !bond->params.use_carrier) { 1440 if (bond->params.miimon && !bond->params.use_carrier) {
1421 link_reporting = bond_check_dev_link(bond, slave_dev, 1); 1441 link_reporting = bond_check_dev_link(bond, slave_dev, 1);
1422 1442
@@ -1493,29 +1513,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1493 1513
1494 switch (bond->params.mode) { 1514 switch (bond->params.mode) {
1495 case BOND_MODE_ACTIVEBACKUP: 1515 case BOND_MODE_ACTIVEBACKUP:
1496 /* if we're in active-backup mode, we need one and 1516 bond_set_slave_inactive_flags(new_slave);
1497 * only one active interface. The backup interfaces 1517 bond_select_active_slave(bond);
1498 * will have their SLAVE_INACTIVE flag set because we
1499 * need them to be drop all packets. Thus, since we
1500 * guarantee that curr_active_slave always point to
1501 * the last usable interface, we just have to verify
1502 * this interface's flag.
1503 */
1504 if (((!bond->curr_active_slave) ||
1505 (bond->curr_active_slave->dev->priv_flags & IFF_SLAVE_INACTIVE)) &&
1506 (new_slave->link != BOND_LINK_DOWN)) {
1507 /* first slave or no active slave yet, and this link
1508 is OK, so make this interface the active one */
1509 bond_change_active_slave(bond, new_slave);
1510 printk(KERN_INFO DRV_NAME
1511 ": %s: first active interface up!\n",
1512 bond->dev->name);
1513 netif_carrier_on(bond->dev);
1514
1515 } else {
1516 dprintk("This is just a backup slave\n");
1517 bond_set_slave_inactive_flags(new_slave);
1518 }
1519 break; 1518 break;
1520 case BOND_MODE_8023AD: 1519 case BOND_MODE_8023AD:
1521 /* in 802.3ad mode, the internal mechanism 1520 /* in 802.3ad mode, the internal mechanism
@@ -1778,7 +1777,8 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
1778 dev_set_mac_address(slave_dev, &addr); 1777 dev_set_mac_address(slave_dev, &addr);
1779 1778
1780 slave_dev->priv_flags &= ~(IFF_MASTER_8023AD | IFF_MASTER_ALB | 1779 slave_dev->priv_flags &= ~(IFF_MASTER_8023AD | IFF_MASTER_ALB |
1781 IFF_SLAVE_INACTIVE); 1780 IFF_SLAVE_INACTIVE | IFF_BONDING |
1781 IFF_SLAVE_NEEDARP);
1782 1782
1783 kfree(slave); 1783 kfree(slave);
1784 1784
@@ -2252,7 +2252,7 @@ static u32 bond_glean_dev_ip(struct net_device *dev)
2252{ 2252{
2253 struct in_device *idev; 2253 struct in_device *idev;
2254 struct in_ifaddr *ifa; 2254 struct in_ifaddr *ifa;
2255 u32 addr = 0; 2255 __be32 addr = 0;
2256 2256
2257 if (!dev) 2257 if (!dev)
2258 return 0; 2258 return 0;
@@ -2291,6 +2291,25 @@ static int bond_has_ip(struct bonding *bond)
2291 return 0; 2291 return 0;
2292} 2292}
2293 2293
2294static int bond_has_this_ip(struct bonding *bond, u32 ip)
2295{
2296 struct vlan_entry *vlan, *vlan_next;
2297
2298 if (ip == bond->master_ip)
2299 return 1;
2300
2301 if (list_empty(&bond->vlan_list))
2302 return 0;
2303
2304 list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
2305 vlan_list) {
2306 if (ip == vlan->vlan_ip)
2307 return 1;
2308 }
2309
2310 return 0;
2311}
2312
2294/* 2313/*
2295 * We go to the (large) trouble of VLAN tagging ARP frames because 2314 * We go to the (large) trouble of VLAN tagging ARP frames because
2296 * switches in VLAN mode (especially if ports are configured as 2315 * switches in VLAN mode (especially if ports are configured as
@@ -2429,6 +2448,93 @@ static void bond_send_gratuitous_arp(struct bonding *bond)
2429 } 2448 }
2430} 2449}
2431 2450
2451static void bond_validate_arp(struct bonding *bond, struct slave *slave, u32 sip, u32 tip)
2452{
2453 int i;
2454 u32 *targets = bond->params.arp_targets;
2455
2456 targets = bond->params.arp_targets;
2457 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && targets[i]; i++) {
2458 dprintk("bva: sip %u.%u.%u.%u tip %u.%u.%u.%u t[%d] "
2459 "%u.%u.%u.%u bhti(tip) %d\n",
2460 NIPQUAD(sip), NIPQUAD(tip), i, NIPQUAD(targets[i]),
2461 bond_has_this_ip(bond, tip));
2462 if (sip == targets[i]) {
2463 if (bond_has_this_ip(bond, tip))
2464 slave->last_arp_rx = jiffies;
2465 return;
2466 }
2467 }
2468}
2469
2470static int bond_arp_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
2471{
2472 struct arphdr *arp;
2473 struct slave *slave;
2474 struct bonding *bond;
2475 unsigned char *arp_ptr;
2476 u32 sip, tip;
2477
2478 if (!(dev->priv_flags & IFF_BONDING) || !(dev->flags & IFF_MASTER))
2479 goto out;
2480
2481 bond = dev->priv;
2482 read_lock(&bond->lock);
2483
2484 dprintk("bond_arp_rcv: bond %s skb->dev %s orig_dev %s\n",
2485 bond->dev->name, skb->dev ? skb->dev->name : "NULL",
2486 orig_dev ? orig_dev->name : "NULL");
2487
2488 slave = bond_get_slave_by_dev(bond, orig_dev);
2489 if (!slave || !slave_do_arp_validate(bond, slave))
2490 goto out_unlock;
2491
2492 /* ARP header, plus 2 device addresses, plus 2 IP addresses. */
2493 if (!pskb_may_pull(skb, (sizeof(struct arphdr) +
2494 (2 * dev->addr_len) +
2495 (2 * sizeof(u32)))))
2496 goto out_unlock;
2497
2498 arp = skb->nh.arph;
2499 if (arp->ar_hln != dev->addr_len ||
2500 skb->pkt_type == PACKET_OTHERHOST ||
2501 skb->pkt_type == PACKET_LOOPBACK ||
2502 arp->ar_hrd != htons(ARPHRD_ETHER) ||
2503 arp->ar_pro != htons(ETH_P_IP) ||
2504 arp->ar_pln != 4)
2505 goto out_unlock;
2506
2507 arp_ptr = (unsigned char *)(arp + 1);
2508 arp_ptr += dev->addr_len;
2509 memcpy(&sip, arp_ptr, 4);
2510 arp_ptr += 4 + dev->addr_len;
2511 memcpy(&tip, arp_ptr, 4);
2512
2513 dprintk("bond_arp_rcv: %s %s/%d av %d sv %d sip %u.%u.%u.%u"
2514 " tip %u.%u.%u.%u\n", bond->dev->name, slave->dev->name,
2515 slave->state, bond->params.arp_validate,
2516 slave_do_arp_validate(bond, slave), NIPQUAD(sip), NIPQUAD(tip));
2517
2518 /*
2519 * Backup slaves won't see the ARP reply, but do come through
2520 * here for each ARP probe (so we swap the sip/tip to validate
2521 * the probe). In a "redundant switch, common router" type of
2522 * configuration, the ARP probe will (hopefully) travel from
2523 * the active, through one switch, the router, then the other
2524 * switch before reaching the backup.
2525 */
2526 if (slave->state == BOND_STATE_ACTIVE)
2527 bond_validate_arp(bond, slave, sip, tip);
2528 else
2529 bond_validate_arp(bond, slave, tip, sip);
2530
2531out_unlock:
2532 read_unlock(&bond->lock);
2533out:
2534 dev_kfree_skb(skb);
2535 return NET_RX_SUCCESS;
2536}
2537
2432/* 2538/*
2433 * this function is called regularly to monitor each slave's link 2539 * this function is called regularly to monitor each slave's link
2434 * ensuring that traffic is being sent and received when arp monitoring 2540 * ensuring that traffic is being sent and received when arp monitoring
@@ -2593,7 +2699,8 @@ void bond_activebackup_arp_mon(struct net_device *bond_dev)
2593 */ 2699 */
2594 bond_for_each_slave(bond, slave, i) { 2700 bond_for_each_slave(bond, slave, i) {
2595 if (slave->link != BOND_LINK_UP) { 2701 if (slave->link != BOND_LINK_UP) {
2596 if ((jiffies - slave->dev->last_rx) <= delta_in_ticks) { 2702 if ((jiffies - slave_last_rx(bond, slave)) <=
2703 delta_in_ticks) {
2597 2704
2598 slave->link = BOND_LINK_UP; 2705 slave->link = BOND_LINK_UP;
2599 2706
@@ -2638,7 +2745,7 @@ void bond_activebackup_arp_mon(struct net_device *bond_dev)
2638 2745
2639 if ((slave != bond->curr_active_slave) && 2746 if ((slave != bond->curr_active_slave) &&
2640 (!bond->current_arp_slave) && 2747 (!bond->current_arp_slave) &&
2641 (((jiffies - slave->dev->last_rx) >= 3*delta_in_ticks) && 2748 (((jiffies - slave_last_rx(bond, slave)) >= 3*delta_in_ticks) &&
2642 bond_has_ip(bond))) { 2749 bond_has_ip(bond))) {
2643 /* a backup slave has gone down; three times 2750 /* a backup slave has gone down; three times
2644 * the delta allows the current slave to be 2751 * the delta allows the current slave to be
@@ -2685,7 +2792,7 @@ void bond_activebackup_arp_mon(struct net_device *bond_dev)
2685 * if it is up and needs to take over as the curr_active_slave 2792 * if it is up and needs to take over as the curr_active_slave
2686 */ 2793 */
2687 if ((((jiffies - slave->dev->trans_start) >= (2*delta_in_ticks)) || 2794 if ((((jiffies - slave->dev->trans_start) >= (2*delta_in_ticks)) ||
2688 (((jiffies - slave->dev->last_rx) >= (2*delta_in_ticks)) && 2795 (((jiffies - slave_last_rx(bond, slave)) >= (2*delta_in_ticks)) &&
2689 bond_has_ip(bond))) && 2796 bond_has_ip(bond))) &&
2690 ((jiffies - slave->jiffies) >= 2*delta_in_ticks)) { 2797 ((jiffies - slave->jiffies) >= 2*delta_in_ticks)) {
2691 2798
@@ -2950,7 +3057,7 @@ static void bond_info_show_slave(struct seq_file *seq, const struct slave *slave
2950 seq_printf(seq, "\nSlave Interface: %s\n", slave->dev->name); 3057 seq_printf(seq, "\nSlave Interface: %s\n", slave->dev->name);
2951 seq_printf(seq, "MII Status: %s\n", 3058 seq_printf(seq, "MII Status: %s\n",
2952 (slave->link == BOND_LINK_UP) ? "up" : "down"); 3059 (slave->link == BOND_LINK_UP) ? "up" : "down");
2953 seq_printf(seq, "Link Failure Count: %d\n", 3060 seq_printf(seq, "Link Failure Count: %u\n",
2954 slave->link_failure_count); 3061 slave->link_failure_count);
2955 3062
2956 seq_printf(seq, 3063 seq_printf(seq,
@@ -3210,6 +3317,9 @@ static int bond_netdev_event(struct notifier_block *this, unsigned long event, v
3210 (event_dev ? event_dev->name : "None"), 3317 (event_dev ? event_dev->name : "None"),
3211 event); 3318 event);
3212 3319
3320 if (!(event_dev->priv_flags & IFF_BONDING))
3321 return NOTIFY_DONE;
3322
3213 if (event_dev->flags & IFF_MASTER) { 3323 if (event_dev->flags & IFF_MASTER) {
3214 dprintk("IFF_MASTER\n"); 3324 dprintk("IFF_MASTER\n");
3215 return bond_master_netdev_event(event, event_dev); 3325 return bond_master_netdev_event(event, event_dev);
@@ -3305,6 +3415,21 @@ static void bond_unregister_lacpdu(struct bonding *bond)
3305 dev_remove_pack(&(BOND_AD_INFO(bond).ad_pkt_type)); 3415 dev_remove_pack(&(BOND_AD_INFO(bond).ad_pkt_type));
3306} 3416}
3307 3417
3418void bond_register_arp(struct bonding *bond)
3419{
3420 struct packet_type *pt = &bond->arp_mon_pt;
3421
3422 pt->type = htons(ETH_P_ARP);
3423 pt->dev = NULL; /*bond->dev;XXX*/
3424 pt->func = bond_arp_rcv;
3425 dev_add_pack(pt);
3426}
3427
3428void bond_unregister_arp(struct bonding *bond)
3429{
3430 dev_remove_pack(&bond->arp_mon_pt);
3431}
3432
3308/*---------------------------- Hashing Policies -----------------------------*/ 3433/*---------------------------- Hashing Policies -----------------------------*/
3309 3434
3310/* 3435/*
@@ -3391,6 +3516,9 @@ static int bond_open(struct net_device *bond_dev)
3391 } else { 3516 } else {
3392 arp_timer->function = (void *)&bond_loadbalance_arp_mon; 3517 arp_timer->function = (void *)&bond_loadbalance_arp_mon;
3393 } 3518 }
3519 if (bond->params.arp_validate)
3520 bond_register_arp(bond);
3521
3394 add_timer(arp_timer); 3522 add_timer(arp_timer);
3395 } 3523 }
3396 3524
@@ -3418,9 +3546,11 @@ static int bond_close(struct net_device *bond_dev)
3418 bond_unregister_lacpdu(bond); 3546 bond_unregister_lacpdu(bond);
3419 } 3547 }
3420 3548
3549 if (bond->params.arp_validate)
3550 bond_unregister_arp(bond);
3551
3421 write_lock_bh(&bond->lock); 3552 write_lock_bh(&bond->lock);
3422 3553
3423 bond_mc_list_destroy(bond);
3424 3554
3425 /* signal timers not to re-arm */ 3555 /* signal timers not to re-arm */
3426 bond->kill_timers = 1; 3556 bond->kill_timers = 1;
@@ -3451,8 +3581,6 @@ static int bond_close(struct net_device *bond_dev)
3451 break; 3581 break;
3452 } 3582 }
3453 3583
3454 /* Release the bonded slaves */
3455 bond_release_all(bond_dev);
3456 3584
3457 if ((bond->params.mode == BOND_MODE_TLB) || 3585 if ((bond->params.mode == BOND_MODE_TLB) ||
3458 (bond->params.mode == BOND_MODE_ALB)) { 3586 (bond->params.mode == BOND_MODE_ALB)) {
@@ -4179,6 +4307,7 @@ static int bond_init(struct net_device *bond_dev, struct bond_params *params)
4179 /* Initialize the device options */ 4307 /* Initialize the device options */
4180 bond_dev->tx_queue_len = 0; 4308 bond_dev->tx_queue_len = 0;
4181 bond_dev->flags |= IFF_MASTER|IFF_MULTICAST; 4309 bond_dev->flags |= IFF_MASTER|IFF_MULTICAST;
4310 bond_dev->priv_flags |= IFF_BONDING;
4182 4311
4183 /* At first, we block adding VLANs. That's the only way to 4312 /* At first, we block adding VLANs. That's the only way to
4184 * prevent problems that occur when adding VLANs over an 4313 * prevent problems that occur when adding VLANs over an
@@ -4237,6 +4366,9 @@ static void bond_free_all(void)
4237 list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list) { 4366 list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list) {
4238 struct net_device *bond_dev = bond->dev; 4367 struct net_device *bond_dev = bond->dev;
4239 4368
4369 bond_mc_list_destroy(bond);
4370 /* Release the bonded slaves */
4371 bond_release_all(bond_dev);
4240 unregister_netdevice(bond_dev); 4372 unregister_netdevice(bond_dev);
4241 bond_deinit(bond_dev); 4373 bond_deinit(bond_dev);
4242 } 4374 }
@@ -4270,6 +4402,8 @@ int bond_parse_parm(char *mode_arg, struct bond_parm_tbl *tbl)
4270 4402
4271static int bond_check_params(struct bond_params *params) 4403static int bond_check_params(struct bond_params *params)
4272{ 4404{
4405 int arp_validate_value;
4406
4273 /* 4407 /*
4274 * Convert string parameters. 4408 * Convert string parameters.
4275 */ 4409 */
@@ -4473,6 +4607,29 @@ static int bond_check_params(struct bond_params *params)
4473 arp_interval = 0; 4607 arp_interval = 0;
4474 } 4608 }
4475 4609
4610 if (arp_validate) {
4611 if (bond_mode != BOND_MODE_ACTIVEBACKUP) {
4612 printk(KERN_ERR DRV_NAME
4613 ": arp_validate only supported in active-backup mode\n");
4614 return -EINVAL;
4615 }
4616 if (!arp_interval) {
4617 printk(KERN_ERR DRV_NAME
4618 ": arp_validate requires arp_interval\n");
4619 return -EINVAL;
4620 }
4621
4622 arp_validate_value = bond_parse_parm(arp_validate,
4623 arp_validate_tbl);
4624 if (arp_validate_value == -1) {
4625 printk(KERN_ERR DRV_NAME
4626 ": Error: invalid arp_validate \"%s\"\n",
4627 arp_validate == NULL ? "NULL" : arp_validate);
4628 return -EINVAL;
4629 }
4630 } else
4631 arp_validate_value = 0;
4632
4476 if (miimon) { 4633 if (miimon) {
4477 printk(KERN_INFO DRV_NAME 4634 printk(KERN_INFO DRV_NAME
4478 ": MII link monitoring set to %d ms\n", 4635 ": MII link monitoring set to %d ms\n",
@@ -4481,8 +4638,10 @@ static int bond_check_params(struct bond_params *params)
4481 int i; 4638 int i;
4482 4639
4483 printk(KERN_INFO DRV_NAME 4640 printk(KERN_INFO DRV_NAME
4484 ": ARP monitoring set to %d ms with %d target(s):", 4641 ": ARP monitoring set to %d ms, validate %s, with %d target(s):",
4485 arp_interval, arp_ip_count); 4642 arp_interval,
4643 arp_validate_tbl[arp_validate_value].modename,
4644 arp_ip_count);
4486 4645
4487 for (i = 0; i < arp_ip_count; i++) 4646 for (i = 0; i < arp_ip_count; i++)
4488 printk (" %s", arp_ip_target[i]); 4647 printk (" %s", arp_ip_target[i]);
@@ -4516,6 +4675,7 @@ static int bond_check_params(struct bond_params *params)
4516 params->xmit_policy = xmit_hashtype; 4675 params->xmit_policy = xmit_hashtype;
4517 params->miimon = miimon; 4676 params->miimon = miimon;
4518 params->arp_interval = arp_interval; 4677 params->arp_interval = arp_interval;
4678 params->arp_validate = arp_validate_value;
4519 params->updelay = updelay; 4679 params->updelay = updelay;
4520 params->downdelay = downdelay; 4680 params->downdelay = downdelay;
4521 params->use_carrier = use_carrier; 4681 params->use_carrier = use_carrier;
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index cfe4dc3a93a3..ced9ed8f995a 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -51,6 +51,7 @@ extern struct bond_params bonding_defaults;
51extern struct bond_parm_tbl bond_mode_tbl[]; 51extern struct bond_parm_tbl bond_mode_tbl[];
52extern struct bond_parm_tbl bond_lacp_tbl[]; 52extern struct bond_parm_tbl bond_lacp_tbl[];
53extern struct bond_parm_tbl xmit_hashtype_tbl[]; 53extern struct bond_parm_tbl xmit_hashtype_tbl[];
54extern struct bond_parm_tbl arp_validate_tbl[];
54 55
55static int expected_refcount = -1; 56static int expected_refcount = -1;
56static struct class *netdev_class; 57static struct class *netdev_class;
@@ -503,6 +504,53 @@ out:
503static CLASS_DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, bonding_show_xmit_hash, bonding_store_xmit_hash); 504static CLASS_DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, bonding_show_xmit_hash, bonding_store_xmit_hash);
504 505
505/* 506/*
507 * Show and set arp_validate.
508 */
509static ssize_t bonding_show_arp_validate(struct class_device *cd, char *buf)
510{
511 struct bonding *bond = to_bond(cd);
512
513 return sprintf(buf, "%s %d\n",
514 arp_validate_tbl[bond->params.arp_validate].modename,
515 bond->params.arp_validate) + 1;
516}
517
518static ssize_t bonding_store_arp_validate(struct class_device *cd, const char *buf, size_t count)
519{
520 int new_value;
521 struct bonding *bond = to_bond(cd);
522
523 new_value = bond_parse_parm((char *)buf, arp_validate_tbl);
524 if (new_value < 0) {
525 printk(KERN_ERR DRV_NAME
526 ": %s: Ignoring invalid arp_validate value %s\n",
527 bond->dev->name, buf);
528 return -EINVAL;
529 }
530 if (new_value && (bond->params.mode != BOND_MODE_ACTIVEBACKUP)) {
531 printk(KERN_ERR DRV_NAME
532 ": %s: arp_validate only supported in active-backup mode.\n",
533 bond->dev->name);
534 return -EINVAL;
535 }
536 printk(KERN_INFO DRV_NAME ": %s: setting arp_validate to %s (%d).\n",
537 bond->dev->name, arp_validate_tbl[new_value].modename,
538 new_value);
539
540 if (!bond->params.arp_validate && new_value) {
541 bond_register_arp(bond);
542 } else if (bond->params.arp_validate && !new_value) {
543 bond_unregister_arp(bond);
544 }
545
546 bond->params.arp_validate = new_value;
547
548 return count;
549}
550
551static CLASS_DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate, bonding_store_arp_validate);
552
553/*
506 * Show and set the arp timer interval. There are two tricky bits 554 * Show and set the arp timer interval. There are two tricky bits
507 * here. First, if ARP monitoring is activated, then we must disable 555 * here. First, if ARP monitoring is activated, then we must disable
508 * MII monitoring. Second, if the ARP timer isn't running, we must 556 * MII monitoring. Second, if the ARP timer isn't running, we must
@@ -914,6 +962,11 @@ static ssize_t bonding_store_miimon(struct class_device *cd, const char *buf, si
914 "ARP monitoring. Disabling ARP monitoring...\n", 962 "ARP monitoring. Disabling ARP monitoring...\n",
915 bond->dev->name); 963 bond->dev->name);
916 bond->params.arp_interval = 0; 964 bond->params.arp_interval = 0;
965 if (bond->params.arp_validate) {
966 bond_unregister_arp(bond);
967 bond->params.arp_validate =
968 BOND_ARP_VALIDATE_NONE;
969 }
917 /* Kill ARP timer, else it brings bond's link down */ 970 /* Kill ARP timer, else it brings bond's link down */
918 if (bond->mii_timer.function) { 971 if (bond->mii_timer.function) {
919 printk(KERN_INFO DRV_NAME 972 printk(KERN_INFO DRV_NAME
@@ -1093,7 +1146,7 @@ static ssize_t bonding_store_active_slave(struct class_device *cd, const char *b
1093 strlen(slave->dev->name)) == 0) { 1146 strlen(slave->dev->name)) == 0) {
1094 old_active = bond->curr_active_slave; 1147 old_active = bond->curr_active_slave;
1095 new_active = slave; 1148 new_active = slave;
1096 if (new_active && (new_active == old_active)) { 1149 if (new_active == old_active) {
1097 /* do nothing */ 1150 /* do nothing */
1098 printk(KERN_INFO DRV_NAME 1151 printk(KERN_INFO DRV_NAME
1099 ": %s: %s is already the current active slave.\n", 1152 ": %s: %s is already the current active slave.\n",
@@ -1273,6 +1326,7 @@ static CLASS_DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, N
1273static struct attribute *per_bond_attrs[] = { 1326static struct attribute *per_bond_attrs[] = {
1274 &class_device_attr_slaves.attr, 1327 &class_device_attr_slaves.attr,
1275 &class_device_attr_mode.attr, 1328 &class_device_attr_mode.attr,
1329 &class_device_attr_arp_validate.attr,
1276 &class_device_attr_arp_interval.attr, 1330 &class_device_attr_arp_interval.attr,
1277 &class_device_attr_arp_ip_target.attr, 1331 &class_device_attr_arp_ip_target.attr,
1278 &class_device_attr_downdelay.attr, 1332 &class_device_attr_downdelay.attr,
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 0bdfe2c71453..dc434fb6da85 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -22,8 +22,8 @@
22#include "bond_3ad.h" 22#include "bond_3ad.h"
23#include "bond_alb.h" 23#include "bond_alb.h"
24 24
25#define DRV_VERSION "3.0.3" 25#define DRV_VERSION "3.1.1"
26#define DRV_RELDATE "March 23, 2006" 26#define DRV_RELDATE "September 26, 2006"
27#define DRV_NAME "bonding" 27#define DRV_NAME "bonding"
28#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver" 28#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver"
29 29
@@ -126,6 +126,7 @@ struct bond_params {
126 int xmit_policy; 126 int xmit_policy;
127 int miimon; 127 int miimon;
128 int arp_interval; 128 int arp_interval;
129 int arp_validate;
129 int use_carrier; 130 int use_carrier;
130 int updelay; 131 int updelay;
131 int downdelay; 132 int downdelay;
@@ -149,8 +150,9 @@ struct slave {
149 struct net_device *dev; /* first - useful for panic debug */ 150 struct net_device *dev; /* first - useful for panic debug */
150 struct slave *next; 151 struct slave *next;
151 struct slave *prev; 152 struct slave *prev;
152 s16 delay; 153 int delay;
153 u32 jiffies; 154 u32 jiffies;
155 u32 last_arp_rx;
154 s8 link; /* one of BOND_LINK_XXXX */ 156 s8 link; /* one of BOND_LINK_XXXX */
155 s8 state; /* one of BOND_STATE_XXXX */ 157 s8 state; /* one of BOND_STATE_XXXX */
156 u32 original_flags; 158 u32 original_flags;
@@ -198,6 +200,7 @@ struct bonding {
198 struct bond_params params; 200 struct bond_params params;
199 struct list_head vlan_list; 201 struct list_head vlan_list;
200 struct vlan_group *vlgrp; 202 struct vlan_group *vlgrp;
203 struct packet_type arp_mon_pt;
201}; 204};
202 205
203/** 206/**
@@ -228,6 +231,25 @@ static inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
228 return (struct bonding *)slave->dev->master->priv; 231 return (struct bonding *)slave->dev->master->priv;
229} 232}
230 233
234#define BOND_ARP_VALIDATE_NONE 0
235#define BOND_ARP_VALIDATE_ACTIVE (1 << BOND_STATE_ACTIVE)
236#define BOND_ARP_VALIDATE_BACKUP (1 << BOND_STATE_BACKUP)
237#define BOND_ARP_VALIDATE_ALL (BOND_ARP_VALIDATE_ACTIVE | \
238 BOND_ARP_VALIDATE_BACKUP)
239
240extern inline int slave_do_arp_validate(struct bonding *bond, struct slave *slave)
241{
242 return bond->params.arp_validate & (1 << slave->state);
243}
244
245extern inline u32 slave_last_rx(struct bonding *bond, struct slave *slave)
246{
247 if (slave_do_arp_validate(bond, slave))
248 return slave->last_arp_rx;
249
250 return slave->dev->last_rx;
251}
252
231static inline void bond_set_slave_inactive_flags(struct slave *slave) 253static inline void bond_set_slave_inactive_flags(struct slave *slave)
232{ 254{
233 struct bonding *bond = slave->dev->master->priv; 255 struct bonding *bond = slave->dev->master->priv;
@@ -235,12 +257,14 @@ static inline void bond_set_slave_inactive_flags(struct slave *slave)
235 bond->params.mode != BOND_MODE_ALB) 257 bond->params.mode != BOND_MODE_ALB)
236 slave->state = BOND_STATE_BACKUP; 258 slave->state = BOND_STATE_BACKUP;
237 slave->dev->priv_flags |= IFF_SLAVE_INACTIVE; 259 slave->dev->priv_flags |= IFF_SLAVE_INACTIVE;
260 if (slave_do_arp_validate(bond, slave))
261 slave->dev->priv_flags |= IFF_SLAVE_NEEDARP;
238} 262}
239 263
240static inline void bond_set_slave_active_flags(struct slave *slave) 264static inline void bond_set_slave_active_flags(struct slave *slave)
241{ 265{
242 slave->state = BOND_STATE_ACTIVE; 266 slave->state = BOND_STATE_ACTIVE;
243 slave->dev->priv_flags &= ~IFF_SLAVE_INACTIVE; 267 slave->dev->priv_flags &= ~(IFF_SLAVE_INACTIVE | IFF_SLAVE_NEEDARP);
244} 268}
245 269
246static inline void bond_set_master_3ad_flags(struct bonding *bond) 270static inline void bond_set_master_3ad_flags(struct bonding *bond)
@@ -284,6 +308,8 @@ int bond_parse_parm(char *mode_arg, struct bond_parm_tbl *tbl);
284const char *bond_mode_name(int mode); 308const char *bond_mode_name(int mode);
285void bond_select_active_slave(struct bonding *bond); 309void bond_select_active_slave(struct bonding *bond);
286void bond_change_active_slave(struct bonding *bond, struct slave *new_active); 310void bond_change_active_slave(struct bonding *bond, struct slave *new_active);
311void bond_register_arp(struct bonding *);
312void bond_unregister_arp(struct bonding *);
287 313
288#endif /* _LINUX_BONDING_H */ 314#endif /* _LINUX_BONDING_H */
289 315
diff --git a/drivers/net/dgrs.c b/drivers/net/dgrs.c
index e9361cb5f4cd..d0842527b369 100644
--- a/drivers/net/dgrs.c
+++ b/drivers/net/dgrs.c
@@ -110,7 +110,6 @@ static char version[] __initdata =
110 * DGRS include files 110 * DGRS include files
111 */ 111 */
112typedef unsigned char uchar; 112typedef unsigned char uchar;
113typedef unsigned int bool;
114#define vol volatile 113#define vol volatile
115 114
116#include "dgrs.h" 115#include "dgrs.h"
diff --git a/drivers/net/e100.c b/drivers/net/e100.c
index dc5e38aefca6..26073c345213 100644
--- a/drivers/net/e100.c
+++ b/drivers/net/e100.c
@@ -1,27 +1,27 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/100 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version.
10 9
11 This program is distributed in the hope that it will be useful, but WITHOUT 10 This program is distributed in the hope it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 26
27*******************************************************************************/ 27*******************************************************************************/
@@ -159,7 +159,7 @@
159 159
160#define DRV_NAME "e100" 160#define DRV_NAME "e100"
161#define DRV_EXT "-NAPI" 161#define DRV_EXT "-NAPI"
162#define DRV_VERSION "3.5.16-k2"DRV_EXT 162#define DRV_VERSION "3.5.17-k2"DRV_EXT
163#define DRV_DESCRIPTION "Intel(R) PRO/100 Network Driver" 163#define DRV_DESCRIPTION "Intel(R) PRO/100 Network Driver"
164#define DRV_COPYRIGHT "Copyright(c) 1999-2006 Intel Corporation" 164#define DRV_COPYRIGHT "Copyright(c) 1999-2006 Intel Corporation"
165#define PFX DRV_NAME ": " 165#define PFX DRV_NAME ": "
@@ -1657,13 +1657,14 @@ static int e100_tx_clean(struct nic *nic)
1657 1657
1658 spin_lock(&nic->cb_lock); 1658 spin_lock(&nic->cb_lock);
1659 1659
1660 DPRINTK(TX_DONE, DEBUG, "cb->status = 0x%04X\n",
1661 nic->cb_to_clean->status);
1662
1663 /* Clean CBs marked complete */ 1660 /* Clean CBs marked complete */
1664 for(cb = nic->cb_to_clean; 1661 for(cb = nic->cb_to_clean;
1665 cb->status & cpu_to_le16(cb_complete); 1662 cb->status & cpu_to_le16(cb_complete);
1666 cb = nic->cb_to_clean = cb->next) { 1663 cb = nic->cb_to_clean = cb->next) {
1664 DPRINTK(TX_DONE, DEBUG, "cb[%d]->status = 0x%04X\n",
1665 (int)(((void*)cb - (void*)nic->cbs)/sizeof(struct cb)),
1666 cb->status);
1667
1667 if(likely(cb->skb != NULL)) { 1668 if(likely(cb->skb != NULL)) {
1668 nic->net_stats.tx_packets++; 1669 nic->net_stats.tx_packets++;
1669 nic->net_stats.tx_bytes += cb->skb->len; 1670 nic->net_stats.tx_bytes += cb->skb->len;
@@ -2572,7 +2573,7 @@ static int __devinit e100_probe(struct pci_dev *pdev,
2572#ifdef CONFIG_NET_POLL_CONTROLLER 2573#ifdef CONFIG_NET_POLL_CONTROLLER
2573 netdev->poll_controller = e100_netpoll; 2574 netdev->poll_controller = e100_netpoll;
2574#endif 2575#endif
2575 strcpy(netdev->name, pci_name(pdev)); 2576 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
2576 2577
2577 nic = netdev_priv(netdev); 2578 nic = netdev_priv(netdev);
2578 nic->netdev = netdev; 2579 nic->netdev = netdev;
@@ -2714,68 +2715,56 @@ static void __devexit e100_remove(struct pci_dev *pdev)
2714 } 2715 }
2715} 2716}
2716 2717
2717#ifdef CONFIG_PM
2718static int e100_suspend(struct pci_dev *pdev, pm_message_t state) 2718static int e100_suspend(struct pci_dev *pdev, pm_message_t state)
2719{ 2719{
2720 struct net_device *netdev = pci_get_drvdata(pdev); 2720 struct net_device *netdev = pci_get_drvdata(pdev);
2721 struct nic *nic = netdev_priv(netdev); 2721 struct nic *nic = netdev_priv(netdev);
2722 int retval;
2723 2722
2724 if(netif_running(netdev)) 2723 if (netif_running(netdev))
2725 e100_down(nic); 2724 e100_down(nic);
2726 e100_hw_reset(nic); 2725 e100_hw_reset(nic);
2727 netif_device_detach(netdev); 2726 netif_device_detach(netdev);
2728 2727
2728#ifdef CONFIG_PM
2729 pci_save_state(pdev); 2729 pci_save_state(pdev);
2730 retval = pci_enable_wake(pdev, pci_choose_state(pdev, state), 2730 if (nic->flags & (wol_magic | e100_asf(nic)))
2731 nic->flags & (wol_magic | e100_asf(nic))); 2731#else
2732 if (retval) 2732 if (nic->flags & (wol_magic))
2733 DPRINTK(PROBE,ERR, "Error enabling wake\n"); 2733#endif
2734 pci_enable_wake(pdev, pci_choose_state(pdev, state), 1);
2735 else
2736 /* disable PME */
2737 pci_enable_wake(pdev, 0, 0);
2738
2734 pci_disable_device(pdev); 2739 pci_disable_device(pdev);
2735 retval = pci_set_power_state(pdev, pci_choose_state(pdev, state)); 2740 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2736 if (retval)
2737 DPRINTK(PROBE,ERR, "Error %d setting power state\n", retval);
2738 2741
2739 return 0; 2742 return 0;
2740} 2743}
2741 2744
2745#ifdef CONFIG_PM
2742static int e100_resume(struct pci_dev *pdev) 2746static int e100_resume(struct pci_dev *pdev)
2743{ 2747{
2744 struct net_device *netdev = pci_get_drvdata(pdev); 2748 struct net_device *netdev = pci_get_drvdata(pdev);
2745 struct nic *nic = netdev_priv(netdev); 2749 struct nic *nic = netdev_priv(netdev);
2746 int retval;
2747 2750
2748 retval = pci_set_power_state(pdev, PCI_D0); 2751 pci_set_power_state(pdev, PCI_D0);
2749 if (retval)
2750 DPRINTK(PROBE,ERR, "Error waking adapter\n");
2751 pci_restore_state(pdev); 2752 pci_restore_state(pdev);
2752 /* ack any pending wake events, disable PME */ 2753 /* ack any pending wake events, disable PME */
2753 retval = pci_enable_wake(pdev, 0, 0); 2754 pci_enable_wake(pdev, 0, 0);
2754 if (retval)
2755 DPRINTK(PROBE,ERR, "Error clearing wake events\n");
2756 2755
2757 netif_device_attach(netdev); 2756 netif_device_attach(netdev);
2758 if(netif_running(netdev)) 2757 if (netif_running(netdev))
2759 e100_up(nic); 2758 e100_up(nic);
2760 2759
2761 return 0; 2760 return 0;
2762} 2761}
2763#endif 2762#endif /* CONFIG_PM */
2764 2763
2765 2764
2766static void e100_shutdown(struct pci_dev *pdev) 2765static void e100_shutdown(struct pci_dev *pdev)
2767{ 2766{
2768 struct net_device *netdev = pci_get_drvdata(pdev); 2767 e100_suspend(pdev, PMSG_SUSPEND);
2769 struct nic *nic = netdev_priv(netdev);
2770 int retval;
2771
2772#ifdef CONFIG_PM
2773 retval = pci_enable_wake(pdev, 0, nic->flags & (wol_magic | e100_asf(nic)));
2774#else
2775 retval = pci_enable_wake(pdev, 0, nic->flags & (wol_magic));
2776#endif
2777 if (retval)
2778 DPRINTK(PROBE,ERR, "Error enabling wake\n");
2779} 2768}
2780 2769
2781/* ------------------ PCI Error Recovery infrastructure -------------- */ 2770/* ------------------ PCI Error Recovery infrastructure -------------- */
@@ -2859,8 +2848,9 @@ static struct pci_driver e100_driver = {
2859 .id_table = e100_id_table, 2848 .id_table = e100_id_table,
2860 .probe = e100_probe, 2849 .probe = e100_probe,
2861 .remove = __devexit_p(e100_remove), 2850 .remove = __devexit_p(e100_remove),
2862#ifdef CONFIG_PM 2851 /* Power Management hooks */
2863 .suspend = e100_suspend, 2852 .suspend = e100_suspend,
2853#ifdef CONFIG_PM
2864 .resume = e100_resume, 2854 .resume = e100_resume,
2865#endif 2855#endif
2866 .shutdown = e100_shutdown, 2856 .shutdown = e100_shutdown,
diff --git a/drivers/net/e1000/LICENSE b/drivers/net/e1000/LICENSE
deleted file mode 100644
index 5f297e5bb465..000000000000
--- a/drivers/net/e1000/LICENSE
+++ /dev/null
@@ -1,339 +0,0 @@
1
2"This software program is licensed subject to the GNU General Public License
3(GPL). Version 2, June 1991, available at
4<http://www.fsf.org/copyleft/gpl.html>"
5
6GNU General Public License
7
8Version 2, June 1991
9
10Copyright (C) 1989, 1991 Free Software Foundation, Inc.
1159 Temple Place - Suite 330, Boston, MA 02111-1307, USA
12
13Everyone is permitted to copy and distribute verbatim copies of this license
14document, but changing it is not allowed.
15
16Preamble
17
18The licenses for most software are designed to take away your freedom to
19share and change it. By contrast, the GNU General Public License is intended
20to guarantee your freedom to share and change free software--to make sure
21the software is free for all its users. This General Public License applies
22to most of the Free Software Foundation's software and to any other program
23whose authors commit to using it. (Some other Free Software Foundation
24software is covered by the GNU Library General Public License instead.) You
25can apply it to your programs, too.
26
27When we speak of free software, we are referring to freedom, not price. Our
28General Public Licenses are designed to make sure that you have the freedom
29to distribute copies of free software (and charge for this service if you
30wish), that you receive source code or can get it if you want it, that you
31can change the software or use pieces of it in new free programs; and that
32you know you can do these things.
33
34To protect your rights, we need to make restrictions that forbid anyone to
35deny you these rights or to ask you to surrender the rights. These
36restrictions translate to certain responsibilities for you if you distribute
37copies of the software, or if you modify it.
38
39For example, if you distribute copies of such a program, whether gratis or
40for a fee, you must give the recipients all the rights that you have. You
41must make sure that they, too, receive or can get the source code. And you
42must show them these terms so they know their rights.
43
44We protect your rights with two steps: (1) copyright the software, and (2)
45offer you this license which gives you legal permission to copy, distribute
46and/or modify the software.
47
48Also, for each author's protection and ours, we want to make certain that
49everyone understands that there is no warranty for this free software. If
50the software is modified by someone else and passed on, we want its
51recipients to know that what they have is not the original, so that any
52problems introduced by others will not reflect on the original authors'
53reputations.
54
55Finally, any free program is threatened constantly by software patents. We
56wish to avoid the danger that redistributors of a free program will
57individually obtain patent licenses, in effect making the program
58proprietary. To prevent this, we have made it clear that any patent must be
59licensed for everyone's free use or not licensed at all.
60
61The precise terms and conditions for copying, distribution and modification
62follow.
63
64TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
65
660. This License applies to any program or other work which contains a notice
67 placed by the copyright holder saying it may be distributed under the
68 terms of this General Public License. The "Program", below, refers to any
69 such program or work, and a "work based on the Program" means either the
70 Program or any derivative work under copyright law: that is to say, a
71 work containing the Program or a portion of it, either verbatim or with
72 modifications and/or translated into another language. (Hereinafter,
73 translation is included without limitation in the term "modification".)
74 Each licensee is addressed as "you".
75
76 Activities other than copying, distribution and modification are not
77 covered by this License; they are outside its scope. The act of running
78 the Program is not restricted, and the output from the Program is covered
79 only if its contents constitute a work based on the Program (independent
80 of having been made by running the Program). Whether that is true depends
81 on what the Program does.
82
831. You may copy and distribute verbatim copies of the Program's source code
84 as you receive it, in any medium, provided that you conspicuously and
85 appropriately publish on each copy an appropriate copyright notice and
86 disclaimer of warranty; keep intact all the notices that refer to this
87 License and to the absence of any warranty; and give any other recipients
88 of the Program a copy of this License along with the Program.
89
90 You may charge a fee for the physical act of transferring a copy, and you
91 may at your option offer warranty protection in exchange for a fee.
92
932. You may modify your copy or copies of the Program or any portion of it,
94 thus forming a work based on the Program, and copy and distribute such
95 modifications or work under the terms of Section 1 above, provided that
96 you also meet all of these conditions:
97
98 * a) You must cause the modified files to carry prominent notices stating
99 that you changed the files and the date of any change.
100
101 * b) You must cause any work that you distribute or publish, that in
102 whole or in part contains or is derived from the Program or any part
103 thereof, to be licensed as a whole at no charge to all third parties
104 under the terms of this License.
105
106 * c) If the modified program normally reads commands interactively when
107 run, you must cause it, when started running for such interactive
108 use in the most ordinary way, to print or display an announcement
109 including an appropriate copyright notice and a notice that there is
110 no warranty (or else, saying that you provide a warranty) and that
111 users may redistribute the program under these conditions, and
112 telling the user how to view a copy of this License. (Exception: if
113 the Program itself is interactive but does not normally print such
114 an announcement, your work based on the Program is not required to
115 print an announcement.)
116
117 These requirements apply to the modified work as a whole. If identifiable
118 sections of that work are not derived from the Program, and can be
119 reasonably considered independent and separate works in themselves, then
120 this License, and its terms, do not apply to those sections when you
121 distribute them as separate works. But when you distribute the same
122 sections as part of a whole which is a work based on the Program, the
123 distribution of the whole must be on the terms of this License, whose
124 permissions for other licensees extend to the entire whole, and thus to
125 each and every part regardless of who wrote it.
126
127 Thus, it is not the intent of this section to claim rights or contest
128 your rights to work written entirely by you; rather, the intent is to
129 exercise the right to control the distribution of derivative or
130 collective works based on the Program.
131
132 In addition, mere aggregation of another work not based on the Program
133 with the Program (or with a work based on the Program) on a volume of a
134 storage or distribution medium does not bring the other work under the
135 scope of this License.
136
1373. You may copy and distribute the Program (or a work based on it, under
138 Section 2) in object code or executable form under the terms of Sections
139 1 and 2 above provided that you also do one of the following:
140
141 * a) Accompany it with the complete corresponding machine-readable source
142 code, which must be distributed under the terms of Sections 1 and 2
143 above on a medium customarily used for software interchange; or,
144
145 * b) Accompany it with a written offer, valid for at least three years,
146 to give any third party, for a charge no more than your cost of
147 physically performing source distribution, a complete machine-
148 readable copy of the corresponding source code, to be distributed
149 under the terms of Sections 1 and 2 above on a medium customarily
150 used for software interchange; or,
151
152 * c) Accompany it with the information you received as to the offer to
153 distribute corresponding source code. (This alternative is allowed
154 only for noncommercial distribution and only if you received the
155 program in object code or executable form with such an offer, in
156 accord with Subsection b above.)
157
158 The source code for a work means the preferred form of the work for
159 making modifications to it. For an executable work, complete source code
160 means all the source code for all modules it contains, plus any
161 associated interface definition files, plus the scripts used to control
162 compilation and installation of the executable. However, as a special
163 exception, the source code distributed need not include anything that is
164 normally distributed (in either source or binary form) with the major
165 components (compiler, kernel, and so on) of the operating system on which
166 the executable runs, unless that component itself accompanies the
167 executable.
168
169 If distribution of executable or object code is made by offering access
170 to copy from a designated place, then offering equivalent access to copy
171 the source code from the same place counts as distribution of the source
172 code, even though third parties are not compelled to copy the source
173 along with the object code.
174
1754. You may not copy, modify, sublicense, or distribute the Program except as
176 expressly provided under this License. Any attempt otherwise to copy,
177 modify, sublicense or distribute the Program is void, and will
178 automatically terminate your rights under this License. However, parties
179 who have received copies, or rights, from you under this License will not
180 have their licenses terminated so long as such parties remain in full
181 compliance.
182
1835. You are not required to accept this License, since you have not signed
184 it. However, nothing else grants you permission to modify or distribute
185 the Program or its derivative works. These actions are prohibited by law
186 if you do not accept this License. Therefore, by modifying or
187 distributing the Program (or any work based on the Program), you
188 indicate your acceptance of this License to do so, and all its terms and
189 conditions for copying, distributing or modifying the Program or works
190 based on it.
191
1926. Each time you redistribute the Program (or any work based on the
193 Program), the recipient automatically receives a license from the
194 original licensor to copy, distribute or modify the Program subject to
195 these terms and conditions. You may not impose any further restrictions
196 on the recipients' exercise of the rights granted herein. You are not
197 responsible for enforcing compliance by third parties to this License.
198
1997. If, as a consequence of a court judgment or allegation of patent
200 infringement or for any other reason (not limited to patent issues),
201 conditions are imposed on you (whether by court order, agreement or
202 otherwise) that contradict the conditions of this License, they do not
203 excuse you from the conditions of this License. If you cannot distribute
204 so as to satisfy simultaneously your obligations under this License and
205 any other pertinent obligations, then as a consequence you may not
206 distribute the Program at all. For example, if a patent license would
207 not permit royalty-free redistribution of the Program by all those who
208 receive copies directly or indirectly through you, then the only way you
209 could satisfy both it and this License would be to refrain entirely from
210 distribution of the Program.
211
212 If any portion of this section is held invalid or unenforceable under any
213 particular circumstance, the balance of the section is intended to apply
214 and the section as a whole is intended to apply in other circumstances.
215
216 It is not the purpose of this section to induce you to infringe any
217 patents or other property right claims or to contest validity of any
218 such claims; this section has the sole purpose of protecting the
219 integrity of the free software distribution system, which is implemented
220 by public license practices. Many people have made generous contributions
221 to the wide range of software distributed through that system in
222 reliance on consistent application of that system; it is up to the
223 author/donor to decide if he or she is willing to distribute software
224 through any other system and a licensee cannot impose that choice.
225
226 This section is intended to make thoroughly clear what is believed to be
227 a consequence of the rest of this License.
228
2298. If the distribution and/or use of the Program is restricted in certain
230 countries either by patents or by copyrighted interfaces, the original
231 copyright holder who places the Program under this License may add an
232 explicit geographical distribution limitation excluding those countries,
233 so that distribution is permitted only in or among countries not thus
234 excluded. In such case, this License incorporates the limitation as if
235 written in the body of this License.
236
2379. The Free Software Foundation may publish revised and/or new versions of
238 the General Public License from time to time. Such new versions will be
239 similar in spirit to the present version, but may differ in detail to
240 address new problems or concerns.
241
242 Each version is given a distinguishing version number. If the Program
243 specifies a version number of this License which applies to it and "any
244 later version", you have the option of following the terms and
245 conditions either of that version or of any later version published by
246 the Free Software Foundation. If the Program does not specify a version
247 number of this License, you may choose any version ever published by the
248 Free Software Foundation.
249
25010. If you wish to incorporate parts of the Program into other free programs
251 whose distribution conditions are different, write to the author to ask
252 for permission. For software which is copyrighted by the Free Software
253 Foundation, write to the Free Software Foundation; we sometimes make
254 exceptions for this. Our decision will be guided by the two goals of
255 preserving the free status of all derivatives of our free software and
256 of promoting the sharing and reuse of software generally.
257
258 NO WARRANTY
259
26011. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
264 EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
265 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
266 ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH
267 YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
268 NECESSARY SERVICING, REPAIR OR CORRECTION.
269
27012. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR
273 DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL
274 DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM
275 (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
276 INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF
277 THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR
278 OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
279
280END OF TERMS AND CONDITIONS
281
282How to Apply These Terms to Your New Programs
283
284If you develop a new program, and you want it to be of the greatest
285possible use to the public, the best way to achieve this is to make it free
286software which everyone can redistribute and change under these terms.
287
288To do so, attach the following notices to the program. It is safest to
289attach them to the start of each source file to most effectively convey the
290exclusion of warranty; and each file should have at least the "copyright"
291line and a pointer to where the full notice is found.
292
293one line to give the program's name and an idea of what it does.
294Copyright (C) yyyy name of author
295
296This program is free software; you can redistribute it and/or modify it
297under the terms of the GNU General Public License as published by the Free
298Software Foundation; either version 2 of the License, or (at your option)
299any later version.
300
301This program is distributed in the hope that it will be useful, but WITHOUT
302ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
303FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
304more details.
305
306You should have received a copy of the GNU General Public License along with
307this program; if not, write to the Free Software Foundation, Inc., 59
308Temple Place - Suite 330, Boston, MA 02111-1307, USA.
309
310Also add information on how to contact you by electronic and paper mail.
311
312If the program is interactive, make it output a short notice like this when
313it starts in an interactive mode:
314
315Gnomovision version 69, Copyright (C) year name of author Gnomovision comes
316with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free
317software, and you are welcome to redistribute it under certain conditions;
318type 'show c' for details.
319
320The hypothetical commands 'show w' and 'show c' should show the appropriate
321parts of the General Public License. Of course, the commands you use may be
322called something other than 'show w' and 'show c'; they could even be
323mouse-clicks or menu items--whatever suits your program.
324
325You should also get your employer (if you work as a programmer) or your
326school, if any, to sign a "copyright disclaimer" for the program, if
327necessary. Here is a sample; alter the names:
328
329Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330'Gnomovision' (which makes passes at compilers) written by James Hacker.
331
332signature of Ty Coon, 1 April 1989
333Ty Coon, President of Vice
334
335This General Public License does not permit incorporating your program into
336proprietary programs. If your program is a subroutine library, you may
337consider it more useful to permit linking proprietary applications with the
338library. If this is what you want to do, use the GNU Library General Public
339License instead of this License.
diff --git a/drivers/net/e1000/Makefile b/drivers/net/e1000/Makefile
index 5dea2b7dea4d..4a6ab1522451 100644
--- a/drivers/net/e1000/Makefile
+++ b/drivers/net/e1000/Makefile
@@ -1,25 +1,24 @@
1################################################################################ 1################################################################################
2# 2#
3# 3# Intel PRO/1000 Linux driver
4# Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4# Copyright(c) 1999 - 2006 Intel Corporation.
5# 5#
6# This program is free software; you can redistribute it and/or modify it 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 7# under the terms and conditions of the GNU General Public License,
8# Software Foundation; either version 2 of the License, or (at your option) 8# version 2, as published by the Free Software Foundation.
9# any later version. 9#
10# 10# This program is distributed in the hope it will be useful, but WITHOUT
11# This program is distributed in the hope that it will be useful, but WITHOUT 11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14# more details. 13# more details.
15# 14#
16# You should have received a copy of the GNU General Public License along with 15# 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 16# this program; if not, write to the Free Software Foundation, Inc.,
18# Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17# 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19# 18#
20# The full GNU General Public License is included in this distribution in the 19# The full GNU General Public License is included in this distribution in
21# file called LICENSE. 20# the file called "COPYING".
22# 21#
23# Contact Information: 22# Contact Information:
24# Linux NICS <linux.nics@intel.com> 23# Linux NICS <linux.nics@intel.com>
25# e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> 24# e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
diff --git a/drivers/net/e1000/e1000.h b/drivers/net/e1000/e1000.h
index 98afa9c2057e..7ecce438d258 100644
--- a/drivers/net/e1000/e1000.h
+++ b/drivers/net/e1000/e1000.h
@@ -1,25 +1,24 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version. 9
10 10 This program is distributed in the hope it will be useful, but WITHOUT
11 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
25 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> 24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
@@ -346,29 +345,9 @@ struct e1000_adapter {
346}; 345};
347 346
348enum e1000_state_t { 347enum e1000_state_t {
349 __E1000_DRIVER_TESTING, 348 __E1000_TESTING,
350 __E1000_RESETTING, 349 __E1000_RESETTING,
350 __E1000_DOWN
351}; 351};
352 352
353/* e1000_main.c */
354extern char e1000_driver_name[];
355extern char e1000_driver_version[];
356int e1000_up(struct e1000_adapter *adapter);
357void e1000_down(struct e1000_adapter *adapter);
358void e1000_reset(struct e1000_adapter *adapter);
359void e1000_reinit_locked(struct e1000_adapter *adapter);
360int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
361void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
362int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
363void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
364void e1000_update_stats(struct e1000_adapter *adapter);
365int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
366
367/* e1000_ethtool.c */
368void e1000_set_ethtool_ops(struct net_device *netdev);
369
370/* e1000_param.c */
371void e1000_check_options(struct e1000_adapter *adapter);
372
373
374#endif /* _E1000_H_ */ 353#endif /* _E1000_H_ */
diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c
index e39aa1fc4d1e..778ede3c0216 100644
--- a/drivers/net/e1000/e1000_ethtool.c
+++ b/drivers/net/e1000/e1000_ethtool.c
@@ -1,25 +1,24 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version. 9
10 10 This program is distributed in the hope it will be useful, but WITHOUT
11 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
25 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> 24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
@@ -33,6 +32,21 @@
33 32
34#include <asm/uaccess.h> 33#include <asm/uaccess.h>
35 34
35extern char e1000_driver_name[];
36extern char e1000_driver_version[];
37
38extern int e1000_up(struct e1000_adapter *adapter);
39extern void e1000_down(struct e1000_adapter *adapter);
40extern void e1000_reinit_locked(struct e1000_adapter *adapter);
41extern void e1000_reset(struct e1000_adapter *adapter);
42extern int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
43extern int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
44extern int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
45extern void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
46extern void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
47extern void e1000_update_stats(struct e1000_adapter *adapter);
48
49
36struct e1000_stats { 50struct e1000_stats {
37 char stat_string[ETH_GSTRING_LEN]; 51 char stat_string[ETH_GSTRING_LEN];
38 int sizeof_stat; 52 int sizeof_stat;
@@ -42,26 +56,30 @@ struct e1000_stats {
42#define E1000_STAT(m) sizeof(((struct e1000_adapter *)0)->m), \ 56#define E1000_STAT(m) sizeof(((struct e1000_adapter *)0)->m), \
43 offsetof(struct e1000_adapter, m) 57 offsetof(struct e1000_adapter, m)
44static const struct e1000_stats e1000_gstrings_stats[] = { 58static const struct e1000_stats e1000_gstrings_stats[] = {
45 { "rx_packets", E1000_STAT(net_stats.rx_packets) }, 59 { "rx_packets", E1000_STAT(stats.gprc) },
46 { "tx_packets", E1000_STAT(net_stats.tx_packets) }, 60 { "tx_packets", E1000_STAT(stats.gptc) },
47 { "rx_bytes", E1000_STAT(net_stats.rx_bytes) }, 61 { "rx_bytes", E1000_STAT(stats.gorcl) },
48 { "tx_bytes", E1000_STAT(net_stats.tx_bytes) }, 62 { "tx_bytes", E1000_STAT(stats.gotcl) },
49 { "rx_errors", E1000_STAT(net_stats.rx_errors) }, 63 { "rx_broadcast", E1000_STAT(stats.bprc) },
50 { "tx_errors", E1000_STAT(net_stats.tx_errors) }, 64 { "tx_broadcast", E1000_STAT(stats.bptc) },
65 { "rx_multicast", E1000_STAT(stats.mprc) },
66 { "tx_multicast", E1000_STAT(stats.mptc) },
67 { "rx_errors", E1000_STAT(stats.rxerrc) },
68 { "tx_errors", E1000_STAT(stats.txerrc) },
51 { "tx_dropped", E1000_STAT(net_stats.tx_dropped) }, 69 { "tx_dropped", E1000_STAT(net_stats.tx_dropped) },
52 { "multicast", E1000_STAT(net_stats.multicast) }, 70 { "multicast", E1000_STAT(stats.mprc) },
53 { "collisions", E1000_STAT(net_stats.collisions) }, 71 { "collisions", E1000_STAT(stats.colc) },
54 { "rx_length_errors", E1000_STAT(net_stats.rx_length_errors) }, 72 { "rx_length_errors", E1000_STAT(stats.rlerrc) },
55 { "rx_over_errors", E1000_STAT(net_stats.rx_over_errors) }, 73 { "rx_over_errors", E1000_STAT(net_stats.rx_over_errors) },
56 { "rx_crc_errors", E1000_STAT(net_stats.rx_crc_errors) }, 74 { "rx_crc_errors", E1000_STAT(stats.crcerrs) },
57 { "rx_frame_errors", E1000_STAT(net_stats.rx_frame_errors) }, 75 { "rx_frame_errors", E1000_STAT(net_stats.rx_frame_errors) },
58 { "rx_no_buffer_count", E1000_STAT(stats.rnbc) }, 76 { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
59 { "rx_missed_errors", E1000_STAT(net_stats.rx_missed_errors) }, 77 { "rx_missed_errors", E1000_STAT(stats.mpc) },
60 { "tx_aborted_errors", E1000_STAT(net_stats.tx_aborted_errors) }, 78 { "tx_aborted_errors", E1000_STAT(stats.ecol) },
61 { "tx_carrier_errors", E1000_STAT(net_stats.tx_carrier_errors) }, 79 { "tx_carrier_errors", E1000_STAT(stats.tncrs) },
62 { "tx_fifo_errors", E1000_STAT(net_stats.tx_fifo_errors) }, 80 { "tx_fifo_errors", E1000_STAT(net_stats.tx_fifo_errors) },
63 { "tx_heartbeat_errors", E1000_STAT(net_stats.tx_heartbeat_errors) }, 81 { "tx_heartbeat_errors", E1000_STAT(net_stats.tx_heartbeat_errors) },
64 { "tx_window_errors", E1000_STAT(net_stats.tx_window_errors) }, 82 { "tx_window_errors", E1000_STAT(stats.latecol) },
65 { "tx_abort_late_coll", E1000_STAT(stats.latecol) }, 83 { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
66 { "tx_deferred_ok", E1000_STAT(stats.dc) }, 84 { "tx_deferred_ok", E1000_STAT(stats.dc) },
67 { "tx_single_coll_ok", E1000_STAT(stats.scc) }, 85 { "tx_single_coll_ok", E1000_STAT(stats.scc) },
@@ -193,13 +211,9 @@ e1000_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
193 ADVERTISED_FIBRE | 211 ADVERTISED_FIBRE |
194 ADVERTISED_Autoneg; 212 ADVERTISED_Autoneg;
195 else 213 else
196 hw->autoneg_advertised = ADVERTISED_10baseT_Half | 214 hw->autoneg_advertised = ecmd->advertising |
197 ADVERTISED_10baseT_Full | 215 ADVERTISED_TP |
198 ADVERTISED_100baseT_Half | 216 ADVERTISED_Autoneg;
199 ADVERTISED_100baseT_Full |
200 ADVERTISED_1000baseT_Full|
201 ADVERTISED_Autoneg |
202 ADVERTISED_TP;
203 ecmd->advertising = hw->autoneg_advertised; 217 ecmd->advertising = hw->autoneg_advertised;
204 } else 218 } else
205 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) { 219 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
@@ -229,11 +243,11 @@ e1000_get_pauseparam(struct net_device *netdev,
229 pause->autoneg = 243 pause->autoneg =
230 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE); 244 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
231 245
232 if (hw->fc == e1000_fc_rx_pause) 246 if (hw->fc == E1000_FC_RX_PAUSE)
233 pause->rx_pause = 1; 247 pause->rx_pause = 1;
234 else if (hw->fc == e1000_fc_tx_pause) 248 else if (hw->fc == E1000_FC_TX_PAUSE)
235 pause->tx_pause = 1; 249 pause->tx_pause = 1;
236 else if (hw->fc == e1000_fc_full) { 250 else if (hw->fc == E1000_FC_FULL) {
237 pause->rx_pause = 1; 251 pause->rx_pause = 1;
238 pause->tx_pause = 1; 252 pause->tx_pause = 1;
239 } 253 }
@@ -253,13 +267,13 @@ e1000_set_pauseparam(struct net_device *netdev,
253 msleep(1); 267 msleep(1);
254 268
255 if (pause->rx_pause && pause->tx_pause) 269 if (pause->rx_pause && pause->tx_pause)
256 hw->fc = e1000_fc_full; 270 hw->fc = E1000_FC_FULL;
257 else if (pause->rx_pause && !pause->tx_pause) 271 else if (pause->rx_pause && !pause->tx_pause)
258 hw->fc = e1000_fc_rx_pause; 272 hw->fc = E1000_FC_RX_PAUSE;
259 else if (!pause->rx_pause && pause->tx_pause) 273 else if (!pause->rx_pause && pause->tx_pause)
260 hw->fc = e1000_fc_tx_pause; 274 hw->fc = E1000_FC_TX_PAUSE;
261 else if (!pause->rx_pause && !pause->tx_pause) 275 else if (!pause->rx_pause && !pause->tx_pause)
262 hw->fc = e1000_fc_none; 276 hw->fc = E1000_FC_NONE;
263 277
264 hw->original_fc = hw->fc; 278 hw->original_fc = hw->fc;
265 279
@@ -632,8 +646,8 @@ e1000_set_ringparam(struct net_device *netdev,
632{ 646{
633 struct e1000_adapter *adapter = netdev_priv(netdev); 647 struct e1000_adapter *adapter = netdev_priv(netdev);
634 e1000_mac_type mac_type = adapter->hw.mac_type; 648 e1000_mac_type mac_type = adapter->hw.mac_type;
635 struct e1000_tx_ring *txdr, *tx_old, *tx_new; 649 struct e1000_tx_ring *txdr, *tx_old;
636 struct e1000_rx_ring *rxdr, *rx_old, *rx_new; 650 struct e1000_rx_ring *rxdr, *rx_old;
637 int i, err, tx_ring_size, rx_ring_size; 651 int i, err, tx_ring_size, rx_ring_size;
638 652
639 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) 653 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
@@ -651,23 +665,17 @@ e1000_set_ringparam(struct net_device *netdev,
651 tx_old = adapter->tx_ring; 665 tx_old = adapter->tx_ring;
652 rx_old = adapter->rx_ring; 666 rx_old = adapter->rx_ring;
653 667
654 adapter->tx_ring = kmalloc(tx_ring_size, GFP_KERNEL); 668 err = -ENOMEM;
655 if (!adapter->tx_ring) { 669 txdr = kzalloc(tx_ring_size, GFP_KERNEL);
656 err = -ENOMEM; 670 if (!txdr)
657 goto err_setup_rx; 671 goto err_alloc_tx;
658 }
659 memset(adapter->tx_ring, 0, tx_ring_size);
660 672
661 adapter->rx_ring = kmalloc(rx_ring_size, GFP_KERNEL); 673 rxdr = kzalloc(rx_ring_size, GFP_KERNEL);
662 if (!adapter->rx_ring) { 674 if (!rxdr)
663 kfree(adapter->tx_ring); 675 goto err_alloc_rx;
664 err = -ENOMEM;
665 goto err_setup_rx;
666 }
667 memset(adapter->rx_ring, 0, rx_ring_size);
668 676
669 txdr = adapter->tx_ring; 677 adapter->tx_ring = txdr;
670 rxdr = adapter->rx_ring; 678 adapter->rx_ring = rxdr;
671 679
672 rxdr->count = max(ring->rx_pending,(uint32_t)E1000_MIN_RXD); 680 rxdr->count = max(ring->rx_pending,(uint32_t)E1000_MIN_RXD);
673 rxdr->count = min(rxdr->count,(uint32_t)(mac_type < e1000_82544 ? 681 rxdr->count = min(rxdr->count,(uint32_t)(mac_type < e1000_82544 ?
@@ -694,16 +702,14 @@ e1000_set_ringparam(struct net_device *netdev,
694 /* save the new, restore the old in order to free it, 702 /* save the new, restore the old in order to free it,
695 * then restore the new back again */ 703 * then restore the new back again */
696 704
697 rx_new = adapter->rx_ring;
698 tx_new = adapter->tx_ring;
699 adapter->rx_ring = rx_old; 705 adapter->rx_ring = rx_old;
700 adapter->tx_ring = tx_old; 706 adapter->tx_ring = tx_old;
701 e1000_free_all_rx_resources(adapter); 707 e1000_free_all_rx_resources(adapter);
702 e1000_free_all_tx_resources(adapter); 708 e1000_free_all_tx_resources(adapter);
703 kfree(tx_old); 709 kfree(tx_old);
704 kfree(rx_old); 710 kfree(rx_old);
705 adapter->rx_ring = rx_new; 711 adapter->rx_ring = rxdr;
706 adapter->tx_ring = tx_new; 712 adapter->tx_ring = txdr;
707 if ((err = e1000_up(adapter))) 713 if ((err = e1000_up(adapter)))
708 goto err_setup; 714 goto err_setup;
709 } 715 }
@@ -715,6 +721,10 @@ err_setup_tx:
715err_setup_rx: 721err_setup_rx:
716 adapter->rx_ring = rx_old; 722 adapter->rx_ring = rx_old;
717 adapter->tx_ring = tx_old; 723 adapter->tx_ring = tx_old;
724 kfree(rxdr);
725err_alloc_rx:
726 kfree(txdr);
727err_alloc_tx:
718 e1000_up(adapter); 728 e1000_up(adapter);
719err_setup: 729err_setup:
720 clear_bit(__E1000_RESETTING, &adapter->flags); 730 clear_bit(__E1000_RESETTING, &adapter->flags);
@@ -1610,7 +1620,7 @@ e1000_diag_test(struct net_device *netdev,
1610 struct e1000_adapter *adapter = netdev_priv(netdev); 1620 struct e1000_adapter *adapter = netdev_priv(netdev);
1611 boolean_t if_running = netif_running(netdev); 1621 boolean_t if_running = netif_running(netdev);
1612 1622
1613 set_bit(__E1000_DRIVER_TESTING, &adapter->flags); 1623 set_bit(__E1000_TESTING, &adapter->flags);
1614 if (eth_test->flags == ETH_TEST_FL_OFFLINE) { 1624 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1615 /* Offline tests */ 1625 /* Offline tests */
1616 1626
@@ -1655,7 +1665,7 @@ e1000_diag_test(struct net_device *netdev,
1655 adapter->hw.autoneg = autoneg; 1665 adapter->hw.autoneg = autoneg;
1656 1666
1657 e1000_reset(adapter); 1667 e1000_reset(adapter);
1658 clear_bit(__E1000_DRIVER_TESTING, &adapter->flags); 1668 clear_bit(__E1000_TESTING, &adapter->flags);
1659 if (if_running) 1669 if (if_running)
1660 dev_open(netdev); 1670 dev_open(netdev);
1661 } else { 1671 } else {
@@ -1670,7 +1680,7 @@ e1000_diag_test(struct net_device *netdev,
1670 data[2] = 0; 1680 data[2] = 0;
1671 data[3] = 0; 1681 data[3] = 0;
1672 1682
1673 clear_bit(__E1000_DRIVER_TESTING, &adapter->flags); 1683 clear_bit(__E1000_TESTING, &adapter->flags);
1674 } 1684 }
1675 msleep_interruptible(4 * 1000); 1685 msleep_interruptible(4 * 1000);
1676} 1686}
diff --git a/drivers/net/e1000/e1000_hw.c b/drivers/net/e1000/e1000_hw.c
index 10b8c8c25325..65077f39da69 100644
--- a/drivers/net/e1000/e1000_hw.c
+++ b/drivers/net/e1000/e1000_hw.c
@@ -1,25 +1,24 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version. 9
10 10 This program is distributed in the hope it will be useful, but WITHOUT
11 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
25 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> 24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
@@ -34,6 +33,63 @@
34 33
35#include "e1000_hw.h" 34#include "e1000_hw.h"
36 35
36static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
37static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
38static int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data);
39static int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data);
40static int32_t e1000_get_software_semaphore(struct e1000_hw *hw);
41static void e1000_release_software_semaphore(struct e1000_hw *hw);
42
43static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
44static int32_t e1000_check_downshift(struct e1000_hw *hw);
45static int32_t e1000_check_polarity(struct e1000_hw *hw, e1000_rev_polarity *polarity);
46static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
47static void e1000_clear_vfta(struct e1000_hw *hw);
48static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
49static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw, boolean_t link_up);
50static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
51static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
52static int32_t e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank);
53static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
54static int32_t e1000_get_cable_length(struct e1000_hw *hw, uint16_t *min_length, uint16_t *max_length);
55static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
56static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
57static int32_t e1000_get_software_flag(struct e1000_hw *hw);
58static int32_t e1000_ich8_cycle_init(struct e1000_hw *hw);
59static int32_t e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout);
60static int32_t e1000_id_led_init(struct e1000_hw *hw);
61static int32_t e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw, uint32_t cnf_base_addr, uint32_t cnf_size);
62static int32_t e1000_init_lcd_from_nvm(struct e1000_hw *hw);
63static void e1000_init_rx_addrs(struct e1000_hw *hw);
64static void e1000_initialize_hardware_bits(struct e1000_hw *hw);
65static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
66static int32_t e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw);
67static int32_t e1000_mng_enable_host_if(struct e1000_hw *hw);
68static int32_t e1000_mng_host_if_write(struct e1000_hw *hw, uint8_t *buffer, uint16_t length, uint16_t offset, uint8_t *sum);
69static int32_t e1000_mng_write_cmd_header(struct e1000_hw* hw, struct e1000_host_mng_command_header* hdr);
70static int32_t e1000_mng_write_commit(struct e1000_hw *hw);
71static int32_t e1000_phy_ife_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
72static int32_t e1000_phy_igp_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
73static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
74static int32_t e1000_write_eeprom_eewr(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
75static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
76static int32_t e1000_phy_m88_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
77static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
78static int32_t e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t *data);
79static int32_t e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
80static int32_t e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
81static int32_t e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data);
82static int32_t e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t *data);
83static int32_t e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t data);
84static int32_t e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
85static int32_t e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
86static void e1000_release_software_flag(struct e1000_hw *hw);
87static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
88static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
89static int32_t e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop);
90static void e1000_set_pci_express_master_disable(struct e1000_hw *hw);
91static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
92static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset, uint32_t value);
37static int32_t e1000_set_phy_type(struct e1000_hw *hw); 93static int32_t e1000_set_phy_type(struct e1000_hw *hw);
38static void e1000_phy_init_script(struct e1000_hw *hw); 94static void e1000_phy_init_script(struct e1000_hw *hw);
39static int32_t e1000_setup_copper_link(struct e1000_hw *hw); 95static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
@@ -70,69 +126,10 @@ static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
70static int32_t e1000_set_phy_mode(struct e1000_hw *hw); 126static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
71static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer); 127static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
72static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length); 128static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
73static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
74static int32_t e1000_check_downshift(struct e1000_hw *hw);
75static int32_t e1000_check_polarity(struct e1000_hw *hw, uint16_t *polarity);
76static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
77static void e1000_clear_vfta(struct e1000_hw *hw);
78static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
79static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw,
80 boolean_t link_up);
81static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
82static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
83static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
84static int32_t e1000_get_cable_length(struct e1000_hw *hw,
85 uint16_t *min_length,
86 uint16_t *max_length);
87static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
88static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
89static int32_t e1000_id_led_init(struct e1000_hw * hw);
90static void e1000_init_rx_addrs(struct e1000_hw *hw);
91static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
92static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
93static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
94static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset,
95 uint16_t words, uint16_t *data);
96static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
97static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
98static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
99
100static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset,
101 uint32_t value);
102
103#define E1000_WRITE_REG_IO(a, reg, val) \
104 e1000_write_reg_io((a), E1000_##reg, val)
105static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, 129static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw,
106 uint16_t duplex); 130 uint16_t duplex);
107static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw); 131static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
108 132
109static int32_t e1000_erase_ich8_4k_segment(struct e1000_hw *hw,
110 uint32_t segment);
111static int32_t e1000_get_software_flag(struct e1000_hw *hw);
112static int32_t e1000_get_software_semaphore(struct e1000_hw *hw);
113static int32_t e1000_init_lcd_from_nvm(struct e1000_hw *hw);
114static int32_t e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw);
115static int32_t e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset,
116 uint16_t words, uint16_t *data);
117static int32_t e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index,
118 uint8_t* data);
119static int32_t e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index,
120 uint16_t *data);
121static int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr,
122 uint16_t *data);
123static void e1000_release_software_flag(struct e1000_hw *hw);
124static void e1000_release_software_semaphore(struct e1000_hw *hw);
125static int32_t e1000_set_pci_ex_no_snoop(struct e1000_hw *hw,
126 uint32_t no_snoop);
127static int32_t e1000_verify_write_ich8_byte(struct e1000_hw *hw,
128 uint32_t index, uint8_t byte);
129static int32_t e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset,
130 uint16_t words, uint16_t *data);
131static int32_t e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index,
132 uint8_t data);
133static int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr,
134 uint16_t data);
135
136/* IGP cable length table */ 133/* IGP cable length table */
137static const 134static const
138uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = 135uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
@@ -156,13 +153,12 @@ uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
156 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124, 153 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
157 104, 109, 114, 118, 121, 124}; 154 104, 109, 114, 118, 121, 124};
158 155
159
160/****************************************************************************** 156/******************************************************************************
161 * Set the phy type member in the hw struct. 157 * Set the phy type member in the hw struct.
162 * 158 *
163 * hw - Struct containing variables accessed by shared code 159 * hw - Struct containing variables accessed by shared code
164 *****************************************************************************/ 160 *****************************************************************************/
165int32_t 161static int32_t
166e1000_set_phy_type(struct e1000_hw *hw) 162e1000_set_phy_type(struct e1000_hw *hw)
167{ 163{
168 DEBUGFUNC("e1000_set_phy_type"); 164 DEBUGFUNC("e1000_set_phy_type");
@@ -208,7 +204,6 @@ e1000_set_phy_type(struct e1000_hw *hw)
208 return E1000_SUCCESS; 204 return E1000_SUCCESS;
209} 205}
210 206
211
212/****************************************************************************** 207/******************************************************************************
213 * IGP phy init script - initializes the GbE PHY 208 * IGP phy init script - initializes the GbE PHY
214 * 209 *
@@ -667,19 +662,12 @@ e1000_reset_hw(struct e1000_hw *hw)
667 E1000_WRITE_FLUSH(hw); 662 E1000_WRITE_FLUSH(hw);
668 } 663 }
669 /* fall through */ 664 /* fall through */
670 case e1000_82571: 665 default:
671 case e1000_82572: 666 /* Auto read done will delay 5ms or poll based on mac type */
672 case e1000_ich8lan:
673 case e1000_80003es2lan:
674 ret_val = e1000_get_auto_rd_done(hw); 667 ret_val = e1000_get_auto_rd_done(hw);
675 if (ret_val) 668 if (ret_val)
676 /* We don't want to continue accessing MAC registers. */
677 return ret_val; 669 return ret_val;
678 break; 670 break;
679 default:
680 /* Wait for EEPROM reload (it happens automatically) */
681 msleep(5);
682 break;
683 } 671 }
684 672
685 /* Disable HW ARPs on ASF enabled adapters */ 673 /* Disable HW ARPs on ASF enabled adapters */
@@ -722,6 +710,123 @@ e1000_reset_hw(struct e1000_hw *hw)
722} 710}
723 711
724/****************************************************************************** 712/******************************************************************************
713 *
714 * Initialize a number of hardware-dependent bits
715 *
716 * hw: Struct containing variables accessed by shared code
717 *
718 * This function contains hardware limitation workarounds for PCI-E adapters
719 *
720 *****************************************************************************/
721static void
722e1000_initialize_hardware_bits(struct e1000_hw *hw)
723{
724 if ((hw->mac_type >= e1000_82571) && (!hw->initialize_hw_bits_disable)) {
725 /* Settings common to all PCI-express silicon */
726 uint32_t reg_ctrl, reg_ctrl_ext;
727 uint32_t reg_tarc0, reg_tarc1;
728 uint32_t reg_tctl;
729 uint32_t reg_txdctl, reg_txdctl1;
730
731 /* link autonegotiation/sync workarounds */
732 reg_tarc0 = E1000_READ_REG(hw, TARC0);
733 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
734
735 /* Enable not-done TX descriptor counting */
736 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
737 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
738 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
739 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
740 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
741 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
742
743 switch (hw->mac_type) {
744 case e1000_82571:
745 case e1000_82572:
746 /* Clear PHY TX compatible mode bits */
747 reg_tarc1 = E1000_READ_REG(hw, TARC1);
748 reg_tarc1 &= ~((1 << 30)|(1 << 29));
749
750 /* link autonegotiation/sync workarounds */
751 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
752
753 /* TX ring control fixes */
754 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
755
756 /* Multiple read bit is reversed polarity */
757 reg_tctl = E1000_READ_REG(hw, TCTL);
758 if (reg_tctl & E1000_TCTL_MULR)
759 reg_tarc1 &= ~(1 << 28);
760 else
761 reg_tarc1 |= (1 << 28);
762
763 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
764 break;
765 case e1000_82573:
766 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
767 reg_ctrl_ext &= ~(1 << 23);
768 reg_ctrl_ext |= (1 << 22);
769
770 /* TX byte count fix */
771 reg_ctrl = E1000_READ_REG(hw, CTRL);
772 reg_ctrl &= ~(1 << 29);
773
774 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
775 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
776 break;
777 case e1000_80003es2lan:
778 /* improve small packet performace for fiber/serdes */
779 if ((hw->media_type == e1000_media_type_fiber) ||
780 (hw->media_type == e1000_media_type_internal_serdes)) {
781 reg_tarc0 &= ~(1 << 20);
782 }
783
784 /* Multiple read bit is reversed polarity */
785 reg_tctl = E1000_READ_REG(hw, TCTL);
786 reg_tarc1 = E1000_READ_REG(hw, TARC1);
787 if (reg_tctl & E1000_TCTL_MULR)
788 reg_tarc1 &= ~(1 << 28);
789 else
790 reg_tarc1 |= (1 << 28);
791
792 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
793 break;
794 case e1000_ich8lan:
795 /* Reduce concurrent DMA requests to 3 from 4 */
796 if ((hw->revision_id < 3) ||
797 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
798 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
799 reg_tarc0 |= ((1 << 29)|(1 << 28));
800
801 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
802 reg_ctrl_ext |= (1 << 22);
803 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
804
805 /* workaround TX hang with TSO=on */
806 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
807
808 /* Multiple read bit is reversed polarity */
809 reg_tctl = E1000_READ_REG(hw, TCTL);
810 reg_tarc1 = E1000_READ_REG(hw, TARC1);
811 if (reg_tctl & E1000_TCTL_MULR)
812 reg_tarc1 &= ~(1 << 28);
813 else
814 reg_tarc1 |= (1 << 28);
815
816 /* workaround TX hang with TSO=on */
817 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
818
819 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
820 break;
821 default:
822 break;
823 }
824
825 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
826 }
827}
828
829/******************************************************************************
725 * Performs basic configuration of the adapter. 830 * Performs basic configuration of the adapter.
726 * 831 *
727 * hw - Struct containing variables accessed by shared code 832 * hw - Struct containing variables accessed by shared code
@@ -749,14 +854,13 @@ e1000_init_hw(struct e1000_hw *hw)
749 DEBUGFUNC("e1000_init_hw"); 854 DEBUGFUNC("e1000_init_hw");
750 855
751 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */ 856 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
752 if (hw->mac_type == e1000_ich8lan) { 857 if ((hw->mac_type == e1000_ich8lan) &&
753 reg_data = E1000_READ_REG(hw, TARC0); 858 ((hw->revision_id < 3) ||
754 reg_data |= 0x30000000; 859 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
755 E1000_WRITE_REG(hw, TARC0, reg_data); 860 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
756 861 reg_data = E1000_READ_REG(hw, STATUS);
757 reg_data = E1000_READ_REG(hw, STATUS); 862 reg_data &= ~0x80000000;
758 reg_data &= ~0x80000000; 863 E1000_WRITE_REG(hw, STATUS, reg_data);
759 E1000_WRITE_REG(hw, STATUS, reg_data);
760 } 864 }
761 865
762 /* Initialize Identification LED */ 866 /* Initialize Identification LED */
@@ -769,6 +873,9 @@ e1000_init_hw(struct e1000_hw *hw)
769 /* Set the media type and TBI compatibility */ 873 /* Set the media type and TBI compatibility */
770 e1000_set_media_type(hw); 874 e1000_set_media_type(hw);
771 875
876 /* Must be called after e1000_set_media_type because media_type is used */
877 e1000_initialize_hardware_bits(hw);
878
772 /* Disabling VLAN filtering. */ 879 /* Disabling VLAN filtering. */
773 DEBUGOUT("Initializing the IEEE VLAN\n"); 880 DEBUGOUT("Initializing the IEEE VLAN\n");
774 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */ 881 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
@@ -860,17 +967,6 @@ e1000_init_hw(struct e1000_hw *hw)
860 if (hw->mac_type > e1000_82544) { 967 if (hw->mac_type > e1000_82544) {
861 ctrl = E1000_READ_REG(hw, TXDCTL); 968 ctrl = E1000_READ_REG(hw, TXDCTL);
862 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB; 969 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
863 switch (hw->mac_type) {
864 default:
865 break;
866 case e1000_82571:
867 case e1000_82572:
868 case e1000_82573:
869 case e1000_ich8lan:
870 case e1000_80003es2lan:
871 ctrl |= E1000_TXDCTL_COUNT_DESC;
872 break;
873 }
874 E1000_WRITE_REG(hw, TXDCTL, ctrl); 970 E1000_WRITE_REG(hw, TXDCTL, ctrl);
875 } 971 }
876 972
@@ -908,8 +1004,6 @@ e1000_init_hw(struct e1000_hw *hw)
908 case e1000_ich8lan: 1004 case e1000_ich8lan:
909 ctrl = E1000_READ_REG(hw, TXDCTL1); 1005 ctrl = E1000_READ_REG(hw, TXDCTL1);
910 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB; 1006 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
911 if (hw->mac_type >= e1000_82571)
912 ctrl |= E1000_TXDCTL_COUNT_DESC;
913 E1000_WRITE_REG(hw, TXDCTL1, ctrl); 1007 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
914 break; 1008 break;
915 } 1009 }
@@ -1018,11 +1112,11 @@ e1000_setup_link(struct e1000_hw *hw)
1018 * control setting, then the variable hw->fc will 1112 * control setting, then the variable hw->fc will
1019 * be initialized based on a value in the EEPROM. 1113 * be initialized based on a value in the EEPROM.
1020 */ 1114 */
1021 if (hw->fc == e1000_fc_default) { 1115 if (hw->fc == E1000_FC_DEFAULT) {
1022 switch (hw->mac_type) { 1116 switch (hw->mac_type) {
1023 case e1000_ich8lan: 1117 case e1000_ich8lan:
1024 case e1000_82573: 1118 case e1000_82573:
1025 hw->fc = e1000_fc_full; 1119 hw->fc = E1000_FC_FULL;
1026 break; 1120 break;
1027 default: 1121 default:
1028 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1122 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
@@ -1032,12 +1126,12 @@ e1000_setup_link(struct e1000_hw *hw)
1032 return -E1000_ERR_EEPROM; 1126 return -E1000_ERR_EEPROM;
1033 } 1127 }
1034 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0) 1128 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
1035 hw->fc = e1000_fc_none; 1129 hw->fc = E1000_FC_NONE;
1036 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 1130 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1037 EEPROM_WORD0F_ASM_DIR) 1131 EEPROM_WORD0F_ASM_DIR)
1038 hw->fc = e1000_fc_tx_pause; 1132 hw->fc = E1000_FC_TX_PAUSE;
1039 else 1133 else
1040 hw->fc = e1000_fc_full; 1134 hw->fc = E1000_FC_FULL;
1041 break; 1135 break;
1042 } 1136 }
1043 } 1137 }
@@ -1047,10 +1141,10 @@ e1000_setup_link(struct e1000_hw *hw)
1047 * hub or switch with different Flow Control capabilities. 1141 * hub or switch with different Flow Control capabilities.
1048 */ 1142 */
1049 if (hw->mac_type == e1000_82542_rev2_0) 1143 if (hw->mac_type == e1000_82542_rev2_0)
1050 hw->fc &= (~e1000_fc_tx_pause); 1144 hw->fc &= (~E1000_FC_TX_PAUSE);
1051 1145
1052 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1)) 1146 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
1053 hw->fc &= (~e1000_fc_rx_pause); 1147 hw->fc &= (~E1000_FC_RX_PAUSE);
1054 1148
1055 hw->original_fc = hw->fc; 1149 hw->original_fc = hw->fc;
1056 1150
@@ -1102,7 +1196,7 @@ e1000_setup_link(struct e1000_hw *hw)
1102 * ability to transmit pause frames in not enabled, then these 1196 * ability to transmit pause frames in not enabled, then these
1103 * registers will be set to 0. 1197 * registers will be set to 0.
1104 */ 1198 */
1105 if (!(hw->fc & e1000_fc_tx_pause)) { 1199 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
1106 E1000_WRITE_REG(hw, FCRTL, 0); 1200 E1000_WRITE_REG(hw, FCRTL, 0);
1107 E1000_WRITE_REG(hw, FCRTH, 0); 1201 E1000_WRITE_REG(hw, FCRTH, 0);
1108 } else { 1202 } else {
@@ -1149,11 +1243,11 @@ e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1149 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) 1243 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1150 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK); 1244 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1151 1245
1152 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be 1246 /* On adapters with a MAC newer than 82544, SWDP 1 will be
1153 * set when the optics detect a signal. On older adapters, it will be 1247 * set when the optics detect a signal. On older adapters, it will be
1154 * cleared when there is a signal. This applies to fiber media only. 1248 * cleared when there is a signal. This applies to fiber media only.
1155 * If we're on serdes media, adjust the output amplitude to value set in 1249 * If we're on serdes media, adjust the output amplitude to value
1156 * the EEPROM. 1250 * set in the EEPROM.
1157 */ 1251 */
1158 ctrl = E1000_READ_REG(hw, CTRL); 1252 ctrl = E1000_READ_REG(hw, CTRL);
1159 if (hw->media_type == e1000_media_type_fiber) 1253 if (hw->media_type == e1000_media_type_fiber)
@@ -1189,11 +1283,11 @@ e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1189 * 3: Both Rx and TX flow control (symmetric) are enabled. 1283 * 3: Both Rx and TX flow control (symmetric) are enabled.
1190 */ 1284 */
1191 switch (hw->fc) { 1285 switch (hw->fc) {
1192 case e1000_fc_none: 1286 case E1000_FC_NONE:
1193 /* Flow control is completely disabled by a software over-ride. */ 1287 /* Flow control is completely disabled by a software over-ride. */
1194 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD); 1288 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1195 break; 1289 break;
1196 case e1000_fc_rx_pause: 1290 case E1000_FC_RX_PAUSE:
1197 /* RX Flow control is enabled and TX Flow control is disabled by a 1291 /* RX Flow control is enabled and TX Flow control is disabled by a
1198 * software over-ride. Since there really isn't a way to advertise 1292 * software over-ride. Since there really isn't a way to advertise
1199 * that we are capable of RX Pause ONLY, we will advertise that we 1293 * that we are capable of RX Pause ONLY, we will advertise that we
@@ -1202,13 +1296,13 @@ e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1202 */ 1296 */
1203 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); 1297 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1204 break; 1298 break;
1205 case e1000_fc_tx_pause: 1299 case E1000_FC_TX_PAUSE:
1206 /* TX Flow control is enabled, and RX Flow control is disabled, by a 1300 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1207 * software over-ride. 1301 * software over-ride.
1208 */ 1302 */
1209 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR); 1303 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1210 break; 1304 break;
1211 case e1000_fc_full: 1305 case E1000_FC_FULL:
1212 /* Flow control (both RX and TX) is enabled by a software over-ride. */ 1306 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1213 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); 1307 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1214 break; 1308 break;
@@ -2124,13 +2218,13 @@ e1000_phy_setup_autoneg(struct e1000_hw *hw)
2124 * in the EEPROM is used. 2218 * in the EEPROM is used.
2125 */ 2219 */
2126 switch (hw->fc) { 2220 switch (hw->fc) {
2127 case e1000_fc_none: /* 0 */ 2221 case E1000_FC_NONE: /* 0 */
2128 /* Flow control (RX & TX) is completely disabled by a 2222 /* Flow control (RX & TX) is completely disabled by a
2129 * software over-ride. 2223 * software over-ride.
2130 */ 2224 */
2131 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); 2225 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2132 break; 2226 break;
2133 case e1000_fc_rx_pause: /* 1 */ 2227 case E1000_FC_RX_PAUSE: /* 1 */
2134 /* RX Flow control is enabled, and TX Flow control is 2228 /* RX Flow control is enabled, and TX Flow control is
2135 * disabled, by a software over-ride. 2229 * disabled, by a software over-ride.
2136 */ 2230 */
@@ -2142,14 +2236,14 @@ e1000_phy_setup_autoneg(struct e1000_hw *hw)
2142 */ 2236 */
2143 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); 2237 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2144 break; 2238 break;
2145 case e1000_fc_tx_pause: /* 2 */ 2239 case E1000_FC_TX_PAUSE: /* 2 */
2146 /* TX Flow control is enabled, and RX Flow control is 2240 /* TX Flow control is enabled, and RX Flow control is
2147 * disabled, by a software over-ride. 2241 * disabled, by a software over-ride.
2148 */ 2242 */
2149 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR; 2243 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2150 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE; 2244 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2151 break; 2245 break;
2152 case e1000_fc_full: /* 3 */ 2246 case E1000_FC_FULL: /* 3 */
2153 /* Flow control (both RX and TX) is enabled by a software 2247 /* Flow control (both RX and TX) is enabled by a software
2154 * over-ride. 2248 * over-ride.
2155 */ 2249 */
@@ -2193,7 +2287,7 @@ e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2193 DEBUGFUNC("e1000_phy_force_speed_duplex"); 2287 DEBUGFUNC("e1000_phy_force_speed_duplex");
2194 2288
2195 /* Turn off Flow control if we are forcing speed and duplex. */ 2289 /* Turn off Flow control if we are forcing speed and duplex. */
2196 hw->fc = e1000_fc_none; 2290 hw->fc = E1000_FC_NONE;
2197 2291
2198 DEBUGOUT1("hw->fc = %d\n", hw->fc); 2292 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2199 2293
@@ -2547,18 +2641,18 @@ e1000_force_mac_fc(struct e1000_hw *hw)
2547 */ 2641 */
2548 2642
2549 switch (hw->fc) { 2643 switch (hw->fc) {
2550 case e1000_fc_none: 2644 case E1000_FC_NONE:
2551 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); 2645 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2552 break; 2646 break;
2553 case e1000_fc_rx_pause: 2647 case E1000_FC_RX_PAUSE:
2554 ctrl &= (~E1000_CTRL_TFCE); 2648 ctrl &= (~E1000_CTRL_TFCE);
2555 ctrl |= E1000_CTRL_RFCE; 2649 ctrl |= E1000_CTRL_RFCE;
2556 break; 2650 break;
2557 case e1000_fc_tx_pause: 2651 case E1000_FC_TX_PAUSE:
2558 ctrl &= (~E1000_CTRL_RFCE); 2652 ctrl &= (~E1000_CTRL_RFCE);
2559 ctrl |= E1000_CTRL_TFCE; 2653 ctrl |= E1000_CTRL_TFCE;
2560 break; 2654 break;
2561 case e1000_fc_full: 2655 case E1000_FC_FULL:
2562 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); 2656 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2563 break; 2657 break;
2564 default: 2658 default:
@@ -2657,14 +2751,14 @@ e1000_config_fc_after_link_up(struct e1000_hw *hw)
2657 * LOCAL DEVICE | LINK PARTNER 2751 * LOCAL DEVICE | LINK PARTNER
2658 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution 2752 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2659 *-------|---------|-------|---------|-------------------- 2753 *-------|---------|-------|---------|--------------------
2660 * 0 | 0 | DC | DC | e1000_fc_none 2754 * 0 | 0 | DC | DC | E1000_FC_NONE
2661 * 0 | 1 | 0 | DC | e1000_fc_none 2755 * 0 | 1 | 0 | DC | E1000_FC_NONE
2662 * 0 | 1 | 1 | 0 | e1000_fc_none 2756 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2663 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause 2757 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2664 * 1 | 0 | 0 | DC | e1000_fc_none 2758 * 1 | 0 | 0 | DC | E1000_FC_NONE
2665 * 1 | DC | 1 | DC | e1000_fc_full 2759 * 1 | DC | 1 | DC | E1000_FC_FULL
2666 * 1 | 1 | 0 | 0 | e1000_fc_none 2760 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2667 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause 2761 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2668 * 2762 *
2669 */ 2763 */
2670 /* Are both PAUSE bits set to 1? If so, this implies 2764 /* Are both PAUSE bits set to 1? If so, this implies
@@ -2676,7 +2770,7 @@ e1000_config_fc_after_link_up(struct e1000_hw *hw)
2676 * LOCAL DEVICE | LINK PARTNER 2770 * LOCAL DEVICE | LINK PARTNER
2677 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result 2771 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2678 *-------|---------|-------|---------|-------------------- 2772 *-------|---------|-------|---------|--------------------
2679 * 1 | DC | 1 | DC | e1000_fc_full 2773 * 1 | DC | 1 | DC | E1000_FC_FULL
2680 * 2774 *
2681 */ 2775 */
2682 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && 2776 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
@@ -2687,11 +2781,11 @@ e1000_config_fc_after_link_up(struct e1000_hw *hw)
2687 * ONLY. Hence, we must now check to see if we need to 2781 * ONLY. Hence, we must now check to see if we need to
2688 * turn OFF the TRANSMISSION of PAUSE frames. 2782 * turn OFF the TRANSMISSION of PAUSE frames.
2689 */ 2783 */
2690 if (hw->original_fc == e1000_fc_full) { 2784 if (hw->original_fc == E1000_FC_FULL) {
2691 hw->fc = e1000_fc_full; 2785 hw->fc = E1000_FC_FULL;
2692 DEBUGOUT("Flow Control = FULL.\n"); 2786 DEBUGOUT("Flow Control = FULL.\n");
2693 } else { 2787 } else {
2694 hw->fc = e1000_fc_rx_pause; 2788 hw->fc = E1000_FC_RX_PAUSE;
2695 DEBUGOUT("Flow Control = RX PAUSE frames only.\n"); 2789 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2696 } 2790 }
2697 } 2791 }
@@ -2700,14 +2794,14 @@ e1000_config_fc_after_link_up(struct e1000_hw *hw)
2700 * LOCAL DEVICE | LINK PARTNER 2794 * LOCAL DEVICE | LINK PARTNER
2701 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result 2795 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2702 *-------|---------|-------|---------|-------------------- 2796 *-------|---------|-------|---------|--------------------
2703 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause 2797 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2704 * 2798 *
2705 */ 2799 */
2706 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && 2800 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2707 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && 2801 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2708 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && 2802 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2709 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { 2803 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2710 hw->fc = e1000_fc_tx_pause; 2804 hw->fc = E1000_FC_TX_PAUSE;
2711 DEBUGOUT("Flow Control = TX PAUSE frames only.\n"); 2805 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2712 } 2806 }
2713 /* For transmitting PAUSE frames ONLY. 2807 /* For transmitting PAUSE frames ONLY.
@@ -2715,14 +2809,14 @@ e1000_config_fc_after_link_up(struct e1000_hw *hw)
2715 * LOCAL DEVICE | LINK PARTNER 2809 * LOCAL DEVICE | LINK PARTNER
2716 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result 2810 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2717 *-------|---------|-------|---------|-------------------- 2811 *-------|---------|-------|---------|--------------------
2718 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause 2812 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2719 * 2813 *
2720 */ 2814 */
2721 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && 2815 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2722 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && 2816 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2723 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && 2817 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2724 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { 2818 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2725 hw->fc = e1000_fc_rx_pause; 2819 hw->fc = E1000_FC_RX_PAUSE;
2726 DEBUGOUT("Flow Control = RX PAUSE frames only.\n"); 2820 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2727 } 2821 }
2728 /* Per the IEEE spec, at this point flow control should be 2822 /* Per the IEEE spec, at this point flow control should be
@@ -2745,13 +2839,13 @@ e1000_config_fc_after_link_up(struct e1000_hw *hw)
2745 * be asked to delay transmission of packets than asking 2839 * be asked to delay transmission of packets than asking
2746 * our link partner to pause transmission of frames. 2840 * our link partner to pause transmission of frames.
2747 */ 2841 */
2748 else if ((hw->original_fc == e1000_fc_none || 2842 else if ((hw->original_fc == E1000_FC_NONE ||
2749 hw->original_fc == e1000_fc_tx_pause) || 2843 hw->original_fc == E1000_FC_TX_PAUSE) ||
2750 hw->fc_strict_ieee) { 2844 hw->fc_strict_ieee) {
2751 hw->fc = e1000_fc_none; 2845 hw->fc = E1000_FC_NONE;
2752 DEBUGOUT("Flow Control = NONE.\n"); 2846 DEBUGOUT("Flow Control = NONE.\n");
2753 } else { 2847 } else {
2754 hw->fc = e1000_fc_rx_pause; 2848 hw->fc = E1000_FC_RX_PAUSE;
2755 DEBUGOUT("Flow Control = RX PAUSE frames only.\n"); 2849 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2756 } 2850 }
2757 2851
@@ -2766,7 +2860,7 @@ e1000_config_fc_after_link_up(struct e1000_hw *hw)
2766 } 2860 }
2767 2861
2768 if (duplex == HALF_DUPLEX) 2862 if (duplex == HALF_DUPLEX)
2769 hw->fc = e1000_fc_none; 2863 hw->fc = E1000_FC_NONE;
2770 2864
2771 /* Now we call a subroutine to actually force the MAC 2865 /* Now we call a subroutine to actually force the MAC
2772 * controller to use the correct flow control settings. 2866 * controller to use the correct flow control settings.
@@ -3417,9 +3511,8 @@ e1000_read_phy_reg(struct e1000_hw *hw,
3417 return ret_val; 3511 return ret_val;
3418} 3512}
3419 3513
3420int32_t 3514static int32_t
3421e1000_read_phy_reg_ex(struct e1000_hw *hw, 3515e1000_read_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3422 uint32_t reg_addr,
3423 uint16_t *phy_data) 3516 uint16_t *phy_data)
3424{ 3517{
3425 uint32_t i; 3518 uint32_t i;
@@ -3499,8 +3592,7 @@ e1000_read_phy_reg_ex(struct e1000_hw *hw,
3499* data - data to write to the PHY 3592* data - data to write to the PHY
3500******************************************************************************/ 3593******************************************************************************/
3501int32_t 3594int32_t
3502e1000_write_phy_reg(struct e1000_hw *hw, 3595e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
3503 uint32_t reg_addr,
3504 uint16_t phy_data) 3596 uint16_t phy_data)
3505{ 3597{
3506 uint32_t ret_val; 3598 uint32_t ret_val;
@@ -3557,10 +3649,9 @@ e1000_write_phy_reg(struct e1000_hw *hw,
3557 return ret_val; 3649 return ret_val;
3558} 3650}
3559 3651
3560int32_t 3652static int32_t
3561e1000_write_phy_reg_ex(struct e1000_hw *hw, 3653e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3562 uint32_t reg_addr, 3654 uint16_t phy_data)
3563 uint16_t phy_data)
3564{ 3655{
3565 uint32_t i; 3656 uint32_t i;
3566 uint32_t mdic = 0; 3657 uint32_t mdic = 0;
@@ -3711,7 +3802,7 @@ e1000_phy_hw_reset(struct e1000_hw *hw)
3711 swfw = E1000_SWFW_PHY0_SM; 3802 swfw = E1000_SWFW_PHY0_SM;
3712 } 3803 }
3713 if (e1000_swfw_sync_acquire(hw, swfw)) { 3804 if (e1000_swfw_sync_acquire(hw, swfw)) {
3714 e1000_release_software_semaphore(hw); 3805 DEBUGOUT("Unable to acquire swfw sync\n");
3715 return -E1000_ERR_SWFW_SYNC; 3806 return -E1000_ERR_SWFW_SYNC;
3716 } 3807 }
3717 /* Read the device control register and assert the E1000_CTRL_PHY_RST 3808 /* Read the device control register and assert the E1000_CTRL_PHY_RST
@@ -3734,6 +3825,7 @@ e1000_phy_hw_reset(struct e1000_hw *hw)
3734 3825
3735 if (hw->mac_type >= e1000_82571) 3826 if (hw->mac_type >= e1000_82571)
3736 mdelay(10); 3827 mdelay(10);
3828
3737 e1000_swfw_sync_release(hw, swfw); 3829 e1000_swfw_sync_release(hw, swfw);
3738 } else { 3830 } else {
3739 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR 3831 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
@@ -3792,15 +3884,14 @@ e1000_phy_reset(struct e1000_hw *hw)
3792 if (ret_val) 3884 if (ret_val)
3793 return E1000_SUCCESS; 3885 return E1000_SUCCESS;
3794 3886
3795 switch (hw->mac_type) { 3887 switch (hw->phy_type) {
3796 case e1000_82541_rev_2: 3888 case e1000_phy_igp:
3797 case e1000_82571: 3889 case e1000_phy_igp_2:
3798 case e1000_82572: 3890 case e1000_phy_igp_3:
3799 case e1000_ich8lan: 3891 case e1000_phy_ife:
3800 ret_val = e1000_phy_hw_reset(hw); 3892 ret_val = e1000_phy_hw_reset(hw);
3801 if (ret_val) 3893 if (ret_val)
3802 return ret_val; 3894 return ret_val;
3803
3804 break; 3895 break;
3805 default: 3896 default:
3806 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); 3897 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
@@ -3936,7 +4027,7 @@ e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
3936* 4027*
3937* hw - Struct containing variables accessed by shared code 4028* hw - Struct containing variables accessed by shared code
3938******************************************************************************/ 4029******************************************************************************/
3939int32_t 4030static int32_t
3940e1000_detect_gig_phy(struct e1000_hw *hw) 4031e1000_detect_gig_phy(struct e1000_hw *hw)
3941{ 4032{
3942 int32_t phy_init_status, ret_val; 4033 int32_t phy_init_status, ret_val;
@@ -3945,6 +4036,9 @@ e1000_detect_gig_phy(struct e1000_hw *hw)
3945 4036
3946 DEBUGFUNC("e1000_detect_gig_phy"); 4037 DEBUGFUNC("e1000_detect_gig_phy");
3947 4038
4039 if (hw->phy_id != 0)
4040 return E1000_SUCCESS;
4041
3948 /* The 82571 firmware may still be configuring the PHY. In this 4042 /* The 82571 firmware may still be configuring the PHY. In this
3949 * case, we cannot access the PHY until the configuration is done. So 4043 * case, we cannot access the PHY until the configuration is done. So
3950 * we explicitly set the PHY values. */ 4044 * we explicitly set the PHY values. */
@@ -4061,7 +4155,8 @@ e1000_phy_igp_get_info(struct e1000_hw *hw,
4061 struct e1000_phy_info *phy_info) 4155 struct e1000_phy_info *phy_info)
4062{ 4156{
4063 int32_t ret_val; 4157 int32_t ret_val;
4064 uint16_t phy_data, polarity, min_length, max_length, average; 4158 uint16_t phy_data, min_length, max_length, average;
4159 e1000_rev_polarity polarity;
4065 4160
4066 DEBUGFUNC("e1000_phy_igp_get_info"); 4161 DEBUGFUNC("e1000_phy_igp_get_info");
4067 4162
@@ -4086,8 +4181,8 @@ e1000_phy_igp_get_info(struct e1000_hw *hw,
4086 if (ret_val) 4181 if (ret_val)
4087 return ret_val; 4182 return ret_val;
4088 4183
4089 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >> 4184 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
4090 IGP01E1000_PSSR_MDIX_SHIFT; 4185 IGP01E1000_PSSR_MDIX_SHIFT);
4091 4186
4092 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == 4187 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
4093 IGP01E1000_PSSR_SPEED_1000MBPS) { 4188 IGP01E1000_PSSR_SPEED_1000MBPS) {
@@ -4096,10 +4191,12 @@ e1000_phy_igp_get_info(struct e1000_hw *hw,
4096 if (ret_val) 4191 if (ret_val)
4097 return ret_val; 4192 return ret_val;
4098 4193
4099 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >> 4194 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4100 SR_1000T_LOCAL_RX_STATUS_SHIFT; 4195 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4101 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >> 4196 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4102 SR_1000T_REMOTE_RX_STATUS_SHIFT; 4197 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4198 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4199 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4103 4200
4104 /* Get cable length */ 4201 /* Get cable length */
4105 ret_val = e1000_get_cable_length(hw, &min_length, &max_length); 4202 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
@@ -4135,7 +4232,8 @@ e1000_phy_ife_get_info(struct e1000_hw *hw,
4135 struct e1000_phy_info *phy_info) 4232 struct e1000_phy_info *phy_info)
4136{ 4233{
4137 int32_t ret_val; 4234 int32_t ret_val;
4138 uint16_t phy_data, polarity; 4235 uint16_t phy_data;
4236 e1000_rev_polarity polarity;
4139 4237
4140 DEBUGFUNC("e1000_phy_ife_get_info"); 4238 DEBUGFUNC("e1000_phy_ife_get_info");
4141 4239
@@ -4146,8 +4244,9 @@ e1000_phy_ife_get_info(struct e1000_hw *hw,
4146 if (ret_val) 4244 if (ret_val)
4147 return ret_val; 4245 return ret_val;
4148 phy_info->polarity_correction = 4246 phy_info->polarity_correction =
4149 (phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >> 4247 ((phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4150 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT; 4248 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT) ?
4249 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
4151 4250
4152 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) { 4251 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4153 ret_val = e1000_check_polarity(hw, &polarity); 4252 ret_val = e1000_check_polarity(hw, &polarity);
@@ -4155,8 +4254,9 @@ e1000_phy_ife_get_info(struct e1000_hw *hw,
4155 return ret_val; 4254 return ret_val;
4156 } else { 4255 } else {
4157 /* Polarity is forced. */ 4256 /* Polarity is forced. */
4158 polarity = (phy_data & IFE_PSC_FORCE_POLARITY) >> 4257 polarity = ((phy_data & IFE_PSC_FORCE_POLARITY) >>
4159 IFE_PSC_FORCE_POLARITY_SHIFT; 4258 IFE_PSC_FORCE_POLARITY_SHIFT) ?
4259 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
4160 } 4260 }
4161 phy_info->cable_polarity = polarity; 4261 phy_info->cable_polarity = polarity;
4162 4262
@@ -4164,9 +4264,9 @@ e1000_phy_ife_get_info(struct e1000_hw *hw,
4164 if (ret_val) 4264 if (ret_val)
4165 return ret_val; 4265 return ret_val;
4166 4266
4167 phy_info->mdix_mode = 4267 phy_info->mdix_mode = (e1000_auto_x_mode)
4168 (phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >> 4268 ((phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4169 IFE_PMC_MDIX_MODE_SHIFT; 4269 IFE_PMC_MDIX_MODE_SHIFT);
4170 4270
4171 return E1000_SUCCESS; 4271 return E1000_SUCCESS;
4172} 4272}
@@ -4182,7 +4282,8 @@ e1000_phy_m88_get_info(struct e1000_hw *hw,
4182 struct e1000_phy_info *phy_info) 4282 struct e1000_phy_info *phy_info)
4183{ 4283{
4184 int32_t ret_val; 4284 int32_t ret_val;
4185 uint16_t phy_data, polarity; 4285 uint16_t phy_data;
4286 e1000_rev_polarity polarity;
4186 4287
4187 DEBUGFUNC("e1000_phy_m88_get_info"); 4288 DEBUGFUNC("e1000_phy_m88_get_info");
4188 4289
@@ -4195,11 +4296,14 @@ e1000_phy_m88_get_info(struct e1000_hw *hw,
4195 return ret_val; 4296 return ret_val;
4196 4297
4197 phy_info->extended_10bt_distance = 4298 phy_info->extended_10bt_distance =
4198 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >> 4299 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
4199 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT; 4300 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
4301 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
4302
4200 phy_info->polarity_correction = 4303 phy_info->polarity_correction =
4201 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >> 4304 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
4202 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT; 4305 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
4306 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
4203 4307
4204 /* Check polarity status */ 4308 /* Check polarity status */
4205 ret_val = e1000_check_polarity(hw, &polarity); 4309 ret_val = e1000_check_polarity(hw, &polarity);
@@ -4211,15 +4315,15 @@ e1000_phy_m88_get_info(struct e1000_hw *hw,
4211 if (ret_val) 4315 if (ret_val)
4212 return ret_val; 4316 return ret_val;
4213 4317
4214 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >> 4318 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
4215 M88E1000_PSSR_MDIX_SHIFT; 4319 M88E1000_PSSR_MDIX_SHIFT);
4216 4320
4217 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) { 4321 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
4218 /* Cable Length Estimation and Local/Remote Receiver Information 4322 /* Cable Length Estimation and Local/Remote Receiver Information
4219 * are only valid at 1000 Mbps. 4323 * are only valid at 1000 Mbps.
4220 */ 4324 */
4221 if (hw->phy_type != e1000_phy_gg82563) { 4325 if (hw->phy_type != e1000_phy_gg82563) {
4222 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >> 4326 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4223 M88E1000_PSSR_CABLE_LENGTH_SHIFT); 4327 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
4224 } else { 4328 } else {
4225 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE, 4329 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
@@ -4227,18 +4331,20 @@ e1000_phy_m88_get_info(struct e1000_hw *hw,
4227 if (ret_val) 4331 if (ret_val)
4228 return ret_val; 4332 return ret_val;
4229 4333
4230 phy_info->cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH; 4334 phy_info->cable_length = (e1000_cable_length)(phy_data & GG82563_DSPD_CABLE_LENGTH);
4231 } 4335 }
4232 4336
4233 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); 4337 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
4234 if (ret_val) 4338 if (ret_val)
4235 return ret_val; 4339 return ret_val;
4236 4340
4237 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >> 4341 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4238 SR_1000T_LOCAL_RX_STATUS_SHIFT; 4342 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4343 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4344 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4345 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4346 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4239 4347
4240 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4241 SR_1000T_REMOTE_RX_STATUS_SHIFT;
4242 } 4348 }
4243 4349
4244 return E1000_SUCCESS; 4350 return E1000_SUCCESS;
@@ -4441,7 +4547,7 @@ e1000_init_eeprom_params(struct e1000_hw *hw)
4441 eeprom->use_eewr = FALSE; 4547 eeprom->use_eewr = FALSE;
4442 break; 4548 break;
4443 case e1000_ich8lan: 4549 case e1000_ich8lan:
4444 { 4550 {
4445 int32_t i = 0; 4551 int32_t i = 0;
4446 uint32_t flash_size = E1000_READ_ICH8_REG(hw, ICH8_FLASH_GFPREG); 4552 uint32_t flash_size = E1000_READ_ICH8_REG(hw, ICH8_FLASH_GFPREG);
4447 4553
@@ -4468,7 +4574,7 @@ e1000_init_eeprom_params(struct e1000_hw *hw)
4468 hw->flash_bank_size /= 2 * sizeof(uint16_t); 4574 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4469 4575
4470 break; 4576 break;
4471 } 4577 }
4472 default: 4578 default:
4473 break; 4579 break;
4474 } 4580 }
@@ -4800,7 +4906,7 @@ e1000_release_eeprom(struct e1000_hw *hw)
4800 * 4906 *
4801 * hw - Struct containing variables accessed by shared code 4907 * hw - Struct containing variables accessed by shared code
4802 *****************************************************************************/ 4908 *****************************************************************************/
4803int32_t 4909static int32_t
4804e1000_spi_eeprom_ready(struct e1000_hw *hw) 4910e1000_spi_eeprom_ready(struct e1000_hw *hw)
4805{ 4911{
4806 uint16_t retry_count = 0; 4912 uint16_t retry_count = 0;
@@ -4854,44 +4960,43 @@ e1000_read_eeprom(struct e1000_hw *hw,
4854{ 4960{
4855 struct e1000_eeprom_info *eeprom = &hw->eeprom; 4961 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4856 uint32_t i = 0; 4962 uint32_t i = 0;
4857 int32_t ret_val;
4858 4963
4859 DEBUGFUNC("e1000_read_eeprom"); 4964 DEBUGFUNC("e1000_read_eeprom");
4860 4965
4966 /* If eeprom is not yet detected, do so now */
4967 if (eeprom->word_size == 0)
4968 e1000_init_eeprom_params(hw);
4969
4861 /* A check for invalid values: offset too large, too many words, and not 4970 /* A check for invalid values: offset too large, too many words, and not
4862 * enough words. 4971 * enough words.
4863 */ 4972 */
4864 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) || 4973 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4865 (words == 0)) { 4974 (words == 0)) {
4866 DEBUGOUT("\"words\" parameter out of bounds\n"); 4975 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
4867 return -E1000_ERR_EEPROM; 4976 return -E1000_ERR_EEPROM;
4868 } 4977 }
4869 4978
4870 /* FLASH reads without acquiring the semaphore are safe */ 4979 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
4980 * directly. In this case, we need to acquire the EEPROM so that
4981 * FW or other port software does not interrupt.
4982 */
4871 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE && 4983 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
4872 hw->eeprom.use_eerd == FALSE) { 4984 hw->eeprom.use_eerd == FALSE) {
4873 switch (hw->mac_type) { 4985 /* Prepare the EEPROM for bit-bang reading */
4874 case e1000_80003es2lan: 4986 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4875 break; 4987 return -E1000_ERR_EEPROM;
4876 default:
4877 /* Prepare the EEPROM for reading */
4878 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4879 return -E1000_ERR_EEPROM;
4880 break;
4881 }
4882 } 4988 }
4883 4989
4884 if (eeprom->use_eerd == TRUE) { 4990 /* Eerd register EEPROM access requires no eeprom aquire/release */
4885 ret_val = e1000_read_eeprom_eerd(hw, offset, words, data); 4991 if (eeprom->use_eerd == TRUE)
4886 if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) || 4992 return e1000_read_eeprom_eerd(hw, offset, words, data);
4887 (hw->mac_type != e1000_82573))
4888 e1000_release_eeprom(hw);
4889 return ret_val;
4890 }
4891 4993
4994 /* ICH EEPROM access is done via the ICH flash controller */
4892 if (eeprom->type == e1000_eeprom_ich8) 4995 if (eeprom->type == e1000_eeprom_ich8)
4893 return e1000_read_eeprom_ich8(hw, offset, words, data); 4996 return e1000_read_eeprom_ich8(hw, offset, words, data);
4894 4997
4998 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
4999 * acquired the EEPROM at this point, so any returns should relase it */
4895 if (eeprom->type == e1000_eeprom_spi) { 5000 if (eeprom->type == e1000_eeprom_spi) {
4896 uint16_t word_in; 5001 uint16_t word_in;
4897 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI; 5002 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
@@ -5206,6 +5311,10 @@ e1000_write_eeprom(struct e1000_hw *hw,
5206 5311
5207 DEBUGFUNC("e1000_write_eeprom"); 5312 DEBUGFUNC("e1000_write_eeprom");
5208 5313
5314 /* If eeprom is not yet detected, do so now */
5315 if (eeprom->word_size == 0)
5316 e1000_init_eeprom_params(hw);
5317
5209 /* A check for invalid values: offset too large, too many words, and not 5318 /* A check for invalid values: offset too large, too many words, and not
5210 * enough words. 5319 * enough words.
5211 */ 5320 */
@@ -5248,7 +5357,7 @@ e1000_write_eeprom(struct e1000_hw *hw,
5248 * data - pointer to array of 8 bit words to be written to the EEPROM 5357 * data - pointer to array of 8 bit words to be written to the EEPROM
5249 * 5358 *
5250 *****************************************************************************/ 5359 *****************************************************************************/
5251int32_t 5360static int32_t
5252e1000_write_eeprom_spi(struct e1000_hw *hw, 5361e1000_write_eeprom_spi(struct e1000_hw *hw,
5253 uint16_t offset, 5362 uint16_t offset,
5254 uint16_t words, 5363 uint16_t words,
@@ -5314,7 +5423,7 @@ e1000_write_eeprom_spi(struct e1000_hw *hw,
5314 * data - pointer to array of 16 bit words to be written to the EEPROM 5423 * data - pointer to array of 16 bit words to be written to the EEPROM
5315 * 5424 *
5316 *****************************************************************************/ 5425 *****************************************************************************/
5317int32_t 5426static int32_t
5318e1000_write_eeprom_microwire(struct e1000_hw *hw, 5427e1000_write_eeprom_microwire(struct e1000_hw *hw,
5319 uint16_t offset, 5428 uint16_t offset,
5320 uint16_t words, 5429 uint16_t words,
@@ -5411,10 +5520,8 @@ e1000_commit_shadow_ram(struct e1000_hw *hw)
5411 int32_t error = E1000_SUCCESS; 5520 int32_t error = E1000_SUCCESS;
5412 uint32_t old_bank_offset = 0; 5521 uint32_t old_bank_offset = 0;
5413 uint32_t new_bank_offset = 0; 5522 uint32_t new_bank_offset = 0;
5414 uint32_t sector_retries = 0;
5415 uint8_t low_byte = 0; 5523 uint8_t low_byte = 0;
5416 uint8_t high_byte = 0; 5524 uint8_t high_byte = 0;
5417 uint8_t temp_byte = 0;
5418 boolean_t sector_write_failed = FALSE; 5525 boolean_t sector_write_failed = FALSE;
5419 5526
5420 if (hw->mac_type == e1000_82573) { 5527 if (hw->mac_type == e1000_82573) {
@@ -5467,41 +5574,46 @@ e1000_commit_shadow_ram(struct e1000_hw *hw)
5467 e1000_erase_ich8_4k_segment(hw, 0); 5574 e1000_erase_ich8_4k_segment(hw, 0);
5468 } 5575 }
5469 5576
5470 do { 5577 sector_write_failed = FALSE;
5471 sector_write_failed = FALSE; 5578 /* Loop for every byte in the shadow RAM,
5472 /* Loop for every byte in the shadow RAM, 5579 * which is in units of words. */
5473 * which is in units of words. */ 5580 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5474 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) { 5581 /* Determine whether to write the value stored
5475 /* Determine whether to write the value stored 5582 * in the other NVM bank or a modified value stored
5476 * in the other NVM bank or a modified value stored 5583 * in the shadow RAM */
5477 * in the shadow RAM */ 5584 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5478 if (hw->eeprom_shadow_ram[i].modified == TRUE) { 5585 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5479 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word; 5586 udelay(100);
5480 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset, 5587 error = e1000_verify_write_ich8_byte(hw,
5481 &temp_byte); 5588 (i << 1) + new_bank_offset, low_byte);
5482 udelay(100); 5589
5483 error = e1000_verify_write_ich8_byte(hw, 5590 if (error != E1000_SUCCESS)
5484 (i << 1) + new_bank_offset, 5591 sector_write_failed = TRUE;
5485 low_byte); 5592 else {
5486 if (error != E1000_SUCCESS)
5487 sector_write_failed = TRUE;
5488 high_byte = 5593 high_byte =
5489 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8); 5594 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
5490 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5491 &temp_byte);
5492 udelay(100);
5493 } else {
5494 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5495 &low_byte);
5496 udelay(100); 5595 udelay(100);
5497 error = e1000_verify_write_ich8_byte(hw, 5596 }
5498 (i << 1) + new_bank_offset, low_byte); 5597 } else {
5499 if (error != E1000_SUCCESS) 5598 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5500 sector_write_failed = TRUE; 5599 &low_byte);
5600 udelay(100);
5601 error = e1000_verify_write_ich8_byte(hw,
5602 (i << 1) + new_bank_offset, low_byte);
5603
5604 if (error != E1000_SUCCESS)
5605 sector_write_failed = TRUE;
5606 else {
5501 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1, 5607 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5502 &high_byte); 5608 &high_byte);
5609 udelay(100);
5503 } 5610 }
5611 }
5504 5612
5613 /* If the write of the low byte was successful, go ahread and
5614 * write the high byte while checking to make sure that if it
5615 * is the signature byte, then it is handled properly */
5616 if (sector_write_failed == FALSE) {
5505 /* If the word is 0x13, then make sure the signature bits 5617 /* If the word is 0x13, then make sure the signature bits
5506 * (15:14) are 11b until the commit has completed. 5618 * (15:14) are 11b until the commit has completed.
5507 * This will allow us to write 10b which indicates the 5619 * This will allow us to write 10b which indicates the
@@ -5512,45 +5624,45 @@ e1000_commit_shadow_ram(struct e1000_hw *hw)
5512 high_byte = E1000_ICH8_NVM_SIG_MASK | high_byte; 5624 high_byte = E1000_ICH8_NVM_SIG_MASK | high_byte;
5513 5625
5514 error = e1000_verify_write_ich8_byte(hw, 5626 error = e1000_verify_write_ich8_byte(hw,
5515 (i << 1) + new_bank_offset + 1, high_byte); 5627 (i << 1) + new_bank_offset + 1, high_byte);
5516 if (error != E1000_SUCCESS) 5628 if (error != E1000_SUCCESS)
5517 sector_write_failed = TRUE; 5629 sector_write_failed = TRUE;
5518 5630
5519 if (sector_write_failed == FALSE) { 5631 } else {
5520 /* Clear the now not used entry in the cache */ 5632 /* If the write failed then break from the loop and
5521 hw->eeprom_shadow_ram[i].modified = FALSE; 5633 * return an error */
5522 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF; 5634 break;
5523 }
5524 } 5635 }
5636 }
5525 5637
5526 /* Don't bother writing the segment valid bits if sector 5638 /* Don't bother writing the segment valid bits if sector
5527 * programming failed. */ 5639 * programming failed. */
5528 if (sector_write_failed == FALSE) { 5640 if (sector_write_failed == FALSE) {
5529 /* Finally validate the new segment by setting bit 15:14 5641 /* Finally validate the new segment by setting bit 15:14
5530 * to 10b in word 0x13 , this can be done without an 5642 * to 10b in word 0x13 , this can be done without an
5531 * erase as well since these bits are 11 to start with 5643 * erase as well since these bits are 11 to start with
5532 * and we need to change bit 14 to 0b */ 5644 * and we need to change bit 14 to 0b */
5533 e1000_read_ich8_byte(hw, 5645 e1000_read_ich8_byte(hw,
5534 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset, 5646 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5535 &high_byte); 5647 &high_byte);
5536 high_byte &= 0xBF; 5648 high_byte &= 0xBF;
5649 error = e1000_verify_write_ich8_byte(hw,
5650 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset, high_byte);
5651 /* And invalidate the previously valid segment by setting
5652 * its signature word (0x13) high_byte to 0b. This can be
5653 * done without an erase because flash erase sets all bits
5654 * to 1's. We can write 1's to 0's without an erase */
5655 if (error == E1000_SUCCESS) {
5537 error = e1000_verify_write_ich8_byte(hw, 5656 error = e1000_verify_write_ich8_byte(hw,
5538 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset, 5657 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + old_bank_offset, 0);
5539 high_byte); 5658 }
5540 if (error != E1000_SUCCESS)
5541 sector_write_failed = TRUE;
5542 5659
5543 /* And invalidate the previously valid segment by setting 5660 /* Clear the now not used entry in the cache */
5544 * its signature word (0x13) high_byte to 0b. This can be 5661 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5545 * done without an erase because flash erase sets all bits 5662 hw->eeprom_shadow_ram[i].modified = FALSE;
5546 * to 1's. We can write 1's to 0's without an erase */ 5663 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
5547 error = e1000_verify_write_ich8_byte(hw,
5548 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + old_bank_offset,
5549 0);
5550 if (error != E1000_SUCCESS)
5551 sector_write_failed = TRUE;
5552 } 5664 }
5553 } while (++sector_retries < 10 && sector_write_failed == TRUE); 5665 }
5554 } 5666 }
5555 5667
5556 return error; 5668 return error;
@@ -5640,99 +5752,6 @@ e1000_init_rx_addrs(struct e1000_hw *hw)
5640} 5752}
5641 5753
5642/****************************************************************************** 5754/******************************************************************************
5643 * Updates the MAC's list of multicast addresses.
5644 *
5645 * hw - Struct containing variables accessed by shared code
5646 * mc_addr_list - the list of new multicast addresses
5647 * mc_addr_count - number of addresses
5648 * pad - number of bytes between addresses in the list
5649 * rar_used_count - offset where to start adding mc addresses into the RAR's
5650 *
5651 * The given list replaces any existing list. Clears the last 15 receive
5652 * address registers and the multicast table. Uses receive address registers
5653 * for the first 15 multicast addresses, and hashes the rest into the
5654 * multicast table.
5655 *****************************************************************************/
5656#if 0
5657void
5658e1000_mc_addr_list_update(struct e1000_hw *hw,
5659 uint8_t *mc_addr_list,
5660 uint32_t mc_addr_count,
5661 uint32_t pad,
5662 uint32_t rar_used_count)
5663{
5664 uint32_t hash_value;
5665 uint32_t i;
5666 uint32_t num_rar_entry;
5667 uint32_t num_mta_entry;
5668
5669 DEBUGFUNC("e1000_mc_addr_list_update");
5670
5671 /* Set the new number of MC addresses that we are being requested to use. */
5672 hw->num_mc_addrs = mc_addr_count;
5673
5674 /* Clear RAR[1-15] */
5675 DEBUGOUT(" Clearing RAR[1-15]\n");
5676 num_rar_entry = E1000_RAR_ENTRIES;
5677 if (hw->mac_type == e1000_ich8lan)
5678 num_rar_entry = E1000_RAR_ENTRIES_ICH8LAN;
5679 /* Reserve a spot for the Locally Administered Address to work around
5680 * an 82571 issue in which a reset on one port will reload the MAC on
5681 * the other port. */
5682 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5683 num_rar_entry -= 1;
5684
5685 for (i = rar_used_count; i < num_rar_entry; i++) {
5686 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5687 E1000_WRITE_FLUSH(hw);
5688 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5689 E1000_WRITE_FLUSH(hw);
5690 }
5691
5692 /* Clear the MTA */
5693 DEBUGOUT(" Clearing MTA\n");
5694 num_mta_entry = E1000_NUM_MTA_REGISTERS;
5695 if (hw->mac_type == e1000_ich8lan)
5696 num_mta_entry = E1000_NUM_MTA_REGISTERS_ICH8LAN;
5697 for (i = 0; i < num_mta_entry; i++) {
5698 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
5699 E1000_WRITE_FLUSH(hw);
5700 }
5701
5702 /* Add the new addresses */
5703 for (i = 0; i < mc_addr_count; i++) {
5704 DEBUGOUT(" Adding the multicast addresses:\n");
5705 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
5706 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
5707 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
5708 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
5709 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
5710 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
5711 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
5712
5713 hash_value = e1000_hash_mc_addr(hw,
5714 mc_addr_list +
5715 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
5716
5717 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
5718
5719 /* Place this multicast address in the RAR if there is room, *
5720 * else put it in the MTA
5721 */
5722 if (rar_used_count < num_rar_entry) {
5723 e1000_rar_set(hw,
5724 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
5725 rar_used_count);
5726 rar_used_count++;
5727 } else {
5728 e1000_mta_set(hw, hash_value);
5729 }
5730 }
5731 DEBUGOUT("MC Update Complete\n");
5732}
5733#endif /* 0 */
5734
5735/******************************************************************************
5736 * Hashes an address to determine its location in the multicast table 5755 * Hashes an address to determine its location in the multicast table
5737 * 5756 *
5738 * hw - Struct containing variables accessed by shared code 5757 * hw - Struct containing variables accessed by shared code
@@ -6290,7 +6309,7 @@ e1000_led_off(struct e1000_hw *hw)
6290 * 6309 *
6291 * hw - Struct containing variables accessed by shared code 6310 * hw - Struct containing variables accessed by shared code
6292 *****************************************************************************/ 6311 *****************************************************************************/
6293void 6312static void
6294e1000_clear_hw_cntrs(struct e1000_hw *hw) 6313e1000_clear_hw_cntrs(struct e1000_hw *hw)
6295{ 6314{
6296 volatile uint32_t temp; 6315 volatile uint32_t temp;
@@ -6539,6 +6558,8 @@ e1000_tbi_adjust_stats(struct e1000_hw *hw,
6539void 6558void
6540e1000_get_bus_info(struct e1000_hw *hw) 6559e1000_get_bus_info(struct e1000_hw *hw)
6541{ 6560{
6561 int32_t ret_val;
6562 uint16_t pci_ex_link_status;
6542 uint32_t status; 6563 uint32_t status;
6543 6564
6544 switch (hw->mac_type) { 6565 switch (hw->mac_type) {
@@ -6548,18 +6569,25 @@ e1000_get_bus_info(struct e1000_hw *hw)
6548 hw->bus_speed = e1000_bus_speed_unknown; 6569 hw->bus_speed = e1000_bus_speed_unknown;
6549 hw->bus_width = e1000_bus_width_unknown; 6570 hw->bus_width = e1000_bus_width_unknown;
6550 break; 6571 break;
6572 case e1000_82571:
6551 case e1000_82572: 6573 case e1000_82572:
6552 case e1000_82573: 6574 case e1000_82573:
6575 case e1000_80003es2lan:
6553 hw->bus_type = e1000_bus_type_pci_express; 6576 hw->bus_type = e1000_bus_type_pci_express;
6554 hw->bus_speed = e1000_bus_speed_2500; 6577 hw->bus_speed = e1000_bus_speed_2500;
6555 hw->bus_width = e1000_bus_width_pciex_1; 6578 ret_val = e1000_read_pcie_cap_reg(hw,
6579 PCI_EX_LINK_STATUS,
6580 &pci_ex_link_status);
6581 if (ret_val)
6582 hw->bus_width = e1000_bus_width_unknown;
6583 else
6584 hw->bus_width = (pci_ex_link_status & PCI_EX_LINK_WIDTH_MASK) >>
6585 PCI_EX_LINK_WIDTH_SHIFT;
6556 break; 6586 break;
6557 case e1000_82571:
6558 case e1000_ich8lan: 6587 case e1000_ich8lan:
6559 case e1000_80003es2lan:
6560 hw->bus_type = e1000_bus_type_pci_express; 6588 hw->bus_type = e1000_bus_type_pci_express;
6561 hw->bus_speed = e1000_bus_speed_2500; 6589 hw->bus_speed = e1000_bus_speed_2500;
6562 hw->bus_width = e1000_bus_width_pciex_4; 6590 hw->bus_width = e1000_bus_width_pciex_1;
6563 break; 6591 break;
6564 default: 6592 default:
6565 status = E1000_READ_REG(hw, STATUS); 6593 status = E1000_READ_REG(hw, STATUS);
@@ -6593,25 +6621,6 @@ e1000_get_bus_info(struct e1000_hw *hw)
6593 break; 6621 break;
6594 } 6622 }
6595} 6623}
6596/******************************************************************************
6597 * Reads a value from one of the devices registers using port I/O (as opposed
6598 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6599 *
6600 * hw - Struct containing variables accessed by shared code
6601 * offset - offset to read from
6602 *****************************************************************************/
6603#if 0
6604uint32_t
6605e1000_read_reg_io(struct e1000_hw *hw,
6606 uint32_t offset)
6607{
6608 unsigned long io_addr = hw->io_base;
6609 unsigned long io_data = hw->io_base + 4;
6610
6611 e1000_io_write(hw, io_addr, offset);
6612 return e1000_io_read(hw, io_data);
6613}
6614#endif /* 0 */
6615 6624
6616/****************************************************************************** 6625/******************************************************************************
6617 * Writes a value to one of the devices registers using port I/O (as opposed to 6626 * Writes a value to one of the devices registers using port I/O (as opposed to
@@ -6633,7 +6642,6 @@ e1000_write_reg_io(struct e1000_hw *hw,
6633 e1000_io_write(hw, io_data, value); 6642 e1000_io_write(hw, io_data, value);
6634} 6643}
6635 6644
6636
6637/****************************************************************************** 6645/******************************************************************************
6638 * Estimates the cable length. 6646 * Estimates the cable length.
6639 * 6647 *
@@ -6842,7 +6850,7 @@ e1000_get_cable_length(struct e1000_hw *hw,
6842 *****************************************************************************/ 6850 *****************************************************************************/
6843static int32_t 6851static int32_t
6844e1000_check_polarity(struct e1000_hw *hw, 6852e1000_check_polarity(struct e1000_hw *hw,
6845 uint16_t *polarity) 6853 e1000_rev_polarity *polarity)
6846{ 6854{
6847 int32_t ret_val; 6855 int32_t ret_val;
6848 uint16_t phy_data; 6856 uint16_t phy_data;
@@ -6856,8 +6864,10 @@ e1000_check_polarity(struct e1000_hw *hw,
6856 &phy_data); 6864 &phy_data);
6857 if (ret_val) 6865 if (ret_val)
6858 return ret_val; 6866 return ret_val;
6859 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >> 6867 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
6860 M88E1000_PSSR_REV_POLARITY_SHIFT; 6868 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
6869 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6870
6861 } else if (hw->phy_type == e1000_phy_igp || 6871 } else if (hw->phy_type == e1000_phy_igp ||
6862 hw->phy_type == e1000_phy_igp_3 || 6872 hw->phy_type == e1000_phy_igp_3 ||
6863 hw->phy_type == e1000_phy_igp_2) { 6873 hw->phy_type == e1000_phy_igp_2) {
@@ -6879,19 +6889,22 @@ e1000_check_polarity(struct e1000_hw *hw,
6879 return ret_val; 6889 return ret_val;
6880 6890
6881 /* Check the polarity bits */ 6891 /* Check the polarity bits */
6882 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0; 6892 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
6893 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6883 } else { 6894 } else {
6884 /* For 10 Mbps, read the polarity bit in the status register. (for 6895 /* For 10 Mbps, read the polarity bit in the status register. (for
6885 * 100 Mbps this bit is always 0) */ 6896 * 100 Mbps this bit is always 0) */
6886 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED; 6897 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
6898 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6887 } 6899 }
6888 } else if (hw->phy_type == e1000_phy_ife) { 6900 } else if (hw->phy_type == e1000_phy_ife) {
6889 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL, 6901 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6890 &phy_data); 6902 &phy_data);
6891 if (ret_val) 6903 if (ret_val)
6892 return ret_val; 6904 return ret_val;
6893 *polarity = (phy_data & IFE_PESC_POLARITY_REVERSED) >> 6905 *polarity = ((phy_data & IFE_PESC_POLARITY_REVERSED) >>
6894 IFE_PESC_POLARITY_REVERSED_SHIFT; 6906 IFE_PESC_POLARITY_REVERSED_SHIFT) ?
6907 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6895 } 6908 }
6896 return E1000_SUCCESS; 6909 return E1000_SUCCESS;
6897} 6910}
@@ -7259,7 +7272,7 @@ e1000_set_d3_lplu_state(struct e1000_hw *hw,
7259 } else if (hw->smart_speed == e1000_smart_speed_off) { 7272 } else if (hw->smart_speed == e1000_smart_speed_off) {
7260 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, 7273 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7261 &phy_data); 7274 &phy_data);
7262 if (ret_val) 7275 if (ret_val)
7263 return ret_val; 7276 return ret_val;
7264 7277
7265 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; 7278 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
@@ -7369,7 +7382,7 @@ e1000_set_d0_lplu_state(struct e1000_hw *hw,
7369 } else if (hw->smart_speed == e1000_smart_speed_off) { 7382 } else if (hw->smart_speed == e1000_smart_speed_off) {
7370 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, 7383 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7371 &phy_data); 7384 &phy_data);
7372 if (ret_val) 7385 if (ret_val)
7373 return ret_val; 7386 return ret_val;
7374 7387
7375 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; 7388 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
@@ -7475,7 +7488,7 @@ e1000_set_vco_speed(struct e1000_hw *hw)
7475 * 7488 *
7476 * returns: - E1000_SUCCESS . 7489 * returns: - E1000_SUCCESS .
7477 ****************************************************************************/ 7490 ****************************************************************************/
7478int32_t 7491static int32_t
7479e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer) 7492e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
7480{ 7493{
7481 uint8_t i; 7494 uint8_t i;
@@ -7686,7 +7699,7 @@ e1000_check_mng_mode(struct e1000_hw *hw)
7686 ****************************************************************************/ 7699 ****************************************************************************/
7687int32_t 7700int32_t
7688e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer, 7701e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
7689 uint16_t length) 7702 uint16_t length)
7690{ 7703{
7691 int32_t ret_val; 7704 int32_t ret_val;
7692 struct e1000_host_mng_command_header hdr; 7705 struct e1000_host_mng_command_header hdr;
@@ -7716,7 +7729,7 @@ e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
7716 * 7729 *
7717 * returns - checksum of buffer contents. 7730 * returns - checksum of buffer contents.
7718 ****************************************************************************/ 7731 ****************************************************************************/
7719uint8_t 7732static uint8_t
7720e1000_calculate_mng_checksum(char *buffer, uint32_t length) 7733e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7721{ 7734{
7722 uint8_t sum = 0; 7735 uint8_t sum = 0;
@@ -7914,32 +7927,6 @@ e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7914 E1000_WRITE_REG(hw, CTRL, ctrl); 7927 E1000_WRITE_REG(hw, CTRL, ctrl);
7915} 7928}
7916 7929
7917/***************************************************************************
7918 *
7919 * Enables PCI-Express master access.
7920 *
7921 * hw: Struct containing variables accessed by shared code
7922 *
7923 * returns: - none.
7924 *
7925 ***************************************************************************/
7926#if 0
7927void
7928e1000_enable_pciex_master(struct e1000_hw *hw)
7929{
7930 uint32_t ctrl;
7931
7932 DEBUGFUNC("e1000_enable_pciex_master");
7933
7934 if (hw->bus_type != e1000_bus_type_pci_express)
7935 return;
7936
7937 ctrl = E1000_READ_REG(hw, CTRL);
7938 ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
7939 E1000_WRITE_REG(hw, CTRL, ctrl);
7940}
7941#endif /* 0 */
7942
7943/******************************************************************************* 7930/*******************************************************************************
7944 * 7931 *
7945 * Disables PCI-Express master access and verifies there are no pending requests 7932 * Disables PCI-Express master access and verifies there are no pending requests
@@ -8063,7 +8050,6 @@ e1000_get_phy_cfg_done(struct e1000_hw *hw)
8063 msleep(1); 8050 msleep(1);
8064 timeout--; 8051 timeout--;
8065 } 8052 }
8066
8067 if (!timeout) { 8053 if (!timeout) {
8068 DEBUGOUT("MNG configuration cycle has not completed.\n"); 8054 DEBUGOUT("MNG configuration cycle has not completed.\n");
8069 return -E1000_ERR_RESET; 8055 return -E1000_ERR_RESET;
@@ -8172,8 +8158,9 @@ e1000_get_software_semaphore(struct e1000_hw *hw)
8172 8158
8173 DEBUGFUNC("e1000_get_software_semaphore"); 8159 DEBUGFUNC("e1000_get_software_semaphore");
8174 8160
8175 if (hw->mac_type != e1000_80003es2lan) 8161 if (hw->mac_type != e1000_80003es2lan) {
8176 return E1000_SUCCESS; 8162 return E1000_SUCCESS;
8163 }
8177 8164
8178 while (timeout) { 8165 while (timeout) {
8179 swsm = E1000_READ_REG(hw, SWSM); 8166 swsm = E1000_READ_REG(hw, SWSM);
@@ -8206,8 +8193,9 @@ e1000_release_software_semaphore(struct e1000_hw *hw)
8206 8193
8207 DEBUGFUNC("e1000_release_software_semaphore"); 8194 DEBUGFUNC("e1000_release_software_semaphore");
8208 8195
8209 if (hw->mac_type != e1000_80003es2lan) 8196 if (hw->mac_type != e1000_80003es2lan) {
8210 return; 8197 return;
8198 }
8211 8199
8212 swsm = E1000_READ_REG(hw, SWSM); 8200 swsm = E1000_READ_REG(hw, SWSM);
8213 /* Release the SW semaphores.*/ 8201 /* Release the SW semaphores.*/
@@ -8241,7 +8229,7 @@ e1000_check_phy_reset_block(struct e1000_hw *hw)
8241 if (hw->mac_type > e1000_82547_rev_2) 8229 if (hw->mac_type > e1000_82547_rev_2)
8242 manc = E1000_READ_REG(hw, MANC); 8230 manc = E1000_READ_REG(hw, MANC);
8243 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ? 8231 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
8244 E1000_BLK_PHY_RESET : E1000_SUCCESS; 8232 E1000_BLK_PHY_RESET : E1000_SUCCESS;
8245} 8233}
8246 8234
8247static uint8_t 8235static uint8_t
@@ -8377,66 +8365,6 @@ e1000_release_software_flag(struct e1000_hw *hw)
8377 return; 8365 return;
8378} 8366}
8379 8367
8380/***************************************************************************
8381 *
8382 * Disable dynamic power down mode in ife PHY.
8383 * It can be used to workaround band-gap problem.
8384 *
8385 * hw: Struct containing variables accessed by shared code
8386 *
8387 ***************************************************************************/
8388#if 0
8389int32_t
8390e1000_ife_disable_dynamic_power_down(struct e1000_hw *hw)
8391{
8392 uint16_t phy_data;
8393 int32_t ret_val = E1000_SUCCESS;
8394
8395 DEBUGFUNC("e1000_ife_disable_dynamic_power_down");
8396
8397 if (hw->phy_type == e1000_phy_ife) {
8398 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
8399 if (ret_val)
8400 return ret_val;
8401
8402 phy_data |= IFE_PSC_DISABLE_DYNAMIC_POWER_DOWN;
8403 ret_val = e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, phy_data);
8404 }
8405
8406 return ret_val;
8407}
8408#endif /* 0 */
8409
8410/***************************************************************************
8411 *
8412 * Enable dynamic power down mode in ife PHY.
8413 * It can be used to workaround band-gap problem.
8414 *
8415 * hw: Struct containing variables accessed by shared code
8416 *
8417 ***************************************************************************/
8418#if 0
8419int32_t
8420e1000_ife_enable_dynamic_power_down(struct e1000_hw *hw)
8421{
8422 uint16_t phy_data;
8423 int32_t ret_val = E1000_SUCCESS;
8424
8425 DEBUGFUNC("e1000_ife_enable_dynamic_power_down");
8426
8427 if (hw->phy_type == e1000_phy_ife) {
8428 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
8429 if (ret_val)
8430 return ret_val;
8431
8432 phy_data &= ~IFE_PSC_DISABLE_DYNAMIC_POWER_DOWN;
8433 ret_val = e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, phy_data);
8434 }
8435
8436 return ret_val;
8437}
8438#endif /* 0 */
8439
8440/****************************************************************************** 8368/******************************************************************************
8441 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access 8369 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8442 * register. 8370 * register.
@@ -8832,20 +8760,22 @@ static int32_t
8832e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte) 8760e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte)
8833{ 8761{
8834 int32_t error = E1000_SUCCESS; 8762 int32_t error = E1000_SUCCESS;
8835 int32_t program_retries; 8763 int32_t program_retries = 0;
8836 uint8_t temp_byte;
8837 8764
8838 e1000_write_ich8_byte(hw, index, byte); 8765 DEBUGOUT2("Byte := %2.2X Offset := %d\n", byte, index);
8839 udelay(100);
8840 8766
8841 for (program_retries = 0; program_retries < 100; program_retries++) { 8767 error = e1000_write_ich8_byte(hw, index, byte);
8842 e1000_read_ich8_byte(hw, index, &temp_byte); 8768
8843 if (temp_byte == byte) 8769 if (error != E1000_SUCCESS) {
8844 break; 8770 for (program_retries = 0; program_retries < 100; program_retries++) {
8845 udelay(10); 8771 DEBUGOUT2("Retrying \t Byte := %2.2X Offset := %d\n", byte, index);
8846 e1000_write_ich8_byte(hw, index, byte); 8772 error = e1000_write_ich8_byte(hw, index, byte);
8847 udelay(100); 8773 udelay(100);
8774 if (error == E1000_SUCCESS)
8775 break;
8776 }
8848 } 8777 }
8778
8849 if (program_retries == 100) 8779 if (program_retries == 100)
8850 error = E1000_ERR_EEPROM; 8780 error = E1000_ERR_EEPROM;
8851 8781
@@ -8886,39 +8816,27 @@ e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data)
8886} 8816}
8887 8817
8888/****************************************************************************** 8818/******************************************************************************
8889 * Writes a word to the NVM using the ICH8 flash access registers. 8819 * Erases the bank specified. Each bank may be a 4, 8 or 64k block. Banks are 0
8820 * based.
8890 * 8821 *
8891 * hw - pointer to e1000_hw structure 8822 * hw - pointer to e1000_hw structure
8892 * index - The starting byte index of the word to read. 8823 * bank - 0 for first bank, 1 for second bank
8893 * data - The word to write to the NVM.
8894 *****************************************************************************/
8895#if 0
8896int32_t
8897e1000_write_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t data)
8898{
8899 int32_t status = E1000_SUCCESS;
8900 status = e1000_write_ich8_data(hw, index, 2, data);
8901 return status;
8902}
8903#endif /* 0 */
8904
8905/******************************************************************************
8906 * Erases the bank specified. Each bank is a 4k block. Segments are 0 based.
8907 * segment N is 4096 * N + flash_reg_addr.
8908 * 8824 *
8909 * hw - pointer to e1000_hw structure 8825 * Note that this function may actually erase as much as 8 or 64 KBytes. The
8910 * segment - 0 for first segment, 1 for second segment, etc. 8826 * amount of NVM used in each bank is a *minimum* of 4 KBytes, but in fact the
8827 * bank size may be 4, 8 or 64 KBytes
8911 *****************************************************************************/ 8828 *****************************************************************************/
8912static int32_t 8829int32_t
8913e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t segment) 8830e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank)
8914{ 8831{
8915 union ich8_hws_flash_status hsfsts; 8832 union ich8_hws_flash_status hsfsts;
8916 union ich8_hws_flash_ctrl hsflctl; 8833 union ich8_hws_flash_ctrl hsflctl;
8917 uint32_t flash_linear_address; 8834 uint32_t flash_linear_address;
8918 int32_t count = 0; 8835 int32_t count = 0;
8919 int32_t error = E1000_ERR_EEPROM; 8836 int32_t error = E1000_ERR_EEPROM;
8920 int32_t iteration, seg_size; 8837 int32_t iteration;
8921 int32_t sector_size; 8838 int32_t sub_sector_size = 0;
8839 int32_t bank_size;
8922 int32_t j = 0; 8840 int32_t j = 0;
8923 int32_t error_flag = 0; 8841 int32_t error_flag = 0;
8924 8842
@@ -8927,22 +8845,27 @@ e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t segment)
8927 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */ 8845 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */
8928 /* 00: The Hw sector is 256 bytes, hence we need to erase 16 8846 /* 00: The Hw sector is 256 bytes, hence we need to erase 16
8929 * consecutive sectors. The start index for the nth Hw sector can be 8847 * consecutive sectors. The start index for the nth Hw sector can be
8930 * calculated as = segment * 4096 + n * 256 8848 * calculated as bank * 4096 + n * 256
8931 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector. 8849 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
8932 * The start index for the nth Hw sector can be calculated 8850 * The start index for the nth Hw sector can be calculated
8933 * as = segment * 4096 8851 * as bank * 4096
8934 * 10: Error condition 8852 * 10: The HW sector is 8K bytes
8935 * 11: The Hw sector size is much bigger than the size asked to 8853 * 11: The Hw sector size is 64K bytes */
8936 * erase...error condition */
8937 if (hsfsts.hsf_status.berasesz == 0x0) { 8854 if (hsfsts.hsf_status.berasesz == 0x0) {
8938 /* Hw sector size 256 */ 8855 /* Hw sector size 256 */
8939 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_256; 8856 sub_sector_size = ICH8_FLASH_SEG_SIZE_256;
8857 bank_size = ICH8_FLASH_SECTOR_SIZE;
8940 iteration = ICH8_FLASH_SECTOR_SIZE / ICH8_FLASH_SEG_SIZE_256; 8858 iteration = ICH8_FLASH_SECTOR_SIZE / ICH8_FLASH_SEG_SIZE_256;
8941 } else if (hsfsts.hsf_status.berasesz == 0x1) { 8859 } else if (hsfsts.hsf_status.berasesz == 0x1) {
8942 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_4K; 8860 bank_size = ICH8_FLASH_SEG_SIZE_4K;
8861 iteration = 1;
8862 } else if (hw->mac_type != e1000_ich8lan &&
8863 hsfsts.hsf_status.berasesz == 0x2) {
8864 /* 8K erase size invalid for ICH8 - added in for ICH9 */
8865 bank_size = ICH9_FLASH_SEG_SIZE_8K;
8943 iteration = 1; 8866 iteration = 1;
8944 } else if (hsfsts.hsf_status.berasesz == 0x3) { 8867 } else if (hsfsts.hsf_status.berasesz == 0x3) {
8945 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_64K; 8868 bank_size = ICH8_FLASH_SEG_SIZE_64K;
8946 iteration = 1; 8869 iteration = 1;
8947 } else { 8870 } else {
8948 return error; 8871 return error;
@@ -8966,16 +8889,15 @@ e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t segment)
8966 8889
8967 /* Write the last 24 bits of an index within the block into Flash 8890 /* Write the last 24 bits of an index within the block into Flash
8968 * Linear address field in Flash Address. This probably needs to 8891 * Linear address field in Flash Address. This probably needs to
8969 * be calculated here based off the on-chip segment size and the 8892 * be calculated here based off the on-chip erase sector size and
8970 * software segment size assumed (4K) */ 8893 * the software bank size (4, 8 or 64 KBytes) */
8971 /* TBD */ 8894 flash_linear_address = bank * bank_size + j * sub_sector_size;
8972 flash_linear_address = segment * sector_size + j * seg_size;
8973 flash_linear_address &= ICH8_FLASH_LINEAR_ADDR_MASK;
8974 flash_linear_address += hw->flash_base_addr; 8895 flash_linear_address += hw->flash_base_addr;
8896 flash_linear_address &= ICH8_FLASH_LINEAR_ADDR_MASK;
8975 8897
8976 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address); 8898 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8977 8899
8978 error = e1000_ich8_flash_cycle(hw, 1000000); 8900 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_ERASE_TIMEOUT);
8979 /* Check if FCERR is set to 1. If 1, clear it and try the whole 8901 /* Check if FCERR is set to 1. If 1, clear it and try the whole
8980 * sequence a few more times else Done */ 8902 * sequence a few more times else Done */
8981 if (error == E1000_SUCCESS) { 8903 if (error == E1000_SUCCESS) {
@@ -8999,44 +8921,6 @@ e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t segment)
8999 return error; 8921 return error;
9000} 8922}
9001 8923
9002/******************************************************************************
9003 *
9004 * Reverse duplex setting without breaking the link.
9005 *
9006 * hw: Struct containing variables accessed by shared code
9007 *
9008 *****************************************************************************/
9009#if 0
9010int32_t
9011e1000_duplex_reversal(struct e1000_hw *hw)
9012{
9013 int32_t ret_val;
9014 uint16_t phy_data;
9015
9016 if (hw->phy_type != e1000_phy_igp_3)
9017 return E1000_SUCCESS;
9018
9019 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
9020 if (ret_val)
9021 return ret_val;
9022
9023 phy_data ^= MII_CR_FULL_DUPLEX;
9024
9025 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
9026 if (ret_val)
9027 return ret_val;
9028
9029 ret_val = e1000_read_phy_reg(hw, IGP3E1000_PHY_MISC_CTRL, &phy_data);
9030 if (ret_val)
9031 return ret_val;
9032
9033 phy_data |= IGP3_PHY_MISC_DUPLEX_MANUAL_SET;
9034 ret_val = e1000_write_phy_reg(hw, IGP3E1000_PHY_MISC_CTRL, phy_data);
9035
9036 return ret_val;
9037}
9038#endif /* 0 */
9039
9040static int32_t 8924static int32_t
9041e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw, 8925e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
9042 uint32_t cnf_base_addr, uint32_t cnf_size) 8926 uint32_t cnf_base_addr, uint32_t cnf_size)
@@ -9071,6 +8955,14 @@ e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
9071} 8955}
9072 8956
9073 8957
8958/******************************************************************************
8959 * This function initializes the PHY from the NVM on ICH8 platforms. This
8960 * is needed due to an issue where the NVM configuration is not properly
8961 * autoloaded after power transitions. Therefore, after each PHY reset, we
8962 * will load the configuration data out of the NVM manually.
8963 *
8964 * hw: Struct containing variables accessed by shared code
8965 *****************************************************************************/
9074static int32_t 8966static int32_t
9075e1000_init_lcd_from_nvm(struct e1000_hw *hw) 8967e1000_init_lcd_from_nvm(struct e1000_hw *hw)
9076{ 8968{
diff --git a/drivers/net/e1000/e1000_hw.h b/drivers/net/e1000/e1000_hw.h
index a170e96251f6..112447fd8bf2 100644
--- a/drivers/net/e1000/e1000_hw.h
+++ b/drivers/net/e1000/e1000_hw.h
@@ -1,25 +1,24 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version. 9
10 10 This program is distributed in the hope it will be useful, but WITHOUT
11 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
25 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> 24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
@@ -93,11 +92,11 @@ typedef enum {
93 92
94/* Flow Control Settings */ 93/* Flow Control Settings */
95typedef enum { 94typedef enum {
96 e1000_fc_none = 0, 95 E1000_FC_NONE = 0,
97 e1000_fc_rx_pause = 1, 96 E1000_FC_RX_PAUSE = 1,
98 e1000_fc_tx_pause = 2, 97 E1000_FC_TX_PAUSE = 2,
99 e1000_fc_full = 3, 98 E1000_FC_FULL = 3,
100 e1000_fc_default = 0xFF 99 E1000_FC_DEFAULT = 0xFF
101} e1000_fc_type; 100} e1000_fc_type;
102 101
103struct e1000_shadow_ram { 102struct e1000_shadow_ram {
@@ -302,6 +301,9 @@ typedef enum {
302#define E1000_BLK_PHY_RESET 12 301#define E1000_BLK_PHY_RESET 12
303#define E1000_ERR_SWFW_SYNC 13 302#define E1000_ERR_SWFW_SYNC 13
304 303
304#define E1000_BYTE_SWAP_WORD(_value) ((((_value) & 0x00ff) << 8) | \
305 (((_value) & 0xff00) >> 8))
306
305/* Function prototypes */ 307/* Function prototypes */
306/* Initialization */ 308/* Initialization */
307int32_t e1000_reset_hw(struct e1000_hw *hw); 309int32_t e1000_reset_hw(struct e1000_hw *hw);
@@ -314,7 +316,7 @@ int32_t e1000_setup_link(struct e1000_hw *hw);
314int32_t e1000_phy_setup_autoneg(struct e1000_hw *hw); 316int32_t e1000_phy_setup_autoneg(struct e1000_hw *hw);
315void e1000_config_collision_dist(struct e1000_hw *hw); 317void e1000_config_collision_dist(struct e1000_hw *hw);
316int32_t e1000_check_for_link(struct e1000_hw *hw); 318int32_t e1000_check_for_link(struct e1000_hw *hw);
317int32_t e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t * speed, uint16_t * duplex); 319int32_t e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t *speed, uint16_t *duplex);
318int32_t e1000_force_mac_fc(struct e1000_hw *hw); 320int32_t e1000_force_mac_fc(struct e1000_hw *hw);
319 321
320/* PHY */ 322/* PHY */
@@ -322,9 +324,9 @@ int32_t e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *phy
322int32_t e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data); 324int32_t e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data);
323int32_t e1000_phy_hw_reset(struct e1000_hw *hw); 325int32_t e1000_phy_hw_reset(struct e1000_hw *hw);
324int32_t e1000_phy_reset(struct e1000_hw *hw); 326int32_t e1000_phy_reset(struct e1000_hw *hw);
325void e1000_phy_powerdown_workaround(struct e1000_hw *hw);
326int32_t e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info); 327int32_t e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
327int32_t e1000_validate_mdi_setting(struct e1000_hw *hw); 328int32_t e1000_validate_mdi_setting(struct e1000_hw *hw);
329void e1000_phy_powerdown_workaround(struct e1000_hw *hw);
328 330
329/* EEPROM Functions */ 331/* EEPROM Functions */
330int32_t e1000_init_eeprom_params(struct e1000_hw *hw); 332int32_t e1000_init_eeprom_params(struct e1000_hw *hw);
@@ -393,7 +395,6 @@ int32_t e1000_read_eeprom(struct e1000_hw *hw, uint16_t reg, uint16_t words, uin
393int32_t e1000_validate_eeprom_checksum(struct e1000_hw *hw); 395int32_t e1000_validate_eeprom_checksum(struct e1000_hw *hw);
394int32_t e1000_update_eeprom_checksum(struct e1000_hw *hw); 396int32_t e1000_update_eeprom_checksum(struct e1000_hw *hw);
395int32_t e1000_write_eeprom(struct e1000_hw *hw, uint16_t reg, uint16_t words, uint16_t *data); 397int32_t e1000_write_eeprom(struct e1000_hw *hw, uint16_t reg, uint16_t words, uint16_t *data);
396int32_t e1000_read_part_num(struct e1000_hw *hw, uint32_t * part_num);
397int32_t e1000_read_mac_addr(struct e1000_hw * hw); 398int32_t e1000_read_mac_addr(struct e1000_hw * hw);
398 399
399/* Filters (multicast, vlan, receive) */ 400/* Filters (multicast, vlan, receive) */
@@ -420,6 +421,7 @@ void e1000_pci_set_mwi(struct e1000_hw *hw);
420void e1000_pci_clear_mwi(struct e1000_hw *hw); 421void e1000_pci_clear_mwi(struct e1000_hw *hw);
421void e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t * value); 422void e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t * value);
422void e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t * value); 423void e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t * value);
424int32_t e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value);
423/* Port I/O is only supported on 82544 and newer */ 425/* Port I/O is only supported on 82544 and newer */
424void e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value); 426void e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value);
425int32_t e1000_disable_pciex_master(struct e1000_hw *hw); 427int32_t e1000_disable_pciex_master(struct e1000_hw *hw);
@@ -574,10 +576,10 @@ int32_t e1000_check_phy_reset_block(struct e1000_hw *hw);
574 * E1000_RAR_ENTRIES - 1 multicast addresses. 576 * E1000_RAR_ENTRIES - 1 multicast addresses.
575 */ 577 */
576#define E1000_RAR_ENTRIES 15 578#define E1000_RAR_ENTRIES 15
577#define E1000_RAR_ENTRIES_ICH8LAN 7 579#define E1000_RAR_ENTRIES_ICH8LAN 6
578 580
579#define MIN_NUMBER_OF_DESCRIPTORS 8 581#define MIN_NUMBER_OF_DESCRIPTORS 8
580#define MAX_NUMBER_OF_DESCRIPTORS 0xFFF8 582#define MAX_NUMBER_OF_DESCRIPTORS 0xFFF8
581 583
582/* Receive Descriptor */ 584/* Receive Descriptor */
583struct e1000_rx_desc { 585struct e1000_rx_desc {
@@ -1300,6 +1302,7 @@ struct e1000_hw_stats {
1300 uint64_t algnerrc; 1302 uint64_t algnerrc;
1301 uint64_t symerrs; 1303 uint64_t symerrs;
1302 uint64_t rxerrc; 1304 uint64_t rxerrc;
1305 uint64_t txerrc;
1303 uint64_t mpc; 1306 uint64_t mpc;
1304 uint64_t scc; 1307 uint64_t scc;
1305 uint64_t ecol; 1308 uint64_t ecol;
@@ -1332,8 +1335,9 @@ struct e1000_hw_stats {
1332 uint64_t gotch; 1335 uint64_t gotch;
1333 uint64_t rnbc; 1336 uint64_t rnbc;
1334 uint64_t ruc; 1337 uint64_t ruc;
1335 uint64_t rfc;
1336 uint64_t roc; 1338 uint64_t roc;
1339 uint64_t rlerrc;
1340 uint64_t rfc;
1337 uint64_t rjc; 1341 uint64_t rjc;
1338 uint64_t mgprc; 1342 uint64_t mgprc;
1339 uint64_t mgpdc; 1343 uint64_t mgpdc;
@@ -1367,8 +1371,8 @@ struct e1000_hw_stats {
1367 1371
1368/* Structure containing variables used by the shared code (e1000_hw.c) */ 1372/* Structure containing variables used by the shared code (e1000_hw.c) */
1369struct e1000_hw { 1373struct e1000_hw {
1370 uint8_t *hw_addr; 1374 uint8_t __iomem *hw_addr;
1371 uint8_t *flash_address; 1375 uint8_t __iomem *flash_address;
1372 e1000_mac_type mac_type; 1376 e1000_mac_type mac_type;
1373 e1000_phy_type phy_type; 1377 e1000_phy_type phy_type;
1374 uint32_t phy_init_script; 1378 uint32_t phy_init_script;
@@ -1440,6 +1444,7 @@ struct e1000_hw {
1440 boolean_t tbi_compatibility_on; 1444 boolean_t tbi_compatibility_on;
1441 boolean_t laa_is_present; 1445 boolean_t laa_is_present;
1442 boolean_t phy_reset_disable; 1446 boolean_t phy_reset_disable;
1447 boolean_t initialize_hw_bits_disable;
1443 boolean_t fc_send_xon; 1448 boolean_t fc_send_xon;
1444 boolean_t fc_strict_ieee; 1449 boolean_t fc_strict_ieee;
1445 boolean_t report_tx_early; 1450 boolean_t report_tx_early;
@@ -1613,16 +1618,17 @@ struct e1000_hw {
1613#define E1000_CTRL_EXT_LINK_MODE_MASK 0x00C00000 1618#define E1000_CTRL_EXT_LINK_MODE_MASK 0x00C00000
1614#define E1000_CTRL_EXT_LINK_MODE_GMII 0x00000000 1619#define E1000_CTRL_EXT_LINK_MODE_GMII 0x00000000
1615#define E1000_CTRL_EXT_LINK_MODE_TBI 0x00C00000 1620#define E1000_CTRL_EXT_LINK_MODE_TBI 0x00C00000
1616#define E1000_CTRL_EXT_LINK_MODE_KMRN 0x00000000 1621#define E1000_CTRL_EXT_LINK_MODE_KMRN 0x00000000
1617#define E1000_CTRL_EXT_LINK_MODE_SERDES 0x00C00000 1622#define E1000_CTRL_EXT_LINK_MODE_SERDES 0x00C00000
1623#define E1000_CTRL_EXT_LINK_MODE_SGMII 0x00800000
1618#define E1000_CTRL_EXT_WR_WMARK_MASK 0x03000000 1624#define E1000_CTRL_EXT_WR_WMARK_MASK 0x03000000
1619#define E1000_CTRL_EXT_WR_WMARK_256 0x00000000 1625#define E1000_CTRL_EXT_WR_WMARK_256 0x00000000
1620#define E1000_CTRL_EXT_WR_WMARK_320 0x01000000 1626#define E1000_CTRL_EXT_WR_WMARK_320 0x01000000
1621#define E1000_CTRL_EXT_WR_WMARK_384 0x02000000 1627#define E1000_CTRL_EXT_WR_WMARK_384 0x02000000
1622#define E1000_CTRL_EXT_WR_WMARK_448 0x03000000 1628#define E1000_CTRL_EXT_WR_WMARK_448 0x03000000
1623#define E1000_CTRL_EXT_DRV_LOAD 0x10000000 /* Driver loaded bit for FW */ 1629#define E1000_CTRL_EXT_DRV_LOAD 0x10000000 /* Driver loaded bit for FW */
1624#define E1000_CTRL_EXT_IAME 0x08000000 /* Interrupt acknowledge Auto-mask */ 1630#define E1000_CTRL_EXT_IAME 0x08000000 /* Interrupt acknowledge Auto-mask */
1625#define E1000_CTRL_EXT_INT_TIMER_CLR 0x20000000 /* Clear Interrupt timers after IMS clear */ 1631#define E1000_CTRL_EXT_INT_TIMER_CLR 0x20000000 /* Clear Interrupt timers after IMS clear */
1626#define E1000_CRTL_EXT_PB_PAREN 0x01000000 /* packet buffer parity error detection enabled */ 1632#define E1000_CRTL_EXT_PB_PAREN 0x01000000 /* packet buffer parity error detection enabled */
1627#define E1000_CTRL_EXT_DF_PAREN 0x02000000 /* descriptor FIFO parity error detection enable */ 1633#define E1000_CTRL_EXT_DF_PAREN 0x02000000 /* descriptor FIFO parity error detection enable */
1628#define E1000_CTRL_EXT_GHOST_PAREN 0x40000000 1634#define E1000_CTRL_EXT_GHOST_PAREN 0x40000000
@@ -2218,6 +2224,11 @@ struct e1000_host_command_info {
2218#define E1000_FACTPS_LAN_FUNC_SEL 0x40000000 2224#define E1000_FACTPS_LAN_FUNC_SEL 0x40000000
2219#define E1000_FACTPS_PM_STATE_CHANGED 0x80000000 2225#define E1000_FACTPS_PM_STATE_CHANGED 0x80000000
2220 2226
2227/* PCI-Ex Config Space */
2228#define PCI_EX_LINK_STATUS 0x12
2229#define PCI_EX_LINK_WIDTH_MASK 0x3F0
2230#define PCI_EX_LINK_WIDTH_SHIFT 4
2231
2221/* EEPROM Commands - Microwire */ 2232/* EEPROM Commands - Microwire */
2222#define EEPROM_READ_OPCODE_MICROWIRE 0x6 /* EEPROM read opcode */ 2233#define EEPROM_READ_OPCODE_MICROWIRE 0x6 /* EEPROM read opcode */
2223#define EEPROM_WRITE_OPCODE_MICROWIRE 0x5 /* EEPROM write opcode */ 2234#define EEPROM_WRITE_OPCODE_MICROWIRE 0x5 /* EEPROM write opcode */
@@ -3120,6 +3131,7 @@ struct e1000_host_command_info {
3120/* I = Integrated 3131/* I = Integrated
3121 * E = External 3132 * E = External
3122 */ 3133 */
3134#define M88_VENDOR 0x0141
3123#define M88E1000_E_PHY_ID 0x01410C50 3135#define M88E1000_E_PHY_ID 0x01410C50
3124#define M88E1000_I_PHY_ID 0x01410C30 3136#define M88E1000_I_PHY_ID 0x01410C30
3125#define M88E1011_I_PHY_ID 0x01410C20 3137#define M88E1011_I_PHY_ID 0x01410C20
@@ -3244,10 +3256,12 @@ struct e1000_host_command_info {
3244#define IFE_PSCL_PROBE_LEDS_OFF 0x0006 /* Force LEDs 0 and 2 off */ 3256#define IFE_PSCL_PROBE_LEDS_OFF 0x0006 /* Force LEDs 0 and 2 off */
3245#define IFE_PSCL_PROBE_LEDS_ON 0x0007 /* Force LEDs 0 and 2 on */ 3257#define IFE_PSCL_PROBE_LEDS_ON 0x0007 /* Force LEDs 0 and 2 on */
3246 3258
3247#define ICH8_FLASH_COMMAND_TIMEOUT 500 /* 500 ms , should be adjusted */ 3259#define ICH8_FLASH_COMMAND_TIMEOUT 5000 /* 5000 uSecs - adjusted */
3248#define ICH8_FLASH_CYCLE_REPEAT_COUNT 10 /* 10 cycles , should be adjusted */ 3260#define ICH8_FLASH_ERASE_TIMEOUT 3000000 /* Up to 3 seconds - worst case */
3261#define ICH8_FLASH_CYCLE_REPEAT_COUNT 10 /* 10 cycles */
3249#define ICH8_FLASH_SEG_SIZE_256 256 3262#define ICH8_FLASH_SEG_SIZE_256 256
3250#define ICH8_FLASH_SEG_SIZE_4K 4096 3263#define ICH8_FLASH_SEG_SIZE_4K 4096
3264#define ICH9_FLASH_SEG_SIZE_8K 8192
3251#define ICH8_FLASH_SEG_SIZE_64K 65536 3265#define ICH8_FLASH_SEG_SIZE_64K 65536
3252 3266
3253#define ICH8_CYCLE_READ 0x0 3267#define ICH8_CYCLE_READ 0x0
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index 3f6a752700a1..7dca38fba6a1 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -1,25 +1,24 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version. 9
10 10 This program is distributed in the hope it will be useful, but WITHOUT
11 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
25 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> 24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
@@ -36,7 +35,7 @@ static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
36#else 35#else
37#define DRIVERNAPI "-NAPI" 36#define DRIVERNAPI "-NAPI"
38#endif 37#endif
39#define DRV_VERSION "7.2.7-k2"DRIVERNAPI 38#define DRV_VERSION "7.2.9-k2"DRIVERNAPI
40char e1000_driver_version[] = DRV_VERSION; 39char e1000_driver_version[] = DRV_VERSION;
41static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation."; 40static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
42 41
@@ -110,16 +109,24 @@ static struct pci_device_id e1000_pci_tbl[] = {
110 109
111MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); 110MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
112 111
112int e1000_up(struct e1000_adapter *adapter);
113void e1000_down(struct e1000_adapter *adapter);
114void e1000_reinit_locked(struct e1000_adapter *adapter);
115void e1000_reset(struct e1000_adapter *adapter);
116int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
117int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
118int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
119void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
120void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
113static int e1000_setup_tx_resources(struct e1000_adapter *adapter, 121static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
114 struct e1000_tx_ring *txdr); 122 struct e1000_tx_ring *txdr);
115static int e1000_setup_rx_resources(struct e1000_adapter *adapter, 123static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
116 struct e1000_rx_ring *rxdr); 124 struct e1000_rx_ring *rxdr);
117static void e1000_free_tx_resources(struct e1000_adapter *adapter, 125static void e1000_free_tx_resources(struct e1000_adapter *adapter,
118 struct e1000_tx_ring *tx_ring); 126 struct e1000_tx_ring *tx_ring);
119static void e1000_free_rx_resources(struct e1000_adapter *adapter, 127static void e1000_free_rx_resources(struct e1000_adapter *adapter,
120 struct e1000_rx_ring *rx_ring); 128 struct e1000_rx_ring *rx_ring);
121 129void e1000_update_stats(struct e1000_adapter *adapter);
122/* Local Function Prototypes */
123 130
124static int e1000_init_module(void); 131static int e1000_init_module(void);
125static void e1000_exit_module(void); 132static void e1000_exit_module(void);
@@ -172,6 +179,7 @@ static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
172static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); 179static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
173static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, 180static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
174 int cmd); 181 int cmd);
182void e1000_set_ethtool_ops(struct net_device *netdev);
175static void e1000_enter_82542_rst(struct e1000_adapter *adapter); 183static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
176static void e1000_leave_82542_rst(struct e1000_adapter *adapter); 184static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
177static void e1000_tx_timeout(struct net_device *dev); 185static void e1000_tx_timeout(struct net_device *dev);
@@ -196,6 +204,8 @@ static void e1000_shutdown(struct pci_dev *pdev);
196static void e1000_netpoll (struct net_device *netdev); 204static void e1000_netpoll (struct net_device *netdev);
197#endif 205#endif
198 206
207extern void e1000_check_options(struct e1000_adapter *adapter);
208
199static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, 209static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
200 pci_channel_state_t state); 210 pci_channel_state_t state);
201static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev); 211static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
@@ -212,9 +222,9 @@ static struct pci_driver e1000_driver = {
212 .id_table = e1000_pci_tbl, 222 .id_table = e1000_pci_tbl,
213 .probe = e1000_probe, 223 .probe = e1000_probe,
214 .remove = __devexit_p(e1000_remove), 224 .remove = __devexit_p(e1000_remove),
225#ifdef CONFIG_PM
215 /* Power Managment Hooks */ 226 /* Power Managment Hooks */
216 .suspend = e1000_suspend, 227 .suspend = e1000_suspend,
217#ifdef CONFIG_PM
218 .resume = e1000_resume, 228 .resume = e1000_resume,
219#endif 229#endif
220 .shutdown = e1000_shutdown, 230 .shutdown = e1000_shutdown,
@@ -466,13 +476,14 @@ e1000_up(struct e1000_adapter *adapter)
466 476
467 adapter->tx_queue_len = netdev->tx_queue_len; 477 adapter->tx_queue_len = netdev->tx_queue_len;
468 478
469 mod_timer(&adapter->watchdog_timer, jiffies);
470
471#ifdef CONFIG_E1000_NAPI 479#ifdef CONFIG_E1000_NAPI
472 netif_poll_enable(netdev); 480 netif_poll_enable(netdev);
473#endif 481#endif
474 e1000_irq_enable(adapter); 482 e1000_irq_enable(adapter);
475 483
484 clear_bit(__E1000_DOWN, &adapter->flags);
485
486 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
476 return 0; 487 return 0;
477} 488}
478 489
@@ -502,25 +513,48 @@ void e1000_power_up_phy(struct e1000_adapter *adapter)
502 513
503static void e1000_power_down_phy(struct e1000_adapter *adapter) 514static void e1000_power_down_phy(struct e1000_adapter *adapter)
504{ 515{
505 boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) && 516 /* Power down the PHY so no link is implied when interface is down *
506 e1000_check_mng_mode(&adapter->hw); 517 * The PHY cannot be powered down if any of the following is TRUE *
507 /* Power down the PHY so no link is implied when interface is down
508 * The PHY cannot be powered down if any of the following is TRUE
509 * (a) WoL is enabled 518 * (a) WoL is enabled
510 * (b) AMT is active 519 * (b) AMT is active
511 * (c) SoL/IDER session is active */ 520 * (c) SoL/IDER session is active */
512 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 && 521 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
513 adapter->hw.mac_type != e1000_ich8lan && 522 adapter->hw.media_type == e1000_media_type_copper) {
514 adapter->hw.media_type == e1000_media_type_copper &&
515 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
516 !mng_mode_enabled &&
517 !e1000_check_phy_reset_block(&adapter->hw)) {
518 uint16_t mii_reg = 0; 523 uint16_t mii_reg = 0;
524
525 switch (adapter->hw.mac_type) {
526 case e1000_82540:
527 case e1000_82545:
528 case e1000_82545_rev_3:
529 case e1000_82546:
530 case e1000_82546_rev_3:
531 case e1000_82541:
532 case e1000_82541_rev_2:
533 case e1000_82547:
534 case e1000_82547_rev_2:
535 if (E1000_READ_REG(&adapter->hw, MANC) &
536 E1000_MANC_SMBUS_EN)
537 goto out;
538 break;
539 case e1000_82571:
540 case e1000_82572:
541 case e1000_82573:
542 case e1000_80003es2lan:
543 case e1000_ich8lan:
544 if (e1000_check_mng_mode(&adapter->hw) ||
545 e1000_check_phy_reset_block(&adapter->hw))
546 goto out;
547 break;
548 default:
549 goto out;
550 }
519 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg); 551 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
520 mii_reg |= MII_CR_POWER_DOWN; 552 mii_reg |= MII_CR_POWER_DOWN;
521 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg); 553 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
522 mdelay(1); 554 mdelay(1);
523 } 555 }
556out:
557 return;
524} 558}
525 559
526void 560void
@@ -528,6 +562,10 @@ e1000_down(struct e1000_adapter *adapter)
528{ 562{
529 struct net_device *netdev = adapter->netdev; 563 struct net_device *netdev = adapter->netdev;
530 564
565 /* signal that we're down so the interrupt handler does not
566 * reschedule our watchdog timer */
567 set_bit(__E1000_DOWN, &adapter->flags);
568
531 e1000_irq_disable(adapter); 569 e1000_irq_disable(adapter);
532 570
533 del_timer_sync(&adapter->tx_fifo_stall_timer); 571 del_timer_sync(&adapter->tx_fifo_stall_timer);
@@ -563,6 +601,9 @@ void
563e1000_reset(struct e1000_adapter *adapter) 601e1000_reset(struct e1000_adapter *adapter)
564{ 602{
565 uint32_t pba, manc; 603 uint32_t pba, manc;
604#ifdef DISABLE_MULR
605 uint32_t tctl;
606#endif
566 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF; 607 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
567 608
568 /* Repartition Pba for greater than 9k mtu 609 /* Repartition Pba for greater than 9k mtu
@@ -629,6 +670,12 @@ e1000_reset(struct e1000_adapter *adapter)
629 e1000_reset_hw(&adapter->hw); 670 e1000_reset_hw(&adapter->hw);
630 if (adapter->hw.mac_type >= e1000_82544) 671 if (adapter->hw.mac_type >= e1000_82544)
631 E1000_WRITE_REG(&adapter->hw, WUC, 0); 672 E1000_WRITE_REG(&adapter->hw, WUC, 0);
673#ifdef DISABLE_MULR
674 /* disable Multiple Reads in Transmit Control Register for debugging */
675 tctl = E1000_READ_REG(hw, TCTL);
676 E1000_WRITE_REG(hw, TCTL, tctl & ~E1000_TCTL_MULR);
677
678#endif
632 if (e1000_init_hw(&adapter->hw)) 679 if (e1000_init_hw(&adapter->hw))
633 DPRINTK(PROBE, ERR, "Hardware Error\n"); 680 DPRINTK(PROBE, ERR, "Hardware Error\n");
634 e1000_update_mng_vlan(adapter); 681 e1000_update_mng_vlan(adapter);
@@ -652,9 +699,7 @@ e1000_reset(struct e1000_adapter *adapter)
652 phy_data); 699 phy_data);
653 } 700 }
654 701
655 if (adapter->hw.mac_type < e1000_ich8lan) 702 if ((adapter->en_mng_pt) && (adapter->hw.mac_type < e1000_82571)) {
656 /* FIXME: this code is duplicate and wrong for PCI Express */
657 if (adapter->en_mng_pt) {
658 manc = E1000_READ_REG(&adapter->hw, MANC); 703 manc = E1000_READ_REG(&adapter->hw, MANC);
659 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST); 704 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
660 E1000_WRITE_REG(&adapter->hw, MANC, manc); 705 E1000_WRITE_REG(&adapter->hw, MANC, manc);
@@ -760,7 +805,7 @@ e1000_probe(struct pci_dev *pdev,
760#ifdef CONFIG_NET_POLL_CONTROLLER 805#ifdef CONFIG_NET_POLL_CONTROLLER
761 netdev->poll_controller = e1000_netpoll; 806 netdev->poll_controller = e1000_netpoll;
762#endif 807#endif
763 strcpy(netdev->name, pci_name(pdev)); 808 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
764 809
765 netdev->mem_start = mmio_start; 810 netdev->mem_start = mmio_start;
766 netdev->mem_end = mmio_start + mmio_len; 811 netdev->mem_end = mmio_start + mmio_len;
@@ -863,11 +908,6 @@ e1000_probe(struct pci_dev *pdev,
863 INIT_WORK(&adapter->reset_task, 908 INIT_WORK(&adapter->reset_task,
864 (void (*)(void *))e1000_reset_task, netdev); 909 (void (*)(void *))e1000_reset_task, netdev);
865 910
866 /* we're going to reset, so assume we have no link for now */
867
868 netif_carrier_off(netdev);
869 netif_stop_queue(netdev);
870
871 e1000_check_options(adapter); 911 e1000_check_options(adapter);
872 912
873 /* Initial Wake on LAN setting 913 /* Initial Wake on LAN setting
@@ -974,6 +1014,10 @@ e1000_probe(struct pci_dev *pdev,
974 if ((err = register_netdev(netdev))) 1014 if ((err = register_netdev(netdev)))
975 goto err_register; 1015 goto err_register;
976 1016
1017 /* tell the stack to leave us alone until e1000_open() is called */
1018 netif_carrier_off(netdev);
1019 netif_stop_queue(netdev);
1020
977 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n"); 1021 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
978 1022
979 cards_found++; 1023 cards_found++;
@@ -1032,8 +1076,7 @@ e1000_remove(struct pci_dev *pdev)
1032 1076
1033 flush_scheduled_work(); 1077 flush_scheduled_work();
1034 1078
1035 if (adapter->hw.mac_type >= e1000_82540 && 1079 if (adapter->hw.mac_type < e1000_82571 &&
1036 adapter->hw.mac_type != e1000_ich8lan &&
1037 adapter->hw.media_type == e1000_media_type_copper) { 1080 adapter->hw.media_type == e1000_media_type_copper) {
1038 manc = E1000_READ_REG(&adapter->hw, MANC); 1081 manc = E1000_READ_REG(&adapter->hw, MANC);
1039 if (manc & E1000_MANC_SMBUS_EN) { 1082 if (manc & E1000_MANC_SMBUS_EN) {
@@ -1161,6 +1204,8 @@ e1000_sw_init(struct e1000_adapter *adapter)
1161 atomic_set(&adapter->irq_sem, 1); 1204 atomic_set(&adapter->irq_sem, 1);
1162 spin_lock_init(&adapter->stats_lock); 1205 spin_lock_init(&adapter->stats_lock);
1163 1206
1207 set_bit(__E1000_DOWN, &adapter->flags);
1208
1164 return 0; 1209 return 0;
1165} 1210}
1166 1211
@@ -1226,7 +1271,7 @@ e1000_open(struct net_device *netdev)
1226 int err; 1271 int err;
1227 1272
1228 /* disallow open during test */ 1273 /* disallow open during test */
1229 if (test_bit(__E1000_DRIVER_TESTING, &adapter->flags)) 1274 if (test_bit(__E1000_TESTING, &adapter->flags))
1230 return -EBUSY; 1275 return -EBUSY;
1231 1276
1232 /* allocate transmit descriptors */ 1277 /* allocate transmit descriptors */
@@ -1299,8 +1344,12 @@ e1000_close(struct net_device *netdev)
1299 e1000_free_all_tx_resources(adapter); 1344 e1000_free_all_tx_resources(adapter);
1300 e1000_free_all_rx_resources(adapter); 1345 e1000_free_all_rx_resources(adapter);
1301 1346
1347 /* kill manageability vlan ID if supported, but not if a vlan with
1348 * the same ID is registered on the host OS (let 8021q kill it) */
1302 if ((adapter->hw.mng_cookie.status & 1349 if ((adapter->hw.mng_cookie.status &
1303 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) { 1350 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1351 !(adapter->vlgrp &&
1352 adapter->vlgrp->vlan_devices[adapter->mng_vlan_id])) {
1304 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); 1353 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1305 } 1354 }
1306 1355
@@ -1510,27 +1559,14 @@ e1000_configure_tx(struct e1000_adapter *adapter)
1510 /* Program the Transmit Control Register */ 1559 /* Program the Transmit Control Register */
1511 1560
1512 tctl = E1000_READ_REG(hw, TCTL); 1561 tctl = E1000_READ_REG(hw, TCTL);
1513
1514 tctl &= ~E1000_TCTL_CT; 1562 tctl &= ~E1000_TCTL_CT;
1515 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | 1563 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1516 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); 1564 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1517 1565
1518#ifdef DISABLE_MULR
1519 /* disable Multiple Reads for debugging */
1520 tctl &= ~E1000_TCTL_MULR;
1521#endif
1522
1523 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) { 1566 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1524 tarc = E1000_READ_REG(hw, TARC0); 1567 tarc = E1000_READ_REG(hw, TARC0);
1525 tarc |= ((1 << 25) | (1 << 21)); 1568 tarc |= (1 << 21);
1526 E1000_WRITE_REG(hw, TARC0, tarc); 1569 E1000_WRITE_REG(hw, TARC0, tarc);
1527 tarc = E1000_READ_REG(hw, TARC1);
1528 tarc |= (1 << 25);
1529 if (tctl & E1000_TCTL_MULR)
1530 tarc &= ~(1 << 28);
1531 else
1532 tarc |= (1 << 28);
1533 E1000_WRITE_REG(hw, TARC1, tarc);
1534 } else if (hw->mac_type == e1000_80003es2lan) { 1570 } else if (hw->mac_type == e1000_80003es2lan) {
1535 tarc = E1000_READ_REG(hw, TARC0); 1571 tarc = E1000_READ_REG(hw, TARC0);
1536 tarc |= 1; 1572 tarc |= 1;
@@ -2892,6 +2928,35 @@ e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2892 return 0; 2928 return 0;
2893} 2929}
2894 2930
2931static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
2932{
2933 struct e1000_adapter *adapter = netdev_priv(netdev);
2934 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
2935
2936 netif_stop_queue(netdev);
2937 /* Herbert's original patch had:
2938 * smp_mb__after_netif_stop_queue();
2939 * but since that doesn't exist yet, just open code it. */
2940 smp_mb();
2941
2942 /* We need to check again in a case another CPU has just
2943 * made room available. */
2944 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
2945 return -EBUSY;
2946
2947 /* A reprieve! */
2948 netif_start_queue(netdev);
2949 return 0;
2950}
2951
2952static int e1000_maybe_stop_tx(struct net_device *netdev,
2953 struct e1000_tx_ring *tx_ring, int size)
2954{
2955 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
2956 return 0;
2957 return __e1000_maybe_stop_tx(netdev, size);
2958}
2959
2895#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) 2960#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2896static int 2961static int
2897e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev) 2962e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
@@ -2910,6 +2975,10 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2910 unsigned int f; 2975 unsigned int f;
2911 len -= skb->data_len; 2976 len -= skb->data_len;
2912 2977
2978 /* This goes back to the question of how to logically map a tx queue
2979 * to a flow. Right now, performance is impacted slightly negatively
2980 * if using multiple tx queues. If the stack breaks away from a
2981 * single qdisc implementation, we can look at this again. */
2913 tx_ring = adapter->tx_ring; 2982 tx_ring = adapter->tx_ring;
2914 2983
2915 if (unlikely(skb->len <= 0)) { 2984 if (unlikely(skb->len <= 0)) {
@@ -3005,8 +3074,7 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3005 3074
3006 /* need: count + 2 desc gap to keep tail from touching 3075 /* need: count + 2 desc gap to keep tail from touching
3007 * head, otherwise try next time */ 3076 * head, otherwise try next time */
3008 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) { 3077 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
3009 netif_stop_queue(netdev);
3010 spin_unlock_irqrestore(&tx_ring->tx_lock, flags); 3078 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3011 return NETDEV_TX_BUSY; 3079 return NETDEV_TX_BUSY;
3012 } 3080 }
@@ -3014,7 +3082,7 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3014 if (unlikely(adapter->hw.mac_type == e1000_82547)) { 3082 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
3015 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) { 3083 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
3016 netif_stop_queue(netdev); 3084 netif_stop_queue(netdev);
3017 mod_timer(&adapter->tx_fifo_stall_timer, jiffies); 3085 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
3018 spin_unlock_irqrestore(&tx_ring->tx_lock, flags); 3086 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3019 return NETDEV_TX_BUSY; 3087 return NETDEV_TX_BUSY;
3020 } 3088 }
@@ -3053,8 +3121,7 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3053 netdev->trans_start = jiffies; 3121 netdev->trans_start = jiffies;
3054 3122
3055 /* Make sure there is space in the ring for the next send. */ 3123 /* Make sure there is space in the ring for the next send. */
3056 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2)) 3124 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
3057 netif_stop_queue(netdev);
3058 3125
3059 spin_unlock_irqrestore(&tx_ring->tx_lock, flags); 3126 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3060 return NETDEV_TX_OK; 3127 return NETDEV_TX_OK;
@@ -3131,11 +3198,13 @@ e1000_change_mtu(struct net_device *netdev, int new_mtu)
3131 } 3198 }
3132 break; 3199 break;
3133 case e1000_82573: 3200 case e1000_82573:
3134 /* only enable jumbo frames if ASPM is disabled completely 3201 /* Jumbo Frames not supported if:
3135 * this means both bits must be zero in 0x1A bits 3:2 */ 3202 * - this is not an 82573L device
3203 * - ASPM is enabled in any way (0x1A bits 3:2) */
3136 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1, 3204 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3137 &eeprom_data); 3205 &eeprom_data);
3138 if (eeprom_data & EEPROM_WORD1A_ASPM_MASK) { 3206 if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
3207 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
3139 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { 3208 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3140 DPRINTK(PROBE, ERR, 3209 DPRINTK(PROBE, ERR,
3141 "Jumbo Frames not supported.\n"); 3210 "Jumbo Frames not supported.\n");
@@ -3143,6 +3212,8 @@ e1000_change_mtu(struct net_device *netdev, int new_mtu)
3143 } 3212 }
3144 break; 3213 break;
3145 } 3214 }
3215 /* ERT will be enabled later to enable wire speed receives */
3216
3146 /* fall through to get support */ 3217 /* fall through to get support */
3147 case e1000_82571: 3218 case e1000_82571:
3148 case e1000_82572: 3219 case e1000_82572:
@@ -3328,16 +3399,15 @@ e1000_update_stats(struct e1000_adapter *adapter)
3328 adapter->stats.crcerrs + adapter->stats.algnerrc + 3399 adapter->stats.crcerrs + adapter->stats.algnerrc +
3329 adapter->stats.ruc + adapter->stats.roc + 3400 adapter->stats.ruc + adapter->stats.roc +
3330 adapter->stats.cexterr; 3401 adapter->stats.cexterr;
3331 adapter->net_stats.rx_length_errors = adapter->stats.ruc + 3402 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3332 adapter->stats.roc; 3403 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
3333 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; 3404 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3334 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc; 3405 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3335 adapter->net_stats.rx_missed_errors = adapter->stats.mpc; 3406 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3336 3407
3337 /* Tx Errors */ 3408 /* Tx Errors */
3338 3409 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3339 adapter->net_stats.tx_errors = adapter->stats.ecol + 3410 adapter->net_stats.tx_errors = adapter->stats.txerrc;
3340 adapter->stats.latecol;
3341 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol; 3411 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3342 adapter->net_stats.tx_window_errors = adapter->stats.latecol; 3412 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3343 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs; 3413 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
@@ -3408,7 +3478,9 @@ e1000_intr(int irq, void *data, struct pt_regs *regs)
3408 rctl = E1000_READ_REG(hw, RCTL); 3478 rctl = E1000_READ_REG(hw, RCTL);
3409 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); 3479 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3410 } 3480 }
3411 mod_timer(&adapter->watchdog_timer, jiffies); 3481 /* guard against interrupt when we're going down */
3482 if (!test_bit(__E1000_DOWN, &adapter->flags))
3483 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3412 } 3484 }
3413 3485
3414#ifdef CONFIG_E1000_NAPI 3486#ifdef CONFIG_E1000_NAPI
@@ -3546,13 +3618,14 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter,
3546 tx_ring->next_to_clean = i; 3618 tx_ring->next_to_clean = i;
3547 3619
3548#define TX_WAKE_THRESHOLD 32 3620#define TX_WAKE_THRESHOLD 32
3549 if (unlikely(cleaned && netif_queue_stopped(netdev) && 3621 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
3550 netif_carrier_ok(netdev))) { 3622 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3551 spin_lock(&tx_ring->tx_lock); 3623 /* Make sure that anybody stopping the queue after this
3552 if (netif_queue_stopped(netdev) && 3624 * sees the new next_to_clean.
3553 (E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) 3625 */
3626 smp_mb();
3627 if (netif_queue_stopped(netdev))
3554 netif_wake_queue(netdev); 3628 netif_wake_queue(netdev);
3555 spin_unlock(&tx_ring->tx_lock);
3556 } 3629 }
3557 3630
3558 if (adapter->detect_tx_hung) { 3631 if (adapter->detect_tx_hung) {
@@ -4412,13 +4485,21 @@ e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4412 pci_write_config_word(adapter->pdev, reg, *value); 4485 pci_write_config_word(adapter->pdev, reg, *value);
4413} 4486}
4414 4487
4415#if 0 4488int32_t
4416uint32_t 4489e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4417e1000_io_read(struct e1000_hw *hw, unsigned long port)
4418{ 4490{
4419 return inl(port); 4491 struct e1000_adapter *adapter = hw->back;
4492 uint16_t cap_offset;
4493
4494 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4495 if (!cap_offset)
4496 return -E1000_ERR_CONFIG;
4497
4498 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4499
4500 return E1000_SUCCESS;
4420} 4501}
4421#endif /* 0 */ 4502
4422 4503
4423void 4504void
4424e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value) 4505e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
@@ -4693,9 +4774,7 @@ e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4693 pci_enable_wake(pdev, PCI_D3cold, 0); 4774 pci_enable_wake(pdev, PCI_D3cold, 0);
4694 } 4775 }
4695 4776
4696 /* FIXME: this code is incorrect for PCI Express */ 4777 if (adapter->hw.mac_type < e1000_82571 &&
4697 if (adapter->hw.mac_type >= e1000_82540 &&
4698 adapter->hw.mac_type != e1000_ich8lan &&
4699 adapter->hw.media_type == e1000_media_type_copper) { 4778 adapter->hw.media_type == e1000_media_type_copper) {
4700 manc = E1000_READ_REG(&adapter->hw, MANC); 4779 manc = E1000_READ_REG(&adapter->hw, MANC);
4701 if (manc & E1000_MANC_SMBUS_EN) { 4780 if (manc & E1000_MANC_SMBUS_EN) {
@@ -4747,9 +4826,7 @@ e1000_resume(struct pci_dev *pdev)
4747 4826
4748 netif_device_attach(netdev); 4827 netif_device_attach(netdev);
4749 4828
4750 /* FIXME: this code is incorrect for PCI Express */ 4829 if (adapter->hw.mac_type < e1000_82571 &&
4751 if (adapter->hw.mac_type >= e1000_82540 &&
4752 adapter->hw.mac_type != e1000_ich8lan &&
4753 adapter->hw.media_type == e1000_media_type_copper) { 4830 adapter->hw.media_type == e1000_media_type_copper) {
4754 manc = E1000_READ_REG(&adapter->hw, MANC); 4831 manc = E1000_READ_REG(&adapter->hw, MANC);
4755 manc &= ~(E1000_MANC_ARP_EN); 4832 manc &= ~(E1000_MANC_ARP_EN);
@@ -4835,8 +4912,8 @@ static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4835 } 4912 }
4836 pci_set_master(pdev); 4913 pci_set_master(pdev);
4837 4914
4838 pci_enable_wake(pdev, 3, 0); 4915 pci_enable_wake(pdev, PCI_D3hot, 0);
4839 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */ 4916 pci_enable_wake(pdev, PCI_D3cold, 0);
4840 4917
4841 /* Perform card reset only on one instance of the card */ 4918 /* Perform card reset only on one instance of the card */
4842 if (PCI_FUNC (pdev->devfn) != 0) 4919 if (PCI_FUNC (pdev->devfn) != 0)
diff --git a/drivers/net/e1000/e1000_osdep.h b/drivers/net/e1000/e1000_osdep.h
index 46bc49df15e7..a464cb290621 100644
--- a/drivers/net/e1000/e1000_osdep.h
+++ b/drivers/net/e1000/e1000_osdep.h
@@ -1,25 +1,24 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version. 9
10 10 This program is distributed in the hope it will be useful, but WITHOUT
11 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
25 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> 24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
diff --git a/drivers/net/e1000/e1000_param.c b/drivers/net/e1000/e1000_param.c
index 212842738972..9c3c1acefccc 100644
--- a/drivers/net/e1000/e1000_param.c
+++ b/drivers/net/e1000/e1000_param.c
@@ -1,25 +1,24 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version. 9
10 10 This program is distributed in the hope it will be useful, but WITHOUT
11 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
25 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> 24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
@@ -397,17 +396,17 @@ e1000_check_options(struct e1000_adapter *adapter)
397 { /* Flow Control */ 396 { /* Flow Control */
398 397
399 struct e1000_opt_list fc_list[] = 398 struct e1000_opt_list fc_list[] =
400 {{ e1000_fc_none, "Flow Control Disabled" }, 399 {{ E1000_FC_NONE, "Flow Control Disabled" },
401 { e1000_fc_rx_pause,"Flow Control Receive Only" }, 400 { E1000_FC_RX_PAUSE,"Flow Control Receive Only" },
402 { e1000_fc_tx_pause,"Flow Control Transmit Only" }, 401 { E1000_FC_TX_PAUSE,"Flow Control Transmit Only" },
403 { e1000_fc_full, "Flow Control Enabled" }, 402 { E1000_FC_FULL, "Flow Control Enabled" },
404 { e1000_fc_default, "Flow Control Hardware Default" }}; 403 { E1000_FC_DEFAULT, "Flow Control Hardware Default" }};
405 404
406 struct e1000_option opt = { 405 struct e1000_option opt = {
407 .type = list_option, 406 .type = list_option,
408 .name = "Flow Control", 407 .name = "Flow Control",
409 .err = "reading default settings from EEPROM", 408 .err = "reading default settings from EEPROM",
410 .def = e1000_fc_default, 409 .def = E1000_FC_DEFAULT,
411 .arg = { .l = { .nr = ARRAY_SIZE(fc_list), 410 .arg = { .l = { .nr = ARRAY_SIZE(fc_list),
412 .p = fc_list }} 411 .p = fc_list }}
413 }; 412 };
diff --git a/drivers/net/fec_8xx/fec_main.c b/drivers/net/fec_8xx/fec_main.c
index 22ac2df1aeb0..e17a1449ee10 100644
--- a/drivers/net/fec_8xx/fec_main.c
+++ b/drivers/net/fec_8xx/fec_main.c
@@ -30,6 +30,7 @@
30#include <linux/mii.h> 30#include <linux/mii.h>
31#include <linux/ethtool.h> 31#include <linux/ethtool.h>
32#include <linux/bitops.h> 32#include <linux/bitops.h>
33#include <linux/dma-mapping.h>
33 34
34#include <asm/8xx_immap.h> 35#include <asm/8xx_immap.h>
35#include <asm/pgtable.h> 36#include <asm/pgtable.h>
@@ -37,7 +38,6 @@
37#include <asm/irq.h> 38#include <asm/irq.h>
38#include <asm/uaccess.h> 39#include <asm/uaccess.h>
39#include <asm/commproc.h> 40#include <asm/commproc.h>
40#include <asm/dma-mapping.h>
41 41
42#include "fec_8xx.h" 42#include "fec_8xx.h"
43 43
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c
index 97db910fbc8c..eea1d66c530e 100644
--- a/drivers/net/forcedeth.c
+++ b/drivers/net/forcedeth.c
@@ -3789,6 +3789,12 @@ static int nv_loopback_test(struct net_device *dev)
3789 /* setup packet for tx */ 3789 /* setup packet for tx */
3790 pkt_len = ETH_DATA_LEN; 3790 pkt_len = ETH_DATA_LEN;
3791 tx_skb = dev_alloc_skb(pkt_len); 3791 tx_skb = dev_alloc_skb(pkt_len);
3792 if (!tx_skb) {
3793 printk(KERN_ERR "dev_alloc_skb() failed during loopback test"
3794 " of %s\n", dev->name);
3795 ret = 0;
3796 goto out;
3797 }
3792 pkt_data = skb_put(tx_skb, pkt_len); 3798 pkt_data = skb_put(tx_skb, pkt_len);
3793 for (i = 0; i < pkt_len; i++) 3799 for (i = 0; i < pkt_len; i++)
3794 pkt_data[i] = (u8)(i & 0xff); 3800 pkt_data[i] = (u8)(i & 0xff);
@@ -3853,7 +3859,7 @@ static int nv_loopback_test(struct net_device *dev)
3853 tx_skb->end-tx_skb->data, 3859 tx_skb->end-tx_skb->data,
3854 PCI_DMA_TODEVICE); 3860 PCI_DMA_TODEVICE);
3855 dev_kfree_skb_any(tx_skb); 3861 dev_kfree_skb_any(tx_skb);
3856 3862 out:
3857 /* stop engines */ 3863 /* stop engines */
3858 nv_stop_rx(dev); 3864 nv_stop_rx(dev);
3859 nv_stop_tx(dev); 3865 nv_stop_tx(dev);
diff --git a/drivers/net/fs_enet/fs_enet.h b/drivers/net/fs_enet/fs_enet.h
index 95022c005f75..92590d8fc24b 100644
--- a/drivers/net/fs_enet/fs_enet.h
+++ b/drivers/net/fs_enet/fs_enet.h
@@ -6,11 +6,10 @@
6#include <linux/types.h> 6#include <linux/types.h>
7#include <linux/list.h> 7#include <linux/list.h>
8#include <linux/phy.h> 8#include <linux/phy.h>
9#include <linux/dma-mapping.h>
9 10
10#include <linux/fs_enet_pd.h> 11#include <linux/fs_enet_pd.h>
11 12
12#include <asm/dma-mapping.h>
13
14#ifdef CONFIG_CPM1 13#ifdef CONFIG_CPM1
15#include <asm/commproc.h> 14#include <asm/commproc.h>
16 15
diff --git a/drivers/net/gt64240eth.h b/drivers/net/gt64240eth.h
deleted file mode 100644
index 0d6f486e4579..000000000000
--- a/drivers/net/gt64240eth.h
+++ /dev/null
@@ -1,402 +0,0 @@
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) 2001 Patton Electronics Company
7 * Copyright (C) 2002 Momentum Computer
8 *
9 * Copyright 2000 MontaVista Software Inc.
10 * Author: MontaVista Software, Inc.
11 * stevel@mvista.com or support@mvista.com
12 *
13 * This program is free software; you can distribute it and/or modify it
14 * under the terms of the GNU General Public License (Version 2) as
15 * published by the Free Software Foundation.
16 *
17 * This program is distributed in the hope it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
25 *
26 * Ethernet driver definitions for the MIPS GT96100 Advanced
27 * Communication Controller.
28 *
29 * Modified for the Marvellous GT64240 Retarded Communication Controller.
30 */
31#ifndef _GT64240ETH_H
32#define _GT64240ETH_H
33
34#include <asm/gt64240.h>
35
36#define ETHERNET_PORTS_DIFFERENCE_OFFSETS 0x400
37
38/* Translate those weanie names from Galileo/VxWorks header files: */
39
40#define GT64240_MRR MAIN_ROUTING_REGISTER
41#define GT64240_CIU_ARBITER_CONFIG COMM_UNIT_ARBITER_CONFIGURATION_REGISTER
42#define GT64240_CIU_ARBITER_CONTROL COMM_UNIT_ARBITER_CONTROL
43#define GT64240_MAIN_LOW_CAUSE LOW_INTERRUPT_CAUSE_REGISTER
44#define GT64240_MAIN_HIGH_CAUSE HIGH_INTERRUPT_CAUSE_REGISTER
45#define GT64240_CPU_LOW_MASK CPU_INTERRUPT_MASK_REGISTER_LOW
46#define GT64240_CPU_HIGH_MASK CPU_INTERRUPT_MASK_REGISTER_HIGH
47#define GT64240_CPU_SELECT_CAUSE CPU_SELECT_CAUSE_REGISTER
48
49#define GT64240_ETH_PHY_ADDR_REG ETHERNET_PHY_ADDRESS_REGISTER
50#define GT64240_ETH_PORT_CONFIG ETHERNET0_PORT_CONFIGURATION_REGISTER
51#define GT64240_ETH_PORT_CONFIG_EXT ETHERNET0_PORT_CONFIGURATION_EXTEND_REGISTER
52#define GT64240_ETH_PORT_COMMAND ETHERNET0_PORT_COMMAND_REGISTER
53#define GT64240_ETH_PORT_STATUS ETHERNET0_PORT_STATUS_REGISTER
54#define GT64240_ETH_IO_SIZE ETHERNET_PORTS_DIFFERENCE_OFFSETS
55#define GT64240_ETH_SMI_REG ETHERNET_SMI_REGISTER
56#define GT64240_ETH_MIB_COUNT_BASE ETHERNET0_MIB_COUNTER_BASE
57#define GT64240_ETH_SDMA_CONFIG ETHERNET0_SDMA_CONFIGURATION_REGISTER
58#define GT64240_ETH_SDMA_COMM ETHERNET0_SDMA_COMMAND_REGISTER
59#define GT64240_ETH_INT_MASK ETHERNET0_INTERRUPT_MASK_REGISTER
60#define GT64240_ETH_INT_CAUSE ETHERNET0_INTERRUPT_CAUSE_REGISTER
61#define GT64240_ETH_CURR_TX_DESC_PTR0 ETHERNET0_CURRENT_TX_DESCRIPTOR_POINTER0
62#define GT64240_ETH_CURR_TX_DESC_PTR1 ETHERNET0_CURRENT_TX_DESCRIPTOR_POINTER1
63#define GT64240_ETH_1ST_RX_DESC_PTR0 ETHERNET0_FIRST_RX_DESCRIPTOR_POINTER0
64#define GT64240_ETH_CURR_RX_DESC_PTR0 ETHERNET0_CURRENT_RX_DESCRIPTOR_POINTER0
65#define GT64240_ETH_HASH_TBL_PTR ETHERNET0_HASH_TABLE_POINTER_REGISTER
66
67/* Turn on NAPI by default */
68
69#define GT64240_NAPI 1
70
71/* Some 64240 settings that SHOULD eventually be setup in PROM monitor: */
72/* (Board-specific to the DSL3224 Rev A board ONLY!) */
73#define D3224_MPP_CTRL0_SETTING 0x66669900
74#define D3224_MPP_CTRL1_SETTING 0x00000000
75#define D3224_MPP_CTRL2_SETTING 0x00887700
76#define D3224_MPP_CTRL3_SETTING 0x00000044
77#define D3224_GPP_IO_CTRL_SETTING 0x0000e800
78#define D3224_GPP_LEVEL_CTRL_SETTING 0xf001f703
79#define D3224_GPP_VALUE_SETTING 0x00000000
80
81/* Keep the ring sizes a power of two for efficiency. */
82//-#define TX_RING_SIZE 16
83#define TX_RING_SIZE 64 /* TESTING !!! */
84#define RX_RING_SIZE 32
85#define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer. */
86
87#define RX_HASH_TABLE_SIZE 16384
88#define HASH_HOP_NUMBER 12
89
90#define NUM_INTERFACES 3
91
92#define GT64240ETH_TX_TIMEOUT HZ/4
93
94#define MIPS_GT64240_BASE 0xf4000000
95#define GT64240_ETH0_BASE (MIPS_GT64240_BASE + GT64240_ETH_PORT_CONFIG)
96#define GT64240_ETH1_BASE (GT64240_ETH0_BASE + GT64240_ETH_IO_SIZE)
97#define GT64240_ETH2_BASE (GT64240_ETH1_BASE + GT64240_ETH_IO_SIZE)
98
99#if defined(CONFIG_MIPS_DSL3224)
100#define GT64240_ETHER0_IRQ 4
101#define GT64240_ETHER1_IRQ 4
102#else
103#define GT64240_ETHER0_IRQ -1
104#define GT64240_ETHER1_IRQ -1
105#endif
106
107#define REV_GT64240 0x1
108#define REV_GT64240A 0x10
109
110#define GT64240ETH_READ(gp, offset) \
111 GT_READ((gp)->port_offset + (offset))
112
113#define GT64240ETH_WRITE(gp, offset, data) \
114 GT_WRITE((gp)->port_offset + (offset), (data))
115
116#define GT64240ETH_SETBIT(gp, offset, bits) \
117 GT64240ETH_WRITE((gp), (offset), \
118 GT64240ETH_READ((gp), (offset)) | (bits))
119
120#define GT64240ETH_CLRBIT(gp, offset, bits) \
121 GT64240ETH_WRITE((gp), (offset), \
122 GT64240ETH_READ((gp), (offset)) & ~(bits))
123
124#define GT64240_READ(ofs) GT_READ(ofs)
125#define GT64240_WRITE(ofs, data) GT_WRITE((ofs), (data))
126
127/* Bit definitions of the SMI Reg */
128enum {
129 smirDataMask = 0xffff,
130 smirPhyAdMask = 0x1f << 16,
131 smirPhyAdBit = 16,
132 smirRegAdMask = 0x1f << 21,
133 smirRegAdBit = 21,
134 smirOpCode = 1 << 26,
135 smirReadValid = 1 << 27,
136 smirBusy = 1 << 28
137};
138
139/* Bit definitions of the Port Config Reg */
140enum pcr_bits {
141 pcrPM = 1 << 0,
142 pcrRBM = 1 << 1,
143 pcrPBF = 1 << 2,
144 pcrEN = 1 << 7,
145 pcrLPBKMask = 0x3 << 8,
146 pcrLPBKBit = 1 << 8,
147 pcrFC = 1 << 10,
148 pcrHS = 1 << 12,
149 pcrHM = 1 << 13,
150 pcrHDM = 1 << 14,
151 pcrHD = 1 << 15,
152 pcrISLMask = 0x7 << 28,
153 pcrISLBit = 28,
154 pcrACCS = 1 << 31
155};
156
157/* Bit definitions of the Port Config Extend Reg */
158enum pcxr_bits {
159 pcxrIGMP = 1,
160 pcxrSPAN = 2,
161 pcxrPAR = 4,
162 pcxrPRIOtxMask = 0x7 << 3,
163 pcxrPRIOtxBit = 3,
164 pcxrPRIOrxMask = 0x3 << 6,
165 pcxrPRIOrxBit = 6,
166 pcxrPRIOrxOverride = 1 << 8,
167 pcxrDPLXen = 1 << 9,
168 pcxrFCTLen = 1 << 10,
169 pcxrFLP = 1 << 11,
170 pcxrFCTL = 1 << 12,
171 pcxrMFLMask = 0x3 << 14,
172 pcxrMFLBit = 14,
173 pcxrMIBclrMode = 1 << 16,
174 pcxrSpeed = 1 << 18,
175 pcxrSpeeden = 1 << 19,
176 pcxrRMIIen = 1 << 20,
177 pcxrDSCPen = 1 << 21
178};
179
180/* Bit definitions of the Port Command Reg */
181enum pcmr_bits {
182 pcmrFJ = 1 << 15
183};
184
185
186/* Bit definitions of the Port Status Reg */
187enum psr_bits {
188 psrSpeed = 1,
189 psrDuplex = 2,
190 psrFctl = 4,
191 psrLink = 8,
192 psrPause = 1 << 4,
193 psrTxLow = 1 << 5,
194 psrTxHigh = 1 << 6,
195 psrTxInProg = 1 << 7
196};
197
198/* Bit definitions of the SDMA Config Reg */
199enum sdcr_bits {
200 sdcrRCMask = 0xf << 2,
201 sdcrRCBit = 2,
202 sdcrBLMR = 1 << 6,
203 sdcrBLMT = 1 << 7,
204 sdcrPOVR = 1 << 8,
205 sdcrRIFB = 1 << 9,
206 sdcrBSZMask = 0x3 << 12,
207 sdcrBSZBit = 12
208};
209
210/* Bit definitions of the SDMA Command Reg */
211enum sdcmr_bits {
212 sdcmrERD = 1 << 7,
213 sdcmrAR = 1 << 15,
214 sdcmrSTDH = 1 << 16,
215 sdcmrSTDL = 1 << 17,
216 sdcmrTXDH = 1 << 23,
217 sdcmrTXDL = 1 << 24,
218 sdcmrAT = 1 << 31
219};
220
221/* Bit definitions of the Interrupt Cause Reg */
222enum icr_bits {
223 icrRxBuffer = 1,
224 icrTxBufferHigh = 1 << 2,
225 icrTxBufferLow = 1 << 3,
226 icrTxEndHigh = 1 << 6,
227 icrTxEndLow = 1 << 7,
228 icrRxError = 1 << 8,
229 icrTxErrorHigh = 1 << 10,
230 icrTxErrorLow = 1 << 11,
231 icrRxOVR = 1 << 12,
232 icrTxUdr = 1 << 13,
233 icrRxBufferQ0 = 1 << 16,
234 icrRxBufferQ1 = 1 << 17,
235 icrRxBufferQ2 = 1 << 18,
236 icrRxBufferQ3 = 1 << 19,
237 icrRxErrorQ0 = 1 << 20,
238 icrRxErrorQ1 = 1 << 21,
239 icrRxErrorQ2 = 1 << 22,
240 icrRxErrorQ3 = 1 << 23,
241 icrMIIPhySTC = 1 << 28,
242 icrSMIdone = 1 << 29,
243 icrEtherIntSum = 1 << 31
244};
245
246
247/* The Rx and Tx descriptor lists. */
248#ifdef __LITTLE_ENDIAN
249typedef struct {
250 u32 cmdstat;
251 u16 reserved; //-prk21aug01 u32 reserved:16;
252 u16 byte_cnt; //-prk21aug01 u32 byte_cnt:16;
253 u32 buff_ptr;
254 u32 next;
255} gt64240_td_t;
256
257typedef struct {
258 u32 cmdstat;
259 u16 byte_cnt; //-prk21aug01 u32 byte_cnt:16;
260 u16 buff_sz; //-prk21aug01 u32 buff_sz:16;
261 u32 buff_ptr;
262 u32 next;
263} gt64240_rd_t;
264#elif defined(__BIG_ENDIAN)
265typedef struct {
266 u16 byte_cnt; //-prk21aug01 u32 byte_cnt:16;
267 u16 reserved; //-prk21aug01 u32 reserved:16;
268 u32 cmdstat;
269 u32 next;
270 u32 buff_ptr;
271} gt64240_td_t;
272
273typedef struct {
274 u16 buff_sz; //-prk21aug01 u32 buff_sz:16;
275 u16 byte_cnt; //-prk21aug01 u32 byte_cnt:16;
276 u32 cmdstat;
277 u32 next;
278 u32 buff_ptr;
279} gt64240_rd_t;
280#else
281#error Either __BIG_ENDIAN or __LITTLE_ENDIAN must be defined!
282#endif
283
284
285/* Values for the Tx command-status descriptor entry. */
286enum td_cmdstat {
287 txOwn = 1 << 31,
288 txAutoMode = 1 << 30,
289 txEI = 1 << 23,
290 txGenCRC = 1 << 22,
291 txPad = 1 << 18,
292 txFirst = 1 << 17,
293 txLast = 1 << 16,
294 txErrorSummary = 1 << 15,
295 txReTxCntMask = 0x0f << 10,
296 txReTxCntBit = 10,
297 txCollision = 1 << 9,
298 txReTxLimit = 1 << 8,
299 txUnderrun = 1 << 6,
300 txLateCollision = 1 << 5
301};
302
303
304/* Values for the Rx command-status descriptor entry. */
305enum rd_cmdstat {
306 rxOwn = 1 << 31,
307 rxAutoMode = 1 << 30,
308 rxEI = 1 << 23,
309 rxFirst = 1 << 17,
310 rxLast = 1 << 16,
311 rxErrorSummary = 1 << 15,
312 rxIGMP = 1 << 14,
313 rxHashExpired = 1 << 13,
314 rxMissedFrame = 1 << 12,
315 rxFrameType = 1 << 11,
316 rxShortFrame = 1 << 8,
317 rxMaxFrameLen = 1 << 7,
318 rxOverrun = 1 << 6,
319 rxCollision = 1 << 4,
320 rxCRCError = 1
321};
322
323/* Bit fields of a Hash Table Entry */
324enum hash_table_entry {
325 hteValid = 1,
326 hteSkip = 2,
327 hteRD = 4
328};
329
330// The MIB counters
331typedef struct {
332 u32 byteReceived;
333 u32 byteSent;
334 u32 framesReceived;
335 u32 framesSent;
336 u32 totalByteReceived;
337 u32 totalFramesReceived;
338 u32 broadcastFramesReceived;
339 u32 multicastFramesReceived;
340 u32 cRCError;
341 u32 oversizeFrames;
342 u32 fragments;
343 u32 jabber;
344 u32 collision;
345 u32 lateCollision;
346 u32 frames64;
347 u32 frames65_127;
348 u32 frames128_255;
349 u32 frames256_511;
350 u32 frames512_1023;
351 u32 frames1024_MaxSize;
352 u32 macRxError;
353 u32 droppedFrames;
354 u32 outMulticastFrames;
355 u32 outBroadcastFrames;
356 u32 undersizeFrames;
357} mib_counters_t;
358
359
360struct gt64240_private {
361 gt64240_rd_t *rx_ring;
362 gt64240_td_t *tx_ring;
363 // The Rx and Tx rings must be 16-byte aligned
364 dma_addr_t rx_ring_dma;
365 dma_addr_t tx_ring_dma;
366 char *hash_table;
367 // The Hash Table must be 8-byte aligned
368 dma_addr_t hash_table_dma;
369 int hash_mode;
370
371 // The Rx buffers must be 8-byte aligned
372 char *rx_buff;
373 dma_addr_t rx_buff_dma;
374 // Tx buffers (tx_skbuff[i]->data) with less than 8 bytes
375 // of payload must be 8-byte aligned
376 struct sk_buff *tx_skbuff[TX_RING_SIZE];
377 int rx_next_out; /* The next free ring entry to receive */
378 int tx_next_in; /* The next free ring entry to send */
379 int tx_next_out; /* The last ring entry the ISR processed */
380 int tx_count; /* current # of pkts waiting to be sent in Tx ring */
381 int intr_work_done; /* number of Rx and Tx pkts processed in the isr */
382 int tx_full; /* Tx ring is full */
383
384 mib_counters_t mib;
385 struct net_device_stats stats;
386
387 int io_size;
388 int port_num; // 0 or 1
389 u32 port_offset;
390
391 int phy_addr; // PHY address
392 u32 last_psr; // last value of the port status register
393
394 int options; /* User-settable misc. driver options. */
395 int drv_flags;
396 spinlock_t lock; /* Serialise access to device */
397 struct mii_if_info mii_if;
398
399 u32 msg_enable;
400};
401
402#endif /* _GT64240ETH_H */
diff --git a/drivers/net/hp100.c b/drivers/net/hp100.c
index 03b3df33d81b..ae8ad4f763bf 100644
--- a/drivers/net/hp100.c
+++ b/drivers/net/hp100.c
@@ -188,10 +188,12 @@ struct hp100_private {
188/* 188/*
189 * variables 189 * variables
190 */ 190 */
191#ifdef CONFIG_ISA
191static const char *hp100_isa_tbl[] = { 192static const char *hp100_isa_tbl[] = {
192 "HWPF150", /* HP J2573 rev A */ 193 "HWPF150", /* HP J2573 rev A */
193 "HWP1950", /* HP J2573 */ 194 "HWP1950", /* HP J2573 */
194}; 195};
196#endif
195 197
196#ifdef CONFIG_EISA 198#ifdef CONFIG_EISA
197static struct eisa_device_id hp100_eisa_tbl[] = { 199static struct eisa_device_id hp100_eisa_tbl[] = {
@@ -333,6 +335,7 @@ static __devinit const char *hp100_read_id(int ioaddr)
333 return str; 335 return str;
334} 336}
335 337
338#ifdef CONFIG_ISA
336static __init int hp100_isa_probe1(struct net_device *dev, int ioaddr) 339static __init int hp100_isa_probe1(struct net_device *dev, int ioaddr)
337{ 340{
338 const char *sig; 341 const char *sig;
@@ -390,9 +393,9 @@ static int __init hp100_isa_probe(struct net_device *dev, int addr)
390 } 393 }
391 return err; 394 return err;
392} 395}
396#endif /* CONFIG_ISA */
393 397
394 398#if !defined(MODULE) && defined(CONFIG_ISA)
395#ifndef MODULE
396struct net_device * __init hp100_probe(int unit) 399struct net_device * __init hp100_probe(int unit)
397{ 400{
398 struct net_device *dev = alloc_etherdev(sizeof(struct hp100_private)); 401 struct net_device *dev = alloc_etherdev(sizeof(struct hp100_private));
@@ -422,7 +425,7 @@ struct net_device * __init hp100_probe(int unit)
422 free_netdev(dev); 425 free_netdev(dev);
423 return ERR_PTR(err); 426 return ERR_PTR(err);
424} 427}
425#endif 428#endif /* !MODULE && CONFIG_ISA */
426 429
427static int __devinit hp100_probe1(struct net_device *dev, int ioaddr, 430static int __devinit hp100_probe1(struct net_device *dev, int ioaddr,
428 u_char bus, struct pci_dev *pci_dev) 431 u_char bus, struct pci_dev *pci_dev)
diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
index 6469130c1413..c26a4b8e552a 100644
--- a/drivers/net/ifb.c
+++ b/drivers/net/ifb.c
@@ -200,8 +200,8 @@ static struct net_device_stats *ifb_get_stats(struct net_device *dev)
200 200
201 pr_debug("tasklets stats %ld:%ld:%ld:%ld:%ld:%ld:%ld:%ld:%ld \n", 201 pr_debug("tasklets stats %ld:%ld:%ld:%ld:%ld:%ld:%ld:%ld:%ld \n",
202 dp->st_task_enter, dp->st_txq_refl_try, dp->st_rxq_enter, 202 dp->st_task_enter, dp->st_txq_refl_try, dp->st_rxq_enter,
203 dp->st_rx2tx_tran dp->st_rxq_notenter, dp->st_rx_frm_egr, 203 dp->st_rx2tx_tran, dp->st_rxq_notenter, dp->st_rx_frm_egr,
204 dp->st_rx_frm_ing, dp->st_rxq_check, dp->st_rxq_rsch ); 204 dp->st_rx_frm_ing, dp->st_rxq_check, dp->st_rxq_rsch);
205 205
206 return stats; 206 return stats;
207} 207}
diff --git a/drivers/net/irda/Kconfig b/drivers/net/irda/Kconfig
index e9e6d99a9add..7c8ccc09b601 100644
--- a/drivers/net/irda/Kconfig
+++ b/drivers/net/irda/Kconfig
@@ -287,6 +287,7 @@ comment "FIR device drivers"
287config USB_IRDA 287config USB_IRDA
288 tristate "IrDA USB dongles" 288 tristate "IrDA USB dongles"
289 depends on IRDA && USB 289 depends on IRDA && USB
290 select FW_LOADER
290 ---help--- 291 ---help---
291 Say Y here if you want to build support for the USB IrDA FIR Dongle 292 Say Y here if you want to build support for the USB IrDA FIR Dongle
292 device driver. To compile it as a module, choose M here: the module 293 device driver. To compile it as a module, choose M here: the module
diff --git a/drivers/net/irda/irda-usb.c b/drivers/net/irda/irda-usb.c
index 2a0d538b387f..383cef1f5999 100644
--- a/drivers/net/irda/irda-usb.c
+++ b/drivers/net/irda/irda-usb.c
@@ -671,10 +671,8 @@ static void irda_usb_net_timeout(struct net_device *netdev)
671 * Jean II */ 671 * Jean II */
672 done = 1; 672 done = 1;
673 break; 673 break;
674 case -ECONNABORTED: /* -103 */ 674 case -ECONNRESET:
675 case -ECONNRESET: /* -104 */ 675 case -ENOENT: /* urb unlinked by us */
676 case -ETIMEDOUT: /* -110 */
677 case -ENOENT: /* -2 (urb unlinked by us) */
678 default: /* ??? - Play safe */ 676 default: /* ??? - Play safe */
679 urb->status = 0; 677 urb->status = 0;
680 netif_wake_queue(self->netdev); 678 netif_wake_queue(self->netdev);
@@ -712,10 +710,8 @@ static void irda_usb_net_timeout(struct net_device *netdev)
712 * Jean II */ 710 * Jean II */
713 done = 1; 711 done = 1;
714 break; 712 break;
715 case -ECONNABORTED: /* -103 */ 713 case -ECONNRESET:
716 case -ECONNRESET: /* -104 */ 714 case -ENOENT: /* urb unlinked by us */
717 case -ETIMEDOUT: /* -110 */
718 case -ENOENT: /* -2 (urb unlinked by us) */
719 default: /* ??? - Play safe */ 715 default: /* ??? - Play safe */
720 if(skb != NULL) { 716 if(skb != NULL) {
721 dev_kfree_skb_any(skb); 717 dev_kfree_skb_any(skb);
@@ -845,14 +841,14 @@ static void irda_usb_receive(struct urb *urb, struct pt_regs *regs)
845 self->stats.rx_crc_errors++; 841 self->stats.rx_crc_errors++;
846 /* Also precursor to a hot-unplug on UHCI. */ 842 /* Also precursor to a hot-unplug on UHCI. */
847 /* Fallthrough... */ 843 /* Fallthrough... */
848 case -ECONNRESET: /* -104 */ 844 case -ECONNRESET:
849 /* Random error, if I remember correctly */ 845 /* Random error, if I remember correctly */
850 /* uhci_cleanup_unlink() is going to kill the Rx 846 /* uhci_cleanup_unlink() is going to kill the Rx
851 * URB just after we return. No problem, at this 847 * URB just after we return. No problem, at this
852 * point the URB will be idle ;-) - Jean II */ 848 * point the URB will be idle ;-) - Jean II */
853 case -ESHUTDOWN: /* -108 */ 849 case -ESHUTDOWN:
854 /* That's usually a hot-unplug. Submit will fail... */ 850 /* That's usually a hot-unplug. Submit will fail... */
855 case -ETIMEDOUT: /* -110 */ 851 case -ETIME:
856 /* Usually precursor to a hot-unplug on OHCI. */ 852 /* Usually precursor to a hot-unplug on OHCI. */
857 default: 853 default:
858 self->stats.rx_errors++; 854 self->stats.rx_errors++;
diff --git a/drivers/net/irda/nsc-ircc.c b/drivers/net/irda/nsc-ircc.c
index cb62f2a9676a..7185a4ee3c1e 100644
--- a/drivers/net/irda/nsc-ircc.c
+++ b/drivers/net/irda/nsc-ircc.c
@@ -110,7 +110,7 @@ static nsc_chip_t chips[] = {
110 { "PC87338", { 0x398, 0x15c, 0x2e }, 0x08, 0xb0, 0xf8, 110 { "PC87338", { 0x398, 0x15c, 0x2e }, 0x08, 0xb0, 0xf8,
111 nsc_ircc_probe_338, nsc_ircc_init_338 }, 111 nsc_ircc_probe_338, nsc_ircc_init_338 },
112 /* Contributed by Steffen Pingel - IBM X40 */ 112 /* Contributed by Steffen Pingel - IBM X40 */
113 { "PC8738x", { 0x164e, 0x4e, 0x0 }, 0x20, 0xf4, 0xff, 113 { "PC8738x", { 0x164e, 0x4e, 0x2e }, 0x20, 0xf4, 0xff,
114 nsc_ircc_probe_39x, nsc_ircc_init_39x }, 114 nsc_ircc_probe_39x, nsc_ircc_init_39x },
115 /* Contributed by Jan Frey - IBM A30/A31 */ 115 /* Contributed by Jan Frey - IBM A30/A31 */
116 { "PC8739x", { 0x2e, 0x4e, 0x0 }, 0x20, 0xea, 0xff, 116 { "PC8739x", { 0x2e, 0x4e, 0x0 }, 0x20, 0xea, 0xff,
diff --git a/drivers/net/irda/smsc-ircc2.c b/drivers/net/irda/smsc-ircc2.c
index 2eff45bedc7c..22358ff68c4c 100644
--- a/drivers/net/irda/smsc-ircc2.c
+++ b/drivers/net/irda/smsc-ircc2.c
@@ -2354,6 +2354,26 @@ static int __init smsc_superio_lpc(unsigned short cfg_base)
2354#define PCIID_VENDOR_INTEL 0x8086 2354#define PCIID_VENDOR_INTEL 0x8086
2355#define PCIID_VENDOR_ALI 0x10b9 2355#define PCIID_VENDOR_ALI 0x10b9
2356static struct smsc_ircc_subsystem_configuration subsystem_configurations[] __initdata = { 2356static struct smsc_ircc_subsystem_configuration subsystem_configurations[] __initdata = {
2357 /*
2358 * Subsystems needing entries:
2359 * 0x10b9:0x1533 0x103c:0x0850 HP nx9010 family
2360 * 0x10b9:0x1533 0x0e11:0x005a Compaq nc4000 family
2361 * 0x8086:0x24cc 0x0e11:0x002a HP nx9000 family
2362 */
2363 {
2364 /* Guessed entry */
2365 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2366 .device = 0x24cc,
2367 .subvendor = 0x103c,
2368 .subdevice = 0x08bc,
2369 .sir_io = 0x02f8,
2370 .fir_io = 0x0130,
2371 .fir_irq = 0x05,
2372 .fir_dma = 0x03,
2373 .cfg_base = 0x004e,
2374 .preconfigure = preconfigure_through_82801,
2375 .name = "HP nx5000 family",
2376 },
2357 { 2377 {
2358 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */ 2378 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2359 .device = 0x24cc, 2379 .device = 0x24cc,
@@ -2366,7 +2386,7 @@ static struct smsc_ircc_subsystem_configuration subsystem_configurations[] __ini
2366 .fir_dma = 0x03, 2386 .fir_dma = 0x03,
2367 .cfg_base = 0x004e, 2387 .cfg_base = 0x004e,
2368 .preconfigure = preconfigure_through_82801, 2388 .preconfigure = preconfigure_through_82801,
2369 .name = "HP nc8000", 2389 .name = "HP nc8000 family",
2370 }, 2390 },
2371 { 2391 {
2372 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */ 2392 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
@@ -2379,7 +2399,21 @@ static struct smsc_ircc_subsystem_configuration subsystem_configurations[] __ini
2379 .fir_dma = 0x03, 2399 .fir_dma = 0x03,
2380 .cfg_base = 0x004e, 2400 .cfg_base = 0x004e,
2381 .preconfigure = preconfigure_through_82801, 2401 .preconfigure = preconfigure_through_82801,
2382 .name = "HP nc6000", 2402 .name = "HP nc6000 family",
2403 },
2404 {
2405 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2406 .device = 0x24cc,
2407 .subvendor = 0x0e11,
2408 .subdevice = 0x0860,
2409 /* I assume these are the same for x1000 as for the others */
2410 .sir_io = 0x02e8,
2411 .fir_io = 0x02f8,
2412 .fir_irq = 0x07,
2413 .fir_dma = 0x03,
2414 .cfg_base = 0x002e,
2415 .preconfigure = preconfigure_through_82801,
2416 .name = "Compaq x1000 family",
2383 }, 2417 },
2384 { 2418 {
2385 /* Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge */ 2419 /* Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge */
diff --git a/drivers/net/irda/stir4200.c b/drivers/net/irda/stir4200.c
index d61b208b52a2..12103c93f7ef 100644
--- a/drivers/net/irda/stir4200.c
+++ b/drivers/net/irda/stir4200.c
@@ -149,8 +149,6 @@ enum StirFifoCtlMask {
149 FIFOCTL_DIR = 0x10, 149 FIFOCTL_DIR = 0x10,
150 FIFOCTL_CLR = 0x08, 150 FIFOCTL_CLR = 0x08,
151 FIFOCTL_EMPTY = 0x04, 151 FIFOCTL_EMPTY = 0x04,
152 FIFOCTL_RXERR = 0x02,
153 FIFOCTL_TXERR = 0x01,
154}; 152};
155 153
156enum StirDiagMask { 154enum StirDiagMask {
@@ -615,19 +613,6 @@ static int fifo_txwait(struct stir_cb *stir, int space)
615 613
616 pr_debug("fifo status 0x%lx count %lu\n", status, count); 614 pr_debug("fifo status 0x%lx count %lu\n", status, count);
617 615
618 /* error when receive/transmit fifo gets confused */
619 if (status & FIFOCTL_RXERR) {
620 stir->stats.rx_fifo_errors++;
621 stir->stats.rx_errors++;
622 break;
623 }
624
625 if (status & FIFOCTL_TXERR) {
626 stir->stats.tx_fifo_errors++;
627 stir->stats.tx_errors++;
628 break;
629 }
630
631 /* is fifo receiving already, or empty */ 616 /* is fifo receiving already, or empty */
632 if (!(status & FIFOCTL_DIR) 617 if (!(status & FIFOCTL_DIR)
633 || (status & FIFOCTL_EMPTY)) 618 || (status & FIFOCTL_EMPTY))
diff --git a/drivers/net/irda/via-ircc.c b/drivers/net/irda/via-ircc.c
index 79b85f327500..d916e1257c47 100644
--- a/drivers/net/irda/via-ircc.c
+++ b/drivers/net/irda/via-ircc.c
@@ -1223,8 +1223,13 @@ static int upload_rxdata(struct via_ircc_cb *self, int iobase)
1223 1223
1224 IRDA_DEBUG(2, "%s(): len=%x\n", __FUNCTION__, len); 1224 IRDA_DEBUG(2, "%s(): len=%x\n", __FUNCTION__, len);
1225 1225
1226 if ((len - 4) < 2) {
1227 self->stats.rx_dropped++;
1228 return FALSE;
1229 }
1230
1226 skb = dev_alloc_skb(len + 1); 1231 skb = dev_alloc_skb(len + 1);
1227 if ((skb == NULL) || ((len - 4) < 2)) { 1232 if (skb == NULL) {
1228 self->stats.rx_dropped++; 1233 self->stats.rx_dropped++;
1229 return FALSE; 1234 return FALSE;
1230 } 1235 }
diff --git a/drivers/net/irda/vlsi_ir.h b/drivers/net/irda/vlsi_ir.h
index a82a4ba8de4f..c37f0bc4c7f9 100644
--- a/drivers/net/irda/vlsi_ir.h
+++ b/drivers/net/irda/vlsi_ir.h
@@ -58,7 +58,7 @@ typedef void irqreturn_t;
58 58
59/* PDE() introduced in 2.5.4 */ 59/* PDE() introduced in 2.5.4 */
60#ifdef CONFIG_PROC_FS 60#ifdef CONFIG_PROC_FS
61#define PDE(inode) ((inode)->u.generic_ip) 61#define PDE(inode) ((inode)->i_private)
62#endif 62#endif
63 63
64/* irda crc16 calculation exported in 2.5.42 */ 64/* irda crc16 calculation exported in 2.5.42 */
diff --git a/drivers/net/ixgb/Makefile b/drivers/net/ixgb/Makefile
index a8a2d3d03567..838a5084fa00 100644
--- a/drivers/net/ixgb/Makefile
+++ b/drivers/net/ixgb/Makefile
@@ -1,33 +1,33 @@
1################################################################################ 1################################################################################
2# 2#
3# 3# Intel PRO/10GbE Linux driver
4# Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4# Copyright(c) 1999 - 2006 Intel Corporation.
5# 5#
6# This program is free software; you can redistribute it and/or modify it 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 7# under the terms and conditions of the GNU General Public License,
8# Software Foundation; either version 2 of the License, or (at your option) 8# version 2, as published by the Free Software Foundation.
9# any later version. 9#
10# 10# This program is distributed in the hope it will be useful, but WITHOUT
11# This program is distributed in the hope that it will be useful, but WITHOUT 11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14# more details. 13# more details.
15# 14#
16# You should have received a copy of the GNU General Public License along with 15# 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 16# this program; if not, write to the Free Software Foundation, Inc.,
18# Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17# 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19# 18#
20# The full GNU General Public License is included in this distribution in the 19# The full GNU General Public License is included in this distribution in
21# file called LICENSE. 20# the file called "COPYING".
22# 21#
23# Contact Information: 22# Contact Information:
24# Linux NICS <linux.nics@intel.com> 23# Linux NICS <linux.nics@intel.com>
24# e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25# Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 25# Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26# 26#
27################################################################################ 27################################################################################
28 28
29# 29#
30# Makefile for the Intel(R) PRO/10GbE driver 30# Makefile for the Intel(R) PRO/10GbE ethernet driver
31# 31#
32 32
33obj-$(CONFIG_IXGB) += ixgb.o 33obj-$(CONFIG_IXGB) += ixgb.o
diff --git a/drivers/net/ixgb/ixgb.h b/drivers/net/ixgb/ixgb.h
index a51604b3651f..50ffe90488ff 100644
--- a/drivers/net/ixgb/ixgb.h
+++ b/drivers/net/ixgb/ixgb.h
@@ -1,27 +1,27 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/10GbE Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version. 9
10 10 This program is distributed in the hope it will be useful, but WITHOUT
11 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 26
27*******************************************************************************/ 27*******************************************************************************/
@@ -111,7 +111,7 @@ struct ixgb_adapter;
111#define IXGB_RXBUFFER_16384 16384 111#define IXGB_RXBUFFER_16384 16384
112 112
113/* How many Rx Buffers do we bundle into one write to the hardware ? */ 113/* How many Rx Buffers do we bundle into one write to the hardware ? */
114#define IXGB_RX_BUFFER_WRITE 4 /* Must be power of 2 */ 114#define IXGB_RX_BUFFER_WRITE 8 /* Must be power of 2 */
115 115
116/* only works for sizes that are powers of 2 */ 116/* only works for sizes that are powers of 2 */
117#define IXGB_ROUNDUP(i, size) ((i) = (((i) + (size) - 1) & ~((size) - 1))) 117#define IXGB_ROUNDUP(i, size) ((i) = (((i) + (size) - 1) & ~((size) - 1)))
diff --git a/drivers/net/ixgb/ixgb_ee.c b/drivers/net/ixgb/ixgb_ee.c
index 8357c5590bfb..f15aebde7b90 100644
--- a/drivers/net/ixgb/ixgb_ee.c
+++ b/drivers/net/ixgb/ixgb_ee.c
@@ -1,27 +1,27 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/10GbE Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version. 9
10 10 This program is distributed in the hope it will be useful, but WITHOUT
11 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 26
27*******************************************************************************/ 27*******************************************************************************/
diff --git a/drivers/net/ixgb/ixgb_ee.h b/drivers/net/ixgb/ixgb_ee.h
index bf6fa220f38e..ef236b935c15 100644
--- a/drivers/net/ixgb/ixgb_ee.h
+++ b/drivers/net/ixgb/ixgb_ee.h
@@ -1,27 +1,27 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/10GbE Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version. 9
10 10 This program is distributed in the hope it will be useful, but WITHOUT
11 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 26
27*******************************************************************************/ 27*******************************************************************************/
diff --git a/drivers/net/ixgb/ixgb_ethtool.c b/drivers/net/ixgb/ixgb_ethtool.c
index 64a383e4e892..cd22523fb035 100644
--- a/drivers/net/ixgb/ixgb_ethtool.c
+++ b/drivers/net/ixgb/ixgb_ethtool.c
@@ -1,27 +1,27 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/10GbE Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version. 9
10 10 This program is distributed in the hope it will be useful, but WITHOUT
11 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 26
27*******************************************************************************/ 27*******************************************************************************/
diff --git a/drivers/net/ixgb/ixgb_hw.c b/drivers/net/ixgb/ixgb_hw.c
index acc6df7a6b38..02089b64e42c 100644
--- a/drivers/net/ixgb/ixgb_hw.c
+++ b/drivers/net/ixgb/ixgb_hw.c
@@ -1,27 +1,27 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/10GbE Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version. 9
10 10 This program is distributed in the hope it will be useful, but WITHOUT
11 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 26
27*******************************************************************************/ 27*******************************************************************************/
diff --git a/drivers/net/ixgb/ixgb_hw.h b/drivers/net/ixgb/ixgb_hw.h
index cb4568915ada..40ef5ca88717 100644
--- a/drivers/net/ixgb/ixgb_hw.h
+++ b/drivers/net/ixgb/ixgb_hw.h
@@ -1,27 +1,27 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/10GbE Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version. 9
10 10 This program is distributed in the hope it will be useful, but WITHOUT
11 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 26
27*******************************************************************************/ 27*******************************************************************************/
diff --git a/drivers/net/ixgb/ixgb_ids.h b/drivers/net/ixgb/ixgb_ids.h
index 9fd61189b4b2..4376e7e8fbef 100644
--- a/drivers/net/ixgb/ixgb_ids.h
+++ b/drivers/net/ixgb/ixgb_ids.h
@@ -1,27 +1,27 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/10GbE Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version. 9
10 10 This program is distributed in the hope it will be useful, but WITHOUT
11 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 26
27*******************************************************************************/ 27*******************************************************************************/
diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
index 2e0f4b950a90..cfde7c2569bb 100644
--- a/drivers/net/ixgb/ixgb_main.c
+++ b/drivers/net/ixgb/ixgb_main.c
@@ -1,27 +1,27 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/10GbE Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version. 9
10 10 This program is distributed in the hope it will be useful, but WITHOUT
11 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 26
27*******************************************************************************/ 27*******************************************************************************/
@@ -36,7 +36,7 @@ static char ixgb_driver_string[] = "Intel(R) PRO/10GbE Network Driver";
36#else 36#else
37#define DRIVERNAPI "-NAPI" 37#define DRIVERNAPI "-NAPI"
38#endif 38#endif
39#define DRV_VERSION "1.0.112-k2"DRIVERNAPI 39#define DRV_VERSION "1.0.117-k2"DRIVERNAPI
40char ixgb_driver_version[] = DRV_VERSION; 40char ixgb_driver_version[] = DRV_VERSION;
41static char ixgb_copyright[] = "Copyright (c) 1999-2006 Intel Corporation."; 41static char ixgb_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
42 42
@@ -437,7 +437,7 @@ ixgb_probe(struct pci_dev *pdev,
437 netdev->poll_controller = ixgb_netpoll; 437 netdev->poll_controller = ixgb_netpoll;
438#endif 438#endif
439 439
440 strcpy(netdev->name, pci_name(pdev)); 440 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
441 netdev->mem_start = mmio_start; 441 netdev->mem_start = mmio_start;
442 netdev->mem_end = mmio_start + mmio_len; 442 netdev->mem_end = mmio_start + mmio_len;
443 netdev->base_addr = adapter->hw.io_base; 443 netdev->base_addr = adapter->hw.io_base;
@@ -2230,7 +2230,7 @@ static pci_ers_result_t ixgb_io_error_detected (struct pci_dev *pdev,
2230 enum pci_channel_state state) 2230 enum pci_channel_state state)
2231{ 2231{
2232 struct net_device *netdev = pci_get_drvdata(pdev); 2232 struct net_device *netdev = pci_get_drvdata(pdev);
2233 struct ixgb_adapter *adapter = netdev->priv; 2233 struct ixgb_adapter *adapter = netdev_priv(netdev);
2234 2234
2235 if(netif_running(netdev)) 2235 if(netif_running(netdev))
2236 ixgb_down(adapter, TRUE); 2236 ixgb_down(adapter, TRUE);
@@ -2253,7 +2253,7 @@ static pci_ers_result_t ixgb_io_error_detected (struct pci_dev *pdev,
2253static pci_ers_result_t ixgb_io_slot_reset (struct pci_dev *pdev) 2253static pci_ers_result_t ixgb_io_slot_reset (struct pci_dev *pdev)
2254{ 2254{
2255 struct net_device *netdev = pci_get_drvdata(pdev); 2255 struct net_device *netdev = pci_get_drvdata(pdev);
2256 struct ixgb_adapter *adapter = netdev->priv; 2256 struct ixgb_adapter *adapter = netdev_priv(netdev);
2257 2257
2258 if(pci_enable_device(pdev)) { 2258 if(pci_enable_device(pdev)) {
2259 DPRINTK(PROBE, ERR, "Cannot re-enable PCI device after reset.\n"); 2259 DPRINTK(PROBE, ERR, "Cannot re-enable PCI device after reset.\n");
@@ -2297,7 +2297,7 @@ static pci_ers_result_t ixgb_io_slot_reset (struct pci_dev *pdev)
2297static void ixgb_io_resume (struct pci_dev *pdev) 2297static void ixgb_io_resume (struct pci_dev *pdev)
2298{ 2298{
2299 struct net_device *netdev = pci_get_drvdata(pdev); 2299 struct net_device *netdev = pci_get_drvdata(pdev);
2300 struct ixgb_adapter *adapter = netdev->priv; 2300 struct ixgb_adapter *adapter = netdev_priv(netdev);
2301 2301
2302 pci_set_master(pdev); 2302 pci_set_master(pdev);
2303 2303
diff --git a/drivers/net/ixgb/ixgb_osdep.h b/drivers/net/ixgb/ixgb_osdep.h
index 19cb1d586dec..8434d752fd81 100644
--- a/drivers/net/ixgb/ixgb_osdep.h
+++ b/drivers/net/ixgb/ixgb_osdep.h
@@ -1,27 +1,27 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/10GbE Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version. 9
10 10 This program is distributed in the hope it will be useful, but WITHOUT
11 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 26
27*******************************************************************************/ 27*******************************************************************************/
diff --git a/drivers/net/ixgb/ixgb_param.c b/drivers/net/ixgb/ixgb_param.c
index 39fbed29a3df..b27442a121f2 100644
--- a/drivers/net/ixgb/ixgb_param.c
+++ b/drivers/net/ixgb/ixgb_param.c
@@ -1,27 +1,27 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 3 Intel PRO/10GbE Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved. 4 Copyright(c) 1999 - 2006 Intel Corporation.
5 5
6 This program is free software; you can redistribute it and/or modify it 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 7 under the terms and conditions of the GNU General Public License,
8 Software Foundation; either version 2 of the License, or (at your option) 8 version 2, as published by the Free Software Foundation.
9 any later version. 9
10 10 This program is distributed in the hope it will be useful, but WITHOUT
11 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. 13 more details.
15 14
16 You should have received a copy of the GNU General Public License along with 15 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 16 this program; if not, write to the Free Software Foundation, Inc.,
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 18
20 The full GNU General Public License is included in this distribution in the 19 The full GNU General Public License is included in this distribution in
21 file called LICENSE. 20 the file called "COPYING".
22 21
23 Contact Information: 22 Contact Information:
24 Linux NICS <linux.nics@intel.com> 23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 26
27*******************************************************************************/ 27*******************************************************************************/
diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c
index f429b19bf620..4178b4b1d2df 100644
--- a/drivers/net/loopback.c
+++ b/drivers/net/loopback.c
@@ -161,15 +161,13 @@ static int loopback_xmit(struct sk_buff *skb, struct net_device *dev)
161 return(0); 161 return(0);
162} 162}
163 163
164static struct net_device_stats loopback_stats;
165
164static struct net_device_stats *get_stats(struct net_device *dev) 166static struct net_device_stats *get_stats(struct net_device *dev)
165{ 167{
166 struct net_device_stats *stats = dev->priv; 168 struct net_device_stats *stats = &loopback_stats;
167 int i; 169 int i;
168 170
169 if (!stats) {
170 return NULL;
171 }
172
173 memset(stats, 0, sizeof(struct net_device_stats)); 171 memset(stats, 0, sizeof(struct net_device_stats));
174 172
175 for_each_possible_cpu(i) { 173 for_each_possible_cpu(i) {
@@ -185,19 +183,28 @@ static struct net_device_stats *get_stats(struct net_device *dev)
185 return stats; 183 return stats;
186} 184}
187 185
188static u32 loopback_get_link(struct net_device *dev) 186static u32 always_on(struct net_device *dev)
189{ 187{
190 return 1; 188 return 1;
191} 189}
192 190
193static const struct ethtool_ops loopback_ethtool_ops = { 191static const struct ethtool_ops loopback_ethtool_ops = {
194 .get_link = loopback_get_link, 192 .get_link = always_on,
195 .get_tso = ethtool_op_get_tso, 193 .get_tso = ethtool_op_get_tso,
196 .set_tso = ethtool_op_set_tso, 194 .set_tso = ethtool_op_set_tso,
195 .get_tx_csum = always_on,
196 .get_sg = always_on,
197 .get_rx_csum = always_on,
197}; 198};
198 199
200/*
201 * The loopback device is special. There is only one instance and
202 * it is statically allocated. Don't do this for other devices.
203 */
199struct net_device loopback_dev = { 204struct net_device loopback_dev = {
200 .name = "lo", 205 .name = "lo",
206 .get_stats = &get_stats,
207 .priv = &loopback_stats,
201 .mtu = (16 * 1024) + 20 + 20 + 12, 208 .mtu = (16 * 1024) + 20 + 20 + 12,
202 .hard_start_xmit = loopback_xmit, 209 .hard_start_xmit = loopback_xmit,
203 .hard_header = eth_header, 210 .hard_header = eth_header,
@@ -221,16 +228,6 @@ struct net_device loopback_dev = {
221/* Setup and register the loopback device. */ 228/* Setup and register the loopback device. */
222int __init loopback_init(void) 229int __init loopback_init(void)
223{ 230{
224 struct net_device_stats *stats;
225
226 /* Can survive without statistics */
227 stats = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL);
228 if (stats) {
229 memset(stats, 0, sizeof(struct net_device_stats));
230 loopback_dev.priv = stats;
231 loopback_dev.get_stats = &get_stats;
232 }
233
234 return register_netdev(&loopback_dev); 231 return register_netdev(&loopback_dev);
235}; 232};
236 233
diff --git a/drivers/net/ne3210.c b/drivers/net/ne3210.c
index 0fa8e4d22769..d66328975425 100644
--- a/drivers/net/ne3210.c
+++ b/drivers/net/ne3210.c
@@ -343,6 +343,7 @@ static struct eisa_device_id ne3210_ids[] = {
343 { "NVL1801" }, 343 { "NVL1801" },
344 { "" }, 344 { "" },
345}; 345};
346MODULE_DEVICE_TABLE(eisa, ne3210_ids);
346 347
347static struct eisa_driver ne3210_eisa_driver = { 348static struct eisa_driver ne3210_eisa_driver = {
348 .id_table = ne3210_ids, 349 .id_table = ne3210_ids,
diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c
index 19f7ee63276f..94b47c8d0ab4 100644
--- a/drivers/net/phy/fixed.c
+++ b/drivers/net/phy/fixed.c
@@ -289,9 +289,13 @@ static int fixed_mdio_register_device(int number, int speed, int duplex)
289 goto probe_fail; 289 goto probe_fail;
290 } 290 }
291 291
292 device_bind_driver(&phydev->dev); 292 err = device_bind_driver(&phydev->dev);
293
293 up_write(&phydev->dev.bus->subsys.rwsem); 294 up_write(&phydev->dev.bus->subsys.rwsem);
294 295
296 if (err)
297 goto probe_fail;
298
295 return 0; 299 return 0;
296 300
297probe_fail: 301probe_fail:
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 2d1ecfdc80db..3bbd5e70c209 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -212,11 +212,13 @@ struct phy_device *phy_attach(struct net_device *dev,
212 212
213 err = d->driver->probe(d); 213 err = d->driver->probe(d);
214 214
215 if (err < 0) 215 if (err >= 0)
216 return ERR_PTR(err); 216 err = device_bind_driver(d);
217 217
218 device_bind_driver(d);
219 up_write(&d->bus->subsys.rwsem); 218 up_write(&d->bus->subsys.rwsem);
219
220 if (err)
221 return ERR_PTR(err);
220 } 222 }
221 223
222 if (phydev->attached_dev) { 224 if (phydev->attached_dev) {
@@ -522,7 +524,7 @@ EXPORT_SYMBOL(genphy_read_status);
522 524
523static int genphy_config_init(struct phy_device *phydev) 525static int genphy_config_init(struct phy_device *phydev)
524{ 526{
525 u32 val; 527 int val;
526 u32 features; 528 u32 features;
527 529
528 /* For now, I'll claim that the generic driver supports 530 /* For now, I'll claim that the generic driver supports
diff --git a/drivers/net/pppoe.c b/drivers/net/pppoe.c
index 5666ed998142..0adee733b761 100644
--- a/drivers/net/pppoe.c
+++ b/drivers/net/pppoe.c
@@ -600,6 +600,7 @@ static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr,
600 po->chan.hdrlen = (sizeof(struct pppoe_hdr) + 600 po->chan.hdrlen = (sizeof(struct pppoe_hdr) +
601 dev->hard_header_len); 601 dev->hard_header_len);
602 602
603 po->chan.mtu = dev->mtu - sizeof(struct pppoe_hdr);
603 po->chan.private = sk; 604 po->chan.private = sk;
604 po->chan.ops = &pppoe_chan_ops; 605 po->chan.ops = &pppoe_chan_ops;
605 606
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index f5dbeb27b6f0..1bf23e41f580 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -2904,7 +2904,7 @@ static void s2io_mdio_write(u32 mmd_type, u64 addr, u16 value, struct net_device
2904{ 2904{
2905 u64 val64 = 0x0; 2905 u64 val64 = 0x0;
2906 nic_t *sp = dev->priv; 2906 nic_t *sp = dev->priv;
2907 XENA_dev_config_t *bar0 = (XENA_dev_config_t *)sp->bar0; 2907 XENA_dev_config_t __iomem *bar0 = sp->bar0;
2908 2908
2909 //address transaction 2909 //address transaction
2910 val64 = val64 | MDIO_MMD_INDX_ADDR(addr) 2910 val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
@@ -2953,7 +2953,7 @@ static u64 s2io_mdio_read(u32 mmd_type, u64 addr, struct net_device *dev)
2953 u64 val64 = 0x0; 2953 u64 val64 = 0x0;
2954 u64 rval64 = 0x0; 2954 u64 rval64 = 0x0;
2955 nic_t *sp = dev->priv; 2955 nic_t *sp = dev->priv;
2956 XENA_dev_config_t *bar0 = (XENA_dev_config_t *)sp->bar0; 2956 XENA_dev_config_t __iomem *bar0 = sp->bar0;
2957 2957
2958 /* address transaction */ 2958 /* address transaction */
2959 val64 = val64 | MDIO_MMD_INDX_ADDR(addr) 2959 val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
@@ -3276,7 +3276,7 @@ static void alarm_intr_handler(struct s2io_nic *nic)
3276 * SUCCESS on success and FAILURE on failure. 3276 * SUCCESS on success and FAILURE on failure.
3277 */ 3277 */
3278 3278
3279static int wait_for_cmd_complete(void *addr, u64 busy_bit) 3279static int wait_for_cmd_complete(void __iomem *addr, u64 busy_bit)
3280{ 3280{
3281 int ret = FAILURE, cnt = 0; 3281 int ret = FAILURE, cnt = 0;
3282 u64 val64; 3282 u64 val64;
@@ -4303,11 +4303,11 @@ static struct net_device_stats *s2io_get_stats(struct net_device *dev)
4303 sp->stats.tx_errors = 4303 sp->stats.tx_errors =
4304 le32_to_cpu(mac_control->stats_info->tmac_any_err_frms); 4304 le32_to_cpu(mac_control->stats_info->tmac_any_err_frms);
4305 sp->stats.rx_errors = 4305 sp->stats.rx_errors =
4306 le32_to_cpu(mac_control->stats_info->rmac_drop_frms); 4306 le64_to_cpu(mac_control->stats_info->rmac_drop_frms);
4307 sp->stats.multicast = 4307 sp->stats.multicast =
4308 le32_to_cpu(mac_control->stats_info->rmac_vld_mcst_frms); 4308 le32_to_cpu(mac_control->stats_info->rmac_vld_mcst_frms);
4309 sp->stats.rx_length_errors = 4309 sp->stats.rx_length_errors =
4310 le32_to_cpu(mac_control->stats_info->rmac_long_frms); 4310 le64_to_cpu(mac_control->stats_info->rmac_long_frms);
4311 4311
4312 return (&sp->stats); 4312 return (&sp->stats);
4313} 4313}
diff --git a/drivers/net/skge.c b/drivers/net/skge.c
index 9142d91355bc..705e9a8fa30f 100644
--- a/drivers/net/skge.c
+++ b/drivers/net/skge.c
@@ -58,6 +58,7 @@
58#define TX_WATCHDOG (5 * HZ) 58#define TX_WATCHDOG (5 * HZ)
59#define NAPI_WEIGHT 64 59#define NAPI_WEIGHT 64
60#define BLINK_MS 250 60#define BLINK_MS 250
61#define LINK_HZ (HZ/2)
61 62
62MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver"); 63MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver");
63MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>"); 64MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>");
@@ -605,7 +606,12 @@ static void skge_led(struct skge_port *skge, enum led_mode mode)
605 if (hw->chip_id == CHIP_ID_GENESIS) { 606 if (hw->chip_id == CHIP_ID_GENESIS) {
606 switch (mode) { 607 switch (mode) {
607 case LED_MODE_OFF: 608 case LED_MODE_OFF:
608 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_OFF); 609 if (hw->phy_type == SK_PHY_BCOM)
610 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_OFF);
611 else {
612 skge_write32(hw, SK_REG(port, TX_LED_VAL), 0);
613 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_T_OFF);
614 }
609 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF); 615 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF);
610 skge_write32(hw, SK_REG(port, RX_LED_VAL), 0); 616 skge_write32(hw, SK_REG(port, RX_LED_VAL), 0);
611 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_T_OFF); 617 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_T_OFF);
@@ -625,8 +631,14 @@ static void skge_led(struct skge_port *skge, enum led_mode mode)
625 skge_write32(hw, SK_REG(port, RX_LED_VAL), 100); 631 skge_write32(hw, SK_REG(port, RX_LED_VAL), 100);
626 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START); 632 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
627 633
628 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_ON); 634 if (hw->phy_type == SK_PHY_BCOM)
629 break; 635 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_ON);
636 else {
637 skge_write8(hw, SK_REG(port, TX_LED_TST), LED_T_ON);
638 skge_write32(hw, SK_REG(port, TX_LED_VAL), 100);
639 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START);
640 }
641
630 } 642 }
631 } else { 643 } else {
632 switch (mode) { 644 switch (mode) {
@@ -879,6 +891,9 @@ static int __xm_phy_read(struct skge_hw *hw, int port, u16 reg, u16 *val)
879 xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr); 891 xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr);
880 *val = xm_read16(hw, port, XM_PHY_DATA); 892 *val = xm_read16(hw, port, XM_PHY_DATA);
881 893
894 if (hw->phy_type == SK_PHY_XMAC)
895 goto ready;
896
882 for (i = 0; i < PHY_RETRIES; i++) { 897 for (i = 0; i < PHY_RETRIES; i++) {
883 if (xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_RDY) 898 if (xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_RDY)
884 goto ready; 899 goto ready;
@@ -965,7 +980,8 @@ static void genesis_reset(struct skge_hw *hw, int port)
965 xm_write16(hw, port, XM_RX_CMD, 0); /* reset RX CMD Reg */ 980 xm_write16(hw, port, XM_RX_CMD, 0); /* reset RX CMD Reg */
966 981
967 /* disable Broadcom PHY IRQ */ 982 /* disable Broadcom PHY IRQ */
968 xm_write16(hw, port, PHY_BCOM_INT_MASK, 0xffff); 983 if (hw->phy_type == SK_PHY_BCOM)
984 xm_write16(hw, port, PHY_BCOM_INT_MASK, 0xffff);
969 985
970 xm_outhash(hw, port, XM_HSM, zero); 986 xm_outhash(hw, port, XM_HSM, zero);
971} 987}
@@ -1000,60 +1016,64 @@ static void bcom_check_link(struct skge_hw *hw, int port)
1000 1016
1001 if (netif_carrier_ok(dev)) 1017 if (netif_carrier_ok(dev))
1002 skge_link_down(skge); 1018 skge_link_down(skge);
1003 } else { 1019 return;
1004 if (skge->autoneg == AUTONEG_ENABLE && 1020 }
1005 (status & PHY_ST_AN_OVER)) {
1006 u16 lpa = xm_phy_read(hw, port, PHY_BCOM_AUNE_LP);
1007 u16 aux = xm_phy_read(hw, port, PHY_BCOM_AUX_STAT);
1008
1009 if (lpa & PHY_B_AN_RF) {
1010 printk(KERN_NOTICE PFX "%s: remote fault\n",
1011 dev->name);
1012 return;
1013 }
1014 1021
1015 /* Check Duplex mismatch */ 1022 if (skge->autoneg == AUTONEG_ENABLE) {
1016 switch (aux & PHY_B_AS_AN_RES_MSK) { 1023 u16 lpa, aux;
1017 case PHY_B_RES_1000FD:
1018 skge->duplex = DUPLEX_FULL;
1019 break;
1020 case PHY_B_RES_1000HD:
1021 skge->duplex = DUPLEX_HALF;
1022 break;
1023 default:
1024 printk(KERN_NOTICE PFX "%s: duplex mismatch\n",
1025 dev->name);
1026 return;
1027 }
1028 1024
1025 if (!(status & PHY_ST_AN_OVER))
1026 return;
1029 1027
1030 /* We are using IEEE 802.3z/D5.0 Table 37-4 */ 1028 lpa = xm_phy_read(hw, port, PHY_XMAC_AUNE_LP);
1031 switch (aux & PHY_B_AS_PAUSE_MSK) { 1029 if (lpa & PHY_B_AN_RF) {
1032 case PHY_B_AS_PAUSE_MSK: 1030 printk(KERN_NOTICE PFX "%s: remote fault\n",
1033 skge->flow_control = FLOW_MODE_SYMMETRIC; 1031 dev->name);
1034 break; 1032 return;
1035 case PHY_B_AS_PRR: 1033 }
1036 skge->flow_control = FLOW_MODE_REM_SEND;
1037 break;
1038 case PHY_B_AS_PRT:
1039 skge->flow_control = FLOW_MODE_LOC_SEND;
1040 break;
1041 default:
1042 skge->flow_control = FLOW_MODE_NONE;
1043 }
1044 1034
1045 skge->speed = SPEED_1000; 1035 aux = xm_phy_read(hw, port, PHY_BCOM_AUX_STAT);
1036
1037 /* Check Duplex mismatch */
1038 switch (aux & PHY_B_AS_AN_RES_MSK) {
1039 case PHY_B_RES_1000FD:
1040 skge->duplex = DUPLEX_FULL;
1041 break;
1042 case PHY_B_RES_1000HD:
1043 skge->duplex = DUPLEX_HALF;
1044 break;
1045 default:
1046 printk(KERN_NOTICE PFX "%s: duplex mismatch\n",
1047 dev->name);
1048 return;
1046 } 1049 }
1047 1050
1048 if (!netif_carrier_ok(dev)) 1051
1049 genesis_link_up(skge); 1052 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
1053 switch (aux & PHY_B_AS_PAUSE_MSK) {
1054 case PHY_B_AS_PAUSE_MSK:
1055 skge->flow_control = FLOW_MODE_SYMMETRIC;
1056 break;
1057 case PHY_B_AS_PRR:
1058 skge->flow_control = FLOW_MODE_REM_SEND;
1059 break;
1060 case PHY_B_AS_PRT:
1061 skge->flow_control = FLOW_MODE_LOC_SEND;
1062 break;
1063 default:
1064 skge->flow_control = FLOW_MODE_NONE;
1065 }
1066 skge->speed = SPEED_1000;
1050 } 1067 }
1068
1069 if (!netif_carrier_ok(dev))
1070 genesis_link_up(skge);
1051} 1071}
1052 1072
1053/* Broadcom 5400 only supports giagabit! SysKonnect did not put an additional 1073/* Broadcom 5400 only supports giagabit! SysKonnect did not put an additional
1054 * Phy on for 100 or 10Mbit operation 1074 * Phy on for 100 or 10Mbit operation
1055 */ 1075 */
1056static void bcom_phy_init(struct skge_port *skge, int jumbo) 1076static void bcom_phy_init(struct skge_port *skge)
1057{ 1077{
1058 struct skge_hw *hw = skge->hw; 1078 struct skge_hw *hw = skge->hw;
1059 int port = skge->port; 1079 int port = skge->port;
@@ -1144,7 +1164,7 @@ static void bcom_phy_init(struct skge_port *skge, int jumbo)
1144 phy_pause_map[skge->flow_control] | PHY_AN_CSMA); 1164 phy_pause_map[skge->flow_control] | PHY_AN_CSMA);
1145 1165
1146 /* Handle Jumbo frames */ 1166 /* Handle Jumbo frames */
1147 if (jumbo) { 1167 if (hw->dev[port]->mtu > ETH_DATA_LEN) {
1148 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, 1168 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL,
1149 PHY_B_AC_TX_TST | PHY_B_AC_LONG_PACK); 1169 PHY_B_AC_TX_TST | PHY_B_AC_LONG_PACK);
1150 1170
@@ -1157,8 +1177,154 @@ static void bcom_phy_init(struct skge_port *skge, int jumbo)
1157 1177
1158 /* Use link status change interrupt */ 1178 /* Use link status change interrupt */
1159 xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK); 1179 xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK);
1180}
1160 1181
1161 bcom_check_link(hw, port); 1182static void xm_phy_init(struct skge_port *skge)
1183{
1184 struct skge_hw *hw = skge->hw;
1185 int port = skge->port;
1186 u16 ctrl = 0;
1187
1188 if (skge->autoneg == AUTONEG_ENABLE) {
1189 if (skge->advertising & ADVERTISED_1000baseT_Half)
1190 ctrl |= PHY_X_AN_HD;
1191 if (skge->advertising & ADVERTISED_1000baseT_Full)
1192 ctrl |= PHY_X_AN_FD;
1193
1194 switch(skge->flow_control) {
1195 case FLOW_MODE_NONE:
1196 ctrl |= PHY_X_P_NO_PAUSE;
1197 break;
1198 case FLOW_MODE_LOC_SEND:
1199 ctrl |= PHY_X_P_ASYM_MD;
1200 break;
1201 case FLOW_MODE_SYMMETRIC:
1202 ctrl |= PHY_X_P_BOTH_MD;
1203 break;
1204 }
1205
1206 xm_phy_write(hw, port, PHY_XMAC_AUNE_ADV, ctrl);
1207
1208 /* Restart Auto-negotiation */
1209 ctrl = PHY_CT_ANE | PHY_CT_RE_CFG;
1210 } else {
1211 /* Set DuplexMode in Config register */
1212 if (skge->duplex == DUPLEX_FULL)
1213 ctrl |= PHY_CT_DUP_MD;
1214 /*
1215 * Do NOT enable Auto-negotiation here. This would hold
1216 * the link down because no IDLEs are transmitted
1217 */
1218 }
1219
1220 xm_phy_write(hw, port, PHY_XMAC_CTRL, ctrl);
1221
1222 /* Poll PHY for status changes */
1223 schedule_delayed_work(&skge->link_thread, LINK_HZ);
1224}
1225
1226static void xm_check_link(struct net_device *dev)
1227{
1228 struct skge_port *skge = netdev_priv(dev);
1229 struct skge_hw *hw = skge->hw;
1230 int port = skge->port;
1231 u16 status;
1232
1233 /* read twice because of latch */
1234 (void) xm_phy_read(hw, port, PHY_XMAC_STAT);
1235 status = xm_phy_read(hw, port, PHY_XMAC_STAT);
1236
1237 if ((status & PHY_ST_LSYNC) == 0) {
1238 u16 cmd = xm_read16(hw, port, XM_MMU_CMD);
1239 cmd &= ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX);
1240 xm_write16(hw, port, XM_MMU_CMD, cmd);
1241 /* dummy read to ensure writing */
1242 (void) xm_read16(hw, port, XM_MMU_CMD);
1243
1244 if (netif_carrier_ok(dev))
1245 skge_link_down(skge);
1246 return;
1247 }
1248
1249 if (skge->autoneg == AUTONEG_ENABLE) {
1250 u16 lpa, res;
1251
1252 if (!(status & PHY_ST_AN_OVER))
1253 return;
1254
1255 lpa = xm_phy_read(hw, port, PHY_XMAC_AUNE_LP);
1256 if (lpa & PHY_B_AN_RF) {
1257 printk(KERN_NOTICE PFX "%s: remote fault\n",
1258 dev->name);
1259 return;
1260 }
1261
1262 res = xm_phy_read(hw, port, PHY_XMAC_RES_ABI);
1263
1264 /* Check Duplex mismatch */
1265 switch (res & (PHY_X_RS_HD | PHY_X_RS_FD)) {
1266 case PHY_X_RS_FD:
1267 skge->duplex = DUPLEX_FULL;
1268 break;
1269 case PHY_X_RS_HD:
1270 skge->duplex = DUPLEX_HALF;
1271 break;
1272 default:
1273 printk(KERN_NOTICE PFX "%s: duplex mismatch\n",
1274 dev->name);
1275 return;
1276 }
1277
1278 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
1279 if (lpa & PHY_X_P_SYM_MD)
1280 skge->flow_control = FLOW_MODE_SYMMETRIC;
1281 else if ((lpa & PHY_X_RS_PAUSE) == PHY_X_P_ASYM_MD)
1282 skge->flow_control = FLOW_MODE_REM_SEND;
1283 else if ((lpa & PHY_X_RS_PAUSE) == PHY_X_P_BOTH_MD)
1284 skge->flow_control = FLOW_MODE_LOC_SEND;
1285 else
1286 skge->flow_control = FLOW_MODE_NONE;
1287
1288
1289 skge->speed = SPEED_1000;
1290 }
1291
1292 if (!netif_carrier_ok(dev))
1293 genesis_link_up(skge);
1294}
1295
1296/* Poll to check for link coming up.
1297 * Since internal PHY is wired to a level triggered pin, can't
1298 * get an interrupt when carrier is detected.
1299 */
1300static void xm_link_timer(void *arg)
1301{
1302 struct net_device *dev = arg;
1303 struct skge_port *skge = netdev_priv(arg);
1304 struct skge_hw *hw = skge->hw;
1305 int port = skge->port;
1306
1307 if (!netif_running(dev))
1308 return;
1309
1310 if (netif_carrier_ok(dev)) {
1311 xm_read16(hw, port, XM_ISRC);
1312 if (!(xm_read16(hw, port, XM_ISRC) & XM_IS_INP_ASS))
1313 goto nochange;
1314 } else {
1315 if (xm_read32(hw, port, XM_GP_PORT) & XM_GP_INP_ASS)
1316 goto nochange;
1317 xm_read16(hw, port, XM_ISRC);
1318 if (xm_read16(hw, port, XM_ISRC) & XM_IS_INP_ASS)
1319 goto nochange;
1320 }
1321
1322 mutex_lock(&hw->phy_mutex);
1323 xm_check_link(dev);
1324 mutex_unlock(&hw->phy_mutex);
1325
1326nochange:
1327 schedule_delayed_work(&skge->link_thread, LINK_HZ);
1162} 1328}
1163 1329
1164static void genesis_mac_init(struct skge_hw *hw, int port) 1330static void genesis_mac_init(struct skge_hw *hw, int port)
@@ -1189,20 +1355,29 @@ static void genesis_mac_init(struct skge_hw *hw, int port)
1189 * namely for the 1000baseTX cards that use the XMAC's 1355 * namely for the 1000baseTX cards that use the XMAC's
1190 * GMII mode. 1356 * GMII mode.
1191 */ 1357 */
1192 /* Take external Phy out of reset */ 1358 if (hw->phy_type != SK_PHY_XMAC) {
1193 r = skge_read32(hw, B2_GP_IO); 1359 /* Take external Phy out of reset */
1194 if (port == 0) 1360 r = skge_read32(hw, B2_GP_IO);
1195 r |= GP_DIR_0|GP_IO_0; 1361 if (port == 0)
1196 else 1362 r |= GP_DIR_0|GP_IO_0;
1197 r |= GP_DIR_2|GP_IO_2; 1363 else
1364 r |= GP_DIR_2|GP_IO_2;
1198 1365
1199 skge_write32(hw, B2_GP_IO, r); 1366 skge_write32(hw, B2_GP_IO, r);
1200 1367
1368 /* Enable GMII interface */
1369 xm_write16(hw, port, XM_HW_CFG, XM_HW_GMII_MD);
1370 }
1201 1371
1202 /* Enable GMII interface */
1203 xm_write16(hw, port, XM_HW_CFG, XM_HW_GMII_MD);
1204 1372
1205 bcom_phy_init(skge, jumbo); 1373 switch(hw->phy_type) {
1374 case SK_PHY_XMAC:
1375 xm_phy_init(skge);
1376 break;
1377 case SK_PHY_BCOM:
1378 bcom_phy_init(skge);
1379 bcom_check_link(hw, port);
1380 }
1206 1381
1207 /* Set Station Address */ 1382 /* Set Station Address */
1208 xm_outaddr(hw, port, XM_SA, dev->dev_addr); 1383 xm_outaddr(hw, port, XM_SA, dev->dev_addr);
@@ -1335,16 +1510,18 @@ static void genesis_stop(struct skge_port *skge)
1335 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_SET_MAC_RST); 1510 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_SET_MAC_RST);
1336 1511
1337 /* For external PHYs there must be special handling */ 1512 /* For external PHYs there must be special handling */
1338 reg = skge_read32(hw, B2_GP_IO); 1513 if (hw->phy_type != SK_PHY_XMAC) {
1339 if (port == 0) { 1514 reg = skge_read32(hw, B2_GP_IO);
1340 reg |= GP_DIR_0; 1515 if (port == 0) {
1341 reg &= ~GP_IO_0; 1516 reg |= GP_DIR_0;
1342 } else { 1517 reg &= ~GP_IO_0;
1343 reg |= GP_DIR_2; 1518 } else {
1344 reg &= ~GP_IO_2; 1519 reg |= GP_DIR_2;
1520 reg &= ~GP_IO_2;
1521 }
1522 skge_write32(hw, B2_GP_IO, reg);
1523 skge_read32(hw, B2_GP_IO);
1345 } 1524 }
1346 skge_write32(hw, B2_GP_IO, reg);
1347 skge_read32(hw, B2_GP_IO);
1348 1525
1349 xm_write16(hw, port, XM_MMU_CMD, 1526 xm_write16(hw, port, XM_MMU_CMD,
1350 xm_read16(hw, port, XM_MMU_CMD) 1527 xm_read16(hw, port, XM_MMU_CMD)
@@ -1406,7 +1583,7 @@ static void genesis_link_up(struct skge_port *skge)
1406 struct skge_hw *hw = skge->hw; 1583 struct skge_hw *hw = skge->hw;
1407 int port = skge->port; 1584 int port = skge->port;
1408 u16 cmd; 1585 u16 cmd;
1409 u32 mode, msk; 1586 u32 mode;
1410 1587
1411 cmd = xm_read16(hw, port, XM_MMU_CMD); 1588 cmd = xm_read16(hw, port, XM_MMU_CMD);
1412 1589
@@ -1454,27 +1631,24 @@ static void genesis_link_up(struct skge_port *skge)
1454 } 1631 }
1455 1632
1456 xm_write32(hw, port, XM_MODE, mode); 1633 xm_write32(hw, port, XM_MODE, mode);
1457 1634 xm_write16(hw, port, XM_IMSK, XM_DEF_MSK);
1458 msk = XM_DEF_MSK;
1459 /* disable GP0 interrupt bit for external Phy */
1460 msk |= XM_IS_INP_ASS;
1461
1462 xm_write16(hw, port, XM_IMSK, msk);
1463 xm_read16(hw, port, XM_ISRC); 1635 xm_read16(hw, port, XM_ISRC);
1464 1636
1465 /* get MMU Command Reg. */ 1637 /* get MMU Command Reg. */
1466 cmd = xm_read16(hw, port, XM_MMU_CMD); 1638 cmd = xm_read16(hw, port, XM_MMU_CMD);
1467 if (skge->duplex == DUPLEX_FULL) 1639 if (hw->phy_type != SK_PHY_XMAC && skge->duplex == DUPLEX_FULL)
1468 cmd |= XM_MMU_GMII_FD; 1640 cmd |= XM_MMU_GMII_FD;
1469 1641
1470 /* 1642 /*
1471 * Workaround BCOM Errata (#10523) for all BCom Phys 1643 * Workaround BCOM Errata (#10523) for all BCom Phys
1472 * Enable Power Management after link up 1644 * Enable Power Management after link up
1473 */ 1645 */
1474 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, 1646 if (hw->phy_type == SK_PHY_BCOM) {
1475 xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL) 1647 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL,
1476 & ~PHY_B_AC_DIS_PM); 1648 xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL)
1477 xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK); 1649 & ~PHY_B_AC_DIS_PM);
1650 xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK);
1651 }
1478 1652
1479 /* enable Rx/Tx */ 1653 /* enable Rx/Tx */
1480 xm_write16(hw, port, XM_MMU_CMD, 1654 xm_write16(hw, port, XM_MMU_CMD,
@@ -2240,6 +2414,8 @@ static int skge_down(struct net_device *dev)
2240 printk(KERN_INFO PFX "%s: disabling interface\n", dev->name); 2414 printk(KERN_INFO PFX "%s: disabling interface\n", dev->name);
2241 2415
2242 netif_stop_queue(dev); 2416 netif_stop_queue(dev);
2417 if (hw->chip_id == CHIP_ID_GENESIS && hw->phy_type == SK_PHY_XMAC)
2418 cancel_rearming_delayed_work(&skge->link_thread);
2243 2419
2244 skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_OFF); 2420 skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_OFF);
2245 if (hw->chip_id == CHIP_ID_GENESIS) 2421 if (hw->chip_id == CHIP_ID_GENESIS)
@@ -2862,7 +3038,7 @@ static void skge_extirq(void *arg)
2862 if (netif_running(dev)) { 3038 if (netif_running(dev)) {
2863 if (hw->chip_id != CHIP_ID_GENESIS) 3039 if (hw->chip_id != CHIP_ID_GENESIS)
2864 yukon_phy_intr(skge); 3040 yukon_phy_intr(skge);
2865 else 3041 else if (hw->phy_type == SK_PHY_BCOM)
2866 bcom_phy_intr(skge); 3042 bcom_phy_intr(skge);
2867 } 3043 }
2868 } 3044 }
@@ -3014,7 +3190,7 @@ static int skge_reset(struct skge_hw *hw)
3014{ 3190{
3015 u32 reg; 3191 u32 reg;
3016 u16 ctst, pci_status; 3192 u16 ctst, pci_status;
3017 u8 t8, mac_cfg, pmd_type, phy_type; 3193 u8 t8, mac_cfg, pmd_type;
3018 int i; 3194 int i;
3019 3195
3020 ctst = skge_read16(hw, B0_CTST); 3196 ctst = skge_read16(hw, B0_CTST);
@@ -3038,19 +3214,22 @@ static int skge_reset(struct skge_hw *hw)
3038 ctst & (CS_CLK_RUN_HOT|CS_CLK_RUN_RST|CS_CLK_RUN_ENA)); 3214 ctst & (CS_CLK_RUN_HOT|CS_CLK_RUN_RST|CS_CLK_RUN_ENA));
3039 3215
3040 hw->chip_id = skge_read8(hw, B2_CHIP_ID); 3216 hw->chip_id = skge_read8(hw, B2_CHIP_ID);
3041 phy_type = skge_read8(hw, B2_E_1) & 0xf; 3217 hw->phy_type = skge_read8(hw, B2_E_1) & 0xf;
3042 pmd_type = skge_read8(hw, B2_PMD_TYP); 3218 pmd_type = skge_read8(hw, B2_PMD_TYP);
3043 hw->copper = (pmd_type == 'T' || pmd_type == '1'); 3219 hw->copper = (pmd_type == 'T' || pmd_type == '1');
3044 3220
3045 switch (hw->chip_id) { 3221 switch (hw->chip_id) {
3046 case CHIP_ID_GENESIS: 3222 case CHIP_ID_GENESIS:
3047 switch (phy_type) { 3223 switch (hw->phy_type) {
3224 case SK_PHY_XMAC:
3225 hw->phy_addr = PHY_ADDR_XMAC;
3226 break;
3048 case SK_PHY_BCOM: 3227 case SK_PHY_BCOM:
3049 hw->phy_addr = PHY_ADDR_BCOM; 3228 hw->phy_addr = PHY_ADDR_BCOM;
3050 break; 3229 break;
3051 default: 3230 default:
3052 printk(KERN_ERR PFX "%s: unsupported phy type 0x%x\n", 3231 printk(KERN_ERR PFX "%s: unsupported phy type 0x%x\n",
3053 pci_name(hw->pdev), phy_type); 3232 pci_name(hw->pdev), hw->phy_type);
3054 return -EOPNOTSUPP; 3233 return -EOPNOTSUPP;
3055 } 3234 }
3056 break; 3235 break;
@@ -3058,7 +3237,7 @@ static int skge_reset(struct skge_hw *hw)
3058 case CHIP_ID_YUKON: 3237 case CHIP_ID_YUKON:
3059 case CHIP_ID_YUKON_LITE: 3238 case CHIP_ID_YUKON_LITE:
3060 case CHIP_ID_YUKON_LP: 3239 case CHIP_ID_YUKON_LP:
3061 if (phy_type < SK_PHY_MARV_COPPER && pmd_type != 'S') 3240 if (hw->phy_type < SK_PHY_MARV_COPPER && pmd_type != 'S')
3062 hw->copper = 1; 3241 hw->copper = 1;
3063 3242
3064 hw->phy_addr = PHY_ADDR_MARV; 3243 hw->phy_addr = PHY_ADDR_MARV;
@@ -3089,10 +3268,13 @@ static int skge_reset(struct skge_hw *hw)
3089 else 3268 else
3090 hw->ram_size = t8 * 4096; 3269 hw->ram_size = t8 * 4096;
3091 3270
3092 hw->intr_mask = IS_HW_ERR | IS_EXT_REG | IS_PORT_1; 3271 hw->intr_mask = IS_HW_ERR | IS_PORT_1;
3093 if (hw->ports > 1) 3272 if (hw->ports > 1)
3094 hw->intr_mask |= IS_PORT_2; 3273 hw->intr_mask |= IS_PORT_2;
3095 3274
3275 if (!(hw->chip_id == CHIP_ID_GENESIS && hw->phy_type == SK_PHY_XMAC))
3276 hw->intr_mask |= IS_EXT_REG;
3277
3096 if (hw->chip_id == CHIP_ID_GENESIS) 3278 if (hw->chip_id == CHIP_ID_GENESIS)
3097 genesis_init(hw); 3279 genesis_init(hw);
3098 else { 3280 else {
@@ -3226,6 +3408,9 @@ static struct net_device *skge_devinit(struct skge_hw *hw, int port,
3226 3408
3227 skge->port = port; 3409 skge->port = port;
3228 3410
3411 /* Only used for Genesis XMAC */
3412 INIT_WORK(&skge->link_thread, xm_link_timer, dev);
3413
3229 if (hw->chip_id != CHIP_ID_GENESIS) { 3414 if (hw->chip_id != CHIP_ID_GENESIS) {
3230 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG; 3415 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
3231 skge->rx_csum = 1; 3416 skge->rx_csum = 1;
diff --git a/drivers/net/skge.h b/drivers/net/skge.h
index 79e09271bcf9..d0b47d46cf9d 100644
--- a/drivers/net/skge.h
+++ b/drivers/net/skge.h
@@ -934,7 +934,7 @@ enum {
934 PHY_XMAC_AUNE_ADV = 0x04,/* 16 bit r/w Auto-Neg. Advertisement */ 934 PHY_XMAC_AUNE_ADV = 0x04,/* 16 bit r/w Auto-Neg. Advertisement */
935 PHY_XMAC_AUNE_LP = 0x05,/* 16 bit r/o Link Partner Abi Reg */ 935 PHY_XMAC_AUNE_LP = 0x05,/* 16 bit r/o Link Partner Abi Reg */
936 PHY_XMAC_AUNE_EXP = 0x06,/* 16 bit r/o Auto-Neg. Expansion Reg */ 936 PHY_XMAC_AUNE_EXP = 0x06,/* 16 bit r/o Auto-Neg. Expansion Reg */
937 PHY_XMAC_NEPG = 0x07,/* 16 bit r/w Next Page Register */ 937 PHY_XMAC_NEPG = 0x07,/* 16 bit r/w Next Page Register */
938 PHY_XMAC_NEPG_LP = 0x08,/* 16 bit r/o Next Page Link Partner */ 938 PHY_XMAC_NEPG_LP = 0x08,/* 16 bit r/o Next Page Link Partner */
939 939
940 PHY_XMAC_EXT_STAT = 0x0f,/* 16 bit r/o Ext Status Register */ 940 PHY_XMAC_EXT_STAT = 0x0f,/* 16 bit r/o Ext Status Register */
@@ -1097,13 +1097,36 @@ enum {
1097 1097
1098/* Pause Bits (PHY_X_AN_PAUSE and PHY_X_RS_PAUSE) encoding */ 1098/* Pause Bits (PHY_X_AN_PAUSE and PHY_X_RS_PAUSE) encoding */
1099enum { 1099enum {
1100 PHY_X_P_NO_PAUSE = 0<<7,/* Bit 8..7: no Pause Mode */ 1100 PHY_X_P_NO_PAUSE= 0<<7,/* Bit 8..7: no Pause Mode */
1101 PHY_X_P_SYM_MD = 1<<7, /* Bit 8..7: symmetric Pause Mode */ 1101 PHY_X_P_SYM_MD = 1<<7, /* Bit 8..7: symmetric Pause Mode */
1102 PHY_X_P_ASYM_MD = 2<<7,/* Bit 8..7: asymmetric Pause Mode */ 1102 PHY_X_P_ASYM_MD = 2<<7,/* Bit 8..7: asymmetric Pause Mode */
1103 PHY_X_P_BOTH_MD = 3<<7,/* Bit 8..7: both Pause Mode */ 1103 PHY_X_P_BOTH_MD = 3<<7,/* Bit 8..7: both Pause Mode */
1104}; 1104};
1105 1105
1106 1106
1107/***** PHY_XMAC_EXT_STAT 16 bit r/w Extended Status Register *****/
1108enum {
1109 PHY_X_EX_FD = 1<<15, /* Bit 15: Device Supports Full Duplex */
1110 PHY_X_EX_HD = 1<<14, /* Bit 14: Device Supports Half Duplex */
1111};
1112
1113/***** PHY_XMAC_RES_ABI 16 bit r/o PHY Resolved Ability *****/
1114enum {
1115 PHY_X_RS_PAUSE = 3<<7, /* Bit 8..7: selected Pause Mode */
1116 PHY_X_RS_HD = 1<<6, /* Bit 6: Half Duplex Mode selected */
1117 PHY_X_RS_FD = 1<<5, /* Bit 5: Full Duplex Mode selected */
1118 PHY_X_RS_ABLMIS = 1<<4, /* Bit 4: duplex or pause cap mismatch */
1119 PHY_X_RS_PAUMIS = 1<<3, /* Bit 3: pause capability mismatch */
1120};
1121
1122/* Remote Fault Bits (PHY_X_AN_RFB) encoding */
1123enum {
1124 X_RFB_OK = 0<<12,/* Bit 13..12 No errors, Link OK */
1125 X_RFB_LF = 1<<12,/* Bit 13..12 Link Failure */
1126 X_RFB_OFF = 2<<12,/* Bit 13..12 Offline */
1127 X_RFB_AN_ERR = 3<<12,/* Bit 13..12 Auto-Negotiation Error */
1128};
1129
1107/* Broadcom-Specific */ 1130/* Broadcom-Specific */
1108/***** PHY_BCOM_1000T_CTRL 16 bit r/w 1000Base-T Control Reg *****/ 1131/***** PHY_BCOM_1000T_CTRL 16 bit r/w 1000Base-T Control Reg *****/
1109enum { 1132enum {
@@ -2158,8 +2181,8 @@ enum {
2158 XM_IS_LNK_AE = 1<<14, /* Bit 14: Link Asynchronous Event */ 2181 XM_IS_LNK_AE = 1<<14, /* Bit 14: Link Asynchronous Event */
2159 XM_IS_TX_ABORT = 1<<13, /* Bit 13: Transmit Abort, late Col. etc */ 2182 XM_IS_TX_ABORT = 1<<13, /* Bit 13: Transmit Abort, late Col. etc */
2160 XM_IS_FRC_INT = 1<<12, /* Bit 12: Force INT bit set in GP */ 2183 XM_IS_FRC_INT = 1<<12, /* Bit 12: Force INT bit set in GP */
2161 XM_IS_INP_ASS = 1<<11, /* Bit 11: Input Asserted, GP bit 0 set */ 2184 XM_IS_INP_ASS = 1<<11, /* Bit 11: Input Asserted, GP bit 0 set */
2162 XM_IS_LIPA_RC = 1<<10, /* Bit 10: Link Partner requests config */ 2185 XM_IS_LIPA_RC = 1<<10, /* Bit 10: Link Partner requests config */
2163 XM_IS_RX_PAGE = 1<<9, /* Bit 9: Page Received */ 2186 XM_IS_RX_PAGE = 1<<9, /* Bit 9: Page Received */
2164 XM_IS_TX_PAGE = 1<<8, /* Bit 8: Next Page Loaded for Transmit */ 2187 XM_IS_TX_PAGE = 1<<8, /* Bit 8: Next Page Loaded for Transmit */
2165 XM_IS_AND = 1<<7, /* Bit 7: Auto-Negotiation Done */ 2188 XM_IS_AND = 1<<7, /* Bit 7: Auto-Negotiation Done */
@@ -2172,9 +2195,7 @@ enum {
2172 XM_IS_RX_COMP = 1<<0, /* Bit 0: Frame Rx Complete */ 2195 XM_IS_RX_COMP = 1<<0, /* Bit 0: Frame Rx Complete */
2173}; 2196};
2174 2197
2175#define XM_DEF_MSK (~(XM_IS_INP_ASS | XM_IS_LIPA_RC | XM_IS_RX_PAGE | \ 2198#define XM_DEF_MSK (~(XM_IS_RXC_OV | XM_IS_TXC_OV | XM_IS_RXF_OV | XM_IS_TXF_UR))
2176 XM_IS_AND | XM_IS_RXC_OV | XM_IS_TXC_OV | \
2177 XM_IS_RXF_OV | XM_IS_TXF_UR))
2178 2199
2179 2200
2180/* XM_HW_CFG 16 bit r/w Hardware Config Register */ 2201/* XM_HW_CFG 16 bit r/w Hardware Config Register */
@@ -2396,6 +2417,7 @@ struct skge_hw {
2396 u8 chip_rev; 2417 u8 chip_rev;
2397 u8 copper; 2418 u8 copper;
2398 u8 ports; 2419 u8 ports;
2420 u8 phy_type;
2399 2421
2400 u32 ram_size; 2422 u32 ram_size;
2401 u32 ram_offset; 2423 u32 ram_offset;
@@ -2422,6 +2444,7 @@ struct skge_port {
2422 2444
2423 struct net_device_stats net_stats; 2445 struct net_device_stats net_stats;
2424 2446
2447 struct work_struct link_thread;
2425 u8 rx_csum; 2448 u8 rx_csum;
2426 u8 blink_on; 2449 u8 blink_on;
2427 u8 flow_control; 2450 u8 flow_control;
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index 7eeefa2d6c89..396e7df3c61b 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -50,19 +50,18 @@
50#include "sky2.h" 50#include "sky2.h"
51 51
52#define DRV_NAME "sky2" 52#define DRV_NAME "sky2"
53#define DRV_VERSION "1.7" 53#define DRV_VERSION "1.9"
54#define PFX DRV_NAME " " 54#define PFX DRV_NAME " "
55 55
56/* 56/*
57 * The Yukon II chipset takes 64 bit command blocks (called list elements) 57 * The Yukon II chipset takes 64 bit command blocks (called list elements)
58 * that are organized into three (receive, transmit, status) different rings 58 * that are organized into three (receive, transmit, status) different rings
59 * similar to Tigon3. A transmit can require several elements; 59 * similar to Tigon3.
60 * a receive requires one (or two if using 64 bit dma).
61 */ 60 */
62 61
63#define RX_LE_SIZE 512 62#define RX_LE_SIZE 1024
64#define RX_LE_BYTES (RX_LE_SIZE*sizeof(struct sky2_rx_le)) 63#define RX_LE_BYTES (RX_LE_SIZE*sizeof(struct sky2_rx_le))
65#define RX_MAX_PENDING (RX_LE_SIZE/2 - 2) 64#define RX_MAX_PENDING (RX_LE_SIZE/6 - 2)
66#define RX_DEF_PENDING RX_MAX_PENDING 65#define RX_DEF_PENDING RX_MAX_PENDING
67#define RX_SKB_ALIGN 8 66#define RX_SKB_ALIGN 8
68#define RX_BUF_WRITE 16 67#define RX_BUF_WRITE 16
@@ -74,7 +73,6 @@
74 73
75#define STATUS_RING_SIZE 2048 /* 2 ports * (TX + 2*RX) */ 74#define STATUS_RING_SIZE 2048 /* 2 ports * (TX + 2*RX) */
76#define STATUS_LE_BYTES (STATUS_RING_SIZE*sizeof(struct sky2_status_le)) 75#define STATUS_LE_BYTES (STATUS_RING_SIZE*sizeof(struct sky2_status_le))
77#define ETH_JUMBO_MTU 9000
78#define TX_WATCHDOG (5 * HZ) 76#define TX_WATCHDOG (5 * HZ)
79#define NAPI_WEIGHT 64 77#define NAPI_WEIGHT 64
80#define PHY_RETRIES 1000 78#define PHY_RETRIES 1000
@@ -90,7 +88,7 @@ static int debug = -1; /* defaults above */
90module_param(debug, int, 0); 88module_param(debug, int, 0);
91MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); 89MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
92 90
93static int copybreak __read_mostly = 256; 91static int copybreak __read_mostly = 128;
94module_param(copybreak, int, 0); 92module_param(copybreak, int, 0);
95MODULE_PARM_DESC(copybreak, "Receive copy threshold"); 93MODULE_PARM_DESC(copybreak, "Receive copy threshold");
96 94
@@ -769,9 +767,16 @@ static inline struct sky2_tx_le *get_tx_le(struct sky2_port *sky2)
769 struct sky2_tx_le *le = sky2->tx_le + sky2->tx_prod; 767 struct sky2_tx_le *le = sky2->tx_le + sky2->tx_prod;
770 768
771 sky2->tx_prod = RING_NEXT(sky2->tx_prod, TX_RING_SIZE); 769 sky2->tx_prod = RING_NEXT(sky2->tx_prod, TX_RING_SIZE);
770 le->ctrl = 0;
772 return le; 771 return le;
773} 772}
774 773
774static inline struct tx_ring_info *tx_le_re(struct sky2_port *sky2,
775 struct sky2_tx_le *le)
776{
777 return sky2->tx_ring + (le - sky2->tx_le);
778}
779
775/* Update chip's next pointer */ 780/* Update chip's next pointer */
776static inline void sky2_put_idx(struct sky2_hw *hw, unsigned q, u16 idx) 781static inline void sky2_put_idx(struct sky2_hw *hw, unsigned q, u16 idx)
777{ 782{
@@ -786,6 +791,7 @@ static inline struct sky2_rx_le *sky2_next_rx(struct sky2_port *sky2)
786{ 791{
787 struct sky2_rx_le *le = sky2->rx_le + sky2->rx_put; 792 struct sky2_rx_le *le = sky2->rx_le + sky2->rx_put;
788 sky2->rx_put = RING_NEXT(sky2->rx_put, RX_LE_SIZE); 793 sky2->rx_put = RING_NEXT(sky2->rx_put, RX_LE_SIZE);
794 le->ctrl = 0;
789 return le; 795 return le;
790} 796}
791 797
@@ -795,17 +801,16 @@ static inline u32 high32(dma_addr_t a)
795 return sizeof(a) > sizeof(u32) ? (a >> 16) >> 16 : 0; 801 return sizeof(a) > sizeof(u32) ? (a >> 16) >> 16 : 0;
796} 802}
797 803
798/* Build description to hardware about buffer */ 804/* Build description to hardware for one receive segment */
799static void sky2_rx_add(struct sky2_port *sky2, dma_addr_t map) 805static void sky2_rx_add(struct sky2_port *sky2, u8 op,
806 dma_addr_t map, unsigned len)
800{ 807{
801 struct sky2_rx_le *le; 808 struct sky2_rx_le *le;
802 u32 hi = high32(map); 809 u32 hi = high32(map);
803 u16 len = sky2->rx_bufsize;
804 810
805 if (sky2->rx_addr64 != hi) { 811 if (sky2->rx_addr64 != hi) {
806 le = sky2_next_rx(sky2); 812 le = sky2_next_rx(sky2);
807 le->addr = cpu_to_le32(hi); 813 le->addr = cpu_to_le32(hi);
808 le->ctrl = 0;
809 le->opcode = OP_ADDR64 | HW_OWNER; 814 le->opcode = OP_ADDR64 | HW_OWNER;
810 sky2->rx_addr64 = high32(map + len); 815 sky2->rx_addr64 = high32(map + len);
811 } 816 }
@@ -813,11 +818,53 @@ static void sky2_rx_add(struct sky2_port *sky2, dma_addr_t map)
813 le = sky2_next_rx(sky2); 818 le = sky2_next_rx(sky2);
814 le->addr = cpu_to_le32((u32) map); 819 le->addr = cpu_to_le32((u32) map);
815 le->length = cpu_to_le16(len); 820 le->length = cpu_to_le16(len);
816 le->ctrl = 0; 821 le->opcode = op | HW_OWNER;
817 le->opcode = OP_PACKET | HW_OWNER; 822}
823
824/* Build description to hardware for one possibly fragmented skb */
825static void sky2_rx_submit(struct sky2_port *sky2,
826 const struct rx_ring_info *re)
827{
828 int i;
829
830 sky2_rx_add(sky2, OP_PACKET, re->data_addr, sky2->rx_data_size);
831
832 for (i = 0; i < skb_shinfo(re->skb)->nr_frags; i++)
833 sky2_rx_add(sky2, OP_BUFFER, re->frag_addr[i], PAGE_SIZE);
818} 834}
819 835
820 836
837static void sky2_rx_map_skb(struct pci_dev *pdev, struct rx_ring_info *re,
838 unsigned size)
839{
840 struct sk_buff *skb = re->skb;
841 int i;
842
843 re->data_addr = pci_map_single(pdev, skb->data, size, PCI_DMA_FROMDEVICE);
844 pci_unmap_len_set(re, data_size, size);
845
846 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
847 re->frag_addr[i] = pci_map_page(pdev,
848 skb_shinfo(skb)->frags[i].page,
849 skb_shinfo(skb)->frags[i].page_offset,
850 skb_shinfo(skb)->frags[i].size,
851 PCI_DMA_FROMDEVICE);
852}
853
854static void sky2_rx_unmap_skb(struct pci_dev *pdev, struct rx_ring_info *re)
855{
856 struct sk_buff *skb = re->skb;
857 int i;
858
859 pci_unmap_single(pdev, re->data_addr, pci_unmap_len(re, data_size),
860 PCI_DMA_FROMDEVICE);
861
862 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
863 pci_unmap_page(pdev, re->frag_addr[i],
864 skb_shinfo(skb)->frags[i].size,
865 PCI_DMA_FROMDEVICE);
866}
867
821/* Tell chip where to start receive checksum. 868/* Tell chip where to start receive checksum.
822 * Actually has two checksums, but set both same to avoid possible byte 869 * Actually has two checksums, but set both same to avoid possible byte
823 * order problems. 870 * order problems.
@@ -877,12 +924,10 @@ static void sky2_rx_clean(struct sky2_port *sky2)
877 924
878 memset(sky2->rx_le, 0, RX_LE_BYTES); 925 memset(sky2->rx_le, 0, RX_LE_BYTES);
879 for (i = 0; i < sky2->rx_pending; i++) { 926 for (i = 0; i < sky2->rx_pending; i++) {
880 struct ring_info *re = sky2->rx_ring + i; 927 struct rx_ring_info *re = sky2->rx_ring + i;
881 928
882 if (re->skb) { 929 if (re->skb) {
883 pci_unmap_single(sky2->hw->pdev, 930 sky2_rx_unmap_skb(sky2->hw->pdev, re);
884 re->mapaddr, sky2->rx_bufsize,
885 PCI_DMA_FROMDEVICE);
886 kfree_skb(re->skb); 931 kfree_skb(re->skb);
887 re->skb = NULL; 932 re->skb = NULL;
888 } 933 }
@@ -936,13 +981,13 @@ static void sky2_vlan_rx_register(struct net_device *dev, struct vlan_group *grp
936 struct sky2_hw *hw = sky2->hw; 981 struct sky2_hw *hw = sky2->hw;
937 u16 port = sky2->port; 982 u16 port = sky2->port;
938 983
939 spin_lock_bh(&sky2->tx_lock); 984 netif_tx_lock_bh(dev);
940 985
941 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), RX_VLAN_STRIP_ON); 986 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), RX_VLAN_STRIP_ON);
942 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_VLAN_TAG_ON); 987 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_VLAN_TAG_ON);
943 sky2->vlgrp = grp; 988 sky2->vlgrp = grp;
944 989
945 spin_unlock_bh(&sky2->tx_lock); 990 netif_tx_unlock_bh(dev);
946} 991}
947 992
948static void sky2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid) 993static void sky2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
@@ -951,50 +996,69 @@ static void sky2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
951 struct sky2_hw *hw = sky2->hw; 996 struct sky2_hw *hw = sky2->hw;
952 u16 port = sky2->port; 997 u16 port = sky2->port;
953 998
954 spin_lock_bh(&sky2->tx_lock); 999 netif_tx_lock_bh(dev);
955 1000
956 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), RX_VLAN_STRIP_OFF); 1001 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), RX_VLAN_STRIP_OFF);
957 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_VLAN_TAG_OFF); 1002 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_VLAN_TAG_OFF);
958 if (sky2->vlgrp) 1003 if (sky2->vlgrp)
959 sky2->vlgrp->vlan_devices[vid] = NULL; 1004 sky2->vlgrp->vlan_devices[vid] = NULL;
960 1005
961 spin_unlock_bh(&sky2->tx_lock); 1006 netif_tx_unlock_bh(dev);
962} 1007}
963#endif 1008#endif
964 1009
965/* 1010/*
1011 * Allocate an skb for receiving. If the MTU is large enough
1012 * make the skb non-linear with a fragment list of pages.
1013 *
966 * It appears the hardware has a bug in the FIFO logic that 1014 * It appears the hardware has a bug in the FIFO logic that
967 * cause it to hang if the FIFO gets overrun and the receive buffer 1015 * cause it to hang if the FIFO gets overrun and the receive buffer
968 * is not 64 byte aligned. The buffer returned from netdev_alloc_skb is 1016 * is not 64 byte aligned. The buffer returned from netdev_alloc_skb is
969 * aligned except if slab debugging is enabled. 1017 * aligned except if slab debugging is enabled.
970 */ 1018 */
971static inline struct sk_buff *sky2_alloc_skb(struct net_device *dev, 1019static struct sk_buff *sky2_rx_alloc(struct sky2_port *sky2)
972 unsigned int length,
973 gfp_t gfp_mask)
974{ 1020{
975 struct sk_buff *skb; 1021 struct sk_buff *skb;
1022 unsigned long p;
1023 int i;
976 1024
977 skb = __netdev_alloc_skb(dev, length + RX_SKB_ALIGN, gfp_mask); 1025 skb = netdev_alloc_skb(sky2->netdev, sky2->rx_data_size + RX_SKB_ALIGN);
978 if (likely(skb)) { 1026 if (!skb)
979 unsigned long p = (unsigned long) skb->data; 1027 goto nomem;
980 skb_reserve(skb, ALIGN(p, RX_SKB_ALIGN) - p); 1028
1029 p = (unsigned long) skb->data;
1030 skb_reserve(skb, ALIGN(p, RX_SKB_ALIGN) - p);
1031
1032 for (i = 0; i < sky2->rx_nfrags; i++) {
1033 struct page *page = alloc_page(GFP_ATOMIC);
1034
1035 if (!page)
1036 goto free_partial;
1037 skb_fill_page_desc(skb, i, page, 0, PAGE_SIZE);
981 } 1038 }
982 1039
983 return skb; 1040 return skb;
1041free_partial:
1042 kfree_skb(skb);
1043nomem:
1044 return NULL;
984} 1045}
985 1046
986/* 1047/*
987 * Allocate and setup receiver buffer pool. 1048 * Allocate and setup receiver buffer pool.
988 * In case of 64 bit dma, there are 2X as many list elements 1049 * Normal case this ends up creating one list element for skb
989 * available as ring entries 1050 * in the receive ring. Worst case if using large MTU and each
990 * and need to reserve one list element so we don't wrap around. 1051 * allocation falls on a different 64 bit region, that results
1052 * in 6 list elements per ring entry.
1053 * One element is used for checksum enable/disable, and one
1054 * extra to avoid wrap.
991 */ 1055 */
992static int sky2_rx_start(struct sky2_port *sky2) 1056static int sky2_rx_start(struct sky2_port *sky2)
993{ 1057{
994 struct sky2_hw *hw = sky2->hw; 1058 struct sky2_hw *hw = sky2->hw;
1059 struct rx_ring_info *re;
995 unsigned rxq = rxqaddr[sky2->port]; 1060 unsigned rxq = rxqaddr[sky2->port];
996 int i; 1061 unsigned i, size, space, thresh;
997 unsigned thresh;
998 1062
999 sky2->rx_put = sky2->rx_next = 0; 1063 sky2->rx_put = sky2->rx_next = 0;
1000 sky2_qset(hw, rxq); 1064 sky2_qset(hw, rxq);
@@ -1007,27 +1071,56 @@ static int sky2_rx_start(struct sky2_port *sky2)
1007 sky2_prefetch_init(hw, rxq, sky2->rx_le_map, RX_LE_SIZE - 1); 1071 sky2_prefetch_init(hw, rxq, sky2->rx_le_map, RX_LE_SIZE - 1);
1008 1072
1009 rx_set_checksum(sky2); 1073 rx_set_checksum(sky2);
1074
1075 /* Space needed for frame data + headers rounded up */
1076 size = ALIGN(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8)
1077 + 8;
1078
1079 /* Stopping point for hardware truncation */
1080 thresh = (size - 8) / sizeof(u32);
1081
1082 /* Account for overhead of skb - to avoid order > 0 allocation */
1083 space = SKB_DATA_ALIGN(size) + NET_SKB_PAD
1084 + sizeof(struct skb_shared_info);
1085
1086 sky2->rx_nfrags = space >> PAGE_SHIFT;
1087 BUG_ON(sky2->rx_nfrags > ARRAY_SIZE(re->frag_addr));
1088
1089 if (sky2->rx_nfrags != 0) {
1090 /* Compute residue after pages */
1091 space = sky2->rx_nfrags << PAGE_SHIFT;
1092
1093 if (space < size)
1094 size -= space;
1095 else
1096 size = 0;
1097
1098 /* Optimize to handle small packets and headers */
1099 if (size < copybreak)
1100 size = copybreak;
1101 if (size < ETH_HLEN)
1102 size = ETH_HLEN;
1103 }
1104 sky2->rx_data_size = size;
1105
1106 /* Fill Rx ring */
1010 for (i = 0; i < sky2->rx_pending; i++) { 1107 for (i = 0; i < sky2->rx_pending; i++) {
1011 struct ring_info *re = sky2->rx_ring + i; 1108 re = sky2->rx_ring + i;
1012 1109
1013 re->skb = sky2_alloc_skb(sky2->netdev, sky2->rx_bufsize, 1110 re->skb = sky2_rx_alloc(sky2);
1014 GFP_KERNEL);
1015 if (!re->skb) 1111 if (!re->skb)
1016 goto nomem; 1112 goto nomem;
1017 1113
1018 re->mapaddr = pci_map_single(hw->pdev, re->skb->data, 1114 sky2_rx_map_skb(hw->pdev, re, sky2->rx_data_size);
1019 sky2->rx_bufsize, PCI_DMA_FROMDEVICE); 1115 sky2_rx_submit(sky2, re);
1020 sky2_rx_add(sky2, re->mapaddr);
1021 } 1116 }
1022 1117
1023
1024 /* 1118 /*
1025 * The receiver hangs if it receives frames larger than the 1119 * The receiver hangs if it receives frames larger than the
1026 * packet buffer. As a workaround, truncate oversize frames, but 1120 * packet buffer. As a workaround, truncate oversize frames, but
1027 * the register is limited to 9 bits, so if you do frames > 2052 1121 * the register is limited to 9 bits, so if you do frames > 2052
1028 * you better get the MTU right! 1122 * you better get the MTU right!
1029 */ 1123 */
1030 thresh = (sky2->rx_bufsize - 8) / sizeof(u32);
1031 if (thresh > 0x1ff) 1124 if (thresh > 0x1ff)
1032 sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_OFF); 1125 sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_OFF);
1033 else { 1126 else {
@@ -1035,7 +1128,6 @@ static int sky2_rx_start(struct sky2_port *sky2)
1035 sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_ON); 1128 sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_ON);
1036 } 1129 }
1037 1130
1038
1039 /* Tell chip about available buffers */ 1131 /* Tell chip about available buffers */
1040 sky2_write16(hw, Y2_QADDR(rxq, PREF_UNIT_PUT_IDX), sky2->rx_put); 1132 sky2_write16(hw, Y2_QADDR(rxq, PREF_UNIT_PUT_IDX), sky2->rx_put);
1041 return 0; 1133 return 0;
@@ -1094,7 +1186,7 @@ static int sky2_up(struct net_device *dev)
1094 goto err_out; 1186 goto err_out;
1095 memset(sky2->rx_le, 0, RX_LE_BYTES); 1187 memset(sky2->rx_le, 0, RX_LE_BYTES);
1096 1188
1097 sky2->rx_ring = kcalloc(sky2->rx_pending, sizeof(struct ring_info), 1189 sky2->rx_ring = kcalloc(sky2->rx_pending, sizeof(struct rx_ring_info),
1098 GFP_KERNEL); 1190 GFP_KERNEL);
1099 if (!sky2->rx_ring) 1191 if (!sky2->rx_ring)
1100 goto err_out; 1192 goto err_out;
@@ -1124,7 +1216,8 @@ static int sky2_up(struct net_device *dev)
1124 sky2_qset(hw, txqaddr[port]); 1216 sky2_qset(hw, txqaddr[port]);
1125 1217
1126 /* Set almost empty threshold */ 1218 /* Set almost empty threshold */
1127 if (hw->chip_id == CHIP_ID_YUKON_EC_U && hw->chip_rev == 1) 1219 if (hw->chip_id == CHIP_ID_YUKON_EC_U
1220 && hw->chip_rev == CHIP_REV_YU_EC_U_A0)
1128 sky2_write16(hw, Q_ADDR(txqaddr[port], Q_AL), 0x1a0); 1221 sky2_write16(hw, Q_ADDR(txqaddr[port], Q_AL), 0x1a0);
1129 1222
1130 sky2_prefetch_init(hw, txqaddr[port], sky2->tx_le_map, 1223 sky2_prefetch_init(hw, txqaddr[port], sky2->tx_le_map,
@@ -1195,8 +1288,6 @@ static unsigned tx_le_req(const struct sk_buff *skb)
1195 * A single packet can generate multiple list elements, and 1288 * A single packet can generate multiple list elements, and
1196 * the number of ring elements will probably be less than the number 1289 * the number of ring elements will probably be less than the number
1197 * of list elements used. 1290 * of list elements used.
1198 *
1199 * No BH disabling for tx_lock here (like tg3)
1200 */ 1291 */
1201static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev) 1292static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
1202{ 1293{
@@ -1210,27 +1301,8 @@ static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
1210 u16 mss; 1301 u16 mss;
1211 u8 ctrl; 1302 u8 ctrl;
1212 1303
1213 /* No BH disabling for tx_lock here. We are running in BH disabled 1304 if (unlikely(tx_avail(sky2) < tx_le_req(skb)))
1214 * context and TX reclaim runs via poll inside of a software 1305 return NETDEV_TX_BUSY;
1215 * interrupt, and no related locks in IRQ processing.
1216 */
1217 if (!spin_trylock(&sky2->tx_lock))
1218 return NETDEV_TX_LOCKED;
1219
1220 if (unlikely(tx_avail(sky2) < tx_le_req(skb))) {
1221 /* There is a known but harmless race with lockless tx
1222 * and netif_stop_queue.
1223 */
1224 if (!netif_queue_stopped(dev)) {
1225 netif_stop_queue(dev);
1226 if (net_ratelimit())
1227 printk(KERN_WARNING PFX "%s: ring full when queue awake!\n",
1228 dev->name);
1229 }
1230 spin_unlock(&sky2->tx_lock);
1231
1232 return NETDEV_TX_BUSY;
1233 }
1234 1306
1235 if (unlikely(netif_msg_tx_queued(sky2))) 1307 if (unlikely(netif_msg_tx_queued(sky2)))
1236 printk(KERN_DEBUG "%s: tx queued, slot %u, len %d\n", 1308 printk(KERN_DEBUG "%s: tx queued, slot %u, len %d\n",
@@ -1240,13 +1312,10 @@ static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
1240 mapping = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE); 1312 mapping = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE);
1241 addr64 = high32(mapping); 1313 addr64 = high32(mapping);
1242 1314
1243 re = sky2->tx_ring + sky2->tx_prod;
1244
1245 /* Send high bits if changed or crosses boundary */ 1315 /* Send high bits if changed or crosses boundary */
1246 if (addr64 != sky2->tx_addr64 || high32(mapping + len) != sky2->tx_addr64) { 1316 if (addr64 != sky2->tx_addr64 || high32(mapping + len) != sky2->tx_addr64) {
1247 le = get_tx_le(sky2); 1317 le = get_tx_le(sky2);
1248 le->addr = cpu_to_le32(addr64); 1318 le->addr = cpu_to_le32(addr64);
1249 le->ctrl = 0;
1250 le->opcode = OP_ADDR64 | HW_OWNER; 1319 le->opcode = OP_ADDR64 | HW_OWNER;
1251 sky2->tx_addr64 = high32(mapping + len); 1320 sky2->tx_addr64 = high32(mapping + len);
1252 } 1321 }
@@ -1262,7 +1331,6 @@ static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
1262 le = get_tx_le(sky2); 1331 le = get_tx_le(sky2);
1263 le->addr = cpu_to_le32(mss); 1332 le->addr = cpu_to_le32(mss);
1264 le->opcode = OP_LRGLEN | HW_OWNER; 1333 le->opcode = OP_LRGLEN | HW_OWNER;
1265 le->ctrl = 0;
1266 sky2->tx_last_mss = mss; 1334 sky2->tx_last_mss = mss;
1267 } 1335 }
1268 } 1336 }
@@ -1275,7 +1343,6 @@ static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
1275 le = get_tx_le(sky2); 1343 le = get_tx_le(sky2);
1276 le->addr = 0; 1344 le->addr = 0;
1277 le->opcode = OP_VLAN|HW_OWNER; 1345 le->opcode = OP_VLAN|HW_OWNER;
1278 le->ctrl = 0;
1279 } else 1346 } else
1280 le->opcode |= OP_VLAN; 1347 le->opcode |= OP_VLAN;
1281 le->length = cpu_to_be16(vlan_tx_tag_get(skb)); 1348 le->length = cpu_to_be16(vlan_tx_tag_get(skb));
@@ -1312,13 +1379,13 @@ static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
1312 le->ctrl = ctrl; 1379 le->ctrl = ctrl;
1313 le->opcode = mss ? (OP_LARGESEND | HW_OWNER) : (OP_PACKET | HW_OWNER); 1380 le->opcode = mss ? (OP_LARGESEND | HW_OWNER) : (OP_PACKET | HW_OWNER);
1314 1381
1315 /* Record the transmit mapping info */ 1382 re = tx_le_re(sky2, le);
1316 re->skb = skb; 1383 re->skb = skb;
1317 pci_unmap_addr_set(re, mapaddr, mapping); 1384 pci_unmap_addr_set(re, mapaddr, mapping);
1385 pci_unmap_len_set(re, maplen, len);
1318 1386
1319 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { 1387 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1320 skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 1388 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1321 struct tx_ring_info *fre;
1322 1389
1323 mapping = pci_map_page(hw->pdev, frag->page, frag->page_offset, 1390 mapping = pci_map_page(hw->pdev, frag->page, frag->page_offset,
1324 frag->size, PCI_DMA_TODEVICE); 1391 frag->size, PCI_DMA_TODEVICE);
@@ -1337,12 +1404,12 @@ static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
1337 le->ctrl = ctrl; 1404 le->ctrl = ctrl;
1338 le->opcode = OP_BUFFER | HW_OWNER; 1405 le->opcode = OP_BUFFER | HW_OWNER;
1339 1406
1340 fre = sky2->tx_ring 1407 re = tx_le_re(sky2, le);
1341 + RING_NEXT((re - sky2->tx_ring) + i, TX_RING_SIZE); 1408 re->skb = skb;
1342 pci_unmap_addr_set(fre, mapaddr, mapping); 1409 pci_unmap_addr_set(re, mapaddr, mapping);
1410 pci_unmap_len_set(re, maplen, frag->size);
1343 } 1411 }
1344 1412
1345 re->idx = sky2->tx_prod;
1346 le->ctrl |= EOP; 1413 le->ctrl |= EOP;
1347 1414
1348 if (tx_avail(sky2) <= MAX_SKB_TX_LE) 1415 if (tx_avail(sky2) <= MAX_SKB_TX_LE)
@@ -1350,8 +1417,6 @@ static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
1350 1417
1351 sky2_put_idx(hw, txqaddr[sky2->port], sky2->tx_prod); 1418 sky2_put_idx(hw, txqaddr[sky2->port], sky2->tx_prod);
1352 1419
1353 spin_unlock(&sky2->tx_lock);
1354
1355 dev->trans_start = jiffies; 1420 dev->trans_start = jiffies;
1356 return NETDEV_TX_OK; 1421 return NETDEV_TX_OK;
1357} 1422}
@@ -1360,59 +1425,59 @@ static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
1360 * Free ring elements from starting at tx_cons until "done" 1425 * Free ring elements from starting at tx_cons until "done"
1361 * 1426 *
1362 * NB: the hardware will tell us about partial completion of multi-part 1427 * NB: the hardware will tell us about partial completion of multi-part
1363 * buffers; these are deferred until completion. 1428 * buffers so make sure not to free skb to early.
1364 */ 1429 */
1365static void sky2_tx_complete(struct sky2_port *sky2, u16 done) 1430static void sky2_tx_complete(struct sky2_port *sky2, u16 done)
1366{ 1431{
1367 struct net_device *dev = sky2->netdev; 1432 struct net_device *dev = sky2->netdev;
1368 struct pci_dev *pdev = sky2->hw->pdev; 1433 struct pci_dev *pdev = sky2->hw->pdev;
1369 u16 nxt, put; 1434 unsigned idx;
1370 unsigned i;
1371 1435
1372 BUG_ON(done >= TX_RING_SIZE); 1436 BUG_ON(done >= TX_RING_SIZE);
1373 1437
1374 if (unlikely(netif_msg_tx_done(sky2))) 1438 for (idx = sky2->tx_cons; idx != done;
1375 printk(KERN_DEBUG "%s: tx done, up to %u\n", 1439 idx = RING_NEXT(idx, TX_RING_SIZE)) {
1376 dev->name, done); 1440 struct sky2_tx_le *le = sky2->tx_le + idx;
1377 1441 struct tx_ring_info *re = sky2->tx_ring + idx;
1378 for (put = sky2->tx_cons; put != done; put = nxt) { 1442
1379 struct tx_ring_info *re = sky2->tx_ring + put; 1443 switch(le->opcode & ~HW_OWNER) {
1380 struct sk_buff *skb = re->skb; 1444 case OP_LARGESEND:
1381 1445 case OP_PACKET:
1382 nxt = re->idx; 1446 pci_unmap_single(pdev,
1383 BUG_ON(nxt >= TX_RING_SIZE); 1447 pci_unmap_addr(re, mapaddr),
1384 prefetch(sky2->tx_ring + nxt); 1448 pci_unmap_len(re, maplen),
1385 1449 PCI_DMA_TODEVICE);
1386 /* Check for partial status */
1387 if (tx_dist(put, done) < tx_dist(put, nxt))
1388 break; 1450 break;
1389 1451 case OP_BUFFER:
1390 skb = re->skb; 1452 pci_unmap_page(pdev, pci_unmap_addr(re, mapaddr),
1391 pci_unmap_single(pdev, pci_unmap_addr(re, mapaddr), 1453 pci_unmap_len(re, maplen),
1392 skb_headlen(skb), PCI_DMA_TODEVICE);
1393
1394 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1395 struct tx_ring_info *fre;
1396 fre = sky2->tx_ring + RING_NEXT(put + i, TX_RING_SIZE);
1397 pci_unmap_page(pdev, pci_unmap_addr(fre, mapaddr),
1398 skb_shinfo(skb)->frags[i].size,
1399 PCI_DMA_TODEVICE); 1454 PCI_DMA_TODEVICE);
1455 break;
1400 } 1456 }
1401 1457
1402 dev_kfree_skb(skb); 1458 if (le->ctrl & EOP) {
1459 if (unlikely(netif_msg_tx_done(sky2)))
1460 printk(KERN_DEBUG "%s: tx done %u\n",
1461 dev->name, idx);
1462 dev_kfree_skb(re->skb);
1463 }
1464
1465 le->opcode = 0; /* paranoia */
1403 } 1466 }
1404 1467
1405 sky2->tx_cons = put; 1468 sky2->tx_cons = idx;
1406 if (tx_avail(sky2) > MAX_SKB_TX_LE + 4) 1469 if (tx_avail(sky2) > MAX_SKB_TX_LE + 4)
1407 netif_wake_queue(dev); 1470 netif_wake_queue(dev);
1408} 1471}
1409 1472
1410/* Cleanup all untransmitted buffers, assume transmitter not running */ 1473/* Cleanup all untransmitted buffers, assume transmitter not running */
1411static void sky2_tx_clean(struct sky2_port *sky2) 1474static void sky2_tx_clean(struct net_device *dev)
1412{ 1475{
1413 spin_lock_bh(&sky2->tx_lock); 1476 struct sky2_port *sky2 = netdev_priv(dev);
1477
1478 netif_tx_lock_bh(dev);
1414 sky2_tx_complete(sky2, sky2->tx_prod); 1479 sky2_tx_complete(sky2, sky2->tx_prod);
1415 spin_unlock_bh(&sky2->tx_lock); 1480 netif_tx_unlock_bh(dev);
1416} 1481}
1417 1482
1418/* Network shutdown */ 1483/* Network shutdown */
@@ -1443,6 +1508,13 @@ static int sky2_down(struct net_device *dev)
1443 sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), 1508 sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL),
1444 RB_RST_SET | RB_DIS_OP_MD); 1509 RB_RST_SET | RB_DIS_OP_MD);
1445 1510
1511 /* WA for dev. #4.209 */
1512 if (hw->chip_id == CHIP_ID_YUKON_EC_U
1513 && hw->chip_rev == CHIP_REV_YU_EC_U_A1)
1514 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T),
1515 sky2->speed != SPEED_1000 ?
1516 TX_STFW_ENA : TX_STFW_DIS);
1517
1446 ctrl = gma_read16(hw, port, GM_GP_CTRL); 1518 ctrl = gma_read16(hw, port, GM_GP_CTRL);
1447 ctrl &= ~(GM_GPCR_TX_ENA | GM_GPCR_RX_ENA); 1519 ctrl &= ~(GM_GPCR_TX_ENA | GM_GPCR_RX_ENA);
1448 gma_write16(hw, port, GM_GP_CTRL, ctrl); 1520 gma_write16(hw, port, GM_GP_CTRL, ctrl);
@@ -1489,7 +1561,7 @@ static int sky2_down(struct net_device *dev)
1489 1561
1490 synchronize_irq(hw->pdev->irq); 1562 synchronize_irq(hw->pdev->irq);
1491 1563
1492 sky2_tx_clean(sky2); 1564 sky2_tx_clean(dev);
1493 sky2_rx_clean(sky2); 1565 sky2_rx_clean(sky2);
1494 1566
1495 pci_free_consistent(hw->pdev, RX_LE_BYTES, 1567 pci_free_consistent(hw->pdev, RX_LE_BYTES,
@@ -1624,22 +1696,33 @@ static int sky2_autoneg_done(struct sky2_port *sky2, u16 aux)
1624 return -1; 1696 return -1;
1625 } 1697 }
1626 1698
1627 if (hw->chip_id != CHIP_ID_YUKON_FE &&
1628 gm_phy_read(hw, port, PHY_MARV_1000T_STAT) & PHY_B_1000S_MSF) {
1629 printk(KERN_ERR PFX "%s: master/slave fault",
1630 sky2->netdev->name);
1631 return -1;
1632 }
1633
1634 if (!(aux & PHY_M_PS_SPDUP_RES)) { 1699 if (!(aux & PHY_M_PS_SPDUP_RES)) {
1635 printk(KERN_ERR PFX "%s: speed/duplex mismatch", 1700 printk(KERN_ERR PFX "%s: speed/duplex mismatch",
1636 sky2->netdev->name); 1701 sky2->netdev->name);
1637 return -1; 1702 return -1;
1638 } 1703 }
1639 1704
1640 sky2->duplex = (aux & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
1641
1642 sky2->speed = sky2_phy_speed(hw, aux); 1705 sky2->speed = sky2_phy_speed(hw, aux);
1706 if (sky2->speed == SPEED_1000) {
1707 u16 ctl2 = gm_phy_read(hw, port, PHY_MARV_1000T_CTRL);
1708 u16 lpa2 = gm_phy_read(hw, port, PHY_MARV_1000T_STAT);
1709 if (lpa2 & PHY_B_1000S_MSF) {
1710 printk(KERN_ERR PFX "%s: master/slave fault",
1711 sky2->netdev->name);
1712 return -1;
1713 }
1714
1715 if ((ctl2 & PHY_M_1000C_AFD) && (lpa2 & PHY_B_1000S_LP_FD))
1716 sky2->duplex = DUPLEX_FULL;
1717 else
1718 sky2->duplex = DUPLEX_HALF;
1719 } else {
1720 u16 adv = gm_phy_read(hw, port, PHY_MARV_AUNE_ADV);
1721 if ((aux & adv) & PHY_AN_FULL)
1722 sky2->duplex = DUPLEX_FULL;
1723 else
1724 sky2->duplex = DUPLEX_HALF;
1725 }
1643 1726
1644 /* Pause bits are offset (9..8) */ 1727 /* Pause bits are offset (9..8) */
1645 if (hw->chip_id == CHIP_ID_YUKON_XL || hw->chip_id == CHIP_ID_YUKON_EC_U) 1728 if (hw->chip_id == CHIP_ID_YUKON_XL || hw->chip_id == CHIP_ID_YUKON_EC_U)
@@ -1730,31 +1813,22 @@ static void sky2_tx_timeout(struct net_device *dev)
1730 } else if (report != sky2->tx_cons) { 1813 } else if (report != sky2->tx_cons) {
1731 printk(KERN_INFO PFX "status report lost?\n"); 1814 printk(KERN_INFO PFX "status report lost?\n");
1732 1815
1733 spin_lock_bh(&sky2->tx_lock); 1816 netif_tx_lock_bh(dev);
1734 sky2_tx_complete(sky2, report); 1817 sky2_tx_complete(sky2, report);
1735 spin_unlock_bh(&sky2->tx_lock); 1818 netif_tx_unlock_bh(dev);
1736 } else { 1819 } else {
1737 printk(KERN_INFO PFX "hardware hung? flushing\n"); 1820 printk(KERN_INFO PFX "hardware hung? flushing\n");
1738 1821
1739 sky2_write32(hw, Q_ADDR(txq, Q_CSR), BMU_STOP); 1822 sky2_write32(hw, Q_ADDR(txq, Q_CSR), BMU_STOP);
1740 sky2_write32(hw, Y2_QADDR(txq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET); 1823 sky2_write32(hw, Y2_QADDR(txq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET);
1741 1824
1742 sky2_tx_clean(sky2); 1825 sky2_tx_clean(dev);
1743 1826
1744 sky2_qset(hw, txq); 1827 sky2_qset(hw, txq);
1745 sky2_prefetch_init(hw, txq, sky2->tx_le_map, TX_RING_SIZE - 1); 1828 sky2_prefetch_init(hw, txq, sky2->tx_le_map, TX_RING_SIZE - 1);
1746 } 1829 }
1747} 1830}
1748 1831
1749
1750/* Want receive buffer size to be multiple of 64 bits
1751 * and incl room for vlan and truncation
1752 */
1753static inline unsigned sky2_buf_size(int mtu)
1754{
1755 return ALIGN(mtu + ETH_HLEN + VLAN_HLEN, 8) + 8;
1756}
1757
1758static int sky2_change_mtu(struct net_device *dev, int new_mtu) 1832static int sky2_change_mtu(struct net_device *dev, int new_mtu)
1759{ 1833{
1760 struct sky2_port *sky2 = netdev_priv(dev); 1834 struct sky2_port *sky2 = netdev_priv(dev);
@@ -1789,7 +1863,7 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu)
1789 sky2_rx_clean(sky2); 1863 sky2_rx_clean(sky2);
1790 1864
1791 dev->mtu = new_mtu; 1865 dev->mtu = new_mtu;
1792 sky2->rx_bufsize = sky2_buf_size(new_mtu); 1866
1793 mode = DATA_BLIND_VAL(DATA_BLIND_DEF) | 1867 mode = DATA_BLIND_VAL(DATA_BLIND_DEF) |
1794 GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF); 1868 GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF);
1795 1869
@@ -1815,16 +1889,100 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu)
1815 return err; 1889 return err;
1816} 1890}
1817 1891
1892/* For small just reuse existing skb for next receive */
1893static struct sk_buff *receive_copy(struct sky2_port *sky2,
1894 const struct rx_ring_info *re,
1895 unsigned length)
1896{
1897 struct sk_buff *skb;
1898
1899 skb = netdev_alloc_skb(sky2->netdev, length + 2);
1900 if (likely(skb)) {
1901 skb_reserve(skb, 2);
1902 pci_dma_sync_single_for_cpu(sky2->hw->pdev, re->data_addr,
1903 length, PCI_DMA_FROMDEVICE);
1904 memcpy(skb->data, re->skb->data, length);
1905 skb->ip_summed = re->skb->ip_summed;
1906 skb->csum = re->skb->csum;
1907 pci_dma_sync_single_for_device(sky2->hw->pdev, re->data_addr,
1908 length, PCI_DMA_FROMDEVICE);
1909 re->skb->ip_summed = CHECKSUM_NONE;
1910 __skb_put(skb, length);
1911 }
1912 return skb;
1913}
1914
1915/* Adjust length of skb with fragments to match received data */
1916static void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space,
1917 unsigned int length)
1918{
1919 int i, num_frags;
1920 unsigned int size;
1921
1922 /* put header into skb */
1923 size = min(length, hdr_space);
1924 skb->tail += size;
1925 skb->len += size;
1926 length -= size;
1927
1928 num_frags = skb_shinfo(skb)->nr_frags;
1929 for (i = 0; i < num_frags; i++) {
1930 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1931
1932 if (length == 0) {
1933 /* don't need this page */
1934 __free_page(frag->page);
1935 --skb_shinfo(skb)->nr_frags;
1936 } else {
1937 size = min(length, (unsigned) PAGE_SIZE);
1938
1939 frag->size = size;
1940 skb->data_len += size;
1941 skb->truesize += size;
1942 skb->len += size;
1943 length -= size;
1944 }
1945 }
1946}
1947
1948/* Normal packet - take skb from ring element and put in a new one */
1949static struct sk_buff *receive_new(struct sky2_port *sky2,
1950 struct rx_ring_info *re,
1951 unsigned int length)
1952{
1953 struct sk_buff *skb, *nskb;
1954 unsigned hdr_space = sky2->rx_data_size;
1955
1956 pr_debug(PFX "receive new length=%d\n", length);
1957
1958 /* Don't be tricky about reusing pages (yet) */
1959 nskb = sky2_rx_alloc(sky2);
1960 if (unlikely(!nskb))
1961 return NULL;
1962
1963 skb = re->skb;
1964 sky2_rx_unmap_skb(sky2->hw->pdev, re);
1965
1966 prefetch(skb->data);
1967 re->skb = nskb;
1968 sky2_rx_map_skb(sky2->hw->pdev, re, hdr_space);
1969
1970 if (skb_shinfo(skb)->nr_frags)
1971 skb_put_frags(skb, hdr_space, length);
1972 else
1973 skb_put(skb, hdr_space);
1974 return skb;
1975}
1976
1818/* 1977/*
1819 * Receive one packet. 1978 * Receive one packet.
1820 * For small packets or errors, just reuse existing skb.
1821 * For larger packets, get new buffer. 1979 * For larger packets, get new buffer.
1822 */ 1980 */
1823static struct sk_buff *sky2_receive(struct net_device *dev, 1981static struct sk_buff *sky2_receive(struct net_device *dev,
1824 u16 length, u32 status) 1982 u16 length, u32 status)
1825{ 1983{
1826 struct sky2_port *sky2 = netdev_priv(dev); 1984 struct sky2_port *sky2 = netdev_priv(dev);
1827 struct ring_info *re = sky2->rx_ring + sky2->rx_next; 1985 struct rx_ring_info *re = sky2->rx_ring + sky2->rx_next;
1828 struct sk_buff *skb = NULL; 1986 struct sk_buff *skb = NULL;
1829 1987
1830 if (unlikely(netif_msg_rx_status(sky2))) 1988 if (unlikely(netif_msg_rx_status(sky2)))
@@ -1843,40 +2001,12 @@ static struct sk_buff *sky2_receive(struct net_device *dev,
1843 if (length > dev->mtu + ETH_HLEN) 2001 if (length > dev->mtu + ETH_HLEN)
1844 goto oversize; 2002 goto oversize;
1845 2003
1846 if (length < copybreak) { 2004 if (length < copybreak)
1847 skb = netdev_alloc_skb(dev, length + 2); 2005 skb = receive_copy(sky2, re, length);
1848 if (!skb) 2006 else
1849 goto resubmit; 2007 skb = receive_new(sky2, re, length);
1850
1851 skb_reserve(skb, 2);
1852 pci_dma_sync_single_for_cpu(sky2->hw->pdev, re->mapaddr,
1853 length, PCI_DMA_FROMDEVICE);
1854 memcpy(skb->data, re->skb->data, length);
1855 skb->ip_summed = re->skb->ip_summed;
1856 skb->csum = re->skb->csum;
1857 pci_dma_sync_single_for_device(sky2->hw->pdev, re->mapaddr,
1858 length, PCI_DMA_FROMDEVICE);
1859 } else {
1860 struct sk_buff *nskb;
1861
1862 nskb = sky2_alloc_skb(dev, sky2->rx_bufsize, GFP_ATOMIC);
1863 if (!nskb)
1864 goto resubmit;
1865
1866 skb = re->skb;
1867 re->skb = nskb;
1868 pci_unmap_single(sky2->hw->pdev, re->mapaddr,
1869 sky2->rx_bufsize, PCI_DMA_FROMDEVICE);
1870 prefetch(skb->data);
1871
1872 re->mapaddr = pci_map_single(sky2->hw->pdev, nskb->data,
1873 sky2->rx_bufsize, PCI_DMA_FROMDEVICE);
1874 }
1875
1876 skb_put(skb, length);
1877resubmit: 2008resubmit:
1878 re->skb->ip_summed = CHECKSUM_NONE; 2009 sky2_rx_submit(sky2, re);
1879 sky2_rx_add(sky2, re->mapaddr);
1880 2010
1881 return skb; 2011 return skb;
1882 2012
@@ -1909,9 +2039,9 @@ static inline void sky2_tx_done(struct net_device *dev, u16 last)
1909 struct sky2_port *sky2 = netdev_priv(dev); 2039 struct sky2_port *sky2 = netdev_priv(dev);
1910 2040
1911 if (netif_running(dev)) { 2041 if (netif_running(dev)) {
1912 spin_lock(&sky2->tx_lock); 2042 netif_tx_lock(dev);
1913 sky2_tx_complete(sky2, last); 2043 sky2_tx_complete(sky2, last);
1914 spin_unlock(&sky2->tx_lock); 2044 netif_tx_unlock(dev);
1915 } 2045 }
1916} 2046}
1917 2047
@@ -2082,7 +2212,7 @@ static void sky2_hw_intr(struct sky2_hw *hw)
2082 2212
2083 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); 2213 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
2084 sky2_pci_write16(hw, PCI_STATUS, 2214 sky2_pci_write16(hw, PCI_STATUS,
2085 pci_err | PCI_STATUS_ERROR_BITS); 2215 pci_err | PCI_STATUS_ERROR_BITS);
2086 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); 2216 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
2087 } 2217 }
2088 2218
@@ -2090,7 +2220,8 @@ static void sky2_hw_intr(struct sky2_hw *hw)
2090 /* PCI-Express uncorrectable Error occurred */ 2220 /* PCI-Express uncorrectable Error occurred */
2091 u32 pex_err; 2221 u32 pex_err;
2092 2222
2093 pex_err = sky2_pci_read32(hw, PEX_UNC_ERR_STAT); 2223 pex_err = sky2_pci_read32(hw,
2224 hw->err_cap + PCI_ERR_UNCOR_STATUS);
2094 2225
2095 if (net_ratelimit()) 2226 if (net_ratelimit())
2096 printk(KERN_ERR PFX "%s: pci express error (0x%x)\n", 2227 printk(KERN_ERR PFX "%s: pci express error (0x%x)\n",
@@ -2098,15 +2229,20 @@ static void sky2_hw_intr(struct sky2_hw *hw)
2098 2229
2099 /* clear the interrupt */ 2230 /* clear the interrupt */
2100 sky2_write32(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); 2231 sky2_write32(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
2101 sky2_pci_write32(hw, PEX_UNC_ERR_STAT, 2232 sky2_pci_write32(hw,
2102 0xffffffffUL); 2233 hw->err_cap + PCI_ERR_UNCOR_STATUS,
2234 0xffffffffUL);
2103 sky2_write32(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); 2235 sky2_write32(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
2104 2236
2105 if (pex_err & PEX_FATAL_ERRORS) { 2237
2238 /* In case of fatal error mask off to keep from getting stuck */
2239 if (pex_err & (PCI_ERR_UNC_POISON_TLP | PCI_ERR_UNC_FCP
2240 | PCI_ERR_UNC_DLP)) {
2106 u32 hwmsk = sky2_read32(hw, B0_HWE_IMSK); 2241 u32 hwmsk = sky2_read32(hw, B0_HWE_IMSK);
2107 hwmsk &= ~Y2_IS_PCI_EXP; 2242 hwmsk &= ~Y2_IS_PCI_EXP;
2108 sky2_write32(hw, B0_HWE_IMSK, hwmsk); 2243 sky2_write32(hw, B0_HWE_IMSK, hwmsk);
2109 } 2244 }
2245
2110 } 2246 }
2111 2247
2112 if (status & Y2_HWE_L1_MASK) 2248 if (status & Y2_HWE_L1_MASK)
@@ -2287,6 +2423,7 @@ static int sky2_reset(struct sky2_hw *hw)
2287 u16 status; 2423 u16 status;
2288 u8 t8; 2424 u8 t8;
2289 int i; 2425 int i;
2426 u32 msk;
2290 2427
2291 sky2_write8(hw, B0_CTST, CS_RST_CLR); 2428 sky2_write8(hw, B0_CTST, CS_RST_CLR);
2292 2429
@@ -2327,9 +2464,13 @@ static int sky2_reset(struct sky2_hw *hw)
2327 sky2_write8(hw, B0_CTST, CS_MRST_CLR); 2464 sky2_write8(hw, B0_CTST, CS_MRST_CLR);
2328 2465
2329 /* clear any PEX errors */ 2466 /* clear any PEX errors */
2330 if (pci_find_capability(hw->pdev, PCI_CAP_ID_EXP)) 2467 if (pci_find_capability(hw->pdev, PCI_CAP_ID_EXP)) {
2331 sky2_pci_write32(hw, PEX_UNC_ERR_STAT, 0xffffffffUL); 2468 hw->err_cap = pci_find_ext_capability(hw->pdev, PCI_EXT_CAP_ID_ERR);
2332 2469 if (hw->err_cap)
2470 sky2_pci_write32(hw,
2471 hw->err_cap + PCI_ERR_UNCOR_STATUS,
2472 0xffffffffUL);
2473 }
2333 2474
2334 hw->pmd_type = sky2_read8(hw, B2_PMD_TYP); 2475 hw->pmd_type = sky2_read8(hw, B2_PMD_TYP);
2335 hw->ports = 1; 2476 hw->ports = 1;
@@ -2386,7 +2527,10 @@ static int sky2_reset(struct sky2_hw *hw)
2386 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS2), SK_RI_TO_53); 2527 sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS2), SK_RI_TO_53);
2387 } 2528 }
2388 2529
2389 sky2_write32(hw, B0_HWE_IMSK, Y2_HWE_ALL_MASK); 2530 msk = Y2_HWE_ALL_MASK;
2531 if (!hw->err_cap)
2532 msk &= ~Y2_IS_PCI_EXP;
2533 sky2_write32(hw, B0_HWE_IMSK, msk);
2390 2534
2391 for (i = 0; i < hw->ports; i++) 2535 for (i = 0; i < hw->ports; i++)
2392 sky2_gmac_reset(hw, i); 2536 sky2_gmac_reset(hw, i);
@@ -3102,7 +3246,6 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
3102 sky2->hw = hw; 3246 sky2->hw = hw;
3103 sky2->msg_enable = netif_msg_init(debug, default_msg); 3247 sky2->msg_enable = netif_msg_init(debug, default_msg);
3104 3248
3105 spin_lock_init(&sky2->tx_lock);
3106 /* Auto speed and flow control */ 3249 /* Auto speed and flow control */
3107 sky2->autoneg = AUTONEG_ENABLE; 3250 sky2->autoneg = AUTONEG_ENABLE;
3108 sky2->tx_pause = 1; 3251 sky2->tx_pause = 1;
@@ -3115,13 +3258,11 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
3115 spin_lock_init(&sky2->phy_lock); 3258 spin_lock_init(&sky2->phy_lock);
3116 sky2->tx_pending = TX_DEF_PENDING; 3259 sky2->tx_pending = TX_DEF_PENDING;
3117 sky2->rx_pending = RX_DEF_PENDING; 3260 sky2->rx_pending = RX_DEF_PENDING;
3118 sky2->rx_bufsize = sky2_buf_size(ETH_DATA_LEN);
3119 3261
3120 hw->dev[port] = dev; 3262 hw->dev[port] = dev;
3121 3263
3122 sky2->port = port; 3264 sky2->port = port;
3123 3265
3124 dev->features |= NETIF_F_LLTX;
3125 if (hw->chip_id != CHIP_ID_YUKON_EC_U) 3266 if (hw->chip_id != CHIP_ID_YUKON_EC_U)
3126 dev->features |= NETIF_F_TSO; 3267 dev->features |= NETIF_F_TSO;
3127 if (highmem) 3268 if (highmem)
@@ -3316,6 +3457,14 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
3316 if (!dev) 3457 if (!dev)
3317 goto err_out_free_pci; 3458 goto err_out_free_pci;
3318 3459
3460 if (!disable_msi && pci_enable_msi(pdev) == 0) {
3461 err = sky2_test_msi(hw);
3462 if (err == -EOPNOTSUPP)
3463 pci_disable_msi(pdev);
3464 else if (err)
3465 goto err_out_free_netdev;
3466 }
3467
3319 err = register_netdev(dev); 3468 err = register_netdev(dev);
3320 if (err) { 3469 if (err) {
3321 printk(KERN_ERR PFX "%s: cannot register net device\n", 3470 printk(KERN_ERR PFX "%s: cannot register net device\n",
@@ -3323,6 +3472,14 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
3323 goto err_out_free_netdev; 3472 goto err_out_free_netdev;
3324 } 3473 }
3325 3474
3475 err = request_irq(pdev->irq, sky2_intr, IRQF_SHARED, dev->name, hw);
3476 if (err) {
3477 printk(KERN_ERR PFX "%s: cannot assign irq %d\n",
3478 pci_name(pdev), pdev->irq);
3479 goto err_out_unregister;
3480 }
3481 sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
3482
3326 sky2_show_addr(dev); 3483 sky2_show_addr(dev);
3327 3484
3328 if (hw->ports > 1 && (dev1 = sky2_init_netdev(hw, 1, using_dac))) { 3485 if (hw->ports > 1 && (dev1 = sky2_init_netdev(hw, 1, using_dac))) {
@@ -3337,23 +3494,6 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
3337 } 3494 }
3338 } 3495 }
3339 3496
3340 if (!disable_msi && pci_enable_msi(pdev) == 0) {
3341 err = sky2_test_msi(hw);
3342 if (err == -EOPNOTSUPP)
3343 pci_disable_msi(pdev);
3344 else if (err)
3345 goto err_out_unregister;
3346 }
3347
3348 err = request_irq(pdev->irq, sky2_intr, IRQF_SHARED, DRV_NAME, hw);
3349 if (err) {
3350 printk(KERN_ERR PFX "%s: cannot assign irq %d\n",
3351 pci_name(pdev), pdev->irq);
3352 goto err_out_unregister;
3353 }
3354
3355 sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
3356
3357 setup_timer(&hw->idle_timer, sky2_idle, (unsigned long) hw); 3497 setup_timer(&hw->idle_timer, sky2_idle, (unsigned long) hw);
3358 sky2_idle_start(hw); 3498 sky2_idle_start(hw);
3359 3499
@@ -3363,10 +3503,6 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
3363 3503
3364err_out_unregister: 3504err_out_unregister:
3365 pci_disable_msi(pdev); 3505 pci_disable_msi(pdev);
3366 if (dev1) {
3367 unregister_netdev(dev1);
3368 free_netdev(dev1);
3369 }
3370 unregister_netdev(dev); 3506 unregister_netdev(dev);
3371err_out_free_netdev: 3507err_out_free_netdev:
3372 free_netdev(dev); 3508 free_netdev(dev);
diff --git a/drivers/net/sky2.h b/drivers/net/sky2.h
index 4c13c371bc21..f66109a96d95 100644
--- a/drivers/net/sky2.h
+++ b/drivers/net/sky2.h
@@ -4,24 +4,17 @@
4#ifndef _SKY2_H 4#ifndef _SKY2_H
5#define _SKY2_H 5#define _SKY2_H
6 6
7/* PCI config registers */ 7#define ETH_JUMBO_MTU 9000 /* Maximum MTU supported */
8
9/* PCI device specific config registers */
8enum { 10enum {
9 PCI_DEV_REG1 = 0x40, 11 PCI_DEV_REG1 = 0x40,
10 PCI_DEV_REG2 = 0x44, 12 PCI_DEV_REG2 = 0x44,
11 PCI_DEV_STATUS = 0x7c,
12 PCI_DEV_REG3 = 0x80, 13 PCI_DEV_REG3 = 0x80,
13 PCI_DEV_REG4 = 0x84, 14 PCI_DEV_REG4 = 0x84,
14 PCI_DEV_REG5 = 0x88, 15 PCI_DEV_REG5 = 0x88,
15}; 16};
16 17
17enum {
18 PEX_DEV_CAP = 0xe4,
19 PEX_DEV_CTRL = 0xe8,
20 PEX_DEV_STA = 0xea,
21 PEX_LNK_STAT = 0xf2,
22 PEX_UNC_ERR_STAT= 0x104,
23};
24
25/* Yukon-2 */ 18/* Yukon-2 */
26enum pci_dev_reg_1 { 19enum pci_dev_reg_1 {
27 PCI_Y2_PIG_ENA = 1<<31, /* Enable Plug-in-Go (YUKON-2) */ 20 PCI_Y2_PIG_ENA = 1<<31, /* Enable Plug-in-Go (YUKON-2) */
@@ -70,39 +63,6 @@ enum pci_dev_reg_4 {
70 PCI_STATUS_REC_MASTER_ABORT | \ 63 PCI_STATUS_REC_MASTER_ABORT | \
71 PCI_STATUS_REC_TARGET_ABORT | \ 64 PCI_STATUS_REC_TARGET_ABORT | \
72 PCI_STATUS_PARITY) 65 PCI_STATUS_PARITY)
73
74enum pex_dev_ctrl {
75 PEX_DC_MAX_RRS_MSK = 7<<12, /* Bit 14..12: Max. Read Request Size */
76 PEX_DC_EN_NO_SNOOP = 1<<11,/* Enable No Snoop */
77 PEX_DC_EN_AUX_POW = 1<<10,/* Enable AUX Power */
78 PEX_DC_EN_PHANTOM = 1<<9, /* Enable Phantom Functions */
79 PEX_DC_EN_EXT_TAG = 1<<8, /* Enable Extended Tag Field */
80 PEX_DC_MAX_PLS_MSK = 7<<5, /* Bit 7.. 5: Max. Payload Size Mask */
81 PEX_DC_EN_REL_ORD = 1<<4, /* Enable Relaxed Ordering */
82 PEX_DC_EN_UNS_RQ_RP = 1<<3, /* Enable Unsupported Request Reporting */
83 PEX_DC_EN_FAT_ER_RP = 1<<2, /* Enable Fatal Error Reporting */
84 PEX_DC_EN_NFA_ER_RP = 1<<1, /* Enable Non-Fatal Error Reporting */
85 PEX_DC_EN_COR_ER_RP = 1<<0, /* Enable Correctable Error Reporting */
86};
87#define PEX_DC_MAX_RD_RQ_SIZE(x) (((x)<<12) & PEX_DC_MAX_RRS_MSK)
88
89/* PEX_UNC_ERR_STAT PEX Uncorrectable Errors Status Register (Yukon-2) */
90enum pex_err {
91 PEX_UNSUP_REQ = 1<<20, /* Unsupported Request Error */
92
93 PEX_MALFOR_TLP = 1<<18, /* Malformed TLP */
94
95 PEX_UNEXP_COMP = 1<<16, /* Unexpected Completion */
96
97 PEX_COMP_TO = 1<<14, /* Completion Timeout */
98 PEX_FLOW_CTRL_P = 1<<13, /* Flow Control Protocol Error */
99 PEX_POIS_TLP = 1<<12, /* Poisoned TLP */
100
101 PEX_DATA_LINK_P = 1<<4, /* Data Link Protocol Error */
102 PEX_FATAL_ERRORS= (PEX_MALFOR_TLP | PEX_FLOW_CTRL_P | PEX_DATA_LINK_P),
103};
104
105
106enum csr_regs { 66enum csr_regs {
107 B0_RAP = 0x0000, 67 B0_RAP = 0x0000,
108 B0_CTST = 0x0004, 68 B0_CTST = 0x0004,
@@ -1816,12 +1776,14 @@ struct sky2_status_le {
1816struct tx_ring_info { 1776struct tx_ring_info {
1817 struct sk_buff *skb; 1777 struct sk_buff *skb;
1818 DECLARE_PCI_UNMAP_ADDR(mapaddr); 1778 DECLARE_PCI_UNMAP_ADDR(mapaddr);
1819 u16 idx; 1779 DECLARE_PCI_UNMAP_ADDR(maplen);
1820}; 1780};
1821 1781
1822struct ring_info { 1782struct rx_ring_info {
1823 struct sk_buff *skb; 1783 struct sk_buff *skb;
1824 dma_addr_t mapaddr; 1784 dma_addr_t data_addr;
1785 DECLARE_PCI_UNMAP_ADDR(data_size);
1786 dma_addr_t frag_addr[ETH_JUMBO_MTU >> PAGE_SHIFT];
1825}; 1787};
1826 1788
1827struct sky2_port { 1789struct sky2_port {
@@ -1831,7 +1793,6 @@ struct sky2_port {
1831 u32 msg_enable; 1793 u32 msg_enable;
1832 spinlock_t phy_lock; 1794 spinlock_t phy_lock;
1833 1795
1834 spinlock_t tx_lock ____cacheline_aligned_in_smp;
1835 struct tx_ring_info *tx_ring; 1796 struct tx_ring_info *tx_ring;
1836 struct sky2_tx_le *tx_le; 1797 struct sky2_tx_le *tx_le;
1837 u16 tx_cons; /* next le to check */ 1798 u16 tx_cons; /* next le to check */
@@ -1841,13 +1802,15 @@ struct sky2_port {
1841 u16 tx_last_mss; 1802 u16 tx_last_mss;
1842 u32 tx_tcpsum; 1803 u32 tx_tcpsum;
1843 1804
1844 struct ring_info *rx_ring ____cacheline_aligned_in_smp; 1805 struct rx_ring_info *rx_ring ____cacheline_aligned_in_smp;
1845 struct sky2_rx_le *rx_le; 1806 struct sky2_rx_le *rx_le;
1846 u32 rx_addr64; 1807 u32 rx_addr64;
1847 u16 rx_next; /* next re to check */ 1808 u16 rx_next; /* next re to check */
1848 u16 rx_put; /* next le index to use */ 1809 u16 rx_put; /* next le index to use */
1849 u16 rx_pending; 1810 u16 rx_pending;
1850 u16 rx_bufsize; 1811 u16 rx_data_size;
1812 u16 rx_nfrags;
1813
1851#ifdef SKY2_VLAN_TAG_USED 1814#ifdef SKY2_VLAN_TAG_USED
1852 u16 rx_tag; 1815 u16 rx_tag;
1853 struct vlan_group *vlgrp; 1816 struct vlan_group *vlgrp;
@@ -1873,6 +1836,7 @@ struct sky2_hw {
1873 struct net_device *dev[2]; 1836 struct net_device *dev[2];
1874 1837
1875 int pm_cap; 1838 int pm_cap;
1839 int err_cap;
1876 u8 chip_id; 1840 u8 chip_id;
1877 u8 chip_rev; 1841 u8 chip_rev;
1878 u8 pmd_type; 1842 u8 pmd_type;
diff --git a/drivers/net/smc91x.h b/drivers/net/smc91x.h
index 7aa7fbac8224..fedd1a37bc3e 100644
--- a/drivers/net/smc91x.h
+++ b/drivers/net/smc91x.h
@@ -195,6 +195,7 @@ SMC_outw(u16 val, void __iomem *ioaddr, int reg)
195#define SMC_IRQ_FLAGS (( \ 195#define SMC_IRQ_FLAGS (( \
196 machine_is_omap_h2() \ 196 machine_is_omap_h2() \
197 || machine_is_omap_h3() \ 197 || machine_is_omap_h3() \
198 || machine_is_omap_h4() \
198 || (machine_is_omap_innovator() && !cpu_is_omap1510()) \ 199 || (machine_is_omap_innovator() && !cpu_is_omap1510()) \
199 ) ? IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING) 200 ) ? IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING)
200 201
@@ -379,6 +380,24 @@ static inline void LPD7_SMC_outsw (unsigned char* a, int r,
379 380
380#define SMC_IRQ_FLAGS (0) 381#define SMC_IRQ_FLAGS (0)
381 382
383#elif defined(CONFIG_ARCH_VERSATILE)
384
385#define SMC_CAN_USE_8BIT 1
386#define SMC_CAN_USE_16BIT 1
387#define SMC_CAN_USE_32BIT 1
388#define SMC_NOWAIT 1
389
390#define SMC_inb(a, r) readb((a) + (r))
391#define SMC_inw(a, r) readw((a) + (r))
392#define SMC_inl(a, r) readl((a) + (r))
393#define SMC_outb(v, a, r) writeb(v, (a) + (r))
394#define SMC_outw(v, a, r) writew(v, (a) + (r))
395#define SMC_outl(v, a, r) writel(v, (a) + (r))
396#define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
397#define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
398
399#define SMC_IRQ_FLAGS (0)
400
382#else 401#else
383 402
384#define SMC_CAN_USE_8BIT 1 403#define SMC_CAN_USE_8BIT 1
diff --git a/drivers/net/spider_net.c b/drivers/net/spider_net.c
index cc240adb7269..1397fc55cf68 100644
--- a/drivers/net/spider_net.c
+++ b/drivers/net/spider_net.c
@@ -317,7 +317,7 @@ spider_net_init_chain(struct spider_net_card *card,
317 SPIDER_NET_DESCR_SIZE, 317 SPIDER_NET_DESCR_SIZE,
318 direction); 318 direction);
319 319
320 if (buf == DMA_ERROR_CODE) 320 if (pci_dma_mapping_error(buf))
321 goto iommu_error; 321 goto iommu_error;
322 322
323 descr->bus_addr = buf; 323 descr->bus_addr = buf;
@@ -420,7 +420,7 @@ spider_net_prepare_rx_descr(struct spider_net_card *card,
420 buf = pci_map_single(card->pdev, descr->skb->data, 420 buf = pci_map_single(card->pdev, descr->skb->data,
421 SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE); 421 SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE);
422 descr->buf_addr = buf; 422 descr->buf_addr = buf;
423 if (buf == DMA_ERROR_CODE) { 423 if (pci_dma_mapping_error(buf)) {
424 dev_kfree_skb_any(descr->skb); 424 dev_kfree_skb_any(descr->skb);
425 if (netif_msg_rx_err(card) && net_ratelimit()) 425 if (netif_msg_rx_err(card) && net_ratelimit())
426 pr_err("Could not iommu-map rx buffer\n"); 426 pr_err("Could not iommu-map rx buffer\n");
@@ -649,7 +649,7 @@ spider_net_prepare_tx_descr(struct spider_net_card *card,
649 dma_addr_t buf; 649 dma_addr_t buf;
650 650
651 buf = pci_map_single(card->pdev, skb->data, skb->len, PCI_DMA_TODEVICE); 651 buf = pci_map_single(card->pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
652 if (buf == DMA_ERROR_CODE) { 652 if (pci_dma_mapping_error(buf)) {
653 if (netif_msg_tx_err(card) && net_ratelimit()) 653 if (netif_msg_tx_err(card) && net_ratelimit())
654 pr_err("could not iommu-map packet (%p, %i). " 654 pr_err("could not iommu-map packet (%p, %i). "
655 "Dropping packet\n", skb->data, skb->len); 655 "Dropping packet\n", skb->data, skb->len);
diff --git a/drivers/net/stnic.c b/drivers/net/stnic.c
index 3fd7a4fee665..e6f90427160c 100644
--- a/drivers/net/stnic.c
+++ b/drivers/net/stnic.c
@@ -19,7 +19,7 @@
19 19
20#include <asm/system.h> 20#include <asm/system.h>
21#include <asm/io.h> 21#include <asm/io.h>
22#include <asm/se/se.h> 22#include <asm/se.h>
23#include <asm/machvec.h> 23#include <asm/machvec.h>
24#ifdef CONFIG_SH_STANDARD_BIOS 24#ifdef CONFIG_SH_STANDARD_BIOS
25#include <asm/sh_bios.h> 25#include <asm/sh_bios.h>
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index aaf45b907a78..c25ba273b745 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -68,8 +68,8 @@
68 68
69#define DRV_MODULE_NAME "tg3" 69#define DRV_MODULE_NAME "tg3"
70#define PFX DRV_MODULE_NAME ": " 70#define PFX DRV_MODULE_NAME ": "
71#define DRV_MODULE_VERSION "3.65" 71#define DRV_MODULE_VERSION "3.66"
72#define DRV_MODULE_RELDATE "August 07, 2006" 72#define DRV_MODULE_RELDATE "September 23, 2006"
73 73
74#define TG3_DEF_MAC_MODE 0 74#define TG3_DEF_MAC_MODE 0
75#define TG3_DEF_RX_MODE 0 75#define TG3_DEF_RX_MODE 0
@@ -173,6 +173,7 @@ static struct pci_device_id tg3_pci_tbl[] = {
173 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)}, 173 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)},
174 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5720)}, 174 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5720)},
175 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)}, 175 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)},
176 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)},
176 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750)}, 177 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750)},
177 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)}, 178 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)},
178 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750M)}, 179 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750M)},
@@ -187,6 +188,7 @@ static struct pci_device_id tg3_pci_tbl[] = {
187 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)}, 188 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)},
188 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)}, 189 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)},
189 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)}, 190 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)},
191 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)},
190 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)}, 192 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)},
191 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)}, 193 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)},
192 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)}, 194 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)},
@@ -197,6 +199,8 @@ static struct pci_device_id tg3_pci_tbl[] = {
197 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)}, 199 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)},
198 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)}, 200 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)},
199 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)}, 201 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)},
202 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)},
203 {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)},
200 {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, 204 {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)},
201 {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)}, 205 {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)},
202 {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)}, 206 {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)},
@@ -424,6 +428,16 @@ static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val)
424 readl(mbox); 428 readl(mbox);
425} 429}
426 430
431static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off)
432{
433 return (readl(tp->regs + off + GRCMBOX_BASE));
434}
435
436static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val)
437{
438 writel(val, tp->regs + off + GRCMBOX_BASE);
439}
440
427#define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val) 441#define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val)
428#define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val)) 442#define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val))
429#define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val) 443#define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val)
@@ -439,6 +453,10 @@ static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val)
439{ 453{
440 unsigned long flags; 454 unsigned long flags;
441 455
456 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
457 (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC))
458 return;
459
442 spin_lock_irqsave(&tp->indirect_lock, flags); 460 spin_lock_irqsave(&tp->indirect_lock, flags);
443 if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) { 461 if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
444 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); 462 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
@@ -460,6 +478,12 @@ static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
460{ 478{
461 unsigned long flags; 479 unsigned long flags;
462 480
481 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
482 (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) {
483 *val = 0;
484 return;
485 }
486
463 spin_lock_irqsave(&tp->indirect_lock, flags); 487 spin_lock_irqsave(&tp->indirect_lock, flags);
464 if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) { 488 if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
465 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); 489 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
@@ -489,6 +513,9 @@ static inline void tg3_cond_int(struct tg3 *tp)
489 if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) && 513 if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
490 (tp->hw_status->status & SD_STATUS_UPDATED)) 514 (tp->hw_status->status & SD_STATUS_UPDATED))
491 tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); 515 tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
516 else
517 tw32(HOSTCC_MODE, tp->coalesce_mode |
518 (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
492} 519}
493 520
494static void tg3_enable_ints(struct tg3 *tp) 521static void tg3_enable_ints(struct tg3 *tp)
@@ -654,6 +681,10 @@ static int tg3_writephy(struct tg3 *tp, int reg, u32 val)
654 unsigned int loops; 681 unsigned int loops;
655 int ret; 682 int ret;
656 683
684 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 &&
685 (reg == MII_TG3_CTRL || reg == MII_TG3_AUX_CTRL))
686 return 0;
687
657 if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { 688 if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
658 tw32_f(MAC_MI_MODE, 689 tw32_f(MAC_MI_MODE,
659 (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); 690 (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
@@ -1004,6 +1035,24 @@ out:
1004 phy_reg | MII_TG3_EXT_CTRL_FIFO_ELASTIC); 1035 phy_reg | MII_TG3_EXT_CTRL_FIFO_ELASTIC);
1005 } 1036 }
1006 1037
1038 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
1039 u32 phy_reg;
1040
1041 /* adjust output voltage */
1042 tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x12);
1043
1044 if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phy_reg)) {
1045 u32 phy_reg2;
1046
1047 tg3_writephy(tp, MII_TG3_EPHY_TEST,
1048 phy_reg | MII_TG3_EPHY_SHADOW_EN);
1049 /* Enable auto-MDIX */
1050 if (!tg3_readphy(tp, 0x10, &phy_reg2))
1051 tg3_writephy(tp, 0x10, phy_reg2 | 0x4000);
1052 tg3_writephy(tp, MII_TG3_EPHY_TEST, phy_reg);
1053 }
1054 }
1055
1007 tg3_phy_set_wirespeed(tp); 1056 tg3_phy_set_wirespeed(tp);
1008 return 0; 1057 return 0;
1009} 1058}
@@ -1117,6 +1166,15 @@ static void tg3_nvram_unlock(struct tg3 *);
1117 1166
1118static void tg3_power_down_phy(struct tg3 *tp) 1167static void tg3_power_down_phy(struct tg3 *tp)
1119{ 1168{
1169 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
1170 return;
1171
1172 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906) {
1173 tg3_writephy(tp, MII_TG3_EXT_CTRL,
1174 MII_TG3_EXT_CTRL_FORCE_LED_OFF);
1175 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2);
1176 }
1177
1120 /* The PHY should not be powered down on some chips because 1178 /* The PHY should not be powered down on some chips because
1121 * of bugs. 1179 * of bugs.
1122 */ 1180 */
@@ -1199,7 +1257,12 @@ static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
1199 tg3_setup_phy(tp, 0); 1257 tg3_setup_phy(tp, 0);
1200 } 1258 }
1201 1259
1202 if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) { 1260 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
1261 u32 val;
1262
1263 val = tr32(GRC_VCPU_EXT_CTRL);
1264 tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL);
1265 } else if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
1203 int i; 1266 int i;
1204 u32 val; 1267 u32 val;
1205 1268
@@ -1223,7 +1286,10 @@ static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
1223 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a); 1286 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a);
1224 udelay(40); 1287 udelay(40);
1225 1288
1226 mac_mode = MAC_MODE_PORT_MODE_MII; 1289 if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
1290 mac_mode = MAC_MODE_PORT_MODE_GMII;
1291 else
1292 mac_mode = MAC_MODE_PORT_MODE_MII;
1227 1293
1228 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 || 1294 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 ||
1229 !(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)) 1295 !(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB))
@@ -1301,15 +1367,8 @@ static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
1301 } 1367 }
1302 1368
1303 if (!(tp->tg3_flags & TG3_FLAG_WOL_ENABLE) && 1369 if (!(tp->tg3_flags & TG3_FLAG_WOL_ENABLE) &&
1304 !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) { 1370 !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
1305 /* Turn off the PHY */ 1371 tg3_power_down_phy(tp);
1306 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
1307 tg3_writephy(tp, MII_TG3_EXT_CTRL,
1308 MII_TG3_EXT_CTRL_FORCE_LED_OFF);
1309 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2);
1310 tg3_power_down_phy(tp);
1311 }
1312 }
1313 1372
1314 tg3_frob_aux_power(tp); 1373 tg3_frob_aux_power(tp);
1315 1374
@@ -1467,6 +1526,13 @@ static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8
1467 break; 1526 break;
1468 1527
1469 default: 1528 default:
1529 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
1530 *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 :
1531 SPEED_10;
1532 *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL :
1533 DUPLEX_HALF;
1534 break;
1535 }
1470 *speed = SPEED_INVALID; 1536 *speed = SPEED_INVALID;
1471 *duplex = DUPLEX_INVALID; 1537 *duplex = DUPLEX_INVALID;
1472 break; 1538 break;
@@ -1749,7 +1815,7 @@ static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset)
1749 1815
1750 if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) 1816 if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT)
1751 tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG); 1817 tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG);
1752 else 1818 else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
1753 tg3_writephy(tp, MII_TG3_IMASK, ~0); 1819 tg3_writephy(tp, MII_TG3_IMASK, ~0);
1754 1820
1755 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || 1821 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
@@ -2406,24 +2472,27 @@ static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
2406 expected_sg_dig_ctrl |= (1 << 12); 2472 expected_sg_dig_ctrl |= (1 << 12);
2407 2473
2408 if (sg_dig_ctrl != expected_sg_dig_ctrl) { 2474 if (sg_dig_ctrl != expected_sg_dig_ctrl) {
2475 if ((tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT) &&
2476 tp->serdes_counter &&
2477 ((mac_status & (MAC_STATUS_PCS_SYNCED |
2478 MAC_STATUS_RCVD_CFG)) ==
2479 MAC_STATUS_PCS_SYNCED)) {
2480 tp->serdes_counter--;
2481 current_link_up = 1;
2482 goto out;
2483 }
2484restart_autoneg:
2409 if (workaround) 2485 if (workaround)
2410 tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000); 2486 tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000);
2411 tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | (1 << 30)); 2487 tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | (1 << 30));
2412 udelay(5); 2488 udelay(5);
2413 tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl); 2489 tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl);
2414 2490
2415 tp->tg3_flags2 |= TG3_FLG2_PHY_JUST_INITTED; 2491 tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
2492 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
2416 } else if (mac_status & (MAC_STATUS_PCS_SYNCED | 2493 } else if (mac_status & (MAC_STATUS_PCS_SYNCED |
2417 MAC_STATUS_SIGNAL_DET)) { 2494 MAC_STATUS_SIGNAL_DET)) {
2418 int i; 2495 sg_dig_status = tr32(SG_DIG_STATUS);
2419
2420 /* Giver time to negotiate (~200ms) */
2421 for (i = 0; i < 40000; i++) {
2422 sg_dig_status = tr32(SG_DIG_STATUS);
2423 if (sg_dig_status & (0x3))
2424 break;
2425 udelay(5);
2426 }
2427 mac_status = tr32(MAC_STATUS); 2496 mac_status = tr32(MAC_STATUS);
2428 2497
2429 if ((sg_dig_status & (1 << 1)) && 2498 if ((sg_dig_status & (1 << 1)) &&
@@ -2439,10 +2508,11 @@ static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
2439 2508
2440 tg3_setup_flow_control(tp, local_adv, remote_adv); 2509 tg3_setup_flow_control(tp, local_adv, remote_adv);
2441 current_link_up = 1; 2510 current_link_up = 1;
2442 tp->tg3_flags2 &= ~TG3_FLG2_PHY_JUST_INITTED; 2511 tp->serdes_counter = 0;
2512 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
2443 } else if (!(sg_dig_status & (1 << 1))) { 2513 } else if (!(sg_dig_status & (1 << 1))) {
2444 if (tp->tg3_flags2 & TG3_FLG2_PHY_JUST_INITTED) 2514 if (tp->serdes_counter)
2445 tp->tg3_flags2 &= ~TG3_FLG2_PHY_JUST_INITTED; 2515 tp->serdes_counter--;
2446 else { 2516 else {
2447 if (workaround) { 2517 if (workaround) {
2448 u32 val = serdes_cfg; 2518 u32 val = serdes_cfg;
@@ -2466,9 +2536,17 @@ static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
2466 !(mac_status & MAC_STATUS_RCVD_CFG)) { 2536 !(mac_status & MAC_STATUS_RCVD_CFG)) {
2467 tg3_setup_flow_control(tp, 0, 0); 2537 tg3_setup_flow_control(tp, 0, 0);
2468 current_link_up = 1; 2538 current_link_up = 1;
2469 } 2539 tp->tg3_flags2 |=
2540 TG3_FLG2_PARALLEL_DETECT;
2541 tp->serdes_counter =
2542 SERDES_PARALLEL_DET_TIMEOUT;
2543 } else
2544 goto restart_autoneg;
2470 } 2545 }
2471 } 2546 }
2547 } else {
2548 tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
2549 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
2472 } 2550 }
2473 2551
2474out: 2552out:
@@ -2599,14 +2677,16 @@ static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset)
2599 MAC_STATUS_CFG_CHANGED)); 2677 MAC_STATUS_CFG_CHANGED));
2600 udelay(5); 2678 udelay(5);
2601 if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED | 2679 if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED |
2602 MAC_STATUS_CFG_CHANGED)) == 0) 2680 MAC_STATUS_CFG_CHANGED |
2681 MAC_STATUS_LNKSTATE_CHANGED)) == 0)
2603 break; 2682 break;
2604 } 2683 }
2605 2684
2606 mac_status = tr32(MAC_STATUS); 2685 mac_status = tr32(MAC_STATUS);
2607 if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) { 2686 if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) {
2608 current_link_up = 0; 2687 current_link_up = 0;
2609 if (tp->link_config.autoneg == AUTONEG_ENABLE) { 2688 if (tp->link_config.autoneg == AUTONEG_ENABLE &&
2689 tp->serdes_counter == 0) {
2610 tw32_f(MAC_MODE, (tp->mac_mode | 2690 tw32_f(MAC_MODE, (tp->mac_mode |
2611 MAC_MODE_SEND_CONFIGS)); 2691 MAC_MODE_SEND_CONFIGS));
2612 udelay(1); 2692 udelay(1);
@@ -2711,7 +2791,7 @@ static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset)
2711 tg3_writephy(tp, MII_BMCR, bmcr); 2791 tg3_writephy(tp, MII_BMCR, bmcr);
2712 2792
2713 tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); 2793 tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
2714 tp->tg3_flags2 |= TG3_FLG2_PHY_JUST_INITTED; 2794 tp->serdes_counter = SERDES_AN_TIMEOUT_5714S;
2715 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT; 2795 tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
2716 2796
2717 return err; 2797 return err;
@@ -2816,9 +2896,9 @@ static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset)
2816 2896
2817static void tg3_serdes_parallel_detect(struct tg3 *tp) 2897static void tg3_serdes_parallel_detect(struct tg3 *tp)
2818{ 2898{
2819 if (tp->tg3_flags2 & TG3_FLG2_PHY_JUST_INITTED) { 2899 if (tp->serdes_counter) {
2820 /* Give autoneg time to complete. */ 2900 /* Give autoneg time to complete. */
2821 tp->tg3_flags2 &= ~TG3_FLG2_PHY_JUST_INITTED; 2901 tp->serdes_counter--;
2822 return; 2902 return;
2823 } 2903 }
2824 if (!netif_carrier_ok(tp->dev) && 2904 if (!netif_carrier_ok(tp->dev) &&
@@ -3535,8 +3615,7 @@ static irqreturn_t tg3_test_isr(int irq, void *dev_id,
3535 3615
3536 if ((sblk->status & SD_STATUS_UPDATED) || 3616 if ((sblk->status & SD_STATUS_UPDATED) ||
3537 !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { 3617 !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
3538 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 3618 tg3_disable_ints(tp);
3539 0x00000001);
3540 return IRQ_RETVAL(1); 3619 return IRQ_RETVAL(1);
3541 } 3620 }
3542 return IRQ_RETVAL(0); 3621 return IRQ_RETVAL(0);
@@ -4644,6 +4723,44 @@ static void tg3_write_sig_legacy(struct tg3 *tp, int kind)
4644 } 4723 }
4645} 4724}
4646 4725
4726static int tg3_poll_fw(struct tg3 *tp)
4727{
4728 int i;
4729 u32 val;
4730
4731 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
4732 for (i = 0; i < 400; i++) {
4733 if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE)
4734 return 0;
4735 udelay(10);
4736 }
4737 return -ENODEV;
4738 }
4739
4740 /* Wait for firmware initialization to complete. */
4741 for (i = 0; i < 100000; i++) {
4742 tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val);
4743 if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
4744 break;
4745 udelay(10);
4746 }
4747
4748 /* Chip might not be fitted with firmware. Some Sun onboard
4749 * parts are configured like that. So don't signal the timeout
4750 * of the above loop as an error, but do report the lack of
4751 * running firmware once.
4752 */
4753 if (i >= 100000 &&
4754 !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) {
4755 tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED;
4756
4757 printk(KERN_INFO PFX "%s: No firmware running.\n",
4758 tp->dev->name);
4759 }
4760
4761 return 0;
4762}
4763
4647static void tg3_stop_fw(struct tg3 *); 4764static void tg3_stop_fw(struct tg3 *);
4648 4765
4649/* tp->lock is held. */ 4766/* tp->lock is held. */
@@ -4651,7 +4768,7 @@ static int tg3_chip_reset(struct tg3 *tp)
4651{ 4768{
4652 u32 val; 4769 u32 val;
4653 void (*write_op)(struct tg3 *, u32, u32); 4770 void (*write_op)(struct tg3 *, u32, u32);
4654 int i; 4771 int err;
4655 4772
4656 tg3_nvram_lock(tp); 4773 tg3_nvram_lock(tp);
4657 4774
@@ -4688,6 +4805,12 @@ static int tg3_chip_reset(struct tg3 *tp)
4688 } 4805 }
4689 } 4806 }
4690 4807
4808 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
4809 tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET);
4810 tw32(GRC_VCPU_EXT_CTRL,
4811 tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU);
4812 }
4813
4691 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) 4814 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
4692 val |= GRC_MISC_CFG_KEEP_GPHY_POWER; 4815 val |= GRC_MISC_CFG_KEEP_GPHY_POWER;
4693 tw32(GRC_MISC_CFG, val); 4816 tw32(GRC_MISC_CFG, val);
@@ -4811,26 +4934,9 @@ static int tg3_chip_reset(struct tg3 *tp)
4811 tw32_f(MAC_MODE, 0); 4934 tw32_f(MAC_MODE, 0);
4812 udelay(40); 4935 udelay(40);
4813 4936
4814 /* Wait for firmware initialization to complete. */ 4937 err = tg3_poll_fw(tp);
4815 for (i = 0; i < 100000; i++) { 4938 if (err)
4816 tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val); 4939 return err;
4817 if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
4818 break;
4819 udelay(10);
4820 }
4821
4822 /* Chip might not be fitted with firmare. Some Sun onboard
4823 * parts are configured like that. So don't signal the timeout
4824 * of the above loop as an error, but do report the lack of
4825 * running firmware once.
4826 */
4827 if (i >= 100000 &&
4828 !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) {
4829 tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED;
4830
4831 printk(KERN_INFO PFX "%s: No firmware running.\n",
4832 tp->dev->name);
4833 }
4834 4940
4835 if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) && 4941 if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
4836 tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) { 4942 tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
@@ -5036,6 +5142,12 @@ static int tg3_halt_cpu(struct tg3 *tp, u32 offset)
5036 BUG_ON(offset == TX_CPU_BASE && 5142 BUG_ON(offset == TX_CPU_BASE &&
5037 (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)); 5143 (tp->tg3_flags2 & TG3_FLG2_5705_PLUS));
5038 5144
5145 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
5146 u32 val = tr32(GRC_VCPU_EXT_CTRL);
5147
5148 tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU);
5149 return 0;
5150 }
5039 if (offset == RX_CPU_BASE) { 5151 if (offset == RX_CPU_BASE) {
5040 for (i = 0; i < 10000; i++) { 5152 for (i = 0; i < 10000; i++) {
5041 tw32(offset + CPU_STATE, 0xffffffff); 5153 tw32(offset + CPU_STATE, 0xffffffff);
@@ -6040,6 +6152,13 @@ static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
6040 val = 1; 6152 val = 1;
6041 else if (val > tp->rx_std_max_post) 6153 else if (val > tp->rx_std_max_post)
6042 val = tp->rx_std_max_post; 6154 val = tp->rx_std_max_post;
6155 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
6156 if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1)
6157 tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2);
6158
6159 if (val > (TG3_RX_INTERNAL_RING_SZ_5906 / 2))
6160 val = TG3_RX_INTERNAL_RING_SZ_5906 / 2;
6161 }
6043 6162
6044 tw32(RCVBDI_STD_THRESH, val); 6163 tw32(RCVBDI_STD_THRESH, val);
6045 6164
@@ -6460,7 +6579,8 @@ static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
6460 if (err) 6579 if (err)
6461 return err; 6580 return err;
6462 6581
6463 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) { 6582 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
6583 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906) {
6464 u32 tmp; 6584 u32 tmp;
6465 6585
6466 /* Clear CRC stats. */ 6586 /* Clear CRC stats. */
@@ -6660,12 +6780,14 @@ static void tg3_timer(unsigned long __opaque)
6660 need_setup = 1; 6780 need_setup = 1;
6661 } 6781 }
6662 if (need_setup) { 6782 if (need_setup) {
6663 tw32_f(MAC_MODE, 6783 if (!tp->serdes_counter) {
6664 (tp->mac_mode & 6784 tw32_f(MAC_MODE,
6665 ~MAC_MODE_PORT_MODE_MASK)); 6785 (tp->mac_mode &
6666 udelay(40); 6786 ~MAC_MODE_PORT_MODE_MASK));
6667 tw32_f(MAC_MODE, tp->mac_mode); 6787 udelay(40);
6668 udelay(40); 6788 tw32_f(MAC_MODE, tp->mac_mode);
6789 udelay(40);
6790 }
6669 tg3_setup_phy(tp, 0); 6791 tg3_setup_phy(tp, 0);
6670 } 6792 }
6671 } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) 6793 } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
@@ -6674,13 +6796,29 @@ static void tg3_timer(unsigned long __opaque)
6674 tp->timer_counter = tp->timer_multiplier; 6796 tp->timer_counter = tp->timer_multiplier;
6675 } 6797 }
6676 6798
6677 /* Heartbeat is only sent once every 2 seconds. */ 6799 /* Heartbeat is only sent once every 2 seconds.
6800 *
6801 * The heartbeat is to tell the ASF firmware that the host
6802 * driver is still alive. In the event that the OS crashes,
6803 * ASF needs to reset the hardware to free up the FIFO space
6804 * that may be filled with rx packets destined for the host.
6805 * If the FIFO is full, ASF will no longer function properly.
6806 *
6807 * Unintended resets have been reported on real time kernels
6808 * where the timer doesn't run on time. Netpoll will also have
6809 * same problem.
6810 *
6811 * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware
6812 * to check the ring condition when the heartbeat is expiring
6813 * before doing the reset. This will prevent most unintended
6814 * resets.
6815 */
6678 if (!--tp->asf_counter) { 6816 if (!--tp->asf_counter) {
6679 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) { 6817 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
6680 u32 val; 6818 u32 val;
6681 6819
6682 tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, 6820 tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX,
6683 FWCMD_NICDRV_ALIVE2); 6821 FWCMD_NICDRV_ALIVE3);
6684 tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); 6822 tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
6685 /* 5 seconds timeout */ 6823 /* 5 seconds timeout */
6686 tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5); 6824 tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
@@ -6721,8 +6859,7 @@ static int tg3_request_irq(struct tg3 *tp)
6721static int tg3_test_interrupt(struct tg3 *tp) 6859static int tg3_test_interrupt(struct tg3 *tp)
6722{ 6860{
6723 struct net_device *dev = tp->dev; 6861 struct net_device *dev = tp->dev;
6724 int err, i; 6862 int err, i, intr_ok = 0;
6725 u32 int_mbox = 0;
6726 6863
6727 if (!netif_running(dev)) 6864 if (!netif_running(dev))
6728 return -ENODEV; 6865 return -ENODEV;
@@ -6743,10 +6880,18 @@ static int tg3_test_interrupt(struct tg3 *tp)
6743 HOSTCC_MODE_NOW); 6880 HOSTCC_MODE_NOW);
6744 6881
6745 for (i = 0; i < 5; i++) { 6882 for (i = 0; i < 5; i++) {
6883 u32 int_mbox, misc_host_ctrl;
6884
6746 int_mbox = tr32_mailbox(MAILBOX_INTERRUPT_0 + 6885 int_mbox = tr32_mailbox(MAILBOX_INTERRUPT_0 +
6747 TG3_64BIT_REG_LOW); 6886 TG3_64BIT_REG_LOW);
6748 if (int_mbox != 0) 6887 misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
6888
6889 if ((int_mbox != 0) ||
6890 (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) {
6891 intr_ok = 1;
6749 break; 6892 break;
6893 }
6894
6750 msleep(10); 6895 msleep(10);
6751 } 6896 }
6752 6897
@@ -6759,7 +6904,7 @@ static int tg3_test_interrupt(struct tg3 *tp)
6759 if (err) 6904 if (err)
6760 return err; 6905 return err;
6761 6906
6762 if (int_mbox != 0) 6907 if (intr_ok)
6763 return 0; 6908 return 0;
6764 6909
6765 return -EIO; 6910 return -EIO;
@@ -6936,9 +7081,10 @@ static int tg3_open(struct net_device *dev)
6936 7081
6937 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) { 7082 if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
6938 if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) { 7083 if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) {
6939 u32 val = tr32(0x7c04); 7084 u32 val = tr32(PCIE_TRANSACTION_CFG);
6940 7085
6941 tw32(0x7c04, val | (1 << 29)); 7086 tw32(PCIE_TRANSACTION_CFG,
7087 val | PCIE_TRANS_CFG_1SHOT_MSI);
6942 } 7088 }
6943 } 7089 }
6944 } 7090 }
@@ -7857,7 +8003,7 @@ static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
7857 if (wol->wolopts & ~WAKE_MAGIC) 8003 if (wol->wolopts & ~WAKE_MAGIC)
7858 return -EINVAL; 8004 return -EINVAL;
7859 if ((wol->wolopts & WAKE_MAGIC) && 8005 if ((wol->wolopts & WAKE_MAGIC) &&
7860 tp->tg3_flags2 & TG3_FLG2_PHY_SERDES && 8006 tp->tg3_flags2 & TG3_FLG2_ANY_SERDES &&
7861 !(tp->tg3_flags & TG3_FLAG_SERDES_WOL_CAP)) 8007 !(tp->tg3_flags & TG3_FLAG_SERDES_WOL_CAP))
7862 return -EINVAL; 8008 return -EINVAL;
7863 8009
@@ -7893,7 +8039,8 @@ static int tg3_set_tso(struct net_device *dev, u32 value)
7893 return -EINVAL; 8039 return -EINVAL;
7894 return 0; 8040 return 0;
7895 } 8041 }
7896 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) { 8042 if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
8043 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)) {
7897 if (value) 8044 if (value)
7898 dev->features |= NETIF_F_TSO6; 8045 dev->features |= NETIF_F_TSO6;
7899 else 8046 else
@@ -8147,6 +8294,8 @@ static void tg3_get_ethtool_stats (struct net_device *dev,
8147 8294
8148#define NVRAM_TEST_SIZE 0x100 8295#define NVRAM_TEST_SIZE 0x100
8149#define NVRAM_SELFBOOT_FORMAT1_SIZE 0x14 8296#define NVRAM_SELFBOOT_FORMAT1_SIZE 0x14
8297#define NVRAM_SELFBOOT_HW_SIZE 0x20
8298#define NVRAM_SELFBOOT_DATA_SIZE 0x1c
8150 8299
8151static int tg3_test_nvram(struct tg3 *tp) 8300static int tg3_test_nvram(struct tg3 *tp)
8152{ 8301{
@@ -8158,12 +8307,14 @@ static int tg3_test_nvram(struct tg3 *tp)
8158 8307
8159 if (magic == TG3_EEPROM_MAGIC) 8308 if (magic == TG3_EEPROM_MAGIC)
8160 size = NVRAM_TEST_SIZE; 8309 size = NVRAM_TEST_SIZE;
8161 else if ((magic & 0xff000000) == 0xa5000000) { 8310 else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) {
8162 if ((magic & 0xe00000) == 0x200000) 8311 if ((magic & 0xe00000) == 0x200000)
8163 size = NVRAM_SELFBOOT_FORMAT1_SIZE; 8312 size = NVRAM_SELFBOOT_FORMAT1_SIZE;
8164 else 8313 else
8165 return 0; 8314 return 0;
8166 } else 8315 } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW)
8316 size = NVRAM_SELFBOOT_HW_SIZE;
8317 else
8167 return -EIO; 8318 return -EIO;
8168 8319
8169 buf = kmalloc(size, GFP_KERNEL); 8320 buf = kmalloc(size, GFP_KERNEL);
@@ -8182,7 +8333,8 @@ static int tg3_test_nvram(struct tg3 *tp)
8182 goto out; 8333 goto out;
8183 8334
8184 /* Selfboot format */ 8335 /* Selfboot format */
8185 if (cpu_to_be32(buf[0]) != TG3_EEPROM_MAGIC) { 8336 if ((cpu_to_be32(buf[0]) & TG3_EEPROM_MAGIC_FW_MSK) ==
8337 TG3_EEPROM_MAGIC_FW) {
8186 u8 *buf8 = (u8 *) buf, csum8 = 0; 8338 u8 *buf8 = (u8 *) buf, csum8 = 0;
8187 8339
8188 for (i = 0; i < size; i++) 8340 for (i = 0; i < size; i++)
@@ -8197,6 +8349,51 @@ static int tg3_test_nvram(struct tg3 *tp)
8197 goto out; 8349 goto out;
8198 } 8350 }
8199 8351
8352 if ((cpu_to_be32(buf[0]) & TG3_EEPROM_MAGIC_HW_MSK) ==
8353 TG3_EEPROM_MAGIC_HW) {
8354 u8 data[NVRAM_SELFBOOT_DATA_SIZE];
8355 u8 parity[NVRAM_SELFBOOT_DATA_SIZE];
8356 u8 *buf8 = (u8 *) buf;
8357 int j, k;
8358
8359 /* Separate the parity bits and the data bytes. */
8360 for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) {
8361 if ((i == 0) || (i == 8)) {
8362 int l;
8363 u8 msk;
8364
8365 for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1)
8366 parity[k++] = buf8[i] & msk;
8367 i++;
8368 }
8369 else if (i == 16) {
8370 int l;
8371 u8 msk;
8372
8373 for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1)
8374 parity[k++] = buf8[i] & msk;
8375 i++;
8376
8377 for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1)
8378 parity[k++] = buf8[i] & msk;
8379 i++;
8380 }
8381 data[j++] = buf8[i];
8382 }
8383
8384 err = -EIO;
8385 for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) {
8386 u8 hw8 = hweight8(data[i]);
8387
8388 if ((hw8 & 0x1) && parity[i])
8389 goto out;
8390 else if (!(hw8 & 0x1) && !parity[i])
8391 goto out;
8392 }
8393 err = 0;
8394 goto out;
8395 }
8396
8200 /* Bootstrap checksum at offset 0x10 */ 8397 /* Bootstrap checksum at offset 0x10 */
8201 csum = calc_crc((unsigned char *) buf, 0x10); 8398 csum = calc_crc((unsigned char *) buf, 0x10);
8202 if(csum != cpu_to_le32(buf[0x10/4])) 8399 if(csum != cpu_to_le32(buf[0x10/4]))
@@ -8243,7 +8440,7 @@ static int tg3_test_link(struct tg3 *tp)
8243/* Only test the commonly used registers */ 8440/* Only test the commonly used registers */
8244static int tg3_test_registers(struct tg3 *tp) 8441static int tg3_test_registers(struct tg3 *tp)
8245{ 8442{
8246 int i, is_5705; 8443 int i, is_5705, is_5750;
8247 u32 offset, read_mask, write_mask, val, save_val, read_val; 8444 u32 offset, read_mask, write_mask, val, save_val, read_val;
8248 static struct { 8445 static struct {
8249 u16 offset; 8446 u16 offset;
@@ -8251,6 +8448,7 @@ static int tg3_test_registers(struct tg3 *tp)
8251#define TG3_FL_5705 0x1 8448#define TG3_FL_5705 0x1
8252#define TG3_FL_NOT_5705 0x2 8449#define TG3_FL_NOT_5705 0x2
8253#define TG3_FL_NOT_5788 0x4 8450#define TG3_FL_NOT_5788 0x4
8451#define TG3_FL_NOT_5750 0x8
8254 u32 read_mask; 8452 u32 read_mask;
8255 u32 write_mask; 8453 u32 write_mask;
8256 } reg_tbl[] = { 8454 } reg_tbl[] = {
@@ -8361,9 +8559,9 @@ static int tg3_test_registers(struct tg3 *tp)
8361 0xffffffff, 0x00000000 }, 8559 0xffffffff, 0x00000000 },
8362 8560
8363 /* Buffer Manager Control Registers. */ 8561 /* Buffer Manager Control Registers. */
8364 { BUFMGR_MB_POOL_ADDR, 0x0000, 8562 { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750,
8365 0x00000000, 0x007fff80 }, 8563 0x00000000, 0x007fff80 },
8366 { BUFMGR_MB_POOL_SIZE, 0x0000, 8564 { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750,
8367 0x00000000, 0x007fffff }, 8565 0x00000000, 0x007fffff },
8368 { BUFMGR_MB_RDMA_LOW_WATER, 0x0000, 8566 { BUFMGR_MB_RDMA_LOW_WATER, 0x0000,
8369 0x00000000, 0x0000003f }, 8567 0x00000000, 0x0000003f },
@@ -8389,10 +8587,12 @@ static int tg3_test_registers(struct tg3 *tp)
8389 { 0xffff, 0x0000, 0x00000000, 0x00000000 }, 8587 { 0xffff, 0x0000, 0x00000000, 0x00000000 },
8390 }; 8588 };
8391 8589
8392 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) 8590 is_5705 = is_5750 = 0;
8591 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
8393 is_5705 = 1; 8592 is_5705 = 1;
8394 else 8593 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
8395 is_5705 = 0; 8594 is_5750 = 1;
8595 }
8396 8596
8397 for (i = 0; reg_tbl[i].offset != 0xffff; i++) { 8597 for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
8398 if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705)) 8598 if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705))
@@ -8405,6 +8605,9 @@ static int tg3_test_registers(struct tg3 *tp)
8405 (reg_tbl[i].flags & TG3_FL_NOT_5788)) 8605 (reg_tbl[i].flags & TG3_FL_NOT_5788))
8406 continue; 8606 continue;
8407 8607
8608 if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750))
8609 continue;
8610
8408 offset = (u32) reg_tbl[i].offset; 8611 offset = (u32) reg_tbl[i].offset;
8409 read_mask = reg_tbl[i].read_mask; 8612 read_mask = reg_tbl[i].read_mask;
8410 write_mask = reg_tbl[i].write_mask; 8613 write_mask = reg_tbl[i].write_mask;
@@ -8496,6 +8699,13 @@ static int tg3_test_memory(struct tg3 *tp)
8496 { 0x00008000, 0x02000}, 8699 { 0x00008000, 0x02000},
8497 { 0x00010000, 0x0c000}, 8700 { 0x00010000, 0x0c000},
8498 { 0xffffffff, 0x00000} 8701 { 0xffffffff, 0x00000}
8702 }, mem_tbl_5906[] = {
8703 { 0x00000200, 0x00008},
8704 { 0x00004000, 0x00400},
8705 { 0x00006000, 0x00400},
8706 { 0x00008000, 0x01000},
8707 { 0x00010000, 0x01000},
8708 { 0xffffffff, 0x00000}
8499 }; 8709 };
8500 struct mem_entry *mem_tbl; 8710 struct mem_entry *mem_tbl;
8501 int err = 0; 8711 int err = 0;
@@ -8505,6 +8715,8 @@ static int tg3_test_memory(struct tg3 *tp)
8505 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || 8715 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
8506 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) 8716 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
8507 mem_tbl = mem_tbl_5755; 8717 mem_tbl = mem_tbl_5755;
8718 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
8719 mem_tbl = mem_tbl_5906;
8508 else 8720 else
8509 mem_tbl = mem_tbl_5705; 8721 mem_tbl = mem_tbl_5705;
8510 } else 8722 } else
@@ -8541,13 +8753,41 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
8541 return 0; 8753 return 0;
8542 8754
8543 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) | 8755 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
8544 MAC_MODE_PORT_INT_LPBACK | MAC_MODE_LINK_POLARITY | 8756 MAC_MODE_PORT_INT_LPBACK | MAC_MODE_LINK_POLARITY;
8545 MAC_MODE_PORT_MODE_GMII; 8757 if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
8758 mac_mode |= MAC_MODE_PORT_MODE_MII;
8759 else
8760 mac_mode |= MAC_MODE_PORT_MODE_GMII;
8546 tw32(MAC_MODE, mac_mode); 8761 tw32(MAC_MODE, mac_mode);
8547 } else if (loopback_mode == TG3_PHY_LOOPBACK) { 8762 } else if (loopback_mode == TG3_PHY_LOOPBACK) {
8548 tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK | BMCR_FULLDPLX | 8763 u32 val;
8549 BMCR_SPEED1000); 8764
8765 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
8766 u32 phytest;
8767
8768 if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phytest)) {
8769 u32 phy;
8770
8771 tg3_writephy(tp, MII_TG3_EPHY_TEST,
8772 phytest | MII_TG3_EPHY_SHADOW_EN);
8773 if (!tg3_readphy(tp, 0x1b, &phy))
8774 tg3_writephy(tp, 0x1b, phy & ~0x20);
8775 if (!tg3_readphy(tp, 0x10, &phy))
8776 tg3_writephy(tp, 0x10, phy & ~0x4000);
8777 tg3_writephy(tp, MII_TG3_EPHY_TEST, phytest);
8778 }
8779 }
8780 val = BMCR_LOOPBACK | BMCR_FULLDPLX;
8781 if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
8782 val |= BMCR_SPEED100;
8783 else
8784 val |= BMCR_SPEED1000;
8785
8786 tg3_writephy(tp, MII_BMCR, val);
8550 udelay(40); 8787 udelay(40);
8788 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
8789 tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x1800);
8790
8551 /* reset to prevent losing 1st rx packet intermittently */ 8791 /* reset to prevent losing 1st rx packet intermittently */
8552 if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) { 8792 if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
8553 tw32_f(MAC_RX_MODE, RX_MODE_RESET); 8793 tw32_f(MAC_RX_MODE, RX_MODE_RESET);
@@ -8555,7 +8795,11 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
8555 tw32_f(MAC_RX_MODE, tp->rx_mode); 8795 tw32_f(MAC_RX_MODE, tp->rx_mode);
8556 } 8796 }
8557 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) | 8797 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
8558 MAC_MODE_LINK_POLARITY | MAC_MODE_PORT_MODE_GMII; 8798 MAC_MODE_LINK_POLARITY;
8799 if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
8800 mac_mode |= MAC_MODE_PORT_MODE_MII;
8801 else
8802 mac_mode |= MAC_MODE_PORT_MODE_GMII;
8559 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) { 8803 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
8560 mac_mode &= ~MAC_MODE_LINK_POLARITY; 8804 mac_mode &= ~MAC_MODE_LINK_POLARITY;
8561 tg3_writephy(tp, MII_TG3_EXT_CTRL, 8805 tg3_writephy(tp, MII_TG3_EXT_CTRL,
@@ -8604,7 +8848,8 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
8604 8848
8605 udelay(10); 8849 udelay(10);
8606 8850
8607 for (i = 0; i < 10; i++) { 8851 /* 250 usec to allow enough time on some 10/100 Mbps devices. */
8852 for (i = 0; i < 25; i++) {
8608 tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | 8853 tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
8609 HOSTCC_MODE_NOW); 8854 HOSTCC_MODE_NOW);
8610 8855
@@ -8956,7 +9201,9 @@ static void __devinit tg3_get_eeprom_size(struct tg3 *tp)
8956 if (tg3_nvram_read_swab(tp, 0, &magic) != 0) 9201 if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
8957 return; 9202 return;
8958 9203
8959 if ((magic != TG3_EEPROM_MAGIC) && ((magic & 0xff000000) != 0xa5000000)) 9204 if ((magic != TG3_EEPROM_MAGIC) &&
9205 ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) &&
9206 ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW))
8960 return; 9207 return;
8961 9208
8962 /* 9209 /*
@@ -9194,6 +9441,13 @@ static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp)
9194 } 9441 }
9195} 9442}
9196 9443
9444static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp)
9445{
9446 tp->nvram_jedecnum = JEDEC_ATMEL;
9447 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
9448 tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
9449}
9450
9197/* Chips other than 5700/5701 use the NVRAM for fetching info. */ 9451/* Chips other than 5700/5701 use the NVRAM for fetching info. */
9198static void __devinit tg3_nvram_init(struct tg3 *tp) 9452static void __devinit tg3_nvram_init(struct tg3 *tp)
9199{ 9453{
@@ -9230,6 +9484,8 @@ static void __devinit tg3_nvram_init(struct tg3 *tp)
9230 tg3_get_5755_nvram_info(tp); 9484 tg3_get_5755_nvram_info(tp);
9231 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) 9485 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
9232 tg3_get_5787_nvram_info(tp); 9486 tg3_get_5787_nvram_info(tp);
9487 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
9488 tg3_get_5906_nvram_info(tp);
9233 else 9489 else
9234 tg3_get_nvram_info(tp); 9490 tg3_get_nvram_info(tp);
9235 9491
@@ -9703,6 +9959,12 @@ static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
9703 /* Assume an onboard device by default. */ 9959 /* Assume an onboard device by default. */
9704 tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT; 9960 tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
9705 9961
9962 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
9963 if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM))
9964 tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
9965 return;
9966 }
9967
9706 tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); 9968 tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
9707 if (val == NIC_SRAM_DATA_SIG_MAGIC) { 9969 if (val == NIC_SRAM_DATA_SIG_MAGIC) {
9708 u32 nic_cfg, led_cfg; 9970 u32 nic_cfg, led_cfg;
@@ -10034,7 +10296,10 @@ static void __devinit tg3_read_partno(struct tg3 *tp)
10034 } 10296 }
10035 10297
10036out_not_found: 10298out_not_found:
10037 strcpy(tp->board_part_number, "none"); 10299 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
10300 strcpy(tp->board_part_number, "BCM95906");
10301 else
10302 strcpy(tp->board_part_number, "none");
10038} 10303}
10039 10304
10040static void __devinit tg3_read_fw_ver(struct tg3 *tp) 10305static void __devinit tg3_read_fw_ver(struct tg3 *tp)
@@ -10236,6 +10501,7 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10236 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || 10501 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
10237 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || 10502 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
10238 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || 10503 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
10504 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
10239 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) 10505 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
10240 tp->tg3_flags2 |= TG3_FLG2_5750_PLUS; 10506 tp->tg3_flags2 |= TG3_FLG2_5750_PLUS;
10241 10507
@@ -10245,7 +10511,8 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10245 10511
10246 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { 10512 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
10247 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || 10513 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
10248 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) { 10514 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
10515 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
10249 tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2; 10516 tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2;
10250 tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI; 10517 tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI;
10251 } else { 10518 } else {
@@ -10262,7 +10529,8 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10262 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750 && 10529 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750 &&
10263 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 && 10530 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 &&
10264 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755 && 10531 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755 &&
10265 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) 10532 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787 &&
10533 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
10266 tp->tg3_flags2 |= TG3_FLG2_JUMBO_CAPABLE; 10534 tp->tg3_flags2 |= TG3_FLG2_JUMBO_CAPABLE;
10267 10535
10268 if (pci_find_capability(tp->pdev, PCI_CAP_ID_EXP) != 0) 10536 if (pci_find_capability(tp->pdev, PCI_CAP_ID_EXP) != 0)
@@ -10392,6 +10660,12 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10392 pci_cmd &= ~PCI_COMMAND_MEMORY; 10660 pci_cmd &= ~PCI_COMMAND_MEMORY;
10393 pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); 10661 pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
10394 } 10662 }
10663 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
10664 tp->read32_mbox = tg3_read32_mbox_5906;
10665 tp->write32_mbox = tg3_write32_mbox_5906;
10666 tp->write32_tx_mbox = tg3_write32_mbox_5906;
10667 tp->write32_rx_mbox = tg3_write32_mbox_5906;
10668 }
10395 10669
10396 if (tp->write32 == tg3_write_indirect_reg32 || 10670 if (tp->write32 == tg3_write_indirect_reg32 ||
10397 ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) && 10671 ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
@@ -10463,6 +10737,7 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10463 ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && 10737 ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
10464 (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) && 10738 (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) &&
10465 (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) || 10739 (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) ||
10740 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) ||
10466 (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) 10741 (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
10467 tp->tg3_flags2 |= TG3_FLG2_NO_ETH_WIRE_SPEED; 10742 tp->tg3_flags2 |= TG3_FLG2_NO_ETH_WIRE_SPEED;
10468 10743
@@ -10476,7 +10751,7 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10476 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || 10751 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
10477 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) 10752 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
10478 tp->tg3_flags2 |= TG3_FLG2_PHY_JITTER_BUG; 10753 tp->tg3_flags2 |= TG3_FLG2_PHY_JITTER_BUG;
10479 else 10754 else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
10480 tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG; 10755 tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG;
10481 } 10756 }
10482 10757
@@ -10566,7 +10841,8 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10566 tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) || 10841 tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) ||
10567 (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && 10842 (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
10568 (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F || 10843 (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F ||
10569 tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F))) 10844 tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F)) ||
10845 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
10570 tp->tg3_flags |= TG3_FLAG_10_100_ONLY; 10846 tp->tg3_flags |= TG3_FLAG_10_100_ONLY;
10571 10847
10572 err = tg3_phy_probe(tp); 10848 err = tg3_phy_probe(tp);
@@ -10617,7 +10893,8 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10617 * straddle the 4GB address boundary in some cases. 10893 * straddle the 4GB address boundary in some cases.
10618 */ 10894 */
10619 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || 10895 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
10620 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) 10896 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
10897 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
10621 tp->dev->hard_start_xmit = tg3_start_xmit; 10898 tp->dev->hard_start_xmit = tg3_start_xmit;
10622 else 10899 else
10623 tp->dev->hard_start_xmit = tg3_start_xmit_dma_bug; 10900 tp->dev->hard_start_xmit = tg3_start_xmit_dma_bug;
@@ -10698,6 +10975,8 @@ static int __devinit tg3_get_device_address(struct tg3 *tp)
10698 else 10975 else
10699 tg3_nvram_unlock(tp); 10976 tg3_nvram_unlock(tp);
10700 } 10977 }
10978 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
10979 mac_offset = 0x10;
10701 10980
10702 /* First try to get it from MAC address mailbox. */ 10981 /* First try to get it from MAC address mailbox. */
10703 tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi); 10982 tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi);
@@ -11181,6 +11460,12 @@ static void __devinit tg3_init_bufmgr_config(struct tg3 *tp)
11181 DEFAULT_MB_MACRX_LOW_WATER_5705; 11460 DEFAULT_MB_MACRX_LOW_WATER_5705;
11182 tp->bufmgr_config.mbuf_high_water = 11461 tp->bufmgr_config.mbuf_high_water =
11183 DEFAULT_MB_HIGH_WATER_5705; 11462 DEFAULT_MB_HIGH_WATER_5705;
11463 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
11464 tp->bufmgr_config.mbuf_mac_rx_low_water =
11465 DEFAULT_MB_MACRX_LOW_WATER_5906;
11466 tp->bufmgr_config.mbuf_high_water =
11467 DEFAULT_MB_HIGH_WATER_5906;
11468 }
11184 11469
11185 tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = 11470 tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
11186 DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780; 11471 DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780;
@@ -11224,6 +11509,8 @@ static char * __devinit tg3_phy_string(struct tg3 *tp)
11224 case PHY_ID_BCM5780: return "5780"; 11509 case PHY_ID_BCM5780: return "5780";
11225 case PHY_ID_BCM5755: return "5755"; 11510 case PHY_ID_BCM5755: return "5755";
11226 case PHY_ID_BCM5787: return "5787"; 11511 case PHY_ID_BCM5787: return "5787";
11512 case PHY_ID_BCM5756: return "5722/5756";
11513 case PHY_ID_BCM5906: return "5906";
11227 case PHY_ID_BCM8002: return "8002/serdes"; 11514 case PHY_ID_BCM8002: return "8002/serdes";
11228 case 0: return "serdes"; 11515 case 0: return "serdes";
11229 default: return "unknown"; 11516 default: return "unknown";
@@ -11526,7 +11813,8 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
11526 */ 11813 */
11527 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) { 11814 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
11528 dev->features |= NETIF_F_TSO; 11815 dev->features |= NETIF_F_TSO;
11529 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) 11816 if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
11817 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906))
11530 dev->features |= NETIF_F_TSO6; 11818 dev->features |= NETIF_F_TSO6;
11531 } 11819 }
11532 11820
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index 3ecf356cfb08..92f53000bce6 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -24,6 +24,8 @@
24 24
25#define RX_COPY_THRESHOLD 256 25#define RX_COPY_THRESHOLD 256
26 26
27#define TG3_RX_INTERNAL_RING_SZ_5906 32
28
27#define RX_STD_MAX_SIZE 1536 29#define RX_STD_MAX_SIZE 1536
28#define RX_STD_MAX_SIZE_5705 512 30#define RX_STD_MAX_SIZE_5705 512
29#define RX_JUMBO_MAX_SIZE 0xdeadbeef /* XXX */ 31#define RX_JUMBO_MAX_SIZE 0xdeadbeef /* XXX */
@@ -129,6 +131,7 @@
129#define CHIPREV_ID_5752_A0_HW 0x5000 131#define CHIPREV_ID_5752_A0_HW 0x5000
130#define CHIPREV_ID_5752_A0 0x6000 132#define CHIPREV_ID_5752_A0 0x6000
131#define CHIPREV_ID_5752_A1 0x6001 133#define CHIPREV_ID_5752_A1 0x6001
134#define CHIPREV_ID_5906_A1 0xc001
132#define GET_ASIC_REV(CHIP_REV_ID) ((CHIP_REV_ID) >> 12) 135#define GET_ASIC_REV(CHIP_REV_ID) ((CHIP_REV_ID) >> 12)
133#define ASIC_REV_5700 0x07 136#define ASIC_REV_5700 0x07
134#define ASIC_REV_5701 0x00 137#define ASIC_REV_5701 0x00
@@ -141,6 +144,7 @@
141#define ASIC_REV_5714 0x09 144#define ASIC_REV_5714 0x09
142#define ASIC_REV_5755 0x0a 145#define ASIC_REV_5755 0x0a
143#define ASIC_REV_5787 0x0b 146#define ASIC_REV_5787 0x0b
147#define ASIC_REV_5906 0x0c
144#define GET_CHIP_REV(CHIP_REV_ID) ((CHIP_REV_ID) >> 8) 148#define GET_CHIP_REV(CHIP_REV_ID) ((CHIP_REV_ID) >> 8)
145#define CHIPREV_5700_AX 0x70 149#define CHIPREV_5700_AX 0x70
146#define CHIPREV_5700_BX 0x71 150#define CHIPREV_5700_BX 0x71
@@ -646,7 +650,8 @@
646#define SNDDATAI_SCTRL_FORCE_ZERO 0x00000010 650#define SNDDATAI_SCTRL_FORCE_ZERO 0x00000010
647#define SNDDATAI_STATSENAB 0x00000c0c 651#define SNDDATAI_STATSENAB 0x00000c0c
648#define SNDDATAI_STATSINCMASK 0x00000c10 652#define SNDDATAI_STATSINCMASK 0x00000c10
649/* 0xc14 --> 0xc80 unused */ 653#define ISO_PKT_TX 0x00000c20
654/* 0xc24 --> 0xc80 unused */
650#define SNDDATAI_COS_CNT_0 0x00000c80 655#define SNDDATAI_COS_CNT_0 0x00000c80
651#define SNDDATAI_COS_CNT_1 0x00000c84 656#define SNDDATAI_COS_CNT_1 0x00000c84
652#define SNDDATAI_COS_CNT_2 0x00000c88 657#define SNDDATAI_COS_CNT_2 0x00000c88
@@ -997,11 +1002,13 @@
997#define BUFMGR_MB_MACRX_LOW_WATER 0x00004414 1002#define BUFMGR_MB_MACRX_LOW_WATER 0x00004414
998#define DEFAULT_MB_MACRX_LOW_WATER 0x00000020 1003#define DEFAULT_MB_MACRX_LOW_WATER 0x00000020
999#define DEFAULT_MB_MACRX_LOW_WATER_5705 0x00000010 1004#define DEFAULT_MB_MACRX_LOW_WATER_5705 0x00000010
1005#define DEFAULT_MB_MACRX_LOW_WATER_5906 0x00000004
1000#define DEFAULT_MB_MACRX_LOW_WATER_JUMBO 0x00000098 1006#define DEFAULT_MB_MACRX_LOW_WATER_JUMBO 0x00000098
1001#define DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780 0x0000004b 1007#define DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780 0x0000004b
1002#define BUFMGR_MB_HIGH_WATER 0x00004418 1008#define BUFMGR_MB_HIGH_WATER 0x00004418
1003#define DEFAULT_MB_HIGH_WATER 0x00000060 1009#define DEFAULT_MB_HIGH_WATER 0x00000060
1004#define DEFAULT_MB_HIGH_WATER_5705 0x00000060 1010#define DEFAULT_MB_HIGH_WATER_5705 0x00000060
1011#define DEFAULT_MB_HIGH_WATER_5906 0x00000010
1005#define DEFAULT_MB_HIGH_WATER_JUMBO 0x0000017c 1012#define DEFAULT_MB_HIGH_WATER_JUMBO 0x0000017c
1006#define DEFAULT_MB_HIGH_WATER_JUMBO_5780 0x00000096 1013#define DEFAULT_MB_HIGH_WATER_JUMBO_5780 0x00000096
1007#define BUFMGR_RX_MB_ALLOC_REQ 0x0000441c 1014#define BUFMGR_RX_MB_ALLOC_REQ 0x0000441c
@@ -1138,7 +1145,12 @@
1138#define TX_CPU_STATE 0x00005404 1145#define TX_CPU_STATE 0x00005404
1139#define TX_CPU_PGMCTR 0x0000541c 1146#define TX_CPU_PGMCTR 0x0000541c
1140 1147
1148#define VCPU_STATUS 0x00005100
1149#define VCPU_STATUS_INIT_DONE 0x04000000
1150#define VCPU_STATUS_DRV_RESET 0x08000000
1151
1141/* Mailboxes */ 1152/* Mailboxes */
1153#define GRCMBOX_BASE 0x00005600
1142#define GRCMBOX_INTERRUPT_0 0x00005800 /* 64-bit */ 1154#define GRCMBOX_INTERRUPT_0 0x00005800 /* 64-bit */
1143#define GRCMBOX_INTERRUPT_1 0x00005808 /* 64-bit */ 1155#define GRCMBOX_INTERRUPT_1 0x00005808 /* 64-bit */
1144#define GRCMBOX_INTERRUPT_2 0x00005810 /* 64-bit */ 1156#define GRCMBOX_INTERRUPT_2 0x00005810 /* 64-bit */
@@ -1398,7 +1410,10 @@
1398#define GRC_EEPROM_CTRL 0x00006840 1410#define GRC_EEPROM_CTRL 0x00006840
1399#define GRC_MDI_CTRL 0x00006844 1411#define GRC_MDI_CTRL 0x00006844
1400#define GRC_SEEPROM_DELAY 0x00006848 1412#define GRC_SEEPROM_DELAY 0x00006848
1401/* 0x684c --> 0x6c00 unused */ 1413/* 0x684c --> 0x6890 unused */
1414#define GRC_VCPU_EXT_CTRL 0x00006890
1415#define GRC_VCPU_EXT_CTRL_HALT_CPU 0x00400000
1416#define GRC_VCPU_EXT_CTRL_DISABLE_WOL 0x20000000
1402#define GRC_FASTBOOT_PC 0x00006894 /* 5752, 5755, 5787 */ 1417#define GRC_FASTBOOT_PC 0x00006894 /* 5752, 5755, 5787 */
1403 1418
1404/* 0x6c00 --> 0x7000 unused */ 1419/* 0x6c00 --> 0x7000 unused */
@@ -1485,9 +1500,17 @@
1485#define NVRAM_WRITE1 0x00007028 1500#define NVRAM_WRITE1 0x00007028
1486/* 0x702c --> 0x7400 unused */ 1501/* 0x702c --> 0x7400 unused */
1487 1502
1488/* 0x7400 --> 0x8000 unused */ 1503/* 0x7400 --> 0x7c00 unused */
1504#define PCIE_TRANSACTION_CFG 0x00007c04
1505#define PCIE_TRANS_CFG_1SHOT_MSI 0x20000000
1506#define PCIE_TRANS_CFG_LOM 0x00000020
1507
1489 1508
1490#define TG3_EEPROM_MAGIC 0x669955aa 1509#define TG3_EEPROM_MAGIC 0x669955aa
1510#define TG3_EEPROM_MAGIC_FW 0xa5000000
1511#define TG3_EEPROM_MAGIC_FW_MSK 0xff000000
1512#define TG3_EEPROM_MAGIC_HW 0xabcd
1513#define TG3_EEPROM_MAGIC_HW_MSK 0xffff
1491 1514
1492/* 32K Window into NIC internal memory */ 1515/* 32K Window into NIC internal memory */
1493#define NIC_SRAM_WIN_BASE 0x00008000 1516#define NIC_SRAM_WIN_BASE 0x00008000
@@ -1537,6 +1560,7 @@
1537#define FWCMD_NICDRV_FIX_DMAR 0x00000005 1560#define FWCMD_NICDRV_FIX_DMAR 0x00000005
1538#define FWCMD_NICDRV_FIX_DMAW 0x00000006 1561#define FWCMD_NICDRV_FIX_DMAW 0x00000006
1539#define FWCMD_NICDRV_ALIVE2 0x0000000d 1562#define FWCMD_NICDRV_ALIVE2 0x0000000d
1563#define FWCMD_NICDRV_ALIVE3 0x0000000e
1540#define NIC_SRAM_FW_CMD_LEN_MBOX 0x00000b7c 1564#define NIC_SRAM_FW_CMD_LEN_MBOX 0x00000b7c
1541#define NIC_SRAM_FW_CMD_DATA_MBOX 0x00000b80 1565#define NIC_SRAM_FW_CMD_DATA_MBOX 0x00000b80
1542#define NIC_SRAM_FW_ASF_STATUS_MBOX 0x00000c00 1566#define NIC_SRAM_FW_ASF_STATUS_MBOX 0x00000c00
@@ -1604,6 +1628,7 @@
1604#define MII_TG3_DSP_RW_PORT 0x15 /* DSP coefficient read/write port */ 1628#define MII_TG3_DSP_RW_PORT 0x15 /* DSP coefficient read/write port */
1605 1629
1606#define MII_TG3_DSP_ADDRESS 0x17 /* DSP address register */ 1630#define MII_TG3_DSP_ADDRESS 0x17 /* DSP address register */
1631#define MII_TG3_EPHY_PTEST 0x17 /* 5906 PHY register */
1607 1632
1608#define MII_TG3_AUX_CTRL 0x18 /* auxilliary control register */ 1633#define MII_TG3_AUX_CTRL 0x18 /* auxilliary control register */
1609 1634
@@ -1617,6 +1642,8 @@
1617#define MII_TG3_AUX_STAT_100FULL 0x0500 1642#define MII_TG3_AUX_STAT_100FULL 0x0500
1618#define MII_TG3_AUX_STAT_1000HALF 0x0600 1643#define MII_TG3_AUX_STAT_1000HALF 0x0600
1619#define MII_TG3_AUX_STAT_1000FULL 0x0700 1644#define MII_TG3_AUX_STAT_1000FULL 0x0700
1645#define MII_TG3_AUX_STAT_100 0x0008
1646#define MII_TG3_AUX_STAT_FULL 0x0001
1620 1647
1621#define MII_TG3_ISTAT 0x1a /* IRQ status register */ 1648#define MII_TG3_ISTAT 0x1a /* IRQ status register */
1622#define MII_TG3_IMASK 0x1b /* IRQ mask register */ 1649#define MII_TG3_IMASK 0x1b /* IRQ mask register */
@@ -1627,6 +1654,9 @@
1627#define MII_TG3_INT_DUPLEXCHG 0x0008 1654#define MII_TG3_INT_DUPLEXCHG 0x0008
1628#define MII_TG3_INT_ANEG_PAGE_RX 0x0400 1655#define MII_TG3_INT_ANEG_PAGE_RX 0x0400
1629 1656
1657#define MII_TG3_EPHY_TEST 0x1f /* 5906 PHY register */
1658#define MII_TG3_EPHY_SHADOW_EN 0x80
1659
1630/* There are two ways to manage the TX descriptors on the tigon3. 1660/* There are two ways to manage the TX descriptors on the tigon3.
1631 * Either the descriptors are in host DMA'able memory, or they 1661 * Either the descriptors are in host DMA'able memory, or they
1632 * exist only in the cards on-chip SRAM. All 16 send bds are under 1662 * exist only in the cards on-chip SRAM. All 16 send bds are under
@@ -2203,7 +2233,6 @@ struct tg3 {
2203#define TG3_FLG2_PCI_EXPRESS 0x00000200 2233#define TG3_FLG2_PCI_EXPRESS 0x00000200
2204#define TG3_FLG2_ASF_NEW_HANDSHAKE 0x00000400 2234#define TG3_FLG2_ASF_NEW_HANDSHAKE 0x00000400
2205#define TG3_FLG2_HW_AUTONEG 0x00000800 2235#define TG3_FLG2_HW_AUTONEG 0x00000800
2206#define TG3_FLG2_PHY_JUST_INITTED 0x00001000
2207#define TG3_FLG2_PHY_SERDES 0x00002000 2236#define TG3_FLG2_PHY_SERDES 0x00002000
2208#define TG3_FLG2_CAPACITIVE_COUPLING 0x00004000 2237#define TG3_FLG2_CAPACITIVE_COUPLING 0x00004000
2209#define TG3_FLG2_FLASH 0x00008000 2238#define TG3_FLG2_FLASH 0x00008000
@@ -2236,6 +2265,12 @@ struct tg3 {
2236 u16 asf_counter; 2265 u16 asf_counter;
2237 u16 asf_multiplier; 2266 u16 asf_multiplier;
2238 2267
2268 /* 1 second counter for transient serdes link events */
2269 u32 serdes_counter;
2270#define SERDES_AN_TIMEOUT_5704S 2
2271#define SERDES_PARALLEL_DET_TIMEOUT 1
2272#define SERDES_AN_TIMEOUT_5714S 1
2273
2239 struct tg3_link_config link_config; 2274 struct tg3_link_config link_config;
2240 struct tg3_bufmgr_config bufmgr_config; 2275 struct tg3_bufmgr_config bufmgr_config;
2241 2276
@@ -2276,6 +2311,8 @@ struct tg3 {
2276#define PHY_ID_BCM5780 0x60008350 2311#define PHY_ID_BCM5780 0x60008350
2277#define PHY_ID_BCM5755 0xbc050cc0 2312#define PHY_ID_BCM5755 0xbc050cc0
2278#define PHY_ID_BCM5787 0xbc050ce0 2313#define PHY_ID_BCM5787 0xbc050ce0
2314#define PHY_ID_BCM5756 0xbc050ed0
2315#define PHY_ID_BCM5906 0xdc00ac40
2279#define PHY_ID_BCM8002 0x60010140 2316#define PHY_ID_BCM8002 0x60010140
2280#define PHY_ID_INVALID 0xffffffff 2317#define PHY_ID_INVALID 0xffffffff
2281#define PHY_ID_REV_MASK 0x0000000f 2318#define PHY_ID_REV_MASK 0x0000000f
@@ -2302,7 +2339,8 @@ struct tg3 {
2302 (X) == PHY_ID_BCM5705 || (X) == PHY_ID_BCM5750 || \ 2339 (X) == PHY_ID_BCM5705 || (X) == PHY_ID_BCM5750 || \
2303 (X) == PHY_ID_BCM5752 || (X) == PHY_ID_BCM5714 || \ 2340 (X) == PHY_ID_BCM5752 || (X) == PHY_ID_BCM5714 || \
2304 (X) == PHY_ID_BCM5780 || (X) == PHY_ID_BCM5787 || \ 2341 (X) == PHY_ID_BCM5780 || (X) == PHY_ID_BCM5787 || \
2305 (X) == PHY_ID_BCM5755 || (X) == PHY_ID_BCM8002) 2342 (X) == PHY_ID_BCM5755 || (X) == PHY_ID_BCM5756 || \
2343 (X) == PHY_ID_BCM5906 || (X) == PHY_ID_BCM8002)
2306 2344
2307 struct tg3_hw_stats *hw_stats; 2345 struct tg3_hw_stats *hw_stats;
2308 dma_addr_t stats_mapping; 2346 dma_addr_t stats_mapping;
diff --git a/drivers/net/tokenring/lanstreamer.c b/drivers/net/tokenring/lanstreamer.c
index 0d66700c6ced..bfc8c3eae9a1 100644
--- a/drivers/net/tokenring/lanstreamer.c
+++ b/drivers/net/tokenring/lanstreamer.c
@@ -1876,7 +1876,6 @@ static int sprintf_info(char *buffer, struct net_device *dev)
1876 datap[size+1]=io_word & 0xff; 1876 datap[size+1]=io_word & 0xff;
1877 } 1877 }
1878 1878
1879
1880 size = sprintf(buffer, "\n%6s: Adapter Address : Node Address : Functional Addr\n", dev->name); 1879 size = sprintf(buffer, "\n%6s: Adapter Address : Node Address : Functional Addr\n", dev->name);
1881 1880
1882 size += sprintf(buffer + size, 1881 size += sprintf(buffer + size,
@@ -1932,64 +1931,6 @@ static int sprintf_info(char *buffer, struct net_device *dev)
1932#endif 1931#endif
1933#endif 1932#endif
1934 1933
1935#if STREAMER_IOCTL && (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1936static int streamer_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1937{
1938 int i;
1939 struct streamer_private *streamer_priv = (struct streamer_private *) dev->priv;
1940 u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
1941
1942 switch(cmd) {
1943 case IOCTL_SISR_MASK:
1944 writew(SISR_MI, streamer_mmio + SISR_MASK_SUM);
1945 break;
1946 case IOCTL_SPIN_LOCK_TEST:
1947 printk(KERN_INFO "spin_lock() called.\n");
1948 spin_lock(&streamer_priv->streamer_lock);
1949 spin_unlock(&streamer_priv->streamer_lock);
1950 printk(KERN_INFO "spin_unlock() finished.\n");
1951 break;
1952 case IOCTL_PRINT_BDAS:
1953 printk(KERN_INFO "bdas: RXBDA: %x RXLBDA: %x TX2FDA: %x TX2LFDA: %x\n",
1954 readw(streamer_mmio + RXBDA),
1955 readw(streamer_mmio + RXLBDA),
1956 readw(streamer_mmio + TX2FDA),
1957 readw(streamer_mmio + TX2LFDA));
1958 break;
1959 case IOCTL_PRINT_REGISTERS:
1960 printk(KERN_INFO "registers:\n");
1961 printk(KERN_INFO "SISR: %04x MISR: %04x LISR: %04x BCTL: %04x BMCTL: %04x\nmask %04x mask %04x\n",
1962 readw(streamer_mmio + SISR),
1963 readw(streamer_mmio + MISR_RUM),
1964 readw(streamer_mmio + LISR),
1965 readw(streamer_mmio + BCTL),
1966 readw(streamer_mmio + BMCTL_SUM),
1967 readw(streamer_mmio + SISR_MASK),
1968 readw(streamer_mmio + MISR_MASK));
1969 break;
1970 case IOCTL_PRINT_RX_BUFS:
1971 printk(KERN_INFO "Print rx bufs:\n");
1972 for(i=0; i<STREAMER_RX_RING_SIZE; i++)
1973 printk(KERN_INFO "rx_ring %d status: 0x%x\n", i,
1974 streamer_priv->streamer_rx_ring[i].status);
1975 break;
1976 case IOCTL_PRINT_TX_BUFS:
1977 printk(KERN_INFO "Print tx bufs:\n");
1978 for(i=0; i<STREAMER_TX_RING_SIZE; i++)
1979 printk(KERN_INFO "tx_ring %d status: 0x%x\n", i,
1980 streamer_priv->streamer_tx_ring[i].status);
1981 break;
1982 case IOCTL_RX_CMD:
1983 streamer_rx(dev);
1984 printk(KERN_INFO "Sent rx command.\n");
1985 break;
1986 default:
1987 printk(KERN_INFO "Bad ioctl!\n");
1988 }
1989 return 0;
1990}
1991#endif
1992
1993static struct pci_driver streamer_pci_driver = { 1934static struct pci_driver streamer_pci_driver = {
1994 .name = "lanstreamer", 1935 .name = "lanstreamer",
1995 .id_table = streamer_pci_tbl, 1936 .id_table = streamer_pci_tbl,
diff --git a/drivers/net/tokenring/lanstreamer.h b/drivers/net/tokenring/lanstreamer.h
index 5557d8e1e22d..e7bb3494afc7 100644
--- a/drivers/net/tokenring/lanstreamer.h
+++ b/drivers/net/tokenring/lanstreamer.h
@@ -62,18 +62,6 @@
62 62
63#include <linux/version.h> 63#include <linux/version.h>
64 64
65#if STREAMER_IOCTL && (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
66#include <asm/ioctl.h>
67#define IOCTL_PRINT_RX_BUFS SIOCDEVPRIVATE
68#define IOCTL_PRINT_TX_BUFS SIOCDEVPRIVATE+1
69#define IOCTL_RX_CMD SIOCDEVPRIVATE+2
70#define IOCTL_TX_CMD SIOCDEVPRIVATE+3
71#define IOCTL_PRINT_REGISTERS SIOCDEVPRIVATE+4
72#define IOCTL_PRINT_BDAS SIOCDEVPRIVATE+5
73#define IOCTL_SPIN_LOCK_TEST SIOCDEVPRIVATE+6
74#define IOCTL_SISR_MASK SIOCDEVPRIVATE+7
75#endif
76
77/* MAX_INTR - the maximum number of times we can loop 65/* MAX_INTR - the maximum number of times we can loop
78 * inside the interrupt function before returning 66 * inside the interrupt function before returning
79 * control to the OS (maximum value is 256) 67 * control to the OS (maximum value is 256)
diff --git a/drivers/net/tulip/de4x5.c b/drivers/net/tulip/de4x5.c
index e661d0a9cc64..fb5fa7d68888 100644
--- a/drivers/net/tulip/de4x5.c
+++ b/drivers/net/tulip/de4x5.c
@@ -2114,6 +2114,7 @@ static struct eisa_device_id de4x5_eisa_ids[] = {
2114 { "DEC4250", 0 }, /* 0 is the board name index... */ 2114 { "DEC4250", 0 }, /* 0 is the board name index... */
2115 { "" } 2115 { "" }
2116}; 2116};
2117MODULE_DEVICE_TABLE(eisa, de4x5_eisa_ids);
2117 2118
2118static struct eisa_driver de4x5_eisa_driver = { 2119static struct eisa_driver de4x5_eisa_driver = {
2119 .id_table = de4x5_eisa_ids, 2120 .id_table = de4x5_eisa_ids,
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index de8da6dee1b0..151a2e10e4f3 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -288,11 +288,10 @@ static inline size_t iov_total(const struct iovec *iv, unsigned long count)
288 return len; 288 return len;
289} 289}
290 290
291/* Writev */ 291static ssize_t tun_chr_aio_write(struct kiocb *iocb, const struct iovec *iv,
292static ssize_t tun_chr_writev(struct file * file, const struct iovec *iv, 292 unsigned long count, loff_t pos)
293 unsigned long count, loff_t *pos)
294{ 293{
295 struct tun_struct *tun = file->private_data; 294 struct tun_struct *tun = iocb->ki_filp->private_data;
296 295
297 if (!tun) 296 if (!tun)
298 return -EBADFD; 297 return -EBADFD;
@@ -302,14 +301,6 @@ static ssize_t tun_chr_writev(struct file * file, const struct iovec *iv,
302 return tun_get_user(tun, (struct iovec *) iv, iov_total(iv, count)); 301 return tun_get_user(tun, (struct iovec *) iv, iov_total(iv, count));
303} 302}
304 303
305/* Write */
306static ssize_t tun_chr_write(struct file * file, const char __user * buf,
307 size_t count, loff_t *pos)
308{
309 struct iovec iv = { (void __user *) buf, count };
310 return tun_chr_writev(file, &iv, 1, pos);
311}
312
313/* Put packet to the user space buffer */ 304/* Put packet to the user space buffer */
314static __inline__ ssize_t tun_put_user(struct tun_struct *tun, 305static __inline__ ssize_t tun_put_user(struct tun_struct *tun,
315 struct sk_buff *skb, 306 struct sk_buff *skb,
@@ -343,10 +334,10 @@ static __inline__ ssize_t tun_put_user(struct tun_struct *tun,
343 return total; 334 return total;
344} 335}
345 336
346/* Readv */ 337static ssize_t tun_chr_aio_read(struct kiocb *iocb, const struct iovec *iv,
347static ssize_t tun_chr_readv(struct file *file, const struct iovec *iv, 338 unsigned long count, loff_t pos)
348 unsigned long count, loff_t *pos)
349{ 339{
340 struct file *file = iocb->ki_filp;
350 struct tun_struct *tun = file->private_data; 341 struct tun_struct *tun = file->private_data;
351 DECLARE_WAITQUEUE(wait, current); 342 DECLARE_WAITQUEUE(wait, current);
352 struct sk_buff *skb; 343 struct sk_buff *skb;
@@ -426,14 +417,6 @@ static ssize_t tun_chr_readv(struct file *file, const struct iovec *iv,
426 return ret; 417 return ret;
427} 418}
428 419
429/* Read */
430static ssize_t tun_chr_read(struct file * file, char __user * buf,
431 size_t count, loff_t *pos)
432{
433 struct iovec iv = { buf, count };
434 return tun_chr_readv(file, &iv, 1, pos);
435}
436
437static void tun_setup(struct net_device *dev) 420static void tun_setup(struct net_device *dev)
438{ 421{
439 struct tun_struct *tun = netdev_priv(dev); 422 struct tun_struct *tun = netdev_priv(dev);
@@ -714,7 +697,7 @@ static int tun_chr_fasync(int fd, struct file *file, int on)
714 return ret; 697 return ret;
715 698
716 if (on) { 699 if (on) {
717 ret = f_setown(file, current->pid, 0); 700 ret = __f_setown(file, task_pid(current), PIDTYPE_PID, 0);
718 if (ret) 701 if (ret)
719 return ret; 702 return ret;
720 tun->flags |= TUN_FASYNC; 703 tun->flags |= TUN_FASYNC;
@@ -764,10 +747,10 @@ static int tun_chr_close(struct inode *inode, struct file *file)
764static struct file_operations tun_fops = { 747static struct file_operations tun_fops = {
765 .owner = THIS_MODULE, 748 .owner = THIS_MODULE,
766 .llseek = no_llseek, 749 .llseek = no_llseek,
767 .read = tun_chr_read, 750 .read = do_sync_read,
768 .readv = tun_chr_readv, 751 .aio_read = tun_chr_aio_read,
769 .write = tun_chr_write, 752 .write = do_sync_write,
770 .writev = tun_chr_writev, 753 .aio_write = tun_chr_aio_write,
771 .poll = tun_chr_poll, 754 .poll = tun_chr_poll,
772 .ioctl = tun_chr_ioctl, 755 .ioctl = tun_chr_ioctl,
773 .open = tun_chr_open, 756 .open = tun_chr_open,
diff --git a/drivers/net/typhoon.c b/drivers/net/typhoon.c
index 8f6f6fd8b87d..d5c32e9caa97 100644
--- a/drivers/net/typhoon.c
+++ b/drivers/net/typhoon.c
@@ -333,11 +333,7 @@ enum state_values {
333#define TYPHOON_RESET_TIMEOUT_NOSLEEP ((6 * 1000000) / TYPHOON_UDELAY) 333#define TYPHOON_RESET_TIMEOUT_NOSLEEP ((6 * 1000000) / TYPHOON_UDELAY)
334#define TYPHOON_WAIT_TIMEOUT ((1000000 / 2) / TYPHOON_UDELAY) 334#define TYPHOON_WAIT_TIMEOUT ((1000000 / 2) / TYPHOON_UDELAY)
335 335
336#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 28)
337#define typhoon_synchronize_irq(x) synchronize_irq()
338#else
339#define typhoon_synchronize_irq(x) synchronize_irq(x) 336#define typhoon_synchronize_irq(x) synchronize_irq(x)
340#endif
341 337
342#if defined(NETIF_F_TSO) 338#if defined(NETIF_F_TSO)
343#define skb_tso_size(x) (skb_shinfo(x)->gso_size) 339#define skb_tso_size(x) (skb_shinfo(x)->gso_size)
diff --git a/drivers/net/wan/Kconfig b/drivers/net/wan/Kconfig
index 54b8e492ef97..58b7efbb0750 100644
--- a/drivers/net/wan/Kconfig
+++ b/drivers/net/wan/Kconfig
@@ -154,7 +154,7 @@ config HDLC
154 If unsure, say N. 154 If unsure, say N.
155 155
156config HDLC_RAW 156config HDLC_RAW
157 bool "Raw HDLC support" 157 tristate "Raw HDLC support"
158 depends on HDLC 158 depends on HDLC
159 help 159 help
160 Generic HDLC driver supporting raw HDLC over WAN connections. 160 Generic HDLC driver supporting raw HDLC over WAN connections.
@@ -162,7 +162,7 @@ config HDLC_RAW
162 If unsure, say N. 162 If unsure, say N.
163 163
164config HDLC_RAW_ETH 164config HDLC_RAW_ETH
165 bool "Raw HDLC Ethernet device support" 165 tristate "Raw HDLC Ethernet device support"
166 depends on HDLC 166 depends on HDLC
167 help 167 help
168 Generic HDLC driver supporting raw HDLC Ethernet device emulation 168 Generic HDLC driver supporting raw HDLC Ethernet device emulation
@@ -173,7 +173,7 @@ config HDLC_RAW_ETH
173 If unsure, say N. 173 If unsure, say N.
174 174
175config HDLC_CISCO 175config HDLC_CISCO
176 bool "Cisco HDLC support" 176 tristate "Cisco HDLC support"
177 depends on HDLC 177 depends on HDLC
178 help 178 help
179 Generic HDLC driver supporting Cisco HDLC over WAN connections. 179 Generic HDLC driver supporting Cisco HDLC over WAN connections.
@@ -181,7 +181,7 @@ config HDLC_CISCO
181 If unsure, say N. 181 If unsure, say N.
182 182
183config HDLC_FR 183config HDLC_FR
184 bool "Frame Relay support" 184 tristate "Frame Relay support"
185 depends on HDLC 185 depends on HDLC
186 help 186 help
187 Generic HDLC driver supporting Frame Relay over WAN connections. 187 Generic HDLC driver supporting Frame Relay over WAN connections.
@@ -189,7 +189,7 @@ config HDLC_FR
189 If unsure, say N. 189 If unsure, say N.
190 190
191config HDLC_PPP 191config HDLC_PPP
192 bool "Synchronous Point-to-Point Protocol (PPP) support" 192 tristate "Synchronous Point-to-Point Protocol (PPP) support"
193 depends on HDLC 193 depends on HDLC
194 help 194 help
195 Generic HDLC driver supporting PPP over WAN connections. 195 Generic HDLC driver supporting PPP over WAN connections.
@@ -197,7 +197,7 @@ config HDLC_PPP
197 If unsure, say N. 197 If unsure, say N.
198 198
199config HDLC_X25 199config HDLC_X25
200 bool "X.25 protocol support" 200 tristate "X.25 protocol support"
201 depends on HDLC && (LAPB=m && HDLC=m || LAPB=y) 201 depends on HDLC && (LAPB=m && HDLC=m || LAPB=y)
202 help 202 help
203 Generic HDLC driver supporting X.25 over WAN connections. 203 Generic HDLC driver supporting X.25 over WAN connections.
diff --git a/drivers/net/wan/Makefile b/drivers/net/wan/Makefile
index 316ca6869d5e..83ec2c87ba3f 100644
--- a/drivers/net/wan/Makefile
+++ b/drivers/net/wan/Makefile
@@ -9,14 +9,13 @@ cyclomx-y := cycx_main.o
9cyclomx-$(CONFIG_CYCLOMX_X25) += cycx_x25.o 9cyclomx-$(CONFIG_CYCLOMX_X25) += cycx_x25.o
10cyclomx-objs := $(cyclomx-y) 10cyclomx-objs := $(cyclomx-y)
11 11
12hdlc-y := hdlc_generic.o 12obj-$(CONFIG_HDLC) += hdlc.o
13hdlc-$(CONFIG_HDLC_RAW) += hdlc_raw.o 13obj-$(CONFIG_HDLC_RAW) += hdlc_raw.o
14hdlc-$(CONFIG_HDLC_RAW_ETH) += hdlc_raw_eth.o 14obj-$(CONFIG_HDLC_RAW_ETH) += hdlc_raw_eth.o
15hdlc-$(CONFIG_HDLC_CISCO) += hdlc_cisco.o 15obj-$(CONFIG_HDLC_CISCO) += hdlc_cisco.o
16hdlc-$(CONFIG_HDLC_FR) += hdlc_fr.o 16obj-$(CONFIG_HDLC_FR) += hdlc_fr.o
17hdlc-$(CONFIG_HDLC_PPP) += hdlc_ppp.o 17obj-$(CONFIG_HDLC_PPP) += hdlc_ppp.o syncppp.o
18hdlc-$(CONFIG_HDLC_X25) += hdlc_x25.o 18obj-$(CONFIG_HDLC_X25) += hdlc_x25.o
19hdlc-objs := $(hdlc-y)
20 19
21pc300-y := pc300_drv.o 20pc300-y := pc300_drv.o
22pc300-$(CONFIG_PC300_MLPPP) += pc300_tty.o 21pc300-$(CONFIG_PC300_MLPPP) += pc300_tty.o
@@ -38,10 +37,6 @@ obj-$(CONFIG_CYCLADES_SYNC) += cycx_drv.o cyclomx.o
38obj-$(CONFIG_LAPBETHER) += lapbether.o 37obj-$(CONFIG_LAPBETHER) += lapbether.o
39obj-$(CONFIG_SBNI) += sbni.o 38obj-$(CONFIG_SBNI) += sbni.o
40obj-$(CONFIG_PC300) += pc300.o 39obj-$(CONFIG_PC300) += pc300.o
41obj-$(CONFIG_HDLC) += hdlc.o
42ifeq ($(CONFIG_HDLC_PPP),y)
43 obj-$(CONFIG_HDLC) += syncppp.o
44endif
45obj-$(CONFIG_N2) += n2.o 40obj-$(CONFIG_N2) += n2.o
46obj-$(CONFIG_C101) += c101.o 41obj-$(CONFIG_C101) += c101.o
47obj-$(CONFIG_WANXL) += wanxl.o 42obj-$(CONFIG_WANXL) += wanxl.o
diff --git a/drivers/net/wan/hdlc_generic.c b/drivers/net/wan/hdlc.c
index 04ca1f7b6424..db354e0edbe5 100644
--- a/drivers/net/wan/hdlc_generic.c
+++ b/drivers/net/wan/hdlc.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Generic HDLC support routines for Linux 2 * Generic HDLC support routines for Linux
3 * 3 *
4 * Copyright (C) 1999 - 2005 Krzysztof Halasa <khc@pm.waw.pl> 4 * Copyright (C) 1999 - 2006 Krzysztof Halasa <khc@pm.waw.pl>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify it 6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License 7 * under the terms of version 2 of the GNU General Public License
@@ -17,9 +17,9 @@
17 * Use sethdlc utility to set line parameters, protocol and PVCs 17 * Use sethdlc utility to set line parameters, protocol and PVCs
18 * 18 *
19 * How does it work: 19 * How does it work:
20 * - proto.open(), close(), start(), stop() calls are serialized. 20 * - proto->open(), close(), start(), stop() calls are serialized.
21 * The order is: open, [ start, stop ... ] close ... 21 * The order is: open, [ start, stop ... ] close ...
22 * - proto.start() and stop() are called with spin_lock_irq held. 22 * - proto->start() and stop() are called with spin_lock_irq held.
23 */ 23 */
24 24
25#include <linux/module.h> 25#include <linux/module.h>
@@ -38,10 +38,12 @@
38#include <linux/hdlc.h> 38#include <linux/hdlc.h>
39 39
40 40
41static const char* version = "HDLC support module revision 1.19"; 41static const char* version = "HDLC support module revision 1.20";
42 42
43#undef DEBUG_LINK 43#undef DEBUG_LINK
44 44
45static struct hdlc_proto *first_proto = NULL;
46
45 47
46static int hdlc_change_mtu(struct net_device *dev, int new_mtu) 48static int hdlc_change_mtu(struct net_device *dev, int new_mtu)
47{ 49{
@@ -63,11 +65,11 @@ static struct net_device_stats *hdlc_get_stats(struct net_device *dev)
63static int hdlc_rcv(struct sk_buff *skb, struct net_device *dev, 65static int hdlc_rcv(struct sk_buff *skb, struct net_device *dev,
64 struct packet_type *p, struct net_device *orig_dev) 66 struct packet_type *p, struct net_device *orig_dev)
65{ 67{
66 hdlc_device *hdlc = dev_to_hdlc(dev); 68 struct hdlc_device_desc *desc = dev_to_desc(dev);
67 if (hdlc->proto.netif_rx) 69 if (desc->netif_rx)
68 return hdlc->proto.netif_rx(skb); 70 return desc->netif_rx(skb);
69 71
70 hdlc->stats.rx_dropped++; /* Shouldn't happen */ 72 desc->stats.rx_dropped++; /* Shouldn't happen */
71 dev_kfree_skb(skb); 73 dev_kfree_skb(skb);
72 return NET_RX_DROP; 74 return NET_RX_DROP;
73} 75}
@@ -77,8 +79,8 @@ static int hdlc_rcv(struct sk_buff *skb, struct net_device *dev,
77static inline void hdlc_proto_start(struct net_device *dev) 79static inline void hdlc_proto_start(struct net_device *dev)
78{ 80{
79 hdlc_device *hdlc = dev_to_hdlc(dev); 81 hdlc_device *hdlc = dev_to_hdlc(dev);
80 if (hdlc->proto.start) 82 if (hdlc->proto->start)
81 return hdlc->proto.start(dev); 83 return hdlc->proto->start(dev);
82} 84}
83 85
84 86
@@ -86,8 +88,8 @@ static inline void hdlc_proto_start(struct net_device *dev)
86static inline void hdlc_proto_stop(struct net_device *dev) 88static inline void hdlc_proto_stop(struct net_device *dev)
87{ 89{
88 hdlc_device *hdlc = dev_to_hdlc(dev); 90 hdlc_device *hdlc = dev_to_hdlc(dev);
89 if (hdlc->proto.stop) 91 if (hdlc->proto->stop)
90 return hdlc->proto.stop(dev); 92 return hdlc->proto->stop(dev);
91} 93}
92 94
93 95
@@ -144,15 +146,15 @@ int hdlc_open(struct net_device *dev)
144{ 146{
145 hdlc_device *hdlc = dev_to_hdlc(dev); 147 hdlc_device *hdlc = dev_to_hdlc(dev);
146#ifdef DEBUG_LINK 148#ifdef DEBUG_LINK
147 printk(KERN_DEBUG "hdlc_open() carrier %i open %i\n", 149 printk(KERN_DEBUG "%s: hdlc_open() carrier %i open %i\n", dev->name,
148 hdlc->carrier, hdlc->open); 150 hdlc->carrier, hdlc->open);
149#endif 151#endif
150 152
151 if (hdlc->proto.id == -1) 153 if (hdlc->proto == NULL)
152 return -ENOSYS; /* no protocol attached */ 154 return -ENOSYS; /* no protocol attached */
153 155
154 if (hdlc->proto.open) { 156 if (hdlc->proto->open) {
155 int result = hdlc->proto.open(dev); 157 int result = hdlc->proto->open(dev);
156 if (result) 158 if (result)
157 return result; 159 return result;
158 } 160 }
@@ -178,7 +180,7 @@ void hdlc_close(struct net_device *dev)
178{ 180{
179 hdlc_device *hdlc = dev_to_hdlc(dev); 181 hdlc_device *hdlc = dev_to_hdlc(dev);
180#ifdef DEBUG_LINK 182#ifdef DEBUG_LINK
181 printk(KERN_DEBUG "hdlc_close() carrier %i open %i\n", 183 printk(KERN_DEBUG "%s: hdlc_close() carrier %i open %i\n", dev->name,
182 hdlc->carrier, hdlc->open); 184 hdlc->carrier, hdlc->open);
183#endif 185#endif
184 186
@@ -190,68 +192,34 @@ void hdlc_close(struct net_device *dev)
190 192
191 spin_unlock_irq(&hdlc->state_lock); 193 spin_unlock_irq(&hdlc->state_lock);
192 194
193 if (hdlc->proto.close) 195 if (hdlc->proto->close)
194 hdlc->proto.close(dev); 196 hdlc->proto->close(dev);
195} 197}
196 198
197 199
198 200
199#ifndef CONFIG_HDLC_RAW
200#define hdlc_raw_ioctl(dev, ifr) -ENOSYS
201#endif
202
203#ifndef CONFIG_HDLC_RAW_ETH
204#define hdlc_raw_eth_ioctl(dev, ifr) -ENOSYS
205#endif
206
207#ifndef CONFIG_HDLC_PPP
208#define hdlc_ppp_ioctl(dev, ifr) -ENOSYS
209#endif
210
211#ifndef CONFIG_HDLC_CISCO
212#define hdlc_cisco_ioctl(dev, ifr) -ENOSYS
213#endif
214
215#ifndef CONFIG_HDLC_FR
216#define hdlc_fr_ioctl(dev, ifr) -ENOSYS
217#endif
218
219#ifndef CONFIG_HDLC_X25
220#define hdlc_x25_ioctl(dev, ifr) -ENOSYS
221#endif
222
223
224int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 201int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
225{ 202{
226 hdlc_device *hdlc = dev_to_hdlc(dev); 203 struct hdlc_proto *proto = first_proto;
227 unsigned int proto; 204 int result;
228 205
229 if (cmd != SIOCWANDEV) 206 if (cmd != SIOCWANDEV)
230 return -EINVAL; 207 return -EINVAL;
231 208
232 switch(ifr->ifr_settings.type) { 209 if (dev_to_hdlc(dev)->proto) {
233 case IF_PROTO_HDLC: 210 result = dev_to_hdlc(dev)->proto->ioctl(dev, ifr);
234 case IF_PROTO_HDLC_ETH: 211 if (result != -EINVAL)
235 case IF_PROTO_PPP: 212 return result;
236 case IF_PROTO_CISCO:
237 case IF_PROTO_FR:
238 case IF_PROTO_X25:
239 proto = ifr->ifr_settings.type;
240 break;
241
242 default:
243 proto = hdlc->proto.id;
244 } 213 }
245 214
246 switch(proto) { 215 /* Not handled by currently attached protocol (if any) */
247 case IF_PROTO_HDLC: return hdlc_raw_ioctl(dev, ifr); 216
248 case IF_PROTO_HDLC_ETH: return hdlc_raw_eth_ioctl(dev, ifr); 217 while (proto) {
249 case IF_PROTO_PPP: return hdlc_ppp_ioctl(dev, ifr); 218 if ((result = proto->ioctl(dev, ifr)) != -EINVAL)
250 case IF_PROTO_CISCO: return hdlc_cisco_ioctl(dev, ifr); 219 return result;
251 case IF_PROTO_FR: return hdlc_fr_ioctl(dev, ifr); 220 proto = proto->next;
252 case IF_PROTO_X25: return hdlc_x25_ioctl(dev, ifr);
253 default: return -EINVAL;
254 } 221 }
222 return -EINVAL;
255} 223}
256 224
257void hdlc_setup(struct net_device *dev) 225void hdlc_setup(struct net_device *dev)
@@ -267,8 +235,6 @@ void hdlc_setup(struct net_device *dev)
267 235
268 dev->flags = IFF_POINTOPOINT | IFF_NOARP; 236 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
269 237
270 hdlc->proto.id = -1;
271 hdlc->proto.detach = NULL;
272 hdlc->carrier = 1; 238 hdlc->carrier = 1;
273 hdlc->open = 0; 239 hdlc->open = 0;
274 spin_lock_init(&hdlc->state_lock); 240 spin_lock_init(&hdlc->state_lock);
@@ -277,7 +243,8 @@ void hdlc_setup(struct net_device *dev)
277struct net_device *alloc_hdlcdev(void *priv) 243struct net_device *alloc_hdlcdev(void *priv)
278{ 244{
279 struct net_device *dev; 245 struct net_device *dev;
280 dev = alloc_netdev(sizeof(hdlc_device), "hdlc%d", hdlc_setup); 246 dev = alloc_netdev(sizeof(struct hdlc_device_desc) +
247 sizeof(hdlc_device), "hdlc%d", hdlc_setup);
281 if (dev) 248 if (dev)
282 dev_to_hdlc(dev)->priv = priv; 249 dev_to_hdlc(dev)->priv = priv;
283 return dev; 250 return dev;
@@ -286,13 +253,71 @@ struct net_device *alloc_hdlcdev(void *priv)
286void unregister_hdlc_device(struct net_device *dev) 253void unregister_hdlc_device(struct net_device *dev)
287{ 254{
288 rtnl_lock(); 255 rtnl_lock();
289 hdlc_proto_detach(dev_to_hdlc(dev));
290 unregister_netdevice(dev); 256 unregister_netdevice(dev);
257 detach_hdlc_protocol(dev);
291 rtnl_unlock(); 258 rtnl_unlock();
292} 259}
293 260
294 261
295 262
263int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
264 int (*rx)(struct sk_buff *skb), size_t size)
265{
266 detach_hdlc_protocol(dev);
267
268 if (!try_module_get(proto->module))
269 return -ENOSYS;
270
271 if (size)
272 if ((dev_to_hdlc(dev)->state = kmalloc(size,
273 GFP_KERNEL)) == NULL) {
274 printk(KERN_WARNING "Memory squeeze on"
275 " hdlc_proto_attach()\n");
276 module_put(proto->module);
277 return -ENOBUFS;
278 }
279 dev_to_hdlc(dev)->proto = proto;
280 dev_to_desc(dev)->netif_rx = rx;
281 return 0;
282}
283
284
285void detach_hdlc_protocol(struct net_device *dev)
286{
287 hdlc_device *hdlc = dev_to_hdlc(dev);
288
289 if (hdlc->proto) {
290 if (hdlc->proto->detach)
291 hdlc->proto->detach(dev);
292 module_put(hdlc->proto->module);
293 hdlc->proto = NULL;
294 }
295 kfree(hdlc->state);
296 hdlc->state = NULL;
297}
298
299
300void register_hdlc_protocol(struct hdlc_proto *proto)
301{
302 proto->next = first_proto;
303 first_proto = proto;
304}
305
306
307void unregister_hdlc_protocol(struct hdlc_proto *proto)
308{
309 struct hdlc_proto **p = &first_proto;
310 while (*p) {
311 if (*p == proto) {
312 *p = proto->next;
313 return;
314 }
315 p = &((*p)->next);
316 }
317}
318
319
320
296MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>"); 321MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
297MODULE_DESCRIPTION("HDLC support module"); 322MODULE_DESCRIPTION("HDLC support module");
298MODULE_LICENSE("GPL v2"); 323MODULE_LICENSE("GPL v2");
@@ -303,6 +328,10 @@ EXPORT_SYMBOL(hdlc_ioctl);
303EXPORT_SYMBOL(hdlc_setup); 328EXPORT_SYMBOL(hdlc_setup);
304EXPORT_SYMBOL(alloc_hdlcdev); 329EXPORT_SYMBOL(alloc_hdlcdev);
305EXPORT_SYMBOL(unregister_hdlc_device); 330EXPORT_SYMBOL(unregister_hdlc_device);
331EXPORT_SYMBOL(register_hdlc_protocol);
332EXPORT_SYMBOL(unregister_hdlc_protocol);
333EXPORT_SYMBOL(attach_hdlc_protocol);
334EXPORT_SYMBOL(detach_hdlc_protocol);
306 335
307static struct packet_type hdlc_packet_type = { 336static struct packet_type hdlc_packet_type = {
308 .type = __constant_htons(ETH_P_HDLC), 337 .type = __constant_htons(ETH_P_HDLC),
diff --git a/drivers/net/wan/hdlc_cisco.c b/drivers/net/wan/hdlc_cisco.c
index f289daba0c7b..b0bc5ddcf1b1 100644
--- a/drivers/net/wan/hdlc_cisco.c
+++ b/drivers/net/wan/hdlc_cisco.c
@@ -2,7 +2,7 @@
2 * Generic HDLC support routines for Linux 2 * Generic HDLC support routines for Linux
3 * Cisco HDLC support 3 * Cisco HDLC support
4 * 4 *
5 * Copyright (C) 2000 - 2003 Krzysztof Halasa <khc@pm.waw.pl> 5 * Copyright (C) 2000 - 2006 Krzysztof Halasa <khc@pm.waw.pl>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify it 7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License 8 * under the terms of version 2 of the GNU General Public License
@@ -34,17 +34,56 @@
34#define CISCO_KEEPALIVE_REQ 2 /* Cisco keepalive request */ 34#define CISCO_KEEPALIVE_REQ 2 /* Cisco keepalive request */
35 35
36 36
37struct hdlc_header {
38 u8 address;
39 u8 control;
40 u16 protocol;
41}__attribute__ ((packed));
42
43
44struct cisco_packet {
45 u32 type; /* code */
46 u32 par1;
47 u32 par2;
48 u16 rel; /* reliability */
49 u32 time;
50}__attribute__ ((packed));
51#define CISCO_PACKET_LEN 18
52#define CISCO_BIG_PACKET_LEN 20
53
54
55struct cisco_state {
56 cisco_proto settings;
57
58 struct timer_list timer;
59 unsigned long last_poll;
60 int up;
61 int request_sent;
62 u32 txseq; /* TX sequence number */
63 u32 rxseq; /* RX sequence number */
64};
65
66
67static int cisco_ioctl(struct net_device *dev, struct ifreq *ifr);
68
69
70static inline struct cisco_state * state(hdlc_device *hdlc)
71{
72 return(struct cisco_state *)(hdlc->state);
73}
74
75
37static int cisco_hard_header(struct sk_buff *skb, struct net_device *dev, 76static int cisco_hard_header(struct sk_buff *skb, struct net_device *dev,
38 u16 type, void *daddr, void *saddr, 77 u16 type, void *daddr, void *saddr,
39 unsigned int len) 78 unsigned int len)
40{ 79{
41 hdlc_header *data; 80 struct hdlc_header *data;
42#ifdef DEBUG_HARD_HEADER 81#ifdef DEBUG_HARD_HEADER
43 printk(KERN_DEBUG "%s: cisco_hard_header called\n", dev->name); 82 printk(KERN_DEBUG "%s: cisco_hard_header called\n", dev->name);
44#endif 83#endif
45 84
46 skb_push(skb, sizeof(hdlc_header)); 85 skb_push(skb, sizeof(struct hdlc_header));
47 data = (hdlc_header*)skb->data; 86 data = (struct hdlc_header*)skb->data;
48 if (type == CISCO_KEEPALIVE) 87 if (type == CISCO_KEEPALIVE)
49 data->address = CISCO_MULTICAST; 88 data->address = CISCO_MULTICAST;
50 else 89 else
@@ -52,7 +91,7 @@ static int cisco_hard_header(struct sk_buff *skb, struct net_device *dev,
52 data->control = 0; 91 data->control = 0;
53 data->protocol = htons(type); 92 data->protocol = htons(type);
54 93
55 return sizeof(hdlc_header); 94 return sizeof(struct hdlc_header);
56} 95}
57 96
58 97
@@ -61,9 +100,10 @@ static void cisco_keepalive_send(struct net_device *dev, u32 type,
61 u32 par1, u32 par2) 100 u32 par1, u32 par2)
62{ 101{
63 struct sk_buff *skb; 102 struct sk_buff *skb;
64 cisco_packet *data; 103 struct cisco_packet *data;
65 104
66 skb = dev_alloc_skb(sizeof(hdlc_header) + sizeof(cisco_packet)); 105 skb = dev_alloc_skb(sizeof(struct hdlc_header) +
106 sizeof(struct cisco_packet));
67 if (!skb) { 107 if (!skb) {
68 printk(KERN_WARNING 108 printk(KERN_WARNING
69 "%s: Memory squeeze on cisco_keepalive_send()\n", 109 "%s: Memory squeeze on cisco_keepalive_send()\n",
@@ -72,7 +112,7 @@ static void cisco_keepalive_send(struct net_device *dev, u32 type,
72 } 112 }
73 skb_reserve(skb, 4); 113 skb_reserve(skb, 4);
74 cisco_hard_header(skb, dev, CISCO_KEEPALIVE, NULL, NULL, 0); 114 cisco_hard_header(skb, dev, CISCO_KEEPALIVE, NULL, NULL, 0);
75 data = (cisco_packet*)(skb->data + 4); 115 data = (struct cisco_packet*)(skb->data + 4);
76 116
77 data->type = htonl(type); 117 data->type = htonl(type);
78 data->par1 = htonl(par1); 118 data->par1 = htonl(par1);
@@ -81,7 +121,7 @@ static void cisco_keepalive_send(struct net_device *dev, u32 type,
81 /* we will need do_div here if 1000 % HZ != 0 */ 121 /* we will need do_div here if 1000 % HZ != 0 */
82 data->time = htonl((jiffies - INITIAL_JIFFIES) * (1000 / HZ)); 122 data->time = htonl((jiffies - INITIAL_JIFFIES) * (1000 / HZ));
83 123
84 skb_put(skb, sizeof(cisco_packet)); 124 skb_put(skb, sizeof(struct cisco_packet));
85 skb->priority = TC_PRIO_CONTROL; 125 skb->priority = TC_PRIO_CONTROL;
86 skb->dev = dev; 126 skb->dev = dev;
87 skb->nh.raw = skb->data; 127 skb->nh.raw = skb->data;
@@ -93,9 +133,9 @@ static void cisco_keepalive_send(struct net_device *dev, u32 type,
93 133
94static __be16 cisco_type_trans(struct sk_buff *skb, struct net_device *dev) 134static __be16 cisco_type_trans(struct sk_buff *skb, struct net_device *dev)
95{ 135{
96 hdlc_header *data = (hdlc_header*)skb->data; 136 struct hdlc_header *data = (struct hdlc_header*)skb->data;
97 137
98 if (skb->len < sizeof(hdlc_header)) 138 if (skb->len < sizeof(struct hdlc_header))
99 return __constant_htons(ETH_P_HDLC); 139 return __constant_htons(ETH_P_HDLC);
100 140
101 if (data->address != CISCO_MULTICAST && 141 if (data->address != CISCO_MULTICAST &&
@@ -106,7 +146,7 @@ static __be16 cisco_type_trans(struct sk_buff *skb, struct net_device *dev)
106 case __constant_htons(ETH_P_IP): 146 case __constant_htons(ETH_P_IP):
107 case __constant_htons(ETH_P_IPX): 147 case __constant_htons(ETH_P_IPX):
108 case __constant_htons(ETH_P_IPV6): 148 case __constant_htons(ETH_P_IPV6):
109 skb_pull(skb, sizeof(hdlc_header)); 149 skb_pull(skb, sizeof(struct hdlc_header));
110 return data->protocol; 150 return data->protocol;
111 default: 151 default:
112 return __constant_htons(ETH_P_HDLC); 152 return __constant_htons(ETH_P_HDLC);
@@ -118,12 +158,12 @@ static int cisco_rx(struct sk_buff *skb)
118{ 158{
119 struct net_device *dev = skb->dev; 159 struct net_device *dev = skb->dev;
120 hdlc_device *hdlc = dev_to_hdlc(dev); 160 hdlc_device *hdlc = dev_to_hdlc(dev);
121 hdlc_header *data = (hdlc_header*)skb->data; 161 struct hdlc_header *data = (struct hdlc_header*)skb->data;
122 cisco_packet *cisco_data; 162 struct cisco_packet *cisco_data;
123 struct in_device *in_dev; 163 struct in_device *in_dev;
124 u32 addr, mask; 164 __be32 addr, mask;
125 165
126 if (skb->len < sizeof(hdlc_header)) 166 if (skb->len < sizeof(struct hdlc_header))
127 goto rx_error; 167 goto rx_error;
128 168
129 if (data->address != CISCO_MULTICAST && 169 if (data->address != CISCO_MULTICAST &&
@@ -137,15 +177,17 @@ static int cisco_rx(struct sk_buff *skb)
137 return NET_RX_SUCCESS; 177 return NET_RX_SUCCESS;
138 178
139 case CISCO_KEEPALIVE: 179 case CISCO_KEEPALIVE:
140 if (skb->len != sizeof(hdlc_header) + CISCO_PACKET_LEN && 180 if ((skb->len != sizeof(struct hdlc_header) +
141 skb->len != sizeof(hdlc_header) + CISCO_BIG_PACKET_LEN) { 181 CISCO_PACKET_LEN) &&
142 printk(KERN_INFO "%s: Invalid length of Cisco " 182 (skb->len != sizeof(struct hdlc_header) +
143 "control packet (%d bytes)\n", 183 CISCO_BIG_PACKET_LEN)) {
144 dev->name, skb->len); 184 printk(KERN_INFO "%s: Invalid length of Cisco control"
185 " packet (%d bytes)\n", dev->name, skb->len);
145 goto rx_error; 186 goto rx_error;
146 } 187 }
147 188
148 cisco_data = (cisco_packet*)(skb->data + sizeof(hdlc_header)); 189 cisco_data = (struct cisco_packet*)(skb->data + sizeof
190 (struct hdlc_header));
149 191
150 switch(ntohl (cisco_data->type)) { 192 switch(ntohl (cisco_data->type)) {
151 case CISCO_ADDR_REQ: /* Stolen from syncppp.c :-) */ 193 case CISCO_ADDR_REQ: /* Stolen from syncppp.c :-) */
@@ -178,11 +220,11 @@ static int cisco_rx(struct sk_buff *skb)
178 goto rx_error; 220 goto rx_error;
179 221
180 case CISCO_KEEPALIVE_REQ: 222 case CISCO_KEEPALIVE_REQ:
181 hdlc->state.cisco.rxseq = ntohl(cisco_data->par1); 223 state(hdlc)->rxseq = ntohl(cisco_data->par1);
182 if (hdlc->state.cisco.request_sent && 224 if (state(hdlc)->request_sent &&
183 ntohl(cisco_data->par2)==hdlc->state.cisco.txseq) { 225 ntohl(cisco_data->par2) == state(hdlc)->txseq) {
184 hdlc->state.cisco.last_poll = jiffies; 226 state(hdlc)->last_poll = jiffies;
185 if (!hdlc->state.cisco.up) { 227 if (!state(hdlc)->up) {
186 u32 sec, min, hrs, days; 228 u32 sec, min, hrs, days;
187 sec = ntohl(cisco_data->time) / 1000; 229 sec = ntohl(cisco_data->time) / 1000;
188 min = sec / 60; sec -= min * 60; 230 min = sec / 60; sec -= min * 60;
@@ -193,7 +235,7 @@ static int cisco_rx(struct sk_buff *skb)
193 dev->name, days, hrs, 235 dev->name, days, hrs,
194 min, sec); 236 min, sec);
195 netif_dormant_off(dev); 237 netif_dormant_off(dev);
196 hdlc->state.cisco.up = 1; 238 state(hdlc)->up = 1;
197 } 239 }
198 } 240 }
199 241
@@ -208,7 +250,7 @@ static int cisco_rx(struct sk_buff *skb)
208 return NET_RX_DROP; 250 return NET_RX_DROP;
209 251
210 rx_error: 252 rx_error:
211 hdlc->stats.rx_errors++; /* Mark error */ 253 dev_to_desc(dev)->stats.rx_errors++; /* Mark error */
212 dev_kfree_skb_any(skb); 254 dev_kfree_skb_any(skb);
213 return NET_RX_DROP; 255 return NET_RX_DROP;
214} 256}
@@ -220,23 +262,22 @@ static void cisco_timer(unsigned long arg)
220 struct net_device *dev = (struct net_device *)arg; 262 struct net_device *dev = (struct net_device *)arg;
221 hdlc_device *hdlc = dev_to_hdlc(dev); 263 hdlc_device *hdlc = dev_to_hdlc(dev);
222 264
223 if (hdlc->state.cisco.up && 265 if (state(hdlc)->up &&
224 time_after(jiffies, hdlc->state.cisco.last_poll + 266 time_after(jiffies, state(hdlc)->last_poll +
225 hdlc->state.cisco.settings.timeout * HZ)) { 267 state(hdlc)->settings.timeout * HZ)) {
226 hdlc->state.cisco.up = 0; 268 state(hdlc)->up = 0;
227 printk(KERN_INFO "%s: Link down\n", dev->name); 269 printk(KERN_INFO "%s: Link down\n", dev->name);
228 netif_dormant_on(dev); 270 netif_dormant_on(dev);
229 } 271 }
230 272
231 cisco_keepalive_send(dev, CISCO_KEEPALIVE_REQ, 273 cisco_keepalive_send(dev, CISCO_KEEPALIVE_REQ, ++state(hdlc)->txseq,
232 ++hdlc->state.cisco.txseq, 274 state(hdlc)->rxseq);
233 hdlc->state.cisco.rxseq); 275 state(hdlc)->request_sent = 1;
234 hdlc->state.cisco.request_sent = 1; 276 state(hdlc)->timer.expires = jiffies +
235 hdlc->state.cisco.timer.expires = jiffies + 277 state(hdlc)->settings.interval * HZ;
236 hdlc->state.cisco.settings.interval * HZ; 278 state(hdlc)->timer.function = cisco_timer;
237 hdlc->state.cisco.timer.function = cisco_timer; 279 state(hdlc)->timer.data = arg;
238 hdlc->state.cisco.timer.data = arg; 280 add_timer(&state(hdlc)->timer);
239 add_timer(&hdlc->state.cisco.timer);
240} 281}
241 282
242 283
@@ -244,15 +285,15 @@ static void cisco_timer(unsigned long arg)
244static void cisco_start(struct net_device *dev) 285static void cisco_start(struct net_device *dev)
245{ 286{
246 hdlc_device *hdlc = dev_to_hdlc(dev); 287 hdlc_device *hdlc = dev_to_hdlc(dev);
247 hdlc->state.cisco.up = 0; 288 state(hdlc)->up = 0;
248 hdlc->state.cisco.request_sent = 0; 289 state(hdlc)->request_sent = 0;
249 hdlc->state.cisco.txseq = hdlc->state.cisco.rxseq = 0; 290 state(hdlc)->txseq = state(hdlc)->rxseq = 0;
250 291
251 init_timer(&hdlc->state.cisco.timer); 292 init_timer(&state(hdlc)->timer);
252 hdlc->state.cisco.timer.expires = jiffies + HZ; /*First poll after 1s*/ 293 state(hdlc)->timer.expires = jiffies + HZ; /*First poll after 1s*/
253 hdlc->state.cisco.timer.function = cisco_timer; 294 state(hdlc)->timer.function = cisco_timer;
254 hdlc->state.cisco.timer.data = (unsigned long)dev; 295 state(hdlc)->timer.data = (unsigned long)dev;
255 add_timer(&hdlc->state.cisco.timer); 296 add_timer(&state(hdlc)->timer);
256} 297}
257 298
258 299
@@ -260,15 +301,24 @@ static void cisco_start(struct net_device *dev)
260static void cisco_stop(struct net_device *dev) 301static void cisco_stop(struct net_device *dev)
261{ 302{
262 hdlc_device *hdlc = dev_to_hdlc(dev); 303 hdlc_device *hdlc = dev_to_hdlc(dev);
263 del_timer_sync(&hdlc->state.cisco.timer); 304 del_timer_sync(&state(hdlc)->timer);
264 netif_dormant_on(dev); 305 netif_dormant_on(dev);
265 hdlc->state.cisco.up = 0; 306 state(hdlc)->up = 0;
266 hdlc->state.cisco.request_sent = 0; 307 state(hdlc)->request_sent = 0;
267} 308}
268 309
269 310
270 311
271int hdlc_cisco_ioctl(struct net_device *dev, struct ifreq *ifr) 312static struct hdlc_proto proto = {
313 .start = cisco_start,
314 .stop = cisco_stop,
315 .type_trans = cisco_type_trans,
316 .ioctl = cisco_ioctl,
317 .module = THIS_MODULE,
318};
319
320
321static int cisco_ioctl(struct net_device *dev, struct ifreq *ifr)
272{ 322{
273 cisco_proto __user *cisco_s = ifr->ifr_settings.ifs_ifsu.cisco; 323 cisco_proto __user *cisco_s = ifr->ifr_settings.ifs_ifsu.cisco;
274 const size_t size = sizeof(cisco_proto); 324 const size_t size = sizeof(cisco_proto);
@@ -278,12 +328,14 @@ int hdlc_cisco_ioctl(struct net_device *dev, struct ifreq *ifr)
278 328
279 switch (ifr->ifr_settings.type) { 329 switch (ifr->ifr_settings.type) {
280 case IF_GET_PROTO: 330 case IF_GET_PROTO:
331 if (dev_to_hdlc(dev)->proto != &proto)
332 return -EINVAL;
281 ifr->ifr_settings.type = IF_PROTO_CISCO; 333 ifr->ifr_settings.type = IF_PROTO_CISCO;
282 if (ifr->ifr_settings.size < size) { 334 if (ifr->ifr_settings.size < size) {
283 ifr->ifr_settings.size = size; /* data size wanted */ 335 ifr->ifr_settings.size = size; /* data size wanted */
284 return -ENOBUFS; 336 return -ENOBUFS;
285 } 337 }
286 if (copy_to_user(cisco_s, &hdlc->state.cisco.settings, size)) 338 if (copy_to_user(cisco_s, &state(hdlc)->settings, size))
287 return -EFAULT; 339 return -EFAULT;
288 return 0; 340 return 0;
289 341
@@ -302,19 +354,15 @@ int hdlc_cisco_ioctl(struct net_device *dev, struct ifreq *ifr)
302 return -EINVAL; 354 return -EINVAL;
303 355
304 result=hdlc->attach(dev, ENCODING_NRZ,PARITY_CRC16_PR1_CCITT); 356 result=hdlc->attach(dev, ENCODING_NRZ,PARITY_CRC16_PR1_CCITT);
305
306 if (result) 357 if (result)
307 return result; 358 return result;
308 359
309 hdlc_proto_detach(hdlc); 360 result = attach_hdlc_protocol(dev, &proto, cisco_rx,
310 memcpy(&hdlc->state.cisco.settings, &new_settings, size); 361 sizeof(struct cisco_state));
311 memset(&hdlc->proto, 0, sizeof(hdlc->proto)); 362 if (result)
363 return result;
312 364
313 hdlc->proto.start = cisco_start; 365 memcpy(&state(hdlc)->settings, &new_settings, size);
314 hdlc->proto.stop = cisco_stop;
315 hdlc->proto.netif_rx = cisco_rx;
316 hdlc->proto.type_trans = cisco_type_trans;
317 hdlc->proto.id = IF_PROTO_CISCO;
318 dev->hard_start_xmit = hdlc->xmit; 366 dev->hard_start_xmit = hdlc->xmit;
319 dev->hard_header = cisco_hard_header; 367 dev->hard_header = cisco_hard_header;
320 dev->hard_header_cache = NULL; 368 dev->hard_header_cache = NULL;
@@ -327,3 +375,25 @@ int hdlc_cisco_ioctl(struct net_device *dev, struct ifreq *ifr)
327 375
328 return -EINVAL; 376 return -EINVAL;
329} 377}
378
379
380static int __init mod_init(void)
381{
382 register_hdlc_protocol(&proto);
383 return 0;
384}
385
386
387
388static void __exit mod_exit(void)
389{
390 unregister_hdlc_protocol(&proto);
391}
392
393
394module_init(mod_init);
395module_exit(mod_exit);
396
397MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
398MODULE_DESCRIPTION("Cisco HDLC protocol support for generic HDLC");
399MODULE_LICENSE("GPL v2");
diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c
index 7bb737bbdeb9..b45ab680d2d6 100644
--- a/drivers/net/wan/hdlc_fr.c
+++ b/drivers/net/wan/hdlc_fr.c
@@ -2,7 +2,7 @@
2 * Generic HDLC support routines for Linux 2 * Generic HDLC support routines for Linux
3 * Frame Relay support 3 * Frame Relay support
4 * 4 *
5 * Copyright (C) 1999 - 2005 Krzysztof Halasa <khc@pm.waw.pl> 5 * Copyright (C) 1999 - 2006 Krzysztof Halasa <khc@pm.waw.pl>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify it 7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License 8 * under the terms of version 2 of the GNU General Public License
@@ -52,6 +52,8 @@
52#undef DEBUG_PKT 52#undef DEBUG_PKT
53#undef DEBUG_ECN 53#undef DEBUG_ECN
54#undef DEBUG_LINK 54#undef DEBUG_LINK
55#undef DEBUG_PROTO
56#undef DEBUG_PVC
55 57
56#define FR_UI 0x03 58#define FR_UI 0x03
57#define FR_PAD 0x00 59#define FR_PAD 0x00
@@ -115,13 +117,53 @@ typedef struct {
115}__attribute__ ((packed)) fr_hdr; 117}__attribute__ ((packed)) fr_hdr;
116 118
117 119
120typedef struct pvc_device_struct {
121 struct net_device *frad;
122 struct net_device *main;
123 struct net_device *ether; /* bridged Ethernet interface */
124 struct pvc_device_struct *next; /* Sorted in ascending DLCI order */
125 int dlci;
126 int open_count;
127
128 struct {
129 unsigned int new: 1;
130 unsigned int active: 1;
131 unsigned int exist: 1;
132 unsigned int deleted: 1;
133 unsigned int fecn: 1;
134 unsigned int becn: 1;
135 unsigned int bandwidth; /* Cisco LMI reporting only */
136 }state;
137}pvc_device;
138
139
140struct frad_state {
141 fr_proto settings;
142 pvc_device *first_pvc;
143 int dce_pvc_count;
144
145 struct timer_list timer;
146 unsigned long last_poll;
147 int reliable;
148 int dce_changed;
149 int request;
150 int fullrep_sent;
151 u32 last_errors; /* last errors bit list */
152 u8 n391cnt;
153 u8 txseq; /* TX sequence number */
154 u8 rxseq; /* RX sequence number */
155};
156
157
158static int fr_ioctl(struct net_device *dev, struct ifreq *ifr);
159
160
118static inline u16 q922_to_dlci(u8 *hdr) 161static inline u16 q922_to_dlci(u8 *hdr)
119{ 162{
120 return ((hdr[0] & 0xFC) << 2) | ((hdr[1] & 0xF0) >> 4); 163 return ((hdr[0] & 0xFC) << 2) | ((hdr[1] & 0xF0) >> 4);
121} 164}
122 165
123 166
124
125static inline void dlci_to_q922(u8 *hdr, u16 dlci) 167static inline void dlci_to_q922(u8 *hdr, u16 dlci)
126{ 168{
127 hdr[0] = (dlci >> 2) & 0xFC; 169 hdr[0] = (dlci >> 2) & 0xFC;
@@ -129,10 +171,21 @@ static inline void dlci_to_q922(u8 *hdr, u16 dlci)
129} 171}
130 172
131 173
174static inline struct frad_state * state(hdlc_device *hdlc)
175{
176 return(struct frad_state *)(hdlc->state);
177}
178
179
180static __inline__ pvc_device* dev_to_pvc(struct net_device *dev)
181{
182 return dev->priv;
183}
184
132 185
133static inline pvc_device* find_pvc(hdlc_device *hdlc, u16 dlci) 186static inline pvc_device* find_pvc(hdlc_device *hdlc, u16 dlci)
134{ 187{
135 pvc_device *pvc = hdlc->state.fr.first_pvc; 188 pvc_device *pvc = state(hdlc)->first_pvc;
136 189
137 while (pvc) { 190 while (pvc) {
138 if (pvc->dlci == dlci) 191 if (pvc->dlci == dlci)
@@ -146,10 +199,10 @@ static inline pvc_device* find_pvc(hdlc_device *hdlc, u16 dlci)
146} 199}
147 200
148 201
149static inline pvc_device* add_pvc(struct net_device *dev, u16 dlci) 202static pvc_device* add_pvc(struct net_device *dev, u16 dlci)
150{ 203{
151 hdlc_device *hdlc = dev_to_hdlc(dev); 204 hdlc_device *hdlc = dev_to_hdlc(dev);
152 pvc_device *pvc, **pvc_p = &hdlc->state.fr.first_pvc; 205 pvc_device *pvc, **pvc_p = &state(hdlc)->first_pvc;
153 206
154 while (*pvc_p) { 207 while (*pvc_p) {
155 if ((*pvc_p)->dlci == dlci) 208 if ((*pvc_p)->dlci == dlci)
@@ -160,12 +213,15 @@ static inline pvc_device* add_pvc(struct net_device *dev, u16 dlci)
160 } 213 }
161 214
162 pvc = kmalloc(sizeof(pvc_device), GFP_ATOMIC); 215 pvc = kmalloc(sizeof(pvc_device), GFP_ATOMIC);
216#ifdef DEBUG_PVC
217 printk(KERN_DEBUG "add_pvc: allocated pvc %p, frad %p\n", pvc, dev);
218#endif
163 if (!pvc) 219 if (!pvc)
164 return NULL; 220 return NULL;
165 221
166 memset(pvc, 0, sizeof(pvc_device)); 222 memset(pvc, 0, sizeof(pvc_device));
167 pvc->dlci = dlci; 223 pvc->dlci = dlci;
168 pvc->master = dev; 224 pvc->frad = dev;
169 pvc->next = *pvc_p; /* Put it in the chain */ 225 pvc->next = *pvc_p; /* Put it in the chain */
170 *pvc_p = pvc; 226 *pvc_p = pvc;
171 return pvc; 227 return pvc;
@@ -174,7 +230,7 @@ static inline pvc_device* add_pvc(struct net_device *dev, u16 dlci)
174 230
175static inline int pvc_is_used(pvc_device *pvc) 231static inline int pvc_is_used(pvc_device *pvc)
176{ 232{
177 return pvc->main != NULL || pvc->ether != NULL; 233 return pvc->main || pvc->ether;
178} 234}
179 235
180 236
@@ -200,11 +256,14 @@ static inline void pvc_carrier(int on, pvc_device *pvc)
200 256
201static inline void delete_unused_pvcs(hdlc_device *hdlc) 257static inline void delete_unused_pvcs(hdlc_device *hdlc)
202{ 258{
203 pvc_device **pvc_p = &hdlc->state.fr.first_pvc; 259 pvc_device **pvc_p = &state(hdlc)->first_pvc;
204 260
205 while (*pvc_p) { 261 while (*pvc_p) {
206 if (!pvc_is_used(*pvc_p)) { 262 if (!pvc_is_used(*pvc_p)) {
207 pvc_device *pvc = *pvc_p; 263 pvc_device *pvc = *pvc_p;
264#ifdef DEBUG_PVC
265 printk(KERN_DEBUG "freeing unused pvc: %p\n", pvc);
266#endif
208 *pvc_p = pvc->next; 267 *pvc_p = pvc->next;
209 kfree(pvc); 268 kfree(pvc);
210 continue; 269 continue;
@@ -295,16 +354,16 @@ static int pvc_open(struct net_device *dev)
295{ 354{
296 pvc_device *pvc = dev_to_pvc(dev); 355 pvc_device *pvc = dev_to_pvc(dev);
297 356
298 if ((pvc->master->flags & IFF_UP) == 0) 357 if ((pvc->frad->flags & IFF_UP) == 0)
299 return -EIO; /* Master must be UP in order to activate PVC */ 358 return -EIO; /* Frad must be UP in order to activate PVC */
300 359
301 if (pvc->open_count++ == 0) { 360 if (pvc->open_count++ == 0) {
302 hdlc_device *hdlc = dev_to_hdlc(pvc->master); 361 hdlc_device *hdlc = dev_to_hdlc(pvc->frad);
303 if (hdlc->state.fr.settings.lmi == LMI_NONE) 362 if (state(hdlc)->settings.lmi == LMI_NONE)
304 pvc->state.active = netif_carrier_ok(pvc->master); 363 pvc->state.active = netif_carrier_ok(pvc->frad);
305 364
306 pvc_carrier(pvc->state.active, pvc); 365 pvc_carrier(pvc->state.active, pvc);
307 hdlc->state.fr.dce_changed = 1; 366 state(hdlc)->dce_changed = 1;
308 } 367 }
309 return 0; 368 return 0;
310} 369}
@@ -316,12 +375,12 @@ static int pvc_close(struct net_device *dev)
316 pvc_device *pvc = dev_to_pvc(dev); 375 pvc_device *pvc = dev_to_pvc(dev);
317 376
318 if (--pvc->open_count == 0) { 377 if (--pvc->open_count == 0) {
319 hdlc_device *hdlc = dev_to_hdlc(pvc->master); 378 hdlc_device *hdlc = dev_to_hdlc(pvc->frad);
320 if (hdlc->state.fr.settings.lmi == LMI_NONE) 379 if (state(hdlc)->settings.lmi == LMI_NONE)
321 pvc->state.active = 0; 380 pvc->state.active = 0;
322 381
323 if (hdlc->state.fr.settings.dce) { 382 if (state(hdlc)->settings.dce) {
324 hdlc->state.fr.dce_changed = 1; 383 state(hdlc)->dce_changed = 1;
325 pvc->state.active = 0; 384 pvc->state.active = 0;
326 } 385 }
327 } 386 }
@@ -348,7 +407,7 @@ static int pvc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
348 } 407 }
349 408
350 info.dlci = pvc->dlci; 409 info.dlci = pvc->dlci;
351 memcpy(info.master, pvc->master->name, IFNAMSIZ); 410 memcpy(info.master, pvc->frad->name, IFNAMSIZ);
352 if (copy_to_user(ifr->ifr_settings.ifs_ifsu.fr_pvc_info, 411 if (copy_to_user(ifr->ifr_settings.ifs_ifsu.fr_pvc_info,
353 &info, sizeof(info))) 412 &info, sizeof(info)))
354 return -EFAULT; 413 return -EFAULT;
@@ -361,7 +420,7 @@ static int pvc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
361 420
362static inline struct net_device_stats *pvc_get_stats(struct net_device *dev) 421static inline struct net_device_stats *pvc_get_stats(struct net_device *dev)
363{ 422{
364 return netdev_priv(dev); 423 return &dev_to_desc(dev)->stats;
365} 424}
366 425
367 426
@@ -393,7 +452,7 @@ static int pvc_xmit(struct sk_buff *skb, struct net_device *dev)
393 stats->tx_packets++; 452 stats->tx_packets++;
394 if (pvc->state.fecn) /* TX Congestion counter */ 453 if (pvc->state.fecn) /* TX Congestion counter */
395 stats->tx_compressed++; 454 stats->tx_compressed++;
396 skb->dev = pvc->master; 455 skb->dev = pvc->frad;
397 dev_queue_xmit(skb); 456 dev_queue_xmit(skb);
398 return 0; 457 return 0;
399 } 458 }
@@ -419,7 +478,7 @@ static int pvc_change_mtu(struct net_device *dev, int new_mtu)
419static inline void fr_log_dlci_active(pvc_device *pvc) 478static inline void fr_log_dlci_active(pvc_device *pvc)
420{ 479{
421 printk(KERN_INFO "%s: DLCI %d [%s%s%s]%s %s\n", 480 printk(KERN_INFO "%s: DLCI %d [%s%s%s]%s %s\n",
422 pvc->master->name, 481 pvc->frad->name,
423 pvc->dlci, 482 pvc->dlci,
424 pvc->main ? pvc->main->name : "", 483 pvc->main ? pvc->main->name : "",
425 pvc->main && pvc->ether ? " " : "", 484 pvc->main && pvc->ether ? " " : "",
@@ -438,21 +497,20 @@ static inline u8 fr_lmi_nextseq(u8 x)
438} 497}
439 498
440 499
441
442static void fr_lmi_send(struct net_device *dev, int fullrep) 500static void fr_lmi_send(struct net_device *dev, int fullrep)
443{ 501{
444 hdlc_device *hdlc = dev_to_hdlc(dev); 502 hdlc_device *hdlc = dev_to_hdlc(dev);
445 struct sk_buff *skb; 503 struct sk_buff *skb;
446 pvc_device *pvc = hdlc->state.fr.first_pvc; 504 pvc_device *pvc = state(hdlc)->first_pvc;
447 int lmi = hdlc->state.fr.settings.lmi; 505 int lmi = state(hdlc)->settings.lmi;
448 int dce = hdlc->state.fr.settings.dce; 506 int dce = state(hdlc)->settings.dce;
449 int len = lmi == LMI_ANSI ? LMI_ANSI_LENGTH : LMI_CCITT_CISCO_LENGTH; 507 int len = lmi == LMI_ANSI ? LMI_ANSI_LENGTH : LMI_CCITT_CISCO_LENGTH;
450 int stat_len = (lmi == LMI_CISCO) ? 6 : 3; 508 int stat_len = (lmi == LMI_CISCO) ? 6 : 3;
451 u8 *data; 509 u8 *data;
452 int i = 0; 510 int i = 0;
453 511
454 if (dce && fullrep) { 512 if (dce && fullrep) {
455 len += hdlc->state.fr.dce_pvc_count * (2 + stat_len); 513 len += state(hdlc)->dce_pvc_count * (2 + stat_len);
456 if (len > HDLC_MAX_MRU) { 514 if (len > HDLC_MAX_MRU) {
457 printk(KERN_WARNING "%s: Too many PVCs while sending " 515 printk(KERN_WARNING "%s: Too many PVCs while sending "
458 "LMI full report\n", dev->name); 516 "LMI full report\n", dev->name);
@@ -486,8 +544,9 @@ static void fr_lmi_send(struct net_device *dev, int fullrep)
486 data[i++] = fullrep ? LMI_FULLREP : LMI_INTEGRITY; 544 data[i++] = fullrep ? LMI_FULLREP : LMI_INTEGRITY;
487 data[i++] = lmi == LMI_CCITT ? LMI_CCITT_ALIVE : LMI_ANSI_CISCO_ALIVE; 545 data[i++] = lmi == LMI_CCITT ? LMI_CCITT_ALIVE : LMI_ANSI_CISCO_ALIVE;
488 data[i++] = LMI_INTEG_LEN; 546 data[i++] = LMI_INTEG_LEN;
489 data[i++] = hdlc->state.fr.txseq =fr_lmi_nextseq(hdlc->state.fr.txseq); 547 data[i++] = state(hdlc)->txseq =
490 data[i++] = hdlc->state.fr.rxseq; 548 fr_lmi_nextseq(state(hdlc)->txseq);
549 data[i++] = state(hdlc)->rxseq;
491 550
492 if (dce && fullrep) { 551 if (dce && fullrep) {
493 while (pvc) { 552 while (pvc) {
@@ -496,7 +555,7 @@ static void fr_lmi_send(struct net_device *dev, int fullrep)
496 data[i++] = stat_len; 555 data[i++] = stat_len;
497 556
498 /* LMI start/restart */ 557 /* LMI start/restart */
499 if (hdlc->state.fr.reliable && !pvc->state.exist) { 558 if (state(hdlc)->reliable && !pvc->state.exist) {
500 pvc->state.exist = pvc->state.new = 1; 559 pvc->state.exist = pvc->state.new = 1;
501 fr_log_dlci_active(pvc); 560 fr_log_dlci_active(pvc);
502 } 561 }
@@ -541,15 +600,15 @@ static void fr_lmi_send(struct net_device *dev, int fullrep)
541static void fr_set_link_state(int reliable, struct net_device *dev) 600static void fr_set_link_state(int reliable, struct net_device *dev)
542{ 601{
543 hdlc_device *hdlc = dev_to_hdlc(dev); 602 hdlc_device *hdlc = dev_to_hdlc(dev);
544 pvc_device *pvc = hdlc->state.fr.first_pvc; 603 pvc_device *pvc = state(hdlc)->first_pvc;
545 604
546 hdlc->state.fr.reliable = reliable; 605 state(hdlc)->reliable = reliable;
547 if (reliable) { 606 if (reliable) {
548 netif_dormant_off(dev); 607 netif_dormant_off(dev);
549 hdlc->state.fr.n391cnt = 0; /* Request full status */ 608 state(hdlc)->n391cnt = 0; /* Request full status */
550 hdlc->state.fr.dce_changed = 1; 609 state(hdlc)->dce_changed = 1;
551 610
552 if (hdlc->state.fr.settings.lmi == LMI_NONE) { 611 if (state(hdlc)->settings.lmi == LMI_NONE) {
553 while (pvc) { /* Activate all PVCs */ 612 while (pvc) { /* Activate all PVCs */
554 pvc_carrier(1, pvc); 613 pvc_carrier(1, pvc);
555 pvc->state.exist = pvc->state.active = 1; 614 pvc->state.exist = pvc->state.active = 1;
@@ -563,7 +622,7 @@ static void fr_set_link_state(int reliable, struct net_device *dev)
563 pvc_carrier(0, pvc); 622 pvc_carrier(0, pvc);
564 pvc->state.exist = pvc->state.active = 0; 623 pvc->state.exist = pvc->state.active = 0;
565 pvc->state.new = 0; 624 pvc->state.new = 0;
566 if (!hdlc->state.fr.settings.dce) 625 if (!state(hdlc)->settings.dce)
567 pvc->state.bandwidth = 0; 626 pvc->state.bandwidth = 0;
568 pvc = pvc->next; 627 pvc = pvc->next;
569 } 628 }
@@ -571,7 +630,6 @@ static void fr_set_link_state(int reliable, struct net_device *dev)
571} 630}
572 631
573 632
574
575static void fr_timer(unsigned long arg) 633static void fr_timer(unsigned long arg)
576{ 634{
577 struct net_device *dev = (struct net_device *)arg; 635 struct net_device *dev = (struct net_device *)arg;
@@ -579,62 +637,61 @@ static void fr_timer(unsigned long arg)
579 int i, cnt = 0, reliable; 637 int i, cnt = 0, reliable;
580 u32 list; 638 u32 list;
581 639
582 if (hdlc->state.fr.settings.dce) { 640 if (state(hdlc)->settings.dce) {
583 reliable = hdlc->state.fr.request && 641 reliable = state(hdlc)->request &&
584 time_before(jiffies, hdlc->state.fr.last_poll + 642 time_before(jiffies, state(hdlc)->last_poll +
585 hdlc->state.fr.settings.t392 * HZ); 643 state(hdlc)->settings.t392 * HZ);
586 hdlc->state.fr.request = 0; 644 state(hdlc)->request = 0;
587 } else { 645 } else {
588 hdlc->state.fr.last_errors <<= 1; /* Shift the list */ 646 state(hdlc)->last_errors <<= 1; /* Shift the list */
589 if (hdlc->state.fr.request) { 647 if (state(hdlc)->request) {
590 if (hdlc->state.fr.reliable) 648 if (state(hdlc)->reliable)
591 printk(KERN_INFO "%s: No LMI status reply " 649 printk(KERN_INFO "%s: No LMI status reply "
592 "received\n", dev->name); 650 "received\n", dev->name);
593 hdlc->state.fr.last_errors |= 1; 651 state(hdlc)->last_errors |= 1;
594 } 652 }
595 653
596 list = hdlc->state.fr.last_errors; 654 list = state(hdlc)->last_errors;
597 for (i = 0; i < hdlc->state.fr.settings.n393; i++, list >>= 1) 655 for (i = 0; i < state(hdlc)->settings.n393; i++, list >>= 1)
598 cnt += (list & 1); /* errors count */ 656 cnt += (list & 1); /* errors count */
599 657
600 reliable = (cnt < hdlc->state.fr.settings.n392); 658 reliable = (cnt < state(hdlc)->settings.n392);
601 } 659 }
602 660
603 if (hdlc->state.fr.reliable != reliable) { 661 if (state(hdlc)->reliable != reliable) {
604 printk(KERN_INFO "%s: Link %sreliable\n", dev->name, 662 printk(KERN_INFO "%s: Link %sreliable\n", dev->name,
605 reliable ? "" : "un"); 663 reliable ? "" : "un");
606 fr_set_link_state(reliable, dev); 664 fr_set_link_state(reliable, dev);
607 } 665 }
608 666
609 if (hdlc->state.fr.settings.dce) 667 if (state(hdlc)->settings.dce)
610 hdlc->state.fr.timer.expires = jiffies + 668 state(hdlc)->timer.expires = jiffies +
611 hdlc->state.fr.settings.t392 * HZ; 669 state(hdlc)->settings.t392 * HZ;
612 else { 670 else {
613 if (hdlc->state.fr.n391cnt) 671 if (state(hdlc)->n391cnt)
614 hdlc->state.fr.n391cnt--; 672 state(hdlc)->n391cnt--;
615 673
616 fr_lmi_send(dev, hdlc->state.fr.n391cnt == 0); 674 fr_lmi_send(dev, state(hdlc)->n391cnt == 0);
617 675
618 hdlc->state.fr.last_poll = jiffies; 676 state(hdlc)->last_poll = jiffies;
619 hdlc->state.fr.request = 1; 677 state(hdlc)->request = 1;
620 hdlc->state.fr.timer.expires = jiffies + 678 state(hdlc)->timer.expires = jiffies +
621 hdlc->state.fr.settings.t391 * HZ; 679 state(hdlc)->settings.t391 * HZ;
622 } 680 }
623 681
624 hdlc->state.fr.timer.function = fr_timer; 682 state(hdlc)->timer.function = fr_timer;
625 hdlc->state.fr.timer.data = arg; 683 state(hdlc)->timer.data = arg;
626 add_timer(&hdlc->state.fr.timer); 684 add_timer(&state(hdlc)->timer);
627} 685}
628 686
629 687
630
631static int fr_lmi_recv(struct net_device *dev, struct sk_buff *skb) 688static int fr_lmi_recv(struct net_device *dev, struct sk_buff *skb)
632{ 689{
633 hdlc_device *hdlc = dev_to_hdlc(dev); 690 hdlc_device *hdlc = dev_to_hdlc(dev);
634 pvc_device *pvc; 691 pvc_device *pvc;
635 u8 rxseq, txseq; 692 u8 rxseq, txseq;
636 int lmi = hdlc->state.fr.settings.lmi; 693 int lmi = state(hdlc)->settings.lmi;
637 int dce = hdlc->state.fr.settings.dce; 694 int dce = state(hdlc)->settings.dce;
638 int stat_len = (lmi == LMI_CISCO) ? 6 : 3, reptype, error, no_ram, i; 695 int stat_len = (lmi == LMI_CISCO) ? 6 : 3, reptype, error, no_ram, i;
639 696
640 if (skb->len < (lmi == LMI_ANSI ? LMI_ANSI_LENGTH : 697 if (skb->len < (lmi == LMI_ANSI ? LMI_ANSI_LENGTH :
@@ -645,8 +702,8 @@ static int fr_lmi_recv(struct net_device *dev, struct sk_buff *skb)
645 702
646 if (skb->data[3] != (lmi == LMI_CISCO ? NLPID_CISCO_LMI : 703 if (skb->data[3] != (lmi == LMI_CISCO ? NLPID_CISCO_LMI :
647 NLPID_CCITT_ANSI_LMI)) { 704 NLPID_CCITT_ANSI_LMI)) {
648 printk(KERN_INFO "%s: Received non-LMI frame with LMI" 705 printk(KERN_INFO "%s: Received non-LMI frame with LMI DLCI\n",
649 " DLCI\n", dev->name); 706 dev->name);
650 return 1; 707 return 1;
651 } 708 }
652 709
@@ -706,53 +763,53 @@ static int fr_lmi_recv(struct net_device *dev, struct sk_buff *skb)
706 } 763 }
707 i++; 764 i++;
708 765
709 hdlc->state.fr.rxseq = skb->data[i++]; /* TX sequence from peer */ 766 state(hdlc)->rxseq = skb->data[i++]; /* TX sequence from peer */
710 rxseq = skb->data[i++]; /* Should confirm our sequence */ 767 rxseq = skb->data[i++]; /* Should confirm our sequence */
711 768
712 txseq = hdlc->state.fr.txseq; 769 txseq = state(hdlc)->txseq;
713 770
714 if (dce) 771 if (dce)
715 hdlc->state.fr.last_poll = jiffies; 772 state(hdlc)->last_poll = jiffies;
716 773
717 error = 0; 774 error = 0;
718 if (!hdlc->state.fr.reliable) 775 if (!state(hdlc)->reliable)
719 error = 1; 776 error = 1;
720 777
721 if (rxseq == 0 || rxseq != txseq) { 778 if (rxseq == 0 || rxseq != txseq) { /* Ask for full report next time */
722 hdlc->state.fr.n391cnt = 0; /* Ask for full report next time */ 779 state(hdlc)->n391cnt = 0;
723 error = 1; 780 error = 1;
724 } 781 }
725 782
726 if (dce) { 783 if (dce) {
727 if (hdlc->state.fr.fullrep_sent && !error) { 784 if (state(hdlc)->fullrep_sent && !error) {
728/* Stop sending full report - the last one has been confirmed by DTE */ 785/* Stop sending full report - the last one has been confirmed by DTE */
729 hdlc->state.fr.fullrep_sent = 0; 786 state(hdlc)->fullrep_sent = 0;
730 pvc = hdlc->state.fr.first_pvc; 787 pvc = state(hdlc)->first_pvc;
731 while (pvc) { 788 while (pvc) {
732 if (pvc->state.new) { 789 if (pvc->state.new) {
733 pvc->state.new = 0; 790 pvc->state.new = 0;
734 791
735/* Tell DTE that new PVC is now active */ 792/* Tell DTE that new PVC is now active */
736 hdlc->state.fr.dce_changed = 1; 793 state(hdlc)->dce_changed = 1;
737 } 794 }
738 pvc = pvc->next; 795 pvc = pvc->next;
739 } 796 }
740 } 797 }
741 798
742 if (hdlc->state.fr.dce_changed) { 799 if (state(hdlc)->dce_changed) {
743 reptype = LMI_FULLREP; 800 reptype = LMI_FULLREP;
744 hdlc->state.fr.fullrep_sent = 1; 801 state(hdlc)->fullrep_sent = 1;
745 hdlc->state.fr.dce_changed = 0; 802 state(hdlc)->dce_changed = 0;
746 } 803 }
747 804
748 hdlc->state.fr.request = 1; /* got request */ 805 state(hdlc)->request = 1; /* got request */
749 fr_lmi_send(dev, reptype == LMI_FULLREP ? 1 : 0); 806 fr_lmi_send(dev, reptype == LMI_FULLREP ? 1 : 0);
750 return 0; 807 return 0;
751 } 808 }
752 809
753 /* DTE */ 810 /* DTE */
754 811
755 hdlc->state.fr.request = 0; /* got response, no request pending */ 812 state(hdlc)->request = 0; /* got response, no request pending */
756 813
757 if (error) 814 if (error)
758 return 0; 815 return 0;
@@ -760,7 +817,7 @@ static int fr_lmi_recv(struct net_device *dev, struct sk_buff *skb)
760 if (reptype != LMI_FULLREP) 817 if (reptype != LMI_FULLREP)
761 return 0; 818 return 0;
762 819
763 pvc = hdlc->state.fr.first_pvc; 820 pvc = state(hdlc)->first_pvc;
764 821
765 while (pvc) { 822 while (pvc) {
766 pvc->state.deleted = 1; 823 pvc->state.deleted = 1;
@@ -827,7 +884,7 @@ static int fr_lmi_recv(struct net_device *dev, struct sk_buff *skb)
827 i += stat_len; 884 i += stat_len;
828 } 885 }
829 886
830 pvc = hdlc->state.fr.first_pvc; 887 pvc = state(hdlc)->first_pvc;
831 888
832 while (pvc) { 889 while (pvc) {
833 if (pvc->state.deleted && pvc->state.exist) { 890 if (pvc->state.deleted && pvc->state.exist) {
@@ -841,17 +898,16 @@ static int fr_lmi_recv(struct net_device *dev, struct sk_buff *skb)
841 } 898 }
842 899
843 /* Next full report after N391 polls */ 900 /* Next full report after N391 polls */
844 hdlc->state.fr.n391cnt = hdlc->state.fr.settings.n391; 901 state(hdlc)->n391cnt = state(hdlc)->settings.n391;
845 902
846 return 0; 903 return 0;
847} 904}
848 905
849 906
850
851static int fr_rx(struct sk_buff *skb) 907static int fr_rx(struct sk_buff *skb)
852{ 908{
853 struct net_device *ndev = skb->dev; 909 struct net_device *frad = skb->dev;
854 hdlc_device *hdlc = dev_to_hdlc(ndev); 910 hdlc_device *hdlc = dev_to_hdlc(frad);
855 fr_hdr *fh = (fr_hdr*)skb->data; 911 fr_hdr *fh = (fr_hdr*)skb->data;
856 u8 *data = skb->data; 912 u8 *data = skb->data;
857 u16 dlci; 913 u16 dlci;
@@ -864,11 +920,11 @@ static int fr_rx(struct sk_buff *skb)
864 dlci = q922_to_dlci(skb->data); 920 dlci = q922_to_dlci(skb->data);
865 921
866 if ((dlci == LMI_CCITT_ANSI_DLCI && 922 if ((dlci == LMI_CCITT_ANSI_DLCI &&
867 (hdlc->state.fr.settings.lmi == LMI_ANSI || 923 (state(hdlc)->settings.lmi == LMI_ANSI ||
868 hdlc->state.fr.settings.lmi == LMI_CCITT)) || 924 state(hdlc)->settings.lmi == LMI_CCITT)) ||
869 (dlci == LMI_CISCO_DLCI && 925 (dlci == LMI_CISCO_DLCI &&
870 hdlc->state.fr.settings.lmi == LMI_CISCO)) { 926 state(hdlc)->settings.lmi == LMI_CISCO)) {
871 if (fr_lmi_recv(ndev, skb)) 927 if (fr_lmi_recv(frad, skb))
872 goto rx_error; 928 goto rx_error;
873 dev_kfree_skb_any(skb); 929 dev_kfree_skb_any(skb);
874 return NET_RX_SUCCESS; 930 return NET_RX_SUCCESS;
@@ -878,7 +934,7 @@ static int fr_rx(struct sk_buff *skb)
878 if (!pvc) { 934 if (!pvc) {
879#ifdef DEBUG_PKT 935#ifdef DEBUG_PKT
880 printk(KERN_INFO "%s: No PVC for received frame's DLCI %d\n", 936 printk(KERN_INFO "%s: No PVC for received frame's DLCI %d\n",
881 ndev->name, dlci); 937 frad->name, dlci);
882#endif 938#endif
883 dev_kfree_skb_any(skb); 939 dev_kfree_skb_any(skb);
884 return NET_RX_DROP; 940 return NET_RX_DROP;
@@ -886,7 +942,7 @@ static int fr_rx(struct sk_buff *skb)
886 942
887 if (pvc->state.fecn != fh->fecn) { 943 if (pvc->state.fecn != fh->fecn) {
888#ifdef DEBUG_ECN 944#ifdef DEBUG_ECN
889 printk(KERN_DEBUG "%s: DLCI %d FECN O%s\n", ndev->name, 945 printk(KERN_DEBUG "%s: DLCI %d FECN O%s\n", frad->name,
890 dlci, fh->fecn ? "N" : "FF"); 946 dlci, fh->fecn ? "N" : "FF");
891#endif 947#endif
892 pvc->state.fecn ^= 1; 948 pvc->state.fecn ^= 1;
@@ -894,7 +950,7 @@ static int fr_rx(struct sk_buff *skb)
894 950
895 if (pvc->state.becn != fh->becn) { 951 if (pvc->state.becn != fh->becn) {
896#ifdef DEBUG_ECN 952#ifdef DEBUG_ECN
897 printk(KERN_DEBUG "%s: DLCI %d BECN O%s\n", ndev->name, 953 printk(KERN_DEBUG "%s: DLCI %d BECN O%s\n", frad->name,
898 dlci, fh->becn ? "N" : "FF"); 954 dlci, fh->becn ? "N" : "FF");
899#endif 955#endif
900 pvc->state.becn ^= 1; 956 pvc->state.becn ^= 1;
@@ -902,7 +958,7 @@ static int fr_rx(struct sk_buff *skb)
902 958
903 959
904 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) { 960 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {
905 hdlc->stats.rx_dropped++; 961 dev_to_desc(frad)->stats.rx_dropped++;
906 return NET_RX_DROP; 962 return NET_RX_DROP;
907 } 963 }
908 964
@@ -938,13 +994,13 @@ static int fr_rx(struct sk_buff *skb)
938 994
939 default: 995 default:
940 printk(KERN_INFO "%s: Unsupported protocol, OUI=%x " 996 printk(KERN_INFO "%s: Unsupported protocol, OUI=%x "
941 "PID=%x\n", ndev->name, oui, pid); 997 "PID=%x\n", frad->name, oui, pid);
942 dev_kfree_skb_any(skb); 998 dev_kfree_skb_any(skb);
943 return NET_RX_DROP; 999 return NET_RX_DROP;
944 } 1000 }
945 } else { 1001 } else {
946 printk(KERN_INFO "%s: Unsupported protocol, NLPID=%x " 1002 printk(KERN_INFO "%s: Unsupported protocol, NLPID=%x "
947 "length = %i\n", ndev->name, data[3], skb->len); 1003 "length = %i\n", frad->name, data[3], skb->len);
948 dev_kfree_skb_any(skb); 1004 dev_kfree_skb_any(skb);
949 return NET_RX_DROP; 1005 return NET_RX_DROP;
950 } 1006 }
@@ -964,7 +1020,7 @@ static int fr_rx(struct sk_buff *skb)
964 } 1020 }
965 1021
966 rx_error: 1022 rx_error:
967 hdlc->stats.rx_errors++; /* Mark error */ 1023 dev_to_desc(frad)->stats.rx_errors++; /* Mark error */
968 dev_kfree_skb_any(skb); 1024 dev_kfree_skb_any(skb);
969 return NET_RX_DROP; 1025 return NET_RX_DROP;
970} 1026}
@@ -977,44 +1033,42 @@ static void fr_start(struct net_device *dev)
977#ifdef DEBUG_LINK 1033#ifdef DEBUG_LINK
978 printk(KERN_DEBUG "fr_start\n"); 1034 printk(KERN_DEBUG "fr_start\n");
979#endif 1035#endif
980 if (hdlc->state.fr.settings.lmi != LMI_NONE) { 1036 if (state(hdlc)->settings.lmi != LMI_NONE) {
981 hdlc->state.fr.reliable = 0; 1037 state(hdlc)->reliable = 0;
982 hdlc->state.fr.dce_changed = 1; 1038 state(hdlc)->dce_changed = 1;
983 hdlc->state.fr.request = 0; 1039 state(hdlc)->request = 0;
984 hdlc->state.fr.fullrep_sent = 0; 1040 state(hdlc)->fullrep_sent = 0;
985 hdlc->state.fr.last_errors = 0xFFFFFFFF; 1041 state(hdlc)->last_errors = 0xFFFFFFFF;
986 hdlc->state.fr.n391cnt = 0; 1042 state(hdlc)->n391cnt = 0;
987 hdlc->state.fr.txseq = hdlc->state.fr.rxseq = 0; 1043 state(hdlc)->txseq = state(hdlc)->rxseq = 0;
988 1044
989 init_timer(&hdlc->state.fr.timer); 1045 init_timer(&state(hdlc)->timer);
990 /* First poll after 1 s */ 1046 /* First poll after 1 s */
991 hdlc->state.fr.timer.expires = jiffies + HZ; 1047 state(hdlc)->timer.expires = jiffies + HZ;
992 hdlc->state.fr.timer.function = fr_timer; 1048 state(hdlc)->timer.function = fr_timer;
993 hdlc->state.fr.timer.data = (unsigned long)dev; 1049 state(hdlc)->timer.data = (unsigned long)dev;
994 add_timer(&hdlc->state.fr.timer); 1050 add_timer(&state(hdlc)->timer);
995 } else 1051 } else
996 fr_set_link_state(1, dev); 1052 fr_set_link_state(1, dev);
997} 1053}
998 1054
999 1055
1000
1001static void fr_stop(struct net_device *dev) 1056static void fr_stop(struct net_device *dev)
1002{ 1057{
1003 hdlc_device *hdlc = dev_to_hdlc(dev); 1058 hdlc_device *hdlc = dev_to_hdlc(dev);
1004#ifdef DEBUG_LINK 1059#ifdef DEBUG_LINK
1005 printk(KERN_DEBUG "fr_stop\n"); 1060 printk(KERN_DEBUG "fr_stop\n");
1006#endif 1061#endif
1007 if (hdlc->state.fr.settings.lmi != LMI_NONE) 1062 if (state(hdlc)->settings.lmi != LMI_NONE)
1008 del_timer_sync(&hdlc->state.fr.timer); 1063 del_timer_sync(&state(hdlc)->timer);
1009 fr_set_link_state(0, dev); 1064 fr_set_link_state(0, dev);
1010} 1065}
1011 1066
1012 1067
1013
1014static void fr_close(struct net_device *dev) 1068static void fr_close(struct net_device *dev)
1015{ 1069{
1016 hdlc_device *hdlc = dev_to_hdlc(dev); 1070 hdlc_device *hdlc = dev_to_hdlc(dev);
1017 pvc_device *pvc = hdlc->state.fr.first_pvc; 1071 pvc_device *pvc = state(hdlc)->first_pvc;
1018 1072
1019 while (pvc) { /* Shutdown all PVCs for this FRAD */ 1073 while (pvc) { /* Shutdown all PVCs for this FRAD */
1020 if (pvc->main) 1074 if (pvc->main)
@@ -1025,7 +1079,8 @@ static void fr_close(struct net_device *dev)
1025 } 1079 }
1026} 1080}
1027 1081
1028static void dlci_setup(struct net_device *dev) 1082
1083static void pvc_setup(struct net_device *dev)
1029{ 1084{
1030 dev->type = ARPHRD_DLCI; 1085 dev->type = ARPHRD_DLCI;
1031 dev->flags = IFF_POINTOPOINT; 1086 dev->flags = IFF_POINTOPOINT;
@@ -1033,9 +1088,9 @@ static void dlci_setup(struct net_device *dev)
1033 dev->addr_len = 2; 1088 dev->addr_len = 2;
1034} 1089}
1035 1090
1036static int fr_add_pvc(struct net_device *master, unsigned int dlci, int type) 1091static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type)
1037{ 1092{
1038 hdlc_device *hdlc = dev_to_hdlc(master); 1093 hdlc_device *hdlc = dev_to_hdlc(frad);
1039 pvc_device *pvc = NULL; 1094 pvc_device *pvc = NULL;
1040 struct net_device *dev; 1095 struct net_device *dev;
1041 int result, used; 1096 int result, used;
@@ -1044,9 +1099,9 @@ static int fr_add_pvc(struct net_device *master, unsigned int dlci, int type)
1044 if (type == ARPHRD_ETHER) 1099 if (type == ARPHRD_ETHER)
1045 prefix = "pvceth%d"; 1100 prefix = "pvceth%d";
1046 1101
1047 if ((pvc = add_pvc(master, dlci)) == NULL) { 1102 if ((pvc = add_pvc(frad, dlci)) == NULL) {
1048 printk(KERN_WARNING "%s: Memory squeeze on fr_add_pvc()\n", 1103 printk(KERN_WARNING "%s: Memory squeeze on fr_add_pvc()\n",
1049 master->name); 1104 frad->name);
1050 return -ENOBUFS; 1105 return -ENOBUFS;
1051 } 1106 }
1052 1107
@@ -1060,11 +1115,11 @@ static int fr_add_pvc(struct net_device *master, unsigned int dlci, int type)
1060 "pvceth%d", ether_setup); 1115 "pvceth%d", ether_setup);
1061 else 1116 else
1062 dev = alloc_netdev(sizeof(struct net_device_stats), 1117 dev = alloc_netdev(sizeof(struct net_device_stats),
1063 "pvc%d", dlci_setup); 1118 "pvc%d", pvc_setup);
1064 1119
1065 if (!dev) { 1120 if (!dev) {
1066 printk(KERN_WARNING "%s: Memory squeeze on fr_pvc()\n", 1121 printk(KERN_WARNING "%s: Memory squeeze on fr_pvc()\n",
1067 master->name); 1122 frad->name);
1068 delete_unused_pvcs(hdlc); 1123 delete_unused_pvcs(hdlc);
1069 return -ENOBUFS; 1124 return -ENOBUFS;
1070 } 1125 }
@@ -1102,8 +1157,8 @@ static int fr_add_pvc(struct net_device *master, unsigned int dlci, int type)
1102 dev->destructor = free_netdev; 1157 dev->destructor = free_netdev;
1103 *get_dev_p(pvc, type) = dev; 1158 *get_dev_p(pvc, type) = dev;
1104 if (!used) { 1159 if (!used) {
1105 hdlc->state.fr.dce_changed = 1; 1160 state(hdlc)->dce_changed = 1;
1106 hdlc->state.fr.dce_pvc_count++; 1161 state(hdlc)->dce_pvc_count++;
1107 } 1162 }
1108 return 0; 1163 return 0;
1109} 1164}
@@ -1128,8 +1183,8 @@ static int fr_del_pvc(hdlc_device *hdlc, unsigned int dlci, int type)
1128 *get_dev_p(pvc, type) = NULL; 1183 *get_dev_p(pvc, type) = NULL;
1129 1184
1130 if (!pvc_is_used(pvc)) { 1185 if (!pvc_is_used(pvc)) {
1131 hdlc->state.fr.dce_pvc_count--; 1186 state(hdlc)->dce_pvc_count--;
1132 hdlc->state.fr.dce_changed = 1; 1187 state(hdlc)->dce_changed = 1;
1133 } 1188 }
1134 delete_unused_pvcs(hdlc); 1189 delete_unused_pvcs(hdlc);
1135 return 0; 1190 return 0;
@@ -1137,14 +1192,13 @@ static int fr_del_pvc(hdlc_device *hdlc, unsigned int dlci, int type)
1137 1192
1138 1193
1139 1194
1140static void fr_destroy(hdlc_device *hdlc) 1195static void fr_destroy(struct net_device *frad)
1141{ 1196{
1142 pvc_device *pvc; 1197 hdlc_device *hdlc = dev_to_hdlc(frad);
1143 1198 pvc_device *pvc = state(hdlc)->first_pvc;
1144 pvc = hdlc->state.fr.first_pvc; 1199 state(hdlc)->first_pvc = NULL; /* All PVCs destroyed */
1145 hdlc->state.fr.first_pvc = NULL; /* All PVCs destroyed */ 1200 state(hdlc)->dce_pvc_count = 0;
1146 hdlc->state.fr.dce_pvc_count = 0; 1201 state(hdlc)->dce_changed = 1;
1147 hdlc->state.fr.dce_changed = 1;
1148 1202
1149 while (pvc) { 1203 while (pvc) {
1150 pvc_device *next = pvc->next; 1204 pvc_device *next = pvc->next;
@@ -1161,8 +1215,17 @@ static void fr_destroy(hdlc_device *hdlc)
1161} 1215}
1162 1216
1163 1217
1218static struct hdlc_proto proto = {
1219 .close = fr_close,
1220 .start = fr_start,
1221 .stop = fr_stop,
1222 .detach = fr_destroy,
1223 .ioctl = fr_ioctl,
1224 .module = THIS_MODULE,
1225};
1226
1164 1227
1165int hdlc_fr_ioctl(struct net_device *dev, struct ifreq *ifr) 1228static int fr_ioctl(struct net_device *dev, struct ifreq *ifr)
1166{ 1229{
1167 fr_proto __user *fr_s = ifr->ifr_settings.ifs_ifsu.fr; 1230 fr_proto __user *fr_s = ifr->ifr_settings.ifs_ifsu.fr;
1168 const size_t size = sizeof(fr_proto); 1231 const size_t size = sizeof(fr_proto);
@@ -1173,12 +1236,14 @@ int hdlc_fr_ioctl(struct net_device *dev, struct ifreq *ifr)
1173 1236
1174 switch (ifr->ifr_settings.type) { 1237 switch (ifr->ifr_settings.type) {
1175 case IF_GET_PROTO: 1238 case IF_GET_PROTO:
1239 if (dev_to_hdlc(dev)->proto != &proto) /* Different proto */
1240 return -EINVAL;
1176 ifr->ifr_settings.type = IF_PROTO_FR; 1241 ifr->ifr_settings.type = IF_PROTO_FR;
1177 if (ifr->ifr_settings.size < size) { 1242 if (ifr->ifr_settings.size < size) {
1178 ifr->ifr_settings.size = size; /* data size wanted */ 1243 ifr->ifr_settings.size = size; /* data size wanted */
1179 return -ENOBUFS; 1244 return -ENOBUFS;
1180 } 1245 }
1181 if (copy_to_user(fr_s, &hdlc->state.fr.settings, size)) 1246 if (copy_to_user(fr_s, &state(hdlc)->settings, size))
1182 return -EFAULT; 1247 return -EFAULT;
1183 return 0; 1248 return 0;
1184 1249
@@ -1213,20 +1278,16 @@ int hdlc_fr_ioctl(struct net_device *dev, struct ifreq *ifr)
1213 if (result) 1278 if (result)
1214 return result; 1279 return result;
1215 1280
1216 if (hdlc->proto.id != IF_PROTO_FR) { 1281 if (dev_to_hdlc(dev)->proto != &proto) { /* Different proto */
1217 hdlc_proto_detach(hdlc); 1282 result = attach_hdlc_protocol(dev, &proto, fr_rx,
1218 hdlc->state.fr.first_pvc = NULL; 1283 sizeof(struct frad_state));
1219 hdlc->state.fr.dce_pvc_count = 0; 1284 if (result)
1285 return result;
1286 state(hdlc)->first_pvc = NULL;
1287 state(hdlc)->dce_pvc_count = 0;
1220 } 1288 }
1221 memcpy(&hdlc->state.fr.settings, &new_settings, size); 1289 memcpy(&state(hdlc)->settings, &new_settings, size);
1222 memset(&hdlc->proto, 0, sizeof(hdlc->proto)); 1290
1223
1224 hdlc->proto.close = fr_close;
1225 hdlc->proto.start = fr_start;
1226 hdlc->proto.stop = fr_stop;
1227 hdlc->proto.detach = fr_destroy;
1228 hdlc->proto.netif_rx = fr_rx;
1229 hdlc->proto.id = IF_PROTO_FR;
1230 dev->hard_start_xmit = hdlc->xmit; 1291 dev->hard_start_xmit = hdlc->xmit;
1231 dev->hard_header = NULL; 1292 dev->hard_header = NULL;
1232 dev->type = ARPHRD_FRAD; 1293 dev->type = ARPHRD_FRAD;
@@ -1238,6 +1299,9 @@ int hdlc_fr_ioctl(struct net_device *dev, struct ifreq *ifr)
1238 case IF_PROTO_FR_DEL_PVC: 1299 case IF_PROTO_FR_DEL_PVC:
1239 case IF_PROTO_FR_ADD_ETH_PVC: 1300 case IF_PROTO_FR_ADD_ETH_PVC:
1240 case IF_PROTO_FR_DEL_ETH_PVC: 1301 case IF_PROTO_FR_DEL_ETH_PVC:
1302 if (dev_to_hdlc(dev)->proto != &proto) /* Different proto */
1303 return -EINVAL;
1304
1241 if(!capable(CAP_NET_ADMIN)) 1305 if(!capable(CAP_NET_ADMIN))
1242 return -EPERM; 1306 return -EPERM;
1243 1307
@@ -1263,3 +1327,24 @@ int hdlc_fr_ioctl(struct net_device *dev, struct ifreq *ifr)
1263 1327
1264 return -EINVAL; 1328 return -EINVAL;
1265} 1329}
1330
1331
1332static int __init mod_init(void)
1333{
1334 register_hdlc_protocol(&proto);
1335 return 0;
1336}
1337
1338
1339static void __exit mod_exit(void)
1340{
1341 unregister_hdlc_protocol(&proto);
1342}
1343
1344
1345module_init(mod_init);
1346module_exit(mod_exit);
1347
1348MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
1349MODULE_DESCRIPTION("Frame-Relay protocol support for generic HDLC");
1350MODULE_LICENSE("GPL v2");
diff --git a/drivers/net/wan/hdlc_ppp.c b/drivers/net/wan/hdlc_ppp.c
index fbaab5bf71eb..e9f717070fde 100644
--- a/drivers/net/wan/hdlc_ppp.c
+++ b/drivers/net/wan/hdlc_ppp.c
@@ -2,7 +2,7 @@
2 * Generic HDLC support routines for Linux 2 * Generic HDLC support routines for Linux
3 * Point-to-point protocol support 3 * Point-to-point protocol support
4 * 4 *
5 * Copyright (C) 1999 - 2003 Krzysztof Halasa <khc@pm.waw.pl> 5 * Copyright (C) 1999 - 2006 Krzysztof Halasa <khc@pm.waw.pl>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify it 7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License 8 * under the terms of version 2 of the GNU General Public License
@@ -22,6 +22,21 @@
22#include <linux/lapb.h> 22#include <linux/lapb.h>
23#include <linux/rtnetlink.h> 23#include <linux/rtnetlink.h>
24#include <linux/hdlc.h> 24#include <linux/hdlc.h>
25#include <net/syncppp.h>
26
27struct ppp_state {
28 struct ppp_device pppdev;
29 struct ppp_device *syncppp_ptr;
30 int (*old_change_mtu)(struct net_device *dev, int new_mtu);
31};
32
33static int ppp_ioctl(struct net_device *dev, struct ifreq *ifr);
34
35
36static inline struct ppp_state* state(hdlc_device *hdlc)
37{
38 return(struct ppp_state *)(hdlc->state);
39}
25 40
26 41
27static int ppp_open(struct net_device *dev) 42static int ppp_open(struct net_device *dev)
@@ -30,16 +45,16 @@ static int ppp_open(struct net_device *dev)
30 void *old_ioctl; 45 void *old_ioctl;
31 int result; 46 int result;
32 47
33 dev->priv = &hdlc->state.ppp.syncppp_ptr; 48 dev->priv = &state(hdlc)->syncppp_ptr;
34 hdlc->state.ppp.syncppp_ptr = &hdlc->state.ppp.pppdev; 49 state(hdlc)->syncppp_ptr = &state(hdlc)->pppdev;
35 hdlc->state.ppp.pppdev.dev = dev; 50 state(hdlc)->pppdev.dev = dev;
36 51
37 old_ioctl = dev->do_ioctl; 52 old_ioctl = dev->do_ioctl;
38 hdlc->state.ppp.old_change_mtu = dev->change_mtu; 53 state(hdlc)->old_change_mtu = dev->change_mtu;
39 sppp_attach(&hdlc->state.ppp.pppdev); 54 sppp_attach(&state(hdlc)->pppdev);
40 /* sppp_attach nukes them. We don't need syncppp's ioctl */ 55 /* sppp_attach nukes them. We don't need syncppp's ioctl */
41 dev->do_ioctl = old_ioctl; 56 dev->do_ioctl = old_ioctl;
42 hdlc->state.ppp.pppdev.sppp.pp_flags &= ~PP_CISCO; 57 state(hdlc)->pppdev.sppp.pp_flags &= ~PP_CISCO;
43 dev->type = ARPHRD_PPP; 58 dev->type = ARPHRD_PPP;
44 result = sppp_open(dev); 59 result = sppp_open(dev);
45 if (result) { 60 if (result) {
@@ -59,7 +74,7 @@ static void ppp_close(struct net_device *dev)
59 sppp_close(dev); 74 sppp_close(dev);
60 sppp_detach(dev); 75 sppp_detach(dev);
61 dev->rebuild_header = NULL; 76 dev->rebuild_header = NULL;
62 dev->change_mtu = hdlc->state.ppp.old_change_mtu; 77 dev->change_mtu = state(hdlc)->old_change_mtu;
63 dev->mtu = HDLC_MAX_MTU; 78 dev->mtu = HDLC_MAX_MTU;
64 dev->hard_header_len = 16; 79 dev->hard_header_len = 16;
65} 80}
@@ -73,13 +88,24 @@ static __be16 ppp_type_trans(struct sk_buff *skb, struct net_device *dev)
73 88
74 89
75 90
76int hdlc_ppp_ioctl(struct net_device *dev, struct ifreq *ifr) 91static struct hdlc_proto proto = {
92 .open = ppp_open,
93 .close = ppp_close,
94 .type_trans = ppp_type_trans,
95 .ioctl = ppp_ioctl,
96 .module = THIS_MODULE,
97};
98
99
100static int ppp_ioctl(struct net_device *dev, struct ifreq *ifr)
77{ 101{
78 hdlc_device *hdlc = dev_to_hdlc(dev); 102 hdlc_device *hdlc = dev_to_hdlc(dev);
79 int result; 103 int result;
80 104
81 switch (ifr->ifr_settings.type) { 105 switch (ifr->ifr_settings.type) {
82 case IF_GET_PROTO: 106 case IF_GET_PROTO:
107 if (dev_to_hdlc(dev)->proto != &proto)
108 return -EINVAL;
83 ifr->ifr_settings.type = IF_PROTO_PPP; 109 ifr->ifr_settings.type = IF_PROTO_PPP;
84 return 0; /* return protocol only, no settable parameters */ 110 return 0; /* return protocol only, no settable parameters */
85 111
@@ -96,13 +122,10 @@ int hdlc_ppp_ioctl(struct net_device *dev, struct ifreq *ifr)
96 if (result) 122 if (result)
97 return result; 123 return result;
98 124
99 hdlc_proto_detach(hdlc); 125 result = attach_hdlc_protocol(dev, &proto, NULL,
100 memset(&hdlc->proto, 0, sizeof(hdlc->proto)); 126 sizeof(struct ppp_state));
101 127 if (result)
102 hdlc->proto.open = ppp_open; 128 return result;
103 hdlc->proto.close = ppp_close;
104 hdlc->proto.type_trans = ppp_type_trans;
105 hdlc->proto.id = IF_PROTO_PPP;
106 dev->hard_start_xmit = hdlc->xmit; 129 dev->hard_start_xmit = hdlc->xmit;
107 dev->hard_header = NULL; 130 dev->hard_header = NULL;
108 dev->type = ARPHRD_PPP; 131 dev->type = ARPHRD_PPP;
@@ -113,3 +136,25 @@ int hdlc_ppp_ioctl(struct net_device *dev, struct ifreq *ifr)
113 136
114 return -EINVAL; 137 return -EINVAL;
115} 138}
139
140
141static int __init mod_init(void)
142{
143 register_hdlc_protocol(&proto);
144 return 0;
145}
146
147
148
149static void __exit mod_exit(void)
150{
151 unregister_hdlc_protocol(&proto);
152}
153
154
155module_init(mod_init);
156module_exit(mod_exit);
157
158MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
159MODULE_DESCRIPTION("PPP protocol support for generic HDLC");
160MODULE_LICENSE("GPL v2");
diff --git a/drivers/net/wan/hdlc_raw.c b/drivers/net/wan/hdlc_raw.c
index f15aa6ba77f1..fe3cae5c6b9d 100644
--- a/drivers/net/wan/hdlc_raw.c
+++ b/drivers/net/wan/hdlc_raw.c
@@ -2,7 +2,7 @@
2 * Generic HDLC support routines for Linux 2 * Generic HDLC support routines for Linux
3 * HDLC support 3 * HDLC support
4 * 4 *
5 * Copyright (C) 1999 - 2003 Krzysztof Halasa <khc@pm.waw.pl> 5 * Copyright (C) 1999 - 2006 Krzysztof Halasa <khc@pm.waw.pl>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify it 7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License 8 * under the terms of version 2 of the GNU General Public License
@@ -24,6 +24,8 @@
24#include <linux/hdlc.h> 24#include <linux/hdlc.h>
25 25
26 26
27static int raw_ioctl(struct net_device *dev, struct ifreq *ifr);
28
27static __be16 raw_type_trans(struct sk_buff *skb, struct net_device *dev) 29static __be16 raw_type_trans(struct sk_buff *skb, struct net_device *dev)
28{ 30{
29 return __constant_htons(ETH_P_IP); 31 return __constant_htons(ETH_P_IP);
@@ -31,7 +33,14 @@ static __be16 raw_type_trans(struct sk_buff *skb, struct net_device *dev)
31 33
32 34
33 35
34int hdlc_raw_ioctl(struct net_device *dev, struct ifreq *ifr) 36static struct hdlc_proto proto = {
37 .type_trans = raw_type_trans,
38 .ioctl = raw_ioctl,
39 .module = THIS_MODULE,
40};
41
42
43static int raw_ioctl(struct net_device *dev, struct ifreq *ifr)
35{ 44{
36 raw_hdlc_proto __user *raw_s = ifr->ifr_settings.ifs_ifsu.raw_hdlc; 45 raw_hdlc_proto __user *raw_s = ifr->ifr_settings.ifs_ifsu.raw_hdlc;
37 const size_t size = sizeof(raw_hdlc_proto); 46 const size_t size = sizeof(raw_hdlc_proto);
@@ -41,12 +50,14 @@ int hdlc_raw_ioctl(struct net_device *dev, struct ifreq *ifr)
41 50
42 switch (ifr->ifr_settings.type) { 51 switch (ifr->ifr_settings.type) {
43 case IF_GET_PROTO: 52 case IF_GET_PROTO:
53 if (dev_to_hdlc(dev)->proto != &proto)
54 return -EINVAL;
44 ifr->ifr_settings.type = IF_PROTO_HDLC; 55 ifr->ifr_settings.type = IF_PROTO_HDLC;
45 if (ifr->ifr_settings.size < size) { 56 if (ifr->ifr_settings.size < size) {
46 ifr->ifr_settings.size = size; /* data size wanted */ 57 ifr->ifr_settings.size = size; /* data size wanted */
47 return -ENOBUFS; 58 return -ENOBUFS;
48 } 59 }
49 if (copy_to_user(raw_s, &hdlc->state.raw_hdlc.settings, size)) 60 if (copy_to_user(raw_s, hdlc->state, size))
50 return -EFAULT; 61 return -EFAULT;
51 return 0; 62 return 0;
52 63
@@ -71,12 +82,11 @@ int hdlc_raw_ioctl(struct net_device *dev, struct ifreq *ifr)
71 if (result) 82 if (result)
72 return result; 83 return result;
73 84
74 hdlc_proto_detach(hdlc); 85 result = attach_hdlc_protocol(dev, &proto, NULL,
75 memcpy(&hdlc->state.raw_hdlc.settings, &new_settings, size); 86 sizeof(raw_hdlc_proto));
76 memset(&hdlc->proto, 0, sizeof(hdlc->proto)); 87 if (result)
77 88 return result;
78 hdlc->proto.type_trans = raw_type_trans; 89 memcpy(hdlc->state, &new_settings, size);
79 hdlc->proto.id = IF_PROTO_HDLC;
80 dev->hard_start_xmit = hdlc->xmit; 90 dev->hard_start_xmit = hdlc->xmit;
81 dev->hard_header = NULL; 91 dev->hard_header = NULL;
82 dev->type = ARPHRD_RAWHDLC; 92 dev->type = ARPHRD_RAWHDLC;
@@ -88,3 +98,25 @@ int hdlc_raw_ioctl(struct net_device *dev, struct ifreq *ifr)
88 98
89 return -EINVAL; 99 return -EINVAL;
90} 100}
101
102
103static int __init mod_init(void)
104{
105 register_hdlc_protocol(&proto);
106 return 0;
107}
108
109
110
111static void __exit mod_exit(void)
112{
113 unregister_hdlc_protocol(&proto);
114}
115
116
117module_init(mod_init);
118module_exit(mod_exit);
119
120MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
121MODULE_DESCRIPTION("Raw HDLC protocol support for generic HDLC");
122MODULE_LICENSE("GPL v2");
diff --git a/drivers/net/wan/hdlc_raw_eth.c b/drivers/net/wan/hdlc_raw_eth.c
index d1884987f94e..1a69a9aaa9b9 100644
--- a/drivers/net/wan/hdlc_raw_eth.c
+++ b/drivers/net/wan/hdlc_raw_eth.c
@@ -2,7 +2,7 @@
2 * Generic HDLC support routines for Linux 2 * Generic HDLC support routines for Linux
3 * HDLC Ethernet emulation support 3 * HDLC Ethernet emulation support
4 * 4 *
5 * Copyright (C) 2002-2003 Krzysztof Halasa <khc@pm.waw.pl> 5 * Copyright (C) 2002-2006 Krzysztof Halasa <khc@pm.waw.pl>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify it 7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License 8 * under the terms of version 2 of the GNU General Public License
@@ -25,6 +25,7 @@
25#include <linux/etherdevice.h> 25#include <linux/etherdevice.h>
26#include <linux/hdlc.h> 26#include <linux/hdlc.h>
27 27
28static int raw_eth_ioctl(struct net_device *dev, struct ifreq *ifr);
28 29
29static int eth_tx(struct sk_buff *skb, struct net_device *dev) 30static int eth_tx(struct sk_buff *skb, struct net_device *dev)
30{ 31{
@@ -44,7 +45,14 @@ static int eth_tx(struct sk_buff *skb, struct net_device *dev)
44} 45}
45 46
46 47
47int hdlc_raw_eth_ioctl(struct net_device *dev, struct ifreq *ifr) 48static struct hdlc_proto proto = {
49 .type_trans = eth_type_trans,
50 .ioctl = raw_eth_ioctl,
51 .module = THIS_MODULE,
52};
53
54
55static int raw_eth_ioctl(struct net_device *dev, struct ifreq *ifr)
48{ 56{
49 raw_hdlc_proto __user *raw_s = ifr->ifr_settings.ifs_ifsu.raw_hdlc; 57 raw_hdlc_proto __user *raw_s = ifr->ifr_settings.ifs_ifsu.raw_hdlc;
50 const size_t size = sizeof(raw_hdlc_proto); 58 const size_t size = sizeof(raw_hdlc_proto);
@@ -56,12 +64,14 @@ int hdlc_raw_eth_ioctl(struct net_device *dev, struct ifreq *ifr)
56 64
57 switch (ifr->ifr_settings.type) { 65 switch (ifr->ifr_settings.type) {
58 case IF_GET_PROTO: 66 case IF_GET_PROTO:
67 if (dev_to_hdlc(dev)->proto != &proto)
68 return -EINVAL;
59 ifr->ifr_settings.type = IF_PROTO_HDLC_ETH; 69 ifr->ifr_settings.type = IF_PROTO_HDLC_ETH;
60 if (ifr->ifr_settings.size < size) { 70 if (ifr->ifr_settings.size < size) {
61 ifr->ifr_settings.size = size; /* data size wanted */ 71 ifr->ifr_settings.size = size; /* data size wanted */
62 return -ENOBUFS; 72 return -ENOBUFS;
63 } 73 }
64 if (copy_to_user(raw_s, &hdlc->state.raw_hdlc.settings, size)) 74 if (copy_to_user(raw_s, hdlc->state, size))
65 return -EFAULT; 75 return -EFAULT;
66 return 0; 76 return 0;
67 77
@@ -86,12 +96,11 @@ int hdlc_raw_eth_ioctl(struct net_device *dev, struct ifreq *ifr)
86 if (result) 96 if (result)
87 return result; 97 return result;
88 98
89 hdlc_proto_detach(hdlc); 99 result = attach_hdlc_protocol(dev, &proto, NULL,
90 memcpy(&hdlc->state.raw_hdlc.settings, &new_settings, size); 100 sizeof(raw_hdlc_proto));
91 memset(&hdlc->proto, 0, sizeof(hdlc->proto)); 101 if (result)
92 102 return result;
93 hdlc->proto.type_trans = eth_type_trans; 103 memcpy(hdlc->state, &new_settings, size);
94 hdlc->proto.id = IF_PROTO_HDLC_ETH;
95 dev->hard_start_xmit = eth_tx; 104 dev->hard_start_xmit = eth_tx;
96 old_ch_mtu = dev->change_mtu; 105 old_ch_mtu = dev->change_mtu;
97 old_qlen = dev->tx_queue_len; 106 old_qlen = dev->tx_queue_len;
@@ -106,3 +115,25 @@ int hdlc_raw_eth_ioctl(struct net_device *dev, struct ifreq *ifr)
106 115
107 return -EINVAL; 116 return -EINVAL;
108} 117}
118
119
120static int __init mod_init(void)
121{
122 register_hdlc_protocol(&proto);
123 return 0;
124}
125
126
127
128static void __exit mod_exit(void)
129{
130 unregister_hdlc_protocol(&proto);
131}
132
133
134module_init(mod_init);
135module_exit(mod_exit);
136
137MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
138MODULE_DESCRIPTION("Ethernet encapsulation support for generic HDLC");
139MODULE_LICENSE("GPL v2");
diff --git a/drivers/net/wan/hdlc_x25.c b/drivers/net/wan/hdlc_x25.c
index a867fb411f89..e4bb9f8ad433 100644
--- a/drivers/net/wan/hdlc_x25.c
+++ b/drivers/net/wan/hdlc_x25.c
@@ -2,7 +2,7 @@
2 * Generic HDLC support routines for Linux 2 * Generic HDLC support routines for Linux
3 * X.25 support 3 * X.25 support
4 * 4 *
5 * Copyright (C) 1999 - 2003 Krzysztof Halasa <khc@pm.waw.pl> 5 * Copyright (C) 1999 - 2006 Krzysztof Halasa <khc@pm.waw.pl>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify it 7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License 8 * under the terms of version 2 of the GNU General Public License
@@ -25,6 +25,8 @@
25 25
26#include <net/x25device.h> 26#include <net/x25device.h>
27 27
28static int x25_ioctl(struct net_device *dev, struct ifreq *ifr);
29
28/* These functions are callbacks called by LAPB layer */ 30/* These functions are callbacks called by LAPB layer */
29 31
30static void x25_connect_disconnect(struct net_device *dev, int reason, int code) 32static void x25_connect_disconnect(struct net_device *dev, int reason, int code)
@@ -162,30 +164,39 @@ static void x25_close(struct net_device *dev)
162 164
163static int x25_rx(struct sk_buff *skb) 165static int x25_rx(struct sk_buff *skb)
164{ 166{
165 hdlc_device *hdlc = dev_to_hdlc(skb->dev); 167 struct hdlc_device_desc *desc = dev_to_desc(skb->dev);
166 168
167 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) { 169 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {
168 hdlc->stats.rx_dropped++; 170 desc->stats.rx_dropped++;
169 return NET_RX_DROP; 171 return NET_RX_DROP;
170 } 172 }
171 173
172 if (lapb_data_received(skb->dev, skb) == LAPB_OK) 174 if (lapb_data_received(skb->dev, skb) == LAPB_OK)
173 return NET_RX_SUCCESS; 175 return NET_RX_SUCCESS;
174 176
175 hdlc->stats.rx_errors++; 177 desc->stats.rx_errors++;
176 dev_kfree_skb_any(skb); 178 dev_kfree_skb_any(skb);
177 return NET_RX_DROP; 179 return NET_RX_DROP;
178} 180}
179 181
180 182
183static struct hdlc_proto proto = {
184 .open = x25_open,
185 .close = x25_close,
186 .ioctl = x25_ioctl,
187 .module = THIS_MODULE,
188};
189
181 190
182int hdlc_x25_ioctl(struct net_device *dev, struct ifreq *ifr) 191static int x25_ioctl(struct net_device *dev, struct ifreq *ifr)
183{ 192{
184 hdlc_device *hdlc = dev_to_hdlc(dev); 193 hdlc_device *hdlc = dev_to_hdlc(dev);
185 int result; 194 int result;
186 195
187 switch (ifr->ifr_settings.type) { 196 switch (ifr->ifr_settings.type) {
188 case IF_GET_PROTO: 197 case IF_GET_PROTO:
198 if (dev_to_hdlc(dev)->proto != &proto)
199 return -EINVAL;
189 ifr->ifr_settings.type = IF_PROTO_X25; 200 ifr->ifr_settings.type = IF_PROTO_X25;
190 return 0; /* return protocol only, no settable parameters */ 201 return 0; /* return protocol only, no settable parameters */
191 202
@@ -200,14 +211,9 @@ int hdlc_x25_ioctl(struct net_device *dev, struct ifreq *ifr)
200 if (result) 211 if (result)
201 return result; 212 return result;
202 213
203 hdlc_proto_detach(hdlc); 214 if ((result = attach_hdlc_protocol(dev, &proto,
204 memset(&hdlc->proto, 0, sizeof(hdlc->proto)); 215 x25_rx, 0)) != 0)
205 216 return result;
206 hdlc->proto.open = x25_open;
207 hdlc->proto.close = x25_close;
208 hdlc->proto.netif_rx = x25_rx;
209 hdlc->proto.type_trans = NULL;
210 hdlc->proto.id = IF_PROTO_X25;
211 dev->hard_start_xmit = x25_xmit; 217 dev->hard_start_xmit = x25_xmit;
212 dev->hard_header = NULL; 218 dev->hard_header = NULL;
213 dev->type = ARPHRD_X25; 219 dev->type = ARPHRD_X25;
@@ -218,3 +224,25 @@ int hdlc_x25_ioctl(struct net_device *dev, struct ifreq *ifr)
218 224
219 return -EINVAL; 225 return -EINVAL;
220} 226}
227
228
229static int __init mod_init(void)
230{
231 register_hdlc_protocol(&proto);
232 return 0;
233}
234
235
236
237static void __exit mod_exit(void)
238{
239 unregister_hdlc_protocol(&proto);
240}
241
242
243module_init(mod_init);
244module_exit(mod_exit);
245
246MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
247MODULE_DESCRIPTION("X.25 protocol support for generic HDLC");
248MODULE_LICENSE("GPL v2");
diff --git a/drivers/net/wan/pc300.h b/drivers/net/wan/pc300.h
index 2024b26b99e6..63e9fcf31fb8 100644
--- a/drivers/net/wan/pc300.h
+++ b/drivers/net/wan/pc300.h
@@ -100,6 +100,7 @@
100#define _PC300_H 100#define _PC300_H
101 101
102#include <linux/hdlc.h> 102#include <linux/hdlc.h>
103#include <net/syncppp.h>
103#include "hd64572.h" 104#include "hd64572.h"
104#include "pc300-falc-lh.h" 105#include "pc300-falc-lh.h"
105 106
diff --git a/drivers/net/wan/pc300_drv.c b/drivers/net/wan/pc300_drv.c
index 56e69403d178..8d9b959bf15b 100644
--- a/drivers/net/wan/pc300_drv.c
+++ b/drivers/net/wan/pc300_drv.c
@@ -2016,7 +2016,6 @@ static void sca_intr(pc300_t * card)
2016 pc300ch_t *chan = &card->chan[ch]; 2016 pc300ch_t *chan = &card->chan[ch];
2017 pc300dev_t *d = &chan->d; 2017 pc300dev_t *d = &chan->d;
2018 struct net_device *dev = d->dev; 2018 struct net_device *dev = d->dev;
2019 hdlc_device *hdlc = dev_to_hdlc(dev);
2020 2019
2021 spin_lock(&card->card_lock); 2020 spin_lock(&card->card_lock);
2022 2021
@@ -2049,8 +2048,8 @@ static void sca_intr(pc300_t * card)
2049 } 2048 }
2050 cpc_net_rx(dev); 2049 cpc_net_rx(dev);
2051 /* Discard invalid frames */ 2050 /* Discard invalid frames */
2052 hdlc->stats.rx_errors++; 2051 hdlc_stats(dev)->rx_errors++;
2053 hdlc->stats.rx_over_errors++; 2052 hdlc_stats(dev)->rx_over_errors++;
2054 chan->rx_first_bd = 0; 2053 chan->rx_first_bd = 0;
2055 chan->rx_last_bd = N_DMA_RX_BUF - 1; 2054 chan->rx_last_bd = N_DMA_RX_BUF - 1;
2056 rx_dma_start(card, ch); 2055 rx_dma_start(card, ch);
@@ -2116,8 +2115,8 @@ static void sca_intr(pc300_t * card)
2116 card->hw.cpld_reg2) & 2115 card->hw.cpld_reg2) &
2117 ~ (CPLD_REG2_FALC_LED1 << (2 * ch))); 2116 ~ (CPLD_REG2_FALC_LED1 << (2 * ch)));
2118 } 2117 }
2119 hdlc->stats.tx_errors++; 2118 hdlc_stats(dev)->tx_errors++;
2120 hdlc->stats.tx_fifo_errors++; 2119 hdlc_stats(dev)->tx_fifo_errors++;
2121 sca_tx_intr(d); 2120 sca_tx_intr(d);
2122 } 2121 }
2123 } 2122 }
@@ -2534,7 +2533,6 @@ static int cpc_change_mtu(struct net_device *dev, int new_mtu)
2534 2533
2535static int cpc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 2534static int cpc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2536{ 2535{
2537 hdlc_device *hdlc = dev_to_hdlc(dev);
2538 pc300dev_t *d = (pc300dev_t *) dev->priv; 2536 pc300dev_t *d = (pc300dev_t *) dev->priv;
2539 pc300ch_t *chan = (pc300ch_t *) d->chan; 2537 pc300ch_t *chan = (pc300ch_t *) d->chan;
2540 pc300_t *card = (pc300_t *) chan->card; 2538 pc300_t *card = (pc300_t *) chan->card;
@@ -2552,10 +2550,10 @@ static int cpc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2552 case SIOCGPC300CONF: 2550 case SIOCGPC300CONF:
2553#ifdef CONFIG_PC300_MLPPP 2551#ifdef CONFIG_PC300_MLPPP
2554 if (conf->proto != PC300_PROTO_MLPPP) { 2552 if (conf->proto != PC300_PROTO_MLPPP) {
2555 conf->proto = hdlc->proto.id; 2553 conf->proto = /* FIXME hdlc->proto.id */ 0;
2556 } 2554 }
2557#else 2555#else
2558 conf->proto = hdlc->proto.id; 2556 conf->proto = /* FIXME hdlc->proto.id */ 0;
2559#endif 2557#endif
2560 memcpy(&conf_aux.conf, conf, sizeof(pc300chconf_t)); 2558 memcpy(&conf_aux.conf, conf, sizeof(pc300chconf_t));
2561 memcpy(&conf_aux.hw, &card->hw, sizeof(pc300hw_t)); 2559 memcpy(&conf_aux.hw, &card->hw, sizeof(pc300hw_t));
@@ -2588,12 +2586,12 @@ static int cpc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2588 } 2586 }
2589 } else { 2587 } else {
2590 memcpy(conf, &conf_aux.conf, sizeof(pc300chconf_t)); 2588 memcpy(conf, &conf_aux.conf, sizeof(pc300chconf_t));
2591 hdlc->proto.id = conf->proto; 2589 /* FIXME hdlc->proto.id = conf->proto; */
2592 } 2590 }
2593 } 2591 }
2594#else 2592#else
2595 memcpy(conf, &conf_aux.conf, sizeof(pc300chconf_t)); 2593 memcpy(conf, &conf_aux.conf, sizeof(pc300chconf_t));
2596 hdlc->proto.id = conf->proto; 2594 /* FIXME hdlc->proto.id = conf->proto; */
2597#endif 2595#endif
2598 return 0; 2596 return 0;
2599 case SIOCGPC300STATUS: 2597 case SIOCGPC300STATUS:
@@ -2606,7 +2604,7 @@ static int cpc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2606 case SIOCGPC300UTILSTATS: 2604 case SIOCGPC300UTILSTATS:
2607 { 2605 {
2608 if (!arg) { /* clear statistics */ 2606 if (!arg) { /* clear statistics */
2609 memset(&hdlc->stats, 0, sizeof(struct net_device_stats)); 2607 memset(hdlc_stats(dev), 0, sizeof(struct net_device_stats));
2610 if (card->hw.type == PC300_TE) { 2608 if (card->hw.type == PC300_TE) {
2611 memset(&chan->falc, 0, sizeof(falc_t)); 2609 memset(&chan->falc, 0, sizeof(falc_t));
2612 } 2610 }
@@ -2617,7 +2615,7 @@ static int cpc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2617 pc300stats.hw_type = card->hw.type; 2615 pc300stats.hw_type = card->hw.type;
2618 pc300stats.line_on = card->chan[ch].d.line_on; 2616 pc300stats.line_on = card->chan[ch].d.line_on;
2619 pc300stats.line_off = card->chan[ch].d.line_off; 2617 pc300stats.line_off = card->chan[ch].d.line_off;
2620 memcpy(&pc300stats.gen_stats, &hdlc->stats, 2618 memcpy(&pc300stats.gen_stats, hdlc_stats(dev),
2621 sizeof(struct net_device_stats)); 2619 sizeof(struct net_device_stats));
2622 if (card->hw.type == PC300_TE) 2620 if (card->hw.type == PC300_TE)
2623 memcpy(&pc300stats.te_stats,&chan->falc,sizeof(falc_t)); 2621 memcpy(&pc300stats.te_stats,&chan->falc,sizeof(falc_t));
@@ -3147,7 +3145,6 @@ static void cpc_closech(pc300dev_t * d)
3147 3145
3148int cpc_open(struct net_device *dev) 3146int cpc_open(struct net_device *dev)
3149{ 3147{
3150 hdlc_device *hdlc = dev_to_hdlc(dev);
3151 pc300dev_t *d = (pc300dev_t *) dev->priv; 3148 pc300dev_t *d = (pc300dev_t *) dev->priv;
3152 struct ifreq ifr; 3149 struct ifreq ifr;
3153 int result; 3150 int result;
@@ -3156,12 +3153,14 @@ int cpc_open(struct net_device *dev)
3156 printk("pc300: cpc_open"); 3153 printk("pc300: cpc_open");
3157#endif 3154#endif
3158 3155
3156#ifdef FIXME
3159 if (hdlc->proto.id == IF_PROTO_PPP) { 3157 if (hdlc->proto.id == IF_PROTO_PPP) {
3160 d->if_ptr = &hdlc->state.ppp.pppdev; 3158 d->if_ptr = &hdlc->state.ppp.pppdev;
3161 } 3159 }
3160#endif
3162 3161
3163 result = hdlc_open(dev); 3162 result = hdlc_open(dev);
3164 if (hdlc->proto.id == IF_PROTO_PPP) { 3163 if (/* FIXME hdlc->proto.id == IF_PROTO_PPP*/ 0) {
3165 dev->priv = d; 3164 dev->priv = d;
3166 } 3165 }
3167 if (result) { 3166 if (result) {
@@ -3176,7 +3175,6 @@ int cpc_open(struct net_device *dev)
3176 3175
3177static int cpc_close(struct net_device *dev) 3176static int cpc_close(struct net_device *dev)
3178{ 3177{
3179 hdlc_device *hdlc = dev_to_hdlc(dev);
3180 pc300dev_t *d = (pc300dev_t *) dev->priv; 3178 pc300dev_t *d = (pc300dev_t *) dev->priv;
3181 pc300ch_t *chan = (pc300ch_t *) d->chan; 3179 pc300ch_t *chan = (pc300ch_t *) d->chan;
3182 pc300_t *card = (pc300_t *) chan->card; 3180 pc300_t *card = (pc300_t *) chan->card;
@@ -3193,7 +3191,7 @@ static int cpc_close(struct net_device *dev)
3193 CPC_UNLOCK(card, flags); 3191 CPC_UNLOCK(card, flags);
3194 3192
3195 hdlc_close(dev); 3193 hdlc_close(dev);
3196 if (hdlc->proto.id == IF_PROTO_PPP) { 3194 if (/* FIXME hdlc->proto.id == IF_PROTO_PPP*/ 0) {
3197 d->if_ptr = NULL; 3195 d->if_ptr = NULL;
3198 } 3196 }
3199#ifdef CONFIG_PC300_MLPPP 3197#ifdef CONFIG_PC300_MLPPP
diff --git a/drivers/net/wan/syncppp.c b/drivers/net/wan/syncppp.c
index c13b459a0137..218f7b574ab3 100644
--- a/drivers/net/wan/syncppp.c
+++ b/drivers/net/wan/syncppp.c
@@ -469,7 +469,7 @@ static void sppp_lcp_input (struct sppp *sp, struct sk_buff *skb)
469 struct net_device *dev = sp->pp_if; 469 struct net_device *dev = sp->pp_if;
470 int len = skb->len; 470 int len = skb->len;
471 u8 *p, opt[6]; 471 u8 *p, opt[6];
472 u32 rmagic; 472 u32 rmagic = 0;
473 473
474 if (!pskb_may_pull(skb, sizeof(struct lcp_header))) { 474 if (!pskb_may_pull(skb, sizeof(struct lcp_header))) {
475 if (sp->pp_flags & PP_DEBUG) 475 if (sp->pp_flags & PP_DEBUG)
@@ -763,7 +763,7 @@ static void sppp_cisco_input (struct sppp *sp, struct sk_buff *skb)
763 { 763 {
764 struct in_device *in_dev; 764 struct in_device *in_dev;
765 struct in_ifaddr *ifa; 765 struct in_ifaddr *ifa;
766 u32 addr = 0, mask = ~0; /* FIXME: is the mask correct? */ 766 __be32 addr = 0, mask = ~0; /* FIXME: is the mask correct? */
767#ifdef CONFIG_INET 767#ifdef CONFIG_INET
768 rcu_read_lock(); 768 rcu_read_lock();
769 if ((in_dev = __in_dev_get_rcu(dev)) != NULL) 769 if ((in_dev = __in_dev_get_rcu(dev)) != NULL)
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index bff04cba3fed..39d09345027c 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -5659,25 +5659,40 @@ static int airo_pci_resume(struct pci_dev *pdev)
5659 5659
5660static int __init airo_init_module( void ) 5660static int __init airo_init_module( void )
5661{ 5661{
5662 int i, have_isa_dev = 0; 5662 int i;
5663#if 0
5664 int have_isa_dev = 0;
5665#endif
5663 5666
5664 airo_entry = create_proc_entry("aironet", 5667 airo_entry = create_proc_entry("aironet",
5665 S_IFDIR | airo_perm, 5668 S_IFDIR | airo_perm,
5666 proc_root_driver); 5669 proc_root_driver);
5667 airo_entry->uid = proc_uid; 5670
5668 airo_entry->gid = proc_gid; 5671 if (airo_entry) {
5672 airo_entry->uid = proc_uid;
5673 airo_entry->gid = proc_gid;
5674 }
5669 5675
5670 for( i = 0; i < 4 && io[i] && irq[i]; i++ ) { 5676 for( i = 0; i < 4 && io[i] && irq[i]; i++ ) {
5671 airo_print_info("", "Trying to configure ISA adapter at irq=%d " 5677 airo_print_info("", "Trying to configure ISA adapter at irq=%d "
5672 "io=0x%x", irq[i], io[i] ); 5678 "io=0x%x", irq[i], io[i] );
5673 if (init_airo_card( irq[i], io[i], 0, NULL )) 5679 if (init_airo_card( irq[i], io[i], 0, NULL ))
5680#if 0
5674 have_isa_dev = 1; 5681 have_isa_dev = 1;
5682#else
5683 /* do nothing */ ;
5684#endif
5675 } 5685 }
5676 5686
5677#ifdef CONFIG_PCI 5687#ifdef CONFIG_PCI
5678 airo_print_info("", "Probing for PCI adapters"); 5688 airo_print_info("", "Probing for PCI adapters");
5679 pci_register_driver(&airo_driver); 5689 i = pci_register_driver(&airo_driver);
5680 airo_print_info("", "Finished probing for PCI adapters"); 5690 airo_print_info("", "Finished probing for PCI adapters");
5691
5692 if (i) {
5693 remove_proc_entry("aironet", proc_root_driver);
5694 return i;
5695 }
5681#endif 5696#endif
5682 5697
5683 /* Always exit with success, as we are a library module 5698 /* Always exit with success, as we are a library module
@@ -5868,7 +5883,7 @@ static int airo_set_essid(struct net_device *dev,
5868 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; 5883 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
5869 5884
5870 /* Check the size of the string */ 5885 /* Check the size of the string */
5871 if(dwrq->length > IW_ESSID_MAX_SIZE+1) { 5886 if(dwrq->length > IW_ESSID_MAX_SIZE) {
5872 return -E2BIG ; 5887 return -E2BIG ;
5873 } 5888 }
5874 /* Check if index is valid */ 5889 /* Check if index is valid */
@@ -5880,7 +5895,7 @@ static int airo_set_essid(struct net_device *dev,
5880 memset(SSID_rid.ssids[index].ssid, 0, 5895 memset(SSID_rid.ssids[index].ssid, 0,
5881 sizeof(SSID_rid.ssids[index].ssid)); 5896 sizeof(SSID_rid.ssids[index].ssid));
5882 memcpy(SSID_rid.ssids[index].ssid, extra, dwrq->length); 5897 memcpy(SSID_rid.ssids[index].ssid, extra, dwrq->length);
5883 SSID_rid.ssids[index].len = dwrq->length - 1; 5898 SSID_rid.ssids[index].len = dwrq->length;
5884 } 5899 }
5885 SSID_rid.len = sizeof(SSID_rid); 5900 SSID_rid.len = sizeof(SSID_rid);
5886 /* Write it to the card */ 5901 /* Write it to the card */
@@ -5990,7 +6005,7 @@ static int airo_set_nick(struct net_device *dev,
5990 struct airo_info *local = dev->priv; 6005 struct airo_info *local = dev->priv;
5991 6006
5992 /* Check the size of the string */ 6007 /* Check the size of the string */
5993 if(dwrq->length > 16 + 1) { 6008 if(dwrq->length > 16) {
5994 return -E2BIG; 6009 return -E2BIG;
5995 } 6010 }
5996 readConfigRid(local, 1); 6011 readConfigRid(local, 1);
@@ -6015,7 +6030,7 @@ static int airo_get_nick(struct net_device *dev,
6015 readConfigRid(local, 1); 6030 readConfigRid(local, 1);
6016 strncpy(extra, local->config.nodeName, 16); 6031 strncpy(extra, local->config.nodeName, 16);
6017 extra[16] = '\0'; 6032 extra[16] = '\0';
6018 dwrq->length = strlen(extra) + 1; 6033 dwrq->length = strlen(extra);
6019 6034
6020 return 0; 6035 return 0;
6021} 6036}
@@ -6767,9 +6782,9 @@ static int airo_set_retry(struct net_device *dev,
6767 } 6782 }
6768 readConfigRid(local, 1); 6783 readConfigRid(local, 1);
6769 if(vwrq->flags & IW_RETRY_LIMIT) { 6784 if(vwrq->flags & IW_RETRY_LIMIT) {
6770 if(vwrq->flags & IW_RETRY_MAX) 6785 if(vwrq->flags & IW_RETRY_LONG)
6771 local->config.longRetryLimit = vwrq->value; 6786 local->config.longRetryLimit = vwrq->value;
6772 else if (vwrq->flags & IW_RETRY_MIN) 6787 else if (vwrq->flags & IW_RETRY_SHORT)
6773 local->config.shortRetryLimit = vwrq->value; 6788 local->config.shortRetryLimit = vwrq->value;
6774 else { 6789 else {
6775 /* No modifier : set both */ 6790 /* No modifier : set both */
@@ -6805,14 +6820,14 @@ static int airo_get_retry(struct net_device *dev,
6805 if((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { 6820 if((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
6806 vwrq->flags = IW_RETRY_LIFETIME; 6821 vwrq->flags = IW_RETRY_LIFETIME;
6807 vwrq->value = (int)local->config.txLifetime * 1024; 6822 vwrq->value = (int)local->config.txLifetime * 1024;
6808 } else if((vwrq->flags & IW_RETRY_MAX)) { 6823 } else if((vwrq->flags & IW_RETRY_LONG)) {
6809 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; 6824 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
6810 vwrq->value = (int)local->config.longRetryLimit; 6825 vwrq->value = (int)local->config.longRetryLimit;
6811 } else { 6826 } else {
6812 vwrq->flags = IW_RETRY_LIMIT; 6827 vwrq->flags = IW_RETRY_LIMIT;
6813 vwrq->value = (int)local->config.shortRetryLimit; 6828 vwrq->value = (int)local->config.shortRetryLimit;
6814 if((int)local->config.shortRetryLimit != (int)local->config.longRetryLimit) 6829 if((int)local->config.shortRetryLimit != (int)local->config.longRetryLimit)
6815 vwrq->flags |= IW_RETRY_MIN; 6830 vwrq->flags |= IW_RETRY_SHORT;
6816 } 6831 }
6817 6832
6818 return 0; 6833 return 0;
@@ -6990,6 +7005,7 @@ static int airo_set_power(struct net_device *dev,
6990 local->config.rmode |= RXMODE_BC_MC_ADDR; 7005 local->config.rmode |= RXMODE_BC_MC_ADDR;
6991 set_bit (FLAG_COMMIT, &local->flags); 7006 set_bit (FLAG_COMMIT, &local->flags);
6992 case IW_POWER_ON: 7007 case IW_POWER_ON:
7008 /* This is broken, fixme ;-) */
6993 break; 7009 break;
6994 default: 7010 default:
6995 return -EINVAL; 7011 return -EINVAL;
diff --git a/drivers/net/wireless/atmel.c b/drivers/net/wireless/atmel.c
index 995c7bea5897..0fc267d626dc 100644
--- a/drivers/net/wireless/atmel.c
+++ b/drivers/net/wireless/atmel.c
@@ -1656,13 +1656,13 @@ static int atmel_set_essid(struct net_device *dev,
1656 priv->connect_to_any_BSS = 0; 1656 priv->connect_to_any_BSS = 0;
1657 1657
1658 /* Check the size of the string */ 1658 /* Check the size of the string */
1659 if (dwrq->length > MAX_SSID_LENGTH + 1) 1659 if (dwrq->length > MAX_SSID_LENGTH)
1660 return -E2BIG; 1660 return -E2BIG;
1661 if (index != 0) 1661 if (index != 0)
1662 return -EINVAL; 1662 return -EINVAL;
1663 1663
1664 memcpy(priv->new_SSID, extra, dwrq->length - 1); 1664 memcpy(priv->new_SSID, extra, dwrq->length);
1665 priv->new_SSID_size = dwrq->length - 1; 1665 priv->new_SSID_size = dwrq->length;
1666 } 1666 }
1667 1667
1668 return -EINPROGRESS; 1668 return -EINPROGRESS;
@@ -2120,9 +2120,9 @@ static int atmel_set_retry(struct net_device *dev,
2120 struct atmel_private *priv = netdev_priv(dev); 2120 struct atmel_private *priv = netdev_priv(dev);
2121 2121
2122 if (!vwrq->disabled && (vwrq->flags & IW_RETRY_LIMIT)) { 2122 if (!vwrq->disabled && (vwrq->flags & IW_RETRY_LIMIT)) {
2123 if (vwrq->flags & IW_RETRY_MAX) 2123 if (vwrq->flags & IW_RETRY_LONG)
2124 priv->long_retry = vwrq->value; 2124 priv->long_retry = vwrq->value;
2125 else if (vwrq->flags & IW_RETRY_MIN) 2125 else if (vwrq->flags & IW_RETRY_SHORT)
2126 priv->short_retry = vwrq->value; 2126 priv->short_retry = vwrq->value;
2127 else { 2127 else {
2128 /* No modifier : set both */ 2128 /* No modifier : set both */
@@ -2144,15 +2144,15 @@ static int atmel_get_retry(struct net_device *dev,
2144 2144
2145 vwrq->disabled = 0; /* Can't be disabled */ 2145 vwrq->disabled = 0; /* Can't be disabled */
2146 2146
2147 /* Note : by default, display the min retry number */ 2147 /* Note : by default, display the short retry number */
2148 if (vwrq->flags & IW_RETRY_MAX) { 2148 if (vwrq->flags & IW_RETRY_LONG) {
2149 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; 2149 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
2150 vwrq->value = priv->long_retry; 2150 vwrq->value = priv->long_retry;
2151 } else { 2151 } else {
2152 vwrq->flags = IW_RETRY_LIMIT; 2152 vwrq->flags = IW_RETRY_LIMIT;
2153 vwrq->value = priv->short_retry; 2153 vwrq->value = priv->short_retry;
2154 if (priv->long_retry != priv->short_retry) 2154 if (priv->long_retry != priv->short_retry)
2155 vwrq->flags |= IW_RETRY_MIN; 2155 vwrq->flags |= IW_RETRY_SHORT;
2156 } 2156 }
2157 2157
2158 return 0; 2158 return 0;
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx.h b/drivers/net/wireless/bcm43xx/bcm43xx.h
index 6d4ea36bc564..d6a8bf09878e 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx.h
+++ b/drivers/net/wireless/bcm43xx/bcm43xx.h
@@ -666,7 +666,6 @@ struct bcm43xx_noise_calculation {
666}; 666};
667 667
668struct bcm43xx_stats { 668struct bcm43xx_stats {
669 u8 link_quality;
670 u8 noise; 669 u8 noise;
671 struct iw_statistics wstats; 670 struct iw_statistics wstats;
672 /* Store the last TX/RX times here for updating the leds. */ 671 /* Store the last TX/RX times here for updating the leds. */
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c b/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c
index 923275ea0789..b9df06a06ea9 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c
@@ -54,7 +54,7 @@ static ssize_t write_file_dummy(struct file *file, const char __user *buf,
54 54
55static int open_file_generic(struct inode *inode, struct file *file) 55static int open_file_generic(struct inode *inode, struct file *file)
56{ 56{
57 file->private_data = inode->u.generic_ip; 57 file->private_data = inode->i_private;
58 return 0; 58 return 0;
59} 59}
60 60
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_main.c b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
index cb9a3ae8463a..eb65db7393ba 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_main.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
@@ -2405,9 +2405,10 @@ static int bcm43xx_chip_init(struct bcm43xx_private *bcm)
2405 BCM43xx_UCODE_TIME) & 0x1f); 2405 BCM43xx_UCODE_TIME) & 0x1f);
2406 2406
2407 if ( value16 > 0x128 ) { 2407 if ( value16 > 0x128 ) {
2408 dprintk(KERN_ERR PFX 2408 printk(KERN_ERR PFX
2409 "Firmware: no support for microcode rev > 0x128\n"); 2409 "Firmware: no support for microcode extracted "
2410 err = -1; 2410 "from version 4.x binary drivers.\n");
2411 err = -EOPNOTSUPP;
2411 goto err_release_fw; 2412 goto err_release_fw;
2412 } 2413 }
2413 2414
@@ -3169,8 +3170,7 @@ static void bcm43xx_periodic_work_handler(void *d)
3169 * be preemtible. 3170 * be preemtible.
3170 */ 3171 */
3171 mutex_lock(&bcm->mutex); 3172 mutex_lock(&bcm->mutex);
3172 netif_stop_queue(bcm->net_dev); 3173 netif_tx_disable(bcm->net_dev);
3173 synchronize_net();
3174 spin_lock_irqsave(&bcm->irq_lock, flags); 3174 spin_lock_irqsave(&bcm->irq_lock, flags);
3175 bcm43xx_mac_suspend(bcm); 3175 bcm43xx_mac_suspend(bcm);
3176 if (bcm43xx_using_pio(bcm)) 3176 if (bcm43xx_using_pio(bcm))
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_phy.c b/drivers/net/wireless/bcm43xx/bcm43xx_phy.c
index eafd0f662686..52ce2a9334fb 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_phy.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_phy.c
@@ -361,7 +361,7 @@ static void bcm43xx_phy_setupg(struct bcm43xx_private *bcm)
361 if (phy->rev <= 2) 361 if (phy->rev <= 2)
362 for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++) 362 for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
363 bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg1[i]); 363 bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg1[i]);
364 else if ((phy->rev == 7) && (bcm43xx_phy_read(bcm, 0x0449) & 0x0200)) 364 else if ((phy->rev >= 7) && (bcm43xx_phy_read(bcm, 0x0449) & 0x0200))
365 for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++) 365 for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
366 bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg3[i]); 366 bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg3[i]);
367 else 367 else
@@ -371,7 +371,7 @@ static void bcm43xx_phy_setupg(struct bcm43xx_private *bcm)
371 if (phy->rev == 2) 371 if (phy->rev == 2)
372 for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++) 372 for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
373 bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr1[i]); 373 bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr1[i]);
374 else if ((phy->rev > 2) && (phy->rev <= 7)) 374 else if ((phy->rev > 2) && (phy->rev <= 8))
375 for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++) 375 for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
376 bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr2[i]); 376 bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr2[i]);
377 377
@@ -1197,7 +1197,7 @@ static void bcm43xx_phy_initg(struct bcm43xx_private *bcm)
1197 1197
1198 if (phy->rev == 1) 1198 if (phy->rev == 1)
1199 bcm43xx_phy_initb5(bcm); 1199 bcm43xx_phy_initb5(bcm);
1200 else if (phy->rev >= 2 && phy->rev <= 7) 1200 else
1201 bcm43xx_phy_initb6(bcm); 1201 bcm43xx_phy_initb6(bcm);
1202 if (phy->rev >= 2 || phy->connected) 1202 if (phy->rev >= 2 || phy->connected)
1203 bcm43xx_phy_inita(bcm); 1203 bcm43xx_phy_inita(bcm);
@@ -1241,23 +1241,22 @@ static void bcm43xx_phy_initg(struct bcm43xx_private *bcm)
1241 bcm43xx_phy_lo_g_measure(bcm); 1241 bcm43xx_phy_lo_g_measure(bcm);
1242 } else { 1242 } else {
1243 if (radio->version == 0x2050 && radio->revision == 8) { 1243 if (radio->version == 0x2050 && radio->revision == 8) {
1244 //FIXME 1244 bcm43xx_radio_write16(bcm, 0x0052,
1245 (radio->txctl1 << 4) | radio->txctl2);
1245 } else { 1246 } else {
1246 bcm43xx_radio_write16(bcm, 0x0052, 1247 bcm43xx_radio_write16(bcm, 0x0052,
1247 (bcm43xx_radio_read16(bcm, 0x0052) 1248 (bcm43xx_radio_read16(bcm, 0x0052)
1248 & 0xFFF0) | radio->txctl1); 1249 & 0xFFF0) | radio->txctl1);
1249 } 1250 }
1250 if (phy->rev >= 6) { 1251 if (phy->rev >= 6) {
1251 /*
1252 bcm43xx_phy_write(bcm, 0x0036, 1252 bcm43xx_phy_write(bcm, 0x0036,
1253 (bcm43xx_phy_read(bcm, 0x0036) 1253 (bcm43xx_phy_read(bcm, 0x0036)
1254 & 0xF000) | (FIXME << 12)); 1254 & 0xF000) | (radio->txctl2 << 12));
1255 */
1256 } 1255 }
1257 if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) 1256 if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
1258 bcm43xx_phy_write(bcm, 0x002E, 0x8075); 1257 bcm43xx_phy_write(bcm, 0x002E, 0x8075);
1259 else 1258 else
1260 bcm43xx_phy_write(bcm, 0x003E, 0x807F); 1259 bcm43xx_phy_write(bcm, 0x002E, 0x807F);
1261 if (phy->rev < 2) 1260 if (phy->rev < 2)
1262 bcm43xx_phy_write(bcm, 0x002F, 0x0101); 1261 bcm43xx_phy_write(bcm, 0x002F, 0x0101);
1263 else 1262 else
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_wx.c b/drivers/net/wireless/bcm43xx/bcm43xx_wx.c
index 888077fc14c4..9b7b15cf6561 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_wx.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_wx.c
@@ -334,7 +334,7 @@ static int bcm43xx_wx_get_nick(struct net_device *net_dev,
334 size_t len; 334 size_t len;
335 335
336 mutex_lock(&bcm->mutex); 336 mutex_lock(&bcm->mutex);
337 len = strlen(bcm->nick) + 1; 337 len = strlen(bcm->nick);
338 memcpy(extra, bcm->nick, len); 338 memcpy(extra, bcm->nick, len);
339 data->data.length = (__u16)len; 339 data->data.length = (__u16)len;
340 data->data.flags = 1; 340 data->data.flags = 1;
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_xmit.c b/drivers/net/wireless/bcm43xx/bcm43xx_xmit.c
index c0efbfe605a5..0159e4e93201 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_xmit.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_xmit.c
@@ -496,15 +496,14 @@ int bcm43xx_rx(struct bcm43xx_private *bcm,
496 stats.signal = bcm43xx_rssi_postprocess(bcm, rxhdr->rssi, is_ofdm, 496 stats.signal = bcm43xx_rssi_postprocess(bcm, rxhdr->rssi, is_ofdm,
497 !!(rxflags1 & BCM43xx_RXHDR_FLAGS1_2053RSSIADJ), 497 !!(rxflags1 & BCM43xx_RXHDR_FLAGS1_2053RSSIADJ),
498 !!(rxflags3 & BCM43xx_RXHDR_FLAGS3_2050RSSIADJ)); 498 !!(rxflags3 & BCM43xx_RXHDR_FLAGS3_2050RSSIADJ));
499//TODO stats.noise = 499 stats.noise = bcm->stats.noise;
500 if (is_ofdm) 500 if (is_ofdm)
501 stats.rate = bcm43xx_plcp_get_bitrate_ofdm(plcp); 501 stats.rate = bcm43xx_plcp_get_bitrate_ofdm(plcp);
502 else 502 else
503 stats.rate = bcm43xx_plcp_get_bitrate_cck(plcp); 503 stats.rate = bcm43xx_plcp_get_bitrate_cck(plcp);
504 stats.received_channel = radio->channel; 504 stats.received_channel = radio->channel;
505//TODO stats.control =
506 stats.mask = IEEE80211_STATMASK_SIGNAL | 505 stats.mask = IEEE80211_STATMASK_SIGNAL |
507//TODO IEEE80211_STATMASK_NOISE | 506 IEEE80211_STATMASK_NOISE |
508 IEEE80211_STATMASK_RATE | 507 IEEE80211_STATMASK_RATE |
509 IEEE80211_STATMASK_RSSI; 508 IEEE80211_STATMASK_RSSI;
510 if (phy->type == BCM43xx_PHYTYPE_A) 509 if (phy->type == BCM43xx_PHYTYPE_A)
diff --git a/drivers/net/wireless/hostap/hostap_ioctl.c b/drivers/net/wireless/hostap/hostap_ioctl.c
index 7a4978516eac..d061fb3443ff 100644
--- a/drivers/net/wireless/hostap/hostap_ioctl.c
+++ b/drivers/net/wireless/hostap/hostap_ioctl.c
@@ -1412,9 +1412,9 @@ static int prism2_ioctl_siwretry(struct net_device *dev,
1412 /* what could be done, if firmware would support this.. */ 1412 /* what could be done, if firmware would support this.. */
1413 1413
1414 if (rrq->flags & IW_RETRY_LIMIT) { 1414 if (rrq->flags & IW_RETRY_LIMIT) {
1415 if (rrq->flags & IW_RETRY_MAX) 1415 if (rrq->flags & IW_RETRY_LONG)
1416 HFA384X_RID_LONGRETRYLIMIT = rrq->value; 1416 HFA384X_RID_LONGRETRYLIMIT = rrq->value;
1417 else if (rrq->flags & IW_RETRY_MIN) 1417 else if (rrq->flags & IW_RETRY_SHORT)
1418 HFA384X_RID_SHORTRETRYLIMIT = rrq->value; 1418 HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
1419 else { 1419 else {
1420 HFA384X_RID_LONGRETRYLIMIT = rrq->value; 1420 HFA384X_RID_LONGRETRYLIMIT = rrq->value;
@@ -1468,14 +1468,14 @@ static int prism2_ioctl_giwretry(struct net_device *dev,
1468 rrq->value = le16_to_cpu(altretry); 1468 rrq->value = le16_to_cpu(altretry);
1469 else 1469 else
1470 rrq->value = local->manual_retry_count; 1470 rrq->value = local->manual_retry_count;
1471 } else if ((rrq->flags & IW_RETRY_MAX)) { 1471 } else if ((rrq->flags & IW_RETRY_LONG)) {
1472 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; 1472 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
1473 rrq->value = longretry; 1473 rrq->value = longretry;
1474 } else { 1474 } else {
1475 rrq->flags = IW_RETRY_LIMIT; 1475 rrq->flags = IW_RETRY_LIMIT;
1476 rrq->value = shortretry; 1476 rrq->value = shortretry;
1477 if (shortretry != longretry) 1477 if (shortretry != longretry)
1478 rrq->flags |= IW_RETRY_MIN; 1478 rrq->flags |= IW_RETRY_SHORT;
1479 } 1479 }
1480 } 1480 }
1481 return 0; 1481 return 0;
diff --git a/drivers/net/wireless/ipw2100.c b/drivers/net/wireless/ipw2100.c
index b4d81a04c895..599e2fe76188 100644
--- a/drivers/net/wireless/ipw2100.c
+++ b/drivers/net/wireless/ipw2100.c
@@ -150,7 +150,6 @@ that only one external action is invoked at a time.
150#include <linux/skbuff.h> 150#include <linux/skbuff.h>
151#include <asm/uaccess.h> 151#include <asm/uaccess.h>
152#include <asm/io.h> 152#include <asm/io.h>
153#define __KERNEL_SYSCALLS__
154#include <linux/fs.h> 153#include <linux/fs.h>
155#include <linux/mm.h> 154#include <linux/mm.h>
156#include <linux/slab.h> 155#include <linux/slab.h>
@@ -163,6 +162,7 @@ that only one external action is invoked at a time.
163#include <linux/firmware.h> 162#include <linux/firmware.h>
164#include <linux/acpi.h> 163#include <linux/acpi.h>
165#include <linux/ctype.h> 164#include <linux/ctype.h>
165#include <linux/latency.h>
166 166
167#include "ipw2100.h" 167#include "ipw2100.h"
168 168
@@ -1697,6 +1697,11 @@ static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
1697 return 0; 1697 return 0;
1698 } 1698 }
1699 1699
1700 /* the ipw2100 hardware really doesn't want power management delays
1701 * longer than 175usec
1702 */
1703 modify_acceptable_latency("ipw2100", 175);
1704
1700 /* If the interrupt is enabled, turn it off... */ 1705 /* If the interrupt is enabled, turn it off... */
1701 spin_lock_irqsave(&priv->low_lock, flags); 1706 spin_lock_irqsave(&priv->low_lock, flags);
1702 ipw2100_disable_interrupts(priv); 1707 ipw2100_disable_interrupts(priv);
@@ -1849,6 +1854,8 @@ static void ipw2100_down(struct ipw2100_priv *priv)
1849 ipw2100_disable_interrupts(priv); 1854 ipw2100_disable_interrupts(priv);
1850 spin_unlock_irqrestore(&priv->low_lock, flags); 1855 spin_unlock_irqrestore(&priv->low_lock, flags);
1851 1856
1857 modify_acceptable_latency("ipw2100", INFINITE_LATENCY);
1858
1852#ifdef ACPI_CSTATE_LIMIT_DEFINED 1859#ifdef ACPI_CSTATE_LIMIT_DEFINED
1853 if (priv->config & CFG_C3_DISABLED) { 1860 if (priv->config & CFG_C3_DISABLED) {
1854 IPW_DEBUG_INFO(": Resetting C3 transitions.\n"); 1861 IPW_DEBUG_INFO(": Resetting C3 transitions.\n");
@@ -6267,7 +6274,9 @@ static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
6267 IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev)); 6274 IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev));
6268 6275
6269 /* perform this after register_netdev so that dev->name is set */ 6276 /* perform this after register_netdev so that dev->name is set */
6270 sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group); 6277 err = sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6278 if (err)
6279 goto fail_unlock;
6271 6280
6272 /* If the RF Kill switch is disabled, go ahead and complete the 6281 /* If the RF Kill switch is disabled, go ahead and complete the
6273 * startup sequence */ 6282 * startup sequence */
@@ -6533,13 +6542,17 @@ static int __init ipw2100_init(void)
6533 printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT); 6542 printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT);
6534 6543
6535 ret = pci_register_driver(&ipw2100_pci_driver); 6544 ret = pci_register_driver(&ipw2100_pci_driver);
6545 if (ret)
6546 goto out;
6536 6547
6548 set_acceptable_latency("ipw2100", INFINITE_LATENCY);
6537#ifdef CONFIG_IPW2100_DEBUG 6549#ifdef CONFIG_IPW2100_DEBUG
6538 ipw2100_debug_level = debug; 6550 ipw2100_debug_level = debug;
6539 driver_create_file(&ipw2100_pci_driver.driver, 6551 ret = driver_create_file(&ipw2100_pci_driver.driver,
6540 &driver_attr_debug_level); 6552 &driver_attr_debug_level);
6541#endif 6553#endif
6542 6554
6555out:
6543 return ret; 6556 return ret;
6544} 6557}
6545 6558
@@ -6554,6 +6567,7 @@ static void __exit ipw2100_exit(void)
6554 &driver_attr_debug_level); 6567 &driver_attr_debug_level);
6555#endif 6568#endif
6556 pci_unregister_driver(&ipw2100_pci_driver); 6569 pci_unregister_driver(&ipw2100_pci_driver);
6570 remove_acceptable_latency("ipw2100");
6557} 6571}
6558 6572
6559module_init(ipw2100_init); 6573module_init(ipw2100_init);
@@ -6958,7 +6972,7 @@ static int ipw2100_wx_set_essid(struct net_device *dev,
6958 } 6972 }
6959 6973
6960 if (wrqu->essid.flags && wrqu->essid.length) { 6974 if (wrqu->essid.flags && wrqu->essid.length) {
6961 length = wrqu->essid.length - 1; 6975 length = wrqu->essid.length;
6962 essid = extra; 6976 essid = extra;
6963 } 6977 }
6964 6978
@@ -7051,7 +7065,7 @@ static int ipw2100_wx_get_nick(struct net_device *dev,
7051 7065
7052 struct ipw2100_priv *priv = ieee80211_priv(dev); 7066 struct ipw2100_priv *priv = ieee80211_priv(dev);
7053 7067
7054 wrqu->data.length = strlen(priv->nick) + 1; 7068 wrqu->data.length = strlen(priv->nick);
7055 memcpy(extra, priv->nick, wrqu->data.length); 7069 memcpy(extra, priv->nick, wrqu->data.length);
7056 wrqu->data.flags = 1; /* active */ 7070 wrqu->data.flags = 1; /* active */
7057 7071
@@ -7343,14 +7357,14 @@ static int ipw2100_wx_set_retry(struct net_device *dev,
7343 goto done; 7357 goto done;
7344 } 7358 }
7345 7359
7346 if (wrqu->retry.flags & IW_RETRY_MIN) { 7360 if (wrqu->retry.flags & IW_RETRY_SHORT) {
7347 err = ipw2100_set_short_retry(priv, wrqu->retry.value); 7361 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7348 IPW_DEBUG_WX("SET Short Retry Limit -> %d \n", 7362 IPW_DEBUG_WX("SET Short Retry Limit -> %d \n",
7349 wrqu->retry.value); 7363 wrqu->retry.value);
7350 goto done; 7364 goto done;
7351 } 7365 }
7352 7366
7353 if (wrqu->retry.flags & IW_RETRY_MAX) { 7367 if (wrqu->retry.flags & IW_RETRY_LONG) {
7354 err = ipw2100_set_long_retry(priv, wrqu->retry.value); 7368 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7355 IPW_DEBUG_WX("SET Long Retry Limit -> %d \n", 7369 IPW_DEBUG_WX("SET Long Retry Limit -> %d \n",
7356 wrqu->retry.value); 7370 wrqu->retry.value);
@@ -7383,14 +7397,14 @@ static int ipw2100_wx_get_retry(struct net_device *dev,
7383 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) 7397 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME)
7384 return -EINVAL; 7398 return -EINVAL;
7385 7399
7386 if (wrqu->retry.flags & IW_RETRY_MAX) { 7400 if (wrqu->retry.flags & IW_RETRY_LONG) {
7387 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX; 7401 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
7388 wrqu->retry.value = priv->long_retry_limit; 7402 wrqu->retry.value = priv->long_retry_limit;
7389 } else { 7403 } else {
7390 wrqu->retry.flags = 7404 wrqu->retry.flags =
7391 (priv->short_retry_limit != 7405 (priv->short_retry_limit !=
7392 priv->long_retry_limit) ? 7406 priv->long_retry_limit) ?
7393 IW_RETRY_LIMIT | IW_RETRY_MIN : IW_RETRY_LIMIT; 7407 IW_RETRY_LIMIT | IW_RETRY_SHORT : IW_RETRY_LIMIT;
7394 7408
7395 wrqu->retry.value = priv->short_retry_limit; 7409 wrqu->retry.value = priv->short_retry_limit;
7396 } 7410 }
diff --git a/drivers/net/wireless/ipw2200.c b/drivers/net/wireless/ipw2200.c
index 7358664e0908..5685d7ba55bb 100644
--- a/drivers/net/wireless/ipw2200.c
+++ b/drivers/net/wireless/ipw2200.c
@@ -8875,8 +8875,6 @@ static int ipw_wx_set_essid(struct net_device *dev,
8875 } 8875 }
8876 8876
8877 length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE); 8877 length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE);
8878 if (!extra[length - 1])
8879 length--;
8880 8878
8881 priv->config |= CFG_STATIC_ESSID; 8879 priv->config |= CFG_STATIC_ESSID;
8882 8880
@@ -8953,7 +8951,7 @@ static int ipw_wx_get_nick(struct net_device *dev,
8953 struct ipw_priv *priv = ieee80211_priv(dev); 8951 struct ipw_priv *priv = ieee80211_priv(dev);
8954 IPW_DEBUG_WX("Getting nick\n"); 8952 IPW_DEBUG_WX("Getting nick\n");
8955 mutex_lock(&priv->mutex); 8953 mutex_lock(&priv->mutex);
8956 wrqu->data.length = strlen(priv->nick) + 1; 8954 wrqu->data.length = strlen(priv->nick);
8957 memcpy(extra, priv->nick, wrqu->data.length); 8955 memcpy(extra, priv->nick, wrqu->data.length);
8958 wrqu->data.flags = 1; /* active */ 8956 wrqu->data.flags = 1; /* active */
8959 mutex_unlock(&priv->mutex); 8957 mutex_unlock(&priv->mutex);
@@ -9276,9 +9274,9 @@ static int ipw_wx_set_retry(struct net_device *dev,
9276 return -EINVAL; 9274 return -EINVAL;
9277 9275
9278 mutex_lock(&priv->mutex); 9276 mutex_lock(&priv->mutex);
9279 if (wrqu->retry.flags & IW_RETRY_MIN) 9277 if (wrqu->retry.flags & IW_RETRY_SHORT)
9280 priv->short_retry_limit = (u8) wrqu->retry.value; 9278 priv->short_retry_limit = (u8) wrqu->retry.value;
9281 else if (wrqu->retry.flags & IW_RETRY_MAX) 9279 else if (wrqu->retry.flags & IW_RETRY_LONG)
9282 priv->long_retry_limit = (u8) wrqu->retry.value; 9280 priv->long_retry_limit = (u8) wrqu->retry.value;
9283 else { 9281 else {
9284 priv->short_retry_limit = (u8) wrqu->retry.value; 9282 priv->short_retry_limit = (u8) wrqu->retry.value;
@@ -9307,11 +9305,11 @@ static int ipw_wx_get_retry(struct net_device *dev,
9307 return -EINVAL; 9305 return -EINVAL;
9308 } 9306 }
9309 9307
9310 if (wrqu->retry.flags & IW_RETRY_MAX) { 9308 if (wrqu->retry.flags & IW_RETRY_LONG) {
9311 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX; 9309 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
9312 wrqu->retry.value = priv->long_retry_limit; 9310 wrqu->retry.value = priv->long_retry_limit;
9313 } else if (wrqu->retry.flags & IW_RETRY_MIN) { 9311 } else if (wrqu->retry.flags & IW_RETRY_SHORT) {
9314 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN; 9312 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
9315 wrqu->retry.value = priv->short_retry_limit; 9313 wrqu->retry.value = priv->short_retry_limit;
9316 } else { 9314 } else {
9317 wrqu->retry.flags = IW_RETRY_LIMIT; 9315 wrqu->retry.flags = IW_RETRY_LIMIT;
diff --git a/drivers/net/wireless/orinoco.c b/drivers/net/wireless/orinoco.c
index 1840b69e3cb5..9e19a963febc 100644
--- a/drivers/net/wireless/orinoco.c
+++ b/drivers/net/wireless/orinoco.c
@@ -3037,7 +3037,7 @@ static int orinoco_ioctl_getessid(struct net_device *dev,
3037 } 3037 }
3038 3038
3039 erq->flags = 1; 3039 erq->flags = 1;
3040 erq->length = strlen(essidbuf) + 1; 3040 erq->length = strlen(essidbuf);
3041 3041
3042 return 0; 3042 return 0;
3043} 3043}
@@ -3078,7 +3078,7 @@ static int orinoco_ioctl_getnick(struct net_device *dev,
3078 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1); 3078 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
3079 orinoco_unlock(priv, &flags); 3079 orinoco_unlock(priv, &flags);
3080 3080
3081 nrq->length = strlen(nickbuf)+1; 3081 nrq->length = strlen(nickbuf);
3082 3082
3083 return 0; 3083 return 0;
3084} 3084}
@@ -3575,14 +3575,14 @@ static int orinoco_ioctl_getretry(struct net_device *dev,
3575 rrq->value = lifetime * 1000; /* ??? */ 3575 rrq->value = lifetime * 1000; /* ??? */
3576 } else { 3576 } else {
3577 /* By default, display the min number */ 3577 /* By default, display the min number */
3578 if ((rrq->flags & IW_RETRY_MAX)) { 3578 if ((rrq->flags & IW_RETRY_LONG)) {
3579 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; 3579 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
3580 rrq->value = long_limit; 3580 rrq->value = long_limit;
3581 } else { 3581 } else {
3582 rrq->flags = IW_RETRY_LIMIT; 3582 rrq->flags = IW_RETRY_LIMIT;
3583 rrq->value = short_limit; 3583 rrq->value = short_limit;
3584 if(short_limit != long_limit) 3584 if(short_limit != long_limit)
3585 rrq->flags |= IW_RETRY_MIN; 3585 rrq->flags |= IW_RETRY_SHORT;
3586 } 3586 }
3587 } 3587 }
3588 3588
diff --git a/drivers/net/wireless/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c
index c09fbf733b3a..286325ca3293 100644
--- a/drivers/net/wireless/prism54/isl_ioctl.c
+++ b/drivers/net/wireless/prism54/isl_ioctl.c
@@ -742,9 +742,9 @@ prism54_set_essid(struct net_device *ndev, struct iw_request_info *info,
742 742
743 /* Check if we were asked for `any' */ 743 /* Check if we were asked for `any' */
744 if (dwrq->flags && dwrq->length) { 744 if (dwrq->flags && dwrq->length) {
745 if (dwrq->length > min(33, IW_ESSID_MAX_SIZE + 1)) 745 if (dwrq->length > 32)
746 return -E2BIG; 746 return -E2BIG;
747 essid.length = dwrq->length - 1; 747 essid.length = dwrq->length;
748 memcpy(essid.octets, extra, dwrq->length); 748 memcpy(essid.octets, extra, dwrq->length);
749 } else 749 } else
750 essid.length = 0; 750 essid.length = 0;
@@ -814,7 +814,7 @@ prism54_get_nick(struct net_device *ndev, struct iw_request_info *info,
814 dwrq->length = 0; 814 dwrq->length = 0;
815 815
816 down_read(&priv->mib_sem); 816 down_read(&priv->mib_sem);
817 dwrq->length = strlen(priv->nickname) + 1; 817 dwrq->length = strlen(priv->nickname);
818 memcpy(extra, priv->nickname, dwrq->length); 818 memcpy(extra, priv->nickname, dwrq->length);
819 up_read(&priv->mib_sem); 819 up_read(&priv->mib_sem);
820 820
@@ -992,9 +992,9 @@ prism54_set_retry(struct net_device *ndev, struct iw_request_info *info,
992 return -EINVAL; 992 return -EINVAL;
993 993
994 if (vwrq->flags & IW_RETRY_LIMIT) { 994 if (vwrq->flags & IW_RETRY_LIMIT) {
995 if (vwrq->flags & IW_RETRY_MIN) 995 if (vwrq->flags & IW_RETRY_SHORT)
996 slimit = vwrq->value; 996 slimit = vwrq->value;
997 else if (vwrq->flags & IW_RETRY_MAX) 997 else if (vwrq->flags & IW_RETRY_LONG)
998 llimit = vwrq->value; 998 llimit = vwrq->value;
999 else { 999 else {
1000 /* we are asked to set both */ 1000 /* we are asked to set both */
@@ -1035,18 +1035,18 @@ prism54_get_retry(struct net_device *ndev, struct iw_request_info *info,
1035 mgt_get_request(priv, DOT11_OID_MAXTXLIFETIME, 0, NULL, &r); 1035 mgt_get_request(priv, DOT11_OID_MAXTXLIFETIME, 0, NULL, &r);
1036 vwrq->value = r.u * 1024; 1036 vwrq->value = r.u * 1024;
1037 vwrq->flags = IW_RETRY_LIFETIME; 1037 vwrq->flags = IW_RETRY_LIFETIME;
1038 } else if ((vwrq->flags & IW_RETRY_MAX)) { 1038 } else if ((vwrq->flags & IW_RETRY_LONG)) {
1039 /* we are asked for the long retry limit */ 1039 /* we are asked for the long retry limit */
1040 rvalue |= 1040 rvalue |=
1041 mgt_get_request(priv, DOT11_OID_LONGRETRIES, 0, NULL, &r); 1041 mgt_get_request(priv, DOT11_OID_LONGRETRIES, 0, NULL, &r);
1042 vwrq->value = r.u; 1042 vwrq->value = r.u;
1043 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; 1043 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
1044 } else { 1044 } else {
1045 /* default. get the short retry limit */ 1045 /* default. get the short retry limit */
1046 rvalue |= 1046 rvalue |=
1047 mgt_get_request(priv, DOT11_OID_SHORTRETRIES, 0, NULL, &r); 1047 mgt_get_request(priv, DOT11_OID_SHORTRETRIES, 0, NULL, &r);
1048 vwrq->value = r.u; 1048 vwrq->value = r.u;
1049 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MIN; 1049 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
1050 } 1050 }
1051 1051
1052 return rvalue; 1052 return rvalue;
diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
index 4574290f971f..e82548ea609a 100644
--- a/drivers/net/wireless/ray_cs.c
+++ b/drivers/net/wireless/ray_cs.c
@@ -1173,7 +1173,7 @@ static int ray_set_essid(struct net_device *dev,
1173 return -EOPNOTSUPP; 1173 return -EOPNOTSUPP;
1174 } else { 1174 } else {
1175 /* Check the size of the string */ 1175 /* Check the size of the string */
1176 if(dwrq->length > IW_ESSID_MAX_SIZE + 1) { 1176 if(dwrq->length > IW_ESSID_MAX_SIZE) {
1177 return -E2BIG; 1177 return -E2BIG;
1178 } 1178 }
1179 1179
diff --git a/drivers/net/wireless/strip.c b/drivers/net/wireless/strip.c
index ccaf28e8db0a..337c692f6fd6 100644
--- a/drivers/net/wireless/strip.c
+++ b/drivers/net/wireless/strip.c
@@ -1342,7 +1342,7 @@ static unsigned char *strip_make_packet(unsigned char *buffer,
1342 * 'broadcast hub' radio (First byte of address being 0xFF means broadcast) 1342 * 'broadcast hub' radio (First byte of address being 0xFF means broadcast)
1343 */ 1343 */
1344 if (haddr.c[0] == 0xFF) { 1344 if (haddr.c[0] == 0xFF) {
1345 u32 brd = 0; 1345 __be32 brd = 0;
1346 struct in_device *in_dev; 1346 struct in_device *in_dev;
1347 1347
1348 rcu_read_lock(); 1348 rcu_read_lock();
@@ -1406,7 +1406,7 @@ static void strip_send(struct strip *strip_info, struct sk_buff *skb)
1406 int doreset = (long) jiffies - strip_info->watchdog_doreset >= 0; 1406 int doreset = (long) jiffies - strip_info->watchdog_doreset >= 0;
1407 int doprobe = (long) jiffies - strip_info->watchdog_doprobe >= 0 1407 int doprobe = (long) jiffies - strip_info->watchdog_doprobe >= 0
1408 && !doreset; 1408 && !doreset;
1409 u32 addr, brd; 1409 __be32 addr, brd;
1410 1410
1411 /* 1411 /*
1412 * 1. If we have a packet, encapsulate it and put it in the buffer 1412 * 1. If we have a packet, encapsulate it and put it in the buffer
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index e0d294c12970..e3ae5f60d5be 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -1802,15 +1802,15 @@ static int wl3501_get_retry(struct net_device *dev,
1802 &retry, sizeof(retry)); 1802 &retry, sizeof(retry));
1803 if (rc) 1803 if (rc)
1804 goto out; 1804 goto out;
1805 if (wrqu->retry.flags & IW_RETRY_MAX) { 1805 if (wrqu->retry.flags & IW_RETRY_LONG) {
1806 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX; 1806 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
1807 goto set_value; 1807 goto set_value;
1808 } 1808 }
1809 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_SHORT_RETRY_LIMIT, 1809 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_SHORT_RETRY_LIMIT,
1810 &retry, sizeof(retry)); 1810 &retry, sizeof(retry));
1811 if (rc) 1811 if (rc)
1812 goto out; 1812 goto out;
1813 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN; 1813 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
1814set_value: 1814set_value:
1815 wrqu->retry.value = retry; 1815 wrqu->retry.value = retry;
1816 wrqu->retry.disabled = 0; 1816 wrqu->retry.disabled = 0;
diff --git a/drivers/net/wireless/zd1201.c b/drivers/net/wireless/zd1201.c
index c52e9bcf8d02..80af9a9fcbb3 100644
--- a/drivers/net/wireless/zd1201.c
+++ b/drivers/net/wireless/zd1201.c
@@ -119,7 +119,7 @@ static void zd1201_usbfree(struct urb *urb, struct pt_regs *regs)
119 switch(urb->status) { 119 switch(urb->status) {
120 case -EILSEQ: 120 case -EILSEQ:
121 case -ENODEV: 121 case -ENODEV:
122 case -ETIMEDOUT: 122 case -ETIME:
123 case -ENOENT: 123 case -ENOENT:
124 case -EPIPE: 124 case -EPIPE:
125 case -EOVERFLOW: 125 case -EOVERFLOW:
@@ -201,7 +201,7 @@ static void zd1201_usbrx(struct urb *urb, struct pt_regs *regs)
201 switch(urb->status) { 201 switch(urb->status) {
202 case -EILSEQ: 202 case -EILSEQ:
203 case -ENODEV: 203 case -ENODEV:
204 case -ETIMEDOUT: 204 case -ETIME:
205 case -ENOENT: 205 case -ENOENT:
206 case -EPIPE: 206 case -EPIPE:
207 case -EOVERFLOW: 207 case -EOVERFLOW:
@@ -1218,7 +1218,7 @@ static int zd1201_set_essid(struct net_device *dev,
1218 return -EINVAL; 1218 return -EINVAL;
1219 if (data->length < 1) 1219 if (data->length < 1)
1220 data->length = 1; 1220 data->length = 1;
1221 zd->essidlen = data->length-1; 1221 zd->essidlen = data->length;
1222 memset(zd->essid, 0, IW_ESSID_MAX_SIZE+1); 1222 memset(zd->essid, 0, IW_ESSID_MAX_SIZE+1);
1223 memcpy(zd->essid, essid, data->length); 1223 memcpy(zd->essid, essid, data->length);
1224 return zd1201_join(zd, zd->essid, zd->essidlen); 1224 return zd1201_join(zd, zd->essid, zd->essidlen);
diff --git a/drivers/net/wireless/zd1211rw/zd_chip.c b/drivers/net/wireless/zd1211rw/zd_chip.c
index 7c4e32cf0d47..aa661b2b76c7 100644
--- a/drivers/net/wireless/zd1211rw/zd_chip.c
+++ b/drivers/net/wireless/zd1211rw/zd_chip.c
@@ -249,7 +249,6 @@ int zd_ioread16(struct zd_chip *chip, zd_addr_t addr, u16 *value)
249{ 249{
250 int r; 250 int r;
251 251
252 ZD_ASSERT(!mutex_is_locked(&chip->mutex));
253 mutex_lock(&chip->mutex); 252 mutex_lock(&chip->mutex);
254 r = zd_ioread16_locked(chip, value, addr); 253 r = zd_ioread16_locked(chip, value, addr);
255 mutex_unlock(&chip->mutex); 254 mutex_unlock(&chip->mutex);
@@ -260,7 +259,6 @@ int zd_ioread32(struct zd_chip *chip, zd_addr_t addr, u32 *value)
260{ 259{
261 int r; 260 int r;
262 261
263 ZD_ASSERT(!mutex_is_locked(&chip->mutex));
264 mutex_lock(&chip->mutex); 262 mutex_lock(&chip->mutex);
265 r = zd_ioread32_locked(chip, value, addr); 263 r = zd_ioread32_locked(chip, value, addr);
266 mutex_unlock(&chip->mutex); 264 mutex_unlock(&chip->mutex);
@@ -271,7 +269,6 @@ int zd_iowrite16(struct zd_chip *chip, zd_addr_t addr, u16 value)
271{ 269{
272 int r; 270 int r;
273 271
274 ZD_ASSERT(!mutex_is_locked(&chip->mutex));
275 mutex_lock(&chip->mutex); 272 mutex_lock(&chip->mutex);
276 r = zd_iowrite16_locked(chip, value, addr); 273 r = zd_iowrite16_locked(chip, value, addr);
277 mutex_unlock(&chip->mutex); 274 mutex_unlock(&chip->mutex);
@@ -282,7 +279,6 @@ int zd_iowrite32(struct zd_chip *chip, zd_addr_t addr, u32 value)
282{ 279{
283 int r; 280 int r;
284 281
285 ZD_ASSERT(!mutex_is_locked(&chip->mutex));
286 mutex_lock(&chip->mutex); 282 mutex_lock(&chip->mutex);
287 r = zd_iowrite32_locked(chip, value, addr); 283 r = zd_iowrite32_locked(chip, value, addr);
288 mutex_unlock(&chip->mutex); 284 mutex_unlock(&chip->mutex);
@@ -294,7 +290,6 @@ int zd_ioread32v(struct zd_chip *chip, const zd_addr_t *addresses,
294{ 290{
295 int r; 291 int r;
296 292
297 ZD_ASSERT(!mutex_is_locked(&chip->mutex));
298 mutex_lock(&chip->mutex); 293 mutex_lock(&chip->mutex);
299 r = zd_ioread32v_locked(chip, values, addresses, count); 294 r = zd_ioread32v_locked(chip, values, addresses, count);
300 mutex_unlock(&chip->mutex); 295 mutex_unlock(&chip->mutex);
@@ -306,7 +301,6 @@ int zd_iowrite32a(struct zd_chip *chip, const struct zd_ioreq32 *ioreqs,
306{ 301{
307 int r; 302 int r;
308 303
309 ZD_ASSERT(!mutex_is_locked(&chip->mutex));
310 mutex_lock(&chip->mutex); 304 mutex_lock(&chip->mutex);
311 r = zd_iowrite32a_locked(chip, ioreqs, count); 305 r = zd_iowrite32a_locked(chip, ioreqs, count);
312 mutex_unlock(&chip->mutex); 306 mutex_unlock(&chip->mutex);
@@ -331,13 +325,22 @@ static int read_pod(struct zd_chip *chip, u8 *rf_type)
331 chip->patch_cr157 = (value >> 13) & 0x1; 325 chip->patch_cr157 = (value >> 13) & 0x1;
332 chip->patch_6m_band_edge = (value >> 21) & 0x1; 326 chip->patch_6m_band_edge = (value >> 21) & 0x1;
333 chip->new_phy_layout = (value >> 31) & 0x1; 327 chip->new_phy_layout = (value >> 31) & 0x1;
328 chip->link_led = ((value >> 4) & 1) ? LED1 : LED2;
329 chip->supports_tx_led = 1;
330 if (value & (1 << 24)) { /* LED scenario */
331 if (value & (1 << 29))
332 chip->supports_tx_led = 0;
333 }
334 334
335 dev_dbg_f(zd_chip_dev(chip), 335 dev_dbg_f(zd_chip_dev(chip),
336 "RF %s %#01x PA type %#01x patch CCK %d patch CR157 %d " 336 "RF %s %#01x PA type %#01x patch CCK %d patch CR157 %d "
337 "patch 6M %d new PHY %d\n", 337 "patch 6M %d new PHY %d link LED%d tx led %d\n",
338 zd_rf_name(*rf_type), *rf_type, 338 zd_rf_name(*rf_type), *rf_type,
339 chip->pa_type, chip->patch_cck_gain, 339 chip->pa_type, chip->patch_cck_gain,
340 chip->patch_cr157, chip->patch_6m_band_edge, chip->new_phy_layout); 340 chip->patch_cr157, chip->patch_6m_band_edge,
341 chip->new_phy_layout,
342 chip->link_led == LED1 ? 1 : 2,
343 chip->supports_tx_led);
341 return 0; 344 return 0;
342error: 345error:
343 *rf_type = 0; 346 *rf_type = 0;
@@ -1181,7 +1184,7 @@ static int update_pwr_int(struct zd_chip *chip, u8 channel)
1181 u8 value = chip->pwr_int_values[channel - 1]; 1184 u8 value = chip->pwr_int_values[channel - 1];
1182 dev_dbg_f(zd_chip_dev(chip), "channel %d pwr_int %#04x\n", 1185 dev_dbg_f(zd_chip_dev(chip), "channel %d pwr_int %#04x\n",
1183 channel, value); 1186 channel, value);
1184 return zd_iowrite32_locked(chip, value, CR31); 1187 return zd_iowrite16_locked(chip, value, CR31);
1185} 1188}
1186 1189
1187static int update_pwr_cal(struct zd_chip *chip, u8 channel) 1190static int update_pwr_cal(struct zd_chip *chip, u8 channel)
@@ -1189,12 +1192,12 @@ static int update_pwr_cal(struct zd_chip *chip, u8 channel)
1189 u8 value = chip->pwr_cal_values[channel-1]; 1192 u8 value = chip->pwr_cal_values[channel-1];
1190 dev_dbg_f(zd_chip_dev(chip), "channel %d pwr_cal %#04x\n", 1193 dev_dbg_f(zd_chip_dev(chip), "channel %d pwr_cal %#04x\n",
1191 channel, value); 1194 channel, value);
1192 return zd_iowrite32_locked(chip, value, CR68); 1195 return zd_iowrite16_locked(chip, value, CR68);
1193} 1196}
1194 1197
1195static int update_ofdm_cal(struct zd_chip *chip, u8 channel) 1198static int update_ofdm_cal(struct zd_chip *chip, u8 channel)
1196{ 1199{
1197 struct zd_ioreq32 ioreqs[3]; 1200 struct zd_ioreq16 ioreqs[3];
1198 1201
1199 ioreqs[0].addr = CR67; 1202 ioreqs[0].addr = CR67;
1200 ioreqs[0].value = chip->ofdm_cal_values[OFDM_36M_INDEX][channel-1]; 1203 ioreqs[0].value = chip->ofdm_cal_values[OFDM_36M_INDEX][channel-1];
@@ -1206,7 +1209,7 @@ static int update_ofdm_cal(struct zd_chip *chip, u8 channel)
1206 dev_dbg_f(zd_chip_dev(chip), 1209 dev_dbg_f(zd_chip_dev(chip),
1207 "channel %d ofdm_cal 36M %#04x 48M %#04x 54M %#04x\n", 1210 "channel %d ofdm_cal 36M %#04x 48M %#04x 54M %#04x\n",
1208 channel, ioreqs[0].value, ioreqs[1].value, ioreqs[2].value); 1211 channel, ioreqs[0].value, ioreqs[1].value, ioreqs[2].value);
1209 return zd_iowrite32a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs)); 1212 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
1210} 1213}
1211 1214
1212static int update_channel_integration_and_calibration(struct zd_chip *chip, 1215static int update_channel_integration_and_calibration(struct zd_chip *chip,
@@ -1218,7 +1221,7 @@ static int update_channel_integration_and_calibration(struct zd_chip *chip,
1218 if (r) 1221 if (r)
1219 return r; 1222 return r;
1220 if (chip->is_zd1211b) { 1223 if (chip->is_zd1211b) {
1221 static const struct zd_ioreq32 ioreqs[] = { 1224 static const struct zd_ioreq16 ioreqs[] = {
1222 { CR69, 0x28 }, 1225 { CR69, 0x28 },
1223 {}, 1226 {},
1224 { CR69, 0x2a }, 1227 { CR69, 0x2a },
@@ -1230,7 +1233,7 @@ static int update_channel_integration_and_calibration(struct zd_chip *chip,
1230 r = update_pwr_cal(chip, channel); 1233 r = update_pwr_cal(chip, channel);
1231 if (r) 1234 if (r)
1232 return r; 1235 return r;
1233 r = zd_iowrite32a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs)); 1236 r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
1234 if (r) 1237 if (r)
1235 return r; 1238 return r;
1236 } 1239 }
@@ -1252,7 +1255,7 @@ static int patch_cck_gain(struct zd_chip *chip)
1252 if (r) 1255 if (r)
1253 return r; 1256 return r;
1254 dev_dbg_f(zd_chip_dev(chip), "patching value %x\n", value & 0xff); 1257 dev_dbg_f(zd_chip_dev(chip), "patching value %x\n", value & 0xff);
1255 return zd_iowrite32_locked(chip, value & 0xff, CR47); 1258 return zd_iowrite16_locked(chip, value & 0xff, CR47);
1256} 1259}
1257 1260
1258int zd_chip_set_channel(struct zd_chip *chip, u8 channel) 1261int zd_chip_set_channel(struct zd_chip *chip, u8 channel)
@@ -1295,89 +1298,60 @@ u8 zd_chip_get_channel(struct zd_chip *chip)
1295 return channel; 1298 return channel;
1296} 1299}
1297 1300
1298static u16 led_mask(int led) 1301int zd_chip_control_leds(struct zd_chip *chip, enum led_status status)
1299{ 1302{
1300 switch (led) { 1303 static const zd_addr_t a[] = {
1301 case 1: 1304 FW_LINK_STATUS,
1302 return LED1; 1305 CR_LED,
1303 case 2: 1306 };
1304 return LED2;
1305 default:
1306 return 0;
1307 }
1308}
1309
1310static int read_led_reg(struct zd_chip *chip, u16 *status)
1311{
1312 ZD_ASSERT(mutex_is_locked(&chip->mutex));
1313 return zd_ioread16_locked(chip, status, CR_LED);
1314}
1315
1316static int write_led_reg(struct zd_chip *chip, u16 status)
1317{
1318 ZD_ASSERT(mutex_is_locked(&chip->mutex));
1319 return zd_iowrite16_locked(chip, status, CR_LED);
1320}
1321 1307
1322int zd_chip_led_status(struct zd_chip *chip, int led, enum led_status status) 1308 int r;
1323{ 1309 u16 v[ARRAY_SIZE(a)];
1324 int r, ret; 1310 struct zd_ioreq16 ioreqs[ARRAY_SIZE(a)] = {
1325 u16 mask = led_mask(led); 1311 [0] = { FW_LINK_STATUS },
1326 u16 reg; 1312 [1] = { CR_LED },
1313 };
1314 u16 other_led;
1327 1315
1328 if (!mask)
1329 return -EINVAL;
1330 mutex_lock(&chip->mutex); 1316 mutex_lock(&chip->mutex);
1331 r = read_led_reg(chip, &reg); 1317 r = zd_ioread16v_locked(chip, v, (const zd_addr_t *)a, ARRAY_SIZE(a));
1332 if (r) 1318 if (r)
1333 return r; 1319 goto out;
1320
1321 other_led = chip->link_led == LED1 ? LED2 : LED1;
1322
1334 switch (status) { 1323 switch (status) {
1335 case LED_STATUS:
1336 return (reg & mask) ? LED_ON : LED_OFF;
1337 case LED_OFF: 1324 case LED_OFF:
1338 reg &= ~mask; 1325 ioreqs[0].value = FW_LINK_OFF;
1339 ret = LED_OFF; 1326 ioreqs[1].value = v[1] & ~(LED1|LED2);
1340 break; 1327 break;
1341 case LED_FLIP: 1328 case LED_SCANNING:
1342 reg ^= mask; 1329 ioreqs[0].value = FW_LINK_OFF;
1343 ret = (reg&mask) ? LED_ON : LED_OFF; 1330 ioreqs[1].value = v[1] & ~other_led;
1331 if (get_seconds() % 3 == 0) {
1332 ioreqs[1].value &= ~chip->link_led;
1333 } else {
1334 ioreqs[1].value |= chip->link_led;
1335 }
1344 break; 1336 break;
1345 case LED_ON: 1337 case LED_ASSOCIATED:
1346 reg |= mask; 1338 ioreqs[0].value = FW_LINK_TX;
1347 ret = LED_ON; 1339 ioreqs[1].value = v[1] & ~other_led;
1340 ioreqs[1].value |= chip->link_led;
1348 break; 1341 break;
1349 default: 1342 default:
1350 return -EINVAL; 1343 r = -EINVAL;
1351 }
1352 r = write_led_reg(chip, reg);
1353 if (r) {
1354 ret = r;
1355 goto out; 1344 goto out;
1356 } 1345 }
1357out:
1358 mutex_unlock(&chip->mutex);
1359 return r;
1360}
1361
1362int zd_chip_led_flip(struct zd_chip *chip, int led,
1363 const unsigned int *phases_msecs, unsigned int count)
1364{
1365 int i, r;
1366 enum led_status status;
1367 1346
1368 r = zd_chip_led_status(chip, led, LED_STATUS); 1347 if (v[0] != ioreqs[0].value || v[1] != ioreqs[1].value) {
1369 if (r) 1348 r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
1370 return r; 1349 if (r)
1371 status = r;
1372 for (i = 0; i < count; i++) {
1373 r = zd_chip_led_status(chip, led, LED_FLIP);
1374 if (r < 0)
1375 goto out; 1350 goto out;
1376 msleep(phases_msecs[i]);
1377 } 1351 }
1378 1352 r = 0;
1379out: 1353out:
1380 zd_chip_led_status(chip, led, status); 1354 mutex_unlock(&chip->mutex);
1381 return r; 1355 return r;
1382} 1356}
1383 1357
@@ -1679,4 +1653,3 @@ int zd_rfwritev_cr_locked(struct zd_chip *chip,
1679 1653
1680 return 0; 1654 return 0;
1681} 1655}
1682
diff --git a/drivers/net/wireless/zd1211rw/zd_chip.h b/drivers/net/wireless/zd1211rw/zd_chip.h
index 4b1250859897..ae59597ce4e1 100644
--- a/drivers/net/wireless/zd1211rw/zd_chip.h
+++ b/drivers/net/wireless/zd1211rw/zd_chip.h
@@ -428,6 +428,7 @@
428/* masks for controlling LEDs */ 428/* masks for controlling LEDs */
429#define LED1 0x0100 429#define LED1 0x0100
430#define LED2 0x0200 430#define LED2 0x0200
431#define LED_SW 0x0400
431 432
432/* Seems to indicate that the configuration is over. 433/* Seems to indicate that the configuration is over.
433 */ 434 */
@@ -629,6 +630,10 @@
629#define FW_SOFT_RESET FW_REG(4) 630#define FW_SOFT_RESET FW_REG(4)
630#define FW_FLASH_CHK FW_REG(5) 631#define FW_FLASH_CHK FW_REG(5)
631 632
633#define FW_LINK_OFF 0x0
634#define FW_LINK_TX 0x1
635/* 0x2 - link led on? */
636
632enum { 637enum {
633 CR_BASE_OFFSET = 0x9000, 638 CR_BASE_OFFSET = 0x9000,
634 FW_START_OFFSET = 0xee00, 639 FW_START_OFFSET = 0xee00,
@@ -663,8 +668,11 @@ struct zd_chip {
663 u8 pwr_int_values[E2P_CHANNEL_COUNT]; 668 u8 pwr_int_values[E2P_CHANNEL_COUNT];
664 /* SetPointOFDM in the vendor driver */ 669 /* SetPointOFDM in the vendor driver */
665 u8 ofdm_cal_values[3][E2P_CHANNEL_COUNT]; 670 u8 ofdm_cal_values[3][E2P_CHANNEL_COUNT];
666 u8 pa_type:4, patch_cck_gain:1, patch_cr157:1, patch_6m_band_edge:1, 671 u16 link_led;
667 new_phy_layout:1, is_zd1211b:1; 672 unsigned int pa_type:4,
673 patch_cck_gain:1, patch_cr157:1, patch_6m_band_edge:1,
674 new_phy_layout:1,
675 is_zd1211b:1, supports_tx_led:1;
668}; 676};
669 677
670static inline struct zd_chip *zd_usb_to_chip(struct zd_usb *usb) 678static inline struct zd_chip *zd_usb_to_chip(struct zd_usb *usb)
@@ -812,15 +820,12 @@ int zd_chip_lock_phy_regs(struct zd_chip *chip);
812int zd_chip_unlock_phy_regs(struct zd_chip *chip); 820int zd_chip_unlock_phy_regs(struct zd_chip *chip);
813 821
814enum led_status { 822enum led_status {
815 LED_OFF = 0, 823 LED_OFF = 0,
816 LED_ON = 1, 824 LED_SCANNING = 1,
817 LED_FLIP = 2, 825 LED_ASSOCIATED = 2,
818 LED_STATUS = 3,
819}; 826};
820 827
821int zd_chip_led_status(struct zd_chip *chip, int led, enum led_status status); 828int zd_chip_control_leds(struct zd_chip *chip, enum led_status status);
822int zd_chip_led_flip(struct zd_chip *chip, int led,
823 const unsigned int *phases_msecs, unsigned int count);
824 829
825int zd_set_beacon_interval(struct zd_chip *chip, u32 interval); 830int zd_set_beacon_interval(struct zd_chip *chip, u32 interval);
826 831
diff --git a/drivers/net/wireless/zd1211rw/zd_mac.c b/drivers/net/wireless/zd1211rw/zd_mac.c
index 1989f1c05fbe..2d12837052b0 100644
--- a/drivers/net/wireless/zd1211rw/zd_mac.c
+++ b/drivers/net/wireless/zd1211rw/zd_mac.c
@@ -33,6 +33,10 @@
33static void ieee_init(struct ieee80211_device *ieee); 33static void ieee_init(struct ieee80211_device *ieee);
34static void softmac_init(struct ieee80211softmac_device *sm); 34static void softmac_init(struct ieee80211softmac_device *sm);
35 35
36static void housekeeping_init(struct zd_mac *mac);
37static void housekeeping_enable(struct zd_mac *mac);
38static void housekeeping_disable(struct zd_mac *mac);
39
36int zd_mac_init(struct zd_mac *mac, 40int zd_mac_init(struct zd_mac *mac,
37 struct net_device *netdev, 41 struct net_device *netdev,
38 struct usb_interface *intf) 42 struct usb_interface *intf)
@@ -46,6 +50,7 @@ int zd_mac_init(struct zd_mac *mac,
46 ieee_init(ieee); 50 ieee_init(ieee);
47 softmac_init(ieee80211_priv(netdev)); 51 softmac_init(ieee80211_priv(netdev));
48 zd_chip_init(&mac->chip, netdev, intf); 52 zd_chip_init(&mac->chip, netdev, intf);
53 housekeeping_init(mac);
49 return 0; 54 return 0;
50} 55}
51 56
@@ -178,6 +183,7 @@ int zd_mac_open(struct net_device *netdev)
178 if (r < 0) 183 if (r < 0)
179 goto disable_rx; 184 goto disable_rx;
180 185
186 housekeeping_enable(mac);
181 ieee80211softmac_start(netdev); 187 ieee80211softmac_start(netdev);
182 return 0; 188 return 0;
183disable_rx: 189disable_rx:
@@ -204,6 +210,7 @@ int zd_mac_stop(struct net_device *netdev)
204 */ 210 */
205 211
206 zd_chip_disable_rx(chip); 212 zd_chip_disable_rx(chip);
213 housekeeping_disable(mac);
207 ieee80211softmac_stop(netdev); 214 ieee80211softmac_stop(netdev);
208 215
209 zd_chip_disable_hwint(chip); 216 zd_chip_disable_hwint(chip);
@@ -1080,3 +1087,46 @@ void zd_dump_rx_status(const struct rx_status *status)
1080 } 1087 }
1081} 1088}
1082#endif /* DEBUG */ 1089#endif /* DEBUG */
1090
1091#define LINK_LED_WORK_DELAY HZ
1092
1093static void link_led_handler(void *p)
1094{
1095 struct zd_mac *mac = p;
1096 struct zd_chip *chip = &mac->chip;
1097 struct ieee80211softmac_device *sm = ieee80211_priv(mac->netdev);
1098 int is_associated;
1099 int r;
1100
1101 spin_lock_irq(&mac->lock);
1102 is_associated = sm->associated != 0;
1103 spin_unlock_irq(&mac->lock);
1104
1105 r = zd_chip_control_leds(chip,
1106 is_associated ? LED_ASSOCIATED : LED_SCANNING);
1107 if (r)
1108 dev_err(zd_mac_dev(mac), "zd_chip_control_leds error %d\n", r);
1109
1110 queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work,
1111 LINK_LED_WORK_DELAY);
1112}
1113
1114static void housekeeping_init(struct zd_mac *mac)
1115{
1116 INIT_WORK(&mac->housekeeping.link_led_work, link_led_handler, mac);
1117}
1118
1119static void housekeeping_enable(struct zd_mac *mac)
1120{
1121 dev_dbg_f(zd_mac_dev(mac), "\n");
1122 queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work,
1123 0);
1124}
1125
1126static void housekeeping_disable(struct zd_mac *mac)
1127{
1128 dev_dbg_f(zd_mac_dev(mac), "\n");
1129 cancel_rearming_delayed_workqueue(zd_workqueue,
1130 &mac->housekeeping.link_led_work);
1131 zd_chip_control_leds(&mac->chip, LED_OFF);
1132}
diff --git a/drivers/net/wireless/zd1211rw/zd_mac.h b/drivers/net/wireless/zd1211rw/zd_mac.h
index 29b51fd7d4e5..b8ea3de7924a 100644
--- a/drivers/net/wireless/zd1211rw/zd_mac.h
+++ b/drivers/net/wireless/zd1211rw/zd_mac.h
@@ -120,6 +120,10 @@ enum mac_flags {
120 MAC_FIXED_CHANNEL = 0x01, 120 MAC_FIXED_CHANNEL = 0x01,
121}; 121};
122 122
123struct housekeeping {
124 struct work_struct link_led_work;
125};
126
123#define ZD_MAC_STATS_BUFFER_SIZE 16 127#define ZD_MAC_STATS_BUFFER_SIZE 16
124 128
125struct zd_mac { 129struct zd_mac {
@@ -128,6 +132,7 @@ struct zd_mac {
128 struct net_device *netdev; 132 struct net_device *netdev;
129 /* Unlocked reading possible */ 133 /* Unlocked reading possible */
130 struct iw_statistics iw_stats; 134 struct iw_statistics iw_stats;
135 struct housekeeping housekeeping;
131 unsigned int stats_count; 136 unsigned int stats_count;
132 u8 qual_buffer[ZD_MAC_STATS_BUFFER_SIZE]; 137 u8 qual_buffer[ZD_MAC_STATS_BUFFER_SIZE];
133 u8 rssi_buffer[ZD_MAC_STATS_BUFFER_SIZE]; 138 u8 rssi_buffer[ZD_MAC_STATS_BUFFER_SIZE];
diff --git a/drivers/net/wireless/zd1211rw/zd_netdev.c b/drivers/net/wireless/zd1211rw/zd_netdev.c
index 440ef24b5fd1..af3a7b36d078 100644
--- a/drivers/net/wireless/zd1211rw/zd_netdev.c
+++ b/drivers/net/wireless/zd1211rw/zd_netdev.c
@@ -82,7 +82,7 @@ static int iw_get_nick(struct net_device *netdev,
82 union iwreq_data *req, char *extra) 82 union iwreq_data *req, char *extra)
83{ 83{
84 strcpy(extra, "zd1211"); 84 strcpy(extra, "zd1211");
85 req->data.length = strlen(extra) + 1; 85 req->data.length = strlen(extra);
86 req->data.flags = 1; 86 req->data.flags = 1;
87 return 0; 87 return 0;
88} 88}
diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
index 31027e52b04b..5c265ad0485a 100644
--- a/drivers/net/wireless/zd1211rw/zd_usb.c
+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
@@ -24,6 +24,7 @@
24#include <linux/errno.h> 24#include <linux/errno.h>
25#include <linux/skbuff.h> 25#include <linux/skbuff.h>
26#include <linux/usb.h> 26#include <linux/usb.h>
27#include <linux/workqueue.h>
27#include <net/ieee80211.h> 28#include <net/ieee80211.h>
28 29
29#include "zd_def.h" 30#include "zd_def.h"
@@ -1112,12 +1113,20 @@ static struct usb_driver driver = {
1112 .disconnect = disconnect, 1113 .disconnect = disconnect,
1113}; 1114};
1114 1115
1116struct workqueue_struct *zd_workqueue;
1117
1115static int __init usb_init(void) 1118static int __init usb_init(void)
1116{ 1119{
1117 int r; 1120 int r;
1118 1121
1119 pr_debug("usb_init()\n"); 1122 pr_debug("usb_init()\n");
1120 1123
1124 zd_workqueue = create_singlethread_workqueue(driver.name);
1125 if (zd_workqueue == NULL) {
1126 printk(KERN_ERR "%s: couldn't create workqueue\n", driver.name);
1127 return -ENOMEM;
1128 }
1129
1121 r = usb_register(&driver); 1130 r = usb_register(&driver);
1122 if (r) { 1131 if (r) {
1123 printk(KERN_ERR "usb_register() failed. Error number %d\n", r); 1132 printk(KERN_ERR "usb_register() failed. Error number %d\n", r);
@@ -1132,6 +1141,7 @@ static void __exit usb_exit(void)
1132{ 1141{
1133 pr_debug("usb_exit()\n"); 1142 pr_debug("usb_exit()\n");
1134 usb_deregister(&driver); 1143 usb_deregister(&driver);
1144 destroy_workqueue(zd_workqueue);
1135} 1145}
1136 1146
1137module_init(usb_init); 1147module_init(usb_init);
diff --git a/drivers/net/wireless/zd1211rw/zd_usb.h b/drivers/net/wireless/zd1211rw/zd_usb.h
index ded39de5f72d..e81a2d3cfffd 100644
--- a/drivers/net/wireless/zd1211rw/zd_usb.h
+++ b/drivers/net/wireless/zd1211rw/zd_usb.h
@@ -238,4 +238,6 @@ int zd_usb_iowrite16v(struct zd_usb *usb, const struct zd_ioreq16 *ioreqs,
238 238
239int zd_usb_rfwrite(struct zd_usb *usb, u32 value, u8 bits); 239int zd_usb_rfwrite(struct zd_usb *usb, u32 value, u8 bits);
240 240
241extern struct workqueue_struct *zd_workqueue;
242
241#endif /* _ZD_USB_H */ 243#endif /* _ZD_USB_H */
diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
index 71c2da277d6e..5756401fb15b 100644
--- a/drivers/oprofile/oprofilefs.c
+++ b/drivers/oprofile/oprofilefs.c
@@ -31,7 +31,6 @@ static struct inode * oprofilefs_get_inode(struct super_block * sb, int mode)
31 inode->i_mode = mode; 31 inode->i_mode = mode;
32 inode->i_uid = 0; 32 inode->i_uid = 0;
33 inode->i_gid = 0; 33 inode->i_gid = 0;
34 inode->i_blksize = PAGE_CACHE_SIZE;
35 inode->i_blocks = 0; 34 inode->i_blocks = 0;
36 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; 35 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
37 } 36 }
@@ -110,8 +109,8 @@ static ssize_t ulong_write_file(struct file * file, char const __user * buf, siz
110 109
111static int default_open(struct inode * inode, struct file * filp) 110static int default_open(struct inode * inode, struct file * filp)
112{ 111{
113 if (inode->u.generic_ip) 112 if (inode->i_private)
114 filp->private_data = inode->u.generic_ip; 113 filp->private_data = inode->i_private;
115 return 0; 114 return 0;
116} 115}
117 116
@@ -158,7 +157,7 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
158 if (!d) 157 if (!d)
159 return -EFAULT; 158 return -EFAULT;
160 159
161 d->d_inode->u.generic_ip = val; 160 d->d_inode->i_private = val;
162 return 0; 161 return 0;
163} 162}
164 163
@@ -171,7 +170,7 @@ int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
171 if (!d) 170 if (!d)
172 return -EFAULT; 171 return -EFAULT;
173 172
174 d->d_inode->u.generic_ip = val; 173 d->d_inode->i_private = val;
175 return 0; 174 return 0;
176} 175}
177 176
@@ -197,7 +196,7 @@ int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
197 if (!d) 196 if (!d)
198 return -EFAULT; 197 return -EFAULT;
199 198
200 d->d_inode->u.generic_ip = val; 199 d->d_inode->i_private = val;
201 return 0; 200 return 0;
202} 201}
203 202
diff --git a/drivers/parisc/led.c b/drivers/parisc/led.c
index bf00fa2537bb..8dac2ba82bb9 100644
--- a/drivers/parisc/led.c
+++ b/drivers/parisc/led.c
@@ -684,7 +684,7 @@ int __init led_init(void)
684 int ret; 684 int ret;
685 685
686 snprintf(lcd_text_default, sizeof(lcd_text_default), 686 snprintf(lcd_text_default, sizeof(lcd_text_default),
687 "Linux %s", system_utsname.release); 687 "Linux %s", init_utsname()->release);
688 688
689 /* Work around the buggy PDC of KittyHawk-machines */ 689 /* Work around the buggy PDC of KittyHawk-machines */
690 switch (CPU_HVERSION) { 690 switch (CPU_HVERSION) {
diff --git a/drivers/parisc/power.c b/drivers/parisc/power.c
index fad5a33bf0fa..4a9f025a6b58 100644
--- a/drivers/parisc/power.c
+++ b/drivers/parisc/power.c
@@ -84,8 +84,7 @@
84 84
85static void deferred_poweroff(void *dummy) 85static void deferred_poweroff(void *dummy)
86{ 86{
87 extern int cad_pid; /* from kernel/sys.c */ 87 if (kill_cad_pid(SIGINT, 1)) {
88 if (kill_proc(cad_pid, SIGINT, 1)) {
89 /* just in case killing init process failed */ 88 /* just in case killing init process failed */
90 machine_power_off(); 89 machine_power_off();
91 } 90 }
diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c
index 98b83a85c60e..78c0a269a2ba 100644
--- a/drivers/parport/parport_serial.c
+++ b/drivers/parport/parport_serial.c
@@ -374,6 +374,7 @@ static void __devexit parport_serial_pci_remove (struct pci_dev *dev)
374 return; 374 return;
375} 375}
376 376
377#ifdef CONFIG_PM
377static int parport_serial_pci_suspend(struct pci_dev *dev, pm_message_t state) 378static int parport_serial_pci_suspend(struct pci_dev *dev, pm_message_t state)
378{ 379{
379 struct parport_serial_private *priv = pci_get_drvdata(dev); 380 struct parport_serial_private *priv = pci_get_drvdata(dev);
@@ -407,14 +408,17 @@ static int parport_serial_pci_resume(struct pci_dev *dev)
407 408
408 return 0; 409 return 0;
409} 410}
411#endif
410 412
411static struct pci_driver parport_serial_pci_driver = { 413static struct pci_driver parport_serial_pci_driver = {
412 .name = "parport_serial", 414 .name = "parport_serial",
413 .id_table = parport_serial_pci_tbl, 415 .id_table = parport_serial_pci_tbl,
414 .probe = parport_serial_pci_probe, 416 .probe = parport_serial_pci_probe,
415 .remove = __devexit_p(parport_serial_pci_remove), 417 .remove = __devexit_p(parport_serial_pci_remove),
418#ifdef CONFIG_PM
416 .suspend = parport_serial_pci_suspend, 419 .suspend = parport_serial_pci_suspend,
417 .resume = parport_serial_pci_resume, 420 .resume = parport_serial_pci_resume,
421#endif
418}; 422};
419 423
420 424
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 4d762fc4878c..c27e782e6df9 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -17,6 +17,31 @@ config PCI_MSI
17 17
18 If you don't know what to do here, say N. 18 If you don't know what to do here, say N.
19 19
20config PCI_MULTITHREAD_PROBE
21 bool "PCI Multi-threaded probe (EXPERIMENTAL)"
22 depends on PCI && EXPERIMENTAL
23 help
24 Say Y here if you want the PCI core to spawn a new thread for
25 every PCI device that is probed. This can cause a huge
26 speedup in boot times on multiprocessor machines, and even a
27 smaller speedup on single processor machines.
28
29 But it can also cause lots of bad things to happen. A number
30 of PCI drivers can not properly handle running in this way,
31 some will just not work properly at all, while others might
32 decide to blow up power supplies with a huge load all at once,
33 so use this option at your own risk.
34
35 It is very unwise to use this option if you are not using a
36 boot process that can handle devices being created in any
37 order. A program that can create persistant block and network
38 device names (like udev) is a good idea if you wish to use
39 this option.
40
41 Again, use this option at your own risk, you have been warned!
42
43 When in doubt, say N.
44
20config PCI_DEBUG 45config PCI_DEBUG
21 bool "PCI Debugging" 46 bool "PCI Debugging"
22 depends on PCI && DEBUG_KERNEL 47 depends on PCI && DEBUG_KERNEL
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 5f7db9d2436e..aadaa3c8096b 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -77,9 +77,12 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
77 * This adds a single pci device to the global 77 * This adds a single pci device to the global
78 * device list and adds sysfs and procfs entries 78 * device list and adds sysfs and procfs entries
79 */ 79 */
80void __devinit pci_bus_add_device(struct pci_dev *dev) 80int __devinit pci_bus_add_device(struct pci_dev *dev)
81{ 81{
82 device_add(&dev->dev); 82 int retval;
83 retval = device_add(&dev->dev);
84 if (retval)
85 return retval;
83 86
84 down_write(&pci_bus_sem); 87 down_write(&pci_bus_sem);
85 list_add_tail(&dev->global_list, &pci_devices); 88 list_add_tail(&dev->global_list, &pci_devices);
@@ -87,6 +90,7 @@ void __devinit pci_bus_add_device(struct pci_dev *dev)
87 90
88 pci_proc_attach_device(dev); 91 pci_proc_attach_device(dev);
89 pci_create_sysfs_dev_files(dev); 92 pci_create_sysfs_dev_files(dev);
93 return 0;
90} 94}
91 95
92/** 96/**
@@ -104,6 +108,7 @@ void __devinit pci_bus_add_device(struct pci_dev *dev)
104void __devinit pci_bus_add_devices(struct pci_bus *bus) 108void __devinit pci_bus_add_devices(struct pci_bus *bus)
105{ 109{
106 struct pci_dev *dev; 110 struct pci_dev *dev;
111 int retval;
107 112
108 list_for_each_entry(dev, &bus->devices, bus_list) { 113 list_for_each_entry(dev, &bus->devices, bus_list) {
109 /* 114 /*
@@ -112,7 +117,9 @@ void __devinit pci_bus_add_devices(struct pci_bus *bus)
112 */ 117 */
113 if (!list_empty(&dev->global_list)) 118 if (!list_empty(&dev->global_list))
114 continue; 119 continue;
115 pci_bus_add_device(dev); 120 retval = pci_bus_add_device(dev);
121 if (retval)
122 dev_err(&dev->dev, "Error adding device, continuing\n");
116 } 123 }
117 124
118 list_for_each_entry(dev, &bus->devices, bus_list) { 125 list_for_each_entry(dev, &bus->devices, bus_list) {
@@ -129,10 +136,13 @@ void __devinit pci_bus_add_devices(struct pci_bus *bus)
129 list_add_tail(&dev->subordinate->node, 136 list_add_tail(&dev->subordinate->node,
130 &dev->bus->children); 137 &dev->bus->children);
131 up_write(&pci_bus_sem); 138 up_write(&pci_bus_sem);
132 } 139 }
133 pci_bus_add_devices(dev->subordinate); 140 pci_bus_add_devices(dev->subordinate);
134 141 retval = sysfs_create_link(&dev->subordinate->class_dev.kobj,
135 sysfs_create_link(&dev->subordinate->class_dev.kobj, &dev->dev.kobj, "bridge"); 142 &dev->dev.kobj, "bridge");
143 if (retval)
144 dev_err(&dev->dev, "Error creating sysfs "
145 "bridge symlink, continuing...\n");
136 } 146 }
137 } 147 }
138} 148}
diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h
index be104eced34c..7fff07e877c7 100644
--- a/drivers/pci/hotplug/acpiphp.h
+++ b/drivers/pci/hotplug/acpiphp.h
@@ -150,6 +150,11 @@ struct acpiphp_attention_info
150 struct module *owner; 150 struct module *owner;
151}; 151};
152 152
153struct acpiphp_ioapic {
154 struct pci_dev *dev;
155 u32 gsi_base;
156 struct list_head list;
157};
153 158
154/* PCI bus bridge HID */ 159/* PCI bus bridge HID */
155#define ACPI_PCI_HOST_HID "PNP0A03" 160#define ACPI_PCI_HOST_HID "PNP0A03"
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index ae67a8f55ba1..83e8e4412de5 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -53,6 +53,8 @@
53#include "acpiphp.h" 53#include "acpiphp.h"
54 54
55static LIST_HEAD(bridge_list); 55static LIST_HEAD(bridge_list);
56static LIST_HEAD(ioapic_list);
57static DEFINE_SPINLOCK(ioapic_list_lock);
56 58
57#define MY_NAME "acpiphp_glue" 59#define MY_NAME "acpiphp_glue"
58 60
@@ -797,6 +799,7 @@ ioapic_add(acpi_handle handle, u32 lvl, void *context, void **rv)
797 struct pci_dev *pdev; 799 struct pci_dev *pdev;
798 u32 gsi_base; 800 u32 gsi_base;
799 u64 phys_addr; 801 u64 phys_addr;
802 struct acpiphp_ioapic *ioapic;
800 803
801 /* Evaluate _STA if present */ 804 /* Evaluate _STA if present */
802 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); 805 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
@@ -811,41 +814,107 @@ ioapic_add(acpi_handle handle, u32 lvl, void *context, void **rv)
811 if (get_gsi_base(handle, &gsi_base)) 814 if (get_gsi_base(handle, &gsi_base))
812 return AE_OK; 815 return AE_OK;
813 816
817 ioapic = kmalloc(sizeof(*ioapic), GFP_KERNEL);
818 if (!ioapic)
819 return AE_NO_MEMORY;
820
814 pdev = get_apic_pci_info(handle); 821 pdev = get_apic_pci_info(handle);
815 if (!pdev) 822 if (!pdev)
816 return AE_OK; 823 goto exit_kfree;
817 824
818 if (pci_enable_device(pdev)) { 825 if (pci_enable_device(pdev))
819 pci_dev_put(pdev); 826 goto exit_pci_dev_put;
820 return AE_OK;
821 }
822 827
823 pci_set_master(pdev); 828 pci_set_master(pdev);
824 829
825 if (pci_request_region(pdev, 0, "I/O APIC(acpiphp)")) { 830 if (pci_request_region(pdev, 0, "I/O APIC(acpiphp)"))
826 pci_disable_device(pdev); 831 goto exit_pci_disable_device;
827 pci_dev_put(pdev);
828 return AE_OK;
829 }
830 832
831 phys_addr = pci_resource_start(pdev, 0); 833 phys_addr = pci_resource_start(pdev, 0);
832 if (acpi_register_ioapic(handle, phys_addr, gsi_base)) { 834 if (acpi_register_ioapic(handle, phys_addr, gsi_base))
833 pci_release_region(pdev, 0); 835 goto exit_pci_release_region;
834 pci_disable_device(pdev); 836
835 pci_dev_put(pdev); 837 ioapic->gsi_base = gsi_base;
838 ioapic->dev = pdev;
839 spin_lock(&ioapic_list_lock);
840 list_add_tail(&ioapic->list, &ioapic_list);
841 spin_unlock(&ioapic_list_lock);
842
843 return AE_OK;
844
845 exit_pci_release_region:
846 pci_release_region(pdev, 0);
847 exit_pci_disable_device:
848 pci_disable_device(pdev);
849 exit_pci_dev_put:
850 pci_dev_put(pdev);
851 exit_kfree:
852 kfree(ioapic);
853
854 return AE_OK;
855}
856
857static acpi_status
858ioapic_remove(acpi_handle handle, u32 lvl, void *context, void **rv)
859{
860 acpi_status status;
861 unsigned long sta;
862 acpi_handle tmp;
863 u32 gsi_base;
864 struct acpiphp_ioapic *pos, *n, *ioapic = NULL;
865
866 /* Evaluate _STA if present */
867 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
868 if (ACPI_SUCCESS(status) && sta != ACPI_STA_ALL)
869 return AE_CTRL_DEPTH;
870
871 /* Scan only PCI bus scope */
872 status = acpi_get_handle(handle, "_HID", &tmp);
873 if (ACPI_SUCCESS(status))
874 return AE_CTRL_DEPTH;
875
876 if (get_gsi_base(handle, &gsi_base))
836 return AE_OK; 877 return AE_OK;
878
879 acpi_unregister_ioapic(handle, gsi_base);
880
881 spin_lock(&ioapic_list_lock);
882 list_for_each_entry_safe(pos, n, &ioapic_list, list) {
883 if (pos->gsi_base != gsi_base)
884 continue;
885 ioapic = pos;
886 list_del(&ioapic->list);
887 break;
837 } 888 }
889 spin_unlock(&ioapic_list_lock);
890
891 if (!ioapic)
892 return AE_OK;
893
894 pci_release_region(ioapic->dev, 0);
895 pci_disable_device(ioapic->dev);
896 pci_dev_put(ioapic->dev);
897 kfree(ioapic);
838 898
839 return AE_OK; 899 return AE_OK;
840} 900}
841 901
842static int acpiphp_configure_ioapics(acpi_handle handle) 902static int acpiphp_configure_ioapics(acpi_handle handle)
843{ 903{
904 ioapic_add(handle, 0, NULL, NULL);
844 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 905 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
845 ACPI_UINT32_MAX, ioapic_add, NULL, NULL); 906 ACPI_UINT32_MAX, ioapic_add, NULL, NULL);
846 return 0; 907 return 0;
847} 908}
848 909
910static int acpiphp_unconfigure_ioapics(acpi_handle handle)
911{
912 ioapic_remove(handle, 0, NULL, NULL);
913 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
914 ACPI_UINT32_MAX, ioapic_remove, NULL, NULL);
915 return 0;
916}
917
849static int power_on_slot(struct acpiphp_slot *slot) 918static int power_on_slot(struct acpiphp_slot *slot)
850{ 919{
851 acpi_status status; 920 acpi_status status;
@@ -997,7 +1066,7 @@ acpiphp_bus_add_out:
997 * @handle: handle to acpi namespace 1066 * @handle: handle to acpi namespace
998 * 1067 *
999 */ 1068 */
1000int acpiphp_bus_trim(acpi_handle handle) 1069static int acpiphp_bus_trim(acpi_handle handle)
1001{ 1070{
1002 struct acpi_device *device; 1071 struct acpi_device *device;
1003 int retval; 1072 int retval;
@@ -1074,10 +1143,11 @@ static int enable_device(struct acpiphp_slot *slot)
1074 1143
1075 pci_bus_assign_resources(bus); 1144 pci_bus_assign_resources(bus);
1076 acpiphp_sanitize_bus(bus); 1145 acpiphp_sanitize_bus(bus);
1146 acpiphp_set_hpp_values(slot->bridge->handle, bus);
1147 list_for_each_entry(func, &slot->funcs, sibling)
1148 acpiphp_configure_ioapics(func->handle);
1077 pci_enable_bridges(bus); 1149 pci_enable_bridges(bus);
1078 pci_bus_add_devices(bus); 1150 pci_bus_add_devices(bus);
1079 acpiphp_set_hpp_values(slot->bridge->handle, bus);
1080 acpiphp_configure_ioapics(slot->bridge->handle);
1081 1151
1082 /* associate pci_dev to our representation */ 1152 /* associate pci_dev to our representation */
1083 list_for_each (l, &slot->funcs) { 1153 list_for_each (l, &slot->funcs) {
@@ -1103,6 +1173,16 @@ static int enable_device(struct acpiphp_slot *slot)
1103 return retval; 1173 return retval;
1104} 1174}
1105 1175
1176static void disable_bridges(struct pci_bus *bus)
1177{
1178 struct pci_dev *dev;
1179 list_for_each_entry(dev, &bus->devices, bus_list) {
1180 if (dev->subordinate) {
1181 disable_bridges(dev->subordinate);
1182 pci_disable_device(dev);
1183 }
1184 }
1185}
1106 1186
1107/** 1187/**
1108 * disable_device - disable a slot 1188 * disable_device - disable a slot
@@ -1127,6 +1207,19 @@ static int disable_device(struct acpiphp_slot *slot)
1127 func->bridge = NULL; 1207 func->bridge = NULL;
1128 } 1208 }
1129 1209
1210 if (func->pci_dev) {
1211 pci_stop_bus_device(func->pci_dev);
1212 if (func->pci_dev->subordinate) {
1213 disable_bridges(func->pci_dev->subordinate);
1214 pci_disable_device(func->pci_dev);
1215 }
1216 }
1217 }
1218
1219 list_for_each (l, &slot->funcs) {
1220 func = list_entry(l, struct acpiphp_func, sibling);
1221
1222 acpiphp_unconfigure_ioapics(func->handle);
1130 acpiphp_bus_trim(func->handle); 1223 acpiphp_bus_trim(func->handle);
1131 /* try to remove anyway. 1224 /* try to remove anyway.
1132 * acpiphp_bus_add might have been failed */ 1225 * acpiphp_bus_add might have been failed */
diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
index 317457dd4014..d0a07d9ab30c 100644
--- a/drivers/pci/hotplug/acpiphp_ibm.c
+++ b/drivers/pci/hotplug/acpiphp_ibm.c
@@ -487,9 +487,7 @@ static void __exit ibm_acpiphp_exit(void)
487 if (ACPI_FAILURE(status)) 487 if (ACPI_FAILURE(status))
488 err("%s: Notification handler removal failed\n", __FUNCTION__); 488 err("%s: Notification handler removal failed\n", __FUNCTION__);
489 /* remove the /sys entries */ 489 /* remove the /sys entries */
490 if (sysfs_remove_bin_file(sysdir, &ibm_apci_table_attr)) 490 sysfs_remove_bin_file(sysdir, &ibm_apci_table_attr);
491 err("%s: removal of sysfs file apci_table failed\n",
492 __FUNCTION__);
493} 491}
494 492
495module_init(ibm_acpiphp_init); 493module_init(ibm_acpiphp_init);
diff --git a/drivers/pci/hotplug/cpqphp_sysfs.c b/drivers/pci/hotplug/cpqphp_sysfs.c
index 8b3da007e859..5bab666cd67e 100644
--- a/drivers/pci/hotplug/cpqphp_sysfs.c
+++ b/drivers/pci/hotplug/cpqphp_sysfs.c
@@ -140,7 +140,7 @@ struct ctrl_dbg {
140 140
141static int open(struct inode *inode, struct file *file) 141static int open(struct inode *inode, struct file *file)
142{ 142{
143 struct controller *ctrl = inode->u.generic_ip; 143 struct controller *ctrl = inode->i_private;
144 struct ctrl_dbg *dbg; 144 struct ctrl_dbg *dbg;
145 int retval = -ENOMEM; 145 int retval = -ENOMEM;
146 146
diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
index dd2b762777c4..05a4f0f90186 100644
--- a/drivers/pci/hotplug/fakephp.c
+++ b/drivers/pci/hotplug/fakephp.c
@@ -176,7 +176,9 @@ static void pci_rescan_slot(struct pci_dev *temp)
176 struct pci_bus *bus = temp->bus; 176 struct pci_bus *bus = temp->bus;
177 struct pci_dev *dev; 177 struct pci_dev *dev;
178 int func; 178 int func;
179 int retval;
179 u8 hdr_type; 180 u8 hdr_type;
181
180 if (!pci_read_config_byte(temp, PCI_HEADER_TYPE, &hdr_type)) { 182 if (!pci_read_config_byte(temp, PCI_HEADER_TYPE, &hdr_type)) {
181 temp->hdr_type = hdr_type & 0x7f; 183 temp->hdr_type = hdr_type & 0x7f;
182 if (!pci_find_slot(bus->number, temp->devfn)) { 184 if (!pci_find_slot(bus->number, temp->devfn)) {
@@ -185,8 +187,12 @@ static void pci_rescan_slot(struct pci_dev *temp)
185 dbg("New device on %s function %x:%x\n", 187 dbg("New device on %s function %x:%x\n",
186 bus->name, temp->devfn >> 3, 188 bus->name, temp->devfn >> 3,
187 temp->devfn & 7); 189 temp->devfn & 7);
188 pci_bus_add_device(dev); 190 retval = pci_bus_add_device(dev);
189 add_slot(dev); 191 if (retval)
192 dev_err(&dev->dev, "error adding "
193 "device, continuing.\n");
194 else
195 add_slot(dev);
190 } 196 }
191 } 197 }
192 /* multifunction device? */ 198 /* multifunction device? */
@@ -205,8 +211,12 @@ static void pci_rescan_slot(struct pci_dev *temp)
205 dbg("New device on %s function %x:%x\n", 211 dbg("New device on %s function %x:%x\n",
206 bus->name, temp->devfn >> 3, 212 bus->name, temp->devfn >> 3,
207 temp->devfn & 7); 213 temp->devfn & 7);
208 pci_bus_add_device(dev); 214 retval = pci_bus_add_device(dev);
209 add_slot(dev); 215 if (retval)
216 dev_err(&dev->dev, "error adding "
217 "device, continuing.\n");
218 else
219 add_slot(dev);
210 } 220 }
211 } 221 }
212 } 222 }
diff --git a/drivers/pci/hotplug/pci_hotplug.h b/drivers/pci/hotplug/pci_hotplug.h
index e929b7c11429..772523dc3860 100644
--- a/drivers/pci/hotplug/pci_hotplug.h
+++ b/drivers/pci/hotplug/pci_hotplug.h
@@ -172,8 +172,8 @@ struct hotplug_slot {
172 172
173extern int pci_hp_register (struct hotplug_slot *slot); 173extern int pci_hp_register (struct hotplug_slot *slot);
174extern int pci_hp_deregister (struct hotplug_slot *slot); 174extern int pci_hp_deregister (struct hotplug_slot *slot);
175extern int pci_hp_change_slot_info (struct hotplug_slot *slot, 175extern int __must_check pci_hp_change_slot_info (struct hotplug_slot *slot,
176 struct hotplug_slot_info *info); 176 struct hotplug_slot_info *info);
177extern struct subsystem pci_hotplug_slots_subsys; 177extern struct subsystem pci_hotplug_slots_subsys;
178 178
179/* PCI Setting Record (Type 0) */ 179/* PCI Setting Record (Type 0) */
diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
index b7b378df89e3..e2823ea9c4ed 100644
--- a/drivers/pci/hotplug/pci_hotplug_core.c
+++ b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -482,31 +482,95 @@ static int has_test_file (struct hotplug_slot *slot)
482 482
483static int fs_add_slot (struct hotplug_slot *slot) 483static int fs_add_slot (struct hotplug_slot *slot)
484{ 484{
485 if (has_power_file(slot) == 0) 485 int retval = 0;
486 sysfs_create_file(&slot->kobj, &hotplug_slot_attr_power.attr);
487 486
488 if (has_attention_file(slot) == 0) 487 if (has_power_file(slot) == 0) {
489 sysfs_create_file(&slot->kobj, &hotplug_slot_attr_attention.attr); 488 retval = sysfs_create_file(&slot->kobj, &hotplug_slot_attr_power.attr);
489 if (retval)
490 goto exit_power;
491 }
490 492
491 if (has_latch_file(slot) == 0) 493 if (has_attention_file(slot) == 0) {
492 sysfs_create_file(&slot->kobj, &hotplug_slot_attr_latch.attr); 494 retval = sysfs_create_file(&slot->kobj,
495 &hotplug_slot_attr_attention.attr);
496 if (retval)
497 goto exit_attention;
498 }
493 499
494 if (has_adapter_file(slot) == 0) 500 if (has_latch_file(slot) == 0) {
495 sysfs_create_file(&slot->kobj, &hotplug_slot_attr_presence.attr); 501 retval = sysfs_create_file(&slot->kobj,
502 &hotplug_slot_attr_latch.attr);
503 if (retval)
504 goto exit_latch;
505 }
496 506
497 if (has_address_file(slot) == 0) 507 if (has_adapter_file(slot) == 0) {
498 sysfs_create_file(&slot->kobj, &hotplug_slot_attr_address.attr); 508 retval = sysfs_create_file(&slot->kobj,
509 &hotplug_slot_attr_presence.attr);
510 if (retval)
511 goto exit_adapter;
512 }
499 513
500 if (has_max_bus_speed_file(slot) == 0) 514 if (has_address_file(slot) == 0) {
501 sysfs_create_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr); 515 retval = sysfs_create_file(&slot->kobj,
516 &hotplug_slot_attr_address.attr);
517 if (retval)
518 goto exit_address;
519 }
502 520
521 if (has_max_bus_speed_file(slot) == 0) {
522 retval = sysfs_create_file(&slot->kobj,
523 &hotplug_slot_attr_max_bus_speed.attr);
524 if (retval)
525 goto exit_max_speed;
526 }
527
528 if (has_cur_bus_speed_file(slot) == 0) {
529 retval = sysfs_create_file(&slot->kobj,
530 &hotplug_slot_attr_cur_bus_speed.attr);
531 if (retval)
532 goto exit_cur_speed;
533 }
534
535 if (has_test_file(slot) == 0) {
536 retval = sysfs_create_file(&slot->kobj,
537 &hotplug_slot_attr_test.attr);
538 if (retval)
539 goto exit_test;
540 }
541
542 goto exit;
543
544exit_test:
503 if (has_cur_bus_speed_file(slot) == 0) 545 if (has_cur_bus_speed_file(slot) == 0)
504 sysfs_create_file(&slot->kobj, &hotplug_slot_attr_cur_bus_speed.attr); 546 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_cur_bus_speed.attr);
505 547
506 if (has_test_file(slot) == 0) 548exit_cur_speed:
507 sysfs_create_file(&slot->kobj, &hotplug_slot_attr_test.attr); 549 if (has_max_bus_speed_file(slot) == 0)
550 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr);
508 551
509 return 0; 552exit_max_speed:
553 if (has_address_file(slot) == 0)
554 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_address.attr);
555
556exit_address:
557 if (has_adapter_file(slot) == 0)
558 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_presence.attr);
559
560exit_adapter:
561 if (has_latch_file(slot) == 0)
562 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_latch.attr);
563
564exit_latch:
565 if (has_attention_file(slot) == 0)
566 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_attention.attr);
567
568exit_attention:
569 if (has_power_file(slot) == 0)
570 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_power.attr);
571exit_power:
572exit:
573 return retval;
510} 574}
511 575
512static void fs_remove_slot (struct hotplug_slot *slot) 576static void fs_remove_slot (struct hotplug_slot *slot)
@@ -626,8 +690,11 @@ int pci_hp_deregister (struct hotplug_slot *slot)
626 * 690 *
627 * Returns 0 if successful, anything else for an error. 691 * Returns 0 if successful, anything else for an error.
628 */ 692 */
629int pci_hp_change_slot_info (struct hotplug_slot *slot, struct hotplug_slot_info *info) 693int __must_check pci_hp_change_slot_info(struct hotplug_slot *slot,
694 struct hotplug_slot_info *info)
630{ 695{
696 int retval;
697
631 if ((slot == NULL) || (info == NULL)) 698 if ((slot == NULL) || (info == NULL))
632 return -ENODEV; 699 return -ENODEV;
633 700
@@ -636,32 +703,60 @@ int pci_hp_change_slot_info (struct hotplug_slot *slot, struct hotplug_slot_info
636 * for the files referring to the fields that have now changed. 703 * for the files referring to the fields that have now changed.
637 */ 704 */
638 if ((has_power_file(slot) == 0) && 705 if ((has_power_file(slot) == 0) &&
639 (slot->info->power_status != info->power_status)) 706 (slot->info->power_status != info->power_status)) {
640 sysfs_update_file(&slot->kobj, &hotplug_slot_attr_power.attr); 707 retval = sysfs_update_file(&slot->kobj,
708 &hotplug_slot_attr_power.attr);
709 if (retval)
710 return retval;
711 }
641 712
642 if ((has_attention_file(slot) == 0) && 713 if ((has_attention_file(slot) == 0) &&
643 (slot->info->attention_status != info->attention_status)) 714 (slot->info->attention_status != info->attention_status)) {
644 sysfs_update_file(&slot->kobj, &hotplug_slot_attr_attention.attr); 715 retval = sysfs_update_file(&slot->kobj,
716 &hotplug_slot_attr_attention.attr);
717 if (retval)
718 return retval;
719 }
645 720
646 if ((has_latch_file(slot) == 0) && 721 if ((has_latch_file(slot) == 0) &&
647 (slot->info->latch_status != info->latch_status)) 722 (slot->info->latch_status != info->latch_status)) {
648 sysfs_update_file(&slot->kobj, &hotplug_slot_attr_latch.attr); 723 retval = sysfs_update_file(&slot->kobj,
724 &hotplug_slot_attr_latch.attr);
725 if (retval)
726 return retval;
727 }
649 728
650 if ((has_adapter_file(slot) == 0) && 729 if ((has_adapter_file(slot) == 0) &&
651 (slot->info->adapter_status != info->adapter_status)) 730 (slot->info->adapter_status != info->adapter_status)) {
652 sysfs_update_file(&slot->kobj, &hotplug_slot_attr_presence.attr); 731 retval = sysfs_update_file(&slot->kobj,
732 &hotplug_slot_attr_presence.attr);
733 if (retval)
734 return retval;
735 }
653 736
654 if ((has_address_file(slot) == 0) && 737 if ((has_address_file(slot) == 0) &&
655 (slot->info->address != info->address)) 738 (slot->info->address != info->address)) {
656 sysfs_update_file(&slot->kobj, &hotplug_slot_attr_address.attr); 739 retval = sysfs_update_file(&slot->kobj,
740 &hotplug_slot_attr_address.attr);
741 if (retval)
742 return retval;
743 }
657 744
658 if ((has_max_bus_speed_file(slot) == 0) && 745 if ((has_max_bus_speed_file(slot) == 0) &&
659 (slot->info->max_bus_speed != info->max_bus_speed)) 746 (slot->info->max_bus_speed != info->max_bus_speed)) {
660 sysfs_update_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr); 747 retval = sysfs_update_file(&slot->kobj,
748 &hotplug_slot_attr_max_bus_speed.attr);
749 if (retval)
750 return retval;
751 }
661 752
662 if ((has_cur_bus_speed_file(slot) == 0) && 753 if ((has_cur_bus_speed_file(slot) == 0) &&
663 (slot->info->cur_bus_speed != info->cur_bus_speed)) 754 (slot->info->cur_bus_speed != info->cur_bus_speed)) {
664 sysfs_update_file(&slot->kobj, &hotplug_slot_attr_cur_bus_speed.attr); 755 retval = sysfs_update_file(&slot->kobj,
756 &hotplug_slot_attr_cur_bus_speed.attr);
757 if (retval)
758 return retval;
759 }
665 760
666 memcpy (slot->info, info, sizeof (struct hotplug_slot_info)); 761 memcpy (slot->info, info, sizeof (struct hotplug_slot_info));
667 762
diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c
index 33d198768356..41290a106bd8 100644
--- a/drivers/pci/hotplug/pciehp_ctrl.c
+++ b/drivers/pci/hotplug/pciehp_ctrl.c
@@ -762,14 +762,14 @@ int pciehp_enable_slot(struct slot *p_slot)
762 if (rc || !getstatus) { 762 if (rc || !getstatus) {
763 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number); 763 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
764 mutex_unlock(&p_slot->ctrl->crit_sect); 764 mutex_unlock(&p_slot->ctrl->crit_sect);
765 return 1; 765 return -ENODEV;
766 } 766 }
767 if (MRL_SENS(p_slot->ctrl->ctrlcap)) { 767 if (MRL_SENS(p_slot->ctrl->ctrlcap)) {
768 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 768 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
769 if (rc || getstatus) { 769 if (rc || getstatus) {
770 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number); 770 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
771 mutex_unlock(&p_slot->ctrl->crit_sect); 771 mutex_unlock(&p_slot->ctrl->crit_sect);
772 return 1; 772 return -ENODEV;
773 } 773 }
774 } 774 }
775 775
@@ -778,7 +778,7 @@ int pciehp_enable_slot(struct slot *p_slot)
778 if (rc || getstatus) { 778 if (rc || getstatus) {
779 info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number); 779 info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number);
780 mutex_unlock(&p_slot->ctrl->crit_sect); 780 mutex_unlock(&p_slot->ctrl->crit_sect);
781 return 1; 781 return -EINVAL;
782 } 782 }
783 } 783 }
784 mutex_unlock(&p_slot->ctrl->crit_sect); 784 mutex_unlock(&p_slot->ctrl->crit_sect);
@@ -813,7 +813,7 @@ int pciehp_disable_slot(struct slot *p_slot)
813 if (ret || !getstatus) { 813 if (ret || !getstatus) {
814 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number); 814 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
815 mutex_unlock(&p_slot->ctrl->crit_sect); 815 mutex_unlock(&p_slot->ctrl->crit_sect);
816 return 1; 816 return -ENODEV;
817 } 817 }
818 } 818 }
819 819
@@ -822,7 +822,7 @@ int pciehp_disable_slot(struct slot *p_slot)
822 if (ret || getstatus) { 822 if (ret || getstatus) {
823 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number); 823 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
824 mutex_unlock(&p_slot->ctrl->crit_sect); 824 mutex_unlock(&p_slot->ctrl->crit_sect);
825 return 1; 825 return -ENODEV;
826 } 826 }
827 } 827 }
828 828
@@ -831,7 +831,7 @@ int pciehp_disable_slot(struct slot *p_slot)
831 if (ret || !getstatus) { 831 if (ret || !getstatus) {
832 info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number); 832 info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number);
833 mutex_unlock(&p_slot->ctrl->crit_sect); 833 mutex_unlock(&p_slot->ctrl->crit_sect);
834 return 1; 834 return -EINVAL;
835 } 835 }
836 } 836 }
837 837
diff --git a/drivers/pci/hotplug/pcihp_skeleton.c b/drivers/pci/hotplug/pcihp_skeleton.c
index 8ad446605f75..2b9e10e38613 100644
--- a/drivers/pci/hotplug/pcihp_skeleton.c
+++ b/drivers/pci/hotplug/pcihp_skeleton.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * PCI Hot Plug Controller Skeleton Driver - 0.2 2 * PCI Hot Plug Controller Skeleton Driver - 0.3
3 * 3 *
4 * Copyright (C) 2001,2003 Greg Kroah-Hartman (greg@kroah.com) 4 * Copyright (C) 2001,2003 Greg Kroah-Hartman (greg@kroah.com)
5 * Copyright (C) 2001,2003 IBM Corp. 5 * Copyright (C) 2001,2003 IBM Corp.
@@ -21,7 +21,7 @@
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., 675 Mass Ave, Cambridge, MA 02139, USA. 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * 23 *
24 * This driver is to be used as a skeleton driver to be show how to interface 24 * This driver is to be used as a skeleton driver to show how to interface
25 * with the pci hotplug core easily. 25 * with the pci hotplug core easily.
26 * 26 *
27 * Send feedback to <greg@kroah.com> 27 * Send feedback to <greg@kroah.com>
@@ -58,8 +58,6 @@ static LIST_HEAD(slot_list);
58#define info(format, arg...) printk(KERN_INFO "%s: " format "\n", MY_NAME , ## arg) 58#define info(format, arg...) printk(KERN_INFO "%s: " format "\n", MY_NAME , ## arg)
59#define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n", MY_NAME , ## arg) 59#define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n", MY_NAME , ## arg)
60 60
61
62
63/* local variables */ 61/* local variables */
64static int debug; 62static int debug;
65static int num_slots; 63static int num_slots;
@@ -109,7 +107,6 @@ static int enable_slot(struct hotplug_slot *hotplug_slot)
109 return retval; 107 return retval;
110} 108}
111 109
112
113static int disable_slot(struct hotplug_slot *hotplug_slot) 110static int disable_slot(struct hotplug_slot *hotplug_slot)
114{ 111{
115 struct slot *slot = hotplug_slot->private; 112 struct slot *slot = hotplug_slot->private;
@@ -342,7 +339,7 @@ static int __init pcihp_skel_init(void)
342 info(DRIVER_DESC " version: " DRIVER_VERSION "\n"); 339 info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
343 /* 340 /*
344 * Do specific initialization stuff for your driver here 341 * Do specific initialization stuff for your driver here
345 * Like initializing your controller hardware (if any) and 342 * like initializing your controller hardware (if any) and
346 * determining the number of slots you have in the system 343 * determining the number of slots you have in the system
347 * right now. 344 * right now.
348 */ 345 */
diff --git a/drivers/pci/hotplug/shpchp.h b/drivers/pci/hotplug/shpchp.h
index 7208b95c6ee7..c7103ac5cd06 100644
--- a/drivers/pci/hotplug/shpchp.h
+++ b/drivers/pci/hotplug/shpchp.h
@@ -173,7 +173,7 @@ struct controller {
173#define msg_button_cancel "PCI slot #%s - action canceled due to button press.\n" 173#define msg_button_cancel "PCI slot #%s - action canceled due to button press.\n"
174 174
175/* sysfs functions for the hotplug controller info */ 175/* sysfs functions for the hotplug controller info */
176extern void shpchp_create_ctrl_files (struct controller *ctrl); 176extern int __must_check shpchp_create_ctrl_files(struct controller *ctrl);
177 177
178extern int shpchp_sysfs_enable_slot(struct slot *slot); 178extern int shpchp_sysfs_enable_slot(struct slot *slot);
179extern int shpchp_sysfs_disable_slot(struct slot *slot); 179extern int shpchp_sysfs_disable_slot(struct slot *slot);
diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c
index a14e7de19846..235c18a22393 100644
--- a/drivers/pci/hotplug/shpchp_core.c
+++ b/drivers/pci/hotplug/shpchp_core.c
@@ -449,10 +449,14 @@ static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
449 ctrl->speed = PCI_SPEED_33MHz; 449 ctrl->speed = PCI_SPEED_33MHz;
450 } 450 }
451 451
452 shpchp_create_ctrl_files(ctrl); 452 rc = shpchp_create_ctrl_files(ctrl);
453 if (rc)
454 goto err_cleanup_slots;
453 455
454 return 0; 456 return 0;
455 457
458err_cleanup_slots:
459 cleanup_slots(ctrl);
456err_out_release_ctlr: 460err_out_release_ctlr:
457 ctrl->hpc_ops->release_ctlr(ctrl); 461 ctrl->hpc_ops->release_ctlr(ctrl);
458err_out_free_ctrl: 462err_out_free_ctrl:
diff --git a/drivers/pci/hotplug/shpchp_sysfs.c b/drivers/pci/hotplug/shpchp_sysfs.c
index 620e1139e607..29fa9d26adae 100644
--- a/drivers/pci/hotplug/shpchp_sysfs.c
+++ b/drivers/pci/hotplug/shpchp_sysfs.c
@@ -91,9 +91,9 @@ static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, cha
91} 91}
92static DEVICE_ATTR (ctrl, S_IRUGO, show_ctrl, NULL); 92static DEVICE_ATTR (ctrl, S_IRUGO, show_ctrl, NULL);
93 93
94void shpchp_create_ctrl_files (struct controller *ctrl) 94int __must_check shpchp_create_ctrl_files (struct controller *ctrl)
95{ 95{
96 device_create_file (&ctrl->pci_dev->dev, &dev_attr_ctrl); 96 return device_create_file (&ctrl->pci_dev->dev, &dev_attr_ctrl);
97} 97}
98 98
99void shpchp_remove_ctrl_files(struct controller *ctrl) 99void shpchp_remove_ctrl_files(struct controller *ctrl)
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index a83c1f5735d6..27a057409eca 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -45,16 +45,10 @@ msi_register(struct msi_ops *ops)
45 return 0; 45 return 0;
46} 46}
47 47
48static void msi_cache_ctor(void *p, kmem_cache_t *cache, unsigned long flags)
49{
50 memset(p, 0, sizeof(struct msi_desc));
51}
52
53static int msi_cache_init(void) 48static int msi_cache_init(void)
54{ 49{
55 msi_cachep = kmem_cache_create("msi_cache", 50 msi_cachep = kmem_cache_create("msi_cache", sizeof(struct msi_desc),
56 sizeof(struct msi_desc), 51 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
57 0, SLAB_HWCACHE_ALIGN, msi_cache_ctor, NULL);
58 if (!msi_cachep) 52 if (!msi_cachep)
59 return -ENOMEM; 53 return -ENOMEM;
60 54
@@ -402,11 +396,10 @@ static struct msi_desc* alloc_msi_entry(void)
402{ 396{
403 struct msi_desc *entry; 397 struct msi_desc *entry;
404 398
405 entry = kmem_cache_alloc(msi_cachep, SLAB_KERNEL); 399 entry = kmem_cache_zalloc(msi_cachep, GFP_KERNEL);
406 if (!entry) 400 if (!entry)
407 return NULL; 401 return NULL;
408 402
409 memset(entry, 0, sizeof(struct msi_desc));
410 entry->link.tail = entry->link.head = 0; /* single message */ 403 entry->link.tail = entry->link.head = 0; /* single message */
411 entry->dev = NULL; 404 entry->dev = NULL;
412 405
@@ -901,6 +894,33 @@ static int msix_capability_init(struct pci_dev *dev,
901} 894}
902 895
903/** 896/**
897 * pci_msi_supported - check whether MSI may be enabled on device
898 * @dev: pointer to the pci_dev data structure of MSI device function
899 *
900 * MSI must be globally enabled and supported by the device and its root
901 * bus. But, the root bus is not easy to find since some architectures
902 * have virtual busses on top of the PCI hierarchy (for instance the
903 * hypertransport bus), while the actual bus where MSI must be supported
904 * is below. So we test the MSI flag on all parent busses and assume
905 * that no quirk will ever set the NO_MSI flag on a non-root bus.
906 **/
907static
908int pci_msi_supported(struct pci_dev * dev)
909{
910 struct pci_bus *bus;
911
912 if (!pci_msi_enable || !dev || dev->no_msi)
913 return -EINVAL;
914
915 /* check MSI flags of all parent busses */
916 for (bus = dev->bus; bus; bus = bus->parent)
917 if (bus->bus_flags & PCI_BUS_FLAGS_NO_MSI)
918 return -EINVAL;
919
920 return 0;
921}
922
923/**
904 * pci_enable_msi - configure device's MSI capability structure 924 * pci_enable_msi - configure device's MSI capability structure
905 * @dev: pointer to the pci_dev data structure of MSI device function 925 * @dev: pointer to the pci_dev data structure of MSI device function
906 * 926 *
@@ -912,19 +932,11 @@ static int msix_capability_init(struct pci_dev *dev,
912 **/ 932 **/
913int pci_enable_msi(struct pci_dev* dev) 933int pci_enable_msi(struct pci_dev* dev)
914{ 934{
915 struct pci_bus *bus; 935 int pos, temp, status;
916 int pos, temp, status = -EINVAL;
917 u16 control; 936 u16 control;
918 937
919 if (!pci_msi_enable || !dev) 938 if (pci_msi_supported(dev) < 0)
920 return status; 939 return -EINVAL;
921
922 if (dev->no_msi)
923 return status;
924
925 for (bus = dev->bus; bus; bus = bus->parent)
926 if (bus->bus_flags & PCI_BUS_FLAGS_NO_MSI)
927 return -EINVAL;
928 940
929 temp = dev->irq; 941 temp = dev->irq;
930 942
@@ -1134,22 +1146,14 @@ static int reroute_msix_table(int head, struct msix_entry *entries, int *nvec)
1134 **/ 1146 **/
1135int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec) 1147int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec)
1136{ 1148{
1137 struct pci_bus *bus;
1138 int status, pos, nr_entries, free_vectors; 1149 int status, pos, nr_entries, free_vectors;
1139 int i, j, temp; 1150 int i, j, temp;
1140 u16 control; 1151 u16 control;
1141 unsigned long flags; 1152 unsigned long flags;
1142 1153
1143 if (!pci_msi_enable || !dev || !entries) 1154 if (!entries || pci_msi_supported(dev) < 0)
1144 return -EINVAL; 1155 return -EINVAL;
1145 1156
1146 if (dev->no_msi)
1147 return -EINVAL;
1148
1149 for (bus = dev->bus; bus; bus = bus->parent)
1150 if (bus->bus_flags & PCI_BUS_FLAGS_NO_MSI)
1151 return -EINVAL;
1152
1153 status = msi_init(); 1157 status = msi_init();
1154 if (status < 0) 1158 if (status < 0)
1155 return status; 1159 return status;
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 474e9cd0e9e4..b1c0c707d96c 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -17,6 +17,16 @@
17 * Registration of PCI drivers and handling of hot-pluggable devices. 17 * Registration of PCI drivers and handling of hot-pluggable devices.
18 */ 18 */
19 19
20/* multithreaded probe logic */
21static int pci_multithread_probe =
22#ifdef CONFIG_PCI_MULTITHREAD_PROBE
23 1;
24#else
25 0;
26#endif
27__module_param_call("", pci_multithread_probe, param_set_bool, param_get_bool, &pci_multithread_probe, 0644);
28
29
20/* 30/*
21 * Dynamic device IDs are disabled for !CONFIG_HOTPLUG 31 * Dynamic device IDs are disabled for !CONFIG_HOTPLUG
22 */ 32 */
@@ -46,6 +56,7 @@ store_new_id(struct device_driver *driver, const char *buf, size_t count)
46 subdevice=PCI_ANY_ID, class=0, class_mask=0; 56 subdevice=PCI_ANY_ID, class=0, class_mask=0;
47 unsigned long driver_data=0; 57 unsigned long driver_data=0;
48 int fields=0; 58 int fields=0;
59 int retval = 0;
49 60
50 fields = sscanf(buf, "%x %x %x %x %x %x %lux", 61 fields = sscanf(buf, "%x %x %x %x %x %x %lux",
51 &vendor, &device, &subvendor, &subdevice, 62 &vendor, &device, &subvendor, &subdevice,
@@ -72,10 +83,12 @@ store_new_id(struct device_driver *driver, const char *buf, size_t count)
72 spin_unlock(&pdrv->dynids.lock); 83 spin_unlock(&pdrv->dynids.lock);
73 84
74 if (get_driver(&pdrv->driver)) { 85 if (get_driver(&pdrv->driver)) {
75 driver_attach(&pdrv->driver); 86 retval = driver_attach(&pdrv->driver);
76 put_driver(&pdrv->driver); 87 put_driver(&pdrv->driver);
77 } 88 }
78 89
90 if (retval)
91 return retval;
79 return count; 92 return count;
80} 93}
81static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id); 94static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
@@ -279,6 +292,18 @@ static int pci_device_suspend(struct device * dev, pm_message_t state)
279 return i; 292 return i;
280} 293}
281 294
295static int pci_device_suspend_late(struct device * dev, pm_message_t state)
296{
297 struct pci_dev * pci_dev = to_pci_dev(dev);
298 struct pci_driver * drv = pci_dev->driver;
299 int i = 0;
300
301 if (drv && drv->suspend_late) {
302 i = drv->suspend_late(pci_dev, state);
303 suspend_report_result(drv->suspend_late, i);
304 }
305 return i;
306}
282 307
283/* 308/*
284 * Default resume method for devices that have no driver provided resume, 309 * Default resume method for devices that have no driver provided resume,
@@ -313,6 +338,17 @@ static int pci_device_resume(struct device * dev)
313 return error; 338 return error;
314} 339}
315 340
341static int pci_device_resume_early(struct device * dev)
342{
343 int error = 0;
344 struct pci_dev * pci_dev = to_pci_dev(dev);
345 struct pci_driver * drv = pci_dev->driver;
346
347 if (drv && drv->resume_early)
348 error = drv->resume_early(pci_dev);
349 return error;
350}
351
316static void pci_device_shutdown(struct device *dev) 352static void pci_device_shutdown(struct device *dev)
317{ 353{
318 struct pci_dev *pci_dev = to_pci_dev(dev); 354 struct pci_dev *pci_dev = to_pci_dev(dev);
@@ -386,6 +422,11 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner)
386 drv->driver.owner = owner; 422 drv->driver.owner = owner;
387 drv->driver.kobj.ktype = &pci_driver_kobj_type; 423 drv->driver.kobj.ktype = &pci_driver_kobj_type;
388 424
425 if (pci_multithread_probe)
426 drv->driver.multithread_probe = pci_multithread_probe;
427 else
428 drv->driver.multithread_probe = drv->multithread_probe;
429
389 spin_lock_init(&drv->dynids.lock); 430 spin_lock_init(&drv->dynids.lock);
390 INIT_LIST_HEAD(&drv->dynids.list); 431 INIT_LIST_HEAD(&drv->dynids.list);
391 432
@@ -509,8 +550,10 @@ struct bus_type pci_bus_type = {
509 .probe = pci_device_probe, 550 .probe = pci_device_probe,
510 .remove = pci_device_remove, 551 .remove = pci_device_remove,
511 .suspend = pci_device_suspend, 552 .suspend = pci_device_suspend,
512 .shutdown = pci_device_shutdown, 553 .suspend_late = pci_device_suspend_late,
554 .resume_early = pci_device_resume_early,
513 .resume = pci_device_resume, 555 .resume = pci_device_resume,
556 .shutdown = pci_device_shutdown,
514 .dev_attrs = pci_dev_attrs, 557 .dev_attrs = pci_dev_attrs,
515}; 558};
516 559
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index fdefa7dcd156..a1d2e979b17f 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -117,6 +117,7 @@ is_enabled_store(struct device *dev, struct device_attribute *attr,
117 const char *buf, size_t count) 117 const char *buf, size_t count)
118{ 118{
119 struct pci_dev *pdev = to_pci_dev(dev); 119 struct pci_dev *pdev = to_pci_dev(dev);
120 int retval = 0;
120 121
121 /* this can crash the machine when done on the "wrong" device */ 122 /* this can crash the machine when done on the "wrong" device */
122 if (!capable(CAP_SYS_ADMIN)) 123 if (!capable(CAP_SYS_ADMIN))
@@ -126,11 +127,53 @@ is_enabled_store(struct device *dev, struct device_attribute *attr,
126 pci_disable_device(pdev); 127 pci_disable_device(pdev);
127 128
128 if (*buf == '1') 129 if (*buf == '1')
129 pci_enable_device(pdev); 130 retval = pci_enable_device(pdev);
130 131
132 if (retval)
133 return retval;
131 return count; 134 return count;
132} 135}
133 136
137static ssize_t
138msi_bus_show(struct device *dev, struct device_attribute *attr, char *buf)
139{
140 struct pci_dev *pdev = to_pci_dev(dev);
141
142 if (!pdev->subordinate)
143 return 0;
144
145 return sprintf (buf, "%u\n",
146 !(pdev->subordinate->bus_flags & PCI_BUS_FLAGS_NO_MSI));
147}
148
149static ssize_t
150msi_bus_store(struct device *dev, struct device_attribute *attr,
151 const char *buf, size_t count)
152{
153 struct pci_dev *pdev = to_pci_dev(dev);
154
155 /* bad things may happen if the no_msi flag is changed
156 * while some drivers are loaded */
157 if (!capable(CAP_SYS_ADMIN))
158 return count;
159
160 if (!pdev->subordinate)
161 return count;
162
163 if (*buf == '0') {
164 pdev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
165 dev_warn(&pdev->dev, "forced subordinate bus to not support MSI,"
166 " bad things could happen.\n");
167 }
168
169 if (*buf == '1') {
170 pdev->subordinate->bus_flags &= ~PCI_BUS_FLAGS_NO_MSI;
171 dev_warn(&pdev->dev, "forced subordinate bus to support MSI,"
172 " bad things could happen.\n");
173 }
174
175 return count;
176}
134 177
135struct device_attribute pci_dev_attrs[] = { 178struct device_attribute pci_dev_attrs[] = {
136 __ATTR_RO(resource), 179 __ATTR_RO(resource),
@@ -145,6 +188,7 @@ struct device_attribute pci_dev_attrs[] = {
145 __ATTR(enable, 0600, is_enabled_show, is_enabled_store), 188 __ATTR(enable, 0600, is_enabled_show, is_enabled_store),
146 __ATTR(broken_parity_status,(S_IRUGO|S_IWUSR), 189 __ATTR(broken_parity_status,(S_IRUGO|S_IWUSR),
147 broken_parity_status_show,broken_parity_status_store), 190 broken_parity_status_show,broken_parity_status_store),
191 __ATTR(msi_bus, 0644, msi_bus_show, msi_bus_store),
148 __ATTR_NULL, 192 __ATTR_NULL,
149}; 193};
150 194
@@ -385,15 +429,38 @@ pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
385} 429}
386 430
387/** 431/**
432 * pci_remove_resource_files - cleanup resource files
433 * @dev: dev to cleanup
434 *
435 * If we created resource files for @dev, remove them from sysfs and
436 * free their resources.
437 */
438static void
439pci_remove_resource_files(struct pci_dev *pdev)
440{
441 int i;
442
443 for (i = 0; i < PCI_ROM_RESOURCE; i++) {
444 struct bin_attribute *res_attr;
445
446 res_attr = pdev->res_attr[i];
447 if (res_attr) {
448 sysfs_remove_bin_file(&pdev->dev.kobj, res_attr);
449 kfree(res_attr);
450 }
451 }
452}
453
454/**
388 * pci_create_resource_files - create resource files in sysfs for @dev 455 * pci_create_resource_files - create resource files in sysfs for @dev
389 * @dev: dev in question 456 * @dev: dev in question
390 * 457 *
391 * Walk the resources in @dev creating files for each resource available. 458 * Walk the resources in @dev creating files for each resource available.
392 */ 459 */
393static void 460static int pci_create_resource_files(struct pci_dev *pdev)
394pci_create_resource_files(struct pci_dev *pdev)
395{ 461{
396 int i; 462 int i;
463 int retval;
397 464
398 /* Expose the PCI resources from this device as files */ 465 /* Expose the PCI resources from this device as files */
399 for (i = 0; i < PCI_ROM_RESOURCE; i++) { 466 for (i = 0; i < PCI_ROM_RESOURCE; i++) {
@@ -416,35 +483,19 @@ pci_create_resource_files(struct pci_dev *pdev)
416 res_attr->size = pci_resource_len(pdev, i); 483 res_attr->size = pci_resource_len(pdev, i);
417 res_attr->mmap = pci_mmap_resource; 484 res_attr->mmap = pci_mmap_resource;
418 res_attr->private = &pdev->resource[i]; 485 res_attr->private = &pdev->resource[i];
419 sysfs_create_bin_file(&pdev->dev.kobj, res_attr); 486 retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr);
420 } 487 if (retval) {
421 } 488 pci_remove_resource_files(pdev);
422} 489 return retval;
423 490 }
424/** 491 } else {
425 * pci_remove_resource_files - cleanup resource files 492 return -ENOMEM;
426 * @dev: dev to cleanup
427 *
428 * If we created resource files for @dev, remove them from sysfs and
429 * free their resources.
430 */
431static void
432pci_remove_resource_files(struct pci_dev *pdev)
433{
434 int i;
435
436 for (i = 0; i < PCI_ROM_RESOURCE; i++) {
437 struct bin_attribute *res_attr;
438
439 res_attr = pdev->res_attr[i];
440 if (res_attr) {
441 sysfs_remove_bin_file(&pdev->dev.kobj, res_attr);
442 kfree(res_attr);
443 } 493 }
444 } 494 }
495 return 0;
445} 496}
446#else /* !HAVE_PCI_MMAP */ 497#else /* !HAVE_PCI_MMAP */
447static inline void pci_create_resource_files(struct pci_dev *dev) { return; } 498static inline int pci_create_resource_files(struct pci_dev *dev) { return 0; }
448static inline void pci_remove_resource_files(struct pci_dev *dev) { return; } 499static inline void pci_remove_resource_files(struct pci_dev *dev) { return; }
449#endif /* HAVE_PCI_MMAP */ 500#endif /* HAVE_PCI_MMAP */
450 501
@@ -529,22 +580,27 @@ static struct bin_attribute pcie_config_attr = {
529 .write = pci_write_config, 580 .write = pci_write_config,
530}; 581};
531 582
532int pci_create_sysfs_dev_files (struct pci_dev *pdev) 583int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
533{ 584{
585 struct bin_attribute *rom_attr = NULL;
586 int retval;
587
534 if (!sysfs_initialized) 588 if (!sysfs_initialized)
535 return -EACCES; 589 return -EACCES;
536 590
537 if (pdev->cfg_size < 4096) 591 if (pdev->cfg_size < 4096)
538 sysfs_create_bin_file(&pdev->dev.kobj, &pci_config_attr); 592 retval = sysfs_create_bin_file(&pdev->dev.kobj, &pci_config_attr);
539 else 593 else
540 sysfs_create_bin_file(&pdev->dev.kobj, &pcie_config_attr); 594 retval = sysfs_create_bin_file(&pdev->dev.kobj, &pcie_config_attr);
595 if (retval)
596 goto err;
541 597
542 pci_create_resource_files(pdev); 598 retval = pci_create_resource_files(pdev);
599 if (retval)
600 goto err_bin_file;
543 601
544 /* If the device has a ROM, try to expose it in sysfs. */ 602 /* If the device has a ROM, try to expose it in sysfs. */
545 if (pci_resource_len(pdev, PCI_ROM_RESOURCE)) { 603 if (pci_resource_len(pdev, PCI_ROM_RESOURCE)) {
546 struct bin_attribute *rom_attr;
547
548 rom_attr = kzalloc(sizeof(*rom_attr), GFP_ATOMIC); 604 rom_attr = kzalloc(sizeof(*rom_attr), GFP_ATOMIC);
549 if (rom_attr) { 605 if (rom_attr) {
550 pdev->rom_attr = rom_attr; 606 pdev->rom_attr = rom_attr;
@@ -554,13 +610,28 @@ int pci_create_sysfs_dev_files (struct pci_dev *pdev)
554 rom_attr->attr.owner = THIS_MODULE; 610 rom_attr->attr.owner = THIS_MODULE;
555 rom_attr->read = pci_read_rom; 611 rom_attr->read = pci_read_rom;
556 rom_attr->write = pci_write_rom; 612 rom_attr->write = pci_write_rom;
557 sysfs_create_bin_file(&pdev->dev.kobj, rom_attr); 613 retval = sysfs_create_bin_file(&pdev->dev.kobj, rom_attr);
614 if (retval)
615 goto err_rom;
616 } else {
617 retval = -ENOMEM;
618 goto err_bin_file;
558 } 619 }
559 } 620 }
560 /* add platform-specific attributes */ 621 /* add platform-specific attributes */
561 pcibios_add_platform_entries(pdev); 622 pcibios_add_platform_entries(pdev);
562 623
563 return 0; 624 return 0;
625
626err_rom:
627 kfree(rom_attr);
628err_bin_file:
629 if (pdev->cfg_size < 4096)
630 sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr);
631 else
632 sysfs_remove_bin_file(&pdev->dev.kobj, &pcie_config_attr);
633err:
634 return retval;
564} 635}
565 636
566/** 637/**
@@ -589,10 +660,14 @@ void pci_remove_sysfs_dev_files(struct pci_dev *pdev)
589static int __init pci_sysfs_init(void) 660static int __init pci_sysfs_init(void)
590{ 661{
591 struct pci_dev *pdev = NULL; 662 struct pci_dev *pdev = NULL;
592 663 int retval;
664
593 sysfs_initialized = 1; 665 sysfs_initialized = 1;
594 for_each_pci_dev(pdev) 666 for_each_pci_dev(pdev) {
595 pci_create_sysfs_dev_files(pdev); 667 retval = pci_create_sysfs_dev_files(pdev);
668 if (retval)
669 return retval;
670 }
596 671
597 return 0; 672 return 0;
598} 673}
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 9f79dd6d51ab..a544997399b3 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -432,10 +432,12 @@ pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
432 case PM_EVENT_ON: 432 case PM_EVENT_ON:
433 return PCI_D0; 433 return PCI_D0;
434 case PM_EVENT_FREEZE: 434 case PM_EVENT_FREEZE:
435 case PM_EVENT_PRETHAW:
436 /* REVISIT both freeze and pre-thaw "should" use D0 */
435 case PM_EVENT_SUSPEND: 437 case PM_EVENT_SUSPEND:
436 return PCI_D3hot; 438 return PCI_D3hot;
437 default: 439 default:
438 printk("They asked me for state %d\n", state.event); 440 printk("Unrecognized suspend event %d\n", state.event);
439 BUG(); 441 BUG();
440 } 442 }
441 return PCI_D0; 443 return PCI_D0;
@@ -443,6 +445,51 @@ pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
443 445
444EXPORT_SYMBOL(pci_choose_state); 446EXPORT_SYMBOL(pci_choose_state);
445 447
448static int pci_save_pcie_state(struct pci_dev *dev)
449{
450 int pos, i = 0;
451 struct pci_cap_saved_state *save_state;
452 u16 *cap;
453
454 pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
455 if (pos <= 0)
456 return 0;
457
458 save_state = kzalloc(sizeof(*save_state) + sizeof(u16) * 4, GFP_KERNEL);
459 if (!save_state) {
460 dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n");
461 return -ENOMEM;
462 }
463 cap = (u16 *)&save_state->data[0];
464
465 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &cap[i++]);
466 pci_read_config_word(dev, pos + PCI_EXP_LNKCTL, &cap[i++]);
467 pci_read_config_word(dev, pos + PCI_EXP_SLTCTL, &cap[i++]);
468 pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &cap[i++]);
469 pci_add_saved_cap(dev, save_state);
470 return 0;
471}
472
473static void pci_restore_pcie_state(struct pci_dev *dev)
474{
475 int i = 0, pos;
476 struct pci_cap_saved_state *save_state;
477 u16 *cap;
478
479 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
480 pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
481 if (!save_state || pos <= 0)
482 return;
483 cap = (u16 *)&save_state->data[0];
484
485 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, cap[i++]);
486 pci_write_config_word(dev, pos + PCI_EXP_LNKCTL, cap[i++]);
487 pci_write_config_word(dev, pos + PCI_EXP_SLTCTL, cap[i++]);
488 pci_write_config_word(dev, pos + PCI_EXP_RTCTL, cap[i++]);
489 pci_remove_saved_cap(save_state);
490 kfree(save_state);
491}
492
446/** 493/**
447 * pci_save_state - save the PCI configuration space of a device before suspending 494 * pci_save_state - save the PCI configuration space of a device before suspending
448 * @dev: - PCI device that we're dealing with 495 * @dev: - PCI device that we're dealing with
@@ -458,6 +505,8 @@ pci_save_state(struct pci_dev *dev)
458 return i; 505 return i;
459 if ((i = pci_save_msix_state(dev)) != 0) 506 if ((i = pci_save_msix_state(dev)) != 0)
460 return i; 507 return i;
508 if ((i = pci_save_pcie_state(dev)) != 0)
509 return i;
461 return 0; 510 return 0;
462} 511}
463 512
@@ -471,6 +520,9 @@ pci_restore_state(struct pci_dev *dev)
471 int i; 520 int i;
472 int val; 521 int val;
473 522
523 /* PCI Express register must be restored first */
524 pci_restore_pcie_state(dev);
525
474 /* 526 /*
475 * The Base Address register should be programmed before the command 527 * The Base Address register should be programmed before the command
476 * register(s) 528 * register(s)
@@ -953,13 +1005,12 @@ static int __devinit pci_setup(char *str)
953 } 1005 }
954 str = k; 1006 str = k;
955 } 1007 }
956 return 1; 1008 return 0;
957} 1009}
1010early_param("pci", pci_setup);
958 1011
959device_initcall(pci_init); 1012device_initcall(pci_init);
960 1013
961__setup("pci=", pci_setup);
962
963#if defined(CONFIG_ISA) || defined(CONFIG_EISA) 1014#if defined(CONFIG_ISA) || defined(CONFIG_EISA)
964/* FIXME: Some boxes have multiple ISA bridges! */ 1015/* FIXME: Some boxes have multiple ISA bridges! */
965struct pci_dev *isa_bridge; 1016struct pci_dev *isa_bridge;
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 08d58fc78ee1..6bf327db5c5e 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -42,7 +42,7 @@ extern void pci_remove_legacy_files(struct pci_bus *bus);
42/* Lock for read/write access to pci device and bus lists */ 42/* Lock for read/write access to pci device and bus lists */
43extern struct rw_semaphore pci_bus_sem; 43extern struct rw_semaphore pci_bus_sem;
44 44
45#ifdef CONFIG_X86_IO_APIC 45#ifdef CONFIG_PCI_MSI
46extern int pci_msi_quirk; 46extern int pci_msi_quirk;
47#else 47#else
48#define pci_msi_quirk 0 48#define pci_msi_quirk 0
diff --git a/drivers/pci/pcie/Kconfig b/drivers/pci/pcie/Kconfig
index 1012db8b8b2c..0ad92a8ad8b1 100644
--- a/drivers/pci/pcie/Kconfig
+++ b/drivers/pci/pcie/Kconfig
@@ -34,3 +34,4 @@ config HOTPLUG_PCI_PCIE_POLL_EVENT_MODE
34 34
35 When in doubt, say N. 35 When in doubt, say N.
36 36
37source "drivers/pci/pcie/aer/Kconfig"
diff --git a/drivers/pci/pcie/Makefile b/drivers/pci/pcie/Makefile
index 984fa87283e3..e00fb99acf44 100644
--- a/drivers/pci/pcie/Makefile
+++ b/drivers/pci/pcie/Makefile
@@ -5,3 +5,6 @@
5pcieportdrv-y := portdrv_core.o portdrv_pci.o portdrv_bus.o 5pcieportdrv-y := portdrv_core.o portdrv_pci.o portdrv_bus.o
6 6
7obj-$(CONFIG_PCIEPORTBUS) += pcieportdrv.o 7obj-$(CONFIG_PCIEPORTBUS) += pcieportdrv.o
8
9# Build PCI Express AER if needed
10obj-$(CONFIG_PCIEAER) += aer/
diff --git a/drivers/pci/pcie/aer/Kconfig b/drivers/pci/pcie/aer/Kconfig
new file mode 100644
index 000000000000..3f37a60a6438
--- /dev/null
+++ b/drivers/pci/pcie/aer/Kconfig
@@ -0,0 +1,12 @@
1#
2# PCI Express Root Port Device AER Configuration
3#
4
5config PCIEAER
6 boolean "Root Port Advanced Error Reporting support"
7 depends on PCIEPORTBUS && ACPI
8 default y
9 help
10 This enables PCI Express Root Port Advanced Error Reporting
11 (AER) driver support. Error reporting messages sent to Root
12 Port will be handled by PCI Express AER driver.
diff --git a/drivers/pci/pcie/aer/Makefile b/drivers/pci/pcie/aer/Makefile
new file mode 100644
index 000000000000..15a4f40d520b
--- /dev/null
+++ b/drivers/pci/pcie/aer/Makefile
@@ -0,0 +1,8 @@
1#
2# Makefile for PCI-Express Root Port Advanced Error Reporting Driver
3#
4
5obj-$(CONFIG_PCIEAER) += aerdriver.o
6
7aerdriver-objs := aerdrv_errprint.o aerdrv_core.o aerdrv.o aerdrv_acpi.o
8
diff --git a/drivers/pci/pcie/aer/aerdrv.c b/drivers/pci/pcie/aer/aerdrv.c
new file mode 100644
index 000000000000..0d4ac027d53e
--- /dev/null
+++ b/drivers/pci/pcie/aer/aerdrv.c
@@ -0,0 +1,346 @@
1/*
2 * drivers/pci/pcie/aer/aerdrv.c
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * This file implements the AER root port service driver. The driver will
9 * register an irq handler. When root port triggers an AER interrupt, the irq
10 * handler will collect root port status and schedule a work.
11 *
12 * Copyright (C) 2006 Intel Corp.
13 * Tom Long Nguyen (tom.l.nguyen@intel.com)
14 * Zhang Yanmin (yanmin.zhang@intel.com)
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/pci.h>
20#include <linux/kernel.h>
21#include <linux/errno.h>
22#include <linux/pm.h>
23#include <linux/init.h>
24#include <linux/interrupt.h>
25#include <linux/delay.h>
26#include <linux/pcieport_if.h>
27
28#include "aerdrv.h"
29
30/*
31 * Version Information
32 */
33#define DRIVER_VERSION "v1.0"
34#define DRIVER_AUTHOR "tom.l.nguyen@intel.com"
35#define DRIVER_DESC "Root Port Advanced Error Reporting Driver"
36MODULE_AUTHOR(DRIVER_AUTHOR);
37MODULE_DESCRIPTION(DRIVER_DESC);
38MODULE_LICENSE("GPL");
39
40static int __devinit aer_probe (struct pcie_device *dev,
41 const struct pcie_port_service_id *id );
42static void aer_remove(struct pcie_device *dev);
43static int aer_suspend(struct pcie_device *dev, pm_message_t state)
44{return 0;}
45static int aer_resume(struct pcie_device *dev) {return 0;}
46static pci_ers_result_t aer_error_detected(struct pci_dev *dev,
47 enum pci_channel_state error);
48static void aer_error_resume(struct pci_dev *dev);
49static pci_ers_result_t aer_root_reset(struct pci_dev *dev);
50
51/*
52 * PCI Express bus's AER Root service driver data structure
53 */
54static struct pcie_port_service_id aer_id[] = {
55 {
56 .vendor = PCI_ANY_ID,
57 .device = PCI_ANY_ID,
58 .port_type = PCIE_RC_PORT,
59 .service_type = PCIE_PORT_SERVICE_AER,
60 },
61 { /* end: all zeroes */ }
62};
63
64static struct pci_error_handlers aer_error_handlers = {
65 .error_detected = aer_error_detected,
66 .resume = aer_error_resume,
67};
68
69static struct pcie_port_service_driver aerdrv = {
70 .name = "aer",
71 .id_table = &aer_id[0],
72
73 .probe = aer_probe,
74 .remove = aer_remove,
75
76 .suspend = aer_suspend,
77 .resume = aer_resume,
78
79 .err_handler = &aer_error_handlers,
80
81 .reset_link = aer_root_reset,
82};
83
84/**
85 * aer_irq - Root Port's ISR
86 * @irq: IRQ assigned to Root Port
87 * @context: pointer to Root Port data structure
88 * @r: pointer struct pt_regs
89 *
90 * Invoked when Root Port detects AER messages.
91 **/
92static irqreturn_t aer_irq(int irq, void *context, struct pt_regs * r)
93{
94 unsigned int status, id;
95 struct pcie_device *pdev = (struct pcie_device *)context;
96 struct aer_rpc *rpc = get_service_data(pdev);
97 int next_prod_idx;
98 unsigned long flags;
99 int pos;
100
101 pos = pci_find_aer_capability(pdev->port);
102 /*
103 * Must lock access to Root Error Status Reg, Root Error ID Reg,
104 * and Root error producer/consumer index
105 */
106 spin_lock_irqsave(&rpc->e_lock, flags);
107
108 /* Read error status */
109 pci_read_config_dword(pdev->port, pos + PCI_ERR_ROOT_STATUS, &status);
110 if (!(status & ROOT_ERR_STATUS_MASKS)) {
111 spin_unlock_irqrestore(&rpc->e_lock, flags);
112 return IRQ_NONE;
113 }
114
115 /* Read error source and clear error status */
116 pci_read_config_dword(pdev->port, pos + PCI_ERR_ROOT_COR_SRC, &id);
117 pci_write_config_dword(pdev->port, pos + PCI_ERR_ROOT_STATUS, status);
118
119 /* Store error source for later DPC handler */
120 next_prod_idx = rpc->prod_idx + 1;
121 if (next_prod_idx == AER_ERROR_SOURCES_MAX)
122 next_prod_idx = 0;
123 if (next_prod_idx == rpc->cons_idx) {
124 /*
125 * Error Storm Condition - possibly the same error occurred.
126 * Drop the error.
127 */
128 spin_unlock_irqrestore(&rpc->e_lock, flags);
129 return IRQ_HANDLED;
130 }
131 rpc->e_sources[rpc->prod_idx].status = status;
132 rpc->e_sources[rpc->prod_idx].id = id;
133 rpc->prod_idx = next_prod_idx;
134 spin_unlock_irqrestore(&rpc->e_lock, flags);
135
136 /* Invoke DPC handler */
137 schedule_work(&rpc->dpc_handler);
138
139 return IRQ_HANDLED;
140}
141
142/**
143 * aer_alloc_rpc - allocate Root Port data structure
144 * @dev: pointer to the pcie_dev data structure
145 *
146 * Invoked when Root Port's AER service is loaded.
147 **/
148static struct aer_rpc* aer_alloc_rpc(struct pcie_device *dev)
149{
150 struct aer_rpc *rpc;
151
152 if (!(rpc = (struct aer_rpc *)kmalloc(sizeof(struct aer_rpc),
153 GFP_KERNEL)))
154 return NULL;
155
156 memset(rpc, 0, sizeof(struct aer_rpc));
157 /*
158 * Initialize Root lock access, e_lock, to Root Error Status Reg,
159 * Root Error ID Reg, and Root error producer/consumer index.
160 */
161 rpc->e_lock = SPIN_LOCK_UNLOCKED;
162
163 rpc->rpd = dev;
164 INIT_WORK(&rpc->dpc_handler, aer_isr, (void *)dev);
165 rpc->prod_idx = rpc->cons_idx = 0;
166 mutex_init(&rpc->rpc_mutex);
167 init_waitqueue_head(&rpc->wait_release);
168
169 /* Use PCIE bus function to store rpc into PCIE device */
170 set_service_data(dev, rpc);
171
172 return rpc;
173}
174
175/**
176 * aer_remove - clean up resources
177 * @dev: pointer to the pcie_dev data structure
178 *
179 * Invoked when PCI Express bus unloads or AER probe fails.
180 **/
181static void aer_remove(struct pcie_device *dev)
182{
183 struct aer_rpc *rpc = get_service_data(dev);
184
185 if (rpc) {
186 /* If register interrupt service, it must be free. */
187 if (rpc->isr)
188 free_irq(dev->irq, dev);
189
190 wait_event(rpc->wait_release, rpc->prod_idx == rpc->cons_idx);
191
192 aer_delete_rootport(rpc);
193 set_service_data(dev, NULL);
194 }
195}
196
197/**
198 * aer_probe - initialize resources
199 * @dev: pointer to the pcie_dev data structure
200 * @id: pointer to the service id data structure
201 *
202 * Invoked when PCI Express bus loads AER service driver.
203 **/
204static int __devinit aer_probe (struct pcie_device *dev,
205 const struct pcie_port_service_id *id )
206{
207 int status;
208 struct aer_rpc *rpc;
209 struct device *device = &dev->device;
210
211 /* Init */
212 if ((status = aer_init(dev)))
213 return status;
214
215 /* Alloc rpc data structure */
216 if (!(rpc = aer_alloc_rpc(dev))) {
217 printk(KERN_DEBUG "%s: Alloc rpc fails on PCIE device[%s]\n",
218 __FUNCTION__, device->bus_id);
219 aer_remove(dev);
220 return -ENOMEM;
221 }
222
223 /* Request IRQ ISR */
224 if ((status = request_irq(dev->irq, aer_irq, SA_SHIRQ, "aerdrv",
225 dev))) {
226 printk(KERN_DEBUG "%s: Request ISR fails on PCIE device[%s]\n",
227 __FUNCTION__, device->bus_id);
228 aer_remove(dev);
229 return status;
230 }
231
232 rpc->isr = 1;
233
234 aer_enable_rootport(rpc);
235
236 return status;
237}
238
239/**
240 * aer_root_reset - reset link on Root Port
241 * @dev: pointer to Root Port's pci_dev data structure
242 *
243 * Invoked by Port Bus driver when performing link reset at Root Port.
244 **/
245static pci_ers_result_t aer_root_reset(struct pci_dev *dev)
246{
247 u16 p2p_ctrl;
248 u32 status;
249 int pos;
250
251 pos = pci_find_aer_capability(dev);
252
253 /* Disable Root's interrupt in response to error messages */
254 pci_write_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND, 0);
255
256 /* Assert Secondary Bus Reset */
257 pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &p2p_ctrl);
258 p2p_ctrl |= PCI_CB_BRIDGE_CTL_CB_RESET;
259 pci_write_config_word(dev, PCI_BRIDGE_CONTROL, p2p_ctrl);
260
261 /* De-assert Secondary Bus Reset */
262 p2p_ctrl &= ~PCI_CB_BRIDGE_CTL_CB_RESET;
263 pci_write_config_word(dev, PCI_BRIDGE_CONTROL, p2p_ctrl);
264
265 /*
266 * System software must wait for at least 100ms from the end
267 * of a reset of one or more device before it is permitted
268 * to issue Configuration Requests to those devices.
269 */
270 msleep(200);
271 printk(KERN_DEBUG "Complete link reset at Root[%s]\n", dev->dev.bus_id);
272
273 /* Enable Root Port's interrupt in response to error messages */
274 pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, &status);
275 pci_write_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, status);
276 pci_write_config_dword(dev,
277 pos + PCI_ERR_ROOT_COMMAND,
278 ROOT_PORT_INTR_ON_MESG_MASK);
279
280 return PCI_ERS_RESULT_RECOVERED;
281}
282
283/**
284 * aer_error_detected - update severity status
285 * @dev: pointer to Root Port's pci_dev data structure
286 * @error: error severity being notified by port bus
287 *
288 * Invoked by Port Bus driver during error recovery.
289 **/
290static pci_ers_result_t aer_error_detected(struct pci_dev *dev,
291 enum pci_channel_state error)
292{
293 /* Root Port has no impact. Always recovers. */
294 return PCI_ERS_RESULT_CAN_RECOVER;
295}
296
297/**
298 * aer_error_resume - clean up corresponding error status bits
299 * @dev: pointer to Root Port's pci_dev data structure
300 *
301 * Invoked by Port Bus driver during nonfatal recovery.
302 **/
303static void aer_error_resume(struct pci_dev *dev)
304{
305 int pos;
306 u32 status, mask;
307 u16 reg16;
308
309 /* Clean up Root device status */
310 pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
311 pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &reg16);
312 pci_write_config_word(dev, pos + PCI_EXP_DEVSTA, reg16);
313
314 /* Clean AER Root Error Status */
315 pos = pci_find_aer_capability(dev);
316 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
317 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask);
318 if (dev->error_state == pci_channel_io_normal)
319 status &= ~mask; /* Clear corresponding nonfatal bits */
320 else
321 status &= mask; /* Clear corresponding fatal bits */
322 pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
323}
324
325/**
326 * aer_service_init - register AER root service driver
327 *
328 * Invoked when AER root service driver is loaded.
329 **/
330static int __init aer_service_init(void)
331{
332 return pcie_port_service_register(&aerdrv);
333}
334
335/**
336 * aer_service_exit - unregister AER root service driver
337 *
338 * Invoked when AER root service driver is unloaded.
339 **/
340static void __exit aer_service_exit(void)
341{
342 pcie_port_service_unregister(&aerdrv);
343}
344
345module_init(aer_service_init);
346module_exit(aer_service_exit);
diff --git a/drivers/pci/pcie/aer/aerdrv.h b/drivers/pci/pcie/aer/aerdrv.h
new file mode 100644
index 000000000000..daf0cad88fc8
--- /dev/null
+++ b/drivers/pci/pcie/aer/aerdrv.h
@@ -0,0 +1,125 @@
1/*
2 * Copyright (C) 2006 Intel Corp.
3 * Tom Long Nguyen (tom.l.nguyen@intel.com)
4 * Zhang Yanmin (yanmin.zhang@intel.com)
5 *
6 */
7
8#ifndef _AERDRV_H_
9#define _AERDRV_H_
10
11#include <linux/pcieport_if.h>
12#include <linux/aer.h>
13
14#define AER_NONFATAL 0
15#define AER_FATAL 1
16#define AER_CORRECTABLE 2
17#define AER_UNCORRECTABLE 4
18#define AER_ERROR_MASK 0x001fffff
19#define AER_ERROR(d) (d & AER_ERROR_MASK)
20
21#define OSC_METHOD_RUN_SUCCESS 0
22#define OSC_METHOD_NOT_SUPPORTED 1
23#define OSC_METHOD_RUN_FAILURE 2
24
25/* Root Error Status Register Bits */
26#define ROOT_ERR_STATUS_MASKS 0x0f
27
28#define SYSTEM_ERROR_INTR_ON_MESG_MASK (PCI_EXP_RTCTL_SECEE| \
29 PCI_EXP_RTCTL_SENFEE| \
30 PCI_EXP_RTCTL_SEFEE)
31#define ROOT_PORT_INTR_ON_MESG_MASK (PCI_ERR_ROOT_CMD_COR_EN| \
32 PCI_ERR_ROOT_CMD_NONFATAL_EN| \
33 PCI_ERR_ROOT_CMD_FATAL_EN)
34#define ERR_COR_ID(d) (d & 0xffff)
35#define ERR_UNCOR_ID(d) (d >> 16)
36
37#define AER_SUCCESS 0
38#define AER_UNSUCCESS 1
39#define AER_ERROR_SOURCES_MAX 100
40
41#define AER_LOG_TLP_MASKS (PCI_ERR_UNC_POISON_TLP| \
42 PCI_ERR_UNC_ECRC| \
43 PCI_ERR_UNC_UNSUP| \
44 PCI_ERR_UNC_COMP_ABORT| \
45 PCI_ERR_UNC_UNX_COMP| \
46 PCI_ERR_UNC_MALF_TLP)
47
48/* AER Error Info Flags */
49#define AER_TLP_HEADER_VALID_FLAG 0x00000001
50#define AER_MULTI_ERROR_VALID_FLAG 0x00000002
51
52#define ERR_CORRECTABLE_ERROR_MASK 0x000031c1
53#define ERR_UNCORRECTABLE_ERROR_MASK 0x001ff010
54
55struct header_log_regs {
56 unsigned int dw0;
57 unsigned int dw1;
58 unsigned int dw2;
59 unsigned int dw3;
60};
61
62struct aer_err_info {
63 int severity; /* 0:NONFATAL | 1:FATAL | 2:COR */
64 int flags;
65 unsigned int status; /* COR/UNCOR Error Status */
66 struct header_log_regs tlp; /* TLP Header */
67};
68
69struct aer_err_source {
70 unsigned int status;
71 unsigned int id;
72};
73
74struct aer_rpc {
75 struct pcie_device *rpd; /* Root Port device */
76 struct work_struct dpc_handler;
77 struct aer_err_source e_sources[AER_ERROR_SOURCES_MAX];
78 unsigned short prod_idx; /* Error Producer Index */
79 unsigned short cons_idx; /* Error Consumer Index */
80 int isr;
81 spinlock_t e_lock; /*
82 * Lock access to Error Status/ID Regs
83 * and error producer/consumer index
84 */
85 struct mutex rpc_mutex; /*
86 * only one thread could do
87 * recovery on the same
88 * root port hierachy
89 */
90 wait_queue_head_t wait_release;
91};
92
93struct aer_broadcast_data {
94 enum pci_channel_state state;
95 enum pci_ers_result result;
96};
97
98static inline pci_ers_result_t merge_result(enum pci_ers_result orig,
99 enum pci_ers_result new)
100{
101 switch (orig) {
102 case PCI_ERS_RESULT_CAN_RECOVER:
103 case PCI_ERS_RESULT_RECOVERED:
104 orig = new;
105 break;
106 case PCI_ERS_RESULT_DISCONNECT:
107 if (new == PCI_ERS_RESULT_NEED_RESET)
108 orig = new;
109 break;
110 default:
111 break;
112 }
113
114 return orig;
115}
116
117extern struct bus_type pcie_port_bus_type;
118extern void aer_enable_rootport(struct aer_rpc *rpc);
119extern void aer_delete_rootport(struct aer_rpc *rpc);
120extern int aer_init(struct pcie_device *dev);
121extern void aer_isr(void *context);
122extern void aer_print_error(struct pci_dev *dev, struct aer_err_info *info);
123extern int aer_osc_setup(struct pci_dev *dev);
124
125#endif //_AERDRV_H_
diff --git a/drivers/pci/pcie/aer/aerdrv_acpi.c b/drivers/pci/pcie/aer/aerdrv_acpi.c
new file mode 100644
index 000000000000..fa68e89ebec9
--- /dev/null
+++ b/drivers/pci/pcie/aer/aerdrv_acpi.c
@@ -0,0 +1,68 @@
1/*
2 * Access ACPI _OSC method
3 *
4 * Copyright (C) 2006 Intel Corp.
5 * Tom Long Nguyen (tom.l.nguyen@intel.com)
6 * Zhang Yanmin (yanmin.zhang@intel.com)
7 *
8 */
9
10#include <linux/module.h>
11#include <linux/pci.h>
12#include <linux/kernel.h>
13#include <linux/errno.h>
14#include <linux/pm.h>
15#include <linux/suspend.h>
16#include <linux/acpi.h>
17#include <linux/pci-acpi.h>
18#include <linux/delay.h>
19#include "aerdrv.h"
20
21/**
22 * aer_osc_setup - run ACPI _OSC method
23 *
24 * Return:
25 * Zero if success. Nonzero for otherwise.
26 *
27 * Invoked when PCIE bus loads AER service driver. To avoid conflict with
28 * BIOS AER support requires BIOS to yield AER control to OS native driver.
29 **/
30int aer_osc_setup(struct pci_dev *dev)
31{
32 int retval = OSC_METHOD_RUN_SUCCESS;
33 acpi_status status;
34 acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
35 struct pci_dev *pdev = dev;
36 struct pci_bus *parent;
37
38 while (!handle) {
39 if (!pdev || !pdev->bus->parent)
40 break;
41 parent = pdev->bus->parent;
42 if (!parent->self)
43 /* Parent must be a host bridge */
44 handle = acpi_get_pci_rootbridge_handle(
45 pci_domain_nr(parent),
46 parent->number);
47 else
48 handle = DEVICE_ACPI_HANDLE(
49 &(parent->self->dev));
50 pdev = parent->self;
51 }
52
53 if (!handle)
54 return OSC_METHOD_NOT_SUPPORTED;
55
56 pci_osc_support_set(OSC_EXT_PCI_CONFIG_SUPPORT);
57 status = pci_osc_control_set(handle, OSC_PCI_EXPRESS_AER_CONTROL |
58 OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
59 if (ACPI_FAILURE(status)) {
60 if (status == AE_SUPPORT)
61 retval = OSC_METHOD_NOT_SUPPORTED;
62 else
63 retval = OSC_METHOD_RUN_FAILURE;
64 }
65
66 return retval;
67}
68
diff --git a/drivers/pci/pcie/aer/aerdrv_core.c b/drivers/pci/pcie/aer/aerdrv_core.c
new file mode 100644
index 000000000000..1c7e660d6535
--- /dev/null
+++ b/drivers/pci/pcie/aer/aerdrv_core.c
@@ -0,0 +1,758 @@
1/*
2 * drivers/pci/pcie/aer/aerdrv_core.c
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * This file implements the core part of PCI-Express AER. When an pci-express
9 * error is delivered, an error message will be collected and printed to
10 * console, then, an error recovery procedure will be executed by following
11 * the pci error recovery rules.
12 *
13 * Copyright (C) 2006 Intel Corp.
14 * Tom Long Nguyen (tom.l.nguyen@intel.com)
15 * Zhang Yanmin (yanmin.zhang@intel.com)
16 *
17 */
18
19#include <linux/module.h>
20#include <linux/pci.h>
21#include <linux/kernel.h>
22#include <linux/errno.h>
23#include <linux/pm.h>
24#include <linux/suspend.h>
25#include <linux/acpi.h>
26#include <linux/pci-acpi.h>
27#include <linux/delay.h>
28#include "aerdrv.h"
29
30static int forceload;
31module_param(forceload, bool, 0);
32
33#define PCI_CFG_SPACE_SIZE (0x100)
34int pci_find_aer_capability(struct pci_dev *dev)
35{
36 int pos;
37 u32 reg32 = 0;
38
39 /* Check if it's a pci-express device */
40 pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
41 if (!pos)
42 return 0;
43
44 /* Check if it supports pci-express AER */
45 pos = PCI_CFG_SPACE_SIZE;
46 while (pos) {
47 if (pci_read_config_dword(dev, pos, &reg32))
48 return 0;
49
50 /* some broken boards return ~0 */
51 if (reg32 == 0xffffffff)
52 return 0;
53
54 if (PCI_EXT_CAP_ID(reg32) == PCI_EXT_CAP_ID_ERR)
55 break;
56
57 pos = reg32 >> 20;
58 }
59
60 return pos;
61}
62
63int pci_enable_pcie_error_reporting(struct pci_dev *dev)
64{
65 u16 reg16 = 0;
66 int pos;
67
68 pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
69 if (!pos)
70 return -EIO;
71
72 pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, &reg16);
73 reg16 = reg16 |
74 PCI_EXP_DEVCTL_CERE |
75 PCI_EXP_DEVCTL_NFERE |
76 PCI_EXP_DEVCTL_FERE |
77 PCI_EXP_DEVCTL_URRE;
78 pci_write_config_word(dev, pos+PCI_EXP_DEVCTL,
79 reg16);
80 return 0;
81}
82
83int pci_disable_pcie_error_reporting(struct pci_dev *dev)
84{
85 u16 reg16 = 0;
86 int pos;
87
88 pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
89 if (!pos)
90 return -EIO;
91
92 pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, &reg16);
93 reg16 = reg16 & ~(PCI_EXP_DEVCTL_CERE |
94 PCI_EXP_DEVCTL_NFERE |
95 PCI_EXP_DEVCTL_FERE |
96 PCI_EXP_DEVCTL_URRE);
97 pci_write_config_word(dev, pos+PCI_EXP_DEVCTL,
98 reg16);
99 return 0;
100}
101
102int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
103{
104 int pos;
105 u32 status, mask;
106
107 pos = pci_find_aer_capability(dev);
108 if (!pos)
109 return -EIO;
110
111 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
112 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask);
113 if (dev->error_state == pci_channel_io_normal)
114 status &= ~mask; /* Clear corresponding nonfatal bits */
115 else
116 status &= mask; /* Clear corresponding fatal bits */
117 pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
118
119 return 0;
120}
121
122static int find_device_iter(struct device *device, void *data)
123{
124 struct pci_dev *dev;
125 u16 id = *(unsigned long *)data;
126 u8 secondary, subordinate, d_bus = id >> 8;
127
128 if (device->bus == &pci_bus_type) {
129 dev = to_pci_dev(device);
130 if (id == ((dev->bus->number << 8) | dev->devfn)) {
131 /*
132 * Device ID match
133 */
134 *(unsigned long*)data = (unsigned long)device;
135 return 1;
136 }
137
138 /*
139 * If device is P2P, check if it is an upstream?
140 */
141 if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE) {
142 pci_read_config_byte(dev, PCI_SECONDARY_BUS,
143 &secondary);
144 pci_read_config_byte(dev, PCI_SUBORDINATE_BUS,
145 &subordinate);
146 if (d_bus >= secondary && d_bus <= subordinate) {
147 *(unsigned long*)data = (unsigned long)device;
148 return 1;
149 }
150 }
151 }
152
153 return 0;
154}
155
156/**
157 * find_source_device - search through device hierarchy for source device
158 * @p_dev: pointer to Root Port pci_dev data structure
159 * @id: device ID of agent who sends an error message to this Root Port
160 *
161 * Invoked when error is detected at the Root Port.
162 **/
163static struct device* find_source_device(struct pci_dev *parent, u16 id)
164{
165 struct pci_dev *dev = parent;
166 struct device *device;
167 unsigned long device_addr;
168 int status;
169
170 /* Is Root Port an agent that sends error message? */
171 if (id == ((dev->bus->number << 8) | dev->devfn))
172 return &dev->dev;
173
174 do {
175 device_addr = id;
176 if ((status = device_for_each_child(&dev->dev,
177 &device_addr, find_device_iter))) {
178 device = (struct device*)device_addr;
179 dev = to_pci_dev(device);
180 if (id == ((dev->bus->number << 8) | dev->devfn))
181 return device;
182 }
183 }while (status);
184
185 return NULL;
186}
187
188static void report_error_detected(struct pci_dev *dev, void *data)
189{
190 pci_ers_result_t vote;
191 struct pci_error_handlers *err_handler;
192 struct aer_broadcast_data *result_data;
193 result_data = (struct aer_broadcast_data *) data;
194
195 dev->error_state = result_data->state;
196
197 if (!dev->driver ||
198 !dev->driver->err_handler ||
199 !dev->driver->err_handler->error_detected) {
200 if (result_data->state == pci_channel_io_frozen &&
201 !(dev->hdr_type & PCI_HEADER_TYPE_BRIDGE)) {
202 /*
203 * In case of fatal recovery, if one of down-
204 * stream device has no driver. We might be
205 * unable to recover because a later insmod
206 * of a driver for this device is unaware of
207 * its hw state.
208 */
209 printk(KERN_DEBUG "Device ID[%s] has %s\n",
210 dev->dev.bus_id, (dev->driver) ?
211 "no AER-aware driver" : "no driver");
212 }
213 return;
214 }
215
216 err_handler = dev->driver->err_handler;
217 vote = err_handler->error_detected(dev, result_data->state);
218 result_data->result = merge_result(result_data->result, vote);
219 return;
220}
221
222static void report_mmio_enabled(struct pci_dev *dev, void *data)
223{
224 pci_ers_result_t vote;
225 struct pci_error_handlers *err_handler;
226 struct aer_broadcast_data *result_data;
227 result_data = (struct aer_broadcast_data *) data;
228
229 if (!dev->driver ||
230 !dev->driver->err_handler ||
231 !dev->driver->err_handler->mmio_enabled)
232 return;
233
234 err_handler = dev->driver->err_handler;
235 vote = err_handler->mmio_enabled(dev);
236 result_data->result = merge_result(result_data->result, vote);
237 return;
238}
239
240static void report_slot_reset(struct pci_dev *dev, void *data)
241{
242 pci_ers_result_t vote;
243 struct pci_error_handlers *err_handler;
244 struct aer_broadcast_data *result_data;
245 result_data = (struct aer_broadcast_data *) data;
246
247 if (!dev->driver ||
248 !dev->driver->err_handler ||
249 !dev->driver->err_handler->slot_reset)
250 return;
251
252 err_handler = dev->driver->err_handler;
253 vote = err_handler->slot_reset(dev);
254 result_data->result = merge_result(result_data->result, vote);
255 return;
256}
257
258static void report_resume(struct pci_dev *dev, void *data)
259{
260 struct pci_error_handlers *err_handler;
261
262 dev->error_state = pci_channel_io_normal;
263
264 if (!dev->driver ||
265 !dev->driver->err_handler ||
266 !dev->driver->err_handler->slot_reset)
267 return;
268
269 err_handler = dev->driver->err_handler;
270 err_handler->resume(dev);
271 return;
272}
273
274/**
275 * broadcast_error_message - handle message broadcast to downstream drivers
276 * @device: pointer to from where in a hierarchy message is broadcasted down
277 * @api: callback to be broadcasted
278 * @state: error state
279 *
280 * Invoked during error recovery process. Once being invoked, the content
281 * of error severity will be broadcasted to all downstream drivers in a
282 * hierarchy in question.
283 **/
284static pci_ers_result_t broadcast_error_message(struct pci_dev *dev,
285 enum pci_channel_state state,
286 char *error_mesg,
287 void (*cb)(struct pci_dev *, void *))
288{
289 struct aer_broadcast_data result_data;
290
291 printk(KERN_DEBUG "Broadcast %s message\n", error_mesg);
292 result_data.state = state;
293 if (cb == report_error_detected)
294 result_data.result = PCI_ERS_RESULT_CAN_RECOVER;
295 else
296 result_data.result = PCI_ERS_RESULT_RECOVERED;
297
298 if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE) {
299 /*
300 * If the error is reported by a bridge, we think this error
301 * is related to the downstream link of the bridge, so we
302 * do error recovery on all subordinates of the bridge instead
303 * of the bridge and clear the error status of the bridge.
304 */
305 if (cb == report_error_detected)
306 dev->error_state = state;
307 pci_walk_bus(dev->subordinate, cb, &result_data);
308 if (cb == report_resume) {
309 pci_cleanup_aer_uncorrect_error_status(dev);
310 dev->error_state = pci_channel_io_normal;
311 }
312 }
313 else {
314 /*
315 * If the error is reported by an end point, we think this
316 * error is related to the upstream link of the end point.
317 */
318 pci_walk_bus(dev->bus, cb, &result_data);
319 }
320
321 return result_data.result;
322}
323
324struct find_aer_service_data {
325 struct pcie_port_service_driver *aer_driver;
326 int is_downstream;
327};
328
329static int find_aer_service_iter(struct device *device, void *data)
330{
331 struct device_driver *driver;
332 struct pcie_port_service_driver *service_driver;
333 struct pcie_device *pcie_dev;
334 struct find_aer_service_data *result;
335
336 result = (struct find_aer_service_data *) data;
337
338 if (device->bus == &pcie_port_bus_type) {
339 pcie_dev = to_pcie_device(device);
340 if (pcie_dev->id.port_type == PCIE_SW_DOWNSTREAM_PORT)
341 result->is_downstream = 1;
342
343 driver = device->driver;
344 if (driver) {
345 service_driver = to_service_driver(driver);
346 if (service_driver->id_table->service_type ==
347 PCIE_PORT_SERVICE_AER) {
348 result->aer_driver = service_driver;
349 return 1;
350 }
351 }
352 }
353
354 return 0;
355}
356
357static void find_aer_service(struct pci_dev *dev,
358 struct find_aer_service_data *data)
359{
360 int retval;
361 retval = device_for_each_child(&dev->dev, data, find_aer_service_iter);
362}
363
364static pci_ers_result_t reset_link(struct pcie_device *aerdev,
365 struct pci_dev *dev)
366{
367 struct pci_dev *udev;
368 pci_ers_result_t status;
369 struct find_aer_service_data data;
370
371 if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE)
372 udev = dev;
373 else
374 udev= dev->bus->self;
375
376 data.is_downstream = 0;
377 data.aer_driver = NULL;
378 find_aer_service(udev, &data);
379
380 /*
381 * Use the aer driver of the error agent firstly.
382 * If it hasn't the aer driver, use the root port's
383 */
384 if (!data.aer_driver || !data.aer_driver->reset_link) {
385 if (data.is_downstream &&
386 aerdev->device.driver &&
387 to_service_driver(aerdev->device.driver)->reset_link) {
388 data.aer_driver =
389 to_service_driver(aerdev->device.driver);
390 } else {
391 printk(KERN_DEBUG "No link-reset support to Device ID"
392 "[%s]\n",
393 dev->dev.bus_id);
394 return PCI_ERS_RESULT_DISCONNECT;
395 }
396 }
397
398 status = data.aer_driver->reset_link(udev);
399 if (status != PCI_ERS_RESULT_RECOVERED) {
400 printk(KERN_DEBUG "Link reset at upstream Device ID"
401 "[%s] failed\n",
402 udev->dev.bus_id);
403 return PCI_ERS_RESULT_DISCONNECT;
404 }
405
406 return status;
407}
408
409/**
410 * do_recovery - handle nonfatal/fatal error recovery process
411 * @aerdev: pointer to a pcie_device data structure of root port
412 * @dev: pointer to a pci_dev data structure of agent detecting an error
413 * @severity: error severity type
414 *
415 * Invoked when an error is nonfatal/fatal. Once being invoked, broadcast
416 * error detected message to all downstream drivers within a hierarchy in
417 * question and return the returned code.
418 **/
419static pci_ers_result_t do_recovery(struct pcie_device *aerdev,
420 struct pci_dev *dev,
421 int severity)
422{
423 pci_ers_result_t status, result = PCI_ERS_RESULT_RECOVERED;
424 enum pci_channel_state state;
425
426 if (severity == AER_FATAL)
427 state = pci_channel_io_frozen;
428 else
429 state = pci_channel_io_normal;
430
431 status = broadcast_error_message(dev,
432 state,
433 "error_detected",
434 report_error_detected);
435
436 if (severity == AER_FATAL) {
437 result = reset_link(aerdev, dev);
438 if (result != PCI_ERS_RESULT_RECOVERED) {
439 /* TODO: Should panic here? */
440 return result;
441 }
442 }
443
444 if (status == PCI_ERS_RESULT_CAN_RECOVER)
445 status = broadcast_error_message(dev,
446 state,
447 "mmio_enabled",
448 report_mmio_enabled);
449
450 if (status == PCI_ERS_RESULT_NEED_RESET) {
451 /*
452 * TODO: Should call platform-specific
453 * functions to reset slot before calling
454 * drivers' slot_reset callbacks?
455 */
456 status = broadcast_error_message(dev,
457 state,
458 "slot_reset",
459 report_slot_reset);
460 }
461
462 if (status == PCI_ERS_RESULT_RECOVERED)
463 broadcast_error_message(dev,
464 state,
465 "resume",
466 report_resume);
467
468 return status;
469}
470
471/**
472 * handle_error_source - handle logging error into an event log
473 * @aerdev: pointer to pcie_device data structure of the root port
474 * @dev: pointer to pci_dev data structure of error source device
475 * @info: comprehensive error information
476 *
477 * Invoked when an error being detected by Root Port.
478 **/
479static void handle_error_source(struct pcie_device * aerdev,
480 struct pci_dev *dev,
481 struct aer_err_info info)
482{
483 pci_ers_result_t status = 0;
484 int pos;
485
486 if (info.severity == AER_CORRECTABLE) {
487 /*
488 * Correctable error does not need software intevention.
489 * No need to go through error recovery process.
490 */
491 pos = pci_find_aer_capability(dev);
492 if (pos)
493 pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS,
494 info.status);
495 } else {
496 status = do_recovery(aerdev, dev, info.severity);
497 if (status == PCI_ERS_RESULT_RECOVERED) {
498 printk(KERN_DEBUG "AER driver successfully recovered\n");
499 } else {
500 /* TODO: Should kernel panic here? */
501 printk(KERN_DEBUG "AER driver didn't recover\n");
502 }
503 }
504}
505
506/**
507 * aer_enable_rootport - enable Root Port's interrupts when receiving messages
508 * @rpc: pointer to a Root Port data structure
509 *
510 * Invoked when PCIE bus loads AER service driver.
511 **/
512void aer_enable_rootport(struct aer_rpc *rpc)
513{
514 struct pci_dev *pdev = rpc->rpd->port;
515 int pos, aer_pos;
516 u16 reg16;
517 u32 reg32;
518
519 pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
520 /* Clear PCIE Capability's Device Status */
521 pci_read_config_word(pdev, pos+PCI_EXP_DEVSTA, &reg16);
522 pci_write_config_word(pdev, pos+PCI_EXP_DEVSTA, reg16);
523
524 /* Disable system error generation in response to error messages */
525 pci_read_config_word(pdev, pos + PCI_EXP_RTCTL, &reg16);
526 reg16 &= ~(SYSTEM_ERROR_INTR_ON_MESG_MASK);
527 pci_write_config_word(pdev, pos + PCI_EXP_RTCTL, reg16);
528
529 aer_pos = pci_find_aer_capability(pdev);
530 /* Clear error status */
531 pci_read_config_dword(pdev, aer_pos + PCI_ERR_ROOT_STATUS, &reg32);
532 pci_write_config_dword(pdev, aer_pos + PCI_ERR_ROOT_STATUS, reg32);
533 pci_read_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, &reg32);
534 pci_write_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, reg32);
535 pci_read_config_dword(pdev, aer_pos + PCI_ERR_UNCOR_STATUS, &reg32);
536 pci_write_config_dword(pdev, aer_pos + PCI_ERR_UNCOR_STATUS, reg32);
537
538 /* Enable Root Port device reporting error itself */
539 pci_read_config_word(pdev, pos+PCI_EXP_DEVCTL, &reg16);
540 reg16 = reg16 |
541 PCI_EXP_DEVCTL_CERE |
542 PCI_EXP_DEVCTL_NFERE |
543 PCI_EXP_DEVCTL_FERE |
544 PCI_EXP_DEVCTL_URRE;
545 pci_write_config_word(pdev, pos+PCI_EXP_DEVCTL,
546 reg16);
547
548 /* Enable Root Port's interrupt in response to error messages */
549 pci_write_config_dword(pdev,
550 aer_pos + PCI_ERR_ROOT_COMMAND,
551 ROOT_PORT_INTR_ON_MESG_MASK);
552}
553
554/**
555 * disable_root_aer - disable Root Port's interrupts when receiving messages
556 * @rpc: pointer to a Root Port data structure
557 *
558 * Invoked when PCIE bus unloads AER service driver.
559 **/
560static void disable_root_aer(struct aer_rpc *rpc)
561{
562 struct pci_dev *pdev = rpc->rpd->port;
563 u32 reg32;
564 int pos;
565
566 pos = pci_find_aer_capability(pdev);
567 /* Disable Root's interrupt in response to error messages */
568 pci_write_config_dword(pdev, pos + PCI_ERR_ROOT_COMMAND, 0);
569
570 /* Clear Root's error status reg */
571 pci_read_config_dword(pdev, pos + PCI_ERR_ROOT_STATUS, &reg32);
572 pci_write_config_dword(pdev, pos + PCI_ERR_ROOT_STATUS, reg32);
573}
574
575/**
576 * get_e_source - retrieve an error source
577 * @rpc: pointer to the root port which holds an error
578 *
579 * Invoked by DPC handler to consume an error.
580 **/
581static struct aer_err_source* get_e_source(struct aer_rpc *rpc)
582{
583 struct aer_err_source *e_source;
584 unsigned long flags;
585
586 /* Lock access to Root error producer/consumer index */
587 spin_lock_irqsave(&rpc->e_lock, flags);
588 if (rpc->prod_idx == rpc->cons_idx) {
589 spin_unlock_irqrestore(&rpc->e_lock, flags);
590 return NULL;
591 }
592 e_source = &rpc->e_sources[rpc->cons_idx];
593 rpc->cons_idx++;
594 if (rpc->cons_idx == AER_ERROR_SOURCES_MAX)
595 rpc->cons_idx = 0;
596 spin_unlock_irqrestore(&rpc->e_lock, flags);
597
598 return e_source;
599}
600
601static int get_device_error_info(struct pci_dev *dev, struct aer_err_info *info)
602{
603 int pos;
604
605 pos = pci_find_aer_capability(dev);
606
607 /* The device might not support AER */
608 if (!pos)
609 return AER_SUCCESS;
610
611 if (info->severity == AER_CORRECTABLE) {
612 pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS,
613 &info->status);
614 if (!(info->status & ERR_CORRECTABLE_ERROR_MASK))
615 return AER_UNSUCCESS;
616 } else if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE ||
617 info->severity == AER_NONFATAL) {
618
619 /* Link is still healthy for IO reads */
620 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS,
621 &info->status);
622 if (!(info->status & ERR_UNCORRECTABLE_ERROR_MASK))
623 return AER_UNSUCCESS;
624
625 if (info->status & AER_LOG_TLP_MASKS) {
626 info->flags |= AER_TLP_HEADER_VALID_FLAG;
627 pci_read_config_dword(dev,
628 pos + PCI_ERR_HEADER_LOG, &info->tlp.dw0);
629 pci_read_config_dword(dev,
630 pos + PCI_ERR_HEADER_LOG + 4, &info->tlp.dw1);
631 pci_read_config_dword(dev,
632 pos + PCI_ERR_HEADER_LOG + 8, &info->tlp.dw2);
633 pci_read_config_dword(dev,
634 pos + PCI_ERR_HEADER_LOG + 12, &info->tlp.dw3);
635 }
636 }
637
638 return AER_SUCCESS;
639}
640
641/**
642 * aer_isr_one_error - consume an error detected by root port
643 * @p_device: pointer to error root port service device
644 * @e_src: pointer to an error source
645 **/
646static void aer_isr_one_error(struct pcie_device *p_device,
647 struct aer_err_source *e_src)
648{
649 struct device *s_device;
650 struct aer_err_info e_info = {0, 0, 0,};
651 int i;
652 u16 id;
653
654 /*
655 * There is a possibility that both correctable error and
656 * uncorrectable error being logged. Report correctable error first.
657 */
658 for (i = 1; i & ROOT_ERR_STATUS_MASKS ; i <<= 2) {
659 if (i > 4)
660 break;
661 if (!(e_src->status & i))
662 continue;
663
664 /* Init comprehensive error information */
665 if (i & PCI_ERR_ROOT_COR_RCV) {
666 id = ERR_COR_ID(e_src->id);
667 e_info.severity = AER_CORRECTABLE;
668 } else {
669 id = ERR_UNCOR_ID(e_src->id);
670 e_info.severity = ((e_src->status >> 6) & 1);
671 }
672 if (e_src->status &
673 (PCI_ERR_ROOT_MULTI_COR_RCV |
674 PCI_ERR_ROOT_MULTI_UNCOR_RCV))
675 e_info.flags |= AER_MULTI_ERROR_VALID_FLAG;
676 if (!(s_device = find_source_device(p_device->port, id))) {
677 printk(KERN_DEBUG "%s->can't find device of ID%04x\n",
678 __FUNCTION__, id);
679 continue;
680 }
681 if (get_device_error_info(to_pci_dev(s_device), &e_info) ==
682 AER_SUCCESS) {
683 aer_print_error(to_pci_dev(s_device), &e_info);
684 handle_error_source(p_device,
685 to_pci_dev(s_device),
686 e_info);
687 }
688 }
689}
690
691/**
692 * aer_isr - consume errors detected by root port
693 * @context: pointer to a private data of pcie device
694 *
695 * Invoked, as DPC, when root port records new detected error
696 **/
697void aer_isr(void *context)
698{
699 struct pcie_device *p_device = (struct pcie_device *) context;
700 struct aer_rpc *rpc = get_service_data(p_device);
701 struct aer_err_source *e_src;
702
703 mutex_lock(&rpc->rpc_mutex);
704 e_src = get_e_source(rpc);
705 while (e_src) {
706 aer_isr_one_error(p_device, e_src);
707 e_src = get_e_source(rpc);
708 }
709 mutex_unlock(&rpc->rpc_mutex);
710
711 wake_up(&rpc->wait_release);
712}
713
714/**
715 * aer_delete_rootport - disable root port aer and delete service data
716 * @rpc: pointer to a root port device being deleted
717 *
718 * Invoked when AER service unloaded on a specific Root Port
719 **/
720void aer_delete_rootport(struct aer_rpc *rpc)
721{
722 /* Disable root port AER itself */
723 disable_root_aer(rpc);
724
725 kfree(rpc);
726}
727
728/**
729 * aer_init - provide AER initialization
730 * @dev: pointer to AER pcie device
731 *
732 * Invoked when AER service driver is loaded.
733 **/
734int aer_init(struct pcie_device *dev)
735{
736 int status;
737
738 /* Run _OSC Method */
739 status = aer_osc_setup(dev->port);
740
741 if(status != OSC_METHOD_RUN_SUCCESS) {
742 printk(KERN_DEBUG "%s: AER service init fails - %s\n",
743 __FUNCTION__,
744 (status == OSC_METHOD_NOT_SUPPORTED) ?
745 "No ACPI _OSC support" : "Run ACPI _OSC fails");
746
747 if (!forceload)
748 return status;
749 }
750
751 return AER_SUCCESS;
752}
753
754EXPORT_SYMBOL_GPL(pci_find_aer_capability);
755EXPORT_SYMBOL_GPL(pci_enable_pcie_error_reporting);
756EXPORT_SYMBOL_GPL(pci_disable_pcie_error_reporting);
757EXPORT_SYMBOL_GPL(pci_cleanup_aer_uncorrect_error_status);
758
diff --git a/drivers/pci/pcie/aer/aerdrv_errprint.c b/drivers/pci/pcie/aer/aerdrv_errprint.c
new file mode 100644
index 000000000000..3933d4f30e8c
--- /dev/null
+++ b/drivers/pci/pcie/aer/aerdrv_errprint.c
@@ -0,0 +1,248 @@
1/*
2 * drivers/pci/pcie/aer/aerdrv_errprint.c
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Format error messages and print them to console.
9 *
10 * Copyright (C) 2006 Intel Corp.
11 * Tom Long Nguyen (tom.l.nguyen@intel.com)
12 * Zhang Yanmin (yanmin.zhang@intel.com)
13 *
14 */
15
16#include <linux/module.h>
17#include <linux/pci.h>
18#include <linux/kernel.h>
19#include <linux/errno.h>
20#include <linux/pm.h>
21#include <linux/suspend.h>
22
23#include "aerdrv.h"
24
25#define AER_AGENT_RECEIVER 0
26#define AER_AGENT_REQUESTER 1
27#define AER_AGENT_COMPLETER 2
28#define AER_AGENT_TRANSMITTER 3
29
30#define AER_AGENT_REQUESTER_MASK (PCI_ERR_UNC_COMP_TIME| \
31 PCI_ERR_UNC_UNSUP)
32
33#define AER_AGENT_COMPLETER_MASK PCI_ERR_UNC_COMP_ABORT
34
35#define AER_AGENT_TRANSMITTER_MASK(t, e) (e & (PCI_ERR_COR_REP_ROLL| \
36 ((t == AER_CORRECTABLE) ? PCI_ERR_COR_REP_TIMER: 0)))
37
38#define AER_GET_AGENT(t, e) \
39 ((e & AER_AGENT_COMPLETER_MASK) ? AER_AGENT_COMPLETER : \
40 (e & AER_AGENT_REQUESTER_MASK) ? AER_AGENT_REQUESTER : \
41 (AER_AGENT_TRANSMITTER_MASK(t, e)) ? AER_AGENT_TRANSMITTER : \
42 AER_AGENT_RECEIVER)
43
44#define AER_PHYSICAL_LAYER_ERROR_MASK PCI_ERR_COR_RCVR
45#define AER_DATA_LINK_LAYER_ERROR_MASK(t, e) \
46 (PCI_ERR_UNC_DLP| \
47 PCI_ERR_COR_BAD_TLP| \
48 PCI_ERR_COR_BAD_DLLP| \
49 PCI_ERR_COR_REP_ROLL| \
50 ((t == AER_CORRECTABLE) ? \
51 PCI_ERR_COR_REP_TIMER: 0))
52
53#define AER_PHYSICAL_LAYER_ERROR 0
54#define AER_DATA_LINK_LAYER_ERROR 1
55#define AER_TRANSACTION_LAYER_ERROR 2
56
57#define AER_GET_LAYER_ERROR(t, e) \
58 ((e & AER_PHYSICAL_LAYER_ERROR_MASK) ? \
59 AER_PHYSICAL_LAYER_ERROR : \
60 (e & AER_DATA_LINK_LAYER_ERROR_MASK(t, e)) ? \
61 AER_DATA_LINK_LAYER_ERROR : \
62 AER_TRANSACTION_LAYER_ERROR)
63
64/*
65 * AER error strings
66 */
67static char* aer_error_severity_string[] = {
68 "Uncorrected (Non-Fatal)",
69 "Uncorrected (Fatal)",
70 "Corrected"
71};
72
73static char* aer_error_layer[] = {
74 "Physical Layer",
75 "Data Link Layer",
76 "Transaction Layer"
77};
78static char* aer_correctable_error_string[] = {
79 "Receiver Error ", /* Bit Position 0 */
80 NULL,
81 NULL,
82 NULL,
83 NULL,
84 NULL,
85 "Bad TLP ", /* Bit Position 6 */
86 "Bad DLLP ", /* Bit Position 7 */
87 "RELAY_NUM Rollover ", /* Bit Position 8 */
88 NULL,
89 NULL,
90 NULL,
91 "Replay Timer Timeout ", /* Bit Position 12 */
92 "Advisory Non-Fatal ", /* Bit Position 13 */
93 NULL,
94 NULL,
95 NULL,
96 NULL,
97 NULL,
98 NULL,
99 NULL,
100 NULL,
101 NULL,
102 NULL,
103 NULL,
104 NULL,
105 NULL,
106 NULL,
107 NULL,
108 NULL,
109 NULL,
110 NULL,
111};
112
113static char* aer_uncorrectable_error_string[] = {
114 NULL,
115 NULL,
116 NULL,
117 NULL,
118 "Data Link Protocol ", /* Bit Position 4 */
119 NULL,
120 NULL,
121 NULL,
122 NULL,
123 NULL,
124 NULL,
125 NULL,
126 "Poisoned TLP ", /* Bit Position 12 */
127 "Flow Control Protocol ", /* Bit Position 13 */
128 "Completion Timeout ", /* Bit Position 14 */
129 "Completer Abort ", /* Bit Position 15 */
130 "Unexpected Completion ", /* Bit Position 16 */
131 "Receiver Overflow ", /* Bit Position 17 */
132 "Malformed TLP ", /* Bit Position 18 */
133 "ECRC ", /* Bit Position 19 */
134 "Unsupported Request ", /* Bit Position 20 */
135 NULL,
136 NULL,
137 NULL,
138 NULL,
139 NULL,
140 NULL,
141 NULL,
142 NULL,
143 NULL,
144 NULL,
145 NULL,
146};
147
148static char* aer_agent_string[] = {
149 "Receiver ID",
150 "Requester ID",
151 "Completer ID",
152 "Transmitter ID"
153};
154
155static char * aer_get_error_source_name(int severity,
156 unsigned int status,
157 char errmsg_buff[])
158{
159 int i;
160 char * errmsg = NULL;
161
162 for (i = 0; i < 32; i++) {
163 if (!(status & (1 << i)))
164 continue;
165
166 if (severity == AER_CORRECTABLE)
167 errmsg = aer_correctable_error_string[i];
168 else
169 errmsg = aer_uncorrectable_error_string[i];
170
171 if (!errmsg) {
172 sprintf(errmsg_buff, "Unknown Error Bit %2d ", i);
173 errmsg = errmsg_buff;
174 }
175
176 break;
177 }
178
179 return errmsg;
180}
181
182static DEFINE_SPINLOCK(logbuf_lock);
183static char errmsg_buff[100];
184void aer_print_error(struct pci_dev *dev, struct aer_err_info *info)
185{
186 char * errmsg;
187 int err_layer, agent;
188 char * loglevel;
189
190 if (info->severity == AER_CORRECTABLE)
191 loglevel = KERN_WARNING;
192 else
193 loglevel = KERN_ERR;
194
195 printk("%s+------ PCI-Express Device Error ------+\n", loglevel);
196 printk("%sError Severity\t\t: %s\n", loglevel,
197 aer_error_severity_string[info->severity]);
198
199 if ( info->status == 0) {
200 printk("%sPCIE Bus Error type\t: (Unaccessible)\n", loglevel);
201 printk("%sUnaccessible Received\t: %s\n", loglevel,
202 info->flags & AER_MULTI_ERROR_VALID_FLAG ?
203 "Multiple" : "First");
204 printk("%sUnregistered Agent ID\t: %04x\n", loglevel,
205 (dev->bus->number << 8) | dev->devfn);
206 } else {
207 err_layer = AER_GET_LAYER_ERROR(info->severity, info->status);
208 printk("%sPCIE Bus Error type\t: %s\n", loglevel,
209 aer_error_layer[err_layer]);
210
211 spin_lock(&logbuf_lock);
212 errmsg = aer_get_error_source_name(info->severity,
213 info->status,
214 errmsg_buff);
215 printk("%s%s\t: %s\n", loglevel, errmsg,
216 info->flags & AER_MULTI_ERROR_VALID_FLAG ?
217 "Multiple" : "First");
218 spin_unlock(&logbuf_lock);
219
220 agent = AER_GET_AGENT(info->severity, info->status);
221 printk("%s%s\t\t: %04x\n", loglevel,
222 aer_agent_string[agent],
223 (dev->bus->number << 8) | dev->devfn);
224
225 printk("%sVendorID=%04xh, DeviceID=%04xh,"
226 " Bus=%02xh, Device=%02xh, Function=%02xh\n",
227 loglevel,
228 dev->vendor,
229 dev->device,
230 dev->bus->number,
231 PCI_SLOT(dev->devfn),
232 PCI_FUNC(dev->devfn));
233
234 if (info->flags & AER_TLP_HEADER_VALID_FLAG) {
235 unsigned char *tlp = (unsigned char *) &info->tlp;
236 printk("%sTLB Header:\n", loglevel);
237 printk("%s%02x%02x%02x%02x %02x%02x%02x%02x"
238 " %02x%02x%02x%02x %02x%02x%02x%02x\n",
239 loglevel,
240 *(tlp + 3), *(tlp + 2), *(tlp + 1), *tlp,
241 *(tlp + 7), *(tlp + 6), *(tlp + 5), *(tlp + 4),
242 *(tlp + 11), *(tlp + 10), *(tlp + 9),
243 *(tlp + 8), *(tlp + 15), *(tlp + 14),
244 *(tlp + 13), *(tlp + 12));
245 }
246 }
247}
248
diff --git a/drivers/pci/pcie/portdrv.h b/drivers/pci/pcie/portdrv.h
index 1d317d22ee89..67fcd176babd 100644
--- a/drivers/pci/pcie/portdrv.h
+++ b/drivers/pci/pcie/portdrv.h
@@ -39,7 +39,7 @@ extern int pcie_port_device_suspend(struct pci_dev *dev, pm_message_t state);
39extern int pcie_port_device_resume(struct pci_dev *dev); 39extern int pcie_port_device_resume(struct pci_dev *dev);
40#endif 40#endif
41extern void pcie_port_device_remove(struct pci_dev *dev); 41extern void pcie_port_device_remove(struct pci_dev *dev);
42extern void pcie_port_bus_register(void); 42extern int pcie_port_bus_register(void);
43extern void pcie_port_bus_unregister(void); 43extern void pcie_port_bus_unregister(void);
44 44
45#endif /* _PORTDRV_H_ */ 45#endif /* _PORTDRV_H_ */
diff --git a/drivers/pci/pcie/portdrv_bus.c b/drivers/pci/pcie/portdrv_bus.c
index 3e84b501e6a4..3f0976868eda 100644
--- a/drivers/pci/pcie/portdrv_bus.c
+++ b/drivers/pci/pcie/portdrv_bus.c
@@ -24,6 +24,7 @@ struct bus_type pcie_port_bus_type = {
24 .suspend = pcie_port_bus_suspend, 24 .suspend = pcie_port_bus_suspend,
25 .resume = pcie_port_bus_resume, 25 .resume = pcie_port_bus_resume,
26}; 26};
27EXPORT_SYMBOL_GPL(pcie_port_bus_type);
27 28
28static int pcie_port_bus_match(struct device *dev, struct device_driver *drv) 29static int pcie_port_bus_match(struct device *dev, struct device_driver *drv)
29{ 30{
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index 55c662267868..bd6615b4d40e 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -6,6 +6,7 @@
6 * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com) 6 * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com)
7 */ 7 */
8 8
9#include <linux/compiler.h>
9#include <linux/module.h> 10#include <linux/module.h>
10#include <linux/pci.h> 11#include <linux/pci.h>
11#include <linux/kernel.h> 12#include <linux/kernel.h>
@@ -339,8 +340,7 @@ static int suspend_iter(struct device *dev, void *data)
339 340
340int pcie_port_device_suspend(struct pci_dev *dev, pm_message_t state) 341int pcie_port_device_suspend(struct pci_dev *dev, pm_message_t state)
341{ 342{
342 device_for_each_child(&dev->dev, &state, suspend_iter); 343 return device_for_each_child(&dev->dev, &state, suspend_iter);
343 return 0;
344} 344}
345 345
346static int resume_iter(struct device *dev, void *data) 346static int resume_iter(struct device *dev, void *data)
@@ -358,8 +358,7 @@ static int resume_iter(struct device *dev, void *data)
358 358
359int pcie_port_device_resume(struct pci_dev *dev) 359int pcie_port_device_resume(struct pci_dev *dev)
360{ 360{
361 device_for_each_child(&dev->dev, NULL, resume_iter); 361 return device_for_each_child(&dev->dev, NULL, resume_iter);
362 return 0;
363} 362}
364#endif 363#endif
365 364
@@ -402,9 +401,9 @@ void pcie_port_device_remove(struct pci_dev *dev)
402 pci_disable_msi(dev); 401 pci_disable_msi(dev);
403} 402}
404 403
405void pcie_port_bus_register(void) 404int __must_check pcie_port_bus_register(void)
406{ 405{
407 bus_register(&pcie_port_bus_type); 406 return bus_register(&pcie_port_bus_type);
408} 407}
409 408
410void pcie_port_bus_unregister(void) 409void pcie_port_bus_unregister(void)
diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
index 478d0d28f7ad..037690e08f5f 100644
--- a/drivers/pci/pcie/portdrv_pci.c
+++ b/drivers/pci/pcie/portdrv_pci.c
@@ -14,8 +14,10 @@
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/pcieport_if.h> 16#include <linux/pcieport_if.h>
17#include <linux/aer.h>
17 18
18#include "portdrv.h" 19#include "portdrv.h"
20#include "aer/aerdrv.h"
19 21
20/* 22/*
21 * Version Information 23 * Version Information
@@ -30,6 +32,43 @@ MODULE_LICENSE("GPL");
30/* global data */ 32/* global data */
31static const char device_name[] = "pcieport-driver"; 33static const char device_name[] = "pcieport-driver";
32 34
35static int pcie_portdrv_save_config(struct pci_dev *dev)
36{
37 return pci_save_state(dev);
38}
39
40#ifdef CONFIG_PM
41static int pcie_portdrv_restore_config(struct pci_dev *dev)
42{
43 int retval;
44
45 pci_restore_state(dev);
46 retval = pci_enable_device(dev);
47 if (retval)
48 return retval;
49 pci_set_master(dev);
50 return 0;
51}
52
53static int pcie_portdrv_suspend(struct pci_dev *dev, pm_message_t state)
54{
55 int ret = pcie_port_device_suspend(dev, state);
56
57 if (!ret)
58 ret = pcie_portdrv_save_config(dev);
59 return ret;
60}
61
62static int pcie_portdrv_resume(struct pci_dev *dev)
63{
64 pcie_portdrv_restore_config(dev);
65 return pcie_port_device_resume(dev);
66}
67#else
68#define pcie_portdrv_suspend NULL
69#define pcie_portdrv_resume NULL
70#endif
71
33/* 72/*
34 * pcie_portdrv_probe - Probe PCI-Express port devices 73 * pcie_portdrv_probe - Probe PCI-Express port devices
35 * @dev: PCI-Express port device being probed 74 * @dev: PCI-Express port device being probed
@@ -61,6 +100,10 @@ static int __devinit pcie_portdrv_probe (struct pci_dev *dev,
61 return -ENOMEM; 100 return -ENOMEM;
62 } 101 }
63 102
103 pcie_portdrv_save_config(dev);
104
105 pci_enable_pcie_error_reporting(dev);
106
64 return 0; 107 return 0;
65} 108}
66 109
@@ -70,39 +113,151 @@ static void pcie_portdrv_remove (struct pci_dev *dev)
70 kfree(pci_get_drvdata(dev)); 113 kfree(pci_get_drvdata(dev));
71} 114}
72 115
73#ifdef CONFIG_PM 116static int error_detected_iter(struct device *device, void *data)
74static int pcie_portdrv_save_config(struct pci_dev *dev)
75{ 117{
76 return pci_save_state(dev); 118 struct pcie_device *pcie_device;
119 struct pcie_port_service_driver *driver;
120 struct aer_broadcast_data *result_data;
121 pci_ers_result_t status;
122
123 result_data = (struct aer_broadcast_data *) data;
124
125 if (device->bus == &pcie_port_bus_type && device->driver) {
126 driver = to_service_driver(device->driver);
127 if (!driver ||
128 !driver->err_handler ||
129 !driver->err_handler->error_detected)
130 return 0;
131
132 pcie_device = to_pcie_device(device);
133
134 /* Forward error detected message to service drivers */
135 status = driver->err_handler->error_detected(
136 pcie_device->port,
137 result_data->state);
138 result_data->result =
139 merge_result(result_data->result, status);
140 }
141
142 return 0;
77} 143}
78 144
79static int pcie_portdrv_restore_config(struct pci_dev *dev) 145static pci_ers_result_t pcie_portdrv_error_detected(struct pci_dev *dev,
146 enum pci_channel_state error)
80{ 147{
148 struct aer_broadcast_data result_data =
149 {error, PCI_ERS_RESULT_CAN_RECOVER};
81 int retval; 150 int retval;
82 151
83 pci_restore_state(dev); 152 /* can not fail */
84 retval = pci_enable_device(dev); 153 retval = device_for_each_child(&dev->dev, &result_data, error_detected_iter);
85 if (retval) 154
86 return retval; 155 return result_data.result;
87 pci_set_master(dev); 156}
157
158static int mmio_enabled_iter(struct device *device, void *data)
159{
160 struct pcie_device *pcie_device;
161 struct pcie_port_service_driver *driver;
162 pci_ers_result_t status, *result;
163
164 result = (pci_ers_result_t *) data;
165
166 if (device->bus == &pcie_port_bus_type && device->driver) {
167 driver = to_service_driver(device->driver);
168 if (driver &&
169 driver->err_handler &&
170 driver->err_handler->mmio_enabled) {
171 pcie_device = to_pcie_device(device);
172
173 /* Forward error message to service drivers */
174 status = driver->err_handler->mmio_enabled(
175 pcie_device->port);
176 *result = merge_result(*result, status);
177 }
178 }
179
88 return 0; 180 return 0;
89} 181}
90 182
91static int pcie_portdrv_suspend (struct pci_dev *dev, pm_message_t state) 183static pci_ers_result_t pcie_portdrv_mmio_enabled(struct pci_dev *dev)
92{ 184{
93 int ret = pcie_port_device_suspend(dev, state); 185 pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
186 int retval;
94 187
95 if (!ret) 188 /* get true return value from &status */
96 ret = pcie_portdrv_save_config(dev); 189 retval = device_for_each_child(&dev->dev, &status, mmio_enabled_iter);
97 return ret; 190 return status;
98} 191}
99 192
100static int pcie_portdrv_resume (struct pci_dev *dev) 193static int slot_reset_iter(struct device *device, void *data)
101{ 194{
102 pcie_portdrv_restore_config(dev); 195 struct pcie_device *pcie_device;
103 return pcie_port_device_resume(dev); 196 struct pcie_port_service_driver *driver;
197 pci_ers_result_t status, *result;
198
199 result = (pci_ers_result_t *) data;
200
201 if (device->bus == &pcie_port_bus_type && device->driver) {
202 driver = to_service_driver(device->driver);
203 if (driver &&
204 driver->err_handler &&
205 driver->err_handler->slot_reset) {
206 pcie_device = to_pcie_device(device);
207
208 /* Forward error message to service drivers */
209 status = driver->err_handler->slot_reset(
210 pcie_device->port);
211 *result = merge_result(*result, status);
212 }
213 }
214
215 return 0;
216}
217
218static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
219{
220 pci_ers_result_t status;
221 int retval;
222
223 /* If fatal, restore cfg space for possible link reset at upstream */
224 if (dev->error_state == pci_channel_io_frozen) {
225 pcie_portdrv_restore_config(dev);
226 pci_enable_pcie_error_reporting(dev);
227 }
228
229 /* get true return value from &status */
230 retval = device_for_each_child(&dev->dev, &status, slot_reset_iter);
231
232 return status;
233}
234
235static int resume_iter(struct device *device, void *data)
236{
237 struct pcie_device *pcie_device;
238 struct pcie_port_service_driver *driver;
239
240 if (device->bus == &pcie_port_bus_type && device->driver) {
241 driver = to_service_driver(device->driver);
242 if (driver &&
243 driver->err_handler &&
244 driver->err_handler->resume) {
245 pcie_device = to_pcie_device(device);
246
247 /* Forward error message to service drivers */
248 driver->err_handler->resume(pcie_device->port);
249 }
250 }
251
252 return 0;
253}
254
255static void pcie_portdrv_err_resume(struct pci_dev *dev)
256{
257 int retval;
258 /* nothing to do with error value, if it ever happens */
259 retval = device_for_each_child(&dev->dev, NULL, resume_iter);
104} 260}
105#endif
106 261
107/* 262/*
108 * LINUX Device Driver Model 263 * LINUX Device Driver Model
@@ -114,6 +269,13 @@ static const struct pci_device_id port_pci_ids[] = { {
114}; 269};
115MODULE_DEVICE_TABLE(pci, port_pci_ids); 270MODULE_DEVICE_TABLE(pci, port_pci_ids);
116 271
272static struct pci_error_handlers pcie_portdrv_err_handler = {
273 .error_detected = pcie_portdrv_error_detected,
274 .mmio_enabled = pcie_portdrv_mmio_enabled,
275 .slot_reset = pcie_portdrv_slot_reset,
276 .resume = pcie_portdrv_err_resume,
277};
278
117static struct pci_driver pcie_portdrv = { 279static struct pci_driver pcie_portdrv = {
118 .name = (char *)device_name, 280 .name = (char *)device_name,
119 .id_table = &port_pci_ids[0], 281 .id_table = &port_pci_ids[0],
@@ -121,20 +283,25 @@ static struct pci_driver pcie_portdrv = {
121 .probe = pcie_portdrv_probe, 283 .probe = pcie_portdrv_probe,
122 .remove = pcie_portdrv_remove, 284 .remove = pcie_portdrv_remove,
123 285
124#ifdef CONFIG_PM
125 .suspend = pcie_portdrv_suspend, 286 .suspend = pcie_portdrv_suspend,
126 .resume = pcie_portdrv_resume, 287 .resume = pcie_portdrv_resume,
127#endif /* PM */ 288
289 .err_handler = &pcie_portdrv_err_handler,
128}; 290};
129 291
130static int __init pcie_portdrv_init(void) 292static int __init pcie_portdrv_init(void)
131{ 293{
132 int retval = 0; 294 int retval;
133 295
134 pcie_port_bus_register(); 296 retval = pcie_port_bus_register();
297 if (retval) {
298 printk(KERN_WARNING "PCIE: bus_register error: %d\n", retval);
299 goto out;
300 }
135 retval = pci_register_driver(&pcie_portdrv); 301 retval = pci_register_driver(&pcie_portdrv);
136 if (retval) 302 if (retval)
137 pcie_port_bus_unregister(); 303 pcie_port_bus_unregister();
304 out:
138 return retval; 305 return retval;
139} 306}
140 307
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index c5a58d1c6c1c..a3b0a5eb5054 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -339,6 +339,7 @@ pci_alloc_child_bus(struct pci_bus *parent, struct pci_dev *bridge, int busnr)
339{ 339{
340 struct pci_bus *child; 340 struct pci_bus *child;
341 int i; 341 int i;
342 int retval;
342 343
343 /* 344 /*
344 * Allocate a new bus, and inherit stuff from the parent.. 345 * Allocate a new bus, and inherit stuff from the parent..
@@ -356,8 +357,13 @@ pci_alloc_child_bus(struct pci_bus *parent, struct pci_dev *bridge, int busnr)
356 357
357 child->class_dev.class = &pcibus_class; 358 child->class_dev.class = &pcibus_class;
358 sprintf(child->class_dev.class_id, "%04x:%02x", pci_domain_nr(child), busnr); 359 sprintf(child->class_dev.class_id, "%04x:%02x", pci_domain_nr(child), busnr);
359 class_device_register(&child->class_dev); 360 retval = class_device_register(&child->class_dev);
360 class_device_create_file(&child->class_dev, &class_device_attr_cpuaffinity); 361 if (retval)
362 goto error_register;
363 retval = class_device_create_file(&child->class_dev,
364 &class_device_attr_cpuaffinity);
365 if (retval)
366 goto error_file_create;
361 367
362 /* 368 /*
363 * Set up the primary, secondary and subordinate 369 * Set up the primary, secondary and subordinate
@@ -375,6 +381,12 @@ pci_alloc_child_bus(struct pci_bus *parent, struct pci_dev *bridge, int busnr)
375 bridge->subordinate = child; 381 bridge->subordinate = child;
376 382
377 return child; 383 return child;
384
385error_file_create:
386 class_device_unregister(&child->class_dev);
387error_register:
388 kfree(child);
389 return NULL;
378} 390}
379 391
380struct pci_bus * __devinit pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int busnr) 392struct pci_bus * __devinit pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int busnr)
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index def78a2a7c15..23b599d6a9d5 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -93,8 +93,21 @@ static void __devinit quirk_nopcipci(struct pci_dev *dev)
93 pci_pci_problems |= PCIPCI_FAIL; 93 pci_pci_problems |= PCIPCI_FAIL;
94 } 94 }
95} 95}
96
97static void __devinit quirk_nopciamd(struct pci_dev *dev)
98{
99 u8 rev;
100 pci_read_config_byte(dev, 0x08, &rev);
101 if (rev == 0x13) {
102 /* Erratum 24 */
103 printk(KERN_INFO "Chipset erratum: Disabling direct PCI/AGP transfers.\n");
104 pci_pci_problems |= PCIAGP_FAIL;
105 }
106}
107
96DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_5597, quirk_nopcipci ); 108DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_5597, quirk_nopcipci );
97DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_496, quirk_nopcipci ); 109DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_496, quirk_nopcipci );
110DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8151_0, quirk_nopciamd );
98 111
99/* 112/*
100 * Triton requires workarounds to be used by the drivers 113 * Triton requires workarounds to be used by the drivers
@@ -555,7 +568,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt
555 * is currently marked NoFix 568 * is currently marked NoFix
556 * 569 *
557 * We have multiple reports of hangs with this chipset that went away with 570 * We have multiple reports of hangs with this chipset that went away with
558 * noapic specified. For the moment we assume its the errata. We may be wrong 571 * noapic specified. For the moment we assume it's the erratum. We may be wrong
559 * of course. However the advice is demonstrably good even if so.. 572 * of course. However the advice is demonstrably good even if so..
560 */ 573 */
561static void __devinit quirk_amd_ioapic(struct pci_dev *dev) 574static void __devinit quirk_amd_ioapic(struct pci_dev *dev)
@@ -564,7 +577,7 @@ static void __devinit quirk_amd_ioapic(struct pci_dev *dev)
564 577
565 pci_read_config_byte(dev, PCI_REVISION_ID, &rev); 578 pci_read_config_byte(dev, PCI_REVISION_ID, &rev);
566 if (rev >= 0x02) { 579 if (rev >= 0x02) {
567 printk(KERN_WARNING "I/O APIC: AMD Errata #22 may be present. In the event of instability try\n"); 580 printk(KERN_WARNING "I/O APIC: AMD Erratum #22 may be present. In the event of instability try\n");
568 printk(KERN_WARNING " : booting with the \"noapic\" option.\n"); 581 printk(KERN_WARNING " : booting with the \"noapic\" option.\n");
569 } 582 }
570} 583}
@@ -577,8 +590,6 @@ static void __init quirk_ioapic_rmw(struct pci_dev *dev)
577} 590}
578DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, PCI_ANY_ID, quirk_ioapic_rmw ); 591DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, PCI_ANY_ID, quirk_ioapic_rmw );
579 592
580int pci_msi_quirk;
581
582#define AMD8131_revA0 0x01 593#define AMD8131_revA0 0x01
583#define AMD8131_revB0 0x11 594#define AMD8131_revB0 0x11
584#define AMD8131_MISC 0x40 595#define AMD8131_MISC 0x40
@@ -587,12 +598,6 @@ static void __init quirk_amd_8131_ioapic(struct pci_dev *dev)
587{ 598{
588 unsigned char revid, tmp; 599 unsigned char revid, tmp;
589 600
590 if (dev->subordinate) {
591 printk(KERN_WARNING "PCI: MSI quirk detected. "
592 "PCI_BUS_FLAGS_NO_MSI set for subordinate bus.\n");
593 dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
594 }
595
596 if (nr_ioapics == 0) 601 if (nr_ioapics == 0)
597 return; 602 return;
598 603
@@ -605,13 +610,6 @@ static void __init quirk_amd_8131_ioapic(struct pci_dev *dev)
605 } 610 }
606} 611}
607DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic); 612DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic);
608
609static void __init quirk_svw_msi(struct pci_dev *dev)
610{
611 pci_msi_quirk = 1;
612 printk(KERN_WARNING "PCI: MSI quirk detected. pci_msi_quirk set.\n");
613}
614DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_GCNB_LE, quirk_svw_msi );
615#endif /* CONFIG_X86_IO_APIC */ 613#endif /* CONFIG_X86_IO_APIC */
616 614
617 615
@@ -1690,6 +1688,95 @@ static void __devinit quirk_nvidia_ck804_pcie_aer_ext_cap(struct pci_dev *dev)
1690DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE, 1688DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
1691 quirk_nvidia_ck804_pcie_aer_ext_cap); 1689 quirk_nvidia_ck804_pcie_aer_ext_cap);
1692 1690
1691#ifdef CONFIG_PCI_MSI
1692/* To disable MSI globally */
1693int pci_msi_quirk;
1694
1695/* The Serverworks PCI-X chipset does not support MSI. We cannot easily rely
1696 * on setting PCI_BUS_FLAGS_NO_MSI in its bus flags because there are actually
1697 * some other busses controlled by the chipset even if Linux is not aware of it.
1698 * Instead of setting the flag on all busses in the machine, simply disable MSI
1699 * globally.
1700 */
1701static void __init quirk_svw_msi(struct pci_dev *dev)
1702{
1703 pci_msi_quirk = 1;
1704 printk(KERN_WARNING "PCI: MSI quirk detected. pci_msi_quirk set.\n");
1705}
1706DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_GCNB_LE, quirk_svw_msi);
1707
1708/* Disable MSI on chipsets that are known to not support it */
1709static void __devinit quirk_disable_msi(struct pci_dev *dev)
1710{
1711 if (dev->subordinate) {
1712 printk(KERN_WARNING "PCI: MSI quirk detected. "
1713 "PCI_BUS_FLAGS_NO_MSI set for %s subordinate bus.\n",
1714 pci_name(dev));
1715 dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
1716 }
1717}
1718DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_disable_msi);
1719
1720/* Go through the list of Hypertransport capabilities and
1721 * return 1 if a HT MSI capability is found and enabled */
1722static int __devinit msi_ht_cap_enabled(struct pci_dev *dev)
1723{
1724 u8 pos;
1725 int ttl;
1726 for (pos = pci_find_capability(dev, PCI_CAP_ID_HT), ttl = 48;
1727 pos && ttl;
1728 pos = pci_find_next_capability(dev, pos, PCI_CAP_ID_HT), ttl--) {
1729 u32 cap_hdr;
1730 /* MSI mapping section according to Hypertransport spec */
1731 if (pci_read_config_dword(dev, pos, &cap_hdr) == 0
1732 && (cap_hdr & 0xf8000000) == 0xa8000000 /* MSI mapping */) {
1733 printk(KERN_INFO "PCI: Found HT MSI mapping on %s with capability %s\n",
1734 pci_name(dev), cap_hdr & 0x10000 ? "enabled" : "disabled");
1735 return (cap_hdr & 0x10000) != 0; /* MSI mapping cap enabled */
1736 }
1737 }
1738 return 0;
1739}
1740
1741/* Check the hypertransport MSI mapping to know whether MSI is enabled or not */
1742static void __devinit quirk_msi_ht_cap(struct pci_dev *dev)
1743{
1744 if (dev->subordinate && !msi_ht_cap_enabled(dev)) {
1745 printk(KERN_WARNING "PCI: MSI quirk detected. "
1746 "MSI disabled on chipset %s.\n",
1747 pci_name(dev));
1748 dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
1749 }
1750}
1751DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT2000_PCIE,
1752 quirk_msi_ht_cap);
1753
1754/* The nVidia CK804 chipset may have 2 HT MSI mappings.
1755 * MSI are supported if the MSI capability set in any of these mappings.
1756 */
1757static void __devinit quirk_nvidia_ck804_msi_ht_cap(struct pci_dev *dev)
1758{
1759 struct pci_dev *pdev;
1760
1761 if (!dev->subordinate)
1762 return;
1763
1764 /* check HT MSI cap on this chipset and the root one.
1765 * a single one having MSI is enough to be sure that MSI are supported.
1766 */
1767 pdev = pci_find_slot(dev->bus->number, 0);
1768 if (dev->subordinate && !msi_ht_cap_enabled(dev)
1769 && !msi_ht_cap_enabled(pdev)) {
1770 printk(KERN_WARNING "PCI: MSI quirk detected. "
1771 "MSI disabled on chipset %s.\n",
1772 pci_name(dev));
1773 dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
1774 }
1775}
1776DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
1777 quirk_nvidia_ck804_msi_ht_cap);
1778#endif /* CONFIG_PCI_MSI */
1779
1693EXPORT_SYMBOL(pcie_mch_quirk); 1780EXPORT_SYMBOL(pcie_mch_quirk);
1694#ifdef CONFIG_HOTPLUG 1781#ifdef CONFIG_HOTPLUG
1695EXPORT_SYMBOL(pci_fixup_device); 1782EXPORT_SYMBOL(pci_fixup_device);
diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c
index 99ffbd478b29..430281b2e921 100644
--- a/drivers/pci/remove.c
+++ b/drivers/pci/remove.c
@@ -16,8 +16,11 @@ static void pci_free_resources(struct pci_dev *dev)
16 } 16 }
17} 17}
18 18
19static void pci_destroy_dev(struct pci_dev *dev) 19static void pci_stop_dev(struct pci_dev *dev)
20{ 20{
21 if (!dev->global_list.next)
22 return;
23
21 if (!list_empty(&dev->global_list)) { 24 if (!list_empty(&dev->global_list)) {
22 pci_proc_detach_device(dev); 25 pci_proc_detach_device(dev);
23 pci_remove_sysfs_dev_files(dev); 26 pci_remove_sysfs_dev_files(dev);
@@ -27,6 +30,11 @@ static void pci_destroy_dev(struct pci_dev *dev)
27 dev->global_list.next = dev->global_list.prev = NULL; 30 dev->global_list.next = dev->global_list.prev = NULL;
28 up_write(&pci_bus_sem); 31 up_write(&pci_bus_sem);
29 } 32 }
33}
34
35static void pci_destroy_dev(struct pci_dev *dev)
36{
37 pci_stop_dev(dev);
30 38
31 /* Remove the device from the device lists, and prevent any further 39 /* Remove the device from the device lists, and prevent any further
32 * list accesses from this device */ 40 * list accesses from this device */
@@ -119,5 +127,32 @@ void pci_remove_behind_bridge(struct pci_dev *dev)
119 } 127 }
120} 128}
121 129
130static void pci_stop_bus_devices(struct pci_bus *bus)
131{
132 struct list_head *l, *n;
133
134 list_for_each_safe(l, n, &bus->devices) {
135 struct pci_dev *dev = pci_dev_b(l);
136 pci_stop_bus_device(dev);
137 }
138}
139
140/**
141 * pci_stop_bus_device - stop a PCI device and any children
142 * @dev: the device to stop
143 *
144 * Stop a PCI device (detach the driver, remove from the global list
145 * and so on). This also stop any subordinate buses and children in a
146 * depth-first manner.
147 */
148void pci_stop_bus_device(struct pci_dev *dev)
149{
150 if (dev->subordinate)
151 pci_stop_bus_devices(dev->subordinate);
152
153 pci_stop_dev(dev);
154}
155
122EXPORT_SYMBOL(pci_remove_bus_device); 156EXPORT_SYMBOL(pci_remove_bus_device);
123EXPORT_SYMBOL(pci_remove_behind_bridge); 157EXPORT_SYMBOL(pci_remove_behind_bridge);
158EXPORT_SYMBOL_GPL(pci_stop_bus_device);
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 47c1071ad84e..54404917be9a 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -55,12 +55,19 @@ pbus_assign_resources_sorted(struct pci_bus *bus)
55 list_for_each_entry(dev, &bus->devices, bus_list) { 55 list_for_each_entry(dev, &bus->devices, bus_list) {
56 u16 class = dev->class >> 8; 56 u16 class = dev->class >> 8;
57 57
58 /* Don't touch classless devices or host bridges or ioapics. */ 58 /* Don't touch classless devices or host bridges. */
59 if (class == PCI_CLASS_NOT_DEFINED || 59 if (class == PCI_CLASS_NOT_DEFINED ||
60 class == PCI_CLASS_BRIDGE_HOST || 60 class == PCI_CLASS_BRIDGE_HOST)
61 class == PCI_CLASS_SYSTEM_PIC)
62 continue; 61 continue;
63 62
63 /* Don't touch ioapics if it has the assigned resources. */
64 if (class == PCI_CLASS_SYSTEM_PIC) {
65 res = &dev->resource[0];
66 if (res[0].start || res[1].start || res[2].start ||
67 res[3].start || res[4].start || res[5].start)
68 continue;
69 }
70
64 pdev_sort_resources(dev, &head); 71 pdev_sort_resources(dev, &head);
65 } 72 }
66 73
diff --git a/drivers/pcmcia/cardbus.c b/drivers/pcmcia/cardbus.c
index 3f6d51d11374..2d7effe7990d 100644
--- a/drivers/pcmcia/cardbus.c
+++ b/drivers/pcmcia/cardbus.c
@@ -138,7 +138,7 @@ int read_cb_mem(struct pcmcia_socket * s, int space, u_int addr, u_int len, void
138 138
139 cs_dbg(s, 3, "read_cb_mem(%d, %#x, %u)\n", space, addr, len); 139 cs_dbg(s, 3, "read_cb_mem(%d, %#x, %u)\n", space, addr, len);
140 140
141 dev = pci_find_slot(s->cb_dev->subordinate->number, 0); 141 dev = pci_get_slot(s->cb_dev->subordinate, 0);
142 if (!dev) 142 if (!dev)
143 goto fail; 143 goto fail;
144 144
@@ -152,6 +152,9 @@ int read_cb_mem(struct pcmcia_socket * s, int space, u_int addr, u_int len, void
152 } 152 }
153 153
154 res = dev->resource + space - 1; 154 res = dev->resource + space - 1;
155
156 pci_dev_put(dev);
157
155 if (!res->flags) 158 if (!res->flags)
156 goto fail; 159 goto fail;
157 160
diff --git a/drivers/pcmcia/omap_cf.c b/drivers/pcmcia/omap_cf.c
index 420e10aec0ae..01be47e72730 100644
--- a/drivers/pcmcia/omap_cf.c
+++ b/drivers/pcmcia/omap_cf.c
@@ -67,6 +67,7 @@ struct omap_cf_socket {
67 struct platform_device *pdev; 67 struct platform_device *pdev;
68 unsigned long phys_cf; 68 unsigned long phys_cf;
69 u_int irq; 69 u_int irq;
70 struct resource iomem;
70}; 71};
71 72
72#define POLL_INTERVAL (2 * HZ) 73#define POLL_INTERVAL (2 * HZ)
@@ -112,16 +113,14 @@ static int omap_cf_get_status(struct pcmcia_socket *s, u_int *sp)
112 if (!sp) 113 if (!sp)
113 return -EINVAL; 114 return -EINVAL;
114 115
115 /* FIXME power management should probably be board-specific: 116 /* NOTE CF is always 3VCARD */
116 * - 3VCARD vs XVCARD (OSK only handles 3VCARD)
117 * - POWERON (switched on/off by set_socket)
118 */
119 if (omap_cf_present()) { 117 if (omap_cf_present()) {
120 struct omap_cf_socket *cf; 118 struct omap_cf_socket *cf;
121 119
122 *sp = SS_READY | SS_DETECT | SS_POWERON | SS_3VCARD; 120 *sp = SS_READY | SS_DETECT | SS_POWERON | SS_3VCARD;
123 cf = container_of(s, struct omap_cf_socket, socket); 121 cf = container_of(s, struct omap_cf_socket, socket);
124 s->irq.AssignedIRQ = cf->irq; 122 s->irq.AssignedIRQ = 0;
123 s->pci_irq = cf->irq;
125 } else 124 } else
126 *sp = 0; 125 *sp = 0;
127 return 0; 126 return 0;
@@ -132,7 +131,7 @@ omap_cf_set_socket(struct pcmcia_socket *sock, struct socket_state_t *s)
132{ 131{
133 u16 control; 132 u16 control;
134 133
135 /* FIXME some non-OSK boards will support power switching */ 134 /* REVISIT some non-OSK boards may support power switching */
136 switch (s->Vcc) { 135 switch (s->Vcc) {
137 case 0: 136 case 0:
138 case 33: 137 case 33:
@@ -204,7 +203,7 @@ static struct pccard_operations omap_cf_ops = {
204 * "what chipselect is used". Boards could want more. 203 * "what chipselect is used". Boards could want more.
205 */ 204 */
206 205
207static int __init omap_cf_probe(struct device *dev) 206static int __devinit omap_cf_probe(struct device *dev)
208{ 207{
209 unsigned seg; 208 unsigned seg;
210 struct omap_cf_socket *cf; 209 struct omap_cf_socket *cf;
@@ -253,6 +252,9 @@ static int __init omap_cf_probe(struct device *dev)
253 default: 252 default:
254 goto fail1; 253 goto fail1;
255 } 254 }
255 cf->iomem.start = cf->phys_cf;
256 cf->iomem.end = cf->iomem.end + SZ_8K - 1;
257 cf->iomem.flags = IORESOURCE_MEM;
256 258
257 /* pcmcia layer only remaps "real" memory */ 259 /* pcmcia layer only remaps "real" memory */
258 cf->socket.io_offset = (unsigned long) 260 cf->socket.io_offset = (unsigned long)
@@ -296,6 +298,7 @@ static int __init omap_cf_probe(struct device *dev)
296 cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP 298 cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP
297 | SS_CAP_MEM_ALIGN; 299 | SS_CAP_MEM_ALIGN;
298 cf->socket.map_size = SZ_2K; 300 cf->socket.map_size = SZ_2K;
301 cf->socket.io[0].res = &cf->iomem;
299 302
300 status = pcmcia_register_socket(&cf->socket); 303 status = pcmcia_register_socket(&cf->socket);
301 if (status < 0) 304 if (status < 0)
@@ -334,15 +337,15 @@ static struct device_driver omap_cf_driver = {
334 .bus = &platform_bus_type, 337 .bus = &platform_bus_type,
335 .probe = omap_cf_probe, 338 .probe = omap_cf_probe,
336 .remove = __devexit_p(omap_cf_remove), 339 .remove = __devexit_p(omap_cf_remove),
337 .suspend = pcmcia_socket_dev_suspend, 340 .suspend = pcmcia_socket_dev_suspend,
338 .resume = pcmcia_socket_dev_resume, 341 .resume = pcmcia_socket_dev_resume,
339}; 342};
340 343
341static int __init omap_cf_init(void) 344static int __init omap_cf_init(void)
342{ 345{
343 if (cpu_is_omap16xx()) 346 if (cpu_is_omap16xx())
344 driver_register(&omap_cf_driver); 347 return driver_register(&omap_cf_driver);
345 return 0; 348 return -ENODEV;
346} 349}
347 350
348static void __exit omap_cf_exit(void) 351static void __exit omap_cf_exit(void)
diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c
index c5d7476da471..933cd864a5c9 100644
--- a/drivers/pcmcia/socket_sysfs.c
+++ b/drivers/pcmcia/socket_sysfs.c
@@ -298,7 +298,7 @@ static ssize_t pccard_store_cis(struct kobject *kobj, char *buf, loff_t off, siz
298{ 298{
299 struct pcmcia_socket *s = to_socket(container_of(kobj, struct class_device, kobj)); 299 struct pcmcia_socket *s = to_socket(container_of(kobj, struct class_device, kobj));
300 cisdump_t *cis; 300 cisdump_t *cis;
301 ssize_t ret = count; 301 int error;
302 302
303 if (off) 303 if (off)
304 return -EINVAL; 304 return -EINVAL;
@@ -316,25 +316,22 @@ static ssize_t pccard_store_cis(struct kobject *kobj, char *buf, loff_t off, siz
316 cis->Length = count + 1; 316 cis->Length = count + 1;
317 memcpy(cis->Data, buf, count); 317 memcpy(cis->Data, buf, count);
318 318
319 if (pcmcia_replace_cis(s, cis)) 319 error = pcmcia_replace_cis(s, cis);
320 ret = -EIO;
321
322 kfree(cis); 320 kfree(cis);
321 if (error)
322 return -EIO;
323 323
324 if (!ret) { 324 mutex_lock(&s->skt_mutex);
325 mutex_lock(&s->skt_mutex); 325 if ((s->callback) && (s->state & SOCKET_PRESENT) &&
326 if ((s->callback) && (s->state & SOCKET_PRESENT) && 326 !(s->state & SOCKET_CARDBUS)) {
327 !(s->state & SOCKET_CARDBUS)) { 327 if (try_module_get(s->callback->owner)) {
328 if (try_module_get(s->callback->owner)) { 328 s->callback->requery(s);
329 s->callback->requery(s); 329 module_put(s->callback->owner);
330 module_put(s->callback->owner);
331 }
332 } 330 }
333 mutex_unlock(&s->skt_mutex);
334 } 331 }
332 mutex_unlock(&s->skt_mutex);
335 333
336 334 return count;
337 return (ret);
338} 335}
339 336
340 337
diff --git a/drivers/pnp/pnpbios/core.c b/drivers/pnp/pnpbios/core.c
index 551f58e29810..81a6c83d89a6 100644
--- a/drivers/pnp/pnpbios/core.c
+++ b/drivers/pnp/pnpbios/core.c
@@ -526,6 +526,10 @@ static int __init pnpbios_init(void)
526{ 526{
527 int ret; 527 int ret;
528 528
529#if defined(CONFIG_PPC_MERGE)
530 if (check_legacy_ioport(PNPBIOS_BASE))
531 return -ENODEV;
532#endif
529 if (pnpbios_disabled || dmi_check_system(pnpbios_dmi_table)) { 533 if (pnpbios_disabled || dmi_check_system(pnpbios_dmi_table)) {
530 printk(KERN_INFO "PnPBIOS: Disabled\n"); 534 printk(KERN_INFO "PnPBIOS: Disabled\n");
531 return -ENODEV; 535 return -ENODEV;
@@ -575,6 +579,10 @@ subsys_initcall(pnpbios_init);
575 579
576static int __init pnpbios_thread_init(void) 580static int __init pnpbios_thread_init(void)
577{ 581{
582#if defined(CONFIG_PPC_MERGE)
583 if (check_legacy_ioport(PNPBIOS_BASE))
584 return 0;
585#endif
578 if (pnpbios_disabled) 586 if (pnpbios_disabled)
579 return 0; 587 return 0;
580#ifdef CONFIG_HOTPLUG 588#ifdef CONFIG_HOTPLUG
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 7ff1d88094b6..fc766a7a611e 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -27,7 +27,7 @@ config RTC_HCTOSYS
27 help 27 help
28 If you say yes here, the system time will be set using 28 If you say yes here, the system time will be set using
29 the value read from the specified RTC device. This is useful 29 the value read from the specified RTC device. This is useful
30 in order to avoid unnecessary fschk runs. 30 in order to avoid unnecessary fsck runs.
31 31
32config RTC_HCTOSYS_DEVICE 32config RTC_HCTOSYS_DEVICE
33 string "The RTC to read the time from" 33 string "The RTC to read the time from"
@@ -37,6 +37,13 @@ config RTC_HCTOSYS_DEVICE
37 The RTC device that will be used as the source for 37 The RTC device that will be used as the source for
38 the system time, usually rtc0. 38 the system time, usually rtc0.
39 39
40config RTC_DEBUG
41 bool "RTC debug support"
42 depends on RTC_CLASS = y
43 help
44 Say yes here to enable debugging support in the RTC framework
45 and individual RTC drivers.
46
40comment "RTC interfaces" 47comment "RTC interfaces"
41 depends on RTC_CLASS 48 depends on RTC_CLASS
42 49
@@ -45,8 +52,8 @@ config RTC_INTF_SYSFS
45 depends on RTC_CLASS && SYSFS 52 depends on RTC_CLASS && SYSFS
46 default RTC_CLASS 53 default RTC_CLASS
47 help 54 help
48 Say yes here if you want to use your RTC using the sysfs 55 Say yes here if you want to use your RTCs using sysfs interfaces,
49 interface, /sys/class/rtc/rtcX . 56 /sys/class/rtc/rtc0 through /sys/.../rtcN.
50 57
51 This driver can also be built as a module. If so, the module 58 This driver can also be built as a module. If so, the module
52 will be called rtc-sysfs. 59 will be called rtc-sysfs.
@@ -56,8 +63,9 @@ config RTC_INTF_PROC
56 depends on RTC_CLASS && PROC_FS 63 depends on RTC_CLASS && PROC_FS
57 default RTC_CLASS 64 default RTC_CLASS
58 help 65 help
59 Say yes here if you want to use your RTC using the proc 66 Say yes here if you want to use your first RTC through the proc
60 interface, /proc/driver/rtc . 67 interface, /proc/driver/rtc. Other RTCs will not be available
68 through that API.
61 69
62 This driver can also be built as a module. If so, the module 70 This driver can also be built as a module. If so, the module
63 will be called rtc-proc. 71 will be called rtc-proc.
@@ -67,8 +75,11 @@ config RTC_INTF_DEV
67 depends on RTC_CLASS 75 depends on RTC_CLASS
68 default RTC_CLASS 76 default RTC_CLASS
69 help 77 help
70 Say yes here if you want to use your RTC using the dev 78 Say yes here if you want to use your RTCs using the /dev
71 interface, /dev/rtc . 79 interfaces, which "udev" sets up as /dev/rtc0 through
80 /dev/rtcN. You may want to set up a symbolic link so one
81 of these can be accessed as /dev/rtc, which is a name
82 expected by "hwclock" and some other programs.
72 83
73 This driver can also be built as a module. If so, the module 84 This driver can also be built as a module. If so, the module
74 will be called rtc-dev. 85 will be called rtc-dev.
@@ -78,7 +89,8 @@ config RTC_INTF_DEV_UIE_EMUL
78 depends on RTC_INTF_DEV 89 depends on RTC_INTF_DEV
79 help 90 help
80 Provides an emulation for RTC_UIE if the underlaying rtc chip 91 Provides an emulation for RTC_UIE if the underlaying rtc chip
81 driver did not provide RTC_UIE ioctls. 92 driver does not expose RTC_UIE ioctls. Those requests generate
93 once-per-second update interrupts, used for synchronization.
82 94
83comment "RTC drivers" 95comment "RTC drivers"
84 depends on RTC_CLASS 96 depends on RTC_CLASS
@@ -238,6 +250,16 @@ config RTC_DRV_SA1100
238 To compile this driver as a module, choose M here: the 250 To compile this driver as a module, choose M here: the
239 module will be called rtc-sa1100. 251 module will be called rtc-sa1100.
240 252
253config RTC_DRV_SH
254 tristate "SuperH On-Chip RTC"
255 depends on RTC_CLASS && SUPERH
256 help
257 Say Y here to enable support for the on-chip RTC found in
258 most SuperH processors.
259
260 To compile this driver as a module, choose M here: the
261 module will be called rtc-sh.
262
241config RTC_DRV_VR41XX 263config RTC_DRV_VR41XX
242 tristate "NEC VR41XX" 264 tristate "NEC VR41XX"
243 depends on RTC_CLASS && CPU_VR41XX 265 depends on RTC_CLASS && CPU_VR41XX
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index bbcfb09d81d9..3ba5ff6e6800 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -2,6 +2,10 @@
2# Makefile for RTC class/drivers. 2# Makefile for RTC class/drivers.
3# 3#
4 4
5ifeq ($(CONFIG_RTC_DEBUG),y)
6 EXTRA_CFLAGS += -DDEBUG
7endif
8
5obj-$(CONFIG_RTC_LIB) += rtc-lib.o 9obj-$(CONFIG_RTC_LIB) += rtc-lib.o
6obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o 10obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o
7obj-$(CONFIG_RTC_CLASS) += rtc-core.o 11obj-$(CONFIG_RTC_CLASS) += rtc-core.o
@@ -31,3 +35,4 @@ obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o
31obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o 35obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o
32obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o 36obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o
33obj-$(CONFIG_RTC_DRV_AT91) += rtc-at91.o 37obj-$(CONFIG_RTC_DRV_AT91) += rtc-at91.o
38obj-$(CONFIG_RTC_DRV_SH) += rtc-sh.o
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 1cb61a761cb2..7a0d8ee2de9c 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -39,7 +39,7 @@ static void rtc_device_release(struct class_device *class_dev)
39 * Returns the pointer to the new struct class device. 39 * Returns the pointer to the new struct class device.
40 */ 40 */
41struct rtc_device *rtc_device_register(const char *name, struct device *dev, 41struct rtc_device *rtc_device_register(const char *name, struct device *dev,
42 struct rtc_class_ops *ops, 42 const struct rtc_class_ops *ops,
43 struct module *owner) 43 struct module *owner)
44{ 44{
45 struct rtc_device *rtc; 45 struct rtc_device *rtc;
@@ -142,9 +142,9 @@ static void __exit rtc_exit(void)
142 class_destroy(rtc_class); 142 class_destroy(rtc_class);
143} 143}
144 144
145module_init(rtc_init); 145subsys_initcall(rtc_init);
146module_exit(rtc_exit); 146module_exit(rtc_exit);
147 147
148MODULE_AUTHOR("Alessandro Zummo <a.zummo@towerteh.it>"); 148MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
149MODULE_DESCRIPTION("RTC class support"); 149MODULE_DESCRIPTION("RTC class support");
150MODULE_LICENSE("GPL"); 150MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-at91.c b/drivers/rtc/rtc-at91.c
index dfd0ce86f6a0..c0714da44920 100644
--- a/drivers/rtc/rtc-at91.c
+++ b/drivers/rtc/rtc-at91.c
@@ -267,7 +267,7 @@ static irqreturn_t at91_rtc_interrupt(int irq, void *dev_id,
267 return IRQ_NONE; /* not handled */ 267 return IRQ_NONE; /* not handled */
268} 268}
269 269
270static struct rtc_class_ops at91_rtc_ops = { 270static const struct rtc_class_ops at91_rtc_ops = {
271 .ioctl = at91_rtc_ioctl, 271 .ioctl = at91_rtc_ioctl,
272 .read_time = at91_rtc_readtime, 272 .read_time = at91_rtc_readtime,
273 .set_time = at91_rtc_settime, 273 .set_time = at91_rtc_settime,
@@ -307,6 +307,7 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
307 return PTR_ERR(rtc); 307 return PTR_ERR(rtc);
308 } 308 }
309 platform_set_drvdata(pdev, rtc); 309 platform_set_drvdata(pdev, rtc);
310 device_init_wakeup(&pdev->dev, 1);
310 311
311 printk(KERN_INFO "AT91 Real Time Clock driver.\n"); 312 printk(KERN_INFO "AT91 Real Time Clock driver.\n");
312 return 0; 313 return 0;
@@ -327,6 +328,7 @@ static int __devexit at91_rtc_remove(struct platform_device *pdev)
327 328
328 rtc_device_unregister(rtc); 329 rtc_device_unregister(rtc);
329 platform_set_drvdata(pdev, NULL); 330 platform_set_drvdata(pdev, NULL);
331 device_init_wakeup(&pdev->dev, 0);
330 332
331 return 0; 333 return 0;
332} 334}
@@ -336,6 +338,7 @@ static int __devexit at91_rtc_remove(struct platform_device *pdev)
336/* AT91RM9200 RTC Power management control */ 338/* AT91RM9200 RTC Power management control */
337 339
338static struct timespec at91_rtc_delta; 340static struct timespec at91_rtc_delta;
341static u32 at91_rtc_imr;
339 342
340static int at91_rtc_suspend(struct platform_device *pdev, pm_message_t state) 343static int at91_rtc_suspend(struct platform_device *pdev, pm_message_t state)
341{ 344{
@@ -349,6 +352,18 @@ static int at91_rtc_suspend(struct platform_device *pdev, pm_message_t state)
349 rtc_tm_to_time(&tm, &time.tv_sec); 352 rtc_tm_to_time(&tm, &time.tv_sec);
350 save_time_delta(&at91_rtc_delta, &time); 353 save_time_delta(&at91_rtc_delta, &time);
351 354
355 /* this IRQ is shared with DBGU and other hardware which isn't
356 * necessarily doing PM like we are...
357 */
358 at91_rtc_imr = at91_sys_read(AT91_RTC_IMR)
359 & (AT91_RTC_ALARM|AT91_RTC_SECEV);
360 if (at91_rtc_imr) {
361 if (device_may_wakeup(&pdev->dev))
362 enable_irq_wake(AT91_ID_SYS);
363 else
364 at91_sys_write(AT91_RTC_IDR, at91_rtc_imr);
365 }
366
352 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__, 367 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__,
353 1900 + tm.tm_year, tm.tm_mon, tm.tm_mday, 368 1900 + tm.tm_year, tm.tm_mon, tm.tm_mday,
354 tm.tm_hour, tm.tm_min, tm.tm_sec); 369 tm.tm_hour, tm.tm_min, tm.tm_sec);
@@ -367,6 +382,13 @@ static int at91_rtc_resume(struct platform_device *pdev)
367 rtc_tm_to_time(&tm, &time.tv_sec); 382 rtc_tm_to_time(&tm, &time.tv_sec);
368 restore_time_delta(&at91_rtc_delta, &time); 383 restore_time_delta(&at91_rtc_delta, &time);
369 384
385 if (at91_rtc_imr) {
386 if (device_may_wakeup(&pdev->dev))
387 disable_irq_wake(AT91_ID_SYS);
388 else
389 at91_sys_write(AT91_RTC_IER, at91_rtc_imr);
390 }
391
370 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__, 392 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__,
371 1900 + tm.tm_year, tm.tm_mon, tm.tm_mday, 393 1900 + tm.tm_year, tm.tm_mon, tm.tm_mday,
372 tm.tm_hour, tm.tm_min, tm.tm_sec); 394 tm.tm_hour, tm.tm_min, tm.tm_sec);
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
index 61a58259c93f..583789c66cdb 100644
--- a/drivers/rtc/rtc-dev.c
+++ b/drivers/rtc/rtc-dev.c
@@ -24,7 +24,7 @@ static int rtc_dev_open(struct inode *inode, struct file *file)
24 int err; 24 int err;
25 struct rtc_device *rtc = container_of(inode->i_cdev, 25 struct rtc_device *rtc = container_of(inode->i_cdev,
26 struct rtc_device, char_dev); 26 struct rtc_device, char_dev);
27 struct rtc_class_ops *ops = rtc->ops; 27 const struct rtc_class_ops *ops = rtc->ops;
28 28
29 /* We keep the lock as long as the device is in use 29 /* We keep the lock as long as the device is in use
30 * and return immediately if busy 30 * and return immediately if busy
@@ -209,7 +209,7 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
209 int err = 0; 209 int err = 0;
210 struct class_device *class_dev = file->private_data; 210 struct class_device *class_dev = file->private_data;
211 struct rtc_device *rtc = to_rtc_device(class_dev); 211 struct rtc_device *rtc = to_rtc_device(class_dev);
212 struct rtc_class_ops *ops = rtc->ops; 212 const struct rtc_class_ops *ops = rtc->ops;
213 struct rtc_time tm; 213 struct rtc_time tm;
214 struct rtc_wkalrm alarm; 214 struct rtc_wkalrm alarm;
215 void __user *uarg = (void __user *) arg; 215 void __user *uarg = (void __user *) arg;
@@ -406,7 +406,6 @@ static int rtc_dev_add_device(struct class_device *class_dev,
406 rtc->char_dev.owner = rtc->owner; 406 rtc->char_dev.owner = rtc->owner;
407 407
408 if (cdev_add(&rtc->char_dev, MKDEV(MAJOR(rtc_devt), rtc->id), 1)) { 408 if (cdev_add(&rtc->char_dev, MKDEV(MAJOR(rtc_devt), rtc->id), 1)) {
409 cdev_del(&rtc->char_dev);
410 dev_err(class_dev->dev, 409 dev_err(class_dev->dev,
411 "failed to add char device %d:%d\n", 410 "failed to add char device %d:%d\n",
412 MAJOR(rtc_devt), rtc->id); 411 MAJOR(rtc_devt), rtc->id);
@@ -496,7 +495,7 @@ static void __exit rtc_dev_exit(void)
496 unregister_chrdev_region(rtc_devt, RTC_DEV_MAX); 495 unregister_chrdev_region(rtc_devt, RTC_DEV_MAX);
497} 496}
498 497
499module_init(rtc_dev_init); 498subsys_initcall(rtc_dev_init);
500module_exit(rtc_dev_exit); 499module_exit(rtc_dev_exit);
501 500
502MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); 501MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index e8afb9384786..cc5032b6f42a 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -178,7 +178,7 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
178 return 0; 178 return 0;
179} 179}
180 180
181static struct rtc_class_ops ds13xx_rtc_ops = { 181static const struct rtc_class_ops ds13xx_rtc_ops = {
182 .read_time = ds1307_get_time, 182 .read_time = ds1307_get_time,
183 .set_time = ds1307_set_time, 183 .set_time = ds1307_set_time,
184}; 184};
diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index 209001495474..9647188fee2c 100644
--- a/drivers/rtc/rtc-ds1553.c
+++ b/drivers/rtc/rtc-ds1553.c
@@ -18,7 +18,7 @@
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/io.h> 19#include <linux/io.h>
20 20
21#define DRV_VERSION "0.1" 21#define DRV_VERSION "0.2"
22 22
23#define RTC_REG_SIZE 0x2000 23#define RTC_REG_SIZE 0x2000
24#define RTC_OFFSET 0x1ff0 24#define RTC_OFFSET 0x1ff0
@@ -250,7 +250,7 @@ static int ds1553_rtc_ioctl(struct device *dev, unsigned int cmd,
250 return 0; 250 return 0;
251} 251}
252 252
253static struct rtc_class_ops ds1553_rtc_ops = { 253static const struct rtc_class_ops ds1553_rtc_ops = {
254 .read_time = ds1553_rtc_read_time, 254 .read_time = ds1553_rtc_read_time,
255 .set_time = ds1553_rtc_set_time, 255 .set_time = ds1553_rtc_set_time,
256 .read_alarm = ds1553_rtc_read_alarm, 256 .read_alarm = ds1553_rtc_read_alarm,
@@ -357,9 +357,13 @@ static int __init ds1553_rtc_probe(struct platform_device *pdev)
357 pdata->rtc = rtc; 357 pdata->rtc = rtc;
358 pdata->last_jiffies = jiffies; 358 pdata->last_jiffies = jiffies;
359 platform_set_drvdata(pdev, pdata); 359 platform_set_drvdata(pdev, pdata);
360 sysfs_create_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr); 360 ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr);
361 if (ret)
362 goto out;
361 return 0; 363 return 0;
362 out: 364 out:
365 if (pdata->rtc)
366 rtc_device_unregister(pdata->rtc);
363 if (pdata->irq >= 0) 367 if (pdata->irq >= 0)
364 free_irq(pdata->irq, pdev); 368 free_irq(pdata->irq, pdev);
365 if (ioaddr) 369 if (ioaddr)
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c
index 9be81fd4737c..9c68ec99afa5 100644
--- a/drivers/rtc/rtc-ds1672.c
+++ b/drivers/rtc/rtc-ds1672.c
@@ -156,7 +156,7 @@ static ssize_t show_control(struct device *dev, struct device_attribute *attr, c
156} 156}
157static DEVICE_ATTR(control, S_IRUGO, show_control, NULL); 157static DEVICE_ATTR(control, S_IRUGO, show_control, NULL);
158 158
159static struct rtc_class_ops ds1672_rtc_ops = { 159static const struct rtc_class_ops ds1672_rtc_ops = {
160 .read_time = ds1672_rtc_read_time, 160 .read_time = ds1672_rtc_read_time,
161 .set_time = ds1672_rtc_set_time, 161 .set_time = ds1672_rtc_set_time,
162 .set_mmss = ds1672_rtc_set_mmss, 162 .set_mmss = ds1672_rtc_set_mmss,
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c
index 8e47e5a06d2a..6273a3d240a2 100644
--- a/drivers/rtc/rtc-ds1742.c
+++ b/drivers/rtc/rtc-ds1742.c
@@ -17,7 +17,7 @@
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/io.h> 18#include <linux/io.h>
19 19
20#define DRV_VERSION "0.1" 20#define DRV_VERSION "0.2"
21 21
22#define RTC_REG_SIZE 0x800 22#define RTC_REG_SIZE 0x800
23#define RTC_OFFSET 0x7f8 23#define RTC_OFFSET 0x7f8
@@ -116,7 +116,7 @@ static int ds1742_rtc_read_time(struct device *dev, struct rtc_time *tm)
116 return 0; 116 return 0;
117} 117}
118 118
119static struct rtc_class_ops ds1742_rtc_ops = { 119static const struct rtc_class_ops ds1742_rtc_ops = {
120 .read_time = ds1742_rtc_read_time, 120 .read_time = ds1742_rtc_read_time,
121 .set_time = ds1742_rtc_set_time, 121 .set_time = ds1742_rtc_set_time,
122}; 122};
@@ -196,7 +196,7 @@ static int __init ds1742_rtc_probe(struct platform_device *pdev)
196 writeb(sec, ioaddr + RTC_SECONDS); 196 writeb(sec, ioaddr + RTC_SECONDS);
197 writeb(cen & RTC_CENTURY_MASK, ioaddr + RTC_CONTROL); 197 writeb(cen & RTC_CENTURY_MASK, ioaddr + RTC_CONTROL);
198 } 198 }
199 if (readb(ioaddr + RTC_DAY) & RTC_BATT_FLAG) 199 if (!(readb(ioaddr + RTC_DAY) & RTC_BATT_FLAG))
200 dev_warn(&pdev->dev, "voltage-low detected.\n"); 200 dev_warn(&pdev->dev, "voltage-low detected.\n");
201 201
202 rtc = rtc_device_register(pdev->name, &pdev->dev, 202 rtc = rtc_device_register(pdev->name, &pdev->dev,
@@ -208,9 +208,13 @@ static int __init ds1742_rtc_probe(struct platform_device *pdev)
208 pdata->rtc = rtc; 208 pdata->rtc = rtc;
209 pdata->last_jiffies = jiffies; 209 pdata->last_jiffies = jiffies;
210 platform_set_drvdata(pdev, pdata); 210 platform_set_drvdata(pdev, pdata);
211 sysfs_create_bin_file(&pdev->dev.kobj, &ds1742_nvram_attr); 211 ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1742_nvram_attr);
212 if (ret)
213 goto out;
212 return 0; 214 return 0;
213 out: 215 out:
216 if (pdata->rtc)
217 rtc_device_unregister(pdata->rtc);
214 if (ioaddr) 218 if (ioaddr)
215 iounmap(ioaddr); 219 iounmap(ioaddr);
216 if (pdata->baseaddr) 220 if (pdata->baseaddr)
diff --git a/drivers/rtc/rtc-ep93xx.c b/drivers/rtc/rtc-ep93xx.c
index e1a1169e4664..ef4f147f3c0c 100644
--- a/drivers/rtc/rtc-ep93xx.c
+++ b/drivers/rtc/rtc-ep93xx.c
@@ -73,7 +73,7 @@ static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq)
73 return 0; 73 return 0;
74} 74}
75 75
76static struct rtc_class_ops ep93xx_rtc_ops = { 76static const struct rtc_class_ops ep93xx_rtc_ops = {
77 .read_time = ep93xx_rtc_read_time, 77 .read_time = ep93xx_rtc_read_time,
78 .set_time = ep93xx_rtc_set_time, 78 .set_time = ep93xx_rtc_set_time,
79 .set_mmss = ep93xx_rtc_set_mmss, 79 .set_mmss = ep93xx_rtc_set_mmss,
diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
index f324d0a635d4..1c743641b73b 100644
--- a/drivers/rtc/rtc-isl1208.c
+++ b/drivers/rtc/rtc-isl1208.c
@@ -390,7 +390,7 @@ static int isl1208_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
390 return isl1208_i2c_read_alarm(to_i2c_client(dev), alarm); 390 return isl1208_i2c_read_alarm(to_i2c_client(dev), alarm);
391} 391}
392 392
393static struct rtc_class_ops isl1208_rtc_ops = { 393static const struct rtc_class_ops isl1208_rtc_ops = {
394 .proc = isl1208_rtc_proc, 394 .proc = isl1208_rtc_proc,
395 .read_time = isl1208_rtc_read_time, 395 .read_time = isl1208_rtc_read_time,
396 .set_time = isl1208_rtc_set_time, 396 .set_time = isl1208_rtc_set_time,
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index 9812120f3a7c..ba795a4db1e9 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -94,12 +94,12 @@ EXPORT_SYMBOL(rtc_time_to_tm);
94int rtc_valid_tm(struct rtc_time *tm) 94int rtc_valid_tm(struct rtc_time *tm)
95{ 95{
96 if (tm->tm_year < 70 96 if (tm->tm_year < 70
97 || tm->tm_mon >= 12 97 || ((unsigned)tm->tm_mon) >= 12
98 || tm->tm_mday < 1 98 || tm->tm_mday < 1
99 || tm->tm_mday > rtc_month_days(tm->tm_mon, tm->tm_year + 1900) 99 || tm->tm_mday > rtc_month_days(tm->tm_mon, tm->tm_year + 1900)
100 || tm->tm_hour >= 24 100 || ((unsigned)tm->tm_hour) >= 24
101 || tm->tm_min >= 60 101 || ((unsigned)tm->tm_min) >= 60
102 || tm->tm_sec >= 60) 102 || ((unsigned)tm->tm_sec) >= 60)
103 return -EINVAL; 103 return -EINVAL;
104 104
105 return 0; 105 return 0;
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index 8c0d1a6739ad..8ff4a1221f59 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -138,7 +138,7 @@ static int m48t86_rtc_proc(struct device *dev, struct seq_file *seq)
138 return 0; 138 return 0;
139} 139}
140 140
141static struct rtc_class_ops m48t86_rtc_ops = { 141static const struct rtc_class_ops m48t86_rtc_ops = {
142 .read_time = m48t86_rtc_read_time, 142 .read_time = m48t86_rtc_read_time,
143 .set_time = m48t86_rtc_set_time, 143 .set_time = m48t86_rtc_set_time,
144 .proc = m48t86_rtc_proc, 144 .proc = m48t86_rtc_proc,
diff --git a/drivers/rtc/rtc-max6902.c b/drivers/rtc/rtc-max6902.c
index 2c9739562b5c..9eeef964663a 100644
--- a/drivers/rtc/rtc-max6902.c
+++ b/drivers/rtc/rtc-max6902.c
@@ -207,7 +207,7 @@ static int max6902_set_time(struct device *dev, struct rtc_time *tm)
207 return max6902_set_datetime(dev, tm); 207 return max6902_set_datetime(dev, tm);
208} 208}
209 209
210static struct rtc_class_ops max6902_rtc_ops = { 210static const struct rtc_class_ops max6902_rtc_ops = {
211 .read_time = max6902_read_time, 211 .read_time = max6902_read_time,
212 .set_time = max6902_set_time, 212 .set_time = max6902_set_time,
213}; 213};
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index ba9a583b7b68..a760cf69af90 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -95,7 +95,7 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
95 tm->tm_wday = buf[PCF8563_REG_DW] & 0x07; 95 tm->tm_wday = buf[PCF8563_REG_DW] & 0x07;
96 tm->tm_mon = BCD2BIN(buf[PCF8563_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */ 96 tm->tm_mon = BCD2BIN(buf[PCF8563_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */
97 tm->tm_year = BCD2BIN(buf[PCF8563_REG_YR]) 97 tm->tm_year = BCD2BIN(buf[PCF8563_REG_YR])
98 + (buf[PCF8563_REG_MO] & PCF8563_MO_C ? 100 : 0); 98 + (buf[PCF8563_REG_MO] & PCF8563_MO_C ? 0 : 100);
99 99
100 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 100 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
101 "mday=%d, mon=%d, year=%d, wday=%d\n", 101 "mday=%d, mon=%d, year=%d, wday=%d\n",
@@ -135,7 +135,7 @@ static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
135 135
136 /* year and century */ 136 /* year and century */
137 buf[PCF8563_REG_YR] = BIN2BCD(tm->tm_year % 100); 137 buf[PCF8563_REG_YR] = BIN2BCD(tm->tm_year % 100);
138 if (tm->tm_year / 100) 138 if (tm->tm_year < 100)
139 buf[PCF8563_REG_MO] |= PCF8563_MO_C; 139 buf[PCF8563_REG_MO] |= PCF8563_MO_C;
140 140
141 buf[PCF8563_REG_DW] = tm->tm_wday & 0x07; 141 buf[PCF8563_REG_DW] = tm->tm_wday & 0x07;
@@ -227,7 +227,7 @@ static int pcf8563_rtc_set_time(struct device *dev, struct rtc_time *tm)
227 return pcf8563_set_datetime(to_i2c_client(dev), tm); 227 return pcf8563_set_datetime(to_i2c_client(dev), tm);
228} 228}
229 229
230static struct rtc_class_ops pcf8563_rtc_ops = { 230static const struct rtc_class_ops pcf8563_rtc_ops = {
231 .read_time = pcf8563_rtc_read_time, 231 .read_time = pcf8563_rtc_read_time,
232 .set_time = pcf8563_rtc_set_time, 232 .set_time = pcf8563_rtc_set_time,
233}; 233};
diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c
index b235a30cb661..5875ebb8c79d 100644
--- a/drivers/rtc/rtc-pcf8583.c
+++ b/drivers/rtc/rtc-pcf8583.c
@@ -273,7 +273,7 @@ static int pcf8583_rtc_set_time(struct device *dev, struct rtc_time *tm)
273 return ret; 273 return ret;
274} 274}
275 275
276static struct rtc_class_ops pcf8583_rtc_ops = { 276static const struct rtc_class_ops pcf8583_rtc_ops = {
277 .read_time = pcf8583_rtc_read_time, 277 .read_time = pcf8583_rtc_read_time,
278 .set_time = pcf8583_rtc_set_time, 278 .set_time = pcf8583_rtc_set_time,
279}; 279};
diff --git a/drivers/rtc/rtc-pl031.c b/drivers/rtc/rtc-pl031.c
index d6d1c5726b0e..739d1a6e14eb 100644
--- a/drivers/rtc/rtc-pl031.c
+++ b/drivers/rtc/rtc-pl031.c
@@ -128,7 +128,7 @@ static int pl031_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
128 return 0; 128 return 0;
129} 129}
130 130
131static struct rtc_class_ops pl031_ops = { 131static const struct rtc_class_ops pl031_ops = {
132 .open = pl031_open, 132 .open = pl031_open,
133 .release = pl031_release, 133 .release = pl031_release,
134 .ioctl = pl031_ioctl, 134 .ioctl = pl031_ioctl,
diff --git a/drivers/rtc/rtc-proc.c b/drivers/rtc/rtc-proc.c
index cef5f5a3bbf9..d51d8f20e634 100644
--- a/drivers/rtc/rtc-proc.c
+++ b/drivers/rtc/rtc-proc.c
@@ -23,7 +23,7 @@ static int rtc_proc_show(struct seq_file *seq, void *offset)
23{ 23{
24 int err; 24 int err;
25 struct class_device *class_dev = seq->private; 25 struct class_device *class_dev = seq->private;
26 struct rtc_class_ops *ops = to_rtc_device(class_dev)->ops; 26 const struct rtc_class_ops *ops = to_rtc_device(class_dev)->ops;
27 struct rtc_wkalrm alrm; 27 struct rtc_wkalrm alrm;
28 struct rtc_time tm; 28 struct rtc_time tm;
29 29
@@ -61,7 +61,7 @@ static int rtc_proc_show(struct seq_file *seq, void *offset)
61 seq_printf(seq, "%02d-", alrm.time.tm_mon + 1); 61 seq_printf(seq, "%02d-", alrm.time.tm_mon + 1);
62 else 62 else
63 seq_printf(seq, "**-"); 63 seq_printf(seq, "**-");
64 if ((unsigned int)alrm.time.tm_mday <= 31) 64 if (alrm.time.tm_mday && (unsigned int)alrm.time.tm_mday <= 31)
65 seq_printf(seq, "%02d\n", alrm.time.tm_mday); 65 seq_printf(seq, "%02d\n", alrm.time.tm_mday);
66 else 66 else
67 seq_printf(seq, "**\n"); 67 seq_printf(seq, "**\n");
@@ -156,7 +156,7 @@ static void __exit rtc_proc_exit(void)
156 class_interface_unregister(&rtc_proc_interface); 156 class_interface_unregister(&rtc_proc_interface);
157} 157}
158 158
159module_init(rtc_proc_init); 159subsys_initcall(rtc_proc_init);
160module_exit(rtc_proc_exit); 160module_exit(rtc_proc_exit);
161 161
162MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); 162MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
diff --git a/drivers/rtc/rtc-rs5c348.c b/drivers/rtc/rtc-rs5c348.c
index 0964d1dba925..f50f3fc353cd 100644
--- a/drivers/rtc/rtc-rs5c348.c
+++ b/drivers/rtc/rtc-rs5c348.c
@@ -23,7 +23,7 @@
23#include <linux/workqueue.h> 23#include <linux/workqueue.h>
24#include <linux/spi/spi.h> 24#include <linux/spi/spi.h>
25 25
26#define DRV_VERSION "0.1" 26#define DRV_VERSION "0.2"
27 27
28#define RS5C348_REG_SECS 0 28#define RS5C348_REG_SECS 0
29#define RS5C348_REG_MINS 1 29#define RS5C348_REG_MINS 1
@@ -140,7 +140,7 @@ rs5c348_rtc_read_time(struct device *dev, struct rtc_time *tm)
140 return 0; 140 return 0;
141} 141}
142 142
143static struct rtc_class_ops rs5c348_rtc_ops = { 143static const struct rtc_class_ops rs5c348_rtc_ops = {
144 .read_time = rs5c348_rtc_read_time, 144 .read_time = rs5c348_rtc_read_time,
145 .set_time = rs5c348_rtc_set_time, 145 .set_time = rs5c348_rtc_set_time,
146}; 146};
@@ -175,8 +175,15 @@ static int __devinit rs5c348_probe(struct spi_device *spi)
175 goto kfree_exit; 175 goto kfree_exit;
176 if (ret & (RS5C348_BIT_XSTP | RS5C348_BIT_VDET)) { 176 if (ret & (RS5C348_BIT_XSTP | RS5C348_BIT_VDET)) {
177 u8 buf[2]; 177 u8 buf[2];
178 struct rtc_time tm;
178 if (ret & RS5C348_BIT_VDET) 179 if (ret & RS5C348_BIT_VDET)
179 dev_warn(&spi->dev, "voltage-low detected.\n"); 180 dev_warn(&spi->dev, "voltage-low detected.\n");
181 if (ret & RS5C348_BIT_XSTP)
182 dev_warn(&spi->dev, "oscillator-stop detected.\n");
183 rtc_time_to_tm(0, &tm); /* 1970/1/1 */
184 ret = rs5c348_rtc_set_time(&spi->dev, &tm);
185 if (ret < 0)
186 goto kfree_exit;
180 buf[0] = RS5C348_CMD_W(RS5C348_REG_CTL2); 187 buf[0] = RS5C348_CMD_W(RS5C348_REG_CTL2);
181 buf[1] = 0; 188 buf[1] = 0;
182 ret = spi_write_then_read(spi, buf, sizeof(buf), NULL, 0); 189 ret = spi_write_then_read(spi, buf, sizeof(buf), NULL, 0);
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
index 7553d797603f..bbdad099471d 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -160,7 +160,7 @@ static int rs5c372_rtc_proc(struct device *dev, struct seq_file *seq)
160 return 0; 160 return 0;
161} 161}
162 162
163static struct rtc_class_ops rs5c372_rtc_ops = { 163static const struct rtc_class_ops rs5c372_rtc_ops = {
164 .proc = rs5c372_rtc_proc, 164 .proc = rs5c372_rtc_proc,
165 .read_time = rs5c372_rtc_read_time, 165 .read_time = rs5c372_rtc_read_time,
166 .set_time = rs5c372_rtc_set_time, 166 .set_time = rs5c372_rtc_set_time,
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 2c7de79c83b9..625dad2eeb4f 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -386,7 +386,7 @@ static void s3c_rtc_release(struct device *dev)
386 free_irq(s3c_rtc_tickno, rtc_dev); 386 free_irq(s3c_rtc_tickno, rtc_dev);
387} 387}
388 388
389static struct rtc_class_ops s3c_rtcops = { 389static const struct rtc_class_ops s3c_rtcops = {
390 .open = s3c_rtc_open, 390 .open = s3c_rtc_open,
391 .release = s3c_rtc_release, 391 .release = s3c_rtc_release,
392 .ioctl = s3c_rtc_ioctl, 392 .ioctl = s3c_rtc_ioctl,
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index ee4b61ee67b0..439c41aea31c 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -303,7 +303,7 @@ static int sa1100_rtc_proc(struct device *dev, struct seq_file *seq)
303 return 0; 303 return 0;
304} 304}
305 305
306static struct rtc_class_ops sa1100_rtc_ops = { 306static const struct rtc_class_ops sa1100_rtc_ops = {
307 .open = sa1100_rtc_open, 307 .open = sa1100_rtc_open,
308 .read_callback = sa1100_rtc_read_callback, 308 .read_callback = sa1100_rtc_read_callback,
309 .release = sa1100_rtc_release, 309 .release = sa1100_rtc_release,
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
new file mode 100644
index 000000000000..d2ce0c8bb8f3
--- /dev/null
+++ b/drivers/rtc/rtc-sh.c
@@ -0,0 +1,467 @@
1/*
2 * SuperH On-Chip RTC Support
3 *
4 * Copyright (C) 2006 Paul Mundt
5 *
6 * Based on the old arch/sh/kernel/cpu/rtc.c by:
7 *
8 * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
9 * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka
10 *
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
13 * for more details.
14 */
15#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/bcd.h>
18#include <linux/rtc.h>
19#include <linux/init.h>
20#include <linux/platform_device.h>
21#include <linux/seq_file.h>
22#include <linux/interrupt.h>
23#include <linux/spinlock.h>
24#include <asm/io.h>
25
26#ifdef CONFIG_CPU_SH3
27#define rtc_reg_size sizeof(u16)
28#define RTC_BIT_INVERTED 0 /* No bug on SH7708, SH7709A */
29#elif defined(CONFIG_CPU_SH4)
30#define rtc_reg_size sizeof(u32)
31#define RTC_BIT_INVERTED 0x40 /* bug on SH7750, SH7750S */
32#endif
33
34#define RTC_REG(r) ((r) * rtc_reg_size)
35
36#define R64CNT RTC_REG(0)
37#define RSECCNT RTC_REG(1)
38#define RMINCNT RTC_REG(2)
39#define RHRCNT RTC_REG(3)
40#define RWKCNT RTC_REG(4)
41#define RDAYCNT RTC_REG(5)
42#define RMONCNT RTC_REG(6)
43#define RYRCNT RTC_REG(7)
44#define RSECAR RTC_REG(8)
45#define RMINAR RTC_REG(9)
46#define RHRAR RTC_REG(10)
47#define RWKAR RTC_REG(11)
48#define RDAYAR RTC_REG(12)
49#define RMONAR RTC_REG(13)
50#define RCR1 RTC_REG(14)
51#define RCR2 RTC_REG(15)
52
53/* RCR1 Bits */
54#define RCR1_CF 0x80 /* Carry Flag */
55#define RCR1_CIE 0x10 /* Carry Interrupt Enable */
56#define RCR1_AIE 0x08 /* Alarm Interrupt Enable */
57#define RCR1_AF 0x01 /* Alarm Flag */
58
59/* RCR2 Bits */
60#define RCR2_PEF 0x80 /* PEriodic interrupt Flag */
61#define RCR2_PESMASK 0x70 /* Periodic interrupt Set */
62#define RCR2_RTCEN 0x08 /* ENable RTC */
63#define RCR2_ADJ 0x04 /* ADJustment (30-second) */
64#define RCR2_RESET 0x02 /* Reset bit */
65#define RCR2_START 0x01 /* Start bit */
66
67struct sh_rtc {
68 void __iomem *regbase;
69 unsigned long regsize;
70 struct resource *res;
71 unsigned int alarm_irq, periodic_irq, carry_irq;
72 struct rtc_device *rtc_dev;
73 spinlock_t lock;
74};
75
76static irqreturn_t sh_rtc_interrupt(int irq, void *id, struct pt_regs *regs)
77{
78 struct platform_device *pdev = id;
79 struct sh_rtc *rtc = platform_get_drvdata(pdev);
80 unsigned int tmp, events = 0;
81
82 spin_lock(&rtc->lock);
83
84 tmp = readb(rtc->regbase + RCR1);
85
86 if (tmp & RCR1_AF)
87 events |= RTC_AF | RTC_IRQF;
88
89 tmp &= ~(RCR1_CF | RCR1_AF);
90
91 writeb(tmp, rtc->regbase + RCR1);
92
93 rtc_update_irq(&rtc->rtc_dev->class_dev, 1, events);
94
95 spin_unlock(&rtc->lock);
96
97 return IRQ_HANDLED;
98}
99
100static irqreturn_t sh_rtc_periodic(int irq, void *id, struct pt_regs *regs)
101{
102 struct sh_rtc *rtc = dev_get_drvdata(id);
103
104 spin_lock(&rtc->lock);
105
106 rtc_update_irq(&rtc->rtc_dev->class_dev, 1, RTC_PF | RTC_IRQF);
107
108 spin_unlock(&rtc->lock);
109
110 return IRQ_HANDLED;
111}
112
113static inline void sh_rtc_setpie(struct device *dev, unsigned int enable)
114{
115 struct sh_rtc *rtc = dev_get_drvdata(dev);
116 unsigned int tmp;
117
118 spin_lock_irq(&rtc->lock);
119
120 tmp = readb(rtc->regbase + RCR2);
121
122 if (enable) {
123 tmp &= ~RCR2_PESMASK;
124 tmp |= RCR2_PEF | (2 << 4);
125 } else
126 tmp &= ~(RCR2_PESMASK | RCR2_PEF);
127
128 writeb(tmp, rtc->regbase + RCR2);
129
130 spin_unlock_irq(&rtc->lock);
131}
132
133static inline void sh_rtc_setaie(struct device *dev, unsigned int enable)
134{
135 struct sh_rtc *rtc = dev_get_drvdata(dev);
136 unsigned int tmp;
137
138 spin_lock_irq(&rtc->lock);
139
140 tmp = readb(rtc->regbase + RCR1);
141
142 if (enable)
143 tmp |= RCR1_AIE;
144 else
145 tmp &= ~RCR1_AIE;
146
147 writeb(tmp, rtc->regbase + RCR1);
148
149 spin_unlock_irq(&rtc->lock);
150}
151
152static int sh_rtc_open(struct device *dev)
153{
154 struct sh_rtc *rtc = dev_get_drvdata(dev);
155 unsigned int tmp;
156 int ret;
157
158 tmp = readb(rtc->regbase + RCR1);
159 tmp &= ~RCR1_CF;
160 tmp |= RCR1_CIE;
161 writeb(tmp, rtc->regbase + RCR1);
162
163 ret = request_irq(rtc->periodic_irq, sh_rtc_periodic, SA_INTERRUPT,
164 "sh-rtc period", dev);
165 if (unlikely(ret)) {
166 dev_err(dev, "request period IRQ failed with %d, IRQ %d\n",
167 ret, rtc->periodic_irq);
168 return ret;
169 }
170
171 ret = request_irq(rtc->carry_irq, sh_rtc_interrupt, SA_INTERRUPT,
172 "sh-rtc carry", dev);
173 if (unlikely(ret)) {
174 dev_err(dev, "request carry IRQ failed with %d, IRQ %d\n",
175 ret, rtc->carry_irq);
176 free_irq(rtc->periodic_irq, dev);
177 goto err_bad_carry;
178 }
179
180 ret = request_irq(rtc->alarm_irq, sh_rtc_interrupt, SA_INTERRUPT,
181 "sh-rtc alarm", dev);
182 if (unlikely(ret)) {
183 dev_err(dev, "request alarm IRQ failed with %d, IRQ %d\n",
184 ret, rtc->alarm_irq);
185 goto err_bad_alarm;
186 }
187
188 return 0;
189
190err_bad_alarm:
191 free_irq(rtc->carry_irq, dev);
192err_bad_carry:
193 free_irq(rtc->periodic_irq, dev);
194
195 return ret;
196}
197
198static void sh_rtc_release(struct device *dev)
199{
200 struct sh_rtc *rtc = dev_get_drvdata(dev);
201
202 sh_rtc_setpie(dev, 0);
203
204 free_irq(rtc->periodic_irq, dev);
205 free_irq(rtc->carry_irq, dev);
206 free_irq(rtc->alarm_irq, dev);
207}
208
209static int sh_rtc_proc(struct device *dev, struct seq_file *seq)
210{
211 struct sh_rtc *rtc = dev_get_drvdata(dev);
212 unsigned int tmp;
213
214 tmp = readb(rtc->regbase + RCR1);
215 seq_printf(seq, "alarm_IRQ\t: %s\n",
216 (tmp & RCR1_AIE) ? "yes" : "no");
217 seq_printf(seq, "carry_IRQ\t: %s\n",
218 (tmp & RCR1_CIE) ? "yes" : "no");
219
220 tmp = readb(rtc->regbase + RCR2);
221 seq_printf(seq, "periodic_IRQ\t: %s\n",
222 (tmp & RCR2_PEF) ? "yes" : "no");
223
224 return 0;
225}
226
227static int sh_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
228{
229 unsigned int ret = -ENOIOCTLCMD;
230
231 switch (cmd) {
232 case RTC_PIE_OFF:
233 case RTC_PIE_ON:
234 sh_rtc_setpie(dev, cmd == RTC_PIE_ON);
235 ret = 0;
236 break;
237 case RTC_AIE_OFF:
238 case RTC_AIE_ON:
239 sh_rtc_setaie(dev, cmd == RTC_AIE_ON);
240 ret = 0;
241 break;
242 }
243
244 return ret;
245}
246
247static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm)
248{
249 struct platform_device *pdev = to_platform_device(dev);
250 struct sh_rtc *rtc = platform_get_drvdata(pdev);
251 unsigned int sec128, sec2, yr, yr100, cf_bit;
252
253 do {
254 unsigned int tmp;
255
256 spin_lock_irq(&rtc->lock);
257
258 tmp = readb(rtc->regbase + RCR1);
259 tmp &= ~RCR1_CF; /* Clear CF-bit */
260 tmp |= RCR1_CIE;
261 writeb(tmp, rtc->regbase + RCR1);
262
263 sec128 = readb(rtc->regbase + R64CNT);
264
265 tm->tm_sec = BCD2BIN(readb(rtc->regbase + RSECCNT));
266 tm->tm_min = BCD2BIN(readb(rtc->regbase + RMINCNT));
267 tm->tm_hour = BCD2BIN(readb(rtc->regbase + RHRCNT));
268 tm->tm_wday = BCD2BIN(readb(rtc->regbase + RWKCNT));
269 tm->tm_mday = BCD2BIN(readb(rtc->regbase + RDAYCNT));
270 tm->tm_mon = BCD2BIN(readb(rtc->regbase + RMONCNT));
271
272#if defined(CONFIG_CPU_SH4)
273 yr = readw(rtc->regbase + RYRCNT);
274 yr100 = BCD2BIN(yr >> 8);
275 yr &= 0xff;
276#else
277 yr = readb(rtc->regbase + RYRCNT);
278 yr100 = BCD2BIN((yr == 0x99) ? 0x19 : 0x20);
279#endif
280
281 tm->tm_year = (yr100 * 100 + BCD2BIN(yr)) - 1900;
282
283 sec2 = readb(rtc->regbase + R64CNT);
284 cf_bit = readb(rtc->regbase + RCR1) & RCR1_CF;
285
286 spin_unlock_irq(&rtc->lock);
287 } while (cf_bit != 0 || ((sec128 ^ sec2) & RTC_BIT_INVERTED) != 0);
288
289#if RTC_BIT_INVERTED != 0
290 if ((sec128 & RTC_BIT_INVERTED))
291 tm->tm_sec--;
292#endif
293
294 dev_dbg(&dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
295 "mday=%d, mon=%d, year=%d, wday=%d\n",
296 __FUNCTION__,
297 tm->tm_sec, tm->tm_min, tm->tm_hour,
298 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
299
300 if (rtc_valid_tm(tm) < 0)
301 dev_err(dev, "invalid date\n");
302
303 return 0;
304}
305
306static int sh_rtc_set_time(struct device *dev, struct rtc_time *tm)
307{
308 struct platform_device *pdev = to_platform_device(dev);
309 struct sh_rtc *rtc = platform_get_drvdata(pdev);
310 unsigned int tmp;
311 int year;
312
313 spin_lock_irq(&rtc->lock);
314
315 /* Reset pre-scaler & stop RTC */
316 tmp = readb(rtc->regbase + RCR2);
317 tmp |= RCR2_RESET;
318 writeb(tmp, rtc->regbase + RCR2);
319
320 writeb(BIN2BCD(tm->tm_sec), rtc->regbase + RSECCNT);
321 writeb(BIN2BCD(tm->tm_min), rtc->regbase + RMINCNT);
322 writeb(BIN2BCD(tm->tm_hour), rtc->regbase + RHRCNT);
323 writeb(BIN2BCD(tm->tm_wday), rtc->regbase + RWKCNT);
324 writeb(BIN2BCD(tm->tm_mday), rtc->regbase + RDAYCNT);
325 writeb(BIN2BCD(tm->tm_mon), rtc->regbase + RMONCNT);
326
327#ifdef CONFIG_CPU_SH3
328 year = tm->tm_year % 100;
329 writeb(BIN2BCD(year), rtc->regbase + RYRCNT);
330#else
331 year = (BIN2BCD((tm->tm_year + 1900) / 100) << 8) |
332 BIN2BCD(tm->tm_year % 100);
333 writew(year, rtc->regbase + RYRCNT);
334#endif
335
336 /* Start RTC */
337 tmp = readb(rtc->regbase + RCR2);
338 tmp &= ~RCR2_RESET;
339 tmp |= RCR2_RTCEN | RCR2_START;
340 writeb(tmp, rtc->regbase + RCR2);
341
342 spin_unlock_irq(&rtc->lock);
343
344 return 0;
345}
346
347static struct rtc_class_ops sh_rtc_ops = {
348 .open = sh_rtc_open,
349 .release = sh_rtc_release,
350 .ioctl = sh_rtc_ioctl,
351 .read_time = sh_rtc_read_time,
352 .set_time = sh_rtc_set_time,
353 .proc = sh_rtc_proc,
354};
355
356static int __devinit sh_rtc_probe(struct platform_device *pdev)
357{
358 struct sh_rtc *rtc;
359 struct resource *res;
360 int ret = -ENOENT;
361
362 rtc = kzalloc(sizeof(struct sh_rtc), GFP_KERNEL);
363 if (unlikely(!rtc))
364 return -ENOMEM;
365
366 spin_lock_init(&rtc->lock);
367
368 rtc->periodic_irq = platform_get_irq(pdev, 0);
369 if (unlikely(rtc->periodic_irq < 0)) {
370 dev_err(&pdev->dev, "No IRQ for period\n");
371 goto err_badres;
372 }
373
374 rtc->carry_irq = platform_get_irq(pdev, 1);
375 if (unlikely(rtc->carry_irq < 0)) {
376 dev_err(&pdev->dev, "No IRQ for carry\n");
377 goto err_badres;
378 }
379
380 rtc->alarm_irq = platform_get_irq(pdev, 2);
381 if (unlikely(rtc->alarm_irq < 0)) {
382 dev_err(&pdev->dev, "No IRQ for alarm\n");
383 goto err_badres;
384 }
385
386 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
387 if (unlikely(res == NULL)) {
388 dev_err(&pdev->dev, "No IO resource\n");
389 goto err_badres;
390 }
391
392 rtc->regsize = res->end - res->start + 1;
393
394 rtc->res = request_mem_region(res->start, rtc->regsize, pdev->name);
395 if (unlikely(!rtc->res)) {
396 ret = -EBUSY;
397 goto err_badres;
398 }
399
400 rtc->regbase = (void __iomem *)rtc->res->start;
401 if (unlikely(!rtc->regbase)) {
402 ret = -EINVAL;
403 goto err_badmap;
404 }
405
406 rtc->rtc_dev = rtc_device_register("sh", &pdev->dev,
407 &sh_rtc_ops, THIS_MODULE);
408 if (IS_ERR(rtc)) {
409 ret = PTR_ERR(rtc->rtc_dev);
410 goto err_badmap;
411 }
412
413 platform_set_drvdata(pdev, rtc);
414
415 return 0;
416
417err_badmap:
418 release_resource(rtc->res);
419err_badres:
420 kfree(rtc);
421
422 return ret;
423}
424
425static int __devexit sh_rtc_remove(struct platform_device *pdev)
426{
427 struct sh_rtc *rtc = platform_get_drvdata(pdev);
428
429 if (likely(rtc->rtc_dev))
430 rtc_device_unregister(rtc->rtc_dev);
431
432 sh_rtc_setpie(&pdev->dev, 0);
433 sh_rtc_setaie(&pdev->dev, 0);
434
435 release_resource(rtc->res);
436
437 platform_set_drvdata(pdev, NULL);
438
439 kfree(rtc);
440
441 return 0;
442}
443static struct platform_driver sh_rtc_platform_driver = {
444 .driver = {
445 .name = "sh-rtc",
446 .owner = THIS_MODULE,
447 },
448 .probe = sh_rtc_probe,
449 .remove = __devexit_p(sh_rtc_remove),
450};
451
452static int __init sh_rtc_init(void)
453{
454 return platform_driver_register(&sh_rtc_platform_driver);
455}
456
457static void __exit sh_rtc_exit(void)
458{
459 platform_driver_unregister(&sh_rtc_platform_driver);
460}
461
462module_init(sh_rtc_init);
463module_exit(sh_rtc_exit);
464
465MODULE_DESCRIPTION("SuperH on-chip RTC driver");
466MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>");
467MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
index 7c1f3d2e53c4..625637b84d33 100644
--- a/drivers/rtc/rtc-sysfs.c
+++ b/drivers/rtc/rtc-sysfs.c
@@ -116,7 +116,7 @@ static void __exit rtc_sysfs_exit(void)
116 class_interface_unregister(&rtc_sysfs_interface); 116 class_interface_unregister(&rtc_sysfs_interface);
117} 117}
118 118
119module_init(rtc_sysfs_init); 119subsys_initcall(rtc_sysfs_init);
120module_exit(rtc_sysfs_exit); 120module_exit(rtc_sysfs_exit);
121 121
122MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); 122MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
index e1fa5fe7901f..bc4bd24508a2 100644
--- a/drivers/rtc/rtc-test.c
+++ b/drivers/rtc/rtc-test.c
@@ -75,7 +75,7 @@ static int test_rtc_ioctl(struct device *dev, unsigned int cmd,
75 } 75 }
76} 76}
77 77
78static struct rtc_class_ops test_rtc_ops = { 78static const struct rtc_class_ops test_rtc_ops = {
79 .proc = test_rtc_proc, 79 .proc = test_rtc_proc,
80 .read_time = test_rtc_read_time, 80 .read_time = test_rtc_read_time,
81 .set_time = test_rtc_set_time, 81 .set_time = test_rtc_set_time,
diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c
index a40f400acff6..09b714f1cdc3 100644
--- a/drivers/rtc/rtc-v3020.c
+++ b/drivers/rtc/rtc-v3020.c
@@ -149,7 +149,7 @@ static int v3020_set_time(struct device *dev, struct rtc_time *dt)
149 return 0; 149 return 0;
150} 150}
151 151
152static struct rtc_class_ops v3020_rtc_ops = { 152static const struct rtc_class_ops v3020_rtc_ops = {
153 .read_time = v3020_read_time, 153 .read_time = v3020_read_time,
154 .set_time = v3020_set_time, 154 .set_time = v3020_set_time,
155}; 155};
@@ -169,9 +169,6 @@ static int rtc_probe(struct platform_device *pdev)
169 if (pdev->resource[0].flags != IORESOURCE_MEM) 169 if (pdev->resource[0].flags != IORESOURCE_MEM)
170 return -EBUSY; 170 return -EBUSY;
171 171
172 if (pdev == NULL)
173 return -EBUSY;
174
175 chip = kzalloc(sizeof *chip, GFP_KERNEL); 172 chip = kzalloc(sizeof *chip, GFP_KERNEL);
176 if (!chip) 173 if (!chip)
177 return -ENOMEM; 174 return -ENOMEM;
diff --git a/drivers/rtc/rtc-vr41xx.c b/drivers/rtc/rtc-vr41xx.c
index 596764fd29f5..58e5ed0aa127 100644
--- a/drivers/rtc/rtc-vr41xx.c
+++ b/drivers/rtc/rtc-vr41xx.c
@@ -296,7 +296,7 @@ static irqreturn_t rtclong1_interrupt(int irq, void *dev_id, struct pt_regs *reg
296 return IRQ_HANDLED; 296 return IRQ_HANDLED;
297} 297}
298 298
299static struct rtc_class_ops vr41xx_rtc_ops = { 299static const struct rtc_class_ops vr41xx_rtc_ops = {
300 .release = vr41xx_rtc_release, 300 .release = vr41xx_rtc_release,
301 .ioctl = vr41xx_rtc_ioctl, 301 .ioctl = vr41xx_rtc_ioctl,
302 .read_time = vr41xx_rtc_read_time, 302 .read_time = vr41xx_rtc_read_time,
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index 788b6d1f8f2f..522c69753bbf 100644
--- a/drivers/rtc/rtc-x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -460,7 +460,7 @@ static int x1205_rtc_proc(struct device *dev, struct seq_file *seq)
460 return 0; 460 return 0;
461} 461}
462 462
463static struct rtc_class_ops x1205_rtc_ops = { 463static const struct rtc_class_ops x1205_rtc_ops = {
464 .proc = x1205_rtc_proc, 464 .proc = x1205_rtc_proc,
465 .read_time = x1205_rtc_read_time, 465 .read_time = x1205_rtc_read_time,
466 .set_time = x1205_rtc_set_time, 466 .set_time = x1205_rtc_set_time,
diff --git a/drivers/s390/block/Kconfig b/drivers/s390/block/Kconfig
index 929d6fff6152..b250c5354503 100644
--- a/drivers/s390/block/Kconfig
+++ b/drivers/s390/block/Kconfig
@@ -1,4 +1,4 @@
1if S390 1if S390 && BLOCK
2 2
3comment "S/390 block device drivers" 3comment "S/390 block device drivers"
4 depends on S390 4 depends on S390
diff --git a/drivers/s390/block/dasd_diag.c b/drivers/s390/block/dasd_diag.c
index 23fa0b289173..222a8a71a5e8 100644
--- a/drivers/s390/block/dasd_diag.c
+++ b/drivers/s390/block/dasd_diag.c
@@ -63,44 +63,26 @@ static const u8 DASD_DIAG_CMS1[] = { 0xc3, 0xd4, 0xe2, 0xf1 };/* EBCDIC CMS1 */
63 * and function code cmd. 63 * and function code cmd.
64 * In case of an exception return 3. Otherwise return result of bitwise OR of 64 * In case of an exception return 3. Otherwise return result of bitwise OR of
65 * resulting condition code and DIAG return code. */ 65 * resulting condition code and DIAG return code. */
66static __inline__ int 66static inline int dia250(void *iob, int cmd)
67dia250(void *iob, int cmd)
68{ 67{
68 register unsigned long reg0 asm ("0") = (unsigned long) iob;
69 typedef union { 69 typedef union {
70 struct dasd_diag_init_io init_io; 70 struct dasd_diag_init_io init_io;
71 struct dasd_diag_rw_io rw_io; 71 struct dasd_diag_rw_io rw_io;
72 } addr_type; 72 } addr_type;
73 int rc; 73 int rc;
74 74
75 __asm__ __volatile__( 75 rc = 3;
76#ifdef CONFIG_64BIT 76 asm volatile(
77 " lghi %0,3\n"
78 " lgr 0,%3\n"
79 " diag 0,%2,0x250\n"
80 "0: ipm %0\n"
81 " srl %0,28\n"
82 " or %0,1\n"
83 "1:\n"
84 ".section __ex_table,\"a\"\n"
85 " .align 8\n"
86 " .quad 0b,1b\n"
87 ".previous\n"
88#else
89 " lhi %0,3\n"
90 " lr 0,%3\n"
91 " diag 0,%2,0x250\n" 77 " diag 0,%2,0x250\n"
92 "0: ipm %0\n" 78 "0: ipm %0\n"
93 " srl %0,28\n" 79 " srl %0,28\n"
94 " or %0,1\n" 80 " or %0,1\n"
95 "1:\n" 81 "1:\n"
96 ".section __ex_table,\"a\"\n" 82 EX_TABLE(0b,1b)
97 " .align 4\n" 83 : "+d" (rc), "=m" (*(addr_type *) iob)
98 " .long 0b,1b\n" 84 : "d" (cmd), "d" (reg0), "m" (*(addr_type *) iob)
99 ".previous\n" 85 : "1", "cc");
100#endif
101 : "=&d" (rc), "=m" (*(addr_type *) iob)
102 : "d" (cmd), "d" (iob), "m" (*(addr_type *) iob)
103 : "0", "1", "cc");
104 return rc; 86 return rc;
105} 87}
106 88
@@ -547,7 +529,7 @@ dasd_diag_build_cp(struct dasd_device * device, struct request *req)
547 } 529 }
548 cqr->retries = DIAG_MAX_RETRIES; 530 cqr->retries = DIAG_MAX_RETRIES;
549 cqr->buildclk = get_clock(); 531 cqr->buildclk = get_clock();
550 if (req->flags & REQ_FAILFAST) 532 if (req->cmd_flags & REQ_FAILFAST)
551 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); 533 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
552 cqr->device = device; 534 cqr->device = device;
553 cqr->expires = DIAG_TIMEOUT; 535 cqr->expires = DIAG_TIMEOUT;
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
index b7a7fac3f7c3..5ecea3e4fdef 100644
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -1266,7 +1266,7 @@ dasd_eckd_build_cp(struct dasd_device * device, struct request *req)
1266 recid++; 1266 recid++;
1267 } 1267 }
1268 } 1268 }
1269 if (req->flags & REQ_FAILFAST) 1269 if (req->cmd_flags & REQ_FAILFAST)
1270 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); 1270 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
1271 cqr->device = device; 1271 cqr->device = device;
1272 cqr->expires = 5 * 60 * HZ; /* 5 minutes */ 1272 cqr->expires = 5 * 60 * HZ; /* 5 minutes */
diff --git a/drivers/s390/block/dasd_fba.c b/drivers/s390/block/dasd_fba.c
index e85015be109b..80926c548228 100644
--- a/drivers/s390/block/dasd_fba.c
+++ b/drivers/s390/block/dasd_fba.c
@@ -344,7 +344,7 @@ dasd_fba_build_cp(struct dasd_device * device, struct request *req)
344 recid++; 344 recid++;
345 } 345 }
346 } 346 }
347 if (req->flags & REQ_FAILFAST) 347 if (req->cmd_flags & REQ_FAILFAST)
348 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); 348 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
349 cqr->device = device; 349 cqr->device = device;
350 cqr->expires = 5 * 60 * HZ; /* 5 minutes */ 350 cqr->expires = 5 * 60 * HZ; /* 5 minutes */
diff --git a/drivers/s390/block/xpram.c b/drivers/s390/block/xpram.c
index cab2c736683a..a04d9120cef0 100644
--- a/drivers/s390/block/xpram.c
+++ b/drivers/s390/block/xpram.c
@@ -89,28 +89,15 @@ MODULE_LICENSE("GPL");
89 */ 89 */
90static int xpram_page_in (unsigned long page_addr, unsigned int xpage_index) 90static int xpram_page_in (unsigned long page_addr, unsigned int xpage_index)
91{ 91{
92 int cc; 92 int cc = 2; /* return unused cc 2 if pgin traps */
93 93
94 __asm__ __volatile__ ( 94 asm volatile(
95 " lhi %0,2\n" /* return unused cc 2 if pgin traps */ 95 " .insn rre,0xb22e0000,%1,%2\n" /* pgin %1,%2 */
96 " .insn rre,0xb22e0000,%1,%2\n" /* pgin %1,%2 */ 96 "0: ipm %0\n"
97 "0: ipm %0\n" 97 " srl %0,28\n"
98 " srl %0,28\n"
99 "1:\n" 98 "1:\n"
100#ifndef CONFIG_64BIT 99 EX_TABLE(0b,1b)
101 ".section __ex_table,\"a\"\n" 100 : "+d" (cc) : "a" (__pa(page_addr)), "d" (xpage_index) : "cc");
102 " .align 4\n"
103 " .long 0b,1b\n"
104 ".previous"
105#else
106 ".section __ex_table,\"a\"\n"
107 " .align 8\n"
108 " .quad 0b,1b\n"
109 ".previous"
110#endif
111 : "=&d" (cc)
112 : "a" (__pa(page_addr)), "a" (xpage_index)
113 : "cc" );
114 if (cc == 3) 101 if (cc == 3)
115 return -ENXIO; 102 return -ENXIO;
116 if (cc == 2) { 103 if (cc == 2) {
@@ -137,28 +124,15 @@ static int xpram_page_in (unsigned long page_addr, unsigned int xpage_index)
137 */ 124 */
138static long xpram_page_out (unsigned long page_addr, unsigned int xpage_index) 125static long xpram_page_out (unsigned long page_addr, unsigned int xpage_index)
139{ 126{
140 int cc; 127 int cc = 2; /* return unused cc 2 if pgin traps */
141 128
142 __asm__ __volatile__ ( 129 asm volatile(
143 " lhi %0,2\n" /* return unused cc 2 if pgout traps */ 130 " .insn rre,0xb22f0000,%1,%2\n" /* pgout %1,%2 */
144 " .insn rre,0xb22f0000,%1,%2\n" /* pgout %1,%2 */ 131 "0: ipm %0\n"
145 "0: ipm %0\n" 132 " srl %0,28\n"
146 " srl %0,28\n"
147 "1:\n" 133 "1:\n"
148#ifndef CONFIG_64BIT 134 EX_TABLE(0b,1b)
149 ".section __ex_table,\"a\"\n" 135 : "+d" (cc) : "a" (__pa(page_addr)), "d" (xpage_index) : "cc");
150 " .align 4\n"
151 " .long 0b,1b\n"
152 ".previous"
153#else
154 ".section __ex_table,\"a\"\n"
155 " .align 8\n"
156 " .quad 0b,1b\n"
157 ".previous"
158#endif
159 : "=&d" (cc)
160 : "a" (__pa(page_addr)), "a" (xpage_index)
161 : "cc" );
162 if (cc == 3) 136 if (cc == 3)
163 return -ENXIO; 137 return -ENXIO;
164 if (cc == 2) { 138 if (cc == 2) {
diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index 2fa566fa6da4..d7de175d53f0 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -1103,7 +1103,7 @@ tty3215_start(struct tty_struct *tty)
1103 } 1103 }
1104} 1104}
1105 1105
1106static struct tty_operations tty3215_ops = { 1106static const struct tty_operations tty3215_ops = {
1107 .open = tty3215_open, 1107 .open = tty3215_open,
1108 .close = tty3215_close, 1108 .close = tty3215_close,
1109 .write = tty3215_write, 1109 .write = tty3215_write,
diff --git a/drivers/s390/char/fs3270.c b/drivers/s390/char/fs3270.c
index ef004d089712..78f8bda81dae 100644
--- a/drivers/s390/char/fs3270.c
+++ b/drivers/s390/char/fs3270.c
@@ -17,7 +17,6 @@
17 17
18#include <asm/ccwdev.h> 18#include <asm/ccwdev.h>
19#include <asm/cio.h> 19#include <asm/cio.h>
20#include <asm/cpcmd.h>
21#include <asm/ebcdic.h> 20#include <asm/ebcdic.h>
22#include <asm/idals.h> 21#include <asm/idals.h>
23 22
@@ -28,7 +27,7 @@ struct raw3270_fn fs3270_fn;
28 27
29struct fs3270 { 28struct fs3270 {
30 struct raw3270_view view; 29 struct raw3270_view view;
31 pid_t fs_pid; /* Pid of controlling program. */ 30 struct pid *fs_pid; /* Pid of controlling program. */
32 int read_command; /* ccw command to use for reads. */ 31 int read_command; /* ccw command to use for reads. */
33 int write_command; /* ccw command to use for writes. */ 32 int write_command; /* ccw command to use for writes. */
34 int attention; /* Got attention. */ 33 int attention; /* Got attention. */
@@ -103,7 +102,7 @@ fs3270_restore_callback(struct raw3270_request *rq, void *data)
103 fp = (struct fs3270 *) rq->view; 102 fp = (struct fs3270 *) rq->view;
104 if (rq->rc != 0 || rq->rescnt != 0) { 103 if (rq->rc != 0 || rq->rescnt != 0) {
105 if (fp->fs_pid) 104 if (fp->fs_pid)
106 kill_proc(fp->fs_pid, SIGHUP, 1); 105 kill_pid(fp->fs_pid, SIGHUP, 1);
107 } 106 }
108 fp->rdbuf_size = 0; 107 fp->rdbuf_size = 0;
109 raw3270_request_reset(rq); 108 raw3270_request_reset(rq);
@@ -174,7 +173,7 @@ fs3270_save_callback(struct raw3270_request *rq, void *data)
174 */ 173 */
175 if (rq->rc != 0 || rq->rescnt == 0) { 174 if (rq->rc != 0 || rq->rescnt == 0) {
176 if (fp->fs_pid) 175 if (fp->fs_pid)
177 kill_proc(fp->fs_pid, SIGHUP, 1); 176 kill_pid(fp->fs_pid, SIGHUP, 1);
178 fp->rdbuf_size = 0; 177 fp->rdbuf_size = 0;
179 } else 178 } else
180 fp->rdbuf_size = fp->rdbuf->size - rq->rescnt; 179 fp->rdbuf_size = fp->rdbuf->size - rq->rescnt;
@@ -443,7 +442,7 @@ fs3270_open(struct inode *inode, struct file *filp)
443 return PTR_ERR(fp); 442 return PTR_ERR(fp);
444 443
445 init_waitqueue_head(&fp->wait); 444 init_waitqueue_head(&fp->wait);
446 fp->fs_pid = current->pid; 445 fp->fs_pid = get_pid(task_pid(current));
447 rc = raw3270_add_view(&fp->view, &fs3270_fn, minor); 446 rc = raw3270_add_view(&fp->view, &fs3270_fn, minor);
448 if (rc) { 447 if (rc) {
449 fs3270_free_view(&fp->view); 448 fs3270_free_view(&fp->view);
@@ -481,7 +480,8 @@ fs3270_close(struct inode *inode, struct file *filp)
481 fp = filp->private_data; 480 fp = filp->private_data;
482 filp->private_data = NULL; 481 filp->private_data = NULL;
483 if (fp) { 482 if (fp) {
484 fp->fs_pid = 0; 483 put_pid(fp->fs_pid);
484 fp->fs_pid = NULL;
485 raw3270_reset(&fp->view); 485 raw3270_reset(&fp->view);
486 raw3270_put_view(&fp->view); 486 raw3270_put_view(&fp->view);
487 raw3270_del_view(&fp->view); 487 raw3270_del_view(&fp->view);
diff --git a/drivers/s390/char/sclp.c b/drivers/s390/char/sclp.c
index 985d1613baaa..31e335751d6d 100644
--- a/drivers/s390/char/sclp.c
+++ b/drivers/s390/char/sclp.c
@@ -100,13 +100,12 @@ service_call(sclp_cmdw_t command, void *sccb)
100{ 100{
101 int cc; 101 int cc;
102 102
103 __asm__ __volatile__( 103 asm volatile(
104 " .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */ 104 " .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */
105 " ipm %0\n" 105 " ipm %0\n"
106 " srl %0,28" 106 " srl %0,28"
107 : "=&d" (cc) 107 : "=&d" (cc) : "d" (command), "a" (__pa(sccb))
108 : "d" (command), "a" (__pa(sccb)) 108 : "cc", "memory");
109 : "cc", "memory" );
110 if (cc == 3) 109 if (cc == 3)
111 return -EIO; 110 return -EIO;
112 if (cc == 2) 111 if (cc == 2)
@@ -360,16 +359,6 @@ sclp_interrupt_handler(struct pt_regs *regs, __u16 code)
360 sclp_process_queue(); 359 sclp_process_queue();
361} 360}
362 361
363/* Return current Time-Of-Day clock. */
364static inline u64
365sclp_get_clock(void)
366{
367 u64 result;
368
369 asm volatile ("STCK 0(%1)" : "=m" (result) : "a" (&(result)) : "cc");
370 return result;
371}
372
373/* Convert interval in jiffies to TOD ticks. */ 362/* Convert interval in jiffies to TOD ticks. */
374static inline u64 363static inline u64
375sclp_tod_from_jiffies(unsigned long jiffies) 364sclp_tod_from_jiffies(unsigned long jiffies)
@@ -382,7 +371,6 @@ sclp_tod_from_jiffies(unsigned long jiffies)
382void 371void
383sclp_sync_wait(void) 372sclp_sync_wait(void)
384{ 373{
385 unsigned long psw_mask;
386 unsigned long flags; 374 unsigned long flags;
387 unsigned long cr0, cr0_sync; 375 unsigned long cr0, cr0_sync;
388 u64 timeout; 376 u64 timeout;
@@ -392,7 +380,7 @@ sclp_sync_wait(void)
392 timeout = 0; 380 timeout = 0;
393 if (timer_pending(&sclp_request_timer)) { 381 if (timer_pending(&sclp_request_timer)) {
394 /* Get timeout TOD value */ 382 /* Get timeout TOD value */
395 timeout = sclp_get_clock() + 383 timeout = get_clock() +
396 sclp_tod_from_jiffies(sclp_request_timer.expires - 384 sclp_tod_from_jiffies(sclp_request_timer.expires -
397 jiffies); 385 jiffies);
398 } 386 }
@@ -406,13 +394,12 @@ sclp_sync_wait(void)
406 cr0_sync |= 0x00000200; 394 cr0_sync |= 0x00000200;
407 cr0_sync &= 0xFFFFF3AC; 395 cr0_sync &= 0xFFFFF3AC;
408 __ctl_load(cr0_sync, 0, 0); 396 __ctl_load(cr0_sync, 0, 0);
409 asm volatile ("STOSM 0(%1),0x01" 397 __raw_local_irq_stosm(0x01);
410 : "=m" (psw_mask) : "a" (&psw_mask) : "memory");
411 /* Loop until driver state indicates finished request */ 398 /* Loop until driver state indicates finished request */
412 while (sclp_running_state != sclp_running_state_idle) { 399 while (sclp_running_state != sclp_running_state_idle) {
413 /* Check for expired request timer */ 400 /* Check for expired request timer */
414 if (timer_pending(&sclp_request_timer) && 401 if (timer_pending(&sclp_request_timer) &&
415 sclp_get_clock() > timeout && 402 get_clock() > timeout &&
416 del_timer(&sclp_request_timer)) 403 del_timer(&sclp_request_timer))
417 sclp_request_timer.function(sclp_request_timer.data); 404 sclp_request_timer.function(sclp_request_timer.data);
418 barrier(); 405 barrier();
diff --git a/drivers/s390/char/sclp_tty.c b/drivers/s390/char/sclp_tty.c
index f6cf9023039e..6f43e04dbefd 100644
--- a/drivers/s390/char/sclp_tty.c
+++ b/drivers/s390/char/sclp_tty.c
@@ -711,7 +711,7 @@ static struct sclp_register sclp_input_event =
711 .receiver_fn = sclp_tty_receiver 711 .receiver_fn = sclp_tty_receiver
712}; 712};
713 713
714static struct tty_operations sclp_ops = { 714static const struct tty_operations sclp_ops = {
715 .open = sclp_tty_open, 715 .open = sclp_tty_open,
716 .close = sclp_tty_close, 716 .close = sclp_tty_close,
717 .write = sclp_tty_write, 717 .write = sclp_tty_write,
diff --git a/drivers/s390/char/sclp_vt220.c b/drivers/s390/char/sclp_vt220.c
index 54fba6f17188..723bf4191bfe 100644
--- a/drivers/s390/char/sclp_vt220.c
+++ b/drivers/s390/char/sclp_vt220.c
@@ -655,7 +655,7 @@ __sclp_vt220_init(int early)
655 return 0; 655 return 0;
656} 656}
657 657
658static struct tty_operations sclp_vt220_ops = { 658static const struct tty_operations sclp_vt220_ops = {
659 .open = sclp_vt220_open, 659 .open = sclp_vt220_open,
660 .close = sclp_vt220_close, 660 .close = sclp_vt220_close,
661 .write = sclp_vt220_write, 661 .write = sclp_vt220_write,
diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c
index 29718042c6c9..4717c3611601 100644
--- a/drivers/s390/char/tty3270.c
+++ b/drivers/s390/char/tty3270.c
@@ -698,7 +698,6 @@ tty3270_alloc_view(void)
698 if (!tp->freemem_pages) 698 if (!tp->freemem_pages)
699 goto out_tp; 699 goto out_tp;
700 INIT_LIST_HEAD(&tp->freemem); 700 INIT_LIST_HEAD(&tp->freemem);
701 init_timer(&tp->timer);
702 for (pages = 0; pages < TTY3270_STRING_PAGES; pages++) { 701 for (pages = 0; pages < TTY3270_STRING_PAGES; pages++) {
703 tp->freemem_pages[pages] = (void *) 702 tp->freemem_pages[pages] = (void *)
704 __get_free_pages(GFP_KERNEL|GFP_DMA, 0); 703 __get_free_pages(GFP_KERNEL|GFP_DMA, 0);
@@ -1738,7 +1737,7 @@ tty3270_ioctl(struct tty_struct *tty, struct file *file,
1738 return kbd_ioctl(tp->kbd, file, cmd, arg); 1737 return kbd_ioctl(tp->kbd, file, cmd, arg);
1739} 1738}
1740 1739
1741static struct tty_operations tty3270_ops = { 1740static const struct tty_operations tty3270_ops = {
1742 .open = tty3270_open, 1741 .open = tty3270_open,
1743 .close = tty3270_close, 1742 .close = tty3270_close,
1744 .write = tty3270_write, 1743 .write = tty3270_write,
diff --git a/drivers/s390/char/vmwatchdog.c b/drivers/s390/char/vmwatchdog.c
index 807320a41fa4..4b868f72fe89 100644
--- a/drivers/s390/char/vmwatchdog.c
+++ b/drivers/s390/char/vmwatchdog.c
@@ -54,48 +54,20 @@ enum vmwdt_func {
54static int __diag288(enum vmwdt_func func, unsigned int timeout, 54static int __diag288(enum vmwdt_func func, unsigned int timeout,
55 char *cmd, size_t len) 55 char *cmd, size_t len)
56{ 56{
57 register unsigned long __func asm("2"); 57 register unsigned long __func asm("2") = func;
58 register unsigned long __timeout asm("3"); 58 register unsigned long __timeout asm("3") = timeout;
59 register unsigned long __cmdp asm("4"); 59 register unsigned long __cmdp asm("4") = virt_to_phys(cmd);
60 register unsigned long __cmdl asm("5"); 60 register unsigned long __cmdl asm("5") = len;
61 int err; 61 int err;
62 62
63 __func = func; 63 err = -EINVAL;
64 __timeout = timeout; 64 asm volatile(
65 __cmdp = virt_to_phys(cmd); 65 " diag %1,%3,0x288\n"
66 __cmdl = len; 66 "0: la %0,0\n"
67 err = 0; 67 "1:\n"
68 asm volatile ( 68 EX_TABLE(0b,1b)
69#ifdef CONFIG_64BIT 69 : "=d" (err) : "d"(__func), "d"(__timeout),
70 "diag %2,%4,0x288\n" 70 "d"(__cmdp), "d"(__cmdl), "0" (-EINVAL) : "1", "cc");
71 "1: \n"
72 ".section .fixup,\"ax\"\n"
73 "2: lghi %0,%1\n"
74 " jg 1b\n"
75 ".previous\n"
76 ".section __ex_table,\"a\"\n"
77 " .align 8\n"
78 " .quad 1b,2b\n"
79 ".previous\n"
80#else
81 "diag %2,%4,0x288\n"
82 "1: \n"
83 ".section .fixup,\"ax\"\n"
84 "2: lhi %0,%1\n"
85 " bras 1,3f\n"
86 " .long 1b\n"
87 "3: l 1,0(1)\n"
88 " br 1\n"
89 ".previous\n"
90 ".section __ex_table,\"a\"\n"
91 " .align 4\n"
92 " .long 1b,2b\n"
93 ".previous\n"
94#endif
95 : "+&d"(err)
96 : "i"(-EINVAL), "d"(__func), "d"(__timeout),
97 "d"(__cmdp), "d"(__cmdl)
98 : "1", "cc");
99 return err; 71 return err;
100} 72}
101 73
diff --git a/drivers/s390/cio/device_id.c b/drivers/s390/cio/device_id.c
index 438db483035d..1398367b5f68 100644
--- a/drivers/s390/cio/device_id.c
+++ b/drivers/s390/cio/device_id.c
@@ -42,18 +42,15 @@ diag210(struct diag210 * addr)
42 spin_lock_irqsave(&diag210_lock, flags); 42 spin_lock_irqsave(&diag210_lock, flags);
43 diag210_tmp = *addr; 43 diag210_tmp = *addr;
44 44
45 asm volatile ( 45 asm volatile(
46 " lhi %0,-1\n" 46 " lhi %0,-1\n"
47 " sam31\n" 47 " sam31\n"
48 " diag %1,0,0x210\n" 48 " diag %1,0,0x210\n"
49 "0: ipm %0\n" 49 "0: ipm %0\n"
50 " srl %0,28\n" 50 " srl %0,28\n"
51 "1: sam64\n" 51 "1: sam64\n"
52 ".section __ex_table,\"a\"\n" 52 EX_TABLE(0b,1b)
53 " .align 8\n" 53 : "=&d" (ccode) : "a" (__pa(&diag210_tmp)) : "cc", "memory");
54 " .quad 0b,1b\n"
55 ".previous"
56 : "=&d" (ccode) : "a" (__pa(&diag210_tmp)) : "cc", "memory" );
57 54
58 *addr = diag210_tmp; 55 *addr = diag210_tmp;
59 spin_unlock_irqrestore(&diag210_lock, flags); 56 spin_unlock_irqrestore(&diag210_lock, flags);
@@ -66,17 +63,14 @@ diag210(struct diag210 * addr)
66{ 63{
67 int ccode; 64 int ccode;
68 65
69 asm volatile ( 66 asm volatile(
70 " lhi %0,-1\n" 67 " lhi %0,-1\n"
71 " diag %1,0,0x210\n" 68 " diag %1,0,0x210\n"
72 "0: ipm %0\n" 69 "0: ipm %0\n"
73 " srl %0,28\n" 70 " srl %0,28\n"
74 "1:\n" 71 "1:\n"
75 ".section __ex_table,\"a\"\n" 72 EX_TABLE(0b,1b)
76 " .align 4\n" 73 : "=&d" (ccode) : "a" (__pa(addr)) : "cc", "memory");
77 " .long 0b,1b\n"
78 ".previous"
79 : "=&d" (ccode) : "a" (__pa(addr)) : "cc", "memory" );
80 74
81 return ccode; 75 return ccode;
82} 76}
diff --git a/drivers/s390/cio/ioasm.h b/drivers/s390/cio/ioasm.h
index 95a9462f9a91..ad6d82940069 100644
--- a/drivers/s390/cio/ioasm.h
+++ b/drivers/s390/cio/ioasm.h
@@ -25,106 +25,74 @@ struct tpi_info {
25static inline int stsch(struct subchannel_id schid, 25static inline int stsch(struct subchannel_id schid,
26 volatile struct schib *addr) 26 volatile struct schib *addr)
27{ 27{
28 register struct subchannel_id reg1 asm ("1") = schid;
28 int ccode; 29 int ccode;
29 30
30 __asm__ __volatile__( 31 asm volatile(
31 " lr 1,%1\n" 32 " stsch 0(%2)\n"
32 " stsch 0(%2)\n" 33 " ipm %0\n"
33 " ipm %0\n" 34 " srl %0,28"
34 " srl %0,28" 35 : "=d" (ccode) : "d" (reg1), "a" (addr), "m" (*addr) : "cc");
35 : "=d" (ccode)
36 : "d" (schid), "a" (addr), "m" (*addr)
37 : "cc", "1" );
38 return ccode; 36 return ccode;
39} 37}
40 38
41static inline int stsch_err(struct subchannel_id schid, 39static inline int stsch_err(struct subchannel_id schid,
42 volatile struct schib *addr) 40 volatile struct schib *addr)
43{ 41{
44 int ccode; 42 register struct subchannel_id reg1 asm ("1") = schid;
43 int ccode = -EIO;
45 44
46 __asm__ __volatile__( 45 asm volatile(
47 " lhi %0,%3\n" 46 " stsch 0(%2)\n"
48 " lr 1,%1\n" 47 "0: ipm %0\n"
49 " stsch 0(%2)\n" 48 " srl %0,28\n"
50 "0: ipm %0\n"
51 " srl %0,28\n"
52 "1:\n" 49 "1:\n"
53#ifdef CONFIG_64BIT 50 EX_TABLE(0b,1b)
54 ".section __ex_table,\"a\"\n" 51 : "+d" (ccode) : "d" (reg1), "a" (addr), "m" (*addr) : "cc");
55 " .align 8\n"
56 " .quad 0b,1b\n"
57 ".previous"
58#else
59 ".section __ex_table,\"a\"\n"
60 " .align 4\n"
61 " .long 0b,1b\n"
62 ".previous"
63#endif
64 : "=&d" (ccode)
65 : "d" (schid), "a" (addr), "K" (-EIO), "m" (*addr)
66 : "cc", "1" );
67 return ccode; 52 return ccode;
68} 53}
69 54
70static inline int msch(struct subchannel_id schid, 55static inline int msch(struct subchannel_id schid,
71 volatile struct schib *addr) 56 volatile struct schib *addr)
72{ 57{
58 register struct subchannel_id reg1 asm ("1") = schid;
73 int ccode; 59 int ccode;
74 60
75 __asm__ __volatile__( 61 asm volatile(
76 " lr 1,%1\n" 62 " msch 0(%2)\n"
77 " msch 0(%2)\n" 63 " ipm %0\n"
78 " ipm %0\n" 64 " srl %0,28"
79 " srl %0,28" 65 : "=d" (ccode) : "d" (reg1), "a" (addr), "m" (*addr) : "cc");
80 : "=d" (ccode)
81 : "d" (schid), "a" (addr), "m" (*addr)
82 : "cc", "1" );
83 return ccode; 66 return ccode;
84} 67}
85 68
86static inline int msch_err(struct subchannel_id schid, 69static inline int msch_err(struct subchannel_id schid,
87 volatile struct schib *addr) 70 volatile struct schib *addr)
88{ 71{
89 int ccode; 72 register struct subchannel_id reg1 asm ("1") = schid;
73 int ccode = -EIO;
90 74
91 __asm__ __volatile__( 75 asm volatile(
92 " lhi %0,%3\n" 76 " msch 0(%2)\n"
93 " lr 1,%1\n" 77 "0: ipm %0\n"
94 " msch 0(%2)\n" 78 " srl %0,28\n"
95 "0: ipm %0\n"
96 " srl %0,28\n"
97 "1:\n" 79 "1:\n"
98#ifdef CONFIG_64BIT 80 EX_TABLE(0b,1b)
99 ".section __ex_table,\"a\"\n" 81 : "+d" (ccode) : "d" (reg1), "a" (addr), "m" (*addr) : "cc");
100 " .align 8\n"
101 " .quad 0b,1b\n"
102 ".previous"
103#else
104 ".section __ex_table,\"a\"\n"
105 " .align 4\n"
106 " .long 0b,1b\n"
107 ".previous"
108#endif
109 : "=&d" (ccode)
110 : "d" (schid), "a" (addr), "K" (-EIO), "m" (*addr)
111 : "cc", "1" );
112 return ccode; 82 return ccode;
113} 83}
114 84
115static inline int tsch(struct subchannel_id schid, 85static inline int tsch(struct subchannel_id schid,
116 volatile struct irb *addr) 86 volatile struct irb *addr)
117{ 87{
88 register struct subchannel_id reg1 asm ("1") = schid;
118 int ccode; 89 int ccode;
119 90
120 __asm__ __volatile__( 91 asm volatile(
121 " lr 1,%1\n" 92 " tsch 0(%2)\n"
122 " tsch 0(%2)\n" 93 " ipm %0\n"
123 " ipm %0\n" 94 " srl %0,28"
124 " srl %0,28" 95 : "=d" (ccode) : "d" (reg1), "a" (addr), "m" (*addr) : "cc");
125 : "=d" (ccode)
126 : "d" (schid), "a" (addr), "m" (*addr)
127 : "cc", "1" );
128 return ccode; 96 return ccode;
129} 97}
130 98
@@ -132,89 +100,77 @@ static inline int tpi( volatile struct tpi_info *addr)
132{ 100{
133 int ccode; 101 int ccode;
134 102
135 __asm__ __volatile__( 103 asm volatile(
136 " tpi 0(%1)\n" 104 " tpi 0(%1)\n"
137 " ipm %0\n" 105 " ipm %0\n"
138 " srl %0,28" 106 " srl %0,28"
139 : "=d" (ccode) 107 : "=d" (ccode) : "a" (addr), "m" (*addr) : "cc");
140 : "a" (addr), "m" (*addr)
141 : "cc", "1" );
142 return ccode; 108 return ccode;
143} 109}
144 110
145static inline int ssch(struct subchannel_id schid, 111static inline int ssch(struct subchannel_id schid,
146 volatile struct orb *addr) 112 volatile struct orb *addr)
147{ 113{
114 register struct subchannel_id reg1 asm ("1") = schid;
148 int ccode; 115 int ccode;
149 116
150 __asm__ __volatile__( 117 asm volatile(
151 " lr 1,%1\n" 118 " ssch 0(%2)\n"
152 " ssch 0(%2)\n" 119 " ipm %0\n"
153 " ipm %0\n" 120 " srl %0,28"
154 " srl %0,28" 121 : "=d" (ccode) : "d" (reg1), "a" (addr), "m" (*addr) : "cc");
155 : "=d" (ccode)
156 : "d" (schid), "a" (addr), "m" (*addr)
157 : "cc", "1" );
158 return ccode; 122 return ccode;
159} 123}
160 124
161static inline int rsch(struct subchannel_id schid) 125static inline int rsch(struct subchannel_id schid)
162{ 126{
127 register struct subchannel_id reg1 asm ("1") = schid;
163 int ccode; 128 int ccode;
164 129
165 __asm__ __volatile__( 130 asm volatile(
166 " lr 1,%1\n" 131 " rsch\n"
167 " rsch\n" 132 " ipm %0\n"
168 " ipm %0\n" 133 " srl %0,28"
169 " srl %0,28" 134 : "=d" (ccode) : "d" (reg1) : "cc");
170 : "=d" (ccode)
171 : "d" (schid)
172 : "cc", "1" );
173 return ccode; 135 return ccode;
174} 136}
175 137
176static inline int csch(struct subchannel_id schid) 138static inline int csch(struct subchannel_id schid)
177{ 139{
140 register struct subchannel_id reg1 asm ("1") = schid;
178 int ccode; 141 int ccode;
179 142
180 __asm__ __volatile__( 143 asm volatile(
181 " lr 1,%1\n" 144 " csch\n"
182 " csch\n" 145 " ipm %0\n"
183 " ipm %0\n" 146 " srl %0,28"
184 " srl %0,28" 147 : "=d" (ccode) : "d" (reg1) : "cc");
185 : "=d" (ccode)
186 : "d" (schid)
187 : "cc", "1" );
188 return ccode; 148 return ccode;
189} 149}
190 150
191static inline int hsch(struct subchannel_id schid) 151static inline int hsch(struct subchannel_id schid)
192{ 152{
153 register struct subchannel_id reg1 asm ("1") = schid;
193 int ccode; 154 int ccode;
194 155
195 __asm__ __volatile__( 156 asm volatile(
196 " lr 1,%1\n" 157 " hsch\n"
197 " hsch\n" 158 " ipm %0\n"
198 " ipm %0\n" 159 " srl %0,28"
199 " srl %0,28" 160 : "=d" (ccode) : "d" (reg1) : "cc");
200 : "=d" (ccode)
201 : "d" (schid)
202 : "cc", "1" );
203 return ccode; 161 return ccode;
204} 162}
205 163
206static inline int xsch(struct subchannel_id schid) 164static inline int xsch(struct subchannel_id schid)
207{ 165{
166 register struct subchannel_id reg1 asm ("1") = schid;
208 int ccode; 167 int ccode;
209 168
210 __asm__ __volatile__( 169 asm volatile(
211 " lr 1,%1\n" 170 " .insn rre,0xb2760000,%1,0\n"
212 " .insn rre,0xb2760000,%1,0\n" 171 " ipm %0\n"
213 " ipm %0\n" 172 " srl %0,28"
214 " srl %0,28" 173 : "=d" (ccode) : "d" (reg1) : "cc");
215 : "=d" (ccode)
216 : "d" (schid)
217 : "cc", "1" );
218 return ccode; 174 return ccode;
219} 175}
220 176
@@ -223,41 +179,27 @@ static inline int chsc(void *chsc_area)
223 typedef struct { char _[4096]; } addr_type; 179 typedef struct { char _[4096]; } addr_type;
224 int cc; 180 int cc;
225 181
226 __asm__ __volatile__ ( 182 asm volatile(
227 ".insn rre,0xb25f0000,%2,0 \n\t" 183 " .insn rre,0xb25f0000,%2,0\n"
228 "ipm %0 \n\t" 184 " ipm %0\n"
229 "srl %0,28 \n\t" 185 " srl %0,28\n"
230 : "=d" (cc), "=m" (*(addr_type *) chsc_area) 186 : "=d" (cc), "=m" (*(addr_type *) chsc_area)
231 : "d" (chsc_area), "m" (*(addr_type *) chsc_area) 187 : "d" (chsc_area), "m" (*(addr_type *) chsc_area)
232 : "cc" ); 188 : "cc");
233
234 return cc; 189 return cc;
235} 190}
236 191
237static inline int iac( void)
238{
239 int ccode;
240
241 __asm__ __volatile__(
242 " iac 1\n"
243 " ipm %0\n"
244 " srl %0,28"
245 : "=d" (ccode) : : "cc", "1" );
246 return ccode;
247}
248
249static inline int rchp(int chpid) 192static inline int rchp(int chpid)
250{ 193{
194 register unsigned int reg1 asm ("1") = chpid;
251 int ccode; 195 int ccode;
252 196
253 __asm__ __volatile__( 197 asm volatile(
254 " lr 1,%1\n" 198 " lr 1,%1\n"
255 " rchp\n" 199 " rchp\n"
256 " ipm %0\n" 200 " ipm %0\n"
257 " srl %0,28" 201 " srl %0,28"
258 : "=d" (ccode) 202 : "=d" (ccode) : "d" (reg1) : "cc");
259 : "d" (chpid)
260 : "cc", "1" );
261 return ccode; 203 return ccode;
262} 204}
263 205
diff --git a/drivers/s390/cio/qdio.h b/drivers/s390/cio/qdio.h
index 124569362f02..49bb9e371c32 100644
--- a/drivers/s390/cio/qdio.h
+++ b/drivers/s390/cio/qdio.h
@@ -274,12 +274,11 @@ do_sqbs(unsigned long sch, unsigned char state, int queue,
274 register unsigned long _sch asm ("1") = sch; 274 register unsigned long _sch asm ("1") = sch;
275 unsigned long _queuestart = ((unsigned long)queue << 32) | *start; 275 unsigned long _queuestart = ((unsigned long)queue << 32) | *start;
276 276
277 asm volatile ( 277 asm volatile(
278 " .insn rsy,0xeb000000008A,%1,0,0(%2)\n\t" 278 " .insn rsy,0xeb000000008A,%1,0,0(%2)"
279 : "+d" (_ccq), "+d" (_queuestart) 279 : "+d" (_ccq), "+d" (_queuestart)
280 : "d" ((unsigned long)state), "d" (_sch) 280 : "d" ((unsigned long)state), "d" (_sch)
281 : "memory", "cc" 281 : "memory", "cc");
282 );
283 *count = _ccq & 0xff; 282 *count = _ccq & 0xff;
284 *start = _queuestart & 0xff; 283 *start = _queuestart & 0xff;
285 284
@@ -299,12 +298,11 @@ do_eqbs(unsigned long sch, unsigned char *state, int queue,
299 unsigned long _queuestart = ((unsigned long)queue << 32) | *start; 298 unsigned long _queuestart = ((unsigned long)queue << 32) | *start;
300 unsigned long _state = 0; 299 unsigned long _state = 0;
301 300
302 asm volatile ( 301 asm volatile(
303 " .insn rrf,0xB99c0000,%1,%2,0,0 \n\t" 302 " .insn rrf,0xB99c0000,%1,%2,0,0"
304 : "+d" (_ccq), "+d" (_queuestart), "+d" (_state) 303 : "+d" (_ccq), "+d" (_queuestart), "+d" (_state)
305 : "d" (_sch) 304 : "d" (_sch)
306 : "memory", "cc" 305 : "memory", "cc" );
307 );
308 *count = _ccq & 0xff; 306 *count = _ccq & 0xff;
309 *start = _queuestart & 0xff; 307 *start = _queuestart & 0xff;
310 *state = _state & 0xff; 308 *state = _state & 0xff;
@@ -319,69 +317,35 @@ do_eqbs(unsigned long sch, unsigned char *state, int queue,
319static inline int 317static inline int
320do_siga_sync(struct subchannel_id schid, unsigned int mask1, unsigned int mask2) 318do_siga_sync(struct subchannel_id schid, unsigned int mask1, unsigned int mask2)
321{ 319{
320 register unsigned long reg0 asm ("0") = 2;
321 register struct subchannel_id reg1 asm ("1") = schid;
322 register unsigned long reg2 asm ("2") = mask1;
323 register unsigned long reg3 asm ("3") = mask2;
322 int cc; 324 int cc;
323 325
324#ifndef CONFIG_64BIT 326 asm volatile(
325 asm volatile ( 327 " siga 0\n"
326 "lhi 0,2 \n\t" 328 " ipm %0\n"
327 "lr 1,%1 \n\t" 329 " srl %0,28\n"
328 "lr 2,%2 \n\t"
329 "lr 3,%3 \n\t"
330 "siga 0 \n\t"
331 "ipm %0 \n\t"
332 "srl %0,28 \n\t"
333 : "=d" (cc) 330 : "=d" (cc)
334 : "d" (schid), "d" (mask1), "d" (mask2) 331 : "d" (reg0), "d" (reg1), "d" (reg2), "d" (reg3) : "cc");
335 : "cc", "0", "1", "2", "3"
336 );
337#else /* CONFIG_64BIT */
338 asm volatile (
339 "lghi 0,2 \n\t"
340 "llgfr 1,%1 \n\t"
341 "llgfr 2,%2 \n\t"
342 "llgfr 3,%3 \n\t"
343 "siga 0 \n\t"
344 "ipm %0 \n\t"
345 "srl %0,28 \n\t"
346 : "=d" (cc)
347 : "d" (schid), "d" (mask1), "d" (mask2)
348 : "cc", "0", "1", "2", "3"
349 );
350#endif /* CONFIG_64BIT */
351 return cc; 332 return cc;
352} 333}
353 334
354static inline int 335static inline int
355do_siga_input(struct subchannel_id schid, unsigned int mask) 336do_siga_input(struct subchannel_id schid, unsigned int mask)
356{ 337{
338 register unsigned long reg0 asm ("0") = 1;
339 register struct subchannel_id reg1 asm ("1") = schid;
340 register unsigned long reg2 asm ("2") = mask;
357 int cc; 341 int cc;
358 342
359#ifndef CONFIG_64BIT 343 asm volatile(
360 asm volatile ( 344 " siga 0\n"
361 "lhi 0,1 \n\t" 345 " ipm %0\n"
362 "lr 1,%1 \n\t" 346 " srl %0,28\n"
363 "lr 2,%2 \n\t"
364 "siga 0 \n\t"
365 "ipm %0 \n\t"
366 "srl %0,28 \n\t"
367 : "=d" (cc)
368 : "d" (schid), "d" (mask)
369 : "cc", "0", "1", "2", "memory"
370 );
371#else /* CONFIG_64BIT */
372 asm volatile (
373 "lghi 0,1 \n\t"
374 "llgfr 1,%1 \n\t"
375 "llgfr 2,%2 \n\t"
376 "siga 0 \n\t"
377 "ipm %0 \n\t"
378 "srl %0,28 \n\t"
379 : "=d" (cc) 347 : "=d" (cc)
380 : "d" (schid), "d" (mask) 348 : "d" (reg0), "d" (reg1), "d" (reg2) : "cc", "memory");
381 : "cc", "0", "1", "2", "memory"
382 );
383#endif /* CONFIG_64BIT */
384
385 return cc; 349 return cc;
386} 350}
387 351
@@ -389,93 +353,35 @@ static inline int
389do_siga_output(unsigned long schid, unsigned long mask, __u32 *bb, 353do_siga_output(unsigned long schid, unsigned long mask, __u32 *bb,
390 unsigned int fc) 354 unsigned int fc)
391{ 355{
356 register unsigned long __fc asm("0") = fc;
357 register unsigned long __schid asm("1") = schid;
358 register unsigned long __mask asm("2") = mask;
392 int cc; 359 int cc;
393 __u32 busy_bit; 360
394 361 asm volatile(
395#ifndef CONFIG_64BIT 362 " siga 0\n"
396 asm volatile ( 363 "0: ipm %0\n"
397 "lhi 0,0 \n\t" 364 " srl %0,28\n"
398 "lr 1,%2 \n\t" 365 "1:\n"
399 "lr 2,%3 \n\t" 366 EX_TABLE(0b,1b)
400 "siga 0 \n\t" 367 : "=d" (cc), "+d" (__fc), "+d" (__schid), "+d" (__mask)
401 "0:" 368 : "0" (QDIO_SIGA_ERROR_ACCESS_EXCEPTION)
402 "ipm %0 \n\t" 369 : "cc", "memory");
403 "srl %0,28 \n\t" 370 (*bb) = ((unsigned int) __fc) >> 31;
404 "srl 0,31 \n\t"
405 "lr %1,0 \n\t"
406 "1: \n\t"
407 ".section .fixup,\"ax\"\n\t"
408 "2: \n\t"
409 "lhi %0,%4 \n\t"
410 "bras 1,3f \n\t"
411 ".long 1b \n\t"
412 "3: \n\t"
413 "l 1,0(1) \n\t"
414 "br 1 \n\t"
415 ".previous \n\t"
416 ".section __ex_table,\"a\"\n\t"
417 ".align 4 \n\t"
418 ".long 0b,2b \n\t"
419 ".previous \n\t"
420 : "=d" (cc), "=d" (busy_bit)
421 : "d" (schid), "d" (mask),
422 "i" (QDIO_SIGA_ERROR_ACCESS_EXCEPTION)
423 : "cc", "0", "1", "2", "memory"
424 );
425#else /* CONFIG_64BIT */
426 asm volatile (
427 "llgfr 0,%5 \n\t"
428 "lgr 1,%2 \n\t"
429 "llgfr 2,%3 \n\t"
430 "siga 0 \n\t"
431 "0:"
432 "ipm %0 \n\t"
433 "srl %0,28 \n\t"
434 "srl 0,31 \n\t"
435 "llgfr %1,0 \n\t"
436 "1: \n\t"
437 ".section .fixup,\"ax\"\n\t"
438 "lghi %0,%4 \n\t"
439 "jg 1b \n\t"
440 ".previous\n\t"
441 ".section __ex_table,\"a\"\n\t"
442 ".align 8 \n\t"
443 ".quad 0b,1b \n\t"
444 ".previous \n\t"
445 : "=d" (cc), "=d" (busy_bit)
446 : "d" (schid), "d" (mask),
447 "i" (QDIO_SIGA_ERROR_ACCESS_EXCEPTION), "d" (fc)
448 : "cc", "0", "1", "2", "memory"
449 );
450#endif /* CONFIG_64BIT */
451
452 (*bb) = busy_bit;
453 return cc; 371 return cc;
454} 372}
455 373
456static inline unsigned long 374static inline unsigned long
457do_clear_global_summary(void) 375do_clear_global_summary(void)
458{ 376{
459 377 register unsigned long __fn asm("1") = 3;
460 unsigned long time; 378 register unsigned long __tmp asm("2");
461 379 register unsigned long __time asm("3");
462#ifndef CONFIG_64BIT 380
463 asm volatile ( 381 asm volatile(
464 "lhi 1,3 \n\t" 382 " .insn rre,0xb2650000,2,0"
465 ".insn rre,0xb2650000,2,0 \n\t" 383 : "+d" (__fn), "=d" (__tmp), "=d" (__time));
466 "lr %0,3 \n\t" 384 return __time;
467 : "=d" (time) : : "cc", "1", "2", "3"
468 );
469#else /* CONFIG_64BIT */
470 asm volatile (
471 "lghi 1,3 \n\t"
472 ".insn rre,0xb2650000,2,0 \n\t"
473 "lgr %0,3 \n\t"
474 : "=d" (time) : : "cc", "1", "2", "3"
475 );
476#endif /* CONFIG_64BIT */
477
478 return time;
479} 385}
480 386
481/* 387/*
diff --git a/drivers/s390/net/iucv.c b/drivers/s390/net/iucv.c
index 821dde86e240..809dd8d7f47a 100644
--- a/drivers/s390/net/iucv.c
+++ b/drivers/s390/net/iucv.c
@@ -534,19 +534,15 @@ iucv_add_handler (handler *new)
534 * 534 *
535 * Returns: return code from CP's IUCV call 535 * Returns: return code from CP's IUCV call
536 */ 536 */
537static __inline__ ulong 537static inline ulong b2f0(__u32 code, void *parm)
538b2f0(__u32 code, void *parm)
539{ 538{
539 register unsigned long reg0 asm ("0");
540 register unsigned long reg1 asm ("1");
540 iucv_dumpit("iparml before b2f0 call:", parm, sizeof(iucv_param)); 541 iucv_dumpit("iparml before b2f0 call:", parm, sizeof(iucv_param));
541 542
542 asm volatile ( 543 reg0 = code;
543 "LRA 1,0(%1)\n\t" 544 reg1 = virt_to_phys(parm);
544 "LR 0,%0\n\t" 545 asm volatile(".long 0xb2f01000" : : "d" (reg0), "a" (reg1));
545 ".long 0xb2f01000"
546 :
547 : "d" (code), "a" (parm)
548 : "0", "1"
549 );
550 546
551 iucv_dumpit("iparml after b2f0 call:", parm, sizeof(iucv_param)); 547 iucv_dumpit("iparml after b2f0 call:", parm, sizeof(iucv_param));
552 548
@@ -1248,6 +1244,8 @@ iucv_purge (__u16 pathid, __u32 msgid, __u32 srccls, __u32 *audit)
1248static int 1244static int
1249iucv_query_generic(int want_maxconn) 1245iucv_query_generic(int want_maxconn)
1250{ 1246{
1247 register unsigned long reg0 asm ("0");
1248 register unsigned long reg1 asm ("1");
1251 iparml_purge *parm = (iparml_purge *)grab_param(); 1249 iparml_purge *parm = (iparml_purge *)grab_param();
1252 int bufsize, maxconn; 1250 int bufsize, maxconn;
1253 int ccode; 1251 int ccode;
@@ -1256,18 +1254,15 @@ iucv_query_generic(int want_maxconn)
1256 * Call b2f0 and store R0 (max buffer size), 1254 * Call b2f0 and store R0 (max buffer size),
1257 * R1 (max connections) and CC. 1255 * R1 (max connections) and CC.
1258 */ 1256 */
1259 asm volatile ( 1257 reg0 = QUERY;
1260 "LRA 1,0(%4)\n\t" 1258 reg1 = virt_to_phys(parm);
1261 "LR 0,%3\n\t" 1259 asm volatile(
1262 ".long 0xb2f01000\n\t" 1260 " .long 0xb2f01000\n"
1263 "IPM %0\n\t" 1261 " ipm %0\n"
1264 "SRL %0,28\n\t" 1262 " srl %0,28\n"
1265 "ST 0,%1\n\t" 1263 : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc");
1266 "ST 1,%2\n\t" 1264 bufsize = reg0;
1267 : "=d" (ccode), "=m" (bufsize), "=m" (maxconn) 1265 maxconn = reg1;
1268 : "d" (QUERY), "a" (parm)
1269 : "0", "1", "cc"
1270 );
1271 release_param(parm); 1266 release_param(parm);
1272 1267
1273 if (ccode) 1268 if (ccode)
diff --git a/drivers/s390/net/qeth_main.c b/drivers/s390/net/qeth_main.c
index 5613b4564fa2..8364d5475ac7 100644
--- a/drivers/s390/net/qeth_main.c
+++ b/drivers/s390/net/qeth_main.c
@@ -8067,7 +8067,7 @@ qeth_arp_constructor(struct neighbour *neigh)
8067 neigh->parms = neigh_parms_clone(parms); 8067 neigh->parms = neigh_parms_clone(parms);
8068 rcu_read_unlock(); 8068 rcu_read_unlock();
8069 8069
8070 neigh->type = inet_addr_type(*(u32 *) neigh->primary_key); 8070 neigh->type = inet_addr_type(*(__be32 *) neigh->primary_key);
8071 neigh->nud_state = NUD_NOARP; 8071 neigh->nud_state = NUD_NOARP;
8072 neigh->ops = arp_direct_ops; 8072 neigh->ops = arp_direct_ops;
8073 neigh->output = neigh->ops->queue_xmit; 8073 neigh->output = neigh->ops->queue_xmit;
diff --git a/drivers/s390/s390mach.c b/drivers/s390/s390mach.c
index a914129a4da9..e088b5e28711 100644
--- a/drivers/s390/s390mach.c
+++ b/drivers/s390/s390mach.c
@@ -208,7 +208,7 @@ s390_handle_mcck(void)
208 */ 208 */
209 __ctl_clear_bit(14, 24); /* Disable WARNING MCH */ 209 __ctl_clear_bit(14, 24); /* Disable WARNING MCH */
210 if (xchg(&mchchk_wng_posted, 1) == 0) 210 if (xchg(&mchchk_wng_posted, 1) == 0)
211 kill_proc(1, SIGPWR, 1); 211 kill_cad_pid(SIGPWR, 1);
212 } 212 }
213#endif 213#endif
214 214
@@ -253,11 +253,12 @@ s390_revalidate_registers(struct mci *mci)
253 kill_task = 1; 253 kill_task = 1;
254 254
255#ifndef CONFIG_64BIT 255#ifndef CONFIG_64BIT
256 asm volatile("ld 0,0(%0)\n" 256 asm volatile(
257 "ld 2,8(%0)\n" 257 " ld 0,0(%0)\n"
258 "ld 4,16(%0)\n" 258 " ld 2,8(%0)\n"
259 "ld 6,24(%0)" 259 " ld 4,16(%0)\n"
260 : : "a" (&S390_lowcore.floating_pt_save_area)); 260 " ld 6,24(%0)"
261 : : "a" (&S390_lowcore.floating_pt_save_area));
261#endif 262#endif
262 263
263 if (MACHINE_HAS_IEEE) { 264 if (MACHINE_HAS_IEEE) {
@@ -274,37 +275,36 @@ s390_revalidate_registers(struct mci *mci)
274 * Floating point control register can't be restored. 275 * Floating point control register can't be restored.
275 * Task will be terminated. 276 * Task will be terminated.
276 */ 277 */
277 asm volatile ("lfpc 0(%0)" : : "a" (&zero), "m" (zero)); 278 asm volatile("lfpc 0(%0)" : : "a" (&zero), "m" (zero));
278 kill_task = 1; 279 kill_task = 1;
279 280
280 } 281 } else
281 else 282 asm volatile("lfpc 0(%0)" : : "a" (fpt_creg_save_area));
282 asm volatile ( 283
283 "lfpc 0(%0)" 284 asm volatile(
284 : : "a" (fpt_creg_save_area)); 285 " ld 0,0(%0)\n"
285 286 " ld 1,8(%0)\n"
286 asm volatile("ld 0,0(%0)\n" 287 " ld 2,16(%0)\n"
287 "ld 1,8(%0)\n" 288 " ld 3,24(%0)\n"
288 "ld 2,16(%0)\n" 289 " ld 4,32(%0)\n"
289 "ld 3,24(%0)\n" 290 " ld 5,40(%0)\n"
290 "ld 4,32(%0)\n" 291 " ld 6,48(%0)\n"
291 "ld 5,40(%0)\n" 292 " ld 7,56(%0)\n"
292 "ld 6,48(%0)\n" 293 " ld 8,64(%0)\n"
293 "ld 7,56(%0)\n" 294 " ld 9,72(%0)\n"
294 "ld 8,64(%0)\n" 295 " ld 10,80(%0)\n"
295 "ld 9,72(%0)\n" 296 " ld 11,88(%0)\n"
296 "ld 10,80(%0)\n" 297 " ld 12,96(%0)\n"
297 "ld 11,88(%0)\n" 298 " ld 13,104(%0)\n"
298 "ld 12,96(%0)\n" 299 " ld 14,112(%0)\n"
299 "ld 13,104(%0)\n" 300 " ld 15,120(%0)\n"
300 "ld 14,112(%0)\n" 301 : : "a" (fpt_save_area));
301 "ld 15,120(%0)\n"
302 : : "a" (fpt_save_area));
303 } 302 }
304 303
305 /* Revalidate access registers */ 304 /* Revalidate access registers */
306 asm volatile("lam 0,15,0(%0)" 305 asm volatile(
307 : : "a" (&S390_lowcore.access_regs_save_area)); 306 " lam 0,15,0(%0)"
307 : : "a" (&S390_lowcore.access_regs_save_area));
308 if (!mci->ar) 308 if (!mci->ar)
309 /* 309 /*
310 * Access registers have unknown contents. 310 * Access registers have unknown contents.
@@ -321,11 +321,13 @@ s390_revalidate_registers(struct mci *mci)
321 s390_handle_damage("invalid control registers."); 321 s390_handle_damage("invalid control registers.");
322 else 322 else
323#ifdef CONFIG_64BIT 323#ifdef CONFIG_64BIT
324 asm volatile("lctlg 0,15,0(%0)" 324 asm volatile(
325 : : "a" (&S390_lowcore.cregs_save_area)); 325 " lctlg 0,15,0(%0)"
326 : : "a" (&S390_lowcore.cregs_save_area));
326#else 327#else
327 asm volatile("lctl 0,15,0(%0)" 328 asm volatile(
328 : : "a" (&S390_lowcore.cregs_save_area)); 329 " lctl 0,15,0(%0)"
330 : : "a" (&S390_lowcore.cregs_save_area));
329#endif 331#endif
330 332
331 /* 333 /*
@@ -339,20 +341,23 @@ s390_revalidate_registers(struct mci *mci)
339 * old contents (should be zero) otherwise set it to zero. 341 * old contents (should be zero) otherwise set it to zero.
340 */ 342 */
341 if (!mci->pr) 343 if (!mci->pr)
342 asm volatile("sr 0,0\n" 344 asm volatile(
343 "sckpf" 345 " sr 0,0\n"
344 : : : "0", "cc"); 346 " sckpf"
347 : : : "0", "cc");
345 else 348 else
346 asm volatile( 349 asm volatile(
347 "l 0,0(%0)\n" 350 " l 0,0(%0)\n"
348 "sckpf" 351 " sckpf"
349 : : "a" (&S390_lowcore.tod_progreg_save_area) : "0", "cc"); 352 : : "a" (&S390_lowcore.tod_progreg_save_area)
353 : "0", "cc");
350#endif 354#endif
351 355
352 /* Revalidate clock comparator register */ 356 /* Revalidate clock comparator register */
353 asm volatile ("stck 0(%1)\n" 357 asm volatile(
354 "sckc 0(%1)" 358 " stck 0(%1)\n"
355 : "=m" (tmpclock) : "a" (&(tmpclock)) : "cc", "memory"); 359 " sckc 0(%1)"
360 : "=m" (tmpclock) : "a" (&(tmpclock)) : "cc", "memory");
356 361
357 /* Check if old PSW is valid */ 362 /* Check if old PSW is valid */
358 if (!mci->wp) 363 if (!mci->wp)
diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
index 7cafa34e4c7f..4d2bc7981324 100644
--- a/drivers/s390/scsi/zfcp_scsi.c
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -301,7 +301,7 @@ zfcp_scsi_command_sync(struct zfcp_unit *unit, struct scsi_cmnd *scpnt,
301 int use_timer) 301 int use_timer)
302{ 302{
303 int ret; 303 int ret;
304 DECLARE_COMPLETION(wait); 304 DECLARE_COMPLETION_ONSTACK(wait);
305 305
306 scpnt->SCp.ptr = (void *) &wait; /* silent re-use */ 306 scpnt->SCp.ptr = (void *) &wait; /* silent re-use */
307 scpnt->scsi_done = zfcp_scsi_command_sync_handler; 307 scpnt->scsi_done = zfcp_scsi_command_sync_handler;
diff --git a/drivers/sbus/char/aurora.c b/drivers/sbus/char/aurora.c
index 4fdb2c932210..a305d4091547 100644
--- a/drivers/sbus/char/aurora.c
+++ b/drivers/sbus/char/aurora.c
@@ -2187,7 +2187,7 @@ static void do_softint(void *private_)
2187#endif 2187#endif
2188} 2188}
2189 2189
2190static struct tty_operations aurora_ops = { 2190static const struct tty_operations aurora_ops = {
2191 .open = aurora_open, 2191 .open = aurora_open,
2192 .close = aurora_close, 2192 .close = aurora_close,
2193 .write = aurora_write, 2193 .write = aurora_write,
diff --git a/drivers/sbus/char/bbc_envctrl.c b/drivers/sbus/char/bbc_envctrl.c
index 1cc706e11119..d27e4f6d7045 100644
--- a/drivers/sbus/char/bbc_envctrl.c
+++ b/drivers/sbus/char/bbc_envctrl.c
@@ -4,9 +4,6 @@
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__
8static int errno;
9
10#include <linux/kernel.h> 7#include <linux/kernel.h>
11#include <linux/kthread.h> 8#include <linux/kthread.h>
12#include <linux/sched.h> 9#include <linux/sched.h>
@@ -200,7 +197,7 @@ static void do_envctrl_shutdown(struct bbc_cpu_temperature *tp)
200 printk(KERN_CRIT "kenvctrld: Shutting down the system now.\n"); 197 printk(KERN_CRIT "kenvctrld: Shutting down the system now.\n");
201 198
202 shutting_down = 1; 199 shutting_down = 1;
203 if (execve("/sbin/shutdown", argv, envp) < 0) 200 if (kernel_execve("/sbin/shutdown", argv, envp) < 0)
204 printk(KERN_CRIT "envctrl: shutdown execution failed\n"); 201 printk(KERN_CRIT "envctrl: shutdown execution failed\n");
205} 202}
206 203
diff --git a/drivers/sbus/char/envctrl.c b/drivers/sbus/char/envctrl.c
index 063e676a3ac0..728a133d0fc5 100644
--- a/drivers/sbus/char/envctrl.c
+++ b/drivers/sbus/char/envctrl.c
@@ -19,9 +19,6 @@
19 * Daniele Bellucci <bellucda@tiscali.it> 19 * Daniele Bellucci <bellucda@tiscali.it>
20 */ 20 */
21 21
22#define __KERNEL_SYSCALLS__
23static int errno;
24
25#include <linux/module.h> 22#include <linux/module.h>
26#include <linux/sched.h> 23#include <linux/sched.h>
27#include <linux/kthread.h> 24#include <linux/kthread.h>
@@ -976,13 +973,15 @@ static void envctrl_do_shutdown(void)
976 "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL }; 973 "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
977 char *argv[] = { 974 char *argv[] = {
978 "/sbin/shutdown", "-h", "now", NULL }; 975 "/sbin/shutdown", "-h", "now", NULL };
976 int ret;
979 977
980 if (inprog != 0) 978 if (inprog != 0)
981 return; 979 return;
982 980
983 inprog = 1; 981 inprog = 1;
984 printk(KERN_CRIT "kenvctrld: WARNING: Shutting down the system now.\n"); 982 printk(KERN_CRIT "kenvctrld: WARNING: Shutting down the system now.\n");
985 if (0 > execve("/sbin/shutdown", argv, envp)) { 983 ret = kernel_execve("/sbin/shutdown", argv, envp);
984 if (ret < 0) {
986 printk(KERN_CRIT "kenvctrld: WARNING: system shutdown failed!\n"); 985 printk(KERN_CRIT "kenvctrld: WARNING: system shutdown failed!\n");
987 inprog = 0; /* unlikely to succeed, but we could try again */ 986 inprog = 0; /* unlikely to succeed, but we could try again */
988 } 987 }
diff --git a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c
index 657a3ab75399..15ce40a7053a 100644
--- a/drivers/scsi/53c700.c
+++ b/drivers/scsi/53c700.c
@@ -1939,7 +1939,7 @@ NCR_700_abort(struct scsi_cmnd * SCp)
1939STATIC int 1939STATIC int
1940NCR_700_bus_reset(struct scsi_cmnd * SCp) 1940NCR_700_bus_reset(struct scsi_cmnd * SCp)
1941{ 1941{
1942 DECLARE_COMPLETION(complete); 1942 DECLARE_COMPLETION_ONSTACK(complete);
1943 struct NCR_700_Host_Parameters *hostdata = 1943 struct NCR_700_Host_Parameters *hostdata =
1944 (struct NCR_700_Host_Parameters *)SCp->device->host->hostdata[0]; 1944 (struct NCR_700_Host_Parameters *)SCp->device->host->hostdata[0];
1945 1945
diff --git a/drivers/scsi/BusLogic.h b/drivers/scsi/BusLogic.h
index 9792e5af5252..d6d1d5613c8a 100644
--- a/drivers/scsi/BusLogic.h
+++ b/drivers/scsi/BusLogic.h
@@ -237,10 +237,7 @@ enum BusLogic_BIOS_DiskGeometryTranslation {
237 Define a Boolean data type. 237 Define a Boolean data type.
238*/ 238*/
239 239
240typedef enum { 240typedef bool boolean;
241 false,
242 true
243} PACKED boolean;
244 241
245/* 242/*
246 Define a 10^18 Statistics Byte Counter data type. 243 Define a 10^18 Statistics Byte Counter data type.
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index c4dfcc91ddda..dab082002e6f 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -3,11 +3,13 @@ menu "SCSI device support"
3config RAID_ATTRS 3config RAID_ATTRS
4 tristate "RAID Transport Class" 4 tristate "RAID Transport Class"
5 default n 5 default n
6 depends on BLOCK
6 ---help--- 7 ---help---
7 Provides RAID 8 Provides RAID
8 9
9config SCSI 10config SCSI
10 tristate "SCSI device support" 11 tristate "SCSI device support"
12 depends on BLOCK
11 ---help--- 13 ---help---
12 If you want to use a SCSI hard disk, SCSI tape drive, SCSI CD-ROM or 14 If you want to use a SCSI hard disk, SCSI tape drive, SCSI CD-ROM or
13 any other SCSI device under Linux, say Y and make sure that you know 15 any other SCSI device under Linux, say Y and make sure that you know
diff --git a/drivers/scsi/aha1740.c b/drivers/scsi/aha1740.c
index 0e4a7ebe300a..6b35ed8301e0 100644
--- a/drivers/scsi/aha1740.c
+++ b/drivers/scsi/aha1740.c
@@ -681,6 +681,7 @@ static struct eisa_device_id aha1740_ids[] = {
681 { "ADP0400" }, /* 1744 */ 681 { "ADP0400" }, /* 1744 */
682 { "" } 682 { "" }
683}; 683};
684MODULE_DEVICE_TABLE(eisa, aha1740_ids);
684 685
685static struct eisa_driver aha1740_driver = { 686static struct eisa_driver aha1740_driver = {
686 .id_table = aha1740_ids, 687 .id_table = aha1740_ids,
diff --git a/drivers/scsi/aic7xxx/aic7770_osm.c b/drivers/scsi/aic7xxx/aic7770_osm.c
index 867cbe23579b..1ac119733bac 100644
--- a/drivers/scsi/aic7xxx/aic7770_osm.c
+++ b/drivers/scsi/aic7xxx/aic7770_osm.c
@@ -132,7 +132,8 @@ static struct eisa_device_id aic7770_ids[] = {
132 { "ADP7770", 5 }, /* AIC7770 generic */ 132 { "ADP7770", 5 }, /* AIC7770 generic */
133 { "" } 133 { "" }
134}; 134};
135 135MODULE_DEVICE_TABLE(eisa, aic7770_ids);
136
136static struct eisa_driver aic7770_driver = { 137static struct eisa_driver aic7770_driver = {
137 .id_table = aic7770_ids, 138 .id_table = aic7770_ids,
138 .driver = { 139 .driver = {
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index c7eeaced324a..1faa008b5b81 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -646,7 +646,7 @@ ahd_linux_dev_reset(struct scsi_cmnd *cmd)
646 struct ahd_initiator_tinfo *tinfo; 646 struct ahd_initiator_tinfo *tinfo;
647 struct ahd_tmode_tstate *tstate; 647 struct ahd_tmode_tstate *tstate;
648 unsigned long flags; 648 unsigned long flags;
649 DECLARE_COMPLETION(done); 649 DECLARE_COMPLETION_ONSTACK(done);
650 650
651 reset_scb = NULL; 651 reset_scb = NULL;
652 paused = FALSE; 652 paused = FALSE;
@@ -2251,7 +2251,7 @@ done:
2251 if (paused) 2251 if (paused)
2252 ahd_unpause(ahd); 2252 ahd_unpause(ahd);
2253 if (wait) { 2253 if (wait) {
2254 DECLARE_COMPLETION(done); 2254 DECLARE_COMPLETION_ONSTACK(done);
2255 2255
2256 ahd->platform_data->eh_done = &done; 2256 ahd->platform_data->eh_done = &done;
2257 ahd_unlock(ahd, &flags); 2257 ahd_unlock(ahd, &flags);
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
index 64c8b88a429f..339b85cb61cd 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -2335,7 +2335,7 @@ done:
2335 if (paused) 2335 if (paused)
2336 ahc_unpause(ahc); 2336 ahc_unpause(ahc);
2337 if (wait) { 2337 if (wait) {
2338 DECLARE_COMPLETION(done); 2338 DECLARE_COMPLETION_ONSTACK(done);
2339 2339
2340 ahc->platform_data->eh_done = &done; 2340 ahc->platform_data->eh_done = &done;
2341 ahc_unlock(ahc, &flags); 2341 ahc_unlock(ahc, &flags);
diff --git a/drivers/scsi/aic7xxx_old.c b/drivers/scsi/aic7xxx_old.c
index 5dcef48d414f..10353379a074 100644
--- a/drivers/scsi/aic7xxx_old.c
+++ b/drivers/scsi/aic7xxx_old.c
@@ -2862,7 +2862,7 @@ aic7xxx_done(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
2862 aic_dev->r_total++; 2862 aic_dev->r_total++;
2863 ptr = aic_dev->r_bins; 2863 ptr = aic_dev->r_bins;
2864 } 2864 }
2865 if(cmd->device->simple_tags && cmd->request->flags & REQ_HARDBARRIER) 2865 if(cmd->device->simple_tags && cmd->request->cmd_flags & REQ_HARDBARRIER)
2866 { 2866 {
2867 aic_dev->barrier_total++; 2867 aic_dev->barrier_total++;
2868 if(scb->tag_action == MSG_ORDERED_Q_TAG) 2868 if(scb->tag_action == MSG_ORDERED_Q_TAG)
@@ -10158,7 +10158,7 @@ aic7xxx_buildscb(struct aic7xxx_host *p, Scsi_Cmnd *cmd,
10158 /* We always force TEST_UNIT_READY to untagged */ 10158 /* We always force TEST_UNIT_READY to untagged */
10159 if (cmd->cmnd[0] != TEST_UNIT_READY && sdptr->simple_tags) 10159 if (cmd->cmnd[0] != TEST_UNIT_READY && sdptr->simple_tags)
10160 { 10160 {
10161 if (req->flags & REQ_HARDBARRIER) 10161 if (req->cmd_flags & REQ_HARDBARRIER)
10162 { 10162 {
10163 if(sdptr->ordered_tags) 10163 if(sdptr->ordered_tags)
10164 { 10164 {
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 43afd476e606..0f3eb22b979a 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -724,7 +724,7 @@ int __gdth_execute(struct scsi_device *sdev, gdth_cmd_str *gdtcmd, char *cmnd,
724 int timeout, u32 *info) 724 int timeout, u32 *info)
725{ 725{
726 Scsi_Cmnd *scp; 726 Scsi_Cmnd *scp;
727 DECLARE_COMPLETION(wait); 727 DECLARE_COMPLETION_ONSTACK(wait);
728 int rval; 728 int rval;
729 729
730 scp = kmalloc(sizeof(*scp), GFP_KERNEL); 730 scp = kmalloc(sizeof(*scp), GFP_KERNEL);
@@ -764,7 +764,7 @@ int __gdth_execute(struct scsi_device *sdev, gdth_cmd_str *gdtcmd, char *cmnd,
764{ 764{
765 Scsi_Cmnd *scp = scsi_allocate_device(sdev, 1, FALSE); 765 Scsi_Cmnd *scp = scsi_allocate_device(sdev, 1, FALSE);
766 unsigned bufflen = gdtcmd ? sizeof(gdth_cmd_str) : 0; 766 unsigned bufflen = gdtcmd ? sizeof(gdth_cmd_str) : 0;
767 DECLARE_COMPLETION(wait); 767 DECLARE_COMPLETION_ONSTACK(wait);
768 int rval; 768 int rval;
769 769
770 if (!scp) 770 if (!scp)
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index 94d1de55607f..1427a41e8441 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -344,7 +344,7 @@ static int idescsi_check_condition(ide_drive_t *drive, struct request *failed_co
344 pc->buffer = buf; 344 pc->buffer = buf;
345 pc->c[0] = REQUEST_SENSE; 345 pc->c[0] = REQUEST_SENSE;
346 pc->c[4] = pc->request_transfer = pc->buffer_size = SCSI_SENSE_BUFFERSIZE; 346 pc->c[4] = pc->request_transfer = pc->buffer_size = SCSI_SENSE_BUFFERSIZE;
347 rq->flags = REQ_SENSE; 347 rq->cmd_type = REQ_TYPE_SENSE;
348 pc->timeout = jiffies + WAIT_READY; 348 pc->timeout = jiffies + WAIT_READY;
349 /* NOTE! Save the failed packet command in "rq->buffer" */ 349 /* NOTE! Save the failed packet command in "rq->buffer" */
350 rq->buffer = (void *) failed_command->special; 350 rq->buffer = (void *) failed_command->special;
@@ -398,12 +398,12 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
398 int errors = rq->errors; 398 int errors = rq->errors;
399 unsigned long flags; 399 unsigned long flags;
400 400
401 if (!(rq->flags & (REQ_SPECIAL|REQ_SENSE))) { 401 if (!blk_special_request(rq) && !blk_sense_request(rq)) {
402 ide_end_request(drive, uptodate, nrsecs); 402 ide_end_request(drive, uptodate, nrsecs);
403 return 0; 403 return 0;
404 } 404 }
405 ide_end_drive_cmd (drive, 0, 0); 405 ide_end_drive_cmd (drive, 0, 0);
406 if (rq->flags & REQ_SENSE) { 406 if (blk_sense_request(rq)) {
407 idescsi_pc_t *opc = (idescsi_pc_t *) rq->buffer; 407 idescsi_pc_t *opc = (idescsi_pc_t *) rq->buffer;
408 if (log) { 408 if (log) {
409 printk ("ide-scsi: %s: wrap up check %lu, rst = ", drive->name, opc->scsi_cmd->serial_number); 409 printk ("ide-scsi: %s: wrap up check %lu, rst = ", drive->name, opc->scsi_cmd->serial_number);
@@ -708,11 +708,11 @@ static ide_startstop_t idescsi_issue_pc (ide_drive_t *drive, idescsi_pc_t *pc)
708static ide_startstop_t idescsi_do_request (ide_drive_t *drive, struct request *rq, sector_t block) 708static ide_startstop_t idescsi_do_request (ide_drive_t *drive, struct request *rq, sector_t block)
709{ 709{
710#if IDESCSI_DEBUG_LOG 710#if IDESCSI_DEBUG_LOG
711 printk (KERN_INFO "rq_status: %d, dev: %s, cmd: %x, errors: %d\n",rq->rq_status, rq->rq_disk->disk_name,rq->cmd[0],rq->errors); 711 printk (KERN_INFO "dev: %s, cmd: %x, errors: %d\n", rq->rq_disk->disk_name,rq->cmd[0],rq->errors);
712 printk (KERN_INFO "sector: %ld, nr_sectors: %ld, current_nr_sectors: %d\n",rq->sector,rq->nr_sectors,rq->current_nr_sectors); 712 printk (KERN_INFO "sector: %ld, nr_sectors: %ld, current_nr_sectors: %d\n",rq->sector,rq->nr_sectors,rq->current_nr_sectors);
713#endif /* IDESCSI_DEBUG_LOG */ 713#endif /* IDESCSI_DEBUG_LOG */
714 714
715 if (rq->flags & (REQ_SPECIAL|REQ_SENSE)) { 715 if (blk_sense_request(rq) || blk_special_request(rq)) {
716 return idescsi_issue_pc (drive, (idescsi_pc_t *) rq->special); 716 return idescsi_issue_pc (drive, (idescsi_pc_t *) rq->special);
717 } 717 }
718 blk_dump_rq_flags(rq, "ide-scsi: unsup command"); 718 blk_dump_rq_flags(rq, "ide-scsi: unsup command");
@@ -938,7 +938,7 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
938 938
939 ide_init_drive_cmd (rq); 939 ide_init_drive_cmd (rq);
940 rq->special = (char *) pc; 940 rq->special = (char *) pc;
941 rq->flags = REQ_SPECIAL; 941 rq->cmd_type = REQ_TYPE_SPECIAL;
942 spin_unlock_irq(host->host_lock); 942 spin_unlock_irq(host->host_lock);
943 rq->rq_disk = scsi->disk; 943 rq->rq_disk = scsi->disk;
944 (void) ide_do_drive_cmd (drive, rq, ide_end); 944 (void) ide_do_drive_cmd (drive, rq, ide_end);
@@ -992,7 +992,7 @@ static int idescsi_eh_abort (struct scsi_cmnd *cmd)
992 */ 992 */
993 printk (KERN_ERR "ide-scsi: cmd aborted!\n"); 993 printk (KERN_ERR "ide-scsi: cmd aborted!\n");
994 994
995 if (scsi->pc->rq->flags & REQ_SENSE) 995 if (blk_sense_request(scsi->pc->rq))
996 kfree(scsi->pc->buffer); 996 kfree(scsi->pc->buffer);
997 kfree(scsi->pc->rq); 997 kfree(scsi->pc->rq);
998 kfree(scsi->pc); 998 kfree(scsi->pc);
@@ -1042,7 +1042,7 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
1042 /* kill current request */ 1042 /* kill current request */
1043 blkdev_dequeue_request(req); 1043 blkdev_dequeue_request(req);
1044 end_that_request_last(req, 0); 1044 end_that_request_last(req, 0);
1045 if (req->flags & REQ_SENSE) 1045 if (blk_sense_request(req))
1046 kfree(scsi->pc->buffer); 1046 kfree(scsi->pc->buffer);
1047 kfree(scsi->pc); 1047 kfree(scsi->pc);
1048 scsi->pc = NULL; 1048 scsi->pc = NULL;
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index 7f9e89bcac7e..e46e79355b77 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -126,7 +126,7 @@ static enum task_attribute sas_scsi_get_task_attr(struct scsi_cmnd *cmd)
126 enum task_attribute ta = TASK_ATTR_SIMPLE; 126 enum task_attribute ta = TASK_ATTR_SIMPLE;
127 if (cmd->request && blk_rq_tagged(cmd->request)) { 127 if (cmd->request && blk_rq_tagged(cmd->request)) {
128 if (cmd->device->ordered_tags && 128 if (cmd->device->ordered_tags &&
129 (cmd->request->flags & REQ_HARDBARRIER)) 129 (cmd->request->cmd_flags & REQ_HARDBARRIER))
130 ta = TASK_ATTR_HOQ; 130 ta = TASK_ATTR_HOQ;
131 } 131 }
132 return ta; 132 return ta;
diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
index ae4106458991..1b53afb1cb57 100644
--- a/drivers/scsi/lpfc/lpfc_ct.c
+++ b/drivers/scsi/lpfc/lpfc_ct.c
@@ -933,8 +933,8 @@ lpfc_fdmi_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
933 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size); 933 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
934 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION); 934 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
935 sprintf(ae->un.OsNameVersion, "%s %s %s", 935 sprintf(ae->un.OsNameVersion, "%s %s %s",
936 system_utsname.sysname, system_utsname.release, 936 init_utsname()->sysname, init_utsname()->release,
937 system_utsname.version); 937 init_utsname()->version);
938 len = strlen(ae->un.OsNameVersion); 938 len = strlen(ae->un.OsNameVersion);
939 len += (len & 3) ? (4 - (len & 3)) : 4; 939 len += (len & 3) ? (4 - (len & 3)) : 4;
940 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len); 940 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
@@ -1052,7 +1052,7 @@ lpfc_fdmi_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
1052 size); 1052 size);
1053 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME); 1053 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1054 sprintf(ae->un.HostName, "%s", 1054 sprintf(ae->un.HostName, "%s",
1055 system_utsname.nodename); 1055 init_utsname()->nodename);
1056 len = strlen(ae->un.HostName); 1056 len = strlen(ae->un.HostName);
1057 len += (len & 3) ? (4 - (len & 3)) : 4; 1057 len += (len & 3) ? (4 - (len & 3)) : 4;
1058 ae->ad.bits.AttrLen = 1058 ae->ad.bits.AttrLen =
@@ -1140,7 +1140,7 @@ lpfc_fdmi_tmo_handler(struct lpfc_hba *phba)
1140 1140
1141 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID); 1141 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
1142 if (ndlp) { 1142 if (ndlp) {
1143 if (system_utsname.nodename[0] != '\0') { 1143 if (init_utsname()->nodename[0] != '\0') {
1144 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA); 1144 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
1145 } else { 1145 } else {
1146 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60); 1146 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c
index 592b52afe658..683fc7ae4b8f 100644
--- a/drivers/scsi/mesh.c
+++ b/drivers/scsi/mesh.c
@@ -1756,16 +1756,23 @@ static void set_mesh_power(struct mesh_state *ms, int state)
1756 pmac_call_feature(PMAC_FTR_MESH_ENABLE, macio_get_of_node(ms->mdev), 0, 0); 1756 pmac_call_feature(PMAC_FTR_MESH_ENABLE, macio_get_of_node(ms->mdev), 0, 0);
1757 msleep(10); 1757 msleep(10);
1758 } 1758 }
1759} 1759}
1760 1760
1761 1761
1762#ifdef CONFIG_PM 1762#ifdef CONFIG_PM
1763static int mesh_suspend(struct macio_dev *mdev, pm_message_t state) 1763static int mesh_suspend(struct macio_dev *mdev, pm_message_t mesg)
1764{ 1764{
1765 struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev); 1765 struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev);
1766 unsigned long flags; 1766 unsigned long flags;
1767 1767
1768 if (state.event == mdev->ofdev.dev.power.power_state.event || state.event < 2) 1768 switch (mesg.event) {
1769 case PM_EVENT_SUSPEND:
1770 case PM_EVENT_FREEZE:
1771 break;
1772 default:
1773 return 0;
1774 }
1775 if (mesg.event == mdev->ofdev.dev.power.power_state.event)
1769 return 0; 1776 return 0;
1770 1777
1771 scsi_block_requests(ms->host); 1778 scsi_block_requests(ms->host);
@@ -1780,7 +1787,7 @@ static int mesh_suspend(struct macio_dev *mdev, pm_message_t state)
1780 disable_irq(ms->meshintr); 1787 disable_irq(ms->meshintr);
1781 set_mesh_power(ms, 0); 1788 set_mesh_power(ms, 0);
1782 1789
1783 mdev->ofdev.dev.power.power_state = state; 1790 mdev->ofdev.dev.power.power_state = mesg;
1784 1791
1785 return 0; 1792 return 0;
1786} 1793}
diff --git a/drivers/scsi/pluto.c b/drivers/scsi/pluto.c
index 0bd9c60e6455..aa60a5f1fbc3 100644
--- a/drivers/scsi/pluto.c
+++ b/drivers/scsi/pluto.c
@@ -67,7 +67,6 @@ static void __init pluto_detect_done(Scsi_Cmnd *SCpnt)
67 67
68static void __init pluto_detect_scsi_done(Scsi_Cmnd *SCpnt) 68static void __init pluto_detect_scsi_done(Scsi_Cmnd *SCpnt)
69{ 69{
70 SCpnt->request->rq_status = RQ_SCSI_DONE;
71 PLND(("Detect done %08lx\n", (long)SCpnt)) 70 PLND(("Detect done %08lx\n", (long)SCpnt))
72 if (atomic_dec_and_test (&fcss)) 71 if (atomic_dec_and_test (&fcss))
73 up(&fc_sem); 72 up(&fc_sem);
@@ -166,7 +165,7 @@ int __init pluto_detect(struct scsi_host_template *tpnt)
166 165
167 SCpnt->cmd_len = COMMAND_SIZE(INQUIRY); 166 SCpnt->cmd_len = COMMAND_SIZE(INQUIRY);
168 167
169 SCpnt->request->rq_status = RQ_SCSI_BUSY; 168 SCpnt->request->cmd_flags &= ~REQ_STARTED;
170 169
171 SCpnt->done = pluto_detect_done; 170 SCpnt->done = pluto_detect_done;
172 SCpnt->request_bufflen = 256; 171 SCpnt->request_bufflen = 256;
@@ -178,7 +177,8 @@ int __init pluto_detect(struct scsi_host_template *tpnt)
178 for (retry = 0; retry < 5; retry++) { 177 for (retry = 0; retry < 5; retry++) {
179 for (i = 0; i < fcscount; i++) { 178 for (i = 0; i < fcscount; i++) {
180 if (!fcs[i].fc) break; 179 if (!fcs[i].fc) break;
181 if (fcs[i].cmd.request->rq_status != RQ_SCSI_DONE) { 180 if (!(fcs[i].cmd.request->cmd_flags & REQ_STARTED)) {
181 fcs[i].cmd.request->cmd_flags |= REQ_STARTED;
182 disable_irq(fcs[i].fc->irq); 182 disable_irq(fcs[i].fc->irq);
183 PLND(("queuecommand %d %d\n", retry, i)) 183 PLND(("queuecommand %d %d\n", retry, i))
184 fcp_scsi_queuecommand (&(fcs[i].cmd), 184 fcp_scsi_queuecommand (&(fcs[i].cmd),
diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index 8953991462d7..332151e2a018 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -813,7 +813,7 @@ qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
813 uint16_t data; 813 uint16_t data;
814 unsigned char *handle; 814 unsigned char *handle;
815 int result, i; 815 int result, i;
816 DECLARE_COMPLETION(wait); 816 DECLARE_COMPLETION_ONSTACK(wait);
817 struct timer_list timer; 817 struct timer_list timer;
818 818
819 ha = (struct scsi_qla_host *)(CMD_HOST(cmd)->hostdata); 819 ha = (struct scsi_qla_host *)(CMD_HOST(cmd)->hostdata);
@@ -2406,7 +2406,7 @@ qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t *mb)
2406 uint16_t *optr, *iptr; 2406 uint16_t *optr, *iptr;
2407 uint16_t __iomem *mptr; 2407 uint16_t __iomem *mptr;
2408 uint16_t data; 2408 uint16_t data;
2409 DECLARE_COMPLETION(wait); 2409 DECLARE_COMPLETION_ONSTACK(wait);
2410 struct timer_list timer; 2410 struct timer_list timer;
2411 2411
2412 ENTER("qla1280_mailbox_command"); 2412 ENTER("qla1280_mailbox_command");
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 7a054f9d1ee3..da95bce907dd 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -592,12 +592,6 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
592 return rtn; 592 return rtn;
593} 593}
594 594
595
596/*
597 * Per-CPU I/O completion queue.
598 */
599static DEFINE_PER_CPU(struct list_head, scsi_done_q);
600
601/** 595/**
602 * scsi_req_abort_cmd -- Request command recovery for the specified command 596 * scsi_req_abort_cmd -- Request command recovery for the specified command
603 * cmd: pointer to the SCSI command of interest 597 * cmd: pointer to the SCSI command of interest
@@ -1065,7 +1059,7 @@ int scsi_device_cancel(struct scsi_device *sdev, int recovery)
1065 1059
1066 spin_lock_irqsave(&sdev->list_lock, flags); 1060 spin_lock_irqsave(&sdev->list_lock, flags);
1067 list_for_each_entry(scmd, &sdev->cmd_list, list) { 1061 list_for_each_entry(scmd, &sdev->cmd_list, list) {
1068 if (scmd->request && scmd->request->rq_status != RQ_INACTIVE) { 1062 if (scmd->request) {
1069 /* 1063 /*
1070 * If we are unable to remove the timer, it means 1064 * If we are unable to remove the timer, it means
1071 * that the command has already timed out or 1065 * that the command has already timed out or
@@ -1102,7 +1096,7 @@ MODULE_PARM_DESC(scsi_logging_level, "a bit mask of logging levels");
1102 1096
1103static int __init init_scsi(void) 1097static int __init init_scsi(void)
1104{ 1098{
1105 int error, i; 1099 int error;
1106 1100
1107 error = scsi_init_queue(); 1101 error = scsi_init_queue();
1108 if (error) 1102 if (error)
@@ -1123,9 +1117,6 @@ static int __init init_scsi(void)
1123 if (error) 1117 if (error)
1124 goto cleanup_sysctl; 1118 goto cleanup_sysctl;
1125 1119
1126 for_each_possible_cpu(i)
1127 INIT_LIST_HEAD(&per_cpu(scsi_done_q, i));
1128
1129 scsi_netlink_init(); 1120 scsi_netlink_init();
1130 1121
1131 printk(KERN_NOTICE "SCSI subsystem initialized\n"); 1122 printk(KERN_NOTICE "SCSI subsystem initialized\n");
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index d6743b959a72..71084728eb42 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -82,7 +82,7 @@ static void scsi_unprep_request(struct request *req)
82{ 82{
83 struct scsi_cmnd *cmd = req->special; 83 struct scsi_cmnd *cmd = req->special;
84 84
85 req->flags &= ~REQ_DONTPREP; 85 req->cmd_flags &= ~REQ_DONTPREP;
86 req->special = NULL; 86 req->special = NULL;
87 87
88 scsi_put_command(cmd); 88 scsi_put_command(cmd);
@@ -196,7 +196,8 @@ int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
196 req->sense_len = 0; 196 req->sense_len = 0;
197 req->retries = retries; 197 req->retries = retries;
198 req->timeout = timeout; 198 req->timeout = timeout;
199 req->flags |= flags | REQ_BLOCK_PC | REQ_SPECIAL | REQ_QUIET; 199 req->cmd_type = REQ_TYPE_BLOCK_PC;
200 req->cmd_flags |= flags | REQ_QUIET | REQ_PREEMPT;
200 201
201 /* 202 /*
202 * head injection *required* here otherwise quiesce won't work 203 * head injection *required* here otherwise quiesce won't work
@@ -397,7 +398,8 @@ int scsi_execute_async(struct scsi_device *sdev, const unsigned char *cmd,
397 req = blk_get_request(sdev->request_queue, write, gfp); 398 req = blk_get_request(sdev->request_queue, write, gfp);
398 if (!req) 399 if (!req)
399 goto free_sense; 400 goto free_sense;
400 req->flags |= REQ_BLOCK_PC | REQ_QUIET; 401 req->cmd_type = REQ_TYPE_BLOCK_PC;
402 req->cmd_flags |= REQ_QUIET;
401 403
402 if (use_sg) 404 if (use_sg)
403 err = scsi_req_map_sg(req, buffer, use_sg, bufflen, gfp); 405 err = scsi_req_map_sg(req, buffer, use_sg, bufflen, gfp);
@@ -933,7 +935,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
933 break; 935 break;
934 } 936 }
935 } 937 }
936 if (!(req->flags & REQ_QUIET)) { 938 if (!(req->cmd_flags & REQ_QUIET)) {
937 scmd_printk(KERN_INFO, cmd, 939 scmd_printk(KERN_INFO, cmd,
938 "Device not ready: "); 940 "Device not ready: ");
939 scsi_print_sense_hdr("", &sshdr); 941 scsi_print_sense_hdr("", &sshdr);
@@ -941,7 +943,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
941 scsi_end_request(cmd, 0, this_count, 1); 943 scsi_end_request(cmd, 0, this_count, 1);
942 return; 944 return;
943 case VOLUME_OVERFLOW: 945 case VOLUME_OVERFLOW:
944 if (!(req->flags & REQ_QUIET)) { 946 if (!(req->cmd_flags & REQ_QUIET)) {
945 scmd_printk(KERN_INFO, cmd, 947 scmd_printk(KERN_INFO, cmd,
946 "Volume overflow, CDB: "); 948 "Volume overflow, CDB: ");
947 __scsi_print_command(cmd->cmnd); 949 __scsi_print_command(cmd->cmnd);
@@ -963,7 +965,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
963 return; 965 return;
964 } 966 }
965 if (result) { 967 if (result) {
966 if (!(req->flags & REQ_QUIET)) { 968 if (!(req->cmd_flags & REQ_QUIET)) {
967 scmd_printk(KERN_INFO, cmd, 969 scmd_printk(KERN_INFO, cmd,
968 "SCSI error: return code = 0x%08x\n", 970 "SCSI error: return code = 0x%08x\n",
969 result); 971 result);
@@ -995,7 +997,7 @@ static int scsi_init_io(struct scsi_cmnd *cmd)
995 /* 997 /*
996 * if this is a rq->data based REQ_BLOCK_PC, setup for a non-sg xfer 998 * if this is a rq->data based REQ_BLOCK_PC, setup for a non-sg xfer
997 */ 999 */
998 if ((req->flags & REQ_BLOCK_PC) && !req->bio) { 1000 if (blk_pc_request(req) && !req->bio) {
999 cmd->request_bufflen = req->data_len; 1001 cmd->request_bufflen = req->data_len;
1000 cmd->request_buffer = req->data; 1002 cmd->request_buffer = req->data;
1001 req->buffer = req->data; 1003 req->buffer = req->data;
@@ -1139,13 +1141,12 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
1139 * these two cases differently. We differentiate by looking 1141 * these two cases differently. We differentiate by looking
1140 * at request->cmd, as this tells us the real story. 1142 * at request->cmd, as this tells us the real story.
1141 */ 1143 */
1142 if (req->flags & REQ_SPECIAL && req->special) { 1144 if (blk_special_request(req) && req->special)
1143 cmd = req->special; 1145 cmd = req->special;
1144 } else if (req->flags & (REQ_CMD | REQ_BLOCK_PC)) { 1146 else if (blk_pc_request(req) || blk_fs_request(req)) {
1145 1147 if (unlikely(specials_only) && !(req->cmd_flags & REQ_PREEMPT)){
1146 if(unlikely(specials_only) && !(req->flags & REQ_SPECIAL)) { 1148 if (specials_only == SDEV_QUIESCE ||
1147 if(specials_only == SDEV_QUIESCE || 1149 specials_only == SDEV_BLOCK)
1148 specials_only == SDEV_BLOCK)
1149 goto defer; 1150 goto defer;
1150 1151
1151 sdev_printk(KERN_ERR, sdev, 1152 sdev_printk(KERN_ERR, sdev,
@@ -1153,7 +1154,6 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
1153 goto kill; 1154 goto kill;
1154 } 1155 }
1155 1156
1156
1157 /* 1157 /*
1158 * Now try and find a command block that we can use. 1158 * Now try and find a command block that we can use.
1159 */ 1159 */
@@ -1184,7 +1184,7 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
1184 * lock. We hope REQ_STARTED prevents anything untoward from 1184 * lock. We hope REQ_STARTED prevents anything untoward from
1185 * happening now. 1185 * happening now.
1186 */ 1186 */
1187 if (req->flags & (REQ_CMD | REQ_BLOCK_PC)) { 1187 if (blk_fs_request(req) || blk_pc_request(req)) {
1188 int ret; 1188 int ret;
1189 1189
1190 /* 1190 /*
@@ -1216,7 +1216,7 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
1216 /* 1216 /*
1217 * Initialize the actual SCSI command for this request. 1217 * Initialize the actual SCSI command for this request.
1218 */ 1218 */
1219 if (req->flags & REQ_BLOCK_PC) { 1219 if (blk_pc_request(req)) {
1220 scsi_setup_blk_pc_cmnd(cmd); 1220 scsi_setup_blk_pc_cmnd(cmd);
1221 } else if (req->rq_disk) { 1221 } else if (req->rq_disk) {
1222 struct scsi_driver *drv; 1222 struct scsi_driver *drv;
@@ -1233,7 +1233,7 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
1233 /* 1233 /*
1234 * The request is now prepped, no need to come back here 1234 * The request is now prepped, no need to come back here
1235 */ 1235 */
1236 req->flags |= REQ_DONTPREP; 1236 req->cmd_flags |= REQ_DONTPREP;
1237 return BLKPREP_OK; 1237 return BLKPREP_OK;
1238 1238
1239 defer: 1239 defer:
@@ -1454,8 +1454,9 @@ static void scsi_request_fn(struct request_queue *q)
1454 if (unlikely(cmd == NULL)) { 1454 if (unlikely(cmd == NULL)) {
1455 printk(KERN_CRIT "impossible request in %s.\n" 1455 printk(KERN_CRIT "impossible request in %s.\n"
1456 "please mail a stack trace to " 1456 "please mail a stack trace to "
1457 "linux-scsi@vger.kernel.org", 1457 "linux-scsi@vger.kernel.org\n",
1458 __FUNCTION__); 1458 __FUNCTION__);
1459 blk_dump_rq_flags(req, "foo");
1459 BUG(); 1460 BUG();
1460 } 1461 }
1461 spin_lock(shost->host_lock); 1462 spin_lock(shost->host_lock);
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 638cff41d436..10bc99c911fa 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -443,8 +443,7 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
443 SCpnt->cmnd[0] = READ_6; 443 SCpnt->cmnd[0] = READ_6;
444 SCpnt->sc_data_direction = DMA_FROM_DEVICE; 444 SCpnt->sc_data_direction = DMA_FROM_DEVICE;
445 } else { 445 } else {
446 printk(KERN_ERR "sd: Unknown command %lx\n", rq->flags); 446 printk(KERN_ERR "sd: Unknown command %x\n", rq->cmd_flags);
447/* overkill panic("Unknown sd command %lx\n", rq->flags); */
448 return 0; 447 return 0;
449 } 448 }
450 449
@@ -840,7 +839,7 @@ static int sd_issue_flush(struct device *dev, sector_t *error_sector)
840static void sd_prepare_flush(request_queue_t *q, struct request *rq) 839static void sd_prepare_flush(request_queue_t *q, struct request *rq)
841{ 840{
842 memset(rq->cmd, 0, sizeof(rq->cmd)); 841 memset(rq->cmd, 0, sizeof(rq->cmd));
843 rq->flags |= REQ_BLOCK_PC; 842 rq->cmd_type = REQ_TYPE_BLOCK_PC;
844 rq->timeout = SD_TIMEOUT; 843 rq->timeout = SD_TIMEOUT;
845 rq->cmd[0] = SYNCHRONIZE_CACHE; 844 rq->cmd[0] = SYNCHRONIZE_CACHE;
846 rq->cmd_len = 10; 845 rq->cmd_len = 10;
diff --git a/drivers/scsi/sim710.c b/drivers/scsi/sim710.c
index b27e85428daa..551baccec523 100644
--- a/drivers/scsi/sim710.c
+++ b/drivers/scsi/sim710.c
@@ -282,6 +282,7 @@ static struct eisa_device_id sim710_eisa_ids[] = {
282 { "HWP0C80" }, 282 { "HWP0C80" },
283 { "" } 283 { "" }
284}; 284};
285MODULE_DEVICE_TABLE(eisa, sim710_eisa_ids);
285 286
286static __init int 287static __init int
287sim710_eisa_probe(struct device *dev) 288sim710_eisa_probe(struct device *dev)
diff --git a/drivers/scsi/sun3_NCR5380.c b/drivers/scsi/sun3_NCR5380.c
index 2f8073b73bf3..7f9bcef6adfa 100644
--- a/drivers/scsi/sun3_NCR5380.c
+++ b/drivers/scsi/sun3_NCR5380.c
@@ -2017,7 +2017,7 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
2017 if((count > SUN3_DMA_MINSIZE) && (sun3_dma_setup_done 2017 if((count > SUN3_DMA_MINSIZE) && (sun3_dma_setup_done
2018 != cmd)) 2018 != cmd))
2019 { 2019 {
2020 if(cmd->request->flags & REQ_CMD) { 2020 if(blk_fs_request(cmd->request)) {
2021 sun3scsi_dma_setup(d, count, 2021 sun3scsi_dma_setup(d, count,
2022 rq_data_dir(cmd->request)); 2022 rq_data_dir(cmd->request));
2023 sun3_dma_setup_done = cmd; 2023 sun3_dma_setup_done = cmd;
diff --git a/drivers/scsi/sun3_scsi.c b/drivers/scsi/sun3_scsi.c
index 837173415d4c..44a99aeb8180 100644
--- a/drivers/scsi/sun3_scsi.c
+++ b/drivers/scsi/sun3_scsi.c
@@ -524,7 +524,7 @@ static inline unsigned long sun3scsi_dma_residual(struct Scsi_Host *instance)
524static inline unsigned long sun3scsi_dma_xfer_len(unsigned long wanted, Scsi_Cmnd *cmd, 524static inline unsigned long sun3scsi_dma_xfer_len(unsigned long wanted, Scsi_Cmnd *cmd,
525 int write_flag) 525 int write_flag)
526{ 526{
527 if(cmd->request->flags & REQ_CMD) 527 if(blk_fs_request(cmd->request))
528 return wanted; 528 return wanted;
529 else 529 else
530 return 0; 530 return 0;
diff --git a/drivers/scsi/sun3_scsi_vme.c b/drivers/scsi/sun3_scsi_vme.c
index 008a82ab8521..f5742b84b27a 100644
--- a/drivers/scsi/sun3_scsi_vme.c
+++ b/drivers/scsi/sun3_scsi_vme.c
@@ -458,7 +458,7 @@ static inline unsigned long sun3scsi_dma_residual(struct Scsi_Host *instance)
458static inline unsigned long sun3scsi_dma_xfer_len(unsigned long wanted, Scsi_Cmnd *cmd, 458static inline unsigned long sun3scsi_dma_xfer_len(unsigned long wanted, Scsi_Cmnd *cmd,
459 int write_flag) 459 int write_flag)
460{ 460{
461 if(cmd->request->flags & REQ_CMD) 461 if(blk_fs_request(cmd->request))
462 return wanted; 462 return wanted;
463 else 463 else
464 return 0; 464 return 0;
diff --git a/drivers/serial/68328serial.c b/drivers/serial/68328serial.c
index 993a702422ec..bac853c5abb5 100644
--- a/drivers/serial/68328serial.c
+++ b/drivers/serial/68328serial.c
@@ -1378,7 +1378,7 @@ void startup_console(void)
1378#endif /* CONFIG_PM_LEGACY */ 1378#endif /* CONFIG_PM_LEGACY */
1379 1379
1380 1380
1381static struct tty_operations rs_ops = { 1381static const struct tty_operations rs_ops = {
1382 .open = rs_open, 1382 .open = rs_open,
1383 .close = rs_close, 1383 .close = rs_close,
1384 .write = rs_write, 1384 .write = rs_write,
diff --git a/drivers/serial/68360serial.c b/drivers/serial/68360serial.c
index e80e70e9b126..1b299e8c57cd 100644
--- a/drivers/serial/68360serial.c
+++ b/drivers/serial/68360serial.c
@@ -2424,7 +2424,7 @@ long console_360_init(long kmem_start, long kmem_end)
2424*/ 2424*/
2425static int baud_idx; 2425static int baud_idx;
2426 2426
2427static struct tty_operations rs_360_ops = { 2427static const struct tty_operations rs_360_ops = {
2428 .owner = THIS_MODULE, 2428 .owner = THIS_MODULE,
2429 .open = rs_360_open, 2429 .open = rs_360_open,
2430 .close = rs_360_close, 2430 .close = rs_360_close,
diff --git a/drivers/serial/8250_acorn.c b/drivers/serial/8250_acorn.c
index 32af3650e8b4..ef8cc8a70c60 100644
--- a/drivers/serial/8250_acorn.c
+++ b/drivers/serial/8250_acorn.c
@@ -35,6 +35,7 @@ struct serial_card_type {
35struct serial_card_info { 35struct serial_card_info {
36 unsigned int num_ports; 36 unsigned int num_ports;
37 int ports[MAX_PORTS]; 37 int ports[MAX_PORTS];
38 void __iomem *vaddr;
38}; 39};
39 40
40static int __devinit 41static int __devinit
@@ -44,7 +45,6 @@ serial_card_probe(struct expansion_card *ec, const struct ecard_id *id)
44 struct serial_card_type *type = id->data; 45 struct serial_card_type *type = id->data;
45 struct uart_port port; 46 struct uart_port port;
46 unsigned long bus_addr; 47 unsigned long bus_addr;
47 unsigned char __iomem *virt_addr;
48 unsigned int i; 48 unsigned int i;
49 49
50 info = kmalloc(sizeof(struct serial_card_info), GFP_KERNEL); 50 info = kmalloc(sizeof(struct serial_card_info), GFP_KERNEL);
@@ -55,8 +55,8 @@ serial_card_probe(struct expansion_card *ec, const struct ecard_id *id)
55 info->num_ports = type->num_ports; 55 info->num_ports = type->num_ports;
56 56
57 bus_addr = ecard_resource_start(ec, type->type); 57 bus_addr = ecard_resource_start(ec, type->type);
58 virt_addr = ioremap(bus_addr, ecard_resource_len(ec, type->type)); 58 info->vaddr = ioremap(bus_addr, ecard_resource_len(ec, type->type));
59 if (!virt_addr) { 59 if (!info->vaddr) {
60 kfree(info); 60 kfree(info);
61 return -ENOMEM; 61 return -ENOMEM;
62 } 62 }
@@ -72,7 +72,7 @@ serial_card_probe(struct expansion_card *ec, const struct ecard_id *id)
72 port.dev = &ec->dev; 72 port.dev = &ec->dev;
73 73
74 for (i = 0; i < info->num_ports; i ++) { 74 for (i = 0; i < info->num_ports; i ++) {
75 port.membase = virt_addr + type->offset[i]; 75 port.membase = info->vaddr + type->offset[i];
76 port.mapbase = bus_addr + type->offset[i]; 76 port.mapbase = bus_addr + type->offset[i];
77 77
78 info->ports[i] = serial8250_register_port(&port); 78 info->ports[i] = serial8250_register_port(&port);
@@ -92,6 +92,7 @@ static void __devexit serial_card_remove(struct expansion_card *ec)
92 if (info->ports[i] > 0) 92 if (info->ports[i] > 0)
93 serial8250_unregister_port(info->ports[i]); 93 serial8250_unregister_port(info->ports[i]);
94 94
95 iounmap(info->vaddr);
95 kfree(info); 96 kfree(info);
96} 97}
97 98
diff --git a/drivers/serial/8250_gsc.c b/drivers/serial/8250_gsc.c
index 913c71cc0569..1ebe6b585d2d 100644
--- a/drivers/serial/8250_gsc.c
+++ b/drivers/serial/8250_gsc.c
@@ -64,6 +64,7 @@ serial_init_chip(struct parisc_device *dev)
64 err = serial8250_register_port(&port); 64 err = serial8250_register_port(&port);
65 if (err < 0) { 65 if (err < 0) {
66 printk(KERN_WARNING "serial8250_register_port returned error %d\n", err); 66 printk(KERN_WARNING "serial8250_register_port returned error %d\n", err);
67 iounmap(port.membase);
67 return err; 68 return err;
68 } 69 }
69 70
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 5b48ac22c9c5..d926272a40db 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -295,7 +295,7 @@ config SERIAL_AMBA_PL011_CONSOLE
295 Even if you say Y here, the currently visible framebuffer console 295 Even if you say Y here, the currently visible framebuffer console
296 (/dev/tty0) will still be used as the system console by default, but 296 (/dev/tty0) will still be used as the system console by default, but
297 you can alter that using a kernel command line option such as 297 you can alter that using a kernel command line option such as
298 "console=ttyAM0". (Try "man bootparam" or see the documentation of 298 "console=ttyAMA0". (Try "man bootparam" or see the documentation of
299 your boot loader (lilo or loadlin) about how to pass options to the 299 your boot loader (lilo or loadlin) about how to pass options to the
300 kernel at boot time.) 300 kernel at boot time.)
301 301
@@ -642,12 +642,17 @@ config V850E_UART_CONSOLE
642 select SERIAL_CORE_CONSOLE 642 select SERIAL_CORE_CONSOLE
643 643
644config SERIAL_SH_SCI 644config SERIAL_SH_SCI
645 tristate "SH SCI(F) serial port support" 645 tristate "SuperH SCI(F) serial port support"
646 depends on SUPERH || H8300 646 depends on SUPERH || H8300
647 select SERIAL_CORE 647 select SERIAL_CORE
648 648
649config SERIAL_SH_SCI_NR_UARTS
650 int "Maximum number of SCI(F) serial ports"
651 depends on SERIAL_SH_SCI
652 default "2"
653
649config SERIAL_SH_SCI_CONSOLE 654config SERIAL_SH_SCI_CONSOLE
650 bool "Support for console on SH SCI(F)" 655 bool "Support for console on SuperH SCI(F)"
651 depends on SERIAL_SH_SCI=y 656 depends on SERIAL_SH_SCI=y
652 select SERIAL_CORE_CONSOLE 657 select SERIAL_CORE_CONSOLE
653 658
diff --git a/drivers/serial/at91_serial.c b/drivers/serial/at91_serial.c
index 54c6b2adf7b7..bf4bf103e5a0 100644
--- a/drivers/serial/at91_serial.c
+++ b/drivers/serial/at91_serial.c
@@ -139,7 +139,7 @@ static void at91_set_mctrl(struct uart_port *port, u_int mctrl)
139 * AT91RM9200 Errata #39: RTS0 is not internally connected to PA21. 139 * AT91RM9200 Errata #39: RTS0 is not internally connected to PA21.
140 * We need to drive the pin manually. 140 * We need to drive the pin manually.
141 */ 141 */
142 if (port->mapbase == AT91_BASE_US0) { 142 if (port->mapbase == AT91RM9200_BASE_US0) {
143 if (mctrl & TIOCM_RTS) 143 if (mctrl & TIOCM_RTS)
144 at91_set_gpio_value(AT91_PIN_PA21, 0); 144 at91_set_gpio_value(AT91_PIN_PA21, 0);
145 else 145 else
diff --git a/drivers/serial/crisv10.c b/drivers/serial/crisv10.c
index cabd048c8636..9851d9eff022 100644
--- a/drivers/serial/crisv10.c
+++ b/drivers/serial/crisv10.c
@@ -4825,7 +4825,7 @@ show_serial_version(void)
4825 4825
4826/* rs_init inits the driver at boot (using the module_init chain) */ 4826/* rs_init inits the driver at boot (using the module_init chain) */
4827 4827
4828static struct tty_operations rs_ops = { 4828static const struct tty_operations rs_ops = {
4829 .open = rs_open, 4829 .open = rs_open,
4830 .close = rs_close, 4830 .close = rs_close,
4831 .write = rs_write, 4831 .write = rs_write,
diff --git a/drivers/serial/ioc4_serial.c b/drivers/serial/ioc4_serial.c
index 576ca1eaa2b6..5ec4716c99bf 100644
--- a/drivers/serial/ioc4_serial.c
+++ b/drivers/serial/ioc4_serial.c
@@ -2685,6 +2685,7 @@ static int ioc4_serial_remove_one(struct ioc4_driver_data *idd)
2685 if (soft) { 2685 if (soft) {
2686 free_irq(control->ic_irq, soft); 2686 free_irq(control->ic_irq, soft);
2687 if (soft->is_ioc4_serial_addr) { 2687 if (soft->is_ioc4_serial_addr) {
2688 iounmap(soft->is_ioc4_serial_addr);
2688 release_region((unsigned long) 2689 release_region((unsigned long)
2689 soft->is_ioc4_serial_addr, 2690 soft->is_ioc4_serial_addr,
2690 sizeof(struct ioc4_serial)); 2691 sizeof(struct ioc4_serial));
@@ -2887,6 +2888,8 @@ out4:
2887out3: 2888out3:
2888 kfree(control); 2889 kfree(control);
2889out2: 2890out2:
2891 if (serial)
2892 iounmap(serial);
2890 release_region(tmp_addr1, sizeof(struct ioc4_serial)); 2893 release_region(tmp_addr1, sizeof(struct ioc4_serial));
2891out1: 2894out1:
2892 2895
diff --git a/drivers/serial/ip22zilog.c b/drivers/serial/ip22zilog.c
index 5ff269fb604c..dbf13c03a1bb 100644
--- a/drivers/serial/ip22zilog.c
+++ b/drivers/serial/ip22zilog.c
@@ -1229,13 +1229,27 @@ static int __init ip22zilog_init(void)
1229static void __exit ip22zilog_exit(void) 1229static void __exit ip22zilog_exit(void)
1230{ 1230{
1231 int i; 1231 int i;
1232 struct uart_ip22zilog_port *up;
1232 1233
1233 for (i = 0; i < NUM_CHANNELS; i++) { 1234 for (i = 0; i < NUM_CHANNELS; i++) {
1234 struct uart_ip22zilog_port *up = &ip22zilog_port_table[i]; 1235 up = &ip22zilog_port_table[i];
1235 1236
1236 uart_remove_one_port(&ip22zilog_reg, &up->port); 1237 uart_remove_one_port(&ip22zilog_reg, &up->port);
1237 } 1238 }
1238 1239
1240 /* Free IO mem */
1241 up = &ip22zilog_port_table[0];
1242 for (i = 0; i < NUM_IP22ZILOG; i++) {
1243 if (up[(i * 2) + 0].port.mapbase) {
1244 iounmap((void*)up[(i * 2) + 0].port.mapbase);
1245 up[(i * 2) + 0].port.mapbase = 0;
1246 }
1247 if (up[(i * 2) + 1].port.mapbase) {
1248 iounmap((void*)up[(i * 2) + 1].port.mapbase);
1249 up[(i * 2) + 1].port.mapbase = 0;
1250 }
1251 }
1252
1239 uart_unregister_driver(&ip22zilog_reg); 1253 uart_unregister_driver(&ip22zilog_reg);
1240} 1254}
1241 1255
diff --git a/drivers/serial/mcfserial.c b/drivers/serial/mcfserial.c
index 832abd3c4706..00d7859c167e 100644
--- a/drivers/serial/mcfserial.c
+++ b/drivers/serial/mcfserial.c
@@ -1666,7 +1666,7 @@ static void show_serial_version(void)
1666 printk(mcfrs_drivername); 1666 printk(mcfrs_drivername);
1667} 1667}
1668 1668
1669static struct tty_operations mcfrs_ops = { 1669static const struct tty_operations mcfrs_ops = {
1670 .open = mcfrs_open, 1670 .open = mcfrs_open,
1671 .close = mcfrs_close, 1671 .close = mcfrs_close,
1672 .write = mcfrs_write, 1672 .write = mcfrs_write,
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 7708e5dd3656..dbad0e31e005 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -338,14 +338,23 @@ mpc52xx_uart_release_port(struct uart_port *port)
338static int 338static int
339mpc52xx_uart_request_port(struct uart_port *port) 339mpc52xx_uart_request_port(struct uart_port *port)
340{ 340{
341 int err;
342
341 if (port->flags & UPF_IOREMAP) /* Need to remap ? */ 343 if (port->flags & UPF_IOREMAP) /* Need to remap ? */
342 port->membase = ioremap(port->mapbase, MPC52xx_PSC_SIZE); 344 port->membase = ioremap(port->mapbase, MPC52xx_PSC_SIZE);
343 345
344 if (!port->membase) 346 if (!port->membase)
345 return -EINVAL; 347 return -EINVAL;
346 348
347 return request_mem_region(port->mapbase, MPC52xx_PSC_SIZE, 349 err = request_mem_region(port->mapbase, MPC52xx_PSC_SIZE,
348 "mpc52xx_psc_uart") != NULL ? 0 : -EBUSY; 350 "mpc52xx_psc_uart") != NULL ? 0 : -EBUSY;
351
352 if (err && (port->flags & UPF_IOREMAP)) {
353 iounmap(port->membase);
354 port->membase = NULL;
355 }
356
357 return err;
349} 358}
350 359
351static void 360static void
diff --git a/drivers/serial/mpsc.c b/drivers/serial/mpsc.c
index 63d2a66e563b..704243c9f78a 100644
--- a/drivers/serial/mpsc.c
+++ b/drivers/serial/mpsc.c
@@ -1893,6 +1893,10 @@ mpsc_drv_map_regs(struct mpsc_port_info *pi, struct platform_device *pd)
1893 } 1893 }
1894 else { 1894 else {
1895 mpsc_resource_err("SDMA base"); 1895 mpsc_resource_err("SDMA base");
1896 if (pi->mpsc_base) {
1897 iounmap(pi->mpsc_base);
1898 pi->mpsc_base = NULL;
1899 }
1896 return -ENOMEM; 1900 return -ENOMEM;
1897 } 1901 }
1898 1902
@@ -1905,6 +1909,14 @@ mpsc_drv_map_regs(struct mpsc_port_info *pi, struct platform_device *pd)
1905 } 1909 }
1906 else { 1910 else {
1907 mpsc_resource_err("BRG base"); 1911 mpsc_resource_err("BRG base");
1912 if (pi->mpsc_base) {
1913 iounmap(pi->mpsc_base);
1914 pi->mpsc_base = NULL;
1915 }
1916 if (pi->sdma_base) {
1917 iounmap(pi->sdma_base);
1918 pi->sdma_base = NULL;
1919 }
1908 return -ENOMEM; 1920 return -ENOMEM;
1909 } 1921 }
1910 1922
diff --git a/drivers/serial/mux.c b/drivers/serial/mux.c
index 4a1c9983f38f..aa819d3f8ee5 100644
--- a/drivers/serial/mux.c
+++ b/drivers/serial/mux.c
@@ -521,6 +521,8 @@ static void __exit mux_exit(void)
521 521
522 for (i = 0; i < port_cnt; i++) { 522 for (i = 0; i < port_cnt; i++) {
523 uart_remove_one_port(&mux_driver, &mux_ports[i]); 523 uart_remove_one_port(&mux_driver, &mux_ports[i]);
524 if (mux_ports[i].membase)
525 iounmap(mux_ports[i].membase);
524 } 526 }
525 527
526 uart_unregister_driver(&mux_driver); 528 uart_unregister_driver(&mux_driver);
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 372e47f7d596..de5e8930a6fd 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -1929,6 +1929,13 @@ int uart_suspend_port(struct uart_driver *drv, struct uart_port *port)
1929 1929
1930 mutex_lock(&state->mutex); 1930 mutex_lock(&state->mutex);
1931 1931
1932#ifdef CONFIG_DISABLE_CONSOLE_SUSPEND
1933 if (uart_console(port)) {
1934 mutex_unlock(&state->mutex);
1935 return 0;
1936 }
1937#endif
1938
1932 if (state->info && state->info->flags & UIF_INITIALIZED) { 1939 if (state->info && state->info->flags & UIF_INITIALIZED) {
1933 const struct uart_ops *ops = port->ops; 1940 const struct uart_ops *ops = port->ops;
1934 1941
@@ -1967,6 +1974,13 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *port)
1967 1974
1968 mutex_lock(&state->mutex); 1975 mutex_lock(&state->mutex);
1969 1976
1977#ifdef CONFIG_DISABLE_CONSOLE_SUSPEND
1978 if (uart_console(port)) {
1979 mutex_unlock(&state->mutex);
1980 return 0;
1981 }
1982#endif
1983
1970 uart_change_pm(state, 0); 1984 uart_change_pm(state, 0);
1971 1985
1972 /* 1986 /*
@@ -2097,7 +2111,7 @@ uart_configure_port(struct uart_driver *drv, struct uart_state *state,
2097 } 2111 }
2098} 2112}
2099 2113
2100static struct tty_operations uart_ops = { 2114static const struct tty_operations uart_ops = {
2101 .open = uart_open, 2115 .open = uart_open,
2102 .close = uart_close, 2116 .close = uart_close,
2103 .write = uart_write, 2117 .write = uart_write,
diff --git a/drivers/serial/sh-sci.c b/drivers/serial/sh-sci.c
index cbede06cac27..f336ba6778dd 100644
--- a/drivers/serial/sh-sci.c
+++ b/drivers/serial/sh-sci.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * SuperH on-chip serial module support. (SCI with no FIFO / with FIFO) 4 * SuperH on-chip serial module support. (SCI with no FIFO / with FIFO)
5 * 5 *
6 * Copyright (C) 2002, 2003, 2004 Paul Mundt 6 * Copyright (C) 2002 - 2006 Paul Mundt
7 * 7 *
8 * based off of the old drivers/char/sh-sci.c by: 8 * based off of the old drivers/char/sh-sci.c by:
9 * 9 *
@@ -20,10 +20,9 @@
20 20
21#undef DEBUG 21#undef DEBUG
22 22
23#include <linux/config.h>
23#include <linux/module.h> 24#include <linux/module.h>
24#include <linux/errno.h> 25#include <linux/errno.h>
25#include <linux/signal.h>
26#include <linux/sched.h>
27#include <linux/timer.h> 26#include <linux/timer.h>
28#include <linux/interrupt.h> 27#include <linux/interrupt.h>
29#include <linux/tty.h> 28#include <linux/tty.h>
@@ -32,71 +31,77 @@
32#include <linux/major.h> 31#include <linux/major.h>
33#include <linux/string.h> 32#include <linux/string.h>
34#include <linux/sysrq.h> 33#include <linux/sysrq.h>
35#include <linux/fcntl.h>
36#include <linux/ptrace.h>
37#include <linux/ioport.h> 34#include <linux/ioport.h>
38#include <linux/mm.h> 35#include <linux/mm.h>
39#include <linux/slab.h>
40#include <linux/init.h> 36#include <linux/init.h>
41#include <linux/delay.h> 37#include <linux/delay.h>
42#include <linux/console.h> 38#include <linux/console.h>
43#include <linux/bitops.h> 39#include <linux/platform_device.h>
44#include <linux/generic_serial.h>
45 40
46#ifdef CONFIG_CPU_FREQ 41#ifdef CONFIG_CPU_FREQ
47#include <linux/notifier.h> 42#include <linux/notifier.h>
48#include <linux/cpufreq.h> 43#include <linux/cpufreq.h>
49#endif 44#endif
50 45
51#include <asm/system.h>
52#include <asm/io.h>
53#include <asm/irq.h>
54#include <asm/uaccess.h>
55
56#if defined(CONFIG_SUPERH) && !defined(CONFIG_SUPERH64) 46#if defined(CONFIG_SUPERH) && !defined(CONFIG_SUPERH64)
57#include <asm/clock.h> 47#include <asm/clock.h>
58#endif
59
60#ifdef CONFIG_SH_STANDARD_BIOS
61#include <asm/sh_bios.h> 48#include <asm/sh_bios.h>
49#include <asm/kgdb.h>
62#endif 50#endif
63 51
52#include <asm/sci.h>
53
64#if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 54#if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
65#define SUPPORT_SYSRQ 55#define SUPPORT_SYSRQ
66#endif 56#endif
67 57
68#include "sh-sci.h" 58#include "sh-sci.h"
69 59
70#ifdef CONFIG_SH_KGDB 60struct sci_port {
71#include <asm/kgdb.h> 61 struct uart_port port;
62
63 /* Port type */
64 unsigned int type;
65
66 /* Port IRQs: ERI, RXI, TXI, BRI (optional) */
67 unsigned int irqs[SCIx_NR_IRQS];
68
69 /* Port pin configuration */
70 void (*init_pins)(struct uart_port *port,
71 unsigned int cflag);
72 72
73static int kgdb_get_char(struct sci_port *port); 73 /* Port enable callback */
74static void kgdb_put_char(struct sci_port *port, char c); 74 void (*enable)(struct uart_port *port);
75static void kgdb_handle_error(struct sci_port *port); 75
76 /* Port disable callback */
77 void (*disable)(struct uart_port *port);
78
79 /* Break timer */
80 struct timer_list break_timer;
81 int break_flag;
82};
83
84#ifdef CONFIG_SH_KGDB
76static struct sci_port *kgdb_sci_port; 85static struct sci_port *kgdb_sci_port;
77#endif /* CONFIG_SH_KGDB */ 86#endif
78 87
79#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE 88#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
80static struct sci_port *serial_console_port = 0; 89static struct sci_port *serial_console_port;
81#endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */ 90#endif
82 91
83/* Function prototypes */ 92/* Function prototypes */
84static void sci_stop_tx(struct uart_port *port); 93static void sci_stop_tx(struct uart_port *port);
85static void sci_start_tx(struct uart_port *port);
86static void sci_start_rx(struct uart_port *port, unsigned int tty_start);
87static void sci_stop_rx(struct uart_port *port);
88static int sci_request_irq(struct sci_port *port);
89static void sci_free_irq(struct sci_port *port);
90
91static struct sci_port sci_ports[];
92static struct uart_driver sci_uart_driver;
93 94
94#define SCI_NPORTS sci_uart_driver.nr 95#define SCI_NPORTS CONFIG_SERIAL_SH_SCI_NR_UARTS
95 96
96#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB) 97static struct sci_port sci_ports[SCI_NPORTS];
98static struct uart_driver sci_uart_driver;
97 99
98static void handle_error(struct uart_port *port) 100#if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) && \
99{ /* Clear error flags */ 101 defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
102static inline void handle_error(struct uart_port *port)
103{
104 /* Clear error flags */
100 sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port)); 105 sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
101} 106}
102 107
@@ -106,8 +111,8 @@ static int get_char(struct uart_port *port)
106 unsigned short status; 111 unsigned short status;
107 int c; 112 int c;
108 113
109 local_irq_save(flags); 114 spin_lock_irqsave(&port->lock, flags);
110 do { 115 do {
111 status = sci_in(port, SCxSR); 116 status = sci_in(port, SCxSR);
112 if (status & SCxSR_ERRORS(port)) { 117 if (status & SCxSR_ERRORS(port)) {
113 handle_error(port); 118 handle_error(port);
@@ -117,38 +122,19 @@ static int get_char(struct uart_port *port)
117 c = sci_in(port, SCxRDR); 122 c = sci_in(port, SCxRDR);
118 sci_in(port, SCxSR); /* Dummy read */ 123 sci_in(port, SCxSR); /* Dummy read */
119 sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); 124 sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
120 local_irq_restore(flags); 125 spin_unlock_irqrestore(&port->lock, flags);
121 126
122 return c; 127 return c;
123} 128}
124
125/* Taken from sh-stub.c of GDB 4.18 */
126static const char hexchars[] = "0123456789abcdef";
127
128static __inline__ char highhex(int x)
129{
130 return hexchars[(x >> 4) & 0xf];
131}
132
133static __inline__ char lowhex(int x)
134{
135 return hexchars[x & 0xf];
136}
137
138#endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_SH_KGDB */ 129#endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_SH_KGDB */
139 130
140/* 131#if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) || defined(CONFIG_SH_KGDB)
141 * Send the packet in buffer. The host gets one chance to read it.
142 * This routine does not wait for a positive acknowledge.
143 */
144
145#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
146static void put_char(struct uart_port *port, char c) 132static void put_char(struct uart_port *port, char c)
147{ 133{
148 unsigned long flags; 134 unsigned long flags;
149 unsigned short status; 135 unsigned short status;
150 136
151 local_irq_save(flags); 137 spin_lock_irqsave(&port->lock, flags);
152 138
153 do { 139 do {
154 status = sci_in(port, SCxSR); 140 status = sci_in(port, SCxSR);
@@ -158,9 +144,11 @@ static void put_char(struct uart_port *port, char c)
158 sci_in(port, SCxSR); /* Dummy read */ 144 sci_in(port, SCxSR); /* Dummy read */
159 sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port)); 145 sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
160 146
161 local_irq_restore(flags); 147 spin_unlock_irqrestore(&port->lock, flags);
162} 148}
149#endif
163 150
151#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
164static void put_string(struct sci_port *sci_port, const char *buffer, int count) 152static void put_string(struct sci_port *sci_port, const char *buffer, int count)
165{ 153{
166 struct uart_port *port = &sci_port->port; 154 struct uart_port *port = &sci_port->port;
@@ -213,96 +201,28 @@ static void put_string(struct sci_port *sci_port, const char *buffer, int count)
213} 201}
214#endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */ 202#endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */
215 203
216
217#ifdef CONFIG_SH_KGDB 204#ifdef CONFIG_SH_KGDB
218
219/* Is the SCI ready, ie is there a char waiting? */
220static int kgdb_is_char_ready(struct sci_port *port)
221{
222 unsigned short status = sci_in(port, SCxSR);
223
224 if (status & (SCxSR_ERRORS(port) | SCxSR_BRK(port)))
225 kgdb_handle_error(port);
226
227 return (status & SCxSR_RDxF(port));
228}
229
230/* Write a char */
231static void kgdb_put_char(struct sci_port *port, char c)
232{
233 unsigned short status;
234
235 do
236 status = sci_in(port, SCxSR);
237 while (!(status & SCxSR_TDxE(port)));
238
239 sci_out(port, SCxTDR, c);
240 sci_in(port, SCxSR); /* Dummy read */
241 sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
242}
243
244/* Get a char if there is one, else ret -1 */
245static int kgdb_get_char(struct sci_port *port)
246{
247 int c;
248
249 if (kgdb_is_char_ready(port) == 0)
250 c = -1;
251 else {
252 c = sci_in(port, SCxRDR);
253 sci_in(port, SCxSR); /* Dummy read */
254 sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
255 }
256
257 return c;
258}
259
260/* Called from kgdbstub.c to get a character, i.e. is blocking */
261static int kgdb_sci_getchar(void) 205static int kgdb_sci_getchar(void)
262{ 206{
263 volatile int c; 207 int c;
264 208
265 /* Keep trying to read a character, this could be neater */ 209 /* Keep trying to read a character, this could be neater */
266 while ((c = kgdb_get_char(kgdb_sci_port)) < 0); 210 while ((c = get_char(kgdb_sci_port)) < 0)
211 cpu_relax();
267 212
268 return c; 213 return c;
269} 214}
270 215
271/* Called from kgdbstub.c to put a character, just a wrapper */ 216static inline void kgdb_sci_putchar(int c)
272static void kgdb_sci_putchar(int c)
273{
274
275 kgdb_put_char(kgdb_sci_port, c);
276}
277
278/* Clear any errors on the SCI */
279static void kgdb_handle_error(struct sci_port *port)
280{ 217{
281 sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port)); /* Clear error flags */ 218 put_char(kgdb_sci_port, c);
282} 219}
283
284/* Breakpoint if there's a break sent on the serial port */
285static void kgdb_break_interrupt(int irq, void *ptr, struct pt_regs *regs)
286{
287 struct sci_port *port = ptr;
288 unsigned short status = sci_in(port, SCxSR);
289
290 if (status & SCxSR_BRK(port)) {
291
292 /* Break into the debugger if a break is detected */
293 BREAKPOINT();
294
295 /* Clear */
296 sci_out(port, SCxSR, SCxSR_BREAK_CLEAR(port));
297 }
298}
299
300#endif /* CONFIG_SH_KGDB */ 220#endif /* CONFIG_SH_KGDB */
301 221
302#if defined(__H8300S__) 222#if defined(__H8300S__)
303enum { sci_disable, sci_enable }; 223enum { sci_disable, sci_enable };
304 224
305static void h8300_sci_enable(struct uart_port* port, unsigned int ctrl) 225static void h8300_sci_config(struct uart_port* port, unsigned int ctrl)
306{ 226{
307 volatile unsigned char *mstpcrl=(volatile unsigned char *)MSTPCRL; 227 volatile unsigned char *mstpcrl=(volatile unsigned char *)MSTPCRL;
308 int ch = (port->mapbase - SMR0) >> 3; 228 int ch = (port->mapbase - SMR0) >> 3;
@@ -314,32 +234,66 @@ static void h8300_sci_enable(struct uart_port* port, unsigned int ctrl)
314 *mstpcrl &= ~mask; 234 *mstpcrl &= ~mask;
315 } 235 }
316} 236}
237
238static inline void h8300_sci_enable(struct uart_port *port)
239{
240 h8300_sci_config(port, sci_enable);
241}
242
243static inline void h8300_sci_disable(struct uart_port *port)
244{
245 h8300_sci_config(port, sci_disable);
246}
317#endif 247#endif
318 248
319#if defined(SCI_ONLY) || defined(SCI_AND_SCIF) 249#if defined(SCI_ONLY) || defined(SCI_AND_SCIF) && \
320#if defined(__H8300H__) || defined(__H8300S__) 250 defined(__H8300H__) || defined(__H8300S__)
321static void sci_init_pins_sci(struct uart_port* port, unsigned int cflag) 251static void sci_init_pins_sci(struct uart_port* port, unsigned int cflag)
322{ 252{
323 int ch = (port->mapbase - SMR0) >> 3; 253 int ch = (port->mapbase - SMR0) >> 3;
324 254
325 /* set DDR regs */ 255 /* set DDR regs */
326 H8300_GPIO_DDR(h8300_sci_pins[ch].port,h8300_sci_pins[ch].rx,H8300_GPIO_INPUT); 256 H8300_GPIO_DDR(h8300_sci_pins[ch].port,
327 H8300_GPIO_DDR(h8300_sci_pins[ch].port,h8300_sci_pins[ch].tx,H8300_GPIO_OUTPUT); 257 h8300_sci_pins[ch].rx,
258 H8300_GPIO_INPUT);
259 H8300_GPIO_DDR(h8300_sci_pins[ch].port,
260 h8300_sci_pins[ch].tx,
261 H8300_GPIO_OUTPUT);
262
328 /* tx mark output*/ 263 /* tx mark output*/
329 H8300_SCI_DR(ch) |= h8300_sci_pins[ch].tx; 264 H8300_SCI_DR(ch) |= h8300_sci_pins[ch].tx;
330} 265}
266#else
267#define sci_init_pins_sci NULL
268#endif
269
270#if defined(CONFIG_CPU_SUBTYPE_SH7707) || defined(CONFIG_CPU_SUBTYPE_SH7709)
271static void sci_init_pins_irda(struct uart_port *port, unsigned int cflag)
272{
273 unsigned int fcr_val = 0;
274
275 if (cflag & CRTSCTS)
276 fcr_val |= SCFCR_MCE;
277
278 sci_out(port, SCFCR, fcr_val);
279}
280#else
281#define sci_init_pins_irda NULL
331#endif 282#endif
283
284#ifdef SCI_ONLY
285#define sci_init_pins_scif NULL
332#endif 286#endif
333 287
334#if defined(SCIF_ONLY) || defined(SCI_AND_SCIF) 288#if defined(SCIF_ONLY) || defined(SCI_AND_SCIF)
335#if defined(CONFIG_CPU_SUBTYPE_SH7300) 289#if defined(CONFIG_CPU_SUBTYPE_SH7300) || defined(CONFIG_CPU_SUBTYPE_SH7710)
336/* SH7300 doesn't use RTS/CTS */ 290/* SH7300 doesn't use RTS/CTS */
337static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag) 291static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag)
338{ 292{
339 sci_out(port, SCFCR, 0); 293 sci_out(port, SCFCR, 0);
340} 294}
341#elif defined(CONFIG_CPU_SH3) 295#elif defined(CONFIG_CPU_SH3)
342/* For SH7705, SH7707, SH7709, SH7709A, SH7729 */ 296/* For SH7705, SH7706, SH7707, SH7709, SH7709A, SH7729 */
343static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag) 297static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag)
344{ 298{
345 unsigned int fcr_val = 0; 299 unsigned int fcr_val = 0;
@@ -366,20 +320,7 @@ static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag)
366 320
367 sci_out(port, SCFCR, fcr_val); 321 sci_out(port, SCFCR, fcr_val);
368} 322}
369
370#if defined(CONFIG_CPU_SUBTYPE_SH7707) || defined(CONFIG_CPU_SUBTYPE_SH7709)
371static void sci_init_pins_irda(struct uart_port *port, unsigned int cflag)
372{
373 unsigned int fcr_val = 0;
374
375 if (cflag & CRTSCTS)
376 fcr_val |= SCFCR_MCE;
377
378 sci_out(port, SCFCR, fcr_val);
379}
380#endif
381#else 323#else
382
383/* For SH7750 */ 324/* For SH7750 */
384static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag) 325static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag)
385{ 326{
@@ -388,7 +329,9 @@ static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag)
388 if (cflag & CRTSCTS) { 329 if (cflag & CRTSCTS) {
389 fcr_val |= SCFCR_MCE; 330 fcr_val |= SCFCR_MCE;
390 } else { 331 } else {
391#ifdef CONFIG_CPU_SUBTYPE_SH7780 332#ifdef CONFIG_CPU_SUBTYPE_SH7343
333 /* Nothing */
334#elif defined(CONFIG_CPU_SUBTYPE_SH7780)
392 ctrl_outw(0x0080, SCSPTR0); /* Set RTS = 1 */ 335 ctrl_outw(0x0080, SCSPTR0); /* Set RTS = 1 */
393#else 336#else
394 ctrl_outw(0x0080, SCSPTR2); /* Set RTS = 1 */ 337 ctrl_outw(0x0080, SCSPTR2); /* Set RTS = 1 */
@@ -396,10 +339,41 @@ static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag)
396 } 339 }
397 sci_out(port, SCFCR, fcr_val); 340 sci_out(port, SCFCR, fcr_val);
398} 341}
342#endif
343
344#if defined(CONFIG_CPU_SUBTYPE_SH7760) || defined(CONFIG_CPU_SUBTYPE_SH7780)
345static inline int scif_txroom(struct uart_port *port)
346{
347 return SCIF_TXROOM_MAX - (sci_in(port, SCTFDR) & 0x7f);
348}
349
350static inline int scif_rxroom(struct uart_port *port)
351{
352 return sci_in(port, SCRFDR) & 0x7f;
353}
354#else
355static inline int scif_txroom(struct uart_port *port)
356{
357 return SCIF_TXROOM_MAX - (sci_in(port, SCFDR) >> 8);
358}
399 359
360static inline int scif_rxroom(struct uart_port *port)
361{
362 return sci_in(port, SCFDR) & SCIF_RFDC_MASK;
363}
400#endif 364#endif
401#endif /* SCIF_ONLY || SCI_AND_SCIF */ 365#endif /* SCIF_ONLY || SCI_AND_SCIF */
402 366
367static inline int sci_txroom(struct uart_port *port)
368{
369 return ((sci_in(port, SCxSR) & SCI_TDRE) != 0);
370}
371
372static inline int sci_rxroom(struct uart_port *port)
373{
374 return ((sci_in(port, SCxSR) & SCxSR_RDxF(port)) != 0);
375}
376
403/* ********************************************************************** * 377/* ********************************************************************** *
404 * the interrupt related routines * 378 * the interrupt related routines *
405 * ********************************************************************** */ 379 * ********************************************************************** */
@@ -408,14 +382,12 @@ static void sci_transmit_chars(struct uart_port *port)
408{ 382{
409 struct circ_buf *xmit = &port->info->xmit; 383 struct circ_buf *xmit = &port->info->xmit;
410 unsigned int stopped = uart_tx_stopped(port); 384 unsigned int stopped = uart_tx_stopped(port);
411 unsigned long flags;
412 unsigned short status; 385 unsigned short status;
413 unsigned short ctrl; 386 unsigned short ctrl;
414 int count, txroom; 387 int count;
415 388
416 status = sci_in(port, SCxSR); 389 status = sci_in(port, SCxSR);
417 if (!(status & SCxSR_TDxE(port))) { 390 if (!(status & SCxSR_TDxE(port))) {
418 local_irq_save(flags);
419 ctrl = sci_in(port, SCSCR); 391 ctrl = sci_in(port, SCSCR);
420 if (uart_circ_empty(xmit)) { 392 if (uart_circ_empty(xmit)) {
421 ctrl &= ~SCI_CTRL_FLAGS_TIE; 393 ctrl &= ~SCI_CTRL_FLAGS_TIE;
@@ -423,25 +395,15 @@ static void sci_transmit_chars(struct uart_port *port)
423 ctrl |= SCI_CTRL_FLAGS_TIE; 395 ctrl |= SCI_CTRL_FLAGS_TIE;
424 } 396 }
425 sci_out(port, SCSCR, ctrl); 397 sci_out(port, SCSCR, ctrl);
426 local_irq_restore(flags);
427 return; 398 return;
428 } 399 }
429 400
430#if !defined(SCI_ONLY) 401#ifndef SCI_ONLY
431 if (port->type == PORT_SCIF) { 402 if (port->type == PORT_SCIF)
432#if defined(CONFIG_CPU_SUBTYPE_SH7760) || defined(CONFIG_CPU_SUBTYPE_SH7780) 403 count = scif_txroom(port);
433 txroom = SCIF_TXROOM_MAX - (sci_in(port, SCTFDR) & 0x7f); 404 else
434#else
435 txroom = SCIF_TXROOM_MAX - (sci_in(port, SCFDR)>>8);
436#endif
437 } else {
438 txroom = (sci_in(port, SCxSR) & SCI_TDRE)?1:0;
439 }
440#else
441 txroom = (sci_in(port, SCxSR) & SCI_TDRE)?1:0;
442#endif 405#endif
443 406 count = sci_txroom(port);
444 count = txroom;
445 407
446 do { 408 do {
447 unsigned char c; 409 unsigned char c;
@@ -468,7 +430,6 @@ static void sci_transmit_chars(struct uart_port *port)
468 if (uart_circ_empty(xmit)) { 430 if (uart_circ_empty(xmit)) {
469 sci_stop_tx(port); 431 sci_stop_tx(port);
470 } else { 432 } else {
471 local_irq_save(flags);
472 ctrl = sci_in(port, SCSCR); 433 ctrl = sci_in(port, SCSCR);
473 434
474#if !defined(SCI_ONLY) 435#if !defined(SCI_ONLY)
@@ -480,7 +441,6 @@ static void sci_transmit_chars(struct uart_port *port)
480 441
481 ctrl |= SCI_CTRL_FLAGS_TIE; 442 ctrl |= SCI_CTRL_FLAGS_TIE;
482 sci_out(port, SCSCR, ctrl); 443 sci_out(port, SCSCR, ctrl);
483 local_irq_restore(flags);
484 } 444 }
485} 445}
486 446
@@ -490,6 +450,7 @@ static void sci_transmit_chars(struct uart_port *port)
490static inline void sci_receive_chars(struct uart_port *port, 450static inline void sci_receive_chars(struct uart_port *port,
491 struct pt_regs *regs) 451 struct pt_regs *regs)
492{ 452{
453 struct sci_port *sci_port = (struct sci_port *)port;
493 struct tty_struct *tty = port->info->tty; 454 struct tty_struct *tty = port->info->tty;
494 int i, count, copied = 0; 455 int i, count, copied = 0;
495 unsigned short status; 456 unsigned short status;
@@ -501,18 +462,11 @@ static inline void sci_receive_chars(struct uart_port *port,
501 462
502 while (1) { 463 while (1) {
503#if !defined(SCI_ONLY) 464#if !defined(SCI_ONLY)
504 if (port->type == PORT_SCIF) { 465 if (port->type == PORT_SCIF)
505#if defined(CONFIG_CPU_SUBTYPE_SH7760) || defined(CONFIG_CPU_SUBTYPE_SH7780) 466 count = scif_rxroom(port);
506 count = sci_in(port, SCRFDR) & 0x7f; 467 else
507#else
508 count = sci_in(port, SCFDR)&SCIF_RFDC_MASK ;
509#endif
510 } else {
511 count = (sci_in(port, SCxSR)&SCxSR_RDxF(port))?1:0;
512 }
513#else
514 count = (sci_in(port, SCxSR)&SCxSR_RDxF(port))?1:0;
515#endif 468#endif
469 count = sci_rxroom(port);
516 470
517 /* Don't copy more bytes than there is room for in the buffer */ 471 /* Don't copy more bytes than there is room for in the buffer */
518 count = tty_buffer_request_room(tty, count); 472 count = tty_buffer_request_room(tty, count);
@@ -523,11 +477,10 @@ static inline void sci_receive_chars(struct uart_port *port,
523 477
524 if (port->type == PORT_SCI) { 478 if (port->type == PORT_SCI) {
525 char c = sci_in(port, SCxRDR); 479 char c = sci_in(port, SCxRDR);
526 if(((struct sci_port *)port)->break_flag 480 if (uart_handle_sysrq_char(port, c, regs) || sci_port->break_flag)
527 || uart_handle_sysrq_char(port, c, regs)) {
528 count = 0; 481 count = 0;
529 } else { 482 else {
530 tty_insert_flip_char(tty, c, TTY_NORMAL); 483 tty_insert_flip_char(tty, c, TTY_NORMAL);
531 } 484 }
532 } else { 485 } else {
533 for (i=0; i<count; i++) { 486 for (i=0; i<count; i++) {
@@ -535,15 +488,17 @@ static inline void sci_receive_chars(struct uart_port *port,
535 status = sci_in(port, SCxSR); 488 status = sci_in(port, SCxSR);
536#if defined(CONFIG_CPU_SH3) 489#if defined(CONFIG_CPU_SH3)
537 /* Skip "chars" during break */ 490 /* Skip "chars" during break */
538 if (((struct sci_port *)port)->break_flag) { 491 if (sci_port->break_flag) {
539 if ((c == 0) && 492 if ((c == 0) &&
540 (status & SCxSR_FER(port))) { 493 (status & SCxSR_FER(port))) {
541 count--; i--; 494 count--; i--;
542 continue; 495 continue;
543 } 496 }
497
544 /* Nonzero => end-of-break */ 498 /* Nonzero => end-of-break */
545 pr_debug("scif: debounce<%02x>\n", c); 499 pr_debug("scif: debounce<%02x>\n", c);
546 ((struct sci_port *)port)->break_flag = 0; 500 sci_port->break_flag = 0;
501
547 if (STEPFN(c)) { 502 if (STEPFN(c)) {
548 count--; i--; 503 count--; i--;
549 continue; 504 continue;
@@ -600,15 +555,17 @@ static void sci_schedule_break_timer(struct sci_port *port)
600/* Ensure that two consecutive samples find the break over. */ 555/* Ensure that two consecutive samples find the break over. */
601static void sci_break_timer(unsigned long data) 556static void sci_break_timer(unsigned long data)
602{ 557{
603 struct sci_port * port = (struct sci_port *)data; 558 struct sci_port *port = (struct sci_port *)data;
604 if(sci_rxd_in(&port->port) == 0) { 559
560 if (sci_rxd_in(&port->port) == 0) {
605 port->break_flag = 1; 561 port->break_flag = 1;
606 sci_schedule_break_timer(port); 562 sci_schedule_break_timer(port);
607 } else if(port->break_flag == 1){ 563 } else if (port->break_flag == 1) {
608 /* break is over. */ 564 /* break is over. */
609 port->break_flag = 2; 565 port->break_flag = 2;
610 sci_schedule_break_timer(port); 566 sci_schedule_break_timer(port);
611 } else port->break_flag = 0; 567 } else
568 port->break_flag = 0;
612} 569}
613 570
614static inline int sci_handle_errors(struct uart_port *port) 571static inline int sci_handle_errors(struct uart_port *port)
@@ -617,40 +574,41 @@ static inline int sci_handle_errors(struct uart_port *port)
617 unsigned short status = sci_in(port, SCxSR); 574 unsigned short status = sci_in(port, SCxSR);
618 struct tty_struct *tty = port->info->tty; 575 struct tty_struct *tty = port->info->tty;
619 576
620 if (status&SCxSR_ORER(port)) { 577 if (status & SCxSR_ORER(port)) {
621 /* overrun error */ 578 /* overrun error */
622 if(tty_insert_flip_char(tty, 0, TTY_OVERRUN)) 579 if (tty_insert_flip_char(tty, 0, TTY_OVERRUN))
623 copied++; 580 copied++;
624 pr_debug("sci: overrun error\n"); 581 pr_debug("sci: overrun error\n");
625 } 582 }
626 583
627 if (status&SCxSR_FER(port)) { 584 if (status & SCxSR_FER(port)) {
628 if (sci_rxd_in(port) == 0) { 585 if (sci_rxd_in(port) == 0) {
629 /* Notify of BREAK */ 586 /* Notify of BREAK */
630 struct sci_port * sci_port = (struct sci_port *)port; 587 struct sci_port *sci_port = (struct sci_port *)port;
631 if(!sci_port->break_flag) { 588
632 sci_port->break_flag = 1; 589 if (!sci_port->break_flag) {
633 sci_schedule_break_timer((struct sci_port *)port); 590 sci_port->break_flag = 1;
591 sci_schedule_break_timer(sci_port);
592
634 /* Do sysrq handling. */ 593 /* Do sysrq handling. */
635 if(uart_handle_break(port)) 594 if (uart_handle_break(port))
636 return 0; 595 return 0;
637 pr_debug("sci: BREAK detected\n"); 596 pr_debug("sci: BREAK detected\n");
638 if(tty_insert_flip_char(tty, 0, TTY_BREAK)) 597 if (tty_insert_flip_char(tty, 0, TTY_BREAK))
639 copied++; 598 copied++;
640 } 599 }
641 } 600 } else {
642 else {
643 /* frame error */ 601 /* frame error */
644 if(tty_insert_flip_char(tty, 0, TTY_FRAME)) 602 if (tty_insert_flip_char(tty, 0, TTY_FRAME))
645 copied++; 603 copied++;
646 pr_debug("sci: frame error\n"); 604 pr_debug("sci: frame error\n");
647 } 605 }
648 } 606 }
649 607
650 if (status&SCxSR_PER(port)) { 608 if (status & SCxSR_PER(port)) {
651 if(tty_insert_flip_char(tty, 0, TTY_PARITY))
652 copied++;
653 /* parity error */ 609 /* parity error */
610 if (tty_insert_flip_char(tty, 0, TTY_PARITY))
611 copied++;
654 pr_debug("sci: parity error\n"); 612 pr_debug("sci: parity error\n");
655 } 613 }
656 614
@@ -673,7 +631,7 @@ static inline int sci_handle_breaks(struct uart_port *port)
673 s->break_flag = 1; 631 s->break_flag = 1;
674#endif 632#endif
675 /* Notify of BREAK */ 633 /* Notify of BREAK */
676 if(tty_insert_flip_char(tty, 0, TTY_BREAK)) 634 if (tty_insert_flip_char(tty, 0, TTY_BREAK))
677 copied++; 635 copied++;
678 pr_debug("sci: BREAK detected\n"); 636 pr_debug("sci: BREAK detected\n");
679 } 637 }
@@ -682,7 +640,7 @@ static inline int sci_handle_breaks(struct uart_port *port)
682 /* XXX: Handle SCIF overrun error */ 640 /* XXX: Handle SCIF overrun error */
683 if (port->type == PORT_SCIF && (sci_in(port, SCLSR) & SCIF_ORER) != 0) { 641 if (port->type == PORT_SCIF && (sci_in(port, SCLSR) & SCIF_ORER) != 0) {
684 sci_out(port, SCLSR, 0); 642 sci_out(port, SCLSR, 0);
685 if(tty_insert_flip_char(tty, 0, TTY_OVERRUN)) { 643 if (tty_insert_flip_char(tty, 0, TTY_OVERRUN)) {
686 copied++; 644 copied++;
687 pr_debug("sci: overrun error\n"); 645 pr_debug("sci: overrun error\n");
688 } 646 }
@@ -691,13 +649,12 @@ static inline int sci_handle_breaks(struct uart_port *port)
691 649
692 if (copied) 650 if (copied)
693 tty_flip_buffer_push(tty); 651 tty_flip_buffer_push(tty);
652
694 return copied; 653 return copied;
695} 654}
696 655
697static irqreturn_t sci_rx_interrupt(int irq, void *ptr, struct pt_regs *regs) 656static irqreturn_t sci_rx_interrupt(int irq, void *port, struct pt_regs *regs)
698{ 657{
699 struct uart_port *port = ptr;
700
701 /* I think sci_receive_chars has to be called irrespective 658 /* I think sci_receive_chars has to be called irrespective
702 * of whether the I_IXOFF is set, otherwise, how is the interrupt 659 * of whether the I_IXOFF is set, otherwise, how is the interrupt
703 * to be disabled? 660 * to be disabled?
@@ -711,7 +668,9 @@ static irqreturn_t sci_tx_interrupt(int irq, void *ptr, struct pt_regs *regs)
711{ 668{
712 struct uart_port *port = ptr; 669 struct uart_port *port = ptr;
713 670
671 spin_lock_irq(&port->lock);
714 sci_transmit_chars(port); 672 sci_transmit_chars(port);
673 spin_unlock_irq(&port->lock);
715 674
716 return IRQ_HANDLED; 675 return IRQ_HANDLED;
717} 676}
@@ -755,6 +714,12 @@ static irqreturn_t sci_br_interrupt(int irq, void *ptr, struct pt_regs *regs)
755 714
756 /* Handle BREAKs */ 715 /* Handle BREAKs */
757 sci_handle_breaks(port); 716 sci_handle_breaks(port);
717
718#ifdef CONFIG_SH_KGDB
719 /* Break into the debugger if a break is detected */
720 BREAKPOINT();
721#endif
722
758 sci_out(port, SCxSR, SCxSR_BREAK_CLEAR(port)); 723 sci_out(port, SCxSR, SCxSR_BREAK_CLEAR(port));
759 724
760 return IRQ_HANDLED; 725 return IRQ_HANDLED;
@@ -769,16 +734,16 @@ static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr, struct pt_regs *regs)
769 scr_status = sci_in(port,SCSCR); 734 scr_status = sci_in(port,SCSCR);
770 735
771 /* Tx Interrupt */ 736 /* Tx Interrupt */
772 if ((ssr_status&0x0020) && (scr_status&0x0080)) 737 if ((ssr_status & 0x0020) && (scr_status & 0x0080))
773 sci_tx_interrupt(irq, ptr, regs); 738 sci_tx_interrupt(irq, ptr, regs);
774 /* Rx Interrupt */ 739 /* Rx Interrupt */
775 if ((ssr_status&0x0002) && (scr_status&0x0040)) 740 if ((ssr_status & 0x0002) && (scr_status & 0x0040))
776 sci_rx_interrupt(irq, ptr, regs); 741 sci_rx_interrupt(irq, ptr, regs);
777 /* Error Interrupt */ 742 /* Error Interrupt */
778 if ((ssr_status&0x0080) && (scr_status&0x0400)) 743 if ((ssr_status & 0x0080) && (scr_status & 0x0400))
779 sci_er_interrupt(irq, ptr, regs); 744 sci_er_interrupt(irq, ptr, regs);
780 /* Break Interrupt */ 745 /* Break Interrupt */
781 if ((ssr_status&0x0010) && (scr_status&0x0200)) 746 if ((ssr_status & 0x0010) && (scr_status & 0x0200))
782 sci_br_interrupt(irq, ptr, regs); 747 sci_br_interrupt(irq, ptr, regs);
783 748
784 return IRQ_HANDLED; 749 return IRQ_HANDLED;
@@ -789,7 +754,8 @@ static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr, struct pt_regs *regs)
789 * Here we define a transistion notifier so that we can update all of our 754 * Here we define a transistion notifier so that we can update all of our
790 * ports' baud rate when the peripheral clock changes. 755 * ports' baud rate when the peripheral clock changes.
791 */ 756 */
792static int sci_notifier(struct notifier_block *self, unsigned long phase, void *p) 757static int sci_notifier(struct notifier_block *self,
758 unsigned long phase, void *p)
793{ 759{
794 struct cpufreq_freqs *freqs = p; 760 struct cpufreq_freqs *freqs = p;
795 int i; 761 int i;
@@ -816,8 +782,9 @@ static int sci_notifier(struct notifier_block *self, unsigned long phase, void *
816 clk_put(clk); 782 clk_put(clk);
817 } 783 }
818 784
819 printk("%s: got a postchange notification for cpu %d (old %d, new %d)\n", 785 printk(KERN_INFO "%s: got a postchange notification "
820 __FUNCTION__, freqs->cpu, freqs->old, freqs->new); 786 "for cpu %d (old %d, new %d)\n",
787 __FUNCTION__, freqs->cpu, freqs->old, freqs->new);
821 } 788 }
822 789
823 return NOTIFY_OK; 790 return NOTIFY_OK;
@@ -841,8 +808,9 @@ static int sci_request_irq(struct sci_port *port)
841 printk(KERN_ERR "sci: Cannot allocate irq.(IRQ=0)\n"); 808 printk(KERN_ERR "sci: Cannot allocate irq.(IRQ=0)\n");
842 return -ENODEV; 809 return -ENODEV;
843 } 810 }
844 if (request_irq(port->irqs[0], sci_mpxed_interrupt, IRQF_DISABLED, 811
845 "sci", port)) { 812 if (request_irq(port->irqs[0], sci_mpxed_interrupt,
813 SA_INTERRUPT, "sci", port)) {
846 printk(KERN_ERR "sci: Cannot allocate irq.\n"); 814 printk(KERN_ERR "sci: Cannot allocate irq.\n");
847 return -ENODEV; 815 return -ENODEV;
848 } 816 }
@@ -850,8 +818,8 @@ static int sci_request_irq(struct sci_port *port)
850 for (i = 0; i < ARRAY_SIZE(handlers); i++) { 818 for (i = 0; i < ARRAY_SIZE(handlers); i++) {
851 if (!port->irqs[i]) 819 if (!port->irqs[i])
852 continue; 820 continue;
853 if (request_irq(port->irqs[i], handlers[i], IRQF_DISABLED, 821 if (request_irq(port->irqs[i], handlers[i],
854 desc[i], port)) { 822 SA_INTERRUPT, desc[i], port)) {
855 printk(KERN_ERR "sci: Cannot allocate irq.\n"); 823 printk(KERN_ERR "sci: Cannot allocate irq.\n");
856 return -ENODEV; 824 return -ENODEV;
857 } 825 }
@@ -903,50 +871,42 @@ static unsigned int sci_get_mctrl(struct uart_port *port)
903 871
904static void sci_start_tx(struct uart_port *port) 872static void sci_start_tx(struct uart_port *port)
905{ 873{
906 struct sci_port *s = &sci_ports[port->line]; 874 unsigned short ctrl;
907 875
908 disable_irq(s->irqs[SCIx_TXI_IRQ]); 876 /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */
909 sci_transmit_chars(port); 877 ctrl = sci_in(port, SCSCR);
910 enable_irq(s->irqs[SCIx_TXI_IRQ]); 878 ctrl |= SCI_CTRL_FLAGS_TIE;
879 sci_out(port, SCSCR, ctrl);
911} 880}
912 881
913static void sci_stop_tx(struct uart_port *port) 882static void sci_stop_tx(struct uart_port *port)
914{ 883{
915 unsigned long flags;
916 unsigned short ctrl; 884 unsigned short ctrl;
917 885
918 /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */ 886 /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */
919 local_irq_save(flags);
920 ctrl = sci_in(port, SCSCR); 887 ctrl = sci_in(port, SCSCR);
921 ctrl &= ~SCI_CTRL_FLAGS_TIE; 888 ctrl &= ~SCI_CTRL_FLAGS_TIE;
922 sci_out(port, SCSCR, ctrl); 889 sci_out(port, SCSCR, ctrl);
923 local_irq_restore(flags);
924} 890}
925 891
926static void sci_start_rx(struct uart_port *port, unsigned int tty_start) 892static void sci_start_rx(struct uart_port *port, unsigned int tty_start)
927{ 893{
928 unsigned long flags;
929 unsigned short ctrl; 894 unsigned short ctrl;
930 895
931 /* Set RIE (Receive Interrupt Enable) bit in SCSCR */ 896 /* Set RIE (Receive Interrupt Enable) bit in SCSCR */
932 local_irq_save(flags);
933 ctrl = sci_in(port, SCSCR); 897 ctrl = sci_in(port, SCSCR);
934 ctrl |= SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE; 898 ctrl |= SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE;
935 sci_out(port, SCSCR, ctrl); 899 sci_out(port, SCSCR, ctrl);
936 local_irq_restore(flags);
937} 900}
938 901
939static void sci_stop_rx(struct uart_port *port) 902static void sci_stop_rx(struct uart_port *port)
940{ 903{
941 unsigned long flags;
942 unsigned short ctrl; 904 unsigned short ctrl;
943 905
944 /* Clear RIE (Receive Interrupt Enable) bit in SCSCR */ 906 /* Clear RIE (Receive Interrupt Enable) bit in SCSCR */
945 local_irq_save(flags);
946 ctrl = sci_in(port, SCSCR); 907 ctrl = sci_in(port, SCSCR);
947 ctrl &= ~(SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE); 908 ctrl &= ~(SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE);
948 sci_out(port, SCSCR, ctrl); 909 sci_out(port, SCSCR, ctrl);
949 local_irq_restore(flags);
950} 910}
951 911
952static void sci_enable_ms(struct uart_port *port) 912static void sci_enable_ms(struct uart_port *port)
@@ -963,9 +923,8 @@ static int sci_startup(struct uart_port *port)
963{ 923{
964 struct sci_port *s = &sci_ports[port->line]; 924 struct sci_port *s = &sci_ports[port->line];
965 925
966#if defined(__H8300S__) 926 if (s->enable)
967 h8300_sci_enable(port, sci_enable); 927 s->enable(port);
968#endif
969 928
970 sci_request_irq(s); 929 sci_request_irq(s);
971 sci_start_tx(port); 930 sci_start_tx(port);
@@ -982,9 +941,8 @@ static void sci_shutdown(struct uart_port *port)
982 sci_stop_tx(port); 941 sci_stop_tx(port);
983 sci_free_irq(s); 942 sci_free_irq(s);
984 943
985#if defined(__H8300S__) 944 if (s->disable)
986 h8300_sci_enable(port, sci_disable); 945 s->disable(port);
987#endif
988} 946}
989 947
990static void sci_set_termios(struct uart_port *port, struct termios *termios, 948static void sci_set_termios(struct uart_port *port, struct termios *termios,
@@ -997,6 +955,23 @@ static void sci_set_termios(struct uart_port *port, struct termios *termios,
997 955
998 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); 956 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
999 957
958 switch (baud) {
959 case 0:
960 t = -1;
961 break;
962 default:
963 {
964#if defined(CONFIG_SUPERH) && !defined(CONFIG_SUPERH64)
965 struct clk *clk = clk_get("module_clk");
966 t = SCBRR_VALUE(baud, clk_get_rate(clk));
967 clk_put(clk);
968#else
969 t = SCBRR_VALUE(baud);
970#endif
971 }
972 break;
973 }
974
1000 spin_lock_irqsave(&port->lock, flags); 975 spin_lock_irqsave(&port->lock, flags);
1001 976
1002 do { 977 do {
@@ -1006,9 +981,8 @@ static void sci_set_termios(struct uart_port *port, struct termios *termios,
1006 sci_out(port, SCSCR, 0x00); /* TE=0, RE=0, CKE1=0 */ 981 sci_out(port, SCSCR, 0x00); /* TE=0, RE=0, CKE1=0 */
1007 982
1008#if !defined(SCI_ONLY) 983#if !defined(SCI_ONLY)
1009 if (port->type == PORT_SCIF) { 984 if (port->type == PORT_SCIF)
1010 sci_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST); 985 sci_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST);
1011 }
1012#endif 986#endif
1013 987
1014 smr_val = sci_in(port, SCSMR) & 3; 988 smr_val = sci_in(port, SCSMR) & 3;
@@ -1025,23 +999,6 @@ static void sci_set_termios(struct uart_port *port, struct termios *termios,
1025 999
1026 sci_out(port, SCSMR, smr_val); 1000 sci_out(port, SCSMR, smr_val);
1027 1001
1028 switch (baud) {
1029 case 0:
1030 t = -1;
1031 break;
1032 default:
1033 {
1034#if defined(CONFIG_SUPERH) && !defined(CONFIG_SUPERH64)
1035 struct clk *clk = clk_get("module_clk");
1036 t = SCBRR_VALUE(baud, clk_get_rate(clk));
1037 clk_put(clk);
1038#else
1039 t = SCBRR_VALUE(baud);
1040#endif
1041 }
1042 break;
1043 }
1044
1045 if (t > 0) { 1002 if (t > 0) {
1046 if(t >= 256) { 1003 if(t >= 256) {
1047 sci_out(port, SCSMR, (sci_in(port, SCSMR) & ~3) | 1); 1004 sci_out(port, SCSMR, (sci_in(port, SCSMR) & ~3) | 1);
@@ -1092,11 +1049,23 @@ static void sci_config_port(struct uart_port *port, int flags)
1092 1049
1093 port->type = s->type; 1050 port->type = s->type;
1094 1051
1052 switch (port->type) {
1053 case PORT_SCI:
1054 s->init_pins = sci_init_pins_sci;
1055 break;
1056 case PORT_SCIF:
1057 s->init_pins = sci_init_pins_scif;
1058 break;
1059 case PORT_IRDA:
1060 s->init_pins = sci_init_pins_irda;
1061 break;
1062 }
1063
1095#if defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103) 1064#if defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
1096 if (port->mapbase == 0) 1065 if (port->mapbase == 0)
1097 port->mapbase = onchip_remap(SCIF_ADDR_SH5, 1024, "SCIF"); 1066 port->mapbase = onchip_remap(SCIF_ADDR_SH5, 1024, "SCIF");
1098 1067
1099 port->membase = (void *)port->mapbase; 1068 port->membase = (void __iomem *)port->mapbase;
1100#endif 1069#endif
1101} 1070}
1102 1071
@@ -1132,412 +1101,61 @@ static struct uart_ops sci_uart_ops = {
1132 .verify_port = sci_verify_port, 1101 .verify_port = sci_verify_port,
1133}; 1102};
1134 1103
1135static struct sci_port sci_ports[] = { 1104static void __init sci_init_ports(void)
1136#if defined(CONFIG_CPU_SUBTYPE_SH7708) 1105{
1137 { 1106 static int first = 1;
1138 .port = { 1107 int i;
1139 .membase = (void *)0xfffffe80, 1108
1140 .mapbase = 0xfffffe80, 1109 if (!first)
1141 .iotype = UPIO_MEM, 1110 return;
1142 .irq = 25, 1111
1143 .ops = &sci_uart_ops, 1112 first = 0;
1144 .flags = UPF_BOOT_AUTOCONF, 1113
1145 .line = 0, 1114 for (i = 0; i < SCI_NPORTS; i++) {
1146 }, 1115 sci_ports[i].port.ops = &sci_uart_ops;
1147 .type = PORT_SCI, 1116 sci_ports[i].port.iotype = UPIO_MEM;
1148 .irqs = SCI_IRQS, 1117 sci_ports[i].port.line = i;
1149 }, 1118 sci_ports[i].port.fifosize = 1;
1150#elif defined(CONFIG_CPU_SUBTYPE_SH7705) 1119
1151 { 1120#if defined(__H8300H__) || defined(__H8300S__)
1152 .port = { 1121#ifdef __H8300S__
1153 .membase = (void *)SCIF0, 1122 sci_ports[i].enable = h8300_sci_enable;
1154 .mapbase = SCIF0, 1123 sci_ports[i].disable = h8300_sci_disable;
1155 .iotype = UPIO_MEM, 1124#endif
1156 .irq = 55, 1125 sci_ports[i].port.uartclk = CONFIG_CPU_CLOCK;
1157 .ops = &sci_uart_ops, 1126#elif defined(CONFIG_SUPERH64)
1158 .flags = UPF_BOOT_AUTOCONF, 1127 sci_ports[i].port.uartclk = current_cpu_data.module_clock * 16;
1159 .line = 0,
1160 },
1161 .type = PORT_SCIF,
1162 .irqs = SH3_IRDA_IRQS,
1163 .init_pins = sci_init_pins_scif,
1164 },
1165 {
1166 .port = {
1167 .membase = (void *)SCIF2,
1168 .mapbase = SCIF2,
1169 .iotype = UPIO_MEM,
1170 .irq = 59,
1171 .ops = &sci_uart_ops,
1172 .flags = UPF_BOOT_AUTOCONF,
1173 .line = 1,
1174 },
1175 .type = PORT_SCIF,
1176 .irqs = SH3_SCIF_IRQS,
1177 .init_pins = sci_init_pins_scif,
1178 }
1179#elif defined(CONFIG_CPU_SUBTYPE_SH7707) || defined(CONFIG_CPU_SUBTYPE_SH7709)
1180 {
1181 .port = {
1182 .membase = (void *)0xfffffe80,
1183 .mapbase = 0xfffffe80,
1184 .iotype = UPIO_MEM,
1185 .irq = 25,
1186 .ops = &sci_uart_ops,
1187 .flags = UPF_BOOT_AUTOCONF,
1188 .line = 0,
1189 },
1190 .type = PORT_SCI,
1191 .irqs = SCI_IRQS,
1192 },
1193 {
1194 .port = {
1195 .membase = (void *)0xa4000150,
1196 .mapbase = 0xa4000150,
1197 .iotype = UPIO_MEM,
1198 .irq = 59,
1199 .ops = &sci_uart_ops,
1200 .flags = UPF_BOOT_AUTOCONF,
1201 .line = 1,
1202 },
1203 .type = PORT_SCIF,
1204 .irqs = SH3_SCIF_IRQS,
1205 .init_pins = sci_init_pins_scif,
1206 },
1207 {
1208 .port = {
1209 .membase = (void *)0xa4000140,
1210 .mapbase = 0xa4000140,
1211 .iotype = UPIO_MEM,
1212 .irq = 55,
1213 .ops = &sci_uart_ops,
1214 .flags = UPF_BOOT_AUTOCONF,
1215 .line = 2,
1216 },
1217 .type = PORT_IRDA,
1218 .irqs = SH3_IRDA_IRQS,
1219 .init_pins = sci_init_pins_irda,
1220 }
1221#elif defined(CONFIG_CPU_SUBTYPE_SH7300)
1222 {
1223 .port = {
1224 .membase = (void *)0xA4430000,
1225 .mapbase = 0xA4430000,
1226 .iotype = UPIO_MEM,
1227 .irq = 25,
1228 .ops = &sci_uart_ops,
1229 .flags = UPF_BOOT_AUTOCONF,
1230 .line = 0,
1231 },
1232 .type = PORT_SCIF,
1233 .irqs = SH7300_SCIF0_IRQS,
1234 .init_pins = sci_init_pins_scif,
1235 },
1236#elif defined(CONFIG_CPU_SUBTYPE_SH73180)
1237 {
1238 .port = {
1239 .membase = (void *)0xffe00000,
1240 .mapbase = 0xffe00000,
1241 .iotype = UPIO_MEM,
1242 .irq = 25,
1243 .ops = &sci_uart_ops,
1244 .flags = UPF_BOOT_AUTOCONF,
1245 .line = 0,
1246 },
1247 .type = PORT_SCIF,
1248 .irqs = SH73180_SCIF_IRQS,
1249 .init_pins = sci_init_pins_scif,
1250 },
1251#elif defined(CONFIG_CPU_SUBTYPE_SH4_202)
1252 {
1253 .port = {
1254 .membase = (void *)0xffe80000,
1255 .mapbase = 0xffe80000,
1256 .iotype = UPIO_MEM,
1257 .irq = 43,
1258 .ops = &sci_uart_ops,
1259 .flags = UPF_BOOT_AUTOCONF,
1260 .line = 0,
1261 },
1262 .type = PORT_SCIF,
1263 .irqs = SH4_SCIF_IRQS,
1264 .init_pins = sci_init_pins_scif,
1265 },
1266#elif defined(CONFIG_CPU_SUBTYPE_SH7750) || defined(CONFIG_CPU_SUBTYPE_SH7751)
1267 {
1268 .port = {
1269 .membase = (void *)0xffe00000,
1270 .mapbase = 0xffe00000,
1271 .iotype = UPIO_MEM,
1272 .irq = 25,
1273 .ops = &sci_uart_ops,
1274 .flags = UPF_BOOT_AUTOCONF,
1275 .line = 0,
1276 },
1277 .type = PORT_SCI,
1278 .irqs = SCI_IRQS,
1279 },
1280 {
1281 .port = {
1282 .membase = (void *)0xffe80000,
1283 .mapbase = 0xffe80000,
1284 .iotype = UPIO_MEM,
1285 .irq = 43,
1286 .ops = &sci_uart_ops,
1287 .flags = UPF_BOOT_AUTOCONF,
1288 .line = 1,
1289 },
1290 .type = PORT_SCIF,
1291 .irqs = SH4_SCIF_IRQS,
1292 .init_pins = sci_init_pins_scif,
1293 },
1294#elif defined(CONFIG_CPU_SUBTYPE_SH7760)
1295 {
1296 .port = {
1297 .membase = (void *)0xfe600000,
1298 .mapbase = 0xfe600000,
1299 .iotype = UPIO_MEM,
1300 .irq = 55,
1301 .ops = &sci_uart_ops,
1302 .flags = UPF_BOOT_AUTOCONF,
1303 .line = 0,
1304 },
1305 .type = PORT_SCIF,
1306 .irqs = SH7760_SCIF0_IRQS,
1307 .init_pins = sci_init_pins_scif,
1308 },
1309 {
1310 .port = {
1311 .membase = (void *)0xfe610000,
1312 .mapbase = 0xfe610000,
1313 .iotype = UPIO_MEM,
1314 .irq = 75,
1315 .ops = &sci_uart_ops,
1316 .flags = UPF_BOOT_AUTOCONF,
1317 .line = 1,
1318 },
1319 .type = PORT_SCIF,
1320 .irqs = SH7760_SCIF1_IRQS,
1321 .init_pins = sci_init_pins_scif,
1322 },
1323 {
1324 .port = {
1325 .membase = (void *)0xfe620000,
1326 .mapbase = 0xfe620000,
1327 .iotype = UPIO_MEM,
1328 .irq = 79,
1329 .ops = &sci_uart_ops,
1330 .flags = UPF_BOOT_AUTOCONF,
1331 .line = 2,
1332 },
1333 .type = PORT_SCIF,
1334 .irqs = SH7760_SCIF2_IRQS,
1335 .init_pins = sci_init_pins_scif,
1336 },
1337#elif defined(CONFIG_CPU_SUBTYPE_ST40STB1)
1338 {
1339 .port = {
1340 .membase = (void *)0xffe00000,
1341 .mapbase = 0xffe00000,
1342 .iotype = UPIO_MEM,
1343 .irq = 26,
1344 .ops = &sci_uart_ops,
1345 .flags = UPF_BOOT_AUTOCONF,
1346 .line = 0,
1347 },
1348 .type = PORT_SCIF,
1349 .irqs = STB1_SCIF1_IRQS,
1350 .init_pins = sci_init_pins_scif,
1351 },
1352 {
1353 .port = {
1354 .membase = (void *)0xffe80000,
1355 .mapbase = 0xffe80000,
1356 .iotype = UPIO_MEM,
1357 .irq = 43,
1358 .ops = &sci_uart_ops,
1359 .flags = UPF_BOOT_AUTOCONF,
1360 .line = 1,
1361 },
1362 .type = PORT_SCIF,
1363 .irqs = SH4_SCIF_IRQS,
1364 .init_pins = sci_init_pins_scif,
1365 },
1366#elif defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
1367 {
1368 .port = {
1369 .iotype = UPIO_MEM,
1370 .irq = 42,
1371 .ops = &sci_uart_ops,
1372 .flags = UPF_BOOT_AUTOCONF,
1373 .line = 0,
1374 },
1375 .type = PORT_SCIF,
1376 .irqs = SH5_SCIF_IRQS,
1377 .init_pins = sci_init_pins_scif,
1378 },
1379#elif defined(CONFIG_H83007) || defined(CONFIG_H83068)
1380 {
1381 .port = {
1382 .membase = (void *)0x00ffffb0,
1383 .mapbase = 0x00ffffb0,
1384 .iotype = UPIO_MEM,
1385 .irq = 54,
1386 .ops = &sci_uart_ops,
1387 .flags = UPF_BOOT_AUTOCONF,
1388 .line = 0,
1389 },
1390 .type = PORT_SCI,
1391 .irqs = H8300H_SCI_IRQS0,
1392 .init_pins = sci_init_pins_sci,
1393 },
1394 {
1395 .port = {
1396 .membase = (void *)0x00ffffb8,
1397 .mapbase = 0x00ffffb8,
1398 .iotype = UPIO_MEM,
1399 .irq = 58,
1400 .ops = &sci_uart_ops,
1401 .flags = UPF_BOOT_AUTOCONF,
1402 .line = 1,
1403 },
1404 .type = PORT_SCI,
1405 .irqs = H8300H_SCI_IRQS1,
1406 .init_pins = sci_init_pins_sci,
1407 },
1408 {
1409 .port = {
1410 .membase = (void *)0x00ffffc0,
1411 .mapbase = 0x00ffffc0,
1412 .iotype = UPIO_MEM,
1413 .irq = 62,
1414 .ops = &sci_uart_ops,
1415 .flags = UPF_BOOT_AUTOCONF,
1416 .line = 2,
1417 },
1418 .type = PORT_SCI,
1419 .irqs = H8300H_SCI_IRQS2,
1420 .init_pins = sci_init_pins_sci,
1421 },
1422#elif defined(CONFIG_H8S2678)
1423 {
1424 .port = {
1425 .membase = (void *)0x00ffff78,
1426 .mapbase = 0x00ffff78,
1427 .iotype = UPIO_MEM,
1428 .irq = 90,
1429 .ops = &sci_uart_ops,
1430 .flags = UPF_BOOT_AUTOCONF,
1431 .line = 0,
1432 },
1433 .type = PORT_SCI,
1434 .irqs = H8S_SCI_IRQS0,
1435 .init_pins = sci_init_pins_sci,
1436 },
1437 {
1438 .port = {
1439 .membase = (void *)0x00ffff80,
1440 .mapbase = 0x00ffff80,
1441 .iotype = UPIO_MEM,
1442 .irq = 94,
1443 .ops = &sci_uart_ops,
1444 .flags = UPF_BOOT_AUTOCONF,
1445 .line = 1,
1446 },
1447 .type = PORT_SCI,
1448 .irqs = H8S_SCI_IRQS1,
1449 .init_pins = sci_init_pins_sci,
1450 },
1451 {
1452 .port = {
1453 .membase = (void *)0x00ffff88,
1454 .mapbase = 0x00ffff88,
1455 .iotype = UPIO_MEM,
1456 .irq = 98,
1457 .ops = &sci_uart_ops,
1458 .flags = UPF_BOOT_AUTOCONF,
1459 .line = 2,
1460 },
1461 .type = PORT_SCI,
1462 .irqs = H8S_SCI_IRQS2,
1463 .init_pins = sci_init_pins_sci,
1464 },
1465#elif defined(CONFIG_CPU_SUBTYPE_SH7770)
1466 {
1467 .port = {
1468 .membase = (void *)0xff923000,
1469 .mapbase = 0xff923000,
1470 .iotype = UPIO_MEM,
1471 .irq = 61,
1472 .ops = &sci_uart_ops,
1473 .flags = UPF_BOOT_AUTOCONF,
1474 .line = 0,
1475 },
1476 .type = PORT_SCIF,
1477 .irqs = SH7770_SCIF0_IRQS,
1478 .init_pins = sci_init_pins_scif,
1479 },
1480 {
1481 .port = {
1482 .membase = (void *)0xff924000,
1483 .mapbase = 0xff924000,
1484 .iotype = UPIO_MEM,
1485 .irq = 62,
1486 .ops = &sci_uart_ops,
1487 .flags = UPF_BOOT_AUTOCONF,
1488 .line = 1,
1489 },
1490 .type = PORT_SCIF,
1491 .irqs = SH7770_SCIF1_IRQS,
1492 .init_pins = sci_init_pins_scif,
1493 },
1494 {
1495 .port = {
1496 .membase = (void *)0xff925000,
1497 .mapbase = 0xff925000,
1498 .iotype = UPIO_MEM,
1499 .irq = 63,
1500 .ops = &sci_uart_ops,
1501 .flags = UPF_BOOT_AUTOCONF,
1502 .line = 2,
1503 },
1504 .type = PORT_SCIF,
1505 .irqs = SH7770_SCIF2_IRQS,
1506 .init_pins = sci_init_pins_scif,
1507 },
1508#elif defined(CONFIG_CPU_SUBTYPE_SH7780)
1509 {
1510 .port = {
1511 .membase = (void *)0xffe00000,
1512 .mapbase = 0xffe00000,
1513 .iotype = UPIO_MEM,
1514 .irq = 43,
1515 .ops = &sci_uart_ops,
1516 .flags = UPF_BOOT_AUTOCONF,
1517 .line = 0,
1518 },
1519 .type = PORT_SCIF,
1520 .irqs = SH7780_SCIF0_IRQS,
1521 .init_pins = sci_init_pins_scif,
1522 },
1523 {
1524 .port = {
1525 .membase = (void *)0xffe10000,
1526 .mapbase = 0xffe10000,
1527 .iotype = UPIO_MEM,
1528 .irq = 79,
1529 .ops = &sci_uart_ops,
1530 .flags = UPF_BOOT_AUTOCONF,
1531 .line = 1,
1532 },
1533 .type = PORT_SCIF,
1534 .irqs = SH7780_SCIF1_IRQS,
1535 .init_pins = sci_init_pins_scif,
1536 },
1537#else 1128#else
1538#error "CPU subtype not defined" 1129 /*
1130 * XXX: We should use a proper SCI/SCIF clock
1131 */
1132 {
1133 struct clk *clk = clk_get("module_clk");
1134 sci_ports[i].port.uartclk = clk_get_rate(clk) * 16;
1135 clk_put(clk);
1136 }
1539#endif 1137#endif
1540}; 1138
1139 sci_ports[i].break_timer.data = (unsigned long)&sci_ports[i];
1140 sci_ports[i].break_timer.function = sci_break_timer;
1141
1142 init_timer(&sci_ports[i].break_timer);
1143 }
1144}
1145
1146int __init early_sci_setup(struct uart_port *port)
1147{
1148 if (unlikely(port->line > SCI_NPORTS))
1149 return -ENODEV;
1150
1151 sci_init_ports();
1152
1153 sci_ports[port->line].port.membase = port->membase;
1154 sci_ports[port->line].port.mapbase = port->mapbase;
1155 sci_ports[port->line].port.type = port->type;
1156
1157 return 0;
1158}
1541 1159
1542#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE 1160#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
1543/* 1161/*
@@ -1559,34 +1177,38 @@ static int __init serial_console_setup(struct console *co, char *options)
1559 int flow = 'n'; 1177 int flow = 'n';
1560 int ret; 1178 int ret;
1561 1179
1180 /*
1181 * Check whether an invalid uart number has been specified, and
1182 * if so, search for the first available port that does have
1183 * console support.
1184 */
1185 if (co->index >= SCI_NPORTS)
1186 co->index = 0;
1187
1562 serial_console_port = &sci_ports[co->index]; 1188 serial_console_port = &sci_ports[co->index];
1563 port = &serial_console_port->port; 1189 port = &serial_console_port->port;
1564 port->type = serial_console_port->type;
1565
1566#ifdef CONFIG_SUPERH64
1567 /* This is especially needed on sh64 to remap the SCIF */
1568 sci_config_port(port, 0);
1569#endif
1570 1190
1571 /* 1191 /*
1572 * We need to set the initial uartclk here, since otherwise it will 1192 * Also need to check port->type, we don't actually have any
1573 * only ever be setup at sci_init() time. 1193 * UPIO_PORT ports, but uart_report_port() handily misreports
1194 * it anyways if we don't have a port available by the time this is
1195 * called.
1574 */ 1196 */
1575#if defined(__H8300H__) || defined(__H8300S__) 1197 if (!port->type)
1576 port->uartclk = CONFIG_CPU_CLOCK; 1198 return -ENODEV;
1199 if (!port->membase || !port->mapbase)
1200 return -ENODEV;
1201
1202 spin_lock_init(&port->lock);
1203
1204 port->type = serial_console_port->type;
1205
1206 if (port->flags & UPF_IOREMAP)
1207 sci_config_port(port, 0);
1208
1209 if (serial_console_port->enable)
1210 serial_console_port->enable(port);
1577 1211
1578#if defined(__H8300S__)
1579 h8300_sci_enable(port, sci_enable);
1580#endif
1581#elif defined(CONFIG_SUPERH64)
1582 port->uartclk = current_cpu_data.module_clock * 16;
1583#else
1584 {
1585 struct clk *clk = clk_get("module_clk");
1586 port->uartclk = clk_get_rate(clk) * 16;
1587 clk_put(clk);
1588 }
1589#endif
1590 if (options) 1212 if (options)
1591 uart_parse_options(options, &baud, &parity, &bits, &flow); 1213 uart_parse_options(options, &baud, &parity, &bits, &flow);
1592 1214
@@ -1604,17 +1226,17 @@ static struct console serial_console = {
1604 .device = uart_console_device, 1226 .device = uart_console_device,
1605 .write = serial_console_write, 1227 .write = serial_console_write,
1606 .setup = serial_console_setup, 1228 .setup = serial_console_setup,
1607 .flags = CON_PRINTBUFFER, 1229 .flags = CON_PRINTBUFFER,
1608 .index = -1, 1230 .index = -1,
1609 .data = &sci_uart_driver, 1231 .data = &sci_uart_driver,
1610}; 1232};
1611 1233
1612static int __init sci_console_init(void) 1234static int __init sci_console_init(void)
1613{ 1235{
1236 sci_init_ports();
1614 register_console(&serial_console); 1237 register_console(&serial_console);
1615 return 0; 1238 return 0;
1616} 1239}
1617
1618console_initcall(sci_console_init); 1240console_initcall(sci_console_init);
1619#endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */ 1241#endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */
1620 1242
@@ -1649,6 +1271,8 @@ int __init kgdb_console_setup(struct console *co, char *options)
1649 int parity = 'n'; 1271 int parity = 'n';
1650 int flow = 'n'; 1272 int flow = 'n';
1651 1273
1274 spin_lock_init(&port->lock);
1275
1652 if (co->index != kgdb_portnum) 1276 if (co->index != kgdb_portnum)
1653 co->index = kgdb_portnum; 1277 co->index = kgdb_portnum;
1654 1278
@@ -1677,10 +1301,10 @@ static struct console kgdb_console = {
1677/* Register the KGDB console so we get messages (d'oh!) */ 1301/* Register the KGDB console so we get messages (d'oh!) */
1678static int __init kgdb_console_init(void) 1302static int __init kgdb_console_init(void)
1679{ 1303{
1304 sci_init_ports();
1680 register_console(&kgdb_console); 1305 register_console(&kgdb_console);
1681 return 0; 1306 return 0;
1682} 1307}
1683
1684console_initcall(kgdb_console_init); 1308console_initcall(kgdb_console_init);
1685#endif /* CONFIG_SH_KGDB_CONSOLE */ 1309#endif /* CONFIG_SH_KGDB_CONSOLE */
1686 1310
@@ -1701,60 +1325,132 @@ static struct uart_driver sci_uart_driver = {
1701 .dev_name = "ttySC", 1325 .dev_name = "ttySC",
1702 .major = SCI_MAJOR, 1326 .major = SCI_MAJOR,
1703 .minor = SCI_MINOR_START, 1327 .minor = SCI_MINOR_START,
1328 .nr = SCI_NPORTS,
1704 .cons = SCI_CONSOLE, 1329 .cons = SCI_CONSOLE,
1705}; 1330};
1706 1331
1707static int __init sci_init(void) 1332/*
1333 * Register a set of serial devices attached to a platform device. The
1334 * list is terminated with a zero flags entry, which means we expect
1335 * all entries to have at least UPF_BOOT_AUTOCONF set. Platforms that need
1336 * remapping (such as sh64) should also set UPF_IOREMAP.
1337 */
1338static int __devinit sci_probe(struct platform_device *dev)
1708{ 1339{
1709 int chan, ret; 1340 struct plat_sci_port *p = dev->dev.platform_data;
1341 int i;
1710 1342
1711 printk("%s", banner); 1343 for (i = 0; p && p->flags != 0 && i < SCI_NPORTS; p++, i++) {
1344 struct sci_port *sciport = &sci_ports[i];
1712 1345
1713 sci_uart_driver.nr = ARRAY_SIZE(sci_ports); 1346 sciport->port.mapbase = p->mapbase;
1714 1347
1715 ret = uart_register_driver(&sci_uart_driver); 1348 /*
1716 if (ret == 0) { 1349 * For the simple (and majority of) cases where we don't need
1717 for (chan = 0; chan < SCI_NPORTS; chan++) { 1350 * to do any remapping, just cast the cookie directly.
1718 struct sci_port *sciport = &sci_ports[chan]; 1351 */
1352 if (p->mapbase && !p->membase && !(p->flags & UPF_IOREMAP))
1353 p->membase = (void __iomem *)p->mapbase;
1719 1354
1720#if defined(__H8300H__) || defined(__H8300S__) 1355 sciport->port.membase = p->membase;
1721 sciport->port.uartclk = CONFIG_CPU_CLOCK; 1356
1722#elif defined(CONFIG_SUPERH64) 1357 sciport->port.irq = p->irqs[SCIx_TXI_IRQ];
1723 sciport->port.uartclk = current_cpu_data.module_clock * 16; 1358 sciport->port.flags = p->flags;
1724#else 1359 sciport->port.dev = &dev->dev;
1725 struct clk *clk = clk_get("module_clk"); 1360
1726 sciport->port.uartclk = clk_get_rate(clk) * 16; 1361 sciport->type = sciport->port.type = p->type;
1727 clk_put(clk); 1362
1728#endif 1363 memcpy(&sciport->irqs, &p->irqs, sizeof(p->irqs));
1729 uart_add_one_port(&sci_uart_driver, &sciport->port); 1364
1730 sciport->break_timer.data = (unsigned long)sciport; 1365 uart_add_one_port(&sci_uart_driver, &sciport->port);
1731 sciport->break_timer.function = sci_break_timer;
1732 init_timer(&sciport->break_timer);
1733 }
1734 } 1366 }
1735 1367
1736#ifdef CONFIG_CPU_FREQ 1368#ifdef CONFIG_CPU_FREQ
1737 cpufreq_register_notifier(&sci_nb, CPUFREQ_TRANSITION_NOTIFIER); 1369 cpufreq_register_notifier(&sci_nb, CPUFREQ_TRANSITION_NOTIFIER);
1738 printk("sci: CPU frequency notifier registered\n"); 1370 dev_info(&dev->dev, "sci: CPU frequency notifier registered\n");
1739#endif 1371#endif
1740 1372
1741#ifdef CONFIG_SH_STANDARD_BIOS 1373#ifdef CONFIG_SH_STANDARD_BIOS
1742 sh_bios_gdb_detach(); 1374 sh_bios_gdb_detach();
1743#endif 1375#endif
1744 1376
1745 return ret; 1377 return 0;
1746} 1378}
1747 1379
1748static void __exit sci_exit(void) 1380static int __devexit sci_remove(struct platform_device *dev)
1381{
1382 int i;
1383
1384 for (i = 0; i < SCI_NPORTS; i++)
1385 uart_remove_one_port(&sci_uart_driver, &sci_ports[i].port);
1386
1387 return 0;
1388}
1389
1390static int sci_suspend(struct platform_device *dev, pm_message_t state)
1749{ 1391{
1750 int chan; 1392 int i;
1393
1394 for (i = 0; i < SCI_NPORTS; i++) {
1395 struct sci_port *p = &sci_ports[i];
1396
1397 if (p->type != PORT_UNKNOWN && p->port.dev == &dev->dev)
1398 uart_suspend_port(&sci_uart_driver, &p->port);
1399 }
1751 1400
1752 for (chan = 0; chan < SCI_NPORTS; chan++) 1401 return 0;
1753 uart_remove_one_port(&sci_uart_driver, &sci_ports[chan].port); 1402}
1754 1403
1404static int sci_resume(struct platform_device *dev)
1405{
1406 int i;
1407
1408 for (i = 0; i < SCI_NPORTS; i++) {
1409 struct sci_port *p = &sci_ports[i];
1410
1411 if (p->type != PORT_UNKNOWN && p->port.dev == &dev->dev)
1412 uart_resume_port(&sci_uart_driver, &p->port);
1413 }
1414
1415 return 0;
1416}
1417
1418static struct platform_driver sci_driver = {
1419 .probe = sci_probe,
1420 .remove = __devexit_p(sci_remove),
1421 .suspend = sci_suspend,
1422 .resume = sci_resume,
1423 .driver = {
1424 .name = "sh-sci",
1425 .owner = THIS_MODULE,
1426 },
1427};
1428
1429static int __init sci_init(void)
1430{
1431 int ret;
1432
1433 printk(banner);
1434
1435 sci_init_ports();
1436
1437 ret = uart_register_driver(&sci_uart_driver);
1438 if (likely(ret == 0)) {
1439 ret = platform_driver_register(&sci_driver);
1440 if (unlikely(ret))
1441 uart_unregister_driver(&sci_uart_driver);
1442 }
1443
1444 return ret;
1445}
1446
1447static void __exit sci_exit(void)
1448{
1449 platform_driver_unregister(&sci_driver);
1755 uart_unregister_driver(&sci_uart_driver); 1450 uart_unregister_driver(&sci_uart_driver);
1756} 1451}
1757 1452
1758module_init(sci_init); 1453module_init(sci_init);
1759module_exit(sci_exit); 1454module_exit(sci_exit);
1760 1455
1456MODULE_LICENSE("GPL");
diff --git a/drivers/serial/sh-sci.h b/drivers/serial/sh-sci.h
index ab320fa3237c..28643c4dc850 100644
--- a/drivers/serial/sh-sci.h
+++ b/drivers/serial/sh-sci.h
@@ -10,7 +10,9 @@
10 * Modified to support SH7300(SH-Mobile) SCIF. Takashi Kusuda (Jun 2003). 10 * Modified to support SH7300(SH-Mobile) SCIF. Takashi Kusuda (Jun 2003).
11 * Modified to support H8/300 Series Yoshinori Sato (Feb 2004). 11 * Modified to support H8/300 Series Yoshinori Sato (Feb 2004).
12 */ 12 */
13#include <linux/config.h>
13#include <linux/serial_core.h> 14#include <linux/serial_core.h>
15#include <asm/io.h>
14 16
15#if defined(__H8300H__) || defined(__H8300S__) 17#if defined(__H8300H__) || defined(__H8300S__)
16#include <asm/gpio.h> 18#include <asm/gpio.h>
@@ -22,40 +24,13 @@
22#endif 24#endif
23#endif 25#endif
24 26
25/* Offsets into the sci_port->irqs array */
26#define SCIx_ERI_IRQ 0
27#define SCIx_RXI_IRQ 1
28#define SCIx_TXI_IRQ 2
29
30/* ERI, RXI, TXI, BRI */
31#define SCI_IRQS { 23, 24, 25, 0 }
32#define SH3_SCIF_IRQS { 56, 57, 59, 58 }
33#define SH3_IRDA_IRQS { 52, 53, 55, 54 }
34#define SH4_SCIF_IRQS { 40, 41, 43, 42 }
35#define STB1_SCIF1_IRQS {23, 24, 26, 25 }
36#define SH7760_SCIF0_IRQS { 52, 53, 55, 54 }
37#define SH7760_SCIF1_IRQS { 72, 73, 75, 74 }
38#define SH7760_SCIF2_IRQS { 76, 77, 79, 78 }
39#define SH7300_SCIF0_IRQS {80, 80, 80, 80 }
40#define SH73180_SCIF_IRQS {80, 81, 83, 82 }
41#define H8300H_SCI_IRQS0 {52, 53, 54, 0 }
42#define H8300H_SCI_IRQS1 {56, 57, 58, 0 }
43#define H8300H_SCI_IRQS2 {60, 61, 62, 0 }
44#define H8S_SCI_IRQS0 {88, 89, 90, 0 }
45#define H8S_SCI_IRQS1 {92, 93, 94, 0 }
46#define H8S_SCI_IRQS2 {96, 97, 98, 0 }
47#define SH5_SCIF_IRQS {39, 40, 42, 0 }
48#define SH7770_SCIF0_IRQS {61, 61, 61, 61 }
49#define SH7770_SCIF1_IRQS {62, 62, 62, 62 }
50#define SH7770_SCIF2_IRQS {63, 63, 63, 63 }
51#define SH7780_SCIF0_IRQS {40, 41, 43, 42 }
52#define SH7780_SCIF1_IRQS {76, 77, 79, 78 }
53
54#if defined(CONFIG_CPU_SUBTYPE_SH7708) 27#if defined(CONFIG_CPU_SUBTYPE_SH7708)
55# define SCSPTR 0xffffff7c /* 8 bit */ 28# define SCSPTR 0xffffff7c /* 8 bit */
56# define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */ 29# define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
57# define SCI_ONLY 30# define SCI_ONLY
58#elif defined(CONFIG_CPU_SUBTYPE_SH7707) || defined(CONFIG_CPU_SUBTYPE_SH7709) 31#elif defined(CONFIG_CPU_SUBTYPE_SH7707) || \
32 defined(CONFIG_CPU_SUBTYPE_SH7709) || \
33 defined(CONFIG_CPU_SUBTYPE_SH7706)
59# define SCPCR 0xA4000116 /* 16 bit SCI and SCIF */ 34# define SCPCR 0xA4000116 /* 16 bit SCI and SCIF */
60# define SCPDR 0xA4000136 /* 8 bit SCI and SCIF */ 35# define SCPDR 0xA4000136 /* 8 bit SCI and SCIF */
61# define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */ 36# define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
@@ -99,12 +74,23 @@
99# define SCPDR 0xA4050136 /* 16 bit SCIF */ 74# define SCPDR 0xA4050136 /* 16 bit SCIF */
100# define SCSCR_INIT(port) 0x0030 /* TIE=0,RIE=0,TE=1,RE=1 */ 75# define SCSCR_INIT(port) 0x0030 /* TIE=0,RIE=0,TE=1,RE=1 */
101# define SCIF_ONLY 76# define SCIF_ONLY
77#elif defined(CONFIG_CPU_SUBTYPE_SH7710)
78# define SCSPTR0 0xA4400000 /* 16 bit SCIF */
79# define SCSCR_INIT(port) 0x0030 /* TIE=0,RIE=0,TE=1,RE=1 */
80# define SCIF_ONLY
102#elif defined(CONFIG_CPU_SUBTYPE_SH73180) 81#elif defined(CONFIG_CPU_SUBTYPE_SH73180)
103# define SCPDR 0xA4050138 /* 16 bit SCIF */ 82# define SCPDR 0xA4050138 /* 16 bit SCIF */
104# define SCSPTR2 SCPDR 83# define SCSPTR2 SCPDR
105# define SCIF_ORER 0x0001 /* overrun error bit */ 84# define SCIF_ORER 0x0001 /* overrun error bit */
106# define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1 */ 85# define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1 */
107# define SCIF_ONLY 86# define SCIF_ONLY
87#elif defined(CONFIG_CPU_SUBTYPE_SH7343)
88# define SCSPTR0 0xffe00010 /* 16 bit SCIF */
89# define SCSPTR1 0xffe10010 /* 16 bit SCIF */
90# define SCSPTR2 0xffe20010 /* 16 bit SCIF */
91# define SCSPTR3 0xffe30010 /* 16 bit SCIF */
92# define SCSCR_INIT(port) 0x32 /* TIE=0,RIE=0,TE=1,RE=1,REIE=0,CKE=1 */
93# define SCIF_ONLY
108#elif defined(CONFIG_CPU_SUBTYPE_SH4_202) 94#elif defined(CONFIG_CPU_SUBTYPE_SH4_202)
109# define SCSPTR2 0xffe80020 /* 16 bit SCIF */ 95# define SCSPTR2 0xffe80020 /* 16 bit SCIF */
110# define SCIF_ORER 0x0001 /* overrun error bit */ 96# define SCIF_ORER 0x0001 /* overrun error bit */
@@ -145,7 +131,7 @@
145#elif defined(CONFIG_CPU_SUBTYPE_SH7780) 131#elif defined(CONFIG_CPU_SUBTYPE_SH7780)
146# define SCSPTR0 0xffe00024 /* 16 bit SCIF */ 132# define SCSPTR0 0xffe00024 /* 16 bit SCIF */
147# define SCSPTR1 0xffe10024 /* 16 bit SCIF */ 133# define SCSPTR1 0xffe10024 /* 16 bit SCIF */
148# define SCIF_OPER 0x0001 /* Overrun error bit */ 134# define SCIF_ORER 0x0001 /* Overrun error bit */
149# define SCSCR_INIT(port) 0x3a /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */ 135# define SCSCR_INIT(port) 0x3a /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
150# define SCIF_ONLY 136# define SCIF_ONLY
151#else 137#else
@@ -273,15 +259,6 @@
273 */ 259 */
274#define SCI_EVENT_WRITE_WAKEUP 0 260#define SCI_EVENT_WRITE_WAKEUP 0
275 261
276struct sci_port {
277 struct uart_port port;
278 int type;
279 unsigned char irqs[4]; /* ERI, RXI, TXI, BRI */
280 void (*init_pins)(struct uart_port *port, unsigned int cflag);
281 int break_flag;
282 struct timer_list break_timer;
283};
284
285#define SCI_IN(size, offset) \ 262#define SCI_IN(size, offset) \
286 unsigned int addr = port->mapbase + (offset); \ 263 unsigned int addr = port->mapbase + (offset); \
287 if ((size) == 8) { \ 264 if ((size) == 8) { \
@@ -336,7 +313,9 @@ struct sci_port {
336 } 313 }
337 314
338#ifdef CONFIG_CPU_SH3 315#ifdef CONFIG_CPU_SH3
339#if defined(CONFIG_CPU_SUBTYPE_SH7300) || defined(CONFIG_CPU_SUBTYPE_SH7705) 316#if defined(CONFIG_CPU_SUBTYPE_SH7300) || \
317 defined(CONFIG_CPU_SUBTYPE_SH7705) || \
318 defined(CONFIG_CPU_SUBTYPE_SH7710)
340#define SCIF_FNS(name, scif_offset, scif_size) \ 319#define SCIF_FNS(name, scif_offset, scif_size) \
341 CPU_SCIF_FNS(name, scif_offset, scif_size) 320 CPU_SCIF_FNS(name, scif_offset, scif_size)
342#else 321#else
@@ -362,7 +341,9 @@ struct sci_port {
362 CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size) 341 CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
363#endif 342#endif
364 343
365#if defined(CONFIG_CPU_SUBTYPE_SH7300) || defined(CONFIG_CPU_SUBTYPE_SH7705) 344#if defined(CONFIG_CPU_SUBTYPE_SH7300) || \
345 defined(CONFIG_CPU_SUBTYPE_SH7705) || \
346 defined(CONFIG_CPU_SUBTYPE_SH7710)
366SCIF_FNS(SCSMR, 0x00, 16) 347SCIF_FNS(SCSMR, 0x00, 16)
367SCIF_FNS(SCBRR, 0x04, 8) 348SCIF_FNS(SCBRR, 0x04, 8)
368SCIF_FNS(SCSCR, 0x08, 16) 349SCIF_FNS(SCSCR, 0x08, 16)
@@ -447,7 +428,9 @@ static inline int sci_rxd_in(struct uart_port *port)
447 return ctrl_inb(SCSPTR)&0x01 ? 1 : 0; /* SCI */ 428 return ctrl_inb(SCSPTR)&0x01 ? 1 : 0; /* SCI */
448 return 1; 429 return 1;
449} 430}
450#elif defined(CONFIG_CPU_SUBTYPE_SH7707) || defined(CONFIG_CPU_SUBTYPE_SH7709) 431#elif defined(CONFIG_CPU_SUBTYPE_SH7707) || \
432 defined(CONFIG_CPU_SUBTYPE_SH7709) || \
433 defined(CONFIG_CPU_SUBTYPE_SH7706)
451static inline int sci_rxd_in(struct uart_port *port) 434static inline int sci_rxd_in(struct uart_port *port)
452{ 435{
453 if (port->mapbase == 0xfffffe80) 436 if (port->mapbase == 0xfffffe80)
@@ -467,6 +450,13 @@ static inline int sci_rxd_in(struct uart_port *port)
467 return ctrl_inb(SCPDR)&0x10 ? 1 : 0; /* SCIF */ 450 return ctrl_inb(SCPDR)&0x10 ? 1 : 0; /* SCIF */
468 return 1; 451 return 1;
469} 452}
453#elif defined(CONFIG_CPU_SUBTYPE_SH7710)
454static inline int sci_rxd_in(struct uart_port *port)
455{
456 if (port->mapbase == SCSPTR0)
457 return ctrl_inw(SCSPTR0 + 0x10) & 0x01 ? 1 : 0;
458 return 1;
459}
470#elif defined(CONFIG_CPU_SUBTYPE_SH7750) || \ 460#elif defined(CONFIG_CPU_SUBTYPE_SH7750) || \
471 defined(CONFIG_CPU_SUBTYPE_SH7751) || \ 461 defined(CONFIG_CPU_SUBTYPE_SH7751) || \
472 defined(CONFIG_CPU_SUBTYPE_SH4_202) 462 defined(CONFIG_CPU_SUBTYPE_SH4_202)
@@ -504,6 +494,19 @@ static inline int sci_rxd_in(struct uart_port *port)
504{ 494{
505 return ctrl_inb(SCPDR)&0x01 ? 1 : 0; /* SCIF0 */ 495 return ctrl_inb(SCPDR)&0x01 ? 1 : 0; /* SCIF0 */
506} 496}
497#elif defined(CONFIG_CPU_SUBTYPE_SH7343)
498static inline int sci_rxd_in(struct uart_port *port)
499{
500 if (port->mapbase == 0xffe00000)
501 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
502 if (port->mapbase == 0xffe10000)
503 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
504 if (port->mapbase == 0xffe20000)
505 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
506 if (port->mapbase == 0xffe30000)
507 return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
508 return 1;
509}
507#elif defined(CONFIG_CPU_SUBTYPE_ST40STB1) 510#elif defined(CONFIG_CPU_SUBTYPE_ST40STB1)
508static inline int sci_rxd_in(struct uart_port *port) 511static inline int sci_rxd_in(struct uart_port *port)
509{ 512{
@@ -587,4 +590,3 @@ static inline int sci_rxd_in(struct uart_port *port)
587#else /* Generic SH */ 590#else /* Generic SH */
588#define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(32*bps)-1) 591#define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(32*bps)-1)
589#endif 592#endif
590
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
index d3a5aeee73a3..9b3b9aaa6b90 100644
--- a/drivers/serial/sunsu.c
+++ b/drivers/serial/sunsu.c
@@ -1499,6 +1499,9 @@ static int __devexit su_remove(struct of_device *dev)
1499 uart_remove_one_port(&sunsu_reg, &up->port); 1499 uart_remove_one_port(&sunsu_reg, &up->port);
1500 } 1500 }
1501 1501
1502 if (up->port.membase)
1503 of_iounmap(up->port.membase, up->reg_size);
1504
1502 dev_set_drvdata(&dev->dev, NULL); 1505 dev_set_drvdata(&dev->dev, NULL);
1503 1506
1504 return 0; 1507 return 0;
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c
index d34f336d53d8..0da3ebfff82d 100644
--- a/drivers/serial/sunzilog.c
+++ b/drivers/serial/sunzilog.c
@@ -1270,7 +1270,7 @@ static void __init sunzilog_register_serio(struct uart_sunzilog_port *up)
1270} 1270}
1271#endif 1271#endif
1272 1272
1273static void __init sunzilog_init_hw(struct uart_sunzilog_port *up) 1273static void __devinit sunzilog_init_hw(struct uart_sunzilog_port *up)
1274{ 1274{
1275 struct zilog_channel __iomem *channel; 1275 struct zilog_channel __iomem *channel;
1276 unsigned long flags; 1276 unsigned long flags;
diff --git a/drivers/tc/zs.c b/drivers/tc/zs.c
index 5e8a27620f6f..622881f26761 100644
--- a/drivers/tc/zs.c
+++ b/drivers/tc/zs.c
@@ -1701,7 +1701,7 @@ static void __init probe_sccs(void)
1701 spin_unlock_irqrestore(&zs_lock, flags); 1701 spin_unlock_irqrestore(&zs_lock, flags);
1702} 1702}
1703 1703
1704static struct tty_operations serial_ops = { 1704static const struct tty_operations serial_ops = {
1705 .open = rs_open, 1705 .open = rs_open,
1706 .close = rs_close, 1706 .close = rs_close,
1707 .write = rs_write, 1707 .write = rs_write,
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 005043197527..f9b1719b9a37 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -25,6 +25,7 @@ config USB_ARCH_HAS_OHCI
25 default y if PXA27x 25 default y if PXA27x
26 default y if ARCH_EP93XX 26 default y if ARCH_EP93XX
27 default y if (ARCH_AT91RM9200 || ARCH_AT91SAM9261) 27 default y if (ARCH_AT91RM9200 || ARCH_AT91SAM9261)
28 default y if ARCH_PNX4008
28 # PPC: 29 # PPC:
29 default y if STB03xxx 30 default y if STB03xxx
30 default y if PPC_MPC52xx 31 default y if PPC_MPC52xx
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 4710eb02ed64..97d57cfc343b 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_USB_ISP116X_HCD) += host/
14obj-$(CONFIG_USB_OHCI_HCD) += host/ 14obj-$(CONFIG_USB_OHCI_HCD) += host/
15obj-$(CONFIG_USB_UHCI_HCD) += host/ 15obj-$(CONFIG_USB_UHCI_HCD) += host/
16obj-$(CONFIG_USB_SL811_HCD) += host/ 16obj-$(CONFIG_USB_SL811_HCD) += host/
17obj-$(CONFIG_USB_U132_HCD) += host/
17obj-$(CONFIG_ETRAX_USB_HOST) += host/ 18obj-$(CONFIG_ETRAX_USB_HOST) += host/
18obj-$(CONFIG_USB_OHCI_AT91) += host/ 19obj-$(CONFIG_USB_OHCI_AT91) += host/
19 20
@@ -23,6 +24,7 @@ obj-$(CONFIG_USB_PRINTER) += class/
23obj-$(CONFIG_USB_STORAGE) += storage/ 24obj-$(CONFIG_USB_STORAGE) += storage/
24obj-$(CONFIG_USB) += storage/ 25obj-$(CONFIG_USB) += storage/
25 26
27obj-$(CONFIG_USB_ACECAD) += input/
26obj-$(CONFIG_USB_AIPTEK) += input/ 28obj-$(CONFIG_USB_AIPTEK) += input/
27obj-$(CONFIG_USB_ATI_REMOTE) += input/ 29obj-$(CONFIG_USB_ATI_REMOTE) += input/
28obj-$(CONFIG_USB_HID) += input/ 30obj-$(CONFIG_USB_HID) += input/
@@ -31,8 +33,8 @@ obj-$(CONFIG_USB_KBTAB) += input/
31obj-$(CONFIG_USB_MOUSE) += input/ 33obj-$(CONFIG_USB_MOUSE) += input/
32obj-$(CONFIG_USB_MTOUCH) += input/ 34obj-$(CONFIG_USB_MTOUCH) += input/
33obj-$(CONFIG_USB_POWERMATE) += input/ 35obj-$(CONFIG_USB_POWERMATE) += input/
36obj-$(CONFIG_USB_TRANCEVIBRATOR)+= input/
34obj-$(CONFIG_USB_WACOM) += input/ 37obj-$(CONFIG_USB_WACOM) += input/
35obj-$(CONFIG_USB_ACECAD) += input/
36obj-$(CONFIG_USB_XPAD) += input/ 38obj-$(CONFIG_USB_XPAD) += input/
37 39
38obj-$(CONFIG_USB_CATC) += net/ 40obj-$(CONFIG_USB_CATC) += net/
@@ -47,22 +49,24 @@ obj-$(CONFIG_USB_MICROTEK) += image/
47 49
48obj-$(CONFIG_USB_SERIAL) += serial/ 50obj-$(CONFIG_USB_SERIAL) += serial/
49 51
52obj-$(CONFIG_USB_ADUTUX) += misc/
53obj-$(CONFIG_USB_APPLEDISPLAY) += misc/
50obj-$(CONFIG_USB_AUERSWALD) += misc/ 54obj-$(CONFIG_USB_AUERSWALD) += misc/
51obj-$(CONFIG_USB_CYPRESS_CY7C63)+= misc/ 55obj-$(CONFIG_USB_CYPRESS_CY7C63)+= misc/
52obj-$(CONFIG_USB_CYTHERM) += misc/ 56obj-$(CONFIG_USB_CYTHERM) += misc/
53obj-$(CONFIG_USB_EMI26) += misc/ 57obj-$(CONFIG_USB_EMI26) += misc/
54obj-$(CONFIG_USB_EMI62) += misc/ 58obj-$(CONFIG_USB_EMI62) += misc/
59obj-$(CONFIG_USB_FTDI_ELAN) += misc/
55obj-$(CONFIG_USB_IDMOUSE) += misc/ 60obj-$(CONFIG_USB_IDMOUSE) += misc/
56obj-$(CONFIG_USB_LCD) += misc/ 61obj-$(CONFIG_USB_LCD) += misc/
57obj-$(CONFIG_USB_LD) += misc/ 62obj-$(CONFIG_USB_LD) += misc/
58obj-$(CONFIG_USB_LED) += misc/ 63obj-$(CONFIG_USB_LED) += misc/
59obj-$(CONFIG_USB_LEGOTOWER) += misc/ 64obj-$(CONFIG_USB_LEGOTOWER) += misc/
65obj-$(CONFIG_USB_PHIDGETSERVO) += misc/
60obj-$(CONFIG_USB_RIO500) += misc/ 66obj-$(CONFIG_USB_RIO500) += misc/
67obj-$(CONFIG_USB_SISUSBVGA) += misc/
61obj-$(CONFIG_USB_TEST) += misc/ 68obj-$(CONFIG_USB_TEST) += misc/
62obj-$(CONFIG_USB_USS720) += misc/ 69obj-$(CONFIG_USB_USS720) += misc/
63obj-$(CONFIG_USB_PHIDGETSERVO) += misc/
64obj-$(CONFIG_USB_SISUSBVGA) += misc/
65obj-$(CONFIG_USB_APPLEDISPLAY) += misc/
66 70
67obj-$(CONFIG_USB_ATM) += atm/ 71obj-$(CONFIG_USB_ATM) += atm/
68obj-$(CONFIG_USB_SPEEDTOUCH) += atm/ 72obj-$(CONFIG_USB_SPEEDTOUCH) += atm/
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index b38990adf1cd..465961a26e4a 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -1621,26 +1621,32 @@ static int claim_interface(struct usb_device *usb_dev,
1621 return ret; 1621 return ret;
1622} 1622}
1623 1623
1624static void create_fs_entries(struct uea_softc *sc, struct usb_interface *intf) 1624static struct attribute *attrs[] = {
1625 &dev_attr_stat_status.attr,
1626 &dev_attr_stat_mflags.attr,
1627 &dev_attr_stat_human_status.attr,
1628 &dev_attr_stat_delin.attr,
1629 &dev_attr_stat_vidcpe.attr,
1630 &dev_attr_stat_usrate.attr,
1631 &dev_attr_stat_dsrate.attr,
1632 &dev_attr_stat_usattenuation.attr,
1633 &dev_attr_stat_dsattenuation.attr,
1634 &dev_attr_stat_usmargin.attr,
1635 &dev_attr_stat_dsmargin.attr,
1636 &dev_attr_stat_txflow.attr,
1637 &dev_attr_stat_rxflow.attr,
1638 &dev_attr_stat_uscorr.attr,
1639 &dev_attr_stat_dscorr.attr,
1640 &dev_attr_stat_usunc.attr,
1641 &dev_attr_stat_dsunc.attr,
1642};
1643static struct attribute_group attr_grp = {
1644 .attrs = attrs,
1645};
1646
1647static int create_fs_entries(struct usb_interface *intf)
1625{ 1648{
1626 /* sysfs interface */ 1649 return sysfs_create_group(&intf->dev.kobj, &attr_grp);
1627 device_create_file(&intf->dev, &dev_attr_stat_status);
1628 device_create_file(&intf->dev, &dev_attr_stat_mflags);
1629 device_create_file(&intf->dev, &dev_attr_stat_human_status);
1630 device_create_file(&intf->dev, &dev_attr_stat_delin);
1631 device_create_file(&intf->dev, &dev_attr_stat_vidcpe);
1632 device_create_file(&intf->dev, &dev_attr_stat_usrate);
1633 device_create_file(&intf->dev, &dev_attr_stat_dsrate);
1634 device_create_file(&intf->dev, &dev_attr_stat_usattenuation);
1635 device_create_file(&intf->dev, &dev_attr_stat_dsattenuation);
1636 device_create_file(&intf->dev, &dev_attr_stat_usmargin);
1637 device_create_file(&intf->dev, &dev_attr_stat_dsmargin);
1638 device_create_file(&intf->dev, &dev_attr_stat_txflow);
1639 device_create_file(&intf->dev, &dev_attr_stat_rxflow);
1640 device_create_file(&intf->dev, &dev_attr_stat_uscorr);
1641 device_create_file(&intf->dev, &dev_attr_stat_dscorr);
1642 device_create_file(&intf->dev, &dev_attr_stat_usunc);
1643 device_create_file(&intf->dev, &dev_attr_stat_dsunc);
1644} 1650}
1645 1651
1646static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf, 1652static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
@@ -1708,37 +1714,25 @@ static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
1708 return ret; 1714 return ret;
1709 } 1715 }
1710 1716
1711 create_fs_entries(sc, intf); 1717 ret = create_fs_entries(intf);
1718 if (ret) {
1719 uea_stop(sc);
1720 kfree(sc);
1721 return ret;
1722 }
1712 return 0; 1723 return 0;
1713} 1724}
1714 1725
1715static void destroy_fs_entries(struct uea_softc *sc, struct usb_interface *intf) 1726static void destroy_fs_entries(struct usb_interface *intf)
1716{ 1727{
1717 /* sysfs interface */ 1728 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
1718 device_remove_file(&intf->dev, &dev_attr_stat_status);
1719 device_remove_file(&intf->dev, &dev_attr_stat_mflags);
1720 device_remove_file(&intf->dev, &dev_attr_stat_human_status);
1721 device_remove_file(&intf->dev, &dev_attr_stat_delin);
1722 device_remove_file(&intf->dev, &dev_attr_stat_vidcpe);
1723 device_remove_file(&intf->dev, &dev_attr_stat_usrate);
1724 device_remove_file(&intf->dev, &dev_attr_stat_dsrate);
1725 device_remove_file(&intf->dev, &dev_attr_stat_usattenuation);
1726 device_remove_file(&intf->dev, &dev_attr_stat_dsattenuation);
1727 device_remove_file(&intf->dev, &dev_attr_stat_usmargin);
1728 device_remove_file(&intf->dev, &dev_attr_stat_dsmargin);
1729 device_remove_file(&intf->dev, &dev_attr_stat_txflow);
1730 device_remove_file(&intf->dev, &dev_attr_stat_rxflow);
1731 device_remove_file(&intf->dev, &dev_attr_stat_uscorr);
1732 device_remove_file(&intf->dev, &dev_attr_stat_dscorr);
1733 device_remove_file(&intf->dev, &dev_attr_stat_usunc);
1734 device_remove_file(&intf->dev, &dev_attr_stat_dsunc);
1735} 1729}
1736 1730
1737static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf) 1731static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
1738{ 1732{
1739 struct uea_softc *sc = usbatm->driver_data; 1733 struct uea_softc *sc = usbatm->driver_data;
1740 1734
1741 destroy_fs_entries(sc, intf); 1735 destroy_fs_entries(intf);
1742 uea_stop(sc); 1736 uea_stop(sc);
1743 kfree(sc); 1737 kfree(sc);
1744} 1738}
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index ca90326f2f5c..71288295df2f 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -1120,7 +1120,7 @@ static struct usb_driver acm_driver = {
1120 * TTY driver structures. 1120 * TTY driver structures.
1121 */ 1121 */
1122 1122
1123static struct tty_operations acm_ops = { 1123static const struct tty_operations acm_ops = {
1124 .open = acm_tty_open, 1124 .open = acm_tty_open,
1125 .close = acm_tty_close, 1125 .close = acm_tty_close,
1126 .write = acm_tty_write, 1126 .write = acm_tty_write,
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 48dee4b8d8e5..9cac11ca1bb7 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -813,7 +813,7 @@ static unsigned int usblp_quirks (__u16 vendor, __u16 product)
813 return 0; 813 return 0;
814} 814}
815 815
816static struct file_operations usblp_fops = { 816static const struct file_operations usblp_fops = {
817 .owner = THIS_MODULE, 817 .owner = THIS_MODULE,
818 .read = usblp_read, 818 .read = usblp_read,
819 .write = usblp_write, 819 .write = usblp_write,
@@ -927,7 +927,9 @@ static int usblp_probe(struct usb_interface *intf,
927 927
928 /* Retrieve and store the device ID string. */ 928 /* Retrieve and store the device ID string. */
929 usblp_cache_device_id_string(usblp); 929 usblp_cache_device_id_string(usblp);
930 device_create_file(&intf->dev, &dev_attr_ieee1284_id); 930 retval = device_create_file(&intf->dev, &dev_attr_ieee1284_id);
931 if (retval)
932 goto abort_intfdata;
931 933
932#ifdef DEBUG 934#ifdef DEBUG
933 usblp_check_status(usblp, 0); 935 usblp_check_status(usblp, 0);
@@ -1021,18 +1023,13 @@ static int usblp_select_alts(struct usblp *usblp)
1021 for (e = 0; e < ifd->desc.bNumEndpoints; e++) { 1023 for (e = 0; e < ifd->desc.bNumEndpoints; e++) {
1022 epd = &ifd->endpoint[e].desc; 1024 epd = &ifd->endpoint[e].desc;
1023 1025
1024 if ((epd->bmAttributes&USB_ENDPOINT_XFERTYPE_MASK)!= 1026 if (usb_endpoint_is_bulk_out(epd))
1025 USB_ENDPOINT_XFER_BULK)
1026 continue;
1027
1028 if (!(epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK)) {
1029 if (!epwrite) 1027 if (!epwrite)
1030 epwrite = epd; 1028 epwrite = epd;
1031 1029
1032 } else { 1030 if (usb_endpoint_is_bulk_in(epd))
1033 if (!epread) 1031 if (!epread)
1034 epread = epd; 1032 epread = epd;
1035 }
1036 } 1033 }
1037 1034
1038 /* Ignore buggy hardware without the right endpoints. */ 1035 /* Ignore buggy hardware without the right endpoints. */
diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile
index ec510922af63..34e9bac319b4 100644
--- a/drivers/usb/core/Makefile
+++ b/drivers/usb/core/Makefile
@@ -4,7 +4,7 @@
4 4
5usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \ 5usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \
6 config.o file.o buffer.o sysfs.o endpoint.o \ 6 config.o file.o buffer.o sysfs.o endpoint.o \
7 devio.o notify.o 7 devio.o notify.o generic.o
8 8
9ifeq ($(CONFIG_PCI),y) 9ifeq ($(CONFIG_PCI),y)
10 usbcore-objs += hcd-pci.o 10 usbcore-objs += hcd-pci.o
diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index f4f4ef0f377a..840442a25b61 100644
--- a/drivers/usb/core/buffer.c
+++ b/drivers/usb/core/buffer.c
@@ -104,7 +104,7 @@ void *hcd_buffer_alloc (
104 dma_addr_t *dma 104 dma_addr_t *dma
105) 105)
106{ 106{
107 struct usb_hcd *hcd = bus->hcpriv; 107 struct usb_hcd *hcd = bus_to_hcd(bus);
108 int i; 108 int i;
109 109
110 /* some USB hosts just use PIO */ 110 /* some USB hosts just use PIO */
@@ -127,7 +127,7 @@ void hcd_buffer_free (
127 dma_addr_t dma 127 dma_addr_t dma
128) 128)
129{ 129{
130 struct usb_hcd *hcd = bus->hcpriv; 130 struct usb_hcd *hcd = bus_to_hcd(bus);
131 int i; 131 int i;
132 132
133 if (!addr) 133 if (!addr)
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index 4c9e63e665b6..bfb3731d42db 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -475,7 +475,9 @@ int usb_get_configuration(struct usb_device *dev)
475 if (result < 0) { 475 if (result < 0) {
476 dev_err(ddev, "unable to read config index %d " 476 dev_err(ddev, "unable to read config index %d "
477 "descriptor/%s\n", cfgno, "start"); 477 "descriptor/%s\n", cfgno, "start");
478 goto err; 478 dev_err(ddev, "chopping to %d config(s)\n", cfgno);
479 dev->descriptor.bNumConfigurations = cfgno;
480 break;
479 } else if (result < 4) { 481 } else if (result < 4) {
480 dev_err(ddev, "config index %d descriptor too short " 482 dev_err(ddev, "config index %d descriptor too short "
481 "(expected %i, got %i)\n", cfgno, 483 "(expected %i, got %i)\n", cfgno,
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
index c0f37343a276..3538c2fdadfe 100644
--- a/drivers/usb/core/devices.c
+++ b/drivers/usb/core/devices.c
@@ -593,7 +593,7 @@ static ssize_t usb_device_read(struct file *file, char __user *buf, size_t nbyte
593/* Kernel lock for "lastev" protection */ 593/* Kernel lock for "lastev" protection */
594static unsigned int usb_device_poll(struct file *file, struct poll_table_struct *wait) 594static unsigned int usb_device_poll(struct file *file, struct poll_table_struct *wait)
595{ 595{
596 struct usb_device_status *st = (struct usb_device_status *)file->private_data; 596 struct usb_device_status *st = file->private_data;
597 unsigned int mask = 0; 597 unsigned int mask = 0;
598 598
599 lock_kernel(); 599 lock_kernel();
@@ -603,7 +603,7 @@ static unsigned int usb_device_poll(struct file *file, struct poll_table_struct
603 unlock_kernel(); 603 unlock_kernel();
604 return POLLIN; 604 return POLLIN;
605 } 605 }
606 606
607 /* we may have dropped BKL - need to check for having lost the race */ 607 /* we may have dropped BKL - need to check for having lost the race */
608 if (file->private_data) { 608 if (file->private_data) {
609 kfree(st); 609 kfree(st);
@@ -667,7 +667,7 @@ static loff_t usb_device_lseek(struct file * file, loff_t offset, int orig)
667 return ret; 667 return ret;
668} 668}
669 669
670struct file_operations usbfs_devices_fops = { 670const struct file_operations usbfs_devices_fops = {
671 .llseek = usb_device_lseek, 671 .llseek = usb_device_lseek,
672 .read = usb_device_read, 672 .read = usb_device_read,
673 .poll = usb_device_poll, 673 .poll = usb_device_poll,
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 218621b9958e..3f509beb88e4 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -59,10 +59,13 @@
59#define USB_DEVICE_MAX USB_MAXBUS * 128 59#define USB_DEVICE_MAX USB_MAXBUS * 128
60static struct class *usb_device_class; 60static struct class *usb_device_class;
61 61
62/* Mutual exclusion for removal, open, and release */
63DEFINE_MUTEX(usbfs_mutex);
64
62struct async { 65struct async {
63 struct list_head asynclist; 66 struct list_head asynclist;
64 struct dev_state *ps; 67 struct dev_state *ps;
65 pid_t pid; 68 struct pid *pid;
66 uid_t uid, euid; 69 uid_t uid, euid;
67 unsigned int signr; 70 unsigned int signr;
68 unsigned int ifnum; 71 unsigned int ifnum;
@@ -87,9 +90,10 @@ MODULE_PARM_DESC (usbfs_snoop, "true to log all usbfs traffic");
87 90
88#define MAX_USBFS_BUFFER_SIZE 16384 91#define MAX_USBFS_BUFFER_SIZE 16384
89 92
90static inline int connected (struct usb_device *dev) 93static inline int connected (struct dev_state *ps)
91{ 94{
92 return dev->state != USB_STATE_NOTATTACHED; 95 return (!list_empty(&ps->list) &&
96 ps->dev->state != USB_STATE_NOTATTACHED);
93} 97}
94 98
95static loff_t usbdev_lseek(struct file *file, loff_t offset, int orig) 99static loff_t usbdev_lseek(struct file *file, loff_t offset, int orig)
@@ -118,7 +122,7 @@ static loff_t usbdev_lseek(struct file *file, loff_t offset, int orig)
118 122
119static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) 123static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
120{ 124{
121 struct dev_state *ps = (struct dev_state *)file->private_data; 125 struct dev_state *ps = file->private_data;
122 struct usb_device *dev = ps->dev; 126 struct usb_device *dev = ps->dev;
123 ssize_t ret = 0; 127 ssize_t ret = 0;
124 unsigned len; 128 unsigned len;
@@ -127,7 +131,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, l
127 131
128 pos = *ppos; 132 pos = *ppos;
129 usb_lock_device(dev); 133 usb_lock_device(dev);
130 if (!connected(dev)) { 134 if (!connected(ps)) {
131 ret = -ENODEV; 135 ret = -ENODEV;
132 goto err; 136 goto err;
133 } else if (pos < 0) { 137 } else if (pos < 0) {
@@ -221,6 +225,7 @@ static struct async *alloc_async(unsigned int numisoframes)
221 225
222static void free_async(struct async *as) 226static void free_async(struct async *as)
223{ 227{
228 put_pid(as->pid);
224 kfree(as->urb->transfer_buffer); 229 kfree(as->urb->transfer_buffer);
225 kfree(as->urb->setup_packet); 230 kfree(as->urb->setup_packet);
226 usb_free_urb(as->urb); 231 usb_free_urb(as->urb);
@@ -301,7 +306,7 @@ static void snoop_urb(struct urb *urb, void __user *userurb)
301 306
302static void async_completed(struct urb *urb, struct pt_regs *regs) 307static void async_completed(struct urb *urb, struct pt_regs *regs)
303{ 308{
304 struct async *as = (struct async *)urb->context; 309 struct async *as = urb->context;
305 struct dev_state *ps = as->ps; 310 struct dev_state *ps = as->ps;
306 struct siginfo sinfo; 311 struct siginfo sinfo;
307 312
@@ -313,7 +318,7 @@ static void async_completed(struct urb *urb, struct pt_regs *regs)
313 sinfo.si_errno = as->urb->status; 318 sinfo.si_errno = as->urb->status;
314 sinfo.si_code = SI_ASYNCIO; 319 sinfo.si_code = SI_ASYNCIO;
315 sinfo.si_addr = as->userurb; 320 sinfo.si_addr = as->userurb;
316 kill_proc_info_as_uid(as->signr, &sinfo, as->pid, as->uid, 321 kill_pid_info_as_uid(as->signr, &sinfo, as->pid, as->uid,
317 as->euid, as->secid); 322 as->euid, as->secid);
318 } 323 }
319 snoop(&urb->dev->dev, "urb complete\n"); 324 snoop(&urb->dev->dev, "urb complete\n");
@@ -541,25 +546,25 @@ static int usbdev_open(struct inode *inode, struct file *file)
541 struct dev_state *ps; 546 struct dev_state *ps;
542 int ret; 547 int ret;
543 548
544 /* 549 /* Protect against simultaneous removal or release */
545 * no locking necessary here, as chrdev_open has the kernel lock 550 mutex_lock(&usbfs_mutex);
546 * (still acquire the kernel lock for safety) 551
547 */
548 ret = -ENOMEM; 552 ret = -ENOMEM;
549 if (!(ps = kmalloc(sizeof(struct dev_state), GFP_KERNEL))) 553 if (!(ps = kmalloc(sizeof(struct dev_state), GFP_KERNEL)))
550 goto out_nolock; 554 goto out;
551 555
552 lock_kernel();
553 ret = -ENOENT; 556 ret = -ENOENT;
554 /* check if we are called from a real node or usbfs */ 557 /* check if we are called from a real node or usbfs */
555 if (imajor(inode) == USB_DEVICE_MAJOR) 558 if (imajor(inode) == USB_DEVICE_MAJOR)
556 dev = usbdev_lookup_minor(iminor(inode)); 559 dev = usbdev_lookup_minor(iminor(inode));
557 if (!dev) 560 if (!dev)
558 dev = inode->u.generic_ip; 561 dev = inode->i_private;
559 if (!dev) { 562 if (!dev)
560 kfree(ps);
561 goto out; 563 goto out;
562 } 564 ret = usb_autoresume_device(dev, 1);
565 if (ret)
566 goto out;
567
563 usb_get_dev(dev); 568 usb_get_dev(dev);
564 ret = 0; 569 ret = 0;
565 ps->dev = dev; 570 ps->dev = dev;
@@ -569,7 +574,7 @@ static int usbdev_open(struct inode *inode, struct file *file)
569 INIT_LIST_HEAD(&ps->async_completed); 574 INIT_LIST_HEAD(&ps->async_completed);
570 init_waitqueue_head(&ps->wait); 575 init_waitqueue_head(&ps->wait);
571 ps->discsignr = 0; 576 ps->discsignr = 0;
572 ps->disc_pid = current->pid; 577 ps->disc_pid = get_pid(task_pid(current));
573 ps->disc_uid = current->uid; 578 ps->disc_uid = current->uid;
574 ps->disc_euid = current->euid; 579 ps->disc_euid = current->euid;
575 ps->disccontext = NULL; 580 ps->disccontext = NULL;
@@ -579,30 +584,37 @@ static int usbdev_open(struct inode *inode, struct file *file)
579 list_add_tail(&ps->list, &dev->filelist); 584 list_add_tail(&ps->list, &dev->filelist);
580 file->private_data = ps; 585 file->private_data = ps;
581 out: 586 out:
582 unlock_kernel(); 587 if (ret)
583 out_nolock: 588 kfree(ps);
584 return ret; 589 mutex_unlock(&usbfs_mutex);
590 return ret;
585} 591}
586 592
587static int usbdev_release(struct inode *inode, struct file *file) 593static int usbdev_release(struct inode *inode, struct file *file)
588{ 594{
589 struct dev_state *ps = (struct dev_state *)file->private_data; 595 struct dev_state *ps = file->private_data;
590 struct usb_device *dev = ps->dev; 596 struct usb_device *dev = ps->dev;
591 unsigned int ifnum; 597 unsigned int ifnum;
592 598
593 usb_lock_device(dev); 599 usb_lock_device(dev);
600
601 /* Protect against simultaneous open */
602 mutex_lock(&usbfs_mutex);
594 list_del_init(&ps->list); 603 list_del_init(&ps->list);
604 mutex_unlock(&usbfs_mutex);
605
595 for (ifnum = 0; ps->ifclaimed && ifnum < 8*sizeof(ps->ifclaimed); 606 for (ifnum = 0; ps->ifclaimed && ifnum < 8*sizeof(ps->ifclaimed);
596 ifnum++) { 607 ifnum++) {
597 if (test_bit(ifnum, &ps->ifclaimed)) 608 if (test_bit(ifnum, &ps->ifclaimed))
598 releaseintf(ps, ifnum); 609 releaseintf(ps, ifnum);
599 } 610 }
600 destroy_all_async(ps); 611 destroy_all_async(ps);
612 usb_autosuspend_device(dev, 1);
601 usb_unlock_device(dev); 613 usb_unlock_device(dev);
602 usb_put_dev(dev); 614 usb_put_dev(dev);
603 ps->dev = NULL; 615 put_pid(ps->disc_pid);
604 kfree(ps); 616 kfree(ps);
605 return 0; 617 return 0;
606} 618}
607 619
608static int proc_control(struct dev_state *ps, void __user *arg) 620static int proc_control(struct dev_state *ps, void __user *arg)
@@ -1053,7 +1065,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1053 as->userbuffer = NULL; 1065 as->userbuffer = NULL;
1054 as->signr = uurb->signr; 1066 as->signr = uurb->signr;
1055 as->ifnum = ifnum; 1067 as->ifnum = ifnum;
1056 as->pid = current->pid; 1068 as->pid = get_pid(task_pid(current));
1057 as->uid = current->uid; 1069 as->uid = current->uid;
1058 as->euid = current->euid; 1070 as->euid = current->euid;
1059 security_task_getsecid(current, &as->secid); 1071 security_task_getsecid(current, &as->secid);
@@ -1322,7 +1334,7 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
1322 } 1334 }
1323 } 1335 }
1324 1336
1325 if (!connected(ps->dev)) { 1337 if (!connected(ps)) {
1326 kfree(buf); 1338 kfree(buf);
1327 return -ENODEV; 1339 return -ENODEV;
1328 } 1340 }
@@ -1349,7 +1361,7 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
1349 /* let kernel drivers try to (re)bind to the interface */ 1361 /* let kernel drivers try to (re)bind to the interface */
1350 case USBDEVFS_CONNECT: 1362 case USBDEVFS_CONNECT:
1351 usb_unlock_device(ps->dev); 1363 usb_unlock_device(ps->dev);
1352 bus_rescan_devices(intf->dev.bus); 1364 retval = bus_rescan_devices(intf->dev.bus);
1353 usb_lock_device(ps->dev); 1365 usb_lock_device(ps->dev);
1354 break; 1366 break;
1355 1367
@@ -1413,7 +1425,7 @@ static int proc_ioctl_compat(struct dev_state *ps, compat_uptr_t arg)
1413 */ 1425 */
1414static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 1426static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1415{ 1427{
1416 struct dev_state *ps = (struct dev_state *)file->private_data; 1428 struct dev_state *ps = file->private_data;
1417 struct usb_device *dev = ps->dev; 1429 struct usb_device *dev = ps->dev;
1418 void __user *p = (void __user *)arg; 1430 void __user *p = (void __user *)arg;
1419 int ret = -ENOTTY; 1431 int ret = -ENOTTY;
@@ -1421,7 +1433,7 @@ static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
1421 if (!(file->f_mode & FMODE_WRITE)) 1433 if (!(file->f_mode & FMODE_WRITE))
1422 return -EPERM; 1434 return -EPERM;
1423 usb_lock_device(dev); 1435 usb_lock_device(dev);
1424 if (!connected(dev)) { 1436 if (!connected(ps)) {
1425 usb_unlock_device(dev); 1437 usb_unlock_device(dev);
1426 return -ENODEV; 1438 return -ENODEV;
1427 } 1439 }
@@ -1556,18 +1568,18 @@ static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
1556/* No kernel lock - fine */ 1568/* No kernel lock - fine */
1557static unsigned int usbdev_poll(struct file *file, struct poll_table_struct *wait) 1569static unsigned int usbdev_poll(struct file *file, struct poll_table_struct *wait)
1558{ 1570{
1559 struct dev_state *ps = (struct dev_state *)file->private_data; 1571 struct dev_state *ps = file->private_data;
1560 unsigned int mask = 0; 1572 unsigned int mask = 0;
1561 1573
1562 poll_wait(file, &ps->wait, wait); 1574 poll_wait(file, &ps->wait, wait);
1563 if (file->f_mode & FMODE_WRITE && !list_empty(&ps->async_completed)) 1575 if (file->f_mode & FMODE_WRITE && !list_empty(&ps->async_completed))
1564 mask |= POLLOUT | POLLWRNORM; 1576 mask |= POLLOUT | POLLWRNORM;
1565 if (!connected(ps->dev)) 1577 if (!connected(ps))
1566 mask |= POLLERR | POLLHUP; 1578 mask |= POLLERR | POLLHUP;
1567 return mask; 1579 return mask;
1568} 1580}
1569 1581
1570struct file_operations usbfs_device_file_operations = { 1582const struct file_operations usbfs_device_file_operations = {
1571 .llseek = usbdev_lseek, 1583 .llseek = usbdev_lseek,
1572 .read = usbdev_read, 1584 .read = usbdev_read,
1573 .poll = usbdev_poll, 1585 .poll = usbdev_poll,
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index ec8906501415..113e484c763e 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -17,12 +17,14 @@
17 * 17 *
18 * NOTE! This is not actually a driver at all, rather this is 18 * NOTE! This is not actually a driver at all, rather this is
19 * just a collection of helper routines that implement the 19 * just a collection of helper routines that implement the
20 * generic USB things that the real drivers can use.. 20 * matching, probing, releasing, suspending and resuming for
21 * real drivers.
21 * 22 *
22 */ 23 */
23 24
24#include <linux/device.h> 25#include <linux/device.h>
25#include <linux/usb.h> 26#include <linux/usb.h>
27#include <linux/workqueue.h>
26#include "hcd.h" 28#include "hcd.h"
27#include "usb.h" 29#include "usb.h"
28 30
@@ -34,38 +36,6 @@ struct usb_dynid {
34 struct usb_device_id id; 36 struct usb_device_id id;
35}; 37};
36 38
37
38static int generic_probe(struct device *dev)
39{
40 return 0;
41}
42static int generic_remove(struct device *dev)
43{
44 struct usb_device *udev = to_usb_device(dev);
45
46 /* if this is only an unbind, not a physical disconnect, then
47 * unconfigure the device */
48 if (udev->state == USB_STATE_CONFIGURED)
49 usb_set_configuration(udev, 0);
50
51 /* in case the call failed or the device was suspended */
52 if (udev->state >= USB_STATE_CONFIGURED)
53 usb_disable_device(udev, 0);
54 return 0;
55}
56
57struct device_driver usb_generic_driver = {
58 .owner = THIS_MODULE,
59 .name = "usb",
60 .bus = &usb_bus_type,
61 .probe = generic_probe,
62 .remove = generic_remove,
63};
64
65/* Fun hack to determine if the struct device is a
66 * usb device or a usb interface. */
67int usb_generic_driver_data;
68
69#ifdef CONFIG_HOTPLUG 39#ifdef CONFIG_HOTPLUG
70 40
71/* 41/*
@@ -80,6 +50,7 @@ static ssize_t store_new_id(struct device_driver *driver,
80 u32 idVendor = 0; 50 u32 idVendor = 0;
81 u32 idProduct = 0; 51 u32 idProduct = 0;
82 int fields = 0; 52 int fields = 0;
53 int retval = 0;
83 54
84 fields = sscanf(buf, "%x %x", &idVendor, &idProduct); 55 fields = sscanf(buf, "%x %x", &idVendor, &idProduct);
85 if (fields < 2) 56 if (fields < 2)
@@ -99,10 +70,12 @@ static ssize_t store_new_id(struct device_driver *driver,
99 spin_unlock(&usb_drv->dynids.lock); 70 spin_unlock(&usb_drv->dynids.lock);
100 71
101 if (get_driver(driver)) { 72 if (get_driver(driver)) {
102 driver_attach(driver); 73 retval = driver_attach(driver);
103 put_driver(driver); 74 put_driver(driver);
104 } 75 }
105 76
77 if (retval)
78 return retval;
106 return count; 79 return count;
107} 80}
108static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id); 81static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
@@ -115,7 +88,7 @@ static int usb_create_newid_file(struct usb_driver *usb_drv)
115 goto exit; 88 goto exit;
116 89
117 if (usb_drv->probe != NULL) 90 if (usb_drv->probe != NULL)
118 error = sysfs_create_file(&usb_drv->driver.kobj, 91 error = sysfs_create_file(&usb_drv->drvwrap.driver.kobj,
119 &driver_attr_new_id.attr); 92 &driver_attr_new_id.attr);
120exit: 93exit:
121 return error; 94 return error;
@@ -127,7 +100,7 @@ static void usb_remove_newid_file(struct usb_driver *usb_drv)
127 return; 100 return;
128 101
129 if (usb_drv->probe != NULL) 102 if (usb_drv->probe != NULL)
130 sysfs_remove_file(&usb_drv->driver.kobj, 103 sysfs_remove_file(&usb_drv->drvwrap.driver.kobj,
131 &driver_attr_new_id.attr); 104 &driver_attr_new_id.attr);
132} 105}
133 106
@@ -174,21 +147,57 @@ static const struct usb_device_id *usb_match_dynamic_id(struct usb_interface *in
174} 147}
175 148
176 149
177/* called from driver core with usb_bus_type.subsys writelock */ 150/* called from driver core with dev locked */
151static int usb_probe_device(struct device *dev)
152{
153 struct usb_device_driver *udriver = to_usb_device_driver(dev->driver);
154 struct usb_device *udev;
155 int error = -ENODEV;
156
157 dev_dbg(dev, "%s\n", __FUNCTION__);
158
159 if (!is_usb_device(dev)) /* Sanity check */
160 return error;
161
162 udev = to_usb_device(dev);
163
164 /* TODO: Add real matching code */
165
166 /* The device should always appear to be in use
167 * unless the driver suports autosuspend.
168 */
169 udev->pm_usage_cnt = !(udriver->supports_autosuspend);
170
171 error = udriver->probe(udev);
172 return error;
173}
174
175/* called from driver core with dev locked */
176static int usb_unbind_device(struct device *dev)
177{
178 struct usb_device_driver *udriver = to_usb_device_driver(dev->driver);
179
180 udriver->disconnect(to_usb_device(dev));
181 return 0;
182}
183
184
185/* called from driver core with dev locked */
178static int usb_probe_interface(struct device *dev) 186static int usb_probe_interface(struct device *dev)
179{ 187{
180 struct usb_interface * intf = to_usb_interface(dev); 188 struct usb_driver *driver = to_usb_driver(dev->driver);
181 struct usb_driver * driver = to_usb_driver(dev->driver); 189 struct usb_interface *intf;
190 struct usb_device *udev;
182 const struct usb_device_id *id; 191 const struct usb_device_id *id;
183 int error = -ENODEV; 192 int error = -ENODEV;
184 193
185 dev_dbg(dev, "%s\n", __FUNCTION__); 194 dev_dbg(dev, "%s\n", __FUNCTION__);
186 195
187 if (!driver->probe) 196 if (is_usb_device(dev)) /* Sanity check */
188 return error; 197 return error;
189 /* FIXME we'd much prefer to just resume it ... */ 198
190 if (interface_to_usbdev(intf)->state == USB_STATE_SUSPENDED) 199 intf = to_usb_interface(dev);
191 return -EHOSTUNREACH; 200 udev = interface_to_usbdev(intf);
192 201
193 id = usb_match_id(intf, driver->id_table); 202 id = usb_match_id(intf, driver->id_table);
194 if (!id) 203 if (!id)
@@ -196,48 +205,165 @@ static int usb_probe_interface(struct device *dev)
196 if (id) { 205 if (id) {
197 dev_dbg(dev, "%s - got id\n", __FUNCTION__); 206 dev_dbg(dev, "%s - got id\n", __FUNCTION__);
198 207
208 error = usb_autoresume_device(udev, 1);
209 if (error)
210 return error;
211
199 /* Interface "power state" doesn't correspond to any hardware 212 /* Interface "power state" doesn't correspond to any hardware
200 * state whatsoever. We use it to record when it's bound to 213 * state whatsoever. We use it to record when it's bound to
201 * a driver that may start I/0: it's not frozen/quiesced. 214 * a driver that may start I/0: it's not frozen/quiesced.
202 */ 215 */
203 mark_active(intf); 216 mark_active(intf);
204 intf->condition = USB_INTERFACE_BINDING; 217 intf->condition = USB_INTERFACE_BINDING;
218
219 /* The interface should always appear to be in use
220 * unless the driver suports autosuspend.
221 */
222 intf->pm_usage_cnt = !(driver->supports_autosuspend);
223
205 error = driver->probe(intf, id); 224 error = driver->probe(intf, id);
206 if (error) { 225 if (error) {
207 mark_quiesced(intf); 226 mark_quiesced(intf);
227 intf->needs_remote_wakeup = 0;
208 intf->condition = USB_INTERFACE_UNBOUND; 228 intf->condition = USB_INTERFACE_UNBOUND;
209 } else 229 } else
210 intf->condition = USB_INTERFACE_BOUND; 230 intf->condition = USB_INTERFACE_BOUND;
231
232 usb_autosuspend_device(udev, 1);
211 } 233 }
212 234
213 return error; 235 return error;
214} 236}
215 237
216/* called from driver core with usb_bus_type.subsys writelock */ 238/* called from driver core with dev locked */
217static int usb_unbind_interface(struct device *dev) 239static int usb_unbind_interface(struct device *dev)
218{ 240{
241 struct usb_driver *driver = to_usb_driver(dev->driver);
219 struct usb_interface *intf = to_usb_interface(dev); 242 struct usb_interface *intf = to_usb_interface(dev);
220 struct usb_driver *driver = to_usb_driver(intf->dev.driver); 243 struct usb_device *udev;
244 int error;
221 245
222 intf->condition = USB_INTERFACE_UNBINDING; 246 intf->condition = USB_INTERFACE_UNBINDING;
223 247
248 /* Autoresume for set_interface call below */
249 udev = interface_to_usbdev(intf);
250 error = usb_autoresume_device(udev, 1);
251
224 /* release all urbs for this interface */ 252 /* release all urbs for this interface */
225 usb_disable_interface(interface_to_usbdev(intf), intf); 253 usb_disable_interface(interface_to_usbdev(intf), intf);
226 254
227 if (driver && driver->disconnect) 255 driver->disconnect(intf);
228 driver->disconnect(intf);
229 256
230 /* reset other interface state */ 257 /* reset other interface state */
231 usb_set_interface(interface_to_usbdev(intf), 258 usb_set_interface(interface_to_usbdev(intf),
232 intf->altsetting[0].desc.bInterfaceNumber, 259 intf->altsetting[0].desc.bInterfaceNumber,
233 0); 260 0);
234 usb_set_intfdata(intf, NULL); 261 usb_set_intfdata(intf, NULL);
262
235 intf->condition = USB_INTERFACE_UNBOUND; 263 intf->condition = USB_INTERFACE_UNBOUND;
236 mark_quiesced(intf); 264 mark_quiesced(intf);
265 intf->needs_remote_wakeup = 0;
266
267 if (!error)
268 usb_autosuspend_device(udev, 1);
237 269
238 return 0; 270 return 0;
239} 271}
240 272
273/**
274 * usb_driver_claim_interface - bind a driver to an interface
275 * @driver: the driver to be bound
276 * @iface: the interface to which it will be bound; must be in the
277 * usb device's active configuration
278 * @priv: driver data associated with that interface
279 *
280 * This is used by usb device drivers that need to claim more than one
281 * interface on a device when probing (audio and acm are current examples).
282 * No device driver should directly modify internal usb_interface or
283 * usb_device structure members.
284 *
285 * Few drivers should need to use this routine, since the most natural
286 * way to bind to an interface is to return the private data from
287 * the driver's probe() method.
288 *
289 * Callers must own the device lock and the driver model's usb_bus_type.subsys
290 * writelock. So driver probe() entries don't need extra locking,
291 * but other call contexts may need to explicitly claim those locks.
292 */
293int usb_driver_claim_interface(struct usb_driver *driver,
294 struct usb_interface *iface, void* priv)
295{
296 struct device *dev = &iface->dev;
297 struct usb_device *udev = interface_to_usbdev(iface);
298 int retval = 0;
299
300 if (dev->driver)
301 return -EBUSY;
302
303 dev->driver = &driver->drvwrap.driver;
304 usb_set_intfdata(iface, priv);
305
306 usb_pm_lock(udev);
307 iface->condition = USB_INTERFACE_BOUND;
308 mark_active(iface);
309 iface->pm_usage_cnt = !(driver->supports_autosuspend);
310 usb_pm_unlock(udev);
311
312 /* if interface was already added, bind now; else let
313 * the future device_add() bind it, bypassing probe()
314 */
315 if (device_is_registered(dev))
316 retval = device_bind_driver(dev);
317
318 return retval;
319}
320EXPORT_SYMBOL(usb_driver_claim_interface);
321
322/**
323 * usb_driver_release_interface - unbind a driver from an interface
324 * @driver: the driver to be unbound
325 * @iface: the interface from which it will be unbound
326 *
327 * This can be used by drivers to release an interface without waiting
328 * for their disconnect() methods to be called. In typical cases this
329 * also causes the driver disconnect() method to be called.
330 *
331 * This call is synchronous, and may not be used in an interrupt context.
332 * Callers must own the device lock and the driver model's usb_bus_type.subsys
333 * writelock. So driver disconnect() entries don't need extra locking,
334 * but other call contexts may need to explicitly claim those locks.
335 */
336void usb_driver_release_interface(struct usb_driver *driver,
337 struct usb_interface *iface)
338{
339 struct device *dev = &iface->dev;
340 struct usb_device *udev = interface_to_usbdev(iface);
341
342 /* this should never happen, don't release something that's not ours */
343 if (!dev->driver || dev->driver != &driver->drvwrap.driver)
344 return;
345
346 /* don't release from within disconnect() */
347 if (iface->condition != USB_INTERFACE_BOUND)
348 return;
349
350 /* don't release if the interface hasn't been added yet */
351 if (device_is_registered(dev)) {
352 iface->condition = USB_INTERFACE_UNBINDING;
353 device_release_driver(dev);
354 }
355
356 dev->driver = NULL;
357 usb_set_intfdata(iface, NULL);
358
359 usb_pm_lock(udev);
360 iface->condition = USB_INTERFACE_UNBOUND;
361 mark_quiesced(iface);
362 iface->needs_remote_wakeup = 0;
363 usb_pm_unlock(udev);
364}
365EXPORT_SYMBOL(usb_driver_release_interface);
366
241/* returns 0 if no match, 1 if match */ 367/* returns 0 if no match, 1 if match */
242static int usb_match_one_id(struct usb_interface *interface, 368static int usb_match_one_id(struct usb_interface *interface,
243 const struct usb_device_id *id) 369 const struct usb_device_id *id)
@@ -381,35 +507,223 @@ EXPORT_SYMBOL_GPL_FUTURE(usb_match_id);
381 507
382int usb_device_match(struct device *dev, struct device_driver *drv) 508int usb_device_match(struct device *dev, struct device_driver *drv)
383{ 509{
510 /* devices and interfaces are handled separately */
511 if (is_usb_device(dev)) {
512
513 /* interface drivers never match devices */
514 if (!is_usb_device_driver(drv))
515 return 0;
516
517 /* TODO: Add real matching code */
518 return 1;
519
520 } else {
521 struct usb_interface *intf;
522 struct usb_driver *usb_drv;
523 const struct usb_device_id *id;
524
525 /* device drivers never match interfaces */
526 if (is_usb_device_driver(drv))
527 return 0;
528
529 intf = to_usb_interface(dev);
530 usb_drv = to_usb_driver(drv);
531
532 id = usb_match_id(intf, usb_drv->id_table);
533 if (id)
534 return 1;
535
536 id = usb_match_dynamic_id(intf, usb_drv);
537 if (id)
538 return 1;
539 }
540
541 return 0;
542}
543
544#ifdef CONFIG_HOTPLUG
545
546/*
547 * This sends an uevent to userspace, typically helping to load driver
548 * or other modules, configure the device, and more. Drivers can provide
549 * a MODULE_DEVICE_TABLE to help with module loading subtasks.
550 *
551 * We're called either from khubd (the typical case) or from root hub
552 * (init, kapmd, modprobe, rmmod, etc), but the agents need to handle
553 * delays in event delivery. Use sysfs (and DEVPATH) to make sure the
554 * device (and this configuration!) are still present.
555 */
556static int usb_uevent(struct device *dev, char **envp, int num_envp,
557 char *buffer, int buffer_size)
558{
384 struct usb_interface *intf; 559 struct usb_interface *intf;
385 struct usb_driver *usb_drv; 560 struct usb_device *usb_dev;
386 const struct usb_device_id *id; 561 struct usb_host_interface *alt;
562 int i = 0;
563 int length = 0;
387 564
388 /* check for generic driver, which we don't match any device with */ 565 if (!dev)
389 if (drv == &usb_generic_driver) 566 return -ENODEV;
390 return 0;
391 567
392 intf = to_usb_interface(dev); 568 /* driver is often null here; dev_dbg() would oops */
393 usb_drv = to_usb_driver(drv); 569 pr_debug ("usb %s: uevent\n", dev->bus_id);
394 570
395 id = usb_match_id(intf, usb_drv->id_table); 571 if (is_usb_device(dev)) {
396 if (id) 572 usb_dev = to_usb_device(dev);
397 return 1; 573 alt = NULL;
574 } else {
575 intf = to_usb_interface(dev);
576 usb_dev = interface_to_usbdev(intf);
577 alt = intf->cur_altsetting;
578 }
579
580 if (usb_dev->devnum < 0) {
581 pr_debug ("usb %s: already deleted?\n", dev->bus_id);
582 return -ENODEV;
583 }
584 if (!usb_dev->bus) {
585 pr_debug ("usb %s: bus removed?\n", dev->bus_id);
586 return -ENODEV;
587 }
588
589#ifdef CONFIG_USB_DEVICEFS
590 /* If this is available, userspace programs can directly read
591 * all the device descriptors we don't tell them about. Or
592 * even act as usermode drivers.
593 *
594 * FIXME reduce hardwired intelligence here
595 */
596 if (add_uevent_var(envp, num_envp, &i,
597 buffer, buffer_size, &length,
598 "DEVICE=/proc/bus/usb/%03d/%03d",
599 usb_dev->bus->busnum, usb_dev->devnum))
600 return -ENOMEM;
601#endif
602
603 /* per-device configurations are common */
604 if (add_uevent_var(envp, num_envp, &i,
605 buffer, buffer_size, &length,
606 "PRODUCT=%x/%x/%x",
607 le16_to_cpu(usb_dev->descriptor.idVendor),
608 le16_to_cpu(usb_dev->descriptor.idProduct),
609 le16_to_cpu(usb_dev->descriptor.bcdDevice)))
610 return -ENOMEM;
611
612 /* class-based driver binding models */
613 if (add_uevent_var(envp, num_envp, &i,
614 buffer, buffer_size, &length,
615 "TYPE=%d/%d/%d",
616 usb_dev->descriptor.bDeviceClass,
617 usb_dev->descriptor.bDeviceSubClass,
618 usb_dev->descriptor.bDeviceProtocol))
619 return -ENOMEM;
620
621 if (!is_usb_device(dev)) {
622
623 if (add_uevent_var(envp, num_envp, &i,
624 buffer, buffer_size, &length,
625 "INTERFACE=%d/%d/%d",
626 alt->desc.bInterfaceClass,
627 alt->desc.bInterfaceSubClass,
628 alt->desc.bInterfaceProtocol))
629 return -ENOMEM;
630
631 if (add_uevent_var(envp, num_envp, &i,
632 buffer, buffer_size, &length,
633 "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X",
634 le16_to_cpu(usb_dev->descriptor.idVendor),
635 le16_to_cpu(usb_dev->descriptor.idProduct),
636 le16_to_cpu(usb_dev->descriptor.bcdDevice),
637 usb_dev->descriptor.bDeviceClass,
638 usb_dev->descriptor.bDeviceSubClass,
639 usb_dev->descriptor.bDeviceProtocol,
640 alt->desc.bInterfaceClass,
641 alt->desc.bInterfaceSubClass,
642 alt->desc.bInterfaceProtocol))
643 return -ENOMEM;
644 }
645
646 envp[i] = NULL;
398 647
399 id = usb_match_dynamic_id(intf, usb_drv);
400 if (id)
401 return 1;
402 return 0; 648 return 0;
403} 649}
404 650
651#else
652
653static int usb_uevent(struct device *dev, char **envp,
654 int num_envp, char *buffer, int buffer_size)
655{
656 return -ENODEV;
657}
658
659#endif /* CONFIG_HOTPLUG */
660
661/**
662 * usb_register_device_driver - register a USB device (not interface) driver
663 * @new_udriver: USB operations for the device driver
664 * @owner: module owner of this driver.
665 *
666 * Registers a USB device driver with the USB core. The list of
667 * unattached devices will be rescanned whenever a new driver is
668 * added, allowing the new driver to attach to any recognized devices.
669 * Returns a negative error code on failure and 0 on success.
670 */
671int usb_register_device_driver(struct usb_device_driver *new_udriver,
672 struct module *owner)
673{
674 int retval = 0;
675
676 if (usb_disabled())
677 return -ENODEV;
678
679 new_udriver->drvwrap.for_devices = 1;
680 new_udriver->drvwrap.driver.name = (char *) new_udriver->name;
681 new_udriver->drvwrap.driver.bus = &usb_bus_type;
682 new_udriver->drvwrap.driver.probe = usb_probe_device;
683 new_udriver->drvwrap.driver.remove = usb_unbind_device;
684 new_udriver->drvwrap.driver.owner = owner;
685
686 retval = driver_register(&new_udriver->drvwrap.driver);
687
688 if (!retval) {
689 pr_info("%s: registered new device driver %s\n",
690 usbcore_name, new_udriver->name);
691 usbfs_update_special();
692 } else {
693 printk(KERN_ERR "%s: error %d registering device "
694 " driver %s\n",
695 usbcore_name, retval, new_udriver->name);
696 }
697
698 return retval;
699}
700EXPORT_SYMBOL_GPL(usb_register_device_driver);
701
702/**
703 * usb_deregister_device_driver - unregister a USB device (not interface) driver
704 * @udriver: USB operations of the device driver to unregister
705 * Context: must be able to sleep
706 *
707 * Unlinks the specified driver from the internal USB driver list.
708 */
709void usb_deregister_device_driver(struct usb_device_driver *udriver)
710{
711 pr_info("%s: deregistering device driver %s\n",
712 usbcore_name, udriver->name);
713
714 driver_unregister(&udriver->drvwrap.driver);
715 usbfs_update_special();
716}
717EXPORT_SYMBOL_GPL(usb_deregister_device_driver);
718
405/** 719/**
406 * usb_register_driver - register a USB driver 720 * usb_register_driver - register a USB interface driver
407 * @new_driver: USB operations for the driver 721 * @new_driver: USB operations for the interface driver
408 * @owner: module owner of this driver. 722 * @owner: module owner of this driver.
409 * 723 *
410 * Registers a USB driver with the USB core. The list of unattached 724 * Registers a USB interface driver with the USB core. The list of
411 * interfaces will be rescanned whenever a new driver is added, allowing 725 * unattached interfaces will be rescanned whenever a new driver is
412 * the new driver to attach to any recognized devices. 726 * added, allowing the new driver to attach to any recognized interfaces.
413 * Returns a negative error code on failure and 0 on success. 727 * Returns a negative error code on failure and 0 on success.
414 * 728 *
415 * NOTE: if you want your driver to use the USB major number, you must call 729 * NOTE: if you want your driver to use the USB major number, you must call
@@ -423,23 +737,25 @@ int usb_register_driver(struct usb_driver *new_driver, struct module *owner)
423 if (usb_disabled()) 737 if (usb_disabled())
424 return -ENODEV; 738 return -ENODEV;
425 739
426 new_driver->driver.name = (char *)new_driver->name; 740 new_driver->drvwrap.for_devices = 0;
427 new_driver->driver.bus = &usb_bus_type; 741 new_driver->drvwrap.driver.name = (char *) new_driver->name;
428 new_driver->driver.probe = usb_probe_interface; 742 new_driver->drvwrap.driver.bus = &usb_bus_type;
429 new_driver->driver.remove = usb_unbind_interface; 743 new_driver->drvwrap.driver.probe = usb_probe_interface;
430 new_driver->driver.owner = owner; 744 new_driver->drvwrap.driver.remove = usb_unbind_interface;
745 new_driver->drvwrap.driver.owner = owner;
431 spin_lock_init(&new_driver->dynids.lock); 746 spin_lock_init(&new_driver->dynids.lock);
432 INIT_LIST_HEAD(&new_driver->dynids.list); 747 INIT_LIST_HEAD(&new_driver->dynids.list);
433 748
434 retval = driver_register(&new_driver->driver); 749 retval = driver_register(&new_driver->drvwrap.driver);
435 750
436 if (!retval) { 751 if (!retval) {
437 pr_info("%s: registered new driver %s\n", 752 pr_info("%s: registered new interface driver %s\n",
438 usbcore_name, new_driver->name); 753 usbcore_name, new_driver->name);
439 usbfs_update_special(); 754 usbfs_update_special();
440 usb_create_newid_file(new_driver); 755 usb_create_newid_file(new_driver);
441 } else { 756 } else {
442 printk(KERN_ERR "%s: error %d registering driver %s\n", 757 printk(KERN_ERR "%s: error %d registering interface "
758 " driver %s\n",
443 usbcore_name, retval, new_driver->name); 759 usbcore_name, retval, new_driver->name);
444 } 760 }
445 761
@@ -448,8 +764,8 @@ int usb_register_driver(struct usb_driver *new_driver, struct module *owner)
448EXPORT_SYMBOL_GPL_FUTURE(usb_register_driver); 764EXPORT_SYMBOL_GPL_FUTURE(usb_register_driver);
449 765
450/** 766/**
451 * usb_deregister - unregister a USB driver 767 * usb_deregister - unregister a USB interface driver
452 * @driver: USB operations of the driver to unregister 768 * @driver: USB operations of the interface driver to unregister
453 * Context: must be able to sleep 769 * Context: must be able to sleep
454 * 770 *
455 * Unlinks the specified driver from the internal USB driver list. 771 * Unlinks the specified driver from the internal USB driver list.
@@ -460,12 +776,554 @@ EXPORT_SYMBOL_GPL_FUTURE(usb_register_driver);
460 */ 776 */
461void usb_deregister(struct usb_driver *driver) 777void usb_deregister(struct usb_driver *driver)
462{ 778{
463 pr_info("%s: deregistering driver %s\n", usbcore_name, driver->name); 779 pr_info("%s: deregistering interface driver %s\n",
780 usbcore_name, driver->name);
464 781
465 usb_remove_newid_file(driver); 782 usb_remove_newid_file(driver);
466 usb_free_dynids(driver); 783 usb_free_dynids(driver);
467 driver_unregister(&driver->driver); 784 driver_unregister(&driver->drvwrap.driver);
468 785
469 usbfs_update_special(); 786 usbfs_update_special();
470} 787}
471EXPORT_SYMBOL_GPL_FUTURE(usb_deregister); 788EXPORT_SYMBOL_GPL_FUTURE(usb_deregister);
789
790#ifdef CONFIG_PM
791
792/* Caller has locked udev's pm_mutex */
793static int suspend_device(struct usb_device *udev, pm_message_t msg)
794{
795 struct usb_device_driver *udriver;
796 int status = 0;
797
798 if (udev->state == USB_STATE_NOTATTACHED ||
799 udev->state == USB_STATE_SUSPENDED)
800 goto done;
801
802 /* For devices that don't have a driver, we do a standard suspend. */
803 if (udev->dev.driver == NULL) {
804 udev->do_remote_wakeup = 0;
805 status = usb_port_suspend(udev);
806 goto done;
807 }
808
809 udriver = to_usb_device_driver(udev->dev.driver);
810 status = udriver->suspend(udev, msg);
811
812done:
813 // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status);
814 if (status == 0)
815 udev->dev.power.power_state.event = msg.event;
816 return status;
817}
818
819/* Caller has locked udev's pm_mutex */
820static int resume_device(struct usb_device *udev)
821{
822 struct usb_device_driver *udriver;
823 int status = 0;
824
825 if (udev->state == USB_STATE_NOTATTACHED ||
826 udev->state != USB_STATE_SUSPENDED)
827 goto done;
828
829 /* Can't resume it if it doesn't have a driver. */
830 if (udev->dev.driver == NULL) {
831 status = -ENOTCONN;
832 goto done;
833 }
834
835 udriver = to_usb_device_driver(udev->dev.driver);
836 status = udriver->resume(udev);
837
838done:
839 // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status);
840 if (status == 0)
841 udev->dev.power.power_state.event = PM_EVENT_ON;
842 return status;
843}
844
845/* Caller has locked intf's usb_device's pm mutex */
846static int suspend_interface(struct usb_interface *intf, pm_message_t msg)
847{
848 struct usb_driver *driver;
849 int status = 0;
850
851 /* with no hardware, USB interfaces only use FREEZE and ON states */
852 if (interface_to_usbdev(intf)->state == USB_STATE_NOTATTACHED ||
853 !is_active(intf))
854 goto done;
855
856 if (intf->condition == USB_INTERFACE_UNBOUND) /* This can't happen */
857 goto done;
858 driver = to_usb_driver(intf->dev.driver);
859
860 if (driver->suspend && driver->resume) {
861 status = driver->suspend(intf, msg);
862 if (status == 0)
863 mark_quiesced(intf);
864 else if (!interface_to_usbdev(intf)->auto_pm)
865 dev_err(&intf->dev, "%s error %d\n",
866 "suspend", status);
867 } else {
868 // FIXME else if there's no suspend method, disconnect...
869 // Not possible if auto_pm is set...
870 dev_warn(&intf->dev, "no suspend for driver %s?\n",
871 driver->name);
872 mark_quiesced(intf);
873 }
874
875done:
876 // dev_dbg(&intf->dev, "%s: status %d\n", __FUNCTION__, status);
877 if (status == 0)
878 intf->dev.power.power_state.event = msg.event;
879 return status;
880}
881
882/* Caller has locked intf's usb_device's pm_mutex */
883static int resume_interface(struct usb_interface *intf)
884{
885 struct usb_driver *driver;
886 int status = 0;
887
888 if (interface_to_usbdev(intf)->state == USB_STATE_NOTATTACHED ||
889 is_active(intf))
890 goto done;
891
892 /* Don't let autoresume interfere with unbinding */
893 if (intf->condition == USB_INTERFACE_UNBINDING)
894 goto done;
895
896 /* Can't resume it if it doesn't have a driver. */
897 if (intf->condition == USB_INTERFACE_UNBOUND) {
898 status = -ENOTCONN;
899 goto done;
900 }
901 driver = to_usb_driver(intf->dev.driver);
902
903 if (driver->resume) {
904 status = driver->resume(intf);
905 if (status)
906 dev_err(&intf->dev, "%s error %d\n",
907 "resume", status);
908 else
909 mark_active(intf);
910 } else {
911 dev_warn(&intf->dev, "no resume for driver %s?\n",
912 driver->name);
913 mark_active(intf);
914 }
915
916done:
917 // dev_dbg(&intf->dev, "%s: status %d\n", __FUNCTION__, status);
918 if (status == 0)
919 intf->dev.power.power_state.event = PM_EVENT_ON;
920 return status;
921}
922
923/**
924 * usb_suspend_both - suspend a USB device and its interfaces
925 * @udev: the usb_device to suspend
926 * @msg: Power Management message describing this state transition
927 *
928 * This is the central routine for suspending USB devices. It calls the
929 * suspend methods for all the interface drivers in @udev and then calls
930 * the suspend method for @udev itself. If an error occurs at any stage,
931 * all the interfaces which were suspended are resumed so that they remain
932 * in the same state as the device.
933 *
934 * If an autosuspend is in progress (@udev->auto_pm is set), the routine
935 * checks first to make sure that neither the device itself or any of its
936 * active interfaces is in use (pm_usage_cnt is greater than 0). If they
937 * are, the autosuspend fails.
938 *
939 * If the suspend succeeds, the routine recursively queues an autosuspend
940 * request for @udev's parent device, thereby propagating the change up
941 * the device tree. If all of the parent's children are now suspended,
942 * the parent will autosuspend in turn.
943 *
944 * The suspend method calls are subject to mutual exclusion under control
945 * of @udev's pm_mutex. Many of these calls are also under the protection
946 * of @udev's device lock (including all requests originating outside the
947 * USB subsystem), but autosuspend requests generated by a child device or
948 * interface driver may not be. Usbcore will insure that the method calls
949 * do not arrive during bind, unbind, or reset operations. However, drivers
950 * must be prepared to handle suspend calls arriving at unpredictable times.
951 * The only way to block such calls is to do an autoresume (preventing
952 * autosuspends) while holding @udev's device lock (preventing outside
953 * suspends).
954 *
955 * The caller must hold @udev->pm_mutex.
956 *
957 * This routine can run only in process context.
958 */
959int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
960{
961 int status = 0;
962 int i = 0;
963 struct usb_interface *intf;
964 struct usb_device *parent = udev->parent;
965
966 cancel_delayed_work(&udev->autosuspend);
967 if (udev->state == USB_STATE_NOTATTACHED)
968 return 0;
969 if (udev->state == USB_STATE_SUSPENDED)
970 return 0;
971
972 udev->do_remote_wakeup = device_may_wakeup(&udev->dev);
973
974 /* For autosuspend, fail fast if anything is in use.
975 * Also fail if any interfaces require remote wakeup but it
976 * isn't available. */
977 if (udev->auto_pm) {
978 if (udev->pm_usage_cnt > 0)
979 return -EBUSY;
980 if (udev->actconfig) {
981 for (; i < udev->actconfig->desc.bNumInterfaces; i++) {
982 intf = udev->actconfig->interface[i];
983 if (!is_active(intf))
984 continue;
985 if (intf->pm_usage_cnt > 0)
986 return -EBUSY;
987 if (intf->needs_remote_wakeup &&
988 !udev->do_remote_wakeup) {
989 dev_dbg(&udev->dev,
990 "remote wakeup needed for autosuspend\n");
991 return -EOPNOTSUPP;
992 }
993 }
994 i = 0;
995 }
996 }
997
998 /* Suspend all the interfaces and then udev itself */
999 if (udev->actconfig) {
1000 for (; i < udev->actconfig->desc.bNumInterfaces; i++) {
1001 intf = udev->actconfig->interface[i];
1002 status = suspend_interface(intf, msg);
1003 if (status != 0)
1004 break;
1005 }
1006 }
1007 if (status == 0)
1008 status = suspend_device(udev, msg);
1009
1010 /* If the suspend failed, resume interfaces that did get suspended */
1011 if (status != 0) {
1012 while (--i >= 0) {
1013 intf = udev->actconfig->interface[i];
1014 resume_interface(intf);
1015 }
1016
1017 /* If the suspend succeeded, propagate it up the tree */
1018 } else if (parent)
1019 usb_autosuspend_device(parent, 0);
1020
1021 // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status);
1022 return status;
1023}
1024
1025/**
1026 * usb_resume_both - resume a USB device and its interfaces
1027 * @udev: the usb_device to resume
1028 *
1029 * This is the central routine for resuming USB devices. It calls the
1030 * the resume method for @udev and then calls the resume methods for all
1031 * the interface drivers in @udev.
1032 *
1033 * Before starting the resume, the routine calls itself recursively for
1034 * the parent device of @udev, thereby propagating the change up the device
1035 * tree and assuring that @udev will be able to resume. If the parent is
1036 * unable to resume successfully, the routine fails.
1037 *
1038 * The resume method calls are subject to mutual exclusion under control
1039 * of @udev's pm_mutex. Many of these calls are also under the protection
1040 * of @udev's device lock (including all requests originating outside the
1041 * USB subsystem), but autoresume requests generated by a child device or
1042 * interface driver may not be. Usbcore will insure that the method calls
1043 * do not arrive during bind, unbind, or reset operations. However, drivers
1044 * must be prepared to handle resume calls arriving at unpredictable times.
1045 * The only way to block such calls is to do an autoresume (preventing
1046 * other autoresumes) while holding @udev's device lock (preventing outside
1047 * resumes).
1048 *
1049 * The caller must hold @udev->pm_mutex.
1050 *
1051 * This routine can run only in process context.
1052 */
1053int usb_resume_both(struct usb_device *udev)
1054{
1055 int status = 0;
1056 int i;
1057 struct usb_interface *intf;
1058 struct usb_device *parent = udev->parent;
1059
1060 cancel_delayed_work(&udev->autosuspend);
1061 if (udev->state == USB_STATE_NOTATTACHED)
1062 return -ENODEV;
1063
1064 /* Propagate the resume up the tree, if necessary */
1065 if (udev->state == USB_STATE_SUSPENDED) {
1066 if (parent) {
1067 usb_pm_lock(parent);
1068 parent->auto_pm = 1;
1069 status = usb_resume_both(parent);
1070 } else {
1071
1072 /* We can't progagate beyond the USB subsystem,
1073 * so if a root hub's controller is suspended
1074 * then we're stuck. */
1075 if (udev->dev.parent->power.power_state.event !=
1076 PM_EVENT_ON)
1077 status = -EHOSTUNREACH;
1078 }
1079 if (status == 0)
1080 status = resume_device(udev);
1081 if (parent)
1082 usb_pm_unlock(parent);
1083 } else {
1084
1085 /* Needed only for setting udev->dev.power.power_state.event
1086 * and for possible debugging message. */
1087 status = resume_device(udev);
1088 }
1089
1090 /* Now the parent won't suspend until we are finished */
1091
1092 if (status == 0 && udev->actconfig) {
1093 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) {
1094 intf = udev->actconfig->interface[i];
1095 resume_interface(intf);
1096 }
1097 }
1098
1099 // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status);
1100 return status;
1101}
1102
1103#ifdef CONFIG_USB_SUSPEND
1104
1105/**
1106 * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces
1107 * @udev: the usb_device to autosuspend
1108 * @dec_usage_cnt: flag to decrement @udev's PM-usage counter
1109 *
1110 * This routine should be called when a core subsystem is finished using
1111 * @udev and wants to allow it to autosuspend. Examples would be when
1112 * @udev's device file in usbfs is closed or after a configuration change.
1113 *
1114 * @dec_usage_cnt should be 1 if the subsystem previously incremented
1115 * @udev's usage counter (such as by passing 1 to usb_autoresume_device);
1116 * otherwise it should be 0.
1117 *
1118 * If the usage counter for @udev or any of its active interfaces is greater
1119 * than 0, the autosuspend request will not be queued. (If an interface
1120 * driver does not support autosuspend then its usage counter is permanently
1121 * positive.) Likewise, if an interface driver requires remote-wakeup
1122 * capability during autosuspend but remote wakeup is disabled, the
1123 * autosuspend will fail.
1124 *
1125 * Often the caller will hold @udev's device lock, but this is not
1126 * necessary.
1127 *
1128 * This routine can run only in process context.
1129 */
1130void usb_autosuspend_device(struct usb_device *udev, int dec_usage_cnt)
1131{
1132 usb_pm_lock(udev);
1133 udev->pm_usage_cnt -= dec_usage_cnt;
1134 if (udev->pm_usage_cnt <= 0)
1135 queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend,
1136 USB_AUTOSUSPEND_DELAY);
1137 usb_pm_unlock(udev);
1138 // dev_dbg(&udev->dev, "%s: cnt %d\n",
1139 // __FUNCTION__, udev->pm_usage_cnt);
1140}
1141
1142/**
1143 * usb_autoresume_device - immediately autoresume a USB device and its interfaces
1144 * @udev: the usb_device to autoresume
1145 * @inc_usage_cnt: flag to increment @udev's PM-usage counter
1146 *
1147 * This routine should be called when a core subsystem wants to use @udev
1148 * and needs to guarantee that it is not suspended. In addition, the
1149 * caller can prevent @udev from being autosuspended subsequently. (Note
1150 * that this will not prevent suspend events originating in the PM core.)
1151 * Examples would be when @udev's device file in usbfs is opened (autosuspend
1152 * should be prevented until the file is closed) or when a remote-wakeup
1153 * request is received (later autosuspends should not be prevented).
1154 *
1155 * @inc_usage_cnt should be 1 to increment @udev's usage counter and prevent
1156 * autosuspends. This prevention will persist until the usage counter is
1157 * decremented again (such as by passing 1 to usb_autosuspend_device).
1158 * Otherwise @inc_usage_cnt should be 0 to leave the usage counter unchanged.
1159 * Regardless, if the autoresume fails then the usage counter is not
1160 * incremented.
1161 *
1162 * Often the caller will hold @udev's device lock, but this is not
1163 * necessary (and attempting it might cause deadlock).
1164 *
1165 * This routine can run only in process context.
1166 */
1167int usb_autoresume_device(struct usb_device *udev, int inc_usage_cnt)
1168{
1169 int status;
1170
1171 usb_pm_lock(udev);
1172 udev->pm_usage_cnt += inc_usage_cnt;
1173 udev->auto_pm = 1;
1174 status = usb_resume_both(udev);
1175 if (status != 0)
1176 udev->pm_usage_cnt -= inc_usage_cnt;
1177 usb_pm_unlock(udev);
1178 // dev_dbg(&udev->dev, "%s: status %d cnt %d\n",
1179 // __FUNCTION__, status, udev->pm_usage_cnt);
1180 return status;
1181}
1182
1183/**
1184 * usb_autopm_put_interface - decrement a USB interface's PM-usage counter
1185 * @intf: the usb_interface whose counter should be decremented
1186 *
1187 * This routine should be called by an interface driver when it is
1188 * finished using @intf and wants to allow it to autosuspend. A typical
1189 * example would be a character-device driver when its device file is
1190 * closed.
1191 *
1192 * The routine decrements @intf's usage counter. When the counter reaches
1193 * 0, a delayed autosuspend request for @intf's device is queued. When
1194 * the delay expires, if @intf->pm_usage_cnt is still <= 0 along with all
1195 * the other usage counters for the sibling interfaces and @intf's
1196 * usb_device, the device and all its interfaces will be autosuspended.
1197 *
1198 * Note that @intf->pm_usage_cnt is owned by the interface driver. The
1199 * core will not change its value other than the increment and decrement
1200 * in usb_autopm_get_interface and usb_autopm_put_interface. The driver
1201 * may use this simple counter-oriented discipline or may set the value
1202 * any way it likes.
1203 *
1204 * If the driver has set @intf->needs_remote_wakeup then autosuspend will
1205 * take place only if the device's remote-wakeup facility is enabled.
1206 *
1207 * Suspend method calls queued by this routine can arrive at any time
1208 * while @intf is resumed and its usage counter is equal to 0. They are
1209 * not protected by the usb_device's lock but only by its pm_mutex.
1210 * Drivers must provide their own synchronization.
1211 *
1212 * This routine can run only in process context.
1213 */
1214void usb_autopm_put_interface(struct usb_interface *intf)
1215{
1216 struct usb_device *udev = interface_to_usbdev(intf);
1217
1218 usb_pm_lock(udev);
1219 if (intf->condition != USB_INTERFACE_UNBOUND &&
1220 --intf->pm_usage_cnt <= 0) {
1221 queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend,
1222 USB_AUTOSUSPEND_DELAY);
1223 }
1224 usb_pm_unlock(udev);
1225 // dev_dbg(&intf->dev, "%s: cnt %d\n",
1226 // __FUNCTION__, intf->pm_usage_cnt);
1227}
1228EXPORT_SYMBOL_GPL(usb_autopm_put_interface);
1229
1230/**
1231 * usb_autopm_get_interface - increment a USB interface's PM-usage counter
1232 * @intf: the usb_interface whose counter should be incremented
1233 *
1234 * This routine should be called by an interface driver when it wants to
1235 * use @intf and needs to guarantee that it is not suspended. In addition,
1236 * the routine prevents @intf from being autosuspended subsequently. (Note
1237 * that this will not prevent suspend events originating in the PM core.)
1238 * This prevention will persist until usb_autopm_put_interface() is called
1239 * or @intf is unbound. A typical example would be a character-device
1240 * driver when its device file is opened.
1241 *
1242 * The routine increments @intf's usage counter. So long as the counter
1243 * is greater than 0, autosuspend will not be allowed for @intf or its
1244 * usb_device. When the driver is finished using @intf it should call
1245 * usb_autopm_put_interface() to decrement the usage counter and queue
1246 * a delayed autosuspend request (if the counter is <= 0).
1247 *
1248 * Note that @intf->pm_usage_cnt is owned by the interface driver. The
1249 * core will not change its value other than the increment and decrement
1250 * in usb_autopm_get_interface and usb_autopm_put_interface. The driver
1251 * may use this simple counter-oriented discipline or may set the value
1252 * any way it likes.
1253 *
1254 * Resume method calls generated by this routine can arrive at any time
1255 * while @intf is suspended. They are not protected by the usb_device's
1256 * lock but only by its pm_mutex. Drivers must provide their own
1257 * synchronization.
1258 *
1259 * This routine can run only in process context.
1260 */
1261int usb_autopm_get_interface(struct usb_interface *intf)
1262{
1263 struct usb_device *udev = interface_to_usbdev(intf);
1264 int status;
1265
1266 usb_pm_lock(udev);
1267 if (intf->condition == USB_INTERFACE_UNBOUND)
1268 status = -ENODEV;
1269 else {
1270 ++intf->pm_usage_cnt;
1271 udev->auto_pm = 1;
1272 status = usb_resume_both(udev);
1273 if (status != 0)
1274 --intf->pm_usage_cnt;
1275 }
1276 usb_pm_unlock(udev);
1277 // dev_dbg(&intf->dev, "%s: status %d cnt %d\n",
1278 // __FUNCTION__, status, intf->pm_usage_cnt);
1279 return status;
1280}
1281EXPORT_SYMBOL_GPL(usb_autopm_get_interface);
1282
1283#endif /* CONFIG_USB_SUSPEND */
1284
1285static int usb_suspend(struct device *dev, pm_message_t message)
1286{
1287 int status;
1288
1289 if (is_usb_device(dev)) {
1290 struct usb_device *udev = to_usb_device(dev);
1291
1292 usb_pm_lock(udev);
1293 udev->auto_pm = 0;
1294 status = usb_suspend_both(udev, message);
1295 usb_pm_unlock(udev);
1296 } else
1297 status = 0;
1298 return status;
1299}
1300
1301static int usb_resume(struct device *dev)
1302{
1303 int status;
1304
1305 if (is_usb_device(dev)) {
1306 struct usb_device *udev = to_usb_device(dev);
1307
1308 usb_pm_lock(udev);
1309 udev->auto_pm = 0;
1310 status = usb_resume_both(udev);
1311 usb_pm_unlock(udev);
1312
1313 /* Rebind drivers that had no suspend method? */
1314 } else
1315 status = 0;
1316 return status;
1317}
1318
1319#endif /* CONFIG_PM */
1320
1321struct bus_type usb_bus_type = {
1322 .name = "usb",
1323 .match = usb_device_match,
1324 .uevent = usb_uevent,
1325#ifdef CONFIG_PM
1326 .suspend = usb_suspend,
1327 .resume = usb_resume,
1328#endif
1329};
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
index 247b5a4913a8..3ebb90149e93 100644
--- a/drivers/usb/core/endpoint.c
+++ b/drivers/usb/core/endpoint.c
@@ -207,9 +207,9 @@ static void ep_device_release(struct device *dev)
207 kfree(ep_dev); 207 kfree(ep_dev);
208} 208}
209 209
210void usb_create_ep_files(struct device *parent, 210int usb_create_ep_files(struct device *parent,
211 struct usb_host_endpoint *endpoint, 211 struct usb_host_endpoint *endpoint,
212 struct usb_device *udev) 212 struct usb_device *udev)
213{ 213{
214 char name[8]; 214 char name[8];
215 struct ep_device *ep_dev; 215 struct ep_device *ep_dev;
@@ -242,19 +242,33 @@ void usb_create_ep_files(struct device *parent,
242 retval = device_register(&ep_dev->dev); 242 retval = device_register(&ep_dev->dev);
243 if (retval) 243 if (retval)
244 goto error; 244 goto error;
245 sysfs_create_group(&ep_dev->dev.kobj, &ep_dev_attr_grp); 245 retval = sysfs_create_group(&ep_dev->dev.kobj, &ep_dev_attr_grp);
246 if (retval)
247 goto error_group;
246 248
247 endpoint->ep_dev = ep_dev; 249 endpoint->ep_dev = ep_dev;
248 250
249 /* create the symlink to the old-style "ep_XX" directory */ 251 /* create the symlink to the old-style "ep_XX" directory */
250 sprintf(name, "ep_%02x", endpoint->desc.bEndpointAddress); 252 sprintf(name, "ep_%02x", endpoint->desc.bEndpointAddress);
251 sysfs_create_link(&parent->kobj, &endpoint->ep_dev->dev.kobj, name); 253 retval = sysfs_create_link(&parent->kobj,
252 254 &endpoint->ep_dev->dev.kobj, name);
255 if (retval)
256 goto error_link;
253exit: 257exit:
254 return; 258 return retval;
259
260error_link:
261 sysfs_remove_group(&ep_dev->dev.kobj, &ep_dev_attr_grp);
262
263error_group:
264 device_unregister(&ep_dev->dev);
265 endpoint->ep_dev = NULL;
266 destroy_endpoint_class();
267 return retval;
255error: 268error:
256 kfree(ep_dev); 269 kfree(ep_dev);
257 return; 270 destroy_endpoint_class();
271 return retval;
258} 272}
259 273
260void usb_remove_ep_files(struct usb_host_endpoint *endpoint) 274void usb_remove_ep_files(struct usb_host_endpoint *endpoint)
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index 8de4f8c99d61..c376c655c5de 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -55,7 +55,7 @@ static int usb_open(struct inode * inode, struct file * file)
55 return err; 55 return err;
56} 56}
57 57
58static struct file_operations usb_fops = { 58static const struct file_operations usb_fops = {
59 .owner = THIS_MODULE, 59 .owner = THIS_MODULE,
60 .open = usb_open, 60 .open = usb_open,
61}; 61};
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c
new file mode 100644
index 000000000000..16332cc57946
--- /dev/null
+++ b/drivers/usb/core/generic.c
@@ -0,0 +1,208 @@
1/*
2 * drivers/usb/generic.c - generic driver for USB devices (not interfaces)
3 *
4 * (C) Copyright 2005 Greg Kroah-Hartman <gregkh@suse.de>
5 *
6 * based on drivers/usb/usb.c which had the following copyrights:
7 * (C) Copyright Linus Torvalds 1999
8 * (C) Copyright Johannes Erdfelt 1999-2001
9 * (C) Copyright Andreas Gal 1999
10 * (C) Copyright Gregory P. Smith 1999
11 * (C) Copyright Deti Fliegl 1999 (new USB architecture)
12 * (C) Copyright Randy Dunlap 2000
13 * (C) Copyright David Brownell 2000-2004
14 * (C) Copyright Yggdrasil Computing, Inc. 2000
15 * (usb_device_id matching changes by Adam J. Richter)
16 * (C) Copyright Greg Kroah-Hartman 2002-2003
17 *
18 */
19
20#include <linux/config.h>
21#include <linux/usb.h>
22#include "usb.h"
23
24static inline const char *plural(int n)
25{
26 return (n == 1 ? "" : "s");
27}
28
29static int choose_configuration(struct usb_device *udev)
30{
31 int i;
32 int num_configs;
33 int insufficient_power = 0;
34 struct usb_host_config *c, *best;
35
36 best = NULL;
37 c = udev->config;
38 num_configs = udev->descriptor.bNumConfigurations;
39 for (i = 0; i < num_configs; (i++, c++)) {
40 struct usb_interface_descriptor *desc = NULL;
41
42 /* It's possible that a config has no interfaces! */
43 if (c->desc.bNumInterfaces > 0)
44 desc = &c->intf_cache[0]->altsetting->desc;
45
46 /*
47 * HP's USB bus-powered keyboard has only one configuration
48 * and it claims to be self-powered; other devices may have
49 * similar errors in their descriptors. If the next test
50 * were allowed to execute, such configurations would always
51 * be rejected and the devices would not work as expected.
52 * In the meantime, we run the risk of selecting a config
53 * that requires external power at a time when that power
54 * isn't available. It seems to be the lesser of two evils.
55 *
56 * Bugzilla #6448 reports a device that appears to crash
57 * when it receives a GET_DEVICE_STATUS request! We don't
58 * have any other way to tell whether a device is self-powered,
59 * but since we don't use that information anywhere but here,
60 * the call has been removed.
61 *
62 * Maybe the GET_DEVICE_STATUS call and the test below can
63 * be reinstated when device firmwares become more reliable.
64 * Don't hold your breath.
65 */
66#if 0
67 /* Rule out self-powered configs for a bus-powered device */
68 if (bus_powered && (c->desc.bmAttributes &
69 USB_CONFIG_ATT_SELFPOWER))
70 continue;
71#endif
72
73 /*
74 * The next test may not be as effective as it should be.
75 * Some hubs have errors in their descriptor, claiming
76 * to be self-powered when they are really bus-powered.
77 * We will overestimate the amount of current such hubs
78 * make available for each port.
79 *
80 * This is a fairly benign sort of failure. It won't
81 * cause us to reject configurations that we should have
82 * accepted.
83 */
84
85 /* Rule out configs that draw too much bus current */
86 if (c->desc.bMaxPower * 2 > udev->bus_mA) {
87 insufficient_power++;
88 continue;
89 }
90
91 /* If the first config's first interface is COMM/2/0xff
92 * (MSFT RNDIS), rule it out unless Linux has host-side
93 * RNDIS support. */
94 if (i == 0 && desc
95 && desc->bInterfaceClass == USB_CLASS_COMM
96 && desc->bInterfaceSubClass == 2
97 && desc->bInterfaceProtocol == 0xff) {
98#ifndef CONFIG_USB_NET_RNDIS_HOST
99 continue;
100#else
101 best = c;
102#endif
103 }
104
105 /* From the remaining configs, choose the first one whose
106 * first interface is for a non-vendor-specific class.
107 * Reason: Linux is more likely to have a class driver
108 * than a vendor-specific driver. */
109 else if (udev->descriptor.bDeviceClass !=
110 USB_CLASS_VENDOR_SPEC &&
111 (!desc || desc->bInterfaceClass !=
112 USB_CLASS_VENDOR_SPEC)) {
113 best = c;
114 break;
115 }
116
117 /* If all the remaining configs are vendor-specific,
118 * choose the first one. */
119 else if (!best)
120 best = c;
121 }
122
123 if (insufficient_power > 0)
124 dev_info(&udev->dev, "rejected %d configuration%s "
125 "due to insufficient available bus power\n",
126 insufficient_power, plural(insufficient_power));
127
128 if (best) {
129 i = best->desc.bConfigurationValue;
130 dev_info(&udev->dev,
131 "configuration #%d chosen from %d choice%s\n",
132 i, num_configs, plural(num_configs));
133 } else {
134 i = -1;
135 dev_warn(&udev->dev,
136 "no configuration chosen from %d choice%s\n",
137 num_configs, plural(num_configs));
138 }
139 return i;
140}
141
142static int generic_probe(struct usb_device *udev)
143{
144 int err, c;
145
146 /* put device-specific files into sysfs */
147 usb_create_sysfs_dev_files(udev);
148
149 /* Choose and set the configuration. This registers the interfaces
150 * with the driver core and lets interface drivers bind to them.
151 */
152 c = choose_configuration(udev);
153 if (c >= 0) {
154 err = usb_set_configuration(udev, c);
155 if (err) {
156 dev_err(&udev->dev, "can't set config #%d, error %d\n",
157 c, err);
158 /* This need not be fatal. The user can try to
159 * set other configurations. */
160 }
161 }
162
163 /* USB device state == configured ... usable */
164 usb_notify_add_device(udev);
165
166 return 0;
167}
168
169static void generic_disconnect(struct usb_device *udev)
170{
171 usb_notify_remove_device(udev);
172
173 /* if this is only an unbind, not a physical disconnect, then
174 * unconfigure the device */
175 if (udev->actconfig)
176 usb_set_configuration(udev, 0);
177
178 usb_remove_sysfs_dev_files(udev);
179}
180
181#ifdef CONFIG_PM
182
183static int generic_suspend(struct usb_device *udev, pm_message_t msg)
184{
185 /* USB devices enter SUSPEND state through their hubs, but can be
186 * marked for FREEZE as soon as their children are already idled.
187 * But those semantics are useless, so we equate the two (sigh).
188 */
189 return usb_port_suspend(udev);
190}
191
192static int generic_resume(struct usb_device *udev)
193{
194 return usb_port_resume(udev);
195}
196
197#endif /* CONFIG_PM */
198
199struct usb_device_driver usb_generic_driver = {
200 .name = "usb",
201 .probe = generic_probe,
202 .disconnect = generic_disconnect,
203#ifdef CONFIG_PM
204 .suspend = generic_suspend,
205 .resume = generic_resume,
206#endif
207 .supports_autosuspend = 1,
208};
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 5078fb3375e3..edf4300a3f7a 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -281,7 +281,7 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message)
281 (void) usb_hcd_pci_resume (dev); 281 (void) usb_hcd_pci_resume (dev);
282 } 282 }
283 283
284 } else { 284 } else if (hcd->state != HC_STATE_HALT) {
285 dev_dbg (hcd->self.controller, "hcd state %d; not suspended\n", 285 dev_dbg (hcd->self.controller, "hcd state %d; not suspended\n",
286 hcd->state); 286 hcd->state);
287 WARN_ON(1); 287 WARN_ON(1);
@@ -413,4 +413,20 @@ EXPORT_SYMBOL (usb_hcd_pci_resume);
413 413
414#endif /* CONFIG_PM */ 414#endif /* CONFIG_PM */
415 415
416/**
417 * usb_hcd_pci_shutdown - shutdown host controller
418 * @dev: USB Host Controller being shutdown
419 */
420void usb_hcd_pci_shutdown (struct pci_dev *dev)
421{
422 struct usb_hcd *hcd;
423
424 hcd = pci_get_drvdata(dev);
425 if (!hcd)
426 return;
427
428 if (hcd->driver->shutdown)
429 hcd->driver->shutdown(hcd);
430}
431EXPORT_SYMBOL (usb_hcd_pci_shutdown);
416 432
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index fb4d058bbde0..e658089f7b50 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -36,6 +36,7 @@
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <asm/irq.h> 37#include <asm/irq.h>
38#include <asm/byteorder.h> 38#include <asm/byteorder.h>
39#include <linux/platform_device.h>
39 40
40#include <linux/usb.h> 41#include <linux/usb.h>
41 42
@@ -317,8 +318,8 @@ static int rh_string (
317 318
318 // id 3 == vendor description 319 // id 3 == vendor description
319 } else if (id == 3) { 320 } else if (id == 3) {
320 snprintf (buf, sizeof buf, "%s %s %s", system_utsname.sysname, 321 snprintf (buf, sizeof buf, "%s %s %s", init_utsname()->sysname,
321 system_utsname.release, hcd->driver->description); 322 init_utsname()->release, hcd->driver->description);
322 323
323 // unsupported IDs --> "protocol stall" 324 // unsupported IDs --> "protocol stall"
324 } else 325 } else
@@ -344,7 +345,8 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
344 struct usb_ctrlrequest *cmd; 345 struct usb_ctrlrequest *cmd;
345 u16 typeReq, wValue, wIndex, wLength; 346 u16 typeReq, wValue, wIndex, wLength;
346 u8 *ubuf = urb->transfer_buffer; 347 u8 *ubuf = urb->transfer_buffer;
347 u8 tbuf [sizeof (struct usb_hub_descriptor)]; 348 u8 tbuf [sizeof (struct usb_hub_descriptor)]
349 __attribute__((aligned(4)));
348 const u8 *bufp = tbuf; 350 const u8 *bufp = tbuf;
349 int len = 0; 351 int len = 0;
350 int patch_wakeup = 0; 352 int patch_wakeup = 0;
@@ -632,31 +634,20 @@ static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb)
632 634
633/*-------------------------------------------------------------------------*/ 635/*-------------------------------------------------------------------------*/
634 636
635/* Asynchronous unlinks of root-hub control URBs are legal, but they 637/* Unlinks of root-hub control URBs are legal, but they don't do anything
636 * don't do anything. Status URB unlinks must be made in process context 638 * since these URBs always execute synchronously.
637 * with interrupts enabled.
638 */ 639 */
639static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) 640static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
640{ 641{
641 if (usb_pipeendpoint(urb->pipe) == 0) { /* Control URB */ 642 unsigned long flags;
642 if (in_interrupt())
643 return 0; /* nothing to do */
644
645 spin_lock_irq(&urb->lock); /* from usb_kill_urb */
646 ++urb->reject;
647 spin_unlock_irq(&urb->lock);
648
649 wait_event(usb_kill_urb_queue,
650 atomic_read(&urb->use_count) == 0);
651 643
652 spin_lock_irq(&urb->lock); 644 if (usb_pipeendpoint(urb->pipe) == 0) { /* Control URB */
653 --urb->reject; 645 ; /* Do nothing */
654 spin_unlock_irq(&urb->lock);
655 646
656 } else { /* Status URB */ 647 } else { /* Status URB */
657 if (!hcd->uses_new_polling) 648 if (!hcd->uses_new_polling)
658 del_timer_sync (&hcd->rh_timer); 649 del_timer (&hcd->rh_timer);
659 local_irq_disable (); 650 local_irq_save (flags);
660 spin_lock (&hcd_root_hub_lock); 651 spin_lock (&hcd_root_hub_lock);
661 if (urb == hcd->status_urb) { 652 if (urb == hcd->status_urb) {
662 hcd->status_urb = NULL; 653 hcd->status_urb = NULL;
@@ -666,7 +657,7 @@ static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
666 spin_unlock (&hcd_root_hub_lock); 657 spin_unlock (&hcd_root_hub_lock);
667 if (urb) 658 if (urb)
668 usb_hcd_giveback_urb (hcd, urb, NULL); 659 usb_hcd_giveback_urb (hcd, urb, NULL);
669 local_irq_enable (); 660 local_irq_restore (flags);
670 } 661 }
671 662
672 return 0; 663 return 0;
@@ -674,31 +665,6 @@ static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
674 665
675/*-------------------------------------------------------------------------*/ 666/*-------------------------------------------------------------------------*/
676 667
677/* exported only within usbcore */
678struct usb_bus *usb_bus_get(struct usb_bus *bus)
679{
680 if (bus)
681 kref_get(&bus->kref);
682 return bus;
683}
684
685static void usb_host_release(struct kref *kref)
686{
687 struct usb_bus *bus = container_of(kref, struct usb_bus, kref);
688
689 if (bus->release)
690 bus->release(bus);
691}
692
693/* exported only within usbcore */
694void usb_bus_put(struct usb_bus *bus)
695{
696 if (bus)
697 kref_put(&bus->kref, usb_host_release);
698}
699
700/*-------------------------------------------------------------------------*/
701
702static struct class *usb_host_class; 668static struct class *usb_host_class;
703 669
704int usb_host_init(void) 670int usb_host_init(void)
@@ -730,39 +696,12 @@ static void usb_bus_init (struct usb_bus *bus)
730 bus->devnum_next = 1; 696 bus->devnum_next = 1;
731 697
732 bus->root_hub = NULL; 698 bus->root_hub = NULL;
733 bus->hcpriv = NULL;
734 bus->busnum = -1; 699 bus->busnum = -1;
735 bus->bandwidth_allocated = 0; 700 bus->bandwidth_allocated = 0;
736 bus->bandwidth_int_reqs = 0; 701 bus->bandwidth_int_reqs = 0;
737 bus->bandwidth_isoc_reqs = 0; 702 bus->bandwidth_isoc_reqs = 0;
738 703
739 INIT_LIST_HEAD (&bus->bus_list); 704 INIT_LIST_HEAD (&bus->bus_list);
740
741 kref_init(&bus->kref);
742}
743
744/**
745 * usb_alloc_bus - creates a new USB host controller structure
746 * @op: pointer to a struct usb_operations that this bus structure should use
747 * Context: !in_interrupt()
748 *
749 * Creates a USB host controller bus structure with the specified
750 * usb_operations and initializes all the necessary internal objects.
751 *
752 * If no memory is available, NULL is returned.
753 *
754 * The caller should call usb_put_bus() when it is finished with the structure.
755 */
756struct usb_bus *usb_alloc_bus (struct usb_operations *op)
757{
758 struct usb_bus *bus;
759
760 bus = kzalloc (sizeof *bus, GFP_KERNEL);
761 if (!bus)
762 return NULL;
763 usb_bus_init (bus);
764 bus->op = op;
765 return bus;
766} 705}
767 706
768/*-------------------------------------------------------------------------*/ 707/*-------------------------------------------------------------------------*/
@@ -897,8 +836,7 @@ void usb_enable_root_hub_irq (struct usb_bus *bus)
897 struct usb_hcd *hcd; 836 struct usb_hcd *hcd;
898 837
899 hcd = container_of (bus, struct usb_hcd, self); 838 hcd = container_of (bus, struct usb_hcd, self);
900 if (hcd->driver->hub_irq_enable && !hcd->poll_rh && 839 if (hcd->driver->hub_irq_enable && hcd->state != HC_STATE_HALT)
901 hcd->state != HC_STATE_HALT)
902 hcd->driver->hub_irq_enable (hcd); 840 hcd->driver->hub_irq_enable (hcd);
903} 841}
904 842
@@ -1112,10 +1050,10 @@ static void urb_unlink (struct urb *urb)
1112 * expects usb_submit_urb() to have sanity checked and conditioned all 1050 * expects usb_submit_urb() to have sanity checked and conditioned all
1113 * inputs in the urb 1051 * inputs in the urb
1114 */ 1052 */
1115static int hcd_submit_urb (struct urb *urb, gfp_t mem_flags) 1053int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
1116{ 1054{
1117 int status; 1055 int status;
1118 struct usb_hcd *hcd = urb->dev->bus->hcpriv; 1056 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus);
1119 struct usb_host_endpoint *ep; 1057 struct usb_host_endpoint *ep;
1120 unsigned long flags; 1058 unsigned long flags;
1121 1059
@@ -1186,7 +1124,7 @@ doit:
1186 /* lower level hcd code should use *_dma exclusively, 1124 /* lower level hcd code should use *_dma exclusively,
1187 * unless it uses pio or talks to another transport. 1125 * unless it uses pio or talks to another transport.
1188 */ 1126 */
1189 if (hcd->self.controller->dma_mask) { 1127 if (hcd->self.uses_dma) {
1190 if (usb_pipecontrol (urb->pipe) 1128 if (usb_pipecontrol (urb->pipe)
1191 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) 1129 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP))
1192 urb->setup_dma = dma_map_single ( 1130 urb->setup_dma = dma_map_single (
@@ -1221,9 +1159,10 @@ done:
1221/*-------------------------------------------------------------------------*/ 1159/*-------------------------------------------------------------------------*/
1222 1160
1223/* called in any context */ 1161/* called in any context */
1224static int hcd_get_frame_number (struct usb_device *udev) 1162int usb_hcd_get_frame_number (struct usb_device *udev)
1225{ 1163{
1226 struct usb_hcd *hcd = (struct usb_hcd *)udev->bus->hcpriv; 1164 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
1165
1227 if (!HC_IS_RUNNING (hcd->state)) 1166 if (!HC_IS_RUNNING (hcd->state))
1228 return -ESHUTDOWN; 1167 return -ESHUTDOWN;
1229 return hcd->driver->get_frame_number (hcd); 1168 return hcd->driver->get_frame_number (hcd);
@@ -1263,7 +1202,7 @@ unlink1 (struct usb_hcd *hcd, struct urb *urb)
1263 * caller guarantees urb won't be recycled till both unlink() 1202 * caller guarantees urb won't be recycled till both unlink()
1264 * and the urb's completion function return 1203 * and the urb's completion function return
1265 */ 1204 */
1266static int hcd_unlink_urb (struct urb *urb, int status) 1205int usb_hcd_unlink_urb (struct urb *urb, int status)
1267{ 1206{
1268 struct usb_host_endpoint *ep; 1207 struct usb_host_endpoint *ep;
1269 struct usb_hcd *hcd = NULL; 1208 struct usb_hcd *hcd = NULL;
@@ -1296,7 +1235,7 @@ static int hcd_unlink_urb (struct urb *urb, int status)
1296 spin_lock (&hcd_data_lock); 1235 spin_lock (&hcd_data_lock);
1297 1236
1298 sys = &urb->dev->dev; 1237 sys = &urb->dev->dev;
1299 hcd = urb->dev->bus->hcpriv; 1238 hcd = bus_to_hcd(urb->dev->bus);
1300 if (hcd == NULL) { 1239 if (hcd == NULL) {
1301 retval = -ENODEV; 1240 retval = -ENODEV;
1302 goto done; 1241 goto done;
@@ -1354,41 +1293,33 @@ done:
1354/*-------------------------------------------------------------------------*/ 1293/*-------------------------------------------------------------------------*/
1355 1294
1356/* disables the endpoint: cancels any pending urbs, then synchronizes with 1295/* disables the endpoint: cancels any pending urbs, then synchronizes with
1357 * the hcd to make sure all endpoint state is gone from hardware. use for 1296 * the hcd to make sure all endpoint state is gone from hardware, and then
1297 * waits until the endpoint's queue is completely drained. use for
1358 * set_configuration, set_interface, driver removal, physical disconnect. 1298 * set_configuration, set_interface, driver removal, physical disconnect.
1359 * 1299 *
1360 * example: a qh stored in ep->hcpriv, holding state related to endpoint 1300 * example: a qh stored in ep->hcpriv, holding state related to endpoint
1361 * type, maxpacket size, toggle, halt status, and scheduling. 1301 * type, maxpacket size, toggle, halt status, and scheduling.
1362 */ 1302 */
1363static void 1303void usb_hcd_endpoint_disable (struct usb_device *udev,
1364hcd_endpoint_disable (struct usb_device *udev, struct usb_host_endpoint *ep) 1304 struct usb_host_endpoint *ep)
1365{ 1305{
1366 struct usb_hcd *hcd; 1306 struct usb_hcd *hcd;
1367 struct urb *urb; 1307 struct urb *urb;
1368 1308
1369 hcd = udev->bus->hcpriv; 1309 hcd = bus_to_hcd(udev->bus);
1370 1310
1371 WARN_ON (!HC_IS_RUNNING (hcd->state) && hcd->state != HC_STATE_HALT && 1311 WARN_ON (!HC_IS_RUNNING (hcd->state) && hcd->state != HC_STATE_HALT &&
1372 udev->state != USB_STATE_NOTATTACHED); 1312 udev->state != USB_STATE_NOTATTACHED);
1373 1313
1374 local_irq_disable (); 1314 local_irq_disable ();
1375 1315
1376 /* FIXME move most of this into message.c as part of its
1377 * endpoint disable logic
1378 */
1379
1380 /* ep is already gone from udev->ep_{in,out}[]; no more submits */ 1316 /* ep is already gone from udev->ep_{in,out}[]; no more submits */
1381rescan: 1317rescan:
1382 spin_lock (&hcd_data_lock); 1318 spin_lock (&hcd_data_lock);
1383 list_for_each_entry (urb, &ep->urb_list, urb_list) { 1319 list_for_each_entry (urb, &ep->urb_list, urb_list) {
1384 int tmp; 1320 int tmp;
1385 1321
1386 /* another cpu may be in hcd, spinning on hcd_data_lock 1322 /* the urb may already have been unlinked */
1387 * to giveback() this urb. the races here should be
1388 * small, but a full fix needs a new "can't submit"
1389 * urb state.
1390 * FIXME urb->reject should allow that...
1391 */
1392 if (urb->status != -EINPROGRESS) 1323 if (urb->status != -EINPROGRESS)
1393 continue; 1324 continue;
1394 usb_get_urb (urb); 1325 usb_get_urb (urb);
@@ -1430,6 +1361,30 @@ rescan:
1430 might_sleep (); 1361 might_sleep ();
1431 if (hcd->driver->endpoint_disable) 1362 if (hcd->driver->endpoint_disable)
1432 hcd->driver->endpoint_disable (hcd, ep); 1363 hcd->driver->endpoint_disable (hcd, ep);
1364
1365 /* Wait until the endpoint queue is completely empty. Most HCDs
1366 * will have done this already in their endpoint_disable method,
1367 * but some might not. And there could be root-hub control URBs
1368 * still pending since they aren't affected by the HCDs'
1369 * endpoint_disable methods.
1370 */
1371 while (!list_empty (&ep->urb_list)) {
1372 spin_lock_irq (&hcd_data_lock);
1373
1374 /* The list may have changed while we acquired the spinlock */
1375 urb = NULL;
1376 if (!list_empty (&ep->urb_list)) {
1377 urb = list_entry (ep->urb_list.prev, struct urb,
1378 urb_list);
1379 usb_get_urb (urb);
1380 }
1381 spin_unlock_irq (&hcd_data_lock);
1382
1383 if (urb) {
1384 usb_kill_urb (urb);
1385 usb_put_urb (urb);
1386 }
1387 }
1433} 1388}
1434 1389
1435/*-------------------------------------------------------------------------*/ 1390/*-------------------------------------------------------------------------*/
@@ -1476,50 +1431,6 @@ int hcd_bus_resume (struct usb_bus *bus)
1476 return status; 1431 return status;
1477} 1432}
1478 1433
1479/*
1480 * usb_hcd_suspend_root_hub - HCD autosuspends downstream ports
1481 * @hcd: host controller for this root hub
1482 *
1483 * This call arranges that usb_hcd_resume_root_hub() is safe to call later;
1484 * that the HCD's root hub polling is deactivated; and that the root's hub
1485 * driver is suspended. HCDs may call this to autosuspend when their root
1486 * hub's downstream ports are all inactive: unpowered, disconnected,
1487 * disabled, or suspended.
1488 *
1489 * The HCD will autoresume on device connect change detection (using SRP
1490 * or a D+/D- pullup). The HCD also autoresumes on remote wakeup signaling
1491 * from any ports that are suspended (if that is enabled). In most cases,
1492 * overcurrent signaling (on powered ports) will also start autoresume.
1493 *
1494 * Always called with IRQs blocked.
1495 */
1496void usb_hcd_suspend_root_hub (struct usb_hcd *hcd)
1497{
1498 struct urb *urb;
1499
1500 spin_lock (&hcd_root_hub_lock);
1501 usb_suspend_root_hub (hcd->self.root_hub);
1502
1503 /* force status urb to complete/unlink while suspended */
1504 if (hcd->status_urb) {
1505 urb = hcd->status_urb;
1506 urb->status = -ECONNRESET;
1507 urb->hcpriv = NULL;
1508 urb->actual_length = 0;
1509
1510 del_timer (&hcd->rh_timer);
1511 hcd->poll_pending = 0;
1512 hcd->status_urb = NULL;
1513 } else
1514 urb = NULL;
1515 spin_unlock (&hcd_root_hub_lock);
1516 hcd->state = HC_STATE_SUSPENDED;
1517
1518 if (urb)
1519 usb_hcd_giveback_urb (hcd, urb, NULL);
1520}
1521EXPORT_SYMBOL_GPL(usb_hcd_suspend_root_hub);
1522
1523/** 1434/**
1524 * usb_hcd_resume_root_hub - called by HCD to resume its root hub 1435 * usb_hcd_resume_root_hub - called by HCD to resume its root hub
1525 * @hcd: host controller for this root hub 1436 * @hcd: host controller for this root hub
@@ -1583,20 +1494,6 @@ EXPORT_SYMBOL (usb_bus_start_enum);
1583 1494
1584/*-------------------------------------------------------------------------*/ 1495/*-------------------------------------------------------------------------*/
1585 1496
1586/*
1587 * usb_hcd_operations - adapts usb_bus framework to HCD framework (bus glue)
1588 */
1589static struct usb_operations usb_hcd_operations = {
1590 .get_frame_number = hcd_get_frame_number,
1591 .submit_urb = hcd_submit_urb,
1592 .unlink_urb = hcd_unlink_urb,
1593 .buffer_alloc = hcd_buffer_alloc,
1594 .buffer_free = hcd_buffer_free,
1595 .disable = hcd_endpoint_disable,
1596};
1597
1598/*-------------------------------------------------------------------------*/
1599
1600/** 1497/**
1601 * usb_hcd_giveback_urb - return URB from HCD to device driver 1498 * usb_hcd_giveback_urb - return URB from HCD to device driver
1602 * @hcd: host controller returning the URB 1499 * @hcd: host controller returning the URB
@@ -1617,8 +1514,9 @@ void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb, struct pt_regs
1617 at_root_hub = (urb->dev == hcd->self.root_hub); 1514 at_root_hub = (urb->dev == hcd->self.root_hub);
1618 urb_unlink (urb); 1515 urb_unlink (urb);
1619 1516
1620 /* lower level hcd code should use *_dma exclusively */ 1517 /* lower level hcd code should use *_dma exclusively if the
1621 if (hcd->self.controller->dma_mask && !at_root_hub) { 1518 * host controller does DMA */
1519 if (hcd->self.uses_dma && !at_root_hub) {
1622 if (usb_pipecontrol (urb->pipe) 1520 if (usb_pipecontrol (urb->pipe)
1623 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) 1521 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP))
1624 dma_unmap_single (hcd->self.controller, urb->setup_dma, 1522 dma_unmap_single (hcd->self.controller, urb->setup_dma,
@@ -1704,14 +1602,6 @@ EXPORT_SYMBOL_GPL (usb_hc_died);
1704 1602
1705/*-------------------------------------------------------------------------*/ 1603/*-------------------------------------------------------------------------*/
1706 1604
1707static void hcd_release (struct usb_bus *bus)
1708{
1709 struct usb_hcd *hcd;
1710
1711 hcd = container_of(bus, struct usb_hcd, self);
1712 kfree(hcd);
1713}
1714
1715/** 1605/**
1716 * usb_create_hcd - create and initialize an HCD structure 1606 * usb_create_hcd - create and initialize an HCD structure
1717 * @driver: HC driver that will use this hcd 1607 * @driver: HC driver that will use this hcd
@@ -1736,13 +1626,12 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
1736 return NULL; 1626 return NULL;
1737 } 1627 }
1738 dev_set_drvdata(dev, hcd); 1628 dev_set_drvdata(dev, hcd);
1629 kref_init(&hcd->kref);
1739 1630
1740 usb_bus_init(&hcd->self); 1631 usb_bus_init(&hcd->self);
1741 hcd->self.op = &usb_hcd_operations;
1742 hcd->self.hcpriv = hcd;
1743 hcd->self.release = &hcd_release;
1744 hcd->self.controller = dev; 1632 hcd->self.controller = dev;
1745 hcd->self.bus_name = bus_name; 1633 hcd->self.bus_name = bus_name;
1634 hcd->self.uses_dma = (dev->dma_mask != NULL);
1746 1635
1747 init_timer(&hcd->rh_timer); 1636 init_timer(&hcd->rh_timer);
1748 hcd->rh_timer.function = rh_timer_func; 1637 hcd->rh_timer.function = rh_timer_func;
@@ -1756,10 +1645,25 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
1756} 1645}
1757EXPORT_SYMBOL (usb_create_hcd); 1646EXPORT_SYMBOL (usb_create_hcd);
1758 1647
1648static void hcd_release (struct kref *kref)
1649{
1650 struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref);
1651
1652 kfree(hcd);
1653}
1654
1655struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd)
1656{
1657 if (hcd)
1658 kref_get (&hcd->kref);
1659 return hcd;
1660}
1661EXPORT_SYMBOL (usb_get_hcd);
1662
1759void usb_put_hcd (struct usb_hcd *hcd) 1663void usb_put_hcd (struct usb_hcd *hcd)
1760{ 1664{
1761 dev_set_drvdata(hcd->self.controller, NULL); 1665 if (hcd)
1762 usb_bus_put(&hcd->self); 1666 kref_put (&hcd->kref, hcd_release);
1763} 1667}
1764EXPORT_SYMBOL (usb_put_hcd); 1668EXPORT_SYMBOL (usb_put_hcd);
1765 1669
@@ -1915,6 +1819,16 @@ void usb_remove_hcd(struct usb_hcd *hcd)
1915} 1819}
1916EXPORT_SYMBOL (usb_remove_hcd); 1820EXPORT_SYMBOL (usb_remove_hcd);
1917 1821
1822void
1823usb_hcd_platform_shutdown(struct platform_device* dev)
1824{
1825 struct usb_hcd *hcd = platform_get_drvdata(dev);
1826
1827 if (hcd->driver->shutdown)
1828 hcd->driver->shutdown(hcd);
1829}
1830EXPORT_SYMBOL (usb_hcd_platform_shutdown);
1831
1918/*-------------------------------------------------------------------------*/ 1832/*-------------------------------------------------------------------------*/
1919 1833
1920#if defined(CONFIG_USB_MON) 1834#if defined(CONFIG_USB_MON)
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
index 7022aafb2ae8..676877c15f81 100644
--- a/drivers/usb/core/hcd.h
+++ b/drivers/usb/core/hcd.h
@@ -55,12 +55,13 @@
55 55
56/*-------------------------------------------------------------------------*/ 56/*-------------------------------------------------------------------------*/
57 57
58struct usb_hcd { /* usb_bus.hcpriv points to this */ 58struct usb_hcd {
59 59
60 /* 60 /*
61 * housekeeping 61 * housekeeping
62 */ 62 */
63 struct usb_bus self; /* hcd is-a bus */ 63 struct usb_bus self; /* hcd is-a bus */
64 struct kref kref; /* reference counter */
64 65
65 const char *product_desc; /* product/vendor string */ 66 const char *product_desc; /* product/vendor string */
66 char irq_descr[24]; /* driver + bus # */ 67 char irq_descr[24]; /* driver + bus # */
@@ -85,6 +86,7 @@ struct usb_hcd { /* usb_bus.hcpriv points to this */
85 unsigned uses_new_polling:1; 86 unsigned uses_new_polling:1;
86 unsigned poll_rh:1; /* poll for rh status? */ 87 unsigned poll_rh:1; /* poll for rh status? */
87 unsigned poll_pending:1; /* status has changed? */ 88 unsigned poll_pending:1; /* status has changed? */
89 unsigned wireless:1; /* Wireless USB HCD */
88 90
89 int irq; /* irq allocated */ 91 int irq; /* irq allocated */
90 void __iomem *regs; /* device memory/io */ 92 void __iomem *regs; /* device memory/io */
@@ -128,8 +130,10 @@ static inline struct usb_bus *hcd_to_bus (struct usb_hcd *hcd)
128 return &hcd->self; 130 return &hcd->self;
129} 131}
130 132
131 133static inline struct usb_hcd *bus_to_hcd (struct usb_bus *bus)
132// urb.hcpriv is really hardware-specific 134{
135 return container_of(bus, struct usb_hcd, self);
136}
133 137
134struct hcd_timeout { /* timeouts we allocate */ 138struct hcd_timeout { /* timeouts we allocate */
135 struct list_head timeout_list; 139 struct list_head timeout_list;
@@ -138,28 +142,6 @@ struct hcd_timeout { /* timeouts we allocate */
138 142
139/*-------------------------------------------------------------------------*/ 143/*-------------------------------------------------------------------------*/
140 144
141/*
142 * FIXME usb_operations should vanish or become hc_driver,
143 * when usb_bus and usb_hcd become the same thing.
144 */
145
146struct usb_operations {
147 int (*get_frame_number) (struct usb_device *usb_dev);
148 int (*submit_urb) (struct urb *urb, gfp_t mem_flags);
149 int (*unlink_urb) (struct urb *urb, int status);
150
151 /* allocate dma-consistent buffer for URB_DMA_NOMAPPING */
152 void *(*buffer_alloc)(struct usb_bus *bus, size_t size,
153 gfp_t mem_flags,
154 dma_addr_t *dma);
155 void (*buffer_free)(struct usb_bus *bus, size_t size,
156 void *addr, dma_addr_t dma);
157
158 void (*disable)(struct usb_device *udev,
159 struct usb_host_endpoint *ep);
160};
161
162/* each driver provides one of these, and hardware init support */
163 145
164struct pt_regs; 146struct pt_regs;
165 147
@@ -192,6 +174,9 @@ struct hc_driver {
192 /* cleanly make HCD stop writing memory and doing I/O */ 174 /* cleanly make HCD stop writing memory and doing I/O */
193 void (*stop) (struct usb_hcd *hcd); 175 void (*stop) (struct usb_hcd *hcd);
194 176
177 /* shutdown HCD */
178 void (*shutdown) (struct usb_hcd *hcd);
179
195 /* return current frame number */ 180 /* return current frame number */
196 int (*get_frame_number) (struct usb_hcd *hcd); 181 int (*get_frame_number) (struct usb_hcd *hcd);
197 182
@@ -218,15 +203,25 @@ struct hc_driver {
218 /* Needed only if port-change IRQs are level-triggered */ 203 /* Needed only if port-change IRQs are level-triggered */
219}; 204};
220 205
221extern void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb, struct pt_regs *regs); 206extern int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags);
207extern int usb_hcd_unlink_urb (struct urb *urb, int status);
208extern void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb,
209 struct pt_regs *regs);
210extern void usb_hcd_endpoint_disable (struct usb_device *udev,
211 struct usb_host_endpoint *ep);
212extern int usb_hcd_get_frame_number (struct usb_device *udev);
222 213
223extern struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, 214extern struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
224 struct device *dev, char *bus_name); 215 struct device *dev, char *bus_name);
216extern struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd);
225extern void usb_put_hcd (struct usb_hcd *hcd); 217extern void usb_put_hcd (struct usb_hcd *hcd);
226extern int usb_add_hcd(struct usb_hcd *hcd, 218extern int usb_add_hcd(struct usb_hcd *hcd,
227 unsigned int irqnum, unsigned long irqflags); 219 unsigned int irqnum, unsigned long irqflags);
228extern void usb_remove_hcd(struct usb_hcd *hcd); 220extern void usb_remove_hcd(struct usb_hcd *hcd);
229 221
222struct platform_device;
223extern void usb_hcd_platform_shutdown(struct platform_device* dev);
224
230#ifdef CONFIG_PCI 225#ifdef CONFIG_PCI
231struct pci_dev; 226struct pci_dev;
232struct pci_device_id; 227struct pci_device_id;
@@ -239,6 +234,8 @@ extern int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t state);
239extern int usb_hcd_pci_resume (struct pci_dev *dev); 234extern int usb_hcd_pci_resume (struct pci_dev *dev);
240#endif /* CONFIG_PM */ 235#endif /* CONFIG_PM */
241 236
237extern void usb_hcd_pci_shutdown (struct pci_dev *dev);
238
242#endif /* CONFIG_PCI */ 239#endif /* CONFIG_PCI */
243 240
244/* pci-ish (pdev null is ok) buffer alloc/mapping support */ 241/* pci-ish (pdev null is ok) buffer alloc/mapping support */
@@ -352,8 +349,6 @@ extern long usb_calc_bus_time (int speed, int is_input,
352 349
353/*-------------------------------------------------------------------------*/ 350/*-------------------------------------------------------------------------*/
354 351
355extern struct usb_bus *usb_alloc_bus (struct usb_operations *);
356
357extern void usb_set_device_state(struct usb_device *udev, 352extern void usb_set_device_state(struct usb_device *udev,
358 enum usb_device_state new_state); 353 enum usb_device_state new_state);
359 354
@@ -365,9 +360,6 @@ extern struct list_head usb_bus_list;
365extern struct mutex usb_bus_list_lock; 360extern struct mutex usb_bus_list_lock;
366extern wait_queue_head_t usb_kill_urb_queue; 361extern wait_queue_head_t usb_kill_urb_queue;
367 362
368extern struct usb_bus *usb_bus_get (struct usb_bus *bus);
369extern void usb_bus_put (struct usb_bus *bus);
370
371extern void usb_enable_root_hub_irq (struct usb_bus *bus); 363extern void usb_enable_root_hub_irq (struct usb_bus *bus);
372 364
373extern int usb_find_interface_driver (struct usb_device *dev, 365extern int usb_find_interface_driver (struct usb_device *dev,
@@ -376,17 +368,11 @@ extern int usb_find_interface_driver (struct usb_device *dev,
376#define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN)) 368#define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN))
377 369
378#ifdef CONFIG_PM 370#ifdef CONFIG_PM
379extern void usb_hcd_suspend_root_hub (struct usb_hcd *hcd);
380extern void usb_hcd_resume_root_hub (struct usb_hcd *hcd); 371extern void usb_hcd_resume_root_hub (struct usb_hcd *hcd);
381extern void usb_root_hub_lost_power (struct usb_device *rhdev); 372extern void usb_root_hub_lost_power (struct usb_device *rhdev);
382extern int hcd_bus_suspend (struct usb_bus *bus); 373extern int hcd_bus_suspend (struct usb_bus *bus);
383extern int hcd_bus_resume (struct usb_bus *bus); 374extern int hcd_bus_resume (struct usb_bus *bus);
384#else 375#else
385static inline void usb_hcd_suspend_root_hub(struct usb_hcd *hcd)
386{
387 return;
388}
389
390static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd) 376static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd)
391{ 377{
392 return; 378 return;
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 26c8cb5f3e67..7676690a0386 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -293,7 +293,7 @@ void usb_kick_khubd(struct usb_device *hdev)
293/* completion function, fires on port status changes and various faults */ 293/* completion function, fires on port status changes and various faults */
294static void hub_irq(struct urb *urb, struct pt_regs *regs) 294static void hub_irq(struct urb *urb, struct pt_regs *regs)
295{ 295{
296 struct usb_hub *hub = (struct usb_hub *)urb->context; 296 struct usb_hub *hub = urb->context;
297 int status; 297 int status;
298 int i; 298 int i;
299 unsigned long bits; 299 unsigned long bits;
@@ -311,7 +311,7 @@ static void hub_irq(struct urb *urb, struct pt_regs *regs)
311 goto resubmit; 311 goto resubmit;
312 hub->error = urb->status; 312 hub->error = urb->status;
313 /* FALL THROUGH */ 313 /* FALL THROUGH */
314 314
315 /* let khubd handle things */ 315 /* let khubd handle things */
316 case 0: /* we got data: port status changed */ 316 case 0: /* we got data: port status changed */
317 bits = 0; 317 bits = 0;
@@ -452,18 +452,14 @@ static void hub_power_on(struct usb_hub *hub)
452 msleep(max(pgood_delay, (unsigned) 100)); 452 msleep(max(pgood_delay, (unsigned) 100));
453} 453}
454 454
455static inline void __hub_quiesce(struct usb_hub *hub) 455static void hub_quiesce(struct usb_hub *hub)
456{ 456{
457 /* (nonblocking) khubd and related activity won't re-trigger */ 457 /* (nonblocking) khubd and related activity won't re-trigger */
458 hub->quiescing = 1; 458 hub->quiescing = 1;
459 hub->activating = 0; 459 hub->activating = 0;
460 hub->resume_root_hub = 0; 460 hub->resume_root_hub = 0;
461}
462 461
463static void hub_quiesce(struct usb_hub *hub)
464{
465 /* (blocking) stop khubd and related activity */ 462 /* (blocking) stop khubd and related activity */
466 __hub_quiesce(hub);
467 usb_kill_urb(hub->urb); 463 usb_kill_urb(hub->urb);
468 if (hub->has_indicators) 464 if (hub->has_indicators)
469 cancel_delayed_work(&hub->leds); 465 cancel_delayed_work(&hub->leds);
@@ -868,13 +864,8 @@ descriptor_error:
868 864
869 endpoint = &desc->endpoint[0].desc; 865 endpoint = &desc->endpoint[0].desc;
870 866
871 /* Output endpoint? Curiouser and curiouser.. */ 867 /* If it's not an interrupt in endpoint, we'd better punt! */
872 if (!(endpoint->bEndpointAddress & USB_DIR_IN)) 868 if (!usb_endpoint_is_int_in(endpoint))
873 goto descriptor_error;
874
875 /* If it's not an interrupt endpoint, we'd better punt! */
876 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
877 != USB_ENDPOINT_XFER_INT)
878 goto descriptor_error; 869 goto descriptor_error;
879 870
880 /* We found a hub */ 871 /* We found a hub */
@@ -1022,26 +1013,29 @@ void usb_set_device_state(struct usb_device *udev,
1022 if (udev->state == USB_STATE_NOTATTACHED) 1013 if (udev->state == USB_STATE_NOTATTACHED)
1023 ; /* do nothing */ 1014 ; /* do nothing */
1024 else if (new_state != USB_STATE_NOTATTACHED) { 1015 else if (new_state != USB_STATE_NOTATTACHED) {
1025 udev->state = new_state;
1026 1016
1027 /* root hub wakeup capabilities are managed out-of-band 1017 /* root hub wakeup capabilities are managed out-of-band
1028 * and may involve silicon errata ... ignore them here. 1018 * and may involve silicon errata ... ignore them here.
1029 */ 1019 */
1030 if (udev->parent) { 1020 if (udev->parent) {
1031 if (new_state == USB_STATE_CONFIGURED) 1021 if (udev->state == USB_STATE_SUSPENDED
1022 || new_state == USB_STATE_SUSPENDED)
1023 ; /* No change to wakeup settings */
1024 else if (new_state == USB_STATE_CONFIGURED)
1032 device_init_wakeup(&udev->dev, 1025 device_init_wakeup(&udev->dev,
1033 (udev->actconfig->desc.bmAttributes 1026 (udev->actconfig->desc.bmAttributes
1034 & USB_CONFIG_ATT_WAKEUP)); 1027 & USB_CONFIG_ATT_WAKEUP));
1035 else if (new_state != USB_STATE_SUSPENDED) 1028 else
1036 device_init_wakeup(&udev->dev, 0); 1029 device_init_wakeup(&udev->dev, 0);
1037 } 1030 }
1031 udev->state = new_state;
1038 } else 1032 } else
1039 recursively_mark_NOTATTACHED(udev); 1033 recursively_mark_NOTATTACHED(udev);
1040 spin_unlock_irqrestore(&device_state_lock, flags); 1034 spin_unlock_irqrestore(&device_state_lock, flags);
1041} 1035}
1042 1036
1043 1037
1044#ifdef CONFIG_PM 1038#ifdef CONFIG_PM
1045 1039
1046/** 1040/**
1047 * usb_root_hub_lost_power - called by HCD if the root hub lost Vbus power 1041 * usb_root_hub_lost_power - called by HCD if the root hub lost Vbus power
@@ -1059,6 +1053,12 @@ void usb_root_hub_lost_power(struct usb_device *rhdev)
1059 unsigned long flags; 1053 unsigned long flags;
1060 1054
1061 dev_warn(&rhdev->dev, "root hub lost power or was reset\n"); 1055 dev_warn(&rhdev->dev, "root hub lost power or was reset\n");
1056
1057 /* Make sure no potential wakeup events get lost,
1058 * by forcing the root hub to be resumed.
1059 */
1060 rhdev->dev.power.prev_state.event = PM_EVENT_ON;
1061
1062 spin_lock_irqsave(&device_state_lock, flags); 1062 spin_lock_irqsave(&device_state_lock, flags);
1063 hub = hdev_to_hub(rhdev); 1063 hub = hdev_to_hub(rhdev);
1064 for (port1 = 1; port1 <= rhdev->maxchild; ++port1) { 1064 for (port1 = 1; port1 <= rhdev->maxchild; ++port1) {
@@ -1072,7 +1072,7 @@ void usb_root_hub_lost_power(struct usb_device *rhdev)
1072} 1072}
1073EXPORT_SYMBOL_GPL(usb_root_hub_lost_power); 1073EXPORT_SYMBOL_GPL(usb_root_hub_lost_power);
1074 1074
1075#endif 1075#endif /* CONFIG_PM */
1076 1076
1077static void choose_address(struct usb_device *udev) 1077static void choose_address(struct usb_device *udev)
1078{ 1078{
@@ -1148,144 +1148,28 @@ void usb_disconnect(struct usb_device **pdev)
1148 * cleaning up all state associated with the current configuration 1148 * cleaning up all state associated with the current configuration
1149 * so that the hardware is now fully quiesced. 1149 * so that the hardware is now fully quiesced.
1150 */ 1150 */
1151 dev_dbg (&udev->dev, "unregistering device\n");
1151 usb_disable_device(udev, 0); 1152 usb_disable_device(udev, 0);
1152 1153
1153 usb_notify_remove_device(udev); 1154 usb_unlock_device(udev);
1154 1155
1155 /* Free the device number, remove the /proc/bus/usb entry and 1156 /* Unregister the device. The device driver is responsible
1156 * the sysfs attributes, and delete the parent's children[] 1157 * for removing the device files from usbfs and sysfs and for
1158 * de-configuring the device.
1159 */
1160 device_del(&udev->dev);
1161
1162 /* Free the device number and delete the parent's children[]
1157 * (or root_hub) pointer. 1163 * (or root_hub) pointer.
1158 */ 1164 */
1159 dev_dbg (&udev->dev, "unregistering device\n");
1160 release_address(udev); 1165 release_address(udev);
1161 usb_remove_sysfs_dev_files(udev);
1162 1166
1163 /* Avoid races with recursively_mark_NOTATTACHED() */ 1167 /* Avoid races with recursively_mark_NOTATTACHED() */
1164 spin_lock_irq(&device_state_lock); 1168 spin_lock_irq(&device_state_lock);
1165 *pdev = NULL; 1169 *pdev = NULL;
1166 spin_unlock_irq(&device_state_lock); 1170 spin_unlock_irq(&device_state_lock);
1167 1171
1168 usb_unlock_device(udev); 1172 put_device(&udev->dev);
1169
1170 device_unregister(&udev->dev);
1171}
1172
1173static inline const char *plural(int n)
1174{
1175 return (n == 1 ? "" : "s");
1176}
1177
1178static int choose_configuration(struct usb_device *udev)
1179{
1180 int i;
1181 int num_configs;
1182 int insufficient_power = 0;
1183 struct usb_host_config *c, *best;
1184
1185 best = NULL;
1186 c = udev->config;
1187 num_configs = udev->descriptor.bNumConfigurations;
1188 for (i = 0; i < num_configs; (i++, c++)) {
1189 struct usb_interface_descriptor *desc = NULL;
1190
1191 /* It's possible that a config has no interfaces! */
1192 if (c->desc.bNumInterfaces > 0)
1193 desc = &c->intf_cache[0]->altsetting->desc;
1194
1195 /*
1196 * HP's USB bus-powered keyboard has only one configuration
1197 * and it claims to be self-powered; other devices may have
1198 * similar errors in their descriptors. If the next test
1199 * were allowed to execute, such configurations would always
1200 * be rejected and the devices would not work as expected.
1201 * In the meantime, we run the risk of selecting a config
1202 * that requires external power at a time when that power
1203 * isn't available. It seems to be the lesser of two evils.
1204 *
1205 * Bugzilla #6448 reports a device that appears to crash
1206 * when it receives a GET_DEVICE_STATUS request! We don't
1207 * have any other way to tell whether a device is self-powered,
1208 * but since we don't use that information anywhere but here,
1209 * the call has been removed.
1210 *
1211 * Maybe the GET_DEVICE_STATUS call and the test below can
1212 * be reinstated when device firmwares become more reliable.
1213 * Don't hold your breath.
1214 */
1215#if 0
1216 /* Rule out self-powered configs for a bus-powered device */
1217 if (bus_powered && (c->desc.bmAttributes &
1218 USB_CONFIG_ATT_SELFPOWER))
1219 continue;
1220#endif
1221
1222 /*
1223 * The next test may not be as effective as it should be.
1224 * Some hubs have errors in their descriptor, claiming
1225 * to be self-powered when they are really bus-powered.
1226 * We will overestimate the amount of current such hubs
1227 * make available for each port.
1228 *
1229 * This is a fairly benign sort of failure. It won't
1230 * cause us to reject configurations that we should have
1231 * accepted.
1232 */
1233
1234 /* Rule out configs that draw too much bus current */
1235 if (c->desc.bMaxPower * 2 > udev->bus_mA) {
1236 insufficient_power++;
1237 continue;
1238 }
1239
1240 /* If the first config's first interface is COMM/2/0xff
1241 * (MSFT RNDIS), rule it out unless Linux has host-side
1242 * RNDIS support. */
1243 if (i == 0 && desc
1244 && desc->bInterfaceClass == USB_CLASS_COMM
1245 && desc->bInterfaceSubClass == 2
1246 && desc->bInterfaceProtocol == 0xff) {
1247#ifndef CONFIG_USB_NET_RNDIS_HOST
1248 continue;
1249#else
1250 best = c;
1251#endif
1252 }
1253
1254 /* From the remaining configs, choose the first one whose
1255 * first interface is for a non-vendor-specific class.
1256 * Reason: Linux is more likely to have a class driver
1257 * than a vendor-specific driver. */
1258 else if (udev->descriptor.bDeviceClass !=
1259 USB_CLASS_VENDOR_SPEC &&
1260 (!desc || desc->bInterfaceClass !=
1261 USB_CLASS_VENDOR_SPEC)) {
1262 best = c;
1263 break;
1264 }
1265
1266 /* If all the remaining configs are vendor-specific,
1267 * choose the first one. */
1268 else if (!best)
1269 best = c;
1270 }
1271
1272 if (insufficient_power > 0)
1273 dev_info(&udev->dev, "rejected %d configuration%s "
1274 "due to insufficient available bus power\n",
1275 insufficient_power, plural(insufficient_power));
1276
1277 if (best) {
1278 i = best->desc.bConfigurationValue;
1279 dev_info(&udev->dev,
1280 "configuration #%d chosen from %d choice%s\n",
1281 i, num_configs, plural(num_configs));
1282 } else {
1283 i = -1;
1284 dev_warn(&udev->dev,
1285 "no configuration chosen from %d choice%s\n",
1286 num_configs, plural(num_configs));
1287 }
1288 return i;
1289} 1173}
1290 1174
1291#ifdef DEBUG 1175#ifdef DEBUG
@@ -1328,7 +1212,6 @@ static inline void show_string(struct usb_device *udev, char *id, char *string)
1328int usb_new_device(struct usb_device *udev) 1212int usb_new_device(struct usb_device *udev)
1329{ 1213{
1330 int err; 1214 int err;
1331 int c;
1332 1215
1333 err = usb_get_configuration(udev); 1216 err = usb_get_configuration(udev);
1334 if (err < 0) { 1217 if (err < 0) {
@@ -1371,8 +1254,7 @@ int usb_new_device(struct usb_device *udev)
1371 USB_DT_OTG, (void **) &desc) == 0) { 1254 USB_DT_OTG, (void **) &desc) == 0) {
1372 if (desc->bmAttributes & USB_OTG_HNP) { 1255 if (desc->bmAttributes & USB_OTG_HNP) {
1373 unsigned port1 = udev->portnum; 1256 unsigned port1 = udev->portnum;
1374 struct usb_device *root = udev->parent; 1257
1375
1376 dev_info(&udev->dev, 1258 dev_info(&udev->dev,
1377 "Dual-Role OTG device on %sHNP port\n", 1259 "Dual-Role OTG device on %sHNP port\n",
1378 (port1 == bus->otg_port) 1260 (port1 == bus->otg_port)
@@ -1407,9 +1289,9 @@ int usb_new_device(struct usb_device *udev)
1407 * (Includes HNP test device.) 1289 * (Includes HNP test device.)
1408 */ 1290 */
1409 if (udev->bus->b_hnp_enable || udev->bus->is_b_host) { 1291 if (udev->bus->b_hnp_enable || udev->bus->is_b_host) {
1410 static int __usb_suspend_device(struct usb_device *, 1292 static int __usb_port_suspend(struct usb_device *,
1411 int port1); 1293 int port1);
1412 err = __usb_suspend_device(udev, udev->bus->otg_port); 1294 err = __usb_port_suspend(udev, udev->bus->otg_port);
1413 if (err < 0) 1295 if (err < 0)
1414 dev_dbg(&udev->dev, "HNP fail, %d\n", err); 1296 dev_dbg(&udev->dev, "HNP fail, %d\n", err);
1415 } 1297 }
@@ -1418,34 +1300,15 @@ int usb_new_device(struct usb_device *udev)
1418 } 1300 }
1419#endif 1301#endif
1420 1302
1421 /* put device-specific files into sysfs */ 1303 /* Register the device. The device driver is responsible
1304 * for adding the device files to usbfs and sysfs and for
1305 * configuring the device.
1306 */
1422 err = device_add (&udev->dev); 1307 err = device_add (&udev->dev);
1423 if (err) { 1308 if (err) {
1424 dev_err(&udev->dev, "can't device_add, error %d\n", err); 1309 dev_err(&udev->dev, "can't device_add, error %d\n", err);
1425 goto fail; 1310 goto fail;
1426 } 1311 }
1427 usb_create_sysfs_dev_files (udev);
1428
1429 usb_lock_device(udev);
1430
1431 /* choose and set the configuration. that registers the interfaces
1432 * with the driver core, and lets usb device drivers bind to them.
1433 */
1434 c = choose_configuration(udev);
1435 if (c >= 0) {
1436 err = usb_set_configuration(udev, c);
1437 if (err) {
1438 dev_err(&udev->dev, "can't set config #%d, error %d\n",
1439 c, err);
1440 /* This need not be fatal. The user can try to
1441 * set other configurations. */
1442 }
1443 }
1444
1445 /* USB device state == configured ... usable */
1446 usb_notify_add_device(udev);
1447
1448 usb_unlock_device(udev);
1449 1312
1450 return 0; 1313 return 0;
1451 1314
@@ -1472,6 +1335,18 @@ static int hub_port_status(struct usb_hub *hub, int port1,
1472 return ret; 1335 return ret;
1473} 1336}
1474 1337
1338
1339/* Returns 1 if @hub is a WUSB root hub, 0 otherwise */
1340static unsigned hub_is_wusb(struct usb_hub *hub)
1341{
1342 struct usb_hcd *hcd;
1343 if (hub->hdev->parent != NULL) /* not a root hub? */
1344 return 0;
1345 hcd = container_of(hub->hdev->bus, struct usb_hcd, self);
1346 return hcd->wireless;
1347}
1348
1349
1475#define PORT_RESET_TRIES 5 1350#define PORT_RESET_TRIES 5
1476#define SET_ADDRESS_TRIES 2 1351#define SET_ADDRESS_TRIES 2
1477#define GET_DESCRIPTOR_TRIES 2 1352#define GET_DESCRIPTOR_TRIES 2
@@ -1512,7 +1387,9 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1,
1512 /* if we`ve finished resetting, then break out of the loop */ 1387 /* if we`ve finished resetting, then break out of the loop */
1513 if (!(portstatus & USB_PORT_STAT_RESET) && 1388 if (!(portstatus & USB_PORT_STAT_RESET) &&
1514 (portstatus & USB_PORT_STAT_ENABLE)) { 1389 (portstatus & USB_PORT_STAT_ENABLE)) {
1515 if (portstatus & USB_PORT_STAT_HIGH_SPEED) 1390 if (hub_is_wusb(hub))
1391 udev->speed = USB_SPEED_VARIABLE;
1392 else if (portstatus & USB_PORT_STAT_HIGH_SPEED)
1516 udev->speed = USB_SPEED_HIGH; 1393 udev->speed = USB_SPEED_HIGH;
1517 else if (portstatus & USB_PORT_STAT_LOW_SPEED) 1394 else if (portstatus & USB_PORT_STAT_LOW_SPEED)
1518 udev->speed = USB_SPEED_LOW; 1395 udev->speed = USB_SPEED_LOW;
@@ -1607,6 +1484,7 @@ static void hub_port_logical_disconnect(struct usb_hub *hub, int port1)
1607 kick_khubd(hub); 1484 kick_khubd(hub);
1608} 1485}
1609 1486
1487#ifdef CONFIG_PM
1610 1488
1611#ifdef CONFIG_USB_SUSPEND 1489#ifdef CONFIG_USB_SUSPEND
1612 1490
@@ -1633,7 +1511,7 @@ static int hub_port_suspend(struct usb_hub *hub, int port1,
1633 * NOTE: OTG devices may issue remote wakeup (or SRP) even when 1511 * NOTE: OTG devices may issue remote wakeup (or SRP) even when
1634 * we don't explicitly enable it here. 1512 * we don't explicitly enable it here.
1635 */ 1513 */
1636 if (device_may_wakeup(&udev->dev)) { 1514 if (udev->do_remote_wakeup) {
1637 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 1515 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1638 USB_REQ_SET_FEATURE, USB_RECIP_DEVICE, 1516 USB_REQ_SET_FEATURE, USB_RECIP_DEVICE,
1639 USB_DEVICE_REMOTE_WAKEUP, 0, 1517 USB_DEVICE_REMOTE_WAKEUP, 0,
@@ -1659,7 +1537,8 @@ static int hub_port_suspend(struct usb_hub *hub, int port1,
1659 USB_CTRL_SET_TIMEOUT); 1537 USB_CTRL_SET_TIMEOUT);
1660 } else { 1538 } else {
1661 /* device has up to 10 msec to fully suspend */ 1539 /* device has up to 10 msec to fully suspend */
1662 dev_dbg(&udev->dev, "usb suspend\n"); 1540 dev_dbg(&udev->dev, "usb %ssuspend\n",
1541 udev->auto_pm ? "auto-" : "");
1663 usb_set_device_state(udev, USB_STATE_SUSPENDED); 1542 usb_set_device_state(udev, USB_STATE_SUSPENDED);
1664 msleep(10); 1543 msleep(10);
1665 } 1544 }
@@ -1684,7 +1563,7 @@ static int hub_port_suspend(struct usb_hub *hub, int port1,
1684 * the root hub for their bus goes into global suspend ... so we don't 1563 * the root hub for their bus goes into global suspend ... so we don't
1685 * (falsely) update the device power state to say it suspended. 1564 * (falsely) update the device power state to say it suspended.
1686 */ 1565 */
1687static int __usb_suspend_device (struct usb_device *udev, int port1) 1566static int __usb_port_suspend (struct usb_device *udev, int port1)
1688{ 1567{
1689 int status = 0; 1568 int status = 0;
1690 1569
@@ -1692,49 +1571,29 @@ static int __usb_suspend_device (struct usb_device *udev, int port1)
1692 if (port1 < 0) 1571 if (port1 < 0)
1693 return port1; 1572 return port1;
1694 1573
1695 if (udev->state == USB_STATE_SUSPENDED 1574 /* we change the device's upstream USB link,
1696 || udev->state == USB_STATE_NOTATTACHED) { 1575 * but root hubs have no upstream USB link.
1697 return 0;
1698 }
1699
1700 /* all interfaces must already be suspended */
1701 if (udev->actconfig) {
1702 int i;
1703
1704 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) {
1705 struct usb_interface *intf;
1706
1707 intf = udev->actconfig->interface[i];
1708 if (is_active(intf)) {
1709 dev_dbg(&intf->dev, "nyet suspended\n");
1710 return -EBUSY;
1711 }
1712 }
1713 }
1714
1715 /* we only change a device's upstream USB link.
1716 * root hubs have no upstream USB link.
1717 */ 1576 */
1718 if (udev->parent) 1577 if (udev->parent)
1719 status = hub_port_suspend(hdev_to_hub(udev->parent), port1, 1578 status = hub_port_suspend(hdev_to_hub(udev->parent), port1,
1720 udev); 1579 udev);
1721 1580 else {
1722 if (status == 0) 1581 dev_dbg(&udev->dev, "usb %ssuspend\n",
1723 udev->dev.power.power_state = PMSG_SUSPEND; 1582 udev->auto_pm ? "auto-" : "");
1583 usb_set_device_state(udev, USB_STATE_SUSPENDED);
1584 }
1724 return status; 1585 return status;
1725} 1586}
1726 1587
1727#endif
1728
1729/* 1588/*
1730 * usb_suspend_device - suspend a usb device 1589 * usb_port_suspend - suspend a usb device's upstream port
1731 * @udev: device that's no longer in active use 1590 * @udev: device that's no longer in active use
1732 * Context: must be able to sleep; device not locked; pm locks held 1591 * Context: must be able to sleep; device not locked; pm locks held
1733 * 1592 *
1734 * Suspends a USB device that isn't in active use, conserving power. 1593 * Suspends a USB device that isn't in active use, conserving power.
1735 * Devices may wake out of a suspend, if anything important happens, 1594 * Devices may wake out of a suspend, if anything important happens,
1736 * using the remote wakeup mechanism. They may also be taken out of 1595 * using the remote wakeup mechanism. They may also be taken out of
1737 * suspend by the host, using usb_resume_device(). It's also routine 1596 * suspend by the host, using usb_port_resume(). It's also routine
1738 * to disconnect devices while they are suspended. 1597 * to disconnect devices while they are suspended.
1739 * 1598 *
1740 * This only affects the USB hardware for a device; its interfaces 1599 * This only affects the USB hardware for a device; its interfaces
@@ -1746,17 +1605,9 @@ static int __usb_suspend_device (struct usb_device *udev, int port1)
1746 * 1605 *
1747 * Returns 0 on success, else negative errno. 1606 * Returns 0 on success, else negative errno.
1748 */ 1607 */
1749int usb_suspend_device(struct usb_device *udev) 1608int usb_port_suspend(struct usb_device *udev)
1750{ 1609{
1751#ifdef CONFIG_USB_SUSPEND 1610 return __usb_port_suspend(udev, udev->portnum);
1752 if (udev->state == USB_STATE_NOTATTACHED)
1753 return -ENODEV;
1754 return __usb_suspend_device(udev, udev->portnum);
1755#else
1756 /* NOTE: udev->state unchanged, it's not lying ... */
1757 udev->dev.power.power_state = PMSG_SUSPEND;
1758 return 0;
1759#endif
1760} 1611}
1761 1612
1762/* 1613/*
@@ -1767,7 +1618,7 @@ int usb_suspend_device(struct usb_device *udev)
1767 * resume (by host) or remote wakeup (by device) ... now see what changed 1618 * resume (by host) or remote wakeup (by device) ... now see what changed
1768 * in the tree that's rooted at this device. 1619 * in the tree that's rooted at this device.
1769 */ 1620 */
1770static int finish_device_resume(struct usb_device *udev) 1621static int finish_port_resume(struct usb_device *udev)
1771{ 1622{
1772 int status; 1623 int status;
1773 u16 devstatus; 1624 u16 devstatus;
@@ -1783,7 +1634,6 @@ static int finish_device_resume(struct usb_device *udev)
1783 usb_set_device_state(udev, udev->actconfig 1634 usb_set_device_state(udev, udev->actconfig
1784 ? USB_STATE_CONFIGURED 1635 ? USB_STATE_CONFIGURED
1785 : USB_STATE_ADDRESS); 1636 : USB_STATE_ADDRESS);
1786 udev->dev.power.power_state = PMSG_ON;
1787 1637
1788 /* 10.5.4.5 says be sure devices in the tree are still there. 1638 /* 10.5.4.5 says be sure devices in the tree are still there.
1789 * For now let's assume the device didn't go crazy on resume, 1639 * For now let's assume the device didn't go crazy on resume,
@@ -1798,9 +1648,6 @@ static int finish_device_resume(struct usb_device *udev)
1798 "gone after usb resume? status %d\n", 1648 "gone after usb resume? status %d\n",
1799 status); 1649 status);
1800 else if (udev->actconfig) { 1650 else if (udev->actconfig) {
1801 unsigned i;
1802 int (*resume)(struct device *);
1803
1804 le16_to_cpus(&devstatus); 1651 le16_to_cpus(&devstatus);
1805 if ((devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) 1652 if ((devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP))
1806 && udev->parent) { 1653 && udev->parent) {
@@ -1811,24 +1658,9 @@ static int finish_device_resume(struct usb_device *udev)
1811 USB_DEVICE_REMOTE_WAKEUP, 0, 1658 USB_DEVICE_REMOTE_WAKEUP, 0,
1812 NULL, 0, 1659 NULL, 0,
1813 USB_CTRL_SET_TIMEOUT); 1660 USB_CTRL_SET_TIMEOUT);
1814 if (status) { 1661 if (status)
1815 dev_dbg(&udev->dev, "disable remote " 1662 dev_dbg(&udev->dev, "disable remote "
1816 "wakeup, status %d\n", status); 1663 "wakeup, status %d\n", status);
1817 status = 0;
1818 }
1819 }
1820
1821 /* resume interface drivers; if this is a hub, it
1822 * may have a child resume event to deal with soon
1823 */
1824 resume = udev->dev.bus->resume;
1825 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) {
1826 struct device *dev =
1827 &udev->actconfig->interface[i]->dev;
1828
1829 down(&dev->sem);
1830 (void) resume(dev);
1831 up(&dev->sem);
1832 } 1664 }
1833 status = 0; 1665 status = 0;
1834 1666
@@ -1839,8 +1671,6 @@ static int finish_device_resume(struct usb_device *udev)
1839 return status; 1671 return status;
1840} 1672}
1841 1673
1842#ifdef CONFIG_USB_SUSPEND
1843
1844static int 1674static int
1845hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev) 1675hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev)
1846{ 1676{
@@ -1848,6 +1678,8 @@ hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev)
1848 1678
1849 // dev_dbg(hub->intfdev, "resume port %d\n", port1); 1679 // dev_dbg(hub->intfdev, "resume port %d\n", port1);
1850 1680
1681 set_bit(port1, hub->busy_bits);
1682
1851 /* see 7.1.7.7; affects power usage, but not budgeting */ 1683 /* see 7.1.7.7; affects power usage, but not budgeting */
1852 status = clear_port_feature(hub->hdev, 1684 status = clear_port_feature(hub->hdev,
1853 port1, USB_PORT_FEAT_SUSPEND); 1685 port1, USB_PORT_FEAT_SUSPEND);
@@ -1861,7 +1693,8 @@ hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev)
1861 1693
1862 /* drive resume for at least 20 msec */ 1694 /* drive resume for at least 20 msec */
1863 if (udev) 1695 if (udev)
1864 dev_dbg(&udev->dev, "RESUME\n"); 1696 dev_dbg(&udev->dev, "usb %sresume\n",
1697 udev->auto_pm ? "auto-" : "");
1865 msleep(25); 1698 msleep(25);
1866 1699
1867#define LIVE_FLAGS ( USB_PORT_STAT_POWER \ 1700#define LIVE_FLAGS ( USB_PORT_STAT_POWER \
@@ -1891,19 +1724,21 @@ hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev)
1891 /* TRSMRCY = 10 msec */ 1724 /* TRSMRCY = 10 msec */
1892 msleep(10); 1725 msleep(10);
1893 if (udev) 1726 if (udev)
1894 status = finish_device_resume(udev); 1727 status = finish_port_resume(udev);
1895 } 1728 }
1896 } 1729 }
1897 if (status < 0) 1730 if (status < 0)
1898 hub_port_logical_disconnect(hub, port1); 1731 hub_port_logical_disconnect(hub, port1);
1899 1732
1733 clear_bit(port1, hub->busy_bits);
1734 if (!hub->hdev->parent && !hub->busy_bits[0])
1735 usb_enable_root_hub_irq(hub->hdev->bus);
1736
1900 return status; 1737 return status;
1901} 1738}
1902 1739
1903#endif
1904
1905/* 1740/*
1906 * usb_resume_device - re-activate a suspended usb device 1741 * usb_port_resume - re-activate a suspended usb device's upstream port
1907 * @udev: device to re-activate 1742 * @udev: device to re-activate
1908 * Context: must be able to sleep; device not locked; pm locks held 1743 * Context: must be able to sleep; device not locked; pm locks held
1909 * 1744 *
@@ -1915,36 +1750,24 @@ hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev)
1915 * 1750 *
1916 * Returns 0 on success, else negative errno. 1751 * Returns 0 on success, else negative errno.
1917 */ 1752 */
1918int usb_resume_device(struct usb_device *udev) 1753int usb_port_resume(struct usb_device *udev)
1919{ 1754{
1920 int status; 1755 int status;
1921 1756
1922 if (udev->state == USB_STATE_NOTATTACHED) 1757 /* we change the device's upstream USB link,
1923 return -ENODEV; 1758 * but root hubs have no upstream USB link.
1924 1759 */
1925 /* selective resume of one downstream hub-to-device port */
1926 if (udev->parent) { 1760 if (udev->parent) {
1927#ifdef CONFIG_USB_SUSPEND 1761 // NOTE this fails if parent is also suspended...
1928 if (udev->state == USB_STATE_SUSPENDED) { 1762 status = hub_port_resume(hdev_to_hub(udev->parent),
1929 // NOTE swsusp may bork us, device state being wrong... 1763 udev->portnum, udev);
1930 // NOTE this fails if parent is also suspended... 1764 } else {
1931 status = hub_port_resume(hdev_to_hub(udev->parent), 1765 dev_dbg(&udev->dev, "usb %sresume\n",
1932 udev->portnum, udev); 1766 udev->auto_pm ? "auto-" : "");
1933 } else 1767 status = finish_port_resume(udev);
1934#endif
1935 status = 0;
1936 } else
1937 status = finish_device_resume(udev);
1938 if (status < 0)
1939 dev_dbg(&udev->dev, "can't resume, status %d\n",
1940 status);
1941
1942 /* rebind drivers that had no suspend() */
1943 if (status == 0) {
1944 usb_unlock_device(udev);
1945 bus_rescan_devices(&usb_bus_type);
1946 usb_lock_device(udev);
1947 } 1768 }
1769 if (status < 0)
1770 dev_dbg(&udev->dev, "can't resume, status %d\n", status);
1948 return status; 1771 return status;
1949} 1772}
1950 1773
@@ -1952,23 +1775,60 @@ static int remote_wakeup(struct usb_device *udev)
1952{ 1775{
1953 int status = 0; 1776 int status = 0;
1954 1777
1955#ifdef CONFIG_USB_SUSPEND 1778 /* All this just to avoid sending a port-resume message
1779 * to the parent hub! */
1956 1780
1957 /* don't repeat RESUME sequence if this device
1958 * was already woken up by some other task
1959 */
1960 usb_lock_device(udev); 1781 usb_lock_device(udev);
1782 usb_pm_lock(udev);
1961 if (udev->state == USB_STATE_SUSPENDED) { 1783 if (udev->state == USB_STATE_SUSPENDED) {
1962 dev_dbg(&udev->dev, "RESUME (wakeup)\n"); 1784 dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-");
1963 /* TRSMRCY = 10 msec */ 1785 /* TRSMRCY = 10 msec */
1964 msleep(10); 1786 msleep(10);
1965 status = finish_device_resume(udev); 1787 status = finish_port_resume(udev);
1788 if (status == 0)
1789 udev->dev.power.power_state.event = PM_EVENT_ON;
1966 } 1790 }
1791 usb_pm_unlock(udev);
1792
1793 if (status == 0)
1794 usb_autoresume_device(udev, 0);
1967 usb_unlock_device(udev); 1795 usb_unlock_device(udev);
1968#endif
1969 return status; 1796 return status;
1970} 1797}
1971 1798
1799#else /* CONFIG_USB_SUSPEND */
1800
1801/* When CONFIG_USB_SUSPEND isn't set, we never suspend or resume any ports. */
1802
1803int usb_port_suspend(struct usb_device *udev)
1804{
1805 return 0;
1806}
1807
1808static inline int
1809finish_port_resume(struct usb_device *udev)
1810{
1811 return 0;
1812}
1813
1814static inline int
1815hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev)
1816{
1817 return 0;
1818}
1819
1820int usb_port_resume(struct usb_device *udev)
1821{
1822 return 0;
1823}
1824
1825static inline int remote_wakeup(struct usb_device *udev)
1826{
1827 return 0;
1828}
1829
1830#endif
1831
1972static int hub_suspend(struct usb_interface *intf, pm_message_t msg) 1832static int hub_suspend(struct usb_interface *intf, pm_message_t msg)
1973{ 1833{
1974 struct usb_hub *hub = usb_get_intfdata (intf); 1834 struct usb_hub *hub = usb_get_intfdata (intf);
@@ -1980,13 +1840,17 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg)
1980 struct usb_device *udev; 1840 struct usb_device *udev;
1981 1841
1982 udev = hdev->children [port1-1]; 1842 udev = hdev->children [port1-1];
1983 if (udev && (udev->dev.power.power_state.event 1843 if (udev && msg.event == PM_EVENT_SUSPEND &&
1984 == PM_EVENT_ON
1985#ifdef CONFIG_USB_SUSPEND 1844#ifdef CONFIG_USB_SUSPEND
1986 || udev->state != USB_STATE_SUSPENDED 1845 udev->state != USB_STATE_SUSPENDED
1846#else
1847 udev->dev.power.power_state.event
1848 == PM_EVENT_ON
1987#endif 1849#endif
1988 )) { 1850 ) {
1989 dev_dbg(&intf->dev, "port %d nyet suspended\n", port1); 1851 if (!hdev->auto_pm)
1852 dev_dbg(&intf->dev, "port %d nyet suspended\n",
1853 port1);
1990 return -EBUSY; 1854 return -EBUSY;
1991 } 1855 }
1992 } 1856 }
@@ -2035,66 +1899,22 @@ static int hub_resume(struct usb_interface *intf)
2035 } 1899 }
2036 } 1900 }
2037 1901
1902 /* tell khubd to look for changes on this hub */
2038 hub_activate(hub); 1903 hub_activate(hub);
2039
2040 /* REVISIT: this recursion probably shouldn't exist. Remove
2041 * this code sometime, after retesting with different root and
2042 * external hubs.
2043 */
2044#ifdef CONFIG_USB_SUSPEND
2045 {
2046 unsigned port1;
2047
2048 for (port1 = 1; port1 <= hdev->maxchild; port1++) {
2049 struct usb_device *udev;
2050 u16 portstat, portchange;
2051
2052 udev = hdev->children [port1-1];
2053 status = hub_port_status(hub, port1, &portstat, &portchange);
2054 if (status == 0) {
2055 if (portchange & USB_PORT_STAT_C_SUSPEND) {
2056 clear_port_feature(hdev, port1,
2057 USB_PORT_FEAT_C_SUSPEND);
2058 portchange &= ~USB_PORT_STAT_C_SUSPEND;
2059 }
2060
2061 /* let khubd handle disconnects etc */
2062 if (portchange)
2063 continue;
2064 }
2065
2066 if (!udev || status < 0)
2067 continue;
2068 usb_lock_device(udev);
2069 if (portstat & USB_PORT_STAT_SUSPEND)
2070 status = hub_port_resume(hub, port1, udev);
2071 else {
2072 status = finish_device_resume(udev);
2073 if (status < 0) {
2074 dev_dbg(&intf->dev, "resume port %d --> %d\n",
2075 port1, status);
2076 hub_port_logical_disconnect(hub, port1);
2077 }
2078 }
2079 usb_unlock_device(udev);
2080 }
2081 }
2082#endif
2083 return 0; 1904 return 0;
2084} 1905}
2085 1906
2086void usb_suspend_root_hub(struct usb_device *hdev) 1907#else /* CONFIG_PM */
2087{
2088 struct usb_hub *hub = hdev_to_hub(hdev);
2089 1908
2090 /* This also makes any led blinker stop retriggering. We're called 1909static inline int remote_wakeup(struct usb_device *udev)
2091 * from irq, so the blinker might still be scheduled. Caller promises 1910{
2092 * that the root hub status URB will be canceled. 1911 return 0;
2093 */
2094 __hub_quiesce(hub);
2095 mark_quiesced(to_usb_interface(hub->intfdev));
2096} 1912}
2097 1913
1914#define hub_suspend NULL
1915#define hub_resume NULL
1916#endif
1917
2098void usb_resume_root_hub(struct usb_device *hdev) 1918void usb_resume_root_hub(struct usb_device *hdev)
2099{ 1919{
2100 struct usb_hub *hub = hdev_to_hub(hdev); 1920 struct usb_hub *hub = hdev_to_hub(hdev);
@@ -2214,6 +2034,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2214 int i, j, retval; 2034 int i, j, retval;
2215 unsigned delay = HUB_SHORT_RESET_TIME; 2035 unsigned delay = HUB_SHORT_RESET_TIME;
2216 enum usb_device_speed oldspeed = udev->speed; 2036 enum usb_device_speed oldspeed = udev->speed;
2037 char *speed, *type;
2217 2038
2218 /* root hub ports have a slightly longer reset period 2039 /* root hub ports have a slightly longer reset period
2219 * (from USB 2.0 spec, section 7.1.7.5) 2040 * (from USB 2.0 spec, section 7.1.7.5)
@@ -2246,8 +2067,13 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2246 2067
2247 /* USB 2.0 section 5.5.3 talks about ep0 maxpacket ... 2068 /* USB 2.0 section 5.5.3 talks about ep0 maxpacket ...
2248 * it's fixed size except for full speed devices. 2069 * it's fixed size except for full speed devices.
2070 * For Wireless USB devices, ep0 max packet is always 512 (tho
2071 * reported as 0xff in the device descriptor). WUSB1.0[4.8.1].
2249 */ 2072 */
2250 switch (udev->speed) { 2073 switch (udev->speed) {
2074 case USB_SPEED_VARIABLE: /* fixed at 512 */
2075 udev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(512);
2076 break;
2251 case USB_SPEED_HIGH: /* fixed at 64 */ 2077 case USB_SPEED_HIGH: /* fixed at 64 */
2252 udev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64); 2078 udev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64);
2253 break; 2079 break;
@@ -2265,17 +2091,21 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2265 goto fail; 2091 goto fail;
2266 } 2092 }
2267 2093
2094 type = "";
2095 switch (udev->speed) {
2096 case USB_SPEED_LOW: speed = "low"; break;
2097 case USB_SPEED_FULL: speed = "full"; break;
2098 case USB_SPEED_HIGH: speed = "high"; break;
2099 case USB_SPEED_VARIABLE:
2100 speed = "variable";
2101 type = "Wireless ";
2102 break;
2103 default: speed = "?"; break;
2104 }
2268 dev_info (&udev->dev, 2105 dev_info (&udev->dev,
2269 "%s %s speed USB device using %s and address %d\n", 2106 "%s %s speed %sUSB device using %s and address %d\n",
2270 (udev->config) ? "reset" : "new", 2107 (udev->config) ? "reset" : "new", speed, type,
2271 ({ char *speed; switch (udev->speed) { 2108 udev->bus->controller->driver->name, udev->devnum);
2272 case USB_SPEED_LOW: speed = "low"; break;
2273 case USB_SPEED_FULL: speed = "full"; break;
2274 case USB_SPEED_HIGH: speed = "high"; break;
2275 default: speed = "?"; break;
2276 }; speed;}),
2277 udev->bus->controller->driver->name,
2278 udev->devnum);
2279 2109
2280 /* Set up TT records, if needed */ 2110 /* Set up TT records, if needed */
2281 if (hdev->tt) { 2111 if (hdev->tt) {
@@ -2317,6 +2147,8 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2317 * down tremendously by NAKing the unexpectedly 2147 * down tremendously by NAKing the unexpectedly
2318 * early status stage. Also, retry on all errors; 2148 * early status stage. Also, retry on all errors;
2319 * some devices are flakey. 2149 * some devices are flakey.
2150 * 255 is for WUSB devices, we actually need to use 512.
2151 * WUSB1.0[4.8.1].
2320 */ 2152 */
2321 for (j = 0; j < 3; ++j) { 2153 for (j = 0; j < 3; ++j) {
2322 buf->bMaxPacketSize0 = 0; 2154 buf->bMaxPacketSize0 = 0;
@@ -2326,7 +2158,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2326 buf, GET_DESCRIPTOR_BUFSIZE, 2158 buf, GET_DESCRIPTOR_BUFSIZE,
2327 (i ? USB_CTRL_GET_TIMEOUT : 1000)); 2159 (i ? USB_CTRL_GET_TIMEOUT : 1000));
2328 switch (buf->bMaxPacketSize0) { 2160 switch (buf->bMaxPacketSize0) {
2329 case 8: case 16: case 32: case 64: 2161 case 8: case 16: case 32: case 64: case 255:
2330 if (buf->bDescriptorType == 2162 if (buf->bDescriptorType ==
2331 USB_DT_DEVICE) { 2163 USB_DT_DEVICE) {
2332 r = 0; 2164 r = 0;
@@ -2400,7 +2232,8 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2400 if (retval) 2232 if (retval)
2401 goto fail; 2233 goto fail;
2402 2234
2403 i = udev->descriptor.bMaxPacketSize0; 2235 i = udev->descriptor.bMaxPacketSize0 == 0xff?
2236 512 : udev->descriptor.bMaxPacketSize0;
2404 if (le16_to_cpu(udev->ep0.desc.wMaxPacketSize) != i) { 2237 if (le16_to_cpu(udev->ep0.desc.wMaxPacketSize) != i) {
2405 if (udev->speed != USB_SPEED_FULL || 2238 if (udev->speed != USB_SPEED_FULL ||
2406 !(i == 8 || i == 16 || i == 32 || i == 64)) { 2239 !(i == 8 || i == 16 || i == 32 || i == 64)) {
@@ -2585,6 +2418,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
2585 usb_set_device_state(udev, USB_STATE_POWERED); 2418 usb_set_device_state(udev, USB_STATE_POWERED);
2586 udev->speed = USB_SPEED_UNKNOWN; 2419 udev->speed = USB_SPEED_UNKNOWN;
2587 udev->bus_mA = hub->mA_per_port; 2420 udev->bus_mA = hub->mA_per_port;
2421 udev->level = hdev->level + 1;
2588 2422
2589 /* set the address */ 2423 /* set the address */
2590 choose_address(udev); 2424 choose_address(udev);
@@ -2736,17 +2570,6 @@ static void hub_events(void)
2736 usb_get_intf(intf); 2570 usb_get_intf(intf);
2737 spin_unlock_irq(&hub_event_lock); 2571 spin_unlock_irq(&hub_event_lock);
2738 2572
2739 /* Is this is a root hub wanting to reactivate the downstream
2740 * ports? If so, be sure the interface resumes even if its
2741 * stub "device" node was never suspended.
2742 */
2743 if (i) {
2744 dpm_runtime_resume(&hdev->dev);
2745 dpm_runtime_resume(&intf->dev);
2746 usb_put_intf(intf);
2747 continue;
2748 }
2749
2750 /* Lock the device, then check to see if we were 2573 /* Lock the device, then check to see if we were
2751 * disconnected while waiting for the lock to succeed. */ 2574 * disconnected while waiting for the lock to succeed. */
2752 if (locktree(hdev) < 0) { 2575 if (locktree(hdev) < 0) {
@@ -2763,6 +2586,13 @@ static void hub_events(void)
2763 goto loop; 2586 goto loop;
2764 } 2587 }
2765 2588
2589 /* Is this is a root hub wanting to reactivate the downstream
2590 * ports? If so, be sure the interface resumes even if its
2591 * stub "device" node was never suspended.
2592 */
2593 if (i)
2594 usb_autoresume_device(hdev, 0);
2595
2766 /* If this is an inactive or suspended hub, do nothing */ 2596 /* If this is an inactive or suspended hub, do nothing */
2767 if (hub->quiescing) 2597 if (hub->quiescing)
2768 goto loop; 2598 goto loop;
@@ -2900,7 +2730,7 @@ static void hub_events(void)
2900 2730
2901 /* If this is a root hub, tell the HCD it's okay to 2731 /* If this is a root hub, tell the HCD it's okay to
2902 * re-enable port-change interrupts now. */ 2732 * re-enable port-change interrupts now. */
2903 if (!hdev->parent) 2733 if (!hdev->parent && !hub->busy_bits[0])
2904 usb_enable_root_hub_irq(hdev->bus); 2734 usb_enable_root_hub_irq(hdev->bus);
2905 2735
2906loop: 2736loop:
@@ -3075,6 +2905,9 @@ int usb_reset_device(struct usb_device *udev)
3075 break; 2905 break;
3076 } 2906 }
3077 clear_bit(port1, parent_hub->busy_bits); 2907 clear_bit(port1, parent_hub->busy_bits);
2908 if (!parent_hdev->parent && !parent_hub->busy_bits[0])
2909 usb_enable_root_hub_irq(parent_hdev->bus);
2910
3078 if (ret < 0) 2911 if (ret < 0)
3079 goto re_enumerate; 2912 goto re_enumerate;
3080 2913
@@ -3128,6 +2961,7 @@ re_enumerate:
3128 hub_port_logical_disconnect(parent_hub, port1); 2961 hub_port_logical_disconnect(parent_hub, port1);
3129 return -ENODEV; 2962 return -ENODEV;
3130} 2963}
2964EXPORT_SYMBOL(usb_reset_device);
3131 2965
3132/** 2966/**
3133 * usb_reset_composite_device - warn interface drivers and perform a USB port reset 2967 * usb_reset_composite_device - warn interface drivers and perform a USB port reset
@@ -3163,6 +2997,9 @@ int usb_reset_composite_device(struct usb_device *udev,
3163 return -EINVAL; 2997 return -EINVAL;
3164 } 2998 }
3165 2999
3000 /* Prevent autosuspend during the reset */
3001 usb_autoresume_device(udev, 1);
3002
3166 if (iface && iface->condition != USB_INTERFACE_BINDING) 3003 if (iface && iface->condition != USB_INTERFACE_BINDING)
3167 iface = NULL; 3004 iface = NULL;
3168 3005
@@ -3204,5 +3041,7 @@ int usb_reset_composite_device(struct usb_device *udev,
3204 } 3041 }
3205 } 3042 }
3206 3043
3044 usb_autosuspend_device(udev, 1);
3207 return ret; 3045 return ret;
3208} 3046}
3047EXPORT_SYMBOL(usb_reset_composite_device);
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h
index 29d5f45a8456..0f8e82a4d480 100644
--- a/drivers/usb/core/hub.h
+++ b/drivers/usb/core/hub.h
@@ -212,7 +212,8 @@ struct usb_hub {
212 unsigned long event_bits[1]; /* status change bitmask */ 212 unsigned long event_bits[1]; /* status change bitmask */
213 unsigned long change_bits[1]; /* ports with logical connect 213 unsigned long change_bits[1]; /* ports with logical connect
214 status change */ 214 status change */
215 unsigned long busy_bits[1]; /* ports being reset */ 215 unsigned long busy_bits[1]; /* ports being reset or
216 resumed */
216#if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */ 217#if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */
217#error event_bits[] is too short! 218#error event_bits[] is too short!
218#endif 219#endif
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index 3182c2224ba2..b5d6a79af0be 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -44,7 +44,7 @@
44#include "hcd.h" 44#include "hcd.h"
45 45
46static struct super_operations usbfs_ops; 46static struct super_operations usbfs_ops;
47static struct file_operations default_file_operations; 47static const struct file_operations default_file_operations;
48static struct vfsmount *usbfs_mount; 48static struct vfsmount *usbfs_mount;
49static int usbfs_mount_count; /* = 0 */ 49static int usbfs_mount_count; /* = 0 */
50static int ignore_mount = 0; 50static int ignore_mount = 0;
@@ -249,7 +249,6 @@ static struct inode *usbfs_get_inode (struct super_block *sb, int mode, dev_t de
249 inode->i_mode = mode; 249 inode->i_mode = mode;
250 inode->i_uid = current->fsuid; 250 inode->i_uid = current->fsuid;
251 inode->i_gid = current->fsgid; 251 inode->i_gid = current->fsgid;
252 inode->i_blksize = PAGE_CACHE_SIZE;
253 inode->i_blocks = 0; 252 inode->i_blocks = 0;
254 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; 253 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
255 switch (mode & S_IFMT) { 254 switch (mode & S_IFMT) {
@@ -264,7 +263,7 @@ static struct inode *usbfs_get_inode (struct super_block *sb, int mode, dev_t de
264 inode->i_fop = &simple_dir_operations; 263 inode->i_fop = &simple_dir_operations;
265 264
266 /* directory inodes start off with i_nlink == 2 (for "." entry) */ 265 /* directory inodes start off with i_nlink == 2 (for "." entry) */
267 inode->i_nlink++; 266 inc_nlink(inode);
268 break; 267 break;
269 } 268 }
270 } 269 }
@@ -296,7 +295,7 @@ static int usbfs_mkdir (struct inode *dir, struct dentry *dentry, int mode)
296 mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR; 295 mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR;
297 res = usbfs_mknod (dir, dentry, mode, 0); 296 res = usbfs_mknod (dir, dentry, mode, 0);
298 if (!res) 297 if (!res)
299 dir->i_nlink++; 298 inc_nlink(dir);
300 return res; 299 return res;
301} 300}
302 301
@@ -333,7 +332,7 @@ static int usbfs_unlink (struct inode *dir, struct dentry *dentry)
333{ 332{
334 struct inode *inode = dentry->d_inode; 333 struct inode *inode = dentry->d_inode;
335 mutex_lock(&inode->i_mutex); 334 mutex_lock(&inode->i_mutex);
336 dentry->d_inode->i_nlink--; 335 drop_nlink(dentry->d_inode);
337 dput(dentry); 336 dput(dentry);
338 mutex_unlock(&inode->i_mutex); 337 mutex_unlock(&inode->i_mutex);
339 d_delete(dentry); 338 d_delete(dentry);
@@ -348,10 +347,11 @@ static int usbfs_rmdir(struct inode *dir, struct dentry *dentry)
348 mutex_lock(&inode->i_mutex); 347 mutex_lock(&inode->i_mutex);
349 dentry_unhash(dentry); 348 dentry_unhash(dentry);
350 if (usbfs_empty(dentry)) { 349 if (usbfs_empty(dentry)) {
351 dentry->d_inode->i_nlink -= 2; 350 drop_nlink(dentry->d_inode);
351 drop_nlink(dentry->d_inode);
352 dput(dentry); 352 dput(dentry);
353 inode->i_flags |= S_DEAD; 353 inode->i_flags |= S_DEAD;
354 dir->i_nlink--; 354 drop_nlink(dir);
355 error = 0; 355 error = 0;
356 } 356 }
357 mutex_unlock(&inode->i_mutex); 357 mutex_unlock(&inode->i_mutex);
@@ -402,13 +402,13 @@ static loff_t default_file_lseek (struct file *file, loff_t offset, int orig)
402 402
403static int default_open (struct inode *inode, struct file *file) 403static int default_open (struct inode *inode, struct file *file)
404{ 404{
405 if (inode->u.generic_ip) 405 if (inode->i_private)
406 file->private_data = inode->u.generic_ip; 406 file->private_data = inode->i_private;
407 407
408 return 0; 408 return 0;
409} 409}
410 410
411static struct file_operations default_file_operations = { 411static const struct file_operations default_file_operations = {
412 .read = default_read_file, 412 .read = default_read_file,
413 .write = default_write_file, 413 .write = default_write_file,
414 .open = default_open, 414 .open = default_open,
@@ -495,7 +495,7 @@ static int fs_create_by_name (const char *name, mode_t mode,
495 495
496static struct dentry *fs_create_file (const char *name, mode_t mode, 496static struct dentry *fs_create_file (const char *name, mode_t mode,
497 struct dentry *parent, void *data, 497 struct dentry *parent, void *data,
498 struct file_operations *fops, 498 const struct file_operations *fops,
499 uid_t uid, gid_t gid) 499 uid_t uid, gid_t gid)
500{ 500{
501 struct dentry *dentry; 501 struct dentry *dentry;
@@ -509,7 +509,7 @@ static struct dentry *fs_create_file (const char *name, mode_t mode,
509 } else { 509 } else {
510 if (dentry->d_inode) { 510 if (dentry->d_inode) {
511 if (data) 511 if (data)
512 dentry->d_inode->u.generic_ip = data; 512 dentry->d_inode->i_private = data;
513 if (fops) 513 if (fops)
514 dentry->d_inode->i_fop = fops; 514 dentry->d_inode->i_fop = fops;
515 dentry->d_inode->i_uid = uid; 515 dentry->d_inode->i_uid = uid;
@@ -699,7 +699,7 @@ static void usbfs_remove_device(struct usb_device *dev)
699 sinfo.si_errno = EPIPE; 699 sinfo.si_errno = EPIPE;
700 sinfo.si_code = SI_ASYNCIO; 700 sinfo.si_code = SI_ASYNCIO;
701 sinfo.si_addr = ds->disccontext; 701 sinfo.si_addr = ds->disccontext;
702 kill_proc_info_as_uid(ds->discsignr, &sinfo, ds->disc_pid, ds->disc_uid, ds->disc_euid, ds->secid); 702 kill_pid_info_as_uid(ds->discsignr, &sinfo, ds->disc_pid, ds->disc_uid, ds->disc_euid, ds->secid);
703 } 703 }
704 } 704 }
705} 705}
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 4cc8d3e67db7..85b1cd18336f 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -23,59 +23,44 @@ static void usb_api_blocking_completion(struct urb *urb, struct pt_regs *regs)
23} 23}
24 24
25 25
26static void timeout_kill(unsigned long data) 26/*
27{ 27 * Starts urb and waits for completion or timeout. Note that this call
28 struct urb *urb = (struct urb *) data; 28 * is NOT interruptible. Many device driver i/o requests should be
29 29 * interruptible and therefore these drivers should implement their
30 usb_unlink_urb(urb); 30 * own interruptible routines.
31} 31 */
32 32static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length)
33// Starts urb and waits for completion or timeout
34// note that this call is NOT interruptible, while
35// many device driver i/o requests should be interruptible
36static int usb_start_wait_urb(struct urb *urb, int timeout, int* actual_length)
37{ 33{
38 struct completion done; 34 struct completion done;
39 struct timer_list timer; 35 unsigned long expire;
40 int status; 36 int status;
41 37
42 init_completion(&done); 38 init_completion(&done);
43 urb->context = &done; 39 urb->context = &done;
44 urb->actual_length = 0; 40 urb->actual_length = 0;
45 status = usb_submit_urb(urb, GFP_NOIO); 41 status = usb_submit_urb(urb, GFP_NOIO);
46 42 if (unlikely(status))
47 if (status == 0) { 43 goto out;
48 if (timeout > 0) { 44
49 init_timer(&timer); 45 expire = timeout ? msecs_to_jiffies(timeout) : MAX_SCHEDULE_TIMEOUT;
50 timer.expires = jiffies + msecs_to_jiffies(timeout); 46 if (!wait_for_completion_timeout(&done, expire)) {
51 timer.data = (unsigned long)urb; 47
52 timer.function = timeout_kill; 48 dev_dbg(&urb->dev->dev,
53 /* grr. timeout _should_ include submit delays. */ 49 "%s timed out on ep%d%s len=%d/%d\n",
54 add_timer(&timer); 50 current->comm,
55 } 51 usb_pipeendpoint(urb->pipe),
56 wait_for_completion(&done); 52 usb_pipein(urb->pipe) ? "in" : "out",
53 urb->actual_length,
54 urb->transfer_buffer_length);
55
56 usb_kill_urb(urb);
57 status = urb->status == -ENOENT ? -ETIMEDOUT : urb->status;
58 } else
57 status = urb->status; 59 status = urb->status;
58 /* note: HCDs return ETIMEDOUT for other reasons too */ 60out:
59 if (status == -ECONNRESET) {
60 dev_dbg(&urb->dev->dev,
61 "%s timed out on ep%d%s len=%d/%d\n",
62 current->comm,
63 usb_pipeendpoint(urb->pipe),
64 usb_pipein(urb->pipe) ? "in" : "out",
65 urb->actual_length,
66 urb->transfer_buffer_length
67 );
68 if (urb->actual_length > 0)
69 status = 0;
70 else
71 status = -ETIMEDOUT;
72 }
73 if (timeout > 0)
74 del_timer_sync(&timer);
75 }
76
77 if (actual_length) 61 if (actual_length)
78 *actual_length = urb->actual_length; 62 *actual_length = urb->actual_length;
63
79 usb_free_urb(urb); 64 usb_free_urb(urb);
80 return status; 65 return status;
81} 66}
@@ -263,7 +248,7 @@ static void sg_clean (struct usb_sg_request *io)
263 248
264static void sg_complete (struct urb *urb, struct pt_regs *regs) 249static void sg_complete (struct urb *urb, struct pt_regs *regs)
265{ 250{
266 struct usb_sg_request *io = (struct usb_sg_request *) urb->context; 251 struct usb_sg_request *io = urb->context;
267 252
268 spin_lock (&io->lock); 253 spin_lock (&io->lock);
269 254
@@ -999,8 +984,8 @@ void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr)
999 ep = dev->ep_in[epnum]; 984 ep = dev->ep_in[epnum];
1000 dev->ep_in[epnum] = NULL; 985 dev->ep_in[epnum] = NULL;
1001 } 986 }
1002 if (ep && dev->bus && dev->bus->op && dev->bus->op->disable) 987 if (ep && dev->bus)
1003 dev->bus->op->disable(dev, ep); 988 usb_hcd_endpoint_disable(dev, ep);
1004} 989}
1005 990
1006/** 991/**
@@ -1381,9 +1366,6 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
1381 if (cp && configuration == 0) 1366 if (cp && configuration == 0)
1382 dev_warn(&dev->dev, "config 0 descriptor??\n"); 1367 dev_warn(&dev->dev, "config 0 descriptor??\n");
1383 1368
1384 if (dev->state == USB_STATE_SUSPENDED)
1385 return -EHOSTUNREACH;
1386
1387 /* Allocate memory for new interfaces before doing anything else, 1369 /* Allocate memory for new interfaces before doing anything else,
1388 * so that if we run out then nothing will have changed. */ 1370 * so that if we run out then nothing will have changed. */
1389 n = nintf = 0; 1371 n = nintf = 0;
@@ -1418,6 +1400,11 @@ free_interfaces:
1418 configuration, -i); 1400 configuration, -i);
1419 } 1401 }
1420 1402
1403 /* Wake up the device so we can send it the Set-Config request */
1404 ret = usb_autoresume_device(dev, 1);
1405 if (ret)
1406 goto free_interfaces;
1407
1421 /* if it's already configured, clear out old state first. 1408 /* if it's already configured, clear out old state first.
1422 * getting rid of old interfaces means unbinding their drivers. 1409 * getting rid of old interfaces means unbinding their drivers.
1423 */ 1410 */
@@ -1437,6 +1424,7 @@ free_interfaces:
1437 dev->actconfig = cp; 1424 dev->actconfig = cp;
1438 if (!cp) { 1425 if (!cp) {
1439 usb_set_device_state(dev, USB_STATE_ADDRESS); 1426 usb_set_device_state(dev, USB_STATE_ADDRESS);
1427 usb_autosuspend_device(dev, 1);
1440 goto free_interfaces; 1428 goto free_interfaces;
1441 } 1429 }
1442 usb_set_device_state(dev, USB_STATE_CONFIGURED); 1430 usb_set_device_state(dev, USB_STATE_CONFIGURED);
@@ -1505,8 +1493,68 @@ free_interfaces:
1505 usb_create_sysfs_intf_files (intf); 1493 usb_create_sysfs_intf_files (intf);
1506 } 1494 }
1507 1495
1496 usb_autosuspend_device(dev, 1);
1497 return 0;
1498}
1499
1500struct set_config_request {
1501 struct usb_device *udev;
1502 int config;
1503 struct work_struct work;
1504};
1505
1506/* Worker routine for usb_driver_set_configuration() */
1507static void driver_set_config_work(void *_req)
1508{
1509 struct set_config_request *req = _req;
1510
1511 usb_lock_device(req->udev);
1512 usb_set_configuration(req->udev, req->config);
1513 usb_unlock_device(req->udev);
1514 usb_put_dev(req->udev);
1515 kfree(req);
1516}
1517
1518/**
1519 * usb_driver_set_configuration - Provide a way for drivers to change device configurations
1520 * @udev: the device whose configuration is being updated
1521 * @config: the configuration being chosen.
1522 * Context: In process context, must be able to sleep
1523 *
1524 * Device interface drivers are not allowed to change device configurations.
1525 * This is because changing configurations will destroy the interface the
1526 * driver is bound to and create new ones; it would be like a floppy-disk
1527 * driver telling the computer to replace the floppy-disk drive with a
1528 * tape drive!
1529 *
1530 * Still, in certain specialized circumstances the need may arise. This
1531 * routine gets around the normal restrictions by using a work thread to
1532 * submit the change-config request.
1533 *
1534 * Returns 0 if the request was succesfully queued, error code otherwise.
1535 * The caller has no way to know whether the queued request will eventually
1536 * succeed.
1537 */
1538int usb_driver_set_configuration(struct usb_device *udev, int config)
1539{
1540 struct set_config_request *req;
1541
1542 req = kmalloc(sizeof(*req), GFP_KERNEL);
1543 if (!req)
1544 return -ENOMEM;
1545 req->udev = udev;
1546 req->config = config;
1547 INIT_WORK(&req->work, driver_set_config_work, req);
1548
1549 usb_get_dev(udev);
1550 if (!schedule_work(&req->work)) {
1551 usb_put_dev(udev);
1552 kfree(req);
1553 return -EINVAL;
1554 }
1508 return 0; 1555 return 0;
1509} 1556}
1557EXPORT_SYMBOL_GPL(usb_driver_set_configuration);
1510 1558
1511// synchronous request completion model 1559// synchronous request completion model
1512EXPORT_SYMBOL(usb_control_msg); 1560EXPORT_SYMBOL(usb_control_msg);
diff --git a/drivers/usb/core/notify.c b/drivers/usb/core/notify.c
index b042676af0a5..6b36897ca151 100644
--- a/drivers/usb/core/notify.c
+++ b/drivers/usb/core/notify.c
@@ -50,8 +50,11 @@ void usb_notify_add_device(struct usb_device *udev)
50 50
51void usb_notify_remove_device(struct usb_device *udev) 51void usb_notify_remove_device(struct usb_device *udev)
52{ 52{
53 /* Protect against simultaneous usbfs open */
54 mutex_lock(&usbfs_mutex);
53 blocking_notifier_call_chain(&usb_notifier_list, 55 blocking_notifier_call_chain(&usb_notifier_list,
54 USB_DEVICE_REMOVE, udev); 56 USB_DEVICE_REMOVE, udev);
57 mutex_unlock(&usbfs_mutex);
55} 58}
56 59
57void usb_notify_add_bus(struct usb_bus *ubus) 60void usb_notify_add_bus(struct usb_bus *ubus)
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index dec973affb0f..55d8f575206d 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -60,7 +60,7 @@ static ssize_t
60set_bConfigurationValue (struct device *dev, struct device_attribute *attr, 60set_bConfigurationValue (struct device *dev, struct device_attribute *attr,
61 const char *buf, size_t count) 61 const char *buf, size_t count)
62{ 62{
63 struct usb_device *udev = udev = to_usb_device (dev); 63 struct usb_device *udev = to_usb_device (dev);
64 int config, value; 64 int config, value;
65 65
66 if (sscanf (buf, "%u", &config) != 1 || config > 255) 66 if (sscanf (buf, "%u", &config) != 1 || config > 255)
@@ -186,6 +186,7 @@ usb_descriptor_attr (bMaxPacketSize0, "%d\n")
186 186
187static struct attribute *dev_attrs[] = { 187static struct attribute *dev_attrs[] = {
188 /* current configuration's attributes */ 188 /* current configuration's attributes */
189 &dev_attr_configuration.attr,
189 &dev_attr_bNumInterfaces.attr, 190 &dev_attr_bNumInterfaces.attr,
190 &dev_attr_bConfigurationValue.attr, 191 &dev_attr_bConfigurationValue.attr,
191 &dev_attr_bmAttributes.attr, 192 &dev_attr_bmAttributes.attr,
@@ -209,20 +210,40 @@ static struct attribute_group dev_attr_grp = {
209 .attrs = dev_attrs, 210 .attrs = dev_attrs,
210}; 211};
211 212
212void usb_create_sysfs_dev_files (struct usb_device *udev) 213int usb_create_sysfs_dev_files(struct usb_device *udev)
213{ 214{
214 struct device *dev = &udev->dev; 215 struct device *dev = &udev->dev;
216 int retval;
215 217
216 sysfs_create_group(&dev->kobj, &dev_attr_grp); 218 retval = sysfs_create_group(&dev->kobj, &dev_attr_grp);
219 if (retval)
220 return retval;
217 221
218 if (udev->manufacturer) 222 if (udev->manufacturer) {
219 device_create_file (dev, &dev_attr_manufacturer); 223 retval = device_create_file (dev, &dev_attr_manufacturer);
220 if (udev->product) 224 if (retval)
221 device_create_file (dev, &dev_attr_product); 225 goto error;
222 if (udev->serial) 226 }
223 device_create_file (dev, &dev_attr_serial); 227 if (udev->product) {
224 device_create_file (dev, &dev_attr_configuration); 228 retval = device_create_file (dev, &dev_attr_product);
225 usb_create_ep_files(dev, &udev->ep0, udev); 229 if (retval)
230 goto error;
231 }
232 if (udev->serial) {
233 retval = device_create_file (dev, &dev_attr_serial);
234 if (retval)
235 goto error;
236 }
237 retval = usb_create_ep_files(dev, &udev->ep0, udev);
238 if (retval)
239 goto error;
240 return 0;
241error:
242 usb_remove_ep_files(&udev->ep0);
243 device_remove_file(dev, &dev_attr_manufacturer);
244 device_remove_file(dev, &dev_attr_product);
245 device_remove_file(dev, &dev_attr_serial);
246 return retval;
226} 247}
227 248
228void usb_remove_sysfs_dev_files (struct usb_device *udev) 249void usb_remove_sysfs_dev_files (struct usb_device *udev)
@@ -238,7 +259,6 @@ void usb_remove_sysfs_dev_files (struct usb_device *udev)
238 device_remove_file(dev, &dev_attr_product); 259 device_remove_file(dev, &dev_attr_product);
239 if (udev->serial) 260 if (udev->serial)
240 device_remove_file(dev, &dev_attr_serial); 261 device_remove_file(dev, &dev_attr_serial);
241 device_remove_file (dev, &dev_attr_configuration);
242} 262}
243 263
244/* Interface fields */ 264/* Interface fields */
@@ -340,18 +360,28 @@ static inline void usb_remove_intf_ep_files(struct usb_interface *intf)
340 usb_remove_ep_files(&iface_desc->endpoint[i]); 360 usb_remove_ep_files(&iface_desc->endpoint[i]);
341} 361}
342 362
343void usb_create_sysfs_intf_files (struct usb_interface *intf) 363int usb_create_sysfs_intf_files(struct usb_interface *intf)
344{ 364{
345 struct usb_device *udev = interface_to_usbdev(intf); 365 struct usb_device *udev = interface_to_usbdev(intf);
346 struct usb_host_interface *alt = intf->cur_altsetting; 366 struct usb_host_interface *alt = intf->cur_altsetting;
367 int retval;
347 368
348 sysfs_create_group(&intf->dev.kobj, &intf_attr_grp); 369 retval = sysfs_create_group(&intf->dev.kobj, &intf_attr_grp);
370 if (retval)
371 goto error;
349 372
350 if (alt->string == NULL) 373 if (alt->string == NULL)
351 alt->string = usb_cache_string(udev, alt->desc.iInterface); 374 alt->string = usb_cache_string(udev, alt->desc.iInterface);
352 if (alt->string) 375 if (alt->string)
353 device_create_file(&intf->dev, &dev_attr_interface); 376 retval = device_create_file(&intf->dev, &dev_attr_interface);
354 usb_create_intf_ep_files(intf, udev); 377 usb_create_intf_ep_files(intf, udev);
378 return 0;
379error:
380 if (alt->string)
381 device_remove_file(&intf->dev, &dev_attr_interface);
382 sysfs_remove_group(&intf->dev.kobj, &intf_attr_grp);
383 usb_remove_intf_ep_files(intf);
384 return retval;
355} 385}
356 386
357void usb_remove_sysfs_intf_files (struct usb_interface *intf) 387void usb_remove_sysfs_intf_files (struct usb_interface *intf)
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index 9864988377c7..9801d08edacf 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -57,7 +57,7 @@ struct urb *usb_alloc_urb(int iso_packets, gfp_t mem_flags)
57{ 57{
58 struct urb *urb; 58 struct urb *urb;
59 59
60 urb = (struct urb *)kmalloc(sizeof(struct urb) + 60 urb = kmalloc(sizeof(struct urb) +
61 iso_packets * sizeof(struct usb_iso_packet_descriptor), 61 iso_packets * sizeof(struct usb_iso_packet_descriptor),
62 mem_flags); 62 mem_flags);
63 if (!urb) { 63 if (!urb) {
@@ -221,7 +221,6 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
221{ 221{
222 int pipe, temp, max; 222 int pipe, temp, max;
223 struct usb_device *dev; 223 struct usb_device *dev;
224 struct usb_operations *op;
225 int is_out; 224 int is_out;
226 225
227 if (!urb || urb->hcpriv || !urb->complete) 226 if (!urb || urb->hcpriv || !urb->complete)
@@ -233,8 +232,6 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
233 if (dev->bus->controller->power.power_state.event != PM_EVENT_ON 232 if (dev->bus->controller->power.power_state.event != PM_EVENT_ON
234 || dev->state == USB_STATE_SUSPENDED) 233 || dev->state == USB_STATE_SUSPENDED)
235 return -EHOSTUNREACH; 234 return -EHOSTUNREACH;
236 if (!(op = dev->bus->op) || !op->submit_urb)
237 return -ENODEV;
238 235
239 urb->status = -EINPROGRESS; 236 urb->status = -EINPROGRESS;
240 urb->actual_length = 0; 237 urb->actual_length = 0;
@@ -376,7 +373,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
376 urb->interval = temp; 373 urb->interval = temp;
377 } 374 }
378 375
379 return op->submit_urb (urb, mem_flags); 376 return usb_hcd_submit_urb (urb, mem_flags);
380} 377}
381 378
382/*-------------------------------------------------------------------*/ 379/*-------------------------------------------------------------------*/
@@ -440,9 +437,9 @@ int usb_unlink_urb(struct urb *urb)
440{ 437{
441 if (!urb) 438 if (!urb)
442 return -EINVAL; 439 return -EINVAL;
443 if (!(urb->dev && urb->dev->bus && urb->dev->bus->op)) 440 if (!(urb->dev && urb->dev->bus))
444 return -ENODEV; 441 return -ENODEV;
445 return urb->dev->bus->op->unlink_urb(urb, -ECONNRESET); 442 return usb_hcd_unlink_urb(urb, -ECONNRESET);
446} 443}
447 444
448/** 445/**
@@ -468,13 +465,13 @@ int usb_unlink_urb(struct urb *urb)
468void usb_kill_urb(struct urb *urb) 465void usb_kill_urb(struct urb *urb)
469{ 466{
470 might_sleep(); 467 might_sleep();
471 if (!(urb && urb->dev && urb->dev->bus && urb->dev->bus->op)) 468 if (!(urb && urb->dev && urb->dev->bus))
472 return; 469 return;
473 spin_lock_irq(&urb->lock); 470 spin_lock_irq(&urb->lock);
474 ++urb->reject; 471 ++urb->reject;
475 spin_unlock_irq(&urb->lock); 472 spin_unlock_irq(&urb->lock);
476 473
477 urb->dev->bus->op->unlink_urb(urb, -ENOENT); 474 usb_hcd_unlink_urb(urb, -ENOENT);
478 wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0); 475 wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0);
479 476
480 spin_lock_irq(&urb->lock); 477 spin_lock_irq(&urb->lock);
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 184c24660a4c..e4df9edf1bc0 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -33,6 +33,7 @@
33#include <linux/smp_lock.h> 33#include <linux/smp_lock.h>
34#include <linux/usb.h> 34#include <linux/usb.h>
35#include <linux/mutex.h> 35#include <linux/mutex.h>
36#include <linux/workqueue.h>
36 37
37#include <asm/io.h> 38#include <asm/io.h>
38#include <asm/scatterlist.h> 39#include <asm/scatterlist.h>
@@ -47,6 +48,8 @@ const char *usbcore_name = "usbcore";
47 48
48static int nousb; /* Disable USB when built into kernel image */ 49static int nousb; /* Disable USB when built into kernel image */
49 50
51struct workqueue_struct *ksuspend_usb_wq; /* For autosuspend */
52
50 53
51/** 54/**
52 * usb_ifnum_to_if - get the interface object with a given interface number 55 * usb_ifnum_to_if - get the interface object with a given interface number
@@ -67,7 +70,8 @@ static int nousb; /* Disable USB when built into kernel image */
67 * Don't call this function unless you are bound to one of the interfaces 70 * Don't call this function unless you are bound to one of the interfaces
68 * on this device or you have locked the device! 71 * on this device or you have locked the device!
69 */ 72 */
70struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum) 73struct usb_interface *usb_ifnum_to_if(const struct usb_device *dev,
74 unsigned ifnum)
71{ 75{
72 struct usb_host_config *config = dev->actconfig; 76 struct usb_host_config *config = dev->actconfig;
73 int i; 77 int i;
@@ -100,8 +104,8 @@ struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum)
100 * Don't call this function unless you are bound to the intf interface 104 * Don't call this function unless you are bound to the intf interface
101 * or you have locked the device! 105 * or you have locked the device!
102 */ 106 */
103struct usb_host_interface *usb_altnum_to_altsetting(struct usb_interface *intf, 107struct usb_host_interface *usb_altnum_to_altsetting(const struct usb_interface *intf,
104 unsigned int altnum) 108 unsigned int altnum)
105{ 109{
106 int i; 110 int i;
107 111
@@ -112,87 +116,6 @@ struct usb_host_interface *usb_altnum_to_altsetting(struct usb_interface *intf,
112 return NULL; 116 return NULL;
113} 117}
114 118
115/**
116 * usb_driver_claim_interface - bind a driver to an interface
117 * @driver: the driver to be bound
118 * @iface: the interface to which it will be bound; must be in the
119 * usb device's active configuration
120 * @priv: driver data associated with that interface
121 *
122 * This is used by usb device drivers that need to claim more than one
123 * interface on a device when probing (audio and acm are current examples).
124 * No device driver should directly modify internal usb_interface or
125 * usb_device structure members.
126 *
127 * Few drivers should need to use this routine, since the most natural
128 * way to bind to an interface is to return the private data from
129 * the driver's probe() method.
130 *
131 * Callers must own the device lock and the driver model's usb_bus_type.subsys
132 * writelock. So driver probe() entries don't need extra locking,
133 * but other call contexts may need to explicitly claim those locks.
134 */
135int usb_driver_claim_interface(struct usb_driver *driver,
136 struct usb_interface *iface, void* priv)
137{
138 struct device *dev = &iface->dev;
139
140 if (dev->driver)
141 return -EBUSY;
142
143 dev->driver = &driver->driver;
144 usb_set_intfdata(iface, priv);
145 iface->condition = USB_INTERFACE_BOUND;
146 mark_active(iface);
147
148 /* if interface was already added, bind now; else let
149 * the future device_add() bind it, bypassing probe()
150 */
151 if (device_is_registered(dev))
152 device_bind_driver(dev);
153
154 return 0;
155}
156
157/**
158 * usb_driver_release_interface - unbind a driver from an interface
159 * @driver: the driver to be unbound
160 * @iface: the interface from which it will be unbound
161 *
162 * This can be used by drivers to release an interface without waiting
163 * for their disconnect() methods to be called. In typical cases this
164 * also causes the driver disconnect() method to be called.
165 *
166 * This call is synchronous, and may not be used in an interrupt context.
167 * Callers must own the device lock and the driver model's usb_bus_type.subsys
168 * writelock. So driver disconnect() entries don't need extra locking,
169 * but other call contexts may need to explicitly claim those locks.
170 */
171void usb_driver_release_interface(struct usb_driver *driver,
172 struct usb_interface *iface)
173{
174 struct device *dev = &iface->dev;
175
176 /* this should never happen, don't release something that's not ours */
177 if (!dev->driver || dev->driver != &driver->driver)
178 return;
179
180 /* don't release from within disconnect() */
181 if (iface->condition != USB_INTERFACE_BOUND)
182 return;
183
184 /* don't release if the interface hasn't been added yet */
185 if (device_is_registered(dev)) {
186 iface->condition = USB_INTERFACE_UNBINDING;
187 device_release_driver(dev);
188 }
189
190 dev->driver = NULL;
191 usb_set_intfdata(iface, NULL);
192 iface->condition = USB_INTERFACE_UNBOUND;
193 mark_quiesced(iface);
194}
195
196struct find_interface_arg { 119struct find_interface_arg {
197 int minor; 120 int minor;
198 struct usb_interface *interface; 121 struct usb_interface *interface;
@@ -204,7 +127,7 @@ static int __find_interface(struct device * dev, void * data)
204 struct usb_interface *intf; 127 struct usb_interface *intf;
205 128
206 /* can't look at usb devices, only interfaces */ 129 /* can't look at usb devices, only interfaces */
207 if (dev->driver == &usb_generic_driver) 130 if (is_usb_device(dev))
208 return 0; 131 return 0;
209 132
210 intf = to_usb_interface(dev); 133 intf = to_usb_interface(dev);
@@ -227,147 +150,82 @@ static int __find_interface(struct device * dev, void * data)
227struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor) 150struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor)
228{ 151{
229 struct find_interface_arg argb; 152 struct find_interface_arg argb;
153 int retval;
230 154
231 argb.minor = minor; 155 argb.minor = minor;
232 argb.interface = NULL; 156 argb.interface = NULL;
233 driver_for_each_device(&drv->driver, NULL, &argb, __find_interface); 157 /* eat the error, it will be in argb.interface */
158 retval = driver_for_each_device(&drv->drvwrap.driver, NULL, &argb,
159 __find_interface);
234 return argb.interface; 160 return argb.interface;
235} 161}
236 162
237#ifdef CONFIG_HOTPLUG 163/**
238 164 * usb_release_dev - free a usb device structure when all users of it are finished.
239/* 165 * @dev: device that's been disconnected
240 * This sends an uevent to userspace, typically helping to load driver
241 * or other modules, configure the device, and more. Drivers can provide
242 * a MODULE_DEVICE_TABLE to help with module loading subtasks.
243 * 166 *
244 * We're called either from khubd (the typical case) or from root hub 167 * Will be called only by the device core when all users of this usb device are
245 * (init, kapmd, modprobe, rmmod, etc), but the agents need to handle 168 * done.
246 * delays in event delivery. Use sysfs (and DEVPATH) to make sure the
247 * device (and this configuration!) are still present.
248 */ 169 */
249static int usb_uevent(struct device *dev, char **envp, int num_envp, 170static void usb_release_dev(struct device *dev)
250 char *buffer, int buffer_size)
251{ 171{
252 struct usb_interface *intf; 172 struct usb_device *udev;
253 struct usb_device *usb_dev;
254 struct usb_host_interface *alt;
255 int i = 0;
256 int length = 0;
257
258 if (!dev)
259 return -ENODEV;
260
261 /* driver is often null here; dev_dbg() would oops */
262 pr_debug ("usb %s: uevent\n", dev->bus_id);
263
264 /* Must check driver_data here, as on remove driver is always NULL */
265 if ((dev->driver == &usb_generic_driver) ||
266 (dev->driver_data == &usb_generic_driver_data))
267 return 0;
268
269 intf = to_usb_interface(dev);
270 usb_dev = interface_to_usbdev (intf);
271 alt = intf->cur_altsetting;
272 173
273 if (usb_dev->devnum < 0) { 174 udev = to_usb_device(dev);
274 pr_debug ("usb %s: already deleted?\n", dev->bus_id);
275 return -ENODEV;
276 }
277 if (!usb_dev->bus) {
278 pr_debug ("usb %s: bus removed?\n", dev->bus_id);
279 return -ENODEV;
280 }
281 175
282#ifdef CONFIG_USB_DEVICEFS 176#ifdef CONFIG_USB_SUSPEND
283 /* If this is available, userspace programs can directly read 177 cancel_delayed_work(&udev->autosuspend);
284 * all the device descriptors we don't tell them about. Or 178 flush_workqueue(ksuspend_usb_wq);
285 * even act as usermode drivers.
286 *
287 * FIXME reduce hardwired intelligence here
288 */
289 if (add_uevent_var(envp, num_envp, &i,
290 buffer, buffer_size, &length,
291 "DEVICE=/proc/bus/usb/%03d/%03d",
292 usb_dev->bus->busnum, usb_dev->devnum))
293 return -ENOMEM;
294#endif 179#endif
180 usb_destroy_configuration(udev);
181 usb_put_hcd(bus_to_hcd(udev->bus));
182 kfree(udev->product);
183 kfree(udev->manufacturer);
184 kfree(udev->serial);
185 kfree(udev);
186}
295 187
296 /* per-device configurations are common */ 188#ifdef CONFIG_PM
297 if (add_uevent_var(envp, num_envp, &i,
298 buffer, buffer_size, &length,
299 "PRODUCT=%x/%x/%x",
300 le16_to_cpu(usb_dev->descriptor.idVendor),
301 le16_to_cpu(usb_dev->descriptor.idProduct),
302 le16_to_cpu(usb_dev->descriptor.bcdDevice)))
303 return -ENOMEM;
304 189
305 /* class-based driver binding models */ 190static int ksuspend_usb_init(void)
306 if (add_uevent_var(envp, num_envp, &i, 191{
307 buffer, buffer_size, &length, 192 ksuspend_usb_wq = create_singlethread_workqueue("ksuspend_usbd");
308 "TYPE=%d/%d/%d", 193 if (!ksuspend_usb_wq)
309 usb_dev->descriptor.bDeviceClass,
310 usb_dev->descriptor.bDeviceSubClass,
311 usb_dev->descriptor.bDeviceProtocol))
312 return -ENOMEM; 194 return -ENOMEM;
195 return 0;
196}
313 197
314 if (add_uevent_var(envp, num_envp, &i, 198static void ksuspend_usb_cleanup(void)
315 buffer, buffer_size, &length, 199{
316 "INTERFACE=%d/%d/%d", 200 destroy_workqueue(ksuspend_usb_wq);
317 alt->desc.bInterfaceClass, 201}
318 alt->desc.bInterfaceSubClass,
319 alt->desc.bInterfaceProtocol))
320 return -ENOMEM;
321 202
322 if (add_uevent_var(envp, num_envp, &i, 203#else
323 buffer, buffer_size, &length,
324 "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X",
325 le16_to_cpu(usb_dev->descriptor.idVendor),
326 le16_to_cpu(usb_dev->descriptor.idProduct),
327 le16_to_cpu(usb_dev->descriptor.bcdDevice),
328 usb_dev->descriptor.bDeviceClass,
329 usb_dev->descriptor.bDeviceSubClass,
330 usb_dev->descriptor.bDeviceProtocol,
331 alt->desc.bInterfaceClass,
332 alt->desc.bInterfaceSubClass,
333 alt->desc.bInterfaceProtocol))
334 return -ENOMEM;
335 204
336 envp[i] = NULL; 205#define ksuspend_usb_init() 0
206#define ksuspend_usb_cleanup() do {} while (0)
337 207
338 return 0; 208#endif
339}
340 209
341#else 210#ifdef CONFIG_USB_SUSPEND
342 211
343static int usb_uevent(struct device *dev, char **envp, 212/* usb_autosuspend_work - callback routine to autosuspend a USB device */
344 int num_envp, char *buffer, int buffer_size) 213static void usb_autosuspend_work(void *_udev)
345{ 214{
346 return -ENODEV; 215 struct usb_device *udev = _udev;
347}
348 216
349#endif /* CONFIG_HOTPLUG */ 217 usb_pm_lock(udev);
218 udev->auto_pm = 1;
219 usb_suspend_both(udev, PMSG_SUSPEND);
220 usb_pm_unlock(udev);
221}
350 222
351/** 223#else
352 * usb_release_dev - free a usb device structure when all users of it are finished.
353 * @dev: device that's been disconnected
354 *
355 * Will be called only by the device core when all users of this usb device are
356 * done.
357 */
358static void usb_release_dev(struct device *dev)
359{
360 struct usb_device *udev;
361 224
362 udev = to_usb_device(dev); 225static void usb_autosuspend_work(void *_udev)
226{}
363 227
364 usb_destroy_configuration(udev); 228#endif
365 usb_bus_put(udev->bus);
366 kfree(udev->product);
367 kfree(udev->manufacturer);
368 kfree(udev->serial);
369 kfree(udev);
370}
371 229
372/** 230/**
373 * usb_alloc_dev - usb device constructor (usbcore-internal) 231 * usb_alloc_dev - usb device constructor (usbcore-internal)
@@ -390,8 +248,7 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1)
390 if (!dev) 248 if (!dev)
391 return NULL; 249 return NULL;
392 250
393 bus = usb_bus_get(bus); 251 if (!usb_get_hcd(bus_to_hcd(bus))) {
394 if (!bus) {
395 kfree(dev); 252 kfree(dev);
396 return NULL; 253 return NULL;
397 } 254 }
@@ -399,11 +256,12 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1)
399 device_initialize(&dev->dev); 256 device_initialize(&dev->dev);
400 dev->dev.bus = &usb_bus_type; 257 dev->dev.bus = &usb_bus_type;
401 dev->dev.dma_mask = bus->controller->dma_mask; 258 dev->dev.dma_mask = bus->controller->dma_mask;
402 dev->dev.driver_data = &usb_generic_driver_data;
403 dev->dev.driver = &usb_generic_driver;
404 dev->dev.release = usb_release_dev; 259 dev->dev.release = usb_release_dev;
405 dev->state = USB_STATE_ATTACHED; 260 dev->state = USB_STATE_ATTACHED;
406 261
262 /* This magic assignment distinguishes devices from interfaces */
263 dev->dev.platform_data = &usb_generic_driver;
264
407 INIT_LIST_HEAD(&dev->ep0.urb_list); 265 INIT_LIST_HEAD(&dev->ep0.urb_list);
408 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE; 266 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
409 dev->ep0.desc.bDescriptorType = USB_DT_ENDPOINT; 267 dev->ep0.desc.bDescriptorType = USB_DT_ENDPOINT;
@@ -444,6 +302,10 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1)
444 dev->parent = parent; 302 dev->parent = parent;
445 INIT_LIST_HEAD(&dev->filelist); 303 INIT_LIST_HEAD(&dev->filelist);
446 304
305#ifdef CONFIG_PM
306 mutex_init(&dev->pm_mutex);
307 INIT_WORK(&dev->autosuspend, usb_autosuspend_work, dev);
308#endif
447 return dev; 309 return dev;
448} 310}
449 311
@@ -549,7 +411,7 @@ void usb_put_intf(struct usb_interface *intf)
549 * case the driver already owns the device lock.) 411 * case the driver already owns the device lock.)
550 */ 412 */
551int usb_lock_device_for_reset(struct usb_device *udev, 413int usb_lock_device_for_reset(struct usb_device *udev,
552 struct usb_interface *iface) 414 const struct usb_interface *iface)
553{ 415{
554 unsigned long jiffies_expire = jiffies + HZ; 416 unsigned long jiffies_expire = jiffies + HZ;
555 417
@@ -672,7 +534,139 @@ exit:
672 */ 534 */
673int usb_get_current_frame_number(struct usb_device *dev) 535int usb_get_current_frame_number(struct usb_device *dev)
674{ 536{
675 return dev->bus->op->get_frame_number (dev); 537 return usb_hcd_get_frame_number (dev);
538}
539
540/**
541 * usb_endpoint_dir_in - check if the endpoint has IN direction
542 * @epd: endpoint to be checked
543 *
544 * Returns true if the endpoint is of type IN, otherwise it returns false.
545 */
546int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
547{
548 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
549}
550
551/**
552 * usb_endpoint_dir_out - check if the endpoint has OUT direction
553 * @epd: endpoint to be checked
554 *
555 * Returns true if the endpoint is of type OUT, otherwise it returns false.
556 */
557int usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd)
558{
559 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
560}
561
562/**
563 * usb_endpoint_xfer_bulk - check if the endpoint has bulk transfer type
564 * @epd: endpoint to be checked
565 *
566 * Returns true if the endpoint is of type bulk, otherwise it returns false.
567 */
568int usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd)
569{
570 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
571 USB_ENDPOINT_XFER_BULK);
572}
573
574/**
575 * usb_endpoint_xfer_int - check if the endpoint has interrupt transfer type
576 * @epd: endpoint to be checked
577 *
578 * Returns true if the endpoint is of type interrupt, otherwise it returns
579 * false.
580 */
581int usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd)
582{
583 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
584 USB_ENDPOINT_XFER_INT);
585}
586
587/**
588 * usb_endpoint_xfer_isoc - check if the endpoint has isochronous transfer type
589 * @epd: endpoint to be checked
590 *
591 * Returns true if the endpoint is of type isochronous, otherwise it returns
592 * false.
593 */
594int usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd)
595{
596 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
597 USB_ENDPOINT_XFER_ISOC);
598}
599
600/**
601 * usb_endpoint_is_bulk_in - check if the endpoint is bulk IN
602 * @epd: endpoint to be checked
603 *
604 * Returns true if the endpoint has bulk transfer type and IN direction,
605 * otherwise it returns false.
606 */
607int usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd)
608{
609 return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd));
610}
611
612/**
613 * usb_endpoint_is_bulk_out - check if the endpoint is bulk OUT
614 * @epd: endpoint to be checked
615 *
616 * Returns true if the endpoint has bulk transfer type and OUT direction,
617 * otherwise it returns false.
618 */
619int usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd)
620{
621 return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd));
622}
623
624/**
625 * usb_endpoint_is_int_in - check if the endpoint is interrupt IN
626 * @epd: endpoint to be checked
627 *
628 * Returns true if the endpoint has interrupt transfer type and IN direction,
629 * otherwise it returns false.
630 */
631int usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd)
632{
633 return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd));
634}
635
636/**
637 * usb_endpoint_is_int_out - check if the endpoint is interrupt OUT
638 * @epd: endpoint to be checked
639 *
640 * Returns true if the endpoint has interrupt transfer type and OUT direction,
641 * otherwise it returns false.
642 */
643int usb_endpoint_is_int_out(const struct usb_endpoint_descriptor *epd)
644{
645 return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd));
646}
647
648/**
649 * usb_endpoint_is_isoc_in - check if the endpoint is isochronous IN
650 * @epd: endpoint to be checked
651 *
652 * Returns true if the endpoint has isochronous transfer type and IN direction,
653 * otherwise it returns false.
654 */
655int usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor *epd)
656{
657 return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd));
658}
659
660/**
661 * usb_endpoint_is_isoc_out - check if the endpoint is isochronous OUT
662 * @epd: endpoint to be checked
663 *
664 * Returns true if the endpoint has isochronous transfer type and OUT direction,
665 * otherwise it returns false.
666 */
667int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor *epd)
668{
669 return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd));
676} 670}
677 671
678/*-------------------------------------------------------------------*/ 672/*-------------------------------------------------------------------*/
@@ -737,9 +731,9 @@ void *usb_buffer_alloc (
737 dma_addr_t *dma 731 dma_addr_t *dma
738) 732)
739{ 733{
740 if (!dev || !dev->bus || !dev->bus->op || !dev->bus->op->buffer_alloc) 734 if (!dev || !dev->bus)
741 return NULL; 735 return NULL;
742 return dev->bus->op->buffer_alloc (dev->bus, size, mem_flags, dma); 736 return hcd_buffer_alloc (dev->bus, size, mem_flags, dma);
743} 737}
744 738
745/** 739/**
@@ -760,9 +754,11 @@ void usb_buffer_free (
760 dma_addr_t dma 754 dma_addr_t dma
761) 755)
762{ 756{
763 if (!dev || !dev->bus || !dev->bus->op || !dev->bus->op->buffer_free) 757 if (!dev || !dev->bus)
764 return; 758 return;
765 dev->bus->op->buffer_free (dev->bus, size, addr, dma); 759 if (!addr)
760 return;
761 hcd_buffer_free (dev->bus, size, addr, dma);
766} 762}
767 763
768/** 764/**
@@ -911,8 +907,8 @@ void usb_buffer_unmap (struct urb *urb)
911 * 907 *
912 * Reverse the effect of this call with usb_buffer_unmap_sg(). 908 * Reverse the effect of this call with usb_buffer_unmap_sg().
913 */ 909 */
914int usb_buffer_map_sg (struct usb_device *dev, unsigned pipe, 910int usb_buffer_map_sg(const struct usb_device *dev, unsigned pipe,
915 struct scatterlist *sg, int nents) 911 struct scatterlist *sg, int nents)
916{ 912{
917 struct usb_bus *bus; 913 struct usb_bus *bus;
918 struct device *controller; 914 struct device *controller;
@@ -946,8 +942,8 @@ int usb_buffer_map_sg (struct usb_device *dev, unsigned pipe,
946 * Use this when you are re-using a scatterlist's data buffers for 942 * Use this when you are re-using a scatterlist's data buffers for
947 * another USB request. 943 * another USB request.
948 */ 944 */
949void usb_buffer_dmasync_sg (struct usb_device *dev, unsigned pipe, 945void usb_buffer_dmasync_sg(const struct usb_device *dev, unsigned pipe,
950 struct scatterlist *sg, int n_hw_ents) 946 struct scatterlist *sg, int n_hw_ents)
951{ 947{
952 struct usb_bus *bus; 948 struct usb_bus *bus;
953 struct device *controller; 949 struct device *controller;
@@ -972,8 +968,8 @@ void usb_buffer_dmasync_sg (struct usb_device *dev, unsigned pipe,
972 * 968 *
973 * Reverses the effect of usb_buffer_map_sg(). 969 * Reverses the effect of usb_buffer_map_sg().
974 */ 970 */
975void usb_buffer_unmap_sg (struct usb_device *dev, unsigned pipe, 971void usb_buffer_unmap_sg(const struct usb_device *dev, unsigned pipe,
976 struct scatterlist *sg, int n_hw_ents) 972 struct scatterlist *sg, int n_hw_ents)
977{ 973{
978 struct usb_bus *bus; 974 struct usb_bus *bus;
979 struct device *controller; 975 struct device *controller;
@@ -988,116 +984,6 @@ void usb_buffer_unmap_sg (struct usb_device *dev, unsigned pipe,
988 usb_pipein (pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE); 984 usb_pipein (pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
989} 985}
990 986
991static int verify_suspended(struct device *dev, void *unused)
992{
993 if (dev->driver == NULL)
994 return 0;
995 return (dev->power.power_state.event == PM_EVENT_ON) ? -EBUSY : 0;
996}
997
998static int usb_generic_suspend(struct device *dev, pm_message_t message)
999{
1000 struct usb_interface *intf;
1001 struct usb_driver *driver;
1002 int status;
1003
1004 /* USB devices enter SUSPEND state through their hubs, but can be
1005 * marked for FREEZE as soon as their children are already idled.
1006 * But those semantics are useless, so we equate the two (sigh).
1007 */
1008 if (dev->driver == &usb_generic_driver) {
1009 if (dev->power.power_state.event == message.event)
1010 return 0;
1011 /* we need to rule out bogus requests through sysfs */
1012 status = device_for_each_child(dev, NULL, verify_suspended);
1013 if (status)
1014 return status;
1015 return usb_suspend_device (to_usb_device(dev));
1016 }
1017
1018 if ((dev->driver == NULL) ||
1019 (dev->driver_data == &usb_generic_driver_data))
1020 return 0;
1021
1022 intf = to_usb_interface(dev);
1023 driver = to_usb_driver(dev->driver);
1024
1025 /* with no hardware, USB interfaces only use FREEZE and ON states */
1026 if (!is_active(intf))
1027 return 0;
1028
1029 if (driver->suspend && driver->resume) {
1030 status = driver->suspend(intf, message);
1031 if (status)
1032 dev_err(dev, "%s error %d\n", "suspend", status);
1033 else
1034 mark_quiesced(intf);
1035 } else {
1036 // FIXME else if there's no suspend method, disconnect...
1037 dev_warn(dev, "no suspend for driver %s?\n", driver->name);
1038 mark_quiesced(intf);
1039 status = 0;
1040 }
1041 return status;
1042}
1043
1044static int usb_generic_resume(struct device *dev)
1045{
1046 struct usb_interface *intf;
1047 struct usb_driver *driver;
1048 struct usb_device *udev;
1049 int status;
1050
1051 if (dev->power.power_state.event == PM_EVENT_ON)
1052 return 0;
1053
1054 /* mark things as "on" immediately, no matter what errors crop up */
1055 dev->power.power_state.event = PM_EVENT_ON;
1056
1057 /* devices resume through their hubs */
1058 if (dev->driver == &usb_generic_driver) {
1059 udev = to_usb_device(dev);
1060 if (udev->state == USB_STATE_NOTATTACHED)
1061 return 0;
1062 return usb_resume_device (to_usb_device(dev));
1063 }
1064
1065 if ((dev->driver == NULL) ||
1066 (dev->driver_data == &usb_generic_driver_data)) {
1067 dev->power.power_state.event = PM_EVENT_FREEZE;
1068 return 0;
1069 }
1070
1071 intf = to_usb_interface(dev);
1072 driver = to_usb_driver(dev->driver);
1073
1074 udev = interface_to_usbdev(intf);
1075 if (udev->state == USB_STATE_NOTATTACHED)
1076 return 0;
1077
1078 /* if driver was suspended, it has a resume method;
1079 * however, sysfs can wrongly mark things as suspended
1080 * (on the "no suspend method" FIXME path above)
1081 */
1082 if (driver->resume) {
1083 status = driver->resume(intf);
1084 if (status) {
1085 dev_err(dev, "%s error %d\n", "resume", status);
1086 mark_quiesced(intf);
1087 }
1088 } else
1089 dev_warn(dev, "no resume for driver %s?\n", driver->name);
1090 return 0;
1091}
1092
1093struct bus_type usb_bus_type = {
1094 .name = "usb",
1095 .match = usb_device_match,
1096 .uevent = usb_uevent,
1097 .suspend = usb_generic_suspend,
1098 .resume = usb_generic_resume,
1099};
1100
1101/* format to disable USB on kernel command line is: nousb */ 987/* format to disable USB on kernel command line is: nousb */
1102__module_param_call("", nousb, param_set_bool, param_get_bool, &nousb, 0444); 988__module_param_call("", nousb, param_set_bool, param_get_bool, &nousb, 0444);
1103 989
@@ -1120,9 +1006,12 @@ static int __init usb_init(void)
1120 return 0; 1006 return 0;
1121 } 1007 }
1122 1008
1009 retval = ksuspend_usb_init();
1010 if (retval)
1011 goto out;
1123 retval = bus_register(&usb_bus_type); 1012 retval = bus_register(&usb_bus_type);
1124 if (retval) 1013 if (retval)
1125 goto out; 1014 goto bus_register_failed;
1126 retval = usb_host_init(); 1015 retval = usb_host_init();
1127 if (retval) 1016 if (retval)
1128 goto host_init_failed; 1017 goto host_init_failed;
@@ -1141,7 +1030,7 @@ static int __init usb_init(void)
1141 retval = usb_hub_init(); 1030 retval = usb_hub_init();
1142 if (retval) 1031 if (retval)
1143 goto hub_init_failed; 1032 goto hub_init_failed;
1144 retval = driver_register(&usb_generic_driver); 1033 retval = usb_register_device_driver(&usb_generic_driver, THIS_MODULE);
1145 if (!retval) 1034 if (!retval)
1146 goto out; 1035 goto out;
1147 1036
@@ -1158,6 +1047,8 @@ major_init_failed:
1158 usb_host_cleanup(); 1047 usb_host_cleanup();
1159host_init_failed: 1048host_init_failed:
1160 bus_unregister(&usb_bus_type); 1049 bus_unregister(&usb_bus_type);
1050bus_register_failed:
1051 ksuspend_usb_cleanup();
1161out: 1052out:
1162 return retval; 1053 return retval;
1163} 1054}
@@ -1171,7 +1062,7 @@ static void __exit usb_exit(void)
1171 if (nousb) 1062 if (nousb)
1172 return; 1063 return;
1173 1064
1174 driver_unregister(&usb_generic_driver); 1065 usb_deregister_device_driver(&usb_generic_driver);
1175 usb_major_cleanup(); 1066 usb_major_cleanup();
1176 usbfs_cleanup(); 1067 usbfs_cleanup();
1177 usb_deregister(&usbfs_driver); 1068 usb_deregister(&usbfs_driver);
@@ -1179,6 +1070,7 @@ static void __exit usb_exit(void)
1179 usb_hub_cleanup(); 1070 usb_hub_cleanup();
1180 usb_host_cleanup(); 1071 usb_host_cleanup();
1181 bus_unregister(&usb_bus_type); 1072 bus_unregister(&usb_bus_type);
1073 ksuspend_usb_cleanup();
1182} 1074}
1183 1075
1184subsys_initcall(usb_init); 1076subsys_initcall(usb_init);
@@ -1201,20 +1093,27 @@ EXPORT_SYMBOL(usb_hub_tt_clear_buffer);
1201 1093
1202EXPORT_SYMBOL(usb_lock_device_for_reset); 1094EXPORT_SYMBOL(usb_lock_device_for_reset);
1203 1095
1204EXPORT_SYMBOL(usb_driver_claim_interface);
1205EXPORT_SYMBOL(usb_driver_release_interface);
1206EXPORT_SYMBOL(usb_find_interface); 1096EXPORT_SYMBOL(usb_find_interface);
1207EXPORT_SYMBOL(usb_ifnum_to_if); 1097EXPORT_SYMBOL(usb_ifnum_to_if);
1208EXPORT_SYMBOL(usb_altnum_to_altsetting); 1098EXPORT_SYMBOL(usb_altnum_to_altsetting);
1209 1099
1210EXPORT_SYMBOL(usb_reset_device);
1211EXPORT_SYMBOL(usb_reset_composite_device);
1212
1213EXPORT_SYMBOL(__usb_get_extra_descriptor); 1100EXPORT_SYMBOL(__usb_get_extra_descriptor);
1214 1101
1215EXPORT_SYMBOL(usb_find_device); 1102EXPORT_SYMBOL(usb_find_device);
1216EXPORT_SYMBOL(usb_get_current_frame_number); 1103EXPORT_SYMBOL(usb_get_current_frame_number);
1217 1104
1105EXPORT_SYMBOL_GPL(usb_endpoint_dir_in);
1106EXPORT_SYMBOL_GPL(usb_endpoint_dir_out);
1107EXPORT_SYMBOL_GPL(usb_endpoint_xfer_bulk);
1108EXPORT_SYMBOL_GPL(usb_endpoint_xfer_int);
1109EXPORT_SYMBOL_GPL(usb_endpoint_xfer_isoc);
1110EXPORT_SYMBOL_GPL(usb_endpoint_is_bulk_in);
1111EXPORT_SYMBOL_GPL(usb_endpoint_is_bulk_out);
1112EXPORT_SYMBOL_GPL(usb_endpoint_is_int_in);
1113EXPORT_SYMBOL_GPL(usb_endpoint_is_int_out);
1114EXPORT_SYMBOL_GPL(usb_endpoint_is_isoc_in);
1115EXPORT_SYMBOL_GPL(usb_endpoint_is_isoc_out);
1116
1218EXPORT_SYMBOL (usb_buffer_alloc); 1117EXPORT_SYMBOL (usb_buffer_alloc);
1219EXPORT_SYMBOL (usb_buffer_free); 1118EXPORT_SYMBOL (usb_buffer_free);
1220 1119
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 49f69236b420..13322e33f912 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -1,10 +1,10 @@
1/* Functions local to drivers/usb/core/ */ 1/* Functions local to drivers/usb/core/ */
2 2
3extern void usb_create_sysfs_dev_files (struct usb_device *dev); 3extern int usb_create_sysfs_dev_files (struct usb_device *dev);
4extern void usb_remove_sysfs_dev_files (struct usb_device *dev); 4extern void usb_remove_sysfs_dev_files (struct usb_device *dev);
5extern void usb_create_sysfs_intf_files (struct usb_interface *intf); 5extern int usb_create_sysfs_intf_files (struct usb_interface *intf);
6extern void usb_remove_sysfs_intf_files (struct usb_interface *intf); 6extern void usb_remove_sysfs_intf_files (struct usb_interface *intf);
7extern void usb_create_ep_files(struct device *parent, struct usb_host_endpoint *endpoint, 7extern int usb_create_ep_files(struct device *parent, struct usb_host_endpoint *endpoint,
8 struct usb_device *udev); 8 struct usb_device *udev);
9extern void usb_remove_ep_files(struct usb_host_endpoint *endpoint); 9extern void usb_remove_ep_files(struct usb_host_endpoint *endpoint);
10 10
@@ -20,7 +20,6 @@ extern char *usb_cache_string(struct usb_device *udev, int index);
20extern int usb_set_configuration(struct usb_device *dev, int configuration); 20extern int usb_set_configuration(struct usb_device *dev, int configuration);
21 21
22extern void usb_kick_khubd(struct usb_device *dev); 22extern void usb_kick_khubd(struct usb_device *dev);
23extern void usb_suspend_root_hub(struct usb_device *hdev);
24extern void usb_resume_root_hub(struct usb_device *dev); 23extern void usb_resume_root_hub(struct usb_device *dev);
25 24
26extern int usb_hub_init(void); 25extern int usb_hub_init(void);
@@ -30,28 +29,91 @@ extern void usb_major_cleanup(void);
30extern int usb_host_init(void); 29extern int usb_host_init(void);
31extern void usb_host_cleanup(void); 30extern void usb_host_cleanup(void);
32 31
33extern int usb_suspend_device(struct usb_device *dev); 32#ifdef CONFIG_PM
34extern int usb_resume_device(struct usb_device *dev);
35 33
36extern struct device_driver usb_generic_driver; 34extern int usb_suspend_both(struct usb_device *udev, pm_message_t msg);
37extern int usb_generic_driver_data; 35extern int usb_resume_both(struct usb_device *udev);
38extern int usb_device_match(struct device *dev, struct device_driver *drv); 36extern int usb_port_suspend(struct usb_device *dev);
37extern int usb_port_resume(struct usb_device *dev);
38
39static inline void usb_pm_lock(struct usb_device *udev)
40{
41 mutex_lock_nested(&udev->pm_mutex, udev->level);
42}
43
44static inline void usb_pm_unlock(struct usb_device *udev)
45{
46 mutex_unlock(&udev->pm_mutex);
47}
48
49#else
50
51#define usb_suspend_both(udev, msg) 0
52static inline int usb_resume_both(struct usb_device *udev)
53{
54 return 0;
55}
56#define usb_port_suspend(dev) 0
57#define usb_port_resume(dev) 0
58static inline void usb_pm_lock(struct usb_device *udev) {}
59static inline void usb_pm_unlock(struct usb_device *udev) {}
60
61#endif
62
63#ifdef CONFIG_USB_SUSPEND
64
65#define USB_AUTOSUSPEND_DELAY (HZ*2)
66
67extern void usb_autosuspend_device(struct usb_device *udev, int dec_busy_cnt);
68extern int usb_autoresume_device(struct usb_device *udev, int inc_busy_cnt);
69
70#else
71
72#define usb_autosuspend_device(udev, dec_busy_cnt) do {} while (0)
73static inline int usb_autoresume_device(struct usb_device *udev,
74 int inc_busy_cnt)
75{
76 return 0;
77}
78
79#endif
80
81extern struct workqueue_struct *ksuspend_usb_wq;
82extern struct bus_type usb_bus_type;
83extern struct usb_device_driver usb_generic_driver;
84
85/* Here's how we tell apart devices and interfaces. Luckily there's
86 * no such thing as a platform USB device, so we can steal the use
87 * of the platform_data field. */
88
89static inline int is_usb_device(const struct device *dev)
90{
91 return dev->platform_data == &usb_generic_driver;
92}
93
94/* Do the same for device drivers and interface drivers. */
95
96static inline int is_usb_device_driver(struct device_driver *drv)
97{
98 return container_of(drv, struct usbdrv_wrap, driver)->
99 for_devices;
100}
39 101
40/* Interfaces and their "power state" are owned by usbcore */ 102/* Interfaces and their "power state" are owned by usbcore */
41 103
42static inline void mark_active(struct usb_interface *f) 104static inline void mark_active(struct usb_interface *f)
43{ 105{
44 f->dev.power.power_state.event = PM_EVENT_ON; 106 f->is_active = 1;
45} 107}
46 108
47static inline void mark_quiesced(struct usb_interface *f) 109static inline void mark_quiesced(struct usb_interface *f)
48{ 110{
49 f->dev.power.power_state.event = PM_EVENT_FREEZE; 111 f->is_active = 0;
50} 112}
51 113
52static inline int is_active(struct usb_interface *f) 114static inline int is_active(const struct usb_interface *f)
53{ 115{
54 return f->dev.power.power_state.event == PM_EVENT_ON; 116 return f->is_active;
55} 117}
56 118
57 119
@@ -59,9 +121,10 @@ static inline int is_active(struct usb_interface *f)
59extern const char *usbcore_name; 121extern const char *usbcore_name;
60 122
61/* usbfs stuff */ 123/* usbfs stuff */
124extern struct mutex usbfs_mutex;
62extern struct usb_driver usbfs_driver; 125extern struct usb_driver usbfs_driver;
63extern struct file_operations usbfs_devices_fops; 126extern const struct file_operations usbfs_devices_fops;
64extern struct file_operations usbfs_device_file_operations; 127extern const struct file_operations usbfs_device_file_operations;
65extern void usbfs_conn_disc_event(void); 128extern void usbfs_conn_disc_event(void);
66 129
67extern int usbdev_init(void); 130extern int usbdev_init(void);
@@ -76,7 +139,7 @@ struct dev_state {
76 struct list_head async_completed; 139 struct list_head async_completed;
77 wait_queue_head_t wait; /* wake up if a request completed */ 140 wait_queue_head_t wait; /* wake up if a request completed */
78 unsigned int discsignr; 141 unsigned int discsignr;
79 pid_t disc_pid; 142 struct pid *disc_pid;
80 uid_t disc_uid, disc_euid; 143 uid_t disc_uid, disc_euid;
81 void __user *disccontext; 144 void __user *disccontext;
82 unsigned long ifclaimed; 145 unsigned long ifclaimed;
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 1a32d96774b4..8e5dd6f29d0b 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -26,7 +26,7 @@ config USB_GADGET
26 you need a low level bus controller driver, and some software 26 you need a low level bus controller driver, and some software
27 talking to it. Peripheral controllers are often discrete silicon, 27 talking to it. Peripheral controllers are often discrete silicon,
28 or are integrated with the CPU in a microcontroller. The more 28 or are integrated with the CPU in a microcontroller. The more
29 familiar host side controllers have names like like "EHCI", "OHCI", 29 familiar host side controllers have names like "EHCI", "OHCI",
30 or "UHCI", and are usually integrated into southbridges on PC 30 or "UHCI", and are usually integrated into southbridges on PC
31 motherboards. 31 motherboards.
32 32
@@ -404,6 +404,20 @@ config USB_G_SERIAL
404 which includes instructions and a "driver info file" needed to 404 which includes instructions and a "driver info file" needed to
405 make MS-Windows work with this driver. 405 make MS-Windows work with this driver.
406 406
407config USB_MIDI_GADGET
408 tristate "MIDI Gadget (EXPERIMENTAL)"
409 depends on SND && EXPERIMENTAL
410 select SND_RAWMIDI
411 help
412 The MIDI Gadget acts as a USB Audio device, with one MIDI
413 input and one MIDI output. These MIDI jacks appear as
414 a sound "card" in the ALSA sound system. Other MIDI
415 connections can then be made on the gadget system, using
416 ALSA's aconnect utility etc.
417
418 Say "y" to link the driver statically, or "m" to build a
419 dynamically linked module called "g_midi".
420
407 421
408# put drivers that need isochronous transfer support (for audio 422# put drivers that need isochronous transfer support (for audio
409# or video class gadget drivers), or specific hardware, here. 423# or video class gadget drivers), or specific hardware, here.
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 5a28e61392ec..e71e086a1cfa 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_USB_AT91) += at91_udc.o
15g_zero-objs := zero.o usbstring.o config.o epautoconf.o 15g_zero-objs := zero.o usbstring.o config.o epautoconf.o
16g_ether-objs := ether.o usbstring.o config.o epautoconf.o 16g_ether-objs := ether.o usbstring.o config.o epautoconf.o
17g_serial-objs := serial.o usbstring.o config.o epautoconf.o 17g_serial-objs := serial.o usbstring.o config.o epautoconf.o
18g_midi-objs := gmidi.o usbstring.o config.o epautoconf.o
18gadgetfs-objs := inode.o 19gadgetfs-objs := inode.o
19g_file_storage-objs := file_storage.o usbstring.o config.o \ 20g_file_storage-objs := file_storage.o usbstring.o config.o \
20 epautoconf.o 21 epautoconf.o
@@ -28,4 +29,5 @@ obj-$(CONFIG_USB_ETH) += g_ether.o
28obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o 29obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o
29obj-$(CONFIG_USB_FILE_STORAGE) += g_file_storage.o 30obj-$(CONFIG_USB_FILE_STORAGE) += g_file_storage.o
30obj-$(CONFIG_USB_G_SERIAL) += g_serial.o 31obj-$(CONFIG_USB_G_SERIAL) += g_serial.o
32obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o
31 33
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index cfebca05ead5..77beba485a84 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -247,7 +247,7 @@ static int proc_udc_open(struct inode *inode, struct file *file)
247 return single_open(file, proc_udc_show, PDE(inode)->data); 247 return single_open(file, proc_udc_show, PDE(inode)->data);
248} 248}
249 249
250static struct file_operations proc_ops = { 250static const struct file_operations proc_ops = {
251 .open = proc_udc_open, 251 .open = proc_udc_open,
252 .read = seq_read, 252 .read = seq_read,
253 .llseek = seq_lseek, 253 .llseek = seq_lseek,
@@ -1658,7 +1658,7 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1658 return -ENODEV; 1658 return -ENODEV;
1659 } 1659 }
1660 1660
1661 if (!request_mem_region(AT91_BASE_UDP, SZ_16K, driver_name)) { 1661 if (!request_mem_region(AT91RM9200_BASE_UDP, SZ_16K, driver_name)) {
1662 DBG("someone's using UDC memory\n"); 1662 DBG("someone's using UDC memory\n");
1663 return -EBUSY; 1663 return -EBUSY;
1664 } 1664 }
@@ -1720,7 +1720,7 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1720fail1: 1720fail1:
1721 device_unregister(&udc->gadget.dev); 1721 device_unregister(&udc->gadget.dev);
1722fail0: 1722fail0:
1723 release_mem_region(AT91_BASE_UDP, SZ_16K); 1723 release_mem_region(AT91RM9200_BASE_UDP, SZ_16K);
1724 DBG("%s probe failed, %d\n", driver_name, retval); 1724 DBG("%s probe failed, %d\n", driver_name, retval);
1725 return retval; 1725 return retval;
1726} 1726}
@@ -1742,7 +1742,7 @@ static int __devexit at91udc_remove(struct platform_device *pdev)
1742 free_irq(udc->board.vbus_pin, udc); 1742 free_irq(udc->board.vbus_pin, udc);
1743 free_irq(udc->udp_irq, udc); 1743 free_irq(udc->udp_irq, udc);
1744 device_unregister(&udc->gadget.dev); 1744 device_unregister(&udc->gadget.dev);
1745 release_mem_region(AT91_BASE_UDP, SZ_16K); 1745 release_mem_region(AT91RM9200_BASE_UDP, SZ_16K);
1746 1746
1747 clk_put(udc->iclk); 1747 clk_put(udc->iclk);
1748 clk_put(udc->fclk); 1748 clk_put(udc->fclk);
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 7d1c22c34957..4d2946e540cf 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -816,15 +816,14 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
816 dum->gadget.dev.driver = &driver->driver; 816 dum->gadget.dev.driver = &driver->driver;
817 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n", 817 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n",
818 driver->driver.name); 818 driver->driver.name);
819 if ((retval = driver->bind (&dum->gadget)) != 0) { 819 if ((retval = driver->bind (&dum->gadget)) != 0)
820 dum->driver = NULL; 820 goto err_bind_gadget;
821 dum->gadget.dev.driver = NULL;
822 return retval;
823 }
824 821
825 driver->driver.bus = dum->gadget.dev.parent->bus; 822 driver->driver.bus = dum->gadget.dev.parent->bus;
826 driver_register (&driver->driver); 823 if ((retval = driver_register (&driver->driver)) != 0)
827 device_bind_driver (&dum->gadget.dev); 824 goto err_register;
825 if ((retval = device_bind_driver (&dum->gadget.dev)) != 0)
826 goto err_bind_driver;
828 827
829 /* khubd will enumerate this in a while */ 828 /* khubd will enumerate this in a while */
830 spin_lock_irq (&dum->lock); 829 spin_lock_irq (&dum->lock);
@@ -834,6 +833,19 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
834 833
835 usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 834 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
836 return 0; 835 return 0;
836
837err_bind_driver:
838 driver_unregister (&driver->driver);
839err_register:
840 driver->unbind (&dum->gadget);
841 spin_lock_irq (&dum->lock);
842 dum->pullup = 0;
843 set_link_state (dum);
844 spin_unlock_irq (&dum->lock);
845err_bind_gadget:
846 dum->driver = NULL;
847 dum->gadget.dev.driver = NULL;
848 return retval;
837} 849}
838EXPORT_SYMBOL (usb_gadget_register_driver); 850EXPORT_SYMBOL (usb_gadget_register_driver);
839 851
@@ -889,11 +901,9 @@ EXPORT_SYMBOL (net2280_set_fifo_mode);
889static void 901static void
890dummy_gadget_release (struct device *dev) 902dummy_gadget_release (struct device *dev)
891{ 903{
892#if 0 /* usb_bus_put isn't EXPORTed! */
893 struct dummy *dum = gadget_dev_to_dummy (dev); 904 struct dummy *dum = gadget_dev_to_dummy (dev);
894 905
895 usb_bus_put (&dummy_to_hcd (dum)->self); 906 usb_put_hcd (dummy_to_hcd (dum));
896#endif
897} 907}
898 908
899static int dummy_udc_probe (struct platform_device *pdev) 909static int dummy_udc_probe (struct platform_device *pdev)
@@ -915,12 +925,12 @@ static int dummy_udc_probe (struct platform_device *pdev)
915 if (rc < 0) 925 if (rc < 0)
916 return rc; 926 return rc;
917 927
918#if 0 /* usb_bus_get isn't EXPORTed! */ 928 usb_get_hcd (dummy_to_hcd (dum));
919 usb_bus_get (&dummy_to_hcd (dum)->self);
920#endif
921 929
922 platform_set_drvdata (pdev, dum); 930 platform_set_drvdata (pdev, dum);
923 device_create_file (&dum->gadget.dev, &dev_attr_function); 931 rc = device_create_file (&dum->gadget.dev, &dev_attr_function);
932 if (rc < 0)
933 device_unregister (&dum->gadget.dev);
924 return rc; 934 return rc;
925} 935}
926 936
@@ -1868,8 +1878,7 @@ static int dummy_start (struct usb_hcd *hcd)
1868#endif 1878#endif
1869 1879
1870 /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */ 1880 /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */
1871 device_create_file (dummy_dev(dum), &dev_attr_urbs); 1881 return device_create_file (dummy_dev(dum), &dev_attr_urbs);
1872 return 0;
1873} 1882}
1874 1883
1875static void dummy_stop (struct usb_hcd *hcd) 1884static void dummy_stop (struct usb_hcd *hcd)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 30299c620d97..1c17d26d03b8 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -262,7 +262,7 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
262#define DEV_CONFIG_CDC 262#define DEV_CONFIG_CDC
263#endif 263#endif
264 264
265#ifdef CONFIG_USB_GADGET_MUSBHDRC 265#ifdef CONFIG_USB_GADGET_MUSB_HDRC
266#define DEV_CONFIG_CDC 266#define DEV_CONFIG_CDC
267#endif 267#endif
268 268
@@ -2014,7 +2014,7 @@ rndis_control_ack_complete (struct usb_ep *ep, struct usb_request *req)
2014static int rndis_control_ack (struct net_device *net) 2014static int rndis_control_ack (struct net_device *net)
2015{ 2015{
2016 struct eth_dev *dev = netdev_priv(net); 2016 struct eth_dev *dev = netdev_priv(net);
2017 u32 length; 2017 int length;
2018 struct usb_request *resp = dev->stat_req; 2018 struct usb_request *resp = dev->stat_req;
2019 2019
2020 /* in case RNDIS calls this after disconnect */ 2020 /* in case RNDIS calls this after disconnect */
@@ -2230,6 +2230,9 @@ eth_bind (struct usb_gadget *gadget)
2230 if (gadget_is_pxa (gadget)) { 2230 if (gadget_is_pxa (gadget)) {
2231 /* pxa doesn't support altsettings */ 2231 /* pxa doesn't support altsettings */
2232 cdc = 0; 2232 cdc = 0;
2233 } else if (gadget_is_musbhdrc(gadget)) {
2234 /* reduce tx dma overhead by avoiding special cases */
2235 zlp = 0;
2233 } else if (gadget_is_sh(gadget)) { 2236 } else if (gadget_is_sh(gadget)) {
2234 /* sh doesn't support multiple interfaces or configs */ 2237 /* sh doesn't support multiple interfaces or configs */
2235 cdc = 0; 2238 cdc = 0;
@@ -2257,7 +2260,7 @@ eth_bind (struct usb_gadget *gadget)
2257 return -ENODEV; 2260 return -ENODEV;
2258 } 2261 }
2259 snprintf (manufacturer, sizeof manufacturer, "%s %s/%s", 2262 snprintf (manufacturer, sizeof manufacturer, "%s %s/%s",
2260 system_utsname.sysname, system_utsname.release, 2263 init_utsname()->sysname, init_utsname()->release,
2261 gadget->name); 2264 gadget->name);
2262 2265
2263 /* If there's an RNDIS configuration, that's what Windows wants to 2266 /* If there's an RNDIS configuration, that's what Windows wants to
@@ -2564,7 +2567,7 @@ static struct usb_gadget_driver eth_driver = {
2564 2567
2565 .function = (char *) driver_desc, 2568 .function = (char *) driver_desc,
2566 .bind = eth_bind, 2569 .bind = eth_bind,
2567 .unbind = __exit_p(eth_unbind), 2570 .unbind = eth_unbind,
2568 2571
2569 .setup = eth_setup, 2572 .setup = eth_setup,
2570 .disconnect = eth_disconnect, 2573 .disconnect = eth_disconnect,
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 8d7f1e84cd7b..8b975d15538d 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -567,6 +567,7 @@ struct lun {
567 unsigned int ro : 1; 567 unsigned int ro : 1;
568 unsigned int prevent_medium_removal : 1; 568 unsigned int prevent_medium_removal : 1;
569 unsigned int registered : 1; 569 unsigned int registered : 1;
570 unsigned int info_valid : 1;
570 571
571 u32 sense_data; 572 u32 sense_data;
572 u32 sense_data_info; 573 u32 sense_data_info;
@@ -1656,6 +1657,7 @@ static int do_read(struct fsg_dev *fsg)
1656 curlun->sense_data = 1657 curlun->sense_data =
1657 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; 1658 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
1658 curlun->sense_data_info = file_offset >> 9; 1659 curlun->sense_data_info = file_offset >> 9;
1660 curlun->info_valid = 1;
1659 bh->inreq->length = 0; 1661 bh->inreq->length = 0;
1660 bh->state = BUF_STATE_FULL; 1662 bh->state = BUF_STATE_FULL;
1661 break; 1663 break;
@@ -1691,6 +1693,7 @@ static int do_read(struct fsg_dev *fsg)
1691 if (nread < amount) { 1693 if (nread < amount) {
1692 curlun->sense_data = SS_UNRECOVERED_READ_ERROR; 1694 curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
1693 curlun->sense_data_info = file_offset >> 9; 1695 curlun->sense_data_info = file_offset >> 9;
1696 curlun->info_valid = 1;
1694 break; 1697 break;
1695 } 1698 }
1696 1699
@@ -1785,6 +1788,7 @@ static int do_write(struct fsg_dev *fsg)
1785 curlun->sense_data = 1788 curlun->sense_data =
1786 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; 1789 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
1787 curlun->sense_data_info = usb_offset >> 9; 1790 curlun->sense_data_info = usb_offset >> 9;
1791 curlun->info_valid = 1;
1788 continue; 1792 continue;
1789 } 1793 }
1790 amount -= (amount & 511); 1794 amount -= (amount & 511);
@@ -1827,6 +1831,7 @@ static int do_write(struct fsg_dev *fsg)
1827 if (bh->outreq->status != 0) { 1831 if (bh->outreq->status != 0) {
1828 curlun->sense_data = SS_COMMUNICATION_FAILURE; 1832 curlun->sense_data = SS_COMMUNICATION_FAILURE;
1829 curlun->sense_data_info = file_offset >> 9; 1833 curlun->sense_data_info = file_offset >> 9;
1834 curlun->info_valid = 1;
1830 break; 1835 break;
1831 } 1836 }
1832 1837
@@ -1868,6 +1873,7 @@ static int do_write(struct fsg_dev *fsg)
1868 if (nwritten < amount) { 1873 if (nwritten < amount) {
1869 curlun->sense_data = SS_WRITE_ERROR; 1874 curlun->sense_data = SS_WRITE_ERROR;
1870 curlun->sense_data_info = file_offset >> 9; 1875 curlun->sense_data_info = file_offset >> 9;
1876 curlun->info_valid = 1;
1871 break; 1877 break;
1872 } 1878 }
1873 1879
@@ -2010,6 +2016,7 @@ static int do_verify(struct fsg_dev *fsg)
2010 curlun->sense_data = 2016 curlun->sense_data =
2011 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; 2017 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
2012 curlun->sense_data_info = file_offset >> 9; 2018 curlun->sense_data_info = file_offset >> 9;
2019 curlun->info_valid = 1;
2013 break; 2020 break;
2014 } 2021 }
2015 2022
@@ -2036,6 +2043,7 @@ static int do_verify(struct fsg_dev *fsg)
2036 if (nread == 0) { 2043 if (nread == 0) {
2037 curlun->sense_data = SS_UNRECOVERED_READ_ERROR; 2044 curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
2038 curlun->sense_data_info = file_offset >> 9; 2045 curlun->sense_data_info = file_offset >> 9;
2046 curlun->info_valid = 1;
2039 break; 2047 break;
2040 } 2048 }
2041 file_offset += nread; 2049 file_offset += nread;
@@ -2079,6 +2087,7 @@ static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2079 struct lun *curlun = fsg->curlun; 2087 struct lun *curlun = fsg->curlun;
2080 u8 *buf = (u8 *) bh->buf; 2088 u8 *buf = (u8 *) bh->buf;
2081 u32 sd, sdinfo; 2089 u32 sd, sdinfo;
2090 int valid;
2082 2091
2083 /* 2092 /*
2084 * From the SCSI-2 spec., section 7.9 (Unit attention condition): 2093 * From the SCSI-2 spec., section 7.9 (Unit attention condition):
@@ -2106,15 +2115,18 @@ static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2106 fsg->bad_lun_okay = 1; 2115 fsg->bad_lun_okay = 1;
2107 sd = SS_LOGICAL_UNIT_NOT_SUPPORTED; 2116 sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
2108 sdinfo = 0; 2117 sdinfo = 0;
2118 valid = 0;
2109 } else { 2119 } else {
2110 sd = curlun->sense_data; 2120 sd = curlun->sense_data;
2111 sdinfo = curlun->sense_data_info; 2121 sdinfo = curlun->sense_data_info;
2122 valid = curlun->info_valid << 7;
2112 curlun->sense_data = SS_NO_SENSE; 2123 curlun->sense_data = SS_NO_SENSE;
2113 curlun->sense_data_info = 0; 2124 curlun->sense_data_info = 0;
2125 curlun->info_valid = 0;
2114 } 2126 }
2115 2127
2116 memset(buf, 0, 18); 2128 memset(buf, 0, 18);
2117 buf[0] = 0x80 | 0x70; // Valid, current error 2129 buf[0] = valid | 0x70; // Valid, current error
2118 buf[2] = SK(sd); 2130 buf[2] = SK(sd);
2119 put_be32(&buf[3], sdinfo); // Sense information 2131 put_be32(&buf[3], sdinfo); // Sense information
2120 buf[7] = 18 - 8; // Additional sense length 2132 buf[7] = 18 - 8; // Additional sense length
@@ -2703,6 +2715,7 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
2703 if (fsg->cmnd[0] != SC_REQUEST_SENSE) { 2715 if (fsg->cmnd[0] != SC_REQUEST_SENSE) {
2704 curlun->sense_data = SS_NO_SENSE; 2716 curlun->sense_data = SS_NO_SENSE;
2705 curlun->sense_data_info = 0; 2717 curlun->sense_data_info = 0;
2718 curlun->info_valid = 0;
2706 } 2719 }
2707 } else { 2720 } else {
2708 fsg->curlun = curlun = NULL; 2721 fsg->curlun = curlun = NULL;
@@ -3332,6 +3345,7 @@ static void handle_exception(struct fsg_dev *fsg)
3332 curlun->sense_data = curlun->unit_attention_data = 3345 curlun->sense_data = curlun->unit_attention_data =
3333 SS_NO_SENSE; 3346 SS_NO_SENSE;
3334 curlun->sense_data_info = 0; 3347 curlun->sense_data_info = 0;
3348 curlun->info_valid = 0;
3335 } 3349 }
3336 fsg->state = FSG_STATE_IDLE; 3350 fsg->state = FSG_STATE_IDLE;
3337 } 3351 }
@@ -3873,21 +3887,26 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3873 for (i = 0; i < fsg->nluns; ++i) { 3887 for (i = 0; i < fsg->nluns; ++i) {
3874 curlun = &fsg->luns[i]; 3888 curlun = &fsg->luns[i];
3875 curlun->ro = mod_data.ro[i]; 3889 curlun->ro = mod_data.ro[i];
3890 curlun->dev.release = lun_release;
3876 curlun->dev.parent = &gadget->dev; 3891 curlun->dev.parent = &gadget->dev;
3877 curlun->dev.driver = &fsg_driver.driver; 3892 curlun->dev.driver = &fsg_driver.driver;
3878 dev_set_drvdata(&curlun->dev, fsg); 3893 dev_set_drvdata(&curlun->dev, fsg);
3879 snprintf(curlun->dev.bus_id, BUS_ID_SIZE, 3894 snprintf(curlun->dev.bus_id, BUS_ID_SIZE,
3880 "%s-lun%d", gadget->dev.bus_id, i); 3895 "%s-lun%d", gadget->dev.bus_id, i);
3881 3896
3882 if ((rc = device_register(&curlun->dev)) != 0) 3897 if ((rc = device_register(&curlun->dev)) != 0) {
3883 INFO(fsg, "failed to register LUN%d: %d\n", i, rc); 3898 INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
3884 else { 3899 goto out;
3885 curlun->registered = 1; 3900 }
3886 curlun->dev.release = lun_release; 3901 if ((rc = device_create_file(&curlun->dev,
3887 device_create_file(&curlun->dev, &dev_attr_ro); 3902 &dev_attr_ro)) != 0 ||
3888 device_create_file(&curlun->dev, &dev_attr_file); 3903 (rc = device_create_file(&curlun->dev,
3889 kref_get(&fsg->ref); 3904 &dev_attr_file)) != 0) {
3905 device_unregister(&curlun->dev);
3906 goto out;
3890 } 3907 }
3908 curlun->registered = 1;
3909 kref_get(&fsg->ref);
3891 3910
3892 if (mod_data.file[i] && *mod_data.file[i]) { 3911 if (mod_data.file[i] && *mod_data.file[i]) {
3893 if ((rc = open_backing_file(curlun, 3912 if ((rc = open_backing_file(curlun,
@@ -3982,7 +4001,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3982 usb_gadget_set_selfpowered(gadget); 4001 usb_gadget_set_selfpowered(gadget);
3983 4002
3984 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", 4003 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
3985 system_utsname.sysname, system_utsname.release, 4004 init_utsname()->sysname, init_utsname()->release,
3986 gadget->name); 4005 gadget->name);
3987 4006
3988 /* On a real device, serial[] would be loaded from permanent 4007 /* On a real device, serial[] would be loaded from permanent
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
new file mode 100644
index 000000000000..83601d4009e3
--- /dev/null
+++ b/drivers/usb/gadget/gmidi.c
@@ -0,0 +1,1337 @@
1/*
2 * gmidi.c -- USB MIDI Gadget Driver
3 *
4 * Copyright (C) 2006 Thumtronics Pty Ltd.
5 * Developed for Thumtronics by Grey Innovation
6 * Ben Williamson <ben.williamson@greyinnovation.com>
7 *
8 * This software is distributed under the terms of the GNU General Public
9 * License ("GPL") version 2, as published by the Free Software Foundation.
10 *
11 * This code is based in part on:
12 *
13 * Gadget Zero driver, Copyright (C) 2003-2004 David Brownell.
14 * USB Audio driver, Copyright (C) 2002 by Takashi Iwai.
15 * USB MIDI driver, Copyright (C) 2002-2005 Clemens Ladisch.
16 *
17 * Refer to the USB Device Class Definition for MIDI Devices:
18 * http://www.usb.org/developers/devclass_docs/midi10.pdf
19 */
20
21#define DEBUG 1
22// #define VERBOSE
23
24#include <linux/config.h>
25#include <linux/module.h>
26#include <linux/kernel.h>
27#include <linux/delay.h>
28#include <linux/errno.h>
29#include <linux/init.h>
30#include <linux/utsname.h>
31#include <linux/device.h>
32#include <linux/moduleparam.h>
33
34#include <sound/driver.h>
35#include <sound/core.h>
36#include <sound/initval.h>
37#include <sound/rawmidi.h>
38
39#include <linux/usb_ch9.h>
40#include <linux/usb_gadget.h>
41#include <linux/usb/audio.h>
42#include <linux/usb/midi.h>
43
44#include "gadget_chips.h"
45
46MODULE_AUTHOR("Ben Williamson");
47MODULE_LICENSE("GPL v2");
48
49#define DRIVER_VERSION "25 Jul 2006"
50
51static const char shortname[] = "g_midi";
52static const char longname[] = "MIDI Gadget";
53
54static int index = SNDRV_DEFAULT_IDX1;
55static char *id = SNDRV_DEFAULT_STR1;
56
57module_param(index, int, 0444);
58MODULE_PARM_DESC(index, "Index value for the USB MIDI Gadget adapter.");
59module_param(id, charp, 0444);
60MODULE_PARM_DESC(id, "ID string for the USB MIDI Gadget adapter.");
61
62/* Some systems will want different product identifers published in the
63 * device descriptor, either numbers or strings or both. These string
64 * parameters are in UTF-8 (superset of ASCII's 7 bit characters).
65 */
66
67static ushort idVendor;
68module_param(idVendor, ushort, S_IRUGO);
69MODULE_PARM_DESC(idVendor, "USB Vendor ID");
70
71static ushort idProduct;
72module_param(idProduct, ushort, S_IRUGO);
73MODULE_PARM_DESC(idProduct, "USB Product ID");
74
75static ushort bcdDevice;
76module_param(bcdDevice, ushort, S_IRUGO);
77MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)");
78
79static char *iManufacturer;
80module_param(iManufacturer, charp, S_IRUGO);
81MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string");
82
83static char *iProduct;
84module_param(iProduct, charp, S_IRUGO);
85MODULE_PARM_DESC(iProduct, "USB Product string");
86
87static char *iSerialNumber;
88module_param(iSerialNumber, charp, S_IRUGO);
89MODULE_PARM_DESC(iSerialNumber, "SerialNumber");
90
91/*
92 * this version autoconfigures as much as possible,
93 * which is reasonable for most "bulk-only" drivers.
94 */
95static const char *EP_IN_NAME;
96static const char *EP_OUT_NAME;
97
98
99/* big enough to hold our biggest descriptor */
100#define USB_BUFSIZ 256
101
102
103/* This is a gadget, and the IN/OUT naming is from the host's perspective.
104 USB -> OUT endpoint -> rawmidi
105 USB <- IN endpoint <- rawmidi */
106struct gmidi_in_port {
107 struct gmidi_device* dev;
108 int active;
109 uint8_t cable; /* cable number << 4 */
110 uint8_t state;
111#define STATE_UNKNOWN 0
112#define STATE_1PARAM 1
113#define STATE_2PARAM_1 2
114#define STATE_2PARAM_2 3
115#define STATE_SYSEX_0 4
116#define STATE_SYSEX_1 5
117#define STATE_SYSEX_2 6
118 uint8_t data[2];
119};
120
121struct gmidi_device {
122 spinlock_t lock;
123 struct usb_gadget *gadget;
124 struct usb_request *req; /* for control responses */
125 u8 config;
126 struct usb_ep *in_ep, *out_ep;
127 struct snd_card *card;
128 struct snd_rawmidi *rmidi;
129 struct snd_rawmidi_substream *in_substream;
130 struct snd_rawmidi_substream *out_substream;
131
132 /* For the moment we only support one port in
133 each direction, but in_port is kept as a
134 separate struct so we can have more later. */
135 struct gmidi_in_port in_port;
136 unsigned long out_triggered;
137 struct tasklet_struct tasklet;
138};
139
140static void gmidi_transmit(struct gmidi_device* dev, struct usb_request* req);
141
142
143#define xprintk(d,level,fmt,args...) \
144 dev_printk(level , &(d)->gadget->dev , fmt , ## args)
145
146#ifdef DEBUG
147#define DBG(dev,fmt,args...) \
148 xprintk(dev , KERN_DEBUG , fmt , ## args)
149#else
150#define DBG(dev,fmt,args...) \
151 do { } while (0)
152#endif /* DEBUG */
153
154#ifdef VERBOSE
155#define VDBG DBG
156#else
157#define VDBG(dev,fmt,args...) \
158 do { } while (0)
159#endif /* VERBOSE */
160
161#define ERROR(dev,fmt,args...) \
162 xprintk(dev , KERN_ERR , fmt , ## args)
163#define WARN(dev,fmt,args...) \
164 xprintk(dev , KERN_WARNING , fmt , ## args)
165#define INFO(dev,fmt,args...) \
166 xprintk(dev , KERN_INFO , fmt , ## args)
167
168
169static unsigned buflen = 256;
170static unsigned qlen = 32;
171
172module_param(buflen, uint, S_IRUGO);
173module_param(qlen, uint, S_IRUGO);
174
175
176/* Thanks to Grey Innovation for donating this product ID.
177 *
178 * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
179 * Instead: allocate your own, using normal USB-IF procedures.
180 */
181#define DRIVER_VENDOR_NUM 0x17b3 /* Grey Innovation */
182#define DRIVER_PRODUCT_NUM 0x0004 /* Linux-USB "MIDI Gadget" */
183
184
185/*
186 * DESCRIPTORS ... most are static, but strings and (full)
187 * configuration descriptors are built on demand.
188 */
189
190#define STRING_MANUFACTURER 25
191#define STRING_PRODUCT 42
192#define STRING_SERIAL 101
193#define STRING_MIDI_GADGET 250
194
195/* We only have the one configuration, it's number 1. */
196#define GMIDI_CONFIG 1
197
198/* We have two interfaces- AudioControl and MIDIStreaming */
199#define GMIDI_AC_INTERFACE 0
200#define GMIDI_MS_INTERFACE 1
201#define GMIDI_NUM_INTERFACES 2
202
203DECLARE_USB_AC_HEADER_DESCRIPTOR(1);
204DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1);
205DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(1);
206
207/* B.1 Device Descriptor */
208static struct usb_device_descriptor device_desc = {
209 .bLength = USB_DT_DEVICE_SIZE,
210 .bDescriptorType = USB_DT_DEVICE,
211 .bcdUSB = __constant_cpu_to_le16(0x0200),
212 .bDeviceClass = USB_CLASS_PER_INTERFACE,
213 .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_NUM),
214 .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_NUM),
215 .iManufacturer = STRING_MANUFACTURER,
216 .iProduct = STRING_PRODUCT,
217 .bNumConfigurations = 1,
218};
219
220/* B.2 Configuration Descriptor */
221static struct usb_config_descriptor config_desc = {
222 .bLength = USB_DT_CONFIG_SIZE,
223 .bDescriptorType = USB_DT_CONFIG,
224 /* compute wTotalLength on the fly */
225 .bNumInterfaces = GMIDI_NUM_INTERFACES,
226 .bConfigurationValue = GMIDI_CONFIG,
227 .iConfiguration = STRING_MIDI_GADGET,
228 /*
229 * FIXME: When embedding this driver in a device,
230 * these need to be set to reflect the actual
231 * power properties of the device. Is it selfpowered?
232 */
233 .bmAttributes = USB_CONFIG_ATT_ONE,
234 .bMaxPower = 1,
235};
236
237/* B.3.1 Standard AC Interface Descriptor */
238static const struct usb_interface_descriptor ac_interface_desc = {
239 .bLength = USB_DT_INTERFACE_SIZE,
240 .bDescriptorType = USB_DT_INTERFACE,
241 .bInterfaceNumber = GMIDI_AC_INTERFACE,
242 .bNumEndpoints = 0,
243 .bInterfaceClass = USB_CLASS_AUDIO,
244 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
245 .iInterface = STRING_MIDI_GADGET,
246};
247
248/* B.3.2 Class-Specific AC Interface Descriptor */
249static const struct usb_ac_header_descriptor_1 ac_header_desc = {
250 .bLength = USB_DT_AC_HEADER_SIZE(1),
251 .bDescriptorType = USB_DT_CS_INTERFACE,
252 .bDescriptorSubtype = USB_MS_HEADER,
253 .bcdADC = __constant_cpu_to_le16(0x0100),
254 .wTotalLength = USB_DT_AC_HEADER_SIZE(1),
255 .bInCollection = 1,
256 .baInterfaceNr = {
257 [0] = GMIDI_MS_INTERFACE,
258 }
259};
260
261/* B.4.1 Standard MS Interface Descriptor */
262static const struct usb_interface_descriptor ms_interface_desc = {
263 .bLength = USB_DT_INTERFACE_SIZE,
264 .bDescriptorType = USB_DT_INTERFACE,
265 .bInterfaceNumber = GMIDI_MS_INTERFACE,
266 .bNumEndpoints = 2,
267 .bInterfaceClass = USB_CLASS_AUDIO,
268 .bInterfaceSubClass = USB_SUBCLASS_MIDISTREAMING,
269 .iInterface = STRING_MIDI_GADGET,
270};
271
272/* B.4.2 Class-Specific MS Interface Descriptor */
273static const struct usb_ms_header_descriptor ms_header_desc = {
274 .bLength = USB_DT_MS_HEADER_SIZE,
275 .bDescriptorType = USB_DT_CS_INTERFACE,
276 .bDescriptorSubtype = USB_MS_HEADER,
277 .bcdMSC = __constant_cpu_to_le16(0x0100),
278 .wTotalLength = USB_DT_MS_HEADER_SIZE
279 + 2*USB_DT_MIDI_IN_SIZE
280 + 2*USB_DT_MIDI_OUT_SIZE(1),
281};
282
283#define JACK_IN_EMB 1
284#define JACK_IN_EXT 2
285#define JACK_OUT_EMB 3
286#define JACK_OUT_EXT 4
287
288/* B.4.3 MIDI IN Jack Descriptors */
289static const struct usb_midi_in_jack_descriptor jack_in_emb_desc = {
290 .bLength = USB_DT_MIDI_IN_SIZE,
291 .bDescriptorType = USB_DT_CS_INTERFACE,
292 .bDescriptorSubtype = USB_MS_MIDI_IN_JACK,
293 .bJackType = USB_MS_EMBEDDED,
294 .bJackID = JACK_IN_EMB,
295};
296
297static const struct usb_midi_in_jack_descriptor jack_in_ext_desc = {
298 .bLength = USB_DT_MIDI_IN_SIZE,
299 .bDescriptorType = USB_DT_CS_INTERFACE,
300 .bDescriptorSubtype = USB_MS_MIDI_IN_JACK,
301 .bJackType = USB_MS_EXTERNAL,
302 .bJackID = JACK_IN_EXT,
303};
304
305/* B.4.4 MIDI OUT Jack Descriptors */
306static const struct usb_midi_out_jack_descriptor_1 jack_out_emb_desc = {
307 .bLength = USB_DT_MIDI_OUT_SIZE(1),
308 .bDescriptorType = USB_DT_CS_INTERFACE,
309 .bDescriptorSubtype = USB_MS_MIDI_OUT_JACK,
310 .bJackType = USB_MS_EMBEDDED,
311 .bJackID = JACK_OUT_EMB,
312 .bNrInputPins = 1,
313 .pins = {
314 [0] = {
315 .baSourceID = JACK_IN_EXT,
316 .baSourcePin = 1,
317 }
318 }
319};
320
321static const struct usb_midi_out_jack_descriptor_1 jack_out_ext_desc = {
322 .bLength = USB_DT_MIDI_OUT_SIZE(1),
323 .bDescriptorType = USB_DT_CS_INTERFACE,
324 .bDescriptorSubtype = USB_MS_MIDI_OUT_JACK,
325 .bJackType = USB_MS_EXTERNAL,
326 .bJackID = JACK_OUT_EXT,
327 .bNrInputPins = 1,
328 .pins = {
329 [0] = {
330 .baSourceID = JACK_IN_EMB,
331 .baSourcePin = 1,
332 }
333 }
334};
335
336/* B.5.1 Standard Bulk OUT Endpoint Descriptor */
337static struct usb_endpoint_descriptor bulk_out_desc = {
338 .bLength = USB_DT_ENDPOINT_AUDIO_SIZE,
339 .bDescriptorType = USB_DT_ENDPOINT,
340 .bEndpointAddress = USB_DIR_OUT,
341 .bmAttributes = USB_ENDPOINT_XFER_BULK,
342};
343
344/* B.5.2 Class-specific MS Bulk OUT Endpoint Descriptor */
345static const struct usb_ms_endpoint_descriptor_1 ms_out_desc = {
346 .bLength = USB_DT_MS_ENDPOINT_SIZE(1),
347 .bDescriptorType = USB_DT_CS_ENDPOINT,
348 .bDescriptorSubtype = USB_MS_GENERAL,
349 .bNumEmbMIDIJack = 1,
350 .baAssocJackID = {
351 [0] = JACK_IN_EMB,
352 }
353};
354
355/* B.6.1 Standard Bulk IN Endpoint Descriptor */
356static struct usb_endpoint_descriptor bulk_in_desc = {
357 .bLength = USB_DT_ENDPOINT_AUDIO_SIZE,
358 .bDescriptorType = USB_DT_ENDPOINT,
359 .bEndpointAddress = USB_DIR_IN,
360 .bmAttributes = USB_ENDPOINT_XFER_BULK,
361};
362
363/* B.6.2 Class-specific MS Bulk IN Endpoint Descriptor */
364static const struct usb_ms_endpoint_descriptor_1 ms_in_desc = {
365 .bLength = USB_DT_MS_ENDPOINT_SIZE(1),
366 .bDescriptorType = USB_DT_CS_ENDPOINT,
367 .bDescriptorSubtype = USB_MS_GENERAL,
368 .bNumEmbMIDIJack = 1,
369 .baAssocJackID = {
370 [0] = JACK_OUT_EMB,
371 }
372};
373
374static const struct usb_descriptor_header *gmidi_function [] = {
375 (struct usb_descriptor_header *)&ac_interface_desc,
376 (struct usb_descriptor_header *)&ac_header_desc,
377 (struct usb_descriptor_header *)&ms_interface_desc,
378
379 (struct usb_descriptor_header *)&ms_header_desc,
380 (struct usb_descriptor_header *)&jack_in_emb_desc,
381 (struct usb_descriptor_header *)&jack_in_ext_desc,
382 (struct usb_descriptor_header *)&jack_out_emb_desc,
383 (struct usb_descriptor_header *)&jack_out_ext_desc,
384 /* If you add more jacks, update ms_header_desc.wTotalLength */
385
386 (struct usb_descriptor_header *)&bulk_out_desc,
387 (struct usb_descriptor_header *)&ms_out_desc,
388 (struct usb_descriptor_header *)&bulk_in_desc,
389 (struct usb_descriptor_header *)&ms_in_desc,
390 NULL,
391};
392
393static char manufacturer[50];
394static char product_desc[40] = "MIDI Gadget";
395static char serial_number[20];
396
397/* static strings, in UTF-8 */
398static struct usb_string strings [] = {
399 { STRING_MANUFACTURER, manufacturer, },
400 { STRING_PRODUCT, product_desc, },
401 { STRING_SERIAL, serial_number, },
402 { STRING_MIDI_GADGET, longname, },
403 { } /* end of list */
404};
405
406static struct usb_gadget_strings stringtab = {
407 .language = 0x0409, /* en-us */
408 .strings = strings,
409};
410
411static int config_buf(struct usb_gadget *gadget,
412 u8 *buf, u8 type, unsigned index)
413{
414 int len;
415
416 /* only one configuration */
417 if (index != 0) {
418 return -EINVAL;
419 }
420 len = usb_gadget_config_buf(&config_desc,
421 buf, USB_BUFSIZ, gmidi_function);
422 if (len < 0) {
423 return len;
424 }
425 ((struct usb_config_descriptor *)buf)->bDescriptorType = type;
426 return len;
427}
428
429static struct usb_request* alloc_ep_req(struct usb_ep *ep, unsigned length)
430{
431 struct usb_request *req;
432
433 req = usb_ep_alloc_request(ep, GFP_ATOMIC);
434 if (req) {
435 req->length = length;
436 req->buf = kmalloc(length, GFP_ATOMIC);
437 if (!req->buf) {
438 usb_ep_free_request(ep, req);
439 req = NULL;
440 }
441 }
442 return req;
443}
444
445static void free_ep_req(struct usb_ep *ep, struct usb_request *req)
446{
447 kfree(req->buf);
448 usb_ep_free_request(ep, req);
449}
450
451static const uint8_t gmidi_cin_length[] = {
452 0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1
453};
454
455/*
456 * Receives a chunk of MIDI data.
457 */
458static void gmidi_read_data(struct usb_ep *ep, int cable,
459 uint8_t* data, int length)
460{
461 struct gmidi_device *dev = ep->driver_data;
462 /* cable is ignored, because for now we only have one. */
463
464 if (!dev->out_substream) {
465 /* Nobody is listening - throw it on the floor. */
466 return;
467 }
468 if (!test_bit(dev->out_substream->number, &dev->out_triggered)) {
469 return;
470 }
471 snd_rawmidi_receive(dev->out_substream, data, length);
472}
473
474static void gmidi_handle_out_data(struct usb_ep *ep, struct usb_request *req)
475{
476 unsigned i;
477 u8 *buf = req->buf;
478
479 for (i = 0; i + 3 < req->actual; i += 4) {
480 if (buf[i] != 0) {
481 int cable = buf[i] >> 4;
482 int length = gmidi_cin_length[buf[i] & 0x0f];
483 gmidi_read_data(ep, cable, &buf[i + 1], length);
484 }
485 }
486}
487
488static void gmidi_complete(struct usb_ep *ep, struct usb_request *req)
489{
490 struct gmidi_device *dev = ep->driver_data;
491 int status = req->status;
492
493 switch (status) {
494 case 0: /* normal completion */
495 if (ep == dev->out_ep) {
496 /* we received stuff.
497 req is queued again, below */
498 gmidi_handle_out_data(ep, req);
499 } else if (ep == dev->in_ep) {
500 /* our transmit completed.
501 see if there's more to go.
502 gmidi_transmit eats req, don't queue it again. */
503 gmidi_transmit(dev, req);
504 return;
505 }
506 break;
507
508 /* this endpoint is normally active while we're configured */
509 case -ECONNABORTED: /* hardware forced ep reset */
510 case -ECONNRESET: /* request dequeued */
511 case -ESHUTDOWN: /* disconnect from host */
512 VDBG(dev, "%s gone (%d), %d/%d\n", ep->name, status,
513 req->actual, req->length);
514 if (ep == dev->out_ep) {
515 gmidi_handle_out_data(ep, req);
516 }
517 free_ep_req(ep, req);
518 return;
519
520 case -EOVERFLOW: /* buffer overrun on read means that
521 * we didn't provide a big enough
522 * buffer.
523 */
524 default:
525 DBG(dev, "%s complete --> %d, %d/%d\n", ep->name,
526 status, req->actual, req->length);
527 break;
528 case -EREMOTEIO: /* short read */
529 break;
530 }
531
532 status = usb_ep_queue(ep, req, GFP_ATOMIC);
533 if (status) {
534 ERROR(dev, "kill %s: resubmit %d bytes --> %d\n",
535 ep->name, req->length, status);
536 usb_ep_set_halt(ep);
537 /* FIXME recover later ... somehow */
538 }
539}
540
541static int set_gmidi_config(struct gmidi_device *dev, gfp_t gfp_flags)
542{
543 int err = 0;
544 struct usb_request *req;
545 struct usb_ep* ep;
546 unsigned i;
547
548 err = usb_ep_enable(dev->in_ep, &bulk_in_desc);
549 if (err) {
550 ERROR(dev, "can't start %s: %d\n", dev->in_ep->name, err);
551 goto fail;
552 }
553 dev->in_ep->driver_data = dev;
554
555 err = usb_ep_enable(dev->out_ep, &bulk_out_desc);
556 if (err) {
557 ERROR(dev, "can't start %s: %d\n", dev->out_ep->name, err);
558 goto fail;
559 }
560 dev->out_ep->driver_data = dev;
561
562 /* allocate a bunch of read buffers and queue them all at once. */
563 ep = dev->out_ep;
564 for (i = 0; i < qlen && err == 0; i++) {
565 req = alloc_ep_req(ep, buflen);
566 if (req) {
567 req->complete = gmidi_complete;
568 err = usb_ep_queue(ep, req, GFP_ATOMIC);
569 if (err) {
570 DBG(dev, "%s queue req: %d\n", ep->name, err);
571 }
572 } else {
573 err = -ENOMEM;
574 }
575 }
576fail:
577 /* caller is responsible for cleanup on error */
578 return err;
579}
580
581
582static void gmidi_reset_config(struct gmidi_device *dev)
583{
584 if (dev->config == 0) {
585 return;
586 }
587
588 DBG(dev, "reset config\n");
589
590 /* just disable endpoints, forcing completion of pending i/o.
591 * all our completion handlers free their requests in this case.
592 */
593 usb_ep_disable(dev->in_ep);
594 usb_ep_disable(dev->out_ep);
595 dev->config = 0;
596}
597
598/* change our operational config. this code must agree with the code
599 * that returns config descriptors, and altsetting code.
600 *
601 * it's also responsible for power management interactions. some
602 * configurations might not work with our current power sources.
603 *
604 * note that some device controller hardware will constrain what this
605 * code can do, perhaps by disallowing more than one configuration or
606 * by limiting configuration choices (like the pxa2xx).
607 */
608static int
609gmidi_set_config(struct gmidi_device *dev, unsigned number, gfp_t gfp_flags)
610{
611 int result = 0;
612 struct usb_gadget *gadget = dev->gadget;
613
614#if 0
615 /* FIXME */
616 /* Hacking this bit out fixes a bug where on receipt of two
617 USB_REQ_SET_CONFIGURATION messages, we end up with no
618 buffered OUT requests waiting for data. This is clearly
619 hiding a bug elsewhere, because if the config didn't
620 change then we really shouldn't do anything. */
621 /* Having said that, when we do "change" from config 1
622 to config 1, we at least gmidi_reset_config() which
623 clears out any requests on endpoints, so it's not like
624 we leak or anything. */
625 if (number == dev->config) {
626 return 0;
627 }
628#endif
629
630 if (gadget_is_sa1100(gadget) && dev->config) {
631 /* tx fifo is full, but we can't clear it...*/
632 INFO(dev, "can't change configurations\n");
633 return -ESPIPE;
634 }
635 gmidi_reset_config(dev);
636
637 switch (number) {
638 case GMIDI_CONFIG:
639 result = set_gmidi_config(dev, gfp_flags);
640 break;
641 default:
642 result = -EINVAL;
643 /* FALL THROUGH */
644 case 0:
645 return result;
646 }
647
648 if (!result && (!dev->in_ep || !dev->out_ep)) {
649 result = -ENODEV;
650 }
651 if (result) {
652 gmidi_reset_config(dev);
653 } else {
654 char *speed;
655
656 switch (gadget->speed) {
657 case USB_SPEED_LOW: speed = "low"; break;
658 case USB_SPEED_FULL: speed = "full"; break;
659 case USB_SPEED_HIGH: speed = "high"; break;
660 default: speed = "?"; break;
661 }
662
663 dev->config = number;
664 INFO(dev, "%s speed\n", speed);
665 }
666 return result;
667}
668
669
670static void gmidi_setup_complete(struct usb_ep *ep, struct usb_request *req)
671{
672 if (req->status || req->actual != req->length) {
673 DBG((struct gmidi_device *) ep->driver_data,
674 "setup complete --> %d, %d/%d\n",
675 req->status, req->actual, req->length);
676 }
677}
678
679/*
680 * The setup() callback implements all the ep0 functionality that's
681 * not handled lower down, in hardware or the hardware driver (like
682 * device and endpoint feature flags, and their status). It's all
683 * housekeeping for the gadget function we're implementing. Most of
684 * the work is in config-specific setup.
685 */
686static int gmidi_setup(struct usb_gadget *gadget,
687 const struct usb_ctrlrequest *ctrl)
688{
689 struct gmidi_device *dev = get_gadget_data(gadget);
690 struct usb_request *req = dev->req;
691 int value = -EOPNOTSUPP;
692 u16 w_index = le16_to_cpu(ctrl->wIndex);
693 u16 w_value = le16_to_cpu(ctrl->wValue);
694 u16 w_length = le16_to_cpu(ctrl->wLength);
695
696 /* usually this stores reply data in the pre-allocated ep0 buffer,
697 * but config change events will reconfigure hardware.
698 */
699 req->zero = 0;
700 switch (ctrl->bRequest) {
701
702 case USB_REQ_GET_DESCRIPTOR:
703 if (ctrl->bRequestType != USB_DIR_IN) {
704 goto unknown;
705 }
706 switch (w_value >> 8) {
707
708 case USB_DT_DEVICE:
709 value = min(w_length, (u16) sizeof(device_desc));
710 memcpy(req->buf, &device_desc, value);
711 break;
712 case USB_DT_CONFIG:
713 value = config_buf(gadget, req->buf,
714 w_value >> 8,
715 w_value & 0xff);
716 if (value >= 0) {
717 value = min(w_length, (u16)value);
718 }
719 break;
720
721 case USB_DT_STRING:
722 /* wIndex == language code.
723 * this driver only handles one language, you can
724 * add string tables for other languages, using
725 * any UTF-8 characters
726 */
727 value = usb_gadget_get_string(&stringtab,
728 w_value & 0xff, req->buf);
729 if (value >= 0) {
730 value = min(w_length, (u16)value);
731 }
732 break;
733 }
734 break;
735
736 /* currently two configs, two speeds */
737 case USB_REQ_SET_CONFIGURATION:
738 if (ctrl->bRequestType != 0) {
739 goto unknown;
740 }
741 if (gadget->a_hnp_support) {
742 DBG(dev, "HNP available\n");
743 } else if (gadget->a_alt_hnp_support) {
744 DBG(dev, "HNP needs a different root port\n");
745 } else {
746 VDBG(dev, "HNP inactive\n");
747 }
748 spin_lock(&dev->lock);
749 value = gmidi_set_config(dev, w_value, GFP_ATOMIC);
750 spin_unlock(&dev->lock);
751 break;
752 case USB_REQ_GET_CONFIGURATION:
753 if (ctrl->bRequestType != USB_DIR_IN) {
754 goto unknown;
755 }
756 *(u8 *)req->buf = dev->config;
757 value = min(w_length, (u16)1);
758 break;
759
760 /* until we add altsetting support, or other interfaces,
761 * only 0/0 are possible. pxa2xx only supports 0/0 (poorly)
762 * and already killed pending endpoint I/O.
763 */
764 case USB_REQ_SET_INTERFACE:
765 if (ctrl->bRequestType != USB_RECIP_INTERFACE) {
766 goto unknown;
767 }
768 spin_lock(&dev->lock);
769 if (dev->config && w_index < GMIDI_NUM_INTERFACES
770 && w_value == 0)
771 {
772 u8 config = dev->config;
773
774 /* resets interface configuration, forgets about
775 * previous transaction state (queued bufs, etc)
776 * and re-inits endpoint state (toggle etc)
777 * no response queued, just zero status == success.
778 * if we had more than one interface we couldn't
779 * use this "reset the config" shortcut.
780 */
781 gmidi_reset_config(dev);
782 gmidi_set_config(dev, config, GFP_ATOMIC);
783 value = 0;
784 }
785 spin_unlock(&dev->lock);
786 break;
787 case USB_REQ_GET_INTERFACE:
788 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)) {
789 goto unknown;
790 }
791 if (!dev->config) {
792 break;
793 }
794 if (w_index >= GMIDI_NUM_INTERFACES) {
795 value = -EDOM;
796 break;
797 }
798 *(u8 *)req->buf = 0;
799 value = min(w_length, (u16)1);
800 break;
801
802 default:
803unknown:
804 VDBG(dev, "unknown control req%02x.%02x v%04x i%04x l%d\n",
805 ctrl->bRequestType, ctrl->bRequest,
806 w_value, w_index, w_length);
807 }
808
809 /* respond with data transfer before status phase? */
810 if (value >= 0) {
811 req->length = value;
812 req->zero = value < w_length;
813 value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
814 if (value < 0) {
815 DBG(dev, "ep_queue --> %d\n", value);
816 req->status = 0;
817 gmidi_setup_complete(gadget->ep0, req);
818 }
819 }
820
821 /* device either stalls (value < 0) or reports success */
822 return value;
823}
824
825static void gmidi_disconnect(struct usb_gadget *gadget)
826{
827 struct gmidi_device *dev = get_gadget_data(gadget);
828 unsigned long flags;
829
830 spin_lock_irqsave(&dev->lock, flags);
831 gmidi_reset_config(dev);
832
833 /* a more significant application might have some non-usb
834 * activities to quiesce here, saving resources like power
835 * or pushing the notification up a network stack.
836 */
837 spin_unlock_irqrestore(&dev->lock, flags);
838
839 /* next we may get setup() calls to enumerate new connections;
840 * or an unbind() during shutdown (including removing module).
841 */
842}
843
844static void /* __init_or_exit */ gmidi_unbind(struct usb_gadget *gadget)
845{
846 struct gmidi_device *dev = get_gadget_data(gadget);
847 struct snd_card* card;
848
849 DBG(dev, "unbind\n");
850
851 card = dev->card;
852 dev->card = NULL;
853 if (card) {
854 snd_card_free(card);
855 }
856
857 /* we've already been disconnected ... no i/o is active */
858 if (dev->req) {
859 dev->req->length = USB_BUFSIZ;
860 free_ep_req(gadget->ep0, dev->req);
861 }
862 kfree(dev);
863 set_gadget_data(gadget, NULL);
864}
865
866static int gmidi_snd_free(struct snd_device *device)
867{
868 return 0;
869}
870
871static void gmidi_transmit_packet(struct usb_request* req, uint8_t p0,
872 uint8_t p1, uint8_t p2, uint8_t p3)
873{
874 unsigned length = req->length;
875
876 uint8_t* buf = (uint8_t*)req->buf + length;
877 buf[0] = p0;
878 buf[1] = p1;
879 buf[2] = p2;
880 buf[3] = p3;
881 req->length = length + 4;
882}
883
884/*
885 * Converts MIDI commands to USB MIDI packets.
886 */
887static void gmidi_transmit_byte(struct usb_request* req,
888 struct gmidi_in_port* port, uint8_t b)
889{
890 uint8_t p0 = port->cable;
891
892 if (b >= 0xf8) {
893 gmidi_transmit_packet(req, p0 | 0x0f, b, 0, 0);
894 } else if (b >= 0xf0) {
895 switch (b) {
896 case 0xf0:
897 port->data[0] = b;
898 port->state = STATE_SYSEX_1;
899 break;
900 case 0xf1:
901 case 0xf3:
902 port->data[0] = b;
903 port->state = STATE_1PARAM;
904 break;
905 case 0xf2:
906 port->data[0] = b;
907 port->state = STATE_2PARAM_1;
908 break;
909 case 0xf4:
910 case 0xf5:
911 port->state = STATE_UNKNOWN;
912 break;
913 case 0xf6:
914 gmidi_transmit_packet(req, p0 | 0x05, 0xf6, 0, 0);
915 port->state = STATE_UNKNOWN;
916 break;
917 case 0xf7:
918 switch (port->state) {
919 case STATE_SYSEX_0:
920 gmidi_transmit_packet(req,
921 p0 | 0x05, 0xf7, 0, 0);
922 break;
923 case STATE_SYSEX_1:
924 gmidi_transmit_packet(req,
925 p0 | 0x06, port->data[0], 0xf7, 0);
926 break;
927 case STATE_SYSEX_2:
928 gmidi_transmit_packet(req,
929 p0 | 0x07, port->data[0],
930 port->data[1], 0xf7);
931 break;
932 }
933 port->state = STATE_UNKNOWN;
934 break;
935 }
936 } else if (b >= 0x80) {
937 port->data[0] = b;
938 if (b >= 0xc0 && b <= 0xdf)
939 port->state = STATE_1PARAM;
940 else
941 port->state = STATE_2PARAM_1;
942 } else { /* b < 0x80 */
943 switch (port->state) {
944 case STATE_1PARAM:
945 if (port->data[0] < 0xf0) {
946 p0 |= port->data[0] >> 4;
947 } else {
948 p0 |= 0x02;
949 port->state = STATE_UNKNOWN;
950 }
951 gmidi_transmit_packet(req, p0, port->data[0], b, 0);
952 break;
953 case STATE_2PARAM_1:
954 port->data[1] = b;
955 port->state = STATE_2PARAM_2;
956 break;
957 case STATE_2PARAM_2:
958 if (port->data[0] < 0xf0) {
959 p0 |= port->data[0] >> 4;
960 port->state = STATE_2PARAM_1;
961 } else {
962 p0 |= 0x03;
963 port->state = STATE_UNKNOWN;
964 }
965 gmidi_transmit_packet(req,
966 p0, port->data[0], port->data[1], b);
967 break;
968 case STATE_SYSEX_0:
969 port->data[0] = b;
970 port->state = STATE_SYSEX_1;
971 break;
972 case STATE_SYSEX_1:
973 port->data[1] = b;
974 port->state = STATE_SYSEX_2;
975 break;
976 case STATE_SYSEX_2:
977 gmidi_transmit_packet(req,
978 p0 | 0x04, port->data[0], port->data[1], b);
979 port->state = STATE_SYSEX_0;
980 break;
981 }
982 }
983}
984
985static void gmidi_transmit(struct gmidi_device* dev, struct usb_request* req)
986{
987 struct usb_ep* ep = dev->in_ep;
988 struct gmidi_in_port* port = &dev->in_port;
989
990 if (!ep) {
991 return;
992 }
993 if (!req) {
994 req = alloc_ep_req(ep, buflen);
995 }
996 if (!req) {
997 ERROR(dev, "gmidi_transmit: alloc_ep_request failed\n");
998 return;
999 }
1000 req->length = 0;
1001 req->complete = gmidi_complete;
1002
1003 if (port->active) {
1004 while (req->length + 3 < buflen) {
1005 uint8_t b;
1006 if (snd_rawmidi_transmit(dev->in_substream, &b, 1)
1007 != 1)
1008 {
1009 port->active = 0;
1010 break;
1011 }
1012 gmidi_transmit_byte(req, port, b);
1013 }
1014 }
1015 if (req->length > 0) {
1016 usb_ep_queue(ep, req, GFP_ATOMIC);
1017 } else {
1018 free_ep_req(ep, req);
1019 }
1020}
1021
1022static void gmidi_in_tasklet(unsigned long data)
1023{
1024 struct gmidi_device* dev = (struct gmidi_device*)data;
1025
1026 gmidi_transmit(dev, NULL);
1027}
1028
1029static int gmidi_in_open(struct snd_rawmidi_substream *substream)
1030{
1031 struct gmidi_device* dev = substream->rmidi->private_data;
1032
1033 VDBG(dev, "gmidi_in_open\n");
1034 dev->in_substream = substream;
1035 dev->in_port.state = STATE_UNKNOWN;
1036 return 0;
1037}
1038
1039static int gmidi_in_close(struct snd_rawmidi_substream *substream)
1040{
1041 VDBG(dev, "gmidi_in_close\n");
1042 return 0;
1043}
1044
1045static void gmidi_in_trigger(struct snd_rawmidi_substream *substream, int up)
1046{
1047 struct gmidi_device* dev = substream->rmidi->private_data;
1048
1049 VDBG(dev, "gmidi_in_trigger %d\n", up);
1050 dev->in_port.active = up;
1051 if (up) {
1052 tasklet_hi_schedule(&dev->tasklet);
1053 }
1054}
1055
1056static int gmidi_out_open(struct snd_rawmidi_substream *substream)
1057{
1058 struct gmidi_device* dev = substream->rmidi->private_data;
1059
1060 VDBG(dev, "gmidi_out_open\n");
1061 dev->out_substream = substream;
1062 return 0;
1063}
1064
1065static int gmidi_out_close(struct snd_rawmidi_substream *substream)
1066{
1067 VDBG(dev, "gmidi_out_close\n");
1068 return 0;
1069}
1070
1071static void gmidi_out_trigger(struct snd_rawmidi_substream *substream, int up)
1072{
1073 struct gmidi_device* dev = substream->rmidi->private_data;
1074
1075 VDBG(dev, "gmidi_out_trigger %d\n", up);
1076 if (up) {
1077 set_bit(substream->number, &dev->out_triggered);
1078 } else {
1079 clear_bit(substream->number, &dev->out_triggered);
1080 }
1081}
1082
1083static struct snd_rawmidi_ops gmidi_in_ops = {
1084 .open = gmidi_in_open,
1085 .close = gmidi_in_close,
1086 .trigger = gmidi_in_trigger,
1087};
1088
1089static struct snd_rawmidi_ops gmidi_out_ops = {
1090 .open = gmidi_out_open,
1091 .close = gmidi_out_close,
1092 .trigger = gmidi_out_trigger
1093};
1094
1095/* register as a sound "card" */
1096static int gmidi_register_card(struct gmidi_device *dev)
1097{
1098 struct snd_card *card;
1099 struct snd_rawmidi *rmidi;
1100 int err;
1101 int out_ports = 1;
1102 int in_ports = 1;
1103 static struct snd_device_ops ops = {
1104 .dev_free = gmidi_snd_free,
1105 };
1106
1107 card = snd_card_new(index, id, THIS_MODULE, 0);
1108 if (!card) {
1109 ERROR(dev, "snd_card_new failed\n");
1110 err = -ENOMEM;
1111 goto fail;
1112 }
1113 dev->card = card;
1114
1115 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, dev, &ops);
1116 if (err < 0) {
1117 ERROR(dev, "snd_device_new failed: error %d\n", err);
1118 goto fail;
1119 }
1120
1121 strcpy(card->driver, longname);
1122 strcpy(card->longname, longname);
1123 strcpy(card->shortname, shortname);
1124
1125 /* Set up rawmidi */
1126 dev->in_port.dev = dev;
1127 dev->in_port.active = 0;
1128 snd_component_add(card, "MIDI");
1129 err = snd_rawmidi_new(card, "USB MIDI Gadget", 0,
1130 out_ports, in_ports, &rmidi);
1131 if (err < 0) {
1132 ERROR(dev, "snd_rawmidi_new failed: error %d\n", err);
1133 goto fail;
1134 }
1135 dev->rmidi = rmidi;
1136 strcpy(rmidi->name, card->shortname);
1137 rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT |
1138 SNDRV_RAWMIDI_INFO_INPUT |
1139 SNDRV_RAWMIDI_INFO_DUPLEX;
1140 rmidi->private_data = dev;
1141
1142 /* Yes, rawmidi OUTPUT = USB IN, and rawmidi INPUT = USB OUT.
1143 It's an upside-down world being a gadget. */
1144 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &gmidi_in_ops);
1145 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &gmidi_out_ops);
1146
1147 snd_card_set_dev(card, &dev->gadget->dev);
1148
1149 /* register it - we're ready to go */
1150 err = snd_card_register(card);
1151 if (err < 0) {
1152 ERROR(dev, "snd_card_register failed\n");
1153 goto fail;
1154 }
1155
1156 VDBG(dev, "gmidi_register_card finished ok\n");
1157 return 0;
1158
1159fail:
1160 if (dev->card) {
1161 snd_card_free(dev->card);
1162 dev->card = NULL;
1163 }
1164 return err;
1165}
1166
1167/*
1168 * Creates an output endpoint, and initializes output ports.
1169 */
1170static int __devinit gmidi_bind(struct usb_gadget *gadget)
1171{
1172 struct gmidi_device *dev;
1173 struct usb_ep *in_ep, *out_ep;
1174 int gcnum, err = 0;
1175
1176 /* support optional vendor/distro customization */
1177 if (idVendor) {
1178 if (!idProduct) {
1179 printk(KERN_ERR "idVendor needs idProduct!\n");
1180 return -ENODEV;
1181 }
1182 device_desc.idVendor = cpu_to_le16(idVendor);
1183 device_desc.idProduct = cpu_to_le16(idProduct);
1184 if (bcdDevice) {
1185 device_desc.bcdDevice = cpu_to_le16(bcdDevice);
1186 }
1187 }
1188 if (iManufacturer) {
1189 strlcpy(manufacturer, iManufacturer, sizeof(manufacturer));
1190 } else {
1191 snprintf(manufacturer, sizeof(manufacturer), "%s %s with %s",
1192 init_utsname()->sysname, init_utsname()->release,
1193 gadget->name);
1194 }
1195 if (iProduct) {
1196 strlcpy(product_desc, iProduct, sizeof(product_desc));
1197 }
1198 if (iSerialNumber) {
1199 device_desc.iSerialNumber = STRING_SERIAL,
1200 strlcpy(serial_number, iSerialNumber, sizeof(serial_number));
1201 }
1202
1203 /* Bulk-only drivers like this one SHOULD be able to
1204 * autoconfigure on any sane usb controller driver,
1205 * but there may also be important quirks to address.
1206 */
1207 usb_ep_autoconfig_reset(gadget);
1208 in_ep = usb_ep_autoconfig(gadget, &bulk_in_desc);
1209 if (!in_ep) {
1210autoconf_fail:
1211 printk(KERN_ERR "%s: can't autoconfigure on %s\n",
1212 shortname, gadget->name);
1213 return -ENODEV;
1214 }
1215 EP_IN_NAME = in_ep->name;
1216 in_ep->driver_data = in_ep; /* claim */
1217
1218 out_ep = usb_ep_autoconfig(gadget, &bulk_out_desc);
1219 if (!out_ep) {
1220 goto autoconf_fail;
1221 }
1222 EP_OUT_NAME = out_ep->name;
1223 out_ep->driver_data = out_ep; /* claim */
1224
1225 gcnum = usb_gadget_controller_number(gadget);
1226 if (gcnum >= 0) {
1227 device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
1228 } else {
1229 /* gmidi is so simple (no altsettings) that
1230 * it SHOULD NOT have problems with bulk-capable hardware.
1231 * so warn about unrecognized controllers, don't panic.
1232 */
1233 printk(KERN_WARNING "%s: controller '%s' not recognized\n",
1234 shortname, gadget->name);
1235 device_desc.bcdDevice = __constant_cpu_to_le16(0x9999);
1236 }
1237
1238
1239 /* ok, we made sense of the hardware ... */
1240 dev = kzalloc(sizeof(*dev), SLAB_KERNEL);
1241 if (!dev) {
1242 return -ENOMEM;
1243 }
1244 spin_lock_init(&dev->lock);
1245 dev->gadget = gadget;
1246 dev->in_ep = in_ep;
1247 dev->out_ep = out_ep;
1248 set_gadget_data(gadget, dev);
1249 tasklet_init(&dev->tasklet, gmidi_in_tasklet, (unsigned long)dev);
1250
1251 /* preallocate control response and buffer */
1252 dev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL);
1253 if (!dev->req) {
1254 err = -ENOMEM;
1255 goto fail;
1256 }
1257 dev->req->buf = usb_ep_alloc_buffer(gadget->ep0, USB_BUFSIZ,
1258 &dev->req->dma, GFP_KERNEL);
1259 if (!dev->req->buf) {
1260 err = -ENOMEM;
1261 goto fail;
1262 }
1263
1264 dev->req->complete = gmidi_setup_complete;
1265
1266 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1267
1268 gadget->ep0->driver_data = dev;
1269
1270 INFO(dev, "%s, version: " DRIVER_VERSION "\n", longname);
1271 INFO(dev, "using %s, OUT %s IN %s\n", gadget->name,
1272 EP_OUT_NAME, EP_IN_NAME);
1273
1274 /* register as an ALSA sound card */
1275 err = gmidi_register_card(dev);
1276 if (err < 0) {
1277 goto fail;
1278 }
1279
1280 VDBG(dev, "gmidi_bind finished ok\n");
1281 return 0;
1282
1283fail:
1284 gmidi_unbind(gadget);
1285 return err;
1286}
1287
1288
1289static void gmidi_suspend(struct usb_gadget *gadget)
1290{
1291 struct gmidi_device *dev = get_gadget_data(gadget);
1292
1293 if (gadget->speed == USB_SPEED_UNKNOWN) {
1294 return;
1295 }
1296
1297 DBG(dev, "suspend\n");
1298}
1299
1300static void gmidi_resume(struct usb_gadget *gadget)
1301{
1302 struct gmidi_device *dev = get_gadget_data(gadget);
1303
1304 DBG(dev, "resume\n");
1305}
1306
1307
1308static struct usb_gadget_driver gmidi_driver = {
1309 .speed = USB_SPEED_FULL,
1310 .function = (char *)longname,
1311 .bind = gmidi_bind,
1312 .unbind = __exit_p(gmidi_unbind),
1313
1314 .setup = gmidi_setup,
1315 .disconnect = gmidi_disconnect,
1316
1317 .suspend = gmidi_suspend,
1318 .resume = gmidi_resume,
1319
1320 .driver = {
1321 .name = (char *)shortname,
1322 .owner = THIS_MODULE,
1323 },
1324};
1325
1326static int __init gmidi_init(void)
1327{
1328 return usb_gadget_register_driver(&gmidi_driver);
1329}
1330module_init(gmidi_init);
1331
1332static void __exit gmidi_cleanup(void)
1333{
1334 usb_gadget_unregister_driver(&gmidi_driver);
1335}
1336module_exit(gmidi_cleanup);
1337
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 3bdc5e3ba234..86924f9cdd7e 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -32,6 +32,7 @@
32#include <linux/compiler.h> 32#include <linux/compiler.h>
33#include <asm/uaccess.h> 33#include <asm/uaccess.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/poll.h>
35 36
36#include <linux/device.h> 37#include <linux/device.h>
37#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
@@ -222,7 +223,6 @@ static void put_ep (struct ep_data *data)
222 /* needs no more cleanup */ 223 /* needs no more cleanup */
223 BUG_ON (!list_empty (&data->epfiles)); 224 BUG_ON (!list_empty (&data->epfiles));
224 BUG_ON (waitqueue_active (&data->wait)); 225 BUG_ON (waitqueue_active (&data->wait));
225 BUG_ON (down_trylock (&data->lock) != 0);
226 kfree (data); 226 kfree (data);
227} 227}
228 228
@@ -342,7 +342,7 @@ fail:
342static ssize_t 342static ssize_t
343ep_io (struct ep_data *epdata, void *buf, unsigned len) 343ep_io (struct ep_data *epdata, void *buf, unsigned len)
344{ 344{
345 DECLARE_COMPLETION (done); 345 DECLARE_COMPLETION_ONSTACK (done);
346 int value; 346 int value;
347 347
348 spin_lock_irq (&epdata->dev->lock); 348 spin_lock_irq (&epdata->dev->lock);
@@ -477,6 +477,10 @@ static int
477ep_release (struct inode *inode, struct file *fd) 477ep_release (struct inode *inode, struct file *fd)
478{ 478{
479 struct ep_data *data = fd->private_data; 479 struct ep_data *data = fd->private_data;
480 int value;
481
482 if ((value = down_interruptible(&data->lock)) < 0)
483 return value;
480 484
481 /* clean up if this can be reopened */ 485 /* clean up if this can be reopened */
482 if (data->state != STATE_EP_UNBOUND) { 486 if (data->state != STATE_EP_UNBOUND) {
@@ -485,6 +489,7 @@ ep_release (struct inode *inode, struct file *fd)
485 data->hs_desc.bDescriptorType = 0; 489 data->hs_desc.bDescriptorType = 0;
486 usb_ep_disable(data->ep); 490 usb_ep_disable(data->ep);
487 } 491 }
492 up (&data->lock);
488 put_ep (data); 493 put_ep (data);
489 return 0; 494 return 0;
490} 495}
@@ -528,7 +533,8 @@ struct kiocb_priv {
528 struct usb_request *req; 533 struct usb_request *req;
529 struct ep_data *epdata; 534 struct ep_data *epdata;
530 void *buf; 535 void *buf;
531 char __user *ubuf; /* NULL for writes */ 536 const struct iovec *iv;
537 unsigned long nr_segs;
532 unsigned actual; 538 unsigned actual;
533}; 539};
534 540
@@ -556,17 +562,32 @@ static int ep_aio_cancel(struct kiocb *iocb, struct io_event *e)
556static ssize_t ep_aio_read_retry(struct kiocb *iocb) 562static ssize_t ep_aio_read_retry(struct kiocb *iocb)
557{ 563{
558 struct kiocb_priv *priv = iocb->private; 564 struct kiocb_priv *priv = iocb->private;
559 ssize_t status = priv->actual; 565 ssize_t len, total;
560 566 int i;
561 /* we "retry" to get the right mm context for this: */ 567
562 status = copy_to_user(priv->ubuf, priv->buf, priv->actual); 568 /* we "retry" to get the right mm context for this: */
563 if (unlikely(0 != status)) 569
564 status = -EFAULT; 570 /* copy stuff into user buffers */
565 else 571 total = priv->actual;
566 status = priv->actual; 572 len = 0;
567 kfree(priv->buf); 573 for (i=0; i < priv->nr_segs; i++) {
568 kfree(priv); 574 ssize_t this = min((ssize_t)(priv->iv[i].iov_len), total);
569 return status; 575
576 if (copy_to_user(priv->iv[i].iov_base, priv->buf, this)) {
577 if (len == 0)
578 len = -EFAULT;
579 break;
580 }
581
582 total -= this;
583 len += this;
584 if (total == 0)
585 break;
586 }
587 kfree(priv->buf);
588 kfree(priv);
589 aio_put_req(iocb);
590 return len;
570} 591}
571 592
572static void ep_aio_complete(struct usb_ep *ep, struct usb_request *req) 593static void ep_aio_complete(struct usb_ep *ep, struct usb_request *req)
@@ -579,7 +600,7 @@ static void ep_aio_complete(struct usb_ep *ep, struct usb_request *req)
579 spin_lock(&epdata->dev->lock); 600 spin_lock(&epdata->dev->lock);
580 priv->req = NULL; 601 priv->req = NULL;
581 priv->epdata = NULL; 602 priv->epdata = NULL;
582 if (priv->ubuf == NULL 603 if (priv->iv == NULL
583 || unlikely(req->actual == 0) 604 || unlikely(req->actual == 0)
584 || unlikely(kiocbIsCancelled(iocb))) { 605 || unlikely(kiocbIsCancelled(iocb))) {
585 kfree(req->buf); 606 kfree(req->buf);
@@ -614,7 +635,8 @@ ep_aio_rwtail(
614 char *buf, 635 char *buf,
615 size_t len, 636 size_t len,
616 struct ep_data *epdata, 637 struct ep_data *epdata,
617 char __user *ubuf 638 const struct iovec *iv,
639 unsigned long nr_segs
618) 640)
619{ 641{
620 struct kiocb_priv *priv; 642 struct kiocb_priv *priv;
@@ -629,7 +651,8 @@ fail:
629 return value; 651 return value;
630 } 652 }
631 iocb->private = priv; 653 iocb->private = priv;
632 priv->ubuf = ubuf; 654 priv->iv = iv;
655 priv->nr_segs = nr_segs;
633 656
634 value = get_ready_ep(iocb->ki_filp->f_flags, epdata); 657 value = get_ready_ep(iocb->ki_filp->f_flags, epdata);
635 if (unlikely(value < 0)) { 658 if (unlikely(value < 0)) {
@@ -669,47 +692,59 @@ fail:
669 kfree(priv); 692 kfree(priv);
670 put_ep(epdata); 693 put_ep(epdata);
671 } else 694 } else
672 value = (ubuf ? -EIOCBRETRY : -EIOCBQUEUED); 695 value = (iv ? -EIOCBRETRY : -EIOCBQUEUED);
673 return value; 696 return value;
674} 697}
675 698
676static ssize_t 699static ssize_t
677ep_aio_read(struct kiocb *iocb, char __user *ubuf, size_t len, loff_t o) 700ep_aio_read(struct kiocb *iocb, const struct iovec *iov,
701 unsigned long nr_segs, loff_t o)
678{ 702{
679 struct ep_data *epdata = iocb->ki_filp->private_data; 703 struct ep_data *epdata = iocb->ki_filp->private_data;
680 char *buf; 704 char *buf;
681 705
682 if (unlikely(epdata->desc.bEndpointAddress & USB_DIR_IN)) 706 if (unlikely(epdata->desc.bEndpointAddress & USB_DIR_IN))
683 return -EINVAL; 707 return -EINVAL;
684 buf = kmalloc(len, GFP_KERNEL); 708
709 buf = kmalloc(iocb->ki_left, GFP_KERNEL);
685 if (unlikely(!buf)) 710 if (unlikely(!buf))
686 return -ENOMEM; 711 return -ENOMEM;
712
687 iocb->ki_retry = ep_aio_read_retry; 713 iocb->ki_retry = ep_aio_read_retry;
688 return ep_aio_rwtail(iocb, buf, len, epdata, ubuf); 714 return ep_aio_rwtail(iocb, buf, iocb->ki_left, epdata, iov, nr_segs);
689} 715}
690 716
691static ssize_t 717static ssize_t
692ep_aio_write(struct kiocb *iocb, const char __user *ubuf, size_t len, loff_t o) 718ep_aio_write(struct kiocb *iocb, const struct iovec *iov,
719 unsigned long nr_segs, loff_t o)
693{ 720{
694 struct ep_data *epdata = iocb->ki_filp->private_data; 721 struct ep_data *epdata = iocb->ki_filp->private_data;
695 char *buf; 722 char *buf;
723 size_t len = 0;
724 int i = 0;
696 725
697 if (unlikely(!(epdata->desc.bEndpointAddress & USB_DIR_IN))) 726 if (unlikely(!(epdata->desc.bEndpointAddress & USB_DIR_IN)))
698 return -EINVAL; 727 return -EINVAL;
699 buf = kmalloc(len, GFP_KERNEL); 728
729 buf = kmalloc(iocb->ki_left, GFP_KERNEL);
700 if (unlikely(!buf)) 730 if (unlikely(!buf))
701 return -ENOMEM; 731 return -ENOMEM;
702 if (unlikely(copy_from_user(buf, ubuf, len) != 0)) { 732
703 kfree(buf); 733 for (i=0; i < nr_segs; i++) {
704 return -EFAULT; 734 if (unlikely(copy_from_user(&buf[len], iov[i].iov_base,
735 iov[i].iov_len) != 0)) {
736 kfree(buf);
737 return -EFAULT;
738 }
739 len += iov[i].iov_len;
705 } 740 }
706 return ep_aio_rwtail(iocb, buf, len, epdata, NULL); 741 return ep_aio_rwtail(iocb, buf, len, epdata, NULL, 0);
707} 742}
708 743
709/*----------------------------------------------------------------------*/ 744/*----------------------------------------------------------------------*/
710 745
711/* used after endpoint configuration */ 746/* used after endpoint configuration */
712static struct file_operations ep_io_operations = { 747static const struct file_operations ep_io_operations = {
713 .owner = THIS_MODULE, 748 .owner = THIS_MODULE,
714 .llseek = no_llseek, 749 .llseek = no_llseek,
715 750
@@ -741,7 +776,7 @@ ep_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
741 struct ep_data *data = fd->private_data; 776 struct ep_data *data = fd->private_data;
742 struct usb_ep *ep; 777 struct usb_ep *ep;
743 u32 tag; 778 u32 tag;
744 int value; 779 int value, length = len;
745 780
746 if ((value = down_interruptible (&data->lock)) < 0) 781 if ((value = down_interruptible (&data->lock)) < 0)
747 return value; 782 return value;
@@ -792,7 +827,6 @@ ep_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
792 goto fail0; 827 goto fail0;
793 } 828 }
794 } 829 }
795 value = len;
796 830
797 spin_lock_irq (&data->dev->lock); 831 spin_lock_irq (&data->dev->lock);
798 if (data->dev->state == STATE_DEV_UNBOUND) { 832 if (data->dev->state == STATE_DEV_UNBOUND) {
@@ -822,8 +856,10 @@ ep_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
822 data->name); 856 data->name);
823 data->state = STATE_EP_DEFER_ENABLE; 857 data->state = STATE_EP_DEFER_ENABLE;
824 } 858 }
825 if (value == 0) 859 if (value == 0) {
826 fd->f_op = &ep_io_operations; 860 fd->f_op = &ep_io_operations;
861 value = length;
862 }
827gone: 863gone:
828 spin_unlock_irq (&data->dev->lock); 864 spin_unlock_irq (&data->dev->lock);
829 if (value < 0) { 865 if (value < 0) {
@@ -844,7 +880,7 @@ fail1:
844static int 880static int
845ep_open (struct inode *inode, struct file *fd) 881ep_open (struct inode *inode, struct file *fd)
846{ 882{
847 struct ep_data *data = inode->u.generic_ip; 883 struct ep_data *data = inode->i_private;
848 int value = -EBUSY; 884 int value = -EBUSY;
849 885
850 if (down_interruptible (&data->lock) != 0) 886 if (down_interruptible (&data->lock) != 0)
@@ -867,7 +903,7 @@ ep_open (struct inode *inode, struct file *fd)
867} 903}
868 904
869/* used before endpoint configuration */ 905/* used before endpoint configuration */
870static struct file_operations ep_config_operations = { 906static const struct file_operations ep_config_operations = {
871 .owner = THIS_MODULE, 907 .owner = THIS_MODULE,
872 .llseek = no_llseek, 908 .llseek = no_llseek,
873 909
@@ -1009,7 +1045,7 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
1009 else { 1045 else {
1010 len = min (len, (size_t)dev->req->actual); 1046 len = min (len, (size_t)dev->req->actual);
1011// FIXME don't call this with the spinlock held ... 1047// FIXME don't call this with the spinlock held ...
1012 if (copy_to_user (buf, &dev->req->buf, len)) 1048 if (copy_to_user (buf, dev->req->buf, len))
1013 retval = -EFAULT; 1049 retval = -EFAULT;
1014 clean_req (dev->gadget->ep0, dev->req); 1050 clean_req (dev->gadget->ep0, dev->req);
1015 /* NOTE userspace can't yet choose to stall */ 1051 /* NOTE userspace can't yet choose to stall */
@@ -1229,6 +1265,35 @@ dev_release (struct inode *inode, struct file *fd)
1229 return 0; 1265 return 0;
1230} 1266}
1231 1267
1268static unsigned int
1269ep0_poll (struct file *fd, poll_table *wait)
1270{
1271 struct dev_data *dev = fd->private_data;
1272 int mask = 0;
1273
1274 poll_wait(fd, &dev->wait, wait);
1275
1276 spin_lock_irq (&dev->lock);
1277
1278 /* report fd mode change before acting on it */
1279 if (dev->setup_abort) {
1280 dev->setup_abort = 0;
1281 mask = POLLHUP;
1282 goto out;
1283 }
1284
1285 if (dev->state == STATE_SETUP) {
1286 if (dev->setup_in || dev->setup_can_stall)
1287 mask = POLLOUT;
1288 } else {
1289 if (dev->ev_next != 0)
1290 mask = POLLIN;
1291 }
1292out:
1293 spin_unlock_irq(&dev->lock);
1294 return mask;
1295}
1296
1232static int dev_ioctl (struct inode *inode, struct file *fd, 1297static int dev_ioctl (struct inode *inode, struct file *fd,
1233 unsigned code, unsigned long value) 1298 unsigned code, unsigned long value)
1234{ 1299{
@@ -1241,14 +1306,14 @@ static int dev_ioctl (struct inode *inode, struct file *fd,
1241} 1306}
1242 1307
1243/* used after device configuration */ 1308/* used after device configuration */
1244static struct file_operations ep0_io_operations = { 1309static const struct file_operations ep0_io_operations = {
1245 .owner = THIS_MODULE, 1310 .owner = THIS_MODULE,
1246 .llseek = no_llseek, 1311 .llseek = no_llseek,
1247 1312
1248 .read = ep0_read, 1313 .read = ep0_read,
1249 .write = ep0_write, 1314 .write = ep0_write,
1250 .fasync = ep0_fasync, 1315 .fasync = ep0_fasync,
1251 // .poll = ep0_poll, 1316 .poll = ep0_poll,
1252 .ioctl = dev_ioctl, 1317 .ioctl = dev_ioctl,
1253 .release = dev_release, 1318 .release = dev_release,
1254}; 1319};
@@ -1696,16 +1761,17 @@ gadgetfs_disconnect (struct usb_gadget *gadget)
1696{ 1761{
1697 struct dev_data *dev = get_gadget_data (gadget); 1762 struct dev_data *dev = get_gadget_data (gadget);
1698 1763
1764 spin_lock (&dev->lock);
1699 if (dev->state == STATE_UNCONNECTED) { 1765 if (dev->state == STATE_UNCONNECTED) {
1700 DBG (dev, "already unconnected\n"); 1766 DBG (dev, "already unconnected\n");
1701 return; 1767 goto exit;
1702 } 1768 }
1703 dev->state = STATE_UNCONNECTED; 1769 dev->state = STATE_UNCONNECTED;
1704 1770
1705 INFO (dev, "disconnected\n"); 1771 INFO (dev, "disconnected\n");
1706 spin_lock (&dev->lock);
1707 next_event (dev, GADGETFS_DISCONNECT); 1772 next_event (dev, GADGETFS_DISCONNECT);
1708 ep0_readable (dev); 1773 ep0_readable (dev);
1774exit:
1709 spin_unlock (&dev->lock); 1775 spin_unlock (&dev->lock);
1710} 1776}
1711 1777
@@ -1909,7 +1975,7 @@ fail:
1909static int 1975static int
1910dev_open (struct inode *inode, struct file *fd) 1976dev_open (struct inode *inode, struct file *fd)
1911{ 1977{
1912 struct dev_data *dev = inode->u.generic_ip; 1978 struct dev_data *dev = inode->i_private;
1913 int value = -EBUSY; 1979 int value = -EBUSY;
1914 1980
1915 if (dev->state == STATE_DEV_DISABLED) { 1981 if (dev->state == STATE_DEV_DISABLED) {
@@ -1922,7 +1988,7 @@ dev_open (struct inode *inode, struct file *fd)
1922 return value; 1988 return value;
1923} 1989}
1924 1990
1925static struct file_operations dev_init_operations = { 1991static const struct file_operations dev_init_operations = {
1926 .owner = THIS_MODULE, 1992 .owner = THIS_MODULE,
1927 .llseek = no_llseek, 1993 .llseek = no_llseek,
1928 1994
@@ -1966,11 +2032,10 @@ gadgetfs_make_inode (struct super_block *sb,
1966 inode->i_mode = mode; 2032 inode->i_mode = mode;
1967 inode->i_uid = default_uid; 2033 inode->i_uid = default_uid;
1968 inode->i_gid = default_gid; 2034 inode->i_gid = default_gid;
1969 inode->i_blksize = PAGE_CACHE_SIZE;
1970 inode->i_blocks = 0; 2035 inode->i_blocks = 0;
1971 inode->i_atime = inode->i_mtime = inode->i_ctime 2036 inode->i_atime = inode->i_mtime = inode->i_ctime
1972 = CURRENT_TIME; 2037 = CURRENT_TIME;
1973 inode->u.generic_ip = data; 2038 inode->i_private = data;
1974 inode->i_fop = fops; 2039 inode->i_fop = fops;
1975 } 2040 }
1976 return inode; 2041 return inode;
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 09243239d948..3bda37f9a35f 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -2,7 +2,7 @@
2 * Driver for the PLX NET2280 USB device controller. 2 * Driver for the PLX NET2280 USB device controller.
3 * Specs and errata are available from <http://www.plxtech.com>. 3 * Specs and errata are available from <http://www.plxtech.com>.
4 * 4 *
5 * PLX Technology Inc. (formerly NetChip Technology) supported the 5 * PLX Technology Inc. (formerly NetChip Technology) supported the
6 * development of this driver. 6 * development of this driver.
7 * 7 *
8 * 8 *
@@ -26,7 +26,8 @@
26 * Copyright (C) 2003 David Brownell 26 * Copyright (C) 2003 David Brownell
27 * Copyright (C) 2003-2005 PLX Technology, Inc. 27 * Copyright (C) 2003-2005 PLX Technology, Inc.
28 * 28 *
29 * Modified Seth Levy 2005 PLX Technology, Inc. to provide compatibility with 2282 chip 29 * Modified Seth Levy 2005 PLX Technology, Inc. to provide compatibility
30 * with 2282 chip
30 * 31 *
31 * This program is free software; you can redistribute it and/or modify 32 * This program is free software; you can redistribute it and/or modify
32 * it under the terms of the GNU General Public License as published by 33 * it under the terms of the GNU General Public License as published by
@@ -85,7 +86,7 @@ static const char driver_name [] = "net2280";
85static const char driver_desc [] = DRIVER_DESC; 86static const char driver_desc [] = DRIVER_DESC;
86 87
87static const char ep0name [] = "ep0"; 88static const char ep0name [] = "ep0";
88static const char *ep_name [] = { 89static const char *const ep_name [] = {
89 ep0name, 90 ep0name,
90 "ep-a", "ep-b", "ep-c", "ep-d", 91 "ep-a", "ep-b", "ep-c", "ep-d",
91 "ep-e", "ep-f", 92 "ep-e", "ep-f",
@@ -225,7 +226,9 @@ net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
225 if (!ep->is_in) 226 if (!ep->is_in)
226 writel ((1 << SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp); 227 writel ((1 << SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
227 else if (dev->pdev->device != 0x2280) { 228 else if (dev->pdev->device != 0x2280) {
228 /* Added for 2282, Don't use nak packets on an in endpoint, this was ignored on 2280 */ 229 /* Added for 2282, Don't use nak packets on an in endpoint,
230 * this was ignored on 2280
231 */
229 writel ((1 << CLEAR_NAK_OUT_PACKETS) 232 writel ((1 << CLEAR_NAK_OUT_PACKETS)
230 | (1 << CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp); 233 | (1 << CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp);
231 } 234 }
@@ -288,7 +291,7 @@ static int handshake (u32 __iomem *ptr, u32 mask, u32 done, int usec)
288 return -ETIMEDOUT; 291 return -ETIMEDOUT;
289} 292}
290 293
291static struct usb_ep_ops net2280_ep_ops; 294static const struct usb_ep_ops net2280_ep_ops;
292 295
293static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep) 296static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep)
294{ 297{
@@ -449,34 +452,15 @@ net2280_free_request (struct usb_ep *_ep, struct usb_request *_req)
449 452
450/*-------------------------------------------------------------------------*/ 453/*-------------------------------------------------------------------------*/
451 454
452#undef USE_KMALLOC 455/*
453 456 * dma-coherent memory allocation (for dma-capable endpoints)
454/* many common platforms have dma-coherent caches, which means that it's
455 * safe to use kmalloc() memory for all i/o buffers without using any
456 * cache flushing calls. (unless you're trying to share cache lines
457 * between dma and non-dma activities, which is a slow idea in any case.)
458 * 457 *
459 * other platforms need more care, with 2.5 having a moderately general 458 * NOTE: the dma_*_coherent() API calls suck. Most implementations are
460 * solution (which falls down for allocations smaller than one page) 459 * (a) page-oriented, so small buffers lose big; and (b) asymmetric with
461 * that improves significantly on the 2.4 PCI allocators by removing 460 * respect to calls with irqs disabled: alloc is safe, free is not.
462 * the restriction that memory never be freed in_interrupt(). 461 * We currently work around (b), but not (a).
463 */ 462 */
464#if defined(CONFIG_X86)
465#define USE_KMALLOC
466
467#elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE)
468#define USE_KMALLOC
469 463
470#elif defined(CONFIG_MIPS) && !defined(CONFIG_DMA_NONCOHERENT)
471#define USE_KMALLOC
472
473/* FIXME there are other cases, including an x86-64 one ... */
474#endif
475
476/* allocating buffers this way eliminates dma mapping overhead, which
477 * on some platforms will mean eliminating a per-io buffer copy. with
478 * some kinds of system caches, further tweaks may still be needed.
479 */
480static void * 464static void *
481net2280_alloc_buffer ( 465net2280_alloc_buffer (
482 struct usb_ep *_ep, 466 struct usb_ep *_ep,
@@ -493,43 +477,71 @@ net2280_alloc_buffer (
493 return NULL; 477 return NULL;
494 *dma = DMA_ADDR_INVALID; 478 *dma = DMA_ADDR_INVALID;
495 479
496#if defined(USE_KMALLOC) 480 if (ep->dma)
497 retval = kmalloc(bytes, gfp_flags);
498 if (retval)
499 *dma = virt_to_phys(retval);
500#else
501 if (ep->dma) {
502 /* the main problem with this call is that it wastes memory
503 * on typical 1/N page allocations: it allocates 1-N pages.
504 */
505#warning Using dma_alloc_coherent even with buffers smaller than a page.
506 retval = dma_alloc_coherent(&ep->dev->pdev->dev, 481 retval = dma_alloc_coherent(&ep->dev->pdev->dev,
507 bytes, dma, gfp_flags); 482 bytes, dma, gfp_flags);
508 } else 483 else
509 retval = kmalloc(bytes, gfp_flags); 484 retval = kmalloc(bytes, gfp_flags);
510#endif
511 return retval; 485 return retval;
512} 486}
513 487
488static DEFINE_SPINLOCK(buflock);
489static LIST_HEAD(buffers);
490
491struct free_record {
492 struct list_head list;
493 struct device *dev;
494 unsigned bytes;
495 dma_addr_t dma;
496};
497
498static void do_free(unsigned long ignored)
499{
500 spin_lock_irq(&buflock);
501 while (!list_empty(&buffers)) {
502 struct free_record *buf;
503
504 buf = list_entry(buffers.next, struct free_record, list);
505 list_del(&buf->list);
506 spin_unlock_irq(&buflock);
507
508 dma_free_coherent(buf->dev, buf->bytes, buf, buf->dma);
509
510 spin_lock_irq(&buflock);
511 }
512 spin_unlock_irq(&buflock);
513}
514
515static DECLARE_TASKLET(deferred_free, do_free, 0);
516
514static void 517static void
515net2280_free_buffer ( 518net2280_free_buffer (
516 struct usb_ep *_ep, 519 struct usb_ep *_ep,
517 void *buf, 520 void *address,
518 dma_addr_t dma, 521 dma_addr_t dma,
519 unsigned bytes 522 unsigned bytes
520) { 523) {
521 /* free memory into the right allocator */ 524 /* free memory into the right allocator */
522#ifndef USE_KMALLOC
523 if (dma != DMA_ADDR_INVALID) { 525 if (dma != DMA_ADDR_INVALID) {
524 struct net2280_ep *ep; 526 struct net2280_ep *ep;
527 struct free_record *buf = address;
528 unsigned long flags;
525 529
526 ep = container_of(_ep, struct net2280_ep, ep); 530 ep = container_of(_ep, struct net2280_ep, ep);
527 if (!_ep) 531 if (!_ep)
528 return; 532 return;
529 dma_free_coherent(&ep->dev->pdev->dev, bytes, buf, dma); 533
534 ep = container_of (_ep, struct net2280_ep, ep);
535 buf->dev = &ep->dev->pdev->dev;
536 buf->bytes = bytes;
537 buf->dma = dma;
538
539 spin_lock_irqsave(&buflock, flags);
540 list_add_tail(&buf->list, &buffers);
541 tasklet_schedule(&deferred_free);
542 spin_unlock_irqrestore(&buflock, flags);
530 } else 543 } else
531#endif 544 kfree (address);
532 kfree (buf);
533} 545}
534 546
535/*-------------------------------------------------------------------------*/ 547/*-------------------------------------------------------------------------*/
@@ -737,7 +749,8 @@ fill_dma_desc (struct net2280_ep *ep, struct net2280_request *req, int valid)
737 */ 749 */
738 if (ep->is_in) 750 if (ep->is_in)
739 dmacount |= (1 << DMA_DIRECTION); 751 dmacount |= (1 << DMA_DIRECTION);
740 if ((!ep->is_in && (dmacount % ep->ep.maxpacket) != 0) || ep->dev->pdev->device != 0x2280) 752 if ((!ep->is_in && (dmacount % ep->ep.maxpacket) != 0)
753 || ep->dev->pdev->device != 0x2280)
741 dmacount |= (1 << END_OF_CHAIN); 754 dmacount |= (1 << END_OF_CHAIN);
742 755
743 req->valid = valid; 756 req->valid = valid;
@@ -812,7 +825,7 @@ static void start_dma (struct net2280_ep *ep, struct net2280_request *req)
812 825
813 /* previous OUT packet might have been short */ 826 /* previous OUT packet might have been short */
814 if (!ep->is_in && ((tmp = readl (&ep->regs->ep_stat)) 827 if (!ep->is_in && ((tmp = readl (&ep->regs->ep_stat))
815 & (1 << NAK_OUT_PACKETS)) != 0) { 828 & (1 << NAK_OUT_PACKETS)) != 0) {
816 writel ((1 << SHORT_PACKET_TRANSFERRED_INTERRUPT), 829 writel ((1 << SHORT_PACKET_TRANSFERRED_INTERRUPT),
817 &ep->regs->ep_stat); 830 &ep->regs->ep_stat);
818 831
@@ -1373,7 +1386,7 @@ net2280_fifo_flush (struct usb_ep *_ep)
1373 (void) readl (&ep->regs->ep_rsp); 1386 (void) readl (&ep->regs->ep_rsp);
1374} 1387}
1375 1388
1376static struct usb_ep_ops net2280_ep_ops = { 1389static const struct usb_ep_ops net2280_ep_ops = {
1377 .enable = net2280_enable, 1390 .enable = net2280_enable,
1378 .disable = net2280_disable, 1391 .disable = net2280_disable,
1379 1392
@@ -1631,7 +1644,7 @@ show_registers (struct device *_dev, struct device_attribute *attr, char *buf)
1631 } 1644 }
1632 1645
1633 /* Indexed Registers */ 1646 /* Indexed Registers */
1634 // none yet 1647 // none yet
1635 1648
1636 /* Statistics */ 1649 /* Statistics */
1637 t = scnprintf (next, size, "\nirqs: "); 1650 t = scnprintf (next, size, "\nirqs: ");
@@ -1691,11 +1704,11 @@ show_queues (struct device *_dev, struct device_attribute *attr, char *buf)
1691 ({ char *val; 1704 ({ char *val;
1692 switch (d->bmAttributes & 0x03) { 1705 switch (d->bmAttributes & 0x03) {
1693 case USB_ENDPOINT_XFER_BULK: 1706 case USB_ENDPOINT_XFER_BULK:
1694 val = "bulk"; break; 1707 val = "bulk"; break;
1695 case USB_ENDPOINT_XFER_INT: 1708 case USB_ENDPOINT_XFER_INT:
1696 val = "intr"; break; 1709 val = "intr"; break;
1697 default: 1710 default:
1698 val = "iso"; break; 1711 val = "iso"; break;
1699 }; val; }), 1712 }; val; }),
1700 le16_to_cpu (d->wMaxPacketSize) & 0x1fff, 1713 le16_to_cpu (d->wMaxPacketSize) & 0x1fff,
1701 ep->dma ? "dma" : "pio", ep->fifo_size 1714 ep->dma ? "dma" : "pio", ep->fifo_size
@@ -1808,8 +1821,8 @@ extern int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode);
1808 * net2280_set_fifo_mode - change allocation of fifo buffers 1821 * net2280_set_fifo_mode - change allocation of fifo buffers
1809 * @gadget: access to the net2280 device that will be updated 1822 * @gadget: access to the net2280 device that will be updated
1810 * @mode: 0 for default, four 1kB buffers (ep-a through ep-d); 1823 * @mode: 0 for default, four 1kB buffers (ep-a through ep-d);
1811 * 1 for two 2kB buffers (ep-a and ep-b only); 1824 * 1 for two 2kB buffers (ep-a and ep-b only);
1812 * 2 for one 2kB buffer (ep-a) and two 1kB ones (ep-b, ep-c). 1825 * 2 for one 2kB buffer (ep-a) and two 1kB ones (ep-b, ep-c).
1813 * 1826 *
1814 * returns zero on success, else negative errno. when this succeeds, 1827 * returns zero on success, else negative errno. when this succeeds,
1815 * the contents of gadget->ep_list may have changed. 1828 * the contents of gadget->ep_list may have changed.
@@ -2241,7 +2254,8 @@ static void handle_ep_small (struct net2280_ep *ep)
2241 req->td->dmacount = 0; 2254 req->td->dmacount = 0;
2242 t = readl (&ep->regs->ep_avail); 2255 t = readl (&ep->regs->ep_avail);
2243 dma_done (ep, req, count, 2256 dma_done (ep, req, count,
2244 (ep->out_overflow || t) ? -EOVERFLOW : 0); 2257 (ep->out_overflow || t)
2258 ? -EOVERFLOW : 0);
2245 } 2259 }
2246 2260
2247 /* also flush to prevent erratum 0106 trouble */ 2261 /* also flush to prevent erratum 0106 trouble */
@@ -2411,7 +2425,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2411 , &ep->regs->ep_stat); 2425 , &ep->regs->ep_stat);
2412 u.raw [0] = readl (&dev->usb->setup0123); 2426 u.raw [0] = readl (&dev->usb->setup0123);
2413 u.raw [1] = readl (&dev->usb->setup4567); 2427 u.raw [1] = readl (&dev->usb->setup4567);
2414 2428
2415 cpu_to_le32s (&u.raw [0]); 2429 cpu_to_le32s (&u.raw [0]);
2416 cpu_to_le32s (&u.raw [1]); 2430 cpu_to_le32s (&u.raw [1]);
2417 2431
@@ -2578,14 +2592,16 @@ static void handle_stat1_irqs (struct net2280 *dev, u32 stat)
2578 2592
2579 /* VBUS disconnect is indicated by VBUS_PIN and VBUS_INTERRUPT set. 2593 /* VBUS disconnect is indicated by VBUS_PIN and VBUS_INTERRUPT set.
2580 * Root Port Reset is indicated by ROOT_PORT_RESET_INTERRRUPT set and 2594 * Root Port Reset is indicated by ROOT_PORT_RESET_INTERRRUPT set and
2581 * both HIGH_SPEED and FULL_SPEED clear (as ROOT_PORT_RESET_INTERRUPT 2595 * both HIGH_SPEED and FULL_SPEED clear (as ROOT_PORT_RESET_INTERRUPT
2582 * only indicates a change in the reset state). 2596 * only indicates a change in the reset state).
2583 */ 2597 */
2584 if (stat & tmp) { 2598 if (stat & tmp) {
2585 writel (tmp, &dev->regs->irqstat1); 2599 writel (tmp, &dev->regs->irqstat1);
2586 if ((((stat & (1 << ROOT_PORT_RESET_INTERRUPT)) && 2600 if ((((stat & (1 << ROOT_PORT_RESET_INTERRUPT))
2587 ((readl (&dev->usb->usbstat) & mask) == 0)) 2601 && ((readl (&dev->usb->usbstat) & mask)
2588 || ((readl (&dev->usb->usbctl) & (1 << VBUS_PIN)) == 0) 2602 == 0))
2603 || ((readl (&dev->usb->usbctl)
2604 & (1 << VBUS_PIN)) == 0)
2589 ) && ( dev->gadget.speed != USB_SPEED_UNKNOWN)) { 2605 ) && ( dev->gadget.speed != USB_SPEED_UNKNOWN)) {
2590 DEBUG (dev, "disconnect %s\n", 2606 DEBUG (dev, "disconnect %s\n",
2591 dev->driver->driver.name); 2607 dev->driver->driver.name);
@@ -2852,7 +2868,7 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2852 2868
2853 /* now all the pci goodies ... */ 2869 /* now all the pci goodies ... */
2854 if (pci_enable_device (pdev) < 0) { 2870 if (pci_enable_device (pdev) < 0) {
2855 retval = -ENODEV; 2871 retval = -ENODEV;
2856 goto done; 2872 goto done;
2857 } 2873 }
2858 dev->enabled = 1; 2874 dev->enabled = 1;
@@ -2870,6 +2886,10 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2870 } 2886 }
2871 dev->region = 1; 2887 dev->region = 1;
2872 2888
2889 /* FIXME provide firmware download interface to put
2890 * 8051 code into the chip, e.g. to turn on PCI PM.
2891 */
2892
2873 base = ioremap_nocache (resource, len); 2893 base = ioremap_nocache (resource, len);
2874 if (base == NULL) { 2894 if (base == NULL) {
2875 DEBUG (dev, "can't map memory\n"); 2895 DEBUG (dev, "can't map memory\n");
@@ -2984,16 +3004,16 @@ static void net2280_shutdown (struct pci_dev *pdev)
2984 3004
2985/*-------------------------------------------------------------------------*/ 3005/*-------------------------------------------------------------------------*/
2986 3006
2987static struct pci_device_id pci_ids [] = { { 3007static const struct pci_device_id pci_ids [] = { {
2988 .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe), 3008 .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
2989 .class_mask = ~0, 3009 .class_mask = ~0,
2990 .vendor = 0x17cc, 3010 .vendor = 0x17cc,
2991 .device = 0x2280, 3011 .device = 0x2280,
2992 .subvendor = PCI_ANY_ID, 3012 .subvendor = PCI_ANY_ID,
2993 .subdevice = PCI_ANY_ID, 3013 .subdevice = PCI_ANY_ID,
2994}, { 3014}, {
2995 .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe), 3015 .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
2996 .class_mask = ~0, 3016 .class_mask = ~0,
2997 .vendor = 0x17cc, 3017 .vendor = 0x17cc,
2998 .device = 0x2282, 3018 .device = 0x2282,
2999 .subvendor = PCI_ANY_ID, 3019 .subvendor = PCI_ANY_ID,
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index 2de9748ee673..8c18df869833 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -40,7 +40,7 @@
40#include <linux/platform_device.h> 40#include <linux/platform_device.h>
41#include <linux/usb_ch9.h> 41#include <linux/usb_ch9.h>
42#include <linux/usb_gadget.h> 42#include <linux/usb_gadget.h>
43#include <linux/usb_otg.h> 43#include <linux/usb/otg.h>
44#include <linux/dma-mapping.h> 44#include <linux/dma-mapping.h>
45 45
46#include <asm/byteorder.h> 46#include <asm/byteorder.h>
@@ -2437,7 +2437,7 @@ static int proc_udc_open(struct inode *inode, struct file *file)
2437 return single_open(file, proc_udc_show, NULL); 2437 return single_open(file, proc_udc_show, NULL);
2438} 2438}
2439 2439
2440static struct file_operations proc_ops = { 2440static const struct file_operations proc_ops = {
2441 .open = proc_udc_open, 2441 .open = proc_udc_open,
2442 .read = seq_read, 2442 .read = seq_read,
2443 .llseek = seq_lseek, 2443 .llseek = seq_lseek,
@@ -2869,7 +2869,7 @@ cleanup0:
2869 2869
2870static int __exit omap_udc_remove(struct platform_device *pdev) 2870static int __exit omap_udc_remove(struct platform_device *pdev)
2871{ 2871{
2872 DECLARE_COMPLETION(done); 2872 DECLARE_COMPLETION_ONSTACK(done);
2873 2873
2874 if (!udc) 2874 if (!udc)
2875 return -ENODEV; 2875 return -ENODEV;
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
index fff027d30a09..f1adcf8b2023 100644
--- a/drivers/usb/gadget/pxa2xx_udc.c
+++ b/drivers/usb/gadget/pxa2xx_udc.c
@@ -150,6 +150,39 @@ MODULE_PARM_DESC (fifo_mode, "pxa2xx udc fifo mode");
150static void pxa2xx_ep_fifo_flush (struct usb_ep *ep); 150static void pxa2xx_ep_fifo_flush (struct usb_ep *ep);
151static void nuke (struct pxa2xx_ep *, int status); 151static void nuke (struct pxa2xx_ep *, int status);
152 152
153/* one GPIO should be used to detect VBUS from the host */
154static int is_vbus_present(void)
155{
156 struct pxa2xx_udc_mach_info *mach = the_controller->mach;
157
158 if (mach->gpio_vbus)
159 return pxa_gpio_get(mach->gpio_vbus);
160 if (mach->udc_is_connected)
161 return mach->udc_is_connected();
162 return 1;
163}
164
165/* one GPIO should control a D+ pullup, so host sees this device (or not) */
166static void pullup_off(void)
167{
168 struct pxa2xx_udc_mach_info *mach = the_controller->mach;
169
170 if (mach->gpio_pullup)
171 pxa_gpio_set(mach->gpio_pullup, 0);
172 else if (mach->udc_command)
173 mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
174}
175
176static void pullup_on(void)
177{
178 struct pxa2xx_udc_mach_info *mach = the_controller->mach;
179
180 if (mach->gpio_pullup)
181 pxa_gpio_set(mach->gpio_pullup, 1);
182 else if (mach->udc_command)
183 mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
184}
185
153static void pio_irq_enable(int bEndpointAddress) 186static void pio_irq_enable(int bEndpointAddress)
154{ 187{
155 bEndpointAddress &= 0xf; 188 bEndpointAddress &= 0xf;
@@ -1721,6 +1754,16 @@ lubbock_vbus_irq(int irq, void *_dev, struct pt_regs *r)
1721 1754
1722#endif 1755#endif
1723 1756
1757static irqreturn_t
1758udc_vbus_irq(int irq, void *_dev, struct pt_regs *r)
1759{
1760 struct pxa2xx_udc *dev = _dev;
1761 int vbus = pxa_gpio_get(dev->mach->gpio_vbus);
1762
1763 pxa2xx_udc_vbus_session(&dev->gadget, vbus);
1764 return IRQ_HANDLED;
1765}
1766
1724 1767
1725/*-------------------------------------------------------------------------*/ 1768/*-------------------------------------------------------------------------*/
1726 1769
@@ -2438,7 +2481,7 @@ static struct pxa2xx_udc memory = {
2438static int __init pxa2xx_udc_probe(struct platform_device *pdev) 2481static int __init pxa2xx_udc_probe(struct platform_device *pdev)
2439{ 2482{
2440 struct pxa2xx_udc *dev = &memory; 2483 struct pxa2xx_udc *dev = &memory;
2441 int retval, out_dma = 1; 2484 int retval, out_dma = 1, vbus_irq;
2442 u32 chiprev; 2485 u32 chiprev;
2443 2486
2444 /* insist on Intel/ARM/XScale */ 2487 /* insist on Intel/ARM/XScale */
@@ -2502,6 +2545,16 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
2502 /* other non-static parts of init */ 2545 /* other non-static parts of init */
2503 dev->dev = &pdev->dev; 2546 dev->dev = &pdev->dev;
2504 dev->mach = pdev->dev.platform_data; 2547 dev->mach = pdev->dev.platform_data;
2548 if (dev->mach->gpio_vbus) {
2549 vbus_irq = IRQ_GPIO(dev->mach->gpio_vbus & GPIO_MD_MASK_NR);
2550 pxa_gpio_mode((dev->mach->gpio_vbus & GPIO_MD_MASK_NR)
2551 | GPIO_IN);
2552 set_irq_type(vbus_irq, IRQT_BOTHEDGE);
2553 } else
2554 vbus_irq = 0;
2555 if (dev->mach->gpio_pullup)
2556 pxa_gpio_mode((dev->mach->gpio_pullup & GPIO_MD_MASK_NR)
2557 | GPIO_OUT | GPIO_DFLT_LOW);
2505 2558
2506 init_timer(&dev->timer); 2559 init_timer(&dev->timer);
2507 dev->timer.function = udc_watchdog; 2560 dev->timer.function = udc_watchdog;
@@ -2557,8 +2610,19 @@ lubbock_fail0:
2557 HEX_DISPLAY(dev->stats.irqs); 2610 HEX_DISPLAY(dev->stats.irqs);
2558 LUB_DISC_BLNK_LED &= 0xff; 2611 LUB_DISC_BLNK_LED &= 0xff;
2559#endif 2612#endif
2560 } 2613 } else
2561#endif 2614#endif
2615 if (vbus_irq) {
2616 retval = request_irq(vbus_irq, udc_vbus_irq,
2617 SA_INTERRUPT | SA_SAMPLE_RANDOM,
2618 driver_name, dev);
2619 if (retval != 0) {
2620 printk(KERN_ERR "%s: can't get irq %i, err %d\n",
2621 driver_name, vbus_irq, retval);
2622 free_irq(IRQ_USB, dev);
2623 return -EBUSY;
2624 }
2625 }
2562 create_proc_files(); 2626 create_proc_files();
2563 2627
2564 return 0; 2628 return 0;
@@ -2587,6 +2651,8 @@ static int __exit pxa2xx_udc_remove(struct platform_device *pdev)
2587 free_irq(LUBBOCK_USB_IRQ, dev); 2651 free_irq(LUBBOCK_USB_IRQ, dev);
2588 } 2652 }
2589#endif 2653#endif
2654 if (dev->mach->gpio_vbus)
2655 free_irq(IRQ_GPIO(dev->mach->gpio_vbus), dev);
2590 platform_set_drvdata(pdev, NULL); 2656 platform_set_drvdata(pdev, NULL);
2591 the_controller = NULL; 2657 the_controller = NULL;
2592 return 0; 2658 return 0;
diff --git a/drivers/usb/gadget/pxa2xx_udc.h b/drivers/usb/gadget/pxa2xx_udc.h
index 19a883f7d1b8..8e598c8bf4e3 100644
--- a/drivers/usb/gadget/pxa2xx_udc.h
+++ b/drivers/usb/gadget/pxa2xx_udc.h
@@ -177,27 +177,19 @@ 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 VBUS from the host */ 180static inline int pxa_gpio_get(unsigned gpio)
181static inline int is_vbus_present(void)
182{ 181{
183 if (!the_controller->mach->udc_is_connected) 182 return (GPLR(gpio) & GPIO_bit(gpio)) != 0;
184 return 1;
185 return the_controller->mach->udc_is_connected();
186} 183}
187 184
188/* one GPIO should control a D+ pullup, so host sees this device (or not) */ 185static inline void pxa_gpio_set(unsigned gpio, int is_on)
189static inline void pullup_off(void)
190{ 186{
191 if (!the_controller->mach->udc_command) 187 int mask = GPIO_bit(gpio);
192 return;
193 the_controller->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
194}
195 188
196static inline void pullup_on(void) 189 if (is_on)
197{ 190 GPSR(gpio) = mask;
198 if (!the_controller->mach->udc_command) 191 else
199 return; 192 GPCR(gpio) = mask;
200 the_controller->mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
201} 193}
202 194
203/*-------------------------------------------------------------------------*/ 195/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index e762aa19ab0a..208e55a667ac 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -271,7 +271,7 @@ static unsigned int use_acm = GS_DEFAULT_USE_ACM;
271 271
272 272
273/* tty driver struct */ 273/* tty driver struct */
274static struct tty_operations gs_tty_ops = { 274static const struct tty_operations gs_tty_ops = {
275 .open = gs_open, 275 .open = gs_open,
276 .close = gs_close, 276 .close = gs_close,
277 .write = gs_write, 277 .write = gs_write,
@@ -1120,12 +1120,15 @@ static int gs_send(struct gs_dev *dev)
1120gs_debug_level(3, "gs_send: len=%d, 0x%2.2x 0x%2.2x 0x%2.2x ...\n", len, *((unsigned char *)req->buf), *((unsigned char *)req->buf+1), *((unsigned char *)req->buf+2)); 1120gs_debug_level(3, "gs_send: len=%d, 0x%2.2x 0x%2.2x 0x%2.2x ...\n", len, *((unsigned char *)req->buf), *((unsigned char *)req->buf+1), *((unsigned char *)req->buf+2));
1121 list_del(&req_entry->re_entry); 1121 list_del(&req_entry->re_entry);
1122 req->length = len; 1122 req->length = len;
1123 spin_unlock_irqrestore(&dev->dev_lock, flags);
1123 if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) { 1124 if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) {
1124 printk(KERN_ERR 1125 printk(KERN_ERR
1125 "gs_send: cannot queue read request, ret=%d\n", 1126 "gs_send: cannot queue read request, ret=%d\n",
1126 ret); 1127 ret);
1128 spin_lock_irqsave(&dev->dev_lock, flags);
1127 break; 1129 break;
1128 } 1130 }
1131 spin_lock_irqsave(&dev->dev_lock, flags);
1129 } else { 1132 } else {
1130 break; 1133 break;
1131 } 1134 }
@@ -1431,7 +1434,7 @@ static int __init gs_bind(struct usb_gadget *gadget)
1431 return -ENOMEM; 1434 return -ENOMEM;
1432 1435
1433 snprintf(manufacturer, sizeof(manufacturer), "%s %s with %s", 1436 snprintf(manufacturer, sizeof(manufacturer), "%s %s with %s",
1434 system_utsname.sysname, system_utsname.release, 1437 init_utsname()->sysname, init_utsname()->release,
1435 gadget->name); 1438 gadget->name);
1436 1439
1437 memset(dev, 0, sizeof(struct gs_dev)); 1440 memset(dev, 0, sizeof(struct gs_dev));
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index b7018ee487ea..0f809dd68492 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -1242,7 +1242,7 @@ autoconf_fail:
1242 EP_OUT_NAME, EP_IN_NAME); 1242 EP_OUT_NAME, EP_IN_NAME);
1243 1243
1244 snprintf (manufacturer, sizeof manufacturer, "%s %s with %s", 1244 snprintf (manufacturer, sizeof manufacturer, "%s %s with %s",
1245 system_utsname.sysname, system_utsname.release, 1245 init_utsname()->sysname, init_utsname()->release,
1246 gadget->name); 1246 gadget->name);
1247 1247
1248 return 0; 1248 return 0;
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index b93d71d28db7..cf10cbc98f80 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -83,6 +83,7 @@ config USB_OHCI_HCD
83 tristate "OHCI HCD support" 83 tristate "OHCI HCD support"
84 depends on USB && USB_ARCH_HAS_OHCI 84 depends on USB && USB_ARCH_HAS_OHCI
85 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 85 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3
86 select I2C if ARCH_PNX4008
86 ---help--- 87 ---help---
87 The Open Host Controller Interface (OHCI) is a standard for accessing 88 The Open Host Controller Interface (OHCI) is a standard for accessing
88 USB 1.1 host controller hardware. It does more in hardware than Intel's 89 USB 1.1 host controller hardware. It does more in hardware than Intel's
@@ -141,6 +142,34 @@ config USB_UHCI_HCD
141 To compile this driver as a module, choose M here: the 142 To compile this driver as a module, choose M here: the
142 module will be called uhci-hcd. 143 module will be called uhci-hcd.
143 144
145config USB_U132_HCD
146 tristate "Elan U132 Adapter Host Controller"
147 depends on USB && USB_FTDI_ELAN
148 default M
149 help
150 The U132 adapter is a USB to CardBus adapter specifically designed
151 for PC cards that contain an OHCI host controller. Typical PC cards
152 are the Orange Mobile 3G Option GlobeTrotter Fusion card. The U132
153 adapter will *NOT* work with PC cards that do not contain an OHCI
154 controller.
155
156 For those PC cards that contain multiple OHCI controllers only ther
157 first one is used.
158
159 The driver consists of two modules, the "ftdi-elan" module is a
160 USB client driver that interfaces to the FTDI chip within ELAN's
161 USB-to-PCMCIA adapter, and this "u132-hcd" module is a USB host
162 controller driver that talks to the OHCI controller within the
163 CardBus cards that are inserted in the U132 adapter.
164
165 This driver has been tested with a CardBus OHCI USB adapter, and
166 worked with a USB PEN Drive inserted into the first USB port of
167 the PCCARD. A rather pointless thing to do, but useful for testing.
168
169 It is safe to say M here.
170
171 See also <http://www.elandigitalsystems.com/support/ufaq/u132linux.php>
172
144config USB_SL811_HCD 173config USB_SL811_HCD
145 tristate "SL811HS HCD support" 174 tristate "SL811HS HCD support"
146 depends on USB 175 depends on USB
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index e3020f4b17be..a2e58c86849f 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -14,4 +14,5 @@ obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o
14obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o 14obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o
15obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o 15obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o
16obj-$(CONFIG_USB_SL811_CS) += sl811_cs.o 16obj-$(CONFIG_USB_SL811_CS) += sl811_cs.o
17obj-$(CONFIG_USB_U132_HCD) += u132-hcd.o
17obj-$(CONFIG_ETRAX_ARCH_V10) += hc_crisv10.o 18obj-$(CONFIG_ETRAX_ARCH_V10) += hc_crisv10.o
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c
index 26ed757d22a6..5d1b12aad776 100644
--- a/drivers/usb/host/ehci-au1xxx.c
+++ b/drivers/usb/host/ehci-au1xxx.c
@@ -200,6 +200,7 @@ static const struct hc_driver ehci_au1xxx_hc_driver = {
200 .reset = ehci_init, 200 .reset = ehci_init,
201 .start = ehci_run, 201 .start = ehci_run,
202 .stop = ehci_stop, 202 .stop = ehci_stop,
203 .shutdown = ehci_shutdown,
203 204
204 /* 205 /*
205 * managing i/o requests and associated device resources 206 * managing i/o requests and associated device resources
@@ -268,6 +269,7 @@ MODULE_ALIAS("au1xxx-ehci");
268static struct platform_driver ehci_hcd_au1xxx_driver = { 269static struct platform_driver ehci_hcd_au1xxx_driver = {
269 .probe = ehci_hcd_au1xxx_drv_probe, 270 .probe = ehci_hcd_au1xxx_drv_probe,
270 .remove = ehci_hcd_au1xxx_drv_remove, 271 .remove = ehci_hcd_au1xxx_drv_remove,
272 .shutdown = usb_hcd_platform_shutdown,
271 /*.suspend = ehci_hcd_au1xxx_drv_suspend, */ 273 /*.suspend = ehci_hcd_au1xxx_drv_suspend, */
272 /*.resume = ehci_hcd_au1xxx_drv_resume, */ 274 /*.resume = ehci_hcd_au1xxx_drv_resume, */
273 .driver = { 275 .driver = {
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 65ac9fef3a7c..23b95b2bfe15 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (c) 2001-2002 by David Brownell 2 * Copyright (c) 2001-2002 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
6 * Free Software Foundation; either version 2 of the License, or (at your 6 * Free Software Foundation; either version 2 of the License, or (at your
@@ -65,7 +65,7 @@ static void dbg_hcs_params (struct ehci_hcd *ehci, char *label)
65 for (i = 0; i < HCS_N_PORTS (params); i++) { 65 for (i = 0; i < HCS_N_PORTS (params); i++) {
66 // FIXME MIPS won't readb() ... 66 // FIXME MIPS won't readb() ...
67 byte = readb (&ehci->caps->portroute[(i>>1)]); 67 byte = readb (&ehci->caps->portroute[(i>>1)]);
68 sprintf(tmp, "%d ", 68 sprintf(tmp, "%d ",
69 ((i & 0x1) ? ((byte)&0xf) : ((byte>>4)&0xf))); 69 ((i & 0x1) ? ((byte)&0xf) : ((byte>>4)&0xf)));
70 strcat(buf, tmp); 70 strcat(buf, tmp);
71 } 71 }
@@ -141,12 +141,12 @@ dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
141} 141}
142 142
143static void __attribute__((__unused__)) 143static void __attribute__((__unused__))
144dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd) 144dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
145{ 145{
146 ehci_dbg (ehci, "%s [%d] itd %p, next %08x, urb %p\n", 146 ehci_dbg (ehci, "%s [%d] itd %p, next %08x, urb %p\n",
147 label, itd->frame, itd, le32_to_cpu(itd->hw_next), itd->urb); 147 label, itd->frame, itd, le32_to_cpu(itd->hw_next), itd->urb);
148 ehci_dbg (ehci, 148 ehci_dbg (ehci,
149 " trans: %08x %08x %08x %08x %08x %08x %08x %08x\n", 149 " trans: %08x %08x %08x %08x %08x %08x %08x %08x\n",
150 le32_to_cpu(itd->hw_transaction[0]), 150 le32_to_cpu(itd->hw_transaction[0]),
151 le32_to_cpu(itd->hw_transaction[1]), 151 le32_to_cpu(itd->hw_transaction[1]),
152 le32_to_cpu(itd->hw_transaction[2]), 152 le32_to_cpu(itd->hw_transaction[2]),
@@ -156,7 +156,7 @@ dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
156 le32_to_cpu(itd->hw_transaction[6]), 156 le32_to_cpu(itd->hw_transaction[6]),
157 le32_to_cpu(itd->hw_transaction[7])); 157 le32_to_cpu(itd->hw_transaction[7]));
158 ehci_dbg (ehci, 158 ehci_dbg (ehci,
159 " buf: %08x %08x %08x %08x %08x %08x %08x\n", 159 " buf: %08x %08x %08x %08x %08x %08x %08x\n",
160 le32_to_cpu(itd->hw_bufp[0]), 160 le32_to_cpu(itd->hw_bufp[0]),
161 le32_to_cpu(itd->hw_bufp[1]), 161 le32_to_cpu(itd->hw_bufp[1]),
162 le32_to_cpu(itd->hw_bufp[2]), 162 le32_to_cpu(itd->hw_bufp[2]),
@@ -171,12 +171,12 @@ dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
171} 171}
172 172
173static void __attribute__((__unused__)) 173static void __attribute__((__unused__))
174dbg_sitd (const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd) 174dbg_sitd (const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd)
175{ 175{
176 ehci_dbg (ehci, "%s [%d] sitd %p, next %08x, urb %p\n", 176 ehci_dbg (ehci, "%s [%d] sitd %p, next %08x, urb %p\n",
177 label, sitd->frame, sitd, le32_to_cpu(sitd->hw_next), sitd->urb); 177 label, sitd->frame, sitd, le32_to_cpu(sitd->hw_next), sitd->urb);
178 ehci_dbg (ehci, 178 ehci_dbg (ehci,
179 " addr %08x sched %04x result %08x buf %08x %08x\n", 179 " addr %08x sched %04x result %08x buf %08x %08x\n",
180 le32_to_cpu(sitd->hw_fullspeed_ep), 180 le32_to_cpu(sitd->hw_fullspeed_ep),
181 le32_to_cpu(sitd->hw_uframe), 181 le32_to_cpu(sitd->hw_uframe),
182 le32_to_cpu(sitd->hw_results), 182 le32_to_cpu(sitd->hw_results),
@@ -451,7 +451,7 @@ show_async (struct class_device *class_dev, char *buf)
451 *buf = 0; 451 *buf = 0;
452 452
453 bus = class_get_devdata(class_dev); 453 bus = class_get_devdata(class_dev);
454 hcd = bus->hcpriv; 454 hcd = bus_to_hcd(bus);
455 ehci = hcd_to_ehci (hcd); 455 ehci = hcd_to_ehci (hcd);
456 next = buf; 456 next = buf;
457 size = PAGE_SIZE; 457 size = PAGE_SIZE;
@@ -497,7 +497,7 @@ show_periodic (struct class_device *class_dev, char *buf)
497 seen_count = 0; 497 seen_count = 0;
498 498
499 bus = class_get_devdata(class_dev); 499 bus = class_get_devdata(class_dev);
500 hcd = bus->hcpriv; 500 hcd = bus_to_hcd(bus);
501 ehci = hcd_to_ehci (hcd); 501 ehci = hcd_to_ehci (hcd);
502 next = buf; 502 next = buf;
503 size = PAGE_SIZE; 503 size = PAGE_SIZE;
@@ -634,7 +634,7 @@ show_registers (struct class_device *class_dev, char *buf)
634 static char label [] = ""; 634 static char label [] = "";
635 635
636 bus = class_get_devdata(class_dev); 636 bus = class_get_devdata(class_dev);
637 hcd = bus->hcpriv; 637 hcd = bus_to_hcd(bus);
638 ehci = hcd_to_ehci (hcd); 638 ehci = hcd_to_ehci (hcd);
639 next = buf; 639 next = buf;
640 size = PAGE_SIZE; 640 size = PAGE_SIZE;
@@ -754,9 +754,7 @@ show_registers (struct class_device *class_dev, char *buf)
754 } 754 }
755 755
756 if (ehci->reclaim) { 756 if (ehci->reclaim) {
757 temp = scnprintf (next, size, "reclaim qh %p%s\n", 757 temp = scnprintf (next, size, "reclaim qh %p\n", ehci->reclaim);
758 ehci->reclaim,
759 ehci->reclaim_ready ? " ready" : "");
760 size -= temp; 758 size -= temp;
761 next += temp; 759 next += temp;
762 } 760 }
@@ -785,10 +783,11 @@ static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
785static inline void create_debug_files (struct ehci_hcd *ehci) 783static inline void create_debug_files (struct ehci_hcd *ehci)
786{ 784{
787 struct class_device *cldev = ehci_to_hcd(ehci)->self.class_dev; 785 struct class_device *cldev = ehci_to_hcd(ehci)->self.class_dev;
786 int retval;
788 787
789 class_device_create_file(cldev, &class_device_attr_async); 788 retval = class_device_create_file(cldev, &class_device_attr_async);
790 class_device_create_file(cldev, &class_device_attr_periodic); 789 retval = class_device_create_file(cldev, &class_device_attr_periodic);
791 class_device_create_file(cldev, &class_device_attr_registers); 790 retval = class_device_create_file(cldev, &class_device_attr_registers);
792} 791}
793 792
794static inline void remove_debug_files (struct ehci_hcd *ehci) 793static inline void remove_debug_files (struct ehci_hcd *ehci)
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index d030516edfb9..1a915e982c1c 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -285,6 +285,7 @@ static const struct hc_driver ehci_fsl_hc_driver = {
285 .resume = ehci_bus_resume, 285 .resume = ehci_bus_resume,
286#endif 286#endif
287 .stop = ehci_stop, 287 .stop = ehci_stop,
288 .shutdown = ehci_shutdown,
288 289
289 /* 290 /*
290 * managing i/o requests and associated device resources 291 * managing i/o requests and associated device resources
@@ -329,6 +330,7 @@ MODULE_ALIAS("fsl-ehci");
329static struct platform_driver ehci_fsl_driver = { 330static struct platform_driver ehci_fsl_driver = {
330 .probe = ehci_fsl_drv_probe, 331 .probe = ehci_fsl_drv_probe,
331 .remove = ehci_fsl_drv_remove, 332 .remove = ehci_fsl_drv_remove,
333 .shutdown = usb_hcd_platform_shutdown,
332 .driver = { 334 .driver = {
333 .name = "fsl-ehci", 335 .name = "fsl-ehci",
334 }, 336 },
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index d63177a8eaea..5ac918591131 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (c) 2000-2004 by David Brownell 2 * Copyright (c) 2000-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
6 * Free Software Foundation; either version 2 of the License, or (at your 6 * Free Software Foundation; either version 2 of the License, or (at your
@@ -70,7 +70,7 @@
70 * 2002-08-06 Handling for bulk and interrupt transfers is mostly shared; 70 * 2002-08-06 Handling for bulk and interrupt transfers is mostly shared;
71 * only scheduling is different, no arbitrary limitations. 71 * only scheduling is different, no arbitrary limitations.
72 * 2002-07-25 Sanity check PCI reads, mostly for better cardbus support, 72 * 2002-07-25 Sanity check PCI reads, mostly for better cardbus support,
73 * clean up HC run state handshaking. 73 * clean up HC run state handshaking.
74 * 2002-05-24 Preliminary FS/LS interrupts, using scheduling shortcuts 74 * 2002-05-24 Preliminary FS/LS interrupts, using scheduling shortcuts
75 * 2002-05-11 Clear TT errors for FS/LS ctrl/bulk. Fill in some other 75 * 2002-05-11 Clear TT errors for FS/LS ctrl/bulk. Fill in some other
76 * missing pieces: enabling 64bit dma, handoff from BIOS/SMM. 76 * missing pieces: enabling 64bit dma, handoff from BIOS/SMM.
@@ -111,7 +111,7 @@ static const char hcd_name [] = "ehci_hcd";
111#define EHCI_TUNE_MULT_TT 1 111#define EHCI_TUNE_MULT_TT 1
112#define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */ 112#define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */
113 113
114#define EHCI_IAA_JIFFIES (HZ/100) /* arbitrary; ~10 msec */ 114#define EHCI_IAA_MSECS 10 /* arbitrary */
115#define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */ 115#define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */
116#define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */ 116#define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */
117#define EHCI_SHRINK_JIFFIES (HZ/200) /* async qh unlink delay */ 117#define EHCI_SHRINK_JIFFIES (HZ/200) /* async qh unlink delay */
@@ -254,6 +254,7 @@ static void ehci_quiesce (struct ehci_hcd *ehci)
254 254
255/*-------------------------------------------------------------------------*/ 255/*-------------------------------------------------------------------------*/
256 256
257static void end_unlink_async (struct ehci_hcd *ehci, struct pt_regs *regs);
257static void ehci_work(struct ehci_hcd *ehci, struct pt_regs *regs); 258static void ehci_work(struct ehci_hcd *ehci, struct pt_regs *regs);
258 259
259#include "ehci-hub.c" 260#include "ehci-hub.c"
@@ -263,28 +264,39 @@ static void ehci_work(struct ehci_hcd *ehci, struct pt_regs *regs);
263 264
264/*-------------------------------------------------------------------------*/ 265/*-------------------------------------------------------------------------*/
265 266
266static void ehci_watchdog (unsigned long param) 267static void ehci_iaa_watchdog (unsigned long param)
267{ 268{
268 struct ehci_hcd *ehci = (struct ehci_hcd *) param; 269 struct ehci_hcd *ehci = (struct ehci_hcd *) param;
269 unsigned long flags; 270 unsigned long flags;
271 u32 status;
270 272
271 spin_lock_irqsave (&ehci->lock, flags); 273 spin_lock_irqsave (&ehci->lock, flags);
274 WARN_ON(!ehci->reclaim);
272 275
273 /* lost IAA irqs wedge things badly; seen with a vt8235 */ 276 /* lost IAA irqs wedge things badly; seen first with a vt8235 */
274 if (ehci->reclaim) { 277 if (ehci->reclaim) {
275 u32 status = readl (&ehci->regs->status); 278 status = readl (&ehci->regs->status);
276
277 if (status & STS_IAA) { 279 if (status & STS_IAA) {
278 ehci_vdbg (ehci, "lost IAA\n"); 280 ehci_vdbg (ehci, "lost IAA\n");
279 COUNT (ehci->stats.lost_iaa); 281 COUNT (ehci->stats.lost_iaa);
280 writel (STS_IAA, &ehci->regs->status); 282 writel (STS_IAA, &ehci->regs->status);
281 ehci->reclaim_ready = 1; 283 end_unlink_async (ehci, NULL);
282 } 284 }
283 } 285 }
284 286
285 /* stop async processing after it's idled a bit */ 287 spin_unlock_irqrestore (&ehci->lock, flags);
288}
289
290static void ehci_watchdog (unsigned long param)
291{
292 struct ehci_hcd *ehci = (struct ehci_hcd *) param;
293 unsigned long flags;
294
295 spin_lock_irqsave (&ehci->lock, flags);
296
297 /* stop async processing after it's idled a bit */
286 if (test_bit (TIMER_ASYNC_OFF, &ehci->actions)) 298 if (test_bit (TIMER_ASYNC_OFF, &ehci->actions))
287 start_unlink_async (ehci, ehci->async); 299 start_unlink_async (ehci, ehci->async);
288 300
289 /* ehci could run by timer, without IRQs ... */ 301 /* ehci could run by timer, without IRQs ... */
290 ehci_work (ehci, NULL); 302 ehci_work (ehci, NULL);
@@ -292,21 +304,20 @@ static void ehci_watchdog (unsigned long param)
292 spin_unlock_irqrestore (&ehci->lock, flags); 304 spin_unlock_irqrestore (&ehci->lock, flags);
293} 305}
294 306
295/* Reboot notifiers kick in for silicon on any bus (not just pci, etc). 307/* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
296 * This forcibly disables dma and IRQs, helping kexec and other cases 308 * This forcibly disables dma and IRQs, helping kexec and other cases
297 * where the next system software may expect clean state. 309 * where the next system software may expect clean state.
298 */ 310 */
299static int 311static void
300ehci_reboot (struct notifier_block *self, unsigned long code, void *null) 312ehci_shutdown (struct usb_hcd *hcd)
301{ 313{
302 struct ehci_hcd *ehci; 314 struct ehci_hcd *ehci;
303 315
304 ehci = container_of (self, struct ehci_hcd, reboot_notifier); 316 ehci = hcd_to_ehci (hcd);
305 (void) ehci_halt (ehci); 317 (void) ehci_halt (ehci);
306 318
307 /* make BIOS/etc use companion controller during reboot */ 319 /* make BIOS/etc use companion controller during reboot */
308 writel (0, &ehci->regs->configured_flag); 320 writel (0, &ehci->regs->configured_flag);
309 return 0;
310} 321}
311 322
312static void ehci_port_power (struct ehci_hcd *ehci, int is_on) 323static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
@@ -334,8 +345,6 @@ static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
334static void ehci_work (struct ehci_hcd *ehci, struct pt_regs *regs) 345static void ehci_work (struct ehci_hcd *ehci, struct pt_regs *regs)
335{ 346{
336 timer_action_done (ehci, TIMER_IO_WATCHDOG); 347 timer_action_done (ehci, TIMER_IO_WATCHDOG);
337 if (ehci->reclaim_ready)
338 end_unlink_async (ehci, regs);
339 348
340 /* another CPU may drop ehci->lock during a schedule scan while 349 /* another CPU may drop ehci->lock during a schedule scan while
341 * it reports urb completions. this flag guards against bogus 350 * it reports urb completions. this flag guards against bogus
@@ -370,6 +379,7 @@ static void ehci_stop (struct usb_hcd *hcd)
370 379
371 /* no more interrupts ... */ 380 /* no more interrupts ... */
372 del_timer_sync (&ehci->watchdog); 381 del_timer_sync (&ehci->watchdog);
382 del_timer_sync (&ehci->iaa_watchdog);
373 383
374 spin_lock_irq(&ehci->lock); 384 spin_lock_irq(&ehci->lock);
375 if (HC_IS_RUNNING (hcd->state)) 385 if (HC_IS_RUNNING (hcd->state))
@@ -381,7 +391,6 @@ static void ehci_stop (struct usb_hcd *hcd)
381 391
382 /* let companion controllers work when we aren't */ 392 /* let companion controllers work when we aren't */
383 writel (0, &ehci->regs->configured_flag); 393 writel (0, &ehci->regs->configured_flag);
384 unregister_reboot_notifier (&ehci->reboot_notifier);
385 394
386 remove_debug_files (ehci); 395 remove_debug_files (ehci);
387 396
@@ -417,6 +426,10 @@ static int ehci_init(struct usb_hcd *hcd)
417 ehci->watchdog.function = ehci_watchdog; 426 ehci->watchdog.function = ehci_watchdog;
418 ehci->watchdog.data = (unsigned long) ehci; 427 ehci->watchdog.data = (unsigned long) ehci;
419 428
429 init_timer(&ehci->iaa_watchdog);
430 ehci->iaa_watchdog.function = ehci_iaa_watchdog;
431 ehci->iaa_watchdog.data = (unsigned long) ehci;
432
420 /* 433 /*
421 * hw default: 1K periodic list heads, one per frame. 434 * hw default: 1K periodic list heads, one per frame.
422 * periodic_size can shrink by USBCMD update if hcc_params allows. 435 * periodic_size can shrink by USBCMD update if hcc_params allows.
@@ -427,13 +440,12 @@ static int ehci_init(struct usb_hcd *hcd)
427 440
428 /* controllers may cache some of the periodic schedule ... */ 441 /* controllers may cache some of the periodic schedule ... */
429 hcc_params = readl(&ehci->caps->hcc_params); 442 hcc_params = readl(&ehci->caps->hcc_params);
430 if (HCC_ISOC_CACHE(hcc_params)) // full frame cache 443 if (HCC_ISOC_CACHE(hcc_params)) // full frame cache
431 ehci->i_thresh = 8; 444 ehci->i_thresh = 8;
432 else // N microframes cached 445 else // N microframes cached
433 ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params); 446 ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
434 447
435 ehci->reclaim = NULL; 448 ehci->reclaim = NULL;
436 ehci->reclaim_ready = 0;
437 ehci->next_uframe = -1; 449 ehci->next_uframe = -1;
438 450
439 /* 451 /*
@@ -483,9 +495,6 @@ static int ehci_init(struct usb_hcd *hcd)
483 } 495 }
484 ehci->command = temp; 496 ehci->command = temp;
485 497
486 ehci->reboot_notifier.notifier_call = ehci_reboot;
487 register_reboot_notifier(&ehci->reboot_notifier);
488
489 return 0; 498 return 0;
490} 499}
491 500
@@ -499,7 +508,6 @@ static int ehci_run (struct usb_hcd *hcd)
499 508
500 /* EHCI spec section 4.1 */ 509 /* EHCI spec section 4.1 */
501 if ((retval = ehci_reset(ehci)) != 0) { 510 if ((retval = ehci_reset(ehci)) != 0) {
502 unregister_reboot_notifier(&ehci->reboot_notifier);
503 ehci_mem_cleanup(ehci); 511 ehci_mem_cleanup(ehci);
504 return retval; 512 return retval;
505 } 513 }
@@ -611,7 +619,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd, struct pt_regs *regs)
611 /* complete the unlinking of some qh [4.15.2.3] */ 619 /* complete the unlinking of some qh [4.15.2.3] */
612 if (status & STS_IAA) { 620 if (status & STS_IAA) {
613 COUNT (ehci->stats.reclaim); 621 COUNT (ehci->stats.reclaim);
614 ehci->reclaim_ready = 1; 622 end_unlink_async (ehci, regs);
615 bh = 1; 623 bh = 1;
616 } 624 }
617 625
@@ -715,10 +723,14 @@ static int ehci_urb_enqueue (
715 723
716static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh) 724static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
717{ 725{
718 /* if we need to use IAA and it's busy, defer */ 726 // BUG_ON(qh->qh_state != QH_STATE_LINKED);
719 if (qh->qh_state == QH_STATE_LINKED 727
720 && ehci->reclaim 728 /* failfast */
721 && HC_IS_RUNNING (ehci_to_hcd(ehci)->state)) { 729 if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state))
730 end_unlink_async (ehci, NULL);
731
732 /* defer till later if busy */
733 else if (ehci->reclaim) {
722 struct ehci_qh *last; 734 struct ehci_qh *last;
723 735
724 for (last = ehci->reclaim; 736 for (last = ehci->reclaim;
@@ -728,12 +740,8 @@ static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
728 qh->qh_state = QH_STATE_UNLINK_WAIT; 740 qh->qh_state = QH_STATE_UNLINK_WAIT;
729 last->reclaim = qh; 741 last->reclaim = qh;
730 742
731 /* bypass IAA if the hc can't care */ 743 /* start IAA cycle */
732 } else if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state) && ehci->reclaim) 744 } else
733 end_unlink_async (ehci, NULL);
734
735 /* something else might have unlinked the qh by now */
736 if (qh->qh_state == QH_STATE_LINKED)
737 start_unlink_async (ehci, qh); 745 start_unlink_async (ehci, qh);
738} 746}
739 747
@@ -755,7 +763,19 @@ static int ehci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
755 qh = (struct ehci_qh *) urb->hcpriv; 763 qh = (struct ehci_qh *) urb->hcpriv;
756 if (!qh) 764 if (!qh)
757 break; 765 break;
758 unlink_async (ehci, qh); 766 switch (qh->qh_state) {
767 case QH_STATE_LINKED:
768 case QH_STATE_COMPLETING:
769 unlink_async (ehci, qh);
770 break;
771 case QH_STATE_UNLINK:
772 case QH_STATE_UNLINK_WAIT:
773 /* already started */
774 break;
775 case QH_STATE_IDLE:
776 WARN_ON(1);
777 break;
778 }
759 break; 779 break;
760 780
761 case PIPE_INTERRUPT: 781 case PIPE_INTERRUPT:
@@ -847,6 +867,7 @@ rescan:
847 unlink_async (ehci, qh); 867 unlink_async (ehci, qh);
848 /* FALL THROUGH */ 868 /* FALL THROUGH */
849 case QH_STATE_UNLINK: /* wait for hw to finish? */ 869 case QH_STATE_UNLINK: /* wait for hw to finish? */
870 case QH_STATE_UNLINK_WAIT:
850idle_timeout: 871idle_timeout:
851 spin_unlock_irqrestore (&ehci->lock, flags); 872 spin_unlock_irqrestore (&ehci->lock, flags);
852 schedule_timeout_uninterruptible(1); 873 schedule_timeout_uninterruptible(1);
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index d03e3cad5ca8..b2ee13c58517 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) 2001-2004 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
6 * Free Software Foundation; either version 2 of the License, or (at your 6 * Free Software Foundation; either version 2 of the License, or (at your
@@ -48,7 +48,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
48 } 48 }
49 ehci->command = readl (&ehci->regs->command); 49 ehci->command = readl (&ehci->regs->command);
50 if (ehci->reclaim) 50 if (ehci->reclaim)
51 ehci->reclaim_ready = 1; 51 end_unlink_async (ehci, NULL);
52 ehci_work(ehci, NULL); 52 ehci_work(ehci, NULL);
53 53
54 /* suspend any active/unsuspended ports, maybe allow wakeup */ 54 /* suspend any active/unsuspended ports, maybe allow wakeup */
@@ -103,10 +103,10 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
103 103
104 /* re-init operational registers in case we lost power */ 104 /* re-init operational registers in case we lost power */
105 if (readl (&ehci->regs->intr_enable) == 0) { 105 if (readl (&ehci->regs->intr_enable) == 0) {
106 /* at least some APM implementations will try to deliver 106 /* at least some APM implementations will try to deliver
107 * IRQs right away, so delay them until we're ready. 107 * IRQs right away, so delay them until we're ready.
108 */ 108 */
109 intr_enable = 1; 109 intr_enable = 1;
110 writel (0, &ehci->regs->segment); 110 writel (0, &ehci->regs->segment);
111 writel (ehci->periodic_dma, &ehci->regs->frame_list); 111 writel (ehci->periodic_dma, &ehci->regs->frame_list);
112 writel ((u32)ehci->async->qh_dma, &ehci->regs->async_next); 112 writel ((u32)ehci->async->qh_dma, &ehci->regs->async_next);
@@ -232,7 +232,7 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
232 buf [1] = 0; 232 buf [1] = 0;
233 retval++; 233 retval++;
234 } 234 }
235 235
236 /* no hub change reports (bit 0) for now (power, ...) */ 236 /* no hub change reports (bit 0) for now (power, ...) */
237 237
238 /* port N changes (bit N)? */ 238 /* port N changes (bit N)? */
@@ -304,7 +304,7 @@ ehci_hub_descriptor (
304 304
305/*-------------------------------------------------------------------------*/ 305/*-------------------------------------------------------------------------*/
306 306
307#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E) 307#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
308 308
309static int ehci_hub_control ( 309static int ehci_hub_control (
310 struct usb_hcd *hcd, 310 struct usb_hcd *hcd,
diff --git a/drivers/usb/host/ehci-mem.c b/drivers/usb/host/ehci-mem.c
index 766061e0260a..a8ba2e1497a4 100644
--- a/drivers/usb/host/ehci-mem.c
+++ b/drivers/usb/host/ehci-mem.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (c) 2001 by David Brownell 2 * Copyright (c) 2001 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
6 * Free Software Foundation; either version 2 of the License, or (at your 6 * Free Software Foundation; either version 2 of the License, or (at your
@@ -25,7 +25,7 @@
25 * - data used only by the HCD ... kmalloc is fine 25 * - data used only by the HCD ... kmalloc is fine
26 * - async and periodic schedules, shared by HC and HCD ... these 26 * - async and periodic schedules, shared by HC and HCD ... these
27 * need to use dma_pool or dma_alloc_coherent 27 * need to use dma_pool or dma_alloc_coherent
28 * - driver buffers, read/written by HC ... single shot DMA mapped 28 * - driver buffers, read/written by HC ... single shot DMA mapped
29 * 29 *
30 * There's also PCI "register" data, which is memory mapped. 30 * There's also PCI "register" data, which is memory mapped.
31 * No memory seen by this driver is pageable. 31 * No memory seen by this driver is pageable.
@@ -119,7 +119,7 @@ static inline void qh_put (struct ehci_qh *qh)
119 119
120/*-------------------------------------------------------------------------*/ 120/*-------------------------------------------------------------------------*/
121 121
122/* The queue heads and transfer descriptors are managed from pools tied 122/* The queue heads and transfer descriptors are managed from pools tied
123 * to each of the "per device" structures. 123 * to each of the "per device" structures.
124 * This is the initialisation and cleanup code. 124 * This is the initialisation and cleanup code.
125 */ 125 */
@@ -165,7 +165,7 @@ static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags)
165 int i; 165 int i;
166 166
167 /* QTDs for control/bulk/intr transfers */ 167 /* QTDs for control/bulk/intr transfers */
168 ehci->qtd_pool = dma_pool_create ("ehci_qtd", 168 ehci->qtd_pool = dma_pool_create ("ehci_qtd",
169 ehci_to_hcd(ehci)->self.controller, 169 ehci_to_hcd(ehci)->self.controller,
170 sizeof (struct ehci_qtd), 170 sizeof (struct ehci_qtd),
171 32 /* byte alignment (for hw parts) */, 171 32 /* byte alignment (for hw parts) */,
@@ -175,7 +175,7 @@ static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags)
175 } 175 }
176 176
177 /* QHs for control/bulk/intr transfers */ 177 /* QHs for control/bulk/intr transfers */
178 ehci->qh_pool = dma_pool_create ("ehci_qh", 178 ehci->qh_pool = dma_pool_create ("ehci_qh",
179 ehci_to_hcd(ehci)->self.controller, 179 ehci_to_hcd(ehci)->self.controller,
180 sizeof (struct ehci_qh), 180 sizeof (struct ehci_qh),
181 32 /* byte alignment (for hw parts) */, 181 32 /* byte alignment (for hw parts) */,
@@ -189,7 +189,7 @@ static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags)
189 } 189 }
190 190
191 /* ITD for high speed ISO transfers */ 191 /* ITD for high speed ISO transfers */
192 ehci->itd_pool = dma_pool_create ("ehci_itd", 192 ehci->itd_pool = dma_pool_create ("ehci_itd",
193 ehci_to_hcd(ehci)->self.controller, 193 ehci_to_hcd(ehci)->self.controller,
194 sizeof (struct ehci_itd), 194 sizeof (struct ehci_itd),
195 32 /* byte alignment (for hw parts) */, 195 32 /* byte alignment (for hw parts) */,
@@ -199,7 +199,7 @@ static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags)
199 } 199 }
200 200
201 /* SITD for full/low speed split ISO transfers */ 201 /* SITD for full/low speed split ISO transfers */
202 ehci->sitd_pool = dma_pool_create ("ehci_sitd", 202 ehci->sitd_pool = dma_pool_create ("ehci_sitd",
203 ehci_to_hcd(ehci)->self.controller, 203 ehci_to_hcd(ehci)->self.controller,
204 sizeof (struct ehci_sitd), 204 sizeof (struct ehci_sitd),
205 32 /* byte alignment (for hw parts) */, 205 32 /* byte alignment (for hw parts) */,
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index cadffacd945b..08d0472d4f57 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -238,6 +238,12 @@ static int ehci_pci_suspend(struct usb_hcd *hcd, pm_message_t message)
238 writel (0, &ehci->regs->intr_enable); 238 writel (0, &ehci->regs->intr_enable);
239 (void)readl(&ehci->regs->intr_enable); 239 (void)readl(&ehci->regs->intr_enable);
240 240
241 /* make sure snapshot being resumed re-enumerates everything */
242 if (message.event == PM_EVENT_PRETHAW) {
243 ehci_halt(ehci);
244 ehci_reset(ehci);
245 }
246
241 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 247 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
242 bail: 248 bail:
243 spin_unlock_irqrestore (&ehci->lock, flags); 249 spin_unlock_irqrestore (&ehci->lock, flags);
@@ -297,7 +303,7 @@ restart:
297 /* emptying the schedule aborts any urbs */ 303 /* emptying the schedule aborts any urbs */
298 spin_lock_irq(&ehci->lock); 304 spin_lock_irq(&ehci->lock);
299 if (ehci->reclaim) 305 if (ehci->reclaim)
300 ehci->reclaim_ready = 1; 306 end_unlink_async (ehci, NULL);
301 ehci_work(ehci, NULL); 307 ehci_work(ehci, NULL);
302 spin_unlock_irq(&ehci->lock); 308 spin_unlock_irq(&ehci->lock);
303 309
@@ -332,6 +338,7 @@ static const struct hc_driver ehci_pci_hc_driver = {
332 .resume = ehci_pci_resume, 338 .resume = ehci_pci_resume,
333#endif 339#endif
334 .stop = ehci_stop, 340 .stop = ehci_stop,
341 .shutdown = ehci_shutdown,
335 342
336 /* 343 /*
337 * managing i/o requests and associated device resources 344 * managing i/o requests and associated device resources
@@ -378,4 +385,5 @@ static struct pci_driver ehci_pci_driver = {
378 .suspend = usb_hcd_pci_suspend, 385 .suspend = usb_hcd_pci_suspend,
379 .resume = usb_hcd_pci_resume, 386 .resume = usb_hcd_pci_resume,
380#endif 387#endif
388 .shutdown = usb_hcd_pci_shutdown,
381}; 389};
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index e469221e7ec3..7fc25b6bd7d2 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) 2001-2004 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
6 * Free Software Foundation; either version 2 of the License, or (at your 6 * Free Software Foundation; either version 2 of the License, or (at your
@@ -31,7 +31,7 @@
31 * ISO traffic uses "ISO TD" (itd, and sitd) records, and (along with 31 * ISO traffic uses "ISO TD" (itd, and sitd) records, and (along with
32 * interrupts) needs careful scheduling. Performance improvements can be 32 * interrupts) needs careful scheduling. Performance improvements can be
33 * an ongoing challenge. That's in "ehci-sched.c". 33 * an ongoing challenge. That's in "ehci-sched.c".
34 * 34 *
35 * USB 1.1 devices are handled (a) by "companion" OHCI or UHCI root hubs, 35 * USB 1.1 devices are handled (a) by "companion" OHCI or UHCI root hubs,
36 * or otherwise through transaction translators (TTs) in USB 2.0 hubs using 36 * or otherwise through transaction translators (TTs) in USB 2.0 hubs using
37 * (b) special fields in qh entries or (c) split iso entries. TTs will 37 * (b) special fields in qh entries or (c) split iso entries. TTs will
@@ -199,7 +199,7 @@ static void qtd_copy_status (
199 && ((token & QTD_STS_MMF) != 0 199 && ((token & QTD_STS_MMF) != 0
200 || QTD_CERR(token) == 0) 200 || QTD_CERR(token) == 0)
201 && (!ehci_is_TDI(ehci) 201 && (!ehci_is_TDI(ehci)
202 || urb->dev->tt->hub != 202 || urb->dev->tt->hub !=
203 ehci_to_hcd(ehci)->self.root_hub)) { 203 ehci_to_hcd(ehci)->self.root_hub)) {
204#ifdef DEBUG 204#ifdef DEBUG
205 struct usb_device *tt = urb->dev->tt->hub; 205 struct usb_device *tt = urb->dev->tt->hub;
@@ -364,7 +364,7 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh, struct pt_regs *regs)
364 */ 364 */
365 if (likely (urb->status == -EINPROGRESS)) 365 if (likely (urb->status == -EINPROGRESS))
366 continue; 366 continue;
367 367
368 /* issue status after short control reads */ 368 /* issue status after short control reads */
369 if (unlikely (do_status != 0) 369 if (unlikely (do_status != 0)
370 && QTD_PID (token) == 0 /* OUT */) { 370 && QTD_PID (token) == 0 /* OUT */) {
@@ -388,7 +388,7 @@ halt:
388 wmb (); 388 wmb ();
389 } 389 }
390 } 390 }
391 391
392 /* remove it from the queue */ 392 /* remove it from the queue */
393 spin_lock (&urb->lock); 393 spin_lock (&urb->lock);
394 qtd_copy_status (ehci, urb, qtd->length, token); 394 qtd_copy_status (ehci, urb, qtd->length, token);
@@ -518,7 +518,7 @@ qh_urb_transaction (
518 /* for zero length DATA stages, STATUS is always IN */ 518 /* for zero length DATA stages, STATUS is always IN */
519 if (len == 0) 519 if (len == 0)
520 token |= (1 /* "in" */ << 8); 520 token |= (1 /* "in" */ << 8);
521 } 521 }
522 522
523 /* 523 /*
524 * data transfer stage: buffer setup 524 * data transfer stage: buffer setup
@@ -759,7 +759,7 @@ qh_make (
759 } 759 }
760 break; 760 break;
761 default: 761 default:
762 dbg ("bogus dev %p speed %d", urb->dev, urb->dev->speed); 762 dbg ("bogus dev %p speed %d", urb->dev, urb->dev->speed);
763done: 763done:
764 qh_put (qh); 764 qh_put (qh);
765 return NULL; 765 return NULL;
@@ -967,17 +967,16 @@ static void end_unlink_async (struct ehci_hcd *ehci, struct pt_regs *regs)
967 struct ehci_qh *qh = ehci->reclaim; 967 struct ehci_qh *qh = ehci->reclaim;
968 struct ehci_qh *next; 968 struct ehci_qh *next;
969 969
970 timer_action_done (ehci, TIMER_IAA_WATCHDOG); 970 iaa_watchdog_done (ehci);
971 971
972 // qh->hw_next = cpu_to_le32 (qh->qh_dma); 972 // qh->hw_next = cpu_to_le32 (qh->qh_dma);
973 qh->qh_state = QH_STATE_IDLE; 973 qh->qh_state = QH_STATE_IDLE;
974 qh->qh_next.qh = NULL; 974 qh->qh_next.qh = NULL;
975 qh_put (qh); // refcount from reclaim 975 qh_put (qh); // refcount from reclaim
976 976
977 /* other unlink(s) may be pending (in QH_STATE_UNLINK_WAIT) */ 977 /* other unlink(s) may be pending (in QH_STATE_UNLINK_WAIT) */
978 next = qh->reclaim; 978 next = qh->reclaim;
979 ehci->reclaim = next; 979 ehci->reclaim = next;
980 ehci->reclaim_ready = 0;
981 qh->reclaim = NULL; 980 qh->reclaim = NULL;
982 981
983 qh_completions (ehci, qh, regs); 982 qh_completions (ehci, qh, regs);
@@ -1031,7 +1030,7 @@ static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
1031 timer_action_done (ehci, TIMER_ASYNC_OFF); 1030 timer_action_done (ehci, TIMER_ASYNC_OFF);
1032 } 1031 }
1033 return; 1032 return;
1034 } 1033 }
1035 1034
1036 qh->qh_state = QH_STATE_UNLINK; 1035 qh->qh_state = QH_STATE_UNLINK;
1037 ehci->reclaim = qh = qh_get (qh); 1036 ehci->reclaim = qh = qh_get (qh);
@@ -1046,17 +1045,16 @@ static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
1046 1045
1047 if (unlikely (ehci_to_hcd(ehci)->state == HC_STATE_HALT)) { 1046 if (unlikely (ehci_to_hcd(ehci)->state == HC_STATE_HALT)) {
1048 /* if (unlikely (qh->reclaim != 0)) 1047 /* if (unlikely (qh->reclaim != 0))
1049 * this will recurse, probably not much 1048 * this will recurse, probably not much
1050 */ 1049 */
1051 end_unlink_async (ehci, NULL); 1050 end_unlink_async (ehci, NULL);
1052 return; 1051 return;
1053 } 1052 }
1054 1053
1055 ehci->reclaim_ready = 0;
1056 cmd |= CMD_IAAD; 1054 cmd |= CMD_IAAD;
1057 writel (cmd, &ehci->regs->command); 1055 writel (cmd, &ehci->regs->command);
1058 (void) readl (&ehci->regs->command); 1056 (void) readl (&ehci->regs->command);
1059 timer_action (ehci, TIMER_IAA_WATCHDOG); 1057 iaa_watchdog_start (ehci);
1060} 1058}
1061 1059
1062/*-------------------------------------------------------------------------*/ 1060/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 4859900bd135..e5e9c653c907 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Copyright (c) 2001-2004 by David Brownell 2 * Copyright (c) 2001-2004 by David Brownell
3 * Copyright (c) 2003 Michal Sojka, for high-speed iso transfers 3 * Copyright (c) 2003 Michal Sojka, for high-speed iso transfers
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify it 5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the 6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your 7 * Free Software Foundation; either version 2 of the License, or (at your
@@ -613,7 +613,7 @@ static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh)
613/*-------------------------------------------------------------------------*/ 613/*-------------------------------------------------------------------------*/
614 614
615static int check_period ( 615static int check_period (
616 struct ehci_hcd *ehci, 616 struct ehci_hcd *ehci,
617 unsigned frame, 617 unsigned frame,
618 unsigned uframe, 618 unsigned uframe,
619 unsigned period, 619 unsigned period,
@@ -629,7 +629,7 @@ static int check_period (
629 629
630 /* 630 /*
631 * 80% periodic == 100 usec/uframe available 631 * 80% periodic == 100 usec/uframe available
632 * convert "usecs we need" to "max already claimed" 632 * convert "usecs we need" to "max already claimed"
633 */ 633 */
634 usecs = 100 - usecs; 634 usecs = 100 - usecs;
635 635
@@ -659,14 +659,14 @@ static int check_period (
659} 659}
660 660
661static int check_intr_schedule ( 661static int check_intr_schedule (
662 struct ehci_hcd *ehci, 662 struct ehci_hcd *ehci,
663 unsigned frame, 663 unsigned frame,
664 unsigned uframe, 664 unsigned uframe,
665 const struct ehci_qh *qh, 665 const struct ehci_qh *qh,
666 __le32 *c_maskp 666 __le32 *c_maskp
667) 667)
668{ 668{
669 int retval = -ENOSPC; 669 int retval = -ENOSPC;
670 u8 mask = 0; 670 u8 mask = 0;
671 671
672 if (qh->c_usecs && uframe >= 6) /* FSTN territory? */ 672 if (qh->c_usecs && uframe >= 6) /* FSTN territory? */
@@ -701,7 +701,7 @@ static int check_intr_schedule (
701 /* Make sure this tt's buffer is also available for CSPLITs. 701 /* Make sure this tt's buffer is also available for CSPLITs.
702 * We pessimize a bit; probably the typical full speed case 702 * We pessimize a bit; probably the typical full speed case
703 * doesn't need the second CSPLIT. 703 * doesn't need the second CSPLIT.
704 * 704 *
705 * NOTE: both SPLIT and CSPLIT could be checked in just 705 * NOTE: both SPLIT and CSPLIT could be checked in just
706 * one smart pass... 706 * one smart pass...
707 */ 707 */
@@ -728,7 +728,7 @@ done:
728 */ 728 */
729static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh) 729static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh)
730{ 730{
731 int status; 731 int status;
732 unsigned uframe; 732 unsigned uframe;
733 __le32 c_mask; 733 __le32 c_mask;
734 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */ 734 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */
@@ -784,7 +784,7 @@ static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh)
784 ehci_dbg (ehci, "reused qh %p schedule\n", qh); 784 ehci_dbg (ehci, "reused qh %p schedule\n", qh);
785 785
786 /* stuff into the periodic schedule */ 786 /* stuff into the periodic schedule */
787 status = qh_link_periodic (ehci, qh); 787 status = qh_link_periodic (ehci, qh);
788done: 788done:
789 return status; 789 return status;
790} 790}
@@ -1681,7 +1681,7 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
1681 status = -ESHUTDOWN; 1681 status = -ESHUTDOWN;
1682 else 1682 else
1683 status = iso_stream_schedule (ehci, urb, stream); 1683 status = iso_stream_schedule (ehci, urb, stream);
1684 if (likely (status == 0)) 1684 if (likely (status == 0))
1685 itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); 1685 itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
1686 spin_unlock_irqrestore (&ehci->lock, flags); 1686 spin_unlock_irqrestore (&ehci->lock, flags);
1687 1687
@@ -1738,7 +1738,7 @@ sitd_sched_init (
1738 if (packet->buf1 != (buf & ~(u64)0x0fff)) 1738 if (packet->buf1 != (buf & ~(u64)0x0fff))
1739 packet->cross = 1; 1739 packet->cross = 1;
1740 1740
1741 /* OUT uses multiple start-splits */ 1741 /* OUT uses multiple start-splits */
1742 if (stream->bEndpointAddress & USB_DIR_IN) 1742 if (stream->bEndpointAddress & USB_DIR_IN)
1743 continue; 1743 continue;
1744 length = (length + 187) / 188; 1744 length = (length + 187) / 188;
@@ -1925,7 +1925,7 @@ sitd_link_urb (
1925/*-------------------------------------------------------------------------*/ 1925/*-------------------------------------------------------------------------*/
1926 1926
1927#define SITD_ERRS (SITD_STS_ERR | SITD_STS_DBE | SITD_STS_BABBLE \ 1927#define SITD_ERRS (SITD_STS_ERR | SITD_STS_DBE | SITD_STS_BABBLE \
1928 | SITD_STS_XACT | SITD_STS_MMF) 1928 | SITD_STS_XACT | SITD_STS_MMF)
1929 1929
1930static unsigned 1930static unsigned
1931sitd_complete ( 1931sitd_complete (
@@ -2043,7 +2043,7 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
2043 status = -ESHUTDOWN; 2043 status = -ESHUTDOWN;
2044 else 2044 else
2045 status = iso_stream_schedule (ehci, urb, stream); 2045 status = iso_stream_schedule (ehci, urb, stream);
2046 if (status == 0) 2046 if (status == 0)
2047 sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); 2047 sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
2048 spin_unlock_irqrestore (&ehci->lock, flags); 2048 spin_unlock_irqrestore (&ehci->lock, flags);
2049 2049
@@ -2226,5 +2226,5 @@ restart:
2226 now_uframe++; 2226 now_uframe++;
2227 now_uframe %= mod; 2227 now_uframe %= mod;
2228 } 2228 }
2229 } 2229 }
2230} 2230}
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 679c1cdcc915..6aac39f50e07 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (c) 2001-2002 by David Brownell 2 * Copyright (c) 2001-2002 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
6 * Free Software Foundation; either version 2 of the License, or (at your 6 * Free Software Foundation; either version 2 of the License, or (at your
@@ -58,7 +58,6 @@ struct ehci_hcd { /* one per controller */
58 /* async schedule support */ 58 /* async schedule support */
59 struct ehci_qh *async; 59 struct ehci_qh *async;
60 struct ehci_qh *reclaim; 60 struct ehci_qh *reclaim;
61 unsigned reclaim_ready : 1;
62 unsigned scanning : 1; 61 unsigned scanning : 1;
63 62
64 /* periodic schedule support */ 63 /* periodic schedule support */
@@ -81,8 +80,8 @@ struct ehci_hcd { /* one per controller */
81 struct dma_pool *itd_pool; /* itd per iso urb */ 80 struct dma_pool *itd_pool; /* itd per iso urb */
82 struct dma_pool *sitd_pool; /* sitd per split iso urb */ 81 struct dma_pool *sitd_pool; /* sitd per split iso urb */
83 82
83 struct timer_list iaa_watchdog;
84 struct timer_list watchdog; 84 struct timer_list watchdog;
85 struct notifier_block reboot_notifier;
86 unsigned long actions; 85 unsigned long actions;
87 unsigned stamp; 86 unsigned stamp;
88 unsigned long next_statechange; 87 unsigned long next_statechange;
@@ -104,7 +103,7 @@ struct ehci_hcd { /* one per controller */
104#endif 103#endif
105}; 104};
106 105
107/* convert between an HCD pointer and the corresponding EHCI_HCD */ 106/* convert between an HCD pointer and the corresponding EHCI_HCD */
108static inline struct ehci_hcd *hcd_to_ehci (struct usb_hcd *hcd) 107static inline struct ehci_hcd *hcd_to_ehci (struct usb_hcd *hcd)
109{ 108{
110 return (struct ehci_hcd *) (hcd->hcd_priv); 109 return (struct ehci_hcd *) (hcd->hcd_priv);
@@ -115,9 +114,21 @@ static inline struct usb_hcd *ehci_to_hcd (struct ehci_hcd *ehci)
115} 114}
116 115
117 116
117static inline void
118iaa_watchdog_start (struct ehci_hcd *ehci)
119{
120 WARN_ON(timer_pending(&ehci->iaa_watchdog));
121 mod_timer (&ehci->iaa_watchdog,
122 jiffies + msecs_to_jiffies(EHCI_IAA_MSECS));
123}
124
125static inline void iaa_watchdog_done (struct ehci_hcd *ehci)
126{
127 del_timer (&ehci->iaa_watchdog);
128}
129
118enum ehci_timer_action { 130enum ehci_timer_action {
119 TIMER_IO_WATCHDOG, 131 TIMER_IO_WATCHDOG,
120 TIMER_IAA_WATCHDOG,
121 TIMER_ASYNC_SHRINK, 132 TIMER_ASYNC_SHRINK,
122 TIMER_ASYNC_OFF, 133 TIMER_ASYNC_OFF,
123}; 134};
@@ -135,9 +146,6 @@ timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action)
135 unsigned long t; 146 unsigned long t;
136 147
137 switch (action) { 148 switch (action) {
138 case TIMER_IAA_WATCHDOG:
139 t = EHCI_IAA_JIFFIES;
140 break;
141 case TIMER_IO_WATCHDOG: 149 case TIMER_IO_WATCHDOG:
142 t = EHCI_IO_JIFFIES; 150 t = EHCI_IO_JIFFIES;
143 break; 151 break;
@@ -154,8 +162,7 @@ timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action)
154 // async queue SHRINK often precedes IAA. while it's ready 162 // async queue SHRINK often precedes IAA. while it's ready
155 // to go OFF neither can matter, and afterwards the IO 163 // to go OFF neither can matter, and afterwards the IO
156 // watchdog stops unless there's still periodic traffic. 164 // watchdog stops unless there's still periodic traffic.
157 if (action != TIMER_IAA_WATCHDOG 165 if (time_before_eq(t, ehci->watchdog.expires)
158 && t > ehci->watchdog.expires
159 && timer_pending (&ehci->watchdog)) 166 && timer_pending (&ehci->watchdog))
160 return; 167 return;
161 mod_timer (&ehci->watchdog, t); 168 mod_timer (&ehci->watchdog, t);
@@ -179,8 +186,8 @@ struct ehci_caps {
179#define HCS_INDICATOR(p) ((p)&(1 << 16)) /* true: has port indicators */ 186#define HCS_INDICATOR(p) ((p)&(1 << 16)) /* true: has port indicators */
180#define HCS_N_CC(p) (((p)>>12)&0xf) /* bits 15:12, #companion HCs */ 187#define HCS_N_CC(p) (((p)>>12)&0xf) /* bits 15:12, #companion HCs */
181#define HCS_N_PCC(p) (((p)>>8)&0xf) /* bits 11:8, ports per CC */ 188#define HCS_N_PCC(p) (((p)>>8)&0xf) /* bits 11:8, ports per CC */
182#define HCS_PORTROUTED(p) ((p)&(1 << 7)) /* true: port routing */ 189#define HCS_PORTROUTED(p) ((p)&(1 << 7)) /* true: port routing */
183#define HCS_PPC(p) ((p)&(1 << 4)) /* true: port power control */ 190#define HCS_PPC(p) ((p)&(1 << 4)) /* true: port power control */
184#define HCS_N_PORTS(p) (((p)>>0)&0xf) /* bits 3:0, ports on HC */ 191#define HCS_N_PORTS(p) (((p)>>0)&0xf) /* bits 3:0, ports on HC */
185 192
186 u32 hcc_params; /* HCCPARAMS - offset 0x8 */ 193 u32 hcc_params; /* HCCPARAMS - offset 0x8 */
@@ -205,7 +212,7 @@ struct ehci_regs {
205#define CMD_LRESET (1<<7) /* partial reset (no ports, etc) */ 212#define CMD_LRESET (1<<7) /* partial reset (no ports, etc) */
206#define CMD_IAAD (1<<6) /* "doorbell" interrupt async advance */ 213#define CMD_IAAD (1<<6) /* "doorbell" interrupt async advance */
207#define CMD_ASE (1<<5) /* async schedule enable */ 214#define CMD_ASE (1<<5) /* async schedule enable */
208#define CMD_PSE (1<<4) /* periodic schedule enable */ 215#define CMD_PSE (1<<4) /* periodic schedule enable */
209/* 3:2 is periodic frame list size */ 216/* 3:2 is periodic frame list size */
210#define CMD_RESET (1<<1) /* reset HC not bus */ 217#define CMD_RESET (1<<1) /* reset HC not bus */
211#define CMD_RUN (1<<0) /* start/stop HC */ 218#define CMD_RUN (1<<0) /* start/stop HC */
@@ -231,9 +238,9 @@ struct ehci_regs {
231 /* FRINDEX: offset 0x0C */ 238 /* FRINDEX: offset 0x0C */
232 u32 frame_index; /* current microframe number */ 239 u32 frame_index; /* current microframe number */
233 /* CTRLDSSEGMENT: offset 0x10 */ 240 /* CTRLDSSEGMENT: offset 0x10 */
234 u32 segment; /* address bits 63:32 if needed */ 241 u32 segment; /* address bits 63:32 if needed */
235 /* PERIODICLISTBASE: offset 0x14 */ 242 /* PERIODICLISTBASE: offset 0x14 */
236 u32 frame_list; /* points to periodic list */ 243 u32 frame_list; /* points to periodic list */
237 /* ASYNCLISTADDR: offset 0x18 */ 244 /* ASYNCLISTADDR: offset 0x18 */
238 u32 async_next; /* address of next async queue head */ 245 u32 async_next; /* address of next async queue head */
239 246
@@ -302,7 +309,7 @@ struct ehci_dbg_port {
302 309
303/* 310/*
304 * EHCI Specification 0.95 Section 3.5 311 * EHCI Specification 0.95 Section 3.5
305 * QTD: describe data transfer components (buffer, direction, ...) 312 * QTD: describe data transfer components (buffer, direction, ...)
306 * See Fig 3-6 "Queue Element Transfer Descriptor Block Diagram". 313 * See Fig 3-6 "Queue Element Transfer Descriptor Block Diagram".
307 * 314 *
308 * These are associated only with "QH" (Queue Head) structures, 315 * These are associated only with "QH" (Queue Head) structures,
@@ -312,7 +319,7 @@ struct ehci_qtd {
312 /* first part defined by EHCI spec */ 319 /* first part defined by EHCI spec */
313 __le32 hw_next; /* see EHCI 3.5.1 */ 320 __le32 hw_next; /* see EHCI 3.5.1 */
314 __le32 hw_alt_next; /* see EHCI 3.5.2 */ 321 __le32 hw_alt_next; /* see EHCI 3.5.2 */
315 __le32 hw_token; /* see EHCI 3.5.3 */ 322 __le32 hw_token; /* see EHCI 3.5.3 */
316#define QTD_TOGGLE (1 << 31) /* data toggle */ 323#define QTD_TOGGLE (1 << 31) /* data toggle */
317#define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff) 324#define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff)
318#define QTD_IOC (1 << 15) /* interrupt on complete */ 325#define QTD_IOC (1 << 15) /* interrupt on complete */
@@ -349,8 +356,8 @@ struct ehci_qtd {
349/* values for that type tag */ 356/* values for that type tag */
350#define Q_TYPE_ITD __constant_cpu_to_le32 (0 << 1) 357#define Q_TYPE_ITD __constant_cpu_to_le32 (0 << 1)
351#define Q_TYPE_QH __constant_cpu_to_le32 (1 << 1) 358#define Q_TYPE_QH __constant_cpu_to_le32 (1 << 1)
352#define Q_TYPE_SITD __constant_cpu_to_le32 (2 << 1) 359#define Q_TYPE_SITD __constant_cpu_to_le32 (2 << 1)
353#define Q_TYPE_FSTN __constant_cpu_to_le32 (3 << 1) 360#define Q_TYPE_FSTN __constant_cpu_to_le32 (3 << 1)
354 361
355/* next async queue entry, or pointer to interrupt/periodic QH */ 362/* next async queue entry, or pointer to interrupt/periodic QH */
356#define QH_NEXT(dma) (cpu_to_le32(((u32)dma)&~0x01f)|Q_TYPE_QH) 363#define QH_NEXT(dma) (cpu_to_le32(((u32)dma)&~0x01f)|Q_TYPE_QH)
@@ -367,7 +374,7 @@ struct ehci_qtd {
367 * For entries in the async schedule, the type tag always says "qh". 374 * For entries in the async schedule, the type tag always says "qh".
368 */ 375 */
369union ehci_shadow { 376union ehci_shadow {
370 struct ehci_qh *qh; /* Q_TYPE_QH */ 377 struct ehci_qh *qh; /* Q_TYPE_QH */
371 struct ehci_itd *itd; /* Q_TYPE_ITD */ 378 struct ehci_itd *itd; /* Q_TYPE_ITD */
372 struct ehci_sitd *sitd; /* Q_TYPE_SITD */ 379 struct ehci_sitd *sitd; /* Q_TYPE_SITD */
373 struct ehci_fstn *fstn; /* Q_TYPE_FSTN */ 380 struct ehci_fstn *fstn; /* Q_TYPE_FSTN */
@@ -397,7 +404,7 @@ struct ehci_qh {
397#define QH_HUBPORT 0x3f800000 404#define QH_HUBPORT 0x3f800000
398#define QH_MULT 0xc0000000 405#define QH_MULT 0xc0000000
399 __le32 hw_current; /* qtd list - see EHCI 3.6.4 */ 406 __le32 hw_current; /* qtd list - see EHCI 3.6.4 */
400 407
401 /* qtd overlay (hardware parts of a struct ehci_qtd) */ 408 /* qtd overlay (hardware parts of a struct ehci_qtd) */
402 __le32 hw_qtd_next; 409 __le32 hw_qtd_next;
403 __le32 hw_alt_next; 410 __le32 hw_alt_next;
@@ -472,7 +479,7 @@ struct ehci_iso_stream {
472 struct list_head td_list; /* queued itds/sitds */ 479 struct list_head td_list; /* queued itds/sitds */
473 struct list_head free_list; /* list of unused itds/sitds */ 480 struct list_head free_list; /* list of unused itds/sitds */
474 struct usb_device *udev; 481 struct usb_device *udev;
475 struct usb_host_endpoint *ep; 482 struct usb_host_endpoint *ep;
476 483
477 /* output of (re)scheduling */ 484 /* output of (re)scheduling */
478 unsigned long start; /* jiffies */ 485 unsigned long start; /* jiffies */
@@ -492,8 +499,8 @@ struct ehci_iso_stream {
492 unsigned bandwidth; 499 unsigned bandwidth;
493 500
494 /* This is used to initialize iTD's hw_bufp fields */ 501 /* This is used to initialize iTD's hw_bufp fields */
495 __le32 buf0; 502 __le32 buf0;
496 __le32 buf1; 503 __le32 buf1;
497 __le32 buf2; 504 __le32 buf2;
498 505
499 /* this is used to initialize sITD's tt info */ 506 /* this is used to initialize sITD's tt info */
@@ -521,7 +528,7 @@ struct ehci_itd {
521 528
522#define ITD_ACTIVE __constant_cpu_to_le32(EHCI_ISOC_ACTIVE) 529#define ITD_ACTIVE __constant_cpu_to_le32(EHCI_ISOC_ACTIVE)
523 530
524 __le32 hw_bufp [7]; /* see EHCI 3.3.3 */ 531 __le32 hw_bufp [7]; /* see EHCI 3.3.3 */
525 __le32 hw_bufp_hi [7]; /* Appendix B */ 532 __le32 hw_bufp_hi [7]; /* Appendix B */
526 533
527 /* the rest is HCD-private */ 534 /* the rest is HCD-private */
@@ -542,7 +549,7 @@ struct ehci_itd {
542/*-------------------------------------------------------------------------*/ 549/*-------------------------------------------------------------------------*/
543 550
544/* 551/*
545 * EHCI Specification 0.95 Section 3.4 552 * EHCI Specification 0.95 Section 3.4
546 * siTD, aka split-transaction isochronous Transfer Descriptor 553 * siTD, aka split-transaction isochronous Transfer Descriptor
547 * ... describe full speed iso xfers through TT in hubs 554 * ... describe full speed iso xfers through TT in hubs
548 * see Figure 3-5 "Split-transaction Isochronous Transaction Descriptor (siTD) 555 * see Figure 3-5 "Split-transaction Isochronous Transaction Descriptor (siTD)
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 5147ed4a6662..a72e041df8e7 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -1204,10 +1204,10 @@ static int isp116x_show_dbg(struct seq_file *s, void *unused)
1204 1204
1205static int isp116x_open_seq(struct inode *inode, struct file *file) 1205static int isp116x_open_seq(struct inode *inode, struct file *file)
1206{ 1206{
1207 return single_open(file, isp116x_show_dbg, inode->u.generic_ip); 1207 return single_open(file, isp116x_show_dbg, inode->i_private);
1208} 1208}
1209 1209
1210static struct file_operations isp116x_debug_fops = { 1210static const struct file_operations isp116x_debug_fops = {
1211 .open = isp116x_open_seq, 1211 .open = isp116x_open_seq,
1212 .read = seq_read, 1212 .read = seq_read,
1213 .llseek = seq_lseek, 1213 .llseek = seq_lseek,
diff --git a/drivers/usb/host/isp116x.h b/drivers/usb/host/isp116x.h
index a1b7c3813d3a..b91e2edd9c5c 100644
--- a/drivers/usb/host/isp116x.h
+++ b/drivers/usb/host/isp116x.h
@@ -233,7 +233,7 @@ static const int cc_to_error[16] = {
233 /* Bit Stuff */ -EPROTO, 233 /* Bit Stuff */ -EPROTO,
234 /* Data Togg */ -EILSEQ, 234 /* Data Togg */ -EILSEQ,
235 /* Stall */ -EPIPE, 235 /* Stall */ -EPIPE,
236 /* DevNotResp */ -ETIMEDOUT, 236 /* DevNotResp */ -ETIME,
237 /* PIDCheck */ -EPROTO, 237 /* PIDCheck */ -EPROTO,
238 /* UnExpPID */ -EPROTO, 238 /* UnExpPID */ -EPROTO,
239 /* DataOver */ -EOVERFLOW, 239 /* DataOver */ -EOVERFLOW,
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 85cc059705a6..b466581beb4a 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -193,7 +193,7 @@ ohci_at91_start (struct usb_hcd *hcd)
193 if ((ret = ohci_init(ohci)) < 0) 193 if ((ret = ohci_init(ohci)) < 0)
194 return ret; 194 return ret;
195 195
196 root->maxchild = board->ports; 196 ohci->num_ports = board->ports;
197 197
198 if ((ret = ohci_run(ohci)) < 0) { 198 if ((ret = ohci_run(ohci)) < 0) {
199 err("can't start %s", hcd->self.bus_name); 199 err("can't start %s", hcd->self.bus_name);
@@ -221,6 +221,7 @@ static const struct hc_driver ohci_at91_hc_driver = {
221 */ 221 */
222 .start = ohci_at91_start, 222 .start = ohci_at91_start,
223 .stop = ohci_stop, 223 .stop = ohci_stop,
224 .shutdown = ohci_shutdown,
224 225
225 /* 226 /*
226 * managing i/o requests and associated device resources 227 * managing i/o requests and associated device resources
@@ -239,7 +240,7 @@ static const struct hc_driver ohci_at91_hc_driver = {
239 */ 240 */
240 .hub_status_data = ohci_hub_status_data, 241 .hub_status_data = ohci_hub_status_data,
241 .hub_control = ohci_hub_control, 242 .hub_control = ohci_hub_control,
242 243 .hub_irq_enable = ohci_rhsc_enable,
243#ifdef CONFIG_PM 244#ifdef CONFIG_PM
244 .bus_suspend = ohci_bus_suspend, 245 .bus_suspend = ohci_bus_suspend,
245 .bus_resume = ohci_bus_resume, 246 .bus_resume = ohci_bus_resume,
@@ -296,6 +297,7 @@ static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
296 if (!clocked) { 297 if (!clocked) {
297 clk_enable(iclk); 298 clk_enable(iclk);
298 clk_enable(fclk); 299 clk_enable(fclk);
300 clocked = 1;
299 } 301 }
300 302
301 return 0; 303 return 0;
@@ -310,6 +312,7 @@ MODULE_ALIAS("at91_ohci");
310static struct platform_driver ohci_hcd_at91_driver = { 312static struct platform_driver ohci_hcd_at91_driver = {
311 .probe = ohci_hcd_at91_drv_probe, 313 .probe = ohci_hcd_at91_drv_probe,
312 .remove = ohci_hcd_at91_drv_remove, 314 .remove = ohci_hcd_at91_drv_remove,
315 .shutdown = usb_hcd_platform_shutdown,
313 .suspend = ohci_hcd_at91_drv_suspend, 316 .suspend = ohci_hcd_at91_drv_suspend,
314 .resume = ohci_hcd_at91_drv_resume, 317 .resume = ohci_hcd_at91_drv_resume,
315 .driver = { 318 .driver = {
diff --git a/drivers/usb/host/ohci-au1xxx.c b/drivers/usb/host/ohci-au1xxx.c
index f7a975d5db09..24e23c5783d8 100644
--- a/drivers/usb/host/ohci-au1xxx.c
+++ b/drivers/usb/host/ohci-au1xxx.c
@@ -268,11 +268,8 @@ static const struct hc_driver ohci_au1xxx_hc_driver = {
268 * basic lifecycle operations 268 * basic lifecycle operations
269 */ 269 */
270 .start = ohci_au1xxx_start, 270 .start = ohci_au1xxx_start,
271#ifdef CONFIG_PM
272 /* suspend: ohci_au1xxx_suspend, -- tbd */
273 /* resume: ohci_au1xxx_resume, -- tbd */
274#endif /*CONFIG_PM*/
275 .stop = ohci_stop, 271 .stop = ohci_stop,
272 .shutdown = ohci_shutdown,
276 273
277 /* 274 /*
278 * managing i/o requests and associated device resources 275 * managing i/o requests and associated device resources
@@ -291,6 +288,7 @@ static const struct hc_driver ohci_au1xxx_hc_driver = {
291 */ 288 */
292 .hub_status_data = ohci_hub_status_data, 289 .hub_status_data = ohci_hub_status_data,
293 .hub_control = ohci_hub_control, 290 .hub_control = ohci_hub_control,
291 .hub_irq_enable = ohci_rhsc_enable,
294#ifdef CONFIG_PM 292#ifdef CONFIG_PM
295 .bus_suspend = ohci_bus_suspend, 293 .bus_suspend = ohci_bus_suspend,
296 .bus_resume = ohci_bus_resume, 294 .bus_resume = ohci_bus_resume,
@@ -338,6 +336,7 @@ static int ohci_hcd_au1xxx_drv_resume(struct platform_device *dev)
338static struct platform_driver ohci_hcd_au1xxx_driver = { 336static struct platform_driver ohci_hcd_au1xxx_driver = {
339 .probe = ohci_hcd_au1xxx_drv_probe, 337 .probe = ohci_hcd_au1xxx_drv_probe,
340 .remove = ohci_hcd_au1xxx_drv_remove, 338 .remove = ohci_hcd_au1xxx_drv_remove,
339 .shutdown = usb_hcd_platform_shutdown,
341 /*.suspend = ohci_hcd_au1xxx_drv_suspend, */ 340 /*.suspend = ohci_hcd_au1xxx_drv_suspend, */
342 /*.resume = ohci_hcd_au1xxx_drv_resume, */ 341 /*.resume = ohci_hcd_au1xxx_drv_resume, */
343 .driver = { 342 .driver = {
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index 7bfffcbbd226..8293c1d4be3f 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -477,7 +477,7 @@ show_async (struct class_device *class_dev, char *buf)
477 unsigned long flags; 477 unsigned long flags;
478 478
479 bus = class_get_devdata(class_dev); 479 bus = class_get_devdata(class_dev);
480 hcd = bus->hcpriv; 480 hcd = bus_to_hcd(bus);
481 ohci = hcd_to_ohci(hcd); 481 ohci = hcd_to_ohci(hcd);
482 482
483 /* display control and bulk lists together, for simplicity */ 483 /* display control and bulk lists together, for simplicity */
@@ -510,7 +510,7 @@ show_periodic (struct class_device *class_dev, char *buf)
510 seen_count = 0; 510 seen_count = 0;
511 511
512 bus = class_get_devdata(class_dev); 512 bus = class_get_devdata(class_dev);
513 hcd = bus->hcpriv; 513 hcd = bus_to_hcd(bus);
514 ohci = hcd_to_ohci(hcd); 514 ohci = hcd_to_ohci(hcd);
515 next = buf; 515 next = buf;
516 size = PAGE_SIZE; 516 size = PAGE_SIZE;
@@ -607,7 +607,7 @@ show_registers (struct class_device *class_dev, char *buf)
607 u32 rdata; 607 u32 rdata;
608 608
609 bus = class_get_devdata(class_dev); 609 bus = class_get_devdata(class_dev);
610 hcd = bus->hcpriv; 610 hcd = bus_to_hcd(bus);
611 ohci = hcd_to_ohci(hcd); 611 ohci = hcd_to_ohci(hcd);
612 regs = ohci->regs; 612 regs = ohci->regs;
613 next = buf; 613 next = buf;
@@ -667,6 +667,11 @@ show_registers (struct class_device *class_dev, char *buf)
667 size -= temp; 667 size -= temp;
668 next += temp; 668 next += temp;
669 669
670 temp = scnprintf (next, size, "hub poll timer %s\n",
671 ohci_to_hcd(ohci)->poll_rh ? "ON" : "off");
672 size -= temp;
673 next += temp;
674
670 /* roothub */ 675 /* roothub */
671 ohci_dump_roothub (ohci, 1, &next, &size); 676 ohci_dump_roothub (ohci, 1, &next, &size);
672 677
@@ -680,10 +685,11 @@ static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
680static inline void create_debug_files (struct ohci_hcd *ohci) 685static inline void create_debug_files (struct ohci_hcd *ohci)
681{ 686{
682 struct class_device *cldev = ohci_to_hcd(ohci)->self.class_dev; 687 struct class_device *cldev = ohci_to_hcd(ohci)->self.class_dev;
688 int retval;
683 689
684 class_device_create_file(cldev, &class_device_attr_async); 690 retval = class_device_create_file(cldev, &class_device_attr_async);
685 class_device_create_file(cldev, &class_device_attr_periodic); 691 retval = class_device_create_file(cldev, &class_device_attr_periodic);
686 class_device_create_file(cldev, &class_device_attr_registers); 692 retval = class_device_create_file(cldev, &class_device_attr_registers);
687 ohci_dbg (ohci, "created debug files\n"); 693 ohci_dbg (ohci, "created debug files\n");
688} 694}
689 695
diff --git a/drivers/usb/host/ohci-ep93xx.c b/drivers/usb/host/ohci-ep93xx.c
index 6531c4d26527..1bf5e7a4e735 100644
--- a/drivers/usb/host/ohci-ep93xx.c
+++ b/drivers/usb/host/ohci-ep93xx.c
@@ -128,12 +128,14 @@ static struct hc_driver ohci_ep93xx_hc_driver = {
128 .flags = HCD_USB11 | HCD_MEMORY, 128 .flags = HCD_USB11 | HCD_MEMORY,
129 .start = ohci_ep93xx_start, 129 .start = ohci_ep93xx_start,
130 .stop = ohci_stop, 130 .stop = ohci_stop,
131 .shutdown = ohci_shutdown,
131 .urb_enqueue = ohci_urb_enqueue, 132 .urb_enqueue = ohci_urb_enqueue,
132 .urb_dequeue = ohci_urb_dequeue, 133 .urb_dequeue = ohci_urb_dequeue,
133 .endpoint_disable = ohci_endpoint_disable, 134 .endpoint_disable = ohci_endpoint_disable,
134 .get_frame_number = ohci_get_frame, 135 .get_frame_number = ohci_get_frame,
135 .hub_status_data = ohci_hub_status_data, 136 .hub_status_data = ohci_hub_status_data,
136 .hub_control = ohci_hub_control, 137 .hub_control = ohci_hub_control,
138 .hub_irq_enable = ohci_rhsc_enable,
137#ifdef CONFIG_PM 139#ifdef CONFIG_PM
138 .bus_suspend = ohci_bus_suspend, 140 .bus_suspend = ohci_bus_suspend,
139 .bus_resume = ohci_bus_resume, 141 .bus_resume = ohci_bus_resume,
@@ -202,6 +204,7 @@ static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
202static struct platform_driver ohci_hcd_ep93xx_driver = { 204static struct platform_driver ohci_hcd_ep93xx_driver = {
203 .probe = ohci_hcd_ep93xx_drv_probe, 205 .probe = ohci_hcd_ep93xx_drv_probe,
204 .remove = ohci_hcd_ep93xx_drv_remove, 206 .remove = ohci_hcd_ep93xx_drv_remove,
207 .shutdown = usb_hcd_platform_shutdown,
205#ifdef CONFIG_PM 208#ifdef CONFIG_PM
206 .suspend = ohci_hcd_ep93xx_drv_suspend, 209 .suspend = ohci_hcd_ep93xx_drv_suspend,
207 .resume = ohci_hcd_ep93xx_drv_resume, 210 .resume = ohci_hcd_ep93xx_drv_resume,
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 94d8cf4b36c1..d1d68c402251 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -88,7 +88,7 @@
88#include <linux/timer.h> 88#include <linux/timer.h>
89#include <linux/list.h> 89#include <linux/list.h>
90#include <linux/usb.h> 90#include <linux/usb.h>
91#include <linux/usb_otg.h> 91#include <linux/usb/otg.h>
92#include <linux/dma-mapping.h> 92#include <linux/dma-mapping.h>
93#include <linux/dmapool.h> 93#include <linux/dmapool.h>
94#include <linux/reboot.h> 94#include <linux/reboot.h>
@@ -101,7 +101,7 @@
101 101
102#include "../core/hcd.h" 102#include "../core/hcd.h"
103 103
104#define DRIVER_VERSION "2005 April 22" 104#define DRIVER_VERSION "2006 August 04"
105#define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell" 105#define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
106#define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver" 106#define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
107 107
@@ -110,9 +110,10 @@
110#undef OHCI_VERBOSE_DEBUG /* not always helpful */ 110#undef OHCI_VERBOSE_DEBUG /* not always helpful */
111 111
112/* For initializing controller (mask in an HCFS mode too) */ 112/* For initializing controller (mask in an HCFS mode too) */
113#define OHCI_CONTROL_INIT OHCI_CTRL_CBSR 113#define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
114#define OHCI_INTR_INIT \ 114#define OHCI_INTR_INIT \
115 (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_WDH) 115 (OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \
116 | OHCI_INTR_RD | OHCI_INTR_WDH)
116 117
117#ifdef __hppa__ 118#ifdef __hppa__
118/* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */ 119/* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
@@ -128,12 +129,13 @@
128 129
129static const char hcd_name [] = "ohci_hcd"; 130static const char hcd_name [] = "ohci_hcd";
130 131
132#define STATECHANGE_DELAY msecs_to_jiffies(300)
133
131#include "ohci.h" 134#include "ohci.h"
132 135
133static void ohci_dump (struct ohci_hcd *ohci, int verbose); 136static void ohci_dump (struct ohci_hcd *ohci, int verbose);
134static int ohci_init (struct ohci_hcd *ohci); 137static int ohci_init (struct ohci_hcd *ohci);
135static void ohci_stop (struct usb_hcd *hcd); 138static void ohci_stop (struct usb_hcd *hcd);
136static int ohci_reboot (struct notifier_block *, unsigned long , void *);
137 139
138#include "ohci-hub.c" 140#include "ohci-hub.c"
139#include "ohci-dbg.c" 141#include "ohci-dbg.c"
@@ -416,21 +418,20 @@ static void ohci_usb_reset (struct ohci_hcd *ohci)
416 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 418 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
417} 419}
418 420
419/* reboot notifier forcibly disables IRQs and DMA, helping kexec and 421/* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
420 * other cases where the next software may expect clean state from the 422 * other cases where the next software may expect clean state from the
421 * "firmware". this is bus-neutral, unlike shutdown() methods. 423 * "firmware". this is bus-neutral, unlike shutdown() methods.
422 */ 424 */
423static int 425static void
424ohci_reboot (struct notifier_block *block, unsigned long code, void *null) 426ohci_shutdown (struct usb_hcd *hcd)
425{ 427{
426 struct ohci_hcd *ohci; 428 struct ohci_hcd *ohci;
427 429
428 ohci = container_of (block, struct ohci_hcd, reboot_notifier); 430 ohci = hcd_to_ohci (hcd);
429 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 431 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
430 ohci_usb_reset (ohci); 432 ohci_usb_reset (ohci);
431 /* flush the writes */ 433 /* flush the writes */
432 (void) ohci_readl (ohci, &ohci->regs->control); 434 (void) ohci_readl (ohci, &ohci->regs->control);
433 return 0;
434} 435}
435 436
436/*-------------------------------------------------------------------------* 437/*-------------------------------------------------------------------------*
@@ -446,7 +447,6 @@ static int ohci_init (struct ohci_hcd *ohci)
446 447
447 disable (ohci); 448 disable (ohci);
448 ohci->regs = hcd->regs; 449 ohci->regs = hcd->regs;
449 ohci->next_statechange = jiffies;
450 450
451 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and 451 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
452 * was never needed for most non-PCI systems ... remove the code? 452 * was never needed for most non-PCI systems ... remove the code?
@@ -502,7 +502,6 @@ static int ohci_init (struct ohci_hcd *ohci)
502 if ((ret = ohci_mem_init (ohci)) < 0) 502 if ((ret = ohci_mem_init (ohci)) < 0)
503 ohci_stop (hcd); 503 ohci_stop (hcd);
504 else { 504 else {
505 register_reboot_notifier (&ohci->reboot_notifier);
506 create_debug_files (ohci); 505 create_debug_files (ohci);
507 } 506 }
508 507
@@ -637,10 +636,14 @@ retry:
637 return -EOVERFLOW; 636 return -EOVERFLOW;
638 } 637 }
639 638
640 /* start controller operations */ 639 /* use rhsc irqs after khubd is fully initialized */
640 hcd->poll_rh = 1;
641 hcd->uses_new_polling = 1;
642
643 /* start controller operations */
641 ohci->hc_control &= OHCI_CTRL_RWC; 644 ohci->hc_control &= OHCI_CTRL_RWC;
642 ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER; 645 ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
643 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 646 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
644 hcd->state = HC_STATE_RUNNING; 647 hcd->state = HC_STATE_RUNNING;
645 648
646 /* wake on ConnectStatusChange, matching external hubs */ 649 /* wake on ConnectStatusChange, matching external hubs */
@@ -648,7 +651,7 @@ retry:
648 651
649 /* Choose the interrupts we care about now, others later on demand */ 652 /* Choose the interrupts we care about now, others later on demand */
650 mask = OHCI_INTR_INIT; 653 mask = OHCI_INTR_INIT;
651 ohci_writel (ohci, mask, &ohci->regs->intrstatus); 654 ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
652 ohci_writel (ohci, mask, &ohci->regs->intrenable); 655 ohci_writel (ohci, mask, &ohci->regs->intrenable);
653 656
654 /* handle root hub init quirks ... */ 657 /* handle root hub init quirks ... */
@@ -672,6 +675,7 @@ retry:
672 // flush those writes 675 // flush those writes
673 (void) ohci_readl (ohci, &ohci->regs->control); 676 (void) ohci_readl (ohci, &ohci->regs->control);
674 677
678 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
675 spin_unlock_irq (&ohci->lock); 679 spin_unlock_irq (&ohci->lock);
676 680
677 // POTPGT delay is bits 24-31, in 2 ms units. 681 // POTPGT delay is bits 24-31, in 2 ms units.
@@ -709,7 +713,14 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd, struct pt_regs *ptregs)
709 /* interrupt for some other device? */ 713 /* interrupt for some other device? */
710 } else if ((ints &= ohci_readl (ohci, &regs->intrenable)) == 0) { 714 } else if ((ints &= ohci_readl (ohci, &regs->intrenable)) == 0) {
711 return IRQ_NOTMINE; 715 return IRQ_NOTMINE;
712 } 716 }
717
718 if (ints & OHCI_INTR_RHSC) {
719 ohci_vdbg (ohci, "rhsc\n");
720 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
721 ohci_writel (ohci, OHCI_INTR_RHSC, &regs->intrstatus);
722 usb_hcd_poll_rh_status(hcd);
723 }
713 724
714 if (ints & OHCI_INTR_UE) { 725 if (ints & OHCI_INTR_UE) {
715 disable (ohci); 726 disable (ohci);
@@ -723,13 +734,18 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd, struct pt_regs *ptregs)
723 if (ints & OHCI_INTR_RD) { 734 if (ints & OHCI_INTR_RD) {
724 ohci_vdbg (ohci, "resume detect\n"); 735 ohci_vdbg (ohci, "resume detect\n");
725 ohci_writel (ohci, OHCI_INTR_RD, &regs->intrstatus); 736 ohci_writel (ohci, OHCI_INTR_RD, &regs->intrstatus);
726 if (hcd->state != HC_STATE_QUIESCING) 737 hcd->poll_rh = 1;
738 if (ohci->autostop) {
739 spin_lock (&ohci->lock);
740 ohci_rh_resume (ohci);
741 spin_unlock (&ohci->lock);
742 } else
727 usb_hcd_resume_root_hub(hcd); 743 usb_hcd_resume_root_hub(hcd);
728 } 744 }
729 745
730 if (ints & OHCI_INTR_WDH) { 746 if (ints & OHCI_INTR_WDH) {
731 if (HC_IS_RUNNING(hcd->state)) 747 if (HC_IS_RUNNING(hcd->state))
732 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrdisable); 748 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrdisable);
733 spin_lock (&ohci->lock); 749 spin_lock (&ohci->lock);
734 dl_done_list (ohci, ptregs); 750 dl_done_list (ohci, ptregs);
735 spin_unlock (&ohci->lock); 751 spin_unlock (&ohci->lock);
@@ -775,9 +791,10 @@ static void ohci_stop (struct usb_hcd *hcd)
775 791
776 ohci_usb_reset (ohci); 792 ohci_usb_reset (ohci);
777 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 793 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
778 794 free_irq(hcd->irq, hcd);
795 hcd->irq = -1;
796
779 remove_debug_files (ohci); 797 remove_debug_files (ohci);
780 unregister_reboot_notifier (&ohci->reboot_notifier);
781 ohci_mem_cleanup (ohci); 798 ohci_mem_cleanup (ohci);
782 if (ohci->hcca) { 799 if (ohci->hcca) {
783 dma_free_coherent (hcd->self.controller, 800 dma_free_coherent (hcd->self.controller,
@@ -917,6 +934,10 @@ MODULE_LICENSE ("GPL");
917#include "ohci-at91.c" 934#include "ohci-at91.c"
918#endif 935#endif
919 936
937#ifdef CONFIG_ARCH_PNX4008
938#include "ohci-pnx4008.c"
939#endif
940
920#if !(defined(CONFIG_PCI) \ 941#if !(defined(CONFIG_PCI) \
921 || defined(CONFIG_SA1111) \ 942 || defined(CONFIG_SA1111) \
922 || defined(CONFIG_ARCH_S3C2410) \ 943 || defined(CONFIG_ARCH_S3C2410) \
@@ -928,6 +949,7 @@ MODULE_LICENSE ("GPL");
928 || defined (CONFIG_USB_OHCI_HCD_PPC_SOC) \ 949 || defined (CONFIG_USB_OHCI_HCD_PPC_SOC) \
929 || defined (CONFIG_ARCH_AT91RM9200) \ 950 || defined (CONFIG_ARCH_AT91RM9200) \
930 || defined (CONFIG_ARCH_AT91SAM9261) \ 951 || defined (CONFIG_ARCH_AT91SAM9261) \
952 || defined (CONFIG_ARCH_PNX4008) \
931 ) 953 )
932#error "missing bus glue for ohci-hcd" 954#error "missing bus glue for ohci-hcd"
933#endif 955#endif
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index 5b0a23fd798b..ec75774abeac 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -36,27 +36,25 @@
36 36
37/*-------------------------------------------------------------------------*/ 37/*-------------------------------------------------------------------------*/
38 38
39#ifdef CONFIG_PM 39/* hcd->hub_irq_enable() */
40static void ohci_rhsc_enable (struct usb_hcd *hcd)
41{
42 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
43
44 ohci_writel (ohci, OHCI_INTR_RHSC, &ohci->regs->intrenable);
45}
40 46
41#define OHCI_SCHED_ENABLES \ 47#define OHCI_SCHED_ENABLES \
42 (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE) 48 (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE)
43 49
44static void dl_done_list (struct ohci_hcd *, struct pt_regs *); 50static void dl_done_list (struct ohci_hcd *, struct pt_regs *);
45static void finish_unlinks (struct ohci_hcd *, u16 , struct pt_regs *); 51static void finish_unlinks (struct ohci_hcd *, u16 , struct pt_regs *);
46static int ohci_restart (struct ohci_hcd *ohci);
47 52
48static int ohci_bus_suspend (struct usb_hcd *hcd) 53static int ohci_rh_suspend (struct ohci_hcd *ohci, int autostop)
54__releases(ohci->lock)
55__acquires(ohci->lock)
49{ 56{
50 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
51 int status = 0; 57 int status = 0;
52 unsigned long flags;
53
54 spin_lock_irqsave (&ohci->lock, flags);
55
56 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) {
57 spin_unlock_irqrestore (&ohci->lock, flags);
58 return -ESHUTDOWN;
59 }
60 58
61 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 59 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
62 switch (ohci->hc_control & OHCI_CTRL_HCFS) { 60 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
@@ -72,15 +70,16 @@ static int ohci_bus_suspend (struct usb_hcd *hcd)
72 ohci_dbg (ohci, "needs reinit!\n"); 70 ohci_dbg (ohci, "needs reinit!\n");
73 goto done; 71 goto done;
74 case OHCI_USB_SUSPEND: 72 case OHCI_USB_SUSPEND:
75 ohci_dbg (ohci, "already suspended\n"); 73 if (!ohci->autostop) {
76 goto done; 74 ohci_dbg (ohci, "already suspended\n");
75 goto done;
76 }
77 } 77 }
78 ohci_dbg (ohci, "suspend root hub\n"); 78 ohci_dbg (ohci, "%s root hub\n",
79 autostop ? "auto-stop" : "suspend");
79 80
80 /* First stop any processing */ 81 /* First stop any processing */
81 if (ohci->hc_control & OHCI_SCHED_ENABLES) { 82 if (!autostop && (ohci->hc_control & OHCI_SCHED_ENABLES)) {
82 int limit;
83
84 ohci->hc_control &= ~OHCI_SCHED_ENABLES; 83 ohci->hc_control &= ~OHCI_SCHED_ENABLES;
85 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 84 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
86 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 85 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
@@ -90,27 +89,22 @@ static int ohci_bus_suspend (struct usb_hcd *hcd)
90 * then the last WDH could take 6+ msec 89 * then the last WDH could take 6+ msec
91 */ 90 */
92 ohci_dbg (ohci, "stopping schedules ...\n"); 91 ohci_dbg (ohci, "stopping schedules ...\n");
93 limit = 2000; 92 ohci->autostop = 0;
94 while (limit > 0) { 93 spin_unlock_irq (&ohci->lock);
95 udelay (250); 94 msleep (8);
96 limit =- 250; 95 spin_lock_irq (&ohci->lock);
97 if (ohci_readl (ohci, &ohci->regs->intrstatus)
98 & OHCI_INTR_SF)
99 break;
100 }
101 dl_done_list (ohci, NULL);
102 mdelay (7);
103 } 96 }
104 dl_done_list (ohci, NULL); 97 dl_done_list (ohci, NULL);
105 finish_unlinks (ohci, ohci_frame_no(ohci), NULL); 98 finish_unlinks (ohci, ohci_frame_no(ohci), NULL);
106 ohci_writel (ohci, ohci_readl (ohci, &ohci->regs->intrstatus),
107 &ohci->regs->intrstatus);
108 99
109 /* maybe resume can wake root hub */ 100 /* maybe resume can wake root hub */
110 if (device_may_wakeup(&ohci_to_hcd(ohci)->self.root_hub->dev)) 101 if (device_may_wakeup(&ohci_to_hcd(ohci)->self.root_hub->dev) ||
102 autostop)
111 ohci->hc_control |= OHCI_CTRL_RWE; 103 ohci->hc_control |= OHCI_CTRL_RWE;
112 else 104 else {
105 ohci_writel (ohci, OHCI_INTR_RHSC, &ohci->regs->intrdisable);
113 ohci->hc_control &= ~OHCI_CTRL_RWE; 106 ohci->hc_control &= ~OHCI_CTRL_RWE;
107 }
114 108
115 /* Suspend hub ... this is the "global (to this bus) suspend" mode, 109 /* Suspend hub ... this is the "global (to this bus) suspend" mode,
116 * which doesn't imply ports will first be individually suspended. 110 * which doesn't imply ports will first be individually suspended.
@@ -121,13 +115,12 @@ static int ohci_bus_suspend (struct usb_hcd *hcd)
121 (void) ohci_readl (ohci, &ohci->regs->control); 115 (void) ohci_readl (ohci, &ohci->regs->control);
122 116
123 /* no resumes until devices finish suspending */ 117 /* no resumes until devices finish suspending */
124 ohci->next_statechange = jiffies + msecs_to_jiffies (5); 118 if (!autostop) {
119 ohci->next_statechange = jiffies + msecs_to_jiffies (5);
120 ohci->autostop = 0;
121 }
125 122
126done: 123done:
127 /* external suspend vs self autosuspend ... same effect */
128 if (status == 0)
129 usb_hcd_suspend_root_hub(hcd);
130 spin_unlock_irqrestore (&ohci->lock, flags);
131 return status; 124 return status;
132} 125}
133 126
@@ -139,25 +132,19 @@ static inline struct ed *find_head (struct ed *ed)
139 return ed; 132 return ed;
140} 133}
141 134
135static int ohci_restart (struct ohci_hcd *ohci);
136
142/* caller has locked the root hub */ 137/* caller has locked the root hub */
143static int ohci_bus_resume (struct usb_hcd *hcd) 138static int ohci_rh_resume (struct ohci_hcd *ohci)
139__releases(ohci->lock)
140__acquires(ohci->lock)
144{ 141{
145 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 142 struct usb_hcd *hcd = ohci_to_hcd (ohci);
146 u32 temp, enables; 143 u32 temp, enables;
147 int status = -EINPROGRESS; 144 int status = -EINPROGRESS;
148 unsigned long flags; 145 int autostopped = ohci->autostop;
149
150 if (time_before (jiffies, ohci->next_statechange))
151 msleep(5);
152
153 spin_lock_irqsave (&ohci->lock, flags);
154
155 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) {
156 spin_unlock_irqrestore (&ohci->lock, flags);
157 return -ESHUTDOWN;
158 }
159
160 146
147 ohci->autostop = 0;
161 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 148 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
162 149
163 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) { 150 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
@@ -177,7 +164,8 @@ static int ohci_bus_resume (struct usb_hcd *hcd)
177 ohci->hc_control |= OHCI_USB_RESUME; 164 ohci->hc_control |= OHCI_USB_RESUME;
178 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 165 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
179 (void) ohci_readl (ohci, &ohci->regs->control); 166 (void) ohci_readl (ohci, &ohci->regs->control);
180 ohci_dbg (ohci, "resume root hub\n"); 167 ohci_dbg (ohci, "%s root hub\n",
168 autostopped ? "auto-start" : "resume");
181 break; 169 break;
182 case OHCI_USB_RESUME: 170 case OHCI_USB_RESUME:
183 /* HCFS changes sometime after INTR_RD */ 171 /* HCFS changes sometime after INTR_RD */
@@ -192,16 +180,24 @@ static int ohci_bus_resume (struct usb_hcd *hcd)
192 ohci_dbg (ohci, "lost power\n"); 180 ohci_dbg (ohci, "lost power\n");
193 status = -EBUSY; 181 status = -EBUSY;
194 } 182 }
195 spin_unlock_irqrestore (&ohci->lock, flags); 183#ifdef CONFIG_PM
196 if (status == -EBUSY) { 184 if (status == -EBUSY) {
197 (void) ohci_init (ohci); 185 if (!autostopped) {
198 return ohci_restart (ohci); 186 spin_unlock_irq (&ohci->lock);
187 (void) ohci_init (ohci);
188 status = ohci_restart (ohci);
189 spin_lock_irq (&ohci->lock);
190 }
191 return status;
199 } 192 }
193#endif
200 if (status != -EINPROGRESS) 194 if (status != -EINPROGRESS)
201 return status; 195 return status;
196 if (autostopped)
197 goto skip_resume;
198 spin_unlock_irq (&ohci->lock);
202 199
203 temp = ohci->num_ports; 200 temp = ohci->num_ports;
204 enables = 0;
205 while (temp--) { 201 while (temp--) {
206 u32 stat = ohci_readl (ohci, 202 u32 stat = ohci_readl (ohci,
207 &ohci->regs->roothub.portstatus [temp]); 203 &ohci->regs->roothub.portstatus [temp]);
@@ -234,17 +230,21 @@ static int ohci_bus_resume (struct usb_hcd *hcd)
234 /* Sometimes PCI D3 suspend trashes frame timings ... */ 230 /* Sometimes PCI D3 suspend trashes frame timings ... */
235 periodic_reinit (ohci); 231 periodic_reinit (ohci);
236 232
233 /* the following code is executed with ohci->lock held and
234 * irqs disabled if and only if autostopped is true
235 */
236
237skip_resume:
237 /* interrupts might have been disabled */ 238 /* interrupts might have been disabled */
238 ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable); 239 ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable);
239 if (ohci->ed_rm_list) 240 if (ohci->ed_rm_list)
240 ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable); 241 ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable);
241 ohci_writel (ohci, ohci_readl (ohci, &ohci->regs->intrstatus),
242 &ohci->regs->intrstatus);
243 242
244 /* Then re-enable operations */ 243 /* Then re-enable operations */
245 ohci_writel (ohci, OHCI_USB_OPER, &ohci->regs->control); 244 ohci_writel (ohci, OHCI_USB_OPER, &ohci->regs->control);
246 (void) ohci_readl (ohci, &ohci->regs->control); 245 (void) ohci_readl (ohci, &ohci->regs->control);
247 msleep (3); 246 if (!autostopped)
247 msleep (3);
248 248
249 temp = ohci->hc_control; 249 temp = ohci->hc_control;
250 temp &= OHCI_CTRL_RWC; 250 temp &= OHCI_CTRL_RWC;
@@ -254,10 +254,14 @@ static int ohci_bus_resume (struct usb_hcd *hcd)
254 (void) ohci_readl (ohci, &ohci->regs->control); 254 (void) ohci_readl (ohci, &ohci->regs->control);
255 255
256 /* TRSMRCY */ 256 /* TRSMRCY */
257 msleep (10); 257 if (!autostopped) {
258 msleep (10);
259 spin_lock_irq (&ohci->lock);
260 }
261 /* now ohci->lock is always held and irqs are always disabled */
258 262
259 /* keep it alive for ~5x suspend + resume costs */ 263 /* keep it alive for more than ~5x suspend + resume costs */
260 ohci->next_statechange = jiffies + msecs_to_jiffies (250); 264 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
261 265
262 /* maybe turn schedules back on */ 266 /* maybe turn schedules back on */
263 enables = 0; 267 enables = 0;
@@ -291,6 +295,45 @@ static int ohci_bus_resume (struct usb_hcd *hcd)
291 return 0; 295 return 0;
292} 296}
293 297
298#ifdef CONFIG_PM
299
300static int ohci_bus_suspend (struct usb_hcd *hcd)
301{
302 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
303 int rc;
304
305 spin_lock_irq (&ohci->lock);
306
307 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
308 rc = -ESHUTDOWN;
309 else
310 rc = ohci_rh_suspend (ohci, 0);
311 spin_unlock_irq (&ohci->lock);
312 return rc;
313}
314
315static int ohci_bus_resume (struct usb_hcd *hcd)
316{
317 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
318 int rc;
319
320 if (time_before (jiffies, ohci->next_statechange))
321 msleep(5);
322
323 spin_lock_irq (&ohci->lock);
324
325 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
326 rc = -ESHUTDOWN;
327 else
328 rc = ohci_rh_resume (ohci);
329 spin_unlock_irq (&ohci->lock);
330
331 /* poll until we know a device is connected or we autostop */
332 if (rc == 0)
333 usb_hcd_poll_rh_status(hcd);
334 return rc;
335}
336
294#endif /* CONFIG_PM */ 337#endif /* CONFIG_PM */
295 338
296/*-------------------------------------------------------------------------*/ 339/*-------------------------------------------------------------------------*/
@@ -302,20 +345,11 @@ ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
302{ 345{
303 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 346 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
304 int i, changed = 0, length = 1; 347 int i, changed = 0, length = 1;
305 int can_suspend = device_may_wakeup(&hcd->self.root_hub->dev); 348 int any_connected = 0, rhsc_enabled = 1;
306 unsigned long flags; 349 unsigned long flags;
307 350
308 spin_lock_irqsave (&ohci->lock, flags); 351 spin_lock_irqsave (&ohci->lock, flags);
309 352
310 /* handle autosuspended root: finish resuming before
311 * letting khubd or root hub timer see state changes.
312 */
313 if (unlikely((ohci->hc_control & OHCI_CTRL_HCFS) != OHCI_USB_OPER
314 || !HC_IS_RUNNING(hcd->state))) {
315 can_suspend = 0;
316 goto done;
317 }
318
319 /* undocumented erratum seen on at least rev D */ 353 /* undocumented erratum seen on at least rev D */
320 if ((ohci->flags & OHCI_QUIRK_AMD756) 354 if ((ohci->flags & OHCI_QUIRK_AMD756)
321 && (roothub_a (ohci) & RH_A_NDP) > MAX_ROOT_PORTS) { 355 && (roothub_a (ohci) & RH_A_NDP) > MAX_ROOT_PORTS) {
@@ -339,6 +373,9 @@ ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
339 for (i = 0; i < ohci->num_ports; i++) { 373 for (i = 0; i < ohci->num_ports; i++) {
340 u32 status = roothub_portstatus (ohci, i); 374 u32 status = roothub_portstatus (ohci, i);
341 375
376 /* can't autostop if ports are connected */
377 any_connected |= (status & RH_PS_CCS);
378
342 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC 379 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
343 | RH_PS_OCIC | RH_PS_PRSC)) { 380 | RH_PS_OCIC | RH_PS_PRSC)) {
344 changed = 1; 381 changed = 1;
@@ -346,39 +383,72 @@ ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
346 buf [0] |= 1 << (i + 1); 383 buf [0] |= 1 << (i + 1);
347 else 384 else
348 buf [1] |= 1 << (i - 7); 385 buf [1] |= 1 << (i - 7);
349 continue;
350 } 386 }
351
352 /* can suspend if no ports are enabled; or if all all
353 * enabled ports are suspended AND remote wakeup is on.
354 */
355 if (!(status & RH_PS_CCS))
356 continue;
357 if ((status & RH_PS_PSS) && can_suspend)
358 continue;
359 can_suspend = 0;
360 } 387 }
361done:
362 spin_unlock_irqrestore (&ohci->lock, flags);
363 388
364#ifdef CONFIG_PM 389 /* NOTE: vendors didn't always make the same implementation
365 /* save power by suspending idle root hubs; 390 * choices for RHSC. Sometimes it triggers on an edge (like
366 * INTR_RD wakes us when there's work 391 * setting and maybe clearing a port status change bit); and
392 * it's level-triggered on other silicon, active until khubd
393 * clears all active port status change bits. If it's still
394 * set (level-triggered) we must disable it and rely on
395 * polling until khubd re-enables it.
367 */ 396 */
368 if (can_suspend 397 if (ohci_readl (ohci, &ohci->regs->intrstatus) & OHCI_INTR_RHSC) {
369 && !changed 398 ohci_writel (ohci, OHCI_INTR_RHSC, &ohci->regs->intrdisable);
370 && !ohci->ed_rm_list 399 (void) ohci_readl (ohci, &ohci->regs->intrdisable);
371 && ((OHCI_CTRL_HCFS | OHCI_SCHED_ENABLES) 400 rhsc_enabled = 0;
372 & ohci->hc_control)
373 == OHCI_USB_OPER
374 && time_after (jiffies, ohci->next_statechange)
375 && usb_trylock_device (hcd->self.root_hub) == 0
376 ) {
377 ohci_vdbg (ohci, "autosuspend\n");
378 (void) ohci_bus_suspend (hcd);
379 usb_unlock_device (hcd->self.root_hub);
380 } 401 }
381#endif 402 hcd->poll_rh = 1;
403
404 /* carry out appropriate state changes */
405 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
406
407 case OHCI_USB_OPER:
408 /* keep on polling until we know a device is connected
409 * and RHSC is enabled */
410 if (!ohci->autostop) {
411 if (any_connected) {
412 if (rhsc_enabled)
413 hcd->poll_rh = 0;
414 } else {
415 ohci->autostop = 1;
416 ohci->next_statechange = jiffies + HZ;
417 }
418
419 /* if no devices have been attached for one second, autostop */
420 } else {
421 if (changed || any_connected) {
422 ohci->autostop = 0;
423 ohci->next_statechange = jiffies +
424 STATECHANGE_DELAY;
425 } else if (time_after_eq (jiffies,
426 ohci->next_statechange)
427 && !ohci->ed_rm_list
428 && !(ohci->hc_control &
429 OHCI_SCHED_ENABLES)) {
430 ohci_rh_suspend (ohci, 1);
431 }
432 }
433 break;
434
435 /* if there is a port change, autostart or ask to be resumed */
436 case OHCI_USB_SUSPEND:
437 case OHCI_USB_RESUME:
438 if (changed) {
439 if (ohci->autostop)
440 ohci_rh_resume (ohci);
441 else
442 usb_hcd_resume_root_hub (hcd);
443 } else {
444 /* everything is idle, no need for polling */
445 hcd->poll_rh = 0;
446 }
447 break;
448 }
449
450done:
451 spin_unlock_irqrestore (&ohci->lock, flags);
382 452
383 return changed ? length : 0; 453 return changed ? length : 0;
384} 454}
@@ -550,9 +620,6 @@ static int ohci_hub_control (
550 break; 620 break;
551 case USB_PORT_FEAT_SUSPEND: 621 case USB_PORT_FEAT_SUSPEND:
552 temp = RH_PS_POCI; 622 temp = RH_PS_POCI;
553 if ((ohci->hc_control & OHCI_CTRL_HCFS)
554 != OHCI_USB_OPER)
555 usb_hcd_resume_root_hub(hcd);
556 break; 623 break;
557 case USB_PORT_FEAT_C_SUSPEND: 624 case USB_PORT_FEAT_C_SUSPEND:
558 temp = RH_PS_PSSC; 625 temp = RH_PS_PSSC;
diff --git a/drivers/usb/host/ohci-lh7a404.c b/drivers/usb/host/ohci-lh7a404.c
index 5602da9bd52c..e121d97ed91c 100644
--- a/drivers/usb/host/ohci-lh7a404.c
+++ b/drivers/usb/host/ohci-lh7a404.c
@@ -173,11 +173,8 @@ static const struct hc_driver ohci_lh7a404_hc_driver = {
173 * basic lifecycle operations 173 * basic lifecycle operations
174 */ 174 */
175 .start = ohci_lh7a404_start, 175 .start = ohci_lh7a404_start,
176#ifdef CONFIG_PM
177 /* suspend: ohci_lh7a404_suspend, -- tbd */
178 /* resume: ohci_lh7a404_resume, -- tbd */
179#endif /*CONFIG_PM*/
180 .stop = ohci_stop, 176 .stop = ohci_stop,
177 .shutdown = ohci_shutdown,
181 178
182 /* 179 /*
183 * managing i/o requests and associated device resources 180 * managing i/o requests and associated device resources
@@ -196,6 +193,7 @@ static const struct hc_driver ohci_lh7a404_hc_driver = {
196 */ 193 */
197 .hub_status_data = ohci_hub_status_data, 194 .hub_status_data = ohci_hub_status_data,
198 .hub_control = ohci_hub_control, 195 .hub_control = ohci_hub_control,
196 .hub_irq_enable = ohci_rhsc_enable,
199#ifdef CONFIG_PM 197#ifdef CONFIG_PM
200 .bus_suspend = ohci_bus_suspend, 198 .bus_suspend = ohci_bus_suspend,
201 .bus_resume = ohci_bus_resume, 199 .bus_resume = ohci_bus_resume,
@@ -244,6 +242,7 @@ static int ohci_hcd_lh7a404_drv_resume(struct platform_device *dev)
244static struct platform_driver ohci_hcd_lh7a404_driver = { 242static struct platform_driver ohci_hcd_lh7a404_driver = {
245 .probe = ohci_hcd_lh7a404_drv_probe, 243 .probe = ohci_hcd_lh7a404_drv_probe,
246 .remove = ohci_hcd_lh7a404_drv_remove, 244 .remove = ohci_hcd_lh7a404_drv_remove,
245 .shutdown = usb_hcd_platform_shutdown,
247 /*.suspend = ohci_hcd_lh7a404_drv_suspend, */ 246 /*.suspend = ohci_hcd_lh7a404_drv_suspend, */
248 /*.resume = ohci_hcd_lh7a404_drv_resume, */ 247 /*.resume = ohci_hcd_lh7a404_drv_resume, */
249 .driver = { 248 .driver = {
diff --git a/drivers/usb/host/ohci-mem.c b/drivers/usb/host/ohci-mem.c
index bfbe328a4788..d976614eebd3 100644
--- a/drivers/usb/host/ohci-mem.c
+++ b/drivers/usb/host/ohci-mem.c
@@ -28,7 +28,6 @@ static void ohci_hcd_init (struct ohci_hcd *ohci)
28 ohci->next_statechange = jiffies; 28 ohci->next_statechange = jiffies;
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 ohci->reboot_notifier.notifier_call = ohci_reboot;
32} 31}
33 32
34/*-------------------------------------------------------------------------*/ 33/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index c4c4babd4767..9c02177de50a 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -4,7 +4,7 @@
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2005 David Brownell 5 * (C) Copyright 2000-2005 David Brownell
6 * (C) Copyright 2002 Hewlett-Packard Company 6 * (C) Copyright 2002 Hewlett-Packard Company
7 * 7 *
8 * OMAP Bus Glue 8 * OMAP Bus Glue
9 * 9 *
10 * Modified for OMAP by Tony Lindgren <tony@atomide.com> 10 * Modified for OMAP by Tony Lindgren <tony@atomide.com>
@@ -66,15 +66,20 @@ extern int usb_disabled(void);
66extern int ocpi_enable(void); 66extern int ocpi_enable(void);
67 67
68static struct clk *usb_host_ck; 68static struct clk *usb_host_ck;
69static struct clk *usb_dc_ck;
70static int host_enabled;
71static int host_initialized;
69 72
70static void omap_ohci_clock_power(int on) 73static void omap_ohci_clock_power(int on)
71{ 74{
72 if (on) { 75 if (on) {
76 clk_enable(usb_dc_ck);
73 clk_enable(usb_host_ck); 77 clk_enable(usb_host_ck);
74 /* guesstimate for T5 == 1x 32K clock + APLL lock time */ 78 /* guesstimate for T5 == 1x 32K clock + APLL lock time */
75 udelay(100); 79 udelay(100);
76 } else { 80 } else {
77 clk_disable(usb_host_ck); 81 clk_disable(usb_host_ck);
82 clk_disable(usb_dc_ck);
78 } 83 }
79} 84}
80 85
@@ -87,14 +92,14 @@ static int omap_ohci_transceiver_power(int on)
87 if (on) { 92 if (on) {
88 if (machine_is_omap_innovator() && cpu_is_omap1510()) 93 if (machine_is_omap_innovator() && cpu_is_omap1510())
89 fpga_write(fpga_read(INNOVATOR_FPGA_CAM_USB_CONTROL) 94 fpga_write(fpga_read(INNOVATOR_FPGA_CAM_USB_CONTROL)
90 | ((1 << 5/*usb1*/) | (1 << 3/*usb2*/)), 95 | ((1 << 5/*usb1*/) | (1 << 3/*usb2*/)),
91 INNOVATOR_FPGA_CAM_USB_CONTROL); 96 INNOVATOR_FPGA_CAM_USB_CONTROL);
92 else if (machine_is_omap_osk()) 97 else if (machine_is_omap_osk())
93 tps65010_set_gpio_out_value(GPIO1, LOW); 98 tps65010_set_gpio_out_value(GPIO1, LOW);
94 } else { 99 } else {
95 if (machine_is_omap_innovator() && cpu_is_omap1510()) 100 if (machine_is_omap_innovator() && cpu_is_omap1510())
96 fpga_write(fpga_read(INNOVATOR_FPGA_CAM_USB_CONTROL) 101 fpga_write(fpga_read(INNOVATOR_FPGA_CAM_USB_CONTROL)
97 & ~((1 << 5/*usb1*/) | (1 << 3/*usb2*/)), 102 & ~((1 << 5/*usb1*/) | (1 << 3/*usb2*/)),
98 INNOVATOR_FPGA_CAM_USB_CONTROL); 103 INNOVATOR_FPGA_CAM_USB_CONTROL);
99 else if (machine_is_omap_osk()) 104 else if (machine_is_omap_osk())
100 tps65010_set_gpio_out_value(GPIO1, HIGH); 105 tps65010_set_gpio_out_value(GPIO1, HIGH);
@@ -103,6 +108,7 @@ static int omap_ohci_transceiver_power(int on)
103 return 0; 108 return 0;
104} 109}
105 110
111#ifdef CONFIG_ARCH_OMAP15XX
106/* 112/*
107 * OMAP-1510 specific Local Bus clock on/off 113 * OMAP-1510 specific Local Bus clock on/off
108 */ 114 */
@@ -121,8 +127,8 @@ static int omap_1510_local_bus_power(int on)
121/* 127/*
122 * OMAP-1510 specific Local Bus initialization 128 * OMAP-1510 specific Local Bus initialization
123 * NOTE: This assumes 32MB memory size in OMAP1510LB_MEMSIZE. 129 * NOTE: This assumes 32MB memory size in OMAP1510LB_MEMSIZE.
124 * See also arch/mach-omap/memory.h for __virt_to_dma() and 130 * See also arch/mach-omap/memory.h for __virt_to_dma() and
125 * __dma_to_virt() which need to match with the physical 131 * __dma_to_virt() which need to match with the physical
126 * Local Bus address below. 132 * Local Bus address below.
127 */ 133 */
128static int omap_1510_local_bus_init(void) 134static int omap_1510_local_bus_init(void)
@@ -130,7 +136,7 @@ static int omap_1510_local_bus_init(void)
130 unsigned int tlb; 136 unsigned int tlb;
131 unsigned long lbaddr, physaddr; 137 unsigned long lbaddr, physaddr;
132 138
133 omap_writel((omap_readl(OMAP1510_LB_CLOCK_DIV) & 0xfffffff8) | 0x4, 139 omap_writel((omap_readl(OMAP1510_LB_CLOCK_DIV) & 0xfffffff8) | 0x4,
134 OMAP1510_LB_CLOCK_DIV); 140 OMAP1510_LB_CLOCK_DIV);
135 141
136 /* Configure the Local Bus MMU table */ 142 /* Configure the Local Bus MMU table */
@@ -138,7 +144,7 @@ static int omap_1510_local_bus_init(void)
138 lbaddr = tlb * 0x00100000 + OMAP1510_LB_OFFSET; 144 lbaddr = tlb * 0x00100000 + OMAP1510_LB_OFFSET;
139 physaddr = tlb * 0x00100000 + PHYS_OFFSET; 145 physaddr = tlb * 0x00100000 + PHYS_OFFSET;
140 omap_writel((lbaddr & 0x0fffffff) >> 22, OMAP1510_LB_MMU_CAM_H); 146 omap_writel((lbaddr & 0x0fffffff) >> 22, OMAP1510_LB_MMU_CAM_H);
141 omap_writel(((lbaddr & 0x003ffc00) >> 6) | 0xc, 147 omap_writel(((lbaddr & 0x003ffc00) >> 6) | 0xc,
142 OMAP1510_LB_MMU_CAM_L); 148 OMAP1510_LB_MMU_CAM_L);
143 omap_writel(physaddr >> 16, OMAP1510_LB_MMU_RAM_H); 149 omap_writel(physaddr >> 16, OMAP1510_LB_MMU_RAM_H);
144 omap_writel((physaddr & 0x0000fc00) | 0x300, OMAP1510_LB_MMU_RAM_L); 150 omap_writel((physaddr & 0x0000fc00) | 0x300, OMAP1510_LB_MMU_RAM_L);
@@ -152,6 +158,10 @@ static int omap_1510_local_bus_init(void)
152 158
153 return 0; 159 return 0;
154} 160}
161#else
162#define omap_1510_local_bus_power(x) {}
163#define omap_1510_local_bus_init() {}
164#endif
155 165
156#ifdef CONFIG_USB_OTG 166#ifdef CONFIG_USB_OTG
157 167
@@ -173,13 +183,14 @@ static void start_hnp(struct ohci_hcd *ohci)
173 183
174/*-------------------------------------------------------------------------*/ 184/*-------------------------------------------------------------------------*/
175 185
176static int omap_start_hc(struct ohci_hcd *ohci, struct platform_device *pdev) 186static int ohci_omap_init(struct usb_hcd *hcd)
177{ 187{
178 struct omap_usb_config *config = pdev->dev.platform_data; 188 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
189 struct omap_usb_config *config = hcd->self.controller->platform_data;
179 int need_transceiver = (config->otg != 0); 190 int need_transceiver = (config->otg != 0);
180 int ret; 191 int ret;
181 192
182 dev_dbg(&pdev->dev, "starting USB Controller\n"); 193 dev_dbg(hcd->self.controller, "starting USB Controller\n");
183 194
184 if (config->otg) { 195 if (config->otg) {
185 ohci_to_hcd(ohci)->self.otg_port = config->otg; 196 ohci_to_hcd(ohci)->self.otg_port = config->otg;
@@ -200,7 +211,7 @@ static int omap_start_hc(struct ohci_hcd *ohci, struct platform_device *pdev)
200 if (ohci->transceiver) { 211 if (ohci->transceiver) {
201 int status = otg_set_host(ohci->transceiver, 212 int status = otg_set_host(ohci->transceiver,
202 &ohci_to_hcd(ohci)->self); 213 &ohci_to_hcd(ohci)->self);
203 dev_dbg(&pdev->dev, "init %s transceiver, status %d\n", 214 dev_dbg(hcd->self.controller, "init %s transceiver, status %d\n",
204 ohci->transceiver->label, status); 215 ohci->transceiver->label, status);
205 if (status) { 216 if (status) {
206 if (ohci->transceiver) 217 if (ohci->transceiver)
@@ -208,7 +219,7 @@ static int omap_start_hc(struct ohci_hcd *ohci, struct platform_device *pdev)
208 return status; 219 return status;
209 } 220 }
210 } else { 221 } else {
211 dev_err(&pdev->dev, "can't find transceiver\n"); 222 dev_err(hcd->self.controller, "can't find transceiver\n");
212 return -ENODEV; 223 return -ENODEV;
213 } 224 }
214 } 225 }
@@ -247,6 +258,10 @@ static int omap_start_hc(struct ohci_hcd *ohci, struct platform_device *pdev)
247 } 258 }
248 ohci_writel(ohci, rh, &ohci->regs->roothub.a); 259 ohci_writel(ohci, rh, &ohci->regs->roothub.a);
249 distrust_firmware = 0; 260 distrust_firmware = 0;
261 } else if (machine_is_nokia770()) {
262 /* We require a self-powered hub, which should have
263 * plenty of power. */
264 ohci_to_hcd(ohci)->power_budget = 0;
250 } 265 }
251 266
252 /* FIXME khubd hub requests should manage power switching */ 267 /* FIXME khubd hub requests should manage power switching */
@@ -260,21 +275,15 @@ static int omap_start_hc(struct ohci_hcd *ohci, struct platform_device *pdev)
260 return 0; 275 return 0;
261} 276}
262 277
263static void omap_stop_hc(struct platform_device *pdev) 278static void ohci_omap_stop(struct usb_hcd *hcd)
264{ 279{
265 dev_dbg(&pdev->dev, "stopping USB Controller\n"); 280 dev_dbg(hcd->self.controller, "stopping USB Controller\n");
266 omap_ohci_clock_power(0); 281 omap_ohci_clock_power(0);
267} 282}
268 283
269 284
270/*-------------------------------------------------------------------------*/ 285/*-------------------------------------------------------------------------*/
271 286
272void usb_hcd_omap_remove (struct usb_hcd *, struct platform_device *);
273
274/* configure so an HC device and id are always provided */
275/* always called with process context; sleeping is OK */
276
277
278/** 287/**
279 * usb_hcd_omap_probe - initialize OMAP-based HCDs 288 * usb_hcd_omap_probe - initialize OMAP-based HCDs
280 * Context: !in_interrupt() 289 * Context: !in_interrupt()
@@ -283,7 +292,7 @@ void usb_hcd_omap_remove (struct usb_hcd *, struct platform_device *);
283 * then invokes the start() method for the HCD associated with it 292 * then invokes the start() method for the HCD associated with it
284 * through the hotplug entry's driver_data. 293 * through the hotplug entry's driver_data.
285 */ 294 */
286int usb_hcd_omap_probe (const struct hc_driver *driver, 295static int usb_hcd_omap_probe (const struct hc_driver *driver,
287 struct platform_device *pdev) 296 struct platform_device *pdev)
288{ 297{
289 int retval, irq; 298 int retval, irq;
@@ -291,12 +300,12 @@ int usb_hcd_omap_probe (const struct hc_driver *driver,
291 struct ohci_hcd *ohci; 300 struct ohci_hcd *ohci;
292 301
293 if (pdev->num_resources != 2) { 302 if (pdev->num_resources != 2) {
294 printk(KERN_ERR "hcd probe: invalid num_resources: %i\n", 303 printk(KERN_ERR "hcd probe: invalid num_resources: %i\n",
295 pdev->num_resources); 304 pdev->num_resources);
296 return -ENODEV; 305 return -ENODEV;
297 } 306 }
298 307
299 if (pdev->resource[0].flags != IORESOURCE_MEM 308 if (pdev->resource[0].flags != IORESOURCE_MEM
300 || pdev->resource[1].flags != IORESOURCE_IRQ) { 309 || pdev->resource[1].flags != IORESOURCE_IRQ) {
301 printk(KERN_ERR "hcd probe: invalid resource type\n"); 310 printk(KERN_ERR "hcd probe: invalid resource type\n");
302 return -ENODEV; 311 return -ENODEV;
@@ -306,6 +315,17 @@ int usb_hcd_omap_probe (const struct hc_driver *driver,
306 if (IS_ERR(usb_host_ck)) 315 if (IS_ERR(usb_host_ck))
307 return PTR_ERR(usb_host_ck); 316 return PTR_ERR(usb_host_ck);
308 317
318 if (!cpu_is_omap1510())
319 usb_dc_ck = clk_get(0, "usb_dc_ck");
320 else
321 usb_dc_ck = clk_get(0, "lb_ck");
322
323 if (IS_ERR(usb_dc_ck)) {
324 clk_put(usb_host_ck);
325 return PTR_ERR(usb_dc_ck);
326 }
327
328
309 hcd = usb_create_hcd (driver, &pdev->dev, pdev->dev.bus_id); 329 hcd = usb_create_hcd (driver, &pdev->dev, pdev->dev.bus_id);
310 if (!hcd) { 330 if (!hcd) {
311 retval = -ENOMEM; 331 retval = -ENOMEM;
@@ -325,9 +345,8 @@ int usb_hcd_omap_probe (const struct hc_driver *driver,
325 ohci = hcd_to_ohci(hcd); 345 ohci = hcd_to_ohci(hcd);
326 ohci_hcd_init(ohci); 346 ohci_hcd_init(ohci);
327 347
328 retval = omap_start_hc(ohci, pdev); 348 host_initialized = 0;
329 if (retval < 0) 349 host_enabled = 1;
330 goto err2;
331 350
332 irq = platform_get_irq(pdev, 0); 351 irq = platform_get_irq(pdev, 0);
333 if (irq < 0) { 352 if (irq < 0) {
@@ -335,15 +354,21 @@ int usb_hcd_omap_probe (const struct hc_driver *driver,
335 goto err2; 354 goto err2;
336 } 355 }
337 retval = usb_add_hcd(hcd, irq, IRQF_DISABLED); 356 retval = usb_add_hcd(hcd, irq, IRQF_DISABLED);
338 if (retval == 0) 357 if (retval)
339 return retval; 358 goto err2;
359
360 host_initialized = 1;
361
362 if (!host_enabled)
363 omap_ohci_clock_power(0);
340 364
341 omap_stop_hc(pdev); 365 return 0;
342err2: 366err2:
343 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 367 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
344err1: 368err1:
345 usb_put_hcd(hcd); 369 usb_put_hcd(hcd);
346err0: 370err0:
371 clk_put(usb_dc_ck);
347 clk_put(usb_host_ck); 372 clk_put(usb_host_ck);
348 return retval; 373 return retval;
349} 374}
@@ -359,31 +384,41 @@ err0:
359 * Reverses the effect of usb_hcd_omap_probe(), first invoking 384 * Reverses the effect of usb_hcd_omap_probe(), first invoking
360 * the HCD's stop() method. It is always called from a thread 385 * the HCD's stop() method. It is always called from a thread
361 * context, normally "rmmod", "apmd", or something similar. 386 * context, normally "rmmod", "apmd", or something similar.
362 *
363 */ 387 */
364void usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev) 388static inline void
389usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev)
365{ 390{
391 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
392
366 usb_remove_hcd(hcd); 393 usb_remove_hcd(hcd);
394 if (ohci->transceiver) {
395 (void) otg_set_host(ohci->transceiver, 0);
396 put_device(ohci->transceiver->dev);
397 }
367 if (machine_is_omap_osk()) 398 if (machine_is_omap_osk())
368 omap_free_gpio(9); 399 omap_free_gpio(9);
369 omap_stop_hc(pdev);
370 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 400 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
371 usb_put_hcd(hcd); 401 usb_put_hcd(hcd);
402 clk_put(usb_dc_ck);
372 clk_put(usb_host_ck); 403 clk_put(usb_host_ck);
373} 404}
374 405
375/*-------------------------------------------------------------------------*/ 406/*-------------------------------------------------------------------------*/
376 407
377static int __devinit 408static int
378ohci_omap_start (struct usb_hcd *hcd) 409ohci_omap_start (struct usb_hcd *hcd)
379{ 410{
380 struct omap_usb_config *config; 411 struct omap_usb_config *config;
381 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 412 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
382 int ret; 413 int ret;
383 414
415 if (!host_enabled)
416 return 0;
384 config = hcd->self.controller->platform_data; 417 config = hcd->self.controller->platform_data;
385 if (config->otg || config->rwc) 418 if (config->otg || config->rwc) {
419 ohci->hc_control = OHCI_CTRL_RWC;
386 writel(OHCI_CTRL_RWC, &ohci->regs->control); 420 writel(OHCI_CTRL_RWC, &ohci->regs->control);
421 }
387 422
388 if ((ret = ohci_run (ohci)) < 0) { 423 if ((ret = ohci_run (ohci)) < 0) {
389 dev_err(hcd->self.controller, "can't start\n"); 424 dev_err(hcd->self.controller, "can't start\n");
@@ -409,8 +444,10 @@ static const struct hc_driver ohci_omap_hc_driver = {
409 /* 444 /*
410 * basic lifecycle operations 445 * basic lifecycle operations
411 */ 446 */
447 .reset = ohci_omap_init,
412 .start = ohci_omap_start, 448 .start = ohci_omap_start,
413 .stop = ohci_stop, 449 .stop = ohci_omap_stop,
450 .shutdown = ohci_shutdown,
414 451
415 /* 452 /*
416 * managing i/o requests and associated device resources 453 * managing i/o requests and associated device resources
@@ -429,6 +466,7 @@ static const struct hc_driver ohci_omap_hc_driver = {
429 */ 466 */
430 .hub_status_data = ohci_hub_status_data, 467 .hub_status_data = ohci_hub_status_data,
431 .hub_control = ohci_hub_control, 468 .hub_control = ohci_hub_control,
469 .hub_irq_enable = ohci_rhsc_enable,
432#ifdef CONFIG_PM 470#ifdef CONFIG_PM
433 .bus_suspend = ohci_bus_suspend, 471 .bus_suspend = ohci_bus_suspend,
434 .bus_resume = ohci_bus_resume, 472 .bus_resume = ohci_bus_resume,
@@ -446,13 +484,8 @@ static int ohci_hcd_omap_drv_probe(struct platform_device *dev)
446static int ohci_hcd_omap_drv_remove(struct platform_device *dev) 484static int ohci_hcd_omap_drv_remove(struct platform_device *dev)
447{ 485{
448 struct usb_hcd *hcd = platform_get_drvdata(dev); 486 struct usb_hcd *hcd = platform_get_drvdata(dev);
449 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
450 487
451 usb_hcd_omap_remove(hcd, dev); 488 usb_hcd_omap_remove(hcd, dev);
452 if (ohci->transceiver) {
453 (void) otg_set_host(ohci->transceiver, 0);
454 put_device(ohci->transceiver->dev);
455 }
456 platform_set_drvdata(dev, NULL); 489 platform_set_drvdata(dev, NULL);
457 490
458 return 0; 491 return 0;
@@ -472,7 +505,7 @@ static int ohci_omap_suspend(struct platform_device *dev, pm_message_t message)
472 505
473 omap_ohci_clock_power(0); 506 omap_ohci_clock_power(0);
474 ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED; 507 ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED;
475 dev->power.power_state = PMSG_SUSPEND; 508 dev->dev.power.power_state = PMSG_SUSPEND;
476 return 0; 509 return 0;
477} 510}
478 511
@@ -485,8 +518,8 @@ static int ohci_omap_resume(struct platform_device *dev)
485 ohci->next_statechange = jiffies; 518 ohci->next_statechange = jiffies;
486 519
487 omap_ohci_clock_power(1); 520 omap_ohci_clock_power(1);
488 dev->power.power_state = PMSG_ON; 521 dev->dev.power.power_state = PMSG_ON;
489 usb_hcd_resume_root_hub(dev_get_drvdata(dev)); 522 usb_hcd_resume_root_hub(platform_get_drvdata(dev));
490 return 0; 523 return 0;
491} 524}
492 525
@@ -500,6 +533,7 @@ static int ohci_omap_resume(struct platform_device *dev)
500static struct platform_driver ohci_hcd_omap_driver = { 533static struct platform_driver ohci_hcd_omap_driver = {
501 .probe = ohci_hcd_omap_drv_probe, 534 .probe = ohci_hcd_omap_drv_probe,
502 .remove = ohci_hcd_omap_drv_remove, 535 .remove = ohci_hcd_omap_drv_remove,
536 .shutdown = usb_hcd_platform_shutdown,
503#ifdef CONFIG_PM 537#ifdef CONFIG_PM
504 .suspend = ohci_omap_suspend, 538 .suspend = ohci_omap_suspend,
505 .resume = ohci_omap_resume, 539 .resume = ohci_omap_resume,
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index b268537e389e..874418552789 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -73,13 +73,14 @@ ohci_pci_start (struct usb_hcd *hcd)
73 else if (pdev->vendor == PCI_VENDOR_ID_NS) { 73 else if (pdev->vendor == PCI_VENDOR_ID_NS) {
74 struct pci_dev *b; 74 struct pci_dev *b;
75 75
76 b = pci_find_slot (pdev->bus->number, 76 b = pci_get_slot (pdev->bus,
77 PCI_DEVFN (PCI_SLOT (pdev->devfn), 1)); 77 PCI_DEVFN (PCI_SLOT (pdev->devfn), 1));
78 if (b && b->device == PCI_DEVICE_ID_NS_87560_LIO 78 if (b && b->device == PCI_DEVICE_ID_NS_87560_LIO
79 && b->vendor == PCI_VENDOR_ID_NS) { 79 && b->vendor == PCI_VENDOR_ID_NS) {
80 ohci->flags |= OHCI_QUIRK_SUPERIO; 80 ohci->flags |= OHCI_QUIRK_SUPERIO;
81 ohci_dbg (ohci, "Using NSC SuperIO setup\n"); 81 ohci_dbg (ohci, "Using NSC SuperIO setup\n");
82 } 82 }
83 pci_dev_put(b);
83 } 84 }
84 85
85 /* Check for Compaq's ZFMicro chipset, which needs short 86 /* Check for Compaq's ZFMicro chipset, which needs short
@@ -135,6 +136,11 @@ static int ohci_pci_suspend (struct usb_hcd *hcd, pm_message_t message)
135 } 136 }
136 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 137 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
137 (void)ohci_readl(ohci, &ohci->regs->intrdisable); 138 (void)ohci_readl(ohci, &ohci->regs->intrdisable);
139
140 /* make sure snapshot being resumed re-enumerates everything */
141 if (message.event == PM_EVENT_PRETHAW)
142 ohci_usb_reset(ohci);
143
138 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 144 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
139 bail: 145 bail:
140 spin_unlock_irqrestore (&ohci->lock, flags); 146 spin_unlock_irqrestore (&ohci->lock, flags);
@@ -171,11 +177,14 @@ static const struct hc_driver ohci_pci_hc_driver = {
171 */ 177 */
172 .reset = ohci_pci_reset, 178 .reset = ohci_pci_reset,
173 .start = ohci_pci_start, 179 .start = ohci_pci_start,
180 .stop = ohci_stop,
181 .shutdown = ohci_shutdown,
182
174#ifdef CONFIG_PM 183#ifdef CONFIG_PM
184 /* these suspend/resume entries are for upstream PCI glue ONLY */
175 .suspend = ohci_pci_suspend, 185 .suspend = ohci_pci_suspend,
176 .resume = ohci_pci_resume, 186 .resume = ohci_pci_resume,
177#endif 187#endif
178 .stop = ohci_stop,
179 188
180 /* 189 /*
181 * managing i/o requests and associated device resources 190 * managing i/o requests and associated device resources
@@ -194,6 +203,7 @@ static const struct hc_driver ohci_pci_hc_driver = {
194 */ 203 */
195 .hub_status_data = ohci_hub_status_data, 204 .hub_status_data = ohci_hub_status_data,
196 .hub_control = ohci_hub_control, 205 .hub_control = ohci_hub_control,
206 .hub_irq_enable = ohci_rhsc_enable,
197#ifdef CONFIG_PM 207#ifdef CONFIG_PM
198 .bus_suspend = ohci_bus_suspend, 208 .bus_suspend = ohci_bus_suspend,
199 .bus_resume = ohci_bus_resume, 209 .bus_resume = ohci_bus_resume,
@@ -224,6 +234,8 @@ static struct pci_driver ohci_pci_driver = {
224 .suspend = usb_hcd_pci_suspend, 234 .suspend = usb_hcd_pci_suspend,
225 .resume = usb_hcd_pci_resume, 235 .resume = usb_hcd_pci_resume,
226#endif 236#endif
237
238 .shutdown = usb_hcd_pci_shutdown,
227}; 239};
228 240
229 241
diff --git a/drivers/usb/host/ohci-pnx4008.c b/drivers/usb/host/ohci-pnx4008.c
new file mode 100644
index 000000000000..82cb22f002e7
--- /dev/null
+++ b/drivers/usb/host/ohci-pnx4008.c
@@ -0,0 +1,476 @@
1/*
2 * drivers/usb/host/ohci-pnx4008.c
3 *
4 * driver for Philips PNX4008 USB Host
5 *
6 * Authors: Dmitry Chigirev <source@mvista.com>
7 * Vitaly Wool <vitalywool@gmail.com>
8 *
9 * register initialization is based on code examples provided by Philips
10 * Copyright (c) 2005 Koninklijke Philips Electronics N.V.
11 *
12 * NOTE: This driver does not have suspend/resume functionality
13 * This driver is intended for engineering development purposes only
14 *
15 * 2005-2006 (c) MontaVista Software, Inc. This file is licensed under
16 * the terms of the GNU General Public License version 2. This program
17 * is licensed "as is" without any warranty of any kind, whether express
18 * or implied.
19 */
20#include <linux/clk.h>
21#include <linux/platform_device.h>
22#include <linux/i2c.h>
23
24#include <asm/hardware.h>
25#include <asm/io.h>
26#include <asm/mach-types.h>
27
28#include <asm/arch/platform.h>
29#include <asm/arch/irqs.h>
30#include <asm/arch/gpio.h>
31
32#define USB_CTRL IO_ADDRESS(PNX4008_PWRMAN_BASE + 0x64)
33
34/* USB_CTRL bit defines */
35#define USB_SLAVE_HCLK_EN (1 << 24)
36#define USB_HOST_NEED_CLK_EN (1 << 21)
37
38#define USB_OTG_CLK_CTRL IO_ADDRESS(PNX4008_USB_CONFIG_BASE + 0xFF4)
39#define USB_OTG_CLK_STAT IO_ADDRESS(PNX4008_USB_CONFIG_BASE + 0xFF8)
40
41/* USB_OTG_CLK_CTRL bit defines */
42#define AHB_M_CLOCK_ON (1 << 4)
43#define OTG_CLOCK_ON (1 << 3)
44#define I2C_CLOCK_ON (1 << 2)
45#define DEV_CLOCK_ON (1 << 1)
46#define HOST_CLOCK_ON (1 << 0)
47
48#define USB_OTG_STAT_CONTROL IO_ADDRESS(PNX4008_USB_CONFIG_BASE + 0x110)
49
50/* USB_OTG_STAT_CONTROL bit defines */
51#define TRANSPARENT_I2C_EN (1 << 7)
52#define HOST_EN (1 << 0)
53
54/* ISP1301 USB transceiver I2C registers */
55#define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */
56
57#define MC1_SPEED_REG (1 << 0)
58#define MC1_SUSPEND_REG (1 << 1)
59#define MC1_DAT_SE0 (1 << 2)
60#define MC1_TRANSPARENT (1 << 3)
61#define MC1_BDIS_ACON_EN (1 << 4)
62#define MC1_OE_INT_EN (1 << 5)
63#define MC1_UART_EN (1 << 6)
64#define MC1_MASK 0x7f
65
66#define ISP1301_MODE_CONTROL_2 0x12 /* u8 read, set, +1 clear */
67
68#define MC2_GLOBAL_PWR_DN (1 << 0)
69#define MC2_SPD_SUSP_CTRL (1 << 1)
70#define MC2_BI_DI (1 << 2)
71#define MC2_TRANSP_BDIR0 (1 << 3)
72#define MC2_TRANSP_BDIR1 (1 << 4)
73#define MC2_AUDIO_EN (1 << 5)
74#define MC2_PSW_EN (1 << 6)
75#define MC2_EN2V7 (1 << 7)
76
77#define ISP1301_OTG_CONTROL_1 0x06 /* u8 read, set, +1 clear */
78# define OTG1_DP_PULLUP (1 << 0)
79# define OTG1_DM_PULLUP (1 << 1)
80# define OTG1_DP_PULLDOWN (1 << 2)
81# define OTG1_DM_PULLDOWN (1 << 3)
82# define OTG1_ID_PULLDOWN (1 << 4)
83# define OTG1_VBUS_DRV (1 << 5)
84# define OTG1_VBUS_DISCHRG (1 << 6)
85# define OTG1_VBUS_CHRG (1 << 7)
86#define ISP1301_OTG_STATUS 0x10 /* u8 readonly */
87# define OTG_B_SESS_END (1 << 6)
88# define OTG_B_SESS_VLD (1 << 7)
89
90#define ISP1301_I2C_ADDR 0x2C
91
92#define ISP1301_I2C_MODE_CONTROL_1 0x4
93#define ISP1301_I2C_MODE_CONTROL_2 0x12
94#define ISP1301_I2C_OTG_CONTROL_1 0x6
95#define ISP1301_I2C_OTG_CONTROL_2 0x10
96#define ISP1301_I2C_INTERRUPT_SOURCE 0x8
97#define ISP1301_I2C_INTERRUPT_LATCH 0xA
98#define ISP1301_I2C_INTERRUPT_FALLING 0xC
99#define ISP1301_I2C_INTERRUPT_RISING 0xE
100#define ISP1301_I2C_REG_CLEAR_ADDR 1
101
102struct i2c_driver isp1301_driver;
103struct i2c_client *isp1301_i2c_client;
104
105extern int usb_disabled(void);
106extern int ocpi_enable(void);
107
108static struct clk *usb_clk;
109
110static int isp1301_probe(struct i2c_adapter *adap);
111static int isp1301_detach(struct i2c_client *client);
112static int isp1301_command(struct i2c_client *client, unsigned int cmd,
113 void *arg);
114
115static unsigned short normal_i2c[] =
116 { ISP1301_I2C_ADDR, ISP1301_I2C_ADDR + 1, I2C_CLIENT_END };
117static unsigned short dummy_i2c_addrlist[] = { I2C_CLIENT_END };
118
119static struct i2c_client_address_data addr_data = {
120 .normal_i2c = normal_i2c,
121 .probe = dummy_i2c_addrlist,
122 .ignore = dummy_i2c_addrlist,
123};
124
125struct i2c_driver isp1301_driver = {
126 .id = I2C_DRIVERID_I2CDEV, /* Fake Id */
127 .class = I2C_CLASS_HWMON,
128 .attach_adapter = isp1301_probe,
129 .detach_client = isp1301_detach,
130 .command = isp1301_command
131};
132
133static int isp1301_attach(struct i2c_adapter *adap, int addr, int kind)
134{
135 struct i2c_client *c;
136
137 c = (struct i2c_client *)kzalloc(sizeof(*c), SLAB_KERNEL);
138
139 if (!c)
140 return -ENOMEM;
141
142 strcpy(c->name, "isp1301");
143 c->flags = 0;
144 c->addr = addr;
145 c->adapter = adap;
146 c->driver = &isp1301_driver;
147
148 isp1301_i2c_client = c;
149
150 return i2c_attach_client(c);
151}
152
153static int isp1301_probe(struct i2c_adapter *adap)
154{
155 return i2c_probe(adap, &addr_data, isp1301_attach);
156}
157
158static int isp1301_detach(struct i2c_client *client)
159{
160 i2c_detach_client(client);
161 kfree(isp1301_i2c_client);
162 return 0;
163}
164
165/* No commands defined */
166static int isp1301_command(struct i2c_client *client, unsigned int cmd,
167 void *arg)
168{
169 return 0;
170}
171
172static void i2c_write(u8 buf, u8 subaddr)
173{
174 char tmpbuf[2];
175
176 tmpbuf[0] = subaddr; /*register number */
177 tmpbuf[1] = buf; /*register data */
178 i2c_master_send(isp1301_i2c_client, &tmpbuf[0], 2);
179}
180
181static void isp1301_configure(void)
182{
183 /* PNX4008 only supports DAT_SE0 USB mode */
184 /* PNX4008 R2A requires setting the MAX603 to output 3.6V */
185 /* Power up externel charge-pump */
186
187 i2c_write(MC1_DAT_SE0 | MC1_SPEED_REG, ISP1301_I2C_MODE_CONTROL_1);
188 i2c_write(~(MC1_DAT_SE0 | MC1_SPEED_REG),
189 ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR);
190 i2c_write(MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL,
191 ISP1301_I2C_MODE_CONTROL_2);
192 i2c_write(~(MC2_BI_DI | MC2_PSW_EN | MC2_SPD_SUSP_CTRL),
193 ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR);
194 i2c_write(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN,
195 ISP1301_I2C_OTG_CONTROL_1);
196 i2c_write(~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN),
197 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR);
198 i2c_write(0xFF,
199 ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR);
200 i2c_write(0xFF,
201 ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR);
202 i2c_write(0xFF,
203 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR);
204
205}
206
207static inline void isp1301_vbus_on(void)
208{
209 i2c_write(OTG1_VBUS_DRV, ISP1301_I2C_OTG_CONTROL_1);
210}
211
212static inline void isp1301_vbus_off(void)
213{
214 i2c_write(OTG1_VBUS_DRV,
215 ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR);
216}
217
218static void pnx4008_start_hc(void)
219{
220 unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN;
221 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
222 isp1301_vbus_on();
223}
224
225static void pnx4008_stop_hc(void)
226{
227 unsigned long tmp;
228 isp1301_vbus_off();
229 tmp = __raw_readl(USB_OTG_STAT_CONTROL) & ~HOST_EN;
230 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
231}
232
233static int __devinit ohci_pnx4008_start(struct usb_hcd *hcd)
234{
235 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
236 int ret;
237
238 if ((ret = ohci_init(ohci)) < 0)
239 return ret;
240
241 if ((ret = ohci_run(ohci)) < 0) {
242 dev_err(hcd->self.controller, "can't start\n");
243 ohci_stop(hcd);
244 return ret;
245 }
246 return 0;
247}
248
249static const struct hc_driver ohci_pnx4008_hc_driver = {
250 .description = hcd_name,
251 .product_desc = "pnx4008 OHCI",
252
253 /*
254 * generic hardware linkage
255 */
256 .irq = ohci_irq,
257 .flags = HCD_USB11 | HCD_MEMORY,
258
259 .hcd_priv_size = sizeof(struct ohci_hcd),
260 /*
261 * basic lifecycle operations
262 */
263 .start = ohci_pnx4008_start,
264 .stop = ohci_stop,
265
266 /*
267 * managing i/o requests and associated device resources
268 */
269 .urb_enqueue = ohci_urb_enqueue,
270 .urb_dequeue = ohci_urb_dequeue,
271 .endpoint_disable = ohci_endpoint_disable,
272
273 /*
274 * scheduling support
275 */
276 .get_frame_number = ohci_get_frame,
277
278 /*
279 * root hub support
280 */
281 .hub_status_data = ohci_hub_status_data,
282 .hub_control = ohci_hub_control,
283
284 .start_port_reset = ohci_start_port_reset,
285};
286
287#define USB_CLOCK_MASK (AHB_M_CLOCK_ON| OTG_CLOCK_ON | HOST_CLOCK_ON | I2C_CLOCK_ON)
288
289static void pnx4008_set_usb_bits(void)
290{
291 start_int_set_falling_edge(SE_USB_OTG_ATX_INT_N);
292 start_int_ack(SE_USB_OTG_ATX_INT_N);
293 start_int_umask(SE_USB_OTG_ATX_INT_N);
294
295 start_int_set_rising_edge(SE_USB_OTG_TIMER_INT);
296 start_int_ack(SE_USB_OTG_TIMER_INT);
297 start_int_umask(SE_USB_OTG_TIMER_INT);
298
299 start_int_set_rising_edge(SE_USB_I2C_INT);
300 start_int_ack(SE_USB_I2C_INT);
301 start_int_umask(SE_USB_I2C_INT);
302
303 start_int_set_rising_edge(SE_USB_INT);
304 start_int_ack(SE_USB_INT);
305 start_int_umask(SE_USB_INT);
306
307 start_int_set_rising_edge(SE_USB_NEED_CLK_INT);
308 start_int_ack(SE_USB_NEED_CLK_INT);
309 start_int_umask(SE_USB_NEED_CLK_INT);
310
311 start_int_set_rising_edge(SE_USB_AHB_NEED_CLK_INT);
312 start_int_ack(SE_USB_AHB_NEED_CLK_INT);
313 start_int_umask(SE_USB_AHB_NEED_CLK_INT);
314}
315
316static void pnx4008_unset_usb_bits(void)
317{
318 start_int_mask(SE_USB_OTG_ATX_INT_N);
319 start_int_mask(SE_USB_OTG_TIMER_INT);
320 start_int_mask(SE_USB_I2C_INT);
321 start_int_mask(SE_USB_INT);
322 start_int_mask(SE_USB_NEED_CLK_INT);
323 start_int_mask(SE_USB_AHB_NEED_CLK_INT);
324}
325
326static int __devinit usb_hcd_pnx4008_probe(struct platform_device *pdev)
327{
328 struct usb_hcd *hcd = 0;
329 struct ohci_hcd *ohci;
330 const struct hc_driver *driver = &ohci_pnx4008_hc_driver;
331
332 int ret = 0, irq;
333
334 dev_dbg(&pdev->dev, "%s: " DRIVER_INFO " (pnx4008)\n", hcd_name);
335 if (usb_disabled()) {
336 err("USB is disabled");
337 ret = -ENODEV;
338 goto out;
339 }
340
341 if (pdev->num_resources != 2
342 || pdev->resource[0].flags != IORESOURCE_MEM
343 || pdev->resource[1].flags != IORESOURCE_IRQ) {
344 err("Invalid resource configuration");
345 ret = -ENODEV;
346 goto out;
347 }
348
349 /* Enable AHB slave USB clock, needed for further USB clock control */
350 __raw_writel(USB_SLAVE_HCLK_EN | (1 << 19), USB_CTRL);
351
352 ret = i2c_add_driver(&isp1301_driver);
353 if (ret < 0) {
354 err("failed to connect I2C to ISP1301 USB Transceiver");
355 goto out;
356 }
357
358 isp1301_configure();
359
360 /* Enable USB PLL */
361 usb_clk = clk_get(&pdev->dev, "ck_pll5");
362 if (IS_ERR(usb_clk)) {
363 err("failed to acquire USB PLL");
364 ret = PTR_ERR(usb_clk);
365 goto out1;
366 }
367
368 ret = clk_enable(usb_clk);
369 if (ret < 0) {
370 err("failed to start USB PLL");
371 goto out2;
372 }
373
374 ret = clk_set_rate(usb_clk, 48000);
375 if (ret < 0) {
376 err("failed to set USB clock rate");
377 goto out3;
378 }
379
380 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
381
382 /* Set to enable all needed USB clocks */
383 __raw_writel(USB_CLOCK_MASK, USB_OTG_CLK_CTRL);
384
385 while ((__raw_readl(USB_OTG_CLK_STAT) & USB_CLOCK_MASK) !=
386 USB_CLOCK_MASK) ;
387
388 hcd = usb_create_hcd (driver, &pdev->dev, pdev->dev.bus_id);
389 if (!hcd) {
390 err("Failed to allocate HC buffer");
391 ret = -ENOMEM;
392 goto out3;
393 }
394
395 /* Set all USB bits in the Start Enable register */
396 pnx4008_set_usb_bits();
397
398 hcd->rsrc_start = pdev->resource[0].start;
399 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
400 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
401 dev_dbg(&pdev->dev, "request_mem_region failed\n");
402 ret = -ENOMEM;
403 goto out4;
404 }
405 hcd->regs = (void __iomem *)pdev->resource[0].start;
406
407 irq = platform_get_irq(pdev, 0);
408 if (irq < 0) {
409 ret = -ENXIO;
410 goto out4;
411 }
412
413 hcd->self.hcpriv = (void *)hcd;
414
415 pnx4008_start_hc();
416 platform_set_drvdata(pdev, hcd);
417 ohci = hcd_to_ohci(hcd);
418 ohci_hcd_init(ohci);
419
420 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
421 ret = usb_add_hcd(hcd, irq, SA_INTERRUPT);
422 if (ret == 0)
423 return ret;
424
425 pnx4008_stop_hc();
426out4:
427 pnx4008_unset_usb_bits();
428 usb_put_hcd(hcd);
429out3:
430 clk_disable(usb_clk);
431out2:
432 clk_put(usb_clk);
433out1:
434 i2c_del_driver(&isp1301_driver);
435out:
436 return ret;
437}
438
439static int usb_hcd_pnx4008_remove(struct platform_device *pdev)
440{
441 struct usb_hcd *hcd = platform_get_drvdata(pdev);
442
443 usb_remove_hcd(hcd);
444 pnx4008_stop_hc();
445 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
446 usb_put_hcd(hcd);
447 pnx4008_unset_usb_bits();
448 clk_disable(usb_clk);
449 clk_put(usb_clk);
450 i2c_del_driver(&isp1301_driver);
451
452 platform_set_drvdata(pdev, NULL);
453
454 return 0;
455}
456
457static struct platform_driver usb_hcd_pnx4008_driver = {
458 .driver = {
459 .name = "usb-ohci",
460 },
461 .probe = usb_hcd_pnx4008_probe,
462 .remove = usb_hcd_pnx4008_remove,
463};
464
465static int __init usb_hcd_pnx4008_init(void)
466{
467 return platform_driver_register(&usb_hcd_pnx4008_driver);
468}
469
470static void __exit usb_hcd_pnx4008_cleanup(void)
471{
472 return platform_driver_unregister(&usb_hcd_pnx4008_driver);
473}
474
475module_init(usb_hcd_pnx4008_init);
476module_exit(usb_hcd_pnx4008_cleanup);
diff --git a/drivers/usb/host/ohci-ppc-soc.c b/drivers/usb/host/ohci-ppc-soc.c
index 9fe56ff1615d..d9d1ae236bd5 100644
--- a/drivers/usb/host/ohci-ppc-soc.c
+++ b/drivers/usb/host/ohci-ppc-soc.c
@@ -148,6 +148,7 @@ static const struct hc_driver ohci_ppc_soc_hc_driver = {
148 */ 148 */
149 .start = ohci_ppc_soc_start, 149 .start = ohci_ppc_soc_start,
150 .stop = ohci_stop, 150 .stop = ohci_stop,
151 .shutdown = ohci_shutdown,
151 152
152 /* 153 /*
153 * managing i/o requests and associated device resources 154 * managing i/o requests and associated device resources
@@ -166,6 +167,7 @@ static const struct hc_driver ohci_ppc_soc_hc_driver = {
166 */ 167 */
167 .hub_status_data = ohci_hub_status_data, 168 .hub_status_data = ohci_hub_status_data,
168 .hub_control = ohci_hub_control, 169 .hub_control = ohci_hub_control,
170 .hub_irq_enable = ohci_rhsc_enable,
169#ifdef CONFIG_PM 171#ifdef CONFIG_PM
170 .bus_suspend = ohci_bus_suspend, 172 .bus_suspend = ohci_bus_suspend,
171 .bus_resume = ohci_bus_resume, 173 .bus_resume = ohci_bus_resume,
@@ -195,6 +197,7 @@ static int ohci_hcd_ppc_soc_drv_remove(struct platform_device *pdev)
195static struct platform_driver ohci_hcd_ppc_soc_driver = { 197static struct platform_driver ohci_hcd_ppc_soc_driver = {
196 .probe = ohci_hcd_ppc_soc_drv_probe, 198 .probe = ohci_hcd_ppc_soc_drv_probe,
197 .remove = ohci_hcd_ppc_soc_drv_remove, 199 .remove = ohci_hcd_ppc_soc_drv_remove,
200 .shutdown = usb_hcd_platform_shutdown,
198#ifdef CONFIG_PM 201#ifdef CONFIG_PM
199 /*.suspend = ohci_hcd_ppc_soc_drv_suspend,*/ 202 /*.suspend = ohci_hcd_ppc_soc_drv_suspend,*/
200 /*.resume = ohci_hcd_ppc_soc_drv_resume,*/ 203 /*.resume = ohci_hcd_ppc_soc_drv_resume,*/
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c
index 6f559e102789..e176b04d7aeb 100644
--- a/drivers/usb/host/ohci-pxa27x.c
+++ b/drivers/usb/host/ohci-pxa27x.c
@@ -270,6 +270,7 @@ static const struct hc_driver ohci_pxa27x_hc_driver = {
270 */ 270 */
271 .start = ohci_pxa27x_start, 271 .start = ohci_pxa27x_start,
272 .stop = ohci_stop, 272 .stop = ohci_stop,
273 .shutdown = ohci_shutdown,
273 274
274 /* 275 /*
275 * managing i/o requests and associated device resources 276 * managing i/o requests and associated device resources
@@ -288,6 +289,7 @@ static const struct hc_driver ohci_pxa27x_hc_driver = {
288 */ 289 */
289 .hub_status_data = ohci_hub_status_data, 290 .hub_status_data = ohci_hub_status_data,
290 .hub_control = ohci_hub_control, 291 .hub_control = ohci_hub_control,
292 .hub_irq_enable = ohci_rhsc_enable,
291#ifdef CONFIG_PM 293#ifdef CONFIG_PM
292 .bus_suspend = ohci_bus_suspend, 294 .bus_suspend = ohci_bus_suspend,
293 .bus_resume = ohci_bus_resume, 295 .bus_resume = ohci_bus_resume,
@@ -357,6 +359,7 @@ static int ohci_hcd_pxa27x_drv_resume(struct platform_device *pdev)
357static struct platform_driver ohci_hcd_pxa27x_driver = { 359static struct platform_driver ohci_hcd_pxa27x_driver = {
358 .probe = ohci_hcd_pxa27x_drv_probe, 360 .probe = ohci_hcd_pxa27x_drv_probe,
359 .remove = ohci_hcd_pxa27x_drv_remove, 361 .remove = ohci_hcd_pxa27x_drv_remove,
362 .shutdown = usb_hcd_platform_shutdown,
360#ifdef CONFIG_PM 363#ifdef CONFIG_PM
361 .suspend = ohci_hcd_pxa27x_drv_suspend, 364 .suspend = ohci_hcd_pxa27x_drv_suspend,
362 .resume = ohci_hcd_pxa27x_drv_resume, 365 .resume = ohci_hcd_pxa27x_drv_resume,
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
index d2fc6969a9f7..59e436424d41 100644
--- a/drivers/usb/host/ohci-s3c2410.c
+++ b/drivers/usb/host/ohci-s3c2410.c
@@ -370,7 +370,7 @@ static int usb_hcd_s3c2410_probe (const struct hc_driver *driver,
370 goto err_mem; 370 goto err_mem;
371 } 371 }
372 372
373 usb_clk = clk_get(&dev->dev, "upll"); 373 usb_clk = clk_get(&dev->dev, "usb-bus-host");
374 if (IS_ERR(usb_clk)) { 374 if (IS_ERR(usb_clk)) {
375 dev_err(&dev->dev, "cannot get usb-host clock\n"); 375 dev_err(&dev->dev, "cannot get usb-host clock\n");
376 retval = -ENOENT; 376 retval = -ENOENT;
@@ -447,6 +447,7 @@ static const struct hc_driver ohci_s3c2410_hc_driver = {
447 */ 447 */
448 .start = ohci_s3c2410_start, 448 .start = ohci_s3c2410_start,
449 .stop = ohci_stop, 449 .stop = ohci_stop,
450 .shutdown = ohci_shutdown,
450 451
451 /* 452 /*
452 * managing i/o requests and associated device resources 453 * managing i/o requests and associated device resources
@@ -465,6 +466,7 @@ static const struct hc_driver ohci_s3c2410_hc_driver = {
465 */ 466 */
466 .hub_status_data = ohci_s3c2410_hub_status_data, 467 .hub_status_data = ohci_s3c2410_hub_status_data,
467 .hub_control = ohci_s3c2410_hub_control, 468 .hub_control = ohci_s3c2410_hub_control,
469 .hub_irq_enable = ohci_rhsc_enable,
468#ifdef CONFIG_PM 470#ifdef CONFIG_PM
469 .bus_suspend = ohci_bus_suspend, 471 .bus_suspend = ohci_bus_suspend,
470 .bus_resume = ohci_bus_resume, 472 .bus_resume = ohci_bus_resume,
@@ -490,6 +492,7 @@ static int ohci_hcd_s3c2410_drv_remove(struct platform_device *pdev)
490static struct platform_driver ohci_hcd_s3c2410_driver = { 492static struct platform_driver ohci_hcd_s3c2410_driver = {
491 .probe = ohci_hcd_s3c2410_drv_probe, 493 .probe = ohci_hcd_s3c2410_drv_probe,
492 .remove = ohci_hcd_s3c2410_drv_remove, 494 .remove = ohci_hcd_s3c2410_drv_remove,
495 .shutdown = usb_hcd_platform_shutdown,
493 /*.suspend = ohci_hcd_s3c2410_drv_suspend, */ 496 /*.suspend = ohci_hcd_s3c2410_drv_suspend, */
494 /*.resume = ohci_hcd_s3c2410_drv_resume, */ 497 /*.resume = ohci_hcd_s3c2410_drv_resume, */
495 .driver = { 498 .driver = {
diff --git a/drivers/usb/host/ohci-sa1111.c b/drivers/usb/host/ohci-sa1111.c
index ce3de106cadc..71371de32ada 100644
--- a/drivers/usb/host/ohci-sa1111.c
+++ b/drivers/usb/host/ohci-sa1111.c
@@ -212,10 +212,6 @@ static const struct hc_driver ohci_sa1111_hc_driver = {
212 * basic lifecycle operations 212 * basic lifecycle operations
213 */ 213 */
214 .start = ohci_sa1111_start, 214 .start = ohci_sa1111_start,
215#ifdef CONFIG_PM
216 /* suspend: ohci_sa1111_suspend, -- tbd */
217 /* resume: ohci_sa1111_resume, -- tbd */
218#endif
219 .stop = ohci_stop, 215 .stop = ohci_stop,
220 216
221 /* 217 /*
@@ -235,6 +231,7 @@ static const struct hc_driver ohci_sa1111_hc_driver = {
235 */ 231 */
236 .hub_status_data = ohci_hub_status_data, 232 .hub_status_data = ohci_hub_status_data,
237 .hub_control = ohci_hub_control, 233 .hub_control = ohci_hub_control,
234 .hub_irq_enable = ohci_rhsc_enable,
238#ifdef CONFIG_PM 235#ifdef CONFIG_PM
239 .bus_suspend = ohci_bus_suspend, 236 .bus_suspend = ohci_bus_suspend,
240 .bus_resume = ohci_bus_resume, 237 .bus_resume = ohci_bus_resume,
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index caacf14371f5..a2f42a2f47c6 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -159,7 +159,7 @@ static const int cc_to_error [16] = {
159 /* Bit Stuff */ -EPROTO, 159 /* Bit Stuff */ -EPROTO,
160 /* Data Togg */ -EILSEQ, 160 /* Data Togg */ -EILSEQ,
161 /* Stall */ -EPIPE, 161 /* Stall */ -EPIPE,
162 /* DevNotResp */ -ETIMEDOUT, 162 /* DevNotResp */ -ETIME,
163 /* PIDCheck */ -EPROTO, 163 /* PIDCheck */ -EPROTO,
164 /* UnExpPID */ -EPROTO, 164 /* UnExpPID */ -EPROTO,
165 /* DataOver */ -EOVERFLOW, 165 /* DataOver */ -EOVERFLOW,
@@ -388,8 +388,7 @@ struct ohci_hcd {
388 u32 hc_control; /* copy of hc control reg */ 388 u32 hc_control; /* copy of hc control reg */
389 unsigned long next_statechange; /* suspend/resume */ 389 unsigned long next_statechange; /* suspend/resume */
390 u32 fminterval; /* saved register */ 390 u32 fminterval; /* saved register */
391 391 unsigned autostop:1; /* rh auto stopping/stopped */
392 struct notifier_block reboot_notifier;
393 392
394 unsigned long flags; /* for HC bugs */ 393 unsigned long flags; /* for HC bugs */
395#define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */ 394#define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index fa34092bbcde..3a586aab3939 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -597,7 +597,7 @@ done(struct sl811 *sl811, struct sl811h_ep *ep, u8 bank, struct pt_regs *regs)
597 /* error? retry, until "3 strikes" */ 597 /* error? retry, until "3 strikes" */
598 } else if (++ep->error_count >= 3) { 598 } else if (++ep->error_count >= 3) {
599 if (status & SL11H_STATMASK_TMOUT) 599 if (status & SL11H_STATMASK_TMOUT)
600 urbstat = -ETIMEDOUT; 600 urbstat = -ETIME;
601 else if (status & SL11H_STATMASK_OVF) 601 else if (status & SL11H_STATMASK_OVF)
602 urbstat = -EOVERFLOW; 602 urbstat = -EOVERFLOW;
603 else 603 else
@@ -1517,7 +1517,7 @@ static int proc_sl811h_open(struct inode *inode, struct file *file)
1517 return single_open(file, proc_sl811h_show, PDE(inode)->data); 1517 return single_open(file, proc_sl811h_show, PDE(inode)->data);
1518} 1518}
1519 1519
1520static struct file_operations proc_ops = { 1520static const struct file_operations proc_ops = {
1521 .open = proc_sl811h_open, 1521 .open = proc_sl811h_open,
1522 .read = seq_read, 1522 .read = seq_read,
1523 .llseek = seq_lseek, 1523 .llseek = seq_lseek,
@@ -1783,10 +1783,15 @@ sl811h_suspend(struct platform_device *dev, pm_message_t state)
1783 struct sl811 *sl811 = hcd_to_sl811(hcd); 1783 struct sl811 *sl811 = hcd_to_sl811(hcd);
1784 int retval = 0; 1784 int retval = 0;
1785 1785
1786 if (state.event == PM_EVENT_FREEZE) 1786 switch (state.event) {
1787 case PM_EVENT_FREEZE:
1787 retval = sl811h_bus_suspend(hcd); 1788 retval = sl811h_bus_suspend(hcd);
1788 else if (state.event == PM_EVENT_SUSPEND) 1789 break;
1790 case PM_EVENT_SUSPEND:
1791 case PM_EVENT_PRETHAW: /* explicitly discard hw state */
1789 port_power(sl811, 0); 1792 port_power(sl811, 0);
1793 break;
1794 }
1790 if (retval == 0) 1795 if (retval == 0)
1791 dev->dev.power.power_state = state; 1796 dev->dev.power.power_state = state;
1792 return retval; 1797 return retval;
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
new file mode 100644
index 000000000000..cb2e2a604d1b
--- /dev/null
+++ b/drivers/usb/host/u132-hcd.c
@@ -0,0 +1,3295 @@
1/*
2* Host Controller Driver for the Elan Digital Systems U132 adapter
3*
4* Copyright(C) 2006 Elan Digital Systems Limited
5* http://www.elandigitalsystems.com
6*
7* Author and Maintainer - Tony Olech - Elan Digital Systems
8* tony.olech@elandigitalsystems.com
9*
10* This program is free software;you can redistribute it and/or
11* modify it under the terms of the GNU General Public License as
12* published by the Free Software Foundation, version 2.
13*
14*
15* This driver was written by Tony Olech(tony.olech@elandigitalsystems.com)
16* based on various USB host drivers in the 2.6.15 linux kernel
17* with constant reference to the 3rd Edition of Linux Device Drivers
18* published by O'Reilly
19*
20* The U132 adapter is a USB to CardBus adapter specifically designed
21* for PC cards that contain an OHCI host controller. Typical PC cards
22* are the Orange Mobile 3G Option GlobeTrotter Fusion card.
23*
24* The U132 adapter will *NOT *work with PC cards that do not contain
25* an OHCI controller. A simple way to test whether a PC card has an
26* OHCI controller as an interface is to insert the PC card directly
27* into a laptop(or desktop) with a CardBus slot and if "lspci" shows
28* a new USB controller and "lsusb -v" shows a new OHCI Host Controller
29* then there is a good chance that the U132 adapter will support the
30* PC card.(you also need the specific client driver for the PC card)
31*
32* Please inform the Author and Maintainer about any PC cards that
33* contain OHCI Host Controller and work when directly connected to
34* an embedded CardBus slot but do not work when they are connected
35* via an ELAN U132 adapter.
36*
37*/
38#include <linux/config.h>
39#include <linux/kernel.h>
40#include <linux/module.h>
41#include <linux/moduleparam.h>
42#include <linux/delay.h>
43#include <linux/ioport.h>
44#include <linux/sched.h>
45#include <linux/slab.h>
46#include <linux/smp_lock.h>
47#include <linux/errno.h>
48#include <linux/init.h>
49#include <linux/timer.h>
50#include <linux/list.h>
51#include <linux/interrupt.h>
52#include <linux/usb.h>
53#include <linux/workqueue.h>
54#include <linux/platform_device.h>
55#include <linux/pci_ids.h>
56#include <asm/io.h>
57#include <asm/irq.h>
58#include <asm/system.h>
59#include <asm/byteorder.h>
60#include "../core/hcd.h"
61#include "ohci.h"
62#define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
63#define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \
64 OHCI_INTR_WDH)
65MODULE_AUTHOR("Tony Olech - Elan Digital Systems Limited");
66MODULE_DESCRIPTION("U132 USB Host Controller Driver");
67MODULE_LICENSE("GPL");
68#define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444)
69INT_MODULE_PARM(testing, 0);
70/* Some boards misreport power switching/overcurrent*/
71static int distrust_firmware = 1;
72module_param(distrust_firmware, bool, 0);
73MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren"
74 "t setup");
75DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait);
76/*
77* u132_module_lock exists to protect access to global variables
78*
79*/
80static struct semaphore u132_module_lock;
81static int u132_exiting = 0;
82static int u132_instances = 0;
83static struct list_head u132_static_list;
84/*
85* end of the global variables protected by u132_module_lock
86*/
87static struct workqueue_struct *workqueue;
88#define MAX_U132_PORTS 7
89#define MAX_U132_ADDRS 128
90#define MAX_U132_UDEVS 4
91#define MAX_U132_ENDPS 100
92#define MAX_U132_RINGS 4
93static const char *cc_to_text[16] = {
94 "No Error ",
95 "CRC Error ",
96 "Bit Stuff ",
97 "Data Togg ",
98 "Stall ",
99 "DevNotResp ",
100 "PIDCheck ",
101 "UnExpPID ",
102 "DataOver ",
103 "DataUnder ",
104 "(for hw) ",
105 "(for hw) ",
106 "BufferOver ",
107 "BuffUnder ",
108 "(for HCD) ",
109 "(for HCD) "
110};
111struct u132_port {
112 struct u132 *u132;
113 int reset;
114 int enable;
115 int power;
116 int Status;
117};
118struct u132_addr {
119 u8 address;
120};
121struct u132_udev {
122 struct kref kref;
123 struct usb_device *usb_device;
124 u8 enumeration;
125 u8 udev_number;
126 u8 usb_addr;
127 u8 portnumber;
128 u8 endp_number_in[16];
129 u8 endp_number_out[16];
130};
131#define ENDP_QUEUE_SHIFT 3
132#define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT)
133#define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1)
134struct u132_urbq {
135 struct list_head urb_more;
136 struct urb *urb;
137};
138struct u132_spin {
139 spinlock_t slock;
140};
141struct u132_endp {
142 struct kref kref;
143 u8 udev_number;
144 u8 endp_number;
145 u8 usb_addr;
146 u8 usb_endp;
147 struct u132 *u132;
148 struct list_head endp_ring;
149 struct u132_ring *ring;
150 unsigned toggle_bits:2;
151 unsigned active:1;
152 unsigned delayed:1;
153 unsigned input:1;
154 unsigned output:1;
155 unsigned pipetype:2;
156 unsigned dequeueing:1;
157 unsigned edset_flush:1;
158 unsigned spare_bits:14;
159 unsigned long jiffies;
160 struct usb_host_endpoint *hep;
161 struct u132_spin queue_lock;
162 u16 queue_size;
163 u16 queue_last;
164 u16 queue_next;
165 struct urb *urb_list[ENDP_QUEUE_SIZE];
166 struct list_head urb_more;
167 struct work_struct scheduler;
168};
169struct u132_ring {
170 unsigned in_use:1;
171 unsigned length:7;
172 u8 number;
173 struct u132 *u132;
174 struct u132_endp *curr_endp;
175 struct work_struct scheduler;
176};
177#define OHCI_QUIRK_AMD756 0x01
178#define OHCI_QUIRK_SUPERIO 0x02
179#define OHCI_QUIRK_INITRESET 0x04
180#define OHCI_BIG_ENDIAN 0x08
181#define OHCI_QUIRK_ZFMICRO 0x10
182struct u132 {
183 struct kref kref;
184 struct list_head u132_list;
185 struct semaphore sw_lock;
186 struct semaphore scheduler_lock;
187 struct u132_platform_data *board;
188 struct platform_device *platform_dev;
189 struct u132_ring ring[MAX_U132_RINGS];
190 int sequence_num;
191 int going;
192 int power;
193 int reset;
194 int num_ports;
195 u32 hc_control;
196 u32 hc_fminterval;
197 u32 hc_roothub_status;
198 u32 hc_roothub_a;
199 u32 hc_roothub_portstatus[MAX_ROOT_PORTS];
200 int flags;
201 unsigned long next_statechange;
202 struct work_struct monitor;
203 int num_endpoints;
204 struct u132_addr addr[MAX_U132_ADDRS];
205 struct u132_udev udev[MAX_U132_UDEVS];
206 struct u132_port port[MAX_U132_PORTS];
207 struct u132_endp *endp[MAX_U132_ENDPS];
208};
209int usb_ftdi_elan_read_reg(struct platform_device *pdev, u32 *data);
210int usb_ftdi_elan_read_pcimem(struct platform_device *pdev, u8 addressofs,
211 u8 width, u32 *data);
212int usb_ftdi_elan_write_pcimem(struct platform_device *pdev, u8 addressofs,
213 u8 width, u32 data);
214/*
215* these can not be inlines because we need the structure offset!!
216* Does anyone have a better way?????
217*/
218#define u132_read_pcimem(u132, member, data) \
219 usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \
220 ohci_regs, member), 0, data);
221#define u132_write_pcimem(u132, member, data) \
222 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
223 ohci_regs, member), 0, data);
224#define u132_write_pcimem_byte(u132, member, data) \
225 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
226 ohci_regs, member), 0x0e, data);
227static inline struct u132 *udev_to_u132(struct u132_udev *udev)
228{
229 u8 udev_number = udev->udev_number;
230 return container_of(udev, struct u132, udev[udev_number]);
231}
232
233static inline struct u132 *hcd_to_u132(struct usb_hcd *hcd)
234{
235 return (struct u132 *)(hcd->hcd_priv);
236}
237
238static inline struct usb_hcd *u132_to_hcd(struct u132 *u132)
239{
240 return container_of((void *)u132, struct usb_hcd, hcd_priv);
241}
242
243static inline void u132_disable(struct u132 *u132)
244{
245 u132_to_hcd(u132)->state = HC_STATE_HALT;
246}
247
248
249#define kref_to_u132(d) container_of(d, struct u132, kref)
250#define kref_to_u132_endp(d) container_of(d, struct u132_endp, kref)
251#define kref_to_u132_udev(d) container_of(d, struct u132_udev, kref)
252#include "../misc/usb_u132.h"
253static const char hcd_name[] = "u132_hcd";
254#define PORT_C_MASK ((USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | \
255 USB_PORT_STAT_C_SUSPEND | USB_PORT_STAT_C_OVERCURRENT | \
256 USB_PORT_STAT_C_RESET) << 16)
257static void u132_hcd_delete(struct kref *kref)
258{
259 struct u132 *u132 = kref_to_u132(kref);
260 struct platform_device *pdev = u132->platform_dev;
261 struct usb_hcd *hcd = u132_to_hcd(u132);
262 u132->going += 1;
263 down(&u132_module_lock);
264 list_del_init(&u132->u132_list);
265 u132_instances -= 1;
266 up(&u132_module_lock);
267 dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13"
268 "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev);
269 usb_put_hcd(hcd);
270}
271
272static inline void u132_u132_put_kref(struct u132 *u132)
273{
274 kref_put(&u132->kref, u132_hcd_delete);
275}
276
277static inline void u132_u132_init_kref(struct u132 *u132)
278{
279 kref_init(&u132->kref);
280}
281
282static void u132_udev_delete(struct kref *kref)
283{
284 struct u132_udev *udev = kref_to_u132_udev(kref);
285 udev->udev_number = 0;
286 udev->usb_device = NULL;
287 udev->usb_addr = 0;
288 udev->enumeration = 0;
289}
290
291static inline void u132_udev_put_kref(struct u132 *u132, struct u132_udev *udev)
292{
293 kref_put(&udev->kref, u132_udev_delete);
294}
295
296static inline void u132_udev_get_kref(struct u132 *u132, struct u132_udev *udev)
297{
298 kref_get(&udev->kref);
299}
300
301static inline void u132_udev_init_kref(struct u132 *u132,
302 struct u132_udev *udev)
303{
304 kref_init(&udev->kref);
305}
306
307static inline void u132_ring_put_kref(struct u132 *u132, struct u132_ring *ring)
308{
309 kref_put(&u132->kref, u132_hcd_delete);
310}
311
312static void u132_ring_requeue_work(struct u132 *u132, struct u132_ring *ring,
313 unsigned int delta)
314{
315 if (delta > 0) {
316 if (queue_delayed_work(workqueue, &ring->scheduler, delta))
317 return;
318 } else if (queue_work(workqueue, &ring->scheduler))
319 return;
320 kref_put(&u132->kref, u132_hcd_delete);
321 return;
322}
323
324static void u132_ring_queue_work(struct u132 *u132, struct u132_ring *ring,
325 unsigned int delta)
326{
327 kref_get(&u132->kref);
328 u132_ring_requeue_work(u132, ring, delta);
329 return;
330}
331
332static void u132_ring_cancel_work(struct u132 *u132, struct u132_ring *ring)
333{
334 if (cancel_delayed_work(&ring->scheduler)) {
335 kref_put(&u132->kref, u132_hcd_delete);
336 }
337}
338
339static void u132_endp_delete(struct kref *kref)
340{
341 struct u132_endp *endp = kref_to_u132_endp(kref);
342 struct u132 *u132 = endp->u132;
343 u8 usb_addr = endp->usb_addr;
344 u8 usb_endp = endp->usb_endp;
345 u8 address = u132->addr[usb_addr].address;
346 struct u132_udev *udev = &u132->udev[address];
347 u8 endp_number = endp->endp_number;
348 struct usb_host_endpoint *hep = endp->hep;
349 struct u132_ring *ring = endp->ring;
350 struct list_head *head = &endp->endp_ring;
351 ring->length -= 1;
352 if (endp == ring->curr_endp) {
353 if (list_empty(head)) {
354 ring->curr_endp = NULL;
355 list_del(head);
356 } else {
357 struct u132_endp *next_endp = list_entry(head->next,
358 struct u132_endp, endp_ring);
359 ring->curr_endp = next_endp;
360 list_del(head);
361 }} else
362 list_del(head);
363 if (endp->input) {
364 udev->endp_number_in[usb_endp] = 0;
365 u132_udev_put_kref(u132, udev);
366 }
367 if (endp->output) {
368 udev->endp_number_out[usb_endp] = 0;
369 u132_udev_put_kref(u132, udev);
370 }
371 u132->endp[endp_number - 1] = NULL;
372 hep->hcpriv = NULL;
373 kfree(endp);
374 u132_u132_put_kref(u132);
375}
376
377static inline void u132_endp_put_kref(struct u132 *u132, struct u132_endp *endp)
378{
379 kref_put(&endp->kref, u132_endp_delete);
380}
381
382static inline void u132_endp_get_kref(struct u132 *u132, struct u132_endp *endp)
383{
384 kref_get(&endp->kref);
385}
386
387static inline void u132_endp_init_kref(struct u132 *u132,
388 struct u132_endp *endp)
389{
390 kref_init(&endp->kref);
391 kref_get(&u132->kref);
392}
393
394static void u132_endp_queue_work(struct u132 *u132, struct u132_endp *endp,
395 unsigned int delta)
396{
397 if (delta > 0) {
398 if (queue_delayed_work(workqueue, &endp->scheduler, delta))
399 kref_get(&endp->kref);
400 } else if (queue_work(workqueue, &endp->scheduler))
401 kref_get(&endp->kref);
402 return;
403}
404
405static void u132_endp_cancel_work(struct u132 *u132, struct u132_endp *endp)
406{
407 if (cancel_delayed_work(&endp->scheduler))
408 kref_put(&endp->kref, u132_endp_delete);
409}
410
411static inline void u132_monitor_put_kref(struct u132 *u132)
412{
413 kref_put(&u132->kref, u132_hcd_delete);
414}
415
416static void u132_monitor_queue_work(struct u132 *u132, unsigned int delta)
417{
418 if (delta > 0) {
419 if (queue_delayed_work(workqueue, &u132->monitor, delta)) {
420 kref_get(&u132->kref);
421 }
422 } else if (queue_work(workqueue, &u132->monitor))
423 kref_get(&u132->kref);
424 return;
425}
426
427static void u132_monitor_requeue_work(struct u132 *u132, unsigned int delta)
428{
429 if (delta > 0) {
430 if (queue_delayed_work(workqueue, &u132->monitor, delta))
431 return;
432 } else if (queue_work(workqueue, &u132->monitor))
433 return;
434 kref_put(&u132->kref, u132_hcd_delete);
435 return;
436}
437
438static void u132_monitor_cancel_work(struct u132 *u132)
439{
440 if (cancel_delayed_work(&u132->monitor))
441 kref_put(&u132->kref, u132_hcd_delete);
442}
443
444static int read_roothub_info(struct u132 *u132)
445{
446 u32 revision;
447 int retval;
448 retval = u132_read_pcimem(u132, revision, &revision);
449 if (retval) {
450 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
451 "ntrol\n", retval);
452 return retval;
453 } else if ((revision & 0xFF) == 0x10) {
454 } else if ((revision & 0xFF) == 0x11) {
455 } else {
456 dev_err(&u132->platform_dev->dev, "device revision is not valid"
457 " %08X\n", revision);
458 return -ENODEV;
459 }
460 retval = u132_read_pcimem(u132, control, &u132->hc_control);
461 if (retval) {
462 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
463 "ntrol\n", retval);
464 return retval;
465 }
466 retval = u132_read_pcimem(u132, roothub.status,
467 &u132->hc_roothub_status);
468 if (retval) {
469 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
470 "g roothub.status\n", retval);
471 return retval;
472 }
473 retval = u132_read_pcimem(u132, roothub.a, &u132->hc_roothub_a);
474 if (retval) {
475 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
476 "g roothub.a\n", retval);
477 return retval;
478 }
479 {
480 int I = u132->num_ports;
481 int i = 0;
482 while (I-- > 0) {
483 retval = u132_read_pcimem(u132, roothub.portstatus[i],
484 &u132->hc_roothub_portstatus[i]);
485 if (retval) {
486 dev_err(&u132->platform_dev->dev, "error %d acc"
487 "essing device roothub.portstatus[%d]\n"
488 , retval, i);
489 return retval;
490 } else
491 i += 1;
492 }
493 }
494 return 0;
495}
496
497static void u132_hcd_monitor_work(void *data)
498{
499 struct u132 *u132 = data;
500 if (u132->going > 1) {
501 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
502 , u132->going);
503 u132_monitor_put_kref(u132);
504 return;
505 } else if (u132->going > 0) {
506 dev_err(&u132->platform_dev->dev, "device is being removed\n");
507 u132_monitor_put_kref(u132);
508 return;
509 } else {
510 int retval;
511 down(&u132->sw_lock);
512 retval = read_roothub_info(u132);
513 if (retval) {
514 struct usb_hcd *hcd = u132_to_hcd(u132);
515 u132_disable(u132);
516 u132->going = 1;
517 up(&u132->sw_lock);
518 usb_hc_died(hcd);
519 ftdi_elan_gone_away(u132->platform_dev);
520 u132_monitor_put_kref(u132);
521 return;
522 } else {
523 u132_monitor_requeue_work(u132, 500);
524 up(&u132->sw_lock);
525 return;
526 }
527 }
528}
529
530static void u132_hcd_giveback_urb(struct u132 *u132, struct u132_endp *endp,
531 struct urb *urb, int status)
532{
533 struct u132_ring *ring;
534 unsigned long irqs;
535 struct usb_hcd *hcd = u132_to_hcd(u132);
536 urb->error_count = 0;
537 urb->status = status;
538 urb->hcpriv = NULL;
539 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
540 endp->queue_next += 1;
541 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
542 endp->active = 0;
543 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
544 } else {
545 struct list_head *next = endp->urb_more.next;
546 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
547 urb_more);
548 list_del(next);
549 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
550 urbq->urb;
551 endp->active = 0;
552 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
553 kfree(urbq);
554 } down(&u132->scheduler_lock);
555 ring = endp->ring;
556 ring->in_use = 0;
557 u132_ring_cancel_work(u132, ring);
558 u132_ring_queue_work(u132, ring, 0);
559 up(&u132->scheduler_lock);
560 u132_endp_put_kref(u132, endp);
561 usb_hcd_giveback_urb(hcd, urb, NULL);
562 return;
563}
564
565static void u132_hcd_forget_urb(struct u132 *u132, struct u132_endp *endp,
566 struct urb *urb, int status)
567{
568 u132_endp_put_kref(u132, endp);
569}
570
571static void u132_hcd_abandon_urb(struct u132 *u132, struct u132_endp *endp,
572 struct urb *urb, int status)
573{
574 unsigned long irqs;
575 struct usb_hcd *hcd = u132_to_hcd(u132);
576 urb->error_count = 0;
577 urb->status = status;
578 urb->hcpriv = NULL;
579 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
580 endp->queue_next += 1;
581 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
582 endp->active = 0;
583 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
584 } else {
585 struct list_head *next = endp->urb_more.next;
586 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
587 urb_more);
588 list_del(next);
589 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
590 urbq->urb;
591 endp->active = 0;
592 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
593 kfree(urbq);
594 } usb_hcd_giveback_urb(hcd, urb, NULL);
595 return;
596}
597
598static inline int edset_input(struct u132 *u132, struct u132_ring *ring,
599 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
600 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
601 int toggle_bits, int error_count, int condition_code, int repeat_number,
602 int halted, int skipped, int actual, int non_null))
603{
604 return usb_ftdi_elan_edset_input(u132->platform_dev, ring->number, endp,
605 urb, address, endp->usb_endp, toggle_bits, callback);
606}
607
608static inline int edset_setup(struct u132 *u132, struct u132_ring *ring,
609 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
610 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
611 int toggle_bits, int error_count, int condition_code, int repeat_number,
612 int halted, int skipped, int actual, int non_null))
613{
614 return usb_ftdi_elan_edset_setup(u132->platform_dev, ring->number, endp,
615 urb, address, endp->usb_endp, toggle_bits, callback);
616}
617
618static inline int edset_single(struct u132 *u132, struct u132_ring *ring,
619 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
620 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
621 int toggle_bits, int error_count, int condition_code, int repeat_number,
622 int halted, int skipped, int actual, int non_null))
623{
624 return usb_ftdi_elan_edset_single(u132->platform_dev, ring->number,
625 endp, urb, address, endp->usb_endp, toggle_bits, callback);
626}
627
628static inline int edset_output(struct u132 *u132, struct u132_ring *ring,
629 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
630 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
631 int toggle_bits, int error_count, int condition_code, int repeat_number,
632 int halted, int skipped, int actual, int non_null))
633{
634 return usb_ftdi_elan_edset_output(u132->platform_dev, ring->number,
635 endp, urb, address, endp->usb_endp, toggle_bits, callback);
636}
637
638
639/*
640* must not LOCK sw_lock
641*
642*/
643static void u132_hcd_interrupt_recv(void *data, struct urb *urb, u8 *buf,
644 int len, int toggle_bits, int error_count, int condition_code,
645 int repeat_number, int halted, int skipped, int actual, int non_null)
646{
647 struct u132_endp *endp = data;
648 struct u132 *u132 = endp->u132;
649 u8 address = u132->addr[endp->usb_addr].address;
650 struct u132_udev *udev = &u132->udev[address];
651 down(&u132->scheduler_lock);
652 if (u132->going > 1) {
653 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
654 , u132->going);
655 up(&u132->scheduler_lock);
656 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
657 return;
658 } else if (endp->dequeueing) {
659 endp->dequeueing = 0;
660 up(&u132->scheduler_lock);
661 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
662 return;
663 } else if (u132->going > 0) {
664 dev_err(&u132->platform_dev->dev, "device is being removed urb="
665 "%p status=%d\n", urb, urb->status);
666 up(&u132->scheduler_lock);
667 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
668 return;
669 } else if (urb->status == -EINPROGRESS) {
670 struct u132_ring *ring = endp->ring;
671 u8 *u = urb->transfer_buffer + urb->actual_length;
672 u8 *b = buf;
673 int L = len;
674 while (L-- > 0) {
675 *u++ = *b++;
676 }
677 urb->actual_length += len;
678 if ((condition_code == TD_CC_NOERROR) &&
679 (urb->transfer_buffer_length > urb->actual_length)) {
680 endp->toggle_bits = toggle_bits;
681 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
682 1 & toggle_bits);
683 if (urb->actual_length > 0) {
684 int retval;
685 up(&u132->scheduler_lock);
686 retval = edset_single(u132, ring, endp, urb,
687 address, endp->toggle_bits,
688 u132_hcd_interrupt_recv);
689 if (retval == 0) {
690 } else
691 u132_hcd_giveback_urb(u132, endp, urb,
692 retval);
693 } else {
694 ring->in_use = 0;
695 endp->active = 0;
696 endp->jiffies = jiffies +
697 msecs_to_jiffies(urb->interval);
698 u132_ring_cancel_work(u132, ring);
699 u132_ring_queue_work(u132, ring, 0);
700 up(&u132->scheduler_lock);
701 u132_endp_put_kref(u132, endp);
702 }
703 return;
704 } else if ((condition_code == TD_DATAUNDERRUN) &&
705 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
706 endp->toggle_bits = toggle_bits;
707 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
708 1 & toggle_bits);
709 up(&u132->scheduler_lock);
710 u132_hcd_giveback_urb(u132, endp, urb, 0);
711 return;
712 } else {
713 if (condition_code == TD_CC_NOERROR) {
714 endp->toggle_bits = toggle_bits;
715 usb_settoggle(udev->usb_device, endp->usb_endp,
716 0, 1 & toggle_bits);
717 } else if (condition_code == TD_CC_STALL) {
718 endp->toggle_bits = 0x2;
719 usb_settoggle(udev->usb_device, endp->usb_endp,
720 0, 0);
721 } else {
722 endp->toggle_bits = 0x2;
723 usb_settoggle(udev->usb_device, endp->usb_endp,
724 0, 0);
725 dev_err(&u132->platform_dev->dev, "urb=%p givin"
726 "g back INTERRUPT %s\n", urb,
727 cc_to_text[condition_code]);
728 }
729 up(&u132->scheduler_lock);
730 u132_hcd_giveback_urb(u132, endp, urb,
731 cc_to_error[condition_code]);
732 return;
733 }
734 } else {
735 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
736 "s=%d\n", urb, urb->status);
737 up(&u132->scheduler_lock);
738 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
739 return;
740 }
741}
742
743static void u132_hcd_bulk_output_sent(void *data, struct urb *urb, u8 *buf,
744 int len, int toggle_bits, int error_count, int condition_code,
745 int repeat_number, int halted, int skipped, int actual, int non_null)
746{
747 struct u132_endp *endp = data;
748 struct u132 *u132 = endp->u132;
749 u8 address = u132->addr[endp->usb_addr].address;
750 down(&u132->scheduler_lock);
751 if (u132->going > 1) {
752 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
753 , u132->going);
754 up(&u132->scheduler_lock);
755 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
756 return;
757 } else if (endp->dequeueing) {
758 endp->dequeueing = 0;
759 up(&u132->scheduler_lock);
760 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
761 return;
762 } else if (u132->going > 0) {
763 dev_err(&u132->platform_dev->dev, "device is being removed urb="
764 "%p status=%d\n", urb, urb->status);
765 up(&u132->scheduler_lock);
766 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
767 return;
768 } else if (urb->status == -EINPROGRESS) {
769 struct u132_ring *ring = endp->ring;
770 urb->actual_length += len;
771 endp->toggle_bits = toggle_bits;
772 if (urb->transfer_buffer_length > urb->actual_length) {
773 int retval;
774 up(&u132->scheduler_lock);
775 retval = edset_output(u132, ring, endp, urb, address,
776 endp->toggle_bits, u132_hcd_bulk_output_sent);
777 if (retval == 0) {
778 } else
779 u132_hcd_giveback_urb(u132, endp, urb, retval);
780 return;
781 } else {
782 up(&u132->scheduler_lock);
783 u132_hcd_giveback_urb(u132, endp, urb, 0);
784 return;
785 }
786 } else {
787 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
788 "s=%d\n", urb, urb->status);
789 up(&u132->scheduler_lock);
790 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
791 return;
792 }
793}
794
795static void u132_hcd_bulk_input_recv(void *data, struct urb *urb, u8 *buf,
796 int len, int toggle_bits, int error_count, int condition_code,
797 int repeat_number, int halted, int skipped, int actual, int non_null)
798{
799 struct u132_endp *endp = data;
800 struct u132 *u132 = endp->u132;
801 u8 address = u132->addr[endp->usb_addr].address;
802 struct u132_udev *udev = &u132->udev[address];
803 down(&u132->scheduler_lock);
804 if (u132->going > 1) {
805 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
806 , u132->going);
807 up(&u132->scheduler_lock);
808 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
809 return;
810 } else if (endp->dequeueing) {
811 endp->dequeueing = 0;
812 up(&u132->scheduler_lock);
813 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
814 return;
815 } else if (u132->going > 0) {
816 dev_err(&u132->platform_dev->dev, "device is being removed urb="
817 "%p status=%d\n", urb, urb->status);
818 up(&u132->scheduler_lock);
819 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
820 return;
821 } else if (urb->status == -EINPROGRESS) {
822 struct u132_ring *ring = endp->ring;
823 u8 *u = urb->transfer_buffer + urb->actual_length;
824 u8 *b = buf;
825 int L = len;
826 while (L-- > 0) {
827 *u++ = *b++;
828 }
829 urb->actual_length += len;
830 if ((condition_code == TD_CC_NOERROR) &&
831 (urb->transfer_buffer_length > urb->actual_length)) {
832 int retval;
833 endp->toggle_bits = toggle_bits;
834 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
835 1 & toggle_bits);
836 up(&u132->scheduler_lock);
837 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
838 ring->number, endp, urb, address,
839 endp->usb_endp, endp->toggle_bits,
840 u132_hcd_bulk_input_recv);
841 if (retval == 0) {
842 } else
843 u132_hcd_giveback_urb(u132, endp, urb, retval);
844 return;
845 } else if (condition_code == TD_CC_NOERROR) {
846 endp->toggle_bits = toggle_bits;
847 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
848 1 & toggle_bits);
849 up(&u132->scheduler_lock);
850 u132_hcd_giveback_urb(u132, endp, urb,
851 cc_to_error[condition_code]);
852 return;
853 } else if ((condition_code == TD_DATAUNDERRUN) &&
854 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
855 endp->toggle_bits = toggle_bits;
856 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
857 1 & toggle_bits);
858 up(&u132->scheduler_lock);
859 u132_hcd_giveback_urb(u132, endp, urb, 0);
860 return;
861 } else if (condition_code == TD_DATAUNDERRUN) {
862 endp->toggle_bits = toggle_bits;
863 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
864 1 & toggle_bits);
865 dev_warn(&u132->platform_dev->dev, "urb=%p(SHORT NOT OK"
866 ") giving back BULK IN %s\n", urb,
867 cc_to_text[condition_code]);
868 up(&u132->scheduler_lock);
869 u132_hcd_giveback_urb(u132, endp, urb, 0);
870 return;
871 } else if (condition_code == TD_CC_STALL) {
872 endp->toggle_bits = 0x2;
873 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
874 up(&u132->scheduler_lock);
875 u132_hcd_giveback_urb(u132, endp, urb,
876 cc_to_error[condition_code]);
877 return;
878 } else {
879 endp->toggle_bits = 0x2;
880 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
881 dev_err(&u132->platform_dev->dev, "urb=%p giving back B"
882 "ULK IN code=%d %s\n", urb, condition_code,
883 cc_to_text[condition_code]);
884 up(&u132->scheduler_lock);
885 u132_hcd_giveback_urb(u132, endp, urb,
886 cc_to_error[condition_code]);
887 return;
888 }
889 } else {
890 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
891 "s=%d\n", urb, urb->status);
892 up(&u132->scheduler_lock);
893 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
894 return;
895 }
896}
897
898static void u132_hcd_configure_empty_sent(void *data, struct urb *urb, u8 *buf,
899 int len, int toggle_bits, int error_count, int condition_code,
900 int repeat_number, int halted, int skipped, int actual, int non_null)
901{
902 struct u132_endp *endp = data;
903 struct u132 *u132 = endp->u132;
904 down(&u132->scheduler_lock);
905 if (u132->going > 1) {
906 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
907 , u132->going);
908 up(&u132->scheduler_lock);
909 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
910 return;
911 } else if (endp->dequeueing) {
912 endp->dequeueing = 0;
913 up(&u132->scheduler_lock);
914 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
915 return;
916 } else if (u132->going > 0) {
917 dev_err(&u132->platform_dev->dev, "device is being removed urb="
918 "%p status=%d\n", urb, urb->status);
919 up(&u132->scheduler_lock);
920 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
921 return;
922 } else if (urb->status == -EINPROGRESS) {
923 up(&u132->scheduler_lock);
924 u132_hcd_giveback_urb(u132, endp, urb, 0);
925 return;
926 } else {
927 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
928 "s=%d\n", urb, urb->status);
929 up(&u132->scheduler_lock);
930 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
931 return;
932 }
933}
934
935static void u132_hcd_configure_input_recv(void *data, struct urb *urb, u8 *buf,
936 int len, int toggle_bits, int error_count, int condition_code,
937 int repeat_number, int halted, int skipped, int actual, int non_null)
938{
939 struct u132_endp *endp = data;
940 struct u132 *u132 = endp->u132;
941 u8 address = u132->addr[endp->usb_addr].address;
942 down(&u132->scheduler_lock);
943 if (u132->going > 1) {
944 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
945 , u132->going);
946 up(&u132->scheduler_lock);
947 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
948 return;
949 } else if (endp->dequeueing) {
950 endp->dequeueing = 0;
951 up(&u132->scheduler_lock);
952 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
953 return;
954 } else if (u132->going > 0) {
955 dev_err(&u132->platform_dev->dev, "device is being removed urb="
956 "%p status=%d\n", urb, urb->status);
957 up(&u132->scheduler_lock);
958 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
959 return;
960 } else if (urb->status == -EINPROGRESS) {
961 struct u132_ring *ring = endp->ring;
962 u8 *u = urb->transfer_buffer;
963 u8 *b = buf;
964 int L = len;
965 while (L-- > 0) {
966 *u++ = *b++;
967 }
968 urb->actual_length = len;
969 if ((condition_code == TD_CC_NOERROR) || ((condition_code ==
970 TD_DATAUNDERRUN) && ((urb->transfer_flags &
971 URB_SHORT_NOT_OK) == 0))) {
972 int retval;
973 up(&u132->scheduler_lock);
974 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
975 ring->number, endp, urb, address,
976 endp->usb_endp, 0x3,
977 u132_hcd_configure_empty_sent);
978 if (retval == 0) {
979 } else
980 u132_hcd_giveback_urb(u132, endp, urb, retval);
981 return;
982 } else if (condition_code == TD_CC_STALL) {
983 up(&u132->scheduler_lock);
984 dev_warn(&u132->platform_dev->dev, "giving back SETUP I"
985 "NPUT STALL urb %p\n", urb);
986 u132_hcd_giveback_urb(u132, endp, urb,
987 cc_to_error[condition_code]);
988 return;
989 } else {
990 up(&u132->scheduler_lock);
991 dev_err(&u132->platform_dev->dev, "giving back SETUP IN"
992 "PUT %s urb %p\n", cc_to_text[condition_code],
993 urb);
994 u132_hcd_giveback_urb(u132, endp, urb,
995 cc_to_error[condition_code]);
996 return;
997 }
998 } else {
999 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1000 "s=%d\n", urb, urb->status);
1001 up(&u132->scheduler_lock);
1002 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1003 return;
1004 }
1005}
1006
1007static void u132_hcd_configure_empty_recv(void *data, struct urb *urb, u8 *buf,
1008 int len, int toggle_bits, int error_count, int condition_code,
1009 int repeat_number, int halted, int skipped, int actual, int non_null)
1010{
1011 struct u132_endp *endp = data;
1012 struct u132 *u132 = endp->u132;
1013 down(&u132->scheduler_lock);
1014 if (u132->going > 1) {
1015 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1016 , u132->going);
1017 up(&u132->scheduler_lock);
1018 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1019 return;
1020 } else if (endp->dequeueing) {
1021 endp->dequeueing = 0;
1022 up(&u132->scheduler_lock);
1023 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1024 return;
1025 } else if (u132->going > 0) {
1026 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1027 "%p status=%d\n", urb, urb->status);
1028 up(&u132->scheduler_lock);
1029 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1030 return;
1031 } else if (urb->status == -EINPROGRESS) {
1032 up(&u132->scheduler_lock);
1033 u132_hcd_giveback_urb(u132, endp, urb, 0);
1034 return;
1035 } else {
1036 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1037 "s=%d\n", urb, urb->status);
1038 up(&u132->scheduler_lock);
1039 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1040 return;
1041 }
1042}
1043
1044static void u132_hcd_configure_setup_sent(void *data, struct urb *urb, u8 *buf,
1045 int len, int toggle_bits, int error_count, int condition_code,
1046 int repeat_number, int halted, int skipped, int actual, int non_null)
1047{
1048 struct u132_endp *endp = data;
1049 struct u132 *u132 = endp->u132;
1050 u8 address = u132->addr[endp->usb_addr].address;
1051 down(&u132->scheduler_lock);
1052 if (u132->going > 1) {
1053 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1054 , u132->going);
1055 up(&u132->scheduler_lock);
1056 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1057 return;
1058 } else if (endp->dequeueing) {
1059 endp->dequeueing = 0;
1060 up(&u132->scheduler_lock);
1061 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1062 return;
1063 } else if (u132->going > 0) {
1064 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1065 "%p status=%d\n", urb, urb->status);
1066 up(&u132->scheduler_lock);
1067 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1068 return;
1069 } else if (urb->status == -EINPROGRESS) {
1070 if (usb_pipein(urb->pipe)) {
1071 int retval;
1072 struct u132_ring *ring = endp->ring;
1073 up(&u132->scheduler_lock);
1074 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1075 ring->number, endp, urb, address,
1076 endp->usb_endp, 0,
1077 u132_hcd_configure_input_recv);
1078 if (retval == 0) {
1079 } else
1080 u132_hcd_giveback_urb(u132, endp, urb, retval);
1081 return;
1082 } else {
1083 int retval;
1084 struct u132_ring *ring = endp->ring;
1085 up(&u132->scheduler_lock);
1086 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1087 ring->number, endp, urb, address,
1088 endp->usb_endp, 0,
1089 u132_hcd_configure_empty_recv);
1090 if (retval == 0) {
1091 } else
1092 u132_hcd_giveback_urb(u132, endp, urb, retval);
1093 return;
1094 }
1095 } else {
1096 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1097 "s=%d\n", urb, urb->status);
1098 up(&u132->scheduler_lock);
1099 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1100 return;
1101 }
1102}
1103
1104static void u132_hcd_enumeration_empty_recv(void *data, struct urb *urb,
1105 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1106 int repeat_number, int halted, int skipped, int actual, int non_null)
1107{
1108 struct u132_endp *endp = data;
1109 struct u132 *u132 = endp->u132;
1110 u8 address = u132->addr[endp->usb_addr].address;
1111 struct u132_udev *udev = &u132->udev[address];
1112 down(&u132->scheduler_lock);
1113 if (u132->going > 1) {
1114 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1115 , u132->going);
1116 up(&u132->scheduler_lock);
1117 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1118 return;
1119 } else if (endp->dequeueing) {
1120 endp->dequeueing = 0;
1121 up(&u132->scheduler_lock);
1122 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1123 return;
1124 } else if (u132->going > 0) {
1125 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1126 "%p status=%d\n", urb, urb->status);
1127 up(&u132->scheduler_lock);
1128 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1129 return;
1130 } else if (urb->status == -EINPROGRESS) {
1131 u132->addr[0].address = 0;
1132 endp->usb_addr = udev->usb_addr;
1133 up(&u132->scheduler_lock);
1134 u132_hcd_giveback_urb(u132, endp, urb, 0);
1135 return;
1136 } else {
1137 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1138 "s=%d\n", urb, urb->status);
1139 up(&u132->scheduler_lock);
1140 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1141 return;
1142 }
1143}
1144
1145static void u132_hcd_enumeration_address_sent(void *data, struct urb *urb,
1146 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1147 int repeat_number, int halted, int skipped, int actual, int non_null)
1148{
1149 struct u132_endp *endp = data;
1150 struct u132 *u132 = endp->u132;
1151 down(&u132->scheduler_lock);
1152 if (u132->going > 1) {
1153 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1154 , u132->going);
1155 up(&u132->scheduler_lock);
1156 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1157 return;
1158 } else if (endp->dequeueing) {
1159 endp->dequeueing = 0;
1160 up(&u132->scheduler_lock);
1161 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1162 return;
1163 } else if (u132->going > 0) {
1164 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1165 "%p status=%d\n", urb, urb->status);
1166 up(&u132->scheduler_lock);
1167 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1168 return;
1169 } else if (urb->status == -EINPROGRESS) {
1170 int retval;
1171 struct u132_ring *ring = endp->ring;
1172 up(&u132->scheduler_lock);
1173 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1174 ring->number, endp, urb, 0, endp->usb_endp, 0,
1175 u132_hcd_enumeration_empty_recv);
1176 if (retval == 0) {
1177 } else
1178 u132_hcd_giveback_urb(u132, endp, urb, retval);
1179 return;
1180 } else {
1181 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1182 "s=%d\n", urb, urb->status);
1183 up(&u132->scheduler_lock);
1184 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1185 return;
1186 }
1187}
1188
1189static void u132_hcd_initial_empty_sent(void *data, struct urb *urb, u8 *buf,
1190 int len, int toggle_bits, int error_count, int condition_code,
1191 int repeat_number, int halted, int skipped, int actual, int non_null)
1192{
1193 struct u132_endp *endp = data;
1194 struct u132 *u132 = endp->u132;
1195 down(&u132->scheduler_lock);
1196 if (u132->going > 1) {
1197 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1198 , u132->going);
1199 up(&u132->scheduler_lock);
1200 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1201 return;
1202 } else if (endp->dequeueing) {
1203 endp->dequeueing = 0;
1204 up(&u132->scheduler_lock);
1205 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1206 return;
1207 } else if (u132->going > 0) {
1208 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1209 "%p status=%d\n", urb, urb->status);
1210 up(&u132->scheduler_lock);
1211 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1212 return;
1213 } else if (urb->status == -EINPROGRESS) {
1214 up(&u132->scheduler_lock);
1215 u132_hcd_giveback_urb(u132, endp, urb, 0);
1216 return;
1217 } else {
1218 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1219 "s=%d\n", urb, urb->status);
1220 up(&u132->scheduler_lock);
1221 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1222 return;
1223 }
1224}
1225
1226static void u132_hcd_initial_input_recv(void *data, struct urb *urb, u8 *buf,
1227 int len, int toggle_bits, int error_count, int condition_code,
1228 int repeat_number, int halted, int skipped, int actual, int non_null)
1229{
1230 struct u132_endp *endp = data;
1231 struct u132 *u132 = endp->u132;
1232 u8 address = u132->addr[endp->usb_addr].address;
1233 down(&u132->scheduler_lock);
1234 if (u132->going > 1) {
1235 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1236 , u132->going);
1237 up(&u132->scheduler_lock);
1238 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1239 return;
1240 } else if (endp->dequeueing) {
1241 endp->dequeueing = 0;
1242 up(&u132->scheduler_lock);
1243 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1244 return;
1245 } else if (u132->going > 0) {
1246 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1247 "%p status=%d\n", urb, urb->status);
1248 up(&u132->scheduler_lock);
1249 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1250 return;
1251 } else if (urb->status == -EINPROGRESS) {
1252 int retval;
1253 struct u132_ring *ring = endp->ring;
1254 u8 *u = urb->transfer_buffer;
1255 u8 *b = buf;
1256 int L = len;
1257 while (L-- > 0) {
1258 *u++ = *b++;
1259 }
1260 urb->actual_length = len;
1261 up(&u132->scheduler_lock);
1262 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
1263 ring->number, endp, urb, address, endp->usb_endp, 0x3,
1264 u132_hcd_initial_empty_sent);
1265 if (retval == 0) {
1266 } else
1267 u132_hcd_giveback_urb(u132, endp, urb, retval);
1268 return;
1269 } else {
1270 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1271 "s=%d\n", urb, urb->status);
1272 up(&u132->scheduler_lock);
1273 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1274 return;
1275 }
1276}
1277
1278static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf,
1279 int len, int toggle_bits, int error_count, int condition_code,
1280 int repeat_number, int halted, int skipped, int actual, int non_null)
1281{
1282 struct u132_endp *endp = data;
1283 struct u132 *u132 = endp->u132;
1284 u8 address = u132->addr[endp->usb_addr].address;
1285 down(&u132->scheduler_lock);
1286 if (u132->going > 1) {
1287 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1288 , u132->going);
1289 up(&u132->scheduler_lock);
1290 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1291 return;
1292 } else if (endp->dequeueing) {
1293 endp->dequeueing = 0;
1294 up(&u132->scheduler_lock);
1295 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1296 return;
1297 } else if (u132->going > 0) {
1298 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1299 "%p status=%d\n", urb, urb->status);
1300 up(&u132->scheduler_lock);
1301 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1302 return;
1303 } else if (urb->status == -EINPROGRESS) {
1304 int retval;
1305 struct u132_ring *ring = endp->ring;
1306 up(&u132->scheduler_lock);
1307 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1308 ring->number, endp, urb, address, endp->usb_endp, 0,
1309 u132_hcd_initial_input_recv);
1310 if (retval == 0) {
1311 } else
1312 u132_hcd_giveback_urb(u132, endp, urb, retval);
1313 return;
1314 } else {
1315 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1316 "s=%d\n", urb, urb->status);
1317 up(&u132->scheduler_lock);
1318 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1319 return;
1320 }
1321}
1322
1323static void u132_hcd_ring_work_scheduler(void *data);
1324static void u132_hcd_endp_work_scheduler(void *data);
1325/*
1326* this work function is only executed from the work queue
1327*
1328*/
1329static void u132_hcd_ring_work_scheduler(void *data)
1330{
1331 struct u132_ring *ring = data;
1332 struct u132 *u132 = ring->u132;
1333 down(&u132->scheduler_lock);
1334 if (ring->in_use) {
1335 up(&u132->scheduler_lock);
1336 u132_ring_put_kref(u132, ring);
1337 return;
1338 } else if (ring->curr_endp) {
1339 struct u132_endp *last_endp = ring->curr_endp;
1340 struct list_head *scan;
1341 struct list_head *head = &last_endp->endp_ring;
1342 unsigned long wakeup = 0;
1343 list_for_each(scan, head) {
1344 struct u132_endp *endp = list_entry(scan,
1345 struct u132_endp, endp_ring);
1346 if (endp->queue_next == endp->queue_last) {
1347 } else if ((endp->delayed == 0)
1348 || time_after_eq(jiffies, endp->jiffies)) {
1349 ring->curr_endp = endp;
1350 u132_endp_cancel_work(u132, last_endp);
1351 u132_endp_queue_work(u132, last_endp, 0);
1352 up(&u132->scheduler_lock);
1353 u132_ring_put_kref(u132, ring);
1354 return;
1355 } else {
1356 unsigned long delta = endp->jiffies - jiffies;
1357 if (delta > wakeup)
1358 wakeup = delta;
1359 }
1360 }
1361 if (last_endp->queue_next == last_endp->queue_last) {
1362 } else if ((last_endp->delayed == 0) || time_after_eq(jiffies,
1363 last_endp->jiffies)) {
1364 u132_endp_cancel_work(u132, last_endp);
1365 u132_endp_queue_work(u132, last_endp, 0);
1366 up(&u132->scheduler_lock);
1367 u132_ring_put_kref(u132, ring);
1368 return;
1369 } else {
1370 unsigned long delta = last_endp->jiffies - jiffies;
1371 if (delta > wakeup)
1372 wakeup = delta;
1373 }
1374 if (wakeup > 0) {
1375 u132_ring_requeue_work(u132, ring, wakeup);
1376 up(&u132->scheduler_lock);
1377 return;
1378 } else {
1379 up(&u132->scheduler_lock);
1380 u132_ring_put_kref(u132, ring);
1381 return;
1382 }
1383 } else {
1384 up(&u132->scheduler_lock);
1385 u132_ring_put_kref(u132, ring);
1386 return;
1387 }
1388}
1389
1390static void u132_hcd_endp_work_scheduler(void *data)
1391{
1392 struct u132_ring *ring;
1393 struct u132_endp *endp = data;
1394 struct u132 *u132 = endp->u132;
1395 down(&u132->scheduler_lock);
1396 ring = endp->ring;
1397 if (endp->edset_flush) {
1398 endp->edset_flush = 0;
1399 if (endp->dequeueing)
1400 usb_ftdi_elan_edset_flush(u132->platform_dev,
1401 ring->number, endp);
1402 up(&u132->scheduler_lock);
1403 u132_endp_put_kref(u132, endp);
1404 return;
1405 } else if (endp->active) {
1406 up(&u132->scheduler_lock);
1407 u132_endp_put_kref(u132, endp);
1408 return;
1409 } else if (ring->in_use) {
1410 up(&u132->scheduler_lock);
1411 u132_endp_put_kref(u132, endp);
1412 return;
1413 } else if (endp->queue_next == endp->queue_last) {
1414 up(&u132->scheduler_lock);
1415 u132_endp_put_kref(u132, endp);
1416 return;
1417 } else if (endp->pipetype == PIPE_INTERRUPT) {
1418 u8 address = u132->addr[endp->usb_addr].address;
1419 if (ring->in_use) {
1420 up(&u132->scheduler_lock);
1421 u132_endp_put_kref(u132, endp);
1422 return;
1423 } else {
1424 int retval;
1425 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1426 endp->queue_next];
1427 endp->active = 1;
1428 ring->curr_endp = endp;
1429 ring->in_use = 1;
1430 up(&u132->scheduler_lock);
1431 retval = edset_single(u132, ring, endp, urb, address,
1432 endp->toggle_bits, u132_hcd_interrupt_recv);
1433 if (retval == 0) {
1434 } else
1435 u132_hcd_giveback_urb(u132, endp, urb, retval);
1436 return;
1437 }
1438 } else if (endp->pipetype == PIPE_CONTROL) {
1439 u8 address = u132->addr[endp->usb_addr].address;
1440 if (ring->in_use) {
1441 up(&u132->scheduler_lock);
1442 u132_endp_put_kref(u132, endp);
1443 return;
1444 } else if (address == 0) {
1445 int retval;
1446 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1447 endp->queue_next];
1448 endp->active = 1;
1449 ring->curr_endp = endp;
1450 ring->in_use = 1;
1451 up(&u132->scheduler_lock);
1452 retval = edset_setup(u132, ring, endp, urb, address,
1453 0x2, u132_hcd_initial_setup_sent);
1454 if (retval == 0) {
1455 } else
1456 u132_hcd_giveback_urb(u132, endp, urb, retval);
1457 return;
1458 } else if (endp->usb_addr == 0) {
1459 int retval;
1460 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1461 endp->queue_next];
1462 endp->active = 1;
1463 ring->curr_endp = endp;
1464 ring->in_use = 1;
1465 up(&u132->scheduler_lock);
1466 retval = edset_setup(u132, ring, endp, urb, 0, 0x2,
1467 u132_hcd_enumeration_address_sent);
1468 if (retval == 0) {
1469 } else
1470 u132_hcd_giveback_urb(u132, endp, urb, retval);
1471 return;
1472 } else {
1473 int retval;
1474 u8 address = u132->addr[endp->usb_addr].address;
1475 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1476 endp->queue_next];
1477 endp->active = 1;
1478 ring->curr_endp = endp;
1479 ring->in_use = 1;
1480 up(&u132->scheduler_lock);
1481 retval = edset_setup(u132, ring, endp, urb, address,
1482 0x2, u132_hcd_configure_setup_sent);
1483 if (retval == 0) {
1484 } else
1485 u132_hcd_giveback_urb(u132, endp, urb, retval);
1486 return;
1487 }
1488 } else {
1489 if (endp->input) {
1490 u8 address = u132->addr[endp->usb_addr].address;
1491 if (ring->in_use) {
1492 up(&u132->scheduler_lock);
1493 u132_endp_put_kref(u132, endp);
1494 return;
1495 } else {
1496 int retval;
1497 struct urb *urb = endp->urb_list[
1498 ENDP_QUEUE_MASK & endp->queue_next];
1499 endp->active = 1;
1500 ring->curr_endp = endp;
1501 ring->in_use = 1;
1502 up(&u132->scheduler_lock);
1503 retval = edset_input(u132, ring, endp, urb,
1504 address, endp->toggle_bits,
1505 u132_hcd_bulk_input_recv);
1506 if (retval == 0) {
1507 } else
1508 u132_hcd_giveback_urb(u132, endp, urb,
1509 retval);
1510 return;
1511 }
1512 } else { /* output pipe */
1513 u8 address = u132->addr[endp->usb_addr].address;
1514 if (ring->in_use) {
1515 up(&u132->scheduler_lock);
1516 u132_endp_put_kref(u132, endp);
1517 return;
1518 } else {
1519 int retval;
1520 struct urb *urb = endp->urb_list[
1521 ENDP_QUEUE_MASK & endp->queue_next];
1522 endp->active = 1;
1523 ring->curr_endp = endp;
1524 ring->in_use = 1;
1525 up(&u132->scheduler_lock);
1526 retval = edset_output(u132, ring, endp, urb,
1527 address, endp->toggle_bits,
1528 u132_hcd_bulk_output_sent);
1529 if (retval == 0) {
1530 } else
1531 u132_hcd_giveback_urb(u132, endp, urb,
1532 retval);
1533 return;
1534 }
1535 }
1536 }
1537}
1538
1539static void port_power(struct u132 *u132, int pn, int is_on)
1540{
1541 u132->port[pn].power = is_on;
1542}
1543
1544static void u132_power(struct u132 *u132, int is_on)
1545{
1546 struct usb_hcd *hcd = u132_to_hcd(u132)
1547 ; /* hub is inactive unless the port is powered */
1548 if (is_on) {
1549 if (u132->power)
1550 return;
1551 u132->power = 1;
1552 hcd->self.controller->power.power_state = PMSG_ON;
1553 } else {
1554 u132->power = 0;
1555 hcd->state = HC_STATE_HALT;
1556 hcd->self.controller->power.power_state = PMSG_SUSPEND;
1557 }
1558}
1559
1560static int u132_periodic_reinit(struct u132 *u132)
1561{
1562 int retval;
1563 u32 fi = u132->hc_fminterval & 0x03fff;
1564 u32 fit;
1565 u32 fminterval;
1566 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1567 if (retval)
1568 return retval;
1569 fit = fminterval & FIT;
1570 retval = u132_write_pcimem(u132, fminterval,
1571 (fit ^ FIT) | u132->hc_fminterval);
1572 if (retval)
1573 return retval;
1574 retval = u132_write_pcimem(u132, periodicstart,
1575 ((9 *fi) / 10) & 0x3fff);
1576 if (retval)
1577 return retval;
1578 return 0;
1579}
1580
1581static char *hcfs2string(int state)
1582{
1583 switch (state) {
1584 case OHCI_USB_RESET:
1585 return "reset";
1586 case OHCI_USB_RESUME:
1587 return "resume";
1588 case OHCI_USB_OPER:
1589 return "operational";
1590 case OHCI_USB_SUSPEND:
1591 return "suspend";
1592 }
1593 return "?";
1594}
1595
1596static int u132_usb_reset(struct u132 *u132)
1597{
1598 int retval;
1599 retval = u132_read_pcimem(u132, control, &u132->hc_control);
1600 if (retval)
1601 return retval;
1602 u132->hc_control &= OHCI_CTRL_RWC;
1603 retval = u132_write_pcimem(u132, control, u132->hc_control);
1604 if (retval)
1605 return retval;
1606 return 0;
1607}
1608
1609static int u132_init(struct u132 *u132)
1610{
1611 int retval;
1612 u32 control;
1613 u132_disable(u132);
1614 u132->next_statechange =
1615 jiffies; /* SMM owns the HC? not for long! */ {
1616 u32 control;
1617 retval = u132_read_pcimem(u132, control, &control);
1618 if (retval)
1619 return retval;
1620 if (control & OHCI_CTRL_IR) {
1621 u32 temp = 50;
1622 retval = u132_write_pcimem(u132, intrenable,
1623 OHCI_INTR_OC);
1624 if (retval)
1625 return retval;
1626 retval = u132_write_pcimem_byte(u132, cmdstatus,
1627 OHCI_OCR);
1628 if (retval)
1629 return retval;
1630 check:{
1631 retval = u132_read_pcimem(u132, control,
1632 &control);
1633 if (retval)
1634 return retval;
1635 }
1636 if (control & OHCI_CTRL_IR) {
1637 msleep(10);
1638 if (--temp == 0) {
1639 dev_err(&u132->platform_dev->dev, "USB "
1640 "HC takeover failed!(BIOS/SMM b"
1641 "ug) control=%08X\n", control);
1642 return -EBUSY;
1643 }
1644 goto check;
1645 }
1646 u132_usb_reset(u132);
1647 }
1648 }
1649 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE);
1650 if (retval)
1651 return retval;
1652 retval = u132_read_pcimem(u132, control, &control);
1653 if (retval)
1654 return retval;
1655 if (u132->num_ports == 0) {
1656 u32 rh_a = -1;
1657 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
1658 if (retval)
1659 return retval;
1660 u132->num_ports = rh_a & RH_A_NDP;
1661 retval = read_roothub_info(u132);
1662 if (retval)
1663 return retval;
1664 }
1665 if (u132->num_ports > MAX_U132_PORTS) {
1666 return -EINVAL;
1667 }
1668 return 0;
1669}
1670
1671
1672/* Start an OHCI controller, set the BUS operational
1673* resets USB and controller
1674* enable interrupts
1675*/
1676static int u132_run(struct u132 *u132)
1677{
1678 int retval;
1679 u32 control;
1680 u32 status;
1681 u32 fminterval;
1682 u32 periodicstart;
1683 u32 cmdstatus;
1684 u32 roothub_a;
1685 int mask = OHCI_INTR_INIT;
1686 int first = u132->hc_fminterval == 0;
1687 int sleep_time = 0;
1688 int reset_timeout = 30; /* ... allow extra time */
1689 u132_disable(u132);
1690 if (first) {
1691 u32 temp;
1692 retval = u132_read_pcimem(u132, fminterval, &temp);
1693 if (retval)
1694 return retval;
1695 u132->hc_fminterval = temp & 0x3fff;
1696 if (u132->hc_fminterval != FI) {
1697 }
1698 u132->hc_fminterval |= FSMP(u132->hc_fminterval) << 16;
1699 }
1700 retval = u132_read_pcimem(u132, control, &u132->hc_control);
1701 if (retval)
1702 return retval;
1703 dev_info(&u132->platform_dev->dev, "resetting from state '%s', control "
1704 "= %08X\n", hcfs2string(u132->hc_control & OHCI_CTRL_HCFS),
1705 u132->hc_control);
1706 switch (u132->hc_control & OHCI_CTRL_HCFS) {
1707 case OHCI_USB_OPER:
1708 sleep_time = 0;
1709 break;
1710 case OHCI_USB_SUSPEND:
1711 case OHCI_USB_RESUME:
1712 u132->hc_control &= OHCI_CTRL_RWC;
1713 u132->hc_control |= OHCI_USB_RESUME;
1714 sleep_time = 10;
1715 break;
1716 default:
1717 u132->hc_control &= OHCI_CTRL_RWC;
1718 u132->hc_control |= OHCI_USB_RESET;
1719 sleep_time = 50;
1720 break;
1721 }
1722 retval = u132_write_pcimem(u132, control, u132->hc_control);
1723 if (retval)
1724 return retval;
1725 retval = u132_read_pcimem(u132, control, &control);
1726 if (retval)
1727 return retval;
1728 msleep(sleep_time);
1729 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1730 if (retval)
1731 return retval;
1732 if (!(roothub_a & RH_A_NPS)) {
1733 int temp; /* power down each port */
1734 for (temp = 0; temp < u132->num_ports; temp++) {
1735 retval = u132_write_pcimem(u132,
1736 roothub.portstatus[temp], RH_PS_LSDA);
1737 if (retval)
1738 return retval;
1739 }
1740 }
1741 retval = u132_read_pcimem(u132, control, &control);
1742 if (retval)
1743 return retval;
1744 retry:retval = u132_read_pcimem(u132, cmdstatus, &status);
1745 if (retval)
1746 return retval;
1747 retval = u132_write_pcimem_byte(u132, cmdstatus, OHCI_HCR);
1748 if (retval)
1749 return retval;
1750 extra:{
1751 retval = u132_read_pcimem(u132, cmdstatus, &status);
1752 if (retval)
1753 return retval;
1754 if (0 != (status & OHCI_HCR)) {
1755 if (--reset_timeout == 0) {
1756 dev_err(&u132->platform_dev->dev, "USB HC reset"
1757 " timed out!\n");
1758 return -ENODEV;
1759 } else {
1760 msleep(5);
1761 goto extra;
1762 }
1763 }
1764 }
1765 if (u132->flags & OHCI_QUIRK_INITRESET) {
1766 retval = u132_write_pcimem(u132, control, u132->hc_control);
1767 if (retval)
1768 return retval;
1769 retval = u132_read_pcimem(u132, control, &control);
1770 if (retval)
1771 return retval;
1772 }
1773 retval = u132_write_pcimem(u132, ed_controlhead, 0x00000000);
1774 if (retval)
1775 return retval;
1776 retval = u132_write_pcimem(u132, ed_bulkhead, 0x11000000);
1777 if (retval)
1778 return retval;
1779 retval = u132_write_pcimem(u132, hcca, 0x00000000);
1780 if (retval)
1781 return retval;
1782 retval = u132_periodic_reinit(u132);
1783 if (retval)
1784 return retval;
1785 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1786 if (retval)
1787 return retval;
1788 retval = u132_read_pcimem(u132, periodicstart, &periodicstart);
1789 if (retval)
1790 return retval;
1791 if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) {
1792 if (!(u132->flags & OHCI_QUIRK_INITRESET)) {
1793 u132->flags |= OHCI_QUIRK_INITRESET;
1794 goto retry;
1795 } else
1796 dev_err(&u132->platform_dev->dev, "init err(%08x %04x)"
1797 "\n", fminterval, periodicstart);
1798 } /* start controller operations */
1799 u132->hc_control &= OHCI_CTRL_RWC;
1800 u132->hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER;
1801 retval = u132_write_pcimem(u132, control, u132->hc_control);
1802 if (retval)
1803 return retval;
1804 retval = u132_write_pcimem_byte(u132, cmdstatus, OHCI_BLF);
1805 if (retval)
1806 return retval;
1807 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus);
1808 if (retval)
1809 return retval;
1810 retval = u132_read_pcimem(u132, control, &control);
1811 if (retval)
1812 return retval;
1813 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1814 retval = u132_write_pcimem(u132, roothub.status, RH_HS_DRWE);
1815 if (retval)
1816 return retval;
1817 retval = u132_write_pcimem(u132, intrstatus, mask);
1818 if (retval)
1819 return retval;
1820 retval = u132_write_pcimem(u132, intrdisable,
1821 OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO |
1822 OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH |
1823 OHCI_INTR_SO);
1824 if (retval)
1825 return retval; /* handle root hub init quirks ... */
1826 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1827 if (retval)
1828 return retval;
1829 roothub_a &= ~(RH_A_PSM | RH_A_OCPM);
1830 if (u132->flags & OHCI_QUIRK_SUPERIO) {
1831 roothub_a |= RH_A_NOCP;
1832 roothub_a &= ~(RH_A_POTPGT | RH_A_NPS);
1833 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1834 if (retval)
1835 return retval;
1836 } else if ((u132->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
1837 roothub_a |= RH_A_NPS;
1838 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1839 if (retval)
1840 return retval;
1841 }
1842 retval = u132_write_pcimem(u132, roothub.status, RH_HS_LPSC);
1843 if (retval)
1844 return retval;
1845 retval = u132_write_pcimem(u132, roothub.b,
1846 (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM);
1847 if (retval)
1848 return retval;
1849 retval = u132_read_pcimem(u132, control, &control);
1850 if (retval)
1851 return retval;
1852 mdelay((roothub_a >> 23) & 0x1fe);
1853 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1854 return 0;
1855}
1856
1857static void u132_hcd_stop(struct usb_hcd *hcd)
1858{
1859 struct u132 *u132 = hcd_to_u132(hcd);
1860 if (u132->going > 1) {
1861 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1862 , u132->going);
1863 } else if (u132->going > 0) {
1864 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
1865 "ed\n", hcd);
1866 } else {
1867 down(&u132->sw_lock);
1868 msleep(100);
1869 u132_power(u132, 0);
1870 up(&u132->sw_lock);
1871 }
1872}
1873
1874static int u132_hcd_start(struct usb_hcd *hcd)
1875{
1876 struct u132 *u132 = hcd_to_u132(hcd);
1877 if (u132->going > 1) {
1878 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1879 , u132->going);
1880 return -ENODEV;
1881 } else if (u132->going > 0) {
1882 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1883 return -ESHUTDOWN;
1884 } else if (hcd->self.controller) {
1885 int retval;
1886 struct platform_device *pdev =
1887 to_platform_device(hcd->self.controller);
1888 u16 vendor = ((struct u132_platform_data *)
1889 (pdev->dev.platform_data))->vendor;
1890 u16 device = ((struct u132_platform_data *)
1891 (pdev->dev.platform_data))->device;
1892 down(&u132->sw_lock);
1893 msleep(10);
1894 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) {
1895 u132->flags = OHCI_QUIRK_AMD756;
1896 } else if (vendor == PCI_VENDOR_ID_OPTI && device == 0xc861) {
1897 dev_err(&u132->platform_dev->dev, "WARNING: OPTi workar"
1898 "ounds unavailable\n");
1899 } else if (vendor == PCI_VENDOR_ID_COMPAQ && device == 0xa0f8)
1900 u132->flags |= OHCI_QUIRK_ZFMICRO;
1901 retval = u132_run(u132);
1902 if (retval) {
1903 u132_disable(u132);
1904 u132->going = 1;
1905 }
1906 msleep(100);
1907 up(&u132->sw_lock);
1908 return retval;
1909 } else {
1910 dev_err(&u132->platform_dev->dev, "platform_device missing\n");
1911 return -ENODEV;
1912 }
1913}
1914
1915static int u132_hcd_reset(struct usb_hcd *hcd)
1916{
1917 struct u132 *u132 = hcd_to_u132(hcd);
1918 if (u132->going > 1) {
1919 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1920 , u132->going);
1921 return -ENODEV;
1922 } else if (u132->going > 0) {
1923 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1924 return -ESHUTDOWN;
1925 } else {
1926 int retval;
1927 down(&u132->sw_lock);
1928 retval = u132_init(u132);
1929 if (retval) {
1930 u132_disable(u132);
1931 u132->going = 1;
1932 }
1933 up(&u132->sw_lock);
1934 return retval;
1935 }
1936}
1937
1938static int create_endpoint_and_queue_int(struct u132 *u132,
1939 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb,
1940 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1941 gfp_t mem_flags)
1942{
1943 struct u132_ring *ring;
1944 unsigned long irqs;
1945 u8 endp_number = ++u132->num_endpoints;
1946 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
1947 kmalloc(sizeof(struct u132_endp), mem_flags);
1948 if (!endp) {
1949 return -ENOMEM;
1950 }
1951 INIT_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler, (void *)endp);
1952 spin_lock_init(&endp->queue_lock.slock);
1953 INIT_LIST_HEAD(&endp->urb_more);
1954 ring = endp->ring = &u132->ring[0];
1955 if (ring->curr_endp) {
1956 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
1957 } else {
1958 INIT_LIST_HEAD(&endp->endp_ring);
1959 ring->curr_endp = endp;
1960 }
1961 ring->length += 1;
1962 endp->dequeueing = 0;
1963 endp->edset_flush = 0;
1964 endp->active = 0;
1965 endp->delayed = 0;
1966 endp->endp_number = endp_number;
1967 endp->u132 = u132;
1968 endp->hep = hep;
1969 endp->pipetype = usb_pipetype(urb->pipe);
1970 u132_endp_init_kref(u132, endp);
1971 if (usb_pipein(urb->pipe)) {
1972 endp->toggle_bits = 0x2;
1973 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
1974 endp->input = 1;
1975 endp->output = 0;
1976 udev->endp_number_in[usb_endp] = endp_number;
1977 u132_udev_get_kref(u132, udev);
1978 } else {
1979 endp->toggle_bits = 0x2;
1980 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
1981 endp->input = 0;
1982 endp->output = 1;
1983 udev->endp_number_out[usb_endp] = endp_number;
1984 u132_udev_get_kref(u132, udev);
1985 }
1986 urb->hcpriv = u132;
1987 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1988 endp->delayed = 1;
1989 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1990 endp->udev_number = address;
1991 endp->usb_addr = usb_addr;
1992 endp->usb_endp = usb_endp;
1993 endp->queue_size = 1;
1994 endp->queue_last = 0;
1995 endp->queue_next = 0;
1996 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1997 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1998 u132_endp_queue_work(u132, endp, msecs_to_jiffies(urb->interval));
1999 return 0;
2000}
2001
2002static int queue_int_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2003 struct usb_host_endpoint *hep, struct urb *urb,
2004 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2005 u8 usb_endp, u8 address)
2006{
2007 urb->hcpriv = u132;
2008 endp->delayed = 1;
2009 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
2010 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2011 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2012 } else {
2013 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
2014 GFP_ATOMIC);
2015 if (urbq == NULL) {
2016 endp->queue_size -= 1;
2017 return -ENOMEM;
2018 } else {
2019 list_add_tail(&urbq->urb_more, &endp->urb_more);
2020 urbq->urb = urb;
2021 }
2022 }
2023 return 0;
2024}
2025
2026static int create_endpoint_and_queue_bulk(struct u132 *u132,
2027 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb,
2028 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
2029 gfp_t mem_flags)
2030{
2031 int ring_number;
2032 struct u132_ring *ring;
2033 unsigned long irqs;
2034 u8 endp_number = ++u132->num_endpoints;
2035 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
2036 kmalloc(sizeof(struct u132_endp), mem_flags);
2037 if (!endp) {
2038 return -ENOMEM;
2039 }
2040 INIT_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler, (void *)endp);
2041 spin_lock_init(&endp->queue_lock.slock);
2042 INIT_LIST_HEAD(&endp->urb_more);
2043 endp->dequeueing = 0;
2044 endp->edset_flush = 0;
2045 endp->active = 0;
2046 endp->delayed = 0;
2047 endp->endp_number = endp_number;
2048 endp->u132 = u132;
2049 endp->hep = hep;
2050 endp->pipetype = usb_pipetype(urb->pipe);
2051 u132_endp_init_kref(u132, endp);
2052 if (usb_pipein(urb->pipe)) {
2053 endp->toggle_bits = 0x2;
2054 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
2055 ring_number = 3;
2056 endp->input = 1;
2057 endp->output = 0;
2058 udev->endp_number_in[usb_endp] = endp_number;
2059 u132_udev_get_kref(u132, udev);
2060 } else {
2061 endp->toggle_bits = 0x2;
2062 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
2063 ring_number = 2;
2064 endp->input = 0;
2065 endp->output = 1;
2066 udev->endp_number_out[usb_endp] = endp_number;
2067 u132_udev_get_kref(u132, udev);
2068 }
2069 ring = endp->ring = &u132->ring[ring_number - 1];
2070 if (ring->curr_endp) {
2071 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2072 } else {
2073 INIT_LIST_HEAD(&endp->endp_ring);
2074 ring->curr_endp = endp;
2075 }
2076 ring->length += 1;
2077 urb->hcpriv = u132;
2078 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2079 endp->udev_number = address;
2080 endp->usb_addr = usb_addr;
2081 endp->usb_endp = usb_endp;
2082 endp->queue_size = 1;
2083 endp->queue_last = 0;
2084 endp->queue_next = 0;
2085 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2086 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2087 u132_endp_queue_work(u132, endp, 0);
2088 return 0;
2089}
2090
2091static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2092 struct usb_host_endpoint *hep, struct urb *urb,
2093 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2094 u8 usb_endp, u8 address)
2095{
2096 urb->hcpriv = u132;
2097 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2098 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2099 } else {
2100 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
2101 GFP_ATOMIC);
2102 if (urbq == NULL) {
2103 endp->queue_size -= 1;
2104 return -ENOMEM;
2105 } else {
2106 list_add_tail(&urbq->urb_more, &endp->urb_more);
2107 urbq->urb = urb;
2108 }
2109 }
2110 return 0;
2111}
2112
2113static int create_endpoint_and_queue_control(struct u132 *u132,
2114 struct usb_host_endpoint *hep, struct urb *urb,
2115 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp,
2116 gfp_t mem_flags)
2117{
2118 struct u132_ring *ring;
2119 u8 endp_number = ++u132->num_endpoints;
2120 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
2121 kmalloc(sizeof(struct u132_endp), mem_flags);
2122 if (!endp) {
2123 return -ENOMEM;
2124 }
2125 INIT_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler, (void *)endp);
2126 spin_lock_init(&endp->queue_lock.slock);
2127 INIT_LIST_HEAD(&endp->urb_more);
2128 ring = endp->ring = &u132->ring[0];
2129 if (ring->curr_endp) {
2130 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2131 } else {
2132 INIT_LIST_HEAD(&endp->endp_ring);
2133 ring->curr_endp = endp;
2134 }
2135 ring->length += 1;
2136 endp->dequeueing = 0;
2137 endp->edset_flush = 0;
2138 endp->active = 0;
2139 endp->delayed = 0;
2140 endp->endp_number = endp_number;
2141 endp->u132 = u132;
2142 endp->hep = hep;
2143 u132_endp_init_kref(u132, endp);
2144 u132_endp_get_kref(u132, endp);
2145 if (usb_addr == 0) {
2146 unsigned long irqs;
2147 u8 address = u132->addr[usb_addr].address;
2148 struct u132_udev *udev = &u132->udev[address];
2149 endp->udev_number = address;
2150 endp->usb_addr = usb_addr;
2151 endp->usb_endp = usb_endp;
2152 endp->input = 1;
2153 endp->output = 1;
2154 endp->pipetype = usb_pipetype(urb->pipe);
2155 u132_udev_init_kref(u132, udev);
2156 u132_udev_get_kref(u132, udev);
2157 udev->endp_number_in[usb_endp] = endp_number;
2158 udev->endp_number_out[usb_endp] = endp_number;
2159 urb->hcpriv = u132;
2160 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2161 endp->queue_size = 1;
2162 endp->queue_last = 0;
2163 endp->queue_next = 0;
2164 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2165 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2166 u132_endp_queue_work(u132, endp, 0);
2167 return 0;
2168 } else { /*(usb_addr > 0) */
2169 unsigned long irqs;
2170 u8 address = u132->addr[usb_addr].address;
2171 struct u132_udev *udev = &u132->udev[address];
2172 endp->udev_number = address;
2173 endp->usb_addr = usb_addr;
2174 endp->usb_endp = usb_endp;
2175 endp->input = 1;
2176 endp->output = 1;
2177 endp->pipetype = usb_pipetype(urb->pipe);
2178 u132_udev_get_kref(u132, udev);
2179 udev->enumeration = 2;
2180 udev->endp_number_in[usb_endp] = endp_number;
2181 udev->endp_number_out[usb_endp] = endp_number;
2182 urb->hcpriv = u132;
2183 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2184 endp->queue_size = 1;
2185 endp->queue_last = 0;
2186 endp->queue_next = 0;
2187 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2188 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2189 u132_endp_queue_work(u132, endp, 0);
2190 return 0;
2191 }
2192}
2193
2194static int queue_control_on_old_endpoint(struct u132 *u132,
2195 struct usb_host_endpoint *hep, struct urb *urb,
2196 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2197 u8 usb_endp)
2198{
2199 if (usb_addr == 0) {
2200 if (usb_pipein(urb->pipe)) {
2201 urb->hcpriv = u132;
2202 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2203 endp->urb_list[ENDP_QUEUE_MASK &
2204 endp->queue_last++] = urb;
2205 } else {
2206 struct u132_urbq *urbq =
2207 kmalloc(sizeof(struct u132_urbq),
2208 GFP_ATOMIC);
2209 if (urbq == NULL) {
2210 endp->queue_size -= 1;
2211 return -ENOMEM;
2212 } else {
2213 list_add_tail(&urbq->urb_more,
2214 &endp->urb_more);
2215 urbq->urb = urb;
2216 }
2217 }
2218 return 0;
2219 } else { /* usb_pipeout(urb->pipe) */
2220 struct u132_addr *addr = &u132->addr[usb_dev->devnum];
2221 int I = MAX_U132_UDEVS;
2222 int i = 0;
2223 while (--I > 0) {
2224 struct u132_udev *udev = &u132->udev[++i];
2225 if (udev->usb_device) {
2226 continue;
2227 } else {
2228 udev->enumeration = 1;
2229 u132->addr[0].address = i;
2230 endp->udev_number = i;
2231 udev->udev_number = i;
2232 udev->usb_addr = usb_dev->devnum;
2233 u132_udev_init_kref(u132, udev);
2234 udev->endp_number_in[usb_endp] =
2235 endp->endp_number;
2236 u132_udev_get_kref(u132, udev);
2237 udev->endp_number_out[usb_endp] =
2238 endp->endp_number;
2239 udev->usb_device = usb_dev;
2240 ((u8 *) (urb->setup_packet))[2] =
2241 addr->address = i;
2242 u132_udev_get_kref(u132, udev);
2243 break;
2244 }
2245 }
2246 if (I == 0) {
2247 dev_err(&u132->platform_dev->dev, "run out of d"
2248 "evice space\n");
2249 return -EINVAL;
2250 }
2251 urb->hcpriv = u132;
2252 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2253 endp->urb_list[ENDP_QUEUE_MASK &
2254 endp->queue_last++] = urb;
2255 } else {
2256 struct u132_urbq *urbq =
2257 kmalloc(sizeof(struct u132_urbq),
2258 GFP_ATOMIC);
2259 if (urbq == NULL) {
2260 endp->queue_size -= 1;
2261 return -ENOMEM;
2262 } else {
2263 list_add_tail(&urbq->urb_more,
2264 &endp->urb_more);
2265 urbq->urb = urb;
2266 }
2267 }
2268 return 0;
2269 }
2270 } else { /*(usb_addr > 0) */
2271 u8 address = u132->addr[usb_addr].address;
2272 struct u132_udev *udev = &u132->udev[address];
2273 urb->hcpriv = u132;
2274 if (udev->enumeration == 2) {
2275 } else
2276 udev->enumeration = 2;
2277 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2278 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
2279 urb;
2280 } else {
2281 struct u132_urbq *urbq =
2282 kmalloc(sizeof(struct u132_urbq), GFP_ATOMIC);
2283 if (urbq == NULL) {
2284 endp->queue_size -= 1;
2285 return -ENOMEM;
2286 } else {
2287 list_add_tail(&urbq->urb_more, &endp->urb_more);
2288 urbq->urb = urb;
2289 }
2290 }
2291 return 0;
2292 }
2293}
2294
2295static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2296 struct urb *urb, gfp_t mem_flags)
2297{
2298 struct u132 *u132 = hcd_to_u132(hcd);
2299 if (irqs_disabled()) {
2300 if (__GFP_WAIT & mem_flags) {
2301 printk(KERN_ERR "invalid context for function that migh"
2302 "t sleep\n");
2303 return -EINVAL;
2304 }
2305 }
2306 if (u132->going > 1) {
2307 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2308 , u132->going);
2309 return -ENODEV;
2310 } else if (u132->going > 0) {
2311 dev_err(&u132->platform_dev->dev, "device is being removed urb="
2312 "%p status=%d\n", urb, urb->status);
2313 return -ESHUTDOWN;
2314 } else {
2315 u8 usb_addr = usb_pipedevice(urb->pipe);
2316 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2317 struct usb_device *usb_dev = urb->dev;
2318 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
2319 u8 address = u132->addr[usb_addr].address;
2320 struct u132_udev *udev = &u132->udev[address];
2321 struct u132_endp *endp = hep->hcpriv;
2322 urb->actual_length = 0;
2323 if (endp) {
2324 unsigned long irqs;
2325 int retval;
2326 spin_lock_irqsave(&endp->queue_lock.slock,
2327 irqs);
2328 retval = queue_int_on_old_endpoint(u132, udev,
2329 hep, urb, usb_dev, endp, usb_addr,
2330 usb_endp, address);
2331 spin_unlock_irqrestore(&endp->queue_lock.slock,
2332 irqs);
2333 if (retval) {
2334 return retval;
2335 } else {
2336 u132_endp_queue_work(u132, endp,
2337 msecs_to_jiffies(urb->interval))
2338 ;
2339 return 0;
2340 }
2341 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2342 return -EINVAL;
2343 } else { /*(endp == NULL) */
2344 return create_endpoint_and_queue_int(u132, udev,
2345 hep, urb, usb_dev, usb_addr, usb_endp,
2346 address, mem_flags);
2347 }
2348 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
2349 dev_err(&u132->platform_dev->dev, "the hardware does no"
2350 "t support PIPE_ISOCHRONOUS\n");
2351 return -EINVAL;
2352 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) {
2353 u8 address = u132->addr[usb_addr].address;
2354 struct u132_udev *udev = &u132->udev[address];
2355 struct u132_endp *endp = hep->hcpriv;
2356 urb->actual_length = 0;
2357 if (endp) {
2358 unsigned long irqs;
2359 int retval;
2360 spin_lock_irqsave(&endp->queue_lock.slock,
2361 irqs);
2362 retval = queue_bulk_on_old_endpoint(u132, udev,
2363 hep, urb, usb_dev, endp, usb_addr,
2364 usb_endp, address);
2365 spin_unlock_irqrestore(&endp->queue_lock.slock,
2366 irqs);
2367 if (retval) {
2368 return retval;
2369 } else {
2370 u132_endp_queue_work(u132, endp, 0);
2371 return 0;
2372 }
2373 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2374 return -EINVAL;
2375 } else
2376 return create_endpoint_and_queue_bulk(u132,
2377 udev, hep, urb, usb_dev, usb_addr,
2378 usb_endp, address, mem_flags);
2379 } else {
2380 struct u132_endp *endp = hep->hcpriv;
2381 u16 urb_size = 8;
2382 u8 *b = urb->setup_packet;
2383 int i = 0;
2384 char data[30 *3 + 4];
2385 char *d = data;
2386 int m = (sizeof(data) - 1) / 3;
2387 int l = 0;
2388 data[0] = 0;
2389 while (urb_size-- > 0) {
2390 if (i > m) {
2391 } else if (i++ < m) {
2392 int w = sprintf(d, " %02X", *b++);
2393 d += w;
2394 l += w;
2395 } else
2396 d += sprintf(d, " ..");
2397 }
2398 if (endp) {
2399 unsigned long irqs;
2400 int retval;
2401 spin_lock_irqsave(&endp->queue_lock.slock,
2402 irqs);
2403 retval = queue_control_on_old_endpoint(u132,
2404 hep, urb, usb_dev, endp, usb_addr,
2405 usb_endp);
2406 spin_unlock_irqrestore(&endp->queue_lock.slock,
2407 irqs);
2408 if (retval) {
2409 return retval;
2410 } else {
2411 u132_endp_queue_work(u132, endp, 0);
2412 return 0;
2413 }
2414 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2415 return -EINVAL;
2416 } else
2417 return create_endpoint_and_queue_control(u132,
2418 hep, urb, usb_dev, usb_addr, usb_endp,
2419 mem_flags);
2420 }
2421 }
2422}
2423
2424static int dequeue_from_overflow_chain(struct u132 *u132,
2425 struct u132_endp *endp, struct urb *urb)
2426{
2427 struct list_head *scan;
2428 struct list_head *head = &endp->urb_more;
2429 list_for_each(scan, head) {
2430 struct u132_urbq *urbq = list_entry(scan, struct u132_urbq,
2431 urb_more);
2432 if (urbq->urb == urb) {
2433 struct usb_hcd *hcd = u132_to_hcd(u132);
2434 list_del(scan);
2435 endp->queue_size -= 1;
2436 urb->error_count = 0;
2437 urb->hcpriv = NULL;
2438 usb_hcd_giveback_urb(hcd, urb, NULL);
2439 return 0;
2440 } else
2441 continue;
2442 }
2443 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]=%p ring"
2444 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X"
2445 "\n", urb, endp->endp_number, endp, endp->ring->number,
2446 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2447 endp->usb_endp, endp->usb_addr, endp->queue_size,
2448 endp->queue_next, endp->queue_last);
2449 return -EINVAL;
2450}
2451
2452static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2453 struct urb *urb)
2454{
2455 unsigned long irqs;
2456 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2457 if (endp->queue_size == 0) {
2458 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]"
2459 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb,
2460 endp->endp_number, endp, endp->ring->number,
2461 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2462 endp->usb_endp, endp->usb_addr);
2463 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2464 return -EINVAL;
2465 }
2466 if (urb == endp->urb_list[ENDP_QUEUE_MASK & endp->queue_next]) {
2467 if (endp->active) {
2468 endp->dequeueing = 1;
2469 endp->edset_flush = 1;
2470 u132_endp_queue_work(u132, endp, 0);
2471 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2472 urb->hcpriv = NULL;
2473 return 0;
2474 } else {
2475 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2476 u132_hcd_abandon_urb(u132, endp, urb, urb->status);
2477 return 0;
2478 }
2479 } else {
2480 u16 queue_list = 0;
2481 u16 queue_size = endp->queue_size;
2482 u16 queue_scan = endp->queue_next;
2483 struct urb **urb_slot = NULL;
2484 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2485 if (urb == endp->urb_list[ENDP_QUEUE_MASK &
2486 ++queue_scan]) {
2487 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2488 queue_scan];
2489 break;
2490 } else
2491 continue;
2492 }
2493 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2494 *urb_slot = endp->urb_list[ENDP_QUEUE_MASK &
2495 ++queue_scan];
2496 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2497 queue_scan];
2498 }
2499 if (urb_slot) {
2500 struct usb_hcd *hcd = u132_to_hcd(u132);
2501 endp->queue_size -= 1;
2502 if (list_empty(&endp->urb_more)) {
2503 spin_unlock_irqrestore(&endp->queue_lock.slock,
2504 irqs);
2505 } else {
2506 struct list_head *next = endp->urb_more.next;
2507 struct u132_urbq *urbq = list_entry(next,
2508 struct u132_urbq, urb_more);
2509 list_del(next);
2510 *urb_slot = urbq->urb;
2511 spin_unlock_irqrestore(&endp->queue_lock.slock,
2512 irqs);
2513 kfree(urbq);
2514 } urb->error_count = 0;
2515 urb->hcpriv = NULL;
2516 usb_hcd_giveback_urb(hcd, urb, NULL);
2517 return 0;
2518 } else if (list_empty(&endp->urb_more)) {
2519 dev_err(&u132->platform_dev->dev, "urb=%p not found in "
2520 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr"
2521 "=%d size=%d next=%04X last=%04X\n", urb,
2522 endp->endp_number, endp, endp->ring->number,
2523 endp->input ? 'I' : ' ',
2524 endp->output ? 'O' : ' ', endp->usb_endp,
2525 endp->usb_addr, endp->queue_size,
2526 endp->queue_next, endp->queue_last);
2527 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2528 return -EINVAL;
2529 } else {
2530 int retval = dequeue_from_overflow_chain(u132, endp,
2531 urb);
2532 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2533 return retval;
2534 }
2535 }
2536}
2537
2538static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
2539{
2540 struct u132 *u132 = hcd_to_u132(hcd);
2541 if (u132->going > 2) {
2542 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2543 , u132->going);
2544 return -ENODEV;
2545 } else {
2546 u8 usb_addr = usb_pipedevice(urb->pipe);
2547 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2548 u8 address = u132->addr[usb_addr].address;
2549 struct u132_udev *udev = &u132->udev[address];
2550 if (usb_pipein(urb->pipe)) {
2551 u8 endp_number = udev->endp_number_in[usb_endp];
2552 struct u132_endp *endp = u132->endp[endp_number - 1];
2553 return u132_endp_urb_dequeue(u132, endp, urb);
2554 } else {
2555 u8 endp_number = udev->endp_number_out[usb_endp];
2556 struct u132_endp *endp = u132->endp[endp_number - 1];
2557 return u132_endp_urb_dequeue(u132, endp, urb);
2558 }
2559 }
2560}
2561
2562static void u132_endpoint_disable(struct usb_hcd *hcd,
2563 struct usb_host_endpoint *hep)
2564{
2565 struct u132 *u132 = hcd_to_u132(hcd);
2566 if (u132->going > 2) {
2567 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2568 , u132->going);
2569 } else {
2570 struct u132_endp *endp = hep->hcpriv;
2571 if (endp)
2572 u132_endp_put_kref(u132, endp);
2573 }
2574}
2575
2576static int u132_get_frame(struct usb_hcd *hcd)
2577{
2578 struct u132 *u132 = hcd_to_u132(hcd);
2579 if (u132->going > 1) {
2580 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2581 , u132->going);
2582 return -ENODEV;
2583 } else if (u132->going > 0) {
2584 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2585 return -ESHUTDOWN;
2586 } else {
2587 int frame = 0;
2588 dev_err(&u132->platform_dev->dev, "TODO: u132_get_frame\n");
2589 msleep(100);
2590 return frame;
2591 }
2592}
2593
2594static int u132_roothub_descriptor(struct u132 *u132,
2595 struct usb_hub_descriptor *desc)
2596{
2597 int retval;
2598 u16 temp;
2599 u32 rh_a = -1;
2600 u32 rh_b = -1;
2601 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
2602 if (retval)
2603 return retval;
2604 desc->bDescriptorType = 0x29;
2605 desc->bPwrOn2PwrGood = (rh_a & RH_A_POTPGT) >> 24;
2606 desc->bHubContrCurrent = 0;
2607 desc->bNbrPorts = u132->num_ports;
2608 temp = 1 + (u132->num_ports / 8);
2609 desc->bDescLength = 7 + 2 *temp;
2610 temp = 0;
2611 if (rh_a & RH_A_NPS)
2612 temp |= 0x0002;
2613 if (rh_a & RH_A_PSM)
2614 temp |= 0x0001;
2615 if (rh_a & RH_A_NOCP) {
2616 temp |= 0x0010;
2617 } else if (rh_a & RH_A_OCPM)
2618 temp |= 0x0008;
2619 desc->wHubCharacteristics = cpu_to_le16(temp);
2620 retval = u132_read_pcimem(u132, roothub.b, &rh_b);
2621 if (retval)
2622 return retval;
2623 memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
2624 desc->bitmap[0] = rh_b & RH_B_DR;
2625 if (u132->num_ports > 7) {
2626 desc->bitmap[1] = (rh_b & RH_B_DR) >> 8;
2627 desc->bitmap[2] = 0xff;
2628 } else
2629 desc->bitmap[1] = 0xff;
2630 return 0;
2631}
2632
2633static int u132_roothub_status(struct u132 *u132, __le32 *desc)
2634{
2635 u32 rh_status = -1;
2636 int ret_status = u132_read_pcimem(u132, roothub.status, &rh_status);
2637 *desc = cpu_to_le32(rh_status);
2638 return ret_status;
2639}
2640
2641static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex)
2642{
2643 if (wIndex == 0 || wIndex > u132->num_ports) {
2644 return -EINVAL;
2645 } else {
2646 int port = wIndex - 1;
2647 u32 rh_portstatus = -1;
2648 int ret_portstatus = u132_read_pcimem(u132,
2649 roothub.portstatus[port], &rh_portstatus);
2650 *desc = cpu_to_le32(rh_portstatus);
2651 if (*(u16 *) (desc + 2)) {
2652 dev_info(&u132->platform_dev->dev, "Port %d Status Chan"
2653 "ge = %08X\n", port, *desc);
2654 }
2655 return ret_portstatus;
2656 }
2657}
2658
2659
2660/* this timer value might be vendor-specific ... */
2661#define PORT_RESET_HW_MSEC 10
2662#define PORT_RESET_MSEC 10
2663/* wrap-aware logic morphed from <linux/jiffies.h> */
2664#define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
2665static int u132_roothub_portreset(struct u132 *u132, int port_index)
2666{
2667 int retval;
2668 u32 fmnumber;
2669 u16 now;
2670 u16 reset_done;
2671 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2672 if (retval)
2673 return retval;
2674 now = fmnumber;
2675 reset_done = now + PORT_RESET_MSEC;
2676 do {
2677 u32 portstat;
2678 do {
2679 retval = u132_read_pcimem(u132,
2680 roothub.portstatus[port_index], &portstat);
2681 if (retval)
2682 return retval;
2683 if (RH_PS_PRS & portstat) {
2684 continue;
2685 } else
2686 break;
2687 } while (tick_before(now, reset_done));
2688 if (RH_PS_PRS & portstat)
2689 return -ENODEV;
2690 if (RH_PS_CCS & portstat) {
2691 if (RH_PS_PRSC & portstat) {
2692 retval = u132_write_pcimem(u132,
2693 roothub.portstatus[port_index],
2694 RH_PS_PRSC);
2695 if (retval)
2696 return retval;
2697 }
2698 } else
2699 break; /* start the next reset,
2700 sleep till it's probably done */
2701 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2702 RH_PS_PRS);
2703 if (retval)
2704 return retval;
2705 msleep(PORT_RESET_HW_MSEC);
2706 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2707 if (retval)
2708 return retval;
2709 now = fmnumber;
2710 } while (tick_before(now, reset_done));
2711 return 0;
2712}
2713
2714static int u132_roothub_setportfeature(struct u132 *u132, u16 wValue,
2715 u16 wIndex)
2716{
2717 if (wIndex == 0 || wIndex > u132->num_ports) {
2718 return -EINVAL;
2719 } else {
2720 int retval;
2721 int port_index = wIndex - 1;
2722 struct u132_port *port = &u132->port[port_index];
2723 port->Status &= ~(1 << wValue);
2724 switch (wValue) {
2725 case USB_PORT_FEAT_SUSPEND:
2726 retval = u132_write_pcimem(u132,
2727 roothub.portstatus[port_index], RH_PS_PSS);
2728 if (retval)
2729 return retval;
2730 return 0;
2731 case USB_PORT_FEAT_POWER:
2732 retval = u132_write_pcimem(u132,
2733 roothub.portstatus[port_index], RH_PS_PPS);
2734 if (retval)
2735 return retval;
2736 return 0;
2737 case USB_PORT_FEAT_RESET:
2738 retval = u132_roothub_portreset(u132, port_index);
2739 if (retval)
2740 return retval;
2741 return 0;
2742 default:
2743 return -EPIPE;
2744 }
2745 }
2746}
2747
2748static int u132_roothub_clearportfeature(struct u132 *u132, u16 wValue,
2749 u16 wIndex)
2750{
2751 if (wIndex == 0 || wIndex > u132->num_ports) {
2752 return -EINVAL;
2753 } else {
2754 int port_index = wIndex - 1;
2755 u32 temp;
2756 int retval;
2757 struct u132_port *port = &u132->port[port_index];
2758 port->Status &= ~(1 << wValue);
2759 switch (wValue) {
2760 case USB_PORT_FEAT_ENABLE:
2761 temp = RH_PS_CCS;
2762 break;
2763 case USB_PORT_FEAT_C_ENABLE:
2764 temp = RH_PS_PESC;
2765 break;
2766 case USB_PORT_FEAT_SUSPEND:
2767 temp = RH_PS_POCI;
2768 if ((u132->hc_control & OHCI_CTRL_HCFS)
2769 != OHCI_USB_OPER) {
2770 dev_err(&u132->platform_dev->dev, "TODO resume_"
2771 "root_hub\n");
2772 }
2773 break;
2774 case USB_PORT_FEAT_C_SUSPEND:
2775 temp = RH_PS_PSSC;
2776 break;
2777 case USB_PORT_FEAT_POWER:
2778 temp = RH_PS_LSDA;
2779 break;
2780 case USB_PORT_FEAT_C_CONNECTION:
2781 temp = RH_PS_CSC;
2782 break;
2783 case USB_PORT_FEAT_C_OVER_CURRENT:
2784 temp = RH_PS_OCIC;
2785 break;
2786 case USB_PORT_FEAT_C_RESET:
2787 temp = RH_PS_PRSC;
2788 break;
2789 default:
2790 return -EPIPE;
2791 }
2792 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2793 temp);
2794 if (retval)
2795 return retval;
2796 return 0;
2797 }
2798}
2799
2800
2801/* the virtual root hub timer IRQ checks for hub status*/
2802static int u132_hub_status_data(struct usb_hcd *hcd, char *buf)
2803{
2804 struct u132 *u132 = hcd_to_u132(hcd);
2805 if (u132->going > 1) {
2806 dev_err(&u132->platform_dev->dev, "device hcd=%p has been remov"
2807 "ed %d\n", hcd, u132->going);
2808 return -ENODEV;
2809 } else if (u132->going > 0) {
2810 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
2811 "ed\n", hcd);
2812 dump_stack();
2813 return -ESHUTDOWN;
2814 } else {
2815 int i, changed = 0, length = 1;
2816 if (u132->flags & OHCI_QUIRK_AMD756) {
2817 if ((u132->hc_roothub_a & RH_A_NDP) > MAX_ROOT_PORTS) {
2818 dev_err(&u132->platform_dev->dev, "bogus NDP, r"
2819 "ereads as NDP=%d\n",
2820 u132->hc_roothub_a & RH_A_NDP);
2821 goto done;
2822 }
2823 }
2824 if (u132->hc_roothub_status & (RH_HS_LPSC | RH_HS_OCIC)) {
2825 buf[0] = changed = 1;
2826 } else
2827 buf[0] = 0;
2828 if (u132->num_ports > 7) {
2829 buf[1] = 0;
2830 length++;
2831 }
2832 for (i = 0; i < u132->num_ports; i++) {
2833 if (u132->hc_roothub_portstatus[i] & (RH_PS_CSC |
2834 RH_PS_PESC | RH_PS_PSSC | RH_PS_OCIC |
2835 RH_PS_PRSC)) {
2836 changed = 1;
2837 if (i < 7) {
2838 buf[0] |= 1 << (i + 1);
2839 } else
2840 buf[1] |= 1 << (i - 7);
2841 continue;
2842 }
2843 if (!(u132->hc_roothub_portstatus[i] & RH_PS_CCS)) {
2844 continue;
2845 }
2846 if ((u132->hc_roothub_portstatus[i] & RH_PS_PSS)) {
2847 continue;
2848 }
2849 }
2850 done:return changed ? length : 0;
2851 }
2852}
2853
2854static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2855 u16 wIndex, char *buf, u16 wLength)
2856{
2857 struct u132 *u132 = hcd_to_u132(hcd);
2858 if (u132->going > 1) {
2859 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2860 , u132->going);
2861 return -ENODEV;
2862 } else if (u132->going > 0) {
2863 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2864 return -ESHUTDOWN;
2865 } else {
2866 int retval = 0;
2867 down(&u132->sw_lock);
2868 switch (typeReq) {
2869 case ClearHubFeature:
2870 switch (wValue) {
2871 case C_HUB_OVER_CURRENT:
2872 case C_HUB_LOCAL_POWER:
2873 break;
2874 default:
2875 goto stall;
2876 }
2877 break;
2878 case SetHubFeature:
2879 switch (wValue) {
2880 case C_HUB_OVER_CURRENT:
2881 case C_HUB_LOCAL_POWER:
2882 break;
2883 default:
2884 goto stall;
2885 }
2886 break;
2887 case ClearPortFeature:{
2888 retval = u132_roothub_clearportfeature(u132,
2889 wValue, wIndex);
2890 if (retval)
2891 goto error;
2892 break;
2893 }
2894 case GetHubDescriptor:{
2895 retval = u132_roothub_descriptor(u132,
2896 (struct usb_hub_descriptor *)buf);
2897 if (retval)
2898 goto error;
2899 break;
2900 }
2901 case GetHubStatus:{
2902 retval = u132_roothub_status(u132,
2903 (__le32 *) buf);
2904 if (retval)
2905 goto error;
2906 break;
2907 }
2908 case GetPortStatus:{
2909 retval = u132_roothub_portstatus(u132,
2910 (__le32 *) buf, wIndex);
2911 if (retval)
2912 goto error;
2913 break;
2914 }
2915 case SetPortFeature:{
2916 retval = u132_roothub_setportfeature(u132,
2917 wValue, wIndex);
2918 if (retval)
2919 goto error;
2920 break;
2921 }
2922 default:
2923 goto stall;
2924 error:u132_disable(u132);
2925 u132->going = 1;
2926 break;
2927 stall:retval = -EPIPE;
2928 break;
2929 }
2930 up(&u132->sw_lock);
2931 return retval;
2932 }
2933}
2934
2935static int u132_start_port_reset(struct usb_hcd *hcd, unsigned port_num)
2936{
2937 struct u132 *u132 = hcd_to_u132(hcd);
2938 if (u132->going > 1) {
2939 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2940 , u132->going);
2941 return -ENODEV;
2942 } else if (u132->going > 0) {
2943 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2944 return -ESHUTDOWN;
2945 } else
2946 return 0;
2947}
2948
2949static void u132_hub_irq_enable(struct usb_hcd *hcd)
2950{
2951 struct u132 *u132 = hcd_to_u132(hcd);
2952 if (u132->going > 1) {
2953 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2954 , u132->going);
2955 } else if (u132->going > 0)
2956 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2957}
2958
2959
2960#ifdef CONFIG_PM
2961static int u132_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
2962{
2963 struct u132 *u132 = hcd_to_u132(hcd);
2964 if (u132->going > 1) {
2965 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2966 , u132->going);
2967 return -ENODEV;
2968 } else if (u132->going > 0) {
2969 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2970 return -ESHUTDOWN;
2971 } else
2972 return 0;
2973}
2974
2975static int u132_hcd_resume(struct usb_hcd *hcd)
2976{
2977 struct u132 *u132 = hcd_to_u132(hcd);
2978 if (u132->going > 1) {
2979 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2980 , u132->going);
2981 return -ENODEV;
2982 } else if (u132->going > 0) {
2983 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2984 return -ESHUTDOWN;
2985 } else
2986 return 0;
2987}
2988
2989static int u132_bus_suspend(struct usb_hcd *hcd)
2990{
2991 struct u132 *u132 = hcd_to_u132(hcd);
2992 if (u132->going > 1) {
2993 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2994 , u132->going);
2995 return -ENODEV;
2996 } else if (u132->going > 0) {
2997 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2998 return -ESHUTDOWN;
2999 } else
3000 return 0;
3001}
3002
3003static int u132_bus_resume(struct usb_hcd *hcd)
3004{
3005 struct u132 *u132 = hcd_to_u132(hcd);
3006 if (u132->going > 1) {
3007 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3008 , u132->going);
3009 return -ENODEV;
3010 } else if (u132->going > 0) {
3011 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3012 return -ESHUTDOWN;
3013 } else
3014 return 0;
3015}
3016
3017#else
3018#define u132_hcd_suspend NULL
3019#define u132_hcd_resume NULL
3020#define u132_bus_suspend NULL
3021#define u132_bus_resume NULL
3022#endif
3023static struct hc_driver u132_hc_driver = {
3024 .description = hcd_name,
3025 .hcd_priv_size = sizeof(struct u132),
3026 .irq = NULL,
3027 .flags = HCD_USB11 | HCD_MEMORY,
3028 .reset = u132_hcd_reset,
3029 .start = u132_hcd_start,
3030 .suspend = u132_hcd_suspend,
3031 .resume = u132_hcd_resume,
3032 .stop = u132_hcd_stop,
3033 .urb_enqueue = u132_urb_enqueue,
3034 .urb_dequeue = u132_urb_dequeue,
3035 .endpoint_disable = u132_endpoint_disable,
3036 .get_frame_number = u132_get_frame,
3037 .hub_status_data = u132_hub_status_data,
3038 .hub_control = u132_hub_control,
3039 .bus_suspend = u132_bus_suspend,
3040 .bus_resume = u132_bus_resume,
3041 .start_port_reset = u132_start_port_reset,
3042 .hub_irq_enable = u132_hub_irq_enable,
3043};
3044
3045/*
3046* This function may be called by the USB core whilst the "usb_all_devices_rwsem"
3047* is held for writing, thus this module must not call usb_remove_hcd()
3048* synchronously - but instead should immediately stop activity to the
3049* device and ansynchronously call usb_remove_hcd()
3050*/
3051static int __devexit u132_remove(struct platform_device *pdev)
3052{
3053 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3054 if (hcd) {
3055 struct u132 *u132 = hcd_to_u132(hcd);
3056 dump_stack();
3057 if (u132->going++ > 1) {
3058 return -ENODEV;
3059 } else {
3060 int rings = MAX_U132_RINGS;
3061 int endps = MAX_U132_ENDPS;
3062 msleep(100);
3063 down(&u132->sw_lock);
3064 u132_monitor_cancel_work(u132);
3065 while (rings-- > 0) {
3066 struct u132_ring *ring = &u132->ring[rings];
3067 u132_ring_cancel_work(u132, ring);
3068 } while (endps-- > 0) {
3069 struct u132_endp *endp = u132->endp[endps];
3070 if (endp)
3071 u132_endp_cancel_work(u132, endp);
3072 }
3073 u132->going += 1;
3074 printk(KERN_INFO "removing device u132.%d\n",
3075 u132->sequence_num);
3076 up(&u132->sw_lock);
3077 usb_remove_hcd(hcd);
3078 u132_u132_put_kref(u132);
3079 return 0;
3080 }
3081 } else
3082 return 0;
3083}
3084
3085static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3086{
3087 int rings = MAX_U132_RINGS;
3088 int ports = MAX_U132_PORTS;
3089 int addrs = MAX_U132_ADDRS;
3090 int udevs = MAX_U132_UDEVS;
3091 int endps = MAX_U132_ENDPS;
3092 u132->board = pdev->dev.platform_data;
3093 u132->platform_dev = pdev;
3094 u132->power = 0;
3095 u132->reset = 0;
3096 init_MUTEX(&u132->sw_lock);
3097 init_MUTEX(&u132->scheduler_lock);
3098 while (rings-- > 0) {
3099 struct u132_ring *ring = &u132->ring[rings];
3100 ring->u132 = u132;
3101 ring->number = rings + 1;
3102 ring->length = 0;
3103 ring->curr_endp = NULL;
3104 INIT_WORK(&ring->scheduler, u132_hcd_ring_work_scheduler,
3105 (void *)ring);
3106 } down(&u132->sw_lock);
3107 INIT_WORK(&u132->monitor, u132_hcd_monitor_work, (void *)u132);
3108 while (ports-- > 0) {
3109 struct u132_port *port = &u132->port[ports];
3110 port->u132 = u132;
3111 port->reset = 0;
3112 port->enable = 0;
3113 port->power = 0;
3114 port->Status = 0;
3115 } while (addrs-- > 0) {
3116 struct u132_addr *addr = &u132->addr[addrs];
3117 addr->address = 0;
3118 } while (udevs-- > 0) {
3119 struct u132_udev *udev = &u132->udev[udevs];
3120 int i = ARRAY_SIZE(udev->endp_number_in);
3121 int o = ARRAY_SIZE(udev->endp_number_out);
3122 udev->usb_device = NULL;
3123 udev->udev_number = 0;
3124 udev->usb_addr = 0;
3125 udev->portnumber = 0;
3126 while (i-- > 0) {
3127 udev->endp_number_in[i] = 0;
3128 }
3129 while (o-- > 0) {
3130 udev->endp_number_out[o] = 0;
3131 }
3132 }
3133 while (endps-- > 0) {
3134 u132->endp[endps] = NULL;
3135 }
3136 up(&u132->sw_lock);
3137 return;
3138}
3139
3140static int __devinit u132_probe(struct platform_device *pdev)
3141{
3142 struct usb_hcd *hcd;
3143 msleep(100);
3144 if (u132_exiting > 0) {
3145 return -ENODEV;
3146 } /* refuse to confuse usbcore */
3147 if (pdev->dev.dma_mask) {
3148 return -EINVAL;
3149 }
3150 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, pdev->dev.bus_id);
3151 if (!hcd) {
3152 printk(KERN_ERR "failed to create the usb hcd struct for U132\n"
3153 );
3154 ftdi_elan_gone_away(pdev);
3155 return -ENOMEM;
3156 } else {
3157 int retval = 0;
3158 struct u132 *u132 = hcd_to_u132(hcd);
3159 hcd->rsrc_start = 0;
3160 down(&u132_module_lock);
3161 list_add_tail(&u132->u132_list, &u132_static_list);
3162 u132->sequence_num = ++u132_instances;
3163 up(&u132_module_lock);
3164 u132_u132_init_kref(u132);
3165 u132_initialise(u132, pdev);
3166 hcd->product_desc = "ELAN U132 Host Controller";
3167 retval = usb_add_hcd(hcd, 0, 0);
3168 if (retval != 0) {
3169 dev_err(&u132->platform_dev->dev, "init error %d\n",
3170 retval);
3171 u132_u132_put_kref(u132);
3172 return retval;
3173 } else {
3174 u132_monitor_queue_work(u132, 100);
3175 return 0;
3176 }
3177 }
3178}
3179
3180
3181#ifdef CONFIG_PM
3182/* for this device there's no useful distinction between the controller
3183* and its root hub, except that the root hub only gets direct PM calls
3184* when CONFIG_USB_SUSPEND is enabled.
3185*/
3186static int u132_suspend(struct platform_device *pdev, pm_message_t state)
3187{
3188 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3189 struct u132 *u132 = hcd_to_u132(hcd);
3190 if (u132->going > 1) {
3191 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3192 , u132->going);
3193 return -ENODEV;
3194 } else if (u132->going > 0) {
3195 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3196 return -ESHUTDOWN;
3197 } else {
3198 int retval = 0;
3199 if (state.event == PM_EVENT_FREEZE) {
3200 retval = u132_bus_suspend(hcd);
3201 } else if (state.event == PM_EVENT_SUSPEND) {
3202 int ports = MAX_U132_PORTS;
3203 while (ports-- > 0) {
3204 port_power(u132, ports, 0);
3205 }
3206 }
3207 if (retval == 0)
3208 pdev->dev.power.power_state = state;
3209 return retval;
3210 }
3211}
3212
3213static int u132_resume(struct platform_device *pdev)
3214{
3215 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3216 struct u132 *u132 = hcd_to_u132(hcd);
3217 if (u132->going > 1) {
3218 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3219 , u132->going);
3220 return -ENODEV;
3221 } else if (u132->going > 0) {
3222 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3223 return -ESHUTDOWN;
3224 } else {
3225 int retval = 0;
3226 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
3227 int ports = MAX_U132_PORTS;
3228 while (ports-- > 0) {
3229 port_power(u132, ports, 1);
3230 }
3231 retval = 0;
3232 } else {
3233 pdev->dev.power.power_state = PMSG_ON;
3234 retval = u132_bus_resume(hcd);
3235 }
3236 return retval;
3237 }
3238}
3239
3240#else
3241#define u132_suspend NULL
3242#define u132_resume NULL
3243#endif
3244/*
3245* this driver is loaded explicitely by ftdi_u132
3246*
3247* the platform_driver struct is static because it is per type of module
3248*/
3249static struct platform_driver u132_platform_driver = {
3250 .probe = u132_probe,
3251 .remove = __devexit_p(u132_remove),
3252 .suspend = u132_suspend,
3253 .resume = u132_resume,
3254 .driver = {
3255 .name = (char *)hcd_name,
3256 .owner = THIS_MODULE,
3257 },
3258};
3259static int __init u132_hcd_init(void)
3260{
3261 int retval;
3262 INIT_LIST_HEAD(&u132_static_list);
3263 u132_instances = 0;
3264 u132_exiting = 0;
3265 init_MUTEX(&u132_module_lock);
3266 if (usb_disabled())
3267 return -ENODEV;
3268 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__,
3269 __DATE__);
3270 workqueue = create_singlethread_workqueue("u132");
3271 retval = platform_driver_register(&u132_platform_driver);
3272 return retval;
3273}
3274
3275
3276module_init(u132_hcd_init);
3277static void __exit u132_hcd_exit(void)
3278{
3279 struct u132 *u132;
3280 struct u132 *temp;
3281 down(&u132_module_lock);
3282 u132_exiting += 1;
3283 up(&u132_module_lock);
3284 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) {
3285 platform_device_unregister(u132->platform_dev);
3286 } platform_driver_unregister(&u132_platform_driver);
3287 printk(KERN_INFO "u132-hcd driver deregistered\n");
3288 wait_event(u132_hcd_wait, u132_instances == 0);
3289 flush_workqueue(workqueue);
3290 destroy_workqueue(workqueue);
3291}
3292
3293
3294module_exit(u132_hcd_exit);
3295MODULE_LICENSE("GPL");
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c
index dc286a48cafd..e345f15b7d87 100644
--- a/drivers/usb/host/uhci-debug.c
+++ b/drivers/usb/host/uhci-debug.c
@@ -16,7 +16,7 @@
16 16
17#include "uhci-hcd.h" 17#include "uhci-hcd.h"
18 18
19#define uhci_debug_operations (* (struct file_operations *) NULL) 19#define uhci_debug_operations (* (const struct file_operations *) NULL)
20static struct dentry *uhci_debugfs_root; 20static struct dentry *uhci_debugfs_root;
21 21
22#ifdef DEBUG 22#ifdef DEBUG
@@ -428,7 +428,7 @@ struct uhci_debug {
428 428
429static int uhci_debug_open(struct inode *inode, struct file *file) 429static int uhci_debug_open(struct inode *inode, struct file *file)
430{ 430{
431 struct uhci_hcd *uhci = inode->u.generic_ip; 431 struct uhci_hcd *uhci = inode->i_private;
432 struct uhci_debug *up; 432 struct uhci_debug *up;
433 int ret = -ENOMEM; 433 int ret = -ENOMEM;
434 unsigned long flags; 434 unsigned long flags;
@@ -500,7 +500,7 @@ static int uhci_debug_release(struct inode *inode, struct file *file)
500} 500}
501 501
502#undef uhci_debug_operations 502#undef uhci_debug_operations
503static struct file_operations uhci_debug_operations = { 503static const struct file_operations uhci_debug_operations = {
504 .owner = THIS_MODULE, 504 .owner = THIS_MODULE,
505 .open = uhci_debug_open, 505 .open = uhci_debug_open,
506 .llseek = uhci_debug_lseek, 506 .llseek = uhci_debug_lseek,
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index 4151f618602d..eb4eab98e8bf 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -734,6 +734,10 @@ static int uhci_suspend(struct usb_hcd *hcd, pm_message_t message)
734 734
735 /* FIXME: Enable non-PME# remote wakeup? */ 735 /* FIXME: Enable non-PME# remote wakeup? */
736 736
737 /* make sure snapshot being resumed re-enumerates everything */
738 if (message.event == PM_EVENT_PRETHAW)
739 uhci_hc_died(uhci);
740
737done_okay: 741done_okay:
738 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 742 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
739done: 743done:
@@ -909,8 +913,7 @@ static int __init uhci_hcd_init(void)
909 return 0; 913 return 0;
910 914
911init_failed: 915init_failed:
912 if (kmem_cache_destroy(uhci_up_cachep)) 916 kmem_cache_destroy(uhci_up_cachep);
913 warn("not all urb_privs were freed!");
914 917
915up_failed: 918up_failed:
916 debugfs_remove(uhci_debugfs_root); 919 debugfs_remove(uhci_debugfs_root);
@@ -926,10 +929,7 @@ errbuf_failed:
926static void __exit uhci_hcd_cleanup(void) 929static void __exit uhci_hcd_cleanup(void)
927{ 930{
928 pci_unregister_driver(&uhci_pci_driver); 931 pci_unregister_driver(&uhci_pci_driver);
929 932 kmem_cache_destroy(uhci_up_cachep);
930 if (kmem_cache_destroy(uhci_up_cachep))
931 warn("not all urb_privs were freed!");
932
933 debugfs_remove(uhci_debugfs_root); 933 debugfs_remove(uhci_debugfs_root);
934 kfree(errbuf); 934 kfree(errbuf);
935} 935}
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c
index c545ef92fe29..16fb72eb6fc9 100644
--- a/drivers/usb/host/uhci-hub.c
+++ b/drivers/usb/host/uhci-hub.c
@@ -84,6 +84,7 @@ static void uhci_finish_suspend(struct uhci_hcd *uhci, int port,
84 unsigned long port_addr) 84 unsigned long port_addr)
85{ 85{
86 int status; 86 int status;
87 int i;
87 88
88 if (inw(port_addr) & (USBPORTSC_SUSP | USBPORTSC_RD)) { 89 if (inw(port_addr) & (USBPORTSC_SUSP | USBPORTSC_RD)) {
89 CLR_RH_PORTSTAT(USBPORTSC_SUSP | USBPORTSC_RD); 90 CLR_RH_PORTSTAT(USBPORTSC_SUSP | USBPORTSC_RD);
@@ -92,9 +93,14 @@ static void uhci_finish_suspend(struct uhci_hcd *uhci, int port,
92 93
93 /* The controller won't actually turn off the RD bit until 94 /* The controller won't actually turn off the RD bit until
94 * it has had a chance to send a low-speed EOP sequence, 95 * it has had a chance to send a low-speed EOP sequence,
95 * which takes 3 bit times (= 2 microseconds). We'll delay 96 * which is supposed to take 3 bit times (= 2 microseconds).
96 * slightly longer for good luck. */ 97 * Experiments show that some controllers take longer, so
97 udelay(4); 98 * we'll poll for completion. */
99 for (i = 0; i < 10; ++i) {
100 if (!(inw(port_addr) & USBPORTSC_RD))
101 break;
102 udelay(1);
103 }
98 } 104 }
99 clear_bit(port, &uhci->resuming_ports); 105 clear_bit(port, &uhci->resuming_ports);
100} 106}
diff --git a/drivers/usb/image/mdc800.c b/drivers/usb/image/mdc800.c
index 08daf400f985..ca6305c1d64c 100644
--- a/drivers/usb/image/mdc800.c
+++ b/drivers/usb/image/mdc800.c
@@ -424,7 +424,7 @@ static void mdc800_usb_download_notify (struct urb *urb, struct pt_regs *res)
424 ***************************************************************************/ 424 ***************************************************************************/
425 425
426static struct usb_driver mdc800_usb_driver; 426static struct usb_driver mdc800_usb_driver;
427static struct file_operations mdc800_device_ops; 427static const struct file_operations mdc800_device_ops;
428static struct usb_class_driver mdc800_class = { 428static struct usb_class_driver mdc800_class = {
429 .name = "mdc800%d", 429 .name = "mdc800%d",
430 .fops = &mdc800_device_ops, 430 .fops = &mdc800_device_ops,
@@ -941,7 +941,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
941****************************************************************************/ 941****************************************************************************/
942 942
943/* File Operations of this drivers */ 943/* File Operations of this drivers */
944static struct file_operations mdc800_device_ops = 944static const struct file_operations mdc800_device_ops =
945{ 945{
946 .owner = THIS_MODULE, 946 .owner = THIS_MODULE,
947 .read = mdc800_device_read, 947 .read = mdc800_device_read,
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index b2bafc37c414..5f861331932a 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -225,7 +225,7 @@ static inline void mts_debug_dump(struct mts_desc* desc) {
225} 225}
226 226
227 227
228static inline void mts_show_command(Scsi_Cmnd *srb) 228static inline void mts_show_command(struct scsi_cmnd *srb)
229{ 229{
230 char *what = NULL; 230 char *what = NULL;
231 231
@@ -309,7 +309,7 @@ static inline void mts_show_command(Scsi_Cmnd *srb)
309 309
310#else 310#else
311 311
312static inline void mts_show_command(Scsi_Cmnd * dummy) 312static inline void mts_show_command(struct scsi_cmnd * dummy)
313{ 313{
314} 314}
315 315
@@ -338,7 +338,7 @@ static int mts_slave_configure (struct scsi_device *s)
338 return 0; 338 return 0;
339} 339}
340 340
341static int mts_scsi_abort (Scsi_Cmnd *srb) 341static int mts_scsi_abort(struct scsi_cmnd *srb)
342{ 342{
343 struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]); 343 struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]);
344 344
@@ -349,7 +349,7 @@ static int mts_scsi_abort (Scsi_Cmnd *srb)
349 return FAILED; 349 return FAILED;
350} 350}
351 351
352static int mts_scsi_host_reset (Scsi_Cmnd *srb) 352static int mts_scsi_host_reset(struct scsi_cmnd *srb)
353{ 353{
354 struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]); 354 struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]);
355 int result, rc; 355 int result, rc;
@@ -366,8 +366,8 @@ static int mts_scsi_host_reset (Scsi_Cmnd *srb)
366 return result ? FAILED : SUCCESS; 366 return result ? FAILED : SUCCESS;
367} 367}
368 368
369static 369static int
370int mts_scsi_queuecommand (Scsi_Cmnd *srb, mts_scsi_cmnd_callback callback ); 370mts_scsi_queuecommand(struct scsi_cmnd *srb, mts_scsi_cmnd_callback callback);
371 371
372static void mts_transfer_cleanup( struct urb *transfer ); 372static void mts_transfer_cleanup( struct urb *transfer );
373static void mts_do_sg(struct urb * transfer, struct pt_regs *regs); 373static void mts_do_sg(struct urb * transfer, struct pt_regs *regs);
@@ -537,7 +537,7 @@ static const unsigned char mts_direction[256/8] = {
537#define MTS_DIRECTION_IS_IN(x) ((mts_direction[x>>3] >> (x & 7)) & 1) 537#define MTS_DIRECTION_IS_IN(x) ((mts_direction[x>>3] >> (x & 7)) & 1)
538 538
539static void 539static void
540mts_build_transfer_context( Scsi_Cmnd *srb, struct mts_desc* desc ) 540mts_build_transfer_context(struct scsi_cmnd *srb, struct mts_desc* desc)
541{ 541{
542 int pipe; 542 int pipe;
543 struct scatterlist * sg; 543 struct scatterlist * sg;
@@ -588,8 +588,8 @@ mts_build_transfer_context( Scsi_Cmnd *srb, struct mts_desc* desc )
588} 588}
589 589
590 590
591static 591static int
592int mts_scsi_queuecommand( Scsi_Cmnd *srb, mts_scsi_cmnd_callback callback ) 592mts_scsi_queuecommand(struct scsi_cmnd *srb, mts_scsi_cmnd_callback callback)
593{ 593{
594 struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]); 594 struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]);
595 int err = 0; 595 int err = 0;
diff --git a/drivers/usb/image/microtek.h b/drivers/usb/image/microtek.h
index 926d4bdc6746..d5d62a939058 100644
--- a/drivers/usb/image/microtek.h
+++ b/drivers/usb/image/microtek.h
@@ -8,14 +8,14 @@
8 * 8 *
9 */ 9 */
10 10
11typedef void (*mts_scsi_cmnd_callback)(Scsi_Cmnd *); 11typedef void (*mts_scsi_cmnd_callback)(struct scsi_cmnd *);
12 12
13 13
14struct mts_transfer_context 14struct mts_transfer_context
15{ 15{
16 struct mts_desc* instance; 16 struct mts_desc* instance;
17 mts_scsi_cmnd_callback final_callback; 17 mts_scsi_cmnd_callback final_callback;
18 Scsi_Cmnd *srb; 18 struct scsi_cmnd *srb;
19 19
20 void* data; 20 void* data;
21 unsigned data_length; 21 unsigned data_length;
diff --git a/drivers/usb/input/Kconfig b/drivers/usb/input/Kconfig
index 650103bc9618..21cd22640080 100644
--- a/drivers/usb/input/Kconfig
+++ b/drivers/usb/input/Kconfig
@@ -60,16 +60,17 @@ config HID_FF
60 If unsure, say N. 60 If unsure, say N.
61 61
62config HID_PID 62config HID_PID
63 bool "PID Devices (Microsoft Sidewinder Force Feedback 2)" 63 bool "PID device support"
64 depends on HID_FF 64 depends on HID_FF
65 help 65 help
66 Say Y here if you have a PID-compliant joystick and wish to enable force 66 Say Y here if you have a PID-compliant device and wish to enable force
67 feedback for it. The Microsoft Sidewinder Force Feedback 2 is one such 67 feedback for it. Microsoft Sidewinder Force Feedback 2 is one of such
68 device. 68 devices.
69 69
70config LOGITECH_FF 70config LOGITECH_FF
71 bool "Logitech WingMan *3D support" 71 bool "Logitech WingMan *3D support"
72 depends on HID_FF 72 depends on HID_FF
73 select INPUT_FF_MEMLESS if USB_HID
73 help 74 help
74 Say Y here if you have one of these devices: 75 Say Y here if you have one of these devices:
75 - Logitech WingMan Cordless RumblePad 76 - Logitech WingMan Cordless RumblePad
@@ -81,12 +82,21 @@ config LOGITECH_FF
81config THRUSTMASTER_FF 82config THRUSTMASTER_FF
82 bool "ThrustMaster FireStorm Dual Power 2 support (EXPERIMENTAL)" 83 bool "ThrustMaster FireStorm Dual Power 2 support (EXPERIMENTAL)"
83 depends on HID_FF && EXPERIMENTAL 84 depends on HID_FF && EXPERIMENTAL
85 select INPUT_FF_MEMLESS if USB_HID
84 help 86 help
85 Say Y here if you have a THRUSTMASTER FireStore Dual Power 2, 87 Say Y here if you have a THRUSTMASTER FireStore Dual Power 2,
86 and want to enable force feedback support for it. 88 and want to enable force feedback support for it.
87 Note: if you say N here, this device will still be supported, but without 89 Note: if you say N here, this device will still be supported, but without
88 force feedback. 90 force feedback.
89 91
92config ZEROPLUS_FF
93 bool "Zeroplus based game controller support"
94 depends on HID_FF
95 select INPUT_FF_MEMLESS if USB_HID
96 help
97 Say Y here if you have a Zeroplus based game controller and want to
98 enable force feedback for it.
99
90config USB_HIDDEV 100config USB_HIDDEV
91 bool "/dev/hiddev raw HID device support" 101 bool "/dev/hiddev raw HID device support"
92 depends on USB_HID 102 depends on USB_HID
@@ -205,10 +215,12 @@ config USB_TOUCHSCREEN
205 depends on USB && INPUT 215 depends on USB && INPUT
206 ---help--- 216 ---help---
207 USB Touchscreen driver for: 217 USB Touchscreen driver for:
208 - eGalax Touchkit USB 218 - eGalax Touchkit USB (also includes eTurboTouch CT-410/510/700)
209 - PanJit TouchSet USB 219 - PanJit TouchSet USB
210 - 3M MicroTouch USB 220 - 3M MicroTouch USB (EX II series)
211 - ITM 221 - ITM
222 - some other eTurboTouch
223 - Gunze AHL61
212 224
213 Have a look at <http://linux.chapter7.ch/touchkit/> for 225 Have a look at <http://linux.chapter7.ch/touchkit/> for
214 a usage description and the required user-space stuff. 226 a usage description and the required user-space stuff.
@@ -218,7 +230,7 @@ config USB_TOUCHSCREEN
218 230
219config USB_TOUCHSCREEN_EGALAX 231config USB_TOUCHSCREEN_EGALAX
220 default y 232 default y
221 bool "eGalax device support" if EMBEDDED 233 bool "eGalax, eTurboTouch CT-410/510/700 device support" if EMBEDDED
222 depends on USB_TOUCHSCREEN 234 depends on USB_TOUCHSCREEN
223 235
224config USB_TOUCHSCREEN_PANJIT 236config USB_TOUCHSCREEN_PANJIT
@@ -228,7 +240,7 @@ config USB_TOUCHSCREEN_PANJIT
228 240
229config USB_TOUCHSCREEN_3M 241config USB_TOUCHSCREEN_3M
230 default y 242 default y
231 bool "3M/Microtouch device support" if EMBEDDED 243 bool "3M/Microtouch EX II series device support" if EMBEDDED
232 depends on USB_TOUCHSCREEN 244 depends on USB_TOUCHSCREEN
233 245
234config USB_TOUCHSCREEN_ITM 246config USB_TOUCHSCREEN_ITM
@@ -236,6 +248,16 @@ config USB_TOUCHSCREEN_ITM
236 bool "ITM device support" if EMBEDDED 248 bool "ITM device support" if EMBEDDED
237 depends on USB_TOUCHSCREEN 249 depends on USB_TOUCHSCREEN
238 250
251config USB_TOUCHSCREEN_ETURBO
252 default y
253 bool "eTurboTouch (non-eGalax compatible) device support" if EMBEDDED
254 depends on USB_TOUCHSCREEN
255
256config USB_TOUCHSCREEN_GUNZE
257 default y
258 bool "Gunze AHL61 device support" if EMBEDDED
259 depends on USB_TOUCHSCREEN
260
239config USB_YEALINK 261config USB_YEALINK
240 tristate "Yealink usb-p1k voip phone" 262 tristate "Yealink usb-p1k voip phone"
241 depends on USB && INPUT && EXPERIMENTAL 263 depends on USB && INPUT && EXPERIMENTAL
@@ -326,3 +348,13 @@ config USB_APPLETOUCH
326 348
327 To compile this driver as a module, choose M here: the 349 To compile this driver as a module, choose M here: the
328 module will be called appletouch. 350 module will be called appletouch.
351
352config USB_TRANCEVIBRATOR
353 tristate "PlayStation 2 Trance Vibrator driver support"
354 depends on USB
355 help
356 Say Y here if you want to connect a PlayStation 2 Trance Vibrator
357 device to your computer's USB port.
358
359 To compile this driver as a module, choose M here: the
360 module will be called trancevibrator.
diff --git a/drivers/usb/input/Makefile b/drivers/usb/input/Makefile
index 764114529c56..295f459d1079 100644
--- a/drivers/usb/input/Makefile
+++ b/drivers/usb/input/Makefile
@@ -3,6 +3,7 @@
3# 3#
4 4
5# Multipart objects. 5# Multipart objects.
6wacom-objs := wacom_sys.o wacom_wac.o
6usbhid-objs := hid-core.o 7usbhid-objs := hid-core.o
7 8
8# Optional parts of multipart objects. 9# Optional parts of multipart objects.
@@ -14,7 +15,7 @@ ifeq ($(CONFIG_USB_HIDINPUT),y)
14 usbhid-objs += hid-input.o 15 usbhid-objs += hid-input.o
15endif 16endif
16ifeq ($(CONFIG_HID_PID),y) 17ifeq ($(CONFIG_HID_PID),y)
17 usbhid-objs += pid.o 18 usbhid-objs += hid-pidff.o
18endif 19endif
19ifeq ($(CONFIG_LOGITECH_FF),y) 20ifeq ($(CONFIG_LOGITECH_FF),y)
20 usbhid-objs += hid-lgff.o 21 usbhid-objs += hid-lgff.o
@@ -22,6 +23,9 @@ endif
22ifeq ($(CONFIG_THRUSTMASTER_FF),y) 23ifeq ($(CONFIG_THRUSTMASTER_FF),y)
23 usbhid-objs += hid-tmff.o 24 usbhid-objs += hid-tmff.o
24endif 25endif
26ifeq ($(CONFIG_ZEROPLUS_FF),y)
27 usbhid-objs += hid-zpff.o
28endif
25ifeq ($(CONFIG_HID_FF),y) 29ifeq ($(CONFIG_HID_FF),y)
26 usbhid-objs += hid-ff.o 30 usbhid-objs += hid-ff.o
27endif 31endif
@@ -44,6 +48,7 @@ obj-$(CONFIG_USB_ACECAD) += acecad.o
44obj-$(CONFIG_USB_YEALINK) += yealink.o 48obj-$(CONFIG_USB_YEALINK) += yealink.o
45obj-$(CONFIG_USB_XPAD) += xpad.o 49obj-$(CONFIG_USB_XPAD) += xpad.o
46obj-$(CONFIG_USB_APPLETOUCH) += appletouch.o 50obj-$(CONFIG_USB_APPLETOUCH) += appletouch.o
51obj-$(CONFIG_USB_TRANCEVIBRATOR) += trancevibrator.o
47 52
48ifeq ($(CONFIG_USB_DEBUG),y) 53ifeq ($(CONFIG_USB_DEBUG),y)
49EXTRA_CFLAGS += -DDEBUG 54EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/usb/input/acecad.c b/drivers/usb/input/acecad.c
index 18c10e150ef3..d83603ba40ae 100644
--- a/drivers/usb/input/acecad.c
+++ b/drivers/usb/input/acecad.c
@@ -141,10 +141,7 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_
141 141
142 endpoint = &interface->endpoint[0].desc; 142 endpoint = &interface->endpoint[0].desc;
143 143
144 if (!(endpoint->bEndpointAddress & 0x80)) 144 if (!usb_endpoint_is_int_in(endpoint))
145 return -ENODEV;
146
147 if ((endpoint->bmAttributes & 3) != 3)
148 return -ENODEV; 145 return -ENODEV;
149 146
150 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); 147 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
diff --git a/drivers/usb/input/appletouch.c b/drivers/usb/input/appletouch.c
index 044faa07e297..0aa9cc2bfd69 100644
--- a/drivers/usb/input/appletouch.c
+++ b/drivers/usb/input/appletouch.c
@@ -436,10 +436,7 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id
436 iface_desc = iface->cur_altsetting; 436 iface_desc = iface->cur_altsetting;
437 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { 437 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
438 endpoint = &iface_desc->endpoint[i].desc; 438 endpoint = &iface_desc->endpoint[i].desc;
439 if (!int_in_endpointAddr && 439 if (!int_in_endpointAddr && usb_endpoint_is_int_in(endpoint)) {
440 (endpoint->bEndpointAddress & USB_DIR_IN) &&
441 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
442 == USB_ENDPOINT_XFER_INT)) {
443 /* we found an interrupt in endpoint */ 440 /* we found an interrupt in endpoint */
444 int_in_endpointAddr = endpoint->bEndpointAddress; 441 int_in_endpointAddr = endpoint->bEndpointAddress;
445 break; 442 break;
diff --git a/drivers/usb/input/ati_remote.c b/drivers/usb/input/ati_remote.c
index 3719fcb04b8f..3558d7ed99b9 100644
--- a/drivers/usb/input/ati_remote.c
+++ b/drivers/usb/input/ati_remote.c
@@ -732,12 +732,8 @@ static int ati_remote_probe(struct usb_interface *interface, const struct usb_de
732 endpoint_in = &iface_host->endpoint[0].desc; 732 endpoint_in = &iface_host->endpoint[0].desc;
733 endpoint_out = &iface_host->endpoint[1].desc; 733 endpoint_out = &iface_host->endpoint[1].desc;
734 734
735 if (!(endpoint_in->bEndpointAddress & USB_DIR_IN)) { 735 if (!usb_endpoint_is_int_in(endpoint_in)) {
736 err("%s: Unexpected endpoint_in->bEndpointAddress\n", __FUNCTION__); 736 err("%s: Unexpected endpoint_in\n", __FUNCTION__);
737 return -ENODEV;
738 }
739 if ((endpoint_in->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT) {
740 err("%s: Unexpected endpoint_in->bmAttributes\n", __FUNCTION__);
741 return -ENODEV; 737 return -ENODEV;
742 } 738 }
743 if (le16_to_cpu(endpoint_in->wMaxPacketSize) == 0) { 739 if (le16_to_cpu(endpoint_in->wMaxPacketSize) == 0) {
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 3305fb6079eb..e0fd11605b43 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -543,8 +543,6 @@ static void hid_free_device(struct hid_device *device)
543{ 543{
544 unsigned i,j; 544 unsigned i,j;
545 545
546 hid_ff_exit(device);
547
548 for (i = 0; i < HID_REPORT_TYPES; i++) { 546 for (i = 0; i < HID_REPORT_TYPES; i++) {
549 struct hid_report_enum *report_enum = device->report_enum + i; 547 struct hid_report_enum *report_enum = device->report_enum + i;
550 548
@@ -1023,7 +1021,8 @@ static void hid_irq_in(struct urb *urb, struct pt_regs *regs)
1023 return; 1021 return;
1024 case -EILSEQ: /* protocol error or unplug */ 1022 case -EILSEQ: /* protocol error or unplug */
1025 case -EPROTO: /* protocol error or unplug */ 1023 case -EPROTO: /* protocol error or unplug */
1026 case -ETIMEDOUT: /* NAK */ 1024 case -ETIME: /* protocol error or unplug */
1025 case -ETIMEDOUT: /* Should never happen, but... */
1027 clear_bit(HID_IN_RUNNING, &hid->iofl); 1026 clear_bit(HID_IN_RUNNING, &hid->iofl);
1028 hid_io_error(hid); 1027 hid_io_error(hid);
1029 return; 1028 return;
@@ -1108,7 +1107,7 @@ int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
1108/* 1107/*
1109 * Find a report field with a specified HID usage. 1108 * Find a report field with a specified HID usage.
1110 */ 1109 */
1111 1110#if 0
1112struct hid_field *hid_find_field_by_usage(struct hid_device *hid, __u32 wanted_usage, int type) 1111struct hid_field *hid_find_field_by_usage(struct hid_device *hid, __u32 wanted_usage, int type)
1113{ 1112{
1114 struct hid_report *report; 1113 struct hid_report *report;
@@ -1120,6 +1119,7 @@ struct hid_field *hid_find_field_by_usage(struct hid_device *hid, __u32 wanted_u
1120 return report->field[i]; 1119 return report->field[i];
1121 return NULL; 1120 return NULL;
1122} 1121}
1122#endif /* 0 */
1123 1123
1124static int hid_submit_out(struct hid_device *hid) 1124static int hid_submit_out(struct hid_device *hid)
1125{ 1125{
@@ -1535,13 +1535,17 @@ void hid_init_reports(struct hid_device *hid)
1535#define USB_VENDOR_ID_GLAB 0x06c2 1535#define USB_VENDOR_ID_GLAB 0x06c2
1536#define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038 1536#define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038
1537#define USB_DEVICE_ID_1_PHIDGETSERVO_30 0x0039 1537#define USB_DEVICE_ID_1_PHIDGETSERVO_30 0x0039
1538#define USB_DEVICE_ID_8_8_8_IF_KIT 0x0045
1539#define USB_DEVICE_ID_0_0_4_IF_KIT 0x0040 1538#define USB_DEVICE_ID_0_0_4_IF_KIT 0x0040
1539#define USB_DEVICE_ID_0_16_16_IF_KIT 0x0044
1540#define USB_DEVICE_ID_8_8_8_IF_KIT 0x0045
1541#define USB_DEVICE_ID_0_8_7_IF_KIT 0x0051
1540#define USB_DEVICE_ID_0_8_8_IF_KIT 0x0053 1542#define USB_DEVICE_ID_0_8_8_IF_KIT 0x0053
1543#define USB_DEVICE_ID_PHIDGET_MOTORCONTROL 0x0058
1541 1544
1542#define USB_VENDOR_ID_WISEGROUP 0x0925 1545#define USB_VENDOR_ID_WISEGROUP 0x0925
1543#define USB_DEVICE_ID_1_PHIDGETSERVO_20 0x8101 1546#define USB_DEVICE_ID_1_PHIDGETSERVO_20 0x8101
1544#define USB_DEVICE_ID_4_PHIDGETSERVO_20 0x8104 1547#define USB_DEVICE_ID_4_PHIDGETSERVO_20 0x8104
1548#define USB_DEVICE_ID_8_8_4_IF_KIT 0x8201
1545#define USB_DEVICE_ID_DUAL_USB_JOYPAD 0x8866 1549#define USB_DEVICE_ID_DUAL_USB_JOYPAD 0x8866
1546 1550
1547#define USB_VENDOR_ID_WISEGROUP_LTD 0x6677 1551#define USB_VENDOR_ID_WISEGROUP_LTD 0x6677
@@ -1591,6 +1595,13 @@ void hid_init_reports(struct hid_device *hid)
1591 1595
1592#define USB_VENDOR_ID_YEALINK 0x6993 1596#define USB_VENDOR_ID_YEALINK 0x6993
1593#define USB_DEVICE_ID_YEALINK_P1K_P4K_B2K 0xb001 1597#define USB_DEVICE_ID_YEALINK_P1K_P4K_B2K 0xb001
1598
1599#define USB_VENDOR_ID_ALCOR 0x058f
1600#define USB_DEVICE_ID_ALCOR_USBRS232 0x9720
1601
1602#define USB_VENDOR_ID_SUN 0x0430
1603#define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab
1604
1594/* 1605/*
1595 * Alphabetically sorted blacklist by quirk type. 1606 * Alphabetically sorted blacklist by quirk type.
1596 */ 1607 */
@@ -1608,6 +1619,7 @@ static const struct hid_blacklist {
1608 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22, HID_QUIRK_IGNORE }, 1619 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22, HID_QUIRK_IGNORE },
1609 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23, HID_QUIRK_IGNORE }, 1620 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23, HID_QUIRK_IGNORE },
1610 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24, HID_QUIRK_IGNORE }, 1621 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24, HID_QUIRK_IGNORE },
1622 { USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232, HID_QUIRK_IGNORE },
1611 { USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD, HID_QUIRK_IGNORE }, 1623 { USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD, HID_QUIRK_IGNORE },
1612 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW40, HID_QUIRK_IGNORE }, 1624 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW40, HID_QUIRK_IGNORE },
1613 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW24, HID_QUIRK_IGNORE }, 1625 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW24, HID_QUIRK_IGNORE },
@@ -1620,9 +1632,12 @@ static const struct hid_blacklist {
1620 { USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5, HID_QUIRK_IGNORE }, 1632 { USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5, HID_QUIRK_IGNORE },
1621 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30, HID_QUIRK_IGNORE }, 1633 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30, HID_QUIRK_IGNORE },
1622 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30, HID_QUIRK_IGNORE }, 1634 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30, HID_QUIRK_IGNORE },
1623 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT, HID_QUIRK_IGNORE },
1624 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT, HID_QUIRK_IGNORE }, 1635 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT, HID_QUIRK_IGNORE },
1636 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT, HID_QUIRK_IGNORE },
1637 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT, HID_QUIRK_IGNORE },
1638 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT, HID_QUIRK_IGNORE },
1625 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT, HID_QUIRK_IGNORE }, 1639 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT, HID_QUIRK_IGNORE },
1640 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL, HID_QUIRK_IGNORE },
1626 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE, HID_QUIRK_IGNORE }, 1641 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE, HID_QUIRK_IGNORE },
1627 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB, HID_QUIRK_IGNORE }, 1642 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB, HID_QUIRK_IGNORE },
1628 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90, HID_QUIRK_IGNORE }, 1643 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90, HID_QUIRK_IGNORE },
@@ -1690,7 +1705,11 @@ static const struct hid_blacklist {
1690 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_IGNORE }, 1705 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_IGNORE },
1691 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1, HID_QUIRK_IGNORE }, 1706 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1, HID_QUIRK_IGNORE },
1692 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100, HID_QUIRK_IGNORE }, 1707 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100, HID_QUIRK_IGNORE },
1708 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20, HID_QUIRK_IGNORE },
1709 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30, HID_QUIRK_IGNORE },
1693 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100, HID_QUIRK_IGNORE }, 1710 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100, HID_QUIRK_IGNORE },
1711 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108, HID_QUIRK_IGNORE },
1712 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118, HID_QUIRK_IGNORE },
1694 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200, HID_QUIRK_IGNORE }, 1713 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200, HID_QUIRK_IGNORE },
1695 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300, HID_QUIRK_IGNORE }, 1714 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300, HID_QUIRK_IGNORE },
1696 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400, HID_QUIRK_IGNORE }, 1715 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400, HID_QUIRK_IGNORE },
@@ -1701,6 +1720,7 @@ static const struct hid_blacklist {
1701 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS, HID_QUIRK_IGNORE }, 1720 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS, HID_QUIRK_IGNORE },
1702 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, 1721 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
1703 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, 1722 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
1723 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT, HID_QUIRK_IGNORE },
1704 { USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K, HID_QUIRK_IGNORE }, 1724 { USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K, HID_QUIRK_IGNORE },
1705 1725
1706 { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR, HID_QUIRK_IGNORE }, 1726 { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR, HID_QUIRK_IGNORE },
@@ -1711,6 +1731,7 @@ static const struct hid_blacklist {
1711 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET }, 1731 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET },
1712 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET }, 1732 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET },
1713 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET }, 1733 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET },
1734 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET },
1714 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, 1735 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
1715 { USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, 1736 { USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
1716 1737
diff --git a/drivers/usb/input/hid-ff.c b/drivers/usb/input/hid-ff.c
index d5c91ee67991..a8fc46c721c5 100644
--- a/drivers/usb/input/hid-ff.c
+++ b/drivers/usb/input/hid-ff.c
@@ -44,45 +44,38 @@ struct hid_ff_initializer {
44 int (*init)(struct hid_device*); 44 int (*init)(struct hid_device*);
45}; 45};
46 46
47/*
48 * We try pidff when no other driver is found because PID is the
49 * standards compliant way of implementing force feedback in HID.
50 * pidff_init() will quickly abort if the device doesn't appear to
51 * be a PID device
52 */
47static struct hid_ff_initializer inits[] = { 53static struct hid_ff_initializer inits[] = {
48#ifdef CONFIG_LOGITECH_FF 54#ifdef CONFIG_LOGITECH_FF
49 {0x46d, 0xc211, hid_lgff_init}, // Logitech Cordless rumble pad 55 { 0x46d, 0xc211, hid_lgff_init }, /* Logitech Cordless rumble pad */
50 {0x46d, 0xc283, hid_lgff_init}, // Logitech Wingman Force 3d 56 { 0x46d, 0xc283, hid_lgff_init }, /* Logitech Wingman Force 3d */
51 {0x46d, 0xc295, hid_lgff_init}, // Logitech MOMO force wheel 57 { 0x46d, 0xc295, hid_lgff_init }, /* Logitech MOMO force wheel */
52 {0x46d, 0xc219, hid_lgff_init}, // Logitech Cordless rumble pad 2 58 { 0x46d, 0xc219, hid_lgff_init }, /* Logitech Cordless rumble pad 2 */
53#endif
54#ifdef CONFIG_HID_PID
55 {0x45e, 0x001b, hid_pid_init},
56#endif 59#endif
57#ifdef CONFIG_THRUSTMASTER_FF 60#ifdef CONFIG_THRUSTMASTER_FF
58 {0x44f, 0xb304, hid_tmff_init}, 61 { 0x44f, 0xb304, hid_tmff_init },
59#endif 62#endif
60 {0, 0, NULL} /* Terminating entry */ 63#ifdef CONFIG_ZEROPLUS_FF
64 { 0xc12, 0x0005, hid_zpff_init },
65 { 0xc12, 0x0030, hid_zpff_init },
66#endif
67 { 0, 0, hid_pidff_init} /* Matches anything */
61}; 68};
62 69
63static struct hid_ff_initializer *hid_get_ff_init(__u16 idVendor,
64 __u16 idProduct)
65{
66 struct hid_ff_initializer *init;
67 for (init = inits;
68 init->idVendor
69 && !(init->idVendor == idVendor
70 && init->idProduct == idProduct);
71 init++);
72
73 return init->idVendor? init : NULL;
74}
75
76int hid_ff_init(struct hid_device* hid) 70int hid_ff_init(struct hid_device* hid)
77{ 71{
78 struct hid_ff_initializer *init; 72 struct hid_ff_initializer *init;
73 int vendor = le16_to_cpu(hid->dev->descriptor.idVendor);
74 int product = le16_to_cpu(hid->dev->descriptor.idProduct);
79 75
80 init = hid_get_ff_init(le16_to_cpu(hid->dev->descriptor.idVendor), 76 for (init = inits; init->idVendor; init++)
81 le16_to_cpu(hid->dev->descriptor.idProduct)); 77 if (init->idVendor == vendor && init->idProduct == product)
78 break;
82 79
83 if (!init) {
84 dbg("hid_ff_init could not find initializer");
85 return -ENOSYS;
86 }
87 return init->init(hid); 80 return init->init(hid);
88} 81}
diff --git a/drivers/usb/input/hid-input.c b/drivers/usb/input/hid-input.c
index 7208839f2dbf..4c62afbeb430 100644
--- a/drivers/usb/input/hid-input.c
+++ b/drivers/usb/input/hid-input.c
@@ -65,11 +65,9 @@ static const struct {
65#define map_rel(c) do { usage->code = c; usage->type = EV_REL; bit = input->relbit; max = REL_MAX; } while (0) 65#define map_rel(c) do { usage->code = c; usage->type = EV_REL; bit = input->relbit; max = REL_MAX; } while (0)
66#define map_key(c) do { usage->code = c; usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX; } while (0) 66#define map_key(c) do { usage->code = c; usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX; } while (0)
67#define map_led(c) do { usage->code = c; usage->type = EV_LED; bit = input->ledbit; max = LED_MAX; } while (0) 67#define map_led(c) do { usage->code = c; usage->type = EV_LED; bit = input->ledbit; max = LED_MAX; } while (0)
68#define map_ff(c) do { usage->code = c; usage->type = EV_FF; bit = input->ffbit; max = FF_MAX; } while (0)
69 68
70#define map_abs_clear(c) do { map_abs(c); clear_bit(c, bit); } while (0) 69#define map_abs_clear(c) do { map_abs(c); clear_bit(c, bit); } while (0)
71#define map_key_clear(c) do { map_key(c); clear_bit(c, bit); } while (0) 70#define map_key_clear(c) do { map_key(c); clear_bit(c, bit); } while (0)
72#define map_ff_effect(c) do { set_bit(c, input->ffbit); } while (0)
73 71
74#ifdef CONFIG_USB_HIDINPUT_POWERBOOK 72#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
75 73
@@ -525,23 +523,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
525 523
526 case HID_UP_PID: 524 case HID_UP_PID:
527 525
528 set_bit(EV_FF, input->evbit);
529 switch(usage->hid & HID_USAGE) { 526 switch(usage->hid & HID_USAGE) {
530 case 0x26: map_ff_effect(FF_CONSTANT); goto ignore;
531 case 0x27: map_ff_effect(FF_RAMP); goto ignore;
532 case 0x28: map_ff_effect(FF_CUSTOM); goto ignore;
533 case 0x30: map_ff_effect(FF_SQUARE); map_ff_effect(FF_PERIODIC); goto ignore;
534 case 0x31: map_ff_effect(FF_SINE); map_ff_effect(FF_PERIODIC); goto ignore;
535 case 0x32: map_ff_effect(FF_TRIANGLE); map_ff_effect(FF_PERIODIC); goto ignore;
536 case 0x33: map_ff_effect(FF_SAW_UP); map_ff_effect(FF_PERIODIC); goto ignore;
537 case 0x34: map_ff_effect(FF_SAW_DOWN); map_ff_effect(FF_PERIODIC); goto ignore;
538 case 0x40: map_ff_effect(FF_SPRING); goto ignore;
539 case 0x41: map_ff_effect(FF_DAMPER); goto ignore;
540 case 0x42: map_ff_effect(FF_INERTIA); goto ignore;
541 case 0x43: map_ff_effect(FF_FRICTION); goto ignore;
542 case 0x7e: map_ff(FF_GAIN); break;
543 case 0x83: input->ff_effects_max = field->value[0]; goto ignore;
544 case 0x98: map_ff(FF_AUTOCENTER); break;
545 case 0xa4: map_key_clear(BTN_DEAD); break; 527 case 0xa4: map_key_clear(BTN_DEAD); break;
546 default: goto ignore; 528 default: goto ignore;
547 } 529 }
@@ -698,8 +680,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
698 } 680 }
699 681
700 if (usage->hid == (HID_UP_PID | 0x83UL)) { /* Simultaneous Effects Max */ 682 if (usage->hid == (HID_UP_PID | 0x83UL)) { /* Simultaneous Effects Max */
701 input->ff_effects_max = value; 683 dbg("Maximum Effects - %d",value);
702 dbg("Maximum Effects - %d",input->ff_effects_max);
703 return; 684 return;
704 } 685 }
705 686
@@ -748,7 +729,7 @@ static int hidinput_input_event(struct input_dev *dev, unsigned int type, unsign
748 int offset; 729 int offset;
749 730
750 if (type == EV_FF) 731 if (type == EV_FF)
751 return hid_ff_event(hid, dev, type, code, value); 732 return input_ff_event(dev, type, code, value);
752 733
753 if (type != EV_LED) 734 if (type != EV_LED)
754 return -1; 735 return -1;
diff --git a/drivers/usb/input/hid-lgff.c b/drivers/usb/input/hid-lgff.c
index f07d44357ff1..93da222b6da8 100644
--- a/drivers/usb/input/hid-lgff.c
+++ b/drivers/usb/input/hid-lgff.c
@@ -1,12 +1,11 @@
1/* 1/*
2 * $$
3 *
4 * Force feedback support for hid-compliant for some of the devices from 2 * Force feedback support for hid-compliant for some of the devices from
5 * Logitech, namely: 3 * Logitech, namely:
6 * - WingMan Cordless RumblePad 4 * - WingMan Cordless RumblePad
7 * - WingMan Force 3D 5 * - WingMan Force 3D
8 * 6 *
9 * Copyright (c) 2002-2004 Johann Deneux 7 * Copyright (c) 2002-2004 Johann Deneux
8 * Copyright (c) 2006 Anssi Hannula <anssi.hannula@gmail.com>
10 */ 9 */
11 10
12/* 11/*
@@ -29,495 +28,117 @@
29 */ 28 */
30 29
31#include <linux/input.h> 30#include <linux/input.h>
32#include <linux/sched.h>
33
34//#define DEBUG
35#include <linux/usb.h> 31#include <linux/usb.h>
36
37#include <linux/circ_buf.h>
38
39#include "hid.h" 32#include "hid.h"
40#include "fixp-arith.h"
41
42
43/* Periodicity of the update */
44#define PERIOD (HZ/10)
45
46#define RUN_AT(t) (jiffies + (t))
47
48/* Effect status */
49#define EFFECT_STARTED 0 /* Effect is going to play after some time
50 (ff_replay.delay) */
51#define EFFECT_PLAYING 1 /* Effect is being played */
52#define EFFECT_USED 2
53
54// For lgff_device::flags
55#define DEVICE_CLOSING 0 /* The driver is being unitialised */
56
57/* Check that the current process can access an effect */
58#define CHECK_OWNERSHIP(effect) (current->pid == 0 \
59 || effect.owner == current->pid)
60
61#define LGFF_CHECK_OWNERSHIP(i, l) \
62 (i>=0 && i<LGFF_EFFECTS \
63 && test_bit(EFFECT_USED, l->effects[i].flags) \
64 && CHECK_OWNERSHIP(l->effects[i]))
65
66#define LGFF_EFFECTS 8
67 33
68struct device_type { 34struct device_type {
69 u16 idVendor; 35 u16 idVendor;
70 u16 idProduct; 36 u16 idProduct;
71 signed short *ff; 37 const signed short *ff;
72};
73
74struct lgff_effect {
75 pid_t owner;
76
77 struct ff_effect effect;
78
79 unsigned long flags[1];
80 unsigned int count; /* Number of times left to play */
81 unsigned long started_at; /* When the effect started to play */
82};
83
84struct lgff_device {
85 struct hid_device* hid;
86
87 struct hid_report* constant;
88 struct hid_report* rumble;
89 struct hid_report* condition;
90
91 struct lgff_effect effects[LGFF_EFFECTS];
92 spinlock_t lock; /* device-level lock. Having locks on
93 a per-effect basis could be nice, but
94 isn't really necessary */
95
96 unsigned long flags[1]; /* Contains various information about the
97 state of the driver for this device */
98
99 struct timer_list timer;
100}; 38};
101 39
102/* Callbacks */ 40static const signed short ff_rumble[] = {
103static void hid_lgff_exit(struct hid_device* hid);
104static int hid_lgff_event(struct hid_device *hid, struct input_dev *input,
105 unsigned int type, unsigned int code, int value);
106static int hid_lgff_flush(struct input_dev *input, struct file *file);
107static int hid_lgff_upload_effect(struct input_dev *input,
108 struct ff_effect *effect);
109static int hid_lgff_erase(struct input_dev *input, int id);
110
111/* Local functions */
112static void hid_lgff_input_init(struct hid_device* hid);
113static void hid_lgff_timer(unsigned long timer_data);
114static struct hid_report* hid_lgff_duplicate_report(struct hid_report*);
115static void hid_lgff_delete_report(struct hid_report*);
116
117static signed short ff_rumble[] = {
118 FF_RUMBLE, 41 FF_RUMBLE,
119 -1 42 -1
120}; 43};
121 44
122static signed short ff_joystick[] = { 45static const signed short ff_joystick[] = {
123 FF_CONSTANT, 46 FF_CONSTANT,
124 -1 47 -1
125}; 48};
126 49
127static struct device_type devices[] = { 50static const struct device_type devices[] = {
128 {0x046d, 0xc211, ff_rumble}, 51 { 0x046d, 0xc211, ff_rumble },
129 {0x046d, 0xc219, ff_rumble}, 52 { 0x046d, 0xc219, ff_rumble },
130 {0x046d, 0xc283, ff_joystick}, 53 { 0x046d, 0xc283, ff_joystick },
131 {0x0000, 0x0000, ff_joystick} 54 { 0x0000, 0x0000, ff_joystick }
132}; 55};
133 56
57static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
58{
59 struct hid_device *hid = dev->private;
60 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
61 struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
62 int x, y;
63 unsigned int left, right;
64
65#define CLAMP(x) if (x < 0) x = 0; if (x > 0xff) x = 0xff
66
67 switch (effect->type) {
68 case FF_CONSTANT:
69 x = effect->u.ramp.start_level + 0x7f; /* 0x7f is center */
70 y = effect->u.ramp.end_level + 0x7f;
71 CLAMP(x);
72 CLAMP(y);
73 report->field[0]->value[0] = 0x51;
74 report->field[0]->value[1] = 0x08;
75 report->field[0]->value[2] = x;
76 report->field[0]->value[3] = y;
77 dbg("(x, y)=(%04x, %04x)", x, y);
78 hid_submit_report(hid, report, USB_DIR_OUT);
79 break;
80
81 case FF_RUMBLE:
82 right = effect->u.rumble.strong_magnitude;
83 left = effect->u.rumble.weak_magnitude;
84 right = right * 0xff / 0xffff;
85 left = left * 0xff / 0xffff;
86 CLAMP(left);
87 CLAMP(right);
88 report->field[0]->value[0] = 0x42;
89 report->field[0]->value[1] = 0x00;
90 report->field[0]->value[2] = left;
91 report->field[0]->value[3] = right;
92 dbg("(left, right)=(%04x, %04x)", left, right);
93 hid_submit_report(hid, report, USB_DIR_OUT);
94 break;
95 }
96 return 0;
97}
98
134int hid_lgff_init(struct hid_device* hid) 99int hid_lgff_init(struct hid_device* hid)
135{ 100{
136 struct lgff_device *private; 101 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
137 struct hid_report* report; 102 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
138 struct hid_field* field; 103 struct input_dev *dev = hidinput->input;
104 struct hid_report *report;
105 struct hid_field *field;
106 int error;
107 int i, j;
139 108
140 /* Find the report to use */ 109 /* Find the report to use */
141 if (list_empty(&hid->report_enum[HID_OUTPUT_REPORT].report_list)) { 110 if (list_empty(report_list)) {
142 err("No output report found"); 111 err("No output report found");
143 return -1; 112 return -1;
144 } 113 }
114
145 /* Check that the report looks ok */ 115 /* Check that the report looks ok */
146 report = (struct hid_report*)hid->report_enum[HID_OUTPUT_REPORT].report_list.next; 116 report = list_entry(report_list->next, struct hid_report, list);
147 if (!report) { 117 if (!report) {
148 err("NULL output report"); 118 err("NULL output report");
149 return -1; 119 return -1;
150 } 120 }
121
151 field = report->field[0]; 122 field = report->field[0];
152 if (!field) { 123 if (!field) {
153 err("NULL field"); 124 err("NULL field");
154 return -1; 125 return -1;
155 } 126 }
156 127
157 private = kzalloc(sizeof(struct lgff_device), GFP_KERNEL); 128 for (i = 0; i < ARRAY_SIZE(devices); i++) {
158 if (!private) 129 if (dev->id.vendor == devices[i].idVendor &&
159 return -1; 130 dev->id.product == devices[i].idProduct) {
160 hid->ff_private = private; 131 for (j = 0; devices[i].ff[j] >= 0; j++)
161 132 set_bit(devices[i].ff[j], dev->ffbit);
162 /* Input init */ 133 break;
163 hid_lgff_input_init(hid);
164
165
166 private->constant = hid_lgff_duplicate_report(report);
167 if (!private->constant) {
168 kfree(private);
169 return -1;
170 }
171 private->constant->field[0]->value[0] = 0x51;
172 private->constant->field[0]->value[1] = 0x08;
173 private->constant->field[0]->value[2] = 0x7f;
174 private->constant->field[0]->value[3] = 0x7f;
175
176 private->rumble = hid_lgff_duplicate_report(report);
177 if (!private->rumble) {
178 hid_lgff_delete_report(private->constant);
179 kfree(private);
180 return -1;
181 }
182 private->rumble->field[0]->value[0] = 0x42;
183
184
185 private->condition = hid_lgff_duplicate_report(report);
186 if (!private->condition) {
187 hid_lgff_delete_report(private->rumble);
188 hid_lgff_delete_report(private->constant);
189 kfree(private);
190 return -1;
191 }
192
193 private->hid = hid;
194
195 spin_lock_init(&private->lock);
196 init_timer(&private->timer);
197 private->timer.data = (unsigned long)private;
198 private->timer.function = hid_lgff_timer;
199
200 /* Event and exit callbacks */
201 hid->ff_exit = hid_lgff_exit;
202 hid->ff_event = hid_lgff_event;
203
204 /* Start the update task */
205 private->timer.expires = RUN_AT(PERIOD);
206 add_timer(&private->timer); /*TODO: only run the timer when at least
207 one effect is playing */
208
209 printk(KERN_INFO "Force feedback for Logitech force feedback devices by Johann Deneux <johann.deneux@it.uu.se>\n");
210
211 return 0;
212}
213
214static struct hid_report* hid_lgff_duplicate_report(struct hid_report* report)
215{
216 struct hid_report* ret;
217
218 ret = kmalloc(sizeof(struct lgff_device), GFP_KERNEL);
219 if (!ret)
220 return NULL;
221 *ret = *report;
222
223 ret->field[0] = kmalloc(sizeof(struct hid_field), GFP_KERNEL);
224 if (!ret->field[0]) {
225 kfree(ret);
226 return NULL;
227 }
228 *ret->field[0] = *report->field[0];
229
230 ret->field[0]->value = kzalloc(sizeof(s32[8]), GFP_KERNEL);
231 if (!ret->field[0]->value) {
232 kfree(ret->field[0]);
233 kfree(ret);
234 return NULL;
235 }
236
237 return ret;
238}
239
240static void hid_lgff_delete_report(struct hid_report* report)
241{
242 if (report) {
243 kfree(report->field[0]->value);
244 kfree(report->field[0]);
245 kfree(report);
246 }
247}
248
249static void hid_lgff_input_init(struct hid_device* hid)
250{
251 struct device_type* dev = devices;
252 signed short* ff;
253 u16 idVendor = le16_to_cpu(hid->dev->descriptor.idVendor);
254 u16 idProduct = le16_to_cpu(hid->dev->descriptor.idProduct);
255 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
256 struct input_dev *input_dev = hidinput->input;
257
258 while (dev->idVendor && (idVendor != dev->idVendor || idProduct != dev->idProduct))
259 dev++;
260
261 for (ff = dev->ff; *ff >= 0; ff++)
262 set_bit(*ff, input_dev->ffbit);
263
264 input_dev->upload_effect = hid_lgff_upload_effect;
265 input_dev->flush = hid_lgff_flush;
266
267 set_bit(EV_FF, input_dev->evbit);
268 input_dev->ff_effects_max = LGFF_EFFECTS;
269}
270
271static void hid_lgff_exit(struct hid_device* hid)
272{
273 struct lgff_device *lgff = hid->ff_private;
274
275 set_bit(DEVICE_CLOSING, lgff->flags);
276 del_timer_sync(&lgff->timer);
277
278 hid_lgff_delete_report(lgff->condition);
279 hid_lgff_delete_report(lgff->rumble);
280 hid_lgff_delete_report(lgff->constant);
281
282 kfree(lgff);
283}
284
285static int hid_lgff_event(struct hid_device *hid, struct input_dev* input,
286 unsigned int type, unsigned int code, int value)
287{
288 struct lgff_device *lgff = hid->ff_private;
289 struct lgff_effect *effect = lgff->effects + code;
290 unsigned long flags;
291
292 if (type != EV_FF) return -EINVAL;
293 if (!LGFF_CHECK_OWNERSHIP(code, lgff)) return -EACCES;
294 if (value < 0) return -EINVAL;
295
296 spin_lock_irqsave(&lgff->lock, flags);
297
298 if (value > 0) {
299 if (test_bit(EFFECT_STARTED, effect->flags)) {
300 spin_unlock_irqrestore(&lgff->lock, flags);
301 return -EBUSY;
302 }
303 if (test_bit(EFFECT_PLAYING, effect->flags)) {
304 spin_unlock_irqrestore(&lgff->lock, flags);
305 return -EBUSY;
306 }
307
308 effect->count = value;
309
310 if (effect->effect.replay.delay) {
311 set_bit(EFFECT_STARTED, effect->flags);
312 } else {
313 set_bit(EFFECT_PLAYING, effect->flags);
314 }
315 effect->started_at = jiffies;
316 }
317 else { /* value == 0 */
318 clear_bit(EFFECT_STARTED, effect->flags);
319 clear_bit(EFFECT_PLAYING, effect->flags);
320 }
321
322 spin_unlock_irqrestore(&lgff->lock, flags);
323
324 return 0;
325
326}
327
328/* Erase all effects this process owns */
329static int hid_lgff_flush(struct input_dev *dev, struct file *file)
330{
331 struct hid_device *hid = dev->private;
332 struct lgff_device *lgff = hid->ff_private;
333 int i;
334
335 for (i=0; i<dev->ff_effects_max; ++i) {
336
337 /*NOTE: no need to lock here. The only times EFFECT_USED is
338 modified is when effects are uploaded or when an effect is
339 erased. But a process cannot close its dev/input/eventX fd
340 and perform ioctls on the same fd all at the same time */
341 if ( current->pid == lgff->effects[i].owner
342 && test_bit(EFFECT_USED, lgff->effects[i].flags)) {
343
344 if (hid_lgff_erase(dev, i))
345 warn("erase effect %d failed", i);
346 }
347
348 }
349
350 return 0;
351}
352
353static int hid_lgff_erase(struct input_dev *dev, int id)
354{
355 struct hid_device *hid = dev->private;
356 struct lgff_device *lgff = hid->ff_private;
357 unsigned long flags;
358
359 if (!LGFF_CHECK_OWNERSHIP(id, lgff)) return -EACCES;
360
361 spin_lock_irqsave(&lgff->lock, flags);
362 lgff->effects[id].flags[0] = 0;
363 spin_unlock_irqrestore(&lgff->lock, flags);
364
365 return 0;
366}
367
368static int hid_lgff_upload_effect(struct input_dev* input,
369 struct ff_effect* effect)
370{
371 struct hid_device *hid = input->private;
372 struct lgff_device *lgff = hid->ff_private;
373 struct lgff_effect new;
374 int id;
375 unsigned long flags;
376
377 dbg("ioctl rumble");
378
379 if (!test_bit(effect->type, input->ffbit)) return -EINVAL;
380
381 spin_lock_irqsave(&lgff->lock, flags);
382
383 if (effect->id == -1) {
384 int i;
385
386 for (i=0; i<LGFF_EFFECTS && test_bit(EFFECT_USED, lgff->effects[i].flags); ++i);
387 if (i >= LGFF_EFFECTS) {
388 spin_unlock_irqrestore(&lgff->lock, flags);
389 return -ENOSPC;
390 } 134 }
391
392 effect->id = i;
393 lgff->effects[i].owner = current->pid;
394 lgff->effects[i].flags[0] = 0;
395 set_bit(EFFECT_USED, lgff->effects[i].flags);
396 } 135 }
397 else if (!LGFF_CHECK_OWNERSHIP(effect->id, lgff)) {
398 spin_unlock_irqrestore(&lgff->lock, flags);
399 return -EACCES;
400 }
401
402 id = effect->id;
403 new = lgff->effects[id];
404
405 new.effect = *effect;
406
407 if (test_bit(EFFECT_STARTED, lgff->effects[id].flags)
408 || test_bit(EFFECT_STARTED, lgff->effects[id].flags)) {
409
410 /* Changing replay parameters is not allowed (for the time
411 being) */
412 if (new.effect.replay.delay != lgff->effects[id].effect.replay.delay
413 || new.effect.replay.length != lgff->effects[id].effect.replay.length) {
414 spin_unlock_irqrestore(&lgff->lock, flags);
415 return -ENOSYS;
416 }
417 136
418 lgff->effects[id] = new; 137 error = input_ff_create_memless(dev, NULL, hid_lgff_play);
138 if (error)
139 return error;
419 140
420 } else { 141 printk(KERN_INFO "Force feedback for Logitech force feedback devices by Johann Deneux <johann.deneux@it.uu.se>\n");
421 lgff->effects[id] = new;
422 }
423 142
424 spin_unlock_irqrestore(&lgff->lock, flags);
425 return 0; 143 return 0;
426} 144}
427
428static void hid_lgff_timer(unsigned long timer_data)
429{
430 struct lgff_device *lgff = (struct lgff_device*)timer_data;
431 struct hid_device *hid = lgff->hid;
432 unsigned long flags;
433 int x = 0x7f, y = 0x7f; // Coordinates of constant effects
434 unsigned int left = 0, right = 0; // Rumbling
435 int i;
436
437 spin_lock_irqsave(&lgff->lock, flags);
438
439 for (i=0; i<LGFF_EFFECTS; ++i) {
440 struct lgff_effect* effect = lgff->effects +i;
441
442 if (test_bit(EFFECT_PLAYING, effect->flags)) {
443
444 switch (effect->effect.type) {
445 case FF_CONSTANT: {
446 //TODO: handle envelopes
447 int degrees = effect->effect.direction * 360 >> 16;
448 x += fixp_mult(fixp_sin(degrees),
449 fixp_new16(effect->effect.u.constant.level));
450 y += fixp_mult(-fixp_cos(degrees),
451 fixp_new16(effect->effect.u.constant.level));
452 } break;
453 case FF_RUMBLE:
454 right += effect->effect.u.rumble.strong_magnitude;
455 left += effect->effect.u.rumble.weak_magnitude;
456 break;
457 };
458
459 /* One run of the effect is finished playing */
460 if (time_after(jiffies,
461 effect->started_at
462 + effect->effect.replay.delay*HZ/1000
463 + effect->effect.replay.length*HZ/1000)) {
464 dbg("Finished playing once %d", i);
465 if (--effect->count <= 0) {
466 dbg("Stopped %d", i);
467 clear_bit(EFFECT_PLAYING, effect->flags);
468 }
469 else {
470 dbg("Start again %d", i);
471 if (effect->effect.replay.length != 0) {
472 clear_bit(EFFECT_PLAYING, effect->flags);
473 set_bit(EFFECT_STARTED, effect->flags);
474 }
475 effect->started_at = jiffies;
476 }
477 }
478
479 } else if (test_bit(EFFECT_STARTED, lgff->effects[i].flags)) {
480 /* Check if we should start playing the effect */
481 if (time_after(jiffies,
482 lgff->effects[i].started_at
483 + lgff->effects[i].effect.replay.delay*HZ/1000)) {
484 dbg("Now playing %d", i);
485 clear_bit(EFFECT_STARTED, lgff->effects[i].flags);
486 set_bit(EFFECT_PLAYING, lgff->effects[i].flags);
487 }
488 }
489 }
490
491#define CLAMP(x) if (x < 0) x = 0; if (x > 0xff) x = 0xff
492
493 // Clamp values
494 CLAMP(x);
495 CLAMP(y);
496 CLAMP(left);
497 CLAMP(right);
498
499#undef CLAMP
500
501 if (x != lgff->constant->field[0]->value[2]
502 || y != lgff->constant->field[0]->value[3]) {
503 lgff->constant->field[0]->value[2] = x;
504 lgff->constant->field[0]->value[3] = y;
505 dbg("(x,y)=(%04x, %04x)", x, y);
506 hid_submit_report(hid, lgff->constant, USB_DIR_OUT);
507 }
508
509 if (left != lgff->rumble->field[0]->value[2]
510 || right != lgff->rumble->field[0]->value[3]) {
511 lgff->rumble->field[0]->value[2] = left;
512 lgff->rumble->field[0]->value[3] = right;
513 dbg("(left,right)=(%04x, %04x)", left, right);
514 hid_submit_report(hid, lgff->rumble, USB_DIR_OUT);
515 }
516
517 if (!test_bit(DEVICE_CLOSING, lgff->flags)) {
518 lgff->timer.expires = RUN_AT(PERIOD);
519 add_timer(&lgff->timer);
520 }
521
522 spin_unlock_irqrestore(&lgff->lock, flags);
523}
diff --git a/drivers/usb/input/hid-pidff.c b/drivers/usb/input/hid-pidff.c
new file mode 100644
index 000000000000..5420c13eb8eb
--- /dev/null
+++ b/drivers/usb/input/hid-pidff.c
@@ -0,0 +1,1330 @@
1/*
2 * Force feedback driver for USB HID PID compliant devices
3 *
4 * Copyright (c) 2005, 2006 Anssi Hannula <anssi.hannula@gmail.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
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23/* #define DEBUG */
24
25#define debug(format, arg...) pr_debug("hid-pidff: " format "\n" , ## arg)
26
27#include <linux/sched.h>
28#include <linux/input.h>
29#include <linux/usb.h>
30
31#include "hid.h"
32
33#define PID_EFFECTS_MAX 64
34
35/* Report usage table used to put reports into an array */
36
37#define PID_SET_EFFECT 0
38#define PID_EFFECT_OPERATION 1
39#define PID_DEVICE_GAIN 2
40#define PID_POOL 3
41#define PID_BLOCK_LOAD 4
42#define PID_BLOCK_FREE 5
43#define PID_DEVICE_CONTROL 6
44#define PID_CREATE_NEW_EFFECT 7
45
46#define PID_REQUIRED_REPORTS 7
47
48#define PID_SET_ENVELOPE 8
49#define PID_SET_CONDITION 9
50#define PID_SET_PERIODIC 10
51#define PID_SET_CONSTANT 11
52#define PID_SET_RAMP 12
53static const u8 pidff_reports[] = {
54 0x21, 0x77, 0x7d, 0x7f, 0x89, 0x90, 0x96, 0xab,
55 0x5a, 0x5f, 0x6e, 0x73, 0x74
56};
57
58/* device_control is really 0x95, but 0x96 specified as it is the usage of
59the only field in that report */
60
61/* Value usage tables used to put fields and values into arrays */
62
63#define PID_EFFECT_BLOCK_INDEX 0
64
65#define PID_DURATION 1
66#define PID_GAIN 2
67#define PID_TRIGGER_BUTTON 3
68#define PID_TRIGGER_REPEAT_INT 4
69#define PID_DIRECTION_ENABLE 5
70#define PID_START_DELAY 6
71static const u8 pidff_set_effect[] = {
72 0x22, 0x50, 0x52, 0x53, 0x54, 0x56, 0xa7
73};
74
75#define PID_ATTACK_LEVEL 1
76#define PID_ATTACK_TIME 2
77#define PID_FADE_LEVEL 3
78#define PID_FADE_TIME 4
79static const u8 pidff_set_envelope[] = { 0x22, 0x5b, 0x5c, 0x5d, 0x5e };
80
81#define PID_PARAM_BLOCK_OFFSET 1
82#define PID_CP_OFFSET 2
83#define PID_POS_COEFFICIENT 3
84#define PID_NEG_COEFFICIENT 4
85#define PID_POS_SATURATION 5
86#define PID_NEG_SATURATION 6
87#define PID_DEAD_BAND 7
88static const u8 pidff_set_condition[] = {
89 0x22, 0x23, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65
90};
91
92#define PID_MAGNITUDE 1
93#define PID_OFFSET 2
94#define PID_PHASE 3
95#define PID_PERIOD 4
96static const u8 pidff_set_periodic[] = { 0x22, 0x70, 0x6f, 0x71, 0x72 };
97static const u8 pidff_set_constant[] = { 0x22, 0x70 };
98
99#define PID_RAMP_START 1
100#define PID_RAMP_END 2
101static const u8 pidff_set_ramp[] = { 0x22, 0x75, 0x76 };
102
103#define PID_RAM_POOL_AVAILABLE 1
104static const u8 pidff_block_load[] = { 0x22, 0xac };
105
106#define PID_LOOP_COUNT 1
107static const u8 pidff_effect_operation[] = { 0x22, 0x7c };
108
109static const u8 pidff_block_free[] = { 0x22 };
110
111#define PID_DEVICE_GAIN_FIELD 0
112static const u8 pidff_device_gain[] = { 0x7e };
113
114#define PID_RAM_POOL_SIZE 0
115#define PID_SIMULTANEOUS_MAX 1
116#define PID_DEVICE_MANAGED_POOL 2
117static const u8 pidff_pool[] = { 0x80, 0x83, 0xa9 };
118
119/* Special field key tables used to put special field keys into arrays */
120
121#define PID_ENABLE_ACTUATORS 0
122#define PID_RESET 1
123static const u8 pidff_device_control[] = { 0x97, 0x9a };
124
125#define PID_CONSTANT 0
126#define PID_RAMP 1
127#define PID_SQUARE 2
128#define PID_SINE 3
129#define PID_TRIANGLE 4
130#define PID_SAW_UP 5
131#define PID_SAW_DOWN 6
132#define PID_SPRING 7
133#define PID_DAMPER 8
134#define PID_INERTIA 9
135#define PID_FRICTION 10
136static const u8 pidff_effect_types[] = {
137 0x26, 0x27, 0x30, 0x31, 0x32, 0x33, 0x34,
138 0x40, 0x41, 0x42, 0x43
139};
140
141#define PID_BLOCK_LOAD_SUCCESS 0
142#define PID_BLOCK_LOAD_FULL 1
143static const u8 pidff_block_load_status[] = { 0x8c, 0x8d };
144
145#define PID_EFFECT_START 0
146#define PID_EFFECT_STOP 1
147static const u8 pidff_effect_operation_status[] = { 0x79, 0x7b };
148
149struct pidff_usage {
150 struct hid_field *field;
151 s32 *value;
152};
153
154struct pidff_device {
155 struct hid_device *hid;
156
157 struct hid_report *reports[sizeof(pidff_reports)];
158
159 struct pidff_usage set_effect[sizeof(pidff_set_effect)];
160 struct pidff_usage set_envelope[sizeof(pidff_set_envelope)];
161 struct pidff_usage set_condition[sizeof(pidff_set_condition)];
162 struct pidff_usage set_periodic[sizeof(pidff_set_periodic)];
163 struct pidff_usage set_constant[sizeof(pidff_set_constant)];
164 struct pidff_usage set_ramp[sizeof(pidff_set_ramp)];
165
166 struct pidff_usage device_gain[sizeof(pidff_device_gain)];
167 struct pidff_usage block_load[sizeof(pidff_block_load)];
168 struct pidff_usage pool[sizeof(pidff_pool)];
169 struct pidff_usage effect_operation[sizeof(pidff_effect_operation)];
170 struct pidff_usage block_free[sizeof(pidff_block_free)];
171
172 /* Special field is a field that is not composed of
173 usage<->value pairs that pidff_usage values are */
174
175 /* Special field in create_new_effect */
176 struct hid_field *create_new_effect_type;
177
178 /* Special fields in set_effect */
179 struct hid_field *set_effect_type;
180 struct hid_field *effect_direction;
181
182 /* Special field in device_control */
183 struct hid_field *device_control;
184
185 /* Special field in block_load */
186 struct hid_field *block_load_status;
187
188 /* Special field in effect_operation */
189 struct hid_field *effect_operation_status;
190
191 int control_id[sizeof(pidff_device_control)];
192 int type_id[sizeof(pidff_effect_types)];
193 int status_id[sizeof(pidff_block_load_status)];
194 int operation_id[sizeof(pidff_effect_operation_status)];
195
196 int pid_id[PID_EFFECTS_MAX];
197};
198
199/*
200 * Scale an unsigned value with range 0..max for the given field
201 */
202static int pidff_rescale(int i, int max, struct hid_field *field)
203{
204 return i * (field->logical_maximum - field->logical_minimum) / max +
205 field->logical_minimum;
206}
207
208/*
209 * Scale a signed value in range -0x8000..0x7fff for the given field
210 */
211static int pidff_rescale_signed(int i, struct hid_field *field)
212{
213 return i == 0 ? 0 : i >
214 0 ? i * field->logical_maximum / 0x7fff : i *
215 field->logical_minimum / -0x8000;
216}
217
218static void pidff_set(struct pidff_usage *usage, u16 value)
219{
220 usage->value[0] = pidff_rescale(value, 0xffff, usage->field);
221 debug("calculated from %d to %d", value, usage->value[0]);
222}
223
224static void pidff_set_signed(struct pidff_usage *usage, s16 value)
225{
226 if (usage->field->logical_minimum < 0)
227 usage->value[0] = pidff_rescale_signed(value, usage->field);
228 else {
229 if (value < 0)
230 usage->value[0] =
231 pidff_rescale(-value, 0x8000, usage->field);
232 else
233 usage->value[0] =
234 pidff_rescale(value, 0x7fff, usage->field);
235 }
236 debug("calculated from %d to %d", value, usage->value[0]);
237}
238
239/*
240 * Send envelope report to the device
241 */
242static void pidff_set_envelope_report(struct pidff_device *pidff,
243 struct ff_envelope *envelope)
244{
245 pidff->set_envelope[PID_EFFECT_BLOCK_INDEX].value[0] =
246 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
247
248 pidff->set_envelope[PID_ATTACK_LEVEL].value[0] =
249 pidff_rescale(envelope->attack_level >
250 0x7fff ? 0x7fff : envelope->attack_level, 0x7fff,
251 pidff->set_envelope[PID_ATTACK_LEVEL].field);
252 pidff->set_envelope[PID_FADE_LEVEL].value[0] =
253 pidff_rescale(envelope->fade_level >
254 0x7fff ? 0x7fff : envelope->fade_level, 0x7fff,
255 pidff->set_envelope[PID_FADE_LEVEL].field);
256
257 pidff->set_envelope[PID_ATTACK_TIME].value[0] = envelope->attack_length;
258 pidff->set_envelope[PID_FADE_TIME].value[0] = envelope->fade_length;
259
260 debug("attack %u => %d", envelope->attack_level,
261 pidff->set_envelope[PID_ATTACK_LEVEL].value[0]);
262
263 hid_submit_report(pidff->hid, pidff->reports[PID_SET_ENVELOPE],
264 USB_DIR_OUT);
265}
266
267/*
268 * Test if the new envelope differs from old one
269 */
270static int pidff_needs_set_envelope(struct ff_envelope *envelope,
271 struct ff_envelope *old)
272{
273 return envelope->attack_level != old->attack_level ||
274 envelope->fade_level != old->fade_level ||
275 envelope->attack_length != old->attack_length ||
276 envelope->fade_length != old->fade_length;
277}
278
279/*
280 * Send constant force report to the device
281 */
282static void pidff_set_constant_force_report(struct pidff_device *pidff,
283 struct ff_effect *effect)
284{
285 pidff->set_constant[PID_EFFECT_BLOCK_INDEX].value[0] =
286 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
287 pidff_set_signed(&pidff->set_constant[PID_MAGNITUDE],
288 effect->u.constant.level);
289
290 hid_submit_report(pidff->hid, pidff->reports[PID_SET_CONSTANT],
291 USB_DIR_OUT);
292}
293
294/*
295 * Test if the constant parameters have changed between effects
296 */
297static int pidff_needs_set_constant(struct ff_effect *effect,
298 struct ff_effect *old)
299{
300 return effect->u.constant.level != old->u.constant.level;
301}
302
303/*
304 * Send set effect report to the device
305 */
306static void pidff_set_effect_report(struct pidff_device *pidff,
307 struct ff_effect *effect)
308{
309 pidff->set_effect[PID_EFFECT_BLOCK_INDEX].value[0] =
310 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
311 pidff->set_effect_type->value[0] =
312 pidff->create_new_effect_type->value[0];
313 pidff->set_effect[PID_DURATION].value[0] = effect->replay.length;
314 pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = effect->trigger.button;
315 pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] =
316 effect->trigger.interval;
317 pidff->set_effect[PID_GAIN].value[0] =
318 pidff->set_effect[PID_GAIN].field->logical_maximum;
319 pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1;
320 pidff->effect_direction->value[0] =
321 pidff_rescale(effect->direction, 0xffff,
322 pidff->effect_direction);
323 pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay;
324
325 hid_submit_report(pidff->hid, pidff->reports[PID_SET_EFFECT],
326 USB_DIR_OUT);
327}
328
329/*
330 * Test if the values used in set_effect have changed
331 */
332static int pidff_needs_set_effect(struct ff_effect *effect,
333 struct ff_effect *old)
334{
335 return effect->replay.length != old->replay.length ||
336 effect->trigger.interval != old->trigger.interval ||
337 effect->trigger.button != old->trigger.button ||
338 effect->direction != old->direction ||
339 effect->replay.delay != old->replay.delay;
340}
341
342/*
343 * Send periodic effect report to the device
344 */
345static void pidff_set_periodic_report(struct pidff_device *pidff,
346 struct ff_effect *effect)
347{
348 pidff->set_periodic[PID_EFFECT_BLOCK_INDEX].value[0] =
349 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
350 pidff_set_signed(&pidff->set_periodic[PID_MAGNITUDE],
351 effect->u.periodic.magnitude);
352 pidff_set_signed(&pidff->set_periodic[PID_OFFSET],
353 effect->u.periodic.offset);
354 pidff_set(&pidff->set_periodic[PID_PHASE], effect->u.periodic.phase);
355 pidff->set_periodic[PID_PERIOD].value[0] = effect->u.periodic.period;
356
357 hid_submit_report(pidff->hid, pidff->reports[PID_SET_PERIODIC],
358 USB_DIR_OUT);
359
360}
361
362/*
363 * Test if periodic effect parameters have changed
364 */
365static int pidff_needs_set_periodic(struct ff_effect *effect,
366 struct ff_effect *old)
367{
368 return effect->u.periodic.magnitude != old->u.periodic.magnitude ||
369 effect->u.periodic.offset != old->u.periodic.offset ||
370 effect->u.periodic.phase != old->u.periodic.phase ||
371 effect->u.periodic.period != old->u.periodic.period;
372}
373
374/*
375 * Send condition effect reports to the device
376 */
377static void pidff_set_condition_report(struct pidff_device *pidff,
378 struct ff_effect *effect)
379{
380 int i;
381
382 pidff->set_condition[PID_EFFECT_BLOCK_INDEX].value[0] =
383 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
384
385 for (i = 0; i < 2; i++) {
386 pidff->set_condition[PID_PARAM_BLOCK_OFFSET].value[0] = i;
387 pidff_set_signed(&pidff->set_condition[PID_CP_OFFSET],
388 effect->u.condition[i].center);
389 pidff_set_signed(&pidff->set_condition[PID_POS_COEFFICIENT],
390 effect->u.condition[i].right_coeff);
391 pidff_set_signed(&pidff->set_condition[PID_NEG_COEFFICIENT],
392 effect->u.condition[i].left_coeff);
393 pidff_set(&pidff->set_condition[PID_POS_SATURATION],
394 effect->u.condition[i].right_saturation);
395 pidff_set(&pidff->set_condition[PID_NEG_SATURATION],
396 effect->u.condition[i].left_saturation);
397 pidff_set(&pidff->set_condition[PID_DEAD_BAND],
398 effect->u.condition[i].deadband);
399 hid_wait_io(pidff->hid);
400 hid_submit_report(pidff->hid, pidff->reports[PID_SET_CONDITION],
401 USB_DIR_OUT);
402 }
403}
404
405/*
406 * Test if condition effect parameters have changed
407 */
408static int pidff_needs_set_condition(struct ff_effect *effect,
409 struct ff_effect *old)
410{
411 int i;
412 int ret = 0;
413
414 for (i = 0; i < 2; i++) {
415 struct ff_condition_effect *cond = &effect->u.condition[i];
416 struct ff_condition_effect *old_cond = &old->u.condition[i];
417
418 ret |= cond->center != old_cond->center ||
419 cond->right_coeff != old_cond->right_coeff ||
420 cond->left_coeff != old_cond->left_coeff ||
421 cond->right_saturation != old_cond->right_saturation ||
422 cond->left_saturation != old_cond->left_saturation ||
423 cond->deadband != old_cond->deadband;
424 }
425
426 return ret;
427}
428
429/*
430 * Send ramp force report to the device
431 */
432static void pidff_set_ramp_force_report(struct pidff_device *pidff,
433 struct ff_effect *effect)
434{
435 pidff->set_ramp[PID_EFFECT_BLOCK_INDEX].value[0] =
436 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
437 pidff_set_signed(&pidff->set_ramp[PID_RAMP_START],
438 effect->u.ramp.start_level);
439 pidff_set_signed(&pidff->set_ramp[PID_RAMP_END],
440 effect->u.ramp.end_level);
441 hid_submit_report(pidff->hid, pidff->reports[PID_SET_RAMP],
442 USB_DIR_OUT);
443}
444
445/*
446 * Test if ramp force parameters have changed
447 */
448static int pidff_needs_set_ramp(struct ff_effect *effect, struct ff_effect *old)
449{
450 return effect->u.ramp.start_level != old->u.ramp.start_level ||
451 effect->u.ramp.end_level != old->u.ramp.end_level;
452}
453
454/*
455 * Send a request for effect upload to the device
456 *
457 * Returns 0 if device reported success, -ENOSPC if the device reported memory
458 * is full. Upon unknown response the function will retry for 60 times, if
459 * still unsuccessful -EIO is returned.
460 */
461static int pidff_request_effect_upload(struct pidff_device *pidff, int efnum)
462{
463 int j;
464
465 pidff->create_new_effect_type->value[0] = efnum;
466 hid_submit_report(pidff->hid, pidff->reports[PID_CREATE_NEW_EFFECT],
467 USB_DIR_OUT);
468 debug("create_new_effect sent, type: %d", efnum);
469
470 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] = 0;
471 pidff->block_load_status->value[0] = 0;
472 hid_wait_io(pidff->hid);
473
474 for (j = 0; j < 60; j++) {
475 debug("pid_block_load requested");
476 hid_submit_report(pidff->hid, pidff->reports[PID_BLOCK_LOAD],
477 USB_DIR_IN);
478 hid_wait_io(pidff->hid);
479 if (pidff->block_load_status->value[0] ==
480 pidff->status_id[PID_BLOCK_LOAD_SUCCESS]) {
481 debug("device reported free memory: %d bytes",
482 pidff->block_load[PID_RAM_POOL_AVAILABLE].value ?
483 pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1);
484 return 0;
485 }
486 if (pidff->block_load_status->value[0] ==
487 pidff->status_id[PID_BLOCK_LOAD_FULL]) {
488 debug("not enough memory free: %d bytes",
489 pidff->block_load[PID_RAM_POOL_AVAILABLE].value ?
490 pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1);
491 return -ENOSPC;
492 }
493 }
494 printk(KERN_ERR "hid-pidff: pid_block_load failed 60 times\n");
495 return -EIO;
496}
497
498/*
499 * Play the effect with PID id n times
500 */
501static void pidff_playback_pid(struct pidff_device *pidff, int pid_id, int n)
502{
503 pidff->effect_operation[PID_EFFECT_BLOCK_INDEX].value[0] = pid_id;
504
505 if (n == 0) {
506 pidff->effect_operation_status->value[0] =
507 pidff->operation_id[PID_EFFECT_STOP];
508 } else {
509 pidff->effect_operation_status->value[0] =
510 pidff->operation_id[PID_EFFECT_START];
511 pidff->effect_operation[PID_LOOP_COUNT].value[0] = n;
512 }
513
514 hid_wait_io(pidff->hid);
515 hid_submit_report(pidff->hid, pidff->reports[PID_EFFECT_OPERATION],
516 USB_DIR_OUT);
517}
518
519/**
520 * Play the effect with effect id @effect_id for @value times
521 */
522static int pidff_playback(struct input_dev *dev, int effect_id, int value)
523{
524 struct pidff_device *pidff = dev->ff->private;
525
526 pidff_playback_pid(pidff, pidff->pid_id[effect_id], value);
527
528 return 0;
529}
530
531/*
532 * Erase effect with PID id
533 */
534static void pidff_erase_pid(struct pidff_device *pidff, int pid_id)
535{
536 pidff->block_free[PID_EFFECT_BLOCK_INDEX].value[0] = pid_id;
537 hid_submit_report(pidff->hid, pidff->reports[PID_BLOCK_FREE],
538 USB_DIR_OUT);
539}
540
541/*
542 * Stop and erase effect with effect_id
543 */
544static int pidff_erase_effect(struct input_dev *dev, int effect_id)
545{
546 struct pidff_device *pidff = dev->ff->private;
547 int pid_id = pidff->pid_id[effect_id];
548
549 debug("starting to erase %d/%d", effect_id, pidff->pid_id[effect_id]);
550 pidff_playback_pid(pidff, pid_id, 0);
551 pidff_erase_pid(pidff, pid_id);
552
553 return 0;
554}
555
556/*
557 * Effect upload handler
558 */
559static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect,
560 struct ff_effect *old)
561{
562 struct pidff_device *pidff = dev->ff->private;
563 int type_id;
564 int error;
565
566 switch (effect->type) {
567 case FF_CONSTANT:
568 if (!old) {
569 error = pidff_request_effect_upload(pidff,
570 pidff->type_id[PID_CONSTANT]);
571 if (error)
572 return error;
573 }
574 if (!old || pidff_needs_set_effect(effect, old))
575 pidff_set_effect_report(pidff, effect);
576 if (!old || pidff_needs_set_constant(effect, old))
577 pidff_set_constant_force_report(pidff, effect);
578 if (!old ||
579 pidff_needs_set_envelope(&effect->u.constant.envelope,
580 &old->u.constant.envelope))
581 pidff_set_envelope_report(pidff,
582 &effect->u.constant.envelope);
583 break;
584
585 case FF_PERIODIC:
586 if (!old) {
587 switch (effect->u.periodic.waveform) {
588 case FF_SQUARE:
589 type_id = PID_SQUARE;
590 break;
591 case FF_TRIANGLE:
592 type_id = PID_TRIANGLE;
593 break;
594 case FF_SINE:
595 type_id = PID_SINE;
596 break;
597 case FF_SAW_UP:
598 type_id = PID_SAW_UP;
599 break;
600 case FF_SAW_DOWN:
601 type_id = PID_SAW_DOWN;
602 break;
603 default:
604 printk(KERN_ERR
605 "hid-pidff: invalid waveform\n");
606 return -EINVAL;
607 }
608
609 error = pidff_request_effect_upload(pidff,
610 pidff->type_id[type_id]);
611 if (error)
612 return error;
613 }
614 if (!old || pidff_needs_set_effect(effect, old))
615 pidff_set_effect_report(pidff, effect);
616 if (!old || pidff_needs_set_periodic(effect, old))
617 pidff_set_periodic_report(pidff, effect);
618 if (!old ||
619 pidff_needs_set_envelope(&effect->u.periodic.envelope,
620 &old->u.periodic.envelope))
621 pidff_set_envelope_report(pidff,
622 &effect->u.periodic.envelope);
623 break;
624
625 case FF_RAMP:
626 if (!old) {
627 error = pidff_request_effect_upload(pidff,
628 pidff->type_id[PID_RAMP]);
629 if (error)
630 return error;
631 }
632 if (!old || pidff_needs_set_effect(effect, old))
633 pidff_set_effect_report(pidff, effect);
634 if (!old || pidff_needs_set_ramp(effect, old))
635 pidff_set_ramp_force_report(pidff, effect);
636 if (!old ||
637 pidff_needs_set_envelope(&effect->u.ramp.envelope,
638 &old->u.ramp.envelope))
639 pidff_set_envelope_report(pidff,
640 &effect->u.ramp.envelope);
641 break;
642
643 case FF_SPRING:
644 if (!old) {
645 error = pidff_request_effect_upload(pidff,
646 pidff->type_id[PID_SPRING]);
647 if (error)
648 return error;
649 }
650 if (!old || pidff_needs_set_effect(effect, old))
651 pidff_set_effect_report(pidff, effect);
652 if (!old || pidff_needs_set_condition(effect, old))
653 pidff_set_condition_report(pidff, effect);
654 break;
655
656 case FF_FRICTION:
657 if (!old) {
658 error = pidff_request_effect_upload(pidff,
659 pidff->type_id[PID_FRICTION]);
660 if (error)
661 return error;
662 }
663 if (!old || pidff_needs_set_effect(effect, old))
664 pidff_set_effect_report(pidff, effect);
665 if (!old || pidff_needs_set_condition(effect, old))
666 pidff_set_condition_report(pidff, effect);
667 break;
668
669 case FF_DAMPER:
670 if (!old) {
671 error = pidff_request_effect_upload(pidff,
672 pidff->type_id[PID_DAMPER]);
673 if (error)
674 return error;
675 }
676 if (!old || pidff_needs_set_effect(effect, old))
677 pidff_set_effect_report(pidff, effect);
678 if (!old || pidff_needs_set_condition(effect, old))
679 pidff_set_condition_report(pidff, effect);
680 break;
681
682 case FF_INERTIA:
683 if (!old) {
684 error = pidff_request_effect_upload(pidff,
685 pidff->type_id[PID_INERTIA]);
686 if (error)
687 return error;
688 }
689 if (!old || pidff_needs_set_effect(effect, old))
690 pidff_set_effect_report(pidff, effect);
691 if (!old || pidff_needs_set_condition(effect, old))
692 pidff_set_condition_report(pidff, effect);
693 break;
694
695 default:
696 printk(KERN_ERR "hid-pidff: invalid type\n");
697 return -EINVAL;
698 }
699
700 if (!old)
701 pidff->pid_id[effect->id] =
702 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
703
704 debug("uploaded");
705
706 return 0;
707}
708
709/*
710 * set_gain() handler
711 */
712static void pidff_set_gain(struct input_dev *dev, u16 gain)
713{
714 struct pidff_device *pidff = dev->ff->private;
715
716 pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], gain);
717 hid_submit_report(pidff->hid, pidff->reports[PID_DEVICE_GAIN],
718 USB_DIR_OUT);
719}
720
721static void pidff_autocenter(struct pidff_device *pidff, u16 magnitude)
722{
723 struct hid_field *field =
724 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field;
725
726 if (!magnitude) {
727 pidff_playback_pid(pidff, field->logical_minimum, 0);
728 return;
729 }
730
731 pidff_playback_pid(pidff, field->logical_minimum, 1);
732
733 pidff->set_effect[PID_EFFECT_BLOCK_INDEX].value[0] =
734 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum;
735 pidff->set_effect_type->value[0] = pidff->type_id[PID_SPRING];
736 pidff->set_effect[PID_DURATION].value[0] = 0;
737 pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = 0;
738 pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] = 0;
739 pidff_set(&pidff->set_effect[PID_GAIN], magnitude);
740 pidff->set_effect[PID_START_DELAY].value[0] = 0;
741
742 hid_submit_report(pidff->hid, pidff->reports[PID_SET_EFFECT],
743 USB_DIR_OUT);
744}
745
746/*
747 * pidff_set_autocenter() handler
748 */
749static void pidff_set_autocenter(struct input_dev *dev, u16 magnitude)
750{
751 struct pidff_device *pidff = dev->ff->private;
752
753 pidff_autocenter(pidff, magnitude);
754}
755
756/*
757 * Find fields from a report and fill a pidff_usage
758 */
759static int pidff_find_fields(struct pidff_usage *usage, const u8 *table,
760 struct hid_report *report, int count, int strict)
761{
762 int i, j, k, found;
763
764 for (k = 0; k < count; k++) {
765 found = 0;
766 for (i = 0; i < report->maxfield; i++) {
767 if (report->field[i]->maxusage !=
768 report->field[i]->report_count) {
769 debug("maxusage and report_count do not match, "
770 "skipping");
771 continue;
772 }
773 for (j = 0; j < report->field[i]->maxusage; j++) {
774 if (report->field[i]->usage[j].hid ==
775 (HID_UP_PID | table[k])) {
776 debug("found %d at %d->%d", k, i, j);
777 usage[k].field = report->field[i];
778 usage[k].value =
779 &report->field[i]->value[j];
780 found = 1;
781 break;
782 }
783 }
784 if (found)
785 break;
786 }
787 if (!found && strict) {
788 debug("failed to locate %d", k);
789 return -1;
790 }
791 }
792 return 0;
793}
794
795/*
796 * Return index into pidff_reports for the given usage
797 */
798static int pidff_check_usage(int usage)
799{
800 int i;
801
802 for (i = 0; i < sizeof(pidff_reports); i++)
803 if (usage == (HID_UP_PID | pidff_reports[i]))
804 return i;
805
806 return -1;
807}
808
809/*
810 * Find the reports and fill pidff->reports[]
811 * report_type specifies either OUTPUT or FEATURE reports
812 */
813static void pidff_find_reports(struct hid_device *hid, int report_type,
814 struct pidff_device *pidff)
815{
816 struct hid_report *report;
817 int i, ret;
818
819 list_for_each_entry(report,
820 &hid->report_enum[report_type].report_list, list) {
821 if (report->maxfield < 1)
822 continue;
823 ret = pidff_check_usage(report->field[0]->logical);
824 if (ret != -1) {
825 debug("found usage 0x%02x from field->logical",
826 pidff_reports[ret]);
827 pidff->reports[ret] = report;
828 continue;
829 }
830
831 /*
832 * Sometimes logical collections are stacked to indicate
833 * different usages for the report and the field, in which
834 * case we want the usage of the parent. However, Linux HID
835 * implementation hides this fact, so we have to dig it up
836 * ourselves
837 */
838 i = report->field[0]->usage[0].collection_index;
839 if (i <= 0 ||
840 hid->collection[i - 1].type != HID_COLLECTION_LOGICAL)
841 continue;
842 ret = pidff_check_usage(hid->collection[i - 1].usage);
843 if (ret != -1 && !pidff->reports[ret]) {
844 debug("found usage 0x%02x from collection array",
845 pidff_reports[ret]);
846 pidff->reports[ret] = report;
847 }
848 }
849}
850
851/*
852 * Test if the required reports have been found
853 */
854static int pidff_reports_ok(struct pidff_device *pidff)
855{
856 int i;
857
858 for (i = 0; i <= PID_REQUIRED_REPORTS; i++) {
859 if (!pidff->reports[i]) {
860 debug("%d missing", i);
861 return 0;
862 }
863 }
864
865 return 1;
866}
867
868/*
869 * Find a field with a specific usage within a report
870 */
871static struct hid_field *pidff_find_special_field(struct hid_report *report,
872 int usage, int enforce_min)
873{
874 int i;
875
876 for (i = 0; i < report->maxfield; i++) {
877 if (report->field[i]->logical == (HID_UP_PID | usage) &&
878 report->field[i]->report_count > 0) {
879 if (!enforce_min ||
880 report->field[i]->logical_minimum == 1)
881 return report->field[i];
882 else {
883 printk(KERN_ERR "hid-pidff: logical_minimum "
884 "is not 1 as it should be\n");
885 return NULL;
886 }
887 }
888 }
889 return NULL;
890}
891
892/*
893 * Fill a pidff->*_id struct table
894 */
895static int pidff_find_special_keys(int *keys, struct hid_field *fld,
896 const u8 *usagetable, int count)
897{
898
899 int i, j;
900 int found = 0;
901
902 for (i = 0; i < count; i++) {
903 for (j = 0; j < fld->maxusage; j++) {
904 if (fld->usage[j].hid == (HID_UP_PID | usagetable[i])) {
905 keys[i] = j + 1;
906 found++;
907 break;
908 }
909 }
910 }
911 return found;
912}
913
914#define PIDFF_FIND_SPECIAL_KEYS(keys, field, name) \
915 pidff_find_special_keys(pidff->keys, pidff->field, pidff_ ## name, \
916 sizeof(pidff_ ## name))
917
918/*
919 * Find and check the special fields
920 */
921static int pidff_find_special_fields(struct pidff_device *pidff)
922{
923 debug("finding special fields");
924
925 pidff->create_new_effect_type =
926 pidff_find_special_field(pidff->reports[PID_CREATE_NEW_EFFECT],
927 0x25, 1);
928 pidff->set_effect_type =
929 pidff_find_special_field(pidff->reports[PID_SET_EFFECT],
930 0x25, 1);
931 pidff->effect_direction =
932 pidff_find_special_field(pidff->reports[PID_SET_EFFECT],
933 0x57, 0);
934 pidff->device_control =
935 pidff_find_special_field(pidff->reports[PID_DEVICE_CONTROL],
936 0x96, 1);
937 pidff->block_load_status =
938 pidff_find_special_field(pidff->reports[PID_BLOCK_LOAD],
939 0x8b, 1);
940 pidff->effect_operation_status =
941 pidff_find_special_field(pidff->reports[PID_EFFECT_OPERATION],
942 0x78, 1);
943
944 debug("search done");
945
946 if (!pidff->create_new_effect_type || !pidff->set_effect_type) {
947 printk(KERN_ERR "hid-pidff: effect lists not found\n");
948 return -1;
949 }
950
951 if (!pidff->effect_direction) {
952 printk(KERN_ERR "hid-pidff: direction field not found\n");
953 return -1;
954 }
955
956 if (!pidff->device_control) {
957 printk(KERN_ERR "hid-pidff: device control field not found\n");
958 return -1;
959 }
960
961 if (!pidff->block_load_status) {
962 printk(KERN_ERR
963 "hid-pidff: block load status field not found\n");
964 return -1;
965 }
966
967 if (!pidff->effect_operation_status) {
968 printk(KERN_ERR
969 "hid-pidff: effect operation field not found\n");
970 return -1;
971 }
972
973 pidff_find_special_keys(pidff->control_id, pidff->device_control,
974 pidff_device_control,
975 sizeof(pidff_device_control));
976
977 PIDFF_FIND_SPECIAL_KEYS(control_id, device_control, device_control);
978
979 if (!PIDFF_FIND_SPECIAL_KEYS(type_id, create_new_effect_type,
980 effect_types)) {
981 printk(KERN_ERR "hid-pidff: no effect types found\n");
982 return -1;
983 }
984
985 if (PIDFF_FIND_SPECIAL_KEYS(status_id, block_load_status,
986 block_load_status) !=
987 sizeof(pidff_block_load_status)) {
988 printk(KERN_ERR
989 "hidpidff: block load status identifiers not found\n");
990 return -1;
991 }
992
993 if (PIDFF_FIND_SPECIAL_KEYS(operation_id, effect_operation_status,
994 effect_operation_status) !=
995 sizeof(pidff_effect_operation_status)) {
996 printk(KERN_ERR
997 "hidpidff: effect operation identifiers not found\n");
998 return -1;
999 }
1000
1001 return 0;
1002}
1003
1004/**
1005 * Find the implemented effect types
1006 */
1007static int pidff_find_effects(struct pidff_device *pidff,
1008 struct input_dev *dev)
1009{
1010 int i;
1011
1012 for (i = 0; i < sizeof(pidff_effect_types); i++) {
1013 int pidff_type = pidff->type_id[i];
1014 if (pidff->set_effect_type->usage[pidff_type].hid !=
1015 pidff->create_new_effect_type->usage[pidff_type].hid) {
1016 printk(KERN_ERR "hid-pidff: "
1017 "effect type number %d is invalid\n", i);
1018 return -1;
1019 }
1020 }
1021
1022 if (pidff->type_id[PID_CONSTANT])
1023 set_bit(FF_CONSTANT, dev->ffbit);
1024 if (pidff->type_id[PID_RAMP])
1025 set_bit(FF_RAMP, dev->ffbit);
1026 if (pidff->type_id[PID_SQUARE]) {
1027 set_bit(FF_SQUARE, dev->ffbit);
1028 set_bit(FF_PERIODIC, dev->ffbit);
1029 }
1030 if (pidff->type_id[PID_SINE]) {
1031 set_bit(FF_SINE, dev->ffbit);
1032 set_bit(FF_PERIODIC, dev->ffbit);
1033 }
1034 if (pidff->type_id[PID_TRIANGLE]) {
1035 set_bit(FF_TRIANGLE, dev->ffbit);
1036 set_bit(FF_PERIODIC, dev->ffbit);
1037 }
1038 if (pidff->type_id[PID_SAW_UP]) {
1039 set_bit(FF_SAW_UP, dev->ffbit);
1040 set_bit(FF_PERIODIC, dev->ffbit);
1041 }
1042 if (pidff->type_id[PID_SAW_DOWN]) {
1043 set_bit(FF_SAW_DOWN, dev->ffbit);
1044 set_bit(FF_PERIODIC, dev->ffbit);
1045 }
1046 if (pidff->type_id[PID_SPRING])
1047 set_bit(FF_SPRING, dev->ffbit);
1048 if (pidff->type_id[PID_DAMPER])
1049 set_bit(FF_DAMPER, dev->ffbit);
1050 if (pidff->type_id[PID_INERTIA])
1051 set_bit(FF_INERTIA, dev->ffbit);
1052 if (pidff->type_id[PID_FRICTION])
1053 set_bit(FF_FRICTION, dev->ffbit);
1054
1055 return 0;
1056
1057}
1058
1059#define PIDFF_FIND_FIELDS(name, report, strict) \
1060 pidff_find_fields(pidff->name, pidff_ ## name, \
1061 pidff->reports[report], \
1062 sizeof(pidff_ ## name), strict)
1063
1064/*
1065 * Fill and check the pidff_usages
1066 */
1067static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev)
1068{
1069 int envelope_ok = 0;
1070
1071 if (PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1)) {
1072 printk(KERN_ERR
1073 "hid-pidff: unknown set_effect report layout\n");
1074 return -ENODEV;
1075 }
1076
1077 PIDFF_FIND_FIELDS(block_load, PID_BLOCK_LOAD, 0);
1078 if (!pidff->block_load[PID_EFFECT_BLOCK_INDEX].value) {
1079 printk(KERN_ERR
1080 "hid-pidff: unknown pid_block_load report layout\n");
1081 return -ENODEV;
1082 }
1083
1084 if (PIDFF_FIND_FIELDS(effect_operation, PID_EFFECT_OPERATION, 1)) {
1085 printk(KERN_ERR
1086 "hid-pidff: unknown effect_operation report layout\n");
1087 return -ENODEV;
1088 }
1089
1090 if (PIDFF_FIND_FIELDS(block_free, PID_BLOCK_FREE, 1)) {
1091 printk(KERN_ERR
1092 "hid-pidff: unknown pid_block_free report layout\n");
1093 return -ENODEV;
1094 }
1095
1096 if (!PIDFF_FIND_FIELDS(set_envelope, PID_SET_ENVELOPE, 1))
1097 envelope_ok = 1;
1098
1099 if (pidff_find_special_fields(pidff) || pidff_find_effects(pidff, dev))
1100 return -ENODEV;
1101
1102 if (!envelope_ok) {
1103 if (test_and_clear_bit(FF_CONSTANT, dev->ffbit))
1104 printk(KERN_WARNING "hid-pidff: "
1105 "has constant effect but no envelope\n");
1106 if (test_and_clear_bit(FF_RAMP, dev->ffbit))
1107 printk(KERN_WARNING "hid-pidff: "
1108 "has ramp effect but no envelope\n");
1109
1110 if (test_and_clear_bit(FF_PERIODIC, dev->ffbit))
1111 printk(KERN_WARNING "hid-pidff: "
1112 "has periodic effect but no envelope\n");
1113 }
1114
1115 if (test_bit(FF_CONSTANT, dev->ffbit) &&
1116 PIDFF_FIND_FIELDS(set_constant, PID_SET_CONSTANT, 1)) {
1117 printk(KERN_WARNING
1118 "hid-pidff: unknown constant effect layout\n");
1119 clear_bit(FF_CONSTANT, dev->ffbit);
1120 }
1121
1122 if (test_bit(FF_RAMP, dev->ffbit) &&
1123 PIDFF_FIND_FIELDS(set_ramp, PID_SET_RAMP, 1)) {
1124 printk(KERN_WARNING "hid-pidff: unknown ramp effect layout\n");
1125 clear_bit(FF_RAMP, dev->ffbit);
1126 }
1127
1128 if ((test_bit(FF_SPRING, dev->ffbit) ||
1129 test_bit(FF_DAMPER, dev->ffbit) ||
1130 test_bit(FF_FRICTION, dev->ffbit) ||
1131 test_bit(FF_INERTIA, dev->ffbit)) &&
1132 PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1)) {
1133 printk(KERN_WARNING
1134 "hid-pidff: unknown condition effect layout\n");
1135 clear_bit(FF_SPRING, dev->ffbit);
1136 clear_bit(FF_DAMPER, dev->ffbit);
1137 clear_bit(FF_FRICTION, dev->ffbit);
1138 clear_bit(FF_INERTIA, dev->ffbit);
1139 }
1140
1141 if (test_bit(FF_PERIODIC, dev->ffbit) &&
1142 PIDFF_FIND_FIELDS(set_periodic, PID_SET_PERIODIC, 1)) {
1143 printk(KERN_WARNING
1144 "hid-pidff: unknown periodic effect layout\n");
1145 clear_bit(FF_PERIODIC, dev->ffbit);
1146 }
1147
1148 PIDFF_FIND_FIELDS(pool, PID_POOL, 0);
1149
1150 if (!PIDFF_FIND_FIELDS(device_gain, PID_DEVICE_GAIN, 1))
1151 set_bit(FF_GAIN, dev->ffbit);
1152
1153 return 0;
1154}
1155
1156/*
1157 * Reset the device
1158 */
1159static void pidff_reset(struct pidff_device *pidff)
1160{
1161 struct hid_device *hid = pidff->hid;
1162 int i = 0;
1163
1164 pidff->device_control->value[0] = pidff->control_id[PID_RESET];
1165 /* We reset twice as sometimes hid_wait_io isn't waiting long enough */
1166 hid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT);
1167 hid_wait_io(hid);
1168 hid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT);
1169 hid_wait_io(hid);
1170
1171 pidff->device_control->value[0] =
1172 pidff->control_id[PID_ENABLE_ACTUATORS];
1173 hid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT);
1174 hid_wait_io(hid);
1175
1176 /* pool report is sometimes messed up, refetch it */
1177 hid_submit_report(hid, pidff->reports[PID_POOL], USB_DIR_IN);
1178 hid_wait_io(hid);
1179
1180 if (pidff->pool[PID_SIMULTANEOUS_MAX].value) {
1181 int sim_effects = pidff->pool[PID_SIMULTANEOUS_MAX].value[0];
1182 while (sim_effects < 2) {
1183 if (i++ > 20) {
1184 printk(KERN_WARNING "hid-pidff: device reports "
1185 "%d simultaneous effects\n",
1186 sim_effects);
1187 break;
1188 }
1189 debug("pid_pool requested again");
1190 hid_submit_report(hid, pidff->reports[PID_POOL],
1191 USB_DIR_IN);
1192 hid_wait_io(hid);
1193 }
1194 }
1195}
1196
1197/*
1198 * Test if autocenter modification is using the supported method
1199 */
1200static int pidff_check_autocenter(struct pidff_device *pidff,
1201 struct input_dev *dev)
1202{
1203 int error;
1204
1205 /*
1206 * Let's find out if autocenter modification is supported
1207 * Specification doesn't specify anything, so we request an
1208 * effect upload and cancel it immediately. If the approved
1209 * effect id was one above the minimum, then we assume the first
1210 * effect id is a built-in spring type effect used for autocenter
1211 */
1212
1213 error = pidff_request_effect_upload(pidff, 1);
1214 if (error) {
1215 printk(KERN_ERR "hid-pidff: upload request failed\n");
1216 return error;
1217 }
1218
1219 if (pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] ==
1220 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum + 1) {
1221 pidff_autocenter(pidff, 0xffff);
1222 set_bit(FF_AUTOCENTER, dev->ffbit);
1223 } else {
1224 printk(KERN_NOTICE "hid-pidff: "
1225 "device has unknown autocenter control method\n");
1226 }
1227
1228 pidff_erase_pid(pidff,
1229 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]);
1230
1231 return 0;
1232
1233}
1234
1235/*
1236 * Check if the device is PID and initialize it
1237 */
1238int hid_pidff_init(struct hid_device *hid)
1239{
1240 struct pidff_device *pidff;
1241 struct hid_input *hidinput = list_entry(hid->inputs.next,
1242 struct hid_input, list);
1243 struct input_dev *dev = hidinput->input;
1244 struct ff_device *ff;
1245 int max_effects;
1246 int error;
1247
1248 debug("starting pid init");
1249
1250 if (list_empty(&hid->report_enum[HID_OUTPUT_REPORT].report_list)) {
1251 debug("not a PID device, no output report");
1252 return -ENODEV;
1253 }
1254
1255 pidff = kzalloc(sizeof(*pidff), GFP_KERNEL);
1256 if (!pidff)
1257 return -ENOMEM;
1258
1259 pidff->hid = hid;
1260
1261 pidff_find_reports(hid, HID_OUTPUT_REPORT, pidff);
1262 pidff_find_reports(hid, HID_FEATURE_REPORT, pidff);
1263
1264 if (!pidff_reports_ok(pidff)) {
1265 debug("reports not ok, aborting");
1266 error = -ENODEV;
1267 goto fail;
1268 }
1269
1270 error = pidff_init_fields(pidff, dev);
1271 if (error)
1272 goto fail;
1273
1274 pidff_reset(pidff);
1275
1276 if (test_bit(FF_GAIN, dev->ffbit)) {
1277 pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], 0xffff);
1278 hid_submit_report(pidff->hid, pidff->reports[PID_DEVICE_GAIN],
1279 USB_DIR_OUT);
1280 }
1281
1282 error = pidff_check_autocenter(pidff, dev);
1283 if (error)
1284 goto fail;
1285
1286 max_effects =
1287 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_maximum -
1288 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum +
1289 1;
1290 debug("max effects is %d", max_effects);
1291
1292 if (max_effects > PID_EFFECTS_MAX)
1293 max_effects = PID_EFFECTS_MAX;
1294
1295 if (pidff->pool[PID_SIMULTANEOUS_MAX].value)
1296 debug("max simultaneous effects is %d",
1297 pidff->pool[PID_SIMULTANEOUS_MAX].value[0]);
1298
1299 if (pidff->pool[PID_RAM_POOL_SIZE].value)
1300 debug("device memory size is %d bytes",
1301 pidff->pool[PID_RAM_POOL_SIZE].value[0]);
1302
1303 if (pidff->pool[PID_DEVICE_MANAGED_POOL].value &&
1304 pidff->pool[PID_DEVICE_MANAGED_POOL].value[0] == 0) {
1305 printk(KERN_NOTICE "hid-pidff: "
1306 "device does not support device managed pool\n");
1307 goto fail;
1308 }
1309
1310 error = input_ff_create(dev, max_effects);
1311 if (error)
1312 goto fail;
1313
1314 ff = dev->ff;
1315 ff->private = pidff;
1316 ff->upload = pidff_upload_effect;
1317 ff->erase = pidff_erase_effect;
1318 ff->set_gain = pidff_set_gain;
1319 ff->set_autocenter = pidff_set_autocenter;
1320 ff->playback = pidff_playback;
1321
1322 printk(KERN_INFO "Force feedback for USB HID PID devices by "
1323 "Anssi Hannula <anssi.hannula@gmail.com>\n");
1324
1325 return 0;
1326
1327 fail:
1328 kfree(pidff);
1329 return error;
1330}
diff --git a/drivers/usb/input/hid-tmff.c b/drivers/usb/input/hid-tmff.c
index 534425c69c0a..2d5be4c318ac 100644
--- a/drivers/usb/input/hid-tmff.c
+++ b/drivers/usb/input/hid-tmff.c
@@ -28,97 +28,65 @@
28 */ 28 */
29 29
30#include <linux/input.h> 30#include <linux/input.h>
31#include <linux/sched.h>
32 31
33#undef DEBUG 32#undef DEBUG
34#include <linux/usb.h> 33#include <linux/usb.h>
35 34
36#include <linux/circ_buf.h>
37
38#include "hid.h" 35#include "hid.h"
39#include "fixp-arith.h"
40 36
41/* Usages for thrustmaster devices I know about */ 37/* Usages for thrustmaster devices I know about */
42#define THRUSTMASTER_USAGE_RUMBLE_LR (HID_UP_GENDESK | 0xbb) 38#define THRUSTMASTER_USAGE_RUMBLE_LR (HID_UP_GENDESK | 0xbb)
43#define DELAY_CALC(t,delay) ((t) + (delay)*HZ/1000)
44
45/* Effect status */
46#define EFFECT_STARTED 0 /* Effect is going to play after some time */
47#define EFFECT_PLAYING 1 /* Effect is playing */
48#define EFFECT_USED 2
49
50/* For tmff_device::flags */
51#define DEVICE_CLOSING 0 /* The driver is being unitialised */
52
53/* Check that the current process can access an effect */
54#define CHECK_OWNERSHIP(effect) (current->pid == 0 \
55 || effect.owner == current->pid)
56
57#define TMFF_CHECK_ID(id) ((id) >= 0 && (id) < TMFF_EFFECTS)
58 39
59#define TMFF_CHECK_OWNERSHIP(i, l) \
60 (test_bit(EFFECT_USED, l->effects[i].flags) \
61 && CHECK_OWNERSHIP(l->effects[i]))
62
63#define TMFF_EFFECTS 8
64
65struct tmff_effect {
66 pid_t owner;
67
68 struct ff_effect effect;
69
70 unsigned long flags[1];
71 unsigned int count; /* Number of times left to play */
72
73 unsigned long play_at; /* When the effect starts to play */
74 unsigned long stop_at; /* When the effect ends */
75};
76 40
77struct tmff_device { 41struct tmff_device {
78 struct hid_device *hid;
79
80 struct hid_report *report; 42 struct hid_report *report;
81
82 struct hid_field *rumble; 43 struct hid_field *rumble;
44};
83 45
84 unsigned int effects_playing; 46/* Changes values from 0 to 0xffff into values from minimum to maximum */
85 struct tmff_effect effects[TMFF_EFFECTS]; 47static inline int hid_tmff_scale(unsigned int in, int minimum, int maximum)
86 spinlock_t lock; /* device-level lock. Having locks on 48{
87 a per-effect basis could be nice, but 49 int ret;
88 isn't really necessary */
89 50
90 unsigned long flags[1]; /* Contains various information about the 51 ret = (in * (maximum - minimum) / 0xffff) + minimum;
91 state of the driver for this device */ 52 if (ret < minimum)
53 return minimum;
54 if (ret > maximum)
55 return maximum;
56 return ret;
57}
92 58
93 struct timer_list timer; 59static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
94}; 60{
61 struct hid_device *hid = dev->private;
62 struct tmff_device *tmff = data;
63 int left, right; /* Rumbling */
95 64
96/* Callbacks */ 65 left = hid_tmff_scale(effect->u.rumble.weak_magnitude,
97static void hid_tmff_exit(struct hid_device *hid); 66 tmff->rumble->logical_minimum, tmff->rumble->logical_maximum);
98static int hid_tmff_event(struct hid_device *hid, struct input_dev *input, 67 right = hid_tmff_scale(effect->u.rumble.strong_magnitude,
99 unsigned int type, unsigned int code, int value); 68 tmff->rumble->logical_minimum, tmff->rumble->logical_maximum);
100static int hid_tmff_flush(struct input_dev *input, struct file *file);
101static int hid_tmff_upload_effect(struct input_dev *input,
102 struct ff_effect *effect);
103static int hid_tmff_erase(struct input_dev *input, int id);
104 69
105/* Local functions */ 70 tmff->rumble->value[0] = left;
106static void hid_tmff_recalculate_timer(struct tmff_device *tmff); 71 tmff->rumble->value[1] = right;
107static void hid_tmff_timer(unsigned long timer_data); 72 dbg("(left,right)=(%08x, %08x)", left, right);
73 hid_submit_report(hid, tmff->report, USB_DIR_OUT);
74
75 return 0;
76}
108 77
109int hid_tmff_init(struct hid_device *hid) 78int hid_tmff_init(struct hid_device *hid)
110{ 79{
111 struct tmff_device *private; 80 struct tmff_device *tmff;
112 struct list_head *pos; 81 struct list_head *pos;
113 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); 82 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
114 struct input_dev *input_dev = hidinput->input; 83 struct input_dev *input_dev = hidinput->input;
84 int error;
115 85
116 private = kzalloc(sizeof(struct tmff_device), GFP_KERNEL); 86 tmff = kzalloc(sizeof(struct tmff_device), GFP_KERNEL);
117 if (!private) 87 if (!tmff)
118 return -ENOMEM; 88 return -ENOMEM;
119 89
120 hid->ff_private = private;
121
122 /* Find the report to use */ 90 /* Find the report to use */
123 __list_for_each(pos, &hid->report_enum[HID_OUTPUT_REPORT].report_list) { 91 __list_for_each(pos, &hid->report_enum[HID_OUTPUT_REPORT].report_list) {
124 struct hid_report *report = (struct hid_report *)pos; 92 struct hid_report *report = (struct hid_report *)pos;
@@ -142,18 +110,18 @@ int hid_tmff_init(struct hid_device *hid)
142 continue; 110 continue;
143 } 111 }
144 112
145 if (private->report && private->report != report) { 113 if (tmff->report && tmff->report != report) {
146 warn("ignoring THRUSTMASTER_USAGE_RUMBLE_LR in other report"); 114 warn("ignoring THRUSTMASTER_USAGE_RUMBLE_LR in other report");
147 continue; 115 continue;
148 } 116 }
149 117
150 if (private->rumble && private->rumble != field) { 118 if (tmff->rumble && tmff->rumble != field) {
151 warn("ignoring duplicate THRUSTMASTER_USAGE_RUMBLE_LR"); 119 warn("ignoring duplicate THRUSTMASTER_USAGE_RUMBLE_LR");
152 continue; 120 continue;
153 } 121 }
154 122
155 private->report = report; 123 tmff->report = report;
156 private->rumble = field; 124 tmff->rumble = field;
157 125
158 set_bit(FF_RUMBLE, input_dev->ffbit); 126 set_bit(FF_RUMBLE, input_dev->ffbit);
159 break; 127 break;
@@ -162,302 +130,17 @@ int hid_tmff_init(struct hid_device *hid)
162 warn("ignoring unknown output usage %08x", field->usage[0].hid); 130 warn("ignoring unknown output usage %08x", field->usage[0].hid);
163 continue; 131 continue;
164 } 132 }
165
166 /* Fallthrough to here only when a valid usage is found */
167 input_dev->upload_effect = hid_tmff_upload_effect;
168 input_dev->flush = hid_tmff_flush;
169
170 set_bit(EV_FF, input_dev->evbit);
171 input_dev->ff_effects_max = TMFF_EFFECTS;
172 } 133 }
173 } 134 }
174 135
175 private->hid = hid; 136 error = input_ff_create_memless(input_dev, tmff, hid_tmff_play);
176 137 if (error) {
177 spin_lock_init(&private->lock); 138 kfree(tmff);
178 init_timer(&private->timer); 139 return error;
179 private->timer.data = (unsigned long)private;
180 private->timer.function = hid_tmff_timer;
181
182 /* Event and exit callbacks */
183 hid->ff_exit = hid_tmff_exit;
184 hid->ff_event = hid_tmff_event;
185
186 info("Force feedback for ThrustMaster rumble pad devices by Zinx Verituse <zinx@epicsol.org>");
187
188 return 0;
189}
190
191static void hid_tmff_exit(struct hid_device *hid)
192{
193 struct tmff_device *tmff = hid->ff_private;
194 unsigned long flags;
195
196 spin_lock_irqsave(&tmff->lock, flags);
197
198 set_bit(DEVICE_CLOSING, tmff->flags);
199 del_timer_sync(&tmff->timer);
200
201 spin_unlock_irqrestore(&tmff->lock, flags);
202
203 kfree(tmff);
204}
205
206static int hid_tmff_event(struct hid_device *hid, struct input_dev *input,
207 unsigned int type, unsigned int code, int value)
208{
209 struct tmff_device *tmff = hid->ff_private;
210 struct tmff_effect *effect = &tmff->effects[code];
211 unsigned long flags;
212
213 if (type != EV_FF)
214 return -EINVAL;
215 if (!TMFF_CHECK_ID(code))
216 return -EINVAL;
217 if (!TMFF_CHECK_OWNERSHIP(code, tmff))
218 return -EACCES;
219 if (value < 0)
220 return -EINVAL;
221
222 spin_lock_irqsave(&tmff->lock, flags);
223
224 if (value > 0) {
225 set_bit(EFFECT_STARTED, effect->flags);
226 clear_bit(EFFECT_PLAYING, effect->flags);
227 effect->count = value;
228 effect->play_at = DELAY_CALC(jiffies, effect->effect.replay.delay);
229 } else {
230 clear_bit(EFFECT_STARTED, effect->flags);
231 clear_bit(EFFECT_PLAYING, effect->flags);
232 }
233
234 hid_tmff_recalculate_timer(tmff);
235
236 spin_unlock_irqrestore(&tmff->lock, flags);
237
238 return 0;
239
240}
241
242/* Erase all effects this process owns */
243
244static int hid_tmff_flush(struct input_dev *dev, struct file *file)
245{
246 struct hid_device *hid = dev->private;
247 struct tmff_device *tmff = hid->ff_private;
248 int i;
249
250 for (i=0; i<dev->ff_effects_max; ++i)
251
252 /* NOTE: no need to lock here. The only times EFFECT_USED is
253 modified is when effects are uploaded or when an effect is
254 erased. But a process cannot close its dev/input/eventX fd
255 and perform ioctls on the same fd all at the same time */
256
257 if (current->pid == tmff->effects[i].owner
258 && test_bit(EFFECT_USED, tmff->effects[i].flags))
259 if (hid_tmff_erase(dev, i))
260 warn("erase effect %d failed", i);
261
262
263 return 0;
264}
265
266static int hid_tmff_erase(struct input_dev *dev, int id)
267{
268 struct hid_device *hid = dev->private;
269 struct tmff_device *tmff = hid->ff_private;
270 unsigned long flags;
271
272 if (!TMFF_CHECK_ID(id))
273 return -EINVAL;
274 if (!TMFF_CHECK_OWNERSHIP(id, tmff))
275 return -EACCES;
276
277 spin_lock_irqsave(&tmff->lock, flags);
278
279 tmff->effects[id].flags[0] = 0;
280 hid_tmff_recalculate_timer(tmff);
281
282 spin_unlock_irqrestore(&tmff->lock, flags);
283
284 return 0;
285}
286
287static int hid_tmff_upload_effect(struct input_dev *input,
288 struct ff_effect *effect)
289{
290 struct hid_device *hid = input->private;
291 struct tmff_device *tmff = hid->ff_private;
292 int id;
293 unsigned long flags;
294
295 if (!test_bit(effect->type, input->ffbit))
296 return -EINVAL;
297 if (effect->id != -1 && !TMFF_CHECK_ID(effect->id))
298 return -EINVAL;
299
300 spin_lock_irqsave(&tmff->lock, flags);
301
302 if (effect->id == -1) {
303 /* Find a free effect */
304 for (id = 0; id < TMFF_EFFECTS && test_bit(EFFECT_USED, tmff->effects[id].flags); ++id);
305
306 if (id >= TMFF_EFFECTS) {
307 spin_unlock_irqrestore(&tmff->lock, flags);
308 return -ENOSPC;
309 }
310
311 effect->id = id;
312 tmff->effects[id].owner = current->pid;
313 tmff->effects[id].flags[0] = 0;
314 set_bit(EFFECT_USED, tmff->effects[id].flags);
315
316 } else {
317 /* Re-uploading an owned effect, to change parameters */
318 id = effect->id;
319 clear_bit(EFFECT_PLAYING, tmff->effects[id].flags);
320 } 140 }
321 141
322 tmff->effects[id].effect = *effect; 142 info("Force feedback for ThrustMaster rumble pad devices by Zinx Verituse <zinx@epicsol.org>");
323
324 hid_tmff_recalculate_timer(tmff);
325 143
326 spin_unlock_irqrestore(&tmff->lock, flags);
327 return 0; 144 return 0;
328} 145}
329 146
330/* Start the timer for the next start/stop/delay */
331/* Always call this while tmff->lock is locked */
332
333static void hid_tmff_recalculate_timer(struct tmff_device *tmff)
334{
335 int i;
336 int events = 0;
337 unsigned long next_time;
338
339 next_time = 0; /* Shut up compiler's incorrect warning */
340
341 /* Find the next change in an effect's status */
342 for (i = 0; i < TMFF_EFFECTS; ++i) {
343 struct tmff_effect *effect = &tmff->effects[i];
344 unsigned long play_time;
345
346 if (!test_bit(EFFECT_STARTED, effect->flags))
347 continue;
348
349 effect->stop_at = DELAY_CALC(effect->play_at, effect->effect.replay.length);
350
351 if (!test_bit(EFFECT_PLAYING, effect->flags))
352 play_time = effect->play_at;
353 else
354 play_time = effect->stop_at;
355
356 events++;
357
358 if (time_after(jiffies, play_time))
359 play_time = jiffies;
360
361 if (events == 1)
362 next_time = play_time;
363 else {
364 if (time_after(next_time, play_time))
365 next_time = play_time;
366 }
367 }
368
369 if (!events && tmff->effects_playing) {
370 /* Treat all effects turning off as an event */
371 events = 1;
372 next_time = jiffies;
373 }
374
375 if (!events) {
376 /* No events, no time, no need for a timer. */
377 del_timer_sync(&tmff->timer);
378 return;
379 }
380
381 mod_timer(&tmff->timer, next_time);
382}
383
384/* Changes values from 0 to 0xffff into values from minimum to maximum */
385static inline int hid_tmff_scale(unsigned int in, int minimum, int maximum)
386{
387 int ret;
388
389 ret = (in * (maximum - minimum) / 0xffff) + minimum;
390 if (ret < minimum)
391 return minimum;
392 if (ret > maximum)
393 return maximum;
394 return ret;
395}
396
397static void hid_tmff_timer(unsigned long timer_data)
398{
399 struct tmff_device *tmff = (struct tmff_device *) timer_data;
400 struct hid_device *hid = tmff->hid;
401 unsigned long flags;
402 int left = 0, right = 0; /* Rumbling */
403 int i;
404
405 spin_lock_irqsave(&tmff->lock, flags);
406
407 tmff->effects_playing = 0;
408
409 for (i = 0; i < TMFF_EFFECTS; ++i) {
410 struct tmff_effect *effect = &tmff->effects[i];
411
412 if (!test_bit(EFFECT_STARTED, effect->flags))
413 continue;
414
415 if (!time_after(jiffies, effect->play_at))
416 continue;
417
418 if (time_after(jiffies, effect->stop_at)) {
419
420 dbg("Finished playing once %d", i);
421 clear_bit(EFFECT_PLAYING, effect->flags);
422
423 if (--effect->count <= 0) {
424 dbg("Stopped %d", i);
425 clear_bit(EFFECT_STARTED, effect->flags);
426 continue;
427 } else {
428 dbg("Start again %d", i);
429 effect->play_at = DELAY_CALC(jiffies, effect->effect.replay.delay);
430 continue;
431 }
432 }
433
434 ++tmff->effects_playing;
435
436 set_bit(EFFECT_PLAYING, effect->flags);
437
438 switch (effect->effect.type) {
439 case FF_RUMBLE:
440 right += effect->effect.u.rumble.strong_magnitude;
441 left += effect->effect.u.rumble.weak_magnitude;
442 break;
443 default:
444 BUG();
445 break;
446 }
447 }
448
449 left = hid_tmff_scale(left, tmff->rumble->logical_minimum, tmff->rumble->logical_maximum);
450 right = hid_tmff_scale(right, tmff->rumble->logical_minimum, tmff->rumble->logical_maximum);
451
452 if (left != tmff->rumble->value[0] || right != tmff->rumble->value[1]) {
453 tmff->rumble->value[0] = left;
454 tmff->rumble->value[1] = right;
455 dbg("(left,right)=(%08x, %08x)", left, right);
456 hid_submit_report(hid, tmff->report, USB_DIR_OUT);
457 }
458
459 if (!test_bit(DEVICE_CLOSING, tmff->flags))
460 hid_tmff_recalculate_timer(tmff);
461
462 spin_unlock_irqrestore(&tmff->lock, flags);
463}
diff --git a/drivers/usb/input/hid-zpff.c b/drivers/usb/input/hid-zpff.c
new file mode 100644
index 000000000000..d2ce3214572c
--- /dev/null
+++ b/drivers/usb/input/hid-zpff.c
@@ -0,0 +1,110 @@
1/*
2 * Force feedback support for Zeroplus based devices
3 *
4 * Copyright (c) 2005, 2006 Anssi Hannula <anssi.hannula@gmail.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
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23
24/* #define DEBUG */
25
26#define debug(format, arg...) pr_debug("hid-zpff: " format "\n" , ## arg)
27
28#include <linux/input.h>
29#include <linux/usb.h>
30#include "hid.h"
31
32struct zpff_device {
33 struct hid_report *report;
34};
35
36static int hid_zpff_play(struct input_dev *dev, void *data,
37 struct ff_effect *effect)
38{
39 struct hid_device *hid = dev->private;
40 struct zpff_device *zpff = data;
41 int left, right;
42
43 /*
44 * The following is specified the other way around in the Zeroplus
45 * datasheet but the order below is correct for the XFX Executioner;
46 * however it is possible that the XFX Executioner is an exception
47 */
48
49 left = effect->u.rumble.strong_magnitude;
50 right = effect->u.rumble.weak_magnitude;
51 debug("called with 0x%04x 0x%04x", left, right);
52
53 left = left * 0x7f / 0xffff;
54 right = right * 0x7f / 0xffff;
55
56 zpff->report->field[2]->value[0] = left;
57 zpff->report->field[3]->value[0] = right;
58 debug("running with 0x%02x 0x%02x", left, right);
59 hid_submit_report(hid, zpff->report, USB_DIR_OUT);
60
61 return 0;
62}
63
64int hid_zpff_init(struct hid_device *hid)
65{
66 struct zpff_device *zpff;
67 struct hid_report *report;
68 struct hid_input *hidinput = list_entry(hid->inputs.next,
69 struct hid_input, list);
70 struct list_head *report_list =
71 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
72 struct input_dev *dev = hidinput->input;
73 int error;
74
75 if (list_empty(report_list)) {
76 printk(KERN_ERR "hid-zpff: no output report found\n");
77 return -ENODEV;
78 }
79
80 report = list_entry(report_list->next, struct hid_report, list);
81
82 if (report->maxfield < 4) {
83 printk(KERN_ERR "hid-zpff: not enough fields in report\n");
84 return -ENODEV;
85 }
86
87 zpff = kzalloc(sizeof(struct zpff_device), GFP_KERNEL);
88 if (!zpff)
89 return -ENOMEM;
90
91 set_bit(FF_RUMBLE, dev->ffbit);
92
93 error = input_ff_create_memless(dev, zpff, hid_zpff_play);
94 if (error) {
95 kfree(zpff);
96 return error;
97 }
98
99 zpff->report = report;
100 zpff->report->field[0]->value[0] = 0x00;
101 zpff->report->field[1]->value[0] = 0x02;
102 zpff->report->field[2]->value[0] = 0x00;
103 zpff->report->field[3]->value[0] = 0x00;
104 hid_submit_report(hid, zpff->report, USB_DIR_OUT);
105
106 printk(KERN_INFO "Force feedback for Zeroplus based devices by "
107 "Anssi Hannula <anssi.hannula@gmail.com>\n");
108
109 return 0;
110}
diff --git a/drivers/usb/input/hid.h b/drivers/usb/input/hid.h
index 778e575de352..b03fd9b075df 100644
--- a/drivers/usb/input/hid.h
+++ b/drivers/usb/input/hid.h
@@ -449,11 +449,6 @@ struct hid_device { /* device report descriptor */
449 char phys[64]; /* Device physical location */ 449 char phys[64]; /* Device physical location */
450 char uniq[64]; /* Device unique identifier (serial #) */ 450 char uniq[64]; /* Device unique identifier (serial #) */
451 451
452 void *ff_private; /* Private data for the force-feedback driver */
453 void (*ff_exit)(struct hid_device*); /* Called by hid_exit_ff(hid) */
454 int (*ff_event)(struct hid_device *hid, struct input_dev *input,
455 unsigned int type, unsigned int code, int value);
456
457#ifdef CONFIG_USB_HIDINPUT_POWERBOOK 452#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
458 unsigned long pb_pressed_fn[NBITS(KEY_MAX)]; 453 unsigned long pb_pressed_fn[NBITS(KEY_MAX)];
459 unsigned long pb_pressed_numlock[NBITS(KEY_MAX)]; 454 unsigned long pb_pressed_numlock[NBITS(KEY_MAX)];
@@ -521,29 +516,22 @@ void hid_close(struct hid_device *);
521int hid_set_field(struct hid_field *, unsigned, __s32); 516int hid_set_field(struct hid_field *, unsigned, __s32);
522void hid_submit_report(struct hid_device *, struct hid_report *, unsigned char dir); 517void hid_submit_report(struct hid_device *, struct hid_report *, unsigned char dir);
523void hid_init_reports(struct hid_device *hid); 518void hid_init_reports(struct hid_device *hid);
524struct hid_field *hid_find_field_by_usage(struct hid_device *hid, __u32 wanted_usage, int type);
525int hid_wait_io(struct hid_device* hid); 519int hid_wait_io(struct hid_device* hid);
526 520
527 521
528#ifdef CONFIG_HID_FF 522#ifdef CONFIG_HID_FF
529int hid_ff_init(struct hid_device *hid); 523int hid_ff_init(struct hid_device *hid);
524
525int hid_lgff_init(struct hid_device *hid);
526int hid_tmff_init(struct hid_device *hid);
527int hid_zpff_init(struct hid_device *hid);
528#ifdef CONFIG_HID_PID
529int hid_pidff_init(struct hid_device *hid);
530#else
531static inline int hid_pidff_init(struct hid_device *hid) { return -ENODEV; }
532#endif
533
530#else 534#else
531static inline int hid_ff_init(struct hid_device *hid) { return -1; } 535static inline int hid_ff_init(struct hid_device *hid) { return -1; }
532#endif 536#endif
533static inline void hid_ff_exit(struct hid_device *hid)
534{
535 if (hid->ff_exit)
536 hid->ff_exit(hid);
537}
538static inline int hid_ff_event(struct hid_device *hid, struct input_dev *input,
539 unsigned int type, unsigned int code, int value)
540{
541 if (hid->ff_event)
542 return hid->ff_event(hid, input, type, code, value);
543 return -ENOSYS;
544}
545
546int hid_lgff_init(struct hid_device* hid);
547int hid_tmff_init(struct hid_device* hid);
548int hid_pid_init(struct hid_device* hid);
549 537
diff --git a/drivers/usb/input/hiddev.c b/drivers/usb/input/hiddev.c
index f6b839c257a7..a2b419d13740 100644
--- a/drivers/usb/input/hiddev.c
+++ b/drivers/usb/input/hiddev.c
@@ -722,7 +722,7 @@ inval:
722 return -EINVAL; 722 return -EINVAL;
723} 723}
724 724
725static struct file_operations hiddev_fops = { 725static const struct file_operations hiddev_fops = {
726 .owner = THIS_MODULE, 726 .owner = THIS_MODULE,
727 .read = hiddev_read, 727 .read = hiddev_read,
728 .write = hiddev_write, 728 .write = hiddev_write,
diff --git a/drivers/usb/input/itmtouch.c b/drivers/usb/input/itmtouch.c
index 86acb5f1907a..61966d719ca3 100644
--- a/drivers/usb/input/itmtouch.c
+++ b/drivers/usb/input/itmtouch.c
@@ -87,7 +87,7 @@ static void itmtouch_irq(struct urb *urb, struct pt_regs *regs)
87 case 0: 87 case 0:
88 /* success */ 88 /* success */
89 break; 89 break;
90 case -ETIMEDOUT: 90 case -ETIME:
91 /* this urb is timing out */ 91 /* this urb is timing out */
92 dbg("%s - urb timed out - was the device unplugged?", 92 dbg("%s - urb timed out - was the device unplugged?",
93 __FUNCTION__); 93 __FUNCTION__);
diff --git a/drivers/usb/input/keyspan_remote.c b/drivers/usb/input/keyspan_remote.c
index 4723b310f277..a90359551575 100644
--- a/drivers/usb/input/keyspan_remote.c
+++ b/drivers/usb/input/keyspan_remote.c
@@ -420,8 +420,7 @@ static struct usb_endpoint_descriptor *keyspan_get_in_endpoint(struct usb_host_i
420 for (i = 0; i < iface->desc.bNumEndpoints; ++i) { 420 for (i = 0; i < iface->desc.bNumEndpoints; ++i) {
421 endpoint = &iface->endpoint[i].desc; 421 endpoint = &iface->endpoint[i].desc;
422 422
423 if ((endpoint->bEndpointAddress & USB_DIR_IN) && 423 if (usb_endpoint_is_int_in(endpoint)) {
424 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
425 /* we found our interrupt in endpoint */ 424 /* we found our interrupt in endpoint */
426 return endpoint; 425 return endpoint;
427 } 426 }
diff --git a/drivers/usb/input/mtouchusb.c b/drivers/usb/input/mtouchusb.c
index a9ccda8810e0..5dce951f2751 100644
--- a/drivers/usb/input/mtouchusb.c
+++ b/drivers/usb/input/mtouchusb.c
@@ -107,7 +107,7 @@ static void mtouchusb_irq(struct urb *urb, struct pt_regs *regs)
107 case 0: 107 case 0:
108 /* success */ 108 /* success */
109 break; 109 break;
110 case -ETIMEDOUT: 110 case -ETIME:
111 /* this urb is timing out */ 111 /* this urb is timing out */
112 dbg("%s - urb timed out - was the device unplugged?", 112 dbg("%s - urb timed out - was the device unplugged?",
113 __FUNCTION__); 113 __FUNCTION__);
diff --git a/drivers/usb/input/pid.c b/drivers/usb/input/pid.c
deleted file mode 100644
index d9d9f656b8c9..000000000000
--- a/drivers/usb/input/pid.c
+++ /dev/null
@@ -1,295 +0,0 @@
1/*
2 * PID Force feedback support for hid devices.
3 *
4 * Copyright (c) 2002 Rodrigo Damazio.
5 * Portions by Johann Deneux and Bjorn Augustson
6 */
7
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 * Should you need to contact me, the author, you can do so by
24 * e-mail - mail your message to <rdamazio@lsi.usp.br>
25 */
26
27#include <linux/config.h>
28#include <linux/module.h>
29#include <linux/slab.h>
30#include <linux/kernel.h>
31#include <linux/init.h>
32#include <linux/mm.h>
33#include <linux/smp_lock.h>
34#include <linux/spinlock.h>
35#include <linux/input.h>
36#include <linux/usb.h>
37#include "hid.h"
38#include "pid.h"
39
40#define CHECK_OWNERSHIP(i, hid_pid) \
41 ((i) < FF_EFFECTS_MAX && i >= 0 && \
42 test_bit(FF_PID_FLAGS_USED, &hid_pid->effects[(i)].flags) && \
43 (current->pid == 0 || \
44 (hid_pid)->effects[(i)].owner == current->pid))
45
46/* Called when a transfer is completed */
47static void hid_pid_ctrl_out(struct urb *u, struct pt_regs *regs)
48{
49 dev_dbg(&u->dev->dev, "hid_pid_ctrl_out - Transfer Completed\n");
50}
51
52static void hid_pid_exit(struct hid_device *hid)
53{
54 struct hid_ff_pid *private = hid->ff_private;
55
56 if (private->urbffout) {
57 usb_kill_urb(private->urbffout);
58 usb_free_urb(private->urbffout);
59 }
60}
61
62static int pid_upload_periodic(struct hid_ff_pid *pid, struct ff_effect *effect, int is_update)
63{
64 dev_info(&pid->hid->dev->dev, "requested periodic force upload\n");
65 return 0;
66}
67
68static int pid_upload_constant(struct hid_ff_pid *pid, struct ff_effect *effect, int is_update)
69{
70 dev_info(&pid->hid->dev->dev, "requested constant force upload\n");
71 return 0;
72}
73
74static int pid_upload_condition(struct hid_ff_pid *pid, struct ff_effect *effect, int is_update)
75{
76 dev_info(&pid->hid->dev->dev, "requested Condition force upload\n");
77 return 0;
78}
79
80static int pid_upload_ramp(struct hid_ff_pid *pid, struct ff_effect *effect, int is_update)
81{
82 dev_info(&pid->hid->dev->dev, "request ramp force upload\n");
83 return 0;
84}
85
86static int hid_pid_event(struct hid_device *hid, struct input_dev *input,
87 unsigned int type, unsigned int code, int value)
88{
89 dev_dbg(&hid->dev->dev, "PID event received: type=%d,code=%d,value=%d.\n", type, code, value);
90
91 if (type != EV_FF)
92 return -1;
93
94 return 0;
95}
96
97/* Lock must be held by caller */
98static void hid_pid_ctrl_playback(struct hid_device *hid, struct hid_pid_effect *effect, int play)
99{
100 if (play)
101 set_bit(FF_PID_FLAGS_PLAYING, &effect->flags);
102 else
103 clear_bit(FF_PID_FLAGS_PLAYING, &effect->flags);
104}
105
106static int hid_pid_erase(struct input_dev *dev, int id)
107{
108 struct hid_device *hid = dev->private;
109 struct hid_ff_pid *pid = hid->ff_private;
110 struct hid_field *field;
111 unsigned long flags;
112 int ret;
113
114 if (!CHECK_OWNERSHIP(id, pid))
115 return -EACCES;
116
117 /* Find report */
118 field = hid_find_field_by_usage(hid, HID_UP_PID | FF_PID_USAGE_BLOCK_FREE,
119 HID_OUTPUT_REPORT);
120 if (!field) {
121 dev_err(&hid->dev->dev, "couldn't find report\n");
122 return -EIO;
123 }
124
125 ret = hid_set_field(field, 0, pid->effects[id].device_id);
126 if (ret) {
127 dev_err(&hid->dev->dev, "couldn't set field\n");
128 return ret;
129 }
130
131 hid_submit_report(hid, field->report, USB_DIR_OUT);
132
133 spin_lock_irqsave(&pid->lock, flags);
134 hid_pid_ctrl_playback(hid, pid->effects + id, 0);
135 pid->effects[id].flags = 0;
136 spin_unlock_irqrestore(&pid->lock, flags);
137
138 return 0;
139}
140
141/* Erase all effects this process owns */
142static int hid_pid_flush(struct input_dev *dev, struct file *file)
143{
144 struct hid_device *hid = dev->private;
145 struct hid_ff_pid *pid = hid->ff_private;
146 int i;
147
148 /*NOTE: no need to lock here. The only times EFFECT_USED is
149 modified is when effects are uploaded or when an effect is
150 erased. But a process cannot close its dev/input/eventX fd
151 and perform ioctls on the same fd all at the same time */
152 /*FIXME: multiple threads, anyone? */
153 for (i = 0; i < dev->ff_effects_max; ++i)
154 if (current->pid == pid->effects[i].owner
155 && test_bit(FF_PID_FLAGS_USED, &pid->effects[i].flags))
156 if (hid_pid_erase(dev, i))
157 dev_warn(&hid->dev->dev, "erase effect %d failed", i);
158
159 return 0;
160}
161
162static int hid_pid_upload_effect(struct input_dev *dev,
163 struct ff_effect *effect)
164{
165 struct hid_ff_pid *pid_private = (struct hid_ff_pid *)(dev->private);
166 int ret;
167 int is_update;
168 unsigned long flags;
169
170 dev_dbg(&pid_private->hid->dev->dev, "upload effect called: effect_type=%x\n", effect->type);
171 /* Check this effect type is supported by this device */
172 if (!test_bit(effect->type, dev->ffbit)) {
173 dev_dbg(&pid_private->hid->dev->dev,
174 "invalid kind of effect requested.\n");
175 return -EINVAL;
176 }
177
178 /*
179 * If we want to create a new effect, get a free id
180 */
181 if (effect->id == -1) {
182 int id = 0;
183
184 // Spinlock so we don`t get a race condition when choosing IDs
185 spin_lock_irqsave(&pid_private->lock, flags);
186
187 while (id < FF_EFFECTS_MAX)
188 if (!test_and_set_bit(FF_PID_FLAGS_USED, &pid_private->effects[id++].flags))
189 break;
190
191 if (id == FF_EFFECTS_MAX) {
192 spin_unlock_irqrestore(&pid_private->lock, flags);
193// TEMP - We need to get ff_effects_max correctly first: || id >= dev->ff_effects_max) {
194 dev_dbg(&pid_private->hid->dev->dev, "Not enough device memory\n");
195 return -ENOMEM;
196 }
197
198 effect->id = id;
199 dev_dbg(&pid_private->hid->dev->dev, "effect ID is %d.\n", id);
200 pid_private->effects[id].owner = current->pid;
201 pid_private->effects[id].flags = (1 << FF_PID_FLAGS_USED);
202 spin_unlock_irqrestore(&pid_private->lock, flags);
203
204 is_update = FF_PID_FALSE;
205 } else {
206 /* We want to update an effect */
207 if (!CHECK_OWNERSHIP(effect->id, pid_private))
208 return -EACCES;
209
210 /* Parameter type cannot be updated */
211 if (effect->type != pid_private->effects[effect->id].effect.type)
212 return -EINVAL;
213
214 /* Check the effect is not already being updated */
215 if (test_bit(FF_PID_FLAGS_UPDATING, &pid_private->effects[effect->id].flags))
216 return -EAGAIN;
217
218 is_update = FF_PID_TRUE;
219 }
220
221 /*
222 * Upload the effect
223 */
224 switch (effect->type) {
225 case FF_PERIODIC:
226 ret = pid_upload_periodic(pid_private, effect, is_update);
227 break;
228
229 case FF_CONSTANT:
230 ret = pid_upload_constant(pid_private, effect, is_update);
231 break;
232
233 case FF_SPRING:
234 case FF_FRICTION:
235 case FF_DAMPER:
236 case FF_INERTIA:
237 ret = pid_upload_condition(pid_private, effect, is_update);
238 break;
239
240 case FF_RAMP:
241 ret = pid_upload_ramp(pid_private, effect, is_update);
242 break;
243
244 default:
245 dev_dbg(&pid_private->hid->dev->dev,
246 "invalid type of effect requested - %x.\n",
247 effect->type);
248 return -EINVAL;
249 }
250 /* If a packet was sent, forbid new updates until we are notified
251 * that the packet was updated
252 */
253 if (ret == 0)
254 set_bit(FF_PID_FLAGS_UPDATING, &pid_private->effects[effect->id].flags);
255 pid_private->effects[effect->id].effect = *effect;
256 return ret;
257}
258
259int hid_pid_init(struct hid_device *hid)
260{
261 struct hid_ff_pid *private;
262 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
263 struct input_dev *input_dev = hidinput->input;
264
265 private = hid->ff_private = kzalloc(sizeof(struct hid_ff_pid), GFP_KERNEL);
266 if (!private)
267 return -ENOMEM;
268
269 private->hid = hid;
270
271 hid->ff_exit = hid_pid_exit;
272 hid->ff_event = hid_pid_event;
273
274 /* Open output URB */
275 if (!(private->urbffout = usb_alloc_urb(0, GFP_KERNEL))) {
276 kfree(private);
277 return -1;
278 }
279
280 usb_fill_control_urb(private->urbffout, hid->dev, 0,
281 (void *)&private->ffcr, private->ctrl_buffer, 8,
282 hid_pid_ctrl_out, hid);
283
284 input_dev->upload_effect = hid_pid_upload_effect;
285 input_dev->flush = hid_pid_flush;
286 input_dev->ff_effects_max = 8; // A random default
287 set_bit(EV_FF, input_dev->evbit);
288 set_bit(EV_FF_STATUS, input_dev->evbit);
289
290 spin_lock_init(&private->lock);
291
292 printk(KERN_INFO "Force feedback driver for PID devices by Rodrigo Damazio <rdamazio@lsi.usp.br>.\n");
293
294 return 0;
295}
diff --git a/drivers/usb/input/pid.h b/drivers/usb/input/pid.h
deleted file mode 100644
index a2cb9627ed0e..000000000000
--- a/drivers/usb/input/pid.h
+++ /dev/null
@@ -1,62 +0,0 @@
1/*
2 * PID Force feedback support for hid devices.
3 *
4 * Copyright (c) 2002 Rodrigo Damazio.
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
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 * Should you need to contact me, the author, you can do so by
23 * e-mail - mail your message to <rdamazio@lsi.usp.br>
24 */
25
26#define FF_EFFECTS_MAX 64
27
28#define FF_PID_FLAGS_USED 1 /* If the effect exists */
29#define FF_PID_FLAGS_UPDATING 2 /* If the effect is being updated */
30#define FF_PID_FLAGS_PLAYING 3 /* If the effect is currently being played */
31
32#define FF_PID_FALSE 0
33#define FF_PID_TRUE 1
34
35struct hid_pid_effect {
36 unsigned long flags;
37 pid_t owner;
38 unsigned int device_id; /* The device-assigned ID */
39 struct ff_effect effect;
40};
41
42struct hid_ff_pid {
43 struct hid_device *hid;
44 unsigned long gain;
45
46 struct urb *urbffout;
47 struct usb_ctrlrequest ffcr;
48 spinlock_t lock;
49
50 unsigned char ctrl_buffer[8];
51
52 struct hid_pid_effect effects[FF_EFFECTS_MAX];
53};
54
55/*
56 * Constants from the PID usage table (still far from complete)
57 */
58
59#define FF_PID_USAGE_BLOCK_LOAD 0x89UL
60#define FF_PID_USAGE_BLOCK_FREE 0x90UL
61#define FF_PID_USAGE_NEW_EFFECT 0xABUL
62#define FF_PID_USAGE_POOL_REPORT 0x7FUL
diff --git a/drivers/usb/input/powermate.c b/drivers/usb/input/powermate.c
index b3c0d0c3eae9..f0f8db6810a2 100644
--- a/drivers/usb/input/powermate.c
+++ b/drivers/usb/input/powermate.c
@@ -313,9 +313,7 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i
313 313
314 interface = intf->cur_altsetting; 314 interface = intf->cur_altsetting;
315 endpoint = &interface->endpoint[0].desc; 315 endpoint = &interface->endpoint[0].desc;
316 if (!(endpoint->bEndpointAddress & 0x80)) 316 if (!usb_endpoint_is_int_in(endpoint))
317 return -EIO;
318 if ((endpoint->bmAttributes & 3) != 3)
319 return -EIO; 317 return -EIO;
320 318
321 usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 319 usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
diff --git a/drivers/usb/input/touchkitusb.c b/drivers/usb/input/touchkitusb.c
index 0149043ffb97..30b9f820e7a8 100644
--- a/drivers/usb/input/touchkitusb.c
+++ b/drivers/usb/input/touchkitusb.c
@@ -201,7 +201,7 @@ static void touchkit_irq(struct urb *urb, struct pt_regs *regs)
201 case 0: 201 case 0:
202 /* success */ 202 /* success */
203 break; 203 break;
204 case -ETIMEDOUT: 204 case -ETIME:
205 /* this urb is timing out */ 205 /* this urb is timing out */
206 dbg("%s - urb timed out - was the device unplugged?", 206 dbg("%s - urb timed out - was the device unplugged?",
207 __FUNCTION__); 207 __FUNCTION__);
diff --git a/drivers/usb/input/trancevibrator.c b/drivers/usb/input/trancevibrator.c
new file mode 100644
index 000000000000..33cd91d11eca
--- /dev/null
+++ b/drivers/usb/input/trancevibrator.c
@@ -0,0 +1,159 @@
1/*
2 * PlayStation 2 Trance Vibrator driver
3 *
4 * Copyright (C) 2006 Sam Hocevar <sam@zoy.org>
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 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21/* Standard include files */
22#include <linux/kernel.h>
23#include <linux/errno.h>
24#include <linux/init.h>
25#include <linux/module.h>
26#include <linux/usb.h>
27
28/* Version Information */
29#define DRIVER_VERSION "v1.1"
30#define DRIVER_AUTHOR "Sam Hocevar, sam@zoy.org"
31#define DRIVER_DESC "PlayStation 2 Trance Vibrator driver"
32
33#define TRANCEVIBRATOR_VENDOR_ID 0x0b49 /* ASCII Corporation */
34#define TRANCEVIBRATOR_PRODUCT_ID 0x064f /* Trance Vibrator */
35
36static struct usb_device_id id_table [] = {
37 { USB_DEVICE(TRANCEVIBRATOR_VENDOR_ID, TRANCEVIBRATOR_PRODUCT_ID) },
38 { },
39};
40MODULE_DEVICE_TABLE (usb, id_table);
41
42/* Driver-local specific stuff */
43struct trancevibrator {
44 struct usb_device *udev;
45 unsigned int speed;
46};
47
48static ssize_t show_speed(struct device *dev, struct device_attribute *attr,
49 char *buf)
50{
51 struct usb_interface *intf = to_usb_interface(dev);
52 struct trancevibrator *tv = usb_get_intfdata(intf);
53
54 return sprintf(buf, "%d\n", tv->speed);
55}
56
57static ssize_t set_speed(struct device *dev, struct device_attribute *attr,
58 const char *buf, size_t count)
59{
60 struct usb_interface *intf = to_usb_interface(dev);
61 struct trancevibrator *tv = usb_get_intfdata(intf);
62 int temp, retval;
63
64 temp = simple_strtoul(buf, NULL, 10);
65 if (temp > 255)
66 temp = 255;
67 else if (temp < 0)
68 temp = 0;
69 tv->speed = temp;
70
71 dev_dbg(&tv->udev->dev, "speed = %d\n", tv->speed);
72
73 /* Set speed */
74 retval = usb_control_msg(tv->udev, usb_sndctrlpipe(tv->udev, 0),
75 0x01, /* vendor request: set speed */
76 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
77 tv->speed, /* speed value */
78 0, NULL, 0, USB_CTRL_GET_TIMEOUT);
79 if (retval) {
80 dev_dbg(&tv->udev->dev, "retval = %d\n", retval);
81 return retval;
82 }
83 return count;
84}
85
86static DEVICE_ATTR(speed, S_IWUGO | S_IRUGO, show_speed, set_speed);
87
88static int tv_probe(struct usb_interface *interface,
89 const struct usb_device_id *id)
90{
91 struct usb_device *udev = interface_to_usbdev(interface);
92 struct trancevibrator *dev;
93 int retval;
94
95 dev = kzalloc(sizeof(struct trancevibrator), GFP_KERNEL);
96 if (dev == NULL) {
97 dev_err(&interface->dev, "Out of memory\n");
98 retval = -ENOMEM;
99 goto error;
100 }
101
102 dev->udev = usb_get_dev(udev);
103 usb_set_intfdata(interface, dev);
104 retval = device_create_file(&interface->dev, &dev_attr_speed);
105 if (retval)
106 goto error_create_file;
107
108 return 0;
109
110error_create_file:
111 usb_put_dev(udev);
112 usb_set_intfdata(interface, NULL);
113error:
114 kfree(dev);
115 return retval;
116}
117
118static void tv_disconnect(struct usb_interface *interface)
119{
120 struct trancevibrator *dev;
121
122 dev = usb_get_intfdata (interface);
123 usb_set_intfdata(interface, NULL);
124 device_remove_file(&interface->dev, &dev_attr_speed);
125 usb_put_dev(dev->udev);
126 kfree(dev);
127}
128
129/* USB subsystem object */
130static struct usb_driver tv_driver = {
131 .name = "trancevibrator",
132 .probe = tv_probe,
133 .disconnect = tv_disconnect,
134 .id_table = id_table,
135};
136
137static int __init tv_init(void)
138{
139 int retval = usb_register(&tv_driver);
140 if (retval) {
141 err("usb_register failed. Error number %d", retval);
142 return retval;
143 }
144
145 info(DRIVER_VERSION ":" DRIVER_DESC);
146 return 0;
147}
148
149static void __exit tv_exit(void)
150{
151 usb_deregister(&tv_driver);
152}
153
154module_init (tv_init);
155module_exit (tv_exit);
156
157MODULE_AUTHOR(DRIVER_AUTHOR);
158MODULE_DESCRIPTION(DRIVER_DESC);
159MODULE_LICENSE("GPL");
diff --git a/drivers/usb/input/usbmouse.c b/drivers/usb/input/usbmouse.c
index 446935b671d9..0fb792be95ef 100644
--- a/drivers/usb/input/usbmouse.c
+++ b/drivers/usb/input/usbmouse.c
@@ -218,7 +218,7 @@ static void usb_mouse_disconnect(struct usb_interface *intf)
218 218
219static struct usb_device_id usb_mouse_id_table [] = { 219static struct usb_device_id usb_mouse_id_table [] = {
220 { USB_INTERFACE_INFO(3, 1, 2) }, 220 { USB_INTERFACE_INFO(3, 1, 2) },
221 { } /* Terminating entry */ 221 { } /* Terminating entry */
222}; 222};
223 223
224MODULE_DEVICE_TABLE (usb, usb_mouse_id_table); 224MODULE_DEVICE_TABLE (usb, usb_mouse_id_table);
diff --git a/drivers/usb/input/usbtouchscreen.c b/drivers/usb/input/usbtouchscreen.c
index a338bf4c2d78..4640d1000d83 100644
--- a/drivers/usb/input/usbtouchscreen.c
+++ b/drivers/usb/input/usbtouchscreen.c
@@ -2,9 +2,12 @@
2 * usbtouchscreen.c 2 * usbtouchscreen.c
3 * Driver for USB Touchscreens, supporting those devices: 3 * Driver for USB Touchscreens, supporting those devices:
4 * - eGalax Touchkit 4 * - eGalax Touchkit
5 * - 3M/Microtouch 5 * includes eTurboTouch CT-410/510/700
6 * - 3M/Microtouch EX II series
6 * - ITM 7 * - ITM
7 * - PanJit TouchSet 8 * - PanJit TouchSet
9 * - eTurboTouch
10 * - Gunze AHL61
8 * 11 *
9 * Copyright (C) 2004-2006 by Daniel Ritz <daniel.ritz@gmx.ch> 12 * Copyright (C) 2004-2006 by Daniel Ritz <daniel.ritz@gmx.ch>
10 * Copyright (C) by Todd E. Johnson (mtouchusb.c) 13 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
@@ -42,7 +45,7 @@
42#include <linux/usb/input.h> 45#include <linux/usb/input.h>
43 46
44 47
45#define DRIVER_VERSION "v0.3" 48#define DRIVER_VERSION "v0.4"
46#define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>" 49#define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>"
47#define DRIVER_DESC "USB Touchscreen Driver" 50#define DRIVER_DESC "USB Touchscreen Driver"
48 51
@@ -60,6 +63,7 @@ struct usbtouch_device_info {
60 int flags; 63 int flags;
61 64
62 void (*process_pkt) (struct usbtouch_usb *usbtouch, struct pt_regs *regs, unsigned char *pkt, int len); 65 void (*process_pkt) (struct usbtouch_usb *usbtouch, struct pt_regs *regs, unsigned char *pkt, int len);
66 int (*get_pkt_len) (unsigned char *pkt, int len);
63 int (*read_data) (unsigned char *pkt, int *x, int *y, int *touch, int *press); 67 int (*read_data) (unsigned char *pkt, int *x, int *y, int *touch, int *press);
64 int (*init) (struct usbtouch_usb *usbtouch); 68 int (*init) (struct usbtouch_usb *usbtouch);
65}; 69};
@@ -81,8 +85,16 @@ struct usbtouch_usb {
81 char phys[64]; 85 char phys[64];
82}; 86};
83 87
84static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch, 88
85 struct pt_regs *regs, unsigned char *pkt, int len); 89#if defined(CONFIG_USB_TOUCHSCREEN_EGALAX) || defined(CONFIG_USB_TOUCHSCREEN_ETURBO)
90#define MULTI_PACKET
91#endif
92
93#ifdef MULTI_PACKET
94static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
95 struct pt_regs *regs,
96 unsigned char *pkt, int len);
97#endif
86 98
87/* device types */ 99/* device types */
88enum { 100enum {
@@ -91,14 +103,19 @@ enum {
91 DEVTYPE_PANJIT, 103 DEVTYPE_PANJIT,
92 DEVTYPE_3M, 104 DEVTYPE_3M,
93 DEVTYPE_ITM, 105 DEVTYPE_ITM,
106 DEVTYPE_ETURBO,
107 DEVTYPE_GUNZE,
94}; 108};
95 109
96static struct usb_device_id usbtouch_devices[] = { 110static struct usb_device_id usbtouch_devices[] = {
97#ifdef CONFIG_USB_TOUCHSCREEN_EGALAX 111#ifdef CONFIG_USB_TOUCHSCREEN_EGALAX
98 {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX}, 112 {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX},
113 {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX},
99 {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX}, 114 {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX},
100 {USB_DEVICE(0x0eef, 0x0001), .driver_info = DEVTYPE_EGALAX}, 115 {USB_DEVICE(0x0eef, 0x0001), .driver_info = DEVTYPE_EGALAX},
101 {USB_DEVICE(0x0eef, 0x0002), .driver_info = DEVTYPE_EGALAX}, 116 {USB_DEVICE(0x0eef, 0x0002), .driver_info = DEVTYPE_EGALAX},
117 {USB_DEVICE(0x1234, 0x0001), .driver_info = DEVTYPE_EGALAX},
118 {USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX},
102#endif 119#endif
103 120
104#ifdef CONFIG_USB_TOUCHSCREEN_PANJIT 121#ifdef CONFIG_USB_TOUCHSCREEN_PANJIT
@@ -116,6 +133,14 @@ static struct usb_device_id usbtouch_devices[] = {
116 {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM}, 133 {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM},
117#endif 134#endif
118 135
136#ifdef CONFIG_USB_TOUCHSCREEN_ETURBO
137 {USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO},
138#endif
139
140#ifdef CONFIG_USB_TOUCHSCREEN_GUNZE
141 {USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE},
142#endif
143
119 {} 144 {}
120}; 145};
121 146
@@ -140,82 +165,23 @@ static int egalax_read_data(unsigned char *pkt, int *x, int *y, int *touch, int
140 *touch = pkt[0] & 0x01; 165 *touch = pkt[0] & 0x01;
141 166
142 return 1; 167 return 1;
143
144} 168}
145 169
146static int egalax_get_pkt_len(unsigned char *buf) 170static int egalax_get_pkt_len(unsigned char *buf, int len)
147{ 171{
148 switch (buf[0] & EGALAX_PKT_TYPE_MASK) { 172 switch (buf[0] & EGALAX_PKT_TYPE_MASK) {
149 case EGALAX_PKT_TYPE_REPT: 173 case EGALAX_PKT_TYPE_REPT:
150 return 5; 174 return 5;
151 175
152 case EGALAX_PKT_TYPE_DIAG: 176 case EGALAX_PKT_TYPE_DIAG:
177 if (len < 2)
178 return -1;
179
153 return buf[1] + 2; 180 return buf[1] + 2;
154 } 181 }
155 182
156 return 0; 183 return 0;
157} 184}
158
159static void egalax_process(struct usbtouch_usb *usbtouch, struct pt_regs *regs,
160 unsigned char *pkt, int len)
161{
162 unsigned char *buffer;
163 int pkt_len, buf_len, pos;
164
165 /* if the buffer contains data, append */
166 if (unlikely(usbtouch->buf_len)) {
167 int tmp;
168
169 /* if only 1 byte in buffer, add another one to get length */
170 if (usbtouch->buf_len == 1)
171 usbtouch->buffer[1] = pkt[0];
172
173 pkt_len = egalax_get_pkt_len(usbtouch->buffer);
174
175 /* unknown packet: drop everything */
176 if (!pkt_len)
177 return;
178
179 /* append, process */
180 tmp = pkt_len - usbtouch->buf_len;
181 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp);
182 usbtouch_process_pkt(usbtouch, regs, usbtouch->buffer, pkt_len);
183
184 buffer = pkt + tmp;
185 buf_len = len - tmp;
186 } else {
187 buffer = pkt;
188 buf_len = len;
189 }
190
191 /* only one byte left in buffer */
192 if (unlikely(buf_len == 1)) {
193 usbtouch->buffer[0] = buffer[0];
194 usbtouch->buf_len = 1;
195 return;
196 }
197
198 /* loop over the buffer */
199 pos = 0;
200 while (pos < buf_len) {
201 /* get packet len */
202 pkt_len = egalax_get_pkt_len(buffer + pos);
203
204 /* unknown packet: drop everything */
205 if (unlikely(!pkt_len))
206 return;
207
208 /* full packet: process */
209 if (likely(pkt_len <= buf_len)) {
210 usbtouch_process_pkt(usbtouch, regs, buffer + pos, pkt_len);
211 } else {
212 /* incomplete packet: save in buffer */
213 memcpy(usbtouch->buffer, buffer + pos, buf_len - pos);
214 usbtouch->buf_len = buf_len - pos;
215 }
216 pos += pkt_len;
217 }
218}
219#endif 185#endif
220 186
221 187
@@ -254,7 +220,7 @@ static int mtouch_read_data(unsigned char *pkt, int *x, int *y, int *touch, int
254 220
255static int mtouch_init(struct usbtouch_usb *usbtouch) 221static int mtouch_init(struct usbtouch_usb *usbtouch)
256{ 222{
257 int ret; 223 int ret, i;
258 224
259 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0), 225 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
260 MTOUCHUSB_RESET, 226 MTOUCHUSB_RESET,
@@ -264,15 +230,20 @@ static int mtouch_init(struct usbtouch_usb *usbtouch)
264 __FUNCTION__, ret); 230 __FUNCTION__, ret);
265 if (ret < 0) 231 if (ret < 0)
266 return ret; 232 return ret;
267 233 msleep(150);
268 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0), 234
269 MTOUCHUSB_ASYNC_REPORT, 235 for (i = 0; i < 3; i++) {
270 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 236 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
271 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT); 237 MTOUCHUSB_ASYNC_REPORT,
272 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d", 238 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
273 __FUNCTION__, ret); 239 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
274 if (ret < 0) 240 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
275 return ret; 241 __FUNCTION__, ret);
242 if (ret >= 0)
243 break;
244 if (ret != -EPIPE)
245 return ret;
246 }
276 247
277 return 0; 248 return 0;
278} 249}
@@ -296,6 +267,54 @@ static int itm_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *pr
296 267
297 268
298/***************************************************************************** 269/*****************************************************************************
270 * eTurboTouch part
271 */
272#ifdef CONFIG_USB_TOUCHSCREEN_ETURBO
273static int eturbo_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press)
274{
275 unsigned int shift;
276
277 /* packets should start with sync */
278 if (!(pkt[0] & 0x80))
279 return 0;
280
281 shift = (6 - (pkt[0] & 0x03));
282 *x = ((pkt[3] << 7) | pkt[4]) >> shift;
283 *y = ((pkt[1] << 7) | pkt[2]) >> shift;
284 *touch = (pkt[0] & 0x10) ? 1 : 0;
285
286 return 1;
287}
288
289static int eturbo_get_pkt_len(unsigned char *buf, int len)
290{
291 if (buf[0] & 0x80)
292 return 5;
293 if (buf[0] == 0x01)
294 return 3;
295 return 0;
296}
297#endif
298
299
300/*****************************************************************************
301 * Gunze part
302 */
303#ifdef CONFIG_USB_TOUCHSCREEN_GUNZE
304static int gunze_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press)
305{
306 if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80))
307 return 0;
308
309 *x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F);
310 *y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F);
311 *touch = pkt[0] & 0x20;
312
313 return 1;
314}
315#endif
316
317/*****************************************************************************
299 * the different device descriptors 318 * the different device descriptors
300 */ 319 */
301static struct usbtouch_device_info usbtouch_dev_info[] = { 320static struct usbtouch_device_info usbtouch_dev_info[] = {
@@ -307,7 +326,8 @@ static struct usbtouch_device_info usbtouch_dev_info[] = {
307 .max_yc = 0x07ff, 326 .max_yc = 0x07ff,
308 .rept_size = 16, 327 .rept_size = 16,
309 .flags = USBTOUCH_FLG_BUFFER, 328 .flags = USBTOUCH_FLG_BUFFER,
310 .process_pkt = egalax_process, 329 .process_pkt = usbtouch_process_multi,
330 .get_pkt_len = egalax_get_pkt_len,
311 .read_data = egalax_read_data, 331 .read_data = egalax_read_data,
312 }, 332 },
313#endif 333#endif
@@ -346,6 +366,31 @@ static struct usbtouch_device_info usbtouch_dev_info[] = {
346 .read_data = itm_read_data, 366 .read_data = itm_read_data,
347 }, 367 },
348#endif 368#endif
369
370#ifdef CONFIG_USB_TOUCHSCREEN_ETURBO
371 [DEVTYPE_ETURBO] = {
372 .min_xc = 0x0,
373 .max_xc = 0x07ff,
374 .min_yc = 0x0,
375 .max_yc = 0x07ff,
376 .rept_size = 8,
377 .flags = USBTOUCH_FLG_BUFFER,
378 .process_pkt = usbtouch_process_multi,
379 .get_pkt_len = eturbo_get_pkt_len,
380 .read_data = eturbo_read_data,
381 },
382#endif
383
384#ifdef CONFIG_USB_TOUCHSCREEN_GUNZE
385 [DEVTYPE_GUNZE] = {
386 .min_xc = 0x0,
387 .max_xc = 0x0fff,
388 .min_yc = 0x0,
389 .max_yc = 0x0fff,
390 .rept_size = 4,
391 .read_data = gunze_read_data,
392 },
393#endif
349}; 394};
350 395
351 396
@@ -377,6 +422,83 @@ static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
377} 422}
378 423
379 424
425#ifdef MULTI_PACKET
426static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
427 struct pt_regs *regs,
428 unsigned char *pkt, int len)
429{
430 unsigned char *buffer;
431 int pkt_len, pos, buf_len, tmp;
432
433 /* process buffer */
434 if (unlikely(usbtouch->buf_len)) {
435 /* try to get size */
436 pkt_len = usbtouch->type->get_pkt_len(
437 usbtouch->buffer, usbtouch->buf_len);
438
439 /* drop? */
440 if (unlikely(!pkt_len))
441 goto out_flush_buf;
442
443 /* need to append -pkt_len bytes before able to get size */
444 if (unlikely(pkt_len < 0)) {
445 int append = -pkt_len;
446 if (unlikely(append > len))
447 append = len;
448 if (usbtouch->buf_len + append >= usbtouch->type->rept_size)
449 goto out_flush_buf;
450 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, append);
451 usbtouch->buf_len += append;
452
453 pkt_len = usbtouch->type->get_pkt_len(
454 usbtouch->buffer, usbtouch->buf_len);
455 if (pkt_len < 0)
456 return;
457 }
458
459 /* append */
460 tmp = pkt_len - usbtouch->buf_len;
461 if (usbtouch->buf_len + tmp >= usbtouch->type->rept_size)
462 goto out_flush_buf;
463 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp);
464 usbtouch_process_pkt(usbtouch, regs, usbtouch->buffer, pkt_len);
465
466 buffer = pkt + tmp;
467 buf_len = len - tmp;
468 } else {
469 buffer = pkt;
470 buf_len = len;
471 }
472
473 /* loop over the received packet, process */
474 pos = 0;
475 while (pos < buf_len) {
476 /* get packet len */
477 pkt_len = usbtouch->type->get_pkt_len(buffer + pos, len);
478
479 /* unknown packet: drop everything */
480 if (unlikely(!pkt_len))
481 goto out_flush_buf;
482
483 /* full packet: process */
484 if (likely((pkt_len > 0) && (pkt_len <= buf_len - pos))) {
485 usbtouch_process_pkt(usbtouch, regs, buffer + pos, pkt_len);
486 } else {
487 /* incomplete packet: save in buffer */
488 memcpy(usbtouch->buffer, buffer + pos, buf_len - pos);
489 usbtouch->buf_len = buf_len - pos;
490 return;
491 }
492 pos += pkt_len;
493 }
494
495out_flush_buf:
496 usbtouch->buf_len = 0;
497 return;
498}
499#endif
500
501
380static void usbtouch_irq(struct urb *urb, struct pt_regs *regs) 502static void usbtouch_irq(struct urb *urb, struct pt_regs *regs)
381{ 503{
382 struct usbtouch_usb *usbtouch = urb->context; 504 struct usbtouch_usb *usbtouch = urb->context;
@@ -386,7 +508,7 @@ static void usbtouch_irq(struct urb *urb, struct pt_regs *regs)
386 case 0: 508 case 0:
387 /* success */ 509 /* success */
388 break; 510 break;
389 case -ETIMEDOUT: 511 case -ETIME:
390 /* this urb is timing out */ 512 /* this urb is timing out */
391 dbg("%s - urb timed out - was the device unplugged?", 513 dbg("%s - urb timed out - was the device unplugged?",
392 __FUNCTION__); 514 __FUNCTION__);
@@ -452,7 +574,7 @@ static int usbtouch_probe(struct usb_interface *intf,
452 struct usb_endpoint_descriptor *endpoint; 574 struct usb_endpoint_descriptor *endpoint;
453 struct usb_device *udev = interface_to_usbdev(intf); 575 struct usb_device *udev = interface_to_usbdev(intf);
454 struct usbtouch_device_info *type; 576 struct usbtouch_device_info *type;
455 int err; 577 int err = -ENOMEM;
456 578
457 interface = intf->cur_altsetting; 579 interface = intf->cur_altsetting;
458 endpoint = &interface->endpoint[0].desc; 580 endpoint = &interface->endpoint[0].desc;
@@ -526,6 +648,7 @@ static int usbtouch_probe(struct usb_interface *intf,
526 usbtouch->data, type->rept_size, 648 usbtouch->data, type->rept_size,
527 usbtouch_irq, usbtouch, endpoint->bInterval); 649 usbtouch_irq, usbtouch, endpoint->bInterval);
528 650
651 usbtouch->irq->dev = usbtouch->udev;
529 usbtouch->irq->transfer_dma = usbtouch->data_dma; 652 usbtouch->irq->transfer_dma = usbtouch->data_dma;
530 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 653 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
531 654
@@ -553,7 +676,7 @@ out_free_buffers:
553out_free: 676out_free:
554 input_free_device(input_dev); 677 input_free_device(input_dev);
555 kfree(usbtouch); 678 kfree(usbtouch);
556 return -ENOMEM; 679 return err;
557} 680}
558 681
559static void usbtouch_disconnect(struct usb_interface *intf) 682static void usbtouch_disconnect(struct usb_interface *intf)
diff --git a/drivers/usb/input/wacom.c b/drivers/usb/input/wacom.c
deleted file mode 100644
index 369461a70b72..000000000000
--- a/drivers/usb/input/wacom.c
+++ /dev/null
@@ -1,1003 +0,0 @@
1/*
2 * USB Wacom Graphire and Wacom Intuos tablet support
3 *
4 * Copyright (c) 2000-2004 Vojtech Pavlik <vojtech@ucw.cz>
5 * Copyright (c) 2000 Andreas Bach Aaen <abach@stofanet.dk>
6 * Copyright (c) 2000 Clifford Wolf <clifford@clifford.at>
7 * Copyright (c) 2000 Sam Mosel <sam.mosel@computer.org>
8 * Copyright (c) 2000 James E. Blair <corvus@gnu.org>
9 * Copyright (c) 2000 Daniel Egger <egger@suse.de>
10 * Copyright (c) 2001 Frederic Lepied <flepied@mandrakesoft.com>
11 * Copyright (c) 2004 Panagiotis Issaris <panagiotis.issaris@mech.kuleuven.ac.be>
12 * Copyright (c) 2002-2006 Ping Cheng <pingc@wacom.com>
13 *
14 * ChangeLog:
15 * v0.1 (vp) - Initial release
16 * v0.2 (aba) - Support for all buttons / combinations
17 * v0.3 (vp) - Support for Intuos added
18 * v0.4 (sm) - Support for more Intuos models, menustrip
19 * relative mode, proximity.
20 * v0.5 (vp) - Big cleanup, nifty features removed,
21 * they belong in userspace
22 * v1.8 (vp) - Submit URB only when operating, moved to CVS,
23 * use input_report_key instead of report_btn and
24 * other cleanups
25 * v1.11 (vp) - Add URB ->dev setting for new kernels
26 * v1.11 (jb) - Add support for the 4D Mouse & Lens
27 * v1.12 (de) - Add support for two more inking pen IDs
28 * v1.14 (vp) - Use new USB device id probing scheme.
29 * Fix Wacom Graphire mouse wheel
30 * v1.18 (vp) - Fix mouse wheel direction
31 * Make mouse relative
32 * v1.20 (fl) - Report tool id for Intuos devices
33 * - Multi tools support
34 * - Corrected Intuos protocol decoding (airbrush, 4D mouse, lens cursor...)
35 * - Add PL models support
36 * - Fix Wacom Graphire mouse wheel again
37 * v1.21 (vp) - Removed protocol descriptions
38 * - Added MISC_SERIAL for tool serial numbers
39 * (gb) - Identify version on module load.
40 * v1.21.1 (fl) - added Graphire2 support
41 * v1.21.2 (fl) - added Intuos2 support
42 * - added all the PL ids
43 * v1.21.3 (fl) - added another eraser id from Neil Okamoto
44 * - added smooth filter for Graphire from Peri Hankey
45 * - added PenPartner support from Olaf van Es
46 * - new tool ids from Ole Martin Bjoerndalen
47 * v1.29 (pc) - Add support for more tablets
48 * - Fix pressure reporting
49 * v1.30 (vp) - Merge 2.4 and 2.5 drivers
50 * - Since 2.5 now has input_sync(), remove MSC_SERIAL abuse
51 * - Cleanups here and there
52 * v1.30.1 (pi) - Added Graphire3 support
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
57 * v1.44 (pc) - Added support for Graphire4, Cintiq 710, Intuos3 6x11, etc.
58 * - Report Device IDs
59 * v1.45 (pc) - Added support for DTF 521, Intuos3 12x12 and 12x19
60 * - Minor data report fix
61 */
62
63/*
64 * This program is free software; you can redistribute it and/or modify
65 * it under the terms of the GNU General Public License as published by
66 * the Free Software Foundation; either version 2 of the License, or
67 * (at your option) any later version.
68 */
69
70#include <linux/kernel.h>
71#include <linux/slab.h>
72#include <linux/module.h>
73#include <linux/init.h>
74#include <linux/usb/input.h>
75#include <asm/unaligned.h>
76
77/*
78 * Version Information
79 */
80#define DRIVER_VERSION "v1.45"
81#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
82#define DRIVER_DESC "USB Wacom Graphire and Wacom Intuos tablet driver"
83#define DRIVER_LICENSE "GPL"
84
85MODULE_AUTHOR(DRIVER_AUTHOR);
86MODULE_DESCRIPTION(DRIVER_DESC);
87MODULE_LICENSE(DRIVER_LICENSE);
88
89#define USB_VENDOR_ID_WACOM 0x056a
90#define STYLUS_DEVICE_ID 0x02
91#define CURSOR_DEVICE_ID 0x06
92#define ERASER_DEVICE_ID 0x0A
93
94enum {
95 PENPARTNER = 0,
96 GRAPHIRE,
97 WACOM_G4,
98 PL,
99 INTUOS,
100 INTUOS3,
101 INTUOS312,
102 INTUOS319,
103 CINTIQ,
104 MAX_TYPE
105};
106
107struct wacom_features {
108 char *name;
109 int pktlen;
110 int x_max;
111 int y_max;
112 int pressure_max;
113 int distance_max;
114 int type;
115 usb_complete_t irq;
116};
117
118struct wacom {
119 signed char *data;
120 dma_addr_t data_dma;
121 struct input_dev *dev;
122 struct usb_device *usbdev;
123 struct urb *irq;
124 struct wacom_features *features;
125 int tool[2];
126 int id[2];
127 __u32 serial[2];
128 char phys[32];
129};
130
131#define USB_REQ_GET_REPORT 0x01
132#define USB_REQ_SET_REPORT 0x09
133
134static int usb_get_report(struct usb_interface *intf, unsigned char type,
135 unsigned char id, void *buf, int size)
136{
137 return usb_control_msg(interface_to_usbdev(intf),
138 usb_rcvctrlpipe(interface_to_usbdev(intf), 0),
139 USB_REQ_GET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
140 (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber,
141 buf, size, 100);
142}
143
144static int usb_set_report(struct usb_interface *intf, unsigned char type,
145 unsigned char id, void *buf, int size)
146{
147 return usb_control_msg(interface_to_usbdev(intf),
148 usb_sndctrlpipe(interface_to_usbdev(intf), 0),
149 USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
150 (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber,
151 buf, size, 1000);
152}
153
154static void wacom_pl_irq(struct urb *urb, struct pt_regs *regs)
155{
156 struct wacom *wacom = urb->context;
157 unsigned char *data = wacom->data;
158 struct input_dev *dev = wacom->dev;
159 int prox, pressure, id;
160 int retval;
161
162 switch (urb->status) {
163 case 0:
164 /* success */
165 break;
166 case -ECONNRESET:
167 case -ENOENT:
168 case -ESHUTDOWN:
169 /* this urb is terminated, clean up */
170 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
171 return;
172 default:
173 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
174 goto exit;
175 }
176
177 if (data[0] != 2) {
178 dbg("wacom_pl_irq: received unknown report #%d", data[0]);
179 goto exit;
180 }
181
182 prox = data[1] & 0x40;
183
184 input_regs(dev, regs);
185
186 id = ERASER_DEVICE_ID;
187 if (prox) {
188
189 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
190 if (wacom->features->pressure_max > 255)
191 pressure = (pressure << 1) | ((data[4] >> 6) & 1);
192 pressure += (wacom->features->pressure_max + 1) / 2;
193
194 /*
195 * if going from out of proximity into proximity select between the eraser
196 * and the pen based on the state of the stylus2 button, choose eraser if
197 * pressed else choose pen. if not a proximity change from out to in, send
198 * an out of proximity for previous tool then a in for new tool.
199 */
200 if (!wacom->tool[0]) {
201 /* Eraser bit set for DTF */
202 if (data[1] & 0x10)
203 wacom->tool[1] = BTN_TOOL_RUBBER;
204 else
205 /* Going into proximity select tool */
206 wacom->tool[1] = (data[4] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
207 } else {
208 /* was entered with stylus2 pressed */
209 if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
210 /* report out proximity for previous tool */
211 input_report_key(dev, wacom->tool[1], 0);
212 input_sync(dev);
213 wacom->tool[1] = BTN_TOOL_PEN;
214 goto exit;
215 }
216 }
217 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
218 /* Unknown tool selected default to pen tool */
219 wacom->tool[1] = BTN_TOOL_PEN;
220 id = STYLUS_DEVICE_ID;
221 }
222 input_report_key(dev, wacom->tool[1], prox); /* report in proximity for tool */
223 input_report_abs(dev, ABS_MISC, id); /* report tool id */
224 input_report_abs(dev, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
225 input_report_abs(dev, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
226 input_report_abs(dev, ABS_PRESSURE, pressure);
227
228 input_report_key(dev, BTN_TOUCH, data[4] & 0x08);
229 input_report_key(dev, BTN_STYLUS, data[4] & 0x10);
230 /* Only allow the stylus2 button to be reported for the pen tool. */
231 input_report_key(dev, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20));
232 } else {
233 /* report proximity-out of a (valid) tool */
234 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
235 /* Unknown tool selected default to pen tool */
236 wacom->tool[1] = BTN_TOOL_PEN;
237 }
238 input_report_key(dev, wacom->tool[1], prox);
239 }
240
241 wacom->tool[0] = prox; /* Save proximity state */
242 input_sync(dev);
243
244 exit:
245 retval = usb_submit_urb (urb, GFP_ATOMIC);
246 if (retval)
247 err ("%s - usb_submit_urb failed with result %d",
248 __FUNCTION__, retval);
249}
250
251static void wacom_ptu_irq(struct urb *urb, struct pt_regs *regs)
252{
253 struct wacom *wacom = urb->context;
254 unsigned char *data = wacom->data;
255 struct input_dev *dev = wacom->dev;
256 int retval, id;
257
258 switch (urb->status) {
259 case 0:
260 /* success */
261 break;
262 case -ECONNRESET:
263 case -ENOENT:
264 case -ESHUTDOWN:
265 /* this urb is terminated, clean up */
266 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
267 return;
268 default:
269 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
270 goto exit;
271 }
272
273 if (data[0] != 2) {
274 printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]);
275 goto exit;
276 }
277
278 input_regs(dev, regs);
279 if (data[1] & 0x04) {
280 input_report_key(dev, BTN_TOOL_RUBBER, data[1] & 0x20);
281 input_report_key(dev, BTN_TOUCH, data[1] & 0x08);
282 id = ERASER_DEVICE_ID;
283 } else {
284 input_report_key(dev, BTN_TOOL_PEN, data[1] & 0x20);
285 input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
286 id = STYLUS_DEVICE_ID;
287 }
288 input_report_abs(dev, ABS_MISC, id); /* report tool id */
289 input_report_abs(dev, ABS_X, le16_to_cpu(*(__le16 *) &data[2]));
290 input_report_abs(dev, ABS_Y, le16_to_cpu(*(__le16 *) &data[4]));
291 input_report_abs(dev, ABS_PRESSURE, le16_to_cpu(*(__le16 *) &data[6]));
292 input_report_key(dev, BTN_STYLUS, data[1] & 0x02);
293 input_report_key(dev, BTN_STYLUS2, data[1] & 0x10);
294
295 input_sync(dev);
296
297 exit:
298 retval = usb_submit_urb (urb, GFP_ATOMIC);
299 if (retval)
300 err ("%s - usb_submit_urb failed with result %d",
301 __FUNCTION__, retval);
302}
303
304static void wacom_penpartner_irq(struct urb *urb, struct pt_regs *regs)
305{
306 struct wacom *wacom = urb->context;
307 unsigned char *data = wacom->data;
308 struct input_dev *dev = wacom->dev;
309 int retval;
310
311 switch (urb->status) {
312 case 0:
313 /* success */
314 break;
315 case -ECONNRESET:
316 case -ENOENT:
317 case -ESHUTDOWN:
318 /* this urb is terminated, clean up */
319 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
320 return;
321 default:
322 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
323 goto exit;
324 }
325
326 if (data[0] != 2) {
327 printk(KERN_INFO "wacom_penpartner_irq: received unknown report #%d\n", data[0]);
328 goto exit;
329 }
330
331 input_regs(dev, regs);
332 input_report_key(dev, BTN_TOOL_PEN, 1);
333 input_report_abs(dev, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
334 input_report_abs(dev, ABS_X, le16_to_cpu(*(__le16 *) &data[1]));
335 input_report_abs(dev, ABS_Y, le16_to_cpu(*(__le16 *) &data[3]));
336 input_report_abs(dev, ABS_PRESSURE, (signed char)data[6] + 127);
337 input_report_key(dev, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
338 input_report_key(dev, BTN_STYLUS, (data[5] & 0x40));
339 input_sync(dev);
340
341 exit:
342 retval = usb_submit_urb (urb, GFP_ATOMIC);
343 if (retval)
344 err ("%s - usb_submit_urb failed with result %d",
345 __FUNCTION__, retval);
346}
347
348static void wacom_graphire_irq(struct urb *urb, struct pt_regs *regs)
349{
350 struct wacom *wacom = urb->context;
351 unsigned char *data = wacom->data;
352 struct input_dev *dev = wacom->dev;
353 int x, y, id, rw;
354 int retval;
355
356 switch (urb->status) {
357 case 0:
358 /* success */
359 break;
360 case -ECONNRESET:
361 case -ENOENT:
362 case -ESHUTDOWN:
363 /* this urb is terminated, clean up */
364 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
365 return;
366 default:
367 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
368 goto exit;
369 }
370
371 if (data[0] == 99) return; /* for Volito tablets */
372
373 if (data[0] != 2) {
374 dbg("wacom_graphire_irq: received unknown report #%d", data[0]);
375 goto exit;
376 }
377
378 input_regs(dev, regs);
379
380 id = STYLUS_DEVICE_ID;
381 if (data[1] & 0x10) { /* in prox */
382
383 switch ((data[1] >> 5) & 3) {
384
385 case 0: /* Pen */
386 wacom->tool[0] = BTN_TOOL_PEN;
387 break;
388
389 case 1: /* Rubber */
390 wacom->tool[0] = BTN_TOOL_RUBBER;
391 id = ERASER_DEVICE_ID;
392 break;
393
394 case 2: /* Mouse with wheel */
395 input_report_key(dev, BTN_MIDDLE, data[1] & 0x04);
396 if (wacom->features->type == WACOM_G4) {
397 rw = data[7] & 0x04 ? (data[7] & 0x03)-4 : (data[7] & 0x03);
398 input_report_rel(dev, REL_WHEEL, -rw);
399 } else
400 input_report_rel(dev, REL_WHEEL, -(signed char) data[6]);
401 /* fall through */
402
403 case 3: /* Mouse without wheel */
404 wacom->tool[0] = BTN_TOOL_MOUSE;
405 id = CURSOR_DEVICE_ID;
406 input_report_key(dev, BTN_LEFT, data[1] & 0x01);
407 input_report_key(dev, BTN_RIGHT, data[1] & 0x02);
408 if (wacom->features->type == WACOM_G4)
409 input_report_abs(dev, ABS_DISTANCE, data[6]);
410 else
411 input_report_abs(dev, ABS_DISTANCE, data[7]);
412 break;
413 }
414 }
415
416 if (data[1] & 0x90) {
417 x = le16_to_cpu(*(__le16 *) &data[2]);
418 y = le16_to_cpu(*(__le16 *) &data[4]);
419 input_report_abs(dev, ABS_X, x);
420 input_report_abs(dev, ABS_Y, y);
421 if (wacom->tool[0] != BTN_TOOL_MOUSE) {
422 input_report_abs(dev, ABS_PRESSURE, data[6] | ((data[7] & 0x01) << 8));
423 input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
424 input_report_key(dev, BTN_STYLUS, data[1] & 0x02);
425 input_report_key(dev, BTN_STYLUS2, data[1] & 0x04);
426 }
427 }
428
429 if (data[1] & 0x10)
430 input_report_abs(dev, ABS_MISC, id); /* report tool id */
431 else
432 input_report_abs(dev, ABS_MISC, 0); /* reset tool id */
433 input_report_key(dev, wacom->tool[0], data[1] & 0x10);
434 input_sync(dev);
435
436 /* send pad data */
437 if (wacom->features->type == WACOM_G4) {
438 if ((wacom->serial[1] & 0xc0) != (data[7] & 0xf8)) {
439 wacom->id[1] = 1;
440 wacom->serial[1] = (data[7] & 0xf8);
441 input_report_key(dev, BTN_0, (data[7] & 0x40));
442 input_report_key(dev, BTN_4, (data[7] & 0x80));
443 rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
444 input_report_rel(dev, REL_WHEEL, rw);
445 input_report_key(dev, BTN_TOOL_FINGER, 0xf0);
446 input_event(dev, EV_MSC, MSC_SERIAL, 0xf0);
447 } else if (wacom->id[1]) {
448 wacom->id[1] = 0;
449 input_report_key(dev, BTN_TOOL_FINGER, 0);
450 input_event(dev, EV_MSC, MSC_SERIAL, 0xf0);
451 }
452 input_sync(dev);
453 }
454 exit:
455 retval = usb_submit_urb (urb, GFP_ATOMIC);
456 if (retval)
457 err ("%s - usb_submit_urb failed with result %d",
458 __FUNCTION__, retval);
459}
460
461static int wacom_intuos_inout(struct urb *urb)
462{
463 struct wacom *wacom = urb->context;
464 unsigned char *data = wacom->data;
465 struct input_dev *dev = wacom->dev;
466 int idx;
467
468 /* tool number */
469 idx = data[1] & 0x01;
470
471 /* Enter report */
472 if ((data[1] & 0xfc) == 0xc0) {
473 /* serial number of the tool */
474 wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
475 (data[4] << 20) + (data[5] << 12) +
476 (data[6] << 4) + (data[7] >> 4);
477
478 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4);
479 switch (wacom->id[idx]) {
480 case 0x812: /* Inking pen */
481 case 0x801: /* Intuos3 Inking pen */
482 case 0x012:
483 wacom->tool[idx] = BTN_TOOL_PENCIL;
484 break;
485 case 0x822: /* Pen */
486 case 0x842:
487 case 0x852:
488 case 0x823: /* Intuos3 Grip Pen */
489 case 0x813: /* Intuos3 Classic Pen */
490 case 0x885: /* Intuos3 Marker Pen */
491 case 0x022:
492 wacom->tool[idx] = BTN_TOOL_PEN;
493 break;
494 case 0x832: /* Stroke pen */
495 case 0x032:
496 wacom->tool[idx] = BTN_TOOL_BRUSH;
497 break;
498 case 0x007: /* Mouse 4D and 2D */
499 case 0x09c:
500 case 0x094:
501 case 0x017: /* Intuos3 2D Mouse */
502 wacom->tool[idx] = BTN_TOOL_MOUSE;
503 break;
504 case 0x096: /* Lens cursor */
505 case 0x097: /* Intuos3 Lens cursor */
506 wacom->tool[idx] = BTN_TOOL_LENS;
507 break;
508 case 0x82a: /* Eraser */
509 case 0x85a:
510 case 0x91a:
511 case 0xd1a:
512 case 0x0fa:
513 case 0x82b: /* Intuos3 Grip Pen Eraser */
514 case 0x81b: /* Intuos3 Classic Pen Eraser */
515 case 0x91b: /* Intuos3 Airbrush Eraser */
516 wacom->tool[idx] = BTN_TOOL_RUBBER;
517 break;
518 case 0xd12:
519 case 0x912:
520 case 0x112:
521 case 0x913: /* Intuos3 Airbrush */
522 wacom->tool[idx] = BTN_TOOL_AIRBRUSH;
523 break;
524 default: /* Unknown tool */
525 wacom->tool[idx] = BTN_TOOL_PEN;
526 }
527 if(!((wacom->tool[idx] == BTN_TOOL_LENS) &&
528 ((wacom->features->type == INTUOS312)
529 || (wacom->features->type == INTUOS319)))) {
530 input_report_abs(dev, ABS_MISC, wacom->id[idx]); /* report tool id */
531 input_report_key(dev, wacom->tool[idx], 1);
532 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
533 input_sync(dev);
534 }
535 return 1;
536 }
537
538 /* Exit report */
539 if ((data[1] & 0xfe) == 0x80) {
540 input_report_key(dev, wacom->tool[idx], 0);
541 input_report_abs(dev, ABS_MISC, 0); /* reset tool id */
542 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
543 input_sync(dev);
544 return 1;
545 }
546
547 if((wacom->tool[idx] == BTN_TOOL_LENS) && ((wacom->features->type == INTUOS312)
548 || (wacom->features->type == INTUOS319)))
549 return 1;
550 else
551 return 0;
552}
553
554static void wacom_intuos_general(struct urb *urb)
555{
556 struct wacom *wacom = urb->context;
557 unsigned char *data = wacom->data;
558 struct input_dev *dev = wacom->dev;
559 unsigned int t;
560
561 /* general pen packet */
562 if ((data[1] & 0xb8) == 0xa0) {
563 t = (data[6] << 2) | ((data[7] >> 6) & 3);
564 input_report_abs(dev, ABS_PRESSURE, t);
565 input_report_abs(dev, ABS_TILT_X,
566 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
567 input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f);
568 input_report_key(dev, BTN_STYLUS, data[1] & 2);
569 input_report_key(dev, BTN_STYLUS2, data[1] & 4);
570 input_report_key(dev, BTN_TOUCH, t > 10);
571 }
572
573 /* airbrush second packet */
574 if ((data[1] & 0xbc) == 0xb4) {
575 input_report_abs(dev, ABS_WHEEL,
576 (data[6] << 2) | ((data[7] >> 6) & 3));
577 input_report_abs(dev, ABS_TILT_X,
578 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
579 input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f);
580 }
581 return;
582}
583
584static void wacom_intuos_irq(struct urb *urb, struct pt_regs *regs)
585{
586 struct wacom *wacom = urb->context;
587 unsigned char *data = wacom->data;
588 struct input_dev *dev = wacom->dev;
589 unsigned int t;
590 int idx;
591 int retval;
592
593 switch (urb->status) {
594 case 0:
595 /* success */
596 break;
597 case -ECONNRESET:
598 case -ENOENT:
599 case -ESHUTDOWN:
600 /* this urb is terminated, clean up */
601 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
602 return;
603 default:
604 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
605 goto exit;
606 }
607
608 if (data[0] != 2 && data[0] != 5 && data[0] != 6 && data[0] != 12) {
609 dbg("wacom_intuos_irq: received unknown report #%d", data[0]);
610 goto exit;
611 }
612
613 input_regs(dev, regs);
614
615 /* tool number */
616 idx = data[1] & 0x01;
617
618 /* pad packets. Works as a second tool and is always in prox */
619 if (data[0] == 12) {
620 /* initiate the pad as a device */
621 if (wacom->tool[1] != BTN_TOOL_FINGER)
622 wacom->tool[1] = BTN_TOOL_FINGER;
623
624 input_report_key(dev, BTN_0, (data[5] & 0x01));
625 input_report_key(dev, BTN_1, (data[5] & 0x02));
626 input_report_key(dev, BTN_2, (data[5] & 0x04));
627 input_report_key(dev, BTN_3, (data[5] & 0x08));
628 input_report_key(dev, BTN_4, (data[6] & 0x01));
629 input_report_key(dev, BTN_5, (data[6] & 0x02));
630 input_report_key(dev, BTN_6, (data[6] & 0x04));
631 input_report_key(dev, BTN_7, (data[6] & 0x08));
632 input_report_abs(dev, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
633 input_report_abs(dev, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
634
635 if((data[5] & 0x0f) | (data[6] & 0x0f) | (data[1] & 0x1f) | data[2])
636 input_report_key(dev, wacom->tool[1], 1);
637 else
638 input_report_key(dev, wacom->tool[1], 0);
639 input_event(dev, EV_MSC, MSC_SERIAL, 0xffffffff);
640 input_sync(dev);
641 goto exit;
642 }
643
644 /* process in/out prox events */
645 if (wacom_intuos_inout(urb))
646 goto exit;
647
648 /* Cintiq doesn't send data when RDY bit isn't set */
649 if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40))
650 goto exit;
651
652 if (wacom->features->type >= INTUOS3) {
653 input_report_abs(dev, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
654 input_report_abs(dev, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
655 input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
656 } else {
657 input_report_abs(dev, ABS_X, be16_to_cpu(*(__be16 *) &data[2]));
658 input_report_abs(dev, ABS_Y, be16_to_cpu(*(__be16 *) &data[4]));
659 input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
660 }
661
662 /* process general packets */
663 wacom_intuos_general(urb);
664
665 /* 4D mouse, 2D mouse, marker pen rotation, or Lens cursor packets */
666 if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0) {
667
668 if (data[1] & 0x02) {
669 /* Rotation packet */
670 if (wacom->features->type >= INTUOS3) {
671 /* I3 marker pen rotation reported as wheel
672 * due to valuator limitation
673 */
674 t = (data[6] << 3) | ((data[7] >> 5) & 7);
675 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
676 ((t-1) / 2 + 450)) : (450 - t / 2) ;
677 input_report_abs(dev, ABS_WHEEL, t);
678 } else {
679 /* 4D mouse rotation packet */
680 t = (data[6] << 3) | ((data[7] >> 5) & 7);
681 input_report_abs(dev, ABS_RZ, (data[7] & 0x20) ?
682 ((t - 1) / 2) : -t / 2);
683 }
684
685 } else if (!(data[1] & 0x10) && wacom->features->type < INTUOS3) {
686 /* 4D mouse packet */
687 input_report_key(dev, BTN_LEFT, data[8] & 0x01);
688 input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
689 input_report_key(dev, BTN_RIGHT, data[8] & 0x04);
690
691 input_report_key(dev, BTN_SIDE, data[8] & 0x20);
692 input_report_key(dev, BTN_EXTRA, data[8] & 0x10);
693 t = (data[6] << 2) | ((data[7] >> 6) & 3);
694 input_report_abs(dev, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
695
696 } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
697 /* 2D mouse packet */
698 input_report_key(dev, BTN_LEFT, data[8] & 0x04);
699 input_report_key(dev, BTN_MIDDLE, data[8] & 0x08);
700 input_report_key(dev, BTN_RIGHT, data[8] & 0x10);
701 input_report_rel(dev, REL_WHEEL, (data[8] & 0x01)
702 - ((data[8] & 0x02) >> 1));
703
704 /* I3 2D mouse side buttons */
705 if (wacom->features->type == INTUOS3) {
706 input_report_key(dev, BTN_SIDE, data[8] & 0x40);
707 input_report_key(dev, BTN_EXTRA, data[8] & 0x20);
708 }
709
710 } else if (wacom->features->type < INTUOS3) {
711 /* Lens cursor packets */
712 input_report_key(dev, BTN_LEFT, data[8] & 0x01);
713 input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
714 input_report_key(dev, BTN_RIGHT, data[8] & 0x04);
715 input_report_key(dev, BTN_SIDE, data[8] & 0x10);
716 input_report_key(dev, BTN_EXTRA, data[8] & 0x08);
717 }
718 }
719
720 input_report_abs(dev, ABS_MISC, wacom->id[idx]); /* report tool id */
721 input_report_key(dev, wacom->tool[idx], 1);
722 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
723 input_sync(dev);
724
725exit:
726 retval = usb_submit_urb (urb, GFP_ATOMIC);
727 if (retval)
728 err ("%s - usb_submit_urb failed with result %d",
729 __FUNCTION__, retval);
730}
731
732static struct wacom_features wacom_features[] = {
733 { "Wacom Penpartner", 7, 5040, 3780, 255, 32, PENPARTNER, wacom_penpartner_irq },
734 { "Wacom Graphire", 8, 10206, 7422, 511, 32, GRAPHIRE, wacom_graphire_irq },
735 { "Wacom Graphire2 4x5", 8, 10206, 7422, 511, 32, GRAPHIRE, wacom_graphire_irq },
736 { "Wacom Graphire2 5x7", 8, 13918, 10206, 511, 32, GRAPHIRE, wacom_graphire_irq },
737 { "Wacom Graphire3", 8, 10208, 7424, 511, 32, GRAPHIRE, wacom_graphire_irq },
738 { "Wacom Graphire3 6x8", 8, 16704, 12064, 511, 32, GRAPHIRE, wacom_graphire_irq },
739 { "Wacom Graphire4 4x5", 8, 10208, 7424, 511, 32, WACOM_G4, wacom_graphire_irq },
740 { "Wacom Graphire4 6x8", 8, 16704, 12064, 511, 32, WACOM_G4, wacom_graphire_irq },
741 { "Wacom Volito", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_graphire_irq },
742 { "Wacom PenStation2", 8, 3250, 2320, 255, 32, GRAPHIRE, wacom_graphire_irq },
743 { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_graphire_irq },
744 { "Wacom Volito2 2x3", 8, 3248, 2320, 511, 32, GRAPHIRE, wacom_graphire_irq },
745 { "Wacom PenPartner2", 8, 3250, 2320, 255, 32, GRAPHIRE, wacom_graphire_irq },
746 { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_intuos_irq },
747 { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
748 { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 15, INTUOS, wacom_intuos_irq },
749 { "Wacom Intuos 12x12", 10, 30480, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
750 { "Wacom Intuos 12x18", 10, 45720, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
751 { "Wacom PL400", 8, 5408, 4056, 255, 32, PL, wacom_pl_irq },
752 { "Wacom PL500", 8, 6144, 4608, 255, 32, PL, wacom_pl_irq },
753 { "Wacom PL600", 8, 6126, 4604, 255, 32, PL, wacom_pl_irq },
754 { "Wacom PL600SX", 8, 6260, 5016, 255, 32, PL, wacom_pl_irq },
755 { "Wacom PL550", 8, 6144, 4608, 511, 32, PL, wacom_pl_irq },
756 { "Wacom PL800", 8, 7220, 5780, 511, 32, PL, wacom_pl_irq },
757 { "Wacom PL700", 8, 6758, 5406, 511, 32, PL, wacom_pl_irq },
758 { "Wacom PL510", 8, 6282, 4762, 511, 32, PL, wacom_pl_irq },
759 { "Wacom DTU710", 8, 34080, 27660, 511, 32, PL, wacom_pl_irq },
760 { "Wacom DTF521", 8, 6282, 4762, 511, 32, PL, wacom_pl_irq },
761 { "Wacom DTF720", 8, 6858, 5506, 511, 32, PL, wacom_pl_irq },
762 { "Wacom Cintiq Partner",8, 20480, 15360, 511, 32, PL, wacom_ptu_irq },
763 { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_intuos_irq },
764 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
765 { "Wacom Intuos2 9x12", 10, 30480, 24060, 1023, 15, INTUOS, wacom_intuos_irq },
766 { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
767 { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
768 { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 15, INTUOS3, wacom_intuos_irq },
769 { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 15, INTUOS3, wacom_intuos_irq },
770 { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 15, INTUOS3, wacom_intuos_irq },
771 { "Wacom Intuos3 12x12", 10, 60960, 60960, 1023, 15, INTUOS312, wacom_intuos_irq },
772 { "Wacom Intuos3 12x19", 10, 97536, 60960, 1023, 15, INTUOS319, wacom_intuos_irq },
773 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 15, INTUOS3, wacom_intuos_irq },
774 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 15, CINTIQ, wacom_intuos_irq },
775 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
776 { }
777};
778
779static struct usb_device_id wacom_ids[] = {
780 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x00) },
781 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x10) },
782 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x11) },
783 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x12) },
784 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x13) },
785 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x14) },
786 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x15) },
787 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x16) },
788 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x60) },
789 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x61) },
790 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x62) },
791 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x63) },
792 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x64) },
793 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x20) },
794 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x21) },
795 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x22) },
796 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x23) },
797 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x24) },
798 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x30) },
799 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x31) },
800 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x32) },
801 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x33) },
802 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x34) },
803 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x35) },
804 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x37) },
805 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x38) },
806 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x39) },
807 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC0) },
808 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC3) },
809 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x03) },
810 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x41) },
811 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x42) },
812 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x43) },
813 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x44) },
814 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x45) },
815 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0) },
816 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1) },
817 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2) },
818 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB3) },
819 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB4) },
820 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB5) },
821 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) },
822 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) },
823 { }
824};
825
826MODULE_DEVICE_TABLE(usb, wacom_ids);
827
828static int wacom_open(struct input_dev *dev)
829{
830 struct wacom *wacom = dev->private;
831
832 wacom->irq->dev = wacom->usbdev;
833 if (usb_submit_urb(wacom->irq, GFP_KERNEL))
834 return -EIO;
835
836 return 0;
837}
838
839static void wacom_close(struct input_dev *dev)
840{
841 struct wacom *wacom = dev->private;
842
843 usb_kill_urb(wacom->irq);
844}
845
846static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
847{
848 struct usb_device *dev = interface_to_usbdev(intf);
849 struct usb_endpoint_descriptor *endpoint;
850 struct wacom *wacom;
851 struct input_dev *input_dev;
852 char rep_data[2], limit = 0;
853
854 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
855 input_dev = input_allocate_device();
856 if (!wacom || !input_dev)
857 goto fail1;
858
859 wacom->data = usb_buffer_alloc(dev, 10, GFP_KERNEL, &wacom->data_dma);
860 if (!wacom->data)
861 goto fail1;
862
863 wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
864 if (!wacom->irq)
865 goto fail2;
866
867 wacom->usbdev = dev;
868 wacom->dev = input_dev;
869 usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
870 strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
871
872 wacom->features = wacom_features + (id - wacom_ids);
873 if (wacom->features->pktlen > 10)
874 BUG();
875
876 input_dev->name = wacom->features->name;
877 usb_to_input_id(dev, &input_dev->id);
878
879 input_dev->cdev.dev = &intf->dev;
880 input_dev->private = wacom;
881 input_dev->open = wacom_open;
882 input_dev->close = wacom_close;
883
884 input_dev->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS);
885 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH) | BIT(BTN_STYLUS);
886 input_set_abs_params(input_dev, ABS_X, 0, wacom->features->x_max, 4, 0);
887 input_set_abs_params(input_dev, ABS_Y, 0, wacom->features->y_max, 4, 0);
888 input_set_abs_params(input_dev, ABS_PRESSURE, 0, wacom->features->pressure_max, 0, 0);
889 input_dev->absbit[LONG(ABS_MISC)] |= BIT(ABS_MISC);
890
891 switch (wacom->features->type) {
892 case WACOM_G4:
893 input_dev->evbit[0] |= BIT(EV_MSC);
894 input_dev->mscbit[0] |= BIT(MSC_SERIAL);
895 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
896 input_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);
897 /* fall through */
898
899 case GRAPHIRE:
900 input_dev->evbit[0] |= BIT(EV_REL);
901 input_dev->relbit[0] |= BIT(REL_WHEEL);
902 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
903 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_STYLUS2);
904 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom->features->distance_max, 0, 0);
905 break;
906
907 case INTUOS3:
908 case INTUOS312:
909 case INTUOS319:
910 case CINTIQ:
911 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
912 input_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);
913 input_set_abs_params(input_dev, ABS_RX, 0, 4097, 0, 0);
914 input_set_abs_params(input_dev, ABS_RY, 0, 4097, 0, 0);
915 /* fall through */
916
917 case INTUOS:
918 input_dev->evbit[0] |= BIT(EV_MSC) | BIT(EV_REL);
919 input_dev->mscbit[0] |= BIT(MSC_SERIAL);
920 input_dev->relbit[0] |= BIT(REL_WHEEL);
921 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE) | BIT(BTN_SIDE) | BIT(BTN_EXTRA);
922 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_TOOL_BRUSH)
923 | BIT(BTN_TOOL_PENCIL) | BIT(BTN_TOOL_AIRBRUSH) | BIT(BTN_TOOL_LENS) | BIT(BTN_STYLUS2);
924 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom->features->distance_max, 0, 0);
925 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
926 input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0);
927 input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0);
928 input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
929 input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
930 break;
931
932 case PL:
933 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_STYLUS2) | BIT(BTN_TOOL_RUBBER);
934 break;
935 }
936
937 endpoint = &intf->cur_altsetting->endpoint[0].desc;
938
939 if (wacom->features->pktlen > 10)
940 BUG();
941
942 usb_fill_int_urb(wacom->irq, dev,
943 usb_rcvintpipe(dev, endpoint->bEndpointAddress),
944 wacom->data, wacom->features->pktlen,
945 wacom->features->irq, wacom, endpoint->bInterval);
946 wacom->irq->transfer_dma = wacom->data_dma;
947 wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
948
949 input_register_device(wacom->dev);
950
951 /* Ask the tablet to report tablet data. Repeat until it succeeds */
952 do {
953 rep_data[0] = 2;
954 rep_data[1] = 2;
955 usb_set_report(intf, 3, 2, rep_data, 2);
956 usb_get_report(intf, 3, 2, rep_data, 2);
957 } while (rep_data[1] != 2 && limit++ < 5);
958
959 usb_set_intfdata(intf, wacom);
960 return 0;
961
962fail2: usb_buffer_free(dev, 10, wacom->data, wacom->data_dma);
963fail1: input_free_device(input_dev);
964 kfree(wacom);
965 return -ENOMEM;
966}
967
968static void wacom_disconnect(struct usb_interface *intf)
969{
970 struct wacom *wacom = usb_get_intfdata (intf);
971
972 usb_set_intfdata(intf, NULL);
973 if (wacom) {
974 usb_kill_urb(wacom->irq);
975 input_unregister_device(wacom->dev);
976 usb_free_urb(wacom->irq);
977 usb_buffer_free(interface_to_usbdev(intf), 10, wacom->data, wacom->data_dma);
978 kfree(wacom);
979 }
980}
981
982static struct usb_driver wacom_driver = {
983 .name = "wacom",
984 .probe = wacom_probe,
985 .disconnect = wacom_disconnect,
986 .id_table = wacom_ids,
987};
988
989static int __init wacom_init(void)
990{
991 int result = usb_register(&wacom_driver);
992 if (result == 0)
993 info(DRIVER_VERSION ":" DRIVER_DESC);
994 return result;
995}
996
997static void __exit wacom_exit(void)
998{
999 usb_deregister(&wacom_driver);
1000}
1001
1002module_init(wacom_init);
1003module_exit(wacom_exit);
diff --git a/drivers/usb/input/wacom.h b/drivers/usb/input/wacom.h
new file mode 100644
index 000000000000..832737b658cf
--- /dev/null
+++ b/drivers/usb/input/wacom.h
@@ -0,0 +1,132 @@
1/*
2 * drivers/usb/input/wacom.h
3 *
4 * USB Wacom Graphire and Wacom Intuos tablet support
5 *
6 * Copyright (c) 2000-2004 Vojtech Pavlik <vojtech@ucw.cz>
7 * Copyright (c) 2000 Andreas Bach Aaen <abach@stofanet.dk>
8 * Copyright (c) 2000 Clifford Wolf <clifford@clifford.at>
9 * Copyright (c) 2000 Sam Mosel <sam.mosel@computer.org>
10 * Copyright (c) 2000 James E. Blair <corvus@gnu.org>
11 * Copyright (c) 2000 Daniel Egger <egger@suse.de>
12 * Copyright (c) 2001 Frederic Lepied <flepied@mandrakesoft.com>
13 * Copyright (c) 2004 Panagiotis Issaris <panagiotis.issaris@mech.kuleuven.ac.be>
14 * Copyright (c) 2002-2006 Ping Cheng <pingc@wacom.com>
15 *
16 * ChangeLog:
17 * v0.1 (vp) - Initial release
18 * v0.2 (aba) - Support for all buttons / combinations
19 * v0.3 (vp) - Support for Intuos added
20 * v0.4 (sm) - Support for more Intuos models, menustrip
21 * relative mode, proximity.
22 * v0.5 (vp) - Big cleanup, nifty features removed,
23 * they belong in userspace
24 * v1.8 (vp) - Submit URB only when operating, moved to CVS,
25 * use input_report_key instead of report_btn and
26 * other cleanups
27 * v1.11 (vp) - Add URB ->dev setting for new kernels
28 * v1.11 (jb) - Add support for the 4D Mouse & Lens
29 * v1.12 (de) - Add support for two more inking pen IDs
30 * v1.14 (vp) - Use new USB device id probing scheme.
31 * Fix Wacom Graphire mouse wheel
32 * v1.18 (vp) - Fix mouse wheel direction
33 * Make mouse relative
34 * v1.20 (fl) - Report tool id for Intuos devices
35 * - Multi tools support
36 * - Corrected Intuos protocol decoding (airbrush, 4D mouse, lens cursor...)
37 * - Add PL models support
38 * - Fix Wacom Graphire mouse wheel again
39 * v1.21 (vp) - Removed protocol descriptions
40 * - Added MISC_SERIAL for tool serial numbers
41 * (gb) - Identify version on module load.
42 * v1.21.1 (fl) - added Graphire2 support
43 * v1.21.2 (fl) - added Intuos2 support
44 * - added all the PL ids
45 * v1.21.3 (fl) - added another eraser id from Neil Okamoto
46 * - added smooth filter for Graphire from Peri Hankey
47 * - added PenPartner support from Olaf van Es
48 * - new tool ids from Ole Martin Bjoerndalen
49 * v1.29 (pc) - Add support for more tablets
50 * - Fix pressure reporting
51 * v1.30 (vp) - Merge 2.4 and 2.5 drivers
52 * - Since 2.5 now has input_sync(), remove MSC_SERIAL abuse
53 * - Cleanups here and there
54 * v1.30.1 (pi) - Added Graphire3 support
55 * v1.40 (pc) - Add support for several new devices, fix eraser reporting, ...
56 * v1.43 (pc) - Added support for Cintiq 21UX
57 * - Fixed a Graphire bug
58 * - Merged wacom_intuos3_irq into wacom_intuos_irq
59 * v1.44 (pc) - Added support for Graphire4, Cintiq 710, Intuos3 6x11, etc.
60 * - Report Device IDs
61 * v1.45 (pc) - Added support for DTF 521, Intuos3 12x12 and 12x19
62 * - Minor data report fix
63 * v1.46 (pc) - Split wacom.c into wacom_sys.c and wacom_wac.c,
64 * - where wacom_sys.c deals with system specific code,
65 * - and wacom_wac.c deals with Wacom specific code
66 */
67
68/*
69 * This program is free software; you can redistribute it and/or modify
70 * it under the terms of the GNU General Public License as published by
71 * the Free Software Foundation; either version 2 of the License, or
72 * (at your option) any later version.
73 */
74#ifndef WACOM_H
75#define WACOM_H
76#include <linux/kernel.h>
77#include <linux/slab.h>
78#include <linux/module.h>
79#include <linux/init.h>
80#include <linux/usb/input.h>
81#include <asm/unaligned.h>
82
83/*
84 * Version Information
85 */
86#define DRIVER_VERSION "v1.46"
87#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
88#define DRIVER_DESC "USB Wacom Graphire and Wacom Intuos tablet driver"
89#define DRIVER_LICENSE "GPL"
90
91MODULE_AUTHOR(DRIVER_AUTHOR);
92MODULE_DESCRIPTION(DRIVER_DESC);
93MODULE_LICENSE(DRIVER_LICENSE);
94
95#define USB_VENDOR_ID_WACOM 0x056a
96
97struct wacom {
98 dma_addr_t data_dma;
99 struct input_dev *dev;
100 struct usb_device *usbdev;
101 struct urb *irq;
102 struct wacom_wac * wacom_wac;
103 char phys[32];
104};
105
106struct wacom_combo {
107 struct wacom * wacom;
108 struct urb * urb;
109 struct pt_regs *regs;
110};
111
112extern int wacom_wac_irq(struct wacom_wac * wacom_wac, void * wcombo);
113extern void wacom_sys_irq(struct urb *urb, struct pt_regs *regs);
114extern void wacom_report_abs(void *wcombo, unsigned int abs_type, int abs_data);
115extern void wacom_report_rel(void *wcombo, unsigned int rel_type, int rel_data);
116extern void wacom_report_key(void *wcombo, unsigned int key_type, int key_data);
117extern void wacom_input_event(void *wcombo, unsigned int type, unsigned int code, int value);
118extern void wacom_input_regs(void *wcombo);
119extern void wacom_input_sync(void *wcombo);
120extern void wacom_init_input_dev(struct input_dev *input_dev, struct wacom_wac *wacom_wac);
121extern void input_dev_g4(struct input_dev *input_dev, struct wacom_wac *wacom_wac);
122extern void input_dev_g(struct input_dev *input_dev, struct wacom_wac *wacom_wac);
123extern void input_dev_i3(struct input_dev *input_dev, struct wacom_wac *wacom_wac);
124extern void input_dev_i(struct input_dev *input_dev, struct wacom_wac *wacom_wac);
125extern void input_dev_pl(struct input_dev *input_dev, struct wacom_wac *wacom_wac);
126extern void input_dev_pt(struct input_dev *input_dev, struct wacom_wac *wacom_wac);
127extern __u16 wacom_le16_to_cpu(unsigned char *data);
128extern __u16 wacom_be16_to_cpu(unsigned char *data);
129extern struct wacom_features * get_wacom_feature(const struct usb_device_id *id);
130extern const struct usb_device_id * get_device_table(void);
131
132#endif
diff --git a/drivers/usb/input/wacom_sys.c b/drivers/usb/input/wacom_sys.c
new file mode 100644
index 000000000000..7c3b52bdd9d6
--- /dev/null
+++ b/drivers/usb/input/wacom_sys.c
@@ -0,0 +1,315 @@
1/*
2 * drivers/usb/input/wacom_sys.c
3 *
4 * USB Wacom Graphire and Wacom Intuos tablet support - system specific code
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
11 * (at your option) any later version.
12 */
13
14#include "wacom.h"
15#include "wacom_wac.h"
16
17#define USB_REQ_GET_REPORT 0x01
18#define USB_REQ_SET_REPORT 0x09
19
20static int usb_get_report(struct usb_interface *intf, unsigned char type,
21 unsigned char id, void *buf, int size)
22{
23 return usb_control_msg(interface_to_usbdev(intf),
24 usb_rcvctrlpipe(interface_to_usbdev(intf), 0),
25 USB_REQ_GET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
26 (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber,
27 buf, size, 100);
28}
29
30static int usb_set_report(struct usb_interface *intf, unsigned char type,
31 unsigned char id, void *buf, int size)
32{
33 return usb_control_msg(interface_to_usbdev(intf),
34 usb_sndctrlpipe(interface_to_usbdev(intf), 0),
35 USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
36 (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber,
37 buf, size, 1000);
38}
39
40static struct input_dev * get_input_dev(struct wacom_combo *wcombo)
41{
42 return wcombo->wacom->dev;
43}
44
45void wacom_sys_irq(struct urb *urb, struct pt_regs *regs)
46{
47 struct wacom *wacom = urb->context;
48 struct wacom_combo wcombo;
49 int retval;
50
51 switch (urb->status) {
52 case 0:
53 /* success */
54 break;
55 case -ECONNRESET:
56 case -ENOENT:
57 case -ESHUTDOWN:
58 /* this urb is terminated, clean up */
59 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
60 return;
61 default:
62 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
63 goto exit;
64 }
65
66 wcombo.wacom = wacom;
67 wcombo.urb = urb;
68 wcombo.regs = regs;
69
70 if (wacom_wac_irq(wacom->wacom_wac, (void *)&wcombo))
71 input_sync(get_input_dev(&wcombo));
72
73 exit:
74 retval = usb_submit_urb (urb, GFP_ATOMIC);
75 if (retval)
76 err ("%s - usb_submit_urb failed with result %d",
77 __FUNCTION__, retval);
78}
79
80void wacom_report_key(void *wcombo, unsigned int key_type, int key_data)
81{
82 input_report_key(get_input_dev((struct wacom_combo *)wcombo), key_type, key_data);
83 return;
84}
85
86void wacom_report_abs(void *wcombo, unsigned int abs_type, int abs_data)
87{
88 input_report_abs(get_input_dev((struct wacom_combo *)wcombo), abs_type, abs_data);
89 return;
90}
91
92void wacom_report_rel(void *wcombo, unsigned int rel_type, int rel_data)
93{
94 input_report_rel(get_input_dev((struct wacom_combo *)wcombo), rel_type, rel_data);
95 return;
96}
97
98void wacom_input_event(void *wcombo, unsigned int type, unsigned int code, int value)
99{
100 input_event(get_input_dev((struct wacom_combo *)wcombo), type, code, value);
101 return;
102}
103
104__u16 wacom_be16_to_cpu(unsigned char *data)
105{
106 __u16 value;
107 value = be16_to_cpu(*(__be16 *) data);
108 return value;
109}
110
111__u16 wacom_le16_to_cpu(unsigned char *data)
112{
113 __u16 value;
114 value = be16_to_cpu(*(__be16 *) data);
115 return value;
116}
117
118void wacom_input_regs(void *wcombo)
119{
120 input_regs(get_input_dev((struct wacom_combo *)wcombo), ((struct wacom_combo *)wcombo)->regs);
121 return;
122}
123
124void wacom_input_sync(void *wcombo)
125{
126 input_sync(get_input_dev((struct wacom_combo *)wcombo));
127 return;
128}
129
130static int wacom_open(struct input_dev *dev)
131{
132 struct wacom *wacom = dev->private;
133
134 wacom->irq->dev = wacom->usbdev;
135 if (usb_submit_urb(wacom->irq, GFP_KERNEL))
136 return -EIO;
137
138 return 0;
139}
140
141static void wacom_close(struct input_dev *dev)
142{
143 struct wacom *wacom = dev->private;
144
145 usb_kill_urb(wacom->irq);
146}
147
148void input_dev_g4(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
149{
150 input_dev->evbit[0] |= BIT(EV_MSC);
151 input_dev->mscbit[0] |= BIT(MSC_SERIAL);
152 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
153 input_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);
154}
155
156void input_dev_g(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
157{
158 input_dev->evbit[0] |= BIT(EV_REL);
159 input_dev->relbit[0] |= BIT(REL_WHEEL);
160 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
161 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_STYLUS2);
162 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom_wac->features->distance_max, 0, 0);
163}
164
165void input_dev_i3(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
166{
167 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
168 input_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);
169 input_set_abs_params(input_dev, ABS_RX, 0, 4097, 0, 0);
170 input_set_abs_params(input_dev, ABS_RY, 0, 4097, 0, 0);
171}
172
173void input_dev_i(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
174{
175 input_dev->evbit[0] |= BIT(EV_MSC) | BIT(EV_REL);
176 input_dev->mscbit[0] |= BIT(MSC_SERIAL);
177 input_dev->relbit[0] |= BIT(REL_WHEEL);
178 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE) | BIT(BTN_SIDE) | BIT(BTN_EXTRA);
179 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_TOOL_BRUSH)
180 | BIT(BTN_TOOL_PENCIL) | BIT(BTN_TOOL_AIRBRUSH) | BIT(BTN_TOOL_LENS) | BIT(BTN_STYLUS2);
181 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom_wac->features->distance_max, 0, 0);
182 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
183 input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0);
184 input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0);
185 input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
186 input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
187}
188
189void input_dev_pl(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
190{
191 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_STYLUS2) | BIT(BTN_TOOL_RUBBER);
192}
193
194void input_dev_pt(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
195{
196 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER);
197}
198
199static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
200{
201 struct usb_device *dev = interface_to_usbdev(intf);
202 struct usb_endpoint_descriptor *endpoint;
203 struct wacom *wacom;
204 struct wacom_wac *wacom_wac;
205 struct input_dev *input_dev;
206 char rep_data[2], limit = 0;
207
208 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
209 wacom_wac = kzalloc(sizeof(struct wacom_wac), GFP_KERNEL);
210 input_dev = input_allocate_device();
211 if (!wacom || !input_dev || !wacom_wac)
212 goto fail1;
213
214 wacom_wac->data = usb_buffer_alloc(dev, 10, GFP_KERNEL, &wacom->data_dma);
215 if (!wacom_wac->data)
216 goto fail1;
217
218 wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
219 if (!wacom->irq)
220 goto fail2;
221
222 wacom->usbdev = dev;
223 wacom->dev = input_dev;
224 usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
225 strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
226
227 wacom_wac->features = get_wacom_feature(id);
228 if (wacom_wac->features->pktlen > 10)
229 BUG();
230
231 input_dev->name = wacom_wac->features->name;
232 wacom->wacom_wac = wacom_wac;
233 usb_to_input_id(dev, &input_dev->id);
234
235 input_dev->cdev.dev = &intf->dev;
236 input_dev->private = wacom;
237 input_dev->open = wacom_open;
238 input_dev->close = wacom_close;
239
240 input_dev->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS);
241 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH) | BIT(BTN_STYLUS);
242 input_set_abs_params(input_dev, ABS_X, 0, wacom_wac->features->x_max, 4, 0);
243 input_set_abs_params(input_dev, ABS_Y, 0, wacom_wac->features->y_max, 4, 0);
244 input_set_abs_params(input_dev, ABS_PRESSURE, 0, wacom_wac->features->pressure_max, 0, 0);
245 input_dev->absbit[LONG(ABS_MISC)] |= BIT(ABS_MISC);
246
247 wacom_init_input_dev(input_dev, wacom_wac);
248
249 endpoint = &intf->cur_altsetting->endpoint[0].desc;
250
251 usb_fill_int_urb(wacom->irq, dev,
252 usb_rcvintpipe(dev, endpoint->bEndpointAddress),
253 wacom_wac->data, wacom_wac->features->pktlen,
254 wacom_wac->features->irq, wacom, endpoint->bInterval);
255 wacom->irq->transfer_dma = wacom->data_dma;
256 wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
257
258 input_register_device(wacom->dev);
259
260 /* Ask the tablet to report tablet data. Repeat until it succeeds */
261 do {
262 rep_data[0] = 2;
263 rep_data[1] = 2;
264 usb_set_report(intf, 3, 2, rep_data, 2);
265 usb_get_report(intf, 3, 2, rep_data, 2);
266 } while (rep_data[1] != 2 && limit++ < 5);
267
268 usb_set_intfdata(intf, wacom);
269 return 0;
270
271fail2: usb_buffer_free(dev, 10, wacom_wac->data, wacom->data_dma);
272fail1: input_free_device(input_dev);
273 kfree(wacom);
274 kfree(wacom_wac);
275 return -ENOMEM;
276}
277
278static void wacom_disconnect(struct usb_interface *intf)
279{
280 struct wacom *wacom = usb_get_intfdata (intf);
281
282 usb_set_intfdata(intf, NULL);
283 if (wacom) {
284 usb_kill_urb(wacom->irq);
285 input_unregister_device(wacom->dev);
286 usb_free_urb(wacom->irq);
287 usb_buffer_free(interface_to_usbdev(intf), 10, wacom->wacom_wac->data, wacom->data_dma);
288 kfree(wacom);
289 kfree(wacom->wacom_wac);
290 }
291}
292
293static struct usb_driver wacom_driver = {
294 .name = "wacom",
295 .probe = wacom_probe,
296 .disconnect = wacom_disconnect,
297};
298
299static int __init wacom_init(void)
300{
301 int result;
302 wacom_driver.id_table = get_device_table();
303 result = usb_register(&wacom_driver);
304 if (result == 0)
305 info(DRIVER_VERSION ":" DRIVER_DESC);
306 return result;
307}
308
309static void __exit wacom_exit(void)
310{
311 usb_deregister(&wacom_driver);
312}
313
314module_init(wacom_init);
315module_exit(wacom_exit);
diff --git a/drivers/usb/input/wacom_wac.c b/drivers/usb/input/wacom_wac.c
new file mode 100644
index 000000000000..85d458c98b6e
--- /dev/null
+++ b/drivers/usb/input/wacom_wac.c
@@ -0,0 +1,646 @@
1/*
2 * drivers/usb/input/wacom_wac.c
3 *
4 * USB Wacom Graphire and Wacom Intuos tablet support - Wacom specific code
5 *
6 */
7
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#include "wacom.h"
15#include "wacom_wac.h"
16
17static int wacom_penpartner_irq(struct wacom_wac *wacom, void *wcombo)
18{
19 unsigned char *data = wacom->data;
20
21 switch (data[0]) {
22 case 1:
23 wacom_input_regs(wcombo);
24 if (data[5] & 0x80) {
25 wacom->tool[0] = (data[5] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
26 wacom->id[0] = (data[5] & 0x20) ? ERASER_DEVICE_ID : STYLUS_DEVICE_ID;
27 wacom_report_key(wcombo, wacom->tool[0], 1);
28 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); /* report tool id */
29 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[1]));
30 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[3]));
31 wacom_report_abs(wcombo, ABS_PRESSURE, (signed char)data[6] + 127);
32 wacom_report_key(wcombo, BTN_TOUCH, ((signed char)data[6] > -127));
33 wacom_report_key(wcombo, BTN_STYLUS, (data[5] & 0x40));
34 } else {
35 wacom_report_key(wcombo, wacom->tool[0], 0);
36 wacom_report_abs(wcombo, ABS_MISC, 0); /* report tool id */
37 wacom_report_abs(wcombo, ABS_PRESSURE, -1);
38 wacom_report_key(wcombo, BTN_TOUCH, 0);
39 }
40 break;
41 case 2:
42 wacom_input_regs(wcombo);
43 wacom_report_key(wcombo, BTN_TOOL_PEN, 1);
44 wacom_report_abs(wcombo, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
45 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[1]));
46 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[3]));
47 wacom_report_abs(wcombo, ABS_PRESSURE, (signed char)data[6] + 127);
48 wacom_report_key(wcombo, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
49 wacom_report_key(wcombo, BTN_STYLUS, (data[5] & 0x40));
50 break;
51 default:
52 printk(KERN_INFO "wacom_penpartner_irq: received unknown report #%d\n", data[0]);
53 return 0;
54 }
55 return 1;
56}
57
58static int wacom_pl_irq(struct wacom_wac *wacom, void *wcombo)
59{
60 unsigned char *data = wacom->data;
61 int prox, id, pressure;
62
63 if (data[0] != 2) {
64 dbg("wacom_pl_irq: received unknown report #%d", data[0]);
65 return 0;
66 }
67
68 prox = data[1] & 0x40;
69
70 wacom_input_regs(wcombo);
71
72 id = ERASER_DEVICE_ID;
73 if (prox) {
74
75 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
76 if (wacom->features->pressure_max > 255)
77 pressure = (pressure << 1) | ((data[4] >> 6) & 1);
78 pressure += (wacom->features->pressure_max + 1) / 2;
79
80 /*
81 * if going from out of proximity into proximity select between the eraser
82 * and the pen based on the state of the stylus2 button, choose eraser if
83 * pressed else choose pen. if not a proximity change from out to in, send
84 * an out of proximity for previous tool then a in for new tool.
85 */
86 if (!wacom->tool[0]) {
87 /* Eraser bit set for DTF */
88 if (data[1] & 0x10)
89 wacom->tool[1] = BTN_TOOL_RUBBER;
90 else
91 /* Going into proximity select tool */
92 wacom->tool[1] = (data[4] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
93 } else {
94 /* was entered with stylus2 pressed */
95 if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
96 /* report out proximity for previous tool */
97 wacom_report_key(wcombo, wacom->tool[1], 0);
98 wacom_input_sync(wcombo);
99 wacom->tool[1] = BTN_TOOL_PEN;
100 return 0;
101 }
102 }
103 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
104 /* Unknown tool selected default to pen tool */
105 wacom->tool[1] = BTN_TOOL_PEN;
106 id = STYLUS_DEVICE_ID;
107 }
108 wacom_report_key(wcombo, wacom->tool[1], prox); /* report in proximity for tool */
109 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */
110 wacom_report_abs(wcombo, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
111 wacom_report_abs(wcombo, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
112 wacom_report_abs(wcombo, ABS_PRESSURE, pressure);
113
114 wacom_report_key(wcombo, BTN_TOUCH, data[4] & 0x08);
115 wacom_report_key(wcombo, BTN_STYLUS, data[4] & 0x10);
116 /* Only allow the stylus2 button to be reported for the pen tool. */
117 wacom_report_key(wcombo, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20));
118 } else {
119 /* report proximity-out of a (valid) tool */
120 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
121 /* Unknown tool selected default to pen tool */
122 wacom->tool[1] = BTN_TOOL_PEN;
123 }
124 wacom_report_key(wcombo, wacom->tool[1], prox);
125 }
126
127 wacom->tool[0] = prox; /* Save proximity state */
128 return 1;
129}
130
131static int wacom_ptu_irq(struct wacom_wac *wacom, void *wcombo)
132{
133 unsigned char *data = wacom->data;
134 int id;
135
136 if (data[0] != 2) {
137 printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]);
138 return 0;
139 }
140
141 wacom_input_regs(wcombo);
142 if (data[1] & 0x04) {
143 wacom_report_key(wcombo, BTN_TOOL_RUBBER, data[1] & 0x20);
144 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x08);
145 id = ERASER_DEVICE_ID;
146 } else {
147 wacom_report_key(wcombo, BTN_TOOL_PEN, data[1] & 0x20);
148 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x01);
149 id = STYLUS_DEVICE_ID;
150 }
151 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */
152 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[2]));
153 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[4]));
154 wacom_report_abs(wcombo, ABS_PRESSURE, wacom_le16_to_cpu(&data[6]));
155 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02);
156 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x10);
157 return 1;
158}
159
160static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
161{
162 unsigned char *data = wacom->data;
163 int x, y, id, rw;
164
165 if (data[0] != 2) {
166 dbg("wacom_graphire_irq: received unknown report #%d", data[0]);
167 return 0;
168 }
169
170 wacom_input_regs(wcombo);
171
172 id = STYLUS_DEVICE_ID;
173 if (data[1] & 0x10) { /* in prox */
174
175 switch ((data[1] >> 5) & 3) {
176
177 case 0: /* Pen */
178 wacom->tool[0] = BTN_TOOL_PEN;
179 break;
180
181 case 1: /* Rubber */
182 wacom->tool[0] = BTN_TOOL_RUBBER;
183 id = ERASER_DEVICE_ID;
184 break;
185
186 case 2: /* Mouse with wheel */
187 wacom_report_key(wcombo, BTN_MIDDLE, data[1] & 0x04);
188 if (wacom->features->type == WACOM_G4) {
189 rw = data[7] & 0x04 ? (data[7] & 0x03)-4 : (data[7] & 0x03);
190 wacom_report_rel(wcombo, REL_WHEEL, -rw);
191 } else
192 wacom_report_rel(wcombo, REL_WHEEL, -(signed char) data[6]);
193 /* fall through */
194
195 case 3: /* Mouse without wheel */
196 wacom->tool[0] = BTN_TOOL_MOUSE;
197 id = CURSOR_DEVICE_ID;
198 wacom_report_key(wcombo, BTN_LEFT, data[1] & 0x01);
199 wacom_report_key(wcombo, BTN_RIGHT, data[1] & 0x02);
200 if (wacom->features->type == WACOM_G4)
201 wacom_report_abs(wcombo, ABS_DISTANCE, data[6]);
202 else
203 wacom_report_abs(wcombo, ABS_DISTANCE, data[7]);
204 break;
205 }
206 }
207
208 if (data[1] & 0x90) {
209 x = wacom_le16_to_cpu(&data[2]);
210 y = wacom_le16_to_cpu(&data[4]);
211 wacom_report_abs(wcombo, ABS_X, x);
212 wacom_report_abs(wcombo, ABS_Y, y);
213 if (wacom->tool[0] != BTN_TOOL_MOUSE) {
214 wacom_report_abs(wcombo, ABS_PRESSURE, data[6] | ((data[7] & 0x01) << 8));
215 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x01);
216 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02);
217 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x04);
218 }
219 }
220
221 if (data[1] & 0x10)
222 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */
223 else
224 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */
225 wacom_report_key(wcombo, wacom->tool[0], data[1] & 0x10);
226 wacom_input_sync(wcombo);
227
228 /* send pad data */
229 if (wacom->features->type == WACOM_G4) {
230 if ( (wacom->serial[1] & 0xc0) != (data[7] & 0xf8) ) {
231 wacom->id[1] = 1;
232 wacom->serial[1] = (data[7] & 0xf8);
233 wacom_report_key(wcombo, BTN_0, (data[7] & 0x40));
234 wacom_report_key(wcombo, BTN_4, (data[7] & 0x80));
235 rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
236 wacom_report_rel(wcombo, REL_WHEEL, rw);
237 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0);
238 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
239 } else if (wacom->id[1]) {
240 wacom->id[1] = 0;
241 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0);
242 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
243 }
244 }
245 return 1;
246}
247
248static int wacom_intuos_inout(struct wacom_wac *wacom, void *wcombo)
249{
250 unsigned char *data = wacom->data;
251 int idx;
252
253 /* tool number */
254 idx = data[1] & 0x01;
255
256 /* Enter report */
257 if ((data[1] & 0xfc) == 0xc0) {
258 /* serial number of the tool */
259 wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
260 (data[4] << 20) + (data[5] << 12) +
261 (data[6] << 4) + (data[7] >> 4);
262
263 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4);
264 switch (wacom->id[idx]) {
265 case 0x812: /* Inking pen */
266 case 0x801: /* Intuos3 Inking pen */
267 case 0x012:
268 wacom->tool[idx] = BTN_TOOL_PENCIL;
269 break;
270 case 0x822: /* Pen */
271 case 0x842:
272 case 0x852:
273 case 0x823: /* Intuos3 Grip Pen */
274 case 0x813: /* Intuos3 Classic Pen */
275 case 0x885: /* Intuos3 Marker Pen */
276 case 0x022:
277 wacom->tool[idx] = BTN_TOOL_PEN;
278 break;
279 case 0x832: /* Stroke pen */
280 case 0x032:
281 wacom->tool[idx] = BTN_TOOL_BRUSH;
282 break;
283 case 0x007: /* Mouse 4D and 2D */
284 case 0x09c:
285 case 0x094:
286 case 0x017: /* Intuos3 2D Mouse */
287 wacom->tool[idx] = BTN_TOOL_MOUSE;
288 break;
289 case 0x096: /* Lens cursor */
290 case 0x097: /* Intuos3 Lens cursor */
291 wacom->tool[idx] = BTN_TOOL_LENS;
292 break;
293 case 0x82a: /* Eraser */
294 case 0x85a:
295 case 0x91a:
296 case 0xd1a:
297 case 0x0fa:
298 case 0x82b: /* Intuos3 Grip Pen Eraser */
299 case 0x81b: /* Intuos3 Classic Pen Eraser */
300 case 0x91b: /* Intuos3 Airbrush Eraser */
301 wacom->tool[idx] = BTN_TOOL_RUBBER;
302 break;
303 case 0xd12:
304 case 0x912:
305 case 0x112:
306 case 0x913: /* Intuos3 Airbrush */
307 wacom->tool[idx] = BTN_TOOL_AIRBRUSH;
308 break;
309 default: /* Unknown tool */
310 wacom->tool[idx] = BTN_TOOL_PEN;
311 }
312 /* only large I3 support Lens Cursor */
313 if(!((wacom->tool[idx] == BTN_TOOL_LENS) &&
314 (wacom->features->type == INTUOS3))) {
315 wacom_report_abs(wcombo, ABS_MISC, wacom->id[idx]); /* report tool id */
316 wacom_report_key(wcombo, wacom->tool[idx], 1);
317 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
318 return 2;
319 }
320 return 1;
321 }
322
323 /* Exit report */
324 if ((data[1] & 0xfe) == 0x80) {
325 wacom_report_key(wcombo, wacom->tool[idx], 0);
326 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */
327 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
328 return 2;
329 }
330 return 0;
331}
332
333static void wacom_intuos_general(struct wacom_wac *wacom, void *wcombo)
334{
335 unsigned char *data = wacom->data;
336 unsigned int t;
337
338 /* general pen packet */
339 if ((data[1] & 0xb8) == 0xa0) {
340 t = (data[6] << 2) | ((data[7] >> 6) & 3);
341 wacom_report_abs(wcombo, ABS_PRESSURE, t);
342 wacom_report_abs(wcombo, ABS_TILT_X,
343 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
344 wacom_report_abs(wcombo, ABS_TILT_Y, data[8] & 0x7f);
345 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 2);
346 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 4);
347 wacom_report_key(wcombo, BTN_TOUCH, t > 10);
348 }
349
350 /* airbrush second packet */
351 if ((data[1] & 0xbc) == 0xb4) {
352 wacom_report_abs(wcombo, ABS_WHEEL,
353 (data[6] << 2) | ((data[7] >> 6) & 3));
354 wacom_report_abs(wcombo, ABS_TILT_X,
355 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
356 wacom_report_abs(wcombo, ABS_TILT_Y, data[8] & 0x7f);
357 }
358 return;
359}
360
361static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
362{
363 unsigned char *data = wacom->data;
364 unsigned int t;
365 int idx, result;
366
367 if (data[0] != 2 && data[0] != 5 && data[0] != 6 && data[0] != 12) {
368 dbg("wacom_intuos_irq: received unknown report #%d", data[0]);
369 return 0;
370 }
371
372 wacom_input_regs(wcombo);
373
374 /* tool number */
375 idx = data[1] & 0x01;
376
377 /* pad packets. Works as a second tool and is always in prox */
378 if (data[0] == 12) {
379 /* initiate the pad as a device */
380 if (wacom->tool[1] != BTN_TOOL_FINGER)
381 wacom->tool[1] = BTN_TOOL_FINGER;
382
383 wacom_report_key(wcombo, BTN_0, (data[5] & 0x01));
384 wacom_report_key(wcombo, BTN_1, (data[5] & 0x02));
385 wacom_report_key(wcombo, BTN_2, (data[5] & 0x04));
386 wacom_report_key(wcombo, BTN_3, (data[5] & 0x08));
387 wacom_report_key(wcombo, BTN_4, (data[6] & 0x01));
388 wacom_report_key(wcombo, BTN_5, (data[6] & 0x02));
389 wacom_report_key(wcombo, BTN_6, (data[6] & 0x04));
390 wacom_report_key(wcombo, BTN_7, (data[6] & 0x08));
391 wacom_report_abs(wcombo, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
392 wacom_report_abs(wcombo, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
393
394 if((data[5] & 0x0f) | (data[6] & 0x0f) | (data[1] & 0x1f) | data[2])
395 wacom_report_key(wcombo, wacom->tool[1], 1);
396 else
397 wacom_report_key(wcombo, wacom->tool[1], 0);
398 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xffffffff);
399 return 1;
400 }
401
402 /* process in/out prox events */
403 result = wacom_intuos_inout(wacom, wcombo);
404 if (result)
405 return result-1;
406
407 /* Cintiq doesn't send data when RDY bit isn't set */
408 if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40))
409 return 0;
410
411 if (wacom->features->type >= INTUOS3) {
412 wacom_report_abs(wcombo, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
413 wacom_report_abs(wcombo, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
414 wacom_report_abs(wcombo, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
415 } else {
416 wacom_report_abs(wcombo, ABS_X, wacom_be16_to_cpu(&data[2]));
417 wacom_report_abs(wcombo, ABS_Y, wacom_be16_to_cpu(&data[4]));
418 wacom_report_abs(wcombo, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
419 }
420
421 /* process general packets */
422 wacom_intuos_general(wacom, wcombo);
423
424 /* 4D mouse, 2D mouse, marker pen rotation, or Lens cursor packets */
425 if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0) {
426
427 if (data[1] & 0x02) {
428 /* Rotation packet */
429 if (wacom->features->type >= INTUOS3) {
430 /* I3 marker pen rotation reported as wheel
431 * due to valuator limitation
432 */
433 t = (data[6] << 3) | ((data[7] >> 5) & 7);
434 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
435 ((t-1) / 2 + 450)) : (450 - t / 2) ;
436 wacom_report_abs(wcombo, ABS_WHEEL, t);
437 } else {
438 /* 4D mouse rotation packet */
439 t = (data[6] << 3) | ((data[7] >> 5) & 7);
440 wacom_report_abs(wcombo, ABS_RZ, (data[7] & 0x20) ?
441 ((t - 1) / 2) : -t / 2);
442 }
443
444 } else if (!(data[1] & 0x10) && wacom->features->type < INTUOS3) {
445 /* 4D mouse packet */
446 wacom_report_key(wcombo, BTN_LEFT, data[8] & 0x01);
447 wacom_report_key(wcombo, BTN_MIDDLE, data[8] & 0x02);
448 wacom_report_key(wcombo, BTN_RIGHT, data[8] & 0x04);
449
450 wacom_report_key(wcombo, BTN_SIDE, data[8] & 0x20);
451 wacom_report_key(wcombo, BTN_EXTRA, data[8] & 0x10);
452 t = (data[6] << 2) | ((data[7] >> 6) & 3);
453 wacom_report_abs(wcombo, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
454
455 } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
456 /* 2D mouse packet */
457 wacom_report_key(wcombo, BTN_LEFT, data[8] & 0x04);
458 wacom_report_key(wcombo, BTN_MIDDLE, data[8] & 0x08);
459 wacom_report_key(wcombo, BTN_RIGHT, data[8] & 0x10);
460 wacom_report_rel(wcombo, REL_WHEEL, (data[8] & 0x01)
461 - ((data[8] & 0x02) >> 1));
462
463 /* I3 2D mouse side buttons */
464 if (wacom->features->type == INTUOS3) {
465 wacom_report_key(wcombo, BTN_SIDE, data[8] & 0x40);
466 wacom_report_key(wcombo, BTN_EXTRA, data[8] & 0x20);
467 }
468
469 } else if (wacom->features->type < INTUOS3) {
470 /* Lens cursor packets */
471 wacom_report_key(wcombo, BTN_LEFT, data[8] & 0x01);
472 wacom_report_key(wcombo, BTN_MIDDLE, data[8] & 0x02);
473 wacom_report_key(wcombo, BTN_RIGHT, data[8] & 0x04);
474 wacom_report_key(wcombo, BTN_SIDE, data[8] & 0x10);
475 wacom_report_key(wcombo, BTN_EXTRA, data[8] & 0x08);
476 }
477 }
478
479 wacom_report_abs(wcombo, ABS_MISC, wacom->id[idx]); /* report tool id */
480 wacom_report_key(wcombo, wacom->tool[idx], 1);
481 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
482 return 1;
483}
484
485int wacom_wac_irq(struct wacom_wac *wacom_wac, void *wcombo)
486{
487 switch (wacom_wac->features->type) {
488 case PENPARTNER:
489 return (wacom_penpartner_irq(wacom_wac, wcombo));
490 break;
491 case PL:
492 return (wacom_pl_irq(wacom_wac, wcombo));
493 break;
494 case WACOM_G4:
495 case GRAPHIRE:
496 return (wacom_graphire_irq(wacom_wac, wcombo));
497 break;
498 case PTU:
499 return (wacom_ptu_irq(wacom_wac, wcombo));
500 break;
501 case INTUOS:
502 case INTUOS3:
503 case INTUOS3L:
504 case CINTIQ:
505 return (wacom_intuos_irq(wacom_wac, wcombo));
506 break;
507 default:
508 return 0;
509 }
510 return 0;
511}
512
513void wacom_init_input_dev(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
514{
515 switch (wacom_wac->features->type) {
516 case WACOM_G4:
517 input_dev_g4(input_dev, wacom_wac);
518 /* fall through */
519 case GRAPHIRE:
520 input_dev_g(input_dev, wacom_wac);
521 break;
522 case INTUOS3:
523 case INTUOS3L:
524 case CINTIQ:
525 input_dev_i3(input_dev, wacom_wac);
526 /* fall through */
527 case INTUOS:
528 input_dev_i(input_dev, wacom_wac);
529 break;
530 case PL:
531 case PTU:
532 input_dev_pl(input_dev, wacom_wac);
533 break;
534 case PENPARTNER:
535 input_dev_pt(input_dev, wacom_wac);
536 break;
537 }
538 return;
539}
540
541static struct wacom_features wacom_features[] = {
542 { "Wacom Penpartner", 7, 5040, 3780, 255, 32, PENPARTNER, wacom_sys_irq },
543 { "Wacom Graphire", 8, 10206, 7422, 511, 32, GRAPHIRE, wacom_sys_irq },
544 { "Wacom Graphire2 4x5", 8, 10206, 7422, 511, 32, GRAPHIRE, wacom_sys_irq },
545 { "Wacom Graphire2 5x7", 8, 13918, 10206, 511, 32, GRAPHIRE, wacom_sys_irq },
546 { "Wacom Graphire3", 8, 10208, 7424, 511, 32, GRAPHIRE, wacom_sys_irq },
547 { "Wacom Graphire3 6x8", 8, 16704, 12064, 511, 32, GRAPHIRE, wacom_sys_irq },
548 { "Wacom Graphire4 4x5", 8, 10208, 7424, 511, 32, WACOM_G4, wacom_sys_irq },
549 { "Wacom Graphire4 6x8", 8, 16704, 12064, 511, 32, WACOM_G4, wacom_sys_irq },
550 { "Wacom Volito", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_sys_irq },
551 { "Wacom PenStation2", 8, 3250, 2320, 255, 32, GRAPHIRE, wacom_sys_irq },
552 { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_sys_irq },
553 { "Wacom Volito2 2x3", 8, 3248, 2320, 511, 32, GRAPHIRE, wacom_sys_irq },
554 { "Wacom PenPartner2", 8, 3250, 2320, 255, 32, GRAPHIRE, wacom_sys_irq },
555 { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_sys_irq},
556 { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_sys_irq },
557 { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 15, INTUOS, wacom_sys_irq },
558 { "Wacom Intuos 12x12", 10, 30480, 31680, 1023, 15, INTUOS, wacom_sys_irq },
559 { "Wacom Intuos 12x18", 10, 45720, 31680, 1023, 15, INTUOS, wacom_sys_irq},
560 { "Wacom PL400", 8, 5408, 4056, 255, 32, PL, wacom_sys_irq },
561 { "Wacom PL500", 8, 6144, 4608, 255, 32, PL, wacom_sys_irq },
562 { "Wacom PL600", 8, 6126, 4604, 255, 32, PL, wacom_sys_irq },
563 { "Wacom PL600SX", 8, 6260, 5016, 255, 32, PL, wacom_sys_irq },
564 { "Wacom PL550", 8, 6144, 4608, 511, 32, PL, wacom_sys_irq },
565 { "Wacom PL800", 8, 7220, 5780, 511, 32, PL, wacom_sys_irq },
566 { "Wacom PL700", 8, 6758, 5406, 511, 32, PL, wacom_sys_irq },
567 { "Wacom PL510", 8, 6282, 4762, 511, 32, PL, wacom_sys_irq },
568 { "Wacom DTU710", 8, 34080, 27660, 511, 32, PL, wacom_sys_irq },
569 { "Wacom DTF521", 8, 6282, 4762, 511, 32, PL, wacom_sys_irq },
570 { "Wacom DTF720", 8, 6858, 5506, 511, 32, PL, wacom_sys_irq },
571 { "Wacom Cintiq Partner",8, 20480, 15360, 511, 32, PTU, wacom_sys_irq },
572 { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_sys_irq },
573 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_sys_irq },
574 { "Wacom Intuos2 9x12", 10, 30480, 24060, 1023, 15, INTUOS, wacom_sys_irq },
575 { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 15, INTUOS, wacom_sys_irq },
576 { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 15, INTUOS, wacom_sys_irq },
577 { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 15, INTUOS3, wacom_sys_irq },
578 { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 15, INTUOS3, wacom_sys_irq },
579 { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 15, INTUOS3, wacom_sys_irq },
580 { "Wacom Intuos3 12x12", 10, 60960, 60960, 1023, 15, INTUOS3L, wacom_sys_irq },
581 { "Wacom Intuos3 12x19", 10, 97536, 60960, 1023, 15, INTUOS3L, wacom_sys_irq },
582 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 15, INTUOS3, wacom_sys_irq },
583 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 15, CINTIQ, wacom_sys_irq },
584 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_sys_irq },
585 { }
586};
587
588static struct usb_device_id wacom_ids[] = {
589 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x00) },
590 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x10) },
591 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x11) },
592 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x12) },
593 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x13) },
594 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x14) },
595 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x15) },
596 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x16) },
597 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x60) },
598 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x61) },
599 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x62) },
600 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x63) },
601 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x64) },
602 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x20) },
603 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x21) },
604 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x22) },
605 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x23) },
606 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x24) },
607 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x30) },
608 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x31) },
609 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x32) },
610 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x33) },
611 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x34) },
612 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x35) },
613 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x37) },
614 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x38) },
615 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x39) },
616 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC0) },
617 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC4) },
618 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x03) },
619 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x41) },
620 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x42) },
621 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x43) },
622 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x44) },
623 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x45) },
624 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0) },
625 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1) },
626 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2) },
627 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB3) },
628 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB4) },
629 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB5) },
630 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) },
631 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) },
632 { }
633};
634
635const struct usb_device_id * get_device_table(void) {
636 const struct usb_device_id * id_table = wacom_ids;
637 return id_table;
638}
639
640struct wacom_features * get_wacom_feature(const struct usb_device_id * id) {
641 int index = id - wacom_ids;
642 struct wacom_features *wf = &wacom_features[index];
643 return wf;
644}
645
646MODULE_DEVICE_TABLE(usb, wacom_ids);
diff --git a/drivers/usb/input/wacom_wac.h b/drivers/usb/input/wacom_wac.h
new file mode 100644
index 000000000000..ceae7bf59d9f
--- /dev/null
+++ b/drivers/usb/input/wacom_wac.h
@@ -0,0 +1,48 @@
1/*
2 * drivers/usb/input/wacom_wac.h
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 */
9#ifndef WACOM_WAC_H
10#define WACOM_WAC_H
11
12#define STYLUS_DEVICE_ID 0x02
13#define CURSOR_DEVICE_ID 0x06
14#define ERASER_DEVICE_ID 0x0A
15
16enum {
17 PENPARTNER = 0,
18 GRAPHIRE,
19 WACOM_G4,
20 PTU,
21 PL,
22 INTUOS,
23 INTUOS3,
24 INTUOS3L,
25 CINTIQ,
26 MAX_TYPE
27};
28
29struct wacom_features {
30 char *name;
31 int pktlen;
32 int x_max;
33 int y_max;
34 int pressure_max;
35 int distance_max;
36 int type;
37 usb_complete_t irq;
38};
39
40struct wacom_wac {
41 signed char *data;
42 int tool[2];
43 int id[2];
44 __u32 serial[2];
45 struct wacom_features *features;
46};
47
48#endif
diff --git a/drivers/usb/input/yealink.c b/drivers/usb/input/yealink.c
index 7b45fd3de911..7291e7a2717b 100644
--- a/drivers/usb/input/yealink.c
+++ b/drivers/usb/input/yealink.c
@@ -971,7 +971,7 @@ static int usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
971 DRIVER_VERSION, sizeof(DRIVER_VERSION)); 971 DRIVER_VERSION, sizeof(DRIVER_VERSION));
972 972
973 /* Register sysfs hooks (don't care about failure) */ 973 /* Register sysfs hooks (don't care about failure) */
974 sysfs_create_group(&intf->dev.kobj, &yld_attr_group); 974 ret = sysfs_create_group(&intf->dev.kobj, &yld_attr_group);
975 return 0; 975 return 0;
976} 976}
977 977
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index 88928a4be805..c29658f69e2a 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -32,6 +32,16 @@ config USB_EMI26
32 To compile this driver as a module, choose M here: the 32 To compile this driver as a module, choose M here: the
33 module will be called emi26. 33 module will be called emi26.
34 34
35config USB_ADUTUX
36 tristate "ADU devices from Ontrak Control Systems (EXPERIMENTAL)"
37 depends on USB && EXPERIMENTAL
38 help
39 Say Y if you want to use an ADU device from Ontrak Control
40 Systems.
41
42 To compile this driver as a module, choose M here. The module
43 will be called adutux.
44
35config USB_AUERSWALD 45config USB_AUERSWALD
36 tristate "USB Auerswald ISDN support (EXPERIMENTAL)" 46 tristate "USB Auerswald ISDN support (EXPERIMENTAL)"
37 depends on USB && EXPERIMENTAL 47 depends on USB && EXPERIMENTAL
@@ -115,19 +125,36 @@ config USB_CYTHERM
115 To compile this driver as a module, choose M here: the 125 To compile this driver as a module, choose M here: the
116 module will be called cytherm. 126 module will be called cytherm.
117 127
118config USB_PHIDGETKIT 128config USB_PHIDGET
119 tristate "USB PhidgetKit support" 129 tristate "USB Phidgets drivers"
120 depends on USB 130 depends on USB
121 help 131 help
122 Say Y here if you want to connect a PhidgetKit USB device from 132 Say Y here to enable the various drivers for devices from
123 Phidgets Inc. 133 Phidgets inc.
134
135config USB_PHIDGETKIT
136 tristate "USB PhidgetInterfaceKit support"
137 depends on USB_PHIDGET
138 help
139 Say Y here if you want to connect a PhidgetInterfaceKit USB device
140 from Phidgets Inc.
124 141
125 To compile this driver as a module, choose M here: the 142 To compile this driver as a module, choose M here: the
126 module will be called phidgetkit. 143 module will be called phidgetkit.
127 144
145config USB_PHIDGETMOTORCONTROL
146 tristate "USB PhidgetMotorControl support"
147 depends on USB_PHIDGET
148 help
149 Say Y here if you want to connect a PhidgetMotorControl USB device
150 from Phidgets Inc.
151
152 To compile this driver as a module, choose M here: the
153 module will be called phidgetmotorcontrol.
154
128config USB_PHIDGETSERVO 155config USB_PHIDGETSERVO
129 tristate "USB PhidgetServo support" 156 tristate "USB PhidgetServo support"
130 depends on USB 157 depends on USB_PHIDGET
131 help 158 help
132 Say Y here if you want to connect an 1 or 4 Motor PhidgetServo 159 Say Y here if you want to connect an 1 or 4 Motor PhidgetServo
133 servo controller version 2.0 or 3.0. 160 servo controller version 2.0 or 3.0.
@@ -151,6 +178,30 @@ config USB_IDMOUSE
151 178
152 See also <http://www.fs.tum.de/~echtler/idmouse/>. 179 See also <http://www.fs.tum.de/~echtler/idmouse/>.
153 180
181config USB_FTDI_ELAN
182 tristate "Elan PCMCIA CardBus Adapter USB Client"
183 depends on USB
184 default M
185 help
186 ELAN's Uxxx series of adapters are USB to PCMCIA CardBus adapters.
187 Currently only the U132 adapter is available.
188
189 The U132 is specifically designed for CardBus PC cards that contain
190 an OHCI host controller. Typical PC cards are the Orange Mobile 3G
191 Option GlobeTrotter Fusion card. The U132 adapter will *NOT* work
192 with PC cards that do not contain an OHCI controller. To use a U132
193 adapter you will need this "ftdi-elan" module as well as the "u132-hcd"
194 module which is a USB host controller driver that talks to the OHCI
195 controller within CardBus card that are inserted in the U132 adapter.
196
197 This driver has been tested with a CardBus OHCI USB adapter, and
198 worked with a USB PEN Drive inserted into the first USB port of
199 the PCCARD. A rather pointless thing to do, but useful for testing.
200
201 See also the USB_U132_HCD entry "Elan U132 Adapter Host Controller"
202
203 It is safe to say M here.
204
154config USB_APPLEDISPLAY 205config USB_APPLEDISPLAY
155 tristate "Apple Cinema Display support" 206 tristate "Apple Cinema Display support"
156 depends on USB 207 depends on USB
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index 2927260c5812..2be70fa259bf 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -3,22 +3,25 @@
3# (the ones that don't fit into any other categories) 3# (the ones that don't fit into any other categories)
4# 4#
5 5
6obj-$(CONFIG_USB_ADUTUX) += adutux.o
6obj-$(CONFIG_USB_AUERSWALD) += auerswald.o 7obj-$(CONFIG_USB_AUERSWALD) += auerswald.o
7obj-$(CONFIG_USB_CYPRESS_CY7C63)+= cypress_cy7c63.o 8obj-$(CONFIG_USB_CYPRESS_CY7C63)+= cypress_cy7c63.o
8obj-$(CONFIG_USB_CYTHERM) += cytherm.o 9obj-$(CONFIG_USB_CYTHERM) += cytherm.o
9obj-$(CONFIG_USB_EMI26) += emi26.o 10obj-$(CONFIG_USB_EMI26) += emi26.o
10obj-$(CONFIG_USB_EMI62) += emi62.o 11obj-$(CONFIG_USB_EMI62) += emi62.o
12obj-$(CONFIG_USB_FTDI_ELAN) += ftdi-elan.o
11obj-$(CONFIG_USB_IDMOUSE) += idmouse.o 13obj-$(CONFIG_USB_IDMOUSE) += idmouse.o
12obj-$(CONFIG_USB_LCD) += usblcd.o 14obj-$(CONFIG_USB_LCD) += usblcd.o
13obj-$(CONFIG_USB_LD) += ldusb.o 15obj-$(CONFIG_USB_LD) += ldusb.o
14obj-$(CONFIG_USB_LED) += usbled.o 16obj-$(CONFIG_USB_LED) += usbled.o
15obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o 17obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o
18obj-$(CONFIG_USB_PHIDGET) += phidget.o
16obj-$(CONFIG_USB_PHIDGETKIT) += phidgetkit.o 19obj-$(CONFIG_USB_PHIDGETKIT) += phidgetkit.o
20obj-$(CONFIG_USB_PHIDGETMOTORCONTROL) += phidgetmotorcontrol.o
17obj-$(CONFIG_USB_PHIDGETSERVO) += phidgetservo.o 21obj-$(CONFIG_USB_PHIDGETSERVO) += phidgetservo.o
18obj-$(CONFIG_USB_RIO500) += rio500.o 22obj-$(CONFIG_USB_RIO500) += rio500.o
19obj-$(CONFIG_USB_TEST) += usbtest.o 23obj-$(CONFIG_USB_TEST) += usbtest.o
20obj-$(CONFIG_USB_USS720) += uss720.o 24obj-$(CONFIG_USB_USS720) += uss720.o
21obj-$(CONFIG_USB_APPLEDISPLAY) += appledisplay.o
22 25
23obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga/ 26obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga/
24 27
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
new file mode 100644
index 000000000000..d3963199b6ec
--- /dev/null
+++ b/drivers/usb/misc/adutux.c
@@ -0,0 +1,900 @@
1/*
2 * adutux - driver for ADU devices from Ontrak Control Systems
3 * This is an experimental driver. Use at your own risk.
4 * This driver is not supported by Ontrak Control Systems.
5 *
6 * Copyright (c) 2003 John Homppi (SCO, leave this notice here)
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * derived from the Lego USB Tower driver 0.56:
14 * Copyright (c) 2003 David Glance <davidgsf@sourceforge.net>
15 * 2001 Juergen Stuber <stuber@loria.fr>
16 * that was derived from USB Skeleton driver - 0.5
17 * Copyright (c) 2001 Greg Kroah-Hartman (greg@kroah.com)
18 *
19 */
20
21#include <linux/kernel.h>
22#include <linux/errno.h>
23#include <linux/init.h>
24#include <linux/slab.h>
25#include <linux/module.h>
26#include <linux/usb.h>
27#include <asm/uaccess.h>
28
29#ifdef CONFIG_USB_DEBUG
30static int debug = 5;
31#else
32static int debug = 1;
33#endif
34
35/* Use our own dbg macro */
36#undef dbg
37#define dbg(lvl, format, arg...) \
38do { \
39 if (debug >= lvl) \
40 printk(KERN_DEBUG __FILE__ " : " format " \n", ## arg); \
41} while (0)
42
43
44/* Version Information */
45#define DRIVER_VERSION "v0.0.13"
46#define DRIVER_AUTHOR "John Homppi"
47#define DRIVER_DESC "adutux (see www.ontrak.net)"
48
49/* Module parameters */
50module_param(debug, int, S_IRUGO | S_IWUSR);
51MODULE_PARM_DESC(debug, "Debug enabled or not");
52
53/* Define these values to match your device */
54#define ADU_VENDOR_ID 0x0a07
55#define ADU_PRODUCT_ID 0x0064
56
57/* table of devices that work with this driver */
58static struct usb_device_id device_table [] = {
59 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID) }, /* ADU100 */
60 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID+20) }, /* ADU120 */
61 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID+30) }, /* ADU130 */
62 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID+100) }, /* ADU200 */
63 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID+108) }, /* ADU208 */
64 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID+118) }, /* ADU218 */
65 { }/* Terminating entry */
66};
67
68MODULE_DEVICE_TABLE(usb, device_table);
69
70#ifdef CONFIG_USB_DYNAMIC_MINORS
71#define ADU_MINOR_BASE 0
72#else
73#define ADU_MINOR_BASE 67
74#endif
75
76/* we can have up to this number of device plugged in at once */
77#define MAX_DEVICES 16
78
79#define COMMAND_TIMEOUT (2*HZ) /* 60 second timeout for a command */
80
81/* Structure to hold all of our device specific stuff */
82struct adu_device {
83 struct semaphore sem; /* locks this structure */
84 struct usb_device* udev; /* save off the usb device pointer */
85 struct usb_interface* interface;
86 unsigned char minor; /* the starting minor number for this device */
87 char serial_number[8];
88
89 int open_count; /* number of times this port has been opened */
90
91 char* read_buffer_primary;
92 int read_buffer_length;
93 char* read_buffer_secondary;
94 int secondary_head;
95 int secondary_tail;
96 spinlock_t buflock;
97
98 wait_queue_head_t read_wait;
99 wait_queue_head_t write_wait;
100
101 char* interrupt_in_buffer;
102 struct usb_endpoint_descriptor* interrupt_in_endpoint;
103 struct urb* interrupt_in_urb;
104 int read_urb_finished;
105
106 char* interrupt_out_buffer;
107 struct usb_endpoint_descriptor* interrupt_out_endpoint;
108 struct urb* interrupt_out_urb;
109};
110
111/* prevent races between open() and disconnect */
112static DEFINE_MUTEX(disconnect_mutex);
113static struct usb_driver adu_driver;
114
115static void adu_debug_data(int level, const char *function, int size,
116 const unsigned char *data)
117{
118 int i;
119
120 if (debug < level)
121 return;
122
123 printk(KERN_DEBUG __FILE__": %s - length = %d, data = ",
124 function, size);
125 for (i = 0; i < size; ++i)
126 printk("%.2x ", data[i]);
127 printk("\n");
128}
129
130/**
131 * adu_abort_transfers
132 * aborts transfers and frees associated data structures
133 */
134static void adu_abort_transfers(struct adu_device *dev)
135{
136 dbg(2," %s : enter", __FUNCTION__);
137
138 if (dev == NULL) {
139 dbg(1," %s : dev is null", __FUNCTION__);
140 goto exit;
141 }
142
143 if (dev->udev == NULL) {
144 dbg(1," %s : udev is null", __FUNCTION__);
145 goto exit;
146 }
147
148 dbg(2," %s : udev state %d", __FUNCTION__, dev->udev->state);
149 if (dev->udev->state == USB_STATE_NOTATTACHED) {
150 dbg(1," %s : udev is not attached", __FUNCTION__);
151 goto exit;
152 }
153
154 /* shutdown transfer */
155 usb_unlink_urb(dev->interrupt_in_urb);
156 usb_unlink_urb(dev->interrupt_out_urb);
157
158exit:
159 dbg(2," %s : leave", __FUNCTION__);
160}
161
162static void adu_delete(struct adu_device *dev)
163{
164 dbg(2, "%s enter", __FUNCTION__);
165
166 adu_abort_transfers(dev);
167
168 /* free data structures */
169 usb_free_urb(dev->interrupt_in_urb);
170 usb_free_urb(dev->interrupt_out_urb);
171 kfree(dev->read_buffer_primary);
172 kfree(dev->read_buffer_secondary);
173 kfree(dev->interrupt_in_buffer);
174 kfree(dev->interrupt_out_buffer);
175 kfree(dev);
176
177 dbg(2, "%s : leave", __FUNCTION__);
178}
179
180static void adu_interrupt_in_callback(struct urb *urb, struct pt_regs *regs)
181{
182 struct adu_device *dev = urb->context;
183
184 dbg(4," %s : enter, status %d", __FUNCTION__, urb->status);
185 adu_debug_data(5, __FUNCTION__, urb->actual_length,
186 urb->transfer_buffer);
187
188 spin_lock(&dev->buflock);
189
190 if (urb->status != 0) {
191 if ((urb->status != -ENOENT) && (urb->status != -ECONNRESET)) {
192 dbg(1," %s : nonzero status received: %d",
193 __FUNCTION__, urb->status);
194 }
195 goto exit;
196 }
197
198 if (urb->actual_length > 0 && dev->interrupt_in_buffer[0] != 0x00) {
199 if (dev->read_buffer_length <
200 (4 * le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize)) -
201 (urb->actual_length)) {
202 memcpy (dev->read_buffer_primary +
203 dev->read_buffer_length,
204 dev->interrupt_in_buffer, urb->actual_length);
205
206 dev->read_buffer_length += urb->actual_length;
207 dbg(2," %s reading %d ", __FUNCTION__,
208 urb->actual_length);
209 } else {
210 dbg(1," %s : read_buffer overflow", __FUNCTION__);
211 }
212 }
213
214exit:
215 dev->read_urb_finished = 1;
216 spin_unlock(&dev->buflock);
217 /* always wake up so we recover from errors */
218 wake_up_interruptible(&dev->read_wait);
219 adu_debug_data(5, __FUNCTION__, urb->actual_length,
220 urb->transfer_buffer);
221 dbg(4," %s : leave, status %d", __FUNCTION__, urb->status);
222}
223
224static void adu_interrupt_out_callback(struct urb *urb, struct pt_regs *regs)
225{
226 struct adu_device *dev = urb->context;
227
228 dbg(4," %s : enter, status %d", __FUNCTION__, urb->status);
229 adu_debug_data(5,__FUNCTION__, urb->actual_length, urb->transfer_buffer);
230
231 if (urb->status != 0) {
232 if ((urb->status != -ENOENT) &&
233 (urb->status != -ECONNRESET)) {
234 dbg(1, " %s :nonzero status received: %d",
235 __FUNCTION__, urb->status);
236 }
237 goto exit;
238 }
239
240 wake_up_interruptible(&dev->write_wait);
241exit:
242
243 adu_debug_data(5, __FUNCTION__, urb->actual_length,
244 urb->transfer_buffer);
245 dbg(4," %s : leave, status %d", __FUNCTION__, urb->status);
246}
247
248static int adu_open(struct inode *inode, struct file *file)
249{
250 struct adu_device *dev = NULL;
251 struct usb_interface *interface;
252 int subminor;
253 int retval = 0;
254
255 dbg(2,"%s : enter", __FUNCTION__);
256
257 subminor = iminor(inode);
258
259 mutex_lock(&disconnect_mutex);
260
261 interface = usb_find_interface(&adu_driver, subminor);
262 if (!interface) {
263 err("%s - error, can't find device for minor %d",
264 __FUNCTION__, subminor);
265 retval = -ENODEV;
266 goto exit_no_device;
267 }
268
269 dev = usb_get_intfdata(interface);
270 if (!dev) {
271 retval = -ENODEV;
272 goto exit_no_device;
273 }
274
275 /* lock this device */
276 if ((retval = down_interruptible(&dev->sem))) {
277 dbg(2, "%s : sem down failed", __FUNCTION__);
278 goto exit_no_device;
279 }
280
281 /* increment our usage count for the device */
282 ++dev->open_count;
283 dbg(2,"%s : open count %d", __FUNCTION__, dev->open_count);
284
285 /* save device in the file's private structure */
286 file->private_data = dev;
287
288 /* initialize in direction */
289 dev->read_buffer_length = 0;
290
291 /* fixup first read by having urb waiting for it */
292 usb_fill_int_urb(dev->interrupt_in_urb,dev->udev,
293 usb_rcvintpipe(dev->udev,
294 dev->interrupt_in_endpoint->bEndpointAddress),
295 dev->interrupt_in_buffer,
296 le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize),
297 adu_interrupt_in_callback, dev,
298 dev->interrupt_in_endpoint->bInterval);
299 /* dev->interrupt_in_urb->transfer_flags |= URB_ASYNC_UNLINK; */
300 dev->read_urb_finished = 0;
301 usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);
302 /* we ignore failure */
303 /* end of fixup for first read */
304
305 up(&dev->sem);
306
307exit_no_device:
308 mutex_unlock(&disconnect_mutex);
309 dbg(2,"%s : leave, return value %d ", __FUNCTION__, retval);
310
311 return retval;
312}
313
314static int adu_release_internal(struct adu_device *dev)
315{
316 int retval = 0;
317
318 dbg(2," %s : enter", __FUNCTION__);
319
320 if (dev->udev == NULL) {
321 /* the device was unplugged before the file was released */
322 adu_delete(dev);
323 goto exit;
324 }
325
326 /* decrement our usage count for the device */
327 --dev->open_count;
328 dbg(2," %s : open count %d", __FUNCTION__, dev->open_count);
329 if (dev->open_count <= 0) {
330 adu_abort_transfers(dev);
331 dev->open_count = 0;
332 }
333
334exit:
335 dbg(2," %s : leave", __FUNCTION__);
336 return retval;
337}
338
339static int adu_release(struct inode *inode, struct file *file)
340{
341 struct adu_device *dev = NULL;
342 int retval = 0;
343
344 dbg(2," %s : enter", __FUNCTION__);
345
346 if (file == NULL) {
347 dbg(1," %s : file is NULL", __FUNCTION__);
348 retval = -ENODEV;
349 goto exit;
350 }
351
352 dev = file->private_data;
353
354 if (dev == NULL) {
355 dbg(1," %s : object is NULL", __FUNCTION__);
356 retval = -ENODEV;
357 goto exit;
358 }
359
360 /* lock our device */
361 down(&dev->sem); /* not interruptible */
362
363 if (dev->open_count <= 0) {
364 dbg(1," %s : device not opened", __FUNCTION__);
365 retval = -ENODEV;
366 goto exit;
367 }
368
369 /* do the work */
370 retval = adu_release_internal(dev);
371
372exit:
373 up(&dev->sem);
374 dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
375 return retval;
376}
377
378static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
379 loff_t *ppos)
380{
381 struct adu_device *dev;
382 size_t bytes_read = 0;
383 size_t bytes_to_read = count;
384 int i;
385 int retval = 0;
386 int timeout = 0;
387 int should_submit = 0;
388 unsigned long flags;
389 DECLARE_WAITQUEUE(wait, current);
390
391 dbg(2," %s : enter, count = %Zd, file=%p", __FUNCTION__, count, file);
392
393 dev = file->private_data;
394 dbg(2," %s : dev=%p", __FUNCTION__, dev);
395 /* lock this object */
396 if (down_interruptible(&dev->sem))
397 return -ERESTARTSYS;
398
399 /* verify that the device wasn't unplugged */
400 if (dev->udev == NULL || dev->minor == 0) {
401 retval = -ENODEV;
402 err("No device or device unplugged %d", retval);
403 goto exit;
404 }
405
406 /* verify that some data was requested */
407 if (count == 0) {
408 dbg(1," %s : read request of 0 bytes", __FUNCTION__);
409 goto exit;
410 }
411
412 timeout = COMMAND_TIMEOUT;
413 dbg(2," %s : about to start looping", __FUNCTION__);
414 while (bytes_to_read) {
415 int data_in_secondary = dev->secondary_tail - dev->secondary_head;
416 dbg(2," %s : while, data_in_secondary=%d, status=%d",
417 __FUNCTION__, data_in_secondary,
418 dev->interrupt_in_urb->status);
419
420 if (data_in_secondary) {
421 /* drain secondary buffer */
422 int amount = bytes_to_read < data_in_secondary ? bytes_to_read : data_in_secondary;
423 i = copy_to_user(buffer, dev->read_buffer_secondary+dev->secondary_head, amount);
424 if (i < 0) {
425 retval = -EFAULT;
426 goto exit;
427 }
428 dev->secondary_head += (amount - i);
429 bytes_read += (amount - i);
430 bytes_to_read -= (amount - i);
431 if (i) {
432 retval = bytes_read ? bytes_read : -EFAULT;
433 goto exit;
434 }
435 } else {
436 /* we check the primary buffer */
437 spin_lock_irqsave (&dev->buflock, flags);
438 if (dev->read_buffer_length) {
439 /* we secure access to the primary */
440 char *tmp;
441 dbg(2," %s : swap, read_buffer_length = %d",
442 __FUNCTION__, dev->read_buffer_length);
443 tmp = dev->read_buffer_secondary;
444 dev->read_buffer_secondary = dev->read_buffer_primary;
445 dev->read_buffer_primary = tmp;
446 dev->secondary_head = 0;
447 dev->secondary_tail = dev->read_buffer_length;
448 dev->read_buffer_length = 0;
449 spin_unlock_irqrestore(&dev->buflock, flags);
450 /* we have a free buffer so use it */
451 should_submit = 1;
452 } else {
453 /* even the primary was empty - we may need to do IO */
454 if (dev->interrupt_in_urb->status == -EINPROGRESS) {
455 /* somebody is doing IO */
456 spin_unlock_irqrestore(&dev->buflock, flags);
457 dbg(2," %s : submitted already", __FUNCTION__);
458 } else {
459 /* we must initiate input */
460 dbg(2," %s : initiate input", __FUNCTION__);
461 dev->read_urb_finished = 0;
462
463 usb_fill_int_urb(dev->interrupt_in_urb,dev->udev,
464 usb_rcvintpipe(dev->udev,
465 dev->interrupt_in_endpoint->bEndpointAddress),
466 dev->interrupt_in_buffer,
467 le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize),
468 adu_interrupt_in_callback,
469 dev,
470 dev->interrupt_in_endpoint->bInterval);
471 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);
472 if (!retval) {
473 spin_unlock_irqrestore(&dev->buflock, flags);
474 dbg(2," %s : submitted OK", __FUNCTION__);
475 } else {
476 if (retval == -ENOMEM) {
477 retval = bytes_read ? bytes_read : -ENOMEM;
478 }
479 spin_unlock_irqrestore(&dev->buflock, flags);
480 dbg(2," %s : submit failed", __FUNCTION__);
481 goto exit;
482 }
483 }
484
485 /* we wait for I/O to complete */
486 set_current_state(TASK_INTERRUPTIBLE);
487 add_wait_queue(&dev->read_wait, &wait);
488 if (!dev->read_urb_finished)
489 timeout = schedule_timeout(COMMAND_TIMEOUT);
490 else
491 set_current_state(TASK_RUNNING);
492 remove_wait_queue(&dev->read_wait, &wait);
493
494 if (timeout <= 0) {
495 dbg(2," %s : timeout", __FUNCTION__);
496 retval = bytes_read ? bytes_read : -ETIMEDOUT;
497 goto exit;
498 }
499
500 if (signal_pending(current)) {
501 dbg(2," %s : signal pending", __FUNCTION__);
502 retval = bytes_read ? bytes_read : -EINTR;
503 goto exit;
504 }
505 }
506 }
507 }
508
509 retval = bytes_read;
510 /* if the primary buffer is empty then use it */
511 if (should_submit && !dev->interrupt_in_urb->status==-EINPROGRESS) {
512 usb_fill_int_urb(dev->interrupt_in_urb,dev->udev,
513 usb_rcvintpipe(dev->udev,
514 dev->interrupt_in_endpoint->bEndpointAddress),
515 dev->interrupt_in_buffer,
516 le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize),
517 adu_interrupt_in_callback,
518 dev,
519 dev->interrupt_in_endpoint->bInterval);
520 /* dev->interrupt_in_urb->transfer_flags |= URB_ASYNC_UNLINK; */
521 dev->read_urb_finished = 0;
522 usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);
523 /* we ignore failure */
524 }
525
526exit:
527 /* unlock the device */
528 up(&dev->sem);
529
530 dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
531 return retval;
532}
533
534static ssize_t adu_write(struct file *file, const __user char *buffer,
535 size_t count, loff_t *ppos)
536{
537 struct adu_device *dev;
538 size_t bytes_written = 0;
539 size_t bytes_to_write;
540 size_t buffer_size;
541 int retval = 0;
542 int timeout = 0;
543
544 dbg(2," %s : enter, count = %Zd", __FUNCTION__, count);
545
546 dev = file->private_data;
547
548 /* lock this object */
549 down_interruptible(&dev->sem);
550
551 /* verify that the device wasn't unplugged */
552 if (dev->udev == NULL || dev->minor == 0) {
553 retval = -ENODEV;
554 err("No device or device unplugged %d", retval);
555 goto exit;
556 }
557
558 /* verify that we actually have some data to write */
559 if (count == 0) {
560 dbg(1," %s : write request of 0 bytes", __FUNCTION__);
561 goto exit;
562 }
563
564
565 while (count > 0) {
566 if (dev->interrupt_out_urb->status == -EINPROGRESS) {
567 timeout = COMMAND_TIMEOUT;
568
569 while (timeout > 0) {
570 if (signal_pending(current)) {
571 dbg(1," %s : interrupted", __FUNCTION__);
572 retval = -EINTR;
573 goto exit;
574 }
575 up(&dev->sem);
576 timeout = interruptible_sleep_on_timeout(&dev->write_wait, timeout);
577 down_interruptible(&dev->sem);
578 if (timeout > 0) {
579 break;
580 }
581 dbg(1," %s : interrupted timeout: %d", __FUNCTION__, timeout);
582 }
583
584
585 dbg(1," %s : final timeout: %d", __FUNCTION__, timeout);
586
587 if (timeout == 0) {
588 dbg(1, "%s - command timed out.", __FUNCTION__);
589 retval = -ETIMEDOUT;
590 goto exit;
591 }
592
593 dbg(4," %s : in progress, count = %Zd", __FUNCTION__, count);
594
595 } else {
596 dbg(4," %s : sending, count = %Zd", __FUNCTION__, count);
597
598 /* write the data into interrupt_out_buffer from userspace */
599 buffer_size = le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize);
600 bytes_to_write = count > buffer_size ? buffer_size : count;
601 dbg(4," %s : buffer_size = %Zd, count = %Zd, bytes_to_write = %Zd",
602 __FUNCTION__, buffer_size, count, bytes_to_write);
603
604 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write) != 0) {
605 retval = -EFAULT;
606 goto exit;
607 }
608
609 /* send off the urb */
610 usb_fill_int_urb(
611 dev->interrupt_out_urb,
612 dev->udev,
613 usb_sndintpipe(dev->udev, dev->interrupt_out_endpoint->bEndpointAddress),
614 dev->interrupt_out_buffer,
615 bytes_to_write,
616 adu_interrupt_out_callback,
617 dev,
618 dev->interrupt_in_endpoint->bInterval);
619 /* dev->interrupt_in_urb->transfer_flags |= URB_ASYNC_UNLINK; */
620 dev->interrupt_out_urb->actual_length = bytes_to_write;
621 retval = usb_submit_urb(dev->interrupt_out_urb, GFP_KERNEL);
622 if (retval < 0) {
623 err("Couldn't submit interrupt_out_urb %d", retval);
624 goto exit;
625 }
626
627 buffer += bytes_to_write;
628 count -= bytes_to_write;
629
630 bytes_written += bytes_to_write;
631 }
632 }
633
634 retval = bytes_written;
635
636exit:
637 /* unlock the device */
638 up(&dev->sem);
639
640 dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
641
642 return retval;
643}
644
645/* file operations needed when we register this driver */
646static struct file_operations adu_fops = {
647 .owner = THIS_MODULE,
648 .read = adu_read,
649 .write = adu_write,
650 .open = adu_open,
651 .release = adu_release,
652};
653
654/*
655 * usb class driver info in order to get a minor number from the usb core,
656 * and to have the device registered with devfs and the driver core
657 */
658static struct usb_class_driver adu_class = {
659 .name = "usb/adutux%d",
660 .fops = &adu_fops,
661 .minor_base = ADU_MINOR_BASE,
662};
663
664/**
665 * adu_probe
666 *
667 * Called by the usb core when a new device is connected that it thinks
668 * this driver might be interested in.
669 */
670static int adu_probe(struct usb_interface *interface,
671 const struct usb_device_id *id)
672{
673 struct usb_device *udev = interface_to_usbdev(interface);
674 struct adu_device *dev = NULL;
675 struct usb_host_interface *iface_desc;
676 struct usb_endpoint_descriptor *endpoint;
677 int retval = -ENODEV;
678 int in_end_size;
679 int out_end_size;
680 int i;
681
682 dbg(2," %s : enter", __FUNCTION__);
683
684 if (udev == NULL) {
685 dev_err(&interface->dev, "udev is NULL.\n");
686 goto exit;
687 }
688
689 /* allocate memory for our device state and intialize it */
690 dev = kzalloc(sizeof(struct adu_device), GFP_KERNEL);
691 if (dev == NULL) {
692 dev_err(&interface->dev, "Out of memory\n");
693 retval = -ENOMEM;
694 goto exit;
695 }
696
697 init_MUTEX(&dev->sem);
698 spin_lock_init(&dev->buflock);
699 dev->udev = udev;
700 init_waitqueue_head(&dev->read_wait);
701 init_waitqueue_head(&dev->write_wait);
702
703 iface_desc = &interface->altsetting[0];
704
705 /* set up the endpoint information */
706 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
707 endpoint = &iface_desc->endpoint[i].desc;
708
709 if (usb_endpoint_is_int_in(endpoint))
710 dev->interrupt_in_endpoint = endpoint;
711
712 if (usb_endpoint_is_int_out(endpoint))
713 dev->interrupt_out_endpoint = endpoint;
714 }
715 if (dev->interrupt_in_endpoint == NULL) {
716 dev_err(&interface->dev, "interrupt in endpoint not found\n");
717 goto error;
718 }
719 if (dev->interrupt_out_endpoint == NULL) {
720 dev_err(&interface->dev, "interrupt out endpoint not found\n");
721 goto error;
722 }
723
724 in_end_size = le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize);
725 out_end_size = le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize);
726
727 dev->read_buffer_primary = kmalloc((4 * in_end_size), GFP_KERNEL);
728 if (!dev->read_buffer_primary) {
729 dev_err(&interface->dev, "Couldn't allocate read_buffer_primary\n");
730 retval = -ENOMEM;
731 goto error;
732 }
733
734 /* debug code prime the buffer */
735 memset(dev->read_buffer_primary, 'a', in_end_size);
736 memset(dev->read_buffer_primary + in_end_size, 'b', in_end_size);
737 memset(dev->read_buffer_primary + (2 * in_end_size), 'c', in_end_size);
738 memset(dev->read_buffer_primary + (3 * in_end_size), 'd', in_end_size);
739
740 dev->read_buffer_secondary = kmalloc((4 * in_end_size), GFP_KERNEL);
741 if (!dev->read_buffer_secondary) {
742 dev_err(&interface->dev, "Couldn't allocate read_buffer_secondary\n");
743 retval = -ENOMEM;
744 goto error;
745 }
746
747 /* debug code prime the buffer */
748 memset(dev->read_buffer_secondary, 'e', in_end_size);
749 memset(dev->read_buffer_secondary + in_end_size, 'f', in_end_size);
750 memset(dev->read_buffer_secondary + (2 * in_end_size), 'g', in_end_size);
751 memset(dev->read_buffer_secondary + (3 * in_end_size), 'h', in_end_size);
752
753 dev->interrupt_in_buffer = kmalloc(in_end_size, GFP_KERNEL);
754 if (!dev->interrupt_in_buffer) {
755 dev_err(&interface->dev, "Couldn't allocate interrupt_in_buffer\n");
756 goto error;
757 }
758
759 /* debug code prime the buffer */
760 memset(dev->interrupt_in_buffer, 'i', in_end_size);
761
762 dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
763 if (!dev->interrupt_in_urb) {
764 dev_err(&interface->dev, "Couldn't allocate interrupt_in_urb\n");
765 goto error;
766 }
767 dev->interrupt_out_buffer = kmalloc(out_end_size, GFP_KERNEL);
768 if (!dev->interrupt_out_buffer) {
769 dev_err(&interface->dev, "Couldn't allocate interrupt_out_buffer\n");
770 goto error;
771 }
772 dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
773 if (!dev->interrupt_out_urb) {
774 dev_err(&interface->dev, "Couldn't allocate interrupt_out_urb\n");
775 goto error;
776 }
777
778 if (!usb_string(udev, udev->descriptor.iSerialNumber, dev->serial_number,
779 sizeof(dev->serial_number))) {
780 dev_err(&interface->dev, "Could not retrieve serial number\n");
781 goto error;
782 }
783 dbg(2," %s : serial_number=%s", __FUNCTION__, dev->serial_number);
784
785 /* we can register the device now, as it is ready */
786 usb_set_intfdata(interface, dev);
787
788 retval = usb_register_dev(interface, &adu_class);
789
790 if (retval) {
791 /* something prevented us from registering this driver */
792 dev_err(&interface->dev, "Not able to get a minor for this device.\n");
793 usb_set_intfdata(interface, NULL);
794 goto error;
795 }
796
797 dev->minor = interface->minor;
798
799 /* let the user know what node this device is now attached to */
800 dev_info(&interface->dev, "ADU%d %s now attached to /dev/usb/adutux%d",
801 udev->descriptor.idProduct, dev->serial_number,
802 (dev->minor - ADU_MINOR_BASE));
803exit:
804 dbg(2," %s : leave, return value %p (dev)", __FUNCTION__, dev);
805
806 return retval;
807
808error:
809 adu_delete(dev);
810 return retval;
811}
812
813/**
814 * adu_disconnect
815 *
816 * Called by the usb core when the device is removed from the system.
817 */
818static void adu_disconnect(struct usb_interface *interface)
819{
820 struct adu_device *dev;
821 int minor;
822
823 dbg(2," %s : enter", __FUNCTION__);
824
825 mutex_lock(&disconnect_mutex); /* not interruptible */
826
827 dev = usb_get_intfdata(interface);
828 usb_set_intfdata(interface, NULL);
829
830 down(&dev->sem); /* not interruptible */
831
832 minor = dev->minor;
833
834 /* give back our minor */
835 usb_deregister_dev(interface, &adu_class);
836 dev->minor = 0;
837
838 /* if the device is not opened, then we clean up right now */
839 dbg(2," %s : open count %d", __FUNCTION__, dev->open_count);
840 if (!dev->open_count) {
841 up(&dev->sem);
842 adu_delete(dev);
843 } else {
844 dev->udev = NULL;
845 up(&dev->sem);
846 }
847
848 mutex_unlock(&disconnect_mutex);
849
850 dev_info(&interface->dev, "ADU device adutux%d now disconnected",
851 (minor - ADU_MINOR_BASE));
852
853 dbg(2," %s : leave", __FUNCTION__);
854}
855
856/* usb specific object needed to register this driver with the usb subsystem */
857static struct usb_driver adu_driver = {
858 .name = "adutux",
859 .probe = adu_probe,
860 .disconnect = adu_disconnect,
861 .id_table = device_table,
862};
863
864static int __init adu_init(void)
865{
866 int result;
867
868 dbg(2," %s : enter", __FUNCTION__);
869
870 /* register this driver with the USB subsystem */
871 result = usb_register(&adu_driver);
872 if (result < 0) {
873 err("usb_register failed for the "__FILE__" driver. "
874 "Error number %d", result);
875 goto exit;
876 }
877
878 info("adutux " DRIVER_DESC " " DRIVER_VERSION);
879 info("adutux is an experimental driver. Use at your own risk");
880
881exit:
882 dbg(2," %s : leave, return value %d", __FUNCTION__, result);
883
884 return result;
885}
886
887static void __exit adu_exit(void)
888{
889 dbg(2," %s : enter", __FUNCTION__);
890 /* deregister this driver with the USB subsystem */
891 usb_deregister(&adu_driver);
892 dbg(2," %s : leave", __FUNCTION__);
893}
894
895module_init(adu_init);
896module_exit(adu_exit);
897
898MODULE_AUTHOR(DRIVER_AUTHOR);
899MODULE_DESCRIPTION(DRIVER_DESC);
900MODULE_LICENSE("GPL");
diff --git a/drivers/usb/misc/auerswald.c b/drivers/usb/misc/auerswald.c
index 1fef36e71c57..4fd2110b3411 100644
--- a/drivers/usb/misc/auerswald.c
+++ b/drivers/usb/misc/auerswald.c
@@ -806,7 +806,7 @@ static void auerbuf_releasebuf( pauerbuf_t bp)
8060 Initial, OK 8060 Initial, OK
807-EINPROGRESS during submission until end 807-EINPROGRESS during submission until end
808-ENOENT if urb is unlinked 808-ENOENT if urb is unlinked
809-ETIMEDOUT Transfer timed out, NAK 809-ETIME Device did not respond
810-ENOMEM Memory Overflow 810-ENOMEM Memory Overflow
811-ENODEV Specified USB-device or bus doesn't exist 811-ENODEV Specified USB-device or bus doesn't exist
812-ENXIO URB already queued 812-ENXIO URB already queued
@@ -832,7 +832,7 @@ static int auerswald_status_retry (int status)
832{ 832{
833 switch (status) { 833 switch (status) {
834 case 0: 834 case 0:
835 case -ETIMEDOUT: 835 case -ETIME:
836 case -EOVERFLOW: 836 case -EOVERFLOW:
837 case -EAGAIN: 837 case -EAGAIN:
838 case -EPIPE: 838 case -EPIPE:
@@ -1858,7 +1858,7 @@ static int auerchar_release (struct inode *inode, struct file *file)
1858 1858
1859/*----------------------------------------------------------------------*/ 1859/*----------------------------------------------------------------------*/
1860/* File operation structure */ 1860/* File operation structure */
1861static struct file_operations auerswald_fops = 1861static const struct file_operations auerswald_fops =
1862{ 1862{
1863 .owner = THIS_MODULE, 1863 .owner = THIS_MODULE,
1864 .llseek = no_llseek, 1864 .llseek = no_llseek,
diff --git a/drivers/usb/misc/cypress_cy7c63.c b/drivers/usb/misc/cypress_cy7c63.c
index 9c46746d5d00..b63b5f34b2aa 100644
--- a/drivers/usb/misc/cypress_cy7c63.c
+++ b/drivers/usb/misc/cypress_cy7c63.c
@@ -209,7 +209,7 @@ static int cypress_probe(struct usb_interface *interface,
209 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 209 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
210 if (dev == NULL) { 210 if (dev == NULL) {
211 dev_err(&interface->dev, "Out of memory!\n"); 211 dev_err(&interface->dev, "Out of memory!\n");
212 goto error; 212 goto error_mem;
213 } 213 }
214 214
215 dev->udev = usb_get_dev(interface_to_usbdev(interface)); 215 dev->udev = usb_get_dev(interface_to_usbdev(interface));
@@ -218,15 +218,26 @@ static int cypress_probe(struct usb_interface *interface,
218 usb_set_intfdata(interface, dev); 218 usb_set_intfdata(interface, dev);
219 219
220 /* create device attribute files */ 220 /* create device attribute files */
221 device_create_file(&interface->dev, &dev_attr_port0); 221 retval = device_create_file(&interface->dev, &dev_attr_port0);
222 device_create_file(&interface->dev, &dev_attr_port1); 222 if (retval)
223 goto error;
224 retval = device_create_file(&interface->dev, &dev_attr_port1);
225 if (retval)
226 goto error;
223 227
224 /* let the user know that the device is now attached */ 228 /* let the user know that the device is now attached */
225 dev_info(&interface->dev, 229 dev_info(&interface->dev,
226 "Cypress CY7C63xxx device now attached\n"); 230 "Cypress CY7C63xxx device now attached\n");
231 return 0;
227 232
228 retval = 0;
229error: 233error:
234 device_remove_file(&interface->dev, &dev_attr_port0);
235 device_remove_file(&interface->dev, &dev_attr_port1);
236 usb_set_intfdata(interface, NULL);
237 usb_put_dev(dev->udev);
238 kfree(dev);
239
240error_mem:
230 return retval; 241 return retval;
231} 242}
232 243
diff --git a/drivers/usb/misc/cytherm.c b/drivers/usb/misc/cytherm.c
index b20bec445552..04e87acd6e46 100644
--- a/drivers/usb/misc/cytherm.c
+++ b/drivers/usb/misc/cytherm.c
@@ -353,7 +353,7 @@ static int cytherm_probe(struct usb_interface *interface,
353 dev = kzalloc (sizeof(struct usb_cytherm), GFP_KERNEL); 353 dev = kzalloc (sizeof(struct usb_cytherm), GFP_KERNEL);
354 if (dev == NULL) { 354 if (dev == NULL) {
355 dev_err (&interface->dev, "Out of memory\n"); 355 dev_err (&interface->dev, "Out of memory\n");
356 goto error; 356 goto error_mem;
357 } 357 }
358 358
359 dev->udev = usb_get_dev(udev); 359 dev->udev = usb_get_dev(udev);
@@ -362,18 +362,35 @@ static int cytherm_probe(struct usb_interface *interface,
362 362
363 dev->brightness = 0xFF; 363 dev->brightness = 0xFF;
364 364
365 device_create_file(&interface->dev, &dev_attr_brightness); 365 retval = device_create_file(&interface->dev, &dev_attr_brightness);
366 device_create_file(&interface->dev, &dev_attr_temp); 366 if (retval)
367 device_create_file(&interface->dev, &dev_attr_button); 367 goto error;
368 device_create_file(&interface->dev, &dev_attr_port0); 368 retval = device_create_file(&interface->dev, &dev_attr_temp);
369 device_create_file(&interface->dev, &dev_attr_port1); 369 if (retval)
370 goto error;
371 retval = device_create_file(&interface->dev, &dev_attr_button);
372 if (retval)
373 goto error;
374 retval = device_create_file(&interface->dev, &dev_attr_port0);
375 if (retval)
376 goto error;
377 retval = device_create_file(&interface->dev, &dev_attr_port1);
378 if (retval)
379 goto error;
370 380
371 dev_info (&interface->dev, 381 dev_info (&interface->dev,
372 "Cypress thermometer device now attached\n"); 382 "Cypress thermometer device now attached\n");
373 return 0; 383 return 0;
374 384error:
375 error: 385 device_remove_file(&interface->dev, &dev_attr_brightness);
386 device_remove_file(&interface->dev, &dev_attr_temp);
387 device_remove_file(&interface->dev, &dev_attr_button);
388 device_remove_file(&interface->dev, &dev_attr_port0);
389 device_remove_file(&interface->dev, &dev_attr_port1);
390 usb_set_intfdata (interface, NULL);
391 usb_put_dev(dev->udev);
376 kfree(dev); 392 kfree(dev);
393error_mem:
377 return retval; 394 return retval;
378} 395}
379 396
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
new file mode 100644
index 000000000000..b88a09497c28
--- /dev/null
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -0,0 +1,2809 @@
1/*
2* USB FTDI client driver for Elan Digital Systems's Uxxx adapters
3*
4* Copyright(C) 2006 Elan Digital Systems Limited
5* http://www.elandigitalsystems.com
6*
7* Author and Maintainer - Tony Olech - Elan Digital Systems
8* tony.olech@elandigitalsystems.com
9*
10* This program is free software;you can redistribute it and/or
11* modify it under the terms of the GNU General Public License as
12* published by the Free Software Foundation, version 2.
13*
14*
15* This driver was written by Tony Olech(tony.olech@elandigitalsystems.com)
16* based on various USB client drivers in the 2.6.15 linux kernel
17* with constant reference to the 3rd Edition of Linux Device Drivers
18* published by O'Reilly
19*
20* The U132 adapter is a USB to CardBus adapter specifically designed
21* for PC cards that contain an OHCI host controller. Typical PC cards
22* are the Orange Mobile 3G Option GlobeTrotter Fusion card.
23*
24* The U132 adapter will *NOT *work with PC cards that do not contain
25* an OHCI controller. A simple way to test whether a PC card has an
26* OHCI controller as an interface is to insert the PC card directly
27* into a laptop(or desktop) with a CardBus slot and if "lspci" shows
28* a new USB controller and "lsusb -v" shows a new OHCI Host Controller
29* then there is a good chance that the U132 adapter will support the
30* PC card.(you also need the specific client driver for the PC card)
31*
32* Please inform the Author and Maintainer about any PC cards that
33* contain OHCI Host Controller and work when directly connected to
34* an embedded CardBus slot but do not work when they are connected
35* via an ELAN U132 adapter.
36*
37*/
38#include <linux/config.h>
39#include <linux/kernel.h>
40#include <linux/errno.h>
41#include <linux/init.h>
42#include <linux/list.h>
43#include <linux/ioctl.h>
44#include <linux/slab.h>
45#include <linux/module.h>
46#include <linux/kref.h>
47#include <asm/uaccess.h>
48#include <linux/usb.h>
49#include <linux/workqueue.h>
50#include <linux/platform_device.h>
51MODULE_AUTHOR("Tony Olech");
52MODULE_DESCRIPTION("FTDI ELAN driver");
53MODULE_LICENSE("GPL");
54#define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444)
55extern struct platform_driver u132_platform_driver;
56static struct workqueue_struct *status_queue;
57static struct workqueue_struct *command_queue;
58static struct workqueue_struct *respond_queue;
59/*
60* ftdi_module_lock exists to protect access to global variables
61*
62*/
63static struct semaphore ftdi_module_lock;
64static int ftdi_instances = 0;
65static struct list_head ftdi_static_list;
66/*
67* end of the global variables protected by ftdi_module_lock
68*/
69#include "usb_u132.h"
70#define TD_DEVNOTRESP 5
71/* Define these values to match your devices*/
72#define USB_FTDI_ELAN_VENDOR_ID 0x0403
73#define USB_FTDI_ELAN_PRODUCT_ID 0xd6ea
74/* table of devices that work with this driver*/
75static struct usb_device_id ftdi_elan_table[] = {
76 {USB_DEVICE(USB_FTDI_ELAN_VENDOR_ID, USB_FTDI_ELAN_PRODUCT_ID)},
77 { /* Terminating entry */ }
78};
79
80MODULE_DEVICE_TABLE(usb, ftdi_elan_table);
81/* only the jtag(firmware upgrade device) interface requires
82* a device file and corresponding minor number, but the
83* interface is created unconditionally - I suppose it could
84* be configured or not according to a module parameter.
85* But since we(now) require one interface per device,
86* and since it unlikely that a normal installation would
87* require more than a couple of elan-ftdi devices, 8 seems
88* like a reasonable limit to have here, and if someone
89* really requires more than 8 devices, then they can frig the
90* code and recompile
91*/
92#define USB_FTDI_ELAN_MINOR_BASE 192
93#define COMMAND_BITS 5
94#define COMMAND_SIZE (1<<COMMAND_BITS)
95#define COMMAND_MASK (COMMAND_SIZE-1)
96struct u132_command {
97 u8 header;
98 u16 length;
99 u8 address;
100 u8 width;
101 u32 value;
102 int follows;
103 void *buffer;
104};
105#define RESPOND_BITS 5
106#define RESPOND_SIZE (1<<RESPOND_BITS)
107#define RESPOND_MASK (RESPOND_SIZE-1)
108struct u132_respond {
109 u8 header;
110 u8 address;
111 u32 *value;
112 int *result;
113 struct completion wait_completion;
114};
115struct u132_target {
116 void *endp;
117 struct urb *urb;
118 int toggle_bits;
119 int error_count;
120 int condition_code;
121 int repeat_number;
122 int halted;
123 int skipped;
124 int actual;
125 int non_null;
126 int active;
127 int abandoning;
128 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
129 int toggle_bits, int error_count, int condition_code,
130 int repeat_number, int halted, int skipped, int actual,
131 int non_null);
132};
133/* Structure to hold all of our device specific stuff*/
134struct usb_ftdi {
135 struct list_head ftdi_list;
136 struct semaphore u132_lock;
137 int command_next;
138 int command_head;
139 struct u132_command command[COMMAND_SIZE];
140 int respond_next;
141 int respond_head;
142 struct u132_respond respond[RESPOND_SIZE];
143 struct u132_target target[4];
144 char device_name[16];
145 unsigned synchronized:1;
146 unsigned enumerated:1;
147 unsigned registered:1;
148 unsigned initialized:1;
149 unsigned card_ejected:1;
150 int function;
151 int sequence_num;
152 int disconnected;
153 int gone_away;
154 int stuck_status;
155 int status_queue_delay;
156 struct semaphore sw_lock;
157 struct usb_device *udev;
158 struct usb_interface *interface;
159 struct usb_class_driver *class;
160 struct work_struct status_work;
161 struct work_struct command_work;
162 struct work_struct respond_work;
163 struct u132_platform_data platform_data;
164 struct resource resources[0];
165 struct platform_device platform_dev;
166 unsigned char *bulk_in_buffer;
167 size_t bulk_in_size;
168 size_t bulk_in_last;
169 size_t bulk_in_left;
170 __u8 bulk_in_endpointAddr;
171 __u8 bulk_out_endpointAddr;
172 struct kref kref;
173 u32 controlreg;
174 u8 response[4 + 1024];
175 int expected;
176 int recieved;
177 int ed_found;
178};
179#define kref_to_usb_ftdi(d) container_of(d, struct usb_ftdi, kref)
180#define platform_device_to_usb_ftdi(d) container_of(d, struct usb_ftdi, \
181 platform_dev)
182static struct usb_driver ftdi_elan_driver;
183static void ftdi_elan_delete(struct kref *kref)
184{
185 struct usb_ftdi *ftdi = kref_to_usb_ftdi(kref);
186 dev_warn(&ftdi->udev->dev, "FREEING ftdi=%p\n", ftdi);
187 usb_put_dev(ftdi->udev);
188 ftdi->disconnected += 1;
189 down(&ftdi_module_lock);
190 list_del_init(&ftdi->ftdi_list);
191 ftdi_instances -= 1;
192 up(&ftdi_module_lock);
193 kfree(ftdi->bulk_in_buffer);
194 ftdi->bulk_in_buffer = NULL;
195}
196
197static void ftdi_elan_put_kref(struct usb_ftdi *ftdi)
198{
199 kref_put(&ftdi->kref, ftdi_elan_delete);
200}
201
202static void ftdi_elan_get_kref(struct usb_ftdi *ftdi)
203{
204 kref_get(&ftdi->kref);
205}
206
207static void ftdi_elan_init_kref(struct usb_ftdi *ftdi)
208{
209 kref_init(&ftdi->kref);
210}
211
212static void ftdi_status_requeue_work(struct usb_ftdi *ftdi, unsigned int delta)
213{
214 if (delta > 0) {
215 if (queue_delayed_work(status_queue, &ftdi->status_work, delta))
216 return;
217 } else if (queue_work(status_queue, &ftdi->status_work))
218 return;
219 kref_put(&ftdi->kref, ftdi_elan_delete);
220 return;
221}
222
223static void ftdi_status_queue_work(struct usb_ftdi *ftdi, unsigned int delta)
224{
225 if (delta > 0) {
226 if (queue_delayed_work(status_queue, &ftdi->status_work, delta))
227 kref_get(&ftdi->kref);
228 } else if (queue_work(status_queue, &ftdi->status_work))
229 kref_get(&ftdi->kref);
230 return;
231}
232
233static void ftdi_status_cancel_work(struct usb_ftdi *ftdi)
234{
235 if (cancel_delayed_work(&ftdi->status_work))
236 kref_put(&ftdi->kref, ftdi_elan_delete);
237}
238
239static void ftdi_command_requeue_work(struct usb_ftdi *ftdi, unsigned int delta)
240{
241 if (delta > 0) {
242 if (queue_delayed_work(command_queue, &ftdi->command_work,
243 delta))
244 return;
245 } else if (queue_work(command_queue, &ftdi->command_work))
246 return;
247 kref_put(&ftdi->kref, ftdi_elan_delete);
248 return;
249}
250
251static void ftdi_command_queue_work(struct usb_ftdi *ftdi, unsigned int delta)
252{
253 if (delta > 0) {
254 if (queue_delayed_work(command_queue, &ftdi->command_work,
255 delta))
256 kref_get(&ftdi->kref);
257 } else if (queue_work(command_queue, &ftdi->command_work))
258 kref_get(&ftdi->kref);
259 return;
260}
261
262static void ftdi_command_cancel_work(struct usb_ftdi *ftdi)
263{
264 if (cancel_delayed_work(&ftdi->command_work))
265 kref_put(&ftdi->kref, ftdi_elan_delete);
266}
267
268static void ftdi_response_requeue_work(struct usb_ftdi *ftdi,
269 unsigned int delta)
270{
271 if (delta > 0) {
272 if (queue_delayed_work(respond_queue, &ftdi->respond_work,
273 delta))
274 return;
275 } else if (queue_work(respond_queue, &ftdi->respond_work))
276 return;
277 kref_put(&ftdi->kref, ftdi_elan_delete);
278 return;
279}
280
281static void ftdi_respond_queue_work(struct usb_ftdi *ftdi, unsigned int delta)
282{
283 if (delta > 0) {
284 if (queue_delayed_work(respond_queue, &ftdi->respond_work,
285 delta))
286 kref_get(&ftdi->kref);
287 } else if (queue_work(respond_queue, &ftdi->respond_work))
288 kref_get(&ftdi->kref);
289 return;
290}
291
292static void ftdi_response_cancel_work(struct usb_ftdi *ftdi)
293{
294 if (cancel_delayed_work(&ftdi->respond_work))
295 kref_put(&ftdi->kref, ftdi_elan_delete);
296}
297
298void ftdi_elan_gone_away(struct platform_device *pdev)
299{
300 struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
301 ftdi->gone_away += 1;
302 ftdi_elan_put_kref(ftdi);
303}
304
305
306EXPORT_SYMBOL_GPL(ftdi_elan_gone_away);
307void ftdi_release_platform_dev(struct device *dev)
308{
309 dev->parent = NULL;
310}
311
312static void ftdi_elan_do_callback(struct usb_ftdi *ftdi,
313 struct u132_target *target, u8 *buffer, int length);
314static void ftdi_elan_kick_command_queue(struct usb_ftdi *ftdi);
315static void ftdi_elan_kick_respond_queue(struct usb_ftdi *ftdi);
316static int ftdi_elan_setupOHCI(struct usb_ftdi *ftdi);
317static int ftdi_elan_checkingPCI(struct usb_ftdi *ftdi);
318static int ftdi_elan_enumeratePCI(struct usb_ftdi *ftdi);
319static int ftdi_elan_synchronize(struct usb_ftdi *ftdi);
320static int ftdi_elan_stuck_waiting(struct usb_ftdi *ftdi);
321static int ftdi_elan_command_engine(struct usb_ftdi *ftdi);
322static int ftdi_elan_respond_engine(struct usb_ftdi *ftdi);
323static int ftdi_elan_hcd_init(struct usb_ftdi *ftdi)
324{
325 int result;
326 if (ftdi->platform_dev.dev.parent)
327 return -EBUSY;
328 ftdi_elan_get_kref(ftdi);
329 ftdi->platform_data.potpg = 100;
330 ftdi->platform_data.reset = NULL;
331 ftdi->platform_dev.id = ftdi->sequence_num;
332 ftdi->platform_dev.resource = ftdi->resources;
333 ftdi->platform_dev.num_resources = ARRAY_SIZE(ftdi->resources);
334 ftdi->platform_dev.dev.platform_data = &ftdi->platform_data;
335 ftdi->platform_dev.dev.parent = NULL;
336 ftdi->platform_dev.dev.release = ftdi_release_platform_dev;
337 ftdi->platform_dev.dev.dma_mask = NULL;
338 snprintf(ftdi->device_name, sizeof(ftdi->device_name), "u132_hcd");
339 ftdi->platform_dev.name = ftdi->device_name;
340 dev_info(&ftdi->udev->dev, "requesting module '%s'\n", "u132_hcd");
341 request_module("u132_hcd");
342 dev_info(&ftdi->udev->dev, "registering '%s'\n",
343 ftdi->platform_dev.name);
344 result = platform_device_register(&ftdi->platform_dev);
345 return result;
346}
347
348static void ftdi_elan_abandon_completions(struct usb_ftdi *ftdi)
349{
350 down(&ftdi->u132_lock);
351 while (ftdi->respond_next > ftdi->respond_head) {
352 struct u132_respond *respond = &ftdi->respond[RESPOND_MASK &
353 ftdi->respond_head++];
354 *respond->result = -ESHUTDOWN;
355 *respond->value = 0;
356 complete(&respond->wait_completion);
357 } up(&ftdi->u132_lock);
358}
359
360static void ftdi_elan_abandon_targets(struct usb_ftdi *ftdi)
361{
362 int ed_number = 4;
363 down(&ftdi->u132_lock);
364 while (ed_number-- > 0) {
365 struct u132_target *target = &ftdi->target[ed_number];
366 if (target->active == 1) {
367 target->condition_code = TD_DEVNOTRESP;
368 up(&ftdi->u132_lock);
369 ftdi_elan_do_callback(ftdi, target, NULL, 0);
370 down(&ftdi->u132_lock);
371 }
372 }
373 ftdi->recieved = 0;
374 ftdi->expected = 4;
375 ftdi->ed_found = 0;
376 up(&ftdi->u132_lock);
377}
378
379static void ftdi_elan_flush_targets(struct usb_ftdi *ftdi)
380{
381 int ed_number = 4;
382 down(&ftdi->u132_lock);
383 while (ed_number-- > 0) {
384 struct u132_target *target = &ftdi->target[ed_number];
385 target->abandoning = 1;
386 wait_1:if (target->active == 1) {
387 int command_size = ftdi->command_next -
388 ftdi->command_head;
389 if (command_size < COMMAND_SIZE) {
390 struct u132_command *command = &ftdi->command[
391 COMMAND_MASK & ftdi->command_next];
392 command->header = 0x80 | (ed_number << 5) | 0x4;
393 command->length = 0x00;
394 command->address = 0x00;
395 command->width = 0x00;
396 command->follows = 0;
397 command->value = 0;
398 command->buffer = &command->value;
399 ftdi->command_next += 1;
400 ftdi_elan_kick_command_queue(ftdi);
401 } else {
402 up(&ftdi->u132_lock);
403 msleep(100);
404 down(&ftdi->u132_lock);
405 goto wait_1;
406 }
407 }
408 wait_2:if (target->active == 1) {
409 int command_size = ftdi->command_next -
410 ftdi->command_head;
411 if (command_size < COMMAND_SIZE) {
412 struct u132_command *command = &ftdi->command[
413 COMMAND_MASK & ftdi->command_next];
414 command->header = 0x90 | (ed_number << 5);
415 command->length = 0x00;
416 command->address = 0x00;
417 command->width = 0x00;
418 command->follows = 0;
419 command->value = 0;
420 command->buffer = &command->value;
421 ftdi->command_next += 1;
422 ftdi_elan_kick_command_queue(ftdi);
423 } else {
424 up(&ftdi->u132_lock);
425 msleep(100);
426 down(&ftdi->u132_lock);
427 goto wait_2;
428 }
429 }
430 }
431 ftdi->recieved = 0;
432 ftdi->expected = 4;
433 ftdi->ed_found = 0;
434 up(&ftdi->u132_lock);
435}
436
437static void ftdi_elan_cancel_targets(struct usb_ftdi *ftdi)
438{
439 int ed_number = 4;
440 down(&ftdi->u132_lock);
441 while (ed_number-- > 0) {
442 struct u132_target *target = &ftdi->target[ed_number];
443 target->abandoning = 1;
444 wait:if (target->active == 1) {
445 int command_size = ftdi->command_next -
446 ftdi->command_head;
447 if (command_size < COMMAND_SIZE) {
448 struct u132_command *command = &ftdi->command[
449 COMMAND_MASK & ftdi->command_next];
450 command->header = 0x80 | (ed_number << 5) | 0x4;
451 command->length = 0x00;
452 command->address = 0x00;
453 command->width = 0x00;
454 command->follows = 0;
455 command->value = 0;
456 command->buffer = &command->value;
457 ftdi->command_next += 1;
458 ftdi_elan_kick_command_queue(ftdi);
459 } else {
460 up(&ftdi->u132_lock);
461 msleep(100);
462 down(&ftdi->u132_lock);
463 goto wait;
464 }
465 }
466 }
467 ftdi->recieved = 0;
468 ftdi->expected = 4;
469 ftdi->ed_found = 0;
470 up(&ftdi->u132_lock);
471}
472
473static void ftdi_elan_kick_command_queue(struct usb_ftdi *ftdi)
474{
475 ftdi_command_queue_work(ftdi, 0);
476 return;
477}
478
479static void ftdi_elan_command_work(void *data)
480{
481 struct usb_ftdi *ftdi = data;
482 if (ftdi->disconnected > 0) {
483 ftdi_elan_put_kref(ftdi);
484 return;
485 } else {
486 int retval = ftdi_elan_command_engine(ftdi);
487 if (retval == -ESHUTDOWN) {
488 ftdi->disconnected += 1;
489 } else if (retval == -ENODEV) {
490 ftdi->disconnected += 1;
491 } else if (retval)
492 dev_err(&ftdi->udev->dev, "command error %d\n", retval);
493 ftdi_command_requeue_work(ftdi, msecs_to_jiffies(10));
494 return;
495 }
496}
497
498static void ftdi_elan_kick_respond_queue(struct usb_ftdi *ftdi)
499{
500 ftdi_respond_queue_work(ftdi, 0);
501 return;
502}
503
504static void ftdi_elan_respond_work(void *data)
505{
506 struct usb_ftdi *ftdi = data;
507 if (ftdi->disconnected > 0) {
508 ftdi_elan_put_kref(ftdi);
509 return;
510 } else {
511 int retval = ftdi_elan_respond_engine(ftdi);
512 if (retval == 0) {
513 } else if (retval == -ESHUTDOWN) {
514 ftdi->disconnected += 1;
515 } else if (retval == -ENODEV) {
516 ftdi->disconnected += 1;
517 } else if (retval == -ENODEV) {
518 ftdi->disconnected += 1;
519 } else if (retval == -EILSEQ) {
520 ftdi->disconnected += 1;
521 } else {
522 ftdi->disconnected += 1;
523 dev_err(&ftdi->udev->dev, "respond error %d\n", retval);
524 }
525 if (ftdi->disconnected > 0) {
526 ftdi_elan_abandon_completions(ftdi);
527 ftdi_elan_abandon_targets(ftdi);
528 }
529 ftdi_response_requeue_work(ftdi, msecs_to_jiffies(10));
530 return;
531 }
532}
533
534
535/*
536* the sw_lock is initially held and will be freed
537* after the FTDI has been synchronized
538*
539*/
540static void ftdi_elan_status_work(void *data)
541{
542 struct usb_ftdi *ftdi = data;
543 int work_delay_in_msec = 0;
544 if (ftdi->disconnected > 0) {
545 ftdi_elan_put_kref(ftdi);
546 return;
547 } else if (ftdi->synchronized == 0) {
548 down(&ftdi->sw_lock);
549 if (ftdi_elan_synchronize(ftdi) == 0) {
550 ftdi->synchronized = 1;
551 ftdi_command_queue_work(ftdi, 1);
552 ftdi_respond_queue_work(ftdi, 1);
553 up(&ftdi->sw_lock);
554 work_delay_in_msec = 100;
555 } else {
556 dev_err(&ftdi->udev->dev, "synchronize failed\n");
557 up(&ftdi->sw_lock);
558 work_delay_in_msec = 10 *1000;
559 }
560 } else if (ftdi->stuck_status > 0) {
561 if (ftdi_elan_stuck_waiting(ftdi) == 0) {
562 ftdi->stuck_status = 0;
563 ftdi->synchronized = 0;
564 } else if ((ftdi->stuck_status++ % 60) == 1) {
565 dev_err(&ftdi->udev->dev, "WRONG type of card inserted "
566 "- please remove\n");
567 } else
568 dev_err(&ftdi->udev->dev, "WRONG type of card inserted "
569 "- checked %d times\n", ftdi->stuck_status);
570 work_delay_in_msec = 100;
571 } else if (ftdi->enumerated == 0) {
572 if (ftdi_elan_enumeratePCI(ftdi) == 0) {
573 ftdi->enumerated = 1;
574 work_delay_in_msec = 250;
575 } else
576 work_delay_in_msec = 1000;
577 } else if (ftdi->initialized == 0) {
578 if (ftdi_elan_setupOHCI(ftdi) == 0) {
579 ftdi->initialized = 1;
580 work_delay_in_msec = 500;
581 } else {
582 dev_err(&ftdi->udev->dev, "initialized failed - trying "
583 "again in 10 seconds\n");
584 work_delay_in_msec = 10 *1000;
585 }
586 } else if (ftdi->registered == 0) {
587 work_delay_in_msec = 10;
588 if (ftdi_elan_hcd_init(ftdi) == 0) {
589 ftdi->registered = 1;
590 } else
591 dev_err(&ftdi->udev->dev, "register failed\n");
592 work_delay_in_msec = 250;
593 } else {
594 if (ftdi_elan_checkingPCI(ftdi) == 0) {
595 work_delay_in_msec = 250;
596 } else if (ftdi->controlreg & 0x00400000) {
597 if (ftdi->gone_away > 0) {
598 dev_err(&ftdi->udev->dev, "PCI device eject con"
599 "firmed platform_dev.dev.parent=%p plat"
600 "form_dev.dev=%p\n",
601 ftdi->platform_dev.dev.parent,
602 &ftdi->platform_dev.dev);
603 platform_device_unregister(&ftdi->platform_dev);
604 ftdi->platform_dev.dev.parent = NULL;
605 ftdi->registered = 0;
606 ftdi->enumerated = 0;
607 ftdi->card_ejected = 0;
608 ftdi->initialized = 0;
609 ftdi->gone_away = 0;
610 } else
611 ftdi_elan_flush_targets(ftdi);
612 work_delay_in_msec = 250;
613 } else {
614 dev_err(&ftdi->udev->dev, "PCI device has disappeared\n"
615 );
616 ftdi_elan_cancel_targets(ftdi);
617 work_delay_in_msec = 500;
618 ftdi->enumerated = 0;
619 ftdi->initialized = 0;
620 }
621 }
622 if (ftdi->disconnected > 0) {
623 ftdi_elan_put_kref(ftdi);
624 return;
625 } else {
626 ftdi_status_requeue_work(ftdi,
627 msecs_to_jiffies(work_delay_in_msec));
628 return;
629 }
630}
631
632
633/*
634* file_operations for the jtag interface
635*
636* the usage count for the device is incremented on open()
637* and decremented on release()
638*/
639static int ftdi_elan_open(struct inode *inode, struct file *file)
640{
641 int subminor = iminor(inode);
642 struct usb_interface *interface = usb_find_interface(&ftdi_elan_driver,
643 subminor);
644 if (!interface) {
645 printk(KERN_ERR "can't find device for minor %d\n", subminor);
646 return -ENODEV;
647 } else {
648 struct usb_ftdi *ftdi = usb_get_intfdata(interface);
649 if (!ftdi) {
650 return -ENODEV;
651 } else {
652 if (down_interruptible(&ftdi->sw_lock)) {
653 return -EINTR;
654 } else {
655 ftdi_elan_get_kref(ftdi);
656 file->private_data = ftdi;
657 return 0;
658 }
659 }
660 }
661}
662
663static int ftdi_elan_release(struct inode *inode, struct file *file)
664{
665 struct usb_ftdi *ftdi = (struct usb_ftdi *)file->private_data;
666 if (ftdi == NULL)
667 return -ENODEV;
668 up(&ftdi->sw_lock); /* decrement the count on our device */
669 ftdi_elan_put_kref(ftdi);
670 return 0;
671}
672
673
674#define FTDI_ELAN_IOC_MAGIC 0xA1
675#define FTDI_ELAN_IOCDEBUG _IOC(_IOC_WRITE, FTDI_ELAN_IOC_MAGIC, 1, 132)
676static int ftdi_elan_ioctl(struct inode *inode, struct file *file,
677 unsigned int cmd, unsigned long arg)
678{
679 switch (cmd) {
680 case FTDI_ELAN_IOCDEBUG:{
681 char line[132];
682 int size = strncpy_from_user(line,
683 (const char __user *)arg, sizeof(line));
684 if (size < 0) {
685 return -EINVAL;
686 } else {
687 printk(KERN_ERR "TODO: ioctl %s\n", line);
688 return 0;
689 }
690 }
691 default:
692 return -EFAULT;
693 }
694}
695
696
697/*
698*
699* blocking bulk reads are used to get data from the device
700*
701*/
702static ssize_t ftdi_elan_read(struct file *file, char __user *buffer,
703 size_t count, loff_t *ppos)
704{
705 char data[30 *3 + 4];
706 char *d = data;
707 int m = (sizeof(data) - 1) / 3;
708 int bytes_read = 0;
709 int retry_on_empty = 10;
710 int retry_on_timeout = 5;
711 struct usb_ftdi *ftdi = (struct usb_ftdi *)file->private_data;
712 if (ftdi->disconnected > 0) {
713 return -ENODEV;
714 }
715 data[0] = 0;
716 have:if (ftdi->bulk_in_left > 0) {
717 if (count-- > 0) {
718 char *p = ++ftdi->bulk_in_last + ftdi->bulk_in_buffer;
719 ftdi->bulk_in_left -= 1;
720 if (bytes_read < m) {
721 d += sprintf(d, " %02X", 0x000000FF & *p);
722 } else if (bytes_read > m) {
723 } else
724 d += sprintf(d, " ..");
725 if (copy_to_user(buffer++, p, 1)) {
726 return -EFAULT;
727 } else {
728 bytes_read += 1;
729 goto have;
730 }
731 } else
732 return bytes_read;
733 }
734 more:if (count > 0) {
735 int packet_bytes = 0;
736 int retval = usb_bulk_msg(ftdi->udev,
737 usb_rcvbulkpipe(ftdi->udev, ftdi->bulk_in_endpointAddr),
738 ftdi->bulk_in_buffer, ftdi->bulk_in_size,
739 &packet_bytes, msecs_to_jiffies(50));
740 if (packet_bytes > 2) {
741 ftdi->bulk_in_left = packet_bytes - 2;
742 ftdi->bulk_in_last = 1;
743 goto have;
744 } else if (retval == -ETIMEDOUT) {
745 if (retry_on_timeout-- > 0) {
746 goto more;
747 } else if (bytes_read > 0) {
748 return bytes_read;
749 } else
750 return retval;
751 } else if (retval == 0) {
752 if (retry_on_empty-- > 0) {
753 goto more;
754 } else
755 return bytes_read;
756 } else
757 return retval;
758 } else
759 return bytes_read;
760}
761
762static void ftdi_elan_write_bulk_callback(struct urb *urb, struct pt_regs *regs)
763{
764 struct usb_ftdi *ftdi = (struct usb_ftdi *)urb->context;
765 if (urb->status && !(urb->status == -ENOENT || urb->status ==
766 -ECONNRESET || urb->status == -ESHUTDOWN)) {
767 dev_err(&ftdi->udev->dev, "urb=%p write bulk status received: %"
768 "d\n", urb, urb->status);
769 }
770 usb_buffer_free(urb->dev, urb->transfer_buffer_length,
771 urb->transfer_buffer, urb->transfer_dma);
772}
773
774static int fill_buffer_with_all_queued_commands(struct usb_ftdi *ftdi,
775 char *buf, int command_size, int total_size)
776{
777 int ed_commands = 0;
778 int b = 0;
779 int I = command_size;
780 int i = ftdi->command_head;
781 while (I-- > 0) {
782 struct u132_command *command = &ftdi->command[COMMAND_MASK &
783 i++];
784 int F = command->follows;
785 u8 *f = command->buffer;
786 if (command->header & 0x80) {
787 ed_commands |= 1 << (0x3 & (command->header >> 5));
788 }
789 buf[b++] = command->header;
790 buf[b++] = (command->length >> 0) & 0x00FF;
791 buf[b++] = (command->length >> 8) & 0x00FF;
792 buf[b++] = command->address;
793 buf[b++] = command->width;
794 while (F-- > 0) {
795 buf[b++] = *f++;
796 }
797 }
798 return ed_commands;
799}
800
801static int ftdi_elan_total_command_size(struct usb_ftdi *ftdi, int command_size)
802{
803 int total_size = 0;
804 int I = command_size;
805 int i = ftdi->command_head;
806 while (I-- > 0) {
807 struct u132_command *command = &ftdi->command[COMMAND_MASK &
808 i++];
809 total_size += 5 + command->follows;
810 } return total_size;
811}
812
813static int ftdi_elan_command_engine(struct usb_ftdi *ftdi)
814{
815 int retval;
816 char *buf;
817 int ed_commands;
818 int total_size;
819 struct urb *urb;
820 int command_size = ftdi->command_next - ftdi->command_head;
821 if (command_size == 0)
822 return 0;
823 total_size = ftdi_elan_total_command_size(ftdi, command_size);
824 urb = usb_alloc_urb(0, GFP_KERNEL);
825 if (!urb) {
826 dev_err(&ftdi->udev->dev, "could not get a urb to write %d comm"
827 "ands totaling %d bytes to the Uxxx\n", command_size,
828 total_size);
829 return -ENOMEM;
830 }
831 buf = usb_buffer_alloc(ftdi->udev, total_size, GFP_KERNEL,
832 &urb->transfer_dma);
833 if (!buf) {
834 dev_err(&ftdi->udev->dev, "could not get a buffer to write %d c"
835 "ommands totaling %d bytes to the Uxxx\n", command_size,
836 total_size);
837 usb_free_urb(urb);
838 return -ENOMEM;
839 }
840 ed_commands = fill_buffer_with_all_queued_commands(ftdi, buf,
841 command_size, total_size);
842 usb_fill_bulk_urb(urb, ftdi->udev, usb_sndbulkpipe(ftdi->udev,
843 ftdi->bulk_out_endpointAddr), buf, total_size,
844 ftdi_elan_write_bulk_callback, ftdi);
845 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
846 if (ed_commands) {
847 char diag[40 *3 + 4];
848 char *d = diag;
849 int m = total_size;
850 u8 *c = buf;
851 int s = (sizeof(diag) - 1) / 3;
852 diag[0] = 0;
853 while (s-- > 0 && m-- > 0) {
854 if (s > 0 || m == 0) {
855 d += sprintf(d, " %02X", *c++);
856 } else
857 d += sprintf(d, " ..");
858 }
859 }
860 retval = usb_submit_urb(urb, GFP_KERNEL);
861 if (retval) {
862 dev_err(&ftdi->udev->dev, "failed %d to submit urb %p to write "
863 "%d commands totaling %d bytes to the Uxxx\n", retval,
864 urb, command_size, total_size);
865 usb_buffer_free(ftdi->udev, total_size, buf, urb->transfer_dma);
866 usb_free_urb(urb);
867 return retval;
868 }
869 usb_free_urb(urb); /* release our reference to this urb,
870 the USB core will eventually free it entirely */
871 ftdi->command_head += command_size;
872 ftdi_elan_kick_respond_queue(ftdi);
873 return 0;
874}
875
876static void ftdi_elan_do_callback(struct usb_ftdi *ftdi,
877 struct u132_target *target, u8 *buffer, int length)
878{
879 struct urb *urb = target->urb;
880 int halted = target->halted;
881 int skipped = target->skipped;
882 int actual = target->actual;
883 int non_null = target->non_null;
884 int toggle_bits = target->toggle_bits;
885 int error_count = target->error_count;
886 int condition_code = target->condition_code;
887 int repeat_number = target->repeat_number;
888 void (*callback) (void *, struct urb *, u8 *, int, int, int, int, int,
889 int, int, int, int) = target->callback;
890 target->active -= 1;
891 target->callback = NULL;
892 (*callback) (target->endp, urb, buffer, length, toggle_bits,
893 error_count, condition_code, repeat_number, halted, skipped,
894 actual, non_null);
895}
896
897static char *have_ed_set_response(struct usb_ftdi *ftdi,
898 struct u132_target *target, u16 ed_length, int ed_number, int ed_type,
899 char *b)
900{
901 int payload = (ed_length >> 0) & 0x07FF;
902 down(&ftdi->u132_lock);
903 target->actual = 0;
904 target->non_null = (ed_length >> 15) & 0x0001;
905 target->repeat_number = (ed_length >> 11) & 0x000F;
906 if (ed_type == 0x02) {
907 if (payload == 0 || target->abandoning > 0) {
908 target->abandoning = 0;
909 up(&ftdi->u132_lock);
910 ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response,
911 payload);
912 ftdi->recieved = 0;
913 ftdi->expected = 4;
914 ftdi->ed_found = 0;
915 return ftdi->response;
916 } else {
917 ftdi->expected = 4 + payload;
918 ftdi->ed_found = 1;
919 up(&ftdi->u132_lock);
920 return b;
921 }
922 } else if (ed_type == 0x03) {
923 if (payload == 0 || target->abandoning > 0) {
924 target->abandoning = 0;
925 up(&ftdi->u132_lock);
926 ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response,
927 payload);
928 ftdi->recieved = 0;
929 ftdi->expected = 4;
930 ftdi->ed_found = 0;
931 return ftdi->response;
932 } else {
933 ftdi->expected = 4 + payload;
934 ftdi->ed_found = 1;
935 up(&ftdi->u132_lock);
936 return b;
937 }
938 } else if (ed_type == 0x01) {
939 target->abandoning = 0;
940 up(&ftdi->u132_lock);
941 ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response,
942 payload);
943 ftdi->recieved = 0;
944 ftdi->expected = 4;
945 ftdi->ed_found = 0;
946 return ftdi->response;
947 } else {
948 target->abandoning = 0;
949 up(&ftdi->u132_lock);
950 ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response,
951 payload);
952 ftdi->recieved = 0;
953 ftdi->expected = 4;
954 ftdi->ed_found = 0;
955 return ftdi->response;
956 }
957}
958
959static char *have_ed_get_response(struct usb_ftdi *ftdi,
960 struct u132_target *target, u16 ed_length, int ed_number, int ed_type,
961 char *b)
962{
963 down(&ftdi->u132_lock);
964 target->condition_code = TD_DEVNOTRESP;
965 target->actual = (ed_length >> 0) & 0x01FF;
966 target->non_null = (ed_length >> 15) & 0x0001;
967 target->repeat_number = (ed_length >> 11) & 0x000F;
968 up(&ftdi->u132_lock);
969 if (target->active)
970 ftdi_elan_do_callback(ftdi, target, NULL, 0);
971 target->abandoning = 0;
972 ftdi->recieved = 0;
973 ftdi->expected = 4;
974 ftdi->ed_found = 0;
975 return ftdi->response;
976}
977
978
979/*
980* The engine tries to empty the FTDI fifo
981*
982* all responses found in the fifo data are dispatched thus
983* the response buffer can only ever hold a maximum sized
984* response from the Uxxx.
985*
986*/
987static int ftdi_elan_respond_engine(struct usb_ftdi *ftdi)
988{
989 u8 *b = ftdi->response + ftdi->recieved;
990 int bytes_read = 0;
991 int retry_on_empty = 1;
992 int retry_on_timeout = 3;
993 int empty_packets = 0;
994 read:{
995 int packet_bytes = 0;
996 int retval = usb_bulk_msg(ftdi->udev,
997 usb_rcvbulkpipe(ftdi->udev, ftdi->bulk_in_endpointAddr),
998 ftdi->bulk_in_buffer, ftdi->bulk_in_size,
999 &packet_bytes, msecs_to_jiffies(500));
1000 char diag[30 *3 + 4];
1001 char *d = diag;
1002 int m = packet_bytes;
1003 u8 *c = ftdi->bulk_in_buffer;
1004 int s = (sizeof(diag) - 1) / 3;
1005 diag[0] = 0;
1006 while (s-- > 0 && m-- > 0) {
1007 if (s > 0 || m == 0) {
1008 d += sprintf(d, " %02X", *c++);
1009 } else
1010 d += sprintf(d, " ..");
1011 }
1012 if (packet_bytes > 2) {
1013 ftdi->bulk_in_left = packet_bytes - 2;
1014 ftdi->bulk_in_last = 1;
1015 goto have;
1016 } else if (retval == -ETIMEDOUT) {
1017 if (retry_on_timeout-- > 0) {
1018 dev_err(&ftdi->udev->dev, "TIMED OUT with packe"
1019 "t_bytes = %d with total %d bytes%s\n",
1020 packet_bytes, bytes_read, diag);
1021 goto more;
1022 } else if (bytes_read > 0) {
1023 dev_err(&ftdi->udev->dev, "ONLY %d bytes%s\n",
1024 bytes_read, diag);
1025 return -ENOMEM;
1026 } else {
1027 dev_err(&ftdi->udev->dev, "TIMED OUT with packe"
1028 "t_bytes = %d with total %d bytes%s\n",
1029 packet_bytes, bytes_read, diag);
1030 return -ENOMEM;
1031 }
1032 } else if (retval == -EILSEQ) {
1033 dev_err(&ftdi->udev->dev, "error = %d with packet_bytes"
1034 " = %d with total %d bytes%s\n", retval,
1035 packet_bytes, bytes_read, diag);
1036 return retval;
1037 } else if (retval) {
1038 dev_err(&ftdi->udev->dev, "error = %d with packet_bytes"
1039 " = %d with total %d bytes%s\n", retval,
1040 packet_bytes, bytes_read, diag);
1041 return retval;
1042 } else if (packet_bytes == 2) {
1043 unsigned char s0 = ftdi->bulk_in_buffer[0];
1044 unsigned char s1 = ftdi->bulk_in_buffer[1];
1045 empty_packets += 1;
1046 if (s0 == 0x31 && s1 == 0x60) {
1047 if (retry_on_empty-- > 0) {
1048 goto more;
1049 } else
1050 return 0;
1051 } else if (s0 == 0x31 && s1 == 0x00) {
1052 if (retry_on_empty-- > 0) {
1053 goto more;
1054 } else
1055 return 0;
1056 } else {
1057 if (retry_on_empty-- > 0) {
1058 goto more;
1059 } else
1060 return 0;
1061 }
1062 } else if (packet_bytes == 1) {
1063 if (retry_on_empty-- > 0) {
1064 goto more;
1065 } else
1066 return 0;
1067 } else {
1068 if (retry_on_empty-- > 0) {
1069 goto more;
1070 } else
1071 return 0;
1072 }
1073 }
1074 more:{
1075 goto read;
1076 }
1077 have:if (ftdi->bulk_in_left > 0) {
1078 u8 c = ftdi->bulk_in_buffer[++ftdi->bulk_in_last];
1079 bytes_read += 1;
1080 ftdi->bulk_in_left -= 1;
1081 if (ftdi->recieved == 0 && c == 0xFF) {
1082 goto have;
1083 } else
1084 *b++ = c;
1085 if (++ftdi->recieved < ftdi->expected) {
1086 goto have;
1087 } else if (ftdi->ed_found) {
1088 int ed_number = (ftdi->response[0] >> 5) & 0x03;
1089 u16 ed_length = (ftdi->response[2] << 8) |
1090 ftdi->response[1];
1091 struct u132_target *target = &ftdi->target[ed_number];
1092 int payload = (ed_length >> 0) & 0x07FF;
1093 char diag[30 *3 + 4];
1094 char *d = diag;
1095 int m = payload;
1096 u8 *c = 4 + ftdi->response;
1097 int s = (sizeof(diag) - 1) / 3;
1098 diag[0] = 0;
1099 while (s-- > 0 && m-- > 0) {
1100 if (s > 0 || m == 0) {
1101 d += sprintf(d, " %02X", *c++);
1102 } else
1103 d += sprintf(d, " ..");
1104 }
1105 ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response,
1106 payload);
1107 ftdi->recieved = 0;
1108 ftdi->expected = 4;
1109 ftdi->ed_found = 0;
1110 b = ftdi->response;
1111 goto have;
1112 } else if (ftdi->expected == 8) {
1113 u8 buscmd;
1114 int respond_head = ftdi->respond_head++;
1115 struct u132_respond *respond = &ftdi->respond[
1116 RESPOND_MASK & respond_head];
1117 u32 data = ftdi->response[7];
1118 data <<= 8;
1119 data |= ftdi->response[6];
1120 data <<= 8;
1121 data |= ftdi->response[5];
1122 data <<= 8;
1123 data |= ftdi->response[4];
1124 *respond->value = data;
1125 *respond->result = 0;
1126 complete(&respond->wait_completion);
1127 ftdi->recieved = 0;
1128 ftdi->expected = 4;
1129 ftdi->ed_found = 0;
1130 b = ftdi->response;
1131 buscmd = (ftdi->response[0] >> 0) & 0x0F;
1132 if (buscmd == 0x00) {
1133 } else if (buscmd == 0x02) {
1134 } else if (buscmd == 0x06) {
1135 } else if (buscmd == 0x0A) {
1136 } else
1137 dev_err(&ftdi->udev->dev, "Uxxx unknown(%0X) va"
1138 "lue = %08X\n", buscmd, data);
1139 goto have;
1140 } else {
1141 if ((ftdi->response[0] & 0x80) == 0x00) {
1142 ftdi->expected = 8;
1143 goto have;
1144 } else {
1145 int ed_number = (ftdi->response[0] >> 5) & 0x03;
1146 int ed_type = (ftdi->response[0] >> 0) & 0x03;
1147 u16 ed_length = (ftdi->response[2] << 8) |
1148 ftdi->response[1];
1149 struct u132_target *target = &ftdi->target[
1150 ed_number];
1151 target->halted = (ftdi->response[0] >> 3) &
1152 0x01;
1153 target->skipped = (ftdi->response[0] >> 2) &
1154 0x01;
1155 target->toggle_bits = (ftdi->response[3] >> 6)
1156 & 0x03;
1157 target->error_count = (ftdi->response[3] >> 4)
1158 & 0x03;
1159 target->condition_code = (ftdi->response[
1160 3] >> 0) & 0x0F;
1161 if ((ftdi->response[0] & 0x10) == 0x00) {
1162 b = have_ed_set_response(ftdi, target,
1163 ed_length, ed_number, ed_type,
1164 b);
1165 goto have;
1166 } else {
1167 b = have_ed_get_response(ftdi, target,
1168 ed_length, ed_number, ed_type,
1169 b);
1170 goto have;
1171 }
1172 }
1173 }
1174 } else
1175 goto more;
1176}
1177
1178
1179/*
1180* create a urb, and a buffer for it, and copy the data to the urb
1181*
1182*/
1183static ssize_t ftdi_elan_write(struct file *file,
1184 const char __user *user_buffer, size_t count,
1185 loff_t *ppos)
1186{
1187 int retval = 0;
1188 struct urb *urb;
1189 char *buf;
1190 char data[30 *3 + 4];
1191 char *d = data;
1192 const char __user *s = user_buffer;
1193 int m = (sizeof(data) - 1) / 3;
1194 struct usb_ftdi *ftdi = (struct usb_ftdi *)file->private_data;
1195 if (ftdi->disconnected > 0) {
1196 return -ENODEV;
1197 }
1198 if (count == 0) {
1199 goto exit;
1200 }
1201 urb = usb_alloc_urb(0, GFP_KERNEL);
1202 if (!urb) {
1203 retval = -ENOMEM;
1204 goto error_1;
1205 }
1206 buf = usb_buffer_alloc(ftdi->udev, count, GFP_KERNEL,
1207 &urb->transfer_dma);
1208 if (!buf) {
1209 retval = -ENOMEM;
1210 goto error_2;
1211 }
1212 if (copy_from_user(buf, user_buffer, count)) {
1213 retval = -EFAULT;
1214 goto error_3;
1215 }
1216 usb_fill_bulk_urb(urb, ftdi->udev, usb_sndbulkpipe(ftdi->udev,
1217 ftdi->bulk_out_endpointAddr), buf, count,
1218 ftdi_elan_write_bulk_callback, ftdi);
1219 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1220 retval = usb_submit_urb(urb, GFP_KERNEL);
1221 if (retval) {
1222 dev_err(&ftdi->udev->dev, "failed submitting write urb, error %"
1223 "d\n", retval);
1224 goto error_4;
1225 }
1226 usb_free_urb(urb);
1227 exit:;
1228 if (count > m) {
1229 int I = m - 1;
1230 while (I-- > 0) {
1231 d += sprintf(d, " %02X", 0x000000FF & *s++);
1232 }
1233 d += sprintf(d, " ..");
1234 } else {
1235 int I = count;
1236 while (I-- > 0) {
1237 d += sprintf(d, " %02X", 0x000000FF & *s++);
1238 }
1239 }
1240 return count;
1241 error_4: error_3:usb_buffer_free(ftdi->udev, count, buf,
1242 urb->transfer_dma);
1243 error_2:usb_free_urb(urb);
1244 error_1:return retval;
1245}
1246
1247static struct file_operations ftdi_elan_fops = {
1248 .owner = THIS_MODULE,
1249 .llseek = no_llseek,
1250 .ioctl = ftdi_elan_ioctl,
1251 .read = ftdi_elan_read,
1252 .write = ftdi_elan_write,
1253 .open = ftdi_elan_open,
1254 .release = ftdi_elan_release,
1255};
1256
1257/*
1258* usb class driver info in order to get a minor number from the usb core,
1259* and to have the device registered with the driver core
1260*/
1261static struct usb_class_driver ftdi_elan_jtag_class = {
1262 .name = "ftdi-%d-jtag",
1263 .fops = &ftdi_elan_fops,
1264 .minor_base = USB_FTDI_ELAN_MINOR_BASE,
1265};
1266
1267/*
1268* the following definitions are for the
1269* ELAN FPGA state machgine processor that
1270* lies on the other side of the FTDI chip
1271*/
1272#define cPCIu132rd 0x0
1273#define cPCIu132wr 0x1
1274#define cPCIiord 0x2
1275#define cPCIiowr 0x3
1276#define cPCImemrd 0x6
1277#define cPCImemwr 0x7
1278#define cPCIcfgrd 0xA
1279#define cPCIcfgwr 0xB
1280#define cPCInull 0xF
1281#define cU132cmd_status 0x0
1282#define cU132flash 0x1
1283#define cPIDsetup 0x0
1284#define cPIDout 0x1
1285#define cPIDin 0x2
1286#define cPIDinonce 0x3
1287#define cCCnoerror 0x0
1288#define cCCcrc 0x1
1289#define cCCbitstuff 0x2
1290#define cCCtoggle 0x3
1291#define cCCstall 0x4
1292#define cCCnoresp 0x5
1293#define cCCbadpid1 0x6
1294#define cCCbadpid2 0x7
1295#define cCCdataoverrun 0x8
1296#define cCCdataunderrun 0x9
1297#define cCCbuffoverrun 0xC
1298#define cCCbuffunderrun 0xD
1299#define cCCnotaccessed 0xF
1300static int ftdi_elan_write_reg(struct usb_ftdi *ftdi, u32 data)
1301{
1302 wait:if (ftdi->disconnected > 0) {
1303 return -ENODEV;
1304 } else {
1305 int command_size;
1306 down(&ftdi->u132_lock);
1307 command_size = ftdi->command_next - ftdi->command_head;
1308 if (command_size < COMMAND_SIZE) {
1309 struct u132_command *command = &ftdi->command[
1310 COMMAND_MASK & ftdi->command_next];
1311 command->header = 0x00 | cPCIu132wr;
1312 command->length = 0x04;
1313 command->address = 0x00;
1314 command->width = 0x00;
1315 command->follows = 4;
1316 command->value = data;
1317 command->buffer = &command->value;
1318 ftdi->command_next += 1;
1319 ftdi_elan_kick_command_queue(ftdi);
1320 up(&ftdi->u132_lock);
1321 return 0;
1322 } else {
1323 up(&ftdi->u132_lock);
1324 msleep(100);
1325 goto wait;
1326 }
1327 }
1328}
1329
1330static int ftdi_elan_write_config(struct usb_ftdi *ftdi, int config_offset,
1331 u8 width, u32 data)
1332{
1333 u8 addressofs = config_offset / 4;
1334 wait:if (ftdi->disconnected > 0) {
1335 return -ENODEV;
1336 } else {
1337 int command_size;
1338 down(&ftdi->u132_lock);
1339 command_size = ftdi->command_next - ftdi->command_head;
1340 if (command_size < COMMAND_SIZE) {
1341 struct u132_command *command = &ftdi->command[
1342 COMMAND_MASK & ftdi->command_next];
1343 command->header = 0x00 | (cPCIcfgwr & 0x0F);
1344 command->length = 0x04;
1345 command->address = addressofs;
1346 command->width = 0x00 | (width & 0x0F);
1347 command->follows = 4;
1348 command->value = data;
1349 command->buffer = &command->value;
1350 ftdi->command_next += 1;
1351 ftdi_elan_kick_command_queue(ftdi);
1352 up(&ftdi->u132_lock);
1353 return 0;
1354 } else {
1355 up(&ftdi->u132_lock);
1356 msleep(100);
1357 goto wait;
1358 }
1359 }
1360}
1361
1362static int ftdi_elan_write_pcimem(struct usb_ftdi *ftdi, int mem_offset,
1363 u8 width, u32 data)
1364{
1365 u8 addressofs = mem_offset / 4;
1366 wait:if (ftdi->disconnected > 0) {
1367 return -ENODEV;
1368 } else {
1369 int command_size;
1370 down(&ftdi->u132_lock);
1371 command_size = ftdi->command_next - ftdi->command_head;
1372 if (command_size < COMMAND_SIZE) {
1373 struct u132_command *command = &ftdi->command[
1374 COMMAND_MASK & ftdi->command_next];
1375 command->header = 0x00 | (cPCImemwr & 0x0F);
1376 command->length = 0x04;
1377 command->address = addressofs;
1378 command->width = 0x00 | (width & 0x0F);
1379 command->follows = 4;
1380 command->value = data;
1381 command->buffer = &command->value;
1382 ftdi->command_next += 1;
1383 ftdi_elan_kick_command_queue(ftdi);
1384 up(&ftdi->u132_lock);
1385 return 0;
1386 } else {
1387 up(&ftdi->u132_lock);
1388 msleep(100);
1389 goto wait;
1390 }
1391 }
1392}
1393
1394int usb_ftdi_elan_write_pcimem(struct platform_device *pdev, int mem_offset,
1395 u8 width, u32 data)
1396{
1397 struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
1398 return ftdi_elan_write_pcimem(ftdi, mem_offset, width, data);
1399}
1400
1401
1402EXPORT_SYMBOL_GPL(usb_ftdi_elan_write_pcimem);
1403static int ftdi_elan_read_reg(struct usb_ftdi *ftdi, u32 *data)
1404{
1405 wait:if (ftdi->disconnected > 0) {
1406 return -ENODEV;
1407 } else {
1408 int command_size;
1409 int respond_size;
1410 down(&ftdi->u132_lock);
1411 command_size = ftdi->command_next - ftdi->command_head;
1412 respond_size = ftdi->respond_next - ftdi->respond_head;
1413 if (command_size < COMMAND_SIZE && respond_size < RESPOND_SIZE)
1414 {
1415 struct u132_command *command = &ftdi->command[
1416 COMMAND_MASK & ftdi->command_next];
1417 struct u132_respond *respond = &ftdi->respond[
1418 RESPOND_MASK & ftdi->respond_next];
1419 int result = -ENODEV;
1420 respond->result = &result;
1421 respond->header = command->header = 0x00 | cPCIu132rd;
1422 command->length = 0x04;
1423 respond->address = command->address = cU132cmd_status;
1424 command->width = 0x00;
1425 command->follows = 0;
1426 command->value = 0;
1427 command->buffer = NULL;
1428 respond->value = data;
1429 init_completion(&respond->wait_completion);
1430 ftdi->command_next += 1;
1431 ftdi->respond_next += 1;
1432 ftdi_elan_kick_command_queue(ftdi);
1433 up(&ftdi->u132_lock);
1434 wait_for_completion(&respond->wait_completion);
1435 return result;
1436 } else {
1437 up(&ftdi->u132_lock);
1438 msleep(100);
1439 goto wait;
1440 }
1441 }
1442}
1443
1444int usb_ftdi_elan_read_reg(struct platform_device *pdev, u32 *data)
1445{
1446 struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
1447 return ftdi_elan_read_reg(ftdi, data);
1448}
1449
1450
1451EXPORT_SYMBOL_GPL(usb_ftdi_elan_read_reg);
1452static int ftdi_elan_read_config(struct usb_ftdi *ftdi, int config_offset,
1453 u8 width, u32 *data)
1454{
1455 u8 addressofs = config_offset / 4;
1456 wait:if (ftdi->disconnected > 0) {
1457 return -ENODEV;
1458 } else {
1459 int command_size;
1460 int respond_size;
1461 down(&ftdi->u132_lock);
1462 command_size = ftdi->command_next - ftdi->command_head;
1463 respond_size = ftdi->respond_next - ftdi->respond_head;
1464 if (command_size < COMMAND_SIZE && respond_size < RESPOND_SIZE)
1465 {
1466 struct u132_command *command = &ftdi->command[
1467 COMMAND_MASK & ftdi->command_next];
1468 struct u132_respond *respond = &ftdi->respond[
1469 RESPOND_MASK & ftdi->respond_next];
1470 int result = -ENODEV;
1471 respond->result = &result;
1472 respond->header = command->header = 0x00 | (cPCIcfgrd &
1473 0x0F);
1474 command->length = 0x04;
1475 respond->address = command->address = addressofs;
1476 command->width = 0x00 | (width & 0x0F);
1477 command->follows = 0;
1478 command->value = 0;
1479 command->buffer = NULL;
1480 respond->value = data;
1481 init_completion(&respond->wait_completion);
1482 ftdi->command_next += 1;
1483 ftdi->respond_next += 1;
1484 ftdi_elan_kick_command_queue(ftdi);
1485 up(&ftdi->u132_lock);
1486 wait_for_completion(&respond->wait_completion);
1487 return result;
1488 } else {
1489 up(&ftdi->u132_lock);
1490 msleep(100);
1491 goto wait;
1492 }
1493 }
1494}
1495
1496static int ftdi_elan_read_pcimem(struct usb_ftdi *ftdi, int mem_offset,
1497 u8 width, u32 *data)
1498{
1499 u8 addressofs = mem_offset / 4;
1500 wait:if (ftdi->disconnected > 0) {
1501 return -ENODEV;
1502 } else {
1503 int command_size;
1504 int respond_size;
1505 down(&ftdi->u132_lock);
1506 command_size = ftdi->command_next - ftdi->command_head;
1507 respond_size = ftdi->respond_next - ftdi->respond_head;
1508 if (command_size < COMMAND_SIZE && respond_size < RESPOND_SIZE)
1509 {
1510 struct u132_command *command = &ftdi->command[
1511 COMMAND_MASK & ftdi->command_next];
1512 struct u132_respond *respond = &ftdi->respond[
1513 RESPOND_MASK & ftdi->respond_next];
1514 int result = -ENODEV;
1515 respond->result = &result;
1516 respond->header = command->header = 0x00 | (cPCImemrd &
1517 0x0F);
1518 command->length = 0x04;
1519 respond->address = command->address = addressofs;
1520 command->width = 0x00 | (width & 0x0F);
1521 command->follows = 0;
1522 command->value = 0;
1523 command->buffer = NULL;
1524 respond->value = data;
1525 init_completion(&respond->wait_completion);
1526 ftdi->command_next += 1;
1527 ftdi->respond_next += 1;
1528 ftdi_elan_kick_command_queue(ftdi);
1529 up(&ftdi->u132_lock);
1530 wait_for_completion(&respond->wait_completion);
1531 return result;
1532 } else {
1533 up(&ftdi->u132_lock);
1534 msleep(100);
1535 goto wait;
1536 }
1537 }
1538}
1539
1540int usb_ftdi_elan_read_pcimem(struct platform_device *pdev, int mem_offset,
1541 u8 width, u32 *data)
1542{
1543 struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
1544 if (ftdi->initialized == 0) {
1545 return -ENODEV;
1546 } else
1547 return ftdi_elan_read_pcimem(ftdi, mem_offset, width, data);
1548}
1549
1550
1551EXPORT_SYMBOL_GPL(usb_ftdi_elan_read_pcimem);
1552static int ftdi_elan_edset_setup(struct usb_ftdi *ftdi, u8 ed_number,
1553 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
1554 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
1555 int toggle_bits, int error_count, int condition_code, int repeat_number,
1556 int halted, int skipped, int actual, int non_null))
1557{
1558 u8 ed = ed_number - 1;
1559 wait:if (ftdi->disconnected > 0) {
1560 return -ENODEV;
1561 } else if (ftdi->initialized == 0) {
1562 return -ENODEV;
1563 } else {
1564 int command_size;
1565 down(&ftdi->u132_lock);
1566 command_size = ftdi->command_next - ftdi->command_head;
1567 if (command_size < COMMAND_SIZE) {
1568 struct u132_target *target = &ftdi->target[ed];
1569 struct u132_command *command = &ftdi->command[
1570 COMMAND_MASK & ftdi->command_next];
1571 command->header = 0x80 | (ed << 5);
1572 command->length = 0x8007;
1573 command->address = (toggle_bits << 6) | (ep_number << 2)
1574 | (address << 0);
1575 command->width = usb_maxpacket(urb->dev, urb->pipe,
1576 usb_pipeout(urb->pipe));
1577 command->follows = 8;
1578 command->value = 0;
1579 command->buffer = urb->setup_packet;
1580 target->callback = callback;
1581 target->endp = endp;
1582 target->urb = urb;
1583 target->active = 1;
1584 ftdi->command_next += 1;
1585 ftdi_elan_kick_command_queue(ftdi);
1586 up(&ftdi->u132_lock);
1587 return 0;
1588 } else {
1589 up(&ftdi->u132_lock);
1590 msleep(100);
1591 goto wait;
1592 }
1593 }
1594}
1595
1596int usb_ftdi_elan_edset_setup(struct platform_device *pdev, u8 ed_number,
1597 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
1598 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
1599 int toggle_bits, int error_count, int condition_code, int repeat_number,
1600 int halted, int skipped, int actual, int non_null))
1601{
1602 struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
1603 return ftdi_elan_edset_setup(ftdi, ed_number, endp, urb, address,
1604 ep_number, toggle_bits, callback);
1605}
1606
1607
1608EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_setup);
1609static int ftdi_elan_edset_input(struct usb_ftdi *ftdi, u8 ed_number,
1610 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
1611 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
1612 int toggle_bits, int error_count, int condition_code, int repeat_number,
1613 int halted, int skipped, int actual, int non_null))
1614{
1615 u8 ed = ed_number - 1;
1616 wait:if (ftdi->disconnected > 0) {
1617 return -ENODEV;
1618 } else if (ftdi->initialized == 0) {
1619 return -ENODEV;
1620 } else {
1621 int command_size;
1622 down(&ftdi->u132_lock);
1623 command_size = ftdi->command_next - ftdi->command_head;
1624 if (command_size < COMMAND_SIZE) {
1625 struct u132_target *target = &ftdi->target[ed];
1626 struct u132_command *command = &ftdi->command[
1627 COMMAND_MASK & ftdi->command_next];
1628 int remaining_length = urb->transfer_buffer_length -
1629 urb->actual_length;
1630 command->header = 0x82 | (ed << 5);
1631 if (remaining_length == 0) {
1632 command->length = 0x0000;
1633 } else if (remaining_length > 1024) {
1634 command->length = 0x8000 | 1023;
1635 } else
1636 command->length = 0x8000 | (remaining_length -
1637 1);
1638 command->address = (toggle_bits << 6) | (ep_number << 2)
1639 | (address << 0);
1640 command->width = usb_maxpacket(urb->dev, urb->pipe,
1641 usb_pipeout(urb->pipe));
1642 command->follows = 0;
1643 command->value = 0;
1644 command->buffer = NULL;
1645 target->callback = callback;
1646 target->endp = endp;
1647 target->urb = urb;
1648 target->active = 1;
1649 ftdi->command_next += 1;
1650 ftdi_elan_kick_command_queue(ftdi);
1651 up(&ftdi->u132_lock);
1652 return 0;
1653 } else {
1654 up(&ftdi->u132_lock);
1655 msleep(100);
1656 goto wait;
1657 }
1658 }
1659}
1660
1661int usb_ftdi_elan_edset_input(struct platform_device *pdev, u8 ed_number,
1662 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
1663 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
1664 int toggle_bits, int error_count, int condition_code, int repeat_number,
1665 int halted, int skipped, int actual, int non_null))
1666{
1667 struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
1668 return ftdi_elan_edset_input(ftdi, ed_number, endp, urb, address,
1669 ep_number, toggle_bits, callback);
1670}
1671
1672
1673EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_input);
1674static int ftdi_elan_edset_empty(struct usb_ftdi *ftdi, u8 ed_number,
1675 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
1676 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
1677 int toggle_bits, int error_count, int condition_code, int repeat_number,
1678 int halted, int skipped, int actual, int non_null))
1679{
1680 u8 ed = ed_number - 1;
1681 wait:if (ftdi->disconnected > 0) {
1682 return -ENODEV;
1683 } else if (ftdi->initialized == 0) {
1684 return -ENODEV;
1685 } else {
1686 int command_size;
1687 down(&ftdi->u132_lock);
1688 command_size = ftdi->command_next - ftdi->command_head;
1689 if (command_size < COMMAND_SIZE) {
1690 struct u132_target *target = &ftdi->target[ed];
1691 struct u132_command *command = &ftdi->command[
1692 COMMAND_MASK & ftdi->command_next];
1693 command->header = 0x81 | (ed << 5);
1694 command->length = 0x0000;
1695 command->address = (toggle_bits << 6) | (ep_number << 2)
1696 | (address << 0);
1697 command->width = usb_maxpacket(urb->dev, urb->pipe,
1698 usb_pipeout(urb->pipe));
1699 command->follows = 0;
1700 command->value = 0;
1701 command->buffer = NULL;
1702 target->callback = callback;
1703 target->endp = endp;
1704 target->urb = urb;
1705 target->active = 1;
1706 ftdi->command_next += 1;
1707 ftdi_elan_kick_command_queue(ftdi);
1708 up(&ftdi->u132_lock);
1709 return 0;
1710 } else {
1711 up(&ftdi->u132_lock);
1712 msleep(100);
1713 goto wait;
1714 }
1715 }
1716}
1717
1718int usb_ftdi_elan_edset_empty(struct platform_device *pdev, u8 ed_number,
1719 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
1720 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
1721 int toggle_bits, int error_count, int condition_code, int repeat_number,
1722 int halted, int skipped, int actual, int non_null))
1723{
1724 struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
1725 return ftdi_elan_edset_empty(ftdi, ed_number, endp, urb, address,
1726 ep_number, toggle_bits, callback);
1727}
1728
1729
1730EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_empty);
1731static int ftdi_elan_edset_output(struct usb_ftdi *ftdi, u8 ed_number,
1732 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
1733 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
1734 int toggle_bits, int error_count, int condition_code, int repeat_number,
1735 int halted, int skipped, int actual, int non_null))
1736{
1737 u8 ed = ed_number - 1;
1738 wait:if (ftdi->disconnected > 0) {
1739 return -ENODEV;
1740 } else if (ftdi->initialized == 0) {
1741 return -ENODEV;
1742 } else {
1743 int command_size;
1744 down(&ftdi->u132_lock);
1745 command_size = ftdi->command_next - ftdi->command_head;
1746 if (command_size < COMMAND_SIZE) {
1747 u8 *b;
1748 u16 urb_size;
1749 int i = 0;
1750 char data[30 *3 + 4];
1751 char *d = data;
1752 int m = (sizeof(data) - 1) / 3;
1753 int l = 0;
1754 struct u132_target *target = &ftdi->target[ed];
1755 struct u132_command *command = &ftdi->command[
1756 COMMAND_MASK & ftdi->command_next];
1757 command->header = 0x81 | (ed << 5);
1758 command->address = (toggle_bits << 6) | (ep_number << 2)
1759 | (address << 0);
1760 command->width = usb_maxpacket(urb->dev, urb->pipe,
1761 usb_pipeout(urb->pipe));
1762 command->follows = min(1024,
1763 urb->transfer_buffer_length -
1764 urb->actual_length);
1765 command->value = 0;
1766 command->buffer = urb->transfer_buffer +
1767 urb->actual_length;
1768 command->length = 0x8000 | (command->follows - 1);
1769 b = command->buffer;
1770 urb_size = command->follows;
1771 data[0] = 0;
1772 while (urb_size-- > 0) {
1773 if (i > m) {
1774 } else if (i++ < m) {
1775 int w = sprintf(d, " %02X", *b++);
1776 d += w;
1777 l += w;
1778 } else
1779 d += sprintf(d, " ..");
1780 }
1781 target->callback = callback;
1782 target->endp = endp;
1783 target->urb = urb;
1784 target->active = 1;
1785 ftdi->command_next += 1;
1786 ftdi_elan_kick_command_queue(ftdi);
1787 up(&ftdi->u132_lock);
1788 return 0;
1789 } else {
1790 up(&ftdi->u132_lock);
1791 msleep(100);
1792 goto wait;
1793 }
1794 }
1795}
1796
1797int usb_ftdi_elan_edset_output(struct platform_device *pdev, u8 ed_number,
1798 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
1799 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
1800 int toggle_bits, int error_count, int condition_code, int repeat_number,
1801 int halted, int skipped, int actual, int non_null))
1802{
1803 struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
1804 return ftdi_elan_edset_output(ftdi, ed_number, endp, urb, address,
1805 ep_number, toggle_bits, callback);
1806}
1807
1808
1809EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_output);
1810static int ftdi_elan_edset_single(struct usb_ftdi *ftdi, u8 ed_number,
1811 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
1812 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
1813 int toggle_bits, int error_count, int condition_code, int repeat_number,
1814 int halted, int skipped, int actual, int non_null))
1815{
1816 u8 ed = ed_number - 1;
1817 wait:if (ftdi->disconnected > 0) {
1818 return -ENODEV;
1819 } else if (ftdi->initialized == 0) {
1820 return -ENODEV;
1821 } else {
1822 int command_size;
1823 down(&ftdi->u132_lock);
1824 command_size = ftdi->command_next - ftdi->command_head;
1825 if (command_size < COMMAND_SIZE) {
1826 int remaining_length = urb->transfer_buffer_length -
1827 urb->actual_length;
1828 struct u132_target *target = &ftdi->target[ed];
1829 struct u132_command *command = &ftdi->command[
1830 COMMAND_MASK & ftdi->command_next];
1831 command->header = 0x83 | (ed << 5);
1832 if (remaining_length == 0) {
1833 command->length = 0x0000;
1834 } else if (remaining_length > 1024) {
1835 command->length = 0x8000 | 1023;
1836 } else
1837 command->length = 0x8000 | (remaining_length -
1838 1);
1839 command->address = (toggle_bits << 6) | (ep_number << 2)
1840 | (address << 0);
1841 command->width = usb_maxpacket(urb->dev, urb->pipe,
1842 usb_pipeout(urb->pipe));
1843 command->follows = 0;
1844 command->value = 0;
1845 command->buffer = NULL;
1846 target->callback = callback;
1847 target->endp = endp;
1848 target->urb = urb;
1849 target->active = 1;
1850 ftdi->command_next += 1;
1851 ftdi_elan_kick_command_queue(ftdi);
1852 up(&ftdi->u132_lock);
1853 return 0;
1854 } else {
1855 up(&ftdi->u132_lock);
1856 msleep(100);
1857 goto wait;
1858 }
1859 }
1860}
1861
1862int usb_ftdi_elan_edset_single(struct platform_device *pdev, u8 ed_number,
1863 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
1864 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
1865 int toggle_bits, int error_count, int condition_code, int repeat_number,
1866 int halted, int skipped, int actual, int non_null))
1867{
1868 struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
1869 return ftdi_elan_edset_single(ftdi, ed_number, endp, urb, address,
1870 ep_number, toggle_bits, callback);
1871}
1872
1873
1874EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_single);
1875static int ftdi_elan_edset_flush(struct usb_ftdi *ftdi, u8 ed_number,
1876 void *endp)
1877{
1878 u8 ed = ed_number - 1;
1879 if (ftdi->disconnected > 0) {
1880 return -ENODEV;
1881 } else if (ftdi->initialized == 0) {
1882 return -ENODEV;
1883 } else {
1884 struct u132_target *target = &ftdi->target[ed];
1885 down(&ftdi->u132_lock);
1886 if (target->abandoning > 0) {
1887 up(&ftdi->u132_lock);
1888 return 0;
1889 } else {
1890 target->abandoning = 1;
1891 wait_1:if (target->active == 1) {
1892 int command_size = ftdi->command_next -
1893 ftdi->command_head;
1894 if (command_size < COMMAND_SIZE) {
1895 struct u132_command *command =
1896 &ftdi->command[COMMAND_MASK &
1897 ftdi->command_next];
1898 command->header = 0x80 | (ed << 5) |
1899 0x4;
1900 command->length = 0x00;
1901 command->address = 0x00;
1902 command->width = 0x00;
1903 command->follows = 0;
1904 command->value = 0;
1905 command->buffer = &command->value;
1906 ftdi->command_next += 1;
1907 ftdi_elan_kick_command_queue(ftdi);
1908 } else {
1909 up(&ftdi->u132_lock);
1910 msleep(100);
1911 down(&ftdi->u132_lock);
1912 goto wait_1;
1913 }
1914 }
1915 up(&ftdi->u132_lock);
1916 return 0;
1917 }
1918 }
1919}
1920
1921int usb_ftdi_elan_edset_flush(struct platform_device *pdev, u8 ed_number,
1922 void *endp)
1923{
1924 struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
1925 return ftdi_elan_edset_flush(ftdi, ed_number, endp);
1926}
1927
1928
1929EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_flush);
1930static int ftdi_elan_flush_input_fifo(struct usb_ftdi *ftdi)
1931{
1932 int retry_on_empty = 10;
1933 int retry_on_timeout = 5;
1934 int retry_on_status = 20;
1935 more:{
1936 int packet_bytes = 0;
1937 int retval = usb_bulk_msg(ftdi->udev,
1938 usb_rcvbulkpipe(ftdi->udev, ftdi->bulk_in_endpointAddr),
1939 ftdi->bulk_in_buffer, ftdi->bulk_in_size,
1940 &packet_bytes, msecs_to_jiffies(100));
1941 if (packet_bytes > 2) {
1942 char diag[30 *3 + 4];
1943 char *d = diag;
1944 int m = (sizeof(diag) - 1) / 3;
1945 char *b = ftdi->bulk_in_buffer;
1946 int bytes_read = 0;
1947 diag[0] = 0;
1948 while (packet_bytes-- > 0) {
1949 char c = *b++;
1950 if (bytes_read < m) {
1951 d += sprintf(d, " %02X",
1952 0x000000FF & c);
1953 } else if (bytes_read > m) {
1954 } else
1955 d += sprintf(d, " ..");
1956 bytes_read += 1;
1957 continue;
1958 }
1959 goto more;
1960 } else if (packet_bytes > 1) {
1961 char s1 = ftdi->bulk_in_buffer[0];
1962 char s2 = ftdi->bulk_in_buffer[1];
1963 if (s1 == 0x31 && s2 == 0x60) {
1964 return 0;
1965 } else if (retry_on_status-- > 0) {
1966 goto more;
1967 } else {
1968 dev_err(&ftdi->udev->dev, "STATUS ERROR retry l"
1969 "imit reached\n");
1970 return -EFAULT;
1971 }
1972 } else if (packet_bytes > 0) {
1973 char b1 = ftdi->bulk_in_buffer[0];
1974 dev_err(&ftdi->udev->dev, "only one byte flushed from F"
1975 "TDI = %02X\n", b1);
1976 if (retry_on_status-- > 0) {
1977 goto more;
1978 } else {
1979 dev_err(&ftdi->udev->dev, "STATUS ERROR retry l"
1980 "imit reached\n");
1981 return -EFAULT;
1982 }
1983 } else if (retval == -ETIMEDOUT) {
1984 if (retry_on_timeout-- > 0) {
1985 goto more;
1986 } else {
1987 dev_err(&ftdi->udev->dev, "TIMED OUT retry limi"
1988 "t reached\n");
1989 return -ENOMEM;
1990 }
1991 } else if (retval == 0) {
1992 if (retry_on_empty-- > 0) {
1993 goto more;
1994 } else {
1995 dev_err(&ftdi->udev->dev, "empty packet retry l"
1996 "imit reached\n");
1997 return -ENOMEM;
1998 }
1999 } else {
2000 dev_err(&ftdi->udev->dev, "error = %d\n", retval);
2001 return retval;
2002 }
2003 }
2004 return -1;
2005}
2006
2007
2008/*
2009* send the long flush sequence
2010*
2011*/
2012static int ftdi_elan_synchronize_flush(struct usb_ftdi *ftdi)
2013{
2014 int retval;
2015 struct urb *urb;
2016 char *buf;
2017 int I = 257;
2018 int i = 0;
2019 urb = usb_alloc_urb(0, GFP_KERNEL);
2020 if (!urb) {
2021 dev_err(&ftdi->udev->dev, "could not alloc a urb for flush sequ"
2022 "ence\n");
2023 return -ENOMEM;
2024 }
2025 buf = usb_buffer_alloc(ftdi->udev, I, GFP_KERNEL, &urb->transfer_dma);
2026 if (!buf) {
2027 dev_err(&ftdi->udev->dev, "could not get a buffer for flush seq"
2028 "uence\n");
2029 usb_free_urb(urb);
2030 return -ENOMEM;
2031 }
2032 while (I-- > 0)
2033 buf[i++] = 0x55;
2034 usb_fill_bulk_urb(urb, ftdi->udev, usb_sndbulkpipe(ftdi->udev,
2035 ftdi->bulk_out_endpointAddr), buf, i,
2036 ftdi_elan_write_bulk_callback, ftdi);
2037 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
2038 retval = usb_submit_urb(urb, GFP_KERNEL);
2039 if (retval) {
2040 dev_err(&ftdi->udev->dev, "failed to submit urb containing the "
2041 "flush sequence\n");
2042 usb_buffer_free(ftdi->udev, i, buf, urb->transfer_dma);
2043 usb_free_urb(urb);
2044 return -ENOMEM;
2045 }
2046 usb_free_urb(urb);
2047 return 0;
2048}
2049
2050
2051/*
2052* send the reset sequence
2053*
2054*/
2055static int ftdi_elan_synchronize_reset(struct usb_ftdi *ftdi)
2056{
2057 int retval;
2058 struct urb *urb;
2059 char *buf;
2060 int I = 4;
2061 int i = 0;
2062 urb = usb_alloc_urb(0, GFP_KERNEL);
2063 if (!urb) {
2064 dev_err(&ftdi->udev->dev, "could not get a urb for the reset se"
2065 "quence\n");
2066 return -ENOMEM;
2067 }
2068 buf = usb_buffer_alloc(ftdi->udev, I, GFP_KERNEL, &urb->transfer_dma);
2069 if (!buf) {
2070 dev_err(&ftdi->udev->dev, "could not get a buffer for the reset"
2071 " sequence\n");
2072 usb_free_urb(urb);
2073 return -ENOMEM;
2074 }
2075 buf[i++] = 0x55;
2076 buf[i++] = 0xAA;
2077 buf[i++] = 0x5A;
2078 buf[i++] = 0xA5;
2079 usb_fill_bulk_urb(urb, ftdi->udev, usb_sndbulkpipe(ftdi->udev,
2080 ftdi->bulk_out_endpointAddr), buf, i,
2081 ftdi_elan_write_bulk_callback, ftdi);
2082 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
2083 retval = usb_submit_urb(urb, GFP_KERNEL);
2084 if (retval) {
2085 dev_err(&ftdi->udev->dev, "failed to submit urb containing the "
2086 "reset sequence\n");
2087 usb_buffer_free(ftdi->udev, i, buf, urb->transfer_dma);
2088 usb_free_urb(urb);
2089 return -ENOMEM;
2090 }
2091 usb_free_urb(urb);
2092 return 0;
2093}
2094
2095static int ftdi_elan_synchronize(struct usb_ftdi *ftdi)
2096{
2097 int retval;
2098 int long_stop = 10;
2099 int retry_on_timeout = 5;
2100 int retry_on_empty = 10;
2101 int err_count = 0;
2102 retval = ftdi_elan_flush_input_fifo(ftdi);
2103 if (retval)
2104 return retval;
2105 ftdi->bulk_in_left = 0;
2106 ftdi->bulk_in_last = -1;
2107 while (long_stop-- > 0) {
2108 int read_stop;
2109 int read_stuck;
2110 retval = ftdi_elan_synchronize_flush(ftdi);
2111 if (retval)
2112 return retval;
2113 retval = ftdi_elan_flush_input_fifo(ftdi);
2114 if (retval)
2115 return retval;
2116 reset:retval = ftdi_elan_synchronize_reset(ftdi);
2117 if (retval)
2118 return retval;
2119 read_stop = 100;
2120 read_stuck = 10;
2121 read:{
2122 int packet_bytes = 0;
2123 retval = usb_bulk_msg(ftdi->udev,
2124 usb_rcvbulkpipe(ftdi->udev,
2125 ftdi->bulk_in_endpointAddr),
2126 ftdi->bulk_in_buffer, ftdi->bulk_in_size,
2127 &packet_bytes, msecs_to_jiffies(500));
2128 if (packet_bytes > 2) {
2129 char diag[30 *3 + 4];
2130 char *d = diag;
2131 int m = (sizeof(diag) - 1) / 3;
2132 char *b = ftdi->bulk_in_buffer;
2133 int bytes_read = 0;
2134 unsigned char c = 0;
2135 diag[0] = 0;
2136 while (packet_bytes-- > 0) {
2137 c = *b++;
2138 if (bytes_read < m) {
2139 d += sprintf(d, " %02X", c);
2140 } else if (bytes_read > m) {
2141 } else
2142 d += sprintf(d, " ..");
2143 bytes_read += 1;
2144 continue;
2145 }
2146 if (c == 0x7E) {
2147 return 0;
2148 } else {
2149 if (c == 0x55) {
2150 goto read;
2151 } else if (read_stop-- > 0) {
2152 goto read;
2153 } else {
2154 dev_err(&ftdi->udev->dev, "retr"
2155 "y limit reached\n");
2156 continue;
2157 }
2158 }
2159 } else if (packet_bytes > 1) {
2160 unsigned char s1 = ftdi->bulk_in_buffer[0];
2161 unsigned char s2 = ftdi->bulk_in_buffer[1];
2162 if (s1 == 0x31 && s2 == 0x00) {
2163 if (read_stuck-- > 0) {
2164 goto read;
2165 } else
2166 goto reset;
2167 } else if (s1 == 0x31 && s2 == 0x60) {
2168 if (read_stop-- > 0) {
2169 goto read;
2170 } else {
2171 dev_err(&ftdi->udev->dev, "retr"
2172 "y limit reached\n");
2173 continue;
2174 }
2175 } else {
2176 if (read_stop-- > 0) {
2177 goto read;
2178 } else {
2179 dev_err(&ftdi->udev->dev, "retr"
2180 "y limit reached\n");
2181 continue;
2182 }
2183 }
2184 } else if (packet_bytes > 0) {
2185 if (read_stop-- > 0) {
2186 goto read;
2187 } else {
2188 dev_err(&ftdi->udev->dev, "retry limit "
2189 "reached\n");
2190 continue;
2191 }
2192 } else if (retval == -ETIMEDOUT) {
2193 if (retry_on_timeout-- > 0) {
2194 goto read;
2195 } else {
2196 dev_err(&ftdi->udev->dev, "TIMED OUT re"
2197 "try limit reached\n");
2198 continue;
2199 }
2200 } else if (retval == 0) {
2201 if (retry_on_empty-- > 0) {
2202 goto read;
2203 } else {
2204 dev_err(&ftdi->udev->dev, "empty packet"
2205 " retry limit reached\n");
2206 continue;
2207 }
2208 } else {
2209 err_count += 1;
2210 dev_err(&ftdi->udev->dev, "error = %d\n",
2211 retval);
2212 if (read_stop-- > 0) {
2213 goto read;
2214 } else {
2215 dev_err(&ftdi->udev->dev, "retry limit "
2216 "reached\n");
2217 continue;
2218 }
2219 }
2220 }
2221 }
2222 dev_err(&ftdi->udev->dev, "failed to synchronize\n");
2223 return -EFAULT;
2224}
2225
2226static int ftdi_elan_stuck_waiting(struct usb_ftdi *ftdi)
2227{
2228 int retry_on_empty = 10;
2229 int retry_on_timeout = 5;
2230 int retry_on_status = 50;
2231 more:{
2232 int packet_bytes = 0;
2233 int retval = usb_bulk_msg(ftdi->udev,
2234 usb_rcvbulkpipe(ftdi->udev, ftdi->bulk_in_endpointAddr),
2235 ftdi->bulk_in_buffer, ftdi->bulk_in_size,
2236 &packet_bytes, msecs_to_jiffies(1000));
2237 if (packet_bytes > 2) {
2238 char diag[30 *3 + 4];
2239 char *d = diag;
2240 int m = (sizeof(diag) - 1) / 3;
2241 char *b = ftdi->bulk_in_buffer;
2242 int bytes_read = 0;
2243 diag[0] = 0;
2244 while (packet_bytes-- > 0) {
2245 char c = *b++;
2246 if (bytes_read < m) {
2247 d += sprintf(d, " %02X",
2248 0x000000FF & c);
2249 } else if (bytes_read > m) {
2250 } else
2251 d += sprintf(d, " ..");
2252 bytes_read += 1;
2253 continue;
2254 }
2255 goto more;
2256 } else if (packet_bytes > 1) {
2257 char s1 = ftdi->bulk_in_buffer[0];
2258 char s2 = ftdi->bulk_in_buffer[1];
2259 if (s1 == 0x31 && s2 == 0x60) {
2260 return 0;
2261 } else if (retry_on_status-- > 0) {
2262 msleep(5);
2263 goto more;
2264 } else
2265 return -EFAULT;
2266 } else if (packet_bytes > 0) {
2267 char b1 = ftdi->bulk_in_buffer[0];
2268 dev_err(&ftdi->udev->dev, "only one byte flushed from F"
2269 "TDI = %02X\n", b1);
2270 if (retry_on_status-- > 0) {
2271 msleep(5);
2272 goto more;
2273 } else {
2274 dev_err(&ftdi->udev->dev, "STATUS ERROR retry l"
2275 "imit reached\n");
2276 return -EFAULT;
2277 }
2278 } else if (retval == -ETIMEDOUT) {
2279 if (retry_on_timeout-- > 0) {
2280 goto more;
2281 } else {
2282 dev_err(&ftdi->udev->dev, "TIMED OUT retry limi"
2283 "t reached\n");
2284 return -ENOMEM;
2285 }
2286 } else if (retval == 0) {
2287 if (retry_on_empty-- > 0) {
2288 goto more;
2289 } else {
2290 dev_err(&ftdi->udev->dev, "empty packet retry l"
2291 "imit reached\n");
2292 return -ENOMEM;
2293 }
2294 } else {
2295 dev_err(&ftdi->udev->dev, "error = %d\n", retval);
2296 return -ENOMEM;
2297 }
2298 }
2299 return -1;
2300}
2301
2302static int ftdi_elan_checkingPCI(struct usb_ftdi *ftdi)
2303{
2304 int UxxxStatus = ftdi_elan_read_reg(ftdi, &ftdi->controlreg);
2305 if (UxxxStatus)
2306 return UxxxStatus;
2307 if (ftdi->controlreg & 0x00400000) {
2308 if (ftdi->card_ejected) {
2309 } else {
2310 ftdi->card_ejected = 1;
2311 dev_err(&ftdi->udev->dev, "CARD EJECTED - controlreg = "
2312 "%08X\n", ftdi->controlreg);
2313 }
2314 return -ENODEV;
2315 } else {
2316 u8 fn = ftdi->function - 1;
2317 int activePCIfn = fn << 8;
2318 u32 pcidata;
2319 u32 pciVID;
2320 u32 pciPID;
2321 int reg = 0;
2322 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2323 &pcidata);
2324 if (UxxxStatus)
2325 return UxxxStatus;
2326 pciVID = pcidata & 0xFFFF;
2327 pciPID = (pcidata >> 16) & 0xFFFF;
2328 if (pciVID == ftdi->platform_data.vendor && pciPID ==
2329 ftdi->platform_data.device) {
2330 return 0;
2331 } else {
2332 dev_err(&ftdi->udev->dev, "vendor=%04X pciVID=%04X devi"
2333 "ce=%04X pciPID=%04X\n",
2334 ftdi->platform_data.vendor, pciVID,
2335 ftdi->platform_data.device, pciPID);
2336 return -ENODEV;
2337 }
2338 }
2339}
2340
2341static int ftdi_elan_enumeratePCI(struct usb_ftdi *ftdi)
2342{
2343 u32 latence_timer;
2344 u32 controlreg;
2345 int UxxxStatus;
2346 u32 pcidata;
2347 int reg = 0;
2348 int foundOHCI = 0;
2349 u8 fn;
2350 int activePCIfn = 0;
2351 u32 pciVID = 0;
2352 u32 pciPID = 0;
2353 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
2354 if (UxxxStatus)
2355 return UxxxStatus;
2356 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000000L);
2357 if (UxxxStatus)
2358 return UxxxStatus;
2359 msleep(750);
2360 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000200L | 0x100);
2361 if (UxxxStatus)
2362 return UxxxStatus;
2363 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000200L | 0x500);
2364 if (UxxxStatus)
2365 return UxxxStatus;
2366 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
2367 if (UxxxStatus)
2368 return UxxxStatus;
2369 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020CL | 0x000);
2370 if (UxxxStatus)
2371 return UxxxStatus;
2372 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020DL | 0x000);
2373 if (UxxxStatus)
2374 return UxxxStatus;
2375 msleep(250);
2376 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020FL | 0x000);
2377 if (UxxxStatus)
2378 return UxxxStatus;
2379 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
2380 if (UxxxStatus)
2381 return UxxxStatus;
2382 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x800);
2383 if (UxxxStatus)
2384 return UxxxStatus;
2385 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
2386 if (UxxxStatus)
2387 return UxxxStatus;
2388 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
2389 if (UxxxStatus)
2390 return UxxxStatus;
2391 msleep(1000);
2392 for (fn = 0; (fn < 4) && (!foundOHCI); fn++) {
2393 activePCIfn = fn << 8;
2394 ftdi->function = fn + 1;
2395 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2396 &pcidata);
2397 if (UxxxStatus)
2398 return UxxxStatus;
2399 pciVID = pcidata & 0xFFFF;
2400 pciPID = (pcidata >> 16) & 0xFFFF;
2401 if ((pciVID == 0x1045) && (pciPID == 0xc861)) {
2402 foundOHCI = 1;
2403 } else if ((pciVID == 0x1033) && (pciPID == 0x0035)) {
2404 foundOHCI = 1;
2405 } else if ((pciVID == 0x10b9) && (pciPID == 0x5237)) {
2406 foundOHCI = 1;
2407 } else if ((pciVID == 0x11c1) && (pciPID == 0x5802)) {
2408 foundOHCI = 1;
2409 } else if ((pciVID == 0x11AB) && (pciPID == 0x1FA6)) {
2410 }
2411 }
2412 if (foundOHCI == 0) {
2413 return -ENXIO;
2414 }
2415 ftdi->platform_data.vendor = pciVID;
2416 ftdi->platform_data.device = pciPID;
2417 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x2800);
2418 if (UxxxStatus)
2419 return UxxxStatus;
2420 reg = 16;
2421 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0,
2422 0xFFFFFFFF);
2423 if (UxxxStatus)
2424 return UxxxStatus;
2425 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2426 &pcidata);
2427 if (UxxxStatus)
2428 return UxxxStatus;
2429 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0,
2430 0xF0000000);
2431 if (UxxxStatus)
2432 return UxxxStatus;
2433 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2434 &pcidata);
2435 if (UxxxStatus)
2436 return UxxxStatus;
2437 reg = 12;
2438 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2439 &latence_timer);
2440 if (UxxxStatus)
2441 return UxxxStatus;
2442 latence_timer &= 0xFFFF00FF;
2443 latence_timer |= 0x00001600;
2444 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00,
2445 latence_timer);
2446 if (UxxxStatus)
2447 return UxxxStatus;
2448 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2449 &pcidata);
2450 if (UxxxStatus)
2451 return UxxxStatus;
2452 reg = 4;
2453 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00,
2454 0x06);
2455 if (UxxxStatus)
2456 return UxxxStatus;
2457 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2458 &pcidata);
2459 if (UxxxStatus)
2460 return UxxxStatus;
2461 return 0;
2462}
2463
2464static int ftdi_elan_setupOHCI(struct usb_ftdi *ftdi)
2465{
2466 u32 pcidata;
2467 int U132Status;
2468 int reg;
2469 int reset_repeat = 0;
2470 do_reset:reg = 8;
2471 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x0e, 0x01);
2472 if (U132Status)
2473 return U132Status;
2474 reset_check:{
2475 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2476 if (U132Status)
2477 return U132Status;
2478 if (pcidata & 1) {
2479 msleep(500);
2480 if (reset_repeat++ > 100) {
2481 reset_repeat = 0;
2482 goto do_reset;
2483 } else
2484 goto reset_check;
2485 }
2486 }
2487 goto dump_regs;
2488 msleep(500);
2489 reg = 0x28;
2490 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x11000000);
2491 if (U132Status)
2492 return U132Status;
2493 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2494 if (U132Status)
2495 return U132Status;
2496 reg = 0x40;
2497 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x2edf);
2498 if (U132Status)
2499 return U132Status;
2500 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2501 if (U132Status)
2502 return U132Status;
2503 reg = 0x34;
2504 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x2edf2edf);
2505 if (U132Status)
2506 return U132Status;
2507 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2508 if (U132Status)
2509 return U132Status;
2510 reg = 4;
2511 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0xA0);
2512 if (U132Status)
2513 return U132Status;
2514 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2515 if (U132Status)
2516 return U132Status;
2517 msleep(250);
2518 reg = 8;
2519 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x0e, 0x04);
2520 if (U132Status)
2521 return U132Status;
2522 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2523 if (U132Status)
2524 return U132Status;
2525 reg = 0x28;
2526 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2527 if (U132Status)
2528 return U132Status;
2529 reg = 8;
2530 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2531 if (U132Status)
2532 return U132Status;
2533 reg = 0x48;
2534 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x00001200);
2535 if (U132Status)
2536 return U132Status;
2537 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2538 if (U132Status)
2539 return U132Status;
2540 reg = 0x54;
2541 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2542 if (U132Status)
2543 return U132Status;
2544 reg = 0x58;
2545 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2546 if (U132Status)
2547 return U132Status;
2548 reg = 0x34;
2549 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x28002edf);
2550 if (U132Status)
2551 return U132Status;
2552 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2553 if (U132Status)
2554 return U132Status;
2555 msleep(100);
2556 reg = 0x50;
2557 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x10000);
2558 if (U132Status)
2559 return U132Status;
2560 reg = 0x54;
2561 power_check:U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2562 if (U132Status)
2563 return U132Status;
2564 if (!(pcidata & 1)) {
2565 msleep(500);
2566 goto power_check;
2567 }
2568 msleep(3000);
2569 reg = 0x54;
2570 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2571 if (U132Status)
2572 return U132Status;
2573 reg = 0x58;
2574 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2575 if (U132Status)
2576 return U132Status;
2577 reg = 0x54;
2578 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x02);
2579 if (U132Status)
2580 return U132Status;
2581 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2582 if (U132Status)
2583 return U132Status;
2584 reg = 0x54;
2585 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x10);
2586 if (U132Status)
2587 return U132Status;
2588 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2589 if (U132Status)
2590 return U132Status;
2591 msleep(750);
2592 reg = 0x54;
2593 if (0) {
2594 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x02);
2595 if (U132Status)
2596 return U132Status;
2597 }
2598 if (0) {
2599 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2600 if (U132Status)
2601 return U132Status;
2602 }
2603 reg = 0x54;
2604 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2605 if (U132Status)
2606 return U132Status;
2607 reg = 0x58;
2608 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2609 if (U132Status)
2610 return U132Status;
2611 dump_regs:for (reg = 0; reg <= 0x54; reg += 4) {
2612 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2613 if (U132Status)
2614 return U132Status;
2615 }
2616 return 0;
2617}
2618
2619
2620/*
2621* we use only the first bulk-in and bulk-out endpoints
2622*/
2623static int ftdi_elan_probe(struct usb_interface *interface,
2624 const struct usb_device_id *id)
2625{
2626 struct usb_host_interface *iface_desc;
2627 struct usb_endpoint_descriptor *endpoint;
2628 size_t buffer_size;
2629 int i;
2630 int retval = -ENOMEM;
2631 struct usb_ftdi *ftdi = kmalloc(sizeof(struct usb_ftdi), GFP_KERNEL);
2632 if (ftdi == NULL) {
2633 printk(KERN_ERR "Out of memory\n");
2634 return -ENOMEM;
2635 }
2636 memset(ftdi, 0x00, sizeof(struct usb_ftdi));
2637 down(&ftdi_module_lock);
2638 list_add_tail(&ftdi->ftdi_list, &ftdi_static_list);
2639 ftdi->sequence_num = ++ftdi_instances;
2640 up(&ftdi_module_lock);
2641 ftdi_elan_init_kref(ftdi);
2642 init_MUTEX(&ftdi->sw_lock);
2643 ftdi->udev = usb_get_dev(interface_to_usbdev(interface));
2644 ftdi->interface = interface;
2645 init_MUTEX(&ftdi->u132_lock);
2646 ftdi->expected = 4;
2647 iface_desc = interface->cur_altsetting;
2648 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
2649 endpoint = &iface_desc->endpoint[i].desc;
2650 if (!ftdi->bulk_in_endpointAddr &&
2651 ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
2652 == USB_DIR_IN) && ((endpoint->bmAttributes &
2653 USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK))
2654 {
2655 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
2656 ftdi->bulk_in_size = buffer_size;
2657 ftdi->bulk_in_endpointAddr = endpoint->bEndpointAddress;
2658 ftdi->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
2659 if (!ftdi->bulk_in_buffer) {
2660 dev_err(&ftdi->udev->dev, "Could not allocate b"
2661 "ulk_in_buffer\n");
2662 retval = -ENOMEM;
2663 goto error;
2664 }
2665 }
2666 if (!ftdi->bulk_out_endpointAddr &&
2667 ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
2668 == USB_DIR_OUT) && ((endpoint->bmAttributes &
2669 USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK))
2670 {
2671 ftdi->bulk_out_endpointAddr =
2672 endpoint->bEndpointAddress;
2673 }
2674 }
2675 if (!(ftdi->bulk_in_endpointAddr && ftdi->bulk_out_endpointAddr)) {
2676 dev_err(&ftdi->udev->dev, "Could not find both bulk-in and bulk"
2677 "-out endpoints\n");
2678 retval = -ENODEV;
2679 goto error;
2680 }
2681 dev_info(&ftdi->udev->dev, "interface %d has I=%02X O=%02X\n",
2682 iface_desc->desc.bInterfaceNumber, ftdi->bulk_in_endpointAddr,
2683 ftdi->bulk_out_endpointAddr);
2684 usb_set_intfdata(interface, ftdi);
2685 if (iface_desc->desc.bInterfaceNumber == 0 &&
2686 ftdi->bulk_in_endpointAddr == 0x81 &&
2687 ftdi->bulk_out_endpointAddr == 0x02) {
2688 retval = usb_register_dev(interface, &ftdi_elan_jtag_class);
2689 if (retval) {
2690 dev_err(&ftdi->udev->dev, "Not able to get a minor for "
2691 "this device.\n");
2692 usb_set_intfdata(interface, NULL);
2693 retval = -ENOMEM;
2694 goto error;
2695 } else {
2696 ftdi->class = &ftdi_elan_jtag_class;
2697 dev_info(&ftdi->udev->dev, "USB FDTI=%p JTAG interface "
2698 "%d now attached to ftdi%d\n", ftdi,
2699 iface_desc->desc.bInterfaceNumber,
2700 interface->minor);
2701 return 0;
2702 }
2703 } else if (iface_desc->desc.bInterfaceNumber == 1 &&
2704 ftdi->bulk_in_endpointAddr == 0x83 &&
2705 ftdi->bulk_out_endpointAddr == 0x04) {
2706 ftdi->class = NULL;
2707 dev_info(&ftdi->udev->dev, "USB FDTI=%p ELAN interface %d now a"
2708 "ctivated\n", ftdi, iface_desc->desc.bInterfaceNumber);
2709 INIT_WORK(&ftdi->status_work, ftdi_elan_status_work,
2710 (void *)ftdi);
2711 INIT_WORK(&ftdi->command_work, ftdi_elan_command_work,
2712 (void *)ftdi);
2713 INIT_WORK(&ftdi->respond_work, ftdi_elan_respond_work,
2714 (void *)ftdi);
2715 ftdi_status_queue_work(ftdi, msecs_to_jiffies(3 *1000));
2716 return 0;
2717 } else {
2718 dev_err(&ftdi->udev->dev,
2719 "Could not find ELAN's U132 device\n");
2720 retval = -ENODEV;
2721 goto error;
2722 }
2723 error:if (ftdi) {
2724 ftdi_elan_put_kref(ftdi);
2725 }
2726 return retval;
2727}
2728
2729static void ftdi_elan_disconnect(struct usb_interface *interface)
2730{
2731 struct usb_ftdi *ftdi = usb_get_intfdata(interface);
2732 ftdi->disconnected += 1;
2733 if (ftdi->class) {
2734 int minor = interface->minor;
2735 struct usb_class_driver *class = ftdi->class;
2736 usb_set_intfdata(interface, NULL);
2737 usb_deregister_dev(interface, class);
2738 dev_info(&ftdi->udev->dev, "USB FTDI U132 jtag interface on min"
2739 "or %d now disconnected\n", minor);
2740 } else {
2741 ftdi_status_cancel_work(ftdi);
2742 ftdi_command_cancel_work(ftdi);
2743 ftdi_response_cancel_work(ftdi);
2744 ftdi_elan_abandon_completions(ftdi);
2745 ftdi_elan_abandon_targets(ftdi);
2746 if (ftdi->registered) {
2747 platform_device_unregister(&ftdi->platform_dev);
2748 ftdi->synchronized = 0;
2749 ftdi->enumerated = 0;
2750 ftdi->registered = 0;
2751 }
2752 flush_workqueue(status_queue);
2753 flush_workqueue(command_queue);
2754 flush_workqueue(respond_queue);
2755 ftdi->disconnected += 1;
2756 usb_set_intfdata(interface, NULL);
2757 dev_info(&ftdi->udev->dev, "USB FTDI U132 host controller inter"
2758 "face now disconnected\n");
2759 }
2760 ftdi_elan_put_kref(ftdi);
2761}
2762
2763static struct usb_driver ftdi_elan_driver = {
2764 .name = "ftdi-elan",
2765 .probe = ftdi_elan_probe,
2766 .disconnect = ftdi_elan_disconnect,
2767 .id_table = ftdi_elan_table,
2768};
2769static int __init ftdi_elan_init(void)
2770{
2771 int result;
2772 printk(KERN_INFO "driver %s built at %s on %s\n", ftdi_elan_driver.name,
2773 __TIME__, __DATE__);
2774 init_MUTEX(&ftdi_module_lock);
2775 INIT_LIST_HEAD(&ftdi_static_list);
2776 status_queue = create_singlethread_workqueue("ftdi-status-control");
2777 command_queue = create_singlethread_workqueue("ftdi-command-engine");
2778 respond_queue = create_singlethread_workqueue("ftdi-respond-engine");
2779 result = usb_register(&ftdi_elan_driver);
2780 if (result)
2781 printk(KERN_ERR "usb_register failed. Error number %d\n",
2782 result);
2783 return result;
2784}
2785
2786static void __exit ftdi_elan_exit(void)
2787{
2788 struct usb_ftdi *ftdi;
2789 struct usb_ftdi *temp;
2790 usb_deregister(&ftdi_elan_driver);
2791 printk(KERN_INFO "ftdi_u132 driver deregistered\n");
2792 list_for_each_entry_safe(ftdi, temp, &ftdi_static_list, ftdi_list) {
2793 ftdi_status_cancel_work(ftdi);
2794 ftdi_command_cancel_work(ftdi);
2795 ftdi_response_cancel_work(ftdi);
2796 } flush_workqueue(status_queue);
2797 destroy_workqueue(status_queue);
2798 status_queue = NULL;
2799 flush_workqueue(command_queue);
2800 destroy_workqueue(command_queue);
2801 command_queue = NULL;
2802 flush_workqueue(respond_queue);
2803 destroy_workqueue(respond_queue);
2804 respond_queue = NULL;
2805}
2806
2807
2808module_init(ftdi_elan_init);
2809module_exit(ftdi_elan_exit);
diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c
index fcd69c52aea9..8e6e195a22ba 100644
--- a/drivers/usb/misc/idmouse.c
+++ b/drivers/usb/misc/idmouse.c
@@ -98,7 +98,7 @@ static int idmouse_probe(struct usb_interface *interface,
98static void idmouse_disconnect(struct usb_interface *interface); 98static void idmouse_disconnect(struct usb_interface *interface);
99 99
100/* file operation pointers */ 100/* file operation pointers */
101static struct file_operations idmouse_fops = { 101static const struct file_operations idmouse_fops = {
102 .owner = THIS_MODULE, 102 .owner = THIS_MODULE,
103 .read = idmouse_read, 103 .read = idmouse_read,
104 .open = idmouse_open, 104 .open = idmouse_open,
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index f30ab1fbb3c8..10b640339d8d 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -589,7 +589,7 @@ exit:
589} 589}
590 590
591/* file operations needed when we register this driver */ 591/* file operations needed when we register this driver */
592static struct file_operations ld_usb_fops = { 592static const struct file_operations ld_usb_fops = {
593 .owner = THIS_MODULE, 593 .owner = THIS_MODULE,
594 .read = ld_usb_read, 594 .read = ld_usb_read,
595 .write = ld_usb_write, 595 .write = ld_usb_write,
@@ -657,15 +657,11 @@ static int ld_usb_probe(struct usb_interface *intf, const struct usb_device_id *
657 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { 657 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
658 endpoint = &iface_desc->endpoint[i].desc; 658 endpoint = &iface_desc->endpoint[i].desc;
659 659
660 if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) && 660 if (usb_endpoint_is_int_in(endpoint))
661 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
662 dev->interrupt_in_endpoint = endpoint; 661 dev->interrupt_in_endpoint = endpoint;
663 }
664 662
665 if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) && 663 if (usb_endpoint_is_int_out(endpoint))
666 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
667 dev->interrupt_out_endpoint = endpoint; 664 dev->interrupt_out_endpoint = endpoint;
668 }
669 } 665 }
670 if (dev->interrupt_in_endpoint == NULL) { 666 if (dev->interrupt_in_endpoint == NULL) {
671 dev_err(&intf->dev, "Interrupt in endpoint not found\n"); 667 dev_err(&intf->dev, "Interrupt in endpoint not found\n");
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 7699d970e680..77c36e63c7bf 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -259,7 +259,7 @@ static void tower_disconnect (struct usb_interface *interface);
259static DEFINE_MUTEX (disconnect_mutex); 259static DEFINE_MUTEX (disconnect_mutex);
260 260
261/* file operations needed when we register this driver */ 261/* file operations needed when we register this driver */
262static struct file_operations tower_fops = { 262static const struct file_operations tower_fops = {
263 .owner = THIS_MODULE, 263 .owner = THIS_MODULE,
264 .read = tower_read, 264 .read = tower_read,
265 .write = tower_write, 265 .write = tower_write,
diff --git a/drivers/usb/misc/phidget.c b/drivers/usb/misc/phidget.c
new file mode 100644
index 000000000000..735ed33f4f7f
--- /dev/null
+++ b/drivers/usb/misc/phidget.c
@@ -0,0 +1,43 @@
1/*
2 * USB Phidgets class
3 *
4 * Copyright (C) 2006 Sean Young <sean@mess.org>
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
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/err.h>
16#include <linux/device.h>
17
18struct class *phidget_class;
19
20static int __init init_phidget(void)
21{
22 phidget_class = class_create(THIS_MODULE, "phidget");
23
24 if (IS_ERR(phidget_class))
25 return PTR_ERR(phidget_class);
26
27 return 0;
28}
29
30static void __exit cleanup_phidget(void)
31{
32 class_destroy(phidget_class);
33}
34
35EXPORT_SYMBOL_GPL(phidget_class);
36
37module_init(init_phidget);
38module_exit(cleanup_phidget);
39
40MODULE_LICENSE("GPL");
41MODULE_AUTHOR("Sean Young <sean@mess.org>");
42MODULE_DESCRIPTION("Container module for phidget class");
43
diff --git a/drivers/usb/misc/phidget.h b/drivers/usb/misc/phidget.h
new file mode 100644
index 000000000000..c4011907d431
--- /dev/null
+++ b/drivers/usb/misc/phidget.h
@@ -0,0 +1,12 @@
1/*
2 * USB Phidgets class
3 *
4 * Copyright (C) 2006 Sean Young <sean@mess.org>
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
12extern struct class *phidget_class;
diff --git a/drivers/usb/misc/phidgetkit.c b/drivers/usb/misc/phidgetkit.c
index bfbbbfbb92bc..78e419904abf 100644
--- a/drivers/usb/misc/phidgetkit.c
+++ b/drivers/usb/misc/phidgetkit.c
@@ -20,6 +20,8 @@
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/usb.h> 21#include <linux/usb.h>
22 22
23#include "phidget.h"
24
23#define DRIVER_AUTHOR "Sean Young <sean@mess.org>" 25#define DRIVER_AUTHOR "Sean Young <sean@mess.org>"
24#define DRIVER_DESC "USB PhidgetInterfaceKit Driver" 26#define DRIVER_DESC "USB PhidgetInterfaceKit Driver"
25 27
@@ -42,26 +44,35 @@ struct driver_interfacekit {
42 int inputs; 44 int inputs;
43 int outputs; 45 int outputs;
44 int has_lcd; 46 int has_lcd;
47 int amnesiac;
45}; 48};
46#define ifkit(_sensors, _inputs, _outputs, _lcd) \ 49
47static struct driver_interfacekit ph_##_sensors##_inputs##_outputs = { \ 50#define ifkit(_sensors, _inputs, _outputs, _lcd, _amnesiac) \
51{ \
48 .sensors = _sensors, \ 52 .sensors = _sensors, \
49 .inputs = _inputs, \ 53 .inputs = _inputs, \
50 .outputs = _outputs, \ 54 .outputs = _outputs, \
51 .has_lcd = _lcd, \ 55 .has_lcd = _lcd, \
56 .amnesiac = _amnesiac \
52}; 57};
53ifkit(0, 0, 4, 0); 58
54ifkit(8, 8, 8, 0); 59static const struct driver_interfacekit ph_004 = ifkit(0, 0, 4, 0, 0);
55ifkit(0, 4, 7, 1); 60static const struct driver_interfacekit ph_888n = ifkit(8, 8, 8, 0, 1);
56ifkit(8, 8, 4, 0); 61static const struct driver_interfacekit ph_888o = ifkit(8, 8, 8, 0, 0);
57ifkit(0, 8, 8, 1); 62static const struct driver_interfacekit ph_047 = ifkit(0, 4, 7, 1, 0);
58ifkit(0, 16, 16, 0); 63static const struct driver_interfacekit ph_884 = ifkit(8, 8, 4, 0, 0);
64static const struct driver_interfacekit ph_088 = ifkit(0, 8, 8, 1, 0);
65static const struct driver_interfacekit ph_01616 = ifkit(0, 16, 16, 0, 0);
66
67static unsigned long device_no;
59 68
60struct interfacekit { 69struct interfacekit {
61 struct usb_device *udev; 70 struct usb_device *udev;
62 struct usb_interface *intf; 71 struct usb_interface *intf;
63 struct driver_interfacekit *ifkit; 72 struct driver_interfacekit *ifkit;
73 struct device *dev;
64 unsigned long outputs; 74 unsigned long outputs;
75 int dev_no;
65 u8 inputs[MAX_INTERFACES]; 76 u8 inputs[MAX_INTERFACES];
66 u16 sensors[MAX_INTERFACES]; 77 u16 sensors[MAX_INTERFACES];
67 u8 lcd_files_on; 78 u8 lcd_files_on;
@@ -71,6 +82,7 @@ struct interfacekit {
71 dma_addr_t data_dma; 82 dma_addr_t data_dma;
72 83
73 struct work_struct do_notify; 84 struct work_struct do_notify;
85 struct work_struct do_resubmit;
74 unsigned long input_events; 86 unsigned long input_events;
75 unsigned long sensor_events; 87 unsigned long sensor_events;
76}; 88};
@@ -78,8 +90,10 @@ struct interfacekit {
78static struct usb_device_id id_table[] = { 90static struct usb_device_id id_table[] = {
79 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT004), 91 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT004),
80 .driver_info = (kernel_ulong_t)&ph_004}, 92 .driver_info = (kernel_ulong_t)&ph_004},
81 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT888), 93 {USB_DEVICE_VER(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT888, 0, 0x814),
82 .driver_info = (kernel_ulong_t)&ph_888}, 94 .driver_info = (kernel_ulong_t)&ph_888o},
95 {USB_DEVICE_VER(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT888, 0x0815, 0xffff),
96 .driver_info = (kernel_ulong_t)&ph_888n},
83 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT047), 97 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT047),
84 .driver_info = (kernel_ulong_t)&ph_047}, 98 .driver_info = (kernel_ulong_t)&ph_047},
85 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT088), 99 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT088),
@@ -92,16 +106,11 @@ static struct usb_device_id id_table[] = {
92}; 106};
93MODULE_DEVICE_TABLE(usb, id_table); 107MODULE_DEVICE_TABLE(usb, id_table);
94 108
95static int change_outputs(struct interfacekit *kit, int output_num, int enable) 109static int set_outputs(struct interfacekit *kit)
96{ 110{
97 u8 *buffer; 111 u8 *buffer;
98 int retval; 112 int retval;
99 113
100 if (enable)
101 set_bit(output_num, &kit->outputs);
102 else
103 clear_bit(output_num, &kit->outputs);
104
105 buffer = kzalloc(4, GFP_KERNEL); 114 buffer = kzalloc(4, GFP_KERNEL);
106 if (!buffer) { 115 if (!buffer) {
107 dev_err(&kit->udev->dev, "%s - out of memory\n", __FUNCTION__); 116 dev_err(&kit->udev->dev, "%s - out of memory\n", __FUNCTION__);
@@ -121,6 +130,9 @@ static int change_outputs(struct interfacekit *kit, int output_num, int enable)
121 retval); 130 retval);
122 kfree(buffer); 131 kfree(buffer);
123 132
133 if (kit->ifkit->amnesiac)
134 schedule_delayed_work(&kit->do_resubmit, HZ / 2);
135
124 return retval < 0 ? retval : 0; 136 return retval < 0 ? retval : 0;
125} 137}
126 138
@@ -180,21 +192,24 @@ exit:
180} 192}
181 193
182#define set_lcd_line(number) \ 194#define set_lcd_line(number) \
183static ssize_t lcd_line_##number(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ 195static ssize_t lcd_line_##number(struct device *dev, \
184{ \ 196 struct device_attribute *attr, \
185 struct usb_interface *intf = to_usb_interface(dev); \ 197 const char *buf, size_t count) \
186 struct interfacekit *kit = usb_get_intfdata(intf); \ 198{ \
187 change_string(kit, buf, number - 1); \ 199 struct interfacekit *kit = dev_get_drvdata(dev); \
188 return count; \ 200 change_string(kit, buf, number - 1); \
189} \ 201 return count; \
190static DEVICE_ATTR(lcd_line_##number, S_IWUGO, NULL, lcd_line_##number); 202}
203
204#define lcd_line_attr(number) \
205 __ATTR(lcd_line_##number, S_IWUGO, NULL, lcd_line_##number)
206
191set_lcd_line(1); 207set_lcd_line(1);
192set_lcd_line(2); 208set_lcd_line(2);
193 209
194static ssize_t set_backlight(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 210static ssize_t set_backlight(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
195{ 211{
196 struct usb_interface *intf = to_usb_interface(dev); 212 struct interfacekit *kit = dev_get_drvdata(dev);
197 struct interfacekit *kit = usb_get_intfdata(intf);
198 int enabled; 213 int enabled;
199 unsigned char *buffer; 214 unsigned char *buffer;
200 int retval = -ENOMEM; 215 int retval = -ENOMEM;
@@ -226,23 +241,30 @@ exit:
226 kfree(buffer); 241 kfree(buffer);
227 return retval; 242 return retval;
228} 243}
229static DEVICE_ATTR(backlight, S_IWUGO, NULL, set_backlight); 244
245static struct device_attribute dev_lcd_line_attrs[] = {
246 lcd_line_attr(1),
247 lcd_line_attr(2),
248 __ATTR(backlight, S_IWUGO, NULL, set_backlight)
249};
230 250
231static void remove_lcd_files(struct interfacekit *kit) 251static void remove_lcd_files(struct interfacekit *kit)
232{ 252{
253 int i;
254
233 if (kit->lcd_files_on) { 255 if (kit->lcd_files_on) {
234 dev_dbg(&kit->udev->dev, "Removing lcd files\n"); 256 dev_dbg(&kit->udev->dev, "Removing lcd files\n");
235 device_remove_file(&kit->intf->dev, &dev_attr_lcd_line_1); 257
236 device_remove_file(&kit->intf->dev, &dev_attr_lcd_line_2); 258 for (i=0; i<ARRAY_SIZE(dev_lcd_line_attrs); i++)
237 device_remove_file(&kit->intf->dev, &dev_attr_backlight); 259 device_remove_file(kit->dev, &dev_lcd_line_attrs[i]);
238 } 260 }
239} 261}
240 262
241static ssize_t enable_lcd_files(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 263static ssize_t enable_lcd_files(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
242{ 264{
243 struct usb_interface *intf = to_usb_interface(dev); 265 struct interfacekit *kit = dev_get_drvdata(dev);
244 struct interfacekit *kit = usb_get_intfdata(intf);
245 int enable; 266 int enable;
267 int i, rc;
246 268
247 if (kit->ifkit->has_lcd == 0) 269 if (kit->ifkit->has_lcd == 0)
248 return -ENODEV; 270 return -ENODEV;
@@ -253,9 +275,12 @@ static ssize_t enable_lcd_files(struct device *dev, struct device_attribute *att
253 if (enable) { 275 if (enable) {
254 if (!kit->lcd_files_on) { 276 if (!kit->lcd_files_on) {
255 dev_dbg(&kit->udev->dev, "Adding lcd files\n"); 277 dev_dbg(&kit->udev->dev, "Adding lcd files\n");
256 device_create_file(&kit->intf->dev, &dev_attr_lcd_line_1); 278 for (i=0; i<ARRAY_SIZE(dev_lcd_line_attrs); i++) {
257 device_create_file(&kit->intf->dev, &dev_attr_lcd_line_2); 279 rc = device_create_file(kit->dev,
258 device_create_file(&kit->intf->dev, &dev_attr_backlight); 280 &dev_lcd_line_attrs[i]);
281 if (rc)
282 goto out;
283 }
259 kit->lcd_files_on = 1; 284 kit->lcd_files_on = 1;
260 } 285 }
261 } else { 286 } else {
@@ -266,7 +291,13 @@ static ssize_t enable_lcd_files(struct device *dev, struct device_attribute *att
266 } 291 }
267 292
268 return count; 293 return count;
294out:
295 while (i-- > 0)
296 device_remove_file(kit->dev, &dev_lcd_line_attrs[i]);
297
298 return rc;
269} 299}
300
270static DEVICE_ATTR(lcd, S_IWUGO, NULL, enable_lcd_files); 301static DEVICE_ATTR(lcd, S_IWUGO, NULL, enable_lcd_files);
271 302
272static void interfacekit_irq(struct urb *urb, struct pt_regs *regs) 303static void interfacekit_irq(struct urb *urb, struct pt_regs *regs)
@@ -362,44 +393,58 @@ static void do_notify(void *data)
362 for (i=0; i<kit->ifkit->inputs; i++) { 393 for (i=0; i<kit->ifkit->inputs; i++) {
363 if (test_and_clear_bit(i, &kit->input_events)) { 394 if (test_and_clear_bit(i, &kit->input_events)) {
364 sprintf(sysfs_file, "input%d", i + 1); 395 sprintf(sysfs_file, "input%d", i + 1);
365 sysfs_notify(&kit->intf->dev.kobj, NULL, sysfs_file); 396 sysfs_notify(&kit->dev->kobj, NULL, sysfs_file);
366 } 397 }
367 } 398 }
368 399
369 for (i=0; i<kit->ifkit->sensors; i++) { 400 for (i=0; i<kit->ifkit->sensors; i++) {
370 if (test_and_clear_bit(i, &kit->sensor_events)) { 401 if (test_and_clear_bit(i, &kit->sensor_events)) {
371 sprintf(sysfs_file, "sensor%d", i + 1); 402 sprintf(sysfs_file, "sensor%d", i + 1);
372 sysfs_notify(&kit->intf->dev.kobj, NULL, sysfs_file); 403 sysfs_notify(&kit->dev->kobj, NULL, sysfs_file);
373 } 404 }
374 } 405 }
375} 406}
376 407
408static void do_resubmit(void *data)
409{
410 set_outputs(data);
411}
412
377#define show_set_output(value) \ 413#define show_set_output(value) \
378static ssize_t set_output##value(struct device *dev, struct device_attribute *attr, const char *buf, \ 414static ssize_t set_output##value(struct device *dev, \
379 size_t count) \ 415 struct device_attribute *attr, \
416 const char *buf, size_t count) \
380{ \ 417{ \
381 struct usb_interface *intf = to_usb_interface(dev); \ 418 struct interfacekit *kit = dev_get_drvdata(dev); \
382 struct interfacekit *kit = usb_get_intfdata(intf); \ 419 int enable; \
383 int enabled; \
384 int retval; \ 420 int retval; \
385 \ 421 \
386 if (sscanf(buf, "%d", &enabled) < 1) \ 422 if (sscanf(buf, "%d", &enable) < 1) \
387 return -EINVAL; \ 423 return -EINVAL; \
388 \ 424 \
389 retval = change_outputs(kit, value - 1, enabled); \ 425 if (enable) \
426 set_bit(value - 1, &kit->outputs); \
427 else \
428 clear_bit(value - 1, &kit->outputs); \
429 \
430 retval = set_outputs(kit); \
390 \ 431 \
391 return retval ? retval : count; \ 432 return retval ? retval : count; \
392} \ 433} \
393 \ 434 \
394static ssize_t show_output##value(struct device *dev, struct device_attribute *attr, char *buf) \ 435static ssize_t show_output##value(struct device *dev, \
436 struct device_attribute *attr, \
437 char *buf) \
395{ \ 438{ \
396 struct usb_interface *intf = to_usb_interface(dev); \ 439 struct interfacekit *kit = dev_get_drvdata(dev); \
397 struct interfacekit *kit = usb_get_intfdata(intf); \
398 \ 440 \
399 return sprintf(buf, "%d\n", !!test_bit(value - 1, &kit->outputs));\ 441 return sprintf(buf, "%d\n", !!test_bit(value - 1, &kit->outputs));\
400} \ 442}
401static DEVICE_ATTR(output##value, S_IWUGO | S_IRUGO, \ 443
402 show_output##value, set_output##value); 444#define output_attr(value) \
445 __ATTR(output##value, S_IWUGO | S_IRUGO, \
446 show_output##value, set_output##value)
447
403show_set_output(1); 448show_set_output(1);
404show_set_output(2); 449show_set_output(2);
405show_set_output(3); 450show_set_output(3);
@@ -417,15 +462,24 @@ show_set_output(14);
417show_set_output(15); 462show_set_output(15);
418show_set_output(16); 463show_set_output(16);
419 464
465static struct device_attribute dev_output_attrs[] = {
466 output_attr(1), output_attr(2), output_attr(3), output_attr(4),
467 output_attr(5), output_attr(6), output_attr(7), output_attr(8),
468 output_attr(9), output_attr(10), output_attr(11), output_attr(12),
469 output_attr(13), output_attr(14), output_attr(15), output_attr(16)
470};
471
420#define show_input(value) \ 472#define show_input(value) \
421static ssize_t show_input##value(struct device *dev, struct device_attribute *attr, char *buf) \ 473static ssize_t show_input##value(struct device *dev, \
474 struct device_attribute *attr, char *buf) \
422{ \ 475{ \
423 struct usb_interface *intf = to_usb_interface(dev); \ 476 struct interfacekit *kit = dev_get_drvdata(dev); \
424 struct interfacekit *kit = usb_get_intfdata(intf); \
425 \ 477 \
426 return sprintf(buf, "%d\n", (int)kit->inputs[value - 1]); \ 478 return sprintf(buf, "%d\n", (int)kit->inputs[value - 1]); \
427} \ 479}
428static DEVICE_ATTR(input##value, S_IRUGO, show_input##value, NULL); 480
481#define input_attr(value) \
482 __ATTR(input##value, S_IRUGO, show_input##value, NULL)
429 483
430show_input(1); 484show_input(1);
431show_input(2); 485show_input(2);
@@ -444,15 +498,25 @@ show_input(14);
444show_input(15); 498show_input(15);
445show_input(16); 499show_input(16);
446 500
501static struct device_attribute dev_input_attrs[] = {
502 input_attr(1), input_attr(2), input_attr(3), input_attr(4),
503 input_attr(5), input_attr(6), input_attr(7), input_attr(8),
504 input_attr(9), input_attr(10), input_attr(11), input_attr(12),
505 input_attr(13), input_attr(14), input_attr(15), input_attr(16)
506};
507
447#define show_sensor(value) \ 508#define show_sensor(value) \
448static ssize_t show_sensor##value(struct device *dev, struct device_attribute *attr, char *buf) \ 509static ssize_t show_sensor##value(struct device *dev, \
510 struct device_attribute *attr, \
511 char *buf) \
449{ \ 512{ \
450 struct usb_interface *intf = to_usb_interface(dev); \ 513 struct interfacekit *kit = dev_get_drvdata(dev); \
451 struct interfacekit *kit = usb_get_intfdata(intf); \
452 \ 514 \
453 return sprintf(buf, "%d\n", (int)kit->sensors[value - 1]); \ 515 return sprintf(buf, "%d\n", (int)kit->sensors[value - 1]); \
454} \ 516}
455static DEVICE_ATTR(sensor##value, S_IRUGO, show_sensor##value, NULL); 517
518#define sensor_attr(value) \
519 __ATTR(sensor##value, S_IRUGO, show_sensor##value, NULL)
456 520
457show_sensor(1); 521show_sensor(1);
458show_sensor(2); 522show_sensor(2);
@@ -463,6 +527,11 @@ show_sensor(6);
463show_sensor(7); 527show_sensor(7);
464show_sensor(8); 528show_sensor(8);
465 529
530static struct device_attribute dev_sensor_attrs[] = {
531 sensor_attr(1), sensor_attr(2), sensor_attr(3), sensor_attr(4),
532 sensor_attr(5), sensor_attr(6), sensor_attr(7), sensor_attr(8)
533};
534
466static int interfacekit_probe(struct usb_interface *intf, const struct usb_device_id *id) 535static int interfacekit_probe(struct usb_interface *intf, const struct usb_device_id *id)
467{ 536{
468 struct usb_device *dev = interface_to_usbdev(intf); 537 struct usb_device *dev = interface_to_usbdev(intf);
@@ -471,6 +540,7 @@ static int interfacekit_probe(struct usb_interface *intf, const struct usb_devic
471 struct interfacekit *kit; 540 struct interfacekit *kit;
472 struct driver_interfacekit *ifkit; 541 struct driver_interfacekit *ifkit;
473 int pipe, maxp, rc = -ENOMEM; 542 int pipe, maxp, rc = -ENOMEM;
543 int bit, value, i;
474 544
475 ifkit = (struct driver_interfacekit *)id->driver_info; 545 ifkit = (struct driver_interfacekit *)id->driver_info;
476 if (!ifkit) 546 if (!ifkit)
@@ -493,6 +563,7 @@ static int interfacekit_probe(struct usb_interface *intf, const struct usb_devic
493 if (!kit) 563 if (!kit)
494 goto out; 564 goto out;
495 565
566 kit->dev_no = -1;
496 kit->ifkit = ifkit; 567 kit->ifkit = ifkit;
497 kit->data = usb_buffer_alloc(dev, URB_INT_SIZE, SLAB_ATOMIC, &kit->data_dma); 568 kit->data = usb_buffer_alloc(dev, URB_INT_SIZE, SLAB_ATOMIC, &kit->data_dma);
498 if (!kit->data) 569 if (!kit->data)
@@ -505,6 +576,7 @@ static int interfacekit_probe(struct usb_interface *intf, const struct usb_devic
505 kit->udev = usb_get_dev(dev); 576 kit->udev = usb_get_dev(dev);
506 kit->intf = intf; 577 kit->intf = intf;
507 INIT_WORK(&kit->do_notify, do_notify, kit); 578 INIT_WORK(&kit->do_notify, do_notify, kit);
579 INIT_WORK(&kit->do_resubmit, do_resubmit, kit);
508 usb_fill_int_urb(kit->irq, kit->udev, pipe, kit->data, 580 usb_fill_int_urb(kit->irq, kit->udev, pipe, kit->data,
509 maxp > URB_INT_SIZE ? URB_INT_SIZE : maxp, 581 maxp > URB_INT_SIZE ? URB_INT_SIZE : maxp,
510 interfacekit_irq, kit, endpoint->bInterval); 582 interfacekit_irq, kit, endpoint->bInterval);
@@ -513,85 +585,80 @@ static int interfacekit_probe(struct usb_interface *intf, const struct usb_devic
513 585
514 usb_set_intfdata(intf, kit); 586 usb_set_intfdata(intf, kit);
515 587
588 do {
589 bit = find_first_zero_bit(&device_no, sizeof(device_no));
590 value = test_and_set_bit(bit, &device_no);
591 } while(value);
592 kit->dev_no = bit;
593
594 kit->dev = device_create(phidget_class, &kit->udev->dev, 0,
595 "interfacekit%d", kit->dev_no);
596 if (IS_ERR(kit->dev)) {
597 rc = PTR_ERR(kit->dev);
598 kit->dev = NULL;
599 goto out;
600 }
601 dev_set_drvdata(kit->dev, kit);
602
516 if (usb_submit_urb(kit->irq, GFP_KERNEL)) { 603 if (usb_submit_urb(kit->irq, GFP_KERNEL)) {
517 rc = -EIO; 604 rc = -EIO;
518 goto out; 605 goto out;
519 } 606 }
520 607
521 if (ifkit->outputs >= 4) { 608 for (i=0; i<ifkit->outputs; i++ ) {
522 device_create_file(&intf->dev, &dev_attr_output1); 609 rc = device_create_file(kit->dev, &dev_output_attrs[i]);
523 device_create_file(&intf->dev, &dev_attr_output2); 610 if (rc)
524 device_create_file(&intf->dev, &dev_attr_output3); 611 goto out2;
525 device_create_file(&intf->dev, &dev_attr_output4);
526 }
527 if (ifkit->outputs >= 8) {
528 device_create_file(&intf->dev, &dev_attr_output5);
529 device_create_file(&intf->dev, &dev_attr_output6);
530 device_create_file(&intf->dev, &dev_attr_output7);
531 device_create_file(&intf->dev, &dev_attr_output8);
532 }
533 if (ifkit->outputs == 16) {
534 device_create_file(&intf->dev, &dev_attr_output9);
535 device_create_file(&intf->dev, &dev_attr_output10);
536 device_create_file(&intf->dev, &dev_attr_output11);
537 device_create_file(&intf->dev, &dev_attr_output12);
538 device_create_file(&intf->dev, &dev_attr_output13);
539 device_create_file(&intf->dev, &dev_attr_output14);
540 device_create_file(&intf->dev, &dev_attr_output15);
541 device_create_file(&intf->dev, &dev_attr_output16);
542 } 612 }
543 613
544 if (ifkit->inputs >= 4) { 614 for (i=0; i<ifkit->inputs; i++ ) {
545 device_create_file(&intf->dev, &dev_attr_input1); 615 rc = device_create_file(kit->dev, &dev_input_attrs[i]);
546 device_create_file(&intf->dev, &dev_attr_input2); 616 if (rc)
547 device_create_file(&intf->dev, &dev_attr_input3); 617 goto out3;
548 device_create_file(&intf->dev, &dev_attr_input4);
549 }
550 if (ifkit->inputs >= 8) {
551 device_create_file(&intf->dev, &dev_attr_input5);
552 device_create_file(&intf->dev, &dev_attr_input6);
553 device_create_file(&intf->dev, &dev_attr_input7);
554 device_create_file(&intf->dev, &dev_attr_input8);
555 }
556 if (ifkit->inputs == 16) {
557 device_create_file(&intf->dev, &dev_attr_input9);
558 device_create_file(&intf->dev, &dev_attr_input10);
559 device_create_file(&intf->dev, &dev_attr_input11);
560 device_create_file(&intf->dev, &dev_attr_input12);
561 device_create_file(&intf->dev, &dev_attr_input13);
562 device_create_file(&intf->dev, &dev_attr_input14);
563 device_create_file(&intf->dev, &dev_attr_input15);
564 device_create_file(&intf->dev, &dev_attr_input16);
565 } 618 }
566 619
567 if (ifkit->sensors >= 4) { 620 for (i=0; i<ifkit->sensors; i++ ) {
568 device_create_file(&intf->dev, &dev_attr_sensor1); 621 rc = device_create_file(kit->dev, &dev_sensor_attrs[i]);
569 device_create_file(&intf->dev, &dev_attr_sensor2); 622 if (rc)
570 device_create_file(&intf->dev, &dev_attr_sensor3); 623 goto out4;
571 device_create_file(&intf->dev, &dev_attr_sensor4);
572 } 624 }
573 if (ifkit->sensors >= 7) {
574 device_create_file(&intf->dev, &dev_attr_sensor5);
575 device_create_file(&intf->dev, &dev_attr_sensor6);
576 device_create_file(&intf->dev, &dev_attr_sensor7);
577 }
578 if (ifkit->sensors == 8)
579 device_create_file(&intf->dev, &dev_attr_sensor8);
580 625
581 if (ifkit->has_lcd) 626 if (ifkit->has_lcd) {
582 device_create_file(&intf->dev, &dev_attr_lcd); 627 rc = device_create_file(kit->dev, &dev_attr_lcd);
628 if (rc)
629 goto out4;
630
631 }
583 632
584 dev_info(&intf->dev, "USB PhidgetInterfaceKit %d/%d/%d attached\n", 633 dev_info(&intf->dev, "USB PhidgetInterfaceKit %d/%d/%d attached\n",
585 ifkit->sensors, ifkit->inputs, ifkit->outputs); 634 ifkit->sensors, ifkit->inputs, ifkit->outputs);
586 635
587 return 0; 636 return 0;
588 637
638out4:
639 while (i-- > 0)
640 device_remove_file(kit->dev, &dev_sensor_attrs[i]);
641
642 i = ifkit->inputs;
643out3:
644 while (i-- > 0)
645 device_remove_file(kit->dev, &dev_input_attrs[i]);
646
647 i = ifkit->outputs;
648out2:
649 while (i-- > 0)
650 device_remove_file(kit->dev, &dev_output_attrs[i]);
589out: 651out:
590 if (kit) { 652 if (kit) {
591 if (kit->irq) 653 if (kit->irq)
592 usb_free_urb(kit->irq); 654 usb_free_urb(kit->irq);
593 if (kit->data) 655 if (kit->data)
594 usb_buffer_free(dev, URB_INT_SIZE, kit->data, kit->data_dma); 656 usb_buffer_free(dev, URB_INT_SIZE, kit->data, kit->data_dma);
657 if (kit->dev)
658 device_unregister(kit->dev);
659 if (kit->dev_no >= 0)
660 clear_bit(kit->dev_no, &device_no);
661
595 kfree(kit); 662 kfree(kit);
596 } 663 }
597 664
@@ -601,6 +668,7 @@ out:
601static void interfacekit_disconnect(struct usb_interface *interface) 668static void interfacekit_disconnect(struct usb_interface *interface)
602{ 669{
603 struct interfacekit *kit; 670 struct interfacekit *kit;
671 int i;
604 672
605 kit = usb_get_intfdata(interface); 673 kit = usb_get_intfdata(interface);
606 usb_set_intfdata(interface, NULL); 674 usb_set_intfdata(interface, NULL);
@@ -612,74 +680,30 @@ static void interfacekit_disconnect(struct usb_interface *interface)
612 usb_buffer_free(kit->udev, URB_INT_SIZE, kit->data, kit->data_dma); 680 usb_buffer_free(kit->udev, URB_INT_SIZE, kit->data, kit->data_dma);
613 681
614 cancel_delayed_work(&kit->do_notify); 682 cancel_delayed_work(&kit->do_notify);
683 cancel_delayed_work(&kit->do_resubmit);
615 684
616 if (kit->ifkit->outputs >= 4) { 685 for (i=0; i<kit->ifkit->outputs; i++)
617 device_remove_file(&interface->dev, &dev_attr_output1); 686 device_remove_file(kit->dev, &dev_output_attrs[i]);
618 device_remove_file(&interface->dev, &dev_attr_output2);
619 device_remove_file(&interface->dev, &dev_attr_output3);
620 device_remove_file(&interface->dev, &dev_attr_output4);
621 }
622 if (kit->ifkit->outputs >= 8) {
623 device_remove_file(&interface->dev, &dev_attr_output5);
624 device_remove_file(&interface->dev, &dev_attr_output6);
625 device_remove_file(&interface->dev, &dev_attr_output7);
626 device_remove_file(&interface->dev, &dev_attr_output8);
627 }
628 if (kit->ifkit->outputs == 16) {
629 device_remove_file(&interface->dev, &dev_attr_output9);
630 device_remove_file(&interface->dev, &dev_attr_output10);
631 device_remove_file(&interface->dev, &dev_attr_output11);
632 device_remove_file(&interface->dev, &dev_attr_output12);
633 device_remove_file(&interface->dev, &dev_attr_output13);
634 device_remove_file(&interface->dev, &dev_attr_output14);
635 device_remove_file(&interface->dev, &dev_attr_output15);
636 device_remove_file(&interface->dev, &dev_attr_output16);
637 }
638 687
639 if (kit->ifkit->inputs >= 4) { 688 for (i=0; i<kit->ifkit->inputs; i++)
640 device_remove_file(&interface->dev, &dev_attr_input1); 689 device_remove_file(kit->dev, &dev_input_attrs[i]);
641 device_remove_file(&interface->dev, &dev_attr_input2);
642 device_remove_file(&interface->dev, &dev_attr_input3);
643 device_remove_file(&interface->dev, &dev_attr_input4);
644 }
645 if (kit->ifkit->inputs >= 8) {
646 device_remove_file(&interface->dev, &dev_attr_input5);
647 device_remove_file(&interface->dev, &dev_attr_input6);
648 device_remove_file(&interface->dev, &dev_attr_input7);
649 device_remove_file(&interface->dev, &dev_attr_input8);
650 }
651 if (kit->ifkit->inputs == 16) {
652 device_remove_file(&interface->dev, &dev_attr_input9);
653 device_remove_file(&interface->dev, &dev_attr_input10);
654 device_remove_file(&interface->dev, &dev_attr_input11);
655 device_remove_file(&interface->dev, &dev_attr_input12);
656 device_remove_file(&interface->dev, &dev_attr_input13);
657 device_remove_file(&interface->dev, &dev_attr_input14);
658 device_remove_file(&interface->dev, &dev_attr_input15);
659 device_remove_file(&interface->dev, &dev_attr_input16);
660 }
661 690
662 if (kit->ifkit->sensors >= 4) { 691 for (i=0; i<kit->ifkit->sensors; i++)
663 device_remove_file(&interface->dev, &dev_attr_sensor1); 692 device_remove_file(kit->dev, &dev_sensor_attrs[i]);
664 device_remove_file(&interface->dev, &dev_attr_sensor2); 693
665 device_remove_file(&interface->dev, &dev_attr_sensor3); 694 if (kit->ifkit->has_lcd) {
666 device_remove_file(&interface->dev, &dev_attr_sensor4); 695 device_remove_file(kit->dev, &dev_attr_lcd);
667 } 696 remove_lcd_files(kit);
668 if (kit->ifkit->sensors >= 7) {
669 device_remove_file(&interface->dev, &dev_attr_sensor5);
670 device_remove_file(&interface->dev, &dev_attr_sensor6);
671 device_remove_file(&interface->dev, &dev_attr_sensor7);
672 } 697 }
673 if (kit->ifkit->sensors == 8)
674 device_remove_file(&interface->dev, &dev_attr_sensor8);
675 698
676 if (kit->ifkit->has_lcd) 699 device_unregister(kit->dev);
677 device_remove_file(&interface->dev, &dev_attr_lcd);
678 700
679 dev_info(&interface->dev, "USB PhidgetInterfaceKit %d/%d/%d detached\n", 701 dev_info(&interface->dev, "USB PhidgetInterfaceKit %d/%d/%d detached\n",
680 kit->ifkit->sensors, kit->ifkit->inputs, kit->ifkit->outputs); 702 kit->ifkit->sensors, kit->ifkit->inputs, kit->ifkit->outputs);
681 703
682 usb_put_dev(kit->udev); 704 usb_put_dev(kit->udev);
705 clear_bit(kit->dev_no, &device_no);
706
683 kfree(kit); 707 kfree(kit);
684} 708}
685 709
diff --git a/drivers/usb/misc/phidgetmotorcontrol.c b/drivers/usb/misc/phidgetmotorcontrol.c
new file mode 100644
index 000000000000..6b59b620d616
--- /dev/null
+++ b/drivers/usb/misc/phidgetmotorcontrol.c
@@ -0,0 +1,466 @@
1/*
2 * USB Phidget MotorControl driver
3 *
4 * Copyright (C) 2006 Sean Young <sean@mess.org>
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
12#include <linux/kernel.h>
13#include <linux/errno.h>
14#include <linux/init.h>
15#include <linux/module.h>
16#include <linux/usb.h>
17
18#include "phidget.h"
19
20#define DRIVER_AUTHOR "Sean Young <sean@mess.org>"
21#define DRIVER_DESC "USB PhidgetMotorControl Driver"
22
23#define USB_VENDOR_ID_GLAB 0x06c2
24#define USB_DEVICE_ID_MOTORCONTROL 0x0058
25
26#define URB_INT_SIZE 8
27
28static unsigned long device_no;
29
30struct motorcontrol {
31 struct usb_device *udev;
32 struct usb_interface *intf;
33 struct device *dev;
34 int dev_no;
35 u8 inputs[4];
36 s8 desired_speed[2];
37 s8 speed[2];
38 s16 _current[2];
39 s8 acceleration[2];
40 struct urb *irq;
41 unsigned char *data;
42 dma_addr_t data_dma;
43
44 struct work_struct do_notify;
45 unsigned long input_events;
46 unsigned long speed_events;
47 unsigned long exceed_events;
48};
49
50static struct usb_device_id id_table[] = {
51 { USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_MOTORCONTROL) },
52 {}
53};
54MODULE_DEVICE_TABLE(usb, id_table);
55
56static int set_motor(struct motorcontrol *mc, int motor)
57{
58 u8 *buffer;
59 int speed, speed2, acceleration;
60 int retval;
61
62 buffer = kzalloc(8, GFP_KERNEL);
63 if (!buffer) {
64 dev_err(&mc->intf->dev, "%s - out of memory\n", __FUNCTION__);
65 return -ENOMEM;
66 }
67
68 acceleration = mc->acceleration[motor] * 10;
69 /* -127 <= speed <= 127 */
70 speed = (mc->desired_speed[motor] * 127) / 100;
71 /* -0x7300 <= speed2 <= 0x7300 */
72 speed2 = (mc->desired_speed[motor] * 230 * 128) / 100;
73
74 buffer[0] = motor;
75 buffer[1] = speed;
76 buffer[2] = acceleration >> 8;
77 buffer[3] = acceleration;
78 buffer[4] = speed2 >> 8;
79 buffer[5] = speed2;
80
81 retval = usb_control_msg(mc->udev,
82 usb_sndctrlpipe(mc->udev, 0),
83 0x09, 0x21, 0x0200, 0x0000, buffer, 8, 2000);
84
85 if (retval != 8)
86 dev_err(&mc->intf->dev, "usb_control_msg returned %d\n",
87 retval);
88 kfree(buffer);
89
90 return retval < 0 ? retval : 0;
91}
92
93static void motorcontrol_irq(struct urb *urb, struct pt_regs *regs)
94{
95 struct motorcontrol *mc = urb->context;
96 unsigned char *buffer = mc->data;
97 int i, level;
98 int status;
99
100 switch (urb->status) {
101 case 0: /* success */
102 break;
103 case -ECONNRESET: /* unlink */
104 case -ENOENT:
105 case -ESHUTDOWN:
106 return;
107 /* -EPIPE: should clear the halt */
108 default: /* error */
109 goto resubmit;
110 }
111
112 /* digital inputs */
113 for (i=0; i<4; i++) {
114 level = (buffer[0] >> i) & 1;
115 if (mc->inputs[i] != level) {
116 mc->inputs[i] = level;
117 set_bit(i, &mc->input_events);
118 }
119 }
120
121 /* motor speed */
122 if (buffer[2] == 0) {
123 for (i=0; i<2; i++) {
124 level = ((s8)buffer[4+i]) * 100 / 127;
125 if (mc->speed[i] != level) {
126 mc->speed[i] = level;
127 set_bit(i, &mc->speed_events);
128 }
129 }
130 } else {
131 int index = buffer[3] & 1;
132
133 level = ((s8)buffer[4] << 8) | buffer[5];
134 level = level * 100 / 29440;
135 if (mc->speed[index] != level) {
136 mc->speed[index] = level;
137 set_bit(index, &mc->speed_events);
138 }
139
140 level = ((s8)buffer[6] << 8) | buffer[7];
141 mc->_current[index] = level * 100 / 1572;
142 }
143
144 if (buffer[1] & 1)
145 set_bit(0, &mc->exceed_events);
146
147 if (buffer[1] & 2)
148 set_bit(1, &mc->exceed_events);
149
150 if (mc->input_events || mc->exceed_events || mc->speed_events)
151 schedule_work(&mc->do_notify);
152
153resubmit:
154 status = usb_submit_urb(urb, SLAB_ATOMIC);
155 if (status)
156 dev_err(&mc->intf->dev,
157 "can't resubmit intr, %s-%s/motorcontrol0, status %d",
158 mc->udev->bus->bus_name,
159 mc->udev->devpath, status);
160}
161
162static void do_notify(void *data)
163{
164 struct motorcontrol *mc = data;
165 int i;
166 char sysfs_file[8];
167
168 for (i=0; i<4; i++) {
169 if (test_and_clear_bit(i, &mc->input_events)) {
170 sprintf(sysfs_file, "input%d", i);
171 sysfs_notify(&mc->dev->kobj, NULL, sysfs_file);
172 }
173 }
174
175 for (i=0; i<2; i++) {
176 if (test_and_clear_bit(i, &mc->speed_events)) {
177 sprintf(sysfs_file, "speed%d", i);
178 sysfs_notify(&mc->dev->kobj, NULL, sysfs_file);
179 }
180 }
181
182 for (i=0; i<2; i++) {
183 if (test_and_clear_bit(i, &mc->exceed_events))
184 dev_warn(&mc->intf->dev,
185 "motor #%d exceeds 1.5 Amp current limit\n", i);
186 }
187}
188
189#define show_set_speed(value) \
190static ssize_t set_speed##value(struct device *dev, \
191 struct device_attribute *attr, \
192 const char *buf, size_t count) \
193{ \
194 struct motorcontrol *mc = dev_get_drvdata(dev); \
195 int speed; \
196 int retval; \
197 \
198 if (sscanf(buf, "%d", &speed) < 1) \
199 return -EINVAL; \
200 \
201 if (speed < -100 || speed > 100) \
202 return -EINVAL; \
203 \
204 mc->desired_speed[value] = speed; \
205 \
206 retval = set_motor(mc, value); \
207 \
208 return retval ? retval : count; \
209} \
210 \
211static ssize_t show_speed##value(struct device *dev, \
212 struct device_attribute *attr, \
213 char *buf) \
214{ \
215 struct motorcontrol *mc = dev_get_drvdata(dev); \
216 \
217 return sprintf(buf, "%d\n", mc->speed[value]); \
218}
219
220#define speed_attr(value) \
221 __ATTR(speed##value, S_IWUGO | S_IRUGO, \
222 show_speed##value, set_speed##value)
223
224show_set_speed(0);
225show_set_speed(1);
226
227#define show_set_acceleration(value) \
228static ssize_t set_acceleration##value(struct device *dev, \
229 struct device_attribute *attr, \
230 const char *buf, size_t count) \
231{ \
232 struct motorcontrol *mc = dev_get_drvdata(dev); \
233 int acceleration; \
234 int retval; \
235 \
236 if (sscanf(buf, "%d", &acceleration) < 1) \
237 return -EINVAL; \
238 \
239 if (acceleration < 0 || acceleration > 100) \
240 return -EINVAL; \
241 \
242 mc->acceleration[value] = acceleration; \
243 \
244 retval = set_motor(mc, value); \
245 \
246 return retval ? retval : count; \
247} \
248 \
249static ssize_t show_acceleration##value(struct device *dev, \
250 struct device_attribute *attr, \
251 char *buf) \
252{ \
253 struct motorcontrol *mc = dev_get_drvdata(dev); \
254 \
255 return sprintf(buf, "%d\n", mc->acceleration[value]); \
256}
257
258#define acceleration_attr(value) \
259 __ATTR(acceleration##value, S_IWUGO | S_IRUGO, \
260 show_acceleration##value, set_acceleration##value)
261
262show_set_acceleration(0);
263show_set_acceleration(1);
264
265#define show_current(value) \
266static ssize_t show_current##value(struct device *dev, \
267 struct device_attribute *attr, \
268 char *buf) \
269{ \
270 struct motorcontrol *mc = dev_get_drvdata(dev); \
271 \
272 return sprintf(buf, "%dmA\n", (int)mc->_current[value]); \
273}
274
275#define current_attr(value) \
276 __ATTR(current##value, S_IRUGO, show_current##value, NULL)
277
278show_current(0);
279show_current(1);
280
281#define show_input(value) \
282static ssize_t show_input##value(struct device *dev, \
283 struct device_attribute *attr, \
284 char *buf) \
285{ \
286 struct motorcontrol *mc = dev_get_drvdata(dev); \
287 \
288 return sprintf(buf, "%d\n", (int)mc->inputs[value]); \
289}
290
291#define input_attr(value) \
292 __ATTR(input##value, S_IRUGO, show_input##value, NULL)
293
294show_input(0);
295show_input(1);
296show_input(2);
297show_input(3);
298
299static struct device_attribute dev_attrs[] = {
300 input_attr(0),
301 input_attr(1),
302 input_attr(2),
303 input_attr(3),
304 speed_attr(0),
305 speed_attr(1),
306 acceleration_attr(0),
307 acceleration_attr(1),
308 current_attr(0),
309 current_attr(1)
310};
311
312static int motorcontrol_probe(struct usb_interface *intf, const struct usb_device_id *id)
313{
314 struct usb_device *dev = interface_to_usbdev(intf);
315 struct usb_host_interface *interface;
316 struct usb_endpoint_descriptor *endpoint;
317 struct motorcontrol *mc;
318 int pipe, maxp, rc = -ENOMEM;
319 int bit, value, i;
320
321 interface = intf->cur_altsetting;
322 if (interface->desc.bNumEndpoints != 1)
323 return -ENODEV;
324
325 endpoint = &interface->endpoint[0].desc;
326 if (!(endpoint->bEndpointAddress & 0x80))
327 return -ENODEV;
328
329 /*
330 * bmAttributes
331 */
332 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
333 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
334
335 mc = kzalloc(sizeof(*mc), GFP_KERNEL);
336 if (!mc)
337 goto out;
338
339 mc->dev_no = -1;
340 mc->data = usb_buffer_alloc(dev, URB_INT_SIZE, SLAB_ATOMIC, &mc->data_dma);
341 if (!mc->data)
342 goto out;
343
344 mc->irq = usb_alloc_urb(0, GFP_KERNEL);
345 if (!mc->irq)
346 goto out;
347
348 mc->udev = usb_get_dev(dev);
349 mc->intf = intf;
350 mc->acceleration[0] = mc->acceleration[1] = 10;
351 INIT_WORK(&mc->do_notify, do_notify, mc);
352 usb_fill_int_urb(mc->irq, mc->udev, pipe, mc->data,
353 maxp > URB_INT_SIZE ? URB_INT_SIZE : maxp,
354 motorcontrol_irq, mc, endpoint->bInterval);
355 mc->irq->transfer_dma = mc->data_dma;
356 mc->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
357
358 usb_set_intfdata(intf, mc);
359
360 do {
361 bit = find_first_zero_bit(&device_no, sizeof(device_no));
362 value = test_and_set_bit(bit, &device_no);
363 } while(value);
364 mc->dev_no = bit;
365
366 mc->dev = device_create(phidget_class, &mc->udev->dev, 0,
367 "motorcontrol%d", mc->dev_no);
368 if (IS_ERR(mc->dev)) {
369 rc = PTR_ERR(mc->dev);
370 mc->dev = NULL;
371 goto out;
372 }
373
374 dev_set_drvdata(mc->dev, mc);
375
376 if (usb_submit_urb(mc->irq, GFP_KERNEL)) {
377 rc = -EIO;
378 goto out;
379 }
380
381 for (i=0; i<ARRAY_SIZE(dev_attrs); i++) {
382 rc = device_create_file(mc->dev, &dev_attrs[i]);
383 if (rc)
384 goto out2;
385 }
386
387 dev_info(&intf->dev, "USB PhidgetMotorControl attached\n");
388
389 return 0;
390out2:
391 while (i-- > 0)
392 device_remove_file(mc->dev, &dev_attrs[i]);
393out:
394 if (mc) {
395 if (mc->irq)
396 usb_free_urb(mc->irq);
397 if (mc->data)
398 usb_buffer_free(dev, URB_INT_SIZE, mc->data, mc->data_dma);
399 if (mc->dev)
400 device_unregister(mc->dev);
401 if (mc->dev_no >= 0)
402 clear_bit(mc->dev_no, &device_no);
403
404 kfree(mc);
405 }
406
407 return rc;
408}
409
410static void motorcontrol_disconnect(struct usb_interface *interface)
411{
412 struct motorcontrol *mc;
413 int i;
414
415 mc = usb_get_intfdata(interface);
416 usb_set_intfdata(interface, NULL);
417 if (!mc)
418 return;
419
420 usb_kill_urb(mc->irq);
421 usb_free_urb(mc->irq);
422 usb_buffer_free(mc->udev, URB_INT_SIZE, mc->data, mc->data_dma);
423
424 cancel_delayed_work(&mc->do_notify);
425
426 for (i=0; i<ARRAY_SIZE(dev_attrs); i++)
427 device_remove_file(mc->dev, &dev_attrs[i]);
428
429 device_unregister(mc->dev);
430
431 usb_put_dev(mc->udev);
432 clear_bit(mc->dev_no, &device_no);
433 kfree(mc);
434
435 dev_info(&interface->dev, "USB PhidgetMotorControl detached\n");
436}
437
438static struct usb_driver motorcontrol_driver = {
439 .name = "phidgetmotorcontrol",
440 .probe = motorcontrol_probe,
441 .disconnect = motorcontrol_disconnect,
442 .id_table = id_table
443};
444
445static int __init motorcontrol_init(void)
446{
447 int retval = 0;
448
449 retval = usb_register(&motorcontrol_driver);
450 if (retval)
451 err("usb_register failed. Error number %d", retval);
452
453 return retval;
454}
455
456static void __exit motorcontrol_exit(void)
457{
458 usb_deregister(&motorcontrol_driver);
459}
460
461module_init(motorcontrol_init);
462module_exit(motorcontrol_exit);
463
464MODULE_AUTHOR(DRIVER_AUTHOR);
465MODULE_DESCRIPTION(DRIVER_DESC);
466MODULE_LICENSE("GPL");
diff --git a/drivers/usb/misc/phidgetservo.c b/drivers/usb/misc/phidgetservo.c
index c0df79c96538..7163f05c5b27 100644
--- a/drivers/usb/misc/phidgetservo.c
+++ b/drivers/usb/misc/phidgetservo.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * USB PhidgetServo driver 1.0 2 * USB PhidgetServo driver 1.0
3 * 3 *
4 * Copyright (C) 2004 Sean Young <sean@mess.org> 4 * Copyright (C) 2004, 2006 Sean Young <sean@mess.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 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 7 * it under the terms of the GNU General Public License as published by
@@ -15,14 +15,6 @@
15 * 15 *
16 * CAUTION: Generally you should use 0 < degrees < 180 as anything else 16 * CAUTION: Generally you should use 0 < degrees < 180 as anything else
17 * is probably beyond the range of your servo and may damage it. 17 * is probably beyond the range of your servo and may damage it.
18 *
19 * Jun 16, 2004: Sean Young <sean@mess.org>
20 * - cleanups
21 * - was using memory after kfree()
22 * Aug 8, 2004: Sean Young <sean@mess.org>
23 * - set the highest angle as high as the hardware allows, there are
24 * some odd servos out there
25 *
26 */ 18 */
27 19
28#include <linux/kernel.h> 20#include <linux/kernel.h>
@@ -32,6 +24,8 @@
32#include <linux/module.h> 24#include <linux/module.h>
33#include <linux/usb.h> 25#include <linux/usb.h>
34 26
27#include "phidget.h"
28
35#define DRIVER_AUTHOR "Sean Young <sean@mess.org>" 29#define DRIVER_AUTHOR "Sean Young <sean@mess.org>"
36#define DRIVER_DESC "USB PhidgetServo Driver" 30#define DRIVER_DESC "USB PhidgetServo Driver"
37 31
@@ -70,8 +64,12 @@ static struct usb_device_id id_table[] = {
70 64
71MODULE_DEVICE_TABLE(usb, id_table); 65MODULE_DEVICE_TABLE(usb, id_table);
72 66
67static int unsigned long device_no;
68
73struct phidget_servo { 69struct phidget_servo {
74 struct usb_device *udev; 70 struct usb_device *udev;
71 struct device *dev;
72 int dev_no;
75 ulong type; 73 ulong type;
76 int pulse[4]; 74 int pulse[4];
77 int degrees[4]; 75 int degrees[4];
@@ -203,16 +201,16 @@ change_position_v20(struct phidget_servo *servo, int servo_no, int degrees,
203} 201}
204 202
205#define show_set(value) \ 203#define show_set(value) \
206static ssize_t set_servo##value (struct device *dev, struct device_attribute *attr, \ 204static ssize_t set_servo##value (struct device *dev, \
205 struct device_attribute *attr, \
207 const char *buf, size_t count) \ 206 const char *buf, size_t count) \
208{ \ 207{ \
209 int degrees, minutes, retval; \ 208 int degrees, minutes, retval; \
210 struct usb_interface *intf = to_usb_interface (dev); \ 209 struct phidget_servo *servo = dev_get_drvdata(dev); \
211 struct phidget_servo *servo = usb_get_intfdata (intf); \
212 \ 210 \
213 minutes = 0; \ 211 minutes = 0; \
214 /* must at least convert degrees */ \ 212 /* must at least convert degrees */ \
215 if (sscanf (buf, "%d.%d", &degrees, &minutes) < 1) { \ 213 if (sscanf(buf, "%d.%d", &degrees, &minutes) < 1) { \
216 return -EINVAL; \ 214 return -EINVAL; \
217 } \ 215 } \
218 \ 216 \
@@ -220,86 +218,127 @@ static ssize_t set_servo##value (struct device *dev, struct device_attribute *at
220 return -EINVAL; \ 218 return -EINVAL; \
221 \ 219 \
222 if (servo->type & SERVO_VERSION_30) \ 220 if (servo->type & SERVO_VERSION_30) \
223 retval = change_position_v30 (servo, value, degrees, \ 221 retval = change_position_v30(servo, value, degrees, \
224 minutes); \ 222 minutes); \
225 else \ 223 else \
226 retval = change_position_v20 (servo, value, degrees, \ 224 retval = change_position_v20(servo, value, degrees, \
227 minutes); \ 225 minutes); \
228 \ 226 \
229 return retval < 0 ? retval : count; \ 227 return retval < 0 ? retval : count; \
230} \ 228} \
231 \ 229 \
232static ssize_t show_servo##value (struct device *dev, struct device_attribute *attr, char *buf) \ 230static ssize_t show_servo##value (struct device *dev, \
231 struct device_attribute *attr, \
232 char *buf) \
233{ \ 233{ \
234 struct usb_interface *intf = to_usb_interface (dev); \ 234 struct phidget_servo *servo = dev_get_drvdata(dev); \
235 struct phidget_servo *servo = usb_get_intfdata (intf); \
236 \ 235 \
237 return sprintf (buf, "%d.%02d\n", servo->degrees[value], \ 236 return sprintf(buf, "%d.%02d\n", servo->degrees[value], \
238 servo->minutes[value]); \ 237 servo->minutes[value]); \
239} \ 238}
240static DEVICE_ATTR(servo##value, S_IWUGO | S_IRUGO, \
241 show_servo##value, set_servo##value);
242 239
240#define servo_attr(value) \
241 __ATTR(servo##value, S_IWUGO | S_IRUGO, \
242 show_servo##value, set_servo##value)
243show_set(0); 243show_set(0);
244show_set(1); 244show_set(1);
245show_set(2); 245show_set(2);
246show_set(3); 246show_set(3);
247 247
248static struct device_attribute dev_attrs[] = {
249 servo_attr(0), servo_attr(1), servo_attr(2), servo_attr(3)
250};
251
248static int 252static int
249servo_probe(struct usb_interface *interface, const struct usb_device_id *id) 253servo_probe(struct usb_interface *interface, const struct usb_device_id *id)
250{ 254{
251 struct usb_device *udev = interface_to_usbdev(interface); 255 struct usb_device *udev = interface_to_usbdev(interface);
252 struct phidget_servo *dev; 256 struct phidget_servo *dev;
257 int bit, value, rc;
258 int servo_count, i;
253 259
254 dev = kzalloc(sizeof (struct phidget_servo), GFP_KERNEL); 260 dev = kzalloc(sizeof (struct phidget_servo), GFP_KERNEL);
255 if (dev == NULL) { 261 if (dev == NULL) {
256 dev_err(&interface->dev, "%s - out of memory\n", __FUNCTION__); 262 dev_err(&interface->dev, "%s - out of memory\n", __FUNCTION__);
257 return -ENOMEM; 263 rc = -ENOMEM;
264 goto out;
258 } 265 }
259 266
260 dev->udev = usb_get_dev(udev); 267 dev->udev = usb_get_dev(udev);
261 dev->type = id->driver_info; 268 dev->type = id->driver_info;
269 dev->dev_no = -1;
262 usb_set_intfdata(interface, dev); 270 usb_set_intfdata(interface, dev);
263 271
264 device_create_file(&interface->dev, &dev_attr_servo0); 272 do {
265 if (dev->type & SERVO_COUNT_QUAD) { 273 bit = find_first_zero_bit(&device_no, sizeof(device_no));
266 device_create_file(&interface->dev, &dev_attr_servo1); 274 value = test_and_set_bit(bit, &device_no);
267 device_create_file(&interface->dev, &dev_attr_servo2); 275 } while (value);
268 device_create_file(&interface->dev, &dev_attr_servo3); 276 dev->dev_no = bit;
277
278 dev->dev = device_create(phidget_class, &dev->udev->dev, 0,
279 "servo%d", dev->dev_no);
280 if (IS_ERR(dev->dev)) {
281 rc = PTR_ERR(dev->dev);
282 dev->dev = NULL;
283 goto out;
284 }
285
286 servo_count = dev->type & SERVO_COUNT_QUAD ? 4 : 1;
287
288 for (i=0; i<servo_count; i++) {
289 rc = device_create_file(dev->dev, &dev_attrs[i]);
290 if (rc)
291 goto out2;
269 } 292 }
270 293
271 dev_info(&interface->dev, "USB %d-Motor PhidgetServo v%d.0 attached\n", 294 dev_info(&interface->dev, "USB %d-Motor PhidgetServo v%d.0 attached\n",
272 dev->type & SERVO_COUNT_QUAD ? 4 : 1, 295 servo_count, dev->type & SERVO_VERSION_30 ? 3 : 2);
273 dev->type & SERVO_VERSION_30 ? 3 : 2);
274 296
275 if(!(dev->type & SERVO_VERSION_30)) 297 if (!(dev->type & SERVO_VERSION_30))
276 dev_info(&interface->dev, 298 dev_info(&interface->dev,
277 "WARNING: v2.0 not tested! Please report if it works.\n"); 299 "WARNING: v2.0 not tested! Please report if it works.\n");
278 300
279 return 0; 301 return 0;
302out2:
303 while (i-- > 0)
304 device_remove_file(dev->dev, &dev_attrs[i]);
305out:
306 if (dev) {
307 if (dev->dev)
308 device_unregister(dev->dev);
309 if (dev->dev_no >= 0)
310 clear_bit(dev->dev_no, &device_no);
311
312 kfree(dev);
313 }
314
315 return rc;
280} 316}
281 317
282static void 318static void
283servo_disconnect(struct usb_interface *interface) 319servo_disconnect(struct usb_interface *interface)
284{ 320{
285 struct phidget_servo *dev; 321 struct phidget_servo *dev;
322 int servo_count, i;
286 323
287 dev = usb_get_intfdata(interface); 324 dev = usb_get_intfdata(interface);
288 usb_set_intfdata(interface, NULL); 325 usb_set_intfdata(interface, NULL);
289 326
290 device_remove_file(&interface->dev, &dev_attr_servo0); 327 if (!dev)
291 if (dev->type & SERVO_COUNT_QUAD) { 328 return;
292 device_remove_file(&interface->dev, &dev_attr_servo1); 329
293 device_remove_file(&interface->dev, &dev_attr_servo2); 330 servo_count = dev->type & SERVO_COUNT_QUAD ? 4 : 1;
294 device_remove_file(&interface->dev, &dev_attr_servo3); 331
295 } 332 for (i=0; i<servo_count; i++)
333 device_remove_file(dev->dev, &dev_attrs[i]);
296 334
335 device_unregister(dev->dev);
297 usb_put_dev(dev->udev); 336 usb_put_dev(dev->udev);
298 337
299 dev_info(&interface->dev, "USB %d-Motor PhidgetServo v%d.0 detached\n", 338 dev_info(&interface->dev, "USB %d-Motor PhidgetServo v%d.0 detached\n",
300 dev->type & SERVO_COUNT_QUAD ? 4 : 1, 339 servo_count, dev->type & SERVO_VERSION_30 ? 3 : 2);
301 dev->type & SERVO_VERSION_30 ? 3 : 2);
302 340
341 clear_bit(dev->dev_no, &device_no);
303 kfree(dev); 342 kfree(dev);
304} 343}
305 344
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index e16582f3733c..a44124c7e851 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -3179,7 +3179,7 @@ sisusb_compat_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
3179} 3179}
3180#endif 3180#endif
3181 3181
3182static struct file_operations usb_sisusb_fops = { 3182static const struct file_operations usb_sisusb_fops = {
3183 .owner = THIS_MODULE, 3183 .owner = THIS_MODULE,
3184 .open = sisusb_open, 3184 .open = sisusb_open,
3185 .release = sisusb_release, 3185 .release = sisusb_release,
diff --git a/drivers/usb/misc/usb_u132.h b/drivers/usb/misc/usb_u132.h
new file mode 100644
index 000000000000..551ba8906d62
--- /dev/null
+++ b/drivers/usb/misc/usb_u132.h
@@ -0,0 +1,97 @@
1/*
2* Common Header File for the Elan Digital Systems U132 adapter
3* this file should be included by both the "ftdi-u132" and
4* the "u132-hcd" modules.
5*
6* Copyright(C) 2006 Elan Digital Systems Limited
7*(http://www.elandigitalsystems.com)
8*
9* Author and Maintainer - Tony Olech - Elan Digital Systems
10*(tony.olech@elandigitalsystems.com)
11*
12* This program is free software;you can redistribute it and/or
13* modify it under the terms of the GNU General Public License as
14* published by the Free Software Foundation, version 2.
15*
16*
17* The driver was written by Tony Olech(tony.olech@elandigitalsystems.com)
18* based on various USB client drivers in the 2.6.15 linux kernel
19* with constant reference to the 3rd Edition of Linux Device Drivers
20* published by O'Reilly
21*
22* The U132 adapter is a USB to CardBus adapter specifically designed
23* for PC cards that contain an OHCI host controller. Typical PC cards
24* are the Orange Mobile 3G Option GlobeTrotter Fusion card.
25*
26* The U132 adapter will *NOT *work with PC cards that do not contain
27* an OHCI controller. A simple way to test whether a PC card has an
28* OHCI controller as an interface is to insert the PC card directly
29* into a laptop(or desktop) with a CardBus slot and if "lspci" shows
30* a new USB controller and "lsusb -v" shows a new OHCI Host Controller
31* then there is a good chance that the U132 adapter will support the
32* PC card.(you also need the specific client driver for the PC card)
33*
34* Please inform the Author and Maintainer about any PC cards that
35* contain OHCI Host Controller and work when directly connected to
36* an embedded CardBus slot but do not work when they are connected
37* via an ELAN U132 adapter.
38*
39* The driver consists of two modules, the "ftdi-u132" module is
40* a USB client driver that interfaces to the FTDI chip within
41* the U132 adapter manufactured by Elan Digital Systems, and the
42* "u132-hcd" module is a USB host controller driver that talks
43* to the OHCI controller within CardBus card that are inserted
44* in the U132 adapter.
45*
46* The "ftdi-u132" module should be loaded automatically by the
47* hot plug system when the U132 adapter is plugged in. The module
48* initialises the adapter which mostly consists of synchronising
49* the FTDI chip, before continuously polling the adapter to detect
50* PC card insertions. As soon as a PC card containing a recognised
51* OHCI controller is seen the "ftdi-u132" module explicitly requests
52* the kernel to load the "u132-hcd" module.
53*
54* The "ftdi-u132" module provides the interface to the inserted
55* PC card and the "u132-hcd" module uses the API to send and recieve
56* data. The API features call-backs, so that part of the "u132-hcd"
57* module code will run in the context of one of the kernel threads
58* of the "ftdi-u132" module.
59*
60*/
61int ftdi_elan_switch_on_diagnostics(int number);
62void ftdi_elan_gone_away(struct platform_device *pdev);
63void start_usb_lock_device_tracing(void);
64struct u132_platform_data {
65 u16 vendor;
66 u16 device;
67 u8 potpg;
68 void (*port_power) (struct device *dev, int is_on);
69 void (*reset) (struct device *dev);
70};
71int usb_ftdi_elan_edset_single(struct platform_device *pdev, u8 ed_number,
72 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
73 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
74 int toggle_bits, int error_count, int condition_code, int repeat_number,
75 int halted, int skipped, int actual, int non_null));
76int usb_ftdi_elan_edset_output(struct platform_device *pdev, u8 ed_number,
77 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
78 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
79 int toggle_bits, int error_count, int condition_code, int repeat_number,
80 int halted, int skipped, int actual, int non_null));
81int usb_ftdi_elan_edset_empty(struct platform_device *pdev, u8 ed_number,
82 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
83 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
84 int toggle_bits, int error_count, int condition_code, int repeat_number,
85 int halted, int skipped, int actual, int non_null));
86int usb_ftdi_elan_edset_input(struct platform_device *pdev, u8 ed_number,
87 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
88 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
89 int toggle_bits, int error_count, int condition_code, int repeat_number,
90 int halted, int skipped, int actual, int non_null));
91int usb_ftdi_elan_edset_setup(struct platform_device *pdev, u8 ed_number,
92 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
93 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
94 int toggle_bits, int error_count, int condition_code, int repeat_number,
95 int halted, int skipped, int actual, int non_null));
96int usb_ftdi_elan_edset_flush(struct platform_device *pdev, u8 ed_number,
97 void *endp);
diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c
index e095772dd8e9..dbaca9f1efad 100644
--- a/drivers/usb/misc/usblcd.c
+++ b/drivers/usb/misc/usblcd.c
@@ -239,7 +239,7 @@ error:
239 return retval; 239 return retval;
240} 240}
241 241
242static struct file_operations lcd_fops = { 242static const struct file_operations lcd_fops = {
243 .owner = THIS_MODULE, 243 .owner = THIS_MODULE,
244 .read = lcd_read, 244 .read = lcd_read,
245 .write = lcd_write, 245 .write = lcd_write,
@@ -290,9 +290,7 @@ static int lcd_probe(struct usb_interface *interface, const struct usb_device_id
290 endpoint = &iface_desc->endpoint[i].desc; 290 endpoint = &iface_desc->endpoint[i].desc;
291 291
292 if (!dev->bulk_in_endpointAddr && 292 if (!dev->bulk_in_endpointAddr &&
293 (endpoint->bEndpointAddress & USB_DIR_IN) && 293 usb_endpoint_is_bulk_in(endpoint)) {
294 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
295 == USB_ENDPOINT_XFER_BULK)) {
296 /* we found a bulk in endpoint */ 294 /* we found a bulk in endpoint */
297 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 295 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
298 dev->bulk_in_size = buffer_size; 296 dev->bulk_in_size = buffer_size;
@@ -305,9 +303,7 @@ static int lcd_probe(struct usb_interface *interface, const struct usb_device_id
305 } 303 }
306 304
307 if (!dev->bulk_out_endpointAddr && 305 if (!dev->bulk_out_endpointAddr &&
308 !(endpoint->bEndpointAddress & USB_DIR_IN) && 306 usb_endpoint_is_bulk_out(endpoint)) {
309 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
310 == USB_ENDPOINT_XFER_BULK)) {
311 /* we found a bulk out endpoint */ 307 /* we found a bulk out endpoint */
312 dev->bulk_out_endpointAddr = endpoint->bEndpointAddress; 308 dev->bulk_out_endpointAddr = endpoint->bEndpointAddress;
313 } 309 }
diff --git a/drivers/usb/misc/usbled.c b/drivers/usb/misc/usbled.c
index 0c5ee0ad6bb9..49c5c5c4c431 100644
--- a/drivers/usb/misc/usbled.c
+++ b/drivers/usb/misc/usbled.c
@@ -108,22 +108,34 @@ static int led_probe(struct usb_interface *interface, const struct usb_device_id
108 dev = kzalloc(sizeof(struct usb_led), GFP_KERNEL); 108 dev = kzalloc(sizeof(struct usb_led), GFP_KERNEL);
109 if (dev == NULL) { 109 if (dev == NULL) {
110 dev_err(&interface->dev, "Out of memory\n"); 110 dev_err(&interface->dev, "Out of memory\n");
111 goto error; 111 goto error_mem;
112 } 112 }
113 113
114 dev->udev = usb_get_dev(udev); 114 dev->udev = usb_get_dev(udev);
115 115
116 usb_set_intfdata (interface, dev); 116 usb_set_intfdata (interface, dev);
117 117
118 device_create_file(&interface->dev, &dev_attr_blue); 118 retval = device_create_file(&interface->dev, &dev_attr_blue);
119 device_create_file(&interface->dev, &dev_attr_red); 119 if (retval)
120 device_create_file(&interface->dev, &dev_attr_green); 120 goto error;
121 retval = device_create_file(&interface->dev, &dev_attr_red);
122 if (retval)
123 goto error;
124 retval = device_create_file(&interface->dev, &dev_attr_green);
125 if (retval)
126 goto error;
121 127
122 dev_info(&interface->dev, "USB LED device now attached\n"); 128 dev_info(&interface->dev, "USB LED device now attached\n");
123 return 0; 129 return 0;
124 130
125error: 131error:
132 device_remove_file(&interface->dev, &dev_attr_blue);
133 device_remove_file(&interface->dev, &dev_attr_red);
134 device_remove_file(&interface->dev, &dev_attr_green);
135 usb_set_intfdata (interface, NULL);
136 usb_put_dev(dev->udev);
126 kfree(dev); 137 kfree(dev);
138error_mem:
127 return retval; 139 return retval;
128} 140}
129 141
diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c
index 275a66f83058..394bbf2f68d4 100644
--- a/drivers/usb/mon/mon_main.c
+++ b/drivers/usb/mon/mon_main.c
@@ -265,7 +265,6 @@ static void mon_dissolve(struct mon_bus *mbus, struct usb_bus *ubus)
265 ubus->mon_bus = NULL; 265 ubus->mon_bus = NULL;
266 mbus->u_bus = NULL; 266 mbus->u_bus = NULL;
267 mb(); 267 mb();
268 // usb_bus_put(ubus);
269} 268}
270 269
271/* 270/*
@@ -297,12 +296,12 @@ static void mon_bus_init(struct dentry *mondir, struct usb_bus *ubus)
297 INIT_LIST_HEAD(&mbus->r_list); 296 INIT_LIST_HEAD(&mbus->r_list);
298 297
299 /* 298 /*
300 * This usb_bus_get here is superfluous, because we receive 299 * We don't need to take a reference to ubus, because we receive
301 * a notification if usb_bus is about to be removed. 300 * a notification if the bus is about to be removed.
302 */ 301 */
303 // usb_bus_get(ubus);
304 mbus->u_bus = ubus; 302 mbus->u_bus = ubus;
305 ubus->mon_bus = mbus; 303 ubus->mon_bus = mbus;
304 mbus->uses_dma = ubus->uses_dma;
306 305
307 rc = snprintf(name, NAMESZ, "%dt", ubus->busnum); 306 rc = snprintf(name, NAMESZ, "%dt", ubus->busnum);
308 if (rc <= 0 || rc >= NAMESZ) 307 if (rc <= 0 || rc >= NAMESZ)
diff --git a/drivers/usb/mon/mon_stat.c b/drivers/usb/mon/mon_stat.c
index 1fe01d994a79..f6d1491256c4 100644
--- a/drivers/usb/mon/mon_stat.c
+++ b/drivers/usb/mon/mon_stat.c
@@ -28,7 +28,7 @@ static int mon_stat_open(struct inode *inode, struct file *file)
28 if ((sp = kmalloc(sizeof(struct snap), GFP_KERNEL)) == NULL) 28 if ((sp = kmalloc(sizeof(struct snap), GFP_KERNEL)) == NULL)
29 return -ENOMEM; 29 return -ENOMEM;
30 30
31 mbus = inode->u.generic_ip; 31 mbus = inode->i_private;
32 32
33 sp->slen = snprintf(sp->str, STAT_BUF_SIZE, 33 sp->slen = snprintf(sp->str, STAT_BUF_SIZE,
34 "nreaders %d events %u text_lost %u\n", 34 "nreaders %d events %u text_lost %u\n",
@@ -62,7 +62,7 @@ static int mon_stat_release(struct inode *inode, struct file *file)
62 return 0; 62 return 0;
63} 63}
64 64
65struct file_operations mon_fops_stat = { 65const struct file_operations mon_fops_stat = {
66 .owner = THIS_MODULE, 66 .owner = THIS_MODULE,
67 .open = mon_stat_open, 67 .open = mon_stat_open,
68 .llseek = no_llseek, 68 .llseek = no_llseek,
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index f961a770cee2..7a2346c53284 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -75,13 +75,13 @@ static void mon_text_ctor(void *, kmem_cache_t *, unsigned long);
75 */ 75 */
76 76
77static inline char mon_text_get_setup(struct mon_event_text *ep, 77static inline char mon_text_get_setup(struct mon_event_text *ep,
78 struct urb *urb, char ev_type) 78 struct urb *urb, char ev_type, struct mon_bus *mbus)
79{ 79{
80 80
81 if (!usb_pipecontrol(urb->pipe) || ev_type != 'S') 81 if (!usb_pipecontrol(urb->pipe) || ev_type != 'S')
82 return '-'; 82 return '-';
83 83
84 if (urb->transfer_flags & URB_NO_SETUP_DMA_MAP) 84 if (mbus->uses_dma && (urb->transfer_flags & URB_NO_SETUP_DMA_MAP))
85 return mon_dmapeek(ep->setup, urb->setup_dma, SETUP_MAX); 85 return mon_dmapeek(ep->setup, urb->setup_dma, SETUP_MAX);
86 if (urb->setup_packet == NULL) 86 if (urb->setup_packet == NULL)
87 return 'Z'; /* '0' would be not as pretty. */ 87 return 'Z'; /* '0' would be not as pretty. */
@@ -91,7 +91,7 @@ static inline char mon_text_get_setup(struct mon_event_text *ep,
91} 91}
92 92
93static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb, 93static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb,
94 int len, char ev_type) 94 int len, char ev_type, struct mon_bus *mbus)
95{ 95{
96 int pipe = urb->pipe; 96 int pipe = urb->pipe;
97 97
@@ -117,7 +117,7 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb,
117 * contain non-NULL garbage in case the upper level promised to 117 * contain non-NULL garbage in case the upper level promised to
118 * set DMA for the HCD. 118 * set DMA for the HCD.
119 */ 119 */
120 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) 120 if (mbus->uses_dma && (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP))
121 return mon_dmapeek(ep->data, urb->transfer_dma, len); 121 return mon_dmapeek(ep->data, urb->transfer_dma, len);
122 122
123 if (urb->transfer_buffer == NULL) 123 if (urb->transfer_buffer == NULL)
@@ -161,8 +161,9 @@ static void mon_text_event(struct mon_reader_text *rp, struct urb *urb,
161 /* Collecting status makes debugging sense for submits, too */ 161 /* Collecting status makes debugging sense for submits, too */
162 ep->status = urb->status; 162 ep->status = urb->status;
163 163
164 ep->setup_flag = mon_text_get_setup(ep, urb, ev_type); 164 ep->setup_flag = mon_text_get_setup(ep, urb, ev_type, rp->r.m_bus);
165 ep->data_flag = mon_text_get_data(ep, urb, ep->length, ev_type); 165 ep->data_flag = mon_text_get_data(ep, urb, ep->length, ev_type,
166 rp->r.m_bus);
166 167
167 rp->nevents++; 168 rp->nevents++;
168 list_add_tail(&ep->e_link, &rp->e_list); 169 list_add_tail(&ep->e_link, &rp->e_list);
@@ -238,7 +239,7 @@ static int mon_text_open(struct inode *inode, struct file *file)
238 int rc; 239 int rc;
239 240
240 mutex_lock(&mon_lock); 241 mutex_lock(&mon_lock);
241 mbus = inode->u.generic_ip; 242 mbus = inode->i_private;
242 ubus = mbus->u_bus; 243 ubus = mbus->u_bus;
243 244
244 rp = kzalloc(sizeof(struct mon_reader_text), GFP_KERNEL); 245 rp = kzalloc(sizeof(struct mon_reader_text), GFP_KERNEL);
@@ -401,7 +402,7 @@ static int mon_text_release(struct inode *inode, struct file *file)
401 struct mon_event_text *ep; 402 struct mon_event_text *ep;
402 403
403 mutex_lock(&mon_lock); 404 mutex_lock(&mon_lock);
404 mbus = inode->u.generic_ip; 405 mbus = inode->i_private;
405 406
406 if (mbus->nreaders <= 0) { 407 if (mbus->nreaders <= 0) {
407 printk(KERN_ERR TAG ": consistency error on close\n"); 408 printk(KERN_ERR TAG ": consistency error on close\n");
@@ -435,7 +436,7 @@ static int mon_text_release(struct inode *inode, struct file *file)
435 return 0; 436 return 0;
436} 437}
437 438
438struct file_operations mon_fops_text = { 439const struct file_operations mon_fops_text = {
439 .owner = THIS_MODULE, 440 .owner = THIS_MODULE,
440 .open = mon_text_open, 441 .open = mon_text_open,
441 .llseek = no_llseek, 442 .llseek = no_llseek,
diff --git a/drivers/usb/mon/usb_mon.h b/drivers/usb/mon/usb_mon.h
index 33678c24ebee..ab9d02d5df77 100644
--- a/drivers/usb/mon/usb_mon.h
+++ b/drivers/usb/mon/usb_mon.h
@@ -20,6 +20,7 @@ struct mon_bus {
20 struct dentry *dent_s; /* Debugging file */ 20 struct dentry *dent_s; /* Debugging file */
21 struct dentry *dent_t; /* Text interface file */ 21 struct dentry *dent_t; /* Text interface file */
22 struct usb_bus *u_bus; 22 struct usb_bus *u_bus;
23 int uses_dma;
23 24
24 /* Ref */ 25 /* Ref */
25 int nreaders; /* Under mon_lock AND mbus->lock */ 26 int nreaders; /* Under mon_lock AND mbus->lock */
@@ -53,7 +54,7 @@ extern char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len);
53 54
54extern struct mutex mon_lock; 55extern struct mutex mon_lock;
55 56
56extern struct file_operations mon_fops_text; 57extern const struct file_operations mon_fops_text;
57extern struct file_operations mon_fops_stat; 58extern const struct file_operations mon_fops_stat;
58 59
59#endif /* __USB_MON_H */ 60#endif /* __USB_MON_H */
diff --git a/drivers/usb/net/asix.c b/drivers/usb/net/asix.c
index 2e2bbc003e93..9c0eacf7055c 100644
--- a/drivers/usb/net/asix.c
+++ b/drivers/usb/net/asix.c
@@ -1,7 +1,8 @@
1/* 1/*
2 * ASIX AX8817X based USB 2.0 Ethernet Devices 2 * ASIX AX8817X based USB 2.0 Ethernet Devices
3 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> 3 * Copyright (C) 2003-2006 David Hollis <dhollis@davehollis.com>
4 * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net> 4 * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
5 * Copyright (C) 2006 James Painter <jamie.painter@iname.com>
5 * Copyright (c) 2002-2003 TiVo Inc. 6 * Copyright (c) 2002-2003 TiVo Inc.
6 * 7 *
7 * 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
@@ -36,6 +37,9 @@
36 37
37#include "usbnet.h" 38#include "usbnet.h"
38 39
40#define DRIVER_VERSION "14-Jun-2006"
41static const char driver_name [] = "asix";
42
39/* ASIX AX8817X based USB 2.0 Ethernet Devices */ 43/* ASIX AX8817X based USB 2.0 Ethernet Devices */
40 44
41#define AX_CMD_SET_SW_MII 0x06 45#define AX_CMD_SET_SW_MII 0x06
@@ -46,23 +50,25 @@
46#define AX_CMD_WRITE_EEPROM 0x0c 50#define AX_CMD_WRITE_EEPROM 0x0c
47#define AX_CMD_WRITE_ENABLE 0x0d 51#define AX_CMD_WRITE_ENABLE 0x0d
48#define AX_CMD_WRITE_DISABLE 0x0e 52#define AX_CMD_WRITE_DISABLE 0x0e
53#define AX_CMD_READ_RX_CTL 0x0f
49#define AX_CMD_WRITE_RX_CTL 0x10 54#define AX_CMD_WRITE_RX_CTL 0x10
50#define AX_CMD_READ_IPG012 0x11 55#define AX_CMD_READ_IPG012 0x11
51#define AX_CMD_WRITE_IPG0 0x12 56#define AX_CMD_WRITE_IPG0 0x12
52#define AX_CMD_WRITE_IPG1 0x13 57#define AX_CMD_WRITE_IPG1 0x13
58#define AX_CMD_READ_NODE_ID 0x13
53#define AX_CMD_WRITE_IPG2 0x14 59#define AX_CMD_WRITE_IPG2 0x14
54#define AX_CMD_WRITE_MULTI_FILTER 0x16 60#define AX_CMD_WRITE_MULTI_FILTER 0x16
55#define AX_CMD_READ_NODE_ID 0x17 61#define AX88172_CMD_READ_NODE_ID 0x17
56#define AX_CMD_READ_PHY_ID 0x19 62#define AX_CMD_READ_PHY_ID 0x19
57#define AX_CMD_READ_MEDIUM_STATUS 0x1a 63#define AX_CMD_READ_MEDIUM_STATUS 0x1a
58#define AX_CMD_WRITE_MEDIUM_MODE 0x1b 64#define AX_CMD_WRITE_MEDIUM_MODE 0x1b
59#define AX_CMD_READ_MONITOR_MODE 0x1c 65#define AX_CMD_READ_MONITOR_MODE 0x1c
60#define AX_CMD_WRITE_MONITOR_MODE 0x1d 66#define AX_CMD_WRITE_MONITOR_MODE 0x1d
67#define AX_CMD_READ_GPIOS 0x1e
61#define AX_CMD_WRITE_GPIOS 0x1f 68#define AX_CMD_WRITE_GPIOS 0x1f
62#define AX_CMD_SW_RESET 0x20 69#define AX_CMD_SW_RESET 0x20
63#define AX_CMD_SW_PHY_STATUS 0x21 70#define AX_CMD_SW_PHY_STATUS 0x21
64#define AX_CMD_SW_PHY_SELECT 0x22 71#define AX_CMD_SW_PHY_SELECT 0x22
65#define AX88772_CMD_READ_NODE_ID 0x13
66 72
67#define AX_MONITOR_MODE 0x01 73#define AX_MONITOR_MODE 0x01
68#define AX_MONITOR_LINK 0x02 74#define AX_MONITOR_LINK 0x02
@@ -70,15 +76,15 @@
70#define AX_MONITOR_HSFS 0x10 76#define AX_MONITOR_HSFS 0x10
71 77
72/* AX88172 Medium Status Register values */ 78/* AX88172 Medium Status Register values */
73#define AX_MEDIUM_FULL_DUPLEX 0x02 79#define AX88172_MEDIUM_FD 0x02
74#define AX_MEDIUM_TX_ABORT_ALLOW 0x04 80#define AX88172_MEDIUM_TX 0x04
75#define AX_MEDIUM_FLOW_CONTROL_EN 0x10 81#define AX88172_MEDIUM_FC 0x10
82#define AX88172_MEDIUM_DEFAULT \
83 ( AX88172_MEDIUM_FD | AX88172_MEDIUM_TX | AX88172_MEDIUM_FC )
76 84
77#define AX_MCAST_FILTER_SIZE 8 85#define AX_MCAST_FILTER_SIZE 8
78#define AX_MAX_MCAST 64 86#define AX_MAX_MCAST 64
79 87
80#define AX_EEPROM_LEN 0x40
81
82#define AX_SWRESET_CLEAR 0x00 88#define AX_SWRESET_CLEAR 0x00
83#define AX_SWRESET_RR 0x01 89#define AX_SWRESET_RR 0x01
84#define AX_SWRESET_RT 0x02 90#define AX_SWRESET_RT 0x02
@@ -92,23 +98,78 @@
92#define AX88772_IPG1_DEFAULT 0x0c 98#define AX88772_IPG1_DEFAULT 0x0c
93#define AX88772_IPG2_DEFAULT 0x12 99#define AX88772_IPG2_DEFAULT 0x12
94 100
95#define AX88772_MEDIUM_FULL_DUPLEX 0x0002 101/* AX88772 & AX88178 Medium Mode Register */
96#define AX88772_MEDIUM_RESERVED 0x0004 102#define AX_MEDIUM_PF 0x0080
97#define AX88772_MEDIUM_RX_FC_ENABLE 0x0010 103#define AX_MEDIUM_JFE 0x0040
98#define AX88772_MEDIUM_TX_FC_ENABLE 0x0020 104#define AX_MEDIUM_TFC 0x0020
99#define AX88772_MEDIUM_PAUSE_FORMAT 0x0080 105#define AX_MEDIUM_RFC 0x0010
100#define AX88772_MEDIUM_RX_ENABLE 0x0100 106#define AX_MEDIUM_ENCK 0x0008
101#define AX88772_MEDIUM_100MB 0x0200 107#define AX_MEDIUM_AC 0x0004
102#define AX88772_MEDIUM_DEFAULT \ 108#define AX_MEDIUM_FD 0x0002
103 (AX88772_MEDIUM_FULL_DUPLEX | AX88772_MEDIUM_RX_FC_ENABLE | \ 109#define AX_MEDIUM_GM 0x0001
104 AX88772_MEDIUM_TX_FC_ENABLE | AX88772_MEDIUM_100MB | \ 110#define AX_MEDIUM_SM 0x1000
105 AX88772_MEDIUM_RESERVED | AX88772_MEDIUM_RX_ENABLE ) 111#define AX_MEDIUM_SBP 0x0800
112#define AX_MEDIUM_PS 0x0200
113#define AX_MEDIUM_RE 0x0100
114
115#define AX88178_MEDIUM_DEFAULT \
116 (AX_MEDIUM_PS | AX_MEDIUM_FD | AX_MEDIUM_AC | \
117 AX_MEDIUM_RFC | AX_MEDIUM_TFC | AX_MEDIUM_JFE | \
118 AX_MEDIUM_RE )
106 119
107#define AX_EEPROM_MAGIC 0xdeadbeef 120#define AX88772_MEDIUM_DEFAULT \
121 (AX_MEDIUM_FD | AX_MEDIUM_RFC | \
122 AX_MEDIUM_TFC | AX_MEDIUM_PS | \
123 AX_MEDIUM_AC | AX_MEDIUM_RE )
124
125/* AX88772 & AX88178 RX_CTL values */
126#define AX_RX_CTL_SO 0x0080
127#define AX_RX_CTL_AP 0x0020
128#define AX_RX_CTL_AM 0x0010
129#define AX_RX_CTL_AB 0x0008
130#define AX_RX_CTL_SEP 0x0004
131#define AX_RX_CTL_AMALL 0x0002
132#define AX_RX_CTL_PRO 0x0001
133#define AX_RX_CTL_MFB_2048 0x0000
134#define AX_RX_CTL_MFB_4096 0x0100
135#define AX_RX_CTL_MFB_8192 0x0200
136#define AX_RX_CTL_MFB_16384 0x0300
137
138#define AX_DEFAULT_RX_CTL \
139 (AX_RX_CTL_SO | AX_RX_CTL_AB )
140
141/* GPIO 0 .. 2 toggles */
142#define AX_GPIO_GPO0EN 0x01 /* GPIO0 Output enable */
143#define AX_GPIO_GPO_0 0x02 /* GPIO0 Output value */
144#define AX_GPIO_GPO1EN 0x04 /* GPIO1 Output enable */
145#define AX_GPIO_GPO_1 0x08 /* GPIO1 Output value */
146#define AX_GPIO_GPO2EN 0x10 /* GPIO2 Output enable */
147#define AX_GPIO_GPO_2 0x20 /* GPIO2 Output value */
148#define AX_GPIO_RESERVED 0x40 /* Reserved */
149#define AX_GPIO_RSE 0x80 /* Reload serial EEPROM */
150
151#define AX_EEPROM_MAGIC 0xdeadbeef
152#define AX88172_EEPROM_LEN 0x40
153#define AX88772_EEPROM_LEN 0xff
154
155#define PHY_MODE_MARVELL 0x0000
156#define MII_MARVELL_LED_CTRL 0x0018
157#define MII_MARVELL_STATUS 0x001b
158#define MII_MARVELL_CTRL 0x0014
159
160#define MARVELL_LED_MANUAL 0x0019
161
162#define MARVELL_STATUS_HWCFG 0x0004
163
164#define MARVELL_CTRL_TXDELAY 0x0002
165#define MARVELL_CTRL_RXDELAY 0x0080
108 166
109/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */ 167/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
110struct asix_data { 168struct asix_data {
111 u8 multi_filter[AX_MCAST_FILTER_SIZE]; 169 u8 multi_filter[AX_MCAST_FILTER_SIZE];
170 u8 phymode;
171 u8 ledmode;
172 u8 eeprom_len;
112}; 173};
113 174
114struct ax88172_int_data { 175struct ax88172_int_data {
@@ -122,6 +183,8 @@ struct ax88172_int_data {
122static int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 183static int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
123 u16 size, void *data) 184 u16 size, void *data)
124{ 185{
186 devdbg(dev,"asix_read_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d",
187 cmd, value, index, size);
125 return usb_control_msg( 188 return usb_control_msg(
126 dev->udev, 189 dev->udev,
127 usb_rcvctrlpipe(dev->udev, 0), 190 usb_rcvctrlpipe(dev->udev, 0),
@@ -137,6 +200,8 @@ static int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
137static int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 200static int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
138 u16 size, void *data) 201 u16 size, void *data)
139{ 202{
203 devdbg(dev,"asix_write_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d",
204 cmd, value, index, size);
140 return usb_control_msg( 205 return usb_control_msg(
141 dev->udev, 206 dev->udev,
142 usb_sndctrlpipe(dev->udev, 0), 207 usb_sndctrlpipe(dev->udev, 0),
@@ -161,12 +226,167 @@ static void asix_async_cmd_callback(struct urb *urb, struct pt_regs *regs)
161 usb_free_urb(urb); 226 usb_free_urb(urb);
162} 227}
163 228
229static void
230asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
231 u16 size, void *data)
232{
233 struct usb_ctrlrequest *req;
234 int status;
235 struct urb *urb;
236
237 devdbg(dev,"asix_write_cmd_async() cmd=0x%02x value=0x%04x index=0x%04x size=%d",
238 cmd, value, index, size);
239 if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) {
240 deverr(dev, "Error allocating URB in write_cmd_async!");
241 return;
242 }
243
244 if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) {
245 deverr(dev, "Failed to allocate memory for control request");
246 usb_free_urb(urb);
247 return;
248 }
249
250 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
251 req->bRequest = cmd;
252 req->wValue = value;
253 req->wIndex = index;
254 req->wLength = size;
255
256 usb_fill_control_urb(urb, dev->udev,
257 usb_sndctrlpipe(dev->udev, 0),
258 (void *)req, data, size,
259 asix_async_cmd_callback, req);
260
261 if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
262 deverr(dev, "Error submitting the control message: status=%d",
263 status);
264 kfree(req);
265 usb_free_urb(urb);
266 }
267}
268
269static int asix_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
270{
271 u8 *head;
272 u32 header;
273 char *packet;
274 struct sk_buff *ax_skb;
275 u16 size;
276
277 head = (u8 *) skb->data;
278 memcpy(&header, head, sizeof(header));
279 le32_to_cpus(&header);
280 packet = head + sizeof(header);
281
282 skb_pull(skb, 4);
283
284 while (skb->len > 0) {
285 if ((short)(header & 0x0000ffff) !=
286 ~((short)((header & 0xffff0000) >> 16))) {
287 deverr(dev,"asix_rx_fixup() Bad Header Length");
288 }
289 /* get the packet length */
290 size = (u16) (header & 0x0000ffff);
291
292 if ((skb->len) - ((size + 1) & 0xfffe) == 0)
293 return 2;
294 if (size > ETH_FRAME_LEN) {
295 deverr(dev,"asix_rx_fixup() Bad RX Length %d", size);
296 return 0;
297 }
298 ax_skb = skb_clone(skb, GFP_ATOMIC);
299 if (ax_skb) {
300 ax_skb->len = size;
301 ax_skb->data = packet;
302 ax_skb->tail = packet + size;
303 usbnet_skb_return(dev, ax_skb);
304 } else {
305 return 0;
306 }
307
308 skb_pull(skb, (size + 1) & 0xfffe);
309
310 if (skb->len == 0)
311 break;
312
313 head = (u8 *) skb->data;
314 memcpy(&header, head, sizeof(header));
315 le32_to_cpus(&header);
316 packet = head + sizeof(header);
317 skb_pull(skb, 4);
318 }
319
320 if (skb->len < 0) {
321 deverr(dev,"asix_rx_fixup() Bad SKB Length %d", skb->len);
322 return 0;
323 }
324 return 1;
325}
326
327static struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
328 gfp_t flags)
329{
330 int padlen;
331 int headroom = skb_headroom(skb);
332 int tailroom = skb_tailroom(skb);
333 u32 packet_len;
334 u32 padbytes = 0xffff0000;
335
336 padlen = ((skb->len + 4) % 512) ? 0 : 4;
337
338 if ((!skb_cloned(skb))
339 && ((headroom + tailroom) >= (4 + padlen))) {
340 if ((headroom < 4) || (tailroom < padlen)) {
341 skb->data = memmove(skb->head + 4, skb->data, skb->len);
342 skb->tail = skb->data + skb->len;
343 }
344 } else {
345 struct sk_buff *skb2;
346 skb2 = skb_copy_expand(skb, 4, padlen, flags);
347 dev_kfree_skb_any(skb);
348 skb = skb2;
349 if (!skb)
350 return NULL;
351 }
352
353 skb_push(skb, 4);
354 packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4);
355 memcpy(skb->data, &packet_len, sizeof(packet_len));
356
357 if ((skb->len % 512) == 0) {
358 memcpy( skb->tail, &padbytes, sizeof(padbytes));
359 skb_put(skb, sizeof(padbytes));
360 }
361 return skb;
362}
363
364static void asix_status(struct usbnet *dev, struct urb *urb)
365{
366 struct ax88172_int_data *event;
367 int link;
368
369 if (urb->actual_length < 8)
370 return;
371
372 event = urb->transfer_buffer;
373 link = event->link & 0x01;
374 if (netif_carrier_ok(dev->net) != link) {
375 if (link) {
376 netif_carrier_on(dev->net);
377 usbnet_defer_kevent (dev, EVENT_LINK_RESET );
378 } else
379 netif_carrier_off(dev->net);
380 devdbg(dev, "Link Status is: %d", link);
381 }
382}
383
164static inline int asix_set_sw_mii(struct usbnet *dev) 384static inline int asix_set_sw_mii(struct usbnet *dev)
165{ 385{
166 int ret; 386 int ret;
167 ret = asix_write_cmd(dev, AX_CMD_SET_SW_MII, 0x0000, 0, 0, NULL); 387 ret = asix_write_cmd(dev, AX_CMD_SET_SW_MII, 0x0000, 0, 0, NULL);
168 if (ret < 0) 388 if (ret < 0)
169 devdbg(dev, "Failed to enable software MII access"); 389 deverr(dev, "Failed to enable software MII access");
170 return ret; 390 return ret;
171} 391}
172 392
@@ -175,24 +395,27 @@ static inline int asix_set_hw_mii(struct usbnet *dev)
175 int ret; 395 int ret;
176 ret = asix_write_cmd(dev, AX_CMD_SET_HW_MII, 0x0000, 0, 0, NULL); 396 ret = asix_write_cmd(dev, AX_CMD_SET_HW_MII, 0x0000, 0, 0, NULL);
177 if (ret < 0) 397 if (ret < 0)
178 devdbg(dev, "Failed to enable hardware MII access"); 398 deverr(dev, "Failed to enable hardware MII access");
179 return ret; 399 return ret;
180} 400}
181 401
182static inline int asix_get_phyid(struct usbnet *dev) 402static inline int asix_get_phy_addr(struct usbnet *dev)
183{ 403{
184 int ret = 0; 404 int ret = 0;
185 void *buf; 405 void *buf;
186 406
407 devdbg(dev, "asix_get_phy_addr()");
408
187 buf = kmalloc(2, GFP_KERNEL); 409 buf = kmalloc(2, GFP_KERNEL);
188 if (!buf) 410 if (!buf)
189 goto out1; 411 goto out1;
190 412
191 if ((ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID, 413 if ((ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID,
192 0, 0, 2, buf)) < 2) { 414 0, 0, 2, buf)) < 2) {
193 devdbg(dev, "Error reading PHYID register: %02x", ret); 415 deverr(dev, "Error reading PHYID register: %02x", ret);
194 goto out2; 416 goto out2;
195 } 417 }
418 devdbg(dev, "asix_get_phy_addr() returning 0x%04x", *((u16 *)buf));
196 ret = *((u8 *)buf + 1); 419 ret = *((u8 *)buf + 1);
197out2: 420out2:
198 kfree(buf); 421 kfree(buf);
@@ -206,91 +429,109 @@ static int asix_sw_reset(struct usbnet *dev, u8 flags)
206 429
207 ret = asix_write_cmd(dev, AX_CMD_SW_RESET, flags, 0, 0, NULL); 430 ret = asix_write_cmd(dev, AX_CMD_SW_RESET, flags, 0, 0, NULL);
208 if (ret < 0) 431 if (ret < 0)
209 devdbg(dev,"Failed to send software reset: %02x", ret); 432 deverr(dev,"Failed to send software reset: %02x", ret);
210 433
211 return ret; 434 return ret;
212} 435}
213 436
437static u16 asix_read_rx_ctl(struct usbnet *dev)
438{
439 u16 ret = 0;
440 void *buf;
441
442 buf = kmalloc(2, GFP_KERNEL);
443 if (!buf)
444 goto out1;
445
446 if ((ret = asix_read_cmd(dev, AX_CMD_READ_RX_CTL,
447 0, 0, 2, buf)) < 2) {
448 deverr(dev, "Error reading RX_CTL register: %02x", ret);
449 goto out2;
450 }
451 ret = le16_to_cpu(*((u16 *)buf));
452out2:
453 kfree(buf);
454out1:
455 return ret;
456}
457
214static int asix_write_rx_ctl(struct usbnet *dev, u16 mode) 458static int asix_write_rx_ctl(struct usbnet *dev, u16 mode)
215{ 459{
216 int ret; 460 int ret;
217 461
462 devdbg(dev,"asix_write_rx_ctl() - mode = 0x%04x", mode);
218 ret = asix_write_cmd(dev, AX_CMD_WRITE_RX_CTL, mode, 0, 0, NULL); 463 ret = asix_write_cmd(dev, AX_CMD_WRITE_RX_CTL, mode, 0, 0, NULL);
219 if (ret < 0) 464 if (ret < 0)
220 devdbg(dev, "Failed to write RX_CTL mode: %02x", ret); 465 deverr(dev, "Failed to write RX_CTL mode to 0x%04x: %02x",
466 mode, ret);
221 467
222 return ret; 468 return ret;
223} 469}
224 470
225static void asix_status(struct usbnet *dev, struct urb *urb) 471static u16 asix_read_medium_status(struct usbnet *dev)
226{ 472{
227 struct ax88172_int_data *event; 473 u16 ret = 0;
228 int link; 474 void *buf;
229 475
230 if (urb->actual_length < 8) 476 buf = kmalloc(2, GFP_KERNEL);
231 return; 477 if (!buf)
478 goto out1;
232 479
233 event = urb->transfer_buffer; 480 if ((ret = asix_read_cmd(dev, AX_CMD_READ_MEDIUM_STATUS,
234 link = event->link & 0x01; 481 0, 0, 2, buf)) < 2) {
235 if (netif_carrier_ok(dev->net) != link) { 482 deverr(dev, "Error reading Medium Status register: %02x", ret);
236 if (link) { 483 goto out2;
237 netif_carrier_on(dev->net);
238 usbnet_defer_kevent (dev, EVENT_LINK_RESET );
239 } else
240 netif_carrier_off(dev->net);
241 devdbg(dev, "Link Status is: %d", link);
242 } 484 }
485 ret = le16_to_cpu(*((u16 *)buf));
486out2:
487 kfree(buf);
488out1:
489 return ret;
243} 490}
244 491
245static void 492static int asix_write_medium_mode(struct usbnet *dev, u16 mode)
246asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
247 u16 size, void *data)
248{ 493{
249 struct usb_ctrlrequest *req; 494 int ret;
250 int status;
251 struct urb *urb;
252 495
253 if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) { 496 devdbg(dev,"asix_write_medium_mode() - mode = 0x%04x", mode);
254 devdbg(dev, "Error allocating URB in write_cmd_async!"); 497 ret = asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
255 return; 498 if (ret < 0)
256 } 499 deverr(dev, "Failed to write Medium Mode mode to 0x%04x: %02x",
500 mode, ret);
257 501
258 if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) { 502 return ret;
259 deverr(dev, "Failed to allocate memory for control request"); 503}
260 usb_free_urb(urb);
261 return;
262 }
263 504
264 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE; 505static int asix_write_gpio(struct usbnet *dev, u16 value, int sleep)
265 req->bRequest = cmd; 506{
266 req->wValue = cpu_to_le16(value); 507 int ret;
267 req->wIndex = cpu_to_le16(index);
268 req->wLength = cpu_to_le16(size);
269 508
270 usb_fill_control_urb(urb, dev->udev, 509 devdbg(dev,"asix_write_gpio() - value = 0x%04x", value);
271 usb_sndctrlpipe(dev->udev, 0), 510 ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS, value, 0, 0, NULL);
272 (void *)req, data, size, 511 if (ret < 0)
273 asix_async_cmd_callback, req); 512 deverr(dev, "Failed to write GPIO value 0x%04x: %02x",
513 value, ret);
274 514
275 if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { 515 if (sleep)
276 deverr(dev, "Error submitting the control message: status=%d", 516 msleep(sleep);
277 status); 517
278 kfree(req); 518 return ret;
279 usb_free_urb(urb);
280 }
281} 519}
282 520
521/*
522 * AX88772 & AX88178 have a 16-bit RX_CTL value
523 */
283static void asix_set_multicast(struct net_device *net) 524static void asix_set_multicast(struct net_device *net)
284{ 525{
285 struct usbnet *dev = netdev_priv(net); 526 struct usbnet *dev = netdev_priv(net);
286 struct asix_data *data = (struct asix_data *)&dev->data; 527 struct asix_data *data = (struct asix_data *)&dev->data;
287 u8 rx_ctl = 0x8c; 528 u16 rx_ctl = AX_DEFAULT_RX_CTL;
288 529
289 if (net->flags & IFF_PROMISC) { 530 if (net->flags & IFF_PROMISC) {
290 rx_ctl |= 0x01; 531 rx_ctl |= AX_RX_CTL_PRO;
291 } else if (net->flags & IFF_ALLMULTI 532 } else if (net->flags & IFF_ALLMULTI
292 || net->mc_count > AX_MAX_MCAST) { 533 || net->mc_count > AX_MAX_MCAST) {
293 rx_ctl |= 0x02; 534 rx_ctl |= AX_RX_CTL_AMALL;
294 } else if (net->mc_count == 0) { 535 } else if (net->mc_count == 0) {
295 /* just broadcast and directed */ 536 /* just broadcast and directed */
296 } else { 537 } else {
@@ -317,7 +558,7 @@ static void asix_set_multicast(struct net_device *net)
317 asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0, 558 asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
318 AX_MCAST_FILTER_SIZE, data->multi_filter); 559 AX_MCAST_FILTER_SIZE, data->multi_filter);
319 560
320 rx_ctl |= 0x10; 561 rx_ctl |= AX_RX_CTL_AM;
321 } 562 }
322 563
323 asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL); 564 asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
@@ -333,50 +574,43 @@ static int asix_mdio_read(struct net_device *netdev, int phy_id, int loc)
333 (__u16)loc, 2, (u16 *)&res); 574 (__u16)loc, 2, (u16 *)&res);
334 asix_set_hw_mii(dev); 575 asix_set_hw_mii(dev);
335 576
336 return res & 0xffff; 577 devdbg(dev, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x", phy_id, loc, le16_to_cpu(res & 0xffff));
337}
338 578
339/* same as above, but converts resulting value to cpu byte order */ 579 return le16_to_cpu(res & 0xffff);
340static int asix_mdio_read_le(struct net_device *netdev, int phy_id, int loc)
341{
342 return le16_to_cpu(asix_mdio_read(netdev,phy_id, loc));
343} 580}
344 581
345static void 582static void
346asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val) 583asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
347{ 584{
348 struct usbnet *dev = netdev_priv(netdev); 585 struct usbnet *dev = netdev_priv(netdev);
349 u16 res = val; 586 u16 res = cpu_to_le16(val);
350 587
588 devdbg(dev, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x", phy_id, loc, val);
351 asix_set_sw_mii(dev); 589 asix_set_sw_mii(dev);
352 asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, 590 asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id,
353 (__u16)loc, 2, (u16 *)&res); 591 (__u16)loc, 2, (u16 *)&res);
354 asix_set_hw_mii(dev); 592 asix_set_hw_mii(dev);
355} 593}
356 594
357/* same as above, but converts new value to le16 byte order before writing */ 595/* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */
358static void 596static u32 asix_get_phyid(struct usbnet *dev)
359asix_mdio_write_le(struct net_device *netdev, int phy_id, int loc, int val)
360{ 597{
361 asix_mdio_write( netdev, phy_id, loc, cpu_to_le16(val) ); 598 int phy_reg;
362} 599 u32 phy_id;
363 600
364static int ax88172_link_reset(struct usbnet *dev) 601 phy_reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID1);
365{ 602 if (phy_reg < 0)
366 u16 lpa; 603 return 0;
367 u16 adv;
368 u16 res;
369 u8 mode;
370 604
371 mode = AX_MEDIUM_TX_ABORT_ALLOW | AX_MEDIUM_FLOW_CONTROL_EN; 605 phy_id = (phy_reg & 0xffff) << 16;
372 lpa = asix_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA);
373 adv = asix_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE);
374 res = mii_nway_result(lpa|adv);
375 if (res & LPA_DUPLEX)
376 mode |= AX_MEDIUM_FULL_DUPLEX;
377 asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
378 606
379 return 0; 607 phy_reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID2);
608 if (phy_reg < 0)
609 return 0;
610
611 phy_id |= (phy_reg & 0xffff);
612
613 return phy_id;
380} 614}
381 615
382static void 616static void
@@ -423,7 +657,10 @@ asix_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
423 657
424static int asix_get_eeprom_len(struct net_device *net) 658static int asix_get_eeprom_len(struct net_device *net)
425{ 659{
426 return AX_EEPROM_LEN; 660 struct usbnet *dev = netdev_priv(net);
661 struct asix_data *data = (struct asix_data *)&dev->data;
662
663 return data->eeprom_len;
427} 664}
428 665
429static int asix_get_eeprom(struct net_device *net, 666static int asix_get_eeprom(struct net_device *net,
@@ -453,9 +690,14 @@ static int asix_get_eeprom(struct net_device *net,
453static void asix_get_drvinfo (struct net_device *net, 690static void asix_get_drvinfo (struct net_device *net,
454 struct ethtool_drvinfo *info) 691 struct ethtool_drvinfo *info)
455{ 692{
693 struct usbnet *dev = netdev_priv(net);
694 struct asix_data *data = (struct asix_data *)&dev->data;
695
456 /* Inherit standard device info */ 696 /* Inherit standard device info */
457 usbnet_get_drvinfo(net, info); 697 usbnet_get_drvinfo(net, info);
458 info->eedump_len = 0x3e; 698 strncpy (info->driver, driver_name, sizeof info->driver);
699 strncpy (info->version, DRIVER_VERSION, sizeof info->version);
700 info->eedump_len = data->eeprom_len;
459} 701}
460 702
461static int asix_get_settings(struct net_device *net, struct ethtool_cmd *cmd) 703static int asix_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
@@ -468,8 +710,34 @@ static int asix_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
468static int asix_set_settings(struct net_device *net, struct ethtool_cmd *cmd) 710static int asix_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
469{ 711{
470 struct usbnet *dev = netdev_priv(net); 712 struct usbnet *dev = netdev_priv(net);
713 int res = mii_ethtool_sset(&dev->mii,cmd);
714
715 /* link speed/duplex might have changed */
716 if (dev->driver_info->link_reset)
717 dev->driver_info->link_reset(dev);
718
719 return res;
720}
721
722static int asix_nway_reset(struct net_device *net)
723{
724 struct usbnet *dev = netdev_priv(net);
725
726 return mii_nway_restart(&dev->mii);
727}
728
729static u32 asix_get_link(struct net_device *net)
730{
731 struct usbnet *dev = netdev_priv(net);
471 732
472 return mii_ethtool_sset(&dev->mii,cmd); 733 return mii_link_ok(&dev->mii);
734}
735
736static int asix_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
737{
738 struct usbnet *dev = netdev_priv(net);
739
740 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
473} 741}
474 742
475/* We need to override some ethtool_ops so we require our 743/* We need to override some ethtool_ops so we require our
@@ -477,7 +745,8 @@ static int asix_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
477 devices that may be connected at the same time. */ 745 devices that may be connected at the same time. */
478static struct ethtool_ops ax88172_ethtool_ops = { 746static struct ethtool_ops ax88172_ethtool_ops = {
479 .get_drvinfo = asix_get_drvinfo, 747 .get_drvinfo = asix_get_drvinfo,
480 .get_link = ethtool_op_get_link, 748 .get_link = asix_get_link,
749 .nway_reset = asix_nway_reset,
481 .get_msglevel = usbnet_get_msglevel, 750 .get_msglevel = usbnet_get_msglevel,
482 .set_msglevel = usbnet_set_msglevel, 751 .set_msglevel = usbnet_set_msglevel,
483 .get_wol = asix_get_wol, 752 .get_wol = asix_get_wol,
@@ -488,11 +757,66 @@ static struct ethtool_ops ax88172_ethtool_ops = {
488 .set_settings = asix_set_settings, 757 .set_settings = asix_set_settings,
489}; 758};
490 759
491static int asix_ioctl (struct net_device *net, struct ifreq *rq, int cmd) 760static void ax88172_set_multicast(struct net_device *net)
492{ 761{
493 struct usbnet *dev = netdev_priv(net); 762 struct usbnet *dev = netdev_priv(net);
763 struct asix_data *data = (struct asix_data *)&dev->data;
764 u8 rx_ctl = 0x8c;
494 765
495 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); 766 if (net->flags & IFF_PROMISC) {
767 rx_ctl |= 0x01;
768 } else if (net->flags & IFF_ALLMULTI
769 || net->mc_count > AX_MAX_MCAST) {
770 rx_ctl |= 0x02;
771 } else if (net->mc_count == 0) {
772 /* just broadcast and directed */
773 } else {
774 /* We use the 20 byte dev->data
775 * for our 8 byte filter buffer
776 * to avoid allocating memory that
777 * is tricky to free later */
778 struct dev_mc_list *mc_list = net->mc_list;
779 u32 crc_bits;
780 int i;
781
782 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
783
784 /* Build the multicast hash filter. */
785 for (i = 0; i < net->mc_count; i++) {
786 crc_bits =
787 ether_crc(ETH_ALEN,
788 mc_list->dmi_addr) >> 26;
789 data->multi_filter[crc_bits >> 3] |=
790 1 << (crc_bits & 7);
791 mc_list = mc_list->next;
792 }
793
794 asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
795 AX_MCAST_FILTER_SIZE, data->multi_filter);
796
797 rx_ctl |= 0x10;
798 }
799
800 asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
801}
802
803static int ax88172_link_reset(struct usbnet *dev)
804{
805 u8 mode;
806 struct ethtool_cmd ecmd;
807
808 mii_check_media(&dev->mii, 1, 1);
809 mii_ethtool_gset(&dev->mii, &ecmd);
810 mode = AX88172_MEDIUM_DEFAULT;
811
812 if (ecmd.duplex != DUPLEX_FULL)
813 mode |= ~AX88172_MEDIUM_FD;
814
815 devdbg(dev, "ax88172_link_reset() speed: %d duplex: %d setting mode to 0x%04x", ecmd.speed, ecmd.duplex, mode);
816
817 asix_write_medium_mode(dev, mode);
818
819 return 0;
496} 820}
497 821
498static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf) 822static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
@@ -501,6 +825,9 @@ static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
501 void *buf; 825 void *buf;
502 int i; 826 int i;
503 unsigned long gpio_bits = dev->driver_info->data; 827 unsigned long gpio_bits = dev->driver_info->data;
828 struct asix_data *data = (struct asix_data *)&dev->data;
829
830 data->eeprom_len = AX88172_EEPROM_LEN;
504 831
505 usbnet_get_endpoints(dev,intf); 832 usbnet_get_endpoints(dev,intf);
506 833
@@ -519,12 +846,12 @@ static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
519 msleep(5); 846 msleep(5);
520 } 847 }
521 848
522 if ((ret = asix_write_rx_ctl(dev,0x80)) < 0) 849 if ((ret = asix_write_rx_ctl(dev, 0x80)) < 0)
523 goto out2; 850 goto out2;
524 851
525 /* Get the MAC address */ 852 /* Get the MAC address */
526 memset(buf, 0, ETH_ALEN); 853 memset(buf, 0, ETH_ALEN);
527 if ((ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 854 if ((ret = asix_read_cmd(dev, AX88172_CMD_READ_NODE_ID,
528 0, 0, 6, buf)) < 0) { 855 0, 0, 6, buf)) < 0) {
529 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret); 856 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
530 goto out2; 857 goto out2;
@@ -537,14 +864,14 @@ static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
537 dev->mii.mdio_write = asix_mdio_write; 864 dev->mii.mdio_write = asix_mdio_write;
538 dev->mii.phy_id_mask = 0x3f; 865 dev->mii.phy_id_mask = 0x3f;
539 dev->mii.reg_num_mask = 0x1f; 866 dev->mii.reg_num_mask = 0x1f;
540 dev->mii.phy_id = asix_get_phyid(dev); 867 dev->mii.phy_id = asix_get_phy_addr(dev);
541 dev->net->do_ioctl = asix_ioctl; 868 dev->net->do_ioctl = asix_ioctl;
542 869
543 dev->net->set_multicast_list = asix_set_multicast; 870 dev->net->set_multicast_list = ax88172_set_multicast;
544 dev->net->ethtool_ops = &ax88172_ethtool_ops; 871 dev->net->ethtool_ops = &ax88172_ethtool_ops;
545 872
546 asix_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); 873 asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
547 asix_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE, 874 asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
548 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); 875 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
549 mii_nway_restart(&dev->mii); 876 mii_nway_restart(&dev->mii);
550 877
@@ -557,7 +884,8 @@ out1:
557 884
558static struct ethtool_ops ax88772_ethtool_ops = { 885static struct ethtool_ops ax88772_ethtool_ops = {
559 .get_drvinfo = asix_get_drvinfo, 886 .get_drvinfo = asix_get_drvinfo,
560 .get_link = ethtool_op_get_link, 887 .get_link = asix_get_link,
888 .nway_reset = asix_nway_reset,
561 .get_msglevel = usbnet_get_msglevel, 889 .get_msglevel = usbnet_get_msglevel,
562 .set_msglevel = usbnet_set_msglevel, 890 .set_msglevel = usbnet_set_msglevel,
563 .get_wol = asix_get_wol, 891 .get_wol = asix_get_wol,
@@ -568,10 +896,37 @@ static struct ethtool_ops ax88772_ethtool_ops = {
568 .set_settings = asix_set_settings, 896 .set_settings = asix_set_settings,
569}; 897};
570 898
899static int ax88772_link_reset(struct usbnet *dev)
900{
901 u16 mode;
902 struct ethtool_cmd ecmd;
903
904 mii_check_media(&dev->mii, 1, 1);
905 mii_ethtool_gset(&dev->mii, &ecmd);
906 mode = AX88772_MEDIUM_DEFAULT;
907
908 if (ecmd.speed != SPEED_100)
909 mode &= ~AX_MEDIUM_PS;
910
911 if (ecmd.duplex != DUPLEX_FULL)
912 mode &= ~AX_MEDIUM_FD;
913
914 devdbg(dev, "ax88772_link_reset() speed: %d duplex: %d setting mode to 0x%04x", ecmd.speed, ecmd.duplex, mode);
915
916 asix_write_medium_mode(dev, mode);
917
918 return 0;
919}
920
571static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) 921static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
572{ 922{
573 int ret; 923 int ret;
574 void *buf; 924 void *buf;
925 u16 rx_ctl;
926 struct asix_data *data = (struct asix_data *)&dev->data;
927 u32 phyid;
928
929 data->eeprom_len = AX88772_EEPROM_LEN;
575 930
576 usbnet_get_endpoints(dev,intf); 931 usbnet_get_endpoints(dev,intf);
577 932
@@ -582,13 +937,12 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
582 goto out1; 937 goto out1;
583 } 938 }
584 939
585 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS, 940 if ((ret = asix_write_gpio(dev,
586 0x00B0, 0, 0, buf)) < 0) 941 AX_GPIO_RSE | AX_GPIO_GPO_2 | AX_GPIO_GPO2EN, 5)) < 0)
587 goto out2; 942 goto out2;
588 943
589 msleep(5);
590 if ((ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 944 if ((ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT,
591 0x0001, 0, 0, buf)) < 0) { 945 0x0000, 0, 0, buf)) < 0) {
592 dbg("Select PHY #1 failed: %d", ret); 946 dbg("Select PHY #1 failed: %d", ret);
593 goto out2; 947 goto out2;
594 } 948 }
@@ -605,36 +959,34 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
605 goto out2; 959 goto out2;
606 960
607 msleep(150); 961 msleep(150);
608 if ((ret = asix_write_rx_ctl(dev, 0x00)) < 0) 962 rx_ctl = asix_read_rx_ctl(dev);
963 dbg("RX_CTL is 0x%04x after software reset", rx_ctl);
964 if ((ret = asix_write_rx_ctl(dev, 0x0000)) < 0)
609 goto out2; 965 goto out2;
610 966
967 rx_ctl = asix_read_rx_ctl(dev);
968 dbg("RX_CTL is 0x%04x setting to 0x0000", rx_ctl);
969
611 /* Get the MAC address */ 970 /* Get the MAC address */
612 memset(buf, 0, ETH_ALEN); 971 memset(buf, 0, ETH_ALEN);
613 if ((ret = asix_read_cmd(dev, AX88772_CMD_READ_NODE_ID, 972 if ((ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
614 0, 0, ETH_ALEN, buf)) < 0) { 973 0, 0, ETH_ALEN, buf)) < 0) {
615 dbg("Failed to read MAC address: %d", ret); 974 dbg("Failed to read MAC address: %d", ret);
616 goto out2; 975 goto out2;
617 } 976 }
618 memcpy(dev->net->dev_addr, buf, ETH_ALEN); 977 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
619 978
620 if ((ret = asix_set_sw_mii(dev)) < 0)
621 goto out2;
622
623 if (((ret = asix_read_cmd(dev, AX_CMD_READ_MII_REG,
624 0x0010, 2, 2, buf)) < 0)
625 || (*((u16 *)buf) != 0x003b)) {
626 dbg("Read PHY register 2 must be 0x3b00: %d", ret);
627 goto out2;
628 }
629
630 /* Initialize MII structure */ 979 /* Initialize MII structure */
631 dev->mii.dev = dev->net; 980 dev->mii.dev = dev->net;
632 dev->mii.mdio_read = asix_mdio_read; 981 dev->mii.mdio_read = asix_mdio_read;
633 dev->mii.mdio_write = asix_mdio_write; 982 dev->mii.mdio_write = asix_mdio_write;
634 dev->mii.phy_id_mask = 0xff; 983 dev->mii.phy_id_mask = 0x1f;
635 dev->mii.reg_num_mask = 0xff; 984 dev->mii.reg_num_mask = 0x1f;
636 dev->net->do_ioctl = asix_ioctl; 985 dev->net->do_ioctl = asix_ioctl;
637 dev->mii.phy_id = asix_get_phyid(dev); 986 dev->mii.phy_id = asix_get_phy_addr(dev);
987
988 phyid = asix_get_phyid(dev);
989 dbg("PHYID=0x%08x", phyid);
638 990
639 if ((ret = asix_sw_reset(dev, AX_SWRESET_PRL)) < 0) 991 if ((ret = asix_sw_reset(dev, AX_SWRESET_PRL)) < 0)
640 goto out2; 992 goto out2;
@@ -649,16 +1001,13 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
649 dev->net->set_multicast_list = asix_set_multicast; 1001 dev->net->set_multicast_list = asix_set_multicast;
650 dev->net->ethtool_ops = &ax88772_ethtool_ops; 1002 dev->net->ethtool_ops = &ax88772_ethtool_ops;
651 1003
652 asix_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); 1004 asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
653 asix_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE, 1005 asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
654 ADVERTISE_ALL | ADVERTISE_CSMA); 1006 ADVERTISE_ALL | ADVERTISE_CSMA);
655 mii_nway_restart(&dev->mii); 1007 mii_nway_restart(&dev->mii);
656 1008
657 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, 1009 if ((ret = asix_write_medium_mode(dev, AX88772_MEDIUM_DEFAULT)) < 0)
658 AX88772_MEDIUM_DEFAULT, 0, 0, buf)) < 0) {
659 dbg("Write medium mode register: %d", ret);
660 goto out2; 1010 goto out2;
661 }
662 1011
663 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0, 1012 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
664 AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT, 1013 AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
@@ -666,13 +1015,17 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
666 dbg("Write IPG,IPG1,IPG2 failed: %d", ret); 1015 dbg("Write IPG,IPG1,IPG2 failed: %d", ret);
667 goto out2; 1016 goto out2;
668 } 1017 }
669 if ((ret = asix_set_hw_mii(dev)) < 0)
670 goto out2;
671 1018
672 /* Set RX_CTL to default values with 2k buffer, and enable cactus */ 1019 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
673 if ((ret = asix_write_rx_ctl(dev, 0x0088)) < 0) 1020 if ((ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL)) < 0)
674 goto out2; 1021 goto out2;
675 1022
1023 rx_ctl = asix_read_rx_ctl(dev);
1024 dbg("RX_CTL is 0x%04x after all initializations", rx_ctl);
1025
1026 rx_ctl = asix_read_medium_status(dev);
1027 dbg("Medium Status is 0x%04x after all initializations", rx_ctl);
1028
676 kfree(buf); 1029 kfree(buf);
677 1030
678 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */ 1031 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
@@ -690,120 +1043,285 @@ out1:
690 return ret; 1043 return ret;
691} 1044}
692 1045
693static int ax88772_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 1046static struct ethtool_ops ax88178_ethtool_ops = {
1047 .get_drvinfo = asix_get_drvinfo,
1048 .get_link = asix_get_link,
1049 .nway_reset = asix_nway_reset,
1050 .get_msglevel = usbnet_get_msglevel,
1051 .set_msglevel = usbnet_set_msglevel,
1052 .get_wol = asix_get_wol,
1053 .set_wol = asix_set_wol,
1054 .get_eeprom_len = asix_get_eeprom_len,
1055 .get_eeprom = asix_get_eeprom,
1056 .get_settings = asix_get_settings,
1057 .set_settings = asix_set_settings,
1058};
1059
1060static int marvell_phy_init(struct usbnet *dev)
694{ 1061{
695 u8 *head; 1062 struct asix_data *data = (struct asix_data *)&dev->data;
696 u32 header; 1063 u16 reg;
697 char *packet;
698 struct sk_buff *ax_skb;
699 u16 size;
700 1064
701 head = (u8 *) skb->data; 1065 devdbg(dev,"marvell_phy_init()");
702 memcpy(&header, head, sizeof(header));
703 le32_to_cpus(&header);
704 packet = head + sizeof(header);
705 1066
706 skb_pull(skb, 4); 1067 reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_MARVELL_STATUS);
1068 devdbg(dev,"MII_MARVELL_STATUS = 0x%04x", reg);
707 1069
708 while (skb->len > 0) { 1070 asix_mdio_write(dev->net, dev->mii.phy_id, MII_MARVELL_CTRL,
709 if ((short)(header & 0x0000ffff) != 1071 MARVELL_CTRL_RXDELAY | MARVELL_CTRL_TXDELAY);
710 ~((short)((header & 0xffff0000) >> 16))) {
711 devdbg(dev,"header length data is error");
712 }
713 /* get the packet length */
714 size = (u16) (header & 0x0000ffff);
715 1072
716 if ((skb->len) - ((size + 1) & 0xfffe) == 0) 1073 if (data->ledmode) {
717 return 2; 1074 reg = asix_mdio_read(dev->net, dev->mii.phy_id,
718 if (size > ETH_FRAME_LEN) { 1075 MII_MARVELL_LED_CTRL);
719 devdbg(dev,"invalid rx length %d", size); 1076 devdbg(dev,"MII_MARVELL_LED_CTRL (1) = 0x%04x", reg);
720 return 0;
721 }
722 ax_skb = skb_clone(skb, GFP_ATOMIC);
723 if (ax_skb) {
724 ax_skb->len = size;
725 ax_skb->data = packet;
726 ax_skb->tail = packet + size;
727 usbnet_skb_return(dev, ax_skb);
728 } else {
729 return 0;
730 }
731 1077
732 skb_pull(skb, (size + 1) & 0xfffe); 1078 reg &= 0xf8ff;
1079 reg |= (1 + 0x0100);
1080 asix_mdio_write(dev->net, dev->mii.phy_id,
1081 MII_MARVELL_LED_CTRL, reg);
733 1082
734 if (skb->len == 0) 1083 reg = asix_mdio_read(dev->net, dev->mii.phy_id,
735 break; 1084 MII_MARVELL_LED_CTRL);
1085 devdbg(dev,"MII_MARVELL_LED_CTRL (2) = 0x%04x", reg);
1086 reg &= 0xfc0f;
1087 }
736 1088
737 head = (u8 *) skb->data; 1089 return 0;
738 memcpy(&header, head, sizeof(header)); 1090}
739 le32_to_cpus(&header); 1091
740 packet = head + sizeof(header); 1092static int marvell_led_status(struct usbnet *dev, u16 speed)
741 skb_pull(skb, 4); 1093{
1094 u16 reg = asix_mdio_read(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL);
1095
1096 devdbg(dev, "marvell_led_status() read 0x%04x", reg);
1097
1098 /* Clear out the center LED bits - 0x03F0 */
1099 reg &= 0xfc0f;
1100
1101 switch (speed) {
1102 case SPEED_1000:
1103 reg |= 0x03e0;
1104 break;
1105 case SPEED_100:
1106 reg |= 0x03b0;
1107 break;
1108 default:
1109 reg |= 0x02f0;
742 } 1110 }
743 1111
744 if (skb->len < 0) { 1112 devdbg(dev, "marvell_led_status() writing 0x%04x", reg);
745 devdbg(dev,"invalid rx length %d", skb->len); 1113 asix_mdio_write(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL, reg);
746 return 0; 1114
1115 return 0;
1116}
1117
1118static int ax88178_link_reset(struct usbnet *dev)
1119{
1120 u16 mode;
1121 struct ethtool_cmd ecmd;
1122 struct asix_data *data = (struct asix_data *)&dev->data;
1123
1124 devdbg(dev,"ax88178_link_reset()");
1125
1126 mii_check_media(&dev->mii, 1, 1);
1127 mii_ethtool_gset(&dev->mii, &ecmd);
1128 mode = AX88178_MEDIUM_DEFAULT;
1129
1130 if (ecmd.speed == SPEED_1000)
1131 mode |= AX_MEDIUM_GM | AX_MEDIUM_ENCK;
1132 else if (ecmd.speed == SPEED_100)
1133 mode |= AX_MEDIUM_PS;
1134 else
1135 mode &= ~(AX_MEDIUM_PS | AX_MEDIUM_GM);
1136
1137 if (ecmd.duplex == DUPLEX_FULL)
1138 mode |= AX_MEDIUM_FD;
1139 else
1140 mode &= ~AX_MEDIUM_FD;
1141
1142 devdbg(dev, "ax88178_link_reset() speed: %d duplex: %d setting mode to 0x%04x", ecmd.speed, ecmd.duplex, mode);
1143
1144 asix_write_medium_mode(dev, mode);
1145
1146 if (data->phymode == PHY_MODE_MARVELL && data->ledmode)
1147 marvell_led_status(dev, ecmd.speed);
1148
1149 return 0;
1150}
1151
1152static void ax88178_set_mfb(struct usbnet *dev)
1153{
1154 u16 mfb = AX_RX_CTL_MFB_16384;
1155 u16 rxctl;
1156 u16 medium;
1157 int old_rx_urb_size = dev->rx_urb_size;
1158
1159 if (dev->hard_mtu < 2048) {
1160 dev->rx_urb_size = 2048;
1161 mfb = AX_RX_CTL_MFB_2048;
1162 } else if (dev->hard_mtu < 4096) {
1163 dev->rx_urb_size = 4096;
1164 mfb = AX_RX_CTL_MFB_4096;
1165 } else if (dev->hard_mtu < 8192) {
1166 dev->rx_urb_size = 8192;
1167 mfb = AX_RX_CTL_MFB_8192;
1168 } else if (dev->hard_mtu < 16384) {
1169 dev->rx_urb_size = 16384;
1170 mfb = AX_RX_CTL_MFB_16384;
747 } 1171 }
748 return 1; 1172
1173 rxctl = asix_read_rx_ctl(dev);
1174 asix_write_rx_ctl(dev, (rxctl & ~AX_RX_CTL_MFB_16384) | mfb);
1175
1176 medium = asix_read_medium_status(dev);
1177 if (dev->net->mtu > 1500)
1178 medium |= AX_MEDIUM_JFE;
1179 else
1180 medium &= ~AX_MEDIUM_JFE;
1181 asix_write_medium_mode(dev, medium);
1182
1183 if (dev->rx_urb_size > old_rx_urb_size)
1184 usbnet_unlink_rx_urbs(dev);
749} 1185}
750 1186
751static struct sk_buff *ax88772_tx_fixup(struct usbnet *dev, struct sk_buff *skb, 1187static int ax88178_change_mtu(struct net_device *net, int new_mtu)
752 gfp_t flags)
753{ 1188{
754 int padlen; 1189 struct usbnet *dev = netdev_priv(net);
755 int headroom = skb_headroom(skb); 1190 int ll_mtu = new_mtu + net->hard_header_len + 4;
756 int tailroom = skb_tailroom(skb);
757 u32 packet_len;
758 u32 padbytes = 0xffff0000;
759 1191
760 padlen = ((skb->len + 4) % 512) ? 0 : 4; 1192 devdbg(dev, "ax88178_change_mtu() new_mtu=%d", new_mtu);
761 1193
762 if ((!skb_cloned(skb)) 1194 if (new_mtu <= 0 || ll_mtu > 16384)
763 && ((headroom + tailroom) >= (4 + padlen))) { 1195 return -EINVAL;
764 if ((headroom < 4) || (tailroom < padlen)) { 1196
765 skb->data = memmove(skb->head + 4, skb->data, skb->len); 1197 if ((ll_mtu % dev->maxpacket) == 0)
766 skb->tail = skb->data + skb->len; 1198 return -EDOM;
767 } 1199
1200 net->mtu = new_mtu;
1201 dev->hard_mtu = net->mtu + net->hard_header_len;
1202 ax88178_set_mfb(dev);
1203
1204 return 0;
1205}
1206
1207static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
1208{
1209 struct asix_data *data = (struct asix_data *)&dev->data;
1210 int ret;
1211 void *buf;
1212 u16 eeprom;
1213 int gpio0 = 0;
1214 u32 phyid;
1215
1216 usbnet_get_endpoints(dev,intf);
1217
1218 buf = kmalloc(6, GFP_KERNEL);
1219 if(!buf) {
1220 dbg ("Cannot allocate memory for buffer");
1221 ret = -ENOMEM;
1222 goto out1;
1223 }
1224
1225 eeprom = 0;
1226 asix_read_cmd(dev, AX_CMD_READ_GPIOS, 0, 0, 1, &eeprom);
1227 dbg("GPIO Status: 0x%04x", eeprom);
1228
1229 asix_write_cmd(dev, AX_CMD_WRITE_ENABLE, 0, 0, 0, NULL);
1230 asix_read_cmd(dev, AX_CMD_READ_EEPROM, 0x0017, 0, 2, &eeprom);
1231 asix_write_cmd(dev, AX_CMD_WRITE_DISABLE, 0, 0, 0, NULL);
1232
1233 dbg("EEPROM index 0x17 is 0x%04x", eeprom);
1234
1235 if (eeprom == 0xffff) {
1236 data->phymode = PHY_MODE_MARVELL;
1237 data->ledmode = 0;
1238 gpio0 = 1;
768 } else { 1239 } else {
769 struct sk_buff *skb2; 1240 data->phymode = eeprom & 7;
770 skb2 = skb_copy_expand(skb, 4, padlen, flags); 1241 data->ledmode = eeprom >> 8;
771 dev_kfree_skb_any(skb); 1242 gpio0 = (eeprom & 0x80) ? 0 : 1;
772 skb = skb2;
773 if (!skb)
774 return NULL;
775 } 1243 }
1244 dbg("GPIO0: %d, PhyMode: %d", gpio0, data->phymode);
776 1245
777 skb_push(skb, 4); 1246 asix_write_gpio(dev, AX_GPIO_RSE | AX_GPIO_GPO_1 | AX_GPIO_GPO1EN, 40);
778 packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4); 1247 if ((eeprom >> 8) != 1) {
779 memcpy(skb->data, &packet_len, sizeof(packet_len)); 1248 asix_write_gpio(dev, 0x003c, 30);
1249 asix_write_gpio(dev, 0x001c, 300);
1250 asix_write_gpio(dev, 0x003c, 30);
1251 } else {
1252 dbg("gpio phymode == 1 path");
1253 asix_write_gpio(dev, AX_GPIO_GPO1EN, 30);
1254 asix_write_gpio(dev, AX_GPIO_GPO1EN | AX_GPIO_GPO_1, 30);
1255 }
780 1256
781 if ((skb->len % 512) == 0) { 1257 asix_sw_reset(dev, 0);
782 memcpy( skb->tail, &padbytes, sizeof(padbytes)); 1258 msleep(150);
783 skb_put(skb, sizeof(padbytes)); 1259
1260 asix_sw_reset(dev, AX_SWRESET_PRL | AX_SWRESET_IPPD);
1261 msleep(150);
1262
1263 asix_write_rx_ctl(dev, 0);
1264
1265 /* Get the MAC address */
1266 memset(buf, 0, ETH_ALEN);
1267 if ((ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
1268 0, 0, ETH_ALEN, buf)) < 0) {
1269 dbg("Failed to read MAC address: %d", ret);
1270 goto out2;
784 } 1271 }
785 return skb; 1272 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
786}
787 1273
788static int ax88772_link_reset(struct usbnet *dev) 1274 /* Initialize MII structure */
789{ 1275 dev->mii.dev = dev->net;
790 u16 lpa; 1276 dev->mii.mdio_read = asix_mdio_read;
791 u16 adv; 1277 dev->mii.mdio_write = asix_mdio_write;
792 u16 res; 1278 dev->mii.phy_id_mask = 0x1f;
793 u16 mode; 1279 dev->mii.reg_num_mask = 0xff;
1280 dev->mii.supports_gmii = 1;
1281 dev->net->do_ioctl = asix_ioctl;
1282 dev->mii.phy_id = asix_get_phy_addr(dev);
1283 dev->net->set_multicast_list = asix_set_multicast;
1284 dev->net->ethtool_ops = &ax88178_ethtool_ops;
1285 dev->net->change_mtu = &ax88178_change_mtu;
794 1286
795 mode = AX88772_MEDIUM_DEFAULT; 1287 phyid = asix_get_phyid(dev);
796 lpa = asix_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA); 1288 dbg("PHYID=0x%08x", phyid);
797 adv = asix_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE); 1289
798 res = mii_nway_result(lpa|adv); 1290 if (data->phymode == PHY_MODE_MARVELL) {
1291 marvell_phy_init(dev);
1292 msleep(60);
1293 }
1294
1295 asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR,
1296 BMCR_RESET | BMCR_ANENABLE);
1297 asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
1298 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
1299 asix_mdio_write(dev->net, dev->mii.phy_id, MII_CTRL1000,
1300 ADVERTISE_1000FULL);
1301
1302 mii_nway_restart(&dev->mii);
1303
1304 if ((ret = asix_write_medium_mode(dev, AX88178_MEDIUM_DEFAULT)) < 0)
1305 goto out2;
799 1306
800 if ((res & LPA_DUPLEX) == 0) 1307 if ((ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL)) < 0)
801 mode &= ~AX88772_MEDIUM_FULL_DUPLEX; 1308 goto out2;
802 if ((res & LPA_100) == 0) 1309
803 mode &= ~AX88772_MEDIUM_100MB; 1310 kfree(buf);
804 asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); 1311
1312 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
1313 if (dev->driver_info->flags & FLAG_FRAMING_AX) {
1314 /* hard_mtu is still the default - the device does not support
1315 jumbo eth frames */
1316 dev->rx_urb_size = 2048;
1317 }
805 1318
806 return 0; 1319 return 0;
1320
1321out2:
1322 kfree(buf);
1323out1:
1324 return ret;
807} 1325}
808 1326
809static const struct driver_info ax8817x_info = { 1327static const struct driver_info ax8817x_info = {
@@ -853,8 +1371,19 @@ static const struct driver_info ax88772_info = {
853 .link_reset = ax88772_link_reset, 1371 .link_reset = ax88772_link_reset,
854 .reset = ax88772_link_reset, 1372 .reset = ax88772_link_reset,
855 .flags = FLAG_ETHER | FLAG_FRAMING_AX, 1373 .flags = FLAG_ETHER | FLAG_FRAMING_AX,
856 .rx_fixup = ax88772_rx_fixup, 1374 .rx_fixup = asix_rx_fixup,
857 .tx_fixup = ax88772_tx_fixup, 1375 .tx_fixup = asix_tx_fixup,
1376};
1377
1378static const struct driver_info ax88178_info = {
1379 .description = "ASIX AX88178 USB 2.0 Ethernet",
1380 .bind = ax88178_bind,
1381 .status = asix_status,
1382 .link_reset = ax88178_link_reset,
1383 .reset = ax88178_link_reset,
1384 .flags = FLAG_ETHER | FLAG_FRAMING_AX,
1385 .rx_fixup = asix_rx_fixup,
1386 .tx_fixup = asix_tx_fixup,
858}; 1387};
859 1388
860static const struct usb_device_id products [] = { 1389static const struct usb_device_id products [] = {
@@ -913,7 +1442,7 @@ static const struct usb_device_id products [] = {
913}, { 1442}, {
914 // ASIX AX88178 10/100/1000 1443 // ASIX AX88178 10/100/1000
915 USB_DEVICE (0x0b95, 0x1780), 1444 USB_DEVICE (0x0b95, 0x1780),
916 .driver_info = (unsigned long) &ax88772_info, 1445 .driver_info = (unsigned long) &ax88178_info,
917}, { 1446}, {
918 // Linksys USB200M Rev 2 1447 // Linksys USB200M Rev 2
919 USB_DEVICE (0x13b1, 0x0018), 1448 USB_DEVICE (0x13b1, 0x0018),
@@ -922,6 +1451,18 @@ static const struct usb_device_id products [] = {
922 // 0Q0 cable ethernet 1451 // 0Q0 cable ethernet
923 USB_DEVICE (0x1557, 0x7720), 1452 USB_DEVICE (0x1557, 0x7720),
924 .driver_info = (unsigned long) &ax88772_info, 1453 .driver_info = (unsigned long) &ax88772_info,
1454}, {
1455 // DLink DUB-E100 H/W Ver B1
1456 USB_DEVICE (0x07d1, 0x3c05),
1457 .driver_info = (unsigned long) &ax88772_info,
1458}, {
1459 // DLink DUB-E100 H/W Ver B1 Alternate
1460 USB_DEVICE (0x2001, 0x3c05),
1461 .driver_info = (unsigned long) &ax88772_info,
1462}, {
1463 // Linksys USB1000
1464 USB_DEVICE (0x1737, 0x0039),
1465 .driver_info = (unsigned long) &ax88178_info,
925}, 1466},
926 { }, // END 1467 { }, // END
927}; 1468};
diff --git a/drivers/usb/net/kaweth.c b/drivers/usb/net/kaweth.c
index def3bb8e2290..544d41fe9b92 100644
--- a/drivers/usb/net/kaweth.c
+++ b/drivers/usb/net/kaweth.c
@@ -165,6 +165,7 @@ static struct usb_device_id usb_klsi_table[] = {
165 { USB_DEVICE(0x1645, 0x0005) }, /* Entrega E45 */ 165 { USB_DEVICE(0x1645, 0x0005) }, /* Entrega E45 */
166 { USB_DEVICE(0x1645, 0x0008) }, /* Entrega USB Ethernet Adapter */ 166 { USB_DEVICE(0x1645, 0x0008) }, /* Entrega USB Ethernet Adapter */
167 { USB_DEVICE(0x1645, 0x8005) }, /* PortGear Ethernet Adapter */ 167 { USB_DEVICE(0x1645, 0x8005) }, /* PortGear Ethernet Adapter */
168 { USB_DEVICE(0x1668, 0x0323) }, /* Actiontec USB Ethernet */
168 { USB_DEVICE(0x2001, 0x4000) }, /* D-link DSB-650C */ 169 { USB_DEVICE(0x2001, 0x4000) }, /* D-link DSB-650C */
169 {} /* Null terminator */ 170 {} /* Null terminator */
170}; 171};
diff --git a/drivers/usb/net/net1080.c b/drivers/usb/net/net1080.c
index a9b6eeac3e3f..301baa72bac7 100644
--- a/drivers/usb/net/net1080.c
+++ b/drivers/usb/net/net1080.c
@@ -498,25 +498,24 @@ static int net1080_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
498static struct sk_buff * 498static struct sk_buff *
499net1080_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) 499net1080_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
500{ 500{
501 int padlen;
502 struct sk_buff *skb2; 501 struct sk_buff *skb2;
503 struct nc_header *header = NULL; 502 struct nc_header *header = NULL;
504 struct nc_trailer *trailer = NULL; 503 struct nc_trailer *trailer = NULL;
504 int padlen = sizeof (struct nc_trailer);
505 int len = skb->len; 505 int len = skb->len;
506 506
507 padlen = ((len + sizeof (struct nc_header) 507 if (!((len + padlen + sizeof (struct nc_header)) & 0x01))
508 + sizeof (struct nc_trailer)) & 0x01) ? 0 : 1; 508 padlen++;
509 if (!skb_cloned(skb)) { 509 if (!skb_cloned(skb)) {
510 int headroom = skb_headroom(skb); 510 int headroom = skb_headroom(skb);
511 int tailroom = skb_tailroom(skb); 511 int tailroom = skb_tailroom(skb);
512 512
513 if ((padlen + sizeof (struct nc_trailer)) <= tailroom 513 if (padlen <= tailroom &&
514 && sizeof (struct nc_header) <= headroom) 514 sizeof(struct nc_header) <= headroom)
515 /* There's enough head and tail room */ 515 /* There's enough head and tail room */
516 goto encapsulate; 516 goto encapsulate;
517 517
518 if ((sizeof (struct nc_header) + padlen 518 if ((sizeof (struct nc_header) + padlen) <
519 + sizeof (struct nc_trailer)) <
520 (headroom + tailroom)) { 519 (headroom + tailroom)) {
521 /* There's enough total room, so just readjust */ 520 /* There's enough total room, so just readjust */
522 skb->data = memmove(skb->head 521 skb->data = memmove(skb->head
@@ -530,7 +529,7 @@ net1080_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
530 /* Create a new skb to use with the correct size */ 529 /* Create a new skb to use with the correct size */
531 skb2 = skb_copy_expand(skb, 530 skb2 = skb_copy_expand(skb,
532 sizeof (struct nc_header), 531 sizeof (struct nc_header),
533 sizeof (struct nc_trailer) + padlen, 532 padlen,
534 flags); 533 flags);
535 dev_kfree_skb_any(skb); 534 dev_kfree_skb_any(skb);
536 if (!skb2) 535 if (!skb2)
diff --git a/drivers/usb/net/pegasus.c b/drivers/usb/net/pegasus.c
index ab21f960d255..918cf5a77c08 100644
--- a/drivers/usb/net/pegasus.c
+++ b/drivers/usb/net/pegasus.c
@@ -45,7 +45,7 @@
45/* 45/*
46 * Version Information 46 * Version Information
47 */ 47 */
48#define DRIVER_VERSION "v0.6.13 (2005/11/13)" 48#define DRIVER_VERSION "v0.6.14 (2006/09/27)"
49#define DRIVER_AUTHOR "Petko Manolov <petkan@users.sourceforge.net>" 49#define DRIVER_AUTHOR "Petko Manolov <petkan@users.sourceforge.net>"
50#define DRIVER_DESC "Pegasus/Pegasus II USB Ethernet driver" 50#define DRIVER_DESC "Pegasus/Pegasus II USB Ethernet driver"
51 51
@@ -339,7 +339,7 @@ static int read_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 * regd)
339 } 339 }
340fail: 340fail:
341 if (netif_msg_drv(pegasus)) 341 if (netif_msg_drv(pegasus))
342 dev_warn(&pegasus->intf->dev, "fail %s\n", __FUNCTION__); 342 dev_warn(&pegasus->intf->dev, "%s failed\n", __FUNCTION__);
343 343
344 return ret; 344 return ret;
345} 345}
@@ -376,7 +376,7 @@ static int write_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 regd)
376 376
377fail: 377fail:
378 if (netif_msg_drv(pegasus)) 378 if (netif_msg_drv(pegasus))
379 dev_warn(&pegasus->intf->dev, "fail %s\n", __FUNCTION__); 379 dev_warn(&pegasus->intf->dev, "%s failed\n", __FUNCTION__);
380 return -ETIMEDOUT; 380 return -ETIMEDOUT;
381} 381}
382 382
@@ -413,7 +413,7 @@ static int read_eprom_word(pegasus_t * pegasus, __u8 index, __u16 * retdata)
413 413
414fail: 414fail:
415 if (netif_msg_drv(pegasus)) 415 if (netif_msg_drv(pegasus))
416 dev_warn(&pegasus->intf->dev, "fail %s\n", __FUNCTION__); 416 dev_warn(&pegasus->intf->dev, "%s failed\n", __FUNCTION__);
417 return -ETIMEDOUT; 417 return -ETIMEDOUT;
418} 418}
419 419
@@ -461,7 +461,7 @@ static int write_eprom_word(pegasus_t * pegasus, __u8 index, __u16 data)
461 return ret; 461 return ret;
462fail: 462fail:
463 if (netif_msg_drv(pegasus)) 463 if (netif_msg_drv(pegasus))
464 dev_warn(&pegasus->intf->dev, "fail %s\n", __FUNCTION__); 464 dev_warn(&pegasus->intf->dev, "%s failed\n", __FUNCTION__);
465 return -ETIMEDOUT; 465 return -ETIMEDOUT;
466} 466}
467#endif /* PEGASUS_WRITE_EEPROM */ 467#endif /* PEGASUS_WRITE_EEPROM */
@@ -481,8 +481,12 @@ static void set_ethernet_addr(pegasus_t * pegasus)
481{ 481{
482 __u8 node_id[6]; 482 __u8 node_id[6];
483 483
484 get_node_id(pegasus, node_id); 484 if (pegasus->features & PEGASUS_II) {
485 set_registers(pegasus, EthID, sizeof (node_id), node_id); 485 get_registers(pegasus, 0x10, sizeof(node_id), node_id);
486 } else {
487 get_node_id(pegasus, node_id);
488 set_registers(pegasus, EthID, sizeof (node_id), node_id);
489 }
486 memcpy(pegasus->net->dev_addr, node_id, sizeof (node_id)); 490 memcpy(pegasus->net->dev_addr, node_id, sizeof (node_id));
487} 491}
488 492
@@ -619,7 +623,7 @@ static void read_bulk_callback(struct urb *urb, struct pt_regs *regs)
619 switch (urb->status) { 623 switch (urb->status) {
620 case 0: 624 case 0:
621 break; 625 break;
622 case -ETIMEDOUT: 626 case -ETIME:
623 if (netif_msg_rx_err(pegasus)) 627 if (netif_msg_rx_err(pegasus))
624 pr_debug("%s: reset MAC\n", net->name); 628 pr_debug("%s: reset MAC\n", net->name);
625 pegasus->flags &= ~PEGASUS_RX_BUSY; 629 pegasus->flags &= ~PEGASUS_RX_BUSY;
diff --git a/drivers/usb/net/rtl8150.c b/drivers/usb/net/rtl8150.c
index a72685b96061..2364c2099387 100644
--- a/drivers/usb/net/rtl8150.c
+++ b/drivers/usb/net/rtl8150.c
@@ -438,7 +438,7 @@ static void read_bulk_callback(struct urb *urb, struct pt_regs *regs)
438 break; 438 break;
439 case -ENOENT: 439 case -ENOENT:
440 return; /* the urb is in unlink state */ 440 return; /* the urb is in unlink state */
441 case -ETIMEDOUT: 441 case -ETIME:
442 warn("may be reset is needed?.."); 442 warn("may be reset is needed?..");
443 goto goon; 443 goto goon;
444 default: 444 default:
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c
index 54183e173a6d..98a522f1e264 100644
--- a/drivers/usb/net/usbnet.c
+++ b/drivers/usb/net/usbnet.c
@@ -61,8 +61,11 @@
61 * let the USB host controller be busy for 5msec or more before an irq 61 * let the USB host controller be busy for 5msec or more before an irq
62 * is required, under load. Jumbograms change the equation. 62 * is required, under load. Jumbograms change the equation.
63 */ 63 */
64#define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) 64#define RX_MAX_QUEUE_MEMORY (60 * 1518)
65#define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) 65#define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? \
66 (RX_MAX_QUEUE_MEMORY/(dev)->rx_urb_size) : 4)
67#define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? \
68 (RX_MAX_QUEUE_MEMORY/(dev)->hard_mtu) : 4)
66 69
67// reawaken network queue this soon after stopping; else watchdog barks 70// reawaken network queue this soon after stopping; else watchdog barks
68#define TX_TIMEOUT_JIFFIES (5*HZ) 71#define TX_TIMEOUT_JIFFIES (5*HZ)
@@ -227,13 +230,23 @@ static int usbnet_change_mtu (struct net_device *net, int new_mtu)
227{ 230{
228 struct usbnet *dev = netdev_priv(net); 231 struct usbnet *dev = netdev_priv(net);
229 int ll_mtu = new_mtu + net->hard_header_len; 232 int ll_mtu = new_mtu + net->hard_header_len;
233 int old_hard_mtu = dev->hard_mtu;
234 int old_rx_urb_size = dev->rx_urb_size;
230 235
231 if (new_mtu <= 0 || ll_mtu > dev->hard_mtu) 236 if (new_mtu <= 0)
232 return -EINVAL; 237 return -EINVAL;
233 // no second zero-length packet read wanted after mtu-sized packets 238 // no second zero-length packet read wanted after mtu-sized packets
234 if ((ll_mtu % dev->maxpacket) == 0) 239 if ((ll_mtu % dev->maxpacket) == 0)
235 return -EDOM; 240 return -EDOM;
236 net->mtu = new_mtu; 241 net->mtu = new_mtu;
242
243 dev->hard_mtu = net->mtu + net->hard_header_len;
244 if (dev->rx_urb_size == old_hard_mtu) {
245 dev->rx_urb_size = dev->hard_mtu;
246 if (dev->rx_urb_size > old_rx_urb_size)
247 usbnet_unlink_rx_urbs(dev);
248 }
249
237 return 0; 250 return 0;
238} 251}
239 252
@@ -412,9 +425,9 @@ static void rx_complete (struct urb *urb, struct pt_regs *regs)
412 // we get controller i/o faults during khubd disconnect() delays. 425 // we get controller i/o faults during khubd disconnect() delays.
413 // throttle down resubmits, to avoid log floods; just temporarily, 426 // throttle down resubmits, to avoid log floods; just temporarily,
414 // so we still recover when the fault isn't a khubd delay. 427 // so we still recover when the fault isn't a khubd delay.
415 case -EPROTO: // ehci 428 case -EPROTO:
416 case -ETIMEDOUT: // ohci 429 case -ETIME:
417 case -EILSEQ: // uhci 430 case -EILSEQ:
418 dev->stats.rx_errors++; 431 dev->stats.rx_errors++;
419 if (!timer_pending (&dev->delay)) { 432 if (!timer_pending (&dev->delay)) {
420 mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES); 433 mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES);
@@ -521,6 +534,17 @@ static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q)
521 return count; 534 return count;
522} 535}
523 536
537// Flush all pending rx urbs
538// minidrivers may need to do this when the MTU changes
539
540void usbnet_unlink_rx_urbs(struct usbnet *dev)
541{
542 if (netif_running(dev->net)) {
543 (void) unlink_urbs (dev, &dev->rxq);
544 tasklet_schedule(&dev->bh);
545 }
546}
547EXPORT_SYMBOL_GPL(usbnet_unlink_rx_urbs);
524 548
525/*-------------------------------------------------------------------------*/ 549/*-------------------------------------------------------------------------*/
526 550
@@ -629,7 +653,7 @@ static int usbnet_open (struct net_device *net)
629 653
630 devinfo (dev, "open: enable queueing " 654 devinfo (dev, "open: enable queueing "
631 "(rx %d, tx %d) mtu %d %s framing", 655 "(rx %d, tx %d) mtu %d %s framing",
632 RX_QLEN (dev), TX_QLEN (dev), dev->net->mtu, 656 (int)RX_QLEN (dev), (int)TX_QLEN (dev), dev->net->mtu,
633 framing); 657 framing);
634 } 658 }
635 659
@@ -797,9 +821,9 @@ static void tx_complete (struct urb *urb, struct pt_regs *regs)
797 821
798 // like rx, tx gets controller i/o faults during khubd delays 822 // like rx, tx gets controller i/o faults during khubd delays
799 // and so it uses the same throttling mechanism. 823 // and so it uses the same throttling mechanism.
800 case -EPROTO: // ehci 824 case -EPROTO:
801 case -ETIMEDOUT: // ohci 825 case -ETIME:
802 case -EILSEQ: // uhci 826 case -EILSEQ:
803 if (!timer_pending (&dev->delay)) { 827 if (!timer_pending (&dev->delay)) {
804 mod_timer (&dev->delay, 828 mod_timer (&dev->delay,
805 jiffies + THROTTLE_JIFFIES); 829 jiffies + THROTTLE_JIFFIES);
diff --git a/drivers/usb/net/usbnet.h b/drivers/usb/net/usbnet.h
index 89fc4958eecf..c0746f0454af 100644
--- a/drivers/usb/net/usbnet.h
+++ b/drivers/usb/net/usbnet.h
@@ -166,6 +166,7 @@ struct skb_data { /* skb->cb is one of these */
166extern int usbnet_get_endpoints(struct usbnet *, struct usb_interface *); 166extern int usbnet_get_endpoints(struct usbnet *, struct usb_interface *);
167extern void usbnet_defer_kevent (struct usbnet *, int); 167extern void usbnet_defer_kevent (struct usbnet *, int);
168extern void usbnet_skb_return (struct usbnet *, struct sk_buff *); 168extern void usbnet_skb_return (struct usbnet *, struct sk_buff *);
169extern void usbnet_unlink_rx_urbs(struct usbnet *);
169 170
170extern u32 usbnet_get_msglevel (struct net_device *); 171extern u32 usbnet_get_msglevel (struct net_device *);
171extern void usbnet_set_msglevel (struct net_device *, u32); 172extern void usbnet_set_msglevel (struct net_device *, u32);
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index f5b9438c94f0..5076b9d97057 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -53,6 +53,15 @@ config USB_SERIAL_GENERIC
53 support" be compiled as a module for this driver to be used 53 support" be compiled as a module for this driver to be used
54 properly. 54 properly.
55 55
56config USB_SERIAL_AIRCABLE
57 tristate "AIRcable USB Bluetooth Dongle Driver (EXPERIMENTAL)"
58 depends on USB_SERIAL && EXPERIMENTAL
59 help
60 Say Y here if you want to use AIRcable USB Bluetoot Dongle.
61
62 To compile this driver as a module, choose M here: the module
63 will be called aircable.
64
56config USB_SERIAL_AIRPRIME 65config USB_SERIAL_AIRPRIME
57 tristate "USB AirPrime CDMA Wireless Driver" 66 tristate "USB AirPrime CDMA Wireless Driver"
58 depends on USB_SERIAL 67 depends on USB_SERIAL
@@ -413,6 +422,21 @@ config USB_SERIAL_MCT_U232
413 To compile this driver as a module, choose M here: the 422 To compile this driver as a module, choose M here: the
414 module will be called mct_u232. 423 module will be called mct_u232.
415 424
425config USB_SERIAL_MOS7840
426 tristate "USB Moschip 7840/7820 USB Serial Driver"
427 depends on USB_SERIAL
428 ---help---
429 Say Y here if you want to use a MCS7840 Quad-Serial or MCS7820
430 Dual-Serial port device from MosChip Semiconductor.
431
432 The MCS7840 and MCS7820 have been developed to connect a wide range
433 of standard serial devices to a USB host. The MCS7840 has a USB
434 device controller connected to four (4) individual UARTs while the
435 MCS7820 controller connects to two (2) individual UARTs.
436
437 To compile this driver as a module, choose M here: the
438 module will be called mos7840. If unsure, choose N.
439
416config USB_SERIAL_NAVMAN 440config USB_SERIAL_NAVMAN
417 tristate "USB Navman GPS device" 441 tristate "USB Navman GPS device"
418 depends on USB_SERIAL 442 depends on USB_SERIAL
@@ -526,5 +550,6 @@ config USB_EZUSB
526 depends on USB_SERIAL_KEYSPAN_PDA || USB_SERIAL_XIRCOM || USB_SERIAL_KEYSPAN || USB_SERIAL_WHITEHEAT 550 depends on USB_SERIAL_KEYSPAN_PDA || USB_SERIAL_XIRCOM || USB_SERIAL_KEYSPAN || USB_SERIAL_WHITEHEAT
527 default y 551 default y
528 552
553
529endmenu 554endmenu
530 555
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index 8efed2ce1ba3..8dce83340e31 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -11,6 +11,7 @@ usbserial-obj-$(CONFIG_USB_EZUSB) += ezusb.o
11 11
12usbserial-objs := usb-serial.o generic.o bus.o $(usbserial-obj-y) 12usbserial-objs := usb-serial.o generic.o bus.o $(usbserial-obj-y)
13 13
14obj-$(CONFIG_USB_SERIAL_AIRCABLE) += aircable.o
14obj-$(CONFIG_USB_SERIAL_AIRPRIME) += airprime.o 15obj-$(CONFIG_USB_SERIAL_AIRPRIME) += airprime.o
15obj-$(CONFIG_USB_SERIAL_ARK3116) += ark3116.o 16obj-$(CONFIG_USB_SERIAL_ARK3116) += ark3116.o
16obj-$(CONFIG_USB_SERIAL_BELKIN) += belkin_sa.o 17obj-$(CONFIG_USB_SERIAL_BELKIN) += belkin_sa.o
@@ -33,6 +34,7 @@ obj-$(CONFIG_USB_SERIAL_KEYSPAN_PDA) += keyspan_pda.o
33obj-$(CONFIG_USB_SERIAL_KLSI) += kl5kusb105.o 34obj-$(CONFIG_USB_SERIAL_KLSI) += kl5kusb105.o
34obj-$(CONFIG_USB_SERIAL_KOBIL_SCT) += kobil_sct.o 35obj-$(CONFIG_USB_SERIAL_KOBIL_SCT) += kobil_sct.o
35obj-$(CONFIG_USB_SERIAL_MCT_U232) += mct_u232.o 36obj-$(CONFIG_USB_SERIAL_MCT_U232) += mct_u232.o
37obj-$(CONFIG_USB_SERIAL_MOS7840) += mos7840.o
36obj-$(CONFIG_USB_SERIAL_NAVMAN) += navman.o 38obj-$(CONFIG_USB_SERIAL_NAVMAN) += navman.o
37obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o 39obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o
38obj-$(CONFIG_USB_SERIAL_OPTION) += option.o 40obj-$(CONFIG_USB_SERIAL_OPTION) += option.o
diff --git a/drivers/usb/serial/aircable.c b/drivers/usb/serial/aircable.c
new file mode 100644
index 000000000000..2ccd9ded52a5
--- /dev/null
+++ b/drivers/usb/serial/aircable.c
@@ -0,0 +1,625 @@
1/*
2 * AIRcable USB Bluetooth Dongle Driver.
3 *
4 * Copyright (C) 2006 Manuel Francisco Naranjo (naranjo.manuel@gmail.com)
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License version 2 as published by the
7 * Free Software Foundation.
8 *
9 * The device works as an standard CDC device, it has 2 interfaces, the first
10 * one is for firmware access and the second is the serial one.
11 * The protocol is very simply, there are two posibilities reading or writing.
12 * When writting the first urb must have a Header that starts with 0x20 0x29 the
13 * next two bytes must say how much data will be sended.
14 * When reading the process is almost equal except that the header starts with
15 * 0x00 0x20.
16 *
17 * The device simply need some stuff to understand data comming from the usb
18 * buffer: The First and Second byte is used for a Header, the Third and Fourth
19 * tells the device the amount of information the package holds.
20 * Packages are 60 bytes long Header Stuff.
21 * When writting to the device the first two bytes of the header are 0x20 0x29
22 * When reading the bytes are 0x00 0x20, or 0x00 0x10, there is an strange
23 * situation, when too much data arrives to the device because it sends the data
24 * but with out the header. I will use a simply hack to override this situation,
25 * if there is data coming that does not contain any header, then that is data
26 * that must go directly to the tty, as there is no documentation about if there
27 * is any other control code, I will simply check for the first
28 * one.
29 *
30 * The driver registers himself with the USB-serial core and the USB Core. I had
31 * to implement a probe function agains USB-serial, because other way, the
32 * driver was attaching himself to both interfaces. I have tryed with different
33 * configurations of usb_serial_driver with out exit, only the probe function
34 * could handle this correctly.
35 *
36 * I have taken some info from a Greg Kroah-Hartman article:
37 * http://www.linuxjournal.com/article/6573
38 * And from Linux Device Driver Kit CD, which is a great work, the authors taken
39 * the work to recompile lots of information an knowladge in drivers development
40 * and made it all avaible inside a cd.
41 * URL: http://kernel.org/pub/linux/kernel/people/gregkh/ddk/
42 *
43 */
44
45#include <linux/tty.h>
46#include <linux/tty_flip.h>
47#include <linux/circ_buf.h>
48#include <linux/usb.h>
49#include <linux/usb/serial.h>
50
51static int debug;
52
53/* Vendor and Product ID */
54#define AIRCABLE_VID 0x16CA
55#define AIRCABLE_USB_PID 0x1502
56
57/* write buffer size defines */
58#define AIRCABLE_BUF_SIZE 2048
59
60/* Protocol Stuff */
61#define HCI_HEADER_LENGTH 0x4
62#define TX_HEADER_0 0x20
63#define TX_HEADER_1 0x29
64#define RX_HEADER_0 0x00
65#define RX_HEADER_1 0x20
66#define MAX_HCI_FRAMESIZE 60
67#define HCI_COMPLETE_FRAME 64
68
69/* rx_flags */
70#define THROTTLED 0x01
71#define ACTUALLY_THROTTLED 0x02
72
73/*
74 * Version Information
75 */
76#define DRIVER_VERSION "v1.0b2"
77#define DRIVER_AUTHOR "Naranjo, Manuel Francisco <naranjo.manuel@gmail.com>"
78#define DRIVER_DESC "AIRcable USB Driver"
79
80/* ID table that will be registered with USB core */
81static struct usb_device_id id_table [] = {
82 { USB_DEVICE(AIRCABLE_VID, AIRCABLE_USB_PID) },
83 { },
84};
85MODULE_DEVICE_TABLE(usb, id_table);
86
87
88/* Internal Structure */
89struct aircable_private {
90 spinlock_t rx_lock; /* spinlock for the receive lines */
91 struct circ_buf *tx_buf; /* write buffer */
92 struct circ_buf *rx_buf; /* read buffer */
93 int rx_flags; /* for throttilng */
94 struct work_struct rx_work; /* work cue for the receiving line */
95};
96
97/* Private methods */
98
99/* Circular Buffer Methods, code from ti_usb_3410_5052 used */
100/*
101 * serial_buf_clear
102 *
103 * Clear out all data in the circular buffer.
104 */
105static void serial_buf_clear(struct circ_buf *cb)
106{
107 cb->head = cb->tail = 0;
108}
109
110/*
111 * serial_buf_alloc
112 *
113 * Allocate a circular buffer and all associated memory.
114 */
115static struct circ_buf *serial_buf_alloc(void)
116{
117 struct circ_buf *cb;
118 cb = kmalloc(sizeof(struct circ_buf), GFP_KERNEL);
119 if (cb == NULL)
120 return NULL;
121 cb->buf = kmalloc(AIRCABLE_BUF_SIZE, GFP_KERNEL);
122 if (cb->buf == NULL) {
123 kfree(cb);
124 return NULL;
125 }
126 serial_buf_clear(cb);
127 return cb;
128}
129
130/*
131 * serial_buf_free
132 *
133 * Free the buffer and all associated memory.
134 */
135static void serial_buf_free(struct circ_buf *cb)
136{
137 kfree(cb->buf);
138 kfree(cb);
139}
140
141/*
142 * serial_buf_data_avail
143 *
144 * Return the number of bytes of data available in the circular
145 * buffer.
146 */
147static int serial_buf_data_avail(struct circ_buf *cb)
148{
149 return CIRC_CNT(cb->head,cb->tail,AIRCABLE_BUF_SIZE);
150}
151
152/*
153 * serial_buf_put
154 *
155 * Copy data data from a user buffer and put it into the circular buffer.
156 * Restrict to the amount of space available.
157 *
158 * Return the number of bytes copied.
159 */
160static int serial_buf_put(struct circ_buf *cb, const char *buf, int count)
161{
162 int c, ret = 0;
163 while (1) {
164 c = CIRC_SPACE_TO_END(cb->head, cb->tail, AIRCABLE_BUF_SIZE);
165 if (count < c)
166 c = count;
167 if (c <= 0)
168 break;
169 memcpy(cb->buf + cb->head, buf, c);
170 cb->head = (cb->head + c) & (AIRCABLE_BUF_SIZE-1);
171 buf += c;
172 count -= c;
173 ret= c;
174 }
175 return ret;
176}
177
178/*
179 * serial_buf_get
180 *
181 * Get data from the circular buffer and copy to the given buffer.
182 * Restrict to the amount of data available.
183 *
184 * Return the number of bytes copied.
185 */
186static int serial_buf_get(struct circ_buf *cb, char *buf, int count)
187{
188 int c, ret = 0;
189 while (1) {
190 c = CIRC_CNT_TO_END(cb->head, cb->tail, AIRCABLE_BUF_SIZE);
191 if (count < c)
192 c = count;
193 if (c <= 0)
194 break;
195 memcpy(buf, cb->buf + cb->tail, c);
196 cb->tail = (cb->tail + c) & (AIRCABLE_BUF_SIZE-1);
197 buf += c;
198 count -= c;
199 ret= c;
200 }
201 return ret;
202}
203
204/* End of circula buffer methods */
205
206static void aircable_send(struct usb_serial_port *port)
207{
208 int count, result;
209 struct aircable_private *priv = usb_get_serial_port_data(port);
210 unsigned char* buf;
211 dbg("%s - port %d", __FUNCTION__, port->number);
212 if (port->write_urb_busy)
213 return;
214
215 count = min(serial_buf_data_avail(priv->tx_buf), MAX_HCI_FRAMESIZE);
216 if (count == 0)
217 return;
218
219 buf = kzalloc(count + HCI_HEADER_LENGTH, GFP_ATOMIC);
220 if (!buf) {
221 err("%s- kzalloc(%d) failed.", __FUNCTION__,
222 count + HCI_HEADER_LENGTH);
223 return;
224 }
225
226 buf[0] = TX_HEADER_0;
227 buf[1] = TX_HEADER_1;
228 buf[2] = (unsigned char)count;
229 buf[3] = (unsigned char)(count >> 8);
230 serial_buf_get(priv->tx_buf,buf + HCI_HEADER_LENGTH, MAX_HCI_FRAMESIZE);
231
232 memcpy(port->write_urb->transfer_buffer, buf,
233 count + HCI_HEADER_LENGTH);
234
235 kfree(buf);
236 port->write_urb_busy = 1;
237 usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
238 count + HCI_HEADER_LENGTH,
239 port->write_urb->transfer_buffer);
240 port->write_urb->transfer_buffer_length = count + HCI_HEADER_LENGTH;
241 port->write_urb->dev = port->serial->dev;
242 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
243
244 if (result) {
245 dev_err(&port->dev,
246 "%s - failed submitting write urb, error %d\n",
247 __FUNCTION__, result);
248 port->write_urb_busy = 0;
249 }
250
251 schedule_work(&port->work);
252}
253
254static void aircable_read(void *params)
255{
256 struct usb_serial_port *port = params;
257 struct aircable_private *priv = usb_get_serial_port_data(port);
258 struct tty_struct *tty;
259 unsigned char *data;
260 int count;
261 if (priv->rx_flags & THROTTLED){
262 if (priv->rx_flags & ACTUALLY_THROTTLED)
263 schedule_work(&priv->rx_work);
264 return;
265 }
266
267 /* By now I will flush data to the tty in packages of no more than
268 * 64 bytes, to ensure I do not get throttled.
269 * Ask USB mailing list for better aproach.
270 */
271 tty = port->tty;
272
273 if (!tty)
274 schedule_work(&priv->rx_work);
275
276 count = min(64, serial_buf_data_avail(priv->rx_buf));
277
278 if (count <= 0)
279 return; //We have finished sending everything.
280
281 tty_prepare_flip_string(tty, &data, count);
282 if (!data){
283 err("%s- kzalloc(%d) failed.", __FUNCTION__, count);
284 return;
285 }
286
287 serial_buf_get(priv->rx_buf, data, count);
288
289 tty_flip_buffer_push(tty);
290
291 if (serial_buf_data_avail(priv->rx_buf))
292 schedule_work(&priv->rx_work);
293
294 return;
295}
296/* End of private methods */
297
298static int aircable_probe(struct usb_serial *serial,
299 const struct usb_device_id *id)
300{
301 struct usb_host_interface *iface_desc = serial->interface->cur_altsetting;
302 struct usb_endpoint_descriptor *endpoint;
303 int num_bulk_out=0;
304 int i;
305
306 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
307 endpoint = &iface_desc->endpoint[i].desc;
308 if (((endpoint->bEndpointAddress & 0x80) == 0x00) &&
309 ((endpoint->bmAttributes & 3) == 0x02)) {
310 /* we found our bulk out endpoint */
311 dbg("found bulk out on endpoint %d", i);
312 ++num_bulk_out;
313 }
314 }
315
316 if (num_bulk_out == 0) {
317 dbg("Invalid interface, discarding");
318 return -ENODEV;
319 }
320
321 return 0;
322}
323
324static int aircable_attach (struct usb_serial *serial)
325{
326 struct usb_serial_port *port = serial->port[0];
327 struct aircable_private *priv;
328
329 priv = kzalloc(sizeof(struct aircable_private), GFP_KERNEL);
330 if (!priv){
331 err("%s- kmalloc(%Zd) failed.", __FUNCTION__,
332 sizeof(struct aircable_private));
333 return -ENOMEM;
334 }
335
336 /* Allocation of Circular Buffers */
337 priv->tx_buf = serial_buf_alloc();
338 if (priv->tx_buf == NULL) {
339 kfree(priv);
340 return -ENOMEM;
341 }
342
343 priv->rx_buf = serial_buf_alloc();
344 if (priv->rx_buf == NULL) {
345 kfree(priv->tx_buf);
346 kfree(priv);
347 return -ENOMEM;
348 }
349
350 priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED);
351 INIT_WORK(&priv->rx_work, aircable_read, port);
352
353 usb_set_serial_port_data(serial->port[0], priv);
354
355 return 0;
356}
357
358static void aircable_shutdown(struct usb_serial *serial)
359{
360
361 struct usb_serial_port *port = serial->port[0];
362 struct aircable_private *priv = usb_get_serial_port_data(port);
363
364 dbg("%s", __FUNCTION__);
365
366 if (priv) {
367 serial_buf_free(priv->tx_buf);
368 serial_buf_free(priv->rx_buf);
369 usb_set_serial_port_data(port, NULL);
370 kfree(priv);
371 }
372}
373
374static int aircable_write_room(struct usb_serial_port *port)
375{
376 struct aircable_private *priv = usb_get_serial_port_data(port);
377 return serial_buf_data_avail(priv->tx_buf);
378}
379
380static int aircable_write(struct usb_serial_port *port,
381 const unsigned char *source, int count)
382{
383 struct aircable_private *priv = usb_get_serial_port_data(port);
384 int temp;
385
386 dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count);
387
388 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, source);
389
390 if (!count){
391 dbg("%s - write request of 0 bytes", __FUNCTION__);
392 return count;
393 }
394
395 temp = serial_buf_put(priv->tx_buf, source, count);
396
397 aircable_send(port);
398
399 if (count > AIRCABLE_BUF_SIZE)
400 count = AIRCABLE_BUF_SIZE;
401
402 return count;
403
404}
405
406static void aircable_write_bulk_callback(struct urb *urb, struct pt_regs *regs)
407{
408 struct usb_serial_port *port = urb->context;
409 int result;
410
411 dbg("%s - urb->status: %d", __FUNCTION__ , urb->status);
412
413 /* This has been taken from cypress_m8.c cypress_write_int_callback */
414 switch (urb->status) {
415 case 0:
416 /* success */
417 break;
418 case -ECONNRESET:
419 case -ENOENT:
420 case -ESHUTDOWN:
421 /* this urb is terminated, clean up */
422 dbg("%s - urb shutting down with status: %d",
423 __FUNCTION__, urb->status);
424 port->write_urb_busy = 0;
425 return;
426 default:
427 /* error in the urb, so we have to resubmit it */
428 dbg("%s - Overflow in write", __FUNCTION__);
429 dbg("%s - nonzero write bulk status received: %d",
430 __FUNCTION__, urb->status);
431 port->write_urb->transfer_buffer_length = 1;
432 port->write_urb->dev = port->serial->dev;
433 result = usb_submit_urb(port->write_urb, GFP_KERNEL);
434 if (result)
435 dev_err(&urb->dev->dev,
436 "%s - failed resubmitting write urb, error %d\n",
437 __FUNCTION__, result);
438 else
439 return;
440 }
441
442 port->write_urb_busy = 0;
443
444 aircable_send(port);
445}
446
447static void aircable_read_bulk_callback(struct urb *urb, struct pt_regs *regs)
448{
449 struct usb_serial_port *port = urb->context;
450 struct aircable_private *priv = usb_get_serial_port_data(port);
451 struct tty_struct *tty;
452 unsigned long no_packages, remaining, package_length, i;
453 int result, shift = 0;
454 unsigned char *temp;
455
456 dbg("%s - port %d", __FUNCTION__, port->number);
457
458 if (urb->status) {
459 dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
460 if (!port->open_count) {
461 dbg("%s - port is closed, exiting.", __FUNCTION__);
462 return;
463 }
464 if (urb->status == -EPROTO) {
465 dbg("%s - caught -EPROTO, resubmitting the urb",
466 __FUNCTION__);
467 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
468 usb_rcvbulkpipe(port->serial->dev,
469 port->bulk_in_endpointAddress),
470 port->read_urb->transfer_buffer,
471 port->read_urb->transfer_buffer_length,
472 aircable_read_bulk_callback, port);
473
474 result = usb_submit_urb(urb, GFP_ATOMIC);
475 if (result)
476 dev_err(&urb->dev->dev,
477 "%s - failed resubmitting read urb, error %d\n",
478 __FUNCTION__, result);
479 return;
480 }
481 dbg("%s - unable to handle the error, exiting.", __FUNCTION__);
482 return;
483 }
484
485 usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
486 urb->actual_length,urb->transfer_buffer);
487
488 tty = port->tty;
489 if (tty && urb->actual_length) {
490 if (urb->actual_length <= 2) {
491 /* This is an incomplete package */
492 serial_buf_put(priv->rx_buf, urb->transfer_buffer,
493 urb->actual_length);
494 } else {
495 temp = urb->transfer_buffer;
496 if (temp[0] == RX_HEADER_0)
497 shift = HCI_HEADER_LENGTH;
498
499 remaining = urb->actual_length;
500 no_packages = urb->actual_length / (HCI_COMPLETE_FRAME);
501
502 if (urb->actual_length % HCI_COMPLETE_FRAME != 0)
503 no_packages+=1;
504
505 for (i = 0; i < no_packages ;i++) {
506 if (remaining > (HCI_COMPLETE_FRAME))
507 package_length = HCI_COMPLETE_FRAME;
508 else
509 package_length = remaining;
510 remaining -= package_length;
511
512 serial_buf_put(priv->rx_buf,
513 urb->transfer_buffer + shift +
514 (HCI_COMPLETE_FRAME) * (i),
515 package_length - shift);
516 }
517 }
518 aircable_read(port);
519 }
520
521 /* Schedule the next read _if_ we are still open */
522 if (port->open_count) {
523 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
524 usb_rcvbulkpipe(port->serial->dev,
525 port->bulk_in_endpointAddress),
526 port->read_urb->transfer_buffer,
527 port->read_urb->transfer_buffer_length,
528 aircable_read_bulk_callback, port);
529
530 result = usb_submit_urb(urb, GFP_ATOMIC);
531 if (result)
532 dev_err(&urb->dev->dev,
533 "%s - failed resubmitting read urb, error %d\n",
534 __FUNCTION__, result);
535 }
536
537 return;
538}
539
540/* Based on ftdi_sio.c throttle */
541static void aircable_throttle(struct usb_serial_port *port)
542{
543 struct aircable_private *priv = usb_get_serial_port_data(port);
544 unsigned long flags;
545
546 dbg("%s - port %d", __FUNCTION__, port->number);
547
548 spin_lock_irqsave(&priv->rx_lock, flags);
549 priv->rx_flags |= THROTTLED;
550 spin_unlock_irqrestore(&priv->rx_lock, flags);
551}
552
553/* Based on ftdi_sio.c unthrottle */
554static void aircable_unthrottle(struct usb_serial_port *port)
555{
556 struct aircable_private *priv = usb_get_serial_port_data(port);
557 int actually_throttled;
558 unsigned long flags;
559
560 dbg("%s - port %d", __FUNCTION__, port->number);
561
562 spin_lock_irqsave(&priv->rx_lock, flags);
563 actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED;
564 priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED);
565 spin_unlock_irqrestore(&priv->rx_lock, flags);
566
567 if (actually_throttled)
568 schedule_work(&priv->rx_work);
569}
570
571static struct usb_serial_driver aircable_device = {
572 .description = "aircable",
573 .id_table = id_table,
574 .num_ports = 1,
575 .attach = aircable_attach,
576 .probe = aircable_probe,
577 .shutdown = aircable_shutdown,
578 .write = aircable_write,
579 .write_room = aircable_write_room,
580 .write_bulk_callback = aircable_write_bulk_callback,
581 .read_bulk_callback = aircable_read_bulk_callback,
582 .throttle = aircable_throttle,
583 .unthrottle = aircable_unthrottle,
584};
585
586static struct usb_driver aircable_driver = {
587 .name = "aircable",
588 .probe = usb_serial_probe,
589 .disconnect = usb_serial_disconnect,
590 .id_table = id_table,
591};
592
593static int __init aircable_init (void)
594{
595 int retval;
596 retval = usb_serial_register(&aircable_device);
597 if (retval)
598 goto failed_serial_register;
599 retval = usb_register(&aircable_driver);
600 if (retval)
601 goto failed_usb_register;
602 return 0;
603
604failed_serial_register:
605 usb_serial_deregister(&aircable_device);
606failed_usb_register:
607 return retval;
608}
609
610static void __exit aircable_exit (void)
611{
612 usb_deregister(&aircable_driver);
613 usb_serial_deregister(&aircable_device);
614}
615
616MODULE_AUTHOR(DRIVER_AUTHOR);
617MODULE_DESCRIPTION(DRIVER_DESC);
618MODULE_VERSION(DRIVER_VERSION);
619MODULE_LICENSE("GPL");
620
621module_init(aircable_init);
622module_exit(aircable_exit);
623
624module_param(debug, bool, S_IRUGO | S_IWUSR);
625MODULE_PARM_DESC(debug, "Debug enabled or not");
diff --git a/drivers/usb/serial/airprime.c b/drivers/usb/serial/airprime.c
index 62082532a8b3..6e1a84a858d4 100644
--- a/drivers/usb/serial/airprime.c
+++ b/drivers/usb/serial/airprime.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * AirPrime CDMA Wireless Serial USB driver 2 * AirPrime CDMA Wireless Serial USB driver
3 * 3 *
4 * Copyright (C) 2005 Greg Kroah-Hartman <gregkh@suse.de> 4 * Copyright (C) 2005-2006 Greg Kroah-Hartman <gregkh@suse.de>
5 * 5 *
6 * This program is free software; you can redistribute it and/or 6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version 7 * modify it under the terms of the GNU General Public License version
@@ -11,26 +11,264 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/tty.h> 13#include <linux/tty.h>
14#include <linux/tty_flip.h>
14#include <linux/module.h> 15#include <linux/module.h>
15#include <linux/usb.h> 16#include <linux/usb.h>
16#include <linux/usb/serial.h> 17#include <linux/usb/serial.h>
17 18
18static struct usb_device_id id_table [] = { 19static struct usb_device_id id_table [] = {
19 { USB_DEVICE(0x0c88, 0x17da) }, /* Kyocera Wireless KPC650/Passport */ 20 { USB_DEVICE(0x0c88, 0x17da) }, /* Kyocera Wireless KPC650/Passport */
20 { USB_DEVICE(0xf3d, 0x0112) }, /* AirPrime CDMA Wireless PC Card */ 21 { USB_DEVICE(0x0f3d, 0x0112) }, /* AirPrime CDMA Wireless PC Card */
21 { USB_DEVICE(0x1410, 0x1110) }, /* Novatel Wireless Merlin CDMA */ 22 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
23 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
22 { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless Aircard 580 */ 24 { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless Aircard 580 */
23 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */ 25 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
26 { USB_DEVICE(0x1410, 0x1110) }, /* Novatel Wireless Merlin CDMA */
24 { }, 27 { },
25}; 28};
26MODULE_DEVICE_TABLE(usb, id_table); 29MODULE_DEVICE_TABLE(usb, id_table);
27 30
31#define URB_TRANSFER_BUFFER_SIZE 4096
32#define NUM_READ_URBS 4
33#define NUM_WRITE_URBS 4
34#define NUM_BULK_EPS 3
35#define MAX_BULK_EPS 6
36
37/* if overridden by the user, then use their value for the size of the
38 * read and write urbs, and the number of endpoints */
39static int buffer_size = URB_TRANSFER_BUFFER_SIZE;
40static int endpoints = NUM_BULK_EPS;
41static int debug;
42struct airprime_private {
43 spinlock_t lock;
44 int outstanding_urbs;
45 int throttled;
46 struct urb *read_urbp[NUM_READ_URBS];
47};
48
49static void airprime_read_bulk_callback(struct urb *urb, struct pt_regs *regs)
50{
51 struct usb_serial_port *port = urb->context;
52 unsigned char *data = urb->transfer_buffer;
53 struct tty_struct *tty;
54 int result;
55
56 dbg("%s - port %d", __FUNCTION__, port->number);
57
58 if (urb->status) {
59 dbg("%s - nonzero read bulk status received: %d",
60 __FUNCTION__, urb->status);
61 /* something happened, so free up the memory for this urb */
62 if (urb->transfer_buffer) {
63 kfree (urb->transfer_buffer);
64 urb->transfer_buffer = NULL;
65 }
66 return;
67 }
68 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
69
70 tty = port->tty;
71 if (tty && urb->actual_length) {
72 tty_insert_flip_string (tty, data, urb->actual_length);
73 tty_flip_buffer_push (tty);
74 }
75
76 result = usb_submit_urb (urb, GFP_ATOMIC);
77 if (result)
78 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n",
79 __FUNCTION__, result);
80 return;
81}
82
83static void airprime_write_bulk_callback(struct urb *urb, struct pt_regs *regs)
84{
85 struct usb_serial_port *port = urb->context;
86 struct airprime_private *priv = usb_get_serial_port_data(port);
87 unsigned long flags;
88
89 dbg("%s - port %d", __FUNCTION__, port->number);
90
91 /* free up the transfer buffer, as usb_free_urb() does not do this */
92 kfree (urb->transfer_buffer);
93
94 if (urb->status)
95 dbg("%s - nonzero write bulk status received: %d",
96 __FUNCTION__, urb->status);
97 spin_lock_irqsave(&priv->lock, flags);
98 --priv->outstanding_urbs;
99 spin_unlock_irqrestore(&priv->lock, flags);
100
101 usb_serial_port_softint(port);
102}
103
104static int airprime_open(struct usb_serial_port *port, struct file *filp)
105{
106 struct airprime_private *priv = usb_get_serial_port_data(port);
107 struct usb_serial *serial = port->serial;
108 struct urb *urb;
109 char *buffer = NULL;
110 int i;
111 int result = 0;
112
113 dbg("%s - port %d", __FUNCTION__, port->number);
114
115 /* initialize our private data structure if it isn't already created */
116 if (!priv) {
117 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
118 if (!priv) {
119 result = -ENOMEM;
120 goto out;
121 }
122 spin_lock_init(&priv->lock);
123 usb_set_serial_port_data(port, priv);
124 }
125
126 for (i = 0; i < NUM_READ_URBS; ++i) {
127 buffer = kmalloc(buffer_size, GFP_KERNEL);
128 if (!buffer) {
129 dev_err(&port->dev, "%s - out of memory.\n",
130 __FUNCTION__);
131 result = -ENOMEM;
132 goto errout;
133 }
134 urb = usb_alloc_urb(0, GFP_KERNEL);
135 if (!urb) {
136 dev_err(&port->dev, "%s - no more urbs?\n",
137 __FUNCTION__);
138 result = -ENOMEM;
139 goto errout;
140 }
141 usb_fill_bulk_urb(urb, serial->dev,
142 usb_rcvbulkpipe(serial->dev,
143 port->bulk_out_endpointAddress),
144 buffer, buffer_size,
145 airprime_read_bulk_callback, port);
146 result = usb_submit_urb(urb, GFP_KERNEL);
147 if (result) {
148 dev_err(&port->dev,
149 "%s - failed submitting read urb %d for port %d, error %d\n",
150 __FUNCTION__, i, port->number, result);
151 goto errout;
152 }
153 /* remember this urb so we can kill it when the port is closed */
154 priv->read_urbp[i] = urb;
155 }
156 goto out;
157
158 errout:
159 /* some error happened, cancel any submitted urbs and clean up anything that
160 got allocated successfully */
161
162 for ( ; i >= 0; --i) {
163 urb = priv->read_urbp[i];
164 if (urb) {
165 /* This urb was submitted successfully. So we have to
166 cancel it.
167 Unlinking the urb will invoke read_bulk_callback()
168 with an error status, so its transfer buffer will
169 be freed there */
170 if (usb_unlink_urb (urb) != -EINPROGRESS) {
171 /* comments in drivers/usb/core/urb.c say this
172 can only happen if the urb was never submitted,
173 or has completed already.
174 Either way we may have to free the transfer
175 buffer here. */
176 if (urb->transfer_buffer) {
177 kfree (urb->transfer_buffer);
178 urb->transfer_buffer = NULL;
179 }
180 }
181 usb_free_urb (urb);
182 }
183 }
184
185 out:
186 return result;
187}
188
189static void airprime_close(struct usb_serial_port *port, struct file * filp)
190{
191 struct airprime_private *priv = usb_get_serial_port_data(port);
192 int i;
193
194 dbg("%s - port %d", __FUNCTION__, port->number);
195
196 /* killing the urb will invoke read_bulk_callback() with an error status,
197 so the transfer buffer will be freed there */
198 for (i = 0; i < NUM_READ_URBS; ++i) {
199 usb_kill_urb (priv->read_urbp[i]);
200 usb_free_urb (priv->read_urbp[i]);
201 }
202
203 /* free up private structure */
204 kfree (priv);
205 usb_set_serial_port_data(port, NULL);
206}
207
208static int airprime_write(struct usb_serial_port *port,
209 const unsigned char *buf, int count)
210{
211 struct airprime_private *priv = usb_get_serial_port_data(port);
212 struct usb_serial *serial = port->serial;
213 struct urb *urb;
214 unsigned char *buffer;
215 unsigned long flags;
216 int status;
217 dbg("%s - port %d", __FUNCTION__, port->number);
218
219 spin_lock_irqsave(&priv->lock, flags);
220 if (priv->outstanding_urbs > NUM_WRITE_URBS) {
221 spin_unlock_irqrestore(&priv->lock, flags);
222 dbg("%s - write limit hit\n", __FUNCTION__);
223 return 0;
224 }
225 spin_unlock_irqrestore(&priv->lock, flags);
226 buffer = kmalloc(count, GFP_ATOMIC);
227 if (!buffer) {
228 dev_err(&port->dev, "out of memory\n");
229 return -ENOMEM;
230 }
231 urb = usb_alloc_urb(0, GFP_ATOMIC);
232 if (!urb) {
233 dev_err(&port->dev, "no more free urbs\n");
234 kfree (buffer);
235 return -ENOMEM;
236 }
237 memcpy (buffer, buf, count);
238
239 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, buffer);
240
241 usb_fill_bulk_urb(urb, serial->dev,
242 usb_sndbulkpipe(serial->dev,
243 port->bulk_out_endpointAddress),
244 buffer, count,
245 airprime_write_bulk_callback, port);
246
247 /* send it down the pipe */
248 status = usb_submit_urb(urb, GFP_ATOMIC);
249 if (status) {
250 dev_err(&port->dev,
251 "%s - usb_submit_urb(write bulk) failed with status = %d\n",
252 __FUNCTION__, status);
253 count = status;
254 kfree (buffer);
255 } else {
256 spin_lock_irqsave(&priv->lock, flags);
257 ++priv->outstanding_urbs;
258 spin_unlock_irqrestore(&priv->lock, flags);
259 }
260 /* we are done with this urb, so let the host driver
261 * really free it when it is finished with it */
262 usb_free_urb (urb);
263 return count;
264}
265
28static struct usb_driver airprime_driver = { 266static struct usb_driver airprime_driver = {
29 .name = "airprime", 267 .name = "airprime",
30 .probe = usb_serial_probe, 268 .probe = usb_serial_probe,
31 .disconnect = usb_serial_disconnect, 269 .disconnect = usb_serial_disconnect,
32 .id_table = id_table, 270 .id_table = id_table,
33 .no_dynamic_id = 1, 271 .no_dynamic_id = 1,
34}; 272};
35 273
36static struct usb_serial_driver airprime_device = { 274static struct usb_serial_driver airprime_device = {
@@ -42,13 +280,17 @@ static struct usb_serial_driver airprime_device = {
42 .num_interrupt_in = NUM_DONT_CARE, 280 .num_interrupt_in = NUM_DONT_CARE,
43 .num_bulk_in = NUM_DONT_CARE, 281 .num_bulk_in = NUM_DONT_CARE,
44 .num_bulk_out = NUM_DONT_CARE, 282 .num_bulk_out = NUM_DONT_CARE,
45 .num_ports = 1, 283 .open = airprime_open,
284 .close = airprime_close,
285 .write = airprime_write,
46}; 286};
47 287
48static int __init airprime_init(void) 288static int __init airprime_init(void)
49{ 289{
50 int retval; 290 int retval;
51 291
292 airprime_device.num_ports =
293 (endpoints > 0 && endpoints <= MAX_BULK_EPS) ? endpoints : NUM_BULK_EPS;
52 retval = usb_serial_register(&airprime_device); 294 retval = usb_serial_register(&airprime_device);
53 if (retval) 295 if (retval)
54 return retval; 296 return retval;
@@ -60,6 +302,8 @@ static int __init airprime_init(void)
60 302
61static void __exit airprime_exit(void) 303static void __exit airprime_exit(void)
62{ 304{
305 dbg("%s", __FUNCTION__);
306
63 usb_deregister(&airprime_driver); 307 usb_deregister(&airprime_driver);
64 usb_serial_deregister(&airprime_device); 308 usb_serial_deregister(&airprime_device);
65} 309}
@@ -67,3 +311,10 @@ static void __exit airprime_exit(void)
67module_init(airprime_init); 311module_init(airprime_init);
68module_exit(airprime_exit); 312module_exit(airprime_exit);
69MODULE_LICENSE("GPL"); 313MODULE_LICENSE("GPL");
314
315module_param(debug, bool, S_IRUGO | S_IWUSR);
316MODULE_PARM_DESC(debug, "Debug enabled");
317module_param(buffer_size, int, 0);
318MODULE_PARM_DESC(buffer_size, "Size of the transfer buffers in bytes (default 4096)");
319module_param(endpoints, int, 0);
320MODULE_PARM_DESC(endpoints, "Number of bulk EPs to configure (default 3)");
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 970d9ef0a7a5..ca52f12f0e24 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -1,4 +1,7 @@
1/* 1/*
2 * Copyright (C) 2006
3 * Simon Schulz (ark3116_driver <at> auctionant.de)
4 *
2 * ark3116 5 * ark3116
3 * - implements a driver for the arkmicro ark3116 chipset (vendor=0x6547, 6 * - implements a driver for the arkmicro ark3116 chipset (vendor=0x6547,
4 * productid=0x0232) (used in a datacable called KQ-U8A) 7 * productid=0x0232) (used in a datacable called KQ-U8A)
@@ -8,8 +11,6 @@
8 * 11 *
9 * - based on logs created by usbsnoopy 12 * - based on logs created by usbsnoopy
10 * 13 *
11 * Author : Simon Schulz [ark3116_driver<AT>auctionant.de]
12 *
13 * This program is free software; you can redistribute it and/or modify it 14 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the 15 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your 16 * Free Software Foundation; either version 2 of the License, or (at your
@@ -22,6 +23,8 @@
22#include <linux/module.h> 23#include <linux/module.h>
23#include <linux/usb.h> 24#include <linux/usb.h>
24#include <linux/usb/serial.h> 25#include <linux/usb/serial.h>
26#include <linux/serial.h>
27#include <asm/uaccess.h>
25 28
26 29
27static int debug; 30static int debug;
@@ -43,10 +46,10 @@ static inline void ARK3116_SND(struct usb_serial *serial, int seq,
43{ 46{
44 int result; 47 int result;
45 result = usb_control_msg(serial->dev, 48 result = usb_control_msg(serial->dev,
46 usb_sndctrlpipe(serial->dev,0), 49 usb_sndctrlpipe(serial->dev, 0),
47 request, requesttype, value, index, 50 request, requesttype, value, index,
48 NULL,0x00, 1000); 51 NULL, 0x00, 1000);
49 dbg("%03d > ok",seq); 52 dbg("%03d > ok", seq);
50} 53}
51 54
52static inline void ARK3116_RCV(struct usb_serial *serial, int seq, 55static inline void ARK3116_RCV(struct usb_serial *serial, int seq,
@@ -56,27 +59,25 @@ static inline void ARK3116_RCV(struct usb_serial *serial, int seq,
56{ 59{
57 int result; 60 int result;
58 result = usb_control_msg(serial->dev, 61 result = usb_control_msg(serial->dev,
59 usb_rcvctrlpipe(serial->dev,0), 62 usb_rcvctrlpipe(serial->dev, 0),
60 request, requesttype, value, index, 63 request, requesttype, value, index,
61 buf, 0x0000001, 1000); 64 buf, 0x0000001, 1000);
62 if (result) 65 if (result)
63 dbg("%03d < %d bytes [0x%02X]",seq, result, buf[0]); 66 dbg("%03d < %d bytes [0x%02X]", seq, result, buf[0]);
64 else 67 else
65 dbg("%03d < 0 bytes", seq); 68 dbg("%03d < 0 bytes", seq);
66} 69}
67 70
68
69static inline void ARK3116_RCV_QUIET(struct usb_serial *serial, 71static inline void ARK3116_RCV_QUIET(struct usb_serial *serial,
70 __u8 request, __u8 requesttype, 72 __u8 request, __u8 requesttype,
71 __u16 value, __u16 index, char *buf) 73 __u16 value, __u16 index, char *buf)
72{ 74{
73 usb_control_msg(serial->dev, 75 usb_control_msg(serial->dev,
74 usb_rcvctrlpipe(serial->dev,0), 76 usb_rcvctrlpipe(serial->dev, 0),
75 request, requesttype, value, index, 77 request, requesttype, value, index,
76 buf, 0x0000001, 1000); 78 buf, 0x0000001, 1000);
77} 79}
78 80
79
80static int ark3116_attach(struct usb_serial *serial) 81static int ark3116_attach(struct usb_serial *serial)
81{ 82{
82 char *buf; 83 char *buf;
@@ -84,10 +85,10 @@ static int ark3116_attach(struct usb_serial *serial)
84 int i; 85 int i;
85 86
86 for (i = 0; i < serial->num_ports; ++i) { 87 for (i = 0; i < serial->num_ports; ++i) {
87 priv = kmalloc (sizeof (struct ark3116_private), GFP_KERNEL); 88 priv = kmalloc(sizeof (struct ark3116_private), GFP_KERNEL);
88 if (!priv) 89 if (!priv)
89 goto cleanup; 90 goto cleanup;
90 memset (priv, 0x00, sizeof (struct ark3116_private)); 91 memset(priv, 0x00, sizeof (struct ark3116_private));
91 spin_lock_init(&priv->lock); 92 spin_lock_init(&priv->lock);
92 93
93 usb_set_serial_port_data(serial->port[i], priv); 94 usb_set_serial_port_data(serial->port[i], priv);
@@ -95,63 +96,62 @@ static int ark3116_attach(struct usb_serial *serial)
95 96
96 buf = kmalloc(1, GFP_KERNEL); 97 buf = kmalloc(1, GFP_KERNEL);
97 if (!buf) { 98 if (!buf) {
98 dbg("error kmalloc -> out of mem ?"); 99 dbg("error kmalloc -> out of mem?");
99 goto cleanup; 100 goto cleanup;
100 } 101 }
101 102
102 /* 3 */ 103 /* 3 */
103 ARK3116_SND(serial, 3,0xFE,0x40,0x0008,0x0002); 104 ARK3116_SND(serial, 3, 0xFE, 0x40, 0x0008, 0x0002);
104 ARK3116_SND(serial, 4,0xFE,0x40,0x0008,0x0001); 105 ARK3116_SND(serial, 4, 0xFE, 0x40, 0x0008, 0x0001);
105 ARK3116_SND(serial, 5,0xFE,0x40,0x0000,0x0008); 106 ARK3116_SND(serial, 5, 0xFE, 0x40, 0x0000, 0x0008);
106 ARK3116_SND(serial, 6,0xFE,0x40,0x0000,0x000B); 107 ARK3116_SND(serial, 6, 0xFE, 0x40, 0x0000, 0x000B);
107 108
108 /* <-- seq7 */ 109 /* <-- seq7 */
109 ARK3116_RCV(serial, 7,0xFE,0xC0,0x0000,0x0003, 0x00, buf); 110 ARK3116_RCV(serial, 7, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf);
110 ARK3116_SND(serial, 8,0xFE,0x40,0x0080,0x0003); 111 ARK3116_SND(serial, 8, 0xFE, 0x40, 0x0080, 0x0003);
111 ARK3116_SND(serial, 9,0xFE,0x40,0x001A,0x0000); 112 ARK3116_SND(serial, 9, 0xFE, 0x40, 0x001A, 0x0000);
112 ARK3116_SND(serial,10,0xFE,0x40,0x0000,0x0001); 113 ARK3116_SND(serial, 10, 0xFE, 0x40, 0x0000, 0x0001);
113 ARK3116_SND(serial,11,0xFE,0x40,0x0000,0x0003); 114 ARK3116_SND(serial, 11, 0xFE, 0x40, 0x0000, 0x0003);
114 115
115 /* <-- seq12 */ 116 /* <-- seq12 */
116 ARK3116_RCV(serial,12,0xFE,0xC0,0x0000,0x0004, 0x00, buf); 117 ARK3116_RCV(serial, 12, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf);
117 ARK3116_SND(serial,13,0xFE,0x40,0x0000,0x0004); 118 ARK3116_SND(serial, 13, 0xFE, 0x40, 0x0000, 0x0004);
118 119
119 /* 14 */ 120 /* 14 */
120 ARK3116_RCV(serial,14,0xFE,0xC0,0x0000,0x0004, 0x00, buf); 121 ARK3116_RCV(serial, 14, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf);
121 ARK3116_SND(serial,15,0xFE,0x40,0x0000,0x0004); 122 ARK3116_SND(serial, 15, 0xFE, 0x40, 0x0000, 0x0004);
122 123
123 /* 16 */ 124 /* 16 */
124 ARK3116_RCV(serial,16,0xFE,0xC0,0x0000,0x0004, 0x00, buf); 125 ARK3116_RCV(serial, 16, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf);
125 /* --> seq17 */ 126 /* --> seq17 */
126 ARK3116_SND(serial,17,0xFE,0x40,0x0001,0x0004); 127 ARK3116_SND(serial, 17, 0xFE, 0x40, 0x0001, 0x0004);
127 128
128 /* <-- seq18 */ 129 /* <-- seq18 */
129 ARK3116_RCV(serial,18,0xFE,0xC0,0x0000,0x0004, 0x01, buf); 130 ARK3116_RCV(serial, 18, 0xFE, 0xC0, 0x0000, 0x0004, 0x01, buf);
130 131
131 /* --> seq19 */ 132 /* --> seq19 */
132 ARK3116_SND(serial,19,0xFE,0x40,0x0003,0x0004); 133 ARK3116_SND(serial, 19, 0xFE, 0x40, 0x0003, 0x0004);
133
134 134
135 /* <-- seq20 */ 135 /* <-- seq20 */
136 /* seems like serial port status info (RTS, CTS,...) */ 136 /* seems like serial port status info (RTS, CTS, ...) */
137 /* returns modem control line status ?! */ 137 /* returns modem control line status?! */
138 ARK3116_RCV(serial,20,0xFE,0xC0,0x0000,0x0006, 0xFF, buf); 138 ARK3116_RCV(serial, 20, 0xFE, 0xC0, 0x0000, 0x0006, 0xFF, buf);
139 139
140 /* set 9600 baud & do some init ?! */ 140 /* set 9600 baud & do some init?! */
141 ARK3116_SND(serial,147,0xFE,0x40,0x0083,0x0003); 141 ARK3116_SND(serial, 147, 0xFE, 0x40, 0x0083, 0x0003);
142 ARK3116_SND(serial,148,0xFE,0x40,0x0038,0x0000); 142 ARK3116_SND(serial, 148, 0xFE, 0x40, 0x0038, 0x0000);
143 ARK3116_SND(serial,149,0xFE,0x40,0x0001,0x0001); 143 ARK3116_SND(serial, 149, 0xFE, 0x40, 0x0001, 0x0001);
144 ARK3116_SND(serial,150,0xFE,0x40,0x0003,0x0003); 144 ARK3116_SND(serial, 150, 0xFE, 0x40, 0x0003, 0x0003);
145 ARK3116_RCV(serial,151,0xFE,0xC0,0x0000,0x0004,0x03, buf); 145 ARK3116_RCV(serial, 151, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf);
146 ARK3116_SND(serial,152,0xFE,0x40,0x0000,0x0003); 146 ARK3116_SND(serial, 152, 0xFE, 0x40, 0x0000, 0x0003);
147 ARK3116_RCV(serial,153,0xFE,0xC0,0x0000,0x0003,0x00, buf); 147 ARK3116_RCV(serial, 153, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf);
148 ARK3116_SND(serial,154,0xFE,0x40,0x0003,0x0003); 148 ARK3116_SND(serial, 154, 0xFE, 0x40, 0x0003, 0x0003);
149 149
150 kfree(buf); 150 kfree(buf);
151 return(0); 151 return 0;
152 152
153cleanup: 153cleanup:
154 for (--i; i>=0; --i) 154 for (--i; i >= 0; --i)
155 usb_set_serial_port_data(serial->port[i], NULL); 155 usb_set_serial_port_data(serial->port[i], NULL);
156 return -ENOMEM; 156 return -ENOMEM;
157} 157}
@@ -180,7 +180,8 @@ static void ark3116_set_termios(struct usb_serial_port *port,
180 spin_lock_irqsave(&priv->lock, flags); 180 spin_lock_irqsave(&priv->lock, flags);
181 if (!priv->termios_initialized) { 181 if (!priv->termios_initialized) {
182 *(port->tty->termios) = tty_std_termios; 182 *(port->tty->termios) = tty_std_termios;
183 port->tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; 183 port->tty->termios->c_cflag = B9600 | CS8
184 | CREAD | HUPCL | CLOCAL;
184 priv->termios_initialized = 1; 185 priv->termios_initialized = 1;
185 } 186 }
186 spin_unlock_irqrestore(&priv->lock, flags); 187 spin_unlock_irqrestore(&priv->lock, flags);
@@ -204,8 +205,8 @@ static void ark3116_set_termios(struct usb_serial_port *port,
204 } 205 }
205 206
206 /* set data bit count (8/7/6/5) */ 207 /* set data bit count (8/7/6/5) */
207 if (cflag & CSIZE){ 208 if (cflag & CSIZE) {
208 switch (cflag & CSIZE){ 209 switch (cflag & CSIZE) {
209 case CS5: 210 case CS5:
210 config |= 0x00; 211 config |= 0x00;
211 dbg("setting CS5"); 212 dbg("setting CS5");
@@ -219,7 +220,8 @@ static void ark3116_set_termios(struct usb_serial_port *port,
219 dbg("setting CS7"); 220 dbg("setting CS7");
220 break; 221 break;
221 default: 222 default:
222 err ("CSIZE was set but not CS5-CS8, using CS8!"); 223 err("CSIZE was set but not CS5-CS8, using CS8!");
224 /* fall through */
223 case CS8: 225 case CS8:
224 config |= 0x03; 226 config |= 0x03;
225 dbg("setting CS8"); 227 dbg("setting CS8");
@@ -227,8 +229,8 @@ static void ark3116_set_termios(struct usb_serial_port *port,
227 } 229 }
228 } 230 }
229 231
230 /* set parity (NONE,EVEN,ODD) */ 232 /* set parity (NONE/EVEN/ODD) */
231 if (cflag & PARENB){ 233 if (cflag & PARENB) {
232 if (cflag & PARODD) { 234 if (cflag & PARODD) {
233 config |= 0x08; 235 config |= 0x08;
234 dbg("setting parity to ODD"); 236 dbg("setting parity to ODD");
@@ -240,20 +242,19 @@ static void ark3116_set_termios(struct usb_serial_port *port,
240 dbg("setting parity to NONE"); 242 dbg("setting parity to NONE");
241 } 243 }
242 244
243 /* SET STOPBIT (1/2) */ 245 /* set stop bit (1/2) */
244 if (cflag & CSTOPB) { 246 if (cflag & CSTOPB) {
245 config |= 0x04; 247 config |= 0x04;
246 dbg ("setting 2 stop bits"); 248 dbg("setting 2 stop bits");
247 } else { 249 } else {
248 dbg ("setting 1 stop bit"); 250 dbg("setting 1 stop bit");
249 } 251 }
250 252
251 253 /* set baudrate */
252 /* set baudrate: */
253 baud = 0; 254 baud = 0;
254 switch (cflag & CBAUD){ 255 switch (cflag & CBAUD) {
255 case B0: 256 case B0:
256 err("can't set 0baud, using 9600 instead"); 257 err("can't set 0 baud, using 9600 instead");
257 break; 258 break;
258 case B75: baud = 75; break; 259 case B75: baud = 75; break;
259 case B150: baud = 150; break; 260 case B150: baud = 150; break;
@@ -285,38 +286,40 @@ static void ark3116_set_termios(struct usb_serial_port *port,
285 */ 286 */
286 if (baud == 460800) 287 if (baud == 460800)
287 /* strange, for 460800 the formula is wrong 288 /* strange, for 460800 the formula is wrong
288 * (dont use round(), then 9600baud is wrong) */ 289 * if using round() then 9600baud is wrong) */
289 ark3116_baud = 7; 290 ark3116_baud = 7;
290 else 291 else
291 ark3116_baud = 3000000 / baud; 292 ark3116_baud = 3000000 / baud;
292 293
293 /* ? */ 294 /* ? */
294 ARK3116_RCV(serial,0,0xFE,0xC0,0x0000,0x0003, 0x03, buf); 295 ARK3116_RCV(serial, 0, 0xFE, 0xC0, 0x0000, 0x0003, 0x03, buf);
296
295 /* offset = buf[0]; */ 297 /* offset = buf[0]; */
296 /* offset = 0x03; */ 298 /* offset = 0x03; */
297 /* dbg("using 0x%04X as target for 0x0003:",0x0080+offset); */ 299 /* dbg("using 0x%04X as target for 0x0003:", 0x0080 + offset); */
298
299 300
300 /* set baudrate */ 301 /* set baudrate */
301 dbg("setting baudrate to %d (->reg=%d)",baud,ark3116_baud); 302 dbg("setting baudrate to %d (->reg=%d)", baud, ark3116_baud);
302 ARK3116_SND(serial,147,0xFE,0x40,0x0083,0x0003); 303 ARK3116_SND(serial, 147, 0xFE, 0x40, 0x0083, 0x0003);
303 ARK3116_SND(serial,148,0xFE,0x40,(ark3116_baud & 0x00FF) ,0x0000); 304 ARK3116_SND(serial, 148, 0xFE, 0x40,
304 ARK3116_SND(serial,149,0xFE,0x40,(ark3116_baud & 0xFF00)>>8,0x0001); 305 (ark3116_baud & 0x00FF), 0x0000);
305 ARK3116_SND(serial,150,0xFE,0x40,0x0003,0x0003); 306 ARK3116_SND(serial, 149, 0xFE, 0x40,
307 (ark3116_baud & 0xFF00) >> 8, 0x0001);
308 ARK3116_SND(serial, 150, 0xFE, 0x40, 0x0003, 0x0003);
306 309
307 /* ? */ 310 /* ? */
308 ARK3116_RCV(serial,151,0xFE,0xC0,0x0000,0x0004,0x03, buf); 311 ARK3116_RCV(serial, 151, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf);
309 ARK3116_SND(serial,152,0xFE,0x40,0x0000,0x0003); 312 ARK3116_SND(serial, 152, 0xFE, 0x40, 0x0000, 0x0003);
310 313
311 /* set data bit count, stop bit count & parity: */ 314 /* set data bit count, stop bit count & parity: */
312 dbg("updating bit count, stop bit or parity (cfg=0x%02X)", config); 315 dbg("updating bit count, stop bit or parity (cfg=0x%02X)", config);
313 ARK3116_RCV(serial,153,0xFE,0xC0,0x0000,0x0003,0x00, buf); 316 ARK3116_RCV(serial, 153, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf);
314 ARK3116_SND(serial,154,0xFE,0x40,config,0x0003); 317 ARK3116_SND(serial, 154, 0xFE, 0x40, config, 0x0003);
315 318
316 if (cflag & CRTSCTS) 319 if (cflag & CRTSCTS)
317 dbg("CRTSCTS not supported by chipset ?!"); 320 dbg("CRTSCTS not supported by chipset?!");
318 321
319 /* TEST ARK3116_SND(154,0xFE,0x40,0xFFFF, 0x0006); */ 322 /* TEST ARK3116_SND(154, 0xFE, 0x40, 0xFFFF, 0x0006); */
320 323
321 kfree(buf); 324 kfree(buf);
322 return; 325 return;
@@ -329,11 +332,11 @@ static int ark3116_open(struct usb_serial_port *port, struct file *filp)
329 char *buf; 332 char *buf;
330 int result = 0; 333 int result = 0;
331 334
332 dbg("%s - port %d", __FUNCTION__, port->number); 335 dbg("%s - port %d", __FUNCTION__, port->number);
333 336
334 buf = kmalloc(1, GFP_KERNEL); 337 buf = kmalloc(1, GFP_KERNEL);
335 if (!buf) { 338 if (!buf) {
336 dbg("error kmalloc -> out of mem ?"); 339 dbg("error kmalloc -> out of mem?");
337 return -ENOMEM; 340 return -ENOMEM;
338 } 341 }
339 342
@@ -342,44 +345,68 @@ static int ark3116_open(struct usb_serial_port *port, struct file *filp)
342 return result; 345 return result;
343 346
344 /* open */ 347 /* open */
345 ARK3116_RCV(serial,111,0xFE,0xC0,0x0000,0x0003, 0x02, buf); 348 ARK3116_RCV(serial, 111, 0xFE, 0xC0, 0x0000, 0x0003, 0x02, buf);
346 349
347 ARK3116_SND(serial,112,0xFE,0x40,0x0082,0x0003); 350 ARK3116_SND(serial, 112, 0xFE, 0x40, 0x0082, 0x0003);
348 ARK3116_SND(serial,113,0xFE,0x40,0x001A,0x0000); 351 ARK3116_SND(serial, 113, 0xFE, 0x40, 0x001A, 0x0000);
349 ARK3116_SND(serial,114,0xFE,0x40,0x0000,0x0001); 352 ARK3116_SND(serial, 114, 0xFE, 0x40, 0x0000, 0x0001);
350 ARK3116_SND(serial,115,0xFE,0x40,0x0002,0x0003); 353 ARK3116_SND(serial, 115, 0xFE, 0x40, 0x0002, 0x0003);
351 354
352 ARK3116_RCV(serial,116,0xFE,0xC0,0x0000,0x0004, 0x03, buf); 355 ARK3116_RCV(serial, 116, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf);
353 ARK3116_SND(serial,117,0xFE,0x40,0x0002,0x0004); 356 ARK3116_SND(serial, 117, 0xFE, 0x40, 0x0002, 0x0004);
354 357
355 ARK3116_RCV(serial,118,0xFE,0xC0,0x0000,0x0004, 0x02, buf); 358 ARK3116_RCV(serial, 118, 0xFE, 0xC0, 0x0000, 0x0004, 0x02, buf);
356 ARK3116_SND(serial,119,0xFE,0x40,0x0000,0x0004); 359 ARK3116_SND(serial, 119, 0xFE, 0x40, 0x0000, 0x0004);
357 360
358 ARK3116_RCV(serial,120,0xFE,0xC0,0x0000,0x0004, 0x00, buf); 361 ARK3116_RCV(serial, 120, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf);
359 362
360 ARK3116_SND(serial,121,0xFE,0x40,0x0001,0x0004); 363 ARK3116_SND(serial, 121, 0xFE, 0x40, 0x0001, 0x0004);
361 364
362 ARK3116_RCV(serial,122,0xFE,0xC0,0x0000,0x0004, 0x01, buf); 365 ARK3116_RCV(serial, 122, 0xFE, 0xC0, 0x0000, 0x0004, 0x01, buf);
363 366
364 ARK3116_SND(serial,123,0xFE,0x40,0x0003,0x0004); 367 ARK3116_SND(serial, 123, 0xFE, 0x40, 0x0003, 0x0004);
365 368
366 /* returns different values (control lines ?!) */ 369 /* returns different values (control lines?!) */
367 ARK3116_RCV(serial,124,0xFE,0xC0,0x0000,0x0006, 0xFF, buf); 370 ARK3116_RCV(serial, 124, 0xFE, 0xC0, 0x0000, 0x0006, 0xFF, buf);
368 371
369 /* initialise termios: */ 372 /* initialise termios */
370 if (port->tty) 373 if (port->tty)
371 ark3116_set_termios(port, &tmp_termios); 374 ark3116_set_termios(port, &tmp_termios);
372 375
373 kfree(buf); 376 kfree(buf);
374 377
375 return result; 378 return result;
376
377} 379}
378 380
379static int ark3116_ioctl(struct usb_serial_port *port, struct file *file, 381static int ark3116_ioctl(struct usb_serial_port *port, struct file *file,
380 unsigned int cmd, unsigned long arg) 382 unsigned int cmd, unsigned long arg)
381{ 383{
382 dbg("ioctl not supported yet..."); 384 struct serial_struct serstruct;
385 void __user *user_arg = (void __user *)arg;
386
387 switch (cmd) {
388 case TIOCGSERIAL:
389 /* XXX: Some of these values are probably wrong. */
390 memset(&serstruct, 0, sizeof (serstruct));
391 serstruct.type = PORT_16654;
392 serstruct.line = port->serial->minor;
393 serstruct.port = port->number;
394 serstruct.custom_divisor = 0;
395 serstruct.baud_base = 460800;
396
397 if (copy_to_user(user_arg, &serstruct, sizeof (serstruct)))
398 return -EFAULT;
399
400 return 0;
401 case TIOCSSERIAL:
402 if (copy_from_user(&serstruct, user_arg, sizeof (serstruct)))
403 return -EFAULT;
404 return 0;
405 default:
406 dbg("%s cmd 0x%04x not supported", __FUNCTION__, cmd);
407 break;
408 }
409
383 return -ENOIOCTLCMD; 410 return -ENOIOCTLCMD;
384} 411}
385 412
@@ -389,7 +416,7 @@ static int ark3116_tiocmget(struct usb_serial_port *port, struct file *file)
389 char *buf; 416 char *buf;
390 char temp; 417 char temp;
391 418
392 /* seems like serial port status info (RTS, CTS,...) is stored 419 /* seems like serial port status info (RTS, CTS, ...) is stored
393 * in reg(?) 0x0006 420 * in reg(?) 0x0006
394 * pcb connection point 11 = GND -> sets bit4 of response 421 * pcb connection point 11 = GND -> sets bit4 of response
395 * pcb connection point 7 = GND -> sets bit6 of response 422 * pcb connection point 7 = GND -> sets bit6 of response
@@ -401,16 +428,16 @@ static int ark3116_tiocmget(struct usb_serial_port *port, struct file *file)
401 return -ENOMEM; 428 return -ENOMEM;
402 } 429 }
403 430
404 /* read register: */ 431 /* read register */
405 ARK3116_RCV_QUIET(serial,0xFE,0xC0,0x0000,0x0006,buf); 432 ARK3116_RCV_QUIET(serial, 0xFE, 0xC0, 0x0000, 0x0006, buf);
406 temp = buf[0]; 433 temp = buf[0];
407 kfree(buf); 434 kfree(buf);
408 435
409 /* i do not really know if bit4=CTS and bit6=DSR... was just a 436 /* i do not really know if bit4=CTS and bit6=DSR... just a
410 * quick guess !! 437 * quick guess!
411 */ 438 */
412 return (temp & (1<<4) ? TIOCM_CTS : 0) | 439 return (temp & (1<<4) ? TIOCM_CTS : 0)
413 (temp & (1<<6) ? TIOCM_DSR : 0); 440 | (temp & (1<<6) ? TIOCM_DSR : 0);
414} 441}
415 442
416static struct usb_driver ark3116_driver = { 443static struct usb_driver ark3116_driver = {
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 6286aba86fae..d954ec34b018 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -214,14 +214,14 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
214 return (0); 214 return (0);
215 } 215 }
216 216
217 spin_lock(&port->lock); 217 spin_lock_bh(&port->lock);
218 if (port->write_urb_busy) { 218 if (port->write_urb_busy) {
219 spin_unlock(&port->lock); 219 spin_unlock_bh(&port->lock);
220 dbg("%s - already writing", __FUNCTION__); 220 dbg("%s - already writing", __FUNCTION__);
221 return 0; 221 return 0;
222 } 222 }
223 port->write_urb_busy = 1; 223 port->write_urb_busy = 1;
224 spin_unlock(&port->lock); 224 spin_unlock_bh(&port->lock);
225 225
226 spin_lock_irqsave(&priv->lock, flags); 226 spin_lock_irqsave(&priv->lock, flags);
227 227
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index ee70fddcab60..e1173c1aee37 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -129,6 +129,9 @@ struct cypress_private {
129 int cmd_ctrl; /* always set this to 1 before issuing a command */ 129 int cmd_ctrl; /* always set this to 1 before issuing a command */
130 struct cypress_buf *buf; /* write buffer */ 130 struct cypress_buf *buf; /* write buffer */
131 int write_urb_in_use; /* write urb in use indicator */ 131 int write_urb_in_use; /* write urb in use indicator */
132 int write_urb_interval; /* interval to use for write urb */
133 int read_urb_interval; /* interval to use for read urb */
134 int comm_is_ok; /* true if communication is (still) ok */
132 int termios_initialized; 135 int termios_initialized;
133 __u8 line_control; /* holds dtr / rts value */ 136 __u8 line_control; /* holds dtr / rts value */
134 __u8 current_status; /* received from last read - info on dsr,cts,cd,ri,etc */ 137 __u8 current_status; /* received from last read - info on dsr,cts,cd,ri,etc */
@@ -168,6 +171,7 @@ static int cypress_tiocmset (struct usb_serial_port *port, struct file *file,
168static int cypress_chars_in_buffer (struct usb_serial_port *port); 171static int cypress_chars_in_buffer (struct usb_serial_port *port);
169static void cypress_throttle (struct usb_serial_port *port); 172static void cypress_throttle (struct usb_serial_port *port);
170static void cypress_unthrottle (struct usb_serial_port *port); 173static void cypress_unthrottle (struct usb_serial_port *port);
174static void cypress_set_dead (struct usb_serial_port *port);
171static void cypress_read_int_callback (struct urb *urb, struct pt_regs *regs); 175static void cypress_read_int_callback (struct urb *urb, struct pt_regs *regs);
172static void cypress_write_int_callback (struct urb *urb, struct pt_regs *regs); 176static void cypress_write_int_callback (struct urb *urb, struct pt_regs *regs);
173/* baud helper functions */ 177/* baud helper functions */
@@ -288,6 +292,9 @@ static int cypress_serial_control (struct usb_serial_port *port, unsigned baud_m
288 292
289 priv = usb_get_serial_port_data(port); 293 priv = usb_get_serial_port_data(port);
290 294
295 if (!priv->comm_is_ok)
296 return -ENODEV;
297
291 switch(cypress_request_type) { 298 switch(cypress_request_type) {
292 case CYPRESS_SET_CONFIG: 299 case CYPRESS_SET_CONFIG:
293 300
@@ -365,13 +372,12 @@ static int cypress_serial_control (struct usb_serial_port *port, unsigned baud_m
365 if (tries++ >= 3) 372 if (tries++ >= 3)
366 break; 373 break;
367 374
368 if (retval == EPIPE) 375 } while (retval != 8 && retval != -ENODEV);
369 usb_clear_halt(port->serial->dev, 0x00);
370 } while (retval != 8 && retval != ENODEV);
371 376
372 if (retval != 8) 377 if (retval != 8) {
373 err("%s - failed sending serial line settings - %d", __FUNCTION__, retval); 378 err("%s - failed sending serial line settings - %d", __FUNCTION__, retval);
374 else { 379 cypress_set_dead(port);
380 } else {
375 spin_lock_irqsave(&priv->lock, flags); 381 spin_lock_irqsave(&priv->lock, flags);
376 priv->baud_rate = new_baudrate; 382 priv->baud_rate = new_baudrate;
377 priv->cbr_mask = baud_mask; 383 priv->cbr_mask = baud_mask;
@@ -392,12 +398,11 @@ static int cypress_serial_control (struct usb_serial_port *port, unsigned baud_m
392 if (tries++ >= 3) 398 if (tries++ >= 3)
393 break; 399 break;
394 400
395 if (retval == EPIPE) 401 } while (retval != 5 && retval != -ENODEV);
396 usb_clear_halt(port->serial->dev, 0x00);
397 } while (retval != 5 && retval != ENODEV);
398 402
399 if (retval != 5) { 403 if (retval != 5) {
400 err("%s - failed to retrieve serial line settings - %d", __FUNCTION__, retval); 404 err("%s - failed to retrieve serial line settings - %d", __FUNCTION__, retval);
405 cypress_set_dead(port);
401 return retval; 406 return retval;
402 } else { 407 } else {
403 spin_lock_irqsave(&priv->lock, flags); 408 spin_lock_irqsave(&priv->lock, flags);
@@ -419,6 +424,24 @@ static int cypress_serial_control (struct usb_serial_port *port, unsigned baud_m
419} /* cypress_serial_control */ 424} /* cypress_serial_control */
420 425
421 426
427static void cypress_set_dead(struct usb_serial_port *port)
428{
429 struct cypress_private *priv = usb_get_serial_port_data(port);
430 unsigned long flags;
431
432 spin_lock_irqsave(&priv->lock, flags);
433 if (!priv->comm_is_ok) {
434 spin_unlock_irqrestore(&priv->lock, flags);
435 return;
436 }
437 priv->comm_is_ok = 0;
438 spin_unlock_irqrestore(&priv->lock, flags);
439
440 err("cypress_m8 suspending failing port %d - interval might be too short",
441 port->number);
442}
443
444
422/* given a baud mask, it will return integer baud on success */ 445/* given a baud mask, it will return integer baud on success */
423static int mask_to_rate (unsigned mask) 446static int mask_to_rate (unsigned mask)
424{ 447{
@@ -472,13 +495,15 @@ static unsigned rate_to_mask (int rate)
472static int generic_startup (struct usb_serial *serial) 495static int generic_startup (struct usb_serial *serial)
473{ 496{
474 struct cypress_private *priv; 497 struct cypress_private *priv;
498 struct usb_serial_port *port = serial->port[0];
475 499
476 dbg("%s - port %d", __FUNCTION__, serial->port[0]->number); 500 dbg("%s - port %d", __FUNCTION__, port->number);
477 501
478 priv = kzalloc(sizeof (struct cypress_private), GFP_KERNEL); 502 priv = kzalloc(sizeof (struct cypress_private), GFP_KERNEL);
479 if (!priv) 503 if (!priv)
480 return -ENOMEM; 504 return -ENOMEM;
481 505
506 priv->comm_is_ok = !0;
482 spin_lock_init(&priv->lock); 507 spin_lock_init(&priv->lock);
483 priv->buf = cypress_buf_alloc(CYPRESS_BUF_SIZE); 508 priv->buf = cypress_buf_alloc(CYPRESS_BUF_SIZE);
484 if (priv->buf == NULL) { 509 if (priv->buf == NULL) {
@@ -489,13 +514,24 @@ static int generic_startup (struct usb_serial *serial)
489 514
490 usb_reset_configuration (serial->dev); 515 usb_reset_configuration (serial->dev);
491 516
492 interval = 1;
493 priv->cmd_ctrl = 0; 517 priv->cmd_ctrl = 0;
494 priv->line_control = 0; 518 priv->line_control = 0;
495 priv->termios_initialized = 0; 519 priv->termios_initialized = 0;
496 priv->rx_flags = 0; 520 priv->rx_flags = 0;
497 priv->cbr_mask = B300; 521 priv->cbr_mask = B300;
498 usb_set_serial_port_data(serial->port[0], priv); 522 if (interval > 0) {
523 priv->write_urb_interval = interval;
524 priv->read_urb_interval = interval;
525 dbg("%s - port %d read & write intervals forced to %d",
526 __FUNCTION__,port->number,interval);
527 } else {
528 priv->write_urb_interval = port->interrupt_out_urb->interval;
529 priv->read_urb_interval = port->interrupt_in_urb->interval;
530 dbg("%s - port %d intervals: read=%d write=%d",
531 __FUNCTION__,port->number,
532 priv->read_urb_interval,priv->write_urb_interval);
533 }
534 usb_set_serial_port_data(port, priv);
499 535
500 return 0; 536 return 0;
501} 537}
@@ -585,6 +621,9 @@ static int cypress_open (struct usb_serial_port *port, struct file *filp)
585 621
586 dbg("%s - port %d", __FUNCTION__, port->number); 622 dbg("%s - port %d", __FUNCTION__, port->number);
587 623
624 if (!priv->comm_is_ok)
625 return -EIO;
626
588 /* clear halts before open */ 627 /* clear halts before open */
589 usb_clear_halt(serial->dev, 0x81); 628 usb_clear_halt(serial->dev, 0x81);
590 usb_clear_halt(serial->dev, 0x02); 629 usb_clear_halt(serial->dev, 0x02);
@@ -624,11 +663,12 @@ static int cypress_open (struct usb_serial_port *port, struct file *filp)
624 usb_fill_int_urb(port->interrupt_in_urb, serial->dev, 663 usb_fill_int_urb(port->interrupt_in_urb, serial->dev,
625 usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress), 664 usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress),
626 port->interrupt_in_urb->transfer_buffer, port->interrupt_in_urb->transfer_buffer_length, 665 port->interrupt_in_urb->transfer_buffer, port->interrupt_in_urb->transfer_buffer_length,
627 cypress_read_int_callback, port, interval); 666 cypress_read_int_callback, port, priv->read_urb_interval);
628 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 667 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
629 668
630 if (result){ 669 if (result){
631 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result); 670 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result);
671 cypress_set_dead(port);
632 } 672 }
633 673
634 return result; 674 return result;
@@ -733,6 +773,9 @@ static void cypress_send(struct usb_serial_port *port)
733 struct cypress_private *priv = usb_get_serial_port_data(port); 773 struct cypress_private *priv = usb_get_serial_port_data(port);
734 unsigned long flags; 774 unsigned long flags;
735 775
776 if (!priv->comm_is_ok)
777 return;
778
736 dbg("%s - port %d", __FUNCTION__, port->number); 779 dbg("%s - port %d", __FUNCTION__, port->number);
737 dbg("%s - interrupt out size is %d", __FUNCTION__, port->interrupt_out_size); 780 dbg("%s - interrupt out size is %d", __FUNCTION__, port->interrupt_out_size);
738 781
@@ -806,14 +849,16 @@ send:
806 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, port->interrupt_out_size, 849 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, port->interrupt_out_size,
807 port->interrupt_out_urb->transfer_buffer); 850 port->interrupt_out_urb->transfer_buffer);
808 851
809 port->interrupt_out_urb->transfer_buffer_length = actual_size; 852 usb_fill_int_urb(port->interrupt_out_urb, port->serial->dev,
810 port->interrupt_out_urb->dev = port->serial->dev; 853 usb_sndintpipe(port->serial->dev, port->interrupt_out_endpointAddress),
811 port->interrupt_out_urb->interval = interval; 854 port->interrupt_out_buffer, port->interrupt_out_size,
855 cypress_write_int_callback, port, priv->write_urb_interval);
812 result = usb_submit_urb (port->interrupt_out_urb, GFP_ATOMIC); 856 result = usb_submit_urb (port->interrupt_out_urb, GFP_ATOMIC);
813 if (result) { 857 if (result) {
814 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, 858 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__,
815 result); 859 result);
816 priv->write_urb_in_use = 0; 860 priv->write_urb_in_use = 0;
861 cypress_set_dead(port);
817 } 862 }
818 863
819 spin_lock_irqsave(&priv->lock, flags); 864 spin_lock_irqsave(&priv->lock, flags);
@@ -1214,13 +1259,18 @@ static void cypress_unthrottle (struct usb_serial_port *port)
1214 priv->rx_flags = 0; 1259 priv->rx_flags = 0;
1215 spin_unlock_irqrestore(&priv->lock, flags); 1260 spin_unlock_irqrestore(&priv->lock, flags);
1216 1261
1262 if (!priv->comm_is_ok)
1263 return;
1264
1217 if (actually_throttled) { 1265 if (actually_throttled) {
1218 port->interrupt_in_urb->dev = port->serial->dev; 1266 port->interrupt_in_urb->dev = port->serial->dev;
1219 1267
1220 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 1268 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1221 if (result) 1269 if (result) {
1222 dev_err(&port->dev, "%s - failed submitting read urb, " 1270 dev_err(&port->dev, "%s - failed submitting read urb, "
1223 "error %d\n", __FUNCTION__, result); 1271 "error %d\n", __FUNCTION__, result);
1272 cypress_set_dead(port);
1273 }
1224 } 1274 }
1225} 1275}
1226 1276
@@ -1240,9 +1290,22 @@ static void cypress_read_int_callback(struct urb *urb, struct pt_regs *regs)
1240 1290
1241 dbg("%s - port %d", __FUNCTION__, port->number); 1291 dbg("%s - port %d", __FUNCTION__, port->number);
1242 1292
1243 if (urb->status) { 1293 switch (urb->status) {
1244 dbg("%s - nonzero read status received: %d", __FUNCTION__, 1294 case 0: /* success */
1245 urb->status); 1295 break;
1296 case -ECONNRESET:
1297 case -ENOENT:
1298 case -ESHUTDOWN:
1299 /* precursor to disconnect so just go away */
1300 return;
1301 case -EPIPE:
1302 usb_clear_halt(port->serial->dev,0x81);
1303 break;
1304 default:
1305 /* something ugly is going on... */
1306 dev_err(&urb->dev->dev,"%s - unexpected nonzero read status received: %d\n",
1307 __FUNCTION__,urb->status);
1308 cypress_set_dead(port);
1246 return; 1309 return;
1247 } 1310 }
1248 1311
@@ -1343,18 +1406,20 @@ continue_read:
1343 1406
1344 /* Continue trying to always read... unless the port has closed. */ 1407 /* Continue trying to always read... unless the port has closed. */
1345 1408
1346 if (port->open_count > 0) { 1409 if (port->open_count > 0 && priv->comm_is_ok) {
1347 usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev, 1410 usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev,
1348 usb_rcvintpipe(port->serial->dev, 1411 usb_rcvintpipe(port->serial->dev,
1349 port->interrupt_in_endpointAddress), 1412 port->interrupt_in_endpointAddress),
1350 port->interrupt_in_urb->transfer_buffer, 1413 port->interrupt_in_urb->transfer_buffer,
1351 port->interrupt_in_urb->transfer_buffer_length, 1414 port->interrupt_in_urb->transfer_buffer_length,
1352 cypress_read_int_callback, port, interval); 1415 cypress_read_int_callback, port, priv->read_urb_interval);
1353 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 1416 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1354 if (result) 1417 if (result) {
1355 dev_err(&urb->dev->dev, "%s - failed resubmitting " 1418 dev_err(&urb->dev->dev, "%s - failed resubmitting "
1356 "read urb, error %d\n", __FUNCTION__, 1419 "read urb, error %d\n", __FUNCTION__,
1357 result); 1420 result);
1421 cypress_set_dead(port);
1422 }
1358 } 1423 }
1359 1424
1360 return; 1425 return;
@@ -1380,20 +1445,26 @@ static void cypress_write_int_callback(struct urb *urb, struct pt_regs *regs)
1380 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); 1445 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
1381 priv->write_urb_in_use = 0; 1446 priv->write_urb_in_use = 0;
1382 return; 1447 return;
1383 case -EPIPE: /* no break needed */ 1448 case -EPIPE: /* no break needed; clear halt and resubmit */
1449 if (!priv->comm_is_ok)
1450 break;
1384 usb_clear_halt(port->serial->dev, 0x02); 1451 usb_clear_halt(port->serial->dev, 0x02);
1385 default:
1386 /* error in the urb, so we have to resubmit it */ 1452 /* error in the urb, so we have to resubmit it */
1387 dbg("%s - Overflow in write", __FUNCTION__);
1388 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); 1453 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
1389 port->interrupt_out_urb->transfer_buffer_length = 1; 1454 port->interrupt_out_urb->transfer_buffer_length = 1;
1390 port->interrupt_out_urb->dev = port->serial->dev; 1455 port->interrupt_out_urb->dev = port->serial->dev;
1391 result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC); 1456 result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC);
1392 if (result) 1457 if (!result)
1393 dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n",
1394 __FUNCTION__, result);
1395 else
1396 return; 1458 return;
1459 dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n",
1460 __FUNCTION__, result);
1461 cypress_set_dead(port);
1462 break;
1463 default:
1464 dev_err(&urb->dev->dev,"%s - unexpected nonzero write status received: %d\n",
1465 __FUNCTION__,urb->status);
1466 cypress_set_dead(port);
1467 break;
1397 } 1468 }
1398 1469
1399 priv->write_urb_in_use = 0; 1470 priv->write_urb_in_use = 0;
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index c6115aa1b445..e774a27c6c98 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -344,6 +344,7 @@ static struct usb_device_id id_table_combined [] = {
344 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2102_PID) }, 344 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2102_PID) },
345 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2103_PID) }, 345 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2103_PID) },
346 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2104_PID) }, 346 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2104_PID) },
347 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2106_PID) },
347 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2201_1_PID) }, 348 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2201_1_PID) },
348 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2201_2_PID) }, 349 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2201_2_PID) },
349 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2202_1_PID) }, 350 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2202_1_PID) },
@@ -507,6 +508,9 @@ static struct usb_device_id id_table_combined [] = {
507 { USB_DEVICE(FTDI_VID, FTDI_THORLABS_PID) }, 508 { USB_DEVICE(FTDI_VID, FTDI_THORLABS_PID) },
508 { USB_DEVICE(TESTO_VID, TESTO_USB_INTERFACE_PID) }, 509 { USB_DEVICE(TESTO_VID, TESTO_USB_INTERFACE_PID) },
509 { USB_DEVICE(FTDI_VID, FTDI_GAMMA_SCOUT_PID) }, 510 { USB_DEVICE(FTDI_VID, FTDI_GAMMA_SCOUT_PID) },
511 { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13M_PID) },
512 { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13S_PID) },
513 { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13U_PID) },
510 { }, /* Optional parameter entry */ 514 { }, /* Optional parameter entry */
511 { } /* Terminating entry */ 515 { } /* Terminating entry */
512}; 516};
@@ -1101,25 +1105,29 @@ static ssize_t store_event_char(struct device *dev, struct device_attribute *att
1101static DEVICE_ATTR(latency_timer, S_IWUSR | S_IRUGO, show_latency_timer, store_latency_timer); 1105static DEVICE_ATTR(latency_timer, S_IWUSR | S_IRUGO, show_latency_timer, store_latency_timer);
1102static DEVICE_ATTR(event_char, S_IWUSR, NULL, store_event_char); 1106static DEVICE_ATTR(event_char, S_IWUSR, NULL, store_event_char);
1103 1107
1104static void create_sysfs_attrs(struct usb_serial *serial) 1108static int create_sysfs_attrs(struct usb_serial *serial)
1105{ 1109{
1106 struct ftdi_private *priv; 1110 struct ftdi_private *priv;
1107 struct usb_device *udev; 1111 struct usb_device *udev;
1112 int retval = 0;
1108 1113
1109 dbg("%s",__FUNCTION__); 1114 dbg("%s",__FUNCTION__);
1110 1115
1111 priv = usb_get_serial_port_data(serial->port[0]); 1116 priv = usb_get_serial_port_data(serial->port[0]);
1112 udev = serial->dev; 1117 udev = serial->dev;
1113 1118
1114 /* XXX I've no idea if the original SIO supports the event_char 1119 /* XXX I've no idea if the original SIO supports the event_char
1115 * sysfs parameter, so I'm playing it safe. */ 1120 * sysfs parameter, so I'm playing it safe. */
1116 if (priv->chip_type != SIO) { 1121 if (priv->chip_type != SIO) {
1117 dbg("sysfs attributes for %s", ftdi_chip_name[priv->chip_type]); 1122 dbg("sysfs attributes for %s", ftdi_chip_name[priv->chip_type]);
1118 device_create_file(&udev->dev, &dev_attr_event_char); 1123 retval = device_create_file(&udev->dev, &dev_attr_event_char);
1119 if (priv->chip_type == FT232BM || priv->chip_type == FT2232C) { 1124 if ((!retval) &&
1120 device_create_file(&udev->dev, &dev_attr_latency_timer); 1125 (priv->chip_type == FT232BM || priv->chip_type == FT2232C)) {
1126 retval = device_create_file(&udev->dev,
1127 &dev_attr_latency_timer);
1121 } 1128 }
1122 } 1129 }
1130 return retval;
1123} 1131}
1124 1132
1125static void remove_sysfs_attrs(struct usb_serial *serial) 1133static void remove_sysfs_attrs(struct usb_serial *serial)
@@ -1162,7 +1170,8 @@ static int ftdi_sio_attach (struct usb_serial *serial)
1162 struct usb_serial_port *port = serial->port[0]; 1170 struct usb_serial_port *port = serial->port[0];
1163 struct ftdi_private *priv; 1171 struct ftdi_private *priv;
1164 struct ftdi_sio_quirk *quirk; 1172 struct ftdi_sio_quirk *quirk;
1165 1173 int retval;
1174
1166 dbg("%s",__FUNCTION__); 1175 dbg("%s",__FUNCTION__);
1167 1176
1168 priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL); 1177 priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL);
@@ -1203,15 +1212,18 @@ static int ftdi_sio_attach (struct usb_serial *serial)
1203 usb_set_serial_port_data(serial->port[0], priv); 1212 usb_set_serial_port_data(serial->port[0], priv);
1204 1213
1205 ftdi_determine_type (serial->port[0]); 1214 ftdi_determine_type (serial->port[0]);
1206 create_sysfs_attrs(serial); 1215 retval = create_sysfs_attrs(serial);
1216 if (retval)
1217 dev_err(&serial->dev->dev, "Error creating sysfs files, "
1218 "continuing\n");
1207 1219
1208 /* Check for device requiring special set up. */ 1220 /* Check for device requiring special set up. */
1209 quirk = (struct ftdi_sio_quirk *)usb_get_serial_data(serial); 1221 quirk = (struct ftdi_sio_quirk *)usb_get_serial_data(serial);
1210 if (quirk && quirk->setup) { 1222 if (quirk && quirk->setup) {
1211 quirk->setup(serial); 1223 quirk->setup(serial);
1212 } 1224 }
1213 1225
1214 return (0); 1226 return 0;
1215} /* ftdi_sio_attach */ 1227} /* ftdi_sio_attach */
1216 1228
1217 1229
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index 77299996f7ee..f0edb87d2dd5 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -111,6 +111,7 @@
111#define SEALEVEL_2102_PID 0x2102 /* SeaLINK+485 (2102) */ 111#define SEALEVEL_2102_PID 0x2102 /* SeaLINK+485 (2102) */
112#define SEALEVEL_2103_PID 0x2103 /* SeaLINK+232I (2103) */ 112#define SEALEVEL_2103_PID 0x2103 /* SeaLINK+232I (2103) */
113#define SEALEVEL_2104_PID 0x2104 /* SeaLINK+485I (2104) */ 113#define SEALEVEL_2104_PID 0x2104 /* SeaLINK+485I (2104) */
114#define SEALEVEL_2106_PID 0x9020 /* SeaLINK+422 (2106) */
114#define SEALEVEL_2201_1_PID 0x2211 /* SeaPORT+2/232 (2201) Port 1 */ 115#define SEALEVEL_2201_1_PID 0x2211 /* SeaPORT+2/232 (2201) Port 1 */
115#define SEALEVEL_2201_2_PID 0x2221 /* SeaPORT+2/232 (2201) Port 2 */ 116#define SEALEVEL_2201_2_PID 0x2221 /* SeaPORT+2/232 (2201) Port 2 */
116#define SEALEVEL_2202_1_PID 0x2212 /* SeaPORT+2/485 (2202) Port 1 */ 117#define SEALEVEL_2202_1_PID 0x2212 /* SeaPORT+2/485 (2202) Port 1 */
@@ -472,6 +473,15 @@
472 */ 473 */
473#define FTDI_GAMMA_SCOUT_PID 0xD678 /* Gamma Scout online */ 474#define FTDI_GAMMA_SCOUT_PID 0xD678 /* Gamma Scout online */
474 475
476/*
477 * Tactrix OpenPort (ECU) devices.
478 * OpenPort 1.3M submitted by Donour Sizemore.
479 * OpenPort 1.3S and 1.3U submitted by Ian Abbott.
480 */
481#define FTDI_TACTRIX_OPENPORT_13M_PID 0xCC48 /* OpenPort 1.3 Mitsubishi */
482#define FTDI_TACTRIX_OPENPORT_13S_PID 0xCC49 /* OpenPort 1.3 Subaru */
483#define FTDI_TACTRIX_OPENPORT_13U_PID 0xCC4A /* OpenPort 1.3 Universal */
484
475/* Commands */ 485/* Commands */
476#define FTDI_SIO_RESET 0 /* Reset the port */ 486#define FTDI_SIO_RESET 0 /* Reset the port */
477#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */ 487#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index 727852634be9..4b1196a8b09e 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Garmin GPS driver 2 * Garmin GPS driver
3 * 3 *
4 * Copyright (C) 2004 Hermann Kneissel herkne@users.sourceforge.net 4 * Copyright (C) 2006 Hermann Kneissel herkne@users.sourceforge.net
5 * 5 *
6 * The latest version of the driver can be found at 6 * The latest version of the driver can be found at
7 * http://sourceforge.net/projects/garmin-gps/ 7 * http://sourceforge.net/projects/garmin-gps/
@@ -37,6 +37,8 @@
37#include <linux/usb.h> 37#include <linux/usb.h>
38#include <linux/usb/serial.h> 38#include <linux/usb/serial.h>
39 39
40#include <linux/version.h>
41
40/* the mode to be set when the port ist opened */ 42/* the mode to be set when the port ist opened */
41static int initial_mode = 1; 43static int initial_mode = 1;
42 44
@@ -50,7 +52,7 @@ static int debug = 0;
50 */ 52 */
51 53
52#define VERSION_MAJOR 0 54#define VERSION_MAJOR 0
53#define VERSION_MINOR 23 55#define VERSION_MINOR 28
54 56
55#define _STR(s) #s 57#define _STR(s) #s
56#define _DRIVER_VERSION(a,b) "v" _STR(a) "." _STR(b) 58#define _DRIVER_VERSION(a,b) "v" _STR(a) "." _STR(b)
@@ -164,7 +166,8 @@ struct garmin_data {
164#define FLAGS_SESSION_REPLY1_SEEN 0x0080 166#define FLAGS_SESSION_REPLY1_SEEN 0x0080
165#define FLAGS_SESSION_REPLY2_SEEN 0x0040 167#define FLAGS_SESSION_REPLY2_SEEN 0x0040
166#define FLAGS_BULK_IN_ACTIVE 0x0020 168#define FLAGS_BULK_IN_ACTIVE 0x0020
167#define FLAGS_THROTTLED 0x0010 169#define FLAGS_BULK_IN_RESTART 0x0010
170#define FLAGS_THROTTLED 0x0008
168#define CLEAR_HALT_REQUIRED 0x0001 171#define CLEAR_HALT_REQUIRED 0x0001
169 172
170#define FLAGS_QUEUING 0x0100 173#define FLAGS_QUEUING 0x0100
@@ -224,7 +227,7 @@ static struct usb_driver garmin_driver = {
224 .probe = usb_serial_probe, 227 .probe = usb_serial_probe,
225 .disconnect = usb_serial_disconnect, 228 .disconnect = usb_serial_disconnect,
226 .id_table = id_table, 229 .id_table = id_table,
227 .no_dynamic_id = 1, 230 .no_dynamic_id = 1,
228}; 231};
229 232
230 233
@@ -270,7 +273,7 @@ static inline int isAbortTrfCmnd(const unsigned char *buf)
270 273
271 274
272static void send_to_tty(struct usb_serial_port *port, 275static void send_to_tty(struct usb_serial_port *port,
273 char *data, unsigned int actual_length) 276 char *data, unsigned int actual_length)
274{ 277{
275 struct tty_struct *tty = port->tty; 278 struct tty_struct *tty = port->tty;
276 279
@@ -294,15 +297,15 @@ static void send_to_tty(struct usb_serial_port *port,
294 * queue a received (usb-)packet for later processing 297 * queue a received (usb-)packet for later processing
295 */ 298 */
296static int pkt_add(struct garmin_data * garmin_data_p, 299static int pkt_add(struct garmin_data * garmin_data_p,
297 unsigned char *data, unsigned int data_length) 300 unsigned char *data, unsigned int data_length)
298{ 301{
302 int state = 0;
299 int result = 0; 303 int result = 0;
300 unsigned long flags; 304 unsigned long flags;
301 struct garmin_packet *pkt; 305 struct garmin_packet *pkt;
302 306
303 /* process only packets containg data ... */ 307 /* process only packets containg data ... */
304 if (data_length) { 308 if (data_length) {
305 garmin_data_p->flags |= FLAGS_QUEUING;
306 pkt = kmalloc(sizeof(struct garmin_packet)+data_length, 309 pkt = kmalloc(sizeof(struct garmin_packet)+data_length,
307 GFP_ATOMIC); 310 GFP_ATOMIC);
308 if (pkt == NULL) { 311 if (pkt == NULL) {
@@ -313,14 +316,16 @@ static int pkt_add(struct garmin_data * garmin_data_p,
313 memcpy(pkt->data, data, data_length); 316 memcpy(pkt->data, data, data_length);
314 317
315 spin_lock_irqsave(&garmin_data_p->lock, flags); 318 spin_lock_irqsave(&garmin_data_p->lock, flags);
319 garmin_data_p->flags |= FLAGS_QUEUING;
316 result = list_empty(&garmin_data_p->pktlist); 320 result = list_empty(&garmin_data_p->pktlist);
317 pkt->seq = garmin_data_p->seq_counter++; 321 pkt->seq = garmin_data_p->seq_counter++;
318 list_add_tail(&pkt->list, &garmin_data_p->pktlist); 322 list_add_tail(&pkt->list, &garmin_data_p->pktlist);
323 state = garmin_data_p->state;
319 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 324 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
320 325
321 /* in serial mode, if someone is waiting for data from 326 /* in serial mode, if someone is waiting for data from
322 the device, iconvert and send the next packet to tty. */ 327 the device, iconvert and send the next packet to tty. */
323 if (result && (garmin_data_p->state == STATE_GSP_WAIT_DATA)) { 328 if (result && (state == STATE_GSP_WAIT_DATA)) {
324 gsp_next_packet(garmin_data_p); 329 gsp_next_packet(garmin_data_p);
325 } 330 }
326 } 331 }
@@ -370,9 +375,9 @@ static void pkt_clear(struct garmin_data * garmin_data_p)
370static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id) 375static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id)
371{ 376{
372 __u8 pkt[10]; 377 __u8 pkt[10];
373 __u8 cksum = 0; 378 __u8 cksum = 0;
374 __u8 *ptr = pkt; 379 __u8 *ptr = pkt;
375 unsigned l = 0; 380 unsigned l = 0;
376 381
377 dbg("%s - pkt-id: 0x%X.", __FUNCTION__, 0xFF & pkt_id); 382 dbg("%s - pkt-id: 0x%X.", __FUNCTION__, 0xFF & pkt_id);
378 383
@@ -416,7 +421,7 @@ static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id)
416static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count) 421static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count)
417{ 422{
418 const __u8* recpkt = garmin_data_p->inbuffer+GSP_INITIAL_OFFSET; 423 const __u8* recpkt = garmin_data_p->inbuffer+GSP_INITIAL_OFFSET;
419 __le32 *usbdata = (__le32 *) garmin_data_p->inbuffer; 424 __le32 *usbdata = (__le32 *) garmin_data_p->inbuffer;
420 425
421 int cksum = 0; 426 int cksum = 0;
422 int n = 0; 427 int n = 0;
@@ -447,11 +452,11 @@ static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count)
447 n++; 452 n++;
448 } 453 }
449 454
450 if ((0xff & (cksum + *recpkt)) != 0) { 455 if ((0xff & (cksum + *recpkt)) != 0) {
451 dbg("%s - invalid checksum, expected %02x, got %02x", 456 dbg("%s - invalid checksum, expected %02x, got %02x",
452 __FUNCTION__, 0xff & -cksum, 0xff & *recpkt); 457 __FUNCTION__, 0xff & -cksum, 0xff & *recpkt);
453 return -EINVPKT; 458 return -EINVPKT;
454 } 459 }
455 460
456 usbdata[0] = __cpu_to_le32(GARMIN_LAYERID_APPL); 461 usbdata[0] = __cpu_to_le32(GARMIN_LAYERID_APPL);
457 usbdata[1] = __cpu_to_le32(pktid); 462 usbdata[1] = __cpu_to_le32(pktid);
@@ -491,20 +496,28 @@ static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count)
491 */ 496 */
492 497
493static int gsp_receive(struct garmin_data * garmin_data_p, 498static int gsp_receive(struct garmin_data * garmin_data_p,
494 const unsigned char *buf, int count) 499 const unsigned char *buf, int count)
495{ 500{
501 unsigned long flags;
496 int offs = 0; 502 int offs = 0;
497 int ack_or_nak_seen = 0; 503 int ack_or_nak_seen = 0;
498 int i = 0; 504 int i = 0;
499 __u8 *dest = garmin_data_p->inbuffer; 505 __u8 *dest;
500 int size = garmin_data_p->insize; 506 int size;
501 // dleSeen: set if last byte read was a DLE 507 // dleSeen: set if last byte read was a DLE
502 int dleSeen = garmin_data_p->flags & FLAGS_GSP_DLESEEN; 508 int dleSeen;
503 // skip: if set, skip incoming data until possible start of 509 // skip: if set, skip incoming data until possible start of
504 // new packet 510 // new packet
505 int skip = garmin_data_p->flags & FLAGS_GSP_SKIP; 511 int skip;
506 __u8 data; 512 __u8 data;
507 513
514 spin_lock_irqsave(&garmin_data_p->lock, flags);
515 dest = garmin_data_p->inbuffer;
516 size = garmin_data_p->insize;
517 dleSeen = garmin_data_p->flags & FLAGS_GSP_DLESEEN;
518 skip = garmin_data_p->flags & FLAGS_GSP_SKIP;
519 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
520
508 dbg("%s - dle=%d skip=%d size=%d count=%d", 521 dbg("%s - dle=%d skip=%d size=%d count=%d",
509 __FUNCTION__, dleSeen, skip, size, count); 522 __FUNCTION__, dleSeen, skip, size, count);
510 523
@@ -572,6 +585,8 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
572 } 585 }
573 } 586 }
574 587
588 spin_lock_irqsave(&garmin_data_p->lock, flags);
589
575 garmin_data_p->insize = size; 590 garmin_data_p->insize = size;
576 591
577 // copy flags back to structure 592 // copy flags back to structure
@@ -587,6 +602,11 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
587 602
588 if (ack_or_nak_seen) { 603 if (ack_or_nak_seen) {
589 garmin_data_p->state = STATE_GSP_WAIT_DATA; 604 garmin_data_p->state = STATE_GSP_WAIT_DATA;
605 }
606
607 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
608
609 if (ack_or_nak_seen) {
590 gsp_next_packet(garmin_data_p); 610 gsp_next_packet(garmin_data_p);
591 } 611 }
592 612
@@ -676,7 +696,7 @@ static int gsp_send(struct garmin_data * garmin_data_p,
676 src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH; 696 src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH;
677 if (k > (GARMIN_PKTHDR_LENGTH-2)) { 697 if (k > (GARMIN_PKTHDR_LENGTH-2)) {
678 /* can't add stuffing DLEs in place, move data to end 698 /* can't add stuffing DLEs in place, move data to end
679 of buffer ... */ 699 of buffer ... */
680 dst = garmin_data_p->outbuffer+GPS_OUT_BUFSIZ-datalen; 700 dst = garmin_data_p->outbuffer+GPS_OUT_BUFSIZ-datalen;
681 memcpy(dst, src, datalen); 701 memcpy(dst, src, datalen);
682 src = dst; 702 src = dst;
@@ -755,8 +775,9 @@ static void gsp_next_packet(struct garmin_data * garmin_data_p)
755 * or even incomplete packets 775 * or even incomplete packets
756 */ 776 */
757static int nat_receive(struct garmin_data * garmin_data_p, 777static int nat_receive(struct garmin_data * garmin_data_p,
758 const unsigned char *buf, int count) 778 const unsigned char *buf, int count)
759{ 779{
780 unsigned long flags;
760 __u8 * dest; 781 __u8 * dest;
761 int offs = 0; 782 int offs = 0;
762 int result = count; 783 int result = count;
@@ -803,7 +824,9 @@ static int nat_receive(struct garmin_data * garmin_data_p,
803 /* if this was an abort-transfer command, 824 /* if this was an abort-transfer command,
804 flush all queued data. */ 825 flush all queued data. */
805 if (isAbortTrfCmnd(garmin_data_p->inbuffer)) { 826 if (isAbortTrfCmnd(garmin_data_p->inbuffer)) {
827 spin_lock_irqsave(&garmin_data_p->lock, flags);
806 garmin_data_p->flags |= FLAGS_DROP_DATA; 828 garmin_data_p->flags |= FLAGS_DROP_DATA;
829 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
807 pkt_clear(garmin_data_p); 830 pkt_clear(garmin_data_p);
808 } 831 }
809 } 832 }
@@ -839,12 +862,15 @@ static void priv_status_resp(struct usb_serial_port *port)
839 862
840static int process_resetdev_request(struct usb_serial_port *port) 863static int process_resetdev_request(struct usb_serial_port *port)
841{ 864{
865 unsigned long flags;
842 int status; 866 int status;
843 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 867 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
844 868
869 spin_lock_irqsave(&garmin_data_p->lock, flags);
845 garmin_data_p->flags &= ~(CLEAR_HALT_REQUIRED); 870 garmin_data_p->flags &= ~(CLEAR_HALT_REQUIRED);
846 garmin_data_p->state = STATE_RESET; 871 garmin_data_p->state = STATE_RESET;
847 garmin_data_p->serial_num = 0; 872 garmin_data_p->serial_num = 0;
873 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
848 874
849 usb_kill_urb (port->interrupt_in_urb); 875 usb_kill_urb (port->interrupt_in_urb);
850 dbg("%s - usb_reset_device", __FUNCTION__ ); 876 dbg("%s - usb_reset_device", __FUNCTION__ );
@@ -862,6 +888,7 @@ static int process_resetdev_request(struct usb_serial_port *port)
862 */ 888 */
863static int garmin_clear(struct garmin_data * garmin_data_p) 889static int garmin_clear(struct garmin_data * garmin_data_p)
864{ 890{
891 unsigned long flags;
865 int status = 0; 892 int status = 0;
866 893
867 struct usb_serial_port *port = garmin_data_p->port; 894 struct usb_serial_port *port = garmin_data_p->port;
@@ -875,8 +902,10 @@ static int garmin_clear(struct garmin_data * garmin_data_p)
875 /* flush all queued data */ 902 /* flush all queued data */
876 pkt_clear(garmin_data_p); 903 pkt_clear(garmin_data_p);
877 904
905 spin_lock_irqsave(&garmin_data_p->lock, flags);
878 garmin_data_p->insize = 0; 906 garmin_data_p->insize = 0;
879 garmin_data_p->outsize = 0; 907 garmin_data_p->outsize = 0;
908 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
880 909
881 return status; 910 return status;
882} 911}
@@ -888,6 +917,7 @@ static int garmin_clear(struct garmin_data * garmin_data_p)
888 917
889static int garmin_init_session(struct usb_serial_port *port) 918static int garmin_init_session(struct usb_serial_port *port)
890{ 919{
920 unsigned long flags;
891 struct usb_serial *serial = port->serial; 921 struct usb_serial *serial = port->serial;
892 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 922 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
893 int status = 0; 923 int status = 0;
@@ -913,7 +943,9 @@ static int garmin_init_session(struct usb_serial_port *port)
913 943
914 if (status >= 0) { 944 if (status >= 0) {
915 945
946 spin_lock_irqsave(&garmin_data_p->lock, flags);
916 garmin_data_p->ignorePkts++; 947 garmin_data_p->ignorePkts++;
948 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
917 949
918 /* not needed, but the win32 driver does it too ... */ 950 /* not needed, but the win32 driver does it too ... */
919 status = garmin_write_bulk(port, 951 status = garmin_write_bulk(port,
@@ -921,7 +953,9 @@ static int garmin_init_session(struct usb_serial_port *port)
921 sizeof(GARMIN_START_SESSION_REQ2)); 953 sizeof(GARMIN_START_SESSION_REQ2));
922 if (status >= 0) { 954 if (status >= 0) {
923 status = 0; 955 status = 0;
956 spin_lock_irqsave(&garmin_data_p->lock, flags);
924 garmin_data_p->ignorePkts++; 957 garmin_data_p->ignorePkts++;
958 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
925 } 959 }
926 } 960 }
927 } 961 }
@@ -935,6 +969,7 @@ static int garmin_init_session(struct usb_serial_port *port)
935 969
936static int garmin_open (struct usb_serial_port *port, struct file *filp) 970static int garmin_open (struct usb_serial_port *port, struct file *filp)
937{ 971{
972 unsigned long flags;
938 int status = 0; 973 int status = 0;
939 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 974 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
940 975
@@ -948,9 +983,11 @@ static int garmin_open (struct usb_serial_port *port, struct file *filp)
948 if (port->tty) 983 if (port->tty)
949 port->tty->low_latency = 1; 984 port->tty->low_latency = 1;
950 985
986 spin_lock_irqsave(&garmin_data_p->lock, flags);
951 garmin_data_p->mode = initial_mode; 987 garmin_data_p->mode = initial_mode;
952 garmin_data_p->count = 0; 988 garmin_data_p->count = 0;
953 garmin_data_p->flags = 0; 989 garmin_data_p->flags = 0;
990 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
954 991
955 /* shutdown any bulk reads that might be going on */ 992 /* shutdown any bulk reads that might be going on */
956 usb_kill_urb (port->write_urb); 993 usb_kill_urb (port->write_urb);
@@ -996,6 +1033,7 @@ static void garmin_close (struct usb_serial_port *port, struct file * filp)
996 1033
997static void garmin_write_bulk_callback (struct urb *urb, struct pt_regs *regs) 1034static void garmin_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
998{ 1035{
1036 unsigned long flags;
999 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1037 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1000 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1038 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1001 1039
@@ -1007,7 +1045,9 @@ static void garmin_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
1007 if (urb->status) { 1045 if (urb->status) {
1008 dbg("%s - nonzero write bulk status received: %d", 1046 dbg("%s - nonzero write bulk status received: %d",
1009 __FUNCTION__, urb->status); 1047 __FUNCTION__, urb->status);
1048 spin_lock_irqsave(&garmin_data_p->lock, flags);
1010 garmin_data_p->flags |= CLEAR_HALT_REQUIRED; 1049 garmin_data_p->flags |= CLEAR_HALT_REQUIRED;
1050 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1011 } 1051 }
1012 1052
1013 usb_serial_port_softint(port); 1053 usb_serial_port_softint(port);
@@ -1015,8 +1055,9 @@ static void garmin_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
1015 1055
1016 1056
1017static int garmin_write_bulk (struct usb_serial_port *port, 1057static int garmin_write_bulk (struct usb_serial_port *port,
1018 const unsigned char *buf, int count) 1058 const unsigned char *buf, int count)
1019{ 1059{
1060 unsigned long flags;
1020 struct usb_serial *serial = port->serial; 1061 struct usb_serial *serial = port->serial;
1021 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1062 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1022 struct urb *urb; 1063 struct urb *urb;
@@ -1026,7 +1067,9 @@ static int garmin_write_bulk (struct usb_serial_port *port,
1026 dbg("%s - port %d, state %d", __FUNCTION__, port->number, 1067 dbg("%s - port %d, state %d", __FUNCTION__, port->number,
1027 garmin_data_p->state); 1068 garmin_data_p->state);
1028 1069
1070 spin_lock_irqsave(&garmin_data_p->lock, flags);
1029 garmin_data_p->flags &= ~FLAGS_DROP_DATA; 1071 garmin_data_p->flags &= ~FLAGS_DROP_DATA;
1072 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1030 1073
1031 buffer = kmalloc (count, GFP_ATOMIC); 1074 buffer = kmalloc (count, GFP_ATOMIC);
1032 if (!buffer) { 1075 if (!buffer) {
@@ -1053,7 +1096,9 @@ static int garmin_write_bulk (struct usb_serial_port *port,
1053 urb->transfer_flags |= URB_ZERO_PACKET; 1096 urb->transfer_flags |= URB_ZERO_PACKET;
1054 1097
1055 if (GARMIN_LAYERID_APPL == getLayerId(buffer)) { 1098 if (GARMIN_LAYERID_APPL == getLayerId(buffer)) {
1099 spin_lock_irqsave(&garmin_data_p->lock, flags);
1056 garmin_data_p->flags |= FLAGS_APP_REQ_SEEN; 1100 garmin_data_p->flags |= FLAGS_APP_REQ_SEEN;
1101 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1057 if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { 1102 if (garmin_data_p->mode == MODE_GARMIN_SERIAL) {
1058 pkt_clear(garmin_data_p); 1103 pkt_clear(garmin_data_p);
1059 garmin_data_p->state = STATE_GSP_WAIT_DATA; 1104 garmin_data_p->state = STATE_GSP_WAIT_DATA;
@@ -1087,8 +1132,9 @@ static int garmin_write_bulk (struct usb_serial_port *port,
1087 1132
1088 1133
1089static int garmin_write (struct usb_serial_port *port, 1134static int garmin_write (struct usb_serial_port *port,
1090 const unsigned char *buf, int count) 1135 const unsigned char *buf, int count)
1091{ 1136{
1137 unsigned long flags;
1092 int pktid, pktsiz, len; 1138 int pktid, pktsiz, len;
1093 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1139 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1094 __le32 *privpkt = (__le32 *)garmin_data_p->privpkt; 1140 __le32 *privpkt = (__le32 *)garmin_data_p->privpkt;
@@ -1139,7 +1185,9 @@ static int garmin_write (struct usb_serial_port *port,
1139 break; 1185 break;
1140 1186
1141 case PRIV_PKTID_RESET_REQ: 1187 case PRIV_PKTID_RESET_REQ:
1188 spin_lock_irqsave(&garmin_data_p->lock, flags);
1142 garmin_data_p->flags |= FLAGS_APP_REQ_SEEN; 1189 garmin_data_p->flags |= FLAGS_APP_REQ_SEEN;
1190 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1143 break; 1191 break;
1144 1192
1145 case PRIV_PKTID_SET_DEF_MODE: 1193 case PRIV_PKTID_SET_DEF_MODE:
@@ -1155,6 +1203,8 @@ static int garmin_write (struct usb_serial_port *port,
1155 } 1203 }
1156 } 1204 }
1157 1205
1206 garmin_data_p->ignorePkts = 0;
1207
1158 if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { 1208 if (garmin_data_p->mode == MODE_GARMIN_SERIAL) {
1159 return gsp_receive(garmin_data_p, buf, count); 1209 return gsp_receive(garmin_data_p, buf, count);
1160 } else { /* MODE_NATIVE */ 1210 } else { /* MODE_NATIVE */
@@ -1177,10 +1227,10 @@ static int garmin_chars_in_buffer (struct usb_serial_port *port)
1177{ 1227{
1178 /* 1228 /*
1179 * Report back the number of bytes currently in our input buffer. 1229 * Report back the number of bytes currently in our input buffer.
1180 * Will this lock up the driver - the buffer contains an incomplete 1230 * Will this lock up the driver - the buffer contains an incomplete
1181 * package which will not be written to the device until it 1231 * package which will not be written to the device until it
1182 * has been completed ? 1232 * has been completed ?
1183 */ 1233 */
1184 //struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1234 //struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1185 //return garmin_data_p->insize; 1235 //return garmin_data_p->insize;
1186 return 0; 1236 return 0;
@@ -1190,6 +1240,8 @@ static int garmin_chars_in_buffer (struct usb_serial_port *port)
1190static void garmin_read_process(struct garmin_data * garmin_data_p, 1240static void garmin_read_process(struct garmin_data * garmin_data_p,
1191 unsigned char *data, unsigned data_length) 1241 unsigned char *data, unsigned data_length)
1192{ 1242{
1243 unsigned long flags;
1244
1193 if (garmin_data_p->flags & FLAGS_DROP_DATA) { 1245 if (garmin_data_p->flags & FLAGS_DROP_DATA) {
1194 /* abort-transfer cmd is actice */ 1246 /* abort-transfer cmd is actice */
1195 dbg("%s - pkt dropped", __FUNCTION__); 1247 dbg("%s - pkt dropped", __FUNCTION__);
@@ -1200,11 +1252,14 @@ static void garmin_read_process(struct garmin_data * garmin_data_p,
1200 if a reset is required or not when closing 1252 if a reset is required or not when closing
1201 the device */ 1253 the device */
1202 if (0 == memcmp(data, GARMIN_APP_LAYER_REPLY, 1254 if (0 == memcmp(data, GARMIN_APP_LAYER_REPLY,
1203 sizeof(GARMIN_APP_LAYER_REPLY))) 1255 sizeof(GARMIN_APP_LAYER_REPLY))) {
1256 spin_lock_irqsave(&garmin_data_p->lock, flags);
1204 garmin_data_p->flags |= FLAGS_APP_RESP_SEEN; 1257 garmin_data_p->flags |= FLAGS_APP_RESP_SEEN;
1258 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1259 }
1205 1260
1206 /* if throttling is active or postprecessing is required 1261 /* if throttling is active or postprecessing is required
1207 put the received data in th input queue, otherwise 1262 put the received data in the input queue, otherwise
1208 send it directly to the tty port */ 1263 send it directly to the tty port */
1209 if (garmin_data_p->flags & FLAGS_QUEUING) { 1264 if (garmin_data_p->flags & FLAGS_QUEUING) {
1210 pkt_add(garmin_data_p, data, data_length); 1265 pkt_add(garmin_data_p, data, data_length);
@@ -1221,6 +1276,7 @@ static void garmin_read_process(struct garmin_data * garmin_data_p,
1221 1276
1222static void garmin_read_bulk_callback (struct urb *urb, struct pt_regs *regs) 1277static void garmin_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
1223{ 1278{
1279 unsigned long flags;
1224 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1280 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1225 struct usb_serial *serial = port->serial; 1281 struct usb_serial *serial = port->serial;
1226 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1282 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
@@ -1245,19 +1301,30 @@ static void garmin_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
1245 1301
1246 garmin_read_process(garmin_data_p, data, urb->actual_length); 1302 garmin_read_process(garmin_data_p, data, urb->actual_length);
1247 1303
1248 /* Continue trying to read until nothing more is received */ 1304 if (urb->actual_length == 0 &&
1249 if (urb->actual_length > 0) { 1305 0 != (garmin_data_p->flags & FLAGS_BULK_IN_RESTART)) {
1250 usb_fill_bulk_urb (port->read_urb, serial->dev, 1306 spin_lock_irqsave(&garmin_data_p->lock, flags);
1251 usb_rcvbulkpipe (serial->dev, 1307 garmin_data_p->flags &= ~FLAGS_BULK_IN_RESTART;
1252 port->bulk_in_endpointAddress), 1308 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1253 port->read_urb->transfer_buffer,
1254 port->read_urb->transfer_buffer_length,
1255 garmin_read_bulk_callback, port);
1256 status = usb_submit_urb(port->read_urb, GFP_ATOMIC); 1309 status = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1257 if (status) 1310 if (status)
1258 dev_err(&port->dev, 1311 dev_err(&port->dev,
1259 "%s - failed resubmitting read urb, error %d\n", 1312 "%s - failed resubmitting read urb, error %d\n",
1260 __FUNCTION__, status); 1313 __FUNCTION__, status);
1314 } else if (urb->actual_length > 0) {
1315 /* Continue trying to read until nothing more is received */
1316 if (0 == (garmin_data_p->flags & FLAGS_THROTTLED)) {
1317 status = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1318 if (status)
1319 dev_err(&port->dev,
1320 "%s - failed resubmitting read urb, error %d\n",
1321 __FUNCTION__, status);
1322 }
1323 } else {
1324 dbg("%s - end of bulk data", __FUNCTION__);
1325 spin_lock_irqsave(&garmin_data_p->lock, flags);
1326 garmin_data_p->flags &= ~FLAGS_BULK_IN_ACTIVE;
1327 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1261 } 1328 }
1262 return; 1329 return;
1263} 1330}
@@ -1265,6 +1332,7 @@ static void garmin_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
1265 1332
1266static void garmin_read_int_callback (struct urb *urb, struct pt_regs *regs) 1333static void garmin_read_int_callback (struct urb *urb, struct pt_regs *regs)
1267{ 1334{
1335 unsigned long flags;
1268 int status; 1336 int status;
1269 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1337 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1270 struct usb_serial *serial = port->serial; 1338 struct usb_serial *serial = port->serial;
@@ -1297,25 +1365,41 @@ static void garmin_read_int_callback (struct urb *urb, struct pt_regs *regs)
1297 1365
1298 dbg("%s - bulk data available.", __FUNCTION__); 1366 dbg("%s - bulk data available.", __FUNCTION__);
1299 1367
1300 /* bulk data available */ 1368 if (0 == (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) {
1301 usb_fill_bulk_urb (port->read_urb, serial->dev, 1369
1302 usb_rcvbulkpipe (serial->dev, 1370 /* bulk data available */
1303 port->bulk_in_endpointAddress), 1371 usb_fill_bulk_urb (port->read_urb, serial->dev,
1304 port->read_urb->transfer_buffer, 1372 usb_rcvbulkpipe (serial->dev,
1305 port->read_urb->transfer_buffer_length, 1373 port->bulk_in_endpointAddress),
1306 garmin_read_bulk_callback, port); 1374 port->read_urb->transfer_buffer,
1307 status = usb_submit_urb(port->read_urb, GFP_KERNEL); 1375 port->read_urb->transfer_buffer_length,
1308 if (status) { 1376 garmin_read_bulk_callback, port);
1309 dev_err(&port->dev, 1377 status = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1310 "%s - failed submitting read urb, error %d\n", 1378 if (status) {
1311 __FUNCTION__, status); 1379 dev_err(&port->dev,
1380 "%s - failed submitting read urb, error %d\n",
1381 __FUNCTION__, status);
1382 } else {
1383 spin_lock_irqsave(&garmin_data_p->lock, flags);
1384 garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE;
1385 /* do not send this packet to the user */
1386 garmin_data_p->ignorePkts = 1;
1387 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1388 }
1389 } else {
1390 /* bulk-in transfer still active */
1391 spin_lock_irqsave(&garmin_data_p->lock, flags);
1392 garmin_data_p->flags |= FLAGS_BULK_IN_RESTART;
1393 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1312 } 1394 }
1313 1395
1314 } else if (urb->actual_length == (4+sizeof(GARMIN_START_SESSION_REPLY)) 1396 } else if (urb->actual_length == (4+sizeof(GARMIN_START_SESSION_REPLY))
1315 && 0 == memcmp(data, GARMIN_START_SESSION_REPLY, 1397 && 0 == memcmp(data, GARMIN_START_SESSION_REPLY,
1316 sizeof(GARMIN_START_SESSION_REPLY))) { 1398 sizeof(GARMIN_START_SESSION_REPLY))) {
1317 1399
1400 spin_lock_irqsave(&garmin_data_p->lock, flags);
1318 garmin_data_p->flags |= FLAGS_SESSION_REPLY1_SEEN; 1401 garmin_data_p->flags |= FLAGS_SESSION_REPLY1_SEEN;
1402 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1319 1403
1320 /* save the serial number */ 1404 /* save the serial number */
1321 garmin_data_p->serial_num 1405 garmin_data_p->serial_num
@@ -1330,7 +1414,9 @@ static void garmin_read_int_callback (struct urb *urb, struct pt_regs *regs)
1330 ignore it. */ 1414 ignore it. */
1331 dbg("%s - pkt ignored (%d)", 1415 dbg("%s - pkt ignored (%d)",
1332 __FUNCTION__, garmin_data_p->ignorePkts); 1416 __FUNCTION__, garmin_data_p->ignorePkts);
1417 spin_lock_irqsave(&garmin_data_p->lock, flags);
1333 garmin_data_p->ignorePkts--; 1418 garmin_data_p->ignorePkts--;
1419 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1334 } else { 1420 } else {
1335 garmin_read_process(garmin_data_p, data, urb->actual_length); 1421 garmin_read_process(garmin_data_p, data, urb->actual_length);
1336 } 1422 }
@@ -1351,18 +1437,20 @@ static void garmin_read_int_callback (struct urb *urb, struct pt_regs *regs)
1351 */ 1437 */
1352static int garmin_flush_queue(struct garmin_data * garmin_data_p) 1438static int garmin_flush_queue(struct garmin_data * garmin_data_p)
1353{ 1439{
1440 unsigned long flags;
1354 struct garmin_packet *pkt; 1441 struct garmin_packet *pkt;
1355 1442
1356 if ((garmin_data_p->flags & FLAGS_THROTTLED) == 0) { 1443 if ((garmin_data_p->flags & FLAGS_THROTTLED) == 0) {
1357 pkt = pkt_pop(garmin_data_p); 1444 pkt = pkt_pop(garmin_data_p);
1358 if (pkt != NULL) { 1445 if (pkt != NULL) {
1359
1360 send_to_tty(garmin_data_p->port, pkt->data, pkt->size); 1446 send_to_tty(garmin_data_p->port, pkt->data, pkt->size);
1361 kfree(pkt); 1447 kfree(pkt);
1362 mod_timer(&garmin_data_p->timer, (1)+jiffies); 1448 mod_timer(&garmin_data_p->timer, (1)+jiffies);
1363 1449
1364 } else { 1450 } else {
1451 spin_lock_irqsave(&garmin_data_p->lock, flags);
1365 garmin_data_p->flags &= ~FLAGS_QUEUING; 1452 garmin_data_p->flags &= ~FLAGS_QUEUING;
1453 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1366 } 1454 }
1367 } 1455 }
1368 return 0; 1456 return 0;
@@ -1371,26 +1459,41 @@ static int garmin_flush_queue(struct garmin_data * garmin_data_p)
1371 1459
1372static void garmin_throttle (struct usb_serial_port *port) 1460static void garmin_throttle (struct usb_serial_port *port)
1373{ 1461{
1462 unsigned long flags;
1374 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1463 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1375 1464
1376 dbg("%s - port %d", __FUNCTION__, port->number); 1465 dbg("%s - port %d", __FUNCTION__, port->number);
1377 /* set flag, data received will be put into a queue 1466 /* set flag, data received will be put into a queue
1378 for later processing */ 1467 for later processing */
1468 spin_lock_irqsave(&garmin_data_p->lock, flags);
1379 garmin_data_p->flags |= FLAGS_QUEUING|FLAGS_THROTTLED; 1469 garmin_data_p->flags |= FLAGS_QUEUING|FLAGS_THROTTLED;
1470 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1380} 1471}
1381 1472
1382 1473
1383static void garmin_unthrottle (struct usb_serial_port *port) 1474static void garmin_unthrottle (struct usb_serial_port *port)
1384{ 1475{
1476 unsigned long flags;
1385 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1477 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1478 int status;
1386 1479
1387 dbg("%s - port %d", __FUNCTION__, port->number); 1480 dbg("%s - port %d", __FUNCTION__, port->number);
1481 spin_lock_irqsave(&garmin_data_p->lock, flags);
1388 garmin_data_p->flags &= ~FLAGS_THROTTLED; 1482 garmin_data_p->flags &= ~FLAGS_THROTTLED;
1483 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1389 1484
1390 /* in native mode send queued data to tty, in 1485 /* in native mode send queued data to tty, in
1391 serial mode nothing needs to be done here */ 1486 serial mode nothing needs to be done here */
1392 if (garmin_data_p->mode == MODE_NATIVE) 1487 if (garmin_data_p->mode == MODE_NATIVE)
1393 garmin_flush_queue(garmin_data_p); 1488 garmin_flush_queue(garmin_data_p);
1489
1490 if (0 != (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) {
1491 status = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1492 if (status)
1493 dev_err(&port->dev,
1494 "%s - failed resubmitting read urb, error %d\n",
1495 __FUNCTION__, status);
1496 }
1394} 1497}
1395 1498
1396 1499
@@ -1420,11 +1523,12 @@ static int garmin_attach (struct usb_serial *serial)
1420 1523
1421 dbg("%s", __FUNCTION__); 1524 dbg("%s", __FUNCTION__);
1422 1525
1423 garmin_data_p = kzalloc(sizeof(struct garmin_data), GFP_KERNEL); 1526 garmin_data_p = kmalloc (sizeof(struct garmin_data), GFP_KERNEL);
1424 if (garmin_data_p == NULL) { 1527 if (garmin_data_p == NULL) {
1425 dev_err(&port->dev, "%s - Out of memory\n", __FUNCTION__); 1528 dev_err(&port->dev, "%s - Out of memory\n", __FUNCTION__);
1426 return -ENOMEM; 1529 return -ENOMEM;
1427 } 1530 }
1531 memset (garmin_data_p, 0, sizeof(struct garmin_data));
1428 init_timer(&garmin_data_p->timer); 1532 init_timer(&garmin_data_p->timer);
1429 spin_lock_init(&garmin_data_p->lock); 1533 spin_lock_init(&garmin_data_p->lock);
1430 INIT_LIST_HEAD(&garmin_data_p->pktlist); 1534 INIT_LIST_HEAD(&garmin_data_p->pktlist);
@@ -1459,10 +1563,10 @@ static void garmin_shutdown (struct usb_serial *serial)
1459/* All of the device info needed */ 1563/* All of the device info needed */
1460static struct usb_serial_driver garmin_device = { 1564static struct usb_serial_driver garmin_device = {
1461 .driver = { 1565 .driver = {
1462 .owner = THIS_MODULE, 1566 .owner = THIS_MODULE,
1463 .name = "garmin_gps", 1567 .name = "garmin_gps",
1464 }, 1568 },
1465 .description = "Garmin GPS usb/tty", 1569 .description = "Garmin GPS usb/tty",
1466 .id_table = id_table, 1570 .id_table = id_table,
1467 .num_interrupt_in = 1, 1571 .num_interrupt_in = 1,
1468 .num_bulk_in = 1, 1572 .num_bulk_in = 1,
@@ -1483,6 +1587,7 @@ static struct usb_serial_driver garmin_device = {
1483}; 1587};
1484 1588
1485 1589
1590
1486static int __init garmin_init (void) 1591static int __init garmin_init (void)
1487{ 1592{
1488 int retval; 1593 int retval;
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 172713556393..21cbaa0fb96b 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -175,14 +175,14 @@ int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *
175 175
176 /* only do something if we have a bulk out endpoint */ 176 /* only do something if we have a bulk out endpoint */
177 if (serial->num_bulk_out) { 177 if (serial->num_bulk_out) {
178 spin_lock(&port->lock); 178 spin_lock_bh(&port->lock);
179 if (port->write_urb_busy) { 179 if (port->write_urb_busy) {
180 spin_unlock(&port->lock); 180 spin_unlock_bh(&port->lock);
181 dbg("%s - already writing", __FUNCTION__); 181 dbg("%s - already writing", __FUNCTION__);
182 return 0; 182 return 0;
183 } 183 }
184 port->write_urb_busy = 1; 184 port->write_urb_busy = 1;
185 spin_unlock(&port->lock); 185 spin_unlock_bh(&port->lock);
186 186
187 count = (count > port->bulk_out_size) ? port->bulk_out_size : count; 187 count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
188 188
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c
index 9840bade79f9..cbc725a6c58e 100644
--- a/drivers/usb/serial/ipaq.c
+++ b/drivers/usb/serial/ipaq.c
@@ -479,6 +479,7 @@ static struct usb_device_id ipaq_id_table [] = {
479 { USB_DEVICE(0x0BB4, 0x0A9D) }, /* SmartPhone USB Sync */ 479 { USB_DEVICE(0x0BB4, 0x0A9D) }, /* SmartPhone USB Sync */
480 { USB_DEVICE(0x0BB4, 0x0A9E) }, /* SmartPhone USB Sync */ 480 { USB_DEVICE(0x0BB4, 0x0A9E) }, /* SmartPhone USB Sync */
481 { USB_DEVICE(0x0BB4, 0x0A9F) }, /* SmartPhone USB Sync */ 481 { USB_DEVICE(0x0BB4, 0x0A9F) }, /* SmartPhone USB Sync */
482 { USB_DEVICE(0x0BB4, 0x0BCE) }, /* "High Tech Computer Corp" */
482 { USB_DEVICE(0x0BF8, 0x1001) }, /* Fujitsu Siemens Computers USB Sync */ 483 { USB_DEVICE(0x0BF8, 0x1001) }, /* Fujitsu Siemens Computers USB Sync */
483 { USB_DEVICE(0x0C44, 0x03A2) }, /* Motorola iDEN Smartphone */ 484 { USB_DEVICE(0x0C44, 0x03A2) }, /* Motorola iDEN Smartphone */
484 { USB_DEVICE(0x0C8E, 0x6000) }, /* Cesscom Luxian Series */ 485 { USB_DEVICE(0x0C8E, 0x6000) }, /* Cesscom Luxian Series */
@@ -652,11 +653,6 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp)
652 port->bulk_out_size = port->write_urb->transfer_buffer_length = URBDATA_SIZE; 653 port->bulk_out_size = port->write_urb->transfer_buffer_length = URBDATA_SIZE;
653 654
654 msleep(1000*initial_wait); 655 msleep(1000*initial_wait);
655 /* Start reading from the device */
656 usb_fill_bulk_urb(port->read_urb, serial->dev,
657 usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress),
658 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length,
659 ipaq_read_bulk_callback, port);
660 656
661 /* 657 /*
662 * Send out control message observed in win98 sniffs. Not sure what 658 * Send out control message observed in win98 sniffs. Not sure what
@@ -670,18 +666,31 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp)
670 result = usb_control_msg(serial->dev, 666 result = usb_control_msg(serial->dev,
671 usb_sndctrlpipe(serial->dev, 0), 0x22, 0x21, 667 usb_sndctrlpipe(serial->dev, 0), 0x22, 0x21,
672 0x1, 0, NULL, 0, 100); 668 0x1, 0, NULL, 0, 100);
673 if (result == 0) { 669 if (!result)
674 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 670 break;
675 if (result) { 671
676 err("%s - failed submitting read urb, error %d", __FUNCTION__, result);
677 goto error;
678 }
679 return 0;
680 }
681 msleep(1000); 672 msleep(1000);
682 } 673 }
683 err("%s - failed doing control urb, error %d", __FUNCTION__, result); 674
684 goto error; 675 if (!retries && result) {
676 err("%s - failed doing control urb, error %d", __FUNCTION__,
677 result);
678 goto error;
679 }
680
681 /* Start reading from the device */
682 usb_fill_bulk_urb(port->read_urb, serial->dev,
683 usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress),
684 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length,
685 ipaq_read_bulk_callback, port);
686
687 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
688 if (result) {
689 err("%s - failed submitting read urb, error %d", __FUNCTION__, result);
690 goto error;
691 }
692
693 return 0;
685 694
686enomem: 695enomem:
687 result = -ENOMEM; 696 result = -ENOMEM;
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c
index 87306cb6f9f5..812bc213a963 100644
--- a/drivers/usb/serial/ipw.c
+++ b/drivers/usb/serial/ipw.c
@@ -394,14 +394,14 @@ static int ipw_write(struct usb_serial_port *port, const unsigned char *buf, int
394 return 0; 394 return 0;
395 } 395 }
396 396
397 spin_lock(&port->lock); 397 spin_lock_bh(&port->lock);
398 if (port->write_urb_busy) { 398 if (port->write_urb_busy) {
399 spin_unlock(&port->lock); 399 spin_unlock_bh(&port->lock);
400 dbg("%s - already writing", __FUNCTION__); 400 dbg("%s - already writing", __FUNCTION__);
401 return 0; 401 return 0;
402 } 402 }
403 port->write_urb_busy = 1; 403 port->write_urb_busy = 1;
404 spin_unlock(&port->lock); 404 spin_unlock_bh(&port->lock);
405 405
406 count = min(count, port->bulk_out_size); 406 count = min(count, port->bulk_out_size);
407 memcpy(port->bulk_out_buffer, buf, count); 407 memcpy(port->bulk_out_buffer, buf, count);
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c
index 1738b0b6a376..1b348df388ed 100644
--- a/drivers/usb/serial/ir-usb.c
+++ b/drivers/usb/serial/ir-usb.c
@@ -342,14 +342,14 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int
342 if (count == 0) 342 if (count == 0)
343 return 0; 343 return 0;
344 344
345 spin_lock(&port->lock); 345 spin_lock_bh(&port->lock);
346 if (port->write_urb_busy) { 346 if (port->write_urb_busy) {
347 spin_unlock(&port->lock); 347 spin_unlock_bh(&port->lock);
348 dbg("%s - already writing", __FUNCTION__); 348 dbg("%s - already writing", __FUNCTION__);
349 return 0; 349 return 0;
350 } 350 }
351 port->write_urb_busy = 1; 351 port->write_urb_busy = 1;
352 spin_unlock(&port->lock); 352 spin_unlock_bh(&port->lock);
353 353
354 transfer_buffer = port->write_urb->transfer_buffer; 354 transfer_buffer = port->write_urb->transfer_buffer;
355 transfer_size = min(count, port->bulk_out_size - 1); 355 transfer_size = min(count, port->bulk_out_size - 1);
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index 49b8dc039d1f..59e777f1e8fd 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -518,13 +518,13 @@ static int keyspan_pda_write(struct usb_serial_port *port,
518 the TX urb is in-flight (wait until it completes) 518 the TX urb is in-flight (wait until it completes)
519 the device is full (wait until it says there is room) 519 the device is full (wait until it says there is room)
520 */ 520 */
521 spin_lock(&port->lock); 521 spin_lock_bh(&port->lock);
522 if (port->write_urb_busy || priv->tx_throttled) { 522 if (port->write_urb_busy || priv->tx_throttled) {
523 spin_unlock(&port->lock); 523 spin_unlock_bh(&port->lock);
524 return 0; 524 return 0;
525 } 525 }
526 port->write_urb_busy = 1; 526 port->write_urb_busy = 1;
527 spin_unlock(&port->lock); 527 spin_unlock_bh(&port->lock);
528 528
529 /* At this point the URB is in our control, nobody else can submit it 529 /* At this point the URB is in our control, nobody else can submit it
530 again (the only sudden transition was the one from EINPROGRESS to 530 again (the only sudden transition was the one from EINPROGRESS to
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
new file mode 100644
index 000000000000..95bf57166c59
--- /dev/null
+++ b/drivers/usb/serial/mos7840.c
@@ -0,0 +1,2962 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 *
16 * Clean ups from Moschip version and a few ioctl implementations by:
17 * Paul B Schroeder <pschroeder "at" uplogix "dot" com>
18 *
19 * Originally based on drivers/usb/serial/io_edgeport.c which is:
20 * Copyright (C) 2000 Inside Out Networks, All rights reserved.
21 * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
22 *
23 */
24
25#include <linux/kernel.h>
26#include <linux/errno.h>
27#include <linux/init.h>
28#include <linux/slab.h>
29#include <linux/tty.h>
30#include <linux/tty_driver.h>
31#include <linux/tty_flip.h>
32#include <linux/module.h>
33#include <linux/serial.h>
34#include <linux/usb.h>
35#include <linux/usb/serial.h>
36#include <asm/uaccess.h>
37
38/*
39 * Version Information
40 */
41#define DRIVER_VERSION "1.3.1"
42#define DRIVER_DESC "Moschip 7840/7820 USB Serial Driver"
43
44/*
45 * 16C50 UART register defines
46 */
47
48#define LCR_BITS_5 0x00 /* 5 bits/char */
49#define LCR_BITS_6 0x01 /* 6 bits/char */
50#define LCR_BITS_7 0x02 /* 7 bits/char */
51#define LCR_BITS_8 0x03 /* 8 bits/char */
52#define LCR_BITS_MASK 0x03 /* Mask for bits/char field */
53
54#define LCR_STOP_1 0x00 /* 1 stop bit */
55#define LCR_STOP_1_5 0x04 /* 1.5 stop bits (if 5 bits/char) */
56#define LCR_STOP_2 0x04 /* 2 stop bits (if 6-8 bits/char) */
57#define LCR_STOP_MASK 0x04 /* Mask for stop bits field */
58
59#define LCR_PAR_NONE 0x00 /* No parity */
60#define LCR_PAR_ODD 0x08 /* Odd parity */
61#define LCR_PAR_EVEN 0x18 /* Even parity */
62#define LCR_PAR_MARK 0x28 /* Force parity bit to 1 */
63#define LCR_PAR_SPACE 0x38 /* Force parity bit to 0 */
64#define LCR_PAR_MASK 0x38 /* Mask for parity field */
65
66#define LCR_SET_BREAK 0x40 /* Set Break condition */
67#define LCR_DL_ENABLE 0x80 /* Enable access to divisor latch */
68
69#define MCR_DTR 0x01 /* Assert DTR */
70#define MCR_RTS 0x02 /* Assert RTS */
71#define MCR_OUT1 0x04 /* Loopback only: Sets state of RI */
72#define MCR_MASTER_IE 0x08 /* Enable interrupt outputs */
73#define MCR_LOOPBACK 0x10 /* Set internal (digital) loopback mode */
74#define MCR_XON_ANY 0x20 /* Enable any char to exit XOFF mode */
75
76#define MOS7840_MSR_CTS 0x10 /* Current state of CTS */
77#define MOS7840_MSR_DSR 0x20 /* Current state of DSR */
78#define MOS7840_MSR_RI 0x40 /* Current state of RI */
79#define MOS7840_MSR_CD 0x80 /* Current state of CD */
80
81/*
82 * Defines used for sending commands to port
83 */
84
85#define WAIT_FOR_EVER (HZ * 0 ) /* timeout urb is wait for ever */
86#define MOS_WDR_TIMEOUT (HZ * 5 ) /* default urb timeout */
87
88#define MOS_PORT1 0x0200
89#define MOS_PORT2 0x0300
90#define MOS_VENREG 0x0000
91#define MOS_MAX_PORT 0x02
92#define MOS_WRITE 0x0E
93#define MOS_READ 0x0D
94
95/* Requests */
96#define MCS_RD_RTYPE 0xC0
97#define MCS_WR_RTYPE 0x40
98#define MCS_RDREQ 0x0D
99#define MCS_WRREQ 0x0E
100#define MCS_CTRL_TIMEOUT 500
101#define VENDOR_READ_LENGTH (0x01)
102
103#define MAX_NAME_LEN 64
104
105#define ZLP_REG1 0x3A //Zero_Flag_Reg1 58
106#define ZLP_REG5 0x3E //Zero_Flag_Reg5 62
107
108/* For higher baud Rates use TIOCEXBAUD */
109#define TIOCEXBAUD 0x5462
110
111/* vendor id and device id defines */
112
113#define USB_VENDOR_ID_MOSCHIP 0x9710
114#define MOSCHIP_DEVICE_ID_7840 0x7840
115#define MOSCHIP_DEVICE_ID_7820 0x7820
116
117/* Interrupt Rotinue Defines */
118
119#define SERIAL_IIR_RLS 0x06
120#define SERIAL_IIR_MS 0x00
121
122/*
123 * Emulation of the bit mask on the LINE STATUS REGISTER.
124 */
125#define SERIAL_LSR_DR 0x0001
126#define SERIAL_LSR_OE 0x0002
127#define SERIAL_LSR_PE 0x0004
128#define SERIAL_LSR_FE 0x0008
129#define SERIAL_LSR_BI 0x0010
130
131#define MOS_MSR_DELTA_CTS 0x10
132#define MOS_MSR_DELTA_DSR 0x20
133#define MOS_MSR_DELTA_RI 0x40
134#define MOS_MSR_DELTA_CD 0x80
135
136// Serial Port register Address
137#define INTERRUPT_ENABLE_REGISTER ((__u16)(0x01))
138#define FIFO_CONTROL_REGISTER ((__u16)(0x02))
139#define LINE_CONTROL_REGISTER ((__u16)(0x03))
140#define MODEM_CONTROL_REGISTER ((__u16)(0x04))
141#define LINE_STATUS_REGISTER ((__u16)(0x05))
142#define MODEM_STATUS_REGISTER ((__u16)(0x06))
143#define SCRATCH_PAD_REGISTER ((__u16)(0x07))
144#define DIVISOR_LATCH_LSB ((__u16)(0x00))
145#define DIVISOR_LATCH_MSB ((__u16)(0x01))
146
147#define CLK_MULTI_REGISTER ((__u16)(0x02))
148#define CLK_START_VALUE_REGISTER ((__u16)(0x03))
149
150#define SERIAL_LCR_DLAB ((__u16)(0x0080))
151
152/*
153 * URB POOL related defines
154 */
155#define NUM_URBS 16 /* URB Count */
156#define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */
157
158
159static struct usb_device_id moschip_port_id_table[] = {
160 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)},
161 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)},
162 {} /* terminating entry */
163};
164
165static __devinitdata struct usb_device_id moschip_id_table_combined[] = {
166 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)},
167 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)},
168 {} /* terminating entry */
169};
170
171MODULE_DEVICE_TABLE(usb, moschip_id_table_combined);
172
173/* This structure holds all of the local port information */
174
175struct moschip_port {
176 int port_num; /*Actual port number in the device(1,2,etc) */
177 struct urb *write_urb; /* write URB for this port */
178 struct urb *read_urb; /* read URB for this port */
179 __u8 shadowLCR; /* last LCR value received */
180 __u8 shadowMCR; /* last MCR value received */
181 char open;
182 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */
183 wait_queue_head_t delta_msr_wait; /* for handling sleeping while waiting for msr change to happen */
184 int delta_msr_cond;
185 struct async_icount icount;
186 struct usb_serial_port *port; /* loop back to the owner of this object */
187
188 /*Offsets */
189 __u8 SpRegOffset;
190 __u8 ControlRegOffset;
191 __u8 DcrRegOffset;
192 //for processing control URBS in interrupt context
193 struct urb *control_urb;
194 char *ctrl_buf;
195 int MsrLsr;
196
197 struct urb *write_urb_pool[NUM_URBS];
198};
199
200
201static int debug;
202static int mos7840_num_ports; //this says the number of ports in the device
203static int mos7840_num_open_ports;
204
205
206/*
207 * mos7840_set_reg_sync
208 * To set the Control register by calling usb_fill_control_urb function
209 * by passing usb_sndctrlpipe function as parameter.
210 */
211
212static int mos7840_set_reg_sync(struct usb_serial_port *port, __u16 reg,
213 __u16 val)
214{
215 struct usb_device *dev = port->serial->dev;
216 val = val & 0x00ff;
217 dbg("mos7840_set_reg_sync offset is %x, value %x\n", reg, val);
218
219 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ,
220 MCS_WR_RTYPE, val, reg, NULL, 0,
221 MOS_WDR_TIMEOUT);
222}
223
224/*
225 * mos7840_get_reg_sync
226 * To set the Uart register by calling usb_fill_control_urb function by
227 * passing usb_rcvctrlpipe function as parameter.
228 */
229
230static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg,
231 __u16 * val)
232{
233 struct usb_device *dev = port->serial->dev;
234 int ret = 0;
235
236 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
237 MCS_RD_RTYPE, 0, reg, val, VENDOR_READ_LENGTH,
238 MOS_WDR_TIMEOUT);
239 dbg("mos7840_get_reg_sync offset is %x, return val %x\n", reg, *val);
240 *val = (*val) & 0x00ff;
241 return ret;
242}
243
244/*
245 * mos7840_set_uart_reg
246 * To set the Uart register by calling usb_fill_control_urb function by
247 * passing usb_sndctrlpipe function as parameter.
248 */
249
250static int mos7840_set_uart_reg(struct usb_serial_port *port, __u16 reg,
251 __u16 val)
252{
253
254 struct usb_device *dev = port->serial->dev;
255 val = val & 0x00ff;
256 // For the UART control registers, the application number need to be Or'ed
257 if (mos7840_num_ports == 4) {
258 val |=
259 (((__u16) port->number - (__u16) (port->serial->minor)) +
260 1) << 8;
261 dbg("mos7840_set_uart_reg application number is %x\n", val);
262 } else {
263 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
264 val |=
265 (((__u16) port->number -
266 (__u16) (port->serial->minor)) + 1) << 8;
267 dbg("mos7840_set_uart_reg application number is %x\n",
268 val);
269 } else {
270 val |=
271 (((__u16) port->number -
272 (__u16) (port->serial->minor)) + 2) << 8;
273 dbg("mos7840_set_uart_reg application number is %x\n",
274 val);
275 }
276 }
277 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ,
278 MCS_WR_RTYPE, val, reg, NULL, 0,
279 MOS_WDR_TIMEOUT);
280
281}
282
283/*
284 * mos7840_get_uart_reg
285 * To set the Control register by calling usb_fill_control_urb function
286 * by passing usb_rcvctrlpipe function as parameter.
287 */
288static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg,
289 __u16 * val)
290{
291 struct usb_device *dev = port->serial->dev;
292 int ret = 0;
293 __u16 Wval;
294
295 //dbg("application number is %4x \n",(((__u16)port->number - (__u16)(port->serial->minor))+1)<<8);
296 /*Wval is same as application number */
297 if (mos7840_num_ports == 4) {
298 Wval =
299 (((__u16) port->number - (__u16) (port->serial->minor)) +
300 1) << 8;
301 dbg("mos7840_get_uart_reg application number is %x\n", Wval);
302 } else {
303 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
304 Wval =
305 (((__u16) port->number -
306 (__u16) (port->serial->minor)) + 1) << 8;
307 dbg("mos7840_get_uart_reg application number is %x\n",
308 Wval);
309 } else {
310 Wval =
311 (((__u16) port->number -
312 (__u16) (port->serial->minor)) + 2) << 8;
313 dbg("mos7840_get_uart_reg application number is %x\n",
314 Wval);
315 }
316 }
317 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
318 MCS_RD_RTYPE, Wval, reg, val, VENDOR_READ_LENGTH,
319 MOS_WDR_TIMEOUT);
320 *val = (*val) & 0x00ff;
321 return ret;
322}
323
324static void mos7840_dump_serial_port(struct moschip_port *mos7840_port)
325{
326
327 dbg("***************************************\n");
328 dbg("SpRegOffset is %2x\n", mos7840_port->SpRegOffset);
329 dbg("ControlRegOffset is %2x \n", mos7840_port->ControlRegOffset);
330 dbg("DCRRegOffset is %2x \n", mos7840_port->DcrRegOffset);
331 dbg("***************************************\n");
332
333}
334
335/************************************************************************/
336/************************************************************************/
337/* I N T E R F A C E F U N C T I O N S */
338/* I N T E R F A C E F U N C T I O N S */
339/************************************************************************/
340/************************************************************************/
341
342static inline void mos7840_set_port_private(struct usb_serial_port *port,
343 struct moschip_port *data)
344{
345 usb_set_serial_port_data(port, (void *)data);
346}
347
348static inline struct moschip_port *mos7840_get_port_private(struct
349 usb_serial_port
350 *port)
351{
352 return (struct moschip_port *)usb_get_serial_port_data(port);
353}
354
355static int mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr)
356{
357 struct moschip_port *mos7840_port;
358 struct async_icount *icount;
359 mos7840_port = port;
360 icount = &mos7840_port->icount;
361 if (new_msr &
362 (MOS_MSR_DELTA_CTS | MOS_MSR_DELTA_DSR | MOS_MSR_DELTA_RI |
363 MOS_MSR_DELTA_CD)) {
364 icount = &mos7840_port->icount;
365
366 /* update input line counters */
367 if (new_msr & MOS_MSR_DELTA_CTS) {
368 icount->cts++;
369 }
370 if (new_msr & MOS_MSR_DELTA_DSR) {
371 icount->dsr++;
372 }
373 if (new_msr & MOS_MSR_DELTA_CD) {
374 icount->dcd++;
375 }
376 if (new_msr & MOS_MSR_DELTA_RI) {
377 icount->rng++;
378 }
379 }
380
381 return 0;
382}
383
384static int mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr)
385{
386 struct async_icount *icount;
387
388 dbg("%s - %02x", __FUNCTION__, new_lsr);
389
390 if (new_lsr & SERIAL_LSR_BI) {
391 //
392 // Parity and Framing errors only count if they
393 // occur exclusive of a break being
394 // received.
395 //
396 new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI);
397 }
398
399 /* update input line counters */
400 icount = &port->icount;
401 if (new_lsr & SERIAL_LSR_BI) {
402 icount->brk++;
403 }
404 if (new_lsr & SERIAL_LSR_OE) {
405 icount->overrun++;
406 }
407 if (new_lsr & SERIAL_LSR_PE) {
408 icount->parity++;
409 }
410 if (new_lsr & SERIAL_LSR_FE) {
411 icount->frame++;
412 }
413
414 return 0;
415}
416
417/************************************************************************/
418/************************************************************************/
419/* U S B C A L L B A C K F U N C T I O N S */
420/* U S B C A L L B A C K F U N C T I O N S */
421/************************************************************************/
422/************************************************************************/
423
424static void mos7840_control_callback(struct urb *urb, struct pt_regs *regs)
425{
426 unsigned char *data;
427 struct moschip_port *mos7840_port;
428 __u8 regval = 0x0;
429
430 if (!urb) {
431 dbg("%s", "Invalid Pointer !!!!:\n");
432 return;
433 }
434
435 switch (urb->status) {
436 case 0:
437 /* success */
438 break;
439 case -ECONNRESET:
440 case -ENOENT:
441 case -ESHUTDOWN:
442 /* this urb is terminated, clean up */
443 dbg("%s - urb shutting down with status: %d", __FUNCTION__,
444 urb->status);
445 return;
446 default:
447 dbg("%s - nonzero urb status received: %d", __FUNCTION__,
448 urb->status);
449 goto exit;
450 }
451
452 mos7840_port = (struct moschip_port *)urb->context;
453
454 dbg("%s urb buffer size is %d\n", __FUNCTION__, urb->actual_length);
455 dbg("%s mos7840_port->MsrLsr is %d port %d\n", __FUNCTION__,
456 mos7840_port->MsrLsr, mos7840_port->port_num);
457 data = urb->transfer_buffer;
458 regval = (__u8) data[0];
459 dbg("%s data is %x\n", __FUNCTION__, regval);
460 if (mos7840_port->MsrLsr == 0)
461 mos7840_handle_new_msr(mos7840_port, regval);
462 else if (mos7840_port->MsrLsr == 1)
463 mos7840_handle_new_lsr(mos7840_port, regval);
464
465 exit:
466 return;
467}
468
469static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg,
470 __u16 * val)
471{
472 struct usb_device *dev = mcs->port->serial->dev;
473 struct usb_ctrlrequest *dr = NULL;
474 unsigned char *buffer = NULL;
475 int ret = 0;
476 buffer = (__u8 *) mcs->ctrl_buf;
477
478// dr=(struct usb_ctrlrequest *)(buffer);
479 dr = (void *)(buffer + 2);
480 dr->bRequestType = MCS_RD_RTYPE;
481 dr->bRequest = MCS_RDREQ;
482 dr->wValue = cpu_to_le16(Wval); //0;
483 dr->wIndex = cpu_to_le16(reg);
484 dr->wLength = cpu_to_le16(2);
485
486 usb_fill_control_urb(mcs->control_urb, dev, usb_rcvctrlpipe(dev, 0),
487 (unsigned char *)dr, buffer, 2,
488 mos7840_control_callback, mcs);
489 mcs->control_urb->transfer_buffer_length = 2;
490 ret = usb_submit_urb(mcs->control_urb, GFP_ATOMIC);
491 return ret;
492}
493
494/*****************************************************************************
495 * mos7840_interrupt_callback
496 * this is the callback function for when we have received data on the
497 * interrupt endpoint.
498 *****************************************************************************/
499
500static void mos7840_interrupt_callback(struct urb *urb, struct pt_regs *regs)
501{
502 int result;
503 int length;
504 struct moschip_port *mos7840_port;
505 struct usb_serial *serial;
506 __u16 Data;
507 unsigned char *data;
508 __u8 sp[5], st;
509 int i;
510 __u16 wval;
511
512 dbg("%s", " : Entering\n");
513 if (!urb) {
514 dbg("%s", "Invalid Pointer !!!!:\n");
515 return;
516 }
517
518 switch (urb->status) {
519 case 0:
520 /* success */
521 break;
522 case -ECONNRESET:
523 case -ENOENT:
524 case -ESHUTDOWN:
525 /* this urb is terminated, clean up */
526 dbg("%s - urb shutting down with status: %d", __FUNCTION__,
527 urb->status);
528 return;
529 default:
530 dbg("%s - nonzero urb status received: %d", __FUNCTION__,
531 urb->status);
532 goto exit;
533 }
534
535 length = urb->actual_length;
536 data = urb->transfer_buffer;
537
538 serial = (struct usb_serial *)urb->context;
539
540 /* Moschip get 5 bytes
541 * Byte 1 IIR Port 1 (port.number is 0)
542 * Byte 2 IIR Port 2 (port.number is 1)
543 * Byte 3 IIR Port 3 (port.number is 2)
544 * Byte 4 IIR Port 4 (port.number is 3)
545 * Byte 5 FIFO status for both */
546
547 if (length && length > 5) {
548 dbg("%s \n", "Wrong data !!!");
549 return;
550 }
551
552 sp[0] = (__u8) data[0];
553 sp[1] = (__u8) data[1];
554 sp[2] = (__u8) data[2];
555 sp[3] = (__u8) data[3];
556 st = (__u8) data[4];
557
558 for (i = 0; i < serial->num_ports; i++) {
559 mos7840_port = mos7840_get_port_private(serial->port[i]);
560 wval =
561 (((__u16) serial->port[i]->number -
562 (__u16) (serial->minor)) + 1) << 8;
563 if (mos7840_port->open) {
564 if (sp[i] & 0x01) {
565 dbg("SP%d No Interrupt !!!\n", i);
566 } else {
567 switch (sp[i] & 0x0f) {
568 case SERIAL_IIR_RLS:
569 dbg("Serial Port %d: Receiver status error or ", i);
570 dbg("address bit detected in 9-bit mode\n");
571 mos7840_port->MsrLsr = 1;
572 mos7840_get_reg(mos7840_port, wval,
573 LINE_STATUS_REGISTER,
574 &Data);
575 break;
576 case SERIAL_IIR_MS:
577 dbg("Serial Port %d: Modem status change\n", i);
578 mos7840_port->MsrLsr = 0;
579 mos7840_get_reg(mos7840_port, wval,
580 MODEM_STATUS_REGISTER,
581 &Data);
582 break;
583 }
584 }
585 }
586 }
587 exit:
588 result = usb_submit_urb(urb, GFP_ATOMIC);
589 if (result) {
590 dev_err(&urb->dev->dev,
591 "%s - Error %d submitting interrupt urb\n",
592 __FUNCTION__, result);
593 }
594
595 return;
596
597}
598
599static int mos7840_port_paranoia_check(struct usb_serial_port *port,
600 const char *function)
601{
602 if (!port) {
603 dbg("%s - port == NULL", function);
604 return -1;
605 }
606 if (!port->serial) {
607 dbg("%s - port->serial == NULL", function);
608 return -1;
609 }
610
611 return 0;
612}
613
614/* Inline functions to check the sanity of a pointer that is passed to us */
615static int mos7840_serial_paranoia_check(struct usb_serial *serial,
616 const char *function)
617{
618 if (!serial) {
619 dbg("%s - serial == NULL", function);
620 return -1;
621 }
622 if (!serial->type) {
623 dbg("%s - serial->type == NULL!", function);
624 return -1;
625 }
626
627 return 0;
628}
629
630static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port,
631 const char *function)
632{
633 /* if no port was specified, or it fails a paranoia check */
634 if (!port ||
635 mos7840_port_paranoia_check(port, function) ||
636 mos7840_serial_paranoia_check(port->serial, function)) {
637 /* then say that we don't have a valid usb_serial thing, which will * end up genrating -ENODEV return values */
638 return NULL;
639 }
640
641 return port->serial;
642}
643
644/*****************************************************************************
645 * mos7840_bulk_in_callback
646 * this is the callback function for when we have received data on the
647 * bulk in endpoint.
648 *****************************************************************************/
649
650static void mos7840_bulk_in_callback(struct urb *urb, struct pt_regs *regs)
651{
652 int status;
653 unsigned char *data;
654 struct usb_serial *serial;
655 struct usb_serial_port *port;
656 struct moschip_port *mos7840_port;
657 struct tty_struct *tty;
658
659 if (!urb) {
660 dbg("%s", "Invalid Pointer !!!!:\n");
661 return;
662 }
663
664 if (urb->status) {
665 dbg("nonzero read bulk status received: %d", urb->status);
666 return;
667 }
668
669 mos7840_port = (struct moschip_port *)urb->context;
670 if (!mos7840_port) {
671 dbg("%s", "NULL mos7840_port pointer \n");
672 return;
673 }
674
675 port = (struct usb_serial_port *)mos7840_port->port;
676 if (mos7840_port_paranoia_check(port, __FUNCTION__)) {
677 dbg("%s", "Port Paranoia failed \n");
678 return;
679 }
680
681 serial = mos7840_get_usb_serial(port, __FUNCTION__);
682 if (!serial) {
683 dbg("%s\n", "Bad serial pointer ");
684 return;
685 }
686
687 dbg("%s\n", "Entering... \n");
688
689 data = urb->transfer_buffer;
690
691 dbg("%s", "Entering ........... \n");
692
693 if (urb->actual_length) {
694 tty = mos7840_port->port->tty;
695 if (tty) {
696 tty_buffer_request_room(tty, urb->actual_length);
697 tty_insert_flip_string(tty, data, urb->actual_length);
698 dbg(" %s \n", data);
699 tty_flip_buffer_push(tty);
700 }
701 mos7840_port->icount.rx += urb->actual_length;
702 dbg("mos7840_port->icount.rx is %d:\n",
703 mos7840_port->icount.rx);
704 }
705
706 if (!mos7840_port->read_urb) {
707 dbg("%s", "URB KILLED !!!\n");
708 return;
709 }
710
711 if (mos7840_port->read_urb->status != -EINPROGRESS) {
712 mos7840_port->read_urb->dev = serial->dev;
713
714 status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
715
716 if (status) {
717 dbg(" usb_submit_urb(read bulk) failed, status = %d",
718 status);
719 }
720 }
721}
722
723/*****************************************************************************
724 * mos7840_bulk_out_data_callback
725 * this is the callback function for when we have finished sending serial data
726 * on the bulk out endpoint.
727 *****************************************************************************/
728
729static void mos7840_bulk_out_data_callback(struct urb *urb,
730 struct pt_regs *regs)
731{
732 struct moschip_port *mos7840_port;
733 struct tty_struct *tty;
734 if (!urb) {
735 dbg("%s", "Invalid Pointer !!!!:\n");
736 return;
737 }
738
739 if (urb->status) {
740 dbg("nonzero write bulk status received:%d\n", urb->status);
741 return;
742 }
743
744 mos7840_port = (struct moschip_port *)urb->context;
745 if (!mos7840_port) {
746 dbg("%s", "NULL mos7840_port pointer \n");
747 return;
748 }
749
750 if (mos7840_port_paranoia_check(mos7840_port->port, __FUNCTION__)) {
751 dbg("%s", "Port Paranoia failed \n");
752 return;
753 }
754
755 dbg("%s \n", "Entering .........");
756
757 tty = mos7840_port->port->tty;
758
759 if (tty && mos7840_port->open) {
760 /* let the tty driver wakeup if it has a special *
761 * write_wakeup function */
762
763 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP))
764 && tty->ldisc.write_wakeup) {
765 (tty->ldisc.write_wakeup) (tty);
766 }
767
768 /* tell the tty driver that something has changed */
769 wake_up_interruptible(&tty->write_wait);
770 }
771
772}
773
774/************************************************************************/
775/* D R I V E R T T Y I N T E R F A C E F U N C T I O N S */
776/************************************************************************/
777#ifdef MCSSerialProbe
778static int mos7840_serial_probe(struct usb_serial *serial,
779 const struct usb_device_id *id)
780{
781
782 /*need to implement the mode_reg reading and updating\
783 structures usb_serial_ device_type\
784 (i.e num_ports, num_bulkin,bulkout etc) */
785 /* Also we can update the changes attach */
786 return 1;
787}
788#endif
789
790/*****************************************************************************
791 * mos7840_open
792 * this function is called by the tty driver when a port is opened
793 * If successful, we return 0
794 * Otherwise we return a negative error number.
795 *****************************************************************************/
796
797static int mos7840_open(struct usb_serial_port *port, struct file *filp)
798{
799 int response;
800 int j;
801 struct usb_serial *serial;
802 struct urb *urb;
803 __u16 Data;
804 int status;
805 struct moschip_port *mos7840_port;
806
807 if (mos7840_port_paranoia_check(port, __FUNCTION__)) {
808 dbg("%s", "Port Paranoia failed \n");
809 return -ENODEV;
810 }
811
812 mos7840_num_open_ports++;
813 serial = port->serial;
814
815 if (mos7840_serial_paranoia_check(serial, __FUNCTION__)) {
816 dbg("%s", "Serial Paranoia failed \n");
817 return -ENODEV;
818 }
819
820 mos7840_port = mos7840_get_port_private(port);
821
822 if (mos7840_port == NULL)
823 return -ENODEV;
824
825 usb_clear_halt(serial->dev, port->write_urb->pipe);
826 usb_clear_halt(serial->dev, port->read_urb->pipe);
827
828 /* Initialising the write urb pool */
829 for (j = 0; j < NUM_URBS; ++j) {
830 urb = usb_alloc_urb(0, SLAB_ATOMIC);
831 mos7840_port->write_urb_pool[j] = urb;
832
833 if (urb == NULL) {
834 err("No more urbs???");
835 continue;
836 }
837
838 urb->transfer_buffer = NULL;
839 urb->transfer_buffer =
840 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
841 if (!urb->transfer_buffer) {
842 err("%s-out of memory for urb buffers.", __FUNCTION__);
843 continue;
844 }
845 }
846
847/*****************************************************************************
848 * Initialize MCS7840 -- Write Init values to corresponding Registers
849 *
850 * Register Index
851 * 1 : IER
852 * 2 : FCR
853 * 3 : LCR
854 * 4 : MCR
855 *
856 * 0x08 : SP1/2 Control Reg
857 *****************************************************************************/
858
859//NEED to check the following Block
860
861 status = 0;
862 Data = 0x0;
863 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
864 if (status < 0) {
865 dbg("Reading Spreg failed\n");
866 return -1;
867 }
868 Data |= 0x80;
869 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
870 if (status < 0) {
871 dbg("writing Spreg failed\n");
872 return -1;
873 }
874
875 Data &= ~0x80;
876 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
877 if (status < 0) {
878 dbg("writing Spreg failed\n");
879 return -1;
880 }
881//End of block to be checked
882
883 status = 0;
884 Data = 0x0;
885 status =
886 mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data);
887 if (status < 0) {
888 dbg("Reading Controlreg failed\n");
889 return -1;
890 }
891 Data |= 0x08; //Driver done bit
892 Data |= 0x20; //rx_disable
893 status = 0;
894 status =
895 mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data);
896 if (status < 0) {
897 dbg("writing Controlreg failed\n");
898 return -1;
899 }
900 //do register settings here
901 // Set all regs to the device default values.
902 ////////////////////////////////////
903 // First Disable all interrupts.
904 ////////////////////////////////////
905
906 Data = 0x00;
907 status = 0;
908 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
909 if (status < 0) {
910 dbg("disableing interrupts failed\n");
911 return -1;
912 }
913 // Set FIFO_CONTROL_REGISTER to the default value
914 Data = 0x00;
915 status = 0;
916 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
917 if (status < 0) {
918 dbg("Writing FIFO_CONTROL_REGISTER failed\n");
919 return -1;
920 }
921
922 Data = 0xcf;
923 status = 0;
924 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
925 if (status < 0) {
926 dbg("Writing FIFO_CONTROL_REGISTER failed\n");
927 return -1;
928 }
929
930 Data = 0x03;
931 status = 0;
932 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
933 mos7840_port->shadowLCR = Data;
934
935 Data = 0x0b;
936 status = 0;
937 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
938 mos7840_port->shadowMCR = Data;
939
940 Data = 0x00;
941 status = 0;
942 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
943 mos7840_port->shadowLCR = Data;
944
945 Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80
946 status = 0;
947 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
948
949 Data = 0x0c;
950 status = 0;
951 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
952
953 Data = 0x0;
954 status = 0;
955 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
956
957 Data = 0x00;
958 status = 0;
959 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
960
961 Data = Data & ~SERIAL_LCR_DLAB;
962 status = 0;
963 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
964 mos7840_port->shadowLCR = Data;
965
966 //clearing Bulkin and Bulkout Fifo
967 Data = 0x0;
968 status = 0;
969 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
970
971 Data = Data | 0x0c;
972 status = 0;
973 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
974
975 Data = Data & ~0x0c;
976 status = 0;
977 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
978 //Finally enable all interrupts
979 Data = 0x0;
980 Data = 0x0c;
981 status = 0;
982 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
983
984 //clearing rx_disable
985 Data = 0x0;
986 status = 0;
987 status =
988 mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data);
989 Data = Data & ~0x20;
990 status = 0;
991 status =
992 mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data);
993
994 // rx_negate
995 Data = 0x0;
996 status = 0;
997 status =
998 mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data);
999 Data = Data | 0x10;
1000 status = 0;
1001 status =
1002 mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data);
1003
1004 /* force low_latency on so that our tty_push actually forces *
1005 * the data through,otherwise it is scheduled, and with *
1006 * high data rates (like with OHCI) data can get lost. */
1007
1008 if (port->tty)
1009 port->tty->low_latency = 1;
1010/* Check to see if we've set up our endpoint info yet *
1011 * (can't set it up in mos7840_startup as the structures *
1012 * were not set up at that time.) */
1013 if (mos7840_num_open_ports == 1) {
1014 if (serial->port[0]->interrupt_in_buffer == NULL) {
1015
1016 /* set up interrupt urb */
1017
1018 usb_fill_int_urb(serial->port[0]->interrupt_in_urb,
1019 serial->dev,
1020 usb_rcvintpipe(serial->dev,
1021 serial->port[0]->
1022 interrupt_in_endpointAddress),
1023 serial->port[0]->interrupt_in_buffer,
1024 serial->port[0]->interrupt_in_urb->
1025 transfer_buffer_length,
1026 mos7840_interrupt_callback,
1027 serial,
1028 serial->port[0]->interrupt_in_urb->
1029 interval);
1030
1031 /* start interrupt read for mos7840 *
1032 * will continue as long as mos7840 is connected */
1033
1034 response =
1035 usb_submit_urb(serial->port[0]->interrupt_in_urb,
1036 GFP_KERNEL);
1037 if (response) {
1038 err("%s - Error %d submitting interrupt urb",
1039 __FUNCTION__, response);
1040 }
1041
1042 }
1043
1044 }
1045
1046 /* see if we've set up our endpoint info yet *
1047 * (can't set it up in mos7840_startup as the *
1048 * structures were not set up at that time.) */
1049
1050 dbg("port number is %d \n", port->number);
1051 dbg("serial number is %d \n", port->serial->minor);
1052 dbg("Bulkin endpoint is %d \n", port->bulk_in_endpointAddress);
1053 dbg("BulkOut endpoint is %d \n", port->bulk_out_endpointAddress);
1054 dbg("Interrupt endpoint is %d \n", port->interrupt_in_endpointAddress);
1055 dbg("port's number in the device is %d\n", mos7840_port->port_num);
1056 mos7840_port->read_urb = port->read_urb;
1057
1058 /* set up our bulk in urb */
1059
1060 usb_fill_bulk_urb(mos7840_port->read_urb,
1061 serial->dev,
1062 usb_rcvbulkpipe(serial->dev,
1063 port->bulk_in_endpointAddress),
1064 port->bulk_in_buffer,
1065 mos7840_port->read_urb->transfer_buffer_length,
1066 mos7840_bulk_in_callback, mos7840_port);
1067
1068 dbg("mos7840_open: bulkin endpoint is %d\n",
1069 port->bulk_in_endpointAddress);
1070 response = usb_submit_urb(mos7840_port->read_urb, GFP_KERNEL);
1071 if (response) {
1072 err("%s - Error %d submitting control urb", __FUNCTION__,
1073 response);
1074 }
1075
1076 /* initialize our wait queues */
1077 init_waitqueue_head(&mos7840_port->wait_chase);
1078 init_waitqueue_head(&mos7840_port->delta_msr_wait);
1079
1080 /* initialize our icount structure */
1081 memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount));
1082
1083 /* initialize our port settings */
1084 mos7840_port->shadowMCR = MCR_MASTER_IE; /* Must set to enable ints! */
1085 /* send a open port command */
1086 mos7840_port->open = 1;
1087 //mos7840_change_port_settings(mos7840_port,old_termios);
1088 mos7840_port->icount.tx = 0;
1089 mos7840_port->icount.rx = 0;
1090
1091 dbg("\n\nusb_serial serial:%x mos7840_port:%x\n usb_serial_port port:%x\n\n", (unsigned int)serial, (unsigned int)mos7840_port, (unsigned int)port);
1092
1093 return 0;
1094
1095}
1096
1097/*****************************************************************************
1098 * mos7840_chars_in_buffer
1099 * this function is called by the tty driver when it wants to know how many
1100 * bytes of data we currently have outstanding in the port (data that has
1101 * been written, but hasn't made it out the port yet)
1102 * If successful, we return the number of bytes left to be written in the
1103 * system,
1104 * Otherwise we return a negative error number.
1105 *****************************************************************************/
1106
1107static int mos7840_chars_in_buffer(struct usb_serial_port *port)
1108{
1109 int i;
1110 int chars = 0;
1111 struct moschip_port *mos7840_port;
1112
1113 dbg("%s \n", " mos7840_chars_in_buffer:entering ...........");
1114
1115 if (mos7840_port_paranoia_check(port, __FUNCTION__)) {
1116 dbg("%s", "Invalid port \n");
1117 return -1;
1118 }
1119
1120 mos7840_port = mos7840_get_port_private(port);
1121 if (mos7840_port == NULL) {
1122 dbg("%s \n", "mos7840_break:leaving ...........");
1123 return -1;
1124 }
1125
1126 for (i = 0; i < NUM_URBS; ++i) {
1127 if (mos7840_port->write_urb_pool[i]->status == -EINPROGRESS) {
1128 chars += URB_TRANSFER_BUFFER_SIZE;
1129 }
1130 }
1131 dbg("%s - returns %d", __FUNCTION__, chars);
1132 return (chars);
1133
1134}
1135
1136/************************************************************************
1137 *
1138 * mos7840_block_until_tx_empty
1139 *
1140 * This function will block the close until one of the following:
1141 * 1. TX count are 0
1142 * 2. The mos7840 has stopped
1143 * 3. A timout of 3 seconds without activity has expired
1144 *
1145 ************************************************************************/
1146static void mos7840_block_until_tx_empty(struct moschip_port *mos7840_port)
1147{
1148 int timeout = HZ / 10;
1149 int wait = 30;
1150 int count;
1151
1152 while (1) {
1153
1154 count = mos7840_chars_in_buffer(mos7840_port->port);
1155
1156 /* Check for Buffer status */
1157 if (count <= 0) {
1158 return;
1159 }
1160
1161 /* Block the thread for a while */
1162 interruptible_sleep_on_timeout(&mos7840_port->wait_chase,
1163 timeout);
1164
1165 /* No activity.. count down section */
1166 wait--;
1167 if (wait == 0) {
1168 dbg("%s - TIMEOUT", __FUNCTION__);
1169 return;
1170 } else {
1171 /* Reset timout value back to seconds */
1172 wait = 30;
1173 }
1174 }
1175}
1176
1177/*****************************************************************************
1178 * mos7840_close
1179 * this function is called by the tty driver when a port is closed
1180 *****************************************************************************/
1181
1182static void mos7840_close(struct usb_serial_port *port, struct file *filp)
1183{
1184 struct usb_serial *serial;
1185 struct moschip_port *mos7840_port;
1186 int j;
1187 __u16 Data;
1188
1189 dbg("%s\n", "mos7840_close:entering...");
1190
1191 if (mos7840_port_paranoia_check(port, __FUNCTION__)) {
1192 dbg("%s", "Port Paranoia failed \n");
1193 return;
1194 }
1195
1196 serial = mos7840_get_usb_serial(port, __FUNCTION__);
1197 if (!serial) {
1198 dbg("%s", "Serial Paranoia failed \n");
1199 return;
1200 }
1201
1202 mos7840_port = mos7840_get_port_private(port);
1203
1204 if (mos7840_port == NULL) {
1205 return;
1206 }
1207
1208 for (j = 0; j < NUM_URBS; ++j)
1209 usb_kill_urb(mos7840_port->write_urb_pool[j]);
1210
1211 /* Freeing Write URBs */
1212 for (j = 0; j < NUM_URBS; ++j) {
1213 if (mos7840_port->write_urb_pool[j]) {
1214 if (mos7840_port->write_urb_pool[j]->transfer_buffer)
1215 kfree(mos7840_port->write_urb_pool[j]->
1216 transfer_buffer);
1217
1218 usb_free_urb(mos7840_port->write_urb_pool[j]);
1219 }
1220 }
1221
1222 if (serial->dev) {
1223 /* flush and block until tx is empty */
1224 mos7840_block_until_tx_empty(mos7840_port);
1225 }
1226
1227 /* While closing port, shutdown all bulk read, write *
1228 * and interrupt read if they exists */
1229 if (serial->dev) {
1230
1231 if (mos7840_port->write_urb) {
1232 dbg("%s", "Shutdown bulk write\n");
1233 usb_kill_urb(mos7840_port->write_urb);
1234 }
1235
1236 if (mos7840_port->read_urb) {
1237 dbg("%s", "Shutdown bulk read\n");
1238 usb_kill_urb(mos7840_port->read_urb);
1239 }
1240 if ((&mos7840_port->control_urb)) {
1241 dbg("%s", "Shutdown control read\n");
1242 // usb_kill_urb (mos7840_port->control_urb);
1243
1244 }
1245 }
1246// if(mos7840_port->ctrl_buf != NULL)
1247// kfree(mos7840_port->ctrl_buf);
1248 mos7840_num_open_ports--;
1249 dbg("mos7840_num_open_ports in close%d:in port%d\n",
1250 mos7840_num_open_ports, port->number);
1251 if (mos7840_num_open_ports == 0) {
1252 if (serial->port[0]->interrupt_in_urb) {
1253 dbg("%s", "Shutdown interrupt_in_urb\n");
1254 }
1255 }
1256
1257 if (mos7840_port->write_urb) {
1258 /* if this urb had a transfer buffer already (old tx) free it */
1259
1260 if (mos7840_port->write_urb->transfer_buffer != NULL) {
1261 kfree(mos7840_port->write_urb->transfer_buffer);
1262 }
1263 usb_free_urb(mos7840_port->write_urb);
1264 }
1265
1266 Data = 0x0;
1267 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1268
1269 Data = 0x00;
1270 mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1271
1272 mos7840_port->open = 0;
1273
1274 dbg("%s \n", "Leaving ............");
1275}
1276
1277/************************************************************************
1278 *
1279 * mos7840_block_until_chase_response
1280 *
1281 * This function will block the close until one of the following:
1282 * 1. Response to our Chase comes from mos7840
1283 * 2. A timout of 10 seconds without activity has expired
1284 * (1K of mos7840 data @ 2400 baud ==> 4 sec to empty)
1285 *
1286 ************************************************************************/
1287
1288static void mos7840_block_until_chase_response(struct moschip_port
1289 *mos7840_port)
1290{
1291 int timeout = 1 * HZ;
1292 int wait = 10;
1293 int count;
1294
1295 while (1) {
1296 count = mos7840_chars_in_buffer(mos7840_port->port);
1297
1298 /* Check for Buffer status */
1299 if (count <= 0) {
1300 return;
1301 }
1302
1303 /* Block the thread for a while */
1304 interruptible_sleep_on_timeout(&mos7840_port->wait_chase,
1305 timeout);
1306 /* No activity.. count down section */
1307 wait--;
1308 if (wait == 0) {
1309 dbg("%s - TIMEOUT", __FUNCTION__);
1310 return;
1311 } else {
1312 /* Reset timout value back to seconds */
1313 wait = 10;
1314 }
1315 }
1316
1317}
1318
1319/*****************************************************************************
1320 * mos7840_break
1321 * this function sends a break to the port
1322 *****************************************************************************/
1323static void mos7840_break(struct usb_serial_port *port, int break_state)
1324{
1325 unsigned char data;
1326 struct usb_serial *serial;
1327 struct moschip_port *mos7840_port;
1328
1329 dbg("%s \n", "Entering ...........");
1330 dbg("mos7840_break: Start\n");
1331
1332 if (mos7840_port_paranoia_check(port, __FUNCTION__)) {
1333 dbg("%s", "Port Paranoia failed \n");
1334 return;
1335 }
1336
1337 serial = mos7840_get_usb_serial(port, __FUNCTION__);
1338 if (!serial) {
1339 dbg("%s", "Serial Paranoia failed \n");
1340 return;
1341 }
1342
1343 mos7840_port = mos7840_get_port_private(port);
1344
1345 if (mos7840_port == NULL) {
1346 return;
1347 }
1348
1349 if (serial->dev) {
1350
1351 /* flush and block until tx is empty */
1352 mos7840_block_until_chase_response(mos7840_port);
1353 }
1354
1355 if (break_state == -1) {
1356 data = mos7840_port->shadowLCR | LCR_SET_BREAK;
1357 } else {
1358 data = mos7840_port->shadowLCR & ~LCR_SET_BREAK;
1359 }
1360
1361 mos7840_port->shadowLCR = data;
1362 dbg("mcs7840_break mos7840_port->shadowLCR is %x\n",
1363 mos7840_port->shadowLCR);
1364 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER,
1365 mos7840_port->shadowLCR);
1366
1367 return;
1368}
1369
1370/*****************************************************************************
1371 * mos7840_write_room
1372 * this function is called by the tty driver when it wants to know how many
1373 * bytes of data we can accept for a specific port.
1374 * If successful, we return the amount of room that we have for this port
1375 * Otherwise we return a negative error number.
1376 *****************************************************************************/
1377
1378static int mos7840_write_room(struct usb_serial_port *port)
1379{
1380 int i;
1381 int room = 0;
1382 struct moschip_port *mos7840_port;
1383
1384 dbg("%s \n", " mos7840_write_room:entering ...........");
1385
1386 if (mos7840_port_paranoia_check(port, __FUNCTION__)) {
1387 dbg("%s", "Invalid port \n");
1388 dbg("%s \n", " mos7840_write_room:leaving ...........");
1389 return -1;
1390 }
1391
1392 mos7840_port = mos7840_get_port_private(port);
1393 if (mos7840_port == NULL) {
1394 dbg("%s \n", "mos7840_break:leaving ...........");
1395 return -1;
1396 }
1397
1398 for (i = 0; i < NUM_URBS; ++i) {
1399 if (mos7840_port->write_urb_pool[i]->status != -EINPROGRESS) {
1400 room += URB_TRANSFER_BUFFER_SIZE;
1401 }
1402 }
1403
1404 dbg("%s - returns %d", __FUNCTION__, room);
1405 return (room);
1406
1407}
1408
1409/*****************************************************************************
1410 * mos7840_write
1411 * this function is called by the tty driver when data should be written to
1412 * the port.
1413 * If successful, we return the number of bytes written, otherwise we
1414 * return a negative error number.
1415 *****************************************************************************/
1416
1417static int mos7840_write(struct usb_serial_port *port,
1418 const unsigned char *data, int count)
1419{
1420 int status;
1421 int i;
1422 int bytes_sent = 0;
1423 int transfer_size;
1424 int from_user = 0;
1425
1426 struct moschip_port *mos7840_port;
1427 struct usb_serial *serial;
1428 struct urb *urb;
1429 //__u16 Data;
1430 const unsigned char *current_position = data;
1431 unsigned char *data1;
1432 dbg("%s \n", "entering ...........");
1433 //dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",mos7840_port->shadowLCR);
1434
1435#ifdef NOTMOS7840
1436 Data = 0x00;
1437 status = 0;
1438 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
1439 mos7840_port->shadowLCR = Data;
1440 dbg("mos7840_write: LINE_CONTROL_REGISTER is %x\n", Data);
1441 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",
1442 mos7840_port->shadowLCR);
1443
1444 //Data = 0x03;
1445 //status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data);
1446 //mos7840_port->shadowLCR=Data;//Need to add later
1447
1448 Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80
1449 status = 0;
1450 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1451
1452 //Data = 0x0c;
1453 //status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data);
1454 Data = 0x00;
1455 status = 0;
1456 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data);
1457 dbg("mos7840_write:DLL value is %x\n", Data);
1458
1459 Data = 0x0;
1460 status = 0;
1461 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data);
1462 dbg("mos7840_write:DLM value is %x\n", Data);
1463
1464 Data = Data & ~SERIAL_LCR_DLAB;
1465 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",
1466 mos7840_port->shadowLCR);
1467 status = 0;
1468 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1469#endif
1470
1471 if (mos7840_port_paranoia_check(port, __FUNCTION__)) {
1472 dbg("%s", "Port Paranoia failed \n");
1473 return -1;
1474 }
1475
1476 serial = port->serial;
1477 if (mos7840_serial_paranoia_check(serial, __FUNCTION__)) {
1478 dbg("%s", "Serial Paranoia failed \n");
1479 return -1;
1480 }
1481
1482 mos7840_port = mos7840_get_port_private(port);
1483 if (mos7840_port == NULL) {
1484 dbg("%s", "mos7840_port is NULL\n");
1485 return -1;
1486 }
1487
1488 /* try to find a free urb in the list */
1489 urb = NULL;
1490
1491 for (i = 0; i < NUM_URBS; ++i) {
1492 if (mos7840_port->write_urb_pool[i]->status != -EINPROGRESS) {
1493 urb = mos7840_port->write_urb_pool[i];
1494 dbg("\nURB:%d", i);
1495 break;
1496 }
1497 }
1498
1499 if (urb == NULL) {
1500 dbg("%s - no more free urbs", __FUNCTION__);
1501 goto exit;
1502 }
1503
1504 if (urb->transfer_buffer == NULL) {
1505 urb->transfer_buffer =
1506 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
1507
1508 if (urb->transfer_buffer == NULL) {
1509 err("%s no more kernel memory...", __FUNCTION__);
1510 goto exit;
1511 }
1512 }
1513 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
1514
1515 if (from_user) {
1516 if (copy_from_user
1517 (urb->transfer_buffer, current_position, transfer_size)) {
1518 bytes_sent = -EFAULT;
1519 goto exit;
1520 }
1521 } else {
1522 memcpy(urb->transfer_buffer, current_position, transfer_size);
1523 }
1524
1525 /* fill urb with data and submit */
1526 usb_fill_bulk_urb(urb,
1527 serial->dev,
1528 usb_sndbulkpipe(serial->dev,
1529 port->bulk_out_endpointAddress),
1530 urb->transfer_buffer,
1531 transfer_size,
1532 mos7840_bulk_out_data_callback, mos7840_port);
1533
1534 data1 = urb->transfer_buffer;
1535 dbg("\nbulkout endpoint is %d", port->bulk_out_endpointAddress);
1536
1537 /* send it down the pipe */
1538 status = usb_submit_urb(urb, GFP_ATOMIC);
1539
1540 if (status) {
1541 err("%s - usb_submit_urb(write bulk) failed with status = %d",
1542 __FUNCTION__, status);
1543 bytes_sent = status;
1544 goto exit;
1545 }
1546 bytes_sent = transfer_size;
1547 mos7840_port->icount.tx += transfer_size;
1548 dbg("mos7840_port->icount.tx is %d:\n", mos7840_port->icount.tx);
1549 exit:
1550
1551 return bytes_sent;
1552
1553}
1554
1555/*****************************************************************************
1556 * mos7840_throttle
1557 * this function is called by the tty driver when it wants to stop the data
1558 * being read from the port.
1559 *****************************************************************************/
1560
1561static void mos7840_throttle(struct usb_serial_port *port)
1562{
1563 struct moschip_port *mos7840_port;
1564 struct tty_struct *tty;
1565 int status;
1566
1567 if (mos7840_port_paranoia_check(port, __FUNCTION__)) {
1568 dbg("%s", "Invalid port \n");
1569 return;
1570 }
1571
1572 dbg("- port %d\n", port->number);
1573
1574 mos7840_port = mos7840_get_port_private(port);
1575
1576 if (mos7840_port == NULL)
1577 return;
1578
1579 if (!mos7840_port->open) {
1580 dbg("%s\n", "port not opened");
1581 return;
1582 }
1583
1584 dbg("%s", "Entering .......... \n");
1585
1586 tty = port->tty;
1587 if (!tty) {
1588 dbg("%s - no tty available", __FUNCTION__);
1589 return;
1590 }
1591
1592 /* if we are implementing XON/XOFF, send the stop character */
1593 if (I_IXOFF(tty)) {
1594 unsigned char stop_char = STOP_CHAR(tty);
1595 status = mos7840_write(port, &stop_char, 1);
1596 if (status <= 0) {
1597 return;
1598 }
1599 }
1600
1601 /* if we are implementing RTS/CTS, toggle that line */
1602 if (tty->termios->c_cflag & CRTSCTS) {
1603 mos7840_port->shadowMCR &= ~MCR_RTS;
1604 status = 0;
1605 status =
1606 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1607 mos7840_port->shadowMCR);
1608
1609 if (status < 0) {
1610 return;
1611 }
1612 }
1613
1614 return;
1615}
1616
1617/*****************************************************************************
1618 * mos7840_unthrottle
1619 * this function is called by the tty driver when it wants to resume the data
1620 * being read from the port (called after SerialThrottle is called)
1621 *****************************************************************************/
1622static void mos7840_unthrottle(struct usb_serial_port *port)
1623{
1624 struct tty_struct *tty;
1625 int status;
1626 struct moschip_port *mos7840_port = mos7840_get_port_private(port);
1627
1628 if (mos7840_port_paranoia_check(port, __FUNCTION__)) {
1629 dbg("%s", "Invalid port \n");
1630 return;
1631 }
1632
1633 if (mos7840_port == NULL)
1634 return;
1635
1636 if (!mos7840_port->open) {
1637 dbg("%s - port not opened", __FUNCTION__);
1638 return;
1639 }
1640
1641 dbg("%s", "Entering .......... \n");
1642
1643 tty = port->tty;
1644 if (!tty) {
1645 dbg("%s - no tty available", __FUNCTION__);
1646 return;
1647 }
1648
1649 /* if we are implementing XON/XOFF, send the start character */
1650 if (I_IXOFF(tty)) {
1651 unsigned char start_char = START_CHAR(tty);
1652 status = mos7840_write(port, &start_char, 1);
1653 if (status <= 0) {
1654 return;
1655 }
1656 }
1657
1658 /* if we are implementing RTS/CTS, toggle that line */
1659 if (tty->termios->c_cflag & CRTSCTS) {
1660 mos7840_port->shadowMCR |= MCR_RTS;
1661 status = 0;
1662 status =
1663 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1664 mos7840_port->shadowMCR);
1665 if (status < 0) {
1666 return;
1667 }
1668 }
1669
1670 return;
1671}
1672
1673static int mos7840_tiocmget(struct usb_serial_port *port, struct file *file)
1674{
1675 struct moschip_port *mos7840_port;
1676 unsigned int result;
1677 __u16 msr;
1678 __u16 mcr;
1679 int status = 0;
1680 mos7840_port = mos7840_get_port_private(port);
1681
1682 dbg("%s - port %d", __FUNCTION__, port->number);
1683
1684 if (mos7840_port == NULL)
1685 return -ENODEV;
1686
1687 status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr);
1688 status = mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr);
1689 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
1690 | ((mcr & MCR_RTS) ? TIOCM_RTS : 0)
1691 | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0)
1692 | ((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0)
1693 | ((msr & MOS7840_MSR_CD) ? TIOCM_CAR : 0)
1694 | ((msr & MOS7840_MSR_RI) ? TIOCM_RI : 0)
1695 | ((msr & MOS7840_MSR_DSR) ? TIOCM_DSR : 0);
1696
1697 dbg("%s - 0x%04X", __FUNCTION__, result);
1698
1699 return result;
1700}
1701
1702static int mos7840_tiocmset(struct usb_serial_port *port, struct file *file,
1703 unsigned int set, unsigned int clear)
1704{
1705 struct moschip_port *mos7840_port;
1706 unsigned int mcr;
1707 unsigned int status;
1708
1709 dbg("%s - port %d", __FUNCTION__, port->number);
1710
1711 mos7840_port = mos7840_get_port_private(port);
1712
1713 if (mos7840_port == NULL)
1714 return -ENODEV;
1715
1716 mcr = mos7840_port->shadowMCR;
1717 if (clear & TIOCM_RTS)
1718 mcr &= ~MCR_RTS;
1719 if (clear & TIOCM_DTR)
1720 mcr &= ~MCR_DTR;
1721 if (clear & TIOCM_LOOP)
1722 mcr &= ~MCR_LOOPBACK;
1723
1724 if (set & TIOCM_RTS)
1725 mcr |= MCR_RTS;
1726 if (set & TIOCM_DTR)
1727 mcr |= MCR_DTR;
1728 if (set & TIOCM_LOOP)
1729 mcr |= MCR_LOOPBACK;
1730
1731 mos7840_port->shadowMCR = mcr;
1732
1733 status = 0;
1734 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, mcr);
1735 if (status < 0) {
1736 dbg("setting MODEM_CONTROL_REGISTER Failed\n");
1737 return -1;
1738 }
1739
1740 return 0;
1741}
1742
1743/*****************************************************************************
1744 * mos7840_calc_baud_rate_divisor
1745 * this function calculates the proper baud rate divisor for the specified
1746 * baud rate.
1747 *****************************************************************************/
1748static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor,
1749 __u16 * clk_sel_val)
1750{
1751
1752 dbg("%s - %d", __FUNCTION__, baudRate);
1753
1754 if (baudRate <= 115200) {
1755 *divisor = 115200 / baudRate;
1756 *clk_sel_val = 0x0;
1757 }
1758 if ((baudRate > 115200) && (baudRate <= 230400)) {
1759 *divisor = 230400 / baudRate;
1760 *clk_sel_val = 0x10;
1761 } else if ((baudRate > 230400) && (baudRate <= 403200)) {
1762 *divisor = 403200 / baudRate;
1763 *clk_sel_val = 0x20;
1764 } else if ((baudRate > 403200) && (baudRate <= 460800)) {
1765 *divisor = 460800 / baudRate;
1766 *clk_sel_val = 0x30;
1767 } else if ((baudRate > 460800) && (baudRate <= 806400)) {
1768 *divisor = 806400 / baudRate;
1769 *clk_sel_val = 0x40;
1770 } else if ((baudRate > 806400) && (baudRate <= 921600)) {
1771 *divisor = 921600 / baudRate;
1772 *clk_sel_val = 0x50;
1773 } else if ((baudRate > 921600) && (baudRate <= 1572864)) {
1774 *divisor = 1572864 / baudRate;
1775 *clk_sel_val = 0x60;
1776 } else if ((baudRate > 1572864) && (baudRate <= 3145728)) {
1777 *divisor = 3145728 / baudRate;
1778 *clk_sel_val = 0x70;
1779 }
1780 return 0;
1781
1782#ifdef NOTMCS7840
1783
1784 for (i = 0; i < ARRAY_SIZE(mos7840_divisor_table); i++) {
1785 if (mos7840_divisor_table[i].BaudRate == baudrate) {
1786 *divisor = mos7840_divisor_table[i].Divisor;
1787 return 0;
1788 }
1789 }
1790
1791 /* After trying for all the standard baud rates *
1792 * Try calculating the divisor for this baud rate */
1793
1794 if (baudrate > 75 && baudrate < 230400) {
1795 /* get the divisor */
1796 custom = (__u16) (230400L / baudrate);
1797
1798 /* Check for round off */
1799 round1 = (__u16) (2304000L / baudrate);
1800 round = (__u16) (round1 - (custom * 10));
1801 if (round > 4) {
1802 custom++;
1803 }
1804 *divisor = custom;
1805
1806 dbg(" Baud %d = %d\n", baudrate, custom);
1807 return 0;
1808 }
1809
1810 dbg("%s\n", " Baud calculation Failed...");
1811 return -1;
1812#endif
1813}
1814
1815/*****************************************************************************
1816 * mos7840_send_cmd_write_baud_rate
1817 * this function sends the proper command to change the baud rate of the
1818 * specified port.
1819 *****************************************************************************/
1820
1821static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1822 int baudRate)
1823{
1824 int divisor = 0;
1825 int status;
1826 __u16 Data;
1827 unsigned char number;
1828 __u16 clk_sel_val;
1829 struct usb_serial_port *port;
1830
1831 if (mos7840_port == NULL)
1832 return -1;
1833
1834 port = (struct usb_serial_port *)mos7840_port->port;
1835 if (mos7840_port_paranoia_check(port, __FUNCTION__)) {
1836 dbg("%s", "Invalid port \n");
1837 return -1;
1838 }
1839
1840 if (mos7840_serial_paranoia_check(port->serial, __FUNCTION__)) {
1841 dbg("%s", "Invalid Serial \n");
1842 return -1;
1843 }
1844
1845 dbg("%s", "Entering .......... \n");
1846
1847 number = mos7840_port->port->number - mos7840_port->port->serial->minor;
1848
1849 dbg("%s - port = %d, baud = %d", __FUNCTION__,
1850 mos7840_port->port->number, baudRate);
1851 //reset clk_uart_sel in spregOffset
1852 if (baudRate > 115200) {
1853#ifdef HW_flow_control
1854 //NOTE: need to see the pther register to modify
1855 //setting h/w flow control bit to 1;
1856 status = 0;
1857 Data = 0x2b;
1858 mos7840_port->shadowMCR = Data;
1859 status =
1860 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1861 if (status < 0) {
1862 dbg("Writing spreg failed in set_serial_baud\n");
1863 return -1;
1864 }
1865#endif
1866
1867 } else {
1868#ifdef HW_flow_control
1869 //setting h/w flow control bit to 0;
1870 status = 0;
1871 Data = 0xb;
1872 mos7840_port->shadowMCR = Data;
1873 status =
1874 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1875 if (status < 0) {
1876 dbg("Writing spreg failed in set_serial_baud\n");
1877 return -1;
1878 }
1879#endif
1880
1881 }
1882
1883 if (1) //baudRate <= 115200)
1884 {
1885 clk_sel_val = 0x0;
1886 Data = 0x0;
1887 status = 0;
1888 status =
1889 mos7840_calc_baud_rate_divisor(baudRate, &divisor,
1890 &clk_sel_val);
1891 status =
1892 mos7840_get_reg_sync(port, mos7840_port->SpRegOffset,
1893 &Data);
1894 if (status < 0) {
1895 dbg("reading spreg failed in set_serial_baud\n");
1896 return -1;
1897 }
1898 Data = (Data & 0x8f) | clk_sel_val;
1899 status = 0;
1900 status =
1901 mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
1902 if (status < 0) {
1903 dbg("Writing spreg failed in set_serial_baud\n");
1904 return -1;
1905 }
1906 /* Calculate the Divisor */
1907
1908 if (status) {
1909 err("%s - bad baud rate", __FUNCTION__);
1910 dbg("%s\n", "bad baud rate");
1911 return status;
1912 }
1913 /* Enable access to divisor latch */
1914 Data = mos7840_port->shadowLCR | SERIAL_LCR_DLAB;
1915 mos7840_port->shadowLCR = Data;
1916 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1917
1918 /* Write the divisor */
1919 Data = (unsigned char)(divisor & 0xff);
1920 dbg("set_serial_baud Value to write DLL is %x\n", Data);
1921 mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
1922
1923 Data = (unsigned char)((divisor & 0xff00) >> 8);
1924 dbg("set_serial_baud Value to write DLM is %x\n", Data);
1925 mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
1926
1927 /* Disable access to divisor latch */
1928 Data = mos7840_port->shadowLCR & ~SERIAL_LCR_DLAB;
1929 mos7840_port->shadowLCR = Data;
1930 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1931
1932 }
1933
1934 return status;
1935}
1936
1937/*****************************************************************************
1938 * mos7840_change_port_settings
1939 * This routine is called to set the UART on the device to match
1940 * the specified new settings.
1941 *****************************************************************************/
1942
1943static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
1944 struct termios *old_termios)
1945{
1946 struct tty_struct *tty;
1947 int baud;
1948 unsigned cflag;
1949 unsigned iflag;
1950 __u8 lData;
1951 __u8 lParity;
1952 __u8 lStop;
1953 int status;
1954 __u16 Data;
1955 struct usb_serial_port *port;
1956 struct usb_serial *serial;
1957
1958 if (mos7840_port == NULL)
1959 return;
1960
1961 port = (struct usb_serial_port *)mos7840_port->port;
1962
1963 if (mos7840_port_paranoia_check(port, __FUNCTION__)) {
1964 dbg("%s", "Invalid port \n");
1965 return;
1966 }
1967
1968 if (mos7840_serial_paranoia_check(port->serial, __FUNCTION__)) {
1969 dbg("%s", "Invalid Serial \n");
1970 return;
1971 }
1972
1973 serial = port->serial;
1974
1975 dbg("%s - port %d", __FUNCTION__, mos7840_port->port->number);
1976
1977 if (!mos7840_port->open) {
1978 dbg("%s - port not opened", __FUNCTION__);
1979 return;
1980 }
1981
1982 tty = mos7840_port->port->tty;
1983
1984 if ((!tty) || (!tty->termios)) {
1985 dbg("%s - no tty structures", __FUNCTION__);
1986 return;
1987 }
1988
1989 dbg("%s", "Entering .......... \n");
1990
1991 lData = LCR_BITS_8;
1992 lStop = LCR_STOP_1;
1993 lParity = LCR_PAR_NONE;
1994
1995 cflag = tty->termios->c_cflag;
1996 iflag = tty->termios->c_iflag;
1997
1998 /* Change the number of bits */
1999 if (cflag & CSIZE) {
2000 switch (cflag & CSIZE) {
2001 case CS5:
2002 lData = LCR_BITS_5;
2003 break;
2004
2005 case CS6:
2006 lData = LCR_BITS_6;
2007 break;
2008
2009 case CS7:
2010 lData = LCR_BITS_7;
2011 break;
2012 default:
2013 case CS8:
2014 lData = LCR_BITS_8;
2015 break;
2016 }
2017 }
2018 /* Change the Parity bit */
2019 if (cflag & PARENB) {
2020 if (cflag & PARODD) {
2021 lParity = LCR_PAR_ODD;
2022 dbg("%s - parity = odd", __FUNCTION__);
2023 } else {
2024 lParity = LCR_PAR_EVEN;
2025 dbg("%s - parity = even", __FUNCTION__);
2026 }
2027
2028 } else {
2029 dbg("%s - parity = none", __FUNCTION__);
2030 }
2031
2032 if (cflag & CMSPAR) {
2033 lParity = lParity | 0x20;
2034 }
2035
2036 /* Change the Stop bit */
2037 if (cflag & CSTOPB) {
2038 lStop = LCR_STOP_2;
2039 dbg("%s - stop bits = 2", __FUNCTION__);
2040 } else {
2041 lStop = LCR_STOP_1;
2042 dbg("%s - stop bits = 1", __FUNCTION__);
2043 }
2044
2045 /* Update the LCR with the correct value */
2046 mos7840_port->shadowLCR &=
2047 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
2048 mos7840_port->shadowLCR |= (lData | lParity | lStop);
2049
2050 dbg("mos7840_change_port_settings mos7840_port->shadowLCR is %x\n",
2051 mos7840_port->shadowLCR);
2052 /* Disable Interrupts */
2053 Data = 0x00;
2054 mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
2055
2056 Data = 0x00;
2057 mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
2058
2059 Data = 0xcf;
2060 mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
2061
2062 /* Send the updated LCR value to the mos7840 */
2063 Data = mos7840_port->shadowLCR;
2064
2065 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
2066
2067 Data = 0x00b;
2068 mos7840_port->shadowMCR = Data;
2069 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2070 Data = 0x00b;
2071 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2072
2073 /* set up the MCR register and send it to the mos7840 */
2074
2075 mos7840_port->shadowMCR = MCR_MASTER_IE;
2076 if (cflag & CBAUD) {
2077 mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS);
2078 }
2079
2080 if (cflag & CRTSCTS) {
2081 mos7840_port->shadowMCR |= (MCR_XON_ANY);
2082
2083 } else {
2084 mos7840_port->shadowMCR &= ~(MCR_XON_ANY);
2085 }
2086
2087 Data = mos7840_port->shadowMCR;
2088 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2089
2090 /* Determine divisor based on baud rate */
2091 baud = tty_get_baud_rate(tty);
2092
2093 if (!baud) {
2094 /* pick a default, any default... */
2095 dbg("%s\n", "Picked default baud...");
2096 baud = 9600;
2097 }
2098
2099 dbg("%s - baud rate = %d", __FUNCTION__, baud);
2100 status = mos7840_send_cmd_write_baud_rate(mos7840_port, baud);
2101
2102 /* Enable Interrupts */
2103 Data = 0x0c;
2104 mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
2105
2106 if (mos7840_port->read_urb->status != -EINPROGRESS) {
2107 mos7840_port->read_urb->dev = serial->dev;
2108
2109 status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
2110
2111 if (status) {
2112 dbg(" usb_submit_urb(read bulk) failed, status = %d",
2113 status);
2114 }
2115 }
2116 wake_up(&mos7840_port->delta_msr_wait);
2117 mos7840_port->delta_msr_cond = 1;
2118 dbg("mos7840_change_port_settings mos7840_port->shadowLCR is End %x\n",
2119 mos7840_port->shadowLCR);
2120
2121 return;
2122}
2123
2124/*****************************************************************************
2125 * mos7840_set_termios
2126 * this function is called by the tty driver when it wants to change
2127 * the termios structure
2128 *****************************************************************************/
2129
2130static void mos7840_set_termios(struct usb_serial_port *port,
2131 struct termios *old_termios)
2132{
2133 int status;
2134 unsigned int cflag;
2135 struct usb_serial *serial;
2136 struct moschip_port *mos7840_port;
2137 struct tty_struct *tty;
2138 dbg("mos7840_set_termios: START\n");
2139 if (mos7840_port_paranoia_check(port, __FUNCTION__)) {
2140 dbg("%s", "Invalid port \n");
2141 return;
2142 }
2143
2144 serial = port->serial;
2145
2146 if (mos7840_serial_paranoia_check(serial, __FUNCTION__)) {
2147 dbg("%s", "Invalid Serial \n");
2148 return;
2149 }
2150
2151 mos7840_port = mos7840_get_port_private(port);
2152
2153 if (mos7840_port == NULL)
2154 return;
2155
2156 tty = port->tty;
2157
2158 if (!port->tty || !port->tty->termios) {
2159 dbg("%s - no tty or termios", __FUNCTION__);
2160 return;
2161 }
2162
2163 if (!mos7840_port->open) {
2164 dbg("%s - port not opened", __FUNCTION__);
2165 return;
2166 }
2167
2168 dbg("%s\n", "setting termios - ");
2169
2170 cflag = tty->termios->c_cflag;
2171
2172 if (!cflag) {
2173 dbg("%s %s\n", __FUNCTION__, "cflag is NULL");
2174 return;
2175 }
2176
2177 /* check that they really want us to change something */
2178 if (old_termios) {
2179 if ((cflag == old_termios->c_cflag) &&
2180 (RELEVANT_IFLAG(tty->termios->c_iflag) ==
2181 RELEVANT_IFLAG(old_termios->c_iflag))) {
2182 dbg("%s\n", "Nothing to change");
2183 return;
2184 }
2185 }
2186
2187 dbg("%s - clfag %08x iflag %08x", __FUNCTION__,
2188 tty->termios->c_cflag, RELEVANT_IFLAG(tty->termios->c_iflag));
2189
2190 if (old_termios) {
2191 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,
2192 old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag));
2193 }
2194
2195 dbg("%s - port %d", __FUNCTION__, port->number);
2196
2197 /* change the port settings to the new ones specified */
2198
2199 mos7840_change_port_settings(mos7840_port, old_termios);
2200
2201 if (!mos7840_port->read_urb) {
2202 dbg("%s", "URB KILLED !!!!!\n");
2203 return;
2204 }
2205
2206 if (mos7840_port->read_urb->status != -EINPROGRESS) {
2207 mos7840_port->read_urb->dev = serial->dev;
2208 status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
2209 if (status) {
2210 dbg(" usb_submit_urb(read bulk) failed, status = %d",
2211 status);
2212 }
2213 }
2214 return;
2215}
2216
2217/*****************************************************************************
2218 * mos7840_get_lsr_info - get line status register info
2219 *
2220 * Purpose: Let user call ioctl() to get info when the UART physically
2221 * is emptied. On bus types like RS485, the transmitter must
2222 * release the bus after transmitting. This must be done when
2223 * the transmit shift register is empty, not be done when the
2224 * transmit holding register is empty. This functionality
2225 * allows an RS485 driver to be written in user space.
2226 *****************************************************************************/
2227
2228static int mos7840_get_lsr_info(struct moschip_port *mos7840_port,
2229 unsigned int *value)
2230{
2231 int count;
2232 unsigned int result = 0;
2233
2234 count = mos7840_chars_in_buffer(mos7840_port->port);
2235 if (count == 0) {
2236 dbg("%s -- Empty", __FUNCTION__);
2237 result = TIOCSER_TEMT;
2238 }
2239
2240 if (copy_to_user(value, &result, sizeof(int)))
2241 return -EFAULT;
2242 return 0;
2243}
2244
2245/*****************************************************************************
2246 * mos7840_get_bytes_avail - get number of bytes available
2247 *
2248 * Purpose: Let user call ioctl to get the count of number of bytes available.
2249 *****************************************************************************/
2250
2251static int mos7840_get_bytes_avail(struct moschip_port *mos7840_port,
2252 unsigned int *value)
2253{
2254 unsigned int result = 0;
2255 struct tty_struct *tty = mos7840_port->port->tty;
2256
2257 if (!tty)
2258 return -ENOIOCTLCMD;
2259
2260 result = tty->read_cnt;
2261
2262 dbg("%s(%d) = %d", __FUNCTION__, mos7840_port->port->number, result);
2263 if (copy_to_user(value, &result, sizeof(int)))
2264 return -EFAULT;
2265
2266 return -ENOIOCTLCMD;
2267}
2268
2269/*****************************************************************************
2270 * mos7840_set_modem_info
2271 * function to set modem info
2272 *****************************************************************************/
2273
2274static int mos7840_set_modem_info(struct moschip_port *mos7840_port,
2275 unsigned int cmd, unsigned int *value)
2276{
2277 unsigned int mcr;
2278 unsigned int arg;
2279 __u16 Data;
2280 int status;
2281 struct usb_serial_port *port;
2282
2283 if (mos7840_port == NULL)
2284 return -1;
2285
2286 port = (struct usb_serial_port *)mos7840_port->port;
2287 if (mos7840_port_paranoia_check(port, __FUNCTION__)) {
2288 dbg("%s", "Invalid port \n");
2289 return -1;
2290 }
2291
2292 mcr = mos7840_port->shadowMCR;
2293
2294 if (copy_from_user(&arg, value, sizeof(int)))
2295 return -EFAULT;
2296
2297 switch (cmd) {
2298 case TIOCMBIS:
2299 if (arg & TIOCM_RTS)
2300 mcr |= MCR_RTS;
2301 if (arg & TIOCM_DTR)
2302 mcr |= MCR_RTS;
2303 if (arg & TIOCM_LOOP)
2304 mcr |= MCR_LOOPBACK;
2305 break;
2306
2307 case TIOCMBIC:
2308 if (arg & TIOCM_RTS)
2309 mcr &= ~MCR_RTS;
2310 if (arg & TIOCM_DTR)
2311 mcr &= ~MCR_RTS;
2312 if (arg & TIOCM_LOOP)
2313 mcr &= ~MCR_LOOPBACK;
2314 break;
2315
2316 case TIOCMSET:
2317 /* turn off the RTS and DTR and LOOPBACK
2318 * and then only turn on what was asked to */
2319 mcr &= ~(MCR_RTS | MCR_DTR | MCR_LOOPBACK);
2320 mcr |= ((arg & TIOCM_RTS) ? MCR_RTS : 0);
2321 mcr |= ((arg & TIOCM_DTR) ? MCR_DTR : 0);
2322 mcr |= ((arg & TIOCM_LOOP) ? MCR_LOOPBACK : 0);
2323 break;
2324 }
2325
2326 mos7840_port->shadowMCR = mcr;
2327
2328 Data = mos7840_port->shadowMCR;
2329 status = 0;
2330 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2331 if (status < 0) {
2332 dbg("setting MODEM_CONTROL_REGISTER Failed\n");
2333 return -1;
2334 }
2335
2336 return 0;
2337}
2338
2339/*****************************************************************************
2340 * mos7840_get_modem_info
2341 * function to get modem info
2342 *****************************************************************************/
2343
2344static int mos7840_get_modem_info(struct moschip_port *mos7840_port,
2345 unsigned int *value)
2346{
2347 unsigned int result = 0;
2348 __u16 msr;
2349 unsigned int mcr = mos7840_port->shadowMCR;
2350 int status = 0;
2351 status =
2352 mos7840_get_uart_reg(mos7840_port->port, MODEM_STATUS_REGISTER,
2353 &msr);
2354 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */
2355 |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */
2356 |((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */
2357 |((msr & MOS7840_MSR_CD) ? TIOCM_CAR : 0) /* 0x040 */
2358 |((msr & MOS7840_MSR_RI) ? TIOCM_RI : 0) /* 0x080 */
2359 |((msr & MOS7840_MSR_DSR) ? TIOCM_DSR : 0); /* 0x100 */
2360
2361 dbg("%s -- %x", __FUNCTION__, result);
2362
2363 if (copy_to_user(value, &result, sizeof(int)))
2364 return -EFAULT;
2365 return 0;
2366}
2367
2368/*****************************************************************************
2369 * mos7840_get_serial_info
2370 * function to get information about serial port
2371 *****************************************************************************/
2372
2373static int mos7840_get_serial_info(struct moschip_port *mos7840_port,
2374 struct serial_struct *retinfo)
2375{
2376 struct serial_struct tmp;
2377
2378 if (mos7840_port == NULL)
2379 return -1;
2380
2381 if (!retinfo)
2382 return -EFAULT;
2383
2384 memset(&tmp, 0, sizeof(tmp));
2385
2386 tmp.type = PORT_16550A;
2387 tmp.line = mos7840_port->port->serial->minor;
2388 tmp.port = mos7840_port->port->number;
2389 tmp.irq = 0;
2390 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
2391 tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
2392 tmp.baud_base = 9600;
2393 tmp.close_delay = 5 * HZ;
2394 tmp.closing_wait = 30 * HZ;
2395
2396 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2397 return -EFAULT;
2398 return 0;
2399}
2400
2401/*****************************************************************************
2402 * SerialIoctl
2403 * this function handles any ioctl calls to the driver
2404 *****************************************************************************/
2405
2406static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2407 unsigned int cmd, unsigned long arg)
2408{
2409 struct moschip_port *mos7840_port;
2410 struct tty_struct *tty;
2411
2412 struct async_icount cnow;
2413 struct async_icount cprev;
2414 struct serial_icounter_struct icount;
2415 int mosret = 0;
2416 int retval;
2417 struct tty_ldisc *ld;
2418
2419 if (mos7840_port_paranoia_check(port, __FUNCTION__)) {
2420 dbg("%s", "Invalid port \n");
2421 return -1;
2422 }
2423
2424 mos7840_port = mos7840_get_port_private(port);
2425 tty = mos7840_port->port->tty;
2426
2427 if (mos7840_port == NULL)
2428 return -1;
2429
2430 dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd);
2431
2432 switch (cmd) {
2433 /* return number of bytes available */
2434
2435 case TIOCINQ:
2436 dbg("%s (%d) TIOCINQ", __FUNCTION__, port->number);
2437 return mos7840_get_bytes_avail(mos7840_port,
2438 (unsigned int *)arg);
2439 break;
2440
2441 case TIOCOUTQ:
2442 dbg("%s (%d) TIOCOUTQ", __FUNCTION__, port->number);
2443 return put_user(tty->driver->chars_in_buffer ?
2444 tty->driver->chars_in_buffer(tty) : 0,
2445 (int __user *)arg);
2446 break;
2447
2448 case TCFLSH:
2449 retval = tty_check_change(tty);
2450 if (retval)
2451 return retval;
2452
2453 ld = tty_ldisc_ref(tty);
2454 switch (arg) {
2455 case TCIFLUSH:
2456 if (ld && ld->flush_buffer)
2457 ld->flush_buffer(tty);
2458 break;
2459 case TCIOFLUSH:
2460 if (ld && ld->flush_buffer)
2461 ld->flush_buffer(tty);
2462 /* fall through */
2463 case TCOFLUSH:
2464 if (tty->driver->flush_buffer)
2465 tty->driver->flush_buffer(tty);
2466 break;
2467 default:
2468 tty_ldisc_deref(ld);
2469 return -EINVAL;
2470 }
2471 tty_ldisc_deref(ld);
2472 return 0;
2473
2474 case TCGETS:
2475 if (kernel_termios_to_user_termios
2476 ((struct termios __user *)arg, tty->termios))
2477 return -EFAULT;
2478 return 0;
2479
2480 case TIOCSERGETLSR:
2481 dbg("%s (%d) TIOCSERGETLSR", __FUNCTION__, port->number);
2482 return mos7840_get_lsr_info(mos7840_port, (unsigned int *)arg);
2483 return 0;
2484
2485 case TIOCMBIS:
2486 case TIOCMBIC:
2487 case TIOCMSET:
2488 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __FUNCTION__,
2489 port->number);
2490 mosret =
2491 mos7840_set_modem_info(mos7840_port, cmd,
2492 (unsigned int *)arg);
2493 return mosret;
2494
2495 case TIOCMGET:
2496 dbg("%s (%d) TIOCMGET", __FUNCTION__, port->number);
2497 return mos7840_get_modem_info(mos7840_port,
2498 (unsigned int *)arg);
2499
2500 case TIOCGSERIAL:
2501 dbg("%s (%d) TIOCGSERIAL", __FUNCTION__, port->number);
2502 return mos7840_get_serial_info(mos7840_port,
2503 (struct serial_struct *)arg);
2504
2505 case TIOCSSERIAL:
2506 dbg("%s (%d) TIOCSSERIAL", __FUNCTION__, port->number);
2507 break;
2508
2509 case TIOCMIWAIT:
2510 dbg("%s (%d) TIOCMIWAIT", __FUNCTION__, port->number);
2511 cprev = mos7840_port->icount;
2512 while (1) {
2513 //interruptible_sleep_on(&mos7840_port->delta_msr_wait);
2514 mos7840_port->delta_msr_cond = 0;
2515 wait_event_interruptible(mos7840_port->delta_msr_wait,
2516 (mos7840_port->
2517 delta_msr_cond == 1));
2518
2519 /* see if a signal did it */
2520 if (signal_pending(current))
2521 return -ERESTARTSYS;
2522 cnow = mos7840_port->icount;
2523 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2524 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2525 return -EIO; /* no change => error */
2526 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2527 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2528 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2529 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
2530 return 0;
2531 }
2532 cprev = cnow;
2533 }
2534 /* NOTREACHED */
2535 break;
2536
2537 case TIOCGICOUNT:
2538 cnow = mos7840_port->icount;
2539 icount.cts = cnow.cts;
2540 icount.dsr = cnow.dsr;
2541 icount.rng = cnow.rng;
2542 icount.dcd = cnow.dcd;
2543 icount.rx = cnow.rx;
2544 icount.tx = cnow.tx;
2545 icount.frame = cnow.frame;
2546 icount.overrun = cnow.overrun;
2547 icount.parity = cnow.parity;
2548 icount.brk = cnow.brk;
2549 icount.buf_overrun = cnow.buf_overrun;
2550
2551 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__,
2552 port->number, icount.rx, icount.tx);
2553 if (copy_to_user((void *)arg, &icount, sizeof(icount)))
2554 return -EFAULT;
2555 return 0;
2556
2557 case TIOCEXBAUD:
2558 return 0;
2559 default:
2560 break;
2561 }
2562
2563 return -ENOIOCTLCMD;
2564}
2565
2566static int mos7840_calc_num_ports(struct usb_serial *serial)
2567{
2568
2569 dbg("numberofendpoints: %d \n",
2570 (int)serial->interface->cur_altsetting->desc.bNumEndpoints);
2571 dbg("numberofendpoints: %d \n",
2572 (int)serial->interface->altsetting->desc.bNumEndpoints);
2573 if (serial->interface->cur_altsetting->desc.bNumEndpoints == 5) {
2574 mos7840_num_ports = 2;
2575 serial->type->num_ports = 2;
2576 } else if (serial->interface->cur_altsetting->desc.bNumEndpoints == 9) {
2577 mos7840_num_ports = 4;
2578 serial->type->num_bulk_in = 4;
2579 serial->type->num_bulk_out = 4;
2580 serial->type->num_ports = 4;
2581 }
2582
2583 return mos7840_num_ports;
2584}
2585
2586/****************************************************************************
2587 * mos7840_startup
2588 ****************************************************************************/
2589
2590static int mos7840_startup(struct usb_serial *serial)
2591{
2592 struct moschip_port *mos7840_port;
2593 struct usb_device *dev;
2594 int i, status;
2595
2596 __u16 Data;
2597 dbg("%s \n", " mos7840_startup :entering..........");
2598
2599 if (!serial) {
2600 dbg("%s\n", "Invalid Handler");
2601 return -1;
2602 }
2603
2604 dev = serial->dev;
2605
2606 dbg("%s\n", "Entering...");
2607
2608 /* we set up the pointers to the endpoints in the mos7840_open *
2609 * function, as the structures aren't created yet. */
2610
2611 /* set up port private structures */
2612 for (i = 0; i < serial->num_ports; ++i) {
2613 mos7840_port = kmalloc(sizeof(struct moschip_port), GFP_KERNEL);
2614 if (mos7840_port == NULL) {
2615 err("%s - Out of memory", __FUNCTION__);
2616 return -ENOMEM;
2617 }
2618 memset(mos7840_port, 0, sizeof(struct moschip_port));
2619
2620 /* Initialize all port interrupt end point to port 0 int endpoint *
2621 * Our device has only one interrupt end point comman to all port */
2622
2623 mos7840_port->port = serial->port[i];
2624 mos7840_set_port_private(serial->port[i], mos7840_port);
2625
2626 mos7840_port->port_num = ((serial->port[i]->number -
2627 (serial->port[i]->serial->minor)) +
2628 1);
2629
2630 if (mos7840_port->port_num == 1) {
2631 mos7840_port->SpRegOffset = 0x0;
2632 mos7840_port->ControlRegOffset = 0x1;
2633 mos7840_port->DcrRegOffset = 0x4;
2634 } else if ((mos7840_port->port_num == 2)
2635 && (mos7840_num_ports == 4)) {
2636 mos7840_port->SpRegOffset = 0x8;
2637 mos7840_port->ControlRegOffset = 0x9;
2638 mos7840_port->DcrRegOffset = 0x16;
2639 } else if ((mos7840_port->port_num == 2)
2640 && (mos7840_num_ports == 2)) {
2641 mos7840_port->SpRegOffset = 0xa;
2642 mos7840_port->ControlRegOffset = 0xb;
2643 mos7840_port->DcrRegOffset = 0x19;
2644 } else if ((mos7840_port->port_num == 3)
2645 && (mos7840_num_ports == 4)) {
2646 mos7840_port->SpRegOffset = 0xa;
2647 mos7840_port->ControlRegOffset = 0xb;
2648 mos7840_port->DcrRegOffset = 0x19;
2649 } else if ((mos7840_port->port_num == 4)
2650 && (mos7840_num_ports == 4)) {
2651 mos7840_port->SpRegOffset = 0xc;
2652 mos7840_port->ControlRegOffset = 0xd;
2653 mos7840_port->DcrRegOffset = 0x1c;
2654 }
2655 mos7840_dump_serial_port(mos7840_port);
2656
2657 mos7840_set_port_private(serial->port[i], mos7840_port);
2658
2659 //enable rx_disable bit in control register
2660
2661 status =
2662 mos7840_get_reg_sync(serial->port[i],
2663 mos7840_port->ControlRegOffset, &Data);
2664 if (status < 0) {
2665 dbg("Reading ControlReg failed status-0x%x\n", status);
2666 break;
2667 } else
2668 dbg("ControlReg Reading success val is %x, status%d\n",
2669 Data, status);
2670 Data |= 0x08; //setting driver done bit
2671 Data |= 0x04; //sp1_bit to have cts change reflect in modem status reg
2672
2673 //Data |= 0x20; //rx_disable bit
2674 status = 0;
2675 status =
2676 mos7840_set_reg_sync(serial->port[i],
2677 mos7840_port->ControlRegOffset, Data);
2678 if (status < 0) {
2679 dbg("Writing ControlReg failed(rx_disable) status-0x%x\n", status);
2680 break;
2681 } else
2682 dbg("ControlReg Writing success(rx_disable) status%d\n",
2683 status);
2684
2685 //Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2 and 0x24 in DCR3
2686 Data = 0x01;
2687 status = 0;
2688 status =
2689 mos7840_set_reg_sync(serial->port[i],
2690 (__u16) (mos7840_port->DcrRegOffset +
2691 0), Data);
2692 if (status < 0) {
2693 dbg("Writing DCR0 failed status-0x%x\n", status);
2694 break;
2695 } else
2696 dbg("DCR0 Writing success status%d\n", status);
2697
2698 Data = 0x05;
2699 status = 0;
2700 status =
2701 mos7840_set_reg_sync(serial->port[i],
2702 (__u16) (mos7840_port->DcrRegOffset +
2703 1), Data);
2704 if (status < 0) {
2705 dbg("Writing DCR1 failed status-0x%x\n", status);
2706 break;
2707 } else
2708 dbg("DCR1 Writing success status%d\n", status);
2709
2710 Data = 0x24;
2711 status = 0;
2712 status =
2713 mos7840_set_reg_sync(serial->port[i],
2714 (__u16) (mos7840_port->DcrRegOffset +
2715 2), Data);
2716 if (status < 0) {
2717 dbg("Writing DCR2 failed status-0x%x\n", status);
2718 break;
2719 } else
2720 dbg("DCR2 Writing success status%d\n", status);
2721
2722 // write values in clkstart0x0 and clkmulti 0x20
2723 Data = 0x0;
2724 status = 0;
2725 status =
2726 mos7840_set_reg_sync(serial->port[i],
2727 CLK_START_VALUE_REGISTER, Data);
2728 if (status < 0) {
2729 dbg("Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status);
2730 break;
2731 } else
2732 dbg("CLK_START_VALUE_REGISTER Writing success status%d\n", status);
2733
2734 Data = 0x20;
2735 status = 0;
2736 status =
2737 mos7840_set_reg_sync(serial->port[i], CLK_MULTI_REGISTER,
2738 Data);
2739 if (status < 0) {
2740 dbg("Writing CLK_MULTI_REGISTER failed status-0x%x\n",
2741 status);
2742 break;
2743 } else
2744 dbg("CLK_MULTI_REGISTER Writing success status%d\n",
2745 status);
2746
2747 //write value 0x0 to scratchpad register
2748 Data = 0x00;
2749 status = 0;
2750 status =
2751 mos7840_set_uart_reg(serial->port[i], SCRATCH_PAD_REGISTER,
2752 Data);
2753 if (status < 0) {
2754 dbg("Writing SCRATCH_PAD_REGISTER failed status-0x%x\n",
2755 status);
2756 break;
2757 } else
2758 dbg("SCRATCH_PAD_REGISTER Writing success status%d\n",
2759 status);
2760
2761 //Zero Length flag register
2762 if ((mos7840_port->port_num != 1)
2763 && (mos7840_num_ports == 2)) {
2764
2765 Data = 0xff;
2766 status = 0;
2767 status = mos7840_set_reg_sync(serial->port[i],
2768 (__u16) (ZLP_REG1 +
2769 ((__u16)
2770 mos7840_port->
2771 port_num)),
2772 Data);
2773 dbg("ZLIP offset%x\n",
2774 (__u16) (ZLP_REG1 +
2775 ((__u16) mos7840_port->port_num)));
2776 if (status < 0) {
2777 dbg("Writing ZLP_REG%d failed status-0x%x\n",
2778 i + 2, status);
2779 break;
2780 } else
2781 dbg("ZLP_REG%d Writing success status%d\n",
2782 i + 2, status);
2783 } else {
2784 Data = 0xff;
2785 status = 0;
2786 status = mos7840_set_reg_sync(serial->port[i],
2787 (__u16) (ZLP_REG1 +
2788 ((__u16)
2789 mos7840_port->
2790 port_num) -
2791 0x1), Data);
2792 dbg("ZLIP offset%x\n",
2793 (__u16) (ZLP_REG1 +
2794 ((__u16) mos7840_port->port_num) - 0x1));
2795 if (status < 0) {
2796 dbg("Writing ZLP_REG%d failed status-0x%x\n",
2797 i + 1, status);
2798 break;
2799 } else
2800 dbg("ZLP_REG%d Writing success status%d\n",
2801 i + 1, status);
2802
2803 }
2804 mos7840_port->control_urb = usb_alloc_urb(0, SLAB_ATOMIC);
2805 mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
2806
2807 }
2808
2809 //Zero Length flag enable
2810 Data = 0x0f;
2811 status = 0;
2812 status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data);
2813 if (status < 0) {
2814 dbg("Writing ZLP_REG5 failed status-0x%x\n", status);
2815 return -1;
2816 } else
2817 dbg("ZLP_REG5 Writing success status%d\n", status);
2818
2819 /* setting configuration feature to one */
2820 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
2821 (__u8) 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 5 * HZ);
2822 return 0;
2823}
2824
2825/****************************************************************************
2826 * mos7840_shutdown
2827 * This function is called whenever the device is removed from the usb bus.
2828 ****************************************************************************/
2829
2830static void mos7840_shutdown(struct usb_serial *serial)
2831{
2832 int i;
2833 struct moschip_port *mos7840_port;
2834 dbg("%s \n", " shutdown :entering..........");
2835
2836 if (!serial) {
2837 dbg("%s", "Invalid Handler \n");
2838 return;
2839 }
2840
2841 /* check for the ports to be closed,close the ports and disconnect */
2842
2843 /* free private structure allocated for serial port *
2844 * stop reads and writes on all ports */
2845
2846 for (i = 0; i < serial->num_ports; ++i) {
2847 mos7840_port = mos7840_get_port_private(serial->port[i]);
2848 kfree(mos7840_port->ctrl_buf);
2849 usb_kill_urb(mos7840_port->control_urb);
2850 kfree(mos7840_port);
2851 mos7840_set_port_private(serial->port[i], NULL);
2852 }
2853
2854 dbg("%s\n", "Thank u :: ");
2855
2856}
2857
2858static struct usb_serial_driver moschip7840_4port_device = {
2859 .driver = {
2860 .owner = THIS_MODULE,
2861 .name = "mos7840",
2862 },
2863 .description = DRIVER_DESC,
2864 .id_table = moschip_port_id_table,
2865 .num_interrupt_in = 1, //NUM_DONT_CARE,//1,
2866#ifdef check
2867 .num_bulk_in = 4,
2868 .num_bulk_out = 4,
2869 .num_ports = 4,
2870#endif
2871 .open = mos7840_open,
2872 .close = mos7840_close,
2873 .write = mos7840_write,
2874 .write_room = mos7840_write_room,
2875 .chars_in_buffer = mos7840_chars_in_buffer,
2876 .throttle = mos7840_throttle,
2877 .unthrottle = mos7840_unthrottle,
2878 .calc_num_ports = mos7840_calc_num_ports,
2879#ifdef MCSSerialProbe
2880 .probe = mos7840_serial_probe,
2881#endif
2882 .ioctl = mos7840_ioctl,
2883 .set_termios = mos7840_set_termios,
2884 .break_ctl = mos7840_break,
2885 .tiocmget = mos7840_tiocmget,
2886 .tiocmset = mos7840_tiocmset,
2887 .attach = mos7840_startup,
2888 .shutdown = mos7840_shutdown,
2889 .read_bulk_callback = mos7840_bulk_in_callback,
2890 .read_int_callback = mos7840_interrupt_callback,
2891};
2892
2893static struct usb_driver io_driver = {
2894 .name = "mos7840",
2895 .probe = usb_serial_probe,
2896 .disconnect = usb_serial_disconnect,
2897 .id_table = moschip_id_table_combined,
2898};
2899
2900/****************************************************************************
2901 * moschip7840_init
2902 * This is called by the module subsystem, or on startup to initialize us
2903 ****************************************************************************/
2904static int __init moschip7840_init(void)
2905{
2906 int retval;
2907
2908 dbg("%s \n", " mos7840_init :entering..........");
2909
2910 /* Register with the usb serial */
2911 retval = usb_serial_register(&moschip7840_4port_device);
2912
2913 if (retval)
2914 goto failed_port_device_register;
2915
2916 dbg("%s\n", "Entring...");
2917 info(DRIVER_DESC " " DRIVER_VERSION);
2918
2919 /* Register with the usb */
2920 retval = usb_register(&io_driver);
2921
2922 if (retval)
2923 goto failed_usb_register;
2924
2925 if (retval == 0) {
2926 dbg("%s\n", "Leaving...");
2927 return 0;
2928 }
2929
2930 failed_usb_register:
2931 usb_serial_deregister(&moschip7840_4port_device);
2932
2933 failed_port_device_register:
2934
2935 return retval;
2936}
2937
2938/****************************************************************************
2939 * moschip7840_exit
2940 * Called when the driver is about to be unloaded.
2941 ****************************************************************************/
2942static void __exit moschip7840_exit(void)
2943{
2944
2945 dbg("%s \n", " mos7840_exit :entering..........");
2946
2947 usb_deregister(&io_driver);
2948
2949 usb_serial_deregister(&moschip7840_4port_device);
2950
2951 dbg("%s\n", "Entring...");
2952}
2953
2954module_init(moschip7840_init);
2955module_exit(moschip7840_exit);
2956
2957/* Module information */
2958MODULE_DESCRIPTION(DRIVER_DESC);
2959MODULE_LICENSE("GPL");
2960
2961module_param(debug, bool, S_IRUGO | S_IWUSR);
2962MODULE_PARM_DESC(debug, "Debug enabled or not");
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index e49f40913c27..a764ff4e326c 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -256,14 +256,14 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
256 return (0); 256 return (0);
257 } 257 }
258 258
259 spin_lock(&wport->lock); 259 spin_lock_bh(&wport->lock);
260 if (wport->write_urb_busy) { 260 if (wport->write_urb_busy) {
261 spin_unlock(&wport->lock); 261 spin_unlock_bh(&wport->lock);
262 dbg("%s - already writing", __FUNCTION__); 262 dbg("%s - already writing", __FUNCTION__);
263 return 0; 263 return 0;
264 } 264 }
265 wport->write_urb_busy = 1; 265 wport->write_urb_busy = 1;
266 spin_unlock(&wport->lock); 266 spin_unlock_bh(&wport->lock);
267 267
268 count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count; 268 count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count;
269 269
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 65e4d046951a..9c18173e33fb 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -81,10 +81,12 @@ static struct usb_device_id id_table [] = {
81 { USB_DEVICE(SPEEDDRAGON_VENDOR_ID, SPEEDDRAGON_PRODUCT_ID) }, 81 { USB_DEVICE(SPEEDDRAGON_VENDOR_ID, SPEEDDRAGON_PRODUCT_ID) },
82 { USB_DEVICE(DATAPILOT_U2_VENDOR_ID, DATAPILOT_U2_PRODUCT_ID) }, 82 { USB_DEVICE(DATAPILOT_U2_VENDOR_ID, DATAPILOT_U2_PRODUCT_ID) },
83 { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) }, 83 { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) },
84 { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) },
85 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ID) },
84 { } /* Terminating entry */ 86 { } /* Terminating entry */
85}; 87};
86 88
87MODULE_DEVICE_TABLE (usb, id_table); 89MODULE_DEVICE_TABLE(usb, id_table);
88 90
89static struct usb_driver pl2303_driver = { 91static struct usb_driver pl2303_driver = {
90 .name = "pl2303", 92 .name = "pl2303",
@@ -127,65 +129,6 @@ static struct usb_driver pl2303_driver = {
127#define UART_OVERRUN_ERROR 0x40 129#define UART_OVERRUN_ERROR 0x40
128#define UART_CTS 0x80 130#define UART_CTS 0x80
129 131
130/* function prototypes for a PL2303 serial converter */
131static int pl2303_open (struct usb_serial_port *port, struct file *filp);
132static void pl2303_close (struct usb_serial_port *port, struct file *filp);
133static void pl2303_set_termios (struct usb_serial_port *port,
134 struct termios *old);
135static int pl2303_ioctl (struct usb_serial_port *port, struct file *file,
136 unsigned int cmd, unsigned long arg);
137static void pl2303_read_int_callback (struct urb *urb, struct pt_regs *regs);
138static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs);
139static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs);
140static int pl2303_write (struct usb_serial_port *port,
141 const unsigned char *buf, int count);
142static void pl2303_send (struct usb_serial_port *port);
143static int pl2303_write_room(struct usb_serial_port *port);
144static int pl2303_chars_in_buffer(struct usb_serial_port *port);
145static void pl2303_break_ctl(struct usb_serial_port *port,int break_state);
146static int pl2303_tiocmget (struct usb_serial_port *port, struct file *file);
147static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file,
148 unsigned int set, unsigned int clear);
149static int pl2303_startup (struct usb_serial *serial);
150static void pl2303_shutdown (struct usb_serial *serial);
151static struct pl2303_buf *pl2303_buf_alloc(unsigned int size);
152static void pl2303_buf_free(struct pl2303_buf *pb);
153static void pl2303_buf_clear(struct pl2303_buf *pb);
154static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb);
155static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb);
156static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf,
157 unsigned int count);
158static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf,
159 unsigned int count);
160
161
162/* All of the device info needed for the PL2303 SIO serial converter */
163static struct usb_serial_driver pl2303_device = {
164 .driver = {
165 .owner = THIS_MODULE,
166 .name = "pl2303",
167 },
168 .id_table = id_table,
169 .num_interrupt_in = NUM_DONT_CARE,
170 .num_bulk_in = 1,
171 .num_bulk_out = 1,
172 .num_ports = 1,
173 .open = pl2303_open,
174 .close = pl2303_close,
175 .write = pl2303_write,
176 .ioctl = pl2303_ioctl,
177 .break_ctl = pl2303_break_ctl,
178 .set_termios = pl2303_set_termios,
179 .tiocmget = pl2303_tiocmget,
180 .tiocmset = pl2303_tiocmset,
181 .read_bulk_callback = pl2303_read_bulk_callback,
182 .read_int_callback = pl2303_read_int_callback,
183 .write_bulk_callback = pl2303_write_bulk_callback,
184 .write_room = pl2303_write_room,
185 .chars_in_buffer = pl2303_chars_in_buffer,
186 .attach = pl2303_startup,
187 .shutdown = pl2303_shutdown,
188};
189 132
190enum pl2303_type { 133enum pl2303_type {
191 type_0, /* don't know the difference between type 0 and */ 134 type_0, /* don't know the difference between type 0 and */
@@ -204,8 +147,166 @@ struct pl2303_private {
204 enum pl2303_type type; 147 enum pl2303_type type;
205}; 148};
206 149
150/*
151 * pl2303_buf_alloc
152 *
153 * Allocate a circular buffer and all associated memory.
154 */
155static struct pl2303_buf *pl2303_buf_alloc(unsigned int size)
156{
157 struct pl2303_buf *pb;
158
159 if (size == 0)
160 return NULL;
161
162 pb = (struct pl2303_buf *)kmalloc(sizeof(struct pl2303_buf), GFP_KERNEL);
163 if (pb == NULL)
164 return NULL;
165
166 pb->buf_buf = kmalloc(size, GFP_KERNEL);
167 if (pb->buf_buf == NULL) {
168 kfree(pb);
169 return NULL;
170 }
171
172 pb->buf_size = size;
173 pb->buf_get = pb->buf_put = pb->buf_buf;
207 174
208static int pl2303_startup (struct usb_serial *serial) 175 return pb;
176}
177
178/*
179 * pl2303_buf_free
180 *
181 * Free the buffer and all associated memory.
182 */
183static void pl2303_buf_free(struct pl2303_buf *pb)
184{
185 if (pb) {
186 kfree(pb->buf_buf);
187 kfree(pb);
188 }
189}
190
191/*
192 * pl2303_buf_clear
193 *
194 * Clear out all data in the circular buffer.
195 */
196static void pl2303_buf_clear(struct pl2303_buf *pb)
197{
198 if (pb != NULL)
199 pb->buf_get = pb->buf_put;
200 /* equivalent to a get of all data available */
201}
202
203/*
204 * pl2303_buf_data_avail
205 *
206 * Return the number of bytes of data available in the circular
207 * buffer.
208 */
209static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb)
210{
211 if (pb == NULL)
212 return 0;
213
214 return ((pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size);
215}
216
217/*
218 * pl2303_buf_space_avail
219 *
220 * Return the number of bytes of space available in the circular
221 * buffer.
222 */
223static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb)
224{
225 if (pb == NULL)
226 return 0;
227
228 return ((pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size);
229}
230
231/*
232 * pl2303_buf_put
233 *
234 * Copy data data from a user buffer and put it into the circular buffer.
235 * Restrict to the amount of space available.
236 *
237 * Return the number of bytes copied.
238 */
239static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf,
240 unsigned int count)
241{
242 unsigned int len;
243
244 if (pb == NULL)
245 return 0;
246
247 len = pl2303_buf_space_avail(pb);
248 if (count > len)
249 count = len;
250
251 if (count == 0)
252 return 0;
253
254 len = pb->buf_buf + pb->buf_size - pb->buf_put;
255 if (count > len) {
256 memcpy(pb->buf_put, buf, len);
257 memcpy(pb->buf_buf, buf+len, count - len);
258 pb->buf_put = pb->buf_buf + count - len;
259 } else {
260 memcpy(pb->buf_put, buf, count);
261 if (count < len)
262 pb->buf_put += count;
263 else /* count == len */
264 pb->buf_put = pb->buf_buf;
265 }
266
267 return count;
268}
269
270/*
271 * pl2303_buf_get
272 *
273 * Get data from the circular buffer and copy to the given buffer.
274 * Restrict to the amount of data available.
275 *
276 * Return the number of bytes copied.
277 */
278static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf,
279 unsigned int count)
280{
281 unsigned int len;
282
283 if (pb == NULL)
284 return 0;
285
286 len = pl2303_buf_data_avail(pb);
287 if (count > len)
288 count = len;
289
290 if (count == 0)
291 return 0;
292
293 len = pb->buf_buf + pb->buf_size - pb->buf_get;
294 if (count > len) {
295 memcpy(buf, pb->buf_get, len);
296 memcpy(buf+len, pb->buf_buf, count - len);
297 pb->buf_get = pb->buf_buf + count - len;
298 } else {
299 memcpy(buf, pb->buf_get, count);
300 if (count < len)
301 pb->buf_get += count;
302 else /* count == len */
303 pb->buf_get = pb->buf_buf;
304 }
305
306 return count;
307}
308
309static int pl2303_startup(struct usb_serial *serial)
209{ 310{
210 struct pl2303_private *priv; 311 struct pl2303_private *priv;
211 enum pl2303_type type = type_0; 312 enum pl2303_type type = type_0;
@@ -247,36 +348,17 @@ cleanup:
247 return -ENOMEM; 348 return -ENOMEM;
248} 349}
249 350
250static int set_control_lines (struct usb_device *dev, u8 value) 351static int set_control_lines(struct usb_device *dev, u8 value)
251{ 352{
252 int retval; 353 int retval;
253 354
254 retval = usb_control_msg (dev, usb_sndctrlpipe (dev, 0), 355 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
255 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE, 356 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE,
256 value, 0, NULL, 0, 100); 357 value, 0, NULL, 0, 100);
257 dbg("%s - value = %d, retval = %d", __FUNCTION__, value, retval); 358 dbg("%s - value = %d, retval = %d", __FUNCTION__, value, retval);
258 return retval; 359 return retval;
259} 360}
260 361
261static int pl2303_write (struct usb_serial_port *port, const unsigned char *buf, int count)
262{
263 struct pl2303_private *priv = usb_get_serial_port_data(port);
264 unsigned long flags;
265
266 dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count);
267
268 if (!count)
269 return count;
270
271 spin_lock_irqsave(&priv->lock, flags);
272 count = pl2303_buf_put(priv->buf, buf, count);
273 spin_unlock_irqrestore(&priv->lock, flags);
274
275 pl2303_send(port);
276
277 return count;
278}
279
280static void pl2303_send(struct usb_serial_port *port) 362static void pl2303_send(struct usb_serial_port *port)
281{ 363{
282 int count, result; 364 int count, result;
@@ -293,7 +375,7 @@ static void pl2303_send(struct usb_serial_port *port)
293 } 375 }
294 376
295 count = pl2303_buf_get(priv->buf, port->write_urb->transfer_buffer, 377 count = pl2303_buf_get(priv->buf, port->write_urb->transfer_buffer,
296 port->bulk_out_size); 378 port->bulk_out_size);
297 379
298 if (count == 0) { 380 if (count == 0) {
299 spin_unlock_irqrestore(&priv->lock, flags); 381 spin_unlock_irqrestore(&priv->lock, flags);
@@ -304,13 +386,15 @@ static void pl2303_send(struct usb_serial_port *port)
304 386
305 spin_unlock_irqrestore(&priv->lock, flags); 387 spin_unlock_irqrestore(&priv->lock, flags);
306 388
307 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, port->write_urb->transfer_buffer); 389 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count,
390 port->write_urb->transfer_buffer);
308 391
309 port->write_urb->transfer_buffer_length = count; 392 port->write_urb->transfer_buffer_length = count;
310 port->write_urb->dev = port->serial->dev; 393 port->write_urb->dev = port->serial->dev;
311 result = usb_submit_urb (port->write_urb, GFP_ATOMIC); 394 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
312 if (result) { 395 if (result) {
313 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result); 396 dev_err(&port->dev, "%s - failed submitting write urb,"
397 " error %d\n", __FUNCTION__, result);
314 priv->write_urb_in_use = 0; 398 priv->write_urb_in_use = 0;
315 // TODO: reschedule pl2303_send 399 // TODO: reschedule pl2303_send
316 } 400 }
@@ -318,6 +402,26 @@ static void pl2303_send(struct usb_serial_port *port)
318 usb_serial_port_softint(port); 402 usb_serial_port_softint(port);
319} 403}
320 404
405static int pl2303_write(struct usb_serial_port *port, const unsigned char *buf,
406 int count)
407{
408 struct pl2303_private *priv = usb_get_serial_port_data(port);
409 unsigned long flags;
410
411 dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count);
412
413 if (!count)
414 return count;
415
416 spin_lock_irqsave(&priv->lock, flags);
417 count = pl2303_buf_put(priv->buf, buf, count);
418 spin_unlock_irqrestore(&priv->lock, flags);
419
420 pl2303_send(port);
421
422 return count;
423}
424
321static int pl2303_write_room(struct usb_serial_port *port) 425static int pl2303_write_room(struct usb_serial_port *port)
322{ 426{
323 struct pl2303_private *priv = usb_get_serial_port_data(port); 427 struct pl2303_private *priv = usb_get_serial_port_data(port);
@@ -350,7 +454,8 @@ static int pl2303_chars_in_buffer(struct usb_serial_port *port)
350 return chars; 454 return chars;
351} 455}
352 456
353static void pl2303_set_termios (struct usb_serial_port *port, struct termios *old_termios) 457static void pl2303_set_termios(struct usb_serial_port *port,
458 struct termios *old_termios)
354{ 459{
355 struct usb_serial *serial = port->serial; 460 struct usb_serial *serial = port->serial;
356 struct pl2303_private *priv = usb_get_serial_port_data(port); 461 struct pl2303_private *priv = usb_get_serial_port_data(port);
@@ -371,7 +476,8 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol
371 spin_lock_irqsave(&priv->lock, flags); 476 spin_lock_irqsave(&priv->lock, flags);
372 if (!priv->termios_initialized) { 477 if (!priv->termios_initialized) {
373 *(port->tty->termios) = tty_std_termios; 478 *(port->tty->termios) = tty_std_termios;
374 port->tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; 479 port->tty->termios->c_cflag = B9600 | CS8 | CREAD |
480 HUPCL | CLOCAL;
375 priv->termios_initialized = 1; 481 priv->termios_initialized = 1;
376 } 482 }
377 spin_unlock_irqrestore(&priv->lock, flags); 483 spin_unlock_irqrestore(&priv->lock, flags);
@@ -380,24 +486,24 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol
380 /* check that they really want us to change something */ 486 /* check that they really want us to change something */
381 if (old_termios) { 487 if (old_termios) {
382 if ((cflag == old_termios->c_cflag) && 488 if ((cflag == old_termios->c_cflag) &&
383 (RELEVANT_IFLAG(port->tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) { 489 (RELEVANT_IFLAG(port->tty->termios->c_iflag) ==
384 dbg("%s - nothing to change...", __FUNCTION__); 490 RELEVANT_IFLAG(old_termios->c_iflag))) {
385 return; 491 dbg("%s - nothing to change...", __FUNCTION__);
492 return;
386 } 493 }
387 } 494 }
388 495
389 buf = kzalloc (7, GFP_KERNEL); 496 buf = kzalloc(7, GFP_KERNEL);
390 if (!buf) { 497 if (!buf) {
391 dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__); 498 dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__);
392 return; 499 return;
393 } 500 }
394
395 i = usb_control_msg (serial->dev, usb_rcvctrlpipe (serial->dev, 0),
396 GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE,
397 0, 0, buf, 7, 100);
398 dbg ("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i,
399 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
400 501
502 i = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
503 GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE,
504 0, 0, buf, 7, 100);
505 dbg("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i,
506 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
401 507
402 if (cflag & CSIZE) { 508 if (cflag & CSIZE) {
403 switch (cflag & CSIZE) { 509 switch (cflag & CSIZE) {
@@ -429,7 +535,8 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol
429 case B230400: baud = 230400; break; 535 case B230400: baud = 230400; break;
430 case B460800: baud = 460800; break; 536 case B460800: baud = 460800; break;
431 default: 537 default:
432 dev_err(&port->dev, "pl2303 driver does not support the baudrate requested (fix it)\n"); 538 dev_err(&port->dev, "pl2303 driver does not support"
539 " the baudrate requested (fix it)\n");
433 break; 540 break;
434 } 541 }
435 dbg("%s - baud = %d", __FUNCTION__, baud); 542 dbg("%s - baud = %d", __FUNCTION__, baud);
@@ -469,10 +576,10 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol
469 dbg("%s - parity = none", __FUNCTION__); 576 dbg("%s - parity = none", __FUNCTION__);
470 } 577 }
471 578
472 i = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0), 579 i = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
473 SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE, 580 SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE,
474 0, 0, buf, 7, 100); 581 0, 0, buf, 7, 100);
475 dbg ("0x21:0x20:0:0 %d", i); 582 dbg("0x21:0x20:0:0 %d", i);
476 583
477 /* change control lines if we are switching to or from B0 */ 584 /* change control lines if we are switching to or from B0 */
478 spin_lock_irqsave(&priv->lock, flags); 585 spin_lock_irqsave(&priv->lock, flags);
@@ -488,13 +595,13 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol
488 } else { 595 } else {
489 spin_unlock_irqrestore(&priv->lock, flags); 596 spin_unlock_irqrestore(&priv->lock, flags);
490 } 597 }
491 598
492 buf[0] = buf[1] = buf[2] = buf[3] = buf[4] = buf[5] = buf[6] = 0; 599 buf[0] = buf[1] = buf[2] = buf[3] = buf[4] = buf[5] = buf[6] = 0;
493 600
494 i = usb_control_msg (serial->dev, usb_rcvctrlpipe (serial->dev, 0), 601 i = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
495 GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, 602 GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE,
496 0, 0, buf, 7, 100); 603 0, 0, buf, 7, 100);
497 dbg ("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i, 604 dbg("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i,
498 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); 605 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
499 606
500 if (cflag & CRTSCTS) { 607 if (cflag & CRTSCTS) {
@@ -503,18 +610,82 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol
503 index = 0x61; 610 index = 0x61;
504 else 611 else
505 index = 0x41; 612 index = 0x41;
506 i = usb_control_msg(serial->dev, 613 i = usb_control_msg(serial->dev,
507 usb_sndctrlpipe(serial->dev, 0), 614 usb_sndctrlpipe(serial->dev, 0),
508 VENDOR_WRITE_REQUEST, 615 VENDOR_WRITE_REQUEST,
509 VENDOR_WRITE_REQUEST_TYPE, 616 VENDOR_WRITE_REQUEST_TYPE,
510 0x0, index, NULL, 0, 100); 617 0x0, index, NULL, 0, 100);
511 dbg ("0x40:0x1:0x0:0x%x %d", index, i); 618 dbg("0x40:0x1:0x0:0x%x %d", index, i);
619 }
620
621 kfree(buf);
622}
623
624static void pl2303_close(struct usb_serial_port *port, struct file *filp)
625{
626 struct pl2303_private *priv = usb_get_serial_port_data(port);
627 unsigned long flags;
628 unsigned int c_cflag;
629 int bps;
630 long timeout;
631 wait_queue_t wait;
632
633 dbg("%s - port %d", __FUNCTION__, port->number);
634
635 /* wait for data to drain from the buffer */
636 spin_lock_irqsave(&priv->lock, flags);
637 timeout = PL2303_CLOSING_WAIT;
638 init_waitqueue_entry(&wait, current);
639 add_wait_queue(&port->tty->write_wait, &wait);
640 for (;;) {
641 set_current_state(TASK_INTERRUPTIBLE);
642 if (pl2303_buf_data_avail(priv->buf) == 0 ||
643 timeout == 0 || signal_pending(current) ||
644 !usb_get_intfdata(port->serial->interface)) /* disconnect */
645 break;
646 spin_unlock_irqrestore(&priv->lock, flags);
647 timeout = schedule_timeout(timeout);
648 spin_lock_irqsave(&priv->lock, flags);
512 } 649 }
650 set_current_state(TASK_RUNNING);
651 remove_wait_queue(&port->tty->write_wait, &wait);
652 /* clear out any remaining data in the buffer */
653 pl2303_buf_clear(priv->buf);
654 spin_unlock_irqrestore(&priv->lock, flags);
655
656 /* wait for characters to drain from the device */
657 /* (this is long enough for the entire 256 byte */
658 /* pl2303 hardware buffer to drain with no flow */
659 /* control for data rates of 1200 bps or more, */
660 /* for lower rates we should really know how much */
661 /* data is in the buffer to compute a delay */
662 /* that is not unnecessarily long) */
663 bps = tty_get_baud_rate(port->tty);
664 if (bps > 1200)
665 timeout = max((HZ*2560)/bps,HZ/10);
666 else
667 timeout = 2*HZ;
668 schedule_timeout_interruptible(timeout);
513 669
514 kfree (buf); 670 /* shutdown our urbs */
671 dbg("%s - shutting down urbs", __FUNCTION__);
672 usb_kill_urb(port->write_urb);
673 usb_kill_urb(port->read_urb);
674 usb_kill_urb(port->interrupt_in_urb);
675
676 if (port->tty) {
677 c_cflag = port->tty->termios->c_cflag;
678 if (c_cflag & HUPCL) {
679 /* drop DTR and RTS */
680 spin_lock_irqsave(&priv->lock, flags);
681 priv->line_control = 0;
682 spin_unlock_irqrestore(&priv->lock, flags);
683 set_control_lines(port->serial->dev, 0);
684 }
685 }
515} 686}
516 687
517static int pl2303_open (struct usb_serial_port *port, struct file *filp) 688static int pl2303_open(struct usb_serial_port *port, struct file *filp)
518{ 689{
519 struct termios tmp_termios; 690 struct termios tmp_termios;
520 struct usb_serial *serial = port->serial; 691 struct usb_serial *serial = port->serial;
@@ -568,98 +739,35 @@ static int pl2303_open (struct usb_serial_port *port, struct file *filp)
568 739
569 /* Setup termios */ 740 /* Setup termios */
570 if (port->tty) { 741 if (port->tty) {
571 pl2303_set_termios (port, &tmp_termios); 742 pl2303_set_termios(port, &tmp_termios);
572 } 743 }
573 744
574 //FIXME: need to assert RTS and DTR if CRTSCTS off 745 //FIXME: need to assert RTS and DTR if CRTSCTS off
575 746
576 dbg("%s - submitting read urb", __FUNCTION__); 747 dbg("%s - submitting read urb", __FUNCTION__);
577 port->read_urb->dev = serial->dev; 748 port->read_urb->dev = serial->dev;
578 result = usb_submit_urb (port->read_urb, GFP_KERNEL); 749 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
579 if (result) { 750 if (result) {
580 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result); 751 dev_err(&port->dev, "%s - failed submitting read urb,"
581 pl2303_close (port, NULL); 752 " error %d\n", __FUNCTION__, result);
753 pl2303_close(port, NULL);
582 return -EPROTO; 754 return -EPROTO;
583 } 755 }
584 756
585 dbg("%s - submitting interrupt urb", __FUNCTION__); 757 dbg("%s - submitting interrupt urb", __FUNCTION__);
586 port->interrupt_in_urb->dev = serial->dev; 758 port->interrupt_in_urb->dev = serial->dev;
587 result = usb_submit_urb (port->interrupt_in_urb, GFP_KERNEL); 759 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
588 if (result) { 760 if (result) {
589 dev_err(&port->dev, "%s - failed submitting interrupt urb, error %d\n", __FUNCTION__, result); 761 dev_err(&port->dev, "%s - failed submitting interrupt urb,"
590 pl2303_close (port, NULL); 762 " error %d\n", __FUNCTION__, result);
763 pl2303_close(port, NULL);
591 return -EPROTO; 764 return -EPROTO;
592 } 765 }
593 return 0; 766 return 0;
594} 767}
595 768
596 769static int pl2303_tiocmset(struct usb_serial_port *port, struct file *file,
597static void pl2303_close (struct usb_serial_port *port, struct file *filp) 770 unsigned int set, unsigned int clear)
598{
599 struct pl2303_private *priv = usb_get_serial_port_data(port);
600 unsigned long flags;
601 unsigned int c_cflag;
602 int bps;
603 long timeout;
604 wait_queue_t wait;
605
606 dbg("%s - port %d", __FUNCTION__, port->number);
607
608 /* wait for data to drain from the buffer */
609 spin_lock_irqsave(&priv->lock, flags);
610 timeout = PL2303_CLOSING_WAIT;
611 init_waitqueue_entry(&wait, current);
612 add_wait_queue(&port->tty->write_wait, &wait);
613 for (;;) {
614 set_current_state(TASK_INTERRUPTIBLE);
615 if (pl2303_buf_data_avail(priv->buf) == 0
616 || timeout == 0 || signal_pending(current)
617 || !usb_get_intfdata(port->serial->interface)) /* disconnect */
618 break;
619 spin_unlock_irqrestore(&priv->lock, flags);
620 timeout = schedule_timeout(timeout);
621 spin_lock_irqsave(&priv->lock, flags);
622 }
623 set_current_state(TASK_RUNNING);
624 remove_wait_queue(&port->tty->write_wait, &wait);
625 /* clear out any remaining data in the buffer */
626 pl2303_buf_clear(priv->buf);
627 spin_unlock_irqrestore(&priv->lock, flags);
628
629 /* wait for characters to drain from the device */
630 /* (this is long enough for the entire 256 byte */
631 /* pl2303 hardware buffer to drain with no flow */
632 /* control for data rates of 1200 bps or more, */
633 /* for lower rates we should really know how much */
634 /* data is in the buffer to compute a delay */
635 /* that is not unnecessarily long) */
636 bps = tty_get_baud_rate(port->tty);
637 if (bps > 1200)
638 timeout = max((HZ*2560)/bps,HZ/10);
639 else
640 timeout = 2*HZ;
641 schedule_timeout_interruptible(timeout);
642
643 /* shutdown our urbs */
644 dbg("%s - shutting down urbs", __FUNCTION__);
645 usb_kill_urb(port->write_urb);
646 usb_kill_urb(port->read_urb);
647 usb_kill_urb(port->interrupt_in_urb);
648
649 if (port->tty) {
650 c_cflag = port->tty->termios->c_cflag;
651 if (c_cflag & HUPCL) {
652 /* drop DTR and RTS */
653 spin_lock_irqsave(&priv->lock, flags);
654 priv->line_control = 0;
655 spin_unlock_irqrestore (&priv->lock, flags);
656 set_control_lines (port->serial->dev, 0);
657 }
658 }
659}
660
661static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file,
662 unsigned int set, unsigned int clear)
663{ 771{
664 struct pl2303_private *priv = usb_get_serial_port_data(port); 772 struct pl2303_private *priv = usb_get_serial_port_data(port);
665 unsigned long flags; 773 unsigned long flags;
@@ -668,7 +776,7 @@ static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file,
668 if (!usb_get_intfdata(port->serial->interface)) 776 if (!usb_get_intfdata(port->serial->interface))
669 return -ENODEV; 777 return -ENODEV;
670 778
671 spin_lock_irqsave (&priv->lock, flags); 779 spin_lock_irqsave(&priv->lock, flags);
672 if (set & TIOCM_RTS) 780 if (set & TIOCM_RTS)
673 priv->line_control |= CONTROL_RTS; 781 priv->line_control |= CONTROL_RTS;
674 if (set & TIOCM_DTR) 782 if (set & TIOCM_DTR)
@@ -678,12 +786,12 @@ static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file,
678 if (clear & TIOCM_DTR) 786 if (clear & TIOCM_DTR)
679 priv->line_control &= ~CONTROL_DTR; 787 priv->line_control &= ~CONTROL_DTR;
680 control = priv->line_control; 788 control = priv->line_control;
681 spin_unlock_irqrestore (&priv->lock, flags); 789 spin_unlock_irqrestore(&priv->lock, flags);
682 790
683 return set_control_lines (port->serial->dev, control); 791 return set_control_lines(port->serial->dev, control);
684} 792}
685 793
686static int pl2303_tiocmget (struct usb_serial_port *port, struct file *file) 794static int pl2303_tiocmget(struct usb_serial_port *port, struct file *file)
687{ 795{
688 struct pl2303_private *priv = usb_get_serial_port_data(port); 796 struct pl2303_private *priv = usb_get_serial_port_data(port);
689 unsigned long flags; 797 unsigned long flags;
@@ -696,10 +804,10 @@ static int pl2303_tiocmget (struct usb_serial_port *port, struct file *file)
696 if (!usb_get_intfdata(port->serial->interface)) 804 if (!usb_get_intfdata(port->serial->interface))
697 return -ENODEV; 805 return -ENODEV;
698 806
699 spin_lock_irqsave (&priv->lock, flags); 807 spin_lock_irqsave(&priv->lock, flags);
700 mcr = priv->line_control; 808 mcr = priv->line_control;
701 status = priv->line_status; 809 status = priv->line_status;
702 spin_unlock_irqrestore (&priv->lock, flags); 810 spin_unlock_irqrestore(&priv->lock, flags);
703 811
704 result = ((mcr & CONTROL_DTR) ? TIOCM_DTR : 0) 812 result = ((mcr & CONTROL_DTR) ? TIOCM_DTR : 0)
705 | ((mcr & CONTROL_RTS) ? TIOCM_RTS : 0) 813 | ((mcr & CONTROL_RTS) ? TIOCM_RTS : 0)
@@ -721,22 +829,22 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
721 unsigned int status; 829 unsigned int status;
722 unsigned int changed; 830 unsigned int changed;
723 831
724 spin_lock_irqsave (&priv->lock, flags); 832 spin_lock_irqsave(&priv->lock, flags);
725 prevstatus = priv->line_status; 833 prevstatus = priv->line_status;
726 spin_unlock_irqrestore (&priv->lock, flags); 834 spin_unlock_irqrestore(&priv->lock, flags);
727 835
728 while (1) { 836 while (1) {
729 interruptible_sleep_on(&priv->delta_msr_wait); 837 interruptible_sleep_on(&priv->delta_msr_wait);
730 /* see if a signal did it */ 838 /* see if a signal did it */
731 if (signal_pending(current)) 839 if (signal_pending(current))
732 return -ERESTARTSYS; 840 return -ERESTARTSYS;
733 841
734 spin_lock_irqsave (&priv->lock, flags); 842 spin_lock_irqsave(&priv->lock, flags);
735 status = priv->line_status; 843 status = priv->line_status;
736 spin_unlock_irqrestore (&priv->lock, flags); 844 spin_unlock_irqrestore(&priv->lock, flags);
737 845
738 changed=prevstatus^status; 846 changed=prevstatus^status;
739 847
740 if (((arg & TIOCM_RNG) && (changed & UART_RING)) || 848 if (((arg & TIOCM_RNG) && (changed & UART_RING)) ||
741 ((arg & TIOCM_DSR) && (changed & UART_DSR)) || 849 ((arg & TIOCM_DSR) && (changed & UART_DSR)) ||
742 ((arg & TIOCM_CD) && (changed & UART_DCD)) || 850 ((arg & TIOCM_CD) && (changed & UART_DCD)) ||
@@ -749,7 +857,8 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
749 return 0; 857 return 0;
750} 858}
751 859
752static int pl2303_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg) 860static int pl2303_ioctl(struct usb_serial_port *port, struct file *file,
861 unsigned int cmd, unsigned long arg)
753{ 862{
754 dbg("%s (%d) cmd = 0x%04x", __FUNCTION__, port->number, cmd); 863 dbg("%s (%d) cmd = 0x%04x", __FUNCTION__, port->number, cmd);
755 864
@@ -766,7 +875,7 @@ static int pl2303_ioctl (struct usb_serial_port *port, struct file *file, unsign
766 return -ENOIOCTLCMD; 875 return -ENOIOCTLCMD;
767} 876}
768 877
769static void pl2303_break_ctl (struct usb_serial_port *port, int break_state) 878static void pl2303_break_ctl(struct usb_serial_port *port, int break_state)
770{ 879{
771 struct usb_serial *serial = port->serial; 880 struct usb_serial *serial = port->serial;
772 u16 state; 881 u16 state;
@@ -780,15 +889,14 @@ static void pl2303_break_ctl (struct usb_serial_port *port, int break_state)
780 state = BREAK_ON; 889 state = BREAK_ON;
781 dbg("%s - turning break %s", __FUNCTION__, state==BREAK_OFF ? "off" : "on"); 890 dbg("%s - turning break %s", __FUNCTION__, state==BREAK_OFF ? "off" : "on");
782 891
783 result = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0), 892 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
784 BREAK_REQUEST, BREAK_REQUEST_TYPE, state, 893 BREAK_REQUEST, BREAK_REQUEST_TYPE, state,
785 0, NULL, 0, 100); 894 0, NULL, 0, 100);
786 if (result) 895 if (result)
787 dbg("%s - error sending break = %d", __FUNCTION__, result); 896 dbg("%s - error sending break = %d", __FUNCTION__, result);
788} 897}
789 898
790 899static void pl2303_shutdown(struct usb_serial *serial)
791static void pl2303_shutdown (struct usb_serial *serial)
792{ 900{
793 int i; 901 int i;
794 struct pl2303_private *priv; 902 struct pl2303_private *priv;
@@ -802,7 +910,7 @@ static void pl2303_shutdown (struct usb_serial *serial)
802 kfree(priv); 910 kfree(priv);
803 usb_set_serial_port_data(serial->port[i], NULL); 911 usb_set_serial_port_data(serial->port[i], NULL);
804 } 912 }
805 } 913 }
806} 914}
807 915
808static void pl2303_update_line_status(struct usb_serial_port *port, 916static void pl2303_update_line_status(struct usb_serial_port *port,
@@ -814,29 +922,33 @@ static void pl2303_update_line_status(struct usb_serial_port *port,
814 unsigned long flags; 922 unsigned long flags;
815 u8 status_idx = UART_STATE; 923 u8 status_idx = UART_STATE;
816 u8 length = UART_STATE + 1; 924 u8 length = UART_STATE + 1;
925 u16 idv, idp;
926
927 idv = le16_to_cpu(port->serial->dev->descriptor.idVendor);
928 idp = le16_to_cpu(port->serial->dev->descriptor.idProduct);
817 929
818 if ((le16_to_cpu(port->serial->dev->descriptor.idVendor) == SIEMENS_VENDOR_ID) && 930
819 (le16_to_cpu(port->serial->dev->descriptor.idProduct) == SIEMENS_PRODUCT_ID_X65 || 931 if (idv == SIEMENS_VENDOR_ID) {
820 le16_to_cpu(port->serial->dev->descriptor.idProduct) == SIEMENS_PRODUCT_ID_SX1 || 932 if (idp == SIEMENS_PRODUCT_ID_X65 ||
821 le16_to_cpu(port->serial->dev->descriptor.idProduct) == SIEMENS_PRODUCT_ID_X75)) { 933 idp == SIEMENS_PRODUCT_ID_SX1 ||
822 length = 1; 934 idp == SIEMENS_PRODUCT_ID_X75) {
823 status_idx = 0; 935
936 length = 1;
937 status_idx = 0;
938 }
824 } 939 }
825 940
826 if (actual_length < length) 941 if (actual_length < length)
827 goto exit; 942 return;
828 943
829 /* Save off the uart status for others to look at */ 944 /* Save off the uart status for others to look at */
830 spin_lock_irqsave(&priv->lock, flags); 945 spin_lock_irqsave(&priv->lock, flags);
831 priv->line_status = data[status_idx]; 946 priv->line_status = data[status_idx];
832 spin_unlock_irqrestore(&priv->lock, flags); 947 spin_unlock_irqrestore(&priv->lock, flags);
833 wake_up_interruptible (&priv->delta_msr_wait); 948 wake_up_interruptible(&priv->delta_msr_wait);
834
835exit:
836 return;
837} 949}
838 950
839static void pl2303_read_int_callback (struct urb *urb, struct pt_regs *regs) 951static void pl2303_read_int_callback(struct urb *urb, struct pt_regs *regs)
840{ 952{
841 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 953 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
842 unsigned char *data = urb->transfer_buffer; 954 unsigned char *data = urb->transfer_buffer;
@@ -853,25 +965,29 @@ static void pl2303_read_int_callback (struct urb *urb, struct pt_regs *regs)
853 case -ENOENT: 965 case -ENOENT:
854 case -ESHUTDOWN: 966 case -ESHUTDOWN:
855 /* this urb is terminated, clean up */ 967 /* this urb is terminated, clean up */
856 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); 968 dbg("%s - urb shutting down with status: %d", __FUNCTION__,
969 urb->status);
857 return; 970 return;
858 default: 971 default:
859 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); 972 dbg("%s - nonzero urb status received: %d", __FUNCTION__,
973 urb->status);
860 goto exit; 974 goto exit;
861 } 975 }
862 976
863 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, urb->transfer_buffer); 977 usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
978 urb->actual_length, urb->transfer_buffer);
979
864 pl2303_update_line_status(port, data, actual_length); 980 pl2303_update_line_status(port, data, actual_length);
865 981
866exit: 982exit:
867 status = usb_submit_urb (urb, GFP_ATOMIC); 983 status = usb_submit_urb(urb, GFP_ATOMIC);
868 if (status) 984 if (status)
869 dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n", 985 dev_err(&urb->dev->dev,
986 "%s - usb_submit_urb failed with result %d\n",
870 __FUNCTION__, status); 987 __FUNCTION__, status);
871} 988}
872 989
873 990static void pl2303_read_bulk_callback(struct urb *urb, struct pt_regs *regs)
874static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
875{ 991{
876 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 992 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
877 struct pl2303_private *priv = usb_get_serial_port_data(port); 993 struct pl2303_private *priv = usb_get_serial_port_data(port);
@@ -892,20 +1008,25 @@ static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
892 return; 1008 return;
893 } 1009 }
894 if (urb->status == -EPROTO) { 1010 if (urb->status == -EPROTO) {
895 /* PL2303 mysteriously fails with -EPROTO reschedule the read */ 1011 /* PL2303 mysteriously fails with -EPROTO reschedule
896 dbg("%s - caught -EPROTO, resubmitting the urb", __FUNCTION__); 1012 * the read */
1013 dbg("%s - caught -EPROTO, resubmitting the urb",
1014 __FUNCTION__);
897 urb->status = 0; 1015 urb->status = 0;
898 urb->dev = port->serial->dev; 1016 urb->dev = port->serial->dev;
899 result = usb_submit_urb(urb, GFP_ATOMIC); 1017 result = usb_submit_urb(urb, GFP_ATOMIC);
900 if (result) 1018 if (result)
901 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); 1019 dev_err(&urb->dev->dev, "%s - failed"
1020 " resubmitting read urb, error %d\n",
1021 __FUNCTION__, result);
902 return; 1022 return;
903 } 1023 }
904 dbg("%s - unable to handle the error, exiting.", __FUNCTION__); 1024 dbg("%s - unable to handle the error, exiting.", __FUNCTION__);
905 return; 1025 return;
906 } 1026 }
907 1027
908 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 1028 usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
1029 urb->actual_length, data);
909 1030
910 /* get tty_flag from status */ 1031 /* get tty_flag from status */
911 tty_flag = TTY_NORMAL; 1032 tty_flag = TTY_NORMAL;
@@ -914,7 +1035,7 @@ static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
914 status = priv->line_status; 1035 status = priv->line_status;
915 priv->line_status &= ~UART_STATE_TRANSIENT_MASK; 1036 priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
916 spin_unlock_irqrestore(&priv->lock, flags); 1037 spin_unlock_irqrestore(&priv->lock, flags);
917 wake_up_interruptible (&priv->delta_msr_wait); 1038 wake_up_interruptible(&priv->delta_msr_wait);
918 1039
919 /* break takes precedence over parity, */ 1040 /* break takes precedence over parity, */
920 /* which takes precedence over framing errors */ 1041 /* which takes precedence over framing errors */
@@ -933,8 +1054,8 @@ static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
933 if (status & UART_OVERRUN_ERROR) 1054 if (status & UART_OVERRUN_ERROR)
934 tty_insert_flip_char(tty, 0, TTY_OVERRUN); 1055 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
935 for (i = 0; i < urb->actual_length; ++i) 1056 for (i = 0; i < urb->actual_length; ++i)
936 tty_insert_flip_char (tty, data[i], tty_flag); 1057 tty_insert_flip_char(tty, data[i], tty_flag);
937 tty_flip_buffer_push (tty); 1058 tty_flip_buffer_push(tty);
938 } 1059 }
939 1060
940 /* Schedule the next read _if_ we are still open */ 1061 /* Schedule the next read _if_ we are still open */
@@ -942,15 +1063,14 @@ static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
942 urb->dev = port->serial->dev; 1063 urb->dev = port->serial->dev;
943 result = usb_submit_urb(urb, GFP_ATOMIC); 1064 result = usb_submit_urb(urb, GFP_ATOMIC);
944 if (result) 1065 if (result)
945 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); 1066 dev_err(&urb->dev->dev, "%s - failed resubmitting"
1067 " read urb, error %d\n", __FUNCTION__, result);
946 } 1068 }
947 1069
948 return; 1070 return;
949} 1071}
950 1072
951 1073static void pl2303_write_bulk_callback(struct urb *urb, struct pt_regs *regs)
952
953static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
954{ 1074{
955 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 1075 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
956 struct pl2303_private *priv = usb_get_serial_port_data(port); 1076 struct pl2303_private *priv = usb_get_serial_port_data(port);
@@ -966,18 +1086,21 @@ static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
966 case -ENOENT: 1086 case -ENOENT:
967 case -ESHUTDOWN: 1087 case -ESHUTDOWN:
968 /* this urb is terminated, clean up */ 1088 /* this urb is terminated, clean up */
969 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); 1089 dbg("%s - urb shutting down with status: %d", __FUNCTION__,
1090 urb->status);
970 priv->write_urb_in_use = 0; 1091 priv->write_urb_in_use = 0;
971 return; 1092 return;
972 default: 1093 default:
973 /* error in the urb, so we have to resubmit it */ 1094 /* error in the urb, so we have to resubmit it */
974 dbg("%s - Overflow in write", __FUNCTION__); 1095 dbg("%s - Overflow in write", __FUNCTION__);
975 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); 1096 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__,
1097 urb->status);
976 port->write_urb->transfer_buffer_length = 1; 1098 port->write_urb->transfer_buffer_length = 1;
977 port->write_urb->dev = port->serial->dev; 1099 port->write_urb->dev = port->serial->dev;
978 result = usb_submit_urb (port->write_urb, GFP_ATOMIC); 1100 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
979 if (result) 1101 if (result)
980 dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n", __FUNCTION__, result); 1102 dev_err(&urb->dev->dev, "%s - failed resubmitting write"
1103 " urb, error %d\n", __FUNCTION__, result);
981 else 1104 else
982 return; 1105 return;
983 } 1106 }
@@ -988,191 +1111,38 @@ static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
988 pl2303_send(port); 1111 pl2303_send(port);
989} 1112}
990 1113
1114/* All of the device info needed for the PL2303 SIO serial converter */
1115static struct usb_serial_driver pl2303_device = {
1116 .driver = {
1117 .owner = THIS_MODULE,
1118 .name = "pl2303",
1119 },
1120 .id_table = id_table,
1121 .num_interrupt_in = NUM_DONT_CARE,
1122 .num_bulk_in = 1,
1123 .num_bulk_out = 1,
1124 .num_ports = 1,
1125 .open = pl2303_open,
1126 .close = pl2303_close,
1127 .write = pl2303_write,
1128 .ioctl = pl2303_ioctl,
1129 .break_ctl = pl2303_break_ctl,
1130 .set_termios = pl2303_set_termios,
1131 .tiocmget = pl2303_tiocmget,
1132 .tiocmset = pl2303_tiocmset,
1133 .read_bulk_callback = pl2303_read_bulk_callback,
1134 .read_int_callback = pl2303_read_int_callback,
1135 .write_bulk_callback = pl2303_write_bulk_callback,
1136 .write_room = pl2303_write_room,
1137 .chars_in_buffer = pl2303_chars_in_buffer,
1138 .attach = pl2303_startup,
1139 .shutdown = pl2303_shutdown,
1140};
991 1141
992/* 1142static int __init pl2303_init(void)
993 * pl2303_buf_alloc
994 *
995 * Allocate a circular buffer and all associated memory.
996 */
997
998static struct pl2303_buf *pl2303_buf_alloc(unsigned int size)
999{
1000
1001 struct pl2303_buf *pb;
1002
1003
1004 if (size == 0)
1005 return NULL;
1006
1007 pb = (struct pl2303_buf *)kmalloc(sizeof(struct pl2303_buf), GFP_KERNEL);
1008 if (pb == NULL)
1009 return NULL;
1010
1011 pb->buf_buf = kmalloc(size, GFP_KERNEL);
1012 if (pb->buf_buf == NULL) {
1013 kfree(pb);
1014 return NULL;
1015 }
1016
1017 pb->buf_size = size;
1018 pb->buf_get = pb->buf_put = pb->buf_buf;
1019
1020 return pb;
1021
1022}
1023
1024
1025/*
1026 * pl2303_buf_free
1027 *
1028 * Free the buffer and all associated memory.
1029 */
1030
1031static void pl2303_buf_free(struct pl2303_buf *pb)
1032{
1033 if (pb) {
1034 kfree(pb->buf_buf);
1035 kfree(pb);
1036 }
1037}
1038
1039
1040/*
1041 * pl2303_buf_clear
1042 *
1043 * Clear out all data in the circular buffer.
1044 */
1045
1046static void pl2303_buf_clear(struct pl2303_buf *pb)
1047{
1048 if (pb != NULL)
1049 pb->buf_get = pb->buf_put;
1050 /* equivalent to a get of all data available */
1051}
1052
1053
1054/*
1055 * pl2303_buf_data_avail
1056 *
1057 * Return the number of bytes of data available in the circular
1058 * buffer.
1059 */
1060
1061static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb)
1062{
1063 if (pb != NULL)
1064 return ((pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size);
1065 else
1066 return 0;
1067}
1068
1069
1070/*
1071 * pl2303_buf_space_avail
1072 *
1073 * Return the number of bytes of space available in the circular
1074 * buffer.
1075 */
1076
1077static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb)
1078{
1079 if (pb != NULL)
1080 return ((pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size);
1081 else
1082 return 0;
1083}
1084
1085
1086/*
1087 * pl2303_buf_put
1088 *
1089 * Copy data data from a user buffer and put it into the circular buffer.
1090 * Restrict to the amount of space available.
1091 *
1092 * Return the number of bytes copied.
1093 */
1094
1095static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf,
1096 unsigned int count)
1097{
1098
1099 unsigned int len;
1100
1101
1102 if (pb == NULL)
1103 return 0;
1104
1105 len = pl2303_buf_space_avail(pb);
1106 if (count > len)
1107 count = len;
1108
1109 if (count == 0)
1110 return 0;
1111
1112 len = pb->buf_buf + pb->buf_size - pb->buf_put;
1113 if (count > len) {
1114 memcpy(pb->buf_put, buf, len);
1115 memcpy(pb->buf_buf, buf+len, count - len);
1116 pb->buf_put = pb->buf_buf + count - len;
1117 } else {
1118 memcpy(pb->buf_put, buf, count);
1119 if (count < len)
1120 pb->buf_put += count;
1121 else /* count == len */
1122 pb->buf_put = pb->buf_buf;
1123 }
1124
1125 return count;
1126
1127}
1128
1129
1130/*
1131 * pl2303_buf_get
1132 *
1133 * Get data from the circular buffer and copy to the given buffer.
1134 * Restrict to the amount of data available.
1135 *
1136 * Return the number of bytes copied.
1137 */
1138
1139static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf,
1140 unsigned int count)
1141{
1142
1143 unsigned int len;
1144
1145
1146 if (pb == NULL)
1147 return 0;
1148
1149 len = pl2303_buf_data_avail(pb);
1150 if (count > len)
1151 count = len;
1152
1153 if (count == 0)
1154 return 0;
1155
1156 len = pb->buf_buf + pb->buf_size - pb->buf_get;
1157 if (count > len) {
1158 memcpy(buf, pb->buf_get, len);
1159 memcpy(buf+len, pb->buf_buf, count - len);
1160 pb->buf_get = pb->buf_buf + count - len;
1161 } else {
1162 memcpy(buf, pb->buf_get, count);
1163 if (count < len)
1164 pb->buf_get += count;
1165 else /* count == len */
1166 pb->buf_get = pb->buf_buf;
1167 }
1168
1169 return count;
1170
1171}
1172
1173static int __init pl2303_init (void)
1174{ 1143{
1175 int retval; 1144 int retval;
1145
1176 retval = usb_serial_register(&pl2303_device); 1146 retval = usb_serial_register(&pl2303_device);
1177 if (retval) 1147 if (retval)
1178 goto failed_usb_serial_register; 1148 goto failed_usb_serial_register;
@@ -1187,14 +1157,12 @@ failed_usb_serial_register:
1187 return retval; 1157 return retval;
1188} 1158}
1189 1159
1190 1160static void __exit pl2303_exit(void)
1191static void __exit pl2303_exit (void)
1192{ 1161{
1193 usb_deregister (&pl2303_driver); 1162 usb_deregister(&pl2303_driver);
1194 usb_serial_deregister (&pl2303_device); 1163 usb_serial_deregister(&pl2303_device);
1195} 1164}
1196 1165
1197
1198module_init(pl2303_init); 1166module_init(pl2303_init);
1199module_exit(pl2303_exit); 1167module_exit(pl2303_exit);
1200 1168
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index 55195e76eb6f..65a5039665e7 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -89,3 +89,11 @@
89/* Belkin "F5U257" Serial Adapter */ 89/* Belkin "F5U257" Serial Adapter */
90#define BELKIN_VENDOR_ID 0x050d 90#define BELKIN_VENDOR_ID 0x050d
91#define BELKIN_PRODUCT_ID 0x0257 91#define BELKIN_PRODUCT_ID 0x0257
92
93/* Alcor Micro Corp. USB 2.0 TO RS-232 */
94#define ALCOR_VENDOR_ID 0x058F
95#define ALCOR_PRODUCT_ID 0x9720
96
97/* Huawei E620 UMTS/HSDPA card (ID: 12d1:1001) */
98#define HUAWEI_VENDOR_ID 0x12d1
99#define HUAWEI_PRODUCT_ID 0x1001
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c
index 789771ecdb11..1e07dfad6853 100644
--- a/drivers/usb/serial/safe_serial.c
+++ b/drivers/usb/serial/safe_serial.c
@@ -298,14 +298,14 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i
298 dbg ("%s - write request of 0 bytes", __FUNCTION__); 298 dbg ("%s - write request of 0 bytes", __FUNCTION__);
299 return (0); 299 return (0);
300 } 300 }
301 spin_lock(&port->lock); 301 spin_lock_bh(&port->lock);
302 if (port->write_urb_busy) { 302 if (port->write_urb_busy) {
303 spin_unlock(&port->lock); 303 spin_unlock_bh(&port->lock);
304 dbg("%s - already writing", __FUNCTION__); 304 dbg("%s - already writing", __FUNCTION__);
305 return 0; 305 return 0;
306 } 306 }
307 port->write_urb_busy = 1; 307 port->write_urb_busy = 1;
308 spin_unlock(&port->lock); 308 spin_unlock_bh(&port->lock);
309 309
310 packet_length = port->bulk_out_size; // get max packetsize 310 packet_length = port->bulk_out_size; // get max packetsize
311 311
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index e06a41bd0f3b..8006e51c34bb 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -676,33 +676,29 @@ int usb_serial_probe(struct usb_interface *interface,
676 iface_desc = interface->cur_altsetting; 676 iface_desc = interface->cur_altsetting;
677 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { 677 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
678 endpoint = &iface_desc->endpoint[i].desc; 678 endpoint = &iface_desc->endpoint[i].desc;
679 679
680 if ((endpoint->bEndpointAddress & 0x80) && 680 if (usb_endpoint_is_bulk_in(endpoint)) {
681 ((endpoint->bmAttributes & 3) == 0x02)) {
682 /* we found a bulk in endpoint */ 681 /* we found a bulk in endpoint */
683 dbg("found bulk in on endpoint %d", i); 682 dbg("found bulk in on endpoint %d", i);
684 bulk_in_endpoint[num_bulk_in] = endpoint; 683 bulk_in_endpoint[num_bulk_in] = endpoint;
685 ++num_bulk_in; 684 ++num_bulk_in;
686 } 685 }
687 686
688 if (((endpoint->bEndpointAddress & 0x80) == 0x00) && 687 if (usb_endpoint_is_bulk_out(endpoint)) {
689 ((endpoint->bmAttributes & 3) == 0x02)) {
690 /* we found a bulk out endpoint */ 688 /* we found a bulk out endpoint */
691 dbg("found bulk out on endpoint %d", i); 689 dbg("found bulk out on endpoint %d", i);
692 bulk_out_endpoint[num_bulk_out] = endpoint; 690 bulk_out_endpoint[num_bulk_out] = endpoint;
693 ++num_bulk_out; 691 ++num_bulk_out;
694 } 692 }
695 693
696 if ((endpoint->bEndpointAddress & 0x80) && 694 if (usb_endpoint_is_int_in(endpoint)) {
697 ((endpoint->bmAttributes & 3) == 0x03)) {
698 /* we found a interrupt in endpoint */ 695 /* we found a interrupt in endpoint */
699 dbg("found interrupt in on endpoint %d", i); 696 dbg("found interrupt in on endpoint %d", i);
700 interrupt_in_endpoint[num_interrupt_in] = endpoint; 697 interrupt_in_endpoint[num_interrupt_in] = endpoint;
701 ++num_interrupt_in; 698 ++num_interrupt_in;
702 } 699 }
703 700
704 if (((endpoint->bEndpointAddress & 0x80) == 0x00) && 701 if (usb_endpoint_is_int_out(endpoint)) {
705 ((endpoint->bmAttributes & 3) == 0x03)) {
706 /* we found an interrupt out endpoint */ 702 /* we found an interrupt out endpoint */
707 dbg("found interrupt out on endpoint %d", i); 703 dbg("found interrupt out on endpoint %d", i);
708 interrupt_out_endpoint[num_interrupt_out] = endpoint; 704 interrupt_out_endpoint[num_interrupt_out] = endpoint;
@@ -716,14 +712,15 @@ int usb_serial_probe(struct usb_interface *interface,
716 if (((le16_to_cpu(dev->descriptor.idVendor) == PL2303_VENDOR_ID) && 712 if (((le16_to_cpu(dev->descriptor.idVendor) == PL2303_VENDOR_ID) &&
717 (le16_to_cpu(dev->descriptor.idProduct) == PL2303_PRODUCT_ID)) || 713 (le16_to_cpu(dev->descriptor.idProduct) == PL2303_PRODUCT_ID)) ||
718 ((le16_to_cpu(dev->descriptor.idVendor) == ATEN_VENDOR_ID) && 714 ((le16_to_cpu(dev->descriptor.idVendor) == ATEN_VENDOR_ID) &&
719 (le16_to_cpu(dev->descriptor.idProduct) == ATEN_PRODUCT_ID))) { 715 (le16_to_cpu(dev->descriptor.idProduct) == ATEN_PRODUCT_ID)) ||
716 ((le16_to_cpu(dev->descriptor.idVendor) == ALCOR_VENDOR_ID) &&
717 (le16_to_cpu(dev->descriptor.idProduct) == ALCOR_PRODUCT_ID))) {
720 if (interface != dev->actconfig->interface[0]) { 718 if (interface != dev->actconfig->interface[0]) {
721 /* check out the endpoints of the other interface*/ 719 /* check out the endpoints of the other interface*/
722 iface_desc = dev->actconfig->interface[0]->cur_altsetting; 720 iface_desc = dev->actconfig->interface[0]->cur_altsetting;
723 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { 721 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
724 endpoint = &iface_desc->endpoint[i].desc; 722 endpoint = &iface_desc->endpoint[i].desc;
725 if ((endpoint->bEndpointAddress & 0x80) && 723 if (usb_endpoint_is_int_in(endpoint)) {
726 ((endpoint->bmAttributes & 3) == 0x03)) {
727 /* we found a interrupt in endpoint */ 724 /* we found a interrupt in endpoint */
728 dbg("found interrupt in for Prolific device on separate interface"); 725 dbg("found interrupt in for Prolific device on separate interface");
729 interrupt_in_endpoint[num_interrupt_in] = endpoint; 726 interrupt_in_endpoint[num_interrupt_in] = endpoint;
@@ -937,7 +934,10 @@ int usb_serial_probe(struct usb_interface *interface,
937 934
938 snprintf (&port->dev.bus_id[0], sizeof(port->dev.bus_id), "ttyUSB%d", port->number); 935 snprintf (&port->dev.bus_id[0], sizeof(port->dev.bus_id), "ttyUSB%d", port->number);
939 dbg ("%s - registering %s", __FUNCTION__, port->dev.bus_id); 936 dbg ("%s - registering %s", __FUNCTION__, port->dev.bus_id);
940 device_register (&port->dev); 937 retval = device_register(&port->dev);
938 if (retval)
939 dev_err(&port->dev, "Error registering port device, "
940 "continuing\n");
941 } 941 }
942 942
943 usb_serial_console_init (debug, minor); 943 usb_serial_console_init (debug, minor);
@@ -1015,7 +1015,7 @@ void usb_serial_disconnect(struct usb_interface *interface)
1015 dev_info(dev, "device disconnected\n"); 1015 dev_info(dev, "device disconnected\n");
1016} 1016}
1017 1017
1018static struct tty_operations serial_ops = { 1018static const struct tty_operations serial_ops = {
1019 .open = serial_open, 1019 .open = serial_open,
1020 .close = serial_close, 1020 .close = serial_close,
1021 .write = serial_write, 1021 .write = serial_write,
diff --git a/drivers/usb/storage/Kconfig b/drivers/usb/storage/Kconfig
index be9eec225743..422a4b288e34 100644
--- a/drivers/usb/storage/Kconfig
+++ b/drivers/usb/storage/Kconfig
@@ -8,8 +8,7 @@ comment "may also be needed; see USB_STORAGE Help for more information"
8 8
9config USB_STORAGE 9config USB_STORAGE
10 tristate "USB Mass Storage support" 10 tristate "USB Mass Storage support"
11 depends on USB 11 depends on USB && SCSI
12 select SCSI
13 ---help--- 12 ---help---
14 Say Y here if you want to connect USB mass storage devices to your 13 Say Y here if you want to connect USB mass storage devices to your
15 computer's USB port. This is the driver you need for USB 14 computer's USB port. This is the driver you need for USB
@@ -18,7 +17,7 @@ config USB_STORAGE
18 similar devices. This driver may also be used for some cameras 17 similar devices. This driver may also be used for some cameras
19 and card readers. 18 and card readers.
20 19
21 This option 'selects' (turns on, enables) 'SCSI', but you 20 This option depends on 'SCSI' support being enabled, but you
22 probably also need 'SCSI device support: SCSI disk support' 21 probably also need 'SCSI device support: SCSI disk support'
23 (BLK_DEV_SD) for most USB storage devices. 22 (BLK_DEV_SD) for most USB storage devices.
24 23
@@ -135,6 +134,18 @@ config USB_STORAGE_ONETOUCH
135 this input in any keybinding software. (e.g. gnome's keyboard short- 134 this input in any keybinding software. (e.g. gnome's keyboard short-
136 cuts) 135 cuts)
137 136
137config USB_STORAGE_KARMA
138 bool "Support for Rio Karma music player"
139 depends on USB_STORAGE
140 help
141 Say Y here to include additional code to support the Rio Karma
142 USB interface.
143
144 This code places the Rio Karma into mass storage mode, enabling
145 it to be mounted as an ordinary filesystem. Performing an eject
146 on the resulting scsi device node returns the Karma to normal
147 operation.
148
138config USB_LIBUSUAL 149config USB_LIBUSUAL
139 bool "The shared table of common (or usual) storage devices" 150 bool "The shared table of common (or usual) storage devices"
140 depends on USB 151 depends on USB
diff --git a/drivers/usb/storage/Makefile b/drivers/usb/storage/Makefile
index 8cbba22508a4..023969b4385b 100644
--- a/drivers/usb/storage/Makefile
+++ b/drivers/usb/storage/Makefile
@@ -20,6 +20,7 @@ usb-storage-obj-$(CONFIG_USB_STORAGE_DATAFAB) += datafab.o
20usb-storage-obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += jumpshot.o 20usb-storage-obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += jumpshot.o
21usb-storage-obj-$(CONFIG_USB_STORAGE_ALAUDA) += alauda.o 21usb-storage-obj-$(CONFIG_USB_STORAGE_ALAUDA) += alauda.o
22usb-storage-obj-$(CONFIG_USB_STORAGE_ONETOUCH) += onetouch.o 22usb-storage-obj-$(CONFIG_USB_STORAGE_ONETOUCH) += onetouch.o
23usb-storage-obj-$(CONFIG_USB_STORAGE_KARMA) += karma.o
23 24
24usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \ 25usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \
25 initializers.o $(usb-storage-obj-y) 26 initializers.o $(usb-storage-obj-y)
diff --git a/drivers/usb/storage/initializers.c b/drivers/usb/storage/initializers.c
index ab173b30076e..5b06f9240d05 100644
--- a/drivers/usb/storage/initializers.c
+++ b/drivers/usb/storage/initializers.c
@@ -45,12 +45,6 @@
45#include "debug.h" 45#include "debug.h"
46#include "transport.h" 46#include "transport.h"
47 47
48#define RIO_MSC 0x08
49#define RIOP_INIT "RIOP\x00\x01\x08"
50#define RIOP_INIT_LEN 7
51#define RIO_SEND_LEN 40
52#define RIO_RECV_LEN 0x200
53
54/* This places the Shuttle/SCM USB<->SCSI bridge devices in multi-target 48/* This places the Shuttle/SCM USB<->SCSI bridge devices in multi-target
55 * mode */ 49 * mode */
56int usb_stor_euscsi_init(struct us_data *us) 50int usb_stor_euscsi_init(struct us_data *us)
@@ -97,70 +91,3 @@ int usb_stor_ucr61s2b_init(struct us_data *us)
97 91
98 return (res ? -1 : 0); 92 return (res ? -1 : 0);
99} 93}
100
101/* Place the Rio Karma into mass storage mode.
102 *
103 * The initialization begins by sending 40 bytes starting
104 * RIOP\x00\x01\x08\x00, which the device will ack with a 512-byte
105 * packet with the high four bits set and everything else null.
106 *
107 * Next, we send RIOP\x80\x00\x08\x00. Each time, a 512 byte response
108 * must be read, but we must loop until byte 5 in the response is 0x08,
109 * indicating success. */
110int rio_karma_init(struct us_data *us)
111{
112 int result, partial;
113 char *recv;
114 unsigned long timeout;
115
116 // us->iobuf is big enough to hold cmd but not receive
117 if (!(recv = kmalloc(RIO_RECV_LEN, GFP_KERNEL)))
118 goto die_nomem;
119
120 US_DEBUGP("Initializing Karma...\n");
121
122 memset(us->iobuf, 0, RIO_SEND_LEN);
123 memcpy(us->iobuf, RIOP_INIT, RIOP_INIT_LEN);
124
125 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
126 us->iobuf, RIO_SEND_LEN, &partial);
127 if (result != USB_STOR_XFER_GOOD)
128 goto die;
129
130 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
131 recv, RIO_RECV_LEN, &partial);
132 if (result != USB_STOR_XFER_GOOD)
133 goto die;
134
135 us->iobuf[4] = 0x80;
136 us->iobuf[5] = 0;
137 timeout = jiffies + msecs_to_jiffies(3000);
138 for (;;) {
139 US_DEBUGP("Sending init command\n");
140 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
141 us->iobuf, RIO_SEND_LEN, &partial);
142 if (result != USB_STOR_XFER_GOOD)
143 goto die;
144
145 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
146 recv, RIO_RECV_LEN, &partial);
147 if (result != USB_STOR_XFER_GOOD)
148 goto die;
149
150 if (recv[5] == RIO_MSC)
151 break;
152 if (time_after(jiffies, timeout))
153 goto die;
154 msleep(10);
155 }
156 US_DEBUGP("Karma initialized.\n");
157 kfree(recv);
158 return 0;
159
160die:
161 kfree(recv);
162die_nomem:
163 US_DEBUGP("Could not initialize karma.\n");
164 return USB_STOR_TRANSPORT_FAILED;
165}
166
diff --git a/drivers/usb/storage/initializers.h b/drivers/usb/storage/initializers.h
index 927f7781080f..e2967a4d48a2 100644
--- a/drivers/usb/storage/initializers.h
+++ b/drivers/usb/storage/initializers.h
@@ -47,4 +47,3 @@ int usb_stor_euscsi_init(struct us_data *us);
47/* This function is required to activate all four slots on the UCR-61S2B 47/* This function is required to activate all four slots on the UCR-61S2B
48 * flash reader */ 48 * flash reader */
49int usb_stor_ucr61s2b_init(struct us_data *us); 49int usb_stor_ucr61s2b_init(struct us_data *us);
50int rio_karma_init(struct us_data *us);
diff --git a/drivers/usb/storage/karma.c b/drivers/usb/storage/karma.c
new file mode 100644
index 000000000000..0d79ae5683f7
--- /dev/null
+++ b/drivers/usb/storage/karma.c
@@ -0,0 +1,155 @@
1/* Driver for Rio Karma
2 *
3 * (c) 2006 Bob Copeland <me@bobcopeland.com>
4 * (c) 2006 Keith Bennett <keith@mcs.st-and.ac.uk>
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
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#include <scsi/scsi.h>
22#include <scsi/scsi_cmnd.h>
23#include <scsi/scsi_device.h>
24
25#include "usb.h"
26#include "transport.h"
27#include "debug.h"
28#include "karma.h"
29
30#define RIO_PREFIX "RIOP\x00"
31#define RIO_PREFIX_LEN 5
32#define RIO_SEND_LEN 40
33#define RIO_RECV_LEN 0x200
34
35#define RIO_ENTER_STORAGE 0x1
36#define RIO_LEAVE_STORAGE 0x2
37#define RIO_RESET 0xC
38
39extern int usb_stor_Bulk_transport(struct scsi_cmnd *, struct us_data *);
40
41struct karma_data {
42 int in_storage;
43 char *recv;
44};
45
46/*
47 * Send commands to Rio Karma.
48 *
49 * For each command we send 40 bytes starting 'RIOP\0' followed by
50 * the command number and a sequence number, which the device will ack
51 * with a 512-byte packet with the high four bits set and everything
52 * else null. Then we send 'RIOP\x80' followed by a zero and the
53 * sequence number, until byte 5 in the response repeats the sequence
54 * number.
55 */
56static int rio_karma_send_command(char cmd, struct us_data *us)
57{
58 int result, partial;
59 unsigned long timeout;
60 static unsigned char seq = 1;
61 struct karma_data *data = (struct karma_data *) us->extra;
62
63 US_DEBUGP("karma: sending command %04x\n", cmd);
64 memset(us->iobuf, 0, RIO_SEND_LEN);
65 memcpy(us->iobuf, RIO_PREFIX, RIO_PREFIX_LEN);
66 us->iobuf[5] = cmd;
67 us->iobuf[6] = seq;
68
69 timeout = jiffies + msecs_to_jiffies(6000);
70 for (;;) {
71 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
72 us->iobuf, RIO_SEND_LEN, &partial);
73 if (result != USB_STOR_XFER_GOOD)
74 goto err;
75
76 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
77 data->recv, RIO_RECV_LEN, &partial);
78 if (result != USB_STOR_XFER_GOOD)
79 goto err;
80
81 if (data->recv[5] == seq)
82 break;
83
84 if (time_after(jiffies, timeout))
85 goto err;
86
87 us->iobuf[4] = 0x80;
88 us->iobuf[5] = 0;
89 msleep(50);
90 }
91
92 seq++;
93 if (seq == 0)
94 seq = 1;
95
96 US_DEBUGP("karma: sent command %04x\n", cmd);
97 return 0;
98err:
99 US_DEBUGP("karma: command %04x failed\n", cmd);
100 return USB_STOR_TRANSPORT_FAILED;
101}
102
103/*
104 * Trap START_STOP and READ_10 to leave/re-enter storage mode.
105 * Everything else is propagated to the normal bulk layer.
106 */
107int rio_karma_transport(struct scsi_cmnd *srb, struct us_data *us)
108{
109 int ret;
110 struct karma_data *data = (struct karma_data *) us->extra;
111
112 if (srb->cmnd[0] == READ_10 && !data->in_storage) {
113 ret = rio_karma_send_command(RIO_ENTER_STORAGE, us);
114 if (ret)
115 return ret;
116
117 data->in_storage = 1;
118 return usb_stor_Bulk_transport(srb, us);
119 } else if (srb->cmnd[0] == START_STOP) {
120 ret = rio_karma_send_command(RIO_LEAVE_STORAGE, us);
121 if (ret)
122 return ret;
123
124 data->in_storage = 0;
125 return rio_karma_send_command(RIO_RESET, us);
126 }
127 return usb_stor_Bulk_transport(srb, us);
128}
129
130static void rio_karma_destructor(void *extra)
131{
132 struct karma_data *data = (struct karma_data *) extra;
133 kfree(data->recv);
134}
135
136int rio_karma_init(struct us_data *us)
137{
138 int ret = 0;
139 struct karma_data *data = kzalloc(sizeof(struct karma_data), GFP_NOIO);
140 if (!data)
141 goto out;
142
143 data->recv = kmalloc(RIO_RECV_LEN, GFP_NOIO);
144 if (!data->recv) {
145 kfree(data);
146 goto out;
147 }
148
149 us->extra = data;
150 us->extra_destructor = rio_karma_destructor;
151 ret = rio_karma_send_command(RIO_ENTER_STORAGE, us);
152 data->in_storage = (ret == 0);
153out:
154 return ret;
155}
diff --git a/drivers/usb/storage/karma.h b/drivers/usb/storage/karma.h
new file mode 100644
index 000000000000..8a60972af8c5
--- /dev/null
+++ b/drivers/usb/storage/karma.h
@@ -0,0 +1,7 @@
1#ifndef _KARMA_USB_H
2#define _KARMA_USB_H
3
4extern int rio_karma_init(struct us_data *us);
5extern int rio_karma_transport(struct scsi_cmnd *srb, struct us_data *us);
6
7#endif
diff --git a/drivers/usb/storage/libusual.c b/drivers/usb/storage/libusual.c
index b1ec4a718547..599ad10a761b 100644
--- a/drivers/usb/storage/libusual.c
+++ b/drivers/usb/storage/libusual.c
@@ -8,6 +8,7 @@
8#include <linux/usb.h> 8#include <linux/usb.h>
9#include <linux/usb_usual.h> 9#include <linux/usb_usual.h>
10#include <linux/vmalloc.h> 10#include <linux/vmalloc.h>
11#include <linux/kthread.h>
11 12
12/* 13/*
13 */ 14 */
@@ -117,7 +118,7 @@ static int usu_probe(struct usb_interface *intf,
117 const struct usb_device_id *id) 118 const struct usb_device_id *id)
118{ 119{
119 unsigned long type; 120 unsigned long type;
120 int rc; 121 struct task_struct* task;
121 unsigned long flags; 122 unsigned long flags;
122 123
123 type = USB_US_TYPE(id->driver_info); 124 type = USB_US_TYPE(id->driver_info);
@@ -132,8 +133,9 @@ static int usu_probe(struct usb_interface *intf,
132 stat[type].fls |= USU_MOD_FL_THREAD; 133 stat[type].fls |= USU_MOD_FL_THREAD;
133 spin_unlock_irqrestore(&usu_lock, flags); 134 spin_unlock_irqrestore(&usu_lock, flags);
134 135
135 rc = kernel_thread(usu_probe_thread, (void*)type, CLONE_VM); 136 task = kthread_run(usu_probe_thread, (void*)type, "libusual_%d", type);
136 if (rc < 0) { 137 if (IS_ERR(task)) {
138 int rc = PTR_ERR(task);
137 printk(KERN_WARNING "libusual: " 139 printk(KERN_WARNING "libusual: "
138 "Unable to start the thread for %s: %d\n", 140 "Unable to start the thread for %s: %d\n",
139 bias_names[type], rc); 141 bias_names[type], rc);
@@ -175,8 +177,6 @@ static int usu_probe_thread(void *arg)
175 int rc; 177 int rc;
176 unsigned long flags; 178 unsigned long flags;
177 179
178 daemonize("libusual_%d", type); /* "usb-storage" is kinda too long */
179
180 /* A completion does not work here because it's counted. */ 180 /* A completion does not work here because it's counted. */
181 down(&usu_init_notify); 181 down(&usu_init_notify);
182 up(&usu_init_notify); 182 up(&usu_init_notify);
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c
index 313920d980c9..f843a0bcf107 100644
--- a/drivers/usb/storage/onetouch.c
+++ b/drivers/usb/storage/onetouch.c
@@ -135,6 +135,7 @@ int onetouch_connect_input(struct us_data *ss)
135 struct usb_onetouch *onetouch; 135 struct usb_onetouch *onetouch;
136 struct input_dev *input_dev; 136 struct input_dev *input_dev;
137 int pipe, maxp; 137 int pipe, maxp;
138 int error = -ENOMEM;
138 139
139 interface = ss->pusb_intf->cur_altsetting; 140 interface = ss->pusb_intf->cur_altsetting;
140 141
@@ -211,15 +212,18 @@ int onetouch_connect_input(struct us_data *ss)
211 ss->suspend_resume_hook = usb_onetouch_pm_hook; 212 ss->suspend_resume_hook = usb_onetouch_pm_hook;
212#endif 213#endif
213 214
214 input_register_device(onetouch->dev); 215 error = input_register_device(onetouch->dev);
216 if (error)
217 goto fail3;
215 218
216 return 0; 219 return 0;
217 220
221 fail3: usb_free_urb(onetouch->irq);
218 fail2: usb_buffer_free(udev, ONETOUCH_PKT_LEN, 222 fail2: usb_buffer_free(udev, ONETOUCH_PKT_LEN,
219 onetouch->data, onetouch->data_dma); 223 onetouch->data, onetouch->data_dma);
220 fail1: kfree(onetouch); 224 fail1: kfree(onetouch);
221 input_free_device(input_dev); 225 input_free_device(input_dev);
222 return -ENOMEM; 226 return error;
223} 227}
224 228
225void onetouch_release_input(void *onetouch_) 229void onetouch_release_input(void *onetouch_)
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index a4b7df9ff8c1..e1072d52d641 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -72,12 +72,27 @@ static const char* host_info(struct Scsi_Host *host)
72 72
73static int slave_alloc (struct scsi_device *sdev) 73static int slave_alloc (struct scsi_device *sdev)
74{ 74{
75 struct us_data *us = host_to_us(sdev->host);
76
75 /* 77 /*
76 * Set the INQUIRY transfer length to 36. We don't use any of 78 * Set the INQUIRY transfer length to 36. We don't use any of
77 * the extra data and many devices choke if asked for more or 79 * the extra data and many devices choke if asked for more or
78 * less than 36 bytes. 80 * less than 36 bytes.
79 */ 81 */
80 sdev->inquiry_len = 36; 82 sdev->inquiry_len = 36;
83
84 /*
85 * The UFI spec treates the Peripheral Qualifier bits in an
86 * INQUIRY result as reserved and requires devices to set them
87 * to 0. However the SCSI spec requires these bits to be set
88 * to 3 to indicate when a LUN is not present.
89 *
90 * Let the scanning code know if this target merely sets
91 * Peripheral Device Type to 0x1f to indicate no LUN.
92 */
93 if (us->subclass == US_SC_UFI)
94 sdev->sdev_target->pdt_1f_for_no_lun = 1;
95
81 return 0; 96 return 0;
82} 97}
83 98
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index d6acc92a4ae3..f23514c4e649 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -294,11 +294,6 @@ static int interpret_urb_result(struct us_data *us, unsigned int pipe,
294 return USB_STOR_XFER_ERROR; 294 return USB_STOR_XFER_ERROR;
295 return USB_STOR_XFER_STALLED; 295 return USB_STOR_XFER_STALLED;
296 296
297 /* timeout or excessively long NAK */
298 case -ETIMEDOUT:
299 US_DEBUGP("-- timeout or NAK\n");
300 return USB_STOR_XFER_ERROR;
301
302 /* babble - the device tried to send more than we wanted to read */ 297 /* babble - the device tried to send more than we wanted to read */
303 case -EOVERFLOW: 298 case -EOVERFLOW:
304 US_DEBUGP("-- babble\n"); 299 US_DEBUGP("-- babble\n");
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index b130e170b4a8..c9a8d50106d1 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -152,6 +152,13 @@ UNUSUAL_DEV( 0x0421, 0x042e, 0x0100, 0x0100,
152 US_SC_DEVICE, US_PR_DEVICE, NULL, 152 US_SC_DEVICE, US_PR_DEVICE, NULL,
153 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ), 153 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ),
154 154
155/* Reported by Jon Hart <Jon.Hart@web.de> */
156UNUSUAL_DEV( 0x0421, 0x0434, 0x0100, 0x0100,
157 "Nokia",
158 "E60",
159 US_SC_DEVICE, US_PR_DEVICE, NULL,
160 US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ),
161
155/* Reported by Sumedha Swamy <sumedhaswamy@gmail.com> and 162/* Reported by Sumedha Swamy <sumedhaswamy@gmail.com> and
156 * Einar Th. Einarsson <einarthered@gmail.com> */ 163 * Einar Th. Einarsson <einarthered@gmail.com> */
157UNUSUAL_DEV( 0x0421, 0x0444, 0x0100, 0x0100, 164UNUSUAL_DEV( 0x0421, 0x0444, 0x0100, 0x0100,
@@ -218,10 +225,12 @@ UNUSUAL_DEV( 0x0457, 0x0151, 0x0100, 0x0100,
218 US_SC_DEVICE, US_PR_DEVICE, NULL, 225 US_SC_DEVICE, US_PR_DEVICE, NULL,
219 US_FL_NOT_LOCKABLE ), 226 US_FL_NOT_LOCKABLE ),
220 227
228#ifdef CONFIG_USB_STORAGE_KARMA
221UNUSUAL_DEV( 0x045a, 0x5210, 0x0101, 0x0101, 229UNUSUAL_DEV( 0x045a, 0x5210, 0x0101, 0x0101,
222 "Rio", 230 "Rio",
223 "Rio Karma", 231 "Rio Karma",
224 US_SC_SCSI, US_PR_BULK, rio_karma_init, 0), 232 US_SC_SCSI, US_PR_KARMA, rio_karma_init, 0),
233#endif
225 234
226/* Patch submitted by Philipp Friedrich <philipp@void.at> */ 235/* Patch submitted by Philipp Friedrich <philipp@void.at> */
227UNUSUAL_DEV( 0x0482, 0x0100, 0x0100, 0x0100, 236UNUSUAL_DEV( 0x0482, 0x0100, 0x0100, 0x0100,
@@ -631,6 +640,13 @@ UNUSUAL_DEV( 0x0595, 0x4343, 0x0000, 0x2210,
631 "Digital Camera EX-20 DSC", 640 "Digital Camera EX-20 DSC",
632 US_SC_8070, US_PR_DEVICE, NULL, 0 ), 641 US_SC_8070, US_PR_DEVICE, NULL, 0 ),
633 642
643/* Reported by <Hendryk.Pfeiffer@gmx.de> */
644UNUSUAL_DEV( 0x059f, 0x0643, 0x0000, 0x0000,
645 "LaCie",
646 "DVD+-RW",
647 US_SC_DEVICE, US_PR_DEVICE, NULL,
648 US_FL_GO_SLOW ),
649
634/* Submitted by Joel Bourquard <numlock@freesurf.ch> 650/* Submitted by Joel Bourquard <numlock@freesurf.ch>
635 * Some versions of this device need the SubClass and Protocol overrides 651 * Some versions of this device need the SubClass and Protocol overrides
636 * while others don't. 652 * while others don't.
@@ -1254,6 +1270,13 @@ UNUSUAL_DEV( 0x0fce, 0xd008, 0x0000, 0x0000,
1254 US_SC_DEVICE, US_PR_DEVICE, NULL, 1270 US_SC_DEVICE, US_PR_DEVICE, NULL,
1255 US_FL_NO_WP_DETECT ), 1271 US_FL_NO_WP_DETECT ),
1256 1272
1273/* Reported by Jan Mate <mate@fiit.stuba.sk> */
1274UNUSUAL_DEV( 0x0fce, 0xe030, 0x0000, 0x0000,
1275 "Sony Ericsson",
1276 "P990i",
1277 US_SC_DEVICE, US_PR_DEVICE, NULL,
1278 US_FL_FIX_CAPACITY ),
1279
1257/* Reported by Emmanuel Vasilakis <evas@forthnet.gr> */ 1280/* Reported by Emmanuel Vasilakis <evas@forthnet.gr> */
1258UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000, 1281UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000,
1259 "Sony Ericsson", 1282 "Sony Ericsson",
@@ -1261,6 +1284,13 @@ UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000,
1261 US_SC_DEVICE, US_PR_DEVICE, NULL, 1284 US_SC_DEVICE, US_PR_DEVICE, NULL,
1262 US_FL_FIX_CAPACITY ), 1285 US_FL_FIX_CAPACITY ),
1263 1286
1287/* Reported by Jan Mate <mate@fiit.stuba.sk> */
1288UNUSUAL_DEV( 0x0fce, 0xe030, 0x0000, 0x0000,
1289 "Sony Ericsson",
1290 "P990i",
1291 US_SC_DEVICE, US_PR_DEVICE, NULL,
1292 US_FL_FIX_CAPACITY ),
1293
1264/* Reported by Kevin Cernekee <kpc-usbdev@gelato.uiuc.edu> 1294/* Reported by Kevin Cernekee <kpc-usbdev@gelato.uiuc.edu>
1265 * Tested on hardware version 1.10. 1295 * Tested on hardware version 1.10.
1266 * Entry is needed only for the initializer function override. 1296 * Entry is needed only for the initializer function override.
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 8d7bdcb5924d..b8d6031b0975 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -98,6 +98,9 @@
98#ifdef CONFIG_USB_STORAGE_ALAUDA 98#ifdef CONFIG_USB_STORAGE_ALAUDA
99#include "alauda.h" 99#include "alauda.h"
100#endif 100#endif
101#ifdef CONFIG_USB_STORAGE_KARMA
102#include "karma.h"
103#endif
101 104
102/* Some informational data */ 105/* Some informational data */
103MODULE_AUTHOR("Matthew Dharm <mdharm-usb@one-eyed-alien.net>"); 106MODULE_AUTHOR("Matthew Dharm <mdharm-usb@one-eyed-alien.net>");
@@ -646,6 +649,14 @@ static int get_transport(struct us_data *us)
646 break; 649 break;
647#endif 650#endif
648 651
652#ifdef CONFIG_USB_STORAGE_KARMA
653 case US_PR_KARMA:
654 us->transport_name = "Rio Karma/Bulk";
655 us->transport = rio_karma_transport;
656 us->transport_reset = usb_stor_Bulk_reset;
657 break;
658#endif
659
649 default: 660 default:
650 return -EIO; 661 return -EIO;
651 } 662 }
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index b362039792b3..1b51d3187a95 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * USB Skeleton driver - 2.0 2 * USB Skeleton driver - 2.2
3 * 3 *
4 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com) 4 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
5 * 5 *
@@ -7,9 +7,8 @@
7 * modify it under the terms of the GNU General Public License as 7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2. 8 * published by the Free Software Foundation, version 2.
9 * 9 *
10 * This driver is based on the 2.6.3 version of drivers/usb/usb-skeleton.c 10 * This driver is based on the 2.6.3 version of drivers/usb/usb-skeleton.c
11 * but has been rewritten to be easy to read and use, as no locks are now 11 * but has been rewritten to be easier to read and use.
12 * needed anymore.
13 * 12 *
14 */ 13 */
15 14
@@ -21,6 +20,7 @@
21#include <linux/kref.h> 20#include <linux/kref.h>
22#include <asm/uaccess.h> 21#include <asm/uaccess.h>
23#include <linux/usb.h> 22#include <linux/usb.h>
23#include <linux/mutex.h>
24 24
25 25
26/* Define these values to match your devices */ 26/* Define these values to match your devices */
@@ -32,38 +32,39 @@ static struct usb_device_id skel_table [] = {
32 { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) }, 32 { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) },
33 { } /* Terminating entry */ 33 { } /* Terminating entry */
34}; 34};
35MODULE_DEVICE_TABLE (usb, skel_table); 35MODULE_DEVICE_TABLE(usb, skel_table);
36 36
37 37
38/* Get a minor range for your devices from the usb maintainer */ 38/* Get a minor range for your devices from the usb maintainer */
39#define USB_SKEL_MINOR_BASE 192 39#define USB_SKEL_MINOR_BASE 192
40 40
41/* our private defines. if this grows any larger, use your own .h file */ 41/* our private defines. if this grows any larger, use your own .h file */
42#define MAX_TRANSFER ( PAGE_SIZE - 512 ) 42#define MAX_TRANSFER (PAGE_SIZE - 512)
43#define WRITES_IN_FLIGHT 8 43#define WRITES_IN_FLIGHT 8
44 44
45/* Structure to hold all of our device specific stuff */ 45/* Structure to hold all of our device specific stuff */
46struct usb_skel { 46struct usb_skel {
47 struct usb_device * udev; /* the usb device for this device */ 47 struct usb_device *dev; /* the usb device for this device */
48 struct usb_interface * interface; /* the interface for this device */ 48 struct usb_interface *interface; /* the interface for this device */
49 struct semaphore limit_sem; /* limiting the number of writes in progress */ 49 struct semaphore limit_sem; /* limiting the number of writes in progress */
50 unsigned char * bulk_in_buffer; /* the buffer to receive data */ 50 unsigned char *bulk_in_buffer; /* the buffer to receive data */
51 size_t bulk_in_size; /* the size of the receive buffer */ 51 size_t bulk_in_size; /* the size of the receive buffer */
52 __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ 52 __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */
53 __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ 53 __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */
54 struct kref kref; 54 struct kref kref;
55 struct mutex io_mutex; /* synchronize I/O with disconnect */
55}; 56};
56#define to_skel_dev(d) container_of(d, struct usb_skel, kref) 57#define to_skel_dev(d) container_of(d, struct usb_skel, kref)
57 58
58static struct usb_driver skel_driver; 59static struct usb_driver skel_driver;
59 60
60static void skel_delete(struct kref *kref) 61static void skel_delete(struct kref *kref)
61{ 62{
62 struct usb_skel *dev = to_skel_dev(kref); 63 struct usb_skel *dev = to_skel_dev(kref);
63 64
64 usb_put_dev(dev->udev); 65 usb_put_dev(dev->udev);
65 kfree (dev->bulk_in_buffer); 66 kfree(dev->bulk_in_buffer);
66 kfree (dev); 67 kfree(dev);
67} 68}
68 69
69static int skel_open(struct inode *inode, struct file *file) 70static int skel_open(struct inode *inode, struct file *file)
@@ -89,6 +90,11 @@ static int skel_open(struct inode *inode, struct file *file)
89 goto exit; 90 goto exit;
90 } 91 }
91 92
93 /* prevent the device from being autosuspended */
94 retval = usb_autopm_get_interface(interface);
95 if (retval)
96 goto exit;
97
92 /* increment our usage count for the device */ 98 /* increment our usage count for the device */
93 kref_get(&dev->kref); 99 kref_get(&dev->kref);
94 100
@@ -107,6 +113,12 @@ static int skel_release(struct inode *inode, struct file *file)
107 if (dev == NULL) 113 if (dev == NULL)
108 return -ENODEV; 114 return -ENODEV;
109 115
116 /* allow the device to be autosuspended */
117 mutex_lock(&dev->io_mutex);
118 if (dev->interface)
119 usb_autopm_put_interface(dev->interface);
120 mutex_unlock(&dev->io_mutex);
121
110 /* decrement the count on our device */ 122 /* decrement the count on our device */
111 kref_put(&dev->kref, skel_delete); 123 kref_put(&dev->kref, skel_delete);
112 return 0; 124 return 0;
@@ -115,11 +127,17 @@ static int skel_release(struct inode *inode, struct file *file)
115static ssize_t skel_read(struct file *file, char *buffer, size_t count, loff_t *ppos) 127static ssize_t skel_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
116{ 128{
117 struct usb_skel *dev; 129 struct usb_skel *dev;
118 int retval = 0; 130 int retval;
119 int bytes_read; 131 int bytes_read;
120 132
121 dev = (struct usb_skel *)file->private_data; 133 dev = (struct usb_skel *)file->private_data;
122 134
135 mutex_lock(&dev->io_mutex);
136 if (!dev->interface) { /* disconnect() was called */
137 retval = -ENODEV;
138 goto exit;
139 }
140
123 /* do a blocking bulk read to get data from the device */ 141 /* do a blocking bulk read to get data from the device */
124 retval = usb_bulk_msg(dev->udev, 142 retval = usb_bulk_msg(dev->udev,
125 usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr), 143 usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr),
@@ -135,6 +153,8 @@ static ssize_t skel_read(struct file *file, char *buffer, size_t count, loff_t *
135 retval = bytes_read; 153 retval = bytes_read;
136 } 154 }
137 155
156exit:
157 mutex_unlock(&dev->io_mutex);
138 return retval; 158 return retval;
139} 159}
140 160
@@ -145,16 +165,16 @@ static void skel_write_bulk_callback(struct urb *urb, struct pt_regs *regs)
145 dev = (struct usb_skel *)urb->context; 165 dev = (struct usb_skel *)urb->context;
146 166
147 /* sync/async unlink faults aren't errors */ 167 /* sync/async unlink faults aren't errors */
148 if (urb->status && 168 if (urb->status &&
149 !(urb->status == -ENOENT || 169 !(urb->status == -ENOENT ||
150 urb->status == -ECONNRESET || 170 urb->status == -ECONNRESET ||
151 urb->status == -ESHUTDOWN)) { 171 urb->status == -ESHUTDOWN)) {
152 dbg("%s - nonzero write bulk status received: %d", 172 err("%s - nonzero write bulk status received: %d",
153 __FUNCTION__, urb->status); 173 __FUNCTION__, urb->status);
154 } 174 }
155 175
156 /* free up our allocated buffer */ 176 /* free up our allocated buffer */
157 usb_buffer_free(urb->dev, urb->transfer_buffer_length, 177 usb_buffer_free(urb->dev, urb->transfer_buffer_length,
158 urb->transfer_buffer, urb->transfer_dma); 178 urb->transfer_buffer, urb->transfer_dma);
159 up(&dev->limit_sem); 179 up(&dev->limit_sem);
160} 180}
@@ -179,6 +199,12 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou
179 goto exit; 199 goto exit;
180 } 200 }
181 201
202 mutex_lock(&dev->io_mutex);
203 if (!dev->interface) { /* disconnect() was called */
204 retval = -ENODEV;
205 goto error;
206 }
207
182 /* create a urb, and a buffer for it, and copy the data to the urb */ 208 /* create a urb, and a buffer for it, and copy the data to the urb */
183 urb = usb_alloc_urb(0, GFP_KERNEL); 209 urb = usb_alloc_urb(0, GFP_KERNEL);
184 if (!urb) { 210 if (!urb) {
@@ -213,17 +239,22 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou
213 /* release our reference to this urb, the USB core will eventually free it entirely */ 239 /* release our reference to this urb, the USB core will eventually free it entirely */
214 usb_free_urb(urb); 240 usb_free_urb(urb);
215 241
216exit: 242 mutex_unlock(&dev->io_mutex);
217 return writesize; 243 return writesize;
218 244
219error: 245error:
220 usb_buffer_free(dev->udev, writesize, buf, urb->transfer_dma); 246 if (urb) {
221 usb_free_urb(urb); 247 usb_buffer_free(dev->udev, writesize, buf, urb->transfer_dma);
248 usb_free_urb(urb);
249 }
250 mutex_unlock(&dev->io_mutex);
222 up(&dev->limit_sem); 251 up(&dev->limit_sem);
252
253exit:
223 return retval; 254 return retval;
224} 255}
225 256
226static struct file_operations skel_fops = { 257static const struct file_operations skel_fops = {
227 .owner = THIS_MODULE, 258 .owner = THIS_MODULE,
228 .read = skel_read, 259 .read = skel_read,
229 .write = skel_write, 260 .write = skel_write,
@@ -231,7 +262,7 @@ static struct file_operations skel_fops = {
231 .release = skel_release, 262 .release = skel_release,
232}; 263};
233 264
234/* 265/*
235 * usb class driver info in order to get a minor number from the usb core, 266 * usb class driver info in order to get a minor number from the usb core,
236 * and to have the device registered with the driver core 267 * and to have the device registered with the driver core
237 */ 268 */
@@ -243,7 +274,7 @@ static struct usb_class_driver skel_class = {
243 274
244static int skel_probe(struct usb_interface *interface, const struct usb_device_id *id) 275static int skel_probe(struct usb_interface *interface, const struct usb_device_id *id)
245{ 276{
246 struct usb_skel *dev = NULL; 277 struct usb_skel *dev;
247 struct usb_host_interface *iface_desc; 278 struct usb_host_interface *iface_desc;
248 struct usb_endpoint_descriptor *endpoint; 279 struct usb_endpoint_descriptor *endpoint;
249 size_t buffer_size; 280 size_t buffer_size;
@@ -252,12 +283,13 @@ static int skel_probe(struct usb_interface *interface, const struct usb_device_i
252 283
253 /* allocate memory for our device state and initialize it */ 284 /* allocate memory for our device state and initialize it */
254 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 285 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
255 if (dev == NULL) { 286 if (!dev) {
256 err("Out of memory"); 287 err("Out of memory");
257 goto error; 288 goto error;
258 } 289 }
259 kref_init(&dev->kref); 290 kref_init(&dev->kref);
260 sema_init(&dev->limit_sem, WRITES_IN_FLIGHT); 291 sema_init(&dev->limit_sem, WRITES_IN_FLIGHT);
292 mutex_init(&dev->io_mutex);
261 293
262 dev->udev = usb_get_dev(interface_to_usbdev(interface)); 294 dev->udev = usb_get_dev(interface_to_usbdev(interface));
263 dev->interface = interface; 295 dev->interface = interface;
@@ -269,10 +301,7 @@ static int skel_probe(struct usb_interface *interface, const struct usb_device_i
269 endpoint = &iface_desc->endpoint[i].desc; 301 endpoint = &iface_desc->endpoint[i].desc;
270 302
271 if (!dev->bulk_in_endpointAddr && 303 if (!dev->bulk_in_endpointAddr &&
272 ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) 304 usb_endpoint_is_bulk_in(endpoint)) {
273 == USB_DIR_IN) &&
274 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
275 == USB_ENDPOINT_XFER_BULK)) {
276 /* we found a bulk in endpoint */ 305 /* we found a bulk in endpoint */
277 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 306 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
278 dev->bulk_in_size = buffer_size; 307 dev->bulk_in_size = buffer_size;
@@ -285,10 +314,7 @@ static int skel_probe(struct usb_interface *interface, const struct usb_device_i
285 } 314 }
286 315
287 if (!dev->bulk_out_endpointAddr && 316 if (!dev->bulk_out_endpointAddr &&
288 ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) 317 usb_endpoint_is_bulk_out(endpoint)) {
289 == USB_DIR_OUT) &&
290 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
291 == USB_ENDPOINT_XFER_BULK)) {
292 /* we found a bulk out endpoint */ 318 /* we found a bulk out endpoint */
293 dev->bulk_out_endpointAddr = endpoint->bEndpointAddress; 319 dev->bulk_out_endpointAddr = endpoint->bEndpointAddress;
294 } 320 }
@@ -334,6 +360,11 @@ static void skel_disconnect(struct usb_interface *interface)
334 /* give back our minor */ 360 /* give back our minor */
335 usb_deregister_dev(interface, &skel_class); 361 usb_deregister_dev(interface, &skel_class);
336 362
363 /* prevent more I/O from starting */
364 mutex_lock(&dev->io_mutex);
365 dev->interface = NULL;
366 mutex_unlock(&dev->io_mutex);
367
337 unlock_kernel(); 368 unlock_kernel();
338 369
339 /* decrement our usage count */ 370 /* decrement our usage count */
@@ -367,7 +398,7 @@ static void __exit usb_skel_exit(void)
367 usb_deregister(&skel_driver); 398 usb_deregister(&skel_driver);
368} 399}
369 400
370module_init (usb_skel_init); 401module_init(usb_skel_init);
371module_exit (usb_skel_exit); 402module_exit(usb_skel_exit);
372 403
373MODULE_LICENSE("GPL"); 404MODULE_LICENSE("GPL");
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 702eb933cf88..a1c8923b0bf5 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -53,6 +53,11 @@ config FB
53 (e.g. an accelerated X server) and that are not frame buffer 53 (e.g. an accelerated X server) and that are not frame buffer
54 device-aware may cause unexpected results. If unsure, say N. 54 device-aware may cause unexpected results. If unsure, say N.
55 55
56config FB_DDC
57 tristate
58 depends on FB && I2C && I2C_ALGOBIT
59 default n
60
56config FB_CFB_FILLRECT 61config FB_CFB_FILLRECT
57 tristate 62 tristate
58 depends on FB 63 depends on FB
@@ -696,6 +701,7 @@ config FB_NVIDIA
696 depends on FB && PCI 701 depends on FB && PCI
697 select I2C_ALGOBIT if FB_NVIDIA_I2C 702 select I2C_ALGOBIT if FB_NVIDIA_I2C
698 select I2C if FB_NVIDIA_I2C 703 select I2C if FB_NVIDIA_I2C
704 select FB_DDC if FB_NVIDIA_I2C
699 select FB_MODE_HELPERS 705 select FB_MODE_HELPERS
700 select FB_CFB_FILLRECT 706 select FB_CFB_FILLRECT
701 select FB_CFB_COPYAREA 707 select FB_CFB_COPYAREA
@@ -734,6 +740,7 @@ config FB_RIVA
734 depends on FB && PCI 740 depends on FB && PCI
735 select I2C_ALGOBIT if FB_RIVA_I2C 741 select I2C_ALGOBIT if FB_RIVA_I2C
736 select I2C if FB_RIVA_I2C 742 select I2C if FB_RIVA_I2C
743 select FB_DDC if FB_RIVA_I2C
737 select FB_MODE_HELPERS 744 select FB_MODE_HELPERS
738 select FB_CFB_FILLRECT 745 select FB_CFB_FILLRECT
739 select FB_CFB_COPYAREA 746 select FB_CFB_COPYAREA
@@ -822,33 +829,52 @@ config FB_I810_I2C
822 depends on FB_I810 && FB_I810_GTF 829 depends on FB_I810 && FB_I810_GTF
823 select I2C 830 select I2C
824 select I2C_ALGOBIT 831 select I2C_ALGOBIT
832 select FB_DDC
825 help 833 help
826 834
827config FB_INTEL 835config FB_INTEL
828 tristate "Intel 830M/845G/852GM/855GM/865G support (EXPERIMENTAL)" 836 tristate "Intel 830M/845G/852GM/855GM/865G/915G/945G support (EXPERIMENTAL)"
829 depends on FB && EXPERIMENTAL && PCI && X86 837 depends on FB && EXPERIMENTAL && PCI && X86
830 select AGP 838 select AGP
831 select AGP_INTEL 839 select AGP_INTEL
840 select I2C_ALGOBIT if FB_INTEL_I2C
841 select I2C if FB_INTEL_I2C
832 select FB_MODE_HELPERS 842 select FB_MODE_HELPERS
833 select FB_CFB_FILLRECT 843 select FB_CFB_FILLRECT
834 select FB_CFB_COPYAREA 844 select FB_CFB_COPYAREA
835 select FB_CFB_IMAGEBLIT 845 select FB_CFB_IMAGEBLIT
836 help 846 help
837 This driver supports the on-board graphics built in to the Intel 847 This driver supports the on-board graphics built in to the Intel
838 830M/845G/852GM/855GM/865G chipsets. 848 830M/845G/852GM/855GM/865G/915G/915GM/945G/945GM chipsets.
839 Say Y if you have and plan to use such a board. 849 Say Y if you have and plan to use such a board.
840 850
841 To compile this driver as a module, choose M here: the 851 If you say Y here and want DDC/I2C support you must first say Y to
852 "I2C support" and "I2C bit-banging support" in the character devices
853 section.
854
855 If you say M here then "I2C support" and "I2C bit-banging support"
856 can be build either as modules or built-in.
857
858 To compile this driver as a module, choose M here: the
842 module will be called intelfb. 859 module will be called intelfb.
843 860
861 For more information, please read <file:Documentation/fb/intelfb.txt>
862
844config FB_INTEL_DEBUG 863config FB_INTEL_DEBUG
845 bool "Intel driver Debug Messages" 864 bool "Intel driver Debug Messages"
846 depends on FB_INTEL 865 depends on FB_INTEL
847 ---help--- 866 ---help---
848 Say Y here if you want the Intel driver to output all sorts 867 Say Y here if you want the Intel driver to output all sorts
849 of debugging informations to provide to the maintainer when 868 of debugging informations to provide to the maintainer when
850 something goes wrong. 869 something goes wrong.
851 870
871config FB_INTEL_I2C
872 bool "DDC/I2C for Intel framebuffer support"
873 depends on FB_INTEL
874 default y
875 help
876 Say Y here if you want DDC/I2C support for your on-board Intel graphics.
877
852config FB_MATROX 878config FB_MATROX
853 tristate "Matrox acceleration" 879 tristate "Matrox acceleration"
854 depends on FB && PCI 880 depends on FB && PCI
@@ -994,6 +1020,7 @@ config FB_RADEON
994 depends on FB && PCI 1020 depends on FB && PCI
995 select I2C_ALGOBIT if FB_RADEON_I2C 1021 select I2C_ALGOBIT if FB_RADEON_I2C
996 select I2C if FB_RADEON_I2C 1022 select I2C if FB_RADEON_I2C
1023 select FB_DDC if FB_RADEON_I2C
997 select FB_MODE_HELPERS 1024 select FB_MODE_HELPERS
998 select FB_CFB_FILLRECT 1025 select FB_CFB_FILLRECT
999 select FB_CFB_COPYAREA 1026 select FB_CFB_COPYAREA
@@ -1122,6 +1149,7 @@ config FB_SAVAGE
1122 depends on FB && PCI && EXPERIMENTAL 1149 depends on FB && PCI && EXPERIMENTAL
1123 select I2C_ALGOBIT if FB_SAVAGE_I2C 1150 select I2C_ALGOBIT if FB_SAVAGE_I2C
1124 select I2C if FB_SAVAGE_I2C 1151 select I2C if FB_SAVAGE_I2C
1152 select FB_DDC if FB_SAVAGE_I2C
1125 select FB_MODE_HELPERS 1153 select FB_MODE_HELPERS
1126 select FB_CFB_FILLRECT 1154 select FB_CFB_FILLRECT
1127 select FB_CFB_COPYAREA 1155 select FB_CFB_COPYAREA
@@ -1601,7 +1629,8 @@ config FB_VIRTUAL
1601 kernel option `video=vfb:'. 1629 kernel option `video=vfb:'.
1602 1630
1603 To compile this driver as a module, choose M here: the 1631 To compile this driver as a module, choose M here: the
1604 module will be called vfb. 1632 module will be called vfb. In order to load it, you must use
1633 the vfb_enable=1 option.
1605 1634
1606 If unsure, say N. 1635 If unsure, say N.
1607if VT 1636if VT
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 481c6c9695f8..a6980e9a2481 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_FB_CFB_FILLRECT) += cfbfillrect.o
18obj-$(CONFIG_FB_CFB_COPYAREA) += cfbcopyarea.o 18obj-$(CONFIG_FB_CFB_COPYAREA) += cfbcopyarea.o
19obj-$(CONFIG_FB_CFB_IMAGEBLIT) += cfbimgblt.o 19obj-$(CONFIG_FB_CFB_IMAGEBLIT) += cfbimgblt.o
20obj-$(CONFIG_FB_MACMODES) += macmodes.o 20obj-$(CONFIG_FB_MACMODES) += macmodes.o
21obj-$(CONFIG_FB_DDC) += fb_ddc.o
21 22
22# Hardware specific drivers go first 23# Hardware specific drivers go first
23obj-$(CONFIG_FB_RETINAZ3) += retz3fb.o 24obj-$(CONFIG_FB_RETINAZ3) += retz3fb.o
diff --git a/drivers/video/aty/atyfb.h b/drivers/video/aty/atyfb.h
index 55fb8b04489b..b04f49fb976a 100644
--- a/drivers/video/aty/atyfb.h
+++ b/drivers/video/aty/atyfb.h
@@ -355,5 +355,9 @@ static inline void wait_for_idle(struct atyfb_par *par)
355 355
356extern void aty_reset_engine(const struct atyfb_par *par); 356extern void aty_reset_engine(const struct atyfb_par *par);
357extern void aty_init_engine(struct atyfb_par *par, struct fb_info *info); 357extern void aty_init_engine(struct atyfb_par *par, struct fb_info *info);
358extern void aty_st_pll_ct(int offset, u8 val, const struct atyfb_par *par);
359extern u8 aty_ld_pll_ct(int offset, const struct atyfb_par *par); 358extern u8 aty_ld_pll_ct(int offset, const struct atyfb_par *par);
359
360void atyfb_copyarea(struct fb_info *info, const struct fb_copyarea *area);
361void atyfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
362void atyfb_imageblit(struct fb_info *info, const struct fb_image *image);
363
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index 19a71f045784..b45c9fd1b330 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -240,9 +240,6 @@ static int atyfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
240static int atyfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info); 240static int atyfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info);
241static int atyfb_blank(int blank, struct fb_info *info); 241static int atyfb_blank(int blank, struct fb_info *info);
242static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg); 242static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg);
243extern void atyfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
244extern void atyfb_copyarea(struct fb_info *info, const struct fb_copyarea *area);
245extern void atyfb_imageblit(struct fb_info *info, const struct fb_image *image);
246#ifdef __sparc__ 243#ifdef __sparc__
247static int atyfb_mmap(struct fb_info *info, struct vm_area_struct *vma); 244static int atyfb_mmap(struct fb_info *info, struct vm_area_struct *vma);
248#endif 245#endif
@@ -3863,6 +3860,7 @@ static int __devinit atyfb_setup(char *options)
3863 3860
3864static int __devinit atyfb_init(void) 3861static int __devinit atyfb_init(void)
3865{ 3862{
3863 int err1 = 1, err2 = 1;
3866#ifndef MODULE 3864#ifndef MODULE
3867 char *option = NULL; 3865 char *option = NULL;
3868 3866
@@ -3872,12 +3870,13 @@ static int __devinit atyfb_init(void)
3872#endif 3870#endif
3873 3871
3874#ifdef CONFIG_PCI 3872#ifdef CONFIG_PCI
3875 pci_register_driver(&atyfb_driver); 3873 err1 = pci_register_driver(&atyfb_driver);
3876#endif 3874#endif
3877#ifdef CONFIG_ATARI 3875#ifdef CONFIG_ATARI
3878 atyfb_atari_probe(); 3876 err2 = atyfb_atari_probe();
3879#endif 3877#endif
3880 return 0; 3878
3879 return (err1 && err2) ? -ENODEV : 0;
3881} 3880}
3882 3881
3883static void __exit atyfb_exit(void) 3882static void __exit atyfb_exit(void)
diff --git a/drivers/video/aty/mach64_ct.c b/drivers/video/aty/mach64_ct.c
index e7056934c6a8..5080816be653 100644
--- a/drivers/video/aty/mach64_ct.c
+++ b/drivers/video/aty/mach64_ct.c
@@ -27,7 +27,7 @@ u8 aty_ld_pll_ct(int offset, const struct atyfb_par *par)
27 return res; 27 return res;
28} 28}
29 29
30void aty_st_pll_ct(int offset, u8 val, const struct atyfb_par *par) 30static void aty_st_pll_ct(int offset, u8 val, const struct atyfb_par *par)
31{ 31{
32 /* write addr byte */ 32 /* write addr byte */
33 aty_st_8(CLOCK_CNTL_ADDR, ((offset << 2) & PLL_ADDR) | PLL_WR_EN, par); 33 aty_st_8(CLOCK_CNTL_ADDR, ((offset << 2) & PLL_ADDR) | PLL_WR_EN, par);
diff --git a/drivers/video/aty/radeon_i2c.c b/drivers/video/aty/radeon_i2c.c
index 9aaca58c074a..676754520099 100644
--- a/drivers/video/aty/radeon_i2c.c
+++ b/drivers/video/aty/radeon_i2c.c
@@ -16,8 +16,6 @@
16#include "radeonfb.h" 16#include "radeonfb.h"
17#include "../edid.h" 17#include "../edid.h"
18 18
19#define RADEON_DDC 0x50
20
21static void radeon_gpio_setscl(void* data, int state) 19static void radeon_gpio_setscl(void* data, int state)
22{ 20{
23 struct radeon_i2c_chan *chan = data; 21 struct radeon_i2c_chan *chan = data;
@@ -138,108 +136,10 @@ void radeon_delete_i2c_busses(struct radeonfb_info *rinfo)
138 rinfo->i2c[3].rinfo = NULL; 136 rinfo->i2c[3].rinfo = NULL;
139} 137}
140 138
141 139int radeon_probe_i2c_connector(struct radeonfb_info *rinfo, int conn,
142static u8 *radeon_do_probe_i2c_edid(struct radeon_i2c_chan *chan) 140 u8 **out_edid)
143{
144 u8 start = 0x0;
145 struct i2c_msg msgs[] = {
146 {
147 .addr = RADEON_DDC,
148 .len = 1,
149 .buf = &start,
150 }, {
151 .addr = RADEON_DDC,
152 .flags = I2C_M_RD,
153 .len = EDID_LENGTH,
154 },
155 };
156 u8 *buf;
157
158 buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
159 if (!buf) {
160 dev_warn(&chan->rinfo->pdev->dev, "Out of memory!\n");
161 return NULL;
162 }
163 msgs[1].buf = buf;
164
165 if (i2c_transfer(&chan->adapter, msgs, 2) == 2)
166 return buf;
167 dev_dbg(&chan->rinfo->pdev->dev, "Unable to read EDID block.\n");
168 kfree(buf);
169 return NULL;
170}
171
172
173int radeon_probe_i2c_connector(struct radeonfb_info *rinfo, int conn, u8 **out_edid)
174{ 141{
175 u32 reg = rinfo->i2c[conn-1].ddc_reg; 142 u8 *edid = fb_ddc_read(&rinfo->i2c[conn-1].adapter);
176 u8 *edid = NULL;
177 int i, j;
178
179 OUTREG(reg, INREG(reg) &
180 ~(VGA_DDC_DATA_OUTPUT | VGA_DDC_CLK_OUTPUT));
181
182 OUTREG(reg, INREG(reg) & ~(VGA_DDC_CLK_OUT_EN));
183 (void)INREG(reg);
184
185 for (i = 0; i < 3; i++) {
186 /* For some old monitors we need the
187 * following process to initialize/stop DDC
188 */
189 OUTREG(reg, INREG(reg) & ~(VGA_DDC_DATA_OUT_EN));
190 (void)INREG(reg);
191 msleep(13);
192
193 OUTREG(reg, INREG(reg) & ~(VGA_DDC_CLK_OUT_EN));
194 (void)INREG(reg);
195 for (j = 0; j < 5; j++) {
196 msleep(10);
197 if (INREG(reg) & VGA_DDC_CLK_INPUT)
198 break;
199 }
200 if (j == 5)
201 continue;
202
203 OUTREG(reg, INREG(reg) | VGA_DDC_DATA_OUT_EN);
204 (void)INREG(reg);
205 msleep(15);
206 OUTREG(reg, INREG(reg) | VGA_DDC_CLK_OUT_EN);
207 (void)INREG(reg);
208 msleep(15);
209 OUTREG(reg, INREG(reg) & ~(VGA_DDC_DATA_OUT_EN));
210 (void)INREG(reg);
211 msleep(15);
212
213 /* Do the real work */
214 edid = radeon_do_probe_i2c_edid(&rinfo->i2c[conn-1]);
215
216 OUTREG(reg, INREG(reg) |
217 (VGA_DDC_DATA_OUT_EN | VGA_DDC_CLK_OUT_EN));
218 (void)INREG(reg);
219 msleep(15);
220
221 OUTREG(reg, INREG(reg) & ~(VGA_DDC_CLK_OUT_EN));
222 (void)INREG(reg);
223 for (j = 0; j < 10; j++) {
224 msleep(10);
225 if (INREG(reg) & VGA_DDC_CLK_INPUT)
226 break;
227 }
228
229 OUTREG(reg, INREG(reg) & ~(VGA_DDC_DATA_OUT_EN));
230 (void)INREG(reg);
231 msleep(15);
232 OUTREG(reg, INREG(reg) |
233 (VGA_DDC_DATA_OUT_EN | VGA_DDC_CLK_OUT_EN));
234 (void)INREG(reg);
235 if (edid)
236 break;
237 }
238 /* Release the DDC lines when done or the Apple Cinema HD display
239 * will switch off
240 */
241 OUTREG(reg, INREG(reg) & ~(VGA_DDC_CLK_OUT_EN | VGA_DDC_DATA_OUT_EN));
242 (void)INREG(reg);
243 143
244 if (out_edid) 144 if (out_edid)
245 *out_edid = edid; 145 *out_edid = edid;
diff --git a/drivers/video/aty/radeon_pm.c b/drivers/video/aty/radeon_pm.c
index e308ed2d249a..9a2b0d69b0ae 100644
--- a/drivers/video/aty/radeon_pm.c
+++ b/drivers/video/aty/radeon_pm.c
@@ -86,6 +86,9 @@ static struct radeon_device_id radeon_workaround_list[] = {
86 BUGFIX("Samsung P35", 86 BUGFIX("Samsung P35",
87 PCI_VENDOR_ID_SAMSUNG, 0xc00c, 87 PCI_VENDOR_ID_SAMSUNG, 0xc00c,
88 radeon_pm_off, radeon_reinitialize_M10), 88 radeon_pm_off, radeon_reinitialize_M10),
89 BUGFIX("Acer Aspire 2010",
90 PCI_VENDOR_ID_AI, 0x0061,
91 radeon_pm_off, radeon_reinitialize_M10),
89 { .ident = NULL } 92 { .ident = NULL }
90}; 93};
91 94
@@ -2621,25 +2624,28 @@ static int radeon_restore_pci_cfg(struct radeonfb_info *rinfo)
2621} 2624}
2622 2625
2623 2626
2624int radeonfb_pci_suspend(struct pci_dev *pdev, pm_message_t state) 2627int radeonfb_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
2625{ 2628{
2626 struct fb_info *info = pci_get_drvdata(pdev); 2629 struct fb_info *info = pci_get_drvdata(pdev);
2627 struct radeonfb_info *rinfo = info->par; 2630 struct radeonfb_info *rinfo = info->par;
2628 int i; 2631 int i;
2629 2632
2630 if (state.event == pdev->dev.power.power_state.event) 2633 if (mesg.event == pdev->dev.power.power_state.event)
2631 return 0; 2634 return 0;
2632 2635
2633 printk(KERN_DEBUG "radeonfb (%s): suspending to state: %d...\n", 2636 printk(KERN_DEBUG "radeonfb (%s): suspending for event: %d...\n",
2634 pci_name(pdev), state.event); 2637 pci_name(pdev), mesg.event);
2635 2638
2636 /* For suspend-to-disk, we cheat here. We don't suspend anything and 2639 /* For suspend-to-disk, we cheat here. We don't suspend anything and
2637 * let fbcon continue drawing until we are all set. That shouldn't 2640 * let fbcon continue drawing until we are all set. That shouldn't
2638 * really cause any problem at this point, provided that the wakeup 2641 * really cause any problem at this point, provided that the wakeup
2639 * code knows that any state in memory may not match the HW 2642 * code knows that any state in memory may not match the HW
2640 */ 2643 */
2641 if (state.event == PM_EVENT_FREEZE) 2644 switch (mesg.event) {
2645 case PM_EVENT_FREEZE: /* about to take snapshot */
2646 case PM_EVENT_PRETHAW: /* before restoring snapshot */
2642 goto done; 2647 goto done;
2648 }
2643 2649
2644 acquire_console_sem(); 2650 acquire_console_sem();
2645 2651
@@ -2706,7 +2712,7 @@ int radeonfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2706 release_console_sem(); 2712 release_console_sem();
2707 2713
2708 done: 2714 done:
2709 pdev->dev.power.power_state = state; 2715 pdev->dev.power.power_state = mesg;
2710 2716
2711 return 0; 2717 return 0;
2712} 2718}
diff --git a/drivers/video/au1100fb.c b/drivers/video/au1100fb.c
index f25d5d648333..ef5c16f7f5a6 100644
--- a/drivers/video/au1100fb.c
+++ b/drivers/video/au1100fb.c
@@ -8,6 +8,7 @@
8 * <c.pellegrin@exadron.com> 8 * <c.pellegrin@exadron.com>
9 * 9 *
10 * PM support added by Rodolfo Giometti <giometti@linux.it> 10 * PM support added by Rodolfo Giometti <giometti@linux.it>
11 * Cursor enable/disable by Rodolfo Giometti <giometti@linux.it>
11 * 12 *
12 * Copyright 2002 MontaVista Software 13 * Copyright 2002 MontaVista Software
13 * Author: MontaVista Software, Inc. 14 * Author: MontaVista Software, Inc.
@@ -110,6 +111,10 @@ static struct fb_var_screeninfo au1100fb_var __initdata = {
110 111
111static struct au1100fb_drv_info drv_info; 112static struct au1100fb_drv_info drv_info;
112 113
114static int nocursor = 0;
115module_param(nocursor, int, 0644);
116MODULE_PARM_DESC(nocursor, "cursor enable/disable");
117
113/* 118/*
114 * Set hardware with var settings. This will enable the controller with a specific 119 * Set hardware with var settings. This will enable the controller with a specific
115 * mode, normally validated with the fb_check_var method 120 * mode, normally validated with the fb_check_var method
@@ -422,6 +427,17 @@ int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
422 return 0; 427 return 0;
423} 428}
424 429
430/* fb_cursor
431 * Used to disable cursor drawing...
432 */
433int au1100fb_fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
434{
435 if (nocursor)
436 return 0;
437 else
438 return -EINVAL; /* just to force soft_cursor() call */
439}
440
425static struct fb_ops au1100fb_ops = 441static struct fb_ops au1100fb_ops =
426{ 442{
427 .owner = THIS_MODULE, 443 .owner = THIS_MODULE,
@@ -433,6 +449,7 @@ static struct fb_ops au1100fb_ops =
433 .fb_imageblit = cfb_imageblit, 449 .fb_imageblit = cfb_imageblit,
434 .fb_rotate = au1100fb_fb_rotate, 450 .fb_rotate = au1100fb_fb_rotate,
435 .fb_mmap = au1100fb_fb_mmap, 451 .fb_mmap = au1100fb_fb_mmap,
452 .fb_cursor = au1100fb_fb_cursor,
436}; 453};
437 454
438 455
@@ -677,7 +694,7 @@ int au1100fb_setup(char *options)
677 if (options) { 694 if (options) {
678 while ((this_opt = strsep(&options,",")) != NULL) { 695 while ((this_opt = strsep(&options,",")) != NULL) {
679 /* Panel option */ 696 /* Panel option */
680 if (!strncmp(this_opt, "panel:", 6)) { 697 if (!strncmp(this_opt, "panel:", 6)) {
681 int i; 698 int i;
682 this_opt += 6; 699 this_opt += 6;
683 for (i = 0; i < num_panels; i++) { 700 for (i = 0; i < num_panels; i++) {
@@ -685,13 +702,18 @@ int au1100fb_setup(char *options)
685 known_lcd_panels[i].name, 702 known_lcd_panels[i].name,
686 strlen(this_opt))) { 703 strlen(this_opt))) {
687 panel_idx = i; 704 panel_idx = i;
688 break; 705 break;
706 }
689 } 707 }
690 }
691 if (i >= num_panels) { 708 if (i >= num_panels) {
692 print_warn("Panel %s not supported!", this_opt); 709 print_warn("Panel %s not supported!", this_opt);
693 } 710 }
694 } 711 }
712 if (!strncmp(this_opt, "nocursor", 8)) {
713 this_opt += 8;
714 nocursor = 1;
715 print_info("Cursor disabled");
716 }
695 /* Mode option (only option that start with digit) */ 717 /* Mode option (only option that start with digit) */
696 else if (isdigit(this_opt[0])) { 718 else if (isdigit(this_opt[0])) {
697 mode = kmalloc(strlen(this_opt) + 1, GFP_KERNEL); 719 mode = kmalloc(strlen(this_opt) + 1, GFP_KERNEL);
@@ -700,7 +722,7 @@ int au1100fb_setup(char *options)
700 /* Unsupported option */ 722 /* Unsupported option */
701 else { 723 else {
702 print_warn("Unsupported option \"%s\"", this_opt); 724 print_warn("Unsupported option \"%s\"", this_opt);
703 } 725 }
704 } 726 }
705 } 727 }
706 728
diff --git a/drivers/video/backlight/hp680_bl.c b/drivers/video/backlight/hp680_bl.c
index ffc72ae3ada8..fe1488374f62 100644
--- a/drivers/video/backlight/hp680_bl.c
+++ b/drivers/video/backlight/hp680_bl.c
@@ -20,7 +20,7 @@
20 20
21#include <asm/cpu/dac.h> 21#include <asm/cpu/dac.h>
22#include <asm/hp6xx/hp6xx.h> 22#include <asm/hp6xx/hp6xx.h>
23#include <asm/hd64461/hd64461.h> 23#include <asm/hd64461.h>
24 24
25#define HP680_MAX_INTENSITY 255 25#define HP680_MAX_INTENSITY 255
26#define HP680_DEFAULT_INTENSITY 10 26#define HP680_DEFAULT_INTENSITY 10
@@ -163,6 +163,6 @@ static void __exit hp680bl_exit(void)
163module_init(hp680bl_init); 163module_init(hp680bl_init);
164module_exit(hp680bl_exit); 164module_exit(hp680bl_exit);
165 165
166MODULE_AUTHOR("Andriy Skulysh <askulysh@image.kiev.ua>"); 166MODULE_AUTHOR("Andriy Skulysh <askulysh@gmail.com>");
167MODULE_DESCRIPTION("HP Jornada 680 Backlight Driver"); 167MODULE_DESCRIPTION("HP Jornada 680 Backlight Driver");
168MODULE_LICENSE("GPL"); 168MODULE_LICENSE("GPL");
diff --git a/drivers/video/backlight/locomolcd.c b/drivers/video/backlight/locomolcd.c
index caf1eca199b0..628571c63bac 100644
--- a/drivers/video/backlight/locomolcd.c
+++ b/drivers/video/backlight/locomolcd.c
@@ -33,19 +33,19 @@ static unsigned long locomolcd_flags;
33 33
34static void locomolcd_on(int comadj) 34static void locomolcd_on(int comadj)
35{ 35{
36 locomo_gpio_set_dir(locomolcd_dev, LOCOMO_GPIO_LCD_VSHA_ON, 0); 36 locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHA_ON, 0);
37 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VSHA_ON, 1); 37 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHA_ON, 1);
38 mdelay(2); 38 mdelay(2);
39 39
40 locomo_gpio_set_dir(locomolcd_dev, LOCOMO_GPIO_LCD_VSHD_ON, 0); 40 locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHD_ON, 0);
41 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VSHD_ON, 1); 41 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHD_ON, 1);
42 mdelay(2); 42 mdelay(2);
43 43
44 locomo_m62332_senddata(locomolcd_dev, comadj, 0); 44 locomo_m62332_senddata(locomolcd_dev, comadj, 0);
45 mdelay(5); 45 mdelay(5);
46 46
47 locomo_gpio_set_dir(locomolcd_dev, LOCOMO_GPIO_LCD_VEE_ON, 0); 47 locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VEE_ON, 0);
48 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VEE_ON, 1); 48 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VEE_ON, 1);
49 mdelay(10); 49 mdelay(10);
50 50
51 /* TFTCRST | CPSOUT=0 | CPSEN */ 51 /* TFTCRST | CPSOUT=0 | CPSEN */
@@ -58,8 +58,8 @@ static void locomolcd_on(int comadj)
58 locomo_writel((0x04 | 0x01), locomolcd_dev->mapbase + LOCOMO_TC); 58 locomo_writel((0x04 | 0x01), locomolcd_dev->mapbase + LOCOMO_TC);
59 mdelay(10); 59 mdelay(10);
60 60
61 locomo_gpio_set_dir(locomolcd_dev, LOCOMO_GPIO_LCD_MOD, 0); 61 locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_MOD, 0);
62 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_MOD, 1); 62 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_MOD, 1);
63} 63}
64 64
65static void locomolcd_off(int comadj) 65static void locomolcd_off(int comadj)
@@ -68,16 +68,16 @@ static void locomolcd_off(int comadj)
68 locomo_writel(0x06, locomolcd_dev->mapbase + LOCOMO_TC); 68 locomo_writel(0x06, locomolcd_dev->mapbase + LOCOMO_TC);
69 mdelay(1); 69 mdelay(1);
70 70
71 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VSHA_ON, 0); 71 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHA_ON, 0);
72 mdelay(110); 72 mdelay(110);
73 73
74 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VEE_ON, 0); 74 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VEE_ON, 0);
75 mdelay(700); 75 mdelay(700);
76 76
77 /* TFTCRST=0 | CPSOUT=0 | CPSEN = 0 */ 77 /* TFTCRST=0 | CPSOUT=0 | CPSEN = 0 */
78 locomo_writel(0, locomolcd_dev->mapbase + LOCOMO_TC); 78 locomo_writel(0, locomolcd_dev->mapbase + LOCOMO_TC);
79 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_MOD, 0); 79 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_MOD, 0);
80 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VSHD_ON, 0); 80 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHD_ON, 0);
81} 81}
82 82
83void locomolcd_power(int on) 83void locomolcd_power(int on)
@@ -167,14 +167,14 @@ static int locomolcd_resume(struct locomo_dev *dev)
167#define locomolcd_resume NULL 167#define locomolcd_resume NULL
168#endif 168#endif
169 169
170static int locomolcd_probe(struct locomo_dev *dev) 170static int locomolcd_probe(struct locomo_dev *ldev)
171{ 171{
172 unsigned long flags; 172 unsigned long flags;
173 173
174 local_irq_save(flags); 174 local_irq_save(flags);
175 locomolcd_dev = dev; 175 locomolcd_dev = ldev;
176 176
177 locomo_gpio_set_dir(dev, LOCOMO_GPIO_FL_VR, 0); 177 locomo_gpio_set_dir(ldev->dev.parent, LOCOMO_GPIO_FL_VR, 0);
178 178
179 /* the poodle_lcd_power function is called for the first time 179 /* the poodle_lcd_power function is called for the first time
180 * from fs_initcall, which is before locomo is activated. 180 * from fs_initcall, which is before locomo is activated.
diff --git a/drivers/video/console/Kconfig b/drivers/video/console/Kconfig
index 4444bef68fba..aa3935df852a 100644
--- a/drivers/video/console/Kconfig
+++ b/drivers/video/console/Kconfig
@@ -6,7 +6,7 @@ menu "Console display driver support"
6 6
7config VGA_CONSOLE 7config VGA_CONSOLE
8 bool "VGA text console" if EMBEDDED || !X86 8 bool "VGA text console" if EMBEDDED || !X86
9 depends on !ARCH_ACORN && !ARCH_EBSA110 && !4xx && !8xx && !SPARC && !M68K && !PARISC && !FRV && !ARCH_VERSATILE 9 depends on !ARCH_ACORN && !ARCH_EBSA110 && !4xx && !8xx && !SPARC && !M68K && !PARISC && !FRV && !ARCH_VERSATILE && !SUPERH
10 default y 10 default y
11 help 11 help
12 Saying Y here will allow you to use Linux in text mode through a 12 Saying Y here will allow you to use Linux in text mode through a
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index 1b4f75d1f8a9..8c041daa3a15 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -133,6 +133,7 @@ static int info_idx = -1;
133 133
134/* console rotation */ 134/* console rotation */
135static int rotate; 135static int rotate;
136static int fbcon_has_sysfs;
136 137
137static const struct consw fb_con; 138static const struct consw fb_con;
138 139
@@ -396,9 +397,8 @@ static void fb_flashcursor(void *private)
396 vc = vc_cons[ops->currcon].d; 397 vc = vc_cons[ops->currcon].d;
397 398
398 if (!vc || !CON_IS_VISIBLE(vc) || 399 if (!vc || !CON_IS_VISIBLE(vc) ||
399 fbcon_is_inactive(vc, info) ||
400 registered_fb[con2fb_map[vc->vc_num]] != info || 400 registered_fb[con2fb_map[vc->vc_num]] != info ||
401 vc_cons[ops->currcon].d->vc_deccm != 1) { 401 vc->vc_deccm != 1) {
402 release_console_sem(); 402 release_console_sem();
403 return; 403 return;
404 } 404 }
@@ -2166,7 +2166,12 @@ static int fbcon_switch(struct vc_data *vc)
2166 fbcon_del_cursor_timer(old_info); 2166 fbcon_del_cursor_timer(old_info);
2167 } 2167 }
2168 2168
2169 fbcon_add_cursor_timer(info); 2169 if (fbcon_is_inactive(vc, info) ||
2170 ops->blank_state != FB_BLANK_UNBLANK)
2171 fbcon_del_cursor_timer(info);
2172 else
2173 fbcon_add_cursor_timer(info);
2174
2170 set_blitting_type(vc, info); 2175 set_blitting_type(vc, info);
2171 ops->cursor_reset = 1; 2176 ops->cursor_reset = 1;
2172 2177
@@ -2276,10 +2281,11 @@ static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2276 update_screen(vc); 2281 update_screen(vc);
2277 } 2282 }
2278 2283
2279 if (!blank) 2284 if (fbcon_is_inactive(vc, info) ||
2280 fbcon_add_cursor_timer(info); 2285 ops->blank_state != FB_BLANK_UNBLANK)
2281 else
2282 fbcon_del_cursor_timer(info); 2286 fbcon_del_cursor_timer(info);
2287 else
2288 fbcon_add_cursor_timer(info);
2283 2289
2284 return 0; 2290 return 0;
2285} 2291}
@@ -3161,11 +3167,26 @@ static struct class_device_attribute class_device_attrs[] = {
3161 3167
3162static int fbcon_init_class_device(void) 3168static int fbcon_init_class_device(void)
3163{ 3169{
3164 int i; 3170 int i, error = 0;
3171
3172 fbcon_has_sysfs = 1;
3173
3174 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) {
3175 error = class_device_create_file(fbcon_class_device,
3176 &class_device_attrs[i]);
3177
3178 if (error)
3179 break;
3180 }
3181
3182 if (error) {
3183 while (--i >= 0)
3184 class_device_remove_file(fbcon_class_device,
3185 &class_device_attrs[i]);
3186
3187 fbcon_has_sysfs = 0;
3188 }
3165 3189
3166 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
3167 class_device_create_file(fbcon_class_device,
3168 &class_device_attrs[i]);
3169 return 0; 3190 return 0;
3170} 3191}
3171 3192
@@ -3225,7 +3246,10 @@ static void fbcon_exit(void)
3225 module_put(info->fbops->owner); 3246 module_put(info->fbops->owner);
3226 3247
3227 if (info->fbcon_par) { 3248 if (info->fbcon_par) {
3249 struct fbcon_ops *ops = info->fbcon_par;
3250
3228 fbcon_del_cursor_timer(info); 3251 fbcon_del_cursor_timer(info);
3252 kfree(ops->cursor_src);
3229 kfree(info->fbcon_par); 3253 kfree(info->fbcon_par);
3230 info->fbcon_par = NULL; 3254 info->fbcon_par = NULL;
3231 } 3255 }
@@ -3271,9 +3295,13 @@ static void __exit fbcon_deinit_class_device(void)
3271{ 3295{
3272 int i; 3296 int i;
3273 3297
3274 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) 3298 if (fbcon_has_sysfs) {
3275 class_device_remove_file(fbcon_class_device, 3299 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
3276 &class_device_attrs[i]); 3300 class_device_remove_file(fbcon_class_device,
3301 &class_device_attrs[i]);
3302
3303 fbcon_has_sysfs = 0;
3304 }
3277} 3305}
3278 3306
3279static void __exit fb_console_exit(void) 3307static void __exit fb_console_exit(void)
diff --git a/drivers/video/console/fbcon.h b/drivers/video/console/fbcon.h
index f244ad066d68..b9386d168c04 100644
--- a/drivers/video/console/fbcon.h
+++ b/drivers/video/console/fbcon.h
@@ -80,6 +80,8 @@ struct fbcon_ops {
80 char *cursor_data; 80 char *cursor_data;
81 u8 *fontbuffer; 81 u8 *fontbuffer;
82 u8 *fontdata; 82 u8 *fontdata;
83 u8 *cursor_src;
84 u32 cursor_size;
83 u32 fd_size; 85 u32 fd_size;
84}; 86};
85 /* 87 /*
diff --git a/drivers/video/console/fbcon_ccw.c b/drivers/video/console/fbcon_ccw.c
index 4481c80b8b2a..825e6d6972a7 100644
--- a/drivers/video/console/fbcon_ccw.c
+++ b/drivers/video/console/fbcon_ccw.c
@@ -391,7 +391,7 @@ static void ccw_cursor(struct vc_data *vc, struct fb_info *info, int mode,
391 ops->cursor_reset = 0; 391 ops->cursor_reset = 0;
392} 392}
393 393
394int ccw_update_start(struct fb_info *info) 394static int ccw_update_start(struct fb_info *info)
395{ 395{
396 struct fbcon_ops *ops = info->fbcon_par; 396 struct fbcon_ops *ops = info->fbcon_par;
397 u32 yoffset; 397 u32 yoffset;
diff --git a/drivers/video/console/fbcon_cw.c b/drivers/video/console/fbcon_cw.c
index 7f92c06afea7..c637e6318803 100644
--- a/drivers/video/console/fbcon_cw.c
+++ b/drivers/video/console/fbcon_cw.c
@@ -375,7 +375,7 @@ static void cw_cursor(struct vc_data *vc, struct fb_info *info, int mode,
375 ops->cursor_reset = 0; 375 ops->cursor_reset = 0;
376} 376}
377 377
378int cw_update_start(struct fb_info *info) 378static int cw_update_start(struct fb_info *info)
379{ 379{
380 struct fbcon_ops *ops = info->fbcon_par; 380 struct fbcon_ops *ops = info->fbcon_par;
381 u32 vxres = GETVXRES(ops->p->scrollmode, info); 381 u32 vxres = GETVXRES(ops->p->scrollmode, info);
diff --git a/drivers/video/console/fbcon_ud.c b/drivers/video/console/fbcon_ud.c
index ab91005e64dc..1473506df5d0 100644
--- a/drivers/video/console/fbcon_ud.c
+++ b/drivers/video/console/fbcon_ud.c
@@ -415,7 +415,7 @@ static void ud_cursor(struct vc_data *vc, struct fb_info *info, int mode,
415 ops->cursor_reset = 0; 415 ops->cursor_reset = 0;
416} 416}
417 417
418int ud_update_start(struct fb_info *info) 418static int ud_update_start(struct fb_info *info)
419{ 419{
420 struct fbcon_ops *ops = info->fbcon_par; 420 struct fbcon_ops *ops = info->fbcon_par;
421 int xoffset, yoffset; 421 int xoffset, yoffset;
diff --git a/drivers/video/console/softcursor.c b/drivers/video/console/softcursor.c
index 557c563e4aed..7d07d8383569 100644
--- a/drivers/video/console/softcursor.c
+++ b/drivers/video/console/softcursor.c
@@ -20,11 +20,12 @@
20 20
21int soft_cursor(struct fb_info *info, struct fb_cursor *cursor) 21int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
22{ 22{
23 struct fbcon_ops *ops = info->fbcon_par;
23 unsigned int scan_align = info->pixmap.scan_align - 1; 24 unsigned int scan_align = info->pixmap.scan_align - 1;
24 unsigned int buf_align = info->pixmap.buf_align - 1; 25 unsigned int buf_align = info->pixmap.buf_align - 1;
25 unsigned int i, size, dsize, s_pitch, d_pitch; 26 unsigned int i, size, dsize, s_pitch, d_pitch;
26 struct fb_image *image; 27 struct fb_image *image;
27 u8 *dst, *src; 28 u8 *dst;
28 29
29 if (info->state != FBINFO_STATE_RUNNING) 30 if (info->state != FBINFO_STATE_RUNNING)
30 return 0; 31 return 0;
@@ -32,11 +33,19 @@ int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
32 s_pitch = (cursor->image.width + 7) >> 3; 33 s_pitch = (cursor->image.width + 7) >> 3;
33 dsize = s_pitch * cursor->image.height; 34 dsize = s_pitch * cursor->image.height;
34 35
35 src = kmalloc(dsize + sizeof(struct fb_image), GFP_ATOMIC); 36 if (dsize + sizeof(struct fb_image) != ops->cursor_size) {
36 if (!src) 37 if (ops->cursor_src != NULL)
37 return -ENOMEM; 38 kfree(ops->cursor_src);
39 ops->cursor_size = dsize + sizeof(struct fb_image);
38 40
39 image = (struct fb_image *) (src + dsize); 41 ops->cursor_src = kmalloc(ops->cursor_size, GFP_ATOMIC);
42 if (!ops->cursor_src) {
43 ops->cursor_size = 0;
44 return -ENOMEM;
45 }
46 }
47
48 image = (struct fb_image *) (ops->cursor_src + dsize);
40 *image = cursor->image; 49 *image = cursor->image;
41 d_pitch = (s_pitch + scan_align) & ~scan_align; 50 d_pitch = (s_pitch + scan_align) & ~scan_align;
42 51
@@ -48,21 +57,23 @@ int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
48 switch (cursor->rop) { 57 switch (cursor->rop) {
49 case ROP_XOR: 58 case ROP_XOR:
50 for (i = 0; i < dsize; i++) 59 for (i = 0; i < dsize; i++)
51 src[i] = image->data[i] ^ cursor->mask[i]; 60 ops->cursor_src[i] = image->data[i] ^
61 cursor->mask[i];
52 break; 62 break;
53 case ROP_COPY: 63 case ROP_COPY:
54 default: 64 default:
55 for (i = 0; i < dsize; i++) 65 for (i = 0; i < dsize; i++)
56 src[i] = image->data[i] & cursor->mask[i]; 66 ops->cursor_src[i] = image->data[i] &
67 cursor->mask[i];
57 break; 68 break;
58 } 69 }
59 } else 70 } else
60 memcpy(src, image->data, dsize); 71 memcpy(ops->cursor_src, image->data, dsize);
61 72
62 fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, image->height); 73 fb_pad_aligned_buffer(dst, d_pitch, ops->cursor_src, s_pitch,
74 image->height);
63 image->data = dst; 75 image->data = dst;
64 info->fbops->fb_imageblit(info, image); 76 info->fbops->fb_imageblit(info, image);
65 kfree(src);
66 return 0; 77 return 0;
67} 78}
68 79
diff --git a/drivers/video/fb_ddc.c b/drivers/video/fb_ddc.c
new file mode 100644
index 000000000000..3aa6ebf68f17
--- /dev/null
+++ b/drivers/video/fb_ddc.c
@@ -0,0 +1,116 @@
1/*
2 * driver/vide/fb_ddc.c - DDC/EDID read support.
3 *
4 * Copyright (C) 2006 Dennis Munsie <dmunsie@cecropia.com>
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/delay.h>
12#include <linux/device.h>
13#include <linux/fb.h>
14#include <linux/i2c-algo-bit.h>
15
16#include "edid.h"
17
18#define DDC_ADDR 0x50
19
20static unsigned char *fb_do_probe_ddc_edid(struct i2c_adapter *adapter)
21{
22 unsigned char start = 0x0;
23 struct i2c_msg msgs[] = {
24 {
25 .addr = DDC_ADDR,
26 .len = 1,
27 .buf = &start,
28 }, {
29 .addr = DDC_ADDR,
30 .flags = I2C_M_RD,
31 .len = EDID_LENGTH,
32 }
33 };
34 unsigned char *buf;
35
36 buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
37 if (!buf) {
38 dev_warn(&adapter->dev, "unable to allocate memory for EDID "
39 "block.\n");
40 return NULL;
41 }
42 msgs[1].buf = buf;
43
44 if (i2c_transfer(adapter, msgs, 2) == 2)
45 return buf;
46
47 dev_warn(&adapter->dev, "unable to read EDID block.\n");
48 kfree(buf);
49 return NULL;
50}
51
52unsigned char *fb_ddc_read(struct i2c_adapter *adapter)
53{
54 struct i2c_algo_bit_data *algo_data = adapter->algo_data;
55 unsigned char *edid = NULL;
56 int i, j;
57
58 algo_data->setscl(algo_data->data, 1);
59 algo_data->setscl(algo_data->data, 0);
60
61 for (i = 0; i < 3; i++) {
62 /* For some old monitors we need the
63 * following process to initialize/stop DDC
64 */
65 algo_data->setsda(algo_data->data, 0);
66 msleep(13);
67
68 algo_data->setscl(algo_data->data, 1);
69 for (j = 0; j < 5; j++) {
70 msleep(10);
71 if (algo_data->getscl(algo_data->data))
72 break;
73 }
74 if (j == 5)
75 continue;
76
77 algo_data->setsda(algo_data->data, 0);
78 msleep(15);
79 algo_data->setscl(algo_data->data, 0);
80 msleep(15);
81 algo_data->setsda(algo_data->data, 1);
82 msleep(15);
83
84 /* Do the real work */
85 edid = fb_do_probe_ddc_edid(adapter);
86 algo_data->setsda(algo_data->data, 0);
87 algo_data->setscl(algo_data->data, 0);
88 msleep(15);
89
90 algo_data->setscl(algo_data->data, 1);
91 for (j = 0; j < 10; j++) {
92 msleep(10);
93 if (algo_data->getscl(algo_data->data))
94 break;
95 }
96
97 algo_data->setsda(algo_data->data, 1);
98 msleep(15);
99 algo_data->setscl(algo_data->data, 0);
100 if (edid)
101 break;
102 }
103 /* Release the DDC lines when done or the Apple Cinema HD display
104 * will switch off
105 */
106 algo_data->setsda(algo_data->data, 0);
107 algo_data->setscl(algo_data->data, 0);
108
109 return edid;
110}
111
112EXPORT_SYMBOL_GPL(fb_ddc_read);
113
114MODULE_AUTHOR("Dennis Munsie <dmunsie@cecropia.com>");
115MODULE_DESCRIPTION("DDC/EDID reading support");
116MODULE_LICENSE("GPL");
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index 17961e3ecaa0..93ffcdd95f50 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -554,7 +554,8 @@ static int fbmem_read_proc(char *buf, char **start, off_t offset,
554 int clen; 554 int clen;
555 555
556 clen = 0; 556 clen = 0;
557 for (fi = registered_fb; fi < &registered_fb[FB_MAX] && len < 4000; fi++) 557 for (fi = registered_fb; fi < &registered_fb[FB_MAX] && clen < 4000;
558 fi++)
558 if (*fi) 559 if (*fi)
559 clen += sprintf(buf + clen, "%d %s\n", 560 clen += sprintf(buf + clen, "%d %s\n",
560 (*fi)->node, 561 (*fi)->node,
diff --git a/drivers/video/fbsysfs.c b/drivers/video/fbsysfs.c
index c151dcf68786..d3a50417ed9a 100644
--- a/drivers/video/fbsysfs.c
+++ b/drivers/video/fbsysfs.c
@@ -20,6 +20,8 @@
20#include <linux/console.h> 20#include <linux/console.h>
21#include <linux/module.h> 21#include <linux/module.h>
22 22
23#define FB_SYSFS_FLAG_ATTR 1
24
23/** 25/**
24 * framebuffer_alloc - creates a new frame buffer info structure 26 * framebuffer_alloc - creates a new frame buffer info structure
25 * 27 *
@@ -483,12 +485,27 @@ static struct class_device_attribute class_device_attrs[] = {
483 485
484int fb_init_class_device(struct fb_info *fb_info) 486int fb_init_class_device(struct fb_info *fb_info)
485{ 487{
486 unsigned int i; 488 int i, error = 0;
489
487 class_set_devdata(fb_info->class_device, fb_info); 490 class_set_devdata(fb_info->class_device, fb_info);
488 491
489 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) 492 fb_info->class_flag |= FB_SYSFS_FLAG_ATTR;
490 class_device_create_file(fb_info->class_device, 493
491 &class_device_attrs[i]); 494 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) {
495 error = class_device_create_file(fb_info->class_device,
496 &class_device_attrs[i]);
497
498 if (error)
499 break;
500 }
501
502 if (error) {
503 while (--i >= 0)
504 class_device_remove_file(fb_info->class_device,
505 &class_device_attrs[i]);
506 fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR;
507 }
508
492 return 0; 509 return 0;
493} 510}
494 511
@@ -496,9 +513,13 @@ void fb_cleanup_class_device(struct fb_info *fb_info)
496{ 513{
497 unsigned int i; 514 unsigned int i;
498 515
499 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) 516 if (fb_info->class_flag & FB_SYSFS_FLAG_ATTR) {
500 class_device_remove_file(fb_info->class_device, 517 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
501 &class_device_attrs[i]); 518 class_device_remove_file(fb_info->class_device,
519 &class_device_attrs[i]);
520
521 fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR;
522 }
502} 523}
503 524
504#ifdef CONFIG_FB_BACKLIGHT 525#ifdef CONFIG_FB_BACKLIGHT
diff --git a/drivers/video/hitfb.c b/drivers/video/hitfb.c
index 4cc6b454265e..3afb472763c0 100644
--- a/drivers/video/hitfb.c
+++ b/drivers/video/hitfb.c
@@ -4,7 +4,7 @@
4 * (C) 1999 Mihai Spatar 4 * (C) 1999 Mihai Spatar
5 * (C) 2000 YAEGASHI Takeshi 5 * (C) 2000 YAEGASHI Takeshi
6 * (C) 2003, 2004 Paul Mundt 6 * (C) 2003, 2004 Paul Mundt
7 * (C) 2003, 2004 Andriy Skulysh 7 * (C) 2003, 2004, 2006 Andriy Skulysh
8 * 8 *
9 * This file is subject to the terms and conditions of the GNU General Public 9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of this archive for 10 * License. See the file COPYING in the main directory of this archive for
@@ -20,18 +20,16 @@
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/platform_device.h>
23#include <linux/fb.h> 24#include <linux/fb.h>
24 25
25#include <asm/machvec.h> 26#include <asm/machvec.h>
26#include <asm/uaccess.h> 27#include <asm/uaccess.h>
27#include <asm/pgtable.h> 28#include <asm/pgtable.h>
28#include <asm/io.h> 29#include <asm/io.h>
29#include <asm/hd64461/hd64461.h> 30#include <asm/hd64461.h>
30
31#ifdef MACH_HP600
32#include <asm/cpu/dac.h> 31#include <asm/cpu/dac.h>
33#include <asm/hp6xx/hp6xx.h> 32#include <asm/hp6xx/hp6xx.h>
34#endif
35 33
36#define WIDTH 640 34#define WIDTH 640
37 35
@@ -45,7 +43,6 @@ static struct fb_var_screeninfo hitfb_var __initdata = {
45static struct fb_fix_screeninfo hitfb_fix __initdata = { 43static struct fb_fix_screeninfo hitfb_fix __initdata = {
46 .id = "Hitachi HD64461", 44 .id = "Hitachi HD64461",
47 .type = FB_TYPE_PACKED_PIXELS, 45 .type = FB_TYPE_PACKED_PIXELS,
48 .ypanstep = 8,
49 .accel = FB_ACCEL_NONE, 46 .accel = FB_ACCEL_NONE,
50}; 47};
51 48
@@ -73,26 +70,14 @@ static inline void hitfb_accel_set_dest(int truecolor, u16 dx, u16 dy,
73 if (truecolor) 70 if (truecolor)
74 saddr <<= 1; 71 saddr <<= 1;
75 72
76 fb_writew(width, HD64461_BBTDWR); 73 fb_writew(width-1, HD64461_BBTDWR);
77 fb_writew(height, HD64461_BBTDHR); 74 fb_writew(height-1, HD64461_BBTDHR);
78 75
79 fb_writew(saddr & 0xffff, HD64461_BBTDSARL); 76 fb_writew(saddr & 0xffff, HD64461_BBTDSARL);
80 fb_writew(saddr >> 16, HD64461_BBTDSARH); 77 fb_writew(saddr >> 16, HD64461_BBTDSARH);
81 78
82} 79}
83 80
84static inline void hitfb_accel_solidfill(int truecolor, u16 dx, u16 dy,
85 u16 width, u16 height, u16 color)
86{
87 hitfb_accel_set_dest(truecolor, dx, dy, width, height);
88
89 fb_writew(0x00f0, HD64461_BBTROPR);
90 fb_writew(16, HD64461_BBTMDR);
91 fb_writew(color, HD64461_GRSCR);
92
93 hitfb_accel_start(truecolor);
94}
95
96static inline void hitfb_accel_bitblt(int truecolor, u16 sx, u16 sy, u16 dx, 81static inline void hitfb_accel_bitblt(int truecolor, u16 sx, u16 sy, u16 dx,
97 u16 dy, u16 width, u16 height, u16 rop, 82 u16 dy, u16 width, u16 height, u16 rop,
98 u32 mask_addr) 83 u32 mask_addr)
@@ -100,6 +85,8 @@ static inline void hitfb_accel_bitblt(int truecolor, u16 sx, u16 sy, u16 dx,
100 u32 saddr, daddr; 85 u32 saddr, daddr;
101 u32 maddr = 0; 86 u32 maddr = 0;
102 87
88 height--;
89 width--;
103 fb_writew(rop, HD64461_BBTROPR); 90 fb_writew(rop, HD64461_BBTROPR);
104 if ((sy < dy) || ((sy == dy) && (sx <= dx))) { 91 if ((sy < dy) || ((sy == dy) && (sx <= dx))) {
105 saddr = WIDTH * (sy + height) + sx + width; 92 saddr = WIDTH * (sy + height) + sx + width;
@@ -146,6 +133,7 @@ static void hitfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
146 if (rect->rop != ROP_COPY) 133 if (rect->rop != ROP_COPY)
147 cfb_fillrect(p, rect); 134 cfb_fillrect(p, rect);
148 else { 135 else {
136 hitfb_accel_wait();
149 fb_writew(0x00f0, HD64461_BBTROPR); 137 fb_writew(0x00f0, HD64461_BBTROPR);
150 fb_writew(16, HD64461_BBTMDR); 138 fb_writew(16, HD64461_BBTMDR);
151 139
@@ -161,16 +149,15 @@ static void hitfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
161 rect->height); 149 rect->height);
162 hitfb_accel_start(0); 150 hitfb_accel_start(0);
163 } 151 }
164 hitfb_accel_wait();
165 } 152 }
166} 153}
167 154
168static void hitfb_copyarea(struct fb_info *p, const struct fb_copyarea *area) 155static void hitfb_copyarea(struct fb_info *p, const struct fb_copyarea *area)
169{ 156{
157 hitfb_accel_wait();
170 hitfb_accel_bitblt(p->var.bits_per_pixel == 16, area->sx, area->sy, 158 hitfb_accel_bitblt(p->var.bits_per_pixel == 16, area->sx, area->sy,
171 area->dx, area->dy, area->width, area->height, 159 area->dx, area->dy, area->width, area->height,
172 0x00cc, 0); 160 0x00cc, 0);
173 hitfb_accel_wait();
174} 161}
175 162
176static int hitfb_pan_display(struct fb_var_screeninfo *var, 163static int hitfb_pan_display(struct fb_var_screeninfo *var,
@@ -182,7 +169,7 @@ static int hitfb_pan_display(struct fb_var_screeninfo *var,
182 if (xoffset != 0) 169 if (xoffset != 0)
183 return -EINVAL; 170 return -EINVAL;
184 171
185 fb_writew(yoffset, HD64461_LCDCBAR); 172 fb_writew((yoffset*info->fix.line_length)>>10, HD64461_LCDCBAR);
186 173
187 return 0; 174 return 0;
188} 175}
@@ -192,12 +179,6 @@ int hitfb_blank(int blank_mode, struct fb_info *info)
192 unsigned short v; 179 unsigned short v;
193 180
194 if (blank_mode) { 181 if (blank_mode) {
195#ifdef MACH_HP600
196 sh_dac_disable(DAC_LCD_BRIGHTNESS);
197 v = fb_readw(HD64461_GPBDR);
198 v |= HD64461_GPBDR_LCDOFF;
199 fb_writew(v, HD64461_GPBDR);
200#endif
201 v = fb_readw(HD64461_LDR1); 182 v = fb_readw(HD64461_LDR1);
202 v &= ~HD64461_LDR1_DON; 183 v &= ~HD64461_LDR1_DON;
203 fb_writew(v, HD64461_LDR1); 184 fb_writew(v, HD64461_LDR1);
@@ -213,19 +194,18 @@ int hitfb_blank(int blank_mode, struct fb_info *info)
213 v = fb_readw(HD64461_STBCR); 194 v = fb_readw(HD64461_STBCR);
214 v &= ~HD64461_STBCR_SLCDST; 195 v &= ~HD64461_STBCR_SLCDST;
215 fb_writew(v, HD64461_STBCR); 196 fb_writew(v, HD64461_STBCR);
216#ifdef MACH_HP600
217 sh_dac_enable(DAC_LCD_BRIGHTNESS);
218 v = fb_readw(HD64461_GPBDR);
219 v &= ~HD64461_GPBDR_LCDOFF;
220 fb_writew(v, HD64461_GPBDR);
221#endif
222 v = fb_readw(HD64461_LDR1);
223 v |= HD64461_LDR1_DON;
224 fb_writew(v, HD64461_LDR1);
225 197
226 v = fb_readw(HD64461_LCDCCR); 198 v = fb_readw(HD64461_LCDCCR);
227 v &= ~HD64461_LCDCCR_MOFF; 199 v &= ~(HD64461_LCDCCR_MOFF | HD64461_LCDCCR_STREQ);
228 fb_writew(v, HD64461_LCDCCR); 200 fb_writew(v, HD64461_LCDCCR);
201
202 do {
203 v = fb_readw(HD64461_LCDCCR);
204 } while(v&HD64461_LCDCCR_STBACK);
205
206 v = fb_readw(HD64461_LDR1);
207 v |= HD64461_LDR1_DON;
208 fb_writew(v, HD64461_LDR1);
229 } 209 }
230 return 0; 210 return 0;
231} 211}
@@ -233,7 +213,7 @@ int hitfb_blank(int blank_mode, struct fb_info *info)
233static int hitfb_setcolreg(unsigned regno, unsigned red, unsigned green, 213static int hitfb_setcolreg(unsigned regno, unsigned red, unsigned green,
234 unsigned blue, unsigned transp, struct fb_info *info) 214 unsigned blue, unsigned transp, struct fb_info *info)
235{ 215{
236 if (regno >= info->cmap.len) 216 if (regno >= 256)
237 return 1; 217 return 1;
238 218
239 switch (info->var.bits_per_pixel) { 219 switch (info->var.bits_per_pixel) {
@@ -244,6 +224,8 @@ static int hitfb_setcolreg(unsigned regno, unsigned red, unsigned green,
244 fb_writew(blue >> 10, HD64461_CPTWDR); 224 fb_writew(blue >> 10, HD64461_CPTWDR);
245 break; 225 break;
246 case 16: 226 case 16:
227 if (regno >= 16)
228 return 1;
247 ((u32 *) (info->pseudo_palette))[regno] = 229 ((u32 *) (info->pseudo_palette))[regno] =
248 ((red & 0xf800)) | 230 ((red & 0xf800)) |
249 ((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11); 231 ((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11);
@@ -252,26 +234,113 @@ static int hitfb_setcolreg(unsigned regno, unsigned red, unsigned green,
252 return 0; 234 return 0;
253} 235}
254 236
237static int hitfb_sync(struct fb_info *info)
238{
239 hitfb_accel_wait();
240
241 return 0;
242}
243
244static int hitfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
245{
246 int maxy;
247
248 var->xres = info->var.xres;
249 var->xres_virtual = info->var.xres;
250 var->yres = info->var.yres;
251
252 if ((var->bits_per_pixel != 8) && (var->bits_per_pixel != 16))
253 var->bits_per_pixel = info->var.bits_per_pixel;
254
255 if (var->yres_virtual < var->yres)
256 var->yres_virtual = var->yres;
257
258 maxy = info->fix.smem_len / var->xres;
259
260 if (var->bits_per_pixel == 16)
261 maxy /= 2;
262
263 if (var->yres_virtual > maxy)
264 var->yres_virtual = maxy;
265
266 var->xoffset = 0;
267 var->yoffset = 0;
268
269 switch (var->bits_per_pixel) {
270 case 8:
271 var->red.offset = 0;
272 var->red.length = 8;
273 var->green.offset = 0;
274 var->green.length = 8;
275 var->blue.offset = 0;
276 var->blue.length = 8;
277 var->transp.offset = 0;
278 var->transp.length = 0;
279 break;
280 case 16: /* RGB 565 */
281 var->red.offset = 11;
282 var->red.length = 5;
283 var->green.offset = 5;
284 var->green.length = 6;
285 var->blue.offset = 0;
286 var->blue.length = 5;
287 var->transp.offset = 0;
288 var->transp.length = 0;
289 break;
290 }
291
292 return 0;
293}
294
295static int hitfb_set_par(struct fb_info *info)
296{
297 unsigned short ldr3;
298
299 switch (info->var.bits_per_pixel) {
300 case 8:
301 info->fix.line_length = info->var.xres;
302 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
303 info->fix.ypanstep = 16;
304 break;
305 case 16:
306 info->fix.line_length = info->var.xres*2;
307 info->fix.visual = FB_VISUAL_TRUECOLOR;
308 info->fix.ypanstep = 8;
309 break;
310 }
311
312 fb_writew(info->fix.line_length, HD64461_LCDCLOR);
313 ldr3 = fb_readw(HD64461_LDR3);
314 ldr3 &= ~15;
315 ldr3 |= (info->var.bits_per_pixel == 8) ? 4 : 8;
316 fb_writew(ldr3, HD64461_LDR3);
317 return 0;
318}
319
255static struct fb_ops hitfb_ops = { 320static struct fb_ops hitfb_ops = {
256 .owner = THIS_MODULE, 321 .owner = THIS_MODULE,
322 .fb_check_var = hitfb_check_var,
323 .fb_set_par = hitfb_set_par,
257 .fb_setcolreg = hitfb_setcolreg, 324 .fb_setcolreg = hitfb_setcolreg,
258 .fb_blank = hitfb_blank, 325 .fb_blank = hitfb_blank,
326 .fb_sync = hitfb_sync,
259 .fb_pan_display = hitfb_pan_display, 327 .fb_pan_display = hitfb_pan_display,
260 .fb_fillrect = hitfb_fillrect, 328 .fb_fillrect = hitfb_fillrect,
261 .fb_copyarea = hitfb_copyarea, 329 .fb_copyarea = hitfb_copyarea,
262 .fb_imageblit = cfb_imageblit, 330 .fb_imageblit = cfb_imageblit,
263}; 331};
264 332
265int __init hitfb_init(void) 333static int __init hitfb_probe(struct platform_device *dev)
266{ 334{
267 unsigned short lcdclor, ldr3, ldvndr; 335 unsigned short lcdclor, ldr3, ldvndr;
268 int size;
269 336
270 if (fb_get_options("hitfb", NULL)) 337 if (fb_get_options("hitfb", NULL))
271 return -ENODEV; 338 return -ENODEV;
272 339
340 hitfb_fix.mmio_start = CONFIG_HD64461_IOBASE+0x1000;
341 hitfb_fix.mmio_len = 0x1000;
273 hitfb_fix.smem_start = CONFIG_HD64461_IOBASE + 0x02000000; 342 hitfb_fix.smem_start = CONFIG_HD64461_IOBASE + 0x02000000;
274 hitfb_fix.smem_len = (MACH_HP690) ? 1024 * 1024 : 512 * 1024; 343 hitfb_fix.smem_len = 512 * 1024;
275 344
276 lcdclor = fb_readw(HD64461_LCDCLOR); 345 lcdclor = fb_readw(HD64461_LCDCLOR);
277 ldvndr = fb_readw(HD64461_LDVNDR); 346 ldvndr = fb_readw(HD64461_LDVNDR);
@@ -321,12 +390,12 @@ int __init hitfb_init(void)
321 fb_info.var = hitfb_var; 390 fb_info.var = hitfb_var;
322 fb_info.fix = hitfb_fix; 391 fb_info.fix = hitfb_fix;
323 fb_info.pseudo_palette = pseudo_palette; 392 fb_info.pseudo_palette = pseudo_palette;
324 fb_info.flags = FBINFO_DEFAULT; 393 fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
394 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
325 395
326 fb_info.screen_base = (void *)hitfb_fix.smem_start; 396 fb_info.screen_base = (void *)hitfb_fix.smem_start;
327 397
328 size = (fb_info.var.bits_per_pixel == 8) ? 256 : 16; 398 fb_alloc_cmap(&fb_info.cmap, 256, 0);
329 fb_alloc_cmap(&fb_info.cmap, size, 0);
330 399
331 if (register_framebuffer(&fb_info) < 0) 400 if (register_framebuffer(&fb_info) < 0)
332 return -EINVAL; 401 return -EINVAL;
@@ -336,9 +405,75 @@ int __init hitfb_init(void)
336 return 0; 405 return 0;
337} 406}
338 407
408static int __devexit hitfb_remove(struct platform_device *dev)
409{
410 return unregister_framebuffer(&fb_info);
411}
412
413#ifdef CONFIG_PM
414static int hitfb_suspend(struct platform_device *dev, pm_message_t state)
415{
416 u16 v;
417
418 hitfb_blank(1,0);
419 v = fb_readw(HD64461_STBCR);
420 v |= HD64461_STBCR_SLCKE_IST;
421 fb_writew(v, HD64461_STBCR);
422
423 return 0;
424}
425
426static int hitfb_resume(struct platform_device *dev)
427{
428 u16 v;
429
430 v = fb_readw(HD64461_STBCR);
431 v &= ~HD64461_STBCR_SLCKE_OST;
432 msleep(100);
433 v = fb_readw(HD64461_STBCR);
434 v &= ~HD64461_STBCR_SLCKE_IST;
435 fb_writew(v, HD64461_STBCR);
436 hitfb_blank(0,0);
437
438 return 0;
439}
440#endif
441
442static struct platform_driver hitfb_driver = {
443 .probe = hitfb_probe,
444 .remove = __devexit_p(hitfb_remove),
445#ifdef CONFIG_PM
446 .suspend = hitfb_suspend,
447 .resume = hitfb_resume,
448#endif
449 .driver = {
450 .name = "hitfb",
451 },
452};
453
454static struct platform_device hitfb_device = {
455 .name = "hitfb",
456 .id = -1,
457};
458
459static int __init hitfb_init(void)
460{
461 int ret;
462
463 ret = platform_driver_register(&hitfb_driver);
464 if (!ret) {
465 ret = platform_device_register(&hitfb_device);
466 if (ret)
467 platform_driver_unregister(&hitfb_driver);
468 }
469 return ret;
470}
471
472
339static void __exit hitfb_exit(void) 473static void __exit hitfb_exit(void)
340{ 474{
341 unregister_framebuffer(&fb_info); 475 platform_device_unregister(&hitfb_device);
476 platform_driver_unregister(&hitfb_driver);
342} 477}
343 478
344module_init(hitfb_init); 479module_init(hitfb_init);
diff --git a/drivers/video/i810/i810-i2c.c b/drivers/video/i810/i810-i2c.c
index c1f7b49975dd..b38d805db313 100644
--- a/drivers/video/i810/i810-i2c.c
+++ b/drivers/video/i810/i810-i2c.c
@@ -19,7 +19,6 @@
19#include "i810_main.h" 19#include "i810_main.h"
20#include "../edid.h" 20#include "../edid.h"
21 21
22#define I810_DDC 0x50
23/* bit locations in the registers */ 22/* bit locations in the registers */
24#define SCL_DIR_MASK 0x0001 23#define SCL_DIR_MASK 0x0001
25#define SCL_DIR 0x0002 24#define SCL_DIR 0x0002
@@ -98,7 +97,6 @@ static int i810_setup_i2c_bus(struct i810fb_i2c_chan *chan, const char *name)
98 chan->algo.getsda = i810i2c_getsda; 97 chan->algo.getsda = i810i2c_getsda;
99 chan->algo.getscl = i810i2c_getscl; 98 chan->algo.getscl = i810i2c_getscl;
100 chan->algo.udelay = 10; 99 chan->algo.udelay = 10;
101 chan->algo.mdelay = 10;
102 chan->algo.timeout = (HZ/2); 100 chan->algo.timeout = (HZ/2);
103 chan->algo.data = chan; 101 chan->algo.data = chan;
104 102
@@ -151,53 +149,14 @@ void i810_delete_i2c_busses(struct i810fb_par *par)
151 par->chan[2].par = NULL; 149 par->chan[2].par = NULL;
152} 150}
153 151
154static u8 *i810_do_probe_i2c_edid(struct i810fb_i2c_chan *chan)
155{
156 u8 start = 0x0;
157 struct i2c_msg msgs[] = {
158 {
159 .addr = I810_DDC,
160 .len = 1,
161 .buf = &start,
162 }, {
163 .addr = I810_DDC,
164 .flags = I2C_M_RD,
165 .len = EDID_LENGTH,
166 },
167 };
168 u8 *buf;
169
170 buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
171 if (!buf) {
172 DPRINTK("i810-i2c: Failed to allocate memory\n");
173 return NULL;
174 }
175 msgs[1].buf = buf;
176
177 if (i2c_transfer(&chan->adapter, msgs, 2) == 2) {
178 DPRINTK("i810-i2c: I2C Transfer successful\n");
179 return buf;
180 }
181
182 DPRINTK("i810-i2c: Unable to read EDID block.\n");
183 kfree(buf);
184 return NULL;
185}
186
187int i810_probe_i2c_connector(struct fb_info *info, u8 **out_edid, int conn) 152int i810_probe_i2c_connector(struct fb_info *info, u8 **out_edid, int conn)
188{ 153{
189 struct i810fb_par *par = info->par; 154 struct i810fb_par *par = info->par;
190 u8 *edid = NULL; 155 u8 *edid = NULL;
191 int i;
192 156
193 DPRINTK("i810-i2c: Probe DDC%i Bus\n", conn+1); 157 DPRINTK("i810-i2c: Probe DDC%i Bus\n", conn+1);
194 if (conn < par->ddc_num) { 158 if (conn < par->ddc_num) {
195 for (i = 0; i < 3; i++) { 159 edid = fb_ddc_read(&par->chan[conn].adapter);
196 /* Do the real work */
197 edid = i810_do_probe_i2c_edid(&par->chan[conn]);
198 if (edid)
199 break;
200 }
201 } else { 160 } else {
202 const u8 *e = fb_firmware_edid(info->device); 161 const u8 *e = fb_firmware_edid(info->device);
203 162
diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
index a6ca02f2156a..b55a12d95eb2 100644
--- a/drivers/video/i810/i810_main.c
+++ b/drivers/video/i810/i810_main.c
@@ -1554,15 +1554,17 @@ static struct fb_ops i810fb_ops __devinitdata = {
1554/*********************************************************************** 1554/***********************************************************************
1555 * Power Management * 1555 * Power Management *
1556 ***********************************************************************/ 1556 ***********************************************************************/
1557static int i810fb_suspend(struct pci_dev *dev, pm_message_t state) 1557static int i810fb_suspend(struct pci_dev *dev, pm_message_t mesg)
1558{ 1558{
1559 struct fb_info *info = pci_get_drvdata(dev); 1559 struct fb_info *info = pci_get_drvdata(dev);
1560 struct i810fb_par *par = info->par; 1560 struct i810fb_par *par = info->par;
1561 1561
1562 par->cur_state = state.event; 1562 par->cur_state = mesg.event;
1563 1563
1564 if (state.event == PM_EVENT_FREEZE) { 1564 switch (mesg.event) {
1565 dev->dev.power.power_state = state; 1565 case PM_EVENT_FREEZE:
1566 case PM_EVENT_PRETHAW:
1567 dev->dev.power.power_state = mesg;
1566 return 0; 1568 return 0;
1567 } 1569 }
1568 1570
@@ -1578,7 +1580,7 @@ static int i810fb_suspend(struct pci_dev *dev, pm_message_t state)
1578 1580
1579 pci_save_state(dev); 1581 pci_save_state(dev);
1580 pci_disable_device(dev); 1582 pci_disable_device(dev);
1581 pci_set_power_state(dev, pci_choose_state(dev, state)); 1583 pci_set_power_state(dev, pci_choose_state(dev, mesg));
1582 release_console_sem(); 1584 release_console_sem();
1583 1585
1584 return 0; 1586 return 0;
@@ -1600,7 +1602,10 @@ static int i810fb_resume(struct pci_dev *dev)
1600 acquire_console_sem(); 1602 acquire_console_sem();
1601 pci_set_power_state(dev, PCI_D0); 1603 pci_set_power_state(dev, PCI_D0);
1602 pci_restore_state(dev); 1604 pci_restore_state(dev);
1603 pci_enable_device(dev); 1605
1606 if (pci_enable_device(dev))
1607 goto fail;
1608
1604 pci_set_master(dev); 1609 pci_set_master(dev);
1605 agp_bind_memory(par->i810_gtt.i810_fb_memory, 1610 agp_bind_memory(par->i810_gtt.i810_fb_memory,
1606 par->fb.offset); 1611 par->fb.offset);
@@ -1609,6 +1614,7 @@ static int i810fb_resume(struct pci_dev *dev)
1609 i810fb_set_par(info); 1614 i810fb_set_par(info);
1610 fb_set_suspend (info, 0); 1615 fb_set_suspend (info, 0);
1611 info->fbops->fb_blank(VESA_NO_BLANKING, info); 1616 info->fbops->fb_blank(VESA_NO_BLANKING, info);
1617fail:
1612 release_console_sem(); 1618 release_console_sem();
1613 return 0; 1619 return 0;
1614} 1620}
diff --git a/drivers/video/intelfb/Makefile b/drivers/video/intelfb/Makefile
index 722d21d6e5cd..6c782d3ae1be 100644
--- a/drivers/video/intelfb/Makefile
+++ b/drivers/video/intelfb/Makefile
@@ -1,6 +1,8 @@
1obj-$(CONFIG_FB_INTEL) += intelfb.o 1obj-$(CONFIG_FB_INTEL) += intelfb.o
2 2
3intelfb-objs := intelfbdrv.o intelfbhw.o 3intelfb-y := intelfbdrv.o intelfbhw.o
4intelfb-$(CONFIG_FB_INTEL_I2C) += intelfb_i2c.o
5intelfb-objs := $(intelfb-y)
4 6
5ifdef CONFIG_FB_INTEL_DEBUG 7ifdef CONFIG_FB_INTEL_DEBUG
6#EXTRA_CFLAGS += -DDEBUG -DVERBOSE -DREGDUMP 8#EXTRA_CFLAGS += -DDEBUG -DVERBOSE -DREGDUMP
diff --git a/drivers/video/intelfb/intelfb.h b/drivers/video/intelfb/intelfb.h
index e290d7460e1b..80b94c19a9fa 100644
--- a/drivers/video/intelfb/intelfb.h
+++ b/drivers/video/intelfb/intelfb.h
@@ -6,6 +6,10 @@
6#include <linux/agp_backend.h> 6#include <linux/agp_backend.h>
7#include <linux/fb.h> 7#include <linux/fb.h>
8 8
9#ifdef CONFIG_FB_INTEL_I2C
10#include <linux/i2c.h>
11#include <linux/i2c-algo-bit.h>
12#endif
9 13
10/*** Version/name ***/ 14/*** Version/name ***/
11#define INTELFB_VERSION "0.9.4" 15#define INTELFB_VERSION "0.9.4"
@@ -115,6 +119,29 @@
115/* Intel agpgart driver */ 119/* Intel agpgart driver */
116#define AGP_PHYSICAL_MEMORY 2 120#define AGP_PHYSICAL_MEMORY 2
117 121
122/* store information about an Ixxx DVO */
123/* The i830->i865 use multiple DVOs with multiple i2cs */
124/* the i915, i945 have a single sDVO i2c bus - which is different */
125#define MAX_OUTPUTS 6
126
127/* these are outputs from the chip - integrated only
128 external chips are via DVO or SDVO output */
129#define INTELFB_OUTPUT_UNUSED 0
130#define INTELFB_OUTPUT_ANALOG 1
131#define INTELFB_OUTPUT_DVO 2
132#define INTELFB_OUTPUT_SDVO 3
133#define INTELFB_OUTPUT_LVDS 4
134#define INTELFB_OUTPUT_TVOUT 5
135
136#define INTELFB_DVO_CHIP_NONE 0
137#define INTELFB_DVO_CHIP_LVDS 1
138#define INTELFB_DVO_CHIP_TMDS 2
139#define INTELFB_DVO_CHIP_TVOUT 4
140
141#define INTELFB_OUTPUT_PIPE_NC 0
142#define INTELFB_OUTPUT_PIPE_A 1
143#define INTELFB_OUTPUT_PIPE_B 2
144
118/*** Data Types ***/ 145/*** Data Types ***/
119 146
120/* supported chipsets */ 147/* supported chipsets */
@@ -195,6 +222,10 @@ struct intelfb_hwstate {
195 u32 mem_mode; 222 u32 mem_mode;
196 u32 fw_blc_0; 223 u32 fw_blc_0;
197 u32 fw_blc_1; 224 u32 fw_blc_1;
225 u16 hwstam;
226 u16 ier;
227 u16 iir;
228 u16 imr;
198}; 229};
199 230
200struct intelfb_heap_data { 231struct intelfb_heap_data {
@@ -204,6 +235,33 @@ struct intelfb_heap_data {
204 u32 size; // in bytes 235 u32 size; // in bytes
205}; 236};
206 237
238#ifdef CONFIG_FB_INTEL_I2C
239struct intelfb_i2c_chan {
240 struct intelfb_info *dinfo;
241 u32 reg;
242 struct i2c_adapter adapter;
243 struct i2c_algo_bit_data algo;
244};
245#endif
246
247struct intelfb_output_rec {
248 int type;
249 int pipe;
250 int flags;
251
252#ifdef CONFIG_FB_INTEL_I2C
253 struct intelfb_i2c_chan i2c_bus;
254 struct intelfb_i2c_chan ddc_bus;
255#endif
256};
257
258struct intelfb_vsync {
259 wait_queue_head_t wait;
260 unsigned int count;
261 int pan_display;
262 u32 pan_offset;
263};
264
207struct intelfb_info { 265struct intelfb_info {
208 struct fb_info *info; 266 struct fb_info *info;
209 struct fb_ops *fbops; 267 struct fb_ops *fbops;
@@ -220,7 +278,7 @@ struct intelfb_info {
220 u8 fbmem_gart; 278 u8 fbmem_gart;
221 279
222 /* mtrr support */ 280 /* mtrr support */
223 u32 mtrr_reg; 281 int mtrr_reg;
224 u32 has_mtrr; 282 u32 has_mtrr;
225 283
226 /* heap data */ 284 /* heap data */
@@ -267,6 +325,12 @@ struct intelfb_info {
267 int fixed_mode; 325 int fixed_mode;
268 int ring_active; 326 int ring_active;
269 int flag; 327 int flag;
328 unsigned long irq_flags;
329 int open;
330
331 /* vsync */
332 struct intelfb_vsync vsync;
333 spinlock_t int_lock;
270 334
271 /* hw cursor */ 335 /* hw cursor */
272 int cursor_on; 336 int cursor_on;
@@ -285,12 +349,25 @@ struct intelfb_info {
285 349
286 /* index into plls */ 350 /* index into plls */
287 int pll_index; 351 int pll_index;
352
353 /* outputs */
354 int num_outputs;
355 struct intelfb_output_rec output[MAX_OUTPUTS];
288}; 356};
289 357
290#define IS_I9XX(dinfo) (((dinfo)->chipset == INTEL_915G)||(dinfo->chipset == INTEL_915GM)||((dinfo)->chipset == INTEL_945G)||(dinfo->chipset==INTEL_945GM)) 358#define IS_I9XX(dinfo) (((dinfo)->chipset == INTEL_915G)||(dinfo->chipset == INTEL_915GM)||((dinfo)->chipset == INTEL_945G)||(dinfo->chipset==INTEL_945GM))
291 359
360#ifndef FBIO_WAITFORVSYNC
361#define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
362#endif
363
292/*** function prototypes ***/ 364/*** function prototypes ***/
293 365
294extern int intelfb_var_to_depth(const struct fb_var_screeninfo *var); 366extern int intelfb_var_to_depth(const struct fb_var_screeninfo *var);
295 367
368#ifdef CONFIG_FB_INTEL_I2C
369extern void intelfb_create_i2c_busses(struct intelfb_info *dinfo);
370extern void intelfb_delete_i2c_busses(struct intelfb_info *dinfo);
371#endif
372
296#endif /* _INTELFB_H */ 373#endif /* _INTELFB_H */
diff --git a/drivers/video/intelfb/intelfb_i2c.c b/drivers/video/intelfb/intelfb_i2c.c
new file mode 100644
index 000000000000..c1113d6e941d
--- /dev/null
+++ b/drivers/video/intelfb/intelfb_i2c.c
@@ -0,0 +1,200 @@
1/**************************************************************************
2
3 Copyright 2006 Dave Airlie <airlied@linux.ie>
4
5All Rights Reserved.
6
7Permission is hereby granted, free of charge, to any person obtaining a
8copy of this software and associated documentation files (the "Software"),
9to deal in the Software without restriction, including without limitation
10on the rights to use, copy, modify, merge, publish, distribute, sub
11license, and/or sell copies of the Software, and to permit persons to whom
12the Software is furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice (including the next
15paragraph) shall be included in all copies or substantial portions of the
16Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26**************************************************************************/
27
28#include <linux/config.h>
29#include <linux/module.h>
30#include <linux/kernel.h>
31#include <linux/sched.h>
32#include <linux/delay.h>
33#include <linux/pci.h>
34#include <linux/fb.h>
35
36#include <linux/i2c.h>
37#include <linux/i2c-id.h>
38#include <linux/i2c-algo-bit.h>
39
40#include <asm/io.h>
41
42#include "intelfb.h"
43#include "intelfbhw.h"
44
45/* bit locations in the registers */
46#define SCL_DIR_MASK 0x0001
47#define SCL_DIR 0x0002
48#define SCL_VAL_MASK 0x0004
49#define SCL_VAL_OUT 0x0008
50#define SCL_VAL_IN 0x0010
51#define SDA_DIR_MASK 0x0100
52#define SDA_DIR 0x0200
53#define SDA_VAL_MASK 0x0400
54#define SDA_VAL_OUT 0x0800
55#define SDA_VAL_IN 0x1000
56
57static void intelfb_gpio_setscl(void *data, int state)
58{
59 struct intelfb_i2c_chan *chan = data;
60 struct intelfb_info *dinfo = chan->dinfo;
61 u32 val;
62
63 OUTREG(chan->reg, (state ? SCL_VAL_OUT : 0) | SCL_DIR | SCL_DIR_MASK | SCL_VAL_MASK);
64 val = INREG(chan->reg);
65}
66
67static void intelfb_gpio_setsda(void *data, int state)
68{
69 struct intelfb_i2c_chan *chan = data;
70 struct intelfb_info *dinfo = chan->dinfo;
71 u32 val;
72
73 OUTREG(chan->reg, (state ? SDA_VAL_OUT : 0) | SDA_DIR | SDA_DIR_MASK | SDA_VAL_MASK);
74 val = INREG(chan->reg);
75}
76
77static int intelfb_gpio_getscl(void *data)
78{
79 struct intelfb_i2c_chan *chan = data;
80 struct intelfb_info *dinfo = chan->dinfo;
81 u32 val;
82
83 OUTREG(chan->reg, SCL_DIR_MASK);
84 OUTREG(chan->reg, 0);
85 val = INREG(chan->reg);
86 return ((val & SCL_VAL_IN) != 0);
87}
88
89static int intelfb_gpio_getsda(void *data)
90{
91 struct intelfb_i2c_chan *chan = data;
92 struct intelfb_info *dinfo = chan->dinfo;
93 u32 val;
94
95 OUTREG(chan->reg, SDA_DIR_MASK);
96 OUTREG(chan->reg, 0);
97 val = INREG(chan->reg);
98 return ((val & SDA_VAL_IN) != 0);
99}
100
101static int intelfb_setup_i2c_bus(struct intelfb_info *dinfo,
102 struct intelfb_i2c_chan *chan,
103 const u32 reg, const char *name)
104{
105 int rc;
106
107 chan->dinfo = dinfo;
108 chan->reg = reg;
109 snprintf(chan->adapter.name, I2C_NAME_SIZE, "intelfb %s", name);
110 chan->adapter.owner = THIS_MODULE;
111 chan->adapter.id = I2C_HW_B_INTELFB;
112 chan->adapter.algo_data = &chan->algo;
113 chan->adapter.dev.parent = &chan->dinfo->pdev->dev;
114 chan->algo.setsda = intelfb_gpio_setsda;
115 chan->algo.setscl = intelfb_gpio_setscl;
116 chan->algo.getsda = intelfb_gpio_getsda;
117 chan->algo.getscl = intelfb_gpio_getscl;
118 chan->algo.udelay = 40;
119 chan->algo.timeout = 20;
120 chan->algo.data = chan;
121
122 i2c_set_adapdata(&chan->adapter, chan);
123
124 /* Raise SCL and SDA */
125 intelfb_gpio_setsda(chan, 1);
126 intelfb_gpio_setscl(chan, 1);
127 udelay(20);
128
129 rc = i2c_bit_add_bus(&chan->adapter);
130 if (rc == 0)
131 DBG_MSG("I2C bus %s registered.\n", name);
132 else
133 WRN_MSG("Failed to register I2C bus %s.\n", name);
134 return rc;
135}
136
137void intelfb_create_i2c_busses(struct intelfb_info *dinfo)
138{
139 int i = 0;
140
141 /* everyone has at least a single analog output */
142 dinfo->num_outputs = 1;
143 dinfo->output[i].type = INTELFB_OUTPUT_ANALOG;
144
145 /* setup the DDC bus for analog output */
146 intelfb_setup_i2c_bus(dinfo, &dinfo->output[i].ddc_bus, GPIOA, "CRTDDC_A");
147 i++;
148
149 /* need to add the output busses for each device
150 - this function is very incomplete
151 - i915GM has LVDS and TVOUT for example
152 */
153 switch(dinfo->chipset) {
154 case INTEL_830M:
155 case INTEL_845G:
156 case INTEL_855GM:
157 case INTEL_865G:
158 dinfo->output[i].type = INTELFB_OUTPUT_DVO;
159 intelfb_setup_i2c_bus(dinfo, &dinfo->output[i].ddc_bus, GPIOD, "DVODDC_D");
160 intelfb_setup_i2c_bus(dinfo, &dinfo->output[i].i2c_bus, GPIOE, "DVOI2C_E");
161 i++;
162 break;
163 case INTEL_915G:
164 case INTEL_915GM:
165 /* has some LVDS + tv-out */
166 case INTEL_945G:
167 case INTEL_945GM:
168 /* SDVO ports have a single control bus - 2 devices */
169 dinfo->output[i].type = INTELFB_OUTPUT_SDVO;
170 intelfb_setup_i2c_bus(dinfo, &dinfo->output[i].i2c_bus, GPIOE, "SDVOCTRL_E");
171 /* TODO: initialize the SDVO */
172// I830SDVOInit(pScrn, i, DVOB);
173 i++;
174
175 /* set up SDVOC */
176 dinfo->output[i].type = INTELFB_OUTPUT_SDVO;
177 dinfo->output[i].i2c_bus = dinfo->output[i - 1].i2c_bus;
178 /* TODO: initialize the SDVO */
179// I830SDVOInit(pScrn, i, DVOC);
180 i++;
181 break;
182 }
183 dinfo->num_outputs = i;
184}
185
186void intelfb_delete_i2c_busses(struct intelfb_info *dinfo)
187{
188 int i;
189
190 for (i = 0; i < MAX_OUTPUTS; i++) {
191 if (dinfo->output[i].i2c_bus.dinfo) {
192 i2c_bit_del_bus(&dinfo->output[i].i2c_bus.adapter);
193 dinfo->output[i].i2c_bus.dinfo = NULL;
194 }
195 if (dinfo->output[i].ddc_bus.dinfo) {
196 i2c_bit_del_bus(&dinfo->output[i].ddc_bus.adapter);
197 dinfo->output[i].ddc_bus.dinfo = NULL;
198 }
199 }
200}
diff --git a/drivers/video/intelfb/intelfbdrv.c b/drivers/video/intelfb/intelfbdrv.c
index 06af89d44a0d..6f9de04193d2 100644
--- a/drivers/video/intelfb/intelfbdrv.c
+++ b/drivers/video/intelfb/intelfbdrv.c
@@ -136,6 +136,8 @@
136static void __devinit get_initial_mode(struct intelfb_info *dinfo); 136static void __devinit get_initial_mode(struct intelfb_info *dinfo);
137static void update_dinfo(struct intelfb_info *dinfo, 137static void update_dinfo(struct intelfb_info *dinfo,
138 struct fb_var_screeninfo *var); 138 struct fb_var_screeninfo *var);
139static int intelfb_open(struct fb_info *info, int user);
140static int intelfb_release(struct fb_info *info, int user);
139static int intelfb_check_var(struct fb_var_screeninfo *var, 141static int intelfb_check_var(struct fb_var_screeninfo *var,
140 struct fb_info *info); 142 struct fb_info *info);
141static int intelfb_set_par(struct fb_info *info); 143static int intelfb_set_par(struct fb_info *info);
@@ -194,6 +196,8 @@ static int num_registered = 0;
194/* fb ops */ 196/* fb ops */
195static struct fb_ops intel_fb_ops = { 197static struct fb_ops intel_fb_ops = {
196 .owner = THIS_MODULE, 198 .owner = THIS_MODULE,
199 .fb_open = intelfb_open,
200 .fb_release = intelfb_release,
197 .fb_check_var = intelfb_check_var, 201 .fb_check_var = intelfb_check_var,
198 .fb_set_par = intelfb_set_par, 202 .fb_set_par = intelfb_set_par,
199 .fb_setcolreg = intelfb_setcolreg, 203 .fb_setcolreg = intelfb_setcolreg,
@@ -446,6 +450,8 @@ cleanup(struct intelfb_info *dinfo)
446 if (!dinfo) 450 if (!dinfo)
447 return; 451 return;
448 452
453 intelfbhw_disable_irq(dinfo);
454
449 fb_dealloc_cmap(&dinfo->info->cmap); 455 fb_dealloc_cmap(&dinfo->info->cmap);
450 kfree(dinfo->info->pixmap.addr); 456 kfree(dinfo->info->pixmap.addr);
451 457
@@ -467,6 +473,11 @@ cleanup(struct intelfb_info *dinfo)
467 agp_free_memory(dinfo->gtt_ring_mem); 473 agp_free_memory(dinfo->gtt_ring_mem);
468 } 474 }
469 475
476#ifdef CONFIG_FB_INTEL_I2C
477 /* un-register I2C bus */
478 intelfb_delete_i2c_busses(dinfo);
479#endif
480
470 if (dinfo->mmio_base) 481 if (dinfo->mmio_base)
471 iounmap((void __iomem *)dinfo->mmio_base); 482 iounmap((void __iomem *)dinfo->mmio_base);
472 if (dinfo->aperture.virtual) 483 if (dinfo->aperture.virtual)
@@ -844,6 +855,11 @@ intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
844 if (bailearly == 5) 855 if (bailearly == 5)
845 bailout(dinfo); 856 bailout(dinfo);
846 857
858#ifdef CONFIG_FB_INTEL_I2C
859 /* register I2C bus */
860 intelfb_create_i2c_busses(dinfo);
861#endif
862
847 if (bailearly == 6) 863 if (bailearly == 6)
848 bailout(dinfo); 864 bailout(dinfo);
849 865
@@ -888,6 +904,13 @@ intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
888 } 904 }
889 905
890 dinfo->registered = 1; 906 dinfo->registered = 1;
907 dinfo->open = 0;
908
909 init_waitqueue_head(&dinfo->vsync.wait);
910 spin_lock_init(&dinfo->int_lock);
911 dinfo->irq_flags = 0;
912 dinfo->vsync.pan_display = 0;
913 dinfo->vsync.pan_offset = 0;
891 914
892 return 0; 915 return 0;
893 916
@@ -1188,6 +1211,34 @@ update_dinfo(struct intelfb_info *dinfo, struct fb_var_screeninfo *var)
1188 ***************************************************************/ 1211 ***************************************************************/
1189 1212
1190static int 1213static int
1214intelfb_open(struct fb_info *info, int user)
1215{
1216 struct intelfb_info *dinfo = GET_DINFO(info);
1217
1218 if (user) {
1219 dinfo->open++;
1220 }
1221
1222 return 0;
1223}
1224
1225static int
1226intelfb_release(struct fb_info *info, int user)
1227{
1228 struct intelfb_info *dinfo = GET_DINFO(info);
1229
1230 if (user) {
1231 dinfo->open--;
1232 msleep(1);
1233 if (!dinfo->open) {
1234 intelfbhw_disable_irq(dinfo);
1235 }
1236 }
1237
1238 return 0;
1239}
1240
1241static int
1191intelfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) 1242intelfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1192{ 1243{
1193 int change_var = 0; 1244 int change_var = 0;
@@ -1433,6 +1484,19 @@ static int
1433intelfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg) 1484intelfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1434{ 1485{
1435 int retval = 0; 1486 int retval = 0;
1487 struct intelfb_info *dinfo = GET_DINFO(info);
1488 u32 pipe = 0;
1489
1490 switch (cmd) {
1491 case FBIO_WAITFORVSYNC:
1492 if (get_user(pipe, (__u32 __user *)arg))
1493 return -EFAULT;
1494
1495 retval = intelfbhw_wait_for_vsync(dinfo, pipe);
1496 break;
1497 default:
1498 break;
1499 }
1436 1500
1437 return retval; 1501 return retval;
1438} 1502}
diff --git a/drivers/video/intelfb/intelfbhw.c b/drivers/video/intelfb/intelfbhw.c
index 2a9322f9cfdc..f887f1efd3fe 100644
--- a/drivers/video/intelfb/intelfbhw.c
+++ b/drivers/video/intelfb/intelfbhw.c
@@ -32,6 +32,7 @@
32#include <linux/pci.h> 32#include <linux/pci.h>
33#include <linux/vmalloc.h> 33#include <linux/vmalloc.h>
34#include <linux/pagemap.h> 34#include <linux/pagemap.h>
35#include <linux/interrupt.h>
35 36
36#include <asm/io.h> 37#include <asm/io.h>
37 38
@@ -368,7 +369,13 @@ intelfbhw_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
368 369
369 offset += dinfo->fb.offset << 12; 370 offset += dinfo->fb.offset << 12;
370 371
371 OUTREG(DSPABASE, offset); 372 dinfo->vsync.pan_offset = offset;
373 if ((var->activate & FB_ACTIVATE_VBL) && !intelfbhw_enable_irq(dinfo, 0)) {
374 dinfo->vsync.pan_display = 1;
375 } else {
376 dinfo->vsync.pan_display = 0;
377 OUTREG(DSPABASE, offset);
378 }
372 379
373 return 0; 380 return 0;
374} 381}
@@ -585,6 +592,11 @@ intelfbhw_read_hw_state(struct intelfb_info *dinfo, struct intelfb_hwstate *hw,
585 hw->fw_blc_0 = INREG(FW_BLC_0); 592 hw->fw_blc_0 = INREG(FW_BLC_0);
586 hw->fw_blc_1 = INREG(FW_BLC_1); 593 hw->fw_blc_1 = INREG(FW_BLC_1);
587 594
595 hw->hwstam = INREG16(HWSTAM);
596 hw->ier = INREG16(IER);
597 hw->iir = INREG16(IIR);
598 hw->imr = INREG16(IMR);
599
588 return 0; 600 return 0;
589} 601}
590 602
@@ -613,6 +625,7 @@ static int calc_vclock(int index, int m1, int m2, int n, int p1, int p2, int lvd
613 return vco / p; 625 return vco / p;
614} 626}
615 627
628#if REGDUMP
616static void 629static void
617intelfbhw_get_p1p2(struct intelfb_info *dinfo, int dpll, int *o_p1, int *o_p2) 630intelfbhw_get_p1p2(struct intelfb_info *dinfo, int dpll, int *o_p1, int *o_p2)
618{ 631{
@@ -638,6 +651,7 @@ intelfbhw_get_p1p2(struct intelfb_info *dinfo, int dpll, int *o_p1, int *o_p2)
638 *o_p1 = p1; 651 *o_p1 = p1;
639 *o_p2 = p2; 652 *o_p2 = p2;
640} 653}
654#endif
641 655
642 656
643void 657void
@@ -794,6 +808,10 @@ intelfbhw_print_hw_state(struct intelfb_info *dinfo, struct intelfb_hwstate *hw)
794 printk(" FW_BLC_0 0x%08x\n", hw->fw_blc_0); 808 printk(" FW_BLC_0 0x%08x\n", hw->fw_blc_0);
795 printk(" FW_BLC_1 0x%08x\n", hw->fw_blc_1); 809 printk(" FW_BLC_1 0x%08x\n", hw->fw_blc_1);
796 810
811 printk(" HWSTAM 0x%04x\n", hw->hwstam);
812 printk(" IER 0x%04x\n", hw->ier);
813 printk(" IIR 0x%04x\n", hw->iir);
814 printk(" IMR 0x%04x\n", hw->imr);
797 printk("hw state dump end\n"); 815 printk("hw state dump end\n");
798#endif 816#endif
799} 817}
@@ -1932,3 +1950,119 @@ intelfbhw_cursor_reset(struct intelfb_info *dinfo) {
1932 addr += 16; 1950 addr += 16;
1933 } 1951 }
1934} 1952}
1953
1954static irqreturn_t
1955intelfbhw_irq(int irq, void *dev_id, struct pt_regs *fp) {
1956 int handled = 0;
1957 u16 tmp;
1958 struct intelfb_info *dinfo = (struct intelfb_info *)dev_id;
1959
1960 spin_lock(&dinfo->int_lock);
1961
1962 tmp = INREG16(IIR);
1963 tmp &= VSYNC_PIPE_A_INTERRUPT;
1964
1965 if (tmp == 0) {
1966 spin_unlock(&dinfo->int_lock);
1967 return IRQ_RETVAL(handled);
1968 }
1969
1970 OUTREG16(IIR, tmp);
1971
1972 if (tmp & VSYNC_PIPE_A_INTERRUPT) {
1973 dinfo->vsync.count++;
1974 if (dinfo->vsync.pan_display) {
1975 dinfo->vsync.pan_display = 0;
1976 OUTREG(DSPABASE, dinfo->vsync.pan_offset);
1977 }
1978 wake_up_interruptible(&dinfo->vsync.wait);
1979 handled = 1;
1980 }
1981
1982 spin_unlock(&dinfo->int_lock);
1983
1984 return IRQ_RETVAL(handled);
1985}
1986
1987int
1988intelfbhw_enable_irq(struct intelfb_info *dinfo, int reenable) {
1989
1990 if (!test_and_set_bit(0, &dinfo->irq_flags)) {
1991 if (request_irq(dinfo->pdev->irq, intelfbhw_irq, SA_SHIRQ, "intelfb", dinfo)) {
1992 clear_bit(0, &dinfo->irq_flags);
1993 return -EINVAL;
1994 }
1995
1996 spin_lock_irq(&dinfo->int_lock);
1997 OUTREG16(HWSTAM, 0xfffe);
1998 OUTREG16(IMR, 0x0);
1999 OUTREG16(IER, VSYNC_PIPE_A_INTERRUPT);
2000 spin_unlock_irq(&dinfo->int_lock);
2001 } else if (reenable) {
2002 u16 ier;
2003
2004 spin_lock_irq(&dinfo->int_lock);
2005 ier = INREG16(IER);
2006 if ((ier & VSYNC_PIPE_A_INTERRUPT)) {
2007 DBG_MSG("someone disabled the IRQ [%08X]\n", ier);
2008 OUTREG(IER, VSYNC_PIPE_A_INTERRUPT);
2009 }
2010 spin_unlock_irq(&dinfo->int_lock);
2011 }
2012 return 0;
2013}
2014
2015void
2016intelfbhw_disable_irq(struct intelfb_info *dinfo) {
2017 u16 tmp;
2018
2019 if (test_and_clear_bit(0, &dinfo->irq_flags)) {
2020 if (dinfo->vsync.pan_display) {
2021 dinfo->vsync.pan_display = 0;
2022 OUTREG(DSPABASE, dinfo->vsync.pan_offset);
2023 }
2024 spin_lock_irq(&dinfo->int_lock);
2025 OUTREG16(HWSTAM, 0xffff);
2026 OUTREG16(IMR, 0xffff);
2027 OUTREG16(IER, 0x0);
2028
2029 tmp = INREG16(IIR);
2030 OUTREG16(IIR, tmp);
2031 spin_unlock_irq(&dinfo->int_lock);
2032
2033 free_irq(dinfo->pdev->irq, dinfo);
2034 }
2035}
2036
2037int
2038intelfbhw_wait_for_vsync(struct intelfb_info *dinfo, u32 pipe) {
2039 struct intelfb_vsync *vsync;
2040 unsigned int count;
2041 int ret;
2042
2043 switch (pipe) {
2044 case 0:
2045 vsync = &dinfo->vsync;
2046 break;
2047 default:
2048 return -ENODEV;
2049 }
2050
2051 ret = intelfbhw_enable_irq(dinfo, 0);
2052 if (ret) {
2053 return ret;
2054 }
2055
2056 count = vsync->count;
2057 ret = wait_event_interruptible_timeout(vsync->wait, count != vsync->count, HZ/10);
2058 if (ret < 0) {
2059 return ret;
2060 }
2061 if (ret == 0) {
2062 intelfbhw_enable_irq(dinfo, 1);
2063 DBG_MSG("wait_for_vsync timed out!\n");
2064 return -ETIMEDOUT;
2065 }
2066
2067 return 0;
2068}
diff --git a/drivers/video/intelfb/intelfbhw.h b/drivers/video/intelfb/intelfbhw.h
index 10acda098b71..8c54ba8fbdda 100644
--- a/drivers/video/intelfb/intelfbhw.h
+++ b/drivers/video/intelfb/intelfbhw.h
@@ -88,6 +88,19 @@
88#define INSTDONE 0x2090 88#define INSTDONE 0x2090
89#define PRI_RING_EMPTY 1 89#define PRI_RING_EMPTY 1
90 90
91#define HWSTAM 0x2098
92#define IER 0x20A0
93#define IIR 0x20A4
94#define IMR 0x20A8
95#define VSYNC_PIPE_A_INTERRUPT (1 << 7)
96#define PIPE_A_EVENT_INTERRUPT (1 << 4)
97#define VSYNC_PIPE_B_INTERRUPT (1 << 5)
98#define PIPE_B_EVENT_INTERRUPT (1 << 4)
99#define HOST_PORT_EVENT_INTERRUPT (1 << 3)
100#define CAPTURE_EVENT_INTERRUPT (1 << 2)
101#define USER_DEFINED_INTERRUPT (1 << 1)
102#define BREAKPOINT_INTERRUPT 1
103
91#define INSTPM 0x20c0 104#define INSTPM 0x20c0
92#define SYNC_FLUSH_ENABLE (1 << 5) 105#define SYNC_FLUSH_ENABLE (1 << 5)
93 106
@@ -113,6 +126,12 @@
113#define FW_DISPC_BL_SHIFT 8 126#define FW_DISPC_BL_SHIFT 8
114#define FW_DISPC_BL_MASK 0x7 127#define FW_DISPC_BL_MASK 0x7
115 128
129#define GPIOA 0x5010
130#define GPIOB 0x5014
131#define GPIOC 0x5018 // this may be external DDC on i830
132#define GPIOD 0x501C // this is DVO DDC
133#define GPIOE 0x5020 // this is DVO i2C
134#define GPIOF 0x5024
116 135
117/* PLL registers */ 136/* PLL registers */
118#define VGA0_DIVISOR 0x06000 137#define VGA0_DIVISOR 0x06000
@@ -468,9 +487,12 @@
468 487
469/* I/O macros */ 488/* I/O macros */
470#define INREG8(addr) readb((u8 __iomem *)(dinfo->mmio_base + (addr))) 489#define INREG8(addr) readb((u8 __iomem *)(dinfo->mmio_base + (addr)))
490#define INREG16(addr) readw((u16 __iomem *)(dinfo->mmio_base + (addr)))
471#define INREG(addr) readl((u32 __iomem *)(dinfo->mmio_base + (addr))) 491#define INREG(addr) readl((u32 __iomem *)(dinfo->mmio_base + (addr)))
472#define OUTREG8(addr, val) writeb((val),(u8 __iomem *)(dinfo->mmio_base + \ 492#define OUTREG8(addr, val) writeb((val),(u8 __iomem *)(dinfo->mmio_base + \
473 (addr))) 493 (addr)))
494#define OUTREG16(addr, val) writew((val),(u16 __iomem *)(dinfo->mmio_base + \
495 (addr)))
474#define OUTREG(addr, val) writel((val),(u32 __iomem *)(dinfo->mmio_base + \ 496#define OUTREG(addr, val) writel((val),(u32 __iomem *)(dinfo->mmio_base + \
475 (addr))) 497 (addr)))
476 498
@@ -545,5 +567,8 @@ extern void intelfbhw_cursor_setcolor(struct intelfb_info *dinfo, u32 bg,
545extern void intelfbhw_cursor_load(struct intelfb_info *dinfo, int width, 567extern void intelfbhw_cursor_load(struct intelfb_info *dinfo, int width,
546 int height, u8 *data); 568 int height, u8 *data);
547extern void intelfbhw_cursor_reset(struct intelfb_info *dinfo); 569extern void intelfbhw_cursor_reset(struct intelfb_info *dinfo);
570extern int intelfbhw_enable_irq(struct intelfb_info *dinfo, int reenable);
571extern void intelfbhw_disable_irq(struct intelfb_info *dinfo);
572extern int intelfbhw_wait_for_vsync(struct intelfb_info *dinfo, u32 pipe);
548 573
549#endif /* _INTELFBHW_H */ 574#endif /* _INTELFBHW_H */
diff --git a/drivers/video/matrox/i2c-matroxfb.c b/drivers/video/matrox/i2c-matroxfb.c
index 57abbae5520f..795c1a99a680 100644
--- a/drivers/video/matrox/i2c-matroxfb.c
+++ b/drivers/video/matrox/i2c-matroxfb.c
@@ -95,12 +95,12 @@ static struct i2c_adapter matrox_i2c_adapter_template =
95 95
96static struct i2c_algo_bit_data matrox_i2c_algo_template = 96static struct i2c_algo_bit_data matrox_i2c_algo_template =
97{ 97{
98 NULL, 98 .setsda = matroxfb_gpio_setsda,
99 matroxfb_gpio_setsda, 99 .setscl = matroxfb_gpio_setscl,
100 matroxfb_gpio_setscl, 100 .getsda = matroxfb_gpio_getsda,
101 matroxfb_gpio_getsda, 101 .getscl = matroxfb_gpio_getscl,
102 matroxfb_gpio_getscl, 102 .udelay = 10,
103 10, 10, 100, 103 .timeout = 100,
104}; 104};
105 105
106static int i2c_bus_reg(struct i2c_bit_adapter* b, struct matrox_fb_info* minfo, 106static int i2c_bus_reg(struct i2c_bit_adapter* b, struct matrox_fb_info* minfo,
diff --git a/drivers/video/matrox/matroxfb_base.c b/drivers/video/matrox/matroxfb_base.c
index 4a57dabb77d4..7acf01c181ee 100644
--- a/drivers/video/matrox/matroxfb_base.c
+++ b/drivers/video/matrox/matroxfb_base.c
@@ -2277,10 +2277,13 @@ static void __init matroxfb_init_params(void) {
2277 } 2277 }
2278} 2278}
2279 2279
2280static void __init matrox_init(void) { 2280static int __init matrox_init(void) {
2281 int err;
2282
2281 matroxfb_init_params(); 2283 matroxfb_init_params();
2282 pci_register_driver(&matroxfb_driver); 2284 err = pci_register_driver(&matroxfb_driver);
2283 dev = -1; /* accept all new devices... */ 2285 dev = -1; /* accept all new devices... */
2286 return err;
2284} 2287}
2285 2288
2286/* **************************** exit-time only **************************** */ 2289/* **************************** exit-time only **************************** */
@@ -2437,6 +2440,7 @@ static int __initdata initialized = 0;
2437static int __init matroxfb_init(void) 2440static int __init matroxfb_init(void)
2438{ 2441{
2439 char *option = NULL; 2442 char *option = NULL;
2443 int err = 0;
2440 2444
2441 DBG(__FUNCTION__) 2445 DBG(__FUNCTION__)
2442 2446
@@ -2448,11 +2452,11 @@ static int __init matroxfb_init(void)
2448 return -ENXIO; 2452 return -ENXIO;
2449 if (!initialized) { 2453 if (!initialized) {
2450 initialized = 1; 2454 initialized = 1;
2451 matrox_init(); 2455 err = matrox_init();
2452 } 2456 }
2453 hotplug = 1; 2457 hotplug = 1;
2454 /* never return failure, user can hotplug matrox later... */ 2458 /* never return failure, user can hotplug matrox later... */
2455 return 0; 2459 return err;
2456} 2460}
2457 2461
2458module_init(matroxfb_init); 2462module_init(matroxfb_init);
diff --git a/drivers/video/mbx/mbxfb.c b/drivers/video/mbx/mbxfb.c
index 6849ab75d403..a32d1af79e07 100644
--- a/drivers/video/mbx/mbxfb.c
+++ b/drivers/video/mbx/mbxfb.c
@@ -118,8 +118,19 @@ static unsigned int mbxfb_get_pixclock(unsigned int pixclock_ps,
118 /* convert pixclock to KHz */ 118 /* convert pixclock to KHz */
119 pixclock = PICOS2KHZ(pixclock_ps); 119 pixclock = PICOS2KHZ(pixclock_ps);
120 120
121 /* PLL output freq = (ref_clk * M) / (N * 2^P)
122 *
123 * M: 1 to 63
124 * N: 1 to 7
125 * P: 0 to 7
126 */
127
128 /* RAPH: When N==1, the resulting pixel clock appears to
129 * get divided by 2. Preventing N=1 by starting the following
130 * loop at 2 prevents this. Is this a bug with my chip
131 * revision or something I dont understand? */
121 for (m = 1; m < 64; m++) { 132 for (m = 1; m < 64; m++) {
122 for (n = 1; n < 8; n++) { 133 for (n = 2; n < 8; n++) {
123 for (p = 0; p < 8; p++) { 134 for (p = 0; p < 8; p++) {
124 clk = (ref_clk * m) / (n * (1 << p)); 135 clk = (ref_clk * m) / (n * (1 << p));
125 err = (clk > pixclock) ? (clk - pixclock) : 136 err = (clk > pixclock) ? (clk - pixclock) :
@@ -244,8 +255,8 @@ static int mbxfb_set_par(struct fb_info *info)
244 255
245 /* setup resolution */ 256 /* setup resolution */
246 gsctrl &= ~(FMsk(GSCTRL_GSWIDTH) | FMsk(GSCTRL_GSHEIGHT)); 257 gsctrl &= ~(FMsk(GSCTRL_GSWIDTH) | FMsk(GSCTRL_GSHEIGHT));
247 gsctrl |= Gsctrl_Width(info->var.xres - 1) | 258 gsctrl |= Gsctrl_Width(info->var.xres) |
248 Gsctrl_Height(info->var.yres - 1); 259 Gsctrl_Height(info->var.yres);
249 writel(gsctrl, GSCTRL); 260 writel(gsctrl, GSCTRL);
250 udelay(1000); 261 udelay(1000);
251 262
@@ -402,8 +413,8 @@ static void __devinit setup_graphics(struct fb_info *fbi)
402{ 413{
403 unsigned long gsctrl; 414 unsigned long gsctrl;
404 415
405 gsctrl = GSCTRL_GAMMA_EN | Gsctrl_Width(fbi->var.xres - 1) | 416 gsctrl = GSCTRL_GAMMA_EN | Gsctrl_Width(fbi->var.xres) |
406 Gsctrl_Height(fbi->var.yres - 1); 417 Gsctrl_Height(fbi->var.yres);
407 switch (fbi->var.bits_per_pixel) { 418 switch (fbi->var.bits_per_pixel) {
408 case 16: 419 case 16:
409 if (fbi->var.green.length == 5) 420 if (fbi->var.green.length == 5)
diff --git a/drivers/video/nvidia/nv_i2c.c b/drivers/video/nvidia/nv_i2c.c
index 19eef3a09023..e48de3c9fd13 100644
--- a/drivers/video/nvidia/nv_i2c.c
+++ b/drivers/video/nvidia/nv_i2c.c
@@ -160,51 +160,12 @@ void nvidia_delete_i2c_busses(struct nvidia_par *par)
160 160
161} 161}
162 162
163static u8 *nvidia_do_probe_i2c_edid(struct nvidia_i2c_chan *chan)
164{
165 u8 start = 0x0;
166 struct i2c_msg msgs[] = {
167 {
168 .addr = 0x50,
169 .len = 1,
170 .buf = &start,
171 }, {
172 .addr = 0x50,
173 .flags = I2C_M_RD,
174 .len = EDID_LENGTH,
175 },
176 };
177 u8 *buf;
178
179 if (!chan->par)
180 return NULL;
181
182 buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
183 if (!buf) {
184 dev_warn(&chan->par->pci_dev->dev, "Out of memory!\n");
185 return NULL;
186 }
187 msgs[1].buf = buf;
188
189 if (i2c_transfer(&chan->adapter, msgs, 2) == 2)
190 return buf;
191 dev_dbg(&chan->par->pci_dev->dev, "Unable to read EDID block.\n");
192 kfree(buf);
193 return NULL;
194}
195
196int nvidia_probe_i2c_connector(struct fb_info *info, int conn, u8 **out_edid) 163int nvidia_probe_i2c_connector(struct fb_info *info, int conn, u8 **out_edid)
197{ 164{
198 struct nvidia_par *par = info->par; 165 struct nvidia_par *par = info->par;
199 u8 *edid = NULL; 166 u8 *edid;
200 int i; 167
201 168 edid = fb_ddc_read(&par->chan[conn - 1].adapter);
202 for (i = 0; i < 3; i++) {
203 /* Do the real work */
204 edid = nvidia_do_probe_i2c_edid(&par->chan[conn - 1]);
205 if (edid)
206 break;
207 }
208 169
209 if (!edid && conn == 1) { 170 if (!edid && conn == 1) {
210 /* try to get from firmware */ 171 /* try to get from firmware */
diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
index d4f850117874..eb24107bcc81 100644
--- a/drivers/video/nvidia/nvidia.c
+++ b/drivers/video/nvidia/nvidia.c
@@ -28,6 +28,9 @@
28#include <asm/prom.h> 28#include <asm/prom.h>
29#include <asm/pci-bridge.h> 29#include <asm/pci-bridge.h>
30#endif 30#endif
31#ifdef CONFIG_BOOTX_TEXT
32#include <asm/btext.h>
33#endif
31 34
32#include "nv_local.h" 35#include "nv_local.h"
33#include "nv_type.h" 36#include "nv_type.h"
@@ -681,6 +684,13 @@ static int nvidiafb_set_par(struct fb_info *info)
681 684
682 nvidia_vga_protect(par, 0); 685 nvidia_vga_protect(par, 0);
683 686
687#ifdef CONFIG_BOOTX_TEXT
688 /* Update debug text engine */
689 btext_update_display(info->fix.smem_start,
690 info->var.xres, info->var.yres,
691 info->var.bits_per_pixel, info->fix.line_length);
692#endif
693
684 NVTRACE_LEAVE(); 694 NVTRACE_LEAVE();
685 return 0; 695 return 0;
686} 696}
@@ -950,24 +960,25 @@ static struct fb_ops nvidia_fb_ops = {
950}; 960};
951 961
952#ifdef CONFIG_PM 962#ifdef CONFIG_PM
953static int nvidiafb_suspend(struct pci_dev *dev, pm_message_t state) 963static int nvidiafb_suspend(struct pci_dev *dev, pm_message_t mesg)
954{ 964{
955 struct fb_info *info = pci_get_drvdata(dev); 965 struct fb_info *info = pci_get_drvdata(dev);
956 struct nvidia_par *par = info->par; 966 struct nvidia_par *par = info->par;
957 967
968 if (mesg.event == PM_EVENT_PRETHAW)
969 mesg.event = PM_EVENT_FREEZE;
958 acquire_console_sem(); 970 acquire_console_sem();
959 par->pm_state = state.event; 971 par->pm_state = mesg.event;
960 972
961 if (state.event == PM_EVENT_FREEZE) { 973 if (mesg.event == PM_EVENT_SUSPEND) {
962 dev->dev.power.power_state = state;
963 } else {
964 fb_set_suspend(info, 1); 974 fb_set_suspend(info, 1);
965 nvidiafb_blank(FB_BLANK_POWERDOWN, info); 975 nvidiafb_blank(FB_BLANK_POWERDOWN, info);
966 nvidia_write_regs(par, &par->SavedReg); 976 nvidia_write_regs(par, &par->SavedReg);
967 pci_save_state(dev); 977 pci_save_state(dev);
968 pci_disable_device(dev); 978 pci_disable_device(dev);
969 pci_set_power_state(dev, pci_choose_state(dev, state)); 979 pci_set_power_state(dev, pci_choose_state(dev, mesg));
970 } 980 }
981 dev->dev.power.power_state = mesg;
971 982
972 release_console_sem(); 983 release_console_sem();
973 return 0; 984 return 0;
@@ -983,7 +994,10 @@ static int nvidiafb_resume(struct pci_dev *dev)
983 994
984 if (par->pm_state != PM_EVENT_FREEZE) { 995 if (par->pm_state != PM_EVENT_FREEZE) {
985 pci_restore_state(dev); 996 pci_restore_state(dev);
986 pci_enable_device(dev); 997
998 if (pci_enable_device(dev))
999 goto fail;
1000
987 pci_set_master(dev); 1001 pci_set_master(dev);
988 } 1002 }
989 1003
@@ -992,6 +1006,7 @@ static int nvidiafb_resume(struct pci_dev *dev)
992 fb_set_suspend (info, 0); 1006 fb_set_suspend (info, 0);
993 nvidiafb_blank(FB_BLANK_UNBLANK, info); 1007 nvidiafb_blank(FB_BLANK_UNBLANK, info);
994 1008
1009fail:
995 release_console_sem(); 1010 release_console_sem();
996 return 0; 1011 return 0;
997} 1012}
diff --git a/drivers/video/pvr2fb.c b/drivers/video/pvr2fb.c
index 940ba2be55e9..78dc59a1751b 100644
--- a/drivers/video/pvr2fb.c
+++ b/drivers/video/pvr2fb.c
@@ -187,7 +187,7 @@ static short do_blank = 0; /* (Un)Blank the screen */
187static unsigned int is_blanked = 0; /* Is the screen blanked? */ 187static unsigned int is_blanked = 0; /* Is the screen blanked? */
188 188
189#ifdef CONFIG_SH_STORE_QUEUES 189#ifdef CONFIG_SH_STORE_QUEUES
190static struct sq_mapping *pvr2fb_map; 190static unsigned long pvr2fb_map;
191#endif 191#endif
192 192
193#ifdef CONFIG_SH_DMA 193#ifdef CONFIG_SH_DMA
@@ -213,15 +213,17 @@ static irqreturn_t pvr2fb_interrupt(int irq, void *dev_id, struct pt_regs *fp);
213static int pvr2_init_cable(void); 213static int pvr2_init_cable(void);
214static int pvr2_get_param(const struct pvr2_params *p, const char *s, 214static int pvr2_get_param(const struct pvr2_params *p, const char *s,
215 int val, int size); 215 int val, int size);
216#ifdef CONFIG_SH_DMA
216static ssize_t pvr2fb_write(struct file *file, const char *buf, 217static ssize_t pvr2fb_write(struct file *file, const char *buf,
217 size_t count, loff_t *ppos); 218 size_t count, loff_t *ppos);
219#endif
218 220
219static struct fb_ops pvr2fb_ops = { 221static struct fb_ops pvr2fb_ops = {
220 .owner = THIS_MODULE, 222 .owner = THIS_MODULE,
221 .fb_setcolreg = pvr2fb_setcolreg, 223 .fb_setcolreg = pvr2fb_setcolreg,
222 .fb_blank = pvr2fb_blank, 224 .fb_blank = pvr2fb_blank,
223 .fb_check_var = pvr2fb_check_var, 225 .fb_check_var = pvr2fb_check_var,
224 .fb_set_par = pvr2fb_set_par, 226 .fb_set_par = pvr2fb_set_par,
225#ifdef CONFIG_SH_DMA 227#ifdef CONFIG_SH_DMA
226 .fb_write = pvr2fb_write, 228 .fb_write = pvr2fb_write,
227#endif 229#endif
@@ -783,7 +785,7 @@ static int __init pvr2fb_common_init(void)
783 goto out_err; 785 goto out_err;
784 } 786 }
785 787
786 fb_memset((unsigned long)fb_info->screen_base, 0, pvr2_fix.smem_len); 788 fb_memset(fb_info->screen_base, 0, pvr2_fix.smem_len);
787 789
788 pvr2_fix.ypanstep = nopan ? 0 : 1; 790 pvr2_fix.ypanstep = nopan ? 0 : 1;
789 pvr2_fix.ywrapstep = nowrap ? 0 : 1; 791 pvr2_fix.ywrapstep = nowrap ? 0 : 1;
@@ -820,7 +822,7 @@ static int __init pvr2fb_common_init(void)
820 modememused >> 10, (unsigned long)(fb_info->fix.smem_len >> 10)); 822 modememused >> 10, (unsigned long)(fb_info->fix.smem_len >> 10));
821 printk("fb%d: Mode %dx%d-%d pitch = %ld cable: %s video output: %s\n", 823 printk("fb%d: Mode %dx%d-%d pitch = %ld cable: %s video output: %s\n",
822 fb_info->node, fb_info->var.xres, fb_info->var.yres, 824 fb_info->node, fb_info->var.xres, fb_info->var.yres,
823 fb_info->var.bits_per_pixel, 825 fb_info->var.bits_per_pixel,
824 get_line_length(fb_info->var.xres, fb_info->var.bits_per_pixel), 826 get_line_length(fb_info->var.xres, fb_info->var.bits_per_pixel),
825 (char *)pvr2_get_param(cables, NULL, cable_type, 3), 827 (char *)pvr2_get_param(cables, NULL, cable_type, 3),
826 (char *)pvr2_get_param(outputs, NULL, video_output, 3)); 828 (char *)pvr2_get_param(outputs, NULL, video_output, 3));
@@ -829,10 +831,10 @@ static int __init pvr2fb_common_init(void)
829 printk(KERN_NOTICE "fb%d: registering with SQ API\n", fb_info->node); 831 printk(KERN_NOTICE "fb%d: registering with SQ API\n", fb_info->node);
830 832
831 pvr2fb_map = sq_remap(fb_info->fix.smem_start, fb_info->fix.smem_len, 833 pvr2fb_map = sq_remap(fb_info->fix.smem_start, fb_info->fix.smem_len,
832 fb_info->fix.id); 834 fb_info->fix.id, pgprot_val(PAGE_SHARED));
833 835
834 printk(KERN_NOTICE "fb%d: Mapped video memory to SQ addr 0x%lx\n", 836 printk(KERN_NOTICE "fb%d: Mapped video memory to SQ addr 0x%lx\n",
835 fb_info->node, pvr2fb_map->sq_addr); 837 fb_info->node, pvr2fb_map);
836#endif 838#endif
837 839
838 return 0; 840 return 0;
diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
index 4acde4f7dbf8..b120896c8ab4 100644
--- a/drivers/video/riva/fbdev.c
+++ b/drivers/video/riva/fbdev.c
@@ -393,8 +393,8 @@ static void riva_bl_init(struct riva_par *par)
393 mutex_lock(&info->bl_mutex); 393 mutex_lock(&info->bl_mutex);
394 info->bl_dev = bd; 394 info->bl_dev = bd;
395 fb_bl_default_curve(info, 0, 395 fb_bl_default_curve(info, 0,
396 0x158 * FB_BACKLIGHT_MAX / MAX_LEVEL, 396 MIN_LEVEL * FB_BACKLIGHT_MAX / MAX_LEVEL,
397 0x534 * FB_BACKLIGHT_MAX / MAX_LEVEL); 397 FB_BACKLIGHT_MAX);
398 mutex_unlock(&info->bl_mutex); 398 mutex_unlock(&info->bl_mutex);
399 399
400 down(&bd->sem); 400 down(&bd->sem);
@@ -784,7 +784,7 @@ static void riva_load_video_mode(struct fb_info *info)
784 784
785 NVTRACE_ENTER(); 785 NVTRACE_ENTER();
786 /* time to calculate */ 786 /* time to calculate */
787 rivafb_blank(1, info); 787 rivafb_blank(FB_BLANK_NORMAL, info);
788 788
789 bpp = info->var.bits_per_pixel; 789 bpp = info->var.bits_per_pixel;
790 if (bpp == 16 && info->var.green.length == 5) 790 if (bpp == 16 && info->var.green.length == 5)
@@ -917,7 +917,7 @@ static void riva_load_video_mode(struct fb_info *info)
917 par->current_state = newmode; 917 par->current_state = newmode;
918 riva_load_state(par, &par->current_state); 918 riva_load_state(par, &par->current_state);
919 par->riva.LockUnlock(&par->riva, 0); /* important for HW cursor */ 919 par->riva.LockUnlock(&par->riva, 0); /* important for HW cursor */
920 rivafb_blank(0, info); 920 rivafb_blank(FB_BLANK_UNBLANK, info);
921 NVTRACE_LEAVE(); 921 NVTRACE_LEAVE();
922} 922}
923 923
diff --git a/drivers/video/riva/rivafb-i2c.c b/drivers/video/riva/rivafb-i2c.c
index 9751c37c0bfd..c15b259af644 100644
--- a/drivers/video/riva/rivafb-i2c.c
+++ b/drivers/video/riva/rivafb-i2c.c
@@ -25,8 +25,6 @@
25#include "rivafb.h" 25#include "rivafb.h"
26#include "../edid.h" 26#include "../edid.h"
27 27
28#define RIVA_DDC 0x50
29
30static void riva_gpio_setscl(void* data, int state) 28static void riva_gpio_setscl(void* data, int state)
31{ 29{
32 struct riva_i2c_chan *chan = data; 30 struct riva_i2c_chan *chan = data;
@@ -158,50 +156,12 @@ void riva_delete_i2c_busses(struct riva_par *par)
158 par->chan[2].par = NULL; 156 par->chan[2].par = NULL;
159} 157}
160 158
161static u8 *riva_do_probe_i2c_edid(struct riva_i2c_chan *chan)
162{
163 u8 start = 0x0;
164 struct i2c_msg msgs[] = {
165 {
166 .addr = RIVA_DDC,
167 .len = 1,
168 .buf = &start,
169 }, {
170 .addr = RIVA_DDC,
171 .flags = I2C_M_RD,
172 .len = EDID_LENGTH,
173 },
174 };
175 u8 *buf;
176
177 if (!chan->par)
178 return NULL;
179
180 buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
181 if (!buf) {
182 dev_warn(&chan->par->pdev->dev, "Out of memory!\n");
183 return NULL;
184 }
185 msgs[1].buf = buf;
186
187 if (i2c_transfer(&chan->adapter, msgs, 2) == 2)
188 return buf;
189 dev_dbg(&chan->par->pdev->dev, "Unable to read EDID block.\n");
190 kfree(buf);
191 return NULL;
192}
193
194int riva_probe_i2c_connector(struct riva_par *par, int conn, u8 **out_edid) 159int riva_probe_i2c_connector(struct riva_par *par, int conn, u8 **out_edid)
195{ 160{
196 u8 *edid = NULL; 161 u8 *edid = NULL;
197 int i;
198 162
199 for (i = 0; i < 3; i++) { 163 edid = fb_ddc_read(&par->chan[conn-1].adapter);
200 /* Do the real work */ 164
201 edid = riva_do_probe_i2c_edid(&par->chan[conn-1]);
202 if (edid)
203 break;
204 }
205 if (out_edid) 165 if (out_edid)
206 *out_edid = edid; 166 *out_edid = edid;
207 if (!edid) 167 if (!edid)
diff --git a/drivers/video/savage/savagefb-i2c.c b/drivers/video/savage/savagefb-i2c.c
index e83befd16d63..3f94223b7f0c 100644
--- a/drivers/video/savage/savagefb-i2c.c
+++ b/drivers/video/savage/savagefb-i2c.c
@@ -148,7 +148,6 @@ static int savage_setup_i2c_bus(struct savagefb_i2c_chan *chan,
148 chan->adapter.algo_data = &chan->algo; 148 chan->adapter.algo_data = &chan->algo;
149 chan->adapter.dev.parent = &chan->par->pcidev->dev; 149 chan->adapter.dev.parent = &chan->par->pcidev->dev;
150 chan->algo.udelay = 40; 150 chan->algo.udelay = 40;
151 chan->algo.mdelay = 5;
152 chan->algo.timeout = 20; 151 chan->algo.timeout = 20;
153 chan->algo.data = chan; 152 chan->algo.data = chan;
154 153
@@ -214,52 +213,15 @@ void savagefb_delete_i2c_busses(struct fb_info *info)
214 par->chan.par = NULL; 213 par->chan.par = NULL;
215} 214}
216 215
217static u8 *savage_do_probe_i2c_edid(struct savagefb_i2c_chan *chan)
218{
219 u8 start = 0x0;
220 struct i2c_msg msgs[] = {
221 {
222 .addr = SAVAGE_DDC,
223 .len = 1,
224 .buf = &start,
225 }, {
226 .addr = SAVAGE_DDC,
227 .flags = I2C_M_RD,
228 .len = EDID_LENGTH,
229 },
230 };
231 u8 *buf = NULL;
232
233 if (chan->par) {
234 buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
235
236 if (buf) {
237 msgs[1].buf = buf;
238
239 if (i2c_transfer(&chan->adapter, msgs, 2) != 2) {
240 dev_dbg(&chan->par->pcidev->dev,
241 "Unable to read EDID block.\n");
242 kfree(buf);
243 buf = NULL;
244 }
245 }
246 }
247
248 return buf;
249}
250
251int savagefb_probe_i2c_connector(struct fb_info *info, u8 **out_edid) 216int savagefb_probe_i2c_connector(struct fb_info *info, u8 **out_edid)
252{ 217{
253 struct savagefb_par *par = info->par; 218 struct savagefb_par *par = info->par;
254 u8 *edid = NULL; 219 u8 *edid;
255 int i; 220
256 221 if (par->chan.par)
257 for (i = 0; i < 3; i++) { 222 edid = fb_ddc_read(&par->chan.adapter);
258 /* Do the real work */ 223 else
259 edid = savage_do_probe_i2c_edid(&par->chan); 224 edid = NULL;
260 if (edid)
261 break;
262 }
263 225
264 if (!edid) { 226 if (!edid) {
265 /* try to get from firmware */ 227 /* try to get from firmware */
diff --git a/drivers/video/savage/savagefb_driver.c b/drivers/video/savage/savagefb_driver.c
index 461e094e7b45..82b3deaae02d 100644
--- a/drivers/video/savage/savagefb_driver.c
+++ b/drivers/video/savage/savagefb_driver.c
@@ -2323,24 +2323,24 @@ static void __devexit savagefb_remove(struct pci_dev *dev)
2323 } 2323 }
2324} 2324}
2325 2325
2326static int savagefb_suspend(struct pci_dev* dev, pm_message_t state) 2326static int savagefb_suspend(struct pci_dev *dev, pm_message_t mesg)
2327{ 2327{
2328 struct fb_info *info = pci_get_drvdata(dev); 2328 struct fb_info *info = pci_get_drvdata(dev);
2329 struct savagefb_par *par = info->par; 2329 struct savagefb_par *par = info->par;
2330 2330
2331 DBG("savagefb_suspend"); 2331 DBG("savagefb_suspend");
2332 2332
2333 2333 if (mesg.event == PM_EVENT_PRETHAW)
2334 par->pm_state = state.event; 2334 mesg.event = PM_EVENT_FREEZE;
2335 par->pm_state = mesg.event;
2336 dev->dev.power.power_state = mesg;
2335 2337
2336 /* 2338 /*
2337 * For PM_EVENT_FREEZE, do not power down so the console 2339 * For PM_EVENT_FREEZE, do not power down so the console
2338 * can remain active. 2340 * can remain active.
2339 */ 2341 */
2340 if (state.event == PM_EVENT_FREEZE) { 2342 if (mesg.event == PM_EVENT_FREEZE)
2341 dev->dev.power.power_state = state;
2342 return 0; 2343 return 0;
2343 }
2344 2344
2345 acquire_console_sem(); 2345 acquire_console_sem();
2346 fb_set_suspend(info, 1); 2346 fb_set_suspend(info, 1);
@@ -2353,7 +2353,7 @@ static int savagefb_suspend(struct pci_dev* dev, pm_message_t state)
2353 savage_disable_mmio(par); 2353 savage_disable_mmio(par);
2354 pci_save_state(dev); 2354 pci_save_state(dev);
2355 pci_disable_device(dev); 2355 pci_disable_device(dev);
2356 pci_set_power_state(dev, pci_choose_state(dev, state)); 2356 pci_set_power_state(dev, pci_choose_state(dev, mesg));
2357 release_console_sem(); 2357 release_console_sem();
2358 2358
2359 return 0; 2359 return 0;
diff --git a/drivers/video/sis/init.h b/drivers/video/sis/init.h
index 7ecab87cef02..59d12844b4dd 100644
--- a/drivers/video/sis/init.h
+++ b/drivers/video/sis/init.h
@@ -77,16 +77,9 @@
77#include <linux/types.h> 77#include <linux/types.h>
78#include <asm/io.h> 78#include <asm/io.h>
79#include <linux/fb.h> 79#include <linux/fb.h>
80#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
81#include <video/fbcon.h>
82#endif
83#include "sis.h" 80#include "sis.h"
84#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
85#include <linux/sisfb.h>
86#else
87#include <video/sisfb.h> 81#include <video/sisfb.h>
88#endif 82#endif
89#endif
90 83
91/* Mode numbers */ 84/* Mode numbers */
92static const unsigned short ModeIndex_320x200[] = {0x59, 0x41, 0x00, 0x4f}; 85static const unsigned short ModeIndex_320x200[] = {0x59, 0x41, 0x00, 0x4f};
diff --git a/drivers/video/sis/init301.h b/drivers/video/sis/init301.h
index bc321dc57e92..4f3a28699d37 100644
--- a/drivers/video/sis/init301.h
+++ b/drivers/video/sis/init301.h
@@ -71,16 +71,9 @@
71#include <linux/types.h> 71#include <linux/types.h>
72#include <asm/io.h> 72#include <asm/io.h>
73#include <linux/fb.h> 73#include <linux/fb.h>
74#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
75#include <video/fbcon.h>
76#endif
77#include "sis.h" 74#include "sis.h"
78#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
79#include <linux/sisfb.h>
80#else
81#include <video/sisfb.h> 75#include <video/sisfb.h>
82#endif 76#endif
83#endif
84 77
85static const unsigned char SiS_YPbPrTable[3][64] = { 78static const unsigned char SiS_YPbPrTable[3][64] = {
86 { 79 {
diff --git a/drivers/video/sis/initextlfb.c b/drivers/video/sis/initextlfb.c
index 09f5d758b6c0..c3884a29f4c5 100644
--- a/drivers/video/sis/initextlfb.c
+++ b/drivers/video/sis/initextlfb.c
@@ -34,12 +34,10 @@
34#include <linux/types.h> 34#include <linux/types.h>
35#include <linux/fb.h> 35#include <linux/fb.h>
36 36
37#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
38int sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr, 37int sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr,
39 unsigned char modeno, unsigned char rateindex); 38 unsigned char modeno, unsigned char rateindex);
40int sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno, 39int sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno,
41 unsigned char rateindex, struct fb_var_screeninfo *var); 40 unsigned char rateindex, struct fb_var_screeninfo *var);
42#endif
43BOOLEAN sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, 41BOOLEAN sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno,
44 int *htotal, int *vtotal, unsigned char rateindex); 42 int *htotal, int *vtotal, unsigned char rateindex);
45 43
@@ -49,7 +47,6 @@ extern BOOLEAN SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *Mode
49extern void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata, 47extern void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata,
50 int xres, int yres, struct fb_var_screeninfo *var, BOOLEAN writeres); 48 int xres, int yres, struct fb_var_screeninfo *var, BOOLEAN writeres);
51 49
52#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
53int 50int
54sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr, unsigned char modeno, 51sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr, unsigned char modeno,
55 unsigned char rateindex) 52 unsigned char rateindex)
@@ -177,7 +174,6 @@ sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno,
177 174
178 return 1; 175 return 1;
179} 176}
180#endif /* Linux >= 2.5 */
181 177
182BOOLEAN 178BOOLEAN
183sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, int *htotal, 179sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, int *htotal,
diff --git a/drivers/video/sis/osdef.h b/drivers/video/sis/osdef.h
index f59568020eb2..d048bd39961b 100644
--- a/drivers/video/sis/osdef.h
+++ b/drivers/video/sis/osdef.h
@@ -100,11 +100,7 @@
100#define SIS315H 100#define SIS315H
101#endif 101#endif
102 102
103#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
104#define SIS_LINUX_KERNEL_26 103#define SIS_LINUX_KERNEL_26
105#else
106#define SIS_LINUX_KERNEL_24
107#endif
108 104
109#if !defined(SIS300) && !defined(SIS315H) 105#if !defined(SIS300) && !defined(SIS315H)
110#warning Neither CONFIG_FB_SIS_300 nor CONFIG_FB_SIS_315 is set 106#warning Neither CONFIG_FB_SIS_300 nor CONFIG_FB_SIS_315 is set
diff --git a/drivers/video/sis/sis_accel.c b/drivers/video/sis/sis_accel.c
index 3b7ce032e2ed..7addf91d2fea 100644
--- a/drivers/video/sis/sis_accel.c
+++ b/drivers/video/sis/sis_accel.c
@@ -32,22 +32,10 @@
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/fb.h> 34#include <linux/fb.h>
35#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
36#include <linux/console.h>
37#endif
38#include <linux/ioport.h> 35#include <linux/ioport.h>
39#include <linux/types.h> 36#include <linux/types.h>
40
41#include <asm/io.h> 37#include <asm/io.h>
42 38
43#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
44#include <video/fbcon.h>
45#include <video/fbcon-cfb8.h>
46#include <video/fbcon-cfb16.h>
47#include <video/fbcon-cfb24.h>
48#include <video/fbcon-cfb32.h>
49#endif
50
51#include "sis.h" 39#include "sis.h"
52#include "sis_accel.h" 40#include "sis_accel.h"
53 41
@@ -91,11 +79,9 @@ static const u8 sisPatALUConv[] =
91 0xFF, /* dest = 0xFF; 1, GXset, 0xF */ 79 0xFF, /* dest = 0xFF; 1, GXset, 0xF */
92}; 80};
93 81
94#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,34)
95static const int myrops[] = { 82static const int myrops[] = {
96 3, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 83 3, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
97}; 84};
98#endif
99 85
100/* 300 series ----------------------------------------------------- */ 86/* 300 series ----------------------------------------------------- */
101#ifdef CONFIG_FB_SIS_300 87#ifdef CONFIG_FB_SIS_300
@@ -315,8 +301,6 @@ void sisfb_syncaccel(struct sis_video_info *ivideo)
315 } 301 }
316} 302}
317 303
318#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) /* --------------- 2.5 --------------- */
319
320int fbcon_sis_sync(struct fb_info *info) 304int fbcon_sis_sync(struct fb_info *info)
321{ 305{
322 struct sis_video_info *ivideo = (struct sis_video_info *)info->par; 306 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
@@ -438,13 +422,3 @@ void fbcon_sis_copyarea(struct fb_info *info, const struct fb_copyarea *area)
438 422
439 sisfb_syncaccel(ivideo); 423 sisfb_syncaccel(ivideo);
440} 424}
441
442#endif
443
444#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* -------------- 2.4 --------------- */
445
446#include "sisfb_accel_2_4.h"
447
448#endif /* KERNEL VERSION */
449
450
diff --git a/drivers/video/sis/sis_accel.h b/drivers/video/sis/sis_accel.h
index 046e2c4a8e09..30e03cdf6b85 100644
--- a/drivers/video/sis/sis_accel.h
+++ b/drivers/video/sis/sis_accel.h
@@ -390,25 +390,11 @@
390 MMIO_OUT32(ivideo->mmio_vbase, FIRE_TRIGGER, 0); \ 390 MMIO_OUT32(ivideo->mmio_vbase, FIRE_TRIGGER, 0); \
391 CmdQueLen -= 2; 391 CmdQueLen -= 2;
392 392
393
394int sisfb_initaccel(struct sis_video_info *ivideo); 393int sisfb_initaccel(struct sis_video_info *ivideo);
395void sisfb_syncaccel(struct sis_video_info *ivideo); 394void sisfb_syncaccel(struct sis_video_info *ivideo);
396 395
397#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,33)
398void fbcon_sis_bmove(struct display *p, int srcy, int srcx, int dsty,
399 int dstx, int height, int width);
400void fbcon_sis_revc(struct display *p, int srcy, int srcx);
401void fbcon_sis_clear8(struct vc_data *conp, struct display *p, int srcy,
402 int srcx, int height, int width);
403void fbcon_sis_clear16(struct vc_data *conp, struct display *p, int srcy,
404 int srcx, int height, int width);
405void fbcon_sis_clear32(struct vc_data *conp, struct display *p, int srcy,
406 int srcx, int height, int width);
407#endif
408#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,34)
409int fbcon_sis_sync(struct fb_info *info); 396int fbcon_sis_sync(struct fb_info *info);
410void fbcon_sis_fillrect(struct fb_info *info, const struct fb_fillrect *rect); 397void fbcon_sis_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
411void fbcon_sis_copyarea(struct fb_info *info, const struct fb_copyarea *area); 398void fbcon_sis_copyarea(struct fb_info *info, const struct fb_copyarea *area);
412#endif
413 399
414#endif 400#endif
diff --git a/drivers/video/sis/sis_main.c b/drivers/video/sis/sis_main.c
index 895ebda7d9e3..baaf495a0a6d 100644
--- a/drivers/video/sis/sis_main.c
+++ b/drivers/video/sis/sis_main.c
@@ -35,9 +35,7 @@
35 35
36#include <linux/version.h> 36#include <linux/version.h>
37#include <linux/module.h> 37#include <linux/module.h>
38#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
39#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
40#endif
41#include <linux/kernel.h> 39#include <linux/kernel.h>
42#include <linux/smp_lock.h> 40#include <linux/smp_lock.h>
43#include <linux/spinlock.h> 41#include <linux/spinlock.h>
@@ -58,9 +56,6 @@
58#include <linux/init.h> 56#include <linux/init.h>
59#include <linux/pci.h> 57#include <linux/pci.h>
60#include <linux/vmalloc.h> 58#include <linux/vmalloc.h>
61#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
62#include <linux/vt_kern.h>
63#endif
64#include <linux/capability.h> 59#include <linux/capability.h>
65#include <linux/fs.h> 60#include <linux/fs.h>
66#include <linux/types.h> 61#include <linux/types.h>
@@ -70,35 +65,9 @@
70#include <asm/mtrr.h> 65#include <asm/mtrr.h>
71#endif 66#endif
72 67
73#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
74#include <video/fbcon.h>
75#include <video/fbcon-cfb8.h>
76#include <video/fbcon-cfb16.h>
77#include <video/fbcon-cfb24.h>
78#include <video/fbcon-cfb32.h>
79#endif
80
81#include "sis.h" 68#include "sis.h"
82#include "sis_main.h" 69#include "sis_main.h"
83 70
84#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
85#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,3)
86#error "This version of sisfb requires at least 2.6.3"
87#endif
88#endif
89
90#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
91#ifdef FBCON_HAS_CFB8
92extern struct display_switch fbcon_sis8;
93#endif
94#ifdef FBCON_HAS_CFB16
95extern struct display_switch fbcon_sis16;
96#endif
97#ifdef FBCON_HAS_CFB32
98extern struct display_switch fbcon_sis32;
99#endif
100#endif
101
102static void sisfb_handle_command(struct sis_video_info *ivideo, 71static void sisfb_handle_command(struct sis_video_info *ivideo,
103 struct sisfb_cmd *sisfb_command); 72 struct sisfb_cmd *sisfb_command);
104 73
@@ -114,17 +83,7 @@ sisfb_setdefaultparms(void)
114 sisfb_max = -1; 83 sisfb_max = -1;
115 sisfb_userom = -1; 84 sisfb_userom = -1;
116 sisfb_useoem = -1; 85 sisfb_useoem = -1;
117#ifdef MODULE
118 /* Module: "None" for 2.4, default mode for 2.5+ */
119#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
120 sisfb_mode_idx = -1;
121#else
122 sisfb_mode_idx = MODE_INDEX_NONE;
123#endif
124#else
125 /* Static: Default mode */
126 sisfb_mode_idx = -1; 86 sisfb_mode_idx = -1;
127#endif
128 sisfb_parm_rate = -1; 87 sisfb_parm_rate = -1;
129 sisfb_crt1off = 0; 88 sisfb_crt1off = 0;
130 sisfb_forcecrt1 = -1; 89 sisfb_forcecrt1 = -1;
@@ -142,10 +101,6 @@ sisfb_setdefaultparms(void)
142 sisfb_tvxposoffset = 0; 101 sisfb_tvxposoffset = 0;
143 sisfb_tvyposoffset = 0; 102 sisfb_tvyposoffset = 0;
144 sisfb_nocrt2rate = 0; 103 sisfb_nocrt2rate = 0;
145#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
146 sisfb_inverse = 0;
147 sisfb_fontname[0] = 0;
148#endif
149#if !defined(__i386__) && !defined(__x86_64__) 104#if !defined(__i386__) && !defined(__x86_64__)
150 sisfb_resetcard = 0; 105 sisfb_resetcard = 0;
151 sisfb_videoram = 0; 106 sisfb_videoram = 0;
@@ -162,14 +117,11 @@ sisfb_search_vesamode(unsigned int vesamode, BOOLEAN quiet)
162 /* We don't know the hardware specs yet and there is no ivideo */ 117 /* We don't know the hardware specs yet and there is no ivideo */
163 118
164 if(vesamode == 0) { 119 if(vesamode == 0) {
165#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
166 sisfb_mode_idx = MODE_INDEX_NONE;
167#else
168 if(!quiet) 120 if(!quiet)
169 printk(KERN_ERR "sisfb: Invalid mode. Using default.\n"); 121 printk(KERN_ERR "sisfb: Invalid mode. Using default.\n");
170 122
171 sisfb_mode_idx = DEFAULT_MODE; 123 sisfb_mode_idx = DEFAULT_MODE;
172#endif 124
173 return; 125 return;
174 } 126 }
175 127
@@ -215,7 +167,6 @@ sisfb_search_mode(char *name, BOOLEAN quiet)
215 return; 167 return;
216 } 168 }
217 169
218#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
219 if(!strnicmp(name, sisbios_mode[MODE_INDEX_NONE].name, strlen(name))) { 170 if(!strnicmp(name, sisbios_mode[MODE_INDEX_NONE].name, strlen(name))) {
220 if(!quiet) 171 if(!quiet)
221 printk(KERN_ERR "sisfb: Mode 'none' not supported anymore. Using default.\n"); 172 printk(KERN_ERR "sisfb: Mode 'none' not supported anymore. Using default.\n");
@@ -223,7 +174,7 @@ sisfb_search_mode(char *name, BOOLEAN quiet)
223 sisfb_mode_idx = DEFAULT_MODE; 174 sisfb_mode_idx = DEFAULT_MODE;
224 return; 175 return;
225 } 176 }
226#endif 177
227 if(strlen(name) <= 19) { 178 if(strlen(name) <= 19) {
228 strcpy(strbuf1, name); 179 strcpy(strbuf1, name);
229 for(i = 0; i < strlen(strbuf1); i++) { 180 for(i = 0; i < strlen(strbuf1); i++) {
@@ -1315,20 +1266,7 @@ sisfb_do_set_var(struct fb_var_screeninfo *var, int isactive, struct fb_info *in
1315 ivideo->refresh_rate = 60; 1266 ivideo->refresh_rate = 60;
1316 } 1267 }
1317 1268
1318#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1319 if(ivideo->sisfb_thismonitor.datavalid) {
1320 if(!sisfb_verify_rate(ivideo, &ivideo->sisfb_thismonitor, ivideo->sisfb_mode_idx,
1321 ivideo->rate_idx, ivideo->refresh_rate)) {
1322 printk(KERN_INFO "sisfb: WARNING: Refresh rate exceeds monitor specs!\n");
1323 }
1324 }
1325#endif
1326
1327#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1328 if(((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) && isactive) {
1329#else
1330 if(isactive) { 1269 if(isactive) {
1331#endif
1332 /* If acceleration to be used? Need to know 1270 /* If acceleration to be used? Need to know
1333 * before pre/post_set_mode() 1271 * before pre/post_set_mode()
1334 */ 1272 */
@@ -1367,9 +1305,7 @@ sisfb_do_set_var(struct fb_var_screeninfo *var, int isactive, struct fb_info *in
1367 ivideo->current_linelength = ivideo->video_linelength; 1305 ivideo->current_linelength = ivideo->video_linelength;
1368 ivideo->current_pixclock = var->pixclock; 1306 ivideo->current_pixclock = var->pixclock;
1369 ivideo->current_refresh_rate = ivideo->refresh_rate; 1307 ivideo->current_refresh_rate = ivideo->refresh_rate;
1370#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1371 ivideo->sisfb_lastrates[ivideo->mode_no] = ivideo->refresh_rate; 1308 ivideo->sisfb_lastrates[ivideo->mode_no] = ivideo->refresh_rate;
1372#endif
1373 } 1309 }
1374 1310
1375 return 0; 1311 return 0;
@@ -1435,18 +1371,6 @@ sisfb_pan_var(struct sis_video_info *ivideo, struct fb_var_screeninfo *var)
1435 return 0; 1371 return 0;
1436} 1372}
1437 1373
1438/* ------------ FBDev related routines for 2.4 series ----------- */
1439
1440#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1441
1442#include "sisfb_fbdev_2_4.h"
1443
1444#endif
1445
1446/* ------------ FBDev related routines for 2.6 series ----------- */
1447
1448#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1449
1450static int 1374static int
1451sisfb_open(struct fb_info *info, int user) 1375sisfb_open(struct fb_info *info, int user)
1452{ 1376{
@@ -1744,8 +1668,6 @@ sisfb_blank(int blank, struct fb_info *info)
1744 return sisfb_myblank(ivideo, blank); 1668 return sisfb_myblank(ivideo, blank);
1745} 1669}
1746 1670
1747#endif
1748
1749/* ----------- FBDev related routines for all series ---------- */ 1671/* ----------- FBDev related routines for all series ---------- */
1750 1672
1751#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) 1673#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
@@ -1969,20 +1891,6 @@ sisfb_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info)
1969 1891
1970/* ---------------- fb_ops structures ----------------- */ 1892/* ---------------- fb_ops structures ----------------- */
1971 1893
1972#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1973static struct fb_ops sisfb_ops = {
1974 .owner = THIS_MODULE,
1975 .fb_get_fix = sisfb_get_fix,
1976 .fb_get_var = sisfb_get_var,
1977 .fb_set_var = sisfb_set_var,
1978 .fb_get_cmap = sisfb_get_cmap,
1979 .fb_set_cmap = sisfb_set_cmap,
1980 .fb_pan_display = sisfb_pan_display,
1981 .fb_ioctl = sisfb_ioctl
1982};
1983#endif
1984
1985#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1986static struct fb_ops sisfb_ops = { 1894static struct fb_ops sisfb_ops = {
1987 .owner = THIS_MODULE, 1895 .owner = THIS_MODULE,
1988 .fb_open = sisfb_open, 1896 .fb_open = sisfb_open,
@@ -2004,7 +1912,6 @@ static struct fb_ops sisfb_ops = {
2004#endif 1912#endif
2005 .fb_ioctl = sisfb_ioctl 1913 .fb_ioctl = sisfb_ioctl
2006}; 1914};
2007#endif
2008 1915
2009/* ---------------- Chip generation dependent routines ---------------- */ 1916/* ---------------- Chip generation dependent routines ---------------- */
2010 1917
@@ -4100,16 +4007,6 @@ sisfb_setup(char *options)
4100 sisfb_search_mode(this_opt + 5, FALSE); 4007 sisfb_search_mode(this_opt + 5, FALSE);
4101 } else if(!strnicmp(this_opt, "vesa:", 5)) { 4008 } else if(!strnicmp(this_opt, "vesa:", 5)) {
4102 sisfb_search_vesamode(simple_strtoul(this_opt + 5, NULL, 0), FALSE); 4009 sisfb_search_vesamode(simple_strtoul(this_opt + 5, NULL, 0), FALSE);
4103#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
4104 } else if(!strnicmp(this_opt, "inverse", 7)) {
4105 sisfb_inverse = 1;
4106 /* fb_invert_cmaps(); */
4107 } else if(!strnicmp(this_opt, "font:", 5)) {
4108 if(strlen(this_opt + 5) < 40) {
4109 strncpy(sisfb_fontname, this_opt + 5, sizeof(sisfb_fontname) - 1);
4110 sisfb_fontname[sizeof(sisfb_fontname) - 1] = '\0';
4111 }
4112#endif
4113 } else if(!strnicmp(this_opt, "rate:", 5)) { 4010 } else if(!strnicmp(this_opt, "rate:", 5)) {
4114 sisfb_parm_rate = simple_strtoul(this_opt + 5, NULL, 0); 4011 sisfb_parm_rate = simple_strtoul(this_opt + 5, NULL, 0);
4115 } else if(!strnicmp(this_opt, "forcecrt1:", 10)) { 4012 } else if(!strnicmp(this_opt, "forcecrt1:", 10)) {
@@ -5870,17 +5767,9 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5870 if(sisfb_off) 5767 if(sisfb_off)
5871 return -ENXIO; 5768 return -ENXIO;
5872 5769
5873#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,3))
5874 sis_fb_info = framebuffer_alloc(sizeof(*ivideo), &pdev->dev); 5770 sis_fb_info = framebuffer_alloc(sizeof(*ivideo), &pdev->dev);
5875 if(!sis_fb_info) 5771 if(!sis_fb_info)
5876 return -ENOMEM; 5772 return -ENOMEM;
5877#else
5878 sis_fb_info = kmalloc(sizeof(*sis_fb_info) + sizeof(*ivideo), GFP_KERNEL);
5879 if(!sis_fb_info)
5880 return -ENOMEM;
5881 memset(sis_fb_info, 0, sizeof(*sis_fb_info) + sizeof(*ivideo));
5882 sis_fb_info->par = ((char *)sis_fb_info + sizeof(*sis_fb_info));
5883#endif
5884 5773
5885 ivideo = (struct sis_video_info *)sis_fb_info->par; 5774 ivideo = (struct sis_video_info *)sis_fb_info->par;
5886 ivideo->memyselfandi = sis_fb_info; 5775 ivideo->memyselfandi = sis_fb_info;
@@ -5970,10 +5859,6 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5970 ivideo->tvxpos = sisfb_tvxposoffset; 5859 ivideo->tvxpos = sisfb_tvxposoffset;
5971 ivideo->tvypos = sisfb_tvyposoffset; 5860 ivideo->tvypos = sisfb_tvyposoffset;
5972 ivideo->sisfb_nocrt2rate = sisfb_nocrt2rate; 5861 ivideo->sisfb_nocrt2rate = sisfb_nocrt2rate;
5973#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,0)
5974 ivideo->sisfb_inverse = sisfb_inverse;
5975#endif
5976
5977 ivideo->refresh_rate = 0; 5862 ivideo->refresh_rate = 0;
5978 if(ivideo->sisfb_parm_rate != -1) { 5863 if(ivideo->sisfb_parm_rate != -1) {
5979 ivideo->refresh_rate = ivideo->sisfb_parm_rate; 5864 ivideo->refresh_rate = ivideo->sisfb_parm_rate;
@@ -6049,10 +5934,6 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
6049 } 5934 }
6050 } 5935 }
6051 5936
6052#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
6053 strcpy(sis_fb_info->modename, ivideo->myid);
6054#endif
6055
6056 ivideo->SiS_Pr.ChipType = ivideo->chip; 5937 ivideo->SiS_Pr.ChipType = ivideo->chip;
6057 5938
6058 ivideo->SiS_Pr.ivideo = (void *)ivideo; 5939 ivideo->SiS_Pr.ivideo = (void *)ivideo;
@@ -6134,20 +6015,6 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
6134#endif 6015#endif
6135 } 6016 }
6136 6017
6137#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
6138#ifdef MODULE
6139 if((reg & 0x80) && (reg != 0xff)) {
6140 if((sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni])
6141 != 0xFF) {
6142 printk(KERN_INFO "sisfb: Cannot initialize display mode, "
6143 "X server is active\n");
6144 ret = -EBUSY;
6145 goto error_4;
6146 }
6147 }
6148#endif
6149#endif
6150
6151 /* Search and copy ROM image */ 6018 /* Search and copy ROM image */
6152 ivideo->bios_abase = NULL; 6019 ivideo->bios_abase = NULL;
6153 ivideo->SiS_Pr.VirtualRomBase = NULL; 6020 ivideo->SiS_Pr.VirtualRomBase = NULL;
@@ -6281,9 +6148,6 @@ error_0: iounmap(ivideo->video_vbase);
6281error_1: release_mem_region(ivideo->video_base, ivideo->video_size); 6148error_1: release_mem_region(ivideo->video_base, ivideo->video_size);
6282error_2: release_mem_region(ivideo->mmio_base, ivideo->mmio_size); 6149error_2: release_mem_region(ivideo->mmio_base, ivideo->mmio_size);
6283error_3: vfree(ivideo->bios_abase); 6150error_3: vfree(ivideo->bios_abase);
6284#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
6285error_4:
6286#endif
6287 if(ivideo->lpcdev) 6151 if(ivideo->lpcdev)
6288 SIS_PCI_PUT_DEVICE(ivideo->lpcdev); 6152 SIS_PCI_PUT_DEVICE(ivideo->lpcdev);
6289 if(ivideo->nbridge) 6153 if(ivideo->nbridge)
@@ -6586,7 +6450,6 @@ error_4:
6586 sis_fb_info->fix = ivideo->sisfb_fix; 6450 sis_fb_info->fix = ivideo->sisfb_fix;
6587 sis_fb_info->screen_base = ivideo->video_vbase + ivideo->video_offset; 6451 sis_fb_info->screen_base = ivideo->video_vbase + ivideo->video_offset;
6588 sis_fb_info->fbops = &sisfb_ops; 6452 sis_fb_info->fbops = &sisfb_ops;
6589
6590 sisfb_get_fix(&sis_fb_info->fix, -1, sis_fb_info); 6453 sisfb_get_fix(&sis_fb_info->fix, -1, sis_fb_info);
6591 sis_fb_info->pseudo_palette = ivideo->pseudo_palette; 6454 sis_fb_info->pseudo_palette = ivideo->pseudo_palette;
6592 6455
@@ -6603,10 +6466,6 @@ error_4:
6603 } 6466 }
6604#endif 6467#endif
6605 6468
6606#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
6607 vc_resize_con(1, 1, 0);
6608#endif
6609
6610 if(register_framebuffer(sis_fb_info) < 0) { 6469 if(register_framebuffer(sis_fb_info) < 0) {
6611 printk(KERN_ERR "sisfb: Fatal error: Failed to register framebuffer\n"); 6470 printk(KERN_ERR "sisfb: Fatal error: Failed to register framebuffer\n");
6612 ret = -EINVAL; 6471 ret = -EINVAL;
@@ -6653,12 +6512,7 @@ error_4:
6653 6512
6654 6513
6655 printk(KERN_INFO "fb%d: %s frame buffer device version %d.%d.%d\n", 6514 printk(KERN_INFO "fb%d: %s frame buffer device version %d.%d.%d\n",
6656#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 6515 sis_fb_info->node, ivideo->myid, VER_MAJOR, VER_MINOR, VER_LEVEL);
6657 GET_FB_IDX(sis_fb_info->node),
6658#else
6659 sis_fb_info->node,
6660#endif
6661 ivideo->myid, VER_MAJOR, VER_MINOR, VER_LEVEL);
6662 6516
6663 printk(KERN_INFO "sisfb: Copyright (C) 2001-2005 Thomas Winischhofer\n"); 6517 printk(KERN_INFO "sisfb: Copyright (C) 2001-2005 Thomas Winischhofer\n");
6664 6518
@@ -6732,11 +6586,7 @@ static void __devexit sisfb_remove(struct pci_dev *pdev)
6732 /* Unregister the framebuffer */ 6586 /* Unregister the framebuffer */
6733 if(ivideo->registered) { 6587 if(ivideo->registered) {
6734 unregister_framebuffer(sis_fb_info); 6588 unregister_framebuffer(sis_fb_info);
6735#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,3))
6736 framebuffer_release(sis_fb_info); 6589 framebuffer_release(sis_fb_info);
6737#else
6738 kfree(sis_fb_info);
6739#endif
6740 } 6590 }
6741 6591
6742 /* OK, our ivideo is gone for good from here. */ 6592 /* OK, our ivideo is gone for good from here. */
@@ -6762,7 +6612,6 @@ static struct pci_driver sisfb_driver = {
6762 6612
6763SISINITSTATIC int __init sisfb_init(void) 6613SISINITSTATIC int __init sisfb_init(void)
6764{ 6614{
6765#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8)
6766#ifndef MODULE 6615#ifndef MODULE
6767 char *options = NULL; 6616 char *options = NULL;
6768 6617
@@ -6771,15 +6620,12 @@ SISINITSTATIC int __init sisfb_init(void)
6771 6620
6772 sisfb_setup(options); 6621 sisfb_setup(options);
6773#endif 6622#endif
6774#endif
6775 return pci_register_driver(&sisfb_driver); 6623 return pci_register_driver(&sisfb_driver);
6776} 6624}
6777 6625
6778#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8)
6779#ifndef MODULE 6626#ifndef MODULE
6780module_init(sisfb_init); 6627module_init(sisfb_init);
6781#endif 6628#endif
6782#endif
6783 6629
6784/*****************************************************/ 6630/*****************************************************/
6785/* MODULE */ 6631/* MODULE */
@@ -6799,9 +6645,6 @@ static int pdc1 = -1;
6799static int noaccel = -1; 6645static int noaccel = -1;
6800static int noypan = -1; 6646static int noypan = -1;
6801static int nomax = -1; 6647static int nomax = -1;
6802#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
6803static int inverse = 0;
6804#endif
6805static int userom = -1; 6648static int userom = -1;
6806static int useoem = -1; 6649static int useoem = -1;
6807static char *tvstandard = NULL; 6650static char *tvstandard = NULL;
@@ -6861,10 +6704,6 @@ static int __init sisfb_init_module(void)
6861 else if(nomax == 0) 6704 else if(nomax == 0)
6862 sisfb_max = 1; 6705 sisfb_max = 1;
6863 6706
6864#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
6865 if(inverse) sisfb_inverse = 1;
6866#endif
6867
6868 if(mem) 6707 if(mem)
6869 sisfb_parm_mem = mem; 6708 sisfb_parm_mem = mem;
6870 6709
@@ -6913,35 +6752,6 @@ MODULE_DESCRIPTION("SiS 300/540/630/730/315/55x/65x/661/74x/330/76x/34x, XGI V3X
6913MODULE_LICENSE("GPL"); 6752MODULE_LICENSE("GPL");
6914MODULE_AUTHOR("Thomas Winischhofer <thomas@winischhofer.net>, Others"); 6753MODULE_AUTHOR("Thomas Winischhofer <thomas@winischhofer.net>, Others");
6915 6754
6916#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
6917MODULE_PARM(mem, "i");
6918MODULE_PARM(noaccel, "i");
6919MODULE_PARM(noypan, "i");
6920MODULE_PARM(nomax, "i");
6921MODULE_PARM(userom, "i");
6922MODULE_PARM(useoem, "i");
6923MODULE_PARM(mode, "s");
6924MODULE_PARM(vesa, "i");
6925MODULE_PARM(rate, "i");
6926MODULE_PARM(forcecrt1, "i");
6927MODULE_PARM(forcecrt2type, "s");
6928MODULE_PARM(scalelcd, "i");
6929MODULE_PARM(pdc, "i");
6930MODULE_PARM(pdc1, "i");
6931MODULE_PARM(specialtiming, "s");
6932MODULE_PARM(lvdshl, "i");
6933MODULE_PARM(tvstandard, "s");
6934MODULE_PARM(tvxposoffset, "i");
6935MODULE_PARM(tvyposoffset, "i");
6936MODULE_PARM(nocrt2rate, "i");
6937MODULE_PARM(inverse, "i");
6938#if !defined(__i386__) && !defined(__x86_64__)
6939MODULE_PARM(resetcard, "i");
6940MODULE_PARM(videoram, "i");
6941#endif
6942#endif
6943
6944#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
6945module_param(mem, int, 0); 6755module_param(mem, int, 0);
6946module_param(noaccel, int, 0); 6756module_param(noaccel, int, 0);
6947module_param(noypan, int, 0); 6757module_param(noypan, int, 0);
@@ -6966,18 +6776,7 @@ module_param(nocrt2rate, int, 0);
6966module_param(resetcard, int, 0); 6776module_param(resetcard, int, 0);
6967module_param(videoram, int, 0); 6777module_param(videoram, int, 0);
6968#endif 6778#endif
6969#endif
6970 6779
6971#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
6972MODULE_PARM_DESC(mem,
6973 "\nDetermines the beginning of the video memory heap in KB. This heap is used\n"
6974 "for video RAM management for eg. DRM/DRI. On 300 series, the default depends\n"
6975 "on the amount of video RAM available. If 8MB of video RAM or less is available,\n"
6976 "the heap starts at 4096KB, if between 8 and 16MB are available at 8192KB,\n"
6977 "otherwise at 12288KB. On 315/330/340 series, the heap size is 32KB by default.\n"
6978 "The value is to be specified without 'KB' and must match the MaxXFBMem setting\n"
6979 "for XFree86 4.x/X.org 6.7 and later.\n");
6980#else
6981MODULE_PARM_DESC(mem, 6780MODULE_PARM_DESC(mem,
6982 "\nDetermines the beginning of the video memory heap in KB. This heap is used\n" 6781 "\nDetermines the beginning of the video memory heap in KB. This heap is used\n"
6983 "for video RAM management for eg. DRM/DRI. On 300 series, the default depends\n" 6782 "for video RAM management for eg. DRM/DRI. On 300 series, the default depends\n"
@@ -6985,7 +6784,6 @@ MODULE_PARM_DESC(mem,
6985 "the heap starts at 4096KB, if between 8 and 16MB are available at 8192KB,\n" 6784 "the heap starts at 4096KB, if between 8 and 16MB are available at 8192KB,\n"
6986 "otherwise at 12288KB. On 315/330/340 series, the heap size is 32KB by default.\n" 6785 "otherwise at 12288KB. On 315/330/340 series, the heap size is 32KB by default.\n"
6987 "The value is to be specified without 'KB'.\n"); 6786 "The value is to be specified without 'KB'.\n");
6988#endif
6989 6787
6990MODULE_PARM_DESC(noaccel, 6788MODULE_PARM_DESC(noaccel,
6991 "\nIf set to anything other than 0, 2D acceleration will be disabled.\n" 6789 "\nIf set to anything other than 0, 2D acceleration will be disabled.\n"
@@ -7002,23 +6800,6 @@ MODULE_PARM_DESC(nomax,
7002 "enable the user to positively specify a virtual Y size of the screen using\n" 6800 "enable the user to positively specify a virtual Y size of the screen using\n"
7003 "fbset. (default: 0)\n"); 6801 "fbset. (default: 0)\n");
7004 6802
7005#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
7006MODULE_PARM_DESC(mode,
7007 "\nSelects the desired display mode in the format [X]x[Y]x[Depth], eg.\n"
7008 "1024x768x16. Other formats supported include XxY-Depth and\n"
7009 "XxY-Depth@Rate. If the parameter is only one (decimal or hexadecimal)\n"
7010 "number, it will be interpreted as a VESA mode number. (default: none if\n"
7011 "sisfb is a module; this leaves the console untouched and the driver will\n"
7012 "only do the video memory management for eg. DRM/DRI; 800x600x8 if sisfb\n"
7013 "is in the kernel)\n");
7014MODULE_PARM_DESC(vesa,
7015 "\nSelects the desired display mode by VESA defined mode number, eg. 0x117\n"
7016 "(default: 0x0000 if sisfb is a module; this leaves the console untouched\n"
7017 "and the driver will only do the video memory management for eg. DRM/DRI;\n"
7018 "0x0103 if sisfb is in the kernel)\n");
7019#endif
7020
7021#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
7022MODULE_PARM_DESC(mode, 6803MODULE_PARM_DESC(mode,
7023 "\nSelects the desired default display mode in the format XxYxDepth,\n" 6804 "\nSelects the desired default display mode in the format XxYxDepth,\n"
7024 "eg. 1024x768x16. Other formats supported include XxY-Depth and\n" 6805 "eg. 1024x768x16. Other formats supported include XxY-Depth and\n"
@@ -7028,7 +6809,6 @@ MODULE_PARM_DESC(mode,
7028MODULE_PARM_DESC(vesa, 6809MODULE_PARM_DESC(vesa,
7029 "\nSelects the desired default display mode by VESA defined mode number, eg.\n" 6810 "\nSelects the desired default display mode by VESA defined mode number, eg.\n"
7030 "0x117 (default: 0x0103)\n"); 6811 "0x117 (default: 0x0103)\n");
7031#endif
7032 6812
7033MODULE_PARM_DESC(rate, 6813MODULE_PARM_DESC(rate,
7034 "\nSelects the desired vertical refresh rate for CRT1 (external VGA) in Hz.\n" 6814 "\nSelects the desired vertical refresh rate for CRT1 (external VGA) in Hz.\n"
@@ -7094,12 +6874,6 @@ MODULE_PARM_DESC(nocrt2rate,
7094 "\nSetting this to 1 will force the driver to use the default refresh rate for\n" 6874 "\nSetting this to 1 will force the driver to use the default refresh rate for\n"
7095 "CRT2 if CRT2 type is VGA. (default: 0, use same rate as CRT1)\n"); 6875 "CRT2 if CRT2 type is VGA. (default: 0, use same rate as CRT1)\n");
7096 6876
7097#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
7098MODULE_PARM_DESC(inverse,
7099 "\nSetting this to anything but 0 should invert the display colors, but this\n"
7100 "does not seem to work. (default: 0)\n");
7101#endif
7102
7103#if !defined(__i386__) && !defined(__x86_64__) 6877#if !defined(__i386__) && !defined(__x86_64__)
7104#ifdef CONFIG_FB_SIS_300 6878#ifdef CONFIG_FB_SIS_300
7105MODULE_PARM_DESC(resetcard, 6879MODULE_PARM_DESC(resetcard,
diff --git a/drivers/video/sis/sis_main.h b/drivers/video/sis/sis_main.h
index 70b6df371b8e..88e4f1e41470 100644
--- a/drivers/video/sis/sis_main.h
+++ b/drivers/video/sis/sis_main.h
@@ -67,15 +67,7 @@ static int sisfb_ypan = -1;
67static int sisfb_max = -1; 67static int sisfb_max = -1;
68static int sisfb_userom = 1; 68static int sisfb_userom = 1;
69static int sisfb_useoem = -1; 69static int sisfb_useoem = -1;
70#ifdef MODULE
71#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
72static int sisfb_mode_idx = -1;
73#else
74static int sisfb_mode_idx = MODE_INDEX_NONE; /* Don't use a mode by default if we are a module */
75#endif
76#else
77static int sisfb_mode_idx = -1; /* Use a default mode if we are inside the kernel */ 70static int sisfb_mode_idx = -1; /* Use a default mode if we are inside the kernel */
78#endif
79static int sisfb_parm_rate = -1; 71static int sisfb_parm_rate = -1;
80static int sisfb_crt1off = 0; 72static int sisfb_crt1off = 0;
81static int sisfb_forcecrt1 = -1; 73static int sisfb_forcecrt1 = -1;
@@ -93,10 +85,6 @@ static int sisfb_tvstd = -1;
93static int sisfb_tvxposoffset = 0; 85static int sisfb_tvxposoffset = 0;
94static int sisfb_tvyposoffset = 0; 86static int sisfb_tvyposoffset = 0;
95static int sisfb_nocrt2rate = 0; 87static int sisfb_nocrt2rate = 0;
96#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
97static int sisfb_inverse = 0;
98static char sisfb_fontname[40];
99#endif
100#if !defined(__i386__) && !defined(__x86_64__) 88#if !defined(__i386__) && !defined(__x86_64__)
101static int sisfb_resetcard = 0; 89static int sisfb_resetcard = 0;
102static int sisfb_videoram = 0; 90static int sisfb_videoram = 0;
@@ -687,54 +675,8 @@ SISINITSTATIC int sisfb_init(void);
687static int sisfb_get_fix(struct fb_fix_screeninfo *fix, int con, 675static int sisfb_get_fix(struct fb_fix_screeninfo *fix, int con,
688 struct fb_info *info); 676 struct fb_info *info);
689 677
690#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
691static int sisfb_get_fix(struct fb_fix_screeninfo *fix,
692 int con,
693 struct fb_info *info);
694static int sisfb_get_var(struct fb_var_screeninfo *var,
695 int con,
696 struct fb_info *info);
697static int sisfb_set_var(struct fb_var_screeninfo *var,
698 int con,
699 struct fb_info *info);
700static void sisfb_crtc_to_var(struct sis_video_info *ivideo,
701 struct fb_var_screeninfo *var);
702static int sisfb_get_cmap(struct fb_cmap *cmap,
703 int kspc,
704 int con,
705 struct fb_info *info);
706static int sisfb_set_cmap(struct fb_cmap *cmap,
707 int kspc,
708 int con,
709 struct fb_info *info);
710static int sisfb_update_var(int con,
711 struct fb_info *info);
712static int sisfb_switch(int con,
713 struct fb_info *info);
714static void sisfb_blank(int blank,
715 struct fb_info *info);
716static void sisfb_set_disp(int con,
717 struct fb_var_screeninfo *var,
718 struct fb_info *info);
719static int sis_getcolreg(unsigned regno, unsigned *red, unsigned *green,
720 unsigned *blue, unsigned *transp,
721 struct fb_info *fb_info);
722static void sisfb_do_install_cmap(int con,
723 struct fb_info *info);
724static int sisfb_ioctl(struct inode *inode, struct file *file,
725 unsigned int cmd, unsigned long arg, int con,
726 struct fb_info *info);
727#endif
728
729#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
730#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
731static int sisfb_ioctl(struct fb_info *info, unsigned int cmd, 678static int sisfb_ioctl(struct fb_info *info, unsigned int cmd,
732 unsigned long arg); 679 unsigned long arg);
733#else
734static int sisfb_ioctl(struct inode *inode, struct file *file,
735 unsigned int cmd, unsigned long arg,
736 struct fb_info *info);
737#endif
738static int sisfb_set_par(struct fb_info *info); 680static int sisfb_set_par(struct fb_info *info);
739static int sisfb_blank(int blank, 681static int sisfb_blank(int blank,
740 struct fb_info *info); 682 struct fb_info *info);
@@ -743,7 +685,6 @@ extern void fbcon_sis_fillrect(struct fb_info *info,
743extern void fbcon_sis_copyarea(struct fb_info *info, 685extern void fbcon_sis_copyarea(struct fb_info *info,
744 const struct fb_copyarea *area); 686 const struct fb_copyarea *area);
745extern int fbcon_sis_sync(struct fb_info *info); 687extern int fbcon_sis_sync(struct fb_info *info);
746#endif
747 688
748/* Internal 2D accelerator functions */ 689/* Internal 2D accelerator functions */
749extern int sisfb_initaccel(struct sis_video_info *ivideo); 690extern int sisfb_initaccel(struct sis_video_info *ivideo);
@@ -811,16 +752,10 @@ extern BOOLEAN SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr);
811 752
812extern BOOLEAN sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, 753extern BOOLEAN sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno,
813 int *htotal, int *vtotal, unsigned char rateindex); 754 int *htotal, int *vtotal, unsigned char rateindex);
814#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
815extern int sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr, 755extern int sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr,
816 unsigned char modeno, unsigned char rateindex); 756 unsigned char modeno, unsigned char rateindex);
817extern int sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno, 757extern int sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno,
818 unsigned char rateindex, struct fb_var_screeninfo *var); 758 unsigned char rateindex, struct fb_var_screeninfo *var);
819#endif
820#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
821extern void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata, int xres,
822 int yres, struct fb_var_screeninfo *var, BOOLEAN writeres);
823#endif
824 759
825/* Chrontel TV, DDC and DPMS functions */ 760/* Chrontel TV, DDC and DPMS functions */
826extern unsigned short SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short reg); 761extern unsigned short SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short reg);
diff --git a/drivers/video/sis/vgatypes.h b/drivers/video/sis/vgatypes.h
index 831b9f42264b..05d08b7889a1 100644
--- a/drivers/video/sis/vgatypes.h
+++ b/drivers/video/sis/vgatypes.h
@@ -73,12 +73,10 @@ typedef unsigned int BOOLEAN;
73 73
74#ifdef SIS_LINUX_KERNEL 74#ifdef SIS_LINUX_KERNEL
75typedef unsigned long SISIOADDRESS; 75typedef unsigned long SISIOADDRESS;
76#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8)
77#include <linux/types.h> /* Need __iomem */ 76#include <linux/types.h> /* Need __iomem */
78#undef SISIOMEMTYPE 77#undef SISIOMEMTYPE
79#define SISIOMEMTYPE __iomem 78#define SISIOMEMTYPE __iomem
80#endif 79#endif
81#endif
82 80
83#ifdef SIS_XORG_XF86 81#ifdef SIS_XORG_XF86
84#if XF86_VERSION_CURRENT < XF86_VERSION_NUMERIC(4,2,0,0,0) 82#if XF86_VERSION_CURRENT < XF86_VERSION_NUMERIC(4,2,0,0,0)
diff --git a/drivers/video/sstfb.c b/drivers/video/sstfb.c
index dad54e73147b..711cb11d6eb3 100644
--- a/drivers/video/sstfb.c
+++ b/drivers/video/sstfb.c
@@ -17,7 +17,10 @@
17 * (port driver to new frambuffer infrastructure) 17 * (port driver to new frambuffer infrastructure)
18 * 01/2003 Helge Deller <deller@gmx.de> 18 * 01/2003 Helge Deller <deller@gmx.de>
19 * (initial work on fb hardware acceleration for voodoo2) 19 * (initial work on fb hardware acceleration for voodoo2)
20 * 20 * 08/2006 Alan Cox <alan@redhat.com>
21 * Remove never finished and bogus 24/32bit support
22 * Clean up macro abuse
23 * Minor tidying for format.
21 */ 24 */
22 25
23/* 26/*
@@ -40,6 +43,7 @@
40 through the fifo. warning: issuing a nop command seems to need pci_fifo 43 through the fifo. warning: issuing a nop command seems to need pci_fifo
41-FIXME: in case of failure in the init sequence, be sure we return to a safe 44-FIXME: in case of failure in the init sequence, be sure we return to a safe
42 state. 45 state.
46- FIXME: Use accelerator for 2D scroll
43-FIXME: 4MB boards have banked memory (FbiInit2 bits 1 & 20) 47-FIXME: 4MB boards have banked memory (FbiInit2 bits 1 & 20)
44 */ 48 */
45 49
@@ -67,9 +71,6 @@
67 71
68#undef SST_DEBUG 72#undef SST_DEBUG
69 73
70/* enable 24/32 bpp functions ? (completely untested!) */
71#undef EN_24_32_BPP
72
73/* 74/*
74 Default video mode . 75 Default video mode .
75 0 800x600@60 took from glide 76 0 800x600@60 took from glide
@@ -377,7 +378,11 @@ static void sstfb_clear_screen(struct fb_info *info)
377 * sstfb_check_var - Optional function. Validates a var passed in. 378 * sstfb_check_var - Optional function. Validates a var passed in.
378 * @var: frame buffer variable screen structure 379 * @var: frame buffer variable screen structure
379 * @info: frame buffer structure that represents a single frame buffer 380 * @info: frame buffer structure that represents a single frame buffer
381 *
382 * Limit to the abilities of a single chip as SLI is not supported
383 * by this driver.
380 */ 384 */
385
381static int sstfb_check_var(struct fb_var_screeninfo *var, 386static int sstfb_check_var(struct fb_var_screeninfo *var,
382 struct fb_info *info) 387 struct fb_info *info)
383{ 388{
@@ -390,7 +395,7 @@ static int sstfb_check_var(struct fb_var_screeninfo *var,
390 unsigned int freq; 395 unsigned int freq;
391 396
392 if (sst_calc_pll(PICOS2KHZ(var->pixclock), &freq, &par->pll)) { 397 if (sst_calc_pll(PICOS2KHZ(var->pixclock), &freq, &par->pll)) {
393 eprintk("Pixclock at %ld KHZ out of range\n", 398 printk(KERN_ERR "sstfb: Pixclock at %ld KHZ out of range\n",
394 PICOS2KHZ(var->pixclock)); 399 PICOS2KHZ(var->pixclock));
395 return -EINVAL; 400 return -EINVAL;
396 } 401 }
@@ -409,27 +414,15 @@ static int sstfb_check_var(struct fb_var_screeninfo *var,
409 case 0 ... 16 : 414 case 0 ... 16 :
410 var->bits_per_pixel = 16; 415 var->bits_per_pixel = 16;
411 break; 416 break;
412#ifdef EN_24_32_BPP
413 case 17 ... 24 :
414 var->bits_per_pixel = 24;
415 break;
416 case 25 ... 32 :
417 var->bits_per_pixel = 32;
418 break;
419#endif
420 default : 417 default :
421 eprintk("Unsupported bpp %d\n", var->bits_per_pixel); 418 printk(KERN_ERR "sstfb: Unsupported bpp %d\n", var->bits_per_pixel);
422 return -EINVAL; 419 return -EINVAL;
423 } 420 }
424 421
425 /* validity tests */ 422 /* validity tests */
426 if ((var->xres <= 1) || (yDim <= 0 ) 423 if (var->xres <= 1 || yDim <= 0 || var->hsync_len <= 1 ||
427 || (var->hsync_len <= 1) 424 hSyncOff <= 1 || var->left_margin <= 2 || vSyncOn <= 0 ||
428 || (hSyncOff <= 1) 425 vSyncOff <= 0 || vBackPorch <= 0) {
429 || (var->left_margin <= 2)
430 || (vSyncOn <= 0)
431 || (vSyncOff <= 0)
432 || (vBackPorch <= 0)) {
433 return -EINVAL; 426 return -EINVAL;
434 } 427 }
435 428
@@ -437,21 +430,17 @@ static int sstfb_check_var(struct fb_var_screeninfo *var,
437 /* Voodoo 2 limits */ 430 /* Voodoo 2 limits */
438 tiles_in_X = (var->xres + 63 ) / 64 * 2; 431 tiles_in_X = (var->xres + 63 ) / 64 * 2;
439 432
440 if (((var->xres - 1) >= POW2(11)) || (yDim >= POW2(11))) { 433 if (var->xres > POW2(11) || yDim >= POW2(11)) {
441 eprintk("Unsupported resolution %dx%d\n", 434 printk(KERN_ERR "sstfb: Unsupported resolution %dx%d\n",
442 var->xres, var->yres); 435 var->xres, var->yres);
443 return -EINVAL; 436 return -EINVAL;
444 } 437 }
445 438
446 if (((var->hsync_len-1) >= POW2(9)) 439 if (var->hsync_len > POW2(9) || hSyncOff > POW2(11) ||
447 || ((hSyncOff-1) >= POW2(11)) 440 var->left_margin - 2 >= POW2(9) || vSyncOn >= POW2(13) ||
448 || ((var->left_margin - 2) >= POW2(9)) 441 vSyncOff >= POW2(13) || vBackPorch >= POW2(9) ||
449 || (vSyncOn >= POW2(13)) 442 tiles_in_X >= POW2(6) || tiles_in_X <= 0) {
450 || (vSyncOff >= POW2(13)) 443 printk(KERN_ERR "sstfb: Unsupported timings\n");
451 || (vBackPorch >= POW2(9))
452 || (tiles_in_X >= POW2(6))
453 || (tiles_in_X <= 0)) {
454 eprintk("Unsupported Timings\n");
455 return -EINVAL; 444 return -EINVAL;
456 } 445 }
457 } else { 446 } else {
@@ -459,24 +448,20 @@ static int sstfb_check_var(struct fb_var_screeninfo *var,
459 tiles_in_X = (var->xres + 63 ) / 64; 448 tiles_in_X = (var->xres + 63 ) / 64;
460 449
461 if (var->vmode) { 450 if (var->vmode) {
462 eprintk("Interlace/Doublescan not supported %#x\n", 451 printk(KERN_ERR "sstfb: Interlace/doublescan not supported %#x\n",
463 var->vmode); 452 var->vmode);
464 return -EINVAL; 453 return -EINVAL;
465 } 454 }
466 if (((var->xres - 1) >= POW2(10)) || (var->yres >= POW2(10))) { 455 if (var->xres > POW2(10) || var->yres >= POW2(10)) {
467 eprintk("Unsupported resolution %dx%d\n", 456 printk(KERN_ERR "sstfb: Unsupported resolution %dx%d\n",
468 var->xres, var->yres); 457 var->xres, var->yres);
469 return -EINVAL; 458 return -EINVAL;
470 } 459 }
471 if (((var->hsync_len - 1) >= POW2(8)) 460 if (var->hsync_len > POW2(8) || hSyncOff - 1 > POW2(10) ||
472 || ((hSyncOff-1) >= POW2(10)) 461 var->left_margin - 2 >= POW2(8) || vSyncOn >= POW2(12) ||
473 || ((var->left_margin - 2) >= POW2(8)) 462 vSyncOff >= POW2(12) || vBackPorch >= POW2(8) ||
474 || (vSyncOn >= POW2(12)) 463 tiles_in_X >= POW2(4) || tiles_in_X <= 0) {
475 || (vSyncOff >= POW2(12)) 464 printk(KERN_ERR "sstfb: Unsupported timings\n");
476 || (vBackPorch >= POW2(8))
477 || (tiles_in_X >= POW2(4))
478 || (tiles_in_X <= 0)) {
479 eprintk("Unsupported Timings\n");
480 return -EINVAL; 465 return -EINVAL;
481 } 466 }
482 } 467 }
@@ -486,8 +471,8 @@ static int sstfb_check_var(struct fb_var_screeninfo *var,
486 real_length = tiles_in_X * (IS_VOODOO2(par) ? 32 : 64 ) 471 real_length = tiles_in_X * (IS_VOODOO2(par) ? 32 : 64 )
487 * ((var->bits_per_pixel == 16) ? 2 : 4); 472 * ((var->bits_per_pixel == 16) ? 2 : 4);
488 473
489 if ((real_length * yDim) > info->fix.smem_len) { 474 if (real_length * yDim > info->fix.smem_len) {
490 eprintk("Not enough video memory\n"); 475 printk(KERN_ERR "sstfb: Not enough video memory\n");
491 return -ENOMEM; 476 return -ENOMEM;
492 } 477 }
493 478
@@ -515,20 +500,6 @@ static int sstfb_check_var(struct fb_var_screeninfo *var,
515 var->blue.offset = 0; 500 var->blue.offset = 0;
516 var->transp.offset = 0; 501 var->transp.offset = 0;
517 break; 502 break;
518#ifdef EN_24_32_BPP
519 case 24: /* RGB 888 LfbMode 4 */
520 case 32: /* ARGB 8888 LfbMode 5 */
521 var->red.length = 8;
522 var->green.length = 8;
523 var->blue.length = 8;
524 var->transp.length = 0;
525
526 var->red.offset = 16;
527 var->green.offset = 8;
528 var->blue.offset = 0;
529 var->transp.offset = 0; /* in 24bpp we fake a 32 bpp mode */
530 break;
531#endif
532 default: 503 default:
533 return -EINVAL; 504 return -EINVAL;
534 } 505 }
@@ -653,13 +624,6 @@ static int sstfb_set_par(struct fb_info *info)
653 case 16: 624 case 16:
654 fbiinit1 |= SEL_SOURCE_VCLK_2X_SEL; 625 fbiinit1 |= SEL_SOURCE_VCLK_2X_SEL;
655 break; 626 break;
656#ifdef EN_24_32_BPP
657 case 24:
658 case 32:
659 /* sst_set_bits(FBIINIT1, SEL_SOURCE_VCLK_2X_DIV2 | EN_24BPP);*/
660 fbiinit1 |= SEL_SOURCE_VCLK_2X_SEL | EN_24BPP;
661 break;
662#endif
663 default: 627 default:
664 return -EINVAL; 628 return -EINVAL;
665 } 629 }
@@ -690,14 +654,6 @@ static int sstfb_set_par(struct fb_info *info)
690 case 16: 654 case 16:
691 lfbmode = LFB_565; 655 lfbmode = LFB_565;
692 break; 656 break;
693#ifdef EN_24_32_BPP
694 case 24:
695 lfbmode = LFB_888;
696 break;
697 case 32:
698 lfbmode = LFB_8888;
699 break;
700#endif
701 default: 657 default:
702 return -EINVAL; 658 return -EINVAL;
703 } 659 }
@@ -789,8 +745,7 @@ static int sstfb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
789 return -EFAULT; 745 return -EFAULT;
790 if (val > info->fix.smem_len) 746 if (val > info->fix.smem_len)
791 val = info->fix.smem_len; 747 val = info->fix.smem_len;
792 printk("filling %#x \n", val); 748 for (p = 0 ; p < val; p += 2)
793 for (p=0 ; p<val; p+=2)
794 writew(p >> 6, info->screen_base + p); 749 writew(p >> 6, info->screen_base + p);
795 return 0; 750 return 0;
796 751
@@ -802,13 +757,10 @@ static int sstfb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
802 pci_write_config_dword(sst_dev, PCI_INIT_ENABLE, 757 pci_write_config_dword(sst_dev, PCI_INIT_ENABLE,
803 tmp | PCI_EN_INIT_WR ); 758 tmp | PCI_EN_INIT_WR );
804 fbiinit0 = sst_read (FBIINIT0); 759 fbiinit0 = sst_read (FBIINIT0);
805 if (val) { 760 if (val)
806 sst_write(FBIINIT0, fbiinit0 & ~EN_VGA_PASSTHROUGH); 761 sst_write(FBIINIT0, fbiinit0 & ~EN_VGA_PASSTHROUGH);
807 iprintk("Disabling VGA pass-through\n"); 762 else
808 } else {
809 sst_write(FBIINIT0, fbiinit0 | EN_VGA_PASSTHROUGH); 763 sst_write(FBIINIT0, fbiinit0 | EN_VGA_PASSTHROUGH);
810 iprintk("Enabling VGA pass-through\n");
811 }
812 pci_write_config_dword(sst_dev, PCI_INIT_ENABLE, tmp); 764 pci_write_config_dword(sst_dev, PCI_INIT_ENABLE, tmp);
813 return 0; 765 return 0;
814 766
@@ -884,9 +836,9 @@ static int __devinit sst_get_memsize(struct fb_info *info, __u32 *memsize)
884 u8 __iomem *fbbase_virt = info->screen_base; 836 u8 __iomem *fbbase_virt = info->screen_base;
885 837
886 /* force memsize */ 838 /* force memsize */
887 if ((mem >= 1 ) && (mem <= 4)) { 839 if (mem >= 1 && mem <= 4) {
888 *memsize = (mem * 0x100000); 840 *memsize = (mem * 0x100000);
889 iprintk("supplied memsize: %#x\n", *memsize); 841 printk(KERN_INFO "supplied memsize: %#x\n", *memsize);
890 return 1; 842 return 1;
891 } 843 }
892 844
@@ -927,7 +879,7 @@ static int __devinit sst_detect_att(struct fb_info *info)
927 struct sstfb_par *par = info->par; 879 struct sstfb_par *par = info->par;
928 int i, mir, dir; 880 int i, mir, dir;
929 881
930 for (i=0; i<3; i++) { 882 for (i = 0; i < 3; i++) {
931 sst_dac_write(DACREG_WMA, 0); /* backdoor */ 883 sst_dac_write(DACREG_WMA, 0); /* backdoor */
932 sst_dac_read(DACREG_RMR); /* read 4 times RMR */ 884 sst_dac_read(DACREG_RMR); /* read 4 times RMR */
933 sst_dac_read(DACREG_RMR); 885 sst_dac_read(DACREG_RMR);
@@ -940,7 +892,7 @@ static int __devinit sst_detect_att(struct fb_info *info)
940 /*the 7th, device ID register */ 892 /*the 7th, device ID register */
941 dir = sst_dac_read(DACREG_RMR); 893 dir = sst_dac_read(DACREG_RMR);
942 f_ddprintk("mir: %#x, dir: %#x\n", mir, dir); 894 f_ddprintk("mir: %#x, dir: %#x\n", mir, dir);
943 if ((mir == DACREG_MIR_ATT ) && (dir == DACREG_DIR_ATT)) { 895 if (mir == DACREG_MIR_ATT && dir == DACREG_DIR_ATT) {
944 return 1; 896 return 1;
945 } 897 }
946 } 898 }
@@ -1134,12 +1086,6 @@ static void sst_set_vidmod_att_ti(struct fb_info *info, const int bpp)
1134 case 16: 1086 case 16:
1135 sst_dac_write(DACREG_RMR, (cr0 & 0x0f) | DACREG_CR0_16BPP); 1087 sst_dac_write(DACREG_RMR, (cr0 & 0x0f) | DACREG_CR0_16BPP);
1136 break; 1088 break;
1137#ifdef EN_24_32_BPP
1138 case 24:
1139 case 32:
1140 sst_dac_write(DACREG_RMR, (cr0 & 0x0f) | DACREG_CR0_24BPP);
1141 break;
1142#endif
1143 default: 1089 default:
1144 dprintk("%s: bad depth '%u'\n", __FUNCTION__, bpp); 1090 dprintk("%s: bad depth '%u'\n", __FUNCTION__, bpp);
1145 break; 1091 break;
@@ -1154,12 +1100,6 @@ static void sst_set_vidmod_ics(struct fb_info *info, const int bpp)
1154 case 16: 1100 case 16:
1155 sst_dac_write(DACREG_ICS_CMD, DACREG_ICS_CMD_16BPP); 1101 sst_dac_write(DACREG_ICS_CMD, DACREG_ICS_CMD_16BPP);
1156 break; 1102 break;
1157#ifdef EN_24_32_BPP
1158 case 24:
1159 case 32:
1160 sst_dac_write(DACREG_ICS_CMD, DACREG_ICS_CMD_24BPP);
1161 break;
1162#endif
1163 default: 1103 default:
1164 dprintk("%s: bad depth '%u'\n", __FUNCTION__, bpp); 1104 dprintk("%s: bad depth '%u'\n", __FUNCTION__, bpp);
1165 break; 1105 break;
@@ -1250,7 +1190,7 @@ static int __devinit sst_init(struct fb_info *info, struct sstfb_par *par)
1250 PCI_EN_INIT_WR | PCI_REMAP_DAC ); 1190 PCI_EN_INIT_WR | PCI_REMAP_DAC );
1251 /* detect dac type */ 1191 /* detect dac type */
1252 if (!sst_detect_dactype(info, par)) { 1192 if (!sst_detect_dactype(info, par)) {
1253 eprintk("Unknown dac type\n"); 1193 printk(KERN_ERR "sstfb: unknown dac type.\n");
1254 //FIXME watch it: we are not in a safe state, bad bad bad. 1194 //FIXME watch it: we are not in a safe state, bad bad bad.
1255 return 0; 1195 return 0;
1256 } 1196 }
@@ -1258,10 +1198,10 @@ static int __devinit sst_init(struct fb_info *info, struct sstfb_par *par)
1258 /* set graphic clock */ 1198 /* set graphic clock */
1259 par->gfx_clock = spec->default_gfx_clock; 1199 par->gfx_clock = spec->default_gfx_clock;
1260 if ((gfxclk >10 ) && (gfxclk < spec->max_gfxclk)) { 1200 if ((gfxclk >10 ) && (gfxclk < spec->max_gfxclk)) {
1261 iprintk("Using supplied graphic freq : %dMHz\n", gfxclk); 1201 printk(KERN_INFO "sstfb: Using supplied graphic freq : %dMHz\n", gfxclk);
1262 par->gfx_clock = gfxclk *1000; 1202 par->gfx_clock = gfxclk *1000;
1263 } else if (gfxclk) { 1203 } else if (gfxclk) {
1264 wprintk ("%dMhz is way out of spec! Using default\n", gfxclk); 1204 printk(KERN_WARNING "sstfb: %dMhz is way out of spec! Using default\n", gfxclk);
1265 } 1205 }
1266 1206
1267 sst_calc_pll(par->gfx_clock, &Fout, &gfx_timings); 1207 sst_calc_pll(par->gfx_clock, &Fout, &gfx_timings);
@@ -1396,7 +1336,7 @@ static int __devinit sstfb_probe(struct pci_dev *pdev,
1396 1336
1397 /* Enable device in PCI config. */ 1337 /* Enable device in PCI config. */
1398 if ((err=pci_enable_device(pdev))) { 1338 if ((err=pci_enable_device(pdev))) {
1399 eprintk("cannot enable device\n"); 1339 printk(KERN_ERR "cannot enable device\n");
1400 return err; 1340 return err;
1401 } 1341 }
1402 1342
@@ -1422,39 +1362,39 @@ static int __devinit sstfb_probe(struct pci_dev *pdev,
1422 fix->smem_start = fix->mmio_start + 0x400000; 1362 fix->smem_start = fix->mmio_start + 0x400000;
1423 1363
1424 if (!request_mem_region(fix->mmio_start, fix->mmio_len, "sstfb MMIO")) { 1364 if (!request_mem_region(fix->mmio_start, fix->mmio_len, "sstfb MMIO")) {
1425 eprintk("cannot reserve mmio memory\n"); 1365 printk(KERN_ERR "sstfb: cannot reserve mmio memory\n");
1426 goto fail_mmio_mem; 1366 goto fail_mmio_mem;
1427 } 1367 }
1428 1368
1429 if (!request_mem_region(fix->smem_start, 0x400000,"sstfb FB")) { 1369 if (!request_mem_region(fix->smem_start, 0x400000,"sstfb FB")) {
1430 eprintk("cannot reserve fb memory\n"); 1370 printk(KERN_ERR "sstfb: cannot reserve fb memory\n");
1431 goto fail_fb_mem; 1371 goto fail_fb_mem;
1432 } 1372 }
1433 1373
1434 par->mmio_vbase = ioremap_nocache(fix->mmio_start, 1374 par->mmio_vbase = ioremap_nocache(fix->mmio_start,
1435 fix->mmio_len); 1375 fix->mmio_len);
1436 if (!par->mmio_vbase) { 1376 if (!par->mmio_vbase) {
1437 eprintk("cannot remap register area %#lx\n", 1377 printk(KERN_ERR "sstfb: cannot remap register area %#lx\n",
1438 fix->mmio_start); 1378 fix->mmio_start);
1439 goto fail_mmio_remap; 1379 goto fail_mmio_remap;
1440 } 1380 }
1441 info->screen_base = ioremap_nocache(fix->smem_start, 0x400000); 1381 info->screen_base = ioremap_nocache(fix->smem_start, 0x400000);
1442 if (!info->screen_base) { 1382 if (!info->screen_base) {
1443 eprintk("cannot remap framebuffer %#lx\n", 1383 printk(KERN_ERR "sstfb: cannot remap framebuffer %#lx\n",
1444 fix->smem_start); 1384 fix->smem_start);
1445 goto fail_fb_remap; 1385 goto fail_fb_remap;
1446 } 1386 }
1447 1387
1448 if (!sst_init(info, par)) { 1388 if (!sst_init(info, par)) {
1449 eprintk("Init failed\n"); 1389 printk(KERN_ERR "sstfb: Init failed\n");
1450 goto fail; 1390 goto fail;
1451 } 1391 }
1452 sst_get_memsize(info, &fix->smem_len); 1392 sst_get_memsize(info, &fix->smem_len);
1453 strlcpy(fix->id, spec->name, sizeof(fix->id)); 1393 strlcpy(fix->id, spec->name, sizeof(fix->id));
1454 1394
1455 iprintk("%s (revision %d) with %s dac\n", 1395 printk(KERN_INFO "%s (revision %d) with %s dac\n",
1456 fix->id, par->revision, par->dac_sw.name); 1396 fix->id, par->revision, par->dac_sw.name);
1457 iprintk("framebuffer at %#lx, mapped to 0x%p, size %dMB\n", 1397 printk(KERN_INFO "framebuffer at %#lx, mapped to 0x%p, size %dMB\n",
1458 fix->smem_start, info->screen_base, 1398 fix->smem_start, info->screen_base,
1459 fix->smem_len >> 20); 1399 fix->smem_len >> 20);
1460 1400
@@ -1471,24 +1411,25 @@ static int __devinit sstfb_probe(struct pci_dev *pdev,
1471 fix->accel = FB_ACCEL_NONE; /* FIXME */ 1411 fix->accel = FB_ACCEL_NONE; /* FIXME */
1472 /* 1412 /*
1473 * According to the specs, the linelength must be of 1024 *pixels* 1413 * According to the specs, the linelength must be of 1024 *pixels*
1474 * and the 24bpp mode is in fact a 32 bpp mode. 1414 * and the 24bpp mode is in fact a 32 bpp mode (and both are in
1415 * fact dithered to 16bit).
1475 */ 1416 */
1476 fix->line_length = 2048; /* default value, for 24 or 32bit: 4096 */ 1417 fix->line_length = 2048; /* default value, for 24 or 32bit: 4096 */
1477 1418
1478 if ( mode_option && 1419 if ( mode_option &&
1479 fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 16)) { 1420 fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 16)) {
1480 eprintk("can't set supplied video mode. Using default\n"); 1421 printk(KERN_ERR "sstfb: can't set supplied video mode. Using default\n");
1481 info->var = sstfb_default; 1422 info->var = sstfb_default;
1482 } else 1423 } else
1483 info->var = sstfb_default; 1424 info->var = sstfb_default;
1484 1425
1485 if (sstfb_check_var(&info->var, info)) { 1426 if (sstfb_check_var(&info->var, info)) {
1486 eprintk("invalid default video mode.\n"); 1427 printk(KERN_ERR "sstfb: invalid default video mode.\n");
1487 goto fail; 1428 goto fail;
1488 } 1429 }
1489 1430
1490 if (sstfb_set_par(info)) { 1431 if (sstfb_set_par(info)) {
1491 eprintk("can't set default video mode.\n"); 1432 printk(KERN_ERR "sstfb: can't set default video mode.\n");
1492 goto fail; 1433 goto fail;
1493 } 1434 }
1494 1435
@@ -1497,7 +1438,7 @@ static int __devinit sstfb_probe(struct pci_dev *pdev,
1497 /* register fb */ 1438 /* register fb */
1498 info->device = &pdev->dev; 1439 info->device = &pdev->dev;
1499 if (register_framebuffer(info) < 0) { 1440 if (register_framebuffer(info) < 0) {
1500 eprintk("can't register framebuffer.\n"); 1441 printk(KERN_ERR "sstfb: can't register framebuffer.\n");
1501 goto fail; 1442 goto fail;
1502 } 1443 }
1503 1444
@@ -1711,4 +1652,3 @@ module_param(gfxclk, int, 0);
1711MODULE_PARM_DESC(gfxclk, "Force graphic chip frequency in MHz. DANGEROUS. (default=auto)"); 1652MODULE_PARM_DESC(gfxclk, "Force graphic chip frequency in MHz. DANGEROUS. (default=auto)");
1712module_param(slowpci, bool, 0); 1653module_param(slowpci, bool, 0);
1713MODULE_PARM_DESC(slowpci, "Uses slow PCI settings (0 or 1) (default=0)"); 1654MODULE_PARM_DESC(slowpci, "Uses slow PCI settings (0 or 1) (default=0)");
1714