aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acorn/char/Makefile1
-rw-r--r--drivers/acorn/char/i2c.c368
-rw-r--r--drivers/acorn/char/pcf8583.c284
-rw-r--r--drivers/acorn/char/pcf8583.h41
-rw-r--r--drivers/acpi/Kconfig12
-rw-r--r--drivers/acpi/asus_acpi.c7
-rw-r--r--drivers/acpi/ibm_acpi.c32
-rw-r--r--drivers/acpi/resources/rscreate.c25
-rw-r--r--drivers/acpi/toshiba_acpi.c7
-rw-r--r--drivers/acpi/video.c36
-rw-r--r--drivers/ata/Kconfig22
-rw-r--r--drivers/ata/Makefile3
-rw-r--r--drivers/ata/ahci.c70
-rw-r--r--drivers/ata/ata_generic.c10
-rw-r--r--drivers/ata/ata_piix.c17
-rw-r--r--drivers/ata/libata-acpi.c702
-rw-r--r--drivers/ata/libata-core.c316
-rw-r--r--drivers/ata/libata-eh.c249
-rw-r--r--drivers/ata/libata-scsi.c46
-rw-r--r--drivers/ata/libata-sff.c8
-rw-r--r--drivers/ata/libata.h28
-rw-r--r--drivers/ata/pata_ali.c8
-rw-r--r--drivers/ata/pata_amd.c12
-rw-r--r--drivers/ata/pata_atiixp.c4
-rw-r--r--drivers/ata/pata_cmd64x.c8
-rw-r--r--drivers/ata/pata_cs5520.c35
-rw-r--r--drivers/ata/pata_cs5530.c8
-rw-r--r--drivers/ata/pata_cs5535.c4
-rw-r--r--drivers/ata/pata_cypress.c4
-rw-r--r--drivers/ata/pata_efar.c4
-rw-r--r--drivers/ata/pata_hpt366.c9
-rw-r--r--drivers/ata/pata_hpt37x.c2
-rw-r--r--drivers/ata/pata_hpt3x3.c6
-rw-r--r--drivers/ata/pata_isapnp.c3
-rw-r--r--drivers/ata/pata_it8213.c4
-rw-r--r--drivers/ata/pata_it821x.c10
-rw-r--r--drivers/ata/pata_ixp4xx_cf.c7
-rw-r--r--drivers/ata/pata_jmicron.c57
-rw-r--r--drivers/ata/pata_legacy.c22
-rw-r--r--drivers/ata/pata_marvell.c4
-rw-r--r--drivers/ata/pata_mpc52xx.c4
-rw-r--r--drivers/ata/pata_mpiix.c4
-rw-r--r--drivers/ata/pata_netcell.c4
-rw-r--r--drivers/ata/pata_ns87410.c4
-rw-r--r--drivers/ata/pata_oldpiix.c9
-rw-r--r--drivers/ata/pata_opti.c6
-rw-r--r--drivers/ata/pata_optidma.c6
-rw-r--r--drivers/ata/pata_pcmcia.c10
-rw-r--r--drivers/ata/pata_pdc2027x.c2
-rw-r--r--drivers/ata/pata_pdc202xx_old.c26
-rw-r--r--drivers/ata/pata_platform.c2
-rw-r--r--drivers/ata/pata_qdi.c14
-rw-r--r--drivers/ata/pata_radisys.c4
-rw-r--r--drivers/ata/pata_rz1000.c7
-rw-r--r--drivers/ata/pata_sc1200.c7
-rw-r--r--drivers/ata/pata_scc.c1230
-rw-r--r--drivers/ata/pata_serverworks.c8
-rw-r--r--drivers/ata/pata_sil680.c22
-rw-r--r--drivers/ata/pata_sis.c13
-rw-r--r--drivers/ata/pata_sl82c105.c42
-rw-r--r--drivers/ata/pata_triflex.c4
-rw-r--r--drivers/ata/pata_via.c8
-rw-r--r--drivers/ata/pata_winbond.c2
-rw-r--r--drivers/ata/pdc_adma.c4
-rw-r--r--drivers/ata/sata_inic162x.c7
-rw-r--r--drivers/ata/sata_mv.c39
-rw-r--r--drivers/ata/sata_nv.c248
-rw-r--r--drivers/ata/sata_promise.c32
-rw-r--r--drivers/ata/sata_qstor.c4
-rw-r--r--drivers/ata/sata_sil.c14
-rw-r--r--drivers/ata/sata_sil24.c7
-rw-r--r--drivers/ata/sata_sis.c5
-rw-r--r--drivers/ata/sata_svw.c2
-rw-r--r--drivers/ata/sata_sx4.c16
-rw-r--r--drivers/ata/sata_uli.c2
-rw-r--r--drivers/ata/sata_via.c30
-rw-r--r--drivers/ata/sata_vsc.c125
-rw-r--r--drivers/ata/sis.h5
-rw-r--r--drivers/atm/he.c2
-rw-r--r--drivers/atm/idt77252.c8
-rw-r--r--drivers/atm/nicstarmac.c4
-rw-r--r--drivers/auxdisplay/cfag12864b.c19
-rw-r--r--drivers/auxdisplay/cfag12864bfb.c10
-rw-r--r--drivers/auxdisplay/ks0108.c12
-rw-r--r--drivers/base/bus.c22
-rw-r--r--drivers/base/class.c45
-rw-r--r--drivers/base/core.c52
-rw-r--r--drivers/base/cpu.c2
-rw-r--r--drivers/base/node.c2
-rw-r--r--drivers/block/Kconfig16
-rw-r--r--drivers/block/aoe/aoecmd.c12
-rw-r--r--drivers/block/aoe/aoenet.c5
-rw-r--r--drivers/block/cciss.c49
-rw-r--r--drivers/block/floppy.c12
-rw-r--r--drivers/block/pktcdvd.c2
-rw-r--r--drivers/block/umem.c5
-rw-r--r--drivers/bluetooth/bcm203x.c2
-rw-r--r--drivers/bluetooth/bfusb.c1
-rw-r--r--drivers/bluetooth/bt3c_cs.c1
-rw-r--r--drivers/cdrom/viocd.c27
-rw-r--r--drivers/char/Kconfig15
-rw-r--r--drivers/char/agp/Makefile3
-rw-r--r--drivers/char/agp/agp.h8
-rw-r--r--drivers/char/agp/ali-agp.c6
-rw-r--r--drivers/char/agp/amd-k7-agp.c6
-rw-r--r--drivers/char/agp/amd64-agp.c4
-rw-r--r--drivers/char/agp/ati-agp.c4
-rw-r--r--drivers/char/agp/efficeon-agp.c6
-rw-r--r--drivers/char/agp/generic.c2
-rw-r--r--drivers/char/agp/hp-agp.c2
-rw-r--r--drivers/char/agp/i460-agp.c4
-rw-r--r--drivers/char/agp/intel-agp.c38
-rw-r--r--drivers/char/agp/nvidia-agp.c6
-rw-r--r--drivers/char/agp/parisc-agp.c4
-rw-r--r--drivers/char/agp/sgi-agp.c2
-rw-r--r--drivers/char/agp/sis-agp.c2
-rw-r--r--drivers/char/agp/sworks-agp.c6
-rw-r--r--drivers/char/agp/uninorth-agp.c8
-rw-r--r--drivers/char/agp/via-agp.c6
-rw-r--r--drivers/char/cyclades.c1
-rw-r--r--drivers/char/ds1286.c9
-rw-r--r--drivers/char/epca.c17
-rw-r--r--drivers/char/hvc_console.c16
-rw-r--r--drivers/char/ip2/i2lib.c4
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c5
-rw-r--r--drivers/char/lcd.c168
-rw-r--r--drivers/char/lcd.h32
-rw-r--r--drivers/char/mwave/3780i.c14
-rw-r--r--drivers/char/pcmcia/cm4040_cs.c3
-rw-r--r--drivers/char/rio/rio_linux.c2
-rw-r--r--drivers/char/tty_io.c21
-rw-r--r--drivers/char/watchdog/machzwd.c2
-rw-r--r--drivers/clocksource/acpi_pm.c5
-rw-r--r--drivers/clocksource/cyclone.c2
-rw-r--r--drivers/connector/connector.c22
-rw-r--r--drivers/cpufreq/cpufreq_ondemand.c5
-rw-r--r--drivers/crypto/geode-aes.c3
-rw-r--r--drivers/hid/hid-core.c7
-rw-r--r--drivers/hid/hid-debug.c1
-rw-r--r--drivers/hid/hid-input.c37
-rw-r--r--drivers/hwmon/Kconfig11
-rw-r--r--drivers/hwmon/Makefile1
-rw-r--r--drivers/hwmon/abituguru.c30
-rw-r--r--drivers/hwmon/adm1026.c1
-rw-r--r--drivers/hwmon/adm1029.c508
-rw-r--r--drivers/hwmon/f71805f.c30
-rw-r--r--drivers/hwmon/hwmon.c2
-rw-r--r--drivers/hwmon/it87.c84
-rw-r--r--drivers/hwmon/lm70.c2
-rw-r--r--drivers/hwmon/lm78.c6
-rw-r--r--drivers/hwmon/lm85.c8
-rw-r--r--drivers/hwmon/sis5595.c6
-rw-r--r--drivers/hwmon/via686a.c5
-rw-r--r--drivers/hwmon/vt1211.c58
-rw-r--r--drivers/hwmon/w83627ehf.c54
-rw-r--r--drivers/hwmon/w83627hf.c5
-rw-r--r--drivers/hwmon/w83781d.c10
-rw-r--r--drivers/i2c/busses/Kconfig10
-rw-r--r--drivers/i2c/busses/Makefile1
-rw-r--r--drivers/i2c/busses/i2c-acorn.c97
-rw-r--r--drivers/i2c/busses/i2c-ali1535.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-i801.c2
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c2
-rw-r--r--drivers/i2c/busses/i2c-piix4.c2
-rw-r--r--drivers/i2c/busses/i2c-pxa.c241
-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-via.c2
-rw-r--r--drivers/ide/Kconfig21
-rw-r--r--drivers/ide/Makefile1
-rw-r--r--drivers/ide/arm/icside.c25
-rw-r--r--drivers/ide/arm/rapide.c2
-rw-r--r--drivers/ide/cris/ide-cris.c36
-rw-r--r--drivers/ide/h8300/ide-h8300.c4
-rw-r--r--drivers/ide/ide-cd.c44
-rw-r--r--drivers/ide/ide-disk.c16
-rw-r--r--drivers/ide/ide-dma.c105
-rw-r--r--drivers/ide/ide-floppy.c29
-rw-r--r--drivers/ide/ide-io.c15
-rw-r--r--drivers/ide/ide-iops.c36
-rw-r--r--drivers/ide/ide-lib.c38
-rw-r--r--drivers/ide/ide-probe.c6
-rw-r--r--drivers/ide/ide-tape.c12
-rw-r--r--drivers/ide/ide.c63
-rw-r--r--drivers/ide/legacy/ali14xx.c11
-rw-r--r--drivers/ide/legacy/buddha.c2
-rw-r--r--drivers/ide/legacy/dtc2278.c14
-rw-r--r--drivers/ide/legacy/gayle.c2
-rw-r--r--drivers/ide/legacy/ht6560b.c24
-rw-r--r--drivers/ide/legacy/ide-cs.c7
-rw-r--r--drivers/ide/legacy/macide.c2
-rw-r--r--drivers/ide/legacy/q40ide.c2
-rw-r--r--drivers/ide/legacy/qd65xx.c14
-rw-r--r--drivers/ide/legacy/umc8672.c15
-rw-r--r--drivers/ide/mips/au1xxx-ide.c43
-rw-r--r--drivers/ide/mips/swarm.c2
-rw-r--r--drivers/ide/pci/aec62xx.c32
-rw-r--r--drivers/ide/pci/alim15x3.c50
-rw-r--r--drivers/ide/pci/amd74xx.c5
-rw-r--r--drivers/ide/pci/atiixp.c41
-rw-r--r--drivers/ide/pci/cmd640.c1
-rw-r--r--drivers/ide/pci/cmd64x.c153
-rw-r--r--drivers/ide/pci/cs5520.c5
-rw-r--r--drivers/ide/pci/cs5530.c41
-rw-r--r--drivers/ide/pci/cs5535.c19
-rw-r--r--drivers/ide/pci/cy82c693.c33
-rw-r--r--drivers/ide/pci/delkin_cb.c2
-rw-r--r--drivers/ide/pci/generic.c2
-rw-r--r--drivers/ide/pci/hpt34x.c42
-rw-r--r--drivers/ide/pci/hpt366.c24
-rw-r--r--drivers/ide/pci/it8213.c14
-rw-r--r--drivers/ide/pci/it821x.c14
-rw-r--r--drivers/ide/pci/jmicron.c14
-rw-r--r--drivers/ide/pci/ns87415.c13
-rw-r--r--drivers/ide/pci/opti621.c66
-rw-r--r--drivers/ide/pci/pdc202xx_new.c28
-rw-r--r--drivers/ide/pci/pdc202xx_old.c104
-rw-r--r--drivers/ide/pci/piix.c162
-rw-r--r--drivers/ide/pci/rz1000.c2
-rw-r--r--drivers/ide/pci/sc1200.c11
-rw-r--r--drivers/ide/pci/serverworks.c59
-rw-r--r--drivers/ide/pci/sgiioc4.c125
-rw-r--r--drivers/ide/pci/siimage.c118
-rw-r--r--drivers/ide/pci/sis5513.c59
-rw-r--r--drivers/ide/pci/sl82c105.c39
-rw-r--r--drivers/ide/pci/slc90e66.c56
-rw-r--r--drivers/ide/pci/tc86c001.c46
-rw-r--r--drivers/ide/pci/triflex.c24
-rw-r--r--drivers/ide/pci/trm290.c42
-rw-r--r--drivers/ide/pci/via82cxxx.c5
-rw-r--r--drivers/ide/ppc/pmac.c47
-rw-r--r--drivers/ide/ppc/scc_pata.c858
-rw-r--r--drivers/ieee1394/ieee1394-ioctl.h2
-rw-r--r--drivers/ieee1394/ieee1394_core.c43
-rw-r--r--drivers/ieee1394/ieee1394_core.h3
-rw-r--r--drivers/ieee1394/nodemgr.c3
-rw-r--r--drivers/ieee1394/ohci1394.c2
-rw-r--r--drivers/ieee1394/raw1394.c20
-rw-r--r--drivers/ieee1394/raw1394.h10
-rw-r--r--drivers/infiniband/core/Makefile2
-rw-r--r--drivers/infiniband/core/cm.c10
-rw-r--r--drivers/infiniband/core/cma.c363
-rw-r--r--drivers/infiniband/core/fmr_pool.c4
-rw-r--r--drivers/infiniband/core/iwcm.c47
-rw-r--r--drivers/infiniband/core/multicast.c837
-rw-r--r--drivers/infiniband/core/sa.h66
-rw-r--r--drivers/infiniband/core/sa_query.c30
-rw-r--r--drivers/infiniband/core/sysfs.c2
-rw-r--r--drivers/infiniband/core/ucma.c206
-rw-r--r--drivers/infiniband/core/uverbs_cmd.c4
-rw-r--r--drivers/infiniband/core/verbs.c2
-rw-r--r--drivers/infiniband/hw/cxgb3/Makefile1
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_dbg.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_hal.c33
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_hal.h6
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_resource.c15
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_resource.h1
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_wr.h1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch.h1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_cm.c26
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_cm.h1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_cq.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_ev.c13
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_mem.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_provider.c43
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_provider.h35
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_qp.c34
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_user.h1
-rw-r--r--drivers/infiniband/hw/ehca/Kconfig8
-rw-r--r--drivers/infiniband/hw/ehca/ehca_classes.h25
-rw-r--r--drivers/infiniband/hw/ehca/ehca_cq.c16
-rw-r--r--drivers/infiniband/hw/ehca/ehca_eq.c1
-rw-r--r--drivers/infiniband/hw/ehca/ehca_hca.c3
-rw-r--r--drivers/infiniband/hw/ehca/ehca_irq.c334
-rw-r--r--drivers/infiniband/hw/ehca/ehca_irq.h1
-rw-r--r--drivers/infiniband/hw/ehca/ehca_main.c32
-rw-r--r--drivers/infiniband/hw/ehca/ipz_pt_fn.h11
-rw-r--r--drivers/infiniband/hw/ipath/ipath_dma.c4
-rw-r--r--drivers/infiniband/hw/ipath/ipath_iba6110.c2
-rw-r--r--drivers/infiniband/hw/ipath/ipath_iba6120.c2
-rw-r--r--drivers/infiniband/hw/mthca/mthca_memfree.c4
-rw-r--r--drivers/infiniband/hw/mthca/mthca_mr.c10
-rw-r--r--drivers/infiniband/hw/mthca/mthca_qp.c15
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib.h1
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_cm.c50
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c2
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_multicast.c206
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_verbs.c13
-rw-r--r--drivers/input/input.c17
-rw-r--r--drivers/input/joystick/amijoy.c2
-rw-r--r--drivers/input/joystick/analog.c2
-rw-r--r--drivers/input/joystick/db9.c4
-rw-r--r--drivers/input/joystick/gamecon.c6
-rw-r--r--drivers/input/joystick/turbografx.c4
-rw-r--r--drivers/input/keyboard/Kconfig10
-rw-r--r--drivers/input/keyboard/atkbd.c4
-rw-r--r--drivers/input/keyboard/gpio_keys.c19
-rw-r--r--drivers/input/keyboard/hilkbd.c2
-rw-r--r--drivers/input/mouse/inport.c2
-rw-r--r--drivers/input/mouse/logibm.c2
-rw-r--r--drivers/input/mouse/psmouse-base.c34
-rw-r--r--drivers/input/mouse/psmouse.h1
-rw-r--r--drivers/input/mouse/synaptics.c1
-rw-r--r--drivers/input/serio/i8042.c73
-rw-r--r--drivers/input/serio/libps2.c2
-rw-r--r--drivers/input/serio/serio.c36
-rw-r--r--drivers/isdn/capi/Kconfig16
-rw-r--r--drivers/isdn/capi/capidrv.c28
-rw-r--r--drivers/isdn/capi/capiutil.c254
-rw-r--r--drivers/isdn/capi/kcapi.c77
-rw-r--r--drivers/isdn/gigaset/Makefile13
-rw-r--r--drivers/isdn/gigaset/asyncdata.c7
-rw-r--r--drivers/isdn/i4l/isdn_ppp.c2
-rw-r--r--drivers/kvm/kvm.h13
-rw-r--r--drivers/kvm/kvm_main.c776
-rw-r--r--drivers/kvm/kvm_svm.h3
-rw-r--r--drivers/kvm/mmu.c36
-rw-r--r--drivers/kvm/paging_tmpl.h18
-rw-r--r--drivers/kvm/svm.c42
-rw-r--r--drivers/kvm/vmx.c33
-rw-r--r--drivers/leds/Kconfig12
-rw-r--r--drivers/leds/Makefile2
-rw-r--r--drivers/leds/leds-cobalt.c43
-rw-r--r--drivers/leds/leds-h1940.c163
-rw-r--r--drivers/macintosh/via-pmu-backlight.c33
-rw-r--r--drivers/md/md.c140
-rw-r--r--drivers/md/raid10.c38
-rw-r--r--drivers/md/raid5.c161
-rw-r--r--drivers/md/raid6mmx.c16
-rw-r--r--drivers/md/raid6sse1.c17
-rw-r--r--drivers/md/raid6sse2.c22
-rw-r--r--drivers/md/raid6x86.h218
-rw-r--r--drivers/media/Kconfig1
-rw-r--r--drivers/media/common/Kconfig4
-rw-r--r--drivers/media/common/ir-functions.c110
-rw-r--r--drivers/media/common/ir-keymaps.c171
-rw-r--r--drivers/media/common/saa7146_fops.c2
-rw-r--r--drivers/media/dvb/b2c2/flexcop-fe-tuner.c90
-rw-r--r--drivers/media/dvb/bt8xx/bt878.c1
-rw-r--r--drivers/media/dvb/bt8xx/dst.c2
-rw-r--r--drivers/media/dvb/bt8xx/dvb-bt8xx.c3
-rw-r--r--drivers/media/dvb/cinergyT2/cinergyT2.c5
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c73
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.c17
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig28
-rw-r--r--drivers/media/dvb/dvb-usb/Makefile9
-rw-r--r--drivers/media/dvb/dvb-usb/au6610.c255
-rw-r--r--drivers/media/dvb/dvb-usb/au6610.h19
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.c4
-rw-r--r--drivers/media/dvb/dvb-usb/digitv.c2
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h5
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-remote.c2
-rw-r--r--drivers/media/dvb/dvb-usb/gl861.c231
-rw-r--r--drivers/media/dvb/dvb-usb/gl861.h15
-rw-r--r--drivers/media/dvb/dvb-usb/m920x.c541
-rw-r--r--drivers/media/dvb/dvb-usb/m920x.h35
-rw-r--r--drivers/media/dvb/frontends/Kconfig7
-rw-r--r--drivers/media/dvb/frontends/Makefile1
-rw-r--r--drivers/media/dvb/frontends/cx24110.c4
-rw-r--r--drivers/media/dvb/frontends/cx24123.c6
-rw-r--r--drivers/media/dvb/frontends/dib3000mb.c2
-rw-r--r--drivers/media/dvb/frontends/dib3000mc.c2
-rw-r--r--drivers/media/dvb/frontends/qt1010.c485
-rw-r--r--drivers/media/dvb/frontends/qt1010.h53
-rw-r--r--drivers/media/dvb/frontends/qt1010_priv.h105
-rw-r--r--drivers/media/dvb/frontends/stv0297.c19
-rw-r--r--drivers/media/dvb/frontends/stv0299.c2
-rw-r--r--drivers/media/dvb/frontends/tda10021.c2
-rw-r--r--drivers/media/dvb/frontends/tda1004x.c2
-rw-r--r--drivers/media/dvb/frontends/zl10353.c103
-rw-r--r--drivers/media/dvb/frontends/zl10353.h3
-rw-r--r--drivers/media/dvb/frontends/zl10353_priv.h36
-rw-r--r--drivers/media/dvb/ttpci/av7110.c57
-rw-r--r--drivers/media/dvb/ttpci/av7110.h2
-rw-r--r--drivers/media/dvb/ttpci/av7110_av.c42
-rw-r--r--drivers/media/dvb/ttpci/av7110_ca.c22
-rw-r--r--drivers/media/dvb/ttpci/av7110_ir.c18
-rw-r--r--drivers/media/dvb/ttpci/av7110_v4l.c30
-rw-r--r--drivers/media/dvb/ttpci/budget-av.c3
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c55
-rw-r--r--drivers/media/dvb/ttusb-dec/ttusb_dec.c4
-rw-r--r--drivers/media/radio/radio-aztech.c278
-rw-r--r--drivers/media/radio/radio-gemtek-pci.c18
-rw-r--r--drivers/media/radio/radio-maxiradio.c354
-rw-r--r--drivers/media/video/Kconfig2
-rw-r--r--drivers/media/video/Makefile1
-rw-r--r--drivers/media/video/bt8xx/bttv-cards.c23
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c893
-rw-r--r--drivers/media/video/bt8xx/bttv-input.c157
-rw-r--r--drivers/media/video/bt8xx/bttv-risc.c171
-rw-r--r--drivers/media/video/bt8xx/bttv-vbi.c368
-rw-r--r--drivers/media/video/bt8xx/bttv.h27
-rw-r--r--drivers/media/video/bt8xx/bttvp.h90
-rw-r--r--drivers/media/video/cafe_ccic.c6
-rw-r--r--drivers/media/video/cpia.c11
-rw-r--r--drivers/media/video/cx2341x.c17
-rw-r--r--drivers/media/video/cx25840/cx25840-core.c28
-rw-r--r--drivers/media/video/cx25840/cx25840-firmware.c2
-rw-r--r--drivers/media/video/cx88/Makefile5
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c581
-rw-r--r--drivers/media/video/cx88/cx88-cards.c6
-rw-r--r--drivers/media/video/cx88/cx88-core.c102
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c10
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c2
-rw-r--r--drivers/media/video/cx88/cx88-tvaudio.c49
-rw-r--r--drivers/media/video/cx88/cx88-vbi.c11
-rw-r--r--drivers/media/video/cx88/cx88-video.c1166
-rw-r--r--drivers/media/video/cx88/cx88.h55
-rw-r--r--drivers/media/video/et61x251/et61x251.h5
-rw-r--r--drivers/media/video/et61x251/et61x251_core.c129
-rw-r--r--drivers/media/video/et61x251/et61x251_sensor.h4
-rw-r--r--drivers/media/video/et61x251/et61x251_tas5130d1b.c2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-audio.c48
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-context.c3
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-ctrl.c45
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c29
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-debugifc.c4
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-eeprom.c5
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-encoder.c269
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-fx2-cmd.h62
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h36
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.c510
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.h44
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c16
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c69
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h3
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-core.c41
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-core.h3
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-io.c3
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-ioread.c3
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-std.c32
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-sysfs.c52
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-tuner.c5
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-v4l2.c339
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-video-v4l.c31
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-wm8775.c30
-rw-r--r--drivers/media/video/pwc/Makefile8
-rw-r--r--drivers/media/video/pwc/pwc-if.c8
-rw-r--r--drivers/media/video/pwc/pwc-v4l.c2
-rw-r--r--drivers/media/video/pwc/pwc.h9
-rw-r--r--drivers/media/video/saa5246a.c10
-rw-r--r--drivers/media/video/saa5246a.h9
-rw-r--r--drivers/media/video/saa5249.c41
-rw-r--r--drivers/media/video/saa7115.c59
-rw-r--r--drivers/media/video/saa7127.c20
-rw-r--r--drivers/media/video/saa7134/Makefile4
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c140
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c12
-rw-r--r--drivers/media/video/saa7134/saa7134-i2c.c24
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c93
-rw-r--r--drivers/media/video/saa7134/saa7134.h30
-rw-r--r--drivers/media/video/sn9c102/Kconfig4
-rw-r--r--drivers/media/video/sn9c102/Makefile2
-rw-r--r--drivers/media/video/sn9c102/sn9c102.h57
-rw-r--r--drivers/media/video/sn9c102/sn9c102_config.h86
-rw-r--r--drivers/media/video/sn9c102/sn9c102_core.c719
-rw-r--r--drivers/media/video/sn9c102/sn9c102_devtable.h142
-rw-r--r--drivers/media/video/sn9c102/sn9c102_hv7131d.c7
-rw-r--r--drivers/media/video/sn9c102/sn9c102_mi0343.c7
-rw-r--r--drivers/media/video/sn9c102/sn9c102_ov7630.c336
-rw-r--r--drivers/media/video/sn9c102/sn9c102_ov7660.c592
-rw-r--r--drivers/media/video/sn9c102/sn9c102_pas106b.c7
-rw-r--r--drivers/media/video/sn9c102/sn9c102_pas202bca.c238
-rw-r--r--drivers/media/video/sn9c102/sn9c102_pas202bcb.c97
-rw-r--r--drivers/media/video/sn9c102/sn9c102_sensor.h168
-rw-r--r--drivers/media/video/sn9c102/sn9c102_tas5110c1b.c8
-rw-r--r--drivers/media/video/sn9c102/sn9c102_tas5130d1b.c8
-rw-r--r--drivers/media/video/tvmixer.c3
-rw-r--r--drivers/media/video/tvp5150.c20
-rw-r--r--drivers/media/video/upd64031a.c22
-rw-r--r--drivers/media/video/upd64083.c22
-rw-r--r--drivers/media/video/usbvision/Kconfig2
-rw-r--r--drivers/media/video/usbvision/usbvision-core.c70
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c174
-rw-r--r--drivers/media/video/usbvision/usbvision.h11
-rw-r--r--drivers/media/video/v4l1-compat.c2
-rw-r--r--drivers/media/video/v4l2-common.c628
-rw-r--r--drivers/media/video/video-buf.c3
-rw-r--r--drivers/media/video/videodev.c56
-rw-r--r--drivers/media/video/vivi.c102
-rw-r--r--drivers/media/video/zc0301/zc0301.h4
-rw-r--r--drivers/media/video/zc0301/zc0301_core.c55
-rw-r--r--drivers/media/video/zc0301/zc0301_pas202bcb.c4
-rw-r--r--drivers/media/video/zc0301/zc0301_pb0330.c4
-rw-r--r--drivers/media/video/zc0301/zc0301_sensor.h12
-rw-r--r--drivers/mfd/Kconfig14
-rw-r--r--drivers/mfd/Makefile2
-rw-r--r--drivers/mfd/sm501.c1148
-rw-r--r--drivers/misc/asus-laptop.c31
-rw-r--r--drivers/misc/msi-laptop.c10
-rw-r--r--drivers/misc/sony-laptop.c16
-rw-r--r--drivers/mmc/at91_mci.c46
-rw-r--r--drivers/mmc/mmc.c83
-rw-r--r--drivers/mmc/sdhci.c39
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0001.c26
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0002.c2
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0020.c4
-rw-r--r--drivers/mtd/devices/doc2000.c1
-rw-r--r--drivers/mtd/devices/doc2001.c1
-rw-r--r--drivers/mtd/devices/doc2001plus.c1
-rw-r--r--drivers/mtd/maps/Kconfig2
-rw-r--r--drivers/mtd/maps/amd76xrom.c4
-rw-r--r--drivers/mtd/maps/ck804xrom.c6
-rw-r--r--drivers/mtd/maps/dilnetpc.c4
-rw-r--r--drivers/mtd/maps/esb2rom.c15
-rw-r--r--drivers/mtd/maps/ichxrom.c4
-rw-r--r--drivers/mtd/maps/netsc520.c4
-rw-r--r--drivers/mtd/maps/sc520cdp.c5
-rw-r--r--drivers/mtd/mtdchar.c5
-rw-r--r--drivers/mtd/mtdconcat.c5
-rw-r--r--drivers/mtd/mtdpart.c9
-rw-r--r--drivers/mtd/nand/Kconfig14
-rw-r--r--drivers/mtd/nand/Makefile1
-rw-r--r--drivers/mtd/nand/cafe.c89
-rw-r--r--drivers/mtd/nand/cafe_ecc.c2
-rw-r--r--drivers/mtd/nand/diskonchip.c2
-rw-r--r--drivers/mtd/nand/excite_nandflash.c248
-rw-r--r--drivers/mtd/nand/nand_base.c48
-rw-r--r--drivers/mtd/nand/s3c2410.c96
-rw-r--r--drivers/mtd/onenand/onenand_base.c651
-rw-r--r--drivers/mtd/onenand/onenand_bbt.c27
-rw-r--r--drivers/mtd/redboot.c19
-rw-r--r--drivers/net/3c59x.c36
-rw-r--r--drivers/net/8139cp.c3
-rw-r--r--drivers/net/8139too.c40
-rw-r--r--drivers/net/Kconfig43
-rw-r--r--drivers/net/acenic.c5
-rw-r--r--drivers/net/amd8111e.c3
-rw-r--r--drivers/net/arcnet/arc-rawmode.c4
-rw-r--r--drivers/net/arcnet/arcnet.c2
-rw-r--r--drivers/net/arcnet/com20020-pci.c3
-rw-r--r--drivers/net/arcnet/com20020.c2
-rw-r--r--drivers/net/atl1/atl1_hw.c37
-rw-r--r--drivers/net/atl1/atl1_main.c10
-rw-r--r--drivers/net/b44.c19
-rw-r--r--drivers/net/bnx2.c4
-rw-r--r--drivers/net/bonding/bond_main.c100
-rw-r--r--drivers/net/chelsio/cxgb2.c3
-rw-r--r--drivers/net/chelsio/sge.c1
-rw-r--r--drivers/net/cxgb3/adapter.h11
-rw-r--r--drivers/net/cxgb3/cxgb3_defs.h1
-rw-r--r--drivers/net/cxgb3/cxgb3_ioctl.h33
-rw-r--r--drivers/net/cxgb3/cxgb3_main.c69
-rw-r--r--drivers/net/cxgb3/cxgb3_offload.c7
-rw-r--r--drivers/net/cxgb3/cxgb3_offload.h1
-rw-r--r--drivers/net/cxgb3/l2t.c1
-rw-r--r--drivers/net/cxgb3/l2t.h1
-rw-r--r--drivers/net/cxgb3/sge.c390
-rw-r--r--drivers/net/cxgb3/t3_hw.c6
-rw-r--r--drivers/net/cxgb3/t3cdev.h1
-rw-r--r--drivers/net/cxgb3/version.h4
-rw-r--r--drivers/net/de600.c6
-rw-r--r--drivers/net/e1000/e1000.h1
-rw-r--r--drivers/net/e1000/e1000_ethtool.c2
-rw-r--r--drivers/net/e1000/e1000_hw.h2
-rw-r--r--drivers/net/e1000/e1000_main.c71
-rw-r--r--drivers/net/eexpress.c7
-rw-r--r--drivers/net/ehea/ehea.h2
-rw-r--r--drivers/net/ehea/ehea_main.c11
-rw-r--r--drivers/net/ehea/ehea_phyp.c10
-rw-r--r--drivers/net/ehea/ehea_phyp.h3
-rw-r--r--drivers/net/ehea/ehea_qmr.c42
-rw-r--r--drivers/net/ehea/ehea_qmr.h5
-rw-r--r--drivers/net/forcedeth.c20
-rw-r--r--drivers/net/gianfar.c88
-rw-r--r--drivers/net/gianfar_sysfs.c108
-rw-r--r--drivers/net/hamradio/Kconfig3
-rw-r--r--drivers/net/hamradio/baycom_epp.c13
-rw-r--r--drivers/net/hamradio/hdlcdrv.c13
-rw-r--r--drivers/net/hamradio/yam.c11
-rw-r--r--drivers/net/ioc3-eth.c16
-rw-r--r--drivers/net/ixgb/ixgb_main.c5
-rw-r--r--drivers/net/lasi_82596.c34
-rw-r--r--drivers/net/macb.c24
-rw-r--r--drivers/net/meth.c26
-rw-r--r--drivers/net/mv643xx_eth.c69
-rw-r--r--drivers/net/mv643xx_eth.h15
-rw-r--r--drivers/net/myri10ge/myri10ge.c91
-rw-r--r--drivers/net/natsemi.c69
-rw-r--r--drivers/net/netxen/netxen_nic.h13
-rw-r--r--drivers/net/netxen/netxen_nic_ethtool.c149
-rw-r--r--drivers/net/netxen/netxen_nic_hw.c21
-rw-r--r--drivers/net/netxen/netxen_nic_init.c40
-rw-r--r--drivers/net/netxen/netxen_nic_main.c18
-rw-r--r--drivers/net/netxen/netxen_nic_niu.c2
-rw-r--r--drivers/net/netxen/netxen_nic_phan_reg.h3
-rw-r--r--drivers/net/ni52.c2
-rw-r--r--drivers/net/ns83820.c3
-rw-r--r--drivers/net/pcmcia/3c574_cs.c2
-rw-r--r--drivers/net/pcmcia/smc91c92_cs.c2
-rw-r--r--drivers/net/pcnet32.c4
-rw-r--r--drivers/net/phy/marvell.c156
-rw-r--r--drivers/net/phy/phy_device.c4
-rw-r--r--drivers/net/pppoe.c53
-rwxr-xr-xdrivers/net/qla3xxx.c492
-rwxr-xr-xdrivers/net/qla3xxx.h11
-rw-r--r--drivers/net/r8169.c42
-rw-r--r--drivers/net/s2io-regs.h1
-rw-r--r--drivers/net/s2io.c321
-rw-r--r--drivers/net/s2io.h10
-rw-r--r--drivers/net/sgiseeq.c11
-rw-r--r--drivers/net/sis190.c7
-rw-r--r--drivers/net/sis900.c10
-rw-r--r--drivers/net/sk98lin/skge.c3
-rw-r--r--drivers/net/skfp/cfm.c2
-rw-r--r--drivers/net/skge.c56
-rw-r--r--drivers/net/skge.h3
-rw-r--r--drivers/net/sky2.c152
-rw-r--r--drivers/net/sky2.h3
-rw-r--r--drivers/net/spider_net.c554
-rw-r--r--drivers/net/spider_net.h34
-rw-r--r--drivers/net/starfire.c5
-rw-r--r--drivers/net/sun3_82586.c2
-rw-r--r--drivers/net/sungem_phy.c389
-rw-r--r--drivers/net/sungem_phy.h10
-rw-r--r--drivers/net/tc35815.c23
-rw-r--r--drivers/net/tg3.c23
-rw-r--r--drivers/net/tg3.h2
-rw-r--r--drivers/net/tokenring/ibmtr.c25
-rw-r--r--drivers/net/tulip/de2104x.c8
-rw-r--r--drivers/net/tulip/dmfe.c204
-rw-r--r--drivers/net/tulip/tulip_core.c2
-rw-r--r--drivers/net/typhoon.c3
-rw-r--r--drivers/net/ucc_geth.c21
-rw-r--r--drivers/net/via-rhine.c32
-rw-r--r--drivers/net/wan/Kconfig2
-rw-r--r--drivers/net/wan/cosa.c1
-rw-r--r--drivers/net/wan/hdlc.c33
-rw-r--r--drivers/net/wan/hdlc_cisco.c3
-rw-r--r--drivers/net/wan/hdlc_fr.c3
-rw-r--r--drivers/net/wan/hdlc_ppp.c2
-rw-r--r--drivers/net/wan/hdlc_raw.c3
-rw-r--r--drivers/net/wan/hdlc_x25.c2
-rw-r--r--drivers/net/wan/pc300too.c2
-rw-r--r--drivers/net/wan/z85230.c2
-rw-r--r--drivers/net/wireless/airo.c4
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx.h9
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_dma.c171
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_ilt.c15
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_ilt.h1
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_main.c56
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_phy.c203
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_radio.c13
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_wx.c38
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_xmit.h10
-rw-r--r--drivers/net/wireless/hostap/hostap.h3
-rw-r--r--drivers/net/wireless/ipw2100.c30
-rw-r--r--drivers/net/wireless/prism54/isl_ioctl.c8
-rw-r--r--drivers/net/wireless/prism54/oid_mgt.c4
-rw-r--r--drivers/net/wireless/wavelan.c14
-rw-r--r--drivers/net/wireless/wavelan.p.h3
-rw-r--r--drivers/net/wireless/wavelan_cs.c8
-rw-r--r--drivers/net/wireless/wl3501_cs.c1
-rw-r--r--drivers/net/wireless/zd1211rw/zd_chip.c2
-rw-r--r--drivers/net/wireless/zd1211rw/zd_mac.c44
-rw-r--r--drivers/net/wireless/zd1211rw/zd_usb.c12
-rw-r--r--drivers/parisc/hppb.c14
-rw-r--r--drivers/parisc/iosapic_private.h2
-rw-r--r--drivers/parisc/lba_pci.c90
-rw-r--r--drivers/parisc/led.c14
-rw-r--r--drivers/parisc/power.c201
-rw-r--r--drivers/parisc/sba_iommu.c4
-rw-r--r--drivers/parport/parport_pc.c6
-rw-r--r--drivers/pci/msi.c146
-rw-r--r--drivers/pci/pci-driver.c1
-rw-r--r--drivers/pci/pci-sysfs.c11
-rw-r--r--drivers/pci/pci.c46
-rw-r--r--drivers/pci/pci.h2
-rw-r--r--drivers/pci/pcie/aer/aerdrv.h2
-rw-r--r--drivers/pci/probe.c45
-rw-r--r--drivers/pci/quirks.c87
-rw-r--r--drivers/pci/setup-bus.c27
-rw-r--r--drivers/pci/setup-irq.c18
-rw-r--r--drivers/pcmcia/at91_cf.c2
-rw-r--r--drivers/pcmcia/cardbus.c2
-rw-r--r--drivers/pcmcia/hd64465_ss.c2
-rw-r--r--drivers/pcmcia/m32r_cfc.c2
-rw-r--r--drivers/pcmcia/m8xx_pcmcia.c2
-rw-r--r--drivers/pcmcia/omap_cf.c2
-rw-r--r--drivers/pcmcia/rsrc_mgr.c2
-rw-r--r--drivers/pcmcia/soc_common.c8
-rw-r--r--drivers/pcmcia/vrc4171_card.c2
-rw-r--r--drivers/pnp/pnpacpi/rsparser.c120
-rw-r--r--drivers/ps3/Makefile1
-rw-r--r--drivers/ps3/sys-manager.c604
-rw-r--r--drivers/ps3/vuart.c398
-rw-r--r--drivers/ps3/vuart.h59
-rw-r--r--drivers/rtc/Kconfig10
-rw-r--r--drivers/rtc/class.c14
-rw-r--r--drivers/rtc/interface.c3
-rw-r--r--drivers/rtc/rtc-at91rm9200.c19
-rw-r--r--drivers/rtc/rtc-pcf8583.c29
-rw-r--r--drivers/rtc/rtc-sa1100.c12
-rw-r--r--drivers/s390/block/dasd_eer.c1
-rw-r--r--drivers/s390/char/sclp_quiesce.c1
-rw-r--r--drivers/s390/char/tape_std.c5
-rw-r--r--drivers/s390/cio/cio.c3
-rw-r--r--drivers/s390/cio/device_fsm.c117
-rw-r--r--drivers/s390/net/qeth_main.c25
-rw-r--r--drivers/sbus/char/Kconfig7
-rw-r--r--drivers/sbus/char/Makefile1
-rw-r--r--drivers/sbus/char/aurora.c2364
-rw-r--r--drivers/sbus/char/aurora.h276
-rw-r--r--drivers/sbus/char/bbc_i2c.c17
-rw-r--r--drivers/sbus/char/cd180.h240
-rw-r--r--drivers/sbus/char/uctrl.c8
-rw-r--r--drivers/sbus/char/vfc_i2c.c2
-rw-r--r--drivers/scsi/Kconfig5
-rw-r--r--drivers/scsi/a100u2w.c2
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.c1
-rw-r--r--drivers/scsi/aic94xx/aic94xx_seq.c13
-rw-r--r--drivers/scsi/aic94xx/aic94xx_seq.h1
-rw-r--r--drivers/scsi/arm/cumana_2.c4
-rw-r--r--drivers/scsi/arm/eesox.c6
-rw-r--r--drivers/scsi/arm/fas216.c9
-rw-r--r--drivers/scsi/arm/powertec.c5
-rw-r--r--drivers/scsi/arm/scsi.h2
-rw-r--r--drivers/scsi/ide-scsi.c8
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c97
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c12
-rw-r--r--drivers/scsi/megaraid.c2
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.c90
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.h6
-rw-r--r--drivers/scsi/osst.c12
-rw-r--r--drivers/scsi/scsi_proc.c5
-rw-r--r--drivers/scsi/scsi_scan.c16
-rw-r--r--drivers/scsi/scsi_sysfs.c2
-rw-r--r--drivers/scsi/scsi_tgt_if.c8
-rw-r--r--drivers/scsi/scsi_transport_fc.c2
-rw-r--r--drivers/scsi/scsi_transport_sas.c4
-rw-r--r--drivers/scsi/sd.c11
-rw-r--r--drivers/scsi/sgiwd93.c5
-rw-r--r--drivers/scsi/st.c38
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_fw1.h4
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_fw2.h4
-rw-r--r--drivers/scsi/wd33c93.c321
-rw-r--r--drivers/scsi/wd33c93.h6
-rw-r--r--drivers/serial/8250.c2
-rw-r--r--drivers/serial/Kconfig3
-rw-r--r--drivers/serial/atmel_serial.c3
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_cpm2.c2
-rw-r--r--drivers/serial/dz.c7
-rw-r--r--drivers/serial/imx.c14
-rw-r--r--drivers/serial/mcfserial.c44
-rw-r--r--drivers/serial/mpc52xx_uart.c4
-rw-r--r--drivers/serial/mux.c167
-rw-r--r--drivers/serial/serial_cs.c5
-rw-r--r--drivers/serial/serial_txx9.c276
-rw-r--r--drivers/serial/sn_console.c52
-rw-r--r--drivers/spi/atmel_spi.c6
-rw-r--r--drivers/spi/omap_uwire.c2
-rw-r--r--drivers/spi/spi_imx.c5
-rw-r--r--drivers/spi/spi_s3c24xx_gpio.c15
-rw-r--r--drivers/usb/Makefile1
-rw-r--r--drivers/usb/atm/ueagle-atm.c1
-rw-r--r--drivers/usb/class/cdc-acm.c33
-rw-r--r--drivers/usb/core/Makefile2
-rw-r--r--drivers/usb/core/devices.c9
-rw-r--r--drivers/usb/core/devio.c4
-rw-r--r--drivers/usb/core/driver.c70
-rw-r--r--drivers/usb/core/endpoint.c2
-rw-r--r--drivers/usb/core/generic.c2
-rw-r--r--drivers/usb/core/hub.c34
-rw-r--r--drivers/usb/core/message.c28
-rw-r--r--drivers/usb/core/otg_whitelist.h2
-rw-r--r--drivers/usb/core/quirks.c77
-rw-r--r--drivers/usb/core/sysfs.c113
-rw-r--r--drivers/usb/core/usb.c12
-rw-r--r--drivers/usb/core/usb.h9
-rw-r--r--drivers/usb/gadget/at91_udc.c19
-rw-r--r--drivers/usb/gadget/inode.c5
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.c16
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.h15
-rw-r--r--drivers/usb/gadget/serial.c1
-rw-r--r--drivers/usb/host/ehci-dbg.c2
-rw-r--r--drivers/usb/host/ehci-hcd.c36
-rw-r--r--drivers/usb/host/ehci-hub.c2
-rw-r--r--drivers/usb/host/isp116x-hcd.c2
-rw-r--r--drivers/usb/host/ohci-at91.c50
-rw-r--r--drivers/usb/host/ohci-hcd.c18
-rw-r--r--drivers/usb/host/uhci-debug.c57
-rw-r--r--drivers/usb/host/uhci-hcd.c58
-rw-r--r--drivers/usb/host/uhci-hcd.h82
-rw-r--r--drivers/usb/host/uhci-q.c219
-rw-r--r--drivers/usb/input/Kconfig6
-rw-r--r--drivers/usb/input/hid-core.c64
-rw-r--r--drivers/usb/input/hid-ff.c3
-rw-r--r--drivers/usb/input/hid-lgff.c12
-rw-r--r--drivers/usb/input/usbkbd.c4
-rw-r--r--drivers/usb/input/usbmouse.c4
-rw-r--r--drivers/usb/input/wacom_wac.c103
-rw-r--r--drivers/usb/input/wacom_wac.h1
-rw-r--r--drivers/usb/misc/Kconfig25
-rw-r--r--drivers/usb/misc/Makefile2
-rw-r--r--drivers/usb/misc/appledisplay.c18
-rw-r--r--drivers/usb/misc/berry_charge.c140
-rw-r--r--drivers/usb/misc/iowarrior.c925
-rw-r--r--drivers/usb/mon/mon_bin.c2
-rw-r--r--drivers/usb/mon/mon_text.c2
-rw-r--r--drivers/usb/mon/usb_mon.h4
-rw-r--r--drivers/usb/net/Kconfig20
-rw-r--r--drivers/usb/net/Makefile1
-rw-r--r--drivers/usb/net/asix.c16
-rw-r--r--drivers/usb/net/cdc_subset.c21
-rw-r--r--drivers/usb/net/dm9601.c606
-rw-r--r--drivers/usb/net/usbnet.c29
-rw-r--r--drivers/usb/serial/airprime.c35
-rw-r--r--drivers/usb/serial/cp2101.c1
-rw-r--r--drivers/usb/serial/ftdi_sio.c1
-rw-r--r--drivers/usb/serial/ftdi_sio.h6
-rw-r--r--drivers/usb/serial/generic.c102
-rw-r--r--drivers/usb/serial/option.c121
-rw-r--r--drivers/usb/serial/pl2303.c1
-rw-r--r--drivers/usb/serial/pl2303.h5
-rw-r--r--drivers/usb/storage/scsiglue.c6
-rw-r--r--drivers/usb/storage/unusual_devs.h26
-rw-r--r--drivers/usb/storage/usb.c4
-rw-r--r--drivers/usb/usb-skeleton.c10
-rw-r--r--drivers/video/Kconfig108
-rw-r--r--drivers/video/Makefile3
-rw-r--r--drivers/video/aty/aty128fb.c114
-rw-r--r--drivers/video/aty/atyfb.h3
-rw-r--r--drivers/video/aty/atyfb_base.c113
-rw-r--r--drivers/video/aty/mach64_ct.c3
-rw-r--r--drivers/video/aty/radeon_backlight.c59
-rw-r--r--drivers/video/aty/radeon_base.c16
-rw-r--r--drivers/video/backlight/Kconfig23
-rw-r--r--drivers/video/backlight/Makefile1
-rw-r--r--drivers/video/backlight/backlight.c123
-rw-r--r--drivers/video/backlight/corgi_bl.c54
-rw-r--r--drivers/video/backlight/hp680_bl.c50
-rw-r--r--drivers/video/backlight/lcd.c83
-rw-r--r--drivers/video/backlight/locomolcd.c13
-rw-r--r--drivers/video/backlight/progear_bl.c153
-rw-r--r--drivers/video/chipsfb.c26
-rw-r--r--drivers/video/console/fbcon.c7
-rw-r--r--drivers/video/fbsysfs.c14
-rw-r--r--drivers/video/i810/i810_main.c2
-rw-r--r--drivers/video/nvidia/nv_backlight.c97
-rw-r--r--drivers/video/nvidia/nv_proto.h2
-rw-r--r--drivers/video/nvidia/nvidia.c17
-rw-r--r--drivers/video/riva/fbdev.c112
-rw-r--r--drivers/video/s3fb.c6
-rw-r--r--drivers/video/sm501fb.c1786
849 files changed, 31836 insertions, 16300 deletions
diff --git a/drivers/acorn/char/Makefile b/drivers/acorn/char/Makefile
index 2fa9a8bf48..d006c9f168 100644
--- a/drivers/acorn/char/Makefile
+++ b/drivers/acorn/char/Makefile
@@ -2,5 +2,4 @@
2# Makefile for the acorn character device drivers. 2# Makefile for the acorn character device drivers.
3# 3#
4 4
5obj-$(CONFIG_ARCH_ACORN) += i2c.o pcf8583.o
6obj-$(CONFIG_L7200_KEYB) += defkeymap-l7200.o keyb_l7200.o 5obj-$(CONFIG_L7200_KEYB) += defkeymap-l7200.o keyb_l7200.o
diff --git a/drivers/acorn/char/i2c.c b/drivers/acorn/char/i2c.c
deleted file mode 100644
index d276fd14d6..0000000000
--- a/drivers/acorn/char/i2c.c
+++ /dev/null
@@ -1,368 +0,0 @@
1/*
2 * linux/drivers/acorn/char/i2c.c
3 *
4 * Copyright (C) 2000 Russell King
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 * ARM IOC/IOMD i2c driver.
11 *
12 * On Acorn machines, the following i2c devices are on the bus:
13 * - PCF8583 real time clock & static RAM
14 */
15#include <linux/capability.h>
16#include <linux/init.h>
17#include <linux/time.h>
18#include <linux/miscdevice.h>
19#include <linux/rtc.h>
20#include <linux/i2c.h>
21#include <linux/i2c-algo-bit.h>
22#include <linux/fs.h>
23
24#include <asm/hardware.h>
25#include <asm/io.h>
26#include <asm/hardware/ioc.h>
27#include <asm/system.h>
28#include <asm/uaccess.h>
29
30#include "pcf8583.h"
31
32extern int (*set_rtc)(void);
33
34static struct i2c_client *rtc_client;
35static const unsigned char days_in_mon[] =
36 { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
37
38#define CMOS_CHECKSUM (63)
39
40/*
41 * Acorn machines store the year in the static RAM at
42 * location 128.
43 */
44#define CMOS_YEAR (64 + 128)
45
46static inline int rtc_command(int cmd, void *data)
47{
48 int ret = -EIO;
49
50 if (rtc_client)
51 ret = rtc_client->driver->command(rtc_client, cmd, data);
52
53 return ret;
54}
55
56/*
57 * Update the century + year bytes in the CMOS RAM, ensuring
58 * that the check byte is correctly adjusted for the change.
59 */
60static int rtc_update_year(unsigned int new_year)
61{
62 unsigned char yr[2], chk;
63 struct mem cmos_year = { CMOS_YEAR, sizeof(yr), yr };
64 struct mem cmos_check = { CMOS_CHECKSUM, 1, &chk };
65 int ret;
66
67 ret = rtc_command(MEM_READ, &cmos_check);
68 if (ret)
69 goto out;
70 ret = rtc_command(MEM_READ, &cmos_year);
71 if (ret)
72 goto out;
73
74 chk -= yr[1] + yr[0];
75
76 yr[1] = new_year / 100;
77 yr[0] = new_year % 100;
78
79 chk += yr[1] + yr[0];
80
81 ret = rtc_command(MEM_WRITE, &cmos_year);
82 if (ret == 0)
83 ret = rtc_command(MEM_WRITE, &cmos_check);
84 out:
85 return ret;
86}
87
88/*
89 * Read the current RTC time and date, and update xtime.
90 */
91static void get_rtc_time(struct rtc_tm *rtctm, unsigned int *year)
92{
93 unsigned char ctrl, yr[2];
94 struct mem rtcmem = { CMOS_YEAR, sizeof(yr), yr };
95 int real_year, year_offset;
96
97 /*
98 * Ensure that the RTC is running.
99 */
100 rtc_command(RTC_GETCTRL, &ctrl);
101 if (ctrl & 0xc0) {
102 unsigned char new_ctrl = ctrl & ~0xc0;
103
104 printk(KERN_WARNING "RTC: resetting control %02x -> %02x\n",
105 ctrl, new_ctrl);
106
107 rtc_command(RTC_SETCTRL, &new_ctrl);
108 }
109
110 if (rtc_command(RTC_GETDATETIME, rtctm) ||
111 rtc_command(MEM_READ, &rtcmem))
112 return;
113
114 real_year = yr[0];
115
116 /*
117 * The RTC year holds the LSB two bits of the current
118 * year, which should reflect the LSB two bits of the
119 * CMOS copy of the year. Any difference indicates
120 * that we have to correct the CMOS version.
121 */
122 year_offset = rtctm->year_off - (real_year & 3);
123 if (year_offset < 0)
124 /*
125 * RTC year wrapped. Adjust it appropriately.
126 */
127 year_offset += 4;
128
129 *year = real_year + year_offset + yr[1] * 100;
130}
131
132static int set_rtc_time(struct rtc_tm *rtctm, unsigned int year)
133{
134 unsigned char leap;
135 int ret;
136
137 leap = (!(year % 4) && (year % 100)) || !(year % 400);
138
139 if (rtctm->mon > 12 || rtctm->mon == 0 || rtctm->mday == 0)
140 return -EINVAL;
141
142 if (rtctm->mday > (days_in_mon[rtctm->mon] + (rtctm->mon == 2 && leap)))
143 return -EINVAL;
144
145 if (rtctm->hours >= 24 || rtctm->mins >= 60 || rtctm->secs >= 60)
146 return -EINVAL;
147
148 /*
149 * The RTC's own 2-bit year must reflect the least
150 * significant two bits of the CMOS year.
151 */
152 rtctm->year_off = (year % 100) & 3;
153
154 ret = rtc_command(RTC_SETDATETIME, rtctm);
155 if (ret == 0)
156 ret = rtc_update_year(year);
157
158 return ret;
159}
160
161/*
162 * Set the RTC time only. Note that
163 * we do not touch the date.
164 */
165static int k_set_rtc_time(void)
166{
167 struct rtc_tm new_rtctm, old_rtctm;
168 unsigned long nowtime = xtime.tv_sec;
169
170 if (rtc_command(RTC_GETDATETIME, &old_rtctm))
171 return 0;
172
173 new_rtctm.cs = xtime.tv_nsec / 10000000;
174 new_rtctm.secs = nowtime % 60; nowtime /= 60;
175 new_rtctm.mins = nowtime % 60; nowtime /= 60;
176 new_rtctm.hours = nowtime % 24;
177
178 /*
179 * avoid writing when we're going to change the day
180 * of the month. We will retry in the next minute.
181 * This basically means that if the RTC must not drift
182 * by more than 1 minute in 11 minutes.
183 *
184 * [ rtc: 1/1/2000 23:58:00, real 2/1/2000 00:01:00,
185 * rtc gets set to 1/1/2000 00:01:00 ]
186 */
187 if ((old_rtctm.hours == 23 && old_rtctm.mins == 59) ||
188 (new_rtctm.hours == 23 && new_rtctm.mins == 59))
189 return 1;
190
191 return rtc_command(RTC_SETTIME, &new_rtctm);
192}
193
194static int rtc_ioctl(struct inode *inode, struct file *file,
195 unsigned int cmd, unsigned long arg)
196{
197 unsigned int year;
198 struct rtc_time rtctm;
199 struct rtc_tm rtc_raw;
200
201 switch (cmd) {
202 case RTC_ALM_READ:
203 case RTC_ALM_SET:
204 break;
205
206 case RTC_RD_TIME:
207 memset(&rtctm, 0, sizeof(struct rtc_time));
208 get_rtc_time(&rtc_raw, &year);
209 rtctm.tm_sec = rtc_raw.secs;
210 rtctm.tm_min = rtc_raw.mins;
211 rtctm.tm_hour = rtc_raw.hours;
212 rtctm.tm_mday = rtc_raw.mday;
213 rtctm.tm_mon = rtc_raw.mon - 1; /* month starts at 0 */
214 rtctm.tm_year = year - 1900; /* starts at 1900 */
215 return copy_to_user((void *)arg, &rtctm, sizeof(rtctm))
216 ? -EFAULT : 0;
217
218 case RTC_SET_TIME:
219 if (!capable(CAP_SYS_TIME))
220 return -EACCES;
221
222 if (copy_from_user(&rtctm, (void *)arg, sizeof(rtctm)))
223 return -EFAULT;
224 rtc_raw.secs = rtctm.tm_sec;
225 rtc_raw.mins = rtctm.tm_min;
226 rtc_raw.hours = rtctm.tm_hour;
227 rtc_raw.mday = rtctm.tm_mday;
228 rtc_raw.mon = rtctm.tm_mon + 1;
229 year = rtctm.tm_year + 1900;
230 return set_rtc_time(&rtc_raw, year);
231 break;
232
233 case RTC_EPOCH_READ:
234 return put_user(1900, (unsigned long *)arg);
235
236 }
237 return -EINVAL;
238}
239
240static const struct file_operations rtc_fops = {
241 .ioctl = rtc_ioctl,
242};
243
244static struct miscdevice rtc_dev = {
245 .minor = RTC_MINOR,
246 .name = "rtc",
247 .fops = &rtc_fops,
248};
249
250/* IOC / IOMD i2c driver */
251
252#define FORCE_ONES 0xdc
253#define SCL 0x02
254#define SDA 0x01
255
256/*
257 * We must preserve all non-i2c output bits in IOC_CONTROL.
258 * Note also that we need to preserve the value of SCL and
259 * SDA outputs as well (which may be different from the
260 * values read back from IOC_CONTROL).
261 */
262static u_int force_ones;
263
264static void ioc_setscl(void *data, int state)
265{
266 u_int ioc_control = ioc_readb(IOC_CONTROL) & ~(SCL | SDA);
267 u_int ones = force_ones;
268
269 if (state)
270 ones |= SCL;
271 else
272 ones &= ~SCL;
273
274 force_ones = ones;
275
276 ioc_writeb(ioc_control | ones, IOC_CONTROL);
277}
278
279static void ioc_setsda(void *data, int state)
280{
281 u_int ioc_control = ioc_readb(IOC_CONTROL) & ~(SCL | SDA);
282 u_int ones = force_ones;
283
284 if (state)
285 ones |= SDA;
286 else
287 ones &= ~SDA;
288
289 force_ones = ones;
290
291 ioc_writeb(ioc_control | ones, IOC_CONTROL);
292}
293
294static int ioc_getscl(void *data)
295{
296 return (ioc_readb(IOC_CONTROL) & SCL) != 0;
297}
298
299static int ioc_getsda(void *data)
300{
301 return (ioc_readb(IOC_CONTROL) & SDA) != 0;
302}
303
304static struct i2c_algo_bit_data ioc_data = {
305 .setsda = ioc_setsda,
306 .setscl = ioc_setscl,
307 .getsda = ioc_getsda,
308 .getscl = ioc_getscl,
309 .udelay = 80,
310 .timeout = 100
311};
312
313static int ioc_client_reg(struct i2c_client *client)
314{
315 if (client->driver->id == I2C_DRIVERID_PCF8583 &&
316 client->addr == 0x50) {
317 struct rtc_tm rtctm;
318 unsigned int year;
319 struct timespec tv;
320
321 rtc_client = client;
322 get_rtc_time(&rtctm, &year);
323
324 tv.tv_nsec = rtctm.cs * 10000000;
325 tv.tv_sec = mktime(year, rtctm.mon, rtctm.mday,
326 rtctm.hours, rtctm.mins, rtctm.secs);
327 do_settimeofday(&tv);
328 set_rtc = k_set_rtc_time;
329 }
330
331 return 0;
332}
333
334static int ioc_client_unreg(struct i2c_client *client)
335{
336 if (client == rtc_client) {
337 set_rtc = NULL;
338 rtc_client = NULL;
339 }
340
341 return 0;
342}
343
344static struct i2c_adapter ioc_ops = {
345 .id = I2C_HW_B_IOC,
346 .algo_data = &ioc_data,
347 .client_register = ioc_client_reg,
348 .client_unregister = ioc_client_unreg,
349};
350
351static int __init i2c_ioc_init(void)
352{
353 int ret;
354
355 force_ones = FORCE_ONES | SCL | SDA;
356
357 ret = i2c_bit_add_bus(&ioc_ops);
358
359 if (ret >= 0){
360 ret = misc_register(&rtc_dev);
361 if(ret < 0)
362 i2c_del_adapter(&ioc_ops);
363 }
364
365 return ret;
366}
367
368__initcall(i2c_ioc_init);
diff --git a/drivers/acorn/char/pcf8583.c b/drivers/acorn/char/pcf8583.c
deleted file mode 100644
index 9b49f316ae..0000000000
--- a/drivers/acorn/char/pcf8583.c
+++ /dev/null
@@ -1,284 +0,0 @@
1/*
2 * linux/drivers/acorn/char/pcf8583.c
3 *
4 * Copyright (C) 2000 Russell King
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 * Driver for PCF8583 RTC & RAM chip
11 */
12#include <linux/module.h>
13#include <linux/i2c.h>
14#include <linux/slab.h>
15#include <linux/string.h>
16#include <linux/mc146818rtc.h>
17#include <linux/init.h>
18#include <linux/errno.h>
19#include <linux/bcd.h>
20
21#include "pcf8583.h"
22
23static struct i2c_driver pcf8583_driver;
24
25static unsigned short ignore[] = { I2C_CLIENT_END };
26static unsigned short normal_addr[] = { 0x50, I2C_CLIENT_END };
27static unsigned short *forces[] = { NULL };
28
29static struct i2c_client_address_data addr_data = {
30 .normal_i2c = normal_addr,
31 .probe = ignore,
32 .ignore = ignore,
33 .forces = forces,
34};
35
36#define set_ctrl(x, v) i2c_set_clientdata(x, (void *)(unsigned int)(v))
37#define get_ctrl(x) ((unsigned int)i2c_get_clientdata(x))
38
39static int
40pcf8583_attach(struct i2c_adapter *adap, int addr, int kind)
41{
42 struct i2c_client *c;
43 unsigned char buf[1], ad[1] = { 0 };
44 struct i2c_msg msgs[2] = {
45 {
46 .addr = addr,
47 .flags = 0,
48 .len = 1,
49 .buf = ad,
50 }, {
51 .addr = addr,
52 .flags = I2C_M_RD,
53 .len = 1,
54 .buf = buf,
55 }
56 };
57
58 c = kmalloc(sizeof(*c), GFP_KERNEL);
59 if (!c)
60 return -ENOMEM;
61
62 memset(c, 0, sizeof(*c));
63 c->addr = addr;
64 c->adapter = adap;
65 c->driver = &pcf8583_driver;
66
67 if (i2c_transfer(c->adapter, msgs, 2) == 2)
68 set_ctrl(c, buf[0]);
69
70 return i2c_attach_client(c);
71}
72
73static int
74pcf8583_probe(struct i2c_adapter *adap)
75{
76 return i2c_probe(adap, &addr_data, pcf8583_attach);
77}
78
79static int
80pcf8583_detach(struct i2c_client *client)
81{
82 i2c_detach_client(client);
83 kfree(client);
84 return 0;
85}
86
87static int
88pcf8583_get_datetime(struct i2c_client *client, struct rtc_tm *dt)
89{
90 unsigned char buf[8], addr[1] = { 1 };
91 struct i2c_msg msgs[2] = {
92 {
93 .addr = client->addr,
94 .flags = 0,
95 .len = 1,
96 .buf = addr,
97 }, {
98 .addr = client->addr,
99 .flags = I2C_M_RD,
100 .len = 6,
101 .buf = buf,
102 }
103 };
104 int ret = -EIO;
105
106 memset(buf, 0, sizeof(buf));
107
108 ret = i2c_transfer(client->adapter, msgs, 2);
109 if (ret == 2) {
110 dt->year_off = buf[4] >> 6;
111 dt->wday = buf[5] >> 5;
112
113 buf[4] &= 0x3f;
114 buf[5] &= 0x1f;
115
116 dt->cs = BCD_TO_BIN(buf[0]);
117 dt->secs = BCD_TO_BIN(buf[1]);
118 dt->mins = BCD_TO_BIN(buf[2]);
119 dt->hours = BCD_TO_BIN(buf[3]);
120 dt->mday = BCD_TO_BIN(buf[4]);
121 dt->mon = BCD_TO_BIN(buf[5]);
122
123 ret = 0;
124 }
125
126 return ret;
127}
128
129static int
130pcf8583_set_datetime(struct i2c_client *client, struct rtc_tm *dt, int datetoo)
131{
132 unsigned char buf[8];
133 int ret, len = 6;
134
135 buf[0] = 0;
136 buf[1] = get_ctrl(client) | 0x80;
137 buf[2] = BIN_TO_BCD(dt->cs);
138 buf[3] = BIN_TO_BCD(dt->secs);
139 buf[4] = BIN_TO_BCD(dt->mins);
140 buf[5] = BIN_TO_BCD(dt->hours);
141
142 if (datetoo) {
143 len = 8;
144 buf[6] = BIN_TO_BCD(dt->mday) | (dt->year_off << 6);
145 buf[7] = BIN_TO_BCD(dt->mon) | (dt->wday << 5);
146 }
147
148 ret = i2c_master_send(client, (char *)buf, len);
149 if (ret == len)
150 ret = 0;
151
152 buf[1] = get_ctrl(client);
153 i2c_master_send(client, (char *)buf, 2);
154
155 return ret;
156}
157
158static int
159pcf8583_get_ctrl(struct i2c_client *client, unsigned char *ctrl)
160{
161 *ctrl = get_ctrl(client);
162 return 0;
163}
164
165static int
166pcf8583_set_ctrl(struct i2c_client *client, unsigned char *ctrl)
167{
168 unsigned char buf[2];
169
170 buf[0] = 0;
171 buf[1] = *ctrl;
172 set_ctrl(client, *ctrl);
173
174 return i2c_master_send(client, (char *)buf, 2);
175}
176
177static int
178pcf8583_read_mem(struct i2c_client *client, struct mem *mem)
179{
180 unsigned char addr[1];
181 struct i2c_msg msgs[2] = {
182 {
183 .addr = client->addr,
184 .flags = 0,
185 .len = 1,
186 .buf = addr,
187 }, {
188 .addr = client->addr,
189 .flags = I2C_M_RD,
190 .len = mem->nr,
191 .buf = mem->data,
192 }
193 };
194
195 if (mem->loc < 8)
196 return -EINVAL;
197
198 addr[0] = mem->loc;
199
200 return i2c_transfer(client->adapter, msgs, 2) == 2 ? 0 : -EIO;
201}
202
203static int
204pcf8583_write_mem(struct i2c_client *client, struct mem *mem)
205{
206 unsigned char addr[1];
207 struct i2c_msg msgs[2] = {
208 {
209 .addr = client->addr,
210 .flags = 0,
211 .len = 1,
212 .buf = addr,
213 }, {
214 .addr = client->addr,
215 .flags = I2C_M_NOSTART,
216 .len = mem->nr,
217 .buf = mem->data,
218 }
219 };
220
221 if (mem->loc < 8)
222 return -EINVAL;
223
224 addr[0] = mem->loc;
225
226 return i2c_transfer(client->adapter, msgs, 2) == 2 ? 0 : -EIO;
227}
228
229static int
230pcf8583_command(struct i2c_client *client, unsigned int cmd, void *arg)
231{
232 switch (cmd) {
233 case RTC_GETDATETIME:
234 return pcf8583_get_datetime(client, arg);
235
236 case RTC_SETTIME:
237 return pcf8583_set_datetime(client, arg, 0);
238
239 case RTC_SETDATETIME:
240 return pcf8583_set_datetime(client, arg, 1);
241
242 case RTC_GETCTRL:
243 return pcf8583_get_ctrl(client, arg);
244
245 case RTC_SETCTRL:
246 return pcf8583_set_ctrl(client, arg);
247
248 case MEM_READ:
249 return pcf8583_read_mem(client, arg);
250
251 case MEM_WRITE:
252 return pcf8583_write_mem(client, arg);
253
254 default:
255 return -EINVAL;
256 }
257}
258
259static struct i2c_driver pcf8583_driver = {
260 .driver = {
261 .name = "PCF8583",
262 },
263 .id = I2C_DRIVERID_PCF8583,
264 .attach_adapter = pcf8583_probe,
265 .detach_client = pcf8583_detach,
266 .command = pcf8583_command
267};
268
269static __init int pcf8583_init(void)
270{
271 return i2c_add_driver(&pcf8583_driver);
272}
273
274static __exit void pcf8583_exit(void)
275{
276 i2c_del_driver(&pcf8583_driver);
277}
278
279module_init(pcf8583_init);
280module_exit(pcf8583_exit);
281
282MODULE_AUTHOR("Russell King");
283MODULE_DESCRIPTION("PCF8583 I2C RTC driver");
284MODULE_LICENSE("GPL");
diff --git a/drivers/acorn/char/pcf8583.h b/drivers/acorn/char/pcf8583.h
deleted file mode 100644
index 847f7fdb87..0000000000
--- a/drivers/acorn/char/pcf8583.h
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 * linux/drivers/acorn/char/pcf8583.h
3 *
4 * Copyright (C) 2000 Russell King
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 */
10struct rtc_tm {
11 unsigned char cs;
12 unsigned char secs;
13 unsigned char mins;
14 unsigned char hours;
15 unsigned char mday;
16 unsigned char mon;
17 unsigned char year_off;
18 unsigned char wday;
19};
20
21struct mem {
22 unsigned int loc;
23 unsigned int nr;
24 unsigned char *data;
25};
26
27#define RTC_GETDATETIME 0
28#define RTC_SETTIME 1
29#define RTC_SETDATETIME 2
30#define RTC_GETCTRL 3
31#define RTC_SETCTRL 4
32#define MEM_READ 5
33#define MEM_WRITE 6
34
35#define CTRL_STOP 0x80
36#define CTRL_HOLD 0x40
37#define CTRL_32KHZ 0x00
38#define CTRL_MASK 0x08
39#define CTRL_ALARMEN 0x04
40#define CTRL_ALARM 0x02
41#define CTRL_TIMER 0x01
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index e942ffe8b5..4a3220b218 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -149,6 +149,7 @@ config ACPI_DOCK
149config ACPI_BAY 149config ACPI_BAY
150 tristate "Removable Drive Bay (EXPERIMENTAL)" 150 tristate "Removable Drive Bay (EXPERIMENTAL)"
151 depends on EXPERIMENTAL 151 depends on EXPERIMENTAL
152 depends on ACPI_DOCK
152 help 153 help
153 This driver adds support for ACPI controlled removable drive 154 This driver adds support for ACPI controlled removable drive
154 bays such as the IBM ultrabay or the Dell Module Bay. 155 bays such as the IBM ultrabay or the Dell Module Bay.
@@ -242,6 +243,17 @@ config ACPI_IBM_DOCK
242 243
243 If you are not sure, say N here. 244 If you are not sure, say N here.
244 245
246config ACPI_IBM_BAY
247 bool "Legacy Removable Bay Support"
248 depends on ACPI_IBM
249 default y
250 ---help---
251 Allows the ibm_acpi driver to handle removable bays. It will allow
252 disabling the device in the bay, and also generate notifications when
253 the bay lever is ejected or inserted.
254
255 If you are not sure, say Y here.
256
245config ACPI_TOSHIBA 257config ACPI_TOSHIBA
246 tristate "Toshiba Laptop Extras" 258 tristate "Toshiba Laptop Extras"
247 depends on X86 259 depends on X86
diff --git a/drivers/acpi/asus_acpi.c b/drivers/acpi/asus_acpi.c
index 772299fb5f..b770deab96 100644
--- a/drivers/acpi/asus_acpi.c
+++ b/drivers/acpi/asus_acpi.c
@@ -848,7 +848,7 @@ out:
848 848
849static int set_brightness_status(struct backlight_device *bd) 849static int set_brightness_status(struct backlight_device *bd)
850{ 850{
851 return set_brightness(bd->props->brightness); 851 return set_brightness(bd->props.brightness);
852} 852}
853 853
854static int 854static int
@@ -1352,11 +1352,9 @@ static int asus_hotk_remove(struct acpi_device *device, int type)
1352 return 0; 1352 return 0;
1353} 1353}
1354 1354
1355static struct backlight_properties asus_backlight_data = { 1355static struct backlight_ops asus_backlight_data = {
1356 .owner = THIS_MODULE,
1357 .get_brightness = read_brightness, 1356 .get_brightness = read_brightness,
1358 .update_status = set_brightness_status, 1357 .update_status = set_brightness_status,
1359 .max_brightness = 15,
1360}; 1358};
1361 1359
1362static void __exit asus_acpi_exit(void) 1360static void __exit asus_acpi_exit(void)
@@ -1410,6 +1408,7 @@ static int __init asus_acpi_init(void)
1410 asus_backlight_device = NULL; 1408 asus_backlight_device = NULL;
1411 asus_acpi_exit(); 1409 asus_acpi_exit();
1412 } 1410 }
1411 asus_backlight_device->props.max_brightness = 15;
1413 1412
1414 return 0; 1413 return 0;
1415} 1414}
diff --git a/drivers/acpi/ibm_acpi.c b/drivers/acpi/ibm_acpi.c
index 1a0ed3dc40..36901362fd 100644
--- a/drivers/acpi/ibm_acpi.c
+++ b/drivers/acpi/ibm_acpi.c
@@ -86,6 +86,7 @@
86 86
87#include <linux/proc_fs.h> 87#include <linux/proc_fs.h>
88#include <linux/backlight.h> 88#include <linux/backlight.h>
89#include <linux/fb.h>
89#include <asm/uaccess.h> 90#include <asm/uaccess.h>
90 91
91#include <linux/dmi.h> 92#include <linux/dmi.h>
@@ -157,6 +158,7 @@ IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
157 "\\_SB.PCI.ISA.SLCE", /* 570 */ 158 "\\_SB.PCI.ISA.SLCE", /* 570 */
158 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ 159 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
159#endif 160#endif
161#ifdef CONFIG_ACPI_IBM_BAY
160IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ 162IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
161 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ 163 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
162 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */ 164 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
@@ -174,6 +176,7 @@ IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
174IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */ 176IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
175 "_EJ0", /* 770x */ 177 "_EJ0", /* 770x */
176 ); /* all others */ 178 ); /* all others */
179#endif /* CONFIG_ACPI_IBM_BAY */
177 180
178/* don't list other alternatives as we install a notify handler on the 570 */ 181/* don't list other alternatives as we install a notify handler on the 570 */
179IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ 182IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
@@ -1044,6 +1047,7 @@ static int light_write(char *buf)
1044 return 0; 1047 return 0;
1045} 1048}
1046 1049
1050#if defined(CONFIG_ACPI_IBM_DOCK) || defined(CONFIG_ACPI_IBM_BAY)
1047static int _sta(acpi_handle handle) 1051static int _sta(acpi_handle handle)
1048{ 1052{
1049 int status; 1053 int status;
@@ -1053,6 +1057,7 @@ static int _sta(acpi_handle handle)
1053 1057
1054 return status; 1058 return status;
1055} 1059}
1060#endif
1056 1061
1057#ifdef CONFIG_ACPI_IBM_DOCK 1062#ifdef CONFIG_ACPI_IBM_DOCK
1058#define dock_docked() (_sta(dock_handle) & 1) 1063#define dock_docked() (_sta(dock_handle) & 1)
@@ -1119,6 +1124,7 @@ static void dock_notify(struct ibm_struct *ibm, u32 event)
1119} 1124}
1120#endif 1125#endif
1121 1126
1127#ifdef CONFIG_ACPI_IBM_BAY
1122static int bay_status_supported; 1128static int bay_status_supported;
1123static int bay_status2_supported; 1129static int bay_status2_supported;
1124static int bay_eject_supported; 1130static int bay_eject_supported;
@@ -1194,6 +1200,7 @@ static void bay_notify(struct ibm_struct *ibm, u32 event)
1194{ 1200{
1195 acpi_bus_generate_event(ibm->device, event, 0); 1201 acpi_bus_generate_event(ibm->device, event, 0);
1196} 1202}
1203#endif /* CONFIG_ACPI_IBM_BAY */
1197 1204
1198static int cmos_read(char *p) 1205static int cmos_read(char *p)
1199{ 1206{
@@ -1701,18 +1708,25 @@ static int brightness_write(char *buf)
1701 1708
1702static int brightness_update_status(struct backlight_device *bd) 1709static int brightness_update_status(struct backlight_device *bd)
1703{ 1710{
1704 return brightness_set(bd->props->brightness); 1711 return brightness_set(
1712 (bd->props.fb_blank == FB_BLANK_UNBLANK &&
1713 bd->props.power == FB_BLANK_UNBLANK) ?
1714 bd->props.brightness : 0);
1705} 1715}
1706 1716
1707static struct backlight_properties ibm_backlight_data = { 1717static struct backlight_ops ibm_backlight_data = {
1708 .owner = THIS_MODULE,
1709 .get_brightness = brightness_get, 1718 .get_brightness = brightness_get,
1710 .update_status = brightness_update_status, 1719 .update_status = brightness_update_status,
1711 .max_brightness = 7,
1712}; 1720};
1713 1721
1714static int brightness_init(void) 1722static int brightness_init(void)
1715{ 1723{
1724 int b;
1725
1726 b = brightness_get(NULL);
1727 if (b < 0)
1728 return b;
1729
1716 ibm_backlight_device = backlight_device_register("ibm", NULL, NULL, 1730 ibm_backlight_device = backlight_device_register("ibm", NULL, NULL,
1717 &ibm_backlight_data); 1731 &ibm_backlight_data);
1718 if (IS_ERR(ibm_backlight_device)) { 1732 if (IS_ERR(ibm_backlight_device)) {
@@ -1720,6 +1734,10 @@ static int brightness_init(void)
1720 return PTR_ERR(ibm_backlight_device); 1734 return PTR_ERR(ibm_backlight_device);
1721 } 1735 }
1722 1736
1737 ibm_backlight_device->props.max_brightness = 7;
1738 ibm_backlight_device->props.brightness = b;
1739 backlight_update_status(ibm_backlight_device);
1740
1723 return 0; 1741 return 0;
1724} 1742}
1725 1743
@@ -2353,6 +2371,7 @@ static struct ibm_struct ibms[] = {
2353 .type = ACPI_SYSTEM_NOTIFY, 2371 .type = ACPI_SYSTEM_NOTIFY,
2354 }, 2372 },
2355#endif 2373#endif
2374#ifdef CONFIG_ACPI_IBM_BAY
2356 { 2375 {
2357 .name = "bay", 2376 .name = "bay",
2358 .init = bay_init, 2377 .init = bay_init,
@@ -2362,6 +2381,7 @@ static struct ibm_struct ibms[] = {
2362 .handle = &bay_handle, 2381 .handle = &bay_handle,
2363 .type = ACPI_SYSTEM_NOTIFY, 2382 .type = ACPI_SYSTEM_NOTIFY,
2364 }, 2383 },
2384#endif /* CONFIG_ACPI_IBM_BAY */
2365 { 2385 {
2366 .name = "cmos", 2386 .name = "cmos",
2367 .read = cmos_read, 2387 .read = cmos_read,
@@ -2647,7 +2667,9 @@ IBM_PARAM(light);
2647#ifdef CONFIG_ACPI_IBM_DOCK 2667#ifdef CONFIG_ACPI_IBM_DOCK
2648IBM_PARAM(dock); 2668IBM_PARAM(dock);
2649#endif 2669#endif
2670#ifdef CONFIG_ACPI_IBM_BAY
2650IBM_PARAM(bay); 2671IBM_PARAM(bay);
2672#endif /* CONFIG_ACPI_IBM_BAY */
2651IBM_PARAM(cmos); 2673IBM_PARAM(cmos);
2652IBM_PARAM(led); 2674IBM_PARAM(led);
2653IBM_PARAM(beep); 2675IBM_PARAM(beep);
@@ -2723,12 +2745,14 @@ static int __init acpi_ibm_init(void)
2723 IBM_HANDLE_INIT(dock); 2745 IBM_HANDLE_INIT(dock);
2724#endif 2746#endif
2725 IBM_HANDLE_INIT(pci); 2747 IBM_HANDLE_INIT(pci);
2748#ifdef CONFIG_ACPI_IBM_BAY
2726 IBM_HANDLE_INIT(bay); 2749 IBM_HANDLE_INIT(bay);
2727 if (bay_handle) 2750 if (bay_handle)
2728 IBM_HANDLE_INIT(bay_ej); 2751 IBM_HANDLE_INIT(bay_ej);
2729 IBM_HANDLE_INIT(bay2); 2752 IBM_HANDLE_INIT(bay2);
2730 if (bay2_handle) 2753 if (bay2_handle)
2731 IBM_HANDLE_INIT(bay2_ej); 2754 IBM_HANDLE_INIT(bay2_ej);
2755#endif /* CONFIG_ACPI_IBM_BAY */
2732 IBM_HANDLE_INIT(beep); 2756 IBM_HANDLE_INIT(beep);
2733 IBM_HANDLE_INIT(ecrd); 2757 IBM_HANDLE_INIT(ecrd);
2734 IBM_HANDLE_INIT(ecwr); 2758 IBM_HANDLE_INIT(ecwr);
diff --git a/drivers/acpi/resources/rscreate.c b/drivers/acpi/resources/rscreate.c
index 1358c06a96..cc48ab0567 100644
--- a/drivers/acpi/resources/rscreate.c
+++ b/drivers/acpi/resources/rscreate.c
@@ -191,6 +191,9 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
191 user_prt = ACPI_CAST_PTR(struct acpi_pci_routing_table, buffer); 191 user_prt = ACPI_CAST_PTR(struct acpi_pci_routing_table, buffer);
192 192
193 for (index = 0; index < number_of_elements; index++) { 193 for (index = 0; index < number_of_elements; index++) {
194 int source_name_index = 2;
195 int source_index_index = 3;
196
194 /* 197 /*
195 * Point user_prt past this current structure 198 * Point user_prt past this current structure
196 * 199 *
@@ -261,10 +264,28 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
261 } 264 }
262 265
263 /* 266 /*
267 * If BIOS erroneously reversed the _PRT source_name and source_index,
268 * then reverse them back.
269 */
270 if (ACPI_GET_OBJECT_TYPE (sub_object_list[3]) != ACPI_TYPE_INTEGER) {
271 if (acpi_gbl_enable_interpreter_slack) {
272 source_name_index = 3;
273 source_index_index = 2;
274 printk(KERN_WARNING "ACPI: Handling Garbled _PRT entry\n");
275 } else {
276 ACPI_ERROR((AE_INFO,
277 "(PRT[%X].source_index) Need Integer, found %s",
278 index,
279 acpi_ut_get_object_type_name(sub_object_list[3])));
280 return_ACPI_STATUS(AE_BAD_DATA);
281 }
282 }
283
284 /*
264 * 3) Third subobject: Dereference the PRT.source_name 285 * 3) Third subobject: Dereference the PRT.source_name
265 * The name may be unresolved (slack mode), so allow a null object 286 * The name may be unresolved (slack mode), so allow a null object
266 */ 287 */
267 obj_desc = sub_object_list[2]; 288 obj_desc = sub_object_list[source_name_index];
268 if (obj_desc) { 289 if (obj_desc) {
269 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 290 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
270 case ACPI_TYPE_LOCAL_REFERENCE: 291 case ACPI_TYPE_LOCAL_REFERENCE:
@@ -339,7 +360,7 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
339 360
340 /* 4) Fourth subobject: Dereference the PRT.source_index */ 361 /* 4) Fourth subobject: Dereference the PRT.source_index */
341 362
342 obj_desc = sub_object_list[3]; 363 obj_desc = sub_object_list[source_index_index];
343 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) { 364 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
344 user_prt->source_index = (u32) obj_desc->integer.value; 365 user_prt->source_index = (u32) obj_desc->integer.value;
345 } else { 366 } else {
diff --git a/drivers/acpi/toshiba_acpi.c b/drivers/acpi/toshiba_acpi.c
index faf8a5232d..3906d47b97 100644
--- a/drivers/acpi/toshiba_acpi.c
+++ b/drivers/acpi/toshiba_acpi.c
@@ -315,7 +315,7 @@ static int set_lcd(int value)
315 315
316static int set_lcd_status(struct backlight_device *bd) 316static int set_lcd_status(struct backlight_device *bd)
317{ 317{
318 return set_lcd(bd->props->brightness); 318 return set_lcd(bd->props.brightness);
319} 319}
320 320
321static unsigned long write_lcd(const char *buffer, unsigned long count) 321static unsigned long write_lcd(const char *buffer, unsigned long count)
@@ -533,11 +533,9 @@ static acpi_status __exit remove_device(void)
533 return AE_OK; 533 return AE_OK;
534} 534}
535 535
536static struct backlight_properties toshiba_backlight_data = { 536static struct backlight_ops toshiba_backlight_data = {
537 .owner = THIS_MODULE,
538 .get_brightness = get_lcd, 537 .get_brightness = get_lcd,
539 .update_status = set_lcd_status, 538 .update_status = set_lcd_status,
540 .max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1,
541}; 539};
542 540
543static void __exit toshiba_acpi_exit(void) 541static void __exit toshiba_acpi_exit(void)
@@ -597,6 +595,7 @@ static int __init toshiba_acpi_init(void)
597 toshiba_backlight_device = NULL; 595 toshiba_backlight_device = NULL;
598 toshiba_acpi_exit(); 596 toshiba_acpi_exit();
599 } 597 }
598 toshiba_backlight_device->props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
600 599
601 return (ACPI_SUCCESS(status)) ? 0 : -ENODEV; 600 return (ACPI_SUCCESS(status)) ? 0 : -ENODEV;
602} 601}
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index bf525cca3b..0771b434fe 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -169,7 +169,6 @@ struct acpi_video_device {
169 struct acpi_device *dev; 169 struct acpi_device *dev;
170 struct acpi_video_device_brightness *brightness; 170 struct acpi_video_device_brightness *brightness;
171 struct backlight_device *backlight; 171 struct backlight_device *backlight;
172 struct backlight_properties *data;
173}; 172};
174 173
175/* bus */ 174/* bus */
@@ -286,13 +285,18 @@ static int acpi_video_get_brightness(struct backlight_device *bd)
286 285
287static int acpi_video_set_brightness(struct backlight_device *bd) 286static int acpi_video_set_brightness(struct backlight_device *bd)
288{ 287{
289 int request_level = bd->props->brightness; 288 int request_level = bd->props.brightness;
290 struct acpi_video_device *vd = 289 struct acpi_video_device *vd =
291 (struct acpi_video_device *)class_get_devdata(&bd->class_dev); 290 (struct acpi_video_device *)class_get_devdata(&bd->class_dev);
292 acpi_video_device_lcd_set_level(vd, request_level); 291 acpi_video_device_lcd_set_level(vd, request_level);
293 return 0; 292 return 0;
294} 293}
295 294
295static struct backlight_ops acpi_backlight_ops = {
296 .get_brightness = acpi_video_get_brightness,
297 .update_status = acpi_video_set_brightness,
298};
299
296/* -------------------------------------------------------------------------- 300/* --------------------------------------------------------------------------
297 Video Management 301 Video Management
298 -------------------------------------------------------------------------- */ 302 -------------------------------------------------------------------------- */
@@ -608,31 +612,18 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
608 unsigned long tmp; 612 unsigned long tmp;
609 static int count = 0; 613 static int count = 0;
610 char *name; 614 char *name;
611 struct backlight_properties *acpi_video_data;
612
613 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL); 615 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
614 if (!name) 616 if (!name)
615 return; 617 return;
616 618
617 acpi_video_data = kzalloc(
618 sizeof(struct backlight_properties),
619 GFP_KERNEL);
620 if (!acpi_video_data){
621 kfree(name);
622 return;
623 }
624 acpi_video_data->owner = THIS_MODULE;
625 acpi_video_data->get_brightness =
626 acpi_video_get_brightness;
627 acpi_video_data->update_status =
628 acpi_video_set_brightness;
629 sprintf(name, "acpi_video%d", count++); 619 sprintf(name, "acpi_video%d", count++);
630 device->data = acpi_video_data;
631 acpi_video_data->max_brightness = max_level;
632 acpi_video_device_lcd_get_level_current(device, &tmp); 620 acpi_video_device_lcd_get_level_current(device, &tmp);
633 acpi_video_data->brightness = (int)tmp;
634 device->backlight = backlight_device_register(name, 621 device->backlight = backlight_device_register(name,
635 NULL, device, acpi_video_data); 622 NULL, device, &acpi_backlight_ops);
623 device->backlight->props.max_brightness = max_level;
624 device->backlight->props.brightness = (int)tmp;
625 backlight_update_status(device->backlight);
626
636 kfree(name); 627 kfree(name);
637 } 628 }
638 return; 629 return;
@@ -1677,10 +1668,7 @@ static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1677 status = acpi_remove_notify_handler(device->dev->handle, 1668 status = acpi_remove_notify_handler(device->dev->handle,
1678 ACPI_DEVICE_NOTIFY, 1669 ACPI_DEVICE_NOTIFY,
1679 acpi_video_device_notify); 1670 acpi_video_device_notify);
1680 if (device->backlight){ 1671 backlight_device_unregister(device->backlight);
1681 backlight_device_unregister(device->backlight);
1682 kfree(device->data);
1683 }
1684 return 0; 1672 return 0;
1685} 1673}
1686 1674
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 3747457fee..d16b5b0c8b 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -161,6 +161,19 @@ config SATA_INTEL_COMBINED
161 depends on IDE=y && !BLK_DEV_IDE_SATA && (SATA_AHCI || ATA_PIIX) 161 depends on IDE=y && !BLK_DEV_IDE_SATA && (SATA_AHCI || ATA_PIIX)
162 default y 162 default y
163 163
164config SATA_ACPI
165 bool
166 depends on ACPI && PCI
167 default y
168 help
169 This option adds support for SATA-related ACPI objects.
170 These ACPI objects add the ability to retrieve taskfiles
171 from the ACPI BIOS and write them to the disk controller.
172 These objects may be related to performance, security,
173 power management, or other areas.
174 You can disable this at kernel boot time by using the
175 option libata.noacpi=1
176
164config PATA_ALI 177config PATA_ALI
165 tristate "ALi PATA support (Experimental)" 178 tristate "ALi PATA support (Experimental)"
166 depends on PCI && EXPERIMENTAL 179 depends on PCI && EXPERIMENTAL
@@ -549,6 +562,15 @@ config PATA_IXP4XX_CF
549 562
550 If unsure, say N. 563 If unsure, say N.
551 564
565config PATA_SCC
566 tristate "Toshiba's Cell Reference Set IDE support"
567 depends on PCI && PPC_IBM_CELL_BLADE
568 help
569 This option enables support for the built-in IDE controller on
570 Toshiba Cell Reference Board.
571
572 If unsure, say N.
573
552endif 574endif
553endmenu 575endmenu
554 576
diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile
index cd096f0c78..13d7397e00 100644
--- a/drivers/ata/Makefile
+++ b/drivers/ata/Makefile
@@ -59,6 +59,7 @@ obj-$(CONFIG_PATA_WINBOND_VLB) += pata_winbond.o
59obj-$(CONFIG_PATA_SIS) += pata_sis.o 59obj-$(CONFIG_PATA_SIS) += pata_sis.o
60obj-$(CONFIG_PATA_TRIFLEX) += pata_triflex.o 60obj-$(CONFIG_PATA_TRIFLEX) += pata_triflex.o
61obj-$(CONFIG_PATA_IXP4XX_CF) += pata_ixp4xx_cf.o 61obj-$(CONFIG_PATA_IXP4XX_CF) += pata_ixp4xx_cf.o
62obj-$(CONFIG_PATA_SCC) += pata_scc.o
62obj-$(CONFIG_PATA_PLATFORM) += pata_platform.o 63obj-$(CONFIG_PATA_PLATFORM) += pata_platform.o
63# Should be last but one libata driver 64# Should be last but one libata driver
64obj-$(CONFIG_ATA_GENERIC) += ata_generic.o 65obj-$(CONFIG_ATA_GENERIC) += ata_generic.o
@@ -66,4 +67,4 @@ obj-$(CONFIG_ATA_GENERIC) += ata_generic.o
66obj-$(CONFIG_PATA_LEGACY) += pata_legacy.o 67obj-$(CONFIG_PATA_LEGACY) += pata_legacy.o
67 68
68libata-objs := libata-core.o libata-scsi.o libata-sff.o libata-eh.o 69libata-objs := libata-core.o libata-scsi.o libata-sff.o libata-eh.o
69 70libata-$(CONFIG_SATA_ACPI) += libata-acpi.o
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 6a3543e062..dc7b562259 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -46,7 +46,7 @@
46#include <linux/libata.h> 46#include <linux/libata.h>
47 47
48#define DRV_NAME "ahci" 48#define DRV_NAME "ahci"
49#define DRV_VERSION "2.0" 49#define DRV_VERSION "2.1"
50 50
51 51
52enum { 52enum {
@@ -198,9 +198,9 @@ struct ahci_port_priv {
198 void *rx_fis; 198 void *rx_fis;
199 dma_addr_t rx_fis_dma; 199 dma_addr_t rx_fis_dma;
200 /* for NCQ spurious interrupt analysis */ 200 /* for NCQ spurious interrupt analysis */
201 int ncq_saw_spurious_sdb_cnt;
202 unsigned int ncq_saw_d2h:1; 201 unsigned int ncq_saw_d2h:1;
203 unsigned int ncq_saw_dmas:1; 202 unsigned int ncq_saw_dmas:1;
203 unsigned int ncq_saw_sdb:1;
204}; 204};
205 205
206static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg); 206static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg);
@@ -219,10 +219,12 @@ static void ahci_thaw(struct ata_port *ap);
219static void ahci_error_handler(struct ata_port *ap); 219static void ahci_error_handler(struct ata_port *ap);
220static void ahci_vt8251_error_handler(struct ata_port *ap); 220static void ahci_vt8251_error_handler(struct ata_port *ap);
221static void ahci_post_internal_cmd(struct ata_queued_cmd *qc); 221static void ahci_post_internal_cmd(struct ata_queued_cmd *qc);
222#ifdef CONFIG_PM
222static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg); 223static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg);
223static int ahci_port_resume(struct ata_port *ap); 224static int ahci_port_resume(struct ata_port *ap);
224static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg); 225static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
225static int ahci_pci_device_resume(struct pci_dev *pdev); 226static int ahci_pci_device_resume(struct pci_dev *pdev);
227#endif
226 228
227static struct scsi_host_template ahci_sht = { 229static struct scsi_host_template ahci_sht = {
228 .module = THIS_MODULE, 230 .module = THIS_MODULE,
@@ -241,8 +243,10 @@ static struct scsi_host_template ahci_sht = {
241 .slave_configure = ata_scsi_slave_config, 243 .slave_configure = ata_scsi_slave_config,
242 .slave_destroy = ata_scsi_slave_destroy, 244 .slave_destroy = ata_scsi_slave_destroy,
243 .bios_param = ata_std_bios_param, 245 .bios_param = ata_std_bios_param,
246#ifdef CONFIG_PM
244 .suspend = ata_scsi_device_suspend, 247 .suspend = ata_scsi_device_suspend,
245 .resume = ata_scsi_device_resume, 248 .resume = ata_scsi_device_resume,
249#endif
246}; 250};
247 251
248static const struct ata_port_operations ahci_ops = { 252static const struct ata_port_operations ahci_ops = {
@@ -271,8 +275,10 @@ static const struct ata_port_operations ahci_ops = {
271 .error_handler = ahci_error_handler, 275 .error_handler = ahci_error_handler,
272 .post_internal_cmd = ahci_post_internal_cmd, 276 .post_internal_cmd = ahci_post_internal_cmd,
273 277
278#ifdef CONFIG_PM
274 .port_suspend = ahci_port_suspend, 279 .port_suspend = ahci_port_suspend,
275 .port_resume = ahci_port_resume, 280 .port_resume = ahci_port_resume,
281#endif
276 282
277 .port_start = ahci_port_start, 283 .port_start = ahci_port_start,
278 .port_stop = ahci_port_stop, 284 .port_stop = ahci_port_stop,
@@ -304,8 +310,10 @@ static const struct ata_port_operations ahci_vt8251_ops = {
304 .error_handler = ahci_vt8251_error_handler, 310 .error_handler = ahci_vt8251_error_handler,
305 .post_internal_cmd = ahci_post_internal_cmd, 311 .post_internal_cmd = ahci_post_internal_cmd,
306 312
313#ifdef CONFIG_PM
307 .port_suspend = ahci_port_suspend, 314 .port_suspend = ahci_port_suspend,
308 .port_resume = ahci_port_resume, 315 .port_resume = ahci_port_resume,
316#endif
309 317
310 .port_start = ahci_port_start, 318 .port_start = ahci_port_start,
311 .port_stop = ahci_port_stop, 319 .port_stop = ahci_port_stop,
@@ -381,16 +389,14 @@ static const struct pci_device_id ahci_pci_tbl[] = {
381 { PCI_VDEVICE(INTEL, 0x2929), board_ahci_pi }, /* ICH9M */ 389 { PCI_VDEVICE(INTEL, 0x2929), board_ahci_pi }, /* ICH9M */
382 { PCI_VDEVICE(INTEL, 0x292a), board_ahci_pi }, /* ICH9M */ 390 { PCI_VDEVICE(INTEL, 0x292a), board_ahci_pi }, /* ICH9M */
383 { PCI_VDEVICE(INTEL, 0x292b), board_ahci_pi }, /* ICH9M */ 391 { PCI_VDEVICE(INTEL, 0x292b), board_ahci_pi }, /* ICH9M */
392 { PCI_VDEVICE(INTEL, 0x292c), board_ahci_pi }, /* ICH9M */
384 { PCI_VDEVICE(INTEL, 0x292f), board_ahci_pi }, /* ICH9M */ 393 { PCI_VDEVICE(INTEL, 0x292f), board_ahci_pi }, /* ICH9M */
385 { PCI_VDEVICE(INTEL, 0x294d), board_ahci_pi }, /* ICH9 */ 394 { PCI_VDEVICE(INTEL, 0x294d), board_ahci_pi }, /* ICH9 */
386 { PCI_VDEVICE(INTEL, 0x294e), board_ahci_pi }, /* ICH9M */ 395 { PCI_VDEVICE(INTEL, 0x294e), board_ahci_pi }, /* ICH9M */
387 396
388 /* JMicron */ 397 /* JMicron 360/1/3/5/6, match class to avoid IDE function */
389 { PCI_VDEVICE(JMICRON, 0x2360), board_ahci_ign_iferr }, /* JMB360 */ 398 { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
390 { PCI_VDEVICE(JMICRON, 0x2361), board_ahci_ign_iferr }, /* JMB361 */ 399 PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci_ign_iferr },
391 { PCI_VDEVICE(JMICRON, 0x2363), board_ahci_ign_iferr }, /* JMB363 */
392 { PCI_VDEVICE(JMICRON, 0x2365), board_ahci_ign_iferr }, /* JMB365 */
393 { PCI_VDEVICE(JMICRON, 0x2366), board_ahci_ign_iferr }, /* JMB366 */
394 400
395 /* ATI */ 401 /* ATI */
396 { PCI_VDEVICE(ATI, 0x4380), board_ahci }, /* ATI SB600 non-raid */ 402 { PCI_VDEVICE(ATI, 0x4380), board_ahci }, /* ATI SB600 non-raid */
@@ -439,8 +445,10 @@ static struct pci_driver ahci_pci_driver = {
439 .id_table = ahci_pci_tbl, 445 .id_table = ahci_pci_tbl,
440 .probe = ahci_init_one, 446 .probe = ahci_init_one,
441 .remove = ata_pci_remove_one, 447 .remove = ata_pci_remove_one,
448#ifdef CONFIG_PM
442 .suspend = ahci_pci_device_suspend, 449 .suspend = ahci_pci_device_suspend,
443 .resume = ahci_pci_device_resume, 450 .resume = ahci_pci_device_resume,
451#endif
444}; 452};
445 453
446 454
@@ -580,6 +588,7 @@ static void ahci_power_up(void __iomem *port_mmio, u32 cap)
580 writel(cmd | PORT_CMD_ICC_ACTIVE, port_mmio + PORT_CMD); 588 writel(cmd | PORT_CMD_ICC_ACTIVE, port_mmio + PORT_CMD);
581} 589}
582 590
591#ifdef CONFIG_PM
583static void ahci_power_down(void __iomem *port_mmio, u32 cap) 592static void ahci_power_down(void __iomem *port_mmio, u32 cap)
584{ 593{
585 u32 cmd, scontrol; 594 u32 cmd, scontrol;
@@ -597,6 +606,7 @@ static void ahci_power_down(void __iomem *port_mmio, u32 cap)
597 cmd &= ~PORT_CMD_SPIN_UP; 606 cmd &= ~PORT_CMD_SPIN_UP;
598 writel(cmd, port_mmio + PORT_CMD); 607 writel(cmd, port_mmio + PORT_CMD);
599} 608}
609#endif
600 610
601static void ahci_init_port(void __iomem *port_mmio, u32 cap, 611static void ahci_init_port(void __iomem *port_mmio, u32 cap,
602 dma_addr_t cmd_slot_dma, dma_addr_t rx_fis_dma) 612 dma_addr_t cmd_slot_dma, dma_addr_t rx_fis_dma)
@@ -1160,23 +1170,32 @@ static void ahci_host_intr(struct ata_port *ap)
1160 known_irq = 1; 1170 known_irq = 1;
1161 } 1171 }
1162 1172
1163 if (status & PORT_IRQ_SDB_FIS && 1173 if (status & PORT_IRQ_SDB_FIS) {
1164 pp->ncq_saw_spurious_sdb_cnt < 10) {
1165 /* SDB FIS containing spurious completions might be
1166 * dangerous, we need to know more about them. Print
1167 * more of it.
1168 */
1169 const __le32 *f = pp->rx_fis + RX_FIS_SDB; 1174 const __le32 *f = pp->rx_fis + RX_FIS_SDB;
1170 1175
1171 ata_port_printk(ap, KERN_INFO, "Spurious SDB FIS during NCQ " 1176 if (le32_to_cpu(f[1])) {
1172 "issue=0x%x SAct=0x%x FIS=%08x:%08x%s\n", 1177 /* SDB FIS containing spurious completions
1178 * might be dangerous, whine and fail commands
1179 * with HSM violation. EH will turn off NCQ
1180 * after several such failures.
1181 */
1182 ata_ehi_push_desc(ehi,
1183 "spurious completions during NCQ "
1184 "issue=0x%x SAct=0x%x FIS=%08x:%08x",
1173 readl(port_mmio + PORT_CMD_ISSUE), 1185 readl(port_mmio + PORT_CMD_ISSUE),
1174 readl(port_mmio + PORT_SCR_ACT), 1186 readl(port_mmio + PORT_SCR_ACT),
1175 le32_to_cpu(f[0]), le32_to_cpu(f[1]), 1187 le32_to_cpu(f[0]), le32_to_cpu(f[1]));
1176 pp->ncq_saw_spurious_sdb_cnt < 10 ? 1188 ehi->err_mask |= AC_ERR_HSM;
1177 "" : ", shutting up"); 1189 ehi->action |= ATA_EH_SOFTRESET;
1178 1190 ata_port_freeze(ap);
1179 pp->ncq_saw_spurious_sdb_cnt++; 1191 } else {
1192 if (!pp->ncq_saw_sdb)
1193 ata_port_printk(ap, KERN_INFO,
1194 "spurious SDB FIS %08x:%08x during NCQ, "
1195 "this message won't be printed again\n",
1196 le32_to_cpu(f[0]), le32_to_cpu(f[1]));
1197 pp->ncq_saw_sdb = 1;
1198 }
1180 known_irq = 1; 1199 known_irq = 1;
1181 } 1200 }
1182 1201
@@ -1329,6 +1348,7 @@ static void ahci_post_internal_cmd(struct ata_queued_cmd *qc)
1329 } 1348 }
1330} 1349}
1331 1350
1351#ifdef CONFIG_PM
1332static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg) 1352static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg)
1333{ 1353{
1334 struct ahci_host_priv *hpriv = ap->host->private_data; 1354 struct ahci_host_priv *hpriv = ap->host->private_data;
@@ -1407,6 +1427,7 @@ static int ahci_pci_device_resume(struct pci_dev *pdev)
1407 1427
1408 return 0; 1428 return 0;
1409} 1429}
1430#endif
1410 1431
1411static int ahci_port_start(struct ata_port *ap) 1432static int ahci_port_start(struct ata_port *ap)
1412{ 1433{
@@ -1665,13 +1686,6 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1665 if (!printed_version++) 1686 if (!printed_version++)
1666 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 1687 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
1667 1688
1668 if (pdev->vendor == PCI_VENDOR_ID_JMICRON) {
1669 /* Function 1 is the PATA controller except on the 368, where
1670 we are not AHCI anyway */
1671 if (PCI_FUNC(pdev->devfn))
1672 return -ENODEV;
1673 }
1674
1675 rc = pcim_enable_device(pdev); 1689 rc = pcim_enable_device(pdev);
1676 if (rc) 1690 if (rc)
1677 return rc; 1691 return rc;
diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c
index be66ea08da..d8e79882b8 100644
--- a/drivers/ata/ata_generic.c
+++ b/drivers/ata/ata_generic.c
@@ -26,7 +26,7 @@
26#include <linux/libata.h> 26#include <linux/libata.h>
27 27
28#define DRV_NAME "ata_generic" 28#define DRV_NAME "ata_generic"
29#define DRV_VERSION "0.2.10" 29#define DRV_VERSION "0.2.11"
30 30
31/* 31/*
32 * A generic parallel ATA driver using libata 32 * A generic parallel ATA driver using libata
@@ -90,10 +90,10 @@ static int generic_set_mode(struct ata_port *ap, struct ata_device **unused)
90 /* We do need the right mode information for DMA or PIO 90 /* We do need the right mode information for DMA or PIO
91 and this comes from the current configuration flags */ 91 and this comes from the current configuration flags */
92 if (dma_enabled & (1 << (5 + i))) { 92 if (dma_enabled & (1 << (5 + i))) {
93 dev->xfer_mode = XFER_MW_DMA_0; 93 ata_id_to_dma_mode(dev, XFER_MW_DMA_0);
94 dev->xfer_shift = ATA_SHIFT_MWDMA;
95 dev->flags &= ~ATA_DFLAG_PIO; 94 dev->flags &= ~ATA_DFLAG_PIO;
96 } else { 95 } else {
96 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
97 dev->xfer_mode = XFER_PIO_0; 97 dev->xfer_mode = XFER_PIO_0;
98 dev->xfer_shift = ATA_SHIFT_PIO; 98 dev->xfer_shift = ATA_SHIFT_PIO;
99 dev->flags |= ATA_DFLAG_PIO; 99 dev->flags |= ATA_DFLAG_PIO;
@@ -119,8 +119,10 @@ static struct scsi_host_template generic_sht = {
119 .slave_configure = ata_scsi_slave_config, 119 .slave_configure = ata_scsi_slave_config,
120 .slave_destroy = ata_scsi_slave_destroy, 120 .slave_destroy = ata_scsi_slave_destroy,
121 .bios_param = ata_std_bios_param, 121 .bios_param = ata_std_bios_param,
122#ifdef CONFIG_PM
122 .resume = ata_scsi_device_resume, 123 .resume = ata_scsi_device_resume,
123 .suspend = ata_scsi_device_suspend, 124 .suspend = ata_scsi_device_suspend,
125#endif
124}; 126};
125 127
126static struct ata_port_operations generic_port_ops = { 128static struct ata_port_operations generic_port_ops = {
@@ -230,8 +232,10 @@ static struct pci_driver ata_generic_pci_driver = {
230 .id_table = ata_generic, 232 .id_table = ata_generic,
231 .probe = ata_generic_init_one, 233 .probe = ata_generic_init_one,
232 .remove = ata_pci_remove_one, 234 .remove = ata_pci_remove_one,
235#ifdef CONFIG_PM
233 .suspend = ata_pci_device_suspend, 236 .suspend = ata_pci_device_suspend,
234 .resume = ata_pci_device_resume, 237 .resume = ata_pci_device_resume,
238#endif
235}; 239};
236 240
237static int __init ata_generic_init(void) 241static int __init ata_generic_init(void)
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index 4d716c7347..b952c58433 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -93,7 +93,7 @@
93#include <linux/libata.h> 93#include <linux/libata.h>
94 94
95#define DRV_NAME "ata_piix" 95#define DRV_NAME "ata_piix"
96#define DRV_VERSION "2.00ac7" 96#define DRV_VERSION "2.10ac1"
97 97
98enum { 98enum {
99 PIIX_IOCFG = 0x54, /* IDE I/O configuration register */ 99 PIIX_IOCFG = 0x54, /* IDE I/O configuration register */
@@ -169,8 +169,6 @@ static const struct pci_device_id piix_pci_tbl[] = {
169 /* Intel PIIX4 for the 430TX/440BX/MX chipset: UDMA 33 */ 169 /* Intel PIIX4 for the 430TX/440BX/MX chipset: UDMA 33 */
170 /* Also PIIX4E (fn3 rev 2) and PIIX4M (fn3 rev 3) */ 170 /* Also PIIX4E (fn3 rev 2) and PIIX4M (fn3 rev 3) */
171 { 0x8086, 0x7111, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 }, 171 { 0x8086, 0x7111, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 },
172 { 0x8086, 0x24db, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
173 { 0x8086, 0x25a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
174 /* Intel PIIX4 */ 172 /* Intel PIIX4 */
175 { 0x8086, 0x7199, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 }, 173 { 0x8086, 0x7199, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 },
176 /* Intel PIIX4 */ 174 /* Intel PIIX4 */
@@ -255,8 +253,10 @@ static struct pci_driver piix_pci_driver = {
255 .id_table = piix_pci_tbl, 253 .id_table = piix_pci_tbl,
256 .probe = piix_init_one, 254 .probe = piix_init_one,
257 .remove = ata_pci_remove_one, 255 .remove = ata_pci_remove_one,
256#ifdef CONFIG_PM
258 .suspend = ata_pci_device_suspend, 257 .suspend = ata_pci_device_suspend,
259 .resume = ata_pci_device_resume, 258 .resume = ata_pci_device_resume,
259#endif
260}; 260};
261 261
262static struct scsi_host_template piix_sht = { 262static struct scsi_host_template piix_sht = {
@@ -275,8 +275,10 @@ static struct scsi_host_template piix_sht = {
275 .slave_configure = ata_scsi_slave_config, 275 .slave_configure = ata_scsi_slave_config,
276 .slave_destroy = ata_scsi_slave_destroy, 276 .slave_destroy = ata_scsi_slave_destroy,
277 .bios_param = ata_std_bios_param, 277 .bios_param = ata_std_bios_param,
278#ifdef CONFIG_PM
278 .resume = ata_scsi_device_resume, 279 .resume = ata_scsi_device_resume,
279 .suspend = ata_scsi_device_suspend, 280 .suspend = ata_scsi_device_suspend,
281#endif
280}; 282};
281 283
282static const struct ata_port_operations piix_pata_ops = { 284static const struct ata_port_operations piix_pata_ops = {
@@ -665,14 +667,9 @@ static int ich_pata_prereset(struct ata_port *ap)
665{ 667{
666 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 668 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
667 669
668 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no])) { 670 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no]))
669 ata_port_printk(ap, KERN_INFO, "port disabled. ignoring.\n"); 671 return -ENOENT;
670 ap->eh_context.i.action &= ~ATA_EH_RESET_MASK;
671 return 0;
672 }
673
674 ich_pata_cbl_detect(ap); 672 ich_pata_cbl_detect(ap);
675
676 return ata_std_prereset(ap); 673 return ata_std_prereset(ap);
677} 674}
678 675
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
new file mode 100644
index 0000000000..019d8ffdde
--- /dev/null
+++ b/drivers/ata/libata-acpi.c
@@ -0,0 +1,702 @@
1/*
2 * libata-acpi.c
3 * Provides ACPI support for PATA/SATA.
4 *
5 * Copyright (C) 2006 Intel Corp.
6 * Copyright (C) 2006 Randy Dunlap
7 */
8
9#include <linux/ata.h>
10#include <linux/delay.h>
11#include <linux/device.h>
12#include <linux/errno.h>
13#include <linux/kernel.h>
14#include <linux/acpi.h>
15#include <linux/libata.h>
16#include <linux/pci.h>
17#include "libata.h"
18
19#include <acpi/acpi_bus.h>
20#include <acpi/acnames.h>
21#include <acpi/acnamesp.h>
22#include <acpi/acparser.h>
23#include <acpi/acexcep.h>
24#include <acpi/acmacros.h>
25#include <acpi/actypes.h>
26
27#define SATA_ROOT_PORT(x) (((x) >> 16) & 0xffff)
28#define SATA_PORT_NUMBER(x) ((x) & 0xffff) /* or NO_PORT_MULT */
29#define NO_PORT_MULT 0xffff
30#define SATA_ADR_RSVD 0xffffffff
31
32#define REGS_PER_GTF 7
33struct taskfile_array {
34 u8 tfa[REGS_PER_GTF]; /* regs. 0x1f1 - 0x1f7 */
35};
36
37/*
38 * Helper - belongs in the PCI layer somewhere eventually
39 */
40static int is_pci_dev(struct device *dev)
41{
42 return (dev->bus == &pci_bus_type);
43}
44
45/**
46 * sata_get_dev_handle - finds acpi_handle and PCI device.function
47 * @dev: device to locate
48 * @handle: returned acpi_handle for @dev
49 * @pcidevfn: return PCI device.func for @dev
50 *
51 * This function is somewhat SATA-specific. Or at least the
52 * PATA & SATA versions of this function are different,
53 * so it's not entirely generic code.
54 *
55 * Returns 0 on success, <0 on error.
56 */
57static int sata_get_dev_handle(struct device *dev, acpi_handle *handle,
58 acpi_integer *pcidevfn)
59{
60 struct pci_dev *pci_dev;
61 acpi_integer addr;
62
63 if (!is_pci_dev(dev))
64 return -ENODEV;
65
66 pci_dev = to_pci_dev(dev); /* NOTE: PCI-specific */
67 /* Please refer to the ACPI spec for the syntax of _ADR. */
68 addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
69 *pcidevfn = addr;
70 *handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr);
71 if (!*handle)
72 return -ENODEV;
73 return 0;
74}
75
76/**
77 * pata_get_dev_handle - finds acpi_handle and PCI device.function
78 * @dev: device to locate
79 * @handle: returned acpi_handle for @dev
80 * @pcidevfn: return PCI device.func for @dev
81 *
82 * The PATA and SATA versions of this function are different.
83 *
84 * Returns 0 on success, <0 on error.
85 */
86static int pata_get_dev_handle(struct device *dev, acpi_handle *handle,
87 acpi_integer *pcidevfn)
88{
89 unsigned int bus, devnum, func;
90 acpi_integer addr;
91 acpi_handle dev_handle, parent_handle;
92 struct acpi_buffer buffer = {.length = ACPI_ALLOCATE_BUFFER,
93 .pointer = NULL};
94 acpi_status status;
95 struct acpi_device_info *dinfo = NULL;
96 int ret = -ENODEV;
97 struct pci_dev *pdev;
98
99 if (!is_pci_dev(dev))
100 return -ENODEV;
101
102 pdev = to_pci_dev(dev);
103
104 bus = pdev->bus->number;
105 devnum = PCI_SLOT(pdev->devfn);
106 func = PCI_FUNC(pdev->devfn);
107
108 dev_handle = DEVICE_ACPI_HANDLE(dev);
109 parent_handle = DEVICE_ACPI_HANDLE(dev->parent);
110
111 status = acpi_get_object_info(parent_handle, &buffer);
112 if (ACPI_FAILURE(status))
113 goto err;
114
115 dinfo = buffer.pointer;
116 if (dinfo && (dinfo->valid & ACPI_VALID_ADR) &&
117 dinfo->address == bus) {
118 /* ACPI spec for _ADR for PCI bus: */
119 addr = (acpi_integer)(devnum << 16 | func);
120 *pcidevfn = addr;
121 *handle = dev_handle;
122 } else {
123 goto err;
124 }
125
126 if (!*handle)
127 goto err;
128 ret = 0;
129err:
130 kfree(dinfo);
131 return ret;
132}
133
134struct walk_info { /* can be trimmed some */
135 struct device *dev;
136 struct acpi_device *adev;
137 acpi_handle handle;
138 acpi_integer pcidevfn;
139 unsigned int drivenum;
140 acpi_handle obj_handle;
141 struct ata_port *ataport;
142 struct ata_device *atadev;
143 u32 sata_adr;
144 int status;
145 char basepath[ACPI_PATHNAME_MAX];
146 int basepath_len;
147};
148
149static acpi_status get_devices(acpi_handle handle,
150 u32 level, void *context, void **return_value)
151{
152 acpi_status status;
153 struct walk_info *winfo = context;
154 struct acpi_buffer namebuf = {ACPI_ALLOCATE_BUFFER, NULL};
155 char *pathname;
156 struct acpi_buffer buffer;
157 struct acpi_device_info *dinfo;
158
159 status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &namebuf);
160 if (status)
161 goto ret;
162 pathname = namebuf.pointer;
163
164 buffer.length = ACPI_ALLOCATE_BUFFER;
165 buffer.pointer = NULL;
166 status = acpi_get_object_info(handle, &buffer);
167 if (ACPI_FAILURE(status))
168 goto out2;
169
170 dinfo = buffer.pointer;
171
172 /* find full device path name for pcidevfn */
173 if (dinfo && (dinfo->valid & ACPI_VALID_ADR) &&
174 dinfo->address == winfo->pcidevfn) {
175 if (ata_msg_probe(winfo->ataport))
176 ata_dev_printk(winfo->atadev, KERN_DEBUG,
177 ":%s: matches pcidevfn (0x%llx)\n",
178 pathname, winfo->pcidevfn);
179 strlcpy(winfo->basepath, pathname,
180 sizeof(winfo->basepath));
181 winfo->basepath_len = strlen(pathname);
182 goto out;
183 }
184
185 /* if basepath is not yet known, ignore this object */
186 if (!winfo->basepath_len)
187 goto out;
188
189 /* if this object is in scope of basepath, maybe use it */
190 if (strncmp(pathname, winfo->basepath,
191 winfo->basepath_len) == 0) {
192 if (!(dinfo->valid & ACPI_VALID_ADR))
193 goto out;
194 if (ata_msg_probe(winfo->ataport))
195 ata_dev_printk(winfo->atadev, KERN_DEBUG,
196 "GOT ONE: (%s) root_port = 0x%llx,"
197 " port_num = 0x%llx\n", pathname,
198 SATA_ROOT_PORT(dinfo->address),
199 SATA_PORT_NUMBER(dinfo->address));
200 /* heuristics: */
201 if (SATA_PORT_NUMBER(dinfo->address) != NO_PORT_MULT)
202 if (ata_msg_probe(winfo->ataport))
203 ata_dev_printk(winfo->atadev,
204 KERN_DEBUG, "warning: don't"
205 " know how to handle SATA port"
206 " multiplier\n");
207 if (SATA_ROOT_PORT(dinfo->address) ==
208 winfo->ataport->port_no &&
209 SATA_PORT_NUMBER(dinfo->address) == NO_PORT_MULT) {
210 if (ata_msg_probe(winfo->ataport))
211 ata_dev_printk(winfo->atadev,
212 KERN_DEBUG,
213 "THIS ^^^^^ is the requested"
214 " SATA drive (handle = 0x%p)\n",
215 handle);
216 winfo->sata_adr = dinfo->address;
217 winfo->obj_handle = handle;
218 }
219 }
220out:
221 kfree(dinfo);
222out2:
223 kfree(pathname);
224
225ret:
226 return status;
227}
228
229/* Get the SATA drive _ADR object. */
230static int get_sata_adr(struct device *dev, acpi_handle handle,
231 acpi_integer pcidevfn, unsigned int drive,
232 struct ata_port *ap,
233 struct ata_device *atadev, u32 *dev_adr)
234{
235 acpi_status status;
236 struct walk_info *winfo;
237 int err = -ENOMEM;
238
239 winfo = kzalloc(sizeof(struct walk_info), GFP_KERNEL);
240 if (!winfo)
241 goto out;
242
243 winfo->dev = dev;
244 winfo->atadev = atadev;
245 winfo->ataport = ap;
246 if (acpi_bus_get_device(handle, &winfo->adev) < 0)
247 if (ata_msg_probe(ap))
248 ata_dev_printk(winfo->atadev, KERN_DEBUG,
249 "acpi_bus_get_device failed\n");
250 winfo->handle = handle;
251 winfo->pcidevfn = pcidevfn;
252 winfo->drivenum = drive;
253
254 status = acpi_get_devices(NULL, get_devices, winfo, NULL);
255 if (ACPI_FAILURE(status)) {
256 if (ata_msg_probe(ap))
257 ata_dev_printk(winfo->atadev, KERN_DEBUG,
258 "%s: acpi_get_devices failed\n",
259 __FUNCTION__);
260 err = -ENODEV;
261 } else {
262 *dev_adr = winfo->sata_adr;
263 atadev->obj_handle = winfo->obj_handle;
264 err = 0;
265 }
266 kfree(winfo);
267out:
268 return err;
269}
270
271/**
272 * do_drive_get_GTF - get the drive bootup default taskfile settings
273 * @ap: the ata_port for the drive
274 * @ix: target ata_device (drive) index
275 * @gtf_length: number of bytes of _GTF data returned at @gtf_address
276 * @gtf_address: buffer containing _GTF taskfile arrays
277 *
278 * This applies to both PATA and SATA drives.
279 *
280 * The _GTF method has no input parameters.
281 * It returns a variable number of register set values (registers
282 * hex 1F1..1F7, taskfiles).
283 * The <variable number> is not known in advance, so have ACPI-CA
284 * allocate the buffer as needed and return it, then free it later.
285 *
286 * The returned @gtf_length and @gtf_address are only valid if the
287 * function return value is 0.
288 */
289static int do_drive_get_GTF(struct ata_port *ap, int ix,
290 unsigned int *gtf_length, unsigned long *gtf_address,
291 unsigned long *obj_loc)
292{
293 acpi_status status;
294 acpi_handle dev_handle = NULL;
295 acpi_handle chan_handle, drive_handle;
296 acpi_integer pcidevfn = 0;
297 u32 dev_adr;
298 struct acpi_buffer output;
299 union acpi_object *out_obj;
300 struct device *dev = ap->host->dev;
301 struct ata_device *atadev = &ap->device[ix];
302 int err = -ENODEV;
303
304 *gtf_length = 0;
305 *gtf_address = 0UL;
306 *obj_loc = 0UL;
307
308 if (noacpi)
309 return 0;
310
311 if (ata_msg_probe(ap))
312 ata_dev_printk(atadev, KERN_DEBUG, "%s: ENTER: port#: %d\n",
313 __FUNCTION__, ap->port_no);
314
315 if (!ata_dev_enabled(atadev) || (ap->flags & ATA_FLAG_DISABLED)) {
316 if (ata_msg_probe(ap))
317 ata_dev_printk(atadev, KERN_DEBUG, "%s: ERR: "
318 "ata_dev_present: %d, PORT_DISABLED: %lu\n",
319 __FUNCTION__, ata_dev_enabled(atadev),
320 ap->flags & ATA_FLAG_DISABLED);
321 goto out;
322 }
323
324 /* Don't continue if device has no _ADR method.
325 * _GTF is intended for known motherboard devices. */
326 if (!(ap->cbl == ATA_CBL_SATA)) {
327 err = pata_get_dev_handle(dev, &dev_handle, &pcidevfn);
328 if (err < 0) {
329 if (ata_msg_probe(ap))
330 ata_dev_printk(atadev, KERN_DEBUG,
331 "%s: pata_get_dev_handle failed (%d)\n",
332 __FUNCTION__, err);
333 goto out;
334 }
335 } else {
336 err = sata_get_dev_handle(dev, &dev_handle, &pcidevfn);
337 if (err < 0) {
338 if (ata_msg_probe(ap))
339 ata_dev_printk(atadev, KERN_DEBUG,
340 "%s: sata_get_dev_handle failed (%d\n",
341 __FUNCTION__, err);
342 goto out;
343 }
344 }
345
346 /* Get this drive's _ADR info. if not already known. */
347 if (!atadev->obj_handle) {
348 if (!(ap->cbl == ATA_CBL_SATA)) {
349 /* get child objects of dev_handle == channel objects,
350 * + _their_ children == drive objects */
351 /* channel is ap->port_no */
352 chan_handle = acpi_get_child(dev_handle,
353 ap->port_no);
354 if (ata_msg_probe(ap))
355 ata_dev_printk(atadev, KERN_DEBUG,
356 "%s: chan adr=%d: chan_handle=0x%p\n",
357 __FUNCTION__, ap->port_no,
358 chan_handle);
359 if (!chan_handle) {
360 err = -ENODEV;
361 goto out;
362 }
363 /* TBD: could also check ACPI object VALID bits */
364 drive_handle = acpi_get_child(chan_handle, ix);
365 if (!drive_handle) {
366 err = -ENODEV;
367 goto out;
368 }
369 dev_adr = ix;
370 atadev->obj_handle = drive_handle;
371 } else { /* for SATA mode */
372 dev_adr = SATA_ADR_RSVD;
373 err = get_sata_adr(dev, dev_handle, pcidevfn, 0,
374 ap, atadev, &dev_adr);
375 }
376 if (err < 0 || dev_adr == SATA_ADR_RSVD ||
377 !atadev->obj_handle) {
378 if (ata_msg_probe(ap))
379 ata_dev_printk(atadev, KERN_DEBUG,
380 "%s: get_sata/pata_adr failed: "
381 "err=%d, dev_adr=%u, obj_handle=0x%p\n",
382 __FUNCTION__, err, dev_adr,
383 atadev->obj_handle);
384 goto out;
385 }
386 }
387
388 /* Setting up output buffer */
389 output.length = ACPI_ALLOCATE_BUFFER;
390 output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
391
392 /* _GTF has no input parameters */
393 err = -EIO;
394 status = acpi_evaluate_object(atadev->obj_handle, "_GTF",
395 NULL, &output);
396 if (ACPI_FAILURE(status)) {
397 if (ata_msg_probe(ap))
398 ata_dev_printk(atadev, KERN_DEBUG,
399 "%s: Run _GTF error: status = 0x%x\n",
400 __FUNCTION__, status);
401 goto out;
402 }
403
404 if (!output.length || !output.pointer) {
405 if (ata_msg_probe(ap))
406 ata_dev_printk(atadev, KERN_DEBUG, "%s: Run _GTF: "
407 "length or ptr is NULL (0x%llx, 0x%p)\n",
408 __FUNCTION__,
409 (unsigned long long)output.length,
410 output.pointer);
411 kfree(output.pointer);
412 goto out;
413 }
414
415 out_obj = output.pointer;
416 if (out_obj->type != ACPI_TYPE_BUFFER) {
417 kfree(output.pointer);
418 if (ata_msg_probe(ap))
419 ata_dev_printk(atadev, KERN_DEBUG, "%s: Run _GTF: "
420 "error: expected object type of "
421 " ACPI_TYPE_BUFFER, got 0x%x\n",
422 __FUNCTION__, out_obj->type);
423 err = -ENOENT;
424 goto out;
425 }
426
427 if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
428 out_obj->buffer.length % REGS_PER_GTF) {
429 if (ata_msg_drv(ap))
430 ata_dev_printk(atadev, KERN_ERR,
431 "%s: unexpected GTF length (%d) or addr (0x%p)\n",
432 __FUNCTION__, out_obj->buffer.length,
433 out_obj->buffer.pointer);
434 err = -ENOENT;
435 goto out;
436 }
437
438 *gtf_length = out_obj->buffer.length;
439 *gtf_address = (unsigned long)out_obj->buffer.pointer;
440 *obj_loc = (unsigned long)out_obj;
441 if (ata_msg_probe(ap))
442 ata_dev_printk(atadev, KERN_DEBUG, "%s: returning "
443 "gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n",
444 __FUNCTION__, *gtf_length, *gtf_address, *obj_loc);
445 err = 0;
446out:
447 return err;
448}
449
450/**
451 * taskfile_load_raw - send taskfile registers to host controller
452 * @ap: Port to which output is sent
453 * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7)
454 *
455 * Outputs ATA taskfile to standard ATA host controller using MMIO
456 * or PIO as indicated by the ATA_FLAG_MMIO flag.
457 * Writes the control, feature, nsect, lbal, lbam, and lbah registers.
458 * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect,
459 * hob_lbal, hob_lbam, and hob_lbah.
460 *
461 * This function waits for idle (!BUSY and !DRQ) after writing
462 * registers. If the control register has a new value, this
463 * function also waits for idle after writing control and before
464 * writing the remaining registers.
465 *
466 * LOCKING: TBD:
467 * Inherited from caller.
468 */
469static void taskfile_load_raw(struct ata_port *ap,
470 struct ata_device *atadev,
471 const struct taskfile_array *gtf)
472{
473 struct ata_taskfile tf;
474 unsigned int err;
475
476 if (ata_msg_probe(ap))
477 ata_dev_printk(atadev, KERN_DEBUG, "%s: (0x1f1-1f7): hex: "
478 "%02x %02x %02x %02x %02x %02x %02x\n",
479 __FUNCTION__,
480 gtf->tfa[0], gtf->tfa[1], gtf->tfa[2],
481 gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]);
482
483 if ((gtf->tfa[0] == 0) && (gtf->tfa[1] == 0) && (gtf->tfa[2] == 0)
484 && (gtf->tfa[3] == 0) && (gtf->tfa[4] == 0) && (gtf->tfa[5] == 0)
485 && (gtf->tfa[6] == 0))
486 return;
487
488 ata_tf_init(atadev, &tf);
489
490 /* convert gtf to tf */
491 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; /* TBD */
492 tf.protocol = atadev->class == ATA_DEV_ATAPI ?
493 ATA_PROT_ATAPI_NODATA : ATA_PROT_NODATA;
494 tf.feature = gtf->tfa[0]; /* 0x1f1 */
495 tf.nsect = gtf->tfa[1]; /* 0x1f2 */
496 tf.lbal = gtf->tfa[2]; /* 0x1f3 */
497 tf.lbam = gtf->tfa[3]; /* 0x1f4 */
498 tf.lbah = gtf->tfa[4]; /* 0x1f5 */
499 tf.device = gtf->tfa[5]; /* 0x1f6 */
500 tf.command = gtf->tfa[6]; /* 0x1f7 */
501
502 err = ata_exec_internal(atadev, &tf, NULL, DMA_NONE, NULL, 0);
503 if (err && ata_msg_probe(ap))
504 ata_dev_printk(atadev, KERN_ERR,
505 "%s: ata_exec_internal failed: %u\n",
506 __FUNCTION__, err);
507}
508
509/**
510 * do_drive_set_taskfiles - write the drive taskfile settings from _GTF
511 * @ap: the ata_port for the drive
512 * @atadev: target ata_device
513 * @gtf_length: total number of bytes of _GTF taskfiles
514 * @gtf_address: location of _GTF taskfile arrays
515 *
516 * This applies to both PATA and SATA drives.
517 *
518 * Write {gtf_address, length gtf_length} in groups of
519 * REGS_PER_GTF bytes.
520 */
521static int do_drive_set_taskfiles(struct ata_port *ap,
522 struct ata_device *atadev, unsigned int gtf_length,
523 unsigned long gtf_address)
524{
525 int err = -ENODEV;
526 int gtf_count = gtf_length / REGS_PER_GTF;
527 int ix;
528 struct taskfile_array *gtf;
529
530 if (ata_msg_probe(ap))
531 ata_dev_printk(atadev, KERN_DEBUG, "%s: ENTER: port#: %d\n",
532 __FUNCTION__, ap->port_no);
533
534 if (noacpi || !(ap->cbl == ATA_CBL_SATA))
535 return 0;
536
537 if (!ata_dev_enabled(atadev) || (ap->flags & ATA_FLAG_DISABLED))
538 goto out;
539 if (!gtf_count) /* shouldn't be here */
540 goto out;
541
542 if (gtf_length % REGS_PER_GTF) {
543 if (ata_msg_drv(ap))
544 ata_dev_printk(atadev, KERN_ERR,
545 "%s: unexpected GTF length (%d)\n",
546 __FUNCTION__, gtf_length);
547 goto out;
548 }
549
550 for (ix = 0; ix < gtf_count; ix++) {
551 gtf = (struct taskfile_array *)
552 (gtf_address + ix * REGS_PER_GTF);
553
554 /* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */
555 taskfile_load_raw(ap, atadev, gtf);
556 }
557
558 err = 0;
559out:
560 return err;
561}
562
563/**
564 * ata_acpi_exec_tfs - get then write drive taskfile settings
565 * @ap: the ata_port for the drive
566 *
567 * This applies to both PATA and SATA drives.
568 */
569int ata_acpi_exec_tfs(struct ata_port *ap)
570{
571 int ix;
572 int ret =0;
573 unsigned int gtf_length;
574 unsigned long gtf_address;
575 unsigned long obj_loc;
576
577 if (noacpi)
578 return 0;
579
580 for (ix = 0; ix < ATA_MAX_DEVICES; ix++) {
581 if (!ata_dev_enabled(&ap->device[ix]))
582 continue;
583
584 ret = do_drive_get_GTF(ap, ix,
585 &gtf_length, &gtf_address, &obj_loc);
586 if (ret < 0) {
587 if (ata_msg_probe(ap))
588 ata_port_printk(ap, KERN_DEBUG,
589 "%s: get_GTF error (%d)\n",
590 __FUNCTION__, ret);
591 break;
592 }
593
594 ret = do_drive_set_taskfiles(ap, &ap->device[ix],
595 gtf_length, gtf_address);
596 kfree((void *)obj_loc);
597 if (ret < 0) {
598 if (ata_msg_probe(ap))
599 ata_port_printk(ap, KERN_DEBUG,
600 "%s: set_taskfiles error (%d)\n",
601 __FUNCTION__, ret);
602 break;
603 }
604 }
605
606 return ret;
607}
608
609/**
610 * ata_acpi_push_id - send Identify data to drive
611 * @ap: the ata_port for the drive
612 * @ix: drive index
613 *
614 * _SDD ACPI object: for SATA mode only
615 * Must be after Identify (Packet) Device -- uses its data
616 * ATM this function never returns a failure. It is an optional
617 * method and if it fails for whatever reason, we should still
618 * just keep going.
619 */
620int ata_acpi_push_id(struct ata_port *ap, unsigned int ix)
621{
622 acpi_handle handle;
623 acpi_integer pcidevfn;
624 int err;
625 struct device *dev = ap->host->dev;
626 struct ata_device *atadev = &ap->device[ix];
627 u32 dev_adr;
628 acpi_status status;
629 struct acpi_object_list input;
630 union acpi_object in_params[1];
631
632 if (noacpi)
633 return 0;
634
635 if (ata_msg_probe(ap))
636 ata_dev_printk(atadev, KERN_DEBUG, "%s: ix = %d, port#: %d\n",
637 __FUNCTION__, ix, ap->port_no);
638
639 /* Don't continue if not a SATA device. */
640 if (!(ap->cbl == ATA_CBL_SATA)) {
641 if (ata_msg_probe(ap))
642 ata_dev_printk(atadev, KERN_DEBUG,
643 "%s: Not a SATA device\n", __FUNCTION__);
644 goto out;
645 }
646
647 /* Don't continue if device has no _ADR method.
648 * _SDD is intended for known motherboard devices. */
649 err = sata_get_dev_handle(dev, &handle, &pcidevfn);
650 if (err < 0) {
651 if (ata_msg_probe(ap))
652 ata_dev_printk(atadev, KERN_DEBUG,
653 "%s: sata_get_dev_handle failed (%d\n",
654 __FUNCTION__, err);
655 goto out;
656 }
657
658 /* Get this drive's _ADR info, if not already known */
659 if (!atadev->obj_handle) {
660 dev_adr = SATA_ADR_RSVD;
661 err = get_sata_adr(dev, handle, pcidevfn, ix, ap, atadev,
662 &dev_adr);
663 if (err < 0 || dev_adr == SATA_ADR_RSVD ||
664 !atadev->obj_handle) {
665 if (ata_msg_probe(ap))
666 ata_dev_printk(atadev, KERN_DEBUG,
667 "%s: get_sata_adr failed: "
668 "err=%d, dev_adr=%u, obj_handle=0x%p\n",
669 __FUNCTION__, err, dev_adr,
670 atadev->obj_handle);
671 goto out;
672 }
673 }
674
675 /* Give the drive Identify data to the drive via the _SDD method */
676 /* _SDD: set up input parameters */
677 input.count = 1;
678 input.pointer = in_params;
679 in_params[0].type = ACPI_TYPE_BUFFER;
680 in_params[0].buffer.length = sizeof(atadev->id[0]) * ATA_ID_WORDS;
681 in_params[0].buffer.pointer = (u8 *)atadev->id;
682 /* Output buffer: _SDD has no output */
683
684 /* It's OK for _SDD to be missing too. */
685 swap_buf_le16(atadev->id, ATA_ID_WORDS);
686 status = acpi_evaluate_object(atadev->obj_handle, "_SDD", &input, NULL);
687 swap_buf_le16(atadev->id, ATA_ID_WORDS);
688
689 err = ACPI_FAILURE(status) ? -EIO : 0;
690 if (err < 0) {
691 if (ata_msg_probe(ap))
692 ata_dev_printk(atadev, KERN_DEBUG,
693 "%s _SDD error: status = 0x%x\n",
694 __FUNCTION__, status);
695 }
696
697 /* always return success */
698out:
699 return 0;
700}
701
702
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 2cf8251728..3c1f8830ac 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -59,7 +59,7 @@
59 59
60#include "libata.h" 60#include "libata.h"
61 61
62#define DRV_VERSION "2.10" /* must be exactly four chars */ 62#define DRV_VERSION "2.20" /* must be exactly four chars */
63 63
64 64
65/* debounce timing parameters in msecs { interval, duration, timeout } */ 65/* debounce timing parameters in msecs { interval, duration, timeout } */
@@ -72,7 +72,7 @@ static unsigned int ata_dev_init_params(struct ata_device *dev,
72static unsigned int ata_dev_set_xfermode(struct ata_device *dev); 72static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
73static void ata_dev_xfermask(struct ata_device *dev); 73static void ata_dev_xfermask(struct ata_device *dev);
74 74
75static unsigned int ata_unique_id = 1; 75static unsigned int ata_print_id = 1;
76static struct workqueue_struct *ata_wq; 76static struct workqueue_struct *ata_wq;
77 77
78struct workqueue_struct *ata_aux_wq; 78struct workqueue_struct *ata_aux_wq;
@@ -93,6 +93,10 @@ static int ata_probe_timeout = ATA_TMOUT_INTERNAL / HZ;
93module_param(ata_probe_timeout, int, 0444); 93module_param(ata_probe_timeout, int, 0444);
94MODULE_PARM_DESC(ata_probe_timeout, "Set ATA probing timeout (seconds)"); 94MODULE_PARM_DESC(ata_probe_timeout, "Set ATA probing timeout (seconds)");
95 95
96int noacpi;
97module_param(noacpi, int, 0444);
98MODULE_PARM_DESC(noacpi, "Disables the use of ACPI in suspend/resume when set");
99
96MODULE_AUTHOR("Jeff Garzik"); 100MODULE_AUTHOR("Jeff Garzik");
97MODULE_DESCRIPTION("Library module for ATA devices"); 101MODULE_DESCRIPTION("Library module for ATA devices");
98MODULE_LICENSE("GPL"); 102MODULE_LICENSE("GPL");
@@ -311,9 +315,7 @@ int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
311 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; 315 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
312 tf->flags |= tf_flags; 316 tf->flags |= tf_flags;
313 317
314 if ((dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ_OFF | 318 if (ata_ncq_enabled(dev) && likely(tag != ATA_TAG_INTERNAL)) {
315 ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ &&
316 likely(tag != ATA_TAG_INTERNAL)) {
317 /* yay, NCQ */ 319 /* yay, NCQ */
318 if (!lba_48_ok(block, n_block)) 320 if (!lba_48_ok(block, n_block))
319 return -ERANGE; 321 return -ERANGE;
@@ -596,6 +598,8 @@ void ata_dev_disable(struct ata_device *dev)
596{ 598{
597 if (ata_dev_enabled(dev) && ata_msg_drv(dev->ap)) { 599 if (ata_dev_enabled(dev) && ata_msg_drv(dev->ap)) {
598 ata_dev_printk(dev, KERN_WARNING, "disabled\n"); 600 ata_dev_printk(dev, KERN_WARNING, "disabled\n");
601 ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 |
602 ATA_DNXFER_QUIET);
599 dev->class++; 603 dev->class++;
600 } 604 }
601} 605}
@@ -704,7 +708,7 @@ unsigned int ata_dev_classify(const struct ata_taskfile *tf)
704 * Device type - %ATA_DEV_ATA, %ATA_DEV_ATAPI or %ATA_DEV_NONE. 708 * Device type - %ATA_DEV_ATA, %ATA_DEV_ATAPI or %ATA_DEV_NONE.
705 */ 709 */
706 710
707static unsigned int 711unsigned int
708ata_dev_try_classify(struct ata_port *ap, unsigned int device, u8 *r_err) 712ata_dev_try_classify(struct ata_port *ap, unsigned int device, u8 *r_err)
709{ 713{
710 struct ata_taskfile tf; 714 struct ata_taskfile tf;
@@ -820,6 +824,48 @@ static u64 ata_id_n_sectors(const u16 *id)
820} 824}
821 825
822/** 826/**
827 * ata_id_to_dma_mode - Identify DMA mode from id block
828 * @dev: device to identify
829 * @mode: mode to assume if we cannot tell
830 *
831 * Set up the timing values for the device based upon the identify
832 * reported values for the DMA mode. This function is used by drivers
833 * which rely upon firmware configured modes, but wish to report the
834 * mode correctly when possible.
835 *
836 * In addition we emit similarly formatted messages to the default
837 * ata_dev_set_mode handler, in order to provide consistency of
838 * presentation.
839 */
840
841void ata_id_to_dma_mode(struct ata_device *dev, u8 unknown)
842{
843 unsigned int mask;
844 u8 mode;
845
846 /* Pack the DMA modes */
847 mask = ((dev->id[63] >> 8) << ATA_SHIFT_MWDMA) & ATA_MASK_MWDMA;
848 if (dev->id[53] & 0x04)
849 mask |= ((dev->id[88] >> 8) << ATA_SHIFT_UDMA) & ATA_MASK_UDMA;
850
851 /* Select the mode in use */
852 mode = ata_xfer_mask2mode(mask);
853
854 if (mode != 0) {
855 ata_dev_printk(dev, KERN_INFO, "configured for %s\n",
856 ata_mode_string(mask));
857 } else {
858 /* SWDMA perhaps ? */
859 mode = unknown;
860 ata_dev_printk(dev, KERN_INFO, "configured for DMA\n");
861 }
862
863 /* Configure the device reporting */
864 dev->xfer_mode = mode;
865 dev->xfer_shift = ata_xfer_mode2shift(mode);
866}
867
868/**
823 * ata_noop_dev_select - Select device 0/1 on ATA bus 869 * ata_noop_dev_select - Select device 0/1 on ATA bus
824 * @ap: ATA channel to manipulate 870 * @ap: ATA channel to manipulate
825 * @device: ATA device (numbered from zero) to select 871 * @device: ATA device (numbered from zero) to select
@@ -887,8 +933,8 @@ void ata_dev_select(struct ata_port *ap, unsigned int device,
887 unsigned int wait, unsigned int can_sleep) 933 unsigned int wait, unsigned int can_sleep)
888{ 934{
889 if (ata_msg_probe(ap)) 935 if (ata_msg_probe(ap))
890 ata_port_printk(ap, KERN_INFO, "ata_dev_select: ENTER, ata%u: " 936 ata_port_printk(ap, KERN_INFO, "ata_dev_select: ENTER, "
891 "device %u, wait %u\n", ap->id, device, wait); 937 "device %u, wait %u\n", device, wait);
892 938
893 if (wait) 939 if (wait)
894 ata_wait_idle(ap); 940 ata_wait_idle(ap);
@@ -1388,8 +1434,7 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
1388 int rc; 1434 int rc;
1389 1435
1390 if (ata_msg_ctl(ap)) 1436 if (ata_msg_ctl(ap))
1391 ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER, host %u, dev %u\n", 1437 ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER\n", __FUNCTION__);
1392 __FUNCTION__, ap->id, dev->devno);
1393 1438
1394 ata_dev_select(ap, dev->devno, 1, 1); /* select device 0/1 */ 1439 ata_dev_select(ap, dev->devno, 1, 1); /* select device 0/1 */
1395 1440
@@ -1426,7 +1471,7 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
1426 if (err_mask) { 1471 if (err_mask) {
1427 if (err_mask & AC_ERR_NODEV_HINT) { 1472 if (err_mask & AC_ERR_NODEV_HINT) {
1428 DPRINTK("ata%u.%d: NODEV after polling detection\n", 1473 DPRINTK("ata%u.%d: NODEV after polling detection\n",
1429 ap->id, dev->devno); 1474 ap->print_id, dev->devno);
1430 return -ENOENT; 1475 return -ENOENT;
1431 } 1476 }
1432 1477
@@ -1554,15 +1599,23 @@ int ata_dev_configure(struct ata_device *dev)
1554 int rc; 1599 int rc;
1555 1600
1556 if (!ata_dev_enabled(dev) && ata_msg_info(ap)) { 1601 if (!ata_dev_enabled(dev) && ata_msg_info(ap)) {
1557 ata_dev_printk(dev, KERN_INFO, 1602 ata_dev_printk(dev, KERN_INFO, "%s: ENTER/EXIT -- nodev\n",
1558 "%s: ENTER/EXIT (host %u, dev %u) -- nodev\n", 1603 __FUNCTION__);
1559 __FUNCTION__, ap->id, dev->devno);
1560 return 0; 1604 return 0;
1561 } 1605 }
1562 1606
1563 if (ata_msg_probe(ap)) 1607 if (ata_msg_probe(ap))
1564 ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER, host %u, dev %u\n", 1608 ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER\n", __FUNCTION__);
1565 __FUNCTION__, ap->id, dev->devno); 1609
1610 /* set _SDD */
1611 rc = ata_acpi_push_id(ap, dev->devno);
1612 if (rc) {
1613 ata_dev_printk(dev, KERN_WARNING, "failed to set _SDD(%d)\n",
1614 rc);
1615 }
1616
1617 /* retrieve and execute the ATA task file of _GTF */
1618 ata_acpi_exec_tfs(ap);
1566 1619
1567 /* print device capabilities */ 1620 /* print device capabilities */
1568 if (ata_msg_probe(ap)) 1621 if (ata_msg_probe(ap))
@@ -1596,8 +1649,9 @@ int ata_dev_configure(struct ata_device *dev)
1596 if (dev->class == ATA_DEV_ATA) { 1649 if (dev->class == ATA_DEV_ATA) {
1597 if (ata_id_is_cfa(id)) { 1650 if (ata_id_is_cfa(id)) {
1598 if (id[162] & 1) /* CPRM may make this media unusable */ 1651 if (id[162] & 1) /* CPRM may make this media unusable */
1599 ata_dev_printk(dev, KERN_WARNING, "ata%u: device %u supports DRM functions and may not be fully accessable.\n", 1652 ata_dev_printk(dev, KERN_WARNING,
1600 ap->id, dev->devno); 1653 "supports DRM functions and may "
1654 "not be fully accessable.\n");
1601 snprintf(revbuf, 7, "CFA"); 1655 snprintf(revbuf, 7, "CFA");
1602 } 1656 }
1603 else 1657 else
@@ -1665,7 +1719,7 @@ int ata_dev_configure(struct ata_device *dev)
1665 "%s: %s, %s, max %s\n", 1719 "%s: %s, %s, max %s\n",
1666 revbuf, modelbuf, fwrevbuf, 1720 revbuf, modelbuf, fwrevbuf,
1667 ata_mode_string(xfer_mask)); 1721 ata_mode_string(xfer_mask));
1668 ata_dev_printk(dev, KERN_INFO, 1722 ata_dev_printk(dev, KERN_INFO,
1669 "%Lu sectors, multi %u, CHS %u/%u/%u\n", 1723 "%Lu sectors, multi %u, CHS %u/%u/%u\n",
1670 (unsigned long long)dev->n_sectors, 1724 (unsigned long long)dev->n_sectors,
1671 dev->multi_count, dev->cylinders, 1725 dev->multi_count, dev->cylinders,
@@ -1764,7 +1818,7 @@ int ata_bus_probe(struct ata_port *ap)
1764{ 1818{
1765 unsigned int classes[ATA_MAX_DEVICES]; 1819 unsigned int classes[ATA_MAX_DEVICES];
1766 int tries[ATA_MAX_DEVICES]; 1820 int tries[ATA_MAX_DEVICES];
1767 int i, rc, down_xfermask; 1821 int i, rc;
1768 struct ata_device *dev; 1822 struct ata_device *dev;
1769 1823
1770 ata_port_probe(ap); 1824 ata_port_probe(ap);
@@ -1773,8 +1827,6 @@ int ata_bus_probe(struct ata_port *ap)
1773 tries[i] = ATA_PROBE_MAX_TRIES; 1827 tries[i] = ATA_PROBE_MAX_TRIES;
1774 1828
1775 retry: 1829 retry:
1776 down_xfermask = 0;
1777
1778 /* reset and determine device classes */ 1830 /* reset and determine device classes */
1779 ap->ops->phy_reset(ap); 1831 ap->ops->phy_reset(ap);
1780 1832
@@ -1798,8 +1850,11 @@ int ata_bus_probe(struct ata_port *ap)
1798 for (i = 0; i < ATA_MAX_DEVICES; i++) 1850 for (i = 0; i < ATA_MAX_DEVICES; i++)
1799 ap->device[i].pio_mode = XFER_PIO_0; 1851 ap->device[i].pio_mode = XFER_PIO_0;
1800 1852
1801 /* read IDENTIFY page and configure devices */ 1853 /* read IDENTIFY page and configure devices. We have to do the identify
1802 for (i = 0; i < ATA_MAX_DEVICES; i++) { 1854 specific sequence bass-ackwards so that PDIAG- is released by
1855 the slave device */
1856
1857 for (i = ATA_MAX_DEVICES - 1; i >= 0; i--) {
1803 dev = &ap->device[i]; 1858 dev = &ap->device[i];
1804 1859
1805 if (tries[i]) 1860 if (tries[i])
@@ -1812,6 +1867,15 @@ int ata_bus_probe(struct ata_port *ap)
1812 dev->id); 1867 dev->id);
1813 if (rc) 1868 if (rc)
1814 goto fail; 1869 goto fail;
1870 }
1871
1872 /* After the identify sequence we can now set up the devices. We do
1873 this in the normal order so that the user doesn't get confused */
1874
1875 for(i = 0; i < ATA_MAX_DEVICES; i++) {
1876 dev = &ap->device[i];
1877 if (!ata_dev_enabled(dev))
1878 continue;
1815 1879
1816 ap->eh_context.i.flags |= ATA_EHI_PRINTINFO; 1880 ap->eh_context.i.flags |= ATA_EHI_PRINTINFO;
1817 rc = ata_dev_configure(dev); 1881 rc = ata_dev_configure(dev);
@@ -1822,10 +1886,8 @@ int ata_bus_probe(struct ata_port *ap)
1822 1886
1823 /* configure transfer mode */ 1887 /* configure transfer mode */
1824 rc = ata_set_mode(ap, &dev); 1888 rc = ata_set_mode(ap, &dev);
1825 if (rc) { 1889 if (rc)
1826 down_xfermask = 1;
1827 goto fail; 1890 goto fail;
1828 }
1829 1891
1830 for (i = 0; i < ATA_MAX_DEVICES; i++) 1892 for (i = 0; i < ATA_MAX_DEVICES; i++)
1831 if (ata_dev_enabled(&ap->device[i])) 1893 if (ata_dev_enabled(&ap->device[i]))
@@ -1837,25 +1899,29 @@ int ata_bus_probe(struct ata_port *ap)
1837 return -ENODEV; 1899 return -ENODEV;
1838 1900
1839 fail: 1901 fail:
1902 tries[dev->devno]--;
1903
1840 switch (rc) { 1904 switch (rc) {
1841 case -EINVAL: 1905 case -EINVAL:
1842 case -ENODEV: 1906 /* eeek, something went very wrong, give up */
1843 tries[dev->devno] = 0; 1907 tries[dev->devno] = 0;
1844 break; 1908 break;
1909
1910 case -ENODEV:
1911 /* give it just one more chance */
1912 tries[dev->devno] = min(tries[dev->devno], 1);
1845 case -EIO: 1913 case -EIO:
1846 sata_down_spd_limit(ap); 1914 if (tries[dev->devno] == 1) {
1847 /* fall through */ 1915 /* This is the last chance, better to slow
1848 default: 1916 * down than lose it.
1849 tries[dev->devno]--; 1917 */
1850 if (down_xfermask && 1918 sata_down_spd_limit(ap);
1851 ata_down_xfermask_limit(dev, tries[dev->devno] == 1)) 1919 ata_down_xfermask_limit(dev, ATA_DNXFER_PIO);
1852 tries[dev->devno] = 0; 1920 }
1853 } 1921 }
1854 1922
1855 if (!tries[dev->devno]) { 1923 if (!tries[dev->devno])
1856 ata_down_xfermask_limit(dev, 1);
1857 ata_dev_disable(dev); 1924 ata_dev_disable(dev);
1858 }
1859 1925
1860 goto retry; 1926 goto retry;
1861} 1927}
@@ -2286,7 +2352,7 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
2286/** 2352/**
2287 * ata_down_xfermask_limit - adjust dev xfer masks downward 2353 * ata_down_xfermask_limit - adjust dev xfer masks downward
2288 * @dev: Device to adjust xfer masks 2354 * @dev: Device to adjust xfer masks
2289 * @force_pio0: Force PIO0 2355 * @sel: ATA_DNXFER_* selector
2290 * 2356 *
2291 * Adjust xfer masks of @dev downward. Note that this function 2357 * Adjust xfer masks of @dev downward. Note that this function
2292 * does not apply the change. Invoking ata_set_mode() afterwards 2358 * does not apply the change. Invoking ata_set_mode() afterwards
@@ -2298,37 +2364,78 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
2298 * RETURNS: 2364 * RETURNS:
2299 * 0 on success, negative errno on failure 2365 * 0 on success, negative errno on failure
2300 */ 2366 */
2301int ata_down_xfermask_limit(struct ata_device *dev, int force_pio0) 2367int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel)
2302{ 2368{
2303 unsigned long xfer_mask; 2369 char buf[32];
2304 int highbit; 2370 unsigned int orig_mask, xfer_mask;
2371 unsigned int pio_mask, mwdma_mask, udma_mask;
2372 int quiet, highbit;
2305 2373
2306 xfer_mask = ata_pack_xfermask(dev->pio_mask, dev->mwdma_mask, 2374 quiet = !!(sel & ATA_DNXFER_QUIET);
2307 dev->udma_mask); 2375 sel &= ~ATA_DNXFER_QUIET;
2308 2376
2309 if (!xfer_mask) 2377 xfer_mask = orig_mask = ata_pack_xfermask(dev->pio_mask,
2310 goto fail; 2378 dev->mwdma_mask,
2311 /* don't gear down to MWDMA from UDMA, go directly to PIO */ 2379 dev->udma_mask);
2312 if (xfer_mask & ATA_MASK_UDMA) 2380 ata_unpack_xfermask(xfer_mask, &pio_mask, &mwdma_mask, &udma_mask);
2313 xfer_mask &= ~ATA_MASK_MWDMA;
2314 2381
2315 highbit = fls(xfer_mask) - 1; 2382 switch (sel) {
2316 xfer_mask &= ~(1 << highbit); 2383 case ATA_DNXFER_PIO:
2317 if (force_pio0) 2384 highbit = fls(pio_mask) - 1;
2318 xfer_mask &= 1 << ATA_SHIFT_PIO; 2385 pio_mask &= ~(1 << highbit);
2319 if (!xfer_mask) 2386 break;
2320 goto fail; 2387
2388 case ATA_DNXFER_DMA:
2389 if (udma_mask) {
2390 highbit = fls(udma_mask) - 1;
2391 udma_mask &= ~(1 << highbit);
2392 if (!udma_mask)
2393 return -ENOENT;
2394 } else if (mwdma_mask) {
2395 highbit = fls(mwdma_mask) - 1;
2396 mwdma_mask &= ~(1 << highbit);
2397 if (!mwdma_mask)
2398 return -ENOENT;
2399 }
2400 break;
2401
2402 case ATA_DNXFER_40C:
2403 udma_mask &= ATA_UDMA_MASK_40C;
2404 break;
2405
2406 case ATA_DNXFER_FORCE_PIO0:
2407 pio_mask &= 1;
2408 case ATA_DNXFER_FORCE_PIO:
2409 mwdma_mask = 0;
2410 udma_mask = 0;
2411 break;
2412
2413 default:
2414 BUG();
2415 }
2416
2417 xfer_mask &= ata_pack_xfermask(pio_mask, mwdma_mask, udma_mask);
2418
2419 if (!(xfer_mask & ATA_MASK_PIO) || xfer_mask == orig_mask)
2420 return -ENOENT;
2421
2422 if (!quiet) {
2423 if (xfer_mask & (ATA_MASK_MWDMA | ATA_MASK_UDMA))
2424 snprintf(buf, sizeof(buf), "%s:%s",
2425 ata_mode_string(xfer_mask),
2426 ata_mode_string(xfer_mask & ATA_MASK_PIO));
2427 else
2428 snprintf(buf, sizeof(buf), "%s",
2429 ata_mode_string(xfer_mask));
2430
2431 ata_dev_printk(dev, KERN_WARNING,
2432 "limiting speed to %s\n", buf);
2433 }
2321 2434
2322 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask, 2435 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask,
2323 &dev->udma_mask); 2436 &dev->udma_mask);
2324 2437
2325 ata_dev_printk(dev, KERN_WARNING, "limiting speed to %s\n",
2326 ata_mode_string(xfer_mask));
2327
2328 return 0; 2438 return 0;
2329
2330 fail:
2331 return -EINVAL;
2332} 2439}
2333 2440
2334static int ata_dev_set_mode(struct ata_device *dev) 2441static int ata_dev_set_mode(struct ata_device *dev)
@@ -2461,12 +2568,11 @@ int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
2461 * host channels are not permitted to do so. 2568 * host channels are not permitted to do so.
2462 */ 2569 */
2463 if (used_dma && (ap->host->flags & ATA_HOST_SIMPLEX)) 2570 if (used_dma && (ap->host->flags & ATA_HOST_SIMPLEX))
2464 ap->host->simplex_claimed = 1; 2571 ap->host->simplex_claimed = ap;
2465 2572
2466 /* step5: chip specific finalisation */ 2573 /* step5: chip specific finalisation */
2467 if (ap->ops->post_set_mode) 2574 if (ap->ops->post_set_mode)
2468 ap->ops->post_set_mode(ap); 2575 ap->ops->post_set_mode(ap);
2469
2470 out: 2576 out:
2471 if (rc) 2577 if (rc)
2472 *r_failed_dev = dev; 2578 *r_failed_dev = dev;
@@ -2595,7 +2701,7 @@ static unsigned int ata_bus_softreset(struct ata_port *ap,
2595{ 2701{
2596 struct ata_ioports *ioaddr = &ap->ioaddr; 2702 struct ata_ioports *ioaddr = &ap->ioaddr;
2597 2703
2598 DPRINTK("ata%u: bus reset via SRST\n", ap->id); 2704 DPRINTK("ata%u: bus reset via SRST\n", ap->print_id);
2599 2705
2600 /* software reset. causes dev0 to be selected */ 2706 /* software reset. causes dev0 to be selected */
2601 iowrite8(ap->ctl, ioaddr->ctl_addr); 2707 iowrite8(ap->ctl, ioaddr->ctl_addr);
@@ -2655,7 +2761,7 @@ void ata_bus_reset(struct ata_port *ap)
2655 u8 err; 2761 u8 err;
2656 unsigned int dev0, dev1 = 0, devmask = 0; 2762 unsigned int dev0, dev1 = 0, devmask = 0;
2657 2763
2658 DPRINTK("ENTER, host %u, port %u\n", ap->id, ap->port_no); 2764 DPRINTK("ENTER, host %u, port %u\n", ap->print_id, ap->port_no);
2659 2765
2660 /* determine if device 0/1 are present */ 2766 /* determine if device 0/1 are present */
2661 if (ap->flags & ATA_FLAG_SATA_RESET) 2767 if (ap->flags & ATA_FLAG_SATA_RESET)
@@ -3242,7 +3348,6 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
3242 { "WPI CDD-820", NULL, ATA_HORKAGE_NODMA }, 3348 { "WPI CDD-820", NULL, ATA_HORKAGE_NODMA },
3243 { "SAMSUNG CD-ROM SC-148C", NULL, ATA_HORKAGE_NODMA }, 3349 { "SAMSUNG CD-ROM SC-148C", NULL, ATA_HORKAGE_NODMA },
3244 { "SAMSUNG CD-ROM SC", NULL, ATA_HORKAGE_NODMA }, 3350 { "SAMSUNG CD-ROM SC", NULL, ATA_HORKAGE_NODMA },
3245 { "SanDisk SDP3B-64", NULL, ATA_HORKAGE_NODMA },
3246 { "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL,ATA_HORKAGE_NODMA }, 3351 { "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL,ATA_HORKAGE_NODMA },
3247 { "_NEC DV5800A", NULL, ATA_HORKAGE_NODMA }, 3352 { "_NEC DV5800A", NULL, ATA_HORKAGE_NODMA },
3248 { "SAMSUNG CD-ROM SN-124","N001", ATA_HORKAGE_NODMA }, 3353 { "SAMSUNG CD-ROM SN-124","N001", ATA_HORKAGE_NODMA },
@@ -3252,6 +3357,8 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
3252 /* Devices where NCQ should be avoided */ 3357 /* Devices where NCQ should be avoided */
3253 /* NCQ is slow */ 3358 /* NCQ is slow */
3254 { "WDC WD740ADFD-00", NULL, ATA_HORKAGE_NONCQ }, 3359 { "WDC WD740ADFD-00", NULL, ATA_HORKAGE_NONCQ },
3360 /* http://thread.gmane.org/gmane.linux.ide/14907 */
3361 { "FUJITSU MHT2060BH", NULL, ATA_HORKAGE_NONCQ },
3255 3362
3256 /* Devices with NCQ limits */ 3363 /* Devices with NCQ limits */
3257 3364
@@ -3348,7 +3455,8 @@ static void ata_dev_xfermask(struct ata_device *dev)
3348 "device is on DMA blacklist, disabling DMA\n"); 3455 "device is on DMA blacklist, disabling DMA\n");
3349 } 3456 }
3350 3457
3351 if ((host->flags & ATA_HOST_SIMPLEX) && host->simplex_claimed) { 3458 if ((host->flags & ATA_HOST_SIMPLEX) &&
3459 host->simplex_claimed && host->simplex_claimed != ap) {
3352 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); 3460 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
3353 ata_dev_printk(dev, KERN_WARNING, "simplex DMA is claimed by " 3461 ata_dev_printk(dev, KERN_WARNING, "simplex DMA is claimed by "
3354 "other device, disabling DMA\n"); 3462 "other device, disabling DMA\n");
@@ -3725,7 +3833,7 @@ static int ata_sg_setup(struct ata_queued_cmd *qc)
3725 struct scatterlist *lsg = &sg[qc->n_elem - 1]; 3833 struct scatterlist *lsg = &sg[qc->n_elem - 1];
3726 int n_elem, pre_n_elem, dir, trim_sg = 0; 3834 int n_elem, pre_n_elem, dir, trim_sg = 0;
3727 3835
3728 VPRINTK("ENTER, ata%u\n", ap->id); 3836 VPRINTK("ENTER, ata%u\n", ap->print_id);
3729 WARN_ON(!(qc->flags & ATA_QCFLAG_SG)); 3837 WARN_ON(!(qc->flags & ATA_QCFLAG_SG));
3730 3838
3731 /* we must lengthen transfers to end on a 32-bit boundary */ 3839 /* we must lengthen transfers to end on a 32-bit boundary */
@@ -4126,7 +4234,7 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc)
4126 if (do_write != i_write) 4234 if (do_write != i_write)
4127 goto err_out; 4235 goto err_out;
4128 4236
4129 VPRINTK("ata%u: xfering %d bytes\n", ap->id, bytes); 4237 VPRINTK("ata%u: xfering %d bytes\n", ap->print_id, bytes);
4130 4238
4131 __atapi_pio_bytes(qc, bytes); 4239 __atapi_pio_bytes(qc, bytes);
4132 4240
@@ -4243,7 +4351,7 @@ int ata_hsm_move(struct ata_port *ap, struct ata_queued_cmd *qc,
4243 4351
4244fsm_start: 4352fsm_start:
4245 DPRINTK("ata%u: protocol %d task_state %d (dev_stat 0x%X)\n", 4353 DPRINTK("ata%u: protocol %d task_state %d (dev_stat 0x%X)\n",
4246 ap->id, qc->tf.protocol, ap->hsm_task_state, status); 4354 ap->print_id, qc->tf.protocol, ap->hsm_task_state, status);
4247 4355
4248 switch (ap->hsm_task_state) { 4356 switch (ap->hsm_task_state) {
4249 case HSM_ST_FIRST: 4357 case HSM_ST_FIRST:
@@ -4276,8 +4384,8 @@ fsm_start:
4276 * let the EH abort the command or reset the device. 4384 * let the EH abort the command or reset the device.
4277 */ 4385 */
4278 if (unlikely(status & (ATA_ERR | ATA_DF))) { 4386 if (unlikely(status & (ATA_ERR | ATA_DF))) {
4279 printk(KERN_WARNING "ata%d: DRQ=1 with device error, dev_stat 0x%X\n", 4387 ata_port_printk(ap, KERN_WARNING, "DRQ=1 with device "
4280 ap->id, status); 4388 "error, dev_stat 0x%X\n", status);
4281 qc->err_mask |= AC_ERR_HSM; 4389 qc->err_mask |= AC_ERR_HSM;
4282 ap->hsm_task_state = HSM_ST_ERR; 4390 ap->hsm_task_state = HSM_ST_ERR;
4283 goto fsm_start; 4391 goto fsm_start;
@@ -4334,8 +4442,9 @@ fsm_start:
4334 * let the EH abort the command or reset the device. 4442 * let the EH abort the command or reset the device.
4335 */ 4443 */
4336 if (unlikely(status & (ATA_ERR | ATA_DF))) { 4444 if (unlikely(status & (ATA_ERR | ATA_DF))) {
4337 printk(KERN_WARNING "ata%d: DRQ=1 with device error, dev_stat 0x%X\n", 4445 ata_port_printk(ap, KERN_WARNING, "DRQ=1 with "
4338 ap->id, status); 4446 "device error, dev_stat 0x%X\n",
4447 status);
4339 qc->err_mask |= AC_ERR_HSM; 4448 qc->err_mask |= AC_ERR_HSM;
4340 ap->hsm_task_state = HSM_ST_ERR; 4449 ap->hsm_task_state = HSM_ST_ERR;
4341 goto fsm_start; 4450 goto fsm_start;
@@ -4421,7 +4530,7 @@ fsm_start:
4421 4530
4422 /* no more data to transfer */ 4531 /* no more data to transfer */
4423 DPRINTK("ata%u: dev %u command complete, drv_stat 0x%x\n", 4532 DPRINTK("ata%u: dev %u command complete, drv_stat 0x%x\n",
4424 ap->id, qc->dev->devno, status); 4533 ap->print_id, qc->dev->devno, status);
4425 4534
4426 WARN_ON(qc->err_mask); 4535 WARN_ON(qc->err_mask);
4427 4536
@@ -4963,7 +5072,7 @@ inline unsigned int ata_host_intr (struct ata_port *ap,
4963 u8 status, host_stat = 0; 5072 u8 status, host_stat = 0;
4964 5073
4965 VPRINTK("ata%u: protocol %d task_state %d\n", 5074 VPRINTK("ata%u: protocol %d task_state %d\n",
4966 ap->id, qc->tf.protocol, ap->hsm_task_state); 5075 ap->print_id, qc->tf.protocol, ap->hsm_task_state);
4967 5076
4968 /* Check whether we are expecting interrupt in this state */ 5077 /* Check whether we are expecting interrupt in this state */
4969 switch (ap->hsm_task_state) { 5078 switch (ap->hsm_task_state) {
@@ -4984,7 +5093,8 @@ inline unsigned int ata_host_intr (struct ata_port *ap,
4984 qc->tf.protocol == ATA_PROT_ATAPI_DMA) { 5093 qc->tf.protocol == ATA_PROT_ATAPI_DMA) {
4985 /* check status of DMA engine */ 5094 /* check status of DMA engine */
4986 host_stat = ap->ops->bmdma_status(ap); 5095 host_stat = ap->ops->bmdma_status(ap);
4987 VPRINTK("ata%u: host_stat 0x%X\n", ap->id, host_stat); 5096 VPRINTK("ata%u: host_stat 0x%X\n",
5097 ap->print_id, host_stat);
4988 5098
4989 /* if it's not our irq... */ 5099 /* if it's not our irq... */
4990 if (!(host_stat & ATA_DMA_INTR)) 5100 if (!(host_stat & ATA_DMA_INTR))
@@ -5245,6 +5355,7 @@ int ata_flush_cache(struct ata_device *dev)
5245 return 0; 5355 return 0;
5246} 5356}
5247 5357
5358#ifdef CONFIG_PM
5248static int ata_host_request_pm(struct ata_host *host, pm_message_t mesg, 5359static int ata_host_request_pm(struct ata_host *host, pm_message_t mesg,
5249 unsigned int action, unsigned int ehi_flags, 5360 unsigned int action, unsigned int ehi_flags,
5250 int wait) 5361 int wait)
@@ -5360,6 +5471,7 @@ void ata_host_resume(struct ata_host *host)
5360 ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET, 0); 5471 ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET, 0);
5361 host->dev->power.power_state = PMSG_ON; 5472 host->dev->power.power_state = PMSG_ON;
5362} 5473}
5474#endif
5363 5475
5364/** 5476/**
5365 * ata_port_start - Set port up for dma. 5477 * ata_port_start - Set port up for dma.
@@ -5443,7 +5555,7 @@ void ata_port_init(struct ata_port *ap, struct ata_host *host,
5443 5555
5444 ap->lock = &host->lock; 5556 ap->lock = &host->lock;
5445 ap->flags = ATA_FLAG_DISABLED; 5557 ap->flags = ATA_FLAG_DISABLED;
5446 ap->id = ata_unique_id++; 5558 ap->print_id = ata_print_id++;
5447 ap->ctl = ATA_DEVCTL_OBS; 5559 ap->ctl = ATA_DEVCTL_OBS;
5448 ap->host = host; 5560 ap->host = host;
5449 ap->dev = ent->dev; 5561 ap->dev = ent->dev;
@@ -5514,7 +5626,7 @@ static void ata_port_init_shost(struct ata_port *ap, struct Scsi_Host *shost)
5514{ 5626{
5515 ap->scsi_host = shost; 5627 ap->scsi_host = shost;
5516 5628
5517 shost->unique_id = ap->id; 5629 shost->unique_id = ap->print_id;
5518 shost->max_id = 16; 5630 shost->max_id = 16;
5519 shost->max_lun = 1; 5631 shost->max_lun = 1;
5520 shost->max_channel = 1; 5632 shost->max_channel = 1;
@@ -5573,17 +5685,23 @@ static void ata_host_release(struct device *gendev, void *res)
5573 for (i = 0; i < host->n_ports; i++) { 5685 for (i = 0; i < host->n_ports; i++) {
5574 struct ata_port *ap = host->ports[i]; 5686 struct ata_port *ap = host->ports[i];
5575 5687
5576 if (!ap) 5688 if (ap && ap->ops->port_stop)
5577 continue;
5578
5579 if (ap->ops->port_stop)
5580 ap->ops->port_stop(ap); 5689 ap->ops->port_stop(ap);
5581
5582 scsi_host_put(ap->scsi_host);
5583 } 5690 }
5584 5691
5585 if (host->ops->host_stop) 5692 if (host->ops->host_stop)
5586 host->ops->host_stop(host); 5693 host->ops->host_stop(host);
5694
5695 for (i = 0; i < host->n_ports; i++) {
5696 struct ata_port *ap = host->ports[i];
5697
5698 if (ap)
5699 scsi_host_put(ap->scsi_host);
5700
5701 host->ports[i] = NULL;
5702 }
5703
5704 dev_set_drvdata(gendev, NULL);
5587} 5705}
5588 5706
5589/** 5707/**
@@ -5778,9 +5896,9 @@ int ata_device_add(const struct ata_probe_ent *ent)
5778 /* wait for EH to finish */ 5896 /* wait for EH to finish */
5779 ata_port_wait_eh(ap); 5897 ata_port_wait_eh(ap);
5780 } else { 5898 } else {
5781 DPRINTK("ata%u: bus probe begin\n", ap->id); 5899 DPRINTK("ata%u: bus probe begin\n", ap->print_id);
5782 rc = ata_bus_probe(ap); 5900 rc = ata_bus_probe(ap);
5783 DPRINTK("ata%u: bus probe end\n", ap->id); 5901 DPRINTK("ata%u: bus probe end\n", ap->print_id);
5784 5902
5785 if (rc) { 5903 if (rc) {
5786 /* FIXME: do something useful here? 5904 /* FIXME: do something useful here?
@@ -5806,7 +5924,6 @@ int ata_device_add(const struct ata_probe_ent *ent)
5806 5924
5807 err_out: 5925 err_out:
5808 devres_release_group(dev, ata_device_add); 5926 devres_release_group(dev, ata_device_add);
5809 dev_set_drvdata(dev, NULL);
5810 VPRINTK("EXIT, returning %d\n", rc); 5927 VPRINTK("EXIT, returning %d\n", rc);
5811 return 0; 5928 return 0;
5812} 5929}
@@ -5891,11 +6008,7 @@ ata_probe_ent_alloc(struct device *dev, const struct ata_port_info *port)
5891{ 6008{
5892 struct ata_probe_ent *probe_ent; 6009 struct ata_probe_ent *probe_ent;
5893 6010
5894 /* XXX - the following if can go away once all LLDs are managed */ 6011 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
5895 if (!list_empty(&dev->devres_head))
5896 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
5897 else
5898 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL);
5899 if (!probe_ent) { 6012 if (!probe_ent) {
5900 printk(KERN_ERR DRV_NAME "(%s): out of memory\n", 6013 printk(KERN_ERR DRV_NAME "(%s): out of memory\n",
5901 kobject_name(&(dev->kobj))); 6014 kobject_name(&(dev->kobj)));
@@ -5998,14 +6111,14 @@ int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits)
5998 return (tmp == bits->val) ? 1 : 0; 6111 return (tmp == bits->val) ? 1 : 0;
5999} 6112}
6000 6113
6114#ifdef CONFIG_PM
6001void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg) 6115void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg)
6002{ 6116{
6003 pci_save_state(pdev); 6117 pci_save_state(pdev);
6118 pci_disable_device(pdev);
6004 6119
6005 if (mesg.event == PM_EVENT_SUSPEND) { 6120 if (mesg.event == PM_EVENT_SUSPEND)
6006 pci_disable_device(pdev);
6007 pci_set_power_state(pdev, PCI_D3hot); 6121 pci_set_power_state(pdev, PCI_D3hot);
6008 }
6009} 6122}
6010 6123
6011int ata_pci_device_do_resume(struct pci_dev *pdev) 6124int ata_pci_device_do_resume(struct pci_dev *pdev)
@@ -6050,6 +6163,8 @@ int ata_pci_device_resume(struct pci_dev *pdev)
6050 ata_host_resume(host); 6163 ata_host_resume(host);
6051 return rc; 6164 return rc;
6052} 6165}
6166#endif /* CONFIG_PM */
6167
6053#endif /* CONFIG_PCI */ 6168#endif /* CONFIG_PCI */
6054 6169
6055 6170
@@ -6227,6 +6342,7 @@ EXPORT_SYMBOL_GPL(ata_bmdma_drive_eh);
6227EXPORT_SYMBOL_GPL(ata_bmdma_error_handler); 6342EXPORT_SYMBOL_GPL(ata_bmdma_error_handler);
6228EXPORT_SYMBOL_GPL(ata_bmdma_post_internal_cmd); 6343EXPORT_SYMBOL_GPL(ata_bmdma_post_internal_cmd);
6229EXPORT_SYMBOL_GPL(ata_port_probe); 6344EXPORT_SYMBOL_GPL(ata_port_probe);
6345EXPORT_SYMBOL_GPL(ata_dev_disable);
6230EXPORT_SYMBOL_GPL(sata_set_spd); 6346EXPORT_SYMBOL_GPL(sata_set_spd);
6231EXPORT_SYMBOL_GPL(sata_phy_debounce); 6347EXPORT_SYMBOL_GPL(sata_phy_debounce);
6232EXPORT_SYMBOL_GPL(sata_phy_resume); 6348EXPORT_SYMBOL_GPL(sata_phy_resume);
@@ -6257,10 +6373,13 @@ EXPORT_SYMBOL_GPL(sata_scr_write);
6257EXPORT_SYMBOL_GPL(sata_scr_write_flush); 6373EXPORT_SYMBOL_GPL(sata_scr_write_flush);
6258EXPORT_SYMBOL_GPL(ata_port_online); 6374EXPORT_SYMBOL_GPL(ata_port_online);
6259EXPORT_SYMBOL_GPL(ata_port_offline); 6375EXPORT_SYMBOL_GPL(ata_port_offline);
6376#ifdef CONFIG_PM
6260EXPORT_SYMBOL_GPL(ata_host_suspend); 6377EXPORT_SYMBOL_GPL(ata_host_suspend);
6261EXPORT_SYMBOL_GPL(ata_host_resume); 6378EXPORT_SYMBOL_GPL(ata_host_resume);
6379#endif /* CONFIG_PM */
6262EXPORT_SYMBOL_GPL(ata_id_string); 6380EXPORT_SYMBOL_GPL(ata_id_string);
6263EXPORT_SYMBOL_GPL(ata_id_c_string); 6381EXPORT_SYMBOL_GPL(ata_id_c_string);
6382EXPORT_SYMBOL_GPL(ata_id_to_dma_mode);
6264EXPORT_SYMBOL_GPL(ata_device_blacklisted); 6383EXPORT_SYMBOL_GPL(ata_device_blacklisted);
6265EXPORT_SYMBOL_GPL(ata_scsi_simulate); 6384EXPORT_SYMBOL_GPL(ata_scsi_simulate);
6266 6385
@@ -6273,16 +6392,20 @@ EXPORT_SYMBOL_GPL(pci_test_config_bits);
6273EXPORT_SYMBOL_GPL(ata_pci_init_native_mode); 6392EXPORT_SYMBOL_GPL(ata_pci_init_native_mode);
6274EXPORT_SYMBOL_GPL(ata_pci_init_one); 6393EXPORT_SYMBOL_GPL(ata_pci_init_one);
6275EXPORT_SYMBOL_GPL(ata_pci_remove_one); 6394EXPORT_SYMBOL_GPL(ata_pci_remove_one);
6395#ifdef CONFIG_PM
6276EXPORT_SYMBOL_GPL(ata_pci_device_do_suspend); 6396EXPORT_SYMBOL_GPL(ata_pci_device_do_suspend);
6277EXPORT_SYMBOL_GPL(ata_pci_device_do_resume); 6397EXPORT_SYMBOL_GPL(ata_pci_device_do_resume);
6278EXPORT_SYMBOL_GPL(ata_pci_device_suspend); 6398EXPORT_SYMBOL_GPL(ata_pci_device_suspend);
6279EXPORT_SYMBOL_GPL(ata_pci_device_resume); 6399EXPORT_SYMBOL_GPL(ata_pci_device_resume);
6400#endif /* CONFIG_PM */
6280EXPORT_SYMBOL_GPL(ata_pci_default_filter); 6401EXPORT_SYMBOL_GPL(ata_pci_default_filter);
6281EXPORT_SYMBOL_GPL(ata_pci_clear_simplex); 6402EXPORT_SYMBOL_GPL(ata_pci_clear_simplex);
6282#endif /* CONFIG_PCI */ 6403#endif /* CONFIG_PCI */
6283 6404
6405#ifdef CONFIG_PM
6284EXPORT_SYMBOL_GPL(ata_scsi_device_suspend); 6406EXPORT_SYMBOL_GPL(ata_scsi_device_suspend);
6285EXPORT_SYMBOL_GPL(ata_scsi_device_resume); 6407EXPORT_SYMBOL_GPL(ata_scsi_device_resume);
6408#endif /* CONFIG_PM */
6286 6409
6287EXPORT_SYMBOL_GPL(ata_eng_timeout); 6410EXPORT_SYMBOL_GPL(ata_eng_timeout);
6288EXPORT_SYMBOL_GPL(ata_port_schedule_eh); 6411EXPORT_SYMBOL_GPL(ata_port_schedule_eh);
@@ -6297,3 +6420,4 @@ EXPORT_SYMBOL_GPL(ata_irq_on);
6297EXPORT_SYMBOL_GPL(ata_dummy_irq_on); 6420EXPORT_SYMBOL_GPL(ata_dummy_irq_on);
6298EXPORT_SYMBOL_GPL(ata_irq_ack); 6421EXPORT_SYMBOL_GPL(ata_irq_ack);
6299EXPORT_SYMBOL_GPL(ata_dummy_irq_ack); 6422EXPORT_SYMBOL_GPL(ata_dummy_irq_ack);
6423EXPORT_SYMBOL_GPL(ata_dev_try_classify);
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 52c85af7fe..7349c3dbf7 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -44,10 +44,41 @@
44 44
45#include "libata.h" 45#include "libata.h"
46 46
47enum {
48 ATA_EH_SPDN_NCQ_OFF = (1 << 0),
49 ATA_EH_SPDN_SPEED_DOWN = (1 << 1),
50 ATA_EH_SPDN_FALLBACK_TO_PIO = (1 << 2),
51};
52
47static void __ata_port_freeze(struct ata_port *ap); 53static void __ata_port_freeze(struct ata_port *ap);
48static void ata_eh_finish(struct ata_port *ap); 54static void ata_eh_finish(struct ata_port *ap);
55#ifdef CONFIG_PM
49static void ata_eh_handle_port_suspend(struct ata_port *ap); 56static void ata_eh_handle_port_suspend(struct ata_port *ap);
50static void ata_eh_handle_port_resume(struct ata_port *ap); 57static void ata_eh_handle_port_resume(struct ata_port *ap);
58static int ata_eh_suspend(struct ata_port *ap,
59 struct ata_device **r_failed_dev);
60static void ata_eh_prep_resume(struct ata_port *ap);
61static int ata_eh_resume(struct ata_port *ap, struct ata_device **r_failed_dev);
62#else /* CONFIG_PM */
63static void ata_eh_handle_port_suspend(struct ata_port *ap)
64{ }
65
66static void ata_eh_handle_port_resume(struct ata_port *ap)
67{ }
68
69static int ata_eh_suspend(struct ata_port *ap, struct ata_device **r_failed_dev)
70{
71 return 0;
72}
73
74static void ata_eh_prep_resume(struct ata_port *ap)
75{ }
76
77static int ata_eh_resume(struct ata_port *ap, struct ata_device **r_failed_dev)
78{
79 return 0;
80}
81#endif /* CONFIG_PM */
51 82
52static void ata_ering_record(struct ata_ering *ering, int is_io, 83static void ata_ering_record(struct ata_ering *ering, int is_io,
53 unsigned int err_mask) 84 unsigned int err_mask)
@@ -65,12 +96,9 @@ static void ata_ering_record(struct ata_ering *ering, int is_io,
65 ent->timestamp = get_jiffies_64(); 96 ent->timestamp = get_jiffies_64();
66} 97}
67 98
68static struct ata_ering_entry * ata_ering_top(struct ata_ering *ering) 99static void ata_ering_clear(struct ata_ering *ering)
69{ 100{
70 struct ata_ering_entry *ent = &ering->ring[ering->cursor]; 101 memset(ering, 0, sizeof(*ering));
71 if (!ent->err_mask)
72 return NULL;
73 return ent;
74} 102}
75 103
76static int ata_ering_map(struct ata_ering *ering, 104static int ata_ering_map(struct ata_ering *ering,
@@ -585,7 +613,7 @@ static void __ata_port_freeze(struct ata_port *ap)
585 613
586 ap->pflags |= ATA_PFLAG_FROZEN; 614 ap->pflags |= ATA_PFLAG_FROZEN;
587 615
588 DPRINTK("ata%u port frozen\n", ap->id); 616 DPRINTK("ata%u port frozen\n", ap->print_id);
589} 617}
590 618
591/** 619/**
@@ -658,7 +686,7 @@ void ata_eh_thaw_port(struct ata_port *ap)
658 686
659 spin_unlock_irqrestore(ap->lock, flags); 687 spin_unlock_irqrestore(ap->lock, flags);
660 688
661 DPRINTK("ata%u port thawed\n", ap->id); 689 DPRINTK("ata%u port thawed\n", ap->print_id);
662} 690}
663 691
664static void ata_eh_scsidone(struct scsi_cmnd *scmd) 692static void ata_eh_scsidone(struct scsi_cmnd *scmd)
@@ -1159,87 +1187,99 @@ static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc,
1159 return action; 1187 return action;
1160} 1188}
1161 1189
1162static int ata_eh_categorize_ering_entry(struct ata_ering_entry *ent) 1190static int ata_eh_categorize_error(int is_io, unsigned int err_mask)
1163{ 1191{
1164 if (ent->err_mask & (AC_ERR_ATA_BUS | AC_ERR_TIMEOUT)) 1192 if (err_mask & AC_ERR_ATA_BUS)
1165 return 1; 1193 return 1;
1166 1194
1167 if (ent->is_io) { 1195 if (err_mask & AC_ERR_TIMEOUT)
1168 if (ent->err_mask & AC_ERR_HSM) 1196 return 2;
1169 return 1; 1197
1170 if ((ent->err_mask & 1198 if (is_io) {
1171 (AC_ERR_DEV|AC_ERR_MEDIA|AC_ERR_INVALID)) == AC_ERR_DEV) 1199 if (err_mask & AC_ERR_HSM)
1172 return 2; 1200 return 2;
1201 if ((err_mask &
1202 (AC_ERR_DEV|AC_ERR_MEDIA|AC_ERR_INVALID)) == AC_ERR_DEV)
1203 return 3;
1173 } 1204 }
1174 1205
1175 return 0; 1206 return 0;
1176} 1207}
1177 1208
1178struct speed_down_needed_arg { 1209struct speed_down_verdict_arg {
1179 u64 since; 1210 u64 since;
1180 int nr_errors[3]; 1211 int nr_errors[4];
1181}; 1212};
1182 1213
1183static int speed_down_needed_cb(struct ata_ering_entry *ent, void *void_arg) 1214static int speed_down_verdict_cb(struct ata_ering_entry *ent, void *void_arg)
1184{ 1215{
1185 struct speed_down_needed_arg *arg = void_arg; 1216 struct speed_down_verdict_arg *arg = void_arg;
1217 int cat = ata_eh_categorize_error(ent->is_io, ent->err_mask);
1186 1218
1187 if (ent->timestamp < arg->since) 1219 if (ent->timestamp < arg->since)
1188 return -1; 1220 return -1;
1189 1221
1190 arg->nr_errors[ata_eh_categorize_ering_entry(ent)]++; 1222 arg->nr_errors[cat]++;
1191 return 0; 1223 return 0;
1192} 1224}
1193 1225
1194/** 1226/**
1195 * ata_eh_speed_down_needed - Determine wheter speed down is necessary 1227 * ata_eh_speed_down_verdict - Determine speed down verdict
1196 * @dev: Device of interest 1228 * @dev: Device of interest
1197 * 1229 *
1198 * This function examines error ring of @dev and determines 1230 * This function examines error ring of @dev and determines
1199 * whether speed down is necessary. Speed down is necessary if 1231 * whether NCQ needs to be turned off, transfer speed should be
1200 * there have been more than 3 of Cat-1 errors or 10 of Cat-2 1232 * stepped down, or falling back to PIO is necessary.
1201 * errors during last 15 minutes.
1202 * 1233 *
1203 * Cat-1 errors are ATA_BUS, TIMEOUT for any command and HSM 1234 * Cat-1 is ATA_BUS error for any command.
1204 * violation for known supported commands.
1205 * 1235 *
1206 * Cat-2 errors are unclassified DEV error for known supported 1236 * Cat-2 is TIMEOUT for any command or HSM violation for known
1237 * supported commands.
1238 *
1239 * Cat-3 is is unclassified DEV error for known supported
1207 * command. 1240 * command.
1208 * 1241 *
1242 * NCQ needs to be turned off if there have been more than 3
1243 * Cat-2 + Cat-3 errors during last 10 minutes.
1244 *
1245 * Speed down is necessary if there have been more than 3 Cat-1 +
1246 * Cat-2 errors or 10 Cat-3 errors during last 10 minutes.
1247 *
1248 * Falling back to PIO mode is necessary if there have been more
1249 * than 10 Cat-1 + Cat-2 + Cat-3 errors during last 5 minutes.
1250 *
1209 * LOCKING: 1251 * LOCKING:
1210 * Inherited from caller. 1252 * Inherited from caller.
1211 * 1253 *
1212 * RETURNS: 1254 * RETURNS:
1213 * 1 if speed down is necessary, 0 otherwise 1255 * OR of ATA_EH_SPDN_* flags.
1214 */ 1256 */
1215static int ata_eh_speed_down_needed(struct ata_device *dev) 1257static unsigned int ata_eh_speed_down_verdict(struct ata_device *dev)
1216{ 1258{
1217 const u64 interval = 15LLU * 60 * HZ; 1259 const u64 j5mins = 5LLU * 60 * HZ, j10mins = 10LLU * 60 * HZ;
1218 static const int err_limits[3] = { -1, 3, 10 }; 1260 u64 j64 = get_jiffies_64();
1219 struct speed_down_needed_arg arg; 1261 struct speed_down_verdict_arg arg;
1220 struct ata_ering_entry *ent; 1262 unsigned int verdict = 0;
1221 int err_cat;
1222 u64 j64;
1223 1263
1224 ent = ata_ering_top(&dev->ering); 1264 /* scan past 10 mins of error history */
1225 if (!ent) 1265 memset(&arg, 0, sizeof(arg));
1226 return 0; 1266 arg.since = j64 - min(j64, j10mins);
1267 ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg);
1227 1268
1228 err_cat = ata_eh_categorize_ering_entry(ent); 1269 if (arg.nr_errors[2] + arg.nr_errors[3] > 3)
1229 if (err_cat == 0) 1270 verdict |= ATA_EH_SPDN_NCQ_OFF;
1230 return 0; 1271 if (arg.nr_errors[1] + arg.nr_errors[2] > 3 || arg.nr_errors[3] > 10)
1272 verdict |= ATA_EH_SPDN_SPEED_DOWN;
1231 1273
1274 /* scan past 3 mins of error history */
1232 memset(&arg, 0, sizeof(arg)); 1275 memset(&arg, 0, sizeof(arg));
1276 arg.since = j64 - min(j64, j5mins);
1277 ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg);
1233 1278
1234 j64 = get_jiffies_64(); 1279 if (arg.nr_errors[1] + arg.nr_errors[2] + arg.nr_errors[3] > 10)
1235 if (j64 >= interval) 1280 verdict |= ATA_EH_SPDN_FALLBACK_TO_PIO;
1236 arg.since = j64 - interval;
1237 else
1238 arg.since = 0;
1239
1240 ata_ering_map(&dev->ering, speed_down_needed_cb, &arg);
1241 1281
1242 return arg.nr_errors[err_cat] > err_limits[err_cat]; 1282 return verdict;
1243} 1283}
1244 1284
1245/** 1285/**
@@ -1257,31 +1297,80 @@ static int ata_eh_speed_down_needed(struct ata_device *dev)
1257 * Kernel thread context (may sleep). 1297 * Kernel thread context (may sleep).
1258 * 1298 *
1259 * RETURNS: 1299 * RETURNS:
1260 * 0 on success, -errno otherwise 1300 * Determined recovery action.
1261 */ 1301 */
1262static int ata_eh_speed_down(struct ata_device *dev, int is_io, 1302static unsigned int ata_eh_speed_down(struct ata_device *dev, int is_io,
1263 unsigned int err_mask) 1303 unsigned int err_mask)
1264{ 1304{
1265 if (!err_mask) 1305 unsigned int verdict;
1306 unsigned int action = 0;
1307
1308 /* don't bother if Cat-0 error */
1309 if (ata_eh_categorize_error(is_io, err_mask) == 0)
1266 return 0; 1310 return 0;
1267 1311
1268 /* record error and determine whether speed down is necessary */ 1312 /* record error and determine whether speed down is necessary */
1269 ata_ering_record(&dev->ering, is_io, err_mask); 1313 ata_ering_record(&dev->ering, is_io, err_mask);
1314 verdict = ata_eh_speed_down_verdict(dev);
1270 1315
1271 if (!ata_eh_speed_down_needed(dev)) 1316 /* turn off NCQ? */
1272 return 0; 1317 if ((verdict & ATA_EH_SPDN_NCQ_OFF) &&
1318 (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ |
1319 ATA_DFLAG_NCQ_OFF)) == ATA_DFLAG_NCQ) {
1320 dev->flags |= ATA_DFLAG_NCQ_OFF;
1321 ata_dev_printk(dev, KERN_WARNING,
1322 "NCQ disabled due to excessive errors\n");
1323 goto done;
1324 }
1273 1325
1274 /* speed down SATA link speed if possible */ 1326 /* speed down? */
1275 if (sata_down_spd_limit(dev->ap) == 0) 1327 if (verdict & ATA_EH_SPDN_SPEED_DOWN) {
1276 return ATA_EH_HARDRESET; 1328 /* speed down SATA link speed if possible */
1329 if (sata_down_spd_limit(dev->ap) == 0) {
1330 action |= ATA_EH_HARDRESET;
1331 goto done;
1332 }
1277 1333
1278 /* lower transfer mode */ 1334 /* lower transfer mode */
1279 if (ata_down_xfermask_limit(dev, 0) == 0) 1335 if (dev->spdn_cnt < 2) {
1280 return ATA_EH_SOFTRESET; 1336 static const int dma_dnxfer_sel[] =
1337 { ATA_DNXFER_DMA, ATA_DNXFER_40C };
1338 static const int pio_dnxfer_sel[] =
1339 { ATA_DNXFER_PIO, ATA_DNXFER_FORCE_PIO0 };
1340 int sel;
1341
1342 if (dev->xfer_shift != ATA_SHIFT_PIO)
1343 sel = dma_dnxfer_sel[dev->spdn_cnt];
1344 else
1345 sel = pio_dnxfer_sel[dev->spdn_cnt];
1346
1347 dev->spdn_cnt++;
1348
1349 if (ata_down_xfermask_limit(dev, sel) == 0) {
1350 action |= ATA_EH_SOFTRESET;
1351 goto done;
1352 }
1353 }
1354 }
1355
1356 /* Fall back to PIO? Slowing down to PIO is meaningless for
1357 * SATA. Consider it only for PATA.
1358 */
1359 if ((verdict & ATA_EH_SPDN_FALLBACK_TO_PIO) && (dev->spdn_cnt >= 2) &&
1360 (dev->ap->cbl != ATA_CBL_SATA) &&
1361 (dev->xfer_shift != ATA_SHIFT_PIO)) {
1362 if (ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO) == 0) {
1363 dev->spdn_cnt = 0;
1364 action |= ATA_EH_SOFTRESET;
1365 goto done;
1366 }
1367 }
1281 1368
1282 ata_dev_printk(dev, KERN_ERR,
1283 "speed down requested but no transfer mode left\n");
1284 return 0; 1369 return 0;
1370 done:
1371 /* device has been slowed down, blow error history */
1372 ata_ering_clear(&dev->ering);
1373 return action;
1285} 1374}
1286 1375
1287/** 1376/**
@@ -1726,6 +1815,7 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
1726 return rc; 1815 return rc;
1727} 1816}
1728 1817
1818#ifdef CONFIG_PM
1729/** 1819/**
1730 * ata_eh_suspend - handle suspend EH action 1820 * ata_eh_suspend - handle suspend EH action
1731 * @ap: target host port 1821 * @ap: target host port
@@ -1883,6 +1973,7 @@ static int ata_eh_resume(struct ata_port *ap, struct ata_device **r_failed_dev)
1883 DPRINTK("EXIT\n"); 1973 DPRINTK("EXIT\n");
1884 return 0; 1974 return 0;
1885} 1975}
1976#endif /* CONFIG_PM */
1886 1977
1887static int ata_port_nr_enabled(struct ata_port *ap) 1978static int ata_port_nr_enabled(struct ata_port *ap)
1888{ 1979{
@@ -1964,7 +2055,7 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
1964{ 2055{
1965 struct ata_eh_context *ehc = &ap->eh_context; 2056 struct ata_eh_context *ehc = &ap->eh_context;
1966 struct ata_device *dev; 2057 struct ata_device *dev;
1967 int down_xfermask, i, rc; 2058 int i, rc;
1968 2059
1969 DPRINTK("ENTER\n"); 2060 DPRINTK("ENTER\n");
1970 2061
@@ -1993,7 +2084,6 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
1993 } 2084 }
1994 2085
1995 retry: 2086 retry:
1996 down_xfermask = 0;
1997 rc = 0; 2087 rc = 0;
1998 2088
1999 /* if UNLOADING, finish immediately */ 2089 /* if UNLOADING, finish immediately */
@@ -2038,10 +2128,8 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
2038 /* configure transfer mode if necessary */ 2128 /* configure transfer mode if necessary */
2039 if (ehc->i.flags & ATA_EHI_SETMODE) { 2129 if (ehc->i.flags & ATA_EHI_SETMODE) {
2040 rc = ata_set_mode(ap, &dev); 2130 rc = ata_set_mode(ap, &dev);
2041 if (rc) { 2131 if (rc)
2042 down_xfermask = 1;
2043 goto dev_fail; 2132 goto dev_fail;
2044 }
2045 ehc->i.flags &= ~ATA_EHI_SETMODE; 2133 ehc->i.flags &= ~ATA_EHI_SETMODE;
2046 } 2134 }
2047 2135
@@ -2053,20 +2141,27 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
2053 goto out; 2141 goto out;
2054 2142
2055 dev_fail: 2143 dev_fail:
2144 ehc->tries[dev->devno]--;
2145
2056 switch (rc) { 2146 switch (rc) {
2057 case -ENODEV:
2058 /* device missing, schedule probing */
2059 ehc->i.probe_mask |= (1 << dev->devno);
2060 case -EINVAL: 2147 case -EINVAL:
2148 /* eeek, something went very wrong, give up */
2061 ehc->tries[dev->devno] = 0; 2149 ehc->tries[dev->devno] = 0;
2062 break; 2150 break;
2151
2152 case -ENODEV:
2153 /* device missing or wrong IDENTIFY data, schedule probing */
2154 ehc->i.probe_mask |= (1 << dev->devno);
2155 /* give it just one more chance */
2156 ehc->tries[dev->devno] = min(ehc->tries[dev->devno], 1);
2063 case -EIO: 2157 case -EIO:
2064 sata_down_spd_limit(ap); 2158 if (ehc->tries[dev->devno] == 1) {
2065 default: 2159 /* This is the last chance, better to slow
2066 ehc->tries[dev->devno]--; 2160 * down than lose it.
2067 if (down_xfermask && 2161 */
2068 ata_down_xfermask_limit(dev, ehc->tries[dev->devno] == 1)) 2162 sata_down_spd_limit(ap);
2069 ehc->tries[dev->devno] = 0; 2163 ata_down_xfermask_limit(dev, ATA_DNXFER_PIO);
2164 }
2070 } 2165 }
2071 2166
2072 if (ata_dev_enabled(dev) && !ehc->tries[dev->devno]) { 2167 if (ata_dev_enabled(dev) && !ehc->tries[dev->devno]) {
@@ -2181,6 +2276,7 @@ void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
2181 ata_eh_finish(ap); 2276 ata_eh_finish(ap);
2182} 2277}
2183 2278
2279#ifdef CONFIG_PM
2184/** 2280/**
2185 * ata_eh_handle_port_suspend - perform port suspend operation 2281 * ata_eh_handle_port_suspend - perform port suspend operation
2186 * @ap: port to suspend 2282 * @ap: port to suspend
@@ -2296,3 +2392,4 @@ static void ata_eh_handle_port_resume(struct ata_port *ap)
2296 } 2392 }
2297 spin_unlock_irqrestore(ap->lock, flags); 2393 spin_unlock_irqrestore(ap->lock, flags);
2298} 2394}
2395#endif /* CONFIG_PM */
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 0009818a43..6cc817a102 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -333,6 +333,7 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
333 scsi_cmd[8] = args[3]; 333 scsi_cmd[8] = args[3];
334 scsi_cmd[10] = args[4]; 334 scsi_cmd[10] = args[4];
335 scsi_cmd[12] = args[5]; 335 scsi_cmd[12] = args[5];
336 scsi_cmd[13] = args[6] & 0x0f;
336 scsi_cmd[14] = args[0]; 337 scsi_cmd[14] = args[0];
337 338
338 /* Good values for timeout and retries? Values below 339 /* Good values for timeout and retries? Values below
@@ -509,6 +510,7 @@ static void ata_dump_status(unsigned id, struct ata_taskfile *tf)
509 } 510 }
510} 511}
511 512
513#ifdef CONFIG_PM
512/** 514/**
513 * ata_scsi_device_suspend - suspend ATA device associated with sdev 515 * ata_scsi_device_suspend - suspend ATA device associated with sdev
514 * @sdev: the SCSI device to suspend 516 * @sdev: the SCSI device to suspend
@@ -633,6 +635,7 @@ int ata_scsi_device_resume(struct scsi_device *sdev)
633 sdev->sdev_gendev.power.power_state = PMSG_ON; 635 sdev->sdev_gendev.power.power_state = PMSG_ON;
634 return 0; 636 return 0;
635} 637}
638#endif /* CONFIG_PM */
636 639
637/** 640/**
638 * ata_to_sense_error - convert ATA error to SCSI error 641 * ata_to_sense_error - convert ATA error to SCSI error
@@ -781,7 +784,7 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
781 */ 784 */
782 if (qc->err_mask || 785 if (qc->err_mask ||
783 tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { 786 tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) {
784 ata_to_sense_error(qc->ap->id, tf->command, tf->feature, 787 ata_to_sense_error(qc->ap->print_id, tf->command, tf->feature,
785 &sb[1], &sb[2], &sb[3], verbose); 788 &sb[1], &sb[2], &sb[3], verbose);
786 sb[1] &= 0x0f; 789 sb[1] &= 0x0f;
787 } 790 }
@@ -854,7 +857,7 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc)
854 */ 857 */
855 if (qc->err_mask || 858 if (qc->err_mask ||
856 tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { 859 tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) {
857 ata_to_sense_error(qc->ap->id, tf->command, tf->feature, 860 ata_to_sense_error(qc->ap->print_id, tf->command, tf->feature,
858 &sb[1], &sb[2], &sb[3], verbose); 861 &sb[1], &sb[2], &sb[3], verbose);
859 sb[1] &= 0x0f; 862 sb[1] &= 0x0f;
860 } 863 }
@@ -986,29 +989,32 @@ int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth)
986 struct ata_port *ap = ata_shost_to_port(sdev->host); 989 struct ata_port *ap = ata_shost_to_port(sdev->host);
987 struct ata_device *dev; 990 struct ata_device *dev;
988 unsigned long flags; 991 unsigned long flags;
989 int max_depth;
990 992
991 if (queue_depth < 1) 993 if (queue_depth < 1 || queue_depth == sdev->queue_depth)
992 return sdev->queue_depth; 994 return sdev->queue_depth;
993 995
994 dev = ata_scsi_find_dev(ap, sdev); 996 dev = ata_scsi_find_dev(ap, sdev);
995 if (!dev || !ata_dev_enabled(dev)) 997 if (!dev || !ata_dev_enabled(dev))
996 return sdev->queue_depth; 998 return sdev->queue_depth;
997 999
998 max_depth = min(sdev->host->can_queue, ata_id_queue_depth(dev->id)); 1000 /* NCQ enabled? */
999 max_depth = min(ATA_MAX_QUEUE - 1, max_depth);
1000 if (queue_depth > max_depth)
1001 queue_depth = max_depth;
1002
1003 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, queue_depth);
1004
1005 spin_lock_irqsave(ap->lock, flags); 1001 spin_lock_irqsave(ap->lock, flags);
1006 if (queue_depth > 1) 1002 dev->flags &= ~ATA_DFLAG_NCQ_OFF;
1007 dev->flags &= ~ATA_DFLAG_NCQ_OFF; 1003 if (queue_depth == 1 || !ata_ncq_enabled(dev)) {
1008 else
1009 dev->flags |= ATA_DFLAG_NCQ_OFF; 1004 dev->flags |= ATA_DFLAG_NCQ_OFF;
1005 queue_depth = 1;
1006 }
1010 spin_unlock_irqrestore(ap->lock, flags); 1007 spin_unlock_irqrestore(ap->lock, flags);
1011 1008
1009 /* limit and apply queue depth */
1010 queue_depth = min(queue_depth, sdev->host->can_queue);
1011 queue_depth = min(queue_depth, ata_id_queue_depth(dev->id));
1012 queue_depth = min(queue_depth, ATA_MAX_QUEUE - 1);
1013
1014 if (sdev->queue_depth == queue_depth)
1015 return -EINVAL;
1016
1017 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, queue_depth);
1012 return queue_depth; 1018 return queue_depth;
1013} 1019}
1014 1020
@@ -1469,7 +1475,7 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
1469 } 1475 }
1470 1476
1471 if (need_sense && !ap->ops->error_handler) 1477 if (need_sense && !ap->ops->error_handler)
1472 ata_dump_status(ap->id, &qc->result_tf); 1478 ata_dump_status(ap->print_id, &qc->result_tf);
1473 1479
1474 qc->scsidone(cmd); 1480 qc->scsidone(cmd);
1475 1481
@@ -1495,11 +1501,9 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
1495static int ata_scmd_need_defer(struct ata_device *dev, int is_io) 1501static int ata_scmd_need_defer(struct ata_device *dev, int is_io)
1496{ 1502{
1497 struct ata_port *ap = dev->ap; 1503 struct ata_port *ap = dev->ap;
1504 int is_ncq = is_io && ata_ncq_enabled(dev);
1498 1505
1499 if (!(dev->flags & ATA_DFLAG_NCQ)) 1506 if (is_ncq) {
1500 return 0;
1501
1502 if (is_io) {
1503 if (!ata_tag_valid(ap->active_tag)) 1507 if (!ata_tag_valid(ap->active_tag))
1504 return 0; 1508 return 0;
1505 } else { 1509 } else {
@@ -2774,7 +2778,7 @@ static inline void ata_scsi_dump_cdb(struct ata_port *ap,
2774 u8 *scsicmd = cmd->cmnd; 2778 u8 *scsicmd = cmd->cmnd;
2775 2779
2776 DPRINTK("CDB (%u:%d,%d,%d) %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", 2780 DPRINTK("CDB (%u:%d,%d,%d) %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
2777 ap->id, 2781 ap->print_id,
2778 scsidev->channel, scsidev->id, scsidev->lun, 2782 scsidev->channel, scsidev->id, scsidev->lun,
2779 scsicmd[0], scsicmd[1], scsicmd[2], scsicmd[3], 2783 scsicmd[0], scsicmd[1], scsicmd[2], scsicmd[3],
2780 scsicmd[4], scsicmd[5], scsicmd[6], scsicmd[7], 2784 scsicmd[4], scsicmd[5], scsicmd[6], scsicmd[7],
@@ -3234,7 +3238,7 @@ struct ata_port *ata_sas_port_alloc(struct ata_host *host,
3234 3238
3235 ata_port_init(ap, host, ent, 0); 3239 ata_port_init(ap, host, ent, 0);
3236 ap->lock = shost->host_lock; 3240 ap->lock = shost->host_lock;
3237 kfree(ent); 3241 devm_kfree(host->dev, ent);
3238 return ap; 3242 return ap;
3239} 3243}
3240EXPORT_SYMBOL_GPL(ata_sas_port_alloc); 3244EXPORT_SYMBOL_GPL(ata_sas_port_alloc);
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index 16bc3e35bd..2ffcca063d 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -175,7 +175,7 @@ void ata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
175 */ 175 */
176void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf) 176void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf)
177{ 177{
178 DPRINTK("ata%u: cmd 0x%X\n", ap->id, tf->command); 178 DPRINTK("ata%u: cmd 0x%X\n", ap->print_id, tf->command);
179 179
180 iowrite8(tf->command, ap->ioaddr.command_addr); 180 iowrite8(tf->command, ap->ioaddr.command_addr);
181 ata_pause(ap); 181 ata_pause(ap);
@@ -521,7 +521,7 @@ void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc)
521static int ata_resources_present(struct pci_dev *pdev, int port) 521static int ata_resources_present(struct pci_dev *pdev, int port)
522{ 522{
523 int i; 523 int i;
524 524
525 /* Check the PCI resources for this channel are enabled */ 525 /* Check the PCI resources for this channel are enabled */
526 port = port * 2; 526 port = port * 2;
527 for (i = 0; i < 2; i ++) { 527 for (i = 0; i < 2; i ++) {
@@ -531,7 +531,7 @@ static int ata_resources_present(struct pci_dev *pdev, int port)
531 } 531 }
532 return 1; 532 return 1;
533} 533}
534 534
535/** 535/**
536 * ata_pci_init_native_mode - Initialize native-mode driver 536 * ata_pci_init_native_mode - Initialize native-mode driver
537 * @pdev: pci device to be initialized 537 * @pdev: pci device to be initialized
@@ -576,7 +576,7 @@ ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int
576 576
577 probe_ent->irq = pdev->irq; 577 probe_ent->irq = pdev->irq;
578 probe_ent->irq_flags = IRQF_SHARED; 578 probe_ent->irq_flags = IRQF_SHARED;
579 579
580 /* Discard disabled ports. Some controllers show their 580 /* Discard disabled ports. Some controllers show their
581 unused channels this way */ 581 unused channels this way */
582 if (ata_resources_present(pdev, 0) == 0) 582 if (ata_resources_present(pdev, 0) == 0)
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 06ccf230e3..c42671493e 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -41,12 +41,22 @@ struct ata_scsi_args {
41enum { 41enum {
42 /* flags for ata_dev_read_id() */ 42 /* flags for ata_dev_read_id() */
43 ATA_READID_POSTRESET = (1 << 0), /* reading ID after reset */ 43 ATA_READID_POSTRESET = (1 << 0), /* reading ID after reset */
44
45 /* selector for ata_down_xfermask_limit() */
46 ATA_DNXFER_PIO = 0, /* speed down PIO */
47 ATA_DNXFER_DMA = 1, /* speed down DMA */
48 ATA_DNXFER_40C = 2, /* apply 40c cable limit */
49 ATA_DNXFER_FORCE_PIO = 3, /* force PIO */
50 ATA_DNXFER_FORCE_PIO0 = 4, /* force PIO0 */
51
52 ATA_DNXFER_QUIET = (1 << 31),
44}; 53};
45 54
46extern struct workqueue_struct *ata_aux_wq; 55extern struct workqueue_struct *ata_aux_wq;
47extern int atapi_enabled; 56extern int atapi_enabled;
48extern int atapi_dmadir; 57extern int atapi_dmadir;
49extern int libata_fua; 58extern int libata_fua;
59extern int noacpi;
50extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev); 60extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev);
51extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, 61extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
52 u64 block, u32 n_block, unsigned int tf_flags, 62 u64 block, u32 n_block, unsigned int tf_flags,
@@ -68,7 +78,7 @@ extern int ata_dev_revalidate(struct ata_device *dev, unsigned int flags);
68extern int ata_dev_configure(struct ata_device *dev); 78extern int ata_dev_configure(struct ata_device *dev);
69extern int sata_down_spd_limit(struct ata_port *ap); 79extern int sata_down_spd_limit(struct ata_port *ap);
70extern int sata_set_spd_needed(struct ata_port *ap); 80extern int sata_set_spd_needed(struct ata_port *ap);
71extern int ata_down_xfermask_limit(struct ata_device *dev, int force_pio0); 81extern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel);
72extern int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev); 82extern int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev);
73extern void ata_sg_clean(struct ata_queued_cmd *qc); 83extern void ata_sg_clean(struct ata_queued_cmd *qc);
74extern void ata_qc_free(struct ata_queued_cmd *qc); 84extern void ata_qc_free(struct ata_queued_cmd *qc);
@@ -87,6 +97,20 @@ extern void ata_port_init(struct ata_port *ap, struct ata_host *host,
87extern struct ata_probe_ent *ata_probe_ent_alloc(struct device *dev, 97extern struct ata_probe_ent *ata_probe_ent_alloc(struct device *dev,
88 const struct ata_port_info *port); 98 const struct ata_port_info *port);
89 99
100/* libata-acpi.c */
101#ifdef CONFIG_SATA_ACPI
102extern int ata_acpi_exec_tfs(struct ata_port *ap);
103extern int ata_acpi_push_id(struct ata_port *ap, unsigned int ix);
104#else
105static inline int ata_acpi_exec_tfs(struct ata_port *ap)
106{
107 return 0;
108}
109static inline int ata_acpi_push_id(struct ata_port *ap, unsigned int ix)
110{
111 return 0;
112}
113#endif
90 114
91/* libata-scsi.c */ 115/* libata-scsi.c */
92extern struct scsi_transport_template ata_scsi_transport_template; 116extern struct scsi_transport_template ata_scsi_transport_template;
@@ -135,7 +159,5 @@ extern void ata_qc_schedule_eh(struct ata_queued_cmd *qc);
135/* libata-sff.c */ 159/* libata-sff.c */
136extern u8 ata_irq_on(struct ata_port *ap); 160extern u8 ata_irq_on(struct ata_port *ap);
137 161
138/* pata_sis.c */
139extern struct ata_port_info sis_info133;
140 162
141#endif /* __LIBATA_H__ */ 163#endif /* __LIBATA_H__ */
diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
index ab44d18850..11ea552a58 100644
--- a/drivers/ata/pata_ali.c
+++ b/drivers/ata/pata_ali.c
@@ -34,7 +34,7 @@
34#include <linux/dmi.h> 34#include <linux/dmi.h>
35 35
36#define DRV_NAME "pata_ali" 36#define DRV_NAME "pata_ali"
37#define DRV_VERSION "0.7.2" 37#define DRV_VERSION "0.7.3"
38 38
39/* 39/*
40 * Cable special cases 40 * Cable special cases
@@ -345,8 +345,10 @@ static struct scsi_host_template ali_sht = {
345 .slave_configure = ata_scsi_slave_config, 345 .slave_configure = ata_scsi_slave_config,
346 .slave_destroy = ata_scsi_slave_destroy, 346 .slave_destroy = ata_scsi_slave_destroy,
347 .bios_param = ata_std_bios_param, 347 .bios_param = ata_std_bios_param,
348#ifdef CONFIG_PM
348 .resume = ata_scsi_device_resume, 349 .resume = ata_scsi_device_resume,
349 .suspend = ata_scsi_device_suspend, 350 .suspend = ata_scsi_device_suspend,
351#endif
350}; 352};
351 353
352/* 354/*
@@ -667,11 +669,13 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
667 return ata_pci_init_one(pdev, port_info, 2); 669 return ata_pci_init_one(pdev, port_info, 2);
668} 670}
669 671
672#ifdef CONFIG_PM
670static int ali_reinit_one(struct pci_dev *pdev) 673static int ali_reinit_one(struct pci_dev *pdev)
671{ 674{
672 ali_init_chipset(pdev); 675 ali_init_chipset(pdev);
673 return ata_pci_device_resume(pdev); 676 return ata_pci_device_resume(pdev);
674} 677}
678#endif
675 679
676static const struct pci_device_id ali[] = { 680static const struct pci_device_id ali[] = {
677 { PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5228), }, 681 { PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5228), },
@@ -685,8 +689,10 @@ static struct pci_driver ali_pci_driver = {
685 .id_table = ali, 689 .id_table = ali,
686 .probe = ali_init_one, 690 .probe = ali_init_one,
687 .remove = ata_pci_remove_one, 691 .remove = ata_pci_remove_one,
692#ifdef CONFIG_PM
688 .suspend = ata_pci_device_suspend, 693 .suspend = ata_pci_device_suspend,
689 .resume = ali_reinit_one, 694 .resume = ali_reinit_one,
695#endif
690}; 696};
691 697
692static int __init ali_init(void) 698static int __init ali_init(void)
diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c
index 619e44b040..1838176290 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.7" 28#define DRV_VERSION "0.2.8"
29 29
30/** 30/**
31 * timing_setup - shared timing computation and load 31 * timing_setup - shared timing computation and load
@@ -128,7 +128,7 @@ static void timing_setup(struct ata_port *ap, struct ata_device *adev, int offse
128 128
129static int amd_pre_reset(struct ata_port *ap) 129static int amd_pre_reset(struct ata_port *ap)
130{ 130{
131 static const u32 bitmask[2] = {0x03, 0xC0}; 131 static const u32 bitmask[2] = {0x03, 0x0C};
132 static const struct pci_bits amd_enable_bits[] = { 132 static const struct pci_bits amd_enable_bits[] = {
133 { 0x40, 1, 0x02, 0x02 }, 133 { 0x40, 1, 0x02, 0x02 },
134 { 0x40, 1, 0x01, 0x01 } 134 { 0x40, 1, 0x01, 0x01 }
@@ -247,7 +247,7 @@ static void amd133_set_dmamode(struct ata_port *ap, struct ata_device *adev)
247 */ 247 */
248 248
249static int nv_pre_reset(struct ata_port *ap) { 249static int nv_pre_reset(struct ata_port *ap) {
250 static const u8 bitmask[2] = {0x03, 0xC0}; 250 static const u8 bitmask[2] = {0x03, 0x0C};
251 static const struct pci_bits nv_enable_bits[] = { 251 static const struct pci_bits nv_enable_bits[] = {
252 { 0x50, 1, 0x02, 0x02 }, 252 { 0x50, 1, 0x02, 0x02 },
253 { 0x50, 1, 0x01, 0x01 } 253 { 0x50, 1, 0x01, 0x01 }
@@ -334,8 +334,10 @@ static struct scsi_host_template amd_sht = {
334 .slave_configure = ata_scsi_slave_config, 334 .slave_configure = ata_scsi_slave_config,
335 .slave_destroy = ata_scsi_slave_destroy, 335 .slave_destroy = ata_scsi_slave_destroy,
336 .bios_param = ata_std_bios_param, 336 .bios_param = ata_std_bios_param,
337#ifdef CONFIG_PM
337 .resume = ata_scsi_device_resume, 338 .resume = ata_scsi_device_resume,
338 .suspend = ata_scsi_device_suspend, 339 .suspend = ata_scsi_device_suspend,
340#endif
339}; 341};
340 342
341static struct ata_port_operations amd33_port_ops = { 343static struct ata_port_operations amd33_port_ops = {
@@ -663,6 +665,7 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
663 return ata_pci_init_one(pdev, port_info, 2); 665 return ata_pci_init_one(pdev, port_info, 2);
664} 666}
665 667
668#ifdef CONFIG_PM
666static int amd_reinit_one(struct pci_dev *pdev) 669static int amd_reinit_one(struct pci_dev *pdev)
667{ 670{
668 if (pdev->vendor == PCI_VENDOR_ID_AMD) { 671 if (pdev->vendor == PCI_VENDOR_ID_AMD) {
@@ -679,6 +682,7 @@ static int amd_reinit_one(struct pci_dev *pdev)
679 } 682 }
680 return ata_pci_device_resume(pdev); 683 return ata_pci_device_resume(pdev);
681} 684}
685#endif
682 686
683static const struct pci_device_id amd[] = { 687static const struct pci_device_id amd[] = {
684 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_COBRA_7401), 0 }, 688 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_COBRA_7401), 0 },
@@ -708,8 +712,10 @@ static struct pci_driver amd_pci_driver = {
708 .id_table = amd, 712 .id_table = amd,
709 .probe = amd_init_one, 713 .probe = amd_init_one,
710 .remove = ata_pci_remove_one, 714 .remove = ata_pci_remove_one,
715#ifdef CONFIG_PM
711 .suspend = ata_pci_device_suspend, 716 .suspend = ata_pci_device_suspend,
712 .resume = amd_reinit_one, 717 .resume = amd_reinit_one,
718#endif
713}; 719};
714 720
715static int __init amd_init(void) 721static int __init amd_init(void)
diff --git a/drivers/ata/pata_atiixp.c b/drivers/ata/pata_atiixp.c
index c3eb40c91c..51d9923be0 100644
--- a/drivers/ata/pata_atiixp.c
+++ b/drivers/ata/pata_atiixp.c
@@ -224,8 +224,10 @@ static struct scsi_host_template atiixp_sht = {
224 .slave_configure = ata_scsi_slave_config, 224 .slave_configure = ata_scsi_slave_config,
225 .slave_destroy = ata_scsi_slave_destroy, 225 .slave_destroy = ata_scsi_slave_destroy,
226 .bios_param = ata_std_bios_param, 226 .bios_param = ata_std_bios_param,
227#ifdef CONFIG_PM
227 .resume = ata_scsi_device_resume, 228 .resume = ata_scsi_device_resume,
228 .suspend = ata_scsi_device_suspend, 229 .suspend = ata_scsi_device_suspend,
230#endif
229}; 231};
230 232
231static struct ata_port_operations atiixp_port_ops = { 233static struct ata_port_operations atiixp_port_ops = {
@@ -290,8 +292,10 @@ static struct pci_driver atiixp_pci_driver = {
290 .id_table = atiixp, 292 .id_table = atiixp,
291 .probe = atiixp_init_one, 293 .probe = atiixp_init_one,
292 .remove = ata_pci_remove_one, 294 .remove = ata_pci_remove_one,
295#ifdef CONFIG_PM
293 .resume = ata_pci_device_resume, 296 .resume = ata_pci_device_resume,
294 .suspend = ata_pci_device_suspend, 297 .suspend = ata_pci_device_suspend,
298#endif
295}; 299};
296 300
297static int __init atiixp_init(void) 301static int __init atiixp_init(void)
diff --git a/drivers/ata/pata_cmd64x.c b/drivers/ata/pata_cmd64x.c
index da098282b5..5b13bdd1ed 100644
--- a/drivers/ata/pata_cmd64x.c
+++ b/drivers/ata/pata_cmd64x.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * pata_cmd64x.c - ATI PATA for new ATA layer 2 * pata_cmd64x.c - CMD64x PATA for new ATA layer
3 * (C) 2005 Red Hat Inc 3 * (C) 2005 Red Hat Inc
4 * Alan Cox <alan@redhat.com> 4 * Alan Cox <alan@redhat.com>
5 * 5 *
@@ -285,8 +285,10 @@ static struct scsi_host_template cmd64x_sht = {
285 .slave_configure = ata_scsi_slave_config, 285 .slave_configure = ata_scsi_slave_config,
286 .slave_destroy = ata_scsi_slave_destroy, 286 .slave_destroy = ata_scsi_slave_destroy,
287 .bios_param = ata_std_bios_param, 287 .bios_param = ata_std_bios_param,
288#ifdef CONFIG_PM
288 .resume = ata_scsi_device_resume, 289 .resume = ata_scsi_device_resume,
289 .suspend = ata_scsi_device_suspend, 290 .suspend = ata_scsi_device_suspend,
291#endif
290}; 292};
291 293
292static struct ata_port_operations cmd64x_port_ops = { 294static struct ata_port_operations cmd64x_port_ops = {
@@ -479,6 +481,7 @@ static int cmd64x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
479 return ata_pci_init_one(pdev, port_info, 2); 481 return ata_pci_init_one(pdev, port_info, 2);
480} 482}
481 483
484#ifdef CONFIG_PM
482static int cmd64x_reinit_one(struct pci_dev *pdev) 485static int cmd64x_reinit_one(struct pci_dev *pdev)
483{ 486{
484 u8 mrdmode; 487 u8 mrdmode;
@@ -492,6 +495,7 @@ static int cmd64x_reinit_one(struct pci_dev *pdev)
492#endif 495#endif
493 return ata_pci_device_resume(pdev); 496 return ata_pci_device_resume(pdev);
494} 497}
498#endif
495 499
496static const struct pci_device_id cmd64x[] = { 500static const struct pci_device_id cmd64x[] = {
497 { PCI_VDEVICE(CMD, PCI_DEVICE_ID_CMD_643), 0 }, 501 { PCI_VDEVICE(CMD, PCI_DEVICE_ID_CMD_643), 0 },
@@ -507,8 +511,10 @@ static struct pci_driver cmd64x_pci_driver = {
507 .id_table = cmd64x, 511 .id_table = cmd64x,
508 .probe = cmd64x_init_one, 512 .probe = cmd64x_init_one,
509 .remove = ata_pci_remove_one, 513 .remove = ata_pci_remove_one,
514#ifdef CONFIG_PM
510 .suspend = ata_pci_device_suspend, 515 .suspend = ata_pci_device_suspend,
511 .resume = cmd64x_reinit_one, 516 .resume = cmd64x_reinit_one,
517#endif
512}; 518};
513 519
514static int __init cmd64x_init(void) 520static int __init cmd64x_init(void)
diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c
index 1ce8fcfd78..7ef834250a 100644
--- a/drivers/ata/pata_cs5520.c
+++ b/drivers/ata/pata_cs5520.c
@@ -41,7 +41,7 @@
41#include <linux/libata.h> 41#include <linux/libata.h>
42 42
43#define DRV_NAME "pata_cs5520" 43#define DRV_NAME "pata_cs5520"
44#define DRV_VERSION "0.6.3" 44#define DRV_VERSION "0.6.4"
45 45
46struct pio_clocks 46struct pio_clocks
47{ 47{
@@ -167,8 +167,10 @@ static struct scsi_host_template cs5520_sht = {
167 .slave_configure = ata_scsi_slave_config, 167 .slave_configure = ata_scsi_slave_config,
168 .slave_destroy = ata_scsi_slave_destroy, 168 .slave_destroy = ata_scsi_slave_destroy,
169 .bios_param = ata_std_bios_param, 169 .bios_param = ata_std_bios_param,
170#ifdef CONFIG_PM
170 .resume = ata_scsi_device_resume, 171 .resume = ata_scsi_device_resume,
171 .suspend = ata_scsi_device_suspend, 172 .suspend = ata_scsi_device_suspend,
173#endif
172}; 174};
173 175
174static struct ata_port_operations cs5520_port_ops = { 176static struct ata_port_operations cs5520_port_ops = {
@@ -306,9 +308,9 @@ static void __devexit cs5520_remove_one(struct pci_dev *pdev)
306 struct ata_host *host = dev_get_drvdata(dev); 308 struct ata_host *host = dev_get_drvdata(dev);
307 309
308 ata_host_detach(host); 310 ata_host_detach(host);
309 dev_set_drvdata(dev, NULL);
310} 311}
311 312
313#ifdef CONFIG_PM
312/** 314/**
313 * cs5520_reinit_one - device resume 315 * cs5520_reinit_one - device resume
314 * @pdev: PCI device 316 * @pdev: PCI device
@@ -325,6 +327,31 @@ static int cs5520_reinit_one(struct pci_dev *pdev)
325 pci_write_config_byte(pdev, 0x60, pcicfg | 0x40); 327 pci_write_config_byte(pdev, 0x60, pcicfg | 0x40);
326 return ata_pci_device_resume(pdev); 328 return ata_pci_device_resume(pdev);
327} 329}
330
331/**
332 * cs5520_pci_device_suspend - device suspend
333 * @pdev: PCI device
334 *
335 * We have to cut and waste bits from the standard method because
336 * the 5520 is a bit odd and not just a pure ATA device. As a result
337 * we must not disable it. The needed code is short and this avoids
338 * chip specific mess in the core code.
339 */
340
341static int cs5520_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
342{
343 struct ata_host *host = dev_get_drvdata(&pdev->dev);
344 int rc = 0;
345
346 rc = ata_host_suspend(host, mesg);
347 if (rc)
348 return rc;
349
350 pci_save_state(pdev);
351 return 0;
352}
353#endif /* CONFIG_PM */
354
328/* For now keep DMA off. We can set it for all but A rev CS5510 once the 355/* For now keep DMA off. We can set it for all but A rev CS5510 once the
329 core ATA code can handle it */ 356 core ATA code can handle it */
330 357
@@ -340,8 +367,10 @@ static struct pci_driver cs5520_pci_driver = {
340 .id_table = pata_cs5520, 367 .id_table = pata_cs5520,
341 .probe = cs5520_init_one, 368 .probe = cs5520_init_one,
342 .remove = cs5520_remove_one, 369 .remove = cs5520_remove_one,
343 .suspend = ata_pci_device_suspend, 370#ifdef CONFIG_PM
371 .suspend = cs5520_pci_device_suspend,
344 .resume = cs5520_reinit_one, 372 .resume = cs5520_reinit_one,
373#endif
345}; 374};
346 375
347static int __init cs5520_init(void) 376static int __init cs5520_init(void)
diff --git a/drivers/ata/pata_cs5530.c b/drivers/ata/pata_cs5530.c
index 3d7b7d87ec..db63e80e60 100644
--- a/drivers/ata/pata_cs5530.c
+++ b/drivers/ata/pata_cs5530.c
@@ -35,7 +35,7 @@
35#include <linux/dmi.h> 35#include <linux/dmi.h>
36 36
37#define DRV_NAME "pata_cs5530" 37#define DRV_NAME "pata_cs5530"
38#define DRV_VERSION "0.7.1" 38#define DRV_VERSION "0.7.2"
39 39
40static void __iomem *cs5530_port_base(struct ata_port *ap) 40static void __iomem *cs5530_port_base(struct ata_port *ap)
41{ 41{
@@ -188,8 +188,10 @@ static struct scsi_host_template cs5530_sht = {
188 .slave_configure = ata_scsi_slave_config, 188 .slave_configure = ata_scsi_slave_config,
189 .slave_destroy = ata_scsi_slave_destroy, 189 .slave_destroy = ata_scsi_slave_destroy,
190 .bios_param = ata_std_bios_param, 190 .bios_param = ata_std_bios_param,
191#ifdef CONFIG_PM
191 .resume = ata_scsi_device_resume, 192 .resume = ata_scsi_device_resume,
192 .suspend = ata_scsi_device_suspend, 193 .suspend = ata_scsi_device_suspend,
194#endif
193}; 195};
194 196
195static struct ata_port_operations cs5530_port_ops = { 197static struct ata_port_operations cs5530_port_ops = {
@@ -376,6 +378,7 @@ static int cs5530_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
376 return ata_pci_init_one(pdev, port_info, 2); 378 return ata_pci_init_one(pdev, port_info, 2);
377} 379}
378 380
381#ifdef CONFIG_PM
379static int cs5530_reinit_one(struct pci_dev *pdev) 382static int cs5530_reinit_one(struct pci_dev *pdev)
380{ 383{
381 /* If we fail on resume we are doomed */ 384 /* If we fail on resume we are doomed */
@@ -383,6 +386,7 @@ static int cs5530_reinit_one(struct pci_dev *pdev)
383 BUG(); 386 BUG();
384 return ata_pci_device_resume(pdev); 387 return ata_pci_device_resume(pdev);
385} 388}
389#endif /* CONFIG_PM */
386 390
387static const struct pci_device_id cs5530[] = { 391static const struct pci_device_id cs5530[] = {
388 { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5530_IDE), }, 392 { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5530_IDE), },
@@ -395,8 +399,10 @@ static struct pci_driver cs5530_pci_driver = {
395 .id_table = cs5530, 399 .id_table = cs5530,
396 .probe = cs5530_init_one, 400 .probe = cs5530_init_one,
397 .remove = ata_pci_remove_one, 401 .remove = ata_pci_remove_one,
402#ifdef CONFIG_PM
398 .suspend = ata_pci_device_suspend, 403 .suspend = ata_pci_device_suspend,
399 .resume = cs5530_reinit_one, 404 .resume = cs5530_reinit_one,
405#endif
400}; 406};
401 407
402static int __init cs5530_init(void) 408static int __init cs5530_init(void)
diff --git a/drivers/ata/pata_cs5535.c b/drivers/ata/pata_cs5535.c
index 17bc693cc5..1572e5c903 100644
--- a/drivers/ata/pata_cs5535.c
+++ b/drivers/ata/pata_cs5535.c
@@ -185,8 +185,10 @@ static struct scsi_host_template cs5535_sht = {
185 .slave_configure = ata_scsi_slave_config, 185 .slave_configure = ata_scsi_slave_config,
186 .slave_destroy = ata_scsi_slave_destroy, 186 .slave_destroy = ata_scsi_slave_destroy,
187 .bios_param = ata_std_bios_param, 187 .bios_param = ata_std_bios_param,
188#ifdef CONFIG_PM
188 .resume = ata_scsi_device_resume, 189 .resume = ata_scsi_device_resume,
189 .suspend = ata_scsi_device_suspend, 190 .suspend = ata_scsi_device_suspend,
191#endif
190}; 192};
191 193
192static struct ata_port_operations cs5535_port_ops = { 194static struct ata_port_operations cs5535_port_ops = {
@@ -270,8 +272,10 @@ static struct pci_driver cs5535_pci_driver = {
270 .id_table = cs5535, 272 .id_table = cs5535,
271 .probe = cs5535_init_one, 273 .probe = cs5535_init_one,
272 .remove = ata_pci_remove_one, 274 .remove = ata_pci_remove_one,
275#ifdef CONFIG_PM
273 .suspend = ata_pci_device_suspend, 276 .suspend = ata_pci_device_suspend,
274 .resume = ata_pci_device_resume, 277 .resume = ata_pci_device_resume,
278#endif
275}; 279};
276 280
277static int __init cs5535_init(void) 281static int __init cs5535_init(void)
diff --git a/drivers/ata/pata_cypress.c b/drivers/ata/pata_cypress.c
index 63f48f0876..f69dde5f70 100644
--- a/drivers/ata/pata_cypress.c
+++ b/drivers/ata/pata_cypress.c
@@ -136,8 +136,10 @@ static struct scsi_host_template cy82c693_sht = {
136 .slave_configure = ata_scsi_slave_config, 136 .slave_configure = ata_scsi_slave_config,
137 .slave_destroy = ata_scsi_slave_destroy, 137 .slave_destroy = ata_scsi_slave_destroy,
138 .bios_param = ata_std_bios_param, 138 .bios_param = ata_std_bios_param,
139#ifdef CONFIG_PM
139 .resume = ata_scsi_device_resume, 140 .resume = ata_scsi_device_resume,
140 .suspend = ata_scsi_device_suspend, 141 .suspend = ata_scsi_device_suspend,
142#endif
141}; 143};
142 144
143static struct ata_port_operations cy82c693_port_ops = { 145static struct ata_port_operations cy82c693_port_ops = {
@@ -206,8 +208,10 @@ static struct pci_driver cy82c693_pci_driver = {
206 .id_table = cy82c693, 208 .id_table = cy82c693,
207 .probe = cy82c693_init_one, 209 .probe = cy82c693_init_one,
208 .remove = ata_pci_remove_one, 210 .remove = ata_pci_remove_one,
211#ifdef CONFIG_PM
209 .suspend = ata_pci_device_suspend, 212 .suspend = ata_pci_device_suspend,
210 .resume = ata_pci_device_resume, 213 .resume = ata_pci_device_resume,
214#endif
211}; 215};
212 216
213static int __init cy82c693_init(void) 217static int __init cy82c693_init(void)
diff --git a/drivers/ata/pata_efar.c b/drivers/ata/pata_efar.c
index c19b6a8a7d..dac7a6554f 100644
--- a/drivers/ata/pata_efar.c
+++ b/drivers/ata/pata_efar.c
@@ -234,8 +234,10 @@ static struct scsi_host_template efar_sht = {
234 .slave_configure = ata_scsi_slave_config, 234 .slave_configure = ata_scsi_slave_config,
235 .slave_destroy = ata_scsi_slave_destroy, 235 .slave_destroy = ata_scsi_slave_destroy,
236 .bios_param = ata_std_bios_param, 236 .bios_param = ata_std_bios_param,
237#ifdef CONFIG_PM
237 .resume = ata_scsi_device_resume, 238 .resume = ata_scsi_device_resume,
238 .suspend = ata_scsi_device_suspend, 239 .suspend = ata_scsi_device_suspend,
240#endif
239}; 241};
240 242
241static const struct ata_port_operations efar_ops = { 243static const struct ata_port_operations efar_ops = {
@@ -317,8 +319,10 @@ static struct pci_driver efar_pci_driver = {
317 .id_table = efar_pci_tbl, 319 .id_table = efar_pci_tbl,
318 .probe = efar_init_one, 320 .probe = efar_init_one,
319 .remove = ata_pci_remove_one, 321 .remove = ata_pci_remove_one,
322#ifdef CONFIG_PM
320 .suspend = ata_pci_device_suspend, 323 .suspend = ata_pci_device_suspend,
321 .resume = ata_pci_device_resume, 324 .resume = ata_pci_device_resume,
325#endif
322}; 326};
323 327
324static int __init efar_init(void) 328static int __init efar_init(void)
diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
index 27d724b5ee..baf35f8760 100644
--- a/drivers/ata/pata_hpt366.c
+++ b/drivers/ata/pata_hpt366.c
@@ -27,7 +27,7 @@
27#include <linux/libata.h> 27#include <linux/libata.h>
28 28
29#define DRV_NAME "pata_hpt366" 29#define DRV_NAME "pata_hpt366"
30#define DRV_VERSION "0.5.3" 30#define DRV_VERSION "0.6.0"
31 31
32struct hpt_clock { 32struct hpt_clock {
33 u8 xfer_speed; 33 u8 xfer_speed;
@@ -328,8 +328,10 @@ static struct scsi_host_template hpt36x_sht = {
328 .slave_configure = ata_scsi_slave_config, 328 .slave_configure = ata_scsi_slave_config,
329 .slave_destroy = ata_scsi_slave_destroy, 329 .slave_destroy = ata_scsi_slave_destroy,
330 .bios_param = ata_std_bios_param, 330 .bios_param = ata_std_bios_param,
331#ifdef CONFIG_PM
331 .resume = ata_scsi_device_resume, 332 .resume = ata_scsi_device_resume,
332 .suspend = ata_scsi_device_suspend, 333 .suspend = ata_scsi_device_suspend,
334#endif
333}; 335};
334 336
335/* 337/*
@@ -457,12 +459,13 @@ static int hpt36x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
457 return ata_pci_init_one(dev, port_info, 2); 459 return ata_pci_init_one(dev, port_info, 2);
458} 460}
459 461
462#ifdef CONFIG_PM
460static int hpt36x_reinit_one(struct pci_dev *dev) 463static int hpt36x_reinit_one(struct pci_dev *dev)
461{ 464{
462 hpt36x_init_chipset(dev); 465 hpt36x_init_chipset(dev);
463 return ata_pci_device_resume(dev); 466 return ata_pci_device_resume(dev);
464} 467}
465 468#endif
466 469
467static const struct pci_device_id hpt36x[] = { 470static const struct pci_device_id hpt36x[] = {
468 { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT366), }, 471 { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT366), },
@@ -474,8 +477,10 @@ static struct pci_driver hpt36x_pci_driver = {
474 .id_table = hpt36x, 477 .id_table = hpt36x,
475 .probe = hpt36x_init_one, 478 .probe = hpt36x_init_one,
476 .remove = ata_pci_remove_one, 479 .remove = ata_pci_remove_one,
480#ifdef CONFIG_PM
477 .suspend = ata_pci_device_suspend, 481 .suspend = ata_pci_device_suspend,
478 .resume = hpt36x_reinit_one, 482 .resume = hpt36x_reinit_one,
483#endif
479}; 484};
480 485
481static int __init hpt36x_init(void) 486static int __init hpt36x_init(void)
diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index 4ffc392052..f331eeeafa 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -25,7 +25,7 @@
25#include <linux/libata.h> 25#include <linux/libata.h>
26 26
27#define DRV_NAME "pata_hpt37x" 27#define DRV_NAME "pata_hpt37x"
28#define DRV_VERSION "0.5.2" 28#define DRV_VERSION "0.6.0"
29 29
30struct hpt_clock { 30struct hpt_clock {
31 u8 xfer_speed; 31 u8 xfer_speed;
diff --git a/drivers/ata/pata_hpt3x3.c b/drivers/ata/pata_hpt3x3.c
index 483ce7c12c..813485c852 100644
--- a/drivers/ata/pata_hpt3x3.c
+++ b/drivers/ata/pata_hpt3x3.c
@@ -119,8 +119,10 @@ static struct scsi_host_template hpt3x3_sht = {
119 .slave_configure = ata_scsi_slave_config, 119 .slave_configure = ata_scsi_slave_config,
120 .slave_destroy = ata_scsi_slave_destroy, 120 .slave_destroy = ata_scsi_slave_destroy,
121 .bios_param = ata_std_bios_param, 121 .bios_param = ata_std_bios_param,
122#ifdef CONFIG_PM
122 .resume = ata_scsi_device_resume, 123 .resume = ata_scsi_device_resume,
123 .suspend = ata_scsi_device_suspend, 124 .suspend = ata_scsi_device_suspend,
125#endif
124}; 126};
125 127
126static struct ata_port_operations hpt3x3_port_ops = { 128static struct ata_port_operations hpt3x3_port_ops = {
@@ -206,11 +208,13 @@ static int hpt3x3_init_one(struct pci_dev *dev, const struct pci_device_id *id)
206 return ata_pci_init_one(dev, port_info, 2); 208 return ata_pci_init_one(dev, port_info, 2);
207} 209}
208 210
211#ifdef CONFIG_PM
209static int hpt3x3_reinit_one(struct pci_dev *dev) 212static int hpt3x3_reinit_one(struct pci_dev *dev)
210{ 213{
211 hpt3x3_init_chipset(dev); 214 hpt3x3_init_chipset(dev);
212 return ata_pci_device_resume(dev); 215 return ata_pci_device_resume(dev);
213} 216}
217#endif
214 218
215static const struct pci_device_id hpt3x3[] = { 219static const struct pci_device_id hpt3x3[] = {
216 { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT343), }, 220 { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT343), },
@@ -223,8 +227,10 @@ static struct pci_driver hpt3x3_pci_driver = {
223 .id_table = hpt3x3, 227 .id_table = hpt3x3,
224 .probe = hpt3x3_init_one, 228 .probe = hpt3x3_init_one,
225 .remove = ata_pci_remove_one, 229 .remove = ata_pci_remove_one,
230#ifdef CONFIG_PM
226 .suspend = ata_pci_device_suspend, 231 .suspend = ata_pci_device_suspend,
227 .resume = hpt3x3_reinit_one, 232 .resume = hpt3x3_reinit_one,
233#endif
228}; 234};
229 235
230static int __init hpt3x3_init(void) 236static int __init hpt3x3_init(void)
diff --git a/drivers/ata/pata_isapnp.c b/drivers/ata/pata_isapnp.c
index 1bf5ec18b2..1a61cc8917 100644
--- a/drivers/ata/pata_isapnp.c
+++ b/drivers/ata/pata_isapnp.c
@@ -17,7 +17,7 @@
17#include <linux/libata.h> 17#include <linux/libata.h>
18 18
19#define DRV_NAME "pata_isapnp" 19#define DRV_NAME "pata_isapnp"
20#define DRV_VERSION "0.1.5" 20#define DRV_VERSION "0.2.0"
21 21
22static struct scsi_host_template isapnp_sht = { 22static struct scsi_host_template isapnp_sht = {
23 .module = THIS_MODULE, 23 .module = THIS_MODULE,
@@ -128,7 +128,6 @@ static void isapnp_remove_one(struct pnp_dev *idev)
128 struct ata_host *host = dev_get_drvdata(dev); 128 struct ata_host *host = dev_get_drvdata(dev);
129 129
130 ata_host_detach(host); 130 ata_host_detach(host);
131 dev_set_drvdata(dev, NULL);
132} 131}
133 132
134static struct pnp_device_id isapnp_devices[] = { 133static struct pnp_device_id isapnp_devices[] = {
diff --git a/drivers/ata/pata_it8213.c b/drivers/ata/pata_it8213.c
index 7eac869dfc..ea73470155 100644
--- a/drivers/ata/pata_it8213.c
+++ b/drivers/ata/pata_it8213.c
@@ -246,8 +246,10 @@ static struct scsi_host_template it8213_sht = {
246 .dma_boundary = ATA_DMA_BOUNDARY, 246 .dma_boundary = ATA_DMA_BOUNDARY,
247 .slave_configure = ata_scsi_slave_config, 247 .slave_configure = ata_scsi_slave_config,
248 .bios_param = ata_std_bios_param, 248 .bios_param = ata_std_bios_param,
249#ifdef CONFIG_PM
249 .resume = ata_scsi_device_resume, 250 .resume = ata_scsi_device_resume,
250 .suspend = ata_scsi_device_suspend, 251 .suspend = ata_scsi_device_suspend,
252#endif
251}; 253};
252 254
253static const struct ata_port_operations it8213_ops = { 255static const struct ata_port_operations it8213_ops = {
@@ -330,8 +332,10 @@ static struct pci_driver it8213_pci_driver = {
330 .id_table = it8213_pci_tbl, 332 .id_table = it8213_pci_tbl,
331 .probe = it8213_init_one, 333 .probe = it8213_init_one,
332 .remove = ata_pci_remove_one, 334 .remove = ata_pci_remove_one,
335#ifdef CONFIG_PM
333 .suspend = ata_pci_device_suspend, 336 .suspend = ata_pci_device_suspend,
334 .resume = ata_pci_device_resume, 337 .resume = ata_pci_device_resume,
338#endif
335}; 339};
336 340
337static int __init it8213_init(void) 341static int __init it8213_init(void)
diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
index 73394c75be..35ecb2ba06 100644
--- a/drivers/ata/pata_it821x.c
+++ b/drivers/ata/pata_it821x.c
@@ -80,7 +80,7 @@
80 80
81 81
82#define DRV_NAME "pata_it821x" 82#define DRV_NAME "pata_it821x"
83#define DRV_VERSION "0.3.3" 83#define DRV_VERSION "0.3.4"
84 84
85struct it821x_dev 85struct it821x_dev
86{ 86{
@@ -503,10 +503,12 @@ static int it821x_smart_set_mode(struct ata_port *ap, struct ata_device **unused
503 /* We do need the right mode information for DMA or PIO 503 /* We do need the right mode information for DMA or PIO
504 and this comes from the current configuration flags */ 504 and this comes from the current configuration flags */
505 if (dma_enabled & (1 << (5 + i))) { 505 if (dma_enabled & (1 << (5 + i))) {
506 ata_dev_printk(dev, KERN_INFO, "configured for DMA\n");
506 dev->xfer_mode = XFER_MW_DMA_0; 507 dev->xfer_mode = XFER_MW_DMA_0;
507 dev->xfer_shift = ATA_SHIFT_MWDMA; 508 dev->xfer_shift = ATA_SHIFT_MWDMA;
508 dev->flags &= ~ATA_DFLAG_PIO; 509 dev->flags &= ~ATA_DFLAG_PIO;
509 } else { 510 } else {
511 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
510 dev->xfer_mode = XFER_PIO_0; 512 dev->xfer_mode = XFER_PIO_0;
511 dev->xfer_shift = ATA_SHIFT_PIO; 513 dev->xfer_shift = ATA_SHIFT_PIO;
512 dev->flags |= ATA_DFLAG_PIO; 514 dev->flags |= ATA_DFLAG_PIO;
@@ -644,8 +646,10 @@ static struct scsi_host_template it821x_sht = {
644 .slave_configure = ata_scsi_slave_config, 646 .slave_configure = ata_scsi_slave_config,
645 .slave_destroy = ata_scsi_slave_destroy, 647 .slave_destroy = ata_scsi_slave_destroy,
646 .bios_param = ata_std_bios_param, 648 .bios_param = ata_std_bios_param,
649#ifdef CONFIG_PM
647 .resume = ata_scsi_device_resume, 650 .resume = ata_scsi_device_resume,
648 .suspend = ata_scsi_device_suspend, 651 .suspend = ata_scsi_device_suspend,
652#endif
649}; 653};
650 654
651static struct ata_port_operations it821x_smart_port_ops = { 655static struct ata_port_operations it821x_smart_port_ops = {
@@ -778,6 +782,7 @@ static int it821x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
778 return ata_pci_init_one(pdev, port_info, 2); 782 return ata_pci_init_one(pdev, port_info, 2);
779} 783}
780 784
785#ifdef CONFIG_PM
781static int it821x_reinit_one(struct pci_dev *pdev) 786static int it821x_reinit_one(struct pci_dev *pdev)
782{ 787{
783 /* Resume - turn raid back off if need be */ 788 /* Resume - turn raid back off if need be */
@@ -785,6 +790,7 @@ static int it821x_reinit_one(struct pci_dev *pdev)
785 it821x_disable_raid(pdev); 790 it821x_disable_raid(pdev);
786 return ata_pci_device_resume(pdev); 791 return ata_pci_device_resume(pdev);
787} 792}
793#endif
788 794
789static const struct pci_device_id it821x[] = { 795static const struct pci_device_id it821x[] = {
790 { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8211), }, 796 { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8211), },
@@ -798,8 +804,10 @@ static struct pci_driver it821x_pci_driver = {
798 .id_table = it821x, 804 .id_table = it821x,
799 .probe = it821x_init_one, 805 .probe = it821x_init_one,
800 .remove = ata_pci_remove_one, 806 .remove = ata_pci_remove_one,
807#ifdef CONFIG_PM
801 .suspend = ata_pci_device_suspend, 808 .suspend = ata_pci_device_suspend,
802 .resume = it821x_reinit_one, 809 .resume = it821x_reinit_one,
810#endif
803}; 811};
804 812
805static int __init it821x_init(void) 813static int __init it821x_init(void)
diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
index 3222ac7b94..9a0523b5c9 100644
--- a/drivers/ata/pata_ixp4xx_cf.c
+++ b/drivers/ata/pata_ixp4xx_cf.c
@@ -23,15 +23,16 @@
23#include <scsi/scsi_host.h> 23#include <scsi/scsi_host.h>
24 24
25#define DRV_NAME "pata_ixp4xx_cf" 25#define DRV_NAME "pata_ixp4xx_cf"
26#define DRV_VERSION "0.1.1ac1" 26#define DRV_VERSION "0.1.2"
27 27
28static int ixp4xx_set_mode(struct ata_port *ap, struct ata_device *adev) 28static int ixp4xx_set_mode(struct ata_port *ap, struct ata_device **error)
29{ 29{
30 int i; 30 int i;
31 31
32 for (i = 0; i < ATA_MAX_DEVICES; i++) { 32 for (i = 0; i < ATA_MAX_DEVICES; i++) {
33 struct ata_device *dev = &ap->device[i]; 33 struct ata_device *dev = &ap->device[i];
34 if (ata_dev_enabled(dev)) { 34 if (ata_dev_ready(dev)) {
35 ata_dev_printk(dev, KERN_INFO, "configured for PIO0\n");
35 dev->pio_mode = XFER_PIO_0; 36 dev->pio_mode = XFER_PIO_0;
36 dev->xfer_mode = XFER_PIO_0; 37 dev->xfer_mode = XFER_PIO_0;
37 dev->xfer_shift = ATA_SHIFT_PIO; 38 dev->xfer_shift = ATA_SHIFT_PIO;
diff --git a/drivers/ata/pata_jmicron.c b/drivers/ata/pata_jmicron.c
index 7a635dd326..43763c99ea 100644
--- a/drivers/ata/pata_jmicron.c
+++ b/drivers/ata/pata_jmicron.c
@@ -137,6 +137,10 @@ static struct scsi_host_template jmicron_sht = {
137 .slave_destroy = ata_scsi_slave_destroy, 137 .slave_destroy = ata_scsi_slave_destroy,
138 /* Use standard CHS mapping rules */ 138 /* Use standard CHS mapping rules */
139 .bios_param = ata_std_bios_param, 139 .bios_param = ata_std_bios_param,
140#ifdef CONFIG_PM
141 .suspend = ata_scsi_device_suspend,
142 .resume = ata_scsi_device_resume,
143#endif
140}; 144};
141 145
142static const struct ata_port_operations jmicron_ops = { 146static const struct ata_port_operations jmicron_ops = {
@@ -202,49 +206,20 @@ static int jmicron_init_one (struct pci_dev *pdev, const struct pci_device_id *i
202 }; 206 };
203 struct ata_port_info *port_info[2] = { &info, &info }; 207 struct ata_port_info *port_info[2] = { &info, &info };
204 208
205 u32 reg;
206
207 /* PATA controller is fn 1, AHCI is fn 0 */
208 if (id->driver_data != 368 && PCI_FUNC(pdev->devfn) != 1)
209 return -ENODEV;
210
211 /* The 365/66 have two PATA channels, redirect the second */
212 if (id->driver_data == 365 || id->driver_data == 366) {
213 pci_read_config_dword(pdev, 0x80, &reg);
214 reg |= (1 << 24); /* IDE1 to PATA IDE secondary */
215 pci_write_config_dword(pdev, 0x80, reg);
216 }
217
218 return ata_pci_init_one(pdev, port_info, 2); 209 return ata_pci_init_one(pdev, port_info, 2);
219} 210}
220 211
221static int jmicron_reinit_one(struct pci_dev *pdev)
222{
223 u32 reg;
224
225 switch(pdev->device) {
226 case PCI_DEVICE_ID_JMICRON_JMB368:
227 break;
228 case PCI_DEVICE_ID_JMICRON_JMB365:
229 case PCI_DEVICE_ID_JMICRON_JMB366:
230 /* Restore mapping or disks swap and boy does it get ugly */
231 pci_read_config_dword(pdev, 0x80, &reg);
232 reg |= (1 << 24); /* IDE1 to PATA IDE secondary */
233 pci_write_config_dword(pdev, 0x80, reg);
234 /* Fall through */
235 default:
236 /* Make sure AHCI is turned back on */
237 pci_write_config_byte(pdev, 0x41, 0xa1);
238 }
239 return ata_pci_device_resume(pdev);
240}
241
242static const struct pci_device_id jmicron_pci_tbl[] = { 212static const struct pci_device_id jmicron_pci_tbl[] = {
243 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB361), 361}, 213 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361,
244 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB363), 363}, 214 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 361 },
245 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB365), 365}, 215 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363,
246 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB366), 366}, 216 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 363 },
247 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB368), 368}, 217 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365,
218 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 365 },
219 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366,
220 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 366 },
221 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368,
222 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 368 },
248 223
249 { } /* terminate list */ 224 { } /* terminate list */
250}; 225};
@@ -254,8 +229,10 @@ static struct pci_driver jmicron_pci_driver = {
254 .id_table = jmicron_pci_tbl, 229 .id_table = jmicron_pci_tbl,
255 .probe = jmicron_init_one, 230 .probe = jmicron_init_one,
256 .remove = ata_pci_remove_one, 231 .remove = ata_pci_remove_one,
232#ifdef CONFIG_PM
257 .suspend = ata_pci_device_suspend, 233 .suspend = ata_pci_device_suspend,
258 .resume = jmicron_reinit_one, 234 .resume = ata_pci_device_resume,
235#endif
259}; 236};
260 237
261static int __init jmicron_init(void) 238static int __init jmicron_init(void)
diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
index 98c1fee4b3..86fbcd6a74 100644
--- a/drivers/ata/pata_legacy.c
+++ b/drivers/ata/pata_legacy.c
@@ -64,12 +64,12 @@
64#include <linux/platform_device.h> 64#include <linux/platform_device.h>
65 65
66#define DRV_NAME "pata_legacy" 66#define DRV_NAME "pata_legacy"
67#define DRV_VERSION "0.5.3" 67#define DRV_VERSION "0.5.4"
68 68
69#define NR_HOST 6 69#define NR_HOST 6
70 70
71static int legacy_port[NR_HOST] = { 0x1f0, 0x170, 0x1e8, 0x168, 0x1e0, 0x160 }; 71static int legacy_port[NR_HOST] = { 0x1f0, 0x170, 0x1e8, 0x168, 0x1e0, 0x160 };
72static int legacy_irq[NR_HOST] = { 15, 14, 11, 10, 8, 12 }; 72static int legacy_irq[NR_HOST] = { 14, 15, 11, 10, 8, 12 };
73 73
74struct legacy_data { 74struct legacy_data {
75 unsigned long timing; 75 unsigned long timing;
@@ -186,7 +186,10 @@ static struct ata_port_operations legacy_port_ops = {
186 .exec_command = ata_exec_command, 186 .exec_command = ata_exec_command,
187 .dev_select = ata_std_dev_select, 187 .dev_select = ata_std_dev_select,
188 188
189 .freeze = ata_bmdma_freeze,
190 .thaw = ata_bmdma_thaw,
189 .error_handler = ata_bmdma_error_handler, 191 .error_handler = ata_bmdma_error_handler,
192 .post_internal_cmd = ata_bmdma_post_internal_cmd,
190 193
191 .qc_prep = ata_qc_prep, 194 .qc_prep = ata_qc_prep,
192 .qc_issue = ata_qc_issue_prot, 195 .qc_issue = ata_qc_issue_prot,
@@ -298,7 +301,10 @@ static struct ata_port_operations pdc20230_port_ops = {
298 .exec_command = ata_exec_command, 301 .exec_command = ata_exec_command,
299 .dev_select = ata_std_dev_select, 302 .dev_select = ata_std_dev_select,
300 303
304 .freeze = ata_bmdma_freeze,
305 .thaw = ata_bmdma_thaw,
301 .error_handler = ata_bmdma_error_handler, 306 .error_handler = ata_bmdma_error_handler,
307 .post_internal_cmd = ata_bmdma_post_internal_cmd,
302 308
303 .qc_prep = ata_qc_prep, 309 .qc_prep = ata_qc_prep,
304 .qc_issue = ata_qc_issue_prot, 310 .qc_issue = ata_qc_issue_prot,
@@ -350,7 +356,10 @@ static struct ata_port_operations ht6560a_port_ops = {
350 .exec_command = ata_exec_command, 356 .exec_command = ata_exec_command,
351 .dev_select = ata_std_dev_select, 357 .dev_select = ata_std_dev_select,
352 358
359 .freeze = ata_bmdma_freeze,
360 .thaw = ata_bmdma_thaw,
353 .error_handler = ata_bmdma_error_handler, 361 .error_handler = ata_bmdma_error_handler,
362 .post_internal_cmd = ata_bmdma_post_internal_cmd,
354 363
355 .qc_prep = ata_qc_prep, 364 .qc_prep = ata_qc_prep,
356 .qc_issue = ata_qc_issue_prot, 365 .qc_issue = ata_qc_issue_prot,
@@ -413,7 +422,10 @@ static struct ata_port_operations ht6560b_port_ops = {
413 .exec_command = ata_exec_command, 422 .exec_command = ata_exec_command,
414 .dev_select = ata_std_dev_select, 423 .dev_select = ata_std_dev_select,
415 424
425 .freeze = ata_bmdma_freeze,
426 .thaw = ata_bmdma_thaw,
416 .error_handler = ata_bmdma_error_handler, 427 .error_handler = ata_bmdma_error_handler,
428 .post_internal_cmd = ata_bmdma_post_internal_cmd,
417 429
418 .qc_prep = ata_qc_prep, 430 .qc_prep = ata_qc_prep,
419 .qc_issue = ata_qc_issue_prot, 431 .qc_issue = ata_qc_issue_prot,
@@ -531,7 +543,10 @@ static struct ata_port_operations opti82c611a_port_ops = {
531 .exec_command = ata_exec_command, 543 .exec_command = ata_exec_command,
532 .dev_select = ata_std_dev_select, 544 .dev_select = ata_std_dev_select,
533 545
546 .freeze = ata_bmdma_freeze,
547 .thaw = ata_bmdma_thaw,
534 .error_handler = ata_bmdma_error_handler, 548 .error_handler = ata_bmdma_error_handler,
549 .post_internal_cmd = ata_bmdma_post_internal_cmd,
535 550
536 .qc_prep = ata_qc_prep, 551 .qc_prep = ata_qc_prep,
537 .qc_issue = ata_qc_issue_prot, 552 .qc_issue = ata_qc_issue_prot,
@@ -661,7 +676,10 @@ static struct ata_port_operations opti82c46x_port_ops = {
661 .exec_command = ata_exec_command, 676 .exec_command = ata_exec_command,
662 .dev_select = ata_std_dev_select, 677 .dev_select = ata_std_dev_select,
663 678
679 .freeze = ata_bmdma_freeze,
680 .thaw = ata_bmdma_thaw,
664 .error_handler = ata_bmdma_error_handler, 681 .error_handler = ata_bmdma_error_handler,
682 .post_internal_cmd = ata_bmdma_post_internal_cmd,
665 683
666 .qc_prep = ata_qc_prep, 684 .qc_prep = ata_qc_prep,
667 .qc_issue = opti82c46x_qc_issue_prot, 685 .qc_issue = opti82c46x_qc_issue_prot,
diff --git a/drivers/ata/pata_marvell.c b/drivers/ata/pata_marvell.c
index 13a70ac6f1..6dd7c4ef3e 100644
--- a/drivers/ata/pata_marvell.c
+++ b/drivers/ata/pata_marvell.c
@@ -103,8 +103,10 @@ static struct scsi_host_template marvell_sht = {
103 .slave_destroy = ata_scsi_slave_destroy, 103 .slave_destroy = ata_scsi_slave_destroy,
104 /* Use standard CHS mapping rules */ 104 /* Use standard CHS mapping rules */
105 .bios_param = ata_std_bios_param, 105 .bios_param = ata_std_bios_param,
106#ifdef CONFIG_PM
106 .resume = ata_scsi_device_resume, 107 .resume = ata_scsi_device_resume,
107 .suspend = ata_scsi_device_suspend, 108 .suspend = ata_scsi_device_suspend,
109#endif
108}; 110};
109 111
110static const struct ata_port_operations marvell_ops = { 112static const struct ata_port_operations marvell_ops = {
@@ -199,8 +201,10 @@ static struct pci_driver marvell_pci_driver = {
199 .id_table = marvell_pci_tbl, 201 .id_table = marvell_pci_tbl,
200 .probe = marvell_init_one, 202 .probe = marvell_init_one,
201 .remove = ata_pci_remove_one, 203 .remove = ata_pci_remove_one,
204#ifdef CONFIG_PM
202 .suspend = ata_pci_device_suspend, 205 .suspend = ata_pci_device_suspend,
203 .resume = ata_pci_device_resume, 206 .resume = ata_pci_device_resume,
207#endif
204}; 208};
205 209
206static int __init marvell_init(void) 210static int __init marvell_init(void)
diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
index 29e1809e5e..f5d88729ca 100644
--- a/drivers/ata/pata_mpc52xx.c
+++ b/drivers/ata/pata_mpc52xx.c
@@ -280,6 +280,10 @@ static struct scsi_host_template mpc52xx_ata_sht = {
280 .dma_boundary = ATA_DMA_BOUNDARY, 280 .dma_boundary = ATA_DMA_BOUNDARY,
281 .slave_configure = ata_scsi_slave_config, 281 .slave_configure = ata_scsi_slave_config,
282 .bios_param = ata_std_bios_param, 282 .bios_param = ata_std_bios_param,
283#ifdef CONFIG_PM
284 .suspend = ata_scsi_device_suspend,
285 .resume = ata_scsi_device_resume,
286#endif
283}; 287};
284 288
285static struct ata_port_operations mpc52xx_ata_port_ops = { 289static struct ata_port_operations mpc52xx_ata_port_ops = {
diff --git a/drivers/ata/pata_mpiix.c b/drivers/ata/pata_mpiix.c
index f2e7115f7a..4abe45ac19 100644
--- a/drivers/ata/pata_mpiix.c
+++ b/drivers/ata/pata_mpiix.c
@@ -165,8 +165,10 @@ static struct scsi_host_template mpiix_sht = {
165 .slave_configure = ata_scsi_slave_config, 165 .slave_configure = ata_scsi_slave_config,
166 .slave_destroy = ata_scsi_slave_destroy, 166 .slave_destroy = ata_scsi_slave_destroy,
167 .bios_param = ata_std_bios_param, 167 .bios_param = ata_std_bios_param,
168#ifdef CONFIG_PM
168 .resume = ata_scsi_device_resume, 169 .resume = ata_scsi_device_resume,
169 .suspend = ata_scsi_device_suspend, 170 .suspend = ata_scsi_device_suspend,
171#endif
170}; 172};
171 173
172static struct ata_port_operations mpiix_port_ops = { 174static struct ata_port_operations mpiix_port_ops = {
@@ -270,8 +272,10 @@ static struct pci_driver mpiix_pci_driver = {
270 .id_table = mpiix, 272 .id_table = mpiix,
271 .probe = mpiix_init_one, 273 .probe = mpiix_init_one,
272 .remove = ata_pci_remove_one, 274 .remove = ata_pci_remove_one,
275#ifdef CONFIG_PM
273 .suspend = ata_pci_device_suspend, 276 .suspend = ata_pci_device_suspend,
274 .resume = ata_pci_device_resume, 277 .resume = ata_pci_device_resume,
278#endif
275}; 279};
276 280
277static int __init mpiix_init(void) 281static int __init mpiix_init(void)
diff --git a/drivers/ata/pata_netcell.c b/drivers/ata/pata_netcell.c
index e8393e19be..38f99b38a5 100644
--- a/drivers/ata/pata_netcell.c
+++ b/drivers/ata/pata_netcell.c
@@ -63,8 +63,10 @@ static struct scsi_host_template netcell_sht = {
63 .slave_destroy = ata_scsi_slave_destroy, 63 .slave_destroy = ata_scsi_slave_destroy,
64 /* Use standard CHS mapping rules */ 64 /* Use standard CHS mapping rules */
65 .bios_param = ata_std_bios_param, 65 .bios_param = ata_std_bios_param,
66#ifdef CONFIG_PM
66 .resume = ata_scsi_device_resume, 67 .resume = ata_scsi_device_resume,
67 .suspend = ata_scsi_device_suspend, 68 .suspend = ata_scsi_device_suspend,
69#endif
68}; 70};
69 71
70static const struct ata_port_operations netcell_ops = { 72static const struct ata_port_operations netcell_ops = {
@@ -153,8 +155,10 @@ static struct pci_driver netcell_pci_driver = {
153 .id_table = netcell_pci_tbl, 155 .id_table = netcell_pci_tbl,
154 .probe = netcell_init_one, 156 .probe = netcell_init_one,
155 .remove = ata_pci_remove_one, 157 .remove = ata_pci_remove_one,
158#ifdef CONFIG_PM
156 .suspend = ata_pci_device_suspend, 159 .suspend = ata_pci_device_suspend,
157 .resume = ata_pci_device_resume, 160 .resume = ata_pci_device_resume,
161#endif
158}; 162};
159 163
160static int __init netcell_init(void) 164static int __init netcell_init(void)
diff --git a/drivers/ata/pata_ns87410.c b/drivers/ata/pata_ns87410.c
index 3d1fa487c4..9944a28daa 100644
--- a/drivers/ata/pata_ns87410.c
+++ b/drivers/ata/pata_ns87410.c
@@ -157,8 +157,10 @@ static struct scsi_host_template ns87410_sht = {
157 .slave_configure = ata_scsi_slave_config, 157 .slave_configure = ata_scsi_slave_config,
158 .slave_destroy = ata_scsi_slave_destroy, 158 .slave_destroy = ata_scsi_slave_destroy,
159 .bios_param = ata_std_bios_param, 159 .bios_param = ata_std_bios_param,
160#ifdef CONFIG_PM
160 .resume = ata_scsi_device_resume, 161 .resume = ata_scsi_device_resume,
161 .suspend = ata_scsi_device_suspend, 162 .suspend = ata_scsi_device_suspend,
163#endif
162}; 164};
163 165
164static struct ata_port_operations ns87410_port_ops = { 166static struct ata_port_operations ns87410_port_ops = {
@@ -212,8 +214,10 @@ static struct pci_driver ns87410_pci_driver = {
212 .id_table = ns87410, 214 .id_table = ns87410,
213 .probe = ns87410_init_one, 215 .probe = ns87410_init_one,
214 .remove = ata_pci_remove_one, 216 .remove = ata_pci_remove_one,
217#ifdef CONFIG_PM
215 .suspend = ata_pci_device_suspend, 218 .suspend = ata_pci_device_suspend,
216 .resume = ata_pci_device_resume, 219 .resume = ata_pci_device_resume,
220#endif
217}; 221};
218 222
219static int __init ns87410_init(void) 223static int __init ns87410_init(void)
diff --git a/drivers/ata/pata_oldpiix.c b/drivers/ata/pata_oldpiix.c
index 45215aa05e..da68cd19ef 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.3" 28#define DRV_VERSION "0.5.4"
29 29
30/** 30/**
31 * oldpiix_pre_reset - probe begin 31 * oldpiix_pre_reset - probe begin
@@ -209,10 +209,9 @@ static unsigned int oldpiix_qc_issue_prot(struct ata_queued_cmd *qc)
209 struct ata_device *adev = qc->dev; 209 struct ata_device *adev = qc->dev;
210 210
211 if (adev != ap->private_data) { 211 if (adev != ap->private_data) {
212 oldpiix_set_piomode(ap, adev);
212 if (adev->dma_mode) 213 if (adev->dma_mode)
213 oldpiix_set_dmamode(ap, adev); 214 oldpiix_set_dmamode(ap, adev);
214 else if (adev->pio_mode)
215 oldpiix_set_piomode(ap, adev);
216 } 215 }
217 return ata_qc_issue_prot(qc); 216 return ata_qc_issue_prot(qc);
218} 217}
@@ -234,8 +233,10 @@ static struct scsi_host_template oldpiix_sht = {
234 .slave_configure = ata_scsi_slave_config, 233 .slave_configure = ata_scsi_slave_config,
235 .slave_destroy = ata_scsi_slave_destroy, 234 .slave_destroy = ata_scsi_slave_destroy,
236 .bios_param = ata_std_bios_param, 235 .bios_param = ata_std_bios_param,
236#ifdef CONFIG_PM
237 .resume = ata_scsi_device_resume, 237 .resume = ata_scsi_device_resume,
238 .suspend = ata_scsi_device_suspend, 238 .suspend = ata_scsi_device_suspend,
239#endif
239}; 240};
240 241
241static const struct ata_port_operations oldpiix_pata_ops = { 242static const struct ata_port_operations oldpiix_pata_ops = {
@@ -317,8 +318,10 @@ static struct pci_driver oldpiix_pci_driver = {
317 .id_table = oldpiix_pci_tbl, 318 .id_table = oldpiix_pci_tbl,
318 .probe = oldpiix_init_one, 319 .probe = oldpiix_init_one,
319 .remove = ata_pci_remove_one, 320 .remove = ata_pci_remove_one,
321#ifdef CONFIG_PM
320 .suspend = ata_pci_device_suspend, 322 .suspend = ata_pci_device_suspend,
321 .resume = ata_pci_device_resume, 323 .resume = ata_pci_device_resume,
324#endif
322}; 325};
323 326
324static int __init oldpiix_init(void) 327static int __init oldpiix_init(void)
diff --git a/drivers/ata/pata_opti.c b/drivers/ata/pata_opti.c
index da1aa148b3..3fd3a35c22 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.7" 37#define DRV_VERSION "0.2.8"
38 38
39enum { 39enum {
40 READ_REG = 0, /* index of Read cycle timing register */ 40 READ_REG = 0, /* index of Read cycle timing register */
@@ -179,8 +179,10 @@ static struct scsi_host_template opti_sht = {
179 .slave_configure = ata_scsi_slave_config, 179 .slave_configure = ata_scsi_slave_config,
180 .slave_destroy = ata_scsi_slave_destroy, 180 .slave_destroy = ata_scsi_slave_destroy,
181 .bios_param = ata_std_bios_param, 181 .bios_param = ata_std_bios_param,
182#ifdef CONFIG_PM
182 .resume = ata_scsi_device_resume, 183 .resume = ata_scsi_device_resume,
183 .suspend = ata_scsi_device_suspend, 184 .suspend = ata_scsi_device_suspend,
185#endif
184}; 186};
185 187
186static struct ata_port_operations opti_port_ops = { 188static struct ata_port_operations opti_port_ops = {
@@ -244,8 +246,10 @@ static struct pci_driver opti_pci_driver = {
244 .id_table = opti, 246 .id_table = opti,
245 .probe = opti_init_one, 247 .probe = opti_init_one,
246 .remove = ata_pci_remove_one, 248 .remove = ata_pci_remove_one,
249#ifdef CONFIG_PM
247 .suspend = ata_pci_device_suspend, 250 .suspend = ata_pci_device_suspend,
248 .resume = ata_pci_device_resume, 251 .resume = ata_pci_device_resume,
252#endif
249}; 253};
250 254
251static int __init opti_init(void) 255static int __init opti_init(void)
diff --git a/drivers/ata/pata_optidma.c b/drivers/ata/pata_optidma.c
index d80b36e209..9764907e8a 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.3" 36#define DRV_VERSION "0.2.4"
37 37
38enum { 38enum {
39 READ_REG = 0, /* index of Read cycle timing register */ 39 READ_REG = 0, /* index of Read cycle timing register */
@@ -360,8 +360,10 @@ static struct scsi_host_template optidma_sht = {
360 .slave_configure = ata_scsi_slave_config, 360 .slave_configure = ata_scsi_slave_config,
361 .slave_destroy = ata_scsi_slave_destroy, 361 .slave_destroy = ata_scsi_slave_destroy,
362 .bios_param = ata_std_bios_param, 362 .bios_param = ata_std_bios_param,
363#ifdef CONFIG_PM
363 .resume = ata_scsi_device_resume, 364 .resume = ata_scsi_device_resume,
364 .suspend = ata_scsi_device_suspend, 365 .suspend = ata_scsi_device_suspend,
366#endif
365}; 367};
366 368
367static struct ata_port_operations optidma_port_ops = { 369static struct ata_port_operations optidma_port_ops = {
@@ -524,8 +526,10 @@ static struct pci_driver optidma_pci_driver = {
524 .id_table = optidma, 526 .id_table = optidma,
525 .probe = optidma_init_one, 527 .probe = optidma_init_one,
526 .remove = ata_pci_remove_one, 528 .remove = ata_pci_remove_one,
529#ifdef CONFIG_PM
527 .suspend = ata_pci_device_suspend, 530 .suspend = ata_pci_device_suspend,
528 .resume = ata_pci_device_resume, 531 .resume = ata_pci_device_resume,
532#endif
529}; 533};
530 534
531static int __init optidma_init(void) 535static int __init optidma_init(void)
diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c
index 36468ec645..103720f873 100644
--- a/drivers/ata/pata_pcmcia.c
+++ b/drivers/ata/pata_pcmcia.c
@@ -42,7 +42,7 @@
42 42
43 43
44#define DRV_NAME "pata_pcmcia" 44#define DRV_NAME "pata_pcmcia"
45#define DRV_VERSION "0.2.11" 45#define DRV_VERSION "0.3.0"
46 46
47/* 47/*
48 * Private data structure to glue stuff together 48 * Private data structure to glue stuff together
@@ -308,7 +308,6 @@ static void pcmcia_remove_one(struct pcmcia_device *pdev)
308 if (info->ndev) { 308 if (info->ndev) {
309 struct ata_host *host = dev_get_drvdata(dev); 309 struct ata_host *host = dev_get_drvdata(dev);
310 ata_host_detach(host); 310 ata_host_detach(host);
311 dev_set_drvdata(dev, NULL);
312 } 311 }
313 info->ndev = 0; 312 info->ndev = 0;
314 pdev->priv = NULL; 313 pdev->priv = NULL;
@@ -320,14 +319,17 @@ static void pcmcia_remove_one(struct pcmcia_device *pdev)
320static struct pcmcia_device_id pcmcia_devices[] = { 319static struct pcmcia_device_id pcmcia_devices[] = {
321 PCMCIA_DEVICE_FUNC_ID(4), 320 PCMCIA_DEVICE_FUNC_ID(4),
322 PCMCIA_DEVICE_MANF_CARD(0x0007, 0x0000), /* Hitachi */ 321 PCMCIA_DEVICE_MANF_CARD(0x0007, 0x0000), /* Hitachi */
322 PCMCIA_DEVICE_MANF_CARD(0x000a, 0x0000), /* I-O Data CFA */
323 PCMCIA_DEVICE_MANF_CARD(0x001c, 0x0001), /* Mitsubishi CFA */
323 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704), 324 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704),
324 PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401), 325 PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401), /* SanDisk CFA */
325 PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000), /* Toshiba */ 326 PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000), /* Toshiba */
326 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d), 327 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d),
327 PCMCIA_DEVICE_MANF_CARD(0x00ce, 0x0000), /* Samsung */ 328 PCMCIA_DEVICE_MANF_CARD(0x00ce, 0x0000), /* Samsung */
328 PCMCIA_DEVICE_MANF_CARD(0x0319, 0x0000), /* Hitachi */ 329 PCMCIA_DEVICE_MANF_CARD(0x0319, 0x0000), /* Hitachi */
329 PCMCIA_DEVICE_MANF_CARD(0x2080, 0x0001), 330 PCMCIA_DEVICE_MANF_CARD(0x2080, 0x0001),
330 PCMCIA_DEVICE_MANF_CARD(0x4e01, 0x0200), /* Lexar */ 331 PCMCIA_DEVICE_MANF_CARD(0x4e01, 0x0100), /* Viking CFA */
332 PCMCIA_DEVICE_MANF_CARD(0x4e01, 0x0200), /* Lexar, Viking CFA */
331 PCMCIA_DEVICE_PROD_ID123("Caravelle", "PSC-IDE ", "PSC000", 0x8c36137c, 0xd0693ab8, 0x2768a9f0), 333 PCMCIA_DEVICE_PROD_ID123("Caravelle", "PSC-IDE ", "PSC000", 0x8c36137c, 0xd0693ab8, 0x2768a9f0),
332 PCMCIA_DEVICE_PROD_ID123("CDROM", "IDE", "MCD-601p", 0x1b9179ca, 0xede88951, 0x0d902f74), 334 PCMCIA_DEVICE_PROD_ID123("CDROM", "IDE", "MCD-601p", 0x1b9179ca, 0xede88951, 0x0d902f74),
333 PCMCIA_DEVICE_PROD_ID123("PCMCIA", "IDE CARD", "F1", 0x281f1c5d, 0x1907960c, 0xf7fde8b9), 335 PCMCIA_DEVICE_PROD_ID123("PCMCIA", "IDE CARD", "F1", 0x281f1c5d, 0x1907960c, 0xf7fde8b9),
diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c
index 61537873d2..93bcdadb7b 100644
--- a/drivers/ata/pata_pdc2027x.c
+++ b/drivers/ata/pata_pdc2027x.c
@@ -35,7 +35,7 @@
35#include <linux/libata.h> 35#include <linux/libata.h>
36 36
37#define DRV_NAME "pata_pdc2027x" 37#define DRV_NAME "pata_pdc2027x"
38#define DRV_VERSION "0.74-ac5" 38#define DRV_VERSION "0.8"
39#undef PDC_DEBUG 39#undef PDC_DEBUG
40 40
41#ifdef PDC_DEBUG 41#ifdef PDC_DEBUG
diff --git a/drivers/ata/pata_pdc202xx_old.c b/drivers/ata/pata_pdc202xx_old.c
index 6dd63413a5..acdc52cbe3 100644
--- a/drivers/ata/pata_pdc202xx_old.c
+++ b/drivers/ata/pata_pdc202xx_old.c
@@ -2,13 +2,14 @@
2 * pata_pdc202xx_old.c - Promise PDC202xx PATA for new ATA layer 2 * pata_pdc202xx_old.c - Promise PDC202xx PATA for new ATA layer
3 * (C) 2005 Red Hat Inc 3 * (C) 2005 Red Hat Inc
4 * Alan Cox <alan@redhat.com> 4 * Alan Cox <alan@redhat.com>
5 * (C) 2007 Bartlomiej Zolnierkiewicz
5 * 6 *
6 * Based in part on linux/drivers/ide/pci/pdc202xx_old.c 7 * Based in part on linux/drivers/ide/pci/pdc202xx_old.c
7 * 8 *
8 * First cut with LBA48/ATAPI 9 * First cut with LBA48/ATAPI
9 * 10 *
10 * TODO: 11 * TODO:
11 * Channel interlock/reset on both required ? 12 * Channel interlock/reset on both required
12 */ 13 */
13 14
14#include <linux/kernel.h> 15#include <linux/kernel.h>
@@ -21,7 +22,7 @@
21#include <linux/libata.h> 22#include <linux/libata.h>
22 23
23#define DRV_NAME "pata_pdc202xx_old" 24#define DRV_NAME "pata_pdc202xx_old"
24#define DRV_VERSION "0.2.3" 25#define DRV_VERSION "0.4.0"
25 26
26/** 27/**
27 * pdc2024x_pre_reset - probe begin 28 * pdc2024x_pre_reset - probe begin
@@ -76,7 +77,7 @@ static void pdc2026x_error_handler(struct ata_port *ap)
76static void pdc202xx_configure_piomode(struct ata_port *ap, struct ata_device *adev, int pio) 77static void pdc202xx_configure_piomode(struct ata_port *ap, struct ata_device *adev, int pio)
77{ 78{
78 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 79 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
79 int port = 0x60 + 4 * ap->port_no + 2 * adev->devno; 80 int port = 0x60 + 8 * ap->port_no + 4 * adev->devno;
80 static u16 pio_timing[5] = { 81 static u16 pio_timing[5] = {
81 0x0913, 0x050C , 0x0308, 0x0206, 0x0104 82 0x0913, 0x050C , 0x0308, 0x0206, 0x0104
82 }; 83 };
@@ -85,7 +86,7 @@ static void pdc202xx_configure_piomode(struct ata_port *ap, struct ata_device *a
85 pci_read_config_byte(pdev, port, &r_ap); 86 pci_read_config_byte(pdev, port, &r_ap);
86 pci_read_config_byte(pdev, port + 1, &r_bp); 87 pci_read_config_byte(pdev, port + 1, &r_bp);
87 r_ap &= ~0x3F; /* Preserve ERRDY_EN, SYNC_IN */ 88 r_ap &= ~0x3F; /* Preserve ERRDY_EN, SYNC_IN */
88 r_bp &= ~0x07; 89 r_bp &= ~0x1F;
89 r_ap |= (pio_timing[pio] >> 8); 90 r_ap |= (pio_timing[pio] >> 8);
90 r_bp |= (pio_timing[pio] & 0xFF); 91 r_bp |= (pio_timing[pio] & 0xFF);
91 92
@@ -123,7 +124,7 @@ static void pdc202xx_set_piomode(struct ata_port *ap, struct ata_device *adev)
123static void pdc202xx_set_dmamode(struct ata_port *ap, struct ata_device *adev) 124static void pdc202xx_set_dmamode(struct ata_port *ap, struct ata_device *adev)
124{ 125{
125 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 126 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
126 int port = 0x60 + 4 * ap->port_no + 2 * adev->devno; 127 int port = 0x60 + 8 * ap->port_no + 4 * adev->devno;
127 static u8 udma_timing[6][2] = { 128 static u8 udma_timing[6][2] = {
128 { 0x60, 0x03 }, /* 33 Mhz Clock */ 129 { 0x60, 0x03 }, /* 33 Mhz Clock */
129 { 0x40, 0x02 }, 130 { 0x40, 0x02 },
@@ -132,12 +133,17 @@ static void pdc202xx_set_dmamode(struct ata_port *ap, struct ata_device *adev)
132 { 0x20, 0x01 }, 133 { 0x20, 0x01 },
133 { 0x20, 0x01 } 134 { 0x20, 0x01 }
134 }; 135 };
136 static u8 mdma_timing[3][2] = {
137 { 0x60, 0x03 },
138 { 0x60, 0x04 },
139 { 0xe0, 0x0f },
140 };
135 u8 r_bp, r_cp; 141 u8 r_bp, r_cp;
136 142
137 pci_read_config_byte(pdev, port + 1, &r_bp); 143 pci_read_config_byte(pdev, port + 1, &r_bp);
138 pci_read_config_byte(pdev, port + 2, &r_cp); 144 pci_read_config_byte(pdev, port + 2, &r_cp);
139 145
140 r_bp &= ~0xF0; 146 r_bp &= ~0xE0;
141 r_cp &= ~0x0F; 147 r_cp &= ~0x0F;
142 148
143 if (adev->dma_mode >= XFER_UDMA_0) { 149 if (adev->dma_mode >= XFER_UDMA_0) {
@@ -147,8 +153,8 @@ static void pdc202xx_set_dmamode(struct ata_port *ap, struct ata_device *adev)
147 153
148 } else { 154 } else {
149 int speed = adev->dma_mode - XFER_MW_DMA_0; 155 int speed = adev->dma_mode - XFER_MW_DMA_0;
150 r_bp |= 0x60; 156 r_bp |= mdma_timing[speed][0];
151 r_cp |= (5 - speed); 157 r_cp |= mdma_timing[speed][1];
152 } 158 }
153 pci_write_config_byte(pdev, port + 1, r_bp); 159 pci_write_config_byte(pdev, port + 1, r_bp);
154 pci_write_config_byte(pdev, port + 2, r_cp); 160 pci_write_config_byte(pdev, port + 2, r_cp);
@@ -267,8 +273,10 @@ static struct scsi_host_template pdc202xx_sht = {
267 .slave_configure = ata_scsi_slave_config, 273 .slave_configure = ata_scsi_slave_config,
268 .slave_destroy = ata_scsi_slave_destroy, 274 .slave_destroy = ata_scsi_slave_destroy,
269 .bios_param = ata_std_bios_param, 275 .bios_param = ata_std_bios_param,
276#ifdef CONFIG_PM
270 .resume = ata_scsi_device_resume, 277 .resume = ata_scsi_device_resume,
271 .suspend = ata_scsi_device_suspend, 278 .suspend = ata_scsi_device_suspend,
279#endif
272}; 280};
273 281
274static struct ata_port_operations pdc2024x_port_ops = { 282static struct ata_port_operations pdc2024x_port_ops = {
@@ -399,8 +407,10 @@ static struct pci_driver pdc202xx_pci_driver = {
399 .id_table = pdc202xx, 407 .id_table = pdc202xx,
400 .probe = pdc202xx_init_one, 408 .probe = pdc202xx_init_one,
401 .remove = ata_pci_remove_one, 409 .remove = ata_pci_remove_one,
410#ifdef CONFIG_PM
402 .suspend = ata_pci_device_suspend, 411 .suspend = ata_pci_device_suspend,
403 .resume = ata_pci_device_resume, 412 .resume = ata_pci_device_resume,
413#endif
404}; 414};
405 415
406static int __init pdc202xx_init(void) 416static int __init pdc202xx_init(void)
diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
index 479a326114..4b82a5435a 100644
--- a/drivers/ata/pata_platform.c
+++ b/drivers/ata/pata_platform.c
@@ -42,6 +42,7 @@ static int pata_platform_set_mode(struct ata_port *ap, struct ata_device **unuse
42 dev->pio_mode = dev->xfer_mode = XFER_PIO_0; 42 dev->pio_mode = dev->xfer_mode = XFER_PIO_0;
43 dev->xfer_shift = ATA_SHIFT_PIO; 43 dev->xfer_shift = ATA_SHIFT_PIO;
44 dev->flags |= ATA_DFLAG_PIO; 44 dev->flags |= ATA_DFLAG_PIO;
45 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
45 } 46 }
46 } 47 }
47 return 0; 48 return 0;
@@ -227,7 +228,6 @@ static int __devexit pata_platform_remove(struct platform_device *pdev)
227 struct ata_host *host = dev_get_drvdata(dev); 228 struct ata_host *host = dev_get_drvdata(dev);
228 229
229 ata_host_detach(host); 230 ata_host_detach(host);
230 dev_set_drvdata(dev, NULL);
231 231
232 return 0; 232 return 0;
233} 233}
diff --git a/drivers/ata/pata_qdi.c b/drivers/ata/pata_qdi.c
index 4362141976..c3810012f3 100644
--- a/drivers/ata/pata_qdi.c
+++ b/drivers/ata/pata_qdi.c
@@ -26,7 +26,7 @@
26#include <linux/platform_device.h> 26#include <linux/platform_device.h>
27 27
28#define DRV_NAME "pata_qdi" 28#define DRV_NAME "pata_qdi"
29#define DRV_VERSION "0.2.4" 29#define DRV_VERSION "0.3.0"
30 30
31#define NR_HOST 4 /* Two 6580s */ 31#define NR_HOST 4 /* Two 6580s */
32 32
@@ -363,7 +363,8 @@ static __init int qdi_init(void)
363 release_region(port, 2); 363 release_region(port, 2);
364 continue; 364 continue;
365 } 365 }
366 ct += qdi_init_one(port, 6500, ide_port[r & 0x01], ide_irq[r & 0x01], r & 0x04); 366 if (qdi_init_one(port, 6500, ide_port[r & 0x01], ide_irq[r & 0x01], r & 0x04) == 0)
367 ct++;
367 } 368 }
368 if (((r & 0xF0) == 0xA0) || (r & 0xF0) == 0x50) { 369 if (((r & 0xF0) == 0xA0) || (r & 0xF0) == 0x50) {
369 /* QD6580: dual channel */ 370 /* QD6580: dual channel */
@@ -375,11 +376,14 @@ static __init int qdi_init(void)
375 res = inb(port + 3); 376 res = inb(port + 3);
376 if (res & 1) { 377 if (res & 1) {
377 /* Single channel mode */ 378 /* Single channel mode */
378 ct += qdi_init_one(port, 6580, ide_port[r & 0x01], ide_irq[r & 0x01], r & 0x04); 379 if (qdi_init_one(port, 6580, ide_port[r & 0x01], ide_irq[r & 0x01], r & 0x04))
380 ct++;
379 } else { 381 } else {
380 /* Dual channel mode */ 382 /* Dual channel mode */
381 ct += qdi_init_one(port, 6580, 0x1F0, 14, r & 0x04); 383 if (qdi_init_one(port, 6580, 0x1F0, 14, r & 0x04) == 0)
382 ct += qdi_init_one(port + 2, 6580, 0x170, 15, r & 0x04); 384 ct++;
385 if (qdi_init_one(port + 2, 6580, 0x170, 15, r & 0x04) == 0)
386 ct++;
383 } 387 }
384 } 388 }
385 } 389 }
diff --git a/drivers/ata/pata_radisys.c b/drivers/ata/pata_radisys.c
index 0d1e571ef6..9a9132c9e3 100644
--- a/drivers/ata/pata_radisys.c
+++ b/drivers/ata/pata_radisys.c
@@ -228,8 +228,10 @@ static struct scsi_host_template radisys_sht = {
228 .slave_configure = ata_scsi_slave_config, 228 .slave_configure = ata_scsi_slave_config,
229 .slave_destroy = ata_scsi_slave_destroy, 229 .slave_destroy = ata_scsi_slave_destroy,
230 .bios_param = ata_std_bios_param, 230 .bios_param = ata_std_bios_param,
231#ifdef CONFIG_PM
231 .resume = ata_scsi_device_resume, 232 .resume = ata_scsi_device_resume,
232 .suspend = ata_scsi_device_suspend, 233 .suspend = ata_scsi_device_suspend,
234#endif
233}; 235};
234 236
235static const struct ata_port_operations radisys_pata_ops = { 237static const struct ata_port_operations radisys_pata_ops = {
@@ -312,8 +314,10 @@ static struct pci_driver radisys_pci_driver = {
312 .id_table = radisys_pci_tbl, 314 .id_table = radisys_pci_tbl,
313 .probe = radisys_init_one, 315 .probe = radisys_init_one,
314 .remove = ata_pci_remove_one, 316 .remove = ata_pci_remove_one,
317#ifdef CONFIG_PM
315 .suspend = ata_pci_device_suspend, 318 .suspend = ata_pci_device_suspend,
316 .resume = ata_pci_device_resume, 319 .resume = ata_pci_device_resume,
320#endif
317}; 321};
318 322
319static int __init radisys_init(void) 323static int __init radisys_init(void)
diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c
index 71a2bac09e..f522daa2a6 100644
--- a/drivers/ata/pata_rz1000.c
+++ b/drivers/ata/pata_rz1000.c
@@ -71,6 +71,7 @@ static int rz1000_set_mode(struct ata_port *ap, struct ata_device **unused)
71 dev->xfer_mode = XFER_PIO_0; 71 dev->xfer_mode = XFER_PIO_0;
72 dev->xfer_shift = ATA_SHIFT_PIO; 72 dev->xfer_shift = ATA_SHIFT_PIO;
73 dev->flags |= ATA_DFLAG_PIO; 73 dev->flags |= ATA_DFLAG_PIO;
74 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
74 } 75 }
75 } 76 }
76 return 0; 77 return 0;
@@ -93,8 +94,10 @@ static struct scsi_host_template rz1000_sht = {
93 .slave_configure = ata_scsi_slave_config, 94 .slave_configure = ata_scsi_slave_config,
94 .slave_destroy = ata_scsi_slave_destroy, 95 .slave_destroy = ata_scsi_slave_destroy,
95 .bios_param = ata_std_bios_param, 96 .bios_param = ata_std_bios_param,
97#ifdef CONFIG_PM
96 .resume = ata_scsi_device_resume, 98 .resume = ata_scsi_device_resume,
97 .suspend = ata_scsi_device_suspend, 99 .suspend = ata_scsi_device_suspend,
100#endif
98}; 101};
99 102
100static struct ata_port_operations rz1000_port_ops = { 103static struct ata_port_operations rz1000_port_ops = {
@@ -177,6 +180,7 @@ static int rz1000_init_one (struct pci_dev *pdev, const struct pci_device_id *en
177 return -ENODEV; 180 return -ENODEV;
178} 181}
179 182
183#ifdef CONFIG_PM
180static int rz1000_reinit_one(struct pci_dev *pdev) 184static int rz1000_reinit_one(struct pci_dev *pdev)
181{ 185{
182 /* If this fails on resume (which is a "cant happen" case), we 186 /* If this fails on resume (which is a "cant happen" case), we
@@ -185,6 +189,7 @@ static int rz1000_reinit_one(struct pci_dev *pdev)
185 panic("rz1000 fifo"); 189 panic("rz1000 fifo");
186 return ata_pci_device_resume(pdev); 190 return ata_pci_device_resume(pdev);
187} 191}
192#endif
188 193
189static const struct pci_device_id pata_rz1000[] = { 194static const struct pci_device_id pata_rz1000[] = {
190 { PCI_VDEVICE(PCTECH, PCI_DEVICE_ID_PCTECH_RZ1000), }, 195 { PCI_VDEVICE(PCTECH, PCI_DEVICE_ID_PCTECH_RZ1000), },
@@ -198,8 +203,10 @@ static struct pci_driver rz1000_pci_driver = {
198 .id_table = pata_rz1000, 203 .id_table = pata_rz1000,
199 .probe = rz1000_init_one, 204 .probe = rz1000_init_one,
200 .remove = ata_pci_remove_one, 205 .remove = ata_pci_remove_one,
206#ifdef CONFIG_PM
201 .suspend = ata_pci_device_suspend, 207 .suspend = ata_pci_device_suspend,
202 .resume = rz1000_reinit_one, 208 .resume = rz1000_reinit_one,
209#endif
203}; 210};
204 211
205static int __init rz1000_init(void) 212static int __init rz1000_init(void)
diff --git a/drivers/ata/pata_sc1200.c b/drivers/ata/pata_sc1200.c
index 58e42fbd14..93b3ed0f9e 100644
--- a/drivers/ata/pata_sc1200.c
+++ b/drivers/ata/pata_sc1200.c
@@ -194,8 +194,10 @@ static struct scsi_host_template sc1200_sht = {
194 .slave_configure = ata_scsi_slave_config, 194 .slave_configure = ata_scsi_slave_config,
195 .slave_destroy = ata_scsi_slave_destroy, 195 .slave_destroy = ata_scsi_slave_destroy,
196 .bios_param = ata_std_bios_param, 196 .bios_param = ata_std_bios_param,
197#ifdef CONFIG_PM
197 .resume = ata_scsi_device_resume, 198 .resume = ata_scsi_device_resume,
198 .suspend = ata_scsi_device_suspend, 199 .suspend = ata_scsi_device_suspend,
200#endif
199}; 201};
200 202
201static struct ata_port_operations sc1200_port_ops = { 203static struct ata_port_operations sc1200_port_ops = {
@@ -210,7 +212,10 @@ static struct ata_port_operations sc1200_port_ops = {
210 .exec_command = ata_exec_command, 212 .exec_command = ata_exec_command,
211 .dev_select = ata_std_dev_select, 213 .dev_select = ata_std_dev_select,
212 214
215 .freeze = ata_bmdma_freeze,
216 .thaw = ata_bmdma_thaw,
213 .error_handler = ata_bmdma_error_handler, 217 .error_handler = ata_bmdma_error_handler,
218 .post_internal_cmd = ata_bmdma_post_internal_cmd,
214 219
215 .bmdma_setup = ata_bmdma_setup, 220 .bmdma_setup = ata_bmdma_setup,
216 .bmdma_start = ata_bmdma_start, 221 .bmdma_start = ata_bmdma_start,
@@ -266,8 +271,10 @@ static struct pci_driver sc1200_pci_driver = {
266 .id_table = sc1200, 271 .id_table = sc1200,
267 .probe = sc1200_init_one, 272 .probe = sc1200_init_one,
268 .remove = ata_pci_remove_one, 273 .remove = ata_pci_remove_one,
274#ifdef CONFIG_PM
269 .suspend = ata_pci_device_suspend, 275 .suspend = ata_pci_device_suspend,
270 .resume = ata_pci_device_resume, 276 .resume = ata_pci_device_resume,
277#endif
271}; 278};
272 279
273static int __init sc1200_init(void) 280static int __init sc1200_init(void)
diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c
new file mode 100644
index 0000000000..f3ed141fdc
--- /dev/null
+++ b/drivers/ata/pata_scc.c
@@ -0,0 +1,1230 @@
1/*
2 * Support for IDE interfaces on Celleb platform
3 *
4 * (C) Copyright 2006 TOSHIBA CORPORATION
5 *
6 * This code is based on drivers/ata/ata_piix.c:
7 * Copyright 2003-2005 Red Hat Inc
8 * Copyright 2003-2005 Jeff Garzik
9 * Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer
10 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
11 * Copyright (C) 2003 Red Hat Inc <alan@redhat.com>
12 *
13 * and drivers/ata/ahci.c:
14 * Copyright 2004-2005 Red Hat, Inc.
15 *
16 * and drivers/ata/libata-core.c:
17 * Copyright 2003-2004 Red Hat, Inc. All rights reserved.
18 * Copyright 2003-2004 Jeff Garzik
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License along
31 * with this program; if not, write to the Free Software Foundation, Inc.,
32 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 */
34
35#include <linux/kernel.h>
36#include <linux/module.h>
37#include <linux/pci.h>
38#include <linux/init.h>
39#include <linux/blkdev.h>
40#include <linux/delay.h>
41#include <linux/device.h>
42#include <scsi/scsi_host.h>
43#include <linux/libata.h>
44
45#define DRV_NAME "pata_scc"
46#define DRV_VERSION "0.1"
47
48#define PCI_DEVICE_ID_TOSHIBA_SCC_ATA 0x01b4
49
50/* PCI BARs */
51#define SCC_CTRL_BAR 0
52#define SCC_BMID_BAR 1
53
54/* offset of CTRL registers */
55#define SCC_CTL_PIOSHT 0x000
56#define SCC_CTL_PIOCT 0x004
57#define SCC_CTL_MDMACT 0x008
58#define SCC_CTL_MCRCST 0x00C
59#define SCC_CTL_SDMACT 0x010
60#define SCC_CTL_SCRCST 0x014
61#define SCC_CTL_UDENVT 0x018
62#define SCC_CTL_TDVHSEL 0x020
63#define SCC_CTL_MODEREG 0x024
64#define SCC_CTL_ECMODE 0xF00
65#define SCC_CTL_MAEA0 0xF50
66#define SCC_CTL_MAEC0 0xF54
67#define SCC_CTL_CCKCTRL 0xFF0
68
69/* offset of BMID registers */
70#define SCC_DMA_CMD 0x000
71#define SCC_DMA_STATUS 0x004
72#define SCC_DMA_TABLE_OFS 0x008
73#define SCC_DMA_INTMASK 0x010
74#define SCC_DMA_INTST 0x014
75#define SCC_DMA_PTERADD 0x018
76#define SCC_REG_CMD_ADDR 0x020
77#define SCC_REG_DATA 0x000
78#define SCC_REG_ERR 0x004
79#define SCC_REG_FEATURE 0x004
80#define SCC_REG_NSECT 0x008
81#define SCC_REG_LBAL 0x00C
82#define SCC_REG_LBAM 0x010
83#define SCC_REG_LBAH 0x014
84#define SCC_REG_DEVICE 0x018
85#define SCC_REG_STATUS 0x01C
86#define SCC_REG_CMD 0x01C
87#define SCC_REG_ALTSTATUS 0x020
88
89/* register value */
90#define TDVHSEL_MASTER 0x00000001
91#define TDVHSEL_SLAVE 0x00000004
92
93#define MODE_JCUSFEN 0x00000080
94
95#define ECMODE_VALUE 0x01
96
97#define CCKCTRL_ATARESET 0x00040000
98#define CCKCTRL_BUFCNT 0x00020000
99#define CCKCTRL_CRST 0x00010000
100#define CCKCTRL_OCLKEN 0x00000100
101#define CCKCTRL_ATACLKOEN 0x00000002
102#define CCKCTRL_LCLKEN 0x00000001
103
104#define QCHCD_IOS_SS 0x00000001
105
106#define QCHSD_STPDIAG 0x00020000
107
108#define INTMASK_MSK 0xD1000012
109#define INTSTS_SERROR 0x80000000
110#define INTSTS_PRERR 0x40000000
111#define INTSTS_RERR 0x10000000
112#define INTSTS_ICERR 0x01000000
113#define INTSTS_BMSINT 0x00000010
114#define INTSTS_BMHE 0x00000008
115#define INTSTS_IOIRQS 0x00000004
116#define INTSTS_INTRQ 0x00000002
117#define INTSTS_ACTEINT 0x00000001
118
119
120/* PIO transfer mode table */
121/* JCHST */
122static const unsigned long JCHSTtbl[2][7] = {
123 {0x0E, 0x05, 0x02, 0x03, 0x02, 0x00, 0x00}, /* 100MHz */
124 {0x13, 0x07, 0x04, 0x04, 0x03, 0x00, 0x00} /* 133MHz */
125};
126
127/* JCHHT */
128static const unsigned long JCHHTtbl[2][7] = {
129 {0x0E, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00}, /* 100MHz */
130 {0x13, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00} /* 133MHz */
131};
132
133/* JCHCT */
134static const unsigned long JCHCTtbl[2][7] = {
135 {0x1D, 0x1D, 0x1C, 0x0B, 0x06, 0x00, 0x00}, /* 100MHz */
136 {0x27, 0x26, 0x26, 0x0E, 0x09, 0x00, 0x00} /* 133MHz */
137};
138
139/* DMA transfer mode table */
140/* JCHDCTM/JCHDCTS */
141static const unsigned long JCHDCTxtbl[2][7] = {
142 {0x0A, 0x06, 0x04, 0x03, 0x01, 0x00, 0x00}, /* 100MHz */
143 {0x0E, 0x09, 0x06, 0x04, 0x02, 0x01, 0x00} /* 133MHz */
144};
145
146/* JCSTWTM/JCSTWTS */
147static const unsigned long JCSTWTxtbl[2][7] = {
148 {0x06, 0x04, 0x03, 0x02, 0x02, 0x02, 0x00}, /* 100MHz */
149 {0x09, 0x06, 0x04, 0x02, 0x02, 0x02, 0x02} /* 133MHz */
150};
151
152/* JCTSS */
153static const unsigned long JCTSStbl[2][7] = {
154 {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00}, /* 100MHz */
155 {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05} /* 133MHz */
156};
157
158/* JCENVT */
159static const unsigned long JCENVTtbl[2][7] = {
160 {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00}, /* 100MHz */
161 {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02} /* 133MHz */
162};
163
164/* JCACTSELS/JCACTSELM */
165static const unsigned long JCACTSELtbl[2][7] = {
166 {0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00}, /* 100MHz */
167 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} /* 133MHz */
168};
169
170static const struct pci_device_id scc_pci_tbl[] = {
171 {PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_SCC_ATA,
172 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
173 { } /* terminate list */
174};
175
176/**
177 * scc_set_piomode - Initialize host controller PATA PIO timings
178 * @ap: Port whose timings we are configuring
179 * @adev: um
180 *
181 * Set PIO mode for device.
182 *
183 * LOCKING:
184 * None (inherited from caller).
185 */
186
187static void scc_set_piomode (struct ata_port *ap, struct ata_device *adev)
188{
189 unsigned int pio = adev->pio_mode - XFER_PIO_0;
190 void __iomem *ctrl_base = ap->host->iomap[SCC_CTRL_BAR];
191 void __iomem *cckctrl_port = ctrl_base + SCC_CTL_CCKCTRL;
192 void __iomem *piosht_port = ctrl_base + SCC_CTL_PIOSHT;
193 void __iomem *pioct_port = ctrl_base + SCC_CTL_PIOCT;
194 unsigned long reg;
195 int offset;
196
197 reg = in_be32(cckctrl_port);
198 if (reg & CCKCTRL_ATACLKOEN)
199 offset = 1; /* 133MHz */
200 else
201 offset = 0; /* 100MHz */
202
203 reg = JCHSTtbl[offset][pio] << 16 | JCHHTtbl[offset][pio];
204 out_be32(piosht_port, reg);
205 reg = JCHCTtbl[offset][pio];
206 out_be32(pioct_port, reg);
207}
208
209/**
210 * scc_set_dmamode - Initialize host controller PATA DMA timings
211 * @ap: Port whose timings we are configuring
212 * @adev: um
213 * @udma: udma mode, 0 - 6
214 *
215 * Set UDMA mode for device.
216 *
217 * LOCKING:
218 * None (inherited from caller).
219 */
220
221static void scc_set_dmamode (struct ata_port *ap, struct ata_device *adev)
222{
223 unsigned int udma = adev->dma_mode;
224 unsigned int is_slave = (adev->devno != 0);
225 u8 speed = udma;
226 void __iomem *ctrl_base = ap->host->iomap[SCC_CTRL_BAR];
227 void __iomem *cckctrl_port = ctrl_base + SCC_CTL_CCKCTRL;
228 void __iomem *mdmact_port = ctrl_base + SCC_CTL_MDMACT;
229 void __iomem *mcrcst_port = ctrl_base + SCC_CTL_MCRCST;
230 void __iomem *sdmact_port = ctrl_base + SCC_CTL_SDMACT;
231 void __iomem *scrcst_port = ctrl_base + SCC_CTL_SCRCST;
232 void __iomem *udenvt_port = ctrl_base + SCC_CTL_UDENVT;
233 void __iomem *tdvhsel_port = ctrl_base + SCC_CTL_TDVHSEL;
234 int offset, idx;
235
236 if (in_be32(cckctrl_port) & CCKCTRL_ATACLKOEN)
237 offset = 1; /* 133MHz */
238 else
239 offset = 0; /* 100MHz */
240
241 if (speed >= XFER_UDMA_0)
242 idx = speed - XFER_UDMA_0;
243 else
244 return;
245
246 if (is_slave) {
247 out_be32(sdmact_port, JCHDCTxtbl[offset][idx]);
248 out_be32(scrcst_port, JCSTWTxtbl[offset][idx]);
249 out_be32(tdvhsel_port,
250 (in_be32(tdvhsel_port) & ~TDVHSEL_SLAVE) | (JCACTSELtbl[offset][idx] << 2));
251 } else {
252 out_be32(mdmact_port, JCHDCTxtbl[offset][idx]);
253 out_be32(mcrcst_port, JCSTWTxtbl[offset][idx]);
254 out_be32(tdvhsel_port,
255 (in_be32(tdvhsel_port) & ~TDVHSEL_MASTER) | JCACTSELtbl[offset][idx]);
256 }
257 out_be32(udenvt_port,
258 JCTSStbl[offset][idx] << 16 | JCENVTtbl[offset][idx]);
259}
260
261/**
262 * scc_tf_load - send taskfile registers to host controller
263 * @ap: Port to which output is sent
264 * @tf: ATA taskfile register set
265 *
266 * Note: Original code is ata_tf_load().
267 */
268
269static void scc_tf_load (struct ata_port *ap, const struct ata_taskfile *tf)
270{
271 struct ata_ioports *ioaddr = &ap->ioaddr;
272 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
273
274 if (tf->ctl != ap->last_ctl) {
275 out_be32(ioaddr->ctl_addr, tf->ctl);
276 ap->last_ctl = tf->ctl;
277 ata_wait_idle(ap);
278 }
279
280 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
281 out_be32(ioaddr->feature_addr, tf->hob_feature);
282 out_be32(ioaddr->nsect_addr, tf->hob_nsect);
283 out_be32(ioaddr->lbal_addr, tf->hob_lbal);
284 out_be32(ioaddr->lbam_addr, tf->hob_lbam);
285 out_be32(ioaddr->lbah_addr, tf->hob_lbah);
286 VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",
287 tf->hob_feature,
288 tf->hob_nsect,
289 tf->hob_lbal,
290 tf->hob_lbam,
291 tf->hob_lbah);
292 }
293
294 if (is_addr) {
295 out_be32(ioaddr->feature_addr, tf->feature);
296 out_be32(ioaddr->nsect_addr, tf->nsect);
297 out_be32(ioaddr->lbal_addr, tf->lbal);
298 out_be32(ioaddr->lbam_addr, tf->lbam);
299 out_be32(ioaddr->lbah_addr, tf->lbah);
300 VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
301 tf->feature,
302 tf->nsect,
303 tf->lbal,
304 tf->lbam,
305 tf->lbah);
306 }
307
308 if (tf->flags & ATA_TFLAG_DEVICE) {
309 out_be32(ioaddr->device_addr, tf->device);
310 VPRINTK("device 0x%X\n", tf->device);
311 }
312
313 ata_wait_idle(ap);
314}
315
316/**
317 * scc_check_status - Read device status reg & clear interrupt
318 * @ap: port where the device is
319 *
320 * Note: Original code is ata_check_status().
321 */
322
323static u8 scc_check_status (struct ata_port *ap)
324{
325 return in_be32(ap->ioaddr.status_addr);
326}
327
328/**
329 * scc_tf_read - input device's ATA taskfile shadow registers
330 * @ap: Port from which input is read
331 * @tf: ATA taskfile register set for storing input
332 *
333 * Note: Original code is ata_tf_read().
334 */
335
336static void scc_tf_read (struct ata_port *ap, struct ata_taskfile *tf)
337{
338 struct ata_ioports *ioaddr = &ap->ioaddr;
339
340 tf->command = scc_check_status(ap);
341 tf->feature = in_be32(ioaddr->error_addr);
342 tf->nsect = in_be32(ioaddr->nsect_addr);
343 tf->lbal = in_be32(ioaddr->lbal_addr);
344 tf->lbam = in_be32(ioaddr->lbam_addr);
345 tf->lbah = in_be32(ioaddr->lbah_addr);
346 tf->device = in_be32(ioaddr->device_addr);
347
348 if (tf->flags & ATA_TFLAG_LBA48) {
349 out_be32(ioaddr->ctl_addr, tf->ctl | ATA_HOB);
350 tf->hob_feature = in_be32(ioaddr->error_addr);
351 tf->hob_nsect = in_be32(ioaddr->nsect_addr);
352 tf->hob_lbal = in_be32(ioaddr->lbal_addr);
353 tf->hob_lbam = in_be32(ioaddr->lbam_addr);
354 tf->hob_lbah = in_be32(ioaddr->lbah_addr);
355 }
356}
357
358/**
359 * scc_exec_command - issue ATA command to host controller
360 * @ap: port to which command is being issued
361 * @tf: ATA taskfile register set
362 *
363 * Note: Original code is ata_exec_command().
364 */
365
366static void scc_exec_command (struct ata_port *ap,
367 const struct ata_taskfile *tf)
368{
369 DPRINTK("ata%u: cmd 0x%X\n", ap->print_id, tf->command);
370
371 out_be32(ap->ioaddr.command_addr, tf->command);
372 ata_pause(ap);
373}
374
375/**
376 * scc_check_altstatus - Read device alternate status reg
377 * @ap: port where the device is
378 */
379
380static u8 scc_check_altstatus (struct ata_port *ap)
381{
382 return in_be32(ap->ioaddr.altstatus_addr);
383}
384
385/**
386 * scc_std_dev_select - Select device 0/1 on ATA bus
387 * @ap: ATA channel to manipulate
388 * @device: ATA device (numbered from zero) to select
389 *
390 * Note: Original code is ata_std_dev_select().
391 */
392
393static void scc_std_dev_select (struct ata_port *ap, unsigned int device)
394{
395 u8 tmp;
396
397 if (device == 0)
398 tmp = ATA_DEVICE_OBS;
399 else
400 tmp = ATA_DEVICE_OBS | ATA_DEV1;
401
402 out_be32(ap->ioaddr.device_addr, tmp);
403 ata_pause(ap);
404}
405
406/**
407 * scc_bmdma_setup - Set up PCI IDE BMDMA transaction
408 * @qc: Info associated with this ATA transaction.
409 *
410 * Note: Original code is ata_bmdma_setup().
411 */
412
413static void scc_bmdma_setup (struct ata_queued_cmd *qc)
414{
415 struct ata_port *ap = qc->ap;
416 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
417 u8 dmactl;
418 void __iomem *mmio = ap->ioaddr.bmdma_addr;
419
420 /* load PRD table addr */
421 out_be32(mmio + SCC_DMA_TABLE_OFS, ap->prd_dma);
422
423 /* specify data direction, triple-check start bit is clear */
424 dmactl = in_be32(mmio + SCC_DMA_CMD);
425 dmactl &= ~(ATA_DMA_WR | ATA_DMA_START);
426 if (!rw)
427 dmactl |= ATA_DMA_WR;
428 out_be32(mmio + SCC_DMA_CMD, dmactl);
429
430 /* issue r/w command */
431 ap->ops->exec_command(ap, &qc->tf);
432}
433
434/**
435 * scc_bmdma_start - Start a PCI IDE BMDMA transaction
436 * @qc: Info associated with this ATA transaction.
437 *
438 * Note: Original code is ata_bmdma_start().
439 */
440
441static void scc_bmdma_start (struct ata_queued_cmd *qc)
442{
443 struct ata_port *ap = qc->ap;
444 u8 dmactl;
445 void __iomem *mmio = ap->ioaddr.bmdma_addr;
446
447 /* start host DMA transaction */
448 dmactl = in_be32(mmio + SCC_DMA_CMD);
449 out_be32(mmio + SCC_DMA_CMD, dmactl | ATA_DMA_START);
450}
451
452/**
453 * scc_devchk - PATA device presence detection
454 * @ap: ATA channel to examine
455 * @device: Device to examine (starting at zero)
456 *
457 * Note: Original code is ata_devchk().
458 */
459
460static unsigned int scc_devchk (struct ata_port *ap,
461 unsigned int device)
462{
463 struct ata_ioports *ioaddr = &ap->ioaddr;
464 u8 nsect, lbal;
465
466 ap->ops->dev_select(ap, device);
467
468 out_be32(ioaddr->nsect_addr, 0x55);
469 out_be32(ioaddr->lbal_addr, 0xaa);
470
471 out_be32(ioaddr->nsect_addr, 0xaa);
472 out_be32(ioaddr->lbal_addr, 0x55);
473
474 out_be32(ioaddr->nsect_addr, 0x55);
475 out_be32(ioaddr->lbal_addr, 0xaa);
476
477 nsect = in_be32(ioaddr->nsect_addr);
478 lbal = in_be32(ioaddr->lbal_addr);
479
480 if ((nsect == 0x55) && (lbal == 0xaa))
481 return 1; /* we found a device */
482
483 return 0; /* nothing found */
484}
485
486/**
487 * scc_bus_post_reset - PATA device post reset
488 *
489 * Note: Original code is ata_bus_post_reset().
490 */
491
492static void scc_bus_post_reset (struct ata_port *ap, unsigned int devmask)
493{
494 struct ata_ioports *ioaddr = &ap->ioaddr;
495 unsigned int dev0 = devmask & (1 << 0);
496 unsigned int dev1 = devmask & (1 << 1);
497 unsigned long timeout;
498
499 /* if device 0 was found in ata_devchk, wait for its
500 * BSY bit to clear
501 */
502 if (dev0)
503 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
504
505 /* if device 1 was found in ata_devchk, wait for
506 * register access, then wait for BSY to clear
507 */
508 timeout = jiffies + ATA_TMOUT_BOOT;
509 while (dev1) {
510 u8 nsect, lbal;
511
512 ap->ops->dev_select(ap, 1);
513 nsect = in_be32(ioaddr->nsect_addr);
514 lbal = in_be32(ioaddr->lbal_addr);
515 if ((nsect == 1) && (lbal == 1))
516 break;
517 if (time_after(jiffies, timeout)) {
518 dev1 = 0;
519 break;
520 }
521 msleep(50); /* give drive a breather */
522 }
523 if (dev1)
524 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
525
526 /* is all this really necessary? */
527 ap->ops->dev_select(ap, 0);
528 if (dev1)
529 ap->ops->dev_select(ap, 1);
530 if (dev0)
531 ap->ops->dev_select(ap, 0);
532}
533
534/**
535 * scc_bus_softreset - PATA device software reset
536 *
537 * Note: Original code is ata_bus_softreset().
538 */
539
540static unsigned int scc_bus_softreset (struct ata_port *ap,
541 unsigned int devmask)
542{
543 struct ata_ioports *ioaddr = &ap->ioaddr;
544
545 DPRINTK("ata%u: bus reset via SRST\n", ap->print_id);
546
547 /* software reset. causes dev0 to be selected */
548 out_be32(ioaddr->ctl_addr, ap->ctl);
549 udelay(20);
550 out_be32(ioaddr->ctl_addr, ap->ctl | ATA_SRST);
551 udelay(20);
552 out_be32(ioaddr->ctl_addr, ap->ctl);
553
554 /* spec mandates ">= 2ms" before checking status.
555 * We wait 150ms, because that was the magic delay used for
556 * ATAPI devices in Hale Landis's ATADRVR, for the period of time
557 * between when the ATA command register is written, and then
558 * status is checked. Because waiting for "a while" before
559 * checking status is fine, post SRST, we perform this magic
560 * delay here as well.
561 *
562 * Old drivers/ide uses the 2mS rule and then waits for ready
563 */
564 msleep(150);
565
566 /* Before we perform post reset processing we want to see if
567 * the bus shows 0xFF because the odd clown forgets the D7
568 * pulldown resistor.
569 */
570 if (scc_check_status(ap) == 0xFF)
571 return 0;
572
573 scc_bus_post_reset(ap, devmask);
574
575 return 0;
576}
577
578/**
579 * scc_std_softreset - reset host port via ATA SRST
580 * @ap: port to reset
581 * @classes: resulting classes of attached devices
582 *
583 * Note: Original code is ata_std_softreset().
584 */
585
586static int scc_std_softreset (struct ata_port *ap, unsigned int *classes)
587{
588 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
589 unsigned int devmask = 0, err_mask;
590 u8 err;
591
592 DPRINTK("ENTER\n");
593
594 if (ata_port_offline(ap)) {
595 classes[0] = ATA_DEV_NONE;
596 goto out;
597 }
598
599 /* determine if device 0/1 are present */
600 if (scc_devchk(ap, 0))
601 devmask |= (1 << 0);
602 if (slave_possible && scc_devchk(ap, 1))
603 devmask |= (1 << 1);
604
605 /* select device 0 again */
606 ap->ops->dev_select(ap, 0);
607
608 /* issue bus reset */
609 DPRINTK("about to softreset, devmask=%x\n", devmask);
610 err_mask = scc_bus_softreset(ap, devmask);
611 if (err_mask) {
612 ata_port_printk(ap, KERN_ERR, "SRST failed (err_mask=0x%x)\n",
613 err_mask);
614 return -EIO;
615 }
616
617 /* determine by signature whether we have ATA or ATAPI devices */
618 classes[0] = ata_dev_try_classify(ap, 0, &err);
619 if (slave_possible && err != 0x81)
620 classes[1] = ata_dev_try_classify(ap, 1, &err);
621
622 out:
623 DPRINTK("EXIT, classes[0]=%u [1]=%u\n", classes[0], classes[1]);
624 return 0;
625}
626
627/**
628 * scc_bmdma_stop - Stop PCI IDE BMDMA transfer
629 * @qc: Command we are ending DMA for
630 */
631
632static void scc_bmdma_stop (struct ata_queued_cmd *qc)
633{
634 struct ata_port *ap = qc->ap;
635 void __iomem *ctrl_base = ap->host->iomap[SCC_CTRL_BAR];
636 void __iomem *bmid_base = ap->host->iomap[SCC_BMID_BAR];
637 u32 reg;
638
639 while (1) {
640 reg = in_be32(bmid_base + SCC_DMA_INTST);
641
642 if (reg & INTSTS_SERROR) {
643 printk(KERN_WARNING "%s: SERROR\n", DRV_NAME);
644 out_be32(bmid_base + SCC_DMA_INTST, INTSTS_SERROR|INTSTS_BMSINT);
645 out_be32(bmid_base + SCC_DMA_CMD,
646 in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
647 continue;
648 }
649
650 if (reg & INTSTS_PRERR) {
651 u32 maea0, maec0;
652 maea0 = in_be32(ctrl_base + SCC_CTL_MAEA0);
653 maec0 = in_be32(ctrl_base + SCC_CTL_MAEC0);
654 printk(KERN_WARNING "%s: PRERR [addr:%x cmd:%x]\n", DRV_NAME, maea0, maec0);
655 out_be32(bmid_base + SCC_DMA_INTST, INTSTS_PRERR|INTSTS_BMSINT);
656 out_be32(bmid_base + SCC_DMA_CMD,
657 in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
658 continue;
659 }
660
661 if (reg & INTSTS_RERR) {
662 printk(KERN_WARNING "%s: Response Error\n", DRV_NAME);
663 out_be32(bmid_base + SCC_DMA_INTST, INTSTS_RERR|INTSTS_BMSINT);
664 out_be32(bmid_base + SCC_DMA_CMD,
665 in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
666 continue;
667 }
668
669 if (reg & INTSTS_ICERR) {
670 out_be32(bmid_base + SCC_DMA_CMD,
671 in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
672 printk(KERN_WARNING "%s: Illegal Configuration\n", DRV_NAME);
673 out_be32(bmid_base + SCC_DMA_INTST, INTSTS_ICERR|INTSTS_BMSINT);
674 continue;
675 }
676
677 if (reg & INTSTS_BMSINT) {
678 unsigned int classes;
679 printk(KERN_WARNING "%s: Internal Bus Error\n", DRV_NAME);
680 out_be32(bmid_base + SCC_DMA_INTST, INTSTS_BMSINT);
681 /* TBD: SW reset */
682 scc_std_softreset(ap, &classes);
683 continue;
684 }
685
686 if (reg & INTSTS_BMHE) {
687 out_be32(bmid_base + SCC_DMA_INTST, INTSTS_BMHE);
688 continue;
689 }
690
691 if (reg & INTSTS_ACTEINT) {
692 out_be32(bmid_base + SCC_DMA_INTST, INTSTS_ACTEINT);
693 continue;
694 }
695
696 if (reg & INTSTS_IOIRQS) {
697 out_be32(bmid_base + SCC_DMA_INTST, INTSTS_IOIRQS);
698 continue;
699 }
700 break;
701 }
702
703 /* clear start/stop bit */
704 out_be32(bmid_base + SCC_DMA_CMD,
705 in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
706
707 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
708 ata_altstatus(ap); /* dummy read */
709}
710
711/**
712 * scc_bmdma_status - Read PCI IDE BMDMA status
713 * @ap: Port associated with this ATA transaction.
714 */
715
716static u8 scc_bmdma_status (struct ata_port *ap)
717{
718 u8 host_stat;
719 void __iomem *mmio = ap->ioaddr.bmdma_addr;
720
721 host_stat = in_be32(mmio + SCC_DMA_STATUS);
722
723 /* Workaround for PTERADD: emulate DMA_INTR when
724 * - IDE_STATUS[ERR] = 1
725 * - INT_STATUS[INTRQ] = 1
726 * - DMA_STATUS[IORACTA] = 1
727 */
728 if (!(host_stat & ATA_DMA_INTR)) {
729 u32 int_status = in_be32(mmio + SCC_DMA_INTST);
730 if (ata_altstatus(ap) & ATA_ERR &&
731 int_status & INTSTS_INTRQ &&
732 host_stat & ATA_DMA_ACTIVE)
733 host_stat |= ATA_DMA_INTR;
734 }
735
736 return host_stat;
737}
738
739/**
740 * scc_data_xfer - Transfer data by PIO
741 * @adev: device for this I/O
742 * @buf: data buffer
743 * @buflen: buffer length
744 * @write_data: read/write
745 *
746 * Note: Original code is ata_data_xfer().
747 */
748
749static void scc_data_xfer (struct ata_device *adev, unsigned char *buf,
750 unsigned int buflen, int write_data)
751{
752 struct ata_port *ap = adev->ap;
753 unsigned int words = buflen >> 1;
754 unsigned int i;
755 u16 *buf16 = (u16 *) buf;
756 void __iomem *mmio = ap->ioaddr.data_addr;
757
758 /* Transfer multiple of 2 bytes */
759 if (write_data) {
760 for (i = 0; i < words; i++)
761 out_be32(mmio, cpu_to_le16(buf16[i]));
762 } else {
763 for (i = 0; i < words; i++)
764 buf16[i] = le16_to_cpu(in_be32(mmio));
765 }
766
767 /* Transfer trailing 1 byte, if any. */
768 if (unlikely(buflen & 0x01)) {
769 u16 align_buf[1] = { 0 };
770 unsigned char *trailing_buf = buf + buflen - 1;
771
772 if (write_data) {
773 memcpy(align_buf, trailing_buf, 1);
774 out_be32(mmio, cpu_to_le16(align_buf[0]));
775 } else {
776 align_buf[0] = le16_to_cpu(in_be32(mmio));
777 memcpy(trailing_buf, align_buf, 1);
778 }
779 }
780}
781
782/**
783 * scc_irq_on - Enable interrupts on a port.
784 * @ap: Port on which interrupts are enabled.
785 *
786 * Note: Original code is ata_irq_on().
787 */
788
789static u8 scc_irq_on (struct ata_port *ap)
790{
791 struct ata_ioports *ioaddr = &ap->ioaddr;
792 u8 tmp;
793
794 ap->ctl &= ~ATA_NIEN;
795 ap->last_ctl = ap->ctl;
796
797 out_be32(ioaddr->ctl_addr, ap->ctl);
798 tmp = ata_wait_idle(ap);
799
800 ap->ops->irq_clear(ap);
801
802 return tmp;
803}
804
805/**
806 * scc_irq_ack - Acknowledge a device interrupt.
807 * @ap: Port on which interrupts are enabled.
808 *
809 * Note: Original code is ata_irq_ack().
810 */
811
812static u8 scc_irq_ack (struct ata_port *ap, unsigned int chk_drq)
813{
814 unsigned int bits = chk_drq ? ATA_BUSY | ATA_DRQ : ATA_BUSY;
815 u8 host_stat, post_stat, status;
816
817 status = ata_busy_wait(ap, bits, 1000);
818 if (status & bits)
819 if (ata_msg_err(ap))
820 printk(KERN_ERR "abnormal status 0x%X\n", status);
821
822 /* get controller status; clear intr, err bits */
823 host_stat = in_be32(ap->ioaddr.bmdma_addr + SCC_DMA_STATUS);
824 out_be32(ap->ioaddr.bmdma_addr + SCC_DMA_STATUS,
825 host_stat | ATA_DMA_INTR | ATA_DMA_ERR);
826
827 post_stat = in_be32(ap->ioaddr.bmdma_addr + SCC_DMA_STATUS);
828
829 if (ata_msg_intr(ap))
830 printk(KERN_INFO "%s: irq ack: host_stat 0x%X, new host_stat 0x%X, drv_stat 0x%X\n",
831 __FUNCTION__,
832 host_stat, post_stat, status);
833
834 return status;
835}
836
837/**
838 * scc_bmdma_freeze - Freeze BMDMA controller port
839 * @ap: port to freeze
840 *
841 * Note: Original code is ata_bmdma_freeze().
842 */
843
844static void scc_bmdma_freeze (struct ata_port *ap)
845{
846 struct ata_ioports *ioaddr = &ap->ioaddr;
847
848 ap->ctl |= ATA_NIEN;
849 ap->last_ctl = ap->ctl;
850
851 out_be32(ioaddr->ctl_addr, ap->ctl);
852
853 /* Under certain circumstances, some controllers raise IRQ on
854 * ATA_NIEN manipulation. Also, many controllers fail to mask
855 * previously pending IRQ on ATA_NIEN assertion. Clear it.
856 */
857 ata_chk_status(ap);
858
859 ap->ops->irq_clear(ap);
860}
861
862/**
863 * scc_pata_prereset - prepare for reset
864 * @ap: ATA port to be reset
865 */
866
867static int scc_pata_prereset (struct ata_port *ap)
868{
869 ap->cbl = ATA_CBL_PATA80;
870 return ata_std_prereset(ap);
871}
872
873/**
874 * scc_std_postreset - standard postreset callback
875 * @ap: the target ata_port
876 * @classes: classes of attached devices
877 *
878 * Note: Original code is ata_std_postreset().
879 */
880
881static void scc_std_postreset (struct ata_port *ap, unsigned int *classes)
882{
883 DPRINTK("ENTER\n");
884
885 /* re-enable interrupts */
886 if (!ap->ops->error_handler)
887 ap->ops->irq_on(ap);
888
889 /* is double-select really necessary? */
890 if (classes[0] != ATA_DEV_NONE)
891 ap->ops->dev_select(ap, 1);
892 if (classes[1] != ATA_DEV_NONE)
893 ap->ops->dev_select(ap, 0);
894
895 /* bail out if no device is present */
896 if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) {
897 DPRINTK("EXIT, no device\n");
898 return;
899 }
900
901 /* set up device control */
902 if (ap->ioaddr.ctl_addr)
903 out_be32(ap->ioaddr.ctl_addr, ap->ctl);
904
905 DPRINTK("EXIT\n");
906}
907
908/**
909 * scc_error_handler - Stock error handler for BMDMA controller
910 * @ap: port to handle error for
911 */
912
913static void scc_error_handler (struct ata_port *ap)
914{
915 ata_bmdma_drive_eh(ap, scc_pata_prereset, scc_std_softreset, NULL,
916 scc_std_postreset);
917}
918
919/**
920 * scc_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt.
921 * @ap: Port associated with this ATA transaction.
922 *
923 * Note: Original code is ata_bmdma_irq_clear().
924 */
925
926static void scc_bmdma_irq_clear (struct ata_port *ap)
927{
928 void __iomem *mmio = ap->ioaddr.bmdma_addr;
929
930 if (!mmio)
931 return;
932
933 out_be32(mmio + SCC_DMA_STATUS, in_be32(mmio + SCC_DMA_STATUS));
934}
935
936/**
937 * scc_port_start - Set port up for dma.
938 * @ap: Port to initialize
939 *
940 * Allocate space for PRD table using ata_port_start().
941 * Set PRD table address for PTERADD. (PRD Transfer End Read)
942 */
943
944static int scc_port_start (struct ata_port *ap)
945{
946 void __iomem *mmio = ap->ioaddr.bmdma_addr;
947 int rc;
948
949 rc = ata_port_start(ap);
950 if (rc)
951 return rc;
952
953 out_be32(mmio + SCC_DMA_PTERADD, ap->prd_dma);
954 return 0;
955}
956
957/**
958 * scc_port_stop - Undo scc_port_start()
959 * @ap: Port to shut down
960 *
961 * Reset PTERADD.
962 */
963
964static void scc_port_stop (struct ata_port *ap)
965{
966 void __iomem *mmio = ap->ioaddr.bmdma_addr;
967
968 out_be32(mmio + SCC_DMA_PTERADD, 0);
969}
970
971static struct scsi_host_template scc_sht = {
972 .module = THIS_MODULE,
973 .name = DRV_NAME,
974 .ioctl = ata_scsi_ioctl,
975 .queuecommand = ata_scsi_queuecmd,
976 .can_queue = ATA_DEF_QUEUE,
977 .this_id = ATA_SHT_THIS_ID,
978 .sg_tablesize = LIBATA_MAX_PRD,
979 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
980 .emulated = ATA_SHT_EMULATED,
981 .use_clustering = ATA_SHT_USE_CLUSTERING,
982 .proc_name = DRV_NAME,
983 .dma_boundary = ATA_DMA_BOUNDARY,
984 .slave_configure = ata_scsi_slave_config,
985 .slave_destroy = ata_scsi_slave_destroy,
986 .bios_param = ata_std_bios_param,
987#ifdef CONFIG_PM
988 .resume = ata_scsi_device_resume,
989 .suspend = ata_scsi_device_suspend,
990#endif
991};
992
993static const struct ata_port_operations scc_pata_ops = {
994 .port_disable = ata_port_disable,
995 .set_piomode = scc_set_piomode,
996 .set_dmamode = scc_set_dmamode,
997 .mode_filter = ata_pci_default_filter,
998
999 .tf_load = scc_tf_load,
1000 .tf_read = scc_tf_read,
1001 .exec_command = scc_exec_command,
1002 .check_status = scc_check_status,
1003 .check_altstatus = scc_check_altstatus,
1004 .dev_select = scc_std_dev_select,
1005
1006 .bmdma_setup = scc_bmdma_setup,
1007 .bmdma_start = scc_bmdma_start,
1008 .bmdma_stop = scc_bmdma_stop,
1009 .bmdma_status = scc_bmdma_status,
1010 .data_xfer = scc_data_xfer,
1011
1012 .qc_prep = ata_qc_prep,
1013 .qc_issue = ata_qc_issue_prot,
1014
1015 .freeze = scc_bmdma_freeze,
1016 .error_handler = scc_error_handler,
1017 .post_internal_cmd = scc_bmdma_stop,
1018
1019 .irq_handler = ata_interrupt,
1020 .irq_clear = scc_bmdma_irq_clear,
1021 .irq_on = scc_irq_on,
1022 .irq_ack = scc_irq_ack,
1023
1024 .port_start = scc_port_start,
1025 .port_stop = scc_port_stop,
1026};
1027
1028static struct ata_port_info scc_port_info[] = {
1029 {
1030 .sht = &scc_sht,
1031 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_MMIO | ATA_FLAG_NO_LEGACY,
1032 .pio_mask = 0x1f, /* pio0-4 */
1033 .mwdma_mask = 0x00,
1034 .udma_mask = ATA_UDMA6,
1035 .port_ops = &scc_pata_ops,
1036 },
1037};
1038
1039/**
1040 * scc_reset_controller - initialize SCC PATA controller.
1041 */
1042
1043static int scc_reset_controller(struct ata_probe_ent *probe_ent)
1044{
1045 void __iomem *ctrl_base = probe_ent->iomap[SCC_CTRL_BAR];
1046 void __iomem *bmid_base = probe_ent->iomap[SCC_BMID_BAR];
1047 void __iomem *cckctrl_port = ctrl_base + SCC_CTL_CCKCTRL;
1048 void __iomem *mode_port = ctrl_base + SCC_CTL_MODEREG;
1049 void __iomem *ecmode_port = ctrl_base + SCC_CTL_ECMODE;
1050 void __iomem *intmask_port = bmid_base + SCC_DMA_INTMASK;
1051 void __iomem *dmastatus_port = bmid_base + SCC_DMA_STATUS;
1052 u32 reg = 0;
1053
1054 out_be32(cckctrl_port, reg);
1055 reg |= CCKCTRL_ATACLKOEN;
1056 out_be32(cckctrl_port, reg);
1057 reg |= CCKCTRL_LCLKEN | CCKCTRL_OCLKEN;
1058 out_be32(cckctrl_port, reg);
1059 reg |= CCKCTRL_CRST;
1060 out_be32(cckctrl_port, reg);
1061
1062 for (;;) {
1063 reg = in_be32(cckctrl_port);
1064 if (reg & CCKCTRL_CRST)
1065 break;
1066 udelay(5000);
1067 }
1068
1069 reg |= CCKCTRL_ATARESET;
1070 out_be32(cckctrl_port, reg);
1071 out_be32(ecmode_port, ECMODE_VALUE);
1072 out_be32(mode_port, MODE_JCUSFEN);
1073 out_be32(intmask_port, INTMASK_MSK);
1074
1075 if (in_be32(dmastatus_port) & QCHSD_STPDIAG) {
1076 printk(KERN_WARNING "%s: failed to detect 80c cable. (PDIAG# is high)\n", DRV_NAME);
1077 return -EIO;
1078 }
1079
1080 return 0;
1081}
1082
1083/**
1084 * scc_setup_ports - initialize ioaddr with SCC PATA port offsets.
1085 * @ioaddr: IO address structure to be initialized
1086 * @base: base address of BMID region
1087 */
1088
1089static void scc_setup_ports (struct ata_ioports *ioaddr, void __iomem *base)
1090{
1091 ioaddr->cmd_addr = base + SCC_REG_CMD_ADDR;
1092 ioaddr->altstatus_addr = ioaddr->cmd_addr + SCC_REG_ALTSTATUS;
1093 ioaddr->ctl_addr = ioaddr->cmd_addr + SCC_REG_ALTSTATUS;
1094 ioaddr->bmdma_addr = base;
1095 ioaddr->data_addr = ioaddr->cmd_addr + SCC_REG_DATA;
1096 ioaddr->error_addr = ioaddr->cmd_addr + SCC_REG_ERR;
1097 ioaddr->feature_addr = ioaddr->cmd_addr + SCC_REG_FEATURE;
1098 ioaddr->nsect_addr = ioaddr->cmd_addr + SCC_REG_NSECT;
1099 ioaddr->lbal_addr = ioaddr->cmd_addr + SCC_REG_LBAL;
1100 ioaddr->lbam_addr = ioaddr->cmd_addr + SCC_REG_LBAM;
1101 ioaddr->lbah_addr = ioaddr->cmd_addr + SCC_REG_LBAH;
1102 ioaddr->device_addr = ioaddr->cmd_addr + SCC_REG_DEVICE;
1103 ioaddr->status_addr = ioaddr->cmd_addr + SCC_REG_STATUS;
1104 ioaddr->command_addr = ioaddr->cmd_addr + SCC_REG_CMD;
1105}
1106
1107static int scc_host_init(struct ata_probe_ent *probe_ent)
1108{
1109 struct pci_dev *pdev = to_pci_dev(probe_ent->dev);
1110 int rc;
1111
1112 rc = scc_reset_controller(probe_ent);
1113 if (rc)
1114 return rc;
1115
1116 probe_ent->n_ports = 1;
1117
1118 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
1119 if (rc)
1120 return rc;
1121 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
1122 if (rc)
1123 return rc;
1124
1125 scc_setup_ports(&probe_ent->port[0], probe_ent->iomap[SCC_BMID_BAR]);
1126
1127 pci_set_master(pdev);
1128
1129 return 0;
1130}
1131
1132/**
1133 * scc_init_one - Register SCC PATA device with kernel services
1134 * @pdev: PCI device to register
1135 * @ent: Entry in scc_pci_tbl matching with @pdev
1136 *
1137 * LOCKING:
1138 * Inherited from PCI layer (may sleep).
1139 *
1140 * RETURNS:
1141 * Zero on success, or -ERRNO value.
1142 */
1143
1144static int scc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1145{
1146 static int printed_version;
1147 unsigned int board_idx = (unsigned int) ent->driver_data;
1148 struct device *dev = &pdev->dev;
1149 struct ata_probe_ent *probe_ent;
1150 int rc;
1151
1152 if (!printed_version++)
1153 dev_printk(KERN_DEBUG, &pdev->dev,
1154 "version " DRV_VERSION "\n");
1155
1156 rc = pcim_enable_device(pdev);
1157 if (rc)
1158 return rc;
1159
1160 rc = pcim_iomap_regions(pdev, (1 << SCC_CTRL_BAR) | (1 << SCC_BMID_BAR), DRV_NAME);
1161 if (rc == -EBUSY)
1162 pcim_pin_device(pdev);
1163 if (rc)
1164 return rc;
1165
1166 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
1167 if (!probe_ent)
1168 return -ENOMEM;
1169
1170 probe_ent->dev = dev;
1171 INIT_LIST_HEAD(&probe_ent->node);
1172
1173 probe_ent->sht = scc_port_info[board_idx].sht;
1174 probe_ent->port_flags = scc_port_info[board_idx].flags;
1175 probe_ent->pio_mask = scc_port_info[board_idx].pio_mask;
1176 probe_ent->udma_mask = scc_port_info[board_idx].udma_mask;
1177 probe_ent->port_ops = scc_port_info[board_idx].port_ops;
1178
1179 probe_ent->irq = pdev->irq;
1180 probe_ent->irq_flags = IRQF_SHARED;
1181 probe_ent->iomap = pcim_iomap_table(pdev);
1182
1183 rc = scc_host_init(probe_ent);
1184 if (rc)
1185 return rc;
1186
1187 if (!ata_device_add(probe_ent))
1188 return -ENODEV;
1189
1190 devm_kfree(dev, probe_ent);
1191 return 0;
1192}
1193
1194static struct pci_driver scc_pci_driver = {
1195 .name = DRV_NAME,
1196 .id_table = scc_pci_tbl,
1197 .probe = scc_init_one,
1198 .remove = ata_pci_remove_one,
1199#ifdef CONFIG_PM
1200 .suspend = ata_pci_device_suspend,
1201 .resume = ata_pci_device_resume,
1202#endif
1203};
1204
1205static int __init scc_init (void)
1206{
1207 int rc;
1208
1209 DPRINTK("pci_register_driver\n");
1210 rc = pci_register_driver(&scc_pci_driver);
1211 if (rc)
1212 return rc;
1213
1214 DPRINTK("done\n");
1215 return 0;
1216}
1217
1218static void __exit scc_exit (void)
1219{
1220 pci_unregister_driver(&scc_pci_driver);
1221}
1222
1223module_init(scc_init);
1224module_exit(scc_exit);
1225
1226MODULE_AUTHOR("Toshiba corp");
1227MODULE_DESCRIPTION("SCSI low-level driver for Toshiba SCC PATA controller");
1228MODULE_LICENSE("GPL");
1229MODULE_DEVICE_TABLE(pci, scc_pci_tbl);
1230MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/ata/pata_serverworks.c b/drivers/ata/pata_serverworks.c
index ad5b43fef3..598eef810a 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.9" 44#define DRV_VERSION "0.4.0"
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) */
@@ -319,8 +319,10 @@ static struct scsi_host_template serverworks_sht = {
319 .slave_configure = ata_scsi_slave_config, 319 .slave_configure = ata_scsi_slave_config,
320 .slave_destroy = ata_scsi_slave_destroy, 320 .slave_destroy = ata_scsi_slave_destroy,
321 .bios_param = ata_std_bios_param, 321 .bios_param = ata_std_bios_param,
322#ifdef CONFIG_PM
322 .resume = ata_scsi_device_resume, 323 .resume = ata_scsi_device_resume,
323 .suspend = ata_scsi_device_suspend, 324 .suspend = ata_scsi_device_suspend,
325#endif
324}; 326};
325 327
326static struct ata_port_operations serverworks_osb4_port_ops = { 328static struct ata_port_operations serverworks_osb4_port_ops = {
@@ -548,6 +550,7 @@ static int serverworks_init_one(struct pci_dev *pdev, const struct pci_device_id
548 return ata_pci_init_one(pdev, port_info, ports); 550 return ata_pci_init_one(pdev, port_info, ports);
549} 551}
550 552
553#ifdef CONFIG_PM
551static int serverworks_reinit_one(struct pci_dev *pdev) 554static int serverworks_reinit_one(struct pci_dev *pdev)
552{ 555{
553 /* Force master latency timer to 64 PCI clocks */ 556 /* Force master latency timer to 64 PCI clocks */
@@ -571,6 +574,7 @@ static int serverworks_reinit_one(struct pci_dev *pdev)
571 } 574 }
572 return ata_pci_device_resume(pdev); 575 return ata_pci_device_resume(pdev);
573} 576}
577#endif
574 578
575static const struct pci_device_id serverworks[] = { 579static const struct pci_device_id serverworks[] = {
576 { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4IDE), 0}, 580 { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4IDE), 0},
@@ -587,8 +591,10 @@ static struct pci_driver serverworks_pci_driver = {
587 .id_table = serverworks, 591 .id_table = serverworks,
588 .probe = serverworks_init_one, 592 .probe = serverworks_init_one,
589 .remove = ata_pci_remove_one, 593 .remove = ata_pci_remove_one,
594#ifdef CONFIG_PM
590 .suspend = ata_pci_device_suspend, 595 .suspend = ata_pci_device_suspend,
591 .resume = serverworks_reinit_one, 596 .resume = serverworks_reinit_one,
597#endif
592}; 598};
593 599
594static int __init serverworks_init(void) 600static int __init serverworks_init(void)
diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
index ed79fabe02..dab2889a55 100644
--- a/drivers/ata/pata_sil680.c
+++ b/drivers/ata/pata_sil680.c
@@ -33,7 +33,7 @@
33#include <linux/libata.h> 33#include <linux/libata.h>
34 34
35#define DRV_NAME "pata_sil680" 35#define DRV_NAME "pata_sil680"
36#define DRV_VERSION "0.4.1" 36#define DRV_VERSION "0.4.5"
37 37
38/** 38/**
39 * sil680_selreg - return register base 39 * sil680_selreg - return register base
@@ -139,10 +139,13 @@ static void sil680_set_piomode(struct ata_port *ap, struct ata_device *adev)
139 139
140 unsigned long tfaddr = sil680_selreg(ap, 0x02); 140 unsigned long tfaddr = sil680_selreg(ap, 0x02);
141 unsigned long addr = sil680_seldev(ap, adev, 0x04); 141 unsigned long addr = sil680_seldev(ap, adev, 0x04);
142 unsigned long addr_mask = 0x80 + 4 * ap->port_no;
142 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 143 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
143 int pio = adev->pio_mode - XFER_PIO_0; 144 int pio = adev->pio_mode - XFER_PIO_0;
144 int lowest_pio = pio; 145 int lowest_pio = pio;
146 int port_shift = 4 * adev->devno;
145 u16 reg; 147 u16 reg;
148 u8 mode;
146 149
147 struct ata_device *pair = ata_dev_pair(adev); 150 struct ata_device *pair = ata_dev_pair(adev);
148 151
@@ -153,10 +156,17 @@ static void sil680_set_piomode(struct ata_port *ap, struct ata_device *adev)
153 pci_write_config_word(pdev, tfaddr, speed_t[lowest_pio]); 156 pci_write_config_word(pdev, tfaddr, speed_t[lowest_pio]);
154 157
155 pci_read_config_word(pdev, tfaddr-2, &reg); 158 pci_read_config_word(pdev, tfaddr-2, &reg);
159 pci_read_config_byte(pdev, addr_mask, &mode);
160
156 reg &= ~0x0200; /* Clear IORDY */ 161 reg &= ~0x0200; /* Clear IORDY */
157 if (ata_pio_need_iordy(adev)) 162 mode &= ~(3 << port_shift); /* Clear IORDY and DMA bits */
163
164 if (ata_pio_need_iordy(adev)) {
158 reg |= 0x0200; /* Enable IORDY */ 165 reg |= 0x0200; /* Enable IORDY */
166 mode |= 1 << port_shift;
167 }
159 pci_write_config_word(pdev, tfaddr-2, reg); 168 pci_write_config_word(pdev, tfaddr-2, reg);
169 pci_write_config_byte(pdev, addr_mask, mode);
160} 170}
161 171
162/** 172/**
@@ -226,6 +236,10 @@ static struct scsi_host_template sil680_sht = {
226 .slave_configure = ata_scsi_slave_config, 236 .slave_configure = ata_scsi_slave_config,
227 .slave_destroy = ata_scsi_slave_destroy, 237 .slave_destroy = ata_scsi_slave_destroy,
228 .bios_param = ata_std_bios_param, 238 .bios_param = ata_std_bios_param,
239#ifdef CONFIG_PM
240 .suspend = ata_scsi_device_suspend,
241 .resume = ata_scsi_device_resume,
242#endif
229}; 243};
230 244
231static struct ata_port_operations sil680_port_ops = { 245static struct ata_port_operations sil680_port_ops = {
@@ -367,11 +381,13 @@ static int sil680_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
367 return ata_pci_init_one(pdev, port_info, 2); 381 return ata_pci_init_one(pdev, port_info, 2);
368} 382}
369 383
384#ifdef CONFIG_PM
370static int sil680_reinit_one(struct pci_dev *pdev) 385static int sil680_reinit_one(struct pci_dev *pdev)
371{ 386{
372 sil680_init_chip(pdev); 387 sil680_init_chip(pdev);
373 return ata_pci_device_resume(pdev); 388 return ata_pci_device_resume(pdev);
374} 389}
390#endif
375 391
376static const struct pci_device_id sil680[] = { 392static const struct pci_device_id sil680[] = {
377 { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_680), }, 393 { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_680), },
@@ -384,8 +400,10 @@ static struct pci_driver sil680_pci_driver = {
384 .id_table = sil680, 400 .id_table = sil680,
385 .probe = sil680_init_one, 401 .probe = sil680_init_one,
386 .remove = ata_pci_remove_one, 402 .remove = ata_pci_remove_one,
403#ifdef CONFIG_PM
387 .suspend = ata_pci_device_suspend, 404 .suspend = ata_pci_device_suspend,
388 .resume = sil680_reinit_one, 405 .resume = sil680_reinit_one,
406#endif
389}; 407};
390 408
391static int __init sil680_init(void) 409static int __init sil680_init(void)
diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c
index 560103d55b..f482078659 100644
--- a/drivers/ata/pata_sis.c
+++ b/drivers/ata/pata_sis.c
@@ -32,11 +32,10 @@
32#include <scsi/scsi_host.h> 32#include <scsi/scsi_host.h>
33#include <linux/libata.h> 33#include <linux/libata.h>
34#include <linux/ata.h> 34#include <linux/ata.h>
35#include "libata.h" 35#include "sis.h"
36 36
37#undef DRV_NAME /* already defined in libata.h, for libata-core */
38#define DRV_NAME "pata_sis" 37#define DRV_NAME "pata_sis"
39#define DRV_VERSION "0.4.5" 38#define DRV_VERSION "0.5.0"
40 39
41struct sis_chipset { 40struct sis_chipset {
42 u16 device; /* PCI host ID */ 41 u16 device; /* PCI host ID */
@@ -151,7 +150,7 @@ static int sis_66_pre_reset(struct ata_port *ap)
151 150
152 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no])) { 151 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no])) {
153 ata_port_disable(ap); 152 ata_port_disable(ap);
154 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id); 153 ata_port_printk(ap, KERN_INFO, "port disabled. ignoring.\n");
155 return 0; 154 return 0;
156 } 155 }
157 /* Older chips keep cable detect in bits 4/5 of reg 0x48 */ 156 /* Older chips keep cable detect in bits 4/5 of reg 0x48 */
@@ -197,7 +196,7 @@ static int sis_old_pre_reset(struct ata_port *ap)
197 196
198 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no])) { 197 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no])) {
199 ata_port_disable(ap); 198 ata_port_disable(ap);
200 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id); 199 ata_port_printk(ap, KERN_INFO, "port disabled. ignoring.\n");
201 return 0; 200 return 0;
202 } 201 }
203 ap->cbl = ATA_CBL_PATA40; 202 ap->cbl = ATA_CBL_PATA40;
@@ -576,8 +575,10 @@ static struct scsi_host_template sis_sht = {
576 .slave_configure = ata_scsi_slave_config, 575 .slave_configure = ata_scsi_slave_config,
577 .slave_destroy = ata_scsi_slave_destroy, 576 .slave_destroy = ata_scsi_slave_destroy,
578 .bios_param = ata_std_bios_param, 577 .bios_param = ata_std_bios_param,
578#ifdef CONFIG_PM
579 .resume = ata_scsi_device_resume, 579 .resume = ata_scsi_device_resume,
580 .suspend = ata_scsi_device_suspend, 580 .suspend = ata_scsi_device_suspend,
581#endif
581}; 582};
582 583
583static const struct ata_port_operations sis_133_ops = { 584static const struct ata_port_operations sis_133_ops = {
@@ -1033,8 +1034,10 @@ static struct pci_driver sis_pci_driver = {
1033 .id_table = sis_pci_tbl, 1034 .id_table = sis_pci_tbl,
1034 .probe = sis_init_one, 1035 .probe = sis_init_one,
1035 .remove = ata_pci_remove_one, 1036 .remove = ata_pci_remove_one,
1037#ifdef CONFIG_PM
1036 .suspend = ata_pci_device_suspend, 1038 .suspend = ata_pci_device_suspend,
1037 .resume = ata_pci_device_resume, 1039 .resume = ata_pci_device_resume,
1040#endif
1038}; 1041};
1039 1042
1040static int __init sis_init(void) 1043static int __init sis_init(void)
diff --git a/drivers/ata/pata_sl82c105.c b/drivers/ata/pata_sl82c105.c
index 96e890fd64..b681441cfc 100644
--- a/drivers/ata/pata_sl82c105.c
+++ b/drivers/ata/pata_sl82c105.c
@@ -7,6 +7,13 @@
7 * SL82C105/Winbond 553 IDE driver 7 * SL82C105/Winbond 553 IDE driver
8 * 8 *
9 * and in part on the documentation and errata sheet 9 * and in part on the documentation and errata sheet
10 *
11 *
12 * Note: The controller like many controllers has shared timings for
13 * PIO and DMA. We thus flip to the DMA timings in dma_start and flip back
14 * in the dma_stop function. Thus we actually don't need a set_dmamode
15 * method as the PIO method is always called and will set the right PIO
16 * timing parameters.
10 */ 17 */
11 18
12#include <linux/kernel.h> 19#include <linux/kernel.h>
@@ -19,7 +26,7 @@
19#include <linux/libata.h> 26#include <linux/libata.h>
20 27
21#define DRV_NAME "pata_sl82c105" 28#define DRV_NAME "pata_sl82c105"
22#define DRV_VERSION "0.2.3" 29#define DRV_VERSION "0.3.0"
23 30
24enum { 31enum {
25 /* 32 /*
@@ -126,33 +133,6 @@ static void sl82c105_configure_dmamode(struct ata_port *ap, struct ata_device *a
126} 133}
127 134
128/** 135/**
129 * sl82c105_set_dmamode - set initial DMA mode data
130 * @ap: ATA interface
131 * @adev: ATA device
132 *
133 * Called to do the DMA mode setup. This replaces the PIO timings
134 * for the device in question. Set appropriate PIO timings not DMA
135 * timings at this point.
136 */
137
138static void sl82c105_set_dmamode(struct ata_port *ap, struct ata_device *adev)
139{
140 switch(adev->dma_mode) {
141 case XFER_MW_DMA_0:
142 sl82c105_configure_piomode(ap, adev, 0);
143 break;
144 case XFER_MW_DMA_1:
145 sl82c105_configure_piomode(ap, adev, 3);
146 break;
147 case XFER_MW_DMA_2:
148 sl82c105_configure_piomode(ap, adev, 4);
149 break;
150 default:
151 BUG();
152 }
153}
154
155/**
156 * sl82c105_reset_engine - Reset the DMA engine 136 * sl82c105_reset_engine - Reset the DMA engine
157 * @ap: ATA interface 137 * @ap: ATA interface
158 * 138 *
@@ -222,7 +202,7 @@ static void sl82c105_bmdma_stop(struct ata_queued_cmd *qc)
222 202
223 /* This will redo the initial setup of the DMA device to matching 203 /* This will redo the initial setup of the DMA device to matching
224 PIO timings */ 204 PIO timings */
225 sl82c105_set_dmamode(ap, qc->dev); 205 sl82c105_set_piomode(ap, qc->dev);
226} 206}
227 207
228static struct scsi_host_template sl82c105_sht = { 208static struct scsi_host_template sl82c105_sht = {
@@ -246,7 +226,6 @@ static struct scsi_host_template sl82c105_sht = {
246static struct ata_port_operations sl82c105_port_ops = { 226static struct ata_port_operations sl82c105_port_ops = {
247 .port_disable = ata_port_disable, 227 .port_disable = ata_port_disable,
248 .set_piomode = sl82c105_set_piomode, 228 .set_piomode = sl82c105_set_piomode,
249 .set_dmamode = sl82c105_set_dmamode,
250 .mode_filter = ata_pci_default_filter, 229 .mode_filter = ata_pci_default_filter,
251 230
252 .tf_load = ata_tf_load, 231 .tf_load = ata_tf_load,
@@ -255,7 +234,10 @@ static struct ata_port_operations sl82c105_port_ops = {
255 .exec_command = ata_exec_command, 234 .exec_command = ata_exec_command,
256 .dev_select = ata_std_dev_select, 235 .dev_select = ata_std_dev_select,
257 236
237 .freeze = ata_bmdma_freeze,
238 .thaw = ata_bmdma_thaw,
258 .error_handler = sl82c105_error_handler, 239 .error_handler = sl82c105_error_handler,
240 .post_internal_cmd = ata_bmdma_post_internal_cmd,
259 241
260 .bmdma_setup = ata_bmdma_setup, 242 .bmdma_setup = ata_bmdma_setup,
261 .bmdma_start = sl82c105_bmdma_start, 243 .bmdma_start = sl82c105_bmdma_start,
diff --git a/drivers/ata/pata_triflex.c b/drivers/ata/pata_triflex.c
index 453ab90b72..71418f2a0c 100644
--- a/drivers/ata/pata_triflex.c
+++ b/drivers/ata/pata_triflex.c
@@ -193,8 +193,10 @@ static struct scsi_host_template triflex_sht = {
193 .slave_configure = ata_scsi_slave_config, 193 .slave_configure = ata_scsi_slave_config,
194 .slave_destroy = ata_scsi_slave_destroy, 194 .slave_destroy = ata_scsi_slave_destroy,
195 .bios_param = ata_std_bios_param, 195 .bios_param = ata_std_bios_param,
196#ifdef CONFIG_PM
196 .resume = ata_scsi_device_resume, 197 .resume = ata_scsi_device_resume,
197 .suspend = ata_scsi_device_suspend, 198 .suspend = ata_scsi_device_suspend,
199#endif
198}; 200};
199 201
200static struct ata_port_operations triflex_port_ops = { 202static struct ata_port_operations triflex_port_ops = {
@@ -260,8 +262,10 @@ static struct pci_driver triflex_pci_driver = {
260 .id_table = triflex, 262 .id_table = triflex,
261 .probe = triflex_init_one, 263 .probe = triflex_init_one,
262 .remove = ata_pci_remove_one, 264 .remove = ata_pci_remove_one,
265#ifdef CONFIG_PM
263 .suspend = ata_pci_device_suspend, 266 .suspend = ata_pci_device_suspend,
264 .resume = ata_pci_device_resume, 267 .resume = ata_pci_device_resume,
268#endif
265}; 269};
266 270
267static int __init triflex_init(void) 271static int __init triflex_init(void)
diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
index 220fcd6c54..946ade0e1f 100644
--- a/drivers/ata/pata_via.c
+++ b/drivers/ata/pata_via.c
@@ -170,7 +170,7 @@ static int via_pre_reset(struct ata_port *ap)
170 ap->cbl = ATA_CBL_PATA40; 170 ap->cbl = ATA_CBL_PATA40;
171 else 171 else
172 ap->cbl = ATA_CBL_PATA_UNK; 172 ap->cbl = ATA_CBL_PATA_UNK;
173 173
174 174
175 return ata_std_prereset(ap); 175 return ata_std_prereset(ap);
176} 176}
@@ -305,8 +305,10 @@ static struct scsi_host_template via_sht = {
305 .slave_configure = ata_scsi_slave_config, 305 .slave_configure = ata_scsi_slave_config,
306 .slave_destroy = ata_scsi_slave_destroy, 306 .slave_destroy = ata_scsi_slave_destroy,
307 .bios_param = ata_std_bios_param, 307 .bios_param = ata_std_bios_param,
308#ifdef CONFIG_PM
308 .resume = ata_scsi_device_resume, 309 .resume = ata_scsi_device_resume,
309 .suspend = ata_scsi_device_suspend, 310 .suspend = ata_scsi_device_suspend,
311#endif
310}; 312};
311 313
312static struct ata_port_operations via_port_ops = { 314static struct ata_port_operations via_port_ops = {
@@ -560,6 +562,7 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
560 return ata_pci_init_one(pdev, port_info, 2); 562 return ata_pci_init_one(pdev, port_info, 2);
561} 563}
562 564
565#ifdef CONFIG_PM
563/** 566/**
564 * via_reinit_one - reinit after resume 567 * via_reinit_one - reinit after resume
565 * @pdev; PCI device 568 * @pdev; PCI device
@@ -592,6 +595,7 @@ static int via_reinit_one(struct pci_dev *pdev)
592 } 595 }
593 return ata_pci_device_resume(pdev); 596 return ata_pci_device_resume(pdev);
594} 597}
598#endif
595 599
596static const struct pci_device_id via[] = { 600static const struct pci_device_id via[] = {
597 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C576_1), }, 601 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C576_1), },
@@ -607,8 +611,10 @@ static struct pci_driver via_pci_driver = {
607 .id_table = via, 611 .id_table = via,
608 .probe = via_init_one, 612 .probe = via_init_one,
609 .remove = ata_pci_remove_one, 613 .remove = ata_pci_remove_one,
614#ifdef CONFIG_PM
610 .suspend = ata_pci_device_suspend, 615 .suspend = ata_pci_device_suspend,
611 .resume = via_reinit_one, 616 .resume = via_reinit_one,
617#endif
612}; 618};
613 619
614static int __init via_init(void) 620static int __init via_init(void)
diff --git a/drivers/ata/pata_winbond.c b/drivers/ata/pata_winbond.c
index 0888b4f19f..6c111035fc 100644
--- a/drivers/ata/pata_winbond.c
+++ b/drivers/ata/pata_winbond.c
@@ -17,7 +17,7 @@
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18 18
19#define DRV_NAME "pata_winbond" 19#define DRV_NAME "pata_winbond"
20#define DRV_VERSION "0.0.1" 20#define DRV_VERSION "0.0.2"
21 21
22#define NR_HOST 4 /* Two winbond controllers, two channels each */ 22#define NR_HOST 4 /* Two winbond controllers, two channels each */
23 23
diff --git a/drivers/ata/pdc_adma.c b/drivers/ata/pdc_adma.c
index 857ac23217..5dd3ca8b5f 100644
--- a/drivers/ata/pdc_adma.c
+++ b/drivers/ata/pdc_adma.c
@@ -44,7 +44,7 @@
44#include <linux/libata.h> 44#include <linux/libata.h>
45 45
46#define DRV_NAME "pdc_adma" 46#define DRV_NAME "pdc_adma"
47#define DRV_VERSION "0.04" 47#define DRV_VERSION "0.05"
48 48
49/* macro to calculate base address for ATA regs */ 49/* macro to calculate base address for ATA regs */
50#define ADMA_ATA_REGS(base,port_no) ((base) + ((port_no) * 0x40)) 50#define ADMA_ATA_REGS(base,port_no) ((base) + ((port_no) * 0x40))
@@ -498,7 +498,7 @@ static inline unsigned int adma_intr_mmio(struct ata_host *host)
498 if ((status & ATA_BUSY)) 498 if ((status & ATA_BUSY))
499 continue; 499 continue;
500 DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n", 500 DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n",
501 ap->id, qc->tf.protocol, status); 501 ap->print_id, qc->tf.protocol, status);
502 502
503 /* complete taskfile transaction */ 503 /* complete taskfile transaction */
504 pp->state = adma_state_idle; 504 pp->state = adma_state_idle;
diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c
index 31b636fac9..3193a603d1 100644
--- a/drivers/ata/sata_inic162x.c
+++ b/drivers/ata/sata_inic162x.c
@@ -135,8 +135,10 @@ static struct scsi_host_template inic_sht = {
135 .slave_configure = inic_slave_config, 135 .slave_configure = inic_slave_config,
136 .slave_destroy = ata_scsi_slave_destroy, 136 .slave_destroy = ata_scsi_slave_destroy,
137 .bios_param = ata_std_bios_param, 137 .bios_param = ata_std_bios_param,
138#ifdef CONFIG_PM
138 .suspend = ata_scsi_device_suspend, 139 .suspend = ata_scsi_device_suspend,
139 .resume = ata_scsi_device_resume, 140 .resume = ata_scsi_device_resume,
141#endif
140}; 142};
141 143
142static const int scr_map[] = { 144static const int scr_map[] = {
@@ -632,6 +634,7 @@ static int init_controller(void __iomem *mmio_base, u16 hctl)
632 return 0; 634 return 0;
633} 635}
634 636
637#ifdef CONFIG_PM
635static int inic_pci_device_resume(struct pci_dev *pdev) 638static int inic_pci_device_resume(struct pci_dev *pdev)
636{ 639{
637 struct ata_host *host = dev_get_drvdata(&pdev->dev); 640 struct ata_host *host = dev_get_drvdata(&pdev->dev);
@@ -642,7 +645,6 @@ static int inic_pci_device_resume(struct pci_dev *pdev)
642 ata_pci_device_do_resume(pdev); 645 ata_pci_device_do_resume(pdev);
643 646
644 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) { 647 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
645 printk("XXX\n");
646 rc = init_controller(mmio_base, hpriv->cached_hctl); 648 rc = init_controller(mmio_base, hpriv->cached_hctl);
647 if (rc) 649 if (rc)
648 return rc; 650 return rc;
@@ -652,6 +654,7 @@ static int inic_pci_device_resume(struct pci_dev *pdev)
652 654
653 return 0; 655 return 0;
654} 656}
657#endif
655 658
656static int inic_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 659static int inic_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
657{ 660{
@@ -755,8 +758,10 @@ static const struct pci_device_id inic_pci_tbl[] = {
755static struct pci_driver inic_pci_driver = { 758static struct pci_driver inic_pci_driver = {
756 .name = DRV_NAME, 759 .name = DRV_NAME,
757 .id_table = inic_pci_tbl, 760 .id_table = inic_pci_tbl,
761#ifdef CONFIG_PM
758 .suspend = ata_pci_device_suspend, 762 .suspend = ata_pci_device_suspend,
759 .resume = inic_pci_device_resume, 763 .resume = inic_pci_device_resume,
764#endif
760 .probe = inic_init_one, 765 .probe = inic_init_one,
761 .remove = ata_pci_remove_one, 766 .remove = ata_pci_remove_one,
762}; 767};
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index d689df52ea..a65ba636aa 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -35,7 +35,7 @@
35#include <linux/libata.h> 35#include <linux/libata.h>
36 36
37#define DRV_NAME "sata_mv" 37#define DRV_NAME "sata_mv"
38#define DRV_VERSION "0.7" 38#define DRV_VERSION "0.8"
39 39
40enum { 40enum {
41 /* BAR's are enumerated in terms of pci_resource_start() terms */ 41 /* BAR's are enumerated in terms of pci_resource_start() terms */
@@ -137,14 +137,19 @@ enum {
137 PCI_ERR = (1 << 18), 137 PCI_ERR = (1 << 18),
138 TRAN_LO_DONE = (1 << 19), /* 6xxx: IRQ coalescing */ 138 TRAN_LO_DONE = (1 << 19), /* 6xxx: IRQ coalescing */
139 TRAN_HI_DONE = (1 << 20), /* 6xxx: IRQ coalescing */ 139 TRAN_HI_DONE = (1 << 20), /* 6xxx: IRQ coalescing */
140 PORTS_0_3_COAL_DONE = (1 << 8),
141 PORTS_4_7_COAL_DONE = (1 << 17),
140 PORTS_0_7_COAL_DONE = (1 << 21), /* 6xxx: IRQ coalescing */ 142 PORTS_0_7_COAL_DONE = (1 << 21), /* 6xxx: IRQ coalescing */
141 GPIO_INT = (1 << 22), 143 GPIO_INT = (1 << 22),
142 SELF_INT = (1 << 23), 144 SELF_INT = (1 << 23),
143 TWSI_INT = (1 << 24), 145 TWSI_INT = (1 << 24),
144 HC_MAIN_RSVD = (0x7f << 25), /* bits 31-25 */ 146 HC_MAIN_RSVD = (0x7f << 25), /* bits 31-25 */
147 HC_MAIN_RSVD_5 = (0x1fff << 19), /* bits 31-19 */
145 HC_MAIN_MASKED_IRQS = (TRAN_LO_DONE | TRAN_HI_DONE | 148 HC_MAIN_MASKED_IRQS = (TRAN_LO_DONE | TRAN_HI_DONE |
146 PORTS_0_7_COAL_DONE | GPIO_INT | TWSI_INT | 149 PORTS_0_7_COAL_DONE | GPIO_INT | TWSI_INT |
147 HC_MAIN_RSVD), 150 HC_MAIN_RSVD),
151 HC_MAIN_MASKED_IRQS_5 = (PORTS_0_3_COAL_DONE | PORTS_4_7_COAL_DONE |
152 HC_MAIN_RSVD_5),
148 153
149 /* SATAHC registers */ 154 /* SATAHC registers */
150 HC_CFG_OFS = 0, 155 HC_CFG_OFS = 0,
@@ -814,23 +819,27 @@ static void mv_edma_cfg(struct mv_host_priv *hpriv, void __iomem *port_mmio)
814 u32 cfg = readl(port_mmio + EDMA_CFG_OFS); 819 u32 cfg = readl(port_mmio + EDMA_CFG_OFS);
815 820
816 /* set up non-NCQ EDMA configuration */ 821 /* set up non-NCQ EDMA configuration */
817 cfg &= ~0x1f; /* clear queue depth */
818 cfg &= ~EDMA_CFG_NCQ; /* clear NCQ mode */
819 cfg &= ~(1 << 9); /* disable equeue */ 822 cfg &= ~(1 << 9); /* disable equeue */
820 823
821 if (IS_GEN_I(hpriv)) 824 if (IS_GEN_I(hpriv)) {
825 cfg &= ~0x1f; /* clear queue depth */
822 cfg |= (1 << 8); /* enab config burst size mask */ 826 cfg |= (1 << 8); /* enab config burst size mask */
827 }
823 828
824 else if (IS_GEN_II(hpriv)) 829 else if (IS_GEN_II(hpriv)) {
830 cfg &= ~0x1f; /* clear queue depth */
825 cfg |= EDMA_CFG_RD_BRST_EXT | EDMA_CFG_WR_BUFF_LEN; 831 cfg |= EDMA_CFG_RD_BRST_EXT | EDMA_CFG_WR_BUFF_LEN;
832 cfg &= ~(EDMA_CFG_NCQ | EDMA_CFG_NCQ_GO_ON_ERR); /* clear NCQ */
833 }
826 834
827 else if (IS_GEN_IIE(hpriv)) { 835 else if (IS_GEN_IIE(hpriv)) {
828 cfg |= (1 << 23); /* dis RX PM port mask */ 836 cfg |= (1 << 23); /* do not mask PM field in rx'd FIS */
829 cfg &= ~(1 << 16); /* dis FIS-based switching (for now) */ 837 cfg |= (1 << 22); /* enab 4-entry host queue cache */
830 cfg &= ~(1 << 19); /* dis 128-entry queue (for now?) */ 838 cfg &= ~(1 << 19); /* dis 128-entry queue (for now?) */
831 cfg |= (1 << 18); /* enab early completion */ 839 cfg |= (1 << 18); /* enab early completion */
832 cfg |= (1 << 17); /* enab host q cache */ 840 cfg |= (1 << 17); /* enab cut-through (dis stor&forwrd) */
833 cfg |= (1 << 22); /* enab cutthrough */ 841 cfg &= ~(1 << 16); /* dis FIS-based switching (for now) */
842 cfg &= ~(EDMA_CFG_NCQ | EDMA_CFG_NCQ_GO_ON_ERR); /* clear NCQ */
834 } 843 }
835 844
836 writelfl(cfg, port_mmio + EDMA_CFG_OFS); 845 writelfl(cfg, port_mmio + EDMA_CFG_OFS);
@@ -1276,7 +1285,7 @@ static void mv_err_intr(struct ata_port *ap, int reset_allowed)
1276 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 1285 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
1277 } 1286 }
1278 DPRINTK(KERN_ERR "ata%u: port error; EDMA err cause: 0x%08x " 1287 DPRINTK(KERN_ERR "ata%u: port error; EDMA err cause: 0x%08x "
1279 "SERR: 0x%08x\n", ap->id, edma_err_cause, serr); 1288 "SERR: 0x%08x\n", ap->print_id, edma_err_cause, serr);
1280 1289
1281 /* Clear EDMA now that SERR cleanup done */ 1290 /* Clear EDMA now that SERR cleanup done */
1282 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 1291 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
@@ -2052,7 +2061,7 @@ static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio)
2052 port->altstatus_addr = port->ctl_addr = shd_base + SHD_CTL_AST_OFS; 2061 port->altstatus_addr = port->ctl_addr = shd_base + SHD_CTL_AST_OFS;
2053 2062
2054 /* unused: */ 2063 /* unused: */
2055 port->cmd_addr = port->bmdma_addr = port->scr_addr = 0; 2064 port->cmd_addr = port->bmdma_addr = port->scr_addr = NULL;
2056 2065
2057 /* Clear any currently outstanding port interrupt conditions */ 2066 /* Clear any currently outstanding port interrupt conditions */
2058 serr_ofs = mv_scr_offset(SCR_ERROR); 2067 serr_ofs = mv_scr_offset(SCR_ERROR);
@@ -2240,7 +2249,11 @@ static int mv_init_host(struct pci_dev *pdev, struct ata_probe_ent *probe_ent,
2240 2249
2241 /* and unmask interrupt generation for host regs */ 2250 /* and unmask interrupt generation for host regs */
2242 writelfl(PCI_UNMASK_ALL_IRQS, mmio + PCI_IRQ_MASK_OFS); 2251 writelfl(PCI_UNMASK_ALL_IRQS, mmio + PCI_IRQ_MASK_OFS);
2243 writelfl(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS); 2252
2253 if (IS_50XX(hpriv))
2254 writelfl(~HC_MAIN_MASKED_IRQS_5, mmio + HC_MAIN_IRQ_MASK_OFS);
2255 else
2256 writelfl(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS);
2244 2257
2245 VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x " 2258 VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x "
2246 "PCI int cause/mask=0x%08x/0x%08x\n", 2259 "PCI int cause/mask=0x%08x/0x%08x\n",
@@ -2347,7 +2360,7 @@ static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2347 return rc; 2360 return rc;
2348 2361
2349 /* Enable interrupts */ 2362 /* Enable interrupts */
2350 if (msi && !pci_enable_msi(pdev)) 2363 if (msi && pci_enable_msi(pdev))
2351 pci_intx(pdev, 1); 2364 pci_intx(pdev, 1);
2352 2365
2353 mv_dump_pci_cfg(pdev, 0x68); 2366 mv_dump_pci_cfg(pdev, 0x68);
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index ab92f208da..9d9670a9b1 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -219,6 +219,7 @@ struct nv_adma_port_priv {
219 void __iomem * gen_block; 219 void __iomem * gen_block;
220 void __iomem * notifier_clear_block; 220 void __iomem * notifier_clear_block;
221 u8 flags; 221 u8 flags;
222 int last_issue_ncq;
222}; 223};
223 224
224struct nv_host_priv { 225struct nv_host_priv {
@@ -229,7 +230,9 @@ struct nv_host_priv {
229 230
230static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 231static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
231static void nv_remove_one (struct pci_dev *pdev); 232static void nv_remove_one (struct pci_dev *pdev);
233#ifdef CONFIG_PM
232static int nv_pci_device_resume(struct pci_dev *pdev); 234static int nv_pci_device_resume(struct pci_dev *pdev);
235#endif
233static void nv_ck804_host_stop(struct ata_host *host); 236static void nv_ck804_host_stop(struct ata_host *host);
234static irqreturn_t nv_generic_interrupt(int irq, void *dev_instance); 237static irqreturn_t nv_generic_interrupt(int irq, void *dev_instance);
235static irqreturn_t nv_nf2_interrupt(int irq, void *dev_instance); 238static irqreturn_t nv_nf2_interrupt(int irq, void *dev_instance);
@@ -250,14 +253,13 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance);
250static void nv_adma_irq_clear(struct ata_port *ap); 253static void nv_adma_irq_clear(struct ata_port *ap);
251static int nv_adma_port_start(struct ata_port *ap); 254static int nv_adma_port_start(struct ata_port *ap);
252static void nv_adma_port_stop(struct ata_port *ap); 255static void nv_adma_port_stop(struct ata_port *ap);
256#ifdef CONFIG_PM
253static int nv_adma_port_suspend(struct ata_port *ap, pm_message_t mesg); 257static int nv_adma_port_suspend(struct ata_port *ap, pm_message_t mesg);
254static int nv_adma_port_resume(struct ata_port *ap); 258static int nv_adma_port_resume(struct ata_port *ap);
259#endif
255static void nv_adma_error_handler(struct ata_port *ap); 260static void nv_adma_error_handler(struct ata_port *ap);
256static void nv_adma_host_stop(struct ata_host *host); 261static void nv_adma_host_stop(struct ata_host *host);
257static void nv_adma_bmdma_setup(struct ata_queued_cmd *qc); 262static void nv_adma_post_internal_cmd(struct ata_queued_cmd *qc);
258static void nv_adma_bmdma_start(struct ata_queued_cmd *qc);
259static void nv_adma_bmdma_stop(struct ata_queued_cmd *qc);
260static u8 nv_adma_bmdma_status(struct ata_port *ap);
261 263
262enum nv_host_type 264enum nv_host_type
263{ 265{
@@ -297,8 +299,10 @@ static struct pci_driver nv_pci_driver = {
297 .name = DRV_NAME, 299 .name = DRV_NAME,
298 .id_table = nv_pci_tbl, 300 .id_table = nv_pci_tbl,
299 .probe = nv_init_one, 301 .probe = nv_init_one,
302#ifdef CONFIG_PM
300 .suspend = ata_pci_device_suspend, 303 .suspend = ata_pci_device_suspend,
301 .resume = nv_pci_device_resume, 304 .resume = nv_pci_device_resume,
305#endif
302 .remove = nv_remove_one, 306 .remove = nv_remove_one,
303}; 307};
304 308
@@ -318,8 +322,10 @@ static struct scsi_host_template nv_sht = {
318 .slave_configure = ata_scsi_slave_config, 322 .slave_configure = ata_scsi_slave_config,
319 .slave_destroy = ata_scsi_slave_destroy, 323 .slave_destroy = ata_scsi_slave_destroy,
320 .bios_param = ata_std_bios_param, 324 .bios_param = ata_std_bios_param,
325#ifdef CONFIG_PM
321 .suspend = ata_scsi_device_suspend, 326 .suspend = ata_scsi_device_suspend,
322 .resume = ata_scsi_device_resume, 327 .resume = ata_scsi_device_resume,
328#endif
323}; 329};
324 330
325static struct scsi_host_template nv_adma_sht = { 331static struct scsi_host_template nv_adma_sht = {
@@ -338,8 +344,10 @@ static struct scsi_host_template nv_adma_sht = {
338 .slave_configure = nv_adma_slave_config, 344 .slave_configure = nv_adma_slave_config,
339 .slave_destroy = ata_scsi_slave_destroy, 345 .slave_destroy = ata_scsi_slave_destroy,
340 .bios_param = ata_std_bios_param, 346 .bios_param = ata_std_bios_param,
347#ifdef CONFIG_PM
341 .suspend = ata_scsi_device_suspend, 348 .suspend = ata_scsi_device_suspend,
342 .resume = ata_scsi_device_resume, 349 .resume = ata_scsi_device_resume,
350#endif
343}; 351};
344 352
345static const struct ata_port_operations nv_generic_ops = { 353static const struct ata_port_operations nv_generic_ops = {
@@ -432,16 +440,16 @@ static const struct ata_port_operations nv_adma_ops = {
432 .exec_command = ata_exec_command, 440 .exec_command = ata_exec_command,
433 .check_status = ata_check_status, 441 .check_status = ata_check_status,
434 .dev_select = ata_std_dev_select, 442 .dev_select = ata_std_dev_select,
435 .bmdma_setup = nv_adma_bmdma_setup, 443 .bmdma_setup = ata_bmdma_setup,
436 .bmdma_start = nv_adma_bmdma_start, 444 .bmdma_start = ata_bmdma_start,
437 .bmdma_stop = nv_adma_bmdma_stop, 445 .bmdma_stop = ata_bmdma_stop,
438 .bmdma_status = nv_adma_bmdma_status, 446 .bmdma_status = ata_bmdma_status,
439 .qc_prep = nv_adma_qc_prep, 447 .qc_prep = nv_adma_qc_prep,
440 .qc_issue = nv_adma_qc_issue, 448 .qc_issue = nv_adma_qc_issue,
441 .freeze = nv_ck804_freeze, 449 .freeze = nv_ck804_freeze,
442 .thaw = nv_ck804_thaw, 450 .thaw = nv_ck804_thaw,
443 .error_handler = nv_adma_error_handler, 451 .error_handler = nv_adma_error_handler,
444 .post_internal_cmd = nv_adma_bmdma_stop, 452 .post_internal_cmd = nv_adma_post_internal_cmd,
445 .data_xfer = ata_data_xfer, 453 .data_xfer = ata_data_xfer,
446 .irq_handler = nv_adma_interrupt, 454 .irq_handler = nv_adma_interrupt,
447 .irq_clear = nv_adma_irq_clear, 455 .irq_clear = nv_adma_irq_clear,
@@ -451,8 +459,10 @@ static const struct ata_port_operations nv_adma_ops = {
451 .scr_write = nv_scr_write, 459 .scr_write = nv_scr_write,
452 .port_start = nv_adma_port_start, 460 .port_start = nv_adma_port_start,
453 .port_stop = nv_adma_port_stop, 461 .port_stop = nv_adma_port_stop,
462#ifdef CONFIG_PM
454 .port_suspend = nv_adma_port_suspend, 463 .port_suspend = nv_adma_port_suspend,
455 .port_resume = nv_adma_port_resume, 464 .port_resume = nv_adma_port_resume,
465#endif
456 .host_stop = nv_adma_host_stop, 466 .host_stop = nv_adma_host_stop,
457}; 467};
458 468
@@ -661,30 +671,31 @@ static unsigned int nv_adma_tf_to_cpb(struct ata_taskfile *tf, __le16 *cpb)
661{ 671{
662 unsigned int idx = 0; 672 unsigned int idx = 0;
663 673
664 cpb[idx++] = cpu_to_le16((ATA_REG_DEVICE << 8) | tf->device | WNB); 674 if(tf->flags & ATA_TFLAG_ISADDR) {
665 675 if (tf->flags & ATA_TFLAG_LBA48) {
666 if ((tf->flags & ATA_TFLAG_LBA48) == 0) { 676 cpb[idx++] = cpu_to_le16((ATA_REG_ERR << 8) | tf->hob_feature | WNB);
667 cpb[idx++] = cpu_to_le16(IGN); 677 cpb[idx++] = cpu_to_le16((ATA_REG_NSECT << 8) | tf->hob_nsect);
668 cpb[idx++] = cpu_to_le16(IGN); 678 cpb[idx++] = cpu_to_le16((ATA_REG_LBAL << 8) | tf->hob_lbal);
669 cpb[idx++] = cpu_to_le16(IGN); 679 cpb[idx++] = cpu_to_le16((ATA_REG_LBAM << 8) | tf->hob_lbam);
670 cpb[idx++] = cpu_to_le16(IGN); 680 cpb[idx++] = cpu_to_le16((ATA_REG_LBAH << 8) | tf->hob_lbah);
671 cpb[idx++] = cpu_to_le16(IGN); 681 cpb[idx++] = cpu_to_le16((ATA_REG_ERR << 8) | tf->feature);
672 } 682 } else
673 else { 683 cpb[idx++] = cpu_to_le16((ATA_REG_ERR << 8) | tf->feature | WNB);
674 cpb[idx++] = cpu_to_le16((ATA_REG_ERR << 8) | tf->hob_feature); 684
675 cpb[idx++] = cpu_to_le16((ATA_REG_NSECT << 8) | tf->hob_nsect); 685 cpb[idx++] = cpu_to_le16((ATA_REG_NSECT << 8) | tf->nsect);
676 cpb[idx++] = cpu_to_le16((ATA_REG_LBAL << 8) | tf->hob_lbal); 686 cpb[idx++] = cpu_to_le16((ATA_REG_LBAL << 8) | tf->lbal);
677 cpb[idx++] = cpu_to_le16((ATA_REG_LBAM << 8) | tf->hob_lbam); 687 cpb[idx++] = cpu_to_le16((ATA_REG_LBAM << 8) | tf->lbam);
678 cpb[idx++] = cpu_to_le16((ATA_REG_LBAH << 8) | tf->hob_lbah); 688 cpb[idx++] = cpu_to_le16((ATA_REG_LBAH << 8) | tf->lbah);
679 } 689 }
680 cpb[idx++] = cpu_to_le16((ATA_REG_ERR << 8) | tf->feature); 690
681 cpb[idx++] = cpu_to_le16((ATA_REG_NSECT << 8) | tf->nsect); 691 if(tf->flags & ATA_TFLAG_DEVICE)
682 cpb[idx++] = cpu_to_le16((ATA_REG_LBAL << 8) | tf->lbal); 692 cpb[idx++] = cpu_to_le16((ATA_REG_DEVICE << 8) | tf->device);
683 cpb[idx++] = cpu_to_le16((ATA_REG_LBAM << 8) | tf->lbam);
684 cpb[idx++] = cpu_to_le16((ATA_REG_LBAH << 8) | tf->lbah);
685 693
686 cpb[idx++] = cpu_to_le16((ATA_REG_CMD << 8) | tf->command | CMDEND); 694 cpb[idx++] = cpu_to_le16((ATA_REG_CMD << 8) | tf->command | CMDEND);
687 695
696 while(idx < 12)
697 cpb[idx++] = cpu_to_le16(IGN);
698
688 return idx; 699 return idx;
689} 700}
690 701
@@ -741,6 +752,17 @@ static int nv_adma_check_cpb(struct ata_port *ap, int cpb_num, int force_err)
741 DPRINTK("Completing qc from tag %d with err_mask %u\n",cpb_num, 752 DPRINTK("Completing qc from tag %d with err_mask %u\n",cpb_num,
742 qc->err_mask); 753 qc->err_mask);
743 ata_qc_complete(qc); 754 ata_qc_complete(qc);
755 } else {
756 struct ata_eh_info *ehi = &ap->eh_info;
757 /* Notifier bits set without a command may indicate the drive
758 is misbehaving. Raise host state machine violation on this
759 condition. */
760 ata_port_printk(ap, KERN_ERR, "notifier for tag %d with no command?\n",
761 cpb_num);
762 ehi->err_mask |= AC_ERR_HSM;
763 ehi->action |= ATA_EH_SOFTRESET;
764 ata_port_freeze(ap);
765 return 1;
744 } 766 }
745 } 767 }
746 return 0; 768 return 0;
@@ -852,22 +874,20 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
852 874
853 if (status & (NV_ADMA_STAT_DONE | 875 if (status & (NV_ADMA_STAT_DONE |
854 NV_ADMA_STAT_CPBERR)) { 876 NV_ADMA_STAT_CPBERR)) {
855 /** Check CPBs for completed commands */ 877 u32 check_commands;
878 int pos, error = 0;
879
880 if(ata_tag_valid(ap->active_tag))
881 check_commands = 1 << ap->active_tag;
882 else
883 check_commands = ap->sactive;
856 884
857 if (ata_tag_valid(ap->active_tag)) { 885 /** Check CPBs for completed commands */
858 /* Non-NCQ command */ 886 while ((pos = ffs(check_commands)) && !error) {
859 nv_adma_check_cpb(ap, ap->active_tag, 887 pos--;
860 notifier_error & (1 << ap->active_tag)); 888 error = nv_adma_check_cpb(ap, pos,
861 } else { 889 notifier_error & (1 << pos) );
862 int pos, error = 0; 890 check_commands &= ~(1 << pos );
863 u32 active = ap->sactive;
864
865 while ((pos = ffs(active)) && !error) {
866 pos--;
867 error = nv_adma_check_cpb(ap, pos,
868 notifier_error & (1 << pos) );
869 active &= ~(1 << pos );
870 }
871 } 891 }
872 } 892 }
873 } 893 }
@@ -905,73 +925,12 @@ static void nv_adma_irq_clear(struct ata_port *ap)
905 iowrite8(ioread8(dma_stat_addr), dma_stat_addr); 925 iowrite8(ioread8(dma_stat_addr), dma_stat_addr);
906} 926}
907 927
908static void nv_adma_bmdma_setup(struct ata_queued_cmd *qc) 928static void nv_adma_post_internal_cmd(struct ata_queued_cmd *qc)
909{
910 struct ata_port *ap = qc->ap;
911 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
912 struct nv_adma_port_priv *pp = ap->private_data;
913 u8 dmactl;
914
915 if(!(pp->flags & NV_ADMA_PORT_REGISTER_MODE)) {
916 WARN_ON(1);
917 return;
918 }
919
920 /* load PRD table addr. */
921 iowrite32(ap->prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS);
922
923 /* specify data direction, triple-check start bit is clear */
924 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
925 dmactl &= ~(ATA_DMA_WR | ATA_DMA_START);
926 if (!rw)
927 dmactl |= ATA_DMA_WR;
928
929 iowrite8(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
930
931 /* issue r/w command */
932 ata_exec_command(ap, &qc->tf);
933}
934
935static void nv_adma_bmdma_start(struct ata_queued_cmd *qc)
936{ 929{
937 struct ata_port *ap = qc->ap; 930 struct nv_adma_port_priv *pp = qc->ap->private_data;
938 struct nv_adma_port_priv *pp = ap->private_data;
939 u8 dmactl;
940
941 if(!(pp->flags & NV_ADMA_PORT_REGISTER_MODE)) {
942 WARN_ON(1);
943 return;
944 }
945
946 /* start host DMA transaction */
947 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
948 iowrite8(dmactl | ATA_DMA_START,
949 ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
950}
951
952static void nv_adma_bmdma_stop(struct ata_queued_cmd *qc)
953{
954 struct ata_port *ap = qc->ap;
955 struct nv_adma_port_priv *pp = ap->private_data;
956
957 if(!(pp->flags & NV_ADMA_PORT_REGISTER_MODE))
958 return;
959
960 /* clear start/stop bit */
961 iowrite8(ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD) & ~ATA_DMA_START,
962 ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
963
964 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
965 ata_altstatus(ap); /* dummy read */
966}
967
968static u8 nv_adma_bmdma_status(struct ata_port *ap)
969{
970 struct nv_adma_port_priv *pp = ap->private_data;
971
972 WARN_ON(!(pp->flags & NV_ADMA_PORT_REGISTER_MODE));
973 931
974 return ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); 932 if(pp->flags & NV_ADMA_PORT_REGISTER_MODE)
933 ata_bmdma_post_internal_cmd(qc);
975} 934}
976 935
977static int nv_adma_port_start(struct ata_port *ap) 936static int nv_adma_port_start(struct ata_port *ap)
@@ -1040,14 +999,15 @@ static int nv_adma_port_start(struct ata_port *ap)
1040 999
1041 /* clear GO for register mode, enable interrupt */ 1000 /* clear GO for register mode, enable interrupt */
1042 tmp = readw(mmio + NV_ADMA_CTL); 1001 tmp = readw(mmio + NV_ADMA_CTL);
1043 writew( (tmp & ~NV_ADMA_CTL_GO) | NV_ADMA_CTL_AIEN, mmio + NV_ADMA_CTL); 1002 writew( (tmp & ~NV_ADMA_CTL_GO) | NV_ADMA_CTL_AIEN |
1003 NV_ADMA_CTL_HOTPLUG_IEN, mmio + NV_ADMA_CTL);
1044 1004
1045 tmp = readw(mmio + NV_ADMA_CTL); 1005 tmp = readw(mmio + NV_ADMA_CTL);
1046 writew(tmp | NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL); 1006 writew(tmp | NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL);
1047 readl( mmio + NV_ADMA_CTL ); /* flush posted write */ 1007 readw( mmio + NV_ADMA_CTL ); /* flush posted write */
1048 udelay(1); 1008 udelay(1);
1049 writew(tmp & ~NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL); 1009 writew(tmp & ~NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL);
1050 readl( mmio + NV_ADMA_CTL ); /* flush posted write */ 1010 readw( mmio + NV_ADMA_CTL ); /* flush posted write */
1051 1011
1052 return 0; 1012 return 0;
1053} 1013}
@@ -1061,6 +1021,7 @@ static void nv_adma_port_stop(struct ata_port *ap)
1061 writew(0, mmio + NV_ADMA_CTL); 1021 writew(0, mmio + NV_ADMA_CTL);
1062} 1022}
1063 1023
1024#ifdef CONFIG_PM
1064static int nv_adma_port_suspend(struct ata_port *ap, pm_message_t mesg) 1025static int nv_adma_port_suspend(struct ata_port *ap, pm_message_t mesg)
1065{ 1026{
1066 struct nv_adma_port_priv *pp = ap->private_data; 1027 struct nv_adma_port_priv *pp = ap->private_data;
@@ -1099,17 +1060,19 @@ static int nv_adma_port_resume(struct ata_port *ap)
1099 1060
1100 /* clear GO for register mode, enable interrupt */ 1061 /* clear GO for register mode, enable interrupt */
1101 tmp = readw(mmio + NV_ADMA_CTL); 1062 tmp = readw(mmio + NV_ADMA_CTL);
1102 writew((tmp & ~NV_ADMA_CTL_GO) | NV_ADMA_CTL_AIEN, mmio + NV_ADMA_CTL); 1063 writew( (tmp & ~NV_ADMA_CTL_GO) | NV_ADMA_CTL_AIEN |
1064 NV_ADMA_CTL_HOTPLUG_IEN, mmio + NV_ADMA_CTL);
1103 1065
1104 tmp = readw(mmio + NV_ADMA_CTL); 1066 tmp = readw(mmio + NV_ADMA_CTL);
1105 writew(tmp | NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL); 1067 writew(tmp | NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL);
1106 readl( mmio + NV_ADMA_CTL ); /* flush posted write */ 1068 readw( mmio + NV_ADMA_CTL ); /* flush posted write */
1107 udelay(1); 1069 udelay(1);
1108 writew(tmp & ~NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL); 1070 writew(tmp & ~NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL);
1109 readl( mmio + NV_ADMA_CTL ); /* flush posted write */ 1071 readw( mmio + NV_ADMA_CTL ); /* flush posted write */
1110 1072
1111 return 0; 1073 return 0;
1112} 1074}
1075#endif
1113 1076
1114static void nv_adma_setup_port(struct ata_probe_ent *probe_ent, unsigned int port) 1077static void nv_adma_setup_port(struct ata_probe_ent *probe_ent, unsigned int port)
1115{ 1078{
@@ -1163,11 +1126,7 @@ static void nv_adma_fill_aprd(struct ata_queued_cmd *qc,
1163 int idx, 1126 int idx,
1164 struct nv_adma_prd *aprd) 1127 struct nv_adma_prd *aprd)
1165{ 1128{
1166 u8 flags; 1129 u8 flags = 0;
1167
1168 memset(aprd, 0, sizeof(struct nv_adma_prd));
1169
1170 flags = 0;
1171 if (qc->tf.flags & ATA_TFLAG_WRITE) 1130 if (qc->tf.flags & ATA_TFLAG_WRITE)
1172 flags |= NV_APRD_WRITE; 1131 flags |= NV_APRD_WRITE;
1173 if (idx == qc->n_elem - 1) 1132 if (idx == qc->n_elem - 1)
@@ -1178,6 +1137,7 @@ static void nv_adma_fill_aprd(struct ata_queued_cmd *qc,
1178 aprd->addr = cpu_to_le64(((u64)sg_dma_address(sg))); 1137 aprd->addr = cpu_to_le64(((u64)sg_dma_address(sg)));
1179 aprd->len = cpu_to_le32(((u32)sg_dma_len(sg))); /* len in bytes */ 1138 aprd->len = cpu_to_le32(((u32)sg_dma_len(sg))); /* len in bytes */
1180 aprd->flags = flags; 1139 aprd->flags = flags;
1140 aprd->packet_len = 0;
1181} 1141}
1182 1142
1183static void nv_adma_fill_sg(struct ata_queued_cmd *qc, struct nv_adma_cpb *cpb) 1143static void nv_adma_fill_sg(struct ata_queued_cmd *qc, struct nv_adma_cpb *cpb)
@@ -1198,6 +1158,8 @@ static void nv_adma_fill_sg(struct ata_queued_cmd *qc, struct nv_adma_cpb *cpb)
1198 } 1158 }
1199 if (idx > 5) 1159 if (idx > 5)
1200 cpb->next_aprd = cpu_to_le64(((u64)(pp->aprd_dma + NV_ADMA_SGTBL_SZ * qc->tag))); 1160 cpb->next_aprd = cpu_to_le64(((u64)(pp->aprd_dma + NV_ADMA_SGTBL_SZ * qc->tag)));
1161 else
1162 cpb->next_aprd = cpu_to_le64(0);
1201} 1163}
1202 1164
1203static int nv_adma_use_reg_mode(struct ata_queued_cmd *qc) 1165static int nv_adma_use_reg_mode(struct ata_queued_cmd *qc)
@@ -1230,7 +1192,10 @@ static void nv_adma_qc_prep(struct ata_queued_cmd *qc)
1230 return; 1192 return;
1231 } 1193 }
1232 1194
1233 memset(cpb, 0, sizeof(struct nv_adma_cpb)); 1195 cpb->resp_flags = NV_CPB_RESP_DONE;
1196 wmb();
1197 cpb->ctl_flags = 0;
1198 wmb();
1234 1199
1235 cpb->len = 3; 1200 cpb->len = 3;
1236 cpb->tag = qc->tag; 1201 cpb->tag = qc->tag;
@@ -1254,12 +1219,15 @@ static void nv_adma_qc_prep(struct ata_queued_cmd *qc)
1254 finished filling in all of the contents */ 1219 finished filling in all of the contents */
1255 wmb(); 1220 wmb();
1256 cpb->ctl_flags = ctl_flags; 1221 cpb->ctl_flags = ctl_flags;
1222 wmb();
1223 cpb->resp_flags = 0;
1257} 1224}
1258 1225
1259static unsigned int nv_adma_qc_issue(struct ata_queued_cmd *qc) 1226static unsigned int nv_adma_qc_issue(struct ata_queued_cmd *qc)
1260{ 1227{
1261 struct nv_adma_port_priv *pp = qc->ap->private_data; 1228 struct nv_adma_port_priv *pp = qc->ap->private_data;
1262 void __iomem *mmio = pp->ctl_block; 1229 void __iomem *mmio = pp->ctl_block;
1230 int curr_ncq = (qc->tf.protocol == ATA_PROT_NCQ);
1263 1231
1264 VPRINTK("ENTER\n"); 1232 VPRINTK("ENTER\n");
1265 1233
@@ -1274,6 +1242,14 @@ static unsigned int nv_adma_qc_issue(struct ata_queued_cmd *qc)
1274 /* write append register, command tag in lower 8 bits 1242 /* write append register, command tag in lower 8 bits
1275 and (number of cpbs to append -1) in top 8 bits */ 1243 and (number of cpbs to append -1) in top 8 bits */
1276 wmb(); 1244 wmb();
1245
1246 if(curr_ncq != pp->last_issue_ncq) {
1247 /* Seems to need some delay before switching between NCQ and non-NCQ
1248 commands, else we get command timeouts and such. */
1249 udelay(20);
1250 pp->last_issue_ncq = curr_ncq;
1251 }
1252
1277 writew(qc->tag, mmio + NV_ADMA_APPEND); 1253 writew(qc->tag, mmio + NV_ADMA_APPEND);
1278 1254
1279 DPRINTK("Issued tag %u\n",qc->tag); 1255 DPRINTK("Issued tag %u\n",qc->tag);
@@ -1447,6 +1423,30 @@ static void nv_adma_error_handler(struct ata_port *ap)
1447 int i; 1423 int i;
1448 u16 tmp; 1424 u16 tmp;
1449 1425
1426 if(ata_tag_valid(ap->active_tag) || ap->sactive) {
1427 u32 notifier = readl(mmio + NV_ADMA_NOTIFIER);
1428 u32 notifier_error = readl(mmio + NV_ADMA_NOTIFIER_ERROR);
1429 u32 gen_ctl = readl(pp->gen_block + NV_ADMA_GEN_CTL);
1430 u32 status = readw(mmio + NV_ADMA_STAT);
1431 u8 cpb_count = readb(mmio + NV_ADMA_CPB_COUNT);
1432 u8 next_cpb_idx = readb(mmio + NV_ADMA_NEXT_CPB_IDX);
1433
1434 ata_port_printk(ap, KERN_ERR, "EH in ADMA mode, notifier 0x%X "
1435 "notifier_error 0x%X gen_ctl 0x%X status 0x%X "
1436 "next cpb count 0x%X next cpb idx 0x%x\n",
1437 notifier, notifier_error, gen_ctl, status,
1438 cpb_count, next_cpb_idx);
1439
1440 for( i=0;i<NV_ADMA_MAX_CPBS;i++) {
1441 struct nv_adma_cpb *cpb = &pp->cpb[i];
1442 if( (ata_tag_valid(ap->active_tag) && i == ap->active_tag) ||
1443 ap->sactive & (1 << i) )
1444 ata_port_printk(ap, KERN_ERR,
1445 "CPB %d: ctl_flags 0x%x, resp_flags 0x%x\n",
1446 i, cpb->ctl_flags, cpb->resp_flags);
1447 }
1448 }
1449
1450 /* Push us back into port register mode for error handling. */ 1450 /* Push us back into port register mode for error handling. */
1451 nv_adma_register_mode(ap); 1451 nv_adma_register_mode(ap);
1452 1452
@@ -1460,10 +1460,10 @@ static void nv_adma_error_handler(struct ata_port *ap)
1460 /* Reset channel */ 1460 /* Reset channel */
1461 tmp = readw(mmio + NV_ADMA_CTL); 1461 tmp = readw(mmio + NV_ADMA_CTL);
1462 writew(tmp | NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL); 1462 writew(tmp | NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL);
1463 readl( mmio + NV_ADMA_CTL ); /* flush posted write */ 1463 readw( mmio + NV_ADMA_CTL ); /* flush posted write */
1464 udelay(1); 1464 udelay(1);
1465 writew(tmp & ~NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL); 1465 writew(tmp & ~NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL);
1466 readl( mmio + NV_ADMA_CTL ); /* flush posted write */ 1466 readw( mmio + NV_ADMA_CTL ); /* flush posted write */
1467 } 1467 }
1468 1468
1469 ata_bmdma_drive_eh(ap, ata_std_prereset, ata_std_softreset, 1469 ata_bmdma_drive_eh(ap, ata_std_prereset, ata_std_softreset,
@@ -1575,6 +1575,7 @@ static void nv_remove_one (struct pci_dev *pdev)
1575 kfree(hpriv); 1575 kfree(hpriv);
1576} 1576}
1577 1577
1578#ifdef CONFIG_PM
1578static int nv_pci_device_resume(struct pci_dev *pdev) 1579static int nv_pci_device_resume(struct pci_dev *pdev)
1579{ 1580{
1580 struct ata_host *host = dev_get_drvdata(&pdev->dev); 1581 struct ata_host *host = dev_get_drvdata(&pdev->dev);
@@ -1622,6 +1623,7 @@ static int nv_pci_device_resume(struct pci_dev *pdev)
1622 1623
1623 return 0; 1624 return 0;
1624} 1625}
1626#endif
1625 1627
1626static void nv_ck804_host_stop(struct ata_host *host) 1628static void nv_ck804_host_stop(struct ata_host *host)
1627{ 1629{
diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c
index cf9ed8c393..2339813ce9 100644
--- a/drivers/ata/sata_promise.c
+++ b/drivers/ata/sata_promise.c
@@ -45,7 +45,7 @@
45#include "sata_promise.h" 45#include "sata_promise.h"
46 46
47#define DRV_NAME "sata_promise" 47#define DRV_NAME "sata_promise"
48#define DRV_VERSION "1.05" 48#define DRV_VERSION "2.00"
49 49
50 50
51enum { 51enum {
@@ -218,6 +218,7 @@ static const struct ata_port_operations pdc_pata_ops = {
218 .freeze = pdc_freeze, 218 .freeze = pdc_freeze,
219 .thaw = pdc_thaw, 219 .thaw = pdc_thaw,
220 .error_handler = pdc_error_handler, 220 .error_handler = pdc_error_handler,
221 .post_internal_cmd = pdc_post_internal_cmd,
221 .data_xfer = ata_data_xfer, 222 .data_xfer = ata_data_xfer,
222 .irq_handler = pdc_interrupt, 223 .irq_handler = pdc_interrupt,
223 .irq_clear = pdc_irq_clear, 224 .irq_clear = pdc_irq_clear,
@@ -776,7 +777,8 @@ static int pdc_old_check_atapi_dma(struct ata_queued_cmd *qc)
776 return pdc_check_atapi_dma(qc); 777 return pdc_check_atapi_dma(qc);
777} 778}
778 779
779static void pdc_ata_setup_port(struct ata_ioports *port, void __iomem *base) 780static void pdc_ata_setup_port(struct ata_ioports *port, void __iomem *base,
781 void __iomem *scr_addr)
780{ 782{
781 port->cmd_addr = base; 783 port->cmd_addr = base;
782 port->data_addr = base; 784 port->data_addr = base;
@@ -791,6 +793,7 @@ static void pdc_ata_setup_port(struct ata_ioports *port, void __iomem *base)
791 port->status_addr = base + 0x1c; 793 port->status_addr = base + 0x1c;
792 port->altstatus_addr = 794 port->altstatus_addr =
793 port->ctl_addr = base + 0x38; 795 port->ctl_addr = base + 0x38;
796 port->scr_addr = scr_addr;
794} 797}
795 798
796 799
@@ -903,11 +906,8 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
903 906
904 base = probe_ent->iomap[PDC_MMIO_BAR]; 907 base = probe_ent->iomap[PDC_MMIO_BAR];
905 908
906 pdc_ata_setup_port(&probe_ent->port[0], base + 0x200); 909 pdc_ata_setup_port(&probe_ent->port[0], base + 0x200, base + 0x400);
907 pdc_ata_setup_port(&probe_ent->port[1], base + 0x280); 910 pdc_ata_setup_port(&probe_ent->port[1], base + 0x280, base + 0x500);
908
909 probe_ent->port[0].scr_addr = base + 0x400;
910 probe_ent->port[1].scr_addr = base + 0x500;
911 911
912 /* notice 4-port boards */ 912 /* notice 4-port boards */
913 switch (board_idx) { 913 switch (board_idx) {
@@ -916,12 +916,8 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
916 /* Fall through */ 916 /* Fall through */
917 case board_20319: 917 case board_20319:
918 probe_ent->n_ports = 4; 918 probe_ent->n_ports = 4;
919 919 pdc_ata_setup_port(&probe_ent->port[2], base + 0x300, base + 0x600);
920 pdc_ata_setup_port(&probe_ent->port[2], base + 0x300); 920 pdc_ata_setup_port(&probe_ent->port[3], base + 0x380, base + 0x700);
921 pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
922
923 probe_ent->port[2].scr_addr = base + 0x600;
924 probe_ent->port[3].scr_addr = base + 0x700;
925 break; 921 break;
926 case board_2057x: 922 case board_2057x:
927 hp->flags |= PDC_FLAG_GEN_II; 923 hp->flags |= PDC_FLAG_GEN_II;
@@ -931,7 +927,7 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
931 tmp = readb(base + PDC_FLASH_CTL+1); 927 tmp = readb(base + PDC_FLASH_CTL+1);
932 if (!(tmp & 0x80)) { 928 if (!(tmp & 0x80)) {
933 probe_ent->n_ports = 3; 929 probe_ent->n_ports = 3;
934 pdc_ata_setup_port(&probe_ent->port[2], base + 0x300); 930 pdc_ata_setup_port(&probe_ent->port[2], base + 0x300, NULL);
935 hp->port_flags[2] = ATA_FLAG_SLAVE_POSS; 931 hp->port_flags[2] = ATA_FLAG_SLAVE_POSS;
936 printk(KERN_INFO DRV_NAME " PATA port found\n"); 932 printk(KERN_INFO DRV_NAME " PATA port found\n");
937 } else 933 } else
@@ -941,12 +937,8 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
941 break; 937 break;
942 case board_20619: 938 case board_20619:
943 probe_ent->n_ports = 4; 939 probe_ent->n_ports = 4;
944 940 pdc_ata_setup_port(&probe_ent->port[2], base + 0x300, NULL);
945 pdc_ata_setup_port(&probe_ent->port[2], base + 0x300); 941 pdc_ata_setup_port(&probe_ent->port[3], base + 0x380, NULL);
946 pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
947
948 probe_ent->port[2].scr_addr = base + 0x600;
949 probe_ent->port[3].scr_addr = base + 0x700;
950 break; 942 break;
951 default: 943 default:
952 BUG(); 944 BUG();
diff --git a/drivers/ata/sata_qstor.c b/drivers/ata/sata_qstor.c
index 6097d8f2a0..8786b45f29 100644
--- a/drivers/ata/sata_qstor.c
+++ b/drivers/ata/sata_qstor.c
@@ -39,7 +39,7 @@
39#include <linux/libata.h> 39#include <linux/libata.h>
40 40
41#define DRV_NAME "sata_qstor" 41#define DRV_NAME "sata_qstor"
42#define DRV_VERSION "0.06" 42#define DRV_VERSION "0.07"
43 43
44enum { 44enum {
45 QS_MMIO_BAR = 4, 45 QS_MMIO_BAR = 4,
@@ -446,7 +446,7 @@ static inline unsigned int qs_intr_mmio(struct ata_host *host)
446 if ((status & ATA_BUSY)) 446 if ((status & ATA_BUSY))
447 continue; 447 continue;
448 DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n", 448 DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n",
449 ap->id, qc->tf.protocol, status); 449 ap->print_id, qc->tf.protocol, status);
450 450
451 /* complete taskfile transaction */ 451 /* complete taskfile transaction */
452 pp->state = qs_state_idle; 452 pp->state = qs_state_idle;
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
index dca3d3749f..917b7ea4ef 100644
--- a/drivers/ata/sata_sil.c
+++ b/drivers/ata/sata_sil.c
@@ -46,7 +46,7 @@
46#include <linux/libata.h> 46#include <linux/libata.h>
47 47
48#define DRV_NAME "sata_sil" 48#define DRV_NAME "sata_sil"
49#define DRV_VERSION "2.0" 49#define DRV_VERSION "2.1"
50 50
51enum { 51enum {
52 SIL_MMIO_BAR = 5, 52 SIL_MMIO_BAR = 5,
@@ -183,8 +183,10 @@ static struct scsi_host_template sil_sht = {
183 .slave_configure = ata_scsi_slave_config, 183 .slave_configure = ata_scsi_slave_config,
184 .slave_destroy = ata_scsi_slave_destroy, 184 .slave_destroy = ata_scsi_slave_destroy,
185 .bios_param = ata_std_bios_param, 185 .bios_param = ata_std_bios_param,
186#ifdef CONFIG_PM
186 .suspend = ata_scsi_device_suspend, 187 .suspend = ata_scsi_device_suspend,
187 .resume = ata_scsi_device_resume, 188 .resume = ata_scsi_device_resume,
189#endif
188}; 190};
189 191
190static const struct ata_port_operations sil_ops = { 192static const struct ata_port_operations sil_ops = {
@@ -339,7 +341,7 @@ static inline void __iomem *sil_scr_addr(struct ata_port *ap, unsigned int sc_re
339 break; 341 break;
340 } 342 }
341 343
342 return 0; 344 return NULL;
343} 345}
344 346
345static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg) 347static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg)
@@ -386,9 +388,15 @@ static void sil_host_intr(struct ata_port *ap, u32 bmdma2)
386 goto freeze; 388 goto freeze;
387 } 389 }
388 390
389 if (unlikely(!qc || qc->tf.ctl & ATA_NIEN)) 391 if (unlikely(!qc))
390 goto freeze; 392 goto freeze;
391 393
394 if (unlikely(qc->tf.flags & ATA_TFLAG_POLLING)) {
395 /* this sometimes happens, just clear IRQ */
396 ata_chk_status(ap);
397 return;
398 }
399
392 /* Check whether we are expecting interrupt in this state */ 400 /* Check whether we are expecting interrupt in this state */
393 switch (ap->hsm_task_state) { 401 switch (ap->hsm_task_state) {
394 case HSM_ST_FIRST: 402 case HSM_ST_FIRST:
diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
index e65e8d55da..75d9615996 100644
--- a/drivers/ata/sata_sil24.c
+++ b/drivers/ata/sata_sil24.c
@@ -30,7 +30,7 @@
30#include <linux/libata.h> 30#include <linux/libata.h>
31 31
32#define DRV_NAME "sata_sil24" 32#define DRV_NAME "sata_sil24"
33#define DRV_VERSION "0.3" 33#define DRV_VERSION "0.8"
34 34
35/* 35/*
36 * Port request block (PRB) 32 bytes 36 * Port request block (PRB) 32 bytes
@@ -380,8 +380,10 @@ static struct scsi_host_template sil24_sht = {
380 .slave_configure = ata_scsi_slave_config, 380 .slave_configure = ata_scsi_slave_config,
381 .slave_destroy = ata_scsi_slave_destroy, 381 .slave_destroy = ata_scsi_slave_destroy,
382 .bios_param = ata_std_bios_param, 382 .bios_param = ata_std_bios_param,
383#ifdef CONFIG_PM
383 .suspend = ata_scsi_device_suspend, 384 .suspend = ata_scsi_device_suspend,
384 .resume = ata_scsi_device_resume, 385 .resume = ata_scsi_device_resume,
386#endif
385}; 387};
386 388
387static const struct ata_port_operations sil24_ops = { 389static const struct ata_port_operations sil24_ops = {
@@ -647,7 +649,6 @@ static inline void sil24_fill_sg(struct ata_queued_cmd *qc,
647 struct sil24_sge *sge) 649 struct sil24_sge *sge)
648{ 650{
649 struct scatterlist *sg; 651 struct scatterlist *sg;
650 unsigned int idx = 0;
651 652
652 ata_for_each_sg(sg, qc) { 653 ata_for_each_sg(sg, qc) {
653 sge->addr = cpu_to_le64(sg_dma_address(sg)); 654 sge->addr = cpu_to_le64(sg_dma_address(sg));
@@ -656,9 +657,7 @@ static inline void sil24_fill_sg(struct ata_queued_cmd *qc,
656 sge->flags = cpu_to_le32(SGE_TRM); 657 sge->flags = cpu_to_le32(SGE_TRM);
657 else 658 else
658 sge->flags = 0; 659 sge->flags = 0;
659
660 sge++; 660 sge++;
661 idx++;
662 } 661 }
663} 662}
664 663
diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c
index 49c9e2bd70..1879e0cd56 100644
--- a/drivers/ata/sata_sis.c
+++ b/drivers/ata/sata_sis.c
@@ -40,9 +40,8 @@
40#include <linux/device.h> 40#include <linux/device.h>
41#include <scsi/scsi_host.h> 41#include <scsi/scsi_host.h>
42#include <linux/libata.h> 42#include <linux/libata.h>
43#include "libata.h" 43#include "sis.h"
44 44
45#undef DRV_NAME /* already defined in libata.h, for libata-core */
46#define DRV_NAME "sata_sis" 45#define DRV_NAME "sata_sis"
47#define DRV_VERSION "0.7" 46#define DRV_VERSION "0.7"
48 47
@@ -310,7 +309,7 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
310 case 0x10: 309 case 0x10:
311 ppi[1] = &sis_info133; 310 ppi[1] = &sis_info133;
312 break; 311 break;
313 312
314 case 0x30: 313 case 0x30:
315 ppi[0] = &sis_info133; 314 ppi[0] = &sis_info133;
316 break; 315 break;
diff --git a/drivers/ata/sata_svw.c b/drivers/ata/sata_svw.c
index 4e42899942..b121195cc5 100644
--- a/drivers/ata/sata_svw.c
+++ b/drivers/ata/sata_svw.c
@@ -53,7 +53,7 @@
53#endif /* CONFIG_PPC_OF */ 53#endif /* CONFIG_PPC_OF */
54 54
55#define DRV_NAME "sata_svw" 55#define DRV_NAME "sata_svw"
56#define DRV_VERSION "2.0" 56#define DRV_VERSION "2.1"
57 57
58enum { 58enum {
59 K2_FLAG_NO_ATAPI_DMA = (1 << 29), 59 K2_FLAG_NO_ATAPI_DMA = (1 << 29),
diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c
index 0ebd77b080..1a081c3a8c 100644
--- a/drivers/ata/sata_sx4.c
+++ b/drivers/ata/sata_sx4.c
@@ -44,7 +44,7 @@
44#include "sata_promise.h" 44#include "sata_promise.h"
45 45
46#define DRV_NAME "sata_sx4" 46#define DRV_NAME "sata_sx4"
47#define DRV_VERSION "0.9" 47#define DRV_VERSION "0.10"
48 48
49 49
50enum { 50enum {
@@ -421,7 +421,7 @@ static void pdc20621_dma_prep(struct ata_queued_cmd *qc)
421 421
422 WARN_ON(!(qc->flags & ATA_QCFLAG_DMAMAP)); 422 WARN_ON(!(qc->flags & ATA_QCFLAG_DMAMAP));
423 423
424 VPRINTK("ata%u: ENTER\n", ap->id); 424 VPRINTK("ata%u: ENTER\n", ap->print_id);
425 425
426 /* hard-code chip #0 */ 426 /* hard-code chip #0 */
427 mmio += PDC_CHIP0_OFS; 427 mmio += PDC_CHIP0_OFS;
@@ -478,7 +478,7 @@ static void pdc20621_nodata_prep(struct ata_queued_cmd *qc)
478 unsigned int portno = ap->port_no; 478 unsigned int portno = ap->port_no;
479 unsigned int i; 479 unsigned int i;
480 480
481 VPRINTK("ata%u: ENTER\n", ap->id); 481 VPRINTK("ata%u: ENTER\n", ap->print_id);
482 482
483 /* hard-code chip #0 */ 483 /* hard-code chip #0 */
484 mmio += PDC_CHIP0_OFS; 484 mmio += PDC_CHIP0_OFS;
@@ -605,7 +605,7 @@ static void pdc20621_packet_start(struct ata_queued_cmd *qc)
605 /* hard-code chip #0 */ 605 /* hard-code chip #0 */
606 mmio += PDC_CHIP0_OFS; 606 mmio += PDC_CHIP0_OFS;
607 607
608 VPRINTK("ata%u: ENTER\n", ap->id); 608 VPRINTK("ata%u: ENTER\n", ap->print_id);
609 609
610 wmb(); /* flush PRD, pkt writes */ 610 wmb(); /* flush PRD, pkt writes */
611 611
@@ -672,7 +672,7 @@ static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
672 672
673 /* step two - DMA from DIMM to host */ 673 /* step two - DMA from DIMM to host */
674 if (doing_hdma) { 674 if (doing_hdma) {
675 VPRINTK("ata%u: read hdma, 0x%x 0x%x\n", ap->id, 675 VPRINTK("ata%u: read hdma, 0x%x 0x%x\n", ap->print_id,
676 readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT)); 676 readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT));
677 /* get drive status; clear intr; complete txn */ 677 /* get drive status; clear intr; complete txn */
678 qc->err_mask |= ac_err_mask(ata_wait_idle(ap)); 678 qc->err_mask |= ac_err_mask(ata_wait_idle(ap));
@@ -683,7 +683,7 @@ static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
683 /* step one - exec ATA command */ 683 /* step one - exec ATA command */
684 else { 684 else {
685 u8 seq = (u8) (port_no + 1 + 4); 685 u8 seq = (u8) (port_no + 1 + 4);
686 VPRINTK("ata%u: read ata, 0x%x 0x%x\n", ap->id, 686 VPRINTK("ata%u: read ata, 0x%x 0x%x\n", ap->print_id,
687 readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT)); 687 readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT));
688 688
689 /* submit hdma pkt */ 689 /* submit hdma pkt */
@@ -698,7 +698,7 @@ static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
698 /* step one - DMA from host to DIMM */ 698 /* step one - DMA from host to DIMM */
699 if (doing_hdma) { 699 if (doing_hdma) {
700 u8 seq = (u8) (port_no + 1); 700 u8 seq = (u8) (port_no + 1);
701 VPRINTK("ata%u: write hdma, 0x%x 0x%x\n", ap->id, 701 VPRINTK("ata%u: write hdma, 0x%x 0x%x\n", ap->print_id,
702 readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT)); 702 readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT));
703 703
704 /* submit ata pkt */ 704 /* submit ata pkt */
@@ -711,7 +711,7 @@ static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
711 711
712 /* step two - execute ATA command */ 712 /* step two - execute ATA command */
713 else { 713 else {
714 VPRINTK("ata%u: write ata, 0x%x 0x%x\n", ap->id, 714 VPRINTK("ata%u: write ata, 0x%x 0x%x\n", ap->print_id,
715 readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT)); 715 readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT));
716 /* get drive status; clear intr; complete txn */ 716 /* get drive status; clear intr; complete txn */
717 qc->err_mask |= ac_err_mask(ata_wait_idle(ap)); 717 qc->err_mask |= ac_err_mask(ata_wait_idle(ap));
diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c
index 80131eec68..d659ace80f 100644
--- a/drivers/ata/sata_uli.c
+++ b/drivers/ata/sata_uli.c
@@ -36,7 +36,7 @@
36#include <linux/libata.h> 36#include <linux/libata.h>
37 37
38#define DRV_NAME "sata_uli" 38#define DRV_NAME "sata_uli"
39#define DRV_VERSION "1.0" 39#define DRV_VERSION "1.1"
40 40
41enum { 41enum {
42 uli_5289 = 0, 42 uli_5289 = 0,
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
index baca6d79bb..598e6a26a4 100644
--- a/drivers/ata/sata_via.c
+++ b/drivers/ata/sata_via.c
@@ -46,7 +46,7 @@
46#include <linux/libata.h> 46#include <linux/libata.h>
47 47
48#define DRV_NAME "sata_via" 48#define DRV_NAME "sata_via"
49#define DRV_VERSION "2.0" 49#define DRV_VERSION "2.1"
50 50
51enum board_ids_enum { 51enum board_ids_enum {
52 vt6420, 52 vt6420,
@@ -60,7 +60,7 @@ enum {
60 SATA_PATA_SHARING = 0x49, /* PATA/SATA sharing func ctrl */ 60 SATA_PATA_SHARING = 0x49, /* PATA/SATA sharing func ctrl */
61 PATA_UDMA_TIMING = 0xB3, /* PATA timing for DMA/ cable detect */ 61 PATA_UDMA_TIMING = 0xB3, /* PATA timing for DMA/ cable detect */
62 PATA_PIO_TIMING = 0xAB, /* PATA timing register */ 62 PATA_PIO_TIMING = 0xAB, /* PATA timing register */
63 63
64 PORT0 = (1 << 1), 64 PORT0 = (1 << 1),
65 PORT1 = (1 << 0), 65 PORT1 = (1 << 0),
66 ALL_PORTS = PORT0 | PORT1, 66 ALL_PORTS = PORT0 | PORT1,
@@ -151,7 +151,7 @@ static const struct ata_port_operations vt6420_sata_ops = {
151 151
152static const struct ata_port_operations vt6421_pata_ops = { 152static const struct ata_port_operations vt6421_pata_ops = {
153 .port_disable = ata_port_disable, 153 .port_disable = ata_port_disable,
154 154
155 .set_piomode = vt6421_set_pio_mode, 155 .set_piomode = vt6421_set_pio_mode,
156 .set_dmamode = vt6421_set_dma_mode, 156 .set_dmamode = vt6421_set_dma_mode,
157 157
@@ -185,7 +185,7 @@ static const struct ata_port_operations vt6421_pata_ops = {
185 185
186static const struct ata_port_operations vt6421_sata_ops = { 186static const struct ata_port_operations vt6421_sata_ops = {
187 .port_disable = ata_port_disable, 187 .port_disable = ata_port_disable,
188 188
189 .tf_load = ata_tf_load, 189 .tf_load = ata_tf_load,
190 .tf_read = ata_tf_read, 190 .tf_read = ata_tf_read,
191 .check_status = ata_check_status, 191 .check_status = ata_check_status,
@@ -423,16 +423,21 @@ static struct ata_probe_ent *vt6420_init_probe_ent(struct pci_dev *pdev)
423{ 423{
424 struct ata_probe_ent *probe_ent; 424 struct ata_probe_ent *probe_ent;
425 struct ata_port_info *ppi[2]; 425 struct ata_port_info *ppi[2];
426 void __iomem * const *iomap; 426 void __iomem *bar5;
427 427
428 ppi[0] = ppi[1] = &vt6420_port_info; 428 ppi[0] = ppi[1] = &vt6420_port_info;
429 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 429 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
430 if (!probe_ent) 430 if (!probe_ent)
431 return NULL; 431 return NULL;
432 432
433 iomap = pcim_iomap_table(pdev); 433 bar5 = pcim_iomap(pdev, 5, 0);
434 probe_ent->port[0].scr_addr = svia_scr_addr(iomap[5], 0); 434 if (!bar5) {
435 probe_ent->port[1].scr_addr = svia_scr_addr(iomap[5], 1); 435 dev_printk(KERN_ERR, &pdev->dev, "failed to iomap PCI BAR 5\n");
436 return NULL;
437 }
438
439 probe_ent->port[0].scr_addr = svia_scr_addr(bar5, 0);
440 probe_ent->port[1].scr_addr = svia_scr_addr(bar5, 1);
436 441
437 return probe_ent; 442 return probe_ent;
438} 443}
@@ -460,6 +465,13 @@ static struct ata_probe_ent *vt6421_init_probe_ent(struct pci_dev *pdev)
460 probe_ent->mwdma_mask = 0x07; 465 probe_ent->mwdma_mask = 0x07;
461 probe_ent->udma_mask = 0x7f; 466 probe_ent->udma_mask = 0x7f;
462 467
468 for (i = 0; i < 6; i++)
469 if (!pcim_iomap(pdev, i, 0)) {
470 dev_printk(KERN_ERR, &pdev->dev,
471 "failed to iomap PCI BAR %d\n", i);
472 return NULL;
473 }
474
463 for (i = 0; i < N_PORTS; i++) 475 for (i = 0; i < N_PORTS; i++)
464 vt6421_init_addrs(probe_ent, pcim_iomap_table(pdev), i); 476 vt6421_init_addrs(probe_ent, pcim_iomap_table(pdev), i);
465 477
@@ -522,7 +534,7 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
522 if (rc) 534 if (rc)
523 return rc; 535 return rc;
524 536
525 rc = pcim_iomap_regions(pdev, 0x1f, DRV_NAME); 537 rc = pci_request_regions(pdev, DRV_NAME);
526 if (rc) { 538 if (rc) {
527 pcim_pin_device(pdev); 539 pcim_pin_device(pdev);
528 return rc; 540 return rc;
diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c
index 2fd037bde0..170bad1b41 100644
--- a/drivers/ata/sata_vsc.c
+++ b/drivers/ata/sata_vsc.c
@@ -47,7 +47,7 @@
47#include <linux/libata.h> 47#include <linux/libata.h>
48 48
49#define DRV_NAME "sata_vsc" 49#define DRV_NAME "sata_vsc"
50#define DRV_VERSION "2.0" 50#define DRV_VERSION "2.1"
51 51
52enum { 52enum {
53 VSC_MMIO_BAR = 0, 53 VSC_MMIO_BAR = 0,
@@ -98,10 +98,6 @@ enum {
98 VSC_SATA_INT_PHY_CHANGE), 98 VSC_SATA_INT_PHY_CHANGE),
99}; 99};
100 100
101#define is_vsc_sata_int_err(port_idx, int_status) \
102 (int_status & (VSC_SATA_INT_ERROR << (8 * port_idx)))
103
104
105static u32 vsc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg) 101static u32 vsc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
106{ 102{
107 if (sc_reg > SCR_CONTROL) 103 if (sc_reg > SCR_CONTROL)
@@ -119,6 +115,28 @@ static void vsc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg,
119} 115}
120 116
121 117
118static void vsc_freeze(struct ata_port *ap)
119{
120 void __iomem *mask_addr;
121
122 mask_addr = ap->host->iomap[VSC_MMIO_BAR] +
123 VSC_SATA_INT_MASK_OFFSET + ap->port_no;
124
125 writeb(0, mask_addr);
126}
127
128
129static void vsc_thaw(struct ata_port *ap)
130{
131 void __iomem *mask_addr;
132
133 mask_addr = ap->host->iomap[VSC_MMIO_BAR] +
134 VSC_SATA_INT_MASK_OFFSET + ap->port_no;
135
136 writeb(0xff, mask_addr);
137}
138
139
122static void vsc_intr_mask_update(struct ata_port *ap, u8 ctl) 140static void vsc_intr_mask_update(struct ata_port *ap, u8 ctl)
123{ 141{
124 void __iomem *mask_addr; 142 void __iomem *mask_addr;
@@ -203,6 +221,36 @@ static void vsc_sata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
203 } 221 }
204} 222}
205 223
224static inline void vsc_error_intr(u8 port_status, struct ata_port *ap)
225{
226 if (port_status & (VSC_SATA_INT_PHY_CHANGE | VSC_SATA_INT_ERROR_M))
227 ata_port_freeze(ap);
228 else
229 ata_port_abort(ap);
230}
231
232static void vsc_port_intr(u8 port_status, struct ata_port *ap)
233{
234 struct ata_queued_cmd *qc;
235 int handled = 0;
236
237 if (unlikely(port_status & VSC_SATA_INT_ERROR)) {
238 vsc_error_intr(port_status, ap);
239 return;
240 }
241
242 qc = ata_qc_from_tag(ap, ap->active_tag);
243 if (qc && likely(!(qc->tf.flags & ATA_TFLAG_POLLING)))
244 handled = ata_host_intr(ap, qc);
245
246 /* We received an interrupt during a polled command,
247 * or some other spurious condition. Interrupt reporting
248 * with this hardware is fairly reliable so it is safe to
249 * simply clear the interrupt
250 */
251 if (unlikely(!handled))
252 ata_chk_status(ap);
253}
206 254
207/* 255/*
208 * vsc_sata_interrupt 256 * vsc_sata_interrupt
@@ -214,59 +262,36 @@ static irqreturn_t vsc_sata_interrupt (int irq, void *dev_instance)
214 struct ata_host *host = dev_instance; 262 struct ata_host *host = dev_instance;
215 unsigned int i; 263 unsigned int i;
216 unsigned int handled = 0; 264 unsigned int handled = 0;
217 u32 int_status; 265 u32 status;
218
219 spin_lock(&host->lock);
220 266
221 int_status = readl(host->iomap[VSC_MMIO_BAR] + 267 status = readl(host->iomap[VSC_MMIO_BAR] + VSC_SATA_INT_STAT_OFFSET);
222 VSC_SATA_INT_STAT_OFFSET);
223 268
224 for (i = 0; i < host->n_ports; i++) { 269 if (unlikely(status == 0xffffffff || status == 0)) {
225 if (int_status & ((u32) 0xFF << (8 * i))) { 270 if (status)
226 struct ata_port *ap; 271 dev_printk(KERN_ERR, host->dev,
272 ": IRQ status == 0xffffffff, "
273 "PCI fault or device removal?\n");
274 goto out;
275 }
227 276
228 ap = host->ports[i]; 277 spin_lock(&host->lock);
229 278
230 if (is_vsc_sata_int_err(i, int_status)) { 279 for (i = 0; i < host->n_ports; i++) {
231 u32 err_status; 280 u8 port_status = (status >> (8 * i)) & 0xff;
232 printk(KERN_DEBUG "%s: ignoring interrupt(s)\n", __FUNCTION__); 281 if (port_status) {
233 err_status = ap ? vsc_sata_scr_read(ap, SCR_ERROR) : 0; 282 struct ata_port *ap = host->ports[i];
234 vsc_sata_scr_write(ap, SCR_ERROR, err_status);
235 handled++;
236 }
237 283
238 if (ap && !(ap->flags & ATA_FLAG_DISABLED)) { 284 if (ap && !(ap->flags & ATA_FLAG_DISABLED)) {
239 struct ata_queued_cmd *qc; 285 vsc_port_intr(port_status, ap);
240 286 handled++;
241 qc = ata_qc_from_tag(ap, ap->active_tag); 287 } else
242 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) 288 dev_printk(KERN_ERR, host->dev,
243 handled += ata_host_intr(ap, qc); 289 ": interrupt from disabled port %d\n", i);
244 else if (is_vsc_sata_int_err(i, int_status)) {
245 /*
246 * On some chips (i.e. Intel 31244), an error
247 * interrupt will sneak in at initialization
248 * time (phy state changes). Clearing the SCR
249 * error register is not required, but it prevents
250 * the phy state change interrupts from recurring
251 * later.
252 */
253 u32 err_status;
254 err_status = vsc_sata_scr_read(ap, SCR_ERROR);
255 printk(KERN_DEBUG "%s: clearing interrupt, "
256 "status %x; sata err status %x\n",
257 __FUNCTION__,
258 int_status, err_status);
259 vsc_sata_scr_write(ap, SCR_ERROR, err_status);
260 /* Clear interrupt status */
261 ata_chk_status(ap);
262 handled++;
263 }
264 }
265 } 290 }
266 } 291 }
267 292
268 spin_unlock(&host->lock); 293 spin_unlock(&host->lock);
269 294out:
270 return IRQ_RETVAL(handled); 295 return IRQ_RETVAL(handled);
271} 296}
272 297
@@ -304,8 +329,8 @@ static const struct ata_port_operations vsc_sata_ops = {
304 .qc_prep = ata_qc_prep, 329 .qc_prep = ata_qc_prep,
305 .qc_issue = ata_qc_issue_prot, 330 .qc_issue = ata_qc_issue_prot,
306 .data_xfer = ata_data_xfer, 331 .data_xfer = ata_data_xfer,
307 .freeze = ata_bmdma_freeze, 332 .freeze = vsc_freeze,
308 .thaw = ata_bmdma_thaw, 333 .thaw = vsc_thaw,
309 .error_handler = ata_bmdma_error_handler, 334 .error_handler = ata_bmdma_error_handler,
310 .post_internal_cmd = ata_bmdma_post_internal_cmd, 335 .post_internal_cmd = ata_bmdma_post_internal_cmd,
311 .irq_handler = vsc_sata_interrupt, 336 .irq_handler = vsc_sata_interrupt,
diff --git a/drivers/ata/sis.h b/drivers/ata/sis.h
new file mode 100644
index 0000000000..231da8fc22
--- /dev/null
+++ b/drivers/ata/sis.h
@@ -0,0 +1,5 @@
1
2struct ata_port_info;
3
4/* pata_sis.c */
5extern struct ata_port_info sis_info133;
diff --git a/drivers/atm/he.c b/drivers/atm/he.c
index db33f6f4dd..8510026b69 100644
--- a/drivers/atm/he.c
+++ b/drivers/atm/he.c
@@ -3017,7 +3017,7 @@ read_prom_byte(struct he_dev *he_dev, int addr)
3017 he_writel(he_dev, val, HOST_CNTL); 3017 he_writel(he_dev, val, HOST_CNTL);
3018 3018
3019 /* Send READ instruction */ 3019 /* Send READ instruction */
3020 for (i = 0; i < sizeof(readtab)/sizeof(readtab[0]); i++) { 3020 for (i = 0; i < ARRAY_SIZE(readtab); i++) {
3021 he_writel(he_dev, val | readtab[i], HOST_CNTL); 3021 he_writel(he_dev, val | readtab[i], HOST_CNTL);
3022 udelay(EEPROM_DELAY); 3022 udelay(EEPROM_DELAY);
3023 } 3023 }
diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index f407861219..b4b80140c3 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -388,7 +388,7 @@ idt77252_eeprom_read_status(struct idt77252_dev *card)
388 388
389 gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO); 389 gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
390 390
391 for (i = 0; i < sizeof(rdsrtab)/sizeof(rdsrtab[0]); i++) { 391 for (i = 0; i < ARRAY_SIZE(rdsrtab); i++) {
392 idt77252_write_gp(card, gp | rdsrtab[i]); 392 idt77252_write_gp(card, gp | rdsrtab[i]);
393 udelay(5); 393 udelay(5);
394 } 394 }
@@ -422,7 +422,7 @@ idt77252_eeprom_read_byte(struct idt77252_dev *card, u8 offset)
422 422
423 gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO); 423 gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
424 424
425 for (i = 0; i < sizeof(rdtab)/sizeof(rdtab[0]); i++) { 425 for (i = 0; i < ARRAY_SIZE(rdtab); i++) {
426 idt77252_write_gp(card, gp | rdtab[i]); 426 idt77252_write_gp(card, gp | rdtab[i]);
427 udelay(5); 427 udelay(5);
428 } 428 }
@@ -469,14 +469,14 @@ idt77252_eeprom_write_byte(struct idt77252_dev *card, u8 offset, u8 data)
469 469
470 gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO); 470 gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
471 471
472 for (i = 0; i < sizeof(wrentab)/sizeof(wrentab[0]); i++) { 472 for (i = 0; i < ARRAY_SIZE(wrentab); i++) {
473 idt77252_write_gp(card, gp | wrentab[i]); 473 idt77252_write_gp(card, gp | wrentab[i]);
474 udelay(5); 474 udelay(5);
475 } 475 }
476 idt77252_write_gp(card, gp | SAR_GP_EECS); 476 idt77252_write_gp(card, gp | SAR_GP_EECS);
477 udelay(5); 477 udelay(5);
478 478
479 for (i = 0; i < sizeof(wrtab)/sizeof(wrtab[0]); i++) { 479 for (i = 0; i < ARRAY_SIZE(wrtab); i++) {
480 idt77252_write_gp(card, gp | wrtab[i]); 480 idt77252_write_gp(card, gp | wrtab[i]);
481 udelay(5); 481 udelay(5);
482 } 482 }
diff --git a/drivers/atm/nicstarmac.c b/drivers/atm/nicstarmac.c
index 2c5e3ae775..480947f4e0 100644
--- a/drivers/atm/nicstarmac.c
+++ b/drivers/atm/nicstarmac.c
@@ -7,6 +7,8 @@
7 * Read this ForeRunner's MAC address from eprom/eeprom 7 * Read this ForeRunner's MAC address from eprom/eeprom
8 */ 8 */
9 9
10#include <linux/kernel.h>
11
10typedef void __iomem *virt_addr_t; 12typedef void __iomem *virt_addr_t;
11 13
12#define CYCLE_DELAY 5 14#define CYCLE_DELAY 5
@@ -176,7 +178,7 @@ read_eprom_byte(virt_addr_t base, u_int8_t offset)
176 val = NICSTAR_REG_READ( base, NICSTAR_REG_GENERAL_PURPOSE ) & 0xFFFFFFF0; 178 val = NICSTAR_REG_READ( base, NICSTAR_REG_GENERAL_PURPOSE ) & 0xFFFFFFF0;
177 179
178 /* Send READ instruction */ 180 /* Send READ instruction */
179 for (i=0; i<sizeof readtab/sizeof readtab[0]; i++) 181 for (i=0; i<ARRAY_SIZE(readtab); i++)
180 { 182 {
181 NICSTAR_REG_WRITE( base, NICSTAR_REG_GENERAL_PURPOSE, 183 NICSTAR_REG_WRITE( base, NICSTAR_REG_GENERAL_PURPOSE,
182 (val | readtab[i]) ); 184 (val | readtab[i]) );
diff --git a/drivers/auxdisplay/cfag12864b.c b/drivers/auxdisplay/cfag12864b.c
index 889583dfc1..cb44cb4f6a 100644
--- a/drivers/auxdisplay/cfag12864b.c
+++ b/drivers/auxdisplay/cfag12864b.c
@@ -312,6 +312,17 @@ EXPORT_SYMBOL_GPL(cfag12864b_disable);
312EXPORT_SYMBOL_GPL(cfag12864b_isenabled); 312EXPORT_SYMBOL_GPL(cfag12864b_isenabled);
313 313
314/* 314/*
315 * Is the module inited?
316 */
317
318static unsigned char cfag12864b_inited;
319unsigned char cfag12864b_isinited(void)
320{
321 return cfag12864b_inited;
322}
323EXPORT_SYMBOL_GPL(cfag12864b_isinited);
324
325/*
315 * Module Init & Exit 326 * Module Init & Exit
316 */ 327 */
317 328
@@ -319,6 +330,13 @@ static int __init cfag12864b_init(void)
319{ 330{
320 int ret = -EINVAL; 331 int ret = -EINVAL;
321 332
333 /* ks0108_init() must be called first */
334 if (!ks0108_isinited()) {
335 printk(KERN_ERR CFAG12864B_NAME ": ERROR: "
336 "ks0108 is not initialized\n");
337 goto none;
338 }
339
322 if (PAGE_SIZE < CFAG12864B_SIZE) { 340 if (PAGE_SIZE < CFAG12864B_SIZE) {
323 printk(KERN_ERR CFAG12864B_NAME ": ERROR: " 341 printk(KERN_ERR CFAG12864B_NAME ": ERROR: "
324 "page size (%i) < cfag12864b size (%i)\n", 342 "page size (%i) < cfag12864b size (%i)\n",
@@ -354,6 +372,7 @@ static int __init cfag12864b_init(void)
354 cfag12864b_clear(); 372 cfag12864b_clear();
355 cfag12864b_on(); 373 cfag12864b_on();
356 374
375 cfag12864b_inited = 1;
357 return 0; 376 return 0;
358 377
359cachealloced: 378cachealloced:
diff --git a/drivers/auxdisplay/cfag12864bfb.c b/drivers/auxdisplay/cfag12864bfb.c
index 94765e7831..66fafbb1d0 100644
--- a/drivers/auxdisplay/cfag12864bfb.c
+++ b/drivers/auxdisplay/cfag12864bfb.c
@@ -137,7 +137,14 @@ static struct platform_device *cfag12864bfb_device;
137 137
138static int __init cfag12864bfb_init(void) 138static int __init cfag12864bfb_init(void)
139{ 139{
140 int ret; 140 int ret = -EINVAL;
141
142 /* cfag12864b_init() must be called first */
143 if (!cfag12864b_isinited()) {
144 printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
145 "cfag12864b is not initialized\n");
146 goto none;
147 }
141 148
142 if (cfag12864b_enable()) { 149 if (cfag12864b_enable()) {
143 printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: " 150 printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
@@ -162,6 +169,7 @@ static int __init cfag12864bfb_init(void)
162 } 169 }
163 } 170 }
164 171
172none:
165 return ret; 173 return ret;
166} 174}
167 175
diff --git a/drivers/auxdisplay/ks0108.c b/drivers/auxdisplay/ks0108.c
index a637575b91..e6c3646ef1 100644
--- a/drivers/auxdisplay/ks0108.c
+++ b/drivers/auxdisplay/ks0108.c
@@ -111,6 +111,17 @@ EXPORT_SYMBOL_GPL(ks0108_address);
111EXPORT_SYMBOL_GPL(ks0108_page); 111EXPORT_SYMBOL_GPL(ks0108_page);
112 112
113/* 113/*
114 * Is the module inited?
115 */
116
117static unsigned char ks0108_inited;
118unsigned char ks0108_isinited(void)
119{
120 return ks0108_inited;
121}
122EXPORT_SYMBOL_GPL(ks0108_isinited);
123
124/*
114 * Module Init & Exit 125 * Module Init & Exit
115 */ 126 */
116 127
@@ -142,6 +153,7 @@ static int __init ks0108_init(void)
142 goto registered; 153 goto registered;
143 } 154 }
144 155
156 ks0108_inited = 1;
145 return 0; 157 return 0;
146 158
147registered: 159registered:
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 472810f8e6..253868e03c 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -324,27 +324,25 @@ int bus_for_each_drv(struct bus_type * bus, struct device_driver * start,
324 return error; 324 return error;
325} 325}
326 326
327static int device_add_attrs(struct bus_type * bus, struct device * dev) 327static int device_add_attrs(struct bus_type *bus, struct device *dev)
328{ 328{
329 int error = 0; 329 int error = 0;
330 int i; 330 int i;
331 331
332 if (bus->dev_attrs) { 332 if (!bus->dev_attrs)
333 for (i = 0; attr_name(bus->dev_attrs[i]); i++) { 333 return 0;
334 error = device_create_file(dev,&bus->dev_attrs[i]); 334
335 if (error) 335 for (i = 0; attr_name(bus->dev_attrs[i]); i++) {
336 goto Err; 336 error = device_create_file(dev,&bus->dev_attrs[i]);
337 if (error) {
338 while (--i >= 0)
339 device_remove_file(dev, &bus->dev_attrs[i]);
340 break;
337 } 341 }
338 } 342 }
339 Done:
340 return error; 343 return error;
341 Err:
342 while (--i >= 0)
343 device_remove_file(dev,&bus->dev_attrs[i]);
344 goto Done;
345} 344}
346 345
347
348static void device_remove_attrs(struct bus_type * bus, struct device * dev) 346static void device_remove_attrs(struct bus_type * bus, struct device * dev)
349{ 347{
350 int i; 348 int i;
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 96def1ddba..d5968128be 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -163,8 +163,7 @@ int class_register(struct class * cls)
163void class_unregister(struct class * cls) 163void class_unregister(struct class * cls)
164{ 164{
165 pr_debug("device class '%s': unregistering\n", cls->name); 165 pr_debug("device class '%s': unregistering\n", cls->name);
166 if (cls->virtual_dir) 166 kobject_unregister(cls->virtual_dir);
167 kobject_unregister(cls->virtual_dir);
168 remove_class_attrs(cls); 167 remove_class_attrs(cls);
169 subsystem_unregister(&cls->subsys); 168 subsystem_unregister(&cls->subsys);
170} 169}
@@ -841,48 +840,6 @@ void class_device_destroy(struct class *cls, dev_t devt)
841 class_device_unregister(class_dev); 840 class_device_unregister(class_dev);
842} 841}
843 842
844int class_device_rename(struct class_device *class_dev, char *new_name)
845{
846 int error = 0;
847 char *old_class_name = NULL, *new_class_name = NULL;
848
849 class_dev = class_device_get(class_dev);
850 if (!class_dev)
851 return -EINVAL;
852
853 pr_debug("CLASS: renaming '%s' to '%s'\n", class_dev->class_id,
854 new_name);
855
856#ifdef CONFIG_SYSFS_DEPRECATED
857 if (class_dev->dev)
858 old_class_name = make_class_name(class_dev->class->name,
859 &class_dev->kobj);
860#endif
861
862 strlcpy(class_dev->class_id, new_name, KOBJ_NAME_LEN);
863
864 error = kobject_rename(&class_dev->kobj, new_name);
865
866#ifdef CONFIG_SYSFS_DEPRECATED
867 if (class_dev->dev) {
868 new_class_name = make_class_name(class_dev->class->name,
869 &class_dev->kobj);
870 if (new_class_name)
871 sysfs_create_link(&class_dev->dev->kobj,
872 &class_dev->kobj, new_class_name);
873 if (old_class_name)
874 sysfs_remove_link(&class_dev->dev->kobj,
875 old_class_name);
876 }
877#endif
878 class_device_put(class_dev);
879
880 kfree(old_class_name);
881 kfree(new_class_name);
882
883 return error;
884}
885
886struct class_device * class_device_get(struct class_device *class_dev) 843struct class_device * class_device_get(struct class_device *class_dev)
887{ 844{
888 if (class_dev) 845 if (class_dev)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index a8ac34ba61..89ebe36827 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -28,6 +28,20 @@ int (*platform_notify)(struct device * dev) = NULL;
28int (*platform_notify_remove)(struct device * dev) = NULL; 28int (*platform_notify_remove)(struct device * dev) = NULL;
29 29
30/* 30/*
31 * Detect the LANANA-assigned LOCAL/EXPERIMENTAL majors
32 */
33bool is_lanana_major(unsigned int major)
34{
35 if (major >= 60 && major <= 63)
36 return 1;
37 if (major >= 120 && major <= 127)
38 return 1;
39 if (major >= 240 && major <= 254)
40 return 1;
41 return 0;
42}
43
44/*
31 * sysfs bindings for devices. 45 * sysfs bindings for devices.
32 */ 46 */
33 47
@@ -623,12 +637,41 @@ int device_add(struct device *dev)
623 BUS_NOTIFY_DEL_DEVICE, dev); 637 BUS_NOTIFY_DEL_DEVICE, dev);
624 device_remove_groups(dev); 638 device_remove_groups(dev);
625 GroupError: 639 GroupError:
626 device_remove_attrs(dev); 640 device_remove_attrs(dev);
627 AttrsError: 641 AttrsError:
628 if (dev->devt_attr) { 642 if (dev->devt_attr) {
629 device_remove_file(dev, dev->devt_attr); 643 device_remove_file(dev, dev->devt_attr);
630 kfree(dev->devt_attr); 644 kfree(dev->devt_attr);
631 } 645 }
646
647 if (dev->class) {
648 sysfs_remove_link(&dev->kobj, "subsystem");
649 /* If this is not a "fake" compatible device, remove the
650 * symlink from the class to the device. */
651 if (dev->kobj.parent != &dev->class->subsys.kset.kobj)
652 sysfs_remove_link(&dev->class->subsys.kset.kobj,
653 dev->bus_id);
654#ifdef CONFIG_SYSFS_DEPRECATED
655 if (parent) {
656 char *class_name = make_class_name(dev->class->name,
657 &dev->kobj);
658 if (class_name)
659 sysfs_remove_link(&dev->parent->kobj,
660 class_name);
661 kfree(class_name);
662 sysfs_remove_link(&dev->kobj, "device");
663 }
664#endif
665
666 down(&dev->class->sem);
667 /* notify any interfaces that the device is now gone */
668 list_for_each_entry(class_intf, &dev->class->interfaces, node)
669 if (class_intf->remove_dev)
670 class_intf->remove_dev(dev, class_intf);
671 /* remove the device from the class list */
672 list_del_init(&dev->node);
673 up(&dev->class->sem);
674 }
632 ueventattrError: 675 ueventattrError:
633 device_remove_file(dev, &dev->uevent_attr); 676 device_remove_file(dev, &dev->uevent_attr);
634 attrError: 677 attrError:
@@ -744,6 +787,13 @@ void device_del(struct device * dev)
744 device_remove_attrs(dev); 787 device_remove_attrs(dev);
745 bus_remove_device(dev); 788 bus_remove_device(dev);
746 789
790 /*
791 * Some platform devices are driven without driver attached
792 * and managed resources may have been acquired. Make sure
793 * all resources are released.
794 */
795 devres_release_all(dev);
796
747 /* Notify the platform of the removal, in case they 797 /* Notify the platform of the removal, in case they
748 * need to do anything... 798 * need to do anything...
749 */ 799 */
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 7fd095efae..fe7ef33941 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -103,7 +103,7 @@ static SYSDEV_ATTR(crash_notes, 0400, show_crash_notes, NULL);
103#endif 103#endif
104 104
105/* 105/*
106 * register_cpu - Setup a driverfs device for a CPU. 106 * register_cpu - Setup a sysfs device for a CPU.
107 * @cpu - cpu->hotpluggable field set to 1 will generate a control file in 107 * @cpu - cpu->hotpluggable field set to 1 will generate a control file in
108 * sysfs for this CPU. 108 * sysfs for this CPU.
109 * @num - CPU number to use when creating the device. 109 * @num - CPU number to use when creating the device.
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 475e33f76e..cae346ef1b 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -133,7 +133,7 @@ static SYSDEV_ATTR(distance, S_IRUGO, node_read_distance, NULL);
133 133
134 134
135/* 135/*
136 * register_node - Setup a driverfs device for a node. 136 * register_node - Setup a sysfs device for a node.
137 * @num - Node number to use when creating the device. 137 * @num - Node number to use when creating the device.
138 * 138 *
139 * Initialize and register the node device. 139 * Initialize and register the node device.
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index cacb1c816e..17ee97f3a9 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -406,22 +406,6 @@ config BLK_DEV_RAM_BLOCKSIZE
406 setups function - apparently needed by the rd_load_image routine 406 setups function - apparently needed by the rd_load_image routine
407 that supposes the filesystem in the image uses a 1024 blocksize. 407 that supposes the filesystem in the image uses a 1024 blocksize.
408 408
409config BLK_DEV_INITRD
410 bool "Initial RAM filesystem and RAM disk (initramfs/initrd) support"
411 depends on BROKEN || !FRV
412 help
413 The initial RAM filesystem is a ramfs which is loaded by the
414 boot loader (loadlin or lilo) and that is mounted as root
415 before the normal boot procedure. It is typically used to
416 load modules needed to mount the "real" root file system,
417 etc. See <file:Documentation/initrd.txt> for details.
418
419 If RAM disk support (BLK_DEV_RAM) is also included, this
420 also enables initial RAM disk (initrd) support and adds
421 15 Kbytes (more on some other architectures) to the kernel size.
422
423 If unsure say Y.
424
425config CDROM_PKTCDVD 409config CDROM_PKTCDVD
426 tristate "Packet writing on CD/DVD media" 410 tristate "Packet writing on CD/DVD media"
427 depends on !UML 411 depends on !UML
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c
index bb022ed4a8..8d17d8df36 100644
--- a/drivers/block/aoe/aoecmd.c
+++ b/drivers/block/aoe/aoecmd.c
@@ -530,7 +530,7 @@ aoecmd_ata_rsp(struct sk_buff *skb)
530 u16 aoemajor; 530 u16 aoemajor;
531 531
532 hin = (struct aoe_hdr *) skb->mac.raw; 532 hin = (struct aoe_hdr *) skb->mac.raw;
533 aoemajor = be16_to_cpu(hin->major); 533 aoemajor = be16_to_cpu(get_unaligned(&hin->major));
534 d = aoedev_by_aoeaddr(aoemajor, hin->minor); 534 d = aoedev_by_aoeaddr(aoemajor, hin->minor);
535 if (d == NULL) { 535 if (d == NULL) {
536 snprintf(ebuf, sizeof ebuf, "aoecmd_ata_rsp: ata response " 536 snprintf(ebuf, sizeof ebuf, "aoecmd_ata_rsp: ata response "
@@ -542,7 +542,7 @@ aoecmd_ata_rsp(struct sk_buff *skb)
542 542
543 spin_lock_irqsave(&d->lock, flags); 543 spin_lock_irqsave(&d->lock, flags);
544 544
545 n = be32_to_cpu(hin->tag); 545 n = be32_to_cpu(get_unaligned(&hin->tag));
546 f = getframe(d, n); 546 f = getframe(d, n);
547 if (f == NULL) { 547 if (f == NULL) {
548 calc_rttavg(d, -tsince(n)); 548 calc_rttavg(d, -tsince(n));
@@ -550,9 +550,9 @@ aoecmd_ata_rsp(struct sk_buff *skb)
550 snprintf(ebuf, sizeof ebuf, 550 snprintf(ebuf, sizeof ebuf,
551 "%15s e%d.%d tag=%08x@%08lx\n", 551 "%15s e%d.%d tag=%08x@%08lx\n",
552 "unexpected rsp", 552 "unexpected rsp",
553 be16_to_cpu(hin->major), 553 be16_to_cpu(get_unaligned(&hin->major)),
554 hin->minor, 554 hin->minor,
555 be32_to_cpu(hin->tag), 555 be32_to_cpu(get_unaligned(&hin->tag)),
556 jiffies); 556 jiffies);
557 aoechr_error(ebuf); 557 aoechr_error(ebuf);
558 return; 558 return;
@@ -631,7 +631,7 @@ aoecmd_ata_rsp(struct sk_buff *skb)
631 printk(KERN_INFO 631 printk(KERN_INFO
632 "aoe: unrecognized ata command %2.2Xh for %d.%d\n", 632 "aoe: unrecognized ata command %2.2Xh for %d.%d\n",
633 ahout->cmdstat, 633 ahout->cmdstat,
634 be16_to_cpu(hin->major), 634 be16_to_cpu(get_unaligned(&hin->major)),
635 hin->minor); 635 hin->minor);
636 } 636 }
637 } 637 }
@@ -733,7 +733,7 @@ aoecmd_cfg_rsp(struct sk_buff *skb)
733 * Enough people have their dip switches set backwards to 733 * Enough people have their dip switches set backwards to
734 * warrant a loud message for this special case. 734 * warrant a loud message for this special case.
735 */ 735 */
736 aoemajor = be16_to_cpu(h->major); 736 aoemajor = be16_to_cpu(get_unaligned(&h->major));
737 if (aoemajor == 0xfff) { 737 if (aoemajor == 0xfff) {
738 printk(KERN_ERR "aoe: Warning: shelf address is all ones. " 738 printk(KERN_ERR "aoe: Warning: shelf address is all ones. "
739 "Check shelf dip switches.\n"); 739 "Check shelf dip switches.\n");
diff --git a/drivers/block/aoe/aoenet.c b/drivers/block/aoe/aoenet.c
index 9626e0f5da..aab6d91a2c 100644
--- a/drivers/block/aoe/aoenet.c
+++ b/drivers/block/aoe/aoenet.c
@@ -8,6 +8,7 @@
8#include <linux/blkdev.h> 8#include <linux/blkdev.h>
9#include <linux/netdevice.h> 9#include <linux/netdevice.h>
10#include <linux/moduleparam.h> 10#include <linux/moduleparam.h>
11#include <asm/unaligned.h>
11#include "aoe.h" 12#include "aoe.h"
12 13
13#define NECODES 5 14#define NECODES 5
@@ -123,7 +124,7 @@ aoenet_rcv(struct sk_buff *skb, struct net_device *ifp, struct packet_type *pt,
123 skb_push(skb, ETH_HLEN); /* (1) */ 124 skb_push(skb, ETH_HLEN); /* (1) */
124 125
125 h = (struct aoe_hdr *) skb->mac.raw; 126 h = (struct aoe_hdr *) skb->mac.raw;
126 n = be32_to_cpu(h->tag); 127 n = be32_to_cpu(get_unaligned(&h->tag));
127 if ((h->verfl & AOEFL_RSP) == 0 || (n & 1<<31)) 128 if ((h->verfl & AOEFL_RSP) == 0 || (n & 1<<31))
128 goto exit; 129 goto exit;
129 130
@@ -133,7 +134,7 @@ aoenet_rcv(struct sk_buff *skb, struct net_device *ifp, struct packet_type *pt,
133 n = 0; 134 n = 0;
134 if (net_ratelimit()) 135 if (net_ratelimit())
135 printk(KERN_ERR "aoe: error packet from %d.%d; ecode=%d '%s'\n", 136 printk(KERN_ERR "aoe: error packet from %d.%d; ecode=%d '%s'\n",
136 be16_to_cpu(h->major), h->minor, 137 be16_to_cpu(get_unaligned(&h->major)), h->minor,
137 h->err, aoe_errlist[n]); 138 h->err, aoe_errlist[n]);
138 goto exit; 139 goto exit;
139 } 140 }
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 05dfe35752..0c716ee905 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -1291,13 +1291,19 @@ static void cciss_update_drive_info(int ctlr, int drv_index)
1291 if (inq_buff == NULL) 1291 if (inq_buff == NULL)
1292 goto mem_msg; 1292 goto mem_msg;
1293 1293
1294 /* testing to see if 16-byte CDBs are already being used */
1295 if (h->cciss_read == CCISS_READ_16) {
1296 cciss_read_capacity_16(h->ctlr, drv_index, 1,
1297 &total_size, &block_size);
1298 goto geo_inq;
1299 }
1300
1294 cciss_read_capacity(ctlr, drv_index, 1, 1301 cciss_read_capacity(ctlr, drv_index, 1,
1295 &total_size, &block_size); 1302 &total_size, &block_size);
1296 1303
1297 /* total size = last LBA + 1 */ 1304 /* if read_capacity returns all F's this volume is >2TB in size */
1298 /* FFFFFFFF + 1 = 0, cannot have a logical volume of size 0 */ 1305 /* so we switch to 16-byte CDB's for all read/write ops */
1299 /* so we assume this volume this must be >2TB in size */ 1306 if (total_size == 0xFFFFFFFFULL) {
1300 if (total_size == (__u32) 0) {
1301 cciss_read_capacity_16(ctlr, drv_index, 1, 1307 cciss_read_capacity_16(ctlr, drv_index, 1,
1302 &total_size, &block_size); 1308 &total_size, &block_size);
1303 h->cciss_read = CCISS_READ_16; 1309 h->cciss_read = CCISS_READ_16;
@@ -1306,6 +1312,7 @@ static void cciss_update_drive_info(int ctlr, int drv_index)
1306 h->cciss_read = CCISS_READ_10; 1312 h->cciss_read = CCISS_READ_10;
1307 h->cciss_write = CCISS_WRITE_10; 1313 h->cciss_write = CCISS_WRITE_10;
1308 } 1314 }
1315geo_inq:
1309 cciss_geometry_inquiry(ctlr, drv_index, 1, total_size, block_size, 1316 cciss_geometry_inquiry(ctlr, drv_index, 1, total_size, block_size,
1310 inq_buff, &h->drv[drv_index]); 1317 inq_buff, &h->drv[drv_index]);
1311 1318
@@ -1917,13 +1924,14 @@ static void cciss_geometry_inquiry(int ctlr, int logvol,
1917 drv->raid_level = inq_buff->data_byte[8]; 1924 drv->raid_level = inq_buff->data_byte[8];
1918 } 1925 }
1919 drv->block_size = block_size; 1926 drv->block_size = block_size;
1920 drv->nr_blocks = total_size; 1927 drv->nr_blocks = total_size + 1;
1921 t = drv->heads * drv->sectors; 1928 t = drv->heads * drv->sectors;
1922 if (t > 1) { 1929 if (t > 1) {
1923 unsigned rem = sector_div(total_size, t); 1930 sector_t real_size = total_size + 1;
1931 unsigned long rem = sector_div(real_size, t);
1924 if (rem) 1932 if (rem)
1925 total_size++; 1933 real_size++;
1926 drv->cylinders = total_size; 1934 drv->cylinders = real_size;
1927 } 1935 }
1928 } else { /* Get geometry failed */ 1936 } else { /* Get geometry failed */
1929 printk(KERN_WARNING "cciss: reading geometry failed\n"); 1937 printk(KERN_WARNING "cciss: reading geometry failed\n");
@@ -1953,16 +1961,16 @@ cciss_read_capacity(int ctlr, int logvol, int withirq, sector_t *total_size,
1953 ctlr, buf, sizeof(ReadCapdata_struct), 1961 ctlr, buf, sizeof(ReadCapdata_struct),
1954 1, logvol, 0, NULL, TYPE_CMD); 1962 1, logvol, 0, NULL, TYPE_CMD);
1955 if (return_code == IO_OK) { 1963 if (return_code == IO_OK) {
1956 *total_size = be32_to_cpu(*(__u32 *) buf->total_size)+1; 1964 *total_size = be32_to_cpu(*(__u32 *) buf->total_size);
1957 *block_size = be32_to_cpu(*(__u32 *) buf->block_size); 1965 *block_size = be32_to_cpu(*(__u32 *) buf->block_size);
1958 } else { /* read capacity command failed */ 1966 } else { /* read capacity command failed */
1959 printk(KERN_WARNING "cciss: read capacity failed\n"); 1967 printk(KERN_WARNING "cciss: read capacity failed\n");
1960 *total_size = 0; 1968 *total_size = 0;
1961 *block_size = BLOCK_SIZE; 1969 *block_size = BLOCK_SIZE;
1962 } 1970 }
1963 if (*total_size != (__u32) 0) 1971 if (*total_size != 0)
1964 printk(KERN_INFO " blocks= %llu block_size= %d\n", 1972 printk(KERN_INFO " blocks= %llu block_size= %d\n",
1965 (unsigned long long)*total_size, *block_size); 1973 (unsigned long long)*total_size+1, *block_size);
1966 kfree(buf); 1974 kfree(buf);
1967 return; 1975 return;
1968} 1976}
@@ -1989,7 +1997,7 @@ cciss_read_capacity_16(int ctlr, int logvol, int withirq, sector_t *total_size,
1989 1, logvol, 0, NULL, TYPE_CMD); 1997 1, logvol, 0, NULL, TYPE_CMD);
1990 } 1998 }
1991 if (return_code == IO_OK) { 1999 if (return_code == IO_OK) {
1992 *total_size = be64_to_cpu(*(__u64 *) buf->total_size)+1; 2000 *total_size = be64_to_cpu(*(__u64 *) buf->total_size);
1993 *block_size = be32_to_cpu(*(__u32 *) buf->block_size); 2001 *block_size = be32_to_cpu(*(__u32 *) buf->block_size);
1994 } else { /* read capacity command failed */ 2002 } else { /* read capacity command failed */
1995 printk(KERN_WARNING "cciss: read capacity failed\n"); 2003 printk(KERN_WARNING "cciss: read capacity failed\n");
@@ -1997,7 +2005,7 @@ cciss_read_capacity_16(int ctlr, int logvol, int withirq, sector_t *total_size,
1997 *block_size = BLOCK_SIZE; 2005 *block_size = BLOCK_SIZE;
1998 } 2006 }
1999 printk(KERN_INFO " blocks= %llu block_size= %d\n", 2007 printk(KERN_INFO " blocks= %llu block_size= %d\n",
2000 (unsigned long long)*total_size, *block_size); 2008 (unsigned long long)*total_size+1, *block_size);
2001 kfree(buf); 2009 kfree(buf);
2002 return; 2010 return;
2003} 2011}
@@ -3119,8 +3127,9 @@ static void cciss_getgeometry(int cntl_num)
3119 } 3127 }
3120 cciss_read_capacity(cntl_num, i, 0, &total_size, &block_size); 3128 cciss_read_capacity(cntl_num, i, 0, &total_size, &block_size);
3121 3129
3122 /* total_size = last LBA + 1 */ 3130 /* If read_capacity returns all F's the logical is >2TB */
3123 if(total_size == (__u32) 0) { 3131 /* so we switch to 16-byte CDBs for all read/write ops */
3132 if(total_size == 0xFFFFFFFFULL) {
3124 cciss_read_capacity_16(cntl_num, i, 0, 3133 cciss_read_capacity_16(cntl_num, i, 0,
3125 &total_size, &block_size); 3134 &total_size, &block_size);
3126 hba[cntl_num]->cciss_read = CCISS_READ_16; 3135 hba[cntl_num]->cciss_read = CCISS_READ_16;
@@ -3395,7 +3404,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3395 return -1; 3404 return -1;
3396} 3405}
3397 3406
3398static void __devexit cciss_remove_one(struct pci_dev *pdev) 3407static void cciss_remove_one(struct pci_dev *pdev)
3399{ 3408{
3400 ctlr_info_t *tmp_ptr; 3409 ctlr_info_t *tmp_ptr;
3401 int i, j; 3410 int i, j;
@@ -3419,9 +3428,10 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev)
3419 memset(flush_buf, 0, 4); 3428 memset(flush_buf, 0, 4);
3420 return_code = sendcmd(CCISS_CACHE_FLUSH, i, flush_buf, 4, 0, 0, 0, NULL, 3429 return_code = sendcmd(CCISS_CACHE_FLUSH, i, flush_buf, 4, 0, 0, 0, NULL,
3421 TYPE_CMD); 3430 TYPE_CMD);
3422 if (return_code != IO_OK) { 3431 if (return_code == IO_OK) {
3423 printk(KERN_WARNING "Error Flushing cache on controller %d\n", 3432 printk(KERN_INFO "Completed flushing cache on controller %d\n", i);
3424 i); 3433 } else {
3434 printk(KERN_WARNING "Error flushing cache on controller %d\n", i);
3425 } 3435 }
3426 free_irq(hba[i]->intr[2], hba[i]); 3436 free_irq(hba[i]->intr[2], hba[i]);
3427 3437
@@ -3472,6 +3482,7 @@ static struct pci_driver cciss_pci_driver = {
3472 .probe = cciss_init_one, 3482 .probe = cciss_init_one,
3473 .remove = __devexit_p(cciss_remove_one), 3483 .remove = __devexit_p(cciss_remove_one),
3474 .id_table = cciss_pci_device_id, /* id_table */ 3484 .id_table = cciss_pci_device_id, /* id_table */
3485 .shutdown = cciss_remove_one,
3475}; 3486};
3476 3487
3477/* 3488/*
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 3f1b38276e..5231ed7e72 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -297,17 +297,17 @@ static int initialising = 1;
297#define DRS (&drive_state[current_drive]) 297#define DRS (&drive_state[current_drive])
298#define DRWE (&write_errors[current_drive]) 298#define DRWE (&write_errors[current_drive])
299#define FDCS (&fdc_state[fdc]) 299#define FDCS (&fdc_state[fdc])
300#define CLEARF(x) (clear_bit(x##_BIT, &DRS->flags)) 300#define CLEARF(x) clear_bit(x##_BIT, &DRS->flags)
301#define SETF(x) (set_bit(x##_BIT, &DRS->flags)) 301#define SETF(x) set_bit(x##_BIT, &DRS->flags)
302#define TESTF(x) (test_bit(x##_BIT, &DRS->flags)) 302#define TESTF(x) test_bit(x##_BIT, &DRS->flags)
303 303
304#define UDP (&drive_params[drive]) 304#define UDP (&drive_params[drive])
305#define UDRS (&drive_state[drive]) 305#define UDRS (&drive_state[drive])
306#define UDRWE (&write_errors[drive]) 306#define UDRWE (&write_errors[drive])
307#define UFDCS (&fdc_state[FDC(drive)]) 307#define UFDCS (&fdc_state[FDC(drive)])
308#define UCLEARF(x) (clear_bit(x##_BIT, &UDRS->flags)) 308#define UCLEARF(x) clear_bit(x##_BIT, &UDRS->flags)
309#define USETF(x) (set_bit(x##_BIT, &UDRS->flags)) 309#define USETF(x) set_bit(x##_BIT, &UDRS->flags)
310#define UTESTF(x) (test_bit(x##_BIT, &UDRS->flags)) 310#define UTESTF(x) test_bit(x##_BIT, &UDRS->flags)
311 311
312#define DPRINT(format, args...) printk(DEVICE_NAME "%d: " format, current_drive , ## args) 312#define DPRINT(format, args...) printk(DEVICE_NAME "%d: " format, current_drive , ## args)
313 313
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 93fb6ed4ed..a4fb703831 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -765,7 +765,7 @@ static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *
765 goto out; 765 goto out;
766 } 766 }
767 767
768 rq->cmd_len = COMMAND_SIZE(rq->cmd[0]); 768 rq->cmd_len = COMMAND_SIZE(cgc->cmd[0]);
769 memcpy(rq->cmd, cgc->cmd, CDROM_PACKET_SIZE); 769 memcpy(rq->cmd, cgc->cmd, CDROM_PACKET_SIZE);
770 if (sizeof(rq->cmd) > CDROM_PACKET_SIZE) 770 if (sizeof(rq->cmd) > CDROM_PACKET_SIZE)
771 memset(rq->cmd + CDROM_PACKET_SIZE, 0, sizeof(rq->cmd) - CDROM_PACKET_SIZE); 771 memset(rq->cmd + CDROM_PACKET_SIZE, 0, sizeof(rq->cmd) - CDROM_PACKET_SIZE);
diff --git a/drivers/block/umem.c b/drivers/block/umem.c
index dff3766f11..5872036e8a 100644
--- a/drivers/block/umem.c
+++ b/drivers/block/umem.c
@@ -1179,8 +1179,10 @@ static int __init mm_init(void)
1179 return -ENOMEM; 1179 return -ENOMEM;
1180 1180
1181 err = major_nr = register_blkdev(0, "umem"); 1181 err = major_nr = register_blkdev(0, "umem");
1182 if (err < 0) 1182 if (err < 0) {
1183 pci_unregister_driver(&mm_pci_driver);
1183 return -EIO; 1184 return -EIO;
1185 }
1184 1186
1185 for (i = 0; i < num_cards; i++) { 1187 for (i = 0; i < num_cards; i++) {
1186 mm_gendisk[i] = alloc_disk(1 << MM_SHIFT); 1188 mm_gendisk[i] = alloc_disk(1 << MM_SHIFT);
@@ -1207,6 +1209,7 @@ static int __init mm_init(void)
1207 return 0; 1209 return 0;
1208 1210
1209out: 1211out:
1212 pci_unregister_driver(&mm_pci_driver);
1210 unregister_blkdev(major_nr, "umem"); 1213 unregister_blkdev(major_nr, "umem");
1211 while (i--) 1214 while (i--)
1212 put_disk(mm_gendisk[i]); 1215 put_disk(mm_gendisk[i]);
diff --git a/drivers/bluetooth/bcm203x.c b/drivers/bluetooth/bcm203x.c
index 9256985cbe..8919ccf827 100644
--- a/drivers/bluetooth/bcm203x.c
+++ b/drivers/bluetooth/bcm203x.c
@@ -307,3 +307,5 @@ MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
307MODULE_DESCRIPTION("Broadcom Blutonium firmware driver ver " VERSION); 307MODULE_DESCRIPTION("Broadcom Blutonium firmware driver ver " VERSION);
308MODULE_VERSION(VERSION); 308MODULE_VERSION(VERSION);
309MODULE_LICENSE("GPL"); 309MODULE_LICENSE("GPL");
310MODULE_FIRMWARE("BCM2033-MD.hex");
311MODULE_FIRMWARE("BCM2033-FW.bin");
diff --git a/drivers/bluetooth/bfusb.c b/drivers/bluetooth/bfusb.c
index 27cceb6f56..4c766f36d8 100644
--- a/drivers/bluetooth/bfusb.c
+++ b/drivers/bluetooth/bfusb.c
@@ -801,3 +801,4 @@ MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
801MODULE_DESCRIPTION("BlueFRITZ! USB driver ver " VERSION); 801MODULE_DESCRIPTION("BlueFRITZ! USB driver ver " VERSION);
802MODULE_VERSION(VERSION); 802MODULE_VERSION(VERSION);
803MODULE_LICENSE("GPL"); 803MODULE_LICENSE("GPL");
804MODULE_FIRMWARE("bfubase.frm");
diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c
index 34e5555cb9..18b0f3992c 100644
--- a/drivers/bluetooth/bt3c_cs.c
+++ b/drivers/bluetooth/bt3c_cs.c
@@ -63,6 +63,7 @@
63MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>, Jose Orlando Pereira <jop@di.uminho.pt>"); 63MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>, Jose Orlando Pereira <jop@di.uminho.pt>");
64MODULE_DESCRIPTION("Bluetooth driver for the 3Com Bluetooth PCMCIA card"); 64MODULE_DESCRIPTION("Bluetooth driver for the 3Com Bluetooth PCMCIA card");
65MODULE_LICENSE("GPL"); 65MODULE_LICENSE("GPL");
66MODULE_FIRMWARE("BT3CPCC.bin");
66 67
67 68
68 69
diff --git a/drivers/cdrom/viocd.c b/drivers/cdrom/viocd.c
index dc13ebaced..44cd7b2ddf 100644
--- a/drivers/cdrom/viocd.c
+++ b/drivers/cdrom/viocd.c
@@ -376,6 +376,25 @@ static int send_request(struct request *req)
376 return 0; 376 return 0;
377} 377}
378 378
379static void viocd_end_request(struct request *req, int uptodate)
380{
381 int nsectors = req->hard_nr_sectors;
382
383 /*
384 * Make sure it's fully ended, and ensure that we process
385 * at least one sector.
386 */
387 if (blk_pc_request(req))
388 nsectors = (req->data_len + 511) >> 9;
389 if (!nsectors)
390 nsectors = 1;
391
392 if (end_that_request_first(req, uptodate, nsectors))
393 BUG();
394 add_disk_randomness(req->rq_disk);
395 blkdev_dequeue_request(req);
396 end_that_request_last(req, uptodate);
397}
379 398
380static int rwreq; 399static int rwreq;
381 400
@@ -385,11 +404,11 @@ static void do_viocd_request(request_queue_t *q)
385 404
386 while ((rwreq == 0) && ((req = elv_next_request(q)) != NULL)) { 405 while ((rwreq == 0) && ((req = elv_next_request(q)) != NULL)) {
387 if (!blk_fs_request(req)) 406 if (!blk_fs_request(req))
388 end_request(req, 0); 407 viocd_end_request(req, 0);
389 else if (send_request(req) < 0) { 408 else if (send_request(req) < 0) {
390 printk(VIOCD_KERN_WARNING 409 printk(VIOCD_KERN_WARNING
391 "unable to send message to OS/400!"); 410 "unable to send message to OS/400!");
392 end_request(req, 0); 411 viocd_end_request(req, 0);
393 } else 412 } else
394 rwreq++; 413 rwreq++;
395 } 414 }
@@ -601,9 +620,9 @@ return_complete:
601 "with rc %d:0x%04X: %s\n", 620 "with rc %d:0x%04X: %s\n",
602 req, event->xRc, 621 req, event->xRc,
603 bevent->sub_result, err->msg); 622 bevent->sub_result, err->msg);
604 end_request(req, 0); 623 viocd_end_request(req, 0);
605 } else 624 } else
606 end_request(req, 1); 625 viocd_end_request(req, 1);
607 626
608 /* restart handling of incoming requests */ 627 /* restart handling of incoming requests */
609 spin_unlock_irqrestore(&viocd_reqlock, flags); 628 spin_unlock_irqrestore(&viocd_reqlock, flags);
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index d0a6dc5321..3429ece4ef 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -1026,16 +1026,17 @@ config MMTIMER
1026source "drivers/char/tpm/Kconfig" 1026source "drivers/char/tpm/Kconfig"
1027 1027
1028config TELCLOCK 1028config TELCLOCK
1029 tristate "Telecom clock driver for MPBL0010 ATCA SBC" 1029 tristate "Telecom clock driver for ATCA SBC"
1030 depends on EXPERIMENTAL && X86 1030 depends on EXPERIMENTAL && X86
1031 default n 1031 default n
1032 help 1032 help
1033 The telecom clock device is specific to the MPBL0010 ATCA computer and 1033 The telecom clock device is specific to the MPCBL0010 and MPCBL0050
1034 allows direct userspace access to the configuration of the telecom clock 1034 ATCA computers and allows direct userspace access to the
1035 configuration settings. This device is used for hardware synchronization 1035 configuration of the telecom clock configuration settings. This
1036 across the ATCA backplane fabric. Upon loading, the driver exports a 1036 device is used for hardware synchronization across the ATCA backplane
1037 sysfs directory, /sys/devices/platform/telco_clock, with a number of 1037 fabric. Upon loading, the driver exports a sysfs directory,
1038 files for controlling the behavior of this hardware. 1038 /sys/devices/platform/telco_clock, with a number of files for
1039 controlling the behavior of this hardware.
1039 1040
1040endmenu 1041endmenu
1041 1042
diff --git a/drivers/char/agp/Makefile b/drivers/char/agp/Makefile
index a0d04a23da..627f542827 100644
--- a/drivers/char/agp/Makefile
+++ b/drivers/char/agp/Makefile
@@ -1,7 +1,8 @@
1agpgart-y := backend.o frontend.o generic.o isoch.o 1agpgart-y := backend.o frontend.o generic.o isoch.o
2 2
3agpgart-$(CONFIG_COMPAT) += compat_ioctl.o
4
3obj-$(CONFIG_AGP) += agpgart.o 5obj-$(CONFIG_AGP) += agpgart.o
4obj-$(CONFIG_COMPAT) += compat_ioctl.o
5obj-$(CONFIG_AGP_ALI) += ali-agp.o 6obj-$(CONFIG_AGP_ALI) += ali-agp.o
6obj-$(CONFIG_AGP_ATI) += ati-agp.o 7obj-$(CONFIG_AGP_ATI) += ati-agp.o
7obj-$(CONFIG_AGP_AMD) += amd-k7-agp.o 8obj-$(CONFIG_AGP_AMD) += amd-k7-agp.o
diff --git a/drivers/char/agp/agp.h b/drivers/char/agp/agp.h
index 9bd68d9f0f..fdbca25a39 100644
--- a/drivers/char/agp/agp.h
+++ b/drivers/char/agp/agp.h
@@ -93,12 +93,12 @@ struct aper_size_info_fixed {
93 93
94struct agp_bridge_driver { 94struct agp_bridge_driver {
95 struct module *owner; 95 struct module *owner;
96 void *aperture_sizes; 96 const void *aperture_sizes;
97 int num_aperture_sizes; 97 int num_aperture_sizes;
98 enum aper_size_type size_type; 98 enum aper_size_type size_type;
99 int cant_use_aperture; 99 int cant_use_aperture;
100 int needs_scratch_page; 100 int needs_scratch_page;
101 struct gatt_mask *masks; 101 const struct gatt_mask *masks;
102 int (*fetch_size)(void); 102 int (*fetch_size)(void);
103 int (*configure)(void); 103 int (*configure)(void);
104 void (*agp_enable)(struct agp_bridge_data *, u32); 104 void (*agp_enable)(struct agp_bridge_data *, u32);
@@ -119,7 +119,7 @@ struct agp_bridge_driver {
119 119
120struct agp_bridge_data { 120struct agp_bridge_data {
121 const struct agp_version *version; 121 const struct agp_version *version;
122 struct agp_bridge_driver *driver; 122 const struct agp_bridge_driver *driver;
123 struct vm_operations_struct *vm_ops; 123 struct vm_operations_struct *vm_ops;
124 void *previous_size; 124 void *previous_size;
125 void *current_size; 125 void *current_size;
@@ -290,7 +290,7 @@ void agp3_generic_cleanup(void);
290 290
291/* aperture sizes have been standardised since v3 */ 291/* aperture sizes have been standardised since v3 */
292#define AGP_GENERIC_SIZES_ENTRIES 11 292#define AGP_GENERIC_SIZES_ENTRIES 11
293extern struct aper_size_info_16 agp3_generic_sizes[]; 293extern const struct aper_size_info_16 agp3_generic_sizes[];
294 294
295#define virt_to_gart(x) (phys_to_gart(virt_to_phys(x))) 295#define virt_to_gart(x) (phys_to_gart(virt_to_phys(x)))
296#define gart_to_virt(x) (phys_to_virt(gart_to_phys(x))) 296#define gart_to_virt(x) (phys_to_virt(gart_to_phys(x)))
diff --git a/drivers/char/agp/ali-agp.c b/drivers/char/agp/ali-agp.c
index 98177a9307..5b684fddcc 100644
--- a/drivers/char/agp/ali-agp.c
+++ b/drivers/char/agp/ali-agp.c
@@ -182,7 +182,7 @@ static void m1541_destroy_page(void * addr)
182 182
183/* Setup function */ 183/* Setup function */
184 184
185static struct aper_size_info_32 ali_generic_sizes[7] = 185static const struct aper_size_info_32 ali_generic_sizes[7] =
186{ 186{
187 {256, 65536, 6, 10}, 187 {256, 65536, 6, 10},
188 {128, 32768, 5, 9}, 188 {128, 32768, 5, 9},
@@ -193,7 +193,7 @@ static struct aper_size_info_32 ali_generic_sizes[7] =
193 {4, 1024, 0, 3} 193 {4, 1024, 0, 3}
194}; 194};
195 195
196static struct agp_bridge_driver ali_generic_bridge = { 196static const struct agp_bridge_driver ali_generic_bridge = {
197 .owner = THIS_MODULE, 197 .owner = THIS_MODULE,
198 .aperture_sizes = ali_generic_sizes, 198 .aperture_sizes = ali_generic_sizes,
199 .size_type = U32_APER_SIZE, 199 .size_type = U32_APER_SIZE,
@@ -217,7 +217,7 @@ static struct agp_bridge_driver ali_generic_bridge = {
217 .agp_type_to_mask_type = agp_generic_type_to_mask_type, 217 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
218}; 218};
219 219
220static struct agp_bridge_driver ali_m1541_bridge = { 220static const struct agp_bridge_driver ali_m1541_bridge = {
221 .owner = THIS_MODULE, 221 .owner = THIS_MODULE,
222 .aperture_sizes = ali_generic_sizes, 222 .aperture_sizes = ali_generic_sizes,
223 .size_type = U32_APER_SIZE, 223 .size_type = U32_APER_SIZE,
diff --git a/drivers/char/agp/amd-k7-agp.c b/drivers/char/agp/amd-k7-agp.c
index 3d8d448bf3..e6c534e628 100644
--- a/drivers/char/agp/amd-k7-agp.c
+++ b/drivers/char/agp/amd-k7-agp.c
@@ -344,7 +344,7 @@ static int amd_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
344 return 0; 344 return 0;
345} 345}
346 346
347static struct aper_size_info_lvl2 amd_irongate_sizes[7] = 347static const struct aper_size_info_lvl2 amd_irongate_sizes[7] =
348{ 348{
349 {2048, 524288, 0x0000000c}, 349 {2048, 524288, 0x0000000c},
350 {1024, 262144, 0x0000000a}, 350 {1024, 262144, 0x0000000a},
@@ -355,12 +355,12 @@ static struct aper_size_info_lvl2 amd_irongate_sizes[7] =
355 {32, 8192, 0x00000000} 355 {32, 8192, 0x00000000}
356}; 356};
357 357
358static struct gatt_mask amd_irongate_masks[] = 358static const struct gatt_mask amd_irongate_masks[] =
359{ 359{
360 {.mask = 1, .type = 0} 360 {.mask = 1, .type = 0}
361}; 361};
362 362
363static struct agp_bridge_driver amd_irongate_driver = { 363static const struct agp_bridge_driver amd_irongate_driver = {
364 .owner = THIS_MODULE, 364 .owner = THIS_MODULE,
365 .aperture_sizes = amd_irongate_sizes, 365 .aperture_sizes = amd_irongate_sizes,
366 .size_type = LVL2_APER_SIZE, 366 .size_type = LVL2_APER_SIZE,
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index 636d984ed4..485720486d 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -192,7 +192,7 @@ static u64 amd64_configure (struct pci_dev *hammer, u64 gatt_table)
192} 192}
193 193
194 194
195static struct aper_size_info_32 amd_8151_sizes[7] = 195static const struct aper_size_info_32 amd_8151_sizes[7] =
196{ 196{
197 {2048, 524288, 9, 0x00000000 }, /* 0 0 0 0 0 0 */ 197 {2048, 524288, 9, 0x00000000 }, /* 0 0 0 0 0 0 */
198 {1024, 262144, 8, 0x00000400 }, /* 1 0 0 0 0 0 */ 198 {1024, 262144, 8, 0x00000400 }, /* 1 0 0 0 0 0 */
@@ -232,7 +232,7 @@ static void amd64_cleanup(void)
232} 232}
233 233
234 234
235static struct agp_bridge_driver amd_8151_driver = { 235static const struct agp_bridge_driver amd_8151_driver = {
236 .owner = THIS_MODULE, 236 .owner = THIS_MODULE,
237 .aperture_sizes = amd_8151_sizes, 237 .aperture_sizes = amd_8151_sizes,
238 .size_type = U32_APER_SIZE, 238 .size_type = U32_APER_SIZE,
diff --git a/drivers/char/agp/ati-agp.c b/drivers/char/agp/ati-agp.c
index 77c9ad68fb..780e59e588 100644
--- a/drivers/char/agp/ati-agp.c
+++ b/drivers/char/agp/ati-agp.c
@@ -24,7 +24,7 @@
24#define ATI_GART_CACHE_ENTRY_CNTRL 0x10 24#define ATI_GART_CACHE_ENTRY_CNTRL 0x10
25 25
26 26
27static struct aper_size_info_lvl2 ati_generic_sizes[7] = 27static const struct aper_size_info_lvl2 ati_generic_sizes[7] =
28{ 28{
29 {2048, 524288, 0x0000000c}, 29 {2048, 524288, 0x0000000c},
30 {1024, 262144, 0x0000000a}, 30 {1024, 262144, 0x0000000a},
@@ -410,7 +410,7 @@ static int ati_free_gatt_table(struct agp_bridge_data *bridge)
410 return 0; 410 return 0;
411} 411}
412 412
413static struct agp_bridge_driver ati_generic_bridge = { 413static const struct agp_bridge_driver ati_generic_bridge = {
414 .owner = THIS_MODULE, 414 .owner = THIS_MODULE,
415 .aperture_sizes = ati_generic_sizes, 415 .aperture_sizes = ati_generic_sizes,
416 .size_type = LVL2_APER_SIZE, 416 .size_type = LVL2_APER_SIZE,
diff --git a/drivers/char/agp/efficeon-agp.c b/drivers/char/agp/efficeon-agp.c
index 658cb1a72d..df8da72628 100644
--- a/drivers/char/agp/efficeon-agp.c
+++ b/drivers/char/agp/efficeon-agp.c
@@ -59,7 +59,7 @@ static struct _efficeon_private {
59 unsigned long l1_table[EFFICEON_L1_SIZE]; 59 unsigned long l1_table[EFFICEON_L1_SIZE];
60} efficeon_private; 60} efficeon_private;
61 61
62static struct gatt_mask efficeon_generic_masks[] = 62static const struct gatt_mask efficeon_generic_masks[] =
63{ 63{
64 {.mask = 0x00000001, .type = 0} 64 {.mask = 0x00000001, .type = 0}
65}; 65};
@@ -70,7 +70,7 @@ static inline unsigned long efficeon_mask_memory(unsigned long addr)
70 return addr | 0x00000001; 70 return addr | 0x00000001;
71} 71}
72 72
73static struct aper_size_info_lvl2 efficeon_generic_sizes[4] = 73static const struct aper_size_info_lvl2 efficeon_generic_sizes[4] =
74{ 74{
75 {256, 65536, 0}, 75 {256, 65536, 0},
76 {128, 32768, 32}, 76 {128, 32768, 32},
@@ -309,7 +309,7 @@ static int efficeon_remove_memory(struct agp_memory * mem, off_t pg_start, int t
309} 309}
310 310
311 311
312static struct agp_bridge_driver efficeon_driver = { 312static const struct agp_bridge_driver efficeon_driver = {
313 .owner = THIS_MODULE, 313 .owner = THIS_MODULE,
314 .aperture_sizes = efficeon_generic_sizes, 314 .aperture_sizes = efficeon_generic_sizes,
315 .size_type = LVL2_APER_SIZE, 315 .size_type = LVL2_APER_SIZE,
diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
index 7923337c3d..f902d71947 100644
--- a/drivers/char/agp/generic.c
+++ b/drivers/char/agp/generic.c
@@ -1340,7 +1340,7 @@ void agp3_generic_cleanup(void)
1340} 1340}
1341EXPORT_SYMBOL(agp3_generic_cleanup); 1341EXPORT_SYMBOL(agp3_generic_cleanup);
1342 1342
1343struct aper_size_info_16 agp3_generic_sizes[AGP_GENERIC_SIZES_ENTRIES] = 1343const struct aper_size_info_16 agp3_generic_sizes[AGP_GENERIC_SIZES_ENTRIES] =
1344{ 1344{
1345 {4096, 1048576, 10,0x000}, 1345 {4096, 1048576, 10,0x000},
1346 {2048, 524288, 9, 0x800}, 1346 {2048, 524288, 9, 0x800},
diff --git a/drivers/char/agp/hp-agp.c b/drivers/char/agp/hp-agp.c
index 847deabf7f..bcdb149c81 100644
--- a/drivers/char/agp/hp-agp.c
+++ b/drivers/char/agp/hp-agp.c
@@ -419,7 +419,7 @@ hp_zx1_enable (struct agp_bridge_data *bridge, u32 mode)
419 agp_device_command(command, (mode & AGP8X_MODE) != 0); 419 agp_device_command(command, (mode & AGP8X_MODE) != 0);
420} 420}
421 421
422struct agp_bridge_driver hp_zx1_driver = { 422const struct agp_bridge_driver hp_zx1_driver = {
423 .owner = THIS_MODULE, 423 .owner = THIS_MODULE,
424 .size_type = FIXED_APER_SIZE, 424 .size_type = FIXED_APER_SIZE,
425 .configure = hp_zx1_configure, 425 .configure = hp_zx1_configure,
diff --git a/drivers/char/agp/i460-agp.c b/drivers/char/agp/i460-agp.c
index 3e7618653a..53354bf83a 100644
--- a/drivers/char/agp/i460-agp.c
+++ b/drivers/char/agp/i460-agp.c
@@ -78,7 +78,7 @@ static struct {
78 } *lp_desc; 78 } *lp_desc;
79} i460; 79} i460;
80 80
81static struct aper_size_info_8 i460_sizes[3] = 81static const struct aper_size_info_8 i460_sizes[3] =
82{ 82{
83 /* 83 /*
84 * The 32GB aperture is only available with a 4M GART page size. Due to the 84 * The 32GB aperture is only available with a 4M GART page size. Due to the
@@ -550,7 +550,7 @@ static unsigned long i460_mask_memory (struct agp_bridge_data *bridge,
550 | (((addr & ~((1 << I460_IO_PAGE_SHIFT) - 1)) & 0xfffff000) >> 12); 550 | (((addr & ~((1 << I460_IO_PAGE_SHIFT) - 1)) & 0xfffff000) >> 12);
551} 551}
552 552
553struct agp_bridge_driver intel_i460_driver = { 553const struct agp_bridge_driver intel_i460_driver = {
554 .owner = THIS_MODULE, 554 .owner = THIS_MODULE,
555 .aperture_sizes = i460_sizes, 555 .aperture_sizes = i460_sizes,
556 .size_type = U8_APER_SIZE, 556 .size_type = U8_APER_SIZE,
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index 06b0bb6d98..e542a628f1 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -63,7 +63,7 @@ extern int agp_memory_reserved;
63#define INTEL_I7505_AGPCTRL 0x70 63#define INTEL_I7505_AGPCTRL 0x70
64#define INTEL_I7505_MCHCFG 0x50 64#define INTEL_I7505_MCHCFG 0x50
65 65
66static struct aper_size_info_fixed intel_i810_sizes[] = 66static const struct aper_size_info_fixed intel_i810_sizes[] =
67{ 67{
68 {64, 16384, 4}, 68 {64, 16384, 4},
69 /* The 32M mode still requires a 64k gatt */ 69 /* The 32M mode still requires a 64k gatt */
@@ -1365,18 +1365,18 @@ static int intel_7505_configure(void)
1365} 1365}
1366 1366
1367/* Setup function */ 1367/* Setup function */
1368static struct gatt_mask intel_generic_masks[] = 1368static const struct gatt_mask intel_generic_masks[] =
1369{ 1369{
1370 {.mask = 0x00000017, .type = 0} 1370 {.mask = 0x00000017, .type = 0}
1371}; 1371};
1372 1372
1373static struct aper_size_info_8 intel_815_sizes[2] = 1373static const struct aper_size_info_8 intel_815_sizes[2] =
1374{ 1374{
1375 {64, 16384, 4, 0}, 1375 {64, 16384, 4, 0},
1376 {32, 8192, 3, 8}, 1376 {32, 8192, 3, 8},
1377}; 1377};
1378 1378
1379static struct aper_size_info_8 intel_8xx_sizes[7] = 1379static const struct aper_size_info_8 intel_8xx_sizes[7] =
1380{ 1380{
1381 {256, 65536, 6, 0}, 1381 {256, 65536, 6, 0},
1382 {128, 32768, 5, 32}, 1382 {128, 32768, 5, 32},
@@ -1387,7 +1387,7 @@ static struct aper_size_info_8 intel_8xx_sizes[7] =
1387 {4, 1024, 0, 63} 1387 {4, 1024, 0, 63}
1388}; 1388};
1389 1389
1390static struct aper_size_info_16 intel_generic_sizes[7] = 1390static const struct aper_size_info_16 intel_generic_sizes[7] =
1391{ 1391{
1392 {256, 65536, 6, 0}, 1392 {256, 65536, 6, 0},
1393 {128, 32768, 5, 32}, 1393 {128, 32768, 5, 32},
@@ -1398,7 +1398,7 @@ static struct aper_size_info_16 intel_generic_sizes[7] =
1398 {4, 1024, 0, 63} 1398 {4, 1024, 0, 63}
1399}; 1399};
1400 1400
1401static struct aper_size_info_8 intel_830mp_sizes[4] = 1401static const struct aper_size_info_8 intel_830mp_sizes[4] =
1402{ 1402{
1403 {256, 65536, 6, 0}, 1403 {256, 65536, 6, 0},
1404 {128, 32768, 5, 32}, 1404 {128, 32768, 5, 32},
@@ -1406,7 +1406,7 @@ static struct aper_size_info_8 intel_830mp_sizes[4] =
1406 {32, 8192, 3, 56} 1406 {32, 8192, 3, 56}
1407}; 1407};
1408 1408
1409static struct agp_bridge_driver intel_generic_driver = { 1409static const struct agp_bridge_driver intel_generic_driver = {
1410 .owner = THIS_MODULE, 1410 .owner = THIS_MODULE,
1411 .aperture_sizes = intel_generic_sizes, 1411 .aperture_sizes = intel_generic_sizes,
1412 .size_type = U16_APER_SIZE, 1412 .size_type = U16_APER_SIZE,
@@ -1430,7 +1430,7 @@ static struct agp_bridge_driver intel_generic_driver = {
1430 .agp_type_to_mask_type = agp_generic_type_to_mask_type, 1430 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1431}; 1431};
1432 1432
1433static struct agp_bridge_driver intel_810_driver = { 1433static const struct agp_bridge_driver intel_810_driver = {
1434 .owner = THIS_MODULE, 1434 .owner = THIS_MODULE,
1435 .aperture_sizes = intel_i810_sizes, 1435 .aperture_sizes = intel_i810_sizes,
1436 .size_type = FIXED_APER_SIZE, 1436 .size_type = FIXED_APER_SIZE,
@@ -1455,7 +1455,7 @@ static struct agp_bridge_driver intel_810_driver = {
1455 .agp_type_to_mask_type = agp_generic_type_to_mask_type, 1455 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1456}; 1456};
1457 1457
1458static struct agp_bridge_driver intel_815_driver = { 1458static const struct agp_bridge_driver intel_815_driver = {
1459 .owner = THIS_MODULE, 1459 .owner = THIS_MODULE,
1460 .aperture_sizes = intel_815_sizes, 1460 .aperture_sizes = intel_815_sizes,
1461 .size_type = U8_APER_SIZE, 1461 .size_type = U8_APER_SIZE,
@@ -1479,7 +1479,7 @@ static struct agp_bridge_driver intel_815_driver = {
1479 .agp_type_to_mask_type = agp_generic_type_to_mask_type, 1479 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1480}; 1480};
1481 1481
1482static struct agp_bridge_driver intel_830_driver = { 1482static const struct agp_bridge_driver intel_830_driver = {
1483 .owner = THIS_MODULE, 1483 .owner = THIS_MODULE,
1484 .aperture_sizes = intel_i830_sizes, 1484 .aperture_sizes = intel_i830_sizes,
1485 .size_type = FIXED_APER_SIZE, 1485 .size_type = FIXED_APER_SIZE,
@@ -1504,7 +1504,7 @@ static struct agp_bridge_driver intel_830_driver = {
1504 .agp_type_to_mask_type = intel_i830_type_to_mask_type, 1504 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
1505}; 1505};
1506 1506
1507static struct agp_bridge_driver intel_820_driver = { 1507static const struct agp_bridge_driver intel_820_driver = {
1508 .owner = THIS_MODULE, 1508 .owner = THIS_MODULE,
1509 .aperture_sizes = intel_8xx_sizes, 1509 .aperture_sizes = intel_8xx_sizes,
1510 .size_type = U8_APER_SIZE, 1510 .size_type = U8_APER_SIZE,
@@ -1528,7 +1528,7 @@ static struct agp_bridge_driver intel_820_driver = {
1528 .agp_type_to_mask_type = agp_generic_type_to_mask_type, 1528 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1529}; 1529};
1530 1530
1531static struct agp_bridge_driver intel_830mp_driver = { 1531static const struct agp_bridge_driver intel_830mp_driver = {
1532 .owner = THIS_MODULE, 1532 .owner = THIS_MODULE,
1533 .aperture_sizes = intel_830mp_sizes, 1533 .aperture_sizes = intel_830mp_sizes,
1534 .size_type = U8_APER_SIZE, 1534 .size_type = U8_APER_SIZE,
@@ -1552,7 +1552,7 @@ static struct agp_bridge_driver intel_830mp_driver = {
1552 .agp_type_to_mask_type = agp_generic_type_to_mask_type, 1552 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1553}; 1553};
1554 1554
1555static struct agp_bridge_driver intel_840_driver = { 1555static const struct agp_bridge_driver intel_840_driver = {
1556 .owner = THIS_MODULE, 1556 .owner = THIS_MODULE,
1557 .aperture_sizes = intel_8xx_sizes, 1557 .aperture_sizes = intel_8xx_sizes,
1558 .size_type = U8_APER_SIZE, 1558 .size_type = U8_APER_SIZE,
@@ -1576,7 +1576,7 @@ static struct agp_bridge_driver intel_840_driver = {
1576 .agp_type_to_mask_type = agp_generic_type_to_mask_type, 1576 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1577}; 1577};
1578 1578
1579static struct agp_bridge_driver intel_845_driver = { 1579static const struct agp_bridge_driver intel_845_driver = {
1580 .owner = THIS_MODULE, 1580 .owner = THIS_MODULE,
1581 .aperture_sizes = intel_8xx_sizes, 1581 .aperture_sizes = intel_8xx_sizes,
1582 .size_type = U8_APER_SIZE, 1582 .size_type = U8_APER_SIZE,
@@ -1600,7 +1600,7 @@ static struct agp_bridge_driver intel_845_driver = {
1600 .agp_type_to_mask_type = agp_generic_type_to_mask_type, 1600 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1601}; 1601};
1602 1602
1603static struct agp_bridge_driver intel_850_driver = { 1603static const struct agp_bridge_driver intel_850_driver = {
1604 .owner = THIS_MODULE, 1604 .owner = THIS_MODULE,
1605 .aperture_sizes = intel_8xx_sizes, 1605 .aperture_sizes = intel_8xx_sizes,
1606 .size_type = U8_APER_SIZE, 1606 .size_type = U8_APER_SIZE,
@@ -1624,7 +1624,7 @@ static struct agp_bridge_driver intel_850_driver = {
1624 .agp_type_to_mask_type = agp_generic_type_to_mask_type, 1624 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1625}; 1625};
1626 1626
1627static struct agp_bridge_driver intel_860_driver = { 1627static const struct agp_bridge_driver intel_860_driver = {
1628 .owner = THIS_MODULE, 1628 .owner = THIS_MODULE,
1629 .aperture_sizes = intel_8xx_sizes, 1629 .aperture_sizes = intel_8xx_sizes,
1630 .size_type = U8_APER_SIZE, 1630 .size_type = U8_APER_SIZE,
@@ -1648,7 +1648,7 @@ static struct agp_bridge_driver intel_860_driver = {
1648 .agp_type_to_mask_type = agp_generic_type_to_mask_type, 1648 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1649}; 1649};
1650 1650
1651static struct agp_bridge_driver intel_915_driver = { 1651static const struct agp_bridge_driver intel_915_driver = {
1652 .owner = THIS_MODULE, 1652 .owner = THIS_MODULE,
1653 .aperture_sizes = intel_i830_sizes, 1653 .aperture_sizes = intel_i830_sizes,
1654 .size_type = FIXED_APER_SIZE, 1654 .size_type = FIXED_APER_SIZE,
@@ -1673,7 +1673,7 @@ static struct agp_bridge_driver intel_915_driver = {
1673 .agp_type_to_mask_type = intel_i830_type_to_mask_type, 1673 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
1674}; 1674};
1675 1675
1676static struct agp_bridge_driver intel_i965_driver = { 1676static const struct agp_bridge_driver intel_i965_driver = {
1677 .owner = THIS_MODULE, 1677 .owner = THIS_MODULE,
1678 .aperture_sizes = intel_i830_sizes, 1678 .aperture_sizes = intel_i830_sizes,
1679 .size_type = FIXED_APER_SIZE, 1679 .size_type = FIXED_APER_SIZE,
@@ -1698,7 +1698,7 @@ static struct agp_bridge_driver intel_i965_driver = {
1698 .agp_type_to_mask_type = intel_i830_type_to_mask_type, 1698 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
1699}; 1699};
1700 1700
1701static struct agp_bridge_driver intel_7505_driver = { 1701static const struct agp_bridge_driver intel_7505_driver = {
1702 .owner = THIS_MODULE, 1702 .owner = THIS_MODULE,
1703 .aperture_sizes = intel_8xx_sizes, 1703 .aperture_sizes = intel_8xx_sizes,
1704 .size_type = U8_APER_SIZE, 1704 .size_type = U8_APER_SIZE,
diff --git a/drivers/char/agp/nvidia-agp.c b/drivers/char/agp/nvidia-agp.c
index 2563286b2f..0c9dab557c 100644
--- a/drivers/char/agp/nvidia-agp.c
+++ b/drivers/char/agp/nvidia-agp.c
@@ -272,7 +272,7 @@ static void nvidia_tlbflush(struct agp_memory *mem)
272} 272}
273 273
274 274
275static struct aper_size_info_8 nvidia_generic_sizes[5] = 275static const struct aper_size_info_8 nvidia_generic_sizes[5] =
276{ 276{
277 {512, 131072, 7, 0}, 277 {512, 131072, 7, 0},
278 {256, 65536, 6, 8}, 278 {256, 65536, 6, 8},
@@ -283,13 +283,13 @@ static struct aper_size_info_8 nvidia_generic_sizes[5] =
283}; 283};
284 284
285 285
286static struct gatt_mask nvidia_generic_masks[] = 286static const struct gatt_mask nvidia_generic_masks[] =
287{ 287{
288 { .mask = 1, .type = 0} 288 { .mask = 1, .type = 0}
289}; 289};
290 290
291 291
292static struct agp_bridge_driver nvidia_driver = { 292static const struct agp_bridge_driver nvidia_driver = {
293 .owner = THIS_MODULE, 293 .owner = THIS_MODULE,
294 .aperture_sizes = nvidia_generic_sizes, 294 .aperture_sizes = nvidia_generic_sizes,
295 .size_type = U8_APER_SIZE, 295 .size_type = U8_APER_SIZE,
diff --git a/drivers/char/agp/parisc-agp.c b/drivers/char/agp/parisc-agp.c
index b7b4590673..3d83b461cc 100644
--- a/drivers/char/agp/parisc-agp.c
+++ b/drivers/char/agp/parisc-agp.c
@@ -210,7 +210,7 @@ parisc_agp_enable(struct agp_bridge_data *bridge, u32 mode)
210 agp_device_command(command, (mode & AGP8X_MODE) != 0); 210 agp_device_command(command, (mode & AGP8X_MODE) != 0);
211} 211}
212 212
213struct agp_bridge_driver parisc_agp_driver = { 213static const struct agp_bridge_driver parisc_agp_driver = {
214 .owner = THIS_MODULE, 214 .owner = THIS_MODULE,
215 .size_type = FIXED_APER_SIZE, 215 .size_type = FIXED_APER_SIZE,
216 .configure = parisc_agp_configure, 216 .configure = parisc_agp_configure,
@@ -236,7 +236,7 @@ static int __init
236agp_ioc_init(void __iomem *ioc_regs) 236agp_ioc_init(void __iomem *ioc_regs)
237{ 237{
238 struct _parisc_agp_info *info = &parisc_agp_info; 238 struct _parisc_agp_info *info = &parisc_agp_info;
239 u64 *iova_base, *io_pdir, io_tlb_ps; 239 u64 iova_base, *io_pdir, io_tlb_ps;
240 int io_tlb_shift; 240 int io_tlb_shift;
241 241
242 printk(KERN_INFO DRVPFX "IO PDIR shared with sba_iommu\n"); 242 printk(KERN_INFO DRVPFX "IO PDIR shared with sba_iommu\n");
diff --git a/drivers/char/agp/sgi-agp.c b/drivers/char/agp/sgi-agp.c
index 92d1dc45b9..ee8f50edde 100644
--- a/drivers/char/agp/sgi-agp.c
+++ b/drivers/char/agp/sgi-agp.c
@@ -247,7 +247,7 @@ static struct agp_bridge_data *sgi_tioca_find_bridge(struct pci_dev *pdev)
247 return bridge; 247 return bridge;
248} 248}
249 249
250struct agp_bridge_driver sgi_tioca_driver = { 250const struct agp_bridge_driver sgi_tioca_driver = {
251 .owner = THIS_MODULE, 251 .owner = THIS_MODULE,
252 .size_type = U16_APER_SIZE, 252 .size_type = U16_APER_SIZE,
253 .configure = sgi_tioca_configure, 253 .configure = sgi_tioca_configure,
diff --git a/drivers/char/agp/sis-agp.c b/drivers/char/agp/sis-agp.c
index 60342b7081..125f4282d9 100644
--- a/drivers/char/agp/sis-agp.c
+++ b/drivers/char/agp/sis-agp.c
@@ -108,7 +108,7 @@ static void sis_delayed_enable(struct agp_bridge_data *bridge, u32 mode)
108 } 108 }
109} 109}
110 110
111static struct aper_size_info_8 sis_generic_sizes[7] = 111static const struct aper_size_info_8 sis_generic_sizes[7] =
112{ 112{
113 {256, 65536, 6, 99}, 113 {256, 65536, 6, 99},
114 {128, 32768, 5, 83}, 114 {128, 32768, 5, 83},
diff --git a/drivers/char/agp/sworks-agp.c b/drivers/char/agp/sworks-agp.c
index 9f5ae7714f..55212a3811 100644
--- a/drivers/char/agp/sworks-agp.c
+++ b/drivers/char/agp/sworks-agp.c
@@ -385,12 +385,12 @@ static int serverworks_remove_memory(struct agp_memory *mem, off_t pg_start,
385 return 0; 385 return 0;
386} 386}
387 387
388static struct gatt_mask serverworks_masks[] = 388static const struct gatt_mask serverworks_masks[] =
389{ 389{
390 {.mask = 1, .type = 0} 390 {.mask = 1, .type = 0}
391}; 391};
392 392
393static struct aper_size_info_lvl2 serverworks_sizes[7] = 393static const struct aper_size_info_lvl2 serverworks_sizes[7] =
394{ 394{
395 {2048, 524288, 0x80000000}, 395 {2048, 524288, 0x80000000},
396 {1024, 262144, 0xc0000000}, 396 {1024, 262144, 0xc0000000},
@@ -423,7 +423,7 @@ static void serverworks_agp_enable(struct agp_bridge_data *bridge, u32 mode)
423 agp_device_command(command, 0); 423 agp_device_command(command, 0);
424} 424}
425 425
426static struct agp_bridge_driver sworks_driver = { 426static const struct agp_bridge_driver sworks_driver = {
427 .owner = THIS_MODULE, 427 .owner = THIS_MODULE,
428 .aperture_sizes = serverworks_sizes, 428 .aperture_sizes = serverworks_sizes,
429 .size_type = LVL2_APER_SIZE, 429 .size_type = LVL2_APER_SIZE,
diff --git a/drivers/char/agp/uninorth-agp.c b/drivers/char/agp/uninorth-agp.c
index 6c45702e54..91b062126a 100644
--- a/drivers/char/agp/uninorth-agp.c
+++ b/drivers/char/agp/uninorth-agp.c
@@ -460,7 +460,7 @@ void null_cache_flush(void)
460 460
461/* Setup function */ 461/* Setup function */
462 462
463static struct aper_size_info_32 uninorth_sizes[7] = 463static const struct aper_size_info_32 uninorth_sizes[7] =
464{ 464{
465#if 0 /* Not sure uninorth supports that high aperture sizes */ 465#if 0 /* Not sure uninorth supports that high aperture sizes */
466 {256, 65536, 6, 64}, 466 {256, 65536, 6, 64},
@@ -477,7 +477,7 @@ static struct aper_size_info_32 uninorth_sizes[7] =
477 * Not sure that u3 supports that high aperture sizes but it 477 * Not sure that u3 supports that high aperture sizes but it
478 * would strange if it did not :) 478 * would strange if it did not :)
479 */ 479 */
480static struct aper_size_info_32 u3_sizes[8] = 480static const struct aper_size_info_32 u3_sizes[8] =
481{ 481{
482 {512, 131072, 7, 128}, 482 {512, 131072, 7, 128},
483 {256, 65536, 6, 64}, 483 {256, 65536, 6, 64},
@@ -489,7 +489,7 @@ static struct aper_size_info_32 u3_sizes[8] =
489 {4, 1024, 0, 1} 489 {4, 1024, 0, 1}
490}; 490};
491 491
492struct agp_bridge_driver uninorth_agp_driver = { 492const struct agp_bridge_driver uninorth_agp_driver = {
493 .owner = THIS_MODULE, 493 .owner = THIS_MODULE,
494 .aperture_sizes = (void *)uninorth_sizes, 494 .aperture_sizes = (void *)uninorth_sizes,
495 .size_type = U32_APER_SIZE, 495 .size_type = U32_APER_SIZE,
@@ -514,7 +514,7 @@ struct agp_bridge_driver uninorth_agp_driver = {
514 .cant_use_aperture = 1, 514 .cant_use_aperture = 1,
515}; 515};
516 516
517struct agp_bridge_driver u3_agp_driver = { 517const struct agp_bridge_driver u3_agp_driver = {
518 .owner = THIS_MODULE, 518 .owner = THIS_MODULE,
519 .aperture_sizes = (void *)u3_sizes, 519 .aperture_sizes = (void *)u3_sizes,
520 .size_type = U32_APER_SIZE, 520 .size_type = U32_APER_SIZE,
diff --git a/drivers/char/agp/via-agp.c b/drivers/char/agp/via-agp.c
index 2e7c04370c..a2bb4eccaa 100644
--- a/drivers/char/agp/via-agp.c
+++ b/drivers/char/agp/via-agp.c
@@ -89,7 +89,7 @@ static void via_tlbflush(struct agp_memory *mem)
89} 89}
90 90
91 91
92static struct aper_size_info_8 via_generic_sizes[9] = 92static const struct aper_size_info_8 via_generic_sizes[9] =
93{ 93{
94 {256, 65536, 6, 0}, 94 {256, 65536, 6, 0},
95 {128, 32768, 5, 128}, 95 {128, 32768, 5, 128},
@@ -170,7 +170,7 @@ static void via_tlbflush_agp3(struct agp_memory *mem)
170} 170}
171 171
172 172
173static struct agp_bridge_driver via_agp3_driver = { 173static const struct agp_bridge_driver via_agp3_driver = {
174 .owner = THIS_MODULE, 174 .owner = THIS_MODULE,
175 .aperture_sizes = agp3_generic_sizes, 175 .aperture_sizes = agp3_generic_sizes,
176 .size_type = U8_APER_SIZE, 176 .size_type = U8_APER_SIZE,
@@ -194,7 +194,7 @@ static struct agp_bridge_driver via_agp3_driver = {
194 .agp_type_to_mask_type = agp_generic_type_to_mask_type, 194 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
195}; 195};
196 196
197static struct agp_bridge_driver via_driver = { 197static const struct agp_bridge_driver via_driver = {
198 .owner = THIS_MODULE, 198 .owner = THIS_MODULE,
199 .aperture_sizes = via_generic_sizes, 199 .aperture_sizes = via_generic_sizes,
200 .size_type = U8_APER_SIZE, 200 .size_type = U8_APER_SIZE,
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index 54df35527b..16dc5d1d3c 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -3501,6 +3501,7 @@ get_serial_info(struct cyclades_port *info,
3501 tmp.irq = cinfo->irq; 3501 tmp.irq = cinfo->irq;
3502 tmp.flags = info->flags; 3502 tmp.flags = info->flags;
3503 tmp.close_delay = info->close_delay; 3503 tmp.close_delay = info->close_delay;
3504 tmp.closing_wait = info->closing_wait;
3504 tmp.baud_base = info->baud; 3505 tmp.baud_base = info->baud;
3505 tmp.custom_divisor = info->custom_divisor; 3506 tmp.custom_divisor = info->custom_divisor;
3506 tmp.hub6 = 0; /*!!! */ 3507 tmp.hub6 = 0; /*!!! */
diff --git a/drivers/char/ds1286.c b/drivers/char/ds1286.c
index 6d58b03708..59146e3365 100644
--- a/drivers/char/ds1286.c
+++ b/drivers/char/ds1286.c
@@ -197,6 +197,7 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
197 197
198 hrs = alm_tm.tm_hour; 198 hrs = alm_tm.tm_hour;
199 min = alm_tm.tm_min; 199 min = alm_tm.tm_min;
200 sec = alm_tm.tm_sec;
200 201
201 if (hrs >= 24) 202 if (hrs >= 24)
202 hrs = 0xff; 203 hrs = 0xff;
@@ -204,9 +205,11 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
204 if (min >= 60) 205 if (min >= 60)
205 min = 0xff; 206 min = 0xff;
206 207
207 BIN_TO_BCD(sec); 208 if (sec != 0)
208 BIN_TO_BCD(min); 209 return -EINVAL;
209 BIN_TO_BCD(hrs); 210
211 min = BIN2BCD(min);
212 min = BIN2BCD(hrs);
210 213
211 spin_lock(&ds1286_lock); 214 spin_lock(&ds1286_lock);
212 rtc_write(hrs, RTC_HOURS_ALARM); 215 rtc_write(hrs, RTC_HOURS_ALARM);
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index 88fc24fc43..de5be30484 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -209,7 +209,6 @@ static void digi_send_break(struct channel *ch, int msec);
209static void setup_empty_event(struct tty_struct *tty, struct channel *ch); 209static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
210void epca_setup(char *, int *); 210void epca_setup(char *, int *);
211 211
212static int get_termio(struct tty_struct *, struct termio __user *);
213static int pc_write(struct tty_struct *, const unsigned char *, int); 212static int pc_write(struct tty_struct *, const unsigned char *, int);
214static int pc_init(void); 213static int pc_init(void);
215static int init_PCI(void); 214static int init_PCI(void);
@@ -2362,15 +2361,6 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2362 2361
2363 switch (cmd) 2362 switch (cmd)
2364 { /* Begin switch cmd */ 2363 { /* Begin switch cmd */
2365
2366#if 0 /* Handled by calling layer properly */
2367 case TCGETS:
2368 if (copy_to_user(argp, tty->termios, sizeof(struct ktermios)))
2369 return -EFAULT;
2370 return 0;
2371 case TCGETA:
2372 return get_termio(tty, argp);
2373#endif
2374 case TCSBRK: /* SVID version: non-zero arg --> no break */ 2364 case TCSBRK: /* SVID version: non-zero arg --> no break */
2375 retval = tty_check_change(tty); 2365 retval = tty_check_change(tty);
2376 if (retval) 2366 if (retval)
@@ -2735,13 +2725,6 @@ static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2735 memoff(ch); 2725 memoff(ch);
2736} /* End setup_empty_event */ 2726} /* End setup_empty_event */
2737 2727
2738/* --------------------- Begin get_termio ----------------------- */
2739
2740static int get_termio(struct tty_struct * tty, struct termio __user * termio)
2741{ /* Begin get_termio */
2742 return kernel_termios_to_user_termio(termio, tty->termios);
2743} /* End get_termio */
2744
2745/* ---------------------- Begin epca_setup -------------------------- */ 2728/* ---------------------- Begin epca_setup -------------------------- */
2746void epca_setup(char *str, int *ints) 2729void epca_setup(char *str, int *ints)
2747{ /* Begin epca_setup */ 2730{ /* Begin epca_setup */
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index cc2cd46bed..a0a88aa23f 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -316,7 +316,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
316{ 316{
317 struct hvc_struct *hp; 317 struct hvc_struct *hp;
318 unsigned long flags; 318 unsigned long flags;
319 int irq = NO_IRQ; 319 int irq = 0;
320 int rc = 0; 320 int rc = 0;
321 struct kobject *kobjp; 321 struct kobject *kobjp;
322 322
@@ -338,14 +338,14 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
338 hp->tty = tty; 338 hp->tty = tty;
339 /* Save for request_irq outside of spin_lock. */ 339 /* Save for request_irq outside of spin_lock. */
340 irq = hp->irq; 340 irq = hp->irq;
341 if (irq != NO_IRQ) 341 if (irq)
342 hp->irq_requested = 1; 342 hp->irq_requested = 1;
343 343
344 kobjp = &hp->kobj; 344 kobjp = &hp->kobj;
345 345
346 spin_unlock_irqrestore(&hp->lock, flags); 346 spin_unlock_irqrestore(&hp->lock, flags);
347 /* check error, fallback to non-irq */ 347 /* check error, fallback to non-irq */
348 if (irq != NO_IRQ) 348 if (irq)
349 rc = request_irq(irq, hvc_handle_interrupt, IRQF_DISABLED, "hvc_console", hp); 349 rc = request_irq(irq, hvc_handle_interrupt, IRQF_DISABLED, "hvc_console", hp);
350 350
351 /* 351 /*
@@ -373,7 +373,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
373{ 373{
374 struct hvc_struct *hp; 374 struct hvc_struct *hp;
375 struct kobject *kobjp; 375 struct kobject *kobjp;
376 int irq = NO_IRQ; 376 int irq = 0;
377 unsigned long flags; 377 unsigned long flags;
378 378
379 if (tty_hung_up_p(filp)) 379 if (tty_hung_up_p(filp))
@@ -407,7 +407,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
407 */ 407 */
408 tty_wait_until_sent(tty, HVC_CLOSE_WAIT); 408 tty_wait_until_sent(tty, HVC_CLOSE_WAIT);
409 409
410 if (irq != NO_IRQ) 410 if (irq)
411 free_irq(irq, hp); 411 free_irq(irq, hp);
412 412
413 } else { 413 } else {
@@ -424,7 +424,7 @@ static void hvc_hangup(struct tty_struct *tty)
424{ 424{
425 struct hvc_struct *hp = tty->driver_data; 425 struct hvc_struct *hp = tty->driver_data;
426 unsigned long flags; 426 unsigned long flags;
427 int irq = NO_IRQ; 427 int irq = 0;
428 int temp_open_count; 428 int temp_open_count;
429 struct kobject *kobjp; 429 struct kobject *kobjp;
430 430
@@ -453,7 +453,7 @@ static void hvc_hangup(struct tty_struct *tty)
453 irq = hp->irq; 453 irq = hp->irq;
454 hp->irq_requested = 0; 454 hp->irq_requested = 0;
455 spin_unlock_irqrestore(&hp->lock, flags); 455 spin_unlock_irqrestore(&hp->lock, flags);
456 if (irq != NO_IRQ) 456 if (irq)
457 free_irq(irq, hp); 457 free_irq(irq, hp);
458 while(temp_open_count) { 458 while(temp_open_count) {
459 --temp_open_count; 459 --temp_open_count;
@@ -583,7 +583,7 @@ static int hvc_poll(struct hvc_struct *hp)
583 /* If we aren't interrupt driven and aren't throttled, we always 583 /* If we aren't interrupt driven and aren't throttled, we always
584 * request a reschedule 584 * request a reschedule
585 */ 585 */
586 if (hp->irq == NO_IRQ) 586 if (hp->irq == 0)
587 poll_mask |= HVC_POLL_READ; 587 poll_mask |= HVC_POLL_READ;
588 588
589 /* Read data if any */ 589 /* Read data if any */
diff --git a/drivers/char/ip2/i2lib.c b/drivers/char/ip2/i2lib.c
index f86fa0c55d..e46120d05b 100644
--- a/drivers/char/ip2/i2lib.c
+++ b/drivers/char/ip2/i2lib.c
@@ -80,7 +80,7 @@ static int i2RetryFlushOutput(i2ChanStrPtr);
80// Not a documented part of the library routines (careful...) but the Diagnostic 80// Not a documented part of the library routines (careful...) but the Diagnostic
81// i2diag.c finds them useful to help the throughput in certain limited 81// i2diag.c finds them useful to help the throughput in certain limited
82// single-threaded operations. 82// single-threaded operations.
83static inline void iiSendPendingMail(i2eBordStrPtr); 83static void iiSendPendingMail(i2eBordStrPtr);
84static void serviceOutgoingFifo(i2eBordStrPtr); 84static void serviceOutgoingFifo(i2eBordStrPtr);
85 85
86// Functions defined in ip2.c as part of interrupt handling 86// Functions defined in ip2.c as part of interrupt handling
@@ -166,7 +166,7 @@ static void iiSendPendingMail_t(unsigned long data)
166// If any outgoing mail bits are set and there is outgoing mailbox is empty, 166// If any outgoing mail bits are set and there is outgoing mailbox is empty,
167// send the mail and clear the bits. 167// send the mail and clear the bits.
168//****************************************************************************** 168//******************************************************************************
169static inline void 169static void
170iiSendPendingMail(i2eBordStrPtr pB) 170iiSendPendingMail(i2eBordStrPtr pB)
171{ 171{
172 if (pB->i2eOutMailWaiting && (!pB->i2eWaitingForEmptyFifo) ) 172 if (pB->i2eOutMailWaiting && (!pB->i2eWaitingForEmptyFifo) )
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index a7b33d2f59..e22146546a 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -2478,6 +2478,11 @@ static __devinit void default_find_bmc(void)
2478 if (!info) 2478 if (!info)
2479 return; 2479 return;
2480 2480
2481#ifdef CONFIG_PPC_MERGE
2482 if (check_legacy_ioport(ipmi_defaults[i].port))
2483 continue;
2484#endif
2485
2481 info->addr_source = NULL; 2486 info->addr_source = NULL;
2482 2487
2483 info->si_type = ipmi_defaults[i].type; 2488 info->si_type = ipmi_defaults[i].type;
diff --git a/drivers/char/lcd.c b/drivers/char/lcd.c
index d649abbf08..5f4fdcf7c9 100644
--- a/drivers/char/lcd.c
+++ b/drivers/char/lcd.c
@@ -409,138 +409,6 @@ static int lcd_ioctl(struct inode *inode, struct file *file,
409 break; 409 break;
410 } 410 }
411 411
412// Erase the flash
413
414 case FLASH_Erase:{
415
416 int ctr = 0;
417
418 if ( !capable(CAP_SYS_ADMIN) ) return -EPERM;
419
420 pr_info(LCD "Erasing Flash\n");
421
422 // Chip Erase Sequence
423 WRITE_FLASH(kFlash_Addr1, kFlash_Data1);
424 WRITE_FLASH(kFlash_Addr2, kFlash_Data2);
425 WRITE_FLASH(kFlash_Addr1, kFlash_Erase3);
426 WRITE_FLASH(kFlash_Addr1, kFlash_Data1);
427 WRITE_FLASH(kFlash_Addr2, kFlash_Data2);
428 WRITE_FLASH(kFlash_Addr1, kFlash_Erase6);
429
430 while ((!dqpoll(0x00000000, 0xFF))
431 && (!timeout(0x00000000))) {
432 ctr++;
433 }
434
435 if (READ_FLASH(0x07FFF0) == 0xFF) {
436 pr_info(LCD "Erase Successful\n");
437 } else if (timeout) {
438 pr_info(LCD "Erase Timed Out\n");
439 }
440
441 break;
442 }
443
444// burn the flash
445
446 case FLASH_Burn:{
447
448 volatile unsigned long burn_addr;
449 unsigned long flags;
450 unsigned int i, index;
451 unsigned char *rom;
452
453
454 struct lcd_display display;
455
456 if ( !capable(CAP_SYS_ADMIN) ) return -EPERM;
457
458 if (copy_from_user
459 (&display, (struct lcd_display *) arg,
460 sizeof(struct lcd_display)))
461 return -EFAULT;
462 rom = kmalloc((128), GFP_ATOMIC);
463 if (rom == NULL) {
464 printk(KERN_ERR LCD "kmalloc() failed in %s\n",
465 __FUNCTION__);
466 return -ENOMEM;
467 }
468
469 pr_info(LCD "Starting Flash burn\n");
470 for (i = 0; i < FLASH_SIZE; i = i + 128) {
471
472 if (copy_from_user
473 (rom, display.RomImage + i, 128)) {
474 kfree(rom);
475 return -EFAULT;
476 }
477 burn_addr = kFlashBase + i;
478 spin_lock_irqsave(&lcd_lock, flags);
479 for (index = 0; index < (128); index++) {
480
481 WRITE_FLASH(kFlash_Addr1,
482 kFlash_Data1);
483 WRITE_FLASH(kFlash_Addr2,
484 kFlash_Data2);
485 WRITE_FLASH(kFlash_Addr1,
486 kFlash_Prog);
487 *((volatile unsigned char *)burn_addr) =
488 (volatile unsigned char) rom[index];
489
490 while ((!dqpoll (burn_addr,
491 (volatile unsigned char)
492 rom[index])) &&
493 (!timeout(burn_addr))) { }
494 burn_addr++;
495 }
496 spin_unlock_irqrestore(&lcd_lock, flags);
497 if (* ((volatile unsigned char *)
498 (burn_addr - 1)) ==
499 (volatile unsigned char)
500 rom[index - 1]) {
501 } else if (timeout) {
502 pr_info(LCD "Flash burn timed out\n");
503 }
504
505
506 }
507 kfree(rom);
508
509 pr_info(LCD "Flash successfully burned\n");
510
511 break;
512 }
513
514// read the flash all at once
515
516 case FLASH_Read:{
517
518 unsigned char *user_bytes;
519 volatile unsigned long read_addr;
520 unsigned int i;
521
522 user_bytes =
523 &(((struct lcd_display *) arg)->RomImage[0]);
524
525 if (!access_ok
526 (VERIFY_WRITE, user_bytes, FLASH_SIZE))
527 return -EFAULT;
528
529 pr_info(LCD "Reading Flash");
530 for (i = 0; i < FLASH_SIZE; i++) {
531 unsigned char tmp_byte;
532 read_addr = kFlashBase + i;
533 tmp_byte =
534 *((volatile unsigned char *)
535 read_addr);
536 if (__put_user(tmp_byte, &user_bytes[i]))
537 return -EFAULT;
538 }
539
540
541 break;
542 }
543
544 default: 412 default:
545 return -EINVAL; 413 return -EINVAL;
546 414
@@ -644,42 +512,6 @@ static void __exit lcd_exit(void)
644 misc_deregister(&lcd_dev); 512 misc_deregister(&lcd_dev);
645} 513}
646 514
647//
648// Function: dqpoll
649//
650// Description: Polls the data lines to see if the flash is busy
651//
652// In: address, byte data
653//
654// Out: 0 = busy, 1 = write or erase complete
655//
656//
657
658static int dqpoll(volatile unsigned long address, volatile unsigned char data)
659{
660 volatile unsigned char dq7;
661
662 dq7 = data & 0x80;
663
664 return ((READ_FLASH(address) & 0x80) == dq7);
665}
666
667//
668// Function: timeout
669//
670// Description: Checks to see if erase or write has timed out
671// By polling dq5
672//
673// In: address
674//
675//
676// Out: 0 = not timed out, 1 = timed out
677
678static int timeout(volatile unsigned long address)
679{
680 return (READ_FLASH(address) & 0x20) == 0x20;
681}
682
683module_init(lcd_init); 515module_init(lcd_init);
684module_exit(lcd_exit); 516module_exit(lcd_exit);
685 517
diff --git a/drivers/char/lcd.h b/drivers/char/lcd.h
index a8d4ae7371..290b3ff23b 100644
--- a/drivers/char/lcd.h
+++ b/drivers/char/lcd.h
@@ -14,11 +14,7 @@
14 14
15// function headers 15// function headers
16 16
17static int dqpoll(volatile unsigned long, volatile unsigned char );
18static int timeout(volatile unsigned long);
19
20#define LCD_CHARS_PER_LINE 40 17#define LCD_CHARS_PER_LINE 40
21#define FLASH_SIZE 524288
22#define MAX_IDLE_TIME 120 18#define MAX_IDLE_TIME 120
23 19
24struct lcd_display { 20struct lcd_display {
@@ -54,26 +50,6 @@ struct lcd_display {
54#define LCDTimeoutValue 0xfff 50#define LCDTimeoutValue 0xfff
55 51
56 52
57// Flash definitions AMD 29F040
58#define kFlashBase 0x0FC00000
59
60#define kFlash_Addr1 0x5555
61#define kFlash_Addr2 0x2AAA
62#define kFlash_Data1 0xAA
63#define kFlash_Data2 0x55
64#define kFlash_Prog 0xA0
65#define kFlash_Erase3 0x80
66#define kFlash_Erase6 0x10
67#define kFlash_Read 0xF0
68
69#define kFlash_ID 0x90
70#define kFlash_VenAddr 0x00
71#define kFlash_DevAddr 0x01
72#define kFlash_VenID 0x01
73#define kFlash_DevID 0xA4 // 29F040
74//#define kFlash_DevID 0xAD // 29F016
75
76
77// Macros 53// Macros
78 54
79#define LCDWriteData(x) outl((x << 24), kLCD_DR) 55#define LCDWriteData(x) outl((x << 24), kLCD_DR)
@@ -89,9 +65,6 @@ struct lcd_display {
89#define WRITE_GAL(x,y) outl(y, 0x04000000 | (x)) 65#define WRITE_GAL(x,y) outl(y, 0x04000000 | (x))
90#define BusyCheck() while ((LCDReadInst & 0x80) == 0x80) 66#define BusyCheck() while ((LCDReadInst & 0x80) == 0x80)
91 67
92#define WRITE_FLASH(x,y) outb((char)y, kFlashBase | (x))
93#define READ_FLASH(x) (inb(kFlashBase | (x)))
94
95 68
96 69
97/* 70/*
@@ -124,11 +97,6 @@ struct lcd_display {
124// Button defs 97// Button defs
125#define BUTTON_Read 50 98#define BUTTON_Read 50
126 99
127// Flash command codes
128#define FLASH_Erase 60
129#define FLASH_Burn 61
130#define FLASH_Read 62
131
132 100
133// Ethernet LINK check hackaroo 101// Ethernet LINK check hackaroo
134#define LINK_Check 90 102#define LINK_Check 90
diff --git a/drivers/char/mwave/3780i.c b/drivers/char/mwave/3780i.c
index 4e4865e90e..492dbfb2ef 100644
--- a/drivers/char/mwave/3780i.c
+++ b/drivers/char/mwave/3780i.c
@@ -63,8 +63,6 @@
63#include "3780i.h" 63#include "3780i.h"
64 64
65static DEFINE_SPINLOCK(dsp_lock); 65static DEFINE_SPINLOCK(dsp_lock);
66static unsigned long flags;
67
68 66
69static void PaceMsaAccess(unsigned short usDspBaseIO) 67static void PaceMsaAccess(unsigned short usDspBaseIO)
70{ 68{
@@ -76,6 +74,7 @@ static void PaceMsaAccess(unsigned short usDspBaseIO)
76unsigned short dsp3780I_ReadMsaCfg(unsigned short usDspBaseIO, 74unsigned short dsp3780I_ReadMsaCfg(unsigned short usDspBaseIO,
77 unsigned long ulMsaAddr) 75 unsigned long ulMsaAddr)
78{ 76{
77 unsigned long flags;
79 unsigned short val; 78 unsigned short val;
80 79
81 PRINTK_3(TRACE_3780I, 80 PRINTK_3(TRACE_3780I,
@@ -96,6 +95,7 @@ unsigned short dsp3780I_ReadMsaCfg(unsigned short usDspBaseIO,
96void dsp3780I_WriteMsaCfg(unsigned short usDspBaseIO, 95void dsp3780I_WriteMsaCfg(unsigned short usDspBaseIO,
97 unsigned long ulMsaAddr, unsigned short usValue) 96 unsigned long ulMsaAddr, unsigned short usValue)
98{ 97{
98 unsigned long flags;
99 99
100 PRINTK_4(TRACE_3780I, 100 PRINTK_4(TRACE_3780I,
101 "3780i::dsp3780i_WriteMsaCfg entry usDspBaseIO %x ulMsaAddr %lx usValue %x\n", 101 "3780i::dsp3780i_WriteMsaCfg entry usDspBaseIO %x ulMsaAddr %lx usValue %x\n",
@@ -175,6 +175,7 @@ int dsp3780I_EnableDSP(DSP_3780I_CONFIG_SETTINGS * pSettings,
175 unsigned short *pIrqMap, 175 unsigned short *pIrqMap,
176 unsigned short *pDmaMap) 176 unsigned short *pDmaMap)
177{ 177{
178 unsigned long flags;
178 unsigned short usDspBaseIO = pSettings->usDspBaseIO; 179 unsigned short usDspBaseIO = pSettings->usDspBaseIO;
179 int i; 180 int i;
180 DSP_UART_CFG_1 rUartCfg1; 181 DSP_UART_CFG_1 rUartCfg1;
@@ -354,6 +355,7 @@ int dsp3780I_EnableDSP(DSP_3780I_CONFIG_SETTINGS * pSettings,
354 355
355int dsp3780I_DisableDSP(DSP_3780I_CONFIG_SETTINGS * pSettings) 356int dsp3780I_DisableDSP(DSP_3780I_CONFIG_SETTINGS * pSettings)
356{ 357{
358 unsigned long flags;
357 unsigned short usDspBaseIO = pSettings->usDspBaseIO; 359 unsigned short usDspBaseIO = pSettings->usDspBaseIO;
358 DSP_ISA_SLAVE_CONTROL rSlaveControl; 360 DSP_ISA_SLAVE_CONTROL rSlaveControl;
359 361
@@ -383,6 +385,7 @@ int dsp3780I_DisableDSP(DSP_3780I_CONFIG_SETTINGS * pSettings)
383 385
384int dsp3780I_Reset(DSP_3780I_CONFIG_SETTINGS * pSettings) 386int dsp3780I_Reset(DSP_3780I_CONFIG_SETTINGS * pSettings)
385{ 387{
388 unsigned long flags;
386 unsigned short usDspBaseIO = pSettings->usDspBaseIO; 389 unsigned short usDspBaseIO = pSettings->usDspBaseIO;
387 DSP_BOOT_DOMAIN rBootDomain; 390 DSP_BOOT_DOMAIN rBootDomain;
388 DSP_HBRIDGE_CONTROL rHBridgeControl; 391 DSP_HBRIDGE_CONTROL rHBridgeControl;
@@ -427,6 +430,7 @@ int dsp3780I_Reset(DSP_3780I_CONFIG_SETTINGS * pSettings)
427 430
428int dsp3780I_Run(DSP_3780I_CONFIG_SETTINGS * pSettings) 431int dsp3780I_Run(DSP_3780I_CONFIG_SETTINGS * pSettings)
429{ 432{
433 unsigned long flags;
430 unsigned short usDspBaseIO = pSettings->usDspBaseIO; 434 unsigned short usDspBaseIO = pSettings->usDspBaseIO;
431 DSP_BOOT_DOMAIN rBootDomain; 435 DSP_BOOT_DOMAIN rBootDomain;
432 DSP_HBRIDGE_CONTROL rHBridgeControl; 436 DSP_HBRIDGE_CONTROL rHBridgeControl;
@@ -473,6 +477,7 @@ int dsp3780I_Run(DSP_3780I_CONFIG_SETTINGS * pSettings)
473int dsp3780I_ReadDStore(unsigned short usDspBaseIO, void __user *pvBuffer, 477int dsp3780I_ReadDStore(unsigned short usDspBaseIO, void __user *pvBuffer,
474 unsigned uCount, unsigned long ulDSPAddr) 478 unsigned uCount, unsigned long ulDSPAddr)
475{ 479{
480 unsigned long flags;
476 unsigned short __user *pusBuffer = pvBuffer; 481 unsigned short __user *pusBuffer = pvBuffer;
477 unsigned short val; 482 unsigned short val;
478 483
@@ -514,6 +519,7 @@ int dsp3780I_ReadAndClearDStore(unsigned short usDspBaseIO,
514 void __user *pvBuffer, unsigned uCount, 519 void __user *pvBuffer, unsigned uCount,
515 unsigned long ulDSPAddr) 520 unsigned long ulDSPAddr)
516{ 521{
522 unsigned long flags;
517 unsigned short __user *pusBuffer = pvBuffer; 523 unsigned short __user *pusBuffer = pvBuffer;
518 unsigned short val; 524 unsigned short val;
519 525
@@ -555,6 +561,7 @@ int dsp3780I_ReadAndClearDStore(unsigned short usDspBaseIO,
555int dsp3780I_WriteDStore(unsigned short usDspBaseIO, void __user *pvBuffer, 561int dsp3780I_WriteDStore(unsigned short usDspBaseIO, void __user *pvBuffer,
556 unsigned uCount, unsigned long ulDSPAddr) 562 unsigned uCount, unsigned long ulDSPAddr)
557{ 563{
564 unsigned long flags;
558 unsigned short __user *pusBuffer = pvBuffer; 565 unsigned short __user *pusBuffer = pvBuffer;
559 566
560 567
@@ -596,6 +603,7 @@ int dsp3780I_WriteDStore(unsigned short usDspBaseIO, void __user *pvBuffer,
596int dsp3780I_ReadIStore(unsigned short usDspBaseIO, void __user *pvBuffer, 603int dsp3780I_ReadIStore(unsigned short usDspBaseIO, void __user *pvBuffer,
597 unsigned uCount, unsigned long ulDSPAddr) 604 unsigned uCount, unsigned long ulDSPAddr)
598{ 605{
606 unsigned long flags;
599 unsigned short __user *pusBuffer = pvBuffer; 607 unsigned short __user *pusBuffer = pvBuffer;
600 608
601 PRINTK_5(TRACE_3780I, 609 PRINTK_5(TRACE_3780I,
@@ -643,6 +651,7 @@ int dsp3780I_ReadIStore(unsigned short usDspBaseIO, void __user *pvBuffer,
643int dsp3780I_WriteIStore(unsigned short usDspBaseIO, void __user *pvBuffer, 651int dsp3780I_WriteIStore(unsigned short usDspBaseIO, void __user *pvBuffer,
644 unsigned uCount, unsigned long ulDSPAddr) 652 unsigned uCount, unsigned long ulDSPAddr)
645{ 653{
654 unsigned long flags;
646 unsigned short __user *pusBuffer = pvBuffer; 655 unsigned short __user *pusBuffer = pvBuffer;
647 656
648 PRINTK_5(TRACE_3780I, 657 PRINTK_5(TRACE_3780I,
@@ -691,6 +700,7 @@ int dsp3780I_WriteIStore(unsigned short usDspBaseIO, void __user *pvBuffer,
691int dsp3780I_GetIPCSource(unsigned short usDspBaseIO, 700int dsp3780I_GetIPCSource(unsigned short usDspBaseIO,
692 unsigned short *pusIPCSource) 701 unsigned short *pusIPCSource)
693{ 702{
703 unsigned long flags;
694 DSP_HBRIDGE_CONTROL rHBridgeControl; 704 DSP_HBRIDGE_CONTROL rHBridgeControl;
695 unsigned short temp; 705 unsigned short temp;
696 706
diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c
index 0e82968c2f..f2e4ec4fd4 100644
--- a/drivers/char/pcmcia/cm4040_cs.c
+++ b/drivers/char/pcmcia/cm4040_cs.c
@@ -273,6 +273,7 @@ static ssize_t cm4040_read(struct file *filp, char __user *buf,
273 DEBUGP(6, dev, "BytesToRead=%lu\n", bytes_to_read); 273 DEBUGP(6, dev, "BytesToRead=%lu\n", bytes_to_read);
274 274
275 min_bytes_to_read = min(count, bytes_to_read + 5); 275 min_bytes_to_read = min(count, bytes_to_read + 5);
276 min_bytes_to_read = min_t(size_t, min_bytes_to_read, READ_WRITE_BUFFER_SIZE);
276 277
277 DEBUGP(6, dev, "Min=%lu\n", min_bytes_to_read); 278 DEBUGP(6, dev, "Min=%lu\n", min_bytes_to_read);
278 279
@@ -340,7 +341,7 @@ static ssize_t cm4040_write(struct file *filp, const char __user *buf,
340 return 0; 341 return 0;
341 } 342 }
342 343
343 if (count < 5) { 344 if ((count < 5) || (count > READ_WRITE_BUFFER_SIZE)) {
344 DEBUGP(2, dev, "<- cm4040_write buffersize=%Zd < 5\n", count); 345 DEBUGP(2, dev, "<- cm4040_write buffersize=%Zd < 5\n", count);
345 return -EIO; 346 return -EIO;
346 } 347 }
diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c
index 85c1618452..294e9cb0c4 100644
--- a/drivers/char/rio/rio_linux.c
+++ b/drivers/char/rio/rio_linux.c
@@ -1146,7 +1146,7 @@ static int __init rio_init(void)
1146 rio_dprintk(RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n"); 1146 rio_dprintk(RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n");
1147 hp->Mode |= RIO_PCI_INT_ENABLE; 1147 hp->Mode |= RIO_PCI_INT_ENABLE;
1148 } else 1148 } else
1149 hp->Mode &= !RIO_PCI_INT_ENABLE; 1149 hp->Mode &= ~RIO_PCI_INT_ENABLE;
1150 rio_dprintk(RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode); 1150 rio_dprintk(RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
1151 rio_start_card_running(hp); 1151 rio_start_card_running(hp);
1152 } 1152 }
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 5289254e7a..e453268566 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -1533,7 +1533,7 @@ void disassociate_ctty(int on_exit)
1533 1533
1534 spin_lock_irq(&current->sighand->siglock); 1534 spin_lock_irq(&current->sighand->siglock);
1535 tty_pgrp = current->signal->tty_old_pgrp; 1535 tty_pgrp = current->signal->tty_old_pgrp;
1536 current->signal->tty_old_pgrp = 0; 1536 current->signal->tty_old_pgrp = NULL;
1537 spin_unlock_irq(&current->sighand->siglock); 1537 spin_unlock_irq(&current->sighand->siglock);
1538 put_pid(tty_pgrp); 1538 put_pid(tty_pgrp);
1539 1539
@@ -1901,6 +1901,20 @@ static int init_dev(struct tty_driver *driver, int idx,
1901 /* check whether we're reopening an existing tty */ 1901 /* check whether we're reopening an existing tty */
1902 if (driver->flags & TTY_DRIVER_DEVPTS_MEM) { 1902 if (driver->flags & TTY_DRIVER_DEVPTS_MEM) {
1903 tty = devpts_get_tty(idx); 1903 tty = devpts_get_tty(idx);
1904 /*
1905 * If we don't have a tty here on a slave open, it's because
1906 * the master already started the close process and there's
1907 * no relation between devpts file and tty anymore.
1908 */
1909 if (!tty && driver->subtype == PTY_TYPE_SLAVE) {
1910 retval = -EIO;
1911 goto end_init;
1912 }
1913 /*
1914 * It's safe from now on because init_dev() is called with
1915 * tty_mutex held and release_dev() won't change tty->count
1916 * or tty->flags without having to grab tty_mutex
1917 */
1904 if (tty && driver->subtype == PTY_TYPE_MASTER) 1918 if (tty && driver->subtype == PTY_TYPE_MASTER)
1905 tty = tty->link; 1919 tty = tty->link;
1906 } else { 1920 } else {
@@ -3713,15 +3727,14 @@ int tty_register_driver(struct tty_driver *driver)
3713 3727
3714 if (!driver->major) { 3728 if (!driver->major) {
3715 error = alloc_chrdev_region(&dev, driver->minor_start, driver->num, 3729 error = alloc_chrdev_region(&dev, driver->minor_start, driver->num,
3716 (char*)driver->name); 3730 driver->name);
3717 if (!error) { 3731 if (!error) {
3718 driver->major = MAJOR(dev); 3732 driver->major = MAJOR(dev);
3719 driver->minor_start = MINOR(dev); 3733 driver->minor_start = MINOR(dev);
3720 } 3734 }
3721 } else { 3735 } else {
3722 dev = MKDEV(driver->major, driver->minor_start); 3736 dev = MKDEV(driver->major, driver->minor_start);
3723 error = register_chrdev_region(dev, driver->num, 3737 error = register_chrdev_region(dev, driver->num, driver->name);
3724 (char*)driver->name);
3725 } 3738 }
3726 if (error < 0) { 3739 if (error < 0) {
3727 kfree(p); 3740 kfree(p);
diff --git a/drivers/char/watchdog/machzwd.c b/drivers/char/watchdog/machzwd.c
index 81fb3dec18..4a328ba0d2 100644
--- a/drivers/char/watchdog/machzwd.c
+++ b/drivers/char/watchdog/machzwd.c
@@ -324,7 +324,7 @@ static int zf_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
324 return put_user(0, p); 324 return put_user(0, p);
325 325
326 case WDIOC_KEEPALIVE: 326 case WDIOC_KEEPALIVE:
327 zf_ping(NULL); 327 zf_ping(0);
328 break; 328 break;
329 329
330 default: 330 default:
diff --git a/drivers/clocksource/acpi_pm.c b/drivers/clocksource/acpi_pm.c
index ccaa6a39cb..d42060ede9 100644
--- a/drivers/clocksource/acpi_pm.c
+++ b/drivers/clocksource/acpi_pm.c
@@ -214,4 +214,7 @@ pm_good:
214 return clocksource_register(&clocksource_acpi_pm); 214 return clocksource_register(&clocksource_acpi_pm);
215} 215}
216 216
217module_init(init_acpi_pm_clocksource); 217/* We use fs_initcall because we want the PCI fixups to have run
218 * but we still need to load before device_initcall
219 */
220fs_initcall(init_acpi_pm_clocksource);
diff --git a/drivers/clocksource/cyclone.c b/drivers/clocksource/cyclone.c
index 4f3925ceb3..1bde303b97 100644
--- a/drivers/clocksource/cyclone.c
+++ b/drivers/clocksource/cyclone.c
@@ -116,4 +116,4 @@ static int __init init_cyclone_clocksource(void)
116 return clocksource_register(&clocksource_cyclone); 116 return clocksource_register(&clocksource_cyclone);
117} 117}
118 118
119module_init(init_cyclone_clocksource); 119arch_initcall(init_cyclone_clocksource);
diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
index a44db75bc2..a905f78203 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -128,7 +128,7 @@ EXPORT_SYMBOL_GPL(cn_netlink_send);
128 */ 128 */
129static int cn_call_callback(struct cn_msg *msg, void (*destruct_data)(void *), void *data) 129static int cn_call_callback(struct cn_msg *msg, void (*destruct_data)(void *), void *data)
130{ 130{
131 struct cn_callback_entry *__cbq; 131 struct cn_callback_entry *__cbq, *__new_cbq;
132 struct cn_dev *dev = &cdev; 132 struct cn_dev *dev = &cdev;
133 int err = -ENODEV; 133 int err = -ENODEV;
134 134
@@ -148,27 +148,27 @@ static int cn_call_callback(struct cn_msg *msg, void (*destruct_data)(void *), v
148 } else { 148 } else {
149 struct cn_callback_data *d; 149 struct cn_callback_data *d;
150 150
151 __cbq = kzalloc(sizeof(*__cbq), GFP_ATOMIC); 151 err = -ENOMEM;
152 if (__cbq) { 152 __new_cbq = kzalloc(sizeof(struct cn_callback_entry), GFP_ATOMIC);
153 d = &__cbq->data; 153 if (__new_cbq) {
154 d = &__new_cbq->data;
154 d->callback_priv = msg; 155 d->callback_priv = msg;
155 d->callback = __cbq->data.callback; 156 d->callback = __cbq->data.callback;
156 d->ddata = data; 157 d->ddata = data;
157 d->destruct_data = destruct_data; 158 d->destruct_data = destruct_data;
158 d->free = __cbq; 159 d->free = __new_cbq;
159 160
160 INIT_WORK(&__cbq->work, 161 INIT_WORK(&__new_cbq->work,
161 &cn_queue_wrapper); 162 &cn_queue_wrapper);
162 163
163 if (queue_work(dev->cbdev->cn_queue, 164 if (queue_work(dev->cbdev->cn_queue,
164 &__cbq->work)) 165 &__new_cbq->work))
165 err = 0; 166 err = 0;
166 else { 167 else {
167 kfree(__cbq); 168 kfree(__new_cbq);
168 err = -EINVAL; 169 err = -EINVAL;
169 } 170 }
170 } else 171 }
171 err = -ENOMEM;
172 } 172 }
173 break; 173 break;
174 } 174 }
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index d60bcb9d14..8d053f500f 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -432,9 +432,6 @@ static void do_dbs_timer(struct work_struct *work)
432 /* We want all CPUs to do sampling nearly on same jiffy */ 432 /* We want all CPUs to do sampling nearly on same jiffy */
433 int delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate); 433 int delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate);
434 434
435 /* Permit rescheduling of this work item */
436 work_release(work);
437
438 delay -= jiffies % delay; 435 delay -= jiffies % delay;
439 436
440 if (lock_policy_rwsem_write(cpu) < 0) 437 if (lock_policy_rwsem_write(cpu) < 0)
@@ -473,7 +470,7 @@ static inline void dbs_timer_init(struct cpu_dbs_info_s *dbs_info)
473 dbs_info->enable = 1; 470 dbs_info->enable = 1;
474 ondemand_powersave_bias_init(); 471 ondemand_powersave_bias_init();
475 dbs_info->sample_type = DBS_NORMAL_SAMPLE; 472 dbs_info->sample_type = DBS_NORMAL_SAMPLE;
476 INIT_DELAYED_WORK_NAR(&dbs_info->work, do_dbs_timer); 473 INIT_DELAYED_WORK(&dbs_info->work, do_dbs_timer);
477 queue_delayed_work_on(dbs_info->cpu, kondemand_wq, &dbs_info->work, 474 queue_delayed_work_on(dbs_info->cpu, kondemand_wq, &dbs_info->work,
478 delay); 475 delay);
479} 476}
diff --git a/drivers/crypto/geode-aes.c b/drivers/crypto/geode-aes.c
index 0eb62841e9..6d3840e629 100644
--- a/drivers/crypto/geode-aes.c
+++ b/drivers/crypto/geode-aes.c
@@ -99,9 +99,8 @@ do_crypt(void *src, void *dst, int len, u32 flags)
99static unsigned int 99static unsigned int
100geode_aes_crypt(struct geode_aes_op *op) 100geode_aes_crypt(struct geode_aes_op *op)
101{ 101{
102
103 u32 flags = 0; 102 u32 flags = 0;
104 int iflags; 103 unsigned long iflags;
105 104
106 if (op->len == 0 || op->src == op->dst) 105 if (op->len == 0 || op->src == op->dst)
107 return 0; 106 return 0;
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 7452399501..f4ee1afe48 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -667,7 +667,6 @@ struct hid_device *hid_parse_report(__u8 *start, unsigned size)
667 667
668 if (item.format != HID_ITEM_FORMAT_SHORT) { 668 if (item.format != HID_ITEM_FORMAT_SHORT) {
669 dbg("unexpected long global item"); 669 dbg("unexpected long global item");
670 kfree(device->collection);
671 hid_free_device(device); 670 hid_free_device(device);
672 kfree(parser); 671 kfree(parser);
673 return NULL; 672 return NULL;
@@ -676,7 +675,6 @@ struct hid_device *hid_parse_report(__u8 *start, unsigned size)
676 if (dispatch_type[item.type](parser, &item)) { 675 if (dispatch_type[item.type](parser, &item)) {
677 dbg("item %u %u %u %u parsing failed\n", 676 dbg("item %u %u %u %u parsing failed\n",
678 item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag); 677 item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag);
679 kfree(device->collection);
680 hid_free_device(device); 678 hid_free_device(device);
681 kfree(parser); 679 kfree(parser);
682 return NULL; 680 return NULL;
@@ -685,14 +683,12 @@ struct hid_device *hid_parse_report(__u8 *start, unsigned size)
685 if (start == end) { 683 if (start == end) {
686 if (parser->collection_stack_ptr) { 684 if (parser->collection_stack_ptr) {
687 dbg("unbalanced collection at end of report description"); 685 dbg("unbalanced collection at end of report description");
688 kfree(device->collection);
689 hid_free_device(device); 686 hid_free_device(device);
690 kfree(parser); 687 kfree(parser);
691 return NULL; 688 return NULL;
692 } 689 }
693 if (parser->local.delimiter_depth) { 690 if (parser->local.delimiter_depth) {
694 dbg("unbalanced delimiter at end of report description"); 691 dbg("unbalanced delimiter at end of report description");
695 kfree(device->collection);
696 hid_free_device(device); 692 hid_free_device(device);
697 kfree(parser); 693 kfree(parser);
698 return NULL; 694 return NULL;
@@ -703,7 +699,6 @@ struct hid_device *hid_parse_report(__u8 *start, unsigned size)
703 } 699 }
704 700
705 dbg("item fetching failed at offset %d\n", (int)(end - start)); 701 dbg("item fetching failed at offset %d\n", (int)(end - start));
706 kfree(device->collection);
707 hid_free_device(device); 702 hid_free_device(device);
708 kfree(parser); 703 kfree(parser);
709 return NULL; 704 return NULL;
@@ -880,7 +875,7 @@ static void hid_output_field(struct hid_field *field, __u8 *data)
880 875
881 /* make sure the unused bits in the last byte are zeros */ 876 /* make sure the unused bits in the last byte are zeros */
882 if (count > 0 && size > 0) 877 if (count > 0 && size > 0)
883 data[(count*size-1)/8] = 0; 878 data[(offset+count*size-1)/8] = 0;
884 879
885 for (n = 0; n < count; n++) { 880 for (n = 0; n < count; n++) {
886 if (field->logical_minimum < 0) /* signed values */ 881 if (field->logical_minimum < 0) /* signed values */
diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c
index 89241be4ec..83c4126b37 100644
--- a/drivers/hid/hid-debug.c
+++ b/drivers/hid/hid-debug.c
@@ -29,6 +29,7 @@
29 */ 29 */
30 30
31#include <linux/hid.h> 31#include <linux/hid.h>
32#include <linux/hid-debug.h>
32 33
33struct hid_usage_entry { 34struct hid_usage_entry {
34 unsigned page; 35 unsigned page;
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 25d180a24f..c8434023ba 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -2,7 +2,7 @@
2 * $Id: hid-input.c,v 1.2 2002/04/23 00:59:25 rdamazio Exp $ 2 * $Id: hid-input.c,v 1.2 2002/04/23 00:59:25 rdamazio Exp $
3 * 3 *
4 * Copyright (c) 2000-2001 Vojtech Pavlik 4 * Copyright (c) 2000-2001 Vojtech Pavlik
5 * Copyright (c) 2006 Jiri Kosina 5 * Copyright (c) 2006-2007 Jiri Kosina
6 * 6 *
7 * HID to Linux Input mapping 7 * HID to Linux Input mapping
8 */ 8 */
@@ -71,7 +71,6 @@ static const struct {
71#define map_led(c) do { usage->code = c; usage->type = EV_LED; bit = input->ledbit; max = LED_MAX; } while (0) 71#define map_led(c) do { usage->code = c; usage->type = EV_LED; bit = input->ledbit; max = LED_MAX; } while (0)
72 72
73#define map_abs_clear(c) do { map_abs(c); clear_bit(c, bit); } while (0) 73#define map_abs_clear(c) do { map_abs(c); clear_bit(c, bit); } while (0)
74#define map_rel_clear(c) do { map_rel(c); clear_bit(c, bit); } while (0)
75#define map_key_clear(c) do { map_key(c); clear_bit(c, bit); } while (0) 74#define map_key_clear(c) do { map_key(c); clear_bit(c, bit); } while (0)
76 75
77#ifdef CONFIG_USB_HIDINPUT_POWERBOOK 76#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
@@ -296,7 +295,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
296 } 295 }
297 } 296 }
298 297
299 map_key_clear(code); 298 map_key(code);
300 break; 299 break;
301 300
302 301
@@ -347,9 +346,9 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
347 case HID_GD_RX: case HID_GD_RY: case HID_GD_RZ: 346 case HID_GD_RX: case HID_GD_RY: case HID_GD_RZ:
348 case HID_GD_SLIDER: case HID_GD_DIAL: case HID_GD_WHEEL: 347 case HID_GD_SLIDER: case HID_GD_DIAL: case HID_GD_WHEEL:
349 if (field->flags & HID_MAIN_ITEM_RELATIVE) 348 if (field->flags & HID_MAIN_ITEM_RELATIVE)
350 map_rel_clear(usage->hid & 0xf); 349 map_rel(usage->hid & 0xf);
351 else 350 else
352 map_abs_clear(usage->hid & 0xf); 351 map_abs(usage->hid & 0xf);
353 break; 352 break;
354 353
355 case HID_GD_HATSWITCH: 354 case HID_GD_HATSWITCH:
@@ -519,7 +518,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
519 case 0x22f: map_key_clear(KEY_ZOOMRESET); break; 518 case 0x22f: map_key_clear(KEY_ZOOMRESET); break;
520 case 0x233: map_key_clear(KEY_SCROLLUP); break; 519 case 0x233: map_key_clear(KEY_SCROLLUP); break;
521 case 0x234: map_key_clear(KEY_SCROLLDOWN); break; 520 case 0x234: map_key_clear(KEY_SCROLLDOWN); break;
522 case 0x238: map_rel_clear(REL_HWHEEL); break; 521 case 0x238: map_rel(REL_HWHEEL); break;
523 case 0x25f: map_key_clear(KEY_CANCEL); break; 522 case 0x25f: map_key_clear(KEY_CANCEL); break;
524 case 0x279: map_key_clear(KEY_REDO); break; 523 case 0x279: map_key_clear(KEY_REDO); break;
525 524
@@ -532,6 +531,26 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
532 case 0x302: map_key_clear(KEY_PROG2); break; 531 case 0x302: map_key_clear(KEY_PROG2); break;
533 case 0x303: map_key_clear(KEY_PROG3); break; 532 case 0x303: map_key_clear(KEY_PROG3); break;
534 533
534 /* Reported on Logitech S510 wireless keyboard */
535 case 0x101f: map_key_clear(KEY_ZOOMIN); break;
536 case 0x1020: map_key_clear(KEY_ZOOMOUT); break;
537 case 0x1021: map_key_clear(KEY_ZOOMRESET); break;
538 /* this one is marked as 'Rotate' */
539 case 0x1028: map_key_clear(KEY_ANGLE); break;
540 case 0x1029: map_key_clear(KEY_SHUFFLE); break;
541 case 0x1041: map_key_clear(KEY_BATTERY); break;
542 case 0x1042: map_key_clear(KEY_WORDPROCESSOR); break;
543 case 0x1043: map_key_clear(KEY_SPREADSHEET); break;
544 case 0x1044: map_key_clear(KEY_PRESENTATION); break;
545 case 0x1045: map_key_clear(KEY_UNDO); break;
546 case 0x1046: map_key_clear(KEY_REDO); break;
547 case 0x1047: map_key_clear(KEY_PRINT); break;
548 case 0x1048: map_key_clear(KEY_SAVE); break;
549 case 0x1049: map_key_clear(KEY_PROG1); break;
550 case 0x104a: map_key_clear(KEY_PROG2); break;
551 case 0x104b: map_key_clear(KEY_PROG3); break;
552 case 0x104c: map_key_clear(KEY_PROG4); break;
553
535 default: goto ignore; 554 default: goto ignore;
536 } 555 }
537 break; 556 break;
@@ -647,6 +666,12 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
647 666
648 set_bit(usage->type, input->evbit); 667 set_bit(usage->type, input->evbit);
649 668
669 if (device->quirks & HID_QUIRK_DUPLICATE_USAGES &&
670 (usage->type == EV_KEY ||
671 usage->type == EV_REL ||
672 usage->type == EV_ABS))
673 clear_bit(usage->code, bit);
674
650 while (usage->code <= max && test_and_set_bit(usage->code, bit)) 675 while (usage->code <= max && test_and_set_bit(usage->code, bit))
651 usage->code = find_next_zero_bit(bit, max + 1, usage->code); 676 usage->code = find_next_zero_bit(bit, max + 1, usage->code);
652 677
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 891ef6d0b1..c3d4856fb6 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -73,6 +73,17 @@ config SENSORS_ADM1026
73 This driver can also be built as a module. If so, the module 73 This driver can also be built as a module. If so, the module
74 will be called adm1026. 74 will be called adm1026.
75 75
76config SENSORS_ADM1029
77 tristate "Analog Devices ADM1029"
78 depends on HWMON && I2C && EXPERIMENTAL
79 help
80 If you say yes here you get support for Analog Devices ADM1029
81 sensor chip.
82 Very rare chip, please let us know you use it.
83
84 This driver can also be built as a module. If so, the module
85 will be called adm1029.
86
76config SENSORS_ADM1031 87config SENSORS_ADM1031
77 tristate "Analog Devices ADM1031 and compatibles" 88 tristate "Analog Devices ADM1031 and compatibles"
78 depends on HWMON && I2C && EXPERIMENTAL 89 depends on HWMON && I2C && EXPERIMENTAL
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 3166112427..4165c27a2f 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_SENSORS_ABITUGURU) += abituguru.o
17obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o 17obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o
18obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o 18obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o
19obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o 19obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o
20obj-$(CONFIG_SENSORS_ADM1029) += adm1029.o
20obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o 21obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o
21obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o 22obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o
22obj-$(CONFIG_SENSORS_AMS) += ams/ 23obj-$(CONFIG_SENSORS_AMS) += ams/
diff --git a/drivers/hwmon/abituguru.c b/drivers/hwmon/abituguru.c
index b1dc63e4ac..bede4d990e 100644
--- a/drivers/hwmon/abituguru.c
+++ b/drivers/hwmon/abituguru.c
@@ -1267,30 +1267,42 @@ static int __devinit abituguru_probe(struct platform_device *pdev)
1267 printk(KERN_INFO ABIT_UGURU_NAME ": found Abit uGuru\n"); 1267 printk(KERN_INFO ABIT_UGURU_NAME ": found Abit uGuru\n");
1268 1268
1269 /* Register sysfs hooks */ 1269 /* Register sysfs hooks */
1270 data->class_dev = hwmon_device_register(&pdev->dev);
1271 if (IS_ERR(data->class_dev)) {
1272 res = PTR_ERR(data->class_dev);
1273 goto abituguru_probe_error;
1274 }
1275 for (i = 0; i < sysfs_attr_i; i++) 1270 for (i = 0; i < sysfs_attr_i; i++)
1276 device_create_file(&pdev->dev, &data->sysfs_attr[i].dev_attr); 1271 if (device_create_file(&pdev->dev,
1272 &data->sysfs_attr[i].dev_attr))
1273 goto abituguru_probe_error;
1277 for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++) 1274 for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++)
1278 device_create_file(&pdev->dev, 1275 if (device_create_file(&pdev->dev,
1279 &abituguru_sysfs_attr[i].dev_attr); 1276 &abituguru_sysfs_attr[i].dev_attr))
1277 goto abituguru_probe_error;
1280 1278
1281 return 0; 1279 data->class_dev = hwmon_device_register(&pdev->dev);
1280 if (!IS_ERR(data->class_dev))
1281 return 0; /* success */
1282 1282
1283 res = PTR_ERR(data->class_dev);
1283abituguru_probe_error: 1284abituguru_probe_error:
1285 for (i = 0; data->sysfs_attr[i].dev_attr.attr.name; i++)
1286 device_remove_file(&pdev->dev, &data->sysfs_attr[i].dev_attr);
1287 for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++)
1288 device_remove_file(&pdev->dev,
1289 &abituguru_sysfs_attr[i].dev_attr);
1284 kfree(data); 1290 kfree(data);
1285 return res; 1291 return res;
1286} 1292}
1287 1293
1288static int __devexit abituguru_remove(struct platform_device *pdev) 1294static int __devexit abituguru_remove(struct platform_device *pdev)
1289{ 1295{
1296 int i;
1290 struct abituguru_data *data = platform_get_drvdata(pdev); 1297 struct abituguru_data *data = platform_get_drvdata(pdev);
1291 1298
1292 platform_set_drvdata(pdev, NULL); 1299 platform_set_drvdata(pdev, NULL);
1293 hwmon_device_unregister(data->class_dev); 1300 hwmon_device_unregister(data->class_dev);
1301 for (i = 0; data->sysfs_attr[i].dev_attr.attr.name; i++)
1302 device_remove_file(&pdev->dev, &data->sysfs_attr[i].dev_attr);
1303 for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++)
1304 device_remove_file(&pdev->dev,
1305 &abituguru_sysfs_attr[i].dev_attr);
1294 kfree(data); 1306 kfree(data);
1295 1307
1296 return 0; 1308 return 0;
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
index b4618b2705..ba80cd3258 100644
--- a/drivers/hwmon/adm1026.c
+++ b/drivers/hwmon/adm1026.c
@@ -261,7 +261,6 @@ struct pwm_data {
261struct adm1026_data { 261struct adm1026_data {
262 struct i2c_client client; 262 struct i2c_client client;
263 struct class_device *class_dev; 263 struct class_device *class_dev;
264 struct mutex lock;
265 enum chips type; 264 enum chips type;
266 265
267 struct mutex update_lock; 266 struct mutex update_lock;
diff --git a/drivers/hwmon/adm1029.c b/drivers/hwmon/adm1029.c
new file mode 100644
index 0000000000..73ce31b315
--- /dev/null
+++ b/drivers/hwmon/adm1029.c
@@ -0,0 +1,508 @@
1/*
2 * adm1029.c - Part of lm_sensors, Linux kernel modules for hardware monitoring
3 *
4 * Copyright (C) 2006 Corentin LABBE <corentin.labbe@geomatys.fr>
5 *
6 * Based on LM83 Driver by Jean Delvare <khali@linux-fr.org>
7 *
8 * Give only processor, motherboard temperatures and fan tachs
9 * Very rare chip please let me know if you use it
10 *
11 * http://www.analog.com/UploadedFiles/Data_Sheets/ADM1029.pdf
12 *
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation version 2 of the License
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/init.h>
30#include <linux/slab.h>
31#include <linux/jiffies.h>
32#include <linux/i2c.h>
33#include <linux/hwmon-sysfs.h>
34#include <linux/hwmon.h>
35#include <linux/err.h>
36#include <linux/mutex.h>
37
38/*
39 * Addresses to scan
40 */
41
42static unsigned short normal_i2c[] = {
43 0x28, 0x29, 0x2a,
44 0x2b, 0x2c, 0x2d,
45 0x2e, 0x2f, I2C_CLIENT_END
46};
47
48/*
49 * Insmod parameters
50 */
51
52I2C_CLIENT_INSMOD_1(adm1029);
53
54/*
55 * The ADM1029 registers
56 * Manufacturer ID is 0x41 for Analog Devices
57 */
58
59#define ADM1029_REG_MAN_ID 0x0D
60#define ADM1029_REG_CHIP_ID 0x0E
61#define ADM1029_REG_CONFIG 0x01
62#define ADM1029_REG_NB_FAN_SUPPORT 0x02
63
64#define ADM1029_REG_TEMP_DEVICES_INSTALLED 0x06
65
66#define ADM1029_REG_LOCAL_TEMP 0xA0
67#define ADM1029_REG_REMOTE1_TEMP 0xA1
68#define ADM1029_REG_REMOTE2_TEMP 0xA2
69
70#define ADM1029_REG_LOCAL_TEMP_HIGH 0x90
71#define ADM1029_REG_REMOTE1_TEMP_HIGH 0x91
72#define ADM1029_REG_REMOTE2_TEMP_HIGH 0x92
73
74#define ADM1029_REG_LOCAL_TEMP_LOW 0x98
75#define ADM1029_REG_REMOTE1_TEMP_LOW 0x99
76#define ADM1029_REG_REMOTE2_TEMP_LOW 0x9A
77
78#define ADM1029_REG_FAN1 0x70
79#define ADM1029_REG_FAN2 0x71
80
81#define ADM1029_REG_FAN1_MIN 0x78
82#define ADM1029_REG_FAN2_MIN 0x79
83
84#define ADM1029_REG_FAN1_CONFIG 0x68
85#define ADM1029_REG_FAN2_CONFIG 0x69
86
87#define TEMP_FROM_REG(val) ((val) * 1000)
88
89#define DIV_FROM_REG(val) ( 1 << (((val) >> 6) - 1))
90
91/* Registers to be checked by adm1029_update_device() */
92static const u8 ADM1029_REG_TEMP[] = {
93 ADM1029_REG_LOCAL_TEMP,
94 ADM1029_REG_REMOTE1_TEMP,
95 ADM1029_REG_REMOTE2_TEMP,
96 ADM1029_REG_LOCAL_TEMP_HIGH,
97 ADM1029_REG_REMOTE1_TEMP_HIGH,
98 ADM1029_REG_REMOTE2_TEMP_HIGH,
99 ADM1029_REG_LOCAL_TEMP_LOW,
100 ADM1029_REG_REMOTE1_TEMP_LOW,
101 ADM1029_REG_REMOTE2_TEMP_LOW,
102};
103
104static const u8 ADM1029_REG_FAN[] = {
105 ADM1029_REG_FAN1,
106 ADM1029_REG_FAN2,
107 ADM1029_REG_FAN1_MIN,
108 ADM1029_REG_FAN2_MIN,
109};
110
111static const u8 ADM1029_REG_FAN_DIV[] = {
112 ADM1029_REG_FAN1_CONFIG,
113 ADM1029_REG_FAN2_CONFIG,
114};
115
116/*
117 * Functions declaration
118 */
119
120static int adm1029_attach_adapter(struct i2c_adapter *adapter);
121static int adm1029_detect(struct i2c_adapter *adapter, int address, int kind);
122static int adm1029_detach_client(struct i2c_client *client);
123static struct adm1029_data *adm1029_update_device(struct device *dev);
124static int adm1029_init_client(struct i2c_client *client);
125
126/*
127 * Driver data (common to all clients)
128 */
129
130static struct i2c_driver adm1029_driver = {
131 .driver = {
132 .name = "adm1029",
133 },
134 .attach_adapter = adm1029_attach_adapter,
135 .detach_client = adm1029_detach_client,
136};
137
138/*
139 * Client data (each client gets its own)
140 */
141
142struct adm1029_data {
143 struct i2c_client client;
144 struct class_device *class_dev;
145 struct mutex update_lock;
146 char valid; /* zero until following fields are valid */
147 unsigned long last_updated; /* in jiffies */
148
149 /* registers values, signed for temperature, unsigned for other stuff */
150 s8 temp[ARRAY_SIZE(ADM1029_REG_TEMP)];
151 u8 fan[ARRAY_SIZE(ADM1029_REG_FAN)];
152 u8 fan_div[ARRAY_SIZE(ADM1029_REG_FAN_DIV)];
153};
154
155/*
156 * Sysfs stuff
157 */
158
159static ssize_t
160show_temp(struct device *dev, struct device_attribute *devattr, char *buf)
161{
162 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
163 struct adm1029_data *data = adm1029_update_device(dev);
164 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]));
165}
166
167static ssize_t
168show_fan(struct device *dev, struct device_attribute *devattr, char *buf)
169{
170 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
171 struct adm1029_data *data = adm1029_update_device(dev);
172 u16 val;
173 if (data->fan[attr->index] == 0 || data->fan_div[attr->index] == 0
174 || data->fan[attr->index] == 255) {
175 return sprintf(buf, "0\n");
176 }
177
178 val = 1880 * 120 / DIV_FROM_REG(data->fan_div[attr->index])
179 / data->fan[attr->index];
180 return sprintf(buf, "%d\n", val);
181}
182
183static ssize_t
184show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf)
185{
186 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
187 struct adm1029_data *data = adm1029_update_device(dev);
188 if (data->fan_div[attr->index] == 0)
189 return sprintf(buf, "0\n");
190 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index]));
191}
192
193static ssize_t set_fan_div(struct device *dev,
194 struct device_attribute *devattr, const char *buf, size_t count)
195{
196 struct i2c_client *client = to_i2c_client(dev);
197 struct adm1029_data *data = i2c_get_clientdata(client);
198 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
199 long val = simple_strtol(buf, NULL, 10);
200 u8 reg;
201
202 mutex_lock(&data->update_lock);
203
204 /*Read actual config */
205 reg = i2c_smbus_read_byte_data(client,
206 ADM1029_REG_FAN_DIV[attr->index]);
207
208 switch (val) {
209 case 1:
210 val = 1;
211 break;
212 case 2:
213 val = 2;
214 break;
215 case 4:
216 val = 3;
217 break;
218 default:
219 mutex_unlock(&data->update_lock);
220 dev_err(&client->dev, "fan_div value %ld not "
221 "supported. Choose one of 1, 2 or 4!\n", val);
222 return -EINVAL;
223 }
224 /* Update the value */
225 reg = (reg & 0x3F) | (val << 6);
226
227 /* Write value */
228 i2c_smbus_write_byte_data(client,
229 ADM1029_REG_FAN_DIV[attr->index], reg);
230 mutex_unlock(&data->update_lock);
231
232 return count;
233}
234
235/*
236Access rights on sysfs, S_IRUGO stand for Is Readable by User, Group and Others
237 S_IWUSR stand for Is Writable by User
238*/
239static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
240static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
241static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
242
243static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_temp, NULL, 3);
244static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO, show_temp, NULL, 4);
245static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO, show_temp, NULL, 5);
246
247static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO, show_temp, NULL, 6);
248static SENSOR_DEVICE_ATTR(temp2_min, S_IRUGO, show_temp, NULL, 7);
249static SENSOR_DEVICE_ATTR(temp3_min, S_IRUGO, show_temp, NULL, 8);
250
251static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
252static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
253
254static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, show_fan, NULL, 2);
255static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO, show_fan, NULL, 3);
256
257static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
258 show_fan_div, set_fan_div, 0);
259static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR,
260 show_fan_div, set_fan_div, 1);
261
262static struct attribute *adm1029_attributes[] = {
263 &sensor_dev_attr_temp1_input.dev_attr.attr,
264 &sensor_dev_attr_temp1_min.dev_attr.attr,
265 &sensor_dev_attr_temp1_max.dev_attr.attr,
266 &sensor_dev_attr_temp2_input.dev_attr.attr,
267 &sensor_dev_attr_temp2_min.dev_attr.attr,
268 &sensor_dev_attr_temp2_max.dev_attr.attr,
269 &sensor_dev_attr_temp3_input.dev_attr.attr,
270 &sensor_dev_attr_temp3_min.dev_attr.attr,
271 &sensor_dev_attr_temp3_max.dev_attr.attr,
272 &sensor_dev_attr_fan1_input.dev_attr.attr,
273 &sensor_dev_attr_fan2_input.dev_attr.attr,
274 &sensor_dev_attr_fan1_min.dev_attr.attr,
275 &sensor_dev_attr_fan2_min.dev_attr.attr,
276 &sensor_dev_attr_fan1_div.dev_attr.attr,
277 &sensor_dev_attr_fan2_div.dev_attr.attr,
278 NULL
279};
280
281static const struct attribute_group adm1029_group = {
282 .attrs = adm1029_attributes,
283};
284
285/*
286 * Real code
287 */
288
289static int adm1029_attach_adapter(struct i2c_adapter *adapter)
290{
291 if (!(adapter->class & I2C_CLASS_HWMON))
292 return 0;
293 return i2c_probe(adapter, &addr_data, adm1029_detect);
294}
295
296/*
297 * The following function does more than just detection. If detection
298 * succeeds, it also registers the new chip.
299 */
300
301static int adm1029_detect(struct i2c_adapter *adapter, int address, int kind)
302{
303 struct i2c_client *client;
304 struct adm1029_data *data;
305 int err = 0;
306 const char *name = "";
307 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
308 goto exit;
309
310 if (!(data = kzalloc(sizeof(struct adm1029_data), GFP_KERNEL))) {
311 err = -ENOMEM;
312 goto exit;
313 }
314
315 client = &data->client;
316 i2c_set_clientdata(client, data);
317 client->addr = address;
318 client->adapter = adapter;
319 client->driver = &adm1029_driver;
320
321 /* Now we do the detection and identification. A negative kind
322 * means that the driver was loaded with no force parameter
323 * (default), so we must both detect and identify the chip
324 * (actually there is only one possible kind of chip for now, adm1029).
325 * A zero kind means that the driver was loaded with the force
326 * parameter, the detection step shall be skipped. A positive kind
327 * means that the driver was loaded with the force parameter and a
328 * given kind of chip is requested, so both the detection and the
329 * identification steps are skipped. */
330
331 /* Default to an adm1029 if forced */
332 if (kind == 0)
333 kind = adm1029;
334
335 /* ADM1029 doesn't have CHIP ID, check just MAN ID
336 * For better detection we check also ADM1029_TEMP_DEVICES_INSTALLED,
337 * ADM1029_REG_NB_FAN_SUPPORT and compare it with possible values
338 * documented
339 */
340
341 if (kind <= 0) { /* identification */
342 u8 man_id, chip_id, temp_devices_installed, nb_fan_support;
343
344 man_id = i2c_smbus_read_byte_data(client, ADM1029_REG_MAN_ID);
345 chip_id = i2c_smbus_read_byte_data(client, ADM1029_REG_CHIP_ID);
346 temp_devices_installed = i2c_smbus_read_byte_data(client,
347 ADM1029_REG_TEMP_DEVICES_INSTALLED);
348 nb_fan_support = i2c_smbus_read_byte_data(client,
349 ADM1029_REG_NB_FAN_SUPPORT);
350 /* 0x41 is Analog Devices */
351 if (man_id == 0x41 && (temp_devices_installed & 0xf9) == 0x01
352 && nb_fan_support == 0x03) {
353 if ((chip_id & 0xF0) == 0x00) {
354 kind = adm1029;
355 } else {
356 /* There are no "official" CHIP ID, so actually
357 * we use Major/Minor revision for that */
358 printk(KERN_INFO
359 "adm1029: Unknown major revision %x, "
360 "please let us know\n", chip_id);
361 }
362 }
363
364 if (kind <= 0) { /* identification failed */
365 pr_debug("adm1029: Unsupported chip (man_id=0x%02X, "
366 "chip_id=0x%02X)\n", man_id, chip_id);
367 goto exit_free;
368 }
369 }
370
371 if (kind == adm1029) {
372 name = "adm1029";
373 }
374
375 /* We can fill in the remaining client fields */
376 strlcpy(client->name, name, I2C_NAME_SIZE);
377 mutex_init(&data->update_lock);
378
379 /* Tell the I2C layer a new client has arrived */
380 if ((err = i2c_attach_client(client)))
381 goto exit_free;
382
383 /*
384 * Initialize the ADM1029 chip
385 * Check config register
386 */
387 if (adm1029_init_client(client) == 0)
388 goto exit_detach;
389
390 /* Register sysfs hooks */
391 if ((err = sysfs_create_group(&client->dev.kobj, &adm1029_group)))
392 goto exit_detach;
393
394 data->class_dev = hwmon_device_register(&client->dev);
395 if (IS_ERR(data->class_dev)) {
396 err = PTR_ERR(data->class_dev);
397 goto exit_remove_files;
398 }
399
400 return 0;
401
402 exit_remove_files:
403 sysfs_remove_group(&client->dev.kobj, &adm1029_group);
404 exit_detach:
405 i2c_detach_client(client);
406 exit_free:
407 kfree(data);
408 exit:
409 return err;
410}
411
412static int adm1029_init_client(struct i2c_client *client)
413{
414 u8 config;
415 config = i2c_smbus_read_byte_data(client, ADM1029_REG_CONFIG);
416 if ((config & 0x10) == 0) {
417 i2c_smbus_write_byte_data(client, ADM1029_REG_CONFIG,
418 config | 0x10);
419 }
420 /* recheck config */
421 config = i2c_smbus_read_byte_data(client, ADM1029_REG_CONFIG);
422 if ((config & 0x10) == 0) {
423 dev_err(&client->dev, "Initialization failed!\n");
424 return 0;
425 }
426 return 1;
427}
428
429static int adm1029_detach_client(struct i2c_client *client)
430{
431 struct adm1029_data *data = i2c_get_clientdata(client);
432 int err;
433
434 hwmon_device_unregister(data->class_dev);
435 sysfs_remove_group(&client->dev.kobj, &adm1029_group);
436
437 if ((err = i2c_detach_client(client)))
438 return err;
439
440 kfree(data);
441 return 0;
442}
443
444/*
445function that update the status of the chips (temperature for exemple)
446*/
447static struct adm1029_data *adm1029_update_device(struct device *dev)
448{
449 struct i2c_client *client = to_i2c_client(dev);
450 struct adm1029_data *data = i2c_get_clientdata(client);
451
452 mutex_lock(&data->update_lock);
453 /*
454 * Use the "cache" Luke, don't recheck values
455 * if there are already checked not a long time later
456 */
457 if (time_after(jiffies, data->last_updated + HZ * 2)
458 || !data->valid) {
459 int nr;
460
461 dev_dbg(&client->dev, "Updating adm1029 data\n");
462
463 for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_TEMP); nr++) {
464 data->temp[nr] =
465 i2c_smbus_read_byte_data(client,
466 ADM1029_REG_TEMP[nr]);
467 }
468 for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_FAN); nr++) {
469 data->fan[nr] =
470 i2c_smbus_read_byte_data(client,
471 ADM1029_REG_FAN[nr]);
472 }
473 for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_FAN_DIV); nr++) {
474 data->fan_div[nr] =
475 i2c_smbus_read_byte_data(client,
476 ADM1029_REG_FAN_DIV[nr]);
477 }
478
479 data->last_updated = jiffies;
480 data->valid = 1;
481 }
482
483 mutex_unlock(&data->update_lock);
484
485 return data;
486}
487
488/*
489 Common module stuff
490*/
491static int __init sensors_adm1029_init(void)
492{
493
494 return i2c_add_driver(&adm1029_driver);
495}
496
497static void __exit sensors_adm1029_exit(void)
498{
499
500 i2c_del_driver(&adm1029_driver);
501}
502
503MODULE_AUTHOR("Corentin LABBE <corentin.labbe@geomatys.fr>");
504MODULE_DESCRIPTION("adm1029 driver");
505MODULE_LICENSE("GPL v2");
506
507module_init(sensors_adm1029_init);
508module_exit(sensors_adm1029_exit);
diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c
index a272cae8f6..7c29734871 100644
--- a/drivers/hwmon/f71805f.c
+++ b/drivers/hwmon/f71805f.c
@@ -146,7 +146,6 @@ superio_exit(int base)
146struct f71805f_data { 146struct f71805f_data {
147 unsigned short addr; 147 unsigned short addr;
148 const char *name; 148 const char *name;
149 struct mutex lock;
150 struct class_device *class_dev; 149 struct class_device *class_dev;
151 150
152 struct mutex update_lock; 151 struct mutex update_lock;
@@ -271,50 +270,42 @@ static inline u8 temp_to_reg(long val)
271 * Device I/O access 270 * Device I/O access
272 */ 271 */
273 272
273/* Must be called with data->update_lock held, except during initialization */
274static u8 f71805f_read8(struct f71805f_data *data, u8 reg) 274static u8 f71805f_read8(struct f71805f_data *data, u8 reg)
275{ 275{
276 u8 val;
277
278 mutex_lock(&data->lock);
279 outb(reg, data->addr + ADDR_REG_OFFSET); 276 outb(reg, data->addr + ADDR_REG_OFFSET);
280 val = inb(data->addr + DATA_REG_OFFSET); 277 return inb(data->addr + DATA_REG_OFFSET);
281 mutex_unlock(&data->lock);
282
283 return val;
284} 278}
285 279
280/* Must be called with data->update_lock held, except during initialization */
286static void f71805f_write8(struct f71805f_data *data, u8 reg, u8 val) 281static void f71805f_write8(struct f71805f_data *data, u8 reg, u8 val)
287{ 282{
288 mutex_lock(&data->lock);
289 outb(reg, data->addr + ADDR_REG_OFFSET); 283 outb(reg, data->addr + ADDR_REG_OFFSET);
290 outb(val, data->addr + DATA_REG_OFFSET); 284 outb(val, data->addr + DATA_REG_OFFSET);
291 mutex_unlock(&data->lock);
292} 285}
293 286
294/* It is important to read the MSB first, because doing so latches the 287/* It is important to read the MSB first, because doing so latches the
295 value of the LSB, so we are sure both bytes belong to the same value. */ 288 value of the LSB, so we are sure both bytes belong to the same value.
289 Must be called with data->update_lock held, except during initialization */
296static u16 f71805f_read16(struct f71805f_data *data, u8 reg) 290static u16 f71805f_read16(struct f71805f_data *data, u8 reg)
297{ 291{
298 u16 val; 292 u16 val;
299 293
300 mutex_lock(&data->lock);
301 outb(reg, data->addr + ADDR_REG_OFFSET); 294 outb(reg, data->addr + ADDR_REG_OFFSET);
302 val = inb(data->addr + DATA_REG_OFFSET) << 8; 295 val = inb(data->addr + DATA_REG_OFFSET) << 8;
303 outb(++reg, data->addr + ADDR_REG_OFFSET); 296 outb(++reg, data->addr + ADDR_REG_OFFSET);
304 val |= inb(data->addr + DATA_REG_OFFSET); 297 val |= inb(data->addr + DATA_REG_OFFSET);
305 mutex_unlock(&data->lock);
306 298
307 return val; 299 return val;
308} 300}
309 301
302/* Must be called with data->update_lock held, except during initialization */
310static void f71805f_write16(struct f71805f_data *data, u8 reg, u16 val) 303static void f71805f_write16(struct f71805f_data *data, u8 reg, u16 val)
311{ 304{
312 mutex_lock(&data->lock);
313 outb(reg, data->addr + ADDR_REG_OFFSET); 305 outb(reg, data->addr + ADDR_REG_OFFSET);
314 outb(val >> 8, data->addr + DATA_REG_OFFSET); 306 outb(val >> 8, data->addr + DATA_REG_OFFSET);
315 outb(++reg, data->addr + ADDR_REG_OFFSET); 307 outb(++reg, data->addr + ADDR_REG_OFFSET);
316 outb(val & 0xff, data->addr + DATA_REG_OFFSET); 308 outb(val & 0xff, data->addr + DATA_REG_OFFSET);
317 mutex_unlock(&data->lock);
318} 309}
319 310
320static struct f71805f_data *f71805f_update_device(struct device *dev) 311static struct f71805f_data *f71805f_update_device(struct device *dev)
@@ -1150,7 +1141,6 @@ static int __devinit f71805f_probe(struct platform_device *pdev)
1150 1141
1151 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 1142 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1152 data->addr = res->start; 1143 data->addr = res->start;
1153 mutex_init(&data->lock);
1154 data->name = names[sio_data->kind]; 1144 data->name = names[sio_data->kind];
1155 mutex_init(&data->update_lock); 1145 mutex_init(&data->update_lock);
1156 1146
@@ -1300,14 +1290,11 @@ static int __init f71805f_device_add(unsigned short address,
1300 if (err) { 1290 if (err) {
1301 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 1291 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
1302 err); 1292 err);
1303 goto exit_kfree_data; 1293 goto exit_device_put;
1304 } 1294 }
1305 1295
1306 return 0; 1296 return 0;
1307 1297
1308exit_kfree_data:
1309 kfree(pdev->dev.platform_data);
1310 pdev->dev.platform_data = NULL;
1311exit_device_put: 1298exit_device_put:
1312 platform_device_put(pdev); 1299 platform_device_put(pdev);
1313exit: 1300exit:
@@ -1400,10 +1387,7 @@ exit:
1400 1387
1401static void __exit f71805f_exit(void) 1388static void __exit f71805f_exit(void)
1402{ 1389{
1403 kfree(pdev->dev.platform_data);
1404 pdev->dev.platform_data = NULL;
1405 platform_device_unregister(pdev); 1390 platform_device_unregister(pdev);
1406
1407 platform_driver_unregister(&f71805f_driver); 1391 platform_driver_unregister(&f71805f_driver);
1408} 1392}
1409 1393
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 106fa01cdb..affcc00764 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -101,7 +101,7 @@ static void __exit hwmon_exit(void)
101 class_destroy(hwmon_class); 101 class_destroy(hwmon_class);
102} 102}
103 103
104module_init(hwmon_init); 104subsys_initcall(hwmon_init);
105module_exit(hwmon_exit); 105module_exit(hwmon_exit);
106 106
107EXPORT_SYMBOL_GPL(hwmon_device_register); 107EXPORT_SYMBOL_GPL(hwmon_device_register);
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 1ed8b7e2c3..62afc63708 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -202,15 +202,23 @@ static int DIV_TO_REG(int val)
202} 202}
203#define DIV_FROM_REG(val) (1 << (val)) 203#define DIV_FROM_REG(val) (1 << (val))
204 204
205static const unsigned int pwm_freq[8] = {
206 48000000 / 128,
207 24000000 / 128,
208 12000000 / 128,
209 8000000 / 128,
210 6000000 / 128,
211 3000000 / 128,
212 1500000 / 128,
213 750000 / 128,
214};
215
205 216
206/* For each registered IT87, we need to keep some data in memory. That 217/* For each registered chip, we need to keep some data in memory.
207 data is pointed to by it87_list[NR]->data. The structure itself is 218 The structure is dynamically allocated. */
208 dynamically allocated, at the same time when a new it87 client is
209 allocated. */
210struct it87_data { 219struct it87_data {
211 struct i2c_client client; 220 struct i2c_client client;
212 struct class_device *class_dev; 221 struct class_device *class_dev;
213 struct mutex lock;
214 enum chips type; 222 enum chips type;
215 223
216 struct mutex update_lock; 224 struct mutex update_lock;
@@ -232,6 +240,7 @@ struct it87_data {
232 u8 vrm; 240 u8 vrm;
233 u32 alarms; /* Register encoding, combined */ 241 u32 alarms; /* Register encoding, combined */
234 u8 fan_main_ctrl; /* Register value */ 242 u8 fan_main_ctrl; /* Register value */
243 u8 fan_ctl; /* Register value */
235 u8 manual_pwm_ctl[3]; /* manual PWM value set by user */ 244 u8 manual_pwm_ctl[3]; /* manual PWM value set by user */
236}; 245};
237 246
@@ -519,6 +528,14 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
519 struct it87_data *data = it87_update_device(dev); 528 struct it87_data *data = it87_update_device(dev);
520 return sprintf(buf,"%d\n", data->manual_pwm_ctl[nr]); 529 return sprintf(buf,"%d\n", data->manual_pwm_ctl[nr]);
521} 530}
531static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
532 char *buf)
533{
534 struct it87_data *data = it87_update_device(dev);
535 int index = (data->fan_ctl >> 4) & 0x07;
536
537 return sprintf(buf, "%u\n", pwm_freq[index]);
538}
522static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, 539static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
523 const char *buf, size_t count) 540 const char *buf, size_t count)
524{ 541{
@@ -528,9 +545,10 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
528 struct i2c_client *client = to_i2c_client(dev); 545 struct i2c_client *client = to_i2c_client(dev);
529 struct it87_data *data = i2c_get_clientdata(client); 546 struct it87_data *data = i2c_get_clientdata(client);
530 int val = simple_strtol(buf, NULL, 10); 547 int val = simple_strtol(buf, NULL, 10);
531 u8 reg = it87_read_value(client, IT87_REG_FAN_DIV); 548 u8 reg;
532 549
533 mutex_lock(&data->update_lock); 550 mutex_lock(&data->update_lock);
551 reg = it87_read_value(client, IT87_REG_FAN_DIV);
534 switch (nr) { 552 switch (nr) {
535 case 0: data->fan_div[nr] = reg & 0x07; break; 553 case 0: data->fan_div[nr] = reg & 0x07; break;
536 case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break; 554 case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break;
@@ -639,6 +657,28 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
639 mutex_unlock(&data->update_lock); 657 mutex_unlock(&data->update_lock);
640 return count; 658 return count;
641} 659}
660static ssize_t set_pwm_freq(struct device *dev,
661 struct device_attribute *attr, const char *buf, size_t count)
662{
663 struct i2c_client *client = to_i2c_client(dev);
664 struct it87_data *data = i2c_get_clientdata(client);
665 unsigned long val = simple_strtoul(buf, NULL, 10);
666 int i;
667
668 /* Search for the nearest available frequency */
669 for (i = 0; i < 7; i++) {
670 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
671 break;
672 }
673
674 mutex_lock(&data->update_lock);
675 data->fan_ctl = it87_read_value(client, IT87_REG_FAN_CTL) & 0x8f;
676 data->fan_ctl |= i << 4;
677 it87_write_value(client, IT87_REG_FAN_CTL, data->fan_ctl);
678 mutex_unlock(&data->update_lock);
679
680 return count;
681}
642 682
643#define show_fan_offset(offset) \ 683#define show_fan_offset(offset) \
644static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ 684static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
@@ -656,7 +696,10 @@ show_fan_offset(3);
656static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ 696static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
657 show_pwm_enable, set_pwm_enable, offset - 1); \ 697 show_pwm_enable, set_pwm_enable, offset - 1); \
658static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ 698static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
659 show_pwm, set_pwm, offset - 1); 699 show_pwm, set_pwm, offset - 1); \
700static DEVICE_ATTR(pwm##offset##_freq, \
701 (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \
702 show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL));
660 703
661show_pwm_offset(1); 704show_pwm_offset(1);
662show_pwm_offset(2); 705show_pwm_offset(2);
@@ -904,7 +947,6 @@ static int it87_detect(struct i2c_adapter *adapter)
904 } 947 }
905 948
906 new_client = &data->client; 949 new_client = &data->client;
907 mutex_init(&data->lock);
908 i2c_set_clientdata(new_client, data); 950 i2c_set_clientdata(new_client, data);
909 new_client->addr = isa_address; 951 new_client->addr = isa_address;
910 new_client->adapter = adapter; 952 new_client->adapter = adapter;
@@ -1021,7 +1063,13 @@ static int it87_detect(struct i2c_adapter *adapter)
1021 || (err = device_create_file(&new_client->dev, 1063 || (err = device_create_file(&new_client->dev,
1022 &sensor_dev_attr_pwm2.dev_attr)) 1064 &sensor_dev_attr_pwm2.dev_attr))
1023 || (err = device_create_file(&new_client->dev, 1065 || (err = device_create_file(&new_client->dev,
1024 &sensor_dev_attr_pwm3.dev_attr))) 1066 &sensor_dev_attr_pwm3.dev_attr))
1067 || (err = device_create_file(&new_client->dev,
1068 &dev_attr_pwm1_freq))
1069 || (err = device_create_file(&new_client->dev,
1070 &dev_attr_pwm2_freq))
1071 || (err = device_create_file(&new_client->dev,
1072 &dev_attr_pwm3_freq)))
1025 goto ERROR4; 1073 goto ERROR4;
1026 } 1074 }
1027 1075
@@ -1076,33 +1124,22 @@ static int it87_detach_client(struct i2c_client *client)
1076 return 0; 1124 return 0;
1077} 1125}
1078 1126
1079/* ISA access must be locked explicitly! 1127/* Must be called with data->update_lock held, except during initialization.
1080 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, 1128 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1081 would slow down the IT87 access and should not be necessary. */ 1129 would slow down the IT87 access and should not be necessary. */
1082static int it87_read_value(struct i2c_client *client, u8 reg) 1130static int it87_read_value(struct i2c_client *client, u8 reg)
1083{ 1131{
1084 struct it87_data *data = i2c_get_clientdata(client);
1085 int res;
1086
1087 mutex_lock(&data->lock);
1088 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); 1132 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
1089 res = inb_p(client->addr + IT87_DATA_REG_OFFSET); 1133 return inb_p(client->addr + IT87_DATA_REG_OFFSET);
1090 mutex_unlock(&data->lock);
1091
1092 return res;
1093} 1134}
1094 1135
1095/* ISA access must be locked explicitly! 1136/* Must be called with data->update_lock held, except during initialization.
1096 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, 1137 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1097 would slow down the IT87 access and should not be necessary. */ 1138 would slow down the IT87 access and should not be necessary. */
1098static void it87_write_value(struct i2c_client *client, u8 reg, u8 value) 1139static void it87_write_value(struct i2c_client *client, u8 reg, u8 value)
1099{ 1140{
1100 struct it87_data *data = i2c_get_clientdata(client);
1101
1102 mutex_lock(&data->lock);
1103 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); 1141 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
1104 outb_p(value, client->addr + IT87_DATA_REG_OFFSET); 1142 outb_p(value, client->addr + IT87_DATA_REG_OFFSET);
1105 mutex_unlock(&data->lock);
1106} 1143}
1107 1144
1108/* Return 1 if and only if the PWM interface is safe to use */ 1145/* Return 1 if and only if the PWM interface is safe to use */
@@ -1316,6 +1353,7 @@ static struct it87_data *it87_update_device(struct device *dev)
1316 (it87_read_value(client, IT87_REG_ALARM2) << 8) | 1353 (it87_read_value(client, IT87_REG_ALARM2) << 8) |
1317 (it87_read_value(client, IT87_REG_ALARM3) << 16); 1354 (it87_read_value(client, IT87_REG_ALARM3) << 16);
1318 data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL); 1355 data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL);
1356 data->fan_ctl = it87_read_value(client, IT87_REG_FAN_CTL);
1319 1357
1320 data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE); 1358 data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE);
1321 /* The 8705 does not have VID capability */ 1359 /* The 8705 does not have VID capability */
diff --git a/drivers/hwmon/lm70.c b/drivers/hwmon/lm70.c
index 6ba84731b9..7eaae3834e 100644
--- a/drivers/hwmon/lm70.c
+++ b/drivers/hwmon/lm70.c
@@ -126,7 +126,7 @@ out_dev_reg_failed:
126 return status; 126 return status;
127} 127}
128 128
129static int __exit lm70_remove(struct spi_device *spi) 129static int __devexit lm70_remove(struct spi_device *spi)
130{ 130{
131 struct lm70 *p_lm70 = dev_get_drvdata(&spi->dev); 131 struct lm70 *p_lm70 = dev_get_drvdata(&spi->dev);
132 132
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index 73bc2ffc59..886786c339 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -125,10 +125,8 @@ static inline int TEMP_FROM_REG(s8 val)
125 bad. Quite a lot of bookkeeping is done. A real driver can often cut 125 bad. Quite a lot of bookkeeping is done. A real driver can often cut
126 some corners. */ 126 some corners. */
127 127
128/* For each registered LM78, we need to keep some data in memory. That 128/* For each registered chip, we need to keep some data in memory.
129 data is pointed to by lm78_list[NR]->data. The structure itself is 129 The structure is dynamically allocated. */
130 dynamically allocated, at the same time when a new lm78 client is
131 allocated. */
132struct lm78_data { 130struct lm78_data {
133 struct i2c_client client; 131 struct i2c_client client;
134 struct class_device *class_dev; 132 struct class_device *class_dev;
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index 2c3293cf69..20a8c64828 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -298,11 +298,6 @@ static int ZONE_TO_REG( int zone )
298#define LM85_DATA_INTERVAL (HZ + HZ / 2) 298#define LM85_DATA_INTERVAL (HZ + HZ / 2)
299#define LM85_CONFIG_INTERVAL (1 * 60 * HZ) 299#define LM85_CONFIG_INTERVAL (1 * 60 * HZ)
300 300
301/* For each registered LM85, we need to keep some data in memory. That
302 data is pointed to by lm85_list[NR]->data. The structure itself is
303 dynamically allocated, at the same time when a new lm85 client is
304 allocated. */
305
306/* LM85 can automatically adjust fan speeds based on temperature 301/* LM85 can automatically adjust fan speeds based on temperature
307 * This structure encapsulates an entire Zone config. There are 302 * This structure encapsulates an entire Zone config. There are
308 * three zones (one for each temperature input) on the lm85 303 * three zones (one for each temperature input) on the lm85
@@ -329,10 +324,11 @@ struct lm85_autofan {
329 u8 min_off; /* Min PWM or OFF below "limit", flag */ 324 u8 min_off; /* Min PWM or OFF below "limit", flag */
330}; 325};
331 326
327/* For each registered chip, we need to keep some data in memory.
328 The structure is dynamically allocated. */
332struct lm85_data { 329struct lm85_data {
333 struct i2c_client client; 330 struct i2c_client client;
334 struct class_device *class_dev; 331 struct class_device *class_dev;
335 struct mutex lock;
336 enum chips type; 332 enum chips type;
337 333
338 struct mutex update_lock; 334 struct mutex update_lock;
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c
index 95a4b5d9ea..3f400263fc 100644
--- a/drivers/hwmon/sis5595.c
+++ b/drivers/hwmon/sis5595.c
@@ -162,10 +162,8 @@ static inline u8 DIV_TO_REG(int val)
162} 162}
163#define DIV_FROM_REG(val) (1 << (val)) 163#define DIV_FROM_REG(val) (1 << (val))
164 164
165/* For the SIS5595, we need to keep some data in memory. That 165/* For each registered chip, we need to keep some data in memory.
166 data is pointed to by sis5595_list[NR]->data. The structure itself is 166 The structure is dynamically allocated. */
167 dynamically allocated, at the time when the new sis5595 client is
168 allocated. */
169struct sis5595_data { 167struct sis5595_data {
170 struct i2c_client client; 168 struct i2c_client client;
171 struct class_device *class_dev; 169 struct class_device *class_dev;
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c
index f8acada053..9a440c8cc5 100644
--- a/drivers/hwmon/via686a.c
+++ b/drivers/hwmon/via686a.c
@@ -292,9 +292,8 @@ static inline long TEMP_FROM_REG10(u16 val)
292#define DIV_FROM_REG(val) (1 << (val)) 292#define DIV_FROM_REG(val) (1 << (val))
293#define DIV_TO_REG(val) ((val)==8?3:(val)==4?2:(val)==1?0:1) 293#define DIV_TO_REG(val) ((val)==8?3:(val)==4?2:(val)==1?0:1)
294 294
295/* For the VIA686A, we need to keep some data in memory. 295/* For each registered chip, we need to keep some data in memory.
296 The structure is dynamically allocated, at the same time when a new 296 The structure is dynamically allocated. */
297 via686a client is allocated. */
298struct via686a_data { 297struct via686a_data {
299 struct i2c_client client; 298 struct i2c_client client;
300 struct class_device *class_dev; 299 struct class_device *class_dev;
diff --git a/drivers/hwmon/vt1211.c b/drivers/hwmon/vt1211.c
index 25cc56003d..89c23d6add 100644
--- a/drivers/hwmon/vt1211.c
+++ b/drivers/hwmon/vt1211.c
@@ -178,9 +178,10 @@ struct vt1211_data {
178 * Super-I/O constants and functions 178 * Super-I/O constants and functions
179 * --------------------------------------------------------------------- */ 179 * --------------------------------------------------------------------- */
180 180
181/* Configuration & data index port registers */ 181/* Configuration index port registers
182#define SIO_REG_CIP 0x2e 182 * The vt1211 can live at 2 different addresses so we need to probe both */
183#define SIO_REG_DIP 0x2f 183#define SIO_REG_CIP1 0x2e
184#define SIO_REG_CIP2 0x4e
184 185
185/* Configuration registers */ 186/* Configuration registers */
186#define SIO_VT1211_LDN 0x07 /* logical device number */ 187#define SIO_VT1211_LDN 0x07 /* logical device number */
@@ -193,33 +194,33 @@ struct vt1211_data {
193/* VT1211 logical device numbers */ 194/* VT1211 logical device numbers */
194#define SIO_VT1211_LDN_HWMON 0x0b /* HW monitor */ 195#define SIO_VT1211_LDN_HWMON 0x0b /* HW monitor */
195 196
196static inline void superio_outb(int reg, int val) 197static inline void superio_outb(int sio_cip, int reg, int val)
197{ 198{
198 outb(reg, SIO_REG_CIP); 199 outb(reg, sio_cip);
199 outb(val, SIO_REG_DIP); 200 outb(val, sio_cip + 1);
200} 201}
201 202
202static inline int superio_inb(int reg) 203static inline int superio_inb(int sio_cip, int reg)
203{ 204{
204 outb(reg, SIO_REG_CIP); 205 outb(reg, sio_cip);
205 return inb(SIO_REG_DIP); 206 return inb(sio_cip + 1);
206} 207}
207 208
208static inline void superio_select(int ldn) 209static inline void superio_select(int sio_cip, int ldn)
209{ 210{
210 outb(SIO_VT1211_LDN, SIO_REG_CIP); 211 outb(SIO_VT1211_LDN, sio_cip);
211 outb(ldn, SIO_REG_DIP); 212 outb(ldn, sio_cip + 1);
212} 213}
213 214
214static inline void superio_enter(void) 215static inline void superio_enter(int sio_cip)
215{ 216{
216 outb(0x87, SIO_REG_CIP); 217 outb(0x87, sio_cip);
217 outb(0x87, SIO_REG_CIP); 218 outb(0x87, sio_cip);
218} 219}
219 220
220static inline void superio_exit(void) 221static inline void superio_exit(int sio_cip)
221{ 222{
222 outb(0xaa, SIO_REG_CIP); 223 outb(0xaa, sio_cip);
223} 224}
224 225
225/* --------------------------------------------------------------------- 226/* ---------------------------------------------------------------------
@@ -1263,26 +1264,26 @@ EXIT:
1263 return err; 1264 return err;
1264} 1265}
1265 1266
1266static int __init vt1211_find(unsigned short *address) 1267static int __init vt1211_find(int sio_cip, unsigned short *address)
1267{ 1268{
1268 int err = -ENODEV; 1269 int err = -ENODEV;
1269 1270
1270 superio_enter(); 1271 superio_enter(sio_cip);
1271 1272
1272 if (superio_inb(SIO_VT1211_DEVID) != SIO_VT1211_ID) { 1273 if (superio_inb(sio_cip, SIO_VT1211_DEVID) != SIO_VT1211_ID) {
1273 goto EXIT; 1274 goto EXIT;
1274 } 1275 }
1275 1276
1276 superio_select(SIO_VT1211_LDN_HWMON); 1277 superio_select(sio_cip, SIO_VT1211_LDN_HWMON);
1277 1278
1278 if ((superio_inb(SIO_VT1211_ACTIVE) & 1) == 0) { 1279 if ((superio_inb(sio_cip, SIO_VT1211_ACTIVE) & 1) == 0) {
1279 printk(KERN_WARNING DRVNAME ": HW monitor is disabled, " 1280 printk(KERN_WARNING DRVNAME ": HW monitor is disabled, "
1280 "skipping\n"); 1281 "skipping\n");
1281 goto EXIT; 1282 goto EXIT;
1282 } 1283 }
1283 1284
1284 *address = ((superio_inb(SIO_VT1211_BADDR) << 8) | 1285 *address = ((superio_inb(sio_cip, SIO_VT1211_BADDR) << 8) |
1285 (superio_inb(SIO_VT1211_BADDR + 1))) & 0xff00; 1286 (superio_inb(sio_cip, SIO_VT1211_BADDR + 1))) & 0xff00;
1286 if (*address == 0) { 1287 if (*address == 0) {
1287 printk(KERN_WARNING DRVNAME ": Base address is not set, " 1288 printk(KERN_WARNING DRVNAME ": Base address is not set, "
1288 "skipping\n"); 1289 "skipping\n");
@@ -1291,10 +1292,11 @@ static int __init vt1211_find(unsigned short *address)
1291 1292
1292 err = 0; 1293 err = 0;
1293 printk(KERN_INFO DRVNAME ": Found VT1211 chip at 0x%04x, " 1294 printk(KERN_INFO DRVNAME ": Found VT1211 chip at 0x%04x, "
1294 "revision %u\n", *address, superio_inb(SIO_VT1211_DEVREV)); 1295 "revision %u\n", *address,
1296 superio_inb(sio_cip, SIO_VT1211_DEVREV));
1295 1297
1296EXIT: 1298EXIT:
1297 superio_exit(); 1299 superio_exit(sio_cip);
1298 return err; 1300 return err;
1299} 1301}
1300 1302
@@ -1303,8 +1305,8 @@ static int __init vt1211_init(void)
1303 int err; 1305 int err;
1304 unsigned short address = 0; 1306 unsigned short address = 0;
1305 1307
1306 err = vt1211_find(&address); 1308 if ((err = vt1211_find(SIO_REG_CIP1, &address)) &&
1307 if (err) { 1309 (err = vt1211_find(SIO_REG_CIP2, &address))) {
1308 goto EXIT; 1310 goto EXIT;
1309 } 1311 }
1310 1312
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 212a1558c6..da5828f2df 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -32,8 +32,10 @@
32 32
33 Supports the following chips: 33 Supports the following chips:
34 34
35 Chip #vin #fan #pwm #temp chip_id man_id 35 Chip #vin #fan #pwm #temp chip IDs man ID
36 w83627ehf 10 5 4 3 0x88,0xa1 0x5ca3 36 w83627ehf 10 5 4 3 0x8850 0x88 0x5ca3
37 0x8860 0xa1
38 w83627dhg 9 5 4 3 0xa020 0xc1 0x5ca3
37*/ 39*/
38 40
39#include <linux/module.h> 41#include <linux/module.h>
@@ -55,8 +57,18 @@ static unsigned short address;
55 * Super-I/O constants and functions 57 * Super-I/O constants and functions
56 */ 58 */
57 59
60/*
61 * The three following globals are initialized in w83627ehf_find(), before
62 * the i2c-isa device is created. Otherwise, they could be stored in
63 * w83627ehf_data. This is ugly, but necessary, and when the driver is next
64 * updated to become a platform driver, the globals will disappear.
65 */
58static int REG; /* The register to read/write */ 66static int REG; /* The register to read/write */
59static int VAL; /* The value to read/write */ 67static int VAL; /* The value to read/write */
68/* The w83627ehf/ehg have 10 voltage inputs, but the w83627dhg has 9. This
69 * value is also used in w83627ehf_detect() to export a device name in sysfs
70 * (e.g. w83627ehf or w83627dhg) */
71static int w83627ehf_num_in;
60 72
61#define W83627EHF_LD_HWM 0x0b 73#define W83627EHF_LD_HWM 0x0b
62 74
@@ -65,8 +77,10 @@ static int VAL; /* The value to read/write */
65#define SIO_REG_ENABLE 0x30 /* Logical device enable */ 77#define SIO_REG_ENABLE 0x30 /* Logical device enable */
66#define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */ 78#define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
67 79
68#define SIO_W83627EHF_ID 0x8840 80#define SIO_W83627EHF_ID 0x8850
69#define SIO_ID_MASK 0xFFC0 81#define SIO_W83627EHG_ID 0x8860
82#define SIO_W83627DHG_ID 0xa020
83#define SIO_ID_MASK 0xFFF0
70 84
71static inline void 85static inline void
72superio_outb(int reg, int val) 86superio_outb(int reg, int val)
@@ -115,8 +129,12 @@ superio_exit(void)
115 129
116#define W83627EHF_REG_BANK 0x4E 130#define W83627EHF_REG_BANK 0x4E
117#define W83627EHF_REG_CONFIG 0x40 131#define W83627EHF_REG_CONFIG 0x40
118#define W83627EHF_REG_CHIP_ID 0x49 132
119#define W83627EHF_REG_MAN_ID 0x4F 133/* Not currently used:
134 * REG_MAN_ID has the value 0x5ca3 for all supported chips.
135 * REG_CHIP_ID == 0x88/0xa1/0xc1 depending on chip model.
136 * REG_MAN_ID is at port 0x4f
137 * REG_CHIP_ID is at port 0x58 */
120 138
121static const u16 W83627EHF_REG_FAN[] = { 0x28, 0x29, 0x2a, 0x3f, 0x553 }; 139static const u16 W83627EHF_REG_FAN[] = { 0x28, 0x29, 0x2a, 0x3f, 0x553 };
122static const u16 W83627EHF_REG_FAN_MIN[] = { 0x3b, 0x3c, 0x3d, 0x3e, 0x55c }; 140static const u16 W83627EHF_REG_FAN_MIN[] = { 0x3b, 0x3c, 0x3d, 0x3e, 0x55c };
@@ -429,7 +447,7 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
429 } 447 }
430 448
431 /* Measured voltages and limits */ 449 /* Measured voltages and limits */
432 for (i = 0; i < 10; i++) { 450 for (i = 0; i < w83627ehf_num_in; i++) {
433 data->in[i] = w83627ehf_read_value(client, 451 data->in[i] = w83627ehf_read_value(client,
434 W83627EHF_REG_IN(i)); 452 W83627EHF_REG_IN(i));
435 data->in_min[i] = w83627ehf_read_value(client, 453 data->in_min[i] = w83627ehf_read_value(client,
@@ -1121,7 +1139,7 @@ static void w83627ehf_device_remove_files(struct device *dev)
1121 device_remove_file(dev, &sda_sf3_arrays[i].dev_attr); 1139 device_remove_file(dev, &sda_sf3_arrays[i].dev_attr);
1122 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) 1140 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++)
1123 device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr); 1141 device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr);
1124 for (i = 0; i < 10; i++) { 1142 for (i = 0; i < w83627ehf_num_in; i++) {
1125 device_remove_file(dev, &sda_in_input[i].dev_attr); 1143 device_remove_file(dev, &sda_in_input[i].dev_attr);
1126 device_remove_file(dev, &sda_in_alarm[i].dev_attr); 1144 device_remove_file(dev, &sda_in_alarm[i].dev_attr);
1127 device_remove_file(dev, &sda_in_min[i].dev_attr); 1145 device_remove_file(dev, &sda_in_min[i].dev_attr);
@@ -1196,7 +1214,11 @@ static int w83627ehf_detect(struct i2c_adapter *adapter)
1196 client->flags = 0; 1214 client->flags = 0;
1197 dev = &client->dev; 1215 dev = &client->dev;
1198 1216
1199 strlcpy(client->name, "w83627ehf", I2C_NAME_SIZE); 1217 if (w83627ehf_num_in == 9)
1218 strlcpy(client->name, "w83627dhg", I2C_NAME_SIZE);
1219 else /* just say ehf. 627EHG is 627EHF in lead-free packaging. */
1220 strlcpy(client->name, "w83627ehf", I2C_NAME_SIZE);
1221
1200 data->valid = 0; 1222 data->valid = 0;
1201 mutex_init(&data->update_lock); 1223 mutex_init(&data->update_lock);
1202 1224
@@ -1246,7 +1268,7 @@ static int w83627ehf_detect(struct i2c_adapter *adapter)
1246 goto exit_remove; 1268 goto exit_remove;
1247 } 1269 }
1248 1270
1249 for (i = 0; i < 10; i++) 1271 for (i = 0; i < w83627ehf_num_in; i++)
1250 if ((err = device_create_file(dev, &sda_in_input[i].dev_attr)) 1272 if ((err = device_create_file(dev, &sda_in_input[i].dev_attr))
1251 || (err = device_create_file(dev, 1273 || (err = device_create_file(dev,
1252 &sda_in_alarm[i].dev_attr)) 1274 &sda_in_alarm[i].dev_attr))
@@ -1340,7 +1362,17 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr)
1340 1362
1341 val = (superio_inb(SIO_REG_DEVID) << 8) 1363 val = (superio_inb(SIO_REG_DEVID) << 8)
1342 | superio_inb(SIO_REG_DEVID + 1); 1364 | superio_inb(SIO_REG_DEVID + 1);
1343 if ((val & SIO_ID_MASK) != SIO_W83627EHF_ID) { 1365 switch (val & SIO_ID_MASK) {
1366 case SIO_W83627DHG_ID:
1367 w83627ehf_num_in = 9;
1368 break;
1369 case SIO_W83627EHF_ID:
1370 case SIO_W83627EHG_ID:
1371 w83627ehf_num_in = 10;
1372 break;
1373 default:
1374 printk(KERN_WARNING "w83627ehf: unsupported chip ID: 0x%04x\n",
1375 val);
1344 superio_exit(); 1376 superio_exit();
1345 return -ENODEV; 1377 return -ENODEV;
1346 } 1378 }
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index dfdc29c771..d7e240635b 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -286,9 +286,8 @@ static inline u8 DIV_TO_REG(long val)
286 return ((u8) i); 286 return ((u8) i);
287} 287}
288 288
289/* For each registered chip, we need to keep some data in memory. That 289/* For each registered chip, we need to keep some data in memory.
290 data is pointed to by w83627hf_list[NR]->data. The structure itself is 290 The structure is dynamically allocated. */
291 dynamically allocated, at the same time when a new client is allocated. */
292struct w83627hf_data { 291struct w83627hf_data {
293 struct i2c_client client; 292 struct i2c_client client;
294 struct class_device *class_dev; 293 struct class_device *class_dev;
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index 1232171c3a..a47da3ec54 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -221,14 +221,8 @@ DIV_TO_REG(long val, enum chips type)
221 a bit - except if there could be more than one SMBus. Groan. No solution 221 a bit - except if there could be more than one SMBus. Groan. No solution
222 for this yet. */ 222 for this yet. */
223 223
224/* This module may seem overly long and complicated. In fact, it is not so 224/* For each registered chip, we need to keep some data in memory.
225 bad. Quite a lot of bookkeeping is done. A real driver can often cut 225 The structure is dynamically allocated. */
226 some corners. */
227
228/* For each registered W83781D, we need to keep some data in memory. That
229 data is pointed to by w83781d_list[NR]->data. The structure itself is
230 dynamically allocated, at the same time when a new w83781d client is
231 allocated. */
232struct w83781d_data { 226struct w83781d_data {
233 struct i2c_client client; 227 struct i2c_client client;
234 struct class_device *class_dev; 228 struct class_device *class_dev;
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 4d44a2db29..fb19dbb31e 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -495,6 +495,16 @@ config I2C_VERSATILE
495 This driver can also be built as a module. If so, the module 495 This driver can also be built as a module. If so, the module
496 will be called i2c-versatile. 496 will be called i2c-versatile.
497 497
498config I2C_ACORN
499 bool "Acorn IOC/IOMD I2C bus support"
500 depends on I2C && ARCH_ACORN
501 default y
502 select I2C_ALGOBIT
503 help
504 Say yes if you want to support the I2C bus on Acorn platforms.
505
506 If you don't know, say Y.
507
498config I2C_VIA 508config I2C_VIA
499 tristate "VIA 82C586B" 509 tristate "VIA 82C586B"
500 depends on I2C && PCI && EXPERIMENTAL 510 depends on I2C && PCI && EXPERIMENTAL
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 03505aa44b..290b540183 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -42,6 +42,7 @@ obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o
42obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o 42obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o
43obj-$(CONFIG_I2C_STUB) += i2c-stub.o 43obj-$(CONFIG_I2C_STUB) += i2c-stub.o
44obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o 44obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o
45obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o
45obj-$(CONFIG_I2C_VIA) += i2c-via.o 46obj-$(CONFIG_I2C_VIA) += i2c-via.o
46obj-$(CONFIG_I2C_VIAPRO) += i2c-viapro.o 47obj-$(CONFIG_I2C_VIAPRO) += i2c-viapro.o
47obj-$(CONFIG_I2C_VOODOO3) += i2c-voodoo3.o 48obj-$(CONFIG_I2C_VOODOO3) += i2c-voodoo3.o
diff --git a/drivers/i2c/busses/i2c-acorn.c b/drivers/i2c/busses/i2c-acorn.c
new file mode 100644
index 0000000000..09bd7f40b9
--- /dev/null
+++ b/drivers/i2c/busses/i2c-acorn.c
@@ -0,0 +1,97 @@
1/*
2 * linux/drivers/acorn/char/i2c.c
3 *
4 * Copyright (C) 2000 Russell King
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 * ARM IOC/IOMD i2c driver.
11 *
12 * On Acorn machines, the following i2c devices are on the bus:
13 * - PCF8583 real time clock & static RAM
14 */
15#include <linux/init.h>
16#include <linux/i2c.h>
17#include <linux/i2c-algo-bit.h>
18
19#include <asm/hardware.h>
20#include <asm/io.h>
21#include <asm/hardware/ioc.h>
22#include <asm/system.h>
23
24#define FORCE_ONES 0xdc
25#define SCL 0x02
26#define SDA 0x01
27
28/*
29 * We must preserve all non-i2c output bits in IOC_CONTROL.
30 * Note also that we need to preserve the value of SCL and
31 * SDA outputs as well (which may be different from the
32 * values read back from IOC_CONTROL).
33 */
34static u_int force_ones;
35
36static void ioc_setscl(void *data, int state)
37{
38 u_int ioc_control = ioc_readb(IOC_CONTROL) & ~(SCL | SDA);
39 u_int ones = force_ones;
40
41 if (state)
42 ones |= SCL;
43 else
44 ones &= ~SCL;
45
46 force_ones = ones;
47
48 ioc_writeb(ioc_control | ones, IOC_CONTROL);
49}
50
51static void ioc_setsda(void *data, int state)
52{
53 u_int ioc_control = ioc_readb(IOC_CONTROL) & ~(SCL | SDA);
54 u_int ones = force_ones;
55
56 if (state)
57 ones |= SDA;
58 else
59 ones &= ~SDA;
60
61 force_ones = ones;
62
63 ioc_writeb(ioc_control | ones, IOC_CONTROL);
64}
65
66static int ioc_getscl(void *data)
67{
68 return (ioc_readb(IOC_CONTROL) & SCL) != 0;
69}
70
71static int ioc_getsda(void *data)
72{
73 return (ioc_readb(IOC_CONTROL) & SDA) != 0;
74}
75
76static struct i2c_algo_bit_data ioc_data = {
77 .setsda = ioc_setsda,
78 .setscl = ioc_setscl,
79 .getsda = ioc_getsda,
80 .getscl = ioc_getscl,
81 .udelay = 80,
82 .timeout = 100
83};
84
85static struct i2c_adapter ioc_ops = {
86 .id = I2C_HW_B_IOC,
87 .algo_data = &ioc_data,
88};
89
90static int __init i2c_ioc_init(void)
91{
92 force_ones = FORCE_ONES | SCL | SDA;
93
94 return i2c_bit_add_bus(&ioc_ops);
95}
96
97__initcall(i2c_ioc_init);
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index 6fd8ad7faa..1e277ba5a9 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -494,7 +494,7 @@ static int __devinit ali1535_probe(struct pci_dev *dev, const struct pci_device_
494 return -ENODEV; 494 return -ENODEV;
495 } 495 }
496 496
497 /* set up the driverfs linkage to our parent device */ 497 /* set up the sysfs linkage to our parent device */
498 ali1535_adapter.dev.parent = &dev->dev; 498 ali1535_adapter.dev.parent = &dev->dev;
499 499
500 snprintf(ali1535_adapter.name, I2C_NAME_SIZE, 500 snprintf(ali1535_adapter.name, I2C_NAME_SIZE,
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index e4e0df1068..e47fe01bf4 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -489,7 +489,7 @@ static int __devinit ali15x3_probe(struct pci_dev *dev, const struct pci_device_
489 return -ENODEV; 489 return -ENODEV;
490 } 490 }
491 491
492 /* set up the driverfs linkage to our parent device */ 492 /* set up the sysfs linkage to our parent device */
493 ali15x3_adapter.dev.parent = &dev->dev; 493 ali15x3_adapter.dev.parent = &dev->dev;
494 494
495 snprintf(ali15x3_adapter.name, I2C_NAME_SIZE, 495 snprintf(ali15x3_adapter.name, I2C_NAME_SIZE,
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index fa6155a54c..7490dc1771 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -374,7 +374,7 @@ static int __devinit amd756_probe(struct pci_dev *pdev,
374 dev_dbg(&pdev->dev, "SMBREV = 0x%X\n", temp); 374 dev_dbg(&pdev->dev, "SMBREV = 0x%X\n", temp);
375 dev_dbg(&pdev->dev, "AMD756_smba = 0x%X\n", amd756_ioport); 375 dev_dbg(&pdev->dev, "AMD756_smba = 0x%X\n", amd756_ioport);
376 376
377 /* set up the driverfs linkage to our parent device */ 377 /* set up the sysfs linkage to our parent device */
378 amd756_smbus.dev.parent = &pdev->dev; 378 amd756_smbus.dev.parent = &pdev->dev;
379 379
380 sprintf(amd756_smbus.name, "SMBus %s adapter at %04x", 380 sprintf(amd756_smbus.name, "SMBus %s adapter at %04x",
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c
index 5bba3fb50d..e15f9e3771 100644
--- a/drivers/i2c/busses/i2c-amd8111.c
+++ b/drivers/i2c/busses/i2c-amd8111.c
@@ -371,7 +371,7 @@ static int __devinit amd8111_probe(struct pci_dev *dev,
371 smbus->adapter.algo = &smbus_algorithm; 371 smbus->adapter.algo = &smbus_algorithm;
372 smbus->adapter.algo_data = smbus; 372 smbus->adapter.algo_data = smbus;
373 373
374 /* set up the driverfs linkage to our parent device */ 374 /* set up the sysfs linkage to our parent device */
375 smbus->adapter.dev.parent = &dev->dev; 375 smbus->adapter.dev.parent = &dev->dev;
376 376
377 pci_write_config_dword(smbus->dev, AMD_PCI_MISC, 0); 377 pci_write_config_dword(smbus->dev, AMD_PCI_MISC, 0);
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 21f2671f72..6569a36985 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -522,7 +522,7 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
522 else 522 else
523 dev_dbg(&dev->dev, "SMBus using PCI Interrupt\n"); 523 dev_dbg(&dev->dev, "SMBus using PCI Interrupt\n");
524 524
525 /* set up the driverfs linkage to our parent device */ 525 /* set up the sysfs linkage to our parent device */
526 i801_adapter.dev.parent = &dev->dev; 526 i801_adapter.dev.parent = &dev->dev;
527 527
528 snprintf(i801_adapter.name, I2C_NAME_SIZE, 528 snprintf(i801_adapter.name, I2C_NAME_SIZE,
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index 20ee4f7c53..90e2d9350c 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -83,7 +83,7 @@ iop3xx_i2c_enable(struct i2c_algo_iop3xx_data *iop3xx_adap)
83 * Every time unit enable is asserted, GPOD needs to be cleared 83 * Every time unit enable is asserted, GPOD needs to be cleared
84 * on IOP3XX to avoid data corruption on the bus. 84 * on IOP3XX to avoid data corruption on the bus.
85 */ 85 */
86#ifdef CONFIG_PLAT_IOP 86#if defined(CONFIG_ARCH_IOP32X) || defined(CONFIG_ARCH_IOP33X)
87 if (iop3xx_adap->id == 0) { 87 if (iop3xx_adap->id == 0) {
88 gpio_line_set(IOP3XX_GPIO_LINE(7), GPIO_LOW); 88 gpio_line_set(IOP3XX_GPIO_LINE(7), GPIO_LOW);
89 gpio_line_set(IOP3XX_GPIO_LINE(6), GPIO_LOW); 89 gpio_line_set(IOP3XX_GPIO_LINE(6), GPIO_LOW);
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index d888293c1a..21b1809040 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -425,7 +425,7 @@ static int __devinit piix4_probe(struct pci_dev *dev,
425 if (retval) 425 if (retval)
426 return retval; 426 return retval;
427 427
428 /* set up the driverfs linkage to our parent device */ 428 /* set up the sysfs linkage to our parent device */
429 piix4_adapter.dev.parent = &dev->dev; 429 piix4_adapter.dev.parent = &dev->dev;
430 430
431 snprintf(piix4_adapter.name, I2C_NAME_SIZE, 431 snprintf(piix4_adapter.name, I2C_NAME_SIZE,
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index c3b1567c85..14e83d0aac 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -34,6 +34,7 @@
34 34
35#include <asm/hardware.h> 35#include <asm/hardware.h>
36#include <asm/irq.h> 36#include <asm/irq.h>
37#include <asm/io.h>
37#include <asm/arch/i2c.h> 38#include <asm/arch/i2c.h>
38#include <asm/arch/pxa-regs.h> 39#include <asm/arch/pxa-regs.h>
39 40
@@ -54,8 +55,21 @@ struct pxa_i2c {
54 unsigned int irqlogidx; 55 unsigned int irqlogidx;
55 u32 isrlog[32]; 56 u32 isrlog[32];
56 u32 icrlog[32]; 57 u32 icrlog[32];
58
59 void __iomem *reg_base;
60
61 unsigned long iobase;
62 unsigned long iosize;
63
64 int irq;
57}; 65};
58 66
67#define _IBMR(i2c) ((i2c)->reg_base + 0)
68#define _IDBR(i2c) ((i2c)->reg_base + 8)
69#define _ICR(i2c) ((i2c)->reg_base + 0x10)
70#define _ISR(i2c) ((i2c)->reg_base + 0x18)
71#define _ISAR(i2c) ((i2c)->reg_base + 0x20)
72
59/* 73/*
60 * I2C Slave mode address 74 * I2C Slave mode address
61 */ 75 */
@@ -130,7 +144,8 @@ static unsigned int i2c_debug = DEBUG;
130 144
131static void i2c_pxa_show_state(struct pxa_i2c *i2c, int lno, const char *fname) 145static void i2c_pxa_show_state(struct pxa_i2c *i2c, int lno, const char *fname)
132{ 146{
133 dev_dbg(&i2c->adap.dev, "state:%s:%d: ISR=%08x, ICR=%08x, IBMR=%02x\n", fname, lno, ISR, ICR, IBMR); 147 dev_dbg(&i2c->adap.dev, "state:%s:%d: ISR=%08x, ICR=%08x, IBMR=%02x\n", fname, lno,
148 readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
134} 149}
135 150
136#define show_state(i2c) i2c_pxa_show_state(i2c, __LINE__, __FUNCTION__) 151#define show_state(i2c) i2c_pxa_show_state(i2c, __LINE__, __FUNCTION__)
@@ -153,7 +168,7 @@ static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why)
153 printk("i2c: msg_num: %d msg_idx: %d msg_ptr: %d\n", 168 printk("i2c: msg_num: %d msg_idx: %d msg_ptr: %d\n",
154 i2c->msg_num, i2c->msg_idx, i2c->msg_ptr); 169 i2c->msg_num, i2c->msg_idx, i2c->msg_ptr);
155 printk("i2c: ICR: %08x ISR: %08x\n" 170 printk("i2c: ICR: %08x ISR: %08x\n"
156 "i2c: log: ", ICR, ISR); 171 "i2c: log: ", readl(_ICR(i2c)), readl(_ISR(i2c)));
157 for (i = 0; i < i2c->irqlogidx; i++) 172 for (i = 0; i < i2c->irqlogidx; i++)
158 printk("[%08x:%08x] ", i2c->isrlog[i], i2c->icrlog[i]); 173 printk("[%08x:%08x] ", i2c->isrlog[i], i2c->icrlog[i]);
159 printk("\n"); 174 printk("\n");
@@ -161,7 +176,7 @@ static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why)
161 176
162static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c) 177static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c)
163{ 178{
164 return !(ICR & ICR_SCLE); 179 return !(readl(_ICR(i2c)) & ICR_SCLE);
165} 180}
166 181
167static void i2c_pxa_abort(struct pxa_i2c *i2c) 182static void i2c_pxa_abort(struct pxa_i2c *i2c)
@@ -173,28 +188,29 @@ static void i2c_pxa_abort(struct pxa_i2c *i2c)
173 return; 188 return;
174 } 189 }
175 190
176 while (time_before(jiffies, timeout) && (IBMR & 0x1) == 0) { 191 while (time_before(jiffies, timeout) && (readl(_IBMR(i2c)) & 0x1) == 0) {
177 unsigned long icr = ICR; 192 unsigned long icr = readl(_ICR(i2c));
178 193
179 icr &= ~ICR_START; 194 icr &= ~ICR_START;
180 icr |= ICR_ACKNAK | ICR_STOP | ICR_TB; 195 icr |= ICR_ACKNAK | ICR_STOP | ICR_TB;
181 196
182 ICR = icr; 197 writel(icr, _ICR(i2c));
183 198
184 show_state(i2c); 199 show_state(i2c);
185 200
186 msleep(1); 201 msleep(1);
187 } 202 }
188 203
189 ICR &= ~(ICR_MA | ICR_START | ICR_STOP); 204 writel(readl(_ICR(i2c)) & ~(ICR_MA | ICR_START | ICR_STOP),
205 _ICR(i2c));
190} 206}
191 207
192static int i2c_pxa_wait_bus_not_busy(struct pxa_i2c *i2c) 208static int i2c_pxa_wait_bus_not_busy(struct pxa_i2c *i2c)
193{ 209{
194 int timeout = DEF_TIMEOUT; 210 int timeout = DEF_TIMEOUT;
195 211
196 while (timeout-- && ISR & (ISR_IBB | ISR_UB)) { 212 while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) {
197 if ((ISR & ISR_SAD) != 0) 213 if ((readl(_ISR(i2c)) & ISR_SAD) != 0)
198 timeout += 4; 214 timeout += 4;
199 215
200 msleep(2); 216 msleep(2);
@@ -214,9 +230,9 @@ static int i2c_pxa_wait_master(struct pxa_i2c *i2c)
214 while (time_before(jiffies, timeout)) { 230 while (time_before(jiffies, timeout)) {
215 if (i2c_debug > 1) 231 if (i2c_debug > 1)
216 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n", 232 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n",
217 __func__, (long)jiffies, ISR, ICR, IBMR); 233 __func__, (long)jiffies, readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
218 234
219 if (ISR & ISR_SAD) { 235 if (readl(_ISR(i2c)) & ISR_SAD) {
220 if (i2c_debug > 0) 236 if (i2c_debug > 0)
221 dev_dbg(&i2c->adap.dev, "%s: Slave detected\n", __func__); 237 dev_dbg(&i2c->adap.dev, "%s: Slave detected\n", __func__);
222 goto out; 238 goto out;
@@ -226,7 +242,7 @@ static int i2c_pxa_wait_master(struct pxa_i2c *i2c)
226 * quick check of the i2c lines themselves to ensure they've 242 * quick check of the i2c lines themselves to ensure they've
227 * gone high... 243 * gone high...
228 */ 244 */
229 if ((ISR & (ISR_UB | ISR_IBB)) == 0 && IBMR == 3) { 245 if ((readl(_ISR(i2c)) & (ISR_UB | ISR_IBB)) == 0 && readl(_IBMR(i2c)) == 3) {
230 if (i2c_debug > 0) 246 if (i2c_debug > 0)
231 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__); 247 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__);
232 return 1; 248 return 1;
@@ -246,7 +262,7 @@ static int i2c_pxa_set_master(struct pxa_i2c *i2c)
246 if (i2c_debug) 262 if (i2c_debug)
247 dev_dbg(&i2c->adap.dev, "setting to bus master\n"); 263 dev_dbg(&i2c->adap.dev, "setting to bus master\n");
248 264
249 if ((ISR & (ISR_UB | ISR_IBB)) != 0) { 265 if ((readl(_ISR(i2c)) & (ISR_UB | ISR_IBB)) != 0) {
250 dev_dbg(&i2c->adap.dev, "%s: unit is busy\n", __func__); 266 dev_dbg(&i2c->adap.dev, "%s: unit is busy\n", __func__);
251 if (!i2c_pxa_wait_master(i2c)) { 267 if (!i2c_pxa_wait_master(i2c)) {
252 dev_dbg(&i2c->adap.dev, "%s: error: unit busy\n", __func__); 268 dev_dbg(&i2c->adap.dev, "%s: error: unit busy\n", __func__);
@@ -254,7 +270,7 @@ static int i2c_pxa_set_master(struct pxa_i2c *i2c)
254 } 270 }
255 } 271 }
256 272
257 ICR |= ICR_SCLE; 273 writel(readl(_ICR(i2c)) | ICR_SCLE, _ICR(i2c));
258 return 0; 274 return 0;
259} 275}
260 276
@@ -270,11 +286,11 @@ static int i2c_pxa_wait_slave(struct pxa_i2c *i2c)
270 while (time_before(jiffies, timeout)) { 286 while (time_before(jiffies, timeout)) {
271 if (i2c_debug > 1) 287 if (i2c_debug > 1)
272 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n", 288 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n",
273 __func__, (long)jiffies, ISR, ICR, IBMR); 289 __func__, (long)jiffies, readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
274 290
275 if ((ISR & (ISR_UB|ISR_IBB)) == 0 || 291 if ((readl(_ISR(i2c)) & (ISR_UB|ISR_IBB)) == 0 ||
276 (ISR & ISR_SAD) != 0 || 292 (readl(_ISR(i2c)) & ISR_SAD) != 0 ||
277 (ICR & ICR_SCLE) == 0) { 293 (readl(_ICR(i2c)) & ICR_SCLE) == 0) {
278 if (i2c_debug > 1) 294 if (i2c_debug > 1)
279 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__); 295 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__);
280 return 1; 296 return 1;
@@ -302,9 +318,9 @@ static void i2c_pxa_set_slave(struct pxa_i2c *i2c, int errcode)
302 /* we need to wait for the stop condition to end */ 318 /* we need to wait for the stop condition to end */
303 319
304 /* if we where in stop, then clear... */ 320 /* if we where in stop, then clear... */
305 if (ICR & ICR_STOP) { 321 if (readl(_ICR(i2c)) & ICR_STOP) {
306 udelay(100); 322 udelay(100);
307 ICR &= ~ICR_STOP; 323 writel(readl(_ICR(i2c)) & ~ICR_STOP, _ICR(i2c));
308 } 324 }
309 325
310 if (!i2c_pxa_wait_slave(i2c)) { 326 if (!i2c_pxa_wait_slave(i2c)) {
@@ -314,12 +330,12 @@ static void i2c_pxa_set_slave(struct pxa_i2c *i2c, int errcode)
314 } 330 }
315 } 331 }
316 332
317 ICR &= ~(ICR_STOP|ICR_ACKNAK|ICR_MA); 333 writel(readl(_ICR(i2c)) & ~(ICR_STOP|ICR_ACKNAK|ICR_MA), _ICR(i2c));
318 ICR &= ~ICR_SCLE; 334 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
319 335
320 if (i2c_debug) { 336 if (i2c_debug) {
321 dev_dbg(&i2c->adap.dev, "ICR now %08x, ISR %08x\n", ICR, ISR); 337 dev_dbg(&i2c->adap.dev, "ICR now %08x, ISR %08x\n", readl(_ICR(i2c)), readl(_ISR(i2c)));
322 decode_ICR(ICR); 338 decode_ICR(readl(_ICR(i2c)));
323 } 339 }
324} 340}
325#else 341#else
@@ -334,24 +350,24 @@ static void i2c_pxa_reset(struct pxa_i2c *i2c)
334 i2c_pxa_abort(i2c); 350 i2c_pxa_abort(i2c);
335 351
336 /* reset according to 9.8 */ 352 /* reset according to 9.8 */
337 ICR = ICR_UR; 353 writel(ICR_UR, _ICR(i2c));
338 ISR = I2C_ISR_INIT; 354 writel(I2C_ISR_INIT, _ISR(i2c));
339 ICR &= ~ICR_UR; 355 writel(readl(_ICR(i2c)) & ~ICR_UR, _ICR(i2c));
340 356
341 ISAR = i2c->slave_addr; 357 writel(i2c->slave_addr, _ISAR(i2c));
342 358
343 /* set control register values */ 359 /* set control register values */
344 ICR = I2C_ICR_INIT; 360 writel(I2C_ICR_INIT, _ICR(i2c));
345 361
346#ifdef CONFIG_I2C_PXA_SLAVE 362#ifdef CONFIG_I2C_PXA_SLAVE
347 dev_info(&i2c->adap.dev, "Enabling slave mode\n"); 363 dev_info(&i2c->adap.dev, "Enabling slave mode\n");
348 ICR |= ICR_SADIE | ICR_ALDIE | ICR_SSDIE; 364 writel(readl(_ICR(i2c)) | ICR_SADIE | ICR_ALDIE | ICR_SSDIE, _ICR(i2c));
349#endif 365#endif
350 366
351 i2c_pxa_set_slave(i2c, 0); 367 i2c_pxa_set_slave(i2c, 0);
352 368
353 /* enable unit */ 369 /* enable unit */
354 ICR |= ICR_IUE; 370 writel(readl(_ICR(i2c)) | ICR_IUE, _ICR(i2c));
355 udelay(100); 371 udelay(100);
356} 372}
357 373
@@ -371,19 +387,19 @@ static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr)
371 if (i2c->slave != NULL) 387 if (i2c->slave != NULL)
372 ret = i2c->slave->read(i2c->slave->data); 388 ret = i2c->slave->read(i2c->slave->data);
373 389
374 IDBR = ret; 390 writel(ret, _IDBR(i2c));
375 ICR |= ICR_TB; /* allow next byte */ 391 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c)); /* allow next byte */
376 } 392 }
377} 393}
378 394
379static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr) 395static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr)
380{ 396{
381 unsigned int byte = IDBR; 397 unsigned int byte = readl(_IDBR(i2c));
382 398
383 if (i2c->slave != NULL) 399 if (i2c->slave != NULL)
384 i2c->slave->write(i2c->slave->data, byte); 400 i2c->slave->write(i2c->slave->data, byte);
385 401
386 ICR |= ICR_TB; 402 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
387} 403}
388 404
389static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr) 405static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
@@ -403,13 +419,13 @@ static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
403 * start condition... if this happens, we'd better back off 419 * start condition... if this happens, we'd better back off
404 * and stop holding the poor thing up 420 * and stop holding the poor thing up
405 */ 421 */
406 ICR &= ~(ICR_START|ICR_STOP); 422 writel(readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP), _ICR(i2c));
407 ICR |= ICR_TB; 423 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
408 424
409 timeout = 0x10000; 425 timeout = 0x10000;
410 426
411 while (1) { 427 while (1) {
412 if ((IBMR & 2) == 2) 428 if ((readl(_IBMR(i2c)) & 2) == 2)
413 break; 429 break;
414 430
415 timeout--; 431 timeout--;
@@ -420,7 +436,7 @@ static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
420 } 436 }
421 } 437 }
422 438
423 ICR &= ~ICR_SCLE; 439 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
424} 440}
425 441
426static void i2c_pxa_slave_stop(struct pxa_i2c *i2c) 442static void i2c_pxa_slave_stop(struct pxa_i2c *i2c)
@@ -447,14 +463,14 @@ static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr)
447 if (isr & ISR_BED) { 463 if (isr & ISR_BED) {
448 /* what should we do here? */ 464 /* what should we do here? */
449 } else { 465 } else {
450 IDBR = 0; 466 writel(0, _IDBR(i2c));
451 ICR |= ICR_TB; 467 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
452 } 468 }
453} 469}
454 470
455static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr) 471static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr)
456{ 472{
457 ICR |= ICR_TB | ICR_ACKNAK; 473 writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c));
458} 474}
459 475
460static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr) 476static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
@@ -466,13 +482,13 @@ static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
466 * start condition... if this happens, we'd better back off 482 * start condition... if this happens, we'd better back off
467 * and stop holding the poor thing up 483 * and stop holding the poor thing up
468 */ 484 */
469 ICR &= ~(ICR_START|ICR_STOP); 485 writel(readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP), _ICR(i2c));
470 ICR |= ICR_TB | ICR_ACKNAK; 486 writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c));
471 487
472 timeout = 0x10000; 488 timeout = 0x10000;
473 489
474 while (1) { 490 while (1) {
475 if ((IBMR & 2) == 2) 491 if ((readl(_IBMR(i2c)) & 2) == 2)
476 break; 492 break;
477 493
478 timeout--; 494 timeout--;
@@ -483,7 +499,7 @@ static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
483 } 499 }
484 } 500 }
485 501
486 ICR &= ~ICR_SCLE; 502 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
487} 503}
488 504
489static void i2c_pxa_slave_stop(struct pxa_i2c *i2c) 505static void i2c_pxa_slave_stop(struct pxa_i2c *i2c)
@@ -514,13 +530,13 @@ static inline void i2c_pxa_start_message(struct pxa_i2c *i2c)
514 /* 530 /*
515 * Step 1: target slave address into IDBR 531 * Step 1: target slave address into IDBR
516 */ 532 */
517 IDBR = i2c_pxa_addr_byte(i2c->msg); 533 writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
518 534
519 /* 535 /*
520 * Step 2: initiate the write. 536 * Step 2: initiate the write.
521 */ 537 */
522 icr = ICR & ~(ICR_STOP | ICR_ALDIE); 538 icr = readl(_ICR(i2c)) & ~(ICR_STOP | ICR_ALDIE);
523 ICR = icr | ICR_START | ICR_TB; 539 writel(icr | ICR_START | ICR_TB, _ICR(i2c));
524} 540}
525 541
526/* 542/*
@@ -594,7 +610,7 @@ static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret)
594 610
595static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr) 611static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
596{ 612{
597 u32 icr = ICR & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB); 613 u32 icr = readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB);
598 614
599 again: 615 again:
600 /* 616 /*
@@ -645,7 +661,7 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
645 /* 661 /*
646 * Write mode. Write the next data byte. 662 * Write mode. Write the next data byte.
647 */ 663 */
648 IDBR = i2c->msg->buf[i2c->msg_ptr++]; 664 writel(i2c->msg->buf[i2c->msg_ptr++], _IDBR(i2c));
649 665
650 icr |= ICR_ALDIE | ICR_TB; 666 icr |= ICR_ALDIE | ICR_TB;
651 667
@@ -675,7 +691,7 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
675 /* 691 /*
676 * Write the next address. 692 * Write the next address.
677 */ 693 */
678 IDBR = i2c_pxa_addr_byte(i2c->msg); 694 writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
679 695
680 /* 696 /*
681 * And trigger a repeated start, and send the byte. 697 * And trigger a repeated start, and send the byte.
@@ -696,18 +712,18 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
696 712
697 i2c->icrlog[i2c->irqlogidx-1] = icr; 713 i2c->icrlog[i2c->irqlogidx-1] = icr;
698 714
699 ICR = icr; 715 writel(icr, _ICR(i2c));
700 show_state(i2c); 716 show_state(i2c);
701} 717}
702 718
703static void i2c_pxa_irq_rxfull(struct pxa_i2c *i2c, u32 isr) 719static void i2c_pxa_irq_rxfull(struct pxa_i2c *i2c, u32 isr)
704{ 720{
705 u32 icr = ICR & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB); 721 u32 icr = readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB);
706 722
707 /* 723 /*
708 * Read the byte. 724 * Read the byte.
709 */ 725 */
710 i2c->msg->buf[i2c->msg_ptr++] = IDBR; 726 i2c->msg->buf[i2c->msg_ptr++] = readl(_IDBR(i2c));
711 727
712 if (i2c->msg_ptr < i2c->msg->len) { 728 if (i2c->msg_ptr < i2c->msg->len) {
713 /* 729 /*
@@ -724,17 +740,17 @@ static void i2c_pxa_irq_rxfull(struct pxa_i2c *i2c, u32 isr)
724 740
725 i2c->icrlog[i2c->irqlogidx-1] = icr; 741 i2c->icrlog[i2c->irqlogidx-1] = icr;
726 742
727 ICR = icr; 743 writel(icr, _ICR(i2c));
728} 744}
729 745
730static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id) 746static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id)
731{ 747{
732 struct pxa_i2c *i2c = dev_id; 748 struct pxa_i2c *i2c = dev_id;
733 u32 isr = ISR; 749 u32 isr = readl(_ISR(i2c));
734 750
735 if (i2c_debug > 2 && 0) { 751 if (i2c_debug > 2 && 0) {
736 dev_dbg(&i2c->adap.dev, "%s: ISR=%08x, ICR=%08x, IBMR=%02x\n", 752 dev_dbg(&i2c->adap.dev, "%s: ISR=%08x, ICR=%08x, IBMR=%02x\n",
737 __func__, isr, ICR, IBMR); 753 __func__, isr, readl(_ICR(i2c)), readl(_IBMR(i2c)));
738 decode_ISR(isr); 754 decode_ISR(isr);
739 } 755 }
740 756
@@ -746,7 +762,7 @@ static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id)
746 /* 762 /*
747 * Always clear all pending IRQs. 763 * Always clear all pending IRQs.
748 */ 764 */
749 ISR = isr & (ISR_SSD|ISR_ALD|ISR_ITE|ISR_IRF|ISR_SAD|ISR_BED); 765 writel(isr & (ISR_SSD|ISR_ALD|ISR_ITE|ISR_IRF|ISR_SAD|ISR_BED), _ISR(i2c));
750 766
751 if (isr & ISR_SAD) 767 if (isr & ISR_SAD)
752 i2c_pxa_slave_start(i2c, isr); 768 i2c_pxa_slave_start(i2c, isr);
@@ -779,7 +795,7 @@ static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num
779 /* If the I2C controller is disabled we need to reset it (probably due 795 /* If the I2C controller is disabled we need to reset it (probably due
780 to a suspend/resume destroying state). We do this here as we can then 796 to a suspend/resume destroying state). We do this here as we can then
781 avoid worrying about resuming the controller before its users. */ 797 avoid worrying about resuming the controller before its users. */
782 if (!(ICR & ICR_IUE)) 798 if (!(readl(_ICR(i2c)) & ICR_IUE))
783 i2c_pxa_reset(i2c); 799 i2c_pxa_reset(i2c);
784 800
785 for (i = adap->retries; i >= 0; i--) { 801 for (i = adap->retries; i >= 0; i--) {
@@ -810,28 +826,53 @@ static const struct i2c_algorithm i2c_pxa_algorithm = {
810 826
811static struct pxa_i2c i2c_pxa = { 827static struct pxa_i2c i2c_pxa = {
812 .lock = SPIN_LOCK_UNLOCKED, 828 .lock = SPIN_LOCK_UNLOCKED,
813 .wait = __WAIT_QUEUE_HEAD_INITIALIZER(i2c_pxa.wait),
814 .adap = { 829 .adap = {
815 .owner = THIS_MODULE, 830 .owner = THIS_MODULE,
816 .algo = &i2c_pxa_algorithm, 831 .algo = &i2c_pxa_algorithm,
817 .name = "pxa2xx-i2c", 832 .name = "pxa2xx-i2c.0",
818 .retries = 5, 833 .retries = 5,
819 }, 834 },
820}; 835};
821 836
837#define res_len(r) ((r)->end - (r)->start + 1)
822static int i2c_pxa_probe(struct platform_device *dev) 838static int i2c_pxa_probe(struct platform_device *dev)
823{ 839{
824 struct pxa_i2c *i2c = &i2c_pxa; 840 struct pxa_i2c *i2c = &i2c_pxa;
841 struct resource *res;
825#ifdef CONFIG_I2C_PXA_SLAVE 842#ifdef CONFIG_I2C_PXA_SLAVE
826 struct i2c_pxa_platform_data *plat = dev->dev.platform_data; 843 struct i2c_pxa_platform_data *plat = dev->dev.platform_data;
827#endif 844#endif
828 int ret; 845 int ret;
846 int irq;
829 847
830#ifdef CONFIG_PXA27x 848 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
831 pxa_gpio_mode(GPIO117_I2CSCL_MD); 849 irq = platform_get_irq(dev, 0);
832 pxa_gpio_mode(GPIO118_I2CSDA_MD); 850 if (res == NULL || irq < 0)
833 udelay(100); 851 return -ENODEV;
834#endif 852
853 if (!request_mem_region(res->start, res_len(res), res->name))
854 return -ENOMEM;
855
856 i2c = kmalloc(sizeof(struct pxa_i2c), GFP_KERNEL);
857 if (!i2c) {
858 ret = -ENOMEM;
859 goto emalloc;
860 }
861
862 memcpy(i2c, &i2c_pxa, sizeof(struct pxa_i2c));
863 init_waitqueue_head(&i2c->wait);
864 i2c->adap.name[strlen(i2c->adap.name) - 1] = '0' + dev->id % 10;
865
866 i2c->reg_base = ioremap(res->start, res_len(res));
867 if (!i2c->reg_base) {
868 ret = -EIO;
869 goto eremap;
870 }
871
872 i2c->iobase = res->start;
873 i2c->iosize = res_len(res);
874
875 i2c->irq = irq;
835 876
836 i2c->slave_addr = I2C_PXA_SLAVE_ADDR; 877 i2c->slave_addr = I2C_PXA_SLAVE_ADDR;
837 878
@@ -842,11 +883,28 @@ static int i2c_pxa_probe(struct platform_device *dev)
842 } 883 }
843#endif 884#endif
844 885
845 pxa_set_cken(CKEN14_I2C, 1); 886 switch (dev->id) {
846 ret = request_irq(IRQ_I2C, i2c_pxa_handler, IRQF_DISABLED, 887 case 0:
847 "pxa2xx-i2c", i2c); 888#ifdef CONFIG_PXA27x
889 pxa_gpio_mode(GPIO117_I2CSCL_MD);
890 pxa_gpio_mode(GPIO118_I2CSDA_MD);
891#endif
892 pxa_set_cken(CKEN14_I2C, 1);
893 break;
894#ifdef CONFIG_PXA27x
895 case 1:
896 local_irq_disable();
897 PCFR |= PCFR_PI2CEN;
898 local_irq_enable();
899 pxa_set_cken(CKEN15_PWRI2C, 1);
900#endif
901 }
902
903 ret = request_irq(irq, i2c_pxa_handler, IRQF_DISABLED,
904 i2c->adap.name, i2c);
848 if (ret) 905 if (ret)
849 goto out; 906 goto ereqirq;
907
850 908
851 i2c_pxa_reset(i2c); 909 i2c_pxa_reset(i2c);
852 910
@@ -856,7 +914,7 @@ static int i2c_pxa_probe(struct platform_device *dev)
856 ret = i2c_add_adapter(&i2c->adap); 914 ret = i2c_add_adapter(&i2c->adap);
857 if (ret < 0) { 915 if (ret < 0) {
858 printk(KERN_INFO "I2C: Failed to add bus\n"); 916 printk(KERN_INFO "I2C: Failed to add bus\n");
859 goto err_irq; 917 goto eadapt;
860 } 918 }
861 919
862 platform_set_drvdata(dev, i2c); 920 platform_set_drvdata(dev, i2c);
@@ -870,9 +928,25 @@ static int i2c_pxa_probe(struct platform_device *dev)
870#endif 928#endif
871 return 0; 929 return 0;
872 930
873 err_irq: 931eadapt:
874 free_irq(IRQ_I2C, i2c); 932 free_irq(irq, i2c);
875 out: 933ereqirq:
934 switch (dev->id) {
935 case 0:
936 pxa_set_cken(CKEN14_I2C, 0);
937 break;
938#ifdef CONFIG_PXA27x
939 case 1:
940 pxa_set_cken(CKEN15_PWRI2C, 0);
941 local_irq_disable();
942 PCFR &= ~PCFR_PI2CEN;
943 local_irq_enable();
944#endif
945 }
946eremap:
947 kfree(i2c);
948emalloc:
949 release_mem_region(res->start, res_len(res));
876 return ret; 950 return ret;
877} 951}
878 952
@@ -883,8 +957,21 @@ static int i2c_pxa_remove(struct platform_device *dev)
883 platform_set_drvdata(dev, NULL); 957 platform_set_drvdata(dev, NULL);
884 958
885 i2c_del_adapter(&i2c->adap); 959 i2c_del_adapter(&i2c->adap);
886 free_irq(IRQ_I2C, i2c); 960 free_irq(i2c->irq, i2c);
887 pxa_set_cken(CKEN14_I2C, 0); 961 switch (dev->id) {
962 case 0:
963 pxa_set_cken(CKEN14_I2C, 0);
964 break;
965#ifdef CONFIG_PXA27x
966 case 1:
967 pxa_set_cken(CKEN15_PWRI2C, 0);
968 local_irq_disable();
969 PCFR &= ~PCFR_PI2CEN;
970 local_irq_enable();
971#endif
972 }
973 release_mem_region(i2c->iobase, i2c->iosize);
974 kfree(i2c);
888 975
889 return 0; 976 return 0;
890} 977}
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index d333babe4a..a6feed449d 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -384,7 +384,7 @@ static int __devinit sis5595_probe(struct pci_dev *dev, const struct pci_device_
384 return -ENODEV; 384 return -ENODEV;
385 } 385 }
386 386
387 /* set up the driverfs linkage to our parent device */ 387 /* set up the sysfs linkage to our parent device */
388 sis5595_adapter.dev.parent = &dev->dev; 388 sis5595_adapter.dev.parent = &dev->dev;
389 389
390 sprintf(sis5595_adapter.name, "SMBus SIS5595 adapter at %04x", 390 sprintf(sis5595_adapter.name, "SMBus SIS5595 adapter at %04x",
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index 172bacf932..5fd734f99e 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -477,7 +477,7 @@ static int __devinit sis630_probe(struct pci_dev *dev, const struct pci_device_i
477 return -ENODEV; 477 return -ENODEV;
478 } 478 }
479 479
480 /* set up the driverfs linkage to our parent device */ 480 /* set up the sysfs linkage to our parent device */
481 sis630_adapter.dev.parent = &dev->dev; 481 sis630_adapter.dev.parent = &dev->dev;
482 482
483 sprintf(sis630_adapter.name, "SMBus SIS630 adapter at %04x", 483 sprintf(sis630_adapter.name, "SMBus SIS630 adapter at %04x",
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index 73dae449fb..4157b0cd60 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -297,7 +297,7 @@ static int __devinit sis96x_probe(struct pci_dev *dev,
297 return -EINVAL; 297 return -EINVAL;
298 } 298 }
299 299
300 /* set up the driverfs linkage to our parent device */ 300 /* set up the sysfs linkage to our parent device */
301 sis96x_adapter.dev.parent = &dev->dev; 301 sis96x_adapter.dev.parent = &dev->dev;
302 302
303 snprintf(sis96x_adapter.name, I2C_NAME_SIZE, 303 snprintf(sis96x_adapter.name, I2C_NAME_SIZE,
diff --git a/drivers/i2c/busses/i2c-via.c b/drivers/i2c/busses/i2c-via.c
index bbcc62151f..8152086879 100644
--- a/drivers/i2c/busses/i2c-via.c
+++ b/drivers/i2c/busses/i2c-via.c
@@ -138,7 +138,7 @@ static int __devinit vt586b_probe(struct pci_dev *dev, const struct pci_device_i
138 outb(inb(I2C_DIR) & ~(I2C_SDA | I2C_SCL), I2C_DIR); 138 outb(inb(I2C_DIR) & ~(I2C_SDA | I2C_SCL), I2C_DIR);
139 outb(inb(I2C_OUT) & ~(I2C_SDA | I2C_SCL), I2C_OUT); 139 outb(inb(I2C_OUT) & ~(I2C_SDA | I2C_SCL), I2C_OUT);
140 140
141 /* set up the driverfs linkage to our parent device */ 141 /* set up the sysfs linkage to our parent device */
142 vt586b_adapter.dev.parent = &dev->dev; 142 vt586b_adapter.dev.parent = &dev->dev;
143 143
144 res = i2c_bit_add_bus(&vt586b_adapter); 144 res = i2c_bit_add_bus(&vt586b_adapter);
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index ec03341d2b..5d134bb75b 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -383,6 +383,9 @@ config BLK_DEV_OFFBOARD
383config BLK_DEV_GENERIC 383config BLK_DEV_GENERIC
384 tristate "Generic PCI IDE Chipset Support" 384 tristate "Generic PCI IDE Chipset Support"
385 depends on BLK_DEV_IDEPCI 385 depends on BLK_DEV_IDEPCI
386 help
387 This option provides generic support for various PCI IDE Chipsets
388 which otherwise might not be supported.
386 389
387config BLK_DEV_OPTI621 390config BLK_DEV_OPTI621
388 tristate "OPTi 82C621 chipset enhanced support (EXPERIMENTAL)" 391 tristate "OPTi 82C621 chipset enhanced support (EXPERIMENTAL)"
@@ -797,6 +800,14 @@ config BLK_DEV_IDEDMA_PMAC
797 to transfer data to and from memory. Saying Y is safe and improves 800 to transfer data to and from memory. Saying Y is safe and improves
798 performance. 801 performance.
799 802
803config BLK_DEV_IDE_CELLEB
804 bool "Toshiba's Cell Reference Set IDE support"
805 depends on PPC_CELLEB
806 help
807 This driver provides support for the built-in IDE controller on
808 Toshiba Cell Reference Board.
809 If unsure, say Y.
810
800config BLK_DEV_IDE_SWARM 811config BLK_DEV_IDE_SWARM
801 tristate "IDE for Sibyte evaluation boards" 812 tristate "IDE for Sibyte evaluation boards"
802 depends on SIBYTE_SB1xxx_SOC 813 depends on SIBYTE_SB1xxx_SOC
@@ -1012,7 +1023,7 @@ config BLK_DEV_4DRIVES
1012config BLK_DEV_ALI14XX 1023config BLK_DEV_ALI14XX
1013 tristate "ALI M14xx support" 1024 tristate "ALI M14xx support"
1014 help 1025 help
1015 This driver is enabled at runtime using the "ide0=ali14xx" kernel 1026 This driver is enabled at runtime using the "ali14xx.probe" kernel
1016 boot parameter. It enables support for the secondary IDE interface 1027 boot parameter. It enables support for the secondary IDE interface
1017 of the ALI M1439/1443/1445/1487/1489 chipsets, and permits faster 1028 of the ALI M1439/1443/1445/1487/1489 chipsets, and permits faster
1018 I/O speeds to be set as well. See the files 1029 I/O speeds to be set as well. See the files
@@ -1022,7 +1033,7 @@ config BLK_DEV_ALI14XX
1022config BLK_DEV_DTC2278 1033config BLK_DEV_DTC2278
1023 tristate "DTC-2278 support" 1034 tristate "DTC-2278 support"
1024 help 1035 help
1025 This driver is enabled at runtime using the "ide0=dtc2278" kernel 1036 This driver is enabled at runtime using the "dtc2278.probe" kernel
1026 boot parameter. It enables support for the secondary IDE interface 1037 boot parameter. It enables support for the secondary IDE interface
1027 of the DTC-2278 card, and permits faster I/O speeds to be set as 1038 of the DTC-2278 card, and permits faster I/O speeds to be set as
1028 well. See the <file:Documentation/ide.txt> and 1039 well. See the <file:Documentation/ide.txt> and
@@ -1031,7 +1042,7 @@ config BLK_DEV_DTC2278
1031config BLK_DEV_HT6560B 1042config BLK_DEV_HT6560B
1032 tristate "Holtek HT6560B support" 1043 tristate "Holtek HT6560B support"
1033 help 1044 help
1034 This driver is enabled at runtime using the "ide0=ht6560b" kernel 1045 This driver is enabled at runtime using the "ht6560b.probe" kernel
1035 boot parameter. It enables support for the secondary IDE interface 1046 boot parameter. It enables support for the secondary IDE interface
1036 of the Holtek card, and permits faster I/O speeds to be set as well. 1047 of the Holtek card, and permits faster I/O speeds to be set as well.
1037 See the <file:Documentation/ide.txt> and 1048 See the <file:Documentation/ide.txt> and
@@ -1040,7 +1051,7 @@ config BLK_DEV_HT6560B
1040config BLK_DEV_QD65XX 1051config BLK_DEV_QD65XX
1041 tristate "QDI QD65xx support" 1052 tristate "QDI QD65xx support"
1042 help 1053 help
1043 This driver is enabled at runtime using the "ide0=qd65xx" kernel 1054 This driver is enabled at runtime using the "qd65xx.probe" kernel
1044 boot parameter. It permits faster I/O speeds to be set. See the 1055 boot parameter. It permits faster I/O speeds to be set. See the
1045 <file:Documentation/ide.txt> and <file:drivers/ide/legacy/qd65xx.c> for 1056 <file:Documentation/ide.txt> and <file:drivers/ide/legacy/qd65xx.c> for
1046 more info. 1057 more info.
@@ -1048,7 +1059,7 @@ config BLK_DEV_QD65XX
1048config BLK_DEV_UMC8672 1059config BLK_DEV_UMC8672
1049 tristate "UMC-8672 support" 1060 tristate "UMC-8672 support"
1050 help 1061 help
1051 This driver is enabled at runtime using the "ide0=umc8672" kernel 1062 This driver is enabled at runtime using the "umc8672.probe" kernel
1052 boot parameter. It enables support for the secondary IDE interface 1063 boot parameter. It enables support for the secondary IDE interface
1053 of the UMC-8672, and permits faster I/O speeds to be set as well. 1064 of the UMC-8672, and permits faster I/O speeds to be set as well.
1054 See the files <file:Documentation/ide.txt> and 1065 See the files <file:Documentation/ide.txt> and
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index d9f029e8ff..28feedfbd2 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -37,6 +37,7 @@ ide-core-$(CONFIG_BLK_DEV_Q40IDE) += legacy/q40ide.o
37# built-in only drivers from ppc/ 37# built-in only drivers from ppc/
38ide-core-$(CONFIG_BLK_DEV_MPC8xx_IDE) += ppc/mpc8xx.o 38ide-core-$(CONFIG_BLK_DEV_MPC8xx_IDE) += ppc/mpc8xx.o
39ide-core-$(CONFIG_BLK_DEV_IDE_PMAC) += ppc/pmac.o 39ide-core-$(CONFIG_BLK_DEV_IDE_PMAC) += ppc/pmac.o
40ide-core-$(CONFIG_BLK_DEV_IDE_CELLEB) += ppc/scc_pata.o
40 41
41# built-in only drivers from h8300/ 42# built-in only drivers from h8300/
42ide-core-$(CONFIG_H8300) += h8300/ide-h8300.o 43ide-core-$(CONFIG_H8300) += h8300/ide-h8300.o
diff --git a/drivers/ide/arm/icside.c b/drivers/ide/arm/icside.c
index 8a1c27f286..40e5c66b81 100644
--- a/drivers/ide/arm/icside.c
+++ b/drivers/ide/arm/icside.c
@@ -307,26 +307,24 @@ static int icside_set_speed(ide_drive_t *drive, u8 xfer_mode)
307 return on; 307 return on;
308} 308}
309 309
310static int icside_dma_host_off(ide_drive_t *drive) 310static void icside_dma_host_off(ide_drive_t *drive)
311{ 311{
312 return 0;
313} 312}
314 313
315static int icside_dma_off_quietly(ide_drive_t *drive) 314static void icside_dma_off_quietly(ide_drive_t *drive)
316{ 315{
317 drive->using_dma = 0; 316 drive->using_dma = 0;
318 return icside_dma_host_off(drive);
319} 317}
320 318
321static int icside_dma_host_on(ide_drive_t *drive) 319static void icside_dma_host_on(ide_drive_t *drive)
322{ 320{
323 return 0;
324} 321}
325 322
326static int icside_dma_on(ide_drive_t *drive) 323static int icside_dma_on(ide_drive_t *drive)
327{ 324{
328 drive->using_dma = 1; 325 drive->using_dma = 1;
329 return icside_dma_host_on(drive); 326
327 return 0;
330} 328}
331 329
332static int icside_dma_check(ide_drive_t *drive) 330static int icside_dma_check(ide_drive_t *drive)
@@ -365,10 +363,7 @@ static int icside_dma_check(ide_drive_t *drive)
365out: 363out:
366 on = icside_set_speed(drive, xfer_mode); 364 on = icside_set_speed(drive, xfer_mode);
367 365
368 if (on) 366 return on ? 0 : -1;
369 return icside_dma_on(drive);
370 else
371 return icside_dma_off_quietly(drive);
372} 367}
373 368
374static int icside_dma_end(ide_drive_t *drive) 369static int icside_dma_end(ide_drive_t *drive)
@@ -497,9 +492,9 @@ static void icside_dma_init(ide_hwif_t *hwif)
497 hwif->autodma = autodma; 492 hwif->autodma = autodma;
498 493
499 hwif->ide_dma_check = icside_dma_check; 494 hwif->ide_dma_check = icside_dma_check;
500 hwif->ide_dma_host_off = icside_dma_host_off; 495 hwif->dma_host_off = icside_dma_host_off;
501 hwif->ide_dma_off_quietly = icside_dma_off_quietly; 496 hwif->dma_off_quietly = icside_dma_off_quietly;
502 hwif->ide_dma_host_on = icside_dma_host_on; 497 hwif->dma_host_on = icside_dma_host_on;
503 hwif->ide_dma_on = icside_dma_on; 498 hwif->ide_dma_on = icside_dma_on;
504 hwif->dma_setup = icside_dma_setup; 499 hwif->dma_setup = icside_dma_setup;
505 hwif->dma_exec_cmd = icside_dma_exec_cmd; 500 hwif->dma_exec_cmd = icside_dma_exec_cmd;
@@ -556,7 +551,7 @@ icside_setup(void __iomem *base, struct cardinfo *info, struct expansion_card *e
556 * Ensure we're using MMIO 551 * Ensure we're using MMIO
557 */ 552 */
558 default_hwif_mmiops(hwif); 553 default_hwif_mmiops(hwif);
559 hwif->mmio = 2; 554 hwif->mmio = 1;
560 555
561 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) { 556 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
562 hwif->hw.io_ports[i] = port; 557 hwif->hw.io_ports[i] = port;
diff --git a/drivers/ide/arm/rapide.c b/drivers/ide/arm/rapide.c
index 3058217767..9c6c49fdd2 100644
--- a/drivers/ide/arm/rapide.c
+++ b/drivers/ide/arm/rapide.c
@@ -46,7 +46,7 @@ rapide_locate_hwif(void __iomem *base, void __iomem *ctrl, unsigned int sz, int
46 hwif->hw.io_ports[IDE_CONTROL_OFFSET] = (unsigned long)ctrl; 46 hwif->hw.io_ports[IDE_CONTROL_OFFSET] = (unsigned long)ctrl;
47 hwif->io_ports[IDE_CONTROL_OFFSET] = (unsigned long)ctrl; 47 hwif->io_ports[IDE_CONTROL_OFFSET] = (unsigned long)ctrl;
48 hwif->hw.irq = hwif->irq = irq; 48 hwif->hw.irq = hwif->irq = irq;
49 hwif->mmio = 2; 49 hwif->mmio = 1;
50 default_hwif_mmiops(hwif); 50 default_hwif_mmiops(hwif);
51 51
52 return hwif; 52 return hwif;
diff --git a/drivers/ide/cris/ide-cris.c b/drivers/ide/cris/ide-cris.c
index 5797e0b5a1..556455fbfa 100644
--- a/drivers/ide/cris/ide-cris.c
+++ b/drivers/ide/cris/ide-cris.c
@@ -17,8 +17,6 @@
17 * device can't do DMA handshaking for some stupid reason. We don't need to do that. 17 * device can't do DMA handshaking for some stupid reason. We don't need to do that.
18 */ 18 */
19 19
20#undef REALLY_SLOW_IO /* most systems can safely undef this */
21
22#include <linux/types.h> 20#include <linux/types.h>
23#include <linux/kernel.h> 21#include <linux/kernel.h>
24#include <linux/timer.h> 22#include <linux/timer.h>
@@ -682,9 +680,12 @@ static void cris_ide_input_data (ide_drive_t *drive, void *, unsigned int);
682static void cris_ide_output_data (ide_drive_t *drive, void *, unsigned int); 680static void cris_ide_output_data (ide_drive_t *drive, void *, unsigned int);
683static void cris_atapi_input_bytes(ide_drive_t *drive, void *, unsigned int); 681static void cris_atapi_input_bytes(ide_drive_t *drive, void *, unsigned int);
684static void cris_atapi_output_bytes(ide_drive_t *drive, void *, unsigned int); 682static void cris_atapi_output_bytes(ide_drive_t *drive, void *, unsigned int);
685static int cris_dma_off (ide_drive_t *drive);
686static int cris_dma_on (ide_drive_t *drive); 683static int cris_dma_on (ide_drive_t *drive);
687 684
685static void cris_dma_off(ide_drive_t *drive)
686{
687}
688
688static void tune_cris_ide(ide_drive_t *drive, u8 pio) 689static void tune_cris_ide(ide_drive_t *drive, u8 pio)
689{ 690{
690 int setup, strobe, hold; 691 int setup, strobe, hold;
@@ -795,7 +796,7 @@ init_e100_ide (void)
795 0, 0, cris_ide_ack_intr, 796 0, 0, cris_ide_ack_intr,
796 ide_default_irq(0)); 797 ide_default_irq(0));
797 ide_register_hw(&hw, &hwif); 798 ide_register_hw(&hw, &hwif);
798 hwif->mmio = 2; 799 hwif->mmio = 1;
799 hwif->chipset = ide_etrax100; 800 hwif->chipset = ide_etrax100;
800 hwif->tuneproc = &tune_cris_ide; 801 hwif->tuneproc = &tune_cris_ide;
801 hwif->speedproc = &speed_cris_ide; 802 hwif->speedproc = &speed_cris_ide;
@@ -814,13 +815,16 @@ init_e100_ide (void)
814 hwif->OUTBSYNC = &cris_ide_outbsync; 815 hwif->OUTBSYNC = &cris_ide_outbsync;
815 hwif->INB = &cris_ide_inb; 816 hwif->INB = &cris_ide_inb;
816 hwif->INW = &cris_ide_inw; 817 hwif->INW = &cris_ide_inw;
817 hwif->ide_dma_host_off = &cris_dma_off; 818 hwif->dma_host_off = &cris_dma_off;
818 hwif->ide_dma_host_on = &cris_dma_on; 819 hwif->dma_host_on = &cris_dma_on;
819 hwif->ide_dma_off_quietly = &cris_dma_off; 820 hwif->dma_off_quietly = &cris_dma_off;
820 hwif->udma_four = 0; 821 hwif->udma_four = 0;
821 hwif->ultra_mask = cris_ultra_mask; 822 hwif->ultra_mask = cris_ultra_mask;
822 hwif->mwdma_mask = 0x07; /* Multiword DMA 0-2 */ 823 hwif->mwdma_mask = 0x07; /* Multiword DMA 0-2 */
823 hwif->swdma_mask = 0x07; /* Singleword DMA 0-2 */ 824 hwif->swdma_mask = 0x07; /* Singleword DMA 0-2 */
825 hwif->autodma = 1;
826 hwif->drives[0].autodma = 1;
827 hwif->drives[1].autodma = 1;
824 } 828 }
825 829
826 /* Reset pulse */ 830 /* Reset pulse */
@@ -835,11 +839,6 @@ init_e100_ide (void)
835 cris_ide_set_speed(TYPE_UDMA, ATA_UDMA2_CYC, ATA_UDMA2_DVS, 0); 839 cris_ide_set_speed(TYPE_UDMA, ATA_UDMA2_CYC, ATA_UDMA2_DVS, 0);
836} 840}
837 841
838static int cris_dma_off (ide_drive_t *drive)
839{
840 return 0;
841}
842
843static int cris_dma_on (ide_drive_t *drive) 842static int cris_dma_on (ide_drive_t *drive)
844{ 843{
845 return 0; 844 return 0;
@@ -1045,17 +1044,10 @@ static ide_startstop_t cris_dma_intr (ide_drive_t *drive)
1045 1044
1046static int cris_dma_check(ide_drive_t *drive) 1045static int cris_dma_check(ide_drive_t *drive)
1047{ 1046{
1048 ide_hwif_t *hwif = drive->hwif; 1047 if (ide_use_dma(drive) && cris_config_drive_for_dma(drive))
1049 struct hd_driveid* id = drive->id; 1048 return 0;
1050
1051 if (id && (id->capability & 1)) {
1052 if (ide_use_dma(drive)) {
1053 if (cris_config_drive_for_dma(drive))
1054 return hwif->ide_dma_on(drive);
1055 }
1056 }
1057 1049
1058 return hwif->ide_dma_off_quietly(drive); 1050 return -1;
1059} 1051}
1060 1052
1061static int cris_dma_end(ide_drive_t *drive) 1053static int cris_dma_end(ide_drive_t *drive)
diff --git a/drivers/ide/h8300/ide-h8300.c b/drivers/ide/h8300/ide-h8300.c
index 608ca87174..88750a3003 100644
--- a/drivers/ide/h8300/ide-h8300.c
+++ b/drivers/ide/h8300/ide-h8300.c
@@ -76,13 +76,11 @@ static inline void hwif_setup(ide_hwif_t *hwif)
76{ 76{
77 default_hwif_iops(hwif); 77 default_hwif_iops(hwif);
78 78
79 hwif->mmio = 2; 79 hwif->mmio = 1;
80 hwif->OUTW = mm_outw; 80 hwif->OUTW = mm_outw;
81 hwif->OUTSW = mm_outsw; 81 hwif->OUTSW = mm_outsw;
82 hwif->INW = mm_inw; 82 hwif->INW = mm_inw;
83 hwif->INSW = mm_insw; 83 hwif->INSW = mm_insw;
84 hwif->OUTL = NULL;
85 hwif->INL = NULL;
86 hwif->OUTSL = NULL; 84 hwif->OUTSL = NULL;
87 hwif->INSL = NULL; 85 hwif->INSL = NULL;
88} 86}
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 5969cec58d..45a928c058 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -687,15 +687,8 @@ static void ide_dump_status_no_sense(ide_drive_t *drive, const char *msg, u8 sta
687static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) 687static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
688{ 688{
689 struct request *rq = HWGROUP(drive)->rq; 689 struct request *rq = HWGROUP(drive)->rq;
690 ide_hwif_t *hwif = HWIF(drive);
691 int stat, err, sense_key; 690 int stat, err, sense_key;
692 691
693 /* We may have bogus DMA interrupts in PIO state here */
694 if (HWIF(drive)->dma_status && hwif->atapi_irq_bogon) {
695 stat = hwif->INB(hwif->dma_status);
696 /* Should we force the bit as well ? */
697 hwif->OUTB(stat, hwif->dma_status);
698 }
699 /* Check for errors. */ 692 /* Check for errors. */
700 stat = HWIF(drive)->INB(IDE_STATUS_REG); 693 stat = HWIF(drive)->INB(IDE_STATUS_REG);
701 if (stat_ret) 694 if (stat_ret)
@@ -930,6 +923,10 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive,
930 HWIF(drive)->OUTB(drive->ctl, IDE_CONTROL_REG); 923 HWIF(drive)->OUTB(drive->ctl, IDE_CONTROL_REG);
931 924
932 if (CDROM_CONFIG_FLAGS (drive)->drq_interrupt) { 925 if (CDROM_CONFIG_FLAGS (drive)->drq_interrupt) {
926 /* waiting for CDB interrupt, not DMA yet. */
927 if (info->dma)
928 drive->waiting_for_dma = 0;
929
933 /* packet command */ 930 /* packet command */
934 ide_execute_command(drive, WIN_PACKETCMD, handler, ATAPI_WAIT_PC, cdrom_timer_expiry); 931 ide_execute_command(drive, WIN_PACKETCMD, handler, ATAPI_WAIT_PC, cdrom_timer_expiry);
935 return ide_started; 932 return ide_started;
@@ -972,6 +969,10 @@ static ide_startstop_t cdrom_transfer_packet_command (ide_drive_t *drive,
972 /* Check for errors. */ 969 /* Check for errors. */
973 if (cdrom_decode_status(drive, DRQ_STAT, NULL)) 970 if (cdrom_decode_status(drive, DRQ_STAT, NULL))
974 return ide_stopped; 971 return ide_stopped;
972
973 /* Ok, next interrupt will be DMA interrupt. */
974 if (info->dma)
975 drive->waiting_for_dma = 1;
975 } else { 976 } else {
976 /* Otherwise, we must wait for DRQ to get set. */ 977 /* Otherwise, we must wait for DRQ to get set. */
977 if (ide_wait_stat(&startstop, drive, DRQ_STAT, 978 if (ide_wait_stat(&startstop, drive, DRQ_STAT,
@@ -1103,7 +1104,7 @@ static ide_startstop_t cdrom_read_intr (ide_drive_t *drive)
1103 if (dma) { 1104 if (dma) {
1104 info->dma = 0; 1105 info->dma = 0;
1105 if ((dma_error = HWIF(drive)->ide_dma_end(drive))) 1106 if ((dma_error = HWIF(drive)->ide_dma_end(drive)))
1106 __ide_dma_off(drive); 1107 ide_dma_off(drive);
1107 } 1108 }
1108 1109
1109 if (cdrom_decode_status(drive, 0, &stat)) 1110 if (cdrom_decode_status(drive, 0, &stat))
@@ -1699,7 +1700,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1699 if (dma) { 1700 if (dma) {
1700 if (dma_error) { 1701 if (dma_error) {
1701 printk(KERN_ERR "ide-cd: dma error\n"); 1702 printk(KERN_ERR "ide-cd: dma error\n");
1702 __ide_dma_off(drive); 1703 ide_dma_off(drive);
1703 return ide_error(drive, "dma error", stat); 1704 return ide_error(drive, "dma error", stat);
1704 } 1705 }
1705 1706
@@ -1825,7 +1826,7 @@ static ide_startstop_t cdrom_write_intr(ide_drive_t *drive)
1825 info->dma = 0; 1826 info->dma = 0;
1826 if ((dma_error = HWIF(drive)->ide_dma_end(drive))) { 1827 if ((dma_error = HWIF(drive)->ide_dma_end(drive))) {
1827 printk(KERN_ERR "ide-cd: write dma error\n"); 1828 printk(KERN_ERR "ide-cd: write dma error\n");
1828 __ide_dma_off(drive); 1829 ide_dma_off(drive);
1829 } 1830 }
1830 } 1831 }
1831 1832
@@ -3254,14 +3255,6 @@ int ide_cdrom_setup (ide_drive_t *drive)
3254 if (drive->autotune == IDE_TUNE_DEFAULT || 3255 if (drive->autotune == IDE_TUNE_DEFAULT ||
3255 drive->autotune == IDE_TUNE_AUTO) 3256 drive->autotune == IDE_TUNE_AUTO)
3256 drive->dsc_overlap = (drive->next != drive); 3257 drive->dsc_overlap = (drive->next != drive);
3257#if 0
3258 drive->dsc_overlap = (HWIF(drive)->no_dsc) ? 0 : 1;
3259 if (HWIF(drive)->no_dsc) {
3260 printk(KERN_INFO "ide-cd: %s: disabling DSC overlap\n",
3261 drive->name);
3262 drive->dsc_overlap = 0;
3263 }
3264#endif
3265 3258
3266 if (ide_cdrom_register(drive, nslots)) { 3259 if (ide_cdrom_register(drive, nslots)) {
3267 printk (KERN_ERR "%s: ide_cdrom_setup failed to register device with the cdrom driver.\n", drive->name); 3260 printk (KERN_ERR "%s: ide_cdrom_setup failed to register device with the cdrom driver.\n", drive->name);
@@ -3360,21 +3353,16 @@ static int idecd_open(struct inode * inode, struct file * file)
3360{ 3353{
3361 struct gendisk *disk = inode->i_bdev->bd_disk; 3354 struct gendisk *disk = inode->i_bdev->bd_disk;
3362 struct cdrom_info *info; 3355 struct cdrom_info *info;
3363 ide_drive_t *drive;
3364 int rc = -ENOMEM; 3356 int rc = -ENOMEM;
3365 3357
3366 if (!(info = ide_cd_get(disk))) 3358 if (!(info = ide_cd_get(disk)))
3367 return -ENXIO; 3359 return -ENXIO;
3368 3360
3369 drive = info->drive;
3370
3371 drive->usage++;
3372
3373 if (!info->buffer) 3361 if (!info->buffer)
3374 info->buffer = kmalloc(SECTOR_BUFFER_SIZE, 3362 info->buffer = kmalloc(SECTOR_BUFFER_SIZE, GFP_KERNEL|__GFP_REPEAT);
3375 GFP_KERNEL|__GFP_REPEAT); 3363
3376 if (!info->buffer || (rc = cdrom_open(&info->devinfo, inode, file))) 3364 if (info->buffer)
3377 drive->usage--; 3365 rc = cdrom_open(&info->devinfo, inode, file);
3378 3366
3379 if (rc < 0) 3367 if (rc < 0)
3380 ide_cd_put(info); 3368 ide_cd_put(info);
@@ -3386,10 +3374,8 @@ static int idecd_release(struct inode * inode, struct file * file)
3386{ 3374{
3387 struct gendisk *disk = inode->i_bdev->bd_disk; 3375 struct gendisk *disk = inode->i_bdev->bd_disk;
3388 struct cdrom_info *info = ide_cd_g(disk); 3376 struct cdrom_info *info = ide_cd_g(disk);
3389 ide_drive_t *drive = info->drive;
3390 3377
3391 cdrom_release (&info->devinfo, file); 3378 cdrom_release (&info->devinfo, file);
3392 drive->usage--;
3393 3379
3394 ide_cd_put(info); 3380 ide_cd_put(info);
3395 3381
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 0a05a377d6..37aa6ddd97 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -43,8 +43,6 @@
43 43
44#define IDEDISK_VERSION "1.18" 44#define IDEDISK_VERSION "1.18"
45 45
46#undef REALLY_SLOW_IO /* most systems can safely undef this */
47
48//#define DEBUG 46//#define DEBUG
49 47
50#include <linux/module.h> 48#include <linux/module.h>
@@ -77,6 +75,7 @@ struct ide_disk_obj {
77 ide_driver_t *driver; 75 ide_driver_t *driver;
78 struct gendisk *disk; 76 struct gendisk *disk;
79 struct kref kref; 77 struct kref kref;
78 unsigned int openers; /* protected by BKL for now */
80}; 79};
81 80
82static DEFINE_MUTEX(idedisk_ref_mutex); 81static DEFINE_MUTEX(idedisk_ref_mutex);
@@ -1081,8 +1080,9 @@ static int idedisk_open(struct inode *inode, struct file *filp)
1081 1080
1082 drive = idkp->drive; 1081 drive = idkp->drive;
1083 1082
1084 drive->usage++; 1083 idkp->openers++;
1085 if (drive->removable && drive->usage == 1) { 1084
1085 if (drive->removable && idkp->openers == 1) {
1086 ide_task_t args; 1086 ide_task_t args;
1087 memset(&args, 0, sizeof(ide_task_t)); 1087 memset(&args, 0, sizeof(ide_task_t));
1088 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_DOORLOCK; 1088 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_DOORLOCK;
@@ -1106,9 +1106,10 @@ static int idedisk_release(struct inode *inode, struct file *filp)
1106 struct ide_disk_obj *idkp = ide_disk_g(disk); 1106 struct ide_disk_obj *idkp = ide_disk_g(disk);
1107 ide_drive_t *drive = idkp->drive; 1107 ide_drive_t *drive = idkp->drive;
1108 1108
1109 if (drive->usage == 1) 1109 if (idkp->openers == 1)
1110 ide_cacheflush_p(drive); 1110 ide_cacheflush_p(drive);
1111 if (drive->removable && drive->usage == 1) { 1111
1112 if (drive->removable && idkp->openers == 1) {
1112 ide_task_t args; 1113 ide_task_t args;
1113 memset(&args, 0, sizeof(ide_task_t)); 1114 memset(&args, 0, sizeof(ide_task_t));
1114 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_DOORUNLOCK; 1115 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_DOORUNLOCK;
@@ -1117,7 +1118,8 @@ static int idedisk_release(struct inode *inode, struct file *filp)
1117 if (drive->doorlocking && ide_raw_taskfile(drive, &args, NULL)) 1118 if (drive->doorlocking && ide_raw_taskfile(drive, &args, NULL))
1118 drive->doorlocking = 0; 1119 drive->doorlocking = 0;
1119 } 1120 }
1120 drive->usage--; 1121
1122 idkp->openers--;
1121 1123
1122 ide_disk_put(idkp); 1124 ide_disk_put(idkp);
1123 1125
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index 56efed6742..08e7cd043b 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -348,15 +348,14 @@ EXPORT_SYMBOL_GPL(ide_destroy_dmatable);
348static int config_drive_for_dma (ide_drive_t *drive) 348static int config_drive_for_dma (ide_drive_t *drive)
349{ 349{
350 struct hd_driveid *id = drive->id; 350 struct hd_driveid *id = drive->id;
351 ide_hwif_t *hwif = HWIF(drive);
352 351
353 if ((id->capability & 1) && hwif->autodma) { 352 if ((id->capability & 1) && drive->hwif->autodma) {
354 /* 353 /*
355 * Enable DMA on any drive that has 354 * Enable DMA on any drive that has
356 * UltraDMA (mode 0/1/2/3/4/5/6) enabled 355 * UltraDMA (mode 0/1/2/3/4/5/6) enabled
357 */ 356 */
358 if ((id->field_valid & 4) && ((id->dma_ultra >> 8) & 0x7f)) 357 if ((id->field_valid & 4) && ((id->dma_ultra >> 8) & 0x7f))
359 return hwif->ide_dma_on(drive); 358 return 0;
360 /* 359 /*
361 * Enable DMA on any drive that has mode2 DMA 360 * Enable DMA on any drive that has mode2 DMA
362 * (multi or single) enabled 361 * (multi or single) enabled
@@ -364,14 +363,14 @@ static int config_drive_for_dma (ide_drive_t *drive)
364 if (id->field_valid & 2) /* regular DMA */ 363 if (id->field_valid & 2) /* regular DMA */
365 if ((id->dma_mword & 0x404) == 0x404 || 364 if ((id->dma_mword & 0x404) == 0x404 ||
366 (id->dma_1word & 0x404) == 0x404) 365 (id->dma_1word & 0x404) == 0x404)
367 return hwif->ide_dma_on(drive); 366 return 0;
368 367
369 /* Consult the list of known "good" drives */ 368 /* Consult the list of known "good" drives */
370 if (__ide_dma_good_drive(drive)) 369 if (__ide_dma_good_drive(drive))
371 return hwif->ide_dma_on(drive); 370 return 0;
372 } 371 }
373// if (hwif->tuneproc != NULL) hwif->tuneproc(drive, 255); 372
374 return hwif->ide_dma_off_quietly(drive); 373 return -1;
375} 374}
376 375
377/** 376/**
@@ -415,72 +414,68 @@ static int dma_timer_expiry (ide_drive_t *drive)
415} 414}
416 415
417/** 416/**
418 * __ide_dma_host_off - Generic DMA kill 417 * ide_dma_host_off - Generic DMA kill
419 * @drive: drive to control 418 * @drive: drive to control
420 * 419 *
421 * Perform the generic IDE controller DMA off operation. This 420 * Perform the generic IDE controller DMA off operation. This
422 * works for most IDE bus mastering controllers 421 * works for most IDE bus mastering controllers
423 */ 422 */
424 423
425int __ide_dma_host_off (ide_drive_t *drive) 424void ide_dma_host_off(ide_drive_t *drive)
426{ 425{
427 ide_hwif_t *hwif = HWIF(drive); 426 ide_hwif_t *hwif = HWIF(drive);
428 u8 unit = (drive->select.b.unit & 0x01); 427 u8 unit = (drive->select.b.unit & 0x01);
429 u8 dma_stat = hwif->INB(hwif->dma_status); 428 u8 dma_stat = hwif->INB(hwif->dma_status);
430 429
431 hwif->OUTB((dma_stat & ~(1<<(5+unit))), hwif->dma_status); 430 hwif->OUTB((dma_stat & ~(1<<(5+unit))), hwif->dma_status);
432 return 0;
433} 431}
434 432
435EXPORT_SYMBOL(__ide_dma_host_off); 433EXPORT_SYMBOL(ide_dma_host_off);
436 434
437/** 435/**
438 * __ide_dma_host_off_quietly - Generic DMA kill 436 * ide_dma_off_quietly - Generic DMA kill
439 * @drive: drive to control 437 * @drive: drive to control
440 * 438 *
441 * Turn off the current DMA on this IDE controller. 439 * Turn off the current DMA on this IDE controller.
442 */ 440 */
443 441
444int __ide_dma_off_quietly (ide_drive_t *drive) 442void ide_dma_off_quietly(ide_drive_t *drive)
445{ 443{
446 drive->using_dma = 0; 444 drive->using_dma = 0;
447 ide_toggle_bounce(drive, 0); 445 ide_toggle_bounce(drive, 0);
448 446
449 if (HWIF(drive)->ide_dma_host_off(drive)) 447 drive->hwif->dma_host_off(drive);
450 return 1;
451
452 return 0;
453} 448}
454 449
455EXPORT_SYMBOL(__ide_dma_off_quietly); 450EXPORT_SYMBOL(ide_dma_off_quietly);
456#endif /* CONFIG_BLK_DEV_IDEDMA_PCI */ 451#endif /* CONFIG_BLK_DEV_IDEDMA_PCI */
457 452
458/** 453/**
459 * __ide_dma_off - disable DMA on a device 454 * ide_dma_off - disable DMA on a device
460 * @drive: drive to disable DMA on 455 * @drive: drive to disable DMA on
461 * 456 *
462 * Disable IDE DMA for a device on this IDE controller. 457 * Disable IDE DMA for a device on this IDE controller.
463 * Inform the user that DMA has been disabled. 458 * Inform the user that DMA has been disabled.
464 */ 459 */
465 460
466int __ide_dma_off (ide_drive_t *drive) 461void ide_dma_off(ide_drive_t *drive)
467{ 462{
468 printk(KERN_INFO "%s: DMA disabled\n", drive->name); 463 printk(KERN_INFO "%s: DMA disabled\n", drive->name);
469 return HWIF(drive)->ide_dma_off_quietly(drive); 464 drive->hwif->dma_off_quietly(drive);
470} 465}
471 466
472EXPORT_SYMBOL(__ide_dma_off); 467EXPORT_SYMBOL(ide_dma_off);
473 468
474#ifdef CONFIG_BLK_DEV_IDEDMA_PCI 469#ifdef CONFIG_BLK_DEV_IDEDMA_PCI
475/** 470/**
476 * __ide_dma_host_on - Enable DMA on a host 471 * ide_dma_host_on - Enable DMA on a host
477 * @drive: drive to enable for DMA 472 * @drive: drive to enable for DMA
478 * 473 *
479 * Enable DMA on an IDE controller following generic bus mastering 474 * Enable DMA on an IDE controller following generic bus mastering
480 * IDE controller behaviour 475 * IDE controller behaviour
481 */ 476 */
482 477
483int __ide_dma_host_on (ide_drive_t *drive) 478void ide_dma_host_on(ide_drive_t *drive)
484{ 479{
485 if (drive->using_dma) { 480 if (drive->using_dma) {
486 ide_hwif_t *hwif = HWIF(drive); 481 ide_hwif_t *hwif = HWIF(drive);
@@ -488,12 +483,10 @@ int __ide_dma_host_on (ide_drive_t *drive)
488 u8 dma_stat = hwif->INB(hwif->dma_status); 483 u8 dma_stat = hwif->INB(hwif->dma_status);
489 484
490 hwif->OUTB((dma_stat|(1<<(5+unit))), hwif->dma_status); 485 hwif->OUTB((dma_stat|(1<<(5+unit))), hwif->dma_status);
491 return 0;
492 } 486 }
493 return 1;
494} 487}
495 488
496EXPORT_SYMBOL(__ide_dma_host_on); 489EXPORT_SYMBOL(ide_dma_host_on);
497 490
498/** 491/**
499 * __ide_dma_on - Enable DMA on a device 492 * __ide_dma_on - Enable DMA on a device
@@ -511,8 +504,7 @@ int __ide_dma_on (ide_drive_t *drive)
511 drive->using_dma = 1; 504 drive->using_dma = 1;
512 ide_toggle_bounce(drive, 1); 505 ide_toggle_bounce(drive, 1);
513 506
514 if (HWIF(drive)->ide_dma_host_on(drive)) 507 drive->hwif->dma_host_on(drive);
515 return 1;
516 508
517 return 0; 509 return 0;
518} 510}
@@ -565,7 +557,10 @@ int ide_dma_setup(ide_drive_t *drive)
565 } 557 }
566 558
567 /* PRD table */ 559 /* PRD table */
568 hwif->OUTL(hwif->dmatable_dma, hwif->dma_prdtable); 560 if (hwif->mmio)
561 writel(hwif->dmatable_dma, (void __iomem *)hwif->dma_prdtable);
562 else
563 outl(hwif->dmatable_dma, hwif->dma_prdtable);
569 564
570 /* specify r/w */ 565 /* specify r/w */
571 hwif->OUTB(reading, hwif->dma_command); 566 hwif->OUTB(reading, hwif->dma_command);
@@ -680,6 +675,9 @@ int ide_use_dma(ide_drive_t *drive)
680 struct hd_driveid *id = drive->id; 675 struct hd_driveid *id = drive->id;
681 ide_hwif_t *hwif = drive->hwif; 676 ide_hwif_t *hwif = drive->hwif;
682 677
678 if ((id->capability & 1) == 0 || drive->autodma == 0)
679 return 0;
680
683 /* consult the list of known "bad" drives */ 681 /* consult the list of known "bad" drives */
684 if (__ide_dma_bad_drive(drive)) 682 if (__ide_dma_bad_drive(drive))
685 return 0; 683 return 0;
@@ -753,12 +751,37 @@ void ide_dma_verbose(ide_drive_t *drive)
753 return; 751 return;
754bug_dma_off: 752bug_dma_off:
755 printk(", BUG DMA OFF"); 753 printk(", BUG DMA OFF");
756 hwif->ide_dma_off_quietly(drive); 754 hwif->dma_off_quietly(drive);
757 return; 755 return;
758} 756}
759 757
760EXPORT_SYMBOL(ide_dma_verbose); 758EXPORT_SYMBOL(ide_dma_verbose);
761 759
760int ide_set_dma(ide_drive_t *drive)
761{
762 ide_hwif_t *hwif = drive->hwif;
763 int rc;
764
765 rc = hwif->ide_dma_check(drive);
766
767 switch(rc) {
768 case -1: /* DMA needs to be disabled */
769 hwif->dma_off_quietly(drive);
770 return 0;
771 case 0: /* DMA needs to be enabled */
772 return hwif->ide_dma_on(drive);
773 case 1: /* DMA setting cannot be changed */
774 break;
775 default:
776 BUG();
777 break;
778 }
779
780 return rc;
781}
782
783EXPORT_SYMBOL_GPL(ide_set_dma);
784
762#ifdef CONFIG_BLK_DEV_IDEDMA_PCI 785#ifdef CONFIG_BLK_DEV_IDEDMA_PCI
763int __ide_dma_lostirq (ide_drive_t *drive) 786int __ide_dma_lostirq (ide_drive_t *drive)
764{ 787{
@@ -809,7 +832,7 @@ int ide_release_dma(ide_hwif_t *hwif)
809{ 832{
810 ide_release_dma_engine(hwif); 833 ide_release_dma_engine(hwif);
811 834
812 if (hwif->mmio == 2) 835 if (hwif->mmio)
813 return 1; 836 return 1;
814 else 837 else
815 return ide_release_iomio_dma(hwif); 838 return ide_release_iomio_dma(hwif);
@@ -878,9 +901,9 @@ static int ide_iomio_dma(ide_hwif_t *hwif, unsigned long base, unsigned int port
878 901
879static int ide_dma_iobase(ide_hwif_t *hwif, unsigned long base, unsigned int ports) 902static int ide_dma_iobase(ide_hwif_t *hwif, unsigned long base, unsigned int ports)
880{ 903{
881 if (hwif->mmio == 2) 904 if (hwif->mmio)
882 return ide_mapped_mmio_dma(hwif, base,ports); 905 return ide_mapped_mmio_dma(hwif, base,ports);
883 BUG_ON(hwif->mmio == 1); 906
884 return ide_iomio_dma(hwif, base, ports); 907 return ide_iomio_dma(hwif, base, ports);
885} 908}
886 909
@@ -908,14 +931,14 @@ void ide_setup_dma (ide_hwif_t *hwif, unsigned long dma_base, unsigned int num_p
908 if (!(hwif->dma_prdtable)) 931 if (!(hwif->dma_prdtable))
909 hwif->dma_prdtable = (hwif->dma_base + 4); 932 hwif->dma_prdtable = (hwif->dma_base + 4);
910 933
911 if (!hwif->ide_dma_off_quietly) 934 if (!hwif->dma_off_quietly)
912 hwif->ide_dma_off_quietly = &__ide_dma_off_quietly; 935 hwif->dma_off_quietly = &ide_dma_off_quietly;
913 if (!hwif->ide_dma_host_off) 936 if (!hwif->dma_host_off)
914 hwif->ide_dma_host_off = &__ide_dma_host_off; 937 hwif->dma_host_off = &ide_dma_host_off;
915 if (!hwif->ide_dma_on) 938 if (!hwif->ide_dma_on)
916 hwif->ide_dma_on = &__ide_dma_on; 939 hwif->ide_dma_on = &__ide_dma_on;
917 if (!hwif->ide_dma_host_on) 940 if (!hwif->dma_host_on)
918 hwif->ide_dma_host_on = &__ide_dma_host_on; 941 hwif->dma_host_on = &ide_dma_host_on;
919 if (!hwif->ide_dma_check) 942 if (!hwif->ide_dma_check)
920 hwif->ide_dma_check = &__ide_dma_check; 943 hwif->ide_dma_check = &__ide_dma_check;
921 if (!hwif->dma_setup) 944 if (!hwif->dma_setup)
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index d33717c8af..57cd21c5b2 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -279,6 +279,7 @@ typedef struct ide_floppy_obj {
279 ide_driver_t *driver; 279 ide_driver_t *driver;
280 struct gendisk *disk; 280 struct gendisk *disk;
281 struct kref kref; 281 struct kref kref;
282 unsigned int openers; /* protected by BKL for now */
282 283
283 /* Current packet command */ 284 /* Current packet command */
284 idefloppy_pc_t *pc; 285 idefloppy_pc_t *pc;
@@ -866,7 +867,7 @@ static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive)
866 if (test_and_clear_bit(PC_DMA_IN_PROGRESS, &pc->flags)) { 867 if (test_and_clear_bit(PC_DMA_IN_PROGRESS, &pc->flags)) {
867 printk(KERN_ERR "ide-floppy: The floppy wants to issue " 868 printk(KERN_ERR "ide-floppy: The floppy wants to issue "
868 "more interrupts in DMA mode\n"); 869 "more interrupts in DMA mode\n");
869 (void)__ide_dma_off(drive); 870 ide_dma_off(drive);
870 return ide_do_reset(drive); 871 return ide_do_reset(drive);
871 } 872 }
872 873
@@ -1096,9 +1097,9 @@ static ide_startstop_t idefloppy_issue_pc (ide_drive_t *drive, idefloppy_pc_t *p
1096 pc->current_position = pc->buffer; 1097 pc->current_position = pc->buffer;
1097 bcount.all = min(pc->request_transfer, 63 * 1024); 1098 bcount.all = min(pc->request_transfer, 63 * 1024);
1098 1099
1099 if (test_and_clear_bit(PC_DMA_ERROR, &pc->flags)) { 1100 if (test_and_clear_bit(PC_DMA_ERROR, &pc->flags))
1100 (void)__ide_dma_off(drive); 1101 ide_dma_off(drive);
1101 } 1102
1102 feature.all = 0; 1103 feature.all = 0;
1103 1104
1104 if (test_bit(PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma) 1105 if (test_bit(PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma)
@@ -1433,7 +1434,8 @@ static int idefloppy_get_capacity (ide_drive_t *drive)
1433 1434
1434 drive->bios_cyl = 0; 1435 drive->bios_cyl = 0;
1435 drive->bios_head = drive->bios_sect = 0; 1436 drive->bios_head = drive->bios_sect = 0;
1436 floppy->blocks = floppy->bs_factor = 0; 1437 floppy->blocks = 0;
1438 floppy->bs_factor = 1;
1437 set_capacity(floppy->disk, 0); 1439 set_capacity(floppy->disk, 0);
1438 1440
1439 idefloppy_create_read_capacity_cmd(&pc); 1441 idefloppy_create_read_capacity_cmd(&pc);
@@ -1949,9 +1951,9 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
1949 1951
1950 drive = floppy->drive; 1952 drive = floppy->drive;
1951 1953
1952 drive->usage++; 1954 floppy->openers++;
1953 1955
1954 if (drive->usage == 1) { 1956 if (floppy->openers == 1) {
1955 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags); 1957 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1956 /* Just in case */ 1958 /* Just in case */
1957 1959
@@ -1969,13 +1971,11 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
1969 ** capacity of the drive or begin the format - Sam 1971 ** capacity of the drive or begin the format - Sam
1970 */ 1972 */
1971 ) { 1973 ) {
1972 drive->usage--;
1973 ret = -EIO; 1974 ret = -EIO;
1974 goto out_put_floppy; 1975 goto out_put_floppy;
1975 } 1976 }
1976 1977
1977 if (floppy->wp && (filp->f_mode & 2)) { 1978 if (floppy->wp && (filp->f_mode & 2)) {
1978 drive->usage--;
1979 ret = -EROFS; 1979 ret = -EROFS;
1980 goto out_put_floppy; 1980 goto out_put_floppy;
1981 } 1981 }
@@ -1987,13 +1987,13 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
1987 } 1987 }
1988 check_disk_change(inode->i_bdev); 1988 check_disk_change(inode->i_bdev);
1989 } else if (test_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags)) { 1989 } else if (test_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags)) {
1990 drive->usage--;
1991 ret = -EBUSY; 1990 ret = -EBUSY;
1992 goto out_put_floppy; 1991 goto out_put_floppy;
1993 } 1992 }
1994 return 0; 1993 return 0;
1995 1994
1996out_put_floppy: 1995out_put_floppy:
1996 floppy->openers--;
1997 ide_floppy_put(floppy); 1997 ide_floppy_put(floppy);
1998 return ret; 1998 return ret;
1999} 1999}
@@ -2007,7 +2007,7 @@ static int idefloppy_release(struct inode *inode, struct file *filp)
2007 2007
2008 debug_log(KERN_INFO "Reached idefloppy_release\n"); 2008 debug_log(KERN_INFO "Reached idefloppy_release\n");
2009 2009
2010 if (drive->usage == 1) { 2010 if (floppy->openers == 1) {
2011 /* IOMEGA Clik! drives do not support lock/unlock commands */ 2011 /* IOMEGA Clik! drives do not support lock/unlock commands */
2012 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) { 2012 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
2013 idefloppy_create_prevent_cmd(&pc, 0); 2013 idefloppy_create_prevent_cmd(&pc, 0);
@@ -2016,7 +2016,8 @@ static int idefloppy_release(struct inode *inode, struct file *filp)
2016 2016
2017 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags); 2017 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
2018 } 2018 }
2019 drive->usage--; 2019
2020 floppy->openers--;
2020 2021
2021 ide_floppy_put(floppy); 2022 ide_floppy_put(floppy);
2022 2023
@@ -2050,7 +2051,7 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file,
2050 prevent = 0; 2051 prevent = 0;
2051 /* fall through */ 2052 /* fall through */
2052 case CDROM_LOCKDOOR: 2053 case CDROM_LOCKDOOR:
2053 if (drive->usage > 1) 2054 if (floppy->openers > 1)
2054 return -EBUSY; 2055 return -EBUSY;
2055 2056
2056 /* The IOMEGA Clik! Drive doesn't support this command - no room for an eject mechanism */ 2057 /* The IOMEGA Clik! Drive doesn't support this command - no room for an eject mechanism */
@@ -2072,7 +2073,7 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file,
2072 if (!(file->f_mode & 2)) 2073 if (!(file->f_mode & 2))
2073 return -EPERM; 2074 return -EPERM;
2074 2075
2075 if (drive->usage > 1) { 2076 if (floppy->openers > 1) {
2076 /* Don't format if someone is using the disk */ 2077 /* Don't format if someone is using the disk */
2077 2078
2078 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, 2079 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS,
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 2614f41b50..c193553f6f 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -226,7 +226,7 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
226 break; 226 break;
227 if (drive->hwif->ide_dma_check == NULL) 227 if (drive->hwif->ide_dma_check == NULL)
228 break; 228 break;
229 drive->hwif->ide_dma_check(drive); 229 ide_set_dma(drive);
230 break; 230 break;
231 } 231 }
232 pm->pm_step = ide_pm_state_completed; 232 pm->pm_step = ide_pm_state_completed;
@@ -1351,7 +1351,7 @@ static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
1351 */ 1351 */
1352 drive->retry_pio++; 1352 drive->retry_pio++;
1353 drive->state = DMA_PIO_RETRY; 1353 drive->state = DMA_PIO_RETRY;
1354 (void) hwif->ide_dma_off_quietly(drive); 1354 hwif->dma_off_quietly(drive);
1355 1355
1356 /* 1356 /*
1357 * un-busy drive etc (hwgroup->busy is cleared on return) and 1357 * un-busy drive etc (hwgroup->busy is cleared on return) and
@@ -1646,6 +1646,17 @@ irqreturn_t ide_intr (int irq, void *dev_id)
1646 del_timer(&hwgroup->timer); 1646 del_timer(&hwgroup->timer);
1647 spin_unlock(&ide_lock); 1647 spin_unlock(&ide_lock);
1648 1648
1649 /* Some controllers might set DMA INTR no matter DMA or PIO;
1650 * bmdma status might need to be cleared even for
1651 * PIO interrupts to prevent spurious/lost irq.
1652 */
1653 if (hwif->ide_dma_clear_irq && !(drive->waiting_for_dma))
1654 /* ide_dma_end() needs bmdma status for error checking.
1655 * So, skip clearing bmdma status here and leave it
1656 * to ide_dma_end() if this is dma interrupt.
1657 */
1658 hwif->ide_dma_clear_irq(drive);
1659
1649 if (drive->unmask) 1660 if (drive->unmask)
1650 local_irq_enable_in_hardirq(); 1661 local_irq_enable_in_hardirq();
1651 /* service this interrupt, may set handler for next interrupt */ 1662 /* service this interrupt, may set handler for next interrupt */
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index badde63317..bd513f5a23 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -49,11 +49,6 @@ static void ide_insw (unsigned long port, void *addr, u32 count)
49 insw(port, addr, count); 49 insw(port, addr, count);
50} 50}
51 51
52static u32 ide_inl (unsigned long port)
53{
54 return (u32) inl(port);
55}
56
57static void ide_insl (unsigned long port, void *addr, u32 count) 52static void ide_insl (unsigned long port, void *addr, u32 count)
58{ 53{
59 insl(port, addr, count); 54 insl(port, addr, count);
@@ -79,11 +74,6 @@ static void ide_outsw (unsigned long port, void *addr, u32 count)
79 outsw(port, addr, count); 74 outsw(port, addr, count);
80} 75}
81 76
82static void ide_outl (u32 val, unsigned long port)
83{
84 outl(val, port);
85}
86
87static void ide_outsl (unsigned long port, void *addr, u32 count) 77static void ide_outsl (unsigned long port, void *addr, u32 count)
88{ 78{
89 outsl(port, addr, count); 79 outsl(port, addr, count);
@@ -94,12 +84,10 @@ void default_hwif_iops (ide_hwif_t *hwif)
94 hwif->OUTB = ide_outb; 84 hwif->OUTB = ide_outb;
95 hwif->OUTBSYNC = ide_outbsync; 85 hwif->OUTBSYNC = ide_outbsync;
96 hwif->OUTW = ide_outw; 86 hwif->OUTW = ide_outw;
97 hwif->OUTL = ide_outl;
98 hwif->OUTSW = ide_outsw; 87 hwif->OUTSW = ide_outsw;
99 hwif->OUTSL = ide_outsl; 88 hwif->OUTSL = ide_outsl;
100 hwif->INB = ide_inb; 89 hwif->INB = ide_inb;
101 hwif->INW = ide_inw; 90 hwif->INW = ide_inw;
102 hwif->INL = ide_inl;
103 hwif->INSW = ide_insw; 91 hwif->INSW = ide_insw;
104 hwif->INSL = ide_insl; 92 hwif->INSL = ide_insl;
105} 93}
@@ -123,11 +111,6 @@ static void ide_mm_insw (unsigned long port, void *addr, u32 count)
123 __ide_mm_insw((void __iomem *) port, addr, count); 111 __ide_mm_insw((void __iomem *) port, addr, count);
124} 112}
125 113
126static u32 ide_mm_inl (unsigned long port)
127{
128 return (u32) readl((void __iomem *) port);
129}
130
131static void ide_mm_insl (unsigned long port, void *addr, u32 count) 114static void ide_mm_insl (unsigned long port, void *addr, u32 count)
132{ 115{
133 __ide_mm_insl((void __iomem *) port, addr, count); 116 __ide_mm_insl((void __iomem *) port, addr, count);
@@ -153,11 +136,6 @@ static void ide_mm_outsw (unsigned long port, void *addr, u32 count)
153 __ide_mm_outsw((void __iomem *) port, addr, count); 136 __ide_mm_outsw((void __iomem *) port, addr, count);
154} 137}
155 138
156static void ide_mm_outl (u32 value, unsigned long port)
157{
158 writel(value, (void __iomem *) port);
159}
160
161static void ide_mm_outsl (unsigned long port, void *addr, u32 count) 139static void ide_mm_outsl (unsigned long port, void *addr, u32 count)
162{ 140{
163 __ide_mm_outsl((void __iomem *) port, addr, count); 141 __ide_mm_outsl((void __iomem *) port, addr, count);
@@ -170,12 +148,10 @@ void default_hwif_mmiops (ide_hwif_t *hwif)
170 this one is controller specific! */ 148 this one is controller specific! */
171 hwif->OUTBSYNC = ide_mm_outbsync; 149 hwif->OUTBSYNC = ide_mm_outbsync;
172 hwif->OUTW = ide_mm_outw; 150 hwif->OUTW = ide_mm_outw;
173 hwif->OUTL = ide_mm_outl;
174 hwif->OUTSW = ide_mm_outsw; 151 hwif->OUTSW = ide_mm_outsw;
175 hwif->OUTSL = ide_mm_outsl; 152 hwif->OUTSL = ide_mm_outsl;
176 hwif->INB = ide_mm_inb; 153 hwif->INB = ide_mm_inb;
177 hwif->INW = ide_mm_inw; 154 hwif->INW = ide_mm_inw;
178 hwif->INL = ide_mm_inl;
179 hwif->INSW = ide_mm_insw; 155 hwif->INSW = ide_mm_insw;
180 hwif->INSL = ide_mm_insl; 156 hwif->INSL = ide_mm_insl;
181} 157}
@@ -607,6 +583,8 @@ u8 eighty_ninty_three (ide_drive_t *drive)
607 if(!(drive->id->hw_config & 0x4000)) 583 if(!(drive->id->hw_config & 0x4000))
608 return 0; 584 return 0;
609#endif /* CONFIG_IDEDMA_IVB */ 585#endif /* CONFIG_IDEDMA_IVB */
586 if (!(drive->id->hw_config & 0x2000))
587 return 0;
610 return 1; 588 return 1;
611} 589}
612 590
@@ -777,7 +755,7 @@ int ide_config_drive_speed (ide_drive_t *drive, u8 speed)
777 755
778#ifdef CONFIG_BLK_DEV_IDEDMA 756#ifdef CONFIG_BLK_DEV_IDEDMA
779 if (hwif->ide_dma_check) /* check if host supports DMA */ 757 if (hwif->ide_dma_check) /* check if host supports DMA */
780 hwif->ide_dma_host_off(drive); 758 hwif->dma_host_off(drive);
781#endif 759#endif
782 760
783 /* 761 /*
@@ -854,9 +832,9 @@ int ide_config_drive_speed (ide_drive_t *drive, u8 speed)
854 832
855#ifdef CONFIG_BLK_DEV_IDEDMA 833#ifdef CONFIG_BLK_DEV_IDEDMA
856 if (speed >= XFER_SW_DMA_0) 834 if (speed >= XFER_SW_DMA_0)
857 hwif->ide_dma_host_on(drive); 835 hwif->dma_host_on(drive);
858 else if (hwif->ide_dma_check) /* check if host supports DMA */ 836 else if (hwif->ide_dma_check) /* check if host supports DMA */
859 hwif->ide_dma_off_quietly(drive); 837 hwif->dma_off_quietly(drive);
860#endif 838#endif
861 839
862 switch(speed) { 840 switch(speed) {
@@ -1066,12 +1044,12 @@ static void check_dma_crc(ide_drive_t *drive)
1066{ 1044{
1067#ifdef CONFIG_BLK_DEV_IDEDMA 1045#ifdef CONFIG_BLK_DEV_IDEDMA
1068 if (drive->crc_count) { 1046 if (drive->crc_count) {
1069 (void) HWIF(drive)->ide_dma_off_quietly(drive); 1047 drive->hwif->dma_off_quietly(drive);
1070 ide_set_xfer_rate(drive, ide_auto_reduce_xfer(drive)); 1048 ide_set_xfer_rate(drive, ide_auto_reduce_xfer(drive));
1071 if (drive->current_speed >= XFER_SW_DMA_0) 1049 if (drive->current_speed >= XFER_SW_DMA_0)
1072 (void) HWIF(drive)->ide_dma_on(drive); 1050 (void) HWIF(drive)->ide_dma_on(drive);
1073 } else 1051 } else
1074 (void)__ide_dma_off(drive); 1052 ide_dma_off(drive);
1075#endif 1053#endif
1076} 1054}
1077 1055
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index 8237d89eec..68719314df 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -205,6 +205,21 @@ int ide_dma_enable (ide_drive_t *drive)
205 205
206EXPORT_SYMBOL(ide_dma_enable); 206EXPORT_SYMBOL(ide_dma_enable);
207 207
208int ide_use_fast_pio(ide_drive_t *drive)
209{
210 struct hd_driveid *id = drive->id;
211
212 if ((id->capability & 1) && drive->autodma)
213 return 1;
214
215 if ((id->capability & 8) || (id->field_valid & 2))
216 return 1;
217
218 return 0;
219}
220
221EXPORT_SYMBOL_GPL(ide_use_fast_pio);
222
208/* 223/*
209 * Standard (generic) timings for PIO modes, from ATA2 specification. 224 * Standard (generic) timings for PIO modes, from ATA2 specification.
210 * These timings are for access to the IDE data port register *only*. 225 * These timings are for access to the IDE data port register *only*.
@@ -330,16 +345,16 @@ static int ide_scan_pio_blacklist (char *model)
330 345
331/** 346/**
332 * ide_get_best_pio_mode - get PIO mode from drive 347 * ide_get_best_pio_mode - get PIO mode from drive
333 * @driver: drive to consider 348 * @drive: drive to consider
334 * @mode_wanted: preferred mode 349 * @mode_wanted: preferred mode
335 * @max_mode: highest allowed 350 * @max_mode: highest allowed mode
336 * @d: pio data 351 * @d: PIO data
337 * 352 *
338 * This routine returns the recommended PIO settings for a given drive, 353 * This routine returns the recommended PIO settings for a given drive,
339 * based on the drive->id information and the ide_pio_blacklist[]. 354 * based on the drive->id information and the ide_pio_blacklist[].
340 * This is used by most chipset support modules when "auto-tuning".
341 * 355 *
342 * Drive PIO mode auto selection 356 * Drive PIO mode is auto-selected if 255 is passed as mode_wanted.
357 * This is used by most chipset support modules when "auto-tuning".
343 */ 358 */
344 359
345u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_pio_data_t *d) 360u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_pio_data_t *d)
@@ -349,15 +364,14 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_p
349 int use_iordy = 0; 364 int use_iordy = 0;
350 struct hd_driveid* id = drive->id; 365 struct hd_driveid* id = drive->id;
351 int overridden = 0; 366 int overridden = 0;
352 int blacklisted = 0;
353 367
354 if (mode_wanted != 255) { 368 if (mode_wanted != 255) {
355 pio_mode = mode_wanted; 369 pio_mode = mode_wanted;
370 use_iordy = (pio_mode > 2);
356 } else if (!drive->id) { 371 } else if (!drive->id) {
357 pio_mode = 0; 372 pio_mode = 0;
358 } else if ((pio_mode = ide_scan_pio_blacklist(id->model)) != -1) { 373 } else if ((pio_mode = ide_scan_pio_blacklist(id->model)) != -1) {
359 overridden = 1; 374 overridden = 1;
360 blacklisted = 1;
361 use_iordy = (pio_mode > 2); 375 use_iordy = (pio_mode > 2);
362 } else { 376 } else {
363 pio_mode = id->tPIO; 377 pio_mode = id->tPIO;
@@ -383,19 +397,12 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_p
383 } 397 }
384 } 398 }
385 399
386#if 0
387 if (drive->id->major_rev_num & 0x0004) printk("ATA-2 ");
388#endif
389
390 /* 400 /*
391 * Conservative "downgrade" for all pre-ATA2 drives 401 * Conservative "downgrade" for all pre-ATA2 drives
392 */ 402 */
393 if (pio_mode && pio_mode < 4) { 403 if (pio_mode && pio_mode < 4) {
394 pio_mode--; 404 pio_mode--;
395 overridden = 1; 405 overridden = 1;
396#if 0
397 use_iordy = (pio_mode > 2);
398#endif
399 if (cycle_time && cycle_time < ide_pio_timings[pio_mode].cycle_time) 406 if (cycle_time && cycle_time < ide_pio_timings[pio_mode].cycle_time)
400 cycle_time = 0; /* use standard timing */ 407 cycle_time = 0; /* use standard timing */
401 } 408 }
@@ -409,7 +416,6 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_p
409 d->cycle_time = cycle_time ? cycle_time : ide_pio_timings[pio_mode].cycle_time; 416 d->cycle_time = cycle_time ? cycle_time : ide_pio_timings[pio_mode].cycle_time;
410 d->use_iordy = use_iordy; 417 d->use_iordy = use_iordy;
411 d->overridden = overridden; 418 d->overridden = overridden;
412 d->blacklisted = blacklisted;
413 } 419 }
414 return pio_mode; 420 return pio_mode;
415} 421}
@@ -462,8 +468,6 @@ int ide_set_xfer_rate(ide_drive_t *drive, u8 rate)
462 return -1; 468 return -1;
463} 469}
464 470
465EXPORT_SYMBOL_GPL(ide_set_xfer_rate);
466
467static void ide_dump_opcode(ide_drive_t *drive) 471static void ide_dump_opcode(ide_drive_t *drive)
468{ 472{
469 struct request *rq; 473 struct request *rq;
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 176bbc850d..8f15c23aa7 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -31,8 +31,6 @@
31 * valid after probe time even with noprobe 31 * valid after probe time even with noprobe
32 */ 32 */
33 33
34#undef REALLY_SLOW_IO /* most systems can safely undef this */
35
36#include <linux/module.h> 34#include <linux/module.h>
37#include <linux/types.h> 35#include <linux/types.h>
38#include <linux/string.h> 36#include <linux/string.h>
@@ -853,11 +851,11 @@ static void probe_hwif(ide_hwif_t *hwif)
853 * things, if not checked and cleared. 851 * things, if not checked and cleared.
854 * PARANOIA!!! 852 * PARANOIA!!!
855 */ 853 */
856 hwif->ide_dma_off_quietly(drive); 854 hwif->dma_off_quietly(drive);
857#ifdef CONFIG_IDEDMA_ONLYDISK 855#ifdef CONFIG_IDEDMA_ONLYDISK
858 if (drive->media == ide_disk) 856 if (drive->media == ide_disk)
859#endif 857#endif
860 hwif->ide_dma_check(drive); 858 ide_set_dma(drive);
861 } 859 }
862 } 860 }
863 } 861 }
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index c6eec0413a..4e59239fef 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -1970,7 +1970,7 @@ static ide_startstop_t idetape_pc_intr (ide_drive_t *drive)
1970 printk(KERN_ERR "ide-tape: The tape wants to issue more " 1970 printk(KERN_ERR "ide-tape: The tape wants to issue more "
1971 "interrupts in DMA mode\n"); 1971 "interrupts in DMA mode\n");
1972 printk(KERN_ERR "ide-tape: DMA disabled, reverting to PIO\n"); 1972 printk(KERN_ERR "ide-tape: DMA disabled, reverting to PIO\n");
1973 (void)__ide_dma_off(drive); 1973 ide_dma_off(drive);
1974 return ide_do_reset(drive); 1974 return ide_do_reset(drive);
1975 } 1975 }
1976 /* Get the number of bytes to transfer on this interrupt. */ 1976 /* Get the number of bytes to transfer on this interrupt. */
@@ -2176,7 +2176,7 @@ static ide_startstop_t idetape_issue_packet_command (ide_drive_t *drive, idetape
2176 if (test_and_clear_bit(PC_DMA_ERROR, &pc->flags)) { 2176 if (test_and_clear_bit(PC_DMA_ERROR, &pc->flags)) {
2177 printk(KERN_WARNING "ide-tape: DMA disabled, " 2177 printk(KERN_WARNING "ide-tape: DMA disabled, "
2178 "reverting to PIO\n"); 2178 "reverting to PIO\n");
2179 (void)__ide_dma_off(drive); 2179 ide_dma_off(drive);
2180 } 2180 }
2181 if (test_bit(PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma) 2181 if (test_bit(PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma)
2182 dma_ok = !hwif->dma_setup(drive); 2182 dma_ok = !hwif->dma_setup(drive);
@@ -4792,15 +4792,10 @@ static int idetape_open(struct inode *inode, struct file *filp)
4792{ 4792{
4793 struct gendisk *disk = inode->i_bdev->bd_disk; 4793 struct gendisk *disk = inode->i_bdev->bd_disk;
4794 struct ide_tape_obj *tape; 4794 struct ide_tape_obj *tape;
4795 ide_drive_t *drive;
4796 4795
4797 if (!(tape = ide_tape_get(disk))) 4796 if (!(tape = ide_tape_get(disk)))
4798 return -ENXIO; 4797 return -ENXIO;
4799 4798
4800 drive = tape->drive;
4801
4802 drive->usage++;
4803
4804 return 0; 4799 return 0;
4805} 4800}
4806 4801
@@ -4808,9 +4803,6 @@ static int idetape_release(struct inode *inode, struct file *filp)
4808{ 4803{
4809 struct gendisk *disk = inode->i_bdev->bd_disk; 4804 struct gendisk *disk = inode->i_bdev->bd_disk;
4810 struct ide_tape_obj *tape = ide_tape_g(disk); 4805 struct ide_tape_obj *tape = ide_tape_g(disk);
4811 ide_drive_t *drive = tape->drive;
4812
4813 drive->usage--;
4814 4806
4815 ide_tape_put(tape); 4807 ide_tape_put(tape);
4816 4808
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index c750f6ce77..dfbd744585 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -126,8 +126,6 @@
126#define REVISION "Revision: 7.00alpha2" 126#define REVISION "Revision: 7.00alpha2"
127#define VERSION "Id: ide.c 7.00a2 20020906" 127#define VERSION "Id: ide.c 7.00a2 20020906"
128 128
129#undef REALLY_SLOW_IO /* most systems can safely undef this */
130
131#define _IDE_C /* Tell ide.h it's really us */ 129#define _IDE_C /* Tell ide.h it's really us */
132 130
133#include <linux/module.h> 131#include <linux/module.h>
@@ -389,9 +387,8 @@ int ide_hwif_request_regions(ide_hwif_t *hwif)
389 unsigned long addr; 387 unsigned long addr;
390 unsigned int i; 388 unsigned int i;
391 389
392 if (hwif->mmio == 2) 390 if (hwif->mmio)
393 return 0; 391 return 0;
394 BUG_ON(hwif->mmio == 1);
395 addr = hwif->io_ports[IDE_CONTROL_OFFSET]; 392 addr = hwif->io_ports[IDE_CONTROL_OFFSET];
396 if (addr && !hwif_request_region(hwif, addr, 1)) 393 if (addr && !hwif_request_region(hwif, addr, 1))
397 goto control_region_busy; 394 goto control_region_busy;
@@ -438,7 +435,7 @@ void ide_hwif_release_regions(ide_hwif_t *hwif)
438{ 435{
439 u32 i = 0; 436 u32 i = 0;
440 437
441 if (hwif->mmio == 2) 438 if (hwif->mmio)
442 return; 439 return;
443 if (hwif->io_ports[IDE_CONTROL_OFFSET]) 440 if (hwif->io_ports[IDE_CONTROL_OFFSET])
444 release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1); 441 release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
@@ -507,23 +504,22 @@ static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
507 hwif->ide_dma_end = tmp_hwif->ide_dma_end; 504 hwif->ide_dma_end = tmp_hwif->ide_dma_end;
508 hwif->ide_dma_check = tmp_hwif->ide_dma_check; 505 hwif->ide_dma_check = tmp_hwif->ide_dma_check;
509 hwif->ide_dma_on = tmp_hwif->ide_dma_on; 506 hwif->ide_dma_on = tmp_hwif->ide_dma_on;
510 hwif->ide_dma_off_quietly = tmp_hwif->ide_dma_off_quietly; 507 hwif->dma_off_quietly = tmp_hwif->dma_off_quietly;
511 hwif->ide_dma_test_irq = tmp_hwif->ide_dma_test_irq; 508 hwif->ide_dma_test_irq = tmp_hwif->ide_dma_test_irq;
512 hwif->ide_dma_host_on = tmp_hwif->ide_dma_host_on; 509 hwif->ide_dma_clear_irq = tmp_hwif->ide_dma_clear_irq;
513 hwif->ide_dma_host_off = tmp_hwif->ide_dma_host_off; 510 hwif->dma_host_on = tmp_hwif->dma_host_on;
511 hwif->dma_host_off = tmp_hwif->dma_host_off;
514 hwif->ide_dma_lostirq = tmp_hwif->ide_dma_lostirq; 512 hwif->ide_dma_lostirq = tmp_hwif->ide_dma_lostirq;
515 hwif->ide_dma_timeout = tmp_hwif->ide_dma_timeout; 513 hwif->ide_dma_timeout = tmp_hwif->ide_dma_timeout;
516 514
517 hwif->OUTB = tmp_hwif->OUTB; 515 hwif->OUTB = tmp_hwif->OUTB;
518 hwif->OUTBSYNC = tmp_hwif->OUTBSYNC; 516 hwif->OUTBSYNC = tmp_hwif->OUTBSYNC;
519 hwif->OUTW = tmp_hwif->OUTW; 517 hwif->OUTW = tmp_hwif->OUTW;
520 hwif->OUTL = tmp_hwif->OUTL;
521 hwif->OUTSW = tmp_hwif->OUTSW; 518 hwif->OUTSW = tmp_hwif->OUTSW;
522 hwif->OUTSL = tmp_hwif->OUTSL; 519 hwif->OUTSL = tmp_hwif->OUTSL;
523 520
524 hwif->INB = tmp_hwif->INB; 521 hwif->INB = tmp_hwif->INB;
525 hwif->INW = tmp_hwif->INW; 522 hwif->INW = tmp_hwif->INW;
526 hwif->INL = tmp_hwif->INL;
527 hwif->INSW = tmp_hwif->INSW; 523 hwif->INSW = tmp_hwif->INSW;
528 hwif->INSL = tmp_hwif->INSL; 524 hwif->INSL = tmp_hwif->INSL;
529 525
@@ -551,7 +547,6 @@ static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
551 hwif->extra_ports = tmp_hwif->extra_ports; 547 hwif->extra_ports = tmp_hwif->extra_ports;
552 hwif->autodma = tmp_hwif->autodma; 548 hwif->autodma = tmp_hwif->autodma;
553 hwif->udma_four = tmp_hwif->udma_four; 549 hwif->udma_four = tmp_hwif->udma_four;
554 hwif->no_dsc = tmp_hwif->no_dsc;
555 550
556 hwif->hwif_data = tmp_hwif->hwif_data; 551 hwif->hwif_data = tmp_hwif->hwif_data;
557} 552}
@@ -1138,12 +1133,11 @@ static int set_using_dma (ide_drive_t *drive, int arg)
1138 if (HWIF(drive)->ide_dma_check == NULL) 1133 if (HWIF(drive)->ide_dma_check == NULL)
1139 return -EPERM; 1134 return -EPERM;
1140 if (arg) { 1135 if (arg) {
1141 if (HWIF(drive)->ide_dma_check(drive)) return -EIO; 1136 if (ide_set_dma(drive))
1142 if (HWIF(drive)->ide_dma_on(drive)) return -EIO;
1143 } else {
1144 if (__ide_dma_off(drive))
1145 return -EIO; 1137 return -EIO;
1146 } 1138 if (HWIF(drive)->ide_dma_on(drive)) return -EIO;
1139 } else
1140 ide_dma_off(drive);
1147 return 0; 1141 return 0;
1148#else 1142#else
1149 return -EPERM; 1143 return -EPERM;
@@ -1490,23 +1484,23 @@ static int __init match_parm (char *s, const char *keywords[], int vals[], int m
1490} 1484}
1491 1485
1492#ifdef CONFIG_BLK_DEV_ALI14XX 1486#ifdef CONFIG_BLK_DEV_ALI14XX
1493static int __initdata probe_ali14xx; 1487extern int probe_ali14xx;
1494extern int ali14xx_init(void); 1488extern int ali14xx_init(void);
1495#endif 1489#endif
1496#ifdef CONFIG_BLK_DEV_UMC8672 1490#ifdef CONFIG_BLK_DEV_UMC8672
1497static int __initdata probe_umc8672; 1491extern int probe_umc8672;
1498extern int umc8672_init(void); 1492extern int umc8672_init(void);
1499#endif 1493#endif
1500#ifdef CONFIG_BLK_DEV_DTC2278 1494#ifdef CONFIG_BLK_DEV_DTC2278
1501static int __initdata probe_dtc2278; 1495extern int probe_dtc2278;
1502extern int dtc2278_init(void); 1496extern int dtc2278_init(void);
1503#endif 1497#endif
1504#ifdef CONFIG_BLK_DEV_HT6560B 1498#ifdef CONFIG_BLK_DEV_HT6560B
1505static int __initdata probe_ht6560b; 1499extern int probe_ht6560b;
1506extern int ht6560b_init(void); 1500extern int ht6560b_init(void);
1507#endif 1501#endif
1508#ifdef CONFIG_BLK_DEV_QD65XX 1502#ifdef CONFIG_BLK_DEV_QD65XX
1509static int __initdata probe_qd65xx; 1503extern int probe_qd65xx;
1510extern int qd65xx_init(void); 1504extern int qd65xx_init(void);
1511#endif 1505#endif
1512 1506
@@ -1584,7 +1578,7 @@ static int __init ide_setup(char *s)
1584 */ 1578 */
1585 if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) { 1579 if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
1586 const char *hd_words[] = { 1580 const char *hd_words[] = {
1587 "none", "noprobe", "nowerr", "cdrom", "serialize", 1581 "none", "noprobe", "nowerr", "cdrom", "minus5",
1588 "autotune", "noautotune", "minus8", "swapdata", "bswap", 1582 "autotune", "noautotune", "minus8", "swapdata", "bswap",
1589 "noflush", "remap", "remap63", "scsi", NULL }; 1583 "noflush", "remap", "remap63", "scsi", NULL };
1590 unit = s[2] - 'a'; 1584 unit = s[2] - 'a';
@@ -1612,9 +1606,6 @@ static int __init ide_setup(char *s)
1612 drive->ready_stat = 0; 1606 drive->ready_stat = 0;
1613 hwif->noprobe = 0; 1607 hwif->noprobe = 0;
1614 goto done; 1608 goto done;
1615 case -5: /* "serialize" */
1616 printk(" -- USE \"ide%d=serialize\" INSTEAD", hw);
1617 goto do_serialize;
1618 case -6: /* "autotune" */ 1609 case -6: /* "autotune" */
1619 drive->autotune = IDE_TUNE_AUTO; 1610 drive->autotune = IDE_TUNE_AUTO;
1620 goto obsolete_option; 1611 goto obsolete_option;
@@ -1675,7 +1666,7 @@ static int __init ide_setup(char *s)
1675 * (-8, -9, -10) are reserved to ease the hardcoding. 1666 * (-8, -9, -10) are reserved to ease the hardcoding.
1676 */ 1667 */
1677 static const char *ide_words[] = { 1668 static const char *ide_words[] = {
1678 "noprobe", "serialize", "autotune", "noautotune", 1669 "noprobe", "serialize", "minus3", "minus4",
1679 "reset", "dma", "ata66", "minus8", "minus9", 1670 "reset", "dma", "ata66", "minus8", "minus9",
1680 "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb", 1671 "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb",
1681 "dtc2278", "umc8672", "ali14xx", NULL }; 1672 "dtc2278", "umc8672", "ali14xx", NULL };
@@ -1746,12 +1737,17 @@ static int __init ide_setup(char *s)
1746 hwif->chipset = mate->chipset = ide_4drives; 1737 hwif->chipset = mate->chipset = ide_4drives;
1747 mate->irq = hwif->irq; 1738 mate->irq = hwif->irq;
1748 memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports)); 1739 memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports));
1749 goto do_serialize; 1740 hwif->mate = mate;
1741 mate->mate = hwif;
1742 hwif->serialized = mate->serialized = 1;
1743 goto obsolete_option;
1750 } 1744 }
1751#endif /* CONFIG_BLK_DEV_4DRIVES */ 1745#endif /* CONFIG_BLK_DEV_4DRIVES */
1752 case -10: /* minus10 */ 1746 case -10: /* minus10 */
1753 case -9: /* minus9 */ 1747 case -9: /* minus9 */
1754 case -8: /* minus8 */ 1748 case -8: /* minus8 */
1749 case -4:
1750 case -3:
1755 goto bad_option; 1751 goto bad_option;
1756 case -7: /* ata66 */ 1752 case -7: /* ata66 */
1757#ifdef CONFIG_BLK_DEV_IDEPCI 1753#ifdef CONFIG_BLK_DEV_IDEPCI
@@ -1766,16 +1762,7 @@ static int __init ide_setup(char *s)
1766 case -5: /* "reset" */ 1762 case -5: /* "reset" */
1767 hwif->reset = 1; 1763 hwif->reset = 1;
1768 goto obsolete_option; 1764 goto obsolete_option;
1769 case -4: /* "noautotune" */
1770 hwif->drives[0].autotune = IDE_TUNE_NOAUTO;
1771 hwif->drives[1].autotune = IDE_TUNE_NOAUTO;
1772 goto obsolete_option;
1773 case -3: /* "autotune" */
1774 hwif->drives[0].autotune = IDE_TUNE_AUTO;
1775 hwif->drives[1].autotune = IDE_TUNE_AUTO;
1776 goto obsolete_option;
1777 case -2: /* "serialize" */ 1765 case -2: /* "serialize" */
1778 do_serialize:
1779 hwif->mate = &ide_hwifs[hw^1]; 1766 hwif->mate = &ide_hwifs[hw^1];
1780 hwif->mate->mate = hwif; 1767 hwif->mate->mate = hwif;
1781 hwif->serialized = hwif->mate->serialized = 1; 1768 hwif->serialized = hwif->mate->serialized = 1;
@@ -1844,8 +1831,8 @@ static void __init probe_for_hwifs (void)
1844#endif /* CONFIG_BLK_DEV_CMD640 */ 1831#endif /* CONFIG_BLK_DEV_CMD640 */
1845#ifdef CONFIG_BLK_DEV_IDE_PMAC 1832#ifdef CONFIG_BLK_DEV_IDE_PMAC
1846 { 1833 {
1847 extern void pmac_ide_probe(void); 1834 extern int pmac_ide_probe(void);
1848 pmac_ide_probe(); 1835 (void)pmac_ide_probe();
1849 } 1836 }
1850#endif /* CONFIG_BLK_DEV_IDE_PMAC */ 1837#endif /* CONFIG_BLK_DEV_IDE_PMAC */
1851#ifdef CONFIG_BLK_DEV_GAYLE 1838#ifdef CONFIG_BLK_DEV_GAYLE
diff --git a/drivers/ide/legacy/ali14xx.c b/drivers/ide/legacy/ali14xx.c
index 9c544467cb..91961aa030 100644
--- a/drivers/ide/legacy/ali14xx.c
+++ b/drivers/ide/legacy/ali14xx.c
@@ -37,8 +37,6 @@
37 * mode 4 for a while now with no trouble.) -Derek 37 * mode 4 for a while now with no trouble.) -Derek
38 */ 38 */
39 39
40#undef REALLY_SLOW_IO /* most systems can safely undef this */
41
42#include <linux/module.h> 40#include <linux/module.h>
43#include <linux/types.h> 41#include <linux/types.h>
44#include <linux/kernel.h> 42#include <linux/kernel.h>
@@ -230,9 +228,17 @@ static int __init ali14xx_probe(void)
230 return 0; 228 return 0;
231} 229}
232 230
231int probe_ali14xx = 0;
232
233module_param_named(probe, probe_ali14xx, bool, 0);
234MODULE_PARM_DESC(probe, "probe for ALI M14xx chipsets");
235
233/* Can be called directly from ide.c. */ 236/* Can be called directly from ide.c. */
234int __init ali14xx_init(void) 237int __init ali14xx_init(void)
235{ 238{
239 if (probe_ali14xx == 0)
240 goto out;
241
236 /* auto-detect IDE controller port */ 242 /* auto-detect IDE controller port */
237 if (findPort()) { 243 if (findPort()) {
238 if (ali14xx_probe()) 244 if (ali14xx_probe())
@@ -240,6 +246,7 @@ int __init ali14xx_init(void)
240 return 0; 246 return 0;
241 } 247 }
242 printk(KERN_ERR "ali14xx: not found.\n"); 248 printk(KERN_ERR "ali14xx: not found.\n");
249out:
243 return -ENODEV; 250 return -ENODEV;
244} 251}
245 252
diff --git a/drivers/ide/legacy/buddha.c b/drivers/ide/legacy/buddha.c
index 0391a31228..1ed224a01f 100644
--- a/drivers/ide/legacy/buddha.c
+++ b/drivers/ide/legacy/buddha.c
@@ -215,7 +215,7 @@ fail_base2:
215 215
216 index = ide_register_hw(&hw, &hwif); 216 index = ide_register_hw(&hw, &hwif);
217 if (index != -1) { 217 if (index != -1) {
218 hwif->mmio = 2; 218 hwif->mmio = 1;
219 printk("ide%d: ", index); 219 printk("ide%d: ", index);
220 switch(type) { 220 switch(type) {
221 case BOARD_BUDDHA: 221 case BOARD_BUDDHA:
diff --git a/drivers/ide/legacy/dtc2278.c b/drivers/ide/legacy/dtc2278.c
index 3b1d33baaa..0219ffa64d 100644
--- a/drivers/ide/legacy/dtc2278.c
+++ b/drivers/ide/legacy/dtc2278.c
@@ -4,8 +4,6 @@
4 * Copyright (C) 1996 Linus Torvalds & author (see below) 4 * Copyright (C) 1996 Linus Torvalds & author (see below)
5 */ 5 */
6 6
7#undef REALLY_SLOW_IO /* most systems can safely undef this */
8
9#include <linux/module.h> 7#include <linux/module.h>
10#include <linux/types.h> 8#include <linux/types.h>
11#include <linux/kernel.h> 9#include <linux/kernel.h>
@@ -94,7 +92,7 @@ static void tune_dtc2278 (ide_drive_t *drive, u8 pio)
94 HWIF(drive)->drives[!drive->select.b.unit].io_32bit = 1; 92 HWIF(drive)->drives[!drive->select.b.unit].io_32bit = 1;
95} 93}
96 94
97static int __init probe_dtc2278(void) 95static int __init dtc2278_probe(void)
98{ 96{
99 unsigned long flags; 97 unsigned long flags;
100 ide_hwif_t *hwif, *mate; 98 ide_hwif_t *hwif, *mate;
@@ -145,10 +143,18 @@ static int __init probe_dtc2278(void)
145 return 0; 143 return 0;
146} 144}
147 145
146int probe_dtc2278 = 0;
147
148module_param_named(probe, probe_dtc2278, bool, 0);
149MODULE_PARM_DESC(probe, "probe for DTC2278xx chipsets");
150
148/* Can be called directly from ide.c. */ 151/* Can be called directly from ide.c. */
149int __init dtc2278_init(void) 152int __init dtc2278_init(void)
150{ 153{
151 if (probe_dtc2278()) { 154 if (probe_dtc2278 == 0)
155 return -ENODEV;
156
157 if (dtc2278_probe()) {
152 printk(KERN_ERR "dtc2278: ide interfaces already in use!\n"); 158 printk(KERN_ERR "dtc2278: ide interfaces already in use!\n");
153 return -EBUSY; 159 return -EBUSY;
154 } 160 }
diff --git a/drivers/ide/legacy/gayle.c b/drivers/ide/legacy/gayle.c
index 64d42619ab..dcfadbbf55 100644
--- a/drivers/ide/legacy/gayle.c
+++ b/drivers/ide/legacy/gayle.c
@@ -167,7 +167,7 @@ found:
167 167
168 index = ide_register_hw(&hw, &hwif); 168 index = ide_register_hw(&hw, &hwif);
169 if (index != -1) { 169 if (index != -1) {
170 hwif->mmio = 2; 170 hwif->mmio = 1;
171 switch (i) { 171 switch (i) {
172 case 0: 172 case 0:
173 printk("ide%d: Gayle IDE interface (A%d style)\n", index, 173 printk("ide%d: Gayle IDE interface (A%d style)\n", index,
diff --git a/drivers/ide/legacy/ht6560b.c b/drivers/ide/legacy/ht6560b.c
index c48e87e512..a2832643c5 100644
--- a/drivers/ide/legacy/ht6560b.c
+++ b/drivers/ide/legacy/ht6560b.c
@@ -36,8 +36,6 @@
36 36
37#define HT6560B_VERSION "v0.07" 37#define HT6560B_VERSION "v0.07"
38 38
39#undef REALLY_SLOW_IO /* most systems can safely undef this */
40
41#include <linux/module.h> 39#include <linux/module.h>
42#include <linux/types.h> 40#include <linux/types.h>
43#include <linux/kernel.h> 41#include <linux/kernel.h>
@@ -143,16 +141,16 @@ static void ht6560b_selectproc (ide_drive_t *drive)
143 current_timing = timing; 141 current_timing = timing;
144 if (drive->media != ide_disk || !drive->present) 142 if (drive->media != ide_disk || !drive->present)
145 select |= HT_PREFETCH_MODE; 143 select |= HT_PREFETCH_MODE;
146 (void) HWIF(drive)->INB(HT_CONFIG_PORT); 144 (void)inb(HT_CONFIG_PORT);
147 (void) HWIF(drive)->INB(HT_CONFIG_PORT); 145 (void)inb(HT_CONFIG_PORT);
148 (void) HWIF(drive)->INB(HT_CONFIG_PORT); 146 (void)inb(HT_CONFIG_PORT);
149 (void) HWIF(drive)->INB(HT_CONFIG_PORT); 147 (void)inb(HT_CONFIG_PORT);
150 HWIF(drive)->OUTB(select, HT_CONFIG_PORT); 148 outb(select, HT_CONFIG_PORT);
151 /* 149 /*
152 * Set timing for this drive: 150 * Set timing for this drive:
153 */ 151 */
154 HWIF(drive)->OUTB(timing, IDE_SELECT_REG); 152 outb(timing, IDE_SELECT_REG);
155 (void) HWIF(drive)->INB(IDE_STATUS_REG); 153 (void)inb(IDE_STATUS_REG);
156#ifdef DEBUG 154#ifdef DEBUG
157 printk("ht6560b: %s: select=%#x timing=%#x\n", 155 printk("ht6560b: %s: select=%#x timing=%#x\n",
158 drive->name, select, timing); 156 drive->name, select, timing);
@@ -303,12 +301,20 @@ static void tune_ht6560b (ide_drive_t *drive, u8 pio)
303#endif 301#endif
304} 302}
305 303
304int probe_ht6560b = 0;
305
306module_param_named(probe, probe_ht6560b, bool, 0);
307MODULE_PARM_DESC(probe, "probe for HT6560B chipset");
308
306/* Can be called directly from ide.c. */ 309/* Can be called directly from ide.c. */
307int __init ht6560b_init(void) 310int __init ht6560b_init(void)
308{ 311{
309 ide_hwif_t *hwif, *mate; 312 ide_hwif_t *hwif, *mate;
310 int t; 313 int t;
311 314
315 if (probe_ht6560b == 0)
316 return -ENODEV;
317
312 hwif = &ide_hwifs[0]; 318 hwif = &ide_hwifs[0];
313 mate = &ide_hwifs[1]; 319 mate = &ide_hwifs[1];
314 320
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index a5023cdbdc..b08c37c9f9 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -359,14 +359,17 @@ void ide_release(struct pcmcia_device *link)
359static struct pcmcia_device_id ide_ids[] = { 359static struct pcmcia_device_id ide_ids[] = {
360 PCMCIA_DEVICE_FUNC_ID(4), 360 PCMCIA_DEVICE_FUNC_ID(4),
361 PCMCIA_DEVICE_MANF_CARD(0x0007, 0x0000), /* Hitachi */ 361 PCMCIA_DEVICE_MANF_CARD(0x0007, 0x0000), /* Hitachi */
362 PCMCIA_DEVICE_MANF_CARD(0x000a, 0x0000), /* I-O Data CFA */
363 PCMCIA_DEVICE_MANF_CARD(0x001c, 0x0001), /* Mitsubishi CFA */
362 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704), 364 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704),
363 PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401), 365 PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401), /* SanDisk CFA */
364 PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000), /* Toshiba */ 366 PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000), /* Toshiba */
365 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d), 367 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d),
366 PCMCIA_DEVICE_MANF_CARD(0x00ce, 0x0000), /* Samsung */ 368 PCMCIA_DEVICE_MANF_CARD(0x00ce, 0x0000), /* Samsung */
367 PCMCIA_DEVICE_MANF_CARD(0x0319, 0x0000), /* Hitachi */ 369 PCMCIA_DEVICE_MANF_CARD(0x0319, 0x0000), /* Hitachi */
368 PCMCIA_DEVICE_MANF_CARD(0x2080, 0x0001), 370 PCMCIA_DEVICE_MANF_CARD(0x2080, 0x0001),
369 PCMCIA_DEVICE_MANF_CARD(0x4e01, 0x0200), /* Lexar */ 371 PCMCIA_DEVICE_MANF_CARD(0x4e01, 0x0100), /* Viking CFA */
372 PCMCIA_DEVICE_MANF_CARD(0x4e01, 0x0200), /* Lexar, Viking CFA */
370 PCMCIA_DEVICE_PROD_ID123("Caravelle", "PSC-IDE ", "PSC000", 0x8c36137c, 0xd0693ab8, 0x2768a9f0), 373 PCMCIA_DEVICE_PROD_ID123("Caravelle", "PSC-IDE ", "PSC000", 0x8c36137c, 0xd0693ab8, 0x2768a9f0),
371 PCMCIA_DEVICE_PROD_ID123("CDROM", "IDE", "MCD-601p", 0x1b9179ca, 0xede88951, 0x0d902f74), 374 PCMCIA_DEVICE_PROD_ID123("CDROM", "IDE", "MCD-601p", 0x1b9179ca, 0xede88951, 0x0d902f74),
372 PCMCIA_DEVICE_PROD_ID123("PCMCIA", "IDE CARD", "F1", 0x281f1c5d, 0x1907960c, 0xf7fde8b9), 375 PCMCIA_DEVICE_PROD_ID123("PCMCIA", "IDE CARD", "F1", 0x281f1c5d, 0x1907960c, 0xf7fde8b9),
diff --git a/drivers/ide/legacy/macide.c b/drivers/ide/legacy/macide.c
index b1730d7e41..4c0079ad52 100644
--- a/drivers/ide/legacy/macide.c
+++ b/drivers/ide/legacy/macide.c
@@ -141,7 +141,7 @@ void macide_init(void)
141 } 141 }
142 142
143 if (index != -1) { 143 if (index != -1) {
144 hwif->mmio = 2; 144 hwif->mmio = 1;
145 if (macintosh_config->ide_type == MAC_IDE_QUADRA) 145 if (macintosh_config->ide_type == MAC_IDE_QUADRA)
146 printk(KERN_INFO "ide%d: Macintosh Quadra IDE interface\n", index); 146 printk(KERN_INFO "ide%d: Macintosh Quadra IDE interface\n", index);
147 else if (macintosh_config->ide_type == MAC_IDE_PB) 147 else if (macintosh_config->ide_type == MAC_IDE_PB)
diff --git a/drivers/ide/legacy/q40ide.c b/drivers/ide/legacy/q40ide.c
index 434a94faa3..74f08124ea 100644
--- a/drivers/ide/legacy/q40ide.c
+++ b/drivers/ide/legacy/q40ide.c
@@ -145,7 +145,7 @@ void q40ide_init(void)
145 index = ide_register_hw(&hw, &hwif); 145 index = ide_register_hw(&hw, &hwif);
146 // **FIXME** 146 // **FIXME**
147 if (index != -1) 147 if (index != -1)
148 hwif->mmio = 2; 148 hwif->mmio = 1;
149 } 149 }
150} 150}
151 151
diff --git a/drivers/ide/legacy/qd65xx.c b/drivers/ide/legacy/qd65xx.c
index d3c3bc2640..2fb8f50f12 100644
--- a/drivers/ide/legacy/qd65xx.c
+++ b/drivers/ide/legacy/qd65xx.c
@@ -16,8 +16,8 @@
16 * Please set local bus speed using kernel parameter idebus 16 * Please set local bus speed using kernel parameter idebus
17 * for example, "idebus=33" stands for 33Mhz VLbus 17 * for example, "idebus=33" stands for 33Mhz VLbus
18 * To activate controller support, use "ide0=qd65xx" 18 * To activate controller support, use "ide0=qd65xx"
19 * To enable tuning, use "ide0=autotune" 19 * To enable tuning, use "hda=autotune hdb=autotune"
20 * To enable second channel tuning (qd6580 only), use "ide1=autotune" 20 * To enable 2nd channel tuning (qd6580 only), use "hdc=autotune hdd=autotune"
21 */ 21 */
22 22
23/* 23/*
@@ -25,8 +25,6 @@
25 * Samuel Thibault <samuel.thibault@fnac.net> 25 * Samuel Thibault <samuel.thibault@fnac.net>
26 */ 26 */
27 27
28#undef REALLY_SLOW_IO /* most systems can safely undef this */
29
30#include <linux/module.h> 28#include <linux/module.h>
31#include <linux/types.h> 29#include <linux/types.h>
32#include <linux/kernel.h> 30#include <linux/kernel.h>
@@ -490,9 +488,17 @@ static int __init qd_probe(int base)
490 return 1; 488 return 1;
491} 489}
492 490
491int probe_qd65xx = 0;
492
493module_param_named(probe, probe_qd65xx, bool, 0);
494MODULE_PARM_DESC(probe, "probe for QD65xx chipsets");
495
493/* Can be called directly from ide.c. */ 496/* Can be called directly from ide.c. */
494int __init qd65xx_init(void) 497int __init qd65xx_init(void)
495{ 498{
499 if (probe_qd65xx == 0)
500 return -ENODEV;
501
496 if (qd_probe(0x30)) 502 if (qd_probe(0x30))
497 qd_probe(0xb0); 503 qd_probe(0xb0);
498 if (ide_hwifs[0].chipset != ide_qd65xx && 504 if (ide_hwifs[0].chipset != ide_qd65xx &&
diff --git a/drivers/ide/legacy/umc8672.c b/drivers/ide/legacy/umc8672.c
index 6e2c58c5f6..ca79744555 100644
--- a/drivers/ide/legacy/umc8672.c
+++ b/drivers/ide/legacy/umc8672.c
@@ -165,12 +165,21 @@ static int __init umc8672_probe(void)
165 return 0; 165 return 0;
166} 166}
167 167
168int probe_umc8672 = 0;
169
170module_param_named(probe, probe_umc8672, bool, 0);
171MODULE_PARM_DESC(probe, "probe for UMC8672 chipset");
172
168/* Can be called directly from ide.c. */ 173/* Can be called directly from ide.c. */
169int __init umc8672_init(void) 174int __init umc8672_init(void)
170{ 175{
171 if (umc8672_probe()) 176 if (probe_umc8672 == 0)
172 return -ENODEV; 177 goto out;
173 return 0; 178
179 if (umc8672_probe() == 0)
180 return 0;;
181out:
182 return -ENODEV;;
174} 183}
175 184
176#ifdef MODULE 185#ifdef MODULE
diff --git a/drivers/ide/mips/au1xxx-ide.c b/drivers/ide/mips/au1xxx-ide.c
index c7854ea57b..b2dc028dc8 100644
--- a/drivers/ide/mips/au1xxx-ide.c
+++ b/drivers/ide/mips/au1xxx-ide.c
@@ -29,8 +29,6 @@
29 * Note: for more information, please refer "AMD Alchemy Au1200/Au1550 IDE 29 * Note: for more information, please refer "AMD Alchemy Au1200/Au1550 IDE
30 * Interface and Linux Device Driver" Application Note. 30 * Interface and Linux Device Driver" Application Note.
31 */ 31 */
32#undef REALLY_SLOW_IO /* most systems can safely undef this */
33
34#include <linux/types.h> 32#include <linux/types.h>
35#include <linux/module.h> 33#include <linux/module.h>
36#include <linux/kernel.h> 34#include <linux/kernel.h>
@@ -181,12 +179,6 @@ static int auide_tune_chipset (ide_drive_t *drive, u8 speed)
181{ 179{
182 int mem_sttime; 180 int mem_sttime;
183 int mem_stcfg; 181 int mem_stcfg;
184 unsigned long mode;
185
186#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
187 if (ide_use_dma(drive))
188 mode = ide_dma_speed(drive, 0);
189#endif
190 182
191 mem_sttime = 0; 183 mem_sttime = 0;
192 mem_stcfg = au_readl(MEM_STCFG2); 184 mem_stcfg = au_readl(MEM_STCFG2);
@@ -195,7 +187,7 @@ static int auide_tune_chipset (ide_drive_t *drive, u8 speed)
195 auide_tune_drive(drive, speed - XFER_PIO_0); 187 auide_tune_drive(drive, speed - XFER_PIO_0);
196 return 0; 188 return 0;
197 } 189 }
198 190
199 switch(speed) { 191 switch(speed) {
200#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA 192#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
201 case XFER_MW_DMA_2: 193 case XFER_MW_DMA_2:
@@ -207,7 +199,6 @@ static int auide_tune_chipset (ide_drive_t *drive, u8 speed)
207 mem_stcfg &= ~TOECS_MASK; 199 mem_stcfg &= ~TOECS_MASK;
208 mem_stcfg |= SBC_IDE_MDMA2_TCSOE | SBC_IDE_MDMA2_TOECS; 200 mem_stcfg |= SBC_IDE_MDMA2_TCSOE | SBC_IDE_MDMA2_TOECS;
209 201
210 mode = XFER_MW_DMA_2;
211 break; 202 break;
212 case XFER_MW_DMA_1: 203 case XFER_MW_DMA_1:
213 mem_sttime = SBC_IDE_TIMING(MDMA1); 204 mem_sttime = SBC_IDE_TIMING(MDMA1);
@@ -218,7 +209,6 @@ static int auide_tune_chipset (ide_drive_t *drive, u8 speed)
218 mem_stcfg &= ~TOECS_MASK; 209 mem_stcfg &= ~TOECS_MASK;
219 mem_stcfg |= SBC_IDE_MDMA1_TCSOE | SBC_IDE_MDMA1_TOECS; 210 mem_stcfg |= SBC_IDE_MDMA1_TCSOE | SBC_IDE_MDMA1_TOECS;
220 211
221 mode = XFER_MW_DMA_1;
222 break; 212 break;
223 case XFER_MW_DMA_0: 213 case XFER_MW_DMA_0:
224 mem_sttime = SBC_IDE_TIMING(MDMA0); 214 mem_sttime = SBC_IDE_TIMING(MDMA0);
@@ -229,14 +219,13 @@ static int auide_tune_chipset (ide_drive_t *drive, u8 speed)
229 mem_stcfg &= ~TOECS_MASK; 219 mem_stcfg &= ~TOECS_MASK;
230 mem_stcfg |= SBC_IDE_MDMA0_TCSOE | SBC_IDE_MDMA0_TOECS; 220 mem_stcfg |= SBC_IDE_MDMA0_TCSOE | SBC_IDE_MDMA0_TOECS;
231 221
232 mode = XFER_MW_DMA_0;
233 break; 222 break;
234#endif 223#endif
235 default: 224 default:
236 return 1; 225 return 1;
237 } 226 }
238 227
239 if (ide_config_drive_speed(drive, mode)) 228 if (ide_config_drive_speed(drive, speed))
240 return 1; 229 return 1;
241 230
242 au_writel(mem_sttime,MEM_STTIME2); 231 au_writel(mem_sttime,MEM_STTIME2);
@@ -423,9 +412,9 @@ static int auide_dma_check(ide_drive_t *drive)
423 speed = ide_find_best_mode(drive, XFER_PIO | XFER_MWDMA); 412 speed = ide_find_best_mode(drive, XFER_PIO | XFER_MWDMA);
424 413
425 if (drive->autodma && (speed & XFER_MODE) != XFER_PIO) 414 if (drive->autodma && (speed & XFER_MODE) != XFER_PIO)
426 return HWIF(drive)->ide_dma_on(drive); 415 return 0;
427 416
428 return HWIF(drive)->ide_dma_off_quietly(drive); 417 return -1;
429} 418}
430 419
431static int auide_dma_test_irq(ide_drive_t *drive) 420static int auide_dma_test_irq(ide_drive_t *drive)
@@ -447,27 +436,24 @@ static int auide_dma_test_irq(ide_drive_t *drive)
447 return 0; 436 return 0;
448} 437}
449 438
450static int auide_dma_host_on(ide_drive_t *drive) 439static void auide_dma_host_on(ide_drive_t *drive)
451{ 440{
452 return 0;
453} 441}
454 442
455static int auide_dma_on(ide_drive_t *drive) 443static int auide_dma_on(ide_drive_t *drive)
456{ 444{
457 drive->using_dma = 1; 445 drive->using_dma = 1;
458 return auide_dma_host_on(drive);
459}
460 446
447 return 0;
448}
461 449
462static int auide_dma_host_off(ide_drive_t *drive) 450static void auide_dma_host_off(ide_drive_t *drive)
463{ 451{
464 return 0;
465} 452}
466 453
467static int auide_dma_off_quietly(ide_drive_t *drive) 454static void auide_dma_off_quietly(ide_drive_t *drive)
468{ 455{
469 drive->using_dma = 0; 456 drive->using_dma = 0;
470 return auide_dma_host_off(drive);
471} 457}
472 458
473static int auide_dma_lostirq(ide_drive_t *drive) 459static int auide_dma_lostirq(ide_drive_t *drive)
@@ -717,7 +703,8 @@ static int au_ide_probe(struct device *dev)
717 703
718 /* hold should be on in all cases */ 704 /* hold should be on in all cases */
719 hwif->hold = 1; 705 hwif->hold = 1;
720 hwif->mmio = 2; 706
707 hwif->mmio = 1;
721 708
722 /* If the user has selected DDMA assisted copies, 709 /* If the user has selected DDMA assisted copies,
723 then set up a few local I/O function entry points 710 then set up a few local I/O function entry points
@@ -732,7 +719,7 @@ static int au_ide_probe(struct device *dev)
732 hwif->speedproc = &auide_tune_chipset; 719 hwif->speedproc = &auide_tune_chipset;
733 720
734#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA 721#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
735 hwif->ide_dma_off_quietly = &auide_dma_off_quietly; 722 hwif->dma_off_quietly = &auide_dma_off_quietly;
736 hwif->ide_dma_timeout = &auide_dma_timeout; 723 hwif->ide_dma_timeout = &auide_dma_timeout;
737 724
738 hwif->ide_dma_check = &auide_dma_check; 725 hwif->ide_dma_check = &auide_dma_check;
@@ -741,8 +728,8 @@ static int au_ide_probe(struct device *dev)
741 hwif->ide_dma_end = &auide_dma_end; 728 hwif->ide_dma_end = &auide_dma_end;
742 hwif->dma_setup = &auide_dma_setup; 729 hwif->dma_setup = &auide_dma_setup;
743 hwif->ide_dma_test_irq = &auide_dma_test_irq; 730 hwif->ide_dma_test_irq = &auide_dma_test_irq;
744 hwif->ide_dma_host_off = &auide_dma_host_off; 731 hwif->dma_host_off = &auide_dma_host_off;
745 hwif->ide_dma_host_on = &auide_dma_host_on; 732 hwif->dma_host_on = &auide_dma_host_on;
746 hwif->ide_dma_lostirq = &auide_dma_lostirq; 733 hwif->ide_dma_lostirq = &auide_dma_lostirq;
747 hwif->ide_dma_on = &auide_dma_on; 734 hwif->ide_dma_on = &auide_dma_on;
748 735
diff --git a/drivers/ide/mips/swarm.c b/drivers/ide/mips/swarm.c
index 09c9e7936b..81fa06851b 100644
--- a/drivers/ide/mips/swarm.c
+++ b/drivers/ide/mips/swarm.c
@@ -115,7 +115,7 @@ static int __devinit swarm_ide_probe(struct device *dev)
115 /* Setup MMIO ops. */ 115 /* Setup MMIO ops. */
116 default_hwif_mmiops(hwif); 116 default_hwif_mmiops(hwif);
117 /* Prevent resource map manipulation. */ 117 /* Prevent resource map manipulation. */
118 hwif->mmio = 2; 118 hwif->mmio = 1;
119 hwif->noprobe = 0; 119 hwif->noprobe = 0;
120 120
121 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) 121 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c
index d261bfbad2..990eafe5ea 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/pci/aec62xx.c
@@ -94,9 +94,9 @@ static u8 aec62xx_ratemask (ide_drive_t *drive)
94 switch(hwif->pci_dev->device) { 94 switch(hwif->pci_dev->device) {
95 case PCI_DEVICE_ID_ARTOP_ATP865: 95 case PCI_DEVICE_ID_ARTOP_ATP865:
96 case PCI_DEVICE_ID_ARTOP_ATP865R: 96 case PCI_DEVICE_ID_ARTOP_ATP865R:
97 mode = (hwif->INB(((hwif->channel) ? 97 mode = (inb(hwif->channel ?
98 hwif->mate->dma_status : 98 hwif->mate->dma_status :
99 hwif->dma_status)) & 0x10) ? 4 : 3; 99 hwif->dma_status) & 0x10) ? 4 : 3;
100 break; 100 break;
101 case PCI_DEVICE_ID_ARTOP_ATP860: 101 case PCI_DEVICE_ID_ARTOP_ATP860:
102 case PCI_DEVICE_ID_ARTOP_ATP860R: 102 case PCI_DEVICE_ID_ARTOP_ATP860R:
@@ -209,25 +209,13 @@ static void aec62xx_tune_drive (ide_drive_t *drive, u8 pio)
209 209
210static int aec62xx_config_drive_xfer_rate (ide_drive_t *drive) 210static int aec62xx_config_drive_xfer_rate (ide_drive_t *drive)
211{ 211{
212 ide_hwif_t *hwif = HWIF(drive); 212 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
213 struct hd_driveid *id = drive->id; 213 return 0;
214
215 if ((id->capability & 1) && drive->autodma) {
216
217 if (ide_use_dma(drive)) {
218 if (config_chipset_for_dma(drive))
219 return hwif->ide_dma_on(drive);
220 }
221
222 goto fast_ata_pio;
223 214
224 } else if ((id->capability & 8) || (id->field_valid & 2)) { 215 if (ide_use_fast_pio(drive))
225fast_ata_pio:
226 aec62xx_tune_drive(drive, 5); 216 aec62xx_tune_drive(drive, 5);
227 return hwif->ide_dma_off_quietly(drive); 217
228 } 218 return -1;
229 /* IORDY not supported */
230 return 0;
231} 219}
232 220
233static int aec62xx_irq_timeout (ide_drive_t *drive) 221static int aec62xx_irq_timeout (ide_drive_t *drive)
@@ -286,10 +274,8 @@ static void __devinit init_hwif_aec62xx(ide_hwif_t *hwif)
286 hwif->tuneproc = &aec62xx_tune_drive; 274 hwif->tuneproc = &aec62xx_tune_drive;
287 hwif->speedproc = &aec62xx_tune_chipset; 275 hwif->speedproc = &aec62xx_tune_chipset;
288 276
289 if (hwif->pci_dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) { 277 if (hwif->pci_dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF)
290 hwif->serialized = hwif->channel; 278 hwif->serialized = hwif->channel;
291 hwif->no_dsc = 1;
292 }
293 279
294 if (hwif->mate) 280 if (hwif->mate)
295 hwif->mate->serialized = hwif->serialized; 281 hwif->mate->serialized = hwif->serialized;
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index 68df77ec50..83e0aa65a4 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/ide/pci/alim15x3.c Version 0.17 2003/01/02 2 * linux/drivers/ide/pci/alim15x3.c Version 0.21 2007/02/03
3 * 3 *
4 * Copyright (C) 1998-2000 Michel Aubry, Maintainer 4 * Copyright (C) 1998-2000 Michel Aubry, Maintainer
5 * Copyright (C) 1998-2000 Andrzej Krzysztofowicz, Maintainer 5 * Copyright (C) 1998-2000 Andrzej Krzysztofowicz, Maintainer
@@ -9,6 +9,7 @@
9 * May be copied or modified under the terms of the GNU General Public License 9 * May be copied or modified under the terms of the GNU General Public License
10 * Copyright (C) 2002 Alan Cox <alan@redhat.com> 10 * Copyright (C) 2002 Alan Cox <alan@redhat.com>
11 * ALi (now ULi M5228) support by Clear Zhang <Clear.Zhang@ali.com.tw> 11 * ALi (now ULi M5228) support by Clear Zhang <Clear.Zhang@ali.com.tw>
12 * Copyright (C) 2007 MontaVista Software, Inc. <source@mvista.com>
12 * 13 *
13 * (U)DMA capable version of ali 1533/1543(C), 1535(D) 14 * (U)DMA capable version of ali 1533/1543(C), 1535(D)
14 * 15 *
@@ -280,15 +281,17 @@ static int ali_get_info (char *buffer, char **addr, off_t offset, int count)
280#endif /* defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_PROC_FS) */ 281#endif /* defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_PROC_FS) */
281 282
282/** 283/**
283 * ali15x3_tune_drive - set up a drive 284 * ali15x3_tune_pio - set up chipset for PIO mode
284 * @drive: drive to tune 285 * @drive: drive to tune
285 * @pio: unused 286 * @pio: desired mode
286 * 287 *
287 * Select the best PIO timing for the drive in question. Then 288 * Select the best PIO mode for the drive in question.
288 * program the controller for this drive set up 289 * Then program the controller for this mode.
290 *
291 * Returns the PIO mode programmed.
289 */ 292 */
290 293
291static void ali15x3_tune_drive (ide_drive_t *drive, u8 pio) 294static u8 ali15x3_tune_pio (ide_drive_t *drive, u8 pio)
292{ 295{
293 ide_pio_data_t d; 296 ide_pio_data_t d;
294 ide_hwif_t *hwif = HWIF(drive); 297 ide_hwif_t *hwif = HWIF(drive);
@@ -356,6 +359,22 @@ static void ali15x3_tune_drive (ide_drive_t *drive, u8 pio)
356 * { 20, 50, 30 } PIO Mode 5 with IORDY (nonstandard) 359 * { 20, 50, 30 } PIO Mode 5 with IORDY (nonstandard)
357 */ 360 */
358 361
362 return pio;
363}
364
365/**
366 * ali15x3_tune_drive - set up drive for PIO mode
367 * @drive: drive to tune
368 * @pio: desired mode
369 *
370 * Program the controller with the best PIO timing for the given drive.
371 * Then set up the drive itself.
372 */
373
374static void ali15x3_tune_drive (ide_drive_t *drive, u8 pio)
375{
376 pio = ali15x3_tune_pio(drive, pio);
377 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio);
359} 378}
360 379
361/** 380/**
@@ -430,7 +449,7 @@ static u8 ali15x3_ratemask (ide_drive_t *drive)
430} 449}
431 450
432/** 451/**
433 * ali15x3_tune_chipset - set up chiset for new speed 452 * ali15x3_tune_chipset - set up chipset/drive for new speed
434 * @drive: drive to configure for 453 * @drive: drive to configure for
435 * @xferspeed: desired speed 454 * @xferspeed: desired speed
436 * 455 *
@@ -461,7 +480,7 @@ static int ali15x3_tune_chipset (ide_drive_t *drive, u8 xferspeed)
461 pci_write_config_byte(dev, m5229_udma, tmpbyte); 480 pci_write_config_byte(dev, m5229_udma, tmpbyte);
462 481
463 if (speed < XFER_SW_DMA_0) 482 if (speed < XFER_SW_DMA_0)
464 ali15x3_tune_drive(drive, speed); 483 (void) ali15x3_tune_pio(drive, speed - XFER_PIO_0);
465 } else { 484 } else {
466 pci_read_config_byte(dev, m5229_udma, &tmpbyte); 485 pci_read_config_byte(dev, m5229_udma, &tmpbyte);
467 tmpbyte &= (0x0f << ((1-unit) << 2)); 486 tmpbyte &= (0x0f << ((1-unit) << 2));
@@ -507,17 +526,15 @@ static int config_chipset_for_dma (ide_drive_t *drive)
507 * 526 *
508 * Configure a drive for DMA operation. If DMA is not possible we 527 * Configure a drive for DMA operation. If DMA is not possible we
509 * drop the drive into PIO mode instead. 528 * drop the drive into PIO mode instead.
510 *
511 * FIXME: exactly what are we trying to return here
512 */ 529 */
513 530
514static int ali15x3_config_drive_for_dma(ide_drive_t *drive) 531static int ali15x3_config_drive_for_dma(ide_drive_t *drive)
515{ 532{
516 ide_hwif_t *hwif = HWIF(drive); 533 ide_hwif_t *hwif = HWIF(drive);
517 struct hd_driveid *id = drive->id; 534 struct hd_driveid *id = drive->id;
518 535
519 if ((m5229_revision<=0x20) && (drive->media!=ide_disk)) 536 if ((m5229_revision<=0x20) && (drive->media!=ide_disk))
520 return hwif->ide_dma_off_quietly(drive); 537 goto no_dma_set;
521 538
522 drive->init_speed = 0; 539 drive->init_speed = 0;
523 540
@@ -552,9 +569,10 @@ try_dma_modes:
552ata_pio: 569ata_pio:
553 hwif->tuneproc(drive, 255); 570 hwif->tuneproc(drive, 255);
554no_dma_set: 571no_dma_set:
555 return hwif->ide_dma_off_quietly(drive); 572 return -1;
556 } 573 }
557 return hwif->ide_dma_on(drive); 574
575 return 0;
558} 576}
559 577
560/** 578/**
@@ -852,8 +870,8 @@ static void __devinit init_dma_ali15x3 (ide_hwif_t *hwif, unsigned long dmabase)
852{ 870{
853 if (m5229_revision < 0x20) 871 if (m5229_revision < 0x20)
854 return; 872 return;
855 if (!(hwif->channel)) 873 if (!hwif->channel)
856 hwif->OUTB(hwif->INB(dmabase+2) & 0x60, dmabase+2); 874 outb(inb(dmabase + 2) & 0x60, dmabase + 2);
857 ide_setup_dma(hwif, dmabase, 8); 875 ide_setup_dma(hwif, dmabase, 8);
858} 876}
859 877
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c
index a4336995a4..7989bdd842 100644
--- a/drivers/ide/pci/amd74xx.c
+++ b/drivers/ide/pci/amd74xx.c
@@ -304,8 +304,9 @@ static int amd74xx_ide_dma_check(ide_drive_t *drive)
304 amd_set_drive(drive, speed); 304 amd_set_drive(drive, speed);
305 305
306 if (drive->autodma && (speed & XFER_MODE) != XFER_PIO) 306 if (drive->autodma && (speed & XFER_MODE) != XFER_PIO)
307 return HWIF(drive)->ide_dma_on(drive); 307 return 0;
308 return HWIF(drive)->ide_dma_off_quietly(drive); 308
309 return -1;
309} 310}
310 311
311/* 312/*
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c
index 982ac31fa9..2d48af32e3 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/pci/atiixp.c
@@ -101,7 +101,7 @@ static u8 atiixp_dma_2_pio(u8 xfer_rate) {
101 } 101 }
102} 102}
103 103
104static int atiixp_ide_dma_host_on(ide_drive_t *drive) 104static void atiixp_dma_host_on(ide_drive_t *drive)
105{ 105{
106 struct pci_dev *dev = drive->hwif->pci_dev; 106 struct pci_dev *dev = drive->hwif->pci_dev;
107 unsigned long flags; 107 unsigned long flags;
@@ -118,10 +118,10 @@ static int atiixp_ide_dma_host_on(ide_drive_t *drive)
118 118
119 spin_unlock_irqrestore(&atiixp_lock, flags); 119 spin_unlock_irqrestore(&atiixp_lock, flags);
120 120
121 return __ide_dma_host_on(drive); 121 ide_dma_host_on(drive);
122} 122}
123 123
124static int atiixp_ide_dma_host_off(ide_drive_t *drive) 124static void atiixp_dma_host_off(ide_drive_t *drive)
125{ 125{
126 struct pci_dev *dev = drive->hwif->pci_dev; 126 struct pci_dev *dev = drive->hwif->pci_dev;
127 unsigned long flags; 127 unsigned long flags;
@@ -135,7 +135,7 @@ static int atiixp_ide_dma_host_off(ide_drive_t *drive)
135 135
136 spin_unlock_irqrestore(&atiixp_lock, flags); 136 spin_unlock_irqrestore(&atiixp_lock, flags);
137 137
138 return __ide_dma_host_off(drive); 138 ide_dma_host_off(drive);
139} 139}
140 140
141/** 141/**
@@ -235,11 +235,8 @@ static int atiixp_config_drive_for_dma(ide_drive_t *drive)
235{ 235{
236 u8 speed = ide_dma_speed(drive, atiixp_ratemask(drive)); 236 u8 speed = ide_dma_speed(drive, atiixp_ratemask(drive));
237 237
238 /* If no DMA speed was available then disable DMA and use PIO. */ 238 if (!speed)
239 if (!speed) { 239 return 0;
240 u8 tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL);
241 speed = atiixp_dma_2_pio(XFER_PIO_0 + tspeed) + XFER_PIO_0;
242 }
243 240
244 (void) atiixp_speedproc(drive, speed); 241 (void) atiixp_speedproc(drive, speed);
245 return ide_dma_enable(drive); 242 return ide_dma_enable(drive);
@@ -255,30 +252,20 @@ static int atiixp_config_drive_for_dma(ide_drive_t *drive)
255 252
256static int atiixp_dma_check(ide_drive_t *drive) 253static int atiixp_dma_check(ide_drive_t *drive)
257{ 254{
258 ide_hwif_t *hwif = HWIF(drive);
259 struct hd_driveid *id = drive->id;
260 u8 tspeed, speed; 255 u8 tspeed, speed;
261 256
262 drive->init_speed = 0; 257 drive->init_speed = 0;
263 258
264 if ((id->capability & 1) && drive->autodma) { 259 if (ide_use_dma(drive) && atiixp_config_drive_for_dma(drive))
265 260 return 0;
266 if (ide_use_dma(drive)) {
267 if (atiixp_config_drive_for_dma(drive))
268 return hwif->ide_dma_on(drive);
269 }
270
271 goto fast_ata_pio;
272 261
273 } else if ((id->capability & 8) || (id->field_valid & 2)) { 262 if (ide_use_fast_pio(drive)) {
274fast_ata_pio:
275 tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL); 263 tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL);
276 speed = atiixp_dma_2_pio(XFER_PIO_0 + tspeed) + XFER_PIO_0; 264 speed = atiixp_dma_2_pio(XFER_PIO_0 + tspeed) + XFER_PIO_0;
277 hwif->speedproc(drive, speed); 265 atiixp_speedproc(drive, speed);
278 return hwif->ide_dma_off_quietly(drive);
279 } 266 }
280 /* IORDY not supported */ 267
281 return 0; 268 return -1;
282} 269}
283 270
284/** 271/**
@@ -318,8 +305,8 @@ static void __devinit init_hwif_atiixp(ide_hwif_t *hwif)
318 else 305 else
319 hwif->udma_four = 0; 306 hwif->udma_four = 0;
320 307
321 hwif->ide_dma_host_on = &atiixp_ide_dma_host_on; 308 hwif->dma_host_on = &atiixp_dma_host_on;
322 hwif->ide_dma_host_off = &atiixp_ide_dma_host_off; 309 hwif->dma_host_off = &atiixp_dma_host_off;
323 hwif->ide_dma_check = &atiixp_dma_check; 310 hwif->ide_dma_check = &atiixp_dma_check;
324 if (!noautodma) 311 if (!noautodma)
325 hwif->autodma = 1; 312 hwif->autodma = 1;
diff --git a/drivers/ide/pci/cmd640.c b/drivers/ide/pci/cmd640.c
index 61b5f9c0b2..dc43f009ac 100644
--- a/drivers/ide/pci/cmd640.c
+++ b/drivers/ide/pci/cmd640.c
@@ -98,7 +98,6 @@
98 * (patch courtesy of Zoltan Hidvegi) 98 * (patch courtesy of Zoltan Hidvegi)
99 */ 99 */
100 100
101#undef REALLY_SLOW_IO /* most systems can safely undef this */
102#define CMD640_PREFETCH_MASKS 1 101#define CMD640_PREFETCH_MASKS 1
103 102
104//#define CMD640_DUMP_REGS 103//#define CMD640_DUMP_REGS
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c
index aee947e8fc..b0d4825c56 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/pci/cmd64x.c
@@ -1,6 +1,6 @@
1/* $Id: cmd64x.c,v 1.21 2000/01/30 23:23:16 1/* $Id: cmd64x.c,v 1.21 2000/01/30 23:23:16
2 * 2 *
3 * linux/drivers/ide/pci/cmd64x.c Version 1.30 Sept 10, 2002 3 * linux/drivers/ide/pci/cmd64x.c Version 1.41 Feb 3, 2007
4 * 4 *
5 * cmd64x.c: Enable interrupts at initialization time on Ultra/PCI machines. 5 * cmd64x.c: Enable interrupts at initialization time on Ultra/PCI machines.
6 * Note, this driver is not used at all on other systems because 6 * Note, this driver is not used at all on other systems because
@@ -12,6 +12,7 @@
12 * Copyright (C) 1998 David S. Miller (davem@redhat.com) 12 * Copyright (C) 1998 David S. Miller (davem@redhat.com)
13 * 13 *
14 * Copyright (C) 1999-2002 Andre Hedrick <andre@linux-ide.org> 14 * Copyright (C) 1999-2002 Andre Hedrick <andre@linux-ide.org>
15 * Copyright (C) 2007 MontaVista Software, Inc. <source@mvista.com>
15 */ 16 */
16 17
17#include <linux/module.h> 18#include <linux/module.h>
@@ -262,43 +263,25 @@ static void program_drive_counts (ide_drive_t *drive, int setup_count, int activ
262} 263}
263 264
264/* 265/*
265 * Attempts to set the interface PIO mode. 266 * This routine selects drive's best PIO mode, calculates setup/active/recovery
266 * The preferred method of selecting PIO modes (e.g. mode 4) is 267 * counts, and then writes them into the chipset registers.
267 * "echo 'piomode:4' > /proc/ide/hdx/settings". Special cases are
268 * 8: prefetch off, 9: prefetch on, 255: auto-select best mode.
269 * Called with 255 at boot time.
270 */ 268 */
271 269static u8 cmd64x_tune_pio (ide_drive_t *drive, u8 mode_wanted)
272static void cmd64x_tuneproc (ide_drive_t *drive, u8 mode_wanted)
273{ 270{
274 int setup_time, active_time, recovery_time; 271 int setup_time, active_time, recovery_time;
275 int clock_time, pio_mode, cycle_time; 272 int clock_time, pio_mode, cycle_time;
276 u8 recovery_count2, cycle_count; 273 u8 recovery_count2, cycle_count;
277 int setup_count, active_count, recovery_count; 274 int setup_count, active_count, recovery_count;
278 int bus_speed = system_bus_clock(); 275 int bus_speed = system_bus_clock();
279 /*byte b;*/
280 ide_pio_data_t d; 276 ide_pio_data_t d;
281 277
282 switch (mode_wanted) { 278 pio_mode = ide_get_best_pio_mode(drive, mode_wanted, 5, &d);
283 case 8: /* set prefetch off */
284 case 9: /* set prefetch on */
285 mode_wanted &= 1;
286 /*set_prefetch_mode(index, mode_wanted);*/
287 cmdprintk("%s: %sabled cmd640 prefetch\n",
288 drive->name, mode_wanted ? "en" : "dis");
289 return;
290 }
291
292 mode_wanted = ide_get_best_pio_mode (drive, mode_wanted, 5, &d);
293 pio_mode = d.pio_mode;
294 cycle_time = d.cycle_time; 279 cycle_time = d.cycle_time;
295 280
296 /* 281 /*
297 * I copied all this complicated stuff from cmd640.c and made a few 282 * I copied all this complicated stuff from cmd640.c and made a few
298 * minor changes. For now I am just going to pray that it is correct. 283 * minor changes. For now I am just going to pray that it is correct.
299 */ 284 */
300 if (pio_mode > 5)
301 pio_mode = 5;
302 setup_time = ide_pio_timings[pio_mode].setup_time; 285 setup_time = ide_pio_timings[pio_mode].setup_time;
303 active_time = ide_pio_timings[pio_mode].active_time; 286 active_time = ide_pio_timings[pio_mode].active_time;
304 recovery_time = cycle_time - (setup_time + active_time); 287 recovery_time = cycle_time - (setup_time + active_time);
@@ -320,22 +303,33 @@ static void cmd64x_tuneproc (ide_drive_t *drive, u8 mode_wanted)
320 if (active_count > 16) 303 if (active_count > 16)
321 active_count = 16; /* maximum allowed by cmd646 */ 304 active_count = 16; /* maximum allowed by cmd646 */
322 305
323 /*
324 * In a perfect world, we might set the drive pio mode here
325 * (using WIN_SETFEATURE) before continuing.
326 *
327 * But we do not, because:
328 * 1) this is the wrong place to do it
329 * (proper is do_special() in ide.c)
330 * 2) in practice this is rarely, if ever, necessary
331 */
332 program_drive_counts (drive, setup_count, active_count, recovery_count); 306 program_drive_counts (drive, setup_count, active_count, recovery_count);
333 307
334 cmdprintk("%s: selected cmd646 PIO mode%d : %d (%dns)%s, " 308 cmdprintk("%s: PIO mode wanted %d, selected %d (%dns)%s, "
335 "clocks=%d/%d/%d\n", 309 "clocks=%d/%d/%d\n",
336 drive->name, pio_mode, mode_wanted, cycle_time, 310 drive->name, mode_wanted, pio_mode, cycle_time,
337 d.overridden ? " (overriding vendor mode)" : "", 311 d.overridden ? " (overriding vendor mode)" : "",
338 setup_count, active_count, recovery_count); 312 setup_count, active_count, recovery_count);
313
314 return pio_mode;
315}
316
317/*
318 * Attempts to set drive's PIO mode.
319 * Special cases are 8: prefetch off, 9: prefetch on (both never worked),
320 * and 255: auto-select best mode (used at boot time).
321 */
322static void cmd64x_tune_drive (ide_drive_t *drive, u8 pio)
323{
324 /*
325 * Filter out the prefetch control values
326 * to prevent PIO5 from being programmed
327 */
328 if (pio == 8 || pio == 9)
329 return;
330
331 pio = cmd64x_tune_pio(drive, pio);
332 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio);
339} 333}
340 334
341static u8 cmd64x_ratemask (ide_drive_t *drive) 335static u8 cmd64x_ratemask (ide_drive_t *drive)
@@ -387,22 +381,6 @@ static u8 cmd64x_ratemask (ide_drive_t *drive)
387 return mode; 381 return mode;
388} 382}
389 383
390static void config_cmd64x_chipset_for_pio (ide_drive_t *drive, u8 set_speed)
391{
392 u8 speed = 0x00;
393 u8 set_pio = ide_get_best_pio_mode(drive, 4, 5, NULL);
394
395 cmd64x_tuneproc(drive, set_pio);
396 speed = XFER_PIO_0 + set_pio;
397 if (set_speed)
398 (void) ide_config_drive_speed(drive, speed);
399}
400
401static void config_chipset_for_pio (ide_drive_t *drive, u8 set_speed)
402{
403 config_cmd64x_chipset_for_pio(drive, set_speed);
404}
405
406static int cmd64x_tune_chipset (ide_drive_t *drive, u8 xferspeed) 384static int cmd64x_tune_chipset (ide_drive_t *drive, u8 xferspeed)
407{ 385{
408 ide_hwif_t *hwif = HWIF(drive); 386 ide_hwif_t *hwif = HWIF(drive);
@@ -414,7 +392,7 @@ static int cmd64x_tune_chipset (ide_drive_t *drive, u8 xferspeed)
414 392
415 u8 speed = ide_rate_filter(cmd64x_ratemask(drive), xferspeed); 393 u8 speed = ide_rate_filter(cmd64x_ratemask(drive), xferspeed);
416 394
417 if (speed > XFER_PIO_4) { 395 if (speed >= XFER_SW_DMA_0) {
418 (void) pci_read_config_byte(dev, pciD, &regD); 396 (void) pci_read_config_byte(dev, pciD, &regD);
419 (void) pci_read_config_byte(dev, pciU, &regU); 397 (void) pci_read_config_byte(dev, pciU, &regU);
420 regD &= ~(unit ? 0x40 : 0x20); 398 regD &= ~(unit ? 0x40 : 0x20);
@@ -438,17 +416,20 @@ static int cmd64x_tune_chipset (ide_drive_t *drive, u8 xferspeed)
438 case XFER_SW_DMA_2: regD |= (unit ? 0x40 : 0x10); break; 416 case XFER_SW_DMA_2: regD |= (unit ? 0x40 : 0x10); break;
439 case XFER_SW_DMA_1: regD |= (unit ? 0x80 : 0x20); break; 417 case XFER_SW_DMA_1: regD |= (unit ? 0x80 : 0x20); break;
440 case XFER_SW_DMA_0: regD |= (unit ? 0xC0 : 0x30); break; 418 case XFER_SW_DMA_0: regD |= (unit ? 0xC0 : 0x30); break;
441 case XFER_PIO_4: cmd64x_tuneproc(drive, 4); break; 419 case XFER_PIO_5:
442 case XFER_PIO_3: cmd64x_tuneproc(drive, 3); break; 420 case XFER_PIO_4:
443 case XFER_PIO_2: cmd64x_tuneproc(drive, 2); break; 421 case XFER_PIO_3:
444 case XFER_PIO_1: cmd64x_tuneproc(drive, 1); break; 422 case XFER_PIO_2:
445 case XFER_PIO_0: cmd64x_tuneproc(drive, 0); break; 423 case XFER_PIO_1:
424 case XFER_PIO_0:
425 (void) cmd64x_tune_pio(drive, speed - XFER_PIO_0);
426 break;
446 427
447 default: 428 default:
448 return 1; 429 return 1;
449 } 430 }
450 431
451 if (speed > XFER_PIO_4) { 432 if (speed >= XFER_SW_DMA_0) {
452 (void) pci_write_config_byte(dev, pciU, regU); 433 (void) pci_write_config_byte(dev, pciU, regU);
453 regD |= (unit ? 0x40 : 0x20); 434 regD |= (unit ? 0x40 : 0x20);
454 (void) pci_write_config_byte(dev, pciD, regD); 435 (void) pci_write_config_byte(dev, pciD, regD);
@@ -461,41 +442,24 @@ static int config_chipset_for_dma (ide_drive_t *drive)
461{ 442{
462 u8 speed = ide_dma_speed(drive, cmd64x_ratemask(drive)); 443 u8 speed = ide_dma_speed(drive, cmd64x_ratemask(drive));
463 444
464 config_chipset_for_pio(drive, !speed);
465
466 if (!speed) 445 if (!speed)
467 return 0; 446 return 0;
468 447
469 if(ide_set_xfer_rate(drive, speed)) 448 if (cmd64x_tune_chipset(drive, speed))
470 return 0; 449 return 0;
471
472 if (!drive->init_speed)
473 drive->init_speed = speed;
474 450
475 return ide_dma_enable(drive); 451 return ide_dma_enable(drive);
476} 452}
477 453
478static int cmd64x_config_drive_for_dma (ide_drive_t *drive) 454static int cmd64x_config_drive_for_dma (ide_drive_t *drive)
479{ 455{
480 ide_hwif_t *hwif = HWIF(drive); 456 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
481 struct hd_driveid *id = drive->id; 457 return 0;
482
483 if ((id != NULL) && ((id->capability & 1) != 0) && drive->autodma) {
484
485 if (ide_use_dma(drive)) {
486 if (config_chipset_for_dma(drive))
487 return hwif->ide_dma_on(drive);
488 }
489 458
490 goto fast_ata_pio; 459 if (ide_use_fast_pio(drive))
460 cmd64x_tune_drive(drive, 255);
491 461
492 } else if ((id->capability & 8) || (id->field_valid & 2)) { 462 return -1;
493fast_ata_pio:
494 config_chipset_for_pio(drive, 1);
495 return hwif->ide_dma_off_quietly(drive);
496 }
497 /* IORDY not supported */
498 return 0;
499} 463}
500 464
501static int cmd64x_alt_dma_status (struct pci_dev *dev) 465static int cmd64x_alt_dma_status (struct pci_dev *dev)
@@ -518,13 +482,13 @@ static int cmd64x_ide_dma_end (ide_drive_t *drive)
518 482
519 drive->waiting_for_dma = 0; 483 drive->waiting_for_dma = 0;
520 /* read DMA command state */ 484 /* read DMA command state */
521 dma_cmd = hwif->INB(hwif->dma_command); 485 dma_cmd = inb(hwif->dma_command);
522 /* stop DMA */ 486 /* stop DMA */
523 hwif->OUTB((dma_cmd & ~1), hwif->dma_command); 487 outb(dma_cmd & ~1, hwif->dma_command);
524 /* get DMA status */ 488 /* get DMA status */
525 dma_stat = hwif->INB(hwif->dma_status); 489 dma_stat = inb(hwif->dma_status);
526 /* clear the INTR & ERROR bits */ 490 /* clear the INTR & ERROR bits */
527 hwif->OUTB(dma_stat|6, hwif->dma_status); 491 outb(dma_stat | 6, hwif->dma_status);
528 if (cmd64x_alt_dma_status(dev)) { 492 if (cmd64x_alt_dma_status(dev)) {
529 u8 dma_intr = 0; 493 u8 dma_intr = 0;
530 u8 dma_mask = (hwif->channel) ? ARTTIM23_INTR_CH1 : 494 u8 dma_mask = (hwif->channel) ? ARTTIM23_INTR_CH1 :
@@ -546,7 +510,7 @@ static int cmd64x_ide_dma_test_irq (ide_drive_t *drive)
546 struct pci_dev *dev = hwif->pci_dev; 510 struct pci_dev *dev = hwif->pci_dev;
547 u8 dma_alt_stat = 0, mask = (hwif->channel) ? MRDMODE_INTR_CH1 : 511 u8 dma_alt_stat = 0, mask = (hwif->channel) ? MRDMODE_INTR_CH1 :
548 MRDMODE_INTR_CH0; 512 MRDMODE_INTR_CH0;
549 u8 dma_stat = hwif->INB(hwif->dma_status); 513 u8 dma_stat = inb(hwif->dma_status);
550 514
551 (void) pci_read_config_byte(dev, MRDMODE, &dma_alt_stat); 515 (void) pci_read_config_byte(dev, MRDMODE, &dma_alt_stat);
552#ifdef DEBUG 516#ifdef DEBUG
@@ -576,13 +540,13 @@ static int cmd646_1_ide_dma_end (ide_drive_t *drive)
576 540
577 drive->waiting_for_dma = 0; 541 drive->waiting_for_dma = 0;
578 /* get DMA status */ 542 /* get DMA status */
579 dma_stat = hwif->INB(hwif->dma_status); 543 dma_stat = inb(hwif->dma_status);
580 /* read DMA command state */ 544 /* read DMA command state */
581 dma_cmd = hwif->INB(hwif->dma_command); 545 dma_cmd = inb(hwif->dma_command);
582 /* stop DMA */ 546 /* stop DMA */
583 hwif->OUTB((dma_cmd & ~1), hwif->dma_command); 547 outb(dma_cmd & ~1, hwif->dma_command);
584 /* clear the INTR & ERROR bits */ 548 /* clear the INTR & ERROR bits */
585 hwif->OUTB(dma_stat|6, hwif->dma_status); 549 outb(dma_stat | 6, hwif->dma_status);
586 /* and free any DMA resources */ 550 /* and free any DMA resources */
587 ide_destroy_dmatable(drive); 551 ide_destroy_dmatable(drive);
588 /* verify good DMA status */ 552 /* verify good DMA status */
@@ -694,14 +658,13 @@ static void __devinit init_hwif_cmd64x(ide_hwif_t *hwif)
694 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev); 658 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
695 class_rev &= 0xff; 659 class_rev &= 0xff;
696 660
697 hwif->tuneproc = &cmd64x_tuneproc; 661 hwif->tuneproc = &cmd64x_tune_drive;
698 hwif->speedproc = &cmd64x_tune_chipset; 662 hwif->speedproc = &cmd64x_tune_chipset;
699 663
700 if (!hwif->dma_base) { 664 hwif->drives[0].autotune = hwif->drives[1].autotune = 1;
701 hwif->drives[0].autotune = 1; 665
702 hwif->drives[1].autotune = 1; 666 if (!hwif->dma_base)
703 return; 667 return;
704 }
705 668
706 hwif->atapi_dma = 1; 669 hwif->atapi_dma = 1;
707 670
diff --git a/drivers/ide/pci/cs5520.c b/drivers/ide/pci/cs5520.c
index ba6786aabf..400859a839 100644
--- a/drivers/ide/pci/cs5520.c
+++ b/drivers/ide/pci/cs5520.c
@@ -132,12 +132,11 @@ static void cs5520_tune_drive(ide_drive_t *drive, u8 pio)
132 132
133static int cs5520_config_drive_xfer_rate(ide_drive_t *drive) 133static int cs5520_config_drive_xfer_rate(ide_drive_t *drive)
134{ 134{
135 ide_hwif_t *hwif = HWIF(drive);
136
137 /* Tune the drive for PIO modes up to PIO 4 */ 135 /* Tune the drive for PIO modes up to PIO 4 */
138 cs5520_tune_drive(drive, 4); 136 cs5520_tune_drive(drive, 4);
137
139 /* Then tell the core to use DMA operations */ 138 /* Then tell the core to use DMA operations */
140 return hwif->ide_dma_on(drive); 139 return 0;
141} 140}
142 141
143/* 142/*
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/pci/cs5530.c
index 9bf5fdfc5b..b2d7c132ef 100644
--- a/drivers/ide/pci/cs5530.c
+++ b/drivers/ide/pci/cs5530.c
@@ -81,8 +81,8 @@ static void cs5530_tuneproc (ide_drive_t *drive, u8 pio) /* pio=255 means "autot
81 81
82 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 82 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
83 if (!cs5530_set_xfer_mode(drive, modes[pio])) { 83 if (!cs5530_set_xfer_mode(drive, modes[pio])) {
84 format = (hwif->INL(basereg+4) >> 31) & 1; 84 format = (inl(basereg + 4) >> 31) & 1;
85 hwif->OUTL(cs5530_pio_timings[format][pio], 85 outl(cs5530_pio_timings[format][pio],
86 basereg+(drive->select.b.unit<<3)); 86 basereg+(drive->select.b.unit<<3));
87 } 87 }
88} 88}
@@ -103,16 +103,13 @@ static int cs5530_config_dma (ide_drive_t *drive)
103 int unit = drive->select.b.unit; 103 int unit = drive->select.b.unit;
104 ide_drive_t *mate = &hwif->drives[unit^1]; 104 ide_drive_t *mate = &hwif->drives[unit^1];
105 struct hd_driveid *id = drive->id; 105 struct hd_driveid *id = drive->id;
106 unsigned int reg, timings; 106 unsigned int reg, timings = 0;
107 unsigned long basereg; 107 unsigned long basereg;
108 108
109 /* 109 /*
110 * Default to DMA-off in case we run into trouble here. 110 * Default to DMA-off in case we run into trouble here.
111 */ 111 */
112 hwif->ide_dma_off_quietly(drive); 112 hwif->dma_off_quietly(drive);
113 /* turn off DMA while we fiddle */
114 hwif->ide_dma_host_off(drive);
115 /* clear DMA_capable bit */
116 113
117 /* 114 /*
118 * The CS5530 specifies that two drives sharing a cable cannot 115 * The CS5530 specifies that two drives sharing a cable cannot
@@ -182,30 +179,24 @@ static int cs5530_config_dma (ide_drive_t *drive)
182 case XFER_MW_DMA_1: timings = 0x00012121; break; 179 case XFER_MW_DMA_1: timings = 0x00012121; break;
183 case XFER_MW_DMA_2: timings = 0x00002020; break; 180 case XFER_MW_DMA_2: timings = 0x00002020; break;
184 default: 181 default:
185 printk(KERN_ERR "%s: cs5530_config_dma: huh? mode=%02x\n", 182 BUG();
186 drive->name, mode); 183 break;
187 return 1; /* failure */
188 } 184 }
189 basereg = CS5530_BASEREG(hwif); 185 basereg = CS5530_BASEREG(hwif);
190 reg = hwif->INL(basereg+4); /* get drive0 config register */ 186 reg = inl(basereg + 4); /* get drive0 config register */
191 timings |= reg & 0x80000000; /* preserve PIO format bit */ 187 timings |= reg & 0x80000000; /* preserve PIO format bit */
192 if (unit == 0) { /* are we configuring drive0? */ 188 if (unit == 0) { /* are we configuring drive0? */
193 hwif->OUTL(timings, basereg+4); /* write drive0 config register */ 189 outl(timings, basereg + 4); /* write drive0 config register */
194 } else { 190 } else {
195 if (timings & 0x00100000) 191 if (timings & 0x00100000)
196 reg |= 0x00100000; /* enable UDMA timings for both drives */ 192 reg |= 0x00100000; /* enable UDMA timings for both drives */
197 else 193 else
198 reg &= ~0x00100000; /* disable UDMA timings for both drives */ 194 reg &= ~0x00100000; /* disable UDMA timings for both drives */
199 hwif->OUTL(reg, basereg+4); /* write drive0 config register */ 195 outl(reg, basereg + 4); /* write drive0 config register */
200 hwif->OUTL(timings, basereg+12); /* write drive1 config register */ 196 outl(timings, basereg + 12); /* write drive1 config register */
201 } 197 }
202 (void) hwif->ide_dma_host_on(drive);
203 /* set DMA_capable bit */
204 198
205 /* 199 return 0; /* success */
206 * Finally, turn DMA on in software, and exit.
207 */
208 return hwif->ide_dma_on(drive); /* success */
209} 200}
210 201
211/** 202/**
@@ -321,17 +312,17 @@ static void __devinit init_hwif_cs5530 (ide_hwif_t *hwif)
321 312
322 hwif->tuneproc = &cs5530_tuneproc; 313 hwif->tuneproc = &cs5530_tuneproc;
323 basereg = CS5530_BASEREG(hwif); 314 basereg = CS5530_BASEREG(hwif);
324 d0_timings = hwif->INL(basereg+0); 315 d0_timings = inl(basereg + 0);
325 if (CS5530_BAD_PIO(d0_timings)) { 316 if (CS5530_BAD_PIO(d0_timings)) {
326 /* PIO timings not initialized? */ 317 /* PIO timings not initialized? */
327 hwif->OUTL(cs5530_pio_timings[(d0_timings>>31)&1][0], basereg+0); 318 outl(cs5530_pio_timings[(d0_timings >> 31) & 1][0], basereg + 0);
328 if (!hwif->drives[0].autotune) 319 if (!hwif->drives[0].autotune)
329 hwif->drives[0].autotune = 1; 320 hwif->drives[0].autotune = 1;
330 /* needs autotuning later */ 321 /* needs autotuning later */
331 } 322 }
332 if (CS5530_BAD_PIO(hwif->INL(basereg+8))) { 323 if (CS5530_BAD_PIO(inl(basereg + 8))) {
333 /* PIO timings not initialized? */ 324 /* PIO timings not initialized? */
334 hwif->OUTL(cs5530_pio_timings[(d0_timings>>31)&1][0], basereg+8); 325 outl(cs5530_pio_timings[(d0_timings >> 31) & 1][0], basereg + 8);
335 if (!hwif->drives[1].autotune) 326 if (!hwif->drives[1].autotune)
336 hwif->drives[1].autotune = 1; 327 hwif->drives[1].autotune = 1;
337 /* needs autotuning later */ 328 /* needs autotuning later */
diff --git a/drivers/ide/pci/cs5535.c b/drivers/ide/pci/cs5535.c
index 5c5aec28e6..45f43efbf9 100644
--- a/drivers/ide/pci/cs5535.c
+++ b/drivers/ide/pci/cs5535.c
@@ -195,28 +195,19 @@ static int cs5535_config_drive_for_dma(ide_drive_t *drive)
195 195
196static int cs5535_dma_check(ide_drive_t *drive) 196static int cs5535_dma_check(ide_drive_t *drive)
197{ 197{
198 ide_hwif_t *hwif = drive->hwif;
199 struct hd_driveid *id = drive->id;
200 u8 speed; 198 u8 speed;
201 199
202 drive->init_speed = 0; 200 drive->init_speed = 0;
203 201
204 if ((id->capability & 1) && drive->autodma) { 202 if (ide_use_dma(drive) && cs5535_config_drive_for_dma(drive))
205 if (ide_use_dma(drive)) { 203 return 0;
206 if (cs5535_config_drive_for_dma(drive))
207 return hwif->ide_dma_on(drive);
208 }
209
210 goto fast_ata_pio;
211 204
212 } else if ((id->capability & 8) || (id->field_valid & 2)) { 205 if (ide_use_fast_pio(drive)) {
213fast_ata_pio:
214 speed = ide_get_best_pio_mode(drive, 255, 4, NULL); 206 speed = ide_get_best_pio_mode(drive, 255, 4, NULL);
215 cs5535_set_drive(drive, speed); 207 cs5535_set_drive(drive, speed);
216 return hwif->ide_dma_off_quietly(drive);
217 } 208 }
218 /* IORDY not supported */ 209
219 return 0; 210 return -1;
220} 211}
221 212
222static u8 __devinit cs5535_cable_detect(struct pci_dev *dev) 213static u8 __devinit cs5535_cable_detect(struct pci_dev *dev)
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/pci/cy82c693.c
index 9eafcbf444..103b9db978 100644
--- a/drivers/ide/pci/cy82c693.c
+++ b/drivers/ide/pci/cy82c693.c
@@ -197,8 +197,8 @@ static void cy82c693_dma_enable (ide_drive_t *drive, int mode, int single)
197#if CY82C693_DEBUG_LOGS 197#if CY82C693_DEBUG_LOGS
198 /* for debug let's show the previous values */ 198 /* for debug let's show the previous values */
199 199
200 HWIF(drive)->OUTB(index, CY82_INDEX_PORT); 200 outb(index, CY82_INDEX_PORT);
201 data = HWIF(drive)->INB(CY82_DATA_PORT); 201 data = inb(CY82_DATA_PORT);
202 202
203 printk (KERN_INFO "%s (ch=%d, dev=%d): DMA mode is %d (single=%d)\n", 203 printk (KERN_INFO "%s (ch=%d, dev=%d): DMA mode is %d (single=%d)\n",
204 drive->name, HWIF(drive)->channel, drive->select.b.unit, 204 drive->name, HWIF(drive)->channel, drive->select.b.unit,
@@ -207,8 +207,8 @@ static void cy82c693_dma_enable (ide_drive_t *drive, int mode, int single)
207 207
208 data = (u8)mode|(u8)(single<<2); 208 data = (u8)mode|(u8)(single<<2);
209 209
210 HWIF(drive)->OUTB(index, CY82_INDEX_PORT); 210 outb(index, CY82_INDEX_PORT);
211 HWIF(drive)->OUTB(data, CY82_DATA_PORT); 211 outb(data, CY82_DATA_PORT);
212 212
213#if CY82C693_DEBUG_INFO 213#if CY82C693_DEBUG_INFO
214 printk(KERN_INFO "%s (ch=%d, dev=%d): set DMA mode to %d (single=%d)\n", 214 printk(KERN_INFO "%s (ch=%d, dev=%d): set DMA mode to %d (single=%d)\n",
@@ -227,8 +227,8 @@ static void cy82c693_dma_enable (ide_drive_t *drive, int mode, int single)
227 */ 227 */
228 228
229 data = BUSMASTER_TIMEOUT; 229 data = BUSMASTER_TIMEOUT;
230 HWIF(drive)->OUTB(CY82_INDEX_TIMEOUT, CY82_INDEX_PORT); 230 outb(CY82_INDEX_TIMEOUT, CY82_INDEX_PORT);
231 HWIF(drive)->OUTB(data, CY82_DATA_PORT); 231 outb(data, CY82_DATA_PORT);
232 232
233#if CY82C693_DEBUG_INFO 233#if CY82C693_DEBUG_INFO
234 printk (KERN_INFO "%s: Set IDE Bus Master TimeOut Register to 0x%X\n", 234 printk (KERN_INFO "%s: Set IDE Bus Master TimeOut Register to 0x%X\n",
@@ -478,21 +478,18 @@ static void __devinit init_iops_cy82c693(ide_hwif_t *hwif)
478 } 478 }
479} 479}
480 480
481static ide_pci_device_t cy82c693_chipsets[] __devinitdata = { 481static ide_pci_device_t cy82c693_chipset __devinitdata = {
482 { /* 0 */ 482 .name = "CY82C693",
483 .name = "CY82C693", 483 .init_chipset = init_chipset_cy82c693,
484 .init_chipset = init_chipset_cy82c693, 484 .init_iops = init_iops_cy82c693,
485 .init_iops = init_iops_cy82c693, 485 .init_hwif = init_hwif_cy82c693,
486 .init_hwif = init_hwif_cy82c693, 486 .channels = 1,
487 .channels = 1, 487 .autodma = AUTODMA,
488 .autodma = AUTODMA, 488 .bootable = ON_BOARD,
489 .bootable = ON_BOARD,
490 }
491}; 489};
492 490
493static int __devinit cy82c693_init_one(struct pci_dev *dev, const struct pci_device_id *id) 491static int __devinit cy82c693_init_one(struct pci_dev *dev, const struct pci_device_id *id)
494{ 492{
495 ide_pci_device_t *d = &cy82c693_chipsets[id->driver_data];
496 struct pci_dev *dev2; 493 struct pci_dev *dev2;
497 int ret = -ENODEV; 494 int ret = -ENODEV;
498 495
@@ -501,7 +498,7 @@ static int __devinit cy82c693_init_one(struct pci_dev *dev, const struct pci_dev
501 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && 498 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE &&
502 PCI_FUNC(dev->devfn) == 1) { 499 PCI_FUNC(dev->devfn) == 1) {
503 dev2 = pci_get_slot(dev->bus, dev->devfn + 1); 500 dev2 = pci_get_slot(dev->bus, dev->devfn + 1);
504 ret = ide_setup_pci_devices(dev, dev2, d); 501 ret = ide_setup_pci_devices(dev, dev2, &cy82c693_chipset);
505 /* We leak pci refs here but thats ok - we can't be unloaded */ 502 /* We leak pci refs here but thats ok - we can't be unloaded */
506 } 503 }
507 return ret; 504 return ret;
diff --git a/drivers/ide/pci/delkin_cb.c b/drivers/ide/pci/delkin_cb.c
index e2672fc65d..d4b753e701 100644
--- a/drivers/ide/pci/delkin_cb.c
+++ b/drivers/ide/pci/delkin_cb.c
@@ -122,7 +122,7 @@ static struct pci_driver driver = {
122static int 122static int
123delkin_cb_init (void) 123delkin_cb_init (void)
124{ 124{
125 return pci_module_init(&driver); 125 return pci_register_driver(&driver);
126} 126}
127 127
128static void 128static void
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c
index b408c6c517..f2c5a141ca 100644
--- a/drivers/ide/pci/generic.c
+++ b/drivers/ide/pci/generic.c
@@ -21,8 +21,6 @@
21 * are deemed to be part of the source code. 21 * are deemed to be part of the source code.
22 */ 22 */
23 23
24#undef REALLY_SLOW_IO /* most systems can safely undef this */
25
26#include <linux/types.h> 24#include <linux/types.h>
27#include <linux/module.h> 25#include <linux/module.h>
28#include <linux/kernel.h> 26#include <linux/kernel.h>
diff --git a/drivers/ide/pci/hpt34x.c b/drivers/ide/pci/hpt34x.c
index ce7b08f08a..924eaa3a57 100644
--- a/drivers/ide/pci/hpt34x.c
+++ b/drivers/ide/pci/hpt34x.c
@@ -48,19 +48,6 @@ static u8 hpt34x_ratemask (ide_drive_t *drive)
48 return 1; 48 return 1;
49} 49}
50 50
51static void hpt34x_clear_chipset (ide_drive_t *drive)
52{
53 struct pci_dev *dev = HWIF(drive)->pci_dev;
54 u32 reg1 = 0, tmp1 = 0, reg2 = 0, tmp2 = 0;
55
56 pci_read_config_dword(dev, 0x44, &reg1);
57 pci_read_config_dword(dev, 0x48, &reg2);
58 tmp1 = ((0x00 << (3*drive->dn)) | (reg1 & ~(7 << (3*drive->dn))));
59 tmp2 = (reg2 & ~(0x11 << drive->dn));
60 pci_write_config_dword(dev, 0x44, tmp1);
61 pci_write_config_dword(dev, 0x48, tmp2);
62}
63
64static int hpt34x_tune_chipset (ide_drive_t *drive, u8 xferspeed) 51static int hpt34x_tune_chipset (ide_drive_t *drive, u8 xferspeed)
65{ 52{
66 struct pci_dev *dev = HWIF(drive)->pci_dev; 53 struct pci_dev *dev = HWIF(drive)->pci_dev;
@@ -81,7 +68,7 @@ static int hpt34x_tune_chipset (ide_drive_t *drive, u8 xferspeed)
81 pci_read_config_dword(dev, 0x44, &reg1); 68 pci_read_config_dword(dev, 0x44, &reg1);
82 pci_read_config_dword(dev, 0x48, &reg2); 69 pci_read_config_dword(dev, 0x48, &reg2);
83 tmp1 = ((lo_speed << (3*drive->dn)) | (reg1 & ~(7 << (3*drive->dn)))); 70 tmp1 = ((lo_speed << (3*drive->dn)) | (reg1 & ~(7 << (3*drive->dn))));
84 tmp2 = ((hi_speed << drive->dn) | reg2); 71 tmp2 = ((hi_speed << drive->dn) | (reg2 & ~(0x11 << drive->dn)));
85 pci_write_config_dword(dev, 0x44, tmp1); 72 pci_write_config_dword(dev, 0x44, tmp1);
86 pci_write_config_dword(dev, 0x48, tmp2); 73 pci_write_config_dword(dev, 0x48, tmp2);
87 74
@@ -99,7 +86,6 @@ static int hpt34x_tune_chipset (ide_drive_t *drive, u8 xferspeed)
99static void hpt34x_tune_drive (ide_drive_t *drive, u8 pio) 86static void hpt34x_tune_drive (ide_drive_t *drive, u8 pio)
100{ 87{
101 pio = ide_get_best_pio_mode(drive, pio, 5, NULL); 88 pio = ide_get_best_pio_mode(drive, pio, 5, NULL);
102 hpt34x_clear_chipset(drive);
103 (void) hpt34x_tune_chipset(drive, (XFER_PIO_0 + pio)); 89 (void) hpt34x_tune_chipset(drive, (XFER_PIO_0 + pio));
104} 90}
105 91
@@ -117,38 +103,25 @@ static int config_chipset_for_dma (ide_drive_t *drive)
117 if (!(speed)) 103 if (!(speed))
118 return 0; 104 return 0;
119 105
120 hpt34x_clear_chipset(drive);
121 (void) hpt34x_tune_chipset(drive, speed); 106 (void) hpt34x_tune_chipset(drive, speed);
122 return ide_dma_enable(drive); 107 return ide_dma_enable(drive);
123} 108}
124 109
125static int hpt34x_config_drive_xfer_rate (ide_drive_t *drive) 110static int hpt34x_config_drive_xfer_rate (ide_drive_t *drive)
126{ 111{
127 ide_hwif_t *hwif = HWIF(drive);
128 struct hd_driveid *id = drive->id;
129
130 drive->init_speed = 0; 112 drive->init_speed = 0;
131 113
132 if (id && (id->capability & 1) && drive->autodma) { 114 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
133
134 if (ide_use_dma(drive)) {
135 if (config_chipset_for_dma(drive))
136#ifndef CONFIG_HPT34X_AUTODMA 115#ifndef CONFIG_HPT34X_AUTODMA
137 return hwif->ide_dma_off_quietly(drive); 116 return -1;
138#else 117#else
139 return hwif->ide_dma_on(drive); 118 return 0;
140#endif 119#endif
141 }
142
143 goto fast_ata_pio;
144 120
145 } else if ((id->capability & 8) || (id->field_valid & 2)) { 121 if (ide_use_fast_pio(drive))
146fast_ata_pio:
147 hpt34x_tune_drive(drive, 255); 122 hpt34x_tune_drive(drive, 255);
148 return hwif->ide_dma_off_quietly(drive); 123
149 } 124 return -1;
150 /* IORDY not supported */
151 return 0;
152} 125}
153 126
154/* 127/*
@@ -209,7 +182,6 @@ static void __devinit init_hwif_hpt34x(ide_hwif_t *hwif)
209 182
210 hwif->tuneproc = &hpt34x_tune_drive; 183 hwif->tuneproc = &hpt34x_tune_drive;
211 hwif->speedproc = &hpt34x_tune_chipset; 184 hwif->speedproc = &hpt34x_tune_chipset;
212 hwif->no_dsc = 1;
213 hwif->drives[0].autotune = 1; 185 hwif->drives[0].autotune = 1;
214 hwif->drives[1].autotune = 1; 186 hwif->drives[1].autotune = 1;
215 187
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index 05be8fadda..60ecdc258c 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -736,24 +736,15 @@ static void hpt3xx_maskproc(ide_drive_t *drive, int mask)
736 736
737static int hpt366_config_drive_xfer_rate(ide_drive_t *drive) 737static int hpt366_config_drive_xfer_rate(ide_drive_t *drive)
738{ 738{
739 ide_hwif_t *hwif = HWIF(drive);
740 struct hd_driveid *id = drive->id;
741
742 drive->init_speed = 0; 739 drive->init_speed = 0;
743 740
744 if ((id->capability & 1) && drive->autodma) { 741 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
745 if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 742 return 0;
746 return hwif->ide_dma_on(drive);
747
748 goto fast_ata_pio;
749 743
750 } else if ((id->capability & 8) || (id->field_valid & 2)) { 744 if (ide_use_fast_pio(drive))
751fast_ata_pio:
752 hpt3xx_tune_drive(drive, 255); 745 hpt3xx_tune_drive(drive, 255);
753 return hwif->ide_dma_off_quietly(drive); 746
754 } 747 return -1;
755 /* IORDY not supported */
756 return 0;
757} 748}
758 749
759/* 750/*
@@ -841,7 +832,7 @@ static int hpt374_ide_dma_test_irq(ide_drive_t *drive)
841 return 0; 832 return 0;
842 } 833 }
843 834
844 dma_stat = hwif->INB(hwif->dma_status); 835 dma_stat = inb(hwif->dma_status);
845 /* return 1 if INTR asserted */ 836 /* return 1 if INTR asserted */
846 if (dma_stat & 4) 837 if (dma_stat & 4)
847 return 1; 838 return 1;
@@ -1391,9 +1382,6 @@ static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase)
1391 u8 dma_new = 0, dma_old = 0; 1382 u8 dma_new = 0, dma_old = 0;
1392 unsigned long flags; 1383 unsigned long flags;
1393 1384
1394 if (!dmabase)
1395 return;
1396
1397 dma_old = hwif->INB(dmabase + 2); 1385 dma_old = hwif->INB(dmabase + 2);
1398 1386
1399 local_irq_save(flags); 1387 local_irq_save(flags);
diff --git a/drivers/ide/pci/it8213.c b/drivers/ide/pci/it8213.c
index 63248b6909..424f00bb16 100644
--- a/drivers/ide/pci/it8213.c
+++ b/drivers/ide/pci/it8213.c
@@ -244,17 +244,15 @@ static int config_chipset_for_dma (ide_drive_t *drive)
244 244
245static int it8213_config_drive_for_dma (ide_drive_t *drive) 245static int it8213_config_drive_for_dma (ide_drive_t *drive)
246{ 246{
247 ide_hwif_t *hwif = drive->hwif; 247 u8 pio;
248 248
249 if (ide_use_dma(drive)) { 249 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
250 if (config_chipset_for_dma(drive)) 250 return 0;
251 return hwif->ide_dma_on(drive);
252 }
253 251
254 hwif->speedproc(drive, XFER_PIO_0 252 pio = ide_get_best_pio_mode(drive, 255, 4, NULL);
255 + ide_get_best_pio_mode(drive, 255, 4, NULL)); 253 it8213_tune_chipset(drive, XFER_PIO_0 + pio);
256 254
257 return hwif->ide_dma_off_quietly(drive); 255 return -1;
258} 256}
259 257
260/** 258/**
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c
index e9bad18596..a132767f7d 100644
--- a/drivers/ide/pci/it821x.c
+++ b/drivers/ide/pci/it821x.c
@@ -520,14 +520,12 @@ static int config_chipset_for_dma (ide_drive_t *drive)
520 520
521static int it821x_config_drive_for_dma (ide_drive_t *drive) 521static int it821x_config_drive_for_dma (ide_drive_t *drive)
522{ 522{
523 ide_hwif_t *hwif = drive->hwif; 523 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
524 return 0;
524 525
525 if (ide_use_dma(drive)) {
526 if (config_chipset_for_dma(drive))
527 return hwif->ide_dma_on(drive);
528 }
529 config_it821x_chipset_for_pio(drive, 1); 526 config_it821x_chipset_for_pio(drive, 1);
530 return hwif->ide_dma_off_quietly(drive); 527
528 return -1;
531} 529}
532 530
533/** 531/**
@@ -608,11 +606,11 @@ static void __devinit it821x_fixups(ide_hwif_t *hwif)
608 printk(".\n"); 606 printk(".\n");
609 /* Now the core code will have wrongly decided no DMA 607 /* Now the core code will have wrongly decided no DMA
610 so we need to fix this */ 608 so we need to fix this */
611 hwif->ide_dma_off_quietly(drive); 609 hwif->dma_off_quietly(drive);
612#ifdef CONFIG_IDEDMA_ONLYDISK 610#ifdef CONFIG_IDEDMA_ONLYDISK
613 if (drive->media == ide_disk) 611 if (drive->media == ide_disk)
614#endif 612#endif
615 hwif->ide_dma_check(drive); 613 ide_set_dma(drive);
616 } else { 614 } else {
617 /* Non RAID volume. Fixups to stop the core code 615 /* Non RAID volume. Fixups to stop the core code
618 doing unsupported things */ 616 doing unsupported things */
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/pci/jmicron.c
index f07bbbed17..53f25500c2 100644
--- a/drivers/ide/pci/jmicron.c
+++ b/drivers/ide/pci/jmicron.c
@@ -147,7 +147,9 @@ static int config_chipset_for_dma (ide_drive_t *drive)
147{ 147{
148 u8 speed = ide_dma_speed(drive, jmicron_ratemask(drive)); 148 u8 speed = ide_dma_speed(drive, jmicron_ratemask(drive));
149 149
150 config_jmicron_chipset_for_pio(drive, !speed); 150 if (!speed)
151 return 0;
152
151 jmicron_tune_chipset(drive, speed); 153 jmicron_tune_chipset(drive, speed);
152 return ide_dma_enable(drive); 154 return ide_dma_enable(drive);
153} 155}
@@ -162,14 +164,12 @@ static int config_chipset_for_dma (ide_drive_t *drive)
162 164
163static int jmicron_config_drive_for_dma (ide_drive_t *drive) 165static int jmicron_config_drive_for_dma (ide_drive_t *drive)
164{ 166{
165 ide_hwif_t *hwif = drive->hwif; 167 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
168 return 0;
166 169
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); 170 config_jmicron_chipset_for_pio(drive, 1);
172 return hwif->ide_dma_off_quietly(drive); 171
172 return -1;
173} 173}
174 174
175/** 175/**
diff --git a/drivers/ide/pci/ns87415.c b/drivers/ide/pci/ns87415.c
index 8aaea4ea55..b310c4f510 100644
--- a/drivers/ide/pci/ns87415.c
+++ b/drivers/ide/pci/ns87415.c
@@ -166,10 +166,10 @@ static int ns87415_ide_dma_end (ide_drive_t *drive)
166 /* get dma command mode */ 166 /* get dma command mode */
167 dma_cmd = hwif->INB(hwif->dma_command); 167 dma_cmd = hwif->INB(hwif->dma_command);
168 /* stop DMA */ 168 /* stop DMA */
169 hwif->OUTB(dma_cmd & ~1, hwif->dma_command); 169 outb(dma_cmd & ~1, hwif->dma_command);
170 /* from ERRATA: clear the INTR & ERROR bits */ 170 /* from ERRATA: clear the INTR & ERROR bits */
171 dma_cmd = hwif->INB(hwif->dma_command); 171 dma_cmd = hwif->INB(hwif->dma_command);
172 hwif->OUTB(dma_cmd|6, hwif->dma_command); 172 outb(dma_cmd | 6, hwif->dma_command);
173 /* and free any DMA resources */ 173 /* and free any DMA resources */
174 ide_destroy_dmatable(drive); 174 ide_destroy_dmatable(drive);
175 /* verify good DMA status */ 175 /* verify good DMA status */
@@ -190,7 +190,8 @@ static int ns87415_ide_dma_setup(ide_drive_t *drive)
190static int ns87415_ide_dma_check (ide_drive_t *drive) 190static int ns87415_ide_dma_check (ide_drive_t *drive)
191{ 191{
192 if (drive->media != ide_disk) 192 if (drive->media != ide_disk)
193 return HWIF(drive)->ide_dma_off_quietly(drive); 193 return -1;
194
194 return __ide_dma_check(drive); 195 return __ide_dma_check(drive);
195} 196}
196 197
@@ -243,9 +244,9 @@ static void __devinit init_hwif_ns87415 (ide_hwif_t *hwif)
243 * to SELECT_DRIVE() properly during first probe_hwif(). 244 * to SELECT_DRIVE() properly during first probe_hwif().
244 */ 245 */
245 timeout = 10000; 246 timeout = 10000;
246 hwif->OUTB(12, hwif->io_ports[IDE_CONTROL_OFFSET]); 247 outb(12, hwif->io_ports[IDE_CONTROL_OFFSET]);
247 udelay(10); 248 udelay(10);
248 hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]); 249 outb(8, hwif->io_ports[IDE_CONTROL_OFFSET]);
249 do { 250 do {
250 udelay(50); 251 udelay(50);
251 stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]); 252 stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]);
@@ -263,7 +264,7 @@ static void __devinit init_hwif_ns87415 (ide_hwif_t *hwif)
263 if (!hwif->dma_base) 264 if (!hwif->dma_base)
264 return; 265 return;
265 266
266 hwif->OUTB(0x60, hwif->dma_status); 267 outb(0x60, hwif->dma_status);
267 hwif->dma_setup = &ns87415_ide_dma_setup; 268 hwif->dma_setup = &ns87415_ide_dma_setup;
268 hwif->ide_dma_check = &ns87415_ide_dma_check; 269 hwif->ide_dma_check = &ns87415_ide_dma_check;
269 hwif->ide_dma_end = &ns87415_ide_dma_end; 270 hwif->ide_dma_end = &ns87415_ide_dma_end;
diff --git a/drivers/ide/pci/opti621.c b/drivers/ide/pci/opti621.c
index 22bbf613f9..aede7eee92 100644
--- a/drivers/ide/pci/opti621.c
+++ b/drivers/ide/pci/opti621.c
@@ -57,7 +57,7 @@
57 * There is a 25/33MHz switch in configuration 57 * There is a 25/33MHz switch in configuration
58 * register, but driver is written for use at any frequency which get 58 * register, but driver is written for use at any frequency which get
59 * (use idebus=xx to select PCI bus speed). 59 * (use idebus=xx to select PCI bus speed).
60 * Use ide0=autotune for automatical tune of the PIO modes. 60 * Use hda=autotune and hdb=autotune for automatical tune of the PIO modes.
61 * If you get strange results, do not use this and set PIO manually 61 * If you get strange results, do not use this and set PIO manually
62 * by hdparm. 62 * by hdparm.
63 * 63 *
@@ -87,7 +87,6 @@
87 * 0.5 doesn't work. 87 * 0.5 doesn't work.
88 */ 88 */
89 89
90#undef REALLY_SLOW_IO /* most systems can safely undef this */
91#define OPTI621_DEBUG /* define for debug messages */ 90#define OPTI621_DEBUG /* define for debug messages */
92 91
93#include <linux/types.h> 92#include <linux/types.h>
@@ -176,34 +175,35 @@ static int cmpt_clk(int time, int bus_speed)
176 return ((time*bus_speed+999)/1000); 175 return ((time*bus_speed+999)/1000);
177} 176}
178 177
179static void write_reg(ide_hwif_t *hwif, u8 value, int reg)
180/* Write value to register reg, base of register 178/* Write value to register reg, base of register
181 * is at reg_base (0x1f0 primary, 0x170 secondary, 179 * is at reg_base (0x1f0 primary, 0x170 secondary,
182 * if not changed by PCI configuration). 180 * if not changed by PCI configuration).
183 * This is from setupvic.exe program. 181 * This is from setupvic.exe program.
184 */ 182 */
183static void write_reg(u8 value, int reg)
185{ 184{
186 hwif->INW(reg_base+1); 185 inw(reg_base + 1);
187 hwif->INW(reg_base+1); 186 inw(reg_base + 1);
188 hwif->OUTB(3, reg_base+2); 187 outb(3, reg_base + 2);
189 hwif->OUTB(value, reg_base+reg); 188 outb(value, reg_base + reg);
190 hwif->OUTB(0x83, reg_base+2); 189 outb(0x83, reg_base + 2);
191} 190}
192 191
193static u8 read_reg(ide_hwif_t *hwif, int reg)
194/* Read value from register reg, base of register 192/* Read value from register reg, base of register
195 * is at reg_base (0x1f0 primary, 0x170 secondary, 193 * is at reg_base (0x1f0 primary, 0x170 secondary,
196 * if not changed by PCI configuration). 194 * if not changed by PCI configuration).
197 * This is from setupvic.exe program. 195 * This is from setupvic.exe program.
198 */ 196 */
197static u8 read_reg(int reg)
199{ 198{
200 u8 ret = 0; 199 u8 ret = 0;
201 200
202 hwif->INW(reg_base+1); 201 inw(reg_base + 1);
203 hwif->INW(reg_base+1); 202 inw(reg_base + 1);
204 hwif->OUTB(3, reg_base+2); 203 outb(3, reg_base + 2);
205 ret = hwif->INB(reg_base+reg); 204 ret = inb(reg_base + reg);
206 hwif->OUTB(0x83, reg_base+2); 205 outb(0x83, reg_base + 2);
206
207 return ret; 207 return ret;
208} 208}
209 209
@@ -286,39 +286,39 @@ static void opti621_tune_drive (ide_drive_t *drive, u8 pio)
286 reg_base = hwif->io_ports[IDE_DATA_OFFSET]; 286 reg_base = hwif->io_ports[IDE_DATA_OFFSET];
287 287
288 /* allow Register-B */ 288 /* allow Register-B */
289 hwif->OUTB(0xc0, reg_base+CNTRL_REG); 289 outb(0xc0, reg_base + CNTRL_REG);
290 /* hmm, setupvic.exe does this ;-) */ 290 /* hmm, setupvic.exe does this ;-) */
291 hwif->OUTB(0xff, reg_base+5); 291 outb(0xff, reg_base + 5);
292 /* if reads 0xff, adapter not exist? */ 292 /* if reads 0xff, adapter not exist? */
293 (void) hwif->INB(reg_base+CNTRL_REG); 293 (void)inb(reg_base + CNTRL_REG);
294 /* if reads 0xc0, no interface exist? */ 294 /* if reads 0xc0, no interface exist? */
295 read_reg(hwif, CNTRL_REG); 295 read_reg(CNTRL_REG);
296 /* read version, probably 0 */ 296 /* read version, probably 0 */
297 read_reg(hwif, STRAP_REG); 297 read_reg(STRAP_REG);
298 298
299 /* program primary drive */ 299 /* program primary drive */
300 /* select Index-0 for Register-A */ 300 /* select Index-0 for Register-A */
301 write_reg(hwif, 0, MISC_REG); 301 write_reg(0, MISC_REG);
302 /* set read cycle timings */ 302 /* set read cycle timings */
303 write_reg(hwif, cycle1, READ_REG); 303 write_reg(cycle1, READ_REG);
304 /* set write cycle timings */ 304 /* set write cycle timings */
305 write_reg(hwif, cycle1, WRITE_REG); 305 write_reg(cycle1, WRITE_REG);
306 306
307 /* program secondary drive */ 307 /* program secondary drive */
308 /* select Index-1 for Register-B */ 308 /* select Index-1 for Register-B */
309 write_reg(hwif, 1, MISC_REG); 309 write_reg(1, MISC_REG);
310 /* set read cycle timings */ 310 /* set read cycle timings */
311 write_reg(hwif, cycle2, READ_REG); 311 write_reg(cycle2, READ_REG);
312 /* set write cycle timings */ 312 /* set write cycle timings */
313 write_reg(hwif, cycle2, WRITE_REG); 313 write_reg(cycle2, WRITE_REG);
314 314
315 /* use Register-A for drive 0 */ 315 /* use Register-A for drive 0 */
316 /* use Register-B for drive 1 */ 316 /* use Register-B for drive 1 */
317 write_reg(hwif, 0x85, CNTRL_REG); 317 write_reg(0x85, CNTRL_REG);
318 318
319 /* set address setup, DRDY timings, */ 319 /* set address setup, DRDY timings, */
320 /* and read prefetch for both drives */ 320 /* and read prefetch for both drives */
321 write_reg(hwif, misc, MISC_REG); 321 write_reg(misc, MISC_REG);
322 322
323 spin_unlock_irqrestore(&ide_lock, flags); 323 spin_unlock_irqrestore(&ide_lock, flags);
324} 324}
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c
index 236a03144a..6ceb25bc5a 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pci/pdc202xx_new.c
@@ -101,8 +101,8 @@ static u8 get_indexed_reg(ide_hwif_t *hwif, u8 index)
101{ 101{
102 u8 value; 102 u8 value;
103 103
104 hwif->OUTB(index, hwif->dma_vendor1); 104 outb(index, hwif->dma_vendor1);
105 value = hwif->INB(hwif->dma_vendor3); 105 value = inb(hwif->dma_vendor3);
106 106
107 DBG("index[%02X] value[%02X]\n", index, value); 107 DBG("index[%02X] value[%02X]\n", index, value);
108 return value; 108 return value;
@@ -115,8 +115,8 @@ static u8 get_indexed_reg(ide_hwif_t *hwif, u8 index)
115 */ 115 */
116static void set_indexed_reg(ide_hwif_t *hwif, u8 index, u8 value) 116static void set_indexed_reg(ide_hwif_t *hwif, u8 index, u8 value)
117{ 117{
118 hwif->OUTB(index, hwif->dma_vendor1); 118 outb(index, hwif->dma_vendor1);
119 hwif->OUTB(value, hwif->dma_vendor3); 119 outb(value, hwif->dma_vendor3);
120 DBG("index[%02X] value[%02X]\n", index, value); 120 DBG("index[%02X] value[%02X]\n", index, value);
121} 121}
122 122
@@ -281,25 +281,15 @@ static int config_chipset_for_dma(ide_drive_t *drive)
281 281
282static int pdcnew_config_drive_xfer_rate(ide_drive_t *drive) 282static int pdcnew_config_drive_xfer_rate(ide_drive_t *drive)
283{ 283{
284 ide_hwif_t *hwif = HWIF(drive);
285 struct hd_driveid *id = drive->id;
286
287 drive->init_speed = 0; 284 drive->init_speed = 0;
288 285
289 if ((id->capability & 1) && drive->autodma) { 286 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
290 287 return 0;
291 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
292 return hwif->ide_dma_on(drive);
293 288
294 goto fast_ata_pio; 289 if (ide_use_fast_pio(drive))
290 pdcnew_tune_drive(drive, 255);
295 291
296 } else if ((id->capability & 8) || (id->field_valid & 2)) { 292 return -1;
297fast_ata_pio:
298 hwif->tuneproc(drive, 255);
299 return hwif->ide_dma_off_quietly(drive);
300 }
301 /* IORDY not supported */
302 return 0;
303} 293}
304 294
305static int pdcnew_quirkproc(ide_drive_t *drive) 295static int pdcnew_quirkproc(ide_drive_t *drive)
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pci/pdc202xx_old.c
index 730e8d1ec2..a7a639fe1e 100644
--- a/drivers/ide/pci/pdc202xx_old.c
+++ b/drivers/ide/pci/pdc202xx_old.c
@@ -2,6 +2,7 @@
2 * linux/drivers/ide/pci/pdc202xx_old.c Version 0.36 Sept 11, 2002 2 * linux/drivers/ide/pci/pdc202xx_old.c Version 0.36 Sept 11, 2002
3 * 3 *
4 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org> 4 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2006-2007 MontaVista Software, Inc.
5 * 6 *
6 * Promise Ultra33 cards with BIOS v1.20 through 1.28 will need this 7 * Promise Ultra33 cards with BIOS v1.20 through 1.28 will need this
7 * compiled into the kernel if you have more than one card installed. 8 * compiled into the kernel if you have more than one card installed.
@@ -216,21 +217,10 @@ static int pdc202xx_tune_chipset (ide_drive_t *drive, u8 xferspeed)
216} 217}
217 218
218 219
219/* 0 1 2 3 4 5 6 7 8 220static void pdc202xx_tune_drive(ide_drive_t *drive, u8 pio)
220 * 960, 480, 390, 300, 240, 180, 120, 90, 60
221 * 180, 150, 120, 90, 60
222 * DMA_Speed
223 * 180, 120, 90, 90, 90, 60, 30
224 * 11, 5, 4, 3, 2, 1, 0
225 */
226static void config_chipset_for_pio (ide_drive_t *drive, u8 pio)
227{ 221{
228 u8 speed = 0; 222 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
229 223 pdc202xx_tune_chipset(drive, XFER_PIO_0 + pio);
230 if (pio == 5) pio = 4;
231 speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, pio, NULL);
232
233 pdc202xx_tune_chipset(drive, speed);
234} 224}
235 225
236static u8 pdc202xx_old_cable_detect (ide_hwif_t *hwif) 226static u8 pdc202xx_old_cable_detect (ide_hwif_t *hwif)
@@ -250,17 +240,17 @@ static u8 pdc202xx_old_cable_detect (ide_hwif_t *hwif)
250static void pdc_old_enable_66MHz_clock(ide_hwif_t *hwif) 240static void pdc_old_enable_66MHz_clock(ide_hwif_t *hwif)
251{ 241{
252 unsigned long clock_reg = hwif->dma_master + 0x11; 242 unsigned long clock_reg = hwif->dma_master + 0x11;
253 u8 clock = hwif->INB(clock_reg); 243 u8 clock = inb(clock_reg);
254 244
255 hwif->OUTB(clock | (hwif->channel ? 0x08 : 0x02), clock_reg); 245 outb(clock | (hwif->channel ? 0x08 : 0x02), clock_reg);
256} 246}
257 247
258static void pdc_old_disable_66MHz_clock(ide_hwif_t *hwif) 248static void pdc_old_disable_66MHz_clock(ide_hwif_t *hwif)
259{ 249{
260 unsigned long clock_reg = hwif->dma_master + 0x11; 250 unsigned long clock_reg = hwif->dma_master + 0x11;
261 u8 clock = hwif->INB(clock_reg); 251 u8 clock = inb(clock_reg);
262 252
263 hwif->OUTB(clock & ~(hwif->channel ? 0x08 : 0x02), clock_reg); 253 outb(clock & ~(hwif->channel ? 0x08 : 0x02), clock_reg);
264} 254}
265 255
266static int config_chipset_for_dma (ide_drive_t *drive) 256static int config_chipset_for_dma (ide_drive_t *drive)
@@ -332,27 +322,15 @@ chipset_is_set:
332 322
333static int pdc202xx_config_drive_xfer_rate (ide_drive_t *drive) 323static int pdc202xx_config_drive_xfer_rate (ide_drive_t *drive)
334{ 324{
335 ide_hwif_t *hwif = HWIF(drive);
336 struct hd_driveid *id = drive->id;
337
338 drive->init_speed = 0; 325 drive->init_speed = 0;
339 326
340 if (id && (id->capability & 1) && drive->autodma) { 327 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
341 328 return 0;
342 if (ide_use_dma(drive)) {
343 if (config_chipset_for_dma(drive))
344 return hwif->ide_dma_on(drive);
345 }
346 329
347 goto fast_ata_pio; 330 if (ide_use_fast_pio(drive))
331 pdc202xx_tune_drive(drive, 255);
348 332
349 } else if ((id->capability & 8) || (id->field_valid & 2)) { 333 return -1;
350fast_ata_pio:
351 hwif->tuneproc(drive, 5);
352 return hwif->ide_dma_off_quietly(drive);
353 }
354 /* IORDY not supported */
355 return 0;
356} 334}
357 335
358static int pdc202xx_quirkproc (ide_drive_t *drive) 336static int pdc202xx_quirkproc (ide_drive_t *drive)
@@ -375,14 +353,14 @@ static void pdc202xx_old_ide_dma_start(ide_drive_t *drive)
375 unsigned long high_16 = hwif->dma_master; 353 unsigned long high_16 = hwif->dma_master;
376 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20); 354 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
377 u32 word_count = 0; 355 u32 word_count = 0;
378 u8 clock = hwif->INB(high_16 + 0x11); 356 u8 clock = inb(high_16 + 0x11);
379 357
380 hwif->OUTB(clock|(hwif->channel ? 0x08 : 0x02), high_16+0x11); 358 outb(clock | (hwif->channel ? 0x08 : 0x02), high_16 + 0x11);
381 word_count = (rq->nr_sectors << 8); 359 word_count = (rq->nr_sectors << 8);
382 word_count = (rq_data_dir(rq) == READ) ? 360 word_count = (rq_data_dir(rq) == READ) ?
383 word_count | 0x05000000 : 361 word_count | 0x05000000 :
384 word_count | 0x06000000; 362 word_count | 0x06000000;
385 hwif->OUTL(word_count, atapi_reg); 363 outl(word_count, atapi_reg);
386 } 364 }
387 ide_dma_start(drive); 365 ide_dma_start(drive);
388} 366}
@@ -395,9 +373,9 @@ static int pdc202xx_old_ide_dma_end(ide_drive_t *drive)
395 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20); 373 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
396 u8 clock = 0; 374 u8 clock = 0;
397 375
398 hwif->OUTL(0, atapi_reg); /* zero out extra */ 376 outl(0, atapi_reg); /* zero out extra */
399 clock = hwif->INB(high_16 + 0x11); 377 clock = inb(high_16 + 0x11);
400 hwif->OUTB(clock & ~(hwif->channel ? 0x08:0x02), high_16+0x11); 378 outb(clock & ~(hwif->channel ? 0x08:0x02), high_16 + 0x11);
401 } 379 }
402 if (drive->current_speed > XFER_UDMA_2) 380 if (drive->current_speed > XFER_UDMA_2)
403 pdc_old_disable_66MHz_clock(drive->hwif); 381 pdc_old_disable_66MHz_clock(drive->hwif);
@@ -408,8 +386,8 @@ static int pdc202xx_old_ide_dma_test_irq(ide_drive_t *drive)
408{ 386{
409 ide_hwif_t *hwif = HWIF(drive); 387 ide_hwif_t *hwif = HWIF(drive);
410 unsigned long high_16 = hwif->dma_master; 388 unsigned long high_16 = hwif->dma_master;
411 u8 dma_stat = hwif->INB(hwif->dma_status); 389 u8 dma_stat = inb(hwif->dma_status);
412 u8 sc1d = hwif->INB((high_16 + 0x001d)); 390 u8 sc1d = inb(high_16 + 0x001d);
413 391
414 if (hwif->channel) { 392 if (hwif->channel) {
415 /* bit7: Error, bit6: Interrupting, bit5: FIFO Full, bit4: FIFO Empty */ 393 /* bit7: Error, bit6: Interrupting, bit5: FIFO Full, bit4: FIFO Empty */
@@ -445,11 +423,11 @@ static int pdc202xx_ide_dma_timeout(ide_drive_t *drive)
445static void pdc202xx_reset_host (ide_hwif_t *hwif) 423static void pdc202xx_reset_host (ide_hwif_t *hwif)
446{ 424{
447 unsigned long high_16 = hwif->dma_master; 425 unsigned long high_16 = hwif->dma_master;
448 u8 udma_speed_flag = hwif->INB(high_16|0x001f); 426 u8 udma_speed_flag = inb(high_16 | 0x001f);
449 427
450 hwif->OUTB((udma_speed_flag | 0x10), (high_16|0x001f)); 428 outb(udma_speed_flag | 0x10, high_16 | 0x001f);
451 mdelay(100); 429 mdelay(100);
452 hwif->OUTB((udma_speed_flag & ~0x10), (high_16|0x001f)); 430 outb(udma_speed_flag & ~0x10, high_16 | 0x001f);
453 mdelay(2000); /* 2 seconds ?! */ 431 mdelay(2000); /* 2 seconds ?! */
454 432
455 printk(KERN_WARNING "PDC202XX: %s channel reset.\n", 433 printk(KERN_WARNING "PDC202XX: %s channel reset.\n",
@@ -463,7 +441,7 @@ static void pdc202xx_reset (ide_drive_t *drive)
463 441
464 pdc202xx_reset_host(hwif); 442 pdc202xx_reset_host(hwif);
465 pdc202xx_reset_host(mate); 443 pdc202xx_reset_host(mate);
466 hwif->tuneproc(drive, 5); 444 pdc202xx_tune_drive(drive, 255);
467} 445}
468 446
469static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev, 447static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev,
@@ -490,7 +468,7 @@ static void __devinit init_hwif_pdc202xx(ide_hwif_t *hwif)
490 hwif->rqsize = 256; 468 hwif->rqsize = 256;
491 469
492 hwif->autodma = 0; 470 hwif->autodma = 0;
493 hwif->tuneproc = &config_chipset_for_pio; 471 hwif->tuneproc = &pdc202xx_tune_drive;
494 hwif->quirkproc = &pdc202xx_quirkproc; 472 hwif->quirkproc = &pdc202xx_quirkproc;
495 473
496 if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246) 474 if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246)
@@ -537,9 +515,9 @@ static void __devinit init_dma_pdc202xx(ide_hwif_t *hwif, unsigned long dmabase)
537 return; 515 return;
538 } 516 }
539 517
540 udma_speed_flag = hwif->INB((dmabase|0x1f)); 518 udma_speed_flag = inb(dmabase | 0x1f);
541 primary_mode = hwif->INB((dmabase|0x1a)); 519 primary_mode = inb(dmabase | 0x1a);
542 secondary_mode = hwif->INB((dmabase|0x1b)); 520 secondary_mode = inb(dmabase | 0x1b);
543 printk(KERN_INFO "%s: (U)DMA Burst Bit %sABLED " \ 521 printk(KERN_INFO "%s: (U)DMA Burst Bit %sABLED " \
544 "Primary %s Mode " \ 522 "Primary %s Mode " \
545 "Secondary %s Mode.\n", hwif->cds->name, 523 "Secondary %s Mode.\n", hwif->cds->name,
@@ -552,30 +530,10 @@ static void __devinit init_dma_pdc202xx(ide_hwif_t *hwif, unsigned long dmabase)
552 printk(KERN_INFO "%s: FORCING BURST BIT 0x%02x->0x%02x ", 530 printk(KERN_INFO "%s: FORCING BURST BIT 0x%02x->0x%02x ",
553 hwif->cds->name, udma_speed_flag, 531 hwif->cds->name, udma_speed_flag,
554 (udma_speed_flag|1)); 532 (udma_speed_flag|1));
555 hwif->OUTB(udma_speed_flag|1,(dmabase|0x1f)); 533 outb(udma_speed_flag | 1, dmabase | 0x1f);
556 printk("%sACTIVE\n", 534 printk("%sACTIVE\n", (inb(dmabase | 0x1f) & 1) ? "" : "IN");
557 (hwif->INB(dmabase|0x1f)&1) ? "":"IN");
558 } 535 }
559#endif /* CONFIG_PDC202XX_BURST */ 536#endif /* CONFIG_PDC202XX_BURST */
560#ifdef CONFIG_PDC202XX_MASTER
561 if (!(primary_mode & 1)) {
562 printk(KERN_INFO "%s: FORCING PRIMARY MODE BIT "
563 "0x%02x -> 0x%02x ", hwif->cds->name,
564 primary_mode, (primary_mode|1));
565 hwif->OUTB(primary_mode|1, (dmabase|0x1a));
566 printk("%s\n",
567 (hwif->INB((dmabase|0x1a)) & 1) ? "MASTER" : "PCI");
568 }
569
570 if (!(secondary_mode & 1)) {
571 printk(KERN_INFO "%s: FORCING SECONDARY MODE BIT "
572 "0x%02x -> 0x%02x ", hwif->cds->name,
573 secondary_mode, (secondary_mode|1));
574 hwif->OUTB(secondary_mode|1, (dmabase|0x1b));
575 printk("%s\n",
576 (hwif->INB((dmabase|0x1b)) & 1) ? "MASTER" : "PCI");
577 }
578#endif /* CONFIG_PDC202XX_MASTER */
579 537
580 ide_setup_dma(hwif, dmabase, 8); 538 ide_setup_dma(hwif, dmabase, 8);
581} 539}
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index 52cfc2ac22..061d300ab8 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * linux/drivers/ide/pci/piix.c Version 0.46 December 3, 2006 2 * linux/drivers/ide/pci/piix.c Version 0.47 February 8, 2007
3 * 3 *
4 * Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer 4 * Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer
5 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org> 5 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
6 * Copyright (C) 2003 Red Hat Inc <alan@redhat.com> 6 * Copyright (C) 2003 Red Hat Inc <alan@redhat.com>
7 * Copyright (C) 2006 MontaVista Software, Inc. <source@mvista.com> 7 * Copyright (C) 2006-2007 MontaVista Software, Inc. <source@mvista.com>
8 * 8 *
9 * May be copied or modified under the terms of the GNU General Public License 9 * May be copied or modified under the terms of the GNU General Public License
10 * 10 *
@@ -205,14 +205,13 @@ static u8 piix_dma_2_pio (u8 xfer_rate) {
205} 205}
206 206
207/** 207/**
208 * piix_tune_drive - tune a drive attached to a PIIX 208 * piix_tune_pio - tune PIIX for PIO mode
209 * @drive: drive to tune 209 * @drive: drive to tune
210 * @pio: desired PIO mode 210 * @pio: desired PIO mode
211 * 211 *
212 * Set the interface PIO mode based upon the settings done by AMI BIOS 212 * Set the interface PIO mode based upon the settings done by AMI BIOS.
213 * (might be useful if drive is not registered in CMOS for any reason).
214 */ 213 */
215static void piix_tune_drive (ide_drive_t *drive, u8 pio) 214static void piix_tune_pio (ide_drive_t *drive, u8 pio)
216{ 215{
217 ide_hwif_t *hwif = HWIF(drive); 216 ide_hwif_t *hwif = HWIF(drive);
218 struct pci_dev *dev = hwif->pci_dev; 217 struct pci_dev *dev = hwif->pci_dev;
@@ -233,8 +232,6 @@ static void piix_tune_drive (ide_drive_t *drive, u8 pio)
233 { 2, 1 }, 232 { 2, 1 },
234 { 2, 3 }, }; 233 { 2, 3 }, };
235 234
236 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
237
238 /* 235 /*
239 * Master vs slave is synchronized above us but the slave register is 236 * Master vs slave is synchronized above us but the slave register is
240 * shared by the two hwifs so the corner case of two slave timeouts in 237 * shared by the two hwifs so the corner case of two slave timeouts in
@@ -253,19 +250,20 @@ static void piix_tune_drive (ide_drive_t *drive, u8 pio)
253 master_data |= 0x4000; 250 master_data |= 0x4000;
254 master_data &= ~0x0070; 251 master_data &= ~0x0070;
255 if (pio > 1) { 252 if (pio > 1) {
256 /* enable PPE, IE and TIME */ 253 /* Set PPE, IE and TIME */
257 master_data = master_data | (control << 4); 254 master_data |= control << 4;
258 } 255 }
259 pci_read_config_byte(dev, slave_port, &slave_data); 256 pci_read_config_byte(dev, slave_port, &slave_data);
260 slave_data = slave_data & (hwif->channel ? 0x0f : 0xf0); 257 slave_data &= hwif->channel ? 0x0f : 0xf0;
261 slave_data = slave_data | (((timings[pio][0] << 2) | timings[pio][1]) << (hwif->channel ? 4 : 0)); 258 slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) <<
259 (hwif->channel ? 4 : 0);
262 } else { 260 } else {
263 master_data &= ~0x3307; 261 master_data &= ~0x3307;
264 if (pio > 1) { 262 if (pio > 1) {
265 /* enable PPE, IE and TIME */ 263 /* enable PPE, IE and TIME */
266 master_data = master_data | control; 264 master_data |= control;
267 } 265 }
268 master_data = master_data | (timings[pio][0] << 12) | (timings[pio][1] << 8); 266 master_data |= (timings[pio][0] << 12) | (timings[pio][1] << 8);
269 } 267 }
270 pci_write_config_word(dev, master_port, master_data); 268 pci_write_config_word(dev, master_port, master_data);
271 if (is_slave) 269 if (is_slave)
@@ -274,6 +272,21 @@ static void piix_tune_drive (ide_drive_t *drive, u8 pio)
274} 272}
275 273
276/** 274/**
275 * piix_tune_drive - tune a drive attached to PIIX
276 * @drive: drive to tune
277 * @pio: desired PIO mode
278 *
279 * Set the drive's PIO mode (might be useful if drive is not registered
280 * in CMOS for any reason).
281 */
282static void piix_tune_drive (ide_drive_t *drive, u8 pio)
283{
284 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
285 piix_tune_pio(drive, pio);
286 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio);
287}
288
289/**
277 * piix_tune_chipset - tune a PIIX interface 290 * piix_tune_chipset - tune a PIIX interface
278 * @drive: IDE drive to tune 291 * @drive: IDE drive to tune
279 * @xferspeed: speed to configure 292 * @xferspeed: speed to configure
@@ -348,8 +361,8 @@ static int piix_tune_chipset (ide_drive_t *drive, u8 xferspeed)
348 pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag); 361 pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag);
349 } 362 }
350 363
351 piix_tune_drive(drive, piix_dma_2_pio(speed)); 364 piix_tune_pio(drive, piix_dma_2_pio(speed));
352 return (ide_config_drive_speed(drive, speed)); 365 return ide_config_drive_speed(drive, speed);
353} 366}
354 367
355/** 368/**
@@ -369,7 +382,7 @@ static int piix_config_drive_for_dma (ide_drive_t *drive)
369 * If no DMA speed was available or the chipset has DMA bugs 382 * If no DMA speed was available or the chipset has DMA bugs
370 * then disable DMA and use PIO 383 * then disable DMA and use PIO
371 */ 384 */
372 if (!speed || no_piix_dma) 385 if (!speed)
373 return 0; 386 return 0;
374 387
375 (void) piix_tune_chipset(drive, speed); 388 (void) piix_tune_chipset(drive, speed);
@@ -386,41 +399,26 @@ static int piix_config_drive_for_dma (ide_drive_t *drive)
386 399
387static int piix_config_drive_xfer_rate (ide_drive_t *drive) 400static int piix_config_drive_xfer_rate (ide_drive_t *drive)
388{ 401{
389 ide_hwif_t *hwif = HWIF(drive);
390 struct hd_driveid *id = drive->id;
391
392 drive->init_speed = 0; 402 drive->init_speed = 0;
393 403
394 if ((id->capability & 1) && drive->autodma) { 404 if (ide_use_dma(drive) && piix_config_drive_for_dma(drive))
395 405 return 0;
396 if (ide_use_dma(drive) && piix_config_drive_for_dma(drive))
397 return hwif->ide_dma_on(drive);
398 406
399 goto fast_ata_pio; 407 if (ide_use_fast_pio(drive))
408 piix_tune_drive(drive, 255);
400 409
401 } else if ((id->capability & 8) || (id->field_valid & 2)) { 410 return -1;
402fast_ata_pio:
403 /* Find best PIO mode. */
404 (void) hwif->speedproc(drive, XFER_PIO_0 +
405 ide_get_best_pio_mode(drive, 255, 4, NULL));
406 return hwif->ide_dma_off_quietly(drive);
407 }
408 /* IORDY not supported */
409 return 0;
410} 411}
411 412
412/** 413/**
413 * init_chipset_piix - set up the PIIX chipset 414 * piix_is_ichx - check if ICHx
414 * @dev: PCI device to set up 415 * @dev: PCI device to check
415 * @name: Name of the device
416 * 416 *
417 * Initialize the PCI device as required. For the PIIX this turns 417 * returns 1 if ICHx, 0 otherwise.
418 * out to be nice and simple
419 */ 418 */
420 419static int piix_is_ichx(struct pci_dev *dev)
421static unsigned int __devinit init_chipset_piix (struct pci_dev *dev, const char *name)
422{ 420{
423 switch(dev->device) { 421 switch (dev->device) {
424 case PCI_DEVICE_ID_INTEL_82801EB_1: 422 case PCI_DEVICE_ID_INTEL_82801EB_1:
425 case PCI_DEVICE_ID_INTEL_82801AA_1: 423 case PCI_DEVICE_ID_INTEL_82801AA_1:
426 case PCI_DEVICE_ID_INTEL_82801AB_1: 424 case PCI_DEVICE_ID_INTEL_82801AB_1:
@@ -438,19 +436,61 @@ static unsigned int __devinit init_chipset_piix (struct pci_dev *dev, const char
438 case PCI_DEVICE_ID_INTEL_ICH7_21: 436 case PCI_DEVICE_ID_INTEL_ICH7_21:
439 case PCI_DEVICE_ID_INTEL_ESB2_18: 437 case PCI_DEVICE_ID_INTEL_ESB2_18:
440 case PCI_DEVICE_ID_INTEL_ICH8_6: 438 case PCI_DEVICE_ID_INTEL_ICH8_6:
441 { 439 return 1;
442 unsigned int extra = 0;
443 pci_read_config_dword(dev, 0x54, &extra);
444 pci_write_config_dword(dev, 0x54, extra|0x400);
445 }
446 default:
447 break;
448 } 440 }
449 441
450 return 0; 442 return 0;
451} 443}
452 444
453/** 445/**
446 * init_chipset_piix - set up the PIIX chipset
447 * @dev: PCI device to set up
448 * @name: Name of the device
449 *
450 * Initialize the PCI device as required. For the PIIX this turns
451 * out to be nice and simple
452 */
453
454static unsigned int __devinit init_chipset_piix (struct pci_dev *dev, const char *name)
455{
456 if (piix_is_ichx(dev)) {
457 unsigned int extra = 0;
458 pci_read_config_dword(dev, 0x54, &extra);
459 pci_write_config_dword(dev, 0x54, extra|0x400);
460 }
461
462 return 0;
463}
464
465/**
466 * piix_dma_clear_irq - clear BMDMA status
467 * @drive: IDE drive to clear
468 *
469 * Called from ide_intr() for PIO interrupts
470 * to clear BMDMA status as needed by ICHx
471 */
472static void piix_dma_clear_irq(ide_drive_t *drive)
473{
474 ide_hwif_t *hwif = HWIF(drive);
475 u8 dma_stat;
476
477 /* clear the INTR & ERROR bits */
478 dma_stat = hwif->INB(hwif->dma_status);
479 /* Should we force the bit as well ? */
480 hwif->OUTB(dma_stat, hwif->dma_status);
481}
482
483static int __devinit piix_cable_detect(ide_hwif_t *hwif)
484{
485 struct pci_dev *dev = hwif->pci_dev;
486 u8 reg54h = 0, mask = hwif->channel ? 0xc0 : 0x30;
487
488 pci_read_config_byte(dev, 0x54, &reg54h);
489
490 return (reg54h & mask) ? 1 : 0;
491}
492
493/**
454 * init_hwif_piix - fill in the hwif for the PIIX 494 * init_hwif_piix - fill in the hwif for the PIIX
455 * @hwif: IDE interface 495 * @hwif: IDE interface
456 * 496 *
@@ -460,9 +500,6 @@ static unsigned int __devinit init_chipset_piix (struct pci_dev *dev, const char
460 500
461static void __devinit init_hwif_piix(ide_hwif_t *hwif) 501static void __devinit init_hwif_piix(ide_hwif_t *hwif)
462{ 502{
463 u8 reg54h = 0, reg55h = 0, ata66 = 0;
464 u8 mask = hwif->channel ? 0xc0 : 0x30;
465
466#ifndef CONFIG_IA64 503#ifndef CONFIG_IA64
467 if (!hwif->irq) 504 if (!hwif->irq)
468 hwif->irq = hwif->channel ? 15 : 14; 505 hwif->irq = hwif->channel ? 15 : 14;
@@ -472,10 +509,6 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
472 /* This is a painful system best to let it self tune for now */ 509 /* This is a painful system best to let it self tune for now */
473 return; 510 return;
474 } 511 }
475 /* ESB2 appears to generate spurious DMA interrupts in PIO mode
476 when in native mode */
477 if (hwif->pci_dev->device == PCI_DEVICE_ID_INTEL_ESB2_18)
478 hwif->atapi_irq_bogon = 1;
479 512
480 hwif->autodma = 0; 513 hwif->autodma = 0;
481 hwif->tuneproc = &piix_tune_drive; 514 hwif->tuneproc = &piix_tune_drive;
@@ -486,15 +519,16 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
486 if (!hwif->dma_base) 519 if (!hwif->dma_base)
487 return; 520 return;
488 521
522 /* ICHx need to clear the bmdma status for all interrupts */
523 if (piix_is_ichx(hwif->pci_dev))
524 hwif->ide_dma_clear_irq = &piix_dma_clear_irq;
525
489 hwif->atapi_dma = 1; 526 hwif->atapi_dma = 1;
490 hwif->ultra_mask = 0x3f; 527 hwif->ultra_mask = 0x3f;
491 hwif->mwdma_mask = 0x06; 528 hwif->mwdma_mask = 0x06;
492 hwif->swdma_mask = 0x04; 529 hwif->swdma_mask = 0x04;
493 530
494 switch(hwif->pci_dev->device) { 531 switch(hwif->pci_dev->device) {
495 case PCI_DEVICE_ID_INTEL_82371MX:
496 hwif->mwdma_mask = 0x80;
497 hwif->swdma_mask = 0x80;
498 case PCI_DEVICE_ID_INTEL_82371FB_0: 532 case PCI_DEVICE_ID_INTEL_82371FB_0:
499 case PCI_DEVICE_ID_INTEL_82371FB_1: 533 case PCI_DEVICE_ID_INTEL_82371FB_1:
500 case PCI_DEVICE_ID_INTEL_82371SB_1: 534 case PCI_DEVICE_ID_INTEL_82371SB_1:
@@ -507,14 +541,14 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
507 hwif->ultra_mask = 0x07; 541 hwif->ultra_mask = 0x07;
508 break; 542 break;
509 default: 543 default:
510 pci_read_config_byte(hwif->pci_dev, 0x54, &reg54h); 544 if (!hwif->udma_four)
511 pci_read_config_byte(hwif->pci_dev, 0x55, &reg55h); 545 hwif->udma_four = piix_cable_detect(hwif);
512 ata66 = (reg54h & mask) ? 1 : 0;
513 break; 546 break;
514 } 547 }
515 548
516 if (!(hwif->udma_four)) 549 if (no_piix_dma)
517 hwif->udma_four = ata66; 550 hwif->ultra_mask = hwif->mwdma_mask = hwif->swdma_mask = 0;
551
518 hwif->ide_dma_check = &piix_config_drive_xfer_rate; 552 hwif->ide_dma_check = &piix_config_drive_xfer_rate;
519 if (!noautodma) 553 if (!noautodma)
520 hwif->autodma = 1; 554 hwif->autodma = 1;
diff --git a/drivers/ide/pci/rz1000.c b/drivers/ide/pci/rz1000.c
index c185531105..f8c9546901 100644
--- a/drivers/ide/pci/rz1000.c
+++ b/drivers/ide/pci/rz1000.c
@@ -15,8 +15,6 @@
15 * Dunno if this fixes both ports, or only the primary port (?). 15 * Dunno if this fixes both ports, or only the primary port (?).
16 */ 16 */
17 17
18#undef REALLY_SLOW_IO /* most systems can safely undef this */
19
20#include <linux/types.h> 18#include <linux/types.h>
21#include <linux/module.h> 19#include <linux/module.h>
22#include <linux/kernel.h> 20#include <linux/kernel.h>
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c
index 8d762d323f..b5ae0c50e2 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/pci/sc1200.c
@@ -161,7 +161,7 @@ static int sc1200_config_dma2 (ide_drive_t *drive, int mode)
161 /* 161 /*
162 * Default to DMA-off in case we run into trouble here. 162 * Default to DMA-off in case we run into trouble here.
163 */ 163 */
164 hwif->ide_dma_off_quietly(drive); /* turn off DMA while we fiddle */ 164 hwif->dma_off_quietly(drive); /* turn off DMA while we fiddle */
165 outb(inb(hwif->dma_base+2)&~(unit?0x40:0x20), hwif->dma_base+2); /* clear DMA_capable bit */ 165 outb(inb(hwif->dma_base+2)&~(unit?0x40:0x20), hwif->dma_base+2); /* clear DMA_capable bit */
166 166
167 /* 167 /*
@@ -241,10 +241,7 @@ static int sc1200_config_dma2 (ide_drive_t *drive, int mode)
241 241
242 outb(inb(hwif->dma_base+2)|(unit?0x40:0x20), hwif->dma_base+2); /* set DMA_capable bit */ 242 outb(inb(hwif->dma_base+2)|(unit?0x40:0x20), hwif->dma_base+2); /* set DMA_capable bit */
243 243
244 /* 244 return 0; /* success */
245 * Finally, turn DMA on in software, and exit.
246 */
247 return hwif->ide_dma_on(drive); /* success */
248} 245}
249 246
250/* 247/*
@@ -442,10 +439,10 @@ static int sc1200_resume (struct pci_dev *dev)
442 ide_drive_t *drive = &(hwif->drives[d]); 439 ide_drive_t *drive = &(hwif->drives[d]);
443 if (drive->present && !__ide_dma_bad_drive(drive)) { 440 if (drive->present && !__ide_dma_bad_drive(drive)) {
444 int was_using_dma = drive->using_dma; 441 int was_using_dma = drive->using_dma;
445 hwif->ide_dma_off_quietly(drive); 442 hwif->dma_off_quietly(drive);
446 sc1200_config_dma(drive); 443 sc1200_config_dma(drive);
447 if (!was_using_dma && drive->using_dma) { 444 if (!was_using_dma && drive->using_dma) {
448 hwif->ide_dma_off_quietly(drive); 445 hwif->dma_off_quietly(drive);
449 } 446 }
450 } 447 }
451 } 448 }
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index ea9a28a458..dbcd37a0c6 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -160,7 +160,7 @@ static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
160 if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) || 160 if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
161 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) { 161 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) {
162 if (!drive->init_speed) { 162 if (!drive->init_speed) {
163 u8 dma_stat = hwif->INB(hwif->dma_status); 163 u8 dma_stat = inb(hwif->dma_status);
164 164
165dma_pio: 165dma_pio:
166 if (((ultra_enable << (7-drive->dn) & 0x80) == 0x80) && 166 if (((ultra_enable << (7-drive->dn) & 0x80) == 0x80) &&
@@ -315,35 +315,15 @@ static int config_chipset_for_dma (ide_drive_t *drive)
315 315
316static int svwks_config_drive_xfer_rate (ide_drive_t *drive) 316static int svwks_config_drive_xfer_rate (ide_drive_t *drive)
317{ 317{
318 ide_hwif_t *hwif = HWIF(drive);
319 struct hd_driveid *id = drive->id;
320
321 drive->init_speed = 0; 318 drive->init_speed = 0;
322 319
323 if ((id->capability & 1) && drive->autodma) { 320 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
324 321 return 0;
325 if (ide_use_dma(drive)) {
326 if (config_chipset_for_dma(drive))
327 return hwif->ide_dma_on(drive);
328 }
329
330 goto fast_ata_pio;
331 322
332 } else if ((id->capability & 8) || (id->field_valid & 2)) { 323 if (ide_use_fast_pio(drive))
333fast_ata_pio:
334 config_chipset_for_pio(drive); 324 config_chipset_for_pio(drive);
335 // hwif->tuneproc(drive, 5);
336 return hwif->ide_dma_off_quietly(drive);
337 }
338 /* IORDY not supported */
339 return 0;
340}
341
342/* This can go soon */
343 325
344static int svwks_ide_dma_end (ide_drive_t *drive) 326 return -1;
345{
346 return __ide_dma_end(drive);
347} 327}
348 328
349static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const char *name) 329static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const char *name)
@@ -537,35 +517,20 @@ static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
537 } 517 }
538 518
539 hwif->ide_dma_check = &svwks_config_drive_xfer_rate; 519 hwif->ide_dma_check = &svwks_config_drive_xfer_rate;
540 if (hwif->pci_dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) 520 if (hwif->pci_dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
541 hwif->ide_dma_end = &svwks_ide_dma_end; 521 if (!hwif->udma_four)
542 else if (!(hwif->udma_four)) 522 hwif->udma_four = ata66_svwks(hwif);
543 hwif->udma_four = ata66_svwks(hwif); 523 }
544 if (!noautodma) 524 if (!noautodma)
545 hwif->autodma = 1; 525 hwif->autodma = 1;
546 526
547 dma_stat = hwif->INB(hwif->dma_status); 527 dma_stat = inb(hwif->dma_status);
548 hwif->drives[0].autodma = (dma_stat & 0x20); 528 hwif->drives[0].autodma = (dma_stat & 0x20);
549 hwif->drives[1].autodma = (dma_stat & 0x40); 529 hwif->drives[1].autodma = (dma_stat & 0x40);
550 hwif->drives[0].autotune = (!(dma_stat & 0x20)); 530 hwif->drives[0].autotune = (!(dma_stat & 0x20));
551 hwif->drives[1].autotune = (!(dma_stat & 0x40)); 531 hwif->drives[1].autotune = (!(dma_stat & 0x40));
552} 532}
553 533
554/*
555 * We allow the BM-DMA driver to only work on enabled interfaces.
556 */
557static void __devinit init_dma_svwks (ide_hwif_t *hwif, unsigned long dmabase)
558{
559 struct pci_dev *dev = hwif->pci_dev;
560
561 if (((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
562 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) &&
563 (!(PCI_FUNC(dev->devfn) & 1)) && (hwif->channel))
564 return;
565
566 ide_setup_dma(hwif, dmabase, 8);
567}
568
569static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d) 534static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d)
570{ 535{
571 return ide_setup_pci_device(dev, d); 536 return ide_setup_pci_device(dev, d);
@@ -600,7 +565,6 @@ static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
600 .init_setup = init_setup_svwks, 565 .init_setup = init_setup_svwks,
601 .init_chipset = init_chipset_svwks, 566 .init_chipset = init_chipset_svwks,
602 .init_hwif = init_hwif_svwks, 567 .init_hwif = init_hwif_svwks,
603 .init_dma = init_dma_svwks,
604 .channels = 2, 568 .channels = 2,
605 .autodma = AUTODMA, 569 .autodma = AUTODMA,
606 .bootable = ON_BOARD, 570 .bootable = ON_BOARD,
@@ -609,7 +573,6 @@ static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
609 .init_setup = init_setup_csb6, 573 .init_setup = init_setup_csb6,
610 .init_chipset = init_chipset_svwks, 574 .init_chipset = init_chipset_svwks,
611 .init_hwif = init_hwif_svwks, 575 .init_hwif = init_hwif_svwks,
612 .init_dma = init_dma_svwks,
613 .channels = 2, 576 .channels = 2,
614 .autodma = AUTODMA, 577 .autodma = AUTODMA,
615 .bootable = ON_BOARD, 578 .bootable = ON_BOARD,
@@ -618,7 +581,6 @@ static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
618 .init_setup = init_setup_csb6, 581 .init_setup = init_setup_csb6,
619 .init_chipset = init_chipset_svwks, 582 .init_chipset = init_chipset_svwks,
620 .init_hwif = init_hwif_svwks, 583 .init_hwif = init_hwif_svwks,
621 .init_dma = init_dma_svwks,
622 .channels = 1, /* 2 */ 584 .channels = 1, /* 2 */
623 .autodma = AUTODMA, 585 .autodma = AUTODMA,
624 .bootable = ON_BOARD, 586 .bootable = ON_BOARD,
@@ -627,7 +589,6 @@ static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
627 .init_setup = init_setup_svwks, 589 .init_setup = init_setup_svwks,
628 .init_chipset = init_chipset_svwks, 590 .init_chipset = init_chipset_svwks,
629 .init_hwif = init_hwif_svwks, 591 .init_hwif = init_hwif_svwks,
630 .init_dma = init_dma_svwks,
631 .channels = 1, /* 2 */ 592 .channels = 1, /* 2 */
632 .autodma = AUTODMA, 593 .autodma = AUTODMA,
633 .bootable = ON_BOARD, 594 .bootable = ON_BOARD,
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c
index b0bf018092..fd09b295a6 100644
--- a/drivers/ide/pci/sgiioc4.c
+++ b/drivers/ide/pci/sgiioc4.c
@@ -110,24 +110,24 @@ sgiioc4_init_hwif_ports(hw_regs_t * hw, unsigned long data_port,
110static void 110static void
111sgiioc4_maskproc(ide_drive_t * drive, int mask) 111sgiioc4_maskproc(ide_drive_t * drive, int mask)
112{ 112{
113 ide_hwif_t *hwif = HWIF(drive); 113 writeb(mask ? (drive->ctl | 2) : (drive->ctl & ~2),
114 hwif->OUTB(mask ? (drive->ctl | 2) : (drive->ctl & ~2), 114 (void __iomem *)IDE_CONTROL_REG);
115 IDE_CONTROL_REG);
116} 115}
117 116
118 117
119static int 118static int
120sgiioc4_checkirq(ide_hwif_t * hwif) 119sgiioc4_checkirq(ide_hwif_t * hwif)
121{ 120{
122 u8 intr_reg = 121 unsigned long intr_addr =
123 hwif->INL(hwif->io_ports[IDE_IRQ_OFFSET] + IOC4_INTR_REG * 4); 122 hwif->io_ports[IDE_IRQ_OFFSET] + IOC4_INTR_REG * 4;
124 123
125 if (intr_reg & 0x03) 124 if ((u8)readl((void __iomem *)intr_addr) & 0x03)
126 return 1; 125 return 1;
127 126
128 return 0; 127 return 0;
129} 128}
130 129
130static u8 sgiioc4_INB(unsigned long);
131 131
132static int 132static int
133sgiioc4_clearirq(ide_drive_t * drive) 133sgiioc4_clearirq(ide_drive_t * drive)
@@ -138,21 +138,21 @@ sgiioc4_clearirq(ide_drive_t * drive)
138 hwif->io_ports[IDE_IRQ_OFFSET] + (IOC4_INTR_REG << 2); 138 hwif->io_ports[IDE_IRQ_OFFSET] + (IOC4_INTR_REG << 2);
139 139
140 /* Code to check for PCI error conditions */ 140 /* Code to check for PCI error conditions */
141 intr_reg = hwif->INL(other_ir); 141 intr_reg = readl((void __iomem *)other_ir);
142 if (intr_reg & 0x03) { /* Valid IOC4-IDE interrupt */ 142 if (intr_reg & 0x03) { /* Valid IOC4-IDE interrupt */
143 /* 143 /*
144 * Using hwif->INB to read the IDE_STATUS_REG has a side effect 144 * Using sgiioc4_INB to read the IDE_STATUS_REG has a side effect
145 * of clearing the interrupt. The first read should clear it 145 * of clearing the interrupt. The first read should clear it
146 * if it is set. The second read should return a "clear" status 146 * if it is set. The second read should return a "clear" status
147 * if it got cleared. If not, then spin for a bit trying to 147 * if it got cleared. If not, then spin for a bit trying to
148 * clear it. 148 * clear it.
149 */ 149 */
150 u8 stat = hwif->INB(IDE_STATUS_REG); 150 u8 stat = sgiioc4_INB(IDE_STATUS_REG);
151 int count = 0; 151 int count = 0;
152 stat = hwif->INB(IDE_STATUS_REG); 152 stat = sgiioc4_INB(IDE_STATUS_REG);
153 while ((stat & 0x80) && (count++ < 100)) { 153 while ((stat & 0x80) && (count++ < 100)) {
154 udelay(1); 154 udelay(1);
155 stat = hwif->INB(IDE_STATUS_REG); 155 stat = sgiioc4_INB(IDE_STATUS_REG);
156 } 156 }
157 157
158 if (intr_reg & 0x02) { 158 if (intr_reg & 0x02) {
@@ -161,9 +161,9 @@ sgiioc4_clearirq(ide_drive_t * drive)
161 pci_stat_cmd_reg; 161 pci_stat_cmd_reg;
162 162
163 pci_err_addr_low = 163 pci_err_addr_low =
164 hwif->INL(hwif->io_ports[IDE_IRQ_OFFSET]); 164 readl((void __iomem *)hwif->io_ports[IDE_IRQ_OFFSET]);
165 pci_err_addr_high = 165 pci_err_addr_high =
166 hwif->INL(hwif->io_ports[IDE_IRQ_OFFSET] + 4); 166 readl((void __iomem *)(hwif->io_ports[IDE_IRQ_OFFSET] + 4));
167 pci_read_config_dword(hwif->pci_dev, PCI_COMMAND, 167 pci_read_config_dword(hwif->pci_dev, PCI_COMMAND,
168 &pci_stat_cmd_reg); 168 &pci_stat_cmd_reg);
169 printk(KERN_ERR 169 printk(KERN_ERR
@@ -180,9 +180,9 @@ sgiioc4_clearirq(ide_drive_t * drive)
180 } 180 }
181 181
182 /* Clear the Interrupt, Error bits on the IOC4 */ 182 /* Clear the Interrupt, Error bits on the IOC4 */
183 hwif->OUTL(0x03, other_ir); 183 writel(0x03, (void __iomem *)other_ir);
184 184
185 intr_reg = hwif->INL(other_ir); 185 intr_reg = readl((void __iomem *)other_ir);
186 } 186 }
187 187
188 return intr_reg & 3; 188 return intr_reg & 3;
@@ -191,23 +191,25 @@ sgiioc4_clearirq(ide_drive_t * drive)
191static void sgiioc4_ide_dma_start(ide_drive_t * drive) 191static void sgiioc4_ide_dma_start(ide_drive_t * drive)
192{ 192{
193 ide_hwif_t *hwif = HWIF(drive); 193 ide_hwif_t *hwif = HWIF(drive);
194 unsigned int reg = hwif->INL(hwif->dma_base + IOC4_DMA_CTRL * 4); 194 unsigned long ioc4_dma_addr = hwif->dma_base + IOC4_DMA_CTRL * 4;
195 unsigned int reg = readl((void __iomem *)ioc4_dma_addr);
195 unsigned int temp_reg = reg | IOC4_S_DMA_START; 196 unsigned int temp_reg = reg | IOC4_S_DMA_START;
196 197
197 hwif->OUTL(temp_reg, hwif->dma_base + IOC4_DMA_CTRL * 4); 198 writel(temp_reg, (void __iomem *)ioc4_dma_addr);
198} 199}
199 200
200static u32 201static u32
201sgiioc4_ide_dma_stop(ide_hwif_t *hwif, u64 dma_base) 202sgiioc4_ide_dma_stop(ide_hwif_t *hwif, u64 dma_base)
202{ 203{
204 unsigned long ioc4_dma_addr = dma_base + IOC4_DMA_CTRL * 4;
203 u32 ioc4_dma; 205 u32 ioc4_dma;
204 int count; 206 int count;
205 207
206 count = 0; 208 count = 0;
207 ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4); 209 ioc4_dma = readl((void __iomem *)ioc4_dma_addr);
208 while ((ioc4_dma & IOC4_S_DMA_STOP) && (count++ < 200)) { 210 while ((ioc4_dma & IOC4_S_DMA_STOP) && (count++ < 200)) {
209 udelay(1); 211 udelay(1);
210 ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4); 212 ioc4_dma = readl((void __iomem *)ioc4_dma_addr);
211 } 213 }
212 return ioc4_dma; 214 return ioc4_dma;
213} 215}
@@ -218,11 +220,11 @@ sgiioc4_ide_dma_end(ide_drive_t * drive)
218{ 220{
219 u32 ioc4_dma, bc_dev, bc_mem, num, valid = 0, cnt = 0; 221 u32 ioc4_dma, bc_dev, bc_mem, num, valid = 0, cnt = 0;
220 ide_hwif_t *hwif = HWIF(drive); 222 ide_hwif_t *hwif = HWIF(drive);
221 u64 dma_base = hwif->dma_base; 223 unsigned long dma_base = hwif->dma_base;
222 int dma_stat = 0; 224 int dma_stat = 0;
223 unsigned long *ending_dma = ide_get_hwifdata(hwif); 225 unsigned long *ending_dma = ide_get_hwifdata(hwif);
224 226
225 hwif->OUTL(IOC4_S_DMA_STOP, dma_base + IOC4_DMA_CTRL * 4); 227 writel(IOC4_S_DMA_STOP, (void __iomem *)(dma_base + IOC4_DMA_CTRL * 4));
226 228
227 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base); 229 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);
228 230
@@ -254,8 +256,8 @@ sgiioc4_ide_dma_end(ide_drive_t * drive)
254 dma_stat = 1; 256 dma_stat = 1;
255 } 257 }
256 258
257 bc_dev = hwif->INL(dma_base + IOC4_BC_DEV * 4); 259 bc_dev = readl((void __iomem *)(dma_base + IOC4_BC_DEV * 4));
258 bc_mem = hwif->INL(dma_base + IOC4_BC_MEM * 4); 260 bc_mem = readl((void __iomem *)(dma_base + IOC4_BC_MEM * 4));
259 261
260 if ((bc_dev & 0x01FF) || (bc_mem & 0x1FF)) { 262 if ((bc_dev & 0x01FF) || (bc_mem & 0x1FF)) {
261 if (bc_dev > bc_mem + 8) { 263 if (bc_dev > bc_mem + 8) {
@@ -273,34 +275,29 @@ sgiioc4_ide_dma_end(ide_drive_t * drive)
273} 275}
274 276
275static int 277static int
276sgiioc4_ide_dma_check(ide_drive_t * drive) 278sgiioc4_ide_dma_on(ide_drive_t * drive)
277{ 279{
278 if (ide_config_drive_speed(drive, XFER_MW_DMA_2) != 0) { 280 drive->using_dma = 1;
279 printk(KERN_INFO
280 "Couldnot set %s in Multimode-2 DMA mode | "
281 "Drive %s using PIO instead\n",
282 drive->name, drive->name);
283 drive->using_dma = 0;
284 } else
285 drive->using_dma = 1;
286 281
287 return 0; 282 return 0;
288} 283}
289 284
290static int 285static void sgiioc4_dma_off_quietly(ide_drive_t *drive)
291sgiioc4_ide_dma_on(ide_drive_t * drive)
292{ 286{
293 drive->using_dma = 1; 287 drive->using_dma = 0;
294 288
295 return HWIF(drive)->ide_dma_host_on(drive); 289 drive->hwif->dma_host_off(drive);
296} 290}
297 291
298static int 292static int sgiioc4_ide_dma_check(ide_drive_t *drive)
299sgiioc4_ide_dma_off_quietly(ide_drive_t * drive)
300{ 293{
301 drive->using_dma = 0; 294 /* FIXME: check for available DMA modes */
302 295 if (ide_config_drive_speed(drive, XFER_MW_DMA_2) != 0) {
303 return HWIF(drive)->ide_dma_host_off(drive); 296 printk(KERN_WARNING "%s: couldn't set MWDMA2 mode, "
297 "using PIO instead\n", drive->name);
298 return -1;
299 } else
300 return 0;
304} 301}
305 302
306/* returns 1 if dma irq issued, 0 otherwise */ 303/* returns 1 if dma irq issued, 0 otherwise */
@@ -310,21 +307,13 @@ sgiioc4_ide_dma_test_irq(ide_drive_t * drive)
310 return sgiioc4_checkirq(HWIF(drive)); 307 return sgiioc4_checkirq(HWIF(drive));
311} 308}
312 309
313static int 310static void sgiioc4_dma_host_on(ide_drive_t * drive)
314sgiioc4_ide_dma_host_on(ide_drive_t * drive)
315{ 311{
316 if (drive->using_dma)
317 return 0;
318
319 return 1;
320} 312}
321 313
322static int 314static void sgiioc4_dma_host_off(ide_drive_t * drive)
323sgiioc4_ide_dma_host_off(ide_drive_t * drive)
324{ 315{
325 sgiioc4_clearirq(drive); 316 sgiioc4_clearirq(drive);
326
327 return 0;
328} 317}
329 318
330static int 319static int
@@ -436,16 +425,17 @@ sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive)
436{ 425{
437 u32 ioc4_dma; 426 u32 ioc4_dma;
438 ide_hwif_t *hwif = HWIF(drive); 427 ide_hwif_t *hwif = HWIF(drive);
439 u64 dma_base = hwif->dma_base; 428 unsigned long dma_base = hwif->dma_base;
429 unsigned long ioc4_dma_addr = dma_base + IOC4_DMA_CTRL * 4;
440 u32 dma_addr, ending_dma_addr; 430 u32 dma_addr, ending_dma_addr;
441 431
442 ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4); 432 ioc4_dma = readl((void __iomem *)ioc4_dma_addr);
443 433
444 if (ioc4_dma & IOC4_S_DMA_ACTIVE) { 434 if (ioc4_dma & IOC4_S_DMA_ACTIVE) {
445 printk(KERN_WARNING 435 printk(KERN_WARNING
446 "%s(%s):Warning!! DMA from previous transfer was still active\n", 436 "%s(%s):Warning!! DMA from previous transfer was still active\n",
447 __FUNCTION__, drive->name); 437 __FUNCTION__, drive->name);
448 hwif->OUTL(IOC4_S_DMA_STOP, dma_base + IOC4_DMA_CTRL * 4); 438 writel(IOC4_S_DMA_STOP, (void __iomem *)ioc4_dma_addr);
449 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base); 439 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);
450 440
451 if (ioc4_dma & IOC4_S_DMA_STOP) 441 if (ioc4_dma & IOC4_S_DMA_STOP)
@@ -454,13 +444,13 @@ sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive)
454 __FUNCTION__, drive->name); 444 __FUNCTION__, drive->name);
455 } 445 }
456 446
457 ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4); 447 ioc4_dma = readl((void __iomem *)ioc4_dma_addr);
458 if (ioc4_dma & IOC4_S_DMA_ERROR) { 448 if (ioc4_dma & IOC4_S_DMA_ERROR) {
459 printk(KERN_WARNING 449 printk(KERN_WARNING
460 "%s(%s) : Warning!! - DMA Error during Previous" 450 "%s(%s) : Warning!! - DMA Error during Previous"
461 " transfer | status 0x%x\n", 451 " transfer | status 0x%x\n",
462 __FUNCTION__, drive->name, ioc4_dma); 452 __FUNCTION__, drive->name, ioc4_dma);
463 hwif->OUTL(IOC4_S_DMA_STOP, dma_base + IOC4_DMA_CTRL * 4); 453 writel(IOC4_S_DMA_STOP, (void __iomem *)ioc4_dma_addr);
464 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base); 454 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);
465 455
466 if (ioc4_dma & IOC4_S_DMA_STOP) 456 if (ioc4_dma & IOC4_S_DMA_STOP)
@@ -471,14 +461,14 @@ sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive)
471 461
472 /* Address of the Scatter Gather List */ 462 /* Address of the Scatter Gather List */
473 dma_addr = cpu_to_le32(hwif->dmatable_dma); 463 dma_addr = cpu_to_le32(hwif->dmatable_dma);
474 hwif->OUTL(dma_addr, dma_base + IOC4_DMA_PTR_L * 4); 464 writel(dma_addr, (void __iomem *)(dma_base + IOC4_DMA_PTR_L * 4));
475 465
476 /* Address of the Ending DMA */ 466 /* Address of the Ending DMA */
477 memset(ide_get_hwifdata(hwif), 0, IOC4_IDE_CACHELINE_SIZE); 467 memset(ide_get_hwifdata(hwif), 0, IOC4_IDE_CACHELINE_SIZE);
478 ending_dma_addr = cpu_to_le32(hwif->dma_status); 468 ending_dma_addr = cpu_to_le32(hwif->dma_status);
479 hwif->OUTL(ending_dma_addr, dma_base + IOC4_DMA_END_ADDR * 4); 469 writel(ending_dma_addr, (void __iomem *)(dma_base + IOC4_DMA_END_ADDR * 4));
480 470
481 hwif->OUTL(dma_direction, dma_base + IOC4_DMA_CTRL * 4); 471 writel(dma_direction, (void __iomem *)ioc4_dma_addr);
482 drive->waiting_for_dma = 1; 472 drive->waiting_for_dma = 1;
483} 473}
484 474
@@ -590,7 +580,7 @@ static int sgiioc4_ide_dma_setup(ide_drive_t *drive)
590static void __devinit 580static void __devinit
591ide_init_sgiioc4(ide_hwif_t * hwif) 581ide_init_sgiioc4(ide_hwif_t * hwif)
592{ 582{
593 hwif->mmio = 2; 583 hwif->mmio = 1;
594 hwif->autodma = 1; 584 hwif->autodma = 1;
595 hwif->atapi_dma = 1; 585 hwif->atapi_dma = 1;
596 hwif->ultra_mask = 0x0; /* Disable Ultra DMA */ 586 hwif->ultra_mask = 0x0; /* Disable Ultra DMA */
@@ -613,10 +603,10 @@ ide_init_sgiioc4(ide_hwif_t * hwif)
613 hwif->ide_dma_end = &sgiioc4_ide_dma_end; 603 hwif->ide_dma_end = &sgiioc4_ide_dma_end;
614 hwif->ide_dma_check = &sgiioc4_ide_dma_check; 604 hwif->ide_dma_check = &sgiioc4_ide_dma_check;
615 hwif->ide_dma_on = &sgiioc4_ide_dma_on; 605 hwif->ide_dma_on = &sgiioc4_ide_dma_on;
616 hwif->ide_dma_off_quietly = &sgiioc4_ide_dma_off_quietly; 606 hwif->dma_off_quietly = &sgiioc4_dma_off_quietly;
617 hwif->ide_dma_test_irq = &sgiioc4_ide_dma_test_irq; 607 hwif->ide_dma_test_irq = &sgiioc4_ide_dma_test_irq;
618 hwif->ide_dma_host_on = &sgiioc4_ide_dma_host_on; 608 hwif->dma_host_on = &sgiioc4_dma_host_on;
619 hwif->ide_dma_host_off = &sgiioc4_ide_dma_host_off; 609 hwif->dma_host_off = &sgiioc4_dma_host_off;
620 hwif->ide_dma_lostirq = &sgiioc4_ide_dma_lostirq; 610 hwif->ide_dma_lostirq = &sgiioc4_ide_dma_lostirq;
621 hwif->ide_dma_timeout = &__ide_dma_timeout; 611 hwif->ide_dma_timeout = &__ide_dma_timeout;
622 612
@@ -688,7 +678,7 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t * d)
688 default_hwif_mmiops(hwif); 678 default_hwif_mmiops(hwif);
689 679
690 /* Initializing chipset IRQ Registers */ 680 /* Initializing chipset IRQ Registers */
691 hwif->OUTL(0x03, irqport + IOC4_INTR_SET * 4); 681 writel(0x03, (void __iomem *)(irqport + IOC4_INTR_SET * 4));
692 682
693 ide_init_sgiioc4(hwif); 683 ide_init_sgiioc4(hwif);
694 684
@@ -729,8 +719,7 @@ out:
729 return ret; 719 return ret;
730} 720}
731 721
732static ide_pci_device_t sgiioc4_chipsets[] __devinitdata = { 722static ide_pci_device_t sgiioc4_chipset __devinitdata = {
733 {
734 /* Channel 0 */ 723 /* Channel 0 */
735 .name = "SGIIOC4", 724 .name = "SGIIOC4",
736 .init_hwif = ide_init_sgiioc4, 725 .init_hwif = ide_init_sgiioc4,
@@ -739,7 +728,6 @@ static ide_pci_device_t sgiioc4_chipsets[] __devinitdata = {
739 .autodma = AUTODMA, 728 .autodma = AUTODMA,
740 /* SGI IOC4 doesn't have enablebits. */ 729 /* SGI IOC4 doesn't have enablebits. */
741 .bootable = ON_BOARD, 730 .bootable = ON_BOARD,
742 }
743}; 731};
744 732
745int 733int
@@ -751,8 +739,7 @@ ioc4_ide_attach_one(struct ioc4_driver_data *idd)
751 if (idd->idd_variant == IOC4_VARIANT_PCI_RT) 739 if (idd->idd_variant == IOC4_VARIANT_PCI_RT)
752 return 0; 740 return 0;
753 741
754 return pci_init_sgiioc4(idd->idd_pdev, 742 return pci_init_sgiioc4(idd->idd_pdev, &sgiioc4_chipset);
755 &sgiioc4_chipsets[idd->idd_pci_id->driver_data]);
756} 743}
757 744
758static struct ioc4_submodule ioc4_ide_submodule = { 745static struct ioc4_submodule ioc4_ide_submodule = {
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index 4ff89c7d99..71eccdf5f8 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -1,8 +1,9 @@
1/* 1/*
2 * linux/drivers/ide/pci/siimage.c Version 1.07 Nov 30, 2003 2 * linux/drivers/ide/pci/siimage.c Version 1.11 Jan 27, 2007
3 * 3 *
4 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org> 4 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2003 Red Hat <alan@redhat.com> 5 * Copyright (C) 2003 Red Hat <alan@redhat.com>
6 * Copyright (C) 2007 MontaVista Software, Inc.
6 * 7 *
7 * May be copied or modified under the terms of the GNU General Public License 8 * May be copied or modified under the terms of the GNU General Public License
8 * 9 *
@@ -25,6 +26,11 @@
25 * If you have strange problems with nVidia chipset systems please 26 * If you have strange problems with nVidia chipset systems please
26 * see the SI support documentation and update your system BIOS 27 * see the SI support documentation and update your system BIOS
27 * if neccessary 28 * if neccessary
29 *
30 * The Dell DRAC4 has some interesting features including effectively hot
31 * unplugging/replugging the virtual CD interface when the DRAC is reset.
32 * This often causes drivers/ide/siimage to panic but is ok with the rather
33 * smarter code in libata.
28 */ 34 */
29 35
30#include <linux/types.h> 36#include <linux/types.h>
@@ -205,41 +211,39 @@ static void siimage_tuneproc (ide_drive_t *drive, byte mode_wanted)
205 unsigned long tfaddr = siimage_selreg(hwif, 0x02); 211 unsigned long tfaddr = siimage_selreg(hwif, 0x02);
206 212
207 /* cheat for now and use the docs */ 213 /* cheat for now and use the docs */
208 switch(mode_wanted) { 214 switch (mode_wanted) {
209 case 4: 215 case 4:
210 speedp = 0x10c1; 216 speedp = 0x10c1;
211 speedt = 0x10c1; 217 speedt = 0x10c1;
212 break; 218 break;
213 case 3: 219 case 3:
214 speedp = 0x10C3; 220 speedp = 0x10c3;
215 speedt = 0x10C3; 221 speedt = 0x10c3;
216 break; 222 break;
217 case 2: 223 case 2:
218 speedp = 0x1104; 224 speedp = 0x1104;
219 speedt = 0x1281; 225 speedt = 0x1281;
220 break; 226 break;
221 case 1: 227 case 1:
222 speedp = 0x2283; 228 speedp = 0x2283;
223 speedt = 0x1281; 229 speedt = 0x2283;
224 break; 230 break;
225 case 0: 231 case 0:
226 default: 232 default:
227 speedp = 0x328A; 233 speedp = 0x328a;
228 speedt = 0x328A; 234 speedt = 0x328a;
229 break; 235 break;
230 } 236 }
231 if (hwif->mmio) 237
232 { 238 if (hwif->mmio) {
233 hwif->OUTW(speedt, addr); 239 hwif->OUTW(speedp, addr);
234 hwif->OUTW(speedp, tfaddr); 240 hwif->OUTW(speedt, tfaddr);
235 /* Now set up IORDY */ 241 /* Now set up IORDY */
236 if(mode_wanted == 3 || mode_wanted == 4) 242 if(mode_wanted == 3 || mode_wanted == 4)
237 hwif->OUTW(hwif->INW(tfaddr-2)|0x200, tfaddr-2); 243 hwif->OUTW(hwif->INW(tfaddr-2)|0x200, tfaddr-2);
238 else 244 else
239 hwif->OUTW(hwif->INW(tfaddr-2)&~0x200, tfaddr-2); 245 hwif->OUTW(hwif->INW(tfaddr-2)&~0x200, tfaddr-2);
240 } 246 } else {
241 else
242 {
243 pci_write_config_word(hwif->pci_dev, addr, speedp); 247 pci_write_config_word(hwif->pci_dev, addr, speedp);
244 pci_write_config_word(hwif->pci_dev, tfaddr, speedt); 248 pci_write_config_word(hwif->pci_dev, tfaddr, speedt);
245 pci_read_config_word(hwif->pci_dev, tfaddr-2, &speedp); 249 pci_read_config_word(hwif->pci_dev, tfaddr-2, &speedp);
@@ -397,12 +401,9 @@ static int config_chipset_for_dma (ide_drive_t *drive)
397 if (!speed) 401 if (!speed)
398 return 0; 402 return 0;
399 403
400 if (ide_set_xfer_rate(drive, speed)) 404 if (siimage_tune_chipset(drive, speed))
401 return 0; 405 return 0;
402 406
403 if (!drive->init_speed)
404 drive->init_speed = speed;
405
406 return ide_dma_enable(drive); 407 return ide_dma_enable(drive);
407} 408}
408 409
@@ -418,25 +419,13 @@ static int config_chipset_for_dma (ide_drive_t *drive)
418 419
419static int siimage_config_drive_for_dma (ide_drive_t *drive) 420static int siimage_config_drive_for_dma (ide_drive_t *drive)
420{ 421{
421 ide_hwif_t *hwif = HWIF(drive); 422 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
422 struct hd_driveid *id = drive->id; 423 return 0;
423
424 if ((id->capability & 1) != 0 && drive->autodma) {
425
426 if (ide_use_dma(drive)) {
427 if (config_chipset_for_dma(drive))
428 return hwif->ide_dma_on(drive);
429 }
430
431 goto fast_ata_pio;
432 424
433 } else if ((id->capability & 8) || (id->field_valid & 2)) { 425 if (ide_use_fast_pio(drive))
434fast_ata_pio:
435 config_chipset_for_pio(drive, 1); 426 config_chipset_for_pio(drive, 1);
436 return hwif->ide_dma_off_quietly(drive); 427
437 } 428 return -1;
438 /* IORDY not supported */
439 return 0;
440} 429}
441 430
442/* returns 1 if dma irq issued, 0 otherwise */ 431/* returns 1 if dma irq issued, 0 otherwise */
@@ -472,11 +461,11 @@ static int siimage_mmio_ide_dma_test_irq (ide_drive_t *drive)
472 unsigned long addr = siimage_selreg(hwif, 0x1); 461 unsigned long addr = siimage_selreg(hwif, 0x1);
473 462
474 if (SATA_ERROR_REG) { 463 if (SATA_ERROR_REG) {
475 u32 ext_stat = hwif->INL(base + 0x10); 464 u32 ext_stat = readl((void __iomem *)(base + 0x10));
476 u8 watchdog = 0; 465 u8 watchdog = 0;
477 if (ext_stat & ((hwif->channel) ? 0x40 : 0x10)) { 466 if (ext_stat & ((hwif->channel) ? 0x40 : 0x10)) {
478 u32 sata_error = hwif->INL(SATA_ERROR_REG); 467 u32 sata_error = readl((void __iomem *)SATA_ERROR_REG);
479 hwif->OUTL(sata_error, SATA_ERROR_REG); 468 writel(sata_error, (void __iomem *)SATA_ERROR_REG);
480 watchdog = (sata_error & 0x00680000) ? 1 : 0; 469 watchdog = (sata_error & 0x00680000) ? 1 : 0;
481 printk(KERN_WARNING "%s: sata_error = 0x%08x, " 470 printk(KERN_WARNING "%s: sata_error = 0x%08x, "
482 "watchdog = %d, %s\n", 471 "watchdog = %d, %s\n",
@@ -493,11 +482,11 @@ static int siimage_mmio_ide_dma_test_irq (ide_drive_t *drive)
493 } 482 }
494 483
495 /* return 1 if INTR asserted */ 484 /* return 1 if INTR asserted */
496 if ((hwif->INB(hwif->dma_status) & 0x04) == 0x04) 485 if ((readb((void __iomem *)hwif->dma_status) & 0x04) == 0x04)
497 return 1; 486 return 1;
498 487
499 /* return 1 if Device INTR asserted */ 488 /* return 1 if Device INTR asserted */
500 if ((hwif->INB(addr) & 8) == 8) 489 if ((readb((void __iomem *)addr) & 8) == 8)
501 return 0; //return 1; 490 return 0; //return 1;
502 491
503 return 0; 492 return 0;
@@ -519,9 +508,9 @@ static int siimage_busproc (ide_drive_t * drive, int state)
519 u32 stat_config = 0; 508 u32 stat_config = 0;
520 unsigned long addr = siimage_selreg(hwif, 0); 509 unsigned long addr = siimage_selreg(hwif, 0);
521 510
522 if (hwif->mmio) { 511 if (hwif->mmio)
523 stat_config = hwif->INL(addr); 512 stat_config = readl((void __iomem *)addr);
524 } else 513 else
525 pci_read_config_dword(hwif->pci_dev, addr, &stat_config); 514 pci_read_config_dword(hwif->pci_dev, addr, &stat_config);
526 515
527 switch (state) { 516 switch (state) {
@@ -557,9 +546,10 @@ static int siimage_reset_poll (ide_drive_t *drive)
557 if (SATA_STATUS_REG) { 546 if (SATA_STATUS_REG) {
558 ide_hwif_t *hwif = HWIF(drive); 547 ide_hwif_t *hwif = HWIF(drive);
559 548
560 if ((hwif->INL(SATA_STATUS_REG) & 0x03) != 0x03) { 549 /* SATA_STATUS_REG is valid only when in MMIO mode */
550 if ((readl((void __iomem *)SATA_STATUS_REG) & 0x03) != 0x03) {
561 printk(KERN_WARNING "%s: reset phy dead, status=0x%08x\n", 551 printk(KERN_WARNING "%s: reset phy dead, status=0x%08x\n",
562 hwif->name, hwif->INL(SATA_STATUS_REG)); 552 hwif->name, readl((void __iomem *)SATA_STATUS_REG));
563 HWGROUP(drive)->polling = 0; 553 HWGROUP(drive)->polling = 0;
564 return ide_started; 554 return ide_started;
565 } 555 }
@@ -619,7 +609,8 @@ static void siimage_reset (ide_drive_t *drive)
619 } 609 }
620 610
621 if (SATA_STATUS_REG) { 611 if (SATA_STATUS_REG) {
622 u32 sata_stat = hwif->INL(SATA_STATUS_REG); 612 /* SATA_STATUS_REG is valid only when in MMIO mode */
613 u32 sata_stat = readl((void __iomem *)SATA_STATUS_REG);
623 printk(KERN_WARNING "%s: reset phy, status=0x%08x, %s\n", 614 printk(KERN_WARNING "%s: reset phy, status=0x%08x, %s\n",
624 hwif->name, sata_stat, __FUNCTION__); 615 hwif->name, sata_stat, __FUNCTION__);
625 if (!(sata_stat)) { 616 if (!(sata_stat)) {
@@ -898,7 +889,8 @@ static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif)
898 base = (unsigned long) addr; 889 base = (unsigned long) addr;
899 890
900 hwif->dma_base = base + (ch ? 0x08 : 0x00); 891 hwif->dma_base = base + (ch ? 0x08 : 0x00);
901 hwif->mmio = 2; 892
893 hwif->mmio = 1;
902} 894}
903 895
904static int is_dev_seagate_sata(ide_drive_t *drive) 896static int is_dev_seagate_sata(ide_drive_t *drive)
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index 1afff659ab..2ba0669f36 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -667,67 +667,20 @@ static int config_chipset_for_dma (ide_drive_t *drive)
667 return ide_dma_enable(drive); 667 return ide_dma_enable(drive);
668} 668}
669 669
670static int sis5513_config_drive_xfer_rate (ide_drive_t *drive) 670static int sis5513_config_xfer_rate(ide_drive_t *drive)
671{ 671{
672 ide_hwif_t *hwif = HWIF(drive); 672 config_art_rwp_pio(drive, 5);
673 struct hd_driveid *id = drive->id;
674 673
675 drive->init_speed = 0; 674 drive->init_speed = 0;
676 675
677 if (id && (id->capability & 1) && drive->autodma) { 676 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
678 677 return 0;
679 if (ide_use_dma(drive)) {
680 if (config_chipset_for_dma(drive))
681 return hwif->ide_dma_on(drive);
682 }
683
684 goto fast_ata_pio;
685 678
686 } else if ((id->capability & 8) || (id->field_valid & 2)) { 679 if (ide_use_fast_pio(drive))
687fast_ata_pio:
688 sis5513_tune_drive(drive, 5); 680 sis5513_tune_drive(drive, 5);
689 return hwif->ide_dma_off_quietly(drive);
690 }
691 /* IORDY not supported */
692 return 0;
693}
694
695/* initiates/aborts (U)DMA read/write operations on a drive. */
696static int sis5513_config_xfer_rate (ide_drive_t *drive)
697{
698 config_drive_art_rwp(drive);
699 config_art_rwp_pio(drive, 5);
700 return sis5513_config_drive_xfer_rate(drive);
701}
702
703/*
704 Future simpler config_xfer_rate :
705 When ide_find_best_mode is made bad-drive aware
706 - remove config_drive_xfer_rate and config_chipset_for_dma,
707 - replace config_xfer_rate with the following
708
709static int sis5513_config_xfer_rate (ide_drive_t *drive)
710{
711 u16 w80 = HWIF(drive)->udma_four;
712 u16 speed;
713
714 config_drive_art_rwp(drive);
715 config_art_rwp_pio(drive, 5);
716
717 speed = ide_find_best_mode(drive,
718 XFER_PIO | XFER_EPIO | XFER_SWDMA | XFER_MWDMA |
719 (chipset_family >= ATA_33 ? XFER_UDMA : 0) |
720 (w80 && chipset_family >= ATA_66 ? XFER_UDMA_66 : 0) |
721 (w80 && chipset_family >= ATA_100a ? XFER_UDMA_100 : 0) |
722 (w80 && chipset_family >= ATA_133a ? XFER_UDMA_133 : 0));
723
724 sis5513_tune_chipset(drive, speed);
725 681
726 if (drive->autodma && (speed & XFER_MODE) != XFER_PIO) 682 return -1;
727 return HWIF(drive)->ide_dma_on(drive);
728 return HWIF(drive)->ide_dma_off_quietly(drive);
729} 683}
730*/
731 684
732/* Chip detection and general config */ 685/* Chip detection and general config */
733static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const char *name) 686static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const char *name)
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c
index 170a261990..3a8a76fc78 100644
--- a/drivers/ide/pci/sl82c105.c
+++ b/drivers/ide/pci/sl82c105.c
@@ -161,14 +161,14 @@ static int sl82c105_check_drive (ide_drive_t *drive)
161 if (id->field_valid & 2) { 161 if (id->field_valid & 2) {
162 if ((id->dma_mword & hwif->mwdma_mask) || 162 if ((id->dma_mword & hwif->mwdma_mask) ||
163 (id->dma_1word & hwif->swdma_mask)) 163 (id->dma_1word & hwif->swdma_mask))
164 return hwif->ide_dma_on(drive); 164 return 0;
165 } 165 }
166 166
167 if (__ide_dma_good_drive(drive)) 167 if (__ide_dma_good_drive(drive) && id->eide_dma_time < 150)
168 return hwif->ide_dma_on(drive); 168 return 0;
169 } while (0); 169 } while (0);
170 170
171 return hwif->ide_dma_off_quietly(drive); 171 return -1;
172} 172}
173 173
174/* 174/*
@@ -215,7 +215,7 @@ static int sl82c105_ide_dma_lost_irq(ide_drive_t *drive)
215 * Was DMA enabled? If so, disable it - we're resetting the 215 * Was DMA enabled? If so, disable it - we're resetting the
216 * host. The IDE layer will be handling the drive for us. 216 * host. The IDE layer will be handling the drive for us.
217 */ 217 */
218 val = hwif->INB(dma_base); 218 val = inb(dma_base);
219 if (val & 1) { 219 if (val & 1) {
220 outb(val & ~1, dma_base); 220 outb(val & ~1, dma_base);
221 printk("sl82c105: DMA was enabled\n"); 221 printk("sl82c105: DMA was enabled\n");
@@ -259,28 +259,22 @@ static int sl82c105_ide_dma_on (ide_drive_t *drive)
259{ 259{
260 DBG(("sl82c105_ide_dma_on(drive:%s)\n", drive->name)); 260 DBG(("sl82c105_ide_dma_on(drive:%s)\n", drive->name));
261 261
262 if (config_for_dma(drive)) { 262 if (config_for_dma(drive))
263 config_for_pio(drive, 4, 0, 0); 263 return 1;
264 return HWIF(drive)->ide_dma_off_quietly(drive);
265 }
266 printk(KERN_INFO "%s: DMA enabled\n", drive->name); 264 printk(KERN_INFO "%s: DMA enabled\n", drive->name);
267 return __ide_dma_on(drive); 265 return __ide_dma_on(drive);
268} 266}
269 267
270static int sl82c105_ide_dma_off_quietly (ide_drive_t *drive) 268static void sl82c105_dma_off_quietly(ide_drive_t *drive)
271{ 269{
272 u8 speed = XFER_PIO_0; 270 u8 speed = XFER_PIO_0;
273 int rc;
274
275 DBG(("sl82c105_ide_dma_off_quietly(drive:%s)\n", drive->name));
276 271
277 rc = __ide_dma_off_quietly(drive); 272 DBG(("sl82c105_dma_off_quietly(drive:%s)\n", drive->name));
273
274 ide_dma_off_quietly(drive);
278 if (drive->pio_speed) 275 if (drive->pio_speed)
279 speed = drive->pio_speed - XFER_PIO_0; 276 speed = drive->pio_speed - XFER_PIO_0;
280 config_for_pio(drive, speed, 0, 1); 277 config_for_pio(drive, speed, 0, 1);
281 drive->current_speed = drive->pio_speed;
282
283 return rc;
284} 278}
285 279
286/* 280/*
@@ -401,11 +395,9 @@ static unsigned int __devinit init_chipset_sl82c105(struct pci_dev *dev, const c
401/* 395/*
402 * Initialise the chip 396 * Initialise the chip
403 */ 397 */
404
405static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif) 398static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif)
406{ 399{
407 unsigned int rev; 400 unsigned int rev;
408 u8 dma_state;
409 401
410 DBG(("init_hwif_sl82c105(hwif: ide%d)\n", hwif->index)); 402 DBG(("init_hwif_sl82c105(hwif: ide%d)\n", hwif->index));
411 403
@@ -431,7 +423,6 @@ static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif)
431 if (!hwif->dma_base) 423 if (!hwif->dma_base)
432 return; 424 return;
433 425
434 dma_state = hwif->INB(hwif->dma_base + 2) & ~0x60;
435 rev = sl82c105_bridge_revision(hwif->pci_dev); 426 rev = sl82c105_bridge_revision(hwif->pci_dev);
436 if (rev <= 5) { 427 if (rev <= 5) {
437 /* 428 /*
@@ -441,15 +432,12 @@ static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif)
441 printk(" %s: Winbond 553 bridge revision %d, BM-DMA disabled\n", 432 printk(" %s: Winbond 553 bridge revision %d, BM-DMA disabled\n",
442 hwif->name, rev); 433 hwif->name, rev);
443 } else { 434 } else {
444 dma_state |= 0x60;
445
446 hwif->atapi_dma = 1; 435 hwif->atapi_dma = 1;
447 hwif->mwdma_mask = 0x07; 436 hwif->mwdma_mask = 0x04;
448 hwif->swdma_mask = 0x07;
449 437
450 hwif->ide_dma_check = &sl82c105_check_drive; 438 hwif->ide_dma_check = &sl82c105_check_drive;
451 hwif->ide_dma_on = &sl82c105_ide_dma_on; 439 hwif->ide_dma_on = &sl82c105_ide_dma_on;
452 hwif->ide_dma_off_quietly = &sl82c105_ide_dma_off_quietly; 440 hwif->dma_off_quietly = &sl82c105_dma_off_quietly;
453 hwif->ide_dma_lostirq = &sl82c105_ide_dma_lost_irq; 441 hwif->ide_dma_lostirq = &sl82c105_ide_dma_lost_irq;
454 hwif->dma_start = &sl82c105_ide_dma_start; 442 hwif->dma_start = &sl82c105_ide_dma_start;
455 hwif->ide_dma_timeout = &sl82c105_ide_dma_timeout; 443 hwif->ide_dma_timeout = &sl82c105_ide_dma_timeout;
@@ -462,7 +450,6 @@ static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif)
462 if (hwif->mate) 450 if (hwif->mate)
463 hwif->serialized = hwif->mate->serialized = 1; 451 hwif->serialized = hwif->mate->serialized = 1;
464 } 452 }
465 hwif->OUTB(dma_state, hwif->dma_base + 2);
466} 453}
467 454
468static ide_pci_device_t sl82c105_chipset __devinitdata = { 455static ide_pci_device_t sl82c105_chipset __devinitdata = {
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c
index 2663ddbd9b..852ccb36da 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/pci/slc90e66.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * linux/drivers/ide/pci/slc90e66.c Version 0.13 December 30, 2006 2 * linux/drivers/ide/pci/slc90e66.c Version 0.14 February 8, 2007
3 * 3 *
4 * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org> 4 * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2006 MontaVista Software, Inc. <source@mvista.com> 5 * Copyright (C) 2006-2007 MontaVista Software, Inc. <source@mvista.com>
6 * 6 *
7 * This is a look-alike variation of the ICH0 PIIX4 Ultra-66, 7 * This is a look-alike variation of the ICH0 PIIX4 Ultra-66,
8 * but this keeps the ISA-Bridge and slots alive. 8 * but this keeps the ISA-Bridge and slots alive.
@@ -57,11 +57,7 @@ static u8 slc90e66_dma_2_pio (u8 xfer_rate) {
57 } 57 }
58} 58}
59 59
60/* 60static void slc90e66_tune_pio (ide_drive_t *drive, u8 pio)
61 * Based on settings done by AMI BIOS
62 * (might be useful if drive is not registered in CMOS for any reason).
63 */
64static void slc90e66_tune_drive (ide_drive_t *drive, u8 pio)
65{ 61{
66 ide_hwif_t *hwif = HWIF(drive); 62 ide_hwif_t *hwif = HWIF(drive);
67 struct pci_dev *dev = hwif->pci_dev; 63 struct pci_dev *dev = hwif->pci_dev;
@@ -80,7 +76,6 @@ static void slc90e66_tune_drive (ide_drive_t *drive, u8 pio)
80 { 2, 1 }, 76 { 2, 1 },
81 { 2, 3 }, }; 77 { 2, 3 }, };
82 78
83 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
84 spin_lock_irqsave(&ide_lock, flags); 79 spin_lock_irqsave(&ide_lock, flags);
85 pci_read_config_word(dev, master_port, &master_data); 80 pci_read_config_word(dev, master_port, &master_data);
86 81
@@ -94,19 +89,20 @@ static void slc90e66_tune_drive (ide_drive_t *drive, u8 pio)
94 master_data |= 0x4000; 89 master_data |= 0x4000;
95 master_data &= ~0x0070; 90 master_data &= ~0x0070;
96 if (pio > 1) { 91 if (pio > 1) {
97 /* enable PPE, IE and TIME */ 92 /* Set PPE, IE and TIME */
98 master_data = master_data | (control << 4); 93 master_data |= control << 4;
99 } 94 }
100 pci_read_config_byte(dev, slave_port, &slave_data); 95 pci_read_config_byte(dev, slave_port, &slave_data);
101 slave_data = slave_data & (hwif->channel ? 0x0f : 0xf0); 96 slave_data &= hwif->channel ? 0x0f : 0xf0;
102 slave_data = slave_data | (((timings[pio][0] << 2) | timings[pio][1]) << (hwif->channel ? 4 : 0)); 97 slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) <<
98 (hwif->channel ? 4 : 0);
103 } else { 99 } else {
104 master_data &= ~0x3307; 100 master_data &= ~0x3307;
105 if (pio > 1) { 101 if (pio > 1) {
106 /* enable PPE, IE and TIME */ 102 /* enable PPE, IE and TIME */
107 master_data = master_data | control; 103 master_data |= control;
108 } 104 }
109 master_data = master_data | (timings[pio][0] << 12) | (timings[pio][1] << 8); 105 master_data |= (timings[pio][0] << 12) | (timings[pio][1] << 8);
110 } 106 }
111 pci_write_config_word(dev, master_port, master_data); 107 pci_write_config_word(dev, master_port, master_data);
112 if (is_slave) 108 if (is_slave)
@@ -114,6 +110,13 @@ static void slc90e66_tune_drive (ide_drive_t *drive, u8 pio)
114 spin_unlock_irqrestore(&ide_lock, flags); 110 spin_unlock_irqrestore(&ide_lock, flags);
115} 111}
116 112
113static void slc90e66_tune_drive (ide_drive_t *drive, u8 pio)
114{
115 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
116 slc90e66_tune_pio(drive, pio);
117 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio);
118}
119
117static int slc90e66_tune_chipset (ide_drive_t *drive, u8 xferspeed) 120static int slc90e66_tune_chipset (ide_drive_t *drive, u8 xferspeed)
118{ 121{
119 ide_hwif_t *hwif = HWIF(drive); 122 ide_hwif_t *hwif = HWIF(drive);
@@ -162,8 +165,8 @@ static int slc90e66_tune_chipset (ide_drive_t *drive, u8 xferspeed)
162 pci_write_config_word(dev, 0x4a, reg4a & ~a_speed); 165 pci_write_config_word(dev, 0x4a, reg4a & ~a_speed);
163 } 166 }
164 167
165 slc90e66_tune_drive(drive, slc90e66_dma_2_pio(speed)); 168 slc90e66_tune_pio(drive, slc90e66_dma_2_pio(speed));
166 return (ide_config_drive_speed(drive, speed)); 169 return ide_config_drive_speed(drive, speed);
167} 170}
168 171
169static int slc90e66_config_drive_for_dma (ide_drive_t *drive) 172static int slc90e66_config_drive_for_dma (ide_drive_t *drive)
@@ -179,26 +182,15 @@ static int slc90e66_config_drive_for_dma (ide_drive_t *drive)
179 182
180static int slc90e66_config_drive_xfer_rate (ide_drive_t *drive) 183static int slc90e66_config_drive_xfer_rate (ide_drive_t *drive)
181{ 184{
182 ide_hwif_t *hwif = HWIF(drive);
183 struct hd_driveid *id = drive->id;
184
185 drive->init_speed = 0; 185 drive->init_speed = 0;
186 186
187 if ((id->capability & 1) && drive->autodma) { 187 if (ide_use_dma(drive) && slc90e66_config_drive_for_dma(drive))
188 188 return 0;
189 if (ide_use_dma(drive) && slc90e66_config_drive_for_dma(drive))
190 return hwif->ide_dma_on(drive);
191 189
192 goto fast_ata_pio; 190 if (ide_use_fast_pio(drive))
191 slc90e66_tune_drive(drive, 255);
193 192
194 } else if ((id->capability & 8) || (id->field_valid & 2)) { 193 return -1;
195fast_ata_pio:
196 (void) hwif->speedproc(drive, XFER_PIO_0 +
197 ide_get_best_pio_mode(drive, 255, 4, NULL));
198 return hwif->ide_dma_off_quietly(drive);
199 }
200 /* IORDY not supported */
201 return 0;
202} 194}
203 195
204static void __devinit init_hwif_slc90e66 (ide_hwif_t *hwif) 196static void __devinit init_hwif_slc90e66 (ide_hwif_t *hwif)
diff --git a/drivers/ide/pci/tc86c001.c b/drivers/ide/pci/tc86c001.c
index 2ad72bbda3..0b6d81d6ce 100644
--- a/drivers/ide/pci/tc86c001.c
+++ b/drivers/ide/pci/tc86c001.c
@@ -45,7 +45,7 @@ static int tc86c001_tune_chipset(ide_drive_t *drive, u8 speed)
45 45
46 scr &= (speed < XFER_MW_DMA_0) ? 0xf8ff : 0xff0f; 46 scr &= (speed < XFER_MW_DMA_0) ? 0xf8ff : 0xff0f;
47 scr |= mode; 47 scr |= mode;
48 hwif->OUTW(scr, scr_port); 48 outw(scr, scr_port);
49 49
50 return ide_config_drive_speed(drive, speed); 50 return ide_config_drive_speed(drive, speed);
51} 51}
@@ -89,15 +89,15 @@ static int tc86c001_timer_expiry(ide_drive_t *drive)
89 "attempting recovery...\n", drive->name); 89 "attempting recovery...\n", drive->name);
90 90
91 /* Stop DMA */ 91 /* Stop DMA */
92 hwif->OUTB(dma_cmd & ~0x01, hwif->dma_command); 92 outb(dma_cmd & ~0x01, hwif->dma_command);
93 93
94 /* Setup the dummy DMA transfer */ 94 /* Setup the dummy DMA transfer */
95 hwif->OUTW(0, sc_base + 0x0a); /* Sector Count */ 95 outw(0, sc_base + 0x0a); /* Sector Count */
96 hwif->OUTW(0, twcr_port); /* Transfer Word Count 1 or 2 */ 96 outw(0, twcr_port); /* Transfer Word Count 1 or 2 */
97 97
98 /* Start the dummy DMA transfer */ 98 /* Start the dummy DMA transfer */
99 hwif->OUTB(0x00, hwif->dma_command); /* clear R_OR_WCTR for write */ 99 outb(0x00, hwif->dma_command); /* clear R_OR_WCTR for write */
100 hwif->OUTB(0x01, hwif->dma_command); /* set START_STOPBM */ 100 outb(0x01, hwif->dma_command); /* set START_STOPBM */
101 101
102 /* 102 /*
103 * If an interrupt was pending, it should come thru shortly. 103 * If an interrupt was pending, it should come thru shortly.
@@ -128,8 +128,8 @@ static void tc86c001_dma_start(ide_drive_t *drive)
128 * the appropriate system control registers for DMA to work 128 * the appropriate system control registers for DMA to work
129 * with LBA48 and ATAPI devices... 129 * with LBA48 and ATAPI devices...
130 */ 130 */
131 hwif->OUTW(nsectors, sc_base + 0x0a); /* Sector Count */ 131 outw(nsectors, sc_base + 0x0a); /* Sector Count */
132 hwif->OUTW(SECTOR_SIZE / 2, twcr_port); /* Transfer Word Count 1/2 */ 132 outw(SECTOR_SIZE / 2, twcr_port); /* Transfer Word Count 1/2 */
133 133
134 /* Install our timeout expiry hook, saving the current handler... */ 134 /* Install our timeout expiry hook, saving the current handler... */
135 ide_set_hwifdata(hwif, hwgroup->expiry); 135 ide_set_hwifdata(hwif, hwgroup->expiry);
@@ -168,7 +168,7 @@ static int tc86c001_busproc(ide_drive_t *drive, int state)
168 } 168 }
169 169
170 /* System Control 1 Register bit 11 (ATA Hard Reset) write */ 170 /* System Control 1 Register bit 11 (ATA Hard Reset) write */
171 hwif->OUTW(scr1, sc_base + 0x00); 171 outw(scr1, sc_base + 0x00);
172 return 0; 172 return 0;
173} 173}
174 174
@@ -185,23 +185,13 @@ static int config_chipset_for_dma(ide_drive_t *drive)
185 185
186static int tc86c001_config_drive_xfer_rate(ide_drive_t *drive) 186static int tc86c001_config_drive_xfer_rate(ide_drive_t *drive)
187{ 187{
188 ide_hwif_t *hwif = HWIF(drive); 188 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
189 struct hd_driveid *id = drive->id; 189 return 0;
190
191 if ((id->capability & 1) && drive->autodma) {
192
193 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
194 return hwif->ide_dma_on(drive);
195
196 goto fast_ata_pio;
197 190
198 } else if ((id->capability & 8) || (id->field_valid & 2)) { 191 if (ide_use_fast_pio(drive))
199fast_ata_pio:
200 tc86c001_tune_drive(drive, 255); 192 tc86c001_tune_drive(drive, 255);
201 return hwif->ide_dma_off_quietly(drive); 193
202 } 194 return -1;
203 /* IORDY not supported */
204 return 0;
205} 195}
206 196
207static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif) 197static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif)
@@ -210,13 +200,13 @@ static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif)
210 u16 scr1 = hwif->INW(sc_base + 0x00);; 200 u16 scr1 = hwif->INW(sc_base + 0x00);;
211 201
212 /* System Control 1 Register bit 15 (Soft Reset) set */ 202 /* System Control 1 Register bit 15 (Soft Reset) set */
213 hwif->OUTW(scr1 | 0x8000, sc_base + 0x00); 203 outw(scr1 | 0x8000, sc_base + 0x00);
214 204
215 /* System Control 1 Register bit 14 (FIFO Reset) set */ 205 /* System Control 1 Register bit 14 (FIFO Reset) set */
216 hwif->OUTW(scr1 | 0x4000, sc_base + 0x00); 206 outw(scr1 | 0x4000, sc_base + 0x00);
217 207
218 /* System Control 1 Register: reset clear */ 208 /* System Control 1 Register: reset clear */
219 hwif->OUTW(scr1 & ~0xc000, sc_base + 0x00); 209 outw(scr1 & ~0xc000, sc_base + 0x00);
220 210
221 /* Store the system control register base for convenience... */ 211 /* Store the system control register base for convenience... */
222 hwif->config_data = sc_base; 212 hwif->config_data = sc_base;
@@ -234,7 +224,7 @@ static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif)
234 * Sector Count Control Register bits 0 and 1 set: 224 * Sector Count Control Register bits 0 and 1 set:
235 * software sets Sector Count Register for master and slave device 225 * software sets Sector Count Register for master and slave device
236 */ 226 */
237 hwif->OUTW(0x0003, sc_base + 0x0c); 227 outw(0x0003, sc_base + 0x0c);
238 228
239 /* Sector Count Register limit */ 229 /* Sector Count Register limit */
240 hwif->rqsize = 0xffff; 230 hwif->rqsize = 0xffff;
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/pci/triflex.c
index b13cce1fd1..5e06179c34 100644
--- a/drivers/ide/pci/triflex.c
+++ b/drivers/ide/pci/triflex.c
@@ -104,29 +104,21 @@ static int triflex_config_drive_for_dma(ide_drive_t *drive)
104{ 104{
105 int speed = ide_dma_speed(drive, 0); /* No ultra speeds */ 105 int speed = ide_dma_speed(drive, 0); /* No ultra speeds */
106 106
107 if (!speed) { 107 if (!speed)
108 u8 pspeed = ide_get_best_pio_mode(drive, 255, 4, NULL); 108 return 0;
109 speed = XFER_PIO_0 + pspeed; 109
110 }
111
112 (void) triflex_tune_chipset(drive, speed); 110 (void) triflex_tune_chipset(drive, speed);
113 return ide_dma_enable(drive); 111 return ide_dma_enable(drive);
114} 112}
115 113
116static int triflex_config_drive_xfer_rate(ide_drive_t *drive) 114static int triflex_config_drive_xfer_rate(ide_drive_t *drive)
117{ 115{
118 ide_hwif_t *hwif = HWIF(drive); 116 if (ide_use_dma(drive) && triflex_config_drive_for_dma(drive))
119 struct hd_driveid *id = drive->id; 117 return 0;
120 118
121 if ((id->capability & 1) && drive->autodma) { 119 triflex_tune_drive(drive, 255);
122 if (ide_use_dma(drive)) {
123 if (triflex_config_drive_for_dma(drive))
124 return hwif->ide_dma_on(drive);
125 }
126 }
127 120
128 hwif->tuneproc(drive, 255); 121 return -1;
129 return hwif->ide_dma_off_quietly(drive);
130} 122}
131 123
132static void __devinit init_hwif_triflex(ide_hwif_t *hwif) 124static void __devinit init_hwif_triflex(ide_hwif_t *hwif)
diff --git a/drivers/ide/pci/trm290.c b/drivers/ide/pci/trm290.c
index 174b88c478..cbb1b11119 100644
--- a/drivers/ide/pci/trm290.c
+++ b/drivers/ide/pci/trm290.c
@@ -157,16 +157,16 @@ static void trm290_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
157 if (reg != hwif->select_data) { 157 if (reg != hwif->select_data) {
158 hwif->select_data = reg; 158 hwif->select_data = reg;
159 /* set PIO/DMA */ 159 /* set PIO/DMA */
160 hwif->OUTB(0x51|(hwif->channel<<3), hwif->config_data+1); 160 outb(0x51 | (hwif->channel << 3), hwif->config_data + 1);
161 hwif->OUTW(reg & 0xff, hwif->config_data); 161 outw(reg & 0xff, hwif->config_data);
162 } 162 }
163 163
164 /* enable IRQ if not probing */ 164 /* enable IRQ if not probing */
165 if (drive->present) { 165 if (drive->present) {
166 reg = hwif->INW(hwif->config_data + 3); 166 reg = inw(hwif->config_data + 3);
167 reg &= 0x13; 167 reg &= 0x13;
168 reg &= ~(1 << hwif->channel); 168 reg &= ~(1 << hwif->channel);
169 hwif->OUTW(reg, hwif->config_data+3); 169 outw(reg, hwif->config_data + 3);
170 } 170 }
171 171
172 local_irq_restore(flags); 172 local_irq_restore(flags);
@@ -177,15 +177,12 @@ static void trm290_selectproc (ide_drive_t *drive)
177 trm290_prepare_drive(drive, drive->using_dma); 177 trm290_prepare_drive(drive, drive->using_dma);
178} 178}
179 179
180#ifdef CONFIG_BLK_DEV_IDEDMA
181static void trm290_ide_dma_exec_cmd(ide_drive_t *drive, u8 command) 180static void trm290_ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
182{ 181{
183 ide_hwif_t *hwif = HWIF(drive);
184
185 BUG_ON(HWGROUP(drive)->handler != NULL); /* paranoia check */ 182 BUG_ON(HWGROUP(drive)->handler != NULL); /* paranoia check */
186 ide_set_handler(drive, &ide_dma_intr, WAIT_CMD, NULL); 183 ide_set_handler(drive, &ide_dma_intr, WAIT_CMD, NULL);
187 /* issue cmd to drive */ 184 /* issue cmd to drive */
188 hwif->OUTB(command, IDE_COMMAND_REG); 185 outb(command, IDE_COMMAND_REG);
189} 186}
190 187
191static int trm290_ide_dma_setup(ide_drive_t *drive) 188static int trm290_ide_dma_setup(ide_drive_t *drive)
@@ -211,10 +208,10 @@ static int trm290_ide_dma_setup(ide_drive_t *drive)
211 } 208 }
212 /* select DMA xfer */ 209 /* select DMA xfer */
213 trm290_prepare_drive(drive, 1); 210 trm290_prepare_drive(drive, 1);
214 hwif->OUTL(hwif->dmatable_dma|rw, hwif->dma_command); 211 outl(hwif->dmatable_dma | rw, hwif->dma_command);
215 drive->waiting_for_dma = 1; 212 drive->waiting_for_dma = 1;
216 /* start DMA */ 213 /* start DMA */
217 hwif->OUTW((count * 2) - 1, hwif->dma_status); 214 outw((count * 2) - 1, hwif->dma_status);
218 return 0; 215 return 0;
219} 216}
220 217
@@ -230,7 +227,7 @@ static int trm290_ide_dma_end (ide_drive_t *drive)
230 drive->waiting_for_dma = 0; 227 drive->waiting_for_dma = 0;
231 /* purge DMA mappings */ 228 /* purge DMA mappings */
232 ide_destroy_dmatable(drive); 229 ide_destroy_dmatable(drive);
233 status = hwif->INW(hwif->dma_status); 230 status = inw(hwif->dma_status);
234 return (status != 0x00ff); 231 return (status != 0x00ff);
235} 232}
236 233
@@ -239,10 +236,9 @@ static int trm290_ide_dma_test_irq (ide_drive_t *drive)
239 ide_hwif_t *hwif = HWIF(drive); 236 ide_hwif_t *hwif = HWIF(drive);
240 u16 status = 0; 237 u16 status = 0;
241 238
242 status = hwif->INW(hwif->dma_status); 239 status = inw(hwif->dma_status);
243 return (status == 0x00ff); 240 return (status == 0x00ff);
244} 241}
245#endif /* CONFIG_BLK_DEV_IDEDMA */
246 242
247/* 243/*
248 * Invoked from ide-dma.c at boot time. 244 * Invoked from ide-dma.c at boot time.
@@ -269,15 +265,15 @@ static void __devinit init_hwif_trm290(ide_hwif_t *hwif)
269 265
270 local_irq_save(flags); 266 local_irq_save(flags);
271 /* put config reg into first byte of hwif->select_data */ 267 /* put config reg into first byte of hwif->select_data */
272 hwif->OUTB(0x51|(hwif->channel<<3), hwif->config_data+1); 268 outb(0x51 | (hwif->channel << 3), hwif->config_data + 1);
273 /* select PIO as default */ 269 /* select PIO as default */
274 hwif->select_data = 0x21; 270 hwif->select_data = 0x21;
275 hwif->OUTB(hwif->select_data, hwif->config_data); 271 outb(hwif->select_data, hwif->config_data);
276 /* get IRQ info */ 272 /* get IRQ info */
277 reg = hwif->INB(hwif->config_data+3); 273 reg = inb(hwif->config_data + 3);
278 /* mask IRQs for both ports */ 274 /* mask IRQs for both ports */
279 reg = (reg & 0x10) | 0x03; 275 reg = (reg & 0x10) | 0x03;
280 hwif->OUTB(reg, hwif->config_data+3); 276 outb(reg, hwif->config_data + 3);
281 local_irq_restore(flags); 277 local_irq_restore(flags);
282 278
283 if ((reg & 0x10)) 279 if ((reg & 0x10))
@@ -289,13 +285,11 @@ static void __devinit init_hwif_trm290(ide_hwif_t *hwif)
289 285
290 ide_setup_dma(hwif, (hwif->config_data + 4) ^ (hwif->channel ? 0x0080 : 0x0000), 3); 286 ide_setup_dma(hwif, (hwif->config_data + 4) ^ (hwif->channel ? 0x0080 : 0x0000), 3);
291 287
292#ifdef CONFIG_BLK_DEV_IDEDMA
293 hwif->dma_setup = &trm290_ide_dma_setup; 288 hwif->dma_setup = &trm290_ide_dma_setup;
294 hwif->dma_exec_cmd = &trm290_ide_dma_exec_cmd; 289 hwif->dma_exec_cmd = &trm290_ide_dma_exec_cmd;
295 hwif->dma_start = &trm290_ide_dma_start; 290 hwif->dma_start = &trm290_ide_dma_start;
296 hwif->ide_dma_end = &trm290_ide_dma_end; 291 hwif->ide_dma_end = &trm290_ide_dma_end;
297 hwif->ide_dma_test_irq = &trm290_ide_dma_test_irq; 292 hwif->ide_dma_test_irq = &trm290_ide_dma_test_irq;
298#endif /* CONFIG_BLK_DEV_IDEDMA */
299 293
300 hwif->selectproc = &trm290_selectproc; 294 hwif->selectproc = &trm290_selectproc;
301 hwif->autodma = 0; /* play it safe for now */ 295 hwif->autodma = 0; /* play it safe for now */
@@ -312,16 +306,16 @@ static void __devinit init_hwif_trm290(ide_hwif_t *hwif)
312 static u16 next_offset = 0; 306 static u16 next_offset = 0;
313 u8 old_mask; 307 u8 old_mask;
314 308
315 hwif->OUTB(0x54|(hwif->channel<<3), hwif->config_data+1); 309 outb(0x54 | (hwif->channel << 3), hwif->config_data + 1);
316 old = hwif->INW(hwif->config_data); 310 old = inw(hwif->config_data);
317 old &= ~1; 311 old &= ~1;
318 old_mask = hwif->INB(old+2); 312 old_mask = inb(old + 2);
319 if (old != compat && old_mask == 0xff) { 313 if (old != compat && old_mask == 0xff) {
320 /* leave lower 10 bits untouched */ 314 /* leave lower 10 bits untouched */
321 compat += (next_offset += 0x400); 315 compat += (next_offset += 0x400);
322 hwif->io_ports[IDE_CONTROL_OFFSET] = compat + 2; 316 hwif->io_ports[IDE_CONTROL_OFFSET] = compat + 2;
323 hwif->OUTW(compat|1, hwif->config_data); 317 outw(compat | 1, hwif->config_data);
324 new = hwif->INW(hwif->config_data); 318 new = inw(hwif->config_data);
325 printk(KERN_INFO "%s: control basereg workaround: " 319 printk(KERN_INFO "%s: control basereg workaround: "
326 "old=0x%04x, new=0x%04x\n", 320 "old=0x%04x, new=0x%04x\n",
327 hwif->name, old, new & ~1); 321 hwif->name, old, new & ~1);
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index 6fb6e50b82..a508550c40 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -240,8 +240,9 @@ static int via82cxxx_ide_dma_check (ide_drive_t *drive)
240 via_set_drive(drive, speed); 240 via_set_drive(drive, speed);
241 241
242 if (drive->autodma && (speed & XFER_MODE) != XFER_PIO) 242 if (drive->autodma && (speed & XFER_MODE) != XFER_PIO)
243 return hwif->ide_dma_on(drive); 243 return 0;
244 return hwif->ide_dma_off_quietly(drive); 244
245 return -1;
245} 246}
246 247
247static struct via_isa_bridge *via_config_find(struct pci_dev **isa) 248static struct via_isa_bridge *via_config_find(struct pci_dev **isa)
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index d8ea23710b..071a030ec2 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -48,7 +48,7 @@
48#include <asm/mediabay.h> 48#include <asm/mediabay.h>
49#endif 49#endif
50 50
51#include "ide-timing.h" 51#include "../ide-timing.h"
52 52
53#undef IDE_PMAC_DEBUG 53#undef IDE_PMAC_DEBUG
54 54
@@ -1237,7 +1237,7 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
1237 hwif->OUTBSYNC = pmac_outbsync; 1237 hwif->OUTBSYNC = pmac_outbsync;
1238 1238
1239 /* Tell common code _not_ to mess with resources */ 1239 /* Tell common code _not_ to mess with resources */
1240 hwif->mmio = 2; 1240 hwif->mmio = 1;
1241 hwif->hwif_data = pmif; 1241 hwif->hwif_data = pmif;
1242 pmac_ide_init_hwif_ports(&hwif->hw, pmif->regbase, 0, &hwif->irq); 1242 pmac_ide_init_hwif_ports(&hwif->hw, pmif->regbase, 0, &hwif->irq);
1243 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports)); 1243 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports));
@@ -1551,19 +1551,34 @@ static struct pci_driver pmac_ide_pci_driver = {
1551}; 1551};
1552MODULE_DEVICE_TABLE(pci, pmac_ide_pci_match); 1552MODULE_DEVICE_TABLE(pci, pmac_ide_pci_match);
1553 1553
1554void __init 1554int __init pmac_ide_probe(void)
1555pmac_ide_probe(void)
1556{ 1555{
1556 int error;
1557
1557 if (!machine_is(powermac)) 1558 if (!machine_is(powermac))
1558 return; 1559 return -ENODEV;
1559 1560
1560#ifdef CONFIG_BLK_DEV_IDE_PMAC_ATA100FIRST 1561#ifdef CONFIG_BLK_DEV_IDE_PMAC_ATA100FIRST
1561 pci_register_driver(&pmac_ide_pci_driver); 1562 error = pci_register_driver(&pmac_ide_pci_driver);
1562 macio_register_driver(&pmac_ide_macio_driver); 1563 if (error)
1564 goto out;
1565 error = macio_register_driver(&pmac_ide_macio_driver);
1566 if (error) {
1567 pci_unregister_driver(&pmac_ide_pci_driver);
1568 goto out;
1569 }
1563#else 1570#else
1564 macio_register_driver(&pmac_ide_macio_driver); 1571 error = macio_register_driver(&pmac_ide_macio_driver);
1565 pci_register_driver(&pmac_ide_pci_driver); 1572 if (error)
1573 goto out;
1574 error = pci_register_driver(&pmac_ide_pci_driver);
1575 if (error) {
1576 macio_unregister_driver(&pmac_ide_macio_driver);
1577 goto out;
1578 }
1566#endif 1579#endif
1580out:
1581 return error;
1567} 1582}
1568 1583
1569#ifdef CONFIG_BLK_DEV_IDEDMA_PMAC 1584#ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
@@ -1979,16 +1994,12 @@ pmac_ide_dma_test_irq (ide_drive_t *drive)
1979 return 1; 1994 return 1;
1980} 1995}
1981 1996
1982static int 1997static void pmac_ide_dma_host_off(ide_drive_t *drive)
1983pmac_ide_dma_host_off (ide_drive_t *drive)
1984{ 1998{
1985 return 0;
1986} 1999}
1987 2000
1988static int 2001static void pmac_ide_dma_host_on(ide_drive_t *drive)
1989pmac_ide_dma_host_on (ide_drive_t *drive)
1990{ 2002{
1991 return 0;
1992} 2003}
1993 2004
1994static int 2005static int
@@ -2034,7 +2045,7 @@ pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
2034 return; 2045 return;
2035 } 2046 }
2036 2047
2037 hwif->ide_dma_off_quietly = &__ide_dma_off_quietly; 2048 hwif->dma_off_quietly = &ide_dma_off_quietly;
2038 hwif->ide_dma_on = &__ide_dma_on; 2049 hwif->ide_dma_on = &__ide_dma_on;
2039 hwif->ide_dma_check = &pmac_ide_dma_check; 2050 hwif->ide_dma_check = &pmac_ide_dma_check;
2040 hwif->dma_setup = &pmac_ide_dma_setup; 2051 hwif->dma_setup = &pmac_ide_dma_setup;
@@ -2042,8 +2053,8 @@ pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
2042 hwif->dma_start = &pmac_ide_dma_start; 2053 hwif->dma_start = &pmac_ide_dma_start;
2043 hwif->ide_dma_end = &pmac_ide_dma_end; 2054 hwif->ide_dma_end = &pmac_ide_dma_end;
2044 hwif->ide_dma_test_irq = &pmac_ide_dma_test_irq; 2055 hwif->ide_dma_test_irq = &pmac_ide_dma_test_irq;
2045 hwif->ide_dma_host_off = &pmac_ide_dma_host_off; 2056 hwif->dma_host_off = &pmac_ide_dma_host_off;
2046 hwif->ide_dma_host_on = &pmac_ide_dma_host_on; 2057 hwif->dma_host_on = &pmac_ide_dma_host_on;
2047 hwif->ide_dma_timeout = &__ide_dma_timeout; 2058 hwif->ide_dma_timeout = &__ide_dma_timeout;
2048 hwif->ide_dma_lostirq = &pmac_ide_dma_lostirq; 2059 hwif->ide_dma_lostirq = &pmac_ide_dma_lostirq;
2049 2060
diff --git a/drivers/ide/ppc/scc_pata.c b/drivers/ide/ppc/scc_pata.c
new file mode 100644
index 0000000000..f84bf791f7
--- /dev/null
+++ b/drivers/ide/ppc/scc_pata.c
@@ -0,0 +1,858 @@
1/*
2 * Support for IDE interfaces on Celleb platform
3 *
4 * (C) Copyright 2006 TOSHIBA CORPORATION
5 *
6 * This code is based on drivers/ide/pci/siimage.c:
7 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
8 * Copyright (C) 2003 Red Hat <alan@redhat.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
24
25#include <linux/types.h>
26#include <linux/module.h>
27#include <linux/pci.h>
28#include <linux/delay.h>
29#include <linux/hdreg.h>
30#include <linux/ide.h>
31#include <linux/init.h>
32
33#define PCI_DEVICE_ID_TOSHIBA_SCC_ATA 0x01b4
34
35#define SCC_PATA_NAME "scc IDE"
36
37#define TDVHSEL_MASTER 0x00000001
38#define TDVHSEL_SLAVE 0x00000004
39
40#define MODE_JCUSFEN 0x00000080
41
42#define CCKCTRL_ATARESET 0x00040000
43#define CCKCTRL_BUFCNT 0x00020000
44#define CCKCTRL_CRST 0x00010000
45#define CCKCTRL_OCLKEN 0x00000100
46#define CCKCTRL_ATACLKOEN 0x00000002
47#define CCKCTRL_LCLKEN 0x00000001
48
49#define QCHCD_IOS_SS 0x00000001
50
51#define QCHSD_STPDIAG 0x00020000
52
53#define INTMASK_MSK 0xD1000012
54#define INTSTS_SERROR 0x80000000
55#define INTSTS_PRERR 0x40000000
56#define INTSTS_RERR 0x10000000
57#define INTSTS_ICERR 0x01000000
58#define INTSTS_BMSINT 0x00000010
59#define INTSTS_BMHE 0x00000008
60#define INTSTS_IOIRQS 0x00000004
61#define INTSTS_INTRQ 0x00000002
62#define INTSTS_ACTEINT 0x00000001
63
64#define ECMODE_VALUE 0x01
65
66static struct scc_ports {
67 unsigned long ctl, dma;
68 unsigned char hwif_id; /* for removing hwif from system */
69} scc_ports[MAX_HWIFS];
70
71/* PIO transfer mode table */
72/* JCHST */
73static unsigned long JCHSTtbl[2][7] = {
74 {0x0E, 0x05, 0x02, 0x03, 0x02, 0x00, 0x00}, /* 100MHz */
75 {0x13, 0x07, 0x04, 0x04, 0x03, 0x00, 0x00} /* 133MHz */
76};
77
78/* JCHHT */
79static unsigned long JCHHTtbl[2][7] = {
80 {0x0E, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00}, /* 100MHz */
81 {0x13, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00} /* 133MHz */
82};
83
84/* JCHCT */
85static unsigned long JCHCTtbl[2][7] = {
86 {0x1D, 0x1D, 0x1C, 0x0B, 0x06, 0x00, 0x00}, /* 100MHz */
87 {0x27, 0x26, 0x26, 0x0E, 0x09, 0x00, 0x00} /* 133MHz */
88};
89
90
91/* DMA transfer mode table */
92/* JCHDCTM/JCHDCTS */
93static unsigned long JCHDCTxtbl[2][7] = {
94 {0x0A, 0x06, 0x04, 0x03, 0x01, 0x00, 0x00}, /* 100MHz */
95 {0x0E, 0x09, 0x06, 0x04, 0x02, 0x01, 0x00} /* 133MHz */
96};
97
98/* JCSTWTM/JCSTWTS */
99static unsigned long JCSTWTxtbl[2][7] = {
100 {0x06, 0x04, 0x03, 0x02, 0x02, 0x02, 0x00}, /* 100MHz */
101 {0x09, 0x06, 0x04, 0x02, 0x02, 0x02, 0x02} /* 133MHz */
102};
103
104/* JCTSS */
105static unsigned long JCTSStbl[2][7] = {
106 {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00}, /* 100MHz */
107 {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05} /* 133MHz */
108};
109
110/* JCENVT */
111static unsigned long JCENVTtbl[2][7] = {
112 {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00}, /* 100MHz */
113 {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02} /* 133MHz */
114};
115
116/* JCACTSELS/JCACTSELM */
117static unsigned long JCACTSELtbl[2][7] = {
118 {0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00}, /* 100MHz */
119 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} /* 133MHz */
120};
121
122
123static u8 scc_ide_inb(unsigned long port)
124{
125 u32 data = in_be32((void*)port);
126 return (u8)data;
127}
128
129static u16 scc_ide_inw(unsigned long port)
130{
131 u32 data = in_be32((void*)port);
132 return (u16)data;
133}
134
135static void scc_ide_insw(unsigned long port, void *addr, u32 count)
136{
137 u16 *ptr = (u16 *)addr;
138 while (count--) {
139 *ptr++ = le16_to_cpu(in_be32((void*)port));
140 }
141}
142
143static void scc_ide_insl(unsigned long port, void *addr, u32 count)
144{
145 u16 *ptr = (u16 *)addr;
146 while (count--) {
147 *ptr++ = le16_to_cpu(in_be32((void*)port));
148 *ptr++ = le16_to_cpu(in_be32((void*)port));
149 }
150}
151
152static void scc_ide_outb(u8 addr, unsigned long port)
153{
154 out_be32((void*)port, addr);
155}
156
157static void scc_ide_outw(u16 addr, unsigned long port)
158{
159 out_be32((void*)port, addr);
160}
161
162static void
163scc_ide_outbsync(ide_drive_t * drive, u8 addr, unsigned long port)
164{
165 ide_hwif_t *hwif = HWIF(drive);
166
167 out_be32((void*)port, addr);
168 __asm__ __volatile__("eieio":::"memory");
169 in_be32((void*)(hwif->dma_base + 0x01c));
170 __asm__ __volatile__("eieio":::"memory");
171}
172
173static void
174scc_ide_outsw(unsigned long port, void *addr, u32 count)
175{
176 u16 *ptr = (u16 *)addr;
177 while (count--) {
178 out_be32((void*)port, cpu_to_le16(*ptr++));
179 }
180}
181
182static void
183scc_ide_outsl(unsigned long port, void *addr, u32 count)
184{
185 u16 *ptr = (u16 *)addr;
186 while (count--) {
187 out_be32((void*)port, cpu_to_le16(*ptr++));
188 out_be32((void*)port, cpu_to_le16(*ptr++));
189 }
190}
191
192/**
193 * scc_ratemask - Compute available modes
194 * @drive: IDE drive
195 *
196 * Compute the available speeds for the devices on the interface.
197 * Enforce UDMA33 as a limit if there is no 80pin cable present.
198 */
199
200static u8 scc_ratemask(ide_drive_t *drive)
201{
202 u8 mode = 4;
203
204 if (!eighty_ninty_three(drive))
205 mode = min(mode, (u8)1);
206 return mode;
207}
208
209/**
210 * scc_tuneproc - tune a drive PIO mode
211 * @drive: drive to tune
212 * @mode_wanted: the target operating mode
213 *
214 * Load the timing settings for this device mode into the
215 * controller.
216 */
217
218static void scc_tuneproc(ide_drive_t *drive, byte mode_wanted)
219{
220 ide_hwif_t *hwif = HWIF(drive);
221 struct scc_ports *ports = ide_get_hwifdata(hwif);
222 unsigned long ctl_base = ports->ctl;
223 unsigned long cckctrl_port = ctl_base + 0xff0;
224 unsigned long piosht_port = ctl_base + 0x000;
225 unsigned long pioct_port = ctl_base + 0x004;
226 unsigned long reg;
227 unsigned char speed = XFER_PIO_0;
228 int offset;
229
230 mode_wanted = ide_get_best_pio_mode(drive, mode_wanted, 4, NULL);
231 switch (mode_wanted) {
232 case 4:
233 speed = XFER_PIO_4;
234 break;
235 case 3:
236 speed = XFER_PIO_3;
237 break;
238 case 2:
239 speed = XFER_PIO_2;
240 break;
241 case 1:
242 speed = XFER_PIO_1;
243 break;
244 case 0:
245 default:
246 speed = XFER_PIO_0;
247 break;
248 }
249
250 reg = in_be32((void __iomem *)cckctrl_port);
251 if (reg & CCKCTRL_ATACLKOEN) {
252 offset = 1; /* 133MHz */
253 } else {
254 offset = 0; /* 100MHz */
255 }
256 reg = JCHSTtbl[offset][mode_wanted] << 16 | JCHHTtbl[offset][mode_wanted];
257 out_be32((void __iomem *)piosht_port, reg);
258 reg = JCHCTtbl[offset][mode_wanted];
259 out_be32((void __iomem *)pioct_port, reg);
260
261 ide_config_drive_speed(drive, speed);
262}
263
264/**
265 * scc_tune_chipset - tune a drive DMA mode
266 * @drive: Drive to set up
267 * @xferspeed: speed we want to achieve
268 *
269 * Load the timing settings for this device mode into the
270 * controller.
271 */
272
273static int scc_tune_chipset(ide_drive_t *drive, byte xferspeed)
274{
275 ide_hwif_t *hwif = HWIF(drive);
276 u8 speed = ide_rate_filter(scc_ratemask(drive), xferspeed);
277 struct scc_ports *ports = ide_get_hwifdata(hwif);
278 unsigned long ctl_base = ports->ctl;
279 unsigned long cckctrl_port = ctl_base + 0xff0;
280 unsigned long mdmact_port = ctl_base + 0x008;
281 unsigned long mcrcst_port = ctl_base + 0x00c;
282 unsigned long sdmact_port = ctl_base + 0x010;
283 unsigned long scrcst_port = ctl_base + 0x014;
284 unsigned long udenvt_port = ctl_base + 0x018;
285 unsigned long tdvhsel_port = ctl_base + 0x020;
286 int is_slave = (&hwif->drives[1] == drive);
287 int offset, idx;
288 unsigned long reg;
289 unsigned long jcactsel;
290
291 reg = in_be32((void __iomem *)cckctrl_port);
292 if (reg & CCKCTRL_ATACLKOEN) {
293 offset = 1; /* 133MHz */
294 } else {
295 offset = 0; /* 100MHz */
296 }
297
298 switch (speed) {
299 case XFER_UDMA_6:
300 idx = 6;
301 break;
302 case XFER_UDMA_5:
303 idx = 5;
304 break;
305 case XFER_UDMA_4:
306 idx = 4;
307 break;
308 case XFER_UDMA_3:
309 idx = 3;
310 break;
311 case XFER_UDMA_2:
312 idx = 2;
313 break;
314 case XFER_UDMA_1:
315 idx = 1;
316 break;
317 case XFER_UDMA_0:
318 idx = 0;
319 break;
320 default:
321 return 1;
322 }
323
324 jcactsel = JCACTSELtbl[offset][idx];
325 if (is_slave) {
326 out_be32((void __iomem *)sdmact_port, JCHDCTxtbl[offset][idx]);
327 out_be32((void __iomem *)scrcst_port, JCSTWTxtbl[offset][idx]);
328 jcactsel = jcactsel << 2;
329 out_be32((void __iomem *)tdvhsel_port, (in_be32((void __iomem *)tdvhsel_port) & ~TDVHSEL_SLAVE) | jcactsel);
330 } else {
331 out_be32((void __iomem *)mdmact_port, JCHDCTxtbl[offset][idx]);
332 out_be32((void __iomem *)mcrcst_port, JCSTWTxtbl[offset][idx]);
333 out_be32((void __iomem *)tdvhsel_port, (in_be32((void __iomem *)tdvhsel_port) & ~TDVHSEL_MASTER) | jcactsel);
334 }
335 reg = JCTSStbl[offset][idx] << 16 | JCENVTtbl[offset][idx];
336 out_be32((void __iomem *)udenvt_port, reg);
337
338 return ide_config_drive_speed(drive, speed);
339}
340
341/**
342 * scc_config_chipset_for_dma - configure for DMA
343 * @drive: drive to configure
344 *
345 * Called by scc_config_drive_for_dma().
346 */
347
348static int scc_config_chipset_for_dma(ide_drive_t *drive)
349{
350 u8 speed = ide_dma_speed(drive, scc_ratemask(drive));
351
352 if (!speed)
353 return 0;
354
355 if (scc_tune_chipset(drive, speed))
356 return 0;
357
358 return ide_dma_enable(drive);
359}
360
361/**
362 * scc_configure_drive_for_dma - set up for DMA transfers
363 * @drive: drive we are going to set up
364 *
365 * Set up the drive for DMA, tune the controller and drive as
366 * required.
367 * If the drive isn't suitable for DMA or we hit other problems
368 * then we will drop down to PIO and set up PIO appropriately.
369 * (return 1)
370 */
371
372static int scc_config_drive_for_dma(ide_drive_t *drive)
373{
374 if (ide_use_dma(drive) && scc_config_chipset_for_dma(drive))
375 return 0;
376
377 if (ide_use_fast_pio(drive))
378 scc_tuneproc(drive, 4);
379
380 return -1;
381}
382
383/**
384 * scc_ide_dma_setup - begin a DMA phase
385 * @drive: target device
386 *
387 * Build an IDE DMA PRD (IDE speak for scatter gather table)
388 * and then set up the DMA transfer registers.
389 *
390 * Returns 0 on success. If a PIO fallback is required then 1
391 * is returned.
392 */
393
394static int scc_dma_setup(ide_drive_t *drive)
395{
396 ide_hwif_t *hwif = drive->hwif;
397 struct request *rq = HWGROUP(drive)->rq;
398 unsigned int reading;
399 u8 dma_stat;
400
401 if (rq_data_dir(rq))
402 reading = 0;
403 else
404 reading = 1 << 3;
405
406 /* fall back to pio! */
407 if (!ide_build_dmatable(drive, rq)) {
408 ide_map_sg(drive, rq);
409 return 1;
410 }
411
412 /* PRD table */
413 out_be32((void __iomem *)hwif->dma_prdtable, hwif->dmatable_dma);
414
415 /* specify r/w */
416 out_be32((void __iomem *)hwif->dma_command, reading);
417
418 /* read dma_status for INTR & ERROR flags */
419 dma_stat = in_be32((void __iomem *)hwif->dma_status);
420
421 /* clear INTR & ERROR flags */
422 out_be32((void __iomem *)hwif->dma_status, dma_stat|6);
423 drive->waiting_for_dma = 1;
424 return 0;
425}
426
427
428/**
429 * scc_ide_dma_end - Stop DMA
430 * @drive: IDE drive
431 *
432 * Check and clear INT Status register.
433 * Then call __ide_dma_end().
434 */
435
436static int scc_ide_dma_end(ide_drive_t * drive)
437{
438 ide_hwif_t *hwif = HWIF(drive);
439 unsigned long intsts_port = hwif->dma_base + 0x014;
440 u32 reg;
441
442 while (1) {
443 reg = in_be32((void __iomem *)intsts_port);
444
445 if (reg & INTSTS_SERROR) {
446 printk(KERN_WARNING "%s: SERROR\n", SCC_PATA_NAME);
447 out_be32((void __iomem *)intsts_port, INTSTS_SERROR|INTSTS_BMSINT);
448
449 out_be32((void __iomem *)hwif->dma_command, in_be32((void __iomem *)hwif->dma_command) & ~QCHCD_IOS_SS);
450 continue;
451 }
452
453 if (reg & INTSTS_PRERR) {
454 u32 maea0, maec0;
455 unsigned long ctl_base = hwif->config_data;
456
457 maea0 = in_be32((void __iomem *)(ctl_base + 0xF50));
458 maec0 = in_be32((void __iomem *)(ctl_base + 0xF54));
459
460 printk(KERN_WARNING "%s: PRERR [addr:%x cmd:%x]\n", SCC_PATA_NAME, maea0, maec0);
461
462 out_be32((void __iomem *)intsts_port, INTSTS_PRERR|INTSTS_BMSINT);
463
464 out_be32((void __iomem *)hwif->dma_command, in_be32((void __iomem *)hwif->dma_command) & ~QCHCD_IOS_SS);
465 continue;
466 }
467
468 if (reg & INTSTS_RERR) {
469 printk(KERN_WARNING "%s: Response Error\n", SCC_PATA_NAME);
470 out_be32((void __iomem *)intsts_port, INTSTS_RERR|INTSTS_BMSINT);
471
472 out_be32((void __iomem *)hwif->dma_command, in_be32((void __iomem *)hwif->dma_command) & ~QCHCD_IOS_SS);
473 continue;
474 }
475
476 if (reg & INTSTS_ICERR) {
477 out_be32((void __iomem *)hwif->dma_command, in_be32((void __iomem *)hwif->dma_command) & ~QCHCD_IOS_SS);
478
479 printk(KERN_WARNING "%s: Illegal Configuration\n", SCC_PATA_NAME);
480 out_be32((void __iomem *)intsts_port, INTSTS_ICERR|INTSTS_BMSINT);
481 continue;
482 }
483
484 if (reg & INTSTS_BMSINT) {
485 printk(KERN_WARNING "%s: Internal Bus Error\n", SCC_PATA_NAME);
486 out_be32((void __iomem *)intsts_port, INTSTS_BMSINT);
487
488 ide_do_reset(drive);
489 continue;
490 }
491
492 if (reg & INTSTS_BMHE) {
493 out_be32((void __iomem *)intsts_port, INTSTS_BMHE);
494 continue;
495 }
496
497 if (reg & INTSTS_ACTEINT) {
498 out_be32((void __iomem *)intsts_port, INTSTS_ACTEINT);
499 continue;
500 }
501
502 if (reg & INTSTS_IOIRQS) {
503 out_be32((void __iomem *)intsts_port, INTSTS_IOIRQS);
504 continue;
505 }
506 break;
507 }
508
509 return __ide_dma_end(drive);
510}
511
512/* returns 1 if dma irq issued, 0 otherwise */
513static int scc_dma_test_irq(ide_drive_t *drive)
514{
515 ide_hwif_t *hwif = HWIF(drive);
516 u8 dma_stat = hwif->INB(hwif->dma_status);
517
518 /* return 1 if INTR asserted */
519 if ((dma_stat & 4) == 4)
520 return 1;
521
522 /* Workaround for PTERADD: emulate DMA_INTR when
523 * - IDE_STATUS[ERR] = 1
524 * - INT_STATUS[INTRQ] = 1
525 * - DMA_STATUS[IORACTA] = 1
526 */
527 if (in_be32((void __iomem *)IDE_ALTSTATUS_REG) & ERR_STAT &&
528 in_be32((void __iomem *)(hwif->dma_base + 0x014)) & INTSTS_INTRQ &&
529 dma_stat & 1)
530 return 1;
531
532 if (!drive->waiting_for_dma)
533 printk(KERN_WARNING "%s: (%s) called while not waiting\n",
534 drive->name, __FUNCTION__);
535 return 0;
536}
537
538/**
539 * setup_mmio_scc - map CTRL/BMID region
540 * @dev: PCI device we are configuring
541 * @name: device name
542 *
543 */
544
545static int setup_mmio_scc (struct pci_dev *dev, const char *name)
546{
547 unsigned long ctl_base = pci_resource_start(dev, 0);
548 unsigned long dma_base = pci_resource_start(dev, 1);
549 unsigned long ctl_size = pci_resource_len(dev, 0);
550 unsigned long dma_size = pci_resource_len(dev, 1);
551 void *ctl_addr;
552 void *dma_addr;
553 int i;
554
555 for (i = 0; i < MAX_HWIFS; i++) {
556 if (scc_ports[i].ctl == 0)
557 break;
558 }
559 if (i >= MAX_HWIFS)
560 return -ENOMEM;
561
562 if (!request_mem_region(ctl_base, ctl_size, name)) {
563 printk(KERN_WARNING "%s: IDE controller MMIO ports not available.\n", SCC_PATA_NAME);
564 goto fail_0;
565 }
566
567 if (!request_mem_region(dma_base, dma_size, name)) {
568 printk(KERN_WARNING "%s: IDE controller MMIO ports not available.\n", SCC_PATA_NAME);
569 goto fail_1;
570 }
571
572 if ((ctl_addr = ioremap(ctl_base, ctl_size)) == NULL)
573 goto fail_2;
574
575 if ((dma_addr = ioremap(dma_base, dma_size)) == NULL)
576 goto fail_3;
577
578 pci_set_master(dev);
579 scc_ports[i].ctl = (unsigned long)ctl_addr;
580 scc_ports[i].dma = (unsigned long)dma_addr;
581 pci_set_drvdata(dev, (void *) &scc_ports[i]);
582
583 return 1;
584
585 fail_3:
586 iounmap(ctl_addr);
587 fail_2:
588 release_mem_region(dma_base, dma_size);
589 fail_1:
590 release_mem_region(ctl_base, ctl_size);
591 fail_0:
592 return -ENOMEM;
593}
594
595/**
596 * init_setup_scc - set up an SCC PATA Controller
597 * @dev: PCI device
598 * @d: IDE PCI device
599 *
600 * Perform the initial set up for this device.
601 */
602
603static int __devinit init_setup_scc(struct pci_dev *dev, ide_pci_device_t *d)
604{
605 unsigned long ctl_base;
606 unsigned long dma_base;
607 unsigned long cckctrl_port;
608 unsigned long intmask_port;
609 unsigned long mode_port;
610 unsigned long ecmode_port;
611 unsigned long dma_status_port;
612 u32 reg = 0;
613 struct scc_ports *ports;
614 int rc;
615
616 rc = setup_mmio_scc(dev, d->name);
617 if (rc < 0) {
618 return rc;
619 }
620
621 ports = pci_get_drvdata(dev);
622 ctl_base = ports->ctl;
623 dma_base = ports->dma;
624 cckctrl_port = ctl_base + 0xff0;
625 intmask_port = dma_base + 0x010;
626 mode_port = ctl_base + 0x024;
627 ecmode_port = ctl_base + 0xf00;
628 dma_status_port = dma_base + 0x004;
629
630 /* controller initialization */
631 reg = 0;
632 out_be32((void*)cckctrl_port, reg);
633 reg |= CCKCTRL_ATACLKOEN;
634 out_be32((void*)cckctrl_port, reg);
635 reg |= CCKCTRL_LCLKEN | CCKCTRL_OCLKEN;
636 out_be32((void*)cckctrl_port, reg);
637 reg |= CCKCTRL_CRST;
638 out_be32((void*)cckctrl_port, reg);
639
640 for (;;) {
641 reg = in_be32((void*)cckctrl_port);
642 if (reg & CCKCTRL_CRST)
643 break;
644 udelay(5000);
645 }
646
647 reg |= CCKCTRL_ATARESET;
648 out_be32((void*)cckctrl_port, reg);
649
650 out_be32((void*)ecmode_port, ECMODE_VALUE);
651 out_be32((void*)mode_port, MODE_JCUSFEN);
652 out_be32((void*)intmask_port, INTMASK_MSK);
653
654 return ide_setup_pci_device(dev, d);
655}
656
657/**
658 * init_mmio_iops_scc - set up the iops for MMIO
659 * @hwif: interface to set up
660 *
661 */
662
663static void __devinit init_mmio_iops_scc(ide_hwif_t *hwif)
664{
665 struct pci_dev *dev = hwif->pci_dev;
666 struct scc_ports *ports = pci_get_drvdata(dev);
667 unsigned long dma_base = ports->dma;
668
669 ide_set_hwifdata(hwif, ports);
670
671 hwif->INB = scc_ide_inb;
672 hwif->INW = scc_ide_inw;
673 hwif->INSW = scc_ide_insw;
674 hwif->INSL = scc_ide_insl;
675 hwif->OUTB = scc_ide_outb;
676 hwif->OUTBSYNC = scc_ide_outbsync;
677 hwif->OUTW = scc_ide_outw;
678 hwif->OUTSW = scc_ide_outsw;
679 hwif->OUTSL = scc_ide_outsl;
680
681 hwif->io_ports[IDE_DATA_OFFSET] = dma_base + 0x20;
682 hwif->io_ports[IDE_ERROR_OFFSET] = dma_base + 0x24;
683 hwif->io_ports[IDE_NSECTOR_OFFSET] = dma_base + 0x28;
684 hwif->io_ports[IDE_SECTOR_OFFSET] = dma_base + 0x2c;
685 hwif->io_ports[IDE_LCYL_OFFSET] = dma_base + 0x30;
686 hwif->io_ports[IDE_HCYL_OFFSET] = dma_base + 0x34;
687 hwif->io_ports[IDE_SELECT_OFFSET] = dma_base + 0x38;
688 hwif->io_ports[IDE_STATUS_OFFSET] = dma_base + 0x3c;
689 hwif->io_ports[IDE_CONTROL_OFFSET] = dma_base + 0x40;
690
691 hwif->irq = hwif->pci_dev->irq;
692 hwif->dma_base = dma_base;
693 hwif->config_data = ports->ctl;
694 hwif->mmio = 1;
695}
696
697/**
698 * init_iops_scc - set up iops
699 * @hwif: interface to set up
700 *
701 * Do the basic setup for the SCC hardware interface
702 * and then do the MMIO setup.
703 */
704
705static void __devinit init_iops_scc(ide_hwif_t *hwif)
706{
707 struct pci_dev *dev = hwif->pci_dev;
708 hwif->hwif_data = NULL;
709 if (pci_get_drvdata(dev) == NULL)
710 return;
711 init_mmio_iops_scc(hwif);
712}
713
714/**
715 * init_hwif_scc - set up hwif
716 * @hwif: interface to set up
717 *
718 * We do the basic set up of the interface structure. The SCC
719 * requires several custom handlers so we override the default
720 * ide DMA handlers appropriately.
721 */
722
723static void __devinit init_hwif_scc(ide_hwif_t *hwif)
724{
725 struct scc_ports *ports = ide_get_hwifdata(hwif);
726
727 ports->hwif_id = hwif->index;
728
729 hwif->dma_command = hwif->dma_base;
730 hwif->dma_status = hwif->dma_base + 0x04;
731 hwif->dma_prdtable = hwif->dma_base + 0x08;
732
733 /* PTERADD */
734 out_be32((void __iomem *)(hwif->dma_base + 0x018), hwif->dmatable_dma);
735
736 hwif->dma_setup = scc_dma_setup;
737 hwif->ide_dma_end = scc_ide_dma_end;
738 hwif->speedproc = scc_tune_chipset;
739 hwif->tuneproc = scc_tuneproc;
740 hwif->ide_dma_check = scc_config_drive_for_dma;
741 hwif->ide_dma_test_irq = scc_dma_test_irq;
742
743 hwif->drives[0].autotune = IDE_TUNE_AUTO;
744 hwif->drives[1].autotune = IDE_TUNE_AUTO;
745
746 if (in_be32((void __iomem *)(hwif->config_data + 0xff0)) & CCKCTRL_ATACLKOEN) {
747 hwif->ultra_mask = 0x7f; /* 133MHz */
748 } else {
749 hwif->ultra_mask = 0x3f; /* 100MHz */
750 }
751 hwif->mwdma_mask = 0x00;
752 hwif->swdma_mask = 0x00;
753 hwif->atapi_dma = 1;
754
755 /* we support 80c cable only. */
756 hwif->udma_four = 1;
757
758 hwif->autodma = 0;
759 if (!noautodma)
760 hwif->autodma = 1;
761 hwif->drives[0].autodma = hwif->autodma;
762 hwif->drives[1].autodma = hwif->autodma;
763}
764
765#define DECLARE_SCC_DEV(name_str) \
766 { \
767 .name = name_str, \
768 .init_setup = init_setup_scc, \
769 .init_iops = init_iops_scc, \
770 .init_hwif = init_hwif_scc, \
771 .channels = 1, \
772 .autodma = AUTODMA, \
773 .bootable = ON_BOARD, \
774 }
775
776static ide_pci_device_t scc_chipsets[] __devinitdata = {
777 /* 0 */ DECLARE_SCC_DEV("sccIDE"),
778};
779
780/**
781 * scc_init_one - pci layer discovery entry
782 * @dev: PCI device
783 * @id: ident table entry
784 *
785 * Called by the PCI code when it finds an SCC PATA controller.
786 * We then use the IDE PCI generic helper to do most of the work.
787 */
788
789static int __devinit scc_init_one(struct pci_dev *dev, const struct pci_device_id *id)
790{
791 ide_pci_device_t *d = &scc_chipsets[id->driver_data];
792 return d->init_setup(dev, d);
793}
794
795/**
796 * scc_remove - pci layer remove entry
797 * @dev: PCI device
798 *
799 * Called by the PCI code when it removes an SCC PATA controller.
800 */
801
802static void __devexit scc_remove(struct pci_dev *dev)
803{
804 struct scc_ports *ports = pci_get_drvdata(dev);
805 ide_hwif_t *hwif = &ide_hwifs[ports->hwif_id];
806 unsigned long ctl_base = pci_resource_start(dev, 0);
807 unsigned long dma_base = pci_resource_start(dev, 1);
808 unsigned long ctl_size = pci_resource_len(dev, 0);
809 unsigned long dma_size = pci_resource_len(dev, 1);
810
811 if (hwif->dmatable_cpu) {
812 pci_free_consistent(hwif->pci_dev,
813 PRD_ENTRIES * PRD_BYTES,
814 hwif->dmatable_cpu,
815 hwif->dmatable_dma);
816 hwif->dmatable_cpu = NULL;
817 }
818
819 ide_unregister(hwif->index);
820
821 hwif->chipset = ide_unknown;
822 iounmap((void*)ports->dma);
823 iounmap((void*)ports->ctl);
824 release_mem_region(dma_base, dma_size);
825 release_mem_region(ctl_base, ctl_size);
826 memset(ports, 0, sizeof(*ports));
827}
828
829static struct pci_device_id scc_pci_tbl[] = {
830 { PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_SCC_ATA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
831 { 0, },
832};
833MODULE_DEVICE_TABLE(pci, scc_pci_tbl);
834
835static struct pci_driver driver = {
836 .name = "SCC IDE",
837 .id_table = scc_pci_tbl,
838 .probe = scc_init_one,
839 .remove = scc_remove,
840};
841
842static int scc_ide_init(void)
843{
844 return ide_pci_register_driver(&driver);
845}
846
847module_init(scc_ide_init);
848/* -- No exit code?
849static void scc_ide_exit(void)
850{
851 ide_pci_unregister_driver(&driver);
852}
853module_exit(scc_ide_exit);
854 */
855
856
857MODULE_DESCRIPTION("PCI driver module for Toshiba SCC IDE");
858MODULE_LICENSE("GPL");
diff --git a/drivers/ieee1394/ieee1394-ioctl.h b/drivers/ieee1394/ieee1394-ioctl.h
index 8f207508ed..46878fef13 100644
--- a/drivers/ieee1394/ieee1394-ioctl.h
+++ b/drivers/ieee1394/ieee1394-ioctl.h
@@ -100,5 +100,7 @@
100 _IO ('#', 0x28) 100 _IO ('#', 0x28)
101#define RAW1394_IOC_ISO_RECV_FLUSH \ 101#define RAW1394_IOC_ISO_RECV_FLUSH \
102 _IO ('#', 0x29) 102 _IO ('#', 0x29)
103#define RAW1394_IOC_GET_CYCLE_TIMER \
104 _IOR ('#', 0x30, struct raw1394_cycle_timer)
103 105
104#endif /* __IEEE1394_IOCTL_H */ 106#endif /* __IEEE1394_IOCTL_H */
diff --git a/drivers/ieee1394/ieee1394_core.c b/drivers/ieee1394/ieee1394_core.c
index 1521e57e12..d791d08c74 100644
--- a/drivers/ieee1394/ieee1394_core.c
+++ b/drivers/ieee1394/ieee1394_core.c
@@ -33,7 +33,10 @@
33#include <linux/skbuff.h> 33#include <linux/skbuff.h>
34#include <linux/suspend.h> 34#include <linux/suspend.h>
35#include <linux/kthread.h> 35#include <linux/kthread.h>
36#include <linux/preempt.h>
37#include <linux/time.h>
36 38
39#include <asm/system.h>
37#include <asm/byteorder.h> 40#include <asm/byteorder.h>
38 41
39#include "ieee1394_types.h" 42#include "ieee1394_types.h"
@@ -186,6 +189,45 @@ int hpsb_reset_bus(struct hpsb_host *host, int type)
186 } 189 }
187} 190}
188 191
192/**
193 * hpsb_read_cycle_timer - read cycle timer register and system time
194 * @host: host whose isochronous cycle timer register is read
195 * @cycle_timer: address of bitfield to return the register contents
196 * @local_time: address to return the system time
197 *
198 * The format of * @cycle_timer, is described in OHCI 1.1 clause 5.13. This
199 * format is also read from non-OHCI controllers. * @local_time contains the
200 * system time in microseconds since the Epoch, read at the moment when the
201 * cycle timer was read.
202 *
203 * Return value: 0 for success or error number otherwise.
204 */
205int hpsb_read_cycle_timer(struct hpsb_host *host, u32 *cycle_timer,
206 u64 *local_time)
207{
208 int ctr;
209 struct timeval tv;
210 unsigned long flags;
211
212 if (!host || !cycle_timer || !local_time)
213 return -EINVAL;
214
215 preempt_disable();
216 local_irq_save(flags);
217
218 ctr = host->driver->devctl(host, GET_CYCLE_COUNTER, 0);
219 if (ctr)
220 do_gettimeofday(&tv);
221
222 local_irq_restore(flags);
223 preempt_enable();
224
225 if (!ctr)
226 return -EIO;
227 *cycle_timer = ctr;
228 *local_time = tv.tv_sec * 1000000ULL + tv.tv_usec;
229 return 0;
230}
189 231
190int hpsb_bus_reset(struct hpsb_host *host) 232int hpsb_bus_reset(struct hpsb_host *host)
191{ 233{
@@ -1190,6 +1232,7 @@ EXPORT_SYMBOL(hpsb_alloc_packet);
1190EXPORT_SYMBOL(hpsb_free_packet); 1232EXPORT_SYMBOL(hpsb_free_packet);
1191EXPORT_SYMBOL(hpsb_send_packet); 1233EXPORT_SYMBOL(hpsb_send_packet);
1192EXPORT_SYMBOL(hpsb_reset_bus); 1234EXPORT_SYMBOL(hpsb_reset_bus);
1235EXPORT_SYMBOL(hpsb_read_cycle_timer);
1193EXPORT_SYMBOL(hpsb_bus_reset); 1236EXPORT_SYMBOL(hpsb_bus_reset);
1194EXPORT_SYMBOL(hpsb_selfid_received); 1237EXPORT_SYMBOL(hpsb_selfid_received);
1195EXPORT_SYMBOL(hpsb_selfid_complete); 1238EXPORT_SYMBOL(hpsb_selfid_complete);
diff --git a/drivers/ieee1394/ieee1394_core.h b/drivers/ieee1394/ieee1394_core.h
index 536ba3f580..bd29d8ef5b 100644
--- a/drivers/ieee1394/ieee1394_core.h
+++ b/drivers/ieee1394/ieee1394_core.h
@@ -127,6 +127,9 @@ int hpsb_send_packet_and_wait(struct hpsb_packet *packet);
127 * progress, 0 otherwise. */ 127 * progress, 0 otherwise. */
128int hpsb_reset_bus(struct hpsb_host *host, int type); 128int hpsb_reset_bus(struct hpsb_host *host, int type);
129 129
130int hpsb_read_cycle_timer(struct hpsb_host *host, u32 *cycle_timer,
131 u64 *local_time);
132
130/* 133/*
131 * The following functions are exported for host driver module usage. All of 134 * The following functions are exported for host driver module usage. All of
132 * them are safe to use in interrupt contexts, although some are quite 135 * them are safe to use in interrupt contexts, although some are quite
diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
index ba9faeff47..c5ace190bf 100644
--- a/drivers/ieee1394/nodemgr.c
+++ b/drivers/ieee1394/nodemgr.c
@@ -1681,7 +1681,8 @@ static int nodemgr_host_thread(void *__hi)
1681 for (;;) { 1681 for (;;) {
1682 /* Sleep until next bus reset */ 1682 /* Sleep until next bus reset */
1683 set_current_state(TASK_INTERRUPTIBLE); 1683 set_current_state(TASK_INTERRUPTIBLE);
1684 if (get_hpsb_generation(host) == generation) 1684 if (get_hpsb_generation(host) == generation &&
1685 !kthread_should_stop())
1685 schedule(); 1686 schedule();
1686 __set_current_state(TASK_RUNNING); 1687 __set_current_state(TASK_RUNNING);
1687 1688
diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c
index e982d60ac4..06fac0d212 100644
--- a/drivers/ieee1394/ohci1394.c
+++ b/drivers/ieee1394/ohci1394.c
@@ -180,7 +180,7 @@ static int alloc_dma_trm_ctx(struct ti_ohci *ohci, struct dma_trm_ctx *d,
180static void ohci1394_pci_remove(struct pci_dev *pdev); 180static void ohci1394_pci_remove(struct pci_dev *pdev);
181 181
182#ifndef __LITTLE_ENDIAN 182#ifndef __LITTLE_ENDIAN
183const static size_t hdr_sizes[] = { 183static const size_t hdr_sizes[] = {
184 3, /* TCODE_WRITEQ */ 184 3, /* TCODE_WRITEQ */
185 4, /* TCODE_WRITEB */ 185 4, /* TCODE_WRITEB */
186 3, /* TCODE_WRITE_RESPONSE */ 186 3, /* TCODE_WRITE_RESPONSE */
diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c
index aa9ca8385e..bb897a37d9 100644
--- a/drivers/ieee1394/raw1394.c
+++ b/drivers/ieee1394/raw1394.c
@@ -2669,6 +2669,18 @@ static void raw1394_iso_shutdown(struct file_info *fi)
2669 fi->iso_state = RAW1394_ISO_INACTIVE; 2669 fi->iso_state = RAW1394_ISO_INACTIVE;
2670} 2670}
2671 2671
2672static int raw1394_read_cycle_timer(struct file_info *fi, void __user * uaddr)
2673{
2674 struct raw1394_cycle_timer ct;
2675 int err;
2676
2677 err = hpsb_read_cycle_timer(fi->host, &ct.cycle_timer, &ct.local_time);
2678 if (!err)
2679 if (copy_to_user(uaddr, &ct, sizeof(ct)))
2680 err = -EFAULT;
2681 return err;
2682}
2683
2672/* mmap the rawiso xmit/recv buffer */ 2684/* mmap the rawiso xmit/recv buffer */
2673static int raw1394_mmap(struct file *file, struct vm_area_struct *vma) 2685static int raw1394_mmap(struct file *file, struct vm_area_struct *vma)
2674{ 2686{
@@ -2777,6 +2789,14 @@ static int raw1394_ioctl(struct inode *inode, struct file *file,
2777 break; 2789 break;
2778 } 2790 }
2779 2791
2792 /* state-independent commands */
2793 switch(cmd) {
2794 case RAW1394_IOC_GET_CYCLE_TIMER:
2795 return raw1394_read_cycle_timer(fi, argp);
2796 default:
2797 break;
2798 }
2799
2780 return -EINVAL; 2800 return -EINVAL;
2781} 2801}
2782 2802
diff --git a/drivers/ieee1394/raw1394.h b/drivers/ieee1394/raw1394.h
index 35bfc38f01..7bd22ee1af 100644
--- a/drivers/ieee1394/raw1394.h
+++ b/drivers/ieee1394/raw1394.h
@@ -178,4 +178,14 @@ struct raw1394_iso_status {
178 __s16 xmit_cycle; 178 __s16 xmit_cycle;
179}; 179};
180 180
181/* argument to RAW1394_IOC_GET_CYCLE_TIMER ioctl */
182struct raw1394_cycle_timer {
183 /* contents of Isochronous Cycle Timer register,
184 as in OHCI 1.1 clause 5.13 (also with non-OHCI hosts) */
185 __u32 cycle_timer;
186
187 /* local time in microseconds since Epoch,
188 simultaneously read with cycle timer */
189 __u64 local_time;
190};
181#endif /* IEEE1394_RAW1394_H */ 191#endif /* IEEE1394_RAW1394_H */
diff --git a/drivers/infiniband/core/Makefile b/drivers/infiniband/core/Makefile
index 50fb1cd447..189e5d4b9b 100644
--- a/drivers/infiniband/core/Makefile
+++ b/drivers/infiniband/core/Makefile
@@ -12,7 +12,7 @@ ib_core-y := packer.o ud_header.o verbs.o sysfs.o \
12 12
13ib_mad-y := mad.o smi.o agent.o mad_rmpp.o 13ib_mad-y := mad.o smi.o agent.o mad_rmpp.o
14 14
15ib_sa-y := sa_query.o 15ib_sa-y := sa_query.o multicast.o
16 16
17ib_cm-y := cm.o 17ib_cm-y := cm.o
18 18
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index d446998b12..842cd0b53e 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -88,7 +88,6 @@ struct cm_port {
88struct cm_device { 88struct cm_device {
89 struct list_head list; 89 struct list_head list;
90 struct ib_device *device; 90 struct ib_device *device;
91 __be64 ca_guid;
92 struct cm_port port[0]; 91 struct cm_port port[0];
93}; 92};
94 93
@@ -739,8 +738,8 @@ retest:
739 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); 738 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
740 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 739 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
741 ib_send_cm_rej(cm_id, IB_CM_REJ_TIMEOUT, 740 ib_send_cm_rej(cm_id, IB_CM_REJ_TIMEOUT,
742 &cm_id_priv->av.port->cm_dev->ca_guid, 741 &cm_id_priv->id.device->node_guid,
743 sizeof cm_id_priv->av.port->cm_dev->ca_guid, 742 sizeof cm_id_priv->id.device->node_guid,
744 NULL, 0); 743 NULL, 0);
745 break; 744 break;
746 case IB_CM_REQ_RCVD: 745 case IB_CM_REQ_RCVD:
@@ -883,7 +882,7 @@ static void cm_format_req(struct cm_req_msg *req_msg,
883 882
884 req_msg->local_comm_id = cm_id_priv->id.local_id; 883 req_msg->local_comm_id = cm_id_priv->id.local_id;
885 req_msg->service_id = param->service_id; 884 req_msg->service_id = param->service_id;
886 req_msg->local_ca_guid = cm_id_priv->av.port->cm_dev->ca_guid; 885 req_msg->local_ca_guid = cm_id_priv->id.device->node_guid;
887 cm_req_set_local_qpn(req_msg, cpu_to_be32(param->qp_num)); 886 cm_req_set_local_qpn(req_msg, cpu_to_be32(param->qp_num));
888 cm_req_set_resp_res(req_msg, param->responder_resources); 887 cm_req_set_resp_res(req_msg, param->responder_resources);
889 cm_req_set_init_depth(req_msg, param->initiator_depth); 888 cm_req_set_init_depth(req_msg, param->initiator_depth);
@@ -1442,7 +1441,7 @@ static void cm_format_rep(struct cm_rep_msg *rep_msg,
1442 cm_rep_set_flow_ctrl(rep_msg, param->flow_control); 1441 cm_rep_set_flow_ctrl(rep_msg, param->flow_control);
1443 cm_rep_set_rnr_retry_count(rep_msg, param->rnr_retry_count); 1442 cm_rep_set_rnr_retry_count(rep_msg, param->rnr_retry_count);
1444 cm_rep_set_srq(rep_msg, param->srq); 1443 cm_rep_set_srq(rep_msg, param->srq);
1445 rep_msg->local_ca_guid = cm_id_priv->av.port->cm_dev->ca_guid; 1444 rep_msg->local_ca_guid = cm_id_priv->id.device->node_guid;
1446 1445
1447 if (param->private_data && param->private_data_len) 1446 if (param->private_data && param->private_data_len)
1448 memcpy(rep_msg->private_data, param->private_data, 1447 memcpy(rep_msg->private_data, param->private_data,
@@ -3385,7 +3384,6 @@ static void cm_add_one(struct ib_device *device)
3385 return; 3384 return;
3386 3385
3387 cm_dev->device = device; 3386 cm_dev->device = device;
3388 cm_dev->ca_guid = device->node_guid;
3389 3387
3390 set_bit(IB_MGMT_METHOD_SEND, reg_req.method_mask); 3388 set_bit(IB_MGMT_METHOD_SEND, reg_req.method_mask);
3391 for (i = 1; i <= device->phys_port_cnt; i++) { 3389 for (i = 1; i <= device->phys_port_cnt; i++) {
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index db88e609bf..fde92ce451 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -71,12 +71,12 @@ static struct workqueue_struct *cma_wq;
71static DEFINE_IDR(sdp_ps); 71static DEFINE_IDR(sdp_ps);
72static DEFINE_IDR(tcp_ps); 72static DEFINE_IDR(tcp_ps);
73static DEFINE_IDR(udp_ps); 73static DEFINE_IDR(udp_ps);
74static DEFINE_IDR(ipoib_ps);
74static int next_port; 75static int next_port;
75 76
76struct cma_device { 77struct cma_device {
77 struct list_head list; 78 struct list_head list;
78 struct ib_device *device; 79 struct ib_device *device;
79 __be64 node_guid;
80 struct completion comp; 80 struct completion comp;
81 atomic_t refcount; 81 atomic_t refcount;
82 struct list_head id_list; 82 struct list_head id_list;
@@ -116,6 +116,7 @@ struct rdma_id_private {
116 struct list_head list; 116 struct list_head list;
117 struct list_head listen_list; 117 struct list_head listen_list;
118 struct cma_device *cma_dev; 118 struct cma_device *cma_dev;
119 struct list_head mc_list;
119 120
120 enum cma_state state; 121 enum cma_state state;
121 spinlock_t lock; 122 spinlock_t lock;
@@ -134,10 +135,23 @@ struct rdma_id_private {
134 } cm_id; 135 } cm_id;
135 136
136 u32 seq_num; 137 u32 seq_num;
138 u32 qkey;
137 u32 qp_num; 139 u32 qp_num;
138 u8 srq; 140 u8 srq;
139}; 141};
140 142
143struct cma_multicast {
144 struct rdma_id_private *id_priv;
145 union {
146 struct ib_sa_multicast *ib;
147 } multicast;
148 struct list_head list;
149 void *context;
150 struct sockaddr addr;
151 u8 pad[sizeof(struct sockaddr_in6) -
152 sizeof(struct sockaddr)];
153};
154
141struct cma_work { 155struct cma_work {
142 struct work_struct work; 156 struct work_struct work;
143 struct rdma_id_private *id; 157 struct rdma_id_private *id;
@@ -243,6 +257,11 @@ static inline void sdp_set_ip_ver(struct sdp_hh *hh, u8 ip_ver)
243 hh->ip_version = (ip_ver << 4) | (hh->ip_version & 0xF); 257 hh->ip_version = (ip_ver << 4) | (hh->ip_version & 0xF);
244} 258}
245 259
260static inline int cma_is_ud_ps(enum rdma_port_space ps)
261{
262 return (ps == RDMA_PS_UDP || ps == RDMA_PS_IPOIB);
263}
264
246static void cma_attach_to_dev(struct rdma_id_private *id_priv, 265static void cma_attach_to_dev(struct rdma_id_private *id_priv,
247 struct cma_device *cma_dev) 266 struct cma_device *cma_dev)
248{ 267{
@@ -265,19 +284,41 @@ static void cma_detach_from_dev(struct rdma_id_private *id_priv)
265 id_priv->cma_dev = NULL; 284 id_priv->cma_dev = NULL;
266} 285}
267 286
287static int cma_set_qkey(struct ib_device *device, u8 port_num,
288 enum rdma_port_space ps,
289 struct rdma_dev_addr *dev_addr, u32 *qkey)
290{
291 struct ib_sa_mcmember_rec rec;
292 int ret = 0;
293
294 switch (ps) {
295 case RDMA_PS_UDP:
296 *qkey = RDMA_UDP_QKEY;
297 break;
298 case RDMA_PS_IPOIB:
299 ib_addr_get_mgid(dev_addr, &rec.mgid);
300 ret = ib_sa_get_mcmember_rec(device, port_num, &rec.mgid, &rec);
301 *qkey = be32_to_cpu(rec.qkey);
302 break;
303 default:
304 break;
305 }
306 return ret;
307}
308
268static int cma_acquire_dev(struct rdma_id_private *id_priv) 309static int cma_acquire_dev(struct rdma_id_private *id_priv)
269{ 310{
270 enum rdma_node_type dev_type = id_priv->id.route.addr.dev_addr.dev_type; 311 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
271 struct cma_device *cma_dev; 312 struct cma_device *cma_dev;
272 union ib_gid gid; 313 union ib_gid gid;
273 int ret = -ENODEV; 314 int ret = -ENODEV;
274 315
275 switch (rdma_node_get_transport(dev_type)) { 316 switch (rdma_node_get_transport(dev_addr->dev_type)) {
276 case RDMA_TRANSPORT_IB: 317 case RDMA_TRANSPORT_IB:
277 ib_addr_get_sgid(&id_priv->id.route.addr.dev_addr, &gid); 318 ib_addr_get_sgid(dev_addr, &gid);
278 break; 319 break;
279 case RDMA_TRANSPORT_IWARP: 320 case RDMA_TRANSPORT_IWARP:
280 iw_addr_get_sgid(&id_priv->id.route.addr.dev_addr, &gid); 321 iw_addr_get_sgid(dev_addr, &gid);
281 break; 322 break;
282 default: 323 default:
283 return -ENODEV; 324 return -ENODEV;
@@ -287,7 +328,12 @@ static int cma_acquire_dev(struct rdma_id_private *id_priv)
287 ret = ib_find_cached_gid(cma_dev->device, &gid, 328 ret = ib_find_cached_gid(cma_dev->device, &gid,
288 &id_priv->id.port_num, NULL); 329 &id_priv->id.port_num, NULL);
289 if (!ret) { 330 if (!ret) {
290 cma_attach_to_dev(id_priv, cma_dev); 331 ret = cma_set_qkey(cma_dev->device,
332 id_priv->id.port_num,
333 id_priv->id.ps, dev_addr,
334 &id_priv->qkey);
335 if (!ret)
336 cma_attach_to_dev(id_priv, cma_dev);
291 break; 337 break;
292 } 338 }
293 } 339 }
@@ -325,40 +371,50 @@ struct rdma_cm_id *rdma_create_id(rdma_cm_event_handler event_handler,
325 init_waitqueue_head(&id_priv->wait_remove); 371 init_waitqueue_head(&id_priv->wait_remove);
326 atomic_set(&id_priv->dev_remove, 0); 372 atomic_set(&id_priv->dev_remove, 0);
327 INIT_LIST_HEAD(&id_priv->listen_list); 373 INIT_LIST_HEAD(&id_priv->listen_list);
374 INIT_LIST_HEAD(&id_priv->mc_list);
328 get_random_bytes(&id_priv->seq_num, sizeof id_priv->seq_num); 375 get_random_bytes(&id_priv->seq_num, sizeof id_priv->seq_num);
329 376
330 return &id_priv->id; 377 return &id_priv->id;
331} 378}
332EXPORT_SYMBOL(rdma_create_id); 379EXPORT_SYMBOL(rdma_create_id);
333 380
334static int cma_init_ib_qp(struct rdma_id_private *id_priv, struct ib_qp *qp) 381static int cma_init_ud_qp(struct rdma_id_private *id_priv, struct ib_qp *qp)
335{ 382{
336 struct ib_qp_attr qp_attr; 383 struct ib_qp_attr qp_attr;
337 struct rdma_dev_addr *dev_addr; 384 int qp_attr_mask, ret;
338 int ret;
339 385
340 dev_addr = &id_priv->id.route.addr.dev_addr; 386 qp_attr.qp_state = IB_QPS_INIT;
341 ret = ib_find_cached_pkey(id_priv->id.device, id_priv->id.port_num, 387 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask);
342 ib_addr_get_pkey(dev_addr),
343 &qp_attr.pkey_index);
344 if (ret) 388 if (ret)
345 return ret; 389 return ret;
346 390
347 qp_attr.qp_state = IB_QPS_INIT; 391 ret = ib_modify_qp(qp, &qp_attr, qp_attr_mask);
348 qp_attr.qp_access_flags = 0; 392 if (ret)
349 qp_attr.port_num = id_priv->id.port_num; 393 return ret;
350 return ib_modify_qp(qp, &qp_attr, IB_QP_STATE | IB_QP_ACCESS_FLAGS | 394
351 IB_QP_PKEY_INDEX | IB_QP_PORT); 395 qp_attr.qp_state = IB_QPS_RTR;
396 ret = ib_modify_qp(qp, &qp_attr, IB_QP_STATE);
397 if (ret)
398 return ret;
399
400 qp_attr.qp_state = IB_QPS_RTS;
401 qp_attr.sq_psn = 0;
402 ret = ib_modify_qp(qp, &qp_attr, IB_QP_STATE | IB_QP_SQ_PSN);
403
404 return ret;
352} 405}
353 406
354static int cma_init_iw_qp(struct rdma_id_private *id_priv, struct ib_qp *qp) 407static int cma_init_conn_qp(struct rdma_id_private *id_priv, struct ib_qp *qp)
355{ 408{
356 struct ib_qp_attr qp_attr; 409 struct ib_qp_attr qp_attr;
410 int qp_attr_mask, ret;
357 411
358 qp_attr.qp_state = IB_QPS_INIT; 412 qp_attr.qp_state = IB_QPS_INIT;
359 qp_attr.qp_access_flags = IB_ACCESS_LOCAL_WRITE; 413 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask);
414 if (ret)
415 return ret;
360 416
361 return ib_modify_qp(qp, &qp_attr, IB_QP_STATE | IB_QP_ACCESS_FLAGS); 417 return ib_modify_qp(qp, &qp_attr, qp_attr_mask);
362} 418}
363 419
364int rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd, 420int rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd,
@@ -376,18 +432,10 @@ int rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd,
376 if (IS_ERR(qp)) 432 if (IS_ERR(qp))
377 return PTR_ERR(qp); 433 return PTR_ERR(qp);
378 434
379 switch (rdma_node_get_transport(id->device->node_type)) { 435 if (cma_is_ud_ps(id_priv->id.ps))
380 case RDMA_TRANSPORT_IB: 436 ret = cma_init_ud_qp(id_priv, qp);
381 ret = cma_init_ib_qp(id_priv, qp); 437 else
382 break; 438 ret = cma_init_conn_qp(id_priv, qp);
383 case RDMA_TRANSPORT_IWARP:
384 ret = cma_init_iw_qp(id_priv, qp);
385 break;
386 default:
387 ret = -ENOSYS;
388 break;
389 }
390
391 if (ret) 439 if (ret)
392 goto err; 440 goto err;
393 441
@@ -460,23 +508,55 @@ static int cma_modify_qp_err(struct rdma_cm_id *id)
460 return ib_modify_qp(id->qp, &qp_attr, IB_QP_STATE); 508 return ib_modify_qp(id->qp, &qp_attr, IB_QP_STATE);
461} 509}
462 510
511static int cma_ib_init_qp_attr(struct rdma_id_private *id_priv,
512 struct ib_qp_attr *qp_attr, int *qp_attr_mask)
513{
514 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
515 int ret;
516
517 ret = ib_find_cached_pkey(id_priv->id.device, id_priv->id.port_num,
518 ib_addr_get_pkey(dev_addr),
519 &qp_attr->pkey_index);
520 if (ret)
521 return ret;
522
523 qp_attr->port_num = id_priv->id.port_num;
524 *qp_attr_mask = IB_QP_STATE | IB_QP_PKEY_INDEX | IB_QP_PORT;
525
526 if (cma_is_ud_ps(id_priv->id.ps)) {
527 qp_attr->qkey = id_priv->qkey;
528 *qp_attr_mask |= IB_QP_QKEY;
529 } else {
530 qp_attr->qp_access_flags = 0;
531 *qp_attr_mask |= IB_QP_ACCESS_FLAGS;
532 }
533 return 0;
534}
535
463int rdma_init_qp_attr(struct rdma_cm_id *id, struct ib_qp_attr *qp_attr, 536int rdma_init_qp_attr(struct rdma_cm_id *id, struct ib_qp_attr *qp_attr,
464 int *qp_attr_mask) 537 int *qp_attr_mask)
465{ 538{
466 struct rdma_id_private *id_priv; 539 struct rdma_id_private *id_priv;
467 int ret; 540 int ret = 0;
468 541
469 id_priv = container_of(id, struct rdma_id_private, id); 542 id_priv = container_of(id, struct rdma_id_private, id);
470 switch (rdma_node_get_transport(id_priv->id.device->node_type)) { 543 switch (rdma_node_get_transport(id_priv->id.device->node_type)) {
471 case RDMA_TRANSPORT_IB: 544 case RDMA_TRANSPORT_IB:
472 ret = ib_cm_init_qp_attr(id_priv->cm_id.ib, qp_attr, 545 if (!id_priv->cm_id.ib || cma_is_ud_ps(id_priv->id.ps))
473 qp_attr_mask); 546 ret = cma_ib_init_qp_attr(id_priv, qp_attr, qp_attr_mask);
547 else
548 ret = ib_cm_init_qp_attr(id_priv->cm_id.ib, qp_attr,
549 qp_attr_mask);
474 if (qp_attr->qp_state == IB_QPS_RTR) 550 if (qp_attr->qp_state == IB_QPS_RTR)
475 qp_attr->rq_psn = id_priv->seq_num; 551 qp_attr->rq_psn = id_priv->seq_num;
476 break; 552 break;
477 case RDMA_TRANSPORT_IWARP: 553 case RDMA_TRANSPORT_IWARP:
478 ret = iw_cm_init_qp_attr(id_priv->cm_id.iw, qp_attr, 554 if (!id_priv->cm_id.iw) {
479 qp_attr_mask); 555 qp_attr->qp_access_flags = IB_ACCESS_LOCAL_WRITE;
556 *qp_attr_mask = IB_QP_STATE | IB_QP_ACCESS_FLAGS;
557 } else
558 ret = iw_cm_init_qp_attr(id_priv->cm_id.iw, qp_attr,
559 qp_attr_mask);
480 break; 560 break;
481 default: 561 default:
482 ret = -ENOSYS; 562 ret = -ENOSYS;
@@ -698,6 +778,19 @@ static void cma_release_port(struct rdma_id_private *id_priv)
698 mutex_unlock(&lock); 778 mutex_unlock(&lock);
699} 779}
700 780
781static void cma_leave_mc_groups(struct rdma_id_private *id_priv)
782{
783 struct cma_multicast *mc;
784
785 while (!list_empty(&id_priv->mc_list)) {
786 mc = container_of(id_priv->mc_list.next,
787 struct cma_multicast, list);
788 list_del(&mc->list);
789 ib_sa_free_multicast(mc->multicast.ib);
790 kfree(mc);
791 }
792}
793
701void rdma_destroy_id(struct rdma_cm_id *id) 794void rdma_destroy_id(struct rdma_cm_id *id)
702{ 795{
703 struct rdma_id_private *id_priv; 796 struct rdma_id_private *id_priv;
@@ -722,6 +815,7 @@ void rdma_destroy_id(struct rdma_cm_id *id)
722 default: 815 default:
723 break; 816 break;
724 } 817 }
818 cma_leave_mc_groups(id_priv);
725 mutex_lock(&lock); 819 mutex_lock(&lock);
726 cma_detach_from_dev(id_priv); 820 cma_detach_from_dev(id_priv);
727 } 821 }
@@ -972,7 +1066,7 @@ static int cma_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event)
972 memset(&event, 0, sizeof event); 1066 memset(&event, 0, sizeof event);
973 offset = cma_user_data_offset(listen_id->id.ps); 1067 offset = cma_user_data_offset(listen_id->id.ps);
974 event.event = RDMA_CM_EVENT_CONNECT_REQUEST; 1068 event.event = RDMA_CM_EVENT_CONNECT_REQUEST;
975 if (listen_id->id.ps == RDMA_PS_UDP) { 1069 if (cma_is_ud_ps(listen_id->id.ps)) {
976 conn_id = cma_new_udp_id(&listen_id->id, ib_event); 1070 conn_id = cma_new_udp_id(&listen_id->id, ib_event);
977 event.param.ud.private_data = ib_event->private_data + offset; 1071 event.param.ud.private_data = ib_event->private_data + offset;
978 event.param.ud.private_data_len = 1072 event.param.ud.private_data_len =
@@ -1397,11 +1491,13 @@ static int cma_query_ib_route(struct rdma_id_private *id_priv, int timeout_ms,
1397 ib_addr_get_dgid(addr, &path_rec.dgid); 1491 ib_addr_get_dgid(addr, &path_rec.dgid);
1398 path_rec.pkey = cpu_to_be16(ib_addr_get_pkey(addr)); 1492 path_rec.pkey = cpu_to_be16(ib_addr_get_pkey(addr));
1399 path_rec.numb_path = 1; 1493 path_rec.numb_path = 1;
1494 path_rec.reversible = 1;
1400 1495
1401 id_priv->query_id = ib_sa_path_rec_get(&sa_client, id_priv->id.device, 1496 id_priv->query_id = ib_sa_path_rec_get(&sa_client, id_priv->id.device,
1402 id_priv->id.port_num, &path_rec, 1497 id_priv->id.port_num, &path_rec,
1403 IB_SA_PATH_REC_DGID | IB_SA_PATH_REC_SGID | 1498 IB_SA_PATH_REC_DGID | IB_SA_PATH_REC_SGID |
1404 IB_SA_PATH_REC_PKEY | IB_SA_PATH_REC_NUMB_PATH, 1499 IB_SA_PATH_REC_PKEY | IB_SA_PATH_REC_NUMB_PATH |
1500 IB_SA_PATH_REC_REVERSIBLE,
1405 timeout_ms, GFP_KERNEL, 1501 timeout_ms, GFP_KERNEL,
1406 cma_query_handler, work, &id_priv->query); 1502 cma_query_handler, work, &id_priv->query);
1407 1503
@@ -1847,6 +1943,9 @@ static int cma_get_port(struct rdma_id_private *id_priv)
1847 case RDMA_PS_UDP: 1943 case RDMA_PS_UDP:
1848 ps = &udp_ps; 1944 ps = &udp_ps;
1849 break; 1945 break;
1946 case RDMA_PS_IPOIB:
1947 ps = &ipoib_ps;
1948 break;
1850 default: 1949 default:
1851 return -EPROTONOSUPPORT; 1950 return -EPROTONOSUPPORT;
1852 } 1951 }
@@ -1961,7 +2060,7 @@ static int cma_sidr_rep_handler(struct ib_cm_id *cm_id,
1961 event.status = ib_event->param.sidr_rep_rcvd.status; 2060 event.status = ib_event->param.sidr_rep_rcvd.status;
1962 break; 2061 break;
1963 } 2062 }
1964 if (rep->qkey != RDMA_UD_QKEY) { 2063 if (id_priv->qkey != rep->qkey) {
1965 event.event = RDMA_CM_EVENT_UNREACHABLE; 2064 event.event = RDMA_CM_EVENT_UNREACHABLE;
1966 event.status = -EINVAL; 2065 event.status = -EINVAL;
1967 break; 2066 break;
@@ -2160,7 +2259,7 @@ int rdma_connect(struct rdma_cm_id *id, struct rdma_conn_param *conn_param)
2160 2259
2161 switch (rdma_node_get_transport(id->device->node_type)) { 2260 switch (rdma_node_get_transport(id->device->node_type)) {
2162 case RDMA_TRANSPORT_IB: 2261 case RDMA_TRANSPORT_IB:
2163 if (id->ps == RDMA_PS_UDP) 2262 if (cma_is_ud_ps(id->ps))
2164 ret = cma_resolve_ib_udp(id_priv, conn_param); 2263 ret = cma_resolve_ib_udp(id_priv, conn_param);
2165 else 2264 else
2166 ret = cma_connect_ib(id_priv, conn_param); 2265 ret = cma_connect_ib(id_priv, conn_param);
@@ -2256,7 +2355,7 @@ static int cma_send_sidr_rep(struct rdma_id_private *id_priv,
2256 rep.status = status; 2355 rep.status = status;
2257 if (status == IB_SIDR_SUCCESS) { 2356 if (status == IB_SIDR_SUCCESS) {
2258 rep.qp_num = id_priv->qp_num; 2357 rep.qp_num = id_priv->qp_num;
2259 rep.qkey = RDMA_UD_QKEY; 2358 rep.qkey = id_priv->qkey;
2260 } 2359 }
2261 rep.private_data = private_data; 2360 rep.private_data = private_data;
2262 rep.private_data_len = private_data_len; 2361 rep.private_data_len = private_data_len;
@@ -2280,7 +2379,7 @@ int rdma_accept(struct rdma_cm_id *id, struct rdma_conn_param *conn_param)
2280 2379
2281 switch (rdma_node_get_transport(id->device->node_type)) { 2380 switch (rdma_node_get_transport(id->device->node_type)) {
2282 case RDMA_TRANSPORT_IB: 2381 case RDMA_TRANSPORT_IB:
2283 if (id->ps == RDMA_PS_UDP) 2382 if (cma_is_ud_ps(id->ps))
2284 ret = cma_send_sidr_rep(id_priv, IB_SIDR_SUCCESS, 2383 ret = cma_send_sidr_rep(id_priv, IB_SIDR_SUCCESS,
2285 conn_param->private_data, 2384 conn_param->private_data,
2286 conn_param->private_data_len); 2385 conn_param->private_data_len);
@@ -2341,7 +2440,7 @@ int rdma_reject(struct rdma_cm_id *id, const void *private_data,
2341 2440
2342 switch (rdma_node_get_transport(id->device->node_type)) { 2441 switch (rdma_node_get_transport(id->device->node_type)) {
2343 case RDMA_TRANSPORT_IB: 2442 case RDMA_TRANSPORT_IB:
2344 if (id->ps == RDMA_PS_UDP) 2443 if (cma_is_ud_ps(id->ps))
2345 ret = cma_send_sidr_rep(id_priv, IB_SIDR_REJECT, 2444 ret = cma_send_sidr_rep(id_priv, IB_SIDR_REJECT,
2346 private_data, private_data_len); 2445 private_data, private_data_len);
2347 else 2446 else
@@ -2392,6 +2491,178 @@ out:
2392} 2491}
2393EXPORT_SYMBOL(rdma_disconnect); 2492EXPORT_SYMBOL(rdma_disconnect);
2394 2493
2494static int cma_ib_mc_handler(int status, struct ib_sa_multicast *multicast)
2495{
2496 struct rdma_id_private *id_priv;
2497 struct cma_multicast *mc = multicast->context;
2498 struct rdma_cm_event event;
2499 int ret;
2500
2501 id_priv = mc->id_priv;
2502 atomic_inc(&id_priv->dev_remove);
2503 if (!cma_comp(id_priv, CMA_ADDR_BOUND) &&
2504 !cma_comp(id_priv, CMA_ADDR_RESOLVED))
2505 goto out;
2506
2507 if (!status && id_priv->id.qp)
2508 status = ib_attach_mcast(id_priv->id.qp, &multicast->rec.mgid,
2509 multicast->rec.mlid);
2510
2511 memset(&event, 0, sizeof event);
2512 event.status = status;
2513 event.param.ud.private_data = mc->context;
2514 if (!status) {
2515 event.event = RDMA_CM_EVENT_MULTICAST_JOIN;
2516 ib_init_ah_from_mcmember(id_priv->id.device,
2517 id_priv->id.port_num, &multicast->rec,
2518 &event.param.ud.ah_attr);
2519 event.param.ud.qp_num = 0xFFFFFF;
2520 event.param.ud.qkey = be32_to_cpu(multicast->rec.qkey);
2521 } else
2522 event.event = RDMA_CM_EVENT_MULTICAST_ERROR;
2523
2524 ret = id_priv->id.event_handler(&id_priv->id, &event);
2525 if (ret) {
2526 cma_exch(id_priv, CMA_DESTROYING);
2527 cma_release_remove(id_priv);
2528 rdma_destroy_id(&id_priv->id);
2529 return 0;
2530 }
2531out:
2532 cma_release_remove(id_priv);
2533 return 0;
2534}
2535
2536static void cma_set_mgid(struct rdma_id_private *id_priv,
2537 struct sockaddr *addr, union ib_gid *mgid)
2538{
2539 unsigned char mc_map[MAX_ADDR_LEN];
2540 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
2541 struct sockaddr_in *sin = (struct sockaddr_in *) addr;
2542 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) addr;
2543
2544 if (cma_any_addr(addr)) {
2545 memset(mgid, 0, sizeof *mgid);
2546 } else if ((addr->sa_family == AF_INET6) &&
2547 ((be32_to_cpu(sin6->sin6_addr.s6_addr32[0]) & 0xFF10A01B) ==
2548 0xFF10A01B)) {
2549 /* IPv6 address is an SA assigned MGID. */
2550 memcpy(mgid, &sin6->sin6_addr, sizeof *mgid);
2551 } else {
2552 ip_ib_mc_map(sin->sin_addr.s_addr, mc_map);
2553 if (id_priv->id.ps == RDMA_PS_UDP)
2554 mc_map[7] = 0x01; /* Use RDMA CM signature */
2555 mc_map[8] = ib_addr_get_pkey(dev_addr) >> 8;
2556 mc_map[9] = (unsigned char) ib_addr_get_pkey(dev_addr);
2557 *mgid = *(union ib_gid *) (mc_map + 4);
2558 }
2559}
2560
2561static int cma_join_ib_multicast(struct rdma_id_private *id_priv,
2562 struct cma_multicast *mc)
2563{
2564 struct ib_sa_mcmember_rec rec;
2565 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
2566 ib_sa_comp_mask comp_mask;
2567 int ret;
2568
2569 ib_addr_get_mgid(dev_addr, &rec.mgid);
2570 ret = ib_sa_get_mcmember_rec(id_priv->id.device, id_priv->id.port_num,
2571 &rec.mgid, &rec);
2572 if (ret)
2573 return ret;
2574
2575 cma_set_mgid(id_priv, &mc->addr, &rec.mgid);
2576 if (id_priv->id.ps == RDMA_PS_UDP)
2577 rec.qkey = cpu_to_be32(RDMA_UDP_QKEY);
2578 ib_addr_get_sgid(dev_addr, &rec.port_gid);
2579 rec.pkey = cpu_to_be16(ib_addr_get_pkey(dev_addr));
2580 rec.join_state = 1;
2581
2582 comp_mask = IB_SA_MCMEMBER_REC_MGID | IB_SA_MCMEMBER_REC_PORT_GID |
2583 IB_SA_MCMEMBER_REC_PKEY | IB_SA_MCMEMBER_REC_JOIN_STATE |
2584 IB_SA_MCMEMBER_REC_QKEY | IB_SA_MCMEMBER_REC_SL |
2585 IB_SA_MCMEMBER_REC_FLOW_LABEL |
2586 IB_SA_MCMEMBER_REC_TRAFFIC_CLASS;
2587
2588 mc->multicast.ib = ib_sa_join_multicast(&sa_client, id_priv->id.device,
2589 id_priv->id.port_num, &rec,
2590 comp_mask, GFP_KERNEL,
2591 cma_ib_mc_handler, mc);
2592 if (IS_ERR(mc->multicast.ib))
2593 return PTR_ERR(mc->multicast.ib);
2594
2595 return 0;
2596}
2597
2598int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr,
2599 void *context)
2600{
2601 struct rdma_id_private *id_priv;
2602 struct cma_multicast *mc;
2603 int ret;
2604
2605 id_priv = container_of(id, struct rdma_id_private, id);
2606 if (!cma_comp(id_priv, CMA_ADDR_BOUND) &&
2607 !cma_comp(id_priv, CMA_ADDR_RESOLVED))
2608 return -EINVAL;
2609
2610 mc = kmalloc(sizeof *mc, GFP_KERNEL);
2611 if (!mc)
2612 return -ENOMEM;
2613
2614 memcpy(&mc->addr, addr, ip_addr_size(addr));
2615 mc->context = context;
2616 mc->id_priv = id_priv;
2617
2618 spin_lock(&id_priv->lock);
2619 list_add(&mc->list, &id_priv->mc_list);
2620 spin_unlock(&id_priv->lock);
2621
2622 switch (rdma_node_get_transport(id->device->node_type)) {
2623 case RDMA_TRANSPORT_IB:
2624 ret = cma_join_ib_multicast(id_priv, mc);
2625 break;
2626 default:
2627 ret = -ENOSYS;
2628 break;
2629 }
2630
2631 if (ret) {
2632 spin_lock_irq(&id_priv->lock);
2633 list_del(&mc->list);
2634 spin_unlock_irq(&id_priv->lock);
2635 kfree(mc);
2636 }
2637 return ret;
2638}
2639EXPORT_SYMBOL(rdma_join_multicast);
2640
2641void rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr)
2642{
2643 struct rdma_id_private *id_priv;
2644 struct cma_multicast *mc;
2645
2646 id_priv = container_of(id, struct rdma_id_private, id);
2647 spin_lock_irq(&id_priv->lock);
2648 list_for_each_entry(mc, &id_priv->mc_list, list) {
2649 if (!memcmp(&mc->addr, addr, ip_addr_size(addr))) {
2650 list_del(&mc->list);
2651 spin_unlock_irq(&id_priv->lock);
2652
2653 if (id->qp)
2654 ib_detach_mcast(id->qp,
2655 &mc->multicast.ib->rec.mgid,
2656 mc->multicast.ib->rec.mlid);
2657 ib_sa_free_multicast(mc->multicast.ib);
2658 kfree(mc);
2659 return;
2660 }
2661 }
2662 spin_unlock_irq(&id_priv->lock);
2663}
2664EXPORT_SYMBOL(rdma_leave_multicast);
2665
2395static void cma_add_one(struct ib_device *device) 2666static void cma_add_one(struct ib_device *device)
2396{ 2667{
2397 struct cma_device *cma_dev; 2668 struct cma_device *cma_dev;
@@ -2402,7 +2673,6 @@ static void cma_add_one(struct ib_device *device)
2402 return; 2673 return;
2403 2674
2404 cma_dev->device = device; 2675 cma_dev->device = device;
2405 cma_dev->node_guid = device->node_guid;
2406 2676
2407 init_completion(&cma_dev->comp); 2677 init_completion(&cma_dev->comp);
2408 atomic_set(&cma_dev->refcount, 1); 2678 atomic_set(&cma_dev->refcount, 1);
@@ -2522,6 +2792,7 @@ static void cma_cleanup(void)
2522 idr_destroy(&sdp_ps); 2792 idr_destroy(&sdp_ps);
2523 idr_destroy(&tcp_ps); 2793 idr_destroy(&tcp_ps);
2524 idr_destroy(&udp_ps); 2794 idr_destroy(&udp_ps);
2795 idr_destroy(&ipoib_ps);
2525} 2796}
2526 2797
2527module_init(cma_init); 2798module_init(cma_init);
diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
index 8926a2bd4a..1d796e7c81 100644
--- a/drivers/infiniband/core/fmr_pool.c
+++ b/drivers/infiniband/core/fmr_pool.c
@@ -301,7 +301,7 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
301 301
302 { 302 {
303 struct ib_pool_fmr *fmr; 303 struct ib_pool_fmr *fmr;
304 struct ib_fmr_attr attr = { 304 struct ib_fmr_attr fmr_attr = {
305 .max_pages = params->max_pages_per_fmr, 305 .max_pages = params->max_pages_per_fmr,
306 .max_maps = pool->max_remaps, 306 .max_maps = pool->max_remaps,
307 .page_shift = params->page_shift 307 .page_shift = params->page_shift
@@ -321,7 +321,7 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
321 fmr->ref_count = 0; 321 fmr->ref_count = 0;
322 INIT_HLIST_NODE(&fmr->cache_node); 322 INIT_HLIST_NODE(&fmr->cache_node);
323 323
324 fmr->fmr = ib_alloc_fmr(pd, params->access, &attr); 324 fmr->fmr = ib_alloc_fmr(pd, params->access, &fmr_attr);
325 if (IS_ERR(fmr->fmr)) { 325 if (IS_ERR(fmr->fmr)) {
326 printk(KERN_WARNING "fmr_create failed for FMR %d", i); 326 printk(KERN_WARNING "fmr_create failed for FMR %d", i);
327 kfree(fmr); 327 kfree(fmr);
diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c
index 1039ad57d5..891d1fa7b2 100644
--- a/drivers/infiniband/core/iwcm.c
+++ b/drivers/infiniband/core/iwcm.c
@@ -146,6 +146,12 @@ static int copy_private_data(struct iw_cm_event *event)
146 return 0; 146 return 0;
147} 147}
148 148
149static void free_cm_id(struct iwcm_id_private *cm_id_priv)
150{
151 dealloc_work_entries(cm_id_priv);
152 kfree(cm_id_priv);
153}
154
149/* 155/*
150 * Release a reference on cm_id. If the last reference is being 156 * Release a reference on cm_id. If the last reference is being
151 * released, enable the waiting thread (in iw_destroy_cm_id) to 157 * released, enable the waiting thread (in iw_destroy_cm_id) to
@@ -153,21 +159,14 @@ static int copy_private_data(struct iw_cm_event *event)
153 */ 159 */
154static int iwcm_deref_id(struct iwcm_id_private *cm_id_priv) 160static int iwcm_deref_id(struct iwcm_id_private *cm_id_priv)
155{ 161{
156 int ret = 0;
157
158 BUG_ON(atomic_read(&cm_id_priv->refcount)==0); 162 BUG_ON(atomic_read(&cm_id_priv->refcount)==0);
159 if (atomic_dec_and_test(&cm_id_priv->refcount)) { 163 if (atomic_dec_and_test(&cm_id_priv->refcount)) {
160 BUG_ON(!list_empty(&cm_id_priv->work_list)); 164 BUG_ON(!list_empty(&cm_id_priv->work_list));
161 if (waitqueue_active(&cm_id_priv->destroy_comp.wait)) {
162 BUG_ON(cm_id_priv->state != IW_CM_STATE_DESTROYING);
163 BUG_ON(test_bit(IWCM_F_CALLBACK_DESTROY,
164 &cm_id_priv->flags));
165 ret = 1;
166 }
167 complete(&cm_id_priv->destroy_comp); 165 complete(&cm_id_priv->destroy_comp);
166 return 1;
168 } 167 }
169 168
170 return ret; 169 return 0;
171} 170}
172 171
173static void add_ref(struct iw_cm_id *cm_id) 172static void add_ref(struct iw_cm_id *cm_id)
@@ -181,7 +180,11 @@ static void rem_ref(struct iw_cm_id *cm_id)
181{ 180{
182 struct iwcm_id_private *cm_id_priv; 181 struct iwcm_id_private *cm_id_priv;
183 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); 182 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
184 iwcm_deref_id(cm_id_priv); 183 if (iwcm_deref_id(cm_id_priv) &&
184 test_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags)) {
185 BUG_ON(!list_empty(&cm_id_priv->work_list));
186 free_cm_id(cm_id_priv);
187 }
185} 188}
186 189
187static int cm_event_handler(struct iw_cm_id *cm_id, struct iw_cm_event *event); 190static int cm_event_handler(struct iw_cm_id *cm_id, struct iw_cm_event *event);
@@ -355,7 +358,9 @@ static void destroy_cm_id(struct iw_cm_id *cm_id)
355 case IW_CM_STATE_CONN_RECV: 358 case IW_CM_STATE_CONN_RECV:
356 /* 359 /*
357 * App called destroy before/without calling accept after 360 * App called destroy before/without calling accept after
358 * receiving connection request event notification. 361 * receiving connection request event notification or
362 * returned non zero from the event callback function.
363 * In either case, must tell the provider to reject.
359 */ 364 */
360 cm_id_priv->state = IW_CM_STATE_DESTROYING; 365 cm_id_priv->state = IW_CM_STATE_DESTROYING;
361 break; 366 break;
@@ -391,9 +396,7 @@ void iw_destroy_cm_id(struct iw_cm_id *cm_id)
391 396
392 wait_for_completion(&cm_id_priv->destroy_comp); 397 wait_for_completion(&cm_id_priv->destroy_comp);
393 398
394 dealloc_work_entries(cm_id_priv); 399 free_cm_id(cm_id_priv);
395
396 kfree(cm_id_priv);
397} 400}
398EXPORT_SYMBOL(iw_destroy_cm_id); 401EXPORT_SYMBOL(iw_destroy_cm_id);
399 402
@@ -647,10 +650,11 @@ static void cm_conn_req_handler(struct iwcm_id_private *listen_id_priv,
647 /* Call the client CM handler */ 650 /* Call the client CM handler */
648 ret = cm_id->cm_handler(cm_id, iw_event); 651 ret = cm_id->cm_handler(cm_id, iw_event);
649 if (ret) { 652 if (ret) {
653 iw_cm_reject(cm_id, NULL, 0);
650 set_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags); 654 set_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags);
651 destroy_cm_id(cm_id); 655 destroy_cm_id(cm_id);
652 if (atomic_read(&cm_id_priv->refcount)==0) 656 if (atomic_read(&cm_id_priv->refcount)==0)
653 kfree(cm_id); 657 free_cm_id(cm_id_priv);
654 } 658 }
655 659
656out: 660out:
@@ -854,13 +858,12 @@ static void cm_work_handler(struct work_struct *_work)
854 destroy_cm_id(&cm_id_priv->id); 858 destroy_cm_id(&cm_id_priv->id);
855 } 859 }
856 BUG_ON(atomic_read(&cm_id_priv->refcount)==0); 860 BUG_ON(atomic_read(&cm_id_priv->refcount)==0);
857 if (iwcm_deref_id(cm_id_priv)) 861 if (iwcm_deref_id(cm_id_priv)) {
858 return; 862 if (test_bit(IWCM_F_CALLBACK_DESTROY,
859 863 &cm_id_priv->flags)) {
860 if (atomic_read(&cm_id_priv->refcount)==0 && 864 BUG_ON(!list_empty(&cm_id_priv->work_list));
861 test_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags)) { 865 free_cm_id(cm_id_priv);
862 dealloc_work_entries(cm_id_priv); 866 }
863 kfree(cm_id_priv);
864 return; 867 return;
865 } 868 }
866 spin_lock_irqsave(&cm_id_priv->lock, flags); 869 spin_lock_irqsave(&cm_id_priv->lock, flags);
diff --git a/drivers/infiniband/core/multicast.c b/drivers/infiniband/core/multicast.c
new file mode 100644
index 0000000000..4a579b3a1c
--- /dev/null
+++ b/drivers/infiniband/core/multicast.c
@@ -0,0 +1,837 @@
1/*
2 * Copyright (c) 2006 Intel Corporation.  All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/completion.h>
34#include <linux/dma-mapping.h>
35#include <linux/err.h>
36#include <linux/interrupt.h>
37#include <linux/pci.h>
38#include <linux/bitops.h>
39#include <linux/random.h>
40
41#include <rdma/ib_cache.h>
42#include "sa.h"
43
44static void mcast_add_one(struct ib_device *device);
45static void mcast_remove_one(struct ib_device *device);
46
47static struct ib_client mcast_client = {
48 .name = "ib_multicast",
49 .add = mcast_add_one,
50 .remove = mcast_remove_one
51};
52
53static struct ib_sa_client sa_client;
54static struct workqueue_struct *mcast_wq;
55static union ib_gid mgid0;
56
57struct mcast_device;
58
59struct mcast_port {
60 struct mcast_device *dev;
61 spinlock_t lock;
62 struct rb_root table;
63 atomic_t refcount;
64 struct completion comp;
65 u8 port_num;
66};
67
68struct mcast_device {
69 struct ib_device *device;
70 struct ib_event_handler event_handler;
71 int start_port;
72 int end_port;
73 struct mcast_port port[0];
74};
75
76enum mcast_state {
77 MCAST_IDLE,
78 MCAST_JOINING,
79 MCAST_MEMBER,
80 MCAST_BUSY,
81 MCAST_ERROR
82};
83
84struct mcast_member;
85
86struct mcast_group {
87 struct ib_sa_mcmember_rec rec;
88 struct rb_node node;
89 struct mcast_port *port;
90 spinlock_t lock;
91 struct work_struct work;
92 struct list_head pending_list;
93 struct list_head active_list;
94 struct mcast_member *last_join;
95 int members[3];
96 atomic_t refcount;
97 enum mcast_state state;
98 struct ib_sa_query *query;
99 int query_id;
100};
101
102struct mcast_member {
103 struct ib_sa_multicast multicast;
104 struct ib_sa_client *client;
105 struct mcast_group *group;
106 struct list_head list;
107 enum mcast_state state;
108 atomic_t refcount;
109 struct completion comp;
110};
111
112static void join_handler(int status, struct ib_sa_mcmember_rec *rec,
113 void *context);
114static void leave_handler(int status, struct ib_sa_mcmember_rec *rec,
115 void *context);
116
117static struct mcast_group *mcast_find(struct mcast_port *port,
118 union ib_gid *mgid)
119{
120 struct rb_node *node = port->table.rb_node;
121 struct mcast_group *group;
122 int ret;
123
124 while (node) {
125 group = rb_entry(node, struct mcast_group, node);
126 ret = memcmp(mgid->raw, group->rec.mgid.raw, sizeof *mgid);
127 if (!ret)
128 return group;
129
130 if (ret < 0)
131 node = node->rb_left;
132 else
133 node = node->rb_right;
134 }
135 return NULL;
136}
137
138static struct mcast_group *mcast_insert(struct mcast_port *port,
139 struct mcast_group *group,
140 int allow_duplicates)
141{
142 struct rb_node **link = &port->table.rb_node;
143 struct rb_node *parent = NULL;
144 struct mcast_group *cur_group;
145 int ret;
146
147 while (*link) {
148 parent = *link;
149 cur_group = rb_entry(parent, struct mcast_group, node);
150
151 ret = memcmp(group->rec.mgid.raw, cur_group->rec.mgid.raw,
152 sizeof group->rec.mgid);
153 if (ret < 0)
154 link = &(*link)->rb_left;
155 else if (ret > 0)
156 link = &(*link)->rb_right;
157 else if (allow_duplicates)
158 link = &(*link)->rb_left;
159 else
160 return cur_group;
161 }
162 rb_link_node(&group->node, parent, link);
163 rb_insert_color(&group->node, &port->table);
164 return NULL;
165}
166
167static void deref_port(struct mcast_port *port)
168{
169 if (atomic_dec_and_test(&port->refcount))
170 complete(&port->comp);
171}
172
173static void release_group(struct mcast_group *group)
174{
175 struct mcast_port *port = group->port;
176 unsigned long flags;
177
178 spin_lock_irqsave(&port->lock, flags);
179 if (atomic_dec_and_test(&group->refcount)) {
180 rb_erase(&group->node, &port->table);
181 spin_unlock_irqrestore(&port->lock, flags);
182 kfree(group);
183 deref_port(port);
184 } else
185 spin_unlock_irqrestore(&port->lock, flags);
186}
187
188static void deref_member(struct mcast_member *member)
189{
190 if (atomic_dec_and_test(&member->refcount))
191 complete(&member->comp);
192}
193
194static void queue_join(struct mcast_member *member)
195{
196 struct mcast_group *group = member->group;
197 unsigned long flags;
198
199 spin_lock_irqsave(&group->lock, flags);
200 list_add(&member->list, &group->pending_list);
201 if (group->state == MCAST_IDLE) {
202 group->state = MCAST_BUSY;
203 atomic_inc(&group->refcount);
204 queue_work(mcast_wq, &group->work);
205 }
206 spin_unlock_irqrestore(&group->lock, flags);
207}
208
209/*
210 * A multicast group has three types of members: full member, non member, and
211 * send only member. We need to keep track of the number of members of each
212 * type based on their join state. Adjust the number of members the belong to
213 * the specified join states.
214 */
215static void adjust_membership(struct mcast_group *group, u8 join_state, int inc)
216{
217 int i;
218
219 for (i = 0; i < 3; i++, join_state >>= 1)
220 if (join_state & 0x1)
221 group->members[i] += inc;
222}
223
224/*
225 * If a multicast group has zero members left for a particular join state, but
226 * the group is still a member with the SA, we need to leave that join state.
227 * Determine which join states we still belong to, but that do not have any
228 * active members.
229 */
230static u8 get_leave_state(struct mcast_group *group)
231{
232 u8 leave_state = 0;
233 int i;
234
235 for (i = 0; i < 3; i++)
236 if (!group->members[i])
237 leave_state |= (0x1 << i);
238
239 return leave_state & group->rec.join_state;
240}
241
242static int check_selector(ib_sa_comp_mask comp_mask,
243 ib_sa_comp_mask selector_mask,
244 ib_sa_comp_mask value_mask,
245 u8 selector, u8 src_value, u8 dst_value)
246{
247 int err;
248
249 if (!(comp_mask & selector_mask) || !(comp_mask & value_mask))
250 return 0;
251
252 switch (selector) {
253 case IB_SA_GT:
254 err = (src_value <= dst_value);
255 break;
256 case IB_SA_LT:
257 err = (src_value >= dst_value);
258 break;
259 case IB_SA_EQ:
260 err = (src_value != dst_value);
261 break;
262 default:
263 err = 0;
264 break;
265 }
266
267 return err;
268}
269
270static int cmp_rec(struct ib_sa_mcmember_rec *src,
271 struct ib_sa_mcmember_rec *dst, ib_sa_comp_mask comp_mask)
272{
273 /* MGID must already match */
274
275 if (comp_mask & IB_SA_MCMEMBER_REC_PORT_GID &&
276 memcmp(&src->port_gid, &dst->port_gid, sizeof src->port_gid))
277 return -EINVAL;
278 if (comp_mask & IB_SA_MCMEMBER_REC_QKEY && src->qkey != dst->qkey)
279 return -EINVAL;
280 if (comp_mask & IB_SA_MCMEMBER_REC_MLID && src->mlid != dst->mlid)
281 return -EINVAL;
282 if (check_selector(comp_mask, IB_SA_MCMEMBER_REC_MTU_SELECTOR,
283 IB_SA_MCMEMBER_REC_MTU, dst->mtu_selector,
284 src->mtu, dst->mtu))
285 return -EINVAL;
286 if (comp_mask & IB_SA_MCMEMBER_REC_TRAFFIC_CLASS &&
287 src->traffic_class != dst->traffic_class)
288 return -EINVAL;
289 if (comp_mask & IB_SA_MCMEMBER_REC_PKEY && src->pkey != dst->pkey)
290 return -EINVAL;
291 if (check_selector(comp_mask, IB_SA_MCMEMBER_REC_RATE_SELECTOR,
292 IB_SA_MCMEMBER_REC_RATE, dst->rate_selector,
293 src->rate, dst->rate))
294 return -EINVAL;
295 if (check_selector(comp_mask,
296 IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME_SELECTOR,
297 IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME,
298 dst->packet_life_time_selector,
299 src->packet_life_time, dst->packet_life_time))
300 return -EINVAL;
301 if (comp_mask & IB_SA_MCMEMBER_REC_SL && src->sl != dst->sl)
302 return -EINVAL;
303 if (comp_mask & IB_SA_MCMEMBER_REC_FLOW_LABEL &&
304 src->flow_label != dst->flow_label)
305 return -EINVAL;
306 if (comp_mask & IB_SA_MCMEMBER_REC_HOP_LIMIT &&
307 src->hop_limit != dst->hop_limit)
308 return -EINVAL;
309 if (comp_mask & IB_SA_MCMEMBER_REC_SCOPE && src->scope != dst->scope)
310 return -EINVAL;
311
312 /* join_state checked separately, proxy_join ignored */
313
314 return 0;
315}
316
317static int send_join(struct mcast_group *group, struct mcast_member *member)
318{
319 struct mcast_port *port = group->port;
320 int ret;
321
322 group->last_join = member;
323 ret = ib_sa_mcmember_rec_query(&sa_client, port->dev->device,
324 port->port_num, IB_MGMT_METHOD_SET,
325 &member->multicast.rec,
326 member->multicast.comp_mask,
327 3000, GFP_KERNEL, join_handler, group,
328 &group->query);
329 if (ret >= 0) {
330 group->query_id = ret;
331 ret = 0;
332 }
333 return ret;
334}
335
336static int send_leave(struct mcast_group *group, u8 leave_state)
337{
338 struct mcast_port *port = group->port;
339 struct ib_sa_mcmember_rec rec;
340 int ret;
341
342 rec = group->rec;
343 rec.join_state = leave_state;
344
345 ret = ib_sa_mcmember_rec_query(&sa_client, port->dev->device,
346 port->port_num, IB_SA_METHOD_DELETE, &rec,
347 IB_SA_MCMEMBER_REC_MGID |
348 IB_SA_MCMEMBER_REC_PORT_GID |
349 IB_SA_MCMEMBER_REC_JOIN_STATE,
350 3000, GFP_KERNEL, leave_handler,
351 group, &group->query);
352 if (ret >= 0) {
353 group->query_id = ret;
354 ret = 0;
355 }
356 return ret;
357}
358
359static void join_group(struct mcast_group *group, struct mcast_member *member,
360 u8 join_state)
361{
362 member->state = MCAST_MEMBER;
363 adjust_membership(group, join_state, 1);
364 group->rec.join_state |= join_state;
365 member->multicast.rec = group->rec;
366 member->multicast.rec.join_state = join_state;
367 list_move(&member->list, &group->active_list);
368}
369
370static int fail_join(struct mcast_group *group, struct mcast_member *member,
371 int status)
372{
373 spin_lock_irq(&group->lock);
374 list_del_init(&member->list);
375 spin_unlock_irq(&group->lock);
376 return member->multicast.callback(status, &member->multicast);
377}
378
379static void process_group_error(struct mcast_group *group)
380{
381 struct mcast_member *member;
382 int ret;
383
384 spin_lock_irq(&group->lock);
385 while (!list_empty(&group->active_list)) {
386 member = list_entry(group->active_list.next,
387 struct mcast_member, list);
388 atomic_inc(&member->refcount);
389 list_del_init(&member->list);
390 adjust_membership(group, member->multicast.rec.join_state, -1);
391 member->state = MCAST_ERROR;
392 spin_unlock_irq(&group->lock);
393
394 ret = member->multicast.callback(-ENETRESET,
395 &member->multicast);
396 deref_member(member);
397 if (ret)
398 ib_sa_free_multicast(&member->multicast);
399 spin_lock_irq(&group->lock);
400 }
401
402 group->rec.join_state = 0;
403 group->state = MCAST_BUSY;
404 spin_unlock_irq(&group->lock);
405}
406
407static void mcast_work_handler(struct work_struct *work)
408{
409 struct mcast_group *group;
410 struct mcast_member *member;
411 struct ib_sa_multicast *multicast;
412 int status, ret;
413 u8 join_state;
414
415 group = container_of(work, typeof(*group), work);
416retest:
417 spin_lock_irq(&group->lock);
418 while (!list_empty(&group->pending_list) ||
419 (group->state == MCAST_ERROR)) {
420
421 if (group->state == MCAST_ERROR) {
422 spin_unlock_irq(&group->lock);
423 process_group_error(group);
424 goto retest;
425 }
426
427 member = list_entry(group->pending_list.next,
428 struct mcast_member, list);
429 multicast = &member->multicast;
430 join_state = multicast->rec.join_state;
431 atomic_inc(&member->refcount);
432
433 if (join_state == (group->rec.join_state & join_state)) {
434 status = cmp_rec(&group->rec, &multicast->rec,
435 multicast->comp_mask);
436 if (!status)
437 join_group(group, member, join_state);
438 else
439 list_del_init(&member->list);
440 spin_unlock_irq(&group->lock);
441 ret = multicast->callback(status, multicast);
442 } else {
443 spin_unlock_irq(&group->lock);
444 status = send_join(group, member);
445 if (!status) {
446 deref_member(member);
447 return;
448 }
449 ret = fail_join(group, member, status);
450 }
451
452 deref_member(member);
453 if (ret)
454 ib_sa_free_multicast(&member->multicast);
455 spin_lock_irq(&group->lock);
456 }
457
458 join_state = get_leave_state(group);
459 if (join_state) {
460 group->rec.join_state &= ~join_state;
461 spin_unlock_irq(&group->lock);
462 if (send_leave(group, join_state))
463 goto retest;
464 } else {
465 group->state = MCAST_IDLE;
466 spin_unlock_irq(&group->lock);
467 release_group(group);
468 }
469}
470
471/*
472 * Fail a join request if it is still active - at the head of the pending queue.
473 */
474static void process_join_error(struct mcast_group *group, int status)
475{
476 struct mcast_member *member;
477 int ret;
478
479 spin_lock_irq(&group->lock);
480 member = list_entry(group->pending_list.next,
481 struct mcast_member, list);
482 if (group->last_join == member) {
483 atomic_inc(&member->refcount);
484 list_del_init(&member->list);
485 spin_unlock_irq(&group->lock);
486 ret = member->multicast.callback(status, &member->multicast);
487 deref_member(member);
488 if (ret)
489 ib_sa_free_multicast(&member->multicast);
490 } else
491 spin_unlock_irq(&group->lock);
492}
493
494static void join_handler(int status, struct ib_sa_mcmember_rec *rec,
495 void *context)
496{
497 struct mcast_group *group = context;
498
499 if (status)
500 process_join_error(group, status);
501 else {
502 spin_lock_irq(&group->port->lock);
503 group->rec = *rec;
504 if (!memcmp(&mgid0, &group->rec.mgid, sizeof mgid0)) {
505 rb_erase(&group->node, &group->port->table);
506 mcast_insert(group->port, group, 1);
507 }
508 spin_unlock_irq(&group->port->lock);
509 }
510 mcast_work_handler(&group->work);
511}
512
513static void leave_handler(int status, struct ib_sa_mcmember_rec *rec,
514 void *context)
515{
516 struct mcast_group *group = context;
517
518 mcast_work_handler(&group->work);
519}
520
521static struct mcast_group *acquire_group(struct mcast_port *port,
522 union ib_gid *mgid, gfp_t gfp_mask)
523{
524 struct mcast_group *group, *cur_group;
525 unsigned long flags;
526 int is_mgid0;
527
528 is_mgid0 = !memcmp(&mgid0, mgid, sizeof mgid0);
529 if (!is_mgid0) {
530 spin_lock_irqsave(&port->lock, flags);
531 group = mcast_find(port, mgid);
532 if (group)
533 goto found;
534 spin_unlock_irqrestore(&port->lock, flags);
535 }
536
537 group = kzalloc(sizeof *group, gfp_mask);
538 if (!group)
539 return NULL;
540
541 group->port = port;
542 group->rec.mgid = *mgid;
543 INIT_LIST_HEAD(&group->pending_list);
544 INIT_LIST_HEAD(&group->active_list);
545 INIT_WORK(&group->work, mcast_work_handler);
546 spin_lock_init(&group->lock);
547
548 spin_lock_irqsave(&port->lock, flags);
549 cur_group = mcast_insert(port, group, is_mgid0);
550 if (cur_group) {
551 kfree(group);
552 group = cur_group;
553 } else
554 atomic_inc(&port->refcount);
555found:
556 atomic_inc(&group->refcount);
557 spin_unlock_irqrestore(&port->lock, flags);
558 return group;
559}
560
561/*
562 * We serialize all join requests to a single group to make our lives much
563 * easier. Otherwise, two users could try to join the same group
564 * simultaneously, with different configurations, one could leave while the
565 * join is in progress, etc., which makes locking around error recovery
566 * difficult.
567 */
568struct ib_sa_multicast *
569ib_sa_join_multicast(struct ib_sa_client *client,
570 struct ib_device *device, u8 port_num,
571 struct ib_sa_mcmember_rec *rec,
572 ib_sa_comp_mask comp_mask, gfp_t gfp_mask,
573 int (*callback)(int status,
574 struct ib_sa_multicast *multicast),
575 void *context)
576{
577 struct mcast_device *dev;
578 struct mcast_member *member;
579 struct ib_sa_multicast *multicast;
580 int ret;
581
582 dev = ib_get_client_data(device, &mcast_client);
583 if (!dev)
584 return ERR_PTR(-ENODEV);
585
586 member = kmalloc(sizeof *member, gfp_mask);
587 if (!member)
588 return ERR_PTR(-ENOMEM);
589
590 ib_sa_client_get(client);
591 member->client = client;
592 member->multicast.rec = *rec;
593 member->multicast.comp_mask = comp_mask;
594 member->multicast.callback = callback;
595 member->multicast.context = context;
596 init_completion(&member->comp);
597 atomic_set(&member->refcount, 1);
598 member->state = MCAST_JOINING;
599
600 member->group = acquire_group(&dev->port[port_num - dev->start_port],
601 &rec->mgid, gfp_mask);
602 if (!member->group) {
603 ret = -ENOMEM;
604 goto err;
605 }
606
607 /*
608 * The user will get the multicast structure in their callback. They
609 * could then free the multicast structure before we can return from
610 * this routine. So we save the pointer to return before queuing
611 * any callback.
612 */
613 multicast = &member->multicast;
614 queue_join(member);
615 return multicast;
616
617err:
618 ib_sa_client_put(client);
619 kfree(member);
620 return ERR_PTR(ret);
621}
622EXPORT_SYMBOL(ib_sa_join_multicast);
623
624void ib_sa_free_multicast(struct ib_sa_multicast *multicast)
625{
626 struct mcast_member *member;
627 struct mcast_group *group;
628
629 member = container_of(multicast, struct mcast_member, multicast);
630 group = member->group;
631
632 spin_lock_irq(&group->lock);
633 if (member->state == MCAST_MEMBER)
634 adjust_membership(group, multicast->rec.join_state, -1);
635
636 list_del_init(&member->list);
637
638 if (group->state == MCAST_IDLE) {
639 group->state = MCAST_BUSY;
640 spin_unlock_irq(&group->lock);
641 /* Continue to hold reference on group until callback */
642 queue_work(mcast_wq, &group->work);
643 } else {
644 spin_unlock_irq(&group->lock);
645 release_group(group);
646 }
647
648 deref_member(member);
649 wait_for_completion(&member->comp);
650 ib_sa_client_put(member->client);
651 kfree(member);
652}
653EXPORT_SYMBOL(ib_sa_free_multicast);
654
655int ib_sa_get_mcmember_rec(struct ib_device *device, u8 port_num,
656 union ib_gid *mgid, struct ib_sa_mcmember_rec *rec)
657{
658 struct mcast_device *dev;
659 struct mcast_port *port;
660 struct mcast_group *group;
661 unsigned long flags;
662 int ret = 0;
663
664 dev = ib_get_client_data(device, &mcast_client);
665 if (!dev)
666 return -ENODEV;
667
668 port = &dev->port[port_num - dev->start_port];
669 spin_lock_irqsave(&port->lock, flags);
670 group = mcast_find(port, mgid);
671 if (group)
672 *rec = group->rec;
673 else
674 ret = -EADDRNOTAVAIL;
675 spin_unlock_irqrestore(&port->lock, flags);
676
677 return ret;
678}
679EXPORT_SYMBOL(ib_sa_get_mcmember_rec);
680
681int ib_init_ah_from_mcmember(struct ib_device *device, u8 port_num,
682 struct ib_sa_mcmember_rec *rec,
683 struct ib_ah_attr *ah_attr)
684{
685 int ret;
686 u16 gid_index;
687 u8 p;
688
689 ret = ib_find_cached_gid(device, &rec->port_gid, &p, &gid_index);
690 if (ret)
691 return ret;
692
693 memset(ah_attr, 0, sizeof *ah_attr);
694 ah_attr->dlid = be16_to_cpu(rec->mlid);
695 ah_attr->sl = rec->sl;
696 ah_attr->port_num = port_num;
697 ah_attr->static_rate = rec->rate;
698
699 ah_attr->ah_flags = IB_AH_GRH;
700 ah_attr->grh.dgid = rec->mgid;
701
702 ah_attr->grh.sgid_index = (u8) gid_index;
703 ah_attr->grh.flow_label = be32_to_cpu(rec->flow_label);
704 ah_attr->grh.hop_limit = rec->hop_limit;
705 ah_attr->grh.traffic_class = rec->traffic_class;
706
707 return 0;
708}
709EXPORT_SYMBOL(ib_init_ah_from_mcmember);
710
711static void mcast_groups_lost(struct mcast_port *port)
712{
713 struct mcast_group *group;
714 struct rb_node *node;
715 unsigned long flags;
716
717 spin_lock_irqsave(&port->lock, flags);
718 for (node = rb_first(&port->table); node; node = rb_next(node)) {
719 group = rb_entry(node, struct mcast_group, node);
720 spin_lock(&group->lock);
721 if (group->state == MCAST_IDLE) {
722 atomic_inc(&group->refcount);
723 queue_work(mcast_wq, &group->work);
724 }
725 group->state = MCAST_ERROR;
726 spin_unlock(&group->lock);
727 }
728 spin_unlock_irqrestore(&port->lock, flags);
729}
730
731static void mcast_event_handler(struct ib_event_handler *handler,
732 struct ib_event *event)
733{
734 struct mcast_device *dev;
735
736 dev = container_of(handler, struct mcast_device, event_handler);
737
738 switch (event->event) {
739 case IB_EVENT_PORT_ERR:
740 case IB_EVENT_LID_CHANGE:
741 case IB_EVENT_SM_CHANGE:
742 case IB_EVENT_CLIENT_REREGISTER:
743 mcast_groups_lost(&dev->port[event->element.port_num -
744 dev->start_port]);
745 break;
746 default:
747 break;
748 }
749}
750
751static void mcast_add_one(struct ib_device *device)
752{
753 struct mcast_device *dev;
754 struct mcast_port *port;
755 int i;
756
757 if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
758 return;
759
760 dev = kmalloc(sizeof *dev + device->phys_port_cnt * sizeof *port,
761 GFP_KERNEL);
762 if (!dev)
763 return;
764
765 if (device->node_type == RDMA_NODE_IB_SWITCH)
766 dev->start_port = dev->end_port = 0;
767 else {
768 dev->start_port = 1;
769 dev->end_port = device->phys_port_cnt;
770 }
771
772 for (i = 0; i <= dev->end_port - dev->start_port; i++) {
773 port = &dev->port[i];
774 port->dev = dev;
775 port->port_num = dev->start_port + i;
776 spin_lock_init(&port->lock);
777 port->table = RB_ROOT;
778 init_completion(&port->comp);
779 atomic_set(&port->refcount, 1);
780 }
781
782 dev->device = device;
783 ib_set_client_data(device, &mcast_client, dev);
784
785 INIT_IB_EVENT_HANDLER(&dev->event_handler, device, mcast_event_handler);
786 ib_register_event_handler(&dev->event_handler);
787}
788
789static void mcast_remove_one(struct ib_device *device)
790{
791 struct mcast_device *dev;
792 struct mcast_port *port;
793 int i;
794
795 dev = ib_get_client_data(device, &mcast_client);
796 if (!dev)
797 return;
798
799 ib_unregister_event_handler(&dev->event_handler);
800 flush_workqueue(mcast_wq);
801
802 for (i = 0; i <= dev->end_port - dev->start_port; i++) {
803 port = &dev->port[i];
804 deref_port(port);
805 wait_for_completion(&port->comp);
806 }
807
808 kfree(dev);
809}
810
811int mcast_init(void)
812{
813 int ret;
814
815 mcast_wq = create_singlethread_workqueue("ib_mcast");
816 if (!mcast_wq)
817 return -ENOMEM;
818
819 ib_sa_register_client(&sa_client);
820
821 ret = ib_register_client(&mcast_client);
822 if (ret)
823 goto err;
824 return 0;
825
826err:
827 ib_sa_unregister_client(&sa_client);
828 destroy_workqueue(mcast_wq);
829 return ret;
830}
831
832void mcast_cleanup(void)
833{
834 ib_unregister_client(&mcast_client);
835 ib_sa_unregister_client(&sa_client);
836 destroy_workqueue(mcast_wq);
837}
diff --git a/drivers/infiniband/core/sa.h b/drivers/infiniband/core/sa.h
new file mode 100644
index 0000000000..24c93fd320
--- /dev/null
+++ b/drivers/infiniband/core/sa.h
@@ -0,0 +1,66 @@
1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Voltaire, Inc.  All rights reserved.
4 * Copyright (c) 2006 Intel Corporation. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35#ifndef SA_H
36#define SA_H
37
38#include <rdma/ib_sa.h>
39
40static inline void ib_sa_client_get(struct ib_sa_client *client)
41{
42 atomic_inc(&client->users);
43}
44
45static inline void ib_sa_client_put(struct ib_sa_client *client)
46{
47 if (atomic_dec_and_test(&client->users))
48 complete(&client->comp);
49}
50
51int ib_sa_mcmember_rec_query(struct ib_sa_client *client,
52 struct ib_device *device, u8 port_num,
53 u8 method,
54 struct ib_sa_mcmember_rec *rec,
55 ib_sa_comp_mask comp_mask,
56 int timeout_ms, gfp_t gfp_mask,
57 void (*callback)(int status,
58 struct ib_sa_mcmember_rec *resp,
59 void *context),
60 void *context,
61 struct ib_sa_query **sa_query);
62
63int mcast_init(void);
64void mcast_cleanup(void);
65
66#endif /* SA_H */
diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
index e45afba753..68db633711 100644
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -47,8 +47,8 @@
47#include <linux/workqueue.h> 47#include <linux/workqueue.h>
48 48
49#include <rdma/ib_pack.h> 49#include <rdma/ib_pack.h>
50#include <rdma/ib_sa.h>
51#include <rdma/ib_cache.h> 50#include <rdma/ib_cache.h>
51#include "sa.h"
52 52
53MODULE_AUTHOR("Roland Dreier"); 53MODULE_AUTHOR("Roland Dreier");
54MODULE_DESCRIPTION("InfiniBand subnet administration query support"); 54MODULE_DESCRIPTION("InfiniBand subnet administration query support");
@@ -425,17 +425,6 @@ void ib_sa_register_client(struct ib_sa_client *client)
425} 425}
426EXPORT_SYMBOL(ib_sa_register_client); 426EXPORT_SYMBOL(ib_sa_register_client);
427 427
428static inline void ib_sa_client_get(struct ib_sa_client *client)
429{
430 atomic_inc(&client->users);
431}
432
433static inline void ib_sa_client_put(struct ib_sa_client *client)
434{
435 if (atomic_dec_and_test(&client->users))
436 complete(&client->comp);
437}
438
439void ib_sa_unregister_client(struct ib_sa_client *client) 428void ib_sa_unregister_client(struct ib_sa_client *client)
440{ 429{
441 ib_sa_client_put(client); 430 ib_sa_client_put(client);
@@ -482,6 +471,7 @@ int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
482 ah_attr->sl = rec->sl; 471 ah_attr->sl = rec->sl;
483 ah_attr->src_path_bits = be16_to_cpu(rec->slid) & 0x7f; 472 ah_attr->src_path_bits = be16_to_cpu(rec->slid) & 0x7f;
484 ah_attr->port_num = port_num; 473 ah_attr->port_num = port_num;
474 ah_attr->static_rate = rec->rate;
485 475
486 if (rec->hop_limit > 1) { 476 if (rec->hop_limit > 1) {
487 ah_attr->ah_flags = IB_AH_GRH; 477 ah_attr->ah_flags = IB_AH_GRH;
@@ -901,7 +891,6 @@ err1:
901 kfree(query); 891 kfree(query);
902 return ret; 892 return ret;
903} 893}
904EXPORT_SYMBOL(ib_sa_mcmember_rec_query);
905 894
906static void send_handler(struct ib_mad_agent *agent, 895static void send_handler(struct ib_mad_agent *agent,
907 struct ib_mad_send_wc *mad_send_wc) 896 struct ib_mad_send_wc *mad_send_wc)
@@ -1053,14 +1042,27 @@ static int __init ib_sa_init(void)
1053 get_random_bytes(&tid, sizeof tid); 1042 get_random_bytes(&tid, sizeof tid);
1054 1043
1055 ret = ib_register_client(&sa_client); 1044 ret = ib_register_client(&sa_client);
1056 if (ret) 1045 if (ret) {
1057 printk(KERN_ERR "Couldn't register ib_sa client\n"); 1046 printk(KERN_ERR "Couldn't register ib_sa client\n");
1047 goto err1;
1048 }
1049
1050 ret = mcast_init();
1051 if (ret) {
1052 printk(KERN_ERR "Couldn't initialize multicast handling\n");
1053 goto err2;
1054 }
1058 1055
1056 return 0;
1057err2:
1058 ib_unregister_client(&sa_client);
1059err1:
1059 return ret; 1060 return ret;
1060} 1061}
1061 1062
1062static void __exit ib_sa_cleanup(void) 1063static void __exit ib_sa_cleanup(void)
1063{ 1064{
1065 mcast_cleanup();
1064 ib_unregister_client(&sa_client); 1066 ib_unregister_client(&sa_client);
1065 idr_destroy(&query_idr); 1067 idr_destroy(&query_idr);
1066} 1068}
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 709323c14c..000c086bf2 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -714,8 +714,6 @@ int ib_device_register_sysfs(struct ib_device *device)
714 if (ret) 714 if (ret)
715 goto err_put; 715 goto err_put;
716 } else { 716 } else {
717 int i;
718
719 for (i = 1; i <= device->phys_port_cnt; ++i) { 717 for (i = 1; i <= device->phys_port_cnt; ++i) {
720 ret = add_port(device, i); 718 ret = add_port(device, i);
721 if (ret) 719 if (ret)
diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index 6b81b98961..c859134c1d 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -70,10 +70,24 @@ struct ucma_context {
70 u64 uid; 70 u64 uid;
71 71
72 struct list_head list; 72 struct list_head list;
73 struct list_head mc_list;
74};
75
76struct ucma_multicast {
77 struct ucma_context *ctx;
78 int id;
79 int events_reported;
80
81 u64 uid;
82 struct list_head list;
83 struct sockaddr addr;
84 u8 pad[sizeof(struct sockaddr_in6) -
85 sizeof(struct sockaddr)];
73}; 86};
74 87
75struct ucma_event { 88struct ucma_event {
76 struct ucma_context *ctx; 89 struct ucma_context *ctx;
90 struct ucma_multicast *mc;
77 struct list_head list; 91 struct list_head list;
78 struct rdma_cm_id *cm_id; 92 struct rdma_cm_id *cm_id;
79 struct rdma_ucm_event_resp resp; 93 struct rdma_ucm_event_resp resp;
@@ -81,6 +95,7 @@ struct ucma_event {
81 95
82static DEFINE_MUTEX(mut); 96static DEFINE_MUTEX(mut);
83static DEFINE_IDR(ctx_idr); 97static DEFINE_IDR(ctx_idr);
98static DEFINE_IDR(multicast_idr);
84 99
85static inline struct ucma_context *_ucma_find_context(int id, 100static inline struct ucma_context *_ucma_find_context(int id,
86 struct ucma_file *file) 101 struct ucma_file *file)
@@ -124,6 +139,7 @@ static struct ucma_context *ucma_alloc_ctx(struct ucma_file *file)
124 139
125 atomic_set(&ctx->ref, 1); 140 atomic_set(&ctx->ref, 1);
126 init_completion(&ctx->comp); 141 init_completion(&ctx->comp);
142 INIT_LIST_HEAD(&ctx->mc_list);
127 ctx->file = file; 143 ctx->file = file;
128 144
129 do { 145 do {
@@ -147,6 +163,37 @@ error:
147 return NULL; 163 return NULL;
148} 164}
149 165
166static struct ucma_multicast* ucma_alloc_multicast(struct ucma_context *ctx)
167{
168 struct ucma_multicast *mc;
169 int ret;
170
171 mc = kzalloc(sizeof(*mc), GFP_KERNEL);
172 if (!mc)
173 return NULL;
174
175 do {
176 ret = idr_pre_get(&multicast_idr, GFP_KERNEL);
177 if (!ret)
178 goto error;
179
180 mutex_lock(&mut);
181 ret = idr_get_new(&multicast_idr, mc, &mc->id);
182 mutex_unlock(&mut);
183 } while (ret == -EAGAIN);
184
185 if (ret)
186 goto error;
187
188 mc->ctx = ctx;
189 list_add_tail(&mc->list, &ctx->mc_list);
190 return mc;
191
192error:
193 kfree(mc);
194 return NULL;
195}
196
150static void ucma_copy_conn_event(struct rdma_ucm_conn_param *dst, 197static void ucma_copy_conn_event(struct rdma_ucm_conn_param *dst,
151 struct rdma_conn_param *src) 198 struct rdma_conn_param *src)
152{ 199{
@@ -180,8 +227,19 @@ static void ucma_set_event_context(struct ucma_context *ctx,
180 struct ucma_event *uevent) 227 struct ucma_event *uevent)
181{ 228{
182 uevent->ctx = ctx; 229 uevent->ctx = ctx;
183 uevent->resp.uid = ctx->uid; 230 switch (event->event) {
184 uevent->resp.id = ctx->id; 231 case RDMA_CM_EVENT_MULTICAST_JOIN:
232 case RDMA_CM_EVENT_MULTICAST_ERROR:
233 uevent->mc = (struct ucma_multicast *)
234 event->param.ud.private_data;
235 uevent->resp.uid = uevent->mc->uid;
236 uevent->resp.id = uevent->mc->id;
237 break;
238 default:
239 uevent->resp.uid = ctx->uid;
240 uevent->resp.id = ctx->id;
241 break;
242 }
185} 243}
186 244
187static int ucma_event_handler(struct rdma_cm_id *cm_id, 245static int ucma_event_handler(struct rdma_cm_id *cm_id,
@@ -199,7 +257,7 @@ static int ucma_event_handler(struct rdma_cm_id *cm_id,
199 ucma_set_event_context(ctx, event, uevent); 257 ucma_set_event_context(ctx, event, uevent);
200 uevent->resp.event = event->event; 258 uevent->resp.event = event->event;
201 uevent->resp.status = event->status; 259 uevent->resp.status = event->status;
202 if (cm_id->ps == RDMA_PS_UDP) 260 if (cm_id->ps == RDMA_PS_UDP || cm_id->ps == RDMA_PS_IPOIB)
203 ucma_copy_ud_event(&uevent->resp.param.ud, &event->param.ud); 261 ucma_copy_ud_event(&uevent->resp.param.ud, &event->param.ud);
204 else 262 else
205 ucma_copy_conn_event(&uevent->resp.param.conn, 263 ucma_copy_conn_event(&uevent->resp.param.conn,
@@ -208,7 +266,7 @@ static int ucma_event_handler(struct rdma_cm_id *cm_id,
208 mutex_lock(&ctx->file->mut); 266 mutex_lock(&ctx->file->mut);
209 if (event->event == RDMA_CM_EVENT_CONNECT_REQUEST) { 267 if (event->event == RDMA_CM_EVENT_CONNECT_REQUEST) {
210 if (!ctx->backlog) { 268 if (!ctx->backlog) {
211 ret = -EDQUOT; 269 ret = -ENOMEM;
212 kfree(uevent); 270 kfree(uevent);
213 goto out; 271 goto out;
214 } 272 }
@@ -290,6 +348,8 @@ static ssize_t ucma_get_event(struct ucma_file *file, const char __user *inbuf,
290 348
291 list_del(&uevent->list); 349 list_del(&uevent->list);
292 uevent->ctx->events_reported++; 350 uevent->ctx->events_reported++;
351 if (uevent->mc)
352 uevent->mc->events_reported++;
293 kfree(uevent); 353 kfree(uevent);
294done: 354done:
295 mutex_unlock(&file->mut); 355 mutex_unlock(&file->mut);
@@ -342,6 +402,19 @@ err1:
342 return ret; 402 return ret;
343} 403}
344 404
405static void ucma_cleanup_multicast(struct ucma_context *ctx)
406{
407 struct ucma_multicast *mc, *tmp;
408
409 mutex_lock(&mut);
410 list_for_each_entry_safe(mc, tmp, &ctx->mc_list, list) {
411 list_del(&mc->list);
412 idr_remove(&multicast_idr, mc->id);
413 kfree(mc);
414 }
415 mutex_unlock(&mut);
416}
417
345static void ucma_cleanup_events(struct ucma_context *ctx) 418static void ucma_cleanup_events(struct ucma_context *ctx)
346{ 419{
347 struct ucma_event *uevent, *tmp; 420 struct ucma_event *uevent, *tmp;
@@ -360,6 +433,19 @@ static void ucma_cleanup_events(struct ucma_context *ctx)
360 } 433 }
361} 434}
362 435
436static void ucma_cleanup_mc_events(struct ucma_multicast *mc)
437{
438 struct ucma_event *uevent, *tmp;
439
440 list_for_each_entry_safe(uevent, tmp, &mc->ctx->file->event_list, list) {
441 if (uevent->mc != mc)
442 continue;
443
444 list_del(&uevent->list);
445 kfree(uevent);
446 }
447}
448
363static int ucma_free_ctx(struct ucma_context *ctx) 449static int ucma_free_ctx(struct ucma_context *ctx)
364{ 450{
365 int events_reported; 451 int events_reported;
@@ -367,6 +453,8 @@ static int ucma_free_ctx(struct ucma_context *ctx)
367 /* No new events will be generated after destroying the id. */ 453 /* No new events will be generated after destroying the id. */
368 rdma_destroy_id(ctx->cm_id); 454 rdma_destroy_id(ctx->cm_id);
369 455
456 ucma_cleanup_multicast(ctx);
457
370 /* Cleanup events not yet reported to the user. */ 458 /* Cleanup events not yet reported to the user. */
371 mutex_lock(&ctx->file->mut); 459 mutex_lock(&ctx->file->mut);
372 ucma_cleanup_events(ctx); 460 ucma_cleanup_events(ctx);
@@ -731,6 +819,114 @@ static ssize_t ucma_notify(struct ucma_file *file, const char __user *inbuf,
731 return ret; 819 return ret;
732} 820}
733 821
822static ssize_t ucma_join_multicast(struct ucma_file *file,
823 const char __user *inbuf,
824 int in_len, int out_len)
825{
826 struct rdma_ucm_join_mcast cmd;
827 struct rdma_ucm_create_id_resp resp;
828 struct ucma_context *ctx;
829 struct ucma_multicast *mc;
830 int ret;
831
832 if (out_len < sizeof(resp))
833 return -ENOSPC;
834
835 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
836 return -EFAULT;
837
838 ctx = ucma_get_ctx(file, cmd.id);
839 if (IS_ERR(ctx))
840 return PTR_ERR(ctx);
841
842 mutex_lock(&file->mut);
843 mc = ucma_alloc_multicast(ctx);
844 if (IS_ERR(mc)) {
845 ret = PTR_ERR(mc);
846 goto err1;
847 }
848
849 mc->uid = cmd.uid;
850 memcpy(&mc->addr, &cmd.addr, sizeof cmd.addr);
851 ret = rdma_join_multicast(ctx->cm_id, &mc->addr, mc);
852 if (ret)
853 goto err2;
854
855 resp.id = mc->id;
856 if (copy_to_user((void __user *)(unsigned long)cmd.response,
857 &resp, sizeof(resp))) {
858 ret = -EFAULT;
859 goto err3;
860 }
861
862 mutex_unlock(&file->mut);
863 ucma_put_ctx(ctx);
864 return 0;
865
866err3:
867 rdma_leave_multicast(ctx->cm_id, &mc->addr);
868 ucma_cleanup_mc_events(mc);
869err2:
870 mutex_lock(&mut);
871 idr_remove(&multicast_idr, mc->id);
872 mutex_unlock(&mut);
873 list_del(&mc->list);
874 kfree(mc);
875err1:
876 mutex_unlock(&file->mut);
877 ucma_put_ctx(ctx);
878 return ret;
879}
880
881static ssize_t ucma_leave_multicast(struct ucma_file *file,
882 const char __user *inbuf,
883 int in_len, int out_len)
884{
885 struct rdma_ucm_destroy_id cmd;
886 struct rdma_ucm_destroy_id_resp resp;
887 struct ucma_multicast *mc;
888 int ret = 0;
889
890 if (out_len < sizeof(resp))
891 return -ENOSPC;
892
893 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
894 return -EFAULT;
895
896 mutex_lock(&mut);
897 mc = idr_find(&multicast_idr, cmd.id);
898 if (!mc)
899 mc = ERR_PTR(-ENOENT);
900 else if (mc->ctx->file != file)
901 mc = ERR_PTR(-EINVAL);
902 else {
903 idr_remove(&multicast_idr, mc->id);
904 atomic_inc(&mc->ctx->ref);
905 }
906 mutex_unlock(&mut);
907
908 if (IS_ERR(mc)) {
909 ret = PTR_ERR(mc);
910 goto out;
911 }
912
913 rdma_leave_multicast(mc->ctx->cm_id, &mc->addr);
914 mutex_lock(&mc->ctx->file->mut);
915 ucma_cleanup_mc_events(mc);
916 list_del(&mc->list);
917 mutex_unlock(&mc->ctx->file->mut);
918
919 ucma_put_ctx(mc->ctx);
920 resp.events_reported = mc->events_reported;
921 kfree(mc);
922
923 if (copy_to_user((void __user *)(unsigned long)cmd.response,
924 &resp, sizeof(resp)))
925 ret = -EFAULT;
926out:
927 return ret;
928}
929
734static ssize_t (*ucma_cmd_table[])(struct ucma_file *file, 930static ssize_t (*ucma_cmd_table[])(struct ucma_file *file,
735 const char __user *inbuf, 931 const char __user *inbuf,
736 int in_len, int out_len) = { 932 int in_len, int out_len) = {
@@ -750,6 +946,8 @@ static ssize_t (*ucma_cmd_table[])(struct ucma_file *file,
750 [RDMA_USER_CM_CMD_GET_OPTION] = NULL, 946 [RDMA_USER_CM_CMD_GET_OPTION] = NULL,
751 [RDMA_USER_CM_CMD_SET_OPTION] = NULL, 947 [RDMA_USER_CM_CMD_SET_OPTION] = NULL,
752 [RDMA_USER_CM_CMD_NOTIFY] = ucma_notify, 948 [RDMA_USER_CM_CMD_NOTIFY] = ucma_notify,
949 [RDMA_USER_CM_CMD_JOIN_MCAST] = ucma_join_multicast,
950 [RDMA_USER_CM_CMD_LEAVE_MCAST] = ucma_leave_multicast,
753}; 951};
754 952
755static ssize_t ucma_write(struct file *filp, const char __user *buf, 953static ssize_t ucma_write(struct file *filp, const char __user *buf,
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index df1efbc108..4fd75afa6a 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -622,8 +622,10 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
622 obj->umem.virt_base = cmd.hca_va; 622 obj->umem.virt_base = cmd.hca_va;
623 623
624 pd = idr_read_pd(cmd.pd_handle, file->ucontext); 624 pd = idr_read_pd(cmd.pd_handle, file->ucontext);
625 if (!pd) 625 if (!pd) {
626 ret = -EINVAL;
626 goto err_release; 627 goto err_release;
628 }
627 629
628 mr = pd->device->reg_user_mr(pd, &obj->umem, cmd.access_flags, &udata); 630 mr = pd->device->reg_user_mr(pd, &obj->umem, cmd.access_flags, &udata);
629 if (IS_ERR(mr)) { 631 if (IS_ERR(mr)) {
diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index 8b5dd3649b..ccdf93d30b 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -167,7 +167,7 @@ int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc,
167 ah_attr->grh.sgid_index = (u8) gid_index; 167 ah_attr->grh.sgid_index = (u8) gid_index;
168 flow_class = be32_to_cpu(grh->version_tclass_flow); 168 flow_class = be32_to_cpu(grh->version_tclass_flow);
169 ah_attr->grh.flow_label = flow_class & 0xFFFFF; 169 ah_attr->grh.flow_label = flow_class & 0xFFFFF;
170 ah_attr->grh.hop_limit = grh->hop_limit; 170 ah_attr->grh.hop_limit = 0xFF;
171 ah_attr->grh.traffic_class = (flow_class >> 20) & 0xFF; 171 ah_attr->grh.traffic_class = (flow_class >> 20) & 0xFF;
172 } 172 }
173 return 0; 173 return 0;
diff --git a/drivers/infiniband/hw/cxgb3/Makefile b/drivers/infiniband/hw/cxgb3/Makefile
index 0e110f32f1..36b98989b1 100644
--- a/drivers/infiniband/hw/cxgb3/Makefile
+++ b/drivers/infiniband/hw/cxgb3/Makefile
@@ -8,5 +8,4 @@ iw_cxgb3-y := iwch_cm.o iwch_ev.o iwch_cq.o iwch_qp.o iwch_mem.o \
8 8
9ifdef CONFIG_INFINIBAND_CXGB3_DEBUG 9ifdef CONFIG_INFINIBAND_CXGB3_DEBUG
10EXTRA_CFLAGS += -DDEBUG 10EXTRA_CFLAGS += -DDEBUG
11iw_cxgb3-y += cxio_dbg.o
12endif 11endif
diff --git a/drivers/infiniband/hw/cxgb3/cxio_dbg.c b/drivers/infiniband/hw/cxgb3/cxio_dbg.c
index 5a7306f5ef..75f7b16a27 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_dbg.c
+++ b/drivers/infiniband/hw/cxgb3/cxio_dbg.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/cxio_hal.c b/drivers/infiniband/hw/cxgb3/cxio_hal.c
index 82fa720419..818cf1aee8 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_hal.c
+++ b/drivers/infiniband/hw/cxgb3/cxio_hal.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
@@ -37,6 +36,7 @@
37#include <linux/sched.h> 36#include <linux/sched.h>
38#include <linux/spinlock.h> 37#include <linux/spinlock.h>
39#include <linux/pci.h> 38#include <linux/pci.h>
39#include <linux/dma-mapping.h>
40 40
41#include "cxio_resource.h" 41#include "cxio_resource.h"
42#include "cxio_hal.h" 42#include "cxio_hal.h"
@@ -46,7 +46,7 @@
46static LIST_HEAD(rdev_list); 46static LIST_HEAD(rdev_list);
47static cxio_hal_ev_callback_func_t cxio_ev_cb = NULL; 47static cxio_hal_ev_callback_func_t cxio_ev_cb = NULL;
48 48
49static inline struct cxio_rdev *cxio_hal_find_rdev_by_name(char *dev_name) 49static struct cxio_rdev *cxio_hal_find_rdev_by_name(char *dev_name)
50{ 50{
51 struct cxio_rdev *rdev; 51 struct cxio_rdev *rdev;
52 52
@@ -56,8 +56,7 @@ static inline struct cxio_rdev *cxio_hal_find_rdev_by_name(char *dev_name)
56 return NULL; 56 return NULL;
57} 57}
58 58
59static inline struct cxio_rdev *cxio_hal_find_rdev_by_t3cdev(struct t3cdev 59static struct cxio_rdev *cxio_hal_find_rdev_by_t3cdev(struct t3cdev *tdev)
60 *tdev)
61{ 60{
62 struct cxio_rdev *rdev; 61 struct cxio_rdev *rdev;
63 62
@@ -119,7 +118,7 @@ int cxio_hal_cq_op(struct cxio_rdev *rdev_p, struct t3_cq *cq,
119 return 0; 118 return 0;
120} 119}
121 120
122static inline int cxio_hal_clear_cq_ctx(struct cxio_rdev *rdev_p, u32 cqid) 121static int cxio_hal_clear_cq_ctx(struct cxio_rdev *rdev_p, u32 cqid)
123{ 122{
124 struct rdma_cq_setup setup; 123 struct rdma_cq_setup setup;
125 setup.id = cqid; 124 setup.id = cqid;
@@ -131,7 +130,7 @@ static inline int cxio_hal_clear_cq_ctx(struct cxio_rdev *rdev_p, u32 cqid)
131 return (rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, RDMA_CQ_SETUP, &setup)); 130 return (rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, RDMA_CQ_SETUP, &setup));
132} 131}
133 132
134int cxio_hal_clear_qp_ctx(struct cxio_rdev *rdev_p, u32 qpid) 133static int cxio_hal_clear_qp_ctx(struct cxio_rdev *rdev_p, u32 qpid)
135{ 134{
136 u64 sge_cmd; 135 u64 sge_cmd;
137 struct t3_modify_qp_wr *wqe; 136 struct t3_modify_qp_wr *wqe;
@@ -426,7 +425,7 @@ void cxio_flush_hw_cq(struct t3_cq *cq)
426 } 425 }
427} 426}
428 427
429static inline int cqe_completes_wr(struct t3_cqe *cqe, struct t3_wq *wq) 428static int cqe_completes_wr(struct t3_cqe *cqe, struct t3_wq *wq)
430{ 429{
431 if (CQE_OPCODE(*cqe) == T3_TERMINATE) 430 if (CQE_OPCODE(*cqe) == T3_TERMINATE)
432 return 0; 431 return 0;
@@ -761,17 +760,6 @@ ret:
761 return err; 760 return err;
762} 761}
763 762
764/* IN : stag key, pdid, pbl_size
765 * Out: stag index, actaul pbl_size, and pbl_addr allocated.
766 */
767int cxio_allocate_stag(struct cxio_rdev *rdev_p, u32 * stag, u32 pdid,
768 enum tpt_mem_perm perm, u32 * pbl_size, u32 * pbl_addr)
769{
770 *stag = T3_STAG_UNSET;
771 return (__cxio_tpt_op(rdev_p, 0, stag, 0, pdid, TPT_NON_SHARED_MR,
772 perm, 0, 0ULL, 0, 0, NULL, pbl_size, pbl_addr));
773}
774
775int cxio_register_phys_mem(struct cxio_rdev *rdev_p, u32 *stag, u32 pdid, 763int cxio_register_phys_mem(struct cxio_rdev *rdev_p, u32 *stag, u32 pdid,
776 enum tpt_mem_perm perm, u32 zbva, u64 to, u32 len, 764 enum tpt_mem_perm perm, u32 zbva, u64 to, u32 len,
777 u8 page_size, __be64 *pbl, u32 *pbl_size, 765 u8 page_size, __be64 *pbl, u32 *pbl_size,
@@ -1030,7 +1018,7 @@ void __exit cxio_hal_exit(void)
1030 cxio_hal_destroy_rhdl_resource(); 1018 cxio_hal_destroy_rhdl_resource();
1031} 1019}
1032 1020
1033static inline void flush_completed_wrs(struct t3_wq *wq, struct t3_cq *cq) 1021static void flush_completed_wrs(struct t3_wq *wq, struct t3_cq *cq)
1034{ 1022{
1035 struct t3_swsq *sqp; 1023 struct t3_swsq *sqp;
1036 __u32 ptr = wq->sq_rptr; 1024 __u32 ptr = wq->sq_rptr;
@@ -1059,9 +1047,8 @@ static inline void flush_completed_wrs(struct t3_wq *wq, struct t3_cq *cq)
1059 break; 1047 break;
1060} 1048}
1061 1049
1062static inline void create_read_req_cqe(struct t3_wq *wq, 1050static void create_read_req_cqe(struct t3_wq *wq, struct t3_cqe *hw_cqe,
1063 struct t3_cqe *hw_cqe, 1051 struct t3_cqe *read_cqe)
1064 struct t3_cqe *read_cqe)
1065{ 1052{
1066 read_cqe->u.scqe.wrid_hi = wq->oldest_read->sq_wptr; 1053 read_cqe->u.scqe.wrid_hi = wq->oldest_read->sq_wptr;
1067 read_cqe->len = wq->oldest_read->read_len; 1054 read_cqe->len = wq->oldest_read->read_len;
@@ -1074,7 +1061,7 @@ static inline void create_read_req_cqe(struct t3_wq *wq,
1074/* 1061/*
1075 * Return a ptr to the next read wr in the SWSQ or NULL. 1062 * Return a ptr to the next read wr in the SWSQ or NULL.
1076 */ 1063 */
1077static inline void advance_oldest_read(struct t3_wq *wq) 1064static void advance_oldest_read(struct t3_wq *wq)
1078{ 1065{
1079 1066
1080 u32 rptr = wq->oldest_read - wq->sq + 1; 1067 u32 rptr = wq->oldest_read - wq->sq + 1;
diff --git a/drivers/infiniband/hw/cxgb3/cxio_hal.h b/drivers/infiniband/hw/cxgb3/cxio_hal.h
index 1b97e80b87..99543d6347 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_hal.h
+++ b/drivers/infiniband/hw/cxgb3/cxio_hal.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
@@ -144,7 +143,6 @@ int cxio_rdev_open(struct cxio_rdev *rdev);
144void cxio_rdev_close(struct cxio_rdev *rdev); 143void cxio_rdev_close(struct cxio_rdev *rdev);
145int cxio_hal_cq_op(struct cxio_rdev *rdev, struct t3_cq *cq, 144int cxio_hal_cq_op(struct cxio_rdev *rdev, struct t3_cq *cq,
146 enum t3_cq_opcode op, u32 credit); 145 enum t3_cq_opcode op, u32 credit);
147int cxio_hal_clear_qp_ctx(struct cxio_rdev *rdev, u32 qpid);
148int cxio_create_cq(struct cxio_rdev *rdev, struct t3_cq *cq); 146int cxio_create_cq(struct cxio_rdev *rdev, struct t3_cq *cq);
149int cxio_destroy_cq(struct cxio_rdev *rdev, struct t3_cq *cq); 147int cxio_destroy_cq(struct cxio_rdev *rdev, struct t3_cq *cq);
150int cxio_resize_cq(struct cxio_rdev *rdev, struct t3_cq *cq); 148int cxio_resize_cq(struct cxio_rdev *rdev, struct t3_cq *cq);
@@ -155,8 +153,6 @@ int cxio_create_qp(struct cxio_rdev *rdev, u32 kernel_domain, struct t3_wq *wq,
155int cxio_destroy_qp(struct cxio_rdev *rdev, struct t3_wq *wq, 153int cxio_destroy_qp(struct cxio_rdev *rdev, struct t3_wq *wq,
156 struct cxio_ucontext *uctx); 154 struct cxio_ucontext *uctx);
157int cxio_peek_cq(struct t3_wq *wr, struct t3_cq *cq, int opcode); 155int cxio_peek_cq(struct t3_wq *wr, struct t3_cq *cq, int opcode);
158int cxio_allocate_stag(struct cxio_rdev *rdev, u32 * stag, u32 pdid,
159 enum tpt_mem_perm perm, u32 * pbl_size, u32 * pbl_addr);
160int cxio_register_phys_mem(struct cxio_rdev *rdev, u32 * stag, u32 pdid, 156int cxio_register_phys_mem(struct cxio_rdev *rdev, u32 * stag, u32 pdid,
161 enum tpt_mem_perm perm, u32 zbva, u64 to, u32 len, 157 enum tpt_mem_perm perm, u32 zbva, u64 to, u32 len,
162 u8 page_size, __be64 *pbl, u32 *pbl_size, 158 u8 page_size, __be64 *pbl, u32 *pbl_size,
@@ -172,8 +168,6 @@ int cxio_deallocate_window(struct cxio_rdev *rdev, u32 stag);
172int cxio_rdma_init(struct cxio_rdev *rdev, struct t3_rdma_init_attr *attr); 168int cxio_rdma_init(struct cxio_rdev *rdev, struct t3_rdma_init_attr *attr);
173void cxio_register_ev_cb(cxio_hal_ev_callback_func_t ev_cb); 169void cxio_register_ev_cb(cxio_hal_ev_callback_func_t ev_cb);
174void cxio_unregister_ev_cb(cxio_hal_ev_callback_func_t ev_cb); 170void cxio_unregister_ev_cb(cxio_hal_ev_callback_func_t ev_cb);
175u32 cxio_hal_get_rhdl(void);
176void cxio_hal_put_rhdl(u32 rhdl);
177u32 cxio_hal_get_pdid(struct cxio_hal_resource *rscp); 171u32 cxio_hal_get_pdid(struct cxio_hal_resource *rscp);
178void cxio_hal_put_pdid(struct cxio_hal_resource *rscp, u32 pdid); 172void cxio_hal_put_pdid(struct cxio_hal_resource *rscp, u32 pdid);
179int __init cxio_hal_init(void); 173int __init cxio_hal_init(void);
diff --git a/drivers/infiniband/hw/cxgb3/cxio_resource.c b/drivers/infiniband/hw/cxgb3/cxio_resource.c
index 997aa32cbf..d3095ae5bc 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_resource.c
+++ b/drivers/infiniband/hw/cxgb3/cxio_resource.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
@@ -180,7 +179,7 @@ tpt_err:
180/* 179/*
181 * returns 0 if no resource available 180 * returns 0 if no resource available
182 */ 181 */
183static inline u32 cxio_hal_get_resource(struct kfifo *fifo) 182static u32 cxio_hal_get_resource(struct kfifo *fifo)
184{ 183{
185 u32 entry; 184 u32 entry;
186 if (kfifo_get(fifo, (unsigned char *) &entry, sizeof(u32))) 185 if (kfifo_get(fifo, (unsigned char *) &entry, sizeof(u32)))
@@ -189,21 +188,11 @@ static inline u32 cxio_hal_get_resource(struct kfifo *fifo)
189 return 0; /* fifo emptry */ 188 return 0; /* fifo emptry */
190} 189}
191 190
192static inline void cxio_hal_put_resource(struct kfifo *fifo, u32 entry) 191static void cxio_hal_put_resource(struct kfifo *fifo, u32 entry)
193{ 192{
194 BUG_ON(kfifo_put(fifo, (unsigned char *) &entry, sizeof(u32)) == 0); 193 BUG_ON(kfifo_put(fifo, (unsigned char *) &entry, sizeof(u32)) == 0);
195} 194}
196 195
197u32 cxio_hal_get_rhdl(void)
198{
199 return cxio_hal_get_resource(rhdl_fifo);
200}
201
202void cxio_hal_put_rhdl(u32 rhdl)
203{
204 cxio_hal_put_resource(rhdl_fifo, rhdl);
205}
206
207u32 cxio_hal_get_stag(struct cxio_hal_resource *rscp) 196u32 cxio_hal_get_stag(struct cxio_hal_resource *rscp)
208{ 197{
209 return cxio_hal_get_resource(rscp->tpt_fifo); 198 return cxio_hal_get_resource(rscp->tpt_fifo);
diff --git a/drivers/infiniband/hw/cxgb3/cxio_resource.h b/drivers/infiniband/hw/cxgb3/cxio_resource.h
index a6bbe8370d..a2703a3d88 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_resource.h
+++ b/drivers/infiniband/hw/cxgb3/cxio_resource.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/cxio_wr.h b/drivers/infiniband/hw/cxgb3/cxio_wr.h
index 103fc42d69..90d7b8972c 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_wr.h
+++ b/drivers/infiniband/hw/cxgb3/cxio_wr.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch.c b/drivers/infiniband/hw/cxgb3/iwch.c
index 4611afa522..0315c9d9fc 100644
--- a/drivers/infiniband/hw/cxgb3/iwch.c
+++ b/drivers/infiniband/hw/cxgb3/iwch.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch.h b/drivers/infiniband/hw/cxgb3/iwch.h
index 6517ef8502..caf4e6007a 100644
--- a/drivers/infiniband/hw/cxgb3/iwch.h
+++ b/drivers/infiniband/hw/cxgb3/iwch.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_cm.c b/drivers/infiniband/hw/cxgb3/iwch_cm.c
index a522b1baa3..d0ed1d35ca 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_cm.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_cm.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
@@ -210,8 +209,7 @@ static enum iwch_ep_state state_read(struct iwch_ep_common *epc)
210 return state; 209 return state;
211} 210}
212 211
213static inline void __state_set(struct iwch_ep_common *epc, 212static void __state_set(struct iwch_ep_common *epc, enum iwch_ep_state new)
214 enum iwch_ep_state new)
215{ 213{
216 epc->state = new; 214 epc->state = new;
217} 215}
@@ -307,8 +305,7 @@ static int status2errno(int status)
307 */ 305 */
308static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp) 306static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
309{ 307{
310 if (skb) { 308 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
311 BUG_ON(skb_cloned(skb));
312 skb_trim(skb, 0); 309 skb_trim(skb, 0);
313 skb_get(skb); 310 skb_get(skb);
314 } else { 311 } else {
@@ -1417,6 +1414,7 @@ static int peer_close(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1417 wake_up(&ep->com.waitq); 1414 wake_up(&ep->com.waitq);
1418 break; 1415 break;
1419 case FPDU_MODE: 1416 case FPDU_MODE:
1417 start_ep_timer(ep);
1420 __state_set(&ep->com, CLOSING); 1418 __state_set(&ep->com, CLOSING);
1421 attrs.next_state = IWCH_QP_STATE_CLOSING; 1419 attrs.next_state = IWCH_QP_STATE_CLOSING;
1422 iwch_modify_qp(ep->com.qp->rhp, ep->com.qp, 1420 iwch_modify_qp(ep->com.qp->rhp, ep->com.qp,
@@ -1427,7 +1425,6 @@ static int peer_close(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1427 disconnect = 0; 1425 disconnect = 0;
1428 break; 1426 break;
1429 case CLOSING: 1427 case CLOSING:
1430 start_ep_timer(ep);
1431 __state_set(&ep->com, MORIBUND); 1428 __state_set(&ep->com, MORIBUND);
1432 disconnect = 0; 1429 disconnect = 0;
1433 break; 1430 break;
@@ -1460,7 +1457,7 @@ static int peer_close(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1460/* 1457/*
1461 * Returns whether an ABORT_REQ_RSS message is a negative advice. 1458 * Returns whether an ABORT_REQ_RSS message is a negative advice.
1462 */ 1459 */
1463static inline int is_neg_adv_abort(unsigned int status) 1460static int is_neg_adv_abort(unsigned int status)
1464{ 1461{
1465 return status == CPL_ERR_RTX_NEG_ADVICE || 1462 return status == CPL_ERR_RTX_NEG_ADVICE ||
1466 status == CPL_ERR_PERSIST_NEG_ADVICE; 1463 status == CPL_ERR_PERSIST_NEG_ADVICE;
@@ -1489,8 +1486,10 @@ static int peer_abort(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1489 case CONNECTING: 1486 case CONNECTING:
1490 break; 1487 break;
1491 case MPA_REQ_WAIT: 1488 case MPA_REQ_WAIT:
1489 stop_ep_timer(ep);
1492 break; 1490 break;
1493 case MPA_REQ_SENT: 1491 case MPA_REQ_SENT:
1492 stop_ep_timer(ep);
1494 connect_reply_upcall(ep, -ECONNRESET); 1493 connect_reply_upcall(ep, -ECONNRESET);
1495 break; 1494 break;
1496 case MPA_REP_SENT: 1495 case MPA_REP_SENT:
@@ -1509,9 +1508,10 @@ static int peer_abort(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1509 get_ep(&ep->com); 1508 get_ep(&ep->com);
1510 break; 1509 break;
1511 case MORIBUND: 1510 case MORIBUND:
1511 case CLOSING:
1512 stop_ep_timer(ep); 1512 stop_ep_timer(ep);
1513 /*FALLTHROUGH*/
1513 case FPDU_MODE: 1514 case FPDU_MODE:
1514 case CLOSING:
1515 if (ep->com.cm_id && ep->com.qp) { 1515 if (ep->com.cm_id && ep->com.qp) {
1516 attrs.next_state = IWCH_QP_STATE_ERROR; 1516 attrs.next_state = IWCH_QP_STATE_ERROR;
1517 ret = iwch_modify_qp(ep->com.qp->rhp, 1517 ret = iwch_modify_qp(ep->com.qp->rhp,
@@ -1572,7 +1572,6 @@ static int close_con_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1572 spin_lock_irqsave(&ep->com.lock, flags); 1572 spin_lock_irqsave(&ep->com.lock, flags);
1573 switch (ep->com.state) { 1573 switch (ep->com.state) {
1574 case CLOSING: 1574 case CLOSING:
1575 start_ep_timer(ep);
1576 __state_set(&ep->com, MORIBUND); 1575 __state_set(&ep->com, MORIBUND);
1577 break; 1576 break;
1578 case MORIBUND: 1577 case MORIBUND:
@@ -1588,6 +1587,8 @@ static int close_con_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1588 __state_set(&ep->com, DEAD); 1587 __state_set(&ep->com, DEAD);
1589 release = 1; 1588 release = 1;
1590 break; 1589 break;
1590 case ABORTING:
1591 break;
1591 case DEAD: 1592 case DEAD:
1592 default: 1593 default:
1593 BUG_ON(1); 1594 BUG_ON(1);
@@ -1636,6 +1637,7 @@ static int ec_status(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1636 1637
1637 printk(KERN_ERR MOD "%s BAD CLOSE - Aborting tid %u\n", 1638 printk(KERN_ERR MOD "%s BAD CLOSE - Aborting tid %u\n",
1638 __FUNCTION__, ep->hwtid); 1639 __FUNCTION__, ep->hwtid);
1640 stop_ep_timer(ep);
1639 attrs.next_state = IWCH_QP_STATE_ERROR; 1641 attrs.next_state = IWCH_QP_STATE_ERROR;
1640 iwch_modify_qp(ep->com.qp->rhp, 1642 iwch_modify_qp(ep->com.qp->rhp,
1641 ep->com.qp, IWCH_QP_ATTR_NEXT_STATE, 1643 ep->com.qp, IWCH_QP_ATTR_NEXT_STATE,
@@ -1660,6 +1662,7 @@ static void ep_timeout(unsigned long arg)
1660 break; 1662 break;
1661 case MPA_REQ_WAIT: 1663 case MPA_REQ_WAIT:
1662 break; 1664 break;
1665 case CLOSING:
1663 case MORIBUND: 1666 case MORIBUND:
1664 if (ep->com.cm_id && ep->com.qp) { 1667 if (ep->com.cm_id && ep->com.qp) {
1665 attrs.next_state = IWCH_QP_STATE_ERROR; 1668 attrs.next_state = IWCH_QP_STATE_ERROR;
@@ -1688,12 +1691,11 @@ int iwch_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
1688 return -ECONNRESET; 1691 return -ECONNRESET;
1689 } 1692 }
1690 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD); 1693 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
1691 state_set(&ep->com, CLOSING);
1692 if (mpa_rev == 0) 1694 if (mpa_rev == 0)
1693 abort_connection(ep, NULL, GFP_KERNEL); 1695 abort_connection(ep, NULL, GFP_KERNEL);
1694 else { 1696 else {
1695 err = send_mpa_reject(ep, pdata, pdata_len); 1697 err = send_mpa_reject(ep, pdata, pdata_len);
1696 err = send_halfclose(ep, GFP_KERNEL); 1698 err = iwch_ep_disconnect(ep, 0, GFP_KERNEL);
1697 } 1699 }
1698 return 0; 1700 return 0;
1699} 1701}
@@ -1958,11 +1960,11 @@ int iwch_ep_disconnect(struct iwch_ep *ep, int abrupt, gfp_t gfp)
1958 case MPA_REQ_RCVD: 1960 case MPA_REQ_RCVD:
1959 case MPA_REP_SENT: 1961 case MPA_REP_SENT:
1960 case FPDU_MODE: 1962 case FPDU_MODE:
1963 start_ep_timer(ep);
1961 ep->com.state = CLOSING; 1964 ep->com.state = CLOSING;
1962 close = 1; 1965 close = 1;
1963 break; 1966 break;
1964 case CLOSING: 1967 case CLOSING:
1965 start_ep_timer(ep);
1966 ep->com.state = MORIBUND; 1968 ep->com.state = MORIBUND;
1967 close = 1; 1969 close = 1;
1968 break; 1970 break;
diff --git a/drivers/infiniband/hw/cxgb3/iwch_cm.h b/drivers/infiniband/hw/cxgb3/iwch_cm.h
index 7c810d9042..0c6f281bd4 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_cm.h
+++ b/drivers/infiniband/hw/cxgb3/iwch_cm.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_cq.c b/drivers/infiniband/hw/cxgb3/iwch_cq.c
index 98b3bdb5de..d7624c170e 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_cq.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_cq.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_ev.c b/drivers/infiniband/hw/cxgb3/iwch_ev.c
index a6efa8fe15..b40676662a 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_ev.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_ev.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
@@ -48,12 +47,6 @@ static void post_qp_event(struct iwch_dev *rnicp, struct iwch_cq *chp,
48 struct iwch_qp_attributes attrs; 47 struct iwch_qp_attributes attrs;
49 struct iwch_qp *qhp; 48 struct iwch_qp *qhp;
50 49
51 printk(KERN_ERR "%s - AE qpid 0x%x opcode %d status 0x%x "
52 "type %d wrid.hi 0x%x wrid.lo 0x%x \n", __FUNCTION__,
53 CQE_QPID(rsp_msg->cqe), CQE_OPCODE(rsp_msg->cqe),
54 CQE_STATUS(rsp_msg->cqe), CQE_TYPE(rsp_msg->cqe),
55 CQE_WRID_HI(rsp_msg->cqe), CQE_WRID_LOW(rsp_msg->cqe));
56
57 spin_lock(&rnicp->lock); 50 spin_lock(&rnicp->lock);
58 qhp = get_qhp(rnicp, CQE_QPID(rsp_msg->cqe)); 51 qhp = get_qhp(rnicp, CQE_QPID(rsp_msg->cqe));
59 52
@@ -74,6 +67,12 @@ static void post_qp_event(struct iwch_dev *rnicp, struct iwch_cq *chp,
74 return; 67 return;
75 } 68 }
76 69
70 printk(KERN_ERR "%s - AE qpid 0x%x opcode %d status 0x%x "
71 "type %d wrid.hi 0x%x wrid.lo 0x%x \n", __FUNCTION__,
72 CQE_QPID(rsp_msg->cqe), CQE_OPCODE(rsp_msg->cqe),
73 CQE_STATUS(rsp_msg->cqe), CQE_TYPE(rsp_msg->cqe),
74 CQE_WRID_HI(rsp_msg->cqe), CQE_WRID_LOW(rsp_msg->cqe));
75
77 atomic_inc(&qhp->refcnt); 76 atomic_inc(&qhp->refcnt);
78 spin_unlock(&rnicp->lock); 77 spin_unlock(&rnicp->lock);
79 78
diff --git a/drivers/infiniband/hw/cxgb3/iwch_mem.c b/drivers/infiniband/hw/cxgb3/iwch_mem.c
index 2b6cd53bb3..a6c2c4ba29 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_mem.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_mem.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_provider.c b/drivers/infiniband/hw/cxgb3/iwch_provider.c
index 6861087d77..f2774ae906 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_provider.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_provider.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
@@ -332,6 +331,7 @@ static int iwch_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
332 int ret = 0; 331 int ret = 0;
333 struct iwch_mm_entry *mm; 332 struct iwch_mm_entry *mm;
334 struct iwch_ucontext *ucontext; 333 struct iwch_ucontext *ucontext;
334 u64 addr;
335 335
336 PDBG("%s pgoff 0x%lx key 0x%x len %d\n", __FUNCTION__, vma->vm_pgoff, 336 PDBG("%s pgoff 0x%lx key 0x%x len %d\n", __FUNCTION__, vma->vm_pgoff,
337 key, len); 337 key, len);
@@ -346,10 +346,11 @@ static int iwch_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
346 mm = remove_mmap(ucontext, key, len); 346 mm = remove_mmap(ucontext, key, len);
347 if (!mm) 347 if (!mm)
348 return -EINVAL; 348 return -EINVAL;
349 addr = mm->addr;
349 kfree(mm); 350 kfree(mm);
350 351
351 if ((mm->addr >= rdev_p->rnic_info.udbell_physbase) && 352 if ((addr >= rdev_p->rnic_info.udbell_physbase) &&
352 (mm->addr < (rdev_p->rnic_info.udbell_physbase + 353 (addr < (rdev_p->rnic_info.udbell_physbase +
353 rdev_p->rnic_info.udbell_len))) { 354 rdev_p->rnic_info.udbell_len))) {
354 355
355 /* 356 /*
@@ -363,7 +364,7 @@ static int iwch_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
363 vma->vm_flags |= VM_DONTCOPY | VM_DONTEXPAND; 364 vma->vm_flags |= VM_DONTCOPY | VM_DONTEXPAND;
364 vma->vm_flags &= ~VM_MAYREAD; 365 vma->vm_flags &= ~VM_MAYREAD;
365 ret = io_remap_pfn_range(vma, vma->vm_start, 366 ret = io_remap_pfn_range(vma, vma->vm_start,
366 mm->addr >> PAGE_SHIFT, 367 addr >> PAGE_SHIFT,
367 len, vma->vm_page_prot); 368 len, vma->vm_page_prot);
368 } else { 369 } else {
369 370
@@ -371,7 +372,7 @@ static int iwch_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
371 * Map WQ or CQ contig dma memory... 372 * Map WQ or CQ contig dma memory...
372 */ 373 */
373 ret = remap_pfn_range(vma, vma->vm_start, 374 ret = remap_pfn_range(vma, vma->vm_start,
374 mm->addr >> PAGE_SHIFT, 375 addr >> PAGE_SHIFT,
375 len, vma->vm_page_prot); 376 len, vma->vm_page_prot);
376 } 377 }
377 378
@@ -464,9 +465,6 @@ static struct ib_mr *iwch_register_phys_mem(struct ib_pd *pd,
464 php = to_iwch_pd(pd); 465 php = to_iwch_pd(pd);
465 rhp = php->rhp; 466 rhp = php->rhp;
466 467
467 acc = iwch_convert_access(acc);
468
469
470 mhp = kzalloc(sizeof(*mhp), GFP_KERNEL); 468 mhp = kzalloc(sizeof(*mhp), GFP_KERNEL);
471 if (!mhp) 469 if (!mhp)
472 return ERR_PTR(-ENOMEM); 470 return ERR_PTR(-ENOMEM);
@@ -492,12 +490,7 @@ static struct ib_mr *iwch_register_phys_mem(struct ib_pd *pd,
492 mhp->attr.pdid = php->pdid; 490 mhp->attr.pdid = php->pdid;
493 mhp->attr.zbva = 0; 491 mhp->attr.zbva = 0;
494 492
495 /* NOTE: TPT perms are backwards from BIND WR perms! */ 493 mhp->attr.perms = iwch_ib_to_tpt_access(acc);
496 mhp->attr.perms = (acc & 0x1) << 3;
497 mhp->attr.perms |= (acc & 0x2) << 1;
498 mhp->attr.perms |= (acc & 0x4) >> 1;
499 mhp->attr.perms |= (acc & 0x8) >> 3;
500
501 mhp->attr.va_fbo = *iova_start; 494 mhp->attr.va_fbo = *iova_start;
502 mhp->attr.page_size = shift - 12; 495 mhp->attr.page_size = shift - 12;
503 496
@@ -526,7 +519,6 @@ static int iwch_reregister_phys_mem(struct ib_mr *mr,
526 struct iwch_mr mh, *mhp; 519 struct iwch_mr mh, *mhp;
527 struct iwch_pd *php; 520 struct iwch_pd *php;
528 struct iwch_dev *rhp; 521 struct iwch_dev *rhp;
529 int new_acc;
530 __be64 *page_list = NULL; 522 __be64 *page_list = NULL;
531 int shift = 0; 523 int shift = 0;
532 u64 total_size; 524 u64 total_size;
@@ -547,14 +539,12 @@ static int iwch_reregister_phys_mem(struct ib_mr *mr,
547 if (rhp != php->rhp) 539 if (rhp != php->rhp)
548 return -EINVAL; 540 return -EINVAL;
549 541
550 new_acc = mhp->attr.perms;
551
552 memcpy(&mh, mhp, sizeof *mhp); 542 memcpy(&mh, mhp, sizeof *mhp);
553 543
554 if (mr_rereg_mask & IB_MR_REREG_PD) 544 if (mr_rereg_mask & IB_MR_REREG_PD)
555 php = to_iwch_pd(pd); 545 php = to_iwch_pd(pd);
556 if (mr_rereg_mask & IB_MR_REREG_ACCESS) 546 if (mr_rereg_mask & IB_MR_REREG_ACCESS)
557 mh.attr.perms = iwch_convert_access(acc); 547 mh.attr.perms = iwch_ib_to_tpt_access(acc);
558 if (mr_rereg_mask & IB_MR_REREG_TRANS) 548 if (mr_rereg_mask & IB_MR_REREG_TRANS)
559 ret = build_phys_page_list(buffer_list, num_phys_buf, 549 ret = build_phys_page_list(buffer_list, num_phys_buf,
560 iova_start, 550 iova_start,
@@ -569,7 +559,7 @@ static int iwch_reregister_phys_mem(struct ib_mr *mr,
569 if (mr_rereg_mask & IB_MR_REREG_PD) 559 if (mr_rereg_mask & IB_MR_REREG_PD)
570 mhp->attr.pdid = php->pdid; 560 mhp->attr.pdid = php->pdid;
571 if (mr_rereg_mask & IB_MR_REREG_ACCESS) 561 if (mr_rereg_mask & IB_MR_REREG_ACCESS)
572 mhp->attr.perms = acc; 562 mhp->attr.perms = iwch_ib_to_tpt_access(acc);
573 if (mr_rereg_mask & IB_MR_REREG_TRANS) { 563 if (mr_rereg_mask & IB_MR_REREG_TRANS) {
574 mhp->attr.zbva = 0; 564 mhp->attr.zbva = 0;
575 mhp->attr.va_fbo = *iova_start; 565 mhp->attr.va_fbo = *iova_start;
@@ -614,8 +604,6 @@ static struct ib_mr *iwch_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
614 goto err; 604 goto err;
615 } 605 }
616 606
617 acc = iwch_convert_access(acc);
618
619 i = n = 0; 607 i = n = 0;
620 608
621 list_for_each_entry(chunk, &region->chunk_list, list) 609 list_for_each_entry(chunk, &region->chunk_list, list)
@@ -631,10 +619,7 @@ static struct ib_mr *iwch_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
631 mhp->rhp = rhp; 619 mhp->rhp = rhp;
632 mhp->attr.pdid = php->pdid; 620 mhp->attr.pdid = php->pdid;
633 mhp->attr.zbva = 0; 621 mhp->attr.zbva = 0;
634 mhp->attr.perms = (acc & 0x1) << 3; 622 mhp->attr.perms = iwch_ib_to_tpt_access(acc);
635 mhp->attr.perms |= (acc & 0x2) << 1;
636 mhp->attr.perms |= (acc & 0x4) >> 1;
637 mhp->attr.perms |= (acc & 0x8) >> 3;
638 mhp->attr.va_fbo = region->virt_base; 623 mhp->attr.va_fbo = region->virt_base;
639 mhp->attr.page_size = shift - 12; 624 mhp->attr.page_size = shift - 12;
640 mhp->attr.len = (u32) region->length; 625 mhp->attr.len = (u32) region->length;
@@ -737,10 +722,8 @@ static int iwch_destroy_qp(struct ib_qp *ib_qp)
737 qhp = to_iwch_qp(ib_qp); 722 qhp = to_iwch_qp(ib_qp);
738 rhp = qhp->rhp; 723 rhp = qhp->rhp;
739 724
740 if (qhp->attr.state == IWCH_QP_STATE_RTS) { 725 attrs.next_state = IWCH_QP_STATE_ERROR;
741 attrs.next_state = IWCH_QP_STATE_ERROR; 726 iwch_modify_qp(rhp, qhp, IWCH_QP_ATTR_NEXT_STATE, &attrs, 0);
742 iwch_modify_qp(rhp, qhp, IWCH_QP_ATTR_NEXT_STATE, &attrs, 0);
743 }
744 wait_event(qhp->wait, !qhp->ep); 727 wait_event(qhp->wait, !qhp->ep);
745 728
746 remove_handle(rhp, &rhp->qpidr, qhp->wq.qpid); 729 remove_handle(rhp, &rhp->qpidr, qhp->wq.qpid);
@@ -949,7 +932,7 @@ void iwch_qp_rem_ref(struct ib_qp *qp)
949 wake_up(&(to_iwch_qp(qp)->wait)); 932 wake_up(&(to_iwch_qp(qp)->wait));
950} 933}
951 934
952struct ib_qp *iwch_get_qp(struct ib_device *dev, int qpn) 935static struct ib_qp *iwch_get_qp(struct ib_device *dev, int qpn)
953{ 936{
954 PDBG("%s ib_dev %p qpn 0x%x\n", __FUNCTION__, dev, qpn); 937 PDBG("%s ib_dev %p qpn 0x%x\n", __FUNCTION__, dev, qpn);
955 return (struct ib_qp *)get_qhp(to_iwch_dev(dev), qpn); 938 return (struct ib_qp *)get_qhp(to_iwch_dev(dev), qpn);
diff --git a/drivers/infiniband/hw/cxgb3/iwch_provider.h b/drivers/infiniband/hw/cxgb3/iwch_provider.h
index 61e3278fd7..93bcc56756 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_provider.h
+++ b/drivers/infiniband/hw/cxgb3/iwch_provider.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
@@ -179,7 +178,6 @@ static inline struct iwch_qp *to_iwch_qp(struct ib_qp *ibqp)
179 178
180void iwch_qp_add_ref(struct ib_qp *qp); 179void iwch_qp_add_ref(struct ib_qp *qp);
181void iwch_qp_rem_ref(struct ib_qp *qp); 180void iwch_qp_rem_ref(struct ib_qp *qp);
182struct ib_qp *iwch_get_qp(struct ib_device *dev, int qpn);
183 181
184struct iwch_ucontext { 182struct iwch_ucontext {
185 struct ib_ucontext ibucontext; 183 struct ib_ucontext ibucontext;
@@ -288,27 +286,20 @@ static inline int iwch_convert_state(enum ib_qp_state ib_state)
288 } 286 }
289} 287}
290 288
291enum iwch_mem_perms { 289static inline u32 iwch_ib_to_tpt_access(int acc)
292 IWCH_MEM_ACCESS_LOCAL_READ = 1 << 0,
293 IWCH_MEM_ACCESS_LOCAL_WRITE = 1 << 1,
294 IWCH_MEM_ACCESS_REMOTE_READ = 1 << 2,
295 IWCH_MEM_ACCESS_REMOTE_WRITE = 1 << 3,
296 IWCH_MEM_ACCESS_ATOMICS = 1 << 4,
297 IWCH_MEM_ACCESS_BINDING = 1 << 5,
298 IWCH_MEM_ACCESS_LOCAL =
299 (IWCH_MEM_ACCESS_LOCAL_READ | IWCH_MEM_ACCESS_LOCAL_WRITE),
300 IWCH_MEM_ACCESS_REMOTE =
301 (IWCH_MEM_ACCESS_REMOTE_WRITE | IWCH_MEM_ACCESS_REMOTE_READ)
302 /* cannot go beyond 1 << 31 */
303} __attribute__ ((packed));
304
305static inline u32 iwch_convert_access(int acc)
306{ 290{
307 return (acc & IB_ACCESS_REMOTE_WRITE ? IWCH_MEM_ACCESS_REMOTE_WRITE : 0) 291 return (acc & IB_ACCESS_REMOTE_WRITE ? TPT_REMOTE_WRITE : 0) |
308 | (acc & IB_ACCESS_REMOTE_READ ? IWCH_MEM_ACCESS_REMOTE_READ : 0) | 292 (acc & IB_ACCESS_REMOTE_READ ? TPT_REMOTE_READ : 0) |
309 (acc & IB_ACCESS_LOCAL_WRITE ? IWCH_MEM_ACCESS_LOCAL_WRITE : 0) | 293 (acc & IB_ACCESS_LOCAL_WRITE ? TPT_LOCAL_WRITE : 0) |
310 (acc & IB_ACCESS_MW_BIND ? IWCH_MEM_ACCESS_BINDING : 0) | 294 TPT_LOCAL_READ;
311 IWCH_MEM_ACCESS_LOCAL_READ; 295}
296
297static inline u32 iwch_ib_to_mwbind_access(int acc)
298{
299 return (acc & IB_ACCESS_REMOTE_WRITE ? T3_MEM_ACCESS_REM_WRITE : 0) |
300 (acc & IB_ACCESS_REMOTE_READ ? T3_MEM_ACCESS_REM_READ : 0) |
301 (acc & IB_ACCESS_LOCAL_WRITE ? T3_MEM_ACCESS_LOCAL_WRITE : 0) |
302 T3_MEM_ACCESS_LOCAL_READ;
312} 303}
313 304
314enum iwch_mmid_state { 305enum iwch_mmid_state {
diff --git a/drivers/infiniband/hw/cxgb3/iwch_qp.c b/drivers/infiniband/hw/cxgb3/iwch_qp.c
index e066727504..0a472c9b44 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_qp.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_qp.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
@@ -37,8 +36,8 @@
37 36
38#define NO_SUPPORT -1 37#define NO_SUPPORT -1
39 38
40static inline int iwch_build_rdma_send(union t3_wr *wqe, struct ib_send_wr *wr, 39static int iwch_build_rdma_send(union t3_wr *wqe, struct ib_send_wr *wr,
41 u8 * flit_cnt) 40 u8 * flit_cnt)
42{ 41{
43 int i; 42 int i;
44 u32 plen; 43 u32 plen;
@@ -97,8 +96,8 @@ static inline int iwch_build_rdma_send(union t3_wr *wqe, struct ib_send_wr *wr,
97 return 0; 96 return 0;
98} 97}
99 98
100static inline int iwch_build_rdma_write(union t3_wr *wqe, struct ib_send_wr *wr, 99static int iwch_build_rdma_write(union t3_wr *wqe, struct ib_send_wr *wr,
101 u8 *flit_cnt) 100 u8 *flit_cnt)
102{ 101{
103 int i; 102 int i;
104 u32 plen; 103 u32 plen;
@@ -138,8 +137,8 @@ static inline int iwch_build_rdma_write(union t3_wr *wqe, struct ib_send_wr *wr,
138 return 0; 137 return 0;
139} 138}
140 139
141static inline int iwch_build_rdma_read(union t3_wr *wqe, struct ib_send_wr *wr, 140static int iwch_build_rdma_read(union t3_wr *wqe, struct ib_send_wr *wr,
142 u8 *flit_cnt) 141 u8 *flit_cnt)
143{ 142{
144 if (wr->num_sge > 1) 143 if (wr->num_sge > 1)
145 return -EINVAL; 144 return -EINVAL;
@@ -159,9 +158,8 @@ static inline int iwch_build_rdma_read(union t3_wr *wqe, struct ib_send_wr *wr,
159/* 158/*
160 * TBD: this is going to be moved to firmware. Missing pdid/qpid check for now. 159 * TBD: this is going to be moved to firmware. Missing pdid/qpid check for now.
161 */ 160 */
162static inline int iwch_sgl2pbl_map(struct iwch_dev *rhp, 161static int iwch_sgl2pbl_map(struct iwch_dev *rhp, struct ib_sge *sg_list,
163 struct ib_sge *sg_list, u32 num_sgle, 162 u32 num_sgle, u32 * pbl_addr, u8 * page_size)
164 u32 * pbl_addr, u8 * page_size)
165{ 163{
166 int i; 164 int i;
167 struct iwch_mr *mhp; 165 struct iwch_mr *mhp;
@@ -207,9 +205,8 @@ static inline int iwch_sgl2pbl_map(struct iwch_dev *rhp,
207 return 0; 205 return 0;
208} 206}
209 207
210static inline int iwch_build_rdma_recv(struct iwch_dev *rhp, 208static int iwch_build_rdma_recv(struct iwch_dev *rhp, union t3_wr *wqe,
211 union t3_wr *wqe, 209 struct ib_recv_wr *wr)
212 struct ib_recv_wr *wr)
213{ 210{
214 int i, err = 0; 211 int i, err = 0;
215 u32 pbl_addr[4]; 212 u32 pbl_addr[4];
@@ -442,7 +439,7 @@ int iwch_bind_mw(struct ib_qp *qp,
442 wqe->bind.type = T3_VA_BASED_TO; 439 wqe->bind.type = T3_VA_BASED_TO;
443 440
444 /* TBD: check perms */ 441 /* TBD: check perms */
445 wqe->bind.perms = iwch_convert_access(mw_bind->mw_access_flags); 442 wqe->bind.perms = iwch_ib_to_mwbind_access(mw_bind->mw_access_flags);
446 wqe->bind.mr_stag = cpu_to_be32(mw_bind->mr->lkey); 443 wqe->bind.mr_stag = cpu_to_be32(mw_bind->mr->lkey);
447 wqe->bind.mw_stag = cpu_to_be32(mw->rkey); 444 wqe->bind.mw_stag = cpu_to_be32(mw->rkey);
448 wqe->bind.mw_len = cpu_to_be32(mw_bind->length); 445 wqe->bind.mw_len = cpu_to_be32(mw_bind->length);
@@ -474,8 +471,7 @@ int iwch_bind_mw(struct ib_qp *qp,
474 return err; 471 return err;
475} 472}
476 473
477static inline void build_term_codes(int t3err, u8 *layer_type, u8 *ecode, 474static void build_term_codes(int t3err, u8 *layer_type, u8 *ecode, int tagged)
478 int tagged)
479{ 475{
480 switch (t3err) { 476 switch (t3err) {
481 case TPT_ERR_STAG: 477 case TPT_ERR_STAG:
@@ -673,7 +669,7 @@ static void __flush_qp(struct iwch_qp *qhp, unsigned long *flag)
673 spin_lock_irqsave(&qhp->lock, *flag); 669 spin_lock_irqsave(&qhp->lock, *flag);
674} 670}
675 671
676static inline void flush_qp(struct iwch_qp *qhp, unsigned long *flag) 672static void flush_qp(struct iwch_qp *qhp, unsigned long *flag)
677{ 673{
678 if (t3b_device(qhp->rhp)) 674 if (t3b_device(qhp->rhp))
679 cxio_set_wq_in_error(&qhp->wq); 675 cxio_set_wq_in_error(&qhp->wq);
@@ -685,7 +681,7 @@ static inline void flush_qp(struct iwch_qp *qhp, unsigned long *flag)
685/* 681/*
686 * Return non zero if at least one RECV was pre-posted. 682 * Return non zero if at least one RECV was pre-posted.
687 */ 683 */
688static inline int rqes_posted(struct iwch_qp *qhp) 684static int rqes_posted(struct iwch_qp *qhp)
689{ 685{
690 return fw_riwrh_opcode((struct fw_riwrh *)qhp->wq.queue) == T3_WR_RCV; 686 return fw_riwrh_opcode((struct fw_riwrh *)qhp->wq.queue) == T3_WR_RCV;
691} 687}
@@ -846,6 +842,8 @@ int iwch_modify_qp(struct iwch_dev *rhp, struct iwch_qp *qhp,
846 break; 842 break;
847 case IWCH_QP_STATE_TERMINATE: 843 case IWCH_QP_STATE_TERMINATE:
848 qhp->attr.state = IWCH_QP_STATE_TERMINATE; 844 qhp->attr.state = IWCH_QP_STATE_TERMINATE;
845 if (t3b_device(qhp->rhp))
846 cxio_set_wq_in_error(&qhp->wq);
849 if (!internal) 847 if (!internal)
850 terminate = 1; 848 terminate = 1;
851 break; 849 break;
diff --git a/drivers/infiniband/hw/cxgb3/iwch_user.h b/drivers/infiniband/hw/cxgb3/iwch_user.h
index c4e7fbea8b..cb7086f558 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_user.h
+++ b/drivers/infiniband/hw/cxgb3/iwch_user.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/ehca/Kconfig b/drivers/infiniband/hw/ehca/Kconfig
index 727b10d896..1a854598e0 100644
--- a/drivers/infiniband/hw/ehca/Kconfig
+++ b/drivers/infiniband/hw/ehca/Kconfig
@@ -7,11 +7,3 @@ config INFINIBAND_EHCA
7 To compile the driver as a module, choose M here. The module 7 To compile the driver as a module, choose M here. The module
8 will be called ib_ehca. 8 will be called ib_ehca.
9 9
10config INFINIBAND_EHCA_SCALING
11 bool "Scaling support (EXPERIMENTAL)"
12 depends on IBMEBUS && INFINIBAND_EHCA && HOTPLUG_CPU && EXPERIMENTAL
13 default y
14 ---help---
15 eHCA scaling support schedules the CQ callbacks to different CPUs.
16
17 To enable this feature choose Y here.
diff --git a/drivers/infiniband/hw/ehca/ehca_classes.h b/drivers/infiniband/hw/ehca/ehca_classes.h
index cf95ee474b..82ded44c6c 100644
--- a/drivers/infiniband/hw/ehca/ehca_classes.h
+++ b/drivers/infiniband/hw/ehca/ehca_classes.h
@@ -42,8 +42,6 @@
42#ifndef __EHCA_CLASSES_H__ 42#ifndef __EHCA_CLASSES_H__
43#define __EHCA_CLASSES_H__ 43#define __EHCA_CLASSES_H__
44 44
45#include "ehca_classes.h"
46#include "ipz_pt_fn.h"
47 45
48struct ehca_module; 46struct ehca_module;
49struct ehca_qp; 47struct ehca_qp;
@@ -54,15 +52,25 @@ struct ehca_mw;
54struct ehca_pd; 52struct ehca_pd;
55struct ehca_av; 53struct ehca_av;
56 54
57#ifdef CONFIG_PPC64 55#include <linux/wait.h>
58#include "ehca_classes_pSeries.h"
59#endif
60 56
61#include <rdma/ib_verbs.h> 57#include <rdma/ib_verbs.h>
62#include <rdma/ib_user_verbs.h> 58#include <rdma/ib_user_verbs.h>
63 59
60#ifdef CONFIG_PPC64
61#include "ehca_classes_pSeries.h"
62#endif
63#include "ipz_pt_fn.h"
64#include "ehca_qes.h"
64#include "ehca_irq.h" 65#include "ehca_irq.h"
65 66
67#define EHCA_EQE_CACHE_SIZE 20
68
69struct ehca_eqe_cache_entry {
70 struct ehca_eqe *eqe;
71 struct ehca_cq *cq;
72};
73
66struct ehca_eq { 74struct ehca_eq {
67 u32 length; 75 u32 length;
68 struct ipz_queue ipz_queue; 76 struct ipz_queue ipz_queue;
@@ -74,6 +82,8 @@ struct ehca_eq {
74 spinlock_t spinlock; 82 spinlock_t spinlock;
75 struct tasklet_struct interrupt_task; 83 struct tasklet_struct interrupt_task;
76 u32 ist; 84 u32 ist;
85 spinlock_t irq_spinlock;
86 struct ehca_eqe_cache_entry eqe_cache[EHCA_EQE_CACHE_SIZE];
77}; 87};
78 88
79struct ehca_sport { 89struct ehca_sport {
@@ -145,7 +155,9 @@ struct ehca_cq {
145 spinlock_t cb_lock; 155 spinlock_t cb_lock;
146 struct hlist_head qp_hashtab[QP_HASHTAB_LEN]; 156 struct hlist_head qp_hashtab[QP_HASHTAB_LEN];
147 struct list_head entry; 157 struct list_head entry;
148 u32 nr_callbacks; 158 u32 nr_callbacks; /* #events assigned to cpu by scaling code */
159 u32 nr_events; /* #events seen */
160 wait_queue_head_t wait_completion;
149 spinlock_t task_lock; 161 spinlock_t task_lock;
150 u32 ownpid; 162 u32 ownpid;
151 /* mmap counter for resources mapped into user space */ 163 /* mmap counter for resources mapped into user space */
@@ -269,6 +281,7 @@ extern struct idr ehca_cq_idr;
269extern int ehca_static_rate; 281extern int ehca_static_rate;
270extern int ehca_port_act_time; 282extern int ehca_port_act_time;
271extern int ehca_use_hp_mr; 283extern int ehca_use_hp_mr;
284extern int ehca_scaling_code;
272 285
273struct ipzu_queue_resp { 286struct ipzu_queue_resp {
274 u32 qe_size; /* queue entry size */ 287 u32 qe_size; /* queue entry size */
diff --git a/drivers/infiniband/hw/ehca/ehca_cq.c b/drivers/infiniband/hw/ehca/ehca_cq.c
index 6ebfa27e4e..e2cdc1a16f 100644
--- a/drivers/infiniband/hw/ehca/ehca_cq.c
+++ b/drivers/infiniband/hw/ehca/ehca_cq.c
@@ -146,6 +146,7 @@ struct ib_cq *ehca_create_cq(struct ib_device *device, int cqe,
146 spin_lock_init(&my_cq->spinlock); 146 spin_lock_init(&my_cq->spinlock);
147 spin_lock_init(&my_cq->cb_lock); 147 spin_lock_init(&my_cq->cb_lock);
148 spin_lock_init(&my_cq->task_lock); 148 spin_lock_init(&my_cq->task_lock);
149 init_waitqueue_head(&my_cq->wait_completion);
149 my_cq->ownpid = current->tgid; 150 my_cq->ownpid = current->tgid;
150 151
151 cq = &my_cq->ib_cq; 152 cq = &my_cq->ib_cq;
@@ -302,6 +303,16 @@ create_cq_exit1:
302 return cq; 303 return cq;
303} 304}
304 305
306static int get_cq_nr_events(struct ehca_cq *my_cq)
307{
308 int ret;
309 unsigned long flags;
310 spin_lock_irqsave(&ehca_cq_idr_lock, flags);
311 ret = my_cq->nr_events;
312 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
313 return ret;
314}
315
305int ehca_destroy_cq(struct ib_cq *cq) 316int ehca_destroy_cq(struct ib_cq *cq)
306{ 317{
307 u64 h_ret; 318 u64 h_ret;
@@ -329,10 +340,11 @@ int ehca_destroy_cq(struct ib_cq *cq)
329 } 340 }
330 341
331 spin_lock_irqsave(&ehca_cq_idr_lock, flags); 342 spin_lock_irqsave(&ehca_cq_idr_lock, flags);
332 while (my_cq->nr_callbacks) { 343 while (my_cq->nr_events) {
333 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags); 344 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
334 yield(); 345 wait_event(my_cq->wait_completion, !get_cq_nr_events(my_cq));
335 spin_lock_irqsave(&ehca_cq_idr_lock, flags); 346 spin_lock_irqsave(&ehca_cq_idr_lock, flags);
347 /* recheck nr_events to assure no cqe has just arrived */
336 } 348 }
337 349
338 idr_remove(&ehca_cq_idr, my_cq->token); 350 idr_remove(&ehca_cq_idr, my_cq->token);
diff --git a/drivers/infiniband/hw/ehca/ehca_eq.c b/drivers/infiniband/hw/ehca/ehca_eq.c
index 24ceab0bae..4961eb8882 100644
--- a/drivers/infiniband/hw/ehca/ehca_eq.c
+++ b/drivers/infiniband/hw/ehca/ehca_eq.c
@@ -61,6 +61,7 @@ int ehca_create_eq(struct ehca_shca *shca,
61 struct ib_device *ib_dev = &shca->ib_device; 61 struct ib_device *ib_dev = &shca->ib_device;
62 62
63 spin_lock_init(&eq->spinlock); 63 spin_lock_init(&eq->spinlock);
64 spin_lock_init(&eq->irq_spinlock);
64 eq->is_initialized = 0; 65 eq->is_initialized = 0;
65 66
66 if (type != EHCA_EQ && type != EHCA_NEQ) { 67 if (type != EHCA_EQ && type != EHCA_NEQ) {
diff --git a/drivers/infiniband/hw/ehca/ehca_hca.c b/drivers/infiniband/hw/ehca/ehca_hca.c
index b7be950ab4..30eb45df9f 100644
--- a/drivers/infiniband/hw/ehca/ehca_hca.c
+++ b/drivers/infiniband/hw/ehca/ehca_hca.c
@@ -162,6 +162,9 @@ int ehca_query_port(struct ib_device *ibdev,
162 props->active_width = IB_WIDTH_12X; 162 props->active_width = IB_WIDTH_12X;
163 props->active_speed = 0x1; 163 props->active_speed = 0x1;
164 164
165 /* at the moment (logical) link state is always LINK_UP */
166 props->phys_state = 0x5;
167
165query_port1: 168query_port1:
166 ehca_free_fw_ctrlblock(rblock); 169 ehca_free_fw_ctrlblock(rblock);
167 170
diff --git a/drivers/infiniband/hw/ehca/ehca_irq.c b/drivers/infiniband/hw/ehca/ehca_irq.c
index 6c4f9f91b1..20f36bf8b2 100644
--- a/drivers/infiniband/hw/ehca/ehca_irq.c
+++ b/drivers/infiniband/hw/ehca/ehca_irq.c
@@ -63,15 +63,11 @@
63#define ERROR_DATA_LENGTH EHCA_BMASK_IBM(52,63) 63#define ERROR_DATA_LENGTH EHCA_BMASK_IBM(52,63)
64#define ERROR_DATA_TYPE EHCA_BMASK_IBM(0,7) 64#define ERROR_DATA_TYPE EHCA_BMASK_IBM(0,7)
65 65
66#ifdef CONFIG_INFINIBAND_EHCA_SCALING
67
68static void queue_comp_task(struct ehca_cq *__cq); 66static void queue_comp_task(struct ehca_cq *__cq);
69 67
70static struct ehca_comp_pool* pool; 68static struct ehca_comp_pool* pool;
71static struct notifier_block comp_pool_callback_nb; 69static struct notifier_block comp_pool_callback_nb;
72 70
73#endif
74
75static inline void comp_event_callback(struct ehca_cq *cq) 71static inline void comp_event_callback(struct ehca_cq *cq)
76{ 72{
77 if (!cq->ib_cq.comp_handler) 73 if (!cq->ib_cq.comp_handler)
@@ -206,7 +202,7 @@ static void qp_event_callback(struct ehca_shca *shca,
206} 202}
207 203
208static void cq_event_callback(struct ehca_shca *shca, 204static void cq_event_callback(struct ehca_shca *shca,
209 u64 eqe) 205 u64 eqe)
210{ 206{
211 struct ehca_cq *cq; 207 struct ehca_cq *cq;
212 unsigned long flags; 208 unsigned long flags;
@@ -318,7 +314,7 @@ static void parse_ec(struct ehca_shca *shca, u64 eqe)
318 "disruptive port %x configuration change", port); 314 "disruptive port %x configuration change", port);
319 315
320 ehca_info(&shca->ib_device, 316 ehca_info(&shca->ib_device,
321 "port %x is inactive.", port); 317 "port %x is inactive.", port);
322 event.device = &shca->ib_device; 318 event.device = &shca->ib_device;
323 event.event = IB_EVENT_PORT_ERR; 319 event.event = IB_EVENT_PORT_ERR;
324 event.element.port_num = port; 320 event.element.port_num = port;
@@ -326,7 +322,7 @@ static void parse_ec(struct ehca_shca *shca, u64 eqe)
326 ib_dispatch_event(&event); 322 ib_dispatch_event(&event);
327 323
328 ehca_info(&shca->ib_device, 324 ehca_info(&shca->ib_device,
329 "port %x is active.", port); 325 "port %x is active.", port);
330 event.device = &shca->ib_device; 326 event.device = &shca->ib_device;
331 event.event = IB_EVENT_PORT_ACTIVE; 327 event.event = IB_EVENT_PORT_ACTIVE;
332 event.element.port_num = port; 328 event.element.port_num = port;
@@ -401,200 +397,274 @@ irqreturn_t ehca_interrupt_eq(int irq, void *dev_id)
401 return IRQ_HANDLED; 397 return IRQ_HANDLED;
402} 398}
403 399
404void ehca_tasklet_eq(unsigned long data) 400
401static inline void process_eqe(struct ehca_shca *shca, struct ehca_eqe *eqe)
405{ 402{
406 struct ehca_shca *shca = (struct ehca_shca*)data; 403 u64 eqe_value;
407 struct ehca_eqe *eqe; 404 u32 token;
408 int int_state; 405 unsigned long flags;
409 int query_cnt = 0; 406 struct ehca_cq *cq;
410 407
411 do { 408 eqe_value = eqe->entry;
412 eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->eq); 409 ehca_dbg(&shca->ib_device, "eqe_value=%lx", eqe_value);
410 if (EHCA_BMASK_GET(EQE_COMPLETION_EVENT, eqe_value)) {
411 ehca_dbg(&shca->ib_device, "Got completion event");
412 token = EHCA_BMASK_GET(EQE_CQ_TOKEN, eqe_value);
413 spin_lock_irqsave(&ehca_cq_idr_lock, flags);
414 cq = idr_find(&ehca_cq_idr, token);
415 if (cq == NULL) {
416 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
417 ehca_err(&shca->ib_device,
418 "Invalid eqe for non-existing cq token=%x",
419 token);
420 return;
421 }
422 reset_eq_pending(cq);
423 cq->nr_events++;
424 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
425 if (ehca_scaling_code)
426 queue_comp_task(cq);
427 else {
428 comp_event_callback(cq);
429 spin_lock_irqsave(&ehca_cq_idr_lock, flags);
430 cq->nr_events--;
431 if (!cq->nr_events)
432 wake_up(&cq->wait_completion);
433 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
434 }
435 } else {
436 ehca_dbg(&shca->ib_device, "Got non completion event");
437 parse_identifier(shca, eqe_value);
438 }
439}
413 440
414 if ((shca->hw_level >= 2) && eqe) 441void ehca_process_eq(struct ehca_shca *shca, int is_irq)
415 int_state = 1; 442{
416 else 443 struct ehca_eq *eq = &shca->eq;
417 int_state = 0; 444 struct ehca_eqe_cache_entry *eqe_cache = eq->eqe_cache;
418 445 u64 eqe_value;
419 while ((int_state == 1) || eqe) { 446 unsigned long flags;
420 while (eqe) { 447 int eqe_cnt, i;
421 u64 eqe_value = eqe->entry; 448 int eq_empty = 0;
422 449
423 ehca_dbg(&shca->ib_device, 450 spin_lock_irqsave(&eq->irq_spinlock, flags);
424 "eqe_value=%lx", eqe_value); 451 if (is_irq) {
425 452 const int max_query_cnt = 100;
426 /* TODO: better structure */ 453 int query_cnt = 0;
427 if (EHCA_BMASK_GET(EQE_COMPLETION_EVENT, 454 int int_state = 1;
428 eqe_value)) { 455 do {
429 unsigned long flags; 456 int_state = hipz_h_query_int_state(
430 u32 token; 457 shca->ipz_hca_handle, eq->ist);
431 struct ehca_cq *cq; 458 query_cnt++;
432 459 iosync();
433 ehca_dbg(&shca->ib_device, 460 } while (int_state && query_cnt < max_query_cnt);
434 "... completion event"); 461 if (unlikely((query_cnt == max_query_cnt)))
435 token = 462 ehca_dbg(&shca->ib_device, "int_state=%x query_cnt=%x",
436 EHCA_BMASK_GET(EQE_CQ_TOKEN, 463 int_state, query_cnt);
437 eqe_value); 464 }
438 spin_lock_irqsave(&ehca_cq_idr_lock,
439 flags);
440 cq = idr_find(&ehca_cq_idr, token);
441
442 if (cq == NULL) {
443 spin_unlock_irqrestore(&ehca_cq_idr_lock,
444 flags);
445 break;
446 }
447
448 reset_eq_pending(cq);
449#ifdef CONFIG_INFINIBAND_EHCA_SCALING
450 queue_comp_task(cq);
451 spin_unlock_irqrestore(&ehca_cq_idr_lock,
452 flags);
453#else
454 spin_unlock_irqrestore(&ehca_cq_idr_lock,
455 flags);
456 comp_event_callback(cq);
457#endif
458 } else {
459 ehca_dbg(&shca->ib_device,
460 "... non completion event");
461 parse_identifier(shca, eqe_value);
462 }
463 eqe =
464 (struct ehca_eqe *)ehca_poll_eq(shca,
465 &shca->eq);
466 }
467 465
468 if (shca->hw_level >= 2) { 466 /* read out all eqes */
469 int_state = 467 eqe_cnt = 0;
470 hipz_h_query_int_state(shca->ipz_hca_handle, 468 do {
471 shca->eq.ist); 469 u32 token;
472 query_cnt++; 470 eqe_cache[eqe_cnt].eqe =
473 iosync(); 471 (struct ehca_eqe *)ehca_poll_eq(shca, eq);
474 if (query_cnt >= 100) { 472 if (!eqe_cache[eqe_cnt].eqe)
475 query_cnt = 0; 473 break;
476 int_state = 0; 474 eqe_value = eqe_cache[eqe_cnt].eqe->entry;
477 } 475 if (EHCA_BMASK_GET(EQE_COMPLETION_EVENT, eqe_value)) {
476 token = EHCA_BMASK_GET(EQE_CQ_TOKEN, eqe_value);
477 spin_lock(&ehca_cq_idr_lock);
478 eqe_cache[eqe_cnt].cq = idr_find(&ehca_cq_idr, token);
479 if (!eqe_cache[eqe_cnt].cq) {
480 spin_unlock(&ehca_cq_idr_lock);
481 ehca_err(&shca->ib_device,
482 "Invalid eqe for non-existing cq "
483 "token=%x", token);
484 continue;
478 } 485 }
479 eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->eq); 486 eqe_cache[eqe_cnt].cq->nr_events++;
480 487 spin_unlock(&ehca_cq_idr_lock);
488 } else
489 eqe_cache[eqe_cnt].cq = NULL;
490 eqe_cnt++;
491 } while (eqe_cnt < EHCA_EQE_CACHE_SIZE);
492 if (!eqe_cnt) {
493 if (is_irq)
494 ehca_dbg(&shca->ib_device,
495 "No eqe found for irq event");
496 goto unlock_irq_spinlock;
497 } else if (!is_irq)
498 ehca_dbg(&shca->ib_device, "deadman found %x eqe", eqe_cnt);
499 if (unlikely(eqe_cnt == EHCA_EQE_CACHE_SIZE))
500 ehca_dbg(&shca->ib_device, "too many eqes for one irq event");
501 /* enable irq for new packets */
502 for (i = 0; i < eqe_cnt; i++) {
503 if (eq->eqe_cache[i].cq)
504 reset_eq_pending(eq->eqe_cache[i].cq);
505 }
506 /* check eq */
507 spin_lock(&eq->spinlock);
508 eq_empty = (!ipz_eqit_eq_peek_valid(&shca->eq.ipz_queue));
509 spin_unlock(&eq->spinlock);
510 /* call completion handler for cached eqes */
511 for (i = 0; i < eqe_cnt; i++)
512 if (eq->eqe_cache[i].cq) {
513 if (ehca_scaling_code)
514 queue_comp_task(eq->eqe_cache[i].cq);
515 else {
516 struct ehca_cq *cq = eq->eqe_cache[i].cq;
517 comp_event_callback(cq);
518 spin_lock_irqsave(&ehca_cq_idr_lock, flags);
519 cq->nr_events--;
520 if (!cq->nr_events)
521 wake_up(&cq->wait_completion);
522 spin_unlock_irqrestore(&ehca_cq_idr_lock,
523 flags);
524 }
525 } else {
526 ehca_dbg(&shca->ib_device, "Got non completion event");
527 parse_identifier(shca, eq->eqe_cache[i].eqe->entry);
481 } 528 }
482 } while (int_state != 0); 529 /* poll eq if not empty */
530 if (eq_empty)
531 goto unlock_irq_spinlock;
532 do {
533 struct ehca_eqe *eqe;
534 eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->eq);
535 if (!eqe)
536 break;
537 process_eqe(shca, eqe);
538 } while (1);
483 539
484 return; 540unlock_irq_spinlock:
541 spin_unlock_irqrestore(&eq->irq_spinlock, flags);
485} 542}
486 543
487#ifdef CONFIG_INFINIBAND_EHCA_SCALING 544void ehca_tasklet_eq(unsigned long data)
545{
546 ehca_process_eq((struct ehca_shca*)data, 1);
547}
488 548
489static inline int find_next_online_cpu(struct ehca_comp_pool* pool) 549static inline int find_next_online_cpu(struct ehca_comp_pool* pool)
490{ 550{
491 unsigned long flags_last_cpu; 551 int cpu;
552 unsigned long flags;
492 553
554 WARN_ON_ONCE(!in_interrupt());
493 if (ehca_debug_level) 555 if (ehca_debug_level)
494 ehca_dmp(&cpu_online_map, sizeof(cpumask_t), ""); 556 ehca_dmp(&cpu_online_map, sizeof(cpumask_t), "");
495 557
496 spin_lock_irqsave(&pool->last_cpu_lock, flags_last_cpu); 558 spin_lock_irqsave(&pool->last_cpu_lock, flags);
497 pool->last_cpu = next_cpu(pool->last_cpu, cpu_online_map); 559 cpu = next_cpu(pool->last_cpu, cpu_online_map);
498 if (pool->last_cpu == NR_CPUS) 560 if (cpu == NR_CPUS)
499 pool->last_cpu = first_cpu(cpu_online_map); 561 cpu = first_cpu(cpu_online_map);
500 spin_unlock_irqrestore(&pool->last_cpu_lock, flags_last_cpu); 562 pool->last_cpu = cpu;
563 spin_unlock_irqrestore(&pool->last_cpu_lock, flags);
501 564
502 return pool->last_cpu; 565 return cpu;
503} 566}
504 567
505static void __queue_comp_task(struct ehca_cq *__cq, 568static void __queue_comp_task(struct ehca_cq *__cq,
506 struct ehca_cpu_comp_task *cct) 569 struct ehca_cpu_comp_task *cct)
507{ 570{
508 unsigned long flags_cct; 571 unsigned long flags;
509 unsigned long flags_cq;
510 572
511 spin_lock_irqsave(&cct->task_lock, flags_cct); 573 spin_lock_irqsave(&cct->task_lock, flags);
512 spin_lock_irqsave(&__cq->task_lock, flags_cq); 574 spin_lock(&__cq->task_lock);
513 575
514 if (__cq->nr_callbacks == 0) { 576 if (__cq->nr_callbacks == 0) {
515 __cq->nr_callbacks++; 577 __cq->nr_callbacks++;
516 list_add_tail(&__cq->entry, &cct->cq_list); 578 list_add_tail(&__cq->entry, &cct->cq_list);
517 cct->cq_jobs++; 579 cct->cq_jobs++;
518 wake_up(&cct->wait_queue); 580 wake_up(&cct->wait_queue);
519 } 581 } else
520 else
521 __cq->nr_callbacks++; 582 __cq->nr_callbacks++;
522 583
523 spin_unlock_irqrestore(&__cq->task_lock, flags_cq); 584 spin_unlock(&__cq->task_lock);
524 spin_unlock_irqrestore(&cct->task_lock, flags_cct); 585 spin_unlock_irqrestore(&cct->task_lock, flags);
525} 586}
526 587
527static void queue_comp_task(struct ehca_cq *__cq) 588static void queue_comp_task(struct ehca_cq *__cq)
528{ 589{
529 int cpu;
530 int cpu_id; 590 int cpu_id;
531 struct ehca_cpu_comp_task *cct; 591 struct ehca_cpu_comp_task *cct;
592 int cq_jobs;
593 unsigned long flags;
532 594
533 cpu = get_cpu();
534 cpu_id = find_next_online_cpu(pool); 595 cpu_id = find_next_online_cpu(pool);
535
536 BUG_ON(!cpu_online(cpu_id)); 596 BUG_ON(!cpu_online(cpu_id));
537 597
538 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id); 598 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id);
599 BUG_ON(!cct);
539 600
540 if (cct->cq_jobs > 0) { 601 spin_lock_irqsave(&cct->task_lock, flags);
602 cq_jobs = cct->cq_jobs;
603 spin_unlock_irqrestore(&cct->task_lock, flags);
604 if (cq_jobs > 0) {
541 cpu_id = find_next_online_cpu(pool); 605 cpu_id = find_next_online_cpu(pool);
542 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id); 606 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id);
607 BUG_ON(!cct);
543 } 608 }
544 609
545 __queue_comp_task(__cq, cct); 610 __queue_comp_task(__cq, cct);
546
547 put_cpu();
548
549 return;
550} 611}
551 612
552static void run_comp_task(struct ehca_cpu_comp_task* cct) 613static void run_comp_task(struct ehca_cpu_comp_task* cct)
553{ 614{
554 struct ehca_cq *cq; 615 struct ehca_cq *cq;
555 unsigned long flags_cct; 616 unsigned long flags;
556 unsigned long flags_cq;
557 617
558 spin_lock_irqsave(&cct->task_lock, flags_cct); 618 spin_lock_irqsave(&cct->task_lock, flags);
559 619
560 while (!list_empty(&cct->cq_list)) { 620 while (!list_empty(&cct->cq_list)) {
561 cq = list_entry(cct->cq_list.next, struct ehca_cq, entry); 621 cq = list_entry(cct->cq_list.next, struct ehca_cq, entry);
562 spin_unlock_irqrestore(&cct->task_lock, flags_cct); 622 spin_unlock_irqrestore(&cct->task_lock, flags);
563 comp_event_callback(cq); 623 comp_event_callback(cq);
564 spin_lock_irqsave(&cct->task_lock, flags_cct);
565 624
566 spin_lock_irqsave(&cq->task_lock, flags_cq); 625 spin_lock_irqsave(&ehca_cq_idr_lock, flags);
626 cq->nr_events--;
627 if (!cq->nr_events)
628 wake_up(&cq->wait_completion);
629 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
630
631 spin_lock_irqsave(&cct->task_lock, flags);
632 spin_lock(&cq->task_lock);
567 cq->nr_callbacks--; 633 cq->nr_callbacks--;
568 if (cq->nr_callbacks == 0) { 634 if (!cq->nr_callbacks) {
569 list_del_init(cct->cq_list.next); 635 list_del_init(cct->cq_list.next);
570 cct->cq_jobs--; 636 cct->cq_jobs--;
571 } 637 }
572 spin_unlock_irqrestore(&cq->task_lock, flags_cq); 638 spin_unlock(&cq->task_lock);
573
574 } 639 }
575 640
576 spin_unlock_irqrestore(&cct->task_lock, flags_cct); 641 spin_unlock_irqrestore(&cct->task_lock, flags);
577
578 return;
579} 642}
580 643
581static int comp_task(void *__cct) 644static int comp_task(void *__cct)
582{ 645{
583 struct ehca_cpu_comp_task* cct = __cct; 646 struct ehca_cpu_comp_task* cct = __cct;
647 int cql_empty;
584 DECLARE_WAITQUEUE(wait, current); 648 DECLARE_WAITQUEUE(wait, current);
585 649
586 set_current_state(TASK_INTERRUPTIBLE); 650 set_current_state(TASK_INTERRUPTIBLE);
587 while(!kthread_should_stop()) { 651 while(!kthread_should_stop()) {
588 add_wait_queue(&cct->wait_queue, &wait); 652 add_wait_queue(&cct->wait_queue, &wait);
589 653
590 if (list_empty(&cct->cq_list)) 654 spin_lock_irq(&cct->task_lock);
655 cql_empty = list_empty(&cct->cq_list);
656 spin_unlock_irq(&cct->task_lock);
657 if (cql_empty)
591 schedule(); 658 schedule();
592 else 659 else
593 __set_current_state(TASK_RUNNING); 660 __set_current_state(TASK_RUNNING);
594 661
595 remove_wait_queue(&cct->wait_queue, &wait); 662 remove_wait_queue(&cct->wait_queue, &wait);
596 663
597 if (!list_empty(&cct->cq_list)) 664 spin_lock_irq(&cct->task_lock);
665 cql_empty = list_empty(&cct->cq_list);
666 spin_unlock_irq(&cct->task_lock);
667 if (!cql_empty)
598 run_comp_task(__cct); 668 run_comp_task(__cct);
599 669
600 set_current_state(TASK_INTERRUPTIBLE); 670 set_current_state(TASK_INTERRUPTIBLE);
@@ -637,8 +707,6 @@ static void destroy_comp_task(struct ehca_comp_pool *pool,
637 707
638 if (task) 708 if (task)
639 kthread_stop(task); 709 kthread_stop(task);
640
641 return;
642} 710}
643 711
644static void take_over_work(struct ehca_comp_pool *pool, 712static void take_over_work(struct ehca_comp_pool *pool,
@@ -654,11 +722,11 @@ static void take_over_work(struct ehca_comp_pool *pool,
654 list_splice_init(&cct->cq_list, &list); 722 list_splice_init(&cct->cq_list, &list);
655 723
656 while(!list_empty(&list)) { 724 while(!list_empty(&list)) {
657 cq = list_entry(cct->cq_list.next, struct ehca_cq, entry); 725 cq = list_entry(cct->cq_list.next, struct ehca_cq, entry);
658 726
659 list_del(&cq->entry); 727 list_del(&cq->entry);
660 __queue_comp_task(cq, per_cpu_ptr(pool->cpu_comp_tasks, 728 __queue_comp_task(cq, per_cpu_ptr(pool->cpu_comp_tasks,
661 smp_processor_id())); 729 smp_processor_id()));
662 } 730 }
663 731
664 spin_unlock_irqrestore(&cct->task_lock, flags_cct); 732 spin_unlock_irqrestore(&cct->task_lock, flags_cct);
@@ -708,14 +776,14 @@ static int comp_pool_callback(struct notifier_block *nfb,
708 return NOTIFY_OK; 776 return NOTIFY_OK;
709} 777}
710 778
711#endif
712
713int ehca_create_comp_pool(void) 779int ehca_create_comp_pool(void)
714{ 780{
715#ifdef CONFIG_INFINIBAND_EHCA_SCALING
716 int cpu; 781 int cpu;
717 struct task_struct *task; 782 struct task_struct *task;
718 783
784 if (!ehca_scaling_code)
785 return 0;
786
719 pool = kzalloc(sizeof(struct ehca_comp_pool), GFP_KERNEL); 787 pool = kzalloc(sizeof(struct ehca_comp_pool), GFP_KERNEL);
720 if (pool == NULL) 788 if (pool == NULL)
721 return -ENOMEM; 789 return -ENOMEM;
@@ -740,16 +808,19 @@ int ehca_create_comp_pool(void)
740 comp_pool_callback_nb.notifier_call = comp_pool_callback; 808 comp_pool_callback_nb.notifier_call = comp_pool_callback;
741 comp_pool_callback_nb.priority =0; 809 comp_pool_callback_nb.priority =0;
742 register_cpu_notifier(&comp_pool_callback_nb); 810 register_cpu_notifier(&comp_pool_callback_nb);
743#endif 811
812 printk(KERN_INFO "eHCA scaling code enabled\n");
744 813
745 return 0; 814 return 0;
746} 815}
747 816
748void ehca_destroy_comp_pool(void) 817void ehca_destroy_comp_pool(void)
749{ 818{
750#ifdef CONFIG_INFINIBAND_EHCA_SCALING
751 int i; 819 int i;
752 820
821 if (!ehca_scaling_code)
822 return;
823
753 unregister_cpu_notifier(&comp_pool_callback_nb); 824 unregister_cpu_notifier(&comp_pool_callback_nb);
754 825
755 for (i = 0; i < NR_CPUS; i++) { 826 for (i = 0; i < NR_CPUS; i++) {
@@ -758,7 +829,4 @@ void ehca_destroy_comp_pool(void)
758 } 829 }
759 free_percpu(pool->cpu_comp_tasks); 830 free_percpu(pool->cpu_comp_tasks);
760 kfree(pool); 831 kfree(pool);
761#endif
762
763 return;
764} 832}
diff --git a/drivers/infiniband/hw/ehca/ehca_irq.h b/drivers/infiniband/hw/ehca/ehca_irq.h
index be579cc0ad..6ed06ee033 100644
--- a/drivers/infiniband/hw/ehca/ehca_irq.h
+++ b/drivers/infiniband/hw/ehca/ehca_irq.h
@@ -56,6 +56,7 @@ void ehca_tasklet_neq(unsigned long data);
56 56
57irqreturn_t ehca_interrupt_eq(int irq, void *dev_id); 57irqreturn_t ehca_interrupt_eq(int irq, void *dev_id);
58void ehca_tasklet_eq(unsigned long data); 58void ehca_tasklet_eq(unsigned long data);
59void ehca_process_eq(struct ehca_shca *shca, int is_irq);
59 60
60struct ehca_cpu_comp_task { 61struct ehca_cpu_comp_task {
61 wait_queue_head_t wait_queue; 62 wait_queue_head_t wait_queue;
diff --git a/drivers/infiniband/hw/ehca/ehca_main.c b/drivers/infiniband/hw/ehca/ehca_main.c
index 1155bcf482..059da9628b 100644
--- a/drivers/infiniband/hw/ehca/ehca_main.c
+++ b/drivers/infiniband/hw/ehca/ehca_main.c
@@ -52,7 +52,7 @@
52MODULE_LICENSE("Dual BSD/GPL"); 52MODULE_LICENSE("Dual BSD/GPL");
53MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>"); 53MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
54MODULE_DESCRIPTION("IBM eServer HCA InfiniBand Device Driver"); 54MODULE_DESCRIPTION("IBM eServer HCA InfiniBand Device Driver");
55MODULE_VERSION("SVNEHCA_0020"); 55MODULE_VERSION("SVNEHCA_0022");
56 56
57int ehca_open_aqp1 = 0; 57int ehca_open_aqp1 = 0;
58int ehca_debug_level = 0; 58int ehca_debug_level = 0;
@@ -62,6 +62,7 @@ int ehca_use_hp_mr = 0;
62int ehca_port_act_time = 30; 62int ehca_port_act_time = 30;
63int ehca_poll_all_eqs = 1; 63int ehca_poll_all_eqs = 1;
64int ehca_static_rate = -1; 64int ehca_static_rate = -1;
65int ehca_scaling_code = 1;
65 66
66module_param_named(open_aqp1, ehca_open_aqp1, int, 0); 67module_param_named(open_aqp1, ehca_open_aqp1, int, 0);
67module_param_named(debug_level, ehca_debug_level, int, 0); 68module_param_named(debug_level, ehca_debug_level, int, 0);
@@ -71,6 +72,7 @@ module_param_named(use_hp_mr, ehca_use_hp_mr, int, 0);
71module_param_named(port_act_time, ehca_port_act_time, int, 0); 72module_param_named(port_act_time, ehca_port_act_time, int, 0);
72module_param_named(poll_all_eqs, ehca_poll_all_eqs, int, 0); 73module_param_named(poll_all_eqs, ehca_poll_all_eqs, int, 0);
73module_param_named(static_rate, ehca_static_rate, int, 0); 74module_param_named(static_rate, ehca_static_rate, int, 0);
75module_param_named(scaling_code, ehca_scaling_code, int, 0);
74 76
75MODULE_PARM_DESC(open_aqp1, 77MODULE_PARM_DESC(open_aqp1,
76 "AQP1 on startup (0: no (default), 1: yes)"); 78 "AQP1 on startup (0: no (default), 1: yes)");
@@ -91,6 +93,8 @@ MODULE_PARM_DESC(poll_all_eqs,
91 " (0: no, 1: yes (default))"); 93 " (0: no, 1: yes (default))");
92MODULE_PARM_DESC(static_rate, 94MODULE_PARM_DESC(static_rate,
93 "set permanent static rate (default: disabled)"); 95 "set permanent static rate (default: disabled)");
96MODULE_PARM_DESC(scaling_code,
97 "set scaling code (0: disabled, 1: enabled/default)");
94 98
95spinlock_t ehca_qp_idr_lock; 99spinlock_t ehca_qp_idr_lock;
96spinlock_t ehca_cq_idr_lock; 100spinlock_t ehca_cq_idr_lock;
@@ -432,8 +436,8 @@ static int ehca_destroy_aqp1(struct ehca_sport *sport)
432 436
433static ssize_t ehca_show_debug_level(struct device_driver *ddp, char *buf) 437static ssize_t ehca_show_debug_level(struct device_driver *ddp, char *buf)
434{ 438{
435 return snprintf(buf, PAGE_SIZE, "%d\n", 439 return snprintf(buf, PAGE_SIZE, "%d\n",
436 ehca_debug_level); 440 ehca_debug_level);
437} 441}
438 442
439static ssize_t ehca_store_debug_level(struct device_driver *ddp, 443static ssize_t ehca_store_debug_level(struct device_driver *ddp,
@@ -778,8 +782,24 @@ void ehca_poll_eqs(unsigned long data)
778 782
779 spin_lock(&shca_list_lock); 783 spin_lock(&shca_list_lock);
780 list_for_each_entry(shca, &shca_list, shca_list) { 784 list_for_each_entry(shca, &shca_list, shca_list) {
781 if (shca->eq.is_initialized) 785 if (shca->eq.is_initialized) {
782 ehca_tasklet_eq((unsigned long)(void*)shca); 786 /* call deadman proc only if eq ptr does not change */
787 struct ehca_eq *eq = &shca->eq;
788 int max = 3;
789 volatile u64 q_ofs, q_ofs2;
790 u64 flags;
791 spin_lock_irqsave(&eq->spinlock, flags);
792 q_ofs = eq->ipz_queue.current_q_offset;
793 spin_unlock_irqrestore(&eq->spinlock, flags);
794 do {
795 spin_lock_irqsave(&eq->spinlock, flags);
796 q_ofs2 = eq->ipz_queue.current_q_offset;
797 spin_unlock_irqrestore(&eq->spinlock, flags);
798 max--;
799 } while (q_ofs == q_ofs2 && max > 0);
800 if (q_ofs == q_ofs2)
801 ehca_process_eq(shca, 0);
802 }
783 } 803 }
784 mod_timer(&poll_eqs_timer, jiffies + HZ); 804 mod_timer(&poll_eqs_timer, jiffies + HZ);
785 spin_unlock(&shca_list_lock); 805 spin_unlock(&shca_list_lock);
@@ -790,7 +810,7 @@ int __init ehca_module_init(void)
790 int ret; 810 int ret;
791 811
792 printk(KERN_INFO "eHCA Infiniband Device Driver " 812 printk(KERN_INFO "eHCA Infiniband Device Driver "
793 "(Rel.: SVNEHCA_0020)\n"); 813 "(Rel.: SVNEHCA_0022)\n");
794 idr_init(&ehca_qp_idr); 814 idr_init(&ehca_qp_idr);
795 idr_init(&ehca_cq_idr); 815 idr_init(&ehca_cq_idr);
796 spin_lock_init(&ehca_qp_idr_lock); 816 spin_lock_init(&ehca_qp_idr_lock);
diff --git a/drivers/infiniband/hw/ehca/ipz_pt_fn.h b/drivers/infiniband/hw/ehca/ipz_pt_fn.h
index dc3bda2634..8199c45768 100644
--- a/drivers/infiniband/hw/ehca/ipz_pt_fn.h
+++ b/drivers/infiniband/hw/ehca/ipz_pt_fn.h
@@ -79,7 +79,7 @@ static inline void *ipz_qeit_calc(struct ipz_queue *queue, u64 q_offset)
79 if (q_offset >= queue->queue_length) 79 if (q_offset >= queue->queue_length)
80 return NULL; 80 return NULL;
81 current_page = (queue->queue_pages)[q_offset >> EHCA_PAGESHIFT]; 81 current_page = (queue->queue_pages)[q_offset >> EHCA_PAGESHIFT];
82 return &current_page->entries[q_offset & (EHCA_PAGESIZE - 1)]; 82 return &current_page->entries[q_offset & (EHCA_PAGESIZE - 1)];
83} 83}
84 84
85/* 85/*
@@ -247,6 +247,15 @@ static inline void *ipz_eqit_eq_get_inc_valid(struct ipz_queue *queue)
247 return ret; 247 return ret;
248} 248}
249 249
250static inline void *ipz_eqit_eq_peek_valid(struct ipz_queue *queue)
251{
252 void *ret = ipz_qeit_get(queue);
253 u32 qe = *(u8 *) ret;
254 if ((qe >> 7) != (queue->toggle_state & 1))
255 return NULL;
256 return ret;
257}
258
250/* returns address (GX) of first queue entry */ 259/* returns address (GX) of first queue entry */
251static inline u64 ipz_qpt_get_firstpage(struct ipz_qpt *qpt) 260static inline u64 ipz_qpt_get_firstpage(struct ipz_qpt *qpt)
252{ 261{
diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
index 6e0f2b8918..f6f9490408 100644
--- a/drivers/infiniband/hw/ipath/ipath_dma.c
+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
@@ -96,8 +96,8 @@ static void ipath_dma_unmap_page(struct ib_device *dev,
96 BUG_ON(!valid_dma_direction(direction)); 96 BUG_ON(!valid_dma_direction(direction));
97} 97}
98 98
99int ipath_map_sg(struct ib_device *dev, struct scatterlist *sg, int nents, 99static int ipath_map_sg(struct ib_device *dev, struct scatterlist *sg, int nents,
100 enum dma_data_direction direction) 100 enum dma_data_direction direction)
101{ 101{
102 u64 addr; 102 u64 addr;
103 int i; 103 int i;
diff --git a/drivers/infiniband/hw/ipath/ipath_iba6110.c b/drivers/infiniband/hw/ipath/ipath_iba6110.c
index 7468477ba8..9934825450 100644
--- a/drivers/infiniband/hw/ipath/ipath_iba6110.c
+++ b/drivers/infiniband/hw/ipath/ipath_iba6110.c
@@ -1534,7 +1534,7 @@ static int ipath_ht_early_init(struct ipath_devdata *dd)
1534 * @kbase: ipath_base_info pointer 1534 * @kbase: ipath_base_info pointer
1535 * 1535 *
1536 * We set the PCIE flag because the lower bandwidth on PCIe vs 1536 * We set the PCIE flag because the lower bandwidth on PCIe vs
1537 * HyperTransport can affect some user packet algorithims. 1537 * HyperTransport can affect some user packet algorithms.
1538 */ 1538 */
1539static int ipath_ht_get_base_info(struct ipath_portdata *pd, void *kbase) 1539static int ipath_ht_get_base_info(struct ipath_portdata *pd, void *kbase)
1540{ 1540{
diff --git a/drivers/infiniband/hw/ipath/ipath_iba6120.c b/drivers/infiniband/hw/ipath/ipath_iba6120.c
index ae8bf9950c..05918e1e7c 100644
--- a/drivers/infiniband/hw/ipath/ipath_iba6120.c
+++ b/drivers/infiniband/hw/ipath/ipath_iba6120.c
@@ -1293,7 +1293,7 @@ int __attribute__((weak)) ipath_unordered_wc(void)
1293 * @kbase: ipath_base_info pointer 1293 * @kbase: ipath_base_info pointer
1294 * 1294 *
1295 * We set the PCIE flag because the lower bandwidth on PCIe vs 1295 * We set the PCIE flag because the lower bandwidth on PCIe vs
1296 * HyperTransport can affect some user packet algorithims. 1296 * HyperTransport can affect some user packet algorithms.
1297 */ 1297 */
1298static int ipath_pe_get_base_info(struct ipath_portdata *pd, void *kbase) 1298static int ipath_pe_get_base_info(struct ipath_portdata *pd, void *kbase)
1299{ 1299{
diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c
index 0b9d053a59..48f7c65e9a 100644
--- a/drivers/infiniband/hw/mthca/mthca_memfree.c
+++ b/drivers/infiniband/hw/mthca/mthca_memfree.c
@@ -175,7 +175,9 @@ struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages,
175 if (!ret) { 175 if (!ret) {
176 ++chunk->npages; 176 ++chunk->npages;
177 177
178 if (!coherent && chunk->npages == MTHCA_ICM_CHUNK_LEN) { 178 if (coherent)
179 ++chunk->nsg;
180 else if (chunk->npages == MTHCA_ICM_CHUNK_LEN) {
179 chunk->nsg = pci_map_sg(dev->pdev, chunk->mem, 181 chunk->nsg = pci_map_sg(dev->pdev, chunk->mem,
180 chunk->npages, 182 chunk->npages,
181 PCI_DMA_BIDIRECTIONAL); 183 PCI_DMA_BIDIRECTIONAL);
diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
index 6037dd3f87..8e4846b5c6 100644
--- a/drivers/infiniband/hw/mthca/mthca_mr.c
+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
@@ -310,8 +310,9 @@ int mthca_write_mtt_size(struct mthca_dev *dev)
310 return mthca_is_memfree(dev) ? (PAGE_SIZE / sizeof (u64)) : 0x7ffffff; 310 return mthca_is_memfree(dev) ? (PAGE_SIZE / sizeof (u64)) : 0x7ffffff;
311} 311}
312 312
313void mthca_tavor_write_mtt_seg(struct mthca_dev *dev, struct mthca_mtt *mtt, 313static void mthca_tavor_write_mtt_seg(struct mthca_dev *dev,
314 int start_index, u64 *buffer_list, int list_len) 314 struct mthca_mtt *mtt, int start_index,
315 u64 *buffer_list, int list_len)
315{ 316{
316 u64 __iomem *mtts; 317 u64 __iomem *mtts;
317 int i; 318 int i;
@@ -323,8 +324,9 @@ void mthca_tavor_write_mtt_seg(struct mthca_dev *dev, struct mthca_mtt *mtt,
323 mtts + i); 324 mtts + i);
324} 325}
325 326
326void mthca_arbel_write_mtt_seg(struct mthca_dev *dev, struct mthca_mtt *mtt, 327static void mthca_arbel_write_mtt_seg(struct mthca_dev *dev,
327 int start_index, u64 *buffer_list, int list_len) 328 struct mthca_mtt *mtt, int start_index,
329 u64 *buffer_list, int list_len)
328{ 330{
329 __be64 *mtts; 331 __be64 *mtts;
330 dma_addr_t dma_handle; 332 dma_addr_t dma_handle;
diff --git a/drivers/infiniband/hw/mthca/mthca_qp.c b/drivers/infiniband/hw/mthca/mthca_qp.c
index 224c93dd29..1c6b63aca2 100644
--- a/drivers/infiniband/hw/mthca/mthca_qp.c
+++ b/drivers/infiniband/hw/mthca/mthca_qp.c
@@ -573,6 +573,11 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask,
573 goto out; 573 goto out;
574 } 574 }
575 575
576 if (cur_state == new_state && cur_state == IB_QPS_RESET) {
577 err = 0;
578 goto out;
579 }
580
576 if ((attr_mask & IB_QP_PKEY_INDEX) && 581 if ((attr_mask & IB_QP_PKEY_INDEX) &&
577 attr->pkey_index >= dev->limits.pkey_table_len) { 582 attr->pkey_index >= dev->limits.pkey_table_len) {
578 mthca_dbg(dev, "P_Key index (%u) too large. max is %d\n", 583 mthca_dbg(dev, "P_Key index (%u) too large. max is %d\n",
@@ -1083,21 +1088,21 @@ static void mthca_unmap_memfree(struct mthca_dev *dev,
1083static int mthca_alloc_memfree(struct mthca_dev *dev, 1088static int mthca_alloc_memfree(struct mthca_dev *dev,
1084 struct mthca_qp *qp) 1089 struct mthca_qp *qp)
1085{ 1090{
1086 int ret = 0;
1087
1088 if (mthca_is_memfree(dev)) { 1091 if (mthca_is_memfree(dev)) {
1089 qp->rq.db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_RQ, 1092 qp->rq.db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_RQ,
1090 qp->qpn, &qp->rq.db); 1093 qp->qpn, &qp->rq.db);
1091 if (qp->rq.db_index < 0) 1094 if (qp->rq.db_index < 0)
1092 return ret; 1095 return -ENOMEM;
1093 1096
1094 qp->sq.db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_SQ, 1097 qp->sq.db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_SQ,
1095 qp->qpn, &qp->sq.db); 1098 qp->qpn, &qp->sq.db);
1096 if (qp->sq.db_index < 0) 1099 if (qp->sq.db_index < 0) {
1097 mthca_free_db(dev, MTHCA_DB_TYPE_RQ, qp->rq.db_index); 1100 mthca_free_db(dev, MTHCA_DB_TYPE_RQ, qp->rq.db_index);
1101 return -ENOMEM;
1102 }
1098 } 1103 }
1099 1104
1100 return ret; 1105 return 0;
1101} 1106}
1102 1107
1103static void mthca_free_memfree(struct mthca_dev *dev, 1108static void mthca_free_memfree(struct mthca_dev *dev,
diff --git a/drivers/infiniband/ulp/ipoib/ipoib.h b/drivers/infiniband/ulp/ipoib/ipoib.h
index 2594db2030..fd558267d1 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib.h
+++ b/drivers/infiniband/ulp/ipoib/ipoib.h
@@ -219,7 +219,6 @@ struct ipoib_dev_priv {
219 219
220 union ib_gid local_gid; 220 union ib_gid local_gid;
221 u16 local_lid; 221 u16 local_lid;
222 u8 local_rate;
223 222
224 unsigned int admin_mtu; 223 unsigned int admin_mtu;
225 unsigned int mcast_mtu; 224 unsigned int mcast_mtu;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
index 2d483874a5..3484e8ba24 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -65,14 +65,14 @@ struct ipoib_cm_id {
65static int ipoib_cm_tx_handler(struct ib_cm_id *cm_id, 65static int ipoib_cm_tx_handler(struct ib_cm_id *cm_id,
66 struct ib_cm_event *event); 66 struct ib_cm_event *event);
67 67
68static void ipoib_cm_dma_unmap_rx(struct ipoib_dev_priv *priv, 68static void ipoib_cm_dma_unmap_rx(struct ipoib_dev_priv *priv, int frags,
69 u64 mapping[IPOIB_CM_RX_SG]) 69 u64 mapping[IPOIB_CM_RX_SG])
70{ 70{
71 int i; 71 int i;
72 72
73 ib_dma_unmap_single(priv->ca, mapping[0], IPOIB_CM_HEAD_SIZE, DMA_FROM_DEVICE); 73 ib_dma_unmap_single(priv->ca, mapping[0], IPOIB_CM_HEAD_SIZE, DMA_FROM_DEVICE);
74 74
75 for (i = 0; i < IPOIB_CM_RX_SG - 1; ++i) 75 for (i = 0; i < frags; ++i)
76 ib_dma_unmap_single(priv->ca, mapping[i + 1], PAGE_SIZE, DMA_FROM_DEVICE); 76 ib_dma_unmap_single(priv->ca, mapping[i + 1], PAGE_SIZE, DMA_FROM_DEVICE);
77} 77}
78 78
@@ -90,7 +90,8 @@ static int ipoib_cm_post_receive(struct net_device *dev, int id)
90 ret = ib_post_srq_recv(priv->cm.srq, &priv->cm.rx_wr, &bad_wr); 90 ret = ib_post_srq_recv(priv->cm.srq, &priv->cm.rx_wr, &bad_wr);
91 if (unlikely(ret)) { 91 if (unlikely(ret)) {
92 ipoib_warn(priv, "post srq failed for buf %d (%d)\n", id, ret); 92 ipoib_warn(priv, "post srq failed for buf %d (%d)\n", id, ret);
93 ipoib_cm_dma_unmap_rx(priv, priv->cm.srq_ring[id].mapping); 93 ipoib_cm_dma_unmap_rx(priv, IPOIB_CM_RX_SG - 1,
94 priv->cm.srq_ring[id].mapping);
94 dev_kfree_skb_any(priv->cm.srq_ring[id].skb); 95 dev_kfree_skb_any(priv->cm.srq_ring[id].skb);
95 priv->cm.srq_ring[id].skb = NULL; 96 priv->cm.srq_ring[id].skb = NULL;
96 } 97 }
@@ -98,8 +99,8 @@ static int ipoib_cm_post_receive(struct net_device *dev, int id)
98 return ret; 99 return ret;
99} 100}
100 101
101static int ipoib_cm_alloc_rx_skb(struct net_device *dev, int id, 102static struct sk_buff *ipoib_cm_alloc_rx_skb(struct net_device *dev, int id, int frags,
102 u64 mapping[IPOIB_CM_RX_SG]) 103 u64 mapping[IPOIB_CM_RX_SG])
103{ 104{
104 struct ipoib_dev_priv *priv = netdev_priv(dev); 105 struct ipoib_dev_priv *priv = netdev_priv(dev);
105 struct sk_buff *skb; 106 struct sk_buff *skb;
@@ -107,7 +108,7 @@ static int ipoib_cm_alloc_rx_skb(struct net_device *dev, int id,
107 108
108 skb = dev_alloc_skb(IPOIB_CM_HEAD_SIZE + 12); 109 skb = dev_alloc_skb(IPOIB_CM_HEAD_SIZE + 12);
109 if (unlikely(!skb)) 110 if (unlikely(!skb))
110 return -ENOMEM; 111 return NULL;
111 112
112 /* 113 /*
113 * IPoIB adds a 4 byte header. So we need 12 more bytes to align the 114 * IPoIB adds a 4 byte header. So we need 12 more bytes to align the
@@ -119,10 +120,10 @@ static int ipoib_cm_alloc_rx_skb(struct net_device *dev, int id,
119 DMA_FROM_DEVICE); 120 DMA_FROM_DEVICE);
120 if (unlikely(ib_dma_mapping_error(priv->ca, mapping[0]))) { 121 if (unlikely(ib_dma_mapping_error(priv->ca, mapping[0]))) {
121 dev_kfree_skb_any(skb); 122 dev_kfree_skb_any(skb);
122 return -EIO; 123 return NULL;
123 } 124 }
124 125
125 for (i = 0; i < IPOIB_CM_RX_SG - 1; i++) { 126 for (i = 0; i < frags; i++) {
126 struct page *page = alloc_page(GFP_ATOMIC); 127 struct page *page = alloc_page(GFP_ATOMIC);
127 128
128 if (!page) 129 if (!page)
@@ -136,7 +137,7 @@ static int ipoib_cm_alloc_rx_skb(struct net_device *dev, int id,
136 } 137 }
137 138
138 priv->cm.srq_ring[id].skb = skb; 139 priv->cm.srq_ring[id].skb = skb;
139 return 0; 140 return skb;
140 141
141partial_error: 142partial_error:
142 143
@@ -145,8 +146,8 @@ partial_error:
145 for (; i >= 0; --i) 146 for (; i >= 0; --i)
146 ib_dma_unmap_single(priv->ca, mapping[i + 1], PAGE_SIZE, DMA_FROM_DEVICE); 147 ib_dma_unmap_single(priv->ca, mapping[i + 1], PAGE_SIZE, DMA_FROM_DEVICE);
147 148
148 kfree_skb(skb); 149 dev_kfree_skb_any(skb);
149 return -ENOMEM; 150 return NULL;
150} 151}
151 152
152static struct ib_qp *ipoib_cm_create_rx_qp(struct net_device *dev, 153static struct ib_qp *ipoib_cm_create_rx_qp(struct net_device *dev,
@@ -309,7 +310,7 @@ static int ipoib_cm_rx_handler(struct ib_cm_id *cm_id,
309} 310}
310/* Adjust length of skb with fragments to match received data */ 311/* Adjust length of skb with fragments to match received data */
311static void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space, 312static void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space,
312 unsigned int length) 313 unsigned int length, struct sk_buff *toskb)
313{ 314{
314 int i, num_frags; 315 int i, num_frags;
315 unsigned int size; 316 unsigned int size;
@@ -326,7 +327,7 @@ static void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space,
326 327
327 if (length == 0) { 328 if (length == 0) {
328 /* don't need this page */ 329 /* don't need this page */
329 __free_page(frag->page); 330 skb_fill_page_desc(toskb, i, frag->page, 0, PAGE_SIZE);
330 --skb_shinfo(skb)->nr_frags; 331 --skb_shinfo(skb)->nr_frags;
331 } else { 332 } else {
332 size = min(length, (unsigned) PAGE_SIZE); 333 size = min(length, (unsigned) PAGE_SIZE);
@@ -344,10 +345,11 @@ void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
344{ 345{
345 struct ipoib_dev_priv *priv = netdev_priv(dev); 346 struct ipoib_dev_priv *priv = netdev_priv(dev);
346 unsigned int wr_id = wc->wr_id & ~IPOIB_CM_OP_SRQ; 347 unsigned int wr_id = wc->wr_id & ~IPOIB_CM_OP_SRQ;
347 struct sk_buff *skb; 348 struct sk_buff *skb, *newskb;
348 struct ipoib_cm_rx *p; 349 struct ipoib_cm_rx *p;
349 unsigned long flags; 350 unsigned long flags;
350 u64 mapping[IPOIB_CM_RX_SG]; 351 u64 mapping[IPOIB_CM_RX_SG];
352 int frags;
351 353
352 ipoib_dbg_data(priv, "cm recv completion: id %d, op %d, status: %d\n", 354 ipoib_dbg_data(priv, "cm recv completion: id %d, op %d, status: %d\n",
353 wr_id, wc->opcode, wc->status); 355 wr_id, wc->opcode, wc->status);
@@ -383,7 +385,11 @@ void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
383 } 385 }
384 } 386 }
385 387
386 if (unlikely(ipoib_cm_alloc_rx_skb(dev, wr_id, mapping))) { 388 frags = PAGE_ALIGN(wc->byte_len - min(wc->byte_len,
389 (unsigned)IPOIB_CM_HEAD_SIZE)) / PAGE_SIZE;
390
391 newskb = ipoib_cm_alloc_rx_skb(dev, wr_id, frags, mapping);
392 if (unlikely(!newskb)) {
387 /* 393 /*
388 * If we can't allocate a new RX buffer, dump 394 * If we can't allocate a new RX buffer, dump
389 * this packet and reuse the old buffer. 395 * this packet and reuse the old buffer.
@@ -393,13 +399,13 @@ void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
393 goto repost; 399 goto repost;
394 } 400 }
395 401
396 ipoib_cm_dma_unmap_rx(priv, priv->cm.srq_ring[wr_id].mapping); 402 ipoib_cm_dma_unmap_rx(priv, frags, priv->cm.srq_ring[wr_id].mapping);
397 memcpy(priv->cm.srq_ring[wr_id].mapping, mapping, sizeof mapping); 403 memcpy(priv->cm.srq_ring[wr_id].mapping, mapping, (frags + 1) * sizeof *mapping);
398 404
399 ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n", 405 ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n",
400 wc->byte_len, wc->slid); 406 wc->byte_len, wc->slid);
401 407
402 skb_put_frags(skb, IPOIB_CM_HEAD_SIZE, wc->byte_len); 408 skb_put_frags(skb, IPOIB_CM_HEAD_SIZE, wc->byte_len, newskb);
403 409
404 skb->protocol = ((struct ipoib_header *) skb->data)->proto; 410 skb->protocol = ((struct ipoib_header *) skb->data)->proto;
405 skb->mac.raw = skb->data; 411 skb->mac.raw = skb->data;
@@ -1138,7 +1144,7 @@ static ssize_t set_mode(struct device *d, struct device_attribute *attr,
1138 return -EINVAL; 1144 return -EINVAL;
1139} 1145}
1140 1146
1141static DEVICE_ATTR(mode, S_IWUGO | S_IRUGO, show_mode, set_mode); 1147static DEVICE_ATTR(mode, S_IWUSR | S_IRUGO, show_mode, set_mode);
1142 1148
1143int ipoib_cm_add_mode_attr(struct net_device *dev) 1149int ipoib_cm_add_mode_attr(struct net_device *dev)
1144{ 1150{
@@ -1193,7 +1199,8 @@ int ipoib_cm_dev_init(struct net_device *dev)
1193 priv->cm.rx_wr.num_sge = IPOIB_CM_RX_SG; 1199 priv->cm.rx_wr.num_sge = IPOIB_CM_RX_SG;
1194 1200
1195 for (i = 0; i < ipoib_recvq_size; ++i) { 1201 for (i = 0; i < ipoib_recvq_size; ++i) {
1196 if (ipoib_cm_alloc_rx_skb(dev, i, priv->cm.srq_ring[i].mapping)) { 1202 if (!ipoib_cm_alloc_rx_skb(dev, i, IPOIB_CM_RX_SG - 1,
1203 priv->cm.srq_ring[i].mapping)) {
1197 ipoib_warn(priv, "failed to allocate receive buffer %d\n", i); 1204 ipoib_warn(priv, "failed to allocate receive buffer %d\n", i);
1198 ipoib_cm_dev_cleanup(dev); 1205 ipoib_cm_dev_cleanup(dev);
1199 return -ENOMEM; 1206 return -ENOMEM;
@@ -1228,7 +1235,8 @@ void ipoib_cm_dev_cleanup(struct net_device *dev)
1228 return; 1235 return;
1229 for (i = 0; i < ipoib_recvq_size; ++i) 1236 for (i = 0; i < ipoib_recvq_size; ++i)
1230 if (priv->cm.srq_ring[i].skb) { 1237 if (priv->cm.srq_ring[i].skb) {
1231 ipoib_cm_dma_unmap_rx(priv, priv->cm.srq_ring[i].mapping); 1238 ipoib_cm_dma_unmap_rx(priv, IPOIB_CM_RX_SG - 1,
1239 priv->cm.srq_ring[i].mapping);
1232 dev_kfree_skb_any(priv->cm.srq_ring[i].skb); 1240 dev_kfree_skb_any(priv->cm.srq_ring[i].skb);
1233 priv->cm.srq_ring[i].skb = NULL; 1241 priv->cm.srq_ring[i].skb = NULL;
1234 } 1242 }
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 18d27fd352..f9dbc6f681 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -385,7 +385,7 @@ static void path_rec_completion(int status,
385 struct sk_buff *skb; 385 struct sk_buff *skb;
386 unsigned long flags; 386 unsigned long flags;
387 387
388 if (pathrec) 388 if (!status)
389 ipoib_dbg(priv, "PathRec LID 0x%04x for GID " IPOIB_GID_FMT "\n", 389 ipoib_dbg(priv, "PathRec LID 0x%04x for GID " IPOIB_GID_FMT "\n",
390 be16_to_cpu(pathrec->dlid), IPOIB_GID_ARG(pathrec->dgid)); 390 be16_to_cpu(pathrec->dlid), IPOIB_GID_ARG(pathrec->dgid));
391 else 391 else
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
index fea737f520..56c87a81bb 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
@@ -60,14 +60,11 @@ static DEFINE_MUTEX(mcast_mutex);
60/* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */ 60/* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */
61struct ipoib_mcast { 61struct ipoib_mcast {
62 struct ib_sa_mcmember_rec mcmember; 62 struct ib_sa_mcmember_rec mcmember;
63 struct ib_sa_multicast *mc;
63 struct ipoib_ah *ah; 64 struct ipoib_ah *ah;
64 65
65 struct rb_node rb_node; 66 struct rb_node rb_node;
66 struct list_head list; 67 struct list_head list;
67 struct completion done;
68
69 int query_id;
70 struct ib_sa_query *query;
71 68
72 unsigned long created; 69 unsigned long created;
73 unsigned long backoff; 70 unsigned long backoff;
@@ -299,18 +296,22 @@ static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast,
299 return 0; 296 return 0;
300} 297}
301 298
302static void 299static int
303ipoib_mcast_sendonly_join_complete(int status, 300ipoib_mcast_sendonly_join_complete(int status,
304 struct ib_sa_mcmember_rec *mcmember, 301 struct ib_sa_multicast *multicast)
305 void *mcast_ptr)
306{ 302{
307 struct ipoib_mcast *mcast = mcast_ptr; 303 struct ipoib_mcast *mcast = multicast->context;
308 struct net_device *dev = mcast->dev; 304 struct net_device *dev = mcast->dev;
309 struct ipoib_dev_priv *priv = netdev_priv(dev); 305 struct ipoib_dev_priv *priv = netdev_priv(dev);
310 306
307 /* We trap for port events ourselves. */
308 if (status == -ENETRESET)
309 return 0;
310
311 if (!status) 311 if (!status)
312 ipoib_mcast_join_finish(mcast, mcmember); 312 status = ipoib_mcast_join_finish(mcast, &multicast->rec);
313 else { 313
314 if (status) {
314 if (mcast->logcount++ < 20) 315 if (mcast->logcount++ < 20)
315 ipoib_dbg_mcast(netdev_priv(dev), "multicast join failed for " 316 ipoib_dbg_mcast(netdev_priv(dev), "multicast join failed for "
316 IPOIB_GID_FMT ", status %d\n", 317 IPOIB_GID_FMT ", status %d\n",
@@ -325,11 +326,10 @@ ipoib_mcast_sendonly_join_complete(int status,
325 spin_unlock_irq(&priv->tx_lock); 326 spin_unlock_irq(&priv->tx_lock);
326 327
327 /* Clear the busy flag so we try again */ 328 /* Clear the busy flag so we try again */
328 clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); 329 status = test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY,
329 mcast->query = NULL; 330 &mcast->flags);
330 } 331 }
331 332 return status;
332 complete(&mcast->done);
333} 333}
334 334
335static int ipoib_mcast_sendonly_join(struct ipoib_mcast *mcast) 335static int ipoib_mcast_sendonly_join(struct ipoib_mcast *mcast)
@@ -359,35 +359,33 @@ static int ipoib_mcast_sendonly_join(struct ipoib_mcast *mcast)
359 rec.port_gid = priv->local_gid; 359 rec.port_gid = priv->local_gid;
360 rec.pkey = cpu_to_be16(priv->pkey); 360 rec.pkey = cpu_to_be16(priv->pkey);
361 361
362 init_completion(&mcast->done); 362 mcast->mc = ib_sa_join_multicast(&ipoib_sa_client, priv->ca,
363 363 priv->port, &rec,
364 ret = ib_sa_mcmember_rec_set(&ipoib_sa_client, priv->ca, priv->port, &rec, 364 IB_SA_MCMEMBER_REC_MGID |
365 IB_SA_MCMEMBER_REC_MGID | 365 IB_SA_MCMEMBER_REC_PORT_GID |
366 IB_SA_MCMEMBER_REC_PORT_GID | 366 IB_SA_MCMEMBER_REC_PKEY |
367 IB_SA_MCMEMBER_REC_PKEY | 367 IB_SA_MCMEMBER_REC_JOIN_STATE,
368 IB_SA_MCMEMBER_REC_JOIN_STATE, 368 GFP_ATOMIC,
369 1000, GFP_ATOMIC, 369 ipoib_mcast_sendonly_join_complete,
370 ipoib_mcast_sendonly_join_complete, 370 mcast);
371 mcast, &mcast->query); 371 if (IS_ERR(mcast->mc)) {
372 if (ret < 0) { 372 ret = PTR_ERR(mcast->mc);
373 ipoib_warn(priv, "ib_sa_mcmember_rec_set failed (ret = %d)\n", 373 clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
374 ipoib_warn(priv, "ib_sa_join_multicast failed (ret = %d)\n",
374 ret); 375 ret);
375 } else { 376 } else {
376 ipoib_dbg_mcast(priv, "no multicast record for " IPOIB_GID_FMT 377 ipoib_dbg_mcast(priv, "no multicast record for " IPOIB_GID_FMT
377 ", starting join\n", 378 ", starting join\n",
378 IPOIB_GID_ARG(mcast->mcmember.mgid)); 379 IPOIB_GID_ARG(mcast->mcmember.mgid));
379
380 mcast->query_id = ret;
381 } 380 }
382 381
383 return ret; 382 return ret;
384} 383}
385 384
386static void ipoib_mcast_join_complete(int status, 385static int ipoib_mcast_join_complete(int status,
387 struct ib_sa_mcmember_rec *mcmember, 386 struct ib_sa_multicast *multicast)
388 void *mcast_ptr)
389{ 387{
390 struct ipoib_mcast *mcast = mcast_ptr; 388 struct ipoib_mcast *mcast = multicast->context;
391 struct net_device *dev = mcast->dev; 389 struct net_device *dev = mcast->dev;
392 struct ipoib_dev_priv *priv = netdev_priv(dev); 390 struct ipoib_dev_priv *priv = netdev_priv(dev);
393 391
@@ -395,24 +393,29 @@ static void ipoib_mcast_join_complete(int status,
395 " (status %d)\n", 393 " (status %d)\n",
396 IPOIB_GID_ARG(mcast->mcmember.mgid), status); 394 IPOIB_GID_ARG(mcast->mcmember.mgid), status);
397 395
398 if (!status && !ipoib_mcast_join_finish(mcast, mcmember)) { 396 /* We trap for port events ourselves. */
397 if (status == -ENETRESET)
398 return 0;
399
400 if (!status)
401 status = ipoib_mcast_join_finish(mcast, &multicast->rec);
402
403 if (!status) {
399 mcast->backoff = 1; 404 mcast->backoff = 1;
400 mutex_lock(&mcast_mutex); 405 mutex_lock(&mcast_mutex);
401 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) 406 if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
402 queue_delayed_work(ipoib_workqueue, 407 queue_delayed_work(ipoib_workqueue,
403 &priv->mcast_task, 0); 408 &priv->mcast_task, 0);
404 mutex_unlock(&mcast_mutex); 409 mutex_unlock(&mcast_mutex);
405 complete(&mcast->done);
406 return;
407 }
408 410
409 if (status == -EINTR) { 411 if (mcast == priv->broadcast)
410 complete(&mcast->done); 412 netif_carrier_on(dev);
411 return; 413
414 return 0;
412 } 415 }
413 416
414 if (status && mcast->logcount++ < 20) { 417 if (mcast->logcount++ < 20) {
415 if (status == -ETIMEDOUT || status == -EINTR) { 418 if (status == -ETIMEDOUT) {
416 ipoib_dbg_mcast(priv, "multicast join failed for " IPOIB_GID_FMT 419 ipoib_dbg_mcast(priv, "multicast join failed for " IPOIB_GID_FMT
417 ", status %d\n", 420 ", status %d\n",
418 IPOIB_GID_ARG(mcast->mcmember.mgid), 421 IPOIB_GID_ARG(mcast->mcmember.mgid),
@@ -429,24 +432,18 @@ static void ipoib_mcast_join_complete(int status,
429 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS) 432 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS)
430 mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS; 433 mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS;
431 434
432 mutex_lock(&mcast_mutex); 435 /* Clear the busy flag so we try again */
436 status = test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
433 437
438 mutex_lock(&mcast_mutex);
434 spin_lock_irq(&priv->lock); 439 spin_lock_irq(&priv->lock);
435 mcast->query = NULL; 440 if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
436 441 queue_delayed_work(ipoib_workqueue, &priv->mcast_task,
437 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) { 442 mcast->backoff * HZ);
438 if (status == -ETIMEDOUT)
439 queue_delayed_work(ipoib_workqueue, &priv->mcast_task,
440 0);
441 else
442 queue_delayed_work(ipoib_workqueue, &priv->mcast_task,
443 mcast->backoff * HZ);
444 } else
445 complete(&mcast->done);
446 spin_unlock_irq(&priv->lock); 443 spin_unlock_irq(&priv->lock);
447 mutex_unlock(&mcast_mutex); 444 mutex_unlock(&mcast_mutex);
448 445
449 return; 446 return status;
450} 447}
451 448
452static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast, 449static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast,
@@ -495,15 +492,14 @@ static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast,
495 rec.hop_limit = priv->broadcast->mcmember.hop_limit; 492 rec.hop_limit = priv->broadcast->mcmember.hop_limit;
496 } 493 }
497 494
498 init_completion(&mcast->done); 495 set_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
499 496 mcast->mc = ib_sa_join_multicast(&ipoib_sa_client, priv->ca, priv->port,
500 ret = ib_sa_mcmember_rec_set(&ipoib_sa_client, priv->ca, priv->port, 497 &rec, comp_mask, GFP_KERNEL,
501 &rec, comp_mask, mcast->backoff * 1000, 498 ipoib_mcast_join_complete, mcast);
502 GFP_ATOMIC, ipoib_mcast_join_complete, 499 if (IS_ERR(mcast->mc)) {
503 mcast, &mcast->query); 500 clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
504 501 ret = PTR_ERR(mcast->mc);
505 if (ret < 0) { 502 ipoib_warn(priv, "ib_sa_join_multicast failed, status %d\n", ret);
506 ipoib_warn(priv, "ib_sa_mcmember_rec_set failed, status %d\n", ret);
507 503
508 mcast->backoff *= 2; 504 mcast->backoff *= 2;
509 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS) 505 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS)
@@ -515,8 +511,7 @@ static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast,
515 &priv->mcast_task, 511 &priv->mcast_task,
516 mcast->backoff * HZ); 512 mcast->backoff * HZ);
517 mutex_unlock(&mcast_mutex); 513 mutex_unlock(&mcast_mutex);
518 } else 514 }
519 mcast->query_id = ret;
520} 515}
521 516
522void ipoib_mcast_join_task(struct work_struct *work) 517void ipoib_mcast_join_task(struct work_struct *work)
@@ -536,12 +531,10 @@ void ipoib_mcast_join_task(struct work_struct *work)
536 { 531 {
537 struct ib_port_attr attr; 532 struct ib_port_attr attr;
538 533
539 if (!ib_query_port(priv->ca, priv->port, &attr)) { 534 if (!ib_query_port(priv->ca, priv->port, &attr))
540 priv->local_lid = attr.lid; 535 priv->local_lid = attr.lid;
541 priv->local_rate = attr.active_speed * 536 else
542 ib_width_enum_to_int(attr.active_width); 537 ipoib_warn(priv, "ib_query_port failed\n");
543 } else
544 ipoib_warn(priv, "ib_query_port failed\n");
545 } 538 }
546 539
547 if (!priv->broadcast) { 540 if (!priv->broadcast) {
@@ -568,7 +561,8 @@ void ipoib_mcast_join_task(struct work_struct *work)
568 } 561 }
569 562
570 if (!test_bit(IPOIB_MCAST_FLAG_ATTACHED, &priv->broadcast->flags)) { 563 if (!test_bit(IPOIB_MCAST_FLAG_ATTACHED, &priv->broadcast->flags)) {
571 ipoib_mcast_join(dev, priv->broadcast, 0); 564 if (!test_bit(IPOIB_MCAST_FLAG_BUSY, &priv->broadcast->flags))
565 ipoib_mcast_join(dev, priv->broadcast, 0);
572 return; 566 return;
573 } 567 }
574 568
@@ -604,7 +598,6 @@ void ipoib_mcast_join_task(struct work_struct *work)
604 ipoib_dbg_mcast(priv, "successfully joined all multicast groups\n"); 598 ipoib_dbg_mcast(priv, "successfully joined all multicast groups\n");
605 599
606 clear_bit(IPOIB_MCAST_RUN, &priv->flags); 600 clear_bit(IPOIB_MCAST_RUN, &priv->flags);
607 netif_carrier_on(dev);
608} 601}
609 602
610int ipoib_mcast_start_thread(struct net_device *dev) 603int ipoib_mcast_start_thread(struct net_device *dev)
@@ -625,26 +618,9 @@ int ipoib_mcast_start_thread(struct net_device *dev)
625 return 0; 618 return 0;
626} 619}
627 620
628static void wait_for_mcast_join(struct ipoib_dev_priv *priv,
629 struct ipoib_mcast *mcast)
630{
631 spin_lock_irq(&priv->lock);
632 if (mcast && mcast->query) {
633 ib_sa_cancel_query(mcast->query_id, mcast->query);
634 mcast->query = NULL;
635 spin_unlock_irq(&priv->lock);
636 ipoib_dbg_mcast(priv, "waiting for MGID " IPOIB_GID_FMT "\n",
637 IPOIB_GID_ARG(mcast->mcmember.mgid));
638 wait_for_completion(&mcast->done);
639 }
640 else
641 spin_unlock_irq(&priv->lock);
642}
643
644int ipoib_mcast_stop_thread(struct net_device *dev, int flush) 621int ipoib_mcast_stop_thread(struct net_device *dev, int flush)
645{ 622{
646 struct ipoib_dev_priv *priv = netdev_priv(dev); 623 struct ipoib_dev_priv *priv = netdev_priv(dev);
647 struct ipoib_mcast *mcast;
648 624
649 ipoib_dbg_mcast(priv, "stopping multicast thread\n"); 625 ipoib_dbg_mcast(priv, "stopping multicast thread\n");
650 626
@@ -660,52 +636,27 @@ int ipoib_mcast_stop_thread(struct net_device *dev, int flush)
660 if (flush) 636 if (flush)
661 flush_workqueue(ipoib_workqueue); 637 flush_workqueue(ipoib_workqueue);
662 638
663 wait_for_mcast_join(priv, priv->broadcast);
664
665 list_for_each_entry(mcast, &priv->multicast_list, list)
666 wait_for_mcast_join(priv, mcast);
667
668 return 0; 639 return 0;
669} 640}
670 641
671static int ipoib_mcast_leave(struct net_device *dev, struct ipoib_mcast *mcast) 642static int ipoib_mcast_leave(struct net_device *dev, struct ipoib_mcast *mcast)
672{ 643{
673 struct ipoib_dev_priv *priv = netdev_priv(dev); 644 struct ipoib_dev_priv *priv = netdev_priv(dev);
674 struct ib_sa_mcmember_rec rec = {
675 .join_state = 1
676 };
677 int ret = 0; 645 int ret = 0;
678 646
679 if (!test_and_clear_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags)) 647 if (test_and_clear_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags)) {
680 return 0; 648 ipoib_dbg_mcast(priv, "leaving MGID " IPOIB_GID_FMT "\n",
681 649 IPOIB_GID_ARG(mcast->mcmember.mgid));
682 ipoib_dbg_mcast(priv, "leaving MGID " IPOIB_GID_FMT "\n",
683 IPOIB_GID_ARG(mcast->mcmember.mgid));
684
685 rec.mgid = mcast->mcmember.mgid;
686 rec.port_gid = priv->local_gid;
687 rec.pkey = cpu_to_be16(priv->pkey);
688 650
689 /* Remove ourselves from the multicast group */ 651 /* Remove ourselves from the multicast group */
690 ret = ipoib_mcast_detach(dev, be16_to_cpu(mcast->mcmember.mlid), 652 ret = ipoib_mcast_detach(dev, be16_to_cpu(mcast->mcmember.mlid),
691 &mcast->mcmember.mgid); 653 &mcast->mcmember.mgid);
692 if (ret) 654 if (ret)
693 ipoib_warn(priv, "ipoib_mcast_detach failed (result = %d)\n", ret); 655 ipoib_warn(priv, "ipoib_mcast_detach failed (result = %d)\n", ret);
656 }
694 657
695 /* 658 if (test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags))
696 * Just make one shot at leaving and don't wait for a reply; 659 ib_sa_free_multicast(mcast->mc);
697 * if we fail, too bad.
698 */
699 ret = ib_sa_mcmember_rec_delete(&ipoib_sa_client, priv->ca, priv->port, &rec,
700 IB_SA_MCMEMBER_REC_MGID |
701 IB_SA_MCMEMBER_REC_PORT_GID |
702 IB_SA_MCMEMBER_REC_PKEY |
703 IB_SA_MCMEMBER_REC_JOIN_STATE,
704 0, GFP_ATOMIC, NULL,
705 mcast, &mcast->query);
706 if (ret < 0)
707 ipoib_warn(priv, "ib_sa_mcmember_rec_delete failed "
708 "for leave (result = %d)\n", ret);
709 660
710 return 0; 661 return 0;
711} 662}
@@ -758,7 +709,7 @@ void ipoib_mcast_send(struct net_device *dev, void *mgid, struct sk_buff *skb)
758 dev_kfree_skb_any(skb); 709 dev_kfree_skb_any(skb);
759 } 710 }
760 711
761 if (mcast->query) 712 if (test_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags))
762 ipoib_dbg_mcast(priv, "no address vector, " 713 ipoib_dbg_mcast(priv, "no address vector, "
763 "but multicast join already started\n"); 714 "but multicast join already started\n");
764 else if (test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) 715 else if (test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags))
@@ -916,7 +867,6 @@ void ipoib_mcast_restart_task(struct work_struct *work)
916 867
917 /* We have to cancel outside of the spinlock */ 868 /* We have to cancel outside of the spinlock */
918 list_for_each_entry_safe(mcast, tmcast, &remove_list, list) { 869 list_for_each_entry_safe(mcast, tmcast, &remove_list, list) {
919 wait_for_mcast_join(priv, mcast);
920 ipoib_mcast_leave(mcast->dev, mcast); 870 ipoib_mcast_leave(mcast->dev, mcast);
921 ipoib_mcast_free(mcast); 871 ipoib_mcast_free(mcast);
922 } 872 }
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
index 3cb551b887..7f3ec205e3 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
@@ -259,12 +259,13 @@ void ipoib_event(struct ib_event_handler *handler,
259 struct ipoib_dev_priv *priv = 259 struct ipoib_dev_priv *priv =
260 container_of(handler, struct ipoib_dev_priv, event_handler); 260 container_of(handler, struct ipoib_dev_priv, event_handler);
261 261
262 if (record->event == IB_EVENT_PORT_ERR || 262 if ((record->event == IB_EVENT_PORT_ERR ||
263 record->event == IB_EVENT_PKEY_CHANGE || 263 record->event == IB_EVENT_PKEY_CHANGE ||
264 record->event == IB_EVENT_PORT_ACTIVE || 264 record->event == IB_EVENT_PORT_ACTIVE ||
265 record->event == IB_EVENT_LID_CHANGE || 265 record->event == IB_EVENT_LID_CHANGE ||
266 record->event == IB_EVENT_SM_CHANGE || 266 record->event == IB_EVENT_SM_CHANGE ||
267 record->event == IB_EVENT_CLIENT_REREGISTER) { 267 record->event == IB_EVENT_CLIENT_REREGISTER) &&
268 record->element.port_num == priv->port) {
268 ipoib_dbg(priv, "Port state change event\n"); 269 ipoib_dbg(priv, "Port state change event\n");
269 queue_work(ipoib_workqueue, &priv->flush_task); 270 queue_work(ipoib_workqueue, &priv->flush_task);
270 } 271 }
diff --git a/drivers/input/input.c b/drivers/input/input.c
index efa1b1f753..a9a706f8ff 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -588,18 +588,9 @@ static inline void input_proc_exit(void) { }
588static ssize_t input_dev_show_##name(struct class_device *dev, char *buf) \ 588static ssize_t input_dev_show_##name(struct class_device *dev, char *buf) \
589{ \ 589{ \
590 struct input_dev *input_dev = to_input_dev(dev); \ 590 struct input_dev *input_dev = to_input_dev(dev); \
591 int retval; \
592 \ 591 \
593 retval = mutex_lock_interruptible(&input_dev->mutex); \ 592 return scnprintf(buf, PAGE_SIZE, "%s\n", \
594 if (retval) \ 593 input_dev->name ? input_dev->name : ""); \
595 return retval; \
596 \
597 retval = scnprintf(buf, PAGE_SIZE, \
598 "%s\n", input_dev->name ? input_dev->name : ""); \
599 \
600 mutex_unlock(&input_dev->mutex); \
601 \
602 return retval; \
603} \ 594} \
604static CLASS_DEVICE_ATTR(name, S_IRUGO, input_dev_show_##name, NULL); 595static CLASS_DEVICE_ATTR(name, S_IRUGO, input_dev_show_##name, NULL);
605 596
@@ -1049,10 +1040,6 @@ void input_unregister_device(struct input_dev *dev)
1049 sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group); 1040 sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group);
1050 sysfs_remove_group(&dev->cdev.kobj, &input_dev_attr_group); 1041 sysfs_remove_group(&dev->cdev.kobj, &input_dev_attr_group);
1051 1042
1052 mutex_lock(&dev->mutex);
1053 dev->name = dev->phys = dev->uniq = NULL;
1054 mutex_unlock(&dev->mutex);
1055
1056 class_device_unregister(&dev->cdev); 1043 class_device_unregister(&dev->cdev);
1057 1044
1058 input_wakeup_procfs_readers(); 1045 input_wakeup_procfs_readers();
diff --git a/drivers/input/joystick/amijoy.c b/drivers/input/joystick/amijoy.c
index e608691b5a..b0f5541ec3 100644
--- a/drivers/input/joystick/amijoy.c
+++ b/drivers/input/joystick/amijoy.c
@@ -50,8 +50,6 @@ static int amijoy[2] = { 0, 1 };
50module_param_array_named(map, amijoy, uint, NULL, 0); 50module_param_array_named(map, amijoy, uint, NULL, 0);
51MODULE_PARM_DESC(map, "Map of attached joysticks in form of <a>,<b> (default is 0,1)"); 51MODULE_PARM_DESC(map, "Map of attached joysticks in form of <a>,<b> (default is 0,1)");
52 52
53__obsolete_setup("amijoy=");
54
55static int amijoy_used; 53static int amijoy_used;
56static DEFINE_MUTEX(amijoy_mutex); 54static DEFINE_MUTEX(amijoy_mutex);
57static struct input_dev *amijoy_dev[2]; 55static struct input_dev *amijoy_dev[2];
diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
index 7ef68456d7..51f1e4bfff 100644
--- a/drivers/input/joystick/analog.c
+++ b/drivers/input/joystick/analog.c
@@ -58,8 +58,6 @@ static int analog_options[ANALOG_PORTS];
58module_param_array_named(map, js, charp, &js_nargs, 0); 58module_param_array_named(map, js, charp, &js_nargs, 0);
59MODULE_PARM_DESC(map, "Describes analog joysticks type/capabilities"); 59MODULE_PARM_DESC(map, "Describes analog joysticks type/capabilities");
60 60
61__obsolete_setup("js=");
62
63/* 61/*
64 * Times, feature definitions. 62 * Times, feature definitions.
65 */ 63 */
diff --git a/drivers/input/joystick/db9.c b/drivers/input/joystick/db9.c
index 5080e15c6d..b41bd2eb37 100644
--- a/drivers/input/joystick/db9.c
+++ b/drivers/input/joystick/db9.c
@@ -59,10 +59,6 @@ MODULE_PARM_DESC(dev2, "Describes second attached device (<parport#>,<type>)");
59module_param_array_named(dev3, db9[2].args, int, &db9[2].nargs, 0); 59module_param_array_named(dev3, db9[2].args, int, &db9[2].nargs, 0);
60MODULE_PARM_DESC(dev3, "Describes third attached device (<parport#>,<type>)"); 60MODULE_PARM_DESC(dev3, "Describes third attached device (<parport#>,<type>)");
61 61
62__obsolete_setup("db9=");
63__obsolete_setup("db9_2=");
64__obsolete_setup("db9_3=");
65
66#define DB9_ARG_PARPORT 0 62#define DB9_ARG_PARPORT 0
67#define DB9_ARG_MODE 1 63#define DB9_ARG_MODE 1
68 64
diff --git a/drivers/input/joystick/gamecon.c b/drivers/input/joystick/gamecon.c
index fe12aa3739..711e4b3e9e 100644
--- a/drivers/input/joystick/gamecon.c
+++ b/drivers/input/joystick/gamecon.c
@@ -60,10 +60,6 @@ MODULE_PARM_DESC(map2, "Describes second set of devices");
60module_param_array_named(map3, gc[2].args, int, &gc[2].nargs, 0); 60module_param_array_named(map3, gc[2].args, int, &gc[2].nargs, 0);
61MODULE_PARM_DESC(map3, "Describes third set of devices"); 61MODULE_PARM_DESC(map3, "Describes third set of devices");
62 62
63__obsolete_setup("gc=");
64__obsolete_setup("gc_2=");
65__obsolete_setup("gc_3=");
66
67/* see also gs_psx_delay parameter in PSX support section */ 63/* see also gs_psx_delay parameter in PSX support section */
68 64
69#define GC_SNES 1 65#define GC_SNES 1
@@ -403,8 +399,6 @@ static int gc_psx_delay = GC_PSX_DELAY;
403module_param_named(psx_delay, gc_psx_delay, uint, 0); 399module_param_named(psx_delay, gc_psx_delay, uint, 0);
404MODULE_PARM_DESC(psx_delay, "Delay when accessing Sony PSX controller (usecs)"); 400MODULE_PARM_DESC(psx_delay, "Delay when accessing Sony PSX controller (usecs)");
405 401
406__obsolete_setup("gc_psx_delay=");
407
408static short gc_psx_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_HAT0X, ABS_HAT0Y }; 402static short gc_psx_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_HAT0X, ABS_HAT0Y };
409static short gc_psx_btn[] = { BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, BTN_A, BTN_B, BTN_X, BTN_Y, 403static short gc_psx_btn[] = { BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, BTN_A, BTN_B, BTN_X, BTN_Y,
410 BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR }; 404 BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR };
diff --git a/drivers/input/joystick/turbografx.c b/drivers/input/joystick/turbografx.c
index 5570fd5487..037d3487fc 100644
--- a/drivers/input/joystick/turbografx.c
+++ b/drivers/input/joystick/turbografx.c
@@ -60,10 +60,6 @@ MODULE_PARM_DESC(map2, "Describes second set of devices");
60module_param_array_named(map3, tgfx[2].args, int, &tgfx[2].nargs, 0); 60module_param_array_named(map3, tgfx[2].args, int, &tgfx[2].nargs, 0);
61MODULE_PARM_DESC(map3, "Describes third set of devices"); 61MODULE_PARM_DESC(map3, "Describes third set of devices");
62 62
63__obsolete_setup("tgfx=");
64__obsolete_setup("tgfx_2=");
65__obsolete_setup("tgfx_3=");
66
67#define TGFX_REFRESH_TIME HZ/100 /* 10 ms */ 63#define TGFX_REFRESH_TIME HZ/100 /* 10 ms */
68 64
69#define TGFX_TRIGGER 0x08 65#define TGFX_TRIGGER 0x08
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 1b81a72e19..f17e9c7d4b 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -215,14 +215,16 @@ config KEYBOARD_AAED2000
215 module will be called aaed2000_kbd. 215 module will be called aaed2000_kbd.
216 216
217config KEYBOARD_GPIO 217config KEYBOARD_GPIO
218 tristate "Buttons on CPU GPIOs (PXA)" 218 tristate "GPIO Buttons"
219 depends on ARCH_PXA 219 depends on GENERIC_GPIO
220 help 220 help
221 This driver implements support for buttons connected 221 This driver implements support for buttons connected
222 directly to GPIO pins of PXA CPUs. 222 to GPIO pins of various CPUs (and some other chips).
223 223
224 Say Y here if your device has buttons connected 224 Say Y here if your device has buttons connected
225 directly to GPIO pins of the CPU. 225 directly to such GPIO pins. Your board-specific
226 setup logic must also provide a platform device,
227 with configuration data saying which GPIOs are used.
226 228
227 To compile this driver as a module, choose M here: the 229 To compile this driver as a module, choose M here: the
228 module will be called gpio-keys. 230 module will be called gpio-keys.
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index c621a9177a..663877076b 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -63,10 +63,6 @@ static int atkbd_extra;
63module_param_named(extra, atkbd_extra, bool, 0); 63module_param_named(extra, atkbd_extra, bool, 0);
64MODULE_PARM_DESC(extra, "Enable extra LEDs and keys on IBM RapidAcces, EzKey and similar keyboards"); 64MODULE_PARM_DESC(extra, "Enable extra LEDs and keys on IBM RapidAcces, EzKey and similar keyboards");
65 65
66__obsolete_setup("atkbd_set=");
67__obsolete_setup("atkbd_reset");
68__obsolete_setup("atkbd_softrepeat=");
69
70/* 66/*
71 * Scancode to keycode tables. These are just the default setting, and 67 * Scancode to keycode tables. These are just the default setting, and
72 * are loadable via an userland utility. 68 * are loadable via an userland utility.
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 7ad479e4e3..ccf6df387b 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -23,11 +23,9 @@
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/input.h> 24#include <linux/input.h>
25#include <linux/irq.h> 25#include <linux/irq.h>
26#include <linux/gpio_keys.h>
26 27
27#include <asm/arch/pxa-regs.h> 28#include <asm/gpio.h>
28#include <asm/arch/hardware.h>
29
30#include <asm/hardware/gpio_keys.h>
31 29
32static irqreturn_t gpio_keys_isr(int irq, void *dev_id) 30static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
33{ 31{
@@ -38,8 +36,8 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
38 36
39 for (i = 0; i < pdata->nbuttons; i++) { 37 for (i = 0; i < pdata->nbuttons; i++) {
40 int gpio = pdata->buttons[i].gpio; 38 int gpio = pdata->buttons[i].gpio;
41 if (irq == IRQ_GPIO(gpio)) { 39 if (irq == gpio_to_irq(gpio)) {
42 int state = ((GPLR(gpio) & GPIO_bit(gpio)) ? 1 : 0) ^ (pdata->buttons[i].active_low); 40 int state = (gpio_get_value(gpio) ? 1 : 0) ^ (pdata->buttons[i].active_low);
43 41
44 input_report_key(input, pdata->buttons[i].keycode, state); 42 input_report_key(input, pdata->buttons[i].keycode, state);
45 input_sync(input); 43 input_sync(input);
@@ -75,14 +73,15 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
75 73
76 for (i = 0; i < pdata->nbuttons; i++) { 74 for (i = 0; i < pdata->nbuttons; i++) {
77 int code = pdata->buttons[i].keycode; 75 int code = pdata->buttons[i].keycode;
78 int irq = IRQ_GPIO(pdata->buttons[i].gpio); 76 int irq = gpio_to_irq(pdata->buttons[i].gpio);
79 77
80 set_irq_type(irq, IRQ_TYPE_EDGE_BOTH); 78 set_irq_type(irq, IRQ_TYPE_EDGE_BOTH);
81 error = request_irq(irq, gpio_keys_isr, IRQF_SAMPLE_RANDOM, 79 error = request_irq(irq, gpio_keys_isr, IRQF_SAMPLE_RANDOM,
82 pdata->buttons[i].desc ? pdata->buttons[i].desc : "gpio_keys", 80 pdata->buttons[i].desc ? pdata->buttons[i].desc : "gpio_keys",
83 pdev); 81 pdev);
84 if (error) { 82 if (error) {
85 printk(KERN_ERR "gpio-keys: unable to claim irq %d; error %d\n", irq, ret); 83 printk(KERN_ERR "gpio-keys: unable to claim irq %d; error %d\n",
84 irq, error);
86 goto fail; 85 goto fail;
87 } 86 }
88 set_bit(code, input->keybit); 87 set_bit(code, input->keybit);
@@ -98,7 +97,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
98 97
99 fail: 98 fail:
100 for (i = i - 1; i >= 0; i--) 99 for (i = i - 1; i >= 0; i--)
101 free_irq(IRQ_GPIO(pdata->buttons[i].gpio), pdev); 100 free_irq(gpio_to_irq(pdata->buttons[i].gpio), pdev);
102 101
103 input_free_device(input); 102 input_free_device(input);
104 103
@@ -112,7 +111,7 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
112 int i; 111 int i;
113 112
114 for (i = 0; i < pdata->nbuttons; i++) { 113 for (i = 0; i < pdata->nbuttons; i++) {
115 int irq = IRQ_GPIO(pdata->buttons[i].gpio); 114 int irq = gpio_to_irq(pdata->buttons[i].gpio);
116 free_irq(irq, pdev); 115 free_irq(irq, pdev);
117 } 116 }
118 117
diff --git a/drivers/input/keyboard/hilkbd.c b/drivers/input/keyboard/hilkbd.c
index 255a6ec75a..4de4dc297d 100644
--- a/drivers/input/keyboard/hilkbd.c
+++ b/drivers/input/keyboard/hilkbd.c
@@ -294,8 +294,10 @@ err3:
294 disable_irq(HIL_IRQ); 294 disable_irq(HIL_IRQ);
295 free_irq(HIL_IRQ, hil_dev.dev_id); 295 free_irq(HIL_IRQ, hil_dev.dev_id);
296err2: 296err2:
297#if defined(CONFIG_HP300)
297 release_region(HILBASE + HIL_DATA, 2); 298 release_region(HILBASE + HIL_DATA, 2);
298err1: 299err1:
300#endif
299 input_free_device(hil_dev.dev); 301 input_free_device(hil_dev.dev);
300 hil_dev.dev = NULL; 302 hil_dev.dev = NULL;
301 return err; 303 return err;
diff --git a/drivers/input/mouse/inport.c b/drivers/input/mouse/inport.c
index 701ebd5473..79b624fe89 100644
--- a/drivers/input/mouse/inport.c
+++ b/drivers/input/mouse/inport.c
@@ -84,8 +84,6 @@ static int inport_irq = INPORT_IRQ;
84module_param_named(irq, inport_irq, uint, 0); 84module_param_named(irq, inport_irq, uint, 0);
85MODULE_PARM_DESC(irq, "IRQ number (5=default)"); 85MODULE_PARM_DESC(irq, "IRQ number (5=default)");
86 86
87__obsolete_setup("inport_irq=");
88
89static struct input_dev *inport_dev; 87static struct input_dev *inport_dev;
90 88
91static irqreturn_t inport_interrupt(int irq, void *dev_id) 89static irqreturn_t inport_interrupt(int irq, void *dev_id)
diff --git a/drivers/input/mouse/logibm.c b/drivers/input/mouse/logibm.c
index db205995bf..26c3b2e2ca 100644
--- a/drivers/input/mouse/logibm.c
+++ b/drivers/input/mouse/logibm.c
@@ -75,8 +75,6 @@ static int logibm_irq = LOGIBM_IRQ;
75module_param_named(irq, logibm_irq, uint, 0); 75module_param_named(irq, logibm_irq, uint, 0);
76MODULE_PARM_DESC(irq, "IRQ number (5=default)"); 76MODULE_PARM_DESC(irq, "IRQ number (5=default)");
77 77
78__obsolete_setup("logibm_irq=");
79
80static struct input_dev *logibm_dev; 78static struct input_dev *logibm_dev;
81 79
82static irqreturn_t logibm_interrupt(int irq, void *dev_id) 80static irqreturn_t logibm_interrupt(int irq, void *dev_id)
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index a0e4a033e2..0fe5869d7d 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -93,12 +93,6 @@ static struct attribute_group psmouse_attribute_group = {
93 .attrs = psmouse_attributes, 93 .attrs = psmouse_attributes,
94}; 94};
95 95
96__obsolete_setup("psmouse_noext");
97__obsolete_setup("psmouse_resolution=");
98__obsolete_setup("psmouse_smartscroll=");
99__obsolete_setup("psmouse_resetafter=");
100__obsolete_setup("psmouse_rate=");
101
102/* 96/*
103 * psmouse_mutex protects all operations changing state of mouse 97 * psmouse_mutex protects all operations changing state of mouse
104 * (connecting, disconnecting, changing rate or resolution via 98 * (connecting, disconnecting, changing rate or resolution via
@@ -987,8 +981,36 @@ static void psmouse_resync(struct work_struct *work)
987static void psmouse_cleanup(struct serio *serio) 981static void psmouse_cleanup(struct serio *serio)
988{ 982{
989 struct psmouse *psmouse = serio_get_drvdata(serio); 983 struct psmouse *psmouse = serio_get_drvdata(serio);
984 struct psmouse *parent = NULL;
985
986 mutex_lock(&psmouse_mutex);
987
988 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
989 parent = serio_get_drvdata(serio->parent);
990 psmouse_deactivate(parent);
991 }
992
993 psmouse_deactivate(psmouse);
994
995 if (psmouse->cleanup)
996 psmouse->cleanup(psmouse);
990 997
991 psmouse_reset(psmouse); 998 psmouse_reset(psmouse);
999
1000/*
1001 * Some boxes, such as HP nx7400, get terribly confused if mouse
1002 * is not fully enabled before suspending/shutting down.
1003 */
1004 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE);
1005
1006 if (parent) {
1007 if (parent->pt_deactivate)
1008 parent->pt_deactivate(parent);
1009
1010 psmouse_activate(parent);
1011 }
1012
1013 mutex_unlock(&psmouse_mutex);
992} 1014}
993 1015
994/* 1016/*
diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
index 1b74cae8a5..cf1de95b6f 100644
--- a/drivers/input/mouse/psmouse.h
+++ b/drivers/input/mouse/psmouse.h
@@ -68,6 +68,7 @@ struct psmouse {
68 68
69 int (*reconnect)(struct psmouse *psmouse); 69 int (*reconnect)(struct psmouse *psmouse);
70 void (*disconnect)(struct psmouse *psmouse); 70 void (*disconnect)(struct psmouse *psmouse);
71 void (*cleanup)(struct psmouse *psmouse);
71 int (*poll)(struct psmouse *psmouse); 72 int (*poll)(struct psmouse *psmouse);
72 73
73 void (*pt_activate)(struct psmouse *psmouse); 74 void (*pt_activate)(struct psmouse *psmouse);
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 49ac696d6c..f0f9413d76 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -652,6 +652,7 @@ int synaptics_init(struct psmouse *psmouse)
652 psmouse->set_rate = synaptics_set_rate; 652 psmouse->set_rate = synaptics_set_rate;
653 psmouse->disconnect = synaptics_disconnect; 653 psmouse->disconnect = synaptics_disconnect;
654 psmouse->reconnect = synaptics_reconnect; 654 psmouse->reconnect = synaptics_reconnect;
655 psmouse->cleanup = synaptics_reset;
655 psmouse->pktsize = 6; 656 psmouse->pktsize = 6;
656 /* Synaptics can usually stay in sync without extra help */ 657 /* Synaptics can usually stay in sync without extra help */
657 psmouse->resync_time = 0; 658 psmouse->resync_time = 0;
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index c3fdfc1f34..db9cca3b65 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -76,13 +76,6 @@ module_param_named(debug, i8042_debug, bool, 0600);
76MODULE_PARM_DESC(debug, "Turn i8042 debugging mode on and off"); 76MODULE_PARM_DESC(debug, "Turn i8042 debugging mode on and off");
77#endif 77#endif
78 78
79__obsolete_setup("i8042_noaux");
80__obsolete_setup("i8042_nomux");
81__obsolete_setup("i8042_unlock");
82__obsolete_setup("i8042_reset");
83__obsolete_setup("i8042_direct");
84__obsolete_setup("i8042_dumbkbd");
85
86#include "i8042.h" 79#include "i8042.h"
87 80
88static DEFINE_SPINLOCK(i8042_lock); 81static DEFINE_SPINLOCK(i8042_lock);
@@ -560,7 +553,8 @@ static int __devinit i8042_check_aux(void)
560 */ 553 */
561 554
562 param = 0x5a; 555 param = 0x5a;
563 if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != 0x5a) { 556 retval = i8042_command(&param, I8042_CMD_AUX_LOOP);
557 if (retval || param != 0x5a) {
564 558
565/* 559/*
566 * External connection test - filters out AT-soldered PS/2 i8042's 560 * External connection test - filters out AT-soldered PS/2 i8042's
@@ -574,7 +568,12 @@ static int __devinit i8042_check_aux(void)
574 (param && param != 0xfa && param != 0xff)) 568 (param && param != 0xfa && param != 0xff))
575 return -1; 569 return -1;
576 570
577 aux_loop_broken = 1; 571/*
572 * If AUX_LOOP completed without error but returned unexpected data
573 * mark it as broken
574 */
575 if (!retval)
576 aux_loop_broken = 1;
578 } 577 }
579 578
580/* 579/*
@@ -724,7 +723,7 @@ static int i8042_controller_init(void)
724 if (~i8042_read_status() & I8042_STR_KEYLOCK) { 723 if (~i8042_read_status() & I8042_STR_KEYLOCK) {
725 if (i8042_unlock) 724 if (i8042_unlock)
726 i8042_ctr |= I8042_CTR_IGNKEYLOCK; 725 i8042_ctr |= I8042_CTR_IGNKEYLOCK;
727 else 726 else
728 printk(KERN_WARNING "i8042.c: Warning: Keylock active.\n"); 727 printk(KERN_WARNING "i8042.c: Warning: Keylock active.\n");
729 } 728 }
730 spin_unlock_irqrestore(&i8042_lock, flags); 729 spin_unlock_irqrestore(&i8042_lock, flags);
@@ -791,27 +790,6 @@ static void i8042_controller_reset(void)
791 790
792 791
793/* 792/*
794 * Here we try to reset everything back to a state in which the BIOS will be
795 * able to talk to the hardware when rebooting.
796 */
797
798static void i8042_controller_cleanup(void)
799{
800 int i;
801
802/*
803 * Reset anything that is connected to the ports.
804 */
805
806 for (i = 0; i < I8042_NUM_PORTS; i++)
807 if (i8042_ports[i].serio)
808 serio_cleanup(i8042_ports[i].serio);
809
810 i8042_controller_reset();
811}
812
813
814/*
815 * i8042_panic_blink() will flash the keyboard LEDs and is called when 793 * i8042_panic_blink() will flash the keyboard LEDs and is called when
816 * kernel panics. Flashing LEDs is useful for users running X who may 794 * kernel panics. Flashing LEDs is useful for users running X who may
817 * not see the console and will help distingushing panics from "real" 795 * not see the console and will help distingushing panics from "real"
@@ -857,13 +835,22 @@ static long i8042_panic_blink(long count)
857 835
858#undef DELAY 836#undef DELAY
859 837
838#ifdef CONFIG_PM
860/* 839/*
861 * Here we try to restore the original BIOS settings 840 * Here we try to restore the original BIOS settings. We only want to
841 * do that once, when we really suspend, not when we taking memory
842 * snapshot for swsusp (in this case we'll perform required cleanup
843 * as part of shutdown process).
862 */ 844 */
863 845
864static int i8042_suspend(struct platform_device *dev, pm_message_t state) 846static int i8042_suspend(struct platform_device *dev, pm_message_t state)
865{ 847{
866 i8042_controller_cleanup(); 848 if (dev->dev.power.power_state.event != state.event) {
849 if (state.event == PM_EVENT_SUSPEND)
850 i8042_controller_reset();
851
852 dev->dev.power.power_state = state;
853 }
867 854
868 return 0; 855 return 0;
869} 856}
@@ -877,6 +864,12 @@ static int i8042_resume(struct platform_device *dev)
877{ 864{
878 int error; 865 int error;
879 866
867/*
868 * Do not bother with restoring state if we haven't suspened yet
869 */
870 if (dev->dev.power.power_state.event == PM_EVENT_ON)
871 return 0;
872
880 error = i8042_controller_check(); 873 error = i8042_controller_check();
881 if (error) 874 if (error)
882 return error; 875 return error;
@@ -886,9 +879,12 @@ static int i8042_resume(struct platform_device *dev)
886 return error; 879 return error;
887 880
888/* 881/*
889 * Restore pre-resume CTR value and disable all ports 882 * Restore original CTR value and disable all ports
890 */ 883 */
891 884
885 i8042_ctr = i8042_initial_ctr;
886 if (i8042_direct)
887 i8042_ctr &= ~I8042_CTR_XLATE;
892 i8042_ctr |= I8042_CTR_AUXDIS | I8042_CTR_KBDDIS; 888 i8042_ctr |= I8042_CTR_AUXDIS | I8042_CTR_KBDDIS;
893 i8042_ctr &= ~(I8042_CTR_AUXINT | I8042_CTR_KBDINT); 889 i8042_ctr &= ~(I8042_CTR_AUXINT | I8042_CTR_KBDINT);
894 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) { 890 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) {
@@ -909,8 +905,11 @@ static int i8042_resume(struct platform_device *dev)
909 905
910 i8042_interrupt(0, NULL); 906 i8042_interrupt(0, NULL);
911 907
908 dev->dev.power.power_state = PMSG_ON;
909
912 return 0; 910 return 0;
913} 911}
912#endif /* CONFIG_PM */
914 913
915/* 914/*
916 * We need to reset the 8042 back to original mode on system shutdown, 915 * We need to reset the 8042 back to original mode on system shutdown,
@@ -919,7 +918,7 @@ static int i8042_resume(struct platform_device *dev)
919 918
920static void i8042_shutdown(struct platform_device *dev) 919static void i8042_shutdown(struct platform_device *dev)
921{ 920{
922 i8042_controller_cleanup(); 921 i8042_controller_reset();
923} 922}
924 923
925static int __devinit i8042_create_kbd_port(void) 924static int __devinit i8042_create_kbd_port(void)
@@ -1154,9 +1153,11 @@ static struct platform_driver i8042_driver = {
1154 }, 1153 },
1155 .probe = i8042_probe, 1154 .probe = i8042_probe,
1156 .remove = __devexit_p(i8042_remove), 1155 .remove = __devexit_p(i8042_remove),
1156 .shutdown = i8042_shutdown,
1157#ifdef CONFIG_PM
1157 .suspend = i8042_suspend, 1158 .suspend = i8042_suspend,
1158 .resume = i8042_resume, 1159 .resume = i8042_resume,
1159 .shutdown = i8042_shutdown, 1160#endif
1160}; 1161};
1161 1162
1162static int __init i8042_init(void) 1163static int __init i8042_init(void)
diff --git a/drivers/input/serio/libps2.c b/drivers/input/serio/libps2.c
index b3e84d3bb7..10d9d74ae4 100644
--- a/drivers/input/serio/libps2.c
+++ b/drivers/input/serio/libps2.c
@@ -97,7 +97,7 @@ EXPORT_SYMBOL(ps2_drain);
97 97
98int ps2_is_keyboard_id(char id_byte) 98int ps2_is_keyboard_id(char id_byte)
99{ 99{
100 const static char keyboard_ids[] = { 100 static const char keyboard_ids[] = {
101 0xab, /* Regular keyboards */ 101 0xab, /* Regular keyboards */
102 0xac, /* NCD Sun keyboard */ 102 0xac, /* NCD Sun keyboard */
103 0x2b, /* Trust keyboard, translated */ 103 0x2b, /* Trust keyboard, translated */
diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
index 17c8c63cbe..a15e531ec7 100644
--- a/drivers/input/serio/serio.c
+++ b/drivers/input/serio/serio.c
@@ -778,6 +778,19 @@ static int serio_driver_remove(struct device *dev)
778 return 0; 778 return 0;
779} 779}
780 780
781static void serio_cleanup(struct serio *serio)
782{
783 if (serio->drv && serio->drv->cleanup)
784 serio->drv->cleanup(serio);
785}
786
787static void serio_shutdown(struct device *dev)
788{
789 struct serio *serio = to_serio_port(dev);
790
791 serio_cleanup(serio);
792}
793
781static void serio_attach_driver(struct serio_driver *drv) 794static void serio_attach_driver(struct serio_driver *drv)
782{ 795{
783 int error; 796 int error;
@@ -910,11 +923,25 @@ static int serio_uevent(struct device *dev, char **envp, int num_envp, char *buf
910 923
911#endif /* CONFIG_HOTPLUG */ 924#endif /* CONFIG_HOTPLUG */
912 925
926#ifdef CONFIG_PM
927static int serio_suspend(struct device *dev, pm_message_t state)
928{
929 if (dev->power.power_state.event != state.event) {
930 if (state.event == PM_EVENT_SUSPEND)
931 serio_cleanup(to_serio_port(dev));
932
933 dev->power.power_state = state;
934 }
935
936 return 0;
937}
938
913static int serio_resume(struct device *dev) 939static int serio_resume(struct device *dev)
914{ 940{
915 struct serio *serio = to_serio_port(dev); 941 struct serio *serio = to_serio_port(dev);
916 942
917 if (serio_reconnect_driver(serio)) { 943 if (dev->power.power_state.event != PM_EVENT_ON &&
944 serio_reconnect_driver(serio)) {
918 /* 945 /*
919 * Driver re-probing can take a while, so better let kseriod 946 * Driver re-probing can take a while, so better let kseriod
920 * deal with it. 947 * deal with it.
@@ -922,8 +949,11 @@ static int serio_resume(struct device *dev)
922 serio_rescan(serio); 949 serio_rescan(serio);
923 } 950 }
924 951
952 dev->power.power_state = PMSG_ON;
953
925 return 0; 954 return 0;
926} 955}
956#endif /* CONFIG_PM */
927 957
928/* called from serio_driver->connect/disconnect methods under serio_mutex */ 958/* called from serio_driver->connect/disconnect methods under serio_mutex */
929int serio_open(struct serio *serio, struct serio_driver *drv) 959int serio_open(struct serio *serio, struct serio_driver *drv)
@@ -974,7 +1004,11 @@ static struct bus_type serio_bus = {
974 .uevent = serio_uevent, 1004 .uevent = serio_uevent,
975 .probe = serio_driver_probe, 1005 .probe = serio_driver_probe,
976 .remove = serio_driver_remove, 1006 .remove = serio_driver_remove,
1007 .shutdown = serio_shutdown,
1008#ifdef CONFIG_PM
1009 .suspend = serio_suspend,
977 .resume = serio_resume, 1010 .resume = serio_resume,
1011#endif
978}; 1012};
979 1013
980static int __init serio_init(void) 1014static int __init serio_init(void)
diff --git a/drivers/isdn/capi/Kconfig b/drivers/isdn/capi/Kconfig
index 8b6c9a431f..c921d6c522 100644
--- a/drivers/isdn/capi/Kconfig
+++ b/drivers/isdn/capi/Kconfig
@@ -2,13 +2,25 @@
2# Config.in for the CAPI subsystem 2# Config.in for the CAPI subsystem
3# 3#
4config ISDN_DRV_AVMB1_VERBOSE_REASON 4config ISDN_DRV_AVMB1_VERBOSE_REASON
5 bool "Verbose reason code reporting (kernel size +=7K)" 5 bool "Verbose reason code reporting"
6 depends on ISDN_CAPI 6 depends on ISDN_CAPI
7 default y
7 help 8 help
8 If you say Y here, the AVM B1 driver will give verbose reasons for 9 If you say Y here, the CAPI drivers will give verbose reasons for
9 disconnecting. This will increase the size of the kernel by 7 KB. If 10 disconnecting. This will increase the size of the kernel by 7 KB. If
10 unsure, say Y. 11 unsure, say Y.
11 12
13config CAPI_TRACE
14 bool "CAPI trace support"
15 depends on ISDN_CAPI
16 default y
17 help
18 If you say Y here, the kernelcapi driver can make verbose traces
19 of CAPI messages. This feature can be enabled/disabled via IOCTL for
20 every controler (default disabled).
21 This will increase the size of the kernelcapi module by 20 KB.
22 If unsure, say Y.
23
12config ISDN_CAPI_MIDDLEWARE 24config ISDN_CAPI_MIDDLEWARE
13 bool "CAPI2.0 Middleware support (EXPERIMENTAL)" 25 bool "CAPI2.0 Middleware support (EXPERIMENTAL)"
14 depends on ISDN_CAPI && EXPERIMENTAL 26 depends on ISDN_CAPI && EXPERIMENTAL
diff --git a/drivers/isdn/capi/capidrv.c b/drivers/isdn/capi/capidrv.c
index 2a49cea0a2..23b6f7bc16 100644
--- a/drivers/isdn/capi/capidrv.c
+++ b/drivers/isdn/capi/capidrv.c
@@ -990,6 +990,7 @@ static void handle_plci(_cmsg * cmsg)
990 capidrv_contr *card = findcontrbynumber(cmsg->adr.adrController & 0x7f); 990 capidrv_contr *card = findcontrbynumber(cmsg->adr.adrController & 0x7f);
991 capidrv_plci *plcip; 991 capidrv_plci *plcip;
992 isdn_ctrl cmd; 992 isdn_ctrl cmd;
993 _cdebbuf *cdb;
993 994
994 if (!card) { 995 if (!card) {
995 printk(KERN_ERR "capidrv: %s from unknown controller 0x%x\n", 996 printk(KERN_ERR "capidrv: %s from unknown controller 0x%x\n",
@@ -1122,8 +1123,15 @@ static void handle_plci(_cmsg * cmsg)
1122 break; 1123 break;
1123 } 1124 }
1124 } 1125 }
1125 printk(KERN_ERR "capidrv-%d: %s\n", 1126 cdb = capi_cmsg2str(cmsg);
1126 card->contrnr, capi_cmsg2str(cmsg)); 1127 if (cdb) {
1128 printk(KERN_WARNING "capidrv-%d: %s\n",
1129 card->contrnr, cdb->buf);
1130 cdebbuf_free(cdb);
1131 } else
1132 printk(KERN_WARNING "capidrv-%d: CAPI_INFO_IND InfoNumber %x not handled\n",
1133 card->contrnr, cmsg->InfoNumber);
1134
1127 break; 1135 break;
1128 1136
1129 case CAPI_CONNECT_ACTIVE_CONF: /* plci */ 1137 case CAPI_CONNECT_ACTIVE_CONF: /* plci */
@@ -1371,10 +1379,18 @@ static _cmsg s_cmsg;
1371static void capidrv_recv_message(struct capi20_appl *ap, struct sk_buff *skb) 1379static void capidrv_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
1372{ 1380{
1373 capi_message2cmsg(&s_cmsg, skb->data); 1381 capi_message2cmsg(&s_cmsg, skb->data);
1374 if (debugmode > 3) 1382 if (debugmode > 3) {
1375 printk(KERN_DEBUG "capidrv_signal: applid=%d %s\n", 1383 _cdebbuf *cdb = capi_cmsg2str(&s_cmsg);
1376 ap->applid, capi_cmsg2str(&s_cmsg)); 1384
1377 1385 if (cdb) {
1386 printk(KERN_DEBUG "%s: applid=%d %s\n", __FUNCTION__,
1387 ap->applid, cdb->buf);
1388 cdebbuf_free(cdb);
1389 } else
1390 printk(KERN_DEBUG "%s: applid=%d %s not traced\n",
1391 __FUNCTION__, ap->applid,
1392 capi_cmd2str(s_cmsg.Command, s_cmsg.Subcommand));
1393 }
1378 if (s_cmsg.Command == CAPI_DATA_B3 1394 if (s_cmsg.Command == CAPI_DATA_B3
1379 && s_cmsg.Subcommand == CAPI_IND) { 1395 && s_cmsg.Subcommand == CAPI_IND) {
1380 handle_data(&s_cmsg, skb); 1396 handle_data(&s_cmsg, skb);
diff --git a/drivers/isdn/capi/capiutil.c b/drivers/isdn/capi/capiutil.c
index c1b21552fc..ad1e2702c2 100644
--- a/drivers/isdn/capi/capiutil.c
+++ b/drivers/isdn/capi/capiutil.c
@@ -648,6 +648,9 @@ char *capi_cmd2str(u8 cmd, u8 subcmd)
648 648
649 649
650/*-------------------------------------------------------*/ 650/*-------------------------------------------------------*/
651
652#ifdef CONFIG_CAPI_TRACE
653
651/*-------------------------------------------------------*/ 654/*-------------------------------------------------------*/
652 655
653static char *pnames[] = 656static char *pnames[] =
@@ -703,44 +706,77 @@ static char *pnames[] =
703}; 706};
704 707
705 708
706static char buf[8192];
707static char *p = NULL;
708 709
709#include <stdarg.h> 710#include <stdarg.h>
710 711
711/*-------------------------------------------------------*/ 712/*-------------------------------------------------------*/
712static void bufprint(char *fmt,...) 713static _cdebbuf *bufprint(_cdebbuf *cdb, char *fmt,...)
713{ 714{
714 va_list f; 715 va_list f;
716 size_t n,r;
717
718 if (!cdb)
719 return NULL;
715 va_start(f, fmt); 720 va_start(f, fmt);
716 vsprintf(p, fmt, f); 721 r = cdb->size - cdb->pos;
722 n = vsnprintf(cdb->p, r, fmt, f);
717 va_end(f); 723 va_end(f);
718 p += strlen(p); 724 if (n >= r) {
725 /* truncated, need bigger buffer */
726 size_t ns = 2 * cdb->size;
727 u_char *nb;
728
729 while ((ns - cdb->pos) <= n)
730 ns *= 2;
731 nb = kmalloc(ns, GFP_ATOMIC);
732 if (!nb) {
733 cdebbuf_free(cdb);
734 return NULL;
735 }
736 memcpy(nb, cdb->buf, cdb->pos);
737 kfree(cdb->buf);
738 nb[cdb->pos] = 0;
739 cdb->buf = nb;
740 cdb->p = cdb->buf + cdb->pos;
741 cdb->size = ns;
742 va_start(f, fmt);
743 r = cdb->size - cdb->pos;
744 n = vsnprintf(cdb->p, r, fmt, f);
745 va_end(f);
746 }
747 cdb->p += n;
748 cdb->pos += n;
749 return cdb;
719} 750}
720 751
721static void printstructlen(u8 * m, unsigned len) 752static _cdebbuf *printstructlen(_cdebbuf *cdb, u8 * m, unsigned len)
722{ 753{
723 unsigned hex = 0; 754 unsigned hex = 0;
755
756 if (!cdb)
757 return NULL;
724 for (; len; len--, m++) 758 for (; len; len--, m++)
725 if (isalnum(*m) || *m == ' ') { 759 if (isalnum(*m) || *m == ' ') {
726 if (hex) 760 if (hex)
727 bufprint(">"); 761 cdb = bufprint(cdb, ">");
728 bufprint("%c", *m); 762 cdb = bufprint(cdb, "%c", *m);
729 hex = 0; 763 hex = 0;
730 } else { 764 } else {
731 if (!hex) 765 if (!hex)
732 bufprint("<%02x", *m); 766 cdb = bufprint(cdb, "<%02x", *m);
733 else 767 else
734 bufprint(" %02x", *m); 768 cdb = bufprint(cdb, " %02x", *m);
735 hex = 1; 769 hex = 1;
736 } 770 }
737 if (hex) 771 if (hex)
738 bufprint(">"); 772 cdb = bufprint(cdb, ">");
773 return cdb;
739} 774}
740 775
741static void printstruct(u8 * m) 776static _cdebbuf *printstruct(_cdebbuf *cdb, u8 * m)
742{ 777{
743 unsigned len; 778 unsigned len;
779
744 if (m[0] != 0xff) { 780 if (m[0] != 0xff) {
745 len = m[0]; 781 len = m[0];
746 m += 1; 782 m += 1;
@@ -748,42 +784,45 @@ static void printstruct(u8 * m)
748 len = ((u16 *) (m + 1))[0]; 784 len = ((u16 *) (m + 1))[0];
749 m += 3; 785 m += 3;
750 } 786 }
751 printstructlen(m, len); 787 cdb = printstructlen(cdb, m, len);
788 return cdb;
752} 789}
753 790
754/*-------------------------------------------------------*/ 791/*-------------------------------------------------------*/
755#define NAME (pnames[cmsg->par[cmsg->p]]) 792#define NAME (pnames[cmsg->par[cmsg->p]])
756 793
757static void protocol_message_2_pars(_cmsg * cmsg, int level) 794static _cdebbuf *protocol_message_2_pars(_cdebbuf *cdb, _cmsg *cmsg, int level)
758{ 795{
759 for (; TYP != _CEND; cmsg->p++) { 796 for (; TYP != _CEND; cmsg->p++) {
760 int slen = 29 + 3 - level; 797 int slen = 29 + 3 - level;
761 int i; 798 int i;
762 799
763 bufprint(" "); 800 if (!cdb)
801 return NULL;
802 cdb = bufprint(cdb, " ");
764 for (i = 0; i < level - 1; i++) 803 for (i = 0; i < level - 1; i++)
765 bufprint(" "); 804 cdb = bufprint(cdb, " ");
766 805
767 switch (TYP) { 806 switch (TYP) {
768 case _CBYTE: 807 case _CBYTE:
769 bufprint("%-*s = 0x%x\n", slen, NAME, *(u8 *) (cmsg->m + cmsg->l)); 808 cdb = bufprint(cdb, "%-*s = 0x%x\n", slen, NAME, *(u8 *) (cmsg->m + cmsg->l));
770 cmsg->l++; 809 cmsg->l++;
771 break; 810 break;
772 case _CWORD: 811 case _CWORD:
773 bufprint("%-*s = 0x%x\n", slen, NAME, *(u16 *) (cmsg->m + cmsg->l)); 812 cdb = bufprint(cdb, "%-*s = 0x%x\n", slen, NAME, *(u16 *) (cmsg->m + cmsg->l));
774 cmsg->l += 2; 813 cmsg->l += 2;
775 break; 814 break;
776 case _CDWORD: 815 case _CDWORD:
777 bufprint("%-*s = 0x%lx\n", slen, NAME, *(u32 *) (cmsg->m + cmsg->l)); 816 cdb = bufprint(cdb, "%-*s = 0x%lx\n", slen, NAME, *(u32 *) (cmsg->m + cmsg->l));
778 cmsg->l += 4; 817 cmsg->l += 4;
779 break; 818 break;
780 case _CSTRUCT: 819 case _CSTRUCT:
781 bufprint("%-*s = ", slen, NAME); 820 cdb = bufprint(cdb, "%-*s = ", slen, NAME);
782 if (cmsg->m[cmsg->l] == '\0') 821 if (cmsg->m[cmsg->l] == '\0')
783 bufprint("default"); 822 cdb = bufprint(cdb, "default");
784 else 823 else
785 printstruct(cmsg->m + cmsg->l); 824 cdb = printstruct(cdb, cmsg->m + cmsg->l);
786 bufprint("\n"); 825 cdb = bufprint(cdb, "\n");
787 if (cmsg->m[cmsg->l] != 0xff) 826 if (cmsg->m[cmsg->l] != 0xff)
788 cmsg->l += 1 + cmsg->m[cmsg->l]; 827 cmsg->l += 1 + cmsg->m[cmsg->l];
789 else 828 else
@@ -794,61 +833,184 @@ static void protocol_message_2_pars(_cmsg * cmsg, int level)
794 case _CMSTRUCT: 833 case _CMSTRUCT:
795/*----- Metastruktur 0 -----*/ 834/*----- Metastruktur 0 -----*/
796 if (cmsg->m[cmsg->l] == '\0') { 835 if (cmsg->m[cmsg->l] == '\0') {
797 bufprint("%-*s = default\n", slen, NAME); 836 cdb = bufprint(cdb, "%-*s = default\n", slen, NAME);
798 cmsg->l++; 837 cmsg->l++;
799 jumpcstruct(cmsg); 838 jumpcstruct(cmsg);
800 } else { 839 } else {
801 char *name = NAME; 840 char *name = NAME;
802 unsigned _l = cmsg->l; 841 unsigned _l = cmsg->l;
803 bufprint("%-*s\n", slen, name); 842 cdb = bufprint(cdb, "%-*s\n", slen, name);
804 cmsg->l = (cmsg->m + _l)[0] == 255 ? cmsg->l + 3 : cmsg->l + 1; 843 cmsg->l = (cmsg->m + _l)[0] == 255 ? cmsg->l + 3 : cmsg->l + 1;
805 cmsg->p++; 844 cmsg->p++;
806 protocol_message_2_pars(cmsg, level + 1); 845 cdb = protocol_message_2_pars(cdb, cmsg, level + 1);
807 } 846 }
808 break; 847 break;
809 } 848 }
810 } 849 }
850 return cdb;
811} 851}
812/*-------------------------------------------------------*/ 852/*-------------------------------------------------------*/
813char *capi_message2str(u8 * msg) 853
854static _cdebbuf *g_debbuf;
855static u_long g_debbuf_lock;
856static _cmsg *g_cmsg;
857
858_cdebbuf *cdebbuf_alloc(void)
814{ 859{
860 _cdebbuf *cdb;
861
862 if (likely(!test_and_set_bit(1, &g_debbuf_lock))) {
863 cdb = g_debbuf;
864 goto init;
865 } else
866 cdb = kmalloc(sizeof(_cdebbuf), GFP_ATOMIC);
867 if (!cdb)
868 return NULL;
869 cdb->buf = kmalloc(CDEBUG_SIZE, GFP_ATOMIC);
870 if (!cdb->buf) {
871 kfree(cdb);
872 return NULL;
873 }
874 cdb->size = CDEBUG_SIZE;
875init:
876 cdb->buf[0] = 0;
877 cdb->p = cdb->buf;
878 cdb->pos = 0;
879 return cdb;
880}
815 881
816 _cmsg cmsg; 882void cdebbuf_free(_cdebbuf *cdb)
817 p = buf; 883{
818 p[0] = 0; 884 if (likely(cdb == g_debbuf)) {
885 test_and_clear_bit(1, &g_debbuf_lock);
886 return;
887 }
888 if (likely(cdb))
889 kfree(cdb->buf);
890 kfree(cdb);
891}
819 892
820 cmsg.m = msg;
821 cmsg.l = 8;
822 cmsg.p = 0;
823 byteTRcpy(cmsg.m + 4, &cmsg.Command);
824 byteTRcpy(cmsg.m + 5, &cmsg.Subcommand);
825 cmsg.par = cpars[command_2_index(cmsg.Command, cmsg.Subcommand)];
826 893
827 bufprint("%-26s ID=%03d #0x%04x LEN=%04d\n", 894_cdebbuf *capi_message2str(u8 * msg)
828 mnames[command_2_index(cmsg.Command, cmsg.Subcommand)], 895{
896 _cdebbuf *cdb;
897 _cmsg *cmsg;
898
899 cdb = cdebbuf_alloc();
900 if (unlikely(!cdb))
901 return NULL;
902 if (likely(cdb == g_debbuf))
903 cmsg = g_cmsg;
904 else
905 cmsg = kmalloc(sizeof(_cmsg), GFP_ATOMIC);
906 if (unlikely(!cmsg)) {
907 cdebbuf_free(cdb);
908 return NULL;
909 }
910 cmsg->m = msg;
911 cmsg->l = 8;
912 cmsg->p = 0;
913 byteTRcpy(cmsg->m + 4, &cmsg->Command);
914 byteTRcpy(cmsg->m + 5, &cmsg->Subcommand);
915 cmsg->par = cpars[command_2_index(cmsg->Command, cmsg->Subcommand)];
916
917 cdb = bufprint(cdb, "%-26s ID=%03d #0x%04x LEN=%04d\n",
918 mnames[command_2_index(cmsg->Command, cmsg->Subcommand)],
829 ((unsigned short *) msg)[1], 919 ((unsigned short *) msg)[1],
830 ((unsigned short *) msg)[3], 920 ((unsigned short *) msg)[3],
831 ((unsigned short *) msg)[0]); 921 ((unsigned short *) msg)[0]);
832 922
833 protocol_message_2_pars(&cmsg, 1); 923 cdb = protocol_message_2_pars(cdb, cmsg, 1);
834 return buf; 924 if (unlikely(cmsg != g_cmsg))
925 kfree(cmsg);
926 return cdb;
835} 927}
836 928
837char *capi_cmsg2str(_cmsg * cmsg) 929_cdebbuf *capi_cmsg2str(_cmsg * cmsg)
838{ 930{
839 p = buf; 931 _cdebbuf *cdb;
840 p[0] = 0; 932
933 cdb = cdebbuf_alloc();
934 if (!cdb)
935 return NULL;
841 cmsg->l = 8; 936 cmsg->l = 8;
842 cmsg->p = 0; 937 cmsg->p = 0;
843 bufprint("%s ID=%03d #0x%04x LEN=%04d\n", 938 cdb = bufprint(cdb, "%s ID=%03d #0x%04x LEN=%04d\n",
844 mnames[command_2_index(cmsg->Command, cmsg->Subcommand)], 939 mnames[command_2_index(cmsg->Command, cmsg->Subcommand)],
845 ((u16 *) cmsg->m)[1], 940 ((u16 *) cmsg->m)[1],
846 ((u16 *) cmsg->m)[3], 941 ((u16 *) cmsg->m)[3],
847 ((u16 *) cmsg->m)[0]); 942 ((u16 *) cmsg->m)[0]);
848 protocol_message_2_pars(cmsg, 1); 943 cdb = protocol_message_2_pars(cdb, cmsg, 1);
849 return buf; 944 return cdb;
850} 945}
851 946
947int __init cdebug_init(void)
948{
949 g_cmsg= kmalloc(sizeof(_cmsg), GFP_KERNEL);
950 if (!g_cmsg)
951 return ENOMEM;
952 g_debbuf = kmalloc(sizeof(_cdebbuf), GFP_KERNEL);
953 if (!g_debbuf) {
954 kfree(g_cmsg);
955 return ENOMEM;
956 }
957 g_debbuf->buf = kmalloc(CDEBUG_GSIZE, GFP_KERNEL);
958 if (!g_debbuf->buf) {
959 kfree(g_cmsg);
960 kfree(g_debbuf);
961 return ENOMEM;;
962 }
963 g_debbuf->size = CDEBUG_GSIZE;
964 g_debbuf->buf[0] = 0;
965 g_debbuf->p = g_debbuf->buf;
966 g_debbuf->pos = 0;
967 return 0;
968}
969
970void __exit cdebug_exit(void)
971{
972 if (g_debbuf)
973 kfree(g_debbuf->buf);
974 kfree(g_debbuf);
975 kfree(g_cmsg);
976}
977
978#else /* !CONFIG_CAPI_TRACE */
979
980static _cdebbuf g_debbuf = {"CONFIG_CAPI_TRACE not enabled", NULL, 0, 0};
981
982_cdebbuf *capi_message2str(u8 * msg)
983{
984 return &g_debbuf;
985}
986
987_cdebbuf *capi_cmsg2str(_cmsg * cmsg)
988{
989 return &g_debbuf;
990}
991
992_cdebbuf *cdebbuf_alloc(void)
993{
994 return &g_debbuf;
995}
996
997void cdebbuf_free(_cdebbuf *cdb)
998{
999}
1000
1001int __init cdebug_init(void)
1002{
1003 return 0;
1004}
1005
1006void __exit cdebug_exit(void)
1007{
1008}
1009
1010#endif
1011
1012EXPORT_SYMBOL(cdebbuf_alloc);
1013EXPORT_SYMBOL(cdebbuf_free);
852EXPORT_SYMBOL(capi_cmsg2message); 1014EXPORT_SYMBOL(capi_cmsg2message);
853EXPORT_SYMBOL(capi_message2cmsg); 1015EXPORT_SYMBOL(capi_message2cmsg);
854EXPORT_SYMBOL(capi_cmsg_header); 1016EXPORT_SYMBOL(capi_cmsg_header);
diff --git a/drivers/isdn/capi/kcapi.c b/drivers/isdn/capi/kcapi.c
index 783a255263..3ed34f7a1c 100644
--- a/drivers/isdn/capi/kcapi.c
+++ b/drivers/isdn/capi/kcapi.c
@@ -276,10 +276,17 @@ void capi_ctr_handle_message(struct capi_ctr * card, u16 appl, struct sk_buff *s
276 int showctl = 0; 276 int showctl = 0;
277 u8 cmd, subcmd; 277 u8 cmd, subcmd;
278 unsigned long flags; 278 unsigned long flags;
279 _cdebbuf *cdb;
279 280
280 if (card->cardstate != CARD_RUNNING) { 281 if (card->cardstate != CARD_RUNNING) {
281 printk(KERN_INFO "kcapi: controller %d not active, got: %s", 282 cdb = capi_message2str(skb->data);
282 card->cnr, capi_message2str(skb->data)); 283 if (cdb) {
284 printk(KERN_INFO "kcapi: controller [%03d] not active, got: %s",
285 card->cnr, cdb->buf);
286 cdebbuf_free(cdb);
287 } else
288 printk(KERN_INFO "kcapi: controller [%03d] not active, cannot trace\n",
289 card->cnr);
283 goto error; 290 goto error;
284 } 291 }
285 292
@@ -295,15 +302,21 @@ void capi_ctr_handle_message(struct capi_ctr * card, u16 appl, struct sk_buff *s
295 showctl |= (card->traceflag & 1); 302 showctl |= (card->traceflag & 1);
296 if (showctl & 2) { 303 if (showctl & 2) {
297 if (showctl & 1) { 304 if (showctl & 1) {
298 printk(KERN_DEBUG "kcapi: got [0x%lx] id#%d %s len=%u\n", 305 printk(KERN_DEBUG "kcapi: got [%03d] id#%d %s len=%u\n",
299 (unsigned long) card->cnr, 306 card->cnr, CAPIMSG_APPID(skb->data),
300 CAPIMSG_APPID(skb->data),
301 capi_cmd2str(cmd, subcmd), 307 capi_cmd2str(cmd, subcmd),
302 CAPIMSG_LEN(skb->data)); 308 CAPIMSG_LEN(skb->data));
303 } else { 309 } else {
304 printk(KERN_DEBUG "kcapi: got [0x%lx] %s\n", 310 cdb = capi_message2str(skb->data);
305 (unsigned long) card->cnr, 311 if (cdb) {
306 capi_message2str(skb->data)); 312 printk(KERN_DEBUG "kcapi: got [%03d] %s\n",
313 card->cnr, cdb->buf);
314 cdebbuf_free(cdb);
315 } else
316 printk(KERN_DEBUG "kcapi: got [%03d] id#%d %s len=%u, cannot trace\n",
317 card->cnr, CAPIMSG_APPID(skb->data),
318 capi_cmd2str(cmd, subcmd),
319 CAPIMSG_LEN(skb->data));
307 } 320 }
308 321
309 } 322 }
@@ -312,8 +325,15 @@ void capi_ctr_handle_message(struct capi_ctr * card, u16 appl, struct sk_buff *s
312 ap = get_capi_appl_by_nr(CAPIMSG_APPID(skb->data)); 325 ap = get_capi_appl_by_nr(CAPIMSG_APPID(skb->data));
313 if ((!ap) || (ap->release_in_progress)) { 326 if ((!ap) || (ap->release_in_progress)) {
314 read_unlock_irqrestore(&application_lock, flags); 327 read_unlock_irqrestore(&application_lock, flags);
315 printk(KERN_ERR "kcapi: handle_message: applid %d state released (%s)\n", 328 cdb = capi_message2str(skb->data);
316 CAPIMSG_APPID(skb->data), capi_message2str(skb->data)); 329 if (cdb) {
330 printk(KERN_ERR "kcapi: handle_message: applid %d state released (%s)\n",
331 CAPIMSG_APPID(skb->data), cdb->buf);
332 cdebbuf_free(cdb);
333 } else
334 printk(KERN_ERR "kcapi: handle_message: applid %d state released (%s) cannot trace\n",
335 CAPIMSG_APPID(skb->data),
336 capi_cmd2str(cmd, subcmd));
317 goto error; 337 goto error;
318 } 338 }
319 skb_queue_tail(&ap->recv_queue, skb); 339 skb_queue_tail(&ap->recv_queue, skb);
@@ -332,7 +352,7 @@ void capi_ctr_ready(struct capi_ctr * card)
332{ 352{
333 card->cardstate = CARD_RUNNING; 353 card->cardstate = CARD_RUNNING;
334 354
335 printk(KERN_NOTICE "kcapi: card %d \"%s\" ready.\n", 355 printk(KERN_NOTICE "kcapi: card [%03d] \"%s\" ready.\n",
336 card->cnr, card->name); 356 card->cnr, card->name);
337 357
338 notify_push(KCI_CONTRUP, card->cnr, 0, 0); 358 notify_push(KCI_CONTRUP, card->cnr, 0, 0);
@@ -364,7 +384,7 @@ void capi_ctr_reseted(struct capi_ctr * card)
364 capi_ctr_put(card); 384 capi_ctr_put(card);
365 } 385 }
366 386
367 printk(KERN_NOTICE "kcapi: card %d down.\n", card->cnr); 387 printk(KERN_NOTICE "kcapi: card [%03d] down.\n", card->cnr);
368 388
369 notify_push(KCI_CONTRDOWN, card->cnr, 0, 0); 389 notify_push(KCI_CONTRDOWN, card->cnr, 0, 0);
370} 390}
@@ -374,7 +394,7 @@ EXPORT_SYMBOL(capi_ctr_reseted);
374void capi_ctr_suspend_output(struct capi_ctr *card) 394void capi_ctr_suspend_output(struct capi_ctr *card)
375{ 395{
376 if (!card->blocked) { 396 if (!card->blocked) {
377 printk(KERN_DEBUG "kcapi: card %d suspend\n", card->cnr); 397 printk(KERN_DEBUG "kcapi: card [%03d] suspend\n", card->cnr);
378 card->blocked = 1; 398 card->blocked = 1;
379 } 399 }
380} 400}
@@ -384,7 +404,7 @@ EXPORT_SYMBOL(capi_ctr_suspend_output);
384void capi_ctr_resume_output(struct capi_ctr *card) 404void capi_ctr_resume_output(struct capi_ctr *card)
385{ 405{
386 if (card->blocked) { 406 if (card->blocked) {
387 printk(KERN_DEBUG "kcapi: card %d resume\n", card->cnr); 407 printk(KERN_DEBUG "kcapi: card [%03d] resume\n", card->cnr);
388 card->blocked = 0; 408 card->blocked = 0;
389 } 409 }
390} 410}
@@ -432,7 +452,7 @@ attach_capi_ctr(struct capi_ctr *card)
432 } 452 }
433 453
434 ncards++; 454 ncards++;
435 printk(KERN_NOTICE "kcapi: Controller %d: %s attached\n", 455 printk(KERN_NOTICE "kcapi: Controller [%03d]: %s attached\n",
436 card->cnr, card->name); 456 card->cnr, card->name);
437 return 0; 457 return 0;
438} 458}
@@ -451,7 +471,7 @@ int detach_capi_ctr(struct capi_ctr *card)
451 card->procent = NULL; 471 card->procent = NULL;
452 } 472 }
453 capi_cards[card->cnr - 1] = NULL; 473 capi_cards[card->cnr - 1] = NULL;
454 printk(KERN_NOTICE "kcapi: Controller %d: %s unregistered\n", 474 printk(KERN_NOTICE "kcapi: Controller [%03d]: %s unregistered\n",
455 card->cnr, card->name); 475 card->cnr, card->name);
456 476
457 return 0; 477 return 0;
@@ -623,17 +643,25 @@ u16 capi20_put_message(struct capi20_appl *ap, struct sk_buff *skb)
623 showctl |= (card->traceflag & 1); 643 showctl |= (card->traceflag & 1);
624 if (showctl & 2) { 644 if (showctl & 2) {
625 if (showctl & 1) { 645 if (showctl & 1) {
626 printk(KERN_DEBUG "kcapi: put [%#x] id#%d %s len=%u\n", 646 printk(KERN_DEBUG "kcapi: put [%03d] id#%d %s len=%u\n",
627 CAPIMSG_CONTROLLER(skb->data), 647 CAPIMSG_CONTROLLER(skb->data),
628 CAPIMSG_APPID(skb->data), 648 CAPIMSG_APPID(skb->data),
629 capi_cmd2str(cmd, subcmd), 649 capi_cmd2str(cmd, subcmd),
630 CAPIMSG_LEN(skb->data)); 650 CAPIMSG_LEN(skb->data));
631 } else { 651 } else {
632 printk(KERN_DEBUG "kcapi: put [%#x] %s\n", 652 _cdebbuf *cdb = capi_message2str(skb->data);
633 CAPIMSG_CONTROLLER(skb->data), 653 if (cdb) {
634 capi_message2str(skb->data)); 654 printk(KERN_DEBUG "kcapi: put [%03d] %s\n",
655 CAPIMSG_CONTROLLER(skb->data),
656 cdb->buf);
657 cdebbuf_free(cdb);
658 } else
659 printk(KERN_DEBUG "kcapi: put [%03d] id#%d %s len=%u cannot trace\n",
660 CAPIMSG_CONTROLLER(skb->data),
661 CAPIMSG_APPID(skb->data),
662 capi_cmd2str(cmd, subcmd),
663 CAPIMSG_LEN(skb->data));
635 } 664 }
636
637 } 665 }
638 return card->send_message(card, skb); 666 return card->send_message(card, skb);
639} 667}
@@ -894,7 +922,7 @@ int capi20_manufacturer(unsigned int cmd, void __user *data)
894 return -ESRCH; 922 return -ESRCH;
895 923
896 card->traceflag = fdef.flag; 924 card->traceflag = fdef.flag;
897 printk(KERN_INFO "kcapi: contr %d set trace=%d\n", 925 printk(KERN_INFO "kcapi: contr [%03d] set trace=%d\n",
898 card->cnr, card->traceflag); 926 card->cnr, card->traceflag);
899 return 0; 927 return 0;
900 } 928 }
@@ -967,7 +995,11 @@ static int __init kcapi_init(void)
967{ 995{
968 char *p; 996 char *p;
969 char rev[32]; 997 char rev[32];
998 int ret;
970 999
1000 ret = cdebug_init();
1001 if (ret)
1002 return ret;
971 kcapi_proc_init(); 1003 kcapi_proc_init();
972 1004
973 if ((p = strchr(revision, ':')) != 0 && p[1]) { 1005 if ((p = strchr(revision, ':')) != 0 && p[1]) {
@@ -988,6 +1020,7 @@ static void __exit kcapi_exit(void)
988 1020
989 /* make sure all notifiers are finished */ 1021 /* make sure all notifiers are finished */
990 flush_scheduled_work(); 1022 flush_scheduled_work();
1023 cdebug_exit();
991} 1024}
992 1025
993module_init(kcapi_init); 1026module_init(kcapi_init);
diff --git a/drivers/isdn/gigaset/Makefile b/drivers/isdn/gigaset/Makefile
index 077e297d8c..e9d3189f56 100644
--- a/drivers/isdn/gigaset/Makefile
+++ b/drivers/isdn/gigaset/Makefile
@@ -1,8 +1,9 @@
1gigaset-y := common.o interface.o proc.o ev-layer.o i4l.o 1gigaset-y := common.o interface.o proc.o ev-layer.o i4l.o asyncdata.o
2usb_gigaset-y := usb-gigaset.o asyncdata.o 2usb_gigaset-y := usb-gigaset.o
3ser_gigaset-y := ser-gigaset.o
3bas_gigaset-y := bas-gigaset.o isocdata.o 4bas_gigaset-y := bas-gigaset.o isocdata.o
4ser_gigaset-y := ser-gigaset.o asyncdata.o
5 5
6obj-$(CONFIG_GIGASET_M105) += usb_gigaset.o gigaset.o 6obj-$(CONFIG_ISDN_DRV_GIGASET) += gigaset.o
7obj-$(CONFIG_GIGASET_BASE) += bas_gigaset.o gigaset.o 7obj-$(CONFIG_GIGASET_M105) += usb_gigaset.o
8obj-$(CONFIG_GIGASET_M101) += ser_gigaset.o gigaset.o 8obj-$(CONFIG_GIGASET_BASE) += bas_gigaset.o
9obj-$(CONFIG_GIGASET_M101) += ser_gigaset.o
diff --git a/drivers/isdn/gigaset/asyncdata.c b/drivers/isdn/gigaset/asyncdata.c
index ddf5e92be4..00a3be5b86 100644
--- a/drivers/isdn/gigaset/asyncdata.c
+++ b/drivers/isdn/gigaset/asyncdata.c
@@ -13,11 +13,6 @@
13 * ===================================================================== 13 * =====================================================================
14 */ 14 */
15 15
16/* not set by Kbuild when building both ser_gigaset and usb_gigaset */
17#ifndef KBUILD_MODNAME
18#define KBUILD_MODNAME "asy_gigaset"
19#endif
20
21#include "gigaset.h" 16#include "gigaset.h"
22#include <linux/crc-ccitt.h> 17#include <linux/crc-ccitt.h>
23#include <linux/bitrev.h> 18#include <linux/bitrev.h>
@@ -444,6 +439,7 @@ nextbyte:
444 atomic_set(&inbuf->head, head); 439 atomic_set(&inbuf->head, head);
445 } 440 }
446} 441}
442EXPORT_SYMBOL_GPL(gigaset_m10x_input);
447 443
448 444
449/* == data output ========================================================== */ 445/* == data output ========================================================== */
@@ -591,3 +587,4 @@ int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb)
591 587
592 return len; /* ok so far */ 588 return len; /* ok so far */
593} 589}
590EXPORT_SYMBOL_GPL(gigaset_m10x_send_skb);
diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c
index 4e3f127e40..1b2df80c3b 100644
--- a/drivers/isdn/i4l/isdn_ppp.c
+++ b/drivers/isdn/i4l/isdn_ppp.c
@@ -1680,7 +1680,7 @@ static void isdn_ppp_mp_receive(isdn_net_dev * net_dev, isdn_net_local * lp,
1680 * - we hit a gap in the sequence, so no reassembly/processing is 1680 * - we hit a gap in the sequence, so no reassembly/processing is
1681 * possible ('start' would be set to NULL) 1681 * possible ('start' would be set to NULL)
1682 * 1682 *
1683 * algorightm for this code is derived from code in the book 1683 * algorithm for this code is derived from code in the book
1684 * 'PPP Design And Debugging' by James Carlson (Addison-Wesley) 1684 * 'PPP Design And Debugging' by James Carlson (Addison-Wesley)
1685 */ 1685 */
1686 while (start != NULL || newfrag != NULL) { 1686 while (start != NULL || newfrag != NULL) {
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 04574a9d44..0d122bf889 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -14,6 +14,7 @@
14 14
15#include "vmx.h" 15#include "vmx.h"
16#include <linux/kvm.h> 16#include <linux/kvm.h>
17#include <linux/kvm_para.h>
17 18
18#define CR0_PE_MASK (1ULL << 0) 19#define CR0_PE_MASK (1ULL << 0)
19#define CR0_TS_MASK (1ULL << 3) 20#define CR0_TS_MASK (1ULL << 3)
@@ -237,6 +238,9 @@ struct kvm_vcpu {
237 unsigned long cr0; 238 unsigned long cr0;
238 unsigned long cr2; 239 unsigned long cr2;
239 unsigned long cr3; 240 unsigned long cr3;
241 gpa_t para_state_gpa;
242 struct page *para_state_page;
243 gpa_t hypercall_gpa;
240 unsigned long cr4; 244 unsigned long cr4;
241 unsigned long cr8; 245 unsigned long cr8;
242 u64 pdptrs[4]; /* pae */ 246 u64 pdptrs[4]; /* pae */
@@ -305,6 +309,7 @@ struct kvm {
305 int busy; 309 int busy;
306 unsigned long rmap_overflow; 310 unsigned long rmap_overflow;
307 struct list_head vm_list; 311 struct list_head vm_list;
312 struct file *filp;
308}; 313};
309 314
310struct kvm_stat { 315struct kvm_stat {
@@ -339,7 +344,7 @@ struct kvm_arch_ops {
339 int (*vcpu_create)(struct kvm_vcpu *vcpu); 344 int (*vcpu_create)(struct kvm_vcpu *vcpu);
340 void (*vcpu_free)(struct kvm_vcpu *vcpu); 345 void (*vcpu_free)(struct kvm_vcpu *vcpu);
341 346
342 struct kvm_vcpu *(*vcpu_load)(struct kvm_vcpu *vcpu); 347 void (*vcpu_load)(struct kvm_vcpu *vcpu);
343 void (*vcpu_put)(struct kvm_vcpu *vcpu); 348 void (*vcpu_put)(struct kvm_vcpu *vcpu);
344 void (*vcpu_decache)(struct kvm_vcpu *vcpu); 349 void (*vcpu_decache)(struct kvm_vcpu *vcpu);
345 350
@@ -382,6 +387,8 @@ struct kvm_arch_ops {
382 int (*run)(struct kvm_vcpu *vcpu, struct kvm_run *run); 387 int (*run)(struct kvm_vcpu *vcpu, struct kvm_run *run);
383 int (*vcpu_setup)(struct kvm_vcpu *vcpu); 388 int (*vcpu_setup)(struct kvm_vcpu *vcpu);
384 void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu); 389 void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu);
390 void (*patch_hypercall)(struct kvm_vcpu *vcpu,
391 unsigned char *hypercall_addr);
385}; 392};
386 393
387extern struct kvm_stat kvm_stat; 394extern struct kvm_stat kvm_stat;
@@ -476,6 +483,8 @@ void kvm_mmu_post_write(struct kvm_vcpu *vcpu, gpa_t gpa, int bytes);
476int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva); 483int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva);
477void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu); 484void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
478 485
486int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run);
487
479static inline int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva, 488static inline int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva,
480 u32 error_code) 489 u32 error_code)
481{ 490{
@@ -523,7 +532,7 @@ static inline struct kvm_mmu_page *page_header(hpa_t shadow_page)
523{ 532{
524 struct page *page = pfn_to_page(shadow_page >> PAGE_SHIFT); 533 struct page *page = pfn_to_page(shadow_page >> PAGE_SHIFT);
525 534
526 return (struct kvm_mmu_page *)page->private; 535 return (struct kvm_mmu_page *)page_private(page);
527} 536}
528 537
529static inline u16 read_fs(void) 538static inline u16 read_fs(void)
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index af866147ff..a163bca389 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -20,6 +20,7 @@
20#include <linux/kvm.h> 20#include <linux/kvm.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/errno.h> 22#include <linux/errno.h>
23#include <linux/magic.h>
23#include <asm/processor.h> 24#include <asm/processor.h>
24#include <linux/percpu.h> 25#include <linux/percpu.h>
25#include <linux/gfp.h> 26#include <linux/gfp.h>
@@ -36,6 +37,9 @@
36#include <asm/desc.h> 37#include <asm/desc.h>
37#include <linux/sysdev.h> 38#include <linux/sysdev.h>
38#include <linux/cpu.h> 39#include <linux/cpu.h>
40#include <linux/file.h>
41#include <linux/fs.h>
42#include <linux/mount.h>
39 43
40#include "x86_emulate.h" 44#include "x86_emulate.h"
41#include "segment_descriptor.h" 45#include "segment_descriptor.h"
@@ -72,6 +76,8 @@ static struct kvm_stats_debugfs_item {
72 76
73static struct dentry *debugfs_dir; 77static struct dentry *debugfs_dir;
74 78
79struct vfsmount *kvmfs_mnt;
80
75#define MAX_IO_MSRS 256 81#define MAX_IO_MSRS 256
76 82
77#define CR0_RESEVED_BITS 0xffffffff1ffaffc0ULL 83#define CR0_RESEVED_BITS 0xffffffff1ffaffc0ULL
@@ -90,6 +96,58 @@ struct segment_descriptor_64 {
90 96
91#endif 97#endif
92 98
99static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl,
100 unsigned long arg);
101
102static struct inode *kvmfs_inode(struct file_operations *fops)
103{
104 int error = -ENOMEM;
105 struct inode *inode = new_inode(kvmfs_mnt->mnt_sb);
106
107 if (!inode)
108 goto eexit_1;
109
110 inode->i_fop = fops;
111
112 /*
113 * Mark the inode dirty from the very beginning,
114 * that way it will never be moved to the dirty
115 * list because mark_inode_dirty() will think
116 * that it already _is_ on the dirty list.
117 */
118 inode->i_state = I_DIRTY;
119 inode->i_mode = S_IRUSR | S_IWUSR;
120 inode->i_uid = current->fsuid;
121 inode->i_gid = current->fsgid;
122 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
123 return inode;
124
125eexit_1:
126 return ERR_PTR(error);
127}
128
129static struct file *kvmfs_file(struct inode *inode, void *private_data)
130{
131 struct file *file = get_empty_filp();
132
133 if (!file)
134 return ERR_PTR(-ENFILE);
135
136 file->f_path.mnt = mntget(kvmfs_mnt);
137 file->f_path.dentry = d_alloc_anon(inode);
138 if (!file->f_path.dentry)
139 return ERR_PTR(-ENOMEM);
140 file->f_mapping = inode->i_mapping;
141
142 file->f_pos = 0;
143 file->f_flags = O_RDWR;
144 file->f_op = inode->i_fop;
145 file->f_mode = FMODE_READ | FMODE_WRITE;
146 file->f_version = 0;
147 file->private_data = private_data;
148 return file;
149}
150
93unsigned long segment_base(u16 selector) 151unsigned long segment_base(u16 selector)
94{ 152{
95 struct descriptor_table gdt; 153 struct descriptor_table gdt;
@@ -126,10 +184,8 @@ static inline int valid_vcpu(int n)
126 return likely(n >= 0 && n < KVM_MAX_VCPUS); 184 return likely(n >= 0 && n < KVM_MAX_VCPUS);
127} 185}
128 186
129int kvm_read_guest(struct kvm_vcpu *vcpu, 187int kvm_read_guest(struct kvm_vcpu *vcpu, gva_t addr, unsigned long size,
130 gva_t addr, 188 void *dest)
131 unsigned long size,
132 void *dest)
133{ 189{
134 unsigned char *host_buf = dest; 190 unsigned char *host_buf = dest;
135 unsigned long req_size = size; 191 unsigned long req_size = size;
@@ -161,10 +217,8 @@ int kvm_read_guest(struct kvm_vcpu *vcpu,
161} 217}
162EXPORT_SYMBOL_GPL(kvm_read_guest); 218EXPORT_SYMBOL_GPL(kvm_read_guest);
163 219
164int kvm_write_guest(struct kvm_vcpu *vcpu, 220int kvm_write_guest(struct kvm_vcpu *vcpu, gva_t addr, unsigned long size,
165 gva_t addr, 221 void *data)
166 unsigned long size,
167 void *data)
168{ 222{
169 unsigned char *host_buf = data; 223 unsigned char *host_buf = data;
170 unsigned long req_size = size; 224 unsigned long req_size = size;
@@ -174,12 +228,15 @@ int kvm_write_guest(struct kvm_vcpu *vcpu,
174 unsigned now; 228 unsigned now;
175 unsigned offset; 229 unsigned offset;
176 hva_t guest_buf; 230 hva_t guest_buf;
231 gfn_t gfn;
177 232
178 paddr = gva_to_hpa(vcpu, addr); 233 paddr = gva_to_hpa(vcpu, addr);
179 234
180 if (is_error_hpa(paddr)) 235 if (is_error_hpa(paddr))
181 break; 236 break;
182 237
238 gfn = vcpu->mmu.gva_to_gpa(vcpu, addr) >> PAGE_SHIFT;
239 mark_page_dirty(vcpu->kvm, gfn);
183 guest_buf = (hva_t)kmap_atomic( 240 guest_buf = (hva_t)kmap_atomic(
184 pfn_to_page(paddr >> PAGE_SHIFT), KM_USER0); 241 pfn_to_page(paddr >> PAGE_SHIFT), KM_USER0);
185 offset = addr & ~PAGE_MASK; 242 offset = addr & ~PAGE_MASK;
@@ -195,24 +252,30 @@ int kvm_write_guest(struct kvm_vcpu *vcpu,
195} 252}
196EXPORT_SYMBOL_GPL(kvm_write_guest); 253EXPORT_SYMBOL_GPL(kvm_write_guest);
197 254
198static int vcpu_slot(struct kvm_vcpu *vcpu) 255/*
256 * Switches to specified vcpu, until a matching vcpu_put()
257 */
258static void vcpu_load(struct kvm_vcpu *vcpu)
199{ 259{
200 return vcpu - vcpu->kvm->vcpus; 260 mutex_lock(&vcpu->mutex);
261 kvm_arch_ops->vcpu_load(vcpu);
201} 262}
202 263
203/* 264/*
204 * Switches to specified vcpu, until a matching vcpu_put() 265 * Switches to specified vcpu, until a matching vcpu_put(). Will return NULL
266 * if the slot is not populated.
205 */ 267 */
206static struct kvm_vcpu *vcpu_load(struct kvm *kvm, int vcpu_slot) 268static struct kvm_vcpu *vcpu_load_slot(struct kvm *kvm, int slot)
207{ 269{
208 struct kvm_vcpu *vcpu = &kvm->vcpus[vcpu_slot]; 270 struct kvm_vcpu *vcpu = &kvm->vcpus[slot];
209 271
210 mutex_lock(&vcpu->mutex); 272 mutex_lock(&vcpu->mutex);
211 if (unlikely(!vcpu->vmcs)) { 273 if (!vcpu->vmcs) {
212 mutex_unlock(&vcpu->mutex); 274 mutex_unlock(&vcpu->mutex);
213 return NULL; 275 return NULL;
214 } 276 }
215 return kvm_arch_ops->vcpu_load(vcpu); 277 kvm_arch_ops->vcpu_load(vcpu);
278 return vcpu;
216} 279}
217 280
218static void vcpu_put(struct kvm_vcpu *vcpu) 281static void vcpu_put(struct kvm_vcpu *vcpu)
@@ -221,13 +284,13 @@ static void vcpu_put(struct kvm_vcpu *vcpu)
221 mutex_unlock(&vcpu->mutex); 284 mutex_unlock(&vcpu->mutex);
222} 285}
223 286
224static int kvm_dev_open(struct inode *inode, struct file *filp) 287static struct kvm *kvm_create_vm(void)
225{ 288{
226 struct kvm *kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL); 289 struct kvm *kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL);
227 int i; 290 int i;
228 291
229 if (!kvm) 292 if (!kvm)
230 return -ENOMEM; 293 return ERR_PTR(-ENOMEM);
231 294
232 spin_lock_init(&kvm->lock); 295 spin_lock_init(&kvm->lock);
233 INIT_LIST_HEAD(&kvm->active_mmu_pages); 296 INIT_LIST_HEAD(&kvm->active_mmu_pages);
@@ -243,7 +306,11 @@ static int kvm_dev_open(struct inode *inode, struct file *filp)
243 list_add(&kvm->vm_list, &vm_list); 306 list_add(&kvm->vm_list, &vm_list);
244 spin_unlock(&kvm_lock); 307 spin_unlock(&kvm_lock);
245 } 308 }
246 filp->private_data = kvm; 309 return kvm;
310}
311
312static int kvm_dev_open(struct inode *inode, struct file *filp)
313{
247 return 0; 314 return 0;
248} 315}
249 316
@@ -281,9 +348,10 @@ static void kvm_free_physmem(struct kvm *kvm)
281 348
282static void kvm_free_vcpu(struct kvm_vcpu *vcpu) 349static void kvm_free_vcpu(struct kvm_vcpu *vcpu)
283{ 350{
284 if (!vcpu_load(vcpu->kvm, vcpu_slot(vcpu))) 351 if (!vcpu->vmcs)
285 return; 352 return;
286 353
354 vcpu_load(vcpu);
287 kvm_mmu_destroy(vcpu); 355 kvm_mmu_destroy(vcpu);
288 vcpu_put(vcpu); 356 vcpu_put(vcpu);
289 kvm_arch_ops->vcpu_free(vcpu); 357 kvm_arch_ops->vcpu_free(vcpu);
@@ -299,14 +367,24 @@ static void kvm_free_vcpus(struct kvm *kvm)
299 367
300static int kvm_dev_release(struct inode *inode, struct file *filp) 368static int kvm_dev_release(struct inode *inode, struct file *filp)
301{ 369{
302 struct kvm *kvm = filp->private_data; 370 return 0;
371}
303 372
373static void kvm_destroy_vm(struct kvm *kvm)
374{
304 spin_lock(&kvm_lock); 375 spin_lock(&kvm_lock);
305 list_del(&kvm->vm_list); 376 list_del(&kvm->vm_list);
306 spin_unlock(&kvm_lock); 377 spin_unlock(&kvm_lock);
307 kvm_free_vcpus(kvm); 378 kvm_free_vcpus(kvm);
308 kvm_free_physmem(kvm); 379 kvm_free_physmem(kvm);
309 kfree(kvm); 380 kfree(kvm);
381}
382
383static int kvm_vm_release(struct inode *inode, struct file *filp)
384{
385 struct kvm *kvm = filp->private_data;
386
387 kvm_destroy_vm(kvm);
310 return 0; 388 return 0;
311} 389}
312 390
@@ -457,7 +535,7 @@ EXPORT_SYMBOL_GPL(set_cr4);
457void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3) 535void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
458{ 536{
459 if (is_long_mode(vcpu)) { 537 if (is_long_mode(vcpu)) {
460 if ( cr3 & CR3_L_MODE_RESEVED_BITS) { 538 if (cr3 & CR3_L_MODE_RESEVED_BITS) {
461 printk(KERN_DEBUG "set_cr3: #GP, reserved bits\n"); 539 printk(KERN_DEBUG "set_cr3: #GP, reserved bits\n");
462 inject_gp(vcpu); 540 inject_gp(vcpu);
463 return; 541 return;
@@ -533,55 +611,11 @@ void fx_init(struct kvm_vcpu *vcpu)
533} 611}
534EXPORT_SYMBOL_GPL(fx_init); 612EXPORT_SYMBOL_GPL(fx_init);
535 613
536/* 614static void do_remove_write_access(struct kvm_vcpu *vcpu, int slot)
537 * Creates some virtual cpus. Good luck creating more than one.
538 */
539static int kvm_dev_ioctl_create_vcpu(struct kvm *kvm, int n)
540{ 615{
541 int r; 616 spin_lock(&vcpu->kvm->lock);
542 struct kvm_vcpu *vcpu; 617 kvm_mmu_slot_remove_write_access(vcpu, slot);
543 618 spin_unlock(&vcpu->kvm->lock);
544 r = -EINVAL;
545 if (!valid_vcpu(n))
546 goto out;
547
548 vcpu = &kvm->vcpus[n];
549
550 mutex_lock(&vcpu->mutex);
551
552 if (vcpu->vmcs) {
553 mutex_unlock(&vcpu->mutex);
554 return -EEXIST;
555 }
556
557 vcpu->host_fx_image = (char*)ALIGN((hva_t)vcpu->fx_buf,
558 FX_IMAGE_ALIGN);
559 vcpu->guest_fx_image = vcpu->host_fx_image + FX_IMAGE_SIZE;
560
561 r = kvm_arch_ops->vcpu_create(vcpu);
562 if (r < 0)
563 goto out_free_vcpus;
564
565 r = kvm_mmu_create(vcpu);
566 if (r < 0)
567 goto out_free_vcpus;
568
569 kvm_arch_ops->vcpu_load(vcpu);
570 r = kvm_mmu_setup(vcpu);
571 if (r >= 0)
572 r = kvm_arch_ops->vcpu_setup(vcpu);
573 vcpu_put(vcpu);
574
575 if (r < 0)
576 goto out_free_vcpus;
577
578 return 0;
579
580out_free_vcpus:
581 kvm_free_vcpu(vcpu);
582 mutex_unlock(&vcpu->mutex);
583out:
584 return r;
585} 619}
586 620
587/* 621/*
@@ -590,8 +624,8 @@ out:
590 * 624 *
591 * Discontiguous memory is allowed, mostly for framebuffers. 625 * Discontiguous memory is allowed, mostly for framebuffers.
592 */ 626 */
593static int kvm_dev_ioctl_set_memory_region(struct kvm *kvm, 627static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
594 struct kvm_memory_region *mem) 628 struct kvm_memory_region *mem)
595{ 629{
596 int r; 630 int r;
597 gfn_t base_gfn; 631 gfn_t base_gfn;
@@ -674,7 +708,7 @@ raced:
674 | __GFP_ZERO); 708 | __GFP_ZERO);
675 if (!new.phys_mem[i]) 709 if (!new.phys_mem[i])
676 goto out_free; 710 goto out_free;
677 new.phys_mem[i]->private = 0; 711 set_page_private(new.phys_mem[i],0);
678 } 712 }
679 } 713 }
680 714
@@ -711,9 +745,11 @@ raced:
711 for (i = 0; i < KVM_MAX_VCPUS; ++i) { 745 for (i = 0; i < KVM_MAX_VCPUS; ++i) {
712 struct kvm_vcpu *vcpu; 746 struct kvm_vcpu *vcpu;
713 747
714 vcpu = vcpu_load(kvm, i); 748 vcpu = vcpu_load_slot(kvm, i);
715 if (!vcpu) 749 if (!vcpu)
716 continue; 750 continue;
751 if (new.flags & KVM_MEM_LOG_DIRTY_PAGES)
752 do_remove_write_access(vcpu, mem->slot);
717 kvm_mmu_reset_context(vcpu); 753 kvm_mmu_reset_context(vcpu);
718 vcpu_put(vcpu); 754 vcpu_put(vcpu);
719 } 755 }
@@ -729,18 +765,11 @@ out:
729 return r; 765 return r;
730} 766}
731 767
732static void do_remove_write_access(struct kvm_vcpu *vcpu, int slot)
733{
734 spin_lock(&vcpu->kvm->lock);
735 kvm_mmu_slot_remove_write_access(vcpu, slot);
736 spin_unlock(&vcpu->kvm->lock);
737}
738
739/* 768/*
740 * Get (and clear) the dirty memory log for a memory slot. 769 * Get (and clear) the dirty memory log for a memory slot.
741 */ 770 */
742static int kvm_dev_ioctl_get_dirty_log(struct kvm *kvm, 771static int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
743 struct kvm_dirty_log *log) 772 struct kvm_dirty_log *log)
744{ 773{
745 struct kvm_memory_slot *memslot; 774 struct kvm_memory_slot *memslot;
746 int r, i; 775 int r, i;
@@ -765,21 +794,21 @@ static int kvm_dev_ioctl_get_dirty_log(struct kvm *kvm,
765 if (!memslot->dirty_bitmap) 794 if (!memslot->dirty_bitmap)
766 goto out; 795 goto out;
767 796
768 n = ALIGN(memslot->npages, 8) / 8; 797 n = ALIGN(memslot->npages, BITS_PER_LONG) / 8;
769 798
770 for (i = 0; !any && i < n; ++i) 799 for (i = 0; !any && i < n/sizeof(long); ++i)
771 any = memslot->dirty_bitmap[i]; 800 any = memslot->dirty_bitmap[i];
772 801
773 r = -EFAULT; 802 r = -EFAULT;
774 if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n)) 803 if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n))
775 goto out; 804 goto out;
776 805
777
778 if (any) { 806 if (any) {
779 cleared = 0; 807 cleared = 0;
780 for (i = 0; i < KVM_MAX_VCPUS; ++i) { 808 for (i = 0; i < KVM_MAX_VCPUS; ++i) {
781 struct kvm_vcpu *vcpu = vcpu_load(kvm, i); 809 struct kvm_vcpu *vcpu;
782 810
811 vcpu = vcpu_load_slot(kvm, i);
783 if (!vcpu) 812 if (!vcpu)
784 continue; 813 continue;
785 if (!cleared) { 814 if (!cleared) {
@@ -903,8 +932,9 @@ static int emulator_read_emulated(unsigned long addr,
903 return X86EMUL_CONTINUE; 932 return X86EMUL_CONTINUE;
904 else { 933 else {
905 gpa_t gpa = vcpu->mmu.gva_to_gpa(vcpu, addr); 934 gpa_t gpa = vcpu->mmu.gva_to_gpa(vcpu, addr);
935
906 if (gpa == UNMAPPED_GVA) 936 if (gpa == UNMAPPED_GVA)
907 return vcpu_printf(vcpu, "not present\n"), X86EMUL_PROPAGATE_FAULT; 937 return X86EMUL_PROPAGATE_FAULT;
908 vcpu->mmio_needed = 1; 938 vcpu->mmio_needed = 1;
909 vcpu->mmio_phys_addr = gpa; 939 vcpu->mmio_phys_addr = gpa;
910 vcpu->mmio_size = bytes; 940 vcpu->mmio_size = bytes;
@@ -928,6 +958,7 @@ static int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
928 return 0; 958 return 0;
929 page = gfn_to_page(m, gpa >> PAGE_SHIFT); 959 page = gfn_to_page(m, gpa >> PAGE_SHIFT);
930 kvm_mmu_pre_write(vcpu, gpa, bytes); 960 kvm_mmu_pre_write(vcpu, gpa, bytes);
961 mark_page_dirty(vcpu->kvm, gpa >> PAGE_SHIFT);
931 virt = kmap_atomic(page, KM_USER0); 962 virt = kmap_atomic(page, KM_USER0);
932 memcpy(virt + offset_in_page(gpa), &val, bytes); 963 memcpy(virt + offset_in_page(gpa), &val, bytes);
933 kunmap_atomic(virt, KM_USER0); 964 kunmap_atomic(virt, KM_USER0);
@@ -1142,6 +1173,42 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
1142} 1173}
1143EXPORT_SYMBOL_GPL(emulate_instruction); 1174EXPORT_SYMBOL_GPL(emulate_instruction);
1144 1175
1176int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run)
1177{
1178 unsigned long nr, a0, a1, a2, a3, a4, a5, ret;
1179
1180 kvm_arch_ops->decache_regs(vcpu);
1181 ret = -KVM_EINVAL;
1182#ifdef CONFIG_X86_64
1183 if (is_long_mode(vcpu)) {
1184 nr = vcpu->regs[VCPU_REGS_RAX];
1185 a0 = vcpu->regs[VCPU_REGS_RDI];
1186 a1 = vcpu->regs[VCPU_REGS_RSI];
1187 a2 = vcpu->regs[VCPU_REGS_RDX];
1188 a3 = vcpu->regs[VCPU_REGS_RCX];
1189 a4 = vcpu->regs[VCPU_REGS_R8];
1190 a5 = vcpu->regs[VCPU_REGS_R9];
1191 } else
1192#endif
1193 {
1194 nr = vcpu->regs[VCPU_REGS_RBX] & -1u;
1195 a0 = vcpu->regs[VCPU_REGS_RAX] & -1u;
1196 a1 = vcpu->regs[VCPU_REGS_RCX] & -1u;
1197 a2 = vcpu->regs[VCPU_REGS_RDX] & -1u;
1198 a3 = vcpu->regs[VCPU_REGS_RSI] & -1u;
1199 a4 = vcpu->regs[VCPU_REGS_RDI] & -1u;
1200 a5 = vcpu->regs[VCPU_REGS_RBP] & -1u;
1201 }
1202 switch (nr) {
1203 default:
1204 ;
1205 }
1206 vcpu->regs[VCPU_REGS_RAX] = ret;
1207 kvm_arch_ops->cache_regs(vcpu);
1208 return 1;
1209}
1210EXPORT_SYMBOL_GPL(kvm_hypercall);
1211
1145static u64 mk_cr_64(u64 curr_cr, u32 new_val) 1212static u64 mk_cr_64(u64 curr_cr, u32 new_val)
1146{ 1213{
1147 return (curr_cr & ~((1ULL << 32) - 1)) | new_val; 1214 return (curr_cr & ~((1ULL << 32) - 1)) | new_val;
@@ -1208,6 +1275,75 @@ void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long val,
1208 } 1275 }
1209} 1276}
1210 1277
1278/*
1279 * Register the para guest with the host:
1280 */
1281static int vcpu_register_para(struct kvm_vcpu *vcpu, gpa_t para_state_gpa)
1282{
1283 struct kvm_vcpu_para_state *para_state;
1284 hpa_t para_state_hpa, hypercall_hpa;
1285 struct page *para_state_page;
1286 unsigned char *hypercall;
1287 gpa_t hypercall_gpa;
1288
1289 printk(KERN_DEBUG "kvm: guest trying to enter paravirtual mode\n");
1290 printk(KERN_DEBUG ".... para_state_gpa: %08Lx\n", para_state_gpa);
1291
1292 /*
1293 * Needs to be page aligned:
1294 */
1295 if (para_state_gpa != PAGE_ALIGN(para_state_gpa))
1296 goto err_gp;
1297
1298 para_state_hpa = gpa_to_hpa(vcpu, para_state_gpa);
1299 printk(KERN_DEBUG ".... para_state_hpa: %08Lx\n", para_state_hpa);
1300 if (is_error_hpa(para_state_hpa))
1301 goto err_gp;
1302
1303 mark_page_dirty(vcpu->kvm, para_state_gpa >> PAGE_SHIFT);
1304 para_state_page = pfn_to_page(para_state_hpa >> PAGE_SHIFT);
1305 para_state = kmap_atomic(para_state_page, KM_USER0);
1306
1307 printk(KERN_DEBUG ".... guest version: %d\n", para_state->guest_version);
1308 printk(KERN_DEBUG ".... size: %d\n", para_state->size);
1309
1310 para_state->host_version = KVM_PARA_API_VERSION;
1311 /*
1312 * We cannot support guests that try to register themselves
1313 * with a newer API version than the host supports:
1314 */
1315 if (para_state->guest_version > KVM_PARA_API_VERSION) {
1316 para_state->ret = -KVM_EINVAL;
1317 goto err_kunmap_skip;
1318 }
1319
1320 hypercall_gpa = para_state->hypercall_gpa;
1321 hypercall_hpa = gpa_to_hpa(vcpu, hypercall_gpa);
1322 printk(KERN_DEBUG ".... hypercall_hpa: %08Lx\n", hypercall_hpa);
1323 if (is_error_hpa(hypercall_hpa)) {
1324 para_state->ret = -KVM_EINVAL;
1325 goto err_kunmap_skip;
1326 }
1327
1328 printk(KERN_DEBUG "kvm: para guest successfully registered.\n");
1329 vcpu->para_state_page = para_state_page;
1330 vcpu->para_state_gpa = para_state_gpa;
1331 vcpu->hypercall_gpa = hypercall_gpa;
1332
1333 mark_page_dirty(vcpu->kvm, hypercall_gpa >> PAGE_SHIFT);
1334 hypercall = kmap_atomic(pfn_to_page(hypercall_hpa >> PAGE_SHIFT),
1335 KM_USER1) + (hypercall_hpa & ~PAGE_MASK);
1336 kvm_arch_ops->patch_hypercall(vcpu, hypercall);
1337 kunmap_atomic(hypercall, KM_USER1);
1338
1339 para_state->ret = 0;
1340err_kunmap_skip:
1341 kunmap_atomic(para_state, KM_USER0);
1342 return 0;
1343err_gp:
1344 return 1;
1345}
1346
1211int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) 1347int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
1212{ 1348{
1213 u64 data; 1349 u64 data;
@@ -1316,6 +1452,12 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
1316 case MSR_IA32_MISC_ENABLE: 1452 case MSR_IA32_MISC_ENABLE:
1317 vcpu->ia32_misc_enable_msr = data; 1453 vcpu->ia32_misc_enable_msr = data;
1318 break; 1454 break;
1455 /*
1456 * This is the 'probe whether the host is KVM' logic:
1457 */
1458 case MSR_KVM_API_MAGIC:
1459 return vcpu_register_para(vcpu, data);
1460
1319 default: 1461 default:
1320 printk(KERN_ERR "kvm: unhandled wrmsr: 0x%x\n", msr); 1462 printk(KERN_ERR "kvm: unhandled wrmsr: 0x%x\n", msr);
1321 return 1; 1463 return 1;
@@ -1338,8 +1480,7 @@ void kvm_resched(struct kvm_vcpu *vcpu)
1338{ 1480{
1339 vcpu_put(vcpu); 1481 vcpu_put(vcpu);
1340 cond_resched(); 1482 cond_resched();
1341 /* Cannot fail - no vcpu unplug yet. */ 1483 vcpu_load(vcpu);
1342 vcpu_load(vcpu->kvm, vcpu_slot(vcpu));
1343} 1484}
1344EXPORT_SYMBOL_GPL(kvm_resched); 1485EXPORT_SYMBOL_GPL(kvm_resched);
1345 1486
@@ -1361,17 +1502,11 @@ void save_msrs(struct vmx_msr_entry *e, int n)
1361} 1502}
1362EXPORT_SYMBOL_GPL(save_msrs); 1503EXPORT_SYMBOL_GPL(save_msrs);
1363 1504
1364static int kvm_dev_ioctl_run(struct kvm *kvm, struct kvm_run *kvm_run) 1505static int kvm_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1365{ 1506{
1366 struct kvm_vcpu *vcpu;
1367 int r; 1507 int r;
1368 1508
1369 if (!valid_vcpu(kvm_run->vcpu)) 1509 vcpu_load(vcpu);
1370 return -EINVAL;
1371
1372 vcpu = vcpu_load(kvm, kvm_run->vcpu);
1373 if (!vcpu)
1374 return -ENOENT;
1375 1510
1376 /* re-sync apic's tpr */ 1511 /* re-sync apic's tpr */
1377 vcpu->cr8 = kvm_run->cr8; 1512 vcpu->cr8 = kvm_run->cr8;
@@ -1394,16 +1529,10 @@ static int kvm_dev_ioctl_run(struct kvm *kvm, struct kvm_run *kvm_run)
1394 return r; 1529 return r;
1395} 1530}
1396 1531
1397static int kvm_dev_ioctl_get_regs(struct kvm *kvm, struct kvm_regs *regs) 1532static int kvm_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu,
1533 struct kvm_regs *regs)
1398{ 1534{
1399 struct kvm_vcpu *vcpu; 1535 vcpu_load(vcpu);
1400
1401 if (!valid_vcpu(regs->vcpu))
1402 return -EINVAL;
1403
1404 vcpu = vcpu_load(kvm, regs->vcpu);
1405 if (!vcpu)
1406 return -ENOENT;
1407 1536
1408 kvm_arch_ops->cache_regs(vcpu); 1537 kvm_arch_ops->cache_regs(vcpu);
1409 1538
@@ -1440,16 +1569,10 @@ static int kvm_dev_ioctl_get_regs(struct kvm *kvm, struct kvm_regs *regs)
1440 return 0; 1569 return 0;
1441} 1570}
1442 1571
1443static int kvm_dev_ioctl_set_regs(struct kvm *kvm, struct kvm_regs *regs) 1572static int kvm_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu,
1573 struct kvm_regs *regs)
1444{ 1574{
1445 struct kvm_vcpu *vcpu; 1575 vcpu_load(vcpu);
1446
1447 if (!valid_vcpu(regs->vcpu))
1448 return -EINVAL;
1449
1450 vcpu = vcpu_load(kvm, regs->vcpu);
1451 if (!vcpu)
1452 return -ENOENT;
1453 1576
1454 vcpu->regs[VCPU_REGS_RAX] = regs->rax; 1577 vcpu->regs[VCPU_REGS_RAX] = regs->rax;
1455 vcpu->regs[VCPU_REGS_RBX] = regs->rbx; 1578 vcpu->regs[VCPU_REGS_RBX] = regs->rbx;
@@ -1486,16 +1609,12 @@ static void get_segment(struct kvm_vcpu *vcpu,
1486 return kvm_arch_ops->get_segment(vcpu, var, seg); 1609 return kvm_arch_ops->get_segment(vcpu, var, seg);
1487} 1610}
1488 1611
1489static int kvm_dev_ioctl_get_sregs(struct kvm *kvm, struct kvm_sregs *sregs) 1612static int kvm_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
1613 struct kvm_sregs *sregs)
1490{ 1614{
1491 struct kvm_vcpu *vcpu;
1492 struct descriptor_table dt; 1615 struct descriptor_table dt;
1493 1616
1494 if (!valid_vcpu(sregs->vcpu)) 1617 vcpu_load(vcpu);
1495 return -EINVAL;
1496 vcpu = vcpu_load(kvm, sregs->vcpu);
1497 if (!vcpu)
1498 return -ENOENT;
1499 1618
1500 get_segment(vcpu, &sregs->cs, VCPU_SREG_CS); 1619 get_segment(vcpu, &sregs->cs, VCPU_SREG_CS);
1501 get_segment(vcpu, &sregs->ds, VCPU_SREG_DS); 1620 get_segment(vcpu, &sregs->ds, VCPU_SREG_DS);
@@ -1537,18 +1656,14 @@ static void set_segment(struct kvm_vcpu *vcpu,
1537 return kvm_arch_ops->set_segment(vcpu, var, seg); 1656 return kvm_arch_ops->set_segment(vcpu, var, seg);
1538} 1657}
1539 1658
1540static int kvm_dev_ioctl_set_sregs(struct kvm *kvm, struct kvm_sregs *sregs) 1659static int kvm_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
1660 struct kvm_sregs *sregs)
1541{ 1661{
1542 struct kvm_vcpu *vcpu;
1543 int mmu_reset_needed = 0; 1662 int mmu_reset_needed = 0;
1544 int i; 1663 int i;
1545 struct descriptor_table dt; 1664 struct descriptor_table dt;
1546 1665
1547 if (!valid_vcpu(sregs->vcpu)) 1666 vcpu_load(vcpu);
1548 return -EINVAL;
1549 vcpu = vcpu_load(kvm, sregs->vcpu);
1550 if (!vcpu)
1551 return -ENOENT;
1552 1667
1553 set_segment(vcpu, &sregs->cs, VCPU_SREG_CS); 1668 set_segment(vcpu, &sregs->cs, VCPU_SREG_CS);
1554 set_segment(vcpu, &sregs->ds, VCPU_SREG_DS); 1669 set_segment(vcpu, &sregs->ds, VCPU_SREG_DS);
@@ -1654,20 +1769,14 @@ static int do_set_msr(struct kvm_vcpu *vcpu, unsigned index, u64 *data)
1654 * 1769 *
1655 * @return number of msrs set successfully. 1770 * @return number of msrs set successfully.
1656 */ 1771 */
1657static int __msr_io(struct kvm *kvm, struct kvm_msrs *msrs, 1772static int __msr_io(struct kvm_vcpu *vcpu, struct kvm_msrs *msrs,
1658 struct kvm_msr_entry *entries, 1773 struct kvm_msr_entry *entries,
1659 int (*do_msr)(struct kvm_vcpu *vcpu, 1774 int (*do_msr)(struct kvm_vcpu *vcpu,
1660 unsigned index, u64 *data)) 1775 unsigned index, u64 *data))
1661{ 1776{
1662 struct kvm_vcpu *vcpu;
1663 int i; 1777 int i;
1664 1778
1665 if (!valid_vcpu(msrs->vcpu)) 1779 vcpu_load(vcpu);
1666 return -EINVAL;
1667
1668 vcpu = vcpu_load(kvm, msrs->vcpu);
1669 if (!vcpu)
1670 return -ENOENT;
1671 1780
1672 for (i = 0; i < msrs->nmsrs; ++i) 1781 for (i = 0; i < msrs->nmsrs; ++i)
1673 if (do_msr(vcpu, entries[i].index, &entries[i].data)) 1782 if (do_msr(vcpu, entries[i].index, &entries[i].data))
@@ -1683,7 +1792,7 @@ static int __msr_io(struct kvm *kvm, struct kvm_msrs *msrs,
1683 * 1792 *
1684 * @return number of msrs set successfully. 1793 * @return number of msrs set successfully.
1685 */ 1794 */
1686static int msr_io(struct kvm *kvm, struct kvm_msrs __user *user_msrs, 1795static int msr_io(struct kvm_vcpu *vcpu, struct kvm_msrs __user *user_msrs,
1687 int (*do_msr)(struct kvm_vcpu *vcpu, 1796 int (*do_msr)(struct kvm_vcpu *vcpu,
1688 unsigned index, u64 *data), 1797 unsigned index, u64 *data),
1689 int writeback) 1798 int writeback)
@@ -1711,7 +1820,7 @@ static int msr_io(struct kvm *kvm, struct kvm_msrs __user *user_msrs,
1711 if (copy_from_user(entries, user_msrs->entries, size)) 1820 if (copy_from_user(entries, user_msrs->entries, size))
1712 goto out_free; 1821 goto out_free;
1713 1822
1714 r = n = __msr_io(kvm, &msrs, entries, do_msr); 1823 r = n = __msr_io(vcpu, &msrs, entries, do_msr);
1715 if (r < 0) 1824 if (r < 0)
1716 goto out_free; 1825 goto out_free;
1717 1826
@@ -1730,38 +1839,31 @@ out:
1730/* 1839/*
1731 * Translate a guest virtual address to a guest physical address. 1840 * Translate a guest virtual address to a guest physical address.
1732 */ 1841 */
1733static int kvm_dev_ioctl_translate(struct kvm *kvm, struct kvm_translation *tr) 1842static int kvm_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
1843 struct kvm_translation *tr)
1734{ 1844{
1735 unsigned long vaddr = tr->linear_address; 1845 unsigned long vaddr = tr->linear_address;
1736 struct kvm_vcpu *vcpu;
1737 gpa_t gpa; 1846 gpa_t gpa;
1738 1847
1739 vcpu = vcpu_load(kvm, tr->vcpu); 1848 vcpu_load(vcpu);
1740 if (!vcpu) 1849 spin_lock(&vcpu->kvm->lock);
1741 return -ENOENT;
1742 spin_lock(&kvm->lock);
1743 gpa = vcpu->mmu.gva_to_gpa(vcpu, vaddr); 1850 gpa = vcpu->mmu.gva_to_gpa(vcpu, vaddr);
1744 tr->physical_address = gpa; 1851 tr->physical_address = gpa;
1745 tr->valid = gpa != UNMAPPED_GVA; 1852 tr->valid = gpa != UNMAPPED_GVA;
1746 tr->writeable = 1; 1853 tr->writeable = 1;
1747 tr->usermode = 0; 1854 tr->usermode = 0;
1748 spin_unlock(&kvm->lock); 1855 spin_unlock(&vcpu->kvm->lock);
1749 vcpu_put(vcpu); 1856 vcpu_put(vcpu);
1750 1857
1751 return 0; 1858 return 0;
1752} 1859}
1753 1860
1754static int kvm_dev_ioctl_interrupt(struct kvm *kvm, struct kvm_interrupt *irq) 1861static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
1862 struct kvm_interrupt *irq)
1755{ 1863{
1756 struct kvm_vcpu *vcpu;
1757
1758 if (!valid_vcpu(irq->vcpu))
1759 return -EINVAL;
1760 if (irq->irq < 0 || irq->irq >= 256) 1864 if (irq->irq < 0 || irq->irq >= 256)
1761 return -EINVAL; 1865 return -EINVAL;
1762 vcpu = vcpu_load(kvm, irq->vcpu); 1866 vcpu_load(vcpu);
1763 if (!vcpu)
1764 return -ENOENT;
1765 1867
1766 set_bit(irq->irq, vcpu->irq_pending); 1868 set_bit(irq->irq, vcpu->irq_pending);
1767 set_bit(irq->irq / BITS_PER_LONG, &vcpu->irq_summary); 1869 set_bit(irq->irq / BITS_PER_LONG, &vcpu->irq_summary);
@@ -1771,17 +1873,12 @@ static int kvm_dev_ioctl_interrupt(struct kvm *kvm, struct kvm_interrupt *irq)
1771 return 0; 1873 return 0;
1772} 1874}
1773 1875
1774static int kvm_dev_ioctl_debug_guest(struct kvm *kvm, 1876static int kvm_vcpu_ioctl_debug_guest(struct kvm_vcpu *vcpu,
1775 struct kvm_debug_guest *dbg) 1877 struct kvm_debug_guest *dbg)
1776{ 1878{
1777 struct kvm_vcpu *vcpu;
1778 int r; 1879 int r;
1779 1880
1780 if (!valid_vcpu(dbg->vcpu)) 1881 vcpu_load(vcpu);
1781 return -EINVAL;
1782 vcpu = vcpu_load(kvm, dbg->vcpu);
1783 if (!vcpu)
1784 return -ENOENT;
1785 1882
1786 r = kvm_arch_ops->set_guest_debug(vcpu, dbg); 1883 r = kvm_arch_ops->set_guest_debug(vcpu, dbg);
1787 1884
@@ -1790,30 +1887,129 @@ static int kvm_dev_ioctl_debug_guest(struct kvm *kvm,
1790 return r; 1887 return r;
1791} 1888}
1792 1889
1793static long kvm_dev_ioctl(struct file *filp, 1890static int kvm_vcpu_release(struct inode *inode, struct file *filp)
1794 unsigned int ioctl, unsigned long arg)
1795{ 1891{
1796 struct kvm *kvm = filp->private_data; 1892 struct kvm_vcpu *vcpu = filp->private_data;
1893
1894 fput(vcpu->kvm->filp);
1895 return 0;
1896}
1897
1898static struct file_operations kvm_vcpu_fops = {
1899 .release = kvm_vcpu_release,
1900 .unlocked_ioctl = kvm_vcpu_ioctl,
1901 .compat_ioctl = kvm_vcpu_ioctl,
1902};
1903
1904/*
1905 * Allocates an inode for the vcpu.
1906 */
1907static int create_vcpu_fd(struct kvm_vcpu *vcpu)
1908{
1909 int fd, r;
1910 struct inode *inode;
1911 struct file *file;
1912
1913 atomic_inc(&vcpu->kvm->filp->f_count);
1914 inode = kvmfs_inode(&kvm_vcpu_fops);
1915 if (IS_ERR(inode)) {
1916 r = PTR_ERR(inode);
1917 goto out1;
1918 }
1919
1920 file = kvmfs_file(inode, vcpu);
1921 if (IS_ERR(file)) {
1922 r = PTR_ERR(file);
1923 goto out2;
1924 }
1925
1926 r = get_unused_fd();
1927 if (r < 0)
1928 goto out3;
1929 fd = r;
1930 fd_install(fd, file);
1931
1932 return fd;
1933
1934out3:
1935 fput(file);
1936out2:
1937 iput(inode);
1938out1:
1939 fput(vcpu->kvm->filp);
1940 return r;
1941}
1942
1943/*
1944 * Creates some virtual cpus. Good luck creating more than one.
1945 */
1946static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, int n)
1947{
1948 int r;
1949 struct kvm_vcpu *vcpu;
1950
1951 r = -EINVAL;
1952 if (!valid_vcpu(n))
1953 goto out;
1954
1955 vcpu = &kvm->vcpus[n];
1956
1957 mutex_lock(&vcpu->mutex);
1958
1959 if (vcpu->vmcs) {
1960 mutex_unlock(&vcpu->mutex);
1961 return -EEXIST;
1962 }
1963
1964 vcpu->host_fx_image = (char*)ALIGN((hva_t)vcpu->fx_buf,
1965 FX_IMAGE_ALIGN);
1966 vcpu->guest_fx_image = vcpu->host_fx_image + FX_IMAGE_SIZE;
1967
1968 r = kvm_arch_ops->vcpu_create(vcpu);
1969 if (r < 0)
1970 goto out_free_vcpus;
1971
1972 r = kvm_mmu_create(vcpu);
1973 if (r < 0)
1974 goto out_free_vcpus;
1975
1976 kvm_arch_ops->vcpu_load(vcpu);
1977 r = kvm_mmu_setup(vcpu);
1978 if (r >= 0)
1979 r = kvm_arch_ops->vcpu_setup(vcpu);
1980 vcpu_put(vcpu);
1981
1982 if (r < 0)
1983 goto out_free_vcpus;
1984
1985 r = create_vcpu_fd(vcpu);
1986 if (r < 0)
1987 goto out_free_vcpus;
1988
1989 return r;
1990
1991out_free_vcpus:
1992 kvm_free_vcpu(vcpu);
1993 mutex_unlock(&vcpu->mutex);
1994out:
1995 return r;
1996}
1997
1998static long kvm_vcpu_ioctl(struct file *filp,
1999 unsigned int ioctl, unsigned long arg)
2000{
2001 struct kvm_vcpu *vcpu = filp->private_data;
1797 void __user *argp = (void __user *)arg; 2002 void __user *argp = (void __user *)arg;
1798 int r = -EINVAL; 2003 int r = -EINVAL;
1799 2004
1800 switch (ioctl) { 2005 switch (ioctl) {
1801 case KVM_GET_API_VERSION:
1802 r = KVM_API_VERSION;
1803 break;
1804 case KVM_CREATE_VCPU: {
1805 r = kvm_dev_ioctl_create_vcpu(kvm, arg);
1806 if (r)
1807 goto out;
1808 break;
1809 }
1810 case KVM_RUN: { 2006 case KVM_RUN: {
1811 struct kvm_run kvm_run; 2007 struct kvm_run kvm_run;
1812 2008
1813 r = -EFAULT; 2009 r = -EFAULT;
1814 if (copy_from_user(&kvm_run, argp, sizeof kvm_run)) 2010 if (copy_from_user(&kvm_run, argp, sizeof kvm_run))
1815 goto out; 2011 goto out;
1816 r = kvm_dev_ioctl_run(kvm, &kvm_run); 2012 r = kvm_vcpu_ioctl_run(vcpu, &kvm_run);
1817 if (r < 0 && r != -EINTR) 2013 if (r < 0 && r != -EINTR)
1818 goto out; 2014 goto out;
1819 if (copy_to_user(argp, &kvm_run, sizeof kvm_run)) { 2015 if (copy_to_user(argp, &kvm_run, sizeof kvm_run)) {
@@ -1825,10 +2021,8 @@ static long kvm_dev_ioctl(struct file *filp,
1825 case KVM_GET_REGS: { 2021 case KVM_GET_REGS: {
1826 struct kvm_regs kvm_regs; 2022 struct kvm_regs kvm_regs;
1827 2023
1828 r = -EFAULT; 2024 memset(&kvm_regs, 0, sizeof kvm_regs);
1829 if (copy_from_user(&kvm_regs, argp, sizeof kvm_regs)) 2025 r = kvm_vcpu_ioctl_get_regs(vcpu, &kvm_regs);
1830 goto out;
1831 r = kvm_dev_ioctl_get_regs(kvm, &kvm_regs);
1832 if (r) 2026 if (r)
1833 goto out; 2027 goto out;
1834 r = -EFAULT; 2028 r = -EFAULT;
@@ -1843,7 +2037,7 @@ static long kvm_dev_ioctl(struct file *filp,
1843 r = -EFAULT; 2037 r = -EFAULT;
1844 if (copy_from_user(&kvm_regs, argp, sizeof kvm_regs)) 2038 if (copy_from_user(&kvm_regs, argp, sizeof kvm_regs))
1845 goto out; 2039 goto out;
1846 r = kvm_dev_ioctl_set_regs(kvm, &kvm_regs); 2040 r = kvm_vcpu_ioctl_set_regs(vcpu, &kvm_regs);
1847 if (r) 2041 if (r)
1848 goto out; 2042 goto out;
1849 r = 0; 2043 r = 0;
@@ -1852,10 +2046,8 @@ static long kvm_dev_ioctl(struct file *filp,
1852 case KVM_GET_SREGS: { 2046 case KVM_GET_SREGS: {
1853 struct kvm_sregs kvm_sregs; 2047 struct kvm_sregs kvm_sregs;
1854 2048
1855 r = -EFAULT; 2049 memset(&kvm_sregs, 0, sizeof kvm_sregs);
1856 if (copy_from_user(&kvm_sregs, argp, sizeof kvm_sregs)) 2050 r = kvm_vcpu_ioctl_get_sregs(vcpu, &kvm_sregs);
1857 goto out;
1858 r = kvm_dev_ioctl_get_sregs(kvm, &kvm_sregs);
1859 if (r) 2051 if (r)
1860 goto out; 2052 goto out;
1861 r = -EFAULT; 2053 r = -EFAULT;
@@ -1870,7 +2062,7 @@ static long kvm_dev_ioctl(struct file *filp,
1870 r = -EFAULT; 2062 r = -EFAULT;
1871 if (copy_from_user(&kvm_sregs, argp, sizeof kvm_sregs)) 2063 if (copy_from_user(&kvm_sregs, argp, sizeof kvm_sregs))
1872 goto out; 2064 goto out;
1873 r = kvm_dev_ioctl_set_sregs(kvm, &kvm_sregs); 2065 r = kvm_vcpu_ioctl_set_sregs(vcpu, &kvm_sregs);
1874 if (r) 2066 if (r)
1875 goto out; 2067 goto out;
1876 r = 0; 2068 r = 0;
@@ -1882,7 +2074,7 @@ static long kvm_dev_ioctl(struct file *filp,
1882 r = -EFAULT; 2074 r = -EFAULT;
1883 if (copy_from_user(&tr, argp, sizeof tr)) 2075 if (copy_from_user(&tr, argp, sizeof tr))
1884 goto out; 2076 goto out;
1885 r = kvm_dev_ioctl_translate(kvm, &tr); 2077 r = kvm_vcpu_ioctl_translate(vcpu, &tr);
1886 if (r) 2078 if (r)
1887 goto out; 2079 goto out;
1888 r = -EFAULT; 2080 r = -EFAULT;
@@ -1897,7 +2089,7 @@ static long kvm_dev_ioctl(struct file *filp,
1897 r = -EFAULT; 2089 r = -EFAULT;
1898 if (copy_from_user(&irq, argp, sizeof irq)) 2090 if (copy_from_user(&irq, argp, sizeof irq))
1899 goto out; 2091 goto out;
1900 r = kvm_dev_ioctl_interrupt(kvm, &irq); 2092 r = kvm_vcpu_ioctl_interrupt(vcpu, &irq);
1901 if (r) 2093 if (r)
1902 goto out; 2094 goto out;
1903 r = 0; 2095 r = 0;
@@ -1909,19 +2101,45 @@ static long kvm_dev_ioctl(struct file *filp,
1909 r = -EFAULT; 2101 r = -EFAULT;
1910 if (copy_from_user(&dbg, argp, sizeof dbg)) 2102 if (copy_from_user(&dbg, argp, sizeof dbg))
1911 goto out; 2103 goto out;
1912 r = kvm_dev_ioctl_debug_guest(kvm, &dbg); 2104 r = kvm_vcpu_ioctl_debug_guest(vcpu, &dbg);
1913 if (r) 2105 if (r)
1914 goto out; 2106 goto out;
1915 r = 0; 2107 r = 0;
1916 break; 2108 break;
1917 } 2109 }
2110 case KVM_GET_MSRS:
2111 r = msr_io(vcpu, argp, get_msr, 1);
2112 break;
2113 case KVM_SET_MSRS:
2114 r = msr_io(vcpu, argp, do_set_msr, 0);
2115 break;
2116 default:
2117 ;
2118 }
2119out:
2120 return r;
2121}
2122
2123static long kvm_vm_ioctl(struct file *filp,
2124 unsigned int ioctl, unsigned long arg)
2125{
2126 struct kvm *kvm = filp->private_data;
2127 void __user *argp = (void __user *)arg;
2128 int r = -EINVAL;
2129
2130 switch (ioctl) {
2131 case KVM_CREATE_VCPU:
2132 r = kvm_vm_ioctl_create_vcpu(kvm, arg);
2133 if (r < 0)
2134 goto out;
2135 break;
1918 case KVM_SET_MEMORY_REGION: { 2136 case KVM_SET_MEMORY_REGION: {
1919 struct kvm_memory_region kvm_mem; 2137 struct kvm_memory_region kvm_mem;
1920 2138
1921 r = -EFAULT; 2139 r = -EFAULT;
1922 if (copy_from_user(&kvm_mem, argp, sizeof kvm_mem)) 2140 if (copy_from_user(&kvm_mem, argp, sizeof kvm_mem))
1923 goto out; 2141 goto out;
1924 r = kvm_dev_ioctl_set_memory_region(kvm, &kvm_mem); 2142 r = kvm_vm_ioctl_set_memory_region(kvm, &kvm_mem);
1925 if (r) 2143 if (r)
1926 goto out; 2144 goto out;
1927 break; 2145 break;
@@ -1932,16 +2150,112 @@ static long kvm_dev_ioctl(struct file *filp,
1932 r = -EFAULT; 2150 r = -EFAULT;
1933 if (copy_from_user(&log, argp, sizeof log)) 2151 if (copy_from_user(&log, argp, sizeof log))
1934 goto out; 2152 goto out;
1935 r = kvm_dev_ioctl_get_dirty_log(kvm, &log); 2153 r = kvm_vm_ioctl_get_dirty_log(kvm, &log);
1936 if (r) 2154 if (r)
1937 goto out; 2155 goto out;
1938 break; 2156 break;
1939 } 2157 }
1940 case KVM_GET_MSRS: 2158 default:
1941 r = msr_io(kvm, argp, get_msr, 1); 2159 ;
2160 }
2161out:
2162 return r;
2163}
2164
2165static struct page *kvm_vm_nopage(struct vm_area_struct *vma,
2166 unsigned long address,
2167 int *type)
2168{
2169 struct kvm *kvm = vma->vm_file->private_data;
2170 unsigned long pgoff;
2171 struct kvm_memory_slot *slot;
2172 struct page *page;
2173
2174 *type = VM_FAULT_MINOR;
2175 pgoff = ((address - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
2176 slot = gfn_to_memslot(kvm, pgoff);
2177 if (!slot)
2178 return NOPAGE_SIGBUS;
2179 page = gfn_to_page(slot, pgoff);
2180 if (!page)
2181 return NOPAGE_SIGBUS;
2182 get_page(page);
2183 return page;
2184}
2185
2186static struct vm_operations_struct kvm_vm_vm_ops = {
2187 .nopage = kvm_vm_nopage,
2188};
2189
2190static int kvm_vm_mmap(struct file *file, struct vm_area_struct *vma)
2191{
2192 vma->vm_ops = &kvm_vm_vm_ops;
2193 return 0;
2194}
2195
2196static struct file_operations kvm_vm_fops = {
2197 .release = kvm_vm_release,
2198 .unlocked_ioctl = kvm_vm_ioctl,
2199 .compat_ioctl = kvm_vm_ioctl,
2200 .mmap = kvm_vm_mmap,
2201};
2202
2203static int kvm_dev_ioctl_create_vm(void)
2204{
2205 int fd, r;
2206 struct inode *inode;
2207 struct file *file;
2208 struct kvm *kvm;
2209
2210 inode = kvmfs_inode(&kvm_vm_fops);
2211 if (IS_ERR(inode)) {
2212 r = PTR_ERR(inode);
2213 goto out1;
2214 }
2215
2216 kvm = kvm_create_vm();
2217 if (IS_ERR(kvm)) {
2218 r = PTR_ERR(kvm);
2219 goto out2;
2220 }
2221
2222 file = kvmfs_file(inode, kvm);
2223 if (IS_ERR(file)) {
2224 r = PTR_ERR(file);
2225 goto out3;
2226 }
2227 kvm->filp = file;
2228
2229 r = get_unused_fd();
2230 if (r < 0)
2231 goto out4;
2232 fd = r;
2233 fd_install(fd, file);
2234
2235 return fd;
2236
2237out4:
2238 fput(file);
2239out3:
2240 kvm_destroy_vm(kvm);
2241out2:
2242 iput(inode);
2243out1:
2244 return r;
2245}
2246
2247static long kvm_dev_ioctl(struct file *filp,
2248 unsigned int ioctl, unsigned long arg)
2249{
2250 void __user *argp = (void __user *)arg;
2251 int r = -EINVAL;
2252
2253 switch (ioctl) {
2254 case KVM_GET_API_VERSION:
2255 r = KVM_API_VERSION;
1942 break; 2256 break;
1943 case KVM_SET_MSRS: 2257 case KVM_CREATE_VM:
1944 r = msr_io(kvm, argp, do_set_msr, 0); 2258 r = kvm_dev_ioctl_create_vm();
1945 break; 2259 break;
1946 case KVM_GET_MSR_INDEX_LIST: { 2260 case KVM_GET_MSR_INDEX_LIST: {
1947 struct kvm_msr_list __user *user_msr_list = argp; 2261 struct kvm_msr_list __user *user_msr_list = argp;
@@ -1977,43 +2291,11 @@ out:
1977 return r; 2291 return r;
1978} 2292}
1979 2293
1980static struct page *kvm_dev_nopage(struct vm_area_struct *vma,
1981 unsigned long address,
1982 int *type)
1983{
1984 struct kvm *kvm = vma->vm_file->private_data;
1985 unsigned long pgoff;
1986 struct kvm_memory_slot *slot;
1987 struct page *page;
1988
1989 *type = VM_FAULT_MINOR;
1990 pgoff = ((address - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
1991 slot = gfn_to_memslot(kvm, pgoff);
1992 if (!slot)
1993 return NOPAGE_SIGBUS;
1994 page = gfn_to_page(slot, pgoff);
1995 if (!page)
1996 return NOPAGE_SIGBUS;
1997 get_page(page);
1998 return page;
1999}
2000
2001static struct vm_operations_struct kvm_dev_vm_ops = {
2002 .nopage = kvm_dev_nopage,
2003};
2004
2005static int kvm_dev_mmap(struct file *file, struct vm_area_struct *vma)
2006{
2007 vma->vm_ops = &kvm_dev_vm_ops;
2008 return 0;
2009}
2010
2011static struct file_operations kvm_chardev_ops = { 2294static struct file_operations kvm_chardev_ops = {
2012 .open = kvm_dev_open, 2295 .open = kvm_dev_open,
2013 .release = kvm_dev_release, 2296 .release = kvm_dev_release,
2014 .unlocked_ioctl = kvm_dev_ioctl, 2297 .unlocked_ioctl = kvm_dev_ioctl,
2015 .compat_ioctl = kvm_dev_ioctl, 2298 .compat_ioctl = kvm_dev_ioctl,
2016 .mmap = kvm_dev_mmap,
2017}; 2299};
2018 2300
2019static struct miscdevice kvm_dev = { 2301static struct miscdevice kvm_dev = {
@@ -2080,13 +2362,17 @@ static int kvm_cpu_hotplug(struct notifier_block *notifier, unsigned long val,
2080 int cpu = (long)v; 2362 int cpu = (long)v;
2081 2363
2082 switch (val) { 2364 switch (val) {
2083 case CPU_DEAD: 2365 case CPU_DOWN_PREPARE:
2084 case CPU_UP_CANCELED: 2366 case CPU_UP_CANCELED:
2367 printk(KERN_INFO "kvm: disabling virtualization on CPU%d\n",
2368 cpu);
2085 decache_vcpus_on_cpu(cpu); 2369 decache_vcpus_on_cpu(cpu);
2086 smp_call_function_single(cpu, kvm_arch_ops->hardware_disable, 2370 smp_call_function_single(cpu, kvm_arch_ops->hardware_disable,
2087 NULL, 0, 1); 2371 NULL, 0, 1);
2088 break; 2372 break;
2089 case CPU_UP_PREPARE: 2373 case CPU_ONLINE:
2374 printk(KERN_INFO "kvm: enabling virtualization on CPU%d\n",
2375 cpu);
2090 smp_call_function_single(cpu, kvm_arch_ops->hardware_enable, 2376 smp_call_function_single(cpu, kvm_arch_ops->hardware_enable,
2091 NULL, 0, 1); 2377 NULL, 0, 1);
2092 break; 2378 break;
@@ -2121,13 +2407,13 @@ static void kvm_exit_debug(void)
2121static int kvm_suspend(struct sys_device *dev, pm_message_t state) 2407static int kvm_suspend(struct sys_device *dev, pm_message_t state)
2122{ 2408{
2123 decache_vcpus_on_cpu(raw_smp_processor_id()); 2409 decache_vcpus_on_cpu(raw_smp_processor_id());
2124 on_each_cpu(kvm_arch_ops->hardware_disable, 0, 0, 1); 2410 on_each_cpu(kvm_arch_ops->hardware_disable, NULL, 0, 1);
2125 return 0; 2411 return 0;
2126} 2412}
2127 2413
2128static int kvm_resume(struct sys_device *dev) 2414static int kvm_resume(struct sys_device *dev)
2129{ 2415{
2130 on_each_cpu(kvm_arch_ops->hardware_enable, 0, 0, 1); 2416 on_each_cpu(kvm_arch_ops->hardware_enable, NULL, 0, 1);
2131 return 0; 2417 return 0;
2132} 2418}
2133 2419
@@ -2144,6 +2430,18 @@ static struct sys_device kvm_sysdev = {
2144 2430
2145hpa_t bad_page_address; 2431hpa_t bad_page_address;
2146 2432
2433static int kvmfs_get_sb(struct file_system_type *fs_type, int flags,
2434 const char *dev_name, void *data, struct vfsmount *mnt)
2435{
2436 return get_sb_pseudo(fs_type, "kvm:", NULL, KVMFS_SUPER_MAGIC, mnt);
2437}
2438
2439static struct file_system_type kvm_fs_type = {
2440 .name = "kvmfs",
2441 .get_sb = kvmfs_get_sb,
2442 .kill_sb = kill_anon_super,
2443};
2444
2147int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module) 2445int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module)
2148{ 2446{
2149 int r; 2447 int r;
@@ -2220,8 +2518,16 @@ void kvm_exit_arch(void)
2220static __init int kvm_init(void) 2518static __init int kvm_init(void)
2221{ 2519{
2222 static struct page *bad_page; 2520 static struct page *bad_page;
2223 int r = 0; 2521 int r;
2522
2523 r = register_filesystem(&kvm_fs_type);
2524 if (r)
2525 goto out3;
2224 2526
2527 kvmfs_mnt = kern_mount(&kvm_fs_type);
2528 r = PTR_ERR(kvmfs_mnt);
2529 if (IS_ERR(kvmfs_mnt))
2530 goto out2;
2225 kvm_init_debug(); 2531 kvm_init_debug();
2226 2532
2227 kvm_init_msr_list(); 2533 kvm_init_msr_list();
@@ -2234,10 +2540,14 @@ static __init int kvm_init(void)
2234 bad_page_address = page_to_pfn(bad_page) << PAGE_SHIFT; 2540 bad_page_address = page_to_pfn(bad_page) << PAGE_SHIFT;
2235 memset(__va(bad_page_address), 0, PAGE_SIZE); 2541 memset(__va(bad_page_address), 0, PAGE_SIZE);
2236 2542
2237 return r; 2543 return 0;
2238 2544
2239out: 2545out:
2240 kvm_exit_debug(); 2546 kvm_exit_debug();
2547 mntput(kvmfs_mnt);
2548out2:
2549 unregister_filesystem(&kvm_fs_type);
2550out3:
2241 return r; 2551 return r;
2242} 2552}
2243 2553
@@ -2245,6 +2555,8 @@ static __exit void kvm_exit(void)
2245{ 2555{
2246 kvm_exit_debug(); 2556 kvm_exit_debug();
2247 __free_page(pfn_to_page(bad_page_address >> PAGE_SHIFT)); 2557 __free_page(pfn_to_page(bad_page_address >> PAGE_SHIFT));
2558 mntput(kvmfs_mnt);
2559 unregister_filesystem(&kvm_fs_type);
2248} 2560}
2249 2561
2250module_init(kvm_init) 2562module_init(kvm_init)
diff --git a/drivers/kvm/kvm_svm.h b/drivers/kvm/kvm_svm.h
index 74cc862f49..624f1ca486 100644
--- a/drivers/kvm/kvm_svm.h
+++ b/drivers/kvm/kvm_svm.h
@@ -1,6 +1,7 @@
1#ifndef __KVM_SVM_H 1#ifndef __KVM_SVM_H
2#define __KVM_SVM_H 2#define __KVM_SVM_H
3 3
4#include <linux/kernel.h>
4#include <linux/types.h> 5#include <linux/types.h>
5#include <linux/list.h> 6#include <linux/list.h>
6#include <asm/msr.h> 7#include <asm/msr.h>
@@ -18,7 +19,7 @@ static const u32 host_save_msrs[] = {
18 MSR_IA32_LASTBRANCHTOIP, MSR_IA32_LASTINTFROMIP,MSR_IA32_LASTINTTOIP,*/ 19 MSR_IA32_LASTBRANCHTOIP, MSR_IA32_LASTINTFROMIP,MSR_IA32_LASTINTTOIP,*/
19}; 20};
20 21
21#define NR_HOST_SAVE_MSRS (sizeof(host_save_msrs) / sizeof(*host_save_msrs)) 22#define NR_HOST_SAVE_MSRS ARRAY_SIZE(host_save_msrs)
22#define NUM_DB_REGS 4 23#define NUM_DB_REGS 4
23 24
24struct vcpu_svm { 25struct vcpu_svm {
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index be793770f3..a1a93368f3 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -298,18 +298,18 @@ static void rmap_add(struct kvm_vcpu *vcpu, u64 *spte)
298 if (!is_rmap_pte(*spte)) 298 if (!is_rmap_pte(*spte))
299 return; 299 return;
300 page = pfn_to_page((*spte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT); 300 page = pfn_to_page((*spte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT);
301 if (!page->private) { 301 if (!page_private(page)) {
302 rmap_printk("rmap_add: %p %llx 0->1\n", spte, *spte); 302 rmap_printk("rmap_add: %p %llx 0->1\n", spte, *spte);
303 page->private = (unsigned long)spte; 303 set_page_private(page,(unsigned long)spte);
304 } else if (!(page->private & 1)) { 304 } else if (!(page_private(page) & 1)) {
305 rmap_printk("rmap_add: %p %llx 1->many\n", spte, *spte); 305 rmap_printk("rmap_add: %p %llx 1->many\n", spte, *spte);
306 desc = mmu_alloc_rmap_desc(vcpu); 306 desc = mmu_alloc_rmap_desc(vcpu);
307 desc->shadow_ptes[0] = (u64 *)page->private; 307 desc->shadow_ptes[0] = (u64 *)page_private(page);
308 desc->shadow_ptes[1] = spte; 308 desc->shadow_ptes[1] = spte;
309 page->private = (unsigned long)desc | 1; 309 set_page_private(page,(unsigned long)desc | 1);
310 } else { 310 } else {
311 rmap_printk("rmap_add: %p %llx many->many\n", spte, *spte); 311 rmap_printk("rmap_add: %p %llx many->many\n", spte, *spte);
312 desc = (struct kvm_rmap_desc *)(page->private & ~1ul); 312 desc = (struct kvm_rmap_desc *)(page_private(page) & ~1ul);
313 while (desc->shadow_ptes[RMAP_EXT-1] && desc->more) 313 while (desc->shadow_ptes[RMAP_EXT-1] && desc->more)
314 desc = desc->more; 314 desc = desc->more;
315 if (desc->shadow_ptes[RMAP_EXT-1]) { 315 if (desc->shadow_ptes[RMAP_EXT-1]) {
@@ -337,12 +337,12 @@ static void rmap_desc_remove_entry(struct kvm_vcpu *vcpu,
337 if (j != 0) 337 if (j != 0)
338 return; 338 return;
339 if (!prev_desc && !desc->more) 339 if (!prev_desc && !desc->more)
340 page->private = (unsigned long)desc->shadow_ptes[0]; 340 set_page_private(page,(unsigned long)desc->shadow_ptes[0]);
341 else 341 else
342 if (prev_desc) 342 if (prev_desc)
343 prev_desc->more = desc->more; 343 prev_desc->more = desc->more;
344 else 344 else
345 page->private = (unsigned long)desc->more | 1; 345 set_page_private(page,(unsigned long)desc->more | 1);
346 mmu_free_rmap_desc(vcpu, desc); 346 mmu_free_rmap_desc(vcpu, desc);
347} 347}
348 348
@@ -356,20 +356,20 @@ static void rmap_remove(struct kvm_vcpu *vcpu, u64 *spte)
356 if (!is_rmap_pte(*spte)) 356 if (!is_rmap_pte(*spte))
357 return; 357 return;
358 page = pfn_to_page((*spte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT); 358 page = pfn_to_page((*spte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT);
359 if (!page->private) { 359 if (!page_private(page)) {
360 printk(KERN_ERR "rmap_remove: %p %llx 0->BUG\n", spte, *spte); 360 printk(KERN_ERR "rmap_remove: %p %llx 0->BUG\n", spte, *spte);
361 BUG(); 361 BUG();
362 } else if (!(page->private & 1)) { 362 } else if (!(page_private(page) & 1)) {
363 rmap_printk("rmap_remove: %p %llx 1->0\n", spte, *spte); 363 rmap_printk("rmap_remove: %p %llx 1->0\n", spte, *spte);
364 if ((u64 *)page->private != spte) { 364 if ((u64 *)page_private(page) != spte) {
365 printk(KERN_ERR "rmap_remove: %p %llx 1->BUG\n", 365 printk(KERN_ERR "rmap_remove: %p %llx 1->BUG\n",
366 spte, *spte); 366 spte, *spte);
367 BUG(); 367 BUG();
368 } 368 }
369 page->private = 0; 369 set_page_private(page,0);
370 } else { 370 } else {
371 rmap_printk("rmap_remove: %p %llx many->many\n", spte, *spte); 371 rmap_printk("rmap_remove: %p %llx many->many\n", spte, *spte);
372 desc = (struct kvm_rmap_desc *)(page->private & ~1ul); 372 desc = (struct kvm_rmap_desc *)(page_private(page) & ~1ul);
373 prev_desc = NULL; 373 prev_desc = NULL;
374 while (desc) { 374 while (desc) {
375 for (i = 0; i < RMAP_EXT && desc->shadow_ptes[i]; ++i) 375 for (i = 0; i < RMAP_EXT && desc->shadow_ptes[i]; ++i)
@@ -398,11 +398,11 @@ static void rmap_write_protect(struct kvm_vcpu *vcpu, u64 gfn)
398 BUG_ON(!slot); 398 BUG_ON(!slot);
399 page = gfn_to_page(slot, gfn); 399 page = gfn_to_page(slot, gfn);
400 400
401 while (page->private) { 401 while (page_private(page)) {
402 if (!(page->private & 1)) 402 if (!(page_private(page) & 1))
403 spte = (u64 *)page->private; 403 spte = (u64 *)page_private(page);
404 else { 404 else {
405 desc = (struct kvm_rmap_desc *)(page->private & ~1ul); 405 desc = (struct kvm_rmap_desc *)(page_private(page) & ~1ul);
406 spte = desc->shadow_ptes[0]; 406 spte = desc->shadow_ptes[0];
407 } 407 }
408 BUG_ON(!spte); 408 BUG_ON(!spte);
@@ -1218,7 +1218,7 @@ static int alloc_mmu_pages(struct kvm_vcpu *vcpu)
1218 INIT_LIST_HEAD(&page_header->link); 1218 INIT_LIST_HEAD(&page_header->link);
1219 if ((page = alloc_page(GFP_KERNEL)) == NULL) 1219 if ((page = alloc_page(GFP_KERNEL)) == NULL)
1220 goto error_1; 1220 goto error_1;
1221 page->private = (unsigned long)page_header; 1221 set_page_private(page, (unsigned long)page_header);
1222 page_header->page_hpa = (hpa_t)page_to_pfn(page) << PAGE_SHIFT; 1222 page_header->page_hpa = (hpa_t)page_to_pfn(page) << PAGE_SHIFT;
1223 memset(__va(page_header->page_hpa), 0, PAGE_SIZE); 1223 memset(__va(page_header->page_hpa), 0, PAGE_SIZE);
1224 list_add(&page_header->link, &vcpu->free_pages); 1224 list_add(&page_header->link, &vcpu->free_pages);
diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index b6b90e9e13..f3bcee9046 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -128,8 +128,10 @@ static int FNAME(walk_addr)(struct guest_walker *walker,
128 goto access_error; 128 goto access_error;
129#endif 129#endif
130 130
131 if (!(*ptep & PT_ACCESSED_MASK)) 131 if (!(*ptep & PT_ACCESSED_MASK)) {
132 *ptep |= PT_ACCESSED_MASK; /* avoid rmw */ 132 mark_page_dirty(vcpu->kvm, table_gfn);
133 *ptep |= PT_ACCESSED_MASK;
134 }
133 135
134 if (walker->level == PT_PAGE_TABLE_LEVEL) { 136 if (walker->level == PT_PAGE_TABLE_LEVEL) {
135 walker->gfn = (*ptep & PT_BASE_ADDR_MASK) 137 walker->gfn = (*ptep & PT_BASE_ADDR_MASK)
@@ -185,6 +187,12 @@ static void FNAME(release_walker)(struct guest_walker *walker)
185 kunmap_atomic(walker->table, KM_USER0); 187 kunmap_atomic(walker->table, KM_USER0);
186} 188}
187 189
190static void FNAME(mark_pagetable_dirty)(struct kvm *kvm,
191 struct guest_walker *walker)
192{
193 mark_page_dirty(kvm, walker->table_gfn[walker->level - 1]);
194}
195
188static void FNAME(set_pte)(struct kvm_vcpu *vcpu, u64 guest_pte, 196static void FNAME(set_pte)(struct kvm_vcpu *vcpu, u64 guest_pte,
189 u64 *shadow_pte, u64 access_bits, gfn_t gfn) 197 u64 *shadow_pte, u64 access_bits, gfn_t gfn)
190{ 198{
@@ -348,12 +356,15 @@ static int FNAME(fix_write_pf)(struct kvm_vcpu *vcpu,
348 } else if (kvm_mmu_lookup_page(vcpu, gfn)) { 356 } else if (kvm_mmu_lookup_page(vcpu, gfn)) {
349 pgprintk("%s: found shadow page for %lx, marking ro\n", 357 pgprintk("%s: found shadow page for %lx, marking ro\n",
350 __FUNCTION__, gfn); 358 __FUNCTION__, gfn);
359 mark_page_dirty(vcpu->kvm, gfn);
360 FNAME(mark_pagetable_dirty)(vcpu->kvm, walker);
351 *guest_ent |= PT_DIRTY_MASK; 361 *guest_ent |= PT_DIRTY_MASK;
352 *write_pt = 1; 362 *write_pt = 1;
353 return 0; 363 return 0;
354 } 364 }
355 mark_page_dirty(vcpu->kvm, gfn); 365 mark_page_dirty(vcpu->kvm, gfn);
356 *shadow_ent |= PT_WRITABLE_MASK; 366 *shadow_ent |= PT_WRITABLE_MASK;
367 FNAME(mark_pagetable_dirty)(vcpu->kvm, walker);
357 *guest_ent |= PT_DIRTY_MASK; 368 *guest_ent |= PT_DIRTY_MASK;
358 rmap_add(vcpu, shadow_ent); 369 rmap_add(vcpu, shadow_ent);
359 370
@@ -430,9 +441,8 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
430 /* 441 /*
431 * mmio: emulate if accessible, otherwise its a guest fault. 442 * mmio: emulate if accessible, otherwise its a guest fault.
432 */ 443 */
433 if (is_io_pte(*shadow_pte)) { 444 if (is_io_pte(*shadow_pte))
434 return 1; 445 return 1;
435 }
436 446
437 ++kvm_stat.pf_fixed; 447 ++kvm_stat.pf_fixed;
438 kvm_mmu_audit(vcpu, "post page fault (fixed)"); 448 kvm_mmu_audit(vcpu, "post page fault (fixed)");
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 83da4ea150..3d8ea7ac2e 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -15,6 +15,7 @@
15 */ 15 */
16 16
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/kernel.h>
18#include <linux/vmalloc.h> 19#include <linux/vmalloc.h>
19#include <linux/highmem.h> 20#include <linux/highmem.h>
20#include <linux/profile.h> 21#include <linux/profile.h>
@@ -75,7 +76,7 @@ struct svm_init_data {
75 76
76static u32 msrpm_ranges[] = {0, 0xc0000000, 0xc0010000}; 77static u32 msrpm_ranges[] = {0, 0xc0000000, 0xc0010000};
77 78
78#define NUM_MSR_MAPS (sizeof(msrpm_ranges) / sizeof(*msrpm_ranges)) 79#define NUM_MSR_MAPS ARRAY_SIZE(msrpm_ranges)
79#define MSRS_RANGE_SIZE 2048 80#define MSRS_RANGE_SIZE 2048
80#define MSRS_IN_RANGE (MSRS_RANGE_SIZE * 8 / 2) 81#define MSRS_IN_RANGE (MSRS_RANGE_SIZE * 8 / 2)
81 82
@@ -485,6 +486,7 @@ static void init_vmcb(struct vmcb *vmcb)
485 486
486 control->intercept = (1ULL << INTERCEPT_INTR) | 487 control->intercept = (1ULL << INTERCEPT_INTR) |
487 (1ULL << INTERCEPT_NMI) | 488 (1ULL << INTERCEPT_NMI) |
489 (1ULL << INTERCEPT_SMI) |
488 /* 490 /*
489 * selective cr0 intercept bug? 491 * selective cr0 intercept bug?
490 * 0: 0f 22 d8 mov %eax,%cr3 492 * 0: 0f 22 d8 mov %eax,%cr3
@@ -553,7 +555,7 @@ static void init_vmcb(struct vmcb *vmcb)
553 * cr0 val on cpu init should be 0x60000010, we enable cpu 555 * cr0 val on cpu init should be 0x60000010, we enable cpu
554 * cache by default. the orderly way is to enable cache in bios. 556 * cache by default. the orderly way is to enable cache in bios.
555 */ 557 */
556 save->cr0 = 0x00000010 | CR0_PG_MASK; 558 save->cr0 = 0x00000010 | CR0_PG_MASK | CR0_WP_MASK;
557 save->cr4 = CR4_PAE_MASK; 559 save->cr4 = CR4_PAE_MASK;
558 /* rdx = ?? */ 560 /* rdx = ?? */
559} 561}
@@ -598,10 +600,9 @@ static void svm_free_vcpu(struct kvm_vcpu *vcpu)
598 kfree(vcpu->svm); 600 kfree(vcpu->svm);
599} 601}
600 602
601static struct kvm_vcpu *svm_vcpu_load(struct kvm_vcpu *vcpu) 603static void svm_vcpu_load(struct kvm_vcpu *vcpu)
602{ 604{
603 get_cpu(); 605 get_cpu();
604 return vcpu;
605} 606}
606 607
607static void svm_vcpu_put(struct kvm_vcpu *vcpu) 608static void svm_vcpu_put(struct kvm_vcpu *vcpu)
@@ -1042,22 +1043,22 @@ static int io_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1042 1043
1043 addr_mask = io_adress(vcpu, _in, &kvm_run->io.address); 1044 addr_mask = io_adress(vcpu, _in, &kvm_run->io.address);
1044 if (!addr_mask) { 1045 if (!addr_mask) {
1045 printk(KERN_DEBUG "%s: get io address failed\n", __FUNCTION__); 1046 printk(KERN_DEBUG "%s: get io address failed\n",
1047 __FUNCTION__);
1046 return 1; 1048 return 1;
1047 } 1049 }
1048 1050
1049 if (kvm_run->io.rep) { 1051 if (kvm_run->io.rep) {
1050 kvm_run->io.count = vcpu->regs[VCPU_REGS_RCX] & addr_mask; 1052 kvm_run->io.count
1053 = vcpu->regs[VCPU_REGS_RCX] & addr_mask;
1051 kvm_run->io.string_down = (vcpu->svm->vmcb->save.rflags 1054 kvm_run->io.string_down = (vcpu->svm->vmcb->save.rflags
1052 & X86_EFLAGS_DF) != 0; 1055 & X86_EFLAGS_DF) != 0;
1053 } 1056 }
1054 } else { 1057 } else
1055 kvm_run->io.value = vcpu->svm->vmcb->save.rax; 1058 kvm_run->io.value = vcpu->svm->vmcb->save.rax;
1056 }
1057 return 0; 1059 return 0;
1058} 1060}
1059 1061
1060
1061static int nop_on_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 1062static int nop_on_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1062{ 1063{
1063 return 1; 1064 return 1;
@@ -1075,6 +1076,12 @@ static int halt_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1075 return 0; 1076 return 0;
1076} 1077}
1077 1078
1079static int vmmcall_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1080{
1081 vcpu->svm->vmcb->save.rip += 3;
1082 return kvm_hypercall(vcpu, kvm_run);
1083}
1084
1078static int invalid_op_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 1085static int invalid_op_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1079{ 1086{
1080 inject_ud(vcpu); 1087 inject_ud(vcpu);
@@ -1275,7 +1282,7 @@ static int (*svm_exit_handlers[])(struct kvm_vcpu *vcpu,
1275 [SVM_EXIT_TASK_SWITCH] = task_switch_interception, 1282 [SVM_EXIT_TASK_SWITCH] = task_switch_interception,
1276 [SVM_EXIT_SHUTDOWN] = shutdown_interception, 1283 [SVM_EXIT_SHUTDOWN] = shutdown_interception,
1277 [SVM_EXIT_VMRUN] = invalid_op_interception, 1284 [SVM_EXIT_VMRUN] = invalid_op_interception,
1278 [SVM_EXIT_VMMCALL] = invalid_op_interception, 1285 [SVM_EXIT_VMMCALL] = vmmcall_interception,
1279 [SVM_EXIT_VMLOAD] = invalid_op_interception, 1286 [SVM_EXIT_VMLOAD] = invalid_op_interception,
1280 [SVM_EXIT_VMSAVE] = invalid_op_interception, 1287 [SVM_EXIT_VMSAVE] = invalid_op_interception,
1281 [SVM_EXIT_STGI] = invalid_op_interception, 1288 [SVM_EXIT_STGI] = invalid_op_interception,
@@ -1297,7 +1304,7 @@ static int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1297 __FUNCTION__, vcpu->svm->vmcb->control.exit_int_info, 1304 __FUNCTION__, vcpu->svm->vmcb->control.exit_int_info,
1298 exit_code); 1305 exit_code);
1299 1306
1300 if (exit_code >= sizeof(svm_exit_handlers) / sizeof(*svm_exit_handlers) 1307 if (exit_code >= ARRAY_SIZE(svm_exit_handlers)
1301 || svm_exit_handlers[exit_code] == 0) { 1308 || svm_exit_handlers[exit_code] == 0) {
1302 kvm_run->exit_reason = KVM_EXIT_UNKNOWN; 1309 kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
1303 printk(KERN_ERR "%s: 0x%x @ 0x%llx cr0 0x%lx rflags 0x%llx\n", 1310 printk(KERN_ERR "%s: 0x%x @ 0x%llx cr0 0x%lx rflags 0x%llx\n",
@@ -1668,6 +1675,18 @@ static int is_disabled(void)
1668 return 0; 1675 return 0;
1669} 1676}
1670 1677
1678static void
1679svm_patch_hypercall(struct kvm_vcpu *vcpu, unsigned char *hypercall)
1680{
1681 /*
1682 * Patch in the VMMCALL instruction:
1683 */
1684 hypercall[0] = 0x0f;
1685 hypercall[1] = 0x01;
1686 hypercall[2] = 0xd9;
1687 hypercall[3] = 0xc3;
1688}
1689
1671static struct kvm_arch_ops svm_arch_ops = { 1690static struct kvm_arch_ops svm_arch_ops = {
1672 .cpu_has_kvm_support = has_svm, 1691 .cpu_has_kvm_support = has_svm,
1673 .disabled_by_bios = is_disabled, 1692 .disabled_by_bios = is_disabled,
@@ -1716,6 +1735,7 @@ static struct kvm_arch_ops svm_arch_ops = {
1716 .run = svm_vcpu_run, 1735 .run = svm_vcpu_run,
1717 .skip_emulated_instruction = skip_emulated_instruction, 1736 .skip_emulated_instruction = skip_emulated_instruction,
1718 .vcpu_setup = svm_vcpu_setup, 1737 .vcpu_setup = svm_vcpu_setup,
1738 .patch_hypercall = svm_patch_hypercall,
1719}; 1739};
1720 1740
1721static int __init svm_init(void) 1741static int __init svm_init(void)
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index fd4e917343..c07178e611 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -19,6 +19,7 @@
19#include "vmx.h" 19#include "vmx.h"
20#include "kvm_vmx.h" 20#include "kvm_vmx.h"
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/kernel.h>
22#include <linux/mm.h> 23#include <linux/mm.h>
23#include <linux/highmem.h> 24#include <linux/highmem.h>
24#include <linux/profile.h> 25#include <linux/profile.h>
@@ -27,7 +28,6 @@
27 28
28#include "segment_descriptor.h" 29#include "segment_descriptor.h"
29 30
30
31MODULE_AUTHOR("Qumranet"); 31MODULE_AUTHOR("Qumranet");
32MODULE_LICENSE("GPL"); 32MODULE_LICENSE("GPL");
33 33
@@ -76,7 +76,7 @@ static const u32 vmx_msr_index[] = {
76#endif 76#endif
77 MSR_EFER, MSR_K6_STAR, 77 MSR_EFER, MSR_K6_STAR,
78}; 78};
79#define NR_VMX_MSR (sizeof(vmx_msr_index) / sizeof(*vmx_msr_index)) 79#define NR_VMX_MSR ARRAY_SIZE(vmx_msr_index)
80 80
81static inline int is_page_fault(u32 intr_info) 81static inline int is_page_fault(u32 intr_info)
82{ 82{
@@ -204,7 +204,7 @@ static void vmcs_write64(unsigned long field, u64 value)
204 * Switches to specified vcpu, until a matching vcpu_put(), but assumes 204 * Switches to specified vcpu, until a matching vcpu_put(), but assumes
205 * vcpu mutex is already taken. 205 * vcpu mutex is already taken.
206 */ 206 */
207static struct kvm_vcpu *vmx_vcpu_load(struct kvm_vcpu *vcpu) 207static void vmx_vcpu_load(struct kvm_vcpu *vcpu)
208{ 208{
209 u64 phys_addr = __pa(vcpu->vmcs); 209 u64 phys_addr = __pa(vcpu->vmcs);
210 int cpu; 210 int cpu;
@@ -242,7 +242,6 @@ static struct kvm_vcpu *vmx_vcpu_load(struct kvm_vcpu *vcpu)
242 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp); 242 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
243 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */ 243 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
244 } 244 }
245 return vcpu;
246} 245}
247 246
248static void vmx_vcpu_put(struct kvm_vcpu *vcpu) 247static void vmx_vcpu_put(struct kvm_vcpu *vcpu)
@@ -418,10 +417,9 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data)
418 case MSR_IA32_SYSENTER_ESP: 417 case MSR_IA32_SYSENTER_ESP:
419 vmcs_write32(GUEST_SYSENTER_ESP, data); 418 vmcs_write32(GUEST_SYSENTER_ESP, data);
420 break; 419 break;
421 case MSR_IA32_TIME_STAMP_COUNTER: { 420 case MSR_IA32_TIME_STAMP_COUNTER:
422 guest_write_tsc(data); 421 guest_write_tsc(data);
423 break; 422 break;
424 }
425 default: 423 default:
426 msr = find_msr_entry(vcpu, msr_index); 424 msr = find_msr_entry(vcpu, msr_index);
427 if (msr) { 425 if (msr) {
@@ -793,6 +791,9 @@ static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
793 */ 791 */
794static void vmx_set_cr0_no_modeswitch(struct kvm_vcpu *vcpu, unsigned long cr0) 792static void vmx_set_cr0_no_modeswitch(struct kvm_vcpu *vcpu, unsigned long cr0)
795{ 793{
794 if (!vcpu->rmode.active && !(cr0 & CR0_PE_MASK))
795 enter_rmode(vcpu);
796
796 vcpu->rmode.active = ((cr0 & CR0_PE_MASK) == 0); 797 vcpu->rmode.active = ((cr0 & CR0_PE_MASK) == 0);
797 update_exception_bitmap(vcpu); 798 update_exception_bitmap(vcpu);
798 vmcs_writel(CR0_READ_SHADOW, cr0); 799 vmcs_writel(CR0_READ_SHADOW, cr0);
@@ -1467,6 +1468,18 @@ static int handle_io(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1467 return 0; 1468 return 0;
1468} 1469}
1469 1470
1471static void
1472vmx_patch_hypercall(struct kvm_vcpu *vcpu, unsigned char *hypercall)
1473{
1474 /*
1475 * Patch in the VMCALL instruction:
1476 */
1477 hypercall[0] = 0x0f;
1478 hypercall[1] = 0x01;
1479 hypercall[2] = 0xc1;
1480 hypercall[3] = 0xc3;
1481}
1482
1470static int handle_cr(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 1483static int handle_cr(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1471{ 1484{
1472 u64 exit_qualification; 1485 u64 exit_qualification;
@@ -1643,6 +1656,12 @@ static int handle_halt(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1643 return 0; 1656 return 0;
1644} 1657}
1645 1658
1659static int handle_vmcall(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1660{
1661 vmcs_writel(GUEST_RIP, vmcs_readl(GUEST_RIP)+3);
1662 return kvm_hypercall(vcpu, kvm_run);
1663}
1664
1646/* 1665/*
1647 * The exit handlers return 1 if the exit was handled fully and guest execution 1666 * The exit handlers return 1 if the exit was handled fully and guest execution
1648 * may resume. Otherwise they set the kvm_run parameter to indicate what needs 1667 * may resume. Otherwise they set the kvm_run parameter to indicate what needs
@@ -1661,6 +1680,7 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu,
1661 [EXIT_REASON_MSR_WRITE] = handle_wrmsr, 1680 [EXIT_REASON_MSR_WRITE] = handle_wrmsr,
1662 [EXIT_REASON_PENDING_INTERRUPT] = handle_interrupt_window, 1681 [EXIT_REASON_PENDING_INTERRUPT] = handle_interrupt_window,
1663 [EXIT_REASON_HLT] = handle_halt, 1682 [EXIT_REASON_HLT] = handle_halt,
1683 [EXIT_REASON_VMCALL] = handle_vmcall,
1664}; 1684};
1665 1685
1666static const int kvm_vmx_max_exit_handlers = 1686static const int kvm_vmx_max_exit_handlers =
@@ -2062,6 +2082,7 @@ static struct kvm_arch_ops vmx_arch_ops = {
2062 .run = vmx_vcpu_run, 2082 .run = vmx_vcpu_run,
2063 .skip_emulated_instruction = skip_emulated_instruction, 2083 .skip_emulated_instruction = skip_emulated_instruction,
2064 .vcpu_setup = vmx_vcpu_setup, 2084 .vcpu_setup = vmx_vcpu_setup,
2085 .patch_hypercall = vmx_patch_hypercall,
2065}; 2086};
2066 2087
2067static int __init vmx_init(void) 2088static int __init vmx_init(void)
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 7399ba7911..80acd08f0e 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -82,6 +82,18 @@ config LEDS_WRAP
82 help 82 help
83 This option enables support for the PCEngines WRAP programmable LEDs. 83 This option enables support for the PCEngines WRAP programmable LEDs.
84 84
85config LEDS_H1940
86 tristate "LED Support for iPAQ H1940 device"
87 depends LEDS_CLASS && ARCH_H1940
88 help
89 This option enables support for the LEDs on the h1940.
90
91config LEDS_COBALT
92 tristate "LED Support for Cobalt Server front LED"
93 depends on LEDS_CLASS && MIPS_COBALT
94 help
95 This option enables support for the front LED on Cobalt Server
96
85comment "LED Triggers" 97comment "LED Triggers"
86 98
87config LEDS_TRIGGERS 99config LEDS_TRIGGERS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 500de3dc96..aa2c18efa5 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -14,6 +14,8 @@ obj-$(CONFIG_LEDS_S3C24XX) += leds-s3c24xx.o
14obj-$(CONFIG_LEDS_AMS_DELTA) += leds-ams-delta.o 14obj-$(CONFIG_LEDS_AMS_DELTA) += leds-ams-delta.o
15obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o 15obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o
16obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o 16obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o
17obj-$(CONFIG_LEDS_H1940) += leds-h1940.o
18obj-$(CONFIG_LEDS_COBALT) += leds-cobalt.o
17 19
18# LED Triggers 20# LED Triggers
19obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o 21obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
diff --git a/drivers/leds/leds-cobalt.c b/drivers/leds/leds-cobalt.c
new file mode 100644
index 0000000000..d16439ce5d
--- /dev/null
+++ b/drivers/leds/leds-cobalt.c
@@ -0,0 +1,43 @@
1/*
2 * Copyright 2006 - Florian Fainelli <florian@openwrt.org>
3 *
4 * Control the Cobalt Qube/RaQ front LED
5 */
6
7#include <linux/module.h>
8#include <linux/types.h>
9#include <linux/kernel.h>
10#include <linux/device.h>
11#include <linux/leds.h>
12#include <asm/mach-cobalt/cobalt.h>
13
14static void cobalt_led_set(struct led_classdev *led_cdev, enum led_brightness brightness)
15{
16 if (brightness)
17 COBALT_LED_PORT = COBALT_LED_BAR_LEFT | COBALT_LED_BAR_RIGHT;
18 else
19 COBALT_LED_PORT = 0;
20}
21
22static struct led_classdev cobalt_led = {
23 .name = "cobalt-front-led",
24 .brightness_set = cobalt_led_set,
25 .default_trigger = "ide-disk",
26};
27
28static int __init cobalt_led_init(void)
29{
30 return led_classdev_register(NULL, &cobalt_led);
31}
32
33static void __exit cobalt_led_exit(void)
34{
35 led_classdev_unregister(&cobalt_led);
36}
37
38module_init(cobalt_led_init);
39module_exit(cobalt_led_exit);
40
41MODULE_LICENSE("GPL");
42MODULE_DESCRIPTION("Front LED support for Cobalt Server");
43MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
diff --git a/drivers/leds/leds-h1940.c b/drivers/leds/leds-h1940.c
new file mode 100644
index 0000000000..1d49d2ade5
--- /dev/null
+++ b/drivers/leds/leds-h1940.c
@@ -0,0 +1,163 @@
1/*
2 * drivers/leds/h1940-leds.c
3 * Copyright (c) Arnaud Patard <arnaud.patard@rtp-net.org>
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file COPYING in the main directory of this archive for
7 * more details.
8 *
9 * H1940 leds driver
10 *
11 */
12
13#include <linux/module.h>
14#include <linux/platform_device.h>
15#include <linux/delay.h>
16#include <linux/string.h>
17#include <linux/ctype.h>
18#include <linux/leds.h>
19#include <asm/arch/regs-gpio.h>
20#include <asm/hardware.h>
21#include <asm/arch/h1940-latch.h>
22
23/*
24 * Green led.
25 */
26void h1940_greenled_set(struct led_classdev *led_dev, enum led_brightness value)
27{
28 switch (value) {
29 case LED_HALF:
30 h1940_latch_control(0,H1940_LATCH_LED_FLASH);
31 s3c2410_gpio_setpin(S3C2410_GPA7,1);
32 break;
33 case LED_FULL:
34 h1940_latch_control(0,H1940_LATCH_LED_GREEN);
35 s3c2410_gpio_setpin(S3C2410_GPA7,1);
36 break;
37 default:
38 case LED_OFF:
39 h1940_latch_control(H1940_LATCH_LED_FLASH,0);
40 h1940_latch_control(H1940_LATCH_LED_GREEN,0);
41 s3c2410_gpio_setpin(S3C2410_GPA7,0);
42 break;
43 }
44}
45
46static struct led_classdev h1940_greenled = {
47 .name = "h1940:green",
48 .brightness_set = h1940_greenled_set,
49 .default_trigger = "h1940-charger",
50};
51
52/*
53 * Red led.
54 */
55void h1940_redled_set(struct led_classdev *led_dev, enum led_brightness value)
56{
57 switch (value) {
58 case LED_HALF:
59 h1940_latch_control(0,H1940_LATCH_LED_FLASH);
60 s3c2410_gpio_setpin(S3C2410_GPA1,1);
61 break;
62 case LED_FULL:
63 h1940_latch_control(0,H1940_LATCH_LED_RED);
64 s3c2410_gpio_setpin(S3C2410_GPA1,1);
65 break;
66 default:
67 case LED_OFF:
68 h1940_latch_control(H1940_LATCH_LED_FLASH,0);
69 h1940_latch_control(H1940_LATCH_LED_RED,0);
70 s3c2410_gpio_setpin(S3C2410_GPA1,0);
71 break;
72 }
73}
74
75static struct led_classdev h1940_redled = {
76 .name = "h1940:red",
77 .brightness_set = h1940_redled_set,
78 .default_trigger = "h1940-charger",
79};
80
81/*
82 * Blue led.
83 * (it can only be blue flashing led)
84 */
85void h1940_blueled_set(struct led_classdev *led_dev, enum led_brightness value)
86{
87 if (value) {
88 /* flashing Blue */
89 h1940_latch_control(0,H1940_LATCH_LED_FLASH);
90 s3c2410_gpio_setpin(S3C2410_GPA3,1);
91 } else {
92 h1940_latch_control(H1940_LATCH_LED_FLASH,0);
93 s3c2410_gpio_setpin(S3C2410_GPA3,0);
94 }
95
96}
97
98static struct led_classdev h1940_blueled = {
99 .name = "h1940:blue",
100 .brightness_set = h1940_blueled_set,
101 .default_trigger = "h1940-bluetooth",
102};
103
104static int __init h1940leds_probe(struct platform_device *pdev)
105{
106 int ret;
107
108 ret = led_classdev_register(&pdev->dev, &h1940_greenled);
109 if (ret)
110 goto err_green;
111
112 ret = led_classdev_register(&pdev->dev, &h1940_redled);
113 if (ret)
114 goto err_red;
115
116 ret = led_classdev_register(&pdev->dev, &h1940_blueled);
117 if (ret)
118 goto err_blue;
119
120 return 0;
121
122err_blue:
123 led_classdev_unregister(&h1940_redled);
124err_red:
125 led_classdev_unregister(&h1940_greenled);
126err_green:
127 return ret;
128}
129
130static int h1940leds_remove(struct platform_device *pdev)
131{
132 led_classdev_unregister(&h1940_greenled);
133 led_classdev_unregister(&h1940_redled);
134 led_classdev_unregister(&h1940_blueled);
135 return 0;
136}
137
138
139static struct platform_driver h1940leds_driver = {
140 .driver = {
141 .name = "h1940-leds",
142 },
143 .probe = h1940leds_probe,
144 .remove = h1940leds_remove,
145};
146
147
148static int __init h1940leds_init(void)
149{
150 return platform_driver_register(&h1940leds_driver);
151}
152
153static void __exit h1940leds_exit(void)
154{
155 platform_driver_unregister(&h1940leds_driver);
156}
157
158module_init(h1940leds_init);
159module_exit(h1940leds_exit);
160
161MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
162MODULE_DESCRIPTION("LED driver for the iPAQ H1940");
163MODULE_LICENSE("GPL");
diff --git a/drivers/macintosh/via-pmu-backlight.c b/drivers/macintosh/via-pmu-backlight.c
index 801a974342..7e27071746 100644
--- a/drivers/macintosh/via-pmu-backlight.c
+++ b/drivers/macintosh/via-pmu-backlight.c
@@ -15,7 +15,7 @@
15 15
16#define MAX_PMU_LEVEL 0xFF 16#define MAX_PMU_LEVEL 0xFF
17 17
18static struct backlight_properties pmu_backlight_data; 18static struct backlight_ops pmu_backlight_data;
19static DEFINE_SPINLOCK(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];
@@ -72,7 +72,7 @@ static int pmu_backlight_update_status(struct backlight_device *bd)
72{ 72{
73 struct adb_request req; 73 struct adb_request req;
74 unsigned long flags; 74 unsigned long flags;
75 int level = bd->props->brightness; 75 int level = bd->props.brightness;
76 76
77 spin_lock_irqsave(&pmu_backlight_lock, flags); 77 spin_lock_irqsave(&pmu_backlight_lock, flags);
78 78
@@ -80,8 +80,8 @@ static int pmu_backlight_update_status(struct backlight_device *bd)
80 if (sleeping) 80 if (sleeping)
81 goto out; 81 goto out;
82 82
83 if (bd->props->power != FB_BLANK_UNBLANK || 83 if (bd->props.power != FB_BLANK_UNBLANK ||
84 bd->props->fb_blank != FB_BLANK_UNBLANK) 84 bd->props.fb_blank != FB_BLANK_UNBLANK)
85 level = 0; 85 level = 0;
86 86
87 if (level > 0) { 87 if (level > 0) {
@@ -107,14 +107,13 @@ out:
107 107
108static int pmu_backlight_get_brightness(struct backlight_device *bd) 108static int pmu_backlight_get_brightness(struct backlight_device *bd)
109{ 109{
110 return bd->props->brightness; 110 return bd->props.brightness;
111} 111}
112 112
113static struct backlight_properties pmu_backlight_data = { 113static struct backlight_ops pmu_backlight_data = {
114 .owner = THIS_MODULE,
115 .get_brightness = pmu_backlight_get_brightness, 114 .get_brightness = pmu_backlight_get_brightness,
116 .update_status = pmu_backlight_update_status, 115 .update_status = pmu_backlight_update_status,
117 .max_brightness = (FB_BACKLIGHT_LEVELS - 1), 116
118}; 117};
119 118
120#ifdef CONFIG_PM 119#ifdef CONFIG_PM
@@ -152,9 +151,10 @@ void __init pmu_backlight_init()
152 printk("pmubl: Backlight registration failed\n"); 151 printk("pmubl: Backlight registration failed\n");
153 goto error; 152 goto error;
154 } 153 }
154 bd->props.max_brightness = FB_BACKLIGHT_LEVELS - 1;
155 pmu_backlight_init_curve(0x7F, 0x46, 0x0E); 155 pmu_backlight_init_curve(0x7F, 0x46, 0x0E);
156 156
157 level = pmu_backlight_data.max_brightness; 157 level = bd->props.max_brightness;
158 158
159 if (autosave) { 159 if (autosave) {
160 /* read autosaved value if available */ 160 /* read autosaved value if available */
@@ -164,19 +164,12 @@ void __init pmu_backlight_init()
164 164
165 level = pmu_backlight_curve_lookup( 165 level = pmu_backlight_curve_lookup(
166 (req.reply[0] >> 4) * 166 (req.reply[0] >> 4) *
167 pmu_backlight_data.max_brightness / 15); 167 bd->props.max_brightness / 15);
168 } 168 }
169 169
170 down(&bd->sem); 170 bd->props.brightness = level;
171 bd->props->brightness = level; 171 bd->props.power = FB_BLANK_UNBLANK;
172 bd->props->power = FB_BLANK_UNBLANK; 172 backlight_update_status(bd);
173 bd->props->update_status(bd);
174 up(&bd->sem);
175
176 mutex_lock(&pmac_backlight_mutex);
177 if (!pmac_backlight)
178 pmac_backlight = bd;
179 mutex_unlock(&pmac_backlight_mutex);
180 173
181 printk("pmubl: Backlight initialized (%s)\n", name); 174 printk("pmubl: Backlight initialized (%s)\n", name);
182 175
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 05febfd9f0..6c06e825cf 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1296,27 +1296,17 @@ static struct super_type super_types[] = {
1296 .sync_super = super_1_sync, 1296 .sync_super = super_1_sync,
1297 }, 1297 },
1298}; 1298};
1299
1300static mdk_rdev_t * match_dev_unit(mddev_t *mddev, mdk_rdev_t *dev)
1301{
1302 struct list_head *tmp;
1303 mdk_rdev_t *rdev;
1304
1305 ITERATE_RDEV(mddev,rdev,tmp)
1306 if (rdev->bdev->bd_contains == dev->bdev->bd_contains)
1307 return rdev;
1308
1309 return NULL;
1310}
1311 1299
1312static int match_mddev_units(mddev_t *mddev1, mddev_t *mddev2) 1300static int match_mddev_units(mddev_t *mddev1, mddev_t *mddev2)
1313{ 1301{
1314 struct list_head *tmp; 1302 struct list_head *tmp, *tmp2;
1315 mdk_rdev_t *rdev; 1303 mdk_rdev_t *rdev, *rdev2;
1316 1304
1317 ITERATE_RDEV(mddev1,rdev,tmp) 1305 ITERATE_RDEV(mddev1,rdev,tmp)
1318 if (match_dev_unit(mddev2, rdev)) 1306 ITERATE_RDEV(mddev2, rdev2, tmp2)
1319 return 1; 1307 if (rdev->bdev->bd_contains ==
1308 rdev2->bdev->bd_contains)
1309 return 1;
1320 1310
1321 return 0; 1311 return 0;
1322} 1312}
@@ -1325,8 +1315,7 @@ static LIST_HEAD(pending_raid_disks);
1325 1315
1326static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev) 1316static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
1327{ 1317{
1328 mdk_rdev_t *same_pdev; 1318 char b[BDEVNAME_SIZE];
1329 char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE];
1330 struct kobject *ko; 1319 struct kobject *ko;
1331 char *s; 1320 char *s;
1332 1321
@@ -1342,14 +1331,6 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
1342 else 1331 else
1343 mddev->size = rdev->size; 1332 mddev->size = rdev->size;
1344 } 1333 }
1345 same_pdev = match_dev_unit(mddev, rdev);
1346 if (same_pdev)
1347 printk(KERN_WARNING
1348 "%s: WARNING: %s appears to be on the same physical"
1349 " disk as %s. True\n protection against single-disk"
1350 " failure might be compromised.\n",
1351 mdname(mddev), bdevname(rdev->bdev,b),
1352 bdevname(same_pdev->bdev,b2));
1353 1334
1354 /* Verify rdev->desc_nr is unique. 1335 /* Verify rdev->desc_nr is unique.
1355 * If it is -1, assign a free number, else 1336 * If it is -1, assign a free number, else
@@ -3109,6 +3090,36 @@ static int do_md_run(mddev_t * mddev)
3109 return -EINVAL; 3090 return -EINVAL;
3110 } 3091 }
3111 3092
3093 if (pers->sync_request) {
3094 /* Warn if this is a potentially silly
3095 * configuration.
3096 */
3097 char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE];
3098 mdk_rdev_t *rdev2;
3099 struct list_head *tmp2;
3100 int warned = 0;
3101 ITERATE_RDEV(mddev, rdev, tmp) {
3102 ITERATE_RDEV(mddev, rdev2, tmp2) {
3103 if (rdev < rdev2 &&
3104 rdev->bdev->bd_contains ==
3105 rdev2->bdev->bd_contains) {
3106 printk(KERN_WARNING
3107 "%s: WARNING: %s appears to be"
3108 " on the same physical disk as"
3109 " %s.\n",
3110 mdname(mddev),
3111 bdevname(rdev->bdev,b),
3112 bdevname(rdev2->bdev,b2));
3113 warned = 1;
3114 }
3115 }
3116 }
3117 if (warned)
3118 printk(KERN_WARNING
3119 "True protection against single-disk"
3120 " failure might be compromised.\n");
3121 }
3122
3112 mddev->recovery = 0; 3123 mddev->recovery = 0;
3113 mddev->resync_max_sectors = mddev->size << 1; /* may be over-ridden by personality */ 3124 mddev->resync_max_sectors = mddev->size << 1; /* may be over-ridden by personality */
3114 mddev->barriers_work = 1; 3125 mddev->barriers_work = 1;
@@ -3311,6 +3322,9 @@ static int do_md_stop(mddev_t * mddev, int mode)
3311 set_disk_ro(disk, 0); 3322 set_disk_ro(disk, 0);
3312 blk_queue_make_request(mddev->queue, md_fail_request); 3323 blk_queue_make_request(mddev->queue, md_fail_request);
3313 mddev->pers->stop(mddev); 3324 mddev->pers->stop(mddev);
3325 mddev->queue->merge_bvec_fn = NULL;
3326 mddev->queue->unplug_fn = NULL;
3327 mddev->queue->issue_flush_fn = NULL;
3314 if (mddev->pers->sync_request) 3328 if (mddev->pers->sync_request)
3315 sysfs_remove_group(&mddev->kobj, &md_redundancy_group); 3329 sysfs_remove_group(&mddev->kobj, &md_redundancy_group);
3316 3330
@@ -5343,6 +5357,44 @@ void md_do_sync(mddev_t *mddev)
5343EXPORT_SYMBOL_GPL(md_do_sync); 5357EXPORT_SYMBOL_GPL(md_do_sync);
5344 5358
5345 5359
5360static int remove_and_add_spares(mddev_t *mddev)
5361{
5362 mdk_rdev_t *rdev;
5363 struct list_head *rtmp;
5364 int spares = 0;
5365
5366 ITERATE_RDEV(mddev,rdev,rtmp)
5367 if (rdev->raid_disk >= 0 &&
5368 (test_bit(Faulty, &rdev->flags) ||
5369 ! test_bit(In_sync, &rdev->flags)) &&
5370 atomic_read(&rdev->nr_pending)==0) {
5371 if (mddev->pers->hot_remove_disk(
5372 mddev, rdev->raid_disk)==0) {
5373 char nm[20];
5374 sprintf(nm,"rd%d", rdev->raid_disk);
5375 sysfs_remove_link(&mddev->kobj, nm);
5376 rdev->raid_disk = -1;
5377 }
5378 }
5379
5380 if (mddev->degraded) {
5381 ITERATE_RDEV(mddev,rdev,rtmp)
5382 if (rdev->raid_disk < 0
5383 && !test_bit(Faulty, &rdev->flags)) {
5384 rdev->recovery_offset = 0;
5385 if (mddev->pers->hot_add_disk(mddev,rdev)) {
5386 char nm[20];
5387 sprintf(nm, "rd%d", rdev->raid_disk);
5388 sysfs_create_link(&mddev->kobj,
5389 &rdev->kobj, nm);
5390 spares++;
5391 md_new_event(mddev);
5392 } else
5393 break;
5394 }
5395 }
5396 return spares;
5397}
5346/* 5398/*
5347 * This routine is regularly called by all per-raid-array threads to 5399 * This routine is regularly called by all per-raid-array threads to
5348 * deal with generic issues like resync and super-block update. 5400 * deal with generic issues like resync and super-block update.
@@ -5397,7 +5449,7 @@ void md_check_recovery(mddev_t *mddev)
5397 return; 5449 return;
5398 5450
5399 if (mddev_trylock(mddev)) { 5451 if (mddev_trylock(mddev)) {
5400 int spares =0; 5452 int spares = 0;
5401 5453
5402 spin_lock_irq(&mddev->write_lock); 5454 spin_lock_irq(&mddev->write_lock);
5403 if (mddev->safemode && !atomic_read(&mddev->writes_pending) && 5455 if (mddev->safemode && !atomic_read(&mddev->writes_pending) &&
@@ -5460,35 +5512,13 @@ void md_check_recovery(mddev_t *mddev)
5460 * Spare are also removed and re-added, to allow 5512 * Spare are also removed and re-added, to allow
5461 * the personality to fail the re-add. 5513 * the personality to fail the re-add.
5462 */ 5514 */
5463 ITERATE_RDEV(mddev,rdev,rtmp)
5464 if (rdev->raid_disk >= 0 &&
5465 (test_bit(Faulty, &rdev->flags) || ! test_bit(In_sync, &rdev->flags)) &&
5466 atomic_read(&rdev->nr_pending)==0) {
5467 if (mddev->pers->hot_remove_disk(mddev, rdev->raid_disk)==0) {
5468 char nm[20];
5469 sprintf(nm,"rd%d", rdev->raid_disk);
5470 sysfs_remove_link(&mddev->kobj, nm);
5471 rdev->raid_disk = -1;
5472 }
5473 }
5474
5475 if (mddev->degraded) {
5476 ITERATE_RDEV(mddev,rdev,rtmp)
5477 if (rdev->raid_disk < 0
5478 && !test_bit(Faulty, &rdev->flags)) {
5479 rdev->recovery_offset = 0;
5480 if (mddev->pers->hot_add_disk(mddev,rdev)) {
5481 char nm[20];
5482 sprintf(nm, "rd%d", rdev->raid_disk);
5483 sysfs_create_link(&mddev->kobj, &rdev->kobj, nm);
5484 spares++;
5485 md_new_event(mddev);
5486 } else
5487 break;
5488 }
5489 }
5490 5515
5491 if (spares) { 5516 if (mddev->reshape_position != MaxSector) {
5517 if (mddev->pers->check_reshape(mddev) != 0)
5518 /* Cannot proceed */
5519 goto unlock;
5520 set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery);
5521 } else if ((spares = remove_and_add_spares(mddev))) {
5492 clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); 5522 clear_bit(MD_RECOVERY_SYNC, &mddev->recovery);
5493 clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); 5523 clear_bit(MD_RECOVERY_CHECK, &mddev->recovery);
5494 } else if (mddev->recovery_cp < MaxSector) { 5524 } else if (mddev->recovery_cp < MaxSector) {
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index a9401c017e..82249a6901 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -429,7 +429,7 @@ static sector_t raid10_find_virt(conf_t *conf, sector_t sector, int dev)
429 if (dev < 0) 429 if (dev < 0)
430 dev += conf->raid_disks; 430 dev += conf->raid_disks;
431 } else { 431 } else {
432 while (sector > conf->stride) { 432 while (sector >= conf->stride) {
433 sector -= conf->stride; 433 sector -= conf->stride;
434 if (dev < conf->near_copies) 434 if (dev < conf->near_copies)
435 dev += conf->raid_disks - conf->near_copies; 435 dev += conf->raid_disks - conf->near_copies;
@@ -1801,6 +1801,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1801 for (k=0; k<conf->copies; k++) 1801 for (k=0; k<conf->copies; k++)
1802 if (r10_bio->devs[k].devnum == i) 1802 if (r10_bio->devs[k].devnum == i)
1803 break; 1803 break;
1804 BUG_ON(k == conf->copies);
1804 bio = r10_bio->devs[1].bio; 1805 bio = r10_bio->devs[1].bio;
1805 bio->bi_next = biolist; 1806 bio->bi_next = biolist;
1806 biolist = bio; 1807 biolist = bio;
@@ -2021,19 +2022,30 @@ static int run(mddev_t *mddev)
2021 if (!conf->tmppage) 2022 if (!conf->tmppage)
2022 goto out_free_conf; 2023 goto out_free_conf;
2023 2024
2025 conf->mddev = mddev;
2026 conf->raid_disks = mddev->raid_disks;
2024 conf->near_copies = nc; 2027 conf->near_copies = nc;
2025 conf->far_copies = fc; 2028 conf->far_copies = fc;
2026 conf->copies = nc*fc; 2029 conf->copies = nc*fc;
2027 conf->far_offset = fo; 2030 conf->far_offset = fo;
2028 conf->chunk_mask = (sector_t)(mddev->chunk_size>>9)-1; 2031 conf->chunk_mask = (sector_t)(mddev->chunk_size>>9)-1;
2029 conf->chunk_shift = ffz(~mddev->chunk_size) - 9; 2032 conf->chunk_shift = ffz(~mddev->chunk_size) - 9;
2033 size = mddev->size >> (conf->chunk_shift-1);
2034 sector_div(size, fc);
2035 size = size * conf->raid_disks;
2036 sector_div(size, nc);
2037 /* 'size' is now the number of chunks in the array */
2038 /* calculate "used chunks per device" in 'stride' */
2039 stride = size * conf->copies;
2040 sector_div(stride, conf->raid_disks);
2041 mddev->size = stride << (conf->chunk_shift-1);
2042
2030 if (fo) 2043 if (fo)
2031 conf->stride = 1 << conf->chunk_shift; 2044 stride = 1;
2032 else { 2045 else
2033 stride = mddev->size >> (conf->chunk_shift-1);
2034 sector_div(stride, fc); 2046 sector_div(stride, fc);
2035 conf->stride = stride << conf->chunk_shift; 2047 conf->stride = stride << conf->chunk_shift;
2036 } 2048
2037 conf->r10bio_pool = mempool_create(NR_RAID10_BIOS, r10bio_pool_alloc, 2049 conf->r10bio_pool = mempool_create(NR_RAID10_BIOS, r10bio_pool_alloc,
2038 r10bio_pool_free, conf); 2050 r10bio_pool_free, conf);
2039 if (!conf->r10bio_pool) { 2051 if (!conf->r10bio_pool) {
@@ -2063,8 +2075,6 @@ static int run(mddev_t *mddev)
2063 2075
2064 disk->head_position = 0; 2076 disk->head_position = 0;
2065 } 2077 }
2066 conf->raid_disks = mddev->raid_disks;
2067 conf->mddev = mddev;
2068 spin_lock_init(&conf->device_lock); 2078 spin_lock_init(&conf->device_lock);
2069 INIT_LIST_HEAD(&conf->retry_list); 2079 INIT_LIST_HEAD(&conf->retry_list);
2070 2080
@@ -2106,16 +2116,8 @@ static int run(mddev_t *mddev)
2106 /* 2116 /*
2107 * Ok, everything is just fine now 2117 * Ok, everything is just fine now
2108 */ 2118 */
2109 if (conf->far_offset) { 2119 mddev->array_size = size << (conf->chunk_shift-1);
2110 size = mddev->size >> (conf->chunk_shift-1); 2120 mddev->resync_max_sectors = size << conf->chunk_shift;
2111 size *= conf->raid_disks;
2112 size <<= conf->chunk_shift;
2113 sector_div(size, conf->far_copies);
2114 } else
2115 size = conf->stride * conf->raid_disks;
2116 sector_div(size, conf->near_copies);
2117 mddev->array_size = size/2;
2118 mddev->resync_max_sectors = size;
2119 2121
2120 mddev->queue->unplug_fn = raid10_unplug; 2122 mddev->queue->unplug_fn = raid10_unplug;
2121 mddev->queue->issue_flush_fn = raid10_issue_flush; 2123 mddev->queue->issue_flush_fn = raid10_issue_flush;
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 11c3d7bfa7..54a1ad5eef 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -1050,7 +1050,7 @@ static void compute_parity5(struct stripe_head *sh, int method)
1050static void compute_parity6(struct stripe_head *sh, int method) 1050static void compute_parity6(struct stripe_head *sh, int method)
1051{ 1051{
1052 raid6_conf_t *conf = sh->raid_conf; 1052 raid6_conf_t *conf = sh->raid_conf;
1053 int i, pd_idx = sh->pd_idx, qd_idx, d0_idx, disks = conf->raid_disks, count; 1053 int i, pd_idx = sh->pd_idx, qd_idx, d0_idx, disks = sh->disks, count;
1054 struct bio *chosen; 1054 struct bio *chosen;
1055 /**** FIX THIS: This could be very bad if disks is close to 256 ****/ 1055 /**** FIX THIS: This could be very bad if disks is close to 256 ****/
1056 void *ptrs[disks]; 1056 void *ptrs[disks];
@@ -1131,8 +1131,7 @@ static void compute_parity6(struct stripe_head *sh, int method)
1131/* Compute one missing block */ 1131/* Compute one missing block */
1132static void compute_block_1(struct stripe_head *sh, int dd_idx, int nozero) 1132static void compute_block_1(struct stripe_head *sh, int dd_idx, int nozero)
1133{ 1133{
1134 raid6_conf_t *conf = sh->raid_conf; 1134 int i, count, disks = sh->disks;
1135 int i, count, disks = conf->raid_disks;
1136 void *ptr[MAX_XOR_BLOCKS], *p; 1135 void *ptr[MAX_XOR_BLOCKS], *p;
1137 int pd_idx = sh->pd_idx; 1136 int pd_idx = sh->pd_idx;
1138 int qd_idx = raid6_next_disk(pd_idx, disks); 1137 int qd_idx = raid6_next_disk(pd_idx, disks);
@@ -1170,8 +1169,7 @@ static void compute_block_1(struct stripe_head *sh, int dd_idx, int nozero)
1170/* Compute two missing blocks */ 1169/* Compute two missing blocks */
1171static void compute_block_2(struct stripe_head *sh, int dd_idx1, int dd_idx2) 1170static void compute_block_2(struct stripe_head *sh, int dd_idx1, int dd_idx2)
1172{ 1171{
1173 raid6_conf_t *conf = sh->raid_conf; 1172 int i, count, disks = sh->disks;
1174 int i, count, disks = conf->raid_disks;
1175 int pd_idx = sh->pd_idx; 1173 int pd_idx = sh->pd_idx;
1176 int qd_idx = raid6_next_disk(pd_idx, disks); 1174 int qd_idx = raid6_next_disk(pd_idx, disks);
1177 int d0_idx = raid6_next_disk(qd_idx, disks); 1175 int d0_idx = raid6_next_disk(qd_idx, disks);
@@ -1887,11 +1885,11 @@ static void handle_stripe5(struct stripe_head *sh)
1887static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page) 1885static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
1888{ 1886{
1889 raid6_conf_t *conf = sh->raid_conf; 1887 raid6_conf_t *conf = sh->raid_conf;
1890 int disks = conf->raid_disks; 1888 int disks = sh->disks;
1891 struct bio *return_bi= NULL; 1889 struct bio *return_bi= NULL;
1892 struct bio *bi; 1890 struct bio *bi;
1893 int i; 1891 int i;
1894 int syncing; 1892 int syncing, expanding, expanded;
1895 int locked=0, uptodate=0, to_read=0, to_write=0, failed=0, written=0; 1893 int locked=0, uptodate=0, to_read=0, to_write=0, failed=0, written=0;
1896 int non_overwrite = 0; 1894 int non_overwrite = 0;
1897 int failed_num[2] = {0, 0}; 1895 int failed_num[2] = {0, 0};
@@ -1909,6 +1907,8 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
1909 clear_bit(STRIPE_DELAYED, &sh->state); 1907 clear_bit(STRIPE_DELAYED, &sh->state);
1910 1908
1911 syncing = test_bit(STRIPE_SYNCING, &sh->state); 1909 syncing = test_bit(STRIPE_SYNCING, &sh->state);
1910 expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state);
1911 expanded = test_bit(STRIPE_EXPAND_READY, &sh->state);
1912 /* Now to look around and see what can be done */ 1912 /* Now to look around and see what can be done */
1913 1913
1914 rcu_read_lock(); 1914 rcu_read_lock();
@@ -2114,13 +2114,15 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
2114 * parity, or to satisfy requests 2114 * parity, or to satisfy requests
2115 * or to load a block that is being partially written. 2115 * or to load a block that is being partially written.
2116 */ 2116 */
2117 if (to_read || non_overwrite || (to_write && failed) || (syncing && (uptodate < disks))) { 2117 if (to_read || non_overwrite || (to_write && failed) ||
2118 (syncing && (uptodate < disks)) || expanding) {
2118 for (i=disks; i--;) { 2119 for (i=disks; i--;) {
2119 dev = &sh->dev[i]; 2120 dev = &sh->dev[i];
2120 if (!test_bit(R5_LOCKED, &dev->flags) && !test_bit(R5_UPTODATE, &dev->flags) && 2121 if (!test_bit(R5_LOCKED, &dev->flags) && !test_bit(R5_UPTODATE, &dev->flags) &&
2121 (dev->toread || 2122 (dev->toread ||
2122 (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) || 2123 (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) ||
2123 syncing || 2124 syncing ||
2125 expanding ||
2124 (failed >= 1 && (sh->dev[failed_num[0]].toread || to_write)) || 2126 (failed >= 1 && (sh->dev[failed_num[0]].toread || to_write)) ||
2125 (failed >= 2 && (sh->dev[failed_num[1]].toread || to_write)) 2127 (failed >= 2 && (sh->dev[failed_num[1]].toread || to_write))
2126 ) 2128 )
@@ -2355,6 +2357,79 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
2355 } 2357 }
2356 } 2358 }
2357 } 2359 }
2360
2361 if (expanded && test_bit(STRIPE_EXPANDING, &sh->state)) {
2362 /* Need to write out all blocks after computing P&Q */
2363 sh->disks = conf->raid_disks;
2364 sh->pd_idx = stripe_to_pdidx(sh->sector, conf,
2365 conf->raid_disks);
2366 compute_parity6(sh, RECONSTRUCT_WRITE);
2367 for (i = conf->raid_disks ; i-- ; ) {
2368 set_bit(R5_LOCKED, &sh->dev[i].flags);
2369 locked++;
2370 set_bit(R5_Wantwrite, &sh->dev[i].flags);
2371 }
2372 clear_bit(STRIPE_EXPANDING, &sh->state);
2373 } else if (expanded) {
2374 clear_bit(STRIPE_EXPAND_READY, &sh->state);
2375 atomic_dec(&conf->reshape_stripes);
2376 wake_up(&conf->wait_for_overlap);
2377 md_done_sync(conf->mddev, STRIPE_SECTORS, 1);
2378 }
2379
2380 if (expanding && locked == 0) {
2381 /* We have read all the blocks in this stripe and now we need to
2382 * copy some of them into a target stripe for expand.
2383 */
2384 clear_bit(STRIPE_EXPAND_SOURCE, &sh->state);
2385 for (i = 0; i < sh->disks ; i++)
2386 if (i != pd_idx && i != qd_idx) {
2387 int dd_idx2, pd_idx2, j;
2388 struct stripe_head *sh2;
2389
2390 sector_t bn = compute_blocknr(sh, i);
2391 sector_t s = raid5_compute_sector(
2392 bn, conf->raid_disks,
2393 conf->raid_disks - conf->max_degraded,
2394 &dd_idx2, &pd_idx2, conf);
2395 sh2 = get_active_stripe(conf, s,
2396 conf->raid_disks,
2397 pd_idx2, 1);
2398 if (sh2 == NULL)
2399 /* so for only the early blocks of
2400 * this stripe have been requests.
2401 * When later blocks get requests, we
2402 * will try again
2403 */
2404 continue;
2405 if (!test_bit(STRIPE_EXPANDING, &sh2->state) ||
2406 test_bit(R5_Expanded,
2407 &sh2->dev[dd_idx2].flags)) {
2408 /* must have already done this block */
2409 release_stripe(sh2);
2410 continue;
2411 }
2412 memcpy(page_address(sh2->dev[dd_idx2].page),
2413 page_address(sh->dev[i].page),
2414 STRIPE_SIZE);
2415 set_bit(R5_Expanded, &sh2->dev[dd_idx2].flags);
2416 set_bit(R5_UPTODATE, &sh2->dev[dd_idx2].flags);
2417 for (j = 0 ; j < conf->raid_disks ; j++)
2418 if (j != sh2->pd_idx &&
2419 j != raid6_next_disk(sh2->pd_idx,
2420 sh2->disks) &&
2421 !test_bit(R5_Expanded,
2422 &sh2->dev[j].flags))
2423 break;
2424 if (j == conf->raid_disks) {
2425 set_bit(STRIPE_EXPAND_READY,
2426 &sh2->state);
2427 set_bit(STRIPE_HANDLE, &sh2->state);
2428 }
2429 release_stripe(sh2);
2430 }
2431 }
2432
2358 spin_unlock(&sh->lock); 2433 spin_unlock(&sh->lock);
2359 2434
2360 while ((bi=return_bi)) { 2435 while ((bi=return_bi)) {
@@ -2395,7 +2470,7 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
2395 rcu_read_unlock(); 2470 rcu_read_unlock();
2396 2471
2397 if (rdev) { 2472 if (rdev) {
2398 if (syncing) 2473 if (syncing || expanding || expanded)
2399 md_sync_acct(rdev->bdev, STRIPE_SECTORS); 2474 md_sync_acct(rdev->bdev, STRIPE_SECTORS);
2400 2475
2401 bi->bi_bdev = rdev->bdev; 2476 bi->bi_bdev = rdev->bdev;
@@ -2915,8 +2990,9 @@ static sector_t reshape_request(mddev_t *mddev, sector_t sector_nr, int *skipped
2915 struct stripe_head *sh; 2990 struct stripe_head *sh;
2916 int pd_idx; 2991 int pd_idx;
2917 sector_t first_sector, last_sector; 2992 sector_t first_sector, last_sector;
2918 int raid_disks; 2993 int raid_disks = conf->previous_raid_disks;
2919 int data_disks; 2994 int data_disks = raid_disks - conf->max_degraded;
2995 int new_data_disks = conf->raid_disks - conf->max_degraded;
2920 int i; 2996 int i;
2921 int dd_idx; 2997 int dd_idx;
2922 sector_t writepos, safepos, gap; 2998 sector_t writepos, safepos, gap;
@@ -2925,7 +3001,7 @@ static sector_t reshape_request(mddev_t *mddev, sector_t sector_nr, int *skipped
2925 conf->expand_progress != 0) { 3001 conf->expand_progress != 0) {
2926 /* restarting in the middle, skip the initial sectors */ 3002 /* restarting in the middle, skip the initial sectors */
2927 sector_nr = conf->expand_progress; 3003 sector_nr = conf->expand_progress;
2928 sector_div(sector_nr, conf->raid_disks-1); 3004 sector_div(sector_nr, new_data_disks);
2929 *skipped = 1; 3005 *skipped = 1;
2930 return sector_nr; 3006 return sector_nr;
2931 } 3007 }
@@ -2939,14 +3015,14 @@ static sector_t reshape_request(mddev_t *mddev, sector_t sector_nr, int *skipped
2939 * to after where expand_lo old_maps to 3015 * to after where expand_lo old_maps to
2940 */ 3016 */
2941 writepos = conf->expand_progress + 3017 writepos = conf->expand_progress +
2942 conf->chunk_size/512*(conf->raid_disks-1); 3018 conf->chunk_size/512*(new_data_disks);
2943 sector_div(writepos, conf->raid_disks-1); 3019 sector_div(writepos, new_data_disks);
2944 safepos = conf->expand_lo; 3020 safepos = conf->expand_lo;
2945 sector_div(safepos, conf->previous_raid_disks-1); 3021 sector_div(safepos, data_disks);
2946 gap = conf->expand_progress - conf->expand_lo; 3022 gap = conf->expand_progress - conf->expand_lo;
2947 3023
2948 if (writepos >= safepos || 3024 if (writepos >= safepos ||
2949 gap > (conf->raid_disks-1)*3000*2 /*3Meg*/) { 3025 gap > (new_data_disks)*3000*2 /*3Meg*/) {
2950 /* Cannot proceed until we've updated the superblock... */ 3026 /* Cannot proceed until we've updated the superblock... */
2951 wait_event(conf->wait_for_overlap, 3027 wait_event(conf->wait_for_overlap,
2952 atomic_read(&conf->reshape_stripes)==0); 3028 atomic_read(&conf->reshape_stripes)==0);
@@ -2976,6 +3052,9 @@ static sector_t reshape_request(mddev_t *mddev, sector_t sector_nr, int *skipped
2976 sector_t s; 3052 sector_t s;
2977 if (j == sh->pd_idx) 3053 if (j == sh->pd_idx)
2978 continue; 3054 continue;
3055 if (conf->level == 6 &&
3056 j == raid6_next_disk(sh->pd_idx, sh->disks))
3057 continue;
2979 s = compute_blocknr(sh, j); 3058 s = compute_blocknr(sh, j);
2980 if (s < (mddev->array_size<<1)) { 3059 if (s < (mddev->array_size<<1)) {
2981 skipped = 1; 3060 skipped = 1;
@@ -2992,28 +3071,27 @@ static sector_t reshape_request(mddev_t *mddev, sector_t sector_nr, int *skipped
2992 release_stripe(sh); 3071 release_stripe(sh);
2993 } 3072 }
2994 spin_lock_irq(&conf->device_lock); 3073 spin_lock_irq(&conf->device_lock);
2995 conf->expand_progress = (sector_nr + i)*(conf->raid_disks-1); 3074 conf->expand_progress = (sector_nr + i) * new_data_disks;
2996 spin_unlock_irq(&conf->device_lock); 3075 spin_unlock_irq(&conf->device_lock);
2997 /* Ok, those stripe are ready. We can start scheduling 3076 /* Ok, those stripe are ready. We can start scheduling
2998 * reads on the source stripes. 3077 * reads on the source stripes.
2999 * The source stripes are determined by mapping the first and last 3078 * The source stripes are determined by mapping the first and last
3000 * block on the destination stripes. 3079 * block on the destination stripes.
3001 */ 3080 */
3002 raid_disks = conf->previous_raid_disks;
3003 data_disks = raid_disks - 1;
3004 first_sector = 3081 first_sector =
3005 raid5_compute_sector(sector_nr*(conf->raid_disks-1), 3082 raid5_compute_sector(sector_nr*(new_data_disks),
3006 raid_disks, data_disks, 3083 raid_disks, data_disks,
3007 &dd_idx, &pd_idx, conf); 3084 &dd_idx, &pd_idx, conf);
3008 last_sector = 3085 last_sector =
3009 raid5_compute_sector((sector_nr+conf->chunk_size/512) 3086 raid5_compute_sector((sector_nr+conf->chunk_size/512)
3010 *(conf->raid_disks-1) -1, 3087 *(new_data_disks) -1,
3011 raid_disks, data_disks, 3088 raid_disks, data_disks,
3012 &dd_idx, &pd_idx, conf); 3089 &dd_idx, &pd_idx, conf);
3013 if (last_sector >= (mddev->size<<1)) 3090 if (last_sector >= (mddev->size<<1))
3014 last_sector = (mddev->size<<1)-1; 3091 last_sector = (mddev->size<<1)-1;
3015 while (first_sector <= last_sector) { 3092 while (first_sector <= last_sector) {
3016 pd_idx = stripe_to_pdidx(first_sector, conf, conf->previous_raid_disks); 3093 pd_idx = stripe_to_pdidx(first_sector, conf,
3094 conf->previous_raid_disks);
3017 sh = get_active_stripe(conf, first_sector, 3095 sh = get_active_stripe(conf, first_sector,
3018 conf->previous_raid_disks, pd_idx, 0); 3096 conf->previous_raid_disks, pd_idx, 0);
3019 set_bit(STRIPE_EXPAND_SOURCE, &sh->state); 3097 set_bit(STRIPE_EXPAND_SOURCE, &sh->state);
@@ -3348,35 +3426,44 @@ static int run(mddev_t *mddev)
3348 */ 3426 */
3349 sector_t here_new, here_old; 3427 sector_t here_new, here_old;
3350 int old_disks; 3428 int old_disks;
3429 int max_degraded = (mddev->level == 5 ? 1 : 2);
3351 3430
3352 if (mddev->new_level != mddev->level || 3431 if (mddev->new_level != mddev->level ||
3353 mddev->new_layout != mddev->layout || 3432 mddev->new_layout != mddev->layout ||
3354 mddev->new_chunk != mddev->chunk_size) { 3433 mddev->new_chunk != mddev->chunk_size) {
3355 printk(KERN_ERR "raid5: %s: unsupported reshape required - aborting.\n", 3434 printk(KERN_ERR "raid5: %s: unsupported reshape "
3435 "required - aborting.\n",
3356 mdname(mddev)); 3436 mdname(mddev));
3357 return -EINVAL; 3437 return -EINVAL;
3358 } 3438 }
3359 if (mddev->delta_disks <= 0) { 3439 if (mddev->delta_disks <= 0) {
3360 printk(KERN_ERR "raid5: %s: unsupported reshape (reduce disks) required - aborting.\n", 3440 printk(KERN_ERR "raid5: %s: unsupported reshape "
3441 "(reduce disks) required - aborting.\n",
3361 mdname(mddev)); 3442 mdname(mddev));
3362 return -EINVAL; 3443 return -EINVAL;
3363 } 3444 }
3364 old_disks = mddev->raid_disks - mddev->delta_disks; 3445 old_disks = mddev->raid_disks - mddev->delta_disks;
3365 /* reshape_position must be on a new-stripe boundary, and one 3446 /* reshape_position must be on a new-stripe boundary, and one
3366 * further up in new geometry must map after here in old geometry. 3447 * further up in new geometry must map after here in old
3448 * geometry.
3367 */ 3449 */
3368 here_new = mddev->reshape_position; 3450 here_new = mddev->reshape_position;
3369 if (sector_div(here_new, (mddev->chunk_size>>9)*(mddev->raid_disks-1))) { 3451 if (sector_div(here_new, (mddev->chunk_size>>9)*
3370 printk(KERN_ERR "raid5: reshape_position not on a stripe boundary\n"); 3452 (mddev->raid_disks - max_degraded))) {
3453 printk(KERN_ERR "raid5: reshape_position not "
3454 "on a stripe boundary\n");
3371 return -EINVAL; 3455 return -EINVAL;
3372 } 3456 }
3373 /* here_new is the stripe we will write to */ 3457 /* here_new is the stripe we will write to */
3374 here_old = mddev->reshape_position; 3458 here_old = mddev->reshape_position;
3375 sector_div(here_old, (mddev->chunk_size>>9)*(old_disks-1)); 3459 sector_div(here_old, (mddev->chunk_size>>9)*
3376 /* here_old is the first stripe that we might need to read from */ 3460 (old_disks-max_degraded));
3461 /* here_old is the first stripe that we might need to read
3462 * from */
3377 if (here_new >= here_old) { 3463 if (here_new >= here_old) {
3378 /* Reading from the same stripe as writing to - bad */ 3464 /* Reading from the same stripe as writing to - bad */
3379 printk(KERN_ERR "raid5: reshape_position too early for auto-recovery - aborting.\n"); 3465 printk(KERN_ERR "raid5: reshape_position too early for "
3466 "auto-recovery - aborting.\n");
3380 return -EINVAL; 3467 return -EINVAL;
3381 } 3468 }
3382 printk(KERN_INFO "raid5: reshape will continue\n"); 3469 printk(KERN_INFO "raid5: reshape will continue\n");
@@ -3814,6 +3901,8 @@ static int raid5_check_reshape(mddev_t *mddev)
3814 if (err) 3901 if (err)
3815 return err; 3902 return err;
3816 3903
3904 if (mddev->degraded > conf->max_degraded)
3905 return -EINVAL;
3817 /* looks like we might be able to manage this */ 3906 /* looks like we might be able to manage this */
3818 return 0; 3907 return 0;
3819} 3908}
@@ -3827,8 +3916,7 @@ static int raid5_start_reshape(mddev_t *mddev)
3827 int added_devices = 0; 3916 int added_devices = 0;
3828 unsigned long flags; 3917 unsigned long flags;
3829 3918
3830 if (mddev->degraded || 3919 if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
3831 test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
3832 return -EBUSY; 3920 return -EBUSY;
3833 3921
3834 ITERATE_RDEV(mddev, rdev, rtmp) 3922 ITERATE_RDEV(mddev, rdev, rtmp)
@@ -3836,7 +3924,7 @@ static int raid5_start_reshape(mddev_t *mddev)
3836 !test_bit(Faulty, &rdev->flags)) 3924 !test_bit(Faulty, &rdev->flags))
3837 spares++; 3925 spares++;
3838 3926
3839 if (spares < mddev->delta_disks-1) 3927 if (spares - mddev->degraded < mddev->delta_disks - conf->max_degraded)
3840 /* Not enough devices even to make a degraded array 3928 /* Not enough devices even to make a degraded array
3841 * of that size 3929 * of that size
3842 */ 3930 */
@@ -3899,7 +3987,8 @@ static void end_reshape(raid5_conf_t *conf)
3899 struct block_device *bdev; 3987 struct block_device *bdev;
3900 3988
3901 if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) { 3989 if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) {
3902 conf->mddev->array_size = conf->mddev->size * (conf->raid_disks-1); 3990 conf->mddev->array_size = conf->mddev->size *
3991 (conf->raid_disks - conf->max_degraded);
3903 set_capacity(conf->mddev->gendisk, conf->mddev->array_size << 1); 3992 set_capacity(conf->mddev->gendisk, conf->mddev->array_size << 1);
3904 conf->mddev->changed = 1; 3993 conf->mddev->changed = 1;
3905 3994
@@ -3972,6 +4061,10 @@ static struct mdk_personality raid6_personality =
3972 .spare_active = raid5_spare_active, 4061 .spare_active = raid5_spare_active,
3973 .sync_request = sync_request, 4062 .sync_request = sync_request,
3974 .resize = raid5_resize, 4063 .resize = raid5_resize,
4064#ifdef CONFIG_MD_RAID5_RESHAPE
4065 .check_reshape = raid5_check_reshape,
4066 .start_reshape = raid5_start_reshape,
4067#endif
3975 .quiesce = raid5_quiesce, 4068 .quiesce = raid5_quiesce,
3976}; 4069};
3977static struct mdk_personality raid5_personality = 4070static struct mdk_personality raid5_personality =
diff --git a/drivers/md/raid6mmx.c b/drivers/md/raid6mmx.c
index 359157aaf9..6181a5a336 100644
--- a/drivers/md/raid6mmx.c
+++ b/drivers/md/raid6mmx.c
@@ -30,14 +30,8 @@ const struct raid6_mmx_constants {
30 30
31static int raid6_have_mmx(void) 31static int raid6_have_mmx(void)
32{ 32{
33#ifdef __KERNEL__
34 /* Not really "boot_cpu" but "all_cpus" */ 33 /* Not really "boot_cpu" but "all_cpus" */
35 return boot_cpu_has(X86_FEATURE_MMX); 34 return boot_cpu_has(X86_FEATURE_MMX);
36#else
37 /* User space test code */
38 u32 features = cpuid_features();
39 return ( (features & (1<<23)) == (1<<23) );
40#endif
41} 35}
42 36
43/* 37/*
@@ -48,13 +42,12 @@ static void raid6_mmx1_gen_syndrome(int disks, size_t bytes, void **ptrs)
48 u8 **dptr = (u8 **)ptrs; 42 u8 **dptr = (u8 **)ptrs;
49 u8 *p, *q; 43 u8 *p, *q;
50 int d, z, z0; 44 int d, z, z0;
51 raid6_mmx_save_t sa;
52 45
53 z0 = disks - 3; /* Highest data disk */ 46 z0 = disks - 3; /* Highest data disk */
54 p = dptr[z0+1]; /* XOR parity */ 47 p = dptr[z0+1]; /* XOR parity */
55 q = dptr[z0+2]; /* RS syndrome */ 48 q = dptr[z0+2]; /* RS syndrome */
56 49
57 raid6_before_mmx(&sa); 50 kernel_fpu_begin();
58 51
59 asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d)); 52 asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d));
60 asm volatile("pxor %mm5,%mm5"); /* Zero temp */ 53 asm volatile("pxor %mm5,%mm5"); /* Zero temp */
@@ -78,7 +71,7 @@ static void raid6_mmx1_gen_syndrome(int disks, size_t bytes, void **ptrs)
78 asm volatile("pxor %mm4,%mm4"); 71 asm volatile("pxor %mm4,%mm4");
79 } 72 }
80 73
81 raid6_after_mmx(&sa); 74 kernel_fpu_end();
82} 75}
83 76
84const struct raid6_calls raid6_mmxx1 = { 77const struct raid6_calls raid6_mmxx1 = {
@@ -96,13 +89,12 @@ static void raid6_mmx2_gen_syndrome(int disks, size_t bytes, void **ptrs)
96 u8 **dptr = (u8 **)ptrs; 89 u8 **dptr = (u8 **)ptrs;
97 u8 *p, *q; 90 u8 *p, *q;
98 int d, z, z0; 91 int d, z, z0;
99 raid6_mmx_save_t sa;
100 92
101 z0 = disks - 3; /* Highest data disk */ 93 z0 = disks - 3; /* Highest data disk */
102 p = dptr[z0+1]; /* XOR parity */ 94 p = dptr[z0+1]; /* XOR parity */
103 q = dptr[z0+2]; /* RS syndrome */ 95 q = dptr[z0+2]; /* RS syndrome */
104 96
105 raid6_before_mmx(&sa); 97 kernel_fpu_begin();
106 98
107 asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d)); 99 asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d));
108 asm volatile("pxor %mm5,%mm5"); /* Zero temp */ 100 asm volatile("pxor %mm5,%mm5"); /* Zero temp */
@@ -137,7 +129,7 @@ static void raid6_mmx2_gen_syndrome(int disks, size_t bytes, void **ptrs)
137 asm volatile("movq %%mm6,%0" : "=m" (q[d+8])); 129 asm volatile("movq %%mm6,%0" : "=m" (q[d+8]));
138 } 130 }
139 131
140 raid6_after_mmx(&sa); 132 kernel_fpu_end();
141} 133}
142 134
143const struct raid6_calls raid6_mmxx2 = { 135const struct raid6_calls raid6_mmxx2 = {
diff --git a/drivers/md/raid6sse1.c b/drivers/md/raid6sse1.c
index f7e7859f71..f0a1ba8f40 100644
--- a/drivers/md/raid6sse1.c
+++ b/drivers/md/raid6sse1.c
@@ -33,16 +33,10 @@ extern const struct raid6_mmx_constants {
33 33
34static int raid6_have_sse1_or_mmxext(void) 34static int raid6_have_sse1_or_mmxext(void)
35{ 35{
36#ifdef __KERNEL__
37 /* Not really boot_cpu but "all_cpus" */ 36 /* Not really boot_cpu but "all_cpus" */
38 return boot_cpu_has(X86_FEATURE_MMX) && 37 return boot_cpu_has(X86_FEATURE_MMX) &&
39 (boot_cpu_has(X86_FEATURE_XMM) || 38 (boot_cpu_has(X86_FEATURE_XMM) ||
40 boot_cpu_has(X86_FEATURE_MMXEXT)); 39 boot_cpu_has(X86_FEATURE_MMXEXT));
41#else
42 /* User space test code - this incorrectly breaks on some Athlons */
43 u32 features = cpuid_features();
44 return ( (features & (5<<23)) == (5<<23) );
45#endif
46} 40}
47 41
48/* 42/*
@@ -53,14 +47,12 @@ static void raid6_sse11_gen_syndrome(int disks, size_t bytes, void **ptrs)
53 u8 **dptr = (u8 **)ptrs; 47 u8 **dptr = (u8 **)ptrs;
54 u8 *p, *q; 48 u8 *p, *q;
55 int d, z, z0; 49 int d, z, z0;
56 raid6_mmx_save_t sa;
57 50
58 z0 = disks - 3; /* Highest data disk */ 51 z0 = disks - 3; /* Highest data disk */
59 p = dptr[z0+1]; /* XOR parity */ 52 p = dptr[z0+1]; /* XOR parity */
60 q = dptr[z0+2]; /* RS syndrome */ 53 q = dptr[z0+2]; /* RS syndrome */
61 54
62 /* This is really MMX code, not SSE */ 55 kernel_fpu_begin();
63 raid6_before_mmx(&sa);
64 56
65 asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d)); 57 asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d));
66 asm volatile("pxor %mm5,%mm5"); /* Zero temp */ 58 asm volatile("pxor %mm5,%mm5"); /* Zero temp */
@@ -94,8 +86,8 @@ static void raid6_sse11_gen_syndrome(int disks, size_t bytes, void **ptrs)
94 asm volatile("movntq %%mm4,%0" : "=m" (q[d])); 86 asm volatile("movntq %%mm4,%0" : "=m" (q[d]));
95 } 87 }
96 88
97 raid6_after_mmx(&sa);
98 asm volatile("sfence" : : : "memory"); 89 asm volatile("sfence" : : : "memory");
90 kernel_fpu_end();
99} 91}
100 92
101const struct raid6_calls raid6_sse1x1 = { 93const struct raid6_calls raid6_sse1x1 = {
@@ -113,13 +105,12 @@ static void raid6_sse12_gen_syndrome(int disks, size_t bytes, void **ptrs)
113 u8 **dptr = (u8 **)ptrs; 105 u8 **dptr = (u8 **)ptrs;
114 u8 *p, *q; 106 u8 *p, *q;
115 int d, z, z0; 107 int d, z, z0;
116 raid6_mmx_save_t sa;
117 108
118 z0 = disks - 3; /* Highest data disk */ 109 z0 = disks - 3; /* Highest data disk */
119 p = dptr[z0+1]; /* XOR parity */ 110 p = dptr[z0+1]; /* XOR parity */
120 q = dptr[z0+2]; /* RS syndrome */ 111 q = dptr[z0+2]; /* RS syndrome */
121 112
122 raid6_before_mmx(&sa); 113 kernel_fpu_begin();
123 114
124 asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d)); 115 asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d));
125 asm volatile("pxor %mm5,%mm5"); /* Zero temp */ 116 asm volatile("pxor %mm5,%mm5"); /* Zero temp */
@@ -157,8 +148,8 @@ static void raid6_sse12_gen_syndrome(int disks, size_t bytes, void **ptrs)
157 asm volatile("movntq %%mm6,%0" : "=m" (q[d+8])); 148 asm volatile("movntq %%mm6,%0" : "=m" (q[d+8]));
158 } 149 }
159 150
160 raid6_after_mmx(&sa);
161 asm volatile("sfence" : :: "memory"); 151 asm volatile("sfence" : :: "memory");
152 kernel_fpu_end();
162} 153}
163 154
164const struct raid6_calls raid6_sse1x2 = { 155const struct raid6_calls raid6_sse1x2 = {
diff --git a/drivers/md/raid6sse2.c b/drivers/md/raid6sse2.c
index b3aa7fe087..0f019762a7 100644
--- a/drivers/md/raid6sse2.c
+++ b/drivers/md/raid6sse2.c
@@ -30,17 +30,11 @@ static const struct raid6_sse_constants {
30 30
31static int raid6_have_sse2(void) 31static int raid6_have_sse2(void)
32{ 32{
33#ifdef __KERNEL__
34 /* Not really boot_cpu but "all_cpus" */ 33 /* Not really boot_cpu but "all_cpus" */
35 return boot_cpu_has(X86_FEATURE_MMX) && 34 return boot_cpu_has(X86_FEATURE_MMX) &&
36 boot_cpu_has(X86_FEATURE_FXSR) && 35 boot_cpu_has(X86_FEATURE_FXSR) &&
37 boot_cpu_has(X86_FEATURE_XMM) && 36 boot_cpu_has(X86_FEATURE_XMM) &&
38 boot_cpu_has(X86_FEATURE_XMM2); 37 boot_cpu_has(X86_FEATURE_XMM2);
39#else
40 /* User space test code */
41 u32 features = cpuid_features();
42 return ( (features & (15<<23)) == (15<<23) );
43#endif
44} 38}
45 39
46/* 40/*
@@ -51,13 +45,12 @@ static void raid6_sse21_gen_syndrome(int disks, size_t bytes, void **ptrs)
51 u8 **dptr = (u8 **)ptrs; 45 u8 **dptr = (u8 **)ptrs;
52 u8 *p, *q; 46 u8 *p, *q;
53 int d, z, z0; 47 int d, z, z0;
54 raid6_sse_save_t sa;
55 48
56 z0 = disks - 3; /* Highest data disk */ 49 z0 = disks - 3; /* Highest data disk */
57 p = dptr[z0+1]; /* XOR parity */ 50 p = dptr[z0+1]; /* XOR parity */
58 q = dptr[z0+2]; /* RS syndrome */ 51 q = dptr[z0+2]; /* RS syndrome */
59 52
60 raid6_before_sse2(&sa); 53 kernel_fpu_begin();
61 54
62 asm volatile("movdqa %0,%%xmm0" : : "m" (raid6_sse_constants.x1d[0])); 55 asm volatile("movdqa %0,%%xmm0" : : "m" (raid6_sse_constants.x1d[0]));
63 asm volatile("pxor %xmm5,%xmm5"); /* Zero temp */ 56 asm volatile("pxor %xmm5,%xmm5"); /* Zero temp */
@@ -93,8 +86,8 @@ static void raid6_sse21_gen_syndrome(int disks, size_t bytes, void **ptrs)
93 asm volatile("pxor %xmm4,%xmm4"); 86 asm volatile("pxor %xmm4,%xmm4");
94 } 87 }
95 88
96 raid6_after_sse2(&sa);
97 asm volatile("sfence" : : : "memory"); 89 asm volatile("sfence" : : : "memory");
90 kernel_fpu_end();
98} 91}
99 92
100const struct raid6_calls raid6_sse2x1 = { 93const struct raid6_calls raid6_sse2x1 = {
@@ -112,13 +105,12 @@ static void raid6_sse22_gen_syndrome(int disks, size_t bytes, void **ptrs)
112 u8 **dptr = (u8 **)ptrs; 105 u8 **dptr = (u8 **)ptrs;
113 u8 *p, *q; 106 u8 *p, *q;
114 int d, z, z0; 107 int d, z, z0;
115 raid6_sse_save_t sa;
116 108
117 z0 = disks - 3; /* Highest data disk */ 109 z0 = disks - 3; /* Highest data disk */
118 p = dptr[z0+1]; /* XOR parity */ 110 p = dptr[z0+1]; /* XOR parity */
119 q = dptr[z0+2]; /* RS syndrome */ 111 q = dptr[z0+2]; /* RS syndrome */
120 112
121 raid6_before_sse2(&sa); 113 kernel_fpu_begin();
122 114
123 asm volatile("movdqa %0,%%xmm0" : : "m" (raid6_sse_constants.x1d[0])); 115 asm volatile("movdqa %0,%%xmm0" : : "m" (raid6_sse_constants.x1d[0]));
124 asm volatile("pxor %xmm5,%xmm5"); /* Zero temp */ 116 asm volatile("pxor %xmm5,%xmm5"); /* Zero temp */
@@ -156,8 +148,8 @@ static void raid6_sse22_gen_syndrome(int disks, size_t bytes, void **ptrs)
156 asm volatile("movntdq %%xmm6,%0" : "=m" (q[d+16])); 148 asm volatile("movntdq %%xmm6,%0" : "=m" (q[d+16]));
157 } 149 }
158 150
159 raid6_after_sse2(&sa);
160 asm volatile("sfence" : : : "memory"); 151 asm volatile("sfence" : : : "memory");
152 kernel_fpu_end();
161} 153}
162 154
163const struct raid6_calls raid6_sse2x2 = { 155const struct raid6_calls raid6_sse2x2 = {
@@ -179,13 +171,12 @@ static void raid6_sse24_gen_syndrome(int disks, size_t bytes, void **ptrs)
179 u8 **dptr = (u8 **)ptrs; 171 u8 **dptr = (u8 **)ptrs;
180 u8 *p, *q; 172 u8 *p, *q;
181 int d, z, z0; 173 int d, z, z0;
182 raid6_sse16_save_t sa;
183 174
184 z0 = disks - 3; /* Highest data disk */ 175 z0 = disks - 3; /* Highest data disk */
185 p = dptr[z0+1]; /* XOR parity */ 176 p = dptr[z0+1]; /* XOR parity */
186 q = dptr[z0+2]; /* RS syndrome */ 177 q = dptr[z0+2]; /* RS syndrome */
187 178
188 raid6_before_sse16(&sa); 179 kernel_fpu_begin();
189 180
190 asm volatile("movdqa %0,%%xmm0" :: "m" (raid6_sse_constants.x1d[0])); 181 asm volatile("movdqa %0,%%xmm0" :: "m" (raid6_sse_constants.x1d[0]));
191 asm volatile("pxor %xmm2,%xmm2"); /* P[0] */ 182 asm volatile("pxor %xmm2,%xmm2"); /* P[0] */
@@ -256,8 +247,9 @@ static void raid6_sse24_gen_syndrome(int disks, size_t bytes, void **ptrs)
256 asm volatile("movntdq %%xmm14,%0" : "=m" (q[d+48])); 247 asm volatile("movntdq %%xmm14,%0" : "=m" (q[d+48]));
257 asm volatile("pxor %xmm14,%xmm14"); 248 asm volatile("pxor %xmm14,%xmm14");
258 } 249 }
250
259 asm volatile("sfence" : : : "memory"); 251 asm volatile("sfence" : : : "memory");
260 raid6_after_sse16(&sa); 252 kernel_fpu_end();
261} 253}
262 254
263const struct raid6_calls raid6_sse2x4 = { 255const struct raid6_calls raid6_sse2x4 = {
diff --git a/drivers/md/raid6x86.h b/drivers/md/raid6x86.h
index 4cf20534fe..9111950414 100644
--- a/drivers/md/raid6x86.h
+++ b/drivers/md/raid6x86.h
@@ -21,224 +21,40 @@
21 21
22#if defined(__i386__) || defined(__x86_64__) 22#if defined(__i386__) || defined(__x86_64__)
23 23
24#ifdef __x86_64__
25
26typedef struct {
27 unsigned int fsave[27];
28 unsigned long cr0;
29} raid6_mmx_save_t __attribute__((aligned(16)));
30
31/* N.B.: For SSE we only save %xmm0-%xmm7 even for x86-64, since
32 the code doesn't know about the additional x86-64 registers */
33typedef struct {
34 unsigned int sarea[8*4+2];
35 unsigned long cr0;
36} raid6_sse_save_t __attribute__((aligned(16)));
37
38/* This is for x86-64-specific code which uses all 16 XMM registers */
39typedef struct {
40 unsigned int sarea[16*4+2];
41 unsigned long cr0;
42} raid6_sse16_save_t __attribute__((aligned(16)));
43
44/* On x86-64 the stack *SHOULD* be 16-byte aligned, but currently this
45 is buggy in the kernel and it's only 8-byte aligned in places, so
46 we need to do this anyway. Sigh. */
47#define SAREA(x) ((unsigned int *)((((unsigned long)&(x)->sarea)+15) & ~15))
48
49#else /* __i386__ */
50
51typedef struct {
52 unsigned int fsave[27];
53 unsigned long cr0;
54} raid6_mmx_save_t;
55
56/* On i386, the stack is only 8-byte aligned, but SSE requires 16-byte
57 alignment. The +3 is so we have the slack space to manually align
58 a properly-sized area correctly. */
59typedef struct {
60 unsigned int sarea[8*4+3];
61 unsigned long cr0;
62} raid6_sse_save_t;
63
64/* Find the 16-byte aligned save area */
65#define SAREA(x) ((unsigned int *)((((unsigned long)&(x)->sarea)+15) & ~15))
66
67#endif
68
69#ifdef __KERNEL__ /* Real code */ 24#ifdef __KERNEL__ /* Real code */
70 25
71/* Note: %cr0 is 32 bits on i386 and 64 bits on x86-64 */ 26#include <asm/i387.h>
72
73static inline unsigned long raid6_get_fpu(void)
74{
75 unsigned long cr0;
76
77 preempt_disable();
78 asm volatile("mov %%cr0,%0 ; clts" : "=r" (cr0));
79 return cr0;
80}
81
82static inline void raid6_put_fpu(unsigned long cr0)
83{
84 asm volatile("mov %0,%%cr0" : : "r" (cr0));
85 preempt_enable();
86}
87 27
88#else /* Dummy code for user space testing */ 28#else /* Dummy code for user space testing */
89 29
90static inline unsigned long raid6_get_fpu(void) 30static inline void kernel_fpu_begin(void)
91{
92 return 0xf00ba6;
93}
94
95static inline void raid6_put_fpu(unsigned long cr0)
96{
97 (void)cr0;
98}
99
100#endif
101
102static inline void raid6_before_mmx(raid6_mmx_save_t *s)
103{
104 s->cr0 = raid6_get_fpu();
105 asm volatile("fsave %0 ; fwait" : "=m" (s->fsave[0]));
106}
107
108static inline void raid6_after_mmx(raid6_mmx_save_t *s)
109{
110 asm volatile("frstor %0" : : "m" (s->fsave[0]));
111 raid6_put_fpu(s->cr0);
112}
113
114static inline void raid6_before_sse(raid6_sse_save_t *s)
115{
116 unsigned int *rsa = SAREA(s);
117
118 s->cr0 = raid6_get_fpu();
119
120 asm volatile("movaps %%xmm0,%0" : "=m" (rsa[0]));
121 asm volatile("movaps %%xmm1,%0" : "=m" (rsa[4]));
122 asm volatile("movaps %%xmm2,%0" : "=m" (rsa[8]));
123 asm volatile("movaps %%xmm3,%0" : "=m" (rsa[12]));
124 asm volatile("movaps %%xmm4,%0" : "=m" (rsa[16]));
125 asm volatile("movaps %%xmm5,%0" : "=m" (rsa[20]));
126 asm volatile("movaps %%xmm6,%0" : "=m" (rsa[24]));
127 asm volatile("movaps %%xmm7,%0" : "=m" (rsa[28]));
128}
129
130static inline void raid6_after_sse(raid6_sse_save_t *s)
131{
132 unsigned int *rsa = SAREA(s);
133
134 asm volatile("movaps %0,%%xmm0" : : "m" (rsa[0]));
135 asm volatile("movaps %0,%%xmm1" : : "m" (rsa[4]));
136 asm volatile("movaps %0,%%xmm2" : : "m" (rsa[8]));
137 asm volatile("movaps %0,%%xmm3" : : "m" (rsa[12]));
138 asm volatile("movaps %0,%%xmm4" : : "m" (rsa[16]));
139 asm volatile("movaps %0,%%xmm5" : : "m" (rsa[20]));
140 asm volatile("movaps %0,%%xmm6" : : "m" (rsa[24]));
141 asm volatile("movaps %0,%%xmm7" : : "m" (rsa[28]));
142
143 raid6_put_fpu(s->cr0);
144}
145
146static inline void raid6_before_sse2(raid6_sse_save_t *s)
147{ 31{
148 unsigned int *rsa = SAREA(s);
149
150 s->cr0 = raid6_get_fpu();
151
152 asm volatile("movdqa %%xmm0,%0" : "=m" (rsa[0]));
153 asm volatile("movdqa %%xmm1,%0" : "=m" (rsa[4]));
154 asm volatile("movdqa %%xmm2,%0" : "=m" (rsa[8]));
155 asm volatile("movdqa %%xmm3,%0" : "=m" (rsa[12]));
156 asm volatile("movdqa %%xmm4,%0" : "=m" (rsa[16]));
157 asm volatile("movdqa %%xmm5,%0" : "=m" (rsa[20]));
158 asm volatile("movdqa %%xmm6,%0" : "=m" (rsa[24]));
159 asm volatile("movdqa %%xmm7,%0" : "=m" (rsa[28]));
160} 32}
161 33
162static inline void raid6_after_sse2(raid6_sse_save_t *s) 34static inline void kernel_fpu_end(void)
163{ 35{
164 unsigned int *rsa = SAREA(s);
165
166 asm volatile("movdqa %0,%%xmm0" : : "m" (rsa[0]));
167 asm volatile("movdqa %0,%%xmm1" : : "m" (rsa[4]));
168 asm volatile("movdqa %0,%%xmm2" : : "m" (rsa[8]));
169 asm volatile("movdqa %0,%%xmm3" : : "m" (rsa[12]));
170 asm volatile("movdqa %0,%%xmm4" : : "m" (rsa[16]));
171 asm volatile("movdqa %0,%%xmm5" : : "m" (rsa[20]));
172 asm volatile("movdqa %0,%%xmm6" : : "m" (rsa[24]));
173 asm volatile("movdqa %0,%%xmm7" : : "m" (rsa[28]));
174
175 raid6_put_fpu(s->cr0);
176} 36}
177 37
178#ifdef __x86_64__ 38#define X86_FEATURE_MMX (0*32+23) /* Multimedia Extensions */
179 39#define X86_FEATURE_FXSR (0*32+24) /* FXSAVE and FXRSTOR instructions
180static inline void raid6_before_sse16(raid6_sse16_save_t *s) 40 * (fast save and restore) */
181{ 41#define X86_FEATURE_XMM (0*32+25) /* Streaming SIMD Extensions */
182 unsigned int *rsa = SAREA(s); 42#define X86_FEATURE_XMM2 (0*32+26) /* Streaming SIMD Extensions-2 */
183 43#define X86_FEATURE_MMXEXT (1*32+22) /* AMD MMX extensions */
184 s->cr0 = raid6_get_fpu();
185 44
186 asm volatile("movdqa %%xmm0,%0" : "=m" (rsa[0])); 45/* Should work well enough on modern CPUs for testing */
187 asm volatile("movdqa %%xmm1,%0" : "=m" (rsa[4])); 46static inline int boot_cpu_has(int flag)
188 asm volatile("movdqa %%xmm2,%0" : "=m" (rsa[8]));
189 asm volatile("movdqa %%xmm3,%0" : "=m" (rsa[12]));
190 asm volatile("movdqa %%xmm4,%0" : "=m" (rsa[16]));
191 asm volatile("movdqa %%xmm5,%0" : "=m" (rsa[20]));
192 asm volatile("movdqa %%xmm6,%0" : "=m" (rsa[24]));
193 asm volatile("movdqa %%xmm7,%0" : "=m" (rsa[28]));
194 asm volatile("movdqa %%xmm8,%0" : "=m" (rsa[32]));
195 asm volatile("movdqa %%xmm9,%0" : "=m" (rsa[36]));
196 asm volatile("movdqa %%xmm10,%0" : "=m" (rsa[40]));
197 asm volatile("movdqa %%xmm11,%0" : "=m" (rsa[44]));
198 asm volatile("movdqa %%xmm12,%0" : "=m" (rsa[48]));
199 asm volatile("movdqa %%xmm13,%0" : "=m" (rsa[52]));
200 asm volatile("movdqa %%xmm14,%0" : "=m" (rsa[56]));
201 asm volatile("movdqa %%xmm15,%0" : "=m" (rsa[60]));
202}
203
204static inline void raid6_after_sse16(raid6_sse16_save_t *s)
205{ 47{
206 unsigned int *rsa = SAREA(s); 48 u32 eax = (flag >> 5) ? 0x80000001 : 1;
49 u32 edx;
207 50
208 asm volatile("movdqa %0,%%xmm0" : : "m" (rsa[0])); 51 asm volatile("cpuid"
209 asm volatile("movdqa %0,%%xmm1" : : "m" (rsa[4])); 52 : "+a" (eax), "=d" (edx)
210 asm volatile("movdqa %0,%%xmm2" : : "m" (rsa[8])); 53 : : "ecx", "ebx");
211 asm volatile("movdqa %0,%%xmm3" : : "m" (rsa[12]));
212 asm volatile("movdqa %0,%%xmm4" : : "m" (rsa[16]));
213 asm volatile("movdqa %0,%%xmm5" : : "m" (rsa[20]));
214 asm volatile("movdqa %0,%%xmm6" : : "m" (rsa[24]));
215 asm volatile("movdqa %0,%%xmm7" : : "m" (rsa[28]));
216 asm volatile("movdqa %0,%%xmm8" : : "m" (rsa[32]));
217 asm volatile("movdqa %0,%%xmm9" : : "m" (rsa[36]));
218 asm volatile("movdqa %0,%%xmm10" : : "m" (rsa[40]));
219 asm volatile("movdqa %0,%%xmm11" : : "m" (rsa[44]));
220 asm volatile("movdqa %0,%%xmm12" : : "m" (rsa[48]));
221 asm volatile("movdqa %0,%%xmm13" : : "m" (rsa[52]));
222 asm volatile("movdqa %0,%%xmm14" : : "m" (rsa[56]));
223 asm volatile("movdqa %0,%%xmm15" : : "m" (rsa[60]));
224 54
225 raid6_put_fpu(s->cr0); 55 return (edx >> (flag & 31)) & 1;
226} 56}
227 57
228#endif /* __x86_64__ */
229
230/* User space test hack */
231#ifndef __KERNEL__
232static inline int cpuid_features(void)
233{
234 u32 eax = 1;
235 u32 ebx, ecx, edx;
236
237 asm volatile("cpuid" :
238 "+a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx));
239
240 return edx;
241}
242#endif /* ndef __KERNEL__ */ 58#endif /* ndef __KERNEL__ */
243 59
244#endif 60#endif
diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index 87410dbd3d..91d25798ae 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -70,6 +70,7 @@ config VIDEO_TUNER
70 depends on I2C 70 depends on I2C
71 71
72config VIDEO_BUF 72config VIDEO_BUF
73 depends on PCI
73 tristate 74 tristate
74 75
75config VIDEO_BUF_DVB 76config VIDEO_BUF_DVB
diff --git a/drivers/media/common/Kconfig b/drivers/media/common/Kconfig
index f33e5d9734..c120114c24 100644
--- a/drivers/media/common/Kconfig
+++ b/drivers/media/common/Kconfig
@@ -5,8 +5,4 @@ config VIDEO_SAA7146
5config VIDEO_SAA7146_VV 5config VIDEO_SAA7146_VV
6 tristate 6 tristate
7 select VIDEO_BUF 7 select VIDEO_BUF
8 select VIDEO_VIDEOBUF
9 select VIDEO_SAA7146 8 select VIDEO_SAA7146
10
11config VIDEO_VIDEOBUF
12 tristate
diff --git a/drivers/media/common/ir-functions.c b/drivers/media/common/ir-functions.c
index 9a8dd8764c..cbf7c05648 100644
--- a/drivers/media/common/ir-functions.c
+++ b/drivers/media/common/ir-functions.c
@@ -256,6 +256,112 @@ int ir_decode_biphase(u32 *samples, int count, int low, int high)
256 return value; 256 return value;
257} 257}
258 258
259/* RC5 decoding stuff, moved from bttv-input.c to share it with
260 * saa7134 */
261
262/* decode raw bit pattern to RC5 code */
263u32 ir_rc5_decode(unsigned int code)
264{
265 unsigned int org_code = code;
266 unsigned int pair;
267 unsigned int rc5 = 0;
268 int i;
269
270 for (i = 0; i < 14; ++i) {
271 pair = code & 0x3;
272 code >>= 2;
273
274 rc5 <<= 1;
275 switch (pair) {
276 case 0:
277 case 2:
278 break;
279 case 1:
280 rc5 |= 1;
281 break;
282 case 3:
283 dprintk(1, "ir-common: ir_rc5_decode(%x) bad code\n", org_code);
284 return 0;
285 }
286 }
287 dprintk(1, "ir-common: code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
288 "instr=%x\n", rc5, org_code, RC5_START(rc5),
289 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
290 return rc5;
291}
292
293void ir_rc5_timer_end(unsigned long data)
294{
295 struct card_ir *ir = (struct card_ir *)data;
296 struct timeval tv;
297 unsigned long current_jiffies, timeout;
298 u32 gap;
299 u32 rc5 = 0;
300
301 /* get time */
302 current_jiffies = jiffies;
303 do_gettimeofday(&tv);
304
305 /* avoid overflow with gap >1s */
306 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
307 gap = 200000;
308 } else {
309 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
310 tv.tv_usec - ir->base_time.tv_usec;
311 }
312
313 /* Allow some timmer jitter (RC5 is ~24ms anyway so this is ok) */
314 if (gap < 28000) {
315 dprintk(1, "ir-common: spurious timer_end\n");
316 return;
317 }
318
319 ir->active = 0;
320 if (ir->last_bit < 20) {
321 /* ignore spurious codes (caused by light/other remotes) */
322 dprintk(1, "ir-common: short code: %x\n", ir->code);
323 } else {
324 ir->code = (ir->code << ir->shift_by) | 1;
325 rc5 = ir_rc5_decode(ir->code);
326
327 /* two start bits? */
328 if (RC5_START(rc5) != ir->start) {
329 dprintk(1, "ir-common: rc5 start bits invalid: %u\n", RC5_START(rc5));
330
331 /* right address? */
332 } else if (RC5_ADDR(rc5) == ir->addr) {
333 u32 toggle = RC5_TOGGLE(rc5);
334 u32 instr = RC5_INSTR(rc5);
335
336 /* Good code, decide if repeat/repress */
337 if (toggle != RC5_TOGGLE(ir->last_rc5) ||
338 instr != RC5_INSTR(ir->last_rc5)) {
339 dprintk(1, "ir-common: instruction %x, toggle %x\n", instr,
340 toggle);
341 ir_input_nokey(ir->dev, &ir->ir);
342 ir_input_keydown(ir->dev, &ir->ir, instr,
343 instr);
344 }
345
346 /* Set/reset key-up timer */
347 timeout = current_jiffies + (500 + ir->rc5_key_timeout
348 * HZ) / 1000;
349 mod_timer(&ir->timer_keyup, timeout);
350
351 /* Save code for repeat test */
352 ir->last_rc5 = rc5;
353 }
354 }
355}
356
357void ir_rc5_timer_keyup(unsigned long data)
358{
359 struct card_ir *ir = (struct card_ir *)data;
360
361 dprintk(1, "ir-common: key released\n");
362 ir_input_nokey(ir->dev, &ir->ir);
363}
364
259EXPORT_SYMBOL_GPL(ir_input_init); 365EXPORT_SYMBOL_GPL(ir_input_init);
260EXPORT_SYMBOL_GPL(ir_input_nokey); 366EXPORT_SYMBOL_GPL(ir_input_nokey);
261EXPORT_SYMBOL_GPL(ir_input_keydown); 367EXPORT_SYMBOL_GPL(ir_input_keydown);
@@ -265,6 +371,10 @@ EXPORT_SYMBOL_GPL(ir_dump_samples);
265EXPORT_SYMBOL_GPL(ir_decode_biphase); 371EXPORT_SYMBOL_GPL(ir_decode_biphase);
266EXPORT_SYMBOL_GPL(ir_decode_pulsedistance); 372EXPORT_SYMBOL_GPL(ir_decode_pulsedistance);
267 373
374EXPORT_SYMBOL_GPL(ir_rc5_decode);
375EXPORT_SYMBOL_GPL(ir_rc5_timer_end);
376EXPORT_SYMBOL_GPL(ir_rc5_timer_keyup);
377
268/* 378/*
269 * Local variables: 379 * Local variables:
270 * c-basic-offset: 8 380 * c-basic-offset: 8
diff --git a/drivers/media/common/ir-keymaps.c b/drivers/media/common/ir-keymaps.c
index 0e948a5c5a..03b47a262f 100644
--- a/drivers/media/common/ir-keymaps.c
+++ b/drivers/media/common/ir-keymaps.c
@@ -1606,3 +1606,174 @@ IR_KEYTAB_TYPE ir_codes_budget_ci_old[IR_KEYTAB_SIZE] = {
1606}; 1606};
1607 1607
1608EXPORT_SYMBOL_GPL(ir_codes_budget_ci_old); 1608EXPORT_SYMBOL_GPL(ir_codes_budget_ci_old);
1609
1610/*
1611 * Marc Fargas <telenieko@telenieko.com>
1612 * this is the remote control that comes with the asus p7131
1613 * which has a label saying is "Model PC-39"
1614 */
1615IR_KEYTAB_TYPE ir_codes_asus_pc39[IR_KEYTAB_SIZE] = {
1616 /* Keys 0 to 9 */
1617 [ 0x15 ] = KEY_0,
1618 [ 0x29 ] = KEY_1,
1619 [ 0x2d ] = KEY_2,
1620 [ 0x2b ] = KEY_3,
1621 [ 0x09 ] = KEY_4,
1622 [ 0x0d ] = KEY_5,
1623 [ 0x0b ] = KEY_6,
1624 [ 0x31 ] = KEY_7,
1625 [ 0x35 ] = KEY_8,
1626 [ 0x33 ] = KEY_9,
1627
1628 [ 0x3e ] = KEY_RADIO, /* radio */
1629 [ 0x03 ] = KEY_MENU, /* dvd/menu */
1630 [ 0x2a ] = KEY_VOLUMEUP,
1631 [ 0x19 ] = KEY_VOLUMEDOWN,
1632 [ 0x37 ] = KEY_UP,
1633 [ 0x3b ] = KEY_DOWN,
1634 [ 0x27 ] = KEY_LEFT,
1635 [ 0x2f ] = KEY_RIGHT,
1636 [ 0x25 ] = KEY_VIDEO, /* video */
1637 [ 0x39 ] = KEY_AUDIO, /* music */
1638
1639 [ 0x21 ] = KEY_TV, /* tv */
1640 [ 0x1d ] = KEY_EXIT, /* back */
1641 [ 0x0a ] = KEY_CHANNELUP, /* channel / program + */
1642 [ 0x1b ] = KEY_CHANNELDOWN, /* channel / program - */
1643 [ 0x1a ] = KEY_ENTER, /* enter */
1644
1645 [ 0x06 ] = KEY_PAUSE, /* play/pause */
1646 [ 0x1e ] = KEY_PREVIOUS, /* rew */
1647 [ 0x26 ] = KEY_NEXT, /* forward */
1648 [ 0x0e ] = KEY_REWIND, /* backward << */
1649 [ 0x3a ] = KEY_FASTFORWARD, /* forward >> */
1650 [ 0x36 ] = KEY_STOP,
1651 [ 0x2e ] = KEY_RECORD, /* recording */
1652 [ 0x16 ] = KEY_POWER, /* the button that reads "close" */
1653
1654 [ 0x11 ] = KEY_ZOOM, /* full screen */
1655 [ 0x13 ] = KEY_MACRO, /* recall */
1656 [ 0x23 ] = KEY_HOME, /* home */
1657 [ 0x05 ] = KEY_PVR, /* picture */
1658 [ 0x3d ] = KEY_MUTE, /* mute */
1659 [ 0x01 ] = KEY_DVD, /* dvd */
1660};
1661
1662EXPORT_SYMBOL_GPL(ir_codes_asus_pc39);
1663
1664
1665/* Encore ENLTV-FM - black plastic, white front cover with white glowing buttons
1666 Juan Pablo Sormani <sorman@gmail.com> */
1667IR_KEYTAB_TYPE ir_codes_encore_enltv[IR_KEYTAB_SIZE] = {
1668
1669 /* Power button does nothing, neither in Windows app,
1670 although it sends data (used for BIOS wakeup?) */
1671 [ 0x0d ] = KEY_MUTE,
1672
1673 [ 0x1e ] = KEY_TV,
1674 [ 0x00 ] = KEY_VIDEO,
1675 [ 0x01 ] = KEY_AUDIO, /* music */
1676 [ 0x02 ] = KEY_MHP, /* picture */
1677
1678 [ 0x1f ] = KEY_1,
1679 [ 0x03 ] = KEY_2,
1680 [ 0x04 ] = KEY_3,
1681 [ 0x05 ] = KEY_4,
1682 [ 0x1c ] = KEY_5,
1683 [ 0x06 ] = KEY_6,
1684 [ 0x07 ] = KEY_7,
1685 [ 0x08 ] = KEY_8,
1686 [ 0x1d ] = KEY_9,
1687 [ 0x0a ] = KEY_0,
1688
1689 [ 0x09 ] = KEY_LIST, /* -/-- */
1690 [ 0x0b ] = KEY_LAST, /* recall */
1691
1692 [ 0x14 ] = KEY_HOME, /* win start menu */
1693 [ 0x15 ] = KEY_EXIT, /* exit */
1694 [ 0x16 ] = KEY_UP,
1695 [ 0x12 ] = KEY_DOWN,
1696 [ 0x0c ] = KEY_RIGHT,
1697 [ 0x17 ] = KEY_LEFT,
1698
1699 [ 0x18 ] = KEY_ENTER, /* OK */
1700
1701 [ 0x0e ] = KEY_ESC,
1702 [ 0x13 ] = KEY_D, /* desktop */
1703 [ 0x11 ] = KEY_TAB,
1704 [ 0x19 ] = KEY_SWITCHVIDEOMODE, /* switch */
1705
1706 [ 0x1a ] = KEY_MENU,
1707 [ 0x1b ] = KEY_ZOOM, /* fullscreen */
1708 [ 0x44 ] = KEY_TIME, /* time shift */
1709 [ 0x40 ] = KEY_MODE, /* source */
1710
1711 [ 0x5a ] = KEY_RECORD,
1712 [ 0x42 ] = KEY_PLAY, /* play/pause */
1713 [ 0x45 ] = KEY_STOP,
1714 [ 0x43 ] = KEY_CAMERA, /* camera icon */
1715
1716 [ 0x48 ] = KEY_REWIND,
1717 [ 0x4a ] = KEY_FASTFORWARD,
1718 [ 0x49 ] = KEY_PREVIOUS,
1719 [ 0x4b ] = KEY_NEXT,
1720
1721 [ 0x4c ] = KEY_FAVORITES, /* tv wall */
1722 [ 0x4d ] = KEY_SOUND, /* DVD sound */
1723 [ 0x4e ] = KEY_LANGUAGE, /* DVD lang */
1724 [ 0x4f ] = KEY_TEXT, /* DVD text */
1725
1726 [ 0x50 ] = KEY_SLEEP, /* shutdown */
1727 [ 0x51 ] = KEY_MODE, /* stereo > main */
1728 [ 0x52 ] = KEY_SELECT, /* stereo > sap */
1729 [ 0x53 ] = KEY_PROG1, /* teletext */
1730
1731
1732 [ 0x59 ] = KEY_RED, /* AP1 */
1733 [ 0x41 ] = KEY_GREEN, /* AP2 */
1734 [ 0x47 ] = KEY_YELLOW, /* AP3 */
1735 [ 0x57 ] = KEY_BLUE, /* AP4 */
1736
1737
1738};
1739
1740EXPORT_SYMBOL_GPL(ir_codes_encore_enltv);
1741
1742/* for the Technotrend 1500 bundled remote: */
1743IR_KEYTAB_TYPE ir_codes_tt_1500[IR_KEYTAB_SIZE] = {
1744 [ 0x01 ] = KEY_POWER,
1745 [ 0x02 ] = KEY_SHUFFLE, /* ? double-arrow key */
1746 [ 0x03 ] = KEY_1,
1747 [ 0x04 ] = KEY_2,
1748 [ 0x05 ] = KEY_3,
1749 [ 0x06 ] = KEY_4,
1750 [ 0x07 ] = KEY_5,
1751 [ 0x08 ] = KEY_6,
1752 [ 0x09 ] = KEY_7,
1753 [ 0x0a ] = KEY_8,
1754 [ 0x0b ] = KEY_9,
1755 [ 0x0c ] = KEY_0,
1756 [ 0x0d ] = KEY_UP,
1757 [ 0x0e ] = KEY_LEFT,
1758 [ 0x0f ] = KEY_OK,
1759 [ 0x10 ] = KEY_RIGHT,
1760 [ 0x11 ] = KEY_DOWN,
1761 [ 0x12 ] = KEY_INFO,
1762 [ 0x13 ] = KEY_EXIT,
1763 [ 0x14 ] = KEY_RED,
1764 [ 0x15 ] = KEY_GREEN,
1765 [ 0x16 ] = KEY_YELLOW,
1766 [ 0x17 ] = KEY_BLUE,
1767 [ 0x18 ] = KEY_MUTE,
1768 [ 0x19 ] = KEY_TEXT,
1769 [ 0x1a ] = KEY_MODE, /* ? TV/Radio */
1770 [ 0x21 ] = KEY_OPTION,
1771 [ 0x22 ] = KEY_EPG,
1772 [ 0x23 ] = KEY_CHANNELUP,
1773 [ 0x24 ] = KEY_CHANNELDOWN,
1774 [ 0x25 ] = KEY_VOLUMEUP,
1775 [ 0x26 ] = KEY_VOLUMEDOWN,
1776 [ 0x27 ] = KEY_SETUP,
1777};
1778
1779EXPORT_SYMBOL_GPL(ir_codes_tt_1500);
diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c
index b8dcfa1652..c18a5da649 100644
--- a/drivers/media/common/saa7146_fops.c
+++ b/drivers/media/common/saa7146_fops.c
@@ -508,7 +508,7 @@ int saa7146_vv_release(struct saa7146_dev* dev)
508 508
509 DEB_EE(("dev:%p\n",dev)); 509 DEB_EE(("dev:%p\n",dev));
510 510
511 pci_free_consistent(dev->pci, SAA7146_RPS_MEM, vv->d_clipping.cpu_addr, vv->d_clipping.dma_handle); 511 pci_free_consistent(dev->pci, SAA7146_CLIPPING_MEM, vv->d_clipping.cpu_addr, vv->d_clipping.dma_handle);
512 kfree(vv); 512 kfree(vv);
513 dev->vv_data = NULL; 513 dev->vv_data = NULL;
514 dev->vv_callback = NULL; 514 dev->vv_callback = NULL;
diff --git a/drivers/media/dvb/b2c2/flexcop-fe-tuner.c b/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
index c2b35e3662..752cf79c53 100644
--- a/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
+++ b/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
@@ -385,9 +385,9 @@ static int alps_tdee4_stv0297_tuner_set_params(struct dvb_frontend* fe,
385 else buf[3] = 0x88; 385 else buf[3] = 0x88;
386 386
387 if (fe->ops.i2c_gate_ctrl) 387 if (fe->ops.i2c_gate_ctrl)
388 fe->ops.i2c_gate_ctrl(fe, 1); 388 fe->ops.i2c_gate_ctrl(fe, 0);
389 deb_tuner("tuner buffer for %d Hz: %x %x %x %x\n",fep->frequency, buf[0],buf[1],buf[2],buf[3]); 389 deb_tuner("tuner buffer for %d Hz: %x %x %x %x\n",fep->frequency, buf[0],buf[1],buf[2],buf[3]);
390 ret = fc->i2c_request(fc,FC_WRITE,FC_I2C_PORT_TUNER,0x61,buf[0],&buf[1],3); 390 ret = fc->i2c_request(fc, FC_WRITE, FC_I2C_PORT_TUNER, 0x61, buf[0], &buf[1], 3);
391 deb_tuner("tuner write returned: %d\n",ret); 391 deb_tuner("tuner write returned: %d\n",ret);
392 392
393 return 0; 393 return 0;
@@ -398,91 +398,71 @@ static u8 alps_tdee4_stv0297_inittab[] = {
398 0x80, 0x00, 398 0x80, 0x00,
399 0x81, 0x01, 399 0x81, 0x01,
400 0x81, 0x00, 400 0x81, 0x00,
401 0x00, 0x09, 401 0x00, 0x48,
402 0x01, 0x69, 402 0x01, 0x58,
403 0x03, 0x00, 403 0x03, 0x00,
404 0x04, 0x00, 404 0x04, 0x00,
405 0x07, 0x00, 405 0x07, 0x00,
406 0x08, 0x00, 406 0x08, 0x00,
407 0x20, 0x00,
408 0x21, 0x40,
409 0x22, 0x00,
410 0x23, 0x00,
411 0x24, 0x40,
412 0x25, 0x88,
413 0x30, 0xff, 407 0x30, 0xff,
414 0x31, 0x00, 408 0x31, 0x9d,
415 0x32, 0xff, 409 0x32, 0xff,
416 0x33, 0x00, 410 0x33, 0x00,
417 0x34, 0x50, 411 0x34, 0x29,
418 0x35, 0x7f, 412 0x35, 0x55,
419 0x36, 0x00, 413 0x36, 0x80,
420 0x37, 0x20, 414 0x37, 0x6e,
421 0x38, 0x00, 415 0x38, 0x9c,
422 0x40, 0x1c, 416 0x40, 0x1a,
423 0x41, 0xff, 417 0x41, 0xfe,
424 0x42, 0x29, 418 0x42, 0x33,
425 0x43, 0x00, 419 0x43, 0x00,
426 0x44, 0xff, 420 0x44, 0xff,
427 0x45, 0x00, 421 0x45, 0x00,
428 0x46, 0x00, 422 0x46, 0x00,
429 0x49, 0x04, 423 0x49, 0x04,
430 0x4a, 0x00, 424 0x4a, 0x51,
431 0x4b, 0xf8, 425 0x4b, 0xf8,
432 0x52, 0x30, 426 0x52, 0x30,
433 0x55, 0xae, 427 0x53, 0x06,
434 0x56, 0x47, 428 0x59, 0x06,
435 0x57, 0xe1, 429 0x5a, 0x5e,
436 0x58, 0x3a, 430 0x5b, 0x04,
437 0x5a, 0x1e, 431 0x61, 0x49,
438 0x5b, 0x34, 432 0x62, 0x0a,
439 0x60, 0x00,
440 0x63, 0x00,
441 0x64, 0x00,
442 0x65, 0x00,
443 0x66, 0x00,
444 0x67, 0x00,
445 0x68, 0x00,
446 0x69, 0x00,
447 0x6a, 0x02,
448 0x6b, 0x00,
449 0x70, 0xff, 433 0x70, 0xff,
450 0x71, 0x00, 434 0x71, 0x04,
451 0x72, 0x00, 435 0x72, 0x00,
452 0x73, 0x00, 436 0x73, 0x00,
453 0x74, 0x0c, 437 0x74, 0x0c,
454 0x80, 0x00, 438 0x80, 0x20,
455 0x81, 0x00, 439 0x81, 0x00,
456 0x82, 0x00, 440 0x82, 0x30,
457 0x83, 0x00, 441 0x83, 0x00,
458 0x84, 0x04, 442 0x84, 0x04,
459 0x85, 0x80, 443 0x85, 0x22,
460 0x86, 0x24, 444 0x86, 0x08,
461 0x87, 0x78, 445 0x87, 0x1b,
462 0x88, 0x10, 446 0x88, 0x00,
463 0x89, 0x00, 447 0x89, 0x00,
464 0x90, 0x01, 448 0x90, 0x00,
465 0x91, 0x01, 449 0x91, 0x04,
466 0xa0, 0x04, 450 0xa0, 0x86,
467 0xa1, 0x00, 451 0xa1, 0x00,
468 0xa2, 0x00, 452 0xa2, 0x00,
469 0xb0, 0x91, 453 0xb0, 0x91,
470 0xb1, 0x0b, 454 0xb1, 0x0b,
471 0xc0, 0x53, 455 0xc0, 0x5b,
472 0xc1, 0x70, 456 0xc1, 0x10,
473 0xc2, 0x12, 457 0xc2, 0x12,
474 0xd0, 0x00, 458 0xd0, 0x02,
475 0xd1, 0x00, 459 0xd1, 0x00,
476 0xd2, 0x00, 460 0xd2, 0x00,
477 0xd3, 0x00, 461 0xd3, 0x00,
478 0xd4, 0x00, 462 0xd4, 0x02,
479 0xd5, 0x00, 463 0xd5, 0x00,
480 0xde, 0x00, 464 0xde, 0x00,
481 0xdf, 0x00, 465 0xdf, 0x01,
482 0x61, 0x49,
483 0x62, 0x0b,
484 0x53, 0x08,
485 0x59, 0x08,
486 0xff, 0xff, 466 0xff, 0xff,
487}; 467};
488 468
diff --git a/drivers/media/dvb/bt8xx/bt878.c b/drivers/media/dvb/bt8xx/bt878.c
index 329a51c185..83b090ef24 100644
--- a/drivers/media/dvb/bt8xx/bt878.c
+++ b/drivers/media/dvb/bt8xx/bt878.c
@@ -390,6 +390,7 @@ static struct cards card_list[] __devinitdata = {
390 { 0xfc00270f, BTTV_BOARD_TWINHAN_DST, "ChainTech digitop DST-1000 DVB-S" }, 390 { 0xfc00270f, BTTV_BOARD_TWINHAN_DST, "ChainTech digitop DST-1000 DVB-S" },
391 { 0x07711461, BTTV_BOARD_AVDVBT_771, "AVermedia AverTV DVB-T 771" }, 391 { 0x07711461, BTTV_BOARD_AVDVBT_771, "AVermedia AverTV DVB-T 771" },
392 { 0xdb1018ac, BTTV_BOARD_DVICO_DVBT_LITE, "DViCO FusionHDTV DVB-T Lite" }, 392 { 0xdb1018ac, BTTV_BOARD_DVICO_DVBT_LITE, "DViCO FusionHDTV DVB-T Lite" },
393 { 0xdb1118ac, BTTV_BOARD_DVICO_DVBT_LITE, "Ultraview DVB-T Lite" },
393 { 0xd50018ac, BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE, "DViCO FusionHDTV 5 Lite" }, 394 { 0xd50018ac, BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE, "DViCO FusionHDTV 5 Lite" },
394 { 0x20007063, BTTV_BOARD_PC_HDTV, "pcHDTV HD-2000 TV" }, 395 { 0x20007063, BTTV_BOARD_PC_HDTV, "pcHDTV HD-2000 TV" },
395 { 0x00261822, BTTV_BOARD_TWINHAN_DST, "DNTV Live! Mini" }, 396 { 0x00261822, BTTV_BOARD_TWINHAN_DST, "DNTV Live! Mini" },
diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index 9f72b7000c..0393a3d199 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -1161,7 +1161,7 @@ static int dst_get_device_id(struct dst_state *state)
1161 } 1161 }
1162 } 1162 }
1163 1163
1164 if (i >= sizeof (dst_tlist) / sizeof (dst_tlist [0])) { 1164 if (i >= ARRAY_SIZE(dst_tlist)) {
1165 dprintk(verbose, DST_ERROR, 1, "Unable to recognize %s or %s", &state->rxbuffer[0], &state->rxbuffer[1]); 1165 dprintk(verbose, DST_ERROR, 1, "Unable to recognize %s or %s", &state->rxbuffer[0], &state->rxbuffer[1]);
1166 dprintk(verbose, DST_ERROR, 1, "please email linux-dvb@linuxtv.org with this type in"); 1166 dprintk(verbose, DST_ERROR, 1, "please email linux-dvb@linuxtv.org with this type in");
1167 use_dst_type = DST_TYPE_IS_SAT; 1167 use_dst_type = DST_TYPE_IS_SAT;
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
index 3e35931af3..58f69f6ae3 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
@@ -23,6 +23,7 @@
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/kernel.h>
26#include <linux/device.h> 27#include <linux/device.h>
27#include <linux/delay.h> 28#include <linux/delay.h>
28#include <linux/slab.h> 29#include <linux/slab.h>
@@ -213,7 +214,7 @@ static int cx24108_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend
213 freq = 2150000; /* satellite IF is 950..2150MHz */ 214 freq = 2150000; /* satellite IF is 950..2150MHz */
214 215
215 /* decide which VCO to use for the input frequency */ 216 /* decide which VCO to use for the input frequency */
216 for(i=1;(i<sizeof(osci)/sizeof(osci[0]))&&(osci[i]<freq);i++); 217 for(i = 1; (i < ARRAY_SIZE(osci)) && (osci[i] < freq); i++);
217 printk("cx24108 debug: select vco #%d (f=%d)\n",i,freq); 218 printk("cx24108 debug: select vco #%d (f=%d)\n",i,freq);
218 band=bandsel[i]; 219 band=bandsel[i];
219 /* the gain values must be set by SetSymbolrate */ 220 /* the gain values must be set by SetSymbolrate */
diff --git a/drivers/media/dvb/cinergyT2/cinergyT2.c b/drivers/media/dvb/cinergyT2/cinergyT2.c
index d64b96cb0c..a6cbbdd262 100644
--- a/drivers/media/dvb/cinergyT2/cinergyT2.c
+++ b/drivers/media/dvb/cinergyT2/cinergyT2.c
@@ -819,6 +819,11 @@ static int cinergyt2_register_rc(struct cinergyt2 *cinergyt2)
819 set_bit(rc_keys[i + 2], input_dev->keybit); 819 set_bit(rc_keys[i + 2], input_dev->keybit);
820 input_dev->keycodesize = 0; 820 input_dev->keycodesize = 0;
821 input_dev->keycodemax = 0; 821 input_dev->keycodemax = 0;
822 input_dev->id.bustype = BUS_USB;
823 input_dev->id.vendor = cinergyt2->udev->descriptor.idVendor;
824 input_dev->id.product = cinergyt2->udev->descriptor.idProduct;
825 input_dev->id.version = 1;
826 input_dev->cdev.dev = &cinergyt2->udev->dev;
822 827
823 err = input_register_device(input_dev); 828 err = input_register_device(input_dev);
824 if (err) { 829 if (err) {
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index e85972222a..a21a894d3f 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -36,6 +36,7 @@
36#include <linux/list.h> 36#include <linux/list.h>
37#include <linux/freezer.h> 37#include <linux/freezer.h>
38#include <linux/jiffies.h> 38#include <linux/jiffies.h>
39#include <linux/kthread.h>
39#include <asm/processor.h> 40#include <asm/processor.h>
40 41
41#include "dvb_frontend.h" 42#include "dvb_frontend.h"
@@ -100,7 +101,7 @@ struct dvb_frontend_private {
100 struct semaphore sem; 101 struct semaphore sem;
101 struct list_head list_head; 102 struct list_head list_head;
102 wait_queue_head_t wait_queue; 103 wait_queue_head_t wait_queue;
103 pid_t thread_pid; 104 struct task_struct *thread;
104 unsigned long release_jiffies; 105 unsigned long release_jiffies;
105 unsigned int exit; 106 unsigned int exit;
106 unsigned int wakeup; 107 unsigned int wakeup;
@@ -508,19 +509,11 @@ static int dvb_frontend_thread(void *data)
508 struct dvb_frontend *fe = data; 509 struct dvb_frontend *fe = data;
509 struct dvb_frontend_private *fepriv = fe->frontend_priv; 510 struct dvb_frontend_private *fepriv = fe->frontend_priv;
510 unsigned long timeout; 511 unsigned long timeout;
511 char name [15];
512 fe_status_t s; 512 fe_status_t s;
513 struct dvb_frontend_parameters *params; 513 struct dvb_frontend_parameters *params;
514 514
515 dprintk("%s\n", __FUNCTION__); 515 dprintk("%s\n", __FUNCTION__);
516 516
517 snprintf (name, sizeof(name), "kdvb-fe-%i", fe->dvb->num);
518
519 lock_kernel();
520 daemonize(name);
521 sigfillset(&current->blocked);
522 unlock_kernel();
523
524 fepriv->check_wrapped = 0; 517 fepriv->check_wrapped = 0;
525 fepriv->quality = 0; 518 fepriv->quality = 0;
526 fepriv->delay = 3*HZ; 519 fepriv->delay = 3*HZ;
@@ -532,16 +525,18 @@ static int dvb_frontend_thread(void *data)
532 525
533 while (1) { 526 while (1) {
534 up(&fepriv->sem); /* is locked when we enter the thread... */ 527 up(&fepriv->sem); /* is locked when we enter the thread... */
535 528restart:
536 timeout = wait_event_interruptible_timeout(fepriv->wait_queue, 529 timeout = wait_event_interruptible_timeout(fepriv->wait_queue,
537 dvb_frontend_should_wakeup(fe), 530 dvb_frontend_should_wakeup(fe) || kthread_should_stop(),
538 fepriv->delay); 531 fepriv->delay);
539 if (0 != dvb_frontend_is_exiting(fe)) { 532
533 if (kthread_should_stop() || dvb_frontend_is_exiting(fe)) {
540 /* got signal or quitting */ 534 /* got signal or quitting */
541 break; 535 break;
542 } 536 }
543 537
544 try_to_freeze(); 538 if (try_to_freeze())
539 goto restart;
545 540
546 if (down_interruptible(&fepriv->sem)) 541 if (down_interruptible(&fepriv->sem))
547 break; 542 break;
@@ -591,7 +586,7 @@ static int dvb_frontend_thread(void *data)
591 fe->ops.sleep(fe); 586 fe->ops.sleep(fe);
592 } 587 }
593 588
594 fepriv->thread_pid = 0; 589 fepriv->thread = NULL;
595 mb(); 590 mb();
596 591
597 dvb_frontend_wakeup(fe); 592 dvb_frontend_wakeup(fe);
@@ -600,7 +595,6 @@ static int dvb_frontend_thread(void *data)
600 595
601static void dvb_frontend_stop(struct dvb_frontend *fe) 596static void dvb_frontend_stop(struct dvb_frontend *fe)
602{ 597{
603 unsigned long ret;
604 struct dvb_frontend_private *fepriv = fe->frontend_priv; 598 struct dvb_frontend_private *fepriv = fe->frontend_priv;
605 599
606 dprintk ("%s\n", __FUNCTION__); 600 dprintk ("%s\n", __FUNCTION__);
@@ -608,33 +602,17 @@ static void dvb_frontend_stop(struct dvb_frontend *fe)
608 fepriv->exit = 1; 602 fepriv->exit = 1;
609 mb(); 603 mb();
610 604
611 if (!fepriv->thread_pid) 605 if (!fepriv->thread)
612 return; 606 return;
613 607
614 /* check if the thread is really alive */ 608 kthread_stop(fepriv->thread);
615 if (kill_proc(fepriv->thread_pid, 0, 1) == -ESRCH) { 609 init_MUTEX (&fepriv->sem);
616 printk("dvb_frontend_stop: thread PID %d already died\n",
617 fepriv->thread_pid);
618 /* make sure the mutex was not held by the thread */
619 init_MUTEX (&fepriv->sem);
620 return;
621 }
622
623 /* wake up the frontend thread, so it notices that fe->exit == 1 */
624 dvb_frontend_wakeup(fe);
625
626 /* wait until the frontend thread has exited */
627 ret = wait_event_interruptible(fepriv->wait_queue,0 == fepriv->thread_pid);
628 if (-ERESTARTSYS != ret) {
629 fepriv->state = FESTATE_IDLE;
630 return;
631 }
632 fepriv->state = FESTATE_IDLE; 610 fepriv->state = FESTATE_IDLE;
633 611
634 /* paranoia check in case a signal arrived */ 612 /* paranoia check in case a signal arrived */
635 if (fepriv->thread_pid) 613 if (fepriv->thread)
636 printk("dvb_frontend_stop: warning: thread PID %d won't exit\n", 614 printk("dvb_frontend_stop: warning: thread %p won't exit\n",
637 fepriv->thread_pid); 615 fepriv->thread);
638} 616}
639 617
640s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime) 618s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime)
@@ -684,10 +662,11 @@ static int dvb_frontend_start(struct dvb_frontend *fe)
684{ 662{
685 int ret; 663 int ret;
686 struct dvb_frontend_private *fepriv = fe->frontend_priv; 664 struct dvb_frontend_private *fepriv = fe->frontend_priv;
665 struct task_struct *fe_thread;
687 666
688 dprintk ("%s\n", __FUNCTION__); 667 dprintk ("%s\n", __FUNCTION__);
689 668
690 if (fepriv->thread_pid) { 669 if (fepriv->thread) {
691 if (!fepriv->exit) 670 if (!fepriv->exit)
692 return 0; 671 return 0;
693 else 672 else
@@ -701,18 +680,18 @@ static int dvb_frontend_start(struct dvb_frontend *fe)
701 680
702 fepriv->state = FESTATE_IDLE; 681 fepriv->state = FESTATE_IDLE;
703 fepriv->exit = 0; 682 fepriv->exit = 0;
704 fepriv->thread_pid = 0; 683 fepriv->thread = NULL;
705 mb(); 684 mb();
706 685
707 ret = kernel_thread (dvb_frontend_thread, fe, 0); 686 fe_thread = kthread_run(dvb_frontend_thread, fe,
708 687 "kdvb-fe-%i", fe->dvb->num);
709 if (ret < 0) { 688 if (IS_ERR(fe_thread)) {
710 printk("dvb_frontend_start: failed to start kernel_thread (%d)\n", ret); 689 ret = PTR_ERR(fe_thread);
690 printk("dvb_frontend_start: failed to start kthread (%d)\n", ret);
711 up(&fepriv->sem); 691 up(&fepriv->sem);
712 return ret; 692 return ret;
713 } 693 }
714 fepriv->thread_pid = ret; 694 fepriv->thread = fe_thread;
715
716 return 0; 695 return 0;
717} 696}
718 697
@@ -915,7 +894,7 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
915 fetunesettings.parameters.inversion = INVERSION_AUTO; 894 fetunesettings.parameters.inversion = INVERSION_AUTO;
916 } 895 }
917 if (fe->ops.info.type == FE_OFDM) { 896 if (fe->ops.info.type == FE_OFDM) {
918 /* without hierachical coding code_rate_LP is irrelevant, 897 /* without hierarchical coding code_rate_LP is irrelevant,
919 * so we tolerate the otherwise invalid FEC_NONE setting */ 898 * so we tolerate the otherwise invalid FEC_NONE setting */
920 if (fepriv->parameters.u.ofdm.hierarchy_information == HIERARCHY_NONE && 899 if (fepriv->parameters.u.ofdm.hierarchy_information == HIERARCHY_NONE &&
921 fepriv->parameters.u.ofdm.code_rate_LP == FEC_NONE) 900 fepriv->parameters.u.ofdm.code_rate_LP == FEC_NONE)
diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
index 826b47f155..490337b5ee 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.c
+++ b/drivers/media/dvb/dvb-core/dvbdev.c
@@ -199,12 +199,14 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
199 const struct dvb_device *template, void *priv, int type) 199 const struct dvb_device *template, void *priv, int type)
200{ 200{
201 struct dvb_device *dvbdev; 201 struct dvb_device *dvbdev;
202 struct file_operations *dvbdevfops;
203
202 int id; 204 int id;
203 205
204 if (mutex_lock_interruptible(&dvbdev_register_lock)) 206 if (mutex_lock_interruptible(&dvbdev_register_lock))
205 return -ERESTARTSYS; 207 return -ERESTARTSYS;
206 208
207 if ((id = dvbdev_get_free_id (adap, type)) < 0) { 209 if ((id = dvbdev_get_free_id (adap, type)) < 0){
208 mutex_unlock(&dvbdev_register_lock); 210 mutex_unlock(&dvbdev_register_lock);
209 *pdvbdev = NULL; 211 *pdvbdev = NULL;
210 printk ("%s: could get find free device id...\n", __FUNCTION__); 212 printk ("%s: could get find free device id...\n", __FUNCTION__);
@@ -213,7 +215,15 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
213 215
214 *pdvbdev = dvbdev = kmalloc(sizeof(struct dvb_device), GFP_KERNEL); 216 *pdvbdev = dvbdev = kmalloc(sizeof(struct dvb_device), GFP_KERNEL);
215 217
216 if (!dvbdev) { 218 if (!dvbdev){
219 mutex_unlock(&dvbdev_register_lock);
220 return -ENOMEM;
221 }
222
223 dvbdevfops = kzalloc(sizeof(struct file_operations), GFP_KERNEL);
224
225 if (!dvbdevfops){
226 kfree (dvbdev);
217 mutex_unlock(&dvbdev_register_lock); 227 mutex_unlock(&dvbdev_register_lock);
218 return -ENOMEM; 228 return -ENOMEM;
219 } 229 }
@@ -223,7 +233,9 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
223 dvbdev->id = id; 233 dvbdev->id = id;
224 dvbdev->adapter = adap; 234 dvbdev->adapter = adap;
225 dvbdev->priv = priv; 235 dvbdev->priv = priv;
236 dvbdev->fops = dvbdevfops;
226 237
238 memcpy(dvbdev->fops, template->fops, sizeof(struct file_operations));
227 dvbdev->fops->owner = adap->module; 239 dvbdev->fops->owner = adap->module;
228 240
229 list_add_tail (&dvbdev->list_head, &adap->device_list); 241 list_add_tail (&dvbdev->list_head, &adap->device_list);
@@ -251,6 +263,7 @@ void dvb_unregister_device(struct dvb_device *dvbdev)
251 dvbdev->type, dvbdev->id))); 263 dvbdev->type, dvbdev->id)));
252 264
253 list_del (&dvbdev->list_head); 265 list_del (&dvbdev->list_head);
266 kfree (dvbdev->fops);
254 kfree (dvbdev); 267 kfree (dvbdev);
255} 268}
256EXPORT_SYMBOL(dvb_unregister_device); 269EXPORT_SYMBOL(dvb_unregister_device);
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index ad52143602..80f67a51b9 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -109,6 +109,34 @@ config DVB_USB_CXUSB
109 Medion MD95700 hybrid USB2.0 device. 109 Medion MD95700 hybrid USB2.0 device.
110 DViCO FusionHDTV (Bluebird) USB2.0 devices 110 DViCO FusionHDTV (Bluebird) USB2.0 devices
111 111
112config DVB_USB_M920X
113 tristate "Uli m920x DVB-T USB2.0 support"
114 depends on DVB_USB
115 select DVB_MT352 if !DVB_FE_CUSTOMISE
116 select DVB_TUNER_QT1010 if !DVB_FE_CUSTOMISE
117 help
118 Say Y here to support the MSI Mega Sky 580 USB2.0 DVB-T receiver.
119 Currently, only devices with a product id of
120 "DTV USB MINI" (in cold state) are supported.
121 Firmware required.
122
123config DVB_USB_GL861
124 tristate "Genesys Logic GL861 USB2.0 support"
125 depends on DVB_USB
126 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
127 select DVB_TUNER_QT1010 if !DVB_FE_CUSTOMISE
128 help
129 Say Y here to support the MSI Megasky 580 (55801) DVB-T USB2.0
130 receiver with USB ID 0db0:5581.
131
132config DVB_USB_AU6610
133 tristate "Alcor Micro AU6610 USB2.0 support"
134 depends on DVB_USB
135 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
136 select DVB_TUNER_QT1010 if !DVB_FE_CUSTOMISE
137 help
138 Say Y here to support the Sigmatek DVB-110 DVB-T USB2.0 receiver.
139
112config DVB_USB_DIGITV 140config DVB_USB_DIGITV
113 tristate "Nebula Electronics uDigiTV DVB-T USB2.0 support" 141 tristate "Nebula Electronics uDigiTV DVB-T USB2.0 support"
114 depends on DVB_USB 142 depends on DVB_USB
diff --git a/drivers/media/dvb/dvb-usb/Makefile b/drivers/media/dvb/dvb-usb/Makefile
index 154d593bbb..40f28f559b 100644
--- a/drivers/media/dvb/dvb-usb/Makefile
+++ b/drivers/media/dvb/dvb-usb/Makefile
@@ -30,6 +30,15 @@ obj-$(CONFIG_DVB_USB_NOVA_T_USB2) += dvb-usb-dibusb-common.o dvb-usb-nova-t-usb2
30dvb-usb-umt-010-objs = umt-010.o 30dvb-usb-umt-010-objs = umt-010.o
31obj-$(CONFIG_DVB_USB_UMT_010) += dvb-usb-dibusb-common.o dvb-usb-umt-010.o 31obj-$(CONFIG_DVB_USB_UMT_010) += dvb-usb-dibusb-common.o dvb-usb-umt-010.o
32 32
33dvb-usb-m920x-objs = m920x.o
34obj-$(CONFIG_DVB_USB_M920X) += dvb-usb-m920x.o
35
36dvb-usb-gl861-objs = gl861.o
37obj-$(CONFIG_DVB_USB_GL861) += dvb-usb-gl861.o
38
39dvb-usb-au6610-objs = au6610.o
40obj-$(CONFIG_DVB_USB_AU6610) += dvb-usb-au6610.o
41
33dvb-usb-digitv-objs = digitv.o 42dvb-usb-digitv-objs = digitv.o
34obj-$(CONFIG_DVB_USB_DIGITV) += dvb-usb-digitv.o 43obj-$(CONFIG_DVB_USB_DIGITV) += dvb-usb-digitv.o
35 44
diff --git a/drivers/media/dvb/dvb-usb/au6610.c b/drivers/media/dvb/dvb-usb/au6610.c
new file mode 100644
index 0000000000..0dc66a8d2b
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/au6610.c
@@ -0,0 +1,255 @@
1/* DVB USB compliant linux driver for Sigmatek DVB-110 DVB-T USB2.0 receiver
2 *
3 * Copyright (C) 2006 Antti Palosaari <crope@iki.fi>
4 *
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 Free
7 * Software Foundation, version 2.
8 *
9 * see Documentation/dvb/README.dvb-usb for more information
10 */
11
12#include "au6610.h"
13
14#include "zl10353.h"
15#include "qt1010.h"
16
17/* debug */
18static int dvb_usb_au6610_debug;
19module_param_named(debug, dvb_usb_au6610_debug, int, 0644);
20MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
21
22static int au6610_usb_msg(struct dvb_usb_device *d, u8 operation, u8 addr,
23 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
24{
25 int ret;
26 u16 index;
27 u8 usb_buf[6]; /* enough for all known requests,
28 read returns 5 and write 6 bytes */
29 switch (wlen) {
30 case 1:
31 index = wbuf[0] << 8;
32 break;
33 case 2:
34 index = wbuf[0] << 8;
35 index += wbuf[1];
36 break;
37 default:
38 warn("wlen = %x, aborting.", wlen);
39 return -EINVAL;
40 }
41
42 ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), operation,
43 USB_TYPE_VENDOR|USB_DIR_IN, addr, index, usb_buf,
44 sizeof(usb_buf), AU6610_USB_TIMEOUT);
45
46 if (ret < 0)
47 return ret;
48
49 switch (operation) {
50 case AU6610_REQ_I2C_READ:
51 case AU6610_REQ_USB_READ:
52 /* requested value is always 5th byte in buffer */
53 rbuf[0] = usb_buf[4];
54 }
55
56 return ret;
57}
58
59static int au6610_i2c_msg(struct dvb_usb_device *d, u8 addr,
60 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
61{
62 u8 request;
63 u8 wo = (rbuf == NULL || rlen == 0); /* write-only */
64
65 if (wo) {
66 request = AU6610_REQ_I2C_WRITE;
67 } else { /* rw */
68 request = AU6610_REQ_I2C_READ;
69 }
70
71 return au6610_usb_msg(d, request, addr, wbuf, wlen, rbuf, rlen);
72}
73
74
75/* I2C */
76static int au6610_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
77 int num)
78{
79 struct dvb_usb_device *d = i2c_get_adapdata(adap);
80 int i;
81
82 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
83 return -EAGAIN;
84
85 if (num > 2)
86 return -EINVAL;
87
88 for (i = 0; i < num; i++) {
89 /* write/read request */
90 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
91 if (au6610_i2c_msg(d, msg[i].addr, msg[i].buf,
92 msg[i].len, msg[i+1].buf,
93 msg[i+1].len) < 0)
94 break;
95 i++;
96 } else if (au6610_i2c_msg(d, msg[i].addr, msg[i].buf,
97 msg[i].len, NULL, 0) < 0)
98 break;
99 }
100
101 mutex_unlock(&d->i2c_mutex);
102 return i;
103}
104
105
106static u32 au6610_i2c_func(struct i2c_adapter *adapter)
107{
108 return I2C_FUNC_I2C;
109}
110
111static struct i2c_algorithm au6610_i2c_algo = {
112 .master_xfer = au6610_i2c_xfer,
113 .functionality = au6610_i2c_func,
114};
115
116/* Callbacks for DVB USB */
117static int au6610_identify_state(struct usb_device *udev,
118 struct dvb_usb_device_properties *props,
119 struct dvb_usb_device_description **desc,
120 int *cold)
121{
122 *cold = 0;
123 return 0;
124}
125
126static struct zl10353_config au6610_zl10353_config = {
127 .demod_address = 0x1e,
128 .no_tuner = 1,
129 .parallel_ts = 1,
130};
131
132static int au6610_zl10353_frontend_attach(struct dvb_usb_adapter *adap)
133{
134 if ((adap->fe = dvb_attach(zl10353_attach, &au6610_zl10353_config,
135 &adap->dev->i2c_adap)) != NULL) {
136 return 0;
137 }
138
139 return -EIO;
140}
141
142static struct qt1010_config au6610_qt1010_config = {
143 .i2c_address = 0xc4
144};
145
146static int au6610_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
147{
148 return dvb_attach(qt1010_attach,
149 adap->fe, &adap->dev->i2c_adap,
150 &au6610_qt1010_config) == NULL ? -ENODEV : 0;
151}
152
153/* DVB USB Driver stuff */
154static struct dvb_usb_device_properties au6610_properties;
155
156static int au6610_probe(struct usb_interface *intf,
157 const struct usb_device_id *id)
158{
159 struct dvb_usb_device *d;
160 struct usb_host_interface *alt;
161 int ret;
162
163 if (intf->num_altsetting < AU6610_ALTSETTING_COUNT)
164 return -ENODEV;
165
166 if ((ret = dvb_usb_device_init(intf, &au6610_properties, THIS_MODULE, &d)) == 0) {
167 alt = usb_altnum_to_altsetting(intf, AU6610_ALTSETTING);
168
169 if (alt == NULL) {
170 deb_rc("no alt found!\n");
171 return -ENODEV;
172 }
173 ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
174 alt->desc.bAlternateSetting);
175 }
176
177 return ret;
178}
179
180
181static struct usb_device_id au6610_table [] = {
182 { USB_DEVICE(USB_VID_ALCOR_MICRO, USB_PID_SIGMATEK_DVB_110) },
183 { } /* Terminating entry */
184};
185MODULE_DEVICE_TABLE (usb, au6610_table);
186
187static struct dvb_usb_device_properties au6610_properties = {
188 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
189 .usb_ctrl = DEVICE_SPECIFIC,
190 .size_of_priv = 0,
191 .identify_state = au6610_identify_state,
192 .num_adapters = 1,
193 .adapter = {
194 {
195 .frontend_attach = au6610_zl10353_frontend_attach,
196 .tuner_attach = au6610_qt1010_tuner_attach,
197
198 .stream = {
199 .type = USB_ISOC,
200 .count = 5,
201 .endpoint = 0x82,
202 .u = {
203 .isoc = {
204 .framesperurb = 40,
205 .framesize = 942, /* maximum packet size */
206 .interval = 1.25, /* 125 us */
207 }
208 }
209 },
210 }
211 },
212 .i2c_algo = &au6610_i2c_algo,
213 .num_device_descs = 1,
214 .devices = {
215 {
216 "Sigmatek DVB-110 DVB-T USB2.0",
217 { &au6610_table[0], NULL },
218 { NULL },
219 },
220 }
221};
222
223static struct usb_driver au6610_driver = {
224 .name = "dvb_usb_au6610",
225 .probe = au6610_probe,
226 .disconnect = dvb_usb_device_exit,
227 .id_table = au6610_table,
228};
229
230/* module stuff */
231static int __init au6610_module_init(void)
232{
233 int ret;
234
235 if ((ret = usb_register(&au6610_driver))) {
236 err("usb_register failed. Error number %d", ret);
237 return ret;
238 }
239
240 return 0;
241}
242
243static void __exit au6610_module_exit(void)
244{
245 /* deregister this driver from the USB subsystem */
246 usb_deregister(&au6610_driver);
247}
248
249module_init (au6610_module_init);
250module_exit (au6610_module_exit);
251
252MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
253MODULE_DESCRIPTION("Driver Sigmatek DVB-110 DVB-T USB2.0 / AU6610");
254MODULE_VERSION("0.1");
255MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/au6610.h b/drivers/media/dvb/dvb-usb/au6610.h
new file mode 100644
index 0000000000..4161b054c7
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/au6610.h
@@ -0,0 +1,19 @@
1#ifndef _DVB_USB_AU6610_H_
2#define _DVB_USB_AU6610_H_
3
4#define DVB_USB_LOG_PREFIX "au6610"
5#include "dvb-usb.h"
6
7#define deb_rc(args...) dprintk(dvb_usb_au6610_debug,0x01,args)
8
9#define AU6610_REQ_I2C_WRITE 0x14
10#define AU6610_REQ_I2C_READ 0x13
11#define AU6610_REQ_USB_WRITE 0x16
12#define AU6610_REQ_USB_READ 0x15
13
14#define AU6610_USB_TIMEOUT 1000
15
16#define AU6610_ALTSETTING_COUNT 6
17#define AU6610_ALTSETTING 5
18
19#endif
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
index 15d12fce34..127a94b9a1 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.c
+++ b/drivers/media/dvb/dvb-usb/cxusb.c
@@ -469,9 +469,9 @@ static int bluebird_patch_dvico_firmware_download(struct usb_device *udev,
469 fw->data[BLUEBIRD_01_ID_OFFSET + 1] == USB_VID_DVICO >> 8) { 469 fw->data[BLUEBIRD_01_ID_OFFSET + 1] == USB_VID_DVICO >> 8) {
470 470
471 fw->data[BLUEBIRD_01_ID_OFFSET + 2] = 471 fw->data[BLUEBIRD_01_ID_OFFSET + 2] =
472 udev->descriptor.idProduct + 1; 472 le16_to_cpu(udev->descriptor.idProduct) + 1;
473 fw->data[BLUEBIRD_01_ID_OFFSET + 3] = 473 fw->data[BLUEBIRD_01_ID_OFFSET + 3] =
474 udev->descriptor.idProduct >> 8; 474 le16_to_cpu(udev->descriptor.idProduct) >> 8;
475 475
476 return usb_cypress_load_firmware(udev, fw, CYPRESS_FX2); 476 return usb_cypress_load_firmware(udev, fw, CYPRESS_FX2);
477 } 477 }
diff --git a/drivers/media/dvb/dvb-usb/digitv.c b/drivers/media/dvb/dvb-usb/digitv.c
index 4a198d4755..b5acb11c0b 100644
--- a/drivers/media/dvb/dvb-usb/digitv.c
+++ b/drivers/media/dvb/dvb-usb/digitv.c
@@ -119,6 +119,8 @@ static int digitv_nxt6000_tuner_set_params(struct dvb_frontend *fe, struct dvb_f
119 struct dvb_usb_adapter *adap = fe->dvb->priv; 119 struct dvb_usb_adapter *adap = fe->dvb->priv;
120 u8 b[5]; 120 u8 b[5];
121 dvb_usb_tuner_calc_regs(fe,fep,b, 5); 121 dvb_usb_tuner_calc_regs(fe,fep,b, 5);
122 if (fe->ops.i2c_gate_ctrl)
123 fe->ops.i2c_gate_ctrl(fe, 1);
122 return digitv_ctrl_msg(adap->dev, USB_WRITE_TUNER, 0, &b[1], 4, NULL, 0); 124 return digitv_ctrl_msg(adap->dev, USB_WRITE_TUNER, 0, &b[1], 4, NULL, 0);
123} 125}
124 126
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index 299382dcb8..148386aba2 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -11,6 +11,7 @@
11 11
12/* Vendor IDs */ 12/* Vendor IDs */
13#define USB_VID_ADSTECH 0x06e1 13#define USB_VID_ADSTECH 0x06e1
14#define USB_VID_ALCOR_MICRO 0x058f
14#define USB_VID_ANCHOR 0x0547 15#define USB_VID_ANCHOR 0x0547
15#define USB_VID_AVERMEDIA 0x07ca 16#define USB_VID_AVERMEDIA 0x07ca
16#define USB_VID_COMPRO 0x185b 17#define USB_VID_COMPRO 0x185b
@@ -29,6 +30,7 @@
29#define USB_VID_LEADTEK 0x0413 30#define USB_VID_LEADTEK 0x0413
30#define USB_VID_LITEON 0x04ca 31#define USB_VID_LITEON 0x04ca
31#define USB_VID_MEDION 0x1660 32#define USB_VID_MEDION 0x1660
33#define USB_VID_MSI 0x0db0
32#define USB_VID_PINNACLE 0x2304 34#define USB_VID_PINNACLE 0x2304
33#define USB_VID_VISIONPLUS 0x13d3 35#define USB_VID_VISIONPLUS 0x13d3
34#define USB_VID_TWINHAN 0x1822 36#define USB_VID_TWINHAN 0x1822
@@ -119,6 +121,8 @@
119#define USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD 0xdb54 121#define USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD 0xdb54
120#define USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM 0xdb55 122#define USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM 0xdb55
121#define USB_PID_MEDION_MD95700 0x0932 123#define USB_PID_MEDION_MD95700 0x0932
124#define USB_PID_MSI_MEGASKY580 0x5580
125#define USB_PID_MSI_MEGASKY580_55801 0x5581
122#define USB_PID_KYE_DVB_T_COLD 0x701e 126#define USB_PID_KYE_DVB_T_COLD 0x701e
123#define USB_PID_KYE_DVB_T_WARM 0x701f 127#define USB_PID_KYE_DVB_T_WARM 0x701f
124#define USB_PID_PCTV_200E 0x020e 128#define USB_PID_PCTV_200E 0x020e
@@ -134,6 +138,7 @@
134#define USB_PID_WINFAST_DTV_DONGLE_STK7700P 0x6f00 138#define USB_PID_WINFAST_DTV_DONGLE_STK7700P 0x6f00
135#define USB_PID_GENPIX_8PSK_COLD 0x0200 139#define USB_PID_GENPIX_8PSK_COLD 0x0200
136#define USB_PID_GENPIX_8PSK_WARM 0x0201 140#define USB_PID_GENPIX_8PSK_WARM 0x0201
141#define USB_PID_SIGMATEK_DVB_110 0x6610
137 142
138 143
139#endif 144#endif
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
index 19ff5978bc..9511a31c8f 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
@@ -151,7 +151,7 @@ int dvb_usb_remote_init(struct dvb_usb_device *d)
151int dvb_usb_remote_exit(struct dvb_usb_device *d) 151int dvb_usb_remote_exit(struct dvb_usb_device *d)
152{ 152{
153 if (d->state & DVB_USB_STATE_REMOTE) { 153 if (d->state & DVB_USB_STATE_REMOTE) {
154 cancel_delayed_work(&d->rc_query_work); 154 cancel_rearming_delayed_work(&d->rc_query_work);
155 flush_scheduled_work(); 155 flush_scheduled_work();
156 input_unregister_device(d->rc_input_dev); 156 input_unregister_device(d->rc_input_dev);
157 } 157 }
diff --git a/drivers/media/dvb/dvb-usb/gl861.c b/drivers/media/dvb/dvb-usb/gl861.c
new file mode 100644
index 0000000000..c9f38a5e70
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/gl861.c
@@ -0,0 +1,231 @@
1/* DVB USB compliant linux driver for GL861 USB2.0 devices.
2 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation, version 2.
6 *
7 * see Documentation/dvb/README.dvb-usb for more information
8 */
9#include "gl861.h"
10
11#include "zl10353.h"
12#include "qt1010.h"
13
14/* debug */
15int dvb_usb_gl861_debug;
16module_param_named(debug,dvb_usb_gl861_debug, int, 0644);
17MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
18
19static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr,
20 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
21{
22 u16 index;
23 u16 value = addr << 8;
24 int wo = (rbuf == NULL || rlen == 0); /* write-only */
25 u8 req, type;
26
27 if (wo) {
28 req = GL861_REQ_I2C_WRITE;
29 type = GL861_WRITE;
30 } else { /* rw */
31 req = GL861_REQ_I2C_READ;
32 type = GL861_READ;
33 }
34
35 switch (wlen) {
36 case 1:
37 index = wbuf[0];
38 break;
39 case 2:
40 index = wbuf[0];
41 value = value + wbuf[1];
42 break;
43 default:
44 warn("wlen = %x, aborting.", wlen);
45 return -EINVAL;
46 }
47
48 return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type,
49 value, index, rbuf, rlen, 2000);
50}
51
52/* I2C */
53static int gl861_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
54 int num)
55{
56 struct dvb_usb_device *d = i2c_get_adapdata(adap);
57 int i;
58
59 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
60 return -EAGAIN;
61
62 if (num > 2)
63 return -EINVAL;
64
65 for (i = 0; i < num; i++) {
66 /* write/read request */
67 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
68 if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf,
69 msg[i].len, msg[i+1].buf, msg[i+1].len) < 0)
70 break;
71 i++;
72 } else
73 if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf,
74 msg[i].len, NULL, 0) < 0)
75 break;
76 }
77
78 mutex_unlock(&d->i2c_mutex);
79 return i;
80}
81
82static u32 gl861_i2c_func(struct i2c_adapter *adapter)
83{
84 return I2C_FUNC_I2C;
85}
86
87static struct i2c_algorithm gl861_i2c_algo = {
88 .master_xfer = gl861_i2c_xfer,
89 .functionality = gl861_i2c_func,
90};
91
92/* Callbacks for DVB USB */
93static int gl861_identify_state(struct usb_device *udev,
94 struct dvb_usb_device_properties *props,
95 struct dvb_usb_device_description **desc,
96 int *cold)
97{
98 *cold = 0;
99
100 return 0;
101}
102
103static struct zl10353_config gl861_zl10353_config = {
104 .demod_address = 0x1e,
105 .no_tuner = 1,
106 .parallel_ts = 1,
107};
108
109static int gl861_frontend_attach(struct dvb_usb_adapter *adap)
110{
111 if ((adap->fe = dvb_attach(zl10353_attach, &gl861_zl10353_config,
112 &adap->dev->i2c_adap)) != NULL) {
113 return 0;
114 }
115
116 return -EIO;
117}
118
119static struct qt1010_config gl861_qt1010_config = {
120 .i2c_address = 0xc4
121};
122
123static int gl861_tuner_attach(struct dvb_usb_adapter *adap)
124{
125 return dvb_attach(qt1010_attach,
126 adap->fe, &adap->dev->i2c_adap,
127 &gl861_qt1010_config) == NULL ? -ENODEV : 0;
128}
129
130/* DVB USB Driver stuff */
131static struct dvb_usb_device_properties gl861_properties;
132
133static int gl861_probe(struct usb_interface *intf,
134 const struct usb_device_id *id)
135{
136 struct dvb_usb_device *d;
137 struct usb_host_interface *alt;
138 int ret;
139
140 if (intf->num_altsetting < 2)
141 return -ENODEV;
142
143 if ((ret = dvb_usb_device_init(intf, &gl861_properties, THIS_MODULE, &d)) == 0) {
144 alt = usb_altnum_to_altsetting(intf, 0);
145
146 if (alt == NULL) {
147 deb_rc("not alt found!\n");
148 return -ENODEV;
149 }
150
151 ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
152 alt->desc.bAlternateSetting);
153 }
154
155 return ret;
156}
157
158static struct usb_device_id gl861_table [] = {
159 { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580_55801) },
160 { } /* Terminating entry */
161};
162MODULE_DEVICE_TABLE (usb, gl861_table);
163
164static struct dvb_usb_device_properties gl861_properties = {
165 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
166 .usb_ctrl = DEVICE_SPECIFIC,
167
168 .size_of_priv = 0,
169
170 .identify_state = gl861_identify_state,
171 .num_adapters = 1,
172 .adapter = {{
173
174 .frontend_attach = gl861_frontend_attach,
175 .tuner_attach = gl861_tuner_attach,
176
177 .stream = {
178 .type = USB_BULK,
179 .count = 7,
180 .endpoint = 0x81,
181 .u = {
182 .bulk = {
183 .buffersize = 512,
184 }
185 }
186 },
187 }},
188 .i2c_algo = &gl861_i2c_algo,
189
190 .num_device_descs = 1,
191 .devices = {
192 { "MSI Mega Sky 55801 DVB-T USB2.0",
193 { &gl861_table[0], NULL },
194 { NULL },
195 },
196 }
197};
198
199static struct usb_driver gl861_driver = {
200 .name = "dvb_usb_gl861",
201 .probe = gl861_probe,
202 .disconnect = dvb_usb_device_exit,
203 .id_table = gl861_table,
204};
205
206/* module stuff */
207static int __init gl861_module_init(void)
208{
209 int ret;
210
211 if ((ret = usb_register(&gl861_driver))) {
212 err("usb_register failed. Error number %d", ret);
213 return ret;
214 }
215
216 return 0;
217}
218
219static void __exit gl861_module_exit(void)
220{
221 /* deregister this driver from the USB subsystem */
222 usb_deregister(&gl861_driver);
223}
224
225module_init (gl861_module_init);
226module_exit (gl861_module_exit);
227
228MODULE_AUTHOR("Carl Lundqvist <comabug@gmail.com>");
229MODULE_DESCRIPTION("Driver MSI Mega Sky 580 DVB-T USB2.0 / GL861");
230MODULE_VERSION("0.1");
231MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/gl861.h b/drivers/media/dvb/dvb-usb/gl861.h
new file mode 100644
index 0000000000..72a51afd5e
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/gl861.h
@@ -0,0 +1,15 @@
1#ifndef _DVB_USB_GL861_H_
2#define _DVB_USB_GL861_H_
3
4#define DVB_USB_LOG_PREFIX "gl861"
5#include "dvb-usb.h"
6
7#define deb_rc(args...) dprintk(dvb_usb_gl861_debug,0x01,args)
8
9#define GL861_WRITE 0x40
10#define GL861_READ 0xc0
11
12#define GL861_REQ_I2C_WRITE 0x01
13#define GL861_REQ_I2C_READ 0x02
14
15#endif
diff --git a/drivers/media/dvb/dvb-usb/m920x.c b/drivers/media/dvb/dvb-usb/m920x.c
new file mode 100644
index 0000000000..d48b24d9ab
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/m920x.c
@@ -0,0 +1,541 @@
1/* DVB USB compliant linux driver for MSI Mega Sky 580 DVB-T USB2.0 receiver
2 *
3 * Copyright (C) 2006 Aapo Tahkola (aet@rasterburn.org)
4 *
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 Free
7 * Software Foundation, version 2.
8 *
9 * see Documentation/dvb/README.dvb-usb for more information
10 */
11
12#include "m920x.h"
13
14#include "mt352.h"
15#include "mt352_priv.h"
16#include "qt1010.h"
17
18/* debug */
19static int dvb_usb_m920x_debug;
20module_param_named(debug,dvb_usb_m920x_debug, int, 0644);
21MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
22
23static struct dvb_usb_rc_key megasky_rc_keys [] = {
24 { 0x0, 0x12, KEY_POWER },
25 { 0x0, 0x1e, KEY_CYCLEWINDOWS }, /* min/max */
26 { 0x0, 0x02, KEY_CHANNELUP },
27 { 0x0, 0x05, KEY_CHANNELDOWN },
28 { 0x0, 0x03, KEY_VOLUMEUP },
29 { 0x0, 0x06, KEY_VOLUMEDOWN },
30 { 0x0, 0x04, KEY_MUTE },
31 { 0x0, 0x07, KEY_OK }, /* TS */
32 { 0x0, 0x08, KEY_STOP },
33 { 0x0, 0x09, KEY_MENU }, /* swap */
34 { 0x0, 0x0a, KEY_REWIND },
35 { 0x0, 0x1b, KEY_PAUSE },
36 { 0x0, 0x1f, KEY_FASTFORWARD },
37 { 0x0, 0x0c, KEY_RECORD },
38 { 0x0, 0x0d, KEY_CAMERA }, /* screenshot */
39 { 0x0, 0x0e, KEY_COFFEE }, /* "MTS" */
40};
41
42static inline int m9206_read(struct usb_device *udev, u8 request, u16 value,\
43 u16 index, void *data, int size)
44{
45 int ret;
46
47 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
48 request, USB_TYPE_VENDOR | USB_DIR_IN,
49 value, index, data, size, 2000);
50 if (ret < 0)
51 return ret;
52
53 if (ret != size)
54 return -EIO;
55
56 return 0;
57}
58
59static inline int m9206_write(struct usb_device *udev, u8 request,
60 u16 value, u16 index)
61{
62 int ret;
63
64 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
65 request, USB_TYPE_VENDOR | USB_DIR_OUT,
66 value, index, NULL, 0, 2000);
67 return ret;
68}
69
70static int m9206_rc_init(struct usb_device *udev)
71{
72 int ret = 0;
73
74 /* Remote controller init. */
75 if ((ret = m9206_write(udev, M9206_CORE, 0xa8, M9206_RC_INIT2)) != 0)
76 return ret;
77
78 if ((ret = m9206_write(udev, M9206_CORE, 0x51, M9206_RC_INIT1)) != 0)
79 return ret;
80
81 return ret;
82}
83
84static int m9206_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
85{
86 struct m9206_state *m = d->priv;
87 int i, ret = 0;
88 u8 rc_state[2];
89
90
91 if ((ret = m9206_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, rc_state, 1)) != 0)
92 goto unlock;
93
94 if ((ret = m9206_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, rc_state + 1, 1)) != 0)
95 goto unlock;
96
97 for (i = 0; i < ARRAY_SIZE(megasky_rc_keys); i++)
98 if (megasky_rc_keys[i].data == rc_state[1]) {
99 *event = megasky_rc_keys[i].event;
100
101 switch(rc_state[0]) {
102 case 0x80:
103 *state = REMOTE_NO_KEY_PRESSED;
104 goto unlock;
105
106 case 0x93:
107 case 0x92:
108 m->rep_count = 0;
109 *state = REMOTE_KEY_PRESSED;
110 goto unlock;
111
112 case 0x91:
113 /* For comfort. */
114 if (++m->rep_count > 2)
115 *state = REMOTE_KEY_REPEAT;
116 goto unlock;
117
118 default:
119 deb_rc("Unexpected rc response %x\n", rc_state[0]);
120 *state = REMOTE_NO_KEY_PRESSED;
121 goto unlock;
122 }
123 }
124
125 if (rc_state[1] != 0)
126 deb_rc("Unknown rc key %x\n", rc_state[1]);
127
128 *state = REMOTE_NO_KEY_PRESSED;
129
130 unlock:
131
132 return ret;
133}
134
135/* I2C */
136static int m9206_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
137 int num)
138{
139 struct dvb_usb_device *d = i2c_get_adapdata(adap);
140 struct m9206_state *m = d->priv;
141 int i;
142 int ret = 0;
143
144 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
145 return -EAGAIN;
146
147 if (num > 2)
148 return -EINVAL;
149
150 for (i = 0; i < num; i++) {
151 if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].addr, 0x80)) != 0)
152 goto unlock;
153
154 if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].buf[0], 0x0)) != 0)
155 goto unlock;
156
157 if (i + 1 < num && msg[i + 1].flags & I2C_M_RD) {
158 int i2c_i;
159
160 for (i2c_i = 0; i2c_i < M9206_I2C_MAX; i2c_i++)
161 if (msg[i].addr == m->i2c_r[i2c_i].addr)
162 break;
163
164 if (i2c_i >= M9206_I2C_MAX) {
165 deb_rc("No magic for i2c addr!\n");
166 ret = -EINVAL;
167 goto unlock;
168 }
169
170 if ((ret = m9206_write(d->udev, M9206_I2C, m->i2c_r[i2c_i].magic, 0x80)) != 0)
171 goto unlock;
172
173 if ((ret = m9206_read(d->udev, M9206_I2C, 0x0, 0x60, msg[i + 1].buf, msg[i + 1].len)) != 0)
174 goto unlock;
175
176 i++;
177 } else {
178 if (msg[i].len != 2)
179 return -EINVAL;
180
181 if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].buf[1], 0x40)) != 0)
182 goto unlock;
183 }
184 }
185 ret = i;
186 unlock:
187 mutex_unlock(&d->i2c_mutex);
188
189 return ret;
190}
191
192static u32 m9206_i2c_func(struct i2c_adapter *adapter)
193{
194 return I2C_FUNC_I2C;
195}
196
197static struct i2c_algorithm m9206_i2c_algo = {
198 .master_xfer = m9206_i2c_xfer,
199 .functionality = m9206_i2c_func,
200};
201
202
203static int m9206_set_filter(struct dvb_usb_adapter *adap, int type, int idx,
204 int pid)
205{
206 int ret = 0;
207
208 if (pid >= 0x8000)
209 return -EINVAL;
210
211 pid |= 0x8000;
212
213 if ((ret = m9206_write(adap->dev->udev, M9206_FILTER, pid, (type << 8) | (idx * 4) )) != 0)
214 return ret;
215
216 if ((ret = m9206_write(adap->dev->udev, M9206_FILTER, 0, (type << 8) | (idx * 4) )) != 0)
217 return ret;
218
219 return ret;
220}
221
222static int m9206_update_filters(struct dvb_usb_adapter *adap)
223{
224 struct m9206_state *m = adap->dev->priv;
225 int enabled = m->filtering_enabled;
226 int i, ret = 0, filter = 0;
227
228 for (i = 0; i < M9206_MAX_FILTERS; i++)
229 if (m->filters[i] == 8192)
230 enabled = 0;
231
232 /* Disable all filters */
233 if ((ret = m9206_set_filter(adap, 0x81, 1, enabled)) != 0)
234 return ret;
235
236 for (i = 0; i < M9206_MAX_FILTERS; i++)
237 if ((ret = m9206_set_filter(adap, 0x81, i + 2, 0)) != 0)
238 return ret;
239
240 if ((ret = m9206_set_filter(adap, 0x82, 0, 0x0)) != 0)
241 return ret;
242
243 /* Set */
244 if (enabled) {
245 for (i = 0; i < M9206_MAX_FILTERS; i++) {
246 if (m->filters[i] == 0)
247 continue;
248
249 if ((ret = m9206_set_filter(adap, 0x81, filter + 2, m->filters[i])) != 0)
250 return ret;
251
252 filter++;
253 }
254 }
255
256 if ((ret = m9206_set_filter(adap, 0x82, 0, 0x02f5)) != 0)
257 return ret;
258
259 return ret;
260}
261
262static int m9206_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
263{
264 struct m9206_state *m = adap->dev->priv;
265
266 m->filtering_enabled = onoff ? 1 : 0;
267
268 return m9206_update_filters(adap);
269}
270
271static int m9206_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
272 int onoff)
273{
274 struct m9206_state *m = adap->dev->priv;
275
276 m->filters[index] = onoff ? pid : 0;
277
278 return m9206_update_filters(adap);
279}
280
281static int m9206_firmware_download(struct usb_device *udev,
282 const struct firmware *fw)
283{
284 u16 value, index, size;
285 u8 read[4], *buff;
286 int i, pass, ret = 0;
287
288 buff = kmalloc(65536, GFP_KERNEL);
289
290 if ((ret = m9206_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0)
291 goto done;
292 deb_rc("%x %x %x %x\n", read[0], read[1], read[2], read[3]);
293
294 if ((ret = m9206_read(udev, M9206_FW, 0x0, 0x0, read, 1)) != 0)
295 goto done;
296 deb_rc("%x\n", read[0]);
297
298 for (pass = 0; pass < 2; pass++) {
299 for (i = 0; i + (sizeof(u16) * 3) < fw->size;) {
300 value = le16_to_cpu(*(u16 *)(fw->data + i));
301 i += sizeof(u16);
302
303 index = le16_to_cpu(*(u16 *)(fw->data + i));
304 i += sizeof(u16);
305
306 size = le16_to_cpu(*(u16 *)(fw->data + i));
307 i += sizeof(u16);
308
309 if (pass == 1) {
310 /* Will stall if using fw->data ... */
311 memcpy(buff, fw->data + i, size);
312
313 ret = usb_control_msg(udev, usb_sndctrlpipe(udev,0),
314 M9206_FW,
315 USB_TYPE_VENDOR | USB_DIR_OUT,
316 value, index, buff, size, 20);
317 if (ret != size) {
318 deb_rc("error while uploading fw!\n");
319 ret = -EIO;
320 goto done;
321 }
322 msleep(3);
323 }
324 i += size;
325 }
326 if (i != fw->size) {
327 ret = -EINVAL;
328 goto done;
329 }
330 }
331
332 msleep(36);
333
334 /* m9206 will disconnect itself from the bus after this. */
335 (void) m9206_write(udev, M9206_CORE, 0x01, M9206_FW_GO);
336 deb_rc("firmware uploaded!\n");
337
338 done:
339 kfree(buff);
340
341 return ret;
342}
343
344/* Callbacks for DVB USB */
345static int megasky_identify_state(struct usb_device *udev,
346 struct dvb_usb_device_properties *props,
347 struct dvb_usb_device_description **desc,
348 int *cold)
349{
350 struct usb_host_interface *alt;
351
352 alt = usb_altnum_to_altsetting(usb_ifnum_to_if(udev, 0), 1);
353 *cold = (alt == NULL) ? 1 : 0;
354
355 return 0;
356}
357
358static int megasky_mt352_demod_init(struct dvb_frontend *fe)
359{
360 u8 config[] = { CONFIG, 0x3d };
361 u8 clock[] = { CLOCK_CTL, 0x30 };
362 u8 reset[] = { RESET, 0x80 };
363 u8 adc_ctl[] = { ADC_CTL_1, 0x40 };
364 u8 agc[] = { AGC_TARGET, 0x1c, 0x20 };
365 u8 sec_agc[] = { 0x69, 0x00, 0xff, 0xff, 0x40, 0xff, 0x00, 0x40, 0x40 };
366 u8 unk1[] = { 0x93, 0x1a };
367 u8 unk2[] = { 0xb5, 0x7a };
368
369 mt352_write(fe, config, ARRAY_SIZE(config));
370 mt352_write(fe, clock, ARRAY_SIZE(clock));
371 mt352_write(fe, reset, ARRAY_SIZE(reset));
372 mt352_write(fe, adc_ctl, ARRAY_SIZE(adc_ctl));
373 mt352_write(fe, agc, ARRAY_SIZE(agc));
374 mt352_write(fe, sec_agc, ARRAY_SIZE(sec_agc));
375 mt352_write(fe, unk1, ARRAY_SIZE(unk1));
376 mt352_write(fe, unk2, ARRAY_SIZE(unk2));
377
378 deb_rc("Demod init!\n");
379
380 return 0;
381}
382
383static struct mt352_config megasky_mt352_config = {
384 .demod_address = 0x1e,
385 .no_tuner = 1,
386 .demod_init = megasky_mt352_demod_init,
387};
388
389static int megasky_mt352_frontend_attach(struct dvb_usb_adapter *adap)
390{
391 struct m9206_state *m = adap->dev->priv;
392
393 deb_rc("megasky_frontend_attach!\n");
394
395 m->i2c_r[M9206_I2C_DEMOD].addr = megasky_mt352_config.demod_address;
396 m->i2c_r[M9206_I2C_DEMOD].magic = 0x1f;
397
398 if ((adap->fe = dvb_attach(mt352_attach, &megasky_mt352_config, &adap->dev->i2c_adap)) == NULL)
399 return -EIO;
400
401 return 0;
402}
403
404static struct qt1010_config megasky_qt1010_config = {
405 .i2c_address = 0xc4
406};
407
408static int megasky_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
409{
410 struct m9206_state *m = adap->dev->priv;
411
412 m->i2c_r[M9206_I2C_TUNER].addr = megasky_qt1010_config.i2c_address;
413 m->i2c_r[M9206_I2C_TUNER].magic = 0xc5;
414
415 if (dvb_attach(qt1010_attach, adap->fe, &adap->dev->i2c_adap,
416 &megasky_qt1010_config) == NULL)
417 return -ENODEV;
418
419 return 0;
420}
421
422/* DVB USB Driver stuff */
423static struct dvb_usb_device_properties megasky_properties;
424
425static int m920x_probe(struct usb_interface *intf,
426 const struct usb_device_id *id)
427{
428 struct dvb_usb_device *d;
429 struct usb_host_interface *alt;
430 int ret;
431
432 if ((ret = dvb_usb_device_init(intf, &megasky_properties, THIS_MODULE, &d)) == 0) {
433 deb_rc("probed!\n");
434
435 alt = usb_altnum_to_altsetting(intf, 1);
436 if (alt == NULL) {
437 deb_rc("not alt found!\n");
438 return -ENODEV;
439 }
440
441 ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
442 alt->desc.bAlternateSetting);
443 if (ret < 0)
444 return ret;
445
446 deb_rc("Changed to alternate setting!\n");
447
448 if ((ret = m9206_rc_init(d->udev)) != 0)
449 return ret;
450 }
451 return ret;
452}
453
454static struct usb_device_id m920x_table [] = {
455 { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580) },
456 { } /* Terminating entry */
457};
458MODULE_DEVICE_TABLE (usb, m920x_table);
459
460static struct dvb_usb_device_properties megasky_properties = {
461 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
462
463 .usb_ctrl = DEVICE_SPECIFIC,
464 .firmware = "dvb-usb-megasky-02.fw",
465 .download_firmware = m9206_firmware_download,
466
467 .rc_interval = 100,
468 .rc_key_map = megasky_rc_keys,
469 .rc_key_map_size = ARRAY_SIZE(megasky_rc_keys),
470 .rc_query = m9206_rc_query,
471
472 .size_of_priv = sizeof(struct m9206_state),
473
474 .identify_state = megasky_identify_state,
475 .num_adapters = 1,
476 .adapter = {{
477 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
478 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
479
480 .pid_filter_count = 8,
481 .pid_filter = m9206_pid_filter,
482 .pid_filter_ctrl = m9206_pid_filter_ctrl,
483
484 .frontend_attach = megasky_mt352_frontend_attach,
485 .tuner_attach = megasky_qt1010_tuner_attach,
486
487 .stream = {
488 .type = USB_BULK,
489 .count = 8,
490 .endpoint = 0x81,
491 .u = {
492 .bulk = {
493 .buffersize = 512,
494 }
495 }
496 },
497 }},
498 .i2c_algo = &m9206_i2c_algo,
499
500 .num_device_descs = 1,
501 .devices = {
502 { "MSI Mega Sky 580 DVB-T USB2.0",
503 { &m920x_table[0], NULL },
504 { NULL },
505 },
506 }
507};
508
509static struct usb_driver m920x_driver = {
510 .name = "dvb_usb_m920x",
511 .probe = m920x_probe,
512 .disconnect = dvb_usb_device_exit,
513 .id_table = m920x_table,
514};
515
516/* module stuff */
517static int __init m920x_module_init(void)
518{
519 int ret;
520
521 if ((ret = usb_register(&m920x_driver))) {
522 err("usb_register failed. Error number %d", ret);
523 return ret;
524 }
525
526 return 0;
527}
528
529static void __exit m920x_module_exit(void)
530{
531 /* deregister this driver from the USB subsystem */
532 usb_deregister(&m920x_driver);
533}
534
535module_init (m920x_module_init);
536module_exit (m920x_module_exit);
537
538MODULE_AUTHOR("Aapo Tahkola <aet@rasterburn.org>");
539MODULE_DESCRIPTION("Driver MSI Mega Sky 580 DVB-T USB2.0 / Uli m920x");
540MODULE_VERSION("0.1");
541MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/m920x.h b/drivers/media/dvb/dvb-usb/m920x.h
new file mode 100644
index 0000000000..c354196ffe
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/m920x.h
@@ -0,0 +1,35 @@
1#ifndef _DVB_USB_M920X_H_
2#define _DVB_USB_M920X_H_
3
4#define DVB_USB_LOG_PREFIX "m920x"
5#include "dvb-usb.h"
6
7#define deb_rc(args...) dprintk(dvb_usb_m920x_debug,0x01,args)
8
9#define M9206_CORE 0x22
10#define M9206_RC_STATE 0xff51
11#define M9206_RC_KEY 0xff52
12#define M9206_RC_INIT1 0xff54
13#define M9206_RC_INIT2 0xff55
14#define M9206_FW_GO 0xff69
15
16#define M9206_I2C 0x23
17#define M9206_FILTER 0x25
18#define M9206_FW 0x30
19
20#define M9206_MAX_FILTERS 8
21
22#define M9206_I2C_TUNER 0
23#define M9206_I2C_DEMOD 1
24#define M9206_I2C_MAX 2
25
26struct m9206_state {
27 u16 filters[M9206_MAX_FILTERS];
28 int filtering_enabled;
29 int rep_count;
30 struct {
31 unsigned char addr;
32 unsigned char magic;
33 }i2c_r[M9206_I2C_MAX];
34};
35#endif
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index af314bb1dc..22c2cf2cea 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -290,6 +290,13 @@ config DVB_TDA826X
290 help 290 help
291 A DVB-S silicon tuner module. Say Y when you want to support this tuner. 291 A DVB-S silicon tuner module. Say Y when you want to support this tuner.
292 292
293config DVB_TUNER_QT1010
294 tristate "Quantek QT1010 silicon tuner"
295 depends on DVB_CORE && I2C
296 default m if DVB_FE_CUSTOMISE
297 help
298 A driver for the silicon tuner QT1010 from Quantek.
299
293config DVB_TUNER_MT2060 300config DVB_TUNER_MT2060
294 tristate "Microtune MT2060 silicon IF tuner" 301 tristate "Microtune MT2060 silicon IF tuner"
295 depends on I2C 302 depends on I2C
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index 3fa6e5d32a..a646d9969b 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -38,5 +38,6 @@ obj-$(CONFIG_DVB_ISL6421) += isl6421.o
38obj-$(CONFIG_DVB_TDA10086) += tda10086.o 38obj-$(CONFIG_DVB_TDA10086) += tda10086.o
39obj-$(CONFIG_DVB_TDA826X) += tda826x.o 39obj-$(CONFIG_DVB_TDA826X) += tda826x.o
40obj-$(CONFIG_DVB_TUNER_MT2060) += mt2060.o 40obj-$(CONFIG_DVB_TUNER_MT2060) += mt2060.o
41obj-$(CONFIG_DVB_TUNER_QT1010) += qt1010.o
41obj-$(CONFIG_DVB_TUA6100) += tua6100.o 42obj-$(CONFIG_DVB_TUA6100) += tua6100.o
42obj-$(CONFIG_DVB_TUNER_LGH06XF) += lgh06xf.o 43obj-$(CONFIG_DVB_TUNER_LGH06XF) += lgh06xf.o
diff --git a/drivers/media/dvb/frontends/cx24110.c b/drivers/media/dvb/frontends/cx24110.c
index ae96395217..10fc0c8316 100644
--- a/drivers/media/dvb/frontends/cx24110.c
+++ b/drivers/media/dvb/frontends/cx24110.c
@@ -254,7 +254,7 @@ static int cx24110_set_symbolrate (struct cx24110_state* state, u32 srate)
254 if (srate<500000) 254 if (srate<500000)
255 srate=500000; 255 srate=500000;
256 256
257 for(i=0;(i<sizeof(bands)/sizeof(bands[0]))&&(srate>bands[i]);i++) 257 for(i = 0; (i < ARRAY_SIZE(bands)) && (srate>bands[i]); i++)
258 ; 258 ;
259 /* first, check which sample rate is appropriate: 45, 60 80 or 90 MHz, 259 /* first, check which sample rate is appropriate: 45, 60 80 or 90 MHz,
260 and set the PLL accordingly (R07[1:0] Fclk, R06[7:4] PLLmult, 260 and set the PLL accordingly (R07[1:0] Fclk, R06[7:4] PLLmult,
@@ -361,7 +361,7 @@ static int cx24110_initfe(struct dvb_frontend* fe)
361 361
362 dprintk("%s: init chip\n", __FUNCTION__); 362 dprintk("%s: init chip\n", __FUNCTION__);
363 363
364 for(i=0;i<sizeof(cx24110_regdata)/sizeof(cx24110_regdata[0]);i++) { 364 for(i = 0; i < ARRAY_SIZE(cx24110_regdata); i++) {
365 cx24110_writereg(state, cx24110_regdata[i].reg, cx24110_regdata[i].data); 365 cx24110_writereg(state, cx24110_regdata[i].reg, cx24110_regdata[i].data);
366 }; 366 };
367 367
diff --git a/drivers/media/dvb/frontends/cx24123.c b/drivers/media/dvb/frontends/cx24123.c
index a356d28fc3..732e94aaa3 100644
--- a/drivers/media/dvb/frontends/cx24123.c
+++ b/drivers/media/dvb/frontends/cx24123.c
@@ -507,7 +507,7 @@ static int cx24123_pll_calculate(struct dvb_frontend* fe, struct dvb_frontend_pa
507 int i = 0; 507 int i = 0;
508 int pump = 2; 508 int pump = 2;
509 int band = 0; 509 int band = 0;
510 int num_bands = sizeof(cx24123_bandselect_vals) / sizeof(cx24123_bandselect_vals[0]); 510 int num_bands = ARRAY_SIZE(cx24123_bandselect_vals);
511 511
512 /* Defaults for low freq, low rate */ 512 /* Defaults for low freq, low rate */
513 state->VCAarg = cx24123_AGC_vals[0].VCAprogdata; 513 state->VCAarg = cx24123_AGC_vals[0].VCAprogdata;
@@ -516,7 +516,7 @@ static int cx24123_pll_calculate(struct dvb_frontend* fe, struct dvb_frontend_pa
516 vco_div = cx24123_bandselect_vals[0].VCOdivider; 516 vco_div = cx24123_bandselect_vals[0].VCOdivider;
517 517
518 /* For the given symbol rate, determine the VCA, VGA and FILTUNE programming bits */ 518 /* For the given symbol rate, determine the VCA, VGA and FILTUNE programming bits */
519 for (i = 0; i < sizeof(cx24123_AGC_vals) / sizeof(cx24123_AGC_vals[0]); i++) 519 for (i = 0; i < ARRAY_SIZE(cx24123_AGC_vals); i++)
520 { 520 {
521 if ((cx24123_AGC_vals[i].symbolrate_low <= p->u.qpsk.symbol_rate) && 521 if ((cx24123_AGC_vals[i].symbolrate_low <= p->u.qpsk.symbol_rate) &&
522 (cx24123_AGC_vals[i].symbolrate_high >= p->u.qpsk.symbol_rate) ) { 522 (cx24123_AGC_vals[i].symbolrate_high >= p->u.qpsk.symbol_rate) ) {
@@ -658,7 +658,7 @@ static int cx24123_initfe(struct dvb_frontend* fe)
658 dprintk("%s: init frontend\n",__FUNCTION__); 658 dprintk("%s: init frontend\n",__FUNCTION__);
659 659
660 /* Configure the demod to a good set of defaults */ 660 /* Configure the demod to a good set of defaults */
661 for (i = 0; i < sizeof(cx24123_regdata) / sizeof(cx24123_regdata[0]); i++) 661 for (i = 0; i < ARRAY_SIZE(cx24123_regdata); i++)
662 cx24123_writereg(state, cx24123_regdata[i].reg, cx24123_regdata[i].data); 662 cx24123_writereg(state, cx24123_regdata[i].reg, cx24123_regdata[i].data);
663 663
664 /* Set the LNB polarity */ 664 /* Set the LNB polarity */
diff --git a/drivers/media/dvb/frontends/dib3000mb.c b/drivers/media/dvb/frontends/dib3000mb.c
index adbabfdb04..b6adea5ffe 100644
--- a/drivers/media/dvb/frontends/dib3000mb.c
+++ b/drivers/media/dvb/frontends/dib3000mb.c
@@ -239,7 +239,7 @@ static int dib3000mb_set_frontend(struct dvb_frontend* fe,
239 default: 239 default:
240 return -EINVAL; 240 return -EINVAL;
241 } 241 }
242 deb_setf("hierachy: "); 242 deb_setf("hierarchy: ");
243 switch (ofdm->hierarchy_information) { 243 switch (ofdm->hierarchy_information) {
244 case HIERARCHY_NONE: 244 case HIERARCHY_NONE:
245 deb_setf("none "); 245 deb_setf("none ");
diff --git a/drivers/media/dvb/frontends/dib3000mc.c b/drivers/media/dvb/frontends/dib3000mc.c
index 23aa75a27c..054d7e6d96 100644
--- a/drivers/media/dvb/frontends/dib3000mc.c
+++ b/drivers/media/dvb/frontends/dib3000mc.c
@@ -475,7 +475,7 @@ static void dib3000mc_set_channel_cfg(struct dib3000mc_state *state, struct dibx
475 tmp = ((chan->nfft & 0x1) << 7) | (chan->guard << 5) | (chan->nqam << 3) | chan->vit_alpha; 475 tmp = ((chan->nfft & 0x1) << 7) | (chan->guard << 5) | (chan->nqam << 3) | chan->vit_alpha;
476 dib3000mc_write_word(state, 0, tmp); 476 dib3000mc_write_word(state, 0, tmp);
477 477
478 dib3000mc_write_word(state, 5, seq); 478 dib3000mc_write_word(state, 5, (1 << 8) | ((seq & 0xf) << 4));
479 479
480 tmp = (chan->vit_hrch << 4) | (chan->vit_select_hp); 480 tmp = (chan->vit_hrch << 4) | (chan->vit_select_hp);
481 if (!chan->vit_hrch || (chan->vit_hrch && chan->vit_select_hp)) 481 if (!chan->vit_hrch || (chan->vit_hrch && chan->vit_select_hp))
diff --git a/drivers/media/dvb/frontends/qt1010.c b/drivers/media/dvb/frontends/qt1010.c
new file mode 100644
index 0000000000..825aa1412e
--- /dev/null
+++ b/drivers/media/dvb/frontends/qt1010.c
@@ -0,0 +1,485 @@
1/*
2 * Driver for Quantek QT1010 silicon tuner
3 *
4 * Copyright (C) 2006 Antti Palosaari <crope@iki.fi>
5 * Aapo Tahkola <aet@rasterburn.org>
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#include "qt1010.h"
22#include "qt1010_priv.h"
23
24static int debug;
25module_param(debug, int, 0644);
26MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
27
28#define dprintk(args...) \
29 do { \
30 if (debug) printk(KERN_DEBUG "QT1010: " args); \
31 } while (0)
32
33/* read single register */
34static int qt1010_readreg(struct qt1010_priv *priv, u8 reg, u8 *val)
35{
36 struct i2c_msg msg[2] = {
37 { .addr = priv->cfg->i2c_address,
38 .flags = 0, .buf = &reg, .len = 1 },
39 { .addr = priv->cfg->i2c_address,
40 .flags = I2C_M_RD, .buf = val, .len = 1 },
41 };
42
43 if (i2c_transfer(priv->i2c, msg, 2) != 2) {
44 printk(KERN_WARNING "qt1010 I2C read failed\n");
45 return -EREMOTEIO;
46 }
47 return 0;
48}
49
50/* write single register */
51static int qt1010_writereg(struct qt1010_priv *priv, u8 reg, u8 val)
52{
53 u8 buf[2] = { reg, val };
54 struct i2c_msg msg = { .addr = priv->cfg->i2c_address,
55 .flags = 0, .buf = buf, .len = 2 };
56
57 if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
58 printk(KERN_WARNING "qt1010 I2C write failed\n");
59 return -EREMOTEIO;
60 }
61 return 0;
62}
63
64/* dump all registers */
65static void qt1010_dump_regs(struct qt1010_priv *priv)
66{
67 char buf[52], buf2[4];
68 u8 reg, val;
69
70 for (reg = 0; ; reg++) {
71 if (reg % 16 == 0) {
72 if (reg)
73 printk("%s\n", buf);
74 sprintf(buf, "%02x: ", reg);
75 }
76 if (qt1010_readreg(priv, reg, &val) == 0)
77 sprintf(buf2, "%02x ", val);
78 else
79 strcpy(buf2, "-- ");
80 strcat(buf, buf2);
81 if (reg == 0x2f)
82 break;
83 }
84 printk("%s\n", buf);
85}
86
87static int qt1010_set_params(struct dvb_frontend *fe,
88 struct dvb_frontend_parameters *params)
89{
90 struct qt1010_priv *priv;
91 int err;
92 u32 freq, div, mod1, mod2;
93 u8 i, tmpval, reg05;
94 qt1010_i2c_oper_t rd[48] = {
95 { QT1010_WR, 0x01, 0x80 },
96 { QT1010_WR, 0x02, 0x3f },
97 { QT1010_WR, 0x05, 0xff }, /* 02 c write */
98 { QT1010_WR, 0x06, 0x44 },
99 { QT1010_WR, 0x07, 0xff }, /* 04 c write */
100 { QT1010_WR, 0x08, 0x08 },
101 { QT1010_WR, 0x09, 0xff }, /* 06 c write */
102 { QT1010_WR, 0x0a, 0xff }, /* 07 c write */
103 { QT1010_WR, 0x0b, 0xff }, /* 08 c write */
104 { QT1010_WR, 0x0c, 0xe1 },
105 { QT1010_WR, 0x1a, 0xff }, /* 10 c write */
106 { QT1010_WR, 0x1b, 0x00 },
107 { QT1010_WR, 0x1c, 0x89 },
108 { QT1010_WR, 0x11, 0xff }, /* 13 c write */
109 { QT1010_WR, 0x12, 0xff }, /* 14 c write */
110 { QT1010_WR, 0x22, 0xff }, /* 15 c write */
111 { QT1010_WR, 0x1e, 0x00 },
112 { QT1010_WR, 0x1e, 0xd0 },
113 { QT1010_RD, 0x22, 0xff }, /* 16 c read */
114 { QT1010_WR, 0x1e, 0x00 },
115 { QT1010_RD, 0x05, 0xff }, /* 20 c read */
116 { QT1010_RD, 0x22, 0xff }, /* 21 c read */
117 { QT1010_WR, 0x23, 0xd0 },
118 { QT1010_WR, 0x1e, 0x00 },
119 { QT1010_WR, 0x1e, 0xe0 },
120 { QT1010_RD, 0x23, 0xff }, /* 25 c read */
121 { QT1010_RD, 0x23, 0xff }, /* 26 c read */
122 { QT1010_WR, 0x1e, 0x00 },
123 { QT1010_WR, 0x24, 0xd0 },
124 { QT1010_WR, 0x1e, 0x00 },
125 { QT1010_WR, 0x1e, 0xf0 },
126 { QT1010_RD, 0x24, 0xff }, /* 31 c read */
127 { QT1010_WR, 0x1e, 0x00 },
128 { QT1010_WR, 0x14, 0x7f },
129 { QT1010_WR, 0x15, 0x7f },
130 { QT1010_WR, 0x05, 0xff }, /* 35 c write */
131 { QT1010_WR, 0x06, 0x00 },
132 { QT1010_WR, 0x15, 0x1f },
133 { QT1010_WR, 0x16, 0xff },
134 { QT1010_WR, 0x18, 0xff },
135 { QT1010_WR, 0x1f, 0xff }, /* 40 c write */
136 { QT1010_WR, 0x20, 0xff }, /* 41 c write */
137 { QT1010_WR, 0x21, 0x53 },
138 { QT1010_WR, 0x25, 0xff }, /* 43 c write */
139 { QT1010_WR, 0x26, 0x15 },
140 { QT1010_WR, 0x00, 0xff }, /* 45 c write */
141 { QT1010_WR, 0x02, 0x00 },
142 { QT1010_WR, 0x01, 0x00 }
143 };
144
145#define FREQ1 32000000 /* 32 MHz */
146#define FREQ2 4000000 /* 4 MHz Quartz oscillator in the stick? */
147
148 priv = fe->tuner_priv;
149 freq = params->frequency;
150 div = (freq + QT1010_OFFSET) / QT1010_STEP;
151 freq = (div * QT1010_STEP) - QT1010_OFFSET;
152 mod1 = (freq + QT1010_OFFSET) % FREQ1;
153 mod2 = (freq + QT1010_OFFSET) % FREQ2;
154 priv->bandwidth =
155 (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
156 priv->frequency = freq;
157
158 if (fe->ops.i2c_gate_ctrl)
159 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
160
161 /* reg 05 base value */
162 if (freq < 290000000) reg05 = 0x14; /* 290 MHz */
163 else if (freq < 610000000) reg05 = 0x34; /* 610 MHz */
164 else if (freq < 802000000) reg05 = 0x54; /* 802 MHz */
165 else reg05 = 0x74;
166
167 /* 0x5 */
168 rd[2].val = reg05;
169
170 /* 07 - set frequency: 32 MHz scale */
171 rd[4].val = (freq + QT1010_OFFSET) / FREQ1;
172
173 /* 09 - changes every 8/24 MHz */
174 if (mod1 < 8000000) rd[6].val = 0x1d;
175 else rd[6].val = 0x1c;
176
177 /* 0a - set frequency: 4 MHz scale (max 28 MHz) */
178 if (mod1 < 1*FREQ2) rd[7].val = 0x09; /* +0 MHz */
179 else if (mod1 < 2*FREQ2) rd[7].val = 0x08; /* +4 MHz */
180 else if (mod1 < 3*FREQ2) rd[7].val = 0x0f; /* +8 MHz */
181 else if (mod1 < 4*FREQ2) rd[7].val = 0x0e; /* +12 MHz */
182 else if (mod1 < 5*FREQ2) rd[7].val = 0x0d; /* +16 MHz */
183 else if (mod1 < 6*FREQ2) rd[7].val = 0x0c; /* +20 MHz */
184 else if (mod1 < 7*FREQ2) rd[7].val = 0x0b; /* +24 MHz */
185 else rd[7].val = 0x0a; /* +28 MHz */
186
187 /* 0b - changes every 2/2 MHz */
188 if (mod2 < 2000000) rd[8].val = 0x45;
189 else rd[8].val = 0x44;
190
191 /* 1a - set frequency: 125 kHz scale (max 3875 kHz)*/
192 tmpval = 0x78; /* byte, overflows intentionally */
193 rd[10].val = tmpval-((mod2/QT1010_STEP)*0x08);
194
195 /* 11 */
196 rd[13].val = 0xfd; /* TODO: correct value calculation */
197
198 /* 12 */
199 rd[14].val = 0x91; /* TODO: correct value calculation */
200
201 /* 22 */
202 if (freq < 450000000) rd[15].val = 0xd0; /* 450 MHz */
203 else if (freq < 482000000) rd[15].val = 0xd1; /* 482 MHz */
204 else if (freq < 514000000) rd[15].val = 0xd4; /* 514 MHz */
205 else if (freq < 546000000) rd[15].val = 0xd7; /* 546 MHz */
206 else if (freq < 610000000) rd[15].val = 0xda; /* 610 MHz */
207 else rd[15].val = 0xd0;
208
209 /* 05 */
210 rd[35].val = (reg05 & 0xf0);
211
212 /* 1f */
213 if (mod1 < 8000000) tmpval = 0x00;
214 else if (mod1 < 12000000) tmpval = 0x01;
215 else if (mod1 < 16000000) tmpval = 0x02;
216 else if (mod1 < 24000000) tmpval = 0x03;
217 else if (mod1 < 28000000) tmpval = 0x04;
218 else tmpval = 0x05;
219 rd[40].val = (priv->reg1f_init_val + 0x0e + tmpval);
220
221 /* 20 */
222 if (mod1 < 8000000) tmpval = 0x00;
223 else if (mod1 < 12000000) tmpval = 0x01;
224 else if (mod1 < 20000000) tmpval = 0x02;
225 else if (mod1 < 24000000) tmpval = 0x03;
226 else if (mod1 < 28000000) tmpval = 0x04;
227 else tmpval = 0x05;
228 rd[41].val = (priv->reg20_init_val + 0x0d + tmpval);
229
230 /* 25 */
231 rd[43].val = priv->reg25_init_val;
232
233 /* 00 */
234 rd[45].val = 0x92; /* TODO: correct value calculation */
235
236 dprintk("freq:%u 05:%02x 07:%02x 09:%02x 0a:%02x 0b:%02x " \
237 "1a:%02x 11:%02x 12:%02x 22:%02x 05:%02x 1f:%02x " \
238 "20:%02x 25:%02x 00:%02x", \
239 freq, rd[2].val, rd[4].val, rd[6].val, rd[7].val, rd[8].val, \
240 rd[10].val, rd[13].val, rd[14].val, rd[15].val, rd[35].val, \
241 rd[40].val, rd[41].val, rd[43].val, rd[45].val);
242
243 for (i = 0; i < ARRAY_SIZE(rd); i++) {
244 if (rd[i].oper == QT1010_WR) {
245 err = qt1010_writereg(priv, rd[i].reg, rd[i].val);
246 } else { /* read is required to proper locking */
247 err = qt1010_readreg(priv, rd[i].reg, &tmpval);
248 }
249 if (err) return err;
250 }
251
252 if (debug)
253 qt1010_dump_regs(priv);
254
255 if (fe->ops.i2c_gate_ctrl)
256 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
257
258 return 0;
259}
260
261static int qt1010_init_meas1(struct qt1010_priv *priv,
262 u8 oper, u8 reg, u8 reg_init_val, u8 *retval)
263{
264 u8 i, val1, val2;
265 int err;
266
267 qt1010_i2c_oper_t i2c_data[] = {
268 { QT1010_WR, reg, reg_init_val },
269 { QT1010_WR, 0x1e, 0x00 },
270 { QT1010_WR, 0x1e, oper },
271 { QT1010_RD, reg, 0xff }
272 };
273
274 for (i = 0; i < ARRAY_SIZE(i2c_data); i++) {
275 if (i2c_data[i].oper == QT1010_WR) {
276 err = qt1010_writereg(priv, i2c_data[i].reg,
277 i2c_data[i].val);
278 } else {
279 err = qt1010_readreg(priv, i2c_data[i].reg, &val2);
280 }
281 if (err) return err;
282 }
283
284 do {
285 val1 = val2;
286 err = qt1010_readreg(priv, reg, &val2);
287 if (err) return err;
288 dprintk("compare reg:%02x %02x %02x", reg, val1, val2);
289 } while (val1 != val2);
290 *retval = val1;
291
292 return qt1010_writereg(priv, 0x1e, 0x00);
293}
294
295static u8 qt1010_init_meas2(struct qt1010_priv *priv,
296 u8 reg_init_val, u8 *retval)
297{
298 u8 i, val;
299 int err;
300 qt1010_i2c_oper_t i2c_data[] = {
301 { QT1010_WR, 0x07, reg_init_val },
302 { QT1010_WR, 0x22, 0xd0 },
303 { QT1010_WR, 0x1e, 0x00 },
304 { QT1010_WR, 0x1e, 0xd0 },
305 { QT1010_RD, 0x22, 0xff },
306 { QT1010_WR, 0x1e, 0x00 },
307 { QT1010_WR, 0x22, 0xff }
308 };
309 for (i = 0; i < ARRAY_SIZE(i2c_data); i++) {
310 if (i2c_data[i].oper == QT1010_WR) {
311 err = qt1010_writereg(priv, i2c_data[i].reg,
312 i2c_data[i].val);
313 } else {
314 err = qt1010_readreg(priv, i2c_data[i].reg, &val);
315 }
316 if (err) return err;
317 }
318 *retval = val;
319 return 0;
320}
321
322static int qt1010_init(struct dvb_frontend *fe)
323{
324 struct qt1010_priv *priv = fe->tuner_priv;
325 struct dvb_frontend_parameters params;
326 int err = 0;
327 u8 i, tmpval, *valptr = NULL;
328
329 qt1010_i2c_oper_t i2c_data[] = {
330 { QT1010_WR, 0x01, 0x80 },
331 { QT1010_WR, 0x0d, 0x84 },
332 { QT1010_WR, 0x0e, 0xb7 },
333 { QT1010_WR, 0x2a, 0x23 },
334 { QT1010_WR, 0x2c, 0xdc },
335 { QT1010_M1, 0x25, 0x40 }, /* get reg 25 init value */
336 { QT1010_M1, 0x81, 0xff }, /* get reg 25 init value */
337 { QT1010_WR, 0x2b, 0x70 },
338 { QT1010_WR, 0x2a, 0x23 },
339 { QT1010_M1, 0x26, 0x08 },
340 { QT1010_M1, 0x82, 0xff },
341 { QT1010_WR, 0x05, 0x14 },
342 { QT1010_WR, 0x06, 0x44 },
343 { QT1010_WR, 0x07, 0x28 },
344 { QT1010_WR, 0x08, 0x0b },
345 { QT1010_WR, 0x11, 0xfd },
346 { QT1010_M1, 0x22, 0x0d },
347 { QT1010_M1, 0xd0, 0xff },
348 { QT1010_WR, 0x06, 0x40 },
349 { QT1010_WR, 0x16, 0xf0 },
350 { QT1010_WR, 0x02, 0x38 },
351 { QT1010_WR, 0x03, 0x18 },
352 { QT1010_WR, 0x20, 0xe0 },
353 { QT1010_M1, 0x1f, 0x20 }, /* get reg 1f init value */
354 { QT1010_M1, 0x84, 0xff }, /* get reg 1f init value */
355 { QT1010_RD, 0x20, 0x20 }, /* get reg 20 init value */
356 { QT1010_WR, 0x03, 0x19 },
357 { QT1010_WR, 0x02, 0x3f },
358 { QT1010_WR, 0x21, 0x53 },
359 { QT1010_RD, 0x21, 0xff },
360 { QT1010_WR, 0x11, 0xfd },
361 { QT1010_WR, 0x05, 0x34 },
362 { QT1010_WR, 0x06, 0x44 },
363 { QT1010_WR, 0x08, 0x08 }
364 };
365
366 if (fe->ops.i2c_gate_ctrl)
367 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
368
369 for (i = 0; i < ARRAY_SIZE(i2c_data); i++) {
370 switch (i2c_data[i].oper) {
371 case QT1010_WR:
372 err = qt1010_writereg(priv, i2c_data[i].reg,
373 i2c_data[i].val);
374 break;
375 case QT1010_RD:
376 if (i2c_data[i].val == 0x20)
377 valptr = &priv->reg20_init_val;
378 else
379 valptr = &tmpval;
380 err = qt1010_readreg(priv, i2c_data[i].reg, valptr);
381 break;
382 case QT1010_M1:
383 if (i2c_data[i].val == 0x25)
384 valptr = &priv->reg25_init_val;
385 else if (i2c_data[i].val == 0x1f)
386 valptr = &priv->reg1f_init_val;
387 else
388 valptr = &tmpval;
389 err = qt1010_init_meas1(priv, i2c_data[i+1].reg,
390 i2c_data[i].reg,
391 i2c_data[i].val, valptr);
392 i++;
393 break;
394 }
395 if (err) return err;
396 }
397
398 for (i = 0x31; i < 0x3a; i++) /* 0x31 - 0x39 */
399 if ((err = qt1010_init_meas2(priv, i, &tmpval)))
400 return err;
401
402 params.frequency = 545000000; /* Sigmatek DVB-110 545000000 */
403 /* MSI Megasky 580 GL861 533000000 */
404 return qt1010_set_params(fe, &params);
405}
406
407static int qt1010_release(struct dvb_frontend *fe)
408{
409 kfree(fe->tuner_priv);
410 fe->tuner_priv = NULL;
411 return 0;
412}
413
414static int qt1010_get_frequency(struct dvb_frontend *fe, u32 *frequency)
415{
416 struct qt1010_priv *priv = fe->tuner_priv;
417 *frequency = priv->frequency;
418 return 0;
419}
420
421static int qt1010_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
422{
423 struct qt1010_priv *priv = fe->tuner_priv;
424 *bandwidth = priv->bandwidth;
425 return 0;
426}
427
428static const struct dvb_tuner_ops qt1010_tuner_ops = {
429 .info = {
430 .name = "Quantek QT1010",
431 .frequency_min = QT1010_MIN_FREQ,
432 .frequency_max = QT1010_MAX_FREQ,
433 .frequency_step = QT1010_STEP,
434 },
435
436 .release = qt1010_release,
437 .init = qt1010_init,
438 /* TODO: implement sleep */
439
440 .set_params = qt1010_set_params,
441 .get_frequency = qt1010_get_frequency,
442 .get_bandwidth = qt1010_get_bandwidth
443};
444
445struct dvb_frontend * qt1010_attach(struct dvb_frontend *fe,
446 struct i2c_adapter *i2c,
447 struct qt1010_config *cfg)
448{
449 struct qt1010_priv *priv = NULL;
450 u8 id;
451
452 priv = kzalloc(sizeof(struct qt1010_priv), GFP_KERNEL);
453 if (priv == NULL)
454 return NULL;
455
456 priv->cfg = cfg;
457 priv->i2c = i2c;
458
459 if (fe->ops.i2c_gate_ctrl)
460 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
461
462
463 /* Try to detect tuner chip. Probably this is not correct register. */
464 if (qt1010_readreg(priv, 0x29, &id) != 0 || (id != 0x39)) {
465 kfree(priv);
466 return NULL;
467 }
468
469 if (fe->ops.i2c_gate_ctrl)
470 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
471
472 printk(KERN_INFO "Quantek QT1010 successfully identified.\n");
473 memcpy(&fe->ops.tuner_ops, &qt1010_tuner_ops,
474 sizeof(struct dvb_tuner_ops));
475
476 fe->tuner_priv = priv;
477 return fe;
478}
479EXPORT_SYMBOL(qt1010_attach);
480
481MODULE_DESCRIPTION("Quantek QT1010 silicon tuner driver");
482MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
483MODULE_AUTHOR("Aapo Tahkola <aet@rasterburn.org>");
484MODULE_VERSION("0.1");
485MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/qt1010.h b/drivers/media/dvb/frontends/qt1010.h
new file mode 100644
index 0000000000..3ab4aa045c
--- /dev/null
+++ b/drivers/media/dvb/frontends/qt1010.h
@@ -0,0 +1,53 @@
1/*
2 * Driver for Quantek QT1010 silicon tuner
3 *
4 * Copyright (C) 2006 Antti Palosaari <crope@iki.fi>
5 * Aapo Tahkola <aet@rasterburn.org>
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#ifndef QT1010_H
23#define QT1010_H
24
25#include "dvb_frontend.h"
26
27struct qt1010_config {
28 u8 i2c_address;
29};
30
31/**
32 * Attach a qt1010 tuner to the supplied frontend structure.
33 *
34 * @param fe frontend to attach to
35 * @param i2c i2c adapter to use
36 * @param cfg tuner hw based configuration
37 * @return fe pointer on success, NULL on failure
38 */
39#if defined(CONFIG_DVB_TUNER_QT1010) || (defined(CONFIG_DVB_TUNER_QT1010_MODULE) && defined(MODULE))
40extern struct dvb_frontend *qt1010_attach(struct dvb_frontend *fe,
41 struct i2c_adapter *i2c,
42 struct qt1010_config *cfg);
43#else
44static inline struct dvb_frontend *qt1010_attach(struct dvb_frontend *fe,
45 struct i2c_adapter *i2c,
46 struct qt1010_config *cfg)
47{
48 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
49 return NULL;
50}
51#endif // CONFIG_DVB_TUNER_QT1010
52
53#endif
diff --git a/drivers/media/dvb/frontends/qt1010_priv.h b/drivers/media/dvb/frontends/qt1010_priv.h
new file mode 100644
index 0000000000..090cf475f0
--- /dev/null
+++ b/drivers/media/dvb/frontends/qt1010_priv.h
@@ -0,0 +1,105 @@
1/*
2 * Driver for Quantek QT1010 silicon tuner
3 *
4 * Copyright (C) 2006 Antti Palosaari <crope@iki.fi>
5 * Aapo Tahkola <aet@rasterburn.org>
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#ifndef QT1010_PRIV_H
23#define QT1010_PRIV_H
24
25/*
26reg def meaning
27=== === =======
2800 00 ?
2901 a0 ? operation start/stop; start=80, stop=00
3002 00 ?
3103 19 ?
3204 00 ?
3305 00 ? maybe band selection
3406 00 ?
3507 2b set frequency: 32 MHz scale, n*32 MHz
3608 0b ?
3709 10 ? changes every 8/24 MHz; values 1d/1c
380a 08 set frequency: 4 MHz scale, n*4 MHz
390b 41 ? changes every 2/2 MHz; values 45/45
400c e1 ?
410d 94 ?
420e b6 ?
430f 2c ?
4410 10 ?
4511 f1 ? maybe device specified adjustment
4612 11 ? maybe device specified adjustment
4713 3f ?
4814 1f ?
4915 3f ?
5016 ff ?
5117 ff ?
5218 f7 ?
5319 80 ?
541a d0 set frequency: 125 kHz scale, n*125 kHz
551b 00 ?
561c 89 ?
571d 00 ?
581e 00 ? looks like operation register; write cmd here, read result from 1f-26
591f 20 ? chip initialization
6020 e0 ? chip initialization
6121 20 ?
6222 d0 ?
6323 d0 ?
6424 d0 ?
6525 40 ? chip initialization
6626 08 ?
6727 29 ?
6828 55 ?
6929 39 ?
702a 13 ?
712b 01 ?
722c ea ?
732d 00 ?
742e 00 ? not used?
752f 00 ? not used?
76*/
77
78#define QT1010_STEP 125000 /* 125 kHz used by Windows drivers,
79 hw could be more precise but we don't
80 know how to use */
81#define QT1010_MIN_FREQ 48000000 /* 48 MHz */
82#define QT1010_MAX_FREQ 860000000 /* 860 MHz */
83#define QT1010_OFFSET 1246000000 /* 1246 MHz */
84
85#define QT1010_WR 0
86#define QT1010_RD 1
87#define QT1010_M1 3
88
89typedef struct {
90 u8 oper, reg, val;
91} qt1010_i2c_oper_t;
92
93struct qt1010_priv {
94 struct qt1010_config *cfg;
95 struct i2c_adapter *i2c;
96
97 u8 reg1f_init_val;
98 u8 reg20_init_val;
99 u8 reg25_init_val;
100
101 u32 frequency;
102 u32 bandwidth;
103};
104
105#endif
diff --git a/drivers/media/dvb/frontends/stv0297.c b/drivers/media/dvb/frontends/stv0297.c
index 1ca6424901..9a343972ff 100644
--- a/drivers/media/dvb/frontends/stv0297.c
+++ b/drivers/media/dvb/frontends/stv0297.c
@@ -35,6 +35,7 @@ struct stv0297_state {
35 const struct stv0297_config *config; 35 const struct stv0297_config *config;
36 struct dvb_frontend frontend; 36 struct dvb_frontend frontend;
37 37
38 unsigned long last_ber;
38 unsigned long base_freq; 39 unsigned long base_freq;
39}; 40};
40 41
@@ -310,6 +311,8 @@ static int stv0297_init(struct dvb_frontend *fe)
310 stv0297_writereg(state, state->config->inittab[i], state->config->inittab[i+1]); 311 stv0297_writereg(state, state->config->inittab[i], state->config->inittab[i+1]);
311 msleep(200); 312 msleep(200);
312 313
314 state->last_ber = 0;
315
313 return 0; 316 return 0;
314} 317}
315 318
@@ -340,11 +343,13 @@ static int stv0297_read_ber(struct dvb_frontend *fe, u32 * ber)
340 struct stv0297_state *state = fe->demodulator_priv; 343 struct stv0297_state *state = fe->demodulator_priv;
341 u8 BER[3]; 344 u8 BER[3];
342 345
343 stv0297_writereg(state, 0xA0, 0x80); // Start Counting bit errors for 4096 Bytes
344 mdelay(25); // Hopefully got 4096 Bytes
345 stv0297_readregs(state, 0xA0, BER, 3); 346 stv0297_readregs(state, 0xA0, BER, 3);
346 mdelay(25); 347 if (!(BER[0] & 0x80)) {
347 *ber = (BER[2] << 8 | BER[1]) / (8 * 4096); 348 state->last_ber = BER[2] << 8 | BER[1];
349 stv0297_writereg_mask(state, 0xA0, 0x80, 0x80);
350 }
351
352 *ber = state->last_ber;
348 353
349 return 0; 354 return 0;
350} 355}
@@ -376,9 +381,14 @@ static int stv0297_read_ucblocks(struct dvb_frontend *fe, u32 * ucblocks)
376{ 381{
377 struct stv0297_state *state = fe->demodulator_priv; 382 struct stv0297_state *state = fe->demodulator_priv;
378 383
384 stv0297_writereg_mask(state, 0xDF, 0x03, 0x03); /* freeze the counters */
385
379 *ucblocks = (stv0297_readreg(state, 0xD5) << 8) 386 *ucblocks = (stv0297_readreg(state, 0xD5) << 8)
380 | stv0297_readreg(state, 0xD4); 387 | stv0297_readreg(state, 0xD4);
381 388
389 stv0297_writereg_mask(state, 0xDF, 0x03, 0x02); /* clear the counters */
390 stv0297_writereg_mask(state, 0xDF, 0x03, 0x01); /* re-enable the counters */
391
382 return 0; 392 return 0;
383} 393}
384 394
@@ -648,6 +658,7 @@ struct dvb_frontend *stv0297_attach(const struct stv0297_config *config,
648 /* setup the state */ 658 /* setup the state */
649 state->config = config; 659 state->config = config;
650 state->i2c = i2c; 660 state->i2c = i2c;
661 state->last_ber = 0;
651 state->base_freq = 0; 662 state->base_freq = 0;
652 663
653 /* check if the demod is there */ 664 /* check if the demod is there */
diff --git a/drivers/media/dvb/frontends/stv0299.c b/drivers/media/dvb/frontends/stv0299.c
index 93483769ec..18768d2f6d 100644
--- a/drivers/media/dvb/frontends/stv0299.c
+++ b/drivers/media/dvb/frontends/stv0299.c
@@ -92,7 +92,7 @@ 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_write(struct dvb_frontend* fe, u8 *buf, int len) 95static int 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
diff --git a/drivers/media/dvb/frontends/tda10021.c b/drivers/media/dvb/frontends/tda10021.c
index dca89171be..5b9c5bb29b 100644
--- a/drivers/media/dvb/frontends/tda10021.c
+++ b/drivers/media/dvb/frontends/tda10021.c
@@ -201,7 +201,7 @@ static int tda10021_set_symbolrate (struct tda10021_state* state, u32 symbolrate
201 return 0; 201 return 0;
202} 202}
203 203
204int tda10021_write(struct dvb_frontend* fe, u8 *buf, int len) 204static int tda10021_write(struct dvb_frontend* fe, u8 *buf, int len)
205{ 205{
206 struct tda10021_state* state = fe->demodulator_priv; 206 struct tda10021_state* state = fe->demodulator_priv;
207 207
diff --git a/drivers/media/dvb/frontends/tda1004x.c b/drivers/media/dvb/frontends/tda1004x.c
index 00e4bcd9f1..f4a9cf9d26 100644
--- a/drivers/media/dvb/frontends/tda1004x.c
+++ b/drivers/media/dvb/frontends/tda1004x.c
@@ -579,7 +579,7 @@ static int tda1004x_decode_fec(int tdafec)
579 return -1; 579 return -1;
580} 580}
581 581
582int tda1004x_write(struct dvb_frontend* fe, u8 *buf, int len) 582static int 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
diff --git a/drivers/media/dvb/frontends/zl10353.c b/drivers/media/dvb/frontends/zl10353.c
index 0e9b59af27..245f9b7ddd 100644
--- a/drivers/media/dvb/frontends/zl10353.c
+++ b/drivers/media/dvb/frontends/zl10353.c
@@ -38,6 +38,12 @@ struct zl10353_state {
38 struct zl10353_config config; 38 struct zl10353_config config;
39}; 39};
40 40
41static int debug;
42#define dprintk(args...) \
43 do { \
44 if (debug) printk(KERN_DEBUG "zl10353: " args); \
45 } while (0)
46
41static int debug_regs = 0; 47static int debug_regs = 0;
42 48
43static int zl10353_single_write(struct dvb_frontend *fe, u8 reg, u8 val) 49static int zl10353_single_write(struct dvb_frontend *fe, u8 reg, u8 val)
@@ -54,7 +60,7 @@ static int zl10353_single_write(struct dvb_frontend *fe, u8 reg, u8 val)
54 return 0; 60 return 0;
55} 61}
56 62
57int zl10353_write(struct dvb_frontend *fe, u8 *ibuf, int ilen) 63static int zl10353_write(struct dvb_frontend *fe, u8 *ibuf, int ilen)
58{ 64{
59 int err, i; 65 int err, i;
60 for (i = 0; i < ilen - 1; i++) 66 for (i = 0; i < ilen - 1; i++)
@@ -113,6 +119,36 @@ static void zl10353_dump_regs(struct dvb_frontend *fe)
113 printk(KERN_DEBUG "%s\n", buf); 119 printk(KERN_DEBUG "%s\n", buf);
114} 120}
115 121
122static void zl10353_calc_nominal_rate(struct dvb_frontend *fe,
123 enum fe_bandwidth bandwidth,
124 u16 *nominal_rate)
125{
126 u32 adc_clock = 22528; /* 20.480 MHz on the board(!?) */
127 u8 bw;
128 struct zl10353_state *state = fe->demodulator_priv;
129
130 if (state->config.adc_clock)
131 adc_clock = state->config.adc_clock;
132
133 switch (bandwidth) {
134 case BANDWIDTH_6_MHZ:
135 bw = 6;
136 break;
137 case BANDWIDTH_7_MHZ:
138 bw = 7;
139 break;
140 case BANDWIDTH_8_MHZ:
141 default:
142 bw = 8;
143 break;
144 }
145
146 *nominal_rate = (64 * bw * (1<<16) / (7 * 8) * 4000 / adc_clock + 2) / 4;
147
148 dprintk("%s: bw %d, adc_clock %d => 0x%x\n",
149 __FUNCTION__, bw, adc_clock, *nominal_rate);
150}
151
116static int zl10353_sleep(struct dvb_frontend *fe) 152static int zl10353_sleep(struct dvb_frontend *fe)
117{ 153{
118 static u8 zl10353_softdown[] = { 0x50, 0x0C, 0x44 }; 154 static u8 zl10353_softdown[] = { 0x50, 0x0C, 0x44 };
@@ -125,7 +161,7 @@ static int zl10353_set_parameters(struct dvb_frontend *fe,
125 struct dvb_frontend_parameters *param) 161 struct dvb_frontend_parameters *param)
126{ 162{
127 struct zl10353_state *state = fe->demodulator_priv; 163 struct zl10353_state *state = fe->demodulator_priv;
128 164 u16 nominal_rate;
129 u8 pllbuf[6] = { 0x67 }; 165 u8 pllbuf[6] = { 0x67 };
130 166
131 /* These settings set "auto-everything" and start the FSM. */ 167 /* These settings set "auto-everything" and start the FSM. */
@@ -138,18 +174,23 @@ static int zl10353_set_parameters(struct dvb_frontend *fe,
138 zl10353_single_write(fe, 0x56, 0x28); 174 zl10353_single_write(fe, 0x56, 0x28);
139 zl10353_single_write(fe, 0x89, 0x20); 175 zl10353_single_write(fe, 0x89, 0x20);
140 zl10353_single_write(fe, 0x5E, 0x00); 176 zl10353_single_write(fe, 0x5E, 0x00);
141 zl10353_single_write(fe, 0x65, 0x5A); 177
142 zl10353_single_write(fe, 0x66, 0xE9); 178 zl10353_calc_nominal_rate(fe, param->u.ofdm.bandwidth, &nominal_rate);
179 zl10353_single_write(fe, TRL_NOMINAL_RATE_1, msb(nominal_rate));
180 zl10353_single_write(fe, TRL_NOMINAL_RATE_0, lsb(nominal_rate));
181
143 zl10353_single_write(fe, 0x6C, 0xCD); 182 zl10353_single_write(fe, 0x6C, 0xCD);
144 zl10353_single_write(fe, 0x6D, 0x7E); 183 zl10353_single_write(fe, 0x6D, 0x7E);
145 zl10353_single_write(fe, 0x62, 0x0A); 184 if (fe->ops.i2c_gate_ctrl)
185 fe->ops.i2c_gate_ctrl(fe, 0);
146 186
147 // if there is no attached secondary tuner, we call set_params to program 187 // if there is no attached secondary tuner, we call set_params to program
148 // a potential tuner attached somewhere else 188 // a potential tuner attached somewhere else
149 if (state->config.no_tuner) { 189 if (state->config.no_tuner) {
150 if (fe->ops.tuner_ops.set_params) { 190 if (fe->ops.tuner_ops.set_params) {
151 fe->ops.tuner_ops.set_params(fe, param); 191 fe->ops.tuner_ops.set_params(fe, param);
152 if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0); 192 if (fe->ops.i2c_gate_ctrl)
193 fe->ops.i2c_gate_ctrl(fe, 0);
153 } 194 }
154 } 195 }
155 196
@@ -213,6 +254,29 @@ static int zl10353_read_status(struct dvb_frontend *fe, fe_status_t *status)
213 return 0; 254 return 0;
214} 255}
215 256
257static int zl10353_read_ber(struct dvb_frontend *fe, u32 *ber)
258{
259 struct zl10353_state *state = fe->demodulator_priv;
260
261 *ber = zl10353_read_register(state, RS_ERR_CNT_2) << 16 |
262 zl10353_read_register(state, RS_ERR_CNT_1) << 8 |
263 zl10353_read_register(state, RS_ERR_CNT_0);
264
265 return 0;
266}
267
268static int zl10353_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
269{
270 struct zl10353_state *state = fe->demodulator_priv;
271
272 u16 signal = zl10353_read_register(state, AGC_GAIN_1) << 10 |
273 zl10353_read_register(state, AGC_GAIN_0) << 2 | 3;
274
275 *strength = ~signal;
276
277 return 0;
278}
279
216static int zl10353_read_snr(struct dvb_frontend *fe, u16 *snr) 280static int zl10353_read_snr(struct dvb_frontend *fe, u16 *snr)
217{ 281{
218 struct zl10353_state *state = fe->demodulator_priv; 282 struct zl10353_state *state = fe->demodulator_priv;
@@ -227,6 +291,16 @@ static int zl10353_read_snr(struct dvb_frontend *fe, u16 *snr)
227 return 0; 291 return 0;
228} 292}
229 293
294static int zl10353_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
295{
296 struct zl10353_state *state = fe->demodulator_priv;
297
298 *ucblocks = zl10353_read_register(state, RS_UBC_1) << 8 |
299 zl10353_read_register(state, RS_UBC_0);
300
301 return 0;
302}
303
230static int zl10353_get_tune_settings(struct dvb_frontend *fe, 304static int zl10353_get_tune_settings(struct dvb_frontend *fe,
231 struct dvb_frontend_tune_settings 305 struct dvb_frontend_tune_settings
232 *fe_tune_settings) 306 *fe_tune_settings)
@@ -261,6 +335,16 @@ static int zl10353_init(struct dvb_frontend *fe)
261 return 0; 335 return 0;
262} 336}
263 337
338static int zl10353_i2c_gate_ctrl(struct dvb_frontend* fe, int enable)
339{
340 u8 val = 0x0a;
341
342 if (enable)
343 val |= 0x10;
344
345 return zl10353_single_write(fe, 0x62, val);
346}
347
264static void zl10353_release(struct dvb_frontend *fe) 348static void zl10353_release(struct dvb_frontend *fe)
265{ 349{
266 struct zl10353_state *state = fe->demodulator_priv; 350 struct zl10353_state *state = fe->demodulator_priv;
@@ -319,15 +403,22 @@ static struct dvb_frontend_ops zl10353_ops = {
319 403
320 .init = zl10353_init, 404 .init = zl10353_init,
321 .sleep = zl10353_sleep, 405 .sleep = zl10353_sleep,
406 .i2c_gate_ctrl = zl10353_i2c_gate_ctrl,
322 .write = zl10353_write, 407 .write = zl10353_write,
323 408
324 .set_frontend = zl10353_set_parameters, 409 .set_frontend = zl10353_set_parameters,
325 .get_tune_settings = zl10353_get_tune_settings, 410 .get_tune_settings = zl10353_get_tune_settings,
326 411
327 .read_status = zl10353_read_status, 412 .read_status = zl10353_read_status,
413 .read_ber = zl10353_read_ber,
414 .read_signal_strength = zl10353_read_signal_strength,
328 .read_snr = zl10353_read_snr, 415 .read_snr = zl10353_read_snr,
416 .read_ucblocks = zl10353_read_ucblocks,
329}; 417};
330 418
419module_param(debug, int, 0644);
420MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
421
331module_param(debug_regs, int, 0644); 422module_param(debug_regs, int, 0644);
332MODULE_PARM_DESC(debug_regs, "Turn on/off frontend register dumps (default:off)."); 423MODULE_PARM_DESC(debug_regs, "Turn on/off frontend register dumps (default:off).");
333 424
diff --git a/drivers/media/dvb/frontends/zl10353.h b/drivers/media/dvb/frontends/zl10353.h
index 0bc0109737..cb274dc12b 100644
--- a/drivers/media/dvb/frontends/zl10353.h
+++ b/drivers/media/dvb/frontends/zl10353.h
@@ -29,6 +29,9 @@ struct zl10353_config
29 /* demodulator's I2C address */ 29 /* demodulator's I2C address */
30 u8 demod_address; 30 u8 demod_address;
31 31
32 /* frequencies in kHz */
33 int adc_clock; // default: 22528
34
32 /* set if no pll is connected to the secondary i2c bus */ 35 /* set if no pll is connected to the secondary i2c bus */
33 int no_tuner; 36 int no_tuner;
34 37
diff --git a/drivers/media/dvb/frontends/zl10353_priv.h b/drivers/media/dvb/frontends/zl10353_priv.h
index b72224bd7d..4962434b35 100644
--- a/drivers/media/dvb/frontends/zl10353_priv.h
+++ b/drivers/media/dvb/frontends/zl10353_priv.h
@@ -24,19 +24,31 @@
24 24
25#define ID_ZL10353 0x14 25#define ID_ZL10353 0x14
26 26
27#define msb(x) (((x) >> 8) & 0xff)
28#define lsb(x) ((x) & 0xff)
29
27enum zl10353_reg_addr { 30enum zl10353_reg_addr {
28 INTERRUPT_0 = 0x00, 31 INTERRUPT_0 = 0x00,
29 INTERRUPT_1 = 0x01, 32 INTERRUPT_1 = 0x01,
30 INTERRUPT_2 = 0x02, 33 INTERRUPT_2 = 0x02,
31 INTERRUPT_3 = 0x03, 34 INTERRUPT_3 = 0x03,
32 INTERRUPT_4 = 0x04, 35 INTERRUPT_4 = 0x04,
33 INTERRUPT_5 = 0x05, 36 INTERRUPT_5 = 0x05,
34 STATUS_6 = 0x06, 37 STATUS_6 = 0x06,
35 STATUS_7 = 0x07, 38 STATUS_7 = 0x07,
36 STATUS_8 = 0x08, 39 STATUS_8 = 0x08,
37 STATUS_9 = 0x09, 40 STATUS_9 = 0x09,
38 SNR = 0x10, 41 AGC_GAIN_1 = 0x0A,
39 CHIP_ID = 0x7F, 42 AGC_GAIN_0 = 0x0B,
43 SNR = 0x10,
44 RS_ERR_CNT_2 = 0x11,
45 RS_ERR_CNT_1 = 0x12,
46 RS_ERR_CNT_0 = 0x13,
47 RS_UBC_1 = 0x14,
48 RS_UBC_0 = 0x15,
49 TRL_NOMINAL_RATE_1 = 0x65,
50 TRL_NOMINAL_RATE_0 = 0x66,
51 CHIP_ID = 0x7F,
40}; 52};
41 53
42#endif /* _ZL10353_PRIV_ */ 54#endif /* _ZL10353_PRIV_ */
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index 366c1371ee..29ed532ba9 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -51,6 +51,7 @@
51#include <linux/firmware.h> 51#include <linux/firmware.h>
52#include <linux/crc32.h> 52#include <linux/crc32.h>
53#include <linux/i2c.h> 53#include <linux/i2c.h>
54#include <linux/kthread.h>
54 55
55#include <asm/system.h> 56#include <asm/system.h>
56 57
@@ -223,11 +224,10 @@ static void recover_arm(struct av7110 *av7110)
223 224
224static void av7110_arm_sync(struct av7110 *av7110) 225static void av7110_arm_sync(struct av7110 *av7110)
225{ 226{
226 av7110->arm_rmmod = 1; 227 if (av7110->arm_thread)
227 wake_up_interruptible(&av7110->arm_wait); 228 kthread_stop(av7110->arm_thread);
228 229
229 while (av7110->arm_thread) 230 av7110->arm_thread = NULL;
230 msleep(1);
231} 231}
232 232
233static int arm_thread(void *data) 233static int arm_thread(void *data)
@@ -238,17 +238,11 @@ static int arm_thread(void *data)
238 238
239 dprintk(4, "%p\n",av7110); 239 dprintk(4, "%p\n",av7110);
240 240
241 lock_kernel();
242 daemonize("arm_mon");
243 sigfillset(&current->blocked);
244 unlock_kernel();
245
246 av7110->arm_thread = current;
247
248 for (;;) { 241 for (;;) {
249 timeout = wait_event_interruptible_timeout(av7110->arm_wait, 242 timeout = wait_event_interruptible_timeout(av7110->arm_wait,
250 av7110->arm_rmmod, 5 * HZ); 243 kthread_should_stop(), 5 * HZ);
251 if (-ERESTARTSYS == timeout || av7110->arm_rmmod) { 244
245 if (-ERESTARTSYS == timeout || kthread_should_stop()) {
252 /* got signal or told to quit*/ 246 /* got signal or told to quit*/
253 break; 247 break;
254 } 248 }
@@ -276,7 +270,6 @@ static int arm_thread(void *data)
276 av7110->arm_errors = 0; 270 av7110->arm_errors = 0;
277 } 271 }
278 272
279 av7110->arm_thread = NULL;
280 return 0; 273 return 0;
281} 274}
282 275
@@ -695,8 +688,8 @@ static void gpioirq(unsigned long data)
695static int dvb_osd_ioctl(struct inode *inode, struct file *file, 688static int dvb_osd_ioctl(struct inode *inode, struct file *file,
696 unsigned int cmd, void *parg) 689 unsigned int cmd, void *parg)
697{ 690{
698 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 691 struct dvb_device *dvbdev = file->private_data;
699 struct av7110 *av7110 = (struct av7110 *) dvbdev->priv; 692 struct av7110 *av7110 = dvbdev->priv;
700 693
701 dprintk(4, "%p\n", av7110); 694 dprintk(4, "%p\n", av7110);
702 695
@@ -786,7 +779,7 @@ int ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid,
786static int StartHWFilter(struct dvb_demux_filter *dvbdmxfilter) 779static int StartHWFilter(struct dvb_demux_filter *dvbdmxfilter)
787{ 780{
788 struct dvb_demux_feed *dvbdmxfeed = dvbdmxfilter->feed; 781 struct dvb_demux_feed *dvbdmxfeed = dvbdmxfilter->feed;
789 struct av7110 *av7110 = (struct av7110 *) dvbdmxfeed->demux->priv; 782 struct av7110 *av7110 = dvbdmxfeed->demux->priv;
790 u16 buf[20]; 783 u16 buf[20];
791 int ret, i; 784 int ret, i;
792 u16 handle; 785 u16 handle;
@@ -835,7 +828,7 @@ static int StartHWFilter(struct dvb_demux_filter *dvbdmxfilter)
835 828
836static int StopHWFilter(struct dvb_demux_filter *dvbdmxfilter) 829static int StopHWFilter(struct dvb_demux_filter *dvbdmxfilter)
837{ 830{
838 struct av7110 *av7110 = (struct av7110 *) dvbdmxfilter->feed->demux->priv; 831 struct av7110 *av7110 = dvbdmxfilter->feed->demux->priv;
839 u16 buf[3]; 832 u16 buf[3];
840 u16 answ[2]; 833 u16 answ[2];
841 int ret; 834 int ret;
@@ -871,7 +864,7 @@ static int StopHWFilter(struct dvb_demux_filter *dvbdmxfilter)
871static int dvb_feed_start_pid(struct dvb_demux_feed *dvbdmxfeed) 864static int dvb_feed_start_pid(struct dvb_demux_feed *dvbdmxfeed)
872{ 865{
873 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 866 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
874 struct av7110 *av7110 = (struct av7110 *) dvbdmx->priv; 867 struct av7110 *av7110 = dvbdmx->priv;
875 u16 *pid = dvbdmx->pids, npids[5]; 868 u16 *pid = dvbdmx->pids, npids[5];
876 int i; 869 int i;
877 int ret = 0; 870 int ret = 0;
@@ -914,7 +907,7 @@ static int dvb_feed_start_pid(struct dvb_demux_feed *dvbdmxfeed)
914static int dvb_feed_stop_pid(struct dvb_demux_feed *dvbdmxfeed) 907static int dvb_feed_stop_pid(struct dvb_demux_feed *dvbdmxfeed)
915{ 908{
916 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 909 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
917 struct av7110 *av7110 = (struct av7110 *) dvbdmx->priv; 910 struct av7110 *av7110 = dvbdmx->priv;
918 u16 *pid = dvbdmx->pids, npids[5]; 911 u16 *pid = dvbdmx->pids, npids[5];
919 int i; 912 int i;
920 913
@@ -1103,9 +1096,9 @@ static int dvb_get_stc(struct dmx_demux *demux, unsigned int num,
1103 1096
1104 /* pointer casting paranoia... */ 1097 /* pointer casting paranoia... */
1105 BUG_ON(!demux); 1098 BUG_ON(!demux);
1106 dvbdemux = (struct dvb_demux *) demux->priv; 1099 dvbdemux = demux->priv;
1107 BUG_ON(!dvbdemux); 1100 BUG_ON(!dvbdemux);
1108 av7110 = (struct av7110 *) dvbdemux->priv; 1101 av7110 = dvbdemux->priv;
1109 1102
1110 dprintk(4, "%p\n", av7110); 1103 dprintk(4, "%p\n", av7110);
1111 1104
@@ -1137,7 +1130,7 @@ static int dvb_get_stc(struct dmx_demux *demux, unsigned int num,
1137 1130
1138static int av7110_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 1131static int av7110_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
1139{ 1132{
1140 struct av7110* av7110 = (struct av7110*) fe->dvb->priv; 1133 struct av7110* av7110 = fe->dvb->priv;
1141 1134
1142 switch (tone) { 1135 switch (tone) {
1143 case SEC_TONE_ON: 1136 case SEC_TONE_ON:
@@ -1197,7 +1190,7 @@ static int start_ts_capture(struct av7110 *budget)
1197static int budget_start_feed(struct dvb_demux_feed *feed) 1190static int budget_start_feed(struct dvb_demux_feed *feed)
1198{ 1191{
1199 struct dvb_demux *demux = feed->demux; 1192 struct dvb_demux *demux = feed->demux;
1200 struct av7110 *budget = (struct av7110 *) demux->priv; 1193 struct av7110 *budget = demux->priv;
1201 int status; 1194 int status;
1202 1195
1203 dprintk(2, "av7110: %p\n", budget); 1196 dprintk(2, "av7110: %p\n", budget);
@@ -1212,7 +1205,7 @@ static int budget_start_feed(struct dvb_demux_feed *feed)
1212static int budget_stop_feed(struct dvb_demux_feed *feed) 1205static int budget_stop_feed(struct dvb_demux_feed *feed)
1213{ 1206{
1214 struct dvb_demux *demux = feed->demux; 1207 struct dvb_demux *demux = feed->demux;
1215 struct av7110 *budget = (struct av7110 *) demux->priv; 1208 struct av7110 *budget = demux->priv;
1216 int status; 1209 int status;
1217 1210
1218 dprintk(2, "budget: %p\n", budget); 1211 dprintk(2, "budget: %p\n", budget);
@@ -1551,7 +1544,7 @@ static int get_firmware(struct av7110* av7110)
1551 1544
1552static int alps_bsrv2_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters *params) 1545static int alps_bsrv2_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters *params)
1553{ 1546{
1554 struct av7110* av7110 = (struct av7110*) fe->dvb->priv; 1547 struct av7110* av7110 = fe->dvb->priv;
1555 u8 pwr = 0; 1548 u8 pwr = 0;
1556 u8 buf[4]; 1549 u8 buf[4];
1557 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) }; 1550 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
@@ -1702,7 +1695,7 @@ static int alps_tdlb7_tuner_set_params(struct dvb_frontend* fe, struct dvb_front
1702static int alps_tdlb7_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name) 1695static int alps_tdlb7_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name)
1703{ 1696{
1704#if defined(CONFIG_DVB_SP8870) || defined(CONFIG_DVB_SP8870_MODULE) 1697#if defined(CONFIG_DVB_SP8870) || defined(CONFIG_DVB_SP8870_MODULE)
1705 struct av7110* av7110 = (struct av7110*) fe->dvb->priv; 1698 struct av7110* av7110 = fe->dvb->priv;
1706 1699
1707 return request_firmware(fw, name, &av7110->dev->pci->dev); 1700 return request_firmware(fw, name, &av7110->dev->pci->dev);
1708#else 1701#else
@@ -1867,7 +1860,7 @@ static struct stv0297_config nexusca_stv0297_config = {
1867 1860
1868static int grundig_29504_401_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters *params) 1861static int grundig_29504_401_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters *params)
1869{ 1862{
1870 struct av7110* av7110 = (struct av7110*) fe->dvb->priv; 1863 struct av7110* av7110 = fe->dvb->priv;
1871 u32 div; 1864 u32 div;
1872 u8 cfg, cpump, band_select; 1865 u8 cfg, cpump, band_select;
1873 u8 data[4]; 1866 u8 data[4];
@@ -2338,6 +2331,7 @@ static int __devinit av7110_attach(struct saa7146_dev* dev,
2338 const int length = TS_WIDTH * TS_HEIGHT; 2331 const int length = TS_WIDTH * TS_HEIGHT;
2339 struct pci_dev *pdev = dev->pci; 2332 struct pci_dev *pdev = dev->pci;
2340 struct av7110 *av7110; 2333 struct av7110 *av7110;
2334 struct task_struct *thread;
2341 int ret, count = 0; 2335 int ret, count = 0;
2342 2336
2343 dprintk(4, "dev: %p\n", dev); 2337 dprintk(4, "dev: %p\n", dev);
@@ -2622,9 +2616,12 @@ static int __devinit av7110_attach(struct saa7146_dev* dev,
2622 printk ("dvb-ttpci: Warning, firmware version 0x%04x is too old. " 2616 printk ("dvb-ttpci: Warning, firmware version 0x%04x is too old. "
2623 "System might be unstable!\n", FW_VERSION(av7110->arm_app)); 2617 "System might be unstable!\n", FW_VERSION(av7110->arm_app));
2624 2618
2625 ret = kernel_thread(arm_thread, (void *) av7110, 0); 2619 thread = kthread_run(arm_thread, (void *) av7110, "arm_mon");
2626 if (ret < 0) 2620 if (IS_ERR(thread)) {
2621 ret = PTR_ERR(thread);
2627 goto err_stop_arm_9; 2622 goto err_stop_arm_9;
2623 }
2624 av7110->arm_thread = thread;
2628 2625
2629 /* set initial volume in mixer struct */ 2626 /* set initial volume in mixer struct */
2630 av7110->mixer.volume_left = volume; 2627 av7110->mixer.volume_left = volume;
diff --git a/drivers/media/dvb/ttpci/av7110.h b/drivers/media/dvb/ttpci/av7110.h
index 9c79696da0..b98bd453ca 100644
--- a/drivers/media/dvb/ttpci/av7110.h
+++ b/drivers/media/dvb/ttpci/av7110.h
@@ -35,7 +35,6 @@
35 35
36#define ANALOG_TUNER_VES1820 1 36#define ANALOG_TUNER_VES1820 1
37#define ANALOG_TUNER_STV0297 2 37#define ANALOG_TUNER_STV0297 2
38#define ANALOG_TUNER_VBI 0x100
39 38
40extern int av7110_debug; 39extern int av7110_debug;
41 40
@@ -205,7 +204,6 @@ struct av7110 {
205 struct task_struct *arm_thread; 204 struct task_struct *arm_thread;
206 wait_queue_head_t arm_wait; 205 wait_queue_head_t arm_wait;
207 u16 arm_loops; 206 u16 arm_loops;
208 int arm_rmmod;
209 207
210 void *debi_virt; 208 void *debi_virt;
211 dma_addr_t debi_bus; 209 dma_addr_t debi_bus;
diff --git a/drivers/media/dvb/ttpci/av7110_av.c b/drivers/media/dvb/ttpci/av7110_av.c
index 795e6e9591..e719af8076 100644
--- a/drivers/media/dvb/ttpci/av7110_av.c
+++ b/drivers/media/dvb/ttpci/av7110_av.c
@@ -880,8 +880,8 @@ static int dvb_video_get_event (struct av7110 *av7110, struct video_event *event
880 880
881static unsigned int dvb_video_poll(struct file *file, poll_table *wait) 881static unsigned int dvb_video_poll(struct file *file, poll_table *wait)
882{ 882{
883 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 883 struct dvb_device *dvbdev = file->private_data;
884 struct av7110 *av7110 = (struct av7110 *) dvbdev->priv; 884 struct av7110 *av7110 = dvbdev->priv;
885 unsigned int mask = 0; 885 unsigned int mask = 0;
886 886
887 dprintk(2, "av7110:%p, \n", av7110); 887 dprintk(2, "av7110:%p, \n", av7110);
@@ -908,8 +908,8 @@ static unsigned int dvb_video_poll(struct file *file, poll_table *wait)
908static ssize_t dvb_video_write(struct file *file, const char __user *buf, 908static ssize_t dvb_video_write(struct file *file, const char __user *buf,
909 size_t count, loff_t *ppos) 909 size_t count, loff_t *ppos)
910{ 910{
911 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 911 struct dvb_device *dvbdev = file->private_data;
912 struct av7110 *av7110 = (struct av7110 *) dvbdev->priv; 912 struct av7110 *av7110 = dvbdev->priv;
913 913
914 dprintk(2, "av7110:%p, \n", av7110); 914 dprintk(2, "av7110:%p, \n", av7110);
915 915
@@ -924,8 +924,8 @@ static ssize_t dvb_video_write(struct file *file, const char __user *buf,
924 924
925static unsigned int dvb_audio_poll(struct file *file, poll_table *wait) 925static unsigned int dvb_audio_poll(struct file *file, poll_table *wait)
926{ 926{
927 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 927 struct dvb_device *dvbdev = file->private_data;
928 struct av7110 *av7110 = (struct av7110 *) dvbdev->priv; 928 struct av7110 *av7110 = dvbdev->priv;
929 unsigned int mask = 0; 929 unsigned int mask = 0;
930 930
931 dprintk(2, "av7110:%p, \n", av7110); 931 dprintk(2, "av7110:%p, \n", av7110);
@@ -944,8 +944,8 @@ static unsigned int dvb_audio_poll(struct file *file, poll_table *wait)
944static ssize_t dvb_audio_write(struct file *file, const char __user *buf, 944static ssize_t dvb_audio_write(struct file *file, const char __user *buf,
945 size_t count, loff_t *ppos) 945 size_t count, loff_t *ppos)
946{ 946{
947 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 947 struct dvb_device *dvbdev = file->private_data;
948 struct av7110 *av7110 = (struct av7110 *) dvbdev->priv; 948 struct av7110 *av7110 = dvbdev->priv;
949 949
950 dprintk(2, "av7110:%p, \n", av7110); 950 dprintk(2, "av7110:%p, \n", av7110);
951 951
@@ -989,8 +989,8 @@ static int play_iframe(struct av7110 *av7110, u8 __user *buf, unsigned int len,
989static int dvb_video_ioctl(struct inode *inode, struct file *file, 989static int dvb_video_ioctl(struct inode *inode, struct file *file,
990 unsigned int cmd, void *parg) 990 unsigned int cmd, void *parg)
991{ 991{
992 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 992 struct dvb_device *dvbdev = file->private_data;
993 struct av7110 *av7110 = (struct av7110 *) dvbdev->priv; 993 struct av7110 *av7110 = dvbdev->priv;
994 unsigned long arg = (unsigned long) parg; 994 unsigned long arg = (unsigned long) parg;
995 int ret = 0; 995 int ret = 0;
996 996
@@ -1203,8 +1203,8 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
1203static int dvb_audio_ioctl(struct inode *inode, struct file *file, 1203static int dvb_audio_ioctl(struct inode *inode, struct file *file,
1204 unsigned int cmd, void *parg) 1204 unsigned int cmd, void *parg)
1205{ 1205{
1206 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 1206 struct dvb_device *dvbdev = file->private_data;
1207 struct av7110 *av7110 = (struct av7110 *) dvbdev->priv; 1207 struct av7110 *av7110 = dvbdev->priv;
1208 unsigned long arg = (unsigned long) parg; 1208 unsigned long arg = (unsigned long) parg;
1209 int ret = 0; 1209 int ret = 0;
1210 1210
@@ -1349,8 +1349,8 @@ static int dvb_audio_ioctl(struct inode *inode, struct file *file,
1349 1349
1350static int dvb_video_open(struct inode *inode, struct file *file) 1350static int dvb_video_open(struct inode *inode, struct file *file)
1351{ 1351{
1352 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 1352 struct dvb_device *dvbdev = file->private_data;
1353 struct av7110 *av7110 = (struct av7110 *) dvbdev->priv; 1353 struct av7110 *av7110 = dvbdev->priv;
1354 int err; 1354 int err;
1355 1355
1356 dprintk(2, "av7110:%p, \n", av7110); 1356 dprintk(2, "av7110:%p, \n", av7110);
@@ -1374,8 +1374,8 @@ static int dvb_video_open(struct inode *inode, struct file *file)
1374 1374
1375static int dvb_video_release(struct inode *inode, struct file *file) 1375static int dvb_video_release(struct inode *inode, struct file *file)
1376{ 1376{
1377 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 1377 struct dvb_device *dvbdev = file->private_data;
1378 struct av7110 *av7110 = (struct av7110 *) dvbdev->priv; 1378 struct av7110 *av7110 = dvbdev->priv;
1379 1379
1380 dprintk(2, "av7110:%p, \n", av7110); 1380 dprintk(2, "av7110:%p, \n", av7110);
1381 1381
@@ -1388,9 +1388,9 @@ static int dvb_video_release(struct inode *inode, struct file *file)
1388 1388
1389static int dvb_audio_open(struct inode *inode, struct file *file) 1389static int dvb_audio_open(struct inode *inode, struct file *file)
1390{ 1390{
1391 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 1391 struct dvb_device *dvbdev = file->private_data;
1392 struct av7110 *av7110 = (struct av7110 *) dvbdev->priv; 1392 struct av7110 *av7110 = dvbdev->priv;
1393 int err=dvb_generic_open(inode, file); 1393 int err = dvb_generic_open(inode, file);
1394 1394
1395 dprintk(2, "av7110:%p, \n", av7110); 1395 dprintk(2, "av7110:%p, \n", av7110);
1396 1396
@@ -1403,8 +1403,8 @@ static int dvb_audio_open(struct inode *inode, struct file *file)
1403 1403
1404static int dvb_audio_release(struct inode *inode, struct file *file) 1404static int dvb_audio_release(struct inode *inode, struct file *file)
1405{ 1405{
1406 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 1406 struct dvb_device *dvbdev = file->private_data;
1407 struct av7110 *av7110 = (struct av7110 *) dvbdev->priv; 1407 struct av7110 *av7110 = dvbdev->priv;
1408 1408
1409 dprintk(2, "av7110:%p, \n", av7110); 1409 dprintk(2, "av7110:%p, \n", av7110);
1410 1410
diff --git a/drivers/media/dvb/ttpci/av7110_ca.c b/drivers/media/dvb/ttpci/av7110_ca.c
index 4251a97d42..e9b4e88e79 100644
--- a/drivers/media/dvb/ttpci/av7110_ca.c
+++ b/drivers/media/dvb/ttpci/av7110_ca.c
@@ -214,8 +214,8 @@ static ssize_t ci_ll_read(struct dvb_ringbuffer *cibuf, struct file *file,
214 214
215static int dvb_ca_open(struct inode *inode, struct file *file) 215static int dvb_ca_open(struct inode *inode, struct file *file)
216{ 216{
217 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 217 struct dvb_device *dvbdev = file->private_data;
218 struct av7110 *av7110 = (struct av7110 *) dvbdev->priv; 218 struct av7110 *av7110 = dvbdev->priv;
219 int err = dvb_generic_open(inode, file); 219 int err = dvb_generic_open(inode, file);
220 220
221 dprintk(8, "av7110:%p\n",av7110); 221 dprintk(8, "av7110:%p\n",av7110);
@@ -228,8 +228,8 @@ static int dvb_ca_open(struct inode *inode, struct file *file)
228 228
229static unsigned int dvb_ca_poll (struct file *file, poll_table *wait) 229static unsigned int dvb_ca_poll (struct file *file, poll_table *wait)
230{ 230{
231 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 231 struct dvb_device *dvbdev = file->private_data;
232 struct av7110 *av7110 = (struct av7110 *) dvbdev->priv; 232 struct av7110 *av7110 = dvbdev->priv;
233 struct dvb_ringbuffer *rbuf = &av7110->ci_rbuffer; 233 struct dvb_ringbuffer *rbuf = &av7110->ci_rbuffer;
234 struct dvb_ringbuffer *wbuf = &av7110->ci_wbuffer; 234 struct dvb_ringbuffer *wbuf = &av7110->ci_wbuffer;
235 unsigned int mask = 0; 235 unsigned int mask = 0;
@@ -251,8 +251,8 @@ static unsigned int dvb_ca_poll (struct file *file, poll_table *wait)
251static int dvb_ca_ioctl(struct inode *inode, struct file *file, 251static int dvb_ca_ioctl(struct inode *inode, struct file *file,
252 unsigned int cmd, void *parg) 252 unsigned int cmd, void *parg)
253{ 253{
254 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 254 struct dvb_device *dvbdev = file->private_data;
255 struct av7110 *av7110 = (struct av7110 *) dvbdev->priv; 255 struct av7110 *av7110 = dvbdev->priv;
256 unsigned long arg = (unsigned long) parg; 256 unsigned long arg = (unsigned long) parg;
257 257
258 dprintk(8, "av7110:%p\n",av7110); 258 dprintk(8, "av7110:%p\n",av7110);
@@ -329,8 +329,8 @@ static int dvb_ca_ioctl(struct inode *inode, struct file *file,
329static ssize_t dvb_ca_write(struct file *file, const char __user *buf, 329static ssize_t dvb_ca_write(struct file *file, const char __user *buf,
330 size_t count, loff_t *ppos) 330 size_t count, loff_t *ppos)
331{ 331{
332 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 332 struct dvb_device *dvbdev = file->private_data;
333 struct av7110 *av7110 = (struct av7110 *) dvbdev->priv; 333 struct av7110 *av7110 = dvbdev->priv;
334 334
335 dprintk(8, "av7110:%p\n",av7110); 335 dprintk(8, "av7110:%p\n",av7110);
336 return ci_ll_write(&av7110->ci_wbuffer, file, buf, count, ppos); 336 return ci_ll_write(&av7110->ci_wbuffer, file, buf, count, ppos);
@@ -339,15 +339,13 @@ static ssize_t dvb_ca_write(struct file *file, const char __user *buf,
339static ssize_t dvb_ca_read(struct file *file, char __user *buf, 339static ssize_t dvb_ca_read(struct file *file, char __user *buf,
340 size_t count, loff_t *ppos) 340 size_t count, loff_t *ppos)
341{ 341{
342 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 342 struct dvb_device *dvbdev = file->private_data;
343 struct av7110 *av7110 = (struct av7110 *) dvbdev->priv; 343 struct av7110 *av7110 = dvbdev->priv;
344 344
345 dprintk(8, "av7110:%p\n",av7110); 345 dprintk(8, "av7110:%p\n",av7110);
346 return ci_ll_read(&av7110->ci_rbuffer, file, buf, count, ppos); 346 return ci_ll_read(&av7110->ci_rbuffer, file, buf, count, ppos);
347} 347}
348 348
349
350
351static struct file_operations dvb_ca_fops = { 349static struct file_operations dvb_ca_fops = {
352 .owner = THIS_MODULE, 350 .owner = THIS_MODULE,
353 .read = dvb_ca_read, 351 .read = dvb_ca_read,
diff --git a/drivers/media/dvb/ttpci/av7110_ir.c b/drivers/media/dvb/ttpci/av7110_ir.c
index e4544ea2b8..f59465bb0a 100644
--- a/drivers/media/dvb/ttpci/av7110_ir.c
+++ b/drivers/media/dvb/ttpci/av7110_ir.c
@@ -4,6 +4,7 @@
4#include <linux/moduleparam.h> 4#include <linux/moduleparam.h>
5#include <linux/input.h> 5#include <linux/input.h>
6#include <linux/proc_fs.h> 6#include <linux/proc_fs.h>
7#include <linux/kernel.h>
7#include <asm/bitops.h> 8#include <asm/bitops.h>
8 9
9#include "av7110.h" 10#include "av7110.h"
@@ -16,6 +17,7 @@
16static int av_cnt; 17static int av_cnt;
17static struct av7110 *av_list[4]; 18static struct av7110 *av_list[4];
18static struct input_dev *input_dev; 19static struct input_dev *input_dev;
20static char input_phys[32];
19 21
20static u8 delay_timer_finished; 22static u8 delay_timer_finished;
21 23
@@ -217,7 +219,7 @@ int __devinit av7110_ir_init(struct av7110 *av7110)
217 static struct proc_dir_entry *e; 219 static struct proc_dir_entry *e;
218 int err; 220 int err;
219 221
220 if (av_cnt >= sizeof av_list/sizeof av_list[0]) 222 if (av_cnt >= ARRAY_SIZE(av_list))
221 return -ENOSPC; 223 return -ENOSPC;
222 224
223 av7110_setup_irc_config(av7110, 0x0001); 225 av7110_setup_irc_config(av7110, 0x0001);
@@ -231,8 +233,22 @@ int __devinit av7110_ir_init(struct av7110 *av7110)
231 if (!input_dev) 233 if (!input_dev)
232 return -ENOMEM; 234 return -ENOMEM;
233 235
236 snprintf(input_phys, sizeof(input_phys),
237 "pci-%s/ir0", pci_name(av7110->dev->pci));
238
234 input_dev->name = "DVB on-card IR receiver"; 239 input_dev->name = "DVB on-card IR receiver";
235 240
241 input_dev->phys = input_phys;
242 input_dev->id.bustype = BUS_PCI;
243 input_dev->id.version = 1;
244 if (av7110->dev->pci->subsystem_vendor) {
245 input_dev->id.vendor = av7110->dev->pci->subsystem_vendor;
246 input_dev->id.product = av7110->dev->pci->subsystem_device;
247 } else {
248 input_dev->id.vendor = av7110->dev->pci->vendor;
249 input_dev->id.product = av7110->dev->pci->device;
250 }
251 input_dev->cdev.dev = &av7110->dev->pci->dev;
236 set_bit(EV_KEY, input_dev->evbit); 252 set_bit(EV_KEY, input_dev->evbit);
237 set_bit(EV_REP, input_dev->evbit); 253 set_bit(EV_REP, input_dev->evbit);
238 input_register_keys(); 254 input_register_keys();
diff --git a/drivers/media/dvb/ttpci/av7110_v4l.c b/drivers/media/dvb/ttpci/av7110_v4l.c
index dbfd5e7b4b..cde5d3ae7e 100644
--- a/drivers/media/dvb/ttpci/av7110_v4l.c
+++ b/drivers/media/dvb/ttpci/av7110_v4l.c
@@ -140,17 +140,6 @@ static int ves1820_writereg(struct saa7146_dev *dev, u8 addr, u8 reg, u8 data)
140 return 0; 140 return 0;
141} 141}
142 142
143static int stv0297_writereg(struct saa7146_dev *dev, u8 addr, u8 reg, u8 data)
144{
145 u8 buf [] = { reg, data };
146 struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = buf, .len = 2 };
147
148 if (1 != saa7146_i2c_transfer(dev, &msg, 1, 1))
149 return -1;
150 return 0;
151}
152
153
154static int tuner_write(struct saa7146_dev *dev, u8 addr, u8 data [4]) 143static int tuner_write(struct saa7146_dev *dev, u8 addr, u8 data [4])
155{ 144{
156 struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = data, .len = 4 }; 145 struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = data, .len = 4 };
@@ -193,6 +182,7 @@ static int ves1820_set_tv_freq(struct saa7146_dev *dev, u32 freq)
193 182
194static int stv0297_set_tv_freq(struct saa7146_dev *dev, u32 freq) 183static int stv0297_set_tv_freq(struct saa7146_dev *dev, u32 freq)
195{ 184{
185 struct av7110 *av7110 = (struct av7110*)dev->ext_priv;
196 u32 div; 186 u32 div;
197 u8 data[4]; 187 u8 data[4];
198 188
@@ -213,8 +203,8 @@ static int stv0297_set_tv_freq(struct saa7146_dev *dev, u32 freq)
213 else 203 else
214 return -EINVAL; 204 return -EINVAL;
215 205
216 stv0297_writereg(dev, 0x1C, 0x87, 0x78); 206 if (av7110->fe->ops.i2c_gate_ctrl)
217 stv0297_writereg(dev, 0x1C, 0x86, 0xc8); 207 av7110->fe->ops.i2c_gate_ctrl(av7110->fe, 1);
218 return tuner_write(dev, 0x63, data); 208 return tuner_write(dev, 0x63, data);
219} 209}
220 210
@@ -817,20 +807,20 @@ int av7110_init_v4l(struct av7110 *av7110)
817 saa7146_vv_release(dev); 807 saa7146_vv_release(dev);
818 return -ENODEV; 808 return -ENODEV;
819 } 809 }
820 if (saa7146_register_device(&av7110->vbi_dev, dev, "av7110", VFL_TYPE_VBI)) { 810 if (saa7146_register_device(&av7110->vbi_dev, dev, "av7110", VFL_TYPE_VBI))
821 ERR(("cannot register vbi v4l2 device. skipping.\n")); 811 ERR(("cannot register vbi v4l2 device. skipping.\n"));
822 } else {
823 if (av7110->analog_tuner_flags)
824 av7110->analog_tuner_flags |= ANALOG_TUNER_VBI;
825 }
826 return 0; 812 return 0;
827} 813}
828 814
829int av7110_exit_v4l(struct av7110 *av7110) 815int av7110_exit_v4l(struct av7110 *av7110)
830{ 816{
817 struct saa7146_dev* dev = av7110->dev;
818
831 saa7146_unregister_device(&av7110->v4l_dev, av7110->dev); 819 saa7146_unregister_device(&av7110->v4l_dev, av7110->dev);
832 if (av7110->analog_tuner_flags & ANALOG_TUNER_VBI) 820 saa7146_unregister_device(&av7110->vbi_dev, av7110->dev);
833 saa7146_unregister_device(&av7110->vbi_dev, av7110->dev); 821
822 saa7146_vv_release(dev);
823
834 return 0; 824 return 0;
835} 825}
836 826
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
index 89ab4b5915..3035b224c7 100644
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ b/drivers/media/dvb/ttpci/budget-av.c
@@ -1089,6 +1089,8 @@ static int budget_av_detach(struct saa7146_dev *dev)
1089 msleep(200); 1089 msleep(200);
1090 1090
1091 saa7146_unregister_device(&budget_av->vd, dev); 1091 saa7146_unregister_device(&budget_av->vd, dev);
1092
1093 saa7146_vv_release(dev);
1092 } 1094 }
1093 1095
1094 if (budget_av->budget.ci_present) 1096 if (budget_av->budget.ci_present)
@@ -1145,6 +1147,7 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
1145 if ((err = saa7146_register_device(&budget_av->vd, dev, "knc1", VFL_TYPE_GRABBER))) { 1147 if ((err = saa7146_register_device(&budget_av->vd, dev, "knc1", VFL_TYPE_GRABBER))) {
1146 /* fixme: proper cleanup here */ 1148 /* fixme: proper cleanup here */
1147 ERR(("cannot register capture v4l2 device.\n")); 1149 ERR(("cannot register capture v4l2 device.\n"));
1150 saa7146_vv_release(dev);
1148 return err; 1151 return err;
1149 } 1152 }
1150 1153
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
index f2066b47ba..464feaf1a9 100644
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ b/drivers/media/dvb/ttpci/budget-ci.c
@@ -29,8 +29,6 @@
29 * the project's page is at http://www.linuxtv.org/dvb/ 29 * the project's page is at http://www.linuxtv.org/dvb/
30 */ 30 */
31 31
32#include "budget.h"
33
34#include <linux/module.h> 32#include <linux/module.h>
35#include <linux/errno.h> 33#include <linux/errno.h>
36#include <linux/slab.h> 34#include <linux/slab.h>
@@ -39,6 +37,8 @@
39#include <linux/spinlock.h> 37#include <linux/spinlock.h>
40#include <media/ir-common.h> 38#include <media/ir-common.h>
41 39
40#include "budget.h"
41
42#include "dvb_ca_en50221.h" 42#include "dvb_ca_en50221.h"
43#include "stv0299.h" 43#include "stv0299.h"
44#include "stv0297.h" 44#include "stv0297.h"
@@ -130,6 +130,7 @@ static void msp430_ir_interrupt(unsigned long data)
130 int toggle; 130 int toggle;
131 static int prev_toggle = -1; 131 static int prev_toggle = -1;
132 static u32 ir_key; 132 static u32 ir_key;
133 static int state = 0;
133 u32 command = ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8; 134 u32 command = ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;
134 135
135 /* 136 /*
@@ -138,21 +139,34 @@ static void msp430_ir_interrupt(unsigned long data)
138 * type1: X1CCCCCC, C = command bits (0 - 63) 139 * type1: X1CCCCCC, C = command bits (0 - 63)
139 * type2: X0TDDDDD, D = device bits (0 - 31), T = RC5 toggle bit 140 * type2: X0TDDDDD, D = device bits (0 - 31), T = RC5 toggle bit
140 * 141 *
141 * More than one command byte may be generated before the device byte 142 * Each signal from the remote control can generate one or more command
142 * Only when we have both, a correct keypress is generated 143 * bytes and one or more device bytes. For the repeated bytes, the
144 * highest bit (X) is set. The first command byte is always generated
145 * before the first device byte. Other than that, no specific order
146 * seems to apply.
147 *
148 * Only when we have a command and device byte, a keypress is
149 * generated.
143 */ 150 */
144 151
152 if (ir_debug)
153 printk("budget_ci: received byte 0x%02x\n", command);
154
155 /* Is this a repeated byte? */
156 if (command & 0x80)
157 return;
158
145 /* Is this a RC5 command byte? */ 159 /* Is this a RC5 command byte? */
146 if (command & 0x40) { 160 if (command & 0x40) {
147 if (ir_debug) 161 state = 1;
148 printk("budget_ci: received command byte 0x%02x\n", command);
149 ir_key = command & 0x3f; 162 ir_key = command & 0x3f;
150 return; 163 return;
151 } 164 }
152 165
153 /* It's a RC5 device byte */ 166 /* It's a RC5 device byte */
154 if (ir_debug) 167 if (!state)
155 printk("budget_ci: received device byte 0x%02x\n", command); 168 return;
169 state = 0;
156 device = command & 0x1f; 170 device = command & 0x1f;
157 toggle = command & 0x20; 171 toggle = command & 0x20;
158 172
@@ -223,7 +237,6 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
223 switch (budget_ci->budget.dev->pci->subsystem_device) { 237 switch (budget_ci->budget.dev->pci->subsystem_device) {
224 case 0x100c: 238 case 0x100c:
225 case 0x100f: 239 case 0x100f:
226 case 0x1010:
227 case 0x1011: 240 case 0x1011:
228 case 0x1012: 241 case 0x1012:
229 case 0x1017: 242 case 0x1017:
@@ -236,6 +249,16 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
236 else 249 else
237 budget_ci->ir.rc5_device = rc5_device; 250 budget_ci->ir.rc5_device = rc5_device;
238 break; 251 break;
252 case 0x1010:
253 /* for the Technotrend 1500 bundled remote */
254 ir_input_init(input_dev, &budget_ci->ir.state,
255 IR_TYPE_RC5, ir_codes_tt_1500);
256
257 if (rc5_device < 0)
258 budget_ci->ir.rc5_device = IR_DEVICE_ANY;
259 else
260 budget_ci->ir.rc5_device = rc5_device;
261 break;
239 default: 262 default:
240 /* unknown remote */ 263 /* unknown remote */
241 ir_input_init(input_dev, &budget_ci->ir.state, 264 ir_input_init(input_dev, &budget_ci->ir.state,
@@ -869,6 +892,17 @@ static struct tda1004x_config philips_tdm1316l_config = {
869 .request_firmware = philips_tdm1316l_request_firmware, 892 .request_firmware = philips_tdm1316l_request_firmware,
870}; 893};
871 894
895static struct tda1004x_config philips_tdm1316l_config_invert = {
896
897 .demod_address = 0x8,
898 .invert = 1,
899 .invert_oclk = 0,
900 .xtal_freq = TDA10046_XTAL_4M,
901 .agc_config = TDA10046_AGC_DEFAULT,
902 .if_freq = TDA10046_FREQ_3617,
903 .request_firmware = philips_tdm1316l_request_firmware,
904};
905
872static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params) 906static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
873{ 907{
874 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv; 908 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
@@ -1092,9 +1126,8 @@ static void frontend_init(struct budget_ci *budget_ci)
1092 1126
1093 case 0x1012: // TT DVB-T CI budget (tda10046/Philips tdm1316l(tda6651tt)) 1127 case 0x1012: // TT DVB-T CI budget (tda10046/Philips tdm1316l(tda6651tt))
1094 budget_ci->tuner_pll_address = 0x60; 1128 budget_ci->tuner_pll_address = 0x60;
1095 philips_tdm1316l_config.invert = 1;
1096 budget_ci->budget.dvb_frontend = 1129 budget_ci->budget.dvb_frontend =
1097 dvb_attach(tda10046_attach, &philips_tdm1316l_config, &budget_ci->budget.i2c_adap); 1130 dvb_attach(tda10046_attach, &philips_tdm1316l_config_invert, &budget_ci->budget.i2c_adap);
1098 if (budget_ci->budget.dvb_frontend) { 1131 if (budget_ci->budget.dvb_frontend) {
1099 budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init; 1132 budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
1100 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params; 1133 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
diff --git a/drivers/media/dvb/ttusb-dec/ttusb_dec.c b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
index bd6e7baae2..78c98b0899 100644
--- a/drivers/media/dvb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
@@ -20,8 +20,6 @@
20 * 20 *
21 */ 21 */
22 22
23#include <linux/mutex.h>
24
25#include <linux/list.h> 23#include <linux/list.h>
26#include <linux/module.h> 24#include <linux/module.h>
27#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
@@ -35,6 +33,8 @@
35#include <linux/init.h> 33#include <linux/init.h>
36#include <linux/input.h> 34#include <linux/input.h>
37 35
36#include <linux/mutex.h>
37
38#include "dmxdev.h" 38#include "dmxdev.h"
39#include "dvb_demux.h" 39#include "dvb_demux.h"
40#include "dvb_filter.h" 40#include "dvb_filter.h"
diff --git a/drivers/media/radio/radio-aztech.c b/drivers/media/radio/radio-aztech.c
index 19d45cc940..9f1addae69 100644
--- a/drivers/media/radio/radio-aztech.c
+++ b/drivers/media/radio/radio-aztech.c
@@ -180,136 +180,163 @@ static int az_setfreq(struct az_device *dev, unsigned long frequency)
180 return 0; 180 return 0;
181} 181}
182 182
183static int az_do_ioctl(struct inode *inode, struct file *file, 183static int vidioc_querycap (struct file *file, void *priv,
184 unsigned int cmd, void *arg) 184 struct v4l2_capability *v)
185{
186 strlcpy(v->driver, "radio-aztech", sizeof (v->driver));
187 strlcpy(v->card, "Aztech Radio", sizeof (v->card));
188 sprintf(v->bus_info,"ISA");
189 v->version = RADIO_VERSION;
190 v->capabilities = V4L2_CAP_TUNER;
191 return 0;
192}
193
194static int vidioc_g_tuner (struct file *file, void *priv,
195 struct v4l2_tuner *v)
185{ 196{
186 struct video_device *dev = video_devdata(file); 197 struct video_device *dev = video_devdata(file);
187 struct az_device *az = dev->priv; 198 struct az_device *az = dev->priv;
188 199
189 switch(cmd) 200 if (v->index > 0)
190 { 201 return -EINVAL;
191 case VIDIOC_QUERYCAP:
192 {
193 struct v4l2_capability *v = arg;
194 memset(v,0,sizeof(*v));
195 strlcpy(v->driver, "radio-aztech", sizeof (v->driver));
196 strlcpy(v->card, "Aztech Radio", sizeof (v->card));
197 sprintf(v->bus_info,"ISA");
198 v->version = RADIO_VERSION;
199 v->capabilities = V4L2_CAP_TUNER;
200 202
201 return 0; 203 strcpy(v->name, "FM");
202 } 204 v->type = V4L2_TUNER_RADIO;
203 case VIDIOC_G_TUNER:
204 {
205 struct v4l2_tuner *v = arg;
206
207 if (v->index > 0)
208 return -EINVAL;
209
210 memset(v,0,sizeof(*v));
211 strcpy(v->name, "FM");
212 v->type = V4L2_TUNER_RADIO;
213
214 v->rangelow=(87*16000);
215 v->rangehigh=(108*16000);
216 v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
217 v->capability=V4L2_TUNER_CAP_LOW;
218 if(az_getstereo(az))
219 v->audmode = V4L2_TUNER_MODE_STEREO;
220 else
221 v->audmode = V4L2_TUNER_MODE_MONO;
222 v->signal=0xFFFF*az_getsigstr(az);
223 205
224 return 0; 206 v->rangelow=(87*16000);
225 } 207 v->rangehigh=(108*16000);
226 case VIDIOC_S_TUNER: 208 v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
227 { 209 v->capability=V4L2_TUNER_CAP_LOW;
228 struct v4l2_tuner *v = arg; 210 if(az_getstereo(az))
211 v->audmode = V4L2_TUNER_MODE_STEREO;
212 else
213 v->audmode = V4L2_TUNER_MODE_MONO;
214 v->signal=0xFFFF*az_getsigstr(az);
229 215
230 if (v->index > 0) 216 return 0;
231 return -EINVAL; 217}
232 218
233 return 0;
234 }
235 case VIDIOC_S_FREQUENCY:
236 {
237 struct v4l2_frequency *f = arg;
238 219
239 az->curfreq = f->frequency; 220static int vidioc_s_tuner (struct file *file, void *priv,
240 az_setfreq(az, az->curfreq); 221 struct v4l2_tuner *v)
241 return 0; 222{
242 } 223 if (v->index > 0)
243 case VIDIOC_G_FREQUENCY: 224 return -EINVAL;
244 {
245 struct v4l2_frequency *f = arg;
246 225
247 f->type = V4L2_TUNER_RADIO; 226 return 0;
248 f->frequency = az->curfreq; 227}
249 228
250 return 0; 229static int vidioc_g_audio (struct file *file, void *priv,
251 } 230 struct v4l2_audio *a)
231{
232 if (a->index > 1)
233 return -EINVAL;
252 234
253 case VIDIOC_QUERYCTRL: 235 strcpy(a->name, "Radio");
254 { 236 a->capability = V4L2_AUDCAP_STEREO;
255 struct v4l2_queryctrl *qc = arg; 237 return 0;
256 int i; 238}
257 239
258 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 240static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
259 if (qc->id && qc->id == radio_qctrl[i].id) { 241{
260 memcpy(qc, &(radio_qctrl[i]), 242 *i = 0;
261 sizeof(*qc)); 243 return 0;
262 return (0); 244}
263 } 245
264 } 246static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
265 return -EINVAL; 247{
266 } 248 if (i != 0)
267 case VIDIOC_G_CTRL: 249 return -EINVAL;
268 { 250 return 0;
269 struct v4l2_control *ctrl= arg; 251}
270 252
271 switch (ctrl->id) { 253
272 case V4L2_CID_AUDIO_MUTE: 254static int vidioc_s_audio (struct file *file, void *priv,
273 if (az->curvol==0) 255 struct v4l2_audio *a)
274 ctrl->value=1; 256{
275 else 257 if (a->index != 0)
276 ctrl->value=0; 258 return -EINVAL;
277 return (0); 259
278 case V4L2_CID_AUDIO_VOLUME: 260 return 0;
279 ctrl->value=az->curvol * 6554; 261}
280 return (0); 262
281 } 263static int vidioc_s_frequency (struct file *file, void *priv,
282 return -EINVAL; 264 struct v4l2_frequency *f)
283 } 265{
284 case VIDIOC_S_CTRL: 266 struct video_device *dev = video_devdata(file);
285 { 267 struct az_device *az = dev->priv;
286 struct v4l2_control *ctrl= arg; 268
287 269 az->curfreq = f->frequency;
288 switch (ctrl->id) { 270 az_setfreq(az, az->curfreq);
289 case V4L2_CID_AUDIO_MUTE: 271 return 0;
290 if (ctrl->value) { 272}
291 az_setvol(az,0); 273
292 } else { 274static int vidioc_g_frequency (struct file *file, void *priv,
293 az_setvol(az,az->curvol); 275 struct v4l2_frequency *f)
294 } 276{
295 return (0); 277 struct video_device *dev = video_devdata(file);
296 case V4L2_CID_AUDIO_VOLUME: 278 struct az_device *az = dev->priv;
297 az_setvol(az,ctrl->value); 279
298 return (0); 280 f->type = V4L2_TUNER_RADIO;
299 } 281 f->frequency = az->curfreq;
300 return -EINVAL; 282
283 return 0;
284}
285
286static int vidioc_queryctrl (struct file *file, void *priv,
287 struct v4l2_queryctrl *qc)
288{
289 int i;
290
291 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
292 if (qc->id && qc->id == radio_qctrl[i].id) {
293 memcpy(qc, &(radio_qctrl[i]),
294 sizeof(*qc));
295 return (0);
301 } 296 }
297 }
298 return -EINVAL;
299}
300
301static int vidioc_g_ctrl (struct file *file, void *priv,
302 struct v4l2_control *ctrl)
303{
304 struct video_device *dev = video_devdata(file);
305 struct az_device *az = dev->priv;
302 306
303 default: 307 switch (ctrl->id) {
304 return v4l_compat_translate_ioctl(inode,file,cmd,arg, 308 case V4L2_CID_AUDIO_MUTE:
305 az_do_ioctl); 309 if (az->curvol==0)
310 ctrl->value=1;
311 else
312 ctrl->value=0;
313 return (0);
314 case V4L2_CID_AUDIO_VOLUME:
315 ctrl->value=az->curvol * 6554;
316 return (0);
306 } 317 }
318 return -EINVAL;
307} 319}
308 320
309static int az_ioctl(struct inode *inode, struct file *file, 321static int vidioc_s_ctrl (struct file *file, void *priv,
310 unsigned int cmd, unsigned long arg) 322 struct v4l2_control *ctrl)
311{ 323{
312 return video_usercopy(inode, file, cmd, arg, az_do_ioctl); 324 struct video_device *dev = video_devdata(file);
325 struct az_device *az = dev->priv;
326
327 switch (ctrl->id) {
328 case V4L2_CID_AUDIO_MUTE:
329 if (ctrl->value) {
330 az_setvol(az,0);
331 } else {
332 az_setvol(az,az->curvol);
333 }
334 return (0);
335 case V4L2_CID_AUDIO_VOLUME:
336 az_setvol(az,ctrl->value);
337 return (0);
338 }
339 return -EINVAL;
313} 340}
314 341
315static struct az_device aztech_unit; 342static struct az_device aztech_unit;
@@ -318,20 +345,35 @@ static const struct file_operations aztech_fops = {
318 .owner = THIS_MODULE, 345 .owner = THIS_MODULE,
319 .open = video_exclusive_open, 346 .open = video_exclusive_open,
320 .release = video_exclusive_release, 347 .release = video_exclusive_release,
321 .ioctl = az_ioctl, 348 .ioctl = video_ioctl2,
322 .compat_ioctl = v4l_compat_ioctl32, 349 .compat_ioctl = v4l_compat_ioctl32,
323 .llseek = no_llseek, 350 .llseek = no_llseek,
324}; 351};
325 352
326static struct video_device aztech_radio= 353static struct video_device aztech_radio=
327{ 354{
328 .owner = THIS_MODULE, 355 .owner = THIS_MODULE,
329 .name = "Aztech radio", 356 .name = "Aztech radio",
330 .type = VID_TYPE_TUNER, 357 .type = VID_TYPE_TUNER,
331 .hardware = 0, 358 .hardware = 0,
332 .fops = &aztech_fops, 359 .fops = &aztech_fops,
360 .vidioc_querycap = vidioc_querycap,
361 .vidioc_g_tuner = vidioc_g_tuner,
362 .vidioc_s_tuner = vidioc_s_tuner,
363 .vidioc_g_audio = vidioc_g_audio,
364 .vidioc_s_audio = vidioc_s_audio,
365 .vidioc_g_input = vidioc_g_input,
366 .vidioc_s_input = vidioc_s_input,
367 .vidioc_g_frequency = vidioc_g_frequency,
368 .vidioc_s_frequency = vidioc_s_frequency,
369 .vidioc_queryctrl = vidioc_queryctrl,
370 .vidioc_g_ctrl = vidioc_g_ctrl,
371 .vidioc_s_ctrl = vidioc_s_ctrl,
333}; 372};
334 373
374module_param_named(debug,aztech_radio.debug, int, 0644);
375MODULE_PARM_DESC(debug,"activates debug info");
376
335static int __init aztech_init(void) 377static int __init aztech_init(void)
336{ 378{
337 if(io==-1) 379 if(io==-1)
diff --git a/drivers/media/radio/radio-gemtek-pci.c b/drivers/media/radio/radio-gemtek-pci.c
index 05e5aa7702..74976cba86 100644
--- a/drivers/media/radio/radio-gemtek-pci.c
+++ b/drivers/media/radio/radio-gemtek-pci.c
@@ -89,14 +89,6 @@ static struct v4l2_queryctrl radio_qctrl[] = {
89#define GEMTEK_PCI_RANGE_HIGH (108*16000) 89#define GEMTEK_PCI_RANGE_HIGH (108*16000)
90#endif 90#endif
91 91
92#ifndef TRUE
93#define TRUE (1)
94#endif
95
96#ifndef FALSE
97#define FALSE (0)
98#endif
99
100struct gemtek_pci_card { 92struct gemtek_pci_card {
101 struct video_device *videodev; 93 struct video_device *videodev;
102 94
@@ -146,12 +138,12 @@ static void __gemtek_pci_cmd( u16 value, u32 port, u8 *last_byte, int keep )
146 138
147static inline void gemtek_pci_nil( u32 port, u8 *last_byte ) 139static inline void gemtek_pci_nil( u32 port, u8 *last_byte )
148{ 140{
149 __gemtek_pci_cmd( 0x00, port, last_byte, FALSE ); 141 __gemtek_pci_cmd( 0x00, port, last_byte, false );
150} 142}
151 143
152static inline void gemtek_pci_cmd( u16 cmd, u32 port, u8 *last_byte ) 144static inline void gemtek_pci_cmd( u16 cmd, u32 port, u8 *last_byte )
153{ 145{
154 __gemtek_pci_cmd( cmd, port, last_byte, TRUE ); 146 __gemtek_pci_cmd( cmd, port, last_byte, true );
155} 147}
156 148
157static void gemtek_pci_setfrequency( struct gemtek_pci_card *card, unsigned long frequency ) 149static void gemtek_pci_setfrequency( struct gemtek_pci_card *card, unsigned long frequency )
@@ -184,14 +176,14 @@ static void gemtek_pci_setfrequency( struct gemtek_pci_card *card, unsigned long
184static inline void gemtek_pci_mute( struct gemtek_pci_card *card ) 176static inline void gemtek_pci_mute( struct gemtek_pci_card *card )
185{ 177{
186 outb( 0x1f, card->iobase ); 178 outb( 0x1f, card->iobase );
187 card->mute = TRUE; 179 card->mute = true;
188} 180}
189 181
190static inline void gemtek_pci_unmute( struct gemtek_pci_card *card ) 182static inline void gemtek_pci_unmute( struct gemtek_pci_card *card )
191{ 183{
192 if ( card->mute ) { 184 if ( card->mute ) {
193 gemtek_pci_setfrequency( card, card->current_frequency ); 185 gemtek_pci_setfrequency( card, card->current_frequency );
194 card->mute = FALSE; 186 card->mute = false;
195 } 187 }
196} 188}
197 189
@@ -259,7 +251,7 @@ static int gemtek_pci_do_ioctl(struct inode *inode, struct file *file,
259 251
260 gemtek_pci_setfrequency( card, f->frequency ); 252 gemtek_pci_setfrequency( card, f->frequency );
261 card->current_frequency = f->frequency; 253 card->current_frequency = f->frequency;
262 card->mute = FALSE; 254 card->mute = false;
263 return 0; 255 return 0;
264 } 256 }
265 case VIDIOC_QUERYCTRL: 257 case VIDIOC_QUERYCTRL:
diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
index 6beeb74004..8e184cfc1c 100644
--- a/drivers/media/radio/radio-maxiradio.c
+++ b/drivers/media/radio/radio-maxiradio.c
@@ -27,7 +27,9 @@
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 * (c) 2006, 2007 by Mauro Carvalho Chehab <mchehab@infradead.org>:
31 * - Conversion to V4L2 API
32 * - Uses video_ioctl2 for parsing and to add debug support
31 */ 33 */
32 34
33 35
@@ -43,10 +45,18 @@
43#include <linux/videodev2.h> 45#include <linux/videodev2.h>
44#include <media/v4l2-common.h> 46#include <media/v4l2-common.h>
45 47
46#define DRIVER_VERSION "0.76" 48#define DRIVER_VERSION "0.77"
47 49
48#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 50#include <linux/version.h> /* for KERNEL_VERSION MACRO */
49#define RADIO_VERSION KERNEL_VERSION(0,7,6) 51#define RADIO_VERSION KERNEL_VERSION(0,7,7)
52
53static struct video_device maxiradio_radio;
54
55#define dprintk(num, fmt, arg...) \
56 do { \
57 if (maxiradio_radio.debug >= num) \
58 printk(KERN_DEBUG "%s: " fmt, \
59 maxiradio_radio.name, ## arg); } while (0)
50 60
51static struct v4l2_queryctrl radio_qctrl[] = { 61static struct v4l2_queryctrl radio_qctrl[] = {
52 { 62 {
@@ -81,30 +91,21 @@ module_param(radio_nr, int, 0);
81#define FREQ_IF 171200 /* 10.7*16000 */ 91#define FREQ_IF 171200 /* 10.7*16000 */
82#define FREQ_STEP 200 /* 12.5*16 */ 92#define FREQ_STEP 200 /* 12.5*16 */
83 93
84#define FREQ2BITS(x) ((( (unsigned int)(x)+FREQ_IF+(FREQ_STEP<<1))\ 94/* (x==fmhz*16*1000) -> bits */
85 /(FREQ_STEP<<2))<<2) /* (x==fmhz*16*1000) -> bits */ 95#define FREQ2BITS(x) ((( (unsigned int)(x)+FREQ_IF+(FREQ_STEP<<1)) \
96 /(FREQ_STEP<<2))<<2)
86 97
87#define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF) 98#define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF)
88 99
89 100
90static int radio_ioctl(struct inode *inode, struct file *file,
91 unsigned int cmd, unsigned long arg);
92
93static const struct file_operations maxiradio_fops = { 101static const struct file_operations maxiradio_fops = {
94 .owner = THIS_MODULE, 102 .owner = THIS_MODULE,
95 .open = video_exclusive_open, 103 .open = video_exclusive_open,
96 .release = video_exclusive_release, 104 .release = video_exclusive_release,
97 .ioctl = radio_ioctl, 105 .ioctl = video_ioctl2,
98 .compat_ioctl = v4l_compat_ioctl32, 106 .compat_ioctl = v4l_compat_ioctl32,
99 .llseek = no_llseek, 107 .llseek = no_llseek,
100}; 108};
101static struct video_device maxiradio_radio =
102{
103 .owner = THIS_MODULE,
104 .name = "Maxi Radio FM2000 radio",
105 .type = VID_TYPE_TUNER,
106 .fops = &maxiradio_fops,
107};
108 109
109static struct radio_device 110static struct radio_device
110{ 111{
@@ -116,12 +117,14 @@ static struct radio_device
116 unsigned long freq; 117 unsigned long freq;
117 118
118 struct mutex lock; 119 struct mutex lock;
119} radio_unit = {0, 0, 0, 0, }; 120} radio_unit = {
120 121 .muted =1,
122 .freq = FREQ_LO,
123};
121 124
122static void outbit(unsigned long bit, __u16 io) 125static void outbit(unsigned long bit, __u16 io)
123{ 126{
124 if(bit != 0) 127 if (bit != 0)
125 { 128 {
126 outb( power|wren|data ,io); udelay(4); 129 outb( power|wren|data ,io); udelay(4);
127 outb( power|wren|data|clk ,io); udelay(4); 130 outb( power|wren|data|clk ,io); udelay(4);
@@ -137,14 +140,20 @@ static void outbit(unsigned long bit, __u16 io)
137 140
138static void turn_power(__u16 io, int p) 141static void turn_power(__u16 io, int p)
139{ 142{
140 if(p != 0) outb(power, io); else outb(0,io); 143 if (p != 0) {
144 dprintk(1, "Radio powered on\n");
145 outb(power, io);
146 } else {
147 dprintk(1, "Radio powered off\n");
148 outb(0,io);
149 }
141} 150}
142 151
143 152static void set_freq(__u16 io, __u32 freq)
144static void set_freq(__u16 io, __u32 data)
145{ 153{
146 unsigned long int si; 154 unsigned long int si;
147 int bl; 155 int bl;
156 int data = FREQ2BITS(freq);
148 157
149 /* TEA5757 shift register bits (see pdf) */ 158 /* TEA5757 shift register bits (see pdf) */
150 159
@@ -163,161 +172,225 @@ static void set_freq(__u16 io, __u32 data)
163 outbit(0,io); // 16 search level 172 outbit(0,io); // 16 search level
164 173
165 si = 0x8000; 174 si = 0x8000;
166 for(bl = 1; bl <= 16 ; bl++) { outbit(data & si,io); si >>=1; } 175 for (bl = 1; bl <= 16 ; bl++) {
176 outbit(data & si,io);
177 si >>=1;
178 }
167 179
168 outb(power,io); 180 dprintk(1, "Radio freq set to %d.%02d MHz\n",
181 freq / 16000,
182 freq % 16000 * 100 / 16000);
183
184 turn_power(io, 1);
169} 185}
170 186
171static int get_stereo(__u16 io) 187static int get_stereo(__u16 io)
172{ 188{
173 outb(power,io); udelay(4); 189 outb(power,io);
190 udelay(4);
191
174 return !(inb(io) & mo_st); 192 return !(inb(io) & mo_st);
175} 193}
176 194
177static int get_tune(__u16 io) 195static int get_tune(__u16 io)
178{ 196{
179 outb(power+clk,io); udelay(4); 197 outb(power+clk,io);
198 udelay(4);
199
180 return !(inb(io) & mo_st); 200 return !(inb(io) & mo_st);
181} 201}
182 202
183 203
184static inline int radio_function(struct inode *inode, struct file *file, 204static int vidioc_querycap (struct file *file, void *priv,
185 unsigned int cmd, void *arg) 205 struct v4l2_capability *v)
206{
207 strlcpy(v->driver, "radio-maxiradio", sizeof (v->driver));
208 strlcpy(v->card, "Maxi Radio FM2000 radio", sizeof (v->card));
209 sprintf(v->bus_info,"ISA");
210 v->version = RADIO_VERSION;
211 v->capabilities = V4L2_CAP_TUNER;
212
213 return 0;
214}
215
216static int vidioc_g_tuner (struct file *file, void *priv,
217 struct v4l2_tuner *v)
186{ 218{
187 struct video_device *dev = video_devdata(file); 219 struct video_device *dev = video_devdata(file);
188 struct radio_device *card=dev->priv; 220 struct radio_device *card=dev->priv;
189 221
190 switch(cmd) { 222 if (v->index > 0)
191 case VIDIOC_QUERYCAP: 223 return -EINVAL;
192 {
193 struct v4l2_capability *v = arg;
194 memset(v,0,sizeof(*v));
195 strlcpy(v->driver, "radio-maxiradio", sizeof (v->driver));
196 strlcpy(v->card, "Maxi Radio FM2000 radio", sizeof (v->card));
197 sprintf(v->bus_info,"ISA");
198 v->version = RADIO_VERSION;
199 v->capabilities = V4L2_CAP_TUNER;
200 224
201 return 0; 225 memset(v,0,sizeof(*v));
202 } 226 strcpy(v->name, "FM");
203 case VIDIOC_G_TUNER: 227 v->type = V4L2_TUNER_RADIO;
204 {
205 struct v4l2_tuner *v = arg;
206 228
207 if (v->index > 0) 229 v->rangelow=FREQ_LO;
208 return -EINVAL; 230 v->rangehigh=FREQ_HI;
231 v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
232 v->capability=V4L2_TUNER_CAP_LOW;
233 if(get_stereo(card->io))
234 v->audmode = V4L2_TUNER_MODE_STEREO;
235 else
236 v->audmode = V4L2_TUNER_MODE_MONO;
237 v->signal=0xffff*get_tune(card->io);
209 238
210 memset(v,0,sizeof(*v)); 239 return 0;
211 strcpy(v->name, "FM"); 240}
212 v->type = V4L2_TUNER_RADIO;
213 241
214 v->rangelow=FREQ_LO; 242static int vidioc_s_tuner (struct file *file, void *priv,
215 v->rangehigh=FREQ_HI; 243 struct v4l2_tuner *v)
216 v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO; 244{
217 v->capability=V4L2_TUNER_CAP_LOW; 245 if (v->index > 0)
218 if(get_stereo(card->io)) 246 return -EINVAL;
219 v->audmode = V4L2_TUNER_MODE_STEREO;
220 else
221 v->audmode = V4L2_TUNER_MODE_MONO;
222 v->signal=0xffff*get_tune(card->io);
223 247
224 return 0; 248 return 0;
225 } 249}
226 case VIDIOC_S_TUNER:
227 {
228 struct v4l2_tuner *v = arg;
229 250
230 if (v->index > 0) 251static int vidioc_g_audio (struct file *file, void *priv,
231 return -EINVAL; 252 struct v4l2_audio *a)
253{
254 if (a->index > 1)
255 return -EINVAL;
232 256
233 return 0; 257 strcpy(a->name, "FM");
234 } 258 a->capability = V4L2_AUDCAP_STEREO;
235 case VIDIOC_S_FREQUENCY: 259 return 0;
236 { 260}
237 struct v4l2_frequency *f = arg;
238 261
239 if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) 262static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
240 return -EINVAL; 263{
264 *i = 0;
241 265
242 card->freq = f->frequency; 266 return 0;
243 set_freq(card->io, FREQ2BITS(card->freq)); 267}
244 msleep(125);
245 return 0;
246 }
247 case VIDIOC_G_FREQUENCY:
248 {
249 struct v4l2_frequency *f = arg;
250 268
251 f->type = V4L2_TUNER_RADIO; 269static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
252 f->frequency = card->freq; 270{
271 if (i != 0)
272 return -EINVAL;
253 273
254 return 0; 274 return 0;
255 } 275}
256 case VIDIOC_QUERYCTRL: 276
257 { 277
258 struct v4l2_queryctrl *qc = arg; 278static int vidioc_s_audio (struct file *file, void *priv,
259 int i; 279 struct v4l2_audio *a)
260 280{
261 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 281 if (a->index != 0)
262 if (qc->id && qc->id == radio_qctrl[i].id) { 282 return -EINVAL;
263 memcpy(qc, &(radio_qctrl[i]), 283
264 sizeof(*qc)); 284 return 0;
265 return (0); 285}
266 } 286
267 } 287static int vidioc_s_frequency (struct file *file, void *priv,
268 return -EINVAL; 288 struct v4l2_frequency *f)
269 } 289{
270 case VIDIOC_G_CTRL: 290 struct video_device *dev = video_devdata(file);
271 { 291 struct radio_device *card=dev->priv;
272 struct v4l2_control *ctrl= arg;
273
274 switch (ctrl->id) {
275 case V4L2_CID_AUDIO_MUTE:
276 ctrl->value=card->muted;
277 return (0);
278 }
279 return -EINVAL;
280 }
281 case VIDIOC_S_CTRL:
282 {
283 struct v4l2_control *ctrl= arg;
284
285 switch (ctrl->id) {
286 case V4L2_CID_AUDIO_MUTE:
287 card->muted = ctrl->value;
288 if(card->muted)
289 turn_power(card->io, 0);
290 else
291 set_freq(card->io, FREQ2BITS(card->freq));
292 return 0;
293 }
294 return -EINVAL;
295 }
296 292
297 default: 293 if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) {
298 return v4l_compat_translate_ioctl(inode,file,cmd,arg, 294 dprintk(1, "radio freq (%d.%02d MHz) out of range (%d-%d)\n",
299 radio_function); 295 f->frequency / 16000,
296 f->frequency % 16000 * 100 / 16000,
297 FREQ_LO / 16000, FREQ_HI / 16000);
300 298
299 return -EINVAL;
301 } 300 }
301
302 card->freq = f->frequency;
303 set_freq(card->io, card->freq);
304 msleep(125);
305
306 return 0;
302} 307}
303 308
304static int radio_ioctl(struct inode *inode, struct file *file, 309static int vidioc_g_frequency (struct file *file, void *priv,
305 unsigned int cmd, unsigned long arg) 310 struct v4l2_frequency *f)
306{ 311{
307 struct video_device *dev = video_devdata(file); 312 struct video_device *dev = video_devdata(file);
308 struct radio_device *card=dev->priv; 313 struct radio_device *card=dev->priv;
309 int ret;
310 314
311 mutex_lock(&card->lock); 315 f->type = V4L2_TUNER_RADIO;
312 ret = video_usercopy(inode, file, cmd, arg, radio_function); 316 f->frequency = card->freq;
313 mutex_unlock(&card->lock); 317
314 return ret; 318 dprintk(4, "radio freq is %d.%02d MHz",
319 f->frequency / 16000,
320 f->frequency % 16000 * 100 / 16000);
321
322 return 0;
315} 323}
316 324
317MODULE_AUTHOR("Dimitromanolakis Apostolos, apdim@grecian.net"); 325static int vidioc_queryctrl (struct file *file, void *priv,
318MODULE_DESCRIPTION("Radio driver for the Guillemot Maxi Radio FM2000 radio."); 326 struct v4l2_queryctrl *qc)
319MODULE_LICENSE("GPL"); 327{
328 int i;
320 329
330 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
331 if (qc->id && qc->id == radio_qctrl[i].id) {
332 memcpy(qc, &(radio_qctrl[i]), sizeof(*qc));
333 return (0);
334 }
335 }
336
337 return -EINVAL;
338}
339
340static int vidioc_g_ctrl (struct file *file, void *priv,
341 struct v4l2_control *ctrl)
342{
343 struct video_device *dev = video_devdata(file);
344 struct radio_device *card=dev->priv;
345
346 switch (ctrl->id) {
347 case V4L2_CID_AUDIO_MUTE:
348 ctrl->value=card->muted;
349 return (0);
350 }
351
352 return -EINVAL;
353}
354
355static int vidioc_s_ctrl (struct file *file, void *priv,
356 struct v4l2_control *ctrl)
357{
358 struct video_device *dev = video_devdata(file);
359 struct radio_device *card=dev->priv;
360
361 switch (ctrl->id) {
362 case V4L2_CID_AUDIO_MUTE:
363 card->muted = ctrl->value;
364 if(card->muted)
365 turn_power(card->io, 0);
366 else
367 set_freq(card->io, card->freq);
368 return 0;
369 }
370
371 return -EINVAL;
372}
373
374static struct video_device maxiradio_radio =
375{
376 .owner = THIS_MODULE,
377 .name = "Maxi Radio FM2000 radio",
378 .type = VID_TYPE_TUNER,
379 .fops = &maxiradio_fops,
380
381 .vidioc_querycap = vidioc_querycap,
382 .vidioc_g_tuner = vidioc_g_tuner,
383 .vidioc_s_tuner = vidioc_s_tuner,
384 .vidioc_g_audio = vidioc_g_audio,
385 .vidioc_s_audio = vidioc_s_audio,
386 .vidioc_g_input = vidioc_g_input,
387 .vidioc_s_input = vidioc_s_input,
388 .vidioc_g_frequency = vidioc_g_frequency,
389 .vidioc_s_frequency = vidioc_s_frequency,
390 .vidioc_queryctrl = vidioc_queryctrl,
391 .vidioc_g_ctrl = vidioc_g_ctrl,
392 .vidioc_s_ctrl = vidioc_s_ctrl,
393};
321 394
322static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 395static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
323{ 396{
@@ -334,7 +407,7 @@ static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_d
334 mutex_init(&radio_unit.lock); 407 mutex_init(&radio_unit.lock);
335 maxiradio_radio.priv = &radio_unit; 408 maxiradio_radio.priv = &radio_unit;
336 409
337 if(video_register_device(&maxiradio_radio, VFL_TYPE_RADIO, radio_nr)==-1) { 410 if (video_register_device(&maxiradio_radio, VFL_TYPE_RADIO, radio_nr)==-1) {
338 printk("radio-maxiradio: can't register device!"); 411 printk("radio-maxiradio: can't register device!");
339 goto err_out_free_region; 412 goto err_out_free_region;
340 } 413 }
@@ -389,3 +462,10 @@ static void __exit maxiradio_radio_exit(void)
389 462
390module_init(maxiradio_radio_init); 463module_init(maxiradio_radio_init);
391module_exit(maxiradio_radio_exit); 464module_exit(maxiradio_radio_exit);
465
466MODULE_AUTHOR("Dimitromanolakis Apostolos, apdim@grecian.net");
467MODULE_DESCRIPTION("Radio driver for the Guillemot Maxi Radio FM2000 radio.");
468MODULE_LICENSE("GPL");
469
470module_param_named(debug,maxiradio_radio.debug, int, 0644);
471MODULE_PARM_DESC(debug,"activates debug info");
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 57357db31b..7a6105153f 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -342,7 +342,7 @@ endmenu # encoder / decoder chips
342 342
343config VIDEO_VIVI 343config VIDEO_VIVI
344 tristate "Virtual Video Driver" 344 tristate "Virtual Video Driver"
345 depends on VIDEO_V4L2 && !SPARC32 && !SPARC64 345 depends on VIDEO_V4L2 && !SPARC32 && !SPARC64 && PCI
346 select VIDEO_BUF 346 select VIDEO_BUF
347 default n 347 default n
348 ---help--- 348 ---help---
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 9b1f3f06bb..44ccaed40b 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -113,4 +113,3 @@ obj-$(CONFIG_USB_QUICKCAM_MESSENGER) += usbvideo/
113obj-$(CONFIG_VIDEO_VIVI) += vivi.o 113obj-$(CONFIG_VIDEO_VIVI) += vivi.o
114 114
115EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core 115EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
116extra-cflags-$(CONFIG_VIDEO_V4L1_COMPAT) += -DCONFIG_VIDEO_V4L1_COMPAT
diff --git a/drivers/media/video/bt8xx/bttv-cards.c b/drivers/media/video/bt8xx/bttv-cards.c
index 21ebe8f138..6addc42df0 100644
--- a/drivers/media/video/bt8xx/bttv-cards.c
+++ b/drivers/media/video/bt8xx/bttv-cards.c
@@ -307,6 +307,7 @@ static struct CARD {
307 { 0x07711461, BTTV_BOARD_AVDVBT_771, "AVermedia AverTV DVB-T 771" }, 307 { 0x07711461, BTTV_BOARD_AVDVBT_771, "AVermedia AverTV DVB-T 771" },
308 { 0x07611461, BTTV_BOARD_AVDVBT_761, "AverMedia AverTV DVB-T 761" }, 308 { 0x07611461, BTTV_BOARD_AVDVBT_761, "AverMedia AverTV DVB-T 761" },
309 { 0xdb1018ac, BTTV_BOARD_DVICO_DVBT_LITE, "DViCO FusionHDTV DVB-T Lite" }, 309 { 0xdb1018ac, BTTV_BOARD_DVICO_DVBT_LITE, "DViCO FusionHDTV DVB-T Lite" },
310 { 0xdb1118ac, BTTV_BOARD_DVICO_DVBT_LITE, "Ultraview DVB-T Lite" },
310 { 0xd50018ac, BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE, "DViCO FusionHDTV 5 Lite" }, 311 { 0xd50018ac, BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE, "DViCO FusionHDTV 5 Lite" },
311 { 0x00261822, BTTV_BOARD_TWINHAN_DST, "DNTV Live! Mini "}, 312 { 0x00261822, BTTV_BOARD_TWINHAN_DST, "DNTV Live! Mini "},
312 313
@@ -578,14 +579,9 @@ struct tvcard bttv_tvcards[] = {
578 .svhs = 2, 579 .svhs = 2,
579 .gpiomask = 0x01fe00, 580 .gpiomask = 0x01fe00,
580 .muxsel = { 2, 3, 1, 1 }, 581 .muxsel = { 2, 3, 1, 1 },
581 #if 0
582 /* old */
583 .gpiomux = { 0x01c000, 0, 0x018000, 0x014000, 0x002000 },
584 #else
585 /* 2003-10-20 by "Anton A. Arapov" <arapov@mail.ru> */ 582 /* 2003-10-20 by "Anton A. Arapov" <arapov@mail.ru> */
586 .gpiomux = { 0x001e00, 0, 0x018000, 0x014000 }, 583 .gpiomux = { 0x001e00, 0, 0x018000, 0x014000 },
587 .gpiomute = 0x002000, 584 .gpiomute = 0x002000,
588 #endif
589 .needs_tvaudio = 1, 585 .needs_tvaudio = 1,
590 .pll = PLL_28, 586 .pll = PLL_28,
591 .tuner_type = -1, 587 .tuner_type = -1,
@@ -894,15 +890,10 @@ struct tvcard bttv_tvcards[] = {
894 .tuner = 0, 890 .tuner = 0,
895 .svhs = 2, 891 .svhs = 2,
896 .muxsel = { 2, 3, 1, 1, 0 }, /* TV, CVid, SVid, CVid over SVid connector */ 892 .muxsel = { 2, 3, 1, 1, 0 }, /* TV, CVid, SVid, CVid over SVid connector */
897 #if 0
898 .gpiomask = 0xc33000,
899 .gpiomux = { 0x422000,0x1000,0x0000,0x620000,0x800000 },
900 #else
901 /* Alexander Varakin <avarakin@hotmail.com> [stereo version] */ 893 /* Alexander Varakin <avarakin@hotmail.com> [stereo version] */
902 .gpiomask = 0xb33000, 894 .gpiomask = 0xb33000,
903 .gpiomux = { 0x122000,0x1000,0x0000,0x620000 }, 895 .gpiomux = { 0x122000,0x1000,0x0000,0x620000 },
904 .gpiomute = 0x800000, 896 .gpiomute = 0x800000,
905 #endif
906 /* Audio Routing for "WinFast 2000 XP" (no tv stereo !) 897 /* Audio Routing for "WinFast 2000 XP" (no tv stereo !)
907 gpio23 -- hef4052:nEnable (0x800000) 898 gpio23 -- hef4052:nEnable (0x800000)
908 gpio12 -- hef4052:A1 899 gpio12 -- hef4052:A1
@@ -1937,11 +1928,6 @@ struct tvcard bttv_tvcards[] = {
1937 .video_inputs = 4, 1928 .video_inputs = 4,
1938 .audio_inputs = 1, 1929 .audio_inputs = 1,
1939 .tuner = -1, 1930 .tuner = -1,
1940 #if 0 /* TODO ... */
1941 .svhs = OSPREY540_SVID_ANALOG,
1942 .muxsel = { [OSPREY540_COMP_ANALOG] = 2,
1943 [OSPREY540_SVID_ANALOG] = 3, },
1944 #endif
1945 .pll = PLL_28, 1931 .pll = PLL_28,
1946 .tuner_type = -1, 1932 .tuner_type = -1,
1947 .tuner_addr = ADDR_UNSET, 1933 .tuner_addr = ADDR_UNSET,
@@ -1949,10 +1935,6 @@ struct tvcard bttv_tvcards[] = {
1949 .no_msp34xx = 1, 1935 .no_msp34xx = 1,
1950 .no_tda9875 = 1, 1936 .no_tda9875 = 1,
1951 .no_tda7432 = 1, 1937 .no_tda7432 = 1,
1952 #if 0 /* TODO ... */
1953 .muxsel_hook = osprey_540_muxsel,
1954 .picture_hook = osprey_540_set_picture,
1955 #endif
1956 }, 1938 },
1957 1939
1958 /* ---- card 0x5C ---------------------------------- */ 1940 /* ---- card 0x5C ---------------------------------- */
@@ -2627,9 +2609,6 @@ struct tvcard bttv_tvcards[] = {
2627 .tuner_addr = ADDR_UNSET, 2609 .tuner_addr = ADDR_UNSET,
2628 .radio_addr = ADDR_UNSET, 2610 .radio_addr = ADDR_UNSET,
2629 .has_radio = 0, 2611 .has_radio = 0,
2630 #if 0
2631 .has_remote = 1,
2632 #endif
2633 }, 2612 },
2634 [BTTV_BOARD_SUPER_TV] = { 2613 [BTTV_BOARD_SUPER_TV] = {
2635 /* Rick C <cryptdragoon@gmail.com> */ 2614 /* Rick C <cryptdragoon@gmail.com> */
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index 41fd09d7d1..5720b77ac9 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -9,6 +9,10 @@
9 some v4l2 code lines are taken from Justin's bttv2 driver which is 9 some v4l2 code lines are taken from Justin's bttv2 driver which is
10 (c) 2000 Justin Schoeman <justin@suntiger.ee.up.ac.za> 10 (c) 2000 Justin Schoeman <justin@suntiger.ee.up.ac.za>
11 11
12 Cropping and overscan support
13 Copyright (C) 2005, 2006 Michael H. Schimek <mschimek@gmx.at>
14 Sponsored by OPQ Systems AB
15
12 This program is free software; you can redistribute it and/or modify 16 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 17 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 18 the Free Software Foundation; either version 2 of the License, or
@@ -64,6 +68,7 @@ static unsigned int radio[BTTV_MAX];
64static unsigned int irq_debug; 68static unsigned int irq_debug;
65static unsigned int gbuffers = 8; 69static unsigned int gbuffers = 8;
66static unsigned int gbufsize = 0x208000; 70static unsigned int gbufsize = 0x208000;
71static unsigned int reset_crop = 1;
67 72
68static int video_nr = -1; 73static int video_nr = -1;
69static int radio_nr = -1; 74static int radio_nr = -1;
@@ -103,6 +108,7 @@ module_param(radio_nr, int, 0444);
103module_param(vbi_nr, int, 0444); 108module_param(vbi_nr, int, 0444);
104module_param(gbuffers, int, 0444); 109module_param(gbuffers, int, 0444);
105module_param(gbufsize, int, 0444); 110module_param(gbufsize, int, 0444);
111module_param(reset_crop, int, 0444);
106 112
107module_param(v4l2, int, 0644); 113module_param(v4l2, int, 0644);
108module_param(bigendian, int, 0644); 114module_param(bigendian, int, 0644);
@@ -129,6 +135,8 @@ MODULE_PARM_DESC(bttv_debug,"debug messages, default is 0 (no)");
129MODULE_PARM_DESC(irq_debug,"irq handler debug messages, default is 0 (no)"); 135MODULE_PARM_DESC(irq_debug,"irq handler debug messages, default is 0 (no)");
130MODULE_PARM_DESC(gbuffers,"number of capture buffers. range 2-32, default 8"); 136MODULE_PARM_DESC(gbuffers,"number of capture buffers. range 2-32, default 8");
131MODULE_PARM_DESC(gbufsize,"size of the capture buffers, default is 0x208000"); 137MODULE_PARM_DESC(gbufsize,"size of the capture buffers, default is 0x208000");
138MODULE_PARM_DESC(reset_crop,"reset cropping parameters at open(), default "
139 "is 1 (yes) for compatibility with older applications");
132MODULE_PARM_DESC(automute,"mute audio on bad/missing video signal, default is 1 (yes)"); 140MODULE_PARM_DESC(automute,"mute audio on bad/missing video signal, default is 1 (yes)");
133MODULE_PARM_DESC(chroma_agc,"enables the AGC of chroma signal, default is 0 (no)"); 141MODULE_PARM_DESC(chroma_agc,"enables the AGC of chroma signal, default is 0 (no)");
134MODULE_PARM_DESC(adc_crush,"enables the luminance ADC crush, default is 1 (yes)"); 142MODULE_PARM_DESC(adc_crush,"enables the luminance ADC crush, default is 1 (yes)");
@@ -192,6 +200,33 @@ static u8 SRAM_Table[][60] =
192 } 200 }
193}; 201};
194 202
203/* minhdelayx1 first video pixel we can capture on a line and
204 hdelayx1 start of active video, both relative to rising edge of
205 /HRESET pulse (0H) in 1 / fCLKx1.
206 swidth width of active video and
207 totalwidth total line width, both in 1 / fCLKx1.
208 sqwidth total line width in square pixels.
209 vdelay start of active video in 2 * field lines relative to
210 trailing edge of /VRESET pulse (VDELAY register).
211 sheight height of active video in 2 * field lines.
212 videostart0 ITU-R frame line number of the line corresponding
213 to vdelay in the first field. */
214#define CROPCAP(minhdelayx1, hdelayx1, swidth, totalwidth, sqwidth, \
215 vdelay, sheight, videostart0) \
216 .cropcap.bounds.left = minhdelayx1, \
217 /* * 2 because vertically we count field lines times two, */ \
218 /* e.g. 23 * 2 to 23 * 2 + 576 in PAL-BGHI defrect. */ \
219 .cropcap.bounds.top = (videostart0) * 2 - (vdelay) + MIN_VDELAY, \
220 /* 4 is a safety margin at the end of the line. */ \
221 .cropcap.bounds.width = (totalwidth) - (minhdelayx1) - 4, \
222 .cropcap.bounds.height = (sheight) + (vdelay) - MIN_VDELAY, \
223 .cropcap.defrect.left = hdelayx1, \
224 .cropcap.defrect.top = (videostart0) * 2, \
225 .cropcap.defrect.width = swidth, \
226 .cropcap.defrect.height = sheight, \
227 .cropcap.pixelaspect.numerator = totalwidth, \
228 .cropcap.pixelaspect.denominator = sqwidth,
229
195const struct bttv_tvnorm bttv_tvnorms[] = { 230const struct bttv_tvnorm bttv_tvnorms[] = {
196 /* PAL-BDGHI */ 231 /* PAL-BDGHI */
197 /* max. active video is actually 922, but 924 is divisible by 4 and 3! */ 232 /* max. active video is actually 922, but 924 is divisible by 4 and 3! */
@@ -210,11 +245,26 @@ const struct bttv_tvnorm bttv_tvnorms[] = {
210 .hdelayx1 = 186, 245 .hdelayx1 = 186,
211 .hactivex1 = 924, 246 .hactivex1 = 924,
212 .vdelay = 0x20, 247 .vdelay = 0x20,
213 .vbipack = 255, 248 .vbipack = 255, /* min (2048 / 4, 0x1ff) & 0xff */
214 .sram = 0, 249 .sram = 0,
215 /* ITU-R frame line number of the first VBI line 250 /* ITU-R frame line number of the first VBI line
216 we can capture, of the first and second field. */ 251 we can capture, of the first and second field.
217 .vbistart = { 7,320 }, 252 The last line is determined by cropcap.bounds. */
253 .vbistart = { 7, 320 },
254 CROPCAP(/* minhdelayx1 */ 68,
255 /* hdelayx1 */ 186,
256 /* Should be (768 * 1135 + 944 / 2) / 944.
257 cropcap.defrect is used for image width
258 checks, so we keep the old value 924. */
259 /* swidth */ 924,
260 /* totalwidth */ 1135,
261 /* sqwidth */ 944,
262 /* vdelay */ 0x20,
263 /* sheight */ 576,
264 /* videostart0 */ 23)
265 /* bt878 (and bt848?) can capture another
266 line below active video. */
267 .cropcap.bounds.height = (576 + 2) + 0x20 - 2,
218 },{ 268 },{
219 .v4l2_id = V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_KR, 269 .v4l2_id = V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_KR,
220 .name = "NTSC", 270 .name = "NTSC",
@@ -229,9 +279,18 @@ const struct bttv_tvnorm bttv_tvnorms[] = {
229 .hdelayx1 = 128, 279 .hdelayx1 = 128,
230 .hactivex1 = 910, 280 .hactivex1 = 910,
231 .vdelay = 0x1a, 281 .vdelay = 0x1a,
232 .vbipack = 144, 282 .vbipack = 144, /* min (1600 / 4, 0x1ff) & 0xff */
233 .sram = 1, 283 .sram = 1,
234 .vbistart = { 10, 273 }, 284 .vbistart = { 10, 273 },
285 CROPCAP(/* minhdelayx1 */ 68,
286 /* hdelayx1 */ 128,
287 /* Should be (640 * 910 + 780 / 2) / 780? */
288 /* swidth */ 768,
289 /* totalwidth */ 910,
290 /* sqwidth */ 780,
291 /* vdelay */ 0x1a,
292 /* sheight */ 480,
293 /* videostart0 */ 23)
235 },{ 294 },{
236 .v4l2_id = V4L2_STD_SECAM, 295 .v4l2_id = V4L2_STD_SECAM,
237 .name = "SECAM", 296 .name = "SECAM",
@@ -249,6 +308,14 @@ const struct bttv_tvnorm bttv_tvnorms[] = {
249 .vbipack = 255, 308 .vbipack = 255,
250 .sram = 0, /* like PAL, correct? */ 309 .sram = 0, /* like PAL, correct? */
251 .vbistart = { 7, 320 }, 310 .vbistart = { 7, 320 },
311 CROPCAP(/* minhdelayx1 */ 68,
312 /* hdelayx1 */ 186,
313 /* swidth */ 924,
314 /* totalwidth */ 1135,
315 /* sqwidth */ 944,
316 /* vdelay */ 0x20,
317 /* sheight */ 576,
318 /* videostart0 */ 23)
252 },{ 319 },{
253 .v4l2_id = V4L2_STD_PAL_Nc, 320 .v4l2_id = V4L2_STD_PAL_Nc,
254 .name = "PAL-Nc", 321 .name = "PAL-Nc",
@@ -266,6 +333,14 @@ const struct bttv_tvnorm bttv_tvnorms[] = {
266 .vbipack = 144, 333 .vbipack = 144,
267 .sram = -1, 334 .sram = -1,
268 .vbistart = { 7, 320 }, 335 .vbistart = { 7, 320 },
336 CROPCAP(/* minhdelayx1 */ 68,
337 /* hdelayx1 */ 130,
338 /* swidth */ (640 * 910 + 780 / 2) / 780,
339 /* totalwidth */ 910,
340 /* sqwidth */ 780,
341 /* vdelay */ 0x1a,
342 /* sheight */ 576,
343 /* videostart0 */ 23)
269 },{ 344 },{
270 .v4l2_id = V4L2_STD_PAL_M, 345 .v4l2_id = V4L2_STD_PAL_M,
271 .name = "PAL-M", 346 .name = "PAL-M",
@@ -283,6 +358,14 @@ const struct bttv_tvnorm bttv_tvnorms[] = {
283 .vbipack = 144, 358 .vbipack = 144,
284 .sram = -1, 359 .sram = -1,
285 .vbistart = { 10, 273 }, 360 .vbistart = { 10, 273 },
361 CROPCAP(/* minhdelayx1 */ 68,
362 /* hdelayx1 */ 135,
363 /* swidth */ (640 * 910 + 780 / 2) / 780,
364 /* totalwidth */ 910,
365 /* sqwidth */ 780,
366 /* vdelay */ 0x1a,
367 /* sheight */ 480,
368 /* videostart0 */ 23)
286 },{ 369 },{
287 .v4l2_id = V4L2_STD_PAL_N, 370 .v4l2_id = V4L2_STD_PAL_N,
288 .name = "PAL-N", 371 .name = "PAL-N",
@@ -299,7 +382,15 @@ const struct bttv_tvnorm bttv_tvnorms[] = {
299 .vdelay = 0x20, 382 .vdelay = 0x20,
300 .vbipack = 144, 383 .vbipack = 144,
301 .sram = -1, 384 .sram = -1,
302 .vbistart = { 7, 320}, 385 .vbistart = { 7, 320 },
386 CROPCAP(/* minhdelayx1 */ 68,
387 /* hdelayx1 */ 186,
388 /* swidth */ (768 * 1135 + 944 / 2) / 944,
389 /* totalwidth */ 1135,
390 /* sqwidth */ 944,
391 /* vdelay */ 0x20,
392 /* sheight */ 576,
393 /* videostart0 */ 23)
303 },{ 394 },{
304 .v4l2_id = V4L2_STD_NTSC_M_JP, 395 .v4l2_id = V4L2_STD_NTSC_M_JP,
305 .name = "NTSC-JP", 396 .name = "NTSC-JP",
@@ -316,7 +407,15 @@ const struct bttv_tvnorm bttv_tvnorms[] = {
316 .vdelay = 0x16, 407 .vdelay = 0x16,
317 .vbipack = 144, 408 .vbipack = 144,
318 .sram = -1, 409 .sram = -1,
319 .vbistart = {10, 273}, 410 .vbistart = { 10, 273 },
411 CROPCAP(/* minhdelayx1 */ 68,
412 /* hdelayx1 */ 135,
413 /* swidth */ (640 * 910 + 780 / 2) / 780,
414 /* totalwidth */ 910,
415 /* sqwidth */ 780,
416 /* vdelay */ 0x16,
417 /* sheight */ 480,
418 /* videostart0 */ 23)
320 },{ 419 },{
321 /* that one hopefully works with the strange timing 420 /* that one hopefully works with the strange timing
322 * which video recorders produce when playing a NTSC 421 * which video recorders produce when playing a NTSC
@@ -338,6 +437,14 @@ const struct bttv_tvnorm bttv_tvnorms[] = {
338 .vtotal = 524, 437 .vtotal = 524,
339 .sram = -1, 438 .sram = -1,
340 .vbistart = { 10, 273 }, 439 .vbistart = { 10, 273 },
440 CROPCAP(/* minhdelayx1 */ 68,
441 /* hdelayx1 */ 186,
442 /* swidth */ 924,
443 /* totalwidth */ 1135,
444 /* sqwidth */ 944,
445 /* vdelay */ 0x1a,
446 /* sheight */ 480,
447 /* videostart0 */ 23)
341 } 448 }
342}; 449};
343static const unsigned int BTTV_TVNORMS = ARRAY_SIZE(bttv_tvnorms); 450static const unsigned int BTTV_TVNORMS = ARRAY_SIZE(bttv_tvnorms);
@@ -678,25 +785,89 @@ static const int BTTV_CTLS = ARRAY_SIZE(bttv_ctls);
678/* ----------------------------------------------------------------------- */ 785/* ----------------------------------------------------------------------- */
679/* resource management */ 786/* resource management */
680 787
788/*
789 RESOURCE_ allocated by freed by
790
791 VIDEO_READ bttv_read 1) bttv_read 2)
792
793 VIDEO_STREAM VIDIOC_STREAMON VIDIOC_STREAMOFF
794 VIDIOC_QBUF 1) bttv_release
795 VIDIOCMCAPTURE 1)
796
797 OVERLAY VIDIOCCAPTURE on VIDIOCCAPTURE off
798 VIDIOC_OVERLAY on VIDIOC_OVERLAY off
799 3) bttv_release
800
801 VBI VIDIOC_STREAMON VIDIOC_STREAMOFF
802 VIDIOC_QBUF 1) bttv_release
803 bttv_read, bttv_poll 1) 4)
804
805 1) The resource must be allocated when we enter buffer prepare functions
806 and remain allocated while buffers are in the DMA queue.
807 2) This is a single frame read.
808 3) VIDIOC_S_FBUF and VIDIOC_S_FMT (OVERLAY) still work when
809 RESOURCE_OVERLAY is allocated.
810 4) This is a continuous read, implies VIDIOC_STREAMON.
811
812 Note this driver permits video input and standard changes regardless if
813 resources are allocated.
814*/
815
816#define VBI_RESOURCES (RESOURCE_VBI)
817#define VIDEO_RESOURCES (RESOURCE_VIDEO_READ | \
818 RESOURCE_VIDEO_STREAM | \
819 RESOURCE_OVERLAY)
820
681static 821static
682int check_alloc_btres(struct bttv *btv, struct bttv_fh *fh, int bit) 822int check_alloc_btres(struct bttv *btv, struct bttv_fh *fh, int bit)
683{ 823{
824 int xbits; /* mutual exclusive resources */
825
684 if (fh->resources & bit) 826 if (fh->resources & bit)
685 /* have it already allocated */ 827 /* have it already allocated */
686 return 1; 828 return 1;
687 829
830 xbits = bit;
831 if (bit & (RESOURCE_VIDEO_READ | RESOURCE_VIDEO_STREAM))
832 xbits |= RESOURCE_VIDEO_READ | RESOURCE_VIDEO_STREAM;
833
688 /* is it free? */ 834 /* is it free? */
689 mutex_lock(&btv->reslock); 835 mutex_lock(&btv->lock);
690 if (btv->resources & bit) { 836 if (btv->resources & xbits) {
691 /* no, someone else uses it */ 837 /* no, someone else uses it */
692 mutex_unlock(&btv->reslock); 838 goto fail;
693 return 0; 839 }
840
841 if ((bit & VIDEO_RESOURCES)
842 && 0 == (btv->resources & VIDEO_RESOURCES)) {
843 /* Do crop - use current, don't - use default parameters. */
844 __s32 top = btv->crop[!!fh->do_crop].rect.top;
845
846 if (btv->vbi_end > top)
847 goto fail;
848
849 /* We cannot capture the same line as video and VBI data.
850 Claim scan lines crop[].rect.top to bottom. */
851 btv->crop_start = top;
852 } else if (bit & VBI_RESOURCES) {
853 __s32 end = fh->vbi_fmt.end;
854
855 if (end > btv->crop_start)
856 goto fail;
857
858 /* Claim scan lines above fh->vbi_fmt.end. */
859 btv->vbi_end = end;
694 } 860 }
861
695 /* it's free, grab it */ 862 /* it's free, grab it */
696 fh->resources |= bit; 863 fh->resources |= bit;
697 btv->resources |= bit; 864 btv->resources |= bit;
698 mutex_unlock(&btv->reslock); 865 mutex_unlock(&btv->lock);
699 return 1; 866 return 1;
867
868 fail:
869 mutex_unlock(&btv->lock);
870 return 0;
700} 871}
701 872
702static 873static
@@ -711,6 +882,35 @@ int locked_btres(struct bttv *btv, int bit)
711 return (btv->resources & bit); 882 return (btv->resources & bit);
712} 883}
713 884
885/* Call with btv->lock down. */
886static void
887disclaim_vbi_lines(struct bttv *btv)
888{
889 btv->vbi_end = 0;
890}
891
892/* Call with btv->lock down. */
893static void
894disclaim_video_lines(struct bttv *btv)
895{
896 const struct bttv_tvnorm *tvnorm;
897 u8 crop;
898
899 tvnorm = &bttv_tvnorms[btv->tvnorm];
900 btv->crop_start = tvnorm->cropcap.bounds.top
901 + tvnorm->cropcap.bounds.height;
902
903 /* VBI capturing ends at VDELAY, start of video capturing, no
904 matter how many lines the VBI RISC program expects. When video
905 capturing is off, it shall no longer "preempt" VBI capturing,
906 so we set VDELAY to maximum. */
907 crop = btread(BT848_E_CROP) | 0xc0;
908 btwrite(crop, BT848_E_CROP);
909 btwrite(0xfe, BT848_E_VDELAY_LO);
910 btwrite(crop, BT848_O_CROP);
911 btwrite(0xfe, BT848_O_VDELAY_LO);
912}
913
714static 914static
715void free_btres(struct bttv *btv, struct bttv_fh *fh, int bits) 915void free_btres(struct bttv *btv, struct bttv_fh *fh, int bits)
716{ 916{
@@ -718,10 +918,19 @@ void free_btres(struct bttv *btv, struct bttv_fh *fh, int bits)
718 /* trying to free ressources not allocated by us ... */ 918 /* trying to free ressources not allocated by us ... */
719 printk("bttv: BUG! (btres)\n"); 919 printk("bttv: BUG! (btres)\n");
720 } 920 }
721 mutex_lock(&btv->reslock); 921 mutex_lock(&btv->lock);
722 fh->resources &= ~bits; 922 fh->resources &= ~bits;
723 btv->resources &= ~bits; 923 btv->resources &= ~bits;
724 mutex_unlock(&btv->reslock); 924
925 bits = btv->resources;
926
927 if (0 == (bits & VIDEO_RESOURCES))
928 disclaim_video_lines(btv);
929
930 if (0 == (bits & VBI_RESOURCES))
931 disclaim_vbi_lines(btv);
932
933 mutex_unlock(&btv->lock);
725} 934}
726 935
727/* ----------------------------------------------------------------------- */ 936/* ----------------------------------------------------------------------- */
@@ -1030,6 +1239,36 @@ i2c_vidiocschan(struct bttv *btv)
1030 bttv_tda9880_setnorm(btv,btv->tvnorm); 1239 bttv_tda9880_setnorm(btv,btv->tvnorm);
1031} 1240}
1032 1241
1242static void
1243bttv_crop_calc_limits(struct bttv_crop *c)
1244{
1245 /* Scale factor min. 1:1, max. 16:1. Min. image size
1246 48 x 32. Scaled width must be a multiple of 4. */
1247
1248 if (1) {
1249 /* For bug compatibility with VIDIOCGCAP and image
1250 size checks in earlier driver versions. */
1251 c->min_scaled_width = 48;
1252 c->min_scaled_height = 32;
1253 } else {
1254 c->min_scaled_width =
1255 (max(48, c->rect.width >> 4) + 3) & ~3;
1256 c->min_scaled_height =
1257 max(32, c->rect.height >> 4);
1258 }
1259
1260 c->max_scaled_width = c->rect.width & ~3;
1261 c->max_scaled_height = c->rect.height;
1262}
1263
1264static void
1265bttv_crop_reset(struct bttv_crop *c, int norm)
1266{
1267 c->rect = bttv_tvnorms[norm].cropcap.defrect;
1268 bttv_crop_calc_limits(c);
1269}
1270
1271/* Call with btv->lock down. */
1033static int 1272static int
1034set_tvnorm(struct bttv *btv, unsigned int norm) 1273set_tvnorm(struct bttv *btv, unsigned int norm)
1035{ 1274{
@@ -1038,9 +1277,24 @@ set_tvnorm(struct bttv *btv, unsigned int norm)
1038 if (norm < 0 || norm >= BTTV_TVNORMS) 1277 if (norm < 0 || norm >= BTTV_TVNORMS)
1039 return -EINVAL; 1278 return -EINVAL;
1040 1279
1041 btv->tvnorm = norm;
1042 tvnorm = &bttv_tvnorms[norm]; 1280 tvnorm = &bttv_tvnorms[norm];
1043 1281
1282 if (btv->tvnorm < 0 ||
1283 btv->tvnorm >= BTTV_TVNORMS ||
1284 0 != memcmp(&bttv_tvnorms[btv->tvnorm].cropcap,
1285 &tvnorm->cropcap,
1286 sizeof (tvnorm->cropcap))) {
1287 bttv_crop_reset(&btv->crop[0], norm);
1288 btv->crop[1] = btv->crop[0]; /* current = default */
1289
1290 if (0 == (btv->resources & VIDEO_RESOURCES)) {
1291 btv->crop_start = tvnorm->cropcap.bounds.top
1292 + tvnorm->cropcap.bounds.height;
1293 }
1294 }
1295
1296 btv->tvnorm = norm;
1297
1044 btwrite(tvnorm->adelay, BT848_ADELAY); 1298 btwrite(tvnorm->adelay, BT848_ADELAY);
1045 btwrite(tvnorm->bdelay, BT848_BDELAY); 1299 btwrite(tvnorm->bdelay, BT848_BDELAY);
1046 btaor(tvnorm->iform,~(BT848_IFORM_NORM|BT848_IFORM_XTBOTH), 1300 btaor(tvnorm->iform,~(BT848_IFORM_NORM|BT848_IFORM_XTBOTH),
@@ -1057,6 +1311,7 @@ set_tvnorm(struct bttv *btv, unsigned int norm)
1057 return 0; 1311 return 0;
1058} 1312}
1059 1313
1314/* Call with btv->lock down. */
1060static void 1315static void
1061set_input(struct bttv *btv, unsigned int input) 1316set_input(struct bttv *btv, unsigned int input)
1062{ 1317{
@@ -1459,13 +1714,13 @@ bttv_switch_overlay(struct bttv *btv, struct bttv_fh *fh,
1459 btv->loop_irq |= 1; 1714 btv->loop_irq |= 1;
1460 bttv_set_dma(btv, 0x03); 1715 bttv_set_dma(btv, 0x03);
1461 spin_unlock_irqrestore(&btv->s_lock,flags); 1716 spin_unlock_irqrestore(&btv->s_lock,flags);
1462 if (NULL == new)
1463 free_btres(btv,fh,RESOURCE_OVERLAY);
1464 if (NULL != old) { 1717 if (NULL != old) {
1465 dprintk("switch_overlay: old=%p state is %d\n",old,old->vb.state); 1718 dprintk("switch_overlay: old=%p state is %d\n",old,old->vb.state);
1466 bttv_dma_free(&fh->cap,btv, old); 1719 bttv_dma_free(&fh->cap,btv, old);
1467 kfree(old); 1720 kfree(old);
1468 } 1721 }
1722 if (NULL == new)
1723 free_btres(btv,fh,RESOURCE_OVERLAY);
1469 dprintk("switch_overlay: done\n"); 1724 dprintk("switch_overlay: done\n");
1470 return retval; 1725 return retval;
1471} 1726}
@@ -1479,7 +1734,10 @@ static int bttv_prepare_buffer(struct videobuf_queue *q,struct bttv *btv,
1479 unsigned int width, unsigned int height, 1734 unsigned int width, unsigned int height,
1480 enum v4l2_field field) 1735 enum v4l2_field field)
1481{ 1736{
1737 struct bttv_fh *fh = q->priv_data;
1482 int redo_dma_risc = 0; 1738 int redo_dma_risc = 0;
1739 struct bttv_crop c;
1740 int norm;
1483 int rc; 1741 int rc;
1484 1742
1485 /* check settings */ 1743 /* check settings */
@@ -1491,12 +1749,52 @@ static int bttv_prepare_buffer(struct videobuf_queue *q,struct bttv *btv,
1491 if (width*height > buf->vb.bsize) 1749 if (width*height > buf->vb.bsize)
1492 return -EINVAL; 1750 return -EINVAL;
1493 buf->vb.size = buf->vb.bsize; 1751 buf->vb.size = buf->vb.bsize;
1752
1753 /* Make sure tvnorm and vbi_end remain consistent
1754 until we're done. */
1755 mutex_lock(&btv->lock);
1756
1757 norm = btv->tvnorm;
1758
1759 /* In this mode capturing always starts at defrect.top
1760 (default VDELAY), ignoring cropping parameters. */
1761 if (btv->vbi_end > bttv_tvnorms[norm].cropcap.defrect.top) {
1762 mutex_unlock(&btv->lock);
1763 return -EINVAL;
1764 }
1765
1766 mutex_unlock(&btv->lock);
1767
1768 c.rect = bttv_tvnorms[norm].cropcap.defrect;
1494 } else { 1769 } else {
1495 if (width < 48 || 1770 mutex_lock(&btv->lock);
1496 height < 32 || 1771
1497 width > bttv_tvnorms[btv->tvnorm].swidth || 1772 norm = btv->tvnorm;
1498 height > bttv_tvnorms[btv->tvnorm].sheight) 1773 c = btv->crop[!!fh->do_crop];
1774
1775 mutex_unlock(&btv->lock);
1776
1777 if (width < c.min_scaled_width ||
1778 width > c.max_scaled_width ||
1779 height < c.min_scaled_height)
1499 return -EINVAL; 1780 return -EINVAL;
1781
1782 switch (field) {
1783 case V4L2_FIELD_TOP:
1784 case V4L2_FIELD_BOTTOM:
1785 case V4L2_FIELD_ALTERNATE:
1786 /* btv->crop counts frame lines. Max. scale
1787 factor is 16:1 for frames, 8:1 for fields. */
1788 if (height * 2 > c.max_scaled_height)
1789 return -EINVAL;
1790 break;
1791
1792 default:
1793 if (height > c.max_scaled_height)
1794 return -EINVAL;
1795 break;
1796 }
1797
1500 buf->vb.size = (width * height * fmt->depth) >> 3; 1798 buf->vb.size = (width * height * fmt->depth) >> 3;
1501 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) 1799 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
1502 return -EINVAL; 1800 return -EINVAL;
@@ -1505,12 +1803,17 @@ static int bttv_prepare_buffer(struct videobuf_queue *q,struct bttv *btv,
1505 /* alloc + fill struct bttv_buffer (if changed) */ 1803 /* alloc + fill struct bttv_buffer (if changed) */
1506 if (buf->vb.width != width || buf->vb.height != height || 1804 if (buf->vb.width != width || buf->vb.height != height ||
1507 buf->vb.field != field || 1805 buf->vb.field != field ||
1508 buf->tvnorm != btv->tvnorm || buf->fmt != fmt) { 1806 buf->tvnorm != norm || buf->fmt != fmt ||
1807 buf->crop.top != c.rect.top ||
1808 buf->crop.left != c.rect.left ||
1809 buf->crop.width != c.rect.width ||
1810 buf->crop.height != c.rect.height) {
1509 buf->vb.width = width; 1811 buf->vb.width = width;
1510 buf->vb.height = height; 1812 buf->vb.height = height;
1511 buf->vb.field = field; 1813 buf->vb.field = field;
1512 buf->tvnorm = btv->tvnorm; 1814 buf->tvnorm = norm;
1513 buf->fmt = fmt; 1815 buf->fmt = fmt;
1816 buf->crop = c.rect;
1514 redo_dma_risc = 1; 1817 redo_dma_risc = 1;
1515 } 1818 }
1516 1819
@@ -1577,7 +1880,7 @@ static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
1577 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); 1880 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb);
1578 struct bttv_fh *fh = q->priv_data; 1881 struct bttv_fh *fh = q->priv_data;
1579 1882
1580 bttv_dma_free(&fh->cap,fh->btv,buf); 1883 bttv_dma_free(q,fh->btv,buf);
1581} 1884}
1582 1885
1583static struct videobuf_queue_ops bttv_video_qops = { 1886static struct videobuf_queue_ops bttv_video_qops = {
@@ -1939,11 +2242,179 @@ static int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg)
1939 return 0; 2242 return 0;
1940} 2243}
1941 2244
1942static int verify_window(const struct bttv_tvnorm *tvn, 2245/* Given cropping boundaries b and the scaled width and height of a
1943 struct v4l2_window *win, int fixup) 2246 single field or frame, which must not exceed hardware limits, this
2247 function adjusts the cropping parameters c. */
2248static void
2249bttv_crop_adjust (struct bttv_crop * c,
2250 const struct v4l2_rect * b,
2251 __s32 width,
2252 __s32 height,
2253 enum v4l2_field field)
2254{
2255 __s32 frame_height = height << !V4L2_FIELD_HAS_BOTH(field);
2256 __s32 max_left;
2257 __s32 max_top;
2258
2259 if (width < c->min_scaled_width) {
2260 /* Max. hor. scale factor 16:1. */
2261 c->rect.width = width * 16;
2262 } else if (width > c->max_scaled_width) {
2263 /* Min. hor. scale factor 1:1. */
2264 c->rect.width = width;
2265
2266 max_left = b->left + b->width - width;
2267 max_left = min(max_left, (__s32) MAX_HDELAY);
2268 if (c->rect.left > max_left)
2269 c->rect.left = max_left;
2270 }
2271
2272 if (height < c->min_scaled_height) {
2273 /* Max. vert. scale factor 16:1, single fields 8:1. */
2274 c->rect.height = height * 16;
2275 } else if (frame_height > c->max_scaled_height) {
2276 /* Min. vert. scale factor 1:1.
2277 Top and height count field lines times two. */
2278 c->rect.height = (frame_height + 1) & ~1;
2279
2280 max_top = b->top + b->height - c->rect.height;
2281 if (c->rect.top > max_top)
2282 c->rect.top = max_top;
2283 }
2284
2285 bttv_crop_calc_limits(c);
2286}
2287
2288/* Returns an error if scaling to a frame or single field with the given
2289 width and height is not possible with the current cropping parameters
2290 and width aligned according to width_mask. If adjust_size is TRUE the
2291 function may adjust the width and/or height instead, rounding width
2292 to (width + width_bias) & width_mask. If adjust_crop is TRUE it may
2293 also adjust the current cropping parameters to get closer to the
2294 desired image size. */
2295static int
2296limit_scaled_size (struct bttv_fh * fh,
2297 __s32 * width,
2298 __s32 * height,
2299 enum v4l2_field field,
2300 unsigned int width_mask,
2301 unsigned int width_bias,
2302 int adjust_size,
2303 int adjust_crop)
2304{
2305 struct bttv *btv = fh->btv;
2306 const struct v4l2_rect *b;
2307 struct bttv_crop *c;
2308 __s32 min_width;
2309 __s32 min_height;
2310 __s32 max_width;
2311 __s32 max_height;
2312 int rc;
2313
2314 BUG_ON((int) width_mask >= 0 ||
2315 width_bias >= (unsigned int) -width_mask);
2316
2317 /* Make sure tvnorm, vbi_end and the current cropping parameters
2318 remain consistent until we're done. */
2319 mutex_lock(&btv->lock);
2320
2321 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds;
2322
2323 /* Do crop - use current, don't - use default parameters. */
2324 c = &btv->crop[!!fh->do_crop];
2325
2326 if (fh->do_crop
2327 && adjust_size
2328 && adjust_crop
2329 && !locked_btres(btv, VIDEO_RESOURCES)) {
2330 min_width = 48;
2331 min_height = 32;
2332
2333 /* We cannot scale up. When the scaled image is larger
2334 than crop.rect we adjust the crop.rect as required
2335 by the V4L2 spec, hence cropcap.bounds are our limit. */
2336 max_width = min(b->width, (__s32) MAX_HACTIVE);
2337 max_height = b->height;
2338
2339 /* We cannot capture the same line as video and VBI data.
2340 Note btv->vbi_end is really a minimum, see
2341 bttv_vbi_try_fmt(). */
2342 if (btv->vbi_end > b->top) {
2343 max_height -= btv->vbi_end - b->top;
2344 rc = -EBUSY;
2345 if (min_height > max_height)
2346 goto fail;
2347 }
2348 } else {
2349 rc = -EBUSY;
2350 if (btv->vbi_end > c->rect.top)
2351 goto fail;
2352
2353 min_width = c->min_scaled_width;
2354 min_height = c->min_scaled_height;
2355 max_width = c->max_scaled_width;
2356 max_height = c->max_scaled_height;
2357
2358 adjust_crop = 0;
2359 }
2360
2361 min_width = (min_width - width_mask - 1) & width_mask;
2362 max_width = max_width & width_mask;
2363
2364 /* Max. scale factor is 16:1 for frames, 8:1 for fields. */
2365 min_height = min_height;
2366 /* Min. scale factor is 1:1. */
2367 max_height >>= !V4L2_FIELD_HAS_BOTH(field);
2368
2369 if (adjust_size) {
2370 *width = clamp(*width, min_width, max_width);
2371 *height = clamp(*height, min_height, max_height);
2372
2373 /* Round after clamping to avoid overflow. */
2374 *width = (*width + width_bias) & width_mask;
2375
2376 if (adjust_crop) {
2377 bttv_crop_adjust(c, b, *width, *height, field);
2378
2379 if (btv->vbi_end > c->rect.top) {
2380 /* Move the crop window out of the way. */
2381 c->rect.top = btv->vbi_end;
2382 }
2383 }
2384 } else {
2385 rc = -EINVAL;
2386 if (*width < min_width ||
2387 *height < min_height ||
2388 *width > max_width ||
2389 *height > max_height ||
2390 0 != (*width & ~width_mask))
2391 goto fail;
2392 }
2393
2394 rc = 0; /* success */
2395
2396 fail:
2397 mutex_unlock(&btv->lock);
2398
2399 return rc;
2400}
2401
2402/* Returns an error if the given overlay window dimensions are not
2403 possible with the current cropping parameters. If adjust_size is
2404 TRUE the function may adjust the window width and/or height
2405 instead, however it always rounds the horizontal position and
2406 width as btcx_align() does. If adjust_crop is TRUE the function
2407 may also adjust the current cropping parameters to get closer
2408 to the desired window size. */
2409static int
2410verify_window (struct bttv_fh * fh,
2411 struct v4l2_window * win,
2412 int adjust_size,
2413 int adjust_crop)
1944{ 2414{
1945 enum v4l2_field field; 2415 enum v4l2_field field;
1946 int maxw, maxh; 2416 unsigned int width_mask;
2417 int rc;
1947 2418
1948 if (win->w.width < 48 || win->w.height < 32) 2419 if (win->w.width < 48 || win->w.height < 32)
1949 return -EINVAL; 2420 return -EINVAL;
@@ -1951,32 +2422,52 @@ static int verify_window(const struct bttv_tvnorm *tvn,
1951 return -EINVAL; 2422 return -EINVAL;
1952 2423
1953 field = win->field; 2424 field = win->field;
1954 maxw = tvn->swidth;
1955 maxh = tvn->sheight;
1956 2425
1957 if (V4L2_FIELD_ANY == field) { 2426 if (V4L2_FIELD_ANY == field) {
1958 field = (win->w.height > maxh/2) 2427 __s32 height2;
2428
2429 height2 = fh->btv->crop[!!fh->do_crop].rect.height >> 1;
2430 field = (win->w.height > height2)
1959 ? V4L2_FIELD_INTERLACED 2431 ? V4L2_FIELD_INTERLACED
1960 : V4L2_FIELD_TOP; 2432 : V4L2_FIELD_TOP;
1961 } 2433 }
1962 switch (field) { 2434 switch (field) {
1963 case V4L2_FIELD_TOP: 2435 case V4L2_FIELD_TOP:
1964 case V4L2_FIELD_BOTTOM: 2436 case V4L2_FIELD_BOTTOM:
1965 maxh = maxh / 2;
1966 break;
1967 case V4L2_FIELD_INTERLACED: 2437 case V4L2_FIELD_INTERLACED:
1968 break; 2438 break;
1969 default: 2439 default:
1970 return -EINVAL; 2440 return -EINVAL;
1971 } 2441 }
1972 2442
1973 if (!fixup && (win->w.width > maxw || win->w.height > maxh)) 2443 /* 4-byte alignment. */
2444 if (NULL == fh->ovfmt)
1974 return -EINVAL; 2445 return -EINVAL;
2446 width_mask = ~0;
2447 switch (fh->ovfmt->depth) {
2448 case 8:
2449 case 24:
2450 width_mask = ~3;
2451 break;
2452 case 16:
2453 width_mask = ~1;
2454 break;
2455 case 32:
2456 break;
2457 default:
2458 BUG();
2459 }
2460
2461 win->w.width -= win->w.left & ~width_mask;
2462 win->w.left = (win->w.left - width_mask - 1) & width_mask;
2463
2464 rc = limit_scaled_size(fh, &win->w.width, &win->w.height,
2465 field, width_mask,
2466 /* width_bias: round down */ 0,
2467 adjust_size, adjust_crop);
2468 if (0 != rc)
2469 return rc;
1975 2470
1976 if (win->w.width > maxw)
1977 win->w.width = maxw;
1978 if (win->w.height > maxh)
1979 win->w.height = maxh;
1980 win->field = field; 2471 win->field = field;
1981 return 0; 2472 return 0;
1982} 2473}
@@ -1991,7 +2482,9 @@ static int setup_window(struct bttv_fh *fh, struct bttv *btv,
1991 return -EINVAL; 2482 return -EINVAL;
1992 if (!(fh->ovfmt->flags & FORMAT_FLAGS_PACKED)) 2483 if (!(fh->ovfmt->flags & FORMAT_FLAGS_PACKED))
1993 return -EINVAL; 2484 return -EINVAL;
1994 retval = verify_window(&bttv_tvnorms[btv->tvnorm],win,fixup); 2485 retval = verify_window(fh, win,
2486 /* adjust_size */ fixup,
2487 /* adjust_crop */ fixup);
1995 if (0 != retval) 2488 if (0 != retval)
1996 return retval; 2489 return retval;
1997 2490
@@ -2048,6 +2541,7 @@ static int setup_window(struct bttv_fh *fh, struct bttv *btv,
2048 struct bttv_buffer *new; 2541 struct bttv_buffer *new;
2049 2542
2050 new = videobuf_alloc(sizeof(*new)); 2543 new = videobuf_alloc(sizeof(*new));
2544 new->crop = btv->crop[!!fh->do_crop].rect;
2051 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); 2545 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
2052 retval = bttv_switch_overlay(btv,fh,new); 2546 retval = bttv_switch_overlay(btv,fh,new);
2053 } 2547 }
@@ -2080,7 +2574,7 @@ static int bttv_resource(struct bttv_fh *fh)
2080 2574
2081 switch (fh->type) { 2575 switch (fh->type) {
2082 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 2576 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
2083 res = RESOURCE_VIDEO; 2577 res = RESOURCE_VIDEO_STREAM;
2084 break; 2578 break;
2085 case V4L2_BUF_TYPE_VBI_CAPTURE: 2579 case V4L2_BUF_TYPE_VBI_CAPTURE:
2086 res = RESOURCE_VBI; 2580 res = RESOURCE_VBI;
@@ -2138,7 +2632,7 @@ static int bttv_g_fmt(struct bttv_fh *fh, struct v4l2_format *f)
2138 f->fmt.win.field = fh->ov.field; 2632 f->fmt.win.field = fh->ov.field;
2139 return 0; 2633 return 0;
2140 case V4L2_BUF_TYPE_VBI_CAPTURE: 2634 case V4L2_BUF_TYPE_VBI_CAPTURE:
2141 bttv_vbi_get_fmt(fh,f); 2635 bttv_vbi_get_fmt(fh, &f->fmt.vbi);
2142 return 0; 2636 return 0;
2143 default: 2637 default:
2144 return -EINVAL; 2638 return -EINVAL;
@@ -2146,35 +2640,35 @@ static int bttv_g_fmt(struct bttv_fh *fh, struct v4l2_format *f)
2146} 2640}
2147 2641
2148static int bttv_try_fmt(struct bttv_fh *fh, struct bttv *btv, 2642static int bttv_try_fmt(struct bttv_fh *fh, struct bttv *btv,
2149 struct v4l2_format *f) 2643 struct v4l2_format *f, int adjust_crop)
2150{ 2644{
2151 switch (f->type) { 2645 switch (f->type) {
2152 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 2646 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
2153 { 2647 {
2154 const struct bttv_format *fmt; 2648 const struct bttv_format *fmt;
2155 enum v4l2_field field; 2649 enum v4l2_field field;
2156 unsigned int maxw,maxh; 2650 __s32 width, height;
2651 int rc;
2157 2652
2158 fmt = format_by_fourcc(f->fmt.pix.pixelformat); 2653 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
2159 if (NULL == fmt) 2654 if (NULL == fmt)
2160 return -EINVAL; 2655 return -EINVAL;
2161 2656
2162 /* fixup format */
2163 maxw = bttv_tvnorms[btv->tvnorm].swidth;
2164 maxh = bttv_tvnorms[btv->tvnorm].sheight;
2165 field = f->fmt.pix.field; 2657 field = f->fmt.pix.field;
2166 if (V4L2_FIELD_ANY == field) 2658 if (V4L2_FIELD_ANY == field) {
2167 field = (f->fmt.pix.height > maxh/2) 2659 __s32 height2;
2660
2661 height2 = btv->crop[!!fh->do_crop].rect.height >> 1;
2662 field = (f->fmt.pix.height > height2)
2168 ? V4L2_FIELD_INTERLACED 2663 ? V4L2_FIELD_INTERLACED
2169 : V4L2_FIELD_BOTTOM; 2664 : V4L2_FIELD_BOTTOM;
2665 }
2170 if (V4L2_FIELD_SEQ_BT == field) 2666 if (V4L2_FIELD_SEQ_BT == field)
2171 field = V4L2_FIELD_SEQ_TB; 2667 field = V4L2_FIELD_SEQ_TB;
2172 switch (field) { 2668 switch (field) {
2173 case V4L2_FIELD_TOP: 2669 case V4L2_FIELD_TOP:
2174 case V4L2_FIELD_BOTTOM: 2670 case V4L2_FIELD_BOTTOM:
2175 case V4L2_FIELD_ALTERNATE: 2671 case V4L2_FIELD_ALTERNATE:
2176 maxh = maxh/2;
2177 break;
2178 case V4L2_FIELD_INTERLACED: 2672 case V4L2_FIELD_INTERLACED:
2179 break; 2673 break;
2180 case V4L2_FIELD_SEQ_TB: 2674 case V4L2_FIELD_SEQ_TB:
@@ -2185,28 +2679,29 @@ static int bttv_try_fmt(struct bttv_fh *fh, struct bttv *btv,
2185 return -EINVAL; 2679 return -EINVAL;
2186 } 2680 }
2187 2681
2682 width = f->fmt.pix.width;
2683 height = f->fmt.pix.height;
2684
2685 rc = limit_scaled_size(fh, &width, &height, field,
2686 /* width_mask: 4 pixels */ ~3,
2687 /* width_bias: nearest */ 2,
2688 /* adjust_size */ 1,
2689 adjust_crop);
2690 if (0 != rc)
2691 return rc;
2692
2188 /* update data for the application */ 2693 /* update data for the application */
2189 f->fmt.pix.field = field; 2694 f->fmt.pix.field = field;
2190 if (f->fmt.pix.width < 48) 2695 pix_format_set_size(&f->fmt.pix, fmt, width, height);
2191 f->fmt.pix.width = 48;
2192 if (f->fmt.pix.height < 32)
2193 f->fmt.pix.height = 32;
2194 if (f->fmt.pix.width > maxw)
2195 f->fmt.pix.width = maxw;
2196 if (f->fmt.pix.height > maxh)
2197 f->fmt.pix.height = maxh;
2198 pix_format_set_size (&f->fmt.pix, fmt,
2199 f->fmt.pix.width & ~3,
2200 f->fmt.pix.height);
2201 2696
2202 return 0; 2697 return 0;
2203 } 2698 }
2204 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 2699 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
2205 return verify_window(&bttv_tvnorms[btv->tvnorm], 2700 return verify_window(fh, &f->fmt.win,
2206 &f->fmt.win, 1); 2701 /* adjust_size */ 1,
2702 /* adjust_crop */ 0);
2207 case V4L2_BUF_TYPE_VBI_CAPTURE: 2703 case V4L2_BUF_TYPE_VBI_CAPTURE:
2208 bttv_vbi_try_fmt(fh,f); 2704 return bttv_vbi_try_fmt(fh, &f->fmt.vbi);
2209 return 0;
2210 default: 2705 default:
2211 return -EINVAL; 2706 return -EINVAL;
2212 } 2707 }
@@ -2225,7 +2720,7 @@ static int bttv_s_fmt(struct bttv_fh *fh, struct bttv *btv,
2225 retval = bttv_switch_type(fh,f->type); 2720 retval = bttv_switch_type(fh,f->type);
2226 if (0 != retval) 2721 if (0 != retval)
2227 return retval; 2722 return retval;
2228 retval = bttv_try_fmt(fh,btv,f); 2723 retval = bttv_try_fmt(fh,btv,f, /* adjust_crop */ 1);
2229 if (0 != retval) 2724 if (0 != retval)
2230 return retval; 2725 return retval;
2231 fmt = format_by_fourcc(f->fmt.pix.pixelformat); 2726 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
@@ -2254,12 +2749,7 @@ static int bttv_s_fmt(struct bttv_fh *fh, struct bttv *btv,
2254 retval = bttv_switch_type(fh,f->type); 2749 retval = bttv_switch_type(fh,f->type);
2255 if (0 != retval) 2750 if (0 != retval)
2256 return retval; 2751 return retval;
2257 if (locked_btres(fh->btv, RESOURCE_VBI)) 2752 return bttv_vbi_set_fmt(fh, &f->fmt.vbi);
2258 return -EBUSY;
2259 bttv_vbi_try_fmt(fh,f);
2260 bttv_vbi_setlines(fh,btv,f->fmt.vbi.count[0]);
2261 bttv_vbi_get_fmt(fh,f);
2262 return 0;
2263 default: 2753 default:
2264 return -EINVAL; 2754 return -EINVAL;
2265 } 2755 }
@@ -2517,6 +3007,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2517 if (*on) { 3007 if (*on) {
2518 fh->ov.tvnorm = btv->tvnorm; 3008 fh->ov.tvnorm = btv->tvnorm;
2519 new = videobuf_alloc(sizeof(*new)); 3009 new = videobuf_alloc(sizeof(*new));
3010 new->crop = btv->crop[!!fh->do_crop].rect;
2520 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); 3011 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
2521 } else { 3012 } else {
2522 new = NULL; 3013 new = NULL;
@@ -2551,10 +3042,16 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2551 struct video_mmap *vm = arg; 3042 struct video_mmap *vm = arg;
2552 struct bttv_buffer *buf; 3043 struct bttv_buffer *buf;
2553 enum v4l2_field field; 3044 enum v4l2_field field;
3045 __s32 height2;
3046 int res;
2554 3047
2555 if (vm->frame >= VIDEO_MAX_FRAME) 3048 if (vm->frame >= VIDEO_MAX_FRAME)
2556 return -EINVAL; 3049 return -EINVAL;
2557 3050
3051 res = bttv_resource(fh);
3052 if (!check_alloc_btres(btv, fh, res))
3053 return -EBUSY;
3054
2558 mutex_lock(&fh->cap.lock); 3055 mutex_lock(&fh->cap.lock);
2559 retval = -EINVAL; 3056 retval = -EINVAL;
2560 buf = (struct bttv_buffer *)fh->cap.bufs[vm->frame]; 3057 buf = (struct bttv_buffer *)fh->cap.bufs[vm->frame];
@@ -2566,7 +3063,8 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2566 buf->vb.state == STATE_ACTIVE) 3063 buf->vb.state == STATE_ACTIVE)
2567 goto fh_unlock_and_return; 3064 goto fh_unlock_and_return;
2568 3065
2569 field = (vm->height > bttv_tvnorms[btv->tvnorm].sheight/2) 3066 height2 = btv->crop[!!fh->do_crop].rect.height >> 1;
3067 field = (vm->height > height2)
2570 ? V4L2_FIELD_INTERLACED 3068 ? V4L2_FIELD_INTERLACED
2571 : V4L2_FIELD_BOTTOM; 3069 : V4L2_FIELD_BOTTOM;
2572 retval = bttv_prepare_buffer(&fh->cap,btv,buf, 3070 retval = bttv_prepare_buffer(&fh->cap,btv,buf,
@@ -2613,54 +3111,17 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2613 } 3111 }
2614 3112
2615 case VIDIOCGVBIFMT: 3113 case VIDIOCGVBIFMT:
2616 {
2617 struct vbi_format *fmt = (void *) arg;
2618 struct v4l2_format fmt2;
2619
2620 if (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE) { 3114 if (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE) {
2621 retval = bttv_switch_type(fh,V4L2_BUF_TYPE_VBI_CAPTURE); 3115 retval = bttv_switch_type(fh,V4L2_BUF_TYPE_VBI_CAPTURE);
2622 if (0 != retval) 3116 if (0 != retval)
2623 return retval; 3117 return retval;
2624 } 3118 }
2625 bttv_vbi_get_fmt(fh, &fmt2);
2626
2627 memset(fmt,0,sizeof(*fmt));
2628 fmt->sampling_rate = fmt2.fmt.vbi.sampling_rate;
2629 fmt->samples_per_line = fmt2.fmt.vbi.samples_per_line;
2630 fmt->sample_format = VIDEO_PALETTE_RAW;
2631 fmt->start[0] = fmt2.fmt.vbi.start[0];
2632 fmt->count[0] = fmt2.fmt.vbi.count[0];
2633 fmt->start[1] = fmt2.fmt.vbi.start[1];
2634 fmt->count[1] = fmt2.fmt.vbi.count[1];
2635 if (fmt2.fmt.vbi.flags & V4L2_VBI_UNSYNC)
2636 fmt->flags |= VBI_UNSYNC;
2637 if (fmt2.fmt.vbi.flags & V4L2_VBI_INTERLACED)
2638 fmt->flags |= VBI_INTERLACED;
2639 return 0;
2640 }
2641 case VIDIOCSVBIFMT:
2642 {
2643 struct vbi_format *fmt = (void *) arg;
2644 struct v4l2_format fmt2;
2645 3119
2646 retval = bttv_switch_type(fh,V4L2_BUF_TYPE_VBI_CAPTURE); 3120 /* fall through */
2647 if (0 != retval)
2648 return retval;
2649 bttv_vbi_get_fmt(fh, &fmt2);
2650
2651 if (fmt->sampling_rate != fmt2.fmt.vbi.sampling_rate ||
2652 fmt->samples_per_line != fmt2.fmt.vbi.samples_per_line ||
2653 fmt->sample_format != VIDEO_PALETTE_RAW ||
2654 fmt->start[0] != fmt2.fmt.vbi.start[0] ||
2655 fmt->start[1] != fmt2.fmt.vbi.start[1] ||
2656 fmt->count[0] != fmt->count[1] ||
2657 fmt->count[0] < 1 ||
2658 fmt->count[0] > 32 /* VBI_MAXLINES */)
2659 return -EINVAL;
2660 3121
2661 bttv_vbi_setlines(fh,btv,fmt->count[0]); 3122 case VIDIOCSVBIFMT:
2662 return 0; 3123 return v4l_compat_translate_ioctl(inode, file, cmd,
2663 } 3124 arg, bttv_do_ioctl);
2664 3125
2665 case BTTV_VERSION: 3126 case BTTV_VERSION:
2666 case VIDIOCGFREQ: 3127 case VIDIOCGFREQ:
@@ -2753,7 +3214,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2753 case VIDIOC_TRY_FMT: 3214 case VIDIOC_TRY_FMT:
2754 { 3215 {
2755 struct v4l2_format *f = arg; 3216 struct v4l2_format *f = arg;
2756 return bttv_try_fmt(fh,btv,f); 3217 return bttv_try_fmt(fh,btv,f, /* adjust_crop */ 0);
2757 } 3218 }
2758 case VIDIOC_G_FMT: 3219 case VIDIOC_G_FMT:
2759 { 3220 {
@@ -2792,16 +3253,23 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2792 if (0 == (fmt->flags & FORMAT_FLAGS_PACKED)) 3253 if (0 == (fmt->flags & FORMAT_FLAGS_PACKED))
2793 return -EINVAL; 3254 return -EINVAL;
2794 3255
2795 mutex_lock(&fh->cap.lock);
2796 retval = -EINVAL; 3256 retval = -EINVAL;
2797 if (fb->flags & V4L2_FBUF_FLAG_OVERLAY) { 3257 if (fb->flags & V4L2_FBUF_FLAG_OVERLAY) {
2798 if (fb->fmt.width > bttv_tvnorms[btv->tvnorm].swidth) 3258 __s32 width = fb->fmt.width;
2799 goto fh_unlock_and_return; 3259 __s32 height = fb->fmt.height;
2800 if (fb->fmt.height > bttv_tvnorms[btv->tvnorm].sheight) 3260
2801 goto fh_unlock_and_return; 3261 retval = limit_scaled_size(fh, &width, &height,
3262 V4L2_FIELD_INTERLACED,
3263 /* width_mask */ ~3,
3264 /* width_bias */ 2,
3265 /* adjust_size */ 0,
3266 /* adjust_crop */ 0);
3267 if (0 != retval)
3268 return retval;
2802 } 3269 }
2803 3270
2804 /* ok, accept it */ 3271 /* ok, accept it */
3272 mutex_lock(&fh->cap.lock);
2805 btv->fbuf.base = fb->base; 3273 btv->fbuf.base = fb->base;
2806 btv->fbuf.fmt.width = fb->fmt.width; 3274 btv->fbuf.fmt.width = fb->fmt.width;
2807 btv->fbuf.fmt.height = fb->fmt.height; 3275 btv->fbuf.fmt.height = fb->fmt.height;
@@ -2828,6 +3296,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2828 struct bttv_buffer *new; 3296 struct bttv_buffer *new;
2829 3297
2830 new = videobuf_alloc(sizeof(*new)); 3298 new = videobuf_alloc(sizeof(*new));
3299 new->crop = btv->crop[!!fh->do_crop].rect;
2831 bttv_overlay_risc(btv,&fh->ov,fh->ovfmt,new); 3300 bttv_overlay_risc(btv,&fh->ov,fh->ovfmt,new);
2832 retval = bttv_switch_overlay(btv,fh,new); 3301 retval = bttv_switch_overlay(btv,fh,new);
2833 } 3302 }
@@ -2843,7 +3312,13 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2843 return videobuf_querybuf(bttv_queue(fh),arg); 3312 return videobuf_querybuf(bttv_queue(fh),arg);
2844 3313
2845 case VIDIOC_QBUF: 3314 case VIDIOC_QBUF:
3315 {
3316 int res = bttv_resource(fh);
3317
3318 if (!check_alloc_btres(btv, fh, res))
3319 return -EBUSY;
2846 return videobuf_qbuf(bttv_queue(fh),arg); 3320 return videobuf_qbuf(bttv_queue(fh),arg);
3321 }
2847 3322
2848 case VIDIOC_DQBUF: 3323 case VIDIOC_DQBUF:
2849 return videobuf_dqbuf(bttv_queue(fh),arg, 3324 return videobuf_dqbuf(bttv_queue(fh),arg,
@@ -2942,6 +3417,122 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2942 return v4l2_prio_change(&btv->prio, &fh->prio, *prio); 3417 return v4l2_prio_change(&btv->prio, &fh->prio, *prio);
2943 } 3418 }
2944 3419
3420 case VIDIOC_CROPCAP:
3421 {
3422 struct v4l2_cropcap *cap = arg;
3423 enum v4l2_buf_type type;
3424
3425 type = cap->type;
3426
3427 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
3428 type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
3429 return -EINVAL;
3430
3431 *cap = bttv_tvnorms[btv->tvnorm].cropcap;
3432 cap->type = type;
3433
3434 return 0;
3435 }
3436 case VIDIOC_G_CROP:
3437 {
3438 struct v4l2_crop * crop = arg;
3439
3440 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
3441 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
3442 return -EINVAL;
3443
3444 /* No fh->do_crop = 1; because btv->crop[1] may be
3445 inconsistent with fh->width or fh->height and apps
3446 do not expect a change here. */
3447
3448 crop->c = btv->crop[!!fh->do_crop].rect;
3449
3450 return 0;
3451 }
3452 case VIDIOC_S_CROP:
3453 {
3454 struct v4l2_crop *crop = arg;
3455 const struct v4l2_rect *b;
3456 struct bttv_crop c;
3457 __s32 b_left;
3458 __s32 b_top;
3459 __s32 b_right;
3460 __s32 b_bottom;
3461
3462 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
3463 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
3464 return -EINVAL;
3465
3466 retval = v4l2_prio_check(&btv->prio,&fh->prio);
3467 if (0 != retval)
3468 return retval;
3469
3470 /* Make sure tvnorm, vbi_end and the current cropping
3471 parameters remain consistent until we're done. Note
3472 read() may change vbi_end in check_alloc_btres(). */
3473 mutex_lock(&btv->lock);
3474
3475 retval = -EBUSY;
3476
3477 if (locked_btres(fh->btv, VIDEO_RESOURCES))
3478 goto btv_unlock_and_return;
3479
3480 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds;
3481
3482 b_left = b->left;
3483 b_right = b_left + b->width;
3484 b_bottom = b->top + b->height;
3485
3486 b_top = max(b->top, btv->vbi_end);
3487 if (b_top + 32 >= b_bottom)
3488 goto btv_unlock_and_return;
3489
3490 /* Min. scaled size 48 x 32. */
3491 c.rect.left = clamp(crop->c.left, b_left, b_right - 48);
3492 c.rect.left = min(c.rect.left, (__s32) MAX_HDELAY);
3493
3494 c.rect.width = clamp(crop->c.width,
3495 48, b_right - c.rect.left);
3496
3497 c.rect.top = clamp(crop->c.top, b_top, b_bottom - 32);
3498 /* Top and height must be a multiple of two. */
3499 c.rect.top = (c.rect.top + 1) & ~1;
3500
3501 c.rect.height = clamp(crop->c.height,
3502 32, b_bottom - c.rect.top);
3503 c.rect.height = (c.rect.height + 1) & ~1;
3504
3505 bttv_crop_calc_limits(&c);
3506
3507 btv->crop[1] = c;
3508
3509 mutex_unlock(&btv->lock);
3510
3511 fh->do_crop = 1;
3512
3513 mutex_lock(&fh->cap.lock);
3514
3515 if (fh->width < c.min_scaled_width) {
3516 fh->width = c.min_scaled_width;
3517 btv->init.width = c.min_scaled_width;
3518 } else if (fh->width > c.max_scaled_width) {
3519 fh->width = c.max_scaled_width;
3520 btv->init.width = c.max_scaled_width;
3521 }
3522
3523 if (fh->height < c.min_scaled_height) {
3524 fh->height = c.min_scaled_height;
3525 btv->init.height = c.min_scaled_height;
3526 } else if (fh->height > c.max_scaled_height) {
3527 fh->height = c.max_scaled_height;
3528 btv->init.height = c.max_scaled_height;
3529 }
3530
3531 mutex_unlock(&fh->cap.lock);
3532
3533 return 0;
3534 }
3535
2945 case VIDIOC_ENUMSTD: 3536 case VIDIOC_ENUMSTD:
2946 case VIDIOC_G_STD: 3537 case VIDIOC_G_STD:
2947 case VIDIOC_S_STD: 3538 case VIDIOC_S_STD:
@@ -2963,6 +3554,10 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2963 fh_unlock_and_return: 3554 fh_unlock_and_return:
2964 mutex_unlock(&fh->cap.lock); 3555 mutex_unlock(&fh->cap.lock);
2965 return retval; 3556 return retval;
3557
3558 btv_unlock_and_return:
3559 mutex_unlock(&btv->lock);
3560 return retval;
2966} 3561}
2967 3562
2968static int bttv_ioctl(struct inode *inode, struct file *file, 3563static int bttv_ioctl(struct inode *inode, struct file *file,
@@ -2972,8 +3567,26 @@ static int bttv_ioctl(struct inode *inode, struct file *file,
2972 3567
2973 switch (cmd) { 3568 switch (cmd) {
2974 case BTTV_VBISIZE: 3569 case BTTV_VBISIZE:
3570 {
3571 const struct bttv_tvnorm *tvnorm;
3572
3573 tvnorm = fh->vbi_fmt.tvnorm;
3574
3575 if (fh->vbi_fmt.fmt.start[0] != tvnorm->vbistart[0] ||
3576 fh->vbi_fmt.fmt.start[1] != tvnorm->vbistart[1] ||
3577 fh->vbi_fmt.fmt.count[0] != fh->vbi_fmt.fmt.count[1]) {
3578 /* BTTV_VBISIZE cannot express these parameters,
3579 however open() resets the paramters to defaults
3580 and apps shouldn't call BTTV_VBISIZE after
3581 VIDIOC_S_FMT. */
3582 return -EINVAL;
3583 }
3584
2975 bttv_switch_type(fh,V4L2_BUF_TYPE_VBI_CAPTURE); 3585 bttv_switch_type(fh,V4L2_BUF_TYPE_VBI_CAPTURE);
2976 return fh->lines * 2 * 2048; 3586 return (fh->vbi_fmt.fmt.count[0] * 2
3587 * fh->vbi_fmt.fmt.samples_per_line);
3588 }
3589
2977 default: 3590 default:
2978 return video_usercopy(inode, file, cmd, arg, bttv_do_ioctl); 3591 return video_usercopy(inode, file, cmd, arg, bttv_do_ioctl);
2979 } 3592 }
@@ -2992,10 +3605,14 @@ static ssize_t bttv_read(struct file *file, char __user *data,
2992 3605
2993 switch (fh->type) { 3606 switch (fh->type) {
2994 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 3607 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
2995 if (locked_btres(fh->btv,RESOURCE_VIDEO)) 3608 if (!check_alloc_btres(fh->btv, fh, RESOURCE_VIDEO_READ)) {
3609 /* VIDEO_READ in use by another fh,
3610 or VIDEO_STREAM by any fh. */
2996 return -EBUSY; 3611 return -EBUSY;
3612 }
2997 retval = videobuf_read_one(&fh->cap, data, count, ppos, 3613 retval = videobuf_read_one(&fh->cap, data, count, ppos,
2998 file->f_flags & O_NONBLOCK); 3614 file->f_flags & O_NONBLOCK);
3615 free_btres(fh->btv, fh, RESOURCE_VIDEO_READ);
2999 break; 3616 break;
3000 case V4L2_BUF_TYPE_VBI_CAPTURE: 3617 case V4L2_BUF_TYPE_VBI_CAPTURE:
3001 if (!check_alloc_btres(fh->btv,fh,RESOURCE_VBI)) 3618 if (!check_alloc_btres(fh->btv,fh,RESOURCE_VBI))
@@ -3021,7 +3638,7 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait)
3021 return videobuf_poll_stream(file, &fh->vbi, wait); 3638 return videobuf_poll_stream(file, &fh->vbi, wait);
3022 } 3639 }
3023 3640
3024 if (check_btres(fh,RESOURCE_VIDEO)) { 3641 if (check_btres(fh,RESOURCE_VIDEO_STREAM)) {
3025 /* streaming capture */ 3642 /* streaming capture */
3026 if (list_empty(&fh->cap.stream)) 3643 if (list_empty(&fh->cap.stream))
3027 return POLLERR; 3644 return POLLERR;
@@ -3031,7 +3648,7 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait)
3031 mutex_lock(&fh->cap.lock); 3648 mutex_lock(&fh->cap.lock);
3032 if (NULL == fh->cap.read_buf) { 3649 if (NULL == fh->cap.read_buf) {
3033 /* need to capture a new frame */ 3650 /* need to capture a new frame */
3034 if (locked_btres(fh->btv,RESOURCE_VIDEO)) { 3651 if (locked_btres(fh->btv,RESOURCE_VIDEO_STREAM)) {
3035 mutex_unlock(&fh->cap.lock); 3652 mutex_unlock(&fh->cap.lock);
3036 return POLLERR; 3653 return POLLERR;
3037 } 3654 }
@@ -3117,8 +3734,23 @@ static int bttv_open(struct inode *inode, struct file *file)
3117 i2c_vidiocschan(btv); 3734 i2c_vidiocschan(btv);
3118 3735
3119 btv->users++; 3736 btv->users++;
3120 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) 3737
3121 bttv_vbi_setlines(fh,btv,16); 3738 /* The V4L2 spec requires one global set of cropping parameters
3739 which only change on request. These are stored in btv->crop[1].
3740 However for compatibility with V4L apps and cropping unaware
3741 V4L2 apps we now reset the cropping parameters as seen through
3742 this fh, which is to say VIDIOC_G_CROP and scaling limit checks
3743 will use btv->crop[0], the default cropping parameters for the
3744 current video standard, and VIDIOC_S_FMT will not implicitely
3745 change the cropping parameters until VIDIOC_S_CROP has been
3746 called. */
3747 fh->do_crop = !reset_crop; /* module parameter */
3748
3749 /* Likewise there should be one global set of VBI capture
3750 parameters, but for compatibility with V4L apps and earlier
3751 driver versions each fh has its own parameters. */
3752 bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm);
3753
3122 bttv_field_count(btv); 3754 bttv_field_count(btv);
3123 return 0; 3755 return 0;
3124} 3756}
@@ -3133,14 +3765,17 @@ static int bttv_release(struct inode *inode, struct file *file)
3133 bttv_switch_overlay(btv,fh,NULL); 3765 bttv_switch_overlay(btv,fh,NULL);
3134 3766
3135 /* stop video capture */ 3767 /* stop video capture */
3136 if (check_btres(fh, RESOURCE_VIDEO)) { 3768 if (check_btres(fh, RESOURCE_VIDEO_STREAM)) {
3137 videobuf_streamoff(&fh->cap); 3769 videobuf_streamoff(&fh->cap);
3138 free_btres(btv,fh,RESOURCE_VIDEO); 3770 free_btres(btv,fh,RESOURCE_VIDEO_STREAM);
3139 } 3771 }
3140 if (fh->cap.read_buf) { 3772 if (fh->cap.read_buf) {
3141 buffer_release(&fh->cap,fh->cap.read_buf); 3773 buffer_release(&fh->cap,fh->cap.read_buf);
3142 kfree(fh->cap.read_buf); 3774 kfree(fh->cap.read_buf);
3143 } 3775 }
3776 if (check_btres(fh, RESOURCE_VIDEO_READ)) {
3777 free_btres(btv, fh, RESOURCE_VIDEO_READ);
3778 }
3144 3779
3145 /* stop vbi capture */ 3780 /* stop vbi capture */
3146 if (check_btres(fh, RESOURCE_VBI)) { 3781 if (check_btres(fh, RESOURCE_VBI)) {
@@ -3997,7 +4632,6 @@ static int __devinit bttv_probe(struct pci_dev *dev,
3997 4632
3998 /* initialize structs / fill in defaults */ 4633 /* initialize structs / fill in defaults */
3999 mutex_init(&btv->lock); 4634 mutex_init(&btv->lock);
4000 mutex_init(&btv->reslock);
4001 spin_lock_init(&btv->s_lock); 4635 spin_lock_init(&btv->s_lock);
4002 spin_lock_init(&btv->gpio_lock); 4636 spin_lock_init(&btv->gpio_lock);
4003 init_waitqueue_head(&btv->gpioq); 4637 init_waitqueue_head(&btv->gpioq);
@@ -4095,7 +4729,6 @@ static int __devinit bttv_probe(struct pci_dev *dev,
4095 btv->init.fmt = format_by_palette(VIDEO_PALETTE_RGB24); 4729 btv->init.fmt = format_by_palette(VIDEO_PALETTE_RGB24);
4096 btv->init.width = 320; 4730 btv->init.width = 320;
4097 btv->init.height = 240; 4731 btv->init.height = 240;
4098 btv->init.lines = 16;
4099 btv->input = 0; 4732 btv->input = 0;
4100 4733
4101 /* initialize hardware */ 4734 /* initialize hardware */
@@ -4130,6 +4763,10 @@ static int __devinit bttv_probe(struct pci_dev *dev,
4130 bt848_sat(btv,32768); 4763 bt848_sat(btv,32768);
4131 audio_mute(btv, 1); 4764 audio_mute(btv, 1);
4132 set_input(btv,0); 4765 set_input(btv,0);
4766 bttv_crop_reset(&btv->crop[0], btv->tvnorm);
4767 btv->crop[1] = btv->crop[0]; /* current = default */
4768 disclaim_vbi_lines(btv);
4769 disclaim_video_lines(btv);
4133 } 4770 }
4134 4771
4135 /* add subdevices */ 4772 /* add subdevices */
diff --git a/drivers/media/video/bt8xx/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c
index cbc012f71f..6f74c8042b 100644
--- a/drivers/media/video/bt8xx/bttv-input.c
+++ b/drivers/media/video/bt8xx/bttv-input.c
@@ -36,13 +36,18 @@ module_param(repeat_delay, int, 0644);
36static int repeat_period = 33; 36static int repeat_period = 33;
37module_param(repeat_period, int, 0644); 37module_param(repeat_period, int, 0644);
38 38
39static int ir_rc5_remote_gap = 885;
40module_param(ir_rc5_remote_gap, int, 0644);
41static int ir_rc5_key_timeout = 200;
42module_param(ir_rc5_key_timeout, int, 0644);
43
39#define DEVNAME "bttv-input" 44#define DEVNAME "bttv-input"
40 45
41/* ---------------------------------------------------------------------- */ 46/* ---------------------------------------------------------------------- */
42 47
43static void ir_handle_key(struct bttv *btv) 48static void ir_handle_key(struct bttv *btv)
44{ 49{
45 struct bttv_ir *ir = btv->remote; 50 struct card_ir *ir = btv->remote;
46 u32 gpio,data; 51 u32 gpio,data;
47 52
48 /* read gpio value */ 53 /* read gpio value */
@@ -72,7 +77,7 @@ static void ir_handle_key(struct bttv *btv)
72 77
73void bttv_input_irq(struct bttv *btv) 78void bttv_input_irq(struct bttv *btv)
74{ 79{
75 struct bttv_ir *ir = btv->remote; 80 struct card_ir *ir = btv->remote;
76 81
77 if (!ir->polling) 82 if (!ir->polling)
78 ir_handle_key(btv); 83 ir_handle_key(btv);
@@ -81,65 +86,21 @@ void bttv_input_irq(struct bttv *btv)
81static void bttv_input_timer(unsigned long data) 86static void bttv_input_timer(unsigned long data)
82{ 87{
83 struct bttv *btv = (struct bttv*)data; 88 struct bttv *btv = (struct bttv*)data;
84 struct bttv_ir *ir = btv->remote; 89 struct card_ir *ir = btv->remote;
85 unsigned long timeout;
86 90
87 ir_handle_key(btv); 91 ir_handle_key(btv);
88 timeout = jiffies + (ir->polling * HZ / 1000); 92 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
89 mod_timer(&ir->timer, timeout);
90} 93}
91 94
92/* ---------------------------------------------------------------*/ 95/* ---------------------------------------------------------------*/
93 96
94static int rc5_remote_gap = 885;
95module_param(rc5_remote_gap, int, 0644);
96static int rc5_key_timeout = 200;
97module_param(rc5_key_timeout, int, 0644);
98
99#define RC5_START(x) (((x)>>12)&3)
100#define RC5_TOGGLE(x) (((x)>>11)&1)
101#define RC5_ADDR(x) (((x)>>6)&31)
102#define RC5_INSTR(x) ((x)&63)
103
104/* decode raw bit pattern to RC5 code */
105static u32 rc5_decode(unsigned int code)
106{
107 unsigned int org_code = code;
108 unsigned int pair;
109 unsigned int rc5 = 0;
110 int i;
111
112 code = (code << 1) | 1;
113 for (i = 0; i < 14; ++i) {
114 pair = code & 0x3;
115 code >>= 2;
116
117 rc5 <<= 1;
118 switch (pair) {
119 case 0:
120 case 2:
121 break;
122 case 1:
123 rc5 |= 1;
124 break;
125 case 3:
126 dprintk(KERN_WARNING "bad code: %x\n", org_code);
127 return 0;
128 }
129 }
130 dprintk(KERN_WARNING "code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
131 "instr=%x\n", rc5, org_code, RC5_START(rc5),
132 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
133 return rc5;
134}
135
136static int bttv_rc5_irq(struct bttv *btv) 97static int bttv_rc5_irq(struct bttv *btv)
137{ 98{
138 struct bttv_ir *ir = btv->remote; 99 struct card_ir *ir = btv->remote;
139 struct timeval tv; 100 struct timeval tv;
140 u32 gpio; 101 u32 gpio;
141 u32 gap; 102 u32 gap;
142 unsigned long current_jiffies, timeout; 103 unsigned long current_jiffies;
143 104
144 /* read gpio port */ 105 /* read gpio port */
145 gpio = bttv_gpio_read(&btv->c); 106 gpio = bttv_gpio_read(&btv->c);
@@ -165,8 +126,8 @@ static int bttv_rc5_irq(struct bttv *btv)
165 /* only if in the code (otherwise spurious IRQ or timer 126 /* only if in the code (otherwise spurious IRQ or timer
166 late) */ 127 late) */
167 if (ir->last_bit < 28) { 128 if (ir->last_bit < 28) {
168 ir->last_bit = (gap - rc5_remote_gap / 2) / 129 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
169 rc5_remote_gap; 130 ir_rc5_remote_gap;
170 ir->code |= 1 << ir->last_bit; 131 ir->code |= 1 << ir->last_bit;
171 } 132 }
172 /* starting new code */ 133 /* starting new code */
@@ -176,8 +137,8 @@ static int bttv_rc5_irq(struct bttv *btv)
176 ir->base_time = tv; 137 ir->base_time = tv;
177 ir->last_bit = 0; 138 ir->last_bit = 0;
178 139
179 timeout = current_jiffies + (500 + 30 * HZ) / 1000; 140 mod_timer(&ir->timer_end,
180 mod_timer(&ir->timer_end, timeout); 141 current_jiffies + msecs_to_jiffies(30));
181 } 142 }
182 143
183 /* toggle GPIO pin 4 to reset the irq */ 144 /* toggle GPIO pin 4 to reset the irq */
@@ -186,96 +147,28 @@ static int bttv_rc5_irq(struct bttv *btv)
186 return 1; 147 return 1;
187} 148}
188 149
189
190static void bttv_rc5_timer_end(unsigned long data)
191{
192 struct bttv_ir *ir = (struct bttv_ir *)data;
193 struct timeval tv;
194 unsigned long current_jiffies, timeout;
195 u32 gap;
196
197 /* get time */
198 current_jiffies = jiffies;
199 do_gettimeofday(&tv);
200
201 /* avoid overflow with gap >1s */
202 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
203 gap = 200000;
204 } else {
205 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
206 tv.tv_usec - ir->base_time.tv_usec;
207 }
208
209 /* Allow some timmer jitter (RC5 is ~24ms anyway so this is ok) */
210 if (gap < 28000) {
211 dprintk(KERN_WARNING "spurious timer_end\n");
212 return;
213 }
214
215 ir->active = 0;
216 if (ir->last_bit < 20) {
217 /* ignore spurious codes (caused by light/other remotes) */
218 dprintk(KERN_WARNING "short code: %x\n", ir->code);
219 } else {
220 u32 rc5 = rc5_decode(ir->code);
221
222 /* two start bits? */
223 if (RC5_START(rc5) != 3) {
224 dprintk(KERN_WARNING "rc5 start bits invalid: %u\n", RC5_START(rc5));
225
226 /* right address? */
227 } else if (RC5_ADDR(rc5) == 0x0) {
228 u32 toggle = RC5_TOGGLE(rc5);
229 u32 instr = RC5_INSTR(rc5);
230
231 /* Good code, decide if repeat/repress */
232 if (toggle != RC5_TOGGLE(ir->last_rc5) ||
233 instr != RC5_INSTR(ir->last_rc5)) {
234 dprintk(KERN_WARNING "instruction %x, toggle %x\n", instr,
235 toggle);
236 ir_input_nokey(ir->dev, &ir->ir);
237 ir_input_keydown(ir->dev, &ir->ir, instr,
238 instr);
239 }
240
241 /* Set/reset key-up timer */
242 timeout = current_jiffies + (500 + rc5_key_timeout
243 * HZ) / 1000;
244 mod_timer(&ir->timer_keyup, timeout);
245
246 /* Save code for repeat test */
247 ir->last_rc5 = rc5;
248 }
249 }
250}
251
252static void bttv_rc5_timer_keyup(unsigned long data)
253{
254 struct bttv_ir *ir = (struct bttv_ir *)data;
255
256 dprintk(KERN_DEBUG "key released\n");
257 ir_input_nokey(ir->dev, &ir->ir);
258}
259
260/* ---------------------------------------------------------------------- */ 150/* ---------------------------------------------------------------------- */
261 151
262static void bttv_ir_start(struct bttv *btv, struct bttv_ir *ir) 152static void bttv_ir_start(struct bttv *btv, struct card_ir *ir)
263{ 153{
264 if (ir->polling) { 154 if (ir->polling) {
265 init_timer(&ir->timer); 155 setup_timer(&ir->timer, bttv_input_timer, (unsigned long)btv);
266 ir->timer.function = bttv_input_timer;
267 ir->timer.data = (unsigned long)btv;
268 ir->timer.expires = jiffies + HZ; 156 ir->timer.expires = jiffies + HZ;
269 add_timer(&ir->timer); 157 add_timer(&ir->timer);
270 } else if (ir->rc5_gpio) { 158 } else if (ir->rc5_gpio) {
271 /* set timer_end for code completion */ 159 /* set timer_end for code completion */
272 init_timer(&ir->timer_end); 160 init_timer(&ir->timer_end);
273 ir->timer_end.function = bttv_rc5_timer_end; 161 ir->timer_end.function = ir_rc5_timer_end;
274 ir->timer_end.data = (unsigned long)ir; 162 ir->timer_end.data = (unsigned long)ir;
275 163
276 init_timer(&ir->timer_keyup); 164 init_timer(&ir->timer_keyup);
277 ir->timer_keyup.function = bttv_rc5_timer_keyup; 165 ir->timer_keyup.function = ir_rc5_timer_keyup;
278 ir->timer_keyup.data = (unsigned long)ir; 166 ir->timer_keyup.data = (unsigned long)ir;
167 ir->shift_by = 1;
168 ir->start = 3;
169 ir->addr = 0x0;
170 ir->rc5_key_timeout = ir_rc5_key_timeout;
171 ir->rc5_remote_gap = ir_rc5_remote_gap;
279 } 172 }
280} 173}
281 174
@@ -299,7 +192,7 @@ static void bttv_ir_stop(struct bttv *btv)
299 192
300int bttv_input_init(struct bttv *btv) 193int bttv_input_init(struct bttv *btv)
301{ 194{
302 struct bttv_ir *ir; 195 struct card_ir *ir;
303 IR_KEYTAB_TYPE *ir_codes = NULL; 196 IR_KEYTAB_TYPE *ir_codes = NULL;
304 struct input_dev *input_dev; 197 struct input_dev *input_dev;
305 int ir_type = IR_TYPE_OTHER; 198 int ir_type = IR_TYPE_OTHER;
diff --git a/drivers/media/video/bt8xx/bttv-risc.c b/drivers/media/video/bt8xx/bttv-risc.c
index afcfe71e37..e7104d9cb4 100644
--- a/drivers/media/video/bt8xx/bttv-risc.c
+++ b/drivers/media/video/bt8xx/bttv-risc.c
@@ -43,7 +43,8 @@ int
43bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc, 43bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,
44 struct scatterlist *sglist, 44 struct scatterlist *sglist,
45 unsigned int offset, unsigned int bpl, 45 unsigned int offset, unsigned int bpl,
46 unsigned int padding, unsigned int lines) 46 unsigned int padding, unsigned int skip_lines,
47 unsigned int store_lines)
47{ 48{
48 u32 instructions,line,todo; 49 u32 instructions,line,todo;
49 struct scatterlist *sg; 50 struct scatterlist *sg;
@@ -54,9 +55,11 @@ bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,
54 one write per scan line + sync + jump (all 2 dwords). padding 55 one write per scan line + sync + jump (all 2 dwords). padding
55 can cause next bpl to start close to a page border. First DMA 56 can cause next bpl to start close to a page border. First DMA
56 region may be smaller than PAGE_SIZE */ 57 region may be smaller than PAGE_SIZE */
57 instructions = 1 + ((bpl + padding) * lines) / PAGE_SIZE + lines; 58 instructions = skip_lines * 4;
58 instructions += 2; 59 instructions += (1 + ((bpl + padding) * store_lines)
59 if ((rc = btcx_riscmem_alloc(btv->c.pci,risc,instructions*8)) < 0) 60 / PAGE_SIZE + store_lines) * 8;
61 instructions += 2 * 8;
62 if ((rc = btcx_riscmem_alloc(btv->c.pci,risc,instructions)) < 0)
60 return rc; 63 return rc;
61 64
62 /* sync instruction */ 65 /* sync instruction */
@@ -64,11 +67,16 @@ bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,
64 *(rp++) = cpu_to_le32(BT848_RISC_SYNC|BT848_FIFO_STATUS_FM1); 67 *(rp++) = cpu_to_le32(BT848_RISC_SYNC|BT848_FIFO_STATUS_FM1);
65 *(rp++) = cpu_to_le32(0); 68 *(rp++) = cpu_to_le32(0);
66 69
70 while (skip_lines-- > 0) {
71 *(rp++) = cpu_to_le32(BT848_RISC_SKIP | BT848_RISC_SOL |
72 BT848_RISC_EOL | bpl);
73 }
74
67 /* scan lines */ 75 /* scan lines */
68 sg = sglist; 76 sg = sglist;
69 for (line = 0; line < lines; line++) { 77 for (line = 0; line < store_lines; line++) {
70 if ((btv->opt_vcr_hack) && 78 if ((btv->opt_vcr_hack) &&
71 (line >= (lines - VCR_HACK_LINES))) 79 (line >= (store_lines - VCR_HACK_LINES)))
72 continue; 80 continue;
73 while (offset && offset >= sg_dma_len(sg)) { 81 while (offset && offset >= sg_dma_len(sg)) {
74 offset -= sg_dma_len(sg); 82 offset -= sg_dma_len(sg);
@@ -130,7 +138,8 @@ bttv_risc_planar(struct bttv *btv, struct btcx_riscmem *risc,
130 /* estimate risc mem: worst case is one write per page border + 138 /* estimate risc mem: worst case is one write per page border +
131 one write per scan line (5 dwords) 139 one write per scan line (5 dwords)
132 plus sync + jump (2 dwords) */ 140 plus sync + jump (2 dwords) */
133 instructions = (ybpl * ylines * 2) / PAGE_SIZE + ylines; 141 instructions = ((3 + (ybpl + ypadding) * ylines * 2)
142 / PAGE_SIZE) + ylines;
134 instructions += 2; 143 instructions += 2;
135 if ((rc = btcx_riscmem_alloc(btv->c.pci,risc,instructions*4*5)) < 0) 144 if ((rc = btcx_riscmem_alloc(btv->c.pci,risc,instructions*4*5)) < 0)
136 return rc; 145 return rc;
@@ -317,10 +326,10 @@ bttv_risc_overlay(struct bttv *btv, struct btcx_riscmem *risc,
317/* ---------------------------------------------------------- */ 326/* ---------------------------------------------------------- */
318 327
319static void 328static void
320bttv_calc_geo(struct bttv *btv, struct bttv_geometry *geo, 329bttv_calc_geo_old(struct bttv *btv, struct bttv_geometry *geo,
321 int width, int height, int interleaved, int norm) 330 int width, int height, int interleaved,
331 const struct bttv_tvnorm *tvnorm)
322{ 332{
323 const struct bttv_tvnorm *tvnorm = &bttv_tvnorms[norm];
324 u32 xsf, sr; 333 u32 xsf, sr;
325 int vdelay; 334 int vdelay;
326 335
@@ -361,6 +370,62 @@ bttv_calc_geo(struct bttv *btv, struct bttv_geometry *geo,
361} 370}
362 371
363static void 372static void
373bttv_calc_geo (struct bttv * btv,
374 struct bttv_geometry * geo,
375 unsigned int width,
376 unsigned int height,
377 int both_fields,
378 const struct bttv_tvnorm * tvnorm,
379 const struct v4l2_rect * crop)
380{
381 unsigned int c_width;
382 unsigned int c_height;
383 u32 sr;
384
385 if ((crop->left == tvnorm->cropcap.defrect.left
386 && crop->top == tvnorm->cropcap.defrect.top
387 && crop->width == tvnorm->cropcap.defrect.width
388 && crop->height == tvnorm->cropcap.defrect.height
389 && width <= tvnorm->swidth /* see PAL-Nc et al */)
390 || bttv_tvcards[btv->c.type].muxsel[btv->input] < 0) {
391 bttv_calc_geo_old(btv, geo, width, height,
392 both_fields, tvnorm);
393 return;
394 }
395
396 /* For bug compatibility the image size checks permit scale
397 factors > 16. See bttv_crop_calc_limits(). */
398 c_width = min((unsigned int) crop->width, width * 16);
399 c_height = min((unsigned int) crop->height, height * 16);
400
401 geo->width = width;
402 geo->hscale = (c_width * 4096U + (width >> 1)) / width - 4096;
403 /* Even to store Cb first, odd for Cr. */
404 geo->hdelay = ((crop->left * width + c_width) / c_width) & ~1;
405
406 geo->sheight = c_height;
407 geo->vdelay = crop->top - tvnorm->cropcap.bounds.top + MIN_VDELAY;
408 sr = c_height >> !both_fields;
409 sr = (sr * 512U + (height >> 1)) / height - 512;
410 geo->vscale = (0x10000UL - sr) & 0x1fff;
411 geo->vscale |= both_fields ? (BT848_VSCALE_INT << 8) : 0;
412 geo->vtotal = tvnorm->vtotal;
413
414 geo->crop = (((geo->width >> 8) & 0x03) |
415 ((geo->hdelay >> 6) & 0x0c) |
416 ((geo->sheight >> 4) & 0x30) |
417 ((geo->vdelay >> 2) & 0xc0));
418
419 if (btv->opt_combfilter) {
420 geo->vtc = (width < 193) ? 2 : ((width < 385) ? 1 : 0);
421 geo->comb = (width < 769) ? 1 : 0;
422 } else {
423 geo->vtc = 0;
424 geo->comb = 0;
425 }
426}
427
428static void
364bttv_apply_geo(struct bttv *btv, struct bttv_geometry *geo, int odd) 429bttv_apply_geo(struct bttv *btv, struct bttv_geometry *geo, int odd)
365{ 430{
366 int off = odd ? 0x80 : 0x00; 431 int off = odd ? 0x80 : 0x00;
@@ -522,16 +587,51 @@ int
522bttv_buffer_activate_vbi(struct bttv *btv, 587bttv_buffer_activate_vbi(struct bttv *btv,
523 struct bttv_buffer *vbi) 588 struct bttv_buffer *vbi)
524{ 589{
525 /* vbi capture */ 590 struct btcx_riscmem *top;
591 struct btcx_riscmem *bottom;
592 int top_irq_flags;
593 int bottom_irq_flags;
594
595 top = NULL;
596 bottom = NULL;
597 top_irq_flags = 0;
598 bottom_irq_flags = 0;
599
526 if (vbi) { 600 if (vbi) {
601 unsigned int crop, vdelay;
602
527 vbi->vb.state = STATE_ACTIVE; 603 vbi->vb.state = STATE_ACTIVE;
528 list_del(&vbi->vb.queue); 604 list_del(&vbi->vb.queue);
529 bttv_risc_hook(btv, RISC_SLOT_O_VBI, &vbi->top, 0); 605
530 bttv_risc_hook(btv, RISC_SLOT_E_VBI, &vbi->bottom, 4); 606 /* VDELAY is start of video, end of VBI capturing. */
531 } else { 607 crop = btread(BT848_E_CROP);
532 bttv_risc_hook(btv, RISC_SLOT_O_VBI, NULL, 0); 608 vdelay = btread(BT848_E_VDELAY_LO) + ((crop & 0xc0) << 2);
533 bttv_risc_hook(btv, RISC_SLOT_E_VBI, NULL, 0); 609
610 if (vbi->geo.vdelay > vdelay) {
611 vdelay = vbi->geo.vdelay & 0xfe;
612 crop = (crop & 0x3f) | ((vbi->geo.vdelay >> 2) & 0xc0);
613
614 btwrite(vdelay, BT848_E_VDELAY_LO);
615 btwrite(crop, BT848_E_CROP);
616 btwrite(vdelay, BT848_O_VDELAY_LO);
617 btwrite(crop, BT848_O_CROP);
618 }
619
620 if (vbi->vbi_count[0] > 0) {
621 top = &vbi->top;
622 top_irq_flags = 4;
623 }
624
625 if (vbi->vbi_count[1] > 0) {
626 top_irq_flags = 0;
627 bottom = &vbi->bottom;
628 bottom_irq_flags = 4;
629 }
534 } 630 }
631
632 bttv_risc_hook(btv, RISC_SLOT_O_VBI, top, top_irq_flags);
633 bttv_risc_hook(btv, RISC_SLOT_E_VBI, bottom, bottom_irq_flags);
634
535 return 0; 635 return 0;
536} 636}
537 637
@@ -611,28 +711,31 @@ bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf)
611 int bpf = bpl * (buf->vb.height >> 1); 711 int bpf = bpl * (buf->vb.height >> 1);
612 712
613 bttv_calc_geo(btv,&buf->geo,buf->vb.width,buf->vb.height, 713 bttv_calc_geo(btv,&buf->geo,buf->vb.width,buf->vb.height,
614 V4L2_FIELD_HAS_BOTH(buf->vb.field),buf->tvnorm); 714 V4L2_FIELD_HAS_BOTH(buf->vb.field),
715 tvnorm,&buf->crop);
615 716
616 switch (buf->vb.field) { 717 switch (buf->vb.field) {
617 case V4L2_FIELD_TOP: 718 case V4L2_FIELD_TOP:
618 bttv_risc_packed(btv,&buf->top,buf->vb.dma.sglist, 719 bttv_risc_packed(btv,&buf->top,buf->vb.dma.sglist,
619 0,bpl,0,buf->vb.height); 720 /* offset */ 0,bpl,
721 /* padding */ 0,/* skip_lines */ 0,
722 buf->vb.height);
620 break; 723 break;
621 case V4L2_FIELD_BOTTOM: 724 case V4L2_FIELD_BOTTOM:
622 bttv_risc_packed(btv,&buf->bottom,buf->vb.dma.sglist, 725 bttv_risc_packed(btv,&buf->bottom,buf->vb.dma.sglist,
623 0,bpl,0,buf->vb.height); 726 0,bpl,0,0,buf->vb.height);
624 break; 727 break;
625 case V4L2_FIELD_INTERLACED: 728 case V4L2_FIELD_INTERLACED:
626 bttv_risc_packed(btv,&buf->top,buf->vb.dma.sglist, 729 bttv_risc_packed(btv,&buf->top,buf->vb.dma.sglist,
627 0,bpl,bpl,buf->vb.height >> 1); 730 0,bpl,bpl,0,buf->vb.height >> 1);
628 bttv_risc_packed(btv,&buf->bottom,buf->vb.dma.sglist, 731 bttv_risc_packed(btv,&buf->bottom,buf->vb.dma.sglist,
629 bpl,bpl,bpl,buf->vb.height >> 1); 732 bpl,bpl,bpl,0,buf->vb.height >> 1);
630 break; 733 break;
631 case V4L2_FIELD_SEQ_TB: 734 case V4L2_FIELD_SEQ_TB:
632 bttv_risc_packed(btv,&buf->top,buf->vb.dma.sglist, 735 bttv_risc_packed(btv,&buf->top,buf->vb.dma.sglist,
633 0,bpl,0,buf->vb.height >> 1); 736 0,bpl,0,0,buf->vb.height >> 1);
634 bttv_risc_packed(btv,&buf->bottom,buf->vb.dma.sglist, 737 bttv_risc_packed(btv,&buf->bottom,buf->vb.dma.sglist,
635 bpf,bpl,0,buf->vb.height >> 1); 738 bpf,bpl,0,0,buf->vb.height >> 1);
636 break; 739 break;
637 default: 740 default:
638 BUG(); 741 BUG();
@@ -662,7 +765,8 @@ bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf)
662 switch (buf->vb.field) { 765 switch (buf->vb.field) {
663 case V4L2_FIELD_TOP: 766 case V4L2_FIELD_TOP:
664 bttv_calc_geo(btv,&buf->geo,buf->vb.width, 767 bttv_calc_geo(btv,&buf->geo,buf->vb.width,
665 buf->vb.height,0,buf->tvnorm); 768 buf->vb.height,/* both_fields */ 0,
769 tvnorm,&buf->crop);
666 bttv_risc_planar(btv, &buf->top, buf->vb.dma.sglist, 770 bttv_risc_planar(btv, &buf->top, buf->vb.dma.sglist,
667 0,buf->vb.width,0,buf->vb.height, 771 0,buf->vb.width,0,buf->vb.height,
668 uoffset,voffset,buf->fmt->hshift, 772 uoffset,voffset,buf->fmt->hshift,
@@ -670,7 +774,8 @@ bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf)
670 break; 774 break;
671 case V4L2_FIELD_BOTTOM: 775 case V4L2_FIELD_BOTTOM:
672 bttv_calc_geo(btv,&buf->geo,buf->vb.width, 776 bttv_calc_geo(btv,&buf->geo,buf->vb.width,
673 buf->vb.height,0,buf->tvnorm); 777 buf->vb.height,0,
778 tvnorm,&buf->crop);
674 bttv_risc_planar(btv, &buf->bottom, buf->vb.dma.sglist, 779 bttv_risc_planar(btv, &buf->bottom, buf->vb.dma.sglist,
675 0,buf->vb.width,0,buf->vb.height, 780 0,buf->vb.width,0,buf->vb.height,
676 uoffset,voffset,buf->fmt->hshift, 781 uoffset,voffset,buf->fmt->hshift,
@@ -678,7 +783,8 @@ bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf)
678 break; 783 break;
679 case V4L2_FIELD_INTERLACED: 784 case V4L2_FIELD_INTERLACED:
680 bttv_calc_geo(btv,&buf->geo,buf->vb.width, 785 bttv_calc_geo(btv,&buf->geo,buf->vb.width,
681 buf->vb.height,1,buf->tvnorm); 786 buf->vb.height,1,
787 tvnorm,&buf->crop);
682 lines = buf->vb.height >> 1; 788 lines = buf->vb.height >> 1;
683 ypadding = buf->vb.width; 789 ypadding = buf->vb.width;
684 cpadding = buf->vb.width >> buf->fmt->hshift; 790 cpadding = buf->vb.width >> buf->fmt->hshift;
@@ -700,7 +806,8 @@ bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf)
700 break; 806 break;
701 case V4L2_FIELD_SEQ_TB: 807 case V4L2_FIELD_SEQ_TB:
702 bttv_calc_geo(btv,&buf->geo,buf->vb.width, 808 bttv_calc_geo(btv,&buf->geo,buf->vb.width,
703 buf->vb.height,1,buf->tvnorm); 809 buf->vb.height,1,
810 tvnorm,&buf->crop);
704 lines = buf->vb.height >> 1; 811 lines = buf->vb.height >> 1;
705 ypadding = buf->vb.width; 812 ypadding = buf->vb.width;
706 cpadding = buf->vb.width >> buf->fmt->hshift; 813 cpadding = buf->vb.width >> buf->fmt->hshift;
@@ -731,11 +838,12 @@ bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf)
731 /* build risc code */ 838 /* build risc code */
732 buf->vb.field = V4L2_FIELD_SEQ_TB; 839 buf->vb.field = V4L2_FIELD_SEQ_TB;
733 bttv_calc_geo(btv,&buf->geo,tvnorm->swidth,tvnorm->sheight, 840 bttv_calc_geo(btv,&buf->geo,tvnorm->swidth,tvnorm->sheight,
734 1,buf->tvnorm); 841 1,tvnorm,&buf->crop);
735 bttv_risc_packed(btv, &buf->top, buf->vb.dma.sglist, 842 bttv_risc_packed(btv, &buf->top, buf->vb.dma.sglist,
736 0, RAW_BPL, 0, RAW_LINES); 843 /* offset */ 0, RAW_BPL, /* padding */ 0,
844 /* skip_lines */ 0, RAW_LINES);
737 bttv_risc_packed(btv, &buf->bottom, buf->vb.dma.sglist, 845 bttv_risc_packed(btv, &buf->bottom, buf->vb.dma.sglist,
738 buf->vb.size/2 , RAW_BPL, 0, RAW_LINES); 846 buf->vb.size/2 , RAW_BPL, 0, 0, RAW_LINES);
739 } 847 }
740 848
741 /* copy format info */ 849 /* copy format info */
@@ -761,7 +869,8 @@ bttv_overlay_risc(struct bttv *btv,
761 869
762 /* calculate geometry */ 870 /* calculate geometry */
763 bttv_calc_geo(btv,&buf->geo,ov->w.width,ov->w.height, 871 bttv_calc_geo(btv,&buf->geo,ov->w.width,ov->w.height,
764 V4L2_FIELD_HAS_BOTH(ov->field), ov->tvnorm); 872 V4L2_FIELD_HAS_BOTH(ov->field),
873 &bttv_tvnorms[ov->tvnorm],&buf->crop);
765 874
766 /* build risc code */ 875 /* build risc code */
767 switch (ov->field) { 876 switch (ov->field) {
diff --git a/drivers/media/video/bt8xx/bttv-vbi.c b/drivers/media/video/bt8xx/bttv-vbi.c
index 6fc6b02600..93e35de5a1 100644
--- a/drivers/media/video/bt8xx/bttv-vbi.c
+++ b/drivers/media/video/bt8xx/bttv-vbi.c
@@ -5,6 +5,9 @@
5 5
6 (c) 2002 Gerd Knorr <kraxel@bytesex.org> 6 (c) 2002 Gerd Knorr <kraxel@bytesex.org>
7 7
8 Copyright (C) 2005, 2006 Michael H. Schimek <mschimek@gmx.at>
9 Sponsored by OPQ Systems AB
10
8 This program is free software; you can redistribute it and/or modify 11 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 12 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 13 the Free Software Foundation; either version 2 of the License, or
@@ -41,8 +44,15 @@
41 to be about 244. */ 44 to be about 244. */
42#define VBI_OFFSET 244 45#define VBI_OFFSET 244
43 46
47/* 2048 for compatibility with earlier driver versions. The driver
48 really stores 1024 + tvnorm->vbipack * 4 samples per line in the
49 buffer. Note tvnorm->vbipack is <= 0xFF (limit of VBIPACK_LO + HI
50 is 0x1FF DWORDs) and VBI read()s store a frame counter in the last
51 four bytes of the VBI image. */
52#define VBI_BPL 2048
53
54/* Compatibility. */
44#define VBI_DEFLINES 16 55#define VBI_DEFLINES 16
45#define VBI_MAXLINES 32
46 56
47static unsigned int vbibufs = 4; 57static unsigned int vbibufs = 4;
48static unsigned int vbi_debug = 0; 58static unsigned int vbi_debug = 0;
@@ -58,21 +68,12 @@ MODULE_PARM_DESC(vbi_debug,"vbi code debug messages, default is 0 (no)");
58#define dprintk(fmt, arg...) if (vbi_debug) \ 68#define dprintk(fmt, arg...) if (vbi_debug) \
59 printk(KERN_DEBUG "bttv%d/vbi: " fmt, btv->c.nr , ## arg) 69 printk(KERN_DEBUG "bttv%d/vbi: " fmt, btv->c.nr , ## arg)
60 70
71#define IMAGE_SIZE(fmt) \
72 (((fmt)->count[0] + (fmt)->count[1]) * (fmt)->samples_per_line)
73
61/* ----------------------------------------------------------------------- */ 74/* ----------------------------------------------------------------------- */
62/* vbi risc code + mm */ 75/* vbi risc code + mm */
63 76
64static int
65vbi_buffer_risc(struct bttv *btv, struct bttv_buffer *buf, int lines)
66{
67 int bpl = 2048;
68
69 bttv_risc_packed(btv, &buf->top, buf->vb.dma.sglist,
70 0, bpl-4, 4, lines);
71 bttv_risc_packed(btv, &buf->bottom, buf->vb.dma.sglist,
72 lines * bpl, bpl-4, 4, lines);
73 return 0;
74}
75
76static int vbi_buffer_setup(struct videobuf_queue *q, 77static int vbi_buffer_setup(struct videobuf_queue *q,
77 unsigned int *count, unsigned int *size) 78 unsigned int *count, unsigned int *size)
78{ 79{
@@ -81,8 +82,16 @@ static int vbi_buffer_setup(struct videobuf_queue *q,
81 82
82 if (0 == *count) 83 if (0 == *count)
83 *count = vbibufs; 84 *count = vbibufs;
84 *size = fh->lines * 2 * 2048; 85
85 dprintk("setup: lines=%d\n",fh->lines); 86 *size = IMAGE_SIZE(&fh->vbi_fmt.fmt);
87
88 dprintk("setup: samples=%u start=%d,%d count=%u,%u\n",
89 fh->vbi_fmt.fmt.samples_per_line,
90 fh->vbi_fmt.fmt.start[0],
91 fh->vbi_fmt.fmt.start[1],
92 fh->vbi_fmt.fmt.count[0],
93 fh->vbi_fmt.fmt.count[1]);
94
86 return 0; 95 return 0;
87} 96}
88 97
@@ -93,18 +102,93 @@ static int vbi_buffer_prepare(struct videobuf_queue *q,
93 struct bttv_fh *fh = q->priv_data; 102 struct bttv_fh *fh = q->priv_data;
94 struct bttv *btv = fh->btv; 103 struct bttv *btv = fh->btv;
95 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); 104 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb);
105 const struct bttv_tvnorm *tvnorm;
106 unsigned int skip_lines0, skip_lines1, min_vdelay;
107 int redo_dma_risc;
96 int rc; 108 int rc;
97 109
98 buf->vb.size = fh->lines * 2 * 2048; 110 buf->vb.size = IMAGE_SIZE(&fh->vbi_fmt.fmt);
99 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) 111 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
100 return -EINVAL; 112 return -EINVAL;
101 113
114 tvnorm = fh->vbi_fmt.tvnorm;
115
116 /* There's no VBI_VDELAY register, RISC must skip the lines
117 we don't want. With default parameters we skip zero lines
118 as earlier driver versions did. The driver permits video
119 standard changes while capturing, so we use vbi_fmt.tvnorm
120 instead of btv->tvnorm to skip zero lines after video
121 standard changes as well. */
122
123 skip_lines0 = 0;
124 skip_lines1 = 0;
125
126 if (fh->vbi_fmt.fmt.count[0] > 0)
127 skip_lines0 = max(0, (fh->vbi_fmt.fmt.start[0]
128 - tvnorm->vbistart[0]));
129 if (fh->vbi_fmt.fmt.count[1] > 0)
130 skip_lines1 = max(0, (fh->vbi_fmt.fmt.start[1]
131 - tvnorm->vbistart[1]));
132
133 redo_dma_risc = 0;
134
135 if (buf->vbi_skip[0] != skip_lines0 ||
136 buf->vbi_skip[1] != skip_lines1 ||
137 buf->vbi_count[0] != fh->vbi_fmt.fmt.count[0] ||
138 buf->vbi_count[1] != fh->vbi_fmt.fmt.count[1]) {
139 buf->vbi_skip[0] = skip_lines0;
140 buf->vbi_skip[1] = skip_lines1;
141 buf->vbi_count[0] = fh->vbi_fmt.fmt.count[0];
142 buf->vbi_count[1] = fh->vbi_fmt.fmt.count[1];
143 redo_dma_risc = 1;
144 }
145
102 if (STATE_NEEDS_INIT == buf->vb.state) { 146 if (STATE_NEEDS_INIT == buf->vb.state) {
147 redo_dma_risc = 1;
103 if (0 != (rc = videobuf_iolock(q, &buf->vb, NULL))) 148 if (0 != (rc = videobuf_iolock(q, &buf->vb, NULL)))
104 goto fail; 149 goto fail;
105 if (0 != (rc = vbi_buffer_risc(btv,buf,fh->lines)))
106 goto fail;
107 } 150 }
151
152 if (redo_dma_risc) {
153 unsigned int bpl, padding, offset;
154
155 bpl = 2044; /* max. vbipack */
156 padding = VBI_BPL - bpl;
157
158 if (fh->vbi_fmt.fmt.count[0] > 0) {
159 rc = bttv_risc_packed(btv, &buf->top,
160 buf->vb.dma.sglist,
161 /* offset */ 0, bpl,
162 padding, skip_lines0,
163 fh->vbi_fmt.fmt.count[0]);
164 if (0 != rc)
165 goto fail;
166 }
167
168 if (fh->vbi_fmt.fmt.count[1] > 0) {
169 offset = fh->vbi_fmt.fmt.count[0] * VBI_BPL;
170
171 rc = bttv_risc_packed(btv, &buf->bottom,
172 buf->vb.dma.sglist,
173 offset, bpl,
174 padding, skip_lines1,
175 fh->vbi_fmt.fmt.count[1]);
176 if (0 != rc)
177 goto fail;
178 }
179 }
180
181 /* VBI capturing ends at VDELAY, start of video capturing,
182 no matter where the RISC program ends. VDELAY minimum is 2,
183 bounds.top is the corresponding first field line number
184 times two. VDELAY counts half field lines. */
185 min_vdelay = MIN_VDELAY;
186 if (fh->vbi_fmt.end >= tvnorm->cropcap.bounds.top)
187 min_vdelay += fh->vbi_fmt.end - tvnorm->cropcap.bounds.top;
188
189 /* For bttv_buffer_activate_vbi(). */
190 buf->geo.vdelay = min_vdelay;
191
108 buf->vb.state = STATE_PREPARED; 192 buf->vb.state = STATE_PREPARED;
109 buf->vb.field = field; 193 buf->vb.field = field;
110 dprintk("buf prepare %p: top=%p bottom=%p field=%s\n", 194 dprintk("buf prepare %p: top=%p bottom=%p field=%s\n",
@@ -140,7 +224,7 @@ static void vbi_buffer_release(struct videobuf_queue *q, struct videobuf_buffer
140 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); 224 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb);
141 225
142 dprintk("free %p\n",vb); 226 dprintk("free %p\n",vb);
143 bttv_dma_free(&fh->cap,fh->btv,buf); 227 bttv_dma_free(q,fh->btv,buf);
144} 228}
145 229
146struct videobuf_queue_ops bttv_vbi_qops = { 230struct videobuf_queue_ops bttv_vbi_qops = {
@@ -152,69 +236,215 @@ struct videobuf_queue_ops bttv_vbi_qops = {
152 236
153/* ----------------------------------------------------------------------- */ 237/* ----------------------------------------------------------------------- */
154 238
155void bttv_vbi_setlines(struct bttv_fh *fh, struct bttv *btv, int lines) 239static int
240try_fmt (struct v4l2_vbi_format * f,
241 const struct bttv_tvnorm * tvnorm,
242 __s32 crop_start)
156{ 243{
157 int vdelay; 244 __s32 min_start, max_start, max_end, f2_offset;
158 245 unsigned int i;
159 if (lines < 1) 246
160 lines = 1; 247 /* For compatibility with earlier driver versions we must pretend
161 if (lines > VBI_MAXLINES) 248 the VBI and video capture window may overlap. In reality RISC
162 lines = VBI_MAXLINES; 249 magic aborts VBI capturing at the first line of video capturing,
163 fh->lines = lines; 250 leaving the rest of the buffer unchanged, usually all zero.
164 251 VBI capturing must always start before video capturing. >> 1
165 vdelay = btread(BT848_E_VDELAY_LO); 252 because cropping counts field lines times two. */
166 if (vdelay < lines*2) { 253 min_start = tvnorm->vbistart[0];
167 vdelay = lines*2; 254 max_start = (crop_start >> 1) - 1;
168 btwrite(vdelay,BT848_E_VDELAY_LO); 255 max_end = (tvnorm->cropcap.bounds.top
169 btwrite(vdelay,BT848_O_VDELAY_LO); 256 + tvnorm->cropcap.bounds.height) >> 1;
257
258 if (min_start > max_start)
259 return -EBUSY;
260
261 BUG_ON(max_start >= max_end);
262
263 f->sampling_rate = tvnorm->Fsc;
264 f->samples_per_line = VBI_BPL;
265 f->sample_format = V4L2_PIX_FMT_GREY;
266 f->offset = VBI_OFFSET;
267
268 f2_offset = tvnorm->vbistart[1] - tvnorm->vbistart[0];
269
270 for (i = 0; i < 2; ++i) {
271 if (0 == f->count[i]) {
272 /* No data from this field. We leave f->start[i]
273 alone because VIDIOCSVBIFMT is w/o and EINVALs
274 when a driver does not support exactly the
275 requested parameters. */
276 } else {
277 s64 start, count;
278
279 start = clamp(f->start[i], min_start, max_start);
280 /* s64 to prevent overflow. */
281 count = (s64) f->start[i] + f->count[i] - start;
282 f->start[i] = start;
283 f->count[i] = clamp(count, (s64) 1,
284 max_end - start);
285 }
286
287 min_start += f2_offset;
288 max_start += f2_offset;
289 max_end += f2_offset;
170 } 290 }
291
292 if (0 == (f->count[0] | f->count[1])) {
293 /* As in earlier driver versions. */
294 f->start[0] = tvnorm->vbistart[0];
295 f->start[1] = tvnorm->vbistart[1];
296 f->count[0] = 1;
297 f->count[1] = 1;
298 }
299
300 f->flags = 0;
301
302 f->reserved[0] = 0;
303 f->reserved[1] = 0;
304
305 return 0;
171} 306}
172 307
173void bttv_vbi_try_fmt(struct bttv_fh *fh, struct v4l2_format *f) 308int
309bttv_vbi_try_fmt (struct bttv_fh * fh,
310 struct v4l2_vbi_format * f)
174{ 311{
312 struct bttv *btv = fh->btv;
175 const struct bttv_tvnorm *tvnorm; 313 const struct bttv_tvnorm *tvnorm;
176 s64 count0,count1,count; 314 __s32 crop_start;
177 315
178 tvnorm = &bttv_tvnorms[fh->btv->tvnorm]; 316 mutex_lock(&btv->lock);
179 f->type = V4L2_BUF_TYPE_VBI_CAPTURE; 317
180 f->fmt.vbi.sampling_rate = tvnorm->Fsc; 318 tvnorm = &bttv_tvnorms[btv->tvnorm];
181 f->fmt.vbi.samples_per_line = 2048; 319 crop_start = btv->crop_start;
182 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; 320
183 f->fmt.vbi.offset = VBI_OFFSET; 321 mutex_unlock(&btv->lock);
184 f->fmt.vbi.flags = 0; 322
185 323 return try_fmt(f, tvnorm, crop_start);
186 /* s64 to prevent overflow. */
187 count0 = (s64) f->fmt.vbi.start[0] + f->fmt.vbi.count[0]
188 - tvnorm->vbistart[0];
189 count1 = (s64) f->fmt.vbi.start[1] + f->fmt.vbi.count[1]
190 - tvnorm->vbistart[1];
191 count = clamp (max (count0, count1), (s64) 1, (s64) VBI_MAXLINES);
192
193 f->fmt.vbi.start[0] = tvnorm->vbistart[0];
194 f->fmt.vbi.start[1] = tvnorm->vbistart[1];
195 f->fmt.vbi.count[0] = count;
196 f->fmt.vbi.count[1] = count;
197
198 f->fmt.vbi.reserved[0] = 0;
199 f->fmt.vbi.reserved[1] = 0;
200} 324}
201 325
202void bttv_vbi_get_fmt(struct bttv_fh *fh, struct v4l2_format *f) 326int
327bttv_vbi_set_fmt (struct bttv_fh * fh,
328 struct v4l2_vbi_format * f)
203{ 329{
330 struct bttv *btv = fh->btv;
204 const struct bttv_tvnorm *tvnorm; 331 const struct bttv_tvnorm *tvnorm;
332 __s32 start1, end;
333 int rc;
334
335 mutex_lock(&btv->lock);
336
337 rc = -EBUSY;
338 if (fh->resources & RESOURCE_VBI)
339 goto fail;
340
341 tvnorm = &bttv_tvnorms[btv->tvnorm];
342
343 rc = try_fmt(f, tvnorm, btv->crop_start);
344 if (0 != rc)
345 goto fail;
346
347 start1 = f->start[1] - tvnorm->vbistart[1] + tvnorm->vbistart[0];
348
349 /* First possible line of video capturing. Should be
350 max(f->start[0] + f->count[0], start1 + f->count[1]) * 2
351 when capturing both fields. But for compatibility we must
352 pretend the VBI and video capture window may overlap,
353 so end = start + 1, the lowest possible value, times two
354 because vbi_fmt.end counts field lines times two. */
355 end = max(f->start[0], start1) * 2 + 2;
356
357 mutex_lock(&fh->vbi.lock);
358
359 fh->vbi_fmt.fmt = *f;
360 fh->vbi_fmt.tvnorm = tvnorm;
361 fh->vbi_fmt.end = end;
362
363 mutex_unlock(&fh->vbi.lock);
364
365 rc = 0;
366
367 fail:
368 mutex_unlock(&btv->lock);
369
370 return rc;
371}
372
373void
374bttv_vbi_get_fmt (struct bttv_fh * fh,
375 struct v4l2_vbi_format * f)
376{
377 const struct bttv_tvnorm *tvnorm;
378
379 *f = fh->vbi_fmt.fmt;
205 380
206 tvnorm = &bttv_tvnorms[fh->btv->tvnorm]; 381 tvnorm = &bttv_tvnorms[fh->btv->tvnorm];
207 memset(f,0,sizeof(*f)); 382
208 f->type = V4L2_BUF_TYPE_VBI_CAPTURE; 383 if (tvnorm != fh->vbi_fmt.tvnorm) {
209 f->fmt.vbi.sampling_rate = tvnorm->Fsc; 384 __s32 max_end;
210 f->fmt.vbi.samples_per_line = 2048; 385 unsigned int i;
211 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; 386
212 f->fmt.vbi.offset = VBI_OFFSET; 387 /* As in vbi_buffer_prepare() this imitates the
213 f->fmt.vbi.start[0] = tvnorm->vbistart[0]; 388 behaviour of earlier driver versions after video
214 f->fmt.vbi.start[1] = tvnorm->vbistart[1]; 389 standard changes, with default parameters anyway. */
215 f->fmt.vbi.count[0] = fh->lines; 390
216 f->fmt.vbi.count[1] = fh->lines; 391 max_end = (tvnorm->cropcap.bounds.top
217 f->fmt.vbi.flags = 0; 392 + tvnorm->cropcap.bounds.height) >> 1;
393
394 f->sampling_rate = tvnorm->Fsc;
395
396 for (i = 0; i < 2; ++i) {
397 __s32 new_start;
398
399 new_start = f->start[i]
400 + tvnorm->vbistart[i]
401 - fh->vbi_fmt.tvnorm->vbistart[i];
402
403 f->start[i] = min(new_start, max_end - 1);
404 f->count[i] = min((__s32) f->count[i],
405 max_end - f->start[i]);
406
407 max_end += tvnorm->vbistart[1]
408 - tvnorm->vbistart[0];
409 }
410 }
411}
412
413void
414bttv_vbi_fmt_reset (struct bttv_vbi_fmt * f,
415 int norm)
416{
417 const struct bttv_tvnorm *tvnorm;
418 unsigned int real_samples_per_line;
419 unsigned int real_count;
420
421 tvnorm = &bttv_tvnorms[norm];
422
423 f->fmt.sampling_rate = tvnorm->Fsc;
424 f->fmt.samples_per_line = VBI_BPL;
425 f->fmt.sample_format = V4L2_PIX_FMT_GREY;
426 f->fmt.offset = VBI_OFFSET;
427 f->fmt.start[0] = tvnorm->vbistart[0];
428 f->fmt.start[1] = tvnorm->vbistart[1];
429 f->fmt.count[0] = VBI_DEFLINES;
430 f->fmt.count[1] = VBI_DEFLINES;
431 f->fmt.flags = 0;
432 f->fmt.reserved[0] = 0;
433 f->fmt.reserved[1] = 0;
434
435 /* For compatibility the buffer size must be 2 * VBI_DEFLINES *
436 VBI_BPL regardless of the current video standard. */
437 real_samples_per_line = 1024 + tvnorm->vbipack * 4;
438 real_count = ((tvnorm->cropcap.defrect.top >> 1)
439 - tvnorm->vbistart[0]);
440
441 BUG_ON(real_samples_per_line > VBI_BPL);
442 BUG_ON(real_count > VBI_DEFLINES);
443
444 f->tvnorm = tvnorm;
445
446 /* See bttv_vbi_fmt_set(). */
447 f->end = tvnorm->vbistart[0] * 2 + 2;
218} 448}
219 449
220/* ----------------------------------------------------------------------- */ 450/* ----------------------------------------------------------------------- */
diff --git a/drivers/media/video/bt8xx/bttv.h b/drivers/media/video/bt8xx/bttv.h
index f9c9e3c4d1..5491acbdaf 100644
--- a/drivers/media/video/bt8xx/bttv.h
+++ b/drivers/media/video/bt8xx/bttv.h
@@ -197,33 +197,6 @@ struct bttv_core {
197struct bttv; 197struct bttv;
198 198
199 199
200struct bttv_ir {
201 struct input_dev *dev;
202 struct ir_input_state ir;
203 char name[32];
204 char phys[32];
205
206 /* Usual gpio signalling */
207
208 u32 mask_keycode;
209 u32 mask_keydown;
210 u32 mask_keyup;
211 u32 polling;
212 u32 last_gpio;
213 struct work_struct work;
214 struct timer_list timer;
215
216 /* RC5 gpio */
217 u32 rc5_gpio;
218 struct timer_list timer_end; /* timer_end for code completion */
219 struct timer_list timer_keyup; /* timer_end for key release */
220 u32 last_rc5; /* last good rc5 code */
221 u32 last_bit; /* last raw bit seen */
222 u32 code; /* raw code under construction */
223 struct timeval base_time; /* time of last seen code */
224 int active; /* building raw code */
225};
226
227struct tvcard 200struct tvcard
228{ 201{
229 char *name; 202 char *name;
diff --git a/drivers/media/video/bt8xx/bttvp.h b/drivers/media/video/bt8xx/bttvp.h
index 311c4c541e..ad79b8d534 100644
--- a/drivers/media/video/bt8xx/bttvp.h
+++ b/drivers/media/video/bt8xx/bttvp.h
@@ -26,7 +26,7 @@
26#define _BTTVP_H_ 26#define _BTTVP_H_
27 27
28#include <linux/version.h> 28#include <linux/version.h>
29#define BTTV_VERSION_CODE KERNEL_VERSION(0,9,16) 29#define BTTV_VERSION_CODE KERNEL_VERSION(0,9,17)
30 30
31#include <linux/types.h> 31#include <linux/types.h>
32#include <linux/wait.h> 32#include <linux/wait.h>
@@ -66,14 +66,22 @@
66#define RISC_SLOT_LOOP 14 66#define RISC_SLOT_LOOP 14
67 67
68#define RESOURCE_OVERLAY 1 68#define RESOURCE_OVERLAY 1
69#define RESOURCE_VIDEO 2 69#define RESOURCE_VIDEO_STREAM 2
70#define RESOURCE_VBI 4 70#define RESOURCE_VBI 4
71#define RESOURCE_VIDEO_READ 8
71 72
72#define RAW_LINES 640 73#define RAW_LINES 640
73#define RAW_BPL 1024 74#define RAW_BPL 1024
74 75
75#define UNSET (-1U) 76#define UNSET (-1U)
76 77
78/* Min. value in VDELAY register. */
79#define MIN_VDELAY 2
80/* Even to get Cb first, odd for Cr. */
81#define MAX_HDELAY (0x3FF & -2)
82/* Limits scaled width, which must be a multiple of 4. */
83#define MAX_HACTIVE (0x3FF & -4)
84
77#define clamp(x, low, high) min (max (low, x), high) 85#define clamp(x, low, high) min (max (low, x), high)
78 86
79/* ---------------------------------------------------------- */ 87/* ---------------------------------------------------------- */
@@ -92,8 +100,13 @@ struct bttv_tvnorm {
92 u16 vtotal; 100 u16 vtotal;
93 int sram; 101 int sram;
94 /* ITU-R frame line number of the first VBI line we can 102 /* ITU-R frame line number of the first VBI line we can
95 capture, of the first and second field. */ 103 capture, of the first and second field. The last possible line
104 is determined by cropcap.bounds. */
96 u16 vbistart[2]; 105 u16 vbistart[2];
106 /* Horizontally this counts fCLKx1 samples following the leading
107 edge of the horizontal sync pulse, vertically ITU-R frame line
108 numbers of the first field times two (2, 4, 6, ... 524 or 624). */
109 struct v4l2_cropcap cropcap;
97}; 110};
98extern const struct bttv_tvnorm bttv_tvnorms[]; 111extern const struct bttv_tvnorm bttv_tvnorms[];
99 112
@@ -128,6 +141,9 @@ struct bttv_buffer {
128 struct bttv_geometry geo; 141 struct bttv_geometry geo;
129 struct btcx_riscmem top; 142 struct btcx_riscmem top;
130 struct btcx_riscmem bottom; 143 struct btcx_riscmem bottom;
144 struct v4l2_rect crop;
145 unsigned int vbi_skip[2];
146 unsigned int vbi_count[2];
131}; 147};
132 148
133struct bttv_buffer_set { 149struct bttv_buffer_set {
@@ -146,6 +162,34 @@ struct bttv_overlay {
146 int setup_ok; 162 int setup_ok;
147}; 163};
148 164
165struct bttv_vbi_fmt {
166 struct v4l2_vbi_format fmt;
167
168 /* fmt.start[] and count[] refer to this video standard. */
169 const struct bttv_tvnorm *tvnorm;
170
171 /* Earliest possible start of video capturing with this
172 v4l2_vbi_format, in struct bttv_crop.rect units. */
173 __s32 end;
174};
175
176/* bttv-vbi.c */
177void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, int norm);
178
179struct bttv_crop {
180 /* A cropping rectangle in struct bttv_tvnorm.cropcap units. */
181 struct v4l2_rect rect;
182
183 /* Scaled image size limits with this crop rect. Divide
184 max_height, but not min_height, by two when capturing
185 single fields. See also bttv_crop_reset() and
186 bttv_crop_adjust() in bttv-driver.c. */
187 __s32 min_scaled_width;
188 __s32 min_scaled_height;
189 __s32 max_scaled_width;
190 __s32 max_scaled_height;
191};
192
149struct bttv_fh { 193struct bttv_fh {
150 struct bttv *btv; 194 struct bttv *btv;
151 int resources; 195 int resources;
@@ -160,13 +204,19 @@ struct bttv_fh {
160 int width; 204 int width;
161 int height; 205 int height;
162 206
163 /* current settings */ 207 /* video overlay */
164 const struct bttv_format *ovfmt; 208 const struct bttv_format *ovfmt;
165 struct bttv_overlay ov; 209 struct bttv_overlay ov;
166 210
167 /* video overlay */ 211 /* Application called VIDIOC_S_CROP. */
212 int do_crop;
213
214 /* vbi capture */
168 struct videobuf_queue vbi; 215 struct videobuf_queue vbi;
169 int lines; 216 /* Current VBI capture window as seen through this fh (cannot
217 be global for compatibility with earlier drivers). Protected
218 by struct bttv.lock and struct bttv_fh.vbi.lock. */
219 struct bttv_vbi_fmt vbi_fmt;
170}; 220};
171 221
172/* ---------------------------------------------------------- */ 222/* ---------------------------------------------------------- */
@@ -176,7 +226,8 @@ struct bttv_fh {
176int bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc, 226int bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,
177 struct scatterlist *sglist, 227 struct scatterlist *sglist,
178 unsigned int offset, unsigned int bpl, 228 unsigned int offset, unsigned int bpl,
179 unsigned int pitch, unsigned int lines); 229 unsigned int pitch, unsigned int skip_lines,
230 unsigned int store_lines);
180 231
181/* control dma register + risc main loop */ 232/* control dma register + risc main loop */
182void bttv_set_dma(struct bttv *btv, int override); 233void bttv_set_dma(struct bttv *btv, int override);
@@ -202,9 +253,9 @@ int bttv_overlay_risc(struct bttv *btv, struct bttv_overlay *ov,
202/* ---------------------------------------------------------- */ 253/* ---------------------------------------------------------- */
203/* bttv-vbi.c */ 254/* bttv-vbi.c */
204 255
205void bttv_vbi_try_fmt(struct bttv_fh *fh, struct v4l2_format *f); 256int bttv_vbi_try_fmt(struct bttv_fh *fh, struct v4l2_vbi_format *f);
206void bttv_vbi_get_fmt(struct bttv_fh *fh, struct v4l2_format *f); 257void bttv_vbi_get_fmt(struct bttv_fh *fh, struct v4l2_vbi_format *f);
207void bttv_vbi_setlines(struct bttv_fh *fh, struct bttv *btv, int lines); 258int bttv_vbi_set_fmt(struct bttv_fh *fh, struct v4l2_vbi_format *f);
208 259
209extern struct videobuf_queue_ops bttv_vbi_qops; 260extern struct videobuf_queue_ops bttv_vbi_qops;
210 261
@@ -233,7 +284,6 @@ extern int fini_bttv_i2c(struct bttv *btv);
233#define d2printk if (bttv_debug >= 2) printk 284#define d2printk if (bttv_debug >= 2) printk
234 285
235#define BTTV_MAX_FBUF 0x208000 286#define BTTV_MAX_FBUF 0x208000
236#define VBIBUF_SIZE (2048*VBI_MAXLINES*2)
237#define BTTV_TIMEOUT (HZ/2) /* 0.5 seconds */ 287#define BTTV_TIMEOUT (HZ/2) /* 0.5 seconds */
238#define BTTV_FREE_IDLE (HZ) /* one second */ 288#define BTTV_FREE_IDLE (HZ) /* one second */
239 289
@@ -308,13 +358,12 @@ struct bttv {
308 358
309 /* infrared remote */ 359 /* infrared remote */
310 int has_remote; 360 int has_remote;
311 struct bttv_ir *remote; 361 struct card_ir *remote;
312 362
313 /* locking */ 363 /* locking */
314 spinlock_t s_lock; 364 spinlock_t s_lock;
315 struct mutex lock; 365 struct mutex lock;
316 int resources; 366 int resources;
317 struct mutex reslock;
318#ifdef VIDIOC_G_PRIORITY 367#ifdef VIDIOC_G_PRIORITY
319 struct v4l2_prio_state prio; 368 struct v4l2_prio_state prio;
320#endif 369#endif
@@ -384,6 +433,21 @@ struct bttv {
384 433
385 unsigned int users; 434 unsigned int users;
386 struct bttv_fh init; 435 struct bttv_fh init;
436
437 /* Default (0) and current (1) video capturing and overlay
438 cropping parameters in bttv_tvnorm.cropcap units. Protected
439 by bttv.lock. */
440 struct bttv_crop crop[2];
441
442 /* Earliest possible start of video capturing in
443 bttv_tvnorm.cropcap line units. Set by check_alloc_btres()
444 and free_btres(). Protected by bttv.lock. */
445 __s32 vbi_end;
446
447 /* Latest possible end of VBI capturing (= crop[x].rect.top when
448 VIDEO_RESOURCES are locked). Set by check_alloc_btres()
449 and free_btres(). Protected by bttv.lock. */
450 __s32 crop_start;
387}; 451};
388 452
389/* our devices */ 453/* our devices */
diff --git a/drivers/media/video/cafe_ccic.c b/drivers/media/video/cafe_ccic.c
index 4dae892566..710c11a682 100644
--- a/drivers/media/video/cafe_ccic.c
+++ b/drivers/media/video/cafe_ccic.c
@@ -1022,7 +1022,7 @@ static ssize_t cafe_v4l_read(struct file *filp,
1022 char __user *buffer, size_t len, loff_t *pos) 1022 char __user *buffer, size_t len, loff_t *pos)
1023{ 1023{
1024 struct cafe_camera *cam = filp->private_data; 1024 struct cafe_camera *cam = filp->private_data;
1025 int ret; 1025 int ret = 0;
1026 1026
1027 /* 1027 /*
1028 * Perhaps we're in speculative read mode and already 1028 * Perhaps we're in speculative read mode and already
@@ -1195,7 +1195,7 @@ static int cafe_vidioc_reqbufs(struct file *filp, void *priv,
1195 struct v4l2_requestbuffers *req) 1195 struct v4l2_requestbuffers *req)
1196{ 1196{
1197 struct cafe_camera *cam = filp->private_data; 1197 struct cafe_camera *cam = filp->private_data;
1198 int ret; 1198 int ret = 0; /* Silence warning */
1199 1199
1200 /* 1200 /*
1201 * Make sure it's something we can do. User pointers could be 1201 * Make sure it's something we can do. User pointers could be
@@ -1251,8 +1251,6 @@ static int cafe_vidioc_reqbufs(struct file *filp, void *priv,
1251 1251
1252 if (cam->n_sbufs == 0) /* no luck at all - ret already set */ 1252 if (cam->n_sbufs == 0) /* no luck at all - ret already set */
1253 kfree(cam->sb_bufs); 1253 kfree(cam->sb_bufs);
1254 else
1255 ret = 0;
1256 req->count = cam->n_sbufs; /* In case of partial success */ 1254 req->count = cam->n_sbufs; /* In case of partial success */
1257 1255
1258 out: 1256 out:
diff --git a/drivers/media/video/cpia.c b/drivers/media/video/cpia.c
index 7e8d5ef58b..78c9699eaf 100644
--- a/drivers/media/video/cpia.c
+++ b/drivers/media/video/cpia.c
@@ -1350,13 +1350,13 @@ out:
1350 1350
1351static void create_proc_cpia_cam(struct cam_data *cam) 1351static void create_proc_cpia_cam(struct cam_data *cam)
1352{ 1352{
1353 char name[7]; 1353 char name[5 + 1 + 10 + 1];
1354 struct proc_dir_entry *ent; 1354 struct proc_dir_entry *ent;
1355 1355
1356 if (!cpia_proc_root || !cam) 1356 if (!cpia_proc_root || !cam)
1357 return; 1357 return;
1358 1358
1359 sprintf(name, "video%d", cam->vdev.minor); 1359 snprintf(name, sizeof(name), "video%d", cam->vdev.minor);
1360 1360
1361 ent = create_proc_entry(name, S_IFREG|S_IRUGO|S_IWUSR, cpia_proc_root); 1361 ent = create_proc_entry(name, S_IFREG|S_IRUGO|S_IWUSR, cpia_proc_root);
1362 if (!ent) 1362 if (!ent)
@@ -1376,12 +1376,12 @@ static void create_proc_cpia_cam(struct cam_data *cam)
1376 1376
1377static void destroy_proc_cpia_cam(struct cam_data *cam) 1377static void destroy_proc_cpia_cam(struct cam_data *cam)
1378{ 1378{
1379 char name[7]; 1379 char name[5 + 1 + 10 + 1];
1380 1380
1381 if (!cam || !cam->proc_entry) 1381 if (!cam || !cam->proc_entry)
1382 return; 1382 return;
1383 1383
1384 sprintf(name, "video%d", cam->vdev.minor); 1384 snprintf(name, sizeof(name), "video%d", cam->vdev.minor);
1385 remove_proc_entry(name, cpia_proc_root); 1385 remove_proc_entry(name, cpia_proc_root);
1386 cam->proc_entry = NULL; 1386 cam->proc_entry = NULL;
1387} 1387}
@@ -3153,8 +3153,7 @@ static int reset_camera(struct cam_data *cam)
3153 3153
3154static void put_cam(struct cpia_camera_ops* ops) 3154static void put_cam(struct cpia_camera_ops* ops)
3155{ 3155{
3156 if (ops->owner) 3156 module_put(ops->owner);
3157 module_put(ops->owner);
3158} 3157}
3159 3158
3160/* ------------------------- V4L interface --------------------- */ 3159/* ------------------------- V4L interface --------------------- */
diff --git a/drivers/media/video/cx2341x.c b/drivers/media/video/cx2341x.c
index 2f5ca71e02..d60cd5ecf8 100644
--- a/drivers/media/video/cx2341x.c
+++ b/drivers/media/video/cx2341x.c
@@ -56,7 +56,6 @@ const u32 cx2341x_mpeg_ctrls[] = {
56 V4L2_CID_MPEG_VIDEO_B_FRAMES, 56 V4L2_CID_MPEG_VIDEO_B_FRAMES,
57 V4L2_CID_MPEG_VIDEO_GOP_SIZE, 57 V4L2_CID_MPEG_VIDEO_GOP_SIZE,
58 V4L2_CID_MPEG_VIDEO_GOP_CLOSURE, 58 V4L2_CID_MPEG_VIDEO_GOP_CLOSURE,
59 V4L2_CID_MPEG_VIDEO_PULLDOWN,
60 V4L2_CID_MPEG_VIDEO_BITRATE_MODE, 59 V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
61 V4L2_CID_MPEG_VIDEO_BITRATE, 60 V4L2_CID_MPEG_VIDEO_BITRATE,
62 V4L2_CID_MPEG_VIDEO_BITRATE_PEAK, 61 V4L2_CID_MPEG_VIDEO_BITRATE_PEAK,
@@ -118,9 +117,6 @@ static int cx2341x_get_ctrl(struct cx2341x_mpeg_params *params,
118 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: 117 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
119 ctrl->value = params->video_gop_closure; 118 ctrl->value = params->video_gop_closure;
120 break; 119 break;
121 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
122 ctrl->value = params->video_pulldown;
123 break;
124 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: 120 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
125 ctrl->value = params->video_bitrate_mode; 121 ctrl->value = params->video_bitrate_mode;
126 break; 122 break;
@@ -231,9 +227,6 @@ static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params,
231 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: 227 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
232 params->video_gop_closure = ctrl->value; 228 params->video_gop_closure = ctrl->value;
233 break; 229 break;
234 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
235 params->video_pulldown = ctrl->value;
236 break;
237 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: 230 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
238 /* MPEG-1 only allows CBR */ 231 /* MPEG-1 only allows CBR */
239 if (params->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1 && 232 if (params->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1 &&
@@ -679,7 +672,6 @@ void cx2341x_fill_defaults(struct cx2341x_mpeg_params *p)
679 .video_b_frames = 2, 672 .video_b_frames = 2,
680 .video_gop_size = 12, 673 .video_gop_size = 12,
681 .video_gop_closure = 1, 674 .video_gop_closure = 1,
682 .video_pulldown = 0,
683 .video_bitrate_mode = V4L2_MPEG_VIDEO_BITRATE_MODE_VBR, 675 .video_bitrate_mode = V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
684 .video_bitrate = 6000000, 676 .video_bitrate = 6000000,
685 .video_bitrate_peak = 8000000, 677 .video_bitrate_peak = 8000000,
@@ -783,10 +775,6 @@ int cx2341x_update(void *priv, cx2341x_mbox_func func,
783 err = cx2341x_api(priv, func, CX2341X_ENC_SET_GOP_CLOSURE, 1, new->video_gop_closure); 775 err = cx2341x_api(priv, func, CX2341X_ENC_SET_GOP_CLOSURE, 1, new->video_gop_closure);
784 if (err) return err; 776 if (err) return err;
785 } 777 }
786 if (old == NULL || old->video_pulldown != new->video_pulldown) {
787 err = cx2341x_api(priv, func, CX2341X_ENC_SET_3_2_PULLDOWN, 1, new->video_pulldown);
788 if (err) return err;
789 }
790 if (old == NULL || old->audio_properties != new->audio_properties) { 778 if (old == NULL || old->audio_properties != new->audio_properties) {
791 err = cx2341x_api(priv, func, CX2341X_ENC_SET_AUDIO_PROPERTIES, 1, new->audio_properties); 779 err = cx2341x_api(priv, func, CX2341X_ENC_SET_AUDIO_PROPERTIES, 1, new->audio_properties);
792 if (err) return err; 780 if (err) return err;
@@ -888,11 +876,10 @@ void cx2341x_log_status(struct cx2341x_mpeg_params *p, const char *prefix)
888 printk(", Peak %d", p->video_bitrate_peak); 876 printk(", Peak %d", p->video_bitrate_peak);
889 } 877 }
890 printk("\n"); 878 printk("\n");
891 printk(KERN_INFO "%s: Video: GOP Size %d, %d B-Frames, %sGOP Closure, %s3:2 Pulldown\n", 879 printk(KERN_INFO "%s: Video: GOP Size %d, %d B-Frames, %sGOP Closure\n",
892 prefix, 880 prefix,
893 p->video_gop_size, p->video_b_frames, 881 p->video_gop_size, p->video_b_frames,
894 p->video_gop_closure ? "" : "No ", 882 p->video_gop_closure ? "" : "No ");
895 p->video_pulldown ? "" : "No ");
896 if (p->video_temporal_decimation) { 883 if (p->video_temporal_decimation) {
897 printk(KERN_INFO "%s: Video: Temporal Decimation %d\n", 884 printk(KERN_INFO "%s: Video: Temporal Decimation %d\n",
898 prefix, p->video_temporal_decimation); 885 prefix, p->video_temporal_decimation);
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index 7bb7589a07..774d253655 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -628,25 +628,19 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
628#ifdef CONFIG_VIDEO_ADV_DEBUG 628#ifdef CONFIG_VIDEO_ADV_DEBUG
629 /* ioctls to allow direct access to the 629 /* ioctls to allow direct access to the
630 * cx25840 registers for testing */ 630 * cx25840 registers for testing */
631 case VIDIOC_INT_G_REGISTER: 631 case VIDIOC_DBG_G_REGISTER:
632 case VIDIOC_DBG_S_REGISTER:
632 { 633 {
633 struct v4l2_register *reg = arg; 634 struct v4l2_register *reg = arg;
634 635
635 if (reg->i2c_id != I2C_DRIVERID_CX25840) 636 if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip))
636 return -EINVAL;
637 reg->val = cx25840_read(client, reg->reg & 0x0fff);
638 break;
639 }
640
641 case VIDIOC_INT_S_REGISTER:
642 {
643 struct v4l2_register *reg = arg;
644
645 if (reg->i2c_id != I2C_DRIVERID_CX25840)
646 return -EINVAL; 637 return -EINVAL;
647 if (!capable(CAP_SYS_ADMIN)) 638 if (!capable(CAP_SYS_ADMIN))
648 return -EPERM; 639 return -EPERM;
649 cx25840_write(client, reg->reg & 0x0fff, reg->val & 0xff); 640 if (cmd == VIDIOC_DBG_G_REGISTER)
641 reg->val = cx25840_read(client, reg->reg & 0x0fff);
642 else
643 cx25840_write(client, reg->reg & 0x0fff, reg->val & 0xff);
650 break; 644 break;
651 } 645 }
652#endif 646#endif
@@ -893,9 +887,11 @@ static int cx25840_detect_client(struct i2c_adapter *adapter, int address,
893 return 0; 887 return 0;
894 } 888 }
895 889
890 /* Note: revision '(device_id & 0x0f) == 2' was never built. The
891 marking skips from 0x1 == 22 to 0x3 == 23. */
896 v4l_info(client, "cx25%3x-2%x found @ 0x%x (%s)\n", 892 v4l_info(client, "cx25%3x-2%x found @ 0x%x (%s)\n",
897 (device_id & 0xfff0) >> 4, 893 (device_id & 0xfff0) >> 4,
898 (device_id & 0x0f) < 3 ? (device_id & 0x0f) + 1 : 3, 894 (device_id & 0x0f) < 3 ? (device_id & 0x0f) + 1 : (device_id & 0x0f),
899 address << 1, adapter->name); 895 address << 1, adapter->name);
900 896
901 i2c_set_clientdata(client, state); 897 i2c_set_clientdata(client, state);
@@ -907,13 +903,13 @@ static int cx25840_detect_client(struct i2c_adapter *adapter, int address,
907 state->vbi_line_offset = 8; 903 state->vbi_line_offset = 8;
908 state->id = id; 904 state->id = id;
909 905
906 i2c_attach_client(client);
907
910 if (state->is_cx25836) 908 if (state->is_cx25836)
911 cx25836_initialize(client); 909 cx25836_initialize(client);
912 else 910 else
913 cx25840_initialize(client, 1); 911 cx25840_initialize(client, 1);
914 912
915 i2c_attach_client(client);
916
917 return 0; 913 return 0;
918} 914}
919 915
diff --git a/drivers/media/video/cx25840/cx25840-firmware.c b/drivers/media/video/cx25840/cx25840-firmware.c
index 1958d4016e..0e86b9d033 100644
--- a/drivers/media/video/cx25840/cx25840-firmware.c
+++ b/drivers/media/video/cx25840/cx25840-firmware.c
@@ -37,7 +37,7 @@
37 */ 37 */
38#define FWSEND 48 38#define FWSEND 48
39 39
40#define FWDEV(x) &((x)->adapter->dev) 40#define FWDEV(x) &((x)->dev)
41 41
42static char *firmware = FWFILE; 42static char *firmware = FWFILE;
43 43
diff --git a/drivers/media/video/cx88/Makefile b/drivers/media/video/cx88/Makefile
index 639c3b659d..532cee35eb 100644
--- a/drivers/media/video/cx88/Makefile
+++ b/drivers/media/video/cx88/Makefile
@@ -12,8 +12,3 @@ obj-$(CONFIG_VIDEO_CX88_VP3054) += cx88-vp3054-i2c.o
12EXTRA_CFLAGS += -Idrivers/media/video 12EXTRA_CFLAGS += -Idrivers/media/video
13EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core 13EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
14EXTRA_CFLAGS += -Idrivers/media/dvb/frontends 14EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
15
16extra-cflags-$(CONFIG_VIDEO_BUF_DVB) += -DHAVE_VIDEO_BUF_DVB=1
17extra-cflags-$(CONFIG_VIDEO_CX88_VP3054)+= -DHAVE_VP3054_I2C=1
18
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 9a7a2996f2..b0466b88f5 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -6,6 +6,9 @@
6 * (c) 2004 Jelle Foks <jelle@foks.8m.com> 6 * (c) 2004 Jelle Foks <jelle@foks.8m.com>
7 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> 7 * (c) 2004 Gerd Knorr <kraxel@bytesex.org>
8 * 8 *
9 * (c) 2005-2006 Mauro Carvalho Chehab <mchehab@infradead.org>
10 * - video_ioctl2 conversion
11 *
9 * Includes parts from the ivtv driver( http://ivtv.sourceforge.net/), 12 * Includes parts from the ivtv driver( http://ivtv.sourceforge.net/),
10 * 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
@@ -53,7 +56,8 @@ MODULE_PARM_DESC(debug,"enable debug messages [blackbird]");
53 56
54/* ------------------------------------------------------------------ */ 57/* ------------------------------------------------------------------ */
55 58
56#define BLACKBIRD_FIRM_IMAGE_SIZE 256*1024 59#define OLD_BLACKBIRD_FIRM_IMAGE_SIZE 262144
60#define BLACKBIRD_FIRM_IMAGE_SIZE 376836
57 61
58/* defines below are from ivtv-driver.h */ 62/* defines below are from ivtv-driver.h */
59 63
@@ -401,7 +405,7 @@ static int blackbird_find_mailbox(struct cx8802_dev *dev)
401 u32 value; 405 u32 value;
402 int i; 406 int i;
403 407
404 for (i = 0; i < BLACKBIRD_FIRM_IMAGE_SIZE; i++) { 408 for (i = 0; i < dev->fw_size; i++) {
405 memory_read(dev->core, i, &value); 409 memory_read(dev->core, i, &value);
406 if (value == signature[signaturecnt]) 410 if (value == signature[signaturecnt])
407 signaturecnt++; 411 signaturecnt++;
@@ -449,12 +453,15 @@ static int blackbird_load_firmware(struct cx8802_dev *dev)
449 return -1; 453 return -1;
450 } 454 }
451 455
452 if (firmware->size != BLACKBIRD_FIRM_IMAGE_SIZE) { 456 if ((firmware->size != BLACKBIRD_FIRM_IMAGE_SIZE) &&
453 dprintk(0, "ERROR: Firmware size mismatch (have %zd, expected %d)\n", 457 (firmware->size != OLD_BLACKBIRD_FIRM_IMAGE_SIZE)) {
454 firmware->size, BLACKBIRD_FIRM_IMAGE_SIZE); 458 dprintk(0, "ERROR: Firmware size mismatch (have %zd, expected %d or %d)\n",
459 firmware->size, BLACKBIRD_FIRM_IMAGE_SIZE,
460 OLD_BLACKBIRD_FIRM_IMAGE_SIZE);
455 release_firmware(firmware); 461 release_firmware(firmware);
456 return -1; 462 return -1;
457 } 463 }
464 dev->fw_size = firmware->size;
458 465
459 if (0 != memcmp(firmware->data, magic, 8)) { 466 if (0 != memcmp(firmware->data, magic, 8)) {
460 dprintk(0, "ERROR: Firmware magic mismatch, wrong file?\n"); 467 dprintk(0, "ERROR: Firmware magic mismatch, wrong file?\n");
@@ -520,7 +527,7 @@ static void blackbird_codec_settings(struct cx8802_dev *dev)
520 527
521 dev->params.width = dev->width; 528 dev->params.width = dev->width;
522 dev->params.height = dev->height; 529 dev->params.height = dev->height;
523 dev->params.is_50hz = (dev->core->tvnorm->id & V4L2_STD_625_50) != 0; 530 dev->params.is_50hz = (dev->core->tvnorm & V4L2_STD_625_50) != 0;
524 531
525 cx2341x_update(dev, blackbird_mbox_func, NULL, &dev->params); 532 cx2341x_update(dev, blackbird_mbox_func, NULL, &dev->params);
526} 533}
@@ -710,8 +717,13 @@ static int blackbird_queryctrl(struct cx8802_dev *dev, struct v4l2_queryctrl *qc
710 return 0; 717 return 0;
711} 718}
712 719
713static int blackbird_querymenu(struct cx8802_dev *dev, struct v4l2_querymenu *qmenu) 720/* ------------------------------------------------------------------ */
721/* IOCTL Handlers */
722
723static int vidioc_querymenu (struct file *file, void *priv,
724 struct v4l2_querymenu *qmenu)
714{ 725{
726 struct cx8802_dev *dev = ((struct cx8802_fh *)priv)->dev;
715 struct v4l2_queryctrl qctrl; 727 struct v4l2_queryctrl qctrl;
716 728
717 qctrl.id = qmenu->id; 729 qctrl.id = qmenu->id;
@@ -719,221 +731,347 @@ static int blackbird_querymenu(struct cx8802_dev *dev, struct v4l2_querymenu *qm
719 return v4l2_ctrl_query_menu(qmenu, &qctrl, cx2341x_ctrl_get_menu(qmenu->id)); 731 return v4l2_ctrl_query_menu(qmenu, &qctrl, cx2341x_ctrl_get_menu(qmenu->id));
720} 732}
721 733
722/* ------------------------------------------------------------------ */ 734static int vidioc_querycap (struct file *file, void *priv,
735 struct v4l2_capability *cap)
736{
737 struct cx8802_dev *dev = ((struct cx8802_fh *)priv)->dev;
738 struct cx88_core *core = dev->core;
723 739
724static int mpeg_do_ioctl(struct inode *inode, struct file *file, 740 strcpy(cap->driver, "cx88_blackbird");
725 unsigned int cmd, void *arg) 741 strlcpy(cap->card, cx88_boards[core->board].name,sizeof(cap->card));
742 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
743 cap->version = CX88_VERSION_CODE;
744 cap->capabilities =
745 V4L2_CAP_VIDEO_CAPTURE |
746 V4L2_CAP_READWRITE |
747 V4L2_CAP_STREAMING;
748 if (UNSET != core->tuner_type)
749 cap->capabilities |= V4L2_CAP_TUNER;
750 return 0;
751}
752
753static int vidioc_enum_fmt_cap (struct file *file, void *priv,
754 struct v4l2_fmtdesc *f)
726{ 755{
727 struct cx8802_fh *fh = file->private_data; 756 if (f->index != 0)
728 struct cx8802_dev *dev = fh->dev; 757 return -EINVAL;
758
759 strlcpy(f->description, "MPEG", sizeof(f->description));
760 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
761 f->pixelformat = V4L2_PIX_FMT_MPEG;
762 return 0;
763}
764
765static int vidioc_g_fmt_cap (struct file *file, void *priv,
766 struct v4l2_format *f)
767{
768 struct cx8802_fh *fh = priv;
769 struct cx8802_dev *dev = fh->dev;
770
771 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
772 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
773 f->fmt.pix.bytesperline = 0;
774 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */
775 f->fmt.pix.colorspace = 0;
776 f->fmt.pix.width = dev->width;
777 f->fmt.pix.height = dev->height;
778 f->fmt.pix.field = fh->mpegq.field;
779 dprintk(0,"VIDIOC_G_FMT: w: %d, h: %d, f: %d\n",
780 dev->width, dev->height, fh->mpegq.field );
781 return 0;
782}
783
784static int vidioc_try_fmt_cap (struct file *file, void *priv,
785 struct v4l2_format *f)
786{
787 struct cx8802_fh *fh = priv;
788 struct cx8802_dev *dev = fh->dev;
789
790 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
791 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
792 f->fmt.pix.bytesperline = 0;
793 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */;
794 f->fmt.pix.colorspace = 0;
795 dprintk(0,"VIDIOC_TRY_FMT: w: %d, h: %d, f: %d\n",
796 dev->width, dev->height, fh->mpegq.field );
797 return 0;
798}
799
800static int vidioc_s_fmt_cap (struct file *file, void *priv,
801 struct v4l2_format *f)
802{
803 struct cx8802_fh *fh = priv;
804 struct cx8802_dev *dev = fh->dev;
729 struct cx88_core *core = dev->core; 805 struct cx88_core *core = dev->core;
730 806
731 if (debug > 1) 807 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
732 v4l_print_ioctl(core->name,cmd); 808 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
733 809 f->fmt.pix.bytesperline = 0;
734 switch (cmd) { 810 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */;
735 811 f->fmt.pix.colorspace = 0;
736 /* --- capabilities ------------------------------------------ */ 812 dev->width = f->fmt.pix.width;
737 case VIDIOC_QUERYCAP: 813 dev->height = f->fmt.pix.height;
738 { 814 fh->mpegq.field = f->fmt.pix.field;
739 struct v4l2_capability *cap = arg; 815 cx88_set_scale(core, f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field);
740 816 blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0,
741 memset(cap,0,sizeof(*cap)); 817 f->fmt.pix.height, f->fmt.pix.width);
742 strcpy(cap->driver, "cx88_blackbird"); 818 dprintk(0,"VIDIOC_S_FMT: w: %d, h: %d, f: %d\n",
743 strlcpy(cap->card, cx88_boards[core->board].name,sizeof(cap->card)); 819 f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field );
744 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci)); 820 return 0;
745 cap->version = CX88_VERSION_CODE; 821}
746 cap->capabilities =
747 V4L2_CAP_VIDEO_CAPTURE |
748 V4L2_CAP_READWRITE |
749 V4L2_CAP_STREAMING |
750 0;
751 if (UNSET != core->tuner_type)
752 cap->capabilities |= V4L2_CAP_TUNER;
753 822
754 return 0; 823static int vidioc_reqbufs (struct file *file, void *priv, struct v4l2_requestbuffers *p)
755 } 824{
825 struct cx8802_fh *fh = priv;
826 return (videobuf_reqbufs(&fh->mpegq, p));
827}
756 828
757 /* --- capture ioctls ---------------------------------------- */ 829static int vidioc_querybuf (struct file *file, void *priv, struct v4l2_buffer *p)
758 case VIDIOC_ENUM_FMT: 830{
759 { 831 struct cx8802_fh *fh = priv;
760 struct v4l2_fmtdesc *f = arg; 832 return (videobuf_querybuf(&fh->mpegq, p));
761 int index; 833}
762
763 index = f->index;
764 if (index != 0)
765 return -EINVAL;
766
767 memset(f,0,sizeof(*f));
768 f->index = index;
769 strlcpy(f->description, "MPEG", sizeof(f->description));
770 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
771 f->pixelformat = V4L2_PIX_FMT_MPEG;
772 return 0;
773 }
774 case VIDIOC_G_FMT:
775 {
776 struct v4l2_format *f = arg;
777
778 memset(f,0,sizeof(*f));
779 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
780 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
781 f->fmt.pix.bytesperline = 0;
782 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */
783 f->fmt.pix.colorspace = 0;
784 f->fmt.pix.width = dev->width;
785 f->fmt.pix.height = dev->height;
786 f->fmt.pix.field = fh->mpegq.field;
787 dprintk(0,"VIDIOC_G_FMT: w: %d, h: %d, f: %d\n",
788 dev->width, dev->height, fh->mpegq.field );
789 return 0;
790 }
791 case VIDIOC_TRY_FMT:
792 {
793 struct v4l2_format *f = arg;
794
795 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
796 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
797 f->fmt.pix.bytesperline = 0;
798 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */;
799 f->fmt.pix.colorspace = 0;
800 dprintk(0,"VIDIOC_TRY_FMT: w: %d, h: %d, f: %d\n",
801 dev->width, dev->height, fh->mpegq.field );
802 return 0;
803 }
804 case VIDIOC_S_FMT:
805 {
806 struct v4l2_format *f = arg;
807
808 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
809 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
810 f->fmt.pix.bytesperline = 0;
811 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */;
812 f->fmt.pix.colorspace = 0;
813 dprintk(0,"VIDIOC_S_FMT: w: %d, h: %d, f: %d\n",
814 f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field );
815 return 0;
816 }
817 834
818 /* --- streaming capture ------------------------------------- */ 835static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *p)
819 case VIDIOC_REQBUFS: 836{
820 return videobuf_reqbufs(&fh->mpegq, arg); 837 struct cx8802_fh *fh = priv;
838 return (videobuf_qbuf(&fh->mpegq, p));
839}
821 840
822 case VIDIOC_QUERYBUF: 841static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p)
823 return videobuf_querybuf(&fh->mpegq, arg); 842{
843 struct cx8802_fh *fh = priv;
844 return (videobuf_dqbuf(&fh->mpegq, p,
845 file->f_flags & O_NONBLOCK));
846}
824 847
825 case VIDIOC_QBUF: 848static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
826 return videobuf_qbuf(&fh->mpegq, arg); 849{
850 struct cx8802_fh *fh = priv;
851 return videobuf_streamon(&fh->mpegq);
852}
827 853
828 case VIDIOC_DQBUF: 854static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
829 return videobuf_dqbuf(&fh->mpegq, arg, 855{
830 file->f_flags & O_NONBLOCK); 856 struct cx8802_fh *fh = priv;
857 return videobuf_streamoff(&fh->mpegq);
858}
831 859
832 case VIDIOC_STREAMON: 860static int vidioc_g_mpegcomp (struct file *file, void *fh,
833 return videobuf_streamon(&fh->mpegq); 861 struct v4l2_mpeg_compression *f)
862{
863 printk(KERN_WARNING "VIDIOC_G_MPEGCOMP is obsolete. "
864 "Replace with VIDIOC_G_EXT_CTRLS!");
865 memcpy(f,&default_mpeg_params,sizeof(*f));
866 return 0;
867}
834 868
835 case VIDIOC_STREAMOFF: 869static int vidioc_s_mpegcomp (struct file *file, void *fh,
836 return videobuf_streamoff(&fh->mpegq); 870 struct v4l2_mpeg_compression *f)
871{
872 printk(KERN_WARNING "VIDIOC_S_MPEGCOMP is obsolete. "
873 "Replace with VIDIOC_S_EXT_CTRLS!");
874 return 0;
875}
837 876
838 /* --- mpeg compression -------------------------------------- */ 877static int vidioc_g_ext_ctrls (struct file *file, void *priv,
839 case VIDIOC_G_MPEGCOMP: 878 struct v4l2_ext_controls *f)
840 { 879{
841 struct v4l2_mpeg_compression *f = arg; 880 struct cx8802_dev *dev = ((struct cx8802_fh *)priv)->dev;
842 881
843 printk(KERN_WARNING "VIDIOC_G_MPEGCOMP is obsolete. " 882 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
844 "Replace with VIDIOC_G_EXT_CTRLS!"); 883 return -EINVAL;
845 memcpy(f,&default_mpeg_params,sizeof(*f)); 884 return cx2341x_ext_ctrls(&dev->params, f, VIDIOC_G_EXT_CTRLS);
846 return 0; 885}
847 }
848 case VIDIOC_S_MPEGCOMP:
849 printk(KERN_WARNING "VIDIOC_S_MPEGCOMP is obsolete. "
850 "Replace with VIDIOC_S_EXT_CTRLS!");
851 return 0;
852 case VIDIOC_G_EXT_CTRLS:
853 {
854 struct v4l2_ext_controls *f = arg;
855 886
856 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG) 887static int vidioc_s_ext_ctrls (struct file *file, void *priv,
857 return -EINVAL; 888 struct v4l2_ext_controls *f)
858 return cx2341x_ext_ctrls(&dev->params, f, cmd); 889{
859 } 890 struct cx8802_dev *dev = ((struct cx8802_fh *)priv)->dev;
860 case VIDIOC_S_EXT_CTRLS: 891 struct cx2341x_mpeg_params p;
861 case VIDIOC_TRY_EXT_CTRLS: 892 int err;
862 { 893
863 struct v4l2_ext_controls *f = arg; 894 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
864 struct cx2341x_mpeg_params p; 895 return -EINVAL;
865 int err; 896 p = dev->params;
866 897 err = cx2341x_ext_ctrls(&p, f, VIDIOC_S_EXT_CTRLS);
867 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG) 898 if (!err) {
868 return -EINVAL; 899 err = cx2341x_update(dev, blackbird_mbox_func, &dev->params, &p);
869 p = dev->params; 900 dev->params = p;
870 err = cx2341x_ext_ctrls(&p, f, cmd);
871 if (err == 0 && cmd == VIDIOC_S_EXT_CTRLS) {
872 err = cx2341x_update(dev, blackbird_mbox_func, &dev->params, &p);
873 dev->params = p;
874 }
875 return err;
876 }
877 case VIDIOC_S_FREQUENCY:
878 {
879 blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
880 BLACKBIRD_END_NOW,
881 BLACKBIRD_MPEG_CAPTURE,
882 BLACKBIRD_RAW_BITS_NONE);
883
884 cx88_do_ioctl(inode, file, 0, dev->core, cmd, arg, cx88_ioctl_hook);
885
886 blackbird_initialize_codec(dev);
887 cx88_set_scale(dev->core, dev->width, dev->height,
888 fh->mpegq.field);
889 return 0;
890 } 901 }
891 case VIDIOC_LOG_STATUS: 902 return err;
892 { 903}
893 char name[32 + 2]; 904
894 905static int vidioc_try_ext_ctrls (struct file *file, void *priv,
895 snprintf(name, sizeof(name), "%s/2", core->name); 906 struct v4l2_ext_controls *f)
896 printk("%s/2: ============ START LOG STATUS ============\n", 907{
897 core->name); 908 struct cx8802_dev *dev = ((struct cx8802_fh *)priv)->dev;
898 cx88_call_i2c_clients(core, VIDIOC_LOG_STATUS, NULL); 909 struct cx2341x_mpeg_params p;
899 cx2341x_log_status(&dev->params, name); 910 int err;
900 printk("%s/2: ============= END LOG STATUS =============\n", 911
901 core->name); 912 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
913 return -EINVAL;
914 p = dev->params;
915 err = cx2341x_ext_ctrls(&p, f, VIDIOC_TRY_EXT_CTRLS);
916
917 return err;
918}
919
920static int vidioc_s_frequency (struct file *file, void *priv,
921 struct v4l2_frequency *f)
922{
923 struct cx8802_fh *fh = priv;
924 struct cx8802_dev *dev = fh->dev;
925 struct cx88_core *core = dev->core;
926
927 blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
928 BLACKBIRD_END_NOW,
929 BLACKBIRD_MPEG_CAPTURE,
930 BLACKBIRD_RAW_BITS_NONE);
931 cx88_set_freq (core,f);
932 blackbird_initialize_codec(dev);
933 cx88_set_scale(dev->core, dev->width, dev->height,
934 fh->mpegq.field);
935 return 0;
936}
937
938static int vidioc_log_status (struct file *file, void *priv)
939{
940 struct cx8802_dev *dev = ((struct cx8802_fh *)priv)->dev;
941 struct cx88_core *core = dev->core;
942 char name[32 + 2];
943
944 snprintf(name, sizeof(name), "%s/2", core->name);
945 printk("%s/2: ============ START LOG STATUS ============\n",
946 core->name);
947 cx88_call_i2c_clients(core, VIDIOC_LOG_STATUS, NULL);
948 cx2341x_log_status(&dev->params, name);
949 printk("%s/2: ============= END LOG STATUS =============\n",
950 core->name);
951 return 0;
952}
953
954static int vidioc_queryctrl (struct file *file, void *priv,
955 struct v4l2_queryctrl *qctrl)
956{
957 struct cx8802_dev *dev = ((struct cx8802_fh *)priv)->dev;
958
959 if (blackbird_queryctrl(dev, qctrl) == 0)
902 return 0; 960 return 0;
903 }
904 case VIDIOC_QUERYMENU:
905 return blackbird_querymenu(dev, arg);
906 case VIDIOC_QUERYCTRL:
907 {
908 struct v4l2_queryctrl *c = arg;
909 961
910 if (blackbird_queryctrl(dev, c) == 0) 962 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
911 return 0; 963 if (unlikely(qctrl->id == 0))
912 return cx88_do_ioctl(inode, file, 0, dev->core, cmd, arg, mpeg_do_ioctl); 964 return -EINVAL;
913 } 965 return cx8800_ctrl_query(qctrl);
966}
914 967
915 default: 968static int vidioc_enum_input (struct file *file, void *priv,
916 return cx88_do_ioctl(inode, file, 0, dev->core, cmd, arg, cx88_ioctl_hook); 969 struct v4l2_input *i)
917 } 970{
971 struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core;
972 return cx88_enum_input (core,i);
973}
974
975static int vidioc_g_ctrl (struct file *file, void *priv,
976 struct v4l2_control *ctl)
977{
978 struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core;
979 return
980 cx88_get_control(core,ctl);
981}
982
983static int vidioc_s_ctrl (struct file *file, void *priv,
984 struct v4l2_control *ctl)
985{
986 struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core;
987 return
988 cx88_set_control(core,ctl);
989}
990
991static int vidioc_g_frequency (struct file *file, void *priv,
992 struct v4l2_frequency *f)
993{
994 struct cx8802_fh *fh = priv;
995 struct cx88_core *core = fh->dev->core;
996
997 if (unlikely(UNSET == core->tuner_type))
998 return -EINVAL;
999
1000 f->type = V4L2_TUNER_ANALOG_TV;
1001 f->frequency = core->freq;
1002 cx88_call_i2c_clients(core,VIDIOC_G_FREQUENCY,f);
1003
1004 return 0;
1005}
1006
1007static int vidioc_g_input (struct file *file, void *priv, unsigned int *i)
1008{
1009 struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core;
1010
1011 *i = core->input;
1012 return 0;
1013}
1014
1015static int vidioc_s_input (struct file *file, void *priv, unsigned int i)
1016{
1017 struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core;
1018
1019 if (i >= 4)
1020 return -EINVAL;
1021
1022 mutex_lock(&core->lock);
1023 cx88_newstation(core);
1024 cx88_video_mux(core,i);
1025 mutex_unlock(&core->lock);
918 return 0; 1026 return 0;
919} 1027}
920 1028
921int (*cx88_ioctl_hook)(struct inode *inode, struct file *file, 1029static int vidioc_g_tuner (struct file *file, void *priv,
922 unsigned int cmd, void *arg); 1030 struct v4l2_tuner *t)
923unsigned int (*cx88_ioctl_translator)(unsigned int cmd); 1031{
1032 struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core;
1033 u32 reg;
1034
1035 if (unlikely(UNSET == core->tuner_type))
1036 return -EINVAL;
1037
1038 strcpy(t->name, "Television");
1039 t->type = V4L2_TUNER_ANALOG_TV;
1040 t->capability = V4L2_TUNER_CAP_NORM;
1041 t->rangehigh = 0xffffffffUL;
1042
1043 cx88_get_stereo(core ,t);
1044 reg = cx_read(MO_DEVICE_STATUS);
1045 t->signal = (reg & (1<<5)) ? 0xffff : 0x0000;
1046 return 0;
1047}
924 1048
925static unsigned int mpeg_translate_ioctl(unsigned int cmd) 1049static int vidioc_s_tuner (struct file *file, void *priv,
1050 struct v4l2_tuner *t)
926{ 1051{
927 return cmd; 1052 struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core;
1053
1054 if (UNSET == core->tuner_type)
1055 return -EINVAL;
1056 if (0 != t->index)
1057 return -EINVAL;
1058
1059 cx88_set_stereo(core, t->audmode, 1);
1060 return 0;
928} 1061}
929 1062
930static int mpeg_ioctl(struct inode *inode, struct file *file, 1063static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *id)
931 unsigned int cmd, unsigned long arg)
932{ 1064{
933 cmd = cx88_ioctl_translator( cmd ); 1065 struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core;
934 return video_usercopy(inode, file, cmd, arg, cx88_ioctl_hook); 1066
1067 mutex_lock(&core->lock);
1068 cx88_set_tvnorm(core,*id);
1069 mutex_unlock(&core->lock);
1070 return 0;
935} 1071}
936 1072
1073/* FIXME: cx88_ioctl_hook not implemented */
1074
937static int mpeg_open(struct inode *inode, struct file *file) 1075static int mpeg_open(struct inode *inode, struct file *file)
938{ 1076{
939 int minor = iminor(inode); 1077 int minor = iminor(inode);
@@ -1059,17 +1197,47 @@ static const struct file_operations mpeg_fops =
1059 .read = mpeg_read, 1197 .read = mpeg_read,
1060 .poll = mpeg_poll, 1198 .poll = mpeg_poll,
1061 .mmap = mpeg_mmap, 1199 .mmap = mpeg_mmap,
1062 .ioctl = mpeg_ioctl, 1200 .ioctl = video_ioctl2,
1063 .llseek = no_llseek, 1201 .llseek = no_llseek,
1064}; 1202};
1065 1203
1066static struct video_device cx8802_mpeg_template = 1204static struct video_device cx8802_mpeg_template =
1067{ 1205{
1068 .name = "cx8802", 1206 .name = "cx8802",
1069 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES|VID_TYPE_MPEG_ENCODER, 1207 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES|VID_TYPE_MPEG_ENCODER,
1070 .hardware = 0, 1208 .fops = &mpeg_fops,
1071 .fops = &mpeg_fops, 1209 .minor = -1,
1072 .minor = -1, 1210 .vidioc_querymenu = vidioc_querymenu,
1211 .vidioc_querycap = vidioc_querycap,
1212 .vidioc_enum_fmt_cap = vidioc_enum_fmt_cap,
1213 .vidioc_g_fmt_cap = vidioc_g_fmt_cap,
1214 .vidioc_try_fmt_cap = vidioc_try_fmt_cap,
1215 .vidioc_s_fmt_cap = vidioc_s_fmt_cap,
1216 .vidioc_reqbufs = vidioc_reqbufs,
1217 .vidioc_querybuf = vidioc_querybuf,
1218 .vidioc_qbuf = vidioc_qbuf,
1219 .vidioc_dqbuf = vidioc_dqbuf,
1220 .vidioc_streamon = vidioc_streamon,
1221 .vidioc_streamoff = vidioc_streamoff,
1222 .vidioc_g_mpegcomp = vidioc_g_mpegcomp,
1223 .vidioc_s_mpegcomp = vidioc_s_mpegcomp,
1224 .vidioc_g_ext_ctrls = vidioc_g_ext_ctrls,
1225 .vidioc_s_ext_ctrls = vidioc_s_ext_ctrls,
1226 .vidioc_try_ext_ctrls = vidioc_try_ext_ctrls,
1227 .vidioc_s_frequency = vidioc_s_frequency,
1228 .vidioc_log_status = vidioc_log_status,
1229 .vidioc_queryctrl = vidioc_queryctrl,
1230 .vidioc_enum_input = vidioc_enum_input,
1231 .vidioc_g_ctrl = vidioc_g_ctrl,
1232 .vidioc_s_ctrl = vidioc_s_ctrl,
1233 .vidioc_g_frequency = vidioc_g_frequency,
1234 .vidioc_g_input = vidioc_g_input,
1235 .vidioc_s_input = vidioc_s_input,
1236 .vidioc_g_tuner = vidioc_g_tuner,
1237 .vidioc_s_tuner = vidioc_s_tuner,
1238 .vidioc_s_std = vidioc_s_std,
1239 .tvnorms = CX88_NORMS,
1240 .current_norm = V4L2_STD_NTSC_M,
1073}; 1241};
1074 1242
1075/* ------------------------------------------------------------------ */ 1243/* ------------------------------------------------------------------ */
@@ -1164,7 +1332,9 @@ static int cx8802_blackbird_probe(struct cx8802_driver *drv)
1164 cx2341x_fill_defaults(&dev->params); 1332 cx2341x_fill_defaults(&dev->params);
1165 dev->params.port = CX2341X_PORT_STREAMING; 1333 dev->params.port = CX2341X_PORT_STREAMING;
1166 1334
1167 if (core->tvnorm->id & V4L2_STD_525_60) { 1335 cx8802_mpeg_template.current_norm = core->tvnorm;
1336
1337 if (core->tvnorm & V4L2_STD_525_60) {
1168 dev->height = 480; 1338 dev->height = 480;
1169 } else { 1339 } else {
1170 dev->height = 576; 1340 dev->height = 576;
@@ -1178,6 +1348,11 @@ static int cx8802_blackbird_probe(struct cx8802_driver *drv)
1178 blackbird_register_video(dev); 1348 blackbird_register_video(dev);
1179 1349
1180 /* initial device configuration: needed ? */ 1350 /* initial device configuration: needed ? */
1351 mutex_lock(&dev->core->lock);
1352// init_controls(core);
1353 cx88_set_tvnorm(core,core->tvnorm);
1354 cx88_video_mux(core,0);
1355 mutex_unlock(&dev->core->lock);
1181 1356
1182 return 0; 1357 return 0;
1183 1358
@@ -1212,8 +1387,6 @@ static int blackbird_init(void)
1212 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n", 1387 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
1213 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100); 1388 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
1214#endif 1389#endif
1215 cx88_ioctl_hook = mpeg_do_ioctl;
1216 cx88_ioctl_translator = mpeg_translate_ioctl;
1217 return cx8802_register_driver(&cx8802_blackbird_driver); 1390 return cx8802_register_driver(&cx8802_blackbird_driver);
1218} 1391}
1219 1392
@@ -1225,8 +1398,8 @@ static void blackbird_fini(void)
1225module_init(blackbird_init); 1398module_init(blackbird_init);
1226module_exit(blackbird_fini); 1399module_exit(blackbird_fini);
1227 1400
1228EXPORT_SYMBOL(cx88_ioctl_hook); 1401module_param_named(video_debug,cx8802_mpeg_template.debug, int, 0644);
1229EXPORT_SYMBOL(cx88_ioctl_translator); 1402MODULE_PARM_DESC(debug,"enable debug messages [video]");
1230 1403
1231/* ----------------------------------------------------------- */ 1404/* ----------------------------------------------------------- */
1232/* 1405/*
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index 434b78ab37..65e9d8096b 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -764,6 +764,12 @@ struct cx88_board cx88_boards[] = {
764 .input = {{ 764 .input = {{
765 .type = CX88_VMUX_DVB, 765 .type = CX88_VMUX_DVB,
766 .vmux = 0, 766 .vmux = 0,
767 },{
768 .type = CX88_VMUX_COMPOSITE1,
769 .vmux = 2,
770 },{
771 .type = CX88_VMUX_SVIDEO,
772 .vmux = 2,
767 }}, 773 }},
768 .mpeg = CX88_MPEG_DVB, 774 .mpeg = CX88_MPEG_DVB,
769 }, 775 },
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index 18997361c7..d86813be56 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -5,6 +5,11 @@
5 * 5 *
6 * (c) 2003 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] 6 * (c) 2003 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
7 * 7 *
8 * (c) 2005-2006 Mauro Carvalho Chehab <mchehab@infradead.org>
9 * - Multituner support
10 * - video_ioctl2 conversion
11 * - PAL/M fixes
12 *
8 * 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
9 * 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
10 * the Free Software Foundation; either version 2 of the License, or 15 * the Free Software Foundation; either version 2 of the License, or
@@ -631,30 +636,30 @@ int cx88_reset(struct cx88_core *core)
631 636
632/* ------------------------------------------------------------------ */ 637/* ------------------------------------------------------------------ */
633 638
634static unsigned int inline norm_swidth(struct cx88_tvnorm *norm) 639static unsigned int inline norm_swidth(v4l2_std_id norm)
635{ 640{
636 return (norm->id & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 754 : 922; 641 return (norm & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 754 : 922;
637} 642}
638 643
639static unsigned int inline norm_hdelay(struct cx88_tvnorm *norm) 644static unsigned int inline norm_hdelay(v4l2_std_id norm)
640{ 645{
641 return (norm->id & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 135 : 186; 646 return (norm & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 135 : 186;
642} 647}
643 648
644static unsigned int inline norm_vdelay(struct cx88_tvnorm *norm) 649static unsigned int inline norm_vdelay(v4l2_std_id norm)
645{ 650{
646 return (norm->id & V4L2_STD_625_50) ? 0x24 : 0x18; 651 return (norm & V4L2_STD_625_50) ? 0x24 : 0x18;
647} 652}
648 653
649static unsigned int inline norm_fsc8(struct cx88_tvnorm *norm) 654static unsigned int inline norm_fsc8(v4l2_std_id norm)
650{ 655{
651 if (norm->id & V4L2_STD_PAL_M) 656 if (norm & V4L2_STD_PAL_M)
652 return 28604892; // 3.575611 MHz 657 return 28604892; // 3.575611 MHz
653 658
654 if (norm->id & (V4L2_STD_PAL_Nc)) 659 if (norm & (V4L2_STD_PAL_Nc))
655 return 28656448; // 3.582056 MHz 660 return 28656448; // 3.582056 MHz
656 661
657 if (norm->id & V4L2_STD_NTSC) // All NTSC/M and variants 662 if (norm & V4L2_STD_NTSC) // All NTSC/M and variants
658 return 28636360; // 3.57954545 MHz +/- 10 Hz 663 return 28636360; // 3.57954545 MHz +/- 10 Hz
659 664
660 /* SECAM have also different sub carrier for chroma, 665 /* SECAM have also different sub carrier for chroma,
@@ -666,20 +671,20 @@ static unsigned int inline norm_fsc8(struct cx88_tvnorm *norm)
666 return 35468950; // 4.43361875 MHz +/- 5 Hz 671 return 35468950; // 4.43361875 MHz +/- 5 Hz
667} 672}
668 673
669static unsigned int inline norm_htotal(struct cx88_tvnorm *norm) 674static unsigned int inline norm_htotal(v4l2_std_id norm)
670{ 675{
671 676
672 unsigned int fsc4=norm_fsc8(norm)/2; 677 unsigned int fsc4=norm_fsc8(norm)/2;
673 678
674 /* returns 4*FSC / vtotal / frames per seconds */ 679 /* returns 4*FSC / vtotal / frames per seconds */
675 return (norm->id & V4L2_STD_625_50) ? 680 return (norm & V4L2_STD_625_50) ?
676 ((fsc4+312)/625+12)/25 : 681 ((fsc4+312)/625+12)/25 :
677 ((fsc4+262)/525*1001+15000)/30000; 682 ((fsc4+262)/525*1001+15000)/30000;
678} 683}
679 684
680static unsigned int inline norm_vbipack(struct cx88_tvnorm *norm) 685static unsigned int inline norm_vbipack(v4l2_std_id norm)
681{ 686{
682 return (norm->id & V4L2_STD_625_50) ? 511 : 400; 687 return (norm & V4L2_STD_625_50) ? 511 : 400;
683} 688}
684 689
685int cx88_set_scale(struct cx88_core *core, unsigned int width, unsigned int height, 690int cx88_set_scale(struct cx88_core *core, unsigned int width, unsigned int height,
@@ -692,7 +697,7 @@ int cx88_set_scale(struct cx88_core *core, unsigned int width, unsigned int heig
692 dprintk(1,"set_scale: %dx%d [%s%s,%s]\n", width, height, 697 dprintk(1,"set_scale: %dx%d [%s%s,%s]\n", width, height,
693 V4L2_FIELD_HAS_TOP(field) ? "T" : "", 698 V4L2_FIELD_HAS_TOP(field) ? "T" : "",
694 V4L2_FIELD_HAS_BOTTOM(field) ? "B" : "", 699 V4L2_FIELD_HAS_BOTTOM(field) ? "B" : "",
695 core->tvnorm->name); 700 v4l2_norm_to_name(core->tvnorm));
696 if (!V4L2_FIELD_HAS_BOTH(field)) 701 if (!V4L2_FIELD_HAS_BOTH(field))
697 height *= 2; 702 height *= 2;
698 703
@@ -729,7 +734,7 @@ int cx88_set_scale(struct cx88_core *core, unsigned int width, unsigned int heig
729 // setup filters 734 // setup filters
730 value = 0; 735 value = 0;
731 value |= (1 << 19); // CFILT (default) 736 value |= (1 << 19); // CFILT (default)
732 if (core->tvnorm->id & V4L2_STD_SECAM) { 737 if (core->tvnorm & V4L2_STD_SECAM) {
733 value |= (1 << 15); 738 value |= (1 << 15);
734 value |= (1 << 16); 739 value |= (1 << 16);
735 } 740 }
@@ -826,36 +831,36 @@ int cx88_stop_audio_dma(struct cx88_core *core)
826 831
827static int set_tvaudio(struct cx88_core *core) 832static int set_tvaudio(struct cx88_core *core)
828{ 833{
829 struct cx88_tvnorm *norm = core->tvnorm; 834 v4l2_std_id norm = core->tvnorm;
830 835
831 if (CX88_VMUX_TELEVISION != INPUT(core->input)->type) 836 if (CX88_VMUX_TELEVISION != INPUT(core->input)->type)
832 return 0; 837 return 0;
833 838
834 if (V4L2_STD_PAL_BG & norm->id) { 839 if (V4L2_STD_PAL_BG & norm) {
835 core->tvaudio = WW_BG; 840 core->tvaudio = WW_BG;
836 841
837 } else if (V4L2_STD_PAL_DK & norm->id) { 842 } else if (V4L2_STD_PAL_DK & norm) {
838 core->tvaudio = WW_DK; 843 core->tvaudio = WW_DK;
839 844
840 } else if (V4L2_STD_PAL_I & norm->id) { 845 } else if (V4L2_STD_PAL_I & norm) {
841 core->tvaudio = WW_I; 846 core->tvaudio = WW_I;
842 847
843 } else if (V4L2_STD_SECAM_L & norm->id) { 848 } else if (V4L2_STD_SECAM_L & norm) {
844 core->tvaudio = WW_L; 849 core->tvaudio = WW_L;
845 850
846 } else if (V4L2_STD_SECAM_DK & norm->id) { 851 } else if (V4L2_STD_SECAM_DK & norm) {
847 core->tvaudio = WW_DK; 852 core->tvaudio = WW_DK;
848 853
849 } else if ((V4L2_STD_NTSC_M & norm->id) || 854 } else if ((V4L2_STD_NTSC_M & norm) ||
850 (V4L2_STD_PAL_M & norm->id)) { 855 (V4L2_STD_PAL_M & norm)) {
851 core->tvaudio = WW_BTSC; 856 core->tvaudio = WW_BTSC;
852 857
853 } else if (V4L2_STD_NTSC_M_JP & norm->id) { 858 } else if (V4L2_STD_NTSC_M_JP & norm) {
854 core->tvaudio = WW_EIAJ; 859 core->tvaudio = WW_EIAJ;
855 860
856 } else { 861 } else {
857 printk("%s/0: tvaudio support needs work for this tv norm [%s], sorry\n", 862 printk("%s/0: tvaudio support needs work for this tv norm [%s], sorry\n",
858 core->name, norm->name); 863 core->name, v4l2_norm_to_name(core->tvnorm));
859 core->tvaudio = 0; 864 core->tvaudio = 0;
860 return 0; 865 return 0;
861 } 866 }
@@ -874,7 +879,7 @@ static int set_tvaudio(struct cx88_core *core)
874 879
875 880
876 881
877int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm) 882int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm)
878{ 883{
879 u32 fsc8; 884 u32 fsc8;
880 u32 adc_clock; 885 u32 adc_clock;
@@ -882,6 +887,7 @@ int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm)
882 u32 step_db,step_dr; 887 u32 step_db,step_dr;
883 u64 tmp64; 888 u64 tmp64;
884 u32 bdelay,agcdelay,htotal; 889 u32 bdelay,agcdelay,htotal;
890 u32 cxiformat, cxoformat;
885 891
886 core->tvnorm = norm; 892 core->tvnorm = norm;
887 fsc8 = norm_fsc8(norm); 893 fsc8 = norm_fsc8(norm);
@@ -890,23 +896,51 @@ int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm)
890 step_db = fsc8; 896 step_db = fsc8;
891 step_dr = fsc8; 897 step_dr = fsc8;
892 898
893 if (norm->id & V4L2_STD_SECAM) { 899 if (norm & V4L2_STD_NTSC_M_JP) {
900 cxiformat = VideoFormatNTSCJapan;
901 cxoformat = 0x181f0008;
902 } else if (norm & V4L2_STD_NTSC_443) {
903 cxiformat = VideoFormatNTSC443;
904 cxoformat = 0x181f0008;
905 } else if (norm & V4L2_STD_PAL_M) {
906 cxiformat = VideoFormatPALM;
907 cxoformat = 0x1c1f0008;
908 } else if (norm & V4L2_STD_PAL_N) {
909 cxiformat = VideoFormatPALN;
910 cxoformat = 0x1c1f0008;
911 } else if (norm & V4L2_STD_PAL_Nc) {
912 cxiformat = VideoFormatPALNC;
913 cxoformat = 0x1c1f0008;
914 } else if (norm & V4L2_STD_PAL_60) {
915 cxiformat = VideoFormatPAL60;
916 cxoformat = 0x181f0008;
917 } else if (norm & V4L2_STD_NTSC) {
918 cxiformat = VideoFormatNTSC;
919 cxoformat = 0x181f0008;
920 } else if (norm & V4L2_STD_SECAM) {
894 step_db = 4250000 * 8; 921 step_db = 4250000 * 8;
895 step_dr = 4406250 * 8; 922 step_dr = 4406250 * 8;
923
924 cxiformat = VideoFormatSECAM;
925 cxoformat = 0x181f0008;
926 } else { /* PAL */
927 cxiformat = VideoFormatPAL;
928 cxoformat = 0x181f0008;
896 } 929 }
897 930
898 dprintk(1,"set_tvnorm: \"%s\" fsc8=%d adc=%d vdec=%d db/dr=%d/%d\n", 931 dprintk(1,"set_tvnorm: \"%s\" fsc8=%d adc=%d vdec=%d db/dr=%d/%d\n",
899 norm->name, fsc8, adc_clock, vdec_clock, step_db, step_dr); 932 v4l2_norm_to_name(core->tvnorm), fsc8, adc_clock, vdec_clock,
933 step_db, step_dr);
900 set_pll(core,2,vdec_clock); 934 set_pll(core,2,vdec_clock);
901 935
902 dprintk(1,"set_tvnorm: MO_INPUT_FORMAT 0x%08x [old=0x%08x]\n", 936 dprintk(1,"set_tvnorm: MO_INPUT_FORMAT 0x%08x [old=0x%08x]\n",
903 norm->cxiformat, cx_read(MO_INPUT_FORMAT) & 0x0f); 937 cxiformat, cx_read(MO_INPUT_FORMAT) & 0x0f);
904 cx_andor(MO_INPUT_FORMAT, 0xf, norm->cxiformat); 938 cx_andor(MO_INPUT_FORMAT, 0xf, cxiformat);
905 939
906 // FIXME: as-is from DScaler 940 // FIXME: as-is from DScaler
907 dprintk(1,"set_tvnorm: MO_OUTPUT_FORMAT 0x%08x [old=0x%08x]\n", 941 dprintk(1,"set_tvnorm: MO_OUTPUT_FORMAT 0x%08x [old=0x%08x]\n",
908 norm->cxoformat, cx_read(MO_OUTPUT_FORMAT)); 942 cxoformat, cx_read(MO_OUTPUT_FORMAT));
909 cx_write(MO_OUTPUT_FORMAT, norm->cxoformat); 943 cx_write(MO_OUTPUT_FORMAT, cxoformat);
910 944
911 // MO_SCONV_REG = adc clock / video dec clock * 2^17 945 // MO_SCONV_REG = adc clock / video dec clock * 2^17
912 tmp64 = adc_clock * (u64)(1 << 17); 946 tmp64 = adc_clock * (u64)(1 << 17);
@@ -955,7 +989,7 @@ int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm)
955 set_tvaudio(core); 989 set_tvaudio(core);
956 990
957 // tell i2c chips 991 // tell i2c chips
958 cx88_call_i2c_clients(core,VIDIOC_S_STD,&norm->id); 992 cx88_call_i2c_clients(core,VIDIOC_S_STD,&norm);
959 993
960 // done 994 // done
961 return 0; 995 return 0;
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index 8b203354fc..4f55602857 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -35,7 +35,7 @@
35 35
36#include "mt352.h" 36#include "mt352.h"
37#include "mt352_priv.h" 37#include "mt352_priv.h"
38#ifdef HAVE_VP3054_I2C 38#if defined(CONFIG_VIDEO_CX88_VP3054) || defined(CONFIG_VIDEO_CX88_VP3054_MODULE)
39# include "cx88-vp3054-i2c.h" 39# include "cx88-vp3054-i2c.h"
40#endif 40#endif
41#include "zl10353.h" 41#include "zl10353.h"
@@ -200,7 +200,7 @@ static struct mt352_config dvico_fusionhdtv_dual = {
200 .demod_init = dvico_dual_demod_init, 200 .demod_init = dvico_dual_demod_init,
201}; 201};
202 202
203#ifdef HAVE_VP3054_I2C 203#if defined(CONFIG_VIDEO_CX88_VP3054) || defined(CONFIG_VIDEO_CX88_VP3054_MODULE)
204static int dntv_live_dvbt_pro_demod_init(struct dvb_frontend* fe) 204static int dntv_live_dvbt_pro_demod_init(struct dvb_frontend* fe)
205{ 205{
206 static u8 clock_config [] = { 0x89, 0x38, 0x38 }; 206 static u8 clock_config [] = { 0x89, 0x38, 0x38 };
@@ -543,7 +543,7 @@ static int dvb_register(struct cx8802_dev *dev)
543 } 543 }
544 break; 544 break;
545 case CX88_BOARD_DNTV_LIVE_DVB_T_PRO: 545 case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
546#ifdef HAVE_VP3054_I2C 546#if defined(CONFIG_VIDEO_CX88_VP3054) || defined(CONFIG_VIDEO_CX88_VP3054_MODULE)
547 dev->core->pll_addr = 0x61; 547 dev->core->pll_addr = 0x61;
548 dev->core->pll_desc = &dvb_pll_fmd1216me; 548 dev->core->pll_desc = &dvb_pll_fmd1216me;
549 dev->dvb.frontend = dvb_attach(mt352_attach, &dntv_live_dvbt_pro_config, 549 dev->dvb.frontend = dvb_attach(mt352_attach, &dntv_live_dvbt_pro_config,
@@ -793,7 +793,7 @@ static int cx8802_dvb_probe(struct cx8802_driver *drv)
793 if (!(cx88_boards[core->board].mpeg & CX88_MPEG_DVB)) 793 if (!(cx88_boards[core->board].mpeg & CX88_MPEG_DVB))
794 goto fail_core; 794 goto fail_core;
795 795
796#ifdef HAVE_VP3054_I2C 796#if defined(CONFIG_VIDEO_CX88_VP3054) || defined(CONFIG_VIDEO_CX88_VP3054_MODULE)
797 err = vp3054_i2c_probe(dev); 797 err = vp3054_i2c_probe(dev);
798 if (0 != err) 798 if (0 != err)
799 goto fail_core; 799 goto fail_core;
@@ -822,7 +822,7 @@ static int cx8802_dvb_remove(struct cx8802_driver *drv)
822 /* dvb */ 822 /* dvb */
823 videobuf_dvb_unregister(&dev->dvb); 823 videobuf_dvb_unregister(&dev->dvb);
824 824
825#ifdef HAVE_VP3054_I2C 825#if defined(CONFIG_VIDEO_CX88_VP3054) || defined(CONFIG_VIDEO_CX88_VP3054_MODULE)
826 vp3054_i2c_remove(dev); 826 vp3054_i2c_remove(dev);
827#endif 827#endif
828 828
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index 88af23a938..9830d5c439 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -145,6 +145,7 @@ void cx88_call_i2c_clients(struct cx88_core *core, unsigned int cmd, void *arg)
145 if (0 != core->i2c_rc) 145 if (0 != core->i2c_rc)
146 return; 146 return;
147 147
148#if defined(CONFIG_VIDEO_BUF_DVB) || defined(CONFIG_VIDEO_BUF_DVB_MODULE)
148 if ( (core->dvbdev) && (core->dvbdev->dvb.frontend) ) { 149 if ( (core->dvbdev) && (core->dvbdev->dvb.frontend) ) {
149 if (core->dvbdev->dvb.frontend->ops.i2c_gate_ctrl) 150 if (core->dvbdev->dvb.frontend->ops.i2c_gate_ctrl)
150 core->dvbdev->dvb.frontend->ops.i2c_gate_ctrl(core->dvbdev->dvb.frontend, 1); 151 core->dvbdev->dvb.frontend->ops.i2c_gate_ctrl(core->dvbdev->dvb.frontend, 1);
@@ -154,6 +155,7 @@ void cx88_call_i2c_clients(struct cx88_core *core, unsigned int cmd, void *arg)
154 if (core->dvbdev->dvb.frontend->ops.i2c_gate_ctrl) 155 if (core->dvbdev->dvb.frontend->ops.i2c_gate_ctrl)
155 core->dvbdev->dvb.frontend->ops.i2c_gate_ctrl(core->dvbdev->dvb.frontend, 0); 156 core->dvbdev->dvb.frontend->ops.i2c_gate_ctrl(core->dvbdev->dvb.frontend, 0);
156 } else 157 } else
158#endif
157 i2c_clients_command(&core->i2c_adap, cmd, arg); 159 i2c_clients_command(&core->i2c_adap, cmd, arg);
158} 160}
159 161
diff --git a/drivers/media/video/cx88/cx88-tvaudio.c b/drivers/media/video/cx88/cx88-tvaudio.c
index 063df03dcf..97ef421dd0 100644
--- a/drivers/media/video/cx88/cx88-tvaudio.c
+++ b/drivers/media/video/cx88/cx88-tvaudio.c
@@ -797,55 +797,6 @@ void cx88_get_stereo(struct cx88_core *core, struct v4l2_tuner *t)
797 Add some code here later. 797 Add some code here later.
798*/ 798*/
799 799
800# if 0
801 t->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_SAP |
802 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
803 t->rxsubchans = V4L2_TUNER_SUB_MONO;
804 t->audmode = V4L2_TUNER_MODE_MONO;
805
806 switch (core->tvaudio) {
807 case WW_BTSC:
808 t->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_SAP;
809 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
810 if (1 == pilot) {
811 /* SAP */
812 t->rxsubchans |= V4L2_TUNER_SUB_SAP;
813 }
814 break;
815 case WW_A2_BG:
816 case WW_A2_DK:
817 case WW_A2_M:
818 if (1 == pilot) {
819 /* stereo */
820 t->rxsubchans =
821 V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
822 if (0 == mode)
823 t->audmode = V4L2_TUNER_MODE_STEREO;
824 }
825 if (2 == pilot) {
826 /* dual language -- FIXME */
827 t->rxsubchans =
828 V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
829 t->audmode = V4L2_TUNER_MODE_LANG1;
830 }
831 break;
832 case WW_NICAM_BGDKL:
833 if (0 == mode) {
834 t->audmode = V4L2_TUNER_MODE_STEREO;
835 t->rxsubchans |= V4L2_TUNER_SUB_STEREO;
836 }
837 break;
838 case WW_SYSTEM_L_AM:
839 if (0x0 == mode && !(cx_read(AUD_INIT) & 0x04)) {
840 t->audmode = V4L2_TUNER_MODE_STEREO;
841 t->rxsubchans |= V4L2_TUNER_SUB_STEREO;
842 }
843 break;
844 default:
845 /* nothing */
846 break;
847 }
848# endif
849 return; 800 return;
850} 801}
851 802
diff --git a/drivers/media/video/cx88/cx88-vbi.c b/drivers/media/video/cx88/cx88-vbi.c
index aa2a697700..86c1cf8334 100644
--- a/drivers/media/video/cx88/cx88-vbi.c
+++ b/drivers/media/video/cx88/cx88-vbi.c
@@ -21,9 +21,11 @@ MODULE_PARM_DESC(vbi_debug,"enable debug messages [vbi]");
21 21
22/* ------------------------------------------------------------------ */ 22/* ------------------------------------------------------------------ */
23 23
24void cx8800_vbi_fmt(struct cx8800_dev *dev, struct v4l2_format *f) 24int cx8800_vbi_fmt (struct file *file, void *priv,
25 struct v4l2_format *f)
25{ 26{
26 memset(&f->fmt.vbi,0,sizeof(f->fmt.vbi)); 27 struct cx8800_fh *fh = priv;
28 struct cx8800_dev *dev = fh->dev;
27 29
28 f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH; 30 f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH;
29 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; 31 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
@@ -31,18 +33,19 @@ void cx8800_vbi_fmt(struct cx8800_dev *dev, struct v4l2_format *f)
31 f->fmt.vbi.count[0] = VBI_LINE_COUNT; 33 f->fmt.vbi.count[0] = VBI_LINE_COUNT;
32 f->fmt.vbi.count[1] = VBI_LINE_COUNT; 34 f->fmt.vbi.count[1] = VBI_LINE_COUNT;
33 35
34 if (dev->core->tvnorm->id & V4L2_STD_525_60) { 36 if (dev->core->tvnorm & V4L2_STD_525_60) {
35 /* ntsc */ 37 /* ntsc */
36 f->fmt.vbi.sampling_rate = 28636363; 38 f->fmt.vbi.sampling_rate = 28636363;
37 f->fmt.vbi.start[0] = 10; 39 f->fmt.vbi.start[0] = 10;
38 f->fmt.vbi.start[1] = 273; 40 f->fmt.vbi.start[1] = 273;
39 41
40 } else if (dev->core->tvnorm->id & V4L2_STD_625_50) { 42 } else if (dev->core->tvnorm & V4L2_STD_625_50) {
41 /* pal */ 43 /* pal */
42 f->fmt.vbi.sampling_rate = 35468950; 44 f->fmt.vbi.sampling_rate = 35468950;
43 f->fmt.vbi.start[0] = 7 -1; 45 f->fmt.vbi.start[0] = 7 -1;
44 f->fmt.vbi.start[1] = 319 -1; 46 f->fmt.vbi.start[1] = 319 -1;
45 } 47 }
48 return 0;
46} 49}
47 50
48static int cx8800_start_vbi_dma(struct cx8800_dev *dev, 51static int cx8800_start_vbi_dma(struct cx8800_dev *dev,
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index c86a7e0623..bdfe2af701 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -1,3 +1,4 @@
1
1/* 2/*
2 * 3 *
3 * device driver for Conexant 2388x based TV cards 4 * device driver for Conexant 2388x based TV cards
@@ -5,6 +6,11 @@
5 * 6 *
6 * (c) 2003-04 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] 7 * (c) 2003-04 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
7 * 8 *
9 * (c) 2005-2006 Mauro Carvalho Chehab <mchehab@infradead.org>
10 * - Multituner support
11 * - video_ioctl2 conversion
12 * - PAL/M fixes
13 *
8 * 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
9 * 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
10 * the Free Software Foundation; either version 2 of the License, or 16 * the Free Software Foundation; either version 2 of the License, or
@@ -80,65 +86,6 @@ static LIST_HEAD(cx8800_devlist);
80/* ------------------------------------------------------------------- */ 86/* ------------------------------------------------------------------- */
81/* static data */ 87/* static data */
82 88
83static struct cx88_tvnorm tvnorms[] = {
84 {
85 .name = "NTSC-M",
86 .id = V4L2_STD_NTSC_M,
87 .cxiformat = VideoFormatNTSC,
88 .cxoformat = 0x181f0008,
89 },{
90 .name = "NTSC-JP",
91 .id = V4L2_STD_NTSC_M_JP,
92 .cxiformat = VideoFormatNTSCJapan,
93 .cxoformat = 0x181f0008,
94 },{
95 .name = "PAL-BG",
96 .id = V4L2_STD_PAL_BG,
97 .cxiformat = VideoFormatPAL,
98 .cxoformat = 0x181f0008,
99 },{
100 .name = "PAL-DK",
101 .id = V4L2_STD_PAL_DK,
102 .cxiformat = VideoFormatPAL,
103 .cxoformat = 0x181f0008,
104 },{
105 .name = "PAL-I",
106 .id = V4L2_STD_PAL_I,
107 .cxiformat = VideoFormatPAL,
108 .cxoformat = 0x181f0008,
109 },{
110 .name = "PAL-M",
111 .id = V4L2_STD_PAL_M,
112 .cxiformat = VideoFormatPALM,
113 .cxoformat = 0x1c1f0008,
114 },{
115 .name = "PAL-N",
116 .id = V4L2_STD_PAL_N,
117 .cxiformat = VideoFormatPALN,
118 .cxoformat = 0x1c1f0008,
119 },{
120 .name = "PAL-Nc",
121 .id = V4L2_STD_PAL_Nc,
122 .cxiformat = VideoFormatPALNC,
123 .cxoformat = 0x1c1f0008,
124 },{
125 .name = "PAL-60",
126 .id = V4L2_STD_PAL_60,
127 .cxiformat = VideoFormatPAL60,
128 .cxoformat = 0x181f0008,
129 },{
130 .name = "SECAM-L",
131 .id = V4L2_STD_SECAM_L,
132 .cxiformat = VideoFormatSECAM,
133 .cxoformat = 0x181f0008,
134 },{
135 .name = "SECAM-DK",
136 .id = V4L2_STD_SECAM_DK,
137 .cxiformat = VideoFormatSECAM,
138 .cxoformat = 0x181f0008,
139 }
140};
141
142static struct cx8800_fmt formats[] = { 89static struct cx8800_fmt formats[] = {
143 { 90 {
144 .name = "8 bpp, gray", 91 .name = "8 bpp, gray",
@@ -364,14 +311,6 @@ int cx8800_ctrl_query(struct v4l2_queryctrl *qctrl)
364} 311}
365EXPORT_SYMBOL(cx8800_ctrl_query); 312EXPORT_SYMBOL(cx8800_ctrl_query);
366 313
367static int cx88_queryctrl(struct v4l2_queryctrl *qctrl)
368{
369 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
370 if (qctrl->id == 0)
371 return -EINVAL;
372 return cx8800_ctrl_query(qctrl);
373}
374
375/* ------------------------------------------------------------------- */ 314/* ------------------------------------------------------------------- */
376/* resource management */ 315/* resource management */
377 316
@@ -424,8 +363,7 @@ void res_free(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bits)
424 363
425/* ------------------------------------------------------------------ */ 364/* ------------------------------------------------------------------ */
426 365
427/* static int video_mux(struct cx8800_dev *dev, unsigned int input) */ 366int cx88_video_mux(struct cx88_core *core, unsigned int input)
428static int video_mux(struct cx88_core *core, unsigned int input)
429{ 367{
430 /* struct cx88_core *core = dev->core; */ 368 /* struct cx88_core *core = dev->core; */
431 369
@@ -464,6 +402,7 @@ static int video_mux(struct cx88_core *core, unsigned int input)
464 } 402 }
465 return 0; 403 return 0;
466} 404}
405EXPORT_SYMBOL(cx88_video_mux);
467 406
468/* ------------------------------------------------------------------ */ 407/* ------------------------------------------------------------------ */
469 408
@@ -944,19 +883,18 @@ video_mmap(struct file *file, struct vm_area_struct * vma)
944} 883}
945 884
946/* ------------------------------------------------------------------ */ 885/* ------------------------------------------------------------------ */
886/* VIDEO CTRL IOCTLS */
947 887
948/* static int get_control(struct cx8800_dev *dev, struct v4l2_control *ctl) */ 888int cx88_get_control (struct cx88_core *core, struct v4l2_control *ctl)
949static int get_control(struct cx88_core *core, struct v4l2_control *ctl)
950{ 889{
951 /* struct cx88_core *core = dev->core; */ 890 struct cx88_ctrl *c = NULL;
952 struct cx88_ctrl *c = NULL;
953 u32 value; 891 u32 value;
954 int i; 892 int i;
955 893
956 for (i = 0; i < CX8800_CTLS; i++) 894 for (i = 0; i < CX8800_CTLS; i++)
957 if (cx8800_ctls[i].v.id == ctl->id) 895 if (cx8800_ctls[i].v.id == ctl->id)
958 c = &cx8800_ctls[i]; 896 c = &cx8800_ctls[i];
959 if (NULL == c) 897 if (unlikely(NULL == c))
960 return -EINVAL; 898 return -EINVAL;
961 899
962 value = c->sreg ? cx_sread(c->sreg) : cx_read(c->reg); 900 value = c->sreg ? cx_sread(c->sreg) : cx_read(c->reg);
@@ -977,20 +915,20 @@ static int get_control(struct cx88_core *core, struct v4l2_control *ctl)
977 value,c->mask, c->sreg ? " [shadowed]" : ""); 915 value,c->mask, c->sreg ? " [shadowed]" : "");
978 return 0; 916 return 0;
979} 917}
918EXPORT_SYMBOL(cx88_get_control);
980 919
981/* static int set_control(struct cx8800_dev *dev, struct v4l2_control *ctl) */ 920int cx88_set_control(struct cx88_core *core, struct v4l2_control *ctl)
982static int set_control(struct cx88_core *core, struct v4l2_control *ctl)
983{ 921{
984 /* struct cx88_core *core = dev->core; */
985 struct cx88_ctrl *c = NULL; 922 struct cx88_ctrl *c = NULL;
986 u32 value,mask; 923 u32 value,mask;
987 int i; 924 int i;
925
988 for (i = 0; i < CX8800_CTLS; i++) { 926 for (i = 0; i < CX8800_CTLS; i++) {
989 if (cx8800_ctls[i].v.id == ctl->id) { 927 if (cx8800_ctls[i].v.id == ctl->id) {
990 c = &cx8800_ctls[i]; 928 c = &cx8800_ctls[i];
991 } 929 }
992 } 930 }
993 if (NULL == c) 931 if (unlikely(NULL == c))
994 return -EINVAL; 932 return -EINVAL;
995 933
996 if (ctl->value < c->v.minimum) 934 if (ctl->value < c->v.minimum)
@@ -1010,7 +948,7 @@ static int set_control(struct cx88_core *core, struct v4l2_control *ctl)
1010 948
1011 value = ((ctl->value - c->off) << c->shift) & c->mask; 949 value = ((ctl->value - c->off) << c->shift) & c->mask;
1012 950
1013 if (core->tvnorm->id & V4L2_STD_SECAM) { 951 if (core->tvnorm & V4L2_STD_SECAM) {
1014 /* For SECAM, both U and V sat should be equal */ 952 /* For SECAM, both U and V sat should be equal */
1015 value=value<<8|value; 953 value=value<<8|value;
1016 } else { 954 } else {
@@ -1033,6 +971,7 @@ static int set_control(struct cx88_core *core, struct v4l2_control *ctl)
1033 } 971 }
1034 return 0; 972 return 0;
1035} 973}
974EXPORT_SYMBOL(cx88_set_control);
1036 975
1037static void init_controls(struct cx88_core *core) 976static void init_controls(struct cx88_core *core)
1038{ 977{
@@ -1042,648 +981,531 @@ static void init_controls(struct cx88_core *core)
1042 for (i = 0; i < CX8800_CTLS; i++) { 981 for (i = 0; i < CX8800_CTLS; i++) {
1043 ctrl.id=cx8800_ctls[i].v.id; 982 ctrl.id=cx8800_ctls[i].v.id;
1044 ctrl.value=cx8800_ctls[i].v.default_value; 983 ctrl.value=cx8800_ctls[i].v.default_value;
1045 set_control(core, &ctrl); 984
985 cx88_set_control(core, &ctrl);
1046 } 986 }
1047} 987}
1048 988
1049/* ------------------------------------------------------------------ */ 989/* ------------------------------------------------------------------ */
990/* VIDEO IOCTLS */
1050 991
1051static int cx8800_g_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh, 992static int vidioc_g_fmt_cap (struct file *file, void *priv,
993 struct v4l2_format *f)
994{
995 struct cx8800_fh *fh = priv;
996
997 f->fmt.pix.width = fh->width;
998 f->fmt.pix.height = fh->height;
999 f->fmt.pix.field = fh->vidq.field;
1000 f->fmt.pix.pixelformat = fh->fmt->fourcc;
1001 f->fmt.pix.bytesperline =
1002 (f->fmt.pix.width * fh->fmt->depth) >> 3;
1003 f->fmt.pix.sizeimage =
1004 f->fmt.pix.height * f->fmt.pix.bytesperline;
1005 return 0;
1006}
1007
1008static int vidioc_try_fmt_cap (struct file *file, void *priv,
1052 struct v4l2_format *f) 1009 struct v4l2_format *f)
1053{ 1010{
1054 switch (f->type) { 1011 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1055 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 1012 struct cx8800_fmt *fmt;
1056 memset(&f->fmt.pix,0,sizeof(f->fmt.pix)); 1013 enum v4l2_field field;
1057 f->fmt.pix.width = fh->width; 1014 unsigned int maxw, maxh;
1058 f->fmt.pix.height = fh->height; 1015
1059 f->fmt.pix.field = fh->vidq.field; 1016 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1060 f->fmt.pix.pixelformat = fh->fmt->fourcc; 1017 if (NULL == fmt)
1061 f->fmt.pix.bytesperline = 1018 return -EINVAL;
1062 (f->fmt.pix.width * fh->fmt->depth) >> 3; 1019
1063 f->fmt.pix.sizeimage = 1020 field = f->fmt.pix.field;
1064 f->fmt.pix.height * f->fmt.pix.bytesperline; 1021 maxw = norm_maxw(core->tvnorm);
1065 return 0; 1022 maxh = norm_maxh(core->tvnorm);
1066 case V4L2_BUF_TYPE_VBI_CAPTURE: 1023
1067 cx8800_vbi_fmt(dev, f); 1024 if (V4L2_FIELD_ANY == field) {
1068 return 0; 1025 field = (f->fmt.pix.height > maxh/2)
1026 ? V4L2_FIELD_INTERLACED
1027 : V4L2_FIELD_BOTTOM;
1028 }
1029
1030 switch (field) {
1031 case V4L2_FIELD_TOP:
1032 case V4L2_FIELD_BOTTOM:
1033 maxh = maxh / 2;
1034 break;
1035 case V4L2_FIELD_INTERLACED:
1036 break;
1069 default: 1037 default:
1070 return -EINVAL; 1038 return -EINVAL;
1071 } 1039 }
1040
1041 f->fmt.pix.field = field;
1042 if (f->fmt.pix.height < 32)
1043 f->fmt.pix.height = 32;
1044 if (f->fmt.pix.height > maxh)
1045 f->fmt.pix.height = maxh;
1046 if (f->fmt.pix.width < 48)
1047 f->fmt.pix.width = 48;
1048 if (f->fmt.pix.width > maxw)
1049 f->fmt.pix.width = maxw;
1050 f->fmt.pix.width &= ~0x03;
1051 f->fmt.pix.bytesperline =
1052 (f->fmt.pix.width * fmt->depth) >> 3;
1053 f->fmt.pix.sizeimage =
1054 f->fmt.pix.height * f->fmt.pix.bytesperline;
1055
1056 return 0;
1072} 1057}
1073 1058
1074static int cx8800_try_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh, 1059static int vidioc_s_fmt_cap (struct file *file, void *priv,
1075 struct v4l2_format *f) 1060 struct v4l2_format *f)
1076{ 1061{
1077 struct cx88_core *core = dev->core; 1062 struct cx8800_fh *fh = priv;
1063 int err = vidioc_try_fmt_cap (file,priv,f);
1078 1064
1079 switch (f->type) { 1065 if (0 != err)
1080 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 1066 return err;
1081 { 1067 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1082 struct cx8800_fmt *fmt; 1068 fh->width = f->fmt.pix.width;
1083 enum v4l2_field field; 1069 fh->height = f->fmt.pix.height;
1084 unsigned int maxw, maxh; 1070 fh->vidq.field = f->fmt.pix.field;
1085 1071 return 0;
1086 fmt = format_by_fourcc(f->fmt.pix.pixelformat); 1072}
1087 if (NULL == fmt)
1088 return -EINVAL;
1089
1090 field = f->fmt.pix.field;
1091 maxw = norm_maxw(core->tvnorm);
1092 maxh = norm_maxh(core->tvnorm);
1093
1094 if (V4L2_FIELD_ANY == field) {
1095 field = (f->fmt.pix.height > maxh/2)
1096 ? V4L2_FIELD_INTERLACED
1097 : V4L2_FIELD_BOTTOM;
1098 }
1099 1073
1100 switch (field) { 1074static int vidioc_querycap (struct file *file, void *priv,
1101 case V4L2_FIELD_TOP: 1075 struct v4l2_capability *cap)
1102 case V4L2_FIELD_BOTTOM: 1076{
1103 maxh = maxh / 2; 1077 struct cx8800_dev *dev = ((struct cx8800_fh *)priv)->dev;
1104 break; 1078 struct cx88_core *core = dev->core;
1105 case V4L2_FIELD_INTERLACED:
1106 break;
1107 default:
1108 return -EINVAL;
1109 }
1110 1079
1111 f->fmt.pix.field = field; 1080 strcpy(cap->driver, "cx8800");
1112 if (f->fmt.pix.height < 32) 1081 strlcpy(cap->card, cx88_boards[core->board].name,
1113 f->fmt.pix.height = 32; 1082 sizeof(cap->card));
1114 if (f->fmt.pix.height > maxh) 1083 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
1115 f->fmt.pix.height = maxh; 1084 cap->version = CX88_VERSION_CODE;
1116 if (f->fmt.pix.width < 48) 1085 cap->capabilities =
1117 f->fmt.pix.width = 48; 1086 V4L2_CAP_VIDEO_CAPTURE |
1118 if (f->fmt.pix.width > maxw) 1087 V4L2_CAP_READWRITE |
1119 f->fmt.pix.width = maxw; 1088 V4L2_CAP_STREAMING |
1120 f->fmt.pix.width &= ~0x03; 1089 V4L2_CAP_VBI_CAPTURE;
1121 f->fmt.pix.bytesperline = 1090 if (UNSET != core->tuner_type)
1122 (f->fmt.pix.width * fmt->depth) >> 3; 1091 cap->capabilities |= V4L2_CAP_TUNER;
1123 f->fmt.pix.sizeimage = 1092 return 0;
1124 f->fmt.pix.height * f->fmt.pix.bytesperline; 1093}
1125 1094
1126 return 0; 1095static int vidioc_enum_fmt_cap (struct file *file, void *priv,
1127 } 1096 struct v4l2_fmtdesc *f)
1128 case V4L2_BUF_TYPE_VBI_CAPTURE: 1097{
1129 cx8800_vbi_fmt(dev, f); 1098 if (unlikely(f->index >= ARRAY_SIZE(formats)))
1130 return 0;
1131 default:
1132 return -EINVAL; 1099 return -EINVAL;
1133 } 1100
1101 strlcpy(f->description,formats[f->index].name,sizeof(f->description));
1102 f->pixelformat = formats[f->index].fourcc;
1103
1104 return 0;
1134} 1105}
1135 1106
1136static int cx8800_s_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh, 1107#ifdef CONFIG_VIDEO_V4L1_COMPAT
1137 struct v4l2_format *f) 1108static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf)
1138{ 1109{
1110 struct cx8800_fh *fh = priv;
1111 struct videobuf_queue *q;
1112 struct v4l2_requestbuffers req;
1113 unsigned int i;
1139 int err; 1114 int err;
1140 1115
1141 switch (f->type) { 1116 q = get_queue(fh);
1142 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 1117 memset(&req,0,sizeof(req));
1143 err = cx8800_try_fmt(dev,fh,f); 1118 req.type = q->type;
1144 if (0 != err) 1119 req.count = 8;
1145 return err; 1120 req.memory = V4L2_MEMORY_MMAP;
1121 err = videobuf_reqbufs(q,&req);
1122 if (err < 0)
1123 return err;
1146 1124
1147 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat); 1125 mbuf->frames = req.count;
1148 fh->width = f->fmt.pix.width; 1126 mbuf->size = 0;
1149 fh->height = f->fmt.pix.height; 1127 for (i = 0; i < mbuf->frames; i++) {
1150 fh->vidq.field = f->fmt.pix.field; 1128 mbuf->offsets[i] = q->bufs[i]->boff;
1151 return 0; 1129 mbuf->size += q->bufs[i]->bsize;
1152 case V4L2_BUF_TYPE_VBI_CAPTURE:
1153 cx8800_vbi_fmt(dev, f);
1154 return 0;
1155 default:
1156 return -EINVAL;
1157 } 1130 }
1131 return 0;
1158} 1132}
1133#endif
1159 1134
1160/* 1135static int vidioc_reqbufs (struct file *file, void *priv, struct v4l2_requestbuffers *p)
1161 * This function is _not_ called directly, but from 1136{
1162 * video_generic_ioctl (and maybe others). userspace 1137 struct cx8800_fh *fh = priv;
1163 * copying is done already, arg is a kernel pointer. 1138 return (videobuf_reqbufs(get_queue(fh), p));
1164 */ 1139}
1165static int video_do_ioctl(struct inode *inode, struct file *file, 1140
1166 unsigned int cmd, void *arg) 1141static int vidioc_querybuf (struct file *file, void *priv, struct v4l2_buffer *p)
1142{
1143 struct cx8800_fh *fh = priv;
1144 return (videobuf_querybuf(get_queue(fh), p));
1145}
1146
1147static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *p)
1148{
1149 struct cx8800_fh *fh = priv;
1150 return (videobuf_qbuf(get_queue(fh), p));
1151}
1152
1153static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p)
1154{
1155 struct cx8800_fh *fh = priv;
1156 return (videobuf_dqbuf(get_queue(fh), p,
1157 file->f_flags & O_NONBLOCK));
1158}
1159
1160static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
1167{ 1161{
1168 struct cx8800_fh *fh = file->private_data; 1162 struct cx8800_fh *fh = priv;
1169 struct cx8800_dev *dev = fh->dev; 1163 struct cx8800_dev *dev = fh->dev;
1170 struct cx88_core *core = dev->core;
1171 int err;
1172 1164
1173 if (video_debug > 1) 1165 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
1174 v4l_print_ioctl(core->name,cmd); 1166 return -EINVAL;
1175 switch (cmd) { 1167 if (unlikely(i != fh->type))
1168 return -EINVAL;
1176 1169
1177 /* --- capabilities ------------------------------------------ */ 1170 if (unlikely(!res_get(dev,fh,get_ressource(fh))))
1178 case VIDIOC_QUERYCAP: 1171 return -EBUSY;
1179 { 1172 return videobuf_streamon(get_queue(fh));
1180 struct v4l2_capability *cap = arg; 1173}
1181
1182 memset(cap,0,sizeof(*cap));
1183 strcpy(cap->driver, "cx8800");
1184 strlcpy(cap->card, cx88_boards[core->board].name,
1185 sizeof(cap->card));
1186 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
1187 cap->version = CX88_VERSION_CODE;
1188 cap->capabilities =
1189 V4L2_CAP_VIDEO_CAPTURE |
1190 V4L2_CAP_READWRITE |
1191 V4L2_CAP_STREAMING |
1192 V4L2_CAP_VBI_CAPTURE |
1193 0;
1194 if (UNSET != core->tuner_type)
1195 cap->capabilities |= V4L2_CAP_TUNER;
1196 return 0;
1197 }
1198 1174
1199 /* --- capture ioctls ---------------------------------------- */ 1175static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1200 case VIDIOC_ENUM_FMT: 1176{
1201 { 1177 struct cx8800_fh *fh = priv;
1202 struct v4l2_fmtdesc *f = arg; 1178 struct cx8800_dev *dev = fh->dev;
1203 enum v4l2_buf_type type; 1179 int err, res;
1204 unsigned int index;
1205
1206 index = f->index;
1207 type = f->type;
1208 switch (type) {
1209 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1210 if (index >= ARRAY_SIZE(formats))
1211 return -EINVAL;
1212 memset(f,0,sizeof(*f));
1213 f->index = index;
1214 f->type = type;
1215 strlcpy(f->description,formats[index].name,sizeof(f->description));
1216 f->pixelformat = formats[index].fourcc;
1217 break;
1218 default:
1219 return -EINVAL;
1220 }
1221 return 0;
1222 }
1223 case VIDIOC_G_FMT:
1224 {
1225 struct v4l2_format *f = arg;
1226 return cx8800_g_fmt(dev,fh,f);
1227 }
1228 case VIDIOC_S_FMT:
1229 {
1230 struct v4l2_format *f = arg;
1231 return cx8800_s_fmt(dev,fh,f);
1232 }
1233 case VIDIOC_TRY_FMT:
1234 {
1235 struct v4l2_format *f = arg;
1236 return cx8800_try_fmt(dev,fh,f);
1237 }
1238#ifdef CONFIG_VIDEO_V4L1_COMPAT
1239 /* --- streaming capture ------------------------------------- */
1240 case VIDIOCGMBUF:
1241 {
1242 struct video_mbuf *mbuf = arg;
1243 struct videobuf_queue *q;
1244 struct v4l2_requestbuffers req;
1245 unsigned int i;
1246
1247 q = get_queue(fh);
1248 memset(&req,0,sizeof(req));
1249 req.type = q->type;
1250 req.count = 8;
1251 req.memory = V4L2_MEMORY_MMAP;
1252 err = videobuf_reqbufs(q,&req);
1253 if (err < 0)
1254 return err;
1255 memset(mbuf,0,sizeof(*mbuf));
1256 mbuf->frames = req.count;
1257 mbuf->size = 0;
1258 for (i = 0; i < mbuf->frames; i++) {
1259 mbuf->offsets[i] = q->bufs[i]->boff;
1260 mbuf->size += q->bufs[i]->bsize;
1261 }
1262 return 0;
1263 }
1264#endif
1265 case VIDIOC_REQBUFS:
1266 return videobuf_reqbufs(get_queue(fh), arg);
1267 1180
1268 case VIDIOC_QUERYBUF: 1181 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1269 return videobuf_querybuf(get_queue(fh), arg); 1182 return -EINVAL;
1183 if (i != fh->type)
1184 return -EINVAL;
1270 1185
1271 case VIDIOC_QBUF: 1186 res = get_ressource(fh);
1272 return videobuf_qbuf(get_queue(fh), arg); 1187 err = videobuf_streamoff(get_queue(fh));
1188 if (err < 0)
1189 return err;
1190 res_free(dev,fh,res);
1191 return 0;
1192}
1273 1193
1274 case VIDIOC_DQBUF: 1194static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *tvnorms)
1275 return videobuf_dqbuf(get_queue(fh), arg, 1195{
1276 file->f_flags & O_NONBLOCK); 1196 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1277 1197
1278 case VIDIOC_STREAMON: 1198 mutex_lock(&core->lock);
1279 { 1199 cx88_set_tvnorm(core,*tvnorms);
1280 int res = get_ressource(fh); 1200 mutex_unlock(&core->lock);
1281 1201
1282 if (!res_get(dev,fh,res)) 1202 return 0;
1283 return -EBUSY; 1203}
1284 return videobuf_streamon(get_queue(fh));
1285 }
1286 case VIDIOC_STREAMOFF:
1287 {
1288 int res = get_ressource(fh);
1289 1204
1290 err = videobuf_streamoff(get_queue(fh)); 1205/* only one input in this sample driver */
1291 if (err < 0) 1206int cx88_enum_input (struct cx88_core *core,struct v4l2_input *i)
1292 return err; 1207{
1293 res_free(dev,fh,res); 1208 static const char *iname[] = {
1294 return 0; 1209 [ CX88_VMUX_COMPOSITE1 ] = "Composite1",
1295 } 1210 [ CX88_VMUX_COMPOSITE2 ] = "Composite2",
1296 default: 1211 [ CX88_VMUX_COMPOSITE3 ] = "Composite3",
1297 return cx88_do_ioctl( inode, file, fh->radio, core, cmd, arg, video_do_ioctl ); 1212 [ CX88_VMUX_COMPOSITE4 ] = "Composite4",
1298 } 1213 [ CX88_VMUX_SVIDEO ] = "S-Video",
1214 [ CX88_VMUX_TELEVISION ] = "Television",
1215 [ CX88_VMUX_CABLE ] = "Cable TV",
1216 [ CX88_VMUX_DVB ] = "DVB",
1217 [ CX88_VMUX_DEBUG ] = "for debug only",
1218 };
1219 unsigned int n;
1220
1221 n = i->index;
1222 if (n >= 4)
1223 return -EINVAL;
1224 if (0 == INPUT(n)->type)
1225 return -EINVAL;
1226 memset(i,0,sizeof(*i));
1227 i->index = n;
1228 i->type = V4L2_INPUT_TYPE_CAMERA;
1229 strcpy(i->name,iname[INPUT(n)->type]);
1230 if ((CX88_VMUX_TELEVISION == INPUT(n)->type) ||
1231 (CX88_VMUX_CABLE == INPUT(n)->type))
1232 i->type = V4L2_INPUT_TYPE_TUNER;
1233 i->std = CX88_NORMS;
1299 return 0; 1234 return 0;
1300} 1235}
1236EXPORT_SYMBOL(cx88_enum_input);
1301 1237
1302int cx88_do_ioctl(struct inode *inode, struct file *file, int radio, 1238static int vidioc_enum_input (struct file *file, void *priv,
1303 struct cx88_core *core, unsigned int cmd, void *arg, v4l2_kioctl driver_ioctl) 1239 struct v4l2_input *i)
1304{ 1240{
1305 int err; 1241 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1242 return cx88_enum_input (core,i);
1243}
1306 1244
1307 if (video_debug) { 1245static int vidioc_g_input (struct file *file, void *priv, unsigned int *i)
1308 if (video_debug > 1) { 1246{
1309 if (_IOC_DIR(cmd) & _IOC_WRITE) 1247 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1310 v4l_printk_ioctl_arg("cx88(w)",cmd, arg);
1311 else if (!_IOC_DIR(cmd) & _IOC_READ) {
1312 v4l_print_ioctl("cx88", cmd);
1313 }
1314 } else
1315 v4l_print_ioctl(core->name,cmd);
1316
1317 }
1318
1319 switch (cmd) {
1320 /* ---------- tv norms ---------- */
1321 case VIDIOC_ENUMSTD:
1322 {
1323 struct v4l2_standard *e = arg;
1324 unsigned int i;
1325
1326 i = e->index;
1327 if (i >= ARRAY_SIZE(tvnorms))
1328 return -EINVAL;
1329 err = v4l2_video_std_construct(e, tvnorms[e->index].id,
1330 tvnorms[e->index].name);
1331 e->index = i;
1332 if (err < 0)
1333 return err;
1334 return 0;
1335 }
1336 case VIDIOC_G_STD:
1337 {
1338 v4l2_std_id *id = arg;
1339 1248
1340 *id = core->tvnorm->id; 1249 *i = core->input;
1341 return 0; 1250 return 0;
1342 } 1251}
1343 case VIDIOC_S_STD:
1344 {
1345 v4l2_std_id *id = arg;
1346 unsigned int i;
1347 1252
1348 for(i = 0; i < ARRAY_SIZE(tvnorms); i++) 1253static int vidioc_s_input (struct file *file, void *priv, unsigned int i)
1349 if (*id & tvnorms[i].id) 1254{
1350 break; 1255 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1351 if (i == ARRAY_SIZE(tvnorms))
1352 return -EINVAL;
1353 1256
1354 mutex_lock(&core->lock); 1257 if (i >= 4)
1355 cx88_set_tvnorm(core,&tvnorms[i]); 1258 return -EINVAL;
1356 mutex_unlock(&core->lock);
1357 return 0;
1358 }
1359 1259
1360 /* ------ input switching ---------- */ 1260 mutex_lock(&core->lock);
1361 case VIDIOC_ENUMINPUT: 1261 cx88_newstation(core);
1362 { 1262 cx88_video_mux(core,i);
1363 static const char *iname[] = { 1263 mutex_unlock(&core->lock);
1364 [ CX88_VMUX_COMPOSITE1 ] = "Composite1", 1264 return 0;
1365 [ CX88_VMUX_COMPOSITE2 ] = "Composite2", 1265}
1366 [ CX88_VMUX_COMPOSITE3 ] = "Composite3",
1367 [ CX88_VMUX_COMPOSITE4 ] = "Composite4",
1368 [ CX88_VMUX_SVIDEO ] = "S-Video",
1369 [ CX88_VMUX_TELEVISION ] = "Television",
1370 [ CX88_VMUX_CABLE ] = "Cable TV",
1371 [ CX88_VMUX_DVB ] = "DVB",
1372 [ CX88_VMUX_DEBUG ] = "for debug only",
1373 };
1374 struct v4l2_input *i = arg;
1375 unsigned int n;
1376
1377 n = i->index;
1378 if (n >= 4)
1379 return -EINVAL;
1380 if (0 == INPUT(n)->type)
1381 return -EINVAL;
1382 memset(i,0,sizeof(*i));
1383 i->index = n;
1384 i->type = V4L2_INPUT_TYPE_CAMERA;
1385 strcpy(i->name,iname[INPUT(n)->type]);
1386 if ((CX88_VMUX_TELEVISION == INPUT(n)->type) ||
1387 (CX88_VMUX_CABLE == INPUT(n)->type))
1388 i->type = V4L2_INPUT_TYPE_TUNER;
1389 for (n = 0; n < ARRAY_SIZE(tvnorms); n++)
1390 i->std |= tvnorms[n].id;
1391 return 0;
1392 }
1393 case VIDIOC_G_INPUT:
1394 {
1395 unsigned int *i = arg;
1396 1266
1397 *i = core->input;
1398 return 0;
1399 }
1400 case VIDIOC_S_INPUT:
1401 {
1402 unsigned int *i = arg;
1403 1267
1404 if (*i >= 4)
1405 return -EINVAL;
1406 mutex_lock(&core->lock);
1407 cx88_newstation(core);
1408 video_mux(core,*i);
1409 mutex_unlock(&core->lock);
1410 return 0;
1411 }
1412 1268
1269static int vidioc_queryctrl (struct file *file, void *priv,
1270 struct v4l2_queryctrl *qctrl)
1271{
1272 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
1273 if (unlikely(qctrl->id == 0))
1274 return -EINVAL;
1275 return cx8800_ctrl_query(qctrl);
1276}
1413 1277
1278static int vidioc_g_ctrl (struct file *file, void *priv,
1279 struct v4l2_control *ctl)
1280{
1281 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1282 return
1283 cx88_get_control(core,ctl);
1284}
1414 1285
1415 /* --- controls ---------------------------------------------- */ 1286static int vidioc_s_ctrl (struct file *file, void *priv,
1416 case VIDIOC_QUERYCTRL: 1287 struct v4l2_control *ctl)
1417 { 1288{
1418 struct v4l2_queryctrl *c = arg; 1289 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1290 return
1291 cx88_set_control(core,ctl);
1292}
1419 1293
1420 return cx88_queryctrl(c); 1294static int vidioc_g_tuner (struct file *file, void *priv,
1421 } 1295 struct v4l2_tuner *t)
1422 case VIDIOC_G_CTRL: 1296{
1423 return get_control(core,arg); 1297 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1424 case VIDIOC_S_CTRL: 1298 u32 reg;
1425 return set_control(core,arg);
1426 1299
1427 /* --- tuner ioctls ------------------------------------------ */ 1300 if (unlikely(UNSET == core->tuner_type))
1428 case VIDIOC_G_TUNER: 1301 return -EINVAL;
1429 { 1302 if (0 != t->index)
1430 struct v4l2_tuner *t = arg; 1303 return -EINVAL;
1431 u32 reg;
1432
1433 if (UNSET == core->tuner_type)
1434 return -EINVAL;
1435 if (0 != t->index)
1436 return -EINVAL;
1437
1438 memset(t,0,sizeof(*t));
1439 strcpy(t->name, "Television");
1440 t->type = V4L2_TUNER_ANALOG_TV;
1441 t->capability = V4L2_TUNER_CAP_NORM;
1442 t->rangehigh = 0xffffffffUL;
1443
1444 cx88_get_stereo(core ,t);
1445 reg = cx_read(MO_DEVICE_STATUS);
1446 t->signal = (reg & (1<<5)) ? 0xffff : 0x0000;
1447 return 0;
1448 }
1449 case VIDIOC_S_TUNER:
1450 {
1451 struct v4l2_tuner *t = arg;
1452 1304
1453 if (UNSET == core->tuner_type) 1305 strcpy(t->name, "Television");
1454 return -EINVAL; 1306 t->type = V4L2_TUNER_ANALOG_TV;
1455 if (0 != t->index) 1307 t->capability = V4L2_TUNER_CAP_NORM;
1456 return -EINVAL; 1308 t->rangehigh = 0xffffffffUL;
1457 cx88_set_stereo(core, t->audmode, 1);
1458 return 0;
1459 }
1460 case VIDIOC_G_FREQUENCY:
1461 {
1462 struct v4l2_frequency *f = arg;
1463 1309
1464 memset(f,0,sizeof(*f)); 1310 cx88_get_stereo(core ,t);
1311 reg = cx_read(MO_DEVICE_STATUS);
1312 t->signal = (reg & (1<<5)) ? 0xffff : 0x0000;
1313 return 0;
1314}
1465 1315
1466 if (UNSET == core->tuner_type) 1316static int vidioc_s_tuner (struct file *file, void *priv,
1467 return -EINVAL; 1317 struct v4l2_tuner *t)
1318{
1319 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1468 1320
1469 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */ 1321 if (UNSET == core->tuner_type)
1470 f->type = radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 1322 return -EINVAL;
1471 f->frequency = core->freq; 1323 if (0 != t->index)
1324 return -EINVAL;
1472 1325
1473 cx88_call_i2c_clients(core,VIDIOC_G_FREQUENCY,f); 1326 cx88_set_stereo(core, t->audmode, 1);
1327 return 0;
1328}
1474 1329
1475 return 0; 1330static int vidioc_g_frequency (struct file *file, void *priv,
1476 } 1331 struct v4l2_frequency *f)
1477 case VIDIOC_S_FREQUENCY: 1332{
1478 { 1333 struct cx8800_fh *fh = priv;
1479 struct v4l2_frequency *f = arg; 1334 struct cx88_core *core = fh->dev->core;
1480
1481 if (UNSET == core->tuner_type)
1482 return -EINVAL;
1483 if (f->tuner != 0)
1484 return -EINVAL;
1485 if (0 == radio && f->type != V4L2_TUNER_ANALOG_TV)
1486 return -EINVAL;
1487 if (1 == radio && f->type != V4L2_TUNER_RADIO)
1488 return -EINVAL;
1489 mutex_lock(&core->lock);
1490 core->freq = f->frequency;
1491 cx88_newstation(core);
1492 cx88_call_i2c_clients(core,VIDIOC_S_FREQUENCY,f);
1493
1494 /* When changing channels it is required to reset TVAUDIO */
1495 msleep (10);
1496 cx88_set_tvaudio(core);
1497 1335
1498 mutex_unlock(&core->lock); 1336 if (unlikely(UNSET == core->tuner_type))
1499 return 0; 1337 return -EINVAL;
1500 }
1501#ifdef CONFIG_VIDEO_ADV_DEBUG
1502 /* ioctls to allow direct acces to the cx2388x registers */
1503 case VIDIOC_INT_G_REGISTER:
1504 {
1505 struct v4l2_register *reg = arg;
1506 1338
1507 if (reg->i2c_id != 0) 1339 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
1508 return -EINVAL; 1340 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1509 /* cx2388x has a 24-bit register space */ 1341 f->frequency = core->freq;
1510 reg->val = cx_read(reg->reg&0xffffff);
1511 return 0;
1512 }
1513 case VIDIOC_INT_S_REGISTER:
1514 {
1515 struct v4l2_register *reg = arg;
1516 1342
1517 if (reg->i2c_id != 0) 1343 cx88_call_i2c_clients(core,VIDIOC_G_FREQUENCY,f);
1518 return -EINVAL;
1519 if (!capable(CAP_SYS_ADMIN))
1520 return -EPERM;
1521 cx_write(reg->reg&0xffffff, reg->val);
1522 return 0;
1523 }
1524#endif
1525 1344
1526 default:
1527 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
1528 driver_ioctl);
1529 }
1530 return 0; 1345 return 0;
1531} 1346}
1532 1347
1533static int video_ioctl(struct inode *inode, struct file *file, 1348int cx88_set_freq (struct cx88_core *core,
1534 unsigned int cmd, unsigned long arg) 1349 struct v4l2_frequency *f)
1535{ 1350{
1536 int retval; 1351 if (unlikely(UNSET == core->tuner_type))
1352 return -EINVAL;
1353 if (unlikely(f->tuner != 0))
1354 return -EINVAL;
1537 1355
1538 retval=video_usercopy(inode, file, cmd, arg, video_do_ioctl); 1356 mutex_lock(&core->lock);
1357 core->freq = f->frequency;
1358 cx88_newstation(core);
1359 cx88_call_i2c_clients(core,VIDIOC_S_FREQUENCY,f);
1360
1361 /* When changing channels it is required to reset TVAUDIO */
1362 msleep (10);
1363 cx88_set_tvaudio(core);
1539 1364
1540 if (video_debug > 1) { 1365 mutex_unlock(&core->lock);
1541 if (retval < 0) { 1366
1542 v4l_print_ioctl("cx88(err)", cmd); 1367 return 0;
1543 printk(KERN_DEBUG "cx88(err): errcode=%d\n",retval); 1368}
1544 } else if (_IOC_DIR(cmd) & _IOC_READ) 1369EXPORT_SYMBOL(cx88_set_freq);
1545 v4l_printk_ioctl_arg("cx88(r)",cmd, (void *)arg); 1370
1546 } 1371static int vidioc_s_frequency (struct file *file, void *priv,
1372 struct v4l2_frequency *f)
1373{
1374 struct cx8800_fh *fh = priv;
1375 struct cx88_core *core = fh->dev->core;
1547 1376
1548 return retval; 1377 if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
1378 return -EINVAL;
1379 if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
1380 return -EINVAL;
1381
1382 return
1383 cx88_set_freq (core,f);
1384}
1385
1386#ifdef CONFIG_VIDEO_ADV_DEBUG
1387static int vidioc_g_register (struct file *file, void *fh,
1388 struct v4l2_register *reg)
1389{
1390 struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core;
1391
1392 if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
1393 return -EINVAL;
1394 /* cx2388x has a 24-bit register space */
1395 reg->val = cx_read(reg->reg&0xffffff);
1396 return 0;
1549} 1397}
1550 1398
1399static int vidioc_s_register (struct file *file, void *fh,
1400 struct v4l2_register *reg)
1401{
1402 struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core;
1403
1404 if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
1405 return -EINVAL;
1406 cx_write(reg->reg&0xffffff, reg->val);
1407 return 0;
1408}
1409#endif
1410
1411/* ----------------------------------------------------------- */
1412/* RADIO ESPECIFIC IOCTLS */
1551/* ----------------------------------------------------------- */ 1413/* ----------------------------------------------------------- */
1552 1414
1553static int radio_do_ioctl(struct inode *inode, struct file *file, 1415static int radio_querycap (struct file *file, void *priv,
1554 unsigned int cmd, void *arg) 1416 struct v4l2_capability *cap)
1555{ 1417{
1556 struct cx8800_fh *fh = file->private_data; 1418 struct cx8800_dev *dev = ((struct cx8800_fh *)priv)->dev;
1557 struct cx8800_dev *dev = fh->dev;
1558 struct cx88_core *core = dev->core; 1419 struct cx88_core *core = dev->core;
1559 1420
1560 if (video_debug > 1) 1421 strcpy(cap->driver, "cx8800");
1561 v4l_print_ioctl(core->name,cmd); 1422 strlcpy(cap->card, cx88_boards[core->board].name,
1562 1423 sizeof(cap->card));
1563 switch (cmd) { 1424 sprintf(cap->bus_info,"PCI:%s", pci_name(dev->pci));
1564 case VIDIOC_QUERYCAP: 1425 cap->version = CX88_VERSION_CODE;
1565 { 1426 cap->capabilities = V4L2_CAP_TUNER;
1566 struct v4l2_capability *cap = arg; 1427 return 0;
1567 1428}
1568 memset(cap,0,sizeof(*cap));
1569 strcpy(cap->driver, "cx8800");
1570 strlcpy(cap->card, cx88_boards[core->board].name,
1571 sizeof(cap->card));
1572 sprintf(cap->bus_info,"PCI:%s", pci_name(dev->pci));
1573 cap->version = CX88_VERSION_CODE;
1574 cap->capabilities = V4L2_CAP_TUNER;
1575 return 0;
1576 }
1577 case VIDIOC_G_TUNER:
1578 {
1579 struct v4l2_tuner *t = arg;
1580 1429
1581 if (t->index > 0) 1430static int radio_g_tuner (struct file *file, void *priv,
1582 return -EINVAL; 1431 struct v4l2_tuner *t)
1432{
1433 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1583 1434
1584 memset(t,0,sizeof(*t)); 1435 if (unlikely(t->index > 0))
1585 strcpy(t->name, "Radio"); 1436 return -EINVAL;
1586 t->type = V4L2_TUNER_RADIO;
1587 1437
1588 cx88_call_i2c_clients(core,VIDIOC_G_TUNER,t); 1438 strcpy(t->name, "Radio");
1589 return 0; 1439 t->type = V4L2_TUNER_RADIO;
1590 }
1591 case VIDIOC_ENUMINPUT:
1592 {
1593 struct v4l2_input *i = arg;
1594 1440
1595 if (i->index != 0) 1441 cx88_call_i2c_clients(core,VIDIOC_G_TUNER,t);
1596 return -EINVAL; 1442 return 0;
1597 strcpy(i->name,"Radio"); 1443}
1598 i->type = V4L2_INPUT_TYPE_TUNER;
1599 return 0;
1600 }
1601 case VIDIOC_G_INPUT:
1602 {
1603 int *i = arg;
1604 *i = 0;
1605 return 0;
1606 }
1607 case VIDIOC_G_AUDIO:
1608 {
1609 struct v4l2_audio *a = arg;
1610 1444
1611 memset(a,0,sizeof(*a)); 1445static int radio_enum_input (struct file *file, void *priv,
1612 strcpy(a->name,"Radio"); 1446 struct v4l2_input *i)
1613 return 0; 1447{
1614 } 1448 if (i->index != 0)
1615 case VIDIOC_G_STD: 1449 return -EINVAL;
1616 { 1450 strcpy(i->name,"Radio");
1617 v4l2_std_id *id = arg; 1451 i->type = V4L2_INPUT_TYPE_TUNER;
1618 *id = 0;
1619 return 0;
1620 }
1621#ifdef CONFIG_VIDEO_V4L1_COMPAT
1622 case VIDIOCSTUNER:
1623 {
1624 struct video_tuner *v = arg;
1625 1452
1626 if (v->tuner) /* Only tuner 0 */ 1453 return 0;
1627 return -EINVAL; 1454}
1628 1455
1629 cx88_call_i2c_clients(core,VIDIOCSTUNER,v); 1456static int radio_g_audio (struct file *file, void *priv, struct v4l2_audio *a)
1630 return 0; 1457{
1631 } 1458 if (unlikely(a->index))
1632#endif 1459 return -EINVAL;
1633 case VIDIOC_S_TUNER:
1634 {
1635 struct v4l2_tuner *t = arg;
1636 1460
1637 if (0 != t->index) 1461 memset(a,0,sizeof(*a));
1638 return -EINVAL; 1462 strcpy(a->name,"Radio");
1463 return 0;
1464}
1639 1465
1640 cx88_call_i2c_clients(core,VIDIOC_S_TUNER,t); 1466/* FIXME: Should add a standard for radio */
1641 1467
1642 return 0; 1468static int radio_s_tuner (struct file *file, void *priv,
1643 } 1469 struct v4l2_tuner *t)
1470{
1471 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1644 1472
1645 case VIDIOC_S_AUDIO: 1473 if (0 != t->index)
1646 case VIDIOC_S_INPUT: 1474 return -EINVAL;
1647 case VIDIOC_S_STD:
1648 return 0;
1649 1475
1650 case VIDIOC_QUERYCTRL: 1476 cx88_call_i2c_clients(core,VIDIOC_S_TUNER,t);
1651 {
1652 struct v4l2_queryctrl *c = arg;
1653 int i;
1654
1655 if (c->id < V4L2_CID_BASE ||
1656 c->id >= V4L2_CID_LASTP1)
1657 return -EINVAL;
1658 if (c->id == V4L2_CID_AUDIO_MUTE) {
1659 for (i = 0; i < CX8800_CTLS; i++)
1660 if (cx8800_ctls[i].v.id == c->id)
1661 break;
1662 *c = cx8800_ctls[i].v;
1663 } else
1664 *c = no_ctl;
1665 return 0;
1666 }
1667 1477
1478 return 0;
1479}
1668 1480
1669 case VIDIOC_G_CTRL: 1481static int radio_s_audio (struct file *file, void *fh,
1670 case VIDIOC_S_CTRL: 1482 struct v4l2_audio *a)
1671 case VIDIOC_G_FREQUENCY: 1483{
1672 case VIDIOC_S_FREQUENCY: 1484 return 0;
1673 return video_do_ioctl(inode,file,cmd,arg); 1485}
1674 1486
1675 default: 1487static int radio_s_input (struct file *file, void *fh, unsigned int i)
1676 return v4l_compat_translate_ioctl(inode,file,cmd,arg, 1488{
1677 radio_do_ioctl);
1678 }
1679 return 0; 1489 return 0;
1680}; 1490}
1681 1491
1682static int radio_ioctl(struct inode *inode, struct file *file, 1492static int radio_queryctrl (struct file *file, void *priv,
1683 unsigned int cmd, unsigned long arg) 1493 struct v4l2_queryctrl *c)
1684{ 1494{
1685 return video_usercopy(inode, file, cmd, arg, radio_do_ioctl); 1495 int i;
1686}; 1496
1497 if (c->id < V4L2_CID_BASE ||
1498 c->id >= V4L2_CID_LASTP1)
1499 return -EINVAL;
1500 if (c->id == V4L2_CID_AUDIO_MUTE) {
1501 for (i = 0; i < CX8800_CTLS; i++)
1502 if (cx8800_ctls[i].v.id == c->id)
1503 break;
1504 *c = cx8800_ctls[i].v;
1505 } else
1506 *c = no_ctl;
1507 return 0;
1508}
1687 1509
1688/* ----------------------------------------------------------- */ 1510/* ----------------------------------------------------------- */
1689 1511
@@ -1816,27 +1638,52 @@ static const struct file_operations video_fops =
1816 .read = video_read, 1638 .read = video_read,
1817 .poll = video_poll, 1639 .poll = video_poll,
1818 .mmap = video_mmap, 1640 .mmap = video_mmap,
1819 .ioctl = video_ioctl, 1641 .ioctl = video_ioctl2,
1820 .compat_ioctl = v4l_compat_ioctl32, 1642 .compat_ioctl = v4l_compat_ioctl32,
1821 .llseek = no_llseek, 1643 .llseek = no_llseek,
1822}; 1644};
1823 1645
1646static struct video_device cx8800_vbi_template;
1824static struct video_device cx8800_video_template = 1647static struct video_device cx8800_video_template =
1825{ 1648{
1826 .name = "cx8800-video", 1649 .name = "cx8800-video",
1827 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES, 1650 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES,
1828 .hardware = 0, 1651 .fops = &video_fops,
1829 .fops = &video_fops, 1652 .minor = -1,
1830 .minor = -1, 1653 .vidioc_querycap = vidioc_querycap,
1831}; 1654 .vidioc_enum_fmt_cap = vidioc_enum_fmt_cap,
1832 1655 .vidioc_g_fmt_cap = vidioc_g_fmt_cap,
1833static struct video_device cx8800_vbi_template = 1656 .vidioc_try_fmt_cap = vidioc_try_fmt_cap,
1834{ 1657 .vidioc_s_fmt_cap = vidioc_s_fmt_cap,
1835 .name = "cx8800-vbi", 1658 .vidioc_g_fmt_vbi = cx8800_vbi_fmt,
1836 .type = VID_TYPE_TELETEXT|VID_TYPE_TUNER, 1659 .vidioc_try_fmt_vbi = cx8800_vbi_fmt,
1837 .hardware = 0, 1660 .vidioc_s_fmt_vbi = cx8800_vbi_fmt,
1838 .fops = &video_fops, 1661 .vidioc_reqbufs = vidioc_reqbufs,
1839 .minor = -1, 1662 .vidioc_querybuf = vidioc_querybuf,
1663 .vidioc_qbuf = vidioc_qbuf,
1664 .vidioc_dqbuf = vidioc_dqbuf,
1665 .vidioc_s_std = vidioc_s_std,
1666 .vidioc_enum_input = vidioc_enum_input,
1667 .vidioc_g_input = vidioc_g_input,
1668 .vidioc_s_input = vidioc_s_input,
1669 .vidioc_queryctrl = vidioc_queryctrl,
1670 .vidioc_g_ctrl = vidioc_g_ctrl,
1671 .vidioc_s_ctrl = vidioc_s_ctrl,
1672 .vidioc_streamon = vidioc_streamon,
1673 .vidioc_streamoff = vidioc_streamoff,
1674#ifdef CONFIG_VIDEO_V4L1_COMPAT
1675 .vidiocgmbuf = vidiocgmbuf,
1676#endif
1677 .vidioc_g_tuner = vidioc_g_tuner,
1678 .vidioc_s_tuner = vidioc_s_tuner,
1679 .vidioc_g_frequency = vidioc_g_frequency,
1680 .vidioc_s_frequency = vidioc_s_frequency,
1681#ifdef CONFIG_VIDEO_ADV_DEBUG
1682 .vidioc_g_register = vidioc_g_register,
1683 .vidioc_s_register = vidioc_s_register,
1684#endif
1685 .tvnorms = CX88_NORMS,
1686 .current_norm = V4L2_STD_NTSC_M,
1840}; 1687};
1841 1688
1842static const struct file_operations radio_fops = 1689static const struct file_operations radio_fops =
@@ -1844,18 +1691,30 @@ static const struct file_operations radio_fops =
1844 .owner = THIS_MODULE, 1691 .owner = THIS_MODULE,
1845 .open = video_open, 1692 .open = video_open,
1846 .release = video_release, 1693 .release = video_release,
1847 .ioctl = radio_ioctl, 1694 .ioctl = video_ioctl2,
1848 .compat_ioctl = v4l_compat_ioctl32, 1695 .compat_ioctl = v4l_compat_ioctl32,
1849 .llseek = no_llseek, 1696 .llseek = no_llseek,
1850}; 1697};
1851 1698
1852static struct video_device cx8800_radio_template = 1699static struct video_device cx8800_radio_template =
1853{ 1700{
1854 .name = "cx8800-radio", 1701 .name = "cx8800-radio",
1855 .type = VID_TYPE_TUNER, 1702 .type = VID_TYPE_TUNER,
1856 .hardware = 0, 1703 .hardware = 0,
1857 .fops = &radio_fops, 1704 .fops = &radio_fops,
1858 .minor = -1, 1705 .minor = -1,
1706 .vidioc_querycap = radio_querycap,
1707 .vidioc_g_tuner = radio_g_tuner,
1708 .vidioc_enum_input = radio_enum_input,
1709 .vidioc_g_audio = radio_g_audio,
1710 .vidioc_s_tuner = radio_s_tuner,
1711 .vidioc_s_audio = radio_s_audio,
1712 .vidioc_s_input = radio_s_input,
1713 .vidioc_queryctrl = radio_queryctrl,
1714 .vidioc_g_ctrl = vidioc_g_ctrl,
1715 .vidioc_s_ctrl = vidioc_s_ctrl,
1716 .vidioc_g_frequency = vidioc_g_frequency,
1717 .vidioc_s_frequency = vidioc_s_frequency,
1859}; 1718};
1860 1719
1861/* ----------------------------------------------------------- */ 1720/* ----------------------------------------------------------- */
@@ -1890,6 +1749,7 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1890{ 1749{
1891 struct cx8800_dev *dev; 1750 struct cx8800_dev *dev;
1892 struct cx88_core *core; 1751 struct cx88_core *core;
1752
1893 int err; 1753 int err;
1894 1754
1895 dev = kzalloc(sizeof(*dev),GFP_KERNEL); 1755 dev = kzalloc(sizeof(*dev),GFP_KERNEL);
@@ -1924,9 +1784,15 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1924 goto fail_core; 1784 goto fail_core;
1925 } 1785 }
1926 1786
1787 /* Initialize VBI template */
1788 memcpy( &cx8800_vbi_template, &cx8800_video_template,
1789 sizeof(cx8800_vbi_template) );
1790 strcpy(cx8800_vbi_template.name,"cx8800-vbi");
1791 cx8800_vbi_template.type = VID_TYPE_TELETEXT|VID_TYPE_TUNER;
1792
1927 /* initialize driver struct */ 1793 /* initialize driver struct */
1928 spin_lock_init(&dev->slock); 1794 spin_lock_init(&dev->slock);
1929 core->tvnorm = tvnorms; 1795 core->tvnorm = cx8800_video_template.current_norm;
1930 1796
1931 /* init video dma queues */ 1797 /* init video dma queues */
1932 INIT_LIST_HEAD(&dev->vidq.active); 1798 INIT_LIST_HEAD(&dev->vidq.active);
@@ -2007,9 +1873,9 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
2007 1873
2008 /* initial device configuration */ 1874 /* initial device configuration */
2009 mutex_lock(&core->lock); 1875 mutex_lock(&core->lock);
2010 cx88_set_tvnorm(core,tvnorms); 1876 cx88_set_tvnorm(core,core->tvnorm);
2011 init_controls(core); 1877 init_controls(core);
2012 video_mux(core,0); 1878 cx88_video_mux(core,0);
2013 mutex_unlock(&core->lock); 1879 mutex_unlock(&core->lock);
2014 1880
2015 /* start tvaudio thread */ 1881 /* start tvaudio thread */
@@ -2178,8 +2044,6 @@ static void cx8800_fini(void)
2178module_init(cx8800_init); 2044module_init(cx8800_init);
2179module_exit(cx8800_fini); 2045module_exit(cx8800_fini);
2180 2046
2181EXPORT_SYMBOL(cx88_do_ioctl);
2182
2183/* ----------------------------------------------------------- */ 2047/* ----------------------------------------------------------- */
2184/* 2048/*
2185 * Local variables: 2049 * Local variables:
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index a9575ad8ca..a4f7befda5 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -31,7 +31,9 @@
31#include <media/video-buf.h> 31#include <media/video-buf.h>
32#include <media/cx2341x.h> 32#include <media/cx2341x.h>
33#include <media/audiochip.h> 33#include <media/audiochip.h>
34#if defined(CONFIG_VIDEO_BUF_DVB) || defined(CONFIG_VIDEO_BUF_DVB_MODULE)
34#include <media/video-buf-dvb.h> 35#include <media/video-buf-dvb.h>
36#endif
35 37
36#include "btcx-risc.h" 38#include "btcx-risc.h"
37#include "cx88-reg.h" 39#include "cx88-reg.h"
@@ -50,6 +52,13 @@
50/* ----------------------------------------------------------- */ 52/* ----------------------------------------------------------- */
51/* defines and enums */ 53/* defines and enums */
52 54
55/* Currently unsupported by the driver: PAL/H, NTSC/Kr, SECAM B/G/H/LC */
56#define CX88_NORMS (\
57 V4L2_STD_NTSC_M| V4L2_STD_NTSC_M_JP| V4L2_STD_NTSC_443 | \
58 V4L2_STD_PAL_BG| V4L2_STD_PAL_DK | V4L2_STD_PAL_I | \
59 V4L2_STD_PAL_M | V4L2_STD_PAL_N | V4L2_STD_PAL_Nc | \
60 V4L2_STD_PAL_60| V4L2_STD_SECAM_L | V4L2_STD_SECAM_DK )
61
53#define FORMAT_FLAGS_PACKED 0x01 62#define FORMAT_FLAGS_PACKED 0x01
54#define FORMAT_FLAGS_PLANAR 0x02 63#define FORMAT_FLAGS_PLANAR 0x02
55 64
@@ -82,22 +91,15 @@ enum cx8802_board_access {
82/* ----------------------------------------------------------- */ 91/* ----------------------------------------------------------- */
83/* tv norms */ 92/* tv norms */
84 93
85struct cx88_tvnorm { 94static unsigned int inline norm_maxw(v4l2_std_id norm)
86 char *name;
87 v4l2_std_id id;
88 u32 cxiformat;
89 u32 cxoformat;
90};
91
92static unsigned int inline norm_maxw(struct cx88_tvnorm *norm)
93{ 95{
94 return (norm->id & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 720 : 768; 96 return (norm & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 720 : 768;
95} 97}
96 98
97 99
98static unsigned int inline norm_maxh(struct cx88_tvnorm *norm) 100static unsigned int inline norm_maxh(v4l2_std_id norm)
99{ 101{
100 return (norm->id & V4L2_STD_625_50) ? 576 : 480; 102 return (norm & V4L2_STD_625_50) ? 576 : 480;
101} 103}
102 104
103/* ----------------------------------------------------------- */ 105/* ----------------------------------------------------------- */
@@ -313,13 +315,15 @@ struct cx88_core {
313 unsigned int tuner_formats; 315 unsigned int tuner_formats;
314 316
315 /* config info -- dvb */ 317 /* config info -- dvb */
318#if defined(CONFIG_VIDEO_BUF_DVB) || defined(CONFIG_VIDEO_BUF_DVB_MODULE)
316 struct dvb_pll_desc *pll_desc; 319 struct dvb_pll_desc *pll_desc;
317 unsigned int pll_addr; 320 unsigned int pll_addr;
318 int (*prev_set_voltage)(struct dvb_frontend* fe, fe_sec_voltage_t voltage); 321 int (*prev_set_voltage)(struct dvb_frontend* fe, fe_sec_voltage_t voltage);
322#endif
319 323
320 /* state info */ 324 /* state info */
321 struct task_struct *kthread; 325 struct task_struct *kthread;
322 struct cx88_tvnorm *tvnorm; 326 v4l2_std_id tvnorm;
323 u32 tvaudio; 327 u32 tvaudio;
324 u32 audiomode_manual; 328 u32 audiomode_manual;
325 u32 audiomode_current; 329 u32 audiomode_current;
@@ -459,13 +463,16 @@ struct cx8802_dev {
459 u32 mailbox; 463 u32 mailbox;
460 int width; 464 int width;
461 int height; 465 int height;
466 int fw_size;
462 467
468#if defined(CONFIG_VIDEO_BUF_DVB) || defined(CONFIG_VIDEO_BUF_DVB_MODULE)
463 /* for dvb only */ 469 /* for dvb only */
464 struct videobuf_dvb dvb; 470 struct videobuf_dvb dvb;
465 void* fe_handle; 471 void* fe_handle;
466 int (*fe_release)(void *handle); 472 int (*fe_release)(void *handle);
467 473
468 void *card_priv; 474 void *card_priv;
475#endif
469 /* for switching modulation types */ 476 /* for switching modulation types */
470 unsigned char ts_gen_cntrl; 477 unsigned char ts_gen_cntrl;
471 478
@@ -536,7 +543,7 @@ extern void cx88_sram_channel_dump(struct cx88_core *core,
536 543
537extern int cx88_set_scale(struct cx88_core *core, unsigned int width, 544extern int cx88_set_scale(struct cx88_core *core, unsigned int width,
538 unsigned int height, enum v4l2_field field); 545 unsigned int height, enum v4l2_field field);
539extern int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm); 546extern int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm);
540 547
541extern struct video_device *cx88_vdev_init(struct cx88_core *core, 548extern struct video_device *cx88_vdev_init(struct cx88_core *core,
542 struct pci_dev *pci, 549 struct pci_dev *pci,
@@ -553,7 +560,10 @@ extern int cx88_stop_audio_dma(struct cx88_core *core);
553/* ----------------------------------------------------------- */ 560/* ----------------------------------------------------------- */
554/* cx88-vbi.c */ 561/* cx88-vbi.c */
555 562
556void cx8800_vbi_fmt(struct cx8800_dev *dev, struct v4l2_format *f); 563/* Can be used as g_vbi_fmt, try_vbi_fmt and s_vbi_fmt */
564int cx8800_vbi_fmt (struct file *file, void *priv,
565 struct v4l2_format *f);
566
557/* 567/*
558int cx8800_start_vbi_dma(struct cx8800_dev *dev, 568int cx8800_start_vbi_dma(struct cx8800_dev *dev,
559 struct cx88_dmaqueue *q, 569 struct cx88_dmaqueue *q,
@@ -633,19 +643,14 @@ int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state);
633int cx8802_resume_common(struct pci_dev *pci_dev); 643int cx8802_resume_common(struct pci_dev *pci_dev);
634 644
635/* ----------------------------------------------------------- */ 645/* ----------------------------------------------------------- */
636/* cx88-video.c */ 646/* cx88-video.c*/
637extern int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
638 struct cx88_core *core, unsigned int cmd,
639 void *arg, v4l2_kioctl driver_ioctl);
640extern const u32 cx88_user_ctrls[]; 647extern const u32 cx88_user_ctrls[];
641extern int cx8800_ctrl_query(struct v4l2_queryctrl *qctrl); 648extern int cx8800_ctrl_query(struct v4l2_queryctrl *qctrl);
642 649int cx88_enum_input (struct cx88_core *core,struct v4l2_input *i);
643/* ----------------------------------------------------------- */ 650int cx88_set_freq (struct cx88_core *core,struct v4l2_frequency *f);
644/* cx88-blackbird.c */ 651int cx88_get_control(struct cx88_core *core, struct v4l2_control *ctl);
645/* used by cx88-ivtv ioctl emulation layer */ 652int cx88_set_control(struct cx88_core *core, struct v4l2_control *ctl);
646extern int (*cx88_ioctl_hook)(struct inode *inode, struct file *file, 653int cx88_video_mux(struct cx88_core *core, unsigned int input);
647 unsigned int cmd, void *arg);
648extern unsigned int (*cx88_ioctl_translator)(unsigned int cmd);
649 654
650/* 655/*
651 * Local variables: 656 * Local variables:
diff --git a/drivers/media/video/et61x251/et61x251.h b/drivers/media/video/et61x251/et61x251.h
index 2e5ca40324..262f98e124 100644
--- a/drivers/media/video/et61x251/et61x251.h
+++ b/drivers/media/video/et61x251/et61x251.h
@@ -171,10 +171,7 @@ struct et61x251_device {
171struct et61x251_device* 171struct et61x251_device*
172et61x251_match_id(struct et61x251_device* cam, const struct usb_device_id *id) 172et61x251_match_id(struct et61x251_device* cam, const struct usb_device_id *id)
173{ 173{
174 if (usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id)) 174 return usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id) ? cam : NULL;
175 return cam;
176
177 return NULL;
178} 175}
179 176
180 177
diff --git a/drivers/media/video/et61x251/et61x251_core.c b/drivers/media/video/et61x251/et61x251_core.c
index 49792ae8c6..a6525513cd 100644
--- a/drivers/media/video/et61x251/et61x251_core.c
+++ b/drivers/media/video/et61x251/et61x251_core.c
@@ -1,7 +1,7 @@
1/*************************************************************************** 1/***************************************************************************
2 * V4L2 driver for ET61X[12]51 PC Camera Controllers * 2 * V4L2 driver for ET61X[12]51 PC Camera Controllers *
3 * * 3 * *
4 * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> * 4 * Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
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 *
@@ -48,8 +48,8 @@
48#define ET61X251_MODULE_AUTHOR "(C) 2006 Luca Risolia" 48#define ET61X251_MODULE_AUTHOR "(C) 2006 Luca Risolia"
49#define ET61X251_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>" 49#define ET61X251_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
50#define ET61X251_MODULE_LICENSE "GPL" 50#define ET61X251_MODULE_LICENSE "GPL"
51#define ET61X251_MODULE_VERSION "1:1.02" 51#define ET61X251_MODULE_VERSION "1:1.04"
52#define ET61X251_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 2) 52#define ET61X251_MODULE_VERSION_CODE KERNEL_VERSION(1, 1, 4)
53 53
54/*****************************************************************************/ 54/*****************************************************************************/
55 55
@@ -85,7 +85,7 @@ MODULE_PARM_DESC(force_munmap,
85 "\ndetected camera." 85 "\ndetected camera."
86 "\n 0 = do not force memory unmapping" 86 "\n 0 = do not force memory unmapping"
87 "\n 1 = force memory unmapping (save memory)" 87 "\n 1 = force memory unmapping (save memory)"
88 "\nDefault value is "__MODULE_STRING(SN9C102_FORCE_MUNMAP)"." 88 "\nDefault value is "__MODULE_STRING(ET61X251_FORCE_MUNMAP)"."
89 "\n"); 89 "\n");
90 90
91static unsigned int frame_timeout[] = {[0 ... ET61X251_MAX_DEVICES-1] = 91static unsigned int frame_timeout[] = {[0 ... ET61X251_MAX_DEVICES-1] =
@@ -133,7 +133,8 @@ et61x251_request_buffers(struct et61x251_device* cam, u32 count,
133 133
134 cam->nbuffers = count; 134 cam->nbuffers = count;
135 while (cam->nbuffers > 0) { 135 while (cam->nbuffers > 0) {
136 if ((buff = vmalloc_32(cam->nbuffers * PAGE_ALIGN(imagesize)))) 136 if ((buff = vmalloc_32_user(cam->nbuffers *
137 PAGE_ALIGN(imagesize))))
137 break; 138 break;
138 cam->nbuffers--; 139 cam->nbuffers--;
139 } 140 }
@@ -543,10 +544,11 @@ static int et61x251_start_transfer(struct et61x251_device* cam)
543{ 544{
544 struct usb_device *udev = cam->usbdev; 545 struct usb_device *udev = cam->usbdev;
545 struct urb* urb; 546 struct urb* urb;
546 const unsigned int wMaxPacketSize[] = {0, 256, 384, 512, 640, 768, 832, 547 struct usb_host_interface* altsetting = usb_altnum_to_altsetting(
547 864, 896, 920, 956, 980, 1000, 548 usb_ifnum_to_if(udev, 0),
548 1022}; 549 ET61X251_ALTERNATE_SETTING);
549 const unsigned int psz = wMaxPacketSize[ET61X251_ALTERNATE_SETTING]; 550 const unsigned int psz = le16_to_cpu(altsetting->
551 endpoint[0].desc.wMaxPacketSize);
550 s8 i, j; 552 s8 i, j;
551 int err = 0; 553 int err = 0;
552 554
@@ -976,29 +978,31 @@ static CLASS_DEVICE_ATTR(i2c_val, S_IRUGO | S_IWUSR,
976static int et61x251_create_sysfs(struct et61x251_device* cam) 978static int et61x251_create_sysfs(struct et61x251_device* cam)
977{ 979{
978 struct video_device *v4ldev = cam->v4ldev; 980 struct video_device *v4ldev = cam->v4ldev;
979 int rc; 981 int err = 0;
982
983 if ((err = video_device_create_file(v4ldev, &class_device_attr_reg)))
984 goto err_out;
985 if ((err = video_device_create_file(v4ldev, &class_device_attr_val)))
986 goto err_reg;
980 987
981 rc = video_device_create_file(v4ldev, &class_device_attr_reg);
982 if (rc) goto err;
983 rc = video_device_create_file(v4ldev, &class_device_attr_val);
984 if (rc) goto err_reg;
985 if (cam->sensor.sysfs_ops) { 988 if (cam->sensor.sysfs_ops) {
986 rc = video_device_create_file(v4ldev, &class_device_attr_i2c_reg); 989 if ((err = video_device_create_file(v4ldev,
987 if (rc) goto err_val; 990 &class_device_attr_i2c_reg)))
988 rc = video_device_create_file(v4ldev, &class_device_attr_i2c_val); 991 goto err_val;
989 if (rc) goto err_i2c_reg; 992 if ((err = video_device_create_file(v4ldev,
993 &class_device_attr_i2c_val)))
994 goto err_i2c_reg;
990 } 995 }
991 996
992 return 0;
993
994err_i2c_reg: 997err_i2c_reg:
998 if (cam->sensor.sysfs_ops)
995 video_device_remove_file(v4ldev, &class_device_attr_i2c_reg); 999 video_device_remove_file(v4ldev, &class_device_attr_i2c_reg);
996err_val: 1000err_val:
997 video_device_remove_file(v4ldev, &class_device_attr_val); 1001 video_device_remove_file(v4ldev, &class_device_attr_val);
998err_reg: 1002err_reg:
999 video_device_remove_file(v4ldev, &class_device_attr_reg); 1003 video_device_remove_file(v4ldev, &class_device_attr_reg);
1000err: 1004err_out:
1001 return rc; 1005 return err;
1002} 1006}
1003#endif /* CONFIG_VIDEO_ADV_DEBUG */ 1007#endif /* CONFIG_VIDEO_ADV_DEBUG */
1004 1008
@@ -1767,10 +1771,10 @@ et61x251_vidioc_s_crop(struct et61x251_device* cam, void __user * arg)
1767 rect->left = (s->_rect.left & 1L) ? rect->left | 1L : rect->left & ~1L; 1771 rect->left = (s->_rect.left & 1L) ? rect->left | 1L : rect->left & ~1L;
1768 rect->top = (s->_rect.top & 1L) ? rect->top | 1L : rect->top & ~1L; 1772 rect->top = (s->_rect.top & 1L) ? rect->top | 1L : rect->top & ~1L;
1769 1773
1770 if (rect->width < 4) 1774 if (rect->width < 16)
1771 rect->width = 4; 1775 rect->width = 16;
1772 if (rect->height < 4) 1776 if (rect->height < 16)
1773 rect->height = 4; 1777 rect->height = 16;
1774 if (rect->width > bounds->width) 1778 if (rect->width > bounds->width)
1775 rect->width = bounds->width; 1779 rect->width = bounds->width;
1776 if (rect->height > bounds->height) 1780 if (rect->height > bounds->height)
@@ -1784,8 +1788,8 @@ et61x251_vidioc_s_crop(struct et61x251_device* cam, void __user * arg)
1784 if (rect->top + rect->height > bounds->top + bounds->height) 1788 if (rect->top + rect->height > bounds->top + bounds->height)
1785 rect->top = bounds->top+bounds->height - rect->height; 1789 rect->top = bounds->top+bounds->height - rect->height;
1786 1790
1787 rect->width &= ~3L; 1791 rect->width &= ~15L;
1788 rect->height &= ~3L; 1792 rect->height &= ~15L;
1789 1793
1790 if (ET61X251_PRESERVE_IMGSCALE) { 1794 if (ET61X251_PRESERVE_IMGSCALE) {
1791 /* Calculate the actual scaling factor */ 1795 /* Calculate the actual scaling factor */
@@ -1846,6 +1850,35 @@ et61x251_vidioc_s_crop(struct et61x251_device* cam, void __user * arg)
1846 1850
1847 1851
1848static int 1852static int
1853et61x251_vidioc_enum_framesizes(struct et61x251_device* cam, void __user * arg)
1854{
1855 struct v4l2_frmsizeenum frmsize;
1856
1857 if (copy_from_user(&frmsize, arg, sizeof(frmsize)))
1858 return -EFAULT;
1859
1860 if (frmsize.index != 0)
1861 return -EINVAL;
1862
1863 if (frmsize.pixel_format != V4L2_PIX_FMT_ET61X251 &&
1864 frmsize.pixel_format != V4L2_PIX_FMT_SBGGR8)
1865 return -EINVAL;
1866
1867 frmsize.type = V4L2_FRMSIZE_TYPE_STEPWISE;
1868 frmsize.stepwise.min_width = frmsize.stepwise.step_width = 16;
1869 frmsize.stepwise.min_height = frmsize.stepwise.step_height = 16;
1870 frmsize.stepwise.max_width = cam->sensor.cropcap.bounds.width;
1871 frmsize.stepwise.max_height = cam->sensor.cropcap.bounds.height;
1872 memset(&frmsize.reserved, 0, sizeof(frmsize.reserved));
1873
1874 if (copy_to_user(arg, &frmsize, sizeof(frmsize)))
1875 return -EFAULT;
1876
1877 return 0;
1878}
1879
1880
1881static int
1849et61x251_vidioc_enum_fmt(struct et61x251_device* cam, void __user * arg) 1882et61x251_vidioc_enum_fmt(struct et61x251_device* cam, void __user * arg)
1850{ 1883{
1851 struct v4l2_fmtdesc fmtd; 1884 struct v4l2_fmtdesc fmtd;
@@ -1853,6 +1886,9 @@ et61x251_vidioc_enum_fmt(struct et61x251_device* cam, void __user * arg)
1853 if (copy_from_user(&fmtd, arg, sizeof(fmtd))) 1886 if (copy_from_user(&fmtd, arg, sizeof(fmtd)))
1854 return -EFAULT; 1887 return -EFAULT;
1855 1888
1889 if (fmtd.type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1890 return -EINVAL;
1891
1856 if (fmtd.index == 0) { 1892 if (fmtd.index == 0) {
1857 strcpy(fmtd.description, "bayer rgb"); 1893 strcpy(fmtd.description, "bayer rgb");
1858 fmtd.pixelformat = V4L2_PIX_FMT_SBGGR8; 1894 fmtd.pixelformat = V4L2_PIX_FMT_SBGGR8;
@@ -1934,17 +1970,17 @@ et61x251_vidioc_try_s_fmt(struct et61x251_device* cam, unsigned int cmd,
1934 rect.width = scale * pix->width; 1970 rect.width = scale * pix->width;
1935 rect.height = scale * pix->height; 1971 rect.height = scale * pix->height;
1936 1972
1937 if (rect.width < 4) 1973 if (rect.width < 16)
1938 rect.width = 4; 1974 rect.width = 16;
1939 if (rect.height < 4) 1975 if (rect.height < 16)
1940 rect.height = 4; 1976 rect.height = 16;
1941 if (rect.width > bounds->left + bounds->width - rect.left) 1977 if (rect.width > bounds->left + bounds->width - rect.left)
1942 rect.width = bounds->left + bounds->width - rect.left; 1978 rect.width = bounds->left + bounds->width - rect.left;
1943 if (rect.height > bounds->top + bounds->height - rect.top) 1979 if (rect.height > bounds->top + bounds->height - rect.top)
1944 rect.height = bounds->top + bounds->height - rect.top; 1980 rect.height = bounds->top + bounds->height - rect.top;
1945 1981
1946 rect.width &= ~3L; 1982 rect.width &= ~15L;
1947 rect.height &= ~3L; 1983 rect.height &= ~15L;
1948 1984
1949 { /* adjust the scaling factor */ 1985 { /* adjust the scaling factor */
1950 u32 a, b; 1986 u32 a, b;
@@ -2378,6 +2414,9 @@ static int et61x251_ioctl_v4l2(struct inode* inode, struct file* filp,
2378 case VIDIOC_S_FMT: 2414 case VIDIOC_S_FMT:
2379 return et61x251_vidioc_try_s_fmt(cam, cmd, arg); 2415 return et61x251_vidioc_try_s_fmt(cam, cmd, arg);
2380 2416
2417 case VIDIOC_ENUM_FRAMESIZES:
2418 return et61x251_vidioc_enum_framesizes(cam, arg);
2419
2381 case VIDIOC_G_JPEGCOMP: 2420 case VIDIOC_G_JPEGCOMP:
2382 return et61x251_vidioc_g_jpegcomp(cam, arg); 2421 return et61x251_vidioc_g_jpegcomp(cam, arg);
2383 2422
@@ -2413,6 +2452,7 @@ static int et61x251_ioctl_v4l2(struct inode* inode, struct file* filp,
2413 case VIDIOC_QUERYSTD: 2452 case VIDIOC_QUERYSTD:
2414 case VIDIOC_ENUMSTD: 2453 case VIDIOC_ENUMSTD:
2415 case VIDIOC_QUERYMENU: 2454 case VIDIOC_QUERYMENU:
2455 case VIDIOC_ENUM_FRAMEINTERVALS:
2416 return -EINVAL; 2456 return -EINVAL;
2417 2457
2418 default: 2458 default:
@@ -2459,6 +2499,7 @@ static const struct file_operations et61x251_fops = {
2459 .open = et61x251_open, 2499 .open = et61x251_open,
2460 .release = et61x251_release, 2500 .release = et61x251_release,
2461 .ioctl = et61x251_ioctl, 2501 .ioctl = et61x251_ioctl,
2502 .compat_ioctl = v4l_compat_ioctl32,
2462 .read = et61x251_read, 2503 .read = et61x251_read,
2463 .poll = et61x251_poll, 2504 .poll = et61x251_poll,
2464 .mmap = et61x251_mmap, 2505 .mmap = et61x251_mmap,
@@ -2497,7 +2538,7 @@ et61x251_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2497 mutex_init(&cam->dev_mutex); 2538 mutex_init(&cam->dev_mutex);
2498 2539
2499 DBG(2, "ET61X[12]51 PC Camera Controller detected " 2540 DBG(2, "ET61X[12]51 PC Camera Controller detected "
2500 "(vid/pid 0x%04X/0x%04X)",id->idVendor, id->idProduct); 2541 "(vid/pid 0x%04X:0x%04X)",id->idVendor, id->idProduct);
2501 2542
2502 for (i = 0; et61x251_sensor_table[i]; i++) { 2543 for (i = 0; et61x251_sensor_table[i]; i++) {
2503 err = et61x251_sensor_table[i](cam); 2544 err = et61x251_sensor_table[i](cam);
@@ -2550,9 +2591,14 @@ et61x251_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2550 2591
2551#ifdef CONFIG_VIDEO_ADV_DEBUG 2592#ifdef CONFIG_VIDEO_ADV_DEBUG
2552 err = et61x251_create_sysfs(cam); 2593 err = et61x251_create_sysfs(cam);
2553 if (err) 2594 if (!err)
2554 goto fail2; 2595 DBG(2, "Optional device control through 'sysfs' "
2555 DBG(2, "Optional device control through 'sysfs' interface ready"); 2596 "interface ready");
2597 else
2598 DBG(2, "Failed to create 'sysfs' interface for optional "
2599 "device controlling. Error #%d", err);
2600#else
2601 DBG(2, "Optional device control through 'sysfs' interface disabled");
2556#endif 2602#endif
2557 2603
2558 usb_set_intfdata(intf, cam); 2604 usb_set_intfdata(intf, cam);
@@ -2561,13 +2607,6 @@ et61x251_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2561 2607
2562 return 0; 2608 return 0;
2563 2609
2564#ifdef CONFIG_VIDEO_ADV_DEBUG
2565fail2:
2566 video_nr[dev_nr] = -1;
2567 dev_nr = (dev_nr < ET61X251_MAX_DEVICES-1) ? dev_nr+1 : 0;
2568 mutex_unlock(&cam->dev_mutex);
2569 video_unregister_device(cam->v4ldev);
2570#endif
2571fail: 2610fail:
2572 if (cam) { 2611 if (cam) {
2573 kfree(cam->control_buffer); 2612 kfree(cam->control_buffer);
diff --git a/drivers/media/video/et61x251/et61x251_sensor.h b/drivers/media/video/et61x251/et61x251_sensor.h
index 65edd08dc3..5fadb5de68 100644
--- a/drivers/media/video/et61x251/et61x251_sensor.h
+++ b/drivers/media/video/et61x251/et61x251_sensor.h
@@ -1,7 +1,7 @@
1/*************************************************************************** 1/***************************************************************************
2 * API for image sensors connected to ET61X[12]51 PC Camera Controllers * 2 * API for image sensors connected to ET61X[12]51 PC Camera Controllers *
3 * * 3 * *
4 * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> * 4 * Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
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 *
@@ -82,7 +82,7 @@ enum et61x251_i2c_rsta {
82 ET61X251_I2C_RSTA_REPEAT = 0x01, /* repeat start */ 82 ET61X251_I2C_RSTA_REPEAT = 0x01, /* repeat start */
83}; 83};
84 84
85#define ET61X251_MAX_CTRLS V4L2_CID_LASTP1-V4L2_CID_BASE+10 85#define ET61X251_MAX_CTRLS (V4L2_CID_LASTP1-V4L2_CID_BASE+10)
86 86
87struct et61x251_sensor { 87struct et61x251_sensor {
88 char name[32]; 88 char name[32];
diff --git a/drivers/media/video/et61x251/et61x251_tas5130d1b.c b/drivers/media/video/et61x251/et61x251_tas5130d1b.c
index a7d65b82b2..b066434098 100644
--- a/drivers/media/video/et61x251/et61x251_tas5130d1b.c
+++ b/drivers/media/video/et61x251/et61x251_tas5130d1b.c
@@ -2,7 +2,7 @@
2 * Plug-in for TAS5130D1B image sensor connected to the ET61X[12]51 * 2 * Plug-in for TAS5130D1B image sensor connected to the ET61X[12]51 *
3 * PC Camera Controllers * 3 * PC Camera Controllers *
4 * * 4 * *
5 * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> * 5 * Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
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 *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
diff --git a/drivers/media/video/pvrusb2/pvrusb2-audio.c b/drivers/media/video/pvrusb2/pvrusb2-audio.c
index 9846c464ec..379645e481 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-audio.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-audio.c
@@ -31,7 +31,6 @@ struct pvr2_msp3400_handler {
31 struct pvr2_hdw *hdw; 31 struct pvr2_hdw *hdw;
32 struct pvr2_i2c_client *client; 32 struct pvr2_i2c_client *client;
33 struct pvr2_i2c_handler i2c_handler; 33 struct pvr2_i2c_handler i2c_handler;
34 struct pvr2_audio_stat astat;
35 unsigned long stale_mask; 34 unsigned long stale_mask;
36}; 35};
37 36
@@ -44,13 +43,6 @@ static void set_stereo(struct pvr2_msp3400_handler *ctxt)
44 43
45 pvr2_trace(PVR2_TRACE_CHIPS,"i2c msp3400 v4l2 set_stereo"); 44 pvr2_trace(PVR2_TRACE_CHIPS,"i2c msp3400 v4l2 set_stereo");
46 45
47 if (hdw->input_val == PVR2_CVAL_INPUT_TV) {
48 struct v4l2_tuner vt;
49 memset(&vt,0,sizeof(vt));
50 vt.audmode = hdw->audiomode_val;
51 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_S_TUNER,&vt);
52 }
53
54 route.input = MSP_INPUT_DEFAULT; 46 route.input = MSP_INPUT_DEFAULT;
55 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1); 47 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
56 switch (hdw->input_val) { 48 switch (hdw->input_val) {
@@ -78,8 +70,7 @@ static void set_stereo(struct pvr2_msp3400_handler *ctxt)
78static int check_stereo(struct pvr2_msp3400_handler *ctxt) 70static int check_stereo(struct pvr2_msp3400_handler *ctxt)
79{ 71{
80 struct pvr2_hdw *hdw = ctxt->hdw; 72 struct pvr2_hdw *hdw = ctxt->hdw;
81 return (hdw->input_dirty || 73 return hdw->input_dirty;
82 hdw->audiomode_dirty);
83} 74}
84 75
85 76
@@ -99,8 +90,7 @@ static int msp3400_check(struct pvr2_msp3400_handler *ctxt)
99 unsigned long msk; 90 unsigned long msk;
100 unsigned int idx; 91 unsigned int idx;
101 92
102 for (idx = 0; idx < sizeof(msp3400_ops)/sizeof(msp3400_ops[0]); 93 for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) {
103 idx++) {
104 msk = 1 << idx; 94 msk = 1 << idx;
105 if (ctxt->stale_mask & msk) continue; 95 if (ctxt->stale_mask & msk) continue;
106 if (msp3400_ops[idx].check(ctxt)) { 96 if (msp3400_ops[idx].check(ctxt)) {
@@ -116,8 +106,7 @@ static void msp3400_update(struct pvr2_msp3400_handler *ctxt)
116 unsigned long msk; 106 unsigned long msk;
117 unsigned int idx; 107 unsigned int idx;
118 108
119 for (idx = 0; idx < sizeof(msp3400_ops)/sizeof(msp3400_ops[0]); 109 for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) {
120 idx++) {
121 msk = 1 << idx; 110 msk = 1 << idx;
122 if (!(ctxt->stale_mask & msk)) continue; 111 if (!(ctxt->stale_mask & msk)) continue;
123 ctxt->stale_mask &= ~msk; 112 ctxt->stale_mask &= ~msk;
@@ -126,27 +115,9 @@ static void msp3400_update(struct pvr2_msp3400_handler *ctxt)
126} 115}
127 116
128 117
129/* This reads back the current signal type */
130static int get_audio_status(struct pvr2_msp3400_handler *ctxt)
131{
132 struct v4l2_tuner vt;
133 int stat;
134
135 memset(&vt,0,sizeof(vt));
136 stat = pvr2_i2c_client_cmd(ctxt->client,VIDIOC_G_TUNER,&vt);
137 if (stat < 0) return stat;
138
139 ctxt->hdw->flag_stereo = (vt.audmode & V4L2_TUNER_MODE_STEREO) != 0;
140 ctxt->hdw->flag_bilingual =
141 (vt.audmode & V4L2_TUNER_MODE_LANG2) != 0;
142 return 0;
143}
144
145
146static void pvr2_msp3400_detach(struct pvr2_msp3400_handler *ctxt) 118static void pvr2_msp3400_detach(struct pvr2_msp3400_handler *ctxt)
147{ 119{
148 ctxt->client->handler = NULL; 120 ctxt->client->handler = NULL;
149 ctxt->hdw->audio_stat = NULL;
150 kfree(ctxt); 121 kfree(ctxt);
151} 122}
152 123
@@ -158,7 +129,7 @@ static unsigned int pvr2_msp3400_describe(struct pvr2_msp3400_handler *ctxt,
158} 129}
159 130
160 131
161const static struct pvr2_i2c_handler_functions msp3400_funcs = { 132static const struct pvr2_i2c_handler_functions msp3400_funcs = {
162 .detach = (void (*)(void *))pvr2_msp3400_detach, 133 .detach = (void (*)(void *))pvr2_msp3400_detach,
163 .check = (int (*)(void *))msp3400_check, 134 .check = (int (*)(void *))msp3400_check,
164 .update = (void (*)(void *))msp3400_update, 135 .update = (void (*)(void *))msp3400_update,
@@ -169,24 +140,17 @@ const static struct pvr2_i2c_handler_functions msp3400_funcs = {
169int pvr2_i2c_msp3400_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp) 140int pvr2_i2c_msp3400_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
170{ 141{
171 struct pvr2_msp3400_handler *ctxt; 142 struct pvr2_msp3400_handler *ctxt;
172 if (hdw->audio_stat) return 0;
173 if (cp->handler) return 0; 143 if (cp->handler) return 0;
174 144
175 ctxt = kmalloc(sizeof(*ctxt),GFP_KERNEL); 145 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
176 if (!ctxt) return 0; 146 if (!ctxt) return 0;
177 memset(ctxt,0,sizeof(*ctxt));
178 147
179 ctxt->i2c_handler.func_data = ctxt; 148 ctxt->i2c_handler.func_data = ctxt;
180 ctxt->i2c_handler.func_table = &msp3400_funcs; 149 ctxt->i2c_handler.func_table = &msp3400_funcs;
181 ctxt->client = cp; 150 ctxt->client = cp;
182 ctxt->hdw = hdw; 151 ctxt->hdw = hdw;
183 ctxt->astat.ctxt = ctxt; 152 ctxt->stale_mask = (1 << ARRAY_SIZE(msp3400_ops)) - 1;
184 ctxt->astat.status = (int (*)(void *))get_audio_status;
185 ctxt->astat.detach = (void (*)(void *))pvr2_msp3400_detach;
186 ctxt->stale_mask = (1 << (sizeof(msp3400_ops)/
187 sizeof(msp3400_ops[0]))) - 1;
188 cp->handler = &ctxt->i2c_handler; 153 cp->handler = &ctxt->i2c_handler;
189 hdw->audio_stat = &ctxt->astat;
190 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x msp3400 V4L2 handler set up", 154 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x msp3400 V4L2 handler set up",
191 cp->client->addr); 155 cp->client->addr);
192 return !0; 156 return !0;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-context.c b/drivers/media/video/pvrusb2/pvrusb2-context.c
index cf12974620..6bbed88d78 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-context.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-context.c
@@ -83,9 +83,8 @@ struct pvr2_context *pvr2_context_create(
83 void (*setup_func)(struct pvr2_context *)) 83 void (*setup_func)(struct pvr2_context *))
84{ 84{
85 struct pvr2_context *mp = NULL; 85 struct pvr2_context *mp = NULL;
86 mp = kmalloc(sizeof(*mp),GFP_KERNEL); 86 mp = kzalloc(sizeof(*mp),GFP_KERNEL);
87 if (!mp) goto done; 87 if (!mp) goto done;
88 memset(mp,0,sizeof(*mp));
89 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr_main id=%p",mp); 88 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr_main id=%p",mp);
90 mp->setup_func = setup_func; 89 mp->setup_func = setup_func;
91 mutex_init(&mp->mutex); 90 mutex_init(&mp->mutex);
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
index c77de859cc..f569b00201 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
@@ -26,6 +26,27 @@
26#include <linux/mutex.h> 26#include <linux/mutex.h>
27 27
28 28
29static int pvr2_ctrl_range_check(struct pvr2_ctrl *cptr,int val)
30{
31 if (cptr->info->check_value) {
32 if (!cptr->info->check_value(cptr,val)) return -ERANGE;
33 } else {
34 int lim;
35 lim = cptr->info->def.type_int.min_value;
36 if (cptr->info->get_min_value) {
37 cptr->info->get_min_value(cptr,&lim);
38 }
39 if (val < lim) return -ERANGE;
40 lim = cptr->info->def.type_int.max_value;
41 if (cptr->info->get_max_value) {
42 cptr->info->get_max_value(cptr,&lim);
43 }
44 if (val > lim) return -ERANGE;
45 }
46 return 0;
47}
48
49
29/* Set the given control. */ 50/* Set the given control. */
30int pvr2_ctrl_set_value(struct pvr2_ctrl *cptr,int val) 51int pvr2_ctrl_set_value(struct pvr2_ctrl *cptr,int val)
31{ 52{
@@ -43,17 +64,8 @@ int pvr2_ctrl_set_mask_value(struct pvr2_ctrl *cptr,int mask,int val)
43 if (cptr->info->type == pvr2_ctl_bitmask) { 64 if (cptr->info->type == pvr2_ctl_bitmask) {
44 mask &= cptr->info->def.type_bitmask.valid_bits; 65 mask &= cptr->info->def.type_bitmask.valid_bits;
45 } else if (cptr->info->type == pvr2_ctl_int) { 66 } else if (cptr->info->type == pvr2_ctl_int) {
46 int lim; 67 ret = pvr2_ctrl_range_check(cptr,val);
47 lim = cptr->info->def.type_int.min_value; 68 if (ret < 0) break;
48 if (cptr->info->get_min_value) {
49 cptr->info->get_min_value(cptr,&lim);
50 }
51 if (val < lim) 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);
55 }
56 if (val > lim) break;
57 } else if (cptr->info->type == pvr2_ctl_enum) { 69 } else if (cptr->info->type == pvr2_ctl_enum) {
58 if (val >= cptr->info->def.type_enum.count) { 70 if (val >= cptr->info->def.type_enum.count) {
59 break; 71 break;
@@ -498,16 +510,13 @@ int pvr2_ctrl_sym_to_value(struct pvr2_ctrl *cptr,
498 LOCK_TAKE(cptr->hdw->big_lock); do { 510 LOCK_TAKE(cptr->hdw->big_lock); do {
499 if (cptr->info->type == pvr2_ctl_int) { 511 if (cptr->info->type == pvr2_ctl_int) {
500 ret = parse_token(ptr,len,valptr,NULL,0); 512 ret = parse_token(ptr,len,valptr,NULL,0);
501 if ((ret >= 0) && 513 if (ret >= 0) {
502 ((*valptr < cptr->info->def.type_int.min_value) || 514 ret = pvr2_ctrl_range_check(cptr,*valptr);
503 (*valptr > cptr->info->def.type_int.max_value))) {
504 ret = -ERANGE;
505 } 515 }
506 if (maskptr) *maskptr = ~0; 516 if (maskptr) *maskptr = ~0;
507 } else if (cptr->info->type == pvr2_ctl_bool) { 517 } else if (cptr->info->type == pvr2_ctl_bool) {
508 ret = parse_token( 518 ret = parse_token(ptr,len,valptr,boolNames,
509 ptr,len,valptr,boolNames, 519 ARRAY_SIZE(boolNames));
510 sizeof(boolNames)/sizeof(boolNames[0]));
511 if (ret == 1) { 520 if (ret == 1) {
512 *valptr = *valptr ? !0 : 0; 521 *valptr = *valptr ? !0 : 0;
513 } else if (ret == 0) { 522 } else if (ret == 0) {
diff --git a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
index 848fb233d8..e8a9252c7d 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
@@ -63,6 +63,7 @@ static void set_input(struct pvr2_v4l_cx2584x *ctxt)
63 vid_input = CX25840_COMPOSITE7; 63 vid_input = CX25840_COMPOSITE7;
64 aud_input = CX25840_AUDIO8; 64 aud_input = CX25840_AUDIO8;
65 break; 65 break;
66 case PVR2_CVAL_INPUT_RADIO: // Treat same as composite
66 case PVR2_CVAL_INPUT_COMPOSITE: 67 case PVR2_CVAL_INPUT_COMPOSITE:
67 vid_input = CX25840_COMPOSITE3; 68 vid_input = CX25840_COMPOSITE3;
68 aud_input = CX25840_AUDIO_SERIAL; 69 aud_input = CX25840_AUDIO_SERIAL;
@@ -71,7 +72,6 @@ static void set_input(struct pvr2_v4l_cx2584x *ctxt)
71 vid_input = CX25840_SVIDEO1; 72 vid_input = CX25840_SVIDEO1;
72 aud_input = CX25840_AUDIO_SERIAL; 73 aud_input = CX25840_AUDIO_SERIAL;
73 break; 74 break;
74 case PVR2_CVAL_INPUT_RADIO:
75 default: 75 default:
76 // Just set it to be composite input for now... 76 // Just set it to be composite input for now...
77 vid_input = CX25840_COMPOSITE3; 77 vid_input = CX25840_COMPOSITE3;
@@ -150,8 +150,7 @@ static int decoder_check(struct pvr2_v4l_cx2584x *ctxt)
150 unsigned long msk; 150 unsigned long msk;
151 unsigned int idx; 151 unsigned int idx;
152 152
153 for (idx = 0; idx < sizeof(decoder_ops)/sizeof(decoder_ops[0]); 153 for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
154 idx++) {
155 msk = 1 << idx; 154 msk = 1 << idx;
156 if (ctxt->stale_mask & msk) continue; 155 if (ctxt->stale_mask & msk) continue;
157 if (decoder_ops[idx].check(ctxt)) { 156 if (decoder_ops[idx].check(ctxt)) {
@@ -167,8 +166,7 @@ static void decoder_update(struct pvr2_v4l_cx2584x *ctxt)
167 unsigned long msk; 166 unsigned long msk;
168 unsigned int idx; 167 unsigned int idx;
169 168
170 for (idx = 0; idx < sizeof(decoder_ops)/sizeof(decoder_ops[0]); 169 for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
171 idx++) {
172 msk = 1 << idx; 170 msk = 1 << idx;
173 if (!(ctxt->stale_mask & msk)) continue; 171 if (!(ctxt->stale_mask & msk)) continue;
174 ctxt->stale_mask &= ~msk; 172 ctxt->stale_mask &= ~msk;
@@ -199,18 +197,6 @@ static int decoder_detect(struct pvr2_i2c_client *cp)
199} 197}
200 198
201 199
202static int decoder_is_tuned(struct pvr2_v4l_cx2584x *ctxt)
203{
204 struct v4l2_tuner vt;
205 int ret;
206
207 memset(&vt,0,sizeof(vt));
208 ret = pvr2_i2c_client_cmd(ctxt->client,VIDIOC_G_TUNER,&vt);
209 if (ret < 0) return -EINVAL;
210 return vt.signal ? 1 : 0;
211}
212
213
214static unsigned int decoder_describe(struct pvr2_v4l_cx2584x *ctxt, 200static unsigned int decoder_describe(struct pvr2_v4l_cx2584x *ctxt,
215 char *buf,unsigned int cnt) 201 char *buf,unsigned int cnt)
216{ 202{
@@ -226,7 +212,7 @@ static void decoder_reset(struct pvr2_v4l_cx2584x *ctxt)
226} 212}
227 213
228 214
229const static struct pvr2_i2c_handler_functions hfuncs = { 215static const struct pvr2_i2c_handler_functions hfuncs = {
230 .detach = (void (*)(void *))decoder_detach, 216 .detach = (void (*)(void *))decoder_detach,
231 .check = (int (*)(void *))decoder_check, 217 .check = (int (*)(void *))decoder_check,
232 .update = (void (*)(void *))decoder_update, 218 .update = (void (*)(void *))decoder_update,
@@ -243,21 +229,18 @@ int pvr2_i2c_cx2584x_v4l_setup(struct pvr2_hdw *hdw,
243 if (cp->handler) return 0; 229 if (cp->handler) return 0;
244 if (!decoder_detect(cp)) return 0; 230 if (!decoder_detect(cp)) return 0;
245 231
246 ctxt = kmalloc(sizeof(*ctxt),GFP_KERNEL); 232 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
247 if (!ctxt) return 0; 233 if (!ctxt) return 0;
248 memset(ctxt,0,sizeof(*ctxt));
249 234
250 ctxt->handler.func_data = ctxt; 235 ctxt->handler.func_data = ctxt;
251 ctxt->handler.func_table = &hfuncs; 236 ctxt->handler.func_table = &hfuncs;
252 ctxt->ctrl.ctxt = ctxt; 237 ctxt->ctrl.ctxt = ctxt;
253 ctxt->ctrl.detach = (void (*)(void *))decoder_detach; 238 ctxt->ctrl.detach = (void (*)(void *))decoder_detach;
254 ctxt->ctrl.enable = (void (*)(void *,int))decoder_enable; 239 ctxt->ctrl.enable = (void (*)(void *,int))decoder_enable;
255 ctxt->ctrl.tuned = (int (*)(void *))decoder_is_tuned;
256 ctxt->ctrl.force_reset = (void (*)(void*))decoder_reset; 240 ctxt->ctrl.force_reset = (void (*)(void*))decoder_reset;
257 ctxt->client = cp; 241 ctxt->client = cp;
258 ctxt->hdw = hdw; 242 ctxt->hdw = hdw;
259 ctxt->stale_mask = (1 << (sizeof(decoder_ops)/ 243 ctxt->stale_mask = (1 << ARRAY_SIZE(decoder_ops)) - 1;
260 sizeof(decoder_ops[0]))) - 1;
261 hdw->decoder_ctrl = &ctxt->ctrl; 244 hdw->decoder_ctrl = &ctxt->ctrl;
262 cp->handler = &ctxt->handler; 245 cp->handler = &ctxt->handler;
263 { 246 {
diff --git a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
index f985f00d88..e9da9bb8f8 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
@@ -152,7 +152,7 @@ static unsigned long debugifc_find_mask(const char *buf,unsigned int count)
152{ 152{
153 struct debugifc_mask_item *mip; 153 struct debugifc_mask_item *mip;
154 unsigned int idx; 154 unsigned int idx;
155 for (idx = 0; idx < sizeof(mask_items)/sizeof(mask_items[0]); idx++) { 155 for (idx = 0; idx < ARRAY_SIZE(mask_items); idx++) {
156 mip = mask_items + idx; 156 mip = mask_items + idx;
157 if (debugifc_match_keyword(buf,count,mip->name)) { 157 if (debugifc_match_keyword(buf,count,mip->name)) {
158 return mip->msk; 158 return mip->msk;
@@ -169,7 +169,7 @@ static int debugifc_print_mask(char *buf,unsigned int sz,
169 unsigned int idx; 169 unsigned int idx;
170 int bcnt = 0; 170 int bcnt = 0;
171 int ccnt; 171 int ccnt;
172 for (idx = 0; idx < sizeof(mask_items)/sizeof(mask_items[0]); idx++) { 172 for (idx = 0; idx < ARRAY_SIZE(mask_items); idx++) {
173 mip = mask_items + idx; 173 mip = mask_items + idx;
174 if (!(mip->msk & msk)) continue; 174 if (!(mip->msk & msk)) continue;
175 ccnt = scnprintf(buf,sz,"%s%c%s", 175 ccnt = scnprintf(buf,sz,"%s%c%s",
diff --git a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
index 6cff8e75f4..45cbca0143 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
@@ -102,9 +102,8 @@ static u8 *pvr2_eeprom_fetch(struct pvr2_hdw *hdw)
102 } 102 }
103 msg[1].len = pcnt; 103 msg[1].len = pcnt;
104 msg[1].buf = eeprom+tcnt; 104 msg[1].buf = eeprom+tcnt;
105 if ((ret = i2c_transfer( 105 if ((ret = i2c_transfer(&hdw->i2c_adap,
106 &hdw->i2c_adap, 106 msg,ARRAY_SIZE(msg))) != 2) {
107 msg,sizeof(msg)/sizeof(msg[0]))) != 2) {
108 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 107 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
109 "eeprom fetch set offs err=%d",ret); 108 "eeprom fetch set offs err=%d",ret);
110 kfree(eeprom); 109 kfree(eeprom);
diff --git a/drivers/media/video/pvrusb2/pvrusb2-encoder.c b/drivers/media/video/pvrusb2/pvrusb2-encoder.c
index c94f97b793..5786faf9b3 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-encoder.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-encoder.c
@@ -26,6 +26,7 @@
26#include "pvrusb2-encoder.h" 26#include "pvrusb2-encoder.h"
27#include "pvrusb2-hdw-internal.h" 27#include "pvrusb2-hdw-internal.h"
28#include "pvrusb2-debug.h" 28#include "pvrusb2-debug.h"
29#include "pvrusb2-fx2-cmd.h"
29 30
30 31
31 32
@@ -34,34 +35,41 @@
34#define IVTV_MBOX_DRIVER_DONE 0x00000002 35#define IVTV_MBOX_DRIVER_DONE 0x00000002
35#define IVTV_MBOX_DRIVER_BUSY 0x00000001 36#define IVTV_MBOX_DRIVER_BUSY 0x00000001
36 37
38#define MBOX_BASE 0x44
39
37 40
38static int pvr2_encoder_write_words(struct pvr2_hdw *hdw, 41static int pvr2_encoder_write_words(struct pvr2_hdw *hdw,
42 unsigned int offs,
39 const u32 *data, unsigned int dlen) 43 const u32 *data, unsigned int dlen)
40{ 44{
41 unsigned int idx; 45 unsigned int idx,addr;
46 unsigned int bAddr;
42 int ret; 47 int ret;
43 unsigned int offs = 0;
44 unsigned int chunkCnt; 48 unsigned int chunkCnt;
45 49
46 /* 50 /*
47 51
48 Format: First byte must be 0x01. Remaining 32 bit words are 52 Format: First byte must be 0x01. Remaining 32 bit words are
49 spread out into chunks of 7 bytes each, little-endian ordered, 53 spread out into chunks of 7 bytes each, with the first 4 bytes
50 offset at zero within each 2 blank bytes following and a 54 being the data word (little endian), and the next 3 bytes
51 single byte that is 0x44 plus the offset of the word. Repeat 55 being the address where that data word is to be written (big
52 request for additional words, with offset adjusted 56 endian). Repeat request for additional words, with offset
53 accordingly. 57 adjusted accordingly.
54 58
55 */ 59 */
56 while (dlen) { 60 while (dlen) {
57 chunkCnt = 8; 61 chunkCnt = 8;
58 if (chunkCnt > dlen) chunkCnt = dlen; 62 if (chunkCnt > dlen) chunkCnt = dlen;
59 memset(hdw->cmd_buffer,0,sizeof(hdw->cmd_buffer)); 63 memset(hdw->cmd_buffer,0,sizeof(hdw->cmd_buffer));
60 hdw->cmd_buffer[0] = 0x01; 64 bAddr = 0;
65 hdw->cmd_buffer[bAddr++] = FX2CMD_MEM_WRITE_DWORD;
61 for (idx = 0; idx < chunkCnt; idx++) { 66 for (idx = 0; idx < chunkCnt; idx++) {
62 hdw->cmd_buffer[1+(idx*7)+6] = 0x44 + idx + offs; 67 addr = idx + offs;
63 PVR2_DECOMPOSE_LE(hdw->cmd_buffer, 1+(idx*7), 68 hdw->cmd_buffer[bAddr+6] = (addr & 0xffu);
64 data[idx]); 69 hdw->cmd_buffer[bAddr+5] = ((addr>>8) & 0xffu);
70 hdw->cmd_buffer[bAddr+4] = ((addr>>16) & 0xffu);
71 PVR2_DECOMPOSE_LE(hdw->cmd_buffer, bAddr,data[idx]);
72 bAddr += 7;
65 } 73 }
66 ret = pvr2_send_request(hdw, 74 ret = pvr2_send_request(hdw,
67 hdw->cmd_buffer,1+(chunkCnt*7), 75 hdw->cmd_buffer,1+(chunkCnt*7),
@@ -76,33 +84,42 @@ static int pvr2_encoder_write_words(struct pvr2_hdw *hdw,
76} 84}
77 85
78 86
79static int pvr2_encoder_read_words(struct pvr2_hdw *hdw,int statusFl, 87static int pvr2_encoder_read_words(struct pvr2_hdw *hdw,
88 unsigned int offs,
80 u32 *data, unsigned int dlen) 89 u32 *data, unsigned int dlen)
81{ 90{
82 unsigned int idx; 91 unsigned int idx;
83 int ret; 92 int ret;
84 unsigned int offs = 0;
85 unsigned int chunkCnt; 93 unsigned int chunkCnt;
86 94
87 /* 95 /*
88 96
89 Format: First byte must be 0x02 (status check) or 0x28 (read 97 Format: First byte must be 0x02 (status check) or 0x28 (read
90 back block of 32 bit words). Next 6 bytes must be zero, 98 back block of 32 bit words). Next 6 bytes must be zero,
91 followed by a single byte of 0x44+offset for portion to be 99 followed by a single byte of MBOX_BASE+offset for portion to
92 read. Returned data is packed set of 32 bits words that were 100 be read. Returned data is packed set of 32 bits words that
93 read. 101 were read.
94 102
95 */ 103 */
96 104
97 while (dlen) { 105 while (dlen) {
98 chunkCnt = 16; 106 chunkCnt = 16;
99 if (chunkCnt > dlen) chunkCnt = dlen; 107 if (chunkCnt > dlen) chunkCnt = dlen;
100 memset(hdw->cmd_buffer,0,sizeof(hdw->cmd_buffer)); 108 if (chunkCnt < 16) chunkCnt = 1;
101 hdw->cmd_buffer[0] = statusFl ? 0x02 : 0x28; 109 hdw->cmd_buffer[0] =
102 hdw->cmd_buffer[7] = 0x44 + offs; 110 ((chunkCnt == 1) ?
111 FX2CMD_MEM_READ_DWORD : FX2CMD_MEM_READ_64BYTES);
112 hdw->cmd_buffer[1] = 0;
113 hdw->cmd_buffer[2] = 0;
114 hdw->cmd_buffer[3] = 0;
115 hdw->cmd_buffer[4] = 0;
116 hdw->cmd_buffer[5] = ((offs>>16) & 0xffu);
117 hdw->cmd_buffer[6] = ((offs>>8) & 0xffu);
118 hdw->cmd_buffer[7] = (offs & 0xffu);
103 ret = pvr2_send_request(hdw, 119 ret = pvr2_send_request(hdw,
104 hdw->cmd_buffer,8, 120 hdw->cmd_buffer,8,
105 hdw->cmd_buffer,chunkCnt * 4); 121 hdw->cmd_buffer,
122 (chunkCnt == 1 ? 4 : 16 * 4));
106 if (ret) return ret; 123 if (ret) return ret;
107 124
108 for (idx = 0; idx < chunkCnt; idx++) { 125 for (idx = 0; idx < chunkCnt; idx++) {
@@ -129,6 +146,8 @@ static int pvr2_encoder_cmd(void *ctxt,
129 u32 *argp) 146 u32 *argp)
130{ 147{
131 unsigned int poll_count; 148 unsigned int poll_count;
149 unsigned int try_count = 0;
150 int retry_flag;
132 int ret = 0; 151 int ret = 0;
133 unsigned int idx; 152 unsigned int idx;
134 /* These sizes look to be limited by the FX2 firmware implementation */ 153 /* These sizes look to be limited by the FX2 firmware implementation */
@@ -140,14 +159,15 @@ static int pvr2_encoder_cmd(void *ctxt,
140 /* 159 /*
141 160
142 The encoder seems to speak entirely using blocks 32 bit words. 161 The encoder seems to speak entirely using blocks 32 bit words.
143 In ivtv driver terms, this is a mailbox which we populate with 162 In ivtv driver terms, this is a mailbox at MBOX_BASE which we
144 data and watch what the hardware does with it. The first word 163 populate with data and watch what the hardware does with it.
145 is a set of flags used to control the transaction, the second 164 The first word is a set of flags used to control the
146 word is the command to execute, the third byte is zero (ivtv 165 transaction, the second word is the command to execute, the
147 driver suggests that this is some kind of return value), and 166 third byte is zero (ivtv driver suggests that this is some
148 the fourth byte is a specified timeout (windows driver always 167 kind of return value), and the fourth byte is a specified
149 uses 0x00060000 except for one case when it is zero). All 168 timeout (windows driver always uses 0x00060000 except for one
150 successive words are the argument words for the command. 169 case when it is zero). All successive words are the argument
170 words for the command.
151 171
152 First, write out the entire set of words, with the first word 172 First, write out the entire set of words, with the first word
153 being zero. 173 being zero.
@@ -156,44 +176,42 @@ static int pvr2_encoder_cmd(void *ctxt,
156 IVTV_MBOX_DRIVER_DONE | IVTV_DRIVER_BUSY this time (which 176 IVTV_MBOX_DRIVER_DONE | IVTV_DRIVER_BUSY this time (which
157 probably means "go"). 177 probably means "go").
158 178
159 Next, read back 16 words as status. Check the first word, 179 Next, read back the return count words. Check the first word,
160 which should have IVTV_MBOX_FIRMWARE_DONE set. If however 180 which should have IVTV_MBOX_FIRMWARE_DONE set. If however
161 that bit is not set, then the command isn't done so repeat the 181 that bit is not set, then the command isn't done so repeat the
162 read. 182 read until it is set.
163
164 Next, read back 32 words and compare with the original
165 arugments. Hopefully they will match.
166 183
167 Finally, write out just the first word again, but set it to 184 Finally, write out just the first word again, but set it to
168 0x0 this time (which probably means "idle"). 185 0x0 this time (which probably means "idle").
169 186
170 */ 187 */
171 188
172 if (arg_cnt_send > (sizeof(wrData)/sizeof(wrData[0]))-4) { 189 if (arg_cnt_send > (ARRAY_SIZE(wrData) - 4)) {
173 pvr2_trace( 190 pvr2_trace(
174 PVR2_TRACE_ERROR_LEGS, 191 PVR2_TRACE_ERROR_LEGS,
175 "Failed to write cx23416 command" 192 "Failed to write cx23416 command"
176 " - too many input arguments" 193 " - too many input arguments"
177 " (was given %u limit %u)", 194 " (was given %u limit %lu)",
178 arg_cnt_send, 195 arg_cnt_send, (long unsigned) ARRAY_SIZE(wrData) - 4);
179 (unsigned int)(sizeof(wrData)/sizeof(wrData[0])) - 4);
180 return -EINVAL; 196 return -EINVAL;
181 } 197 }
182 198
183 if (arg_cnt_recv > (sizeof(rdData)/sizeof(rdData[0]))-4) { 199 if (arg_cnt_recv > (ARRAY_SIZE(rdData) - 4)) {
184 pvr2_trace( 200 pvr2_trace(
185 PVR2_TRACE_ERROR_LEGS, 201 PVR2_TRACE_ERROR_LEGS,
186 "Failed to write cx23416 command" 202 "Failed to write cx23416 command"
187 " - too many return arguments" 203 " - too many return arguments"
188 " (was given %u limit %u)", 204 " (was given %u limit %lu)",
189 arg_cnt_recv, 205 arg_cnt_recv, (long unsigned) ARRAY_SIZE(rdData) - 4);
190 (unsigned int)(sizeof(rdData)/sizeof(rdData[0])) - 4);
191 return -EINVAL; 206 return -EINVAL;
192 } 207 }
193 208
194 209
195 LOCK_TAKE(hdw->ctl_lock); do { 210 LOCK_TAKE(hdw->ctl_lock); do {
196 211
212 retry_flag = 0;
213 try_count++;
214 ret = 0;
197 wrData[0] = 0; 215 wrData[0] = 0;
198 wrData[1] = cmd; 216 wrData[1] = cmd;
199 wrData[2] = 0; 217 wrData[2] = 0;
@@ -201,59 +219,74 @@ static int pvr2_encoder_cmd(void *ctxt,
201 for (idx = 0; idx < arg_cnt_send; idx++) { 219 for (idx = 0; idx < arg_cnt_send; idx++) {
202 wrData[idx+4] = argp[idx]; 220 wrData[idx+4] = argp[idx];
203 } 221 }
204 for (; idx < (sizeof(wrData)/sizeof(wrData[0]))-4; idx++) { 222 for (; idx < ARRAY_SIZE(wrData) - 4; idx++) {
205 wrData[idx+4] = 0; 223 wrData[idx+4] = 0;
206 } 224 }
207 225
208 ret = pvr2_encoder_write_words(hdw,wrData,idx); 226 ret = pvr2_encoder_write_words(hdw,MBOX_BASE,wrData,idx);
209 if (ret) break; 227 if (ret) break;
210 wrData[0] = IVTV_MBOX_DRIVER_DONE|IVTV_MBOX_DRIVER_BUSY; 228 wrData[0] = IVTV_MBOX_DRIVER_DONE|IVTV_MBOX_DRIVER_BUSY;
211 ret = pvr2_encoder_write_words(hdw,wrData,1); 229 ret = pvr2_encoder_write_words(hdw,MBOX_BASE,wrData,1);
212 if (ret) break; 230 if (ret) break;
213 poll_count = 0; 231 poll_count = 0;
214 while (1) { 232 while (1) {
215 if (poll_count < 10000000) poll_count++; 233 poll_count++;
216 ret = pvr2_encoder_read_words(hdw,!0,rdData,1); 234 ret = pvr2_encoder_read_words(hdw,MBOX_BASE,rdData,
217 if (ret) break; 235 arg_cnt_recv+4);
236 if (ret) {
237 break;
238 }
218 if (rdData[0] & IVTV_MBOX_FIRMWARE_DONE) { 239 if (rdData[0] & IVTV_MBOX_FIRMWARE_DONE) {
219 break; 240 break;
220 } 241 }
221 if (poll_count == 100) { 242 if (rdData[0] && (poll_count < 1000)) continue;
243 if (!rdData[0]) {
244 retry_flag = !0;
222 pvr2_trace( 245 pvr2_trace(
223 PVR2_TRACE_ERROR_LEGS, 246 PVR2_TRACE_ERROR_LEGS,
224 "***WARNING*** device's encoder" 247 "Encoder timed out waiting for us"
225 " appears to be stuck" 248 "; arranging to retry");
226 " (status=0%08x)",rdData[0]); 249 } else {
227 pvr2_trace( 250 pvr2_trace(
228 PVR2_TRACE_ERROR_LEGS, 251 PVR2_TRACE_ERROR_LEGS,
229 "Encoder command: 0x%02x",cmd); 252 "***WARNING*** device's encoder"
230 for (idx = 4; idx < arg_cnt_send; idx++) { 253 " appears to be stuck"
231 pvr2_trace( 254 " (status=0x%08x)",rdData[0]);
232 PVR2_TRACE_ERROR_LEGS, 255 }
233 "Encoder arg%d: 0x%08x", 256 pvr2_trace(
234 idx-3,wrData[idx]); 257 PVR2_TRACE_ERROR_LEGS,
235 } 258 "Encoder command: 0x%02x",cmd);
259 for (idx = 4; idx < arg_cnt_send; idx++) {
236 pvr2_trace( 260 pvr2_trace(
237 PVR2_TRACE_ERROR_LEGS, 261 PVR2_TRACE_ERROR_LEGS,
238 "Giving up waiting." 262 "Encoder arg%d: 0x%08x",
239 " It is likely that" 263 idx-3,wrData[idx]);
240 " this is a bad idea...");
241 ret = -EBUSY;
242 break;
243 } 264 }
265 ret = -EBUSY;
266 break;
267 }
268 if (retry_flag) {
269 if (try_count < 20) continue;
270 pvr2_trace(
271 PVR2_TRACE_ERROR_LEGS,
272 "Too many retries...");
273 ret = -EBUSY;
274 }
275 if (ret) {
276 pvr2_trace(
277 PVR2_TRACE_ERROR_LEGS,
278 "Giving up on command."
279 " It is likely that"
280 " this is a bad idea...");
281 break;
244 } 282 }
245 if (ret) break;
246 wrData[0] = 0x7; 283 wrData[0] = 0x7;
247 ret = pvr2_encoder_read_words(
248 hdw,0,rdData,
249 sizeof(rdData)/sizeof(rdData[0]));
250 if (ret) break;
251 for (idx = 0; idx < arg_cnt_recv; idx++) { 284 for (idx = 0; idx < arg_cnt_recv; idx++) {
252 argp[idx] = rdData[idx+4]; 285 argp[idx] = rdData[idx+4];
253 } 286 }
254 287
255 wrData[0] = 0x0; 288 wrData[0] = 0x0;
256 ret = pvr2_encoder_write_words(hdw,wrData,1); 289 ret = pvr2_encoder_write_words(hdw,MBOX_BASE,wrData,1);
257 if (ret) break; 290 if (ret) break;
258 291
259 } while(0); LOCK_GIVE(hdw->ctl_lock); 292 } while(0); LOCK_GIVE(hdw->ctl_lock);
@@ -269,13 +302,13 @@ static int pvr2_encoder_vcmd(struct pvr2_hdw *hdw, int cmd,
269 unsigned int idx; 302 unsigned int idx;
270 u32 data[12]; 303 u32 data[12];
271 304
272 if (args > sizeof(data)/sizeof(data[0])) { 305 if (args > ARRAY_SIZE(data)) {
273 pvr2_trace( 306 pvr2_trace(
274 PVR2_TRACE_ERROR_LEGS, 307 PVR2_TRACE_ERROR_LEGS,
275 "Failed to write cx23416 command" 308 "Failed to write cx23416 command"
276 " - too many arguments" 309 " - too many arguments"
277 " (was given %u limit %u)", 310 " (was given %u limit %lu)",
278 args,(unsigned int)(sizeof(data)/sizeof(data[0]))); 311 args, (long unsigned) ARRAY_SIZE(data));
279 return -EINVAL; 312 return -EINVAL;
280 } 313 }
281 314
@@ -288,6 +321,73 @@ static int pvr2_encoder_vcmd(struct pvr2_hdw *hdw, int cmd,
288 return pvr2_encoder_cmd(hdw,cmd,args,0,data); 321 return pvr2_encoder_cmd(hdw,cmd,args,0,data);
289} 322}
290 323
324
325/* This implements some extra setup for the encoder that seems to be
326 specific to the PVR USB2 hardware. */
327int pvr2_encoder_prep_config(struct pvr2_hdw *hdw)
328{
329 int ret = 0;
330 int encMisc3Arg = 0;
331
332#if 0
333 /* This inexplicable bit happens in the Hauppage windows
334 driver (for both 24xxx and 29xxx devices). However I
335 currently see no difference in behavior with or without
336 this stuff. Leave this here as a note of its existence,
337 but don't use it. */
338 LOCK_TAKE(hdw->ctl_lock); do {
339 u32 dat[1];
340 dat[0] = 0x80000640;
341 pvr2_encoder_write_words(hdw,0x01fe,dat,1);
342 pvr2_encoder_write_words(hdw,0x023e,dat,1);
343 } while(0); LOCK_GIVE(hdw->ctl_lock);
344#endif
345
346 /* Mike Isely <isely@pobox.com> 26-Jan-2006 The windows driver
347 sends the following list of ENC_MISC commands (for both
348 24xxx and 29xxx devices). Meanings are not entirely clear,
349 however without the ENC_MISC(3,1) command then we risk
350 random perpetual video corruption whenever the video input
351 breaks up for a moment (like when switching channels). */
352
353
354#if 0
355 /* This ENC_MISC(5,0) command seems to hurt 29xxx sync
356 performance on channel changes, but is not a problem on
357 24xxx devices. */
358 ret |= pvr2_encoder_vcmd(hdw, CX2341X_ENC_MISC,4, 5,0,0,0);
359#endif
360
361 /* This ENC_MISC(3,encMisc3Arg) command is critical - without
362 it there will eventually be video corruption. Also, the
363 29xxx case is strange - the Windows driver is passing 1
364 regardless of device type but if we have 1 for 29xxx device
365 the video turns sluggish. */
366 switch (hdw->hdw_type) {
367 case PVR2_HDW_TYPE_24XXX: encMisc3Arg = 1; break;
368 case PVR2_HDW_TYPE_29XXX: encMisc3Arg = 0; break;
369 default: break;
370 }
371 ret |= pvr2_encoder_vcmd(hdw, CX2341X_ENC_MISC,4, 3,
372 encMisc3Arg,0,0);
373
374 ret |= pvr2_encoder_vcmd(hdw, CX2341X_ENC_MISC,4, 8,0,0,0);
375
376#if 0
377 /* This ENC_MISC(4,1) command is poisonous, so it is commented
378 out. But I'm leaving it here anyway to document its
379 existence in the Windows driver. The effect of this
380 command is that apps displaying the stream become sluggish
381 with stuttering video. */
382 ret |= pvr2_encoder_vcmd(hdw, CX2341X_ENC_MISC,4, 4,1,0,0);
383#endif
384
385 ret |= pvr2_encoder_vcmd(hdw, CX2341X_ENC_MISC,4, 0,3,0,0);
386 ret |= pvr2_encoder_vcmd(hdw, CX2341X_ENC_MISC,4,15,0,0,0);
387
388 return ret;
389}
390
291int pvr2_encoder_configure(struct pvr2_hdw *hdw) 391int pvr2_encoder_configure(struct pvr2_hdw *hdw)
292{ 392{
293 int ret; 393 int ret;
@@ -302,6 +402,8 @@ int pvr2_encoder_configure(struct pvr2_hdw *hdw)
302 402
303 ret = 0; 403 ret = 0;
304 404
405 ret |= pvr2_encoder_prep_config(hdw);
406
305 if (!ret) ret = pvr2_encoder_vcmd( 407 if (!ret) ret = pvr2_encoder_vcmd(
306 hdw,CX2341X_ENC_SET_NUM_VSYNC_LINES, 2, 408 hdw,CX2341X_ENC_SET_NUM_VSYNC_LINES, 2,
307 0xf0, 0xf0); 409 0xf0, 0xf0);
@@ -360,15 +462,22 @@ int pvr2_encoder_start(struct pvr2_hdw *hdw)
360 pvr2_hdw_gpio_chg_dir(hdw,0xffffffff,0x00000481); 462 pvr2_hdw_gpio_chg_dir(hdw,0xffffffff,0x00000481);
361 pvr2_hdw_gpio_chg_out(hdw,0xffffffff,0x00000000); 463 pvr2_hdw_gpio_chg_out(hdw,0xffffffff,0x00000000);
362 464
363 if (hdw->config == pvr2_config_vbi) { 465 pvr2_encoder_vcmd(hdw,CX2341X_ENC_MUTE_VIDEO,1,
466 hdw->input_val == PVR2_CVAL_INPUT_RADIO ? 1 : 0);
467
468 switch (hdw->config) {
469 case pvr2_config_vbi:
364 status = pvr2_encoder_vcmd(hdw,CX2341X_ENC_START_CAPTURE,2, 470 status = pvr2_encoder_vcmd(hdw,CX2341X_ENC_START_CAPTURE,2,
365 0x01,0x14); 471 0x01,0x14);
366 } else if (hdw->config == pvr2_config_mpeg) { 472 break;
473 case pvr2_config_mpeg:
367 status = pvr2_encoder_vcmd(hdw,CX2341X_ENC_START_CAPTURE,2, 474 status = pvr2_encoder_vcmd(hdw,CX2341X_ENC_START_CAPTURE,2,
368 0,0x13); 475 0,0x13);
369 } else { 476 break;
477 default: /* Unhandled cases for now */
370 status = pvr2_encoder_vcmd(hdw,CX2341X_ENC_START_CAPTURE,2, 478 status = pvr2_encoder_vcmd(hdw,CX2341X_ENC_START_CAPTURE,2,
371 0,0x13); 479 0,0x13);
480 break;
372 } 481 }
373 if (!status) { 482 if (!status) {
374 hdw->subsys_enabled_mask |= (1<<PVR2_SUBSYS_B_ENC_RUN); 483 hdw->subsys_enabled_mask |= (1<<PVR2_SUBSYS_B_ENC_RUN);
@@ -383,15 +492,19 @@ int pvr2_encoder_stop(struct pvr2_hdw *hdw)
383 /* mask all interrupts */ 492 /* mask all interrupts */
384 pvr2_write_register(hdw, 0x0048, 0xffffffff); 493 pvr2_write_register(hdw, 0x0048, 0xffffffff);
385 494
386 if (hdw->config == pvr2_config_vbi) { 495 switch (hdw->config) {
496 case pvr2_config_vbi:
387 status = pvr2_encoder_vcmd(hdw,CX2341X_ENC_STOP_CAPTURE,3, 497 status = pvr2_encoder_vcmd(hdw,CX2341X_ENC_STOP_CAPTURE,3,
388 0x01,0x01,0x14); 498 0x01,0x01,0x14);
389 } else if (hdw->config == pvr2_config_mpeg) { 499 break;
500 case pvr2_config_mpeg:
390 status = pvr2_encoder_vcmd(hdw,CX2341X_ENC_STOP_CAPTURE,3, 501 status = pvr2_encoder_vcmd(hdw,CX2341X_ENC_STOP_CAPTURE,3,
391 0x01,0,0x13); 502 0x01,0,0x13);
392 } else { 503 break;
504 default: /* Unhandled cases for now */
393 status = pvr2_encoder_vcmd(hdw,CX2341X_ENC_STOP_CAPTURE,3, 505 status = pvr2_encoder_vcmd(hdw,CX2341X_ENC_STOP_CAPTURE,3,
394 0x01,0,0x13); 506 0x01,0,0x13);
507 break;
395 } 508 }
396 509
397 /* change some GPIO data */ 510 /* change some GPIO data */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-fx2-cmd.h b/drivers/media/video/pvrusb2/pvrusb2-fx2-cmd.h
new file mode 100644
index 0000000000..ffbc6d0961
--- /dev/null
+++ b/drivers/media/video/pvrusb2/pvrusb2-fx2-cmd.h
@@ -0,0 +1,62 @@
1/*
2 *
3 * $Id$
4 *
5 * Copyright (C) 2007 Michael Krufky <mkrufky@linuxtv.org>
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
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#ifndef _PVRUSB2_FX2_CMD_H_
23#define _PVRUSB2_FX2_CMD_H_
24
25#define FX2CMD_MEM_WRITE_DWORD 0x01
26#define FX2CMD_MEM_READ_DWORD 0x02
27
28#define FX2CMD_MEM_READ_64BYTES 0x28
29
30#define FX2CMD_REG_WRITE 0x04
31#define FX2CMD_REG_READ 0x05
32#define FX2CMD_MEMSEL 0x06
33
34#define FX2CMD_I2C_WRITE 0x08
35#define FX2CMD_I2C_READ 0x09
36
37#define FX2CMD_GET_USB_SPEED 0x0b
38
39#define FX2CMD_STREAMING_ON 0x36
40#define FX2CMD_STREAMING_OFF 0x37
41
42#define FX2CMD_FWPOST1 0x52
43
44#define FX2CMD_POWER_OFF 0xdc
45#define FX2CMD_POWER_ON 0xde
46
47#define FX2CMD_DEEP_RESET 0xdd
48
49#define FX2CMD_GET_EEPROM_ADDR 0xeb
50#define FX2CMD_GET_IR_CODE 0xec
51
52#endif /* _PVRUSB2_FX2_CMD_H_ */
53
54/*
55 Stuff for Emacs to see, in order to encourage consistent editing style:
56 *** Local Variables: ***
57 *** mode: c ***
58 *** fill-column: 75 ***
59 *** tab-width: 8 ***
60 *** c-basic-offset: 8 ***
61 *** End: ***
62 */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
index 34b08fbcc6..16bd741996 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
@@ -60,6 +60,7 @@ struct pvr2_decoder;
60 60
61typedef int (*pvr2_ctlf_is_dirty)(struct pvr2_ctrl *); 61typedef int (*pvr2_ctlf_is_dirty)(struct pvr2_ctrl *);
62typedef void (*pvr2_ctlf_clear_dirty)(struct pvr2_ctrl *); 62typedef void (*pvr2_ctlf_clear_dirty)(struct pvr2_ctrl *);
63typedef int (*pvr2_ctlf_check_value)(struct pvr2_ctrl *,int);
63typedef int (*pvr2_ctlf_get_value)(struct pvr2_ctrl *,int *); 64typedef int (*pvr2_ctlf_get_value)(struct pvr2_ctrl *,int *);
64typedef int (*pvr2_ctlf_set_value)(struct pvr2_ctrl *,int msk,int val); 65typedef int (*pvr2_ctlf_set_value)(struct pvr2_ctrl *,int msk,int val);
65typedef int (*pvr2_ctlf_val_to_sym)(struct pvr2_ctrl *,int msk,int val, 66typedef int (*pvr2_ctlf_val_to_sym)(struct pvr2_ctrl *,int msk,int val,
@@ -83,6 +84,7 @@ struct pvr2_ctl_info {
83 pvr2_ctlf_get_value get_min_value; /* Get minimum allowed value */ 84 pvr2_ctlf_get_value get_min_value; /* Get minimum allowed value */
84 pvr2_ctlf_get_value get_max_value; /* Get maximum allowed value */ 85 pvr2_ctlf_get_value get_max_value; /* Get maximum allowed value */
85 pvr2_ctlf_set_value set_value; /* Set its value */ 86 pvr2_ctlf_set_value set_value; /* Set its value */
87 pvr2_ctlf_check_value check_value; /* Check that value is valid */
86 pvr2_ctlf_val_to_sym val_to_sym; /* Custom convert value->symbol */ 88 pvr2_ctlf_val_to_sym val_to_sym; /* Custom convert value->symbol */
87 pvr2_ctlf_sym_to_val sym_to_val; /* Custom convert symbol->value */ 89 pvr2_ctlf_sym_to_val sym_to_val; /* Custom convert symbol->value */
88 pvr2_ctlf_is_dirty is_dirty; /* Return true if dirty */ 90 pvr2_ctlf_is_dirty is_dirty; /* Return true if dirty */
@@ -135,17 +137,10 @@ struct pvr2_ctrl {
135}; 137};
136 138
137 139
138struct pvr2_audio_stat {
139 void *ctxt;
140 void (*detach)(void *);
141 int (*status)(void *);
142};
143
144struct pvr2_decoder_ctrl { 140struct pvr2_decoder_ctrl {
145 void *ctxt; 141 void *ctxt;
146 void (*detach)(void *); 142 void (*detach)(void *);
147 void (*enable)(void *,int); 143 void (*enable)(void *,int);
148 int (*tuned)(void *);
149 void (*force_reset)(void *); 144 void (*force_reset)(void *);
150}; 145};
151 146
@@ -212,7 +207,6 @@ struct pvr2_hdw {
212 /* Frequency table */ 207 /* Frequency table */
213 unsigned int freqTable[FREQTABLE_SIZE]; 208 unsigned int freqTable[FREQTABLE_SIZE];
214 unsigned int freqProgSlot; 209 unsigned int freqProgSlot;
215 unsigned int freqSlot;
216 210
217 /* Stuff for handling low level control interaction with device */ 211 /* Stuff for handling low level control interaction with device */
218 struct mutex ctl_lock_mutex; 212 struct mutex ctl_lock_mutex;
@@ -258,9 +252,17 @@ struct pvr2_hdw {
258 /* Tuner / frequency control stuff */ 252 /* Tuner / frequency control stuff */
259 unsigned int tuner_type; 253 unsigned int tuner_type;
260 int tuner_updated; 254 int tuner_updated;
261 unsigned int freqVal; 255 unsigned int freqValTelevision; /* Current freq for tv mode */
256 unsigned int freqValRadio; /* Current freq for radio mode */
257 unsigned int freqSlotTelevision; /* Current slot for tv mode */
258 unsigned int freqSlotRadio; /* Current slot for radio mode */
259 unsigned int freqSelector; /* 0=radio 1=television */
262 int freqDirty; 260 int freqDirty;
263 261
262 /* Current tuner info - this information is polled from the I2C bus */
263 struct v4l2_tuner tuner_signal_info;
264 int tuner_signal_stale;
265
264 /* Video standard handling */ 266 /* Video standard handling */
265 v4l2_std_id std_mask_eeprom; // Hardware supported selections 267 v4l2_std_id std_mask_eeprom; // Hardware supported selections
266 v4l2_std_id std_mask_avail; // Which standards we may select from 268 v4l2_std_id std_mask_avail; // Which standards we may select from
@@ -281,20 +283,17 @@ struct pvr2_hdw {
281 int unit_number; /* ID for driver instance */ 283 int unit_number; /* ID for driver instance */
282 unsigned long serial_number; /* ID for hardware itself */ 284 unsigned long serial_number; /* ID for hardware itself */
283 285
284 /* Minor number used by v4l logic (yes, this is a hack, as there should 286 /* Minor numbers used by v4l logic (yes, this is a hack, as there
285 be no v4l junk here). Probably a better way to do this. */ 287 should be no v4l junk here). Probably a better way to do this. */
286 int v4l_minor_number; 288 int v4l_minor_number_video;
289 int v4l_minor_number_vbi;
290 int v4l_minor_number_radio;
287 291
288 /* Location of eeprom or a negative number if none */ 292 /* Location of eeprom or a negative number if none */
289 int eeprom_addr; 293 int eeprom_addr;
290 294
291 enum pvr2_config config; 295 enum pvr2_config config;
292 296
293 /* Information about what audio signal we're hearing */
294 int flag_stereo;
295 int flag_bilingual;
296 struct pvr2_audio_stat *audio_stat;
297
298 /* Control state needed for cx2341x module */ 297 /* Control state needed for cx2341x module */
299 struct cx2341x_mpeg_params enc_cur_state; 298 struct cx2341x_mpeg_params enc_cur_state;
300 struct cx2341x_mpeg_params enc_ctl_state; 299 struct cx2341x_mpeg_params enc_ctl_state;
@@ -327,6 +326,9 @@ struct pvr2_hdw {
327 unsigned int control_cnt; 326 unsigned int control_cnt;
328}; 327};
329 328
329/* This function gets the current frequency */
330unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *);
331
330#endif /* __PVRUSB2_HDW_INTERNAL_H */ 332#endif /* __PVRUSB2_HDW_INTERNAL_H */
331 333
332/* 334/*
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index d200496518..1ff5138e4b 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -36,6 +36,10 @@
36#include "pvrusb2-hdw-internal.h" 36#include "pvrusb2-hdw-internal.h"
37#include "pvrusb2-encoder.h" 37#include "pvrusb2-encoder.h"
38#include "pvrusb2-debug.h" 38#include "pvrusb2-debug.h"
39#include "pvrusb2-fx2-cmd.h"
40
41#define TV_MIN_FREQ 55250000L
42#define TV_MAX_FREQ 850000000L
39 43
40struct usb_device_id pvr2_device_table[] = { 44struct usb_device_id pvr2_device_table[] = {
41 [PVR2_HDW_TYPE_29XXX] = { USB_DEVICE(0x2040, 0x2900) }, 45 [PVR2_HDW_TYPE_29XXX] = { USB_DEVICE(0x2040, 0x2900) },
@@ -71,12 +75,10 @@ static const char *pvr2_client_29xxx[] = {
71 75
72static struct pvr2_string_table pvr2_client_lists[] = { 76static struct pvr2_string_table pvr2_client_lists[] = {
73 [PVR2_HDW_TYPE_29XXX] = { 77 [PVR2_HDW_TYPE_29XXX] = {
74 pvr2_client_29xxx, 78 pvr2_client_29xxx, ARRAY_SIZE(pvr2_client_29xxx)
75 sizeof(pvr2_client_29xxx)/sizeof(pvr2_client_29xxx[0]),
76 }, 79 },
77 [PVR2_HDW_TYPE_24XXX] = { 80 [PVR2_HDW_TYPE_24XXX] = {
78 pvr2_client_24xxx, 81 pvr2_client_24xxx, ARRAY_SIZE(pvr2_client_24xxx)
79 sizeof(pvr2_client_24xxx)/sizeof(pvr2_client_24xxx[0]),
80 }, 82 },
81}; 83};
82 84
@@ -160,9 +162,6 @@ static const struct pvr2_mpeg_ids mpeg_ids[] = {
160 .strid = "video_gop_closure", 162 .strid = "video_gop_closure",
161 .id = V4L2_CID_MPEG_VIDEO_GOP_CLOSURE, 163 .id = V4L2_CID_MPEG_VIDEO_GOP_CLOSURE,
162 },{ 164 },{
163 .strid = "video_pulldown",
164 .id = V4L2_CID_MPEG_VIDEO_PULLDOWN,
165 },{
166 .strid = "video_bitrate_mode", 165 .strid = "video_bitrate_mode",
167 .id = V4L2_CID_MPEG_VIDEO_BITRATE_MODE, 166 .id = V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
168 },{ 167 },{
@@ -212,7 +211,7 @@ static const struct pvr2_mpeg_ids mpeg_ids[] = {
212 .id = V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM, 211 .id = V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM,
213 } 212 }
214}; 213};
215#define MPEGDEF_COUNT (sizeof(mpeg_ids)/sizeof(mpeg_ids[0])) 214#define MPEGDEF_COUNT ARRAY_SIZE(mpeg_ids)
216 215
217 216
218static const char *control_values_srate[] = { 217static const char *control_values_srate[] = {
@@ -255,10 +254,10 @@ static const char *control_values_subsystem[] = {
255 [PVR2_SUBSYS_B_ENC_RUN] = "enc_run", 254 [PVR2_SUBSYS_B_ENC_RUN] = "enc_run",
256}; 255};
257 256
257static void pvr2_hdw_set_cur_freq(struct pvr2_hdw *,unsigned long);
258static int pvr2_hdw_cmd_usbstream(struct pvr2_hdw *hdw,int runFl); 258static int pvr2_hdw_cmd_usbstream(struct pvr2_hdw *hdw,int runFl);
259static int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw); 259static int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw);
260static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw); 260static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw);
261static unsigned int pvr2_hdw_get_signal_status_internal(struct pvr2_hdw *hdw);
262static void pvr2_hdw_internal_find_stdenum(struct pvr2_hdw *hdw); 261static void pvr2_hdw_internal_find_stdenum(struct pvr2_hdw *hdw);
263static void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw); 262static void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw);
264static void pvr2_hdw_render_useless_unlocked(struct pvr2_hdw *hdw); 263static void pvr2_hdw_render_useless_unlocked(struct pvr2_hdw *hdw);
@@ -272,8 +271,6 @@ static int pvr2_send_request_ex(struct pvr2_hdw *hdw,
272 unsigned int timeout,int probe_fl, 271 unsigned int timeout,int probe_fl,
273 void *write_data,unsigned int write_len, 272 void *write_data,unsigned int write_len,
274 void *read_data,unsigned int read_len); 273 void *read_data,unsigned int read_len);
275static int pvr2_write_u16(struct pvr2_hdw *hdw, u16 data, int res);
276static int pvr2_write_u8(struct pvr2_hdw *hdw, u8 data, int res);
277 274
278static int ctrl_channelfreq_get(struct pvr2_ctrl *cptr,int *vp) 275static int ctrl_channelfreq_get(struct pvr2_ctrl *cptr,int *vp)
279{ 276{
@@ -289,8 +286,21 @@ static int ctrl_channelfreq_get(struct pvr2_ctrl *cptr,int *vp)
289static int ctrl_channelfreq_set(struct pvr2_ctrl *cptr,int m,int v) 286static int ctrl_channelfreq_set(struct pvr2_ctrl *cptr,int m,int v)
290{ 287{
291 struct pvr2_hdw *hdw = cptr->hdw; 288 struct pvr2_hdw *hdw = cptr->hdw;
292 if ((hdw->freqProgSlot > 0) && (hdw->freqProgSlot <= FREQTABLE_SIZE)) { 289 unsigned int slotId = hdw->freqProgSlot;
293 hdw->freqTable[hdw->freqProgSlot-1] = v; 290 if ((slotId > 0) && (slotId <= FREQTABLE_SIZE)) {
291 hdw->freqTable[slotId-1] = v;
292 /* Handle side effects correctly - if we're tuned to this
293 slot, then forgot the slot id relation since the stored
294 frequency has been changed. */
295 if (hdw->freqSelector) {
296 if (hdw->freqSlotRadio == slotId) {
297 hdw->freqSlotRadio = 0;
298 }
299 } else {
300 if (hdw->freqSlotTelevision == slotId) {
301 hdw->freqSlotTelevision = 0;
302 }
303 }
294 } 304 }
295 return 0; 305 return 0;
296} 306}
@@ -312,28 +322,32 @@ static int ctrl_channelprog_set(struct pvr2_ctrl *cptr,int m,int v)
312 322
313static int ctrl_channel_get(struct pvr2_ctrl *cptr,int *vp) 323static int ctrl_channel_get(struct pvr2_ctrl *cptr,int *vp)
314{ 324{
315 *vp = cptr->hdw->freqSlot; 325 struct pvr2_hdw *hdw = cptr->hdw;
326 *vp = hdw->freqSelector ? hdw->freqSlotRadio : hdw->freqSlotTelevision;
316 return 0; 327 return 0;
317} 328}
318 329
319static int ctrl_channel_set(struct pvr2_ctrl *cptr,int m,int v) 330static int ctrl_channel_set(struct pvr2_ctrl *cptr,int m,int slotId)
320{ 331{
321 unsigned freq = 0; 332 unsigned freq = 0;
322 struct pvr2_hdw *hdw = cptr->hdw; 333 struct pvr2_hdw *hdw = cptr->hdw;
323 hdw->freqSlot = v; 334 if ((slotId < 0) || (slotId > FREQTABLE_SIZE)) return 0;
324 if ((hdw->freqSlot > 0) && (hdw->freqSlot <= FREQTABLE_SIZE)) { 335 if (slotId > 0) {
325 freq = hdw->freqTable[hdw->freqSlot-1]; 336 freq = hdw->freqTable[slotId-1];
326 } 337 if (!freq) return 0;
327 if (freq && (freq != hdw->freqVal)) { 338 pvr2_hdw_set_cur_freq(hdw,freq);
328 hdw->freqVal = freq; 339 }
329 hdw->freqDirty = !0; 340 if (hdw->freqSelector) {
341 hdw->freqSlotRadio = slotId;
342 } else {
343 hdw->freqSlotTelevision = slotId;
330 } 344 }
331 return 0; 345 return 0;
332} 346}
333 347
334static int ctrl_freq_get(struct pvr2_ctrl *cptr,int *vp) 348static int ctrl_freq_get(struct pvr2_ctrl *cptr,int *vp)
335{ 349{
336 *vp = cptr->hdw->freqVal; 350 *vp = pvr2_hdw_get_cur_freq(cptr->hdw);
337 return 0; 351 return 0;
338} 352}
339 353
@@ -349,10 +363,7 @@ static void ctrl_freq_clear_dirty(struct pvr2_ctrl *cptr)
349 363
350static int ctrl_freq_set(struct pvr2_ctrl *cptr,int m,int v) 364static int ctrl_freq_set(struct pvr2_ctrl *cptr,int m,int v)
351{ 365{
352 struct pvr2_hdw *hdw = cptr->hdw; 366 pvr2_hdw_set_cur_freq(cptr->hdw,v);
353 hdw->freqVal = v;
354 hdw->freqDirty = !0;
355 hdw->freqSlot = 0;
356 return 0; 367 return 0;
357} 368}
358 369
@@ -378,6 +389,89 @@ static int ctrl_vres_min_get(struct pvr2_ctrl *cptr,int *vp)
378 return 0; 389 return 0;
379} 390}
380 391
392static int ctrl_get_input(struct pvr2_ctrl *cptr,int *vp)
393{
394 *vp = cptr->hdw->input_val;
395 return 0;
396}
397
398static int ctrl_set_input(struct pvr2_ctrl *cptr,int m,int v)
399{
400 struct pvr2_hdw *hdw = cptr->hdw;
401
402 if (hdw->input_val != v) {
403 hdw->input_val = v;
404 hdw->input_dirty = !0;
405 }
406
407 /* Handle side effects - if we switch to a mode that needs the RF
408 tuner, then select the right frequency choice as well and mark
409 it dirty. */
410 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
411 hdw->freqSelector = 0;
412 hdw->freqDirty = !0;
413 } else if (hdw->input_val == PVR2_CVAL_INPUT_TV) {
414 hdw->freqSelector = 1;
415 hdw->freqDirty = !0;
416 }
417 return 0;
418}
419
420static int ctrl_isdirty_input(struct pvr2_ctrl *cptr)
421{
422 return cptr->hdw->input_dirty != 0;
423}
424
425static void ctrl_cleardirty_input(struct pvr2_ctrl *cptr)
426{
427 cptr->hdw->input_dirty = 0;
428}
429
430
431static int ctrl_freq_max_get(struct pvr2_ctrl *cptr, int *vp)
432{
433 unsigned long fv;
434 struct pvr2_hdw *hdw = cptr->hdw;
435 if (hdw->tuner_signal_stale) {
436 pvr2_i2c_core_status_poll(hdw);
437 }
438 fv = hdw->tuner_signal_info.rangehigh;
439 if (!fv) {
440 /* Safety fallback */
441 *vp = TV_MAX_FREQ;
442 return 0;
443 }
444 if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) {
445 fv = (fv * 125) / 2;
446 } else {
447 fv = fv * 62500;
448 }
449 *vp = fv;
450 return 0;
451}
452
453static int ctrl_freq_min_get(struct pvr2_ctrl *cptr, int *vp)
454{
455 unsigned long fv;
456 struct pvr2_hdw *hdw = cptr->hdw;
457 if (hdw->tuner_signal_stale) {
458 pvr2_i2c_core_status_poll(hdw);
459 }
460 fv = hdw->tuner_signal_info.rangelow;
461 if (!fv) {
462 /* Safety fallback */
463 *vp = TV_MIN_FREQ;
464 return 0;
465 }
466 if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) {
467 fv = (fv * 125) / 2;
468 } else {
469 fv = fv * 62500;
470 }
471 *vp = fv;
472 return 0;
473}
474
381static int ctrl_cx2341x_is_dirty(struct pvr2_ctrl *cptr) 475static int ctrl_cx2341x_is_dirty(struct pvr2_ctrl *cptr)
382{ 476{
383 return cptr->hdw->enc_stale != 0; 477 return cptr->hdw->enc_stale != 0;
@@ -534,8 +628,32 @@ static void ctrl_stdcur_clear_dirty(struct pvr2_ctrl *cptr)
534 628
535static int ctrl_signal_get(struct pvr2_ctrl *cptr,int *vp) 629static int ctrl_signal_get(struct pvr2_ctrl *cptr,int *vp)
536{ 630{
537 *vp = ((pvr2_hdw_get_signal_status_internal(cptr->hdw) & 631 struct pvr2_hdw *hdw = cptr->hdw;
538 PVR2_SIGNAL_OK) ? 1 : 0); 632 pvr2_i2c_core_status_poll(hdw);
633 *vp = hdw->tuner_signal_info.signal;
634 return 0;
635}
636
637static int ctrl_audio_modes_present_get(struct pvr2_ctrl *cptr,int *vp)
638{
639 int val = 0;
640 unsigned int subchan;
641 struct pvr2_hdw *hdw = cptr->hdw;
642 pvr2_i2c_core_status_poll(hdw);
643 subchan = hdw->tuner_signal_info.rxsubchans;
644 if (subchan & V4L2_TUNER_SUB_MONO) {
645 val |= (1 << V4L2_TUNER_MODE_MONO);
646 }
647 if (subchan & V4L2_TUNER_SUB_STEREO) {
648 val |= (1 << V4L2_TUNER_MODE_STEREO);
649 }
650 if (subchan & V4L2_TUNER_SUB_LANG1) {
651 val |= (1 << V4L2_TUNER_MODE_LANG1);
652 }
653 if (subchan & V4L2_TUNER_SUB_LANG2) {
654 val |= (1 << V4L2_TUNER_MODE_LANG2);
655 }
656 *vp = val;
539 return 0; 657 return 0;
540} 658}
541 659
@@ -604,7 +722,7 @@ static void ctrl_stdenumcur_clear_dirty(struct pvr2_ctrl *cptr)
604 722
605#define DEFENUM(tab) \ 723#define DEFENUM(tab) \
606 .type = pvr2_ctl_enum, \ 724 .type = pvr2_ctl_enum, \
607 .def.type_enum.count = (sizeof(tab)/sizeof((tab)[0])), \ 725 .def.type_enum.count = ARRAY_SIZE(tab), \
608 .def.type_enum.value_names = tab 726 .def.type_enum.value_names = tab
609 727
610#define DEFBOOL \ 728#define DEFBOOL \
@@ -641,15 +759,11 @@ VCREATE_FUNCS(balance)
641VCREATE_FUNCS(bass) 759VCREATE_FUNCS(bass)
642VCREATE_FUNCS(treble) 760VCREATE_FUNCS(treble)
643VCREATE_FUNCS(mute) 761VCREATE_FUNCS(mute)
644VCREATE_FUNCS(input)
645VCREATE_FUNCS(audiomode) 762VCREATE_FUNCS(audiomode)
646VCREATE_FUNCS(res_hor) 763VCREATE_FUNCS(res_hor)
647VCREATE_FUNCS(res_ver) 764VCREATE_FUNCS(res_ver)
648VCREATE_FUNCS(srate) 765VCREATE_FUNCS(srate)
649 766
650#define MIN_FREQ 55250000L
651#define MAX_FREQ 850000000L
652
653/* Table definition of all controls which can be manipulated */ 767/* Table definition of all controls which can be manipulated */
654static const struct pvr2_ctl_info control_defs[] = { 768static const struct pvr2_ctl_info control_defs[] = {
655 { 769 {
@@ -684,7 +798,7 @@ static const struct pvr2_ctl_info control_defs[] = {
684 .v4l_id = V4L2_CID_AUDIO_VOLUME, 798 .v4l_id = V4L2_CID_AUDIO_VOLUME,
685 .desc = "Volume", 799 .desc = "Volume",
686 .name = "volume", 800 .name = "volume",
687 .default_value = 65535, 801 .default_value = 62000,
688 DEFREF(volume), 802 DEFREF(volume),
689 DEFINT(0,65535), 803 DEFINT(0,65535),
690 },{ 804 },{
@@ -758,12 +872,16 @@ static const struct pvr2_ctl_info control_defs[] = {
758 .desc = "Tuner Frequency (Hz)", 872 .desc = "Tuner Frequency (Hz)",
759 .name = "frequency", 873 .name = "frequency",
760 .internal_id = PVR2_CID_FREQUENCY, 874 .internal_id = PVR2_CID_FREQUENCY,
761 .default_value = 175250000L, 875 .default_value = 0,
762 .set_value = ctrl_freq_set, 876 .set_value = ctrl_freq_set,
763 .get_value = ctrl_freq_get, 877 .get_value = ctrl_freq_get,
764 .is_dirty = ctrl_freq_is_dirty, 878 .is_dirty = ctrl_freq_is_dirty,
765 .clear_dirty = ctrl_freq_clear_dirty, 879 .clear_dirty = ctrl_freq_clear_dirty,
766 DEFINT(MIN_FREQ,MAX_FREQ), 880 DEFINT(0,0),
881 /* Hook in check for input value (tv/radio) and adjust
882 max/min values accordingly */
883 .get_max_value = ctrl_freq_max_get,
884 .get_min_value = ctrl_freq_min_get,
767 },{ 885 },{
768 .desc = "Channel", 886 .desc = "Channel",
769 .name = "channel", 887 .name = "channel",
@@ -775,7 +893,11 @@ static const struct pvr2_ctl_info control_defs[] = {
775 .name = "freq_table_value", 893 .name = "freq_table_value",
776 .set_value = ctrl_channelfreq_set, 894 .set_value = ctrl_channelfreq_set,
777 .get_value = ctrl_channelfreq_get, 895 .get_value = ctrl_channelfreq_get,
778 DEFINT(MIN_FREQ,MAX_FREQ), 896 DEFINT(0,0),
897 /* Hook in check for input value (tv/radio) and adjust
898 max/min values accordingly */
899 .get_max_value = ctrl_freq_max_get,
900 .get_min_value = ctrl_freq_min_get,
779 },{ 901 },{
780 .desc = "Channel Program ID", 902 .desc = "Channel Program ID",
781 .name = "freq_table_channel", 903 .name = "freq_table_channel",
@@ -796,7 +918,20 @@ static const struct pvr2_ctl_info control_defs[] = {
796 .desc = "Signal Present", 918 .desc = "Signal Present",
797 .name = "signal_present", 919 .name = "signal_present",
798 .get_value = ctrl_signal_get, 920 .get_value = ctrl_signal_get,
799 DEFBOOL, 921 DEFINT(0,65535),
922 },{
923 .desc = "Audio Modes Present",
924 .name = "audio_modes_present",
925 .get_value = ctrl_audio_modes_present_get,
926 /* For this type we "borrow" the V4L2_TUNER_MODE enum from
927 v4l. Nothing outside of this module cares about this,
928 but I reuse it in order to also reuse the
929 control_values_audiomode string table. */
930 DEFMASK(((1 << V4L2_TUNER_MODE_MONO)|
931 (1 << V4L2_TUNER_MODE_STEREO)|
932 (1 << V4L2_TUNER_MODE_LANG1)|
933 (1 << V4L2_TUNER_MODE_LANG2)),
934 control_values_audiomode),
800 },{ 935 },{
801 .desc = "Video Standards Available Mask", 936 .desc = "Video Standards Available Mask",
802 .name = "video_standard_mask_available", 937 .name = "video_standard_mask_available",
@@ -846,7 +981,7 @@ static const struct pvr2_ctl_info control_defs[] = {
846 } 981 }
847}; 982};
848 983
849#define CTRLDEF_COUNT (sizeof(control_defs)/sizeof(control_defs[0])) 984#define CTRLDEF_COUNT ARRAY_SIZE(control_defs)
850 985
851 986
852const char *pvr2_config_get_name(enum pvr2_config cfg) 987const char *pvr2_config_get_name(enum pvr2_config cfg)
@@ -855,7 +990,8 @@ const char *pvr2_config_get_name(enum pvr2_config cfg)
855 case pvr2_config_empty: return "empty"; 990 case pvr2_config_empty: return "empty";
856 case pvr2_config_mpeg: return "mpeg"; 991 case pvr2_config_mpeg: return "mpeg";
857 case pvr2_config_vbi: return "vbi"; 992 case pvr2_config_vbi: return "vbi";
858 case pvr2_config_radio: return "radio"; 993 case pvr2_config_pcm: return "pcm";
994 case pvr2_config_rawvideo: return "raw video";
859 } 995 }
860 return "<unknown>"; 996 return "<unknown>";
861} 997}
@@ -872,6 +1008,40 @@ unsigned long pvr2_hdw_get_sn(struct pvr2_hdw *hdw)
872 return hdw->serial_number; 1008 return hdw->serial_number;
873} 1009}
874 1010
1011unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *hdw)
1012{
1013 return hdw->freqSelector ? hdw->freqValTelevision : hdw->freqValRadio;
1014}
1015
1016/* Set the currently tuned frequency and account for all possible
1017 driver-core side effects of this action. */
1018void pvr2_hdw_set_cur_freq(struct pvr2_hdw *hdw,unsigned long val)
1019{
1020 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
1021 if (hdw->freqSelector) {
1022 /* Swing over to radio frequency selection */
1023 hdw->freqSelector = 0;
1024 hdw->freqDirty = !0;
1025 }
1026 if (hdw->freqValRadio != val) {
1027 hdw->freqValRadio = val;
1028 hdw->freqSlotRadio = 0;
1029 hdw->freqDirty = !0;
1030 }
1031 } else {
1032 if (!(hdw->freqSelector)) {
1033 /* Swing over to television frequency selection */
1034 hdw->freqSelector = 1;
1035 hdw->freqDirty = !0;
1036 }
1037 if (hdw->freqValTelevision != val) {
1038 hdw->freqValTelevision = val;
1039 hdw->freqSlotTelevision = 0;
1040 hdw->freqDirty = !0;
1041 }
1042 }
1043}
1044
875int pvr2_hdw_get_unit_number(struct pvr2_hdw *hdw) 1045int pvr2_hdw_get_unit_number(struct pvr2_hdw *hdw)
876{ 1046{
877 return hdw->unit_number; 1047 return hdw->unit_number;
@@ -960,12 +1130,10 @@ static int pvr2_upload_firmware1(struct pvr2_hdw *hdw)
960 }; 1130 };
961 static const struct pvr2_string_table fw_file_defs[] = { 1131 static const struct pvr2_string_table fw_file_defs[] = {
962 [PVR2_HDW_TYPE_29XXX] = { 1132 [PVR2_HDW_TYPE_29XXX] = {
963 fw_files_29xxx, 1133 fw_files_29xxx, ARRAY_SIZE(fw_files_29xxx)
964 sizeof(fw_files_29xxx)/sizeof(fw_files_29xxx[0]),
965 }, 1134 },
966 [PVR2_HDW_TYPE_24XXX] = { 1135 [PVR2_HDW_TYPE_24XXX] = {
967 fw_files_24xxx, 1136 fw_files_24xxx, ARRAY_SIZE(fw_files_24xxx)
968 sizeof(fw_files_24xxx)/sizeof(fw_files_24xxx[0]),
969 }, 1137 },
970 }; 1138 };
971 hdw->fw1_state = FW1_STATE_FAILED; // default result 1139 hdw->fw1_state = FW1_STATE_FAILED; // default result
@@ -1041,7 +1209,7 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
1041{ 1209{
1042 const struct firmware *fw_entry = NULL; 1210 const struct firmware *fw_entry = NULL;
1043 void *fw_ptr; 1211 void *fw_ptr;
1044 unsigned int pipe, fw_len, fw_done; 1212 unsigned int pipe, fw_len, fw_done, bcnt, icnt;
1045 int actual_length; 1213 int actual_length;
1046 int ret = 0; 1214 int ret = 0;
1047 int fwidx; 1215 int fwidx;
@@ -1052,8 +1220,7 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
1052 trace_firmware("pvr2_upload_firmware2"); 1220 trace_firmware("pvr2_upload_firmware2");
1053 1221
1054 ret = pvr2_locate_firmware(hdw,&fw_entry,"encoder", 1222 ret = pvr2_locate_firmware(hdw,&fw_entry,"encoder",
1055 sizeof(fw_files)/sizeof(fw_files[0]), 1223 ARRAY_SIZE(fw_files), fw_files);
1056 fw_files);
1057 if (ret < 0) return ret; 1224 if (ret < 0) return ret;
1058 fwidx = ret; 1225 fwidx = ret;
1059 ret = 0; 1226 ret = 0;
@@ -1079,8 +1246,13 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
1079 ret |= pvr2_write_register(hdw, 0xaa04, 0x00057810); /*unknown*/ 1246 ret |= pvr2_write_register(hdw, 0xaa04, 0x00057810); /*unknown*/
1080 ret |= pvr2_write_register(hdw, 0xaa10, 0x00148500); /*unknown*/ 1247 ret |= pvr2_write_register(hdw, 0xaa10, 0x00148500); /*unknown*/
1081 ret |= pvr2_write_register(hdw, 0xaa18, 0x00840000); /*unknown*/ 1248 ret |= pvr2_write_register(hdw, 0xaa18, 0x00840000); /*unknown*/
1082 ret |= pvr2_write_u8(hdw, 0x52, 0); 1249 LOCK_TAKE(hdw->ctl_lock); do {
1083 ret |= pvr2_write_u16(hdw, 0x0600, 0); 1250 hdw->cmd_buffer[0] = FX2CMD_FWPOST1;
1251 ret |= pvr2_send_request(hdw,hdw->cmd_buffer,1,0,0);
1252 hdw->cmd_buffer[0] = FX2CMD_MEMSEL;
1253 hdw->cmd_buffer[1] = 0;
1254 ret |= pvr2_send_request(hdw,hdw->cmd_buffer,2,0,0);
1255 } while (0); LOCK_GIVE(hdw->ctl_lock);
1084 1256
1085 if (ret) { 1257 if (ret) {
1086 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 1258 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
@@ -1093,11 +1265,11 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
1093 1265
1094 fw_len = fw_entry->size; 1266 fw_len = fw_entry->size;
1095 1267
1096 if (fw_len % FIRMWARE_CHUNK_SIZE) { 1268 if (fw_len % sizeof(u32)) {
1097 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 1269 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1098 "size of %s firmware" 1270 "size of %s firmware"
1099 " must be a multiple of 8192B", 1271 " must be a multiple of %zu bytes",
1100 fw_files[fwidx]); 1272 fw_files[fwidx],sizeof(u32));
1101 release_firmware(fw_entry); 1273 release_firmware(fw_entry);
1102 return -1; 1274 return -1;
1103 } 1275 }
@@ -1112,18 +1284,21 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
1112 1284
1113 pipe = usb_sndbulkpipe(hdw->usb_dev, PVR2_FIRMWARE_ENDPOINT); 1285 pipe = usb_sndbulkpipe(hdw->usb_dev, PVR2_FIRMWARE_ENDPOINT);
1114 1286
1115 for (fw_done = 0 ; (fw_done < fw_len) && !ret ; 1287 fw_done = 0;
1116 fw_done += FIRMWARE_CHUNK_SIZE ) { 1288 for (fw_done = 0; fw_done < fw_len;) {
1117 int i; 1289 bcnt = fw_len - fw_done;
1118 memcpy(fw_ptr, fw_entry->data + fw_done, FIRMWARE_CHUNK_SIZE); 1290 if (bcnt > FIRMWARE_CHUNK_SIZE) bcnt = FIRMWARE_CHUNK_SIZE;
1119 /* Usbsnoop log shows that we must swap bytes... */ 1291 memcpy(fw_ptr, fw_entry->data + fw_done, bcnt);
1120 for (i = 0; i < FIRMWARE_CHUNK_SIZE/4 ; i++) 1292 /* Usbsnoop log shows that we must swap bytes... */
1121 ((u32 *)fw_ptr)[i] = ___swab32(((u32 *)fw_ptr)[i]); 1293 for (icnt = 0; icnt < bcnt/4 ; icnt++)
1122 1294 ((u32 *)fw_ptr)[icnt] =
1123 ret |= usb_bulk_msg(hdw->usb_dev, pipe, fw_ptr, 1295 ___swab32(((u32 *)fw_ptr)[icnt]);
1124 FIRMWARE_CHUNK_SIZE, 1296
1297 ret |= usb_bulk_msg(hdw->usb_dev, pipe, fw_ptr,bcnt,
1125 &actual_length, HZ); 1298 &actual_length, HZ);
1126 ret |= (actual_length != FIRMWARE_CHUNK_SIZE); 1299 ret |= (actual_length != bcnt);
1300 if (ret) break;
1301 fw_done += bcnt;
1127 } 1302 }
1128 1303
1129 trace_firmware("upload of %s : %i / %i ", 1304 trace_firmware("upload of %s : %i / %i ",
@@ -1142,7 +1317,11 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
1142 1317
1143 ret |= pvr2_write_register(hdw, 0x9054, 0xffffffff); /*reset hw blocks*/ 1318 ret |= pvr2_write_register(hdw, 0x9054, 0xffffffff); /*reset hw blocks*/
1144 ret |= pvr2_write_register(hdw, 0x9058, 0xffffffe8); /*VPU ctrl*/ 1319 ret |= pvr2_write_register(hdw, 0x9058, 0xffffffe8); /*VPU ctrl*/
1145 ret |= pvr2_write_u16(hdw, 0x0600, 0); 1320 LOCK_TAKE(hdw->ctl_lock); do {
1321 hdw->cmd_buffer[0] = FX2CMD_MEMSEL;
1322 hdw->cmd_buffer[1] = 0;
1323 ret |= pvr2_send_request(hdw,hdw->cmd_buffer,2,0,0);
1324 } while (0); LOCK_GIVE(hdw->ctl_lock);
1146 1325
1147 if (ret) { 1326 if (ret) {
1148 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 1327 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
@@ -1479,7 +1658,7 @@ static int pvr2_hdw_check_firmware(struct pvr2_hdw *hdw)
1479 firmware needs be loaded. */ 1658 firmware needs be loaded. */
1480 int result; 1659 int result;
1481 LOCK_TAKE(hdw->ctl_lock); do { 1660 LOCK_TAKE(hdw->ctl_lock); do {
1482 hdw->cmd_buffer[0] = 0xeb; 1661 hdw->cmd_buffer[0] = FX2CMD_GET_EEPROM_ADDR;
1483 result = pvr2_send_request_ex(hdw,HZ*1,!0, 1662 result = pvr2_send_request_ex(hdw,HZ*1,!0,
1484 hdw->cmd_buffer,1, 1663 hdw->cmd_buffer,1,
1485 hdw->cmd_buffer,1); 1664 hdw->cmd_buffer,1);
@@ -1611,6 +1790,16 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
1611 cptr->info->set_value(cptr,~0,cptr->info->default_value); 1790 cptr->info->set_value(cptr,~0,cptr->info->default_value);
1612 } 1791 }
1613 1792
1793 /* Set up special default values for the television and radio
1794 frequencies here. It's not really important what these defaults
1795 are, but I set them to something usable in the Chicago area just
1796 to make driver testing a little easier. */
1797
1798 /* US Broadcast channel 7 (175.25 MHz) */
1799 hdw->freqValTelevision = 175250000L;
1800 /* 104.3 MHz, a usable FM station for my area */
1801 hdw->freqValRadio = 104300000L;
1802
1614 // Do not use pvr2_reset_ctl_endpoints() here. It is not 1803 // Do not use pvr2_reset_ctl_endpoints() here. It is not
1615 // thread-safe against the normal pvr2_send_request() mechanism. 1804 // thread-safe against the normal pvr2_send_request() mechanism.
1616 // (We should make it thread safe). 1805 // (We should make it thread safe).
@@ -1750,26 +1939,24 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
1750 struct pvr2_ctl_info *ciptr; 1939 struct pvr2_ctl_info *ciptr;
1751 1940
1752 hdw_type = devid - pvr2_device_table; 1941 hdw_type = devid - pvr2_device_table;
1753 if (hdw_type >= 1942 if (hdw_type >= ARRAY_SIZE(pvr2_device_names)) {
1754 sizeof(pvr2_device_names)/sizeof(pvr2_device_names[0])) {
1755 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 1943 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1756 "Bogus device type of %u reported",hdw_type); 1944 "Bogus device type of %u reported",hdw_type);
1757 return NULL; 1945 return NULL;
1758 } 1946 }
1759 1947
1760 hdw = kmalloc(sizeof(*hdw),GFP_KERNEL); 1948 hdw = kzalloc(sizeof(*hdw),GFP_KERNEL);
1761 pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_create: hdw=%p, type \"%s\"", 1949 pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_create: hdw=%p, type \"%s\"",
1762 hdw,pvr2_device_names[hdw_type]); 1950 hdw,pvr2_device_names[hdw_type]);
1763 if (!hdw) goto fail; 1951 if (!hdw) goto fail;
1764 memset(hdw,0,sizeof(*hdw)); 1952 hdw->tuner_signal_stale = !0;
1765 cx2341x_fill_defaults(&hdw->enc_ctl_state); 1953 cx2341x_fill_defaults(&hdw->enc_ctl_state);
1766 1954
1767 hdw->control_cnt = CTRLDEF_COUNT; 1955 hdw->control_cnt = CTRLDEF_COUNT;
1768 hdw->control_cnt += MPEGDEF_COUNT; 1956 hdw->control_cnt += MPEGDEF_COUNT;
1769 hdw->controls = kmalloc(sizeof(struct pvr2_ctrl) * hdw->control_cnt, 1957 hdw->controls = kzalloc(sizeof(struct pvr2_ctrl) * hdw->control_cnt,
1770 GFP_KERNEL); 1958 GFP_KERNEL);
1771 if (!hdw->controls) goto fail; 1959 if (!hdw->controls) goto fail;
1772 memset(hdw->controls,0,sizeof(struct pvr2_ctrl) * hdw->control_cnt);
1773 hdw->hdw_type = hdw_type; 1960 hdw->hdw_type = hdw_type;
1774 for (idx = 0; idx < hdw->control_cnt; idx++) { 1961 for (idx = 0; idx < hdw->control_cnt; idx++) {
1775 cptr = hdw->controls + idx; 1962 cptr = hdw->controls + idx;
@@ -1783,11 +1970,9 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
1783 cptr->info = control_defs+idx; 1970 cptr->info = control_defs+idx;
1784 } 1971 }
1785 /* Define and configure additional controls from cx2341x module. */ 1972 /* Define and configure additional controls from cx2341x module. */
1786 hdw->mpeg_ctrl_info = kmalloc( 1973 hdw->mpeg_ctrl_info = kzalloc(
1787 sizeof(*(hdw->mpeg_ctrl_info)) * MPEGDEF_COUNT, GFP_KERNEL); 1974 sizeof(*(hdw->mpeg_ctrl_info)) * MPEGDEF_COUNT, GFP_KERNEL);
1788 if (!hdw->mpeg_ctrl_info) goto fail; 1975 if (!hdw->mpeg_ctrl_info) goto fail;
1789 memset(hdw->mpeg_ctrl_info,0,
1790 sizeof(*(hdw->mpeg_ctrl_info)) * MPEGDEF_COUNT);
1791 for (idx = 0; idx < MPEGDEF_COUNT; idx++) { 1976 for (idx = 0; idx < MPEGDEF_COUNT; idx++) {
1792 cptr = hdw->controls + idx + CTRLDEF_COUNT; 1977 cptr = hdw->controls + idx + CTRLDEF_COUNT;
1793 ciptr = &(hdw->mpeg_ctrl_info[idx].info); 1978 ciptr = &(hdw->mpeg_ctrl_info[idx].info);
@@ -1872,7 +2057,9 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
1872 2057
1873 hdw->eeprom_addr = -1; 2058 hdw->eeprom_addr = -1;
1874 hdw->unit_number = -1; 2059 hdw->unit_number = -1;
1875 hdw->v4l_minor_number = -1; 2060 hdw->v4l_minor_number_video = -1;
2061 hdw->v4l_minor_number_vbi = -1;
2062 hdw->v4l_minor_number_radio = -1;
1876 hdw->ctl_write_buffer = kmalloc(PVR2_CTL_BUFFSIZE,GFP_KERNEL); 2063 hdw->ctl_write_buffer = kmalloc(PVR2_CTL_BUFFSIZE,GFP_KERNEL);
1877 if (!hdw->ctl_write_buffer) goto fail; 2064 if (!hdw->ctl_write_buffer) goto fail;
1878 hdw->ctl_read_buffer = kmalloc(PVR2_CTL_BUFFSIZE,GFP_KERNEL); 2065 hdw->ctl_read_buffer = kmalloc(PVR2_CTL_BUFFSIZE,GFP_KERNEL);
@@ -1929,10 +2116,10 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
1929 if (hdw) { 2116 if (hdw) {
1930 usb_free_urb(hdw->ctl_read_urb); 2117 usb_free_urb(hdw->ctl_read_urb);
1931 usb_free_urb(hdw->ctl_write_urb); 2118 usb_free_urb(hdw->ctl_write_urb);
1932 if (hdw->ctl_read_buffer) kfree(hdw->ctl_read_buffer); 2119 kfree(hdw->ctl_read_buffer);
1933 if (hdw->ctl_write_buffer) kfree(hdw->ctl_write_buffer); 2120 kfree(hdw->ctl_write_buffer);
1934 if (hdw->controls) kfree(hdw->controls); 2121 kfree(hdw->controls);
1935 if (hdw->mpeg_ctrl_info) kfree(hdw->mpeg_ctrl_info); 2122 kfree(hdw->mpeg_ctrl_info);
1936 kfree(hdw); 2123 kfree(hdw);
1937 } 2124 }
1938 return NULL; 2125 return NULL;
@@ -1982,9 +2169,6 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
1982 pvr2_stream_destroy(hdw->vid_stream); 2169 pvr2_stream_destroy(hdw->vid_stream);
1983 hdw->vid_stream = NULL; 2170 hdw->vid_stream = NULL;
1984 } 2171 }
1985 if (hdw->audio_stat) {
1986 hdw->audio_stat->detach(hdw->audio_stat->ctxt);
1987 }
1988 if (hdw->decoder_ctrl) { 2172 if (hdw->decoder_ctrl) {
1989 hdw->decoder_ctrl->detach(hdw->decoder_ctrl->ctxt); 2173 hdw->decoder_ctrl->detach(hdw->decoder_ctrl->ctxt);
1990 } 2174 }
@@ -1997,10 +2181,10 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
1997 unit_pointers[hdw->unit_number] = NULL; 2181 unit_pointers[hdw->unit_number] = NULL;
1998 } 2182 }
1999 } while (0); up(&pvr2_unit_sem); 2183 } while (0); up(&pvr2_unit_sem);
2000 if (hdw->controls) kfree(hdw->controls); 2184 kfree(hdw->controls);
2001 if (hdw->mpeg_ctrl_info) kfree(hdw->mpeg_ctrl_info); 2185 kfree(hdw->mpeg_ctrl_info);
2002 if (hdw->std_defs) kfree(hdw->std_defs); 2186 kfree(hdw->std_defs);
2003 if (hdw->std_enum_names) kfree(hdw->std_enum_names); 2187 kfree(hdw->std_enum_names);
2004 kfree(hdw); 2188 kfree(hdw);
2005} 2189}
2006 2190
@@ -2210,10 +2394,9 @@ static int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw)
2210 cptr = hdw->controls + idx; 2394 cptr = hdw->controls + idx;
2211 if (cptr->info->is_dirty == 0) continue; 2395 if (cptr->info->is_dirty == 0) continue;
2212 if (!cptr->info->is_dirty(cptr)) continue; 2396 if (!cptr->info->is_dirty(cptr)) continue;
2213 if (!commit_flag) { 2397 commit_flag = !0;
2214 commit_flag = !0;
2215 }
2216 2398
2399 if (!(pvrusb2_debug & PVR2_TRACE_CTL)) continue;
2217 bcnt = scnprintf(buf,sizeof(buf),"\"%s\" <-- ", 2400 bcnt = scnprintf(buf,sizeof(buf),"\"%s\" <-- ",
2218 cptr->info->name); 2401 cptr->info->name);
2219 value = 0; 2402 value = 0;
@@ -2263,6 +2446,13 @@ static int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw)
2263 stale_subsys_mask |= (1<<PVR2_SUBSYS_B_ENC_CFG); 2446 stale_subsys_mask |= (1<<PVR2_SUBSYS_B_ENC_CFG);
2264 } 2447 }
2265 2448
2449 if (hdw->input_dirty) {
2450 /* pk: If input changes to or from radio, then the encoder
2451 needs to be restarted (for ENC_MUTE_VIDEO to work) */
2452 stale_subsys_mask |= (1<<PVR2_SUBSYS_B_ENC_RUN);
2453 }
2454
2455
2266 if (hdw->srate_dirty) { 2456 if (hdw->srate_dirty) {
2267 /* Write new sample rate into control structure since 2457 /* Write new sample rate into control structure since
2268 * the master copy is stale. We must track srate 2458 * the master copy is stale. We must track srate
@@ -2343,39 +2533,11 @@ const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *hdw)
2343} 2533}
2344 2534
2345 2535
2346/* Return bit mask indicating signal status */
2347static unsigned int pvr2_hdw_get_signal_status_internal(struct pvr2_hdw *hdw)
2348{
2349 unsigned int msk = 0;
2350 switch (hdw->input_val) {
2351 case PVR2_CVAL_INPUT_TV:
2352 case PVR2_CVAL_INPUT_RADIO:
2353 if (hdw->decoder_ctrl &&
2354 hdw->decoder_ctrl->tuned(hdw->decoder_ctrl->ctxt)) {
2355 msk |= PVR2_SIGNAL_OK;
2356 if (hdw->audio_stat &&
2357 hdw->audio_stat->status(hdw->audio_stat->ctxt)) {
2358 if (hdw->flag_stereo) {
2359 msk |= PVR2_SIGNAL_STEREO;
2360 }
2361 if (hdw->flag_bilingual) {
2362 msk |= PVR2_SIGNAL_SAP;
2363 }
2364 }
2365 }
2366 break;
2367 default:
2368 msk |= PVR2_SIGNAL_OK | PVR2_SIGNAL_STEREO;
2369 }
2370 return msk;
2371}
2372
2373
2374int pvr2_hdw_is_hsm(struct pvr2_hdw *hdw) 2536int pvr2_hdw_is_hsm(struct pvr2_hdw *hdw)
2375{ 2537{
2376 int result; 2538 int result;
2377 LOCK_TAKE(hdw->ctl_lock); do { 2539 LOCK_TAKE(hdw->ctl_lock); do {
2378 hdw->cmd_buffer[0] = 0x0b; 2540 hdw->cmd_buffer[0] = FX2CMD_GET_USB_SPEED;
2379 result = pvr2_send_request(hdw, 2541 result = pvr2_send_request(hdw,
2380 hdw->cmd_buffer,1, 2542 hdw->cmd_buffer,1,
2381 hdw->cmd_buffer,1); 2543 hdw->cmd_buffer,1);
@@ -2386,14 +2548,25 @@ int pvr2_hdw_is_hsm(struct pvr2_hdw *hdw)
2386} 2548}
2387 2549
2388 2550
2389/* Return bit mask indicating signal status */ 2551/* Execute poll of tuner status */
2390unsigned int pvr2_hdw_get_signal_status(struct pvr2_hdw *hdw) 2552void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *hdw)
2391{ 2553{
2392 unsigned int msk = 0;
2393 LOCK_TAKE(hdw->big_lock); do { 2554 LOCK_TAKE(hdw->big_lock); do {
2394 msk = pvr2_hdw_get_signal_status_internal(hdw); 2555 pvr2_i2c_core_status_poll(hdw);
2395 } while (0); LOCK_GIVE(hdw->big_lock); 2556 } while (0); LOCK_GIVE(hdw->big_lock);
2396 return msk; 2557}
2558
2559
2560/* Return information about the tuner */
2561int pvr2_hdw_get_tuner_status(struct pvr2_hdw *hdw,struct v4l2_tuner *vtp)
2562{
2563 LOCK_TAKE(hdw->big_lock); do {
2564 if (hdw->tuner_signal_stale) {
2565 pvr2_i2c_core_status_poll(hdw);
2566 }
2567 memcpy(vtp,&hdw->tuner_signal_info,sizeof(struct v4l2_tuner));
2568 } while (0); LOCK_GIVE(hdw->big_lock);
2569 return 0;
2397} 2570}
2398 2571
2399 2572
@@ -2442,14 +2615,12 @@ void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *hdw, int enable_flag)
2442 pvr2_trace(PVR2_TRACE_FIRMWARE, 2615 pvr2_trace(PVR2_TRACE_FIRMWARE,
2443 "Preparing to suck out CPU firmware"); 2616 "Preparing to suck out CPU firmware");
2444 hdw->fw_size = 0x2000; 2617 hdw->fw_size = 0x2000;
2445 hdw->fw_buffer = kmalloc(hdw->fw_size,GFP_KERNEL); 2618 hdw->fw_buffer = kzalloc(hdw->fw_size,GFP_KERNEL);
2446 if (!hdw->fw_buffer) { 2619 if (!hdw->fw_buffer) {
2447 hdw->fw_size = 0; 2620 hdw->fw_size = 0;
2448 break; 2621 break;
2449 } 2622 }
2450 2623
2451 memset(hdw->fw_buffer,0,hdw->fw_size);
2452
2453 /* We have to hold the CPU during firmware upload. */ 2624 /* We have to hold the CPU during firmware upload. */
2454 pvr2_hdw_cpureset_assert(hdw,1); 2625 pvr2_hdw_cpureset_assert(hdw,1);
2455 2626
@@ -2513,16 +2684,28 @@ int pvr2_hdw_cpufw_get(struct pvr2_hdw *hdw,unsigned int offs,
2513} 2684}
2514 2685
2515 2686
2516int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *hdw) 2687int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *hdw,
2688 enum pvr2_v4l_type index)
2517{ 2689{
2518 return hdw->v4l_minor_number; 2690 switch (index) {
2691 case pvr2_v4l_type_video: return hdw->v4l_minor_number_video;
2692 case pvr2_v4l_type_vbi: return hdw->v4l_minor_number_vbi;
2693 case pvr2_v4l_type_radio: return hdw->v4l_minor_number_radio;
2694 default: return -1;
2695 }
2519} 2696}
2520 2697
2521 2698
2522/* Store the v4l minor device number */ 2699/* Store a v4l minor device number */
2523void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *hdw,int v) 2700void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *hdw,
2701 enum pvr2_v4l_type index,int v)
2524{ 2702{
2525 hdw->v4l_minor_number = v; 2703 switch (index) {
2704 case pvr2_v4l_type_video: hdw->v4l_minor_number_video = v;
2705 case pvr2_v4l_type_vbi: hdw->v4l_minor_number_vbi = v;
2706 case pvr2_v4l_type_radio: hdw->v4l_minor_number_radio = v;
2707 default: break;
2708 }
2526} 2709}
2527 2710
2528 2711
@@ -2804,7 +2987,7 @@ int pvr2_write_register(struct pvr2_hdw *hdw, u16 reg, u32 data)
2804 2987
2805 LOCK_TAKE(hdw->ctl_lock); 2988 LOCK_TAKE(hdw->ctl_lock);
2806 2989
2807 hdw->cmd_buffer[0] = 0x04; /* write register prefix */ 2990 hdw->cmd_buffer[0] = FX2CMD_REG_WRITE; /* write register prefix */
2808 PVR2_DECOMPOSE_LE(hdw->cmd_buffer,1,data); 2991 PVR2_DECOMPOSE_LE(hdw->cmd_buffer,1,data);
2809 hdw->cmd_buffer[5] = 0; 2992 hdw->cmd_buffer[5] = 0;
2810 hdw->cmd_buffer[6] = (reg >> 8) & 0xff; 2993 hdw->cmd_buffer[6] = (reg >> 8) & 0xff;
@@ -2825,7 +3008,7 @@ static int pvr2_read_register(struct pvr2_hdw *hdw, u16 reg, u32 *data)
2825 3008
2826 LOCK_TAKE(hdw->ctl_lock); 3009 LOCK_TAKE(hdw->ctl_lock);
2827 3010
2828 hdw->cmd_buffer[0] = 0x05; /* read register prefix */ 3011 hdw->cmd_buffer[0] = FX2CMD_REG_READ; /* read register prefix */
2829 hdw->cmd_buffer[1] = 0; 3012 hdw->cmd_buffer[1] = 0;
2830 hdw->cmd_buffer[2] = 0; 3013 hdw->cmd_buffer[2] = 0;
2831 hdw->cmd_buffer[3] = 0; 3014 hdw->cmd_buffer[3] = 0;
@@ -2843,39 +3026,6 @@ static int pvr2_read_register(struct pvr2_hdw *hdw, u16 reg, u32 *data)
2843} 3026}
2844 3027
2845 3028
2846static int pvr2_write_u16(struct pvr2_hdw *hdw, u16 data, int res)
2847{
2848 int ret;
2849
2850 LOCK_TAKE(hdw->ctl_lock);
2851
2852 hdw->cmd_buffer[0] = (data >> 8) & 0xff;
2853 hdw->cmd_buffer[1] = data & 0xff;
2854
2855 ret = pvr2_send_request(hdw, hdw->cmd_buffer, 2, hdw->cmd_buffer, res);
2856
2857 LOCK_GIVE(hdw->ctl_lock);
2858
2859 return ret;
2860}
2861
2862
2863static int pvr2_write_u8(struct pvr2_hdw *hdw, u8 data, int res)
2864{
2865 int ret;
2866
2867 LOCK_TAKE(hdw->ctl_lock);
2868
2869 hdw->cmd_buffer[0] = data;
2870
2871 ret = pvr2_send_request(hdw, hdw->cmd_buffer, 1, hdw->cmd_buffer, res);
2872
2873 LOCK_GIVE(hdw->ctl_lock);
2874
2875 return ret;
2876}
2877
2878
2879static void pvr2_hdw_render_useless_unlocked(struct pvr2_hdw *hdw) 3029static void pvr2_hdw_render_useless_unlocked(struct pvr2_hdw *hdw)
2880{ 3030{
2881 if (!hdw->flag_ok) return; 3031 if (!hdw->flag_ok) return;
@@ -2949,7 +3099,7 @@ int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *hdw)
2949 LOCK_TAKE(hdw->ctl_lock); do { 3099 LOCK_TAKE(hdw->ctl_lock); do {
2950 pvr2_trace(PVR2_TRACE_INIT,"Requesting uproc hard reset"); 3100 pvr2_trace(PVR2_TRACE_INIT,"Requesting uproc hard reset");
2951 hdw->flag_ok = !0; 3101 hdw->flag_ok = !0;
2952 hdw->cmd_buffer[0] = 0xdd; 3102 hdw->cmd_buffer[0] = FX2CMD_DEEP_RESET;
2953 status = pvr2_send_request(hdw,hdw->cmd_buffer,1,NULL,0); 3103 status = pvr2_send_request(hdw,hdw->cmd_buffer,1,NULL,0);
2954 } while (0); LOCK_GIVE(hdw->ctl_lock); 3104 } while (0); LOCK_GIVE(hdw->ctl_lock);
2955 return status; 3105 return status;
@@ -2961,7 +3111,7 @@ int pvr2_hdw_cmd_powerup(struct pvr2_hdw *hdw)
2961 int status; 3111 int status;
2962 LOCK_TAKE(hdw->ctl_lock); do { 3112 LOCK_TAKE(hdw->ctl_lock); do {
2963 pvr2_trace(PVR2_TRACE_INIT,"Requesting powerup"); 3113 pvr2_trace(PVR2_TRACE_INIT,"Requesting powerup");
2964 hdw->cmd_buffer[0] = 0xde; 3114 hdw->cmd_buffer[0] = FX2CMD_POWER_ON;
2965 status = pvr2_send_request(hdw,hdw->cmd_buffer,1,NULL,0); 3115 status = pvr2_send_request(hdw,hdw->cmd_buffer,1,NULL,0);
2966 } while (0); LOCK_GIVE(hdw->ctl_lock); 3116 } while (0); LOCK_GIVE(hdw->ctl_lock);
2967 return status; 3117 return status;
@@ -2994,7 +3144,8 @@ static int pvr2_hdw_cmd_usbstream(struct pvr2_hdw *hdw,int runFl)
2994{ 3144{
2995 int status; 3145 int status;
2996 LOCK_TAKE(hdw->ctl_lock); do { 3146 LOCK_TAKE(hdw->ctl_lock); do {
2997 hdw->cmd_buffer[0] = (runFl ? 0x36 : 0x37); 3147 hdw->cmd_buffer[0] =
3148 (runFl ? FX2CMD_STREAMING_ON : FX2CMD_STREAMING_OFF);
2998 status = pvr2_send_request(hdw,hdw->cmd_buffer,1,NULL,0); 3149 status = pvr2_send_request(hdw,hdw->cmd_buffer,1,NULL,0);
2999 } while (0); LOCK_GIVE(hdw->ctl_lock); 3150 } while (0); LOCK_GIVE(hdw->ctl_lock);
3000 if (!status) { 3151 if (!status) {
@@ -3093,7 +3244,7 @@ static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw)
3093{ 3244{
3094 int result; 3245 int result;
3095 LOCK_TAKE(hdw->ctl_lock); do { 3246 LOCK_TAKE(hdw->ctl_lock); do {
3096 hdw->cmd_buffer[0] = 0xeb; 3247 hdw->cmd_buffer[0] = FX2CMD_GET_EEPROM_ADDR;
3097 result = pvr2_send_request(hdw, 3248 result = pvr2_send_request(hdw,
3098 hdw->cmd_buffer,1, 3249 hdw->cmd_buffer,1,
3099 hdw->cmd_buffer,1); 3250 hdw->cmd_buffer,1);
@@ -3105,8 +3256,8 @@ static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw)
3105 3256
3106 3257
3107int pvr2_hdw_register_access(struct pvr2_hdw *hdw, 3258int pvr2_hdw_register_access(struct pvr2_hdw *hdw,
3108 u32 chip_id,unsigned long reg_id, 3259 u32 match_type, u32 match_chip, u64 reg_id,
3109 int setFl,u32 *val_ptr) 3260 int setFl,u64 *val_ptr)
3110{ 3261{
3111#ifdef CONFIG_VIDEO_ADV_DEBUG 3262#ifdef CONFIG_VIDEO_ADV_DEBUG
3112 struct list_head *item; 3263 struct list_head *item;
@@ -3115,16 +3266,21 @@ int pvr2_hdw_register_access(struct pvr2_hdw *hdw,
3115 int stat = 0; 3266 int stat = 0;
3116 int okFl = 0; 3267 int okFl = 0;
3117 3268
3118 req.i2c_id = chip_id; 3269 if (!capable(CAP_SYS_ADMIN)) return -EPERM;
3270
3271 req.match_type = match_type;
3272 req.match_chip = match_chip;
3119 req.reg = reg_id; 3273 req.reg = reg_id;
3120 if (setFl) req.val = *val_ptr; 3274 if (setFl) req.val = *val_ptr;
3121 mutex_lock(&hdw->i2c_list_lock); do { 3275 mutex_lock(&hdw->i2c_list_lock); do {
3122 list_for_each(item,&hdw->i2c_clients) { 3276 list_for_each(item,&hdw->i2c_clients) {
3123 cp = list_entry(item,struct pvr2_i2c_client,list); 3277 cp = list_entry(item,struct pvr2_i2c_client,list);
3124 if (cp->client->driver->id != chip_id) continue; 3278 if (!v4l2_chip_match_i2c_client(cp->client, req.match_type, req.match_chip)) {
3279 continue;
3280 }
3125 stat = pvr2_i2c_client_cmd( 3281 stat = pvr2_i2c_client_cmd(
3126 cp,(setFl ? VIDIOC_INT_S_REGISTER : 3282 cp,(setFl ? VIDIOC_DBG_S_REGISTER :
3127 VIDIOC_INT_G_REGISTER),&req); 3283 VIDIOC_DBG_G_REGISTER),&req);
3128 if (!setFl) *val_ptr = req.val; 3284 if (!setFl) *val_ptr = req.val;
3129 okFl = !0; 3285 okFl = !0;
3130 break; 3286 break;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.h b/drivers/media/video/pvrusb2/pvrusb2-hdw.h
index 29979bb2a7..0c9cca43ff 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.h
@@ -44,12 +44,6 @@
44#define PVR2_CVAL_INPUT_COMPOSITE 2 44#define PVR2_CVAL_INPUT_COMPOSITE 2
45#define PVR2_CVAL_INPUT_RADIO 3 45#define PVR2_CVAL_INPUT_RADIO 3
46 46
47/* Values that pvr2_hdw_get_signal_status() returns */
48#define PVR2_SIGNAL_OK 0x0001
49#define PVR2_SIGNAL_STEREO 0x0002
50#define PVR2_SIGNAL_SAP 0x0004
51
52
53/* Subsystem definitions - these are various pieces that can be 47/* Subsystem definitions - these are various pieces that can be
54 independently stopped / started. Usually you don't want to mess with 48 independently stopped / started. Usually you don't want to mess with
55 this directly (let the driver handle things itself), but it is useful 49 this directly (let the driver handle things itself), but it is useful
@@ -72,10 +66,17 @@
72 PVR2_SUBSYS_RUN_ALL ) 66 PVR2_SUBSYS_RUN_ALL )
73 67
74enum pvr2_config { 68enum pvr2_config {
75 pvr2_config_empty, 69 pvr2_config_empty, /* No configuration */
76 pvr2_config_mpeg, 70 pvr2_config_mpeg, /* Encoded / compressed video */
77 pvr2_config_vbi, 71 pvr2_config_vbi, /* Standard vbi info */
78 pvr2_config_radio, 72 pvr2_config_pcm, /* Audio raw pcm stream */
73 pvr2_config_rawvideo, /* Video raw frames */
74};
75
76enum pvr2_v4l_type {
77 pvr2_v4l_type_video,
78 pvr2_v4l_type_vbi,
79 pvr2_v4l_type_radio,
79}; 80};
80 81
81const char *pvr2_config_get_name(enum pvr2_config); 82const char *pvr2_config_get_name(enum pvr2_config);
@@ -148,8 +149,11 @@ int pvr2_hdw_commit_ctl(struct pvr2_hdw *);
148/* Return name for this driver instance */ 149/* Return name for this driver instance */
149const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *); 150const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *);
150 151
151/* Return PVR2_SIGNAL_XXXX bit mask indicating signal status */ 152/* Mark tuner status stale so that it will be re-fetched */
152unsigned int pvr2_hdw_get_signal_status(struct pvr2_hdw *); 153void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *);
154
155/* Return information about the tuner */
156int pvr2_hdw_get_tuner_status(struct pvr2_hdw *,struct v4l2_tuner *);
153 157
154/* Query device and see if it thinks it is on a high-speed USB link */ 158/* Query device and see if it thinks it is on a high-speed USB link */
155int pvr2_hdw_is_hsm(struct pvr2_hdw *); 159int pvr2_hdw_is_hsm(struct pvr2_hdw *);
@@ -205,20 +209,22 @@ int pvr2_hdw_cpufw_get_enabled(struct pvr2_hdw *);
205int pvr2_hdw_cpufw_get(struct pvr2_hdw *,unsigned int offs, 209int pvr2_hdw_cpufw_get(struct pvr2_hdw *,unsigned int offs,
206 char *buf,unsigned int cnt); 210 char *buf,unsigned int cnt);
207 211
208/* Retrieve previously stored v4l minor device number */ 212/* Retrieve a previously stored v4l minor device number */
209int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *); 213int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *,enum pvr2_v4l_type index);
210 214
211/* Store the v4l minor device number */ 215/* Store a v4l minor device number */
212void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,int); 216void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,
217 enum pvr2_v4l_type index,int);
213 218
214/* Direct read/write access to chip's registers: 219/* Direct read/write access to chip's registers:
215 chip_id - unique id of chip (e.g. I2C_DRIVERD_xxxx) 220 match_type - how to interpret match_chip (e.g. driver ID, i2c address)
221 match_chip - chip match value (e.g. I2C_DRIVERD_xxxx)
216 reg_id - register number to access 222 reg_id - register number to access
217 setFl - true to set the register, false to read it 223 setFl - true to set the register, false to read it
218 val_ptr - storage location for source / result. */ 224 val_ptr - storage location for source / result. */
219int pvr2_hdw_register_access(struct pvr2_hdw *, 225int pvr2_hdw_register_access(struct pvr2_hdw *,
220 u32 chip_id,unsigned long reg_id, 226 u32 match_type, u32 match_chip,u64 reg_id,
221 int setFl,u32 *val_ptr); 227 int setFl,u64 *val_ptr);
222 228
223/* The following entry points are all lower level things you normally don't 229/* The following entry points are all lower level things you normally don't
224 want to worry about. */ 230 want to worry about. */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c
index 05121666b9..4977376438 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c
@@ -33,15 +33,17 @@
33#define trace_i2c(...) pvr2_trace(PVR2_TRACE_I2C,__VA_ARGS__) 33#define trace_i2c(...) pvr2_trace(PVR2_TRACE_I2C,__VA_ARGS__)
34 34
35#define OP_STANDARD 0 35#define OP_STANDARD 0
36#define OP_BCSH 1 36#define OP_AUDIOMODE 1
37#define OP_VOLUME 2 37#define OP_BCSH 2
38#define OP_FREQ 3 38#define OP_VOLUME 3
39#define OP_AUDIORATE 4 39#define OP_FREQ 4
40#define OP_SIZE 5 40#define OP_AUDIORATE 5
41#define OP_LOG 6 41#define OP_SIZE 6
42#define OP_LOG 7
42 43
43static const struct pvr2_i2c_op * const ops[] = { 44static const struct pvr2_i2c_op * const ops[] = {
44 [OP_STANDARD] = &pvr2_i2c_op_v4l2_standard, 45 [OP_STANDARD] = &pvr2_i2c_op_v4l2_standard,
46 [OP_AUDIOMODE] = &pvr2_i2c_op_v4l2_audiomode,
45 [OP_BCSH] = &pvr2_i2c_op_v4l2_bcsh, 47 [OP_BCSH] = &pvr2_i2c_op_v4l2_bcsh,
46 [OP_VOLUME] = &pvr2_i2c_op_v4l2_volume, 48 [OP_VOLUME] = &pvr2_i2c_op_v4l2_volume,
47 [OP_FREQ] = &pvr2_i2c_op_v4l2_frequency, 49 [OP_FREQ] = &pvr2_i2c_op_v4l2_frequency,
@@ -54,11 +56,13 @@ void pvr2_i2c_probe(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
54 int id; 56 int id;
55 id = cp->client->driver->id; 57 id = cp->client->driver->id;
56 cp->ctl_mask = ((1 << OP_STANDARD) | 58 cp->ctl_mask = ((1 << OP_STANDARD) |
59 (1 << OP_AUDIOMODE) |
57 (1 << OP_BCSH) | 60 (1 << OP_BCSH) |
58 (1 << OP_VOLUME) | 61 (1 << OP_VOLUME) |
59 (1 << OP_FREQ) | 62 (1 << OP_FREQ) |
60 (1 << OP_SIZE) | 63 (1 << OP_SIZE) |
61 (1 << OP_LOG)); 64 (1 << OP_LOG));
65 cp->status_poll = pvr2_v4l2_cmd_status_poll;
62 66
63 if (id == I2C_DRIVERID_MSP3400) { 67 if (id == I2C_DRIVERID_MSP3400) {
64 if (pvr2_i2c_msp3400_setup(hdw,cp)) { 68 if (pvr2_i2c_msp3400_setup(hdw,cp)) {
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c
index 05ea17afe9..c650e02ccd 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c
@@ -24,22 +24,26 @@
24#include "pvrusb2-hdw-internal.h" 24#include "pvrusb2-hdw-internal.h"
25#include "pvrusb2-debug.h" 25#include "pvrusb2-debug.h"
26#include <linux/videodev2.h> 26#include <linux/videodev2.h>
27 27#include <media/v4l2-common.h>
28 28
29static void set_standard(struct pvr2_hdw *hdw) 29static void set_standard(struct pvr2_hdw *hdw)
30{ 30{
31 v4l2_std_id vs; 31 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_standard");
32 vs = hdw->std_mask_cur; 32
33 pvr2_trace(PVR2_TRACE_CHIPS, 33 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
34 "i2c v4l2 set_standard(0x%llx)",(long long unsigned)vs); 34 pvr2_i2c_core_cmd(hdw,AUDC_SET_RADIO,NULL);
35 35 } else {
36 pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs); 36 v4l2_std_id vs;
37 vs = hdw->std_mask_cur;
38 pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs);
39 }
40 hdw->tuner_signal_stale = !0;
37} 41}
38 42
39 43
40static int check_standard(struct pvr2_hdw *hdw) 44static int check_standard(struct pvr2_hdw *hdw)
41{ 45{
42 return hdw->std_dirty != 0; 46 return (hdw->input_dirty != 0) || (hdw->std_dirty != 0);
43} 47}
44 48
45 49
@@ -136,16 +140,53 @@ const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume = {
136}; 140};
137 141
138 142
143static void set_audiomode(struct pvr2_hdw *hdw)
144{
145 struct v4l2_tuner vt;
146 memset(&vt,0,sizeof(vt));
147 vt.audmode = hdw->audiomode_val;
148 pvr2_i2c_core_cmd(hdw,VIDIOC_S_TUNER,&vt);
149}
150
151
152static int check_audiomode(struct pvr2_hdw *hdw)
153{
154 return (hdw->input_dirty ||
155 hdw->audiomode_dirty);
156}
157
158
159const struct pvr2_i2c_op pvr2_i2c_op_v4l2_audiomode = {
160 .check = check_audiomode,
161 .update = set_audiomode,
162 .name = "v4l2_audiomode",
163};
164
165
139static void set_frequency(struct pvr2_hdw *hdw) 166static void set_frequency(struct pvr2_hdw *hdw)
140{ 167{
141 unsigned long fv; 168 unsigned long fv;
142 struct v4l2_frequency freq; 169 struct v4l2_frequency freq;
143 fv = hdw->freqVal; 170 fv = pvr2_hdw_get_cur_freq(hdw);
144 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv); 171 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv);
172 if (hdw->tuner_signal_stale) {
173 pvr2_i2c_core_status_poll(hdw);
174 }
145 memset(&freq,0,sizeof(freq)); 175 memset(&freq,0,sizeof(freq));
146 freq.frequency = fv / 62500; 176 if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) {
177 // ((fv * 1000) / 62500)
178 freq.frequency = (fv * 2) / 125;
179 } else {
180 freq.frequency = fv / 62500;
181 }
182 /* tuner-core currently doesn't seem to care about this, but
183 let's set it anyway for completeness. */
184 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
185 freq.type = V4L2_TUNER_RADIO;
186 } else {
187 freq.type = V4L2_TUNER_ANALOG_TV;
188 }
147 freq.tuner = 0; 189 freq.tuner = 0;
148 freq.type = V4L2_TUNER_ANALOG_TV;
149 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq); 190 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq);
150} 191}
151 192
@@ -221,6 +262,12 @@ void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl)
221} 262}
222 263
223 264
265void pvr2_v4l2_cmd_status_poll(struct pvr2_i2c_client *cp)
266{
267 pvr2_i2c_client_cmd(cp,VIDIOC_G_TUNER,&cp->hdw->tuner_signal_info);
268}
269
270
224/* 271/*
225 Stuff for Emacs to see, in order to encourage consistent editing style: 272 Stuff for Emacs to see, in order to encourage consistent editing style:
226 *** Local Variables: *** 273 *** Local Variables: ***
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h b/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h
index ecabddba1e..c838df6167 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h
@@ -26,13 +26,16 @@
26#include "pvrusb2-i2c-core.h" 26#include "pvrusb2-i2c-core.h"
27 27
28extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard; 28extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard;
29extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_radio;
29extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh; 30extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh;
30extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume; 31extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume;
31extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency; 32extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency;
32extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size; 33extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size;
34extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_audiomode;
33extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log; 35extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log;
34 36
35void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *,int); 37void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *,int);
38void pvr2_v4l2_cmd_status_poll(struct pvr2_i2c_client *);
36 39
37#endif /* __PVRUSB2_CMD_V4L2_H */ 40#endif /* __PVRUSB2_CMD_V4L2_H */
38 41
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
index 62a7cfca83..58fc3c730f 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
@@ -22,6 +22,7 @@
22#include "pvrusb2-i2c-core.h" 22#include "pvrusb2-i2c-core.h"
23#include "pvrusb2-hdw-internal.h" 23#include "pvrusb2-hdw-internal.h"
24#include "pvrusb2-debug.h" 24#include "pvrusb2-debug.h"
25#include "pvrusb2-fx2-cmd.h"
25 26
26#define trace_i2c(...) pvr2_trace(PVR2_TRACE_I2C,__VA_ARGS__) 27#define trace_i2c(...) pvr2_trace(PVR2_TRACE_I2C,__VA_ARGS__)
27 28
@@ -66,7 +67,7 @@ static int pvr2_i2c_write(struct pvr2_hdw *hdw, /* Context */
66 memset(hdw->cmd_buffer, 0, sizeof(hdw->cmd_buffer)); 67 memset(hdw->cmd_buffer, 0, sizeof(hdw->cmd_buffer));
67 68
68 /* Set up command buffer for an I2C write */ 69 /* Set up command buffer for an I2C write */
69 hdw->cmd_buffer[0] = 0x08; /* write prefix */ 70 hdw->cmd_buffer[0] = FX2CMD_I2C_WRITE; /* write prefix */
70 hdw->cmd_buffer[1] = i2c_addr; /* i2c addr of chip */ 71 hdw->cmd_buffer[1] = i2c_addr; /* i2c addr of chip */
71 hdw->cmd_buffer[2] = length; /* length of what follows */ 72 hdw->cmd_buffer[2] = length; /* length of what follows */
72 if (length) memcpy(hdw->cmd_buffer + 3, data, length); 73 if (length) memcpy(hdw->cmd_buffer + 3, data, length);
@@ -128,7 +129,7 @@ static int pvr2_i2c_read(struct pvr2_hdw *hdw, /* Context */
128 memset(hdw->cmd_buffer, 0, sizeof(hdw->cmd_buffer)); 129 memset(hdw->cmd_buffer, 0, sizeof(hdw->cmd_buffer));
129 130
130 /* Set up command buffer for an I2C write followed by a read */ 131 /* Set up command buffer for an I2C write followed by a read */
131 hdw->cmd_buffer[0] = 0x09; /* read prefix */ 132 hdw->cmd_buffer[0] = FX2CMD_I2C_READ; /* read prefix */
132 hdw->cmd_buffer[1] = dlen; /* arg length */ 133 hdw->cmd_buffer[1] = dlen; /* arg length */
133 hdw->cmd_buffer[2] = rlen; /* answer length. Device will send one 134 hdw->cmd_buffer[2] = rlen; /* answer length. Device will send one
134 more byte (status). */ 135 more byte (status). */
@@ -221,7 +222,7 @@ static int i2c_24xxx_ir(struct pvr2_hdw *hdw,
221 222
222 /* Issue a command to the FX2 to read the IR receiver. */ 223 /* Issue a command to the FX2 to read the IR receiver. */
223 LOCK_TAKE(hdw->ctl_lock); do { 224 LOCK_TAKE(hdw->ctl_lock); do {
224 hdw->cmd_buffer[0] = 0xec; 225 hdw->cmd_buffer[0] = FX2CMD_GET_IR_CODE;
225 stat = pvr2_send_request(hdw, 226 stat = pvr2_send_request(hdw,
226 hdw->cmd_buffer,1, 227 hdw->cmd_buffer,1,
227 hdw->cmd_buffer,4); 228 hdw->cmd_buffer,4);
@@ -590,6 +591,33 @@ static int handler_check(struct pvr2_i2c_client *cp)
590 591
591#define BUFSIZE 500 592#define BUFSIZE 500
592 593
594
595void pvr2_i2c_core_status_poll(struct pvr2_hdw *hdw)
596{
597 struct list_head *item;
598 struct pvr2_i2c_client *cp;
599 mutex_lock(&hdw->i2c_list_lock); do {
600 struct v4l2_tuner *vtp = &hdw->tuner_signal_info;
601 memset(vtp,0,sizeof(*vtp));
602 list_for_each(item,&hdw->i2c_clients) {
603 cp = list_entry(item,struct pvr2_i2c_client,list);
604 if (!cp->detected_flag) continue;
605 if (!cp->status_poll) continue;
606 cp->status_poll(cp);
607 }
608 hdw->tuner_signal_stale = 0;
609 pvr2_trace(PVR2_TRACE_CHIPS,"i2c status poll"
610 " type=%u strength=%u audio=0x%x cap=0x%x"
611 " low=%u hi=%u",
612 vtp->type,
613 vtp->signal,vtp->rxsubchans,vtp->capability,
614 vtp->rangelow,vtp->rangehigh);
615 } while (0); mutex_unlock(&hdw->i2c_list_lock);
616}
617
618
619/* Issue various I2C operations to bring chip-level drivers into sync with
620 state stored in this driver. */
593void pvr2_i2c_core_sync(struct pvr2_hdw *hdw) 621void pvr2_i2c_core_sync(struct pvr2_hdw *hdw)
594{ 622{
595 unsigned long msk; 623 unsigned long msk;
@@ -870,12 +898,12 @@ static int pvr2_i2c_attach_inform(struct i2c_client *client)
870 struct pvr2_hdw *hdw = (struct pvr2_hdw *)(client->adapter->algo_data); 898 struct pvr2_hdw *hdw = (struct pvr2_hdw *)(client->adapter->algo_data);
871 struct pvr2_i2c_client *cp; 899 struct pvr2_i2c_client *cp;
872 int fl = !(hdw->i2c_pend_types & PVR2_I2C_PEND_ALL); 900 int fl = !(hdw->i2c_pend_types & PVR2_I2C_PEND_ALL);
873 cp = kmalloc(sizeof(*cp),GFP_KERNEL); 901 cp = kzalloc(sizeof(*cp),GFP_KERNEL);
874 trace_i2c("i2c_attach [client=%s @ 0x%x ctxt=%p]", 902 trace_i2c("i2c_attach [client=%s @ 0x%x ctxt=%p]",
875 client->name, 903 client->name,
876 client->addr,cp); 904 client->addr,cp);
877 if (!cp) return -ENOMEM; 905 if (!cp) return -ENOMEM;
878 memset(cp,0,sizeof(*cp)); 906 cp->hdw = hdw;
879 INIT_LIST_HEAD(&cp->list); 907 INIT_LIST_HEAD(&cp->list);
880 cp->client = client; 908 cp->client = client;
881 mutex_lock(&hdw->i2c_list_lock); do { 909 mutex_lock(&hdw->i2c_list_lock); do {
@@ -948,8 +976,7 @@ static void do_i2c_scan(struct pvr2_hdw *hdw)
948 printk("%s: i2c scan beginning\n",hdw->name); 976 printk("%s: i2c scan beginning\n",hdw->name);
949 for (i = 0; i < 128; i++) { 977 for (i = 0; i < 128; i++) {
950 msg[0].addr = i; 978 msg[0].addr = i;
951 rc = i2c_transfer(&hdw->i2c_adap,msg, 979 rc = i2c_transfer(&hdw->i2c_adap,msg, ARRAY_SIZE(msg));
952 sizeof(msg)/sizeof(msg[0]));
953 if (rc != 1) continue; 980 if (rc != 1) continue;
954 printk("%s: i2c scan: found device @ 0x%x\n",hdw->name,i); 981 printk("%s: i2c scan: found device @ 0x%x\n",hdw->name,i);
955 } 982 }
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.h b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.h
index 6d7e252475..bd0807b905 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.h
@@ -35,10 +35,12 @@ struct pvr2_i2c_client {
35 struct i2c_client *client; 35 struct i2c_client *client;
36 struct pvr2_i2c_handler *handler; 36 struct pvr2_i2c_handler *handler;
37 struct list_head list; 37 struct list_head list;
38 struct pvr2_hdw *hdw;
38 int detected_flag; 39 int detected_flag;
39 int recv_enable; 40 int recv_enable;
40 unsigned long pend_mask; 41 unsigned long pend_mask;
41 unsigned long ctl_mask; 42 unsigned long ctl_mask;
43 void (*status_poll)(struct pvr2_i2c_client *);
42}; 44};
43 45
44struct pvr2_i2c_handler { 46struct pvr2_i2c_handler {
@@ -67,6 +69,7 @@ int pvr2_i2c_core_cmd(struct pvr2_hdw *,unsigned int cmd,void *arg);
67 69
68int pvr2_i2c_core_check_stale(struct pvr2_hdw *); 70int pvr2_i2c_core_check_stale(struct pvr2_hdw *);
69void pvr2_i2c_core_sync(struct pvr2_hdw *); 71void pvr2_i2c_core_sync(struct pvr2_hdw *);
72void pvr2_i2c_core_status_poll(struct pvr2_hdw *);
70unsigned int pvr2_i2c_report(struct pvr2_hdw *,char *buf,unsigned int maxlen); 73unsigned int pvr2_i2c_report(struct pvr2_hdw *,char *buf,unsigned int maxlen);
71#define PVR2_I2C_DETAIL_DEBUG 0x0001 74#define PVR2_I2C_DETAIL_DEBUG 0x0001
72#define PVR2_I2C_DETAIL_HANDLER 0x0002 75#define PVR2_I2C_DETAIL_HANDLER 0x0002
diff --git a/drivers/media/video/pvrusb2/pvrusb2-io.c b/drivers/media/video/pvrusb2/pvrusb2-io.c
index 57fb320335..ce3c8982ff 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-io.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-io.c
@@ -474,9 +474,8 @@ static void buffer_complete(struct urb *urb)
474struct pvr2_stream *pvr2_stream_create(void) 474struct pvr2_stream *pvr2_stream_create(void)
475{ 475{
476 struct pvr2_stream *sp; 476 struct pvr2_stream *sp;
477 sp = kmalloc(sizeof(*sp),GFP_KERNEL); 477 sp = kzalloc(sizeof(*sp),GFP_KERNEL);
478 if (!sp) return sp; 478 if (!sp) return sp;
479 memset(sp,0,sizeof(*sp));
480 pvr2_trace(PVR2_TRACE_INIT,"pvr2_stream_create: sp=%p",sp); 479 pvr2_trace(PVR2_TRACE_INIT,"pvr2_stream_create: sp=%p",sp);
481 pvr2_stream_init(sp); 480 pvr2_stream_init(sp);
482 return sp; 481 return sp;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ioread.c b/drivers/media/video/pvrusb2/pvrusb2-ioread.c
index b71f9a961f..f782418afa 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-ioread.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-ioread.c
@@ -87,10 +87,9 @@ static void pvr2_ioread_done(struct pvr2_ioread *cp)
87struct pvr2_ioread *pvr2_ioread_create(void) 87struct pvr2_ioread *pvr2_ioread_create(void)
88{ 88{
89 struct pvr2_ioread *cp; 89 struct pvr2_ioread *cp;
90 cp = kmalloc(sizeof(*cp),GFP_KERNEL); 90 cp = kzalloc(sizeof(*cp),GFP_KERNEL);
91 if (!cp) return NULL; 91 if (!cp) return NULL;
92 pvr2_trace(PVR2_TRACE_STRUCT,"pvr2_ioread_create id=%p",cp); 92 pvr2_trace(PVR2_TRACE_STRUCT,"pvr2_ioread_create id=%p",cp);
93 memset(cp,0,sizeof(*cp));
94 if (pvr2_ioread_init(cp) < 0) { 93 if (pvr2_ioread_init(cp) < 0) {
95 kfree(cp); 94 kfree(cp);
96 return NULL; 95 return NULL;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-std.c b/drivers/media/video/pvrusb2/pvrusb2-std.c
index f95c598ff6..81de26ba41 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-std.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-std.c
@@ -78,14 +78,14 @@ struct std_name {
78#define CSTD_ALL (CSTD_PAL|CSTD_NTSC|CSTD_SECAM) 78#define CSTD_ALL (CSTD_PAL|CSTD_NTSC|CSTD_SECAM)
79 79
80/* Mapping of standard bits to color system */ 80/* Mapping of standard bits to color system */
81const static struct std_name std_groups[] = { 81static const struct std_name std_groups[] = {
82 {"PAL",CSTD_PAL}, 82 {"PAL",CSTD_PAL},
83 {"NTSC",CSTD_NTSC}, 83 {"NTSC",CSTD_NTSC},
84 {"SECAM",CSTD_SECAM}, 84 {"SECAM",CSTD_SECAM},
85}; 85};
86 86
87/* Mapping of standard bits to modulation system */ 87/* Mapping of standard bits to modulation system */
88const static struct std_name std_items[] = { 88static const struct std_name std_items[] = {
89 {"B",TSTD_B}, 89 {"B",TSTD_B},
90 {"B1",TSTD_B1}, 90 {"B1",TSTD_B1},
91 {"D",TSTD_D}, 91 {"D",TSTD_D},
@@ -141,10 +141,8 @@ int pvr2_std_str_to_id(v4l2_std_id *idPtr,const char *bufPtr,
141 cnt = 0; 141 cnt = 0;
142 while ((cnt < bufSize) && (bufPtr[cnt] != '-')) cnt++; 142 while ((cnt < bufSize) && (bufPtr[cnt] != '-')) cnt++;
143 if (cnt >= bufSize) return 0; // No more characters 143 if (cnt >= bufSize) return 0; // No more characters
144 sp = find_std_name( 144 sp = find_std_name(std_groups, ARRAY_SIZE(std_groups),
145 std_groups, 145 bufPtr,cnt);
146 sizeof(std_groups)/sizeof(std_groups[0]),
147 bufPtr,cnt);
148 if (!sp) return 0; // Illegal color system name 146 if (!sp) return 0; // Illegal color system name
149 cnt++; 147 cnt++;
150 bufPtr += cnt; 148 bufPtr += cnt;
@@ -163,8 +161,7 @@ int pvr2_std_str_to_id(v4l2_std_id *idPtr,const char *bufPtr,
163 if (ch == '/') break; 161 if (ch == '/') break;
164 cnt++; 162 cnt++;
165 } 163 }
166 sp = find_std_name(std_items, 164 sp = find_std_name(std_items, ARRAY_SIZE(std_items),
167 sizeof(std_items)/sizeof(std_items[0]),
168 bufPtr,cnt); 165 bufPtr,cnt);
169 if (!sp) return 0; // Illegal modulation system ID 166 if (!sp) return 0; // Illegal modulation system ID
170 t = sp->id & cmsk; 167 t = sp->id & cmsk;
@@ -189,14 +186,10 @@ unsigned int pvr2_std_id_to_str(char *bufPtr, unsigned int bufSize,
189 unsigned int c1,c2; 186 unsigned int c1,c2;
190 cfl = 0; 187 cfl = 0;
191 c1 = 0; 188 c1 = 0;
192 for (idx1 = 0; 189 for (idx1 = 0; idx1 < ARRAY_SIZE(std_groups); idx1++) {
193 idx1 < sizeof(std_groups)/sizeof(std_groups[0]);
194 idx1++) {
195 gp = std_groups + idx1; 190 gp = std_groups + idx1;
196 gfl = 0; 191 gfl = 0;
197 for (idx2 = 0; 192 for (idx2 = 0; idx2 < ARRAY_SIZE(std_items); idx2++) {
198 idx2 < sizeof(std_items)/sizeof(std_items[0]);
199 idx2++) {
200 ip = std_items + idx2; 193 ip = std_items + idx2;
201 if (!(gp->id & ip->id & id)) continue; 194 if (!(gp->id & ip->id & id)) continue;
202 if (!gfl) { 195 if (!gfl) {
@@ -279,7 +272,7 @@ static struct v4l2_standard generic_standards[] = {
279 } 272 }
280}; 273};
281 274
282#define generic_standards_cnt (sizeof(generic_standards)/sizeof(generic_standards[0])) 275#define generic_standards_cnt ARRAY_SIZE(generic_standards)
283 276
284static struct v4l2_standard *match_std(v4l2_std_id id) 277static struct v4l2_standard *match_std(v4l2_std_id id)
285{ 278{
@@ -348,7 +341,7 @@ struct v4l2_standard *pvr2_std_create_enum(unsigned int *countptr,
348 fmsk |= idmsk; 341 fmsk |= idmsk;
349 } 342 }
350 343
351 for (idx2 = 0; idx2 < sizeof(std_mixes)/sizeof(std_mixes[0]); idx2++) { 344 for (idx2 = 0; idx2 < ARRAY_SIZE(std_mixes); idx2++) {
352 if ((id & std_mixes[idx2]) == std_mixes[idx2]) std_cnt++; 345 if ((id & std_mixes[idx2]) == std_mixes[idx2]) std_cnt++;
353 } 346 }
354 347
@@ -366,16 +359,15 @@ struct v4l2_standard *pvr2_std_create_enum(unsigned int *countptr,
366 std_cnt); 359 std_cnt);
367 if (!std_cnt) return NULL; // paranoia 360 if (!std_cnt) return NULL; // paranoia
368 361
369 stddefs = kmalloc(sizeof(struct v4l2_standard) * std_cnt, 362 stddefs = kzalloc(sizeof(struct v4l2_standard) * std_cnt,
370 GFP_KERNEL); 363 GFP_KERNEL);
371 memset(stddefs,0,sizeof(struct v4l2_standard) * std_cnt);
372 for (idx = 0; idx < std_cnt; idx++) stddefs[idx].index = idx; 364 for (idx = 0; idx < std_cnt; idx++) stddefs[idx].index = idx;
373 365
374 idx = 0; 366 idx = 0;
375 367
376 /* Enumerate potential special cases */ 368 /* Enumerate potential special cases */
377 for (idx2 = 0; ((idx2 < sizeof(std_mixes)/sizeof(std_mixes[0])) && 369 for (idx2 = 0; (idx2 < ARRAY_SIZE(std_mixes)) && (idx < std_cnt);
378 (idx < std_cnt)); idx2++) { 370 idx2++) {
379 if (!(id & std_mixes[idx2])) continue; 371 if (!(id & std_mixes[idx2])) continue;
380 if (pvr2_std_fill(stddefs+idx,std_mixes[idx2])) idx++; 372 if (pvr2_std_fill(stddefs+idx,std_mixes[idx2])) idx++;
381 } 373 }
diff --git a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
index c294f46db9..91396fd573 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
@@ -40,8 +40,10 @@ struct pvr2_sysfs {
40 struct pvr2_sysfs_ctl_item *item_first; 40 struct pvr2_sysfs_ctl_item *item_first;
41 struct pvr2_sysfs_ctl_item *item_last; 41 struct pvr2_sysfs_ctl_item *item_last;
42 struct class_device_attribute attr_v4l_minor_number; 42 struct class_device_attribute attr_v4l_minor_number;
43 struct class_device_attribute attr_v4l_radio_minor_number;
43 struct class_device_attribute attr_unit_number; 44 struct class_device_attribute attr_unit_number;
44 int v4l_minor_number_created_ok; 45 int v4l_minor_number_created_ok;
46 int v4l_radio_minor_number_created_ok;
45 int unit_number_created_ok; 47 int unit_number_created_ok;
46}; 48};
47 49
@@ -491,7 +493,7 @@ static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
491 unsigned int cnt,acnt; 493 unsigned int cnt,acnt;
492 int ret; 494 int ret;
493 495
494 if ((ctl_id < 0) || (ctl_id >= (sizeof(funcs)/sizeof(funcs[0])))) { 496 if ((ctl_id < 0) || (ctl_id >= ARRAY_SIZE(funcs))) {
495 return; 497 return;
496 } 498 }
497 499
@@ -499,9 +501,8 @@ static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
499 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id); 501 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id);
500 if (!cptr) return; 502 if (!cptr) return;
501 503
502 cip = kmalloc(sizeof(*cip),GFP_KERNEL); 504 cip = kzalloc(sizeof(*cip),GFP_KERNEL);
503 if (!cip) return; 505 if (!cip) return;
504 memset(cip,0,sizeof(*cip));
505 pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip); 506 pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip);
506 507
507 cip->cptr = cptr; 508 cip->cptr = cptr;
@@ -611,9 +612,8 @@ static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
611 struct pvr2_sysfs_debugifc *dip; 612 struct pvr2_sysfs_debugifc *dip;
612 int ret; 613 int ret;
613 614
614 dip = kmalloc(sizeof(*dip),GFP_KERNEL); 615 dip = kzalloc(sizeof(*dip),GFP_KERNEL);
615 if (!dip) return; 616 if (!dip) return;
616 memset(dip,0,sizeof(*dip));
617 dip->attr_debugcmd.attr.owner = THIS_MODULE; 617 dip->attr_debugcmd.attr.owner = THIS_MODULE;
618 dip->attr_debugcmd.attr.name = "debugcmd"; 618 dip->attr_debugcmd.attr.name = "debugcmd";
619 dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP; 619 dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP;
@@ -709,6 +709,10 @@ static void class_dev_destroy(struct pvr2_sysfs *sfp)
709 class_device_remove_file(sfp->class_dev, 709 class_device_remove_file(sfp->class_dev,
710 &sfp->attr_v4l_minor_number); 710 &sfp->attr_v4l_minor_number);
711 } 711 }
712 if (sfp->v4l_radio_minor_number_created_ok) {
713 class_device_remove_file(sfp->class_dev,
714 &sfp->attr_v4l_radio_minor_number);
715 }
712 if (sfp->unit_number_created_ok) { 716 if (sfp->unit_number_created_ok) {
713 class_device_remove_file(sfp->class_dev, 717 class_device_remove_file(sfp->class_dev,
714 &sfp->attr_unit_number); 718 &sfp->attr_unit_number);
@@ -726,7 +730,20 @@ static ssize_t v4l_minor_number_show(struct class_device *class_dev,char *buf)
726 sfp = (struct pvr2_sysfs *)class_dev->class_data; 730 sfp = (struct pvr2_sysfs *)class_dev->class_data;
727 if (!sfp) return -EINVAL; 731 if (!sfp) return -EINVAL;
728 return scnprintf(buf,PAGE_SIZE,"%d\n", 732 return scnprintf(buf,PAGE_SIZE,"%d\n",
729 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw)); 733 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
734 pvr2_v4l_type_video));
735}
736
737
738static ssize_t v4l_radio_minor_number_show(struct class_device *class_dev,
739 char *buf)
740{
741 struct pvr2_sysfs *sfp;
742 sfp = (struct pvr2_sysfs *)class_dev->class_data;
743 if (!sfp) return -EINVAL;
744 return scnprintf(buf,PAGE_SIZE,"%d\n",
745 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
746 pvr2_v4l_type_radio));
730} 747}
731 748
732 749
@@ -749,9 +766,8 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
749 766
750 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw); 767 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw);
751 if (!usb_dev) return; 768 if (!usb_dev) return;
752 class_dev = kmalloc(sizeof(*class_dev),GFP_KERNEL); 769 class_dev = kzalloc(sizeof(*class_dev),GFP_KERNEL);
753 if (!class_dev) return; 770 if (!class_dev) return;
754 memset(class_dev,0,sizeof(*class_dev));
755 771
756 pvr2_sysfs_trace("Creating class_dev id=%p",class_dev); 772 pvr2_sysfs_trace("Creating class_dev id=%p",class_dev);
757 773
@@ -793,6 +809,20 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
793 sfp->v4l_minor_number_created_ok = !0; 809 sfp->v4l_minor_number_created_ok = !0;
794 } 810 }
795 811
812 sfp->attr_v4l_radio_minor_number.attr.owner = THIS_MODULE;
813 sfp->attr_v4l_radio_minor_number.attr.name = "v4l_radio_minor_number";
814 sfp->attr_v4l_radio_minor_number.attr.mode = S_IRUGO;
815 sfp->attr_v4l_radio_minor_number.show = v4l_radio_minor_number_show;
816 sfp->attr_v4l_radio_minor_number.store = NULL;
817 ret = class_device_create_file(sfp->class_dev,
818 &sfp->attr_v4l_radio_minor_number);
819 if (ret < 0) {
820 printk(KERN_WARNING "%s: class_device_create_file error: %d\n",
821 __FUNCTION__, ret);
822 } else {
823 sfp->v4l_radio_minor_number_created_ok = !0;
824 }
825
796 sfp->attr_unit_number.attr.owner = THIS_MODULE; 826 sfp->attr_unit_number.attr.owner = THIS_MODULE;
797 sfp->attr_unit_number.attr.name = "unit_number"; 827 sfp->attr_unit_number.attr.name = "unit_number";
798 sfp->attr_unit_number.attr.mode = S_IRUGO; 828 sfp->attr_unit_number.attr.mode = S_IRUGO;
@@ -829,9 +859,8 @@ struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp,
829 struct pvr2_sysfs_class *class_ptr) 859 struct pvr2_sysfs_class *class_ptr)
830{ 860{
831 struct pvr2_sysfs *sfp; 861 struct pvr2_sysfs *sfp;
832 sfp = kmalloc(sizeof(*sfp),GFP_KERNEL); 862 sfp = kzalloc(sizeof(*sfp),GFP_KERNEL);
833 if (!sfp) return sfp; 863 if (!sfp) return sfp;
834 memset(sfp,0,sizeof(*sfp));
835 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_sysfs id=%p",sfp); 864 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_sysfs id=%p",sfp);
836 pvr2_channel_init(&sfp->channel,mp); 865 pvr2_channel_init(&sfp->channel,mp);
837 sfp->channel.check_func = pvr2_sysfs_internal_check; 866 sfp->channel.check_func = pvr2_sysfs_internal_check;
@@ -852,9 +881,8 @@ static int pvr2_sysfs_hotplug(struct class_device *cd,char **envp,
852struct pvr2_sysfs_class *pvr2_sysfs_class_create(void) 881struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
853{ 882{
854 struct pvr2_sysfs_class *clp; 883 struct pvr2_sysfs_class *clp;
855 clp = kmalloc(sizeof(*clp),GFP_KERNEL); 884 clp = kzalloc(sizeof(*clp),GFP_KERNEL);
856 if (!clp) return clp; 885 if (!clp) return clp;
857 memset(clp,0,sizeof(*clp));
858 pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp); 886 pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp);
859 clp->class.name = "pvrusb2"; 887 clp->class.name = "pvrusb2";
860 clp->class.class_release = pvr2_sysfs_class_release; 888 clp->class.class_release = pvr2_sysfs_class_release;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-tuner.c b/drivers/media/video/pvrusb2/pvrusb2-tuner.c
index af9f246f8d..05e65ce2e3 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-tuner.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-tuner.c
@@ -80,7 +80,7 @@ static unsigned int pvr2_tuner_describe(struct pvr2_tuner_handler *ctxt,char *bu
80} 80}
81 81
82 82
83const static struct pvr2_i2c_handler_functions tuner_funcs = { 83static const struct pvr2_i2c_handler_functions tuner_funcs = {
84 .detach = (void (*)(void *))pvr2_tuner_detach, 84 .detach = (void (*)(void *))pvr2_tuner_detach,
85 .check = (int (*)(void *))tuner_check, 85 .check = (int (*)(void *))tuner_check,
86 .update = (void (*)(void *))tuner_update, 86 .update = (void (*)(void *))tuner_update,
@@ -93,9 +93,8 @@ int pvr2_i2c_tuner_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
93 struct pvr2_tuner_handler *ctxt; 93 struct pvr2_tuner_handler *ctxt;
94 if (cp->handler) return 0; 94 if (cp->handler) return 0;
95 95
96 ctxt = kmalloc(sizeof(*ctxt),GFP_KERNEL); 96 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
97 if (!ctxt) return 0; 97 if (!ctxt) return 0;
98 memset(ctxt,0,sizeof(*ctxt));
99 98
100 ctxt->i2c_handler.func_data = ctxt; 99 ctxt->i2c_handler.func_data = ctxt;
101 ctxt->i2c_handler.func_table = &tuner_funcs; 100 ctxt->i2c_handler.func_table = &tuner_funcs;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
index 6cf17080eb..5313d34266 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
@@ -40,7 +40,10 @@ struct pvr2_v4l2_dev {
40 struct video_device devbase; /* MUST be first! */ 40 struct video_device devbase; /* MUST be first! */
41 struct pvr2_v4l2 *v4lp; 41 struct pvr2_v4l2 *v4lp;
42 struct pvr2_context_stream *stream; 42 struct pvr2_context_stream *stream;
43 enum pvr2_config config; 43 /* Information about this device: */
44 enum pvr2_config config; /* Expected stream format */
45 int v4l_type; /* V4L defined type for this device node */
46 enum pvr2_v4l_type minor_type; /* pvr2-understood minor device type */
44}; 47};
45 48
46struct pvr2_v4l2_fh { 49struct pvr2_v4l2_fh {
@@ -54,6 +57,7 @@ struct pvr2_v4l2_fh {
54 struct pvr2_v4l2_fh *vprev; 57 struct pvr2_v4l2_fh *vprev;
55 wait_queue_head_t wait_data; 58 wait_queue_head_t wait_data;
56 int fw_mode_flag; 59 int fw_mode_flag;
60 int prev_input_val;
57}; 61};
58 62
59struct pvr2_v4l2 { 63struct pvr2_v4l2 {
@@ -63,13 +67,22 @@ struct pvr2_v4l2 {
63 67
64 struct v4l2_prio_state prio; 68 struct v4l2_prio_state prio;
65 69
66 /* streams */ 70 /* streams - Note that these must be separately, individually,
67 struct pvr2_v4l2_dev *vdev; 71 * allocated pointers. This is because the v4l core is going to
72 * manage their deletion - separately, individually... */
73 struct pvr2_v4l2_dev *dev_video;
74 struct pvr2_v4l2_dev *dev_radio;
68}; 75};
69 76
70static int video_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1}; 77static int video_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1};
71module_param_array(video_nr, int, NULL, 0444); 78module_param_array(video_nr, int, NULL, 0444);
72MODULE_PARM_DESC(video_nr, "Offset for device's minor"); 79MODULE_PARM_DESC(video_nr, "Offset for device's video dev minor");
80static int radio_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1};
81module_param_array(radio_nr, int, NULL, 0444);
82MODULE_PARM_DESC(radio_nr, "Offset for device's radio dev minor");
83static int vbi_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1};
84module_param_array(vbi_nr, int, NULL, 0444);
85MODULE_PARM_DESC(vbi_nr, "Offset for device's vbi dev minor");
73 86
74static struct v4l2_capability pvr_capability ={ 87static struct v4l2_capability pvr_capability ={
75 .driver = "pvrusb2", 88 .driver = "pvrusb2",
@@ -77,30 +90,11 @@ static struct v4l2_capability pvr_capability ={
77 .bus_info = "usb", 90 .bus_info = "usb",
78 .version = KERNEL_VERSION(0,8,0), 91 .version = KERNEL_VERSION(0,8,0),
79 .capabilities = (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE | 92 .capabilities = (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE |
80 V4L2_CAP_TUNER | V4L2_CAP_AUDIO | 93 V4L2_CAP_TUNER | V4L2_CAP_AUDIO | V4L2_CAP_RADIO |
81 V4L2_CAP_READWRITE), 94 V4L2_CAP_READWRITE),
82 .reserved = {0,0,0,0} 95 .reserved = {0,0,0,0}
83}; 96};
84 97
85static struct v4l2_tuner pvr_v4l2_tuners[]= {
86 {
87 .index = 0,
88 .name = "TV Tuner",
89 .type = V4L2_TUNER_ANALOG_TV,
90 .capability = (V4L2_TUNER_CAP_NORM |
91 V4L2_TUNER_CAP_STEREO |
92 V4L2_TUNER_CAP_LANG1 |
93 V4L2_TUNER_CAP_LANG2),
94 .rangelow = 0,
95 .rangehigh = 0,
96 .rxsubchans = V4L2_TUNER_SUB_STEREO,
97 .audmode = V4L2_TUNER_MODE_STEREO,
98 .signal = 0,
99 .afc = 0,
100 .reserved = {0,0,0,0}
101 }
102};
103
104static struct v4l2_fmtdesc pvr_fmtdesc [] = { 98static struct v4l2_fmtdesc pvr_fmtdesc [] = {
105 { 99 {
106 .index = 0, 100 .index = 0,
@@ -154,6 +148,18 @@ static struct v4l2_format pvr_format [] = {
154 } 148 }
155}; 149};
156 150
151
152static const char *get_v4l_name(int v4l_type)
153{
154 switch (v4l_type) {
155 case VFL_TYPE_GRABBER: return "video";
156 case VFL_TYPE_RADIO: return "radio";
157 case VFL_TYPE_VBI: return "vbi";
158 default: return "?";
159 }
160}
161
162
157/* 163/*
158 * pvr_ioctl() 164 * pvr_ioctl()
159 * 165 *
@@ -315,13 +321,39 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
315 321
316 case VIDIOC_ENUMAUDIO: 322 case VIDIOC_ENUMAUDIO:
317 { 323 {
324 /* pkt: FIXME: We are returning one "fake" input here
325 which could very well be called "whatever_we_like".
326 This is for apps that want to see an audio input
327 just to feel comfortable, as well as to test if
328 it can do stereo or sth. There is actually no guarantee
329 that the actual audio input cannot change behind the app's
330 back, but most applications should not mind that either.
331
332 Hopefully, mplayer people will work with us on this (this
333 whole mess is to support mplayer pvr://), or Hans will come
334 up with a more standard way to say "we have inputs but we
335 don 't want you to change them independent of video" which
336 will sort this mess.
337 */
338 struct v4l2_audio *vin = arg;
318 ret = -EINVAL; 339 ret = -EINVAL;
340 if (vin->index > 0) break;
341 strncpy(vin->name, "PVRUSB2 Audio",14);
342 vin->capability = V4L2_AUDCAP_STEREO;
343 ret = 0;
344 break;
319 break; 345 break;
320 } 346 }
321 347
322 case VIDIOC_G_AUDIO: 348 case VIDIOC_G_AUDIO:
323 { 349 {
324 ret = -EINVAL; 350 /* pkt: FIXME: see above comment (VIDIOC_ENUMAUDIO) */
351 struct v4l2_audio *vin = arg;
352 memset(vin,0,sizeof(*vin));
353 vin->index = 0;
354 strncpy(vin->name, "PVRUSB2 Audio",14);
355 vin->capability = V4L2_AUDCAP_STEREO;
356 ret = 0;
325 break; 357 break;
326 } 358 }
327 359
@@ -333,34 +365,11 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
333 case VIDIOC_G_TUNER: 365 case VIDIOC_G_TUNER:
334 { 366 {
335 struct v4l2_tuner *vt = (struct v4l2_tuner *)arg; 367 struct v4l2_tuner *vt = (struct v4l2_tuner *)arg;
336 unsigned int status_mask;
337 int val;
338 if (vt->index !=0) break;
339 368
340 status_mask = pvr2_hdw_get_signal_status(hdw); 369 if (vt->index != 0) break; /* Only answer for the 1st tuner */
341 370
342 memcpy(vt, &pvr_v4l2_tuners[vt->index], 371 pvr2_hdw_execute_tuner_poll(hdw);
343 sizeof(struct v4l2_tuner)); 372 ret = pvr2_hdw_get_tuner_status(hdw,vt);
344
345 vt->signal = 0;
346 if (status_mask & PVR2_SIGNAL_OK) {
347 if (status_mask & PVR2_SIGNAL_STEREO) {
348 vt->rxsubchans = V4L2_TUNER_SUB_STEREO;
349 } else {
350 vt->rxsubchans = V4L2_TUNER_SUB_MONO;
351 }
352 if (status_mask & PVR2_SIGNAL_SAP) {
353 vt->rxsubchans |= (V4L2_TUNER_SUB_LANG1 |
354 V4L2_TUNER_SUB_LANG2);
355 }
356 vt->signal = 65535;
357 }
358
359 val = 0;
360 ret = pvr2_ctrl_get_value(
361 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_AUDIOMODE),
362 &val);
363 vt->audmode = val;
364 break; 373 break;
365 } 374 }
366 375
@@ -374,14 +383,40 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
374 ret = pvr2_ctrl_set_value( 383 ret = pvr2_ctrl_set_value(
375 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_AUDIOMODE), 384 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_AUDIOMODE),
376 vt->audmode); 385 vt->audmode);
386 break;
377 } 387 }
378 388
379 case VIDIOC_S_FREQUENCY: 389 case VIDIOC_S_FREQUENCY:
380 { 390 {
381 const struct v4l2_frequency *vf = (struct v4l2_frequency *)arg; 391 const struct v4l2_frequency *vf = (struct v4l2_frequency *)arg;
392 unsigned long fv;
393 struct v4l2_tuner vt;
394 int cur_input;
395 struct pvr2_ctrl *ctrlp;
396 ret = pvr2_hdw_get_tuner_status(hdw,&vt);
397 if (ret != 0) break;
398 ctrlp = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT);
399 ret = pvr2_ctrl_get_value(ctrlp,&cur_input);
400 if (ret != 0) break;
401 if (vf->type == V4L2_TUNER_RADIO) {
402 if (cur_input != PVR2_CVAL_INPUT_RADIO) {
403 pvr2_ctrl_set_value(ctrlp,
404 PVR2_CVAL_INPUT_RADIO);
405 }
406 } else {
407 if (cur_input == PVR2_CVAL_INPUT_RADIO) {
408 pvr2_ctrl_set_value(ctrlp,
409 PVR2_CVAL_INPUT_TV);
410 }
411 }
412 fv = vf->frequency;
413 if (vt.capability & V4L2_TUNER_CAP_LOW) {
414 fv = (fv * 125) / 2;
415 } else {
416 fv = fv * 62500;
417 }
382 ret = pvr2_ctrl_set_value( 418 ret = pvr2_ctrl_set_value(
383 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_FREQUENCY), 419 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_FREQUENCY),fv);
384 vf->frequency * 62500);
385 break; 420 break;
386 } 421 }
387 422
@@ -389,10 +424,27 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
389 { 424 {
390 struct v4l2_frequency *vf = (struct v4l2_frequency *)arg; 425 struct v4l2_frequency *vf = (struct v4l2_frequency *)arg;
391 int val = 0; 426 int val = 0;
427 int cur_input;
428 struct v4l2_tuner vt;
429 ret = pvr2_hdw_get_tuner_status(hdw,&vt);
430 if (ret != 0) break;
392 ret = pvr2_ctrl_get_value( 431 ret = pvr2_ctrl_get_value(
393 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_FREQUENCY), 432 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_FREQUENCY),
394 &val); 433 &val);
395 val /= 62500; 434 if (ret != 0) break;
435 pvr2_ctrl_get_value(
436 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT),
437 &cur_input);
438 if (cur_input == PVR2_CVAL_INPUT_RADIO) {
439 vf->type = V4L2_TUNER_RADIO;
440 } else {
441 vf->type = V4L2_TUNER_ANALOG_TV;
442 }
443 if (vt.capability & V4L2_TUNER_CAP_LOW) {
444 val = (val * 2) / 125;
445 } else {
446 val /= 62500;
447 }
396 vf->frequency = val; 448 vf->frequency = val;
397 break; 449 break;
398 } 450 }
@@ -449,7 +501,7 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
449 ret = 0; 501 ret = 0;
450 switch(vf->type) { 502 switch(vf->type) {
451 case V4L2_BUF_TYPE_VIDEO_CAPTURE: { 503 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
452 int lmin,lmax; 504 int lmin,lmax,ldef;
453 struct pvr2_ctrl *hcp,*vcp; 505 struct pvr2_ctrl *hcp,*vcp;
454 int h = vf->fmt.pix.height; 506 int h = vf->fmt.pix.height;
455 int w = vf->fmt.pix.width; 507 int w = vf->fmt.pix.width;
@@ -458,14 +510,20 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
458 510
459 lmin = pvr2_ctrl_get_min(hcp); 511 lmin = pvr2_ctrl_get_min(hcp);
460 lmax = pvr2_ctrl_get_max(hcp); 512 lmax = pvr2_ctrl_get_max(hcp);
461 if (w < lmin) { 513 ldef = pvr2_ctrl_get_def(hcp);
514 if (w == -1) {
515 w = ldef;
516 } else if (w < lmin) {
462 w = lmin; 517 w = lmin;
463 } else if (w > lmax) { 518 } else if (w > lmax) {
464 w = lmax; 519 w = lmax;
465 } 520 }
466 lmin = pvr2_ctrl_get_min(vcp); 521 lmin = pvr2_ctrl_get_min(vcp);
467 lmax = pvr2_ctrl_get_max(vcp); 522 lmax = pvr2_ctrl_get_max(vcp);
468 if (h < lmin) { 523 ldef = pvr2_ctrl_get_def(vcp);
524 if (h == -1) {
525 h = ldef;
526 } else if (h < lmin) {
469 h = lmin; 527 h = lmin;
470 } else if (h > lmax) { 528 } else if (h > lmax) {
471 h = lmax; 529 h = lmax;
@@ -494,6 +552,13 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
494 552
495 case VIDIOC_STREAMON: 553 case VIDIOC_STREAMON:
496 { 554 {
555 if (!fh->dev_info->stream) {
556 /* No stream defined for this node. This means
557 that we're not currently allowed to stream from
558 this node. */
559 ret = -EPERM;
560 break;
561 }
497 ret = pvr2_hdw_set_stream_type(hdw,dev_info->config); 562 ret = pvr2_hdw_set_stream_type(hdw,dev_info->config);
498 if (ret < 0) return ret; 563 if (ret < 0) return ret;
499 ret = pvr2_hdw_set_streaming(hdw,!0); 564 ret = pvr2_hdw_set_streaming(hdw,!0);
@@ -502,6 +567,13 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
502 567
503 case VIDIOC_STREAMOFF: 568 case VIDIOC_STREAMOFF:
504 { 569 {
570 if (!fh->dev_info->stream) {
571 /* No stream defined for this node. This means
572 that we're not currently allowed to stream from
573 this node. */
574 ret = -EPERM;
575 break;
576 }
505 ret = pvr2_hdw_set_streaming(hdw,0); 577 ret = pvr2_hdw_set_streaming(hdw,0);
506 break; 578 break;
507 } 579 }
@@ -599,6 +671,7 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
599 struct v4l2_ext_control *ctrl; 671 struct v4l2_ext_control *ctrl;
600 unsigned int idx; 672 unsigned int idx;
601 int val; 673 int val;
674 ret = 0;
602 for (idx = 0; idx < ctls->count; idx++) { 675 for (idx = 0; idx < ctls->count; idx++) {
603 ctrl = ctls->controls + idx; 676 ctrl = ctls->controls + idx;
604 ret = pvr2_ctrl_get_value( 677 ret = pvr2_ctrl_get_value(
@@ -621,6 +694,7 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
621 (struct v4l2_ext_controls *)arg; 694 (struct v4l2_ext_controls *)arg;
622 struct v4l2_ext_control *ctrl; 695 struct v4l2_ext_control *ctrl;
623 unsigned int idx; 696 unsigned int idx;
697 ret = 0;
624 for (idx = 0; idx < ctls->count; idx++) { 698 for (idx = 0; idx < ctls->count; idx++) {
625 ctrl = ctls->controls + idx; 699 ctrl = ctls->controls + idx;
626 ret = pvr2_ctrl_set_value( 700 ret = pvr2_ctrl_set_value(
@@ -643,6 +717,7 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
643 unsigned int idx; 717 unsigned int idx;
644 /* For the moment just validate that the requested control 718 /* For the moment just validate that the requested control
645 actually exists. */ 719 actually exists. */
720 ret = 0;
646 for (idx = 0; idx < ctls->count; idx++) { 721 for (idx = 0; idx < ctls->count; idx++) {
647 ctrl = ctls->controls + idx; 722 ctrl = ctls->controls + idx;
648 pctl = pvr2_hdw_get_ctrl_v4l(hdw,ctrl->id); 723 pctl = pvr2_hdw_get_ctrl_v4l(hdw,ctrl->id);
@@ -662,16 +737,16 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
662 break; 737 break;
663 } 738 }
664#ifdef CONFIG_VIDEO_ADV_DEBUG 739#ifdef CONFIG_VIDEO_ADV_DEBUG
665 case VIDIOC_INT_G_REGISTER: 740 case VIDIOC_DBG_S_REGISTER:
666 case VIDIOC_INT_S_REGISTER: 741 case VIDIOC_DBG_G_REGISTER:
667 { 742 {
668 u32 val; 743 u64 val;
669 struct v4l2_register *req = (struct v4l2_register *)arg; 744 struct v4l2_register *req = (struct v4l2_register *)arg;
670 if (cmd == VIDIOC_INT_S_REGISTER) val = req->val; 745 if (cmd == VIDIOC_DBG_S_REGISTER) val = req->val;
671 ret = pvr2_hdw_register_access( 746 ret = pvr2_hdw_register_access(
672 hdw,req->i2c_id,req->reg, 747 hdw,req->match_type,req->match_chip,req->reg,
673 cmd == VIDIOC_INT_S_REGISTER,&val); 748 cmd == VIDIOC_DBG_S_REGISTER,&val);
674 if (cmd == VIDIOC_INT_G_REGISTER) req->val = val; 749 if (cmd == VIDIOC_DBG_G_REGISTER) req->val = val;
675 break; 750 break;
676 } 751 }
677#endif 752#endif
@@ -707,8 +782,12 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
707 782
708static void pvr2_v4l2_dev_destroy(struct pvr2_v4l2_dev *dip) 783static void pvr2_v4l2_dev_destroy(struct pvr2_v4l2_dev *dip)
709{ 784{
710 printk(KERN_INFO "pvrusb2: unregistering device video%d [%s]\n", 785 int minor_id = dip->devbase.minor;
711 dip->devbase.minor,pvr2_config_get_name(dip->config)); 786 struct pvr2_hdw *hdw = dip->v4lp->channel.mc_head->hdw;
787 enum pvr2_config cfg = dip->config;
788 int v4l_type = dip->v4l_type;
789
790 pvr2_hdw_v4l_store_minor_number(hdw,dip->minor_type,-1);
712 791
713 /* Paranoia */ 792 /* Paranoia */
714 dip->v4lp = NULL; 793 dip->v4lp = NULL;
@@ -717,13 +796,24 @@ static void pvr2_v4l2_dev_destroy(struct pvr2_v4l2_dev *dip)
717 /* Actual deallocation happens later when all internal references 796 /* Actual deallocation happens later when all internal references
718 are gone. */ 797 are gone. */
719 video_unregister_device(&dip->devbase); 798 video_unregister_device(&dip->devbase);
799
800 printk(KERN_INFO "pvrusb2: unregistered device %s%u [%s]\n",
801 get_v4l_name(v4l_type),minor_id & 0x1f,
802 pvr2_config_get_name(cfg));
803
720} 804}
721 805
722 806
723static void pvr2_v4l2_destroy_no_lock(struct pvr2_v4l2 *vp) 807static void pvr2_v4l2_destroy_no_lock(struct pvr2_v4l2 *vp)
724{ 808{
725 pvr2_hdw_v4l_store_minor_number(vp->channel.mc_head->hdw,-1); 809 if (vp->dev_video) {
726 pvr2_v4l2_dev_destroy(vp->vdev); 810 pvr2_v4l2_dev_destroy(vp->dev_video);
811 vp->dev_video = 0;
812 }
813 if (vp->dev_radio) {
814 pvr2_v4l2_dev_destroy(vp->dev_radio);
815 vp->dev_radio = 0;
816 }
727 817
728 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_v4l2 id=%p",vp); 818 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_v4l2 id=%p",vp);
729 pvr2_channel_done(&vp->channel); 819 pvr2_channel_done(&vp->channel);
@@ -766,23 +856,37 @@ static int pvr2_v4l2_release(struct inode *inode, struct file *file)
766 struct pvr2_v4l2_fh *fhp = file->private_data; 856 struct pvr2_v4l2_fh *fhp = file->private_data;
767 struct pvr2_v4l2 *vp = fhp->vhead; 857 struct pvr2_v4l2 *vp = fhp->vhead;
768 struct pvr2_context *mp = fhp->vhead->channel.mc_head; 858 struct pvr2_context *mp = fhp->vhead->channel.mc_head;
859 struct pvr2_hdw *hdw = fhp->channel.mc_head->hdw;
769 860
770 pvr2_trace(PVR2_TRACE_OPEN_CLOSE,"pvr2_v4l2_release"); 861 pvr2_trace(PVR2_TRACE_OPEN_CLOSE,"pvr2_v4l2_release");
771 862
772 if (fhp->rhp) { 863 if (fhp->rhp) {
773 struct pvr2_stream *sp; 864 struct pvr2_stream *sp;
774 struct pvr2_hdw *hdw;
775 hdw = fhp->channel.mc_head->hdw;
776 pvr2_hdw_set_streaming(hdw,0); 865 pvr2_hdw_set_streaming(hdw,0);
777 sp = pvr2_ioread_get_stream(fhp->rhp); 866 sp = pvr2_ioread_get_stream(fhp->rhp);
778 if (sp) pvr2_stream_set_callback(sp,NULL,NULL); 867 if (sp) pvr2_stream_set_callback(sp,NULL,NULL);
779 pvr2_ioread_destroy(fhp->rhp); 868 pvr2_ioread_destroy(fhp->rhp);
780 fhp->rhp = NULL; 869 fhp->rhp = NULL;
781 } 870 }
871
782 v4l2_prio_close(&vp->prio, &fhp->prio); 872 v4l2_prio_close(&vp->prio, &fhp->prio);
783 file->private_data = NULL; 873 file->private_data = NULL;
784 874
785 pvr2_context_enter(mp); do { 875 pvr2_context_enter(mp); do {
876 /* Restore the previous input selection, if it makes sense
877 to do so. */
878 if (fhp->dev_info->v4l_type == VFL_TYPE_RADIO) {
879 struct pvr2_ctrl *cp;
880 int pval;
881 cp = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT);
882 pvr2_ctrl_get_value(cp,&pval);
883 /* Only restore if we're still selecting the radio */
884 if (pval == PVR2_CVAL_INPUT_RADIO) {
885 pvr2_ctrl_set_value(cp,fhp->prev_input_val);
886 pvr2_hdw_commit_ctl(hdw);
887 }
888 }
889
786 if (fhp->vnext) { 890 if (fhp->vnext) {
787 fhp->vnext->vprev = fhp->vprev; 891 fhp->vnext->vprev = fhp->vprev;
788 } else { 892 } else {
@@ -828,11 +932,10 @@ static int pvr2_v4l2_open(struct inode *inode, struct file *file)
828 return -EIO; 932 return -EIO;
829 } 933 }
830 934
831 fhp = kmalloc(sizeof(*fhp),GFP_KERNEL); 935 fhp = kzalloc(sizeof(*fhp),GFP_KERNEL);
832 if (!fhp) { 936 if (!fhp) {
833 return -ENOMEM; 937 return -ENOMEM;
834 } 938 }
835 memset(fhp,0,sizeof(*fhp));
836 939
837 init_waitqueue_head(&fhp->wait_data); 940 init_waitqueue_head(&fhp->wait_data);
838 fhp->dev_info = dip; 941 fhp->dev_info = dip;
@@ -840,6 +943,7 @@ static int pvr2_v4l2_open(struct inode *inode, struct file *file)
840 pvr2_context_enter(vp->channel.mc_head); do { 943 pvr2_context_enter(vp->channel.mc_head); do {
841 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr_v4l2_fh id=%p",fhp); 944 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr_v4l2_fh id=%p",fhp);
842 pvr2_channel_init(&fhp->channel,vp->channel.mc_head); 945 pvr2_channel_init(&fhp->channel,vp->channel.mc_head);
946
843 fhp->vnext = NULL; 947 fhp->vnext = NULL;
844 fhp->vprev = vp->vlast; 948 fhp->vprev = vp->vlast;
845 if (vp->vlast) { 949 if (vp->vlast) {
@@ -849,6 +953,18 @@ static int pvr2_v4l2_open(struct inode *inode, struct file *file)
849 } 953 }
850 vp->vlast = fhp; 954 vp->vlast = fhp;
851 fhp->vhead = vp; 955 fhp->vhead = vp;
956
957 /* Opening the /dev/radioX device implies a mode switch.
958 So execute that here. Note that you can get the
959 IDENTICAL effect merely by opening the normal video
960 device and setting the input appropriately. */
961 if (dip->v4l_type == VFL_TYPE_RADIO) {
962 struct pvr2_ctrl *cp;
963 cp = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT);
964 pvr2_ctrl_get_value(cp,&fhp->prev_input_val);
965 pvr2_ctrl_set_value(cp,PVR2_CVAL_INPUT_RADIO);
966 pvr2_hdw_commit_ctl(hdw);
967 }
852 } while (0); pvr2_context_exit(vp->channel.mc_head); 968 } while (0); pvr2_context_exit(vp->channel.mc_head);
853 969
854 fhp->file = file; 970 fhp->file = file;
@@ -873,6 +989,12 @@ static int pvr2_v4l2_iosetup(struct pvr2_v4l2_fh *fh)
873 struct pvr2_hdw *hdw; 989 struct pvr2_hdw *hdw;
874 if (fh->rhp) return 0; 990 if (fh->rhp) return 0;
875 991
992 if (!fh->dev_info->stream) {
993 /* No stream defined for this node. This means that we're
994 not currently allowed to stream from this node. */
995 return -EPERM;
996 }
997
876 /* First read() attempt. Try to claim the stream and start 998 /* First read() attempt. Try to claim the stream and start
877 it... */ 999 it... */
878 if ((ret = pvr2_channel_claim_stream(&fh->channel, 1000 if ((ret = pvr2_channel_claim_stream(&fh->channel,
@@ -1012,25 +1134,37 @@ static struct video_device vdev_template = {
1012 1134
1013static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip, 1135static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
1014 struct pvr2_v4l2 *vp, 1136 struct pvr2_v4l2 *vp,
1015 enum pvr2_config cfg) 1137 int v4l_type)
1016{ 1138{
1017 int mindevnum; 1139 int mindevnum;
1018 int unit_number; 1140 int unit_number;
1019 int v4l_type; 1141 int *nr_ptr = 0;
1020 dip->v4lp = vp; 1142 dip->v4lp = vp;
1021 dip->config = cfg;
1022 1143
1023 1144
1024 switch (cfg) { 1145 dip->v4l_type = v4l_type;
1025 case pvr2_config_mpeg: 1146 switch (v4l_type) {
1026 v4l_type = VFL_TYPE_GRABBER; 1147 case VFL_TYPE_GRABBER:
1027 dip->stream = &vp->channel.mc_head->video_stream; 1148 dip->stream = &vp->channel.mc_head->video_stream;
1149 dip->config = pvr2_config_mpeg;
1150 dip->minor_type = pvr2_v4l_type_video;
1151 nr_ptr = video_nr;
1152 if (!dip->stream) {
1153 err("Failed to set up pvrusb2 v4l video dev"
1154 " due to missing stream instance");
1155 return;
1156 }
1028 break; 1157 break;
1029 case pvr2_config_vbi: 1158 case VFL_TYPE_VBI:
1030 v4l_type = VFL_TYPE_VBI; 1159 dip->config = pvr2_config_vbi;
1160 dip->minor_type = pvr2_v4l_type_vbi;
1161 nr_ptr = vbi_nr;
1031 break; 1162 break;
1032 case pvr2_config_radio: 1163 case VFL_TYPE_RADIO:
1033 v4l_type = VFL_TYPE_RADIO; 1164 dip->stream = &vp->channel.mc_head->video_stream;
1165 dip->config = pvr2_config_mpeg;
1166 dip->minor_type = pvr2_v4l_type_radio;
1167 nr_ptr = radio_nr;
1034 break; 1168 break;
1035 default: 1169 default:
1036 /* Bail out (this should be impossible) */ 1170 /* Bail out (this should be impossible) */
@@ -1039,30 +1173,27 @@ static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
1039 return; 1173 return;
1040 } 1174 }
1041 1175
1042 if (!dip->stream) {
1043 err("Failed to set up pvrusb2 v4l dev"
1044 " due to missing stream instance");
1045 return;
1046 }
1047
1048 memcpy(&dip->devbase,&vdev_template,sizeof(vdev_template)); 1176 memcpy(&dip->devbase,&vdev_template,sizeof(vdev_template));
1049 dip->devbase.release = pvr2_video_device_release; 1177 dip->devbase.release = pvr2_video_device_release;
1050 1178
1051 mindevnum = -1; 1179 mindevnum = -1;
1052 unit_number = pvr2_hdw_get_unit_number(vp->channel.mc_head->hdw); 1180 unit_number = pvr2_hdw_get_unit_number(vp->channel.mc_head->hdw);
1053 if ((unit_number >= 0) && (unit_number < PVR_NUM)) { 1181 if (nr_ptr && (unit_number >= 0) && (unit_number < PVR_NUM)) {
1054 mindevnum = video_nr[unit_number]; 1182 mindevnum = nr_ptr[unit_number];
1055 } 1183 }
1056 if ((video_register_device(&dip->devbase, v4l_type, mindevnum) < 0) && 1184 if ((video_register_device(&dip->devbase,
1057 (video_register_device(&dip->devbase, v4l_type, -1) < 0)) { 1185 dip->v4l_type, mindevnum) < 0) &&
1058 err("Failed to register pvrusb2 v4l video device"); 1186 (video_register_device(&dip->devbase,
1059 } else { 1187 dip->v4l_type, -1) < 0)) {
1060 printk(KERN_INFO "pvrusb2: registered device video%d [%s]\n", 1188 err("Failed to register pvrusb2 v4l device");
1061 dip->devbase.minor,pvr2_config_get_name(dip->config));
1062 } 1189 }
1063 1190
1191 printk(KERN_INFO "pvrusb2: registered device %s%u [%s]\n",
1192 get_v4l_name(dip->v4l_type),dip->devbase.minor & 0x1f,
1193 pvr2_config_get_name(dip->config));
1194
1064 pvr2_hdw_v4l_store_minor_number(vp->channel.mc_head->hdw, 1195 pvr2_hdw_v4l_store_minor_number(vp->channel.mc_head->hdw,
1065 dip->devbase.minor); 1196 dip->minor_type,dip->devbase.minor);
1066} 1197}
1067 1198
1068 1199
@@ -1070,22 +1201,24 @@ struct pvr2_v4l2 *pvr2_v4l2_create(struct pvr2_context *mnp)
1070{ 1201{
1071 struct pvr2_v4l2 *vp; 1202 struct pvr2_v4l2 *vp;
1072 1203
1073 vp = kmalloc(sizeof(*vp),GFP_KERNEL); 1204 vp = kzalloc(sizeof(*vp),GFP_KERNEL);
1074 if (!vp) return vp; 1205 if (!vp) return vp;
1075 memset(vp,0,sizeof(*vp)); 1206 vp->dev_video = kzalloc(sizeof(*vp->dev_video),GFP_KERNEL);
1076 vp->vdev = kmalloc(sizeof(*vp->vdev),GFP_KERNEL); 1207 vp->dev_radio = kzalloc(sizeof(*vp->dev_radio),GFP_KERNEL);
1077 if (!vp->vdev) { 1208 if (!(vp->dev_video && vp->dev_radio)) {
1209 kfree(vp->dev_video);
1210 kfree(vp->dev_radio);
1078 kfree(vp); 1211 kfree(vp);
1079 return NULL; 1212 return NULL;
1080 } 1213 }
1081 memset(vp->vdev,0,sizeof(*vp->vdev));
1082 pvr2_channel_init(&vp->channel,mnp); 1214 pvr2_channel_init(&vp->channel,mnp);
1083 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_v4l2 id=%p",vp); 1215 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_v4l2 id=%p",vp);
1084 1216
1085 vp->channel.check_func = pvr2_v4l2_internal_check; 1217 vp->channel.check_func = pvr2_v4l2_internal_check;
1086 1218
1087 /* register streams */ 1219 /* register streams */
1088 pvr2_v4l2_dev_init(vp->vdev,vp,pvr2_config_mpeg); 1220 pvr2_v4l2_dev_init(vp->dev_video,vp,VFL_TYPE_GRABBER);
1221 pvr2_v4l2_dev_init(vp->dev_radio,vp,VFL_TYPE_RADIO);
1089 1222
1090 return vp; 1223 return vp;
1091} 1224}
diff --git a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
index 05f2cddeb4..61efa6f022 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
@@ -66,7 +66,9 @@ static void set_input(struct pvr2_v4l_decoder *ctxt)
66 route.input = SAA7115_SVIDEO2; 66 route.input = SAA7115_SVIDEO2;
67 break; 67 break;
68 case PVR2_CVAL_INPUT_RADIO: 68 case PVR2_CVAL_INPUT_RADIO:
69 // ????? No idea yet what to do here 69 // In radio mode, we mute the video, but point at one
70 // spot just to stay consistent
71 route.input = SAA7115_COMPOSITE5;
70 default: 72 default:
71 return; 73 return;
72 } 74 }
@@ -137,8 +139,7 @@ static int decoder_check(struct pvr2_v4l_decoder *ctxt)
137 unsigned long msk; 139 unsigned long msk;
138 unsigned int idx; 140 unsigned int idx;
139 141
140 for (idx = 0; idx < sizeof(decoder_ops)/sizeof(decoder_ops[0]); 142 for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
141 idx++) {
142 msk = 1 << idx; 143 msk = 1 << idx;
143 if (ctxt->stale_mask & msk) continue; 144 if (ctxt->stale_mask & msk) continue;
144 if (decoder_ops[idx].check(ctxt)) { 145 if (decoder_ops[idx].check(ctxt)) {
@@ -154,8 +155,7 @@ static void decoder_update(struct pvr2_v4l_decoder *ctxt)
154 unsigned long msk; 155 unsigned long msk;
155 unsigned int idx; 156 unsigned int idx;
156 157
157 for (idx = 0; idx < sizeof(decoder_ops)/sizeof(decoder_ops[0]); 158 for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
158 idx++) {
159 msk = 1 << idx; 159 msk = 1 << idx;
160 if (!(ctxt->stale_mask & msk)) continue; 160 if (!(ctxt->stale_mask & msk)) continue;
161 ctxt->stale_mask &= ~msk; 161 ctxt->stale_mask &= ~msk;
@@ -183,25 +183,13 @@ static void decoder_enable(struct pvr2_v4l_decoder *ctxt,int fl)
183} 183}
184 184
185 185
186static int decoder_is_tuned(struct pvr2_v4l_decoder *ctxt)
187{
188 struct v4l2_tuner vt;
189 int ret;
190
191 memset(&vt,0,sizeof(vt));
192 ret = pvr2_i2c_client_cmd(ctxt->client,VIDIOC_G_TUNER,&vt);
193 if (ret < 0) return -EINVAL;
194 return vt.signal ? 1 : 0;
195}
196
197
198static unsigned int decoder_describe(struct pvr2_v4l_decoder *ctxt,char *buf,unsigned int cnt) 186static unsigned int decoder_describe(struct pvr2_v4l_decoder *ctxt,char *buf,unsigned int cnt)
199{ 187{
200 return scnprintf(buf,cnt,"handler: pvrusb2-video-v4l"); 188 return scnprintf(buf,cnt,"handler: pvrusb2-video-v4l");
201} 189}
202 190
203 191
204const static struct pvr2_i2c_handler_functions hfuncs = { 192static const struct pvr2_i2c_handler_functions hfuncs = {
205 .detach = (void (*)(void *))decoder_detach, 193 .detach = (void (*)(void *))decoder_detach,
206 .check = (int (*)(void *))decoder_check, 194 .check = (int (*)(void *))decoder_check,
207 .update = (void (*)(void *))decoder_update, 195 .update = (void (*)(void *))decoder_update,
@@ -218,20 +206,17 @@ int pvr2_i2c_decoder_v4l_setup(struct pvr2_hdw *hdw,
218 if (cp->handler) return 0; 206 if (cp->handler) return 0;
219 if (!decoder_detect(cp)) return 0; 207 if (!decoder_detect(cp)) return 0;
220 208
221 ctxt = kmalloc(sizeof(*ctxt),GFP_KERNEL); 209 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
222 if (!ctxt) return 0; 210 if (!ctxt) return 0;
223 memset(ctxt,0,sizeof(*ctxt));
224 211
225 ctxt->handler.func_data = ctxt; 212 ctxt->handler.func_data = ctxt;
226 ctxt->handler.func_table = &hfuncs; 213 ctxt->handler.func_table = &hfuncs;
227 ctxt->ctrl.ctxt = ctxt; 214 ctxt->ctrl.ctxt = ctxt;
228 ctxt->ctrl.detach = (void (*)(void *))decoder_detach; 215 ctxt->ctrl.detach = (void (*)(void *))decoder_detach;
229 ctxt->ctrl.enable = (void (*)(void *,int))decoder_enable; 216 ctxt->ctrl.enable = (void (*)(void *,int))decoder_enable;
230 ctxt->ctrl.tuned = (int (*)(void *))decoder_is_tuned;
231 ctxt->client = cp; 217 ctxt->client = cp;
232 ctxt->hdw = hdw; 218 ctxt->hdw = hdw;
233 ctxt->stale_mask = (1 << (sizeof(decoder_ops)/ 219 ctxt->stale_mask = (1 << ARRAY_SIZE(decoder_ops)) - 1;
234 sizeof(decoder_ops[0]))) - 1;
235 hdw->decoder_ctrl = &ctxt->ctrl; 220 hdw->decoder_ctrl = &ctxt->ctrl;
236 cp->handler = &ctxt->handler; 221 cp->handler = &ctxt->handler;
237 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x saa711x V4L2 handler set up", 222 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x saa711x V4L2 handler set up",
diff --git a/drivers/media/video/pvrusb2/pvrusb2-wm8775.c b/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
index 2413e5198e..66b4d36ef7 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
@@ -50,15 +50,21 @@ static void set_input(struct pvr2_v4l_wm8775 *ctxt)
50{ 50{
51 struct v4l2_routing route; 51 struct v4l2_routing route;
52 struct pvr2_hdw *hdw = ctxt->hdw; 52 struct pvr2_hdw *hdw = ctxt->hdw;
53 int msk = 0;
54 53
55 memset(&route,0,sizeof(route)); 54 memset(&route,0,sizeof(route));
56 55
57 pvr2_trace(PVR2_TRACE_CHIPS,"i2c wm8775 set_input(val=%d msk=0x%x)", 56 switch(hdw->input_val) {
58 hdw->input_val,msk); 57 case PVR2_CVAL_INPUT_RADIO:
58 route.input = 1;
59 break;
60 default:
61 /* All other cases just use the second input */
62 route.input = 2;
63 break;
64 }
65 pvr2_trace(PVR2_TRACE_CHIPS,"i2c wm8775 set_input(val=%d route=0x%x)",
66 hdw->input_val,route.input);
59 67
60 // Always point to input #1 no matter what
61 route.input = 2;
62 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route); 68 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route);
63} 69}
64 70
@@ -99,8 +105,7 @@ static int wm8775_check(struct pvr2_v4l_wm8775 *ctxt)
99 unsigned long msk; 105 unsigned long msk;
100 unsigned int idx; 106 unsigned int idx;
101 107
102 for (idx = 0; idx < sizeof(wm8775_ops)/sizeof(wm8775_ops[0]); 108 for (idx = 0; idx < ARRAY_SIZE(wm8775_ops); idx++) {
103 idx++) {
104 msk = 1 << idx; 109 msk = 1 << idx;
105 if (ctxt->stale_mask & msk) continue; 110 if (ctxt->stale_mask & msk) continue;
106 if (wm8775_ops[idx].check(ctxt)) { 111 if (wm8775_ops[idx].check(ctxt)) {
@@ -116,8 +121,7 @@ static void wm8775_update(struct pvr2_v4l_wm8775 *ctxt)
116 unsigned long msk; 121 unsigned long msk;
117 unsigned int idx; 122 unsigned int idx;
118 123
119 for (idx = 0; idx < sizeof(wm8775_ops)/sizeof(wm8775_ops[0]); 124 for (idx = 0; idx < ARRAY_SIZE(wm8775_ops); idx++) {
120 idx++) {
121 msk = 1 << idx; 125 msk = 1 << idx;
122 if (!(ctxt->stale_mask & msk)) continue; 126 if (!(ctxt->stale_mask & msk)) continue;
123 ctxt->stale_mask &= ~msk; 127 ctxt->stale_mask &= ~msk;
@@ -126,7 +130,7 @@ static void wm8775_update(struct pvr2_v4l_wm8775 *ctxt)
126} 130}
127 131
128 132
129const static struct pvr2_i2c_handler_functions hfuncs = { 133static const struct pvr2_i2c_handler_functions hfuncs = {
130 .detach = (void (*)(void *))wm8775_detach, 134 .detach = (void (*)(void *))wm8775_detach,
131 .check = (int (*)(void *))wm8775_check, 135 .check = (int (*)(void *))wm8775_check,
132 .update = (void (*)(void *))wm8775_update, 136 .update = (void (*)(void *))wm8775_update,
@@ -140,16 +144,14 @@ int pvr2_i2c_wm8775_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
140 144
141 if (cp->handler) return 0; 145 if (cp->handler) return 0;
142 146
143 ctxt = kmalloc(sizeof(*ctxt),GFP_KERNEL); 147 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
144 if (!ctxt) return 0; 148 if (!ctxt) return 0;
145 memset(ctxt,0,sizeof(*ctxt));
146 149
147 ctxt->handler.func_data = ctxt; 150 ctxt->handler.func_data = ctxt;
148 ctxt->handler.func_table = &hfuncs; 151 ctxt->handler.func_table = &hfuncs;
149 ctxt->client = cp; 152 ctxt->client = cp;
150 ctxt->hdw = hdw; 153 ctxt->hdw = hdw;
151 ctxt->stale_mask = (1 << (sizeof(wm8775_ops)/ 154 ctxt->stale_mask = (1 << ARRAY_SIZE(wm8775_ops)) - 1;
152 sizeof(wm8775_ops[0]))) - 1;
153 cp->handler = &ctxt->handler; 155 cp->handler = &ctxt->handler;
154 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x wm8775 V4L2 handler set up", 156 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x wm8775 V4L2 handler set up",
155 cp->client->addr); 157 cp->client->addr);
diff --git a/drivers/media/video/pwc/Makefile b/drivers/media/video/pwc/Makefile
index 9db2260d10..f5c8ec261e 100644
--- a/drivers/media/video/pwc/Makefile
+++ b/drivers/media/video/pwc/Makefile
@@ -2,11 +2,3 @@ pwc-objs := pwc-if.o pwc-misc.o pwc-ctrl.o pwc-v4l.o pwc-uncompress.o
2pwc-objs += pwc-dec1.o pwc-dec23.o pwc-kiara.o pwc-timon.o 2pwc-objs += pwc-dec1.o pwc-dec23.o pwc-kiara.o pwc-timon.o
3 3
4obj-$(CONFIG_USB_PWC) += pwc.o 4obj-$(CONFIG_USB_PWC) += pwc.o
5
6ifeq ($(CONFIG_USB_PWC_DEBUG),y)
7EXTRA_CFLAGS += -DCONFIG_PWC_DEBUG=1
8else
9EXTRA_CFLAGS += -DCONFIG_PWC_DEBUG=0
10endif
11
12
diff --git a/drivers/media/video/pwc/pwc-if.c b/drivers/media/video/pwc/pwc-if.c
index 9825fd3481..27ed76986c 100644
--- a/drivers/media/video/pwc/pwc-if.c
+++ b/drivers/media/video/pwc/pwc-if.c
@@ -128,7 +128,7 @@ static int default_size = PSZ_QCIF;
128static int default_fps = 10; 128static int default_fps = 10;
129static int default_fbufs = 3; /* Default number of frame buffers */ 129static int default_fbufs = 3; /* Default number of frame buffers */
130 int pwc_mbufs = 2; /* Default number of mmap() buffers */ 130 int pwc_mbufs = 2; /* Default number of mmap() buffers */
131#if CONFIG_PWC_DEBUG 131#ifdef CONFIG_USB_PWC_DEBUG
132 int pwc_trace = PWC_DEBUG_LEVEL; 132 int pwc_trace = PWC_DEBUG_LEVEL;
133#endif 133#endif
134static int power_save = 0; 134static int power_save = 0;
@@ -1051,7 +1051,7 @@ static void pwc_remove_sysfs_files(struct video_device *vdev)
1051 video_device_remove_file(vdev, &class_device_attr_button); 1051 video_device_remove_file(vdev, &class_device_attr_button);
1052} 1052}
1053 1053
1054#if CONFIG_PWC_DEBUG 1054#ifdef CONFIG_USB_PWC_DEBUG
1055static const char *pwc_sensor_type_to_string(unsigned int sensor_type) 1055static const char *pwc_sensor_type_to_string(unsigned int sensor_type)
1056{ 1056{
1057 switch(sensor_type) { 1057 switch(sensor_type) {
@@ -1835,7 +1835,7 @@ module_param(size, charp, 0444);
1835module_param(fps, int, 0444); 1835module_param(fps, int, 0444);
1836module_param(fbufs, int, 0444); 1836module_param(fbufs, int, 0444);
1837module_param(mbufs, int, 0444); 1837module_param(mbufs, int, 0444);
1838#if CONFIG_PWC_DEBUG 1838#ifdef CONFIG_USB_PWC_DEBUG
1839module_param_named(trace, pwc_trace, int, 0644); 1839module_param_named(trace, pwc_trace, int, 0644);
1840#endif 1840#endif
1841module_param(power_save, int, 0444); 1841module_param(power_save, int, 0444);
@@ -1908,7 +1908,7 @@ static int __init usb_pwc_init(void)
1908 default_fbufs = fbufs; 1908 default_fbufs = fbufs;
1909 PWC_DEBUG_MODULE("Number of frame buffers set to %d.\n", default_fbufs); 1909 PWC_DEBUG_MODULE("Number of frame buffers set to %d.\n", default_fbufs);
1910 } 1910 }
1911#if CONFIG_PWC_DEBUG 1911#ifdef CONFIG_USB_PWC_DEBUG
1912 if (pwc_trace >= 0) { 1912 if (pwc_trace >= 0) {
1913 PWC_DEBUG_MODULE("Trace options: 0x%04x\n", pwc_trace); 1913 PWC_DEBUG_MODULE("Trace options: 0x%04x\n", pwc_trace);
1914 } 1914 }
diff --git a/drivers/media/video/pwc/pwc-v4l.c b/drivers/media/video/pwc/pwc-v4l.c
index b7eb3ce3b9..d5e6bc8506 100644
--- a/drivers/media/video/pwc/pwc-v4l.c
+++ b/drivers/media/video/pwc/pwc-v4l.c
@@ -350,7 +350,7 @@ int pwc_video_do_ioctl(struct inode *inode, struct file *file,
350 if (pdev == NULL) 350 if (pdev == NULL)
351 return -EFAULT; 351 return -EFAULT;
352 352
353#if CONFIG_PWC_DEBUG 353#ifdef CONFIG_USB_PWC_DEBUG
354 if (PWC_DEBUG_LEVEL_IOCTL & pwc_trace) 354 if (PWC_DEBUG_LEVEL_IOCTL & pwc_trace)
355 v4l_printk_ioctl(cmd); 355 v4l_printk_ioctl(cmd);
356#endif 356#endif
diff --git a/drivers/media/video/pwc/pwc.h b/drivers/media/video/pwc/pwc.h
index 7e9c4237d1..e778a2b8c2 100644
--- a/drivers/media/video/pwc/pwc.h
+++ b/drivers/media/video/pwc/pwc.h
@@ -39,11 +39,6 @@
39#include "pwc-uncompress.h" 39#include "pwc-uncompress.h"
40#include <media/pwc-ioctl.h> 40#include <media/pwc-ioctl.h>
41 41
42/* Turn some debugging options on/off */
43#ifndef CONFIG_PWC_DEBUG
44#define CONFIG_PWC_DEBUG 1
45#endif
46
47/* Version block */ 42/* Version block */
48#define PWC_MAJOR 10 43#define PWC_MAJOR 10
49#define PWC_MINOR 0 44#define PWC_MINOR 0
@@ -76,7 +71,7 @@
76#define PWC_DEBUG_TRACE(fmt, args...) PWC_DEBUG(TRACE, fmt, ##args) 71#define PWC_DEBUG_TRACE(fmt, args...) PWC_DEBUG(TRACE, fmt, ##args)
77 72
78 73
79#if CONFIG_PWC_DEBUG 74#ifdef CONFIG_USB_PWC_DEBUG
80 75
81#define PWC_DEBUG_LEVEL (PWC_DEBUG_LEVEL_MODULE) 76#define PWC_DEBUG_LEVEL (PWC_DEBUG_LEVEL_MODULE)
82 77
@@ -270,7 +265,7 @@ extern "C" {
270#endif 265#endif
271 266
272/* Global variables */ 267/* Global variables */
273#if CONFIG_PWC_DEBUG 268#ifdef CONFIG_USB_PWC_DEBUG
274extern int pwc_trace; 269extern int pwc_trace;
275#endif 270#endif
276extern int pwc_mbufs; 271extern int pwc_mbufs;
diff --git a/drivers/media/video/saa5246a.c b/drivers/media/video/saa5246a.c
index 76f5f5d49d..e20aa3612a 100644
--- a/drivers/media/video/saa5246a.c
+++ b/drivers/media/video/saa5246a.c
@@ -111,7 +111,7 @@ static int saa5246a_attach(struct i2c_adapter *adap, int addr, int kind)
111 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) 111 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++)
112 { 112 {
113 memset(t->pgbuf[pgbuf], ' ', sizeof(t->pgbuf[0])); 113 memset(t->pgbuf[pgbuf], ' ', sizeof(t->pgbuf[0]));
114 t->is_searching[pgbuf] = FALSE; 114 t->is_searching[pgbuf] = false;
115 } 115 }
116 vd->priv=t; 116 vd->priv=t;
117 117
@@ -198,7 +198,7 @@ static int i2c_senddata(struct saa5246a_device *t, ...)
198 198
199/* Get count number of bytes from I²C-device at address adr, store them in buf. 199/* Get count number of bytes from I²C-device at address adr, store them in buf.
200 * Start & stop handshaking is done by this routine, ack will be sent after the 200 * Start & stop handshaking is done by this routine, ack will be sent after the
201 * last byte to inhibit further sending of data. If uaccess is TRUE, data is 201 * last byte to inhibit further sending of data. If uaccess is 'true', data is
202 * written to user-space with put_user. Returns -1 if I²C-device didn't send 202 * written to user-space with put_user. Returns -1 if I²C-device didn't send
203 * acknowledge, 0 otherwise 203 * acknowledge, 0 otherwise
204 */ 204 */
@@ -338,7 +338,7 @@ static int saa5246a_request_page(struct saa5246a_device *t,
338 return -EIO; 338 return -EIO;
339 } 339 }
340 340
341 t->is_searching[req->pgbuf] = TRUE; 341 t->is_searching[req->pgbuf] = true;
342 return 0; 342 return 0;
343} 343}
344 344
@@ -452,7 +452,7 @@ static inline int saa5246a_get_status(struct saa5246a_device *t,
452 } 452 }
453 } 453 }
454 if (!info->hamming && !info->notfound) 454 if (!info->hamming && !info->notfound)
455 t->is_searching[dau_no] = FALSE; 455 t->is_searching[dau_no] = false;
456 return 0; 456 return 0;
457} 457}
458 458
@@ -564,7 +564,7 @@ static inline int saa5246a_stop_dau(struct saa5246a_device *t,
564 { 564 {
565 return -EIO; 565 return -EIO;
566 } 566 }
567 t->is_searching[dau_no] = FALSE; 567 t->is_searching[dau_no] = false;
568 return 0; 568 return 0;
569} 569}
570 570
diff --git a/drivers/media/video/saa5246a.h b/drivers/media/video/saa5246a.h
index 7b91112304..64394c036c 100644
--- a/drivers/media/video/saa5246a.h
+++ b/drivers/media/video/saa5246a.h
@@ -41,23 +41,18 @@
41#define POS_HEADER_START 7 41#define POS_HEADER_START 7
42#define POS_HEADER_END 31 42#define POS_HEADER_END 31
43 43
44/* Returns TRUE if the part of the videotext page described with req contains 44/* Returns 'true' if the part of the videotext page described with req contains
45 (at least parts of) the time field */ 45 (at least parts of) the time field */
46#define REQ_CONTAINS_TIME(p_req) \ 46#define REQ_CONTAINS_TIME(p_req) \
47 ((p_req)->start <= POS_TIME_END && \ 47 ((p_req)->start <= POS_TIME_END && \
48 (p_req)->end >= POS_TIME_START) 48 (p_req)->end >= POS_TIME_START)
49 49
50/* Returns TRUE if the part of the videotext page described with req contains 50/* Returns 'true' if the part of the videotext page described with req contains
51 (at least parts of) the page header */ 51 (at least parts of) the page header */
52#define REQ_CONTAINS_HEADER(p_req) \ 52#define REQ_CONTAINS_HEADER(p_req) \
53 ((p_req)->start <= POS_HEADER_END && \ 53 ((p_req)->start <= POS_HEADER_END && \
54 (p_req)->end >= POS_HEADER_START) 54 (p_req)->end >= POS_HEADER_START)
55 55
56#ifndef FALSE
57#define FALSE 0
58#define TRUE 1
59#endif
60
61/*****************************************************************************/ 56/*****************************************************************************/
62/* Mode register numbers of the SAA5246A */ 57/* Mode register numbers of the SAA5246A */
63/*****************************************************************************/ 58/*****************************************************************************/
diff --git a/drivers/media/video/saa5249.c b/drivers/media/video/saa5249.c
index 3e84737878..f2a2f34cd6 100644
--- a/drivers/media/video/saa5249.c
+++ b/drivers/media/video/saa5249.c
@@ -124,11 +124,6 @@ struct saa5249_device
124 124
125/* General defines and debugging support */ 125/* General defines and debugging support */
126 126
127#ifndef FALSE
128#define FALSE 0
129#define TRUE 1
130#endif
131
132#define RESCHED do { cond_resched(); } while(0) 127#define RESCHED do { cond_resched(); } while(0)
133 128
134static struct video_device saa_template; /* Declared near bottom */ 129static struct video_device saa_template; /* Declared near bottom */
@@ -183,9 +178,9 @@ static int saa5249_attach(struct i2c_adapter *adap, int addr, int kind)
183 memset(t->vdau[pgbuf].sregs, 0, sizeof(t->vdau[0].sregs)); 178 memset(t->vdau[pgbuf].sregs, 0, sizeof(t->vdau[0].sregs));
184 memset(t->vdau[pgbuf].laststat, 0, sizeof(t->vdau[0].laststat)); 179 memset(t->vdau[pgbuf].laststat, 0, sizeof(t->vdau[0].laststat));
185 t->vdau[pgbuf].expire = 0; 180 t->vdau[pgbuf].expire = 0;
186 t->vdau[pgbuf].clrfound = TRUE; 181 t->vdau[pgbuf].clrfound = true;
187 t->vdau[pgbuf].stopped = TRUE; 182 t->vdau[pgbuf].stopped = true;
188 t->is_searching[pgbuf] = FALSE; 183 t->is_searching[pgbuf] = false;
189 } 184 }
190 vd->priv=t; 185 vd->priv=t;
191 186
@@ -298,7 +293,7 @@ static int i2c_senddata(struct saa5249_device *t, ...)
298 293
299/* Get count number of bytes from I²C-device at address adr, store them in buf. Start & stop 294/* Get count number of bytes from I²C-device at address adr, store them in buf. Start & stop
300 * handshaking is done by this routine, ack will be sent after the last byte to inhibit further 295 * handshaking is done by this routine, ack will be sent after the last byte to inhibit further
301 * sending of data. If uaccess is TRUE, data is written to user-space with put_user. 296 * sending of data. If uaccess is 'true', data is written to user-space with put_user.
302 * Returns -1 if I²C-device didn't send acknowledge, 0 otherwise 297 * Returns -1 if I²C-device didn't send acknowledge, 0 otherwise
303 */ 298 */
304 299
@@ -317,7 +312,7 @@ static int i2c_getdata(struct saa5249_device *t, int count, u8 *buf)
317static int do_saa5249_ioctl(struct inode *inode, struct file *file, 312static int do_saa5249_ioctl(struct inode *inode, struct file *file,
318 unsigned int cmd, void *arg) 313 unsigned int cmd, void *arg)
319{ 314{
320 static int virtual_mode = FALSE; 315 static int virtual_mode = false;
321 struct video_device *vd = video_devdata(file); 316 struct video_device *vd = video_devdata(file);
322 struct saa5249_device *t=vd->priv; 317 struct saa5249_device *t=vd->priv;
323 318
@@ -340,7 +335,7 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
340 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS) 335 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
341 return -EINVAL; 336 return -EINVAL;
342 memset(t->vdau[req->pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf)); 337 memset(t->vdau[req->pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
343 t->vdau[req->pgbuf].clrfound = TRUE; 338 t->vdau[req->pgbuf].clrfound = true;
344 return 0; 339 return 0;
345 } 340 }
346 341
@@ -350,7 +345,7 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
350 345
351 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS) 346 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
352 return -EINVAL; 347 return -EINVAL;
353 t->vdau[req->pgbuf].clrfound = TRUE; 348 t->vdau[req->pgbuf].clrfound = true;
354 return 0; 349 return 0;
355 } 350 }
356 351
@@ -376,9 +371,9 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
376 t->vdau[req->pgbuf].sregs[4] = (req->pagemask & HR_UNIT ? 0x10 : 0) | (req->hour & 0xf); 371 t->vdau[req->pgbuf].sregs[4] = (req->pagemask & HR_UNIT ? 0x10 : 0) | (req->hour & 0xf);
377 t->vdau[req->pgbuf].sregs[5] = (req->pagemask & MIN_TEN ? 0x10 : 0) | (req->minute / 0x10); 372 t->vdau[req->pgbuf].sregs[5] = (req->pagemask & MIN_TEN ? 0x10 : 0) | (req->minute / 0x10);
378 t->vdau[req->pgbuf].sregs[6] = (req->pagemask & MIN_UNIT ? 0x10 : 0) | (req->minute & 0xf); 373 t->vdau[req->pgbuf].sregs[6] = (req->pagemask & MIN_UNIT ? 0x10 : 0) | (req->minute & 0xf);
379 t->vdau[req->pgbuf].stopped = FALSE; 374 t->vdau[req->pgbuf].stopped = false;
380 t->vdau[req->pgbuf].clrfound = TRUE; 375 t->vdau[req->pgbuf].clrfound = true;
381 t->is_searching[req->pgbuf] = TRUE; 376 t->is_searching[req->pgbuf] = true;
382 return 0; 377 return 0;
383 } 378 }
384 379
@@ -430,7 +425,7 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
430 i2c_getdata(t, 40, t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE + 23 * 40)) 425 i2c_getdata(t, 40, t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE + 23 * 40))
431 return -EIO; 426 return -EIO;
432 } 427 }
433 t->vdau[req->pgbuf].clrfound = FALSE; 428 t->vdau[req->pgbuf].clrfound = false;
434 memcpy(t->vdau[req->pgbuf].laststat, infobits, sizeof(infobits)); 429 memcpy(t->vdau[req->pgbuf].laststat, infobits, sizeof(infobits));
435 } 430 }
436 else 431 else
@@ -474,7 +469,7 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
474 return -EFAULT; 469 return -EFAULT;
475 if (!info.hamming && !info.notfound) 470 if (!info.hamming && !info.notfound)
476 { 471 {
477 t->is_searching[req->pgbuf] = FALSE; 472 t->is_searching[req->pgbuf] = false;
478 } 473 }
479 return 0; 474 return 0;
480 } 475 }
@@ -530,8 +525,8 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
530 525
531 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS) 526 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
532 return -EINVAL; 527 return -EINVAL;
533 t->vdau[req->pgbuf].stopped = TRUE; 528 t->vdau[req->pgbuf].stopped = true;
534 t->is_searching[req->pgbuf] = FALSE; 529 t->is_searching[req->pgbuf] = false;
535 return 0; 530 return 0;
536 } 531 }
537 532
@@ -660,11 +655,11 @@ static int saa5249_open(struct inode *inode, struct file *file)
660 memset(t->vdau[pgbuf].sregs, 0, sizeof(t->vdau[0].sregs)); 655 memset(t->vdau[pgbuf].sregs, 0, sizeof(t->vdau[0].sregs));
661 memset(t->vdau[pgbuf].laststat, 0, sizeof(t->vdau[0].laststat)); 656 memset(t->vdau[pgbuf].laststat, 0, sizeof(t->vdau[0].laststat));
662 t->vdau[pgbuf].expire = 0; 657 t->vdau[pgbuf].expire = 0;
663 t->vdau[pgbuf].clrfound = TRUE; 658 t->vdau[pgbuf].clrfound = true;
664 t->vdau[pgbuf].stopped = TRUE; 659 t->vdau[pgbuf].stopped = true;
665 t->is_searching[pgbuf] = FALSE; 660 t->is_searching[pgbuf] = false;
666 } 661 }
667 t->virtual_mode=FALSE; 662 t->virtual_mode = false;
668 return 0; 663 return 0;
669 664
670 fail: 665 fail:
diff --git a/drivers/media/video/saa7115.c b/drivers/media/video/saa7115.c
index c2374ed7ba..7735b67589 100644
--- a/drivers/media/video/saa7115.c
+++ b/drivers/media/video/saa7115.c
@@ -71,6 +71,7 @@ I2C_CLIENT_INSMOD;
71struct saa711x_state { 71struct saa711x_state {
72 v4l2_std_id std; 72 v4l2_std_id std;
73 int input; 73 int input;
74 int output;
74 int enable; 75 int enable;
75 int radio; 76 int radio;
76 int bright; 77 int bright;
@@ -1301,7 +1302,7 @@ static int saa711x_command(struct i2c_client *client, unsigned int cmd, void *ar
1301 struct v4l2_routing *route = arg; 1302 struct v4l2_routing *route = arg;
1302 1303
1303 route->input = state->input; 1304 route->input = state->input;
1304 route->output = 0; 1305 route->output = state->output;
1305 break; 1306 break;
1306 } 1307 }
1307 1308
@@ -1309,7 +1310,7 @@ static int saa711x_command(struct i2c_client *client, unsigned int cmd, void *ar
1309 { 1310 {
1310 struct v4l2_routing *route = arg; 1311 struct v4l2_routing *route = arg;
1311 1312
1312 v4l_dbg(1, debug, client, "decoder set input %d\n", route->input); 1313 v4l_dbg(1, debug, client, "decoder set input %d output %d\n", route->input, route->output);
1313 /* saa7113 does not have these inputs */ 1314 /* saa7113 does not have these inputs */
1314 if (state->ident == V4L2_IDENT_SAA7113 && 1315 if (state->ident == V4L2_IDENT_SAA7113 &&
1315 (route->input == SAA7115_COMPOSITE4 || 1316 (route->input == SAA7115_COMPOSITE4 ||
@@ -1318,10 +1319,12 @@ static int saa711x_command(struct i2c_client *client, unsigned int cmd, void *ar
1318 } 1319 }
1319 if (route->input > SAA7115_SVIDEO3) 1320 if (route->input > SAA7115_SVIDEO3)
1320 return -EINVAL; 1321 return -EINVAL;
1321 if (state->input == route->input) 1322 if (route->output > SAA7115_IPORT_ON)
1323 return -EINVAL;
1324 if (state->input == route->input && state->output == route->output)
1322 break; 1325 break;
1323 v4l_dbg(1, debug, client, "now setting %s input\n", 1326 v4l_dbg(1, debug, client, "now setting %s input %s output\n",
1324 (route->input >= SAA7115_SVIDEO0) ? "S-Video" : "Composite"); 1327 (route->input >= SAA7115_SVIDEO0) ? "S-Video" : "Composite", (route->output == SAA7115_IPORT_ON) ? "iport on" : "iport off");
1325 state->input = route->input; 1328 state->input = route->input;
1326 1329
1327 /* select mode */ 1330 /* select mode */
@@ -1333,6 +1336,14 @@ static int saa711x_command(struct i2c_client *client, unsigned int cmd, void *ar
1333 saa711x_write(client, R_09_LUMA_CNTL, 1336 saa711x_write(client, R_09_LUMA_CNTL,
1334 (saa711x_read(client, R_09_LUMA_CNTL) & 0x7f) | 1337 (saa711x_read(client, R_09_LUMA_CNTL) & 0x7f) |
1335 (state->input >= SAA7115_SVIDEO0 ? 0x80 : 0x0)); 1338 (state->input >= SAA7115_SVIDEO0 ? 0x80 : 0x0));
1339
1340 state->output = route->output;
1341 if (state->ident == V4L2_IDENT_SAA7114 ||
1342 state->ident == V4L2_IDENT_SAA7115) {
1343 saa711x_write(client, R_83_X_PORT_I_O_ENA_AND_OUT_CLK,
1344 (saa711x_read(client, R_83_X_PORT_I_O_ENA_AND_OUT_CLK) & 0xfe) |
1345 (state->output & 0x01));
1346 }
1336 break; 1347 break;
1337 } 1348 }
1338 1349
@@ -1377,6 +1388,9 @@ static int saa711x_command(struct i2c_client *client, unsigned int cmd, void *ar
1377 { 1388 {
1378 struct v4l2_sliced_vbi_data *data = arg; 1389 struct v4l2_sliced_vbi_data *data = arg;
1379 1390
1391 /* Note: the internal field ID is inverted for NTSC,
1392 so data->field 0 maps to the saa7115 even field,
1393 whereas for PAL it maps to the saa7115 odd field. */
1380 switch (data->id) { 1394 switch (data->id) {
1381 case V4L2_SLICED_WSS_625: 1395 case V4L2_SLICED_WSS_625:
1382 if (saa711x_read(client, 0x6b) & 0xc0) 1396 if (saa711x_read(client, 0x6b) & 0xc0)
@@ -1387,17 +1401,17 @@ static int saa711x_command(struct i2c_client *client, unsigned int cmd, void *ar
1387 case V4L2_SLICED_CAPTION_525: 1401 case V4L2_SLICED_CAPTION_525:
1388 if (data->field == 0) { 1402 if (data->field == 0) {
1389 /* CC */ 1403 /* CC */
1390 if (saa711x_read(client, 0x66) & 0xc0) 1404 if (saa711x_read(client, 0x66) & 0x30)
1391 return -EIO; 1405 return -EIO;
1392 data->data[0] = saa711x_read(client, 0x67); 1406 data->data[0] = saa711x_read(client, 0x69);
1393 data->data[1] = saa711x_read(client, 0x68); 1407 data->data[1] = saa711x_read(client, 0x6a);
1394 return 0; 1408 return 0;
1395 } 1409 }
1396 /* XDS */ 1410 /* XDS */
1397 if (saa711x_read(client, 0x66) & 0x30) 1411 if (saa711x_read(client, 0x66) & 0xc0)
1398 return -EIO; 1412 return -EIO;
1399 data->data[0] = saa711x_read(client, 0x69); 1413 data->data[0] = saa711x_read(client, 0x67);
1400 data->data[1] = saa711x_read(client, 0x6a); 1414 data->data[1] = saa711x_read(client, 0x68);
1401 return 0; 1415 return 0;
1402 default: 1416 default:
1403 return -EINVAL; 1417 return -EINVAL;
@@ -1406,25 +1420,19 @@ static int saa711x_command(struct i2c_client *client, unsigned int cmd, void *ar
1406 } 1420 }
1407 1421
1408#ifdef CONFIG_VIDEO_ADV_DEBUG 1422#ifdef CONFIG_VIDEO_ADV_DEBUG
1409 case VIDIOC_INT_G_REGISTER: 1423 case VIDIOC_DBG_G_REGISTER:
1424 case VIDIOC_DBG_S_REGISTER:
1410 { 1425 {
1411 struct v4l2_register *reg = arg; 1426 struct v4l2_register *reg = arg;
1412 1427
1413 if (reg->i2c_id != I2C_DRIVERID_SAA711X) 1428 if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip))
1414 return -EINVAL;
1415 reg->val = saa711x_read(client, reg->reg & 0xff);
1416 break;
1417 }
1418
1419 case VIDIOC_INT_S_REGISTER:
1420 {
1421 struct v4l2_register *reg = arg;
1422
1423 if (reg->i2c_id != I2C_DRIVERID_SAA711X)
1424 return -EINVAL; 1429 return -EINVAL;
1425 if (!capable(CAP_SYS_ADMIN)) 1430 if (!capable(CAP_SYS_ADMIN))
1426 return -EPERM; 1431 return -EPERM;
1427 saa711x_write(client, reg->reg & 0xff, reg->val & 0xff); 1432 if (cmd == VIDIOC_DBG_G_REGISTER)
1433 reg->val = saa711x_read(client, reg->reg & 0xff);
1434 else
1435 saa711x_write(client, reg->reg & 0xff, reg->val & 0xff);
1428 break; 1436 break;
1429 } 1437 }
1430#endif 1438#endif
@@ -1492,6 +1500,7 @@ static int saa711x_attach(struct i2c_adapter *adapter, int address, int kind)
1492 return -ENOMEM; 1500 return -ENOMEM;
1493 } 1501 }
1494 state->input = -1; 1502 state->input = -1;
1503 state->output = SAA7115_IPORT_ON;
1495 state->enable = 1; 1504 state->enable = 1;
1496 state->radio = 0; 1505 state->radio = 0;
1497 state->bright = 128; 1506 state->bright = 128;
@@ -1550,7 +1559,7 @@ static int saa711x_attach(struct i2c_adapter *adapter, int address, int kind)
1550 1559
1551static int saa711x_probe(struct i2c_adapter *adapter) 1560static int saa711x_probe(struct i2c_adapter *adapter)
1552{ 1561{
1553 if (adapter->class & I2C_CLASS_TV_ANALOG) 1562 if (adapter->class & I2C_CLASS_TV_ANALOG || adapter->class & I2C_CLASS_TV_DIGITAL)
1554 return i2c_probe(adapter, &addr_data, &saa711x_attach); 1563 return i2c_probe(adapter, &addr_data, &saa711x_attach);
1555 return 0; 1564 return 0;
1556} 1565}
diff --git a/drivers/media/video/saa7127.c b/drivers/media/video/saa7127.c
index ad401bdefe..654863db15 100644
--- a/drivers/media/video/saa7127.c
+++ b/drivers/media/video/saa7127.c
@@ -614,25 +614,19 @@ static int saa7127_command(struct i2c_client *client,
614 break; 614 break;
615 615
616#ifdef CONFIG_VIDEO_ADV_DEBUG 616#ifdef CONFIG_VIDEO_ADV_DEBUG
617 case VIDIOC_INT_G_REGISTER: 617 case VIDIOC_DBG_G_REGISTER:
618 case VIDIOC_DBG_S_REGISTER:
618 { 619 {
619 struct v4l2_register *reg = arg; 620 struct v4l2_register *reg = arg;
620 621
621 if (reg->i2c_id != I2C_DRIVERID_SAA7127) 622 if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip))
622 return -EINVAL;
623 reg->val = saa7127_read(client, reg->reg & 0xff);
624 break;
625 }
626
627 case VIDIOC_INT_S_REGISTER:
628 {
629 struct v4l2_register *reg = arg;
630
631 if (reg->i2c_id != I2C_DRIVERID_SAA7127)
632 return -EINVAL; 623 return -EINVAL;
633 if (!capable(CAP_SYS_ADMIN)) 624 if (!capable(CAP_SYS_ADMIN))
634 return -EPERM; 625 return -EPERM;
635 saa7127_write(client, reg->reg & 0xff, reg->val & 0xff); 626 if (cmd == VIDIOC_DBG_G_REGISTER)
627 reg->val = saa7127_read(client, reg->reg & 0xff);
628 else
629 saa7127_write(client, reg->reg & 0xff, reg->val & 0xff);
636 break; 630 break;
637 } 631 }
638#endif 632#endif
diff --git a/drivers/media/video/saa7134/Makefile b/drivers/media/video/saa7134/Makefile
index 89a1565b42..c85c8a8ec3 100644
--- a/drivers/media/video/saa7134/Makefile
+++ b/drivers/media/video/saa7134/Makefile
@@ -14,7 +14,3 @@ obj-$(CONFIG_VIDEO_SAA7134_DVB) += saa7134-dvb.o
14EXTRA_CFLAGS += -Idrivers/media/video 14EXTRA_CFLAGS += -Idrivers/media/video
15EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core 15EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
16EXTRA_CFLAGS += -Idrivers/media/dvb/frontends 16EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
17
18extra-cflags-$(CONFIG_VIDEO_BUF_DVB) += -DHAVE_VIDEO_BUF_DVB=1
19
20EXTRA_CFLAGS += $(extra-cflags-y) $(extra-cflags-m)
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index ae984bbe36..89f32107f4 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -2469,6 +2469,11 @@ struct saa7134_board saa7134_boards[] = {
2469 .amux = LINE2, 2469 .amux = LINE2,
2470 .gpio = 0x0200000, 2470 .gpio = 0x0200000,
2471 },{ 2471 },{
2472 .name = name_comp2,
2473 .vmux = 0,
2474 .amux = LINE2,
2475 .gpio = 0x0200000,
2476 },{
2472 .name = name_svideo, 2477 .name = name_svideo,
2473 .vmux = 8, 2478 .vmux = 8,
2474 .amux = LINE2, 2479 .amux = LINE2,
@@ -3183,6 +3188,107 @@ struct saa7134_board saa7134_boards[] = {
3183 .amux = LINE1, 3188 .amux = LINE1,
3184 }}, 3189 }},
3185 }, 3190 },
3191 [SAA7134_BOARD_ENCORE_ENLTV] = {
3192 /* Steven Walter <stevenrwalter@gmail.com>
3193 Juan Pablo Sormani <sorman@gmail.com> */
3194 .name = "Encore ENLTV",
3195 .audio_clock = 0x00200000,
3196 .tuner_type = TUNER_TNF_5335MF,
3197 .radio_type = UNSET,
3198 .tuner_addr = ADDR_UNSET,
3199 .radio_addr = ADDR_UNSET,
3200 .inputs = {{
3201 .name = name_tv,
3202 .vmux = 1,
3203 .amux = 3,
3204 .tv = 1,
3205 },{
3206 .name = name_tv_mono,
3207 .vmux = 7,
3208 .amux = 4,
3209 .tv = 1,
3210 },{
3211 .name = name_comp1,
3212 .vmux = 3,
3213 .amux = 2,
3214 },{
3215 .name = name_svideo,
3216 .vmux = 0,
3217 .amux = 2,
3218 }},
3219 .radio = {
3220 .name = name_radio,
3221 .amux = LINE2,
3222/* .gpio = 0x00300001,*/
3223 .gpio = 0x20000,
3224
3225 },
3226 .mute = {
3227 .name = name_mute,
3228 .amux = 0,
3229 },
3230 },
3231 [SAA7134_BOARD_ENCORE_ENLTV_FM] = {
3232 /* Juan Pablo Sormani <sorman@gmail.com> */
3233 .name = "Encore ENLTV-FM",
3234 .audio_clock = 0x00200000,
3235 .tuner_type = TUNER_PHILIPS_ATSC,
3236 .radio_type = UNSET,
3237 .tuner_addr = ADDR_UNSET,
3238 .radio_addr = ADDR_UNSET,
3239 .inputs = {{
3240 .name = name_tv,
3241 .vmux = 1,
3242 .amux = 3,
3243 .tv = 1,
3244 },{
3245 .name = name_tv_mono,
3246 .vmux = 7,
3247 .amux = 4,
3248 .tv = 1,
3249 },{
3250 .name = name_comp1,
3251 .vmux = 3,
3252 .amux = 2,
3253 },{
3254 .name = name_svideo,
3255 .vmux = 0,
3256 .amux = 2,
3257 }},
3258 .radio = {
3259 .name = name_radio,
3260 .amux = LINE2,
3261 .gpio = 0x20000,
3262
3263 },
3264 .mute = {
3265 .name = name_mute,
3266 .amux = 0,
3267 },
3268 },
3269 [SAA7134_BOARD_CINERGY_HT_PCI] = {
3270 .name = "Terratec Cinergy HT PCI",
3271 .audio_clock = 0x00187de7,
3272 .tuner_type = TUNER_PHILIPS_TDA8290,
3273 .radio_type = UNSET,
3274 .tuner_addr = ADDR_UNSET,
3275 .radio_addr = ADDR_UNSET,
3276 .mpeg = SAA7134_MPEG_DVB,
3277 .inputs = {{
3278 .name = name_tv,
3279 .vmux = 1,
3280 .amux = TV,
3281 .tv = 1,
3282 },{
3283 .name = name_comp1,
3284 .vmux = 0,
3285 .amux = LINE1,
3286 },{
3287 .name = name_svideo,
3288 .vmux = 6,
3289 .amux = LINE1,
3290 }},
3291 },
3186}; 3292};
3187 3293
3188const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards); 3294const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
@@ -3822,6 +3928,36 @@ struct pci_device_id saa7134_pci_tbl[] = {
3822 .subdevice = 0x1172, 3928 .subdevice = 0x1172,
3823 .driver_data = SAA7134_BOARD_CINERGY_HT_PCMCIA, 3929 .driver_data = SAA7134_BOARD_CINERGY_HT_PCMCIA,
3824 },{ 3930 },{
3931 .vendor = PCI_VENDOR_ID_PHILIPS,
3932 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
3933 .subvendor = PCI_VENDOR_ID_PHILIPS,
3934 .subdevice = 0x2342,
3935 .driver_data = SAA7134_BOARD_ENCORE_ENLTV,
3936 },{
3937 .vendor = PCI_VENDOR_ID_PHILIPS,
3938 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
3939 .subvendor = 0x1131,
3940 .subdevice = 0x2341,
3941 .driver_data = SAA7134_BOARD_ENCORE_ENLTV,
3942 },{
3943 .vendor = PCI_VENDOR_ID_PHILIPS,
3944 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
3945 .subvendor = 0x3016,
3946 .subdevice = 0x2344,
3947 .driver_data = SAA7134_BOARD_ENCORE_ENLTV,
3948 },{
3949 .vendor = PCI_VENDOR_ID_PHILIPS,
3950 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
3951 .subvendor = 0x1131,
3952 .subdevice = 0x230f,
3953 .driver_data = SAA7134_BOARD_ENCORE_ENLTV_FM,
3954 },{
3955 .vendor = PCI_VENDOR_ID_PHILIPS,
3956 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3957 .subvendor = 0x153b,
3958 .subdevice = 0x1175,
3959 .driver_data = SAA7134_BOARD_CINERGY_HT_PCI,
3960 },{
3825 /* --- boards without eeprom + subsystem ID --- */ 3961 /* --- boards without eeprom + subsystem ID --- */
3826 .vendor = PCI_VENDOR_ID_PHILIPS, 3962 .vendor = PCI_VENDOR_ID_PHILIPS,
3827 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 3963 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -3926,9 +4062,12 @@ int saa7134_board_init1(struct saa7134_dev *dev)
3926 case SAA7134_BOARD_KWORLD_TERMINATOR: 4062 case SAA7134_BOARD_KWORLD_TERMINATOR:
3927 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS: 4063 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
3928 case SAA7134_BOARD_FLYDVBT_LR301: 4064 case SAA7134_BOARD_FLYDVBT_LR301:
4065 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
3929 case SAA7134_BOARD_FLYDVBTDUO: 4066 case SAA7134_BOARD_FLYDVBTDUO:
3930 case SAA7134_BOARD_PROTEUS_2309: 4067 case SAA7134_BOARD_PROTEUS_2309:
3931 case SAA7134_BOARD_AVERMEDIA_A16AR: 4068 case SAA7134_BOARD_AVERMEDIA_A16AR:
4069 case SAA7134_BOARD_ENCORE_ENLTV:
4070 case SAA7134_BOARD_ENCORE_ENLTV_FM:
3932 dev->has_remote = SAA7134_REMOTE_GPIO; 4071 dev->has_remote = SAA7134_REMOTE_GPIO;
3933 break; 4072 break;
3934 case SAA7134_BOARD_FLYDVBS_LR300: 4073 case SAA7134_BOARD_FLYDVBS_LR300:
@@ -4150,6 +4289,7 @@ int saa7134_board_init2(struct saa7134_dev *dev)
4150 } 4289 }
4151 break; 4290 break;
4152 case SAA7134_BOARD_CINERGY_HT_PCMCIA: 4291 case SAA7134_BOARD_CINERGY_HT_PCMCIA:
4292 case SAA7134_BOARD_CINERGY_HT_PCI:
4153 /* make the tda10046 find its eeprom */ 4293 /* make the tda10046 find its eeprom */
4154 { 4294 {
4155 u8 data[] = { 0x3c, 0x33, 0x60}; 4295 u8 data[] = { 0x3c, 0x33, 0x60};
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index c33f6a69a2..e3059fd339 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -1426,6 +1426,18 @@ static int dvb_init(struct saa7134_dev *dev)
1426 1426
1427 } 1427 }
1428 break; 1428 break;
1429 case SAA7134_BOARD_CINERGY_HT_PCI:
1430 dev->dvb.frontend = dvb_attach(tda10046_attach,
1431 &cinergy_ht_config,
1432 &dev->i2c_adap);
1433 if (dev->dvb.frontend) {
1434 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
1435 dev->dvb.frontend->ops.tuner_ops.init = cinergy_ht_tuner_init;
1436 dev->dvb.frontend->ops.tuner_ops.sleep = cinergy_ht_tuner_sleep;
1437 dev->dvb.frontend->ops.tuner_ops.set_params = md8800_dvbt_pll_set;
1438
1439 }
1440 break;
1429 default: 1441 default:
1430 printk("%s: Huh? unknown DVB card?\n",dev->name); 1442 printk("%s: Huh? unknown DVB card?\n",dev->name);
1431 break; 1443 break;
diff --git a/drivers/media/video/saa7134/saa7134-i2c.c b/drivers/media/video/saa7134/saa7134-i2c.c
index 6f9fe86fed..cce8da6a4f 100644
--- a/drivers/media/video/saa7134/saa7134-i2c.c
+++ b/drivers/media/video/saa7134/saa7134-i2c.c
@@ -120,9 +120,9 @@ static inline int i2c_is_error(enum i2c_status status)
120 case ARB_LOST: 120 case ARB_LOST:
121 case SEQ_ERR: 121 case SEQ_ERR:
122 case ST_ERR: 122 case ST_ERR:
123 return TRUE; 123 return true;
124 default: 124 default:
125 return FALSE; 125 return false;
126 } 126 }
127} 127}
128 128
@@ -131,9 +131,9 @@ static inline int i2c_is_idle(enum i2c_status status)
131 switch (status) { 131 switch (status) {
132 case IDLE: 132 case IDLE:
133 case DONE_STOP: 133 case DONE_STOP:
134 return TRUE; 134 return true;
135 default: 135 default:
136 return FALSE; 136 return false;
137 } 137 }
138} 138}
139 139
@@ -141,9 +141,9 @@ static inline int i2c_is_busy(enum i2c_status status)
141{ 141{
142 switch (status) { 142 switch (status) {
143 case BUSY: 143 case BUSY:
144 return TRUE; 144 return true;
145 default: 145 default:
146 return FALSE; 146 return false;
147 } 147 }
148} 148}
149 149
@@ -159,8 +159,8 @@ static int i2c_is_busy_wait(struct saa7134_dev *dev)
159 saa_wait(I2C_WAIT_DELAY); 159 saa_wait(I2C_WAIT_DELAY);
160 } 160 }
161 if (I2C_WAIT_RETRY == count) 161 if (I2C_WAIT_RETRY == count)
162 return FALSE; 162 return false;
163 return TRUE; 163 return true;
164} 164}
165 165
166static int i2c_reset(struct saa7134_dev *dev) 166static int i2c_reset(struct saa7134_dev *dev)
@@ -171,7 +171,7 @@ static int i2c_reset(struct saa7134_dev *dev)
171 d2printk(KERN_DEBUG "%s: i2c reset\n",dev->name); 171 d2printk(KERN_DEBUG "%s: i2c reset\n",dev->name);
172 status = i2c_get_status(dev); 172 status = i2c_get_status(dev);
173 if (!i2c_is_error(status)) 173 if (!i2c_is_error(status))
174 return TRUE; 174 return true;
175 i2c_set_status(dev,status); 175 i2c_set_status(dev,status);
176 176
177 for (count = 0; count < I2C_WAIT_RETRY; count++) { 177 for (count = 0; count < I2C_WAIT_RETRY; count++) {
@@ -181,13 +181,13 @@ static int i2c_reset(struct saa7134_dev *dev)
181 udelay(I2C_WAIT_DELAY); 181 udelay(I2C_WAIT_DELAY);
182 } 182 }
183 if (I2C_WAIT_RETRY == count) 183 if (I2C_WAIT_RETRY == count)
184 return FALSE; 184 return false;
185 185
186 if (!i2c_is_idle(status)) 186 if (!i2c_is_idle(status))
187 return FALSE; 187 return false;
188 188
189 i2c_set_attr(dev,NOP); 189 i2c_set_attr(dev,NOP);
190 return TRUE; 190 return true;
191} 191}
192 192
193static inline int i2c_send_byte(struct saa7134_dev *dev, 193static inline int i2c_send_byte(struct saa7134_dev *dev,
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index e4252683a5..46c583f1e7 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -40,16 +40,24 @@ static int pinnacle_remote = 0;
40module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */ 40module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */
41MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)"); 41MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
42 42
43static int ir_rc5_remote_gap = 885;
44module_param(ir_rc5_remote_gap, int, 0644);
45static int ir_rc5_key_timeout = 115;
46module_param(ir_rc5_key_timeout, int, 0644);
47
43#define dprintk(fmt, arg...) if (ir_debug) \ 48#define dprintk(fmt, arg...) if (ir_debug) \
44 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg) 49 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
45#define i2cdprintk(fmt, arg...) if (ir_debug) \ 50#define i2cdprintk(fmt, arg...) if (ir_debug) \
46 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg) 51 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
47 52
53/** rc5 functions */
54static int saa7134_rc5_irq(struct saa7134_dev *dev);
55
48/* -------------------- GPIO generic keycode builder -------------------- */ 56/* -------------------- GPIO generic keycode builder -------------------- */
49 57
50static int build_key(struct saa7134_dev *dev) 58static int build_key(struct saa7134_dev *dev)
51{ 59{
52 struct saa7134_ir *ir = dev->remote; 60 struct card_ir *ir = dev->remote;
53 u32 gpio, data; 61 u32 gpio, data;
54 62
55 /* rising SAA7134_GPIO_GPRESCAN reads the status */ 63 /* rising SAA7134_GPIO_GPRESCAN reads the status */
@@ -134,16 +142,19 @@ static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
134 142
135void saa7134_input_irq(struct saa7134_dev *dev) 143void saa7134_input_irq(struct saa7134_dev *dev)
136{ 144{
137 struct saa7134_ir *ir = dev->remote; 145 struct card_ir *ir = dev->remote;
138 146
139 if (!ir->polling) 147 if (!ir->polling && !ir->rc5_gpio) {
140 build_key(dev); 148 build_key(dev);
149 } else if (ir->rc5_gpio) {
150 saa7134_rc5_irq(dev);
151 }
141} 152}
142 153
143static void saa7134_input_timer(unsigned long data) 154static void saa7134_input_timer(unsigned long data)
144{ 155{
145 struct saa7134_dev *dev = (struct saa7134_dev*)data; 156 struct saa7134_dev *dev = (struct saa7134_dev*)data;
146 struct saa7134_ir *ir = dev->remote; 157 struct card_ir *ir = dev->remote;
147 unsigned long timeout; 158 unsigned long timeout;
148 159
149 build_key(dev); 160 build_key(dev);
@@ -151,7 +162,7 @@ static void saa7134_input_timer(unsigned long data)
151 mod_timer(&ir->timer, timeout); 162 mod_timer(&ir->timer, timeout);
152} 163}
153 164
154static void saa7134_ir_start(struct saa7134_dev *dev, struct saa7134_ir *ir) 165static void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir)
155{ 166{
156 if (ir->polling) { 167 if (ir->polling) {
157 init_timer(&ir->timer); 168 init_timer(&ir->timer);
@@ -159,6 +170,19 @@ static void saa7134_ir_start(struct saa7134_dev *dev, struct saa7134_ir *ir)
159 ir->timer.data = (unsigned long)dev; 170 ir->timer.data = (unsigned long)dev;
160 ir->timer.expires = jiffies + HZ; 171 ir->timer.expires = jiffies + HZ;
161 add_timer(&ir->timer); 172 add_timer(&ir->timer);
173 } else if (ir->rc5_gpio) {
174 /* set timer_end for code completion */
175 init_timer(&ir->timer_end);
176 ir->timer_end.function = ir_rc5_timer_end;
177 ir->timer_end.data = (unsigned long)ir;
178 init_timer(&ir->timer_keyup);
179 ir->timer_keyup.function = ir_rc5_timer_keyup;
180 ir->timer_keyup.data = (unsigned long)ir;
181 ir->shift_by = 2;
182 ir->start = 0x2;
183 ir->addr = 0x17;
184 ir->rc5_key_timeout = ir_rc5_key_timeout;
185 ir->rc5_remote_gap = ir_rc5_remote_gap;
162 } 186 }
163} 187}
164 188
@@ -170,13 +194,14 @@ static void saa7134_ir_stop(struct saa7134_dev *dev)
170 194
171int saa7134_input_init1(struct saa7134_dev *dev) 195int saa7134_input_init1(struct saa7134_dev *dev)
172{ 196{
173 struct saa7134_ir *ir; 197 struct card_ir *ir;
174 struct input_dev *input_dev; 198 struct input_dev *input_dev;
175 IR_KEYTAB_TYPE *ir_codes = NULL; 199 IR_KEYTAB_TYPE *ir_codes = NULL;
176 u32 mask_keycode = 0; 200 u32 mask_keycode = 0;
177 u32 mask_keydown = 0; 201 u32 mask_keydown = 0;
178 u32 mask_keyup = 0; 202 u32 mask_keyup = 0;
179 int polling = 0; 203 int polling = 0;
204 int rc5_gpio = 0;
180 int ir_type = IR_TYPE_OTHER; 205 int ir_type = IR_TYPE_OTHER;
181 int err; 206 int err;
182 207
@@ -295,6 +320,18 @@ int saa7134_input_init1(struct saa7134_dev *dev)
295 mask_keycode = 0x0001F00; 320 mask_keycode = 0x0001F00;
296 mask_keydown = 0x0040000; 321 mask_keydown = 0x0040000;
297 break; 322 break;
323 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
324 ir_codes = ir_codes_asus_pc39;
325 mask_keydown = 0x0040000;
326 rc5_gpio = 1;
327 break;
328 case SAA7134_BOARD_ENCORE_ENLTV:
329 case SAA7134_BOARD_ENCORE_ENLTV_FM:
330 ir_codes = ir_codes_encore_enltv;
331 mask_keycode = 0x00007f;
332 mask_keyup = 0x040000;
333 polling = 50; // ms
334 break;
298 } 335 }
299 if (NULL == ir_codes) { 336 if (NULL == ir_codes) {
300 printk("%s: Oops: IR config error [card=%d]\n", 337 printk("%s: Oops: IR config error [card=%d]\n",
@@ -316,6 +353,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
316 ir->mask_keydown = mask_keydown; 353 ir->mask_keydown = mask_keydown;
317 ir->mask_keyup = mask_keyup; 354 ir->mask_keyup = mask_keyup;
318 ir->polling = polling; 355 ir->polling = polling;
356 ir->rc5_gpio = rc5_gpio;
319 357
320 /* init input device */ 358 /* init input device */
321 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)", 359 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
@@ -402,6 +440,49 @@ void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
402 } 440 }
403 441
404} 442}
443
444static int saa7134_rc5_irq(struct saa7134_dev *dev)
445{
446 struct card_ir *ir = dev->remote;
447 struct timeval tv;
448 u32 gap;
449 unsigned long current_jiffies, timeout;
450
451 /* get time of bit */
452 current_jiffies = jiffies;
453 do_gettimeofday(&tv);
454
455 /* avoid overflow with gap >1s */
456 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
457 gap = 200000;
458 } else {
459 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
460 tv.tv_usec - ir->base_time.tv_usec;
461 }
462
463 /* active code => add bit */
464 if (ir->active) {
465 /* only if in the code (otherwise spurious IRQ or timer
466 late) */
467 if (ir->last_bit < 28) {
468 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
469 ir_rc5_remote_gap;
470 ir->code |= 1 << ir->last_bit;
471 }
472 /* starting new code */
473 } else {
474 ir->active = 1;
475 ir->code = 0;
476 ir->base_time = tv;
477 ir->last_bit = 0;
478
479 timeout = current_jiffies + (500 + 30 * HZ) / 1000;
480 mod_timer(&ir->timer_end, timeout);
481 }
482
483 return 1;
484}
485
405/* ---------------------------------------------------------------------- 486/* ----------------------------------------------------------------------
406 * Local variables: 487 * Local variables:
407 * c-basic-offset: 8 488 * c-basic-offset: 8
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index 88cd1297df..b3e3957c89 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -41,14 +41,10 @@
41#include <sound/driver.h> 41#include <sound/driver.h>
42#include <sound/core.h> 42#include <sound/core.h>
43#include <sound/pcm.h> 43#include <sound/pcm.h>
44#if defined(CONFIG_VIDEO_BUF_DVB) || defined(CONFIG_VIDEO_BUF_DVB_MODULE)
44#include <media/video-buf-dvb.h> 45#include <media/video-buf-dvb.h>
45
46#ifndef TRUE
47# define TRUE (1==1)
48#endif
49#ifndef FALSE
50# define FALSE (1==0)
51#endif 46#endif
47
52#define UNSET (-1U) 48#define UNSET (-1U)
53 49
54/* ----------------------------------------------------------- */ 50/* ----------------------------------------------------------- */
@@ -232,6 +228,9 @@ struct saa7134_format {
232#define SAA7134_BOARD_VIDEOMATE_DVBT_200A 103 228#define SAA7134_BOARD_VIDEOMATE_DVBT_200A 103
233#define SAA7134_BOARD_HAUPPAUGE_HVR1110 104 229#define SAA7134_BOARD_HAUPPAUGE_HVR1110 104
234#define SAA7134_BOARD_CINERGY_HT_PCMCIA 105 230#define SAA7134_BOARD_CINERGY_HT_PCMCIA 105
231#define SAA7134_BOARD_ENCORE_ENLTV 106
232#define SAA7134_BOARD_ENCORE_ENLTV_FM 107
233#define SAA7134_BOARD_CINERGY_HT_PCI 108
235 234
236#define SAA7134_MAXBOARDS 8 235#define SAA7134_MAXBOARDS 8
237#define SAA7134_INPUT_MAX 8 236#define SAA7134_INPUT_MAX 8
@@ -411,20 +410,6 @@ struct saa7134_dmasound {
411 struct snd_pcm_substream *substream; 410 struct snd_pcm_substream *substream;
412}; 411};
413 412
414/* IR input */
415struct saa7134_ir {
416 struct input_dev *dev;
417 struct ir_input_state ir;
418 char name[32];
419 char phys[32];
420 u32 mask_keycode;
421 u32 mask_keydown;
422 u32 mask_keyup;
423 int polling;
424 u32 last_gpio;
425 struct timer_list timer;
426};
427
428/* ts/mpeg status */ 413/* ts/mpeg status */
429struct saa7134_ts { 414struct saa7134_ts {
430 /* TS capture */ 415 /* TS capture */
@@ -463,7 +448,7 @@ struct saa7134_dev {
463 448
464 /* infrared remote */ 449 /* infrared remote */
465 int has_remote; 450 int has_remote;
466 struct saa7134_ir *remote; 451 struct card_ir *remote;
467 452
468 /* pci i/o */ 453 /* pci i/o */
469 char name[32]; 454 char name[32];
@@ -543,9 +528,11 @@ struct saa7134_dev {
543 struct work_struct empress_workqueue; 528 struct work_struct empress_workqueue;
544 int empress_started; 529 int empress_started;
545 530
531#if defined(CONFIG_VIDEO_BUF_DVB) || defined(CONFIG_VIDEO_BUF_DVB_MODULE)
546 /* SAA7134_MPEG_DVB only */ 532 /* SAA7134_MPEG_DVB only */
547 struct videobuf_dvb dvb; 533 struct videobuf_dvb dvb;
548 int (*original_demod_sleep)(struct dvb_frontend* fe); 534 int (*original_demod_sleep)(struct dvb_frontend* fe);
535#endif
549}; 536};
550 537
551/* ----------------------------------------------------------- */ 538/* ----------------------------------------------------------- */
@@ -698,6 +685,7 @@ void saa7134_input_fini(struct saa7134_dev *dev);
698void saa7134_input_irq(struct saa7134_dev *dev); 685void saa7134_input_irq(struct saa7134_dev *dev);
699void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir); 686void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir);
700 687
688
701/* 689/*
702 * Local variables: 690 * Local variables:
703 * c-basic-offset: 8 691 * c-basic-offset: 8
diff --git a/drivers/media/video/sn9c102/Kconfig b/drivers/media/video/sn9c102/Kconfig
index cf552e6b8e..1a7ccb666a 100644
--- a/drivers/media/video/sn9c102/Kconfig
+++ b/drivers/media/video/sn9c102/Kconfig
@@ -1,9 +1,9 @@
1config USB_SN9C102 1config USB_SN9C102
2 tristate "USB SN9C10x PC Camera Controller support" 2 tristate "USB SN9C1xx PC Camera Controller support"
3 depends on USB && VIDEO_V4L1 3 depends on USB && VIDEO_V4L1
4 ---help--- 4 ---help---
5 Say Y here if you want support for cameras based on SONiX SN9C101, 5 Say Y here if you want support for cameras based on SONiX SN9C101,
6 SN9C102 or SN9C103 PC Camera Controllers. 6 SN9C102, SN9C103, SN9C105 and SN9C120 PC Camera Controllers.
7 7
8 See <file:Documentation/video4linux/sn9c102.txt> for more info. 8 See <file:Documentation/video4linux/sn9c102.txt> for more info.
9 9
diff --git a/drivers/media/video/sn9c102/Makefile b/drivers/media/video/sn9c102/Makefile
index 536ad3098d..30e3dfe537 100644
--- a/drivers/media/video/sn9c102/Makefile
+++ b/drivers/media/video/sn9c102/Makefile
@@ -1,5 +1,5 @@
1sn9c102-objs := sn9c102_core.o sn9c102_hv7131d.o sn9c102_mi0343.o \ 1sn9c102-objs := sn9c102_core.o sn9c102_hv7131d.o sn9c102_mi0343.o \
2 sn9c102_ov7630.o sn9c102_pas106b.o sn9c102_pas202bca.o \ 2 sn9c102_ov7630.o sn9c102_ov7660.o sn9c102_pas106b.o \
3 sn9c102_pas202bcb.o sn9c102_tas5110c1b.o \ 3 sn9c102_pas202bcb.o sn9c102_tas5110c1b.o \
4 sn9c102_tas5130d1b.o 4 sn9c102_tas5130d1b.o
5 5
diff --git a/drivers/media/video/sn9c102/sn9c102.h b/drivers/media/video/sn9c102/sn9c102.h
index 2c6ff396da..5428f34e7c 100644
--- a/drivers/media/video/sn9c102/sn9c102.h
+++ b/drivers/media/video/sn9c102/sn9c102.h
@@ -1,5 +1,5 @@
1/*************************************************************************** 1/***************************************************************************
2 * V4L2 driver for SN9C10x PC Camera Controllers * 2 * V4L2 driver for SN9C1xx PC Camera Controllers *
3 * * 3 * *
4 * Copyright (C) 2004-2006 by Luca Risolia <luca.risolia@studio.unibo.it> * 4 * Copyright (C) 2004-2006 by Luca Risolia <luca.risolia@studio.unibo.it> *
5 * * 5 * *
@@ -37,33 +37,10 @@
37#include <linux/string.h> 37#include <linux/string.h>
38#include <linux/stddef.h> 38#include <linux/stddef.h>
39 39
40#include "sn9c102_config.h"
40#include "sn9c102_sensor.h" 41#include "sn9c102_sensor.h"
42#include "sn9c102_devtable.h"
41 43
42/*****************************************************************************/
43
44#define SN9C102_DEBUG
45#define SN9C102_DEBUG_LEVEL 2
46#define SN9C102_MAX_DEVICES 64
47#define SN9C102_PRESERVE_IMGSCALE 0
48#define SN9C102_FORCE_MUNMAP 0
49#define SN9C102_MAX_FRAMES 32
50#define SN9C102_URBS 2
51#define SN9C102_ISO_PACKETS 7
52#define SN9C102_ALTERNATE_SETTING 8
53#define SN9C102_URB_TIMEOUT msecs_to_jiffies(2 * SN9C102_ISO_PACKETS)
54#define SN9C102_CTRL_TIMEOUT 300
55#define SN9C102_FRAME_TIMEOUT 2
56
57/*****************************************************************************/
58
59enum sn9c102_bridge {
60 BRIDGE_SN9C101 = 0x01,
61 BRIDGE_SN9C102 = 0x02,
62 BRIDGE_SN9C103 = 0x04,
63};
64
65SN9C102_ID_TABLE
66SN9C102_SENSOR_TABLE
67 44
68enum sn9c102_frame_state { 45enum sn9c102_frame_state {
69 F_UNUSED, 46 F_UNUSED,
@@ -99,13 +76,11 @@ enum sn9c102_stream_state {
99 STREAM_ON, 76 STREAM_ON,
100}; 77};
101 78
102typedef char sn9c103_sof_header_t[18]; 79typedef char sn9c102_sof_header_t[62];
103typedef char sn9c102_sof_header_t[12];
104typedef char sn9c102_eof_header_t[4];
105 80
106struct sn9c102_sysfs_attr { 81struct sn9c102_sysfs_attr {
107 u8 reg, i2c_reg; 82 u8 reg, i2c_reg;
108 sn9c103_sof_header_t frame_header; 83 sn9c102_sof_header_t frame_header;
109}; 84};
110 85
111struct sn9c102_module_param { 86struct sn9c102_module_param {
@@ -137,8 +112,8 @@ struct sn9c102_device {
137 struct v4l2_jpegcompression compression; 112 struct v4l2_jpegcompression compression;
138 113
139 struct sn9c102_sysfs_attr sysfs; 114 struct sn9c102_sysfs_attr sysfs;
140 sn9c103_sof_header_t sof_header; 115 sn9c102_sof_header_t sof_header;
141 u16 reg[63]; 116 u16 reg[384];
142 117
143 struct sn9c102_module_param module_param; 118 struct sn9c102_module_param module_param;
144 119
@@ -155,10 +130,7 @@ struct sn9c102_device {
155struct sn9c102_device* 130struct sn9c102_device*
156sn9c102_match_id(struct sn9c102_device* cam, const struct usb_device_id *id) 131sn9c102_match_id(struct sn9c102_device* cam, const struct usb_device_id *id)
157{ 132{
158 if (usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id)) 133 return usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id) ? cam : NULL;
159 return cam;
160
161 return NULL;
162} 134}
163 135
164 136
@@ -169,6 +141,19 @@ sn9c102_attach_sensor(struct sn9c102_device* cam,
169 memcpy(&cam->sensor, sensor, sizeof(struct sn9c102_sensor)); 141 memcpy(&cam->sensor, sensor, sizeof(struct sn9c102_sensor));
170} 142}
171 143
144
145enum sn9c102_bridge
146sn9c102_get_bridge(struct sn9c102_device* cam)
147{
148 return cam->bridge;
149}
150
151
152struct sn9c102_sensor* sn9c102_get_sensor(struct sn9c102_device* cam)
153{
154 return &cam->sensor;
155}
156
172/*****************************************************************************/ 157/*****************************************************************************/
173 158
174#undef DBG 159#undef DBG
diff --git a/drivers/media/video/sn9c102/sn9c102_config.h b/drivers/media/video/sn9c102/sn9c102_config.h
new file mode 100644
index 0000000000..0f4e0378b0
--- /dev/null
+++ b/drivers/media/video/sn9c102/sn9c102_config.h
@@ -0,0 +1,86 @@
1/***************************************************************************
2 * Global parameters for the V4L2 driver for SN9C1xx PC Camera Controllers *
3 * *
4 * Copyright (C) 2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
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#ifndef _SN9C102_CONFIG_H_
22#define _SN9C102_CONFIG_H_
23
24#include <linux/types.h>
25#include <linux/jiffies.h>
26
27#define SN9C102_DEBUG
28#define SN9C102_DEBUG_LEVEL 2
29#define SN9C102_MAX_DEVICES 64
30#define SN9C102_PRESERVE_IMGSCALE 0
31#define SN9C102_FORCE_MUNMAP 0
32#define SN9C102_MAX_FRAMES 32
33#define SN9C102_URBS 2
34#define SN9C102_ISO_PACKETS 7
35#define SN9C102_ALTERNATE_SETTING 8
36#define SN9C102_URB_TIMEOUT msecs_to_jiffies(2 * SN9C102_ISO_PACKETS)
37#define SN9C102_CTRL_TIMEOUT 300
38#define SN9C102_FRAME_TIMEOUT 0
39
40/*****************************************************************************/
41
42static const u8 SN9C102_Y_QTABLE0[64] = {
43 8, 5, 5, 8, 12, 20, 25, 30,
44 6, 6, 7, 9, 13, 29, 30, 27,
45 7, 6, 8, 12, 20, 28, 34, 28,
46 7, 8, 11, 14, 25, 43, 40, 31,
47 9, 11, 18, 28, 34, 54, 51, 38,
48 12, 17, 27, 32, 40, 52, 56, 46,
49 24, 32, 39, 43, 51, 60, 60, 50,
50 36, 46, 47, 49, 56, 50, 51, 49
51};
52
53static const u8 SN9C102_UV_QTABLE0[64] = {
54 8, 9, 12, 23, 49, 49, 49, 49,
55 9, 10, 13, 33, 49, 49, 49, 49,
56 12, 13, 28, 49, 49, 49, 49, 49,
57 23, 33, 49, 49, 49, 49, 49, 49,
58 49, 49, 49, 49, 49, 49, 49, 49,
59 49, 49, 49, 49, 49, 49, 49, 49,
60 49, 49, 49, 49, 49, 49, 49, 49,
61 49, 49, 49, 49, 49, 49, 49, 49
62};
63
64static const u8 SN9C102_Y_QTABLE1[64] = {
65 16, 11, 10, 16, 24, 40, 51, 61,
66 12, 12, 14, 19, 26, 58, 60, 55,
67 14, 13, 16, 24, 40, 57, 69, 56,
68 14, 17, 22, 29, 51, 87, 80, 62,
69 18, 22, 37, 56, 68, 109, 103, 77,
70 24, 35, 55, 64, 81, 104, 113, 92,
71 49, 64, 78, 87, 103, 121, 120, 101,
72 72, 92, 95, 98, 112, 100, 103, 99
73};
74
75static const u8 SN9C102_UV_QTABLE1[64] = {
76 17, 18, 24, 47, 99, 99, 99, 99,
77 18, 21, 26, 66, 99, 99, 99, 99,
78 24, 26, 56, 99, 99, 99, 99, 99,
79 47, 66, 99, 99, 99, 99, 99, 99,
80 99, 99, 99, 99, 99, 99, 99, 99,
81 99, 99, 99, 99, 99, 99, 99, 99,
82 99, 99, 99, 99, 99, 99, 99, 99,
83 99, 99, 99, 99, 99, 99, 99, 99
84};
85
86#endif /* _SN9C102_CONFIG_H_ */
diff --git a/drivers/media/video/sn9c102/sn9c102_core.c b/drivers/media/video/sn9c102/sn9c102_core.c
index 04d4c8f28b..d0e2b40a77 100644
--- a/drivers/media/video/sn9c102/sn9c102_core.c
+++ b/drivers/media/video/sn9c102/sn9c102_core.c
@@ -1,7 +1,7 @@
1/*************************************************************************** 1/***************************************************************************
2 * V4L2 driver for SN9C10x PC Camera Controllers * 2 * V4L2 driver for SN9C1xx PC Camera Controllers *
3 * * 3 * *
4 * Copyright (C) 2004-2006 by Luca Risolia <luca.risolia@studio.unibo.it> * 4 * Copyright (C) 2004-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
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 *
@@ -43,12 +43,12 @@
43 43
44/*****************************************************************************/ 44/*****************************************************************************/
45 45
46#define SN9C102_MODULE_NAME "V4L2 driver for SN9C10x PC Camera Controllers" 46#define SN9C102_MODULE_NAME "V4L2 driver for SN9C1xx PC Camera Controllers"
47#define SN9C102_MODULE_AUTHOR "(C) 2004-2006 Luca Risolia" 47#define SN9C102_MODULE_AUTHOR "(C) 2004-2006 Luca Risolia"
48#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>" 48#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
49#define SN9C102_MODULE_LICENSE "GPL" 49#define SN9C102_MODULE_LICENSE "GPL"
50#define SN9C102_MODULE_VERSION "1:1.27" 50#define SN9C102_MODULE_VERSION "1:1.34"
51#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 27) 51#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 1, 34)
52 52
53/*****************************************************************************/ 53/*****************************************************************************/
54 54
@@ -91,7 +91,8 @@ static unsigned int frame_timeout[] = {[0 ... SN9C102_MAX_DEVICES-1] =
91 SN9C102_FRAME_TIMEOUT}; 91 SN9C102_FRAME_TIMEOUT};
92module_param_array(frame_timeout, uint, NULL, 0644); 92module_param_array(frame_timeout, uint, NULL, 0644);
93MODULE_PARM_DESC(frame_timeout, 93MODULE_PARM_DESC(frame_timeout,
94 "\n<n[,...]> Timeout for a video frame in seconds." 94 "\n<0|n[,...]> Timeout for a video frame in seconds before"
95 "\nreturning an I/O error; 0 for infinity."
95 "\nThis parameter is specific for each detected camera." 96 "\nThis parameter is specific for each detected camera."
96 "\nDefault value is "__MODULE_STRING(SN9C102_FRAME_TIMEOUT)"." 97 "\nDefault value is "__MODULE_STRING(SN9C102_FRAME_TIMEOUT)"."
97 "\n"); 98 "\n");
@@ -113,32 +114,13 @@ MODULE_PARM_DESC(debug,
113 114
114/*****************************************************************************/ 115/*****************************************************************************/
115 116
116static sn9c102_sof_header_t sn9c102_sof_header[] = {
117 {0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96, 0x00},
118 {0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96, 0x01},
119};
120
121static sn9c103_sof_header_t sn9c103_sof_header[] = {
122 {0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96, 0x20},
123};
124
125static sn9c102_eof_header_t sn9c102_eof_header[] = {
126 {0x00, 0x00, 0x00, 0x00},
127 {0x40, 0x00, 0x00, 0x00},
128 {0x80, 0x00, 0x00, 0x00},
129 {0xc0, 0x00, 0x00, 0x00},
130};
131
132/*****************************************************************************/
133
134static u32 117static u32
135sn9c102_request_buffers(struct sn9c102_device* cam, u32 count, 118sn9c102_request_buffers(struct sn9c102_device* cam, u32 count,
136 enum sn9c102_io_method io) 119 enum sn9c102_io_method io)
137{ 120{
138 struct v4l2_pix_format* p = &(cam->sensor.pix_format); 121 struct v4l2_pix_format* p = &(cam->sensor.pix_format);
139 struct v4l2_rect* r = &(cam->sensor.cropcap.bounds); 122 struct v4l2_rect* r = &(cam->sensor.cropcap.bounds);
140 const size_t imagesize = cam->module_param.force_munmap || 123 size_t imagesize = cam->module_param.force_munmap || io == IO_READ ?
141 io == IO_READ ?
142 (p->width * p->height * p->priv) / 8 : 124 (p->width * p->height * p->priv) / 8 :
143 (r->width * r->height * p->priv) / 8; 125 (r->width * r->height * p->priv) / 8;
144 void* buff = NULL; 126 void* buff = NULL;
@@ -147,9 +129,13 @@ sn9c102_request_buffers(struct sn9c102_device* cam, u32 count,
147 if (count > SN9C102_MAX_FRAMES) 129 if (count > SN9C102_MAX_FRAMES)
148 count = SN9C102_MAX_FRAMES; 130 count = SN9C102_MAX_FRAMES;
149 131
132 if (cam->bridge == BRIDGE_SN9C105 || cam->bridge == BRIDGE_SN9C120)
133 imagesize += 589 + 2; /* length of JPEG header + EOI marker */
134
150 cam->nbuffers = count; 135 cam->nbuffers = count;
151 while (cam->nbuffers > 0) { 136 while (cam->nbuffers > 0) {
152 if ((buff = vmalloc_32(cam->nbuffers * PAGE_ALIGN(imagesize)))) 137 if ((buff = vmalloc_32_user(cam->nbuffers *
138 PAGE_ALIGN(imagesize))))
153 break; 139 break;
154 cam->nbuffers--; 140 cam->nbuffers--;
155 } 141 }
@@ -322,9 +308,21 @@ static int
322sn9c102_i2c_detect_read_error(struct sn9c102_device* cam, 308sn9c102_i2c_detect_read_error(struct sn9c102_device* cam,
323 struct sn9c102_sensor* sensor) 309 struct sn9c102_sensor* sensor)
324{ 310{
325 int r; 311 int r , err = 0;
312
326 r = sn9c102_read_reg(cam, 0x08); 313 r = sn9c102_read_reg(cam, 0x08);
327 return (r < 0 || (r >= 0 && !(r & 0x08))) ? -EIO : 0; 314 if (r < 0)
315 err += r;
316
317 if (cam->bridge == BRIDGE_SN9C101 || cam->bridge == BRIDGE_SN9C102) {
318 if (!(r & 0x08))
319 err += -1;
320 } else {
321 if (r & 0x08)
322 err += -1;
323 }
324
325 return err ? -EIO : 0;
328} 326}
329 327
330 328
@@ -415,7 +413,7 @@ sn9c102_i2c_try_raw_write(struct sn9c102_device* cam,
415 data[4] = data3; 413 data[4] = data3;
416 data[5] = data4; 414 data[5] = data4;
417 data[6] = data5; 415 data[6] = data5;
418 data[7] = 0x14; 416 data[7] = 0x17;
419 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x08, 0x41, 417 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x08, 0x41,
420 0x08, 0, data, 8, SN9C102_CTRL_TIMEOUT); 418 0x08, 0, data, 8, SN9C102_CTRL_TIMEOUT);
421 if (res < 0) 419 if (res < 0)
@@ -467,31 +465,35 @@ int sn9c102_i2c_write(struct sn9c102_device* cam, u8 address, u8 value)
467 465
468/*****************************************************************************/ 466/*****************************************************************************/
469 467
470static void* 468static size_t sn9c102_sof_length(struct sn9c102_device* cam)
471sn9c102_find_sof_header(struct sn9c102_device* cam, void* mem, size_t len)
472{ 469{
473 size_t soflen = 0, i;
474 u8 j, n = 0;
475
476 switch (cam->bridge) { 470 switch (cam->bridge) {
477 case BRIDGE_SN9C101: 471 case BRIDGE_SN9C101:
478 case BRIDGE_SN9C102: 472 case BRIDGE_SN9C102:
479 soflen = sizeof(sn9c102_sof_header_t); 473 return 12;
480 n = sizeof(sn9c102_sof_header) / soflen;
481 break;
482 case BRIDGE_SN9C103: 474 case BRIDGE_SN9C103:
483 soflen = sizeof(sn9c103_sof_header_t); 475 return 18;
484 n = sizeof(sn9c103_sof_header) / soflen; 476 case BRIDGE_SN9C105:
477 case BRIDGE_SN9C120:
478 return 62;
485 } 479 }
486 480
481 return 0;
482}
483
484
485static void*
486sn9c102_find_sof_header(struct sn9c102_device* cam, void* mem, size_t len)
487{
488 char sof_header[6] = {0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96};
489 size_t soflen = 0, i;
490
491 soflen = sn9c102_sof_length(cam);
492
487 for (i = 0; (len >= soflen) && (i <= len - soflen); i++) 493 for (i = 0; (len >= soflen) && (i <= len - soflen); i++)
488 for (j = 0; j < n; j++) 494 if (!memcmp(mem + i, sof_header, sizeof(sof_header))) {
489 /* The invariable part of the header is 6 bytes long */ 495 memcpy(cam->sof_header, mem + i,
490 if ((cam->bridge != BRIDGE_SN9C103 && 496 sizeof(sn9c102_sof_header_t));
491 !memcmp(mem + i, sn9c102_sof_header[j], 6)) ||
492 (cam->bridge == BRIDGE_SN9C103 &&
493 !memcmp(mem + i, sn9c103_sof_header[j], 6))) {
494 memcpy(cam->sof_header, mem + i, soflen);
495 /* Skip the header */ 497 /* Skip the header */
496 return mem + i + soflen; 498 return mem + i + soflen;
497 } 499 }
@@ -503,21 +505,123 @@ sn9c102_find_sof_header(struct sn9c102_device* cam, void* mem, size_t len)
503static void* 505static void*
504sn9c102_find_eof_header(struct sn9c102_device* cam, void* mem, size_t len) 506sn9c102_find_eof_header(struct sn9c102_device* cam, void* mem, size_t len)
505{ 507{
506 size_t eoflen = sizeof(sn9c102_eof_header_t), i; 508 char eof_header[4][4] = {
507 unsigned j, n = sizeof(sn9c102_eof_header) / eoflen; 509 {0x00, 0x00, 0x00, 0x00},
510 {0x40, 0x00, 0x00, 0x00},
511 {0x80, 0x00, 0x00, 0x00},
512 {0xc0, 0x00, 0x00, 0x00},
513 };
514 size_t i, j;
508 515
509 if (cam->sensor.pix_format.pixelformat == V4L2_PIX_FMT_SN9C10X) 516 if (cam->sensor.pix_format.pixelformat == V4L2_PIX_FMT_SN9C10X ||
517 cam->sensor.pix_format.pixelformat == V4L2_PIX_FMT_JPEG)
510 return NULL; /* EOF header does not exist in compressed data */ 518 return NULL; /* EOF header does not exist in compressed data */
511 519
512 for (i = 0; (len >= eoflen) && (i <= len - eoflen); i++) 520 for (i = 0; (len >= 4) && (i <= len - 4); i++)
513 for (j = 0; j < n; j++) 521 for (j = 0; j < ARRAY_SIZE(eof_header); j++)
514 if (!memcmp(mem + i, sn9c102_eof_header[j], eoflen)) 522 if (!memcmp(mem + i, eof_header[j], 4))
515 return mem + i; 523 return mem + i;
516 524
517 return NULL; 525 return NULL;
518} 526}
519 527
520 528
529static void
530sn9c102_write_jpegheader(struct sn9c102_device* cam, struct sn9c102_frame_t* f)
531{
532 static u8 jpeg_header[589] = {
533 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x84, 0x00, 0x06, 0x04, 0x05,
534 0x06, 0x05, 0x04, 0x06, 0x06, 0x05, 0x06, 0x07, 0x07, 0x06,
535 0x08, 0x0a, 0x10, 0x0a, 0x0a, 0x09, 0x09, 0x0a, 0x14, 0x0e,
536 0x0f, 0x0c, 0x10, 0x17, 0x14, 0x18, 0x18, 0x17, 0x14, 0x16,
537 0x16, 0x1a, 0x1d, 0x25, 0x1f, 0x1a, 0x1b, 0x23, 0x1c, 0x16,
538 0x16, 0x20, 0x2c, 0x20, 0x23, 0x26, 0x27, 0x29, 0x2a, 0x29,
539 0x19, 0x1f, 0x2d, 0x30, 0x2d, 0x28, 0x30, 0x25, 0x28, 0x29,
540 0x28, 0x01, 0x07, 0x07, 0x07, 0x0a, 0x08, 0x0a, 0x13, 0x0a,
541 0x0a, 0x13, 0x28, 0x1a, 0x16, 0x1a, 0x28, 0x28, 0x28, 0x28,
542 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
543 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
544 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
545 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
546 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0xff, 0xc4, 0x01, 0xa2,
547 0x00, 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
548 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02,
549 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x01,
550 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
551 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03,
552 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x10, 0x00,
553 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, 0x04,
554 0x04, 0x00, 0x00, 0x01, 0x7d, 0x01, 0x02, 0x03, 0x00, 0x04,
555 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61,
556 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, 0x23,
557 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, 0x24, 0x33, 0x62,
558 0x72, 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25,
559 0x26, 0x27, 0x28, 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38,
560 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a,
561 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64,
562 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76,
563 0x77, 0x78, 0x79, 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
564 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
565 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa,
566 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2,
567 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3,
568 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, 0xe3,
569 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3,
570 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0x11, 0x00, 0x02,
571 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04,
572 0x00, 0x01, 0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04,
573 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
574 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xa1, 0xb1,
575 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, 0x15, 0x62, 0x72, 0xd1,
576 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19,
577 0x1a, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
578 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a,
579 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64,
580 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76,
581 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
582 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
583 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9,
584 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba,
585 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
586 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe2, 0xe3,
587 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4,
588 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xff, 0xc0, 0x00, 0x11,
589 0x08, 0x01, 0xe0, 0x02, 0x80, 0x03, 0x01, 0x21, 0x00, 0x02,
590 0x11, 0x01, 0x03, 0x11, 0x01, 0xff, 0xda, 0x00, 0x0c, 0x03,
591 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00
592 };
593 u8 *pos = f->bufmem;
594
595 memcpy(pos, jpeg_header, sizeof(jpeg_header));
596 *(pos + 6) = 0x00;
597 *(pos + 7 + 64) = 0x01;
598 if (cam->compression.quality == 0) {
599 memcpy(pos + 7, SN9C102_Y_QTABLE0, 64);
600 memcpy(pos + 8 + 64, SN9C102_UV_QTABLE0, 64);
601 } else if (cam->compression.quality == 1) {
602 memcpy(pos + 7, SN9C102_Y_QTABLE1, 64);
603 memcpy(pos + 8 + 64, SN9C102_UV_QTABLE1, 64);
604 }
605 *(pos + 564) = cam->sensor.pix_format.width & 0xFF;
606 *(pos + 563) = (cam->sensor.pix_format.width >> 8) & 0xFF;
607 *(pos + 562) = cam->sensor.pix_format.height & 0xFF;
608 *(pos + 561) = (cam->sensor.pix_format.height >> 8) & 0xFF;
609 *(pos + 567) = 0x21;
610
611 f->buf.bytesused += sizeof(jpeg_header);
612}
613
614
615static void
616sn9c102_write_eoimarker(struct sn9c102_device* cam, struct sn9c102_frame_t* f)
617{
618 static const u8 eoi_marker[2] = {0xff, 0xd9};
619
620 memcpy(f->bufmem + f->buf.bytesused, eoi_marker, sizeof(eoi_marker));
621 f->buf.bytesused += sizeof(eoi_marker);
622}
623
624
521static void sn9c102_urb_complete(struct urb *urb) 625static void sn9c102_urb_complete(struct urb *urb)
522{ 626{
523 struct sn9c102_device* cam = urb->context; 627 struct sn9c102_device* cam = urb->context;
@@ -535,7 +639,7 @@ static void sn9c102_urb_complete(struct urb *urb)
535 cam->stream = STREAM_OFF; 639 cam->stream = STREAM_OFF;
536 if ((*f)) 640 if ((*f))
537 (*f)->state = F_QUEUED; 641 (*f)->state = F_QUEUED;
538 DBG(3, "Stream interrupted"); 642 DBG(3, "Stream interrupted by application");
539 wake_up(&cam->wait_stream); 643 wake_up(&cam->wait_stream);
540 } 644 }
541 645
@@ -557,10 +661,9 @@ static void sn9c102_urb_complete(struct urb *urb)
557 imagesize = (cam->sensor.pix_format.width * 661 imagesize = (cam->sensor.pix_format.width *
558 cam->sensor.pix_format.height * 662 cam->sensor.pix_format.height *
559 cam->sensor.pix_format.priv) / 8; 663 cam->sensor.pix_format.priv) / 8;
560 664 if (cam->sensor.pix_format.pixelformat == V4L2_PIX_FMT_JPEG)
561 soflen = (cam->bridge) == BRIDGE_SN9C103 ? 665 imagesize += 589; /* length of jpeg header */
562 sizeof(sn9c103_sof_header_t) : 666 soflen = sn9c102_sof_length(cam);
563 sizeof(sn9c102_sof_header_t);
564 667
565 for (i = 0; i < urb->number_of_packets; i++) { 668 for (i = 0; i < urb->number_of_packets; i++) {
566 unsigned int img, len, status; 669 unsigned int img, len, status;
@@ -610,12 +713,21 @@ end_of_frame:
610 (*f)->buf.bytesused += img; 713 (*f)->buf.bytesused += img;
611 714
612 if ((*f)->buf.bytesused == imagesize || 715 if ((*f)->buf.bytesused == imagesize ||
613 (cam->sensor.pix_format.pixelformat == 716 ((cam->sensor.pix_format.pixelformat ==
614 V4L2_PIX_FMT_SN9C10X && eof)) { 717 V4L2_PIX_FMT_SN9C10X ||
718 cam->sensor.pix_format.pixelformat ==
719 V4L2_PIX_FMT_JPEG) && eof)) {
615 u32 b; 720 u32 b;
721
722 if (cam->sensor.pix_format.pixelformat
723 == V4L2_PIX_FMT_JPEG)
724 sn9c102_write_eoimarker(cam,
725 (*f));
726
616 b = (*f)->buf.bytesused; 727 b = (*f)->buf.bytesused;
617 (*f)->state = F_DONE; 728 (*f)->state = F_DONE;
618 (*f)->buf.sequence= ++cam->frame_count; 729 (*f)->buf.sequence= ++cam->frame_count;
730
619 spin_lock(&cam->queue_lock); 731 spin_lock(&cam->queue_lock);
620 list_move_tail(&(*f)->frame, 732 list_move_tail(&(*f)->frame,
621 &cam->outqueue); 733 &cam->outqueue);
@@ -627,8 +739,10 @@ end_of_frame:
627 else 739 else
628 (*f) = NULL; 740 (*f) = NULL;
629 spin_unlock(&cam->queue_lock); 741 spin_unlock(&cam->queue_lock);
742
630 memcpy(cam->sysfs.frame_header, 743 memcpy(cam->sysfs.frame_header,
631 cam->sof_header, soflen); 744 cam->sof_header, soflen);
745
632 DBG(3, "Video frame captured: %lu " 746 DBG(3, "Video frame captured: %lu "
633 "bytes", (unsigned long)(b)); 747 "bytes", (unsigned long)(b));
634 748
@@ -661,6 +775,9 @@ start_of_frame:
661 (*f)->buf.bytesused = 0; 775 (*f)->buf.bytesused = 0;
662 len -= (sof - pos); 776 len -= (sof - pos);
663 pos = sof; 777 pos = sof;
778 if (cam->sensor.pix_format.pixelformat ==
779 V4L2_PIX_FMT_JPEG)
780 sn9c102_write_jpegheader(cam, (*f));
664 DBG(3, "SOF detected: new video frame"); 781 DBG(3, "SOF detected: new video frame");
665 if (len) 782 if (len)
666 goto redo; 783 goto redo;
@@ -671,7 +788,9 @@ start_of_frame:
671 goto end_of_frame; /* (1) */ 788 goto end_of_frame; /* (1) */
672 else { 789 else {
673 if (cam->sensor.pix_format.pixelformat == 790 if (cam->sensor.pix_format.pixelformat ==
674 V4L2_PIX_FMT_SN9C10X) { 791 V4L2_PIX_FMT_SN9C10X ||
792 cam->sensor.pix_format.pixelformat ==
793 V4L2_PIX_FMT_JPEG) {
675 eof = sof - soflen; 794 eof = sof - soflen;
676 goto end_of_frame; 795 goto end_of_frame;
677 } else { 796 } else {
@@ -701,13 +820,11 @@ static int sn9c102_start_transfer(struct sn9c102_device* cam)
701{ 820{
702 struct usb_device *udev = cam->usbdev; 821 struct usb_device *udev = cam->usbdev;
703 struct urb* urb; 822 struct urb* urb;
704 const unsigned int sn9c102_wMaxPacketSize[] = {0, 128, 256, 384, 512, 823 struct usb_host_interface* altsetting = usb_altnum_to_altsetting(
705 680, 800, 900, 1023}; 824 usb_ifnum_to_if(udev, 0),
706 const unsigned int sn9c103_wMaxPacketSize[] = {0, 128, 256, 384, 512, 825 SN9C102_ALTERNATE_SETTING);
707 680, 800, 900, 1003}; 826 const unsigned int psz = le16_to_cpu(altsetting->
708 const unsigned int psz = (cam->bridge == BRIDGE_SN9C103) ? 827 endpoint[0].desc.wMaxPacketSize);
709 sn9c103_wMaxPacketSize[SN9C102_ALTERNATE_SETTING] :
710 sn9c102_wMaxPacketSize[SN9C102_ALTERNATE_SETTING];
711 s8 i, j; 828 s8 i, j;
712 int err = 0; 829 int err = 0;
713 830
@@ -775,7 +892,7 @@ static int sn9c102_start_transfer(struct sn9c102_device* cam)
775 return 0; 892 return 0;
776 893
777free_urbs: 894free_urbs:
778 for (i = 0; i < SN9C102_URBS; i++) 895 for (i = 0; (i < SN9C102_URBS) && cam->urb[i]; i++)
779 usb_free_urb(cam->urb[i]); 896 usb_free_urb(cam->urb[i]);
780 897
781free_buffers: 898free_buffers:
@@ -834,29 +951,29 @@ static int sn9c102_stream_interrupt(struct sn9c102_device* cam)
834/*****************************************************************************/ 951/*****************************************************************************/
835 952
836#ifdef CONFIG_VIDEO_ADV_DEBUG 953#ifdef CONFIG_VIDEO_ADV_DEBUG
837static u8 sn9c102_strtou8(const char* buff, size_t len, ssize_t* count) 954static u16 sn9c102_strtou16(const char* buff, size_t len, ssize_t* count)
838{ 955{
839 char str[5]; 956 char str[7];
840 char* endp; 957 char* endp;
841 unsigned long val; 958 unsigned long val;
842 959
843 if (len < 4) { 960 if (len < 6) {
844 strncpy(str, buff, len); 961 strncpy(str, buff, len);
845 str[len+1] = '\0'; 962 str[len+1] = '\0';
846 } else { 963 } else {
847 strncpy(str, buff, 4); 964 strncpy(str, buff, 4);
848 str[4] = '\0'; 965 str[6] = '\0';
849 } 966 }
850 967
851 val = simple_strtoul(str, &endp, 0); 968 val = simple_strtoul(str, &endp, 0);
852 969
853 *count = 0; 970 *count = 0;
854 if (val <= 0xff) 971 if (val <= 0xffff)
855 *count = (ssize_t)(endp - str); 972 *count = (ssize_t)(endp - str);
856 if ((*count) && (len == *count+1) && (buff[*count] == '\n')) 973 if ((*count) && (len == *count+1) && (buff[*count] == '\n'))
857 *count += 1; 974 *count += 1;
858 975
859 return (u8)val; 976 return (u16)val;
860} 977}
861 978
862/* 979/*
@@ -873,7 +990,8 @@ static ssize_t sn9c102_show_reg(struct class_device* cd, char* buf)
873 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 990 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
874 return -ERESTARTSYS; 991 return -ERESTARTSYS;
875 992
876 cam = video_get_drvdata(to_video_device(cd)); 993 cam = video_get_drvdata(container_of(cd, struct video_device,
994 class_dev));
877 if (!cam) { 995 if (!cam) {
878 mutex_unlock(&sn9c102_sysfs_lock); 996 mutex_unlock(&sn9c102_sysfs_lock);
879 return -ENODEV; 997 return -ENODEV;
@@ -891,27 +1009,28 @@ static ssize_t
891sn9c102_store_reg(struct class_device* cd, const char* buf, size_t len) 1009sn9c102_store_reg(struct class_device* cd, const char* buf, size_t len)
892{ 1010{
893 struct sn9c102_device* cam; 1011 struct sn9c102_device* cam;
894 u8 index; 1012 u16 index;
895 ssize_t count; 1013 ssize_t count;
896 1014
897 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 1015 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
898 return -ERESTARTSYS; 1016 return -ERESTARTSYS;
899 1017
900 cam = video_get_drvdata(to_video_device(cd)); 1018 cam = video_get_drvdata(container_of(cd, struct video_device,
1019 class_dev));
901 if (!cam) { 1020 if (!cam) {
902 mutex_unlock(&sn9c102_sysfs_lock); 1021 mutex_unlock(&sn9c102_sysfs_lock);
903 return -ENODEV; 1022 return -ENODEV;
904 } 1023 }
905 1024
906 index = sn9c102_strtou8(buf, len, &count); 1025 index = sn9c102_strtou16(buf, len, &count);
907 if (index > 0x1f || !count) { 1026 if (index >= ARRAY_SIZE(cam->reg) || !count) {
908 mutex_unlock(&sn9c102_sysfs_lock); 1027 mutex_unlock(&sn9c102_sysfs_lock);
909 return -EINVAL; 1028 return -EINVAL;
910 } 1029 }
911 1030
912 cam->sysfs.reg = index; 1031 cam->sysfs.reg = index;
913 1032
914 DBG(2, "Moved SN9C10X register index to 0x%02X", cam->sysfs.reg); 1033 DBG(2, "Moved SN9C1XX register index to 0x%02X", cam->sysfs.reg);
915 DBG(3, "Written bytes: %zd", count); 1034 DBG(3, "Written bytes: %zd", count);
916 1035
917 mutex_unlock(&sn9c102_sysfs_lock); 1036 mutex_unlock(&sn9c102_sysfs_lock);
@@ -929,7 +1048,8 @@ static ssize_t sn9c102_show_val(struct class_device* cd, char* buf)
929 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 1048 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
930 return -ERESTARTSYS; 1049 return -ERESTARTSYS;
931 1050
932 cam = video_get_drvdata(to_video_device(cd)); 1051 cam = video_get_drvdata(container_of(cd, struct video_device,
1052 class_dev));
933 if (!cam) { 1053 if (!cam) {
934 mutex_unlock(&sn9c102_sysfs_lock); 1054 mutex_unlock(&sn9c102_sysfs_lock);
935 return -ENODEV; 1055 return -ENODEV;
@@ -954,20 +1074,21 @@ static ssize_t
954sn9c102_store_val(struct class_device* cd, const char* buf, size_t len) 1074sn9c102_store_val(struct class_device* cd, const char* buf, size_t len)
955{ 1075{
956 struct sn9c102_device* cam; 1076 struct sn9c102_device* cam;
957 u8 value; 1077 u16 value;
958 ssize_t count; 1078 ssize_t count;
959 int err; 1079 int err;
960 1080
961 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 1081 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
962 return -ERESTARTSYS; 1082 return -ERESTARTSYS;
963 1083
964 cam = video_get_drvdata(to_video_device(cd)); 1084 cam = video_get_drvdata(container_of(cd, struct video_device,
1085 class_dev));
965 if (!cam) { 1086 if (!cam) {
966 mutex_unlock(&sn9c102_sysfs_lock); 1087 mutex_unlock(&sn9c102_sysfs_lock);
967 return -ENODEV; 1088 return -ENODEV;
968 } 1089 }
969 1090
970 value = sn9c102_strtou8(buf, len, &count); 1091 value = sn9c102_strtou16(buf, len, &count);
971 if (!count) { 1092 if (!count) {
972 mutex_unlock(&sn9c102_sysfs_lock); 1093 mutex_unlock(&sn9c102_sysfs_lock);
973 return -EINVAL; 1094 return -EINVAL;
@@ -979,7 +1100,7 @@ sn9c102_store_val(struct class_device* cd, const char* buf, size_t len)
979 return -EIO; 1100 return -EIO;
980 } 1101 }
981 1102
982 DBG(2, "Written SN9C10X reg. 0x%02X, val. 0x%02X", 1103 DBG(2, "Written SN9C1XX reg. 0x%02X, val. 0x%02X",
983 cam->sysfs.reg, value); 1104 cam->sysfs.reg, value);
984 DBG(3, "Written bytes: %zd", count); 1105 DBG(3, "Written bytes: %zd", count);
985 1106
@@ -997,7 +1118,8 @@ static ssize_t sn9c102_show_i2c_reg(struct class_device* cd, char* buf)
997 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 1118 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
998 return -ERESTARTSYS; 1119 return -ERESTARTSYS;
999 1120
1000 cam = video_get_drvdata(to_video_device(cd)); 1121 cam = video_get_drvdata(container_of(cd, struct video_device,
1122 class_dev));
1001 if (!cam) { 1123 if (!cam) {
1002 mutex_unlock(&sn9c102_sysfs_lock); 1124 mutex_unlock(&sn9c102_sysfs_lock);
1003 return -ENODEV; 1125 return -ENODEV;
@@ -1017,19 +1139,20 @@ static ssize_t
1017sn9c102_store_i2c_reg(struct class_device* cd, const char* buf, size_t len) 1139sn9c102_store_i2c_reg(struct class_device* cd, const char* buf, size_t len)
1018{ 1140{
1019 struct sn9c102_device* cam; 1141 struct sn9c102_device* cam;
1020 u8 index; 1142 u16 index;
1021 ssize_t count; 1143 ssize_t count;
1022 1144
1023 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 1145 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1024 return -ERESTARTSYS; 1146 return -ERESTARTSYS;
1025 1147
1026 cam = video_get_drvdata(to_video_device(cd)); 1148 cam = video_get_drvdata(container_of(cd, struct video_device,
1149 class_dev));
1027 if (!cam) { 1150 if (!cam) {
1028 mutex_unlock(&sn9c102_sysfs_lock); 1151 mutex_unlock(&sn9c102_sysfs_lock);
1029 return -ENODEV; 1152 return -ENODEV;
1030 } 1153 }
1031 1154
1032 index = sn9c102_strtou8(buf, len, &count); 1155 index = sn9c102_strtou16(buf, len, &count);
1033 if (!count) { 1156 if (!count) {
1034 mutex_unlock(&sn9c102_sysfs_lock); 1157 mutex_unlock(&sn9c102_sysfs_lock);
1035 return -EINVAL; 1158 return -EINVAL;
@@ -1055,7 +1178,8 @@ static ssize_t sn9c102_show_i2c_val(struct class_device* cd, char* buf)
1055 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 1178 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1056 return -ERESTARTSYS; 1179 return -ERESTARTSYS;
1057 1180
1058 cam = video_get_drvdata(to_video_device(cd)); 1181 cam = video_get_drvdata(container_of(cd, struct video_device,
1182 class_dev));
1059 if (!cam) { 1183 if (!cam) {
1060 mutex_unlock(&sn9c102_sysfs_lock); 1184 mutex_unlock(&sn9c102_sysfs_lock);
1061 return -ENODEV; 1185 return -ENODEV;
@@ -1085,14 +1209,15 @@ static ssize_t
1085sn9c102_store_i2c_val(struct class_device* cd, const char* buf, size_t len) 1209sn9c102_store_i2c_val(struct class_device* cd, const char* buf, size_t len)
1086{ 1210{
1087 struct sn9c102_device* cam; 1211 struct sn9c102_device* cam;
1088 u8 value; 1212 u16 value;
1089 ssize_t count; 1213 ssize_t count;
1090 int err; 1214 int err;
1091 1215
1092 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 1216 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1093 return -ERESTARTSYS; 1217 return -ERESTARTSYS;
1094 1218
1095 cam = video_get_drvdata(to_video_device(cd)); 1219 cam = video_get_drvdata(container_of(cd, struct video_device,
1220 class_dev));
1096 if (!cam) { 1221 if (!cam) {
1097 mutex_unlock(&sn9c102_sysfs_lock); 1222 mutex_unlock(&sn9c102_sysfs_lock);
1098 return -ENODEV; 1223 return -ENODEV;
@@ -1103,7 +1228,7 @@ sn9c102_store_i2c_val(struct class_device* cd, const char* buf, size_t len)
1103 return -ENOSYS; 1228 return -ENOSYS;
1104 } 1229 }
1105 1230
1106 value = sn9c102_strtou8(buf, len, &count); 1231 value = sn9c102_strtou16(buf, len, &count);
1107 if (!count) { 1232 if (!count) {
1108 mutex_unlock(&sn9c102_sysfs_lock); 1233 mutex_unlock(&sn9c102_sysfs_lock);
1109 return -EINVAL; 1234 return -EINVAL;
@@ -1131,13 +1256,14 @@ sn9c102_store_green(struct class_device* cd, const char* buf, size_t len)
1131 struct sn9c102_device* cam; 1256 struct sn9c102_device* cam;
1132 enum sn9c102_bridge bridge; 1257 enum sn9c102_bridge bridge;
1133 ssize_t res = 0; 1258 ssize_t res = 0;
1134 u8 value; 1259 u16 value;
1135 ssize_t count; 1260 ssize_t count;
1136 1261
1137 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 1262 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1138 return -ERESTARTSYS; 1263 return -ERESTARTSYS;
1139 1264
1140 cam = video_get_drvdata(to_video_device(cd)); 1265 cam = video_get_drvdata(container_of(cd, struct video_device,
1266 class_dev));
1141 if (!cam) { 1267 if (!cam) {
1142 mutex_unlock(&sn9c102_sysfs_lock); 1268 mutex_unlock(&sn9c102_sysfs_lock);
1143 return -ENODEV; 1269 return -ENODEV;
@@ -1147,7 +1273,7 @@ sn9c102_store_green(struct class_device* cd, const char* buf, size_t len)
1147 1273
1148 mutex_unlock(&sn9c102_sysfs_lock); 1274 mutex_unlock(&sn9c102_sysfs_lock);
1149 1275
1150 value = sn9c102_strtou8(buf, len, &count); 1276 value = sn9c102_strtou16(buf, len, &count);
1151 if (!count) 1277 if (!count)
1152 return -EINVAL; 1278 return -EINVAL;
1153 1279
@@ -1160,9 +1286,11 @@ sn9c102_store_green(struct class_device* cd, const char* buf, size_t len)
1160 res = sn9c102_store_val(cd, buf, len); 1286 res = sn9c102_store_val(cd, buf, len);
1161 break; 1287 break;
1162 case BRIDGE_SN9C103: 1288 case BRIDGE_SN9C103:
1289 case BRIDGE_SN9C105:
1290 case BRIDGE_SN9C120:
1163 if (value > 0x7f) 1291 if (value > 0x7f)
1164 return -EINVAL; 1292 return -EINVAL;
1165 if ((res = sn9c102_store_reg(cd, "0x04", 4)) >= 0) 1293 if ((res = sn9c102_store_reg(cd, "0x07", 4)) >= 0)
1166 res = sn9c102_store_val(cd, buf, len); 1294 res = sn9c102_store_val(cd, buf, len);
1167 break; 1295 break;
1168 } 1296 }
@@ -1175,10 +1303,10 @@ static ssize_t
1175sn9c102_store_blue(struct class_device* cd, const char* buf, size_t len) 1303sn9c102_store_blue(struct class_device* cd, const char* buf, size_t len)
1176{ 1304{
1177 ssize_t res = 0; 1305 ssize_t res = 0;
1178 u8 value; 1306 u16 value;
1179 ssize_t count; 1307 ssize_t count;
1180 1308
1181 value = sn9c102_strtou8(buf, len, &count); 1309 value = sn9c102_strtou16(buf, len, &count);
1182 if (!count || value > 0x7f) 1310 if (!count || value > 0x7f)
1183 return -EINVAL; 1311 return -EINVAL;
1184 1312
@@ -1193,10 +1321,10 @@ static ssize_t
1193sn9c102_store_red(struct class_device* cd, const char* buf, size_t len) 1321sn9c102_store_red(struct class_device* cd, const char* buf, size_t len)
1194{ 1322{
1195 ssize_t res = 0; 1323 ssize_t res = 0;
1196 u8 value; 1324 u16 value;
1197 ssize_t count; 1325 ssize_t count;
1198 1326
1199 value = sn9c102_strtou8(buf, len, &count); 1327 value = sn9c102_strtou16(buf, len, &count);
1200 if (!count || value > 0x7f) 1328 if (!count || value > 0x7f)
1201 return -EINVAL; 1329 return -EINVAL;
1202 1330
@@ -1212,7 +1340,8 @@ static ssize_t sn9c102_show_frame_header(struct class_device* cd, char* buf)
1212 struct sn9c102_device* cam; 1340 struct sn9c102_device* cam;
1213 ssize_t count; 1341 ssize_t count;
1214 1342
1215 cam = video_get_drvdata(to_video_device(cd)); 1343 cam = video_get_drvdata(container_of(cd, struct video_device,
1344 class_dev));
1216 if (!cam) 1345 if (!cam)
1217 return -ENODEV; 1346 return -ENODEV;
1218 1347
@@ -1243,30 +1372,36 @@ static CLASS_DEVICE_ATTR(frame_header, S_IRUGO,
1243static int sn9c102_create_sysfs(struct sn9c102_device* cam) 1372static int sn9c102_create_sysfs(struct sn9c102_device* cam)
1244{ 1373{
1245 struct video_device *v4ldev = cam->v4ldev; 1374 struct video_device *v4ldev = cam->v4ldev;
1246 int rc; 1375 int err = 0;
1247 1376
1248 rc = video_device_create_file(v4ldev, &class_device_attr_reg); 1377 if ((err = video_device_create_file(v4ldev, &class_device_attr_reg)))
1249 if (rc) goto err; 1378 goto err_out;
1250 rc = video_device_create_file(v4ldev, &class_device_attr_val); 1379 if ((err = video_device_create_file(v4ldev, &class_device_attr_val)))
1251 if (rc) goto err_reg; 1380 goto err_reg;
1252 rc = video_device_create_file(v4ldev, &class_device_attr_frame_header); 1381 if ((err = video_device_create_file(v4ldev,
1253 if (rc) goto err_val; 1382 &class_device_attr_frame_header)))
1383 goto err_val;
1254 1384
1255 if (cam->sensor.sysfs_ops) { 1385 if (cam->sensor.sysfs_ops) {
1256 rc = video_device_create_file(v4ldev, &class_device_attr_i2c_reg); 1386 if ((err = video_device_create_file(v4ldev,
1257 if (rc) goto err_frhead; 1387 &class_device_attr_i2c_reg)))
1258 rc = video_device_create_file(v4ldev, &class_device_attr_i2c_val); 1388 goto err_frame_header;
1259 if (rc) goto err_i2c_reg; 1389 if ((err = video_device_create_file(v4ldev,
1390 &class_device_attr_i2c_val)))
1391 goto err_i2c_reg;
1260 } 1392 }
1261 1393
1262 if (cam->bridge == BRIDGE_SN9C101 || cam->bridge == BRIDGE_SN9C102) { 1394 if (cam->bridge == BRIDGE_SN9C101 || cam->bridge == BRIDGE_SN9C102) {
1263 rc = video_device_create_file(v4ldev, &class_device_attr_green); 1395 if ((err = video_device_create_file(v4ldev,
1264 if (rc) goto err_i2c_val; 1396 &class_device_attr_green)))
1265 } else if (cam->bridge == BRIDGE_SN9C103) { 1397 goto err_i2c_val;
1266 rc = video_device_create_file(v4ldev, &class_device_attr_blue); 1398 } else {
1267 if (rc) goto err_i2c_val; 1399 if ((err = video_device_create_file(v4ldev,
1268 rc = video_device_create_file(v4ldev, &class_device_attr_red); 1400 &class_device_attr_blue)))
1269 if (rc) goto err_blue; 1401 goto err_i2c_val;
1402 if ((err = video_device_create_file(v4ldev,
1403 &class_device_attr_red)))
1404 goto err_blue;
1270 } 1405 }
1271 1406
1272 return 0; 1407 return 0;
@@ -1279,14 +1414,14 @@ err_i2c_val:
1279err_i2c_reg: 1414err_i2c_reg:
1280 if (cam->sensor.sysfs_ops) 1415 if (cam->sensor.sysfs_ops)
1281 video_device_remove_file(v4ldev, &class_device_attr_i2c_reg); 1416 video_device_remove_file(v4ldev, &class_device_attr_i2c_reg);
1282err_frhead: 1417err_frame_header:
1283 video_device_remove_file(v4ldev, &class_device_attr_frame_header); 1418 video_device_remove_file(v4ldev, &class_device_attr_frame_header);
1284err_val: 1419err_val:
1285 video_device_remove_file(v4ldev, &class_device_attr_val); 1420 video_device_remove_file(v4ldev, &class_device_attr_val);
1286err_reg: 1421err_reg:
1287 video_device_remove_file(v4ldev, &class_device_attr_reg); 1422 video_device_remove_file(v4ldev, &class_device_attr_reg);
1288err: 1423err_out:
1289 return rc; 1424 return err;
1290} 1425}
1291#endif /* CONFIG_VIDEO_ADV_DEBUG */ 1426#endif /* CONFIG_VIDEO_ADV_DEBUG */
1292 1427
@@ -1297,10 +1432,36 @@ sn9c102_set_pix_format(struct sn9c102_device* cam, struct v4l2_pix_format* pix)
1297{ 1432{
1298 int err = 0; 1433 int err = 0;
1299 1434
1300 if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X) 1435 if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X ||
1301 err += sn9c102_write_reg(cam, cam->reg[0x18] | 0x80, 0x18); 1436 pix->pixelformat == V4L2_PIX_FMT_JPEG) {
1302 else 1437 switch (cam->bridge) {
1303 err += sn9c102_write_reg(cam, cam->reg[0x18] & 0x7f, 0x18); 1438 case BRIDGE_SN9C101:
1439 case BRIDGE_SN9C102:
1440 case BRIDGE_SN9C103:
1441 err += sn9c102_write_reg(cam, cam->reg[0x18] | 0x80,
1442 0x18);
1443 break;
1444 case BRIDGE_SN9C105:
1445 case BRIDGE_SN9C120:
1446 err += sn9c102_write_reg(cam, cam->reg[0x18] & 0x7f,
1447 0x18);
1448 break;
1449 }
1450 } else {
1451 switch (cam->bridge) {
1452 case BRIDGE_SN9C101:
1453 case BRIDGE_SN9C102:
1454 case BRIDGE_SN9C103:
1455 err += sn9c102_write_reg(cam, cam->reg[0x18] & 0x7f,
1456 0x18);
1457 break;
1458 case BRIDGE_SN9C105:
1459 case BRIDGE_SN9C120:
1460 err += sn9c102_write_reg(cam, cam->reg[0x18] | 0x80,
1461 0x18);
1462 break;
1463 }
1464 }
1304 1465
1305 return err ? -EIO : 0; 1466 return err ? -EIO : 0;
1306} 1467}
@@ -1310,12 +1471,46 @@ static int
1310sn9c102_set_compression(struct sn9c102_device* cam, 1471sn9c102_set_compression(struct sn9c102_device* cam,
1311 struct v4l2_jpegcompression* compression) 1472 struct v4l2_jpegcompression* compression)
1312{ 1473{
1313 int err = 0; 1474 int i, err = 0;
1314 1475
1476 switch (cam->bridge) {
1477 case BRIDGE_SN9C101:
1478 case BRIDGE_SN9C102:
1479 case BRIDGE_SN9C103:
1315 if (compression->quality == 0) 1480 if (compression->quality == 0)
1316 err += sn9c102_write_reg(cam, cam->reg[0x17] | 0x01, 0x17); 1481 err += sn9c102_write_reg(cam, cam->reg[0x17] | 0x01,
1482 0x17);
1317 else if (compression->quality == 1) 1483 else if (compression->quality == 1)
1318 err += sn9c102_write_reg(cam, cam->reg[0x17] & 0xfe, 0x17); 1484 err += sn9c102_write_reg(cam, cam->reg[0x17] & 0xfe,
1485 0x17);
1486 break;
1487 case BRIDGE_SN9C105:
1488 case BRIDGE_SN9C120:
1489 if (compression->quality == 0) {
1490 for (i = 0; i <= 63; i++) {
1491 err += sn9c102_write_reg(cam,
1492 SN9C102_Y_QTABLE0[i],
1493 0x100 + i);
1494 err += sn9c102_write_reg(cam,
1495 SN9C102_UV_QTABLE0[i],
1496 0x140 + i);
1497 }
1498 err += sn9c102_write_reg(cam, cam->reg[0x18] & 0xbf,
1499 0x18);
1500 } else if (compression->quality == 1) {
1501 for (i = 0; i <= 63; i++) {
1502 err += sn9c102_write_reg(cam,
1503 SN9C102_Y_QTABLE1[i],
1504 0x100 + i);
1505 err += sn9c102_write_reg(cam,
1506 SN9C102_UV_QTABLE1[i],
1507 0x140 + i);
1508 }
1509 err += sn9c102_write_reg(cam, cam->reg[0x18] | 0x40,
1510 0x18);
1511 }
1512 break;
1513 }
1319 1514
1320 return err ? -EIO : 0; 1515 return err ? -EIO : 0;
1321} 1516}
@@ -1399,7 +1594,16 @@ static int sn9c102_init(struct sn9c102_device* cam)
1399 } 1594 }
1400 1595
1401 if (!(cam->state & DEV_INITIALIZED)) 1596 if (!(cam->state & DEV_INITIALIZED))
1402 cam->compression.quality = cam->reg[0x17] & 0x01 ? 0 : 1; 1597 if (cam->bridge == BRIDGE_SN9C101 ||
1598 cam->bridge == BRIDGE_SN9C102 ||
1599 cam->bridge == BRIDGE_SN9C103) {
1600 cam->compression.quality = cam->reg[0x17] & 0x01 ?
1601 0 : 1;
1602 } else {
1603 cam->compression.quality = cam->reg[0x18] & 0x40 ?
1604 0 : 1;
1605 err += sn9c102_set_compression(cam, &cam->compression);
1606 }
1403 else 1607 else
1404 err += sn9c102_set_compression(cam, &cam->compression); 1608 err += sn9c102_set_compression(cam, &cam->compression);
1405 err += sn9c102_set_pix_format(cam, &s->pix_format); 1609 err += sn9c102_set_pix_format(cam, &s->pix_format);
@@ -1408,7 +1612,8 @@ static int sn9c102_init(struct sn9c102_device* cam)
1408 if (err) 1612 if (err)
1409 return err; 1613 return err;
1410 1614
1411 if (s->pix_format.pixelformat == V4L2_PIX_FMT_SN9C10X) 1615 if (s->pix_format.pixelformat == V4L2_PIX_FMT_SN9C10X ||
1616 s->pix_format.pixelformat == V4L2_PIX_FMT_JPEG)
1412 DBG(3, "Compressed video format is active, quality %d", 1617 DBG(3, "Compressed video format is active, quality %d",
1413 cam->compression.quality); 1618 cam->compression.quality);
1414 else 1619 else
@@ -1490,6 +1695,7 @@ static int sn9c102_open(struct inode* inode, struct file* filp)
1490 1695
1491 if (cam->users) { 1696 if (cam->users) {
1492 DBG(2, "Device /dev/video%d is busy...", cam->v4ldev->minor); 1697 DBG(2, "Device /dev/video%d is busy...", cam->v4ldev->minor);
1698 DBG(3, "Simultaneous opens are not supported");
1493 if ((filp->f_flags & O_NONBLOCK) || 1699 if ((filp->f_flags & O_NONBLOCK) ||
1494 (filp->f_flags & O_NDELAY)) { 1700 (filp->f_flags & O_NDELAY)) {
1495 err = -EWOULDBLOCK; 1701 err = -EWOULDBLOCK;
@@ -1628,6 +1834,17 @@ sn9c102_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
1628 mutex_unlock(&cam->fileop_mutex); 1834 mutex_unlock(&cam->fileop_mutex);
1629 return -EAGAIN; 1835 return -EAGAIN;
1630 } 1836 }
1837 if (!cam->module_param.frame_timeout) {
1838 err = wait_event_interruptible
1839 ( cam->wait_frame,
1840 (!list_empty(&cam->outqueue)) ||
1841 (cam->state & DEV_DISCONNECTED) ||
1842 (cam->state & DEV_MISCONFIGURED) );
1843 if (err) {
1844 mutex_unlock(&cam->fileop_mutex);
1845 return err;
1846 }
1847 } else {
1631 timeout = wait_event_interruptible_timeout 1848 timeout = wait_event_interruptible_timeout
1632 ( cam->wait_frame, 1849 ( cam->wait_frame,
1633 (!list_empty(&cam->outqueue)) || 1850 (!list_empty(&cam->outqueue)) ||
@@ -1638,12 +1855,18 @@ sn9c102_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
1638 if (timeout < 0) { 1855 if (timeout < 0) {
1639 mutex_unlock(&cam->fileop_mutex); 1856 mutex_unlock(&cam->fileop_mutex);
1640 return timeout; 1857 return timeout;
1858 } else if (timeout == 0 &&
1859 !(cam->state & DEV_DISCONNECTED)) {
1860 DBG(1, "Video frame timeout elapsed");
1861 mutex_unlock(&cam->fileop_mutex);
1862 return -EIO;
1863 }
1641 } 1864 }
1642 if (cam->state & DEV_DISCONNECTED) { 1865 if (cam->state & DEV_DISCONNECTED) {
1643 mutex_unlock(&cam->fileop_mutex); 1866 mutex_unlock(&cam->fileop_mutex);
1644 return -ENODEV; 1867 return -ENODEV;
1645 } 1868 }
1646 if (!timeout || (cam->state & DEV_MISCONFIGURED)) { 1869 if (cam->state & DEV_MISCONFIGURED) {
1647 mutex_unlock(&cam->fileop_mutex); 1870 mutex_unlock(&cam->fileop_mutex);
1648 return -EIO; 1871 return -EIO;
1649 } 1872 }
@@ -1940,6 +2163,9 @@ exit:
1940 if (copy_to_user(arg, &ctrl, sizeof(ctrl))) 2163 if (copy_to_user(arg, &ctrl, sizeof(ctrl)))
1941 return -EFAULT; 2164 return -EFAULT;
1942 2165
2166 PDBGG("VIDIOC_G_CTRL: id %lu, value %lu",
2167 (unsigned long)ctrl.id, (unsigned long)ctrl.value);
2168
1943 return err; 2169 return err;
1944} 2170}
1945 2171
@@ -2127,6 +2353,45 @@ sn9c102_vidioc_s_crop(struct sn9c102_device* cam, void __user * arg)
2127 2353
2128 2354
2129static int 2355static int
2356sn9c102_vidioc_enum_framesizes(struct sn9c102_device* cam, void __user * arg)
2357{
2358 struct v4l2_frmsizeenum frmsize;
2359
2360 if (copy_from_user(&frmsize, arg, sizeof(frmsize)))
2361 return -EFAULT;
2362
2363 if (frmsize.index != 0)
2364 return -EINVAL;
2365
2366 switch (cam->bridge) {
2367 case BRIDGE_SN9C101:
2368 case BRIDGE_SN9C102:
2369 case BRIDGE_SN9C103:
2370 if (frmsize.pixel_format != V4L2_PIX_FMT_SN9C10X &&
2371 frmsize.pixel_format != V4L2_PIX_FMT_SBGGR8)
2372 return -EINVAL;
2373 case BRIDGE_SN9C105:
2374 case BRIDGE_SN9C120:
2375 if (frmsize.pixel_format != V4L2_PIX_FMT_JPEG &&
2376 frmsize.pixel_format != V4L2_PIX_FMT_SBGGR8)
2377 return -EINVAL;
2378 }
2379
2380 frmsize.type = V4L2_FRMSIZE_TYPE_STEPWISE;
2381 frmsize.stepwise.min_width = frmsize.stepwise.step_width = 16;
2382 frmsize.stepwise.min_height = frmsize.stepwise.step_height = 16;
2383 frmsize.stepwise.max_width = cam->sensor.cropcap.bounds.width;
2384 frmsize.stepwise.max_height = cam->sensor.cropcap.bounds.height;
2385 memset(&frmsize.reserved, 0, sizeof(frmsize.reserved));
2386
2387 if (copy_to_user(arg, &frmsize, sizeof(frmsize)))
2388 return -EFAULT;
2389
2390 return 0;
2391}
2392
2393
2394static int
2130sn9c102_vidioc_enum_fmt(struct sn9c102_device* cam, void __user * arg) 2395sn9c102_vidioc_enum_fmt(struct sn9c102_device* cam, void __user * arg)
2131{ 2396{
2132 struct v4l2_fmtdesc fmtd; 2397 struct v4l2_fmtdesc fmtd;
@@ -2134,12 +2399,26 @@ sn9c102_vidioc_enum_fmt(struct sn9c102_device* cam, void __user * arg)
2134 if (copy_from_user(&fmtd, arg, sizeof(fmtd))) 2399 if (copy_from_user(&fmtd, arg, sizeof(fmtd)))
2135 return -EFAULT; 2400 return -EFAULT;
2136 2401
2402 if (fmtd.type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
2403 return -EINVAL;
2404
2137 if (fmtd.index == 0) { 2405 if (fmtd.index == 0) {
2138 strcpy(fmtd.description, "bayer rgb"); 2406 strcpy(fmtd.description, "bayer rgb");
2139 fmtd.pixelformat = V4L2_PIX_FMT_SBGGR8; 2407 fmtd.pixelformat = V4L2_PIX_FMT_SBGGR8;
2140 } else if (fmtd.index == 1) { 2408 } else if (fmtd.index == 1) {
2409 switch (cam->bridge) {
2410 case BRIDGE_SN9C101:
2411 case BRIDGE_SN9C102:
2412 case BRIDGE_SN9C103:
2141 strcpy(fmtd.description, "compressed"); 2413 strcpy(fmtd.description, "compressed");
2142 fmtd.pixelformat = V4L2_PIX_FMT_SN9C10X; 2414 fmtd.pixelformat = V4L2_PIX_FMT_SN9C10X;
2415 break;
2416 case BRIDGE_SN9C105:
2417 case BRIDGE_SN9C120:
2418 strcpy(fmtd.description, "JPEG");
2419 fmtd.pixelformat = V4L2_PIX_FMT_JPEG;
2420 break;
2421 }
2143 fmtd.flags = V4L2_FMT_FLAG_COMPRESSED; 2422 fmtd.flags = V4L2_FMT_FLAG_COMPRESSED;
2144 } else 2423 } else
2145 return -EINVAL; 2424 return -EINVAL;
@@ -2166,7 +2445,8 @@ sn9c102_vidioc_g_fmt(struct sn9c102_device* cam, void __user * arg)
2166 if (format.type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 2445 if (format.type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
2167 return -EINVAL; 2446 return -EINVAL;
2168 2447
2169 pfmt->bytesperline = (pfmt->pixelformat==V4L2_PIX_FMT_SN9C10X) 2448 pfmt->bytesperline = (pfmt->pixelformat==V4L2_PIX_FMT_SN9C10X ||
2449 pfmt->pixelformat==V4L2_PIX_FMT_JPEG)
2170 ? 0 : (pfmt->width * pfmt->priv) / 8; 2450 ? 0 : (pfmt->width * pfmt->priv) / 8;
2171 pfmt->sizeimage = pfmt->height * ((pfmt->width*pfmt->priv)/8); 2451 pfmt->sizeimage = pfmt->height * ((pfmt->width*pfmt->priv)/8);
2172 pfmt->field = V4L2_FIELD_NONE; 2452 pfmt->field = V4L2_FIELD_NONE;
@@ -2237,12 +2517,25 @@ sn9c102_vidioc_try_s_fmt(struct sn9c102_device* cam, unsigned int cmd,
2237 pix->width = rect.width / scale; 2517 pix->width = rect.width / scale;
2238 pix->height = rect.height / scale; 2518 pix->height = rect.height / scale;
2239 2519
2520 switch (cam->bridge) {
2521 case BRIDGE_SN9C101:
2522 case BRIDGE_SN9C102:
2523 case BRIDGE_SN9C103:
2240 if (pix->pixelformat != V4L2_PIX_FMT_SN9C10X && 2524 if (pix->pixelformat != V4L2_PIX_FMT_SN9C10X &&
2241 pix->pixelformat != V4L2_PIX_FMT_SBGGR8) 2525 pix->pixelformat != V4L2_PIX_FMT_SBGGR8)
2242 pix->pixelformat = pfmt->pixelformat; 2526 pix->pixelformat = pfmt->pixelformat;
2527 break;
2528 case BRIDGE_SN9C105:
2529 case BRIDGE_SN9C120:
2530 if (pix->pixelformat != V4L2_PIX_FMT_JPEG &&
2531 pix->pixelformat != V4L2_PIX_FMT_SBGGR8)
2532 pix->pixelformat = pfmt->pixelformat;
2533 break;
2534 }
2243 pix->priv = pfmt->priv; /* bpp */ 2535 pix->priv = pfmt->priv; /* bpp */
2244 pix->colorspace = pfmt->colorspace; 2536 pix->colorspace = pfmt->colorspace;
2245 pix->bytesperline = (pix->pixelformat == V4L2_PIX_FMT_SN9C10X) 2537 pix->bytesperline = (pix->pixelformat == V4L2_PIX_FMT_SN9C10X ||
2538 pix->pixelformat == V4L2_PIX_FMT_JPEG)
2246 ? 0 : (pix->width * pix->priv) / 8; 2539 ? 0 : (pix->width * pix->priv) / 8;
2247 pix->sizeimage = pix->height * ((pix->width * pix->priv) / 8); 2540 pix->sizeimage = pix->height * ((pix->width * pix->priv) / 8);
2248 pix->field = V4L2_FIELD_NONE; 2541 pix->field = V4L2_FIELD_NONE;
@@ -2315,8 +2608,7 @@ sn9c102_vidioc_try_s_fmt(struct sn9c102_device* cam, unsigned int cmd,
2315static int 2608static int
2316sn9c102_vidioc_g_jpegcomp(struct sn9c102_device* cam, void __user * arg) 2609sn9c102_vidioc_g_jpegcomp(struct sn9c102_device* cam, void __user * arg)
2317{ 2610{
2318 if (copy_to_user(arg, &cam->compression, 2611 if (copy_to_user(arg, &cam->compression, sizeof(cam->compression)))
2319 sizeof(cam->compression)))
2320 return -EFAULT; 2612 return -EFAULT;
2321 2613
2322 return 0; 2614 return 0;
@@ -2471,6 +2763,7 @@ sn9c102_vidioc_dqbuf(struct sn9c102_device* cam, struct file* filp,
2471 struct sn9c102_frame_t *f; 2763 struct sn9c102_frame_t *f;
2472 unsigned long lock_flags; 2764 unsigned long lock_flags;
2473 long timeout; 2765 long timeout;
2766 int err = 0;
2474 2767
2475 if (copy_from_user(&b, arg, sizeof(b))) 2768 if (copy_from_user(&b, arg, sizeof(b)))
2476 return -EFAULT; 2769 return -EFAULT;
@@ -2483,6 +2776,15 @@ sn9c102_vidioc_dqbuf(struct sn9c102_device* cam, struct file* filp,
2483 return -EINVAL; 2776 return -EINVAL;
2484 if (filp->f_flags & O_NONBLOCK) 2777 if (filp->f_flags & O_NONBLOCK)
2485 return -EAGAIN; 2778 return -EAGAIN;
2779 if (!cam->module_param.frame_timeout) {
2780 err = wait_event_interruptible
2781 ( cam->wait_frame,
2782 (!list_empty(&cam->outqueue)) ||
2783 (cam->state & DEV_DISCONNECTED) ||
2784 (cam->state & DEV_MISCONFIGURED) );
2785 if (err)
2786 return err;
2787 } else {
2486 timeout = wait_event_interruptible_timeout 2788 timeout = wait_event_interruptible_timeout
2487 ( cam->wait_frame, 2789 ( cam->wait_frame,
2488 (!list_empty(&cam->outqueue)) || 2790 (!list_empty(&cam->outqueue)) ||
@@ -2492,9 +2794,15 @@ sn9c102_vidioc_dqbuf(struct sn9c102_device* cam, struct file* filp,
2492 1000 * msecs_to_jiffies(1) ); 2794 1000 * msecs_to_jiffies(1) );
2493 if (timeout < 0) 2795 if (timeout < 0)
2494 return timeout; 2796 return timeout;
2797 else if (timeout == 0 &&
2798 !(cam->state & DEV_DISCONNECTED)) {
2799 DBG(1, "Video frame timeout elapsed");
2800 return -EIO;
2801 }
2802 }
2495 if (cam->state & DEV_DISCONNECTED) 2803 if (cam->state & DEV_DISCONNECTED)
2496 return -ENODEV; 2804 return -ENODEV;
2497 if (!timeout || (cam->state & DEV_MISCONFIGURED)) 2805 if (cam->state & DEV_MISCONFIGURED)
2498 return -EIO; 2806 return -EIO;
2499 } 2807 }
2500 2808
@@ -2612,6 +2920,70 @@ sn9c102_vidioc_s_parm(struct sn9c102_device* cam, void __user * arg)
2612} 2920}
2613 2921
2614 2922
2923static int
2924sn9c102_vidioc_enumaudio(struct sn9c102_device* cam, void __user * arg)
2925{
2926 struct v4l2_audio audio;
2927
2928 if (cam->bridge == BRIDGE_SN9C101 || cam->bridge == BRIDGE_SN9C102)
2929 return -EINVAL;
2930
2931 if (copy_from_user(&audio, arg, sizeof(audio)))
2932 return -EFAULT;
2933
2934 if (audio.index != 0)
2935 return -EINVAL;
2936
2937 strcpy(audio.name, "Microphone");
2938 audio.capability = 0;
2939 audio.mode = 0;
2940
2941 if (copy_to_user(arg, &audio, sizeof(audio)))
2942 return -EFAULT;
2943
2944 return 0;
2945}
2946
2947
2948static int
2949sn9c102_vidioc_g_audio(struct sn9c102_device* cam, void __user * arg)
2950{
2951 struct v4l2_audio audio;
2952
2953 if (cam->bridge == BRIDGE_SN9C101 || cam->bridge == BRIDGE_SN9C102)
2954 return -EINVAL;
2955
2956 if (copy_from_user(&audio, arg, sizeof(audio)))
2957 return -EFAULT;
2958
2959 memset(&audio, 0, sizeof(audio));
2960 strcpy(audio.name, "Microphone");
2961
2962 if (copy_to_user(arg, &audio, sizeof(audio)))
2963 return -EFAULT;
2964
2965 return 0;
2966}
2967
2968
2969static int
2970sn9c102_vidioc_s_audio(struct sn9c102_device* cam, void __user * arg)
2971{
2972 struct v4l2_audio audio;
2973
2974 if (cam->bridge == BRIDGE_SN9C101 || cam->bridge == BRIDGE_SN9C102)
2975 return -EINVAL;
2976
2977 if (copy_from_user(&audio, arg, sizeof(audio)))
2978 return -EFAULT;
2979
2980 if (audio.index != 0)
2981 return -EINVAL;
2982
2983 return 0;
2984}
2985
2986
2615static int sn9c102_ioctl_v4l2(struct inode* inode, struct file* filp, 2987static int sn9c102_ioctl_v4l2(struct inode* inode, struct file* filp,
2616 unsigned int cmd, void __user * arg) 2988 unsigned int cmd, void __user * arg)
2617{ 2989{
@@ -2649,6 +3021,9 @@ static int sn9c102_ioctl_v4l2(struct inode* inode, struct file* filp,
2649 case VIDIOC_S_CROP: 3021 case VIDIOC_S_CROP:
2650 return sn9c102_vidioc_s_crop(cam, arg); 3022 return sn9c102_vidioc_s_crop(cam, arg);
2651 3023
3024 case VIDIOC_ENUM_FRAMESIZES:
3025 return sn9c102_vidioc_enum_framesizes(cam, arg);
3026
2652 case VIDIOC_ENUM_FMT: 3027 case VIDIOC_ENUM_FMT:
2653 return sn9c102_vidioc_enum_fmt(cam, arg); 3028 return sn9c102_vidioc_enum_fmt(cam, arg);
2654 3029
@@ -2689,11 +3064,21 @@ static int sn9c102_ioctl_v4l2(struct inode* inode, struct file* filp,
2689 case VIDIOC_S_PARM: 3064 case VIDIOC_S_PARM:
2690 return sn9c102_vidioc_s_parm(cam, arg); 3065 return sn9c102_vidioc_s_parm(cam, arg);
2691 3066
3067 case VIDIOC_ENUMAUDIO:
3068 return sn9c102_vidioc_enumaudio(cam, arg);
3069
3070 case VIDIOC_G_AUDIO:
3071 return sn9c102_vidioc_g_audio(cam, arg);
3072
3073 case VIDIOC_S_AUDIO:
3074 return sn9c102_vidioc_s_audio(cam, arg);
3075
2692 case VIDIOC_G_STD: 3076 case VIDIOC_G_STD:
2693 case VIDIOC_S_STD: 3077 case VIDIOC_S_STD:
2694 case VIDIOC_QUERYSTD: 3078 case VIDIOC_QUERYSTD:
2695 case VIDIOC_ENUMSTD: 3079 case VIDIOC_ENUMSTD:
2696 case VIDIOC_QUERYMENU: 3080 case VIDIOC_QUERYMENU:
3081 case VIDIOC_ENUM_FRAMEINTERVALS:
2697 return -EINVAL; 3082 return -EINVAL;
2698 3083
2699 default: 3084 default:
@@ -2741,6 +3126,7 @@ static const struct file_operations sn9c102_fops = {
2741 .open = sn9c102_open, 3126 .open = sn9c102_open,
2742 .release = sn9c102_release, 3127 .release = sn9c102_release,
2743 .ioctl = sn9c102_ioctl, 3128 .ioctl = sn9c102_ioctl,
3129 .compat_ioctl = v4l_compat_ioctl32,
2744 .read = sn9c102_read, 3130 .read = sn9c102_read,
2745 .poll = sn9c102_poll, 3131 .poll = sn9c102_poll,
2746 .mmap = sn9c102_mmap, 3132 .mmap = sn9c102_mmap,
@@ -2765,7 +3151,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2765 cam->usbdev = udev; 3151 cam->usbdev = udev;
2766 3152
2767 if (!(cam->control_buffer = kzalloc(8, GFP_KERNEL))) { 3153 if (!(cam->control_buffer = kzalloc(8, GFP_KERNEL))) {
2768 DBG(1, "kmalloc() failed"); 3154 DBG(1, "kzalloc() failed");
2769 err = -ENOMEM; 3155 err = -ENOMEM;
2770 goto fail; 3156 goto fail;
2771 } 3157 }
@@ -2779,24 +3165,31 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2779 mutex_init(&cam->dev_mutex); 3165 mutex_init(&cam->dev_mutex);
2780 3166
2781 r = sn9c102_read_reg(cam, 0x00); 3167 r = sn9c102_read_reg(cam, 0x00);
2782 if (r < 0 || r != 0x10) { 3168 if (r < 0 || (r != 0x10 && r != 0x11 && r != 0x12)) {
2783 DBG(1, "Sorry, this is not a SN9C10x based camera " 3169 DBG(1, "Sorry, this is not a SN9C1xx based camera "
2784 "(vid/pid 0x%04X/0x%04X)", id->idVendor, id->idProduct); 3170 "(vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct);
2785 err = -ENODEV; 3171 err = -ENODEV;
2786 goto fail; 3172 goto fail;
2787 } 3173 }
2788 3174
2789 cam->bridge = (id->idProduct & 0xffc0) == 0x6080 ? 3175 cam->bridge = id->driver_info;
2790 BRIDGE_SN9C103 : BRIDGE_SN9C102;
2791 switch (cam->bridge) { 3176 switch (cam->bridge) {
2792 case BRIDGE_SN9C101: 3177 case BRIDGE_SN9C101:
2793 case BRIDGE_SN9C102: 3178 case BRIDGE_SN9C102:
2794 DBG(2, "SN9C10[12] PC Camera Controller detected " 3179 DBG(2, "SN9C10[12] PC Camera Controller detected "
2795 "(vid/pid 0x%04X/0x%04X)", id->idVendor, id->idProduct); 3180 "(vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct);
2796 break; 3181 break;
2797 case BRIDGE_SN9C103: 3182 case BRIDGE_SN9C103:
2798 DBG(2, "SN9C103 PC Camera Controller detected " 3183 DBG(2, "SN9C103 PC Camera Controller detected "
2799 "(vid/pid 0x%04X/0x%04X)", id->idVendor, id->idProduct); 3184 "(vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct);
3185 break;
3186 case BRIDGE_SN9C105:
3187 DBG(2, "SN9C105 PC Camera Controller detected "
3188 "(vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct);
3189 break;
3190 case BRIDGE_SN9C120:
3191 DBG(2, "SN9C120 PC Camera Controller detected "
3192 "(vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct);
2800 break; 3193 break;
2801 } 3194 }
2802 3195
@@ -2816,12 +3209,18 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2816 goto fail; 3209 goto fail;
2817 } 3210 }
2818 3211
3212 if (!(cam->bridge & cam->sensor.supported_bridge)) {
3213 DBG(1, "Bridge not supported");
3214 err = -ENODEV;
3215 goto fail;
3216 }
3217
2819 if (sn9c102_init(cam)) { 3218 if (sn9c102_init(cam)) {
2820 DBG(1, "Initialization failed. I will retry on open()."); 3219 DBG(1, "Initialization failed. I will retry on open().");
2821 cam->state |= DEV_MISCONFIGURED; 3220 cam->state |= DEV_MISCONFIGURED;
2822 } 3221 }
2823 3222
2824 strcpy(cam->v4ldev->name, "SN9C10x PC Camera"); 3223 strcpy(cam->v4ldev->name, "SN9C1xx PC Camera");
2825 cam->v4ldev->owner = THIS_MODULE; 3224 cam->v4ldev->owner = THIS_MODULE;
2826 cam->v4ldev->type = VID_TYPE_CAPTURE | VID_TYPE_SCALES; 3225 cam->v4ldev->type = VID_TYPE_CAPTURE | VID_TYPE_SCALES;
2827 cam->v4ldev->hardware = 0; 3226 cam->v4ldev->hardware = 0;
@@ -2838,7 +3237,10 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2838 DBG(1, "V4L2 device registration failed"); 3237 DBG(1, "V4L2 device registration failed");
2839 if (err == -ENFILE && video_nr[dev_nr] == -1) 3238 if (err == -ENFILE && video_nr[dev_nr] == -1)
2840 DBG(1, "Free /dev/videoX node not found"); 3239 DBG(1, "Free /dev/videoX node not found");
2841 goto fail2; 3240 video_nr[dev_nr] = -1;
3241 dev_nr = (dev_nr < SN9C102_MAX_DEVICES-1) ? dev_nr+1 : 0;
3242 mutex_unlock(&cam->dev_mutex);
3243 goto fail;
2842 } 3244 }
2843 3245
2844 DBG(2, "V4L2 device registered as /dev/video%d", cam->v4ldev->minor); 3246 DBG(2, "V4L2 device registered as /dev/video%d", cam->v4ldev->minor);
@@ -2850,9 +3252,14 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2850 3252
2851#ifdef CONFIG_VIDEO_ADV_DEBUG 3253#ifdef CONFIG_VIDEO_ADV_DEBUG
2852 err = sn9c102_create_sysfs(cam); 3254 err = sn9c102_create_sysfs(cam);
2853 if (err) 3255 if (!err)
2854 goto fail3; 3256 DBG(2, "Optional device control through 'sysfs' "
2855 DBG(2, "Optional device control through 'sysfs' interface ready"); 3257 "interface ready");
3258 else
3259 DBG(2, "Failed to create optional 'sysfs' interface for "
3260 "device controlling. Error #%d", err);
3261#else
3262 DBG(2, "Optional device control through 'sysfs' interface disabled");
2856#endif 3263#endif
2857 3264
2858 usb_set_intfdata(intf, cam); 3265 usb_set_intfdata(intf, cam);
@@ -2861,14 +3268,6 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2861 3268
2862 return 0; 3269 return 0;
2863 3270
2864#ifdef CONFIG_VIDEO_ADV_DEBUG
2865fail3:
2866 video_unregister_device(cam->v4ldev);
2867#endif
2868fail2:
2869 video_nr[dev_nr] = -1;
2870 dev_nr = (dev_nr < SN9C102_MAX_DEVICES-1) ? dev_nr+1 : 0;
2871 mutex_unlock(&cam->dev_mutex);
2872fail: 3271fail:
2873 if (cam) { 3272 if (cam) {
2874 kfree(cam->control_buffer); 3273 kfree(cam->control_buffer);
diff --git a/drivers/media/video/sn9c102/sn9c102_devtable.h b/drivers/media/video/sn9c102/sn9c102_devtable.h
new file mode 100644
index 0000000000..3a682eca6c
--- /dev/null
+++ b/drivers/media/video/sn9c102/sn9c102_devtable.h
@@ -0,0 +1,142 @@
1/***************************************************************************
2 * Table of device identifiers of the SN9C1xx PC Camera Controllers *
3 * *
4 * Copyright (C) 2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
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#ifndef _SN9C102_DEVTABLE_H_
22#define _SN9C102_DEVTABLE_H_
23
24#include <linux/usb.h>
25
26struct sn9c102_device;
27
28/*
29 Each SN9C1xx camera has proper PID/VID identifiers.
30 SN9C103, SN9C105, SN9C120 support multiple interfaces, but we only have to
31 handle the video class interface.
32*/
33#define SN9C102_USB_DEVICE(vend, prod, bridge) \
34 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
35 USB_DEVICE_ID_MATCH_INT_CLASS, \
36 .idVendor = (vend), \
37 .idProduct = (prod), \
38 .bInterfaceClass = 0xff, \
39 .driver_info = (bridge)
40
41static const struct usb_device_id sn9c102_id_table[] = {
42 /* SN9C101 and SN9C102 */
43 { SN9C102_USB_DEVICE(0x0c45, 0x6001, BRIDGE_SN9C102), },
44 { SN9C102_USB_DEVICE(0x0c45, 0x6005, BRIDGE_SN9C102), },
45 { SN9C102_USB_DEVICE(0x0c45, 0x6007, BRIDGE_SN9C102), },
46 { SN9C102_USB_DEVICE(0x0c45, 0x6009, BRIDGE_SN9C102), },
47 { SN9C102_USB_DEVICE(0x0c45, 0x6011, BRIDGE_SN9C102), },
48 { SN9C102_USB_DEVICE(0x0c45, 0x600d, BRIDGE_SN9C102), },
49 { SN9C102_USB_DEVICE(0x0c45, 0x6019, BRIDGE_SN9C102), },
50 { SN9C102_USB_DEVICE(0x0c45, 0x6024, BRIDGE_SN9C102), },
51 { SN9C102_USB_DEVICE(0x0c45, 0x6025, BRIDGE_SN9C102), },
52 { SN9C102_USB_DEVICE(0x0c45, 0x6028, BRIDGE_SN9C102), },
53 { SN9C102_USB_DEVICE(0x0c45, 0x6029, BRIDGE_SN9C102), },
54 { SN9C102_USB_DEVICE(0x0c45, 0x602a, BRIDGE_SN9C102), },
55 { SN9C102_USB_DEVICE(0x0c45, 0x602b, BRIDGE_SN9C102), },
56 { SN9C102_USB_DEVICE(0x0c45, 0x602c, BRIDGE_SN9C102), },
57 { SN9C102_USB_DEVICE(0x0c45, 0x602d, BRIDGE_SN9C102), },
58 { SN9C102_USB_DEVICE(0x0c45, 0x602e, BRIDGE_SN9C102), },
59 { SN9C102_USB_DEVICE(0x0c45, 0x6030, BRIDGE_SN9C102), },
60 { SN9C102_USB_DEVICE(0x0c45, 0x603f, BRIDGE_SN9C102), },
61 /* SN9C103 */
62 { SN9C102_USB_DEVICE(0x0c45, 0x6080, BRIDGE_SN9C103), },
63 { SN9C102_USB_DEVICE(0x0c45, 0x6082, BRIDGE_SN9C103), },
64 { SN9C102_USB_DEVICE(0x0c45, 0x6083, BRIDGE_SN9C103), },
65 { SN9C102_USB_DEVICE(0x0c45, 0x6088, BRIDGE_SN9C103), },
66 { SN9C102_USB_DEVICE(0x0c45, 0x608a, BRIDGE_SN9C103), },
67 { SN9C102_USB_DEVICE(0x0c45, 0x608b, BRIDGE_SN9C103), },
68 { SN9C102_USB_DEVICE(0x0c45, 0x608c, BRIDGE_SN9C103), },
69 { SN9C102_USB_DEVICE(0x0c45, 0x608e, BRIDGE_SN9C103), },
70 { SN9C102_USB_DEVICE(0x0c45, 0x608f, BRIDGE_SN9C103), },
71 { SN9C102_USB_DEVICE(0x0c45, 0x60a0, BRIDGE_SN9C103), },
72 { SN9C102_USB_DEVICE(0x0c45, 0x60a2, BRIDGE_SN9C103), },
73 { SN9C102_USB_DEVICE(0x0c45, 0x60a3, BRIDGE_SN9C103), },
74 { SN9C102_USB_DEVICE(0x0c45, 0x60a8, BRIDGE_SN9C103), },
75 { SN9C102_USB_DEVICE(0x0c45, 0x60aa, BRIDGE_SN9C103), },
76 { SN9C102_USB_DEVICE(0x0c45, 0x60ab, BRIDGE_SN9C103), },
77 { SN9C102_USB_DEVICE(0x0c45, 0x60ac, BRIDGE_SN9C103), },
78 { SN9C102_USB_DEVICE(0x0c45, 0x60ae, BRIDGE_SN9C103), },
79 { SN9C102_USB_DEVICE(0x0c45, 0x60af, BRIDGE_SN9C103), },
80 { SN9C102_USB_DEVICE(0x0c45, 0x60b0, BRIDGE_SN9C103), },
81 { SN9C102_USB_DEVICE(0x0c45, 0x60b2, BRIDGE_SN9C103), },
82 { SN9C102_USB_DEVICE(0x0c45, 0x60b3, BRIDGE_SN9C103), },
83 { SN9C102_USB_DEVICE(0x0c45, 0x60b8, BRIDGE_SN9C103), },
84 { SN9C102_USB_DEVICE(0x0c45, 0x60ba, BRIDGE_SN9C103), },
85 { SN9C102_USB_DEVICE(0x0c45, 0x60bb, BRIDGE_SN9C103), },
86 { SN9C102_USB_DEVICE(0x0c45, 0x60bc, BRIDGE_SN9C103), },
87 { SN9C102_USB_DEVICE(0x0c45, 0x60be, BRIDGE_SN9C103), },
88 /* SN9C105 */
89 { SN9C102_USB_DEVICE(0x0471, 0x0327, BRIDGE_SN9C105), },
90 { SN9C102_USB_DEVICE(0x0471, 0x0328, BRIDGE_SN9C105), },
91 { SN9C102_USB_DEVICE(0x0c45, 0x60c0, BRIDGE_SN9C105), },
92 { SN9C102_USB_DEVICE(0x0c45, 0x60c8, BRIDGE_SN9C105), },
93 { SN9C102_USB_DEVICE(0x0c45, 0x60cc, BRIDGE_SN9C105), },
94 { SN9C102_USB_DEVICE(0x0c45, 0x60ea, BRIDGE_SN9C105), },
95 { SN9C102_USB_DEVICE(0x0c45, 0x60ec, BRIDGE_SN9C105), },
96 { SN9C102_USB_DEVICE(0x0c45, 0x60fa, BRIDGE_SN9C105), },
97 { SN9C102_USB_DEVICE(0x0c45, 0x60fb, BRIDGE_SN9C105), },
98 { SN9C102_USB_DEVICE(0x0c45, 0x60fc, BRIDGE_SN9C105), },
99 { SN9C102_USB_DEVICE(0x0c45, 0x60fe, BRIDGE_SN9C105), },
100 /* SN9C120 */
101 { SN9C102_USB_DEVICE(0x0c45, 0x6130, BRIDGE_SN9C120), },
102 { SN9C102_USB_DEVICE(0x0c45, 0x613a, BRIDGE_SN9C120), },
103 { SN9C102_USB_DEVICE(0x0c45, 0x613b, BRIDGE_SN9C120), },
104 { SN9C102_USB_DEVICE(0x0c45, 0x613c, BRIDGE_SN9C120), },
105 { SN9C102_USB_DEVICE(0x0c45, 0x613e, BRIDGE_SN9C120), },
106 { }
107};
108
109/*
110 Probing functions: on success, you must attach the sensor to the camera
111 by calling sn9c102_attach_sensor().
112 To enable the I2C communication, you might need to perform a really basic
113 initialization of the SN9C1XX chip.
114 Functions must return 0 on success, the appropriate error otherwise.
115*/
116extern int sn9c102_probe_hv7131d(struct sn9c102_device* cam);
117extern int sn9c102_probe_mi0343(struct sn9c102_device* cam);
118extern int sn9c102_probe_ov7630(struct sn9c102_device* cam);
119extern int sn9c102_probe_ov7660(struct sn9c102_device* cam);
120extern int sn9c102_probe_pas106b(struct sn9c102_device* cam);
121extern int sn9c102_probe_pas202bcb(struct sn9c102_device* cam);
122extern int sn9c102_probe_tas5110c1b(struct sn9c102_device* cam);
123extern int sn9c102_probe_tas5130d1b(struct sn9c102_device* cam);
124
125/*
126 Add the above entries to this table. Be sure to add the entry in the right
127 place, since, on failure, the next probing routine is called according to
128 the order of the list below, from top to bottom.
129*/
130static int (*sn9c102_sensor_table[])(struct sn9c102_device*) = {
131 &sn9c102_probe_mi0343, /* strong detection based on SENSOR ids */
132 &sn9c102_probe_pas106b, /* strong detection based on SENSOR ids */
133 &sn9c102_probe_pas202bcb, /* strong detection based on SENSOR ids */
134 &sn9c102_probe_hv7131d, /* strong detection based on SENSOR ids */
135 &sn9c102_probe_ov7630, /* strong detection based on SENSOR ids */
136 &sn9c102_probe_ov7660, /* strong detection based on SENSOR ids */
137 &sn9c102_probe_tas5110c1b, /* detection based on USB pid/vid */
138 &sn9c102_probe_tas5130d1b, /* detection based on USB pid/vid */
139 NULL,
140};
141
142#endif /* _SN9C102_DEVTABLE_H_ */
diff --git a/drivers/media/video/sn9c102/sn9c102_hv7131d.c b/drivers/media/video/sn9c102/sn9c102_hv7131d.c
index c4117bf64b..7ae368f60d 100644
--- a/drivers/media/video/sn9c102/sn9c102_hv7131d.c
+++ b/drivers/media/video/sn9c102/sn9c102_hv7131d.c
@@ -1,8 +1,8 @@
1/*************************************************************************** 1/***************************************************************************
2 * Plug-in for HV7131D image sensor connected to the SN9C10x PC Camera * 2 * Plug-in for HV7131D image sensor connected to the SN9C1xx PC Camera *
3 * Controllers * 3 * Controllers *
4 * * 4 * *
5 * Copyright (C) 2004-2006 by Luca Risolia <luca.risolia@studio.unibo.it> * 5 * Copyright (C) 2004-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
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 *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
@@ -124,7 +124,7 @@ static int hv7131d_set_ctrl(struct sn9c102_device* cam,
124static int hv7131d_set_crop(struct sn9c102_device* cam, 124static int hv7131d_set_crop(struct sn9c102_device* cam,
125 const struct v4l2_rect* rect) 125 const struct v4l2_rect* rect)
126{ 126{
127 struct sn9c102_sensor* s = &hv7131d; 127 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
128 int err = 0; 128 int err = 0;
129 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 2, 129 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 2,
130 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 2; 130 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 2;
@@ -153,6 +153,7 @@ static int hv7131d_set_pix_format(struct sn9c102_device* cam,
153static struct sn9c102_sensor hv7131d = { 153static struct sn9c102_sensor hv7131d = {
154 .name = "HV7131D", 154 .name = "HV7131D",
155 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 155 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
156 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102 | BRIDGE_SN9C103,
156 .sysfs_ops = SN9C102_I2C_READ | SN9C102_I2C_WRITE, 157 .sysfs_ops = SN9C102_I2C_READ | SN9C102_I2C_WRITE,
157 .frequency = SN9C102_I2C_100KHZ, 158 .frequency = SN9C102_I2C_100KHZ,
158 .interface = SN9C102_I2C_2WIRES, 159 .interface = SN9C102_I2C_2WIRES,
diff --git a/drivers/media/video/sn9c102/sn9c102_mi0343.c b/drivers/media/video/sn9c102/sn9c102_mi0343.c
index 4169ea4a2e..a33d1bc10f 100644
--- a/drivers/media/video/sn9c102/sn9c102_mi0343.c
+++ b/drivers/media/video/sn9c102/sn9c102_mi0343.c
@@ -1,8 +1,8 @@
1/*************************************************************************** 1/***************************************************************************
2 * Plug-in for MI-0343 image sensor connected to the SN9C10x PC Camera * 2 * Plug-in for MI-0343 image sensor connected to the SN9C1xx PC Camera *
3 * Controllers * 3 * Controllers *
4 * * 4 * *
5 * Copyright (C) 2004-2006 by Luca Risolia <luca.risolia@studio.unibo.it> * 5 * Copyright (C) 2004-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
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 *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
@@ -201,7 +201,7 @@ static int mi0343_set_ctrl(struct sn9c102_device* cam,
201static int mi0343_set_crop(struct sn9c102_device* cam, 201static int mi0343_set_crop(struct sn9c102_device* cam,
202 const struct v4l2_rect* rect) 202 const struct v4l2_rect* rect)
203{ 203{
204 struct sn9c102_sensor* s = &mi0343; 204 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
205 int err = 0; 205 int err = 0;
206 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 0, 206 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 0,
207 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 2; 207 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 2;
@@ -237,6 +237,7 @@ static int mi0343_set_pix_format(struct sn9c102_device* cam,
237static struct sn9c102_sensor mi0343 = { 237static struct sn9c102_sensor mi0343 = {
238 .name = "MI-0343", 238 .name = "MI-0343",
239 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 239 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
240 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102 | BRIDGE_SN9C103,
240 .frequency = SN9C102_I2C_100KHZ, 241 .frequency = SN9C102_I2C_100KHZ,
241 .interface = SN9C102_I2C_2WIRES, 242 .interface = SN9C102_I2C_2WIRES,
242 .i2c_slave_id = 0x5d, 243 .i2c_slave_id = 0x5d,
diff --git a/drivers/media/video/sn9c102/sn9c102_ov7630.c b/drivers/media/video/sn9c102/sn9c102_ov7630.c
index 3da0420217..7df09ff38e 100644
--- a/drivers/media/video/sn9c102/sn9c102_ov7630.c
+++ b/drivers/media/video/sn9c102/sn9c102_ov7630.c
@@ -1,8 +1,8 @@
1/*************************************************************************** 1/***************************************************************************
2 * Plug-in for OV7630 image sensor connected to the SN9C10x PC Camera * 2 * Plug-in for OV7630 image sensor connected to the SN9C1xx PC Camera *
3 * Controllers * 3 * Controllers *
4 * * 4 * *
5 * Copyright (C) 2005-2006 by Luca Risolia <luca.risolia@studio.unibo.it> * 5 * Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
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 *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
@@ -29,13 +29,17 @@ static int ov7630_init(struct sn9c102_device* cam)
29{ 29{
30 int err = 0; 30 int err = 0;
31 31
32 switch (sn9c102_get_bridge(cam)) {
33 case BRIDGE_SN9C101:
34 case BRIDGE_SN9C102:
32 err += sn9c102_write_reg(cam, 0x00, 0x14); 35 err += sn9c102_write_reg(cam, 0x00, 0x14);
33 err += sn9c102_write_reg(cam, 0x60, 0x17); 36 err += sn9c102_write_reg(cam, 0x60, 0x17);
34 err += sn9c102_write_reg(cam, 0x0f, 0x18); 37 err += sn9c102_write_reg(cam, 0x0f, 0x18);
35 err += sn9c102_write_reg(cam, 0x50, 0x19); 38 err += sn9c102_write_reg(cam, 0x50, 0x19);
36 39
37 err += sn9c102_i2c_write(cam, 0x12, 0x80); 40 err += sn9c102_i2c_write(cam, 0x12, 0x8d);
38 err += sn9c102_i2c_write(cam, 0x11, 0x01); 41 err += sn9c102_i2c_write(cam, 0x12, 0x0d);
42 err += sn9c102_i2c_write(cam, 0x11, 0x00);
39 err += sn9c102_i2c_write(cam, 0x15, 0x34); 43 err += sn9c102_i2c_write(cam, 0x15, 0x34);
40 err += sn9c102_i2c_write(cam, 0x16, 0x03); 44 err += sn9c102_i2c_write(cam, 0x16, 0x03);
41 err += sn9c102_i2c_write(cam, 0x17, 0x1c); 45 err += sn9c102_i2c_write(cam, 0x17, 0x1c);
@@ -43,14 +47,72 @@ static int ov7630_init(struct sn9c102_device* cam)
43 err += sn9c102_i2c_write(cam, 0x19, 0x06); 47 err += sn9c102_i2c_write(cam, 0x19, 0x06);
44 err += sn9c102_i2c_write(cam, 0x1a, 0xf6); 48 err += sn9c102_i2c_write(cam, 0x1a, 0xf6);
45 err += sn9c102_i2c_write(cam, 0x1b, 0x04); 49 err += sn9c102_i2c_write(cam, 0x1b, 0x04);
46 err += sn9c102_i2c_write(cam, 0x20, 0xf6); 50 err += sn9c102_i2c_write(cam, 0x20, 0x44);
51 err += sn9c102_i2c_write(cam, 0x23, 0xee);
52 err += sn9c102_i2c_write(cam, 0x26, 0xa0);
53 err += sn9c102_i2c_write(cam, 0x27, 0x9a);
54 err += sn9c102_i2c_write(cam, 0x28, 0x20);
55 err += sn9c102_i2c_write(cam, 0x29, 0x30);
56 err += sn9c102_i2c_write(cam, 0x2f, 0x3d);
57 err += sn9c102_i2c_write(cam, 0x30, 0x24);
58 err += sn9c102_i2c_write(cam, 0x32, 0x86);
59 err += sn9c102_i2c_write(cam, 0x60, 0xa9);
60 err += sn9c102_i2c_write(cam, 0x61, 0x42);
61 err += sn9c102_i2c_write(cam, 0x65, 0x00);
62 err += sn9c102_i2c_write(cam, 0x69, 0x38);
63 err += sn9c102_i2c_write(cam, 0x6f, 0x88);
64 err += sn9c102_i2c_write(cam, 0x70, 0x0b);
65 err += sn9c102_i2c_write(cam, 0x71, 0x00);
66 err += sn9c102_i2c_write(cam, 0x74, 0x21);
67 err += sn9c102_i2c_write(cam, 0x7d, 0xf7);
68 break;
69 case BRIDGE_SN9C103:
70 err += sn9c102_write_reg(cam, 0x00, 0x02);
71 err += sn9c102_write_reg(cam, 0x00, 0x03);
72 err += sn9c102_write_reg(cam, 0x1a, 0x04);
73 err += sn9c102_write_reg(cam, 0x20, 0x05);
74 err += sn9c102_write_reg(cam, 0x20, 0x06);
75 err += sn9c102_write_reg(cam, 0x20, 0x07);
76 err += sn9c102_write_reg(cam, 0x03, 0x10);
77 err += sn9c102_write_reg(cam, 0x0a, 0x14);
78 err += sn9c102_write_reg(cam, 0x60, 0x17);
79 err += sn9c102_write_reg(cam, 0x0f, 0x18);
80 err += sn9c102_write_reg(cam, 0x50, 0x19);
81 err += sn9c102_write_reg(cam, 0x1d, 0x1a);
82 err += sn9c102_write_reg(cam, 0x10, 0x1b);
83 err += sn9c102_write_reg(cam, 0x02, 0x1c);
84 err += sn9c102_write_reg(cam, 0x03, 0x1d);
85 err += sn9c102_write_reg(cam, 0x0f, 0x1e);
86 err += sn9c102_write_reg(cam, 0x0c, 0x1f);
87 err += sn9c102_write_reg(cam, 0x00, 0x20);
88 err += sn9c102_write_reg(cam, 0x10, 0x21);
89 err += sn9c102_write_reg(cam, 0x20, 0x22);
90 err += sn9c102_write_reg(cam, 0x30, 0x23);
91 err += sn9c102_write_reg(cam, 0x40, 0x24);
92 err += sn9c102_write_reg(cam, 0x50, 0x25);
93 err += sn9c102_write_reg(cam, 0x60, 0x26);
94 err += sn9c102_write_reg(cam, 0x70, 0x27);
95 err += sn9c102_write_reg(cam, 0x80, 0x28);
96 err += sn9c102_write_reg(cam, 0x90, 0x29);
97 err += sn9c102_write_reg(cam, 0xa0, 0x2a);
98 err += sn9c102_write_reg(cam, 0xb0, 0x2b);
99 err += sn9c102_write_reg(cam, 0xc0, 0x2c);
100 err += sn9c102_write_reg(cam, 0xd0, 0x2d);
101 err += sn9c102_write_reg(cam, 0xe0, 0x2e);
102 err += sn9c102_write_reg(cam, 0xf0, 0x2f);
103 err += sn9c102_write_reg(cam, 0xff, 0x30);
104
105 err += sn9c102_i2c_write(cam, 0x12, 0x8d);
106 err += sn9c102_i2c_write(cam, 0x12, 0x0d);
107 err += sn9c102_i2c_write(cam, 0x15, 0x34);
108 err += sn9c102_i2c_write(cam, 0x11, 0x01);
109 err += sn9c102_i2c_write(cam, 0x1b, 0x04);
110 err += sn9c102_i2c_write(cam, 0x20, 0x44);
47 err += sn9c102_i2c_write(cam, 0x23, 0xee); 111 err += sn9c102_i2c_write(cam, 0x23, 0xee);
48 err += sn9c102_i2c_write(cam, 0x26, 0xa0); 112 err += sn9c102_i2c_write(cam, 0x26, 0xa0);
49 err += sn9c102_i2c_write(cam, 0x27, 0x9a); 113 err += sn9c102_i2c_write(cam, 0x27, 0x9a);
50 err += sn9c102_i2c_write(cam, 0x28, 0xa0); 114 err += sn9c102_i2c_write(cam, 0x28, 0x20);
51 err += sn9c102_i2c_write(cam, 0x29, 0x30); 115 err += sn9c102_i2c_write(cam, 0x29, 0x30);
52 err += sn9c102_i2c_write(cam, 0x2a, 0xa0);
53 err += sn9c102_i2c_write(cam, 0x2b, 0x1f);
54 err += sn9c102_i2c_write(cam, 0x2f, 0x3d); 116 err += sn9c102_i2c_write(cam, 0x2f, 0x3d);
55 err += sn9c102_i2c_write(cam, 0x30, 0x24); 117 err += sn9c102_i2c_write(cam, 0x30, 0x24);
56 err += sn9c102_i2c_write(cam, 0x32, 0x86); 118 err += sn9c102_i2c_write(cam, 0x32, 0x86);
@@ -63,45 +125,97 @@ static int ov7630_init(struct sn9c102_device* cam)
63 err += sn9c102_i2c_write(cam, 0x71, 0x00); 125 err += sn9c102_i2c_write(cam, 0x71, 0x00);
64 err += sn9c102_i2c_write(cam, 0x74, 0x21); 126 err += sn9c102_i2c_write(cam, 0x74, 0x21);
65 err += sn9c102_i2c_write(cam, 0x7d, 0xf7); 127 err += sn9c102_i2c_write(cam, 0x7d, 0xf7);
128 break;
129 default:
130 break;
131 }
66 132
67 return err; 133 return err;
68} 134}
69 135
70 136
71static int ov7630_set_ctrl(struct sn9c102_device* cam, 137static int ov7630_get_ctrl(struct sn9c102_device* cam,
72 const struct v4l2_control* ctrl) 138 struct v4l2_control* ctrl)
73{ 139{
74 int err = 0; 140 int err = 0;
75 141
76 switch (ctrl->id) { 142 switch (ctrl->id) {
77 case V4L2_CID_EXPOSURE: 143 case V4L2_CID_EXPOSURE:
78 err += sn9c102_i2c_write(cam, 0x10, ctrl->value >> 2); 144 if ((ctrl->value = sn9c102_i2c_read(cam, 0x10)) < 0)
79 err += sn9c102_i2c_write(cam, 0x76, ctrl->value & 0x03); 145 return -EIO;
80 break; 146 break;
81 case V4L2_CID_RED_BALANCE: 147 case V4L2_CID_RED_BALANCE:
82 err += sn9c102_i2c_write(cam, 0x02, ctrl->value); 148 ctrl->value = sn9c102_pread_reg(cam, 0x07);
83 break; 149 break;
84 case V4L2_CID_BLUE_BALANCE: 150 case V4L2_CID_BLUE_BALANCE:
85 err += sn9c102_i2c_write(cam, 0x01, ctrl->value); 151 ctrl->value = sn9c102_pread_reg(cam, 0x06);
152 break;
153 case SN9C102_V4L2_CID_GREEN_BALANCE:
154 ctrl->value = sn9c102_pread_reg(cam, 0x05);
86 break; 155 break;
87 case V4L2_CID_GAIN: 156 case V4L2_CID_GAIN:
88 err += sn9c102_i2c_write(cam, 0x00, ctrl->value); 157 if ((ctrl->value = sn9c102_i2c_read(cam, 0x00)) < 0)
158 return -EIO;
159 ctrl->value &= 0x3f;
160 break;
161 case V4L2_CID_DO_WHITE_BALANCE:
162 if ((ctrl->value = sn9c102_i2c_read(cam, 0x0c)) < 0)
163 return -EIO;
164 ctrl->value &= 0x3f;
165 break;
166 case V4L2_CID_WHITENESS:
167 if ((ctrl->value = sn9c102_i2c_read(cam, 0x0d)) < 0)
168 return -EIO;
169 ctrl->value &= 0x3f;
170 break;
171 case V4L2_CID_AUTOGAIN:
172 if ((ctrl->value = sn9c102_i2c_read(cam, 0x13)) < 0)
173 return -EIO;
174 ctrl->value &= 0x01;
175 break;
176 case V4L2_CID_VFLIP:
177 if ((ctrl->value = sn9c102_i2c_read(cam, 0x75)) < 0)
178 return -EIO;
179 ctrl->value = (ctrl->value & 0x80) ? 1 : 0;
180 break;
181 case SN9C102_V4L2_CID_GAMMA:
182 if ((ctrl->value = sn9c102_i2c_read(cam, 0x14)) < 0)
183 return -EIO;
184 ctrl->value = (ctrl->value & 0x02) ? 1 : 0;
185 break;
186 case SN9C102_V4L2_CID_BAND_FILTER:
187 if ((ctrl->value = sn9c102_i2c_read(cam, 0x2d)) < 0)
188 return -EIO;
189 ctrl->value = (ctrl->value & 0x02) ? 1 : 0;
190 break;
191 default:
192 return -EINVAL;
193 }
194
195 return err ? -EIO : 0;
196}
197
198
199static int ov7630_set_ctrl(struct sn9c102_device* cam,
200 const struct v4l2_control* ctrl)
201{
202 int err = 0;
203
204 switch (ctrl->id) {
205 case V4L2_CID_EXPOSURE:
206 err += sn9c102_i2c_write(cam, 0x10, ctrl->value);
89 break; 207 break;
90 case V4L2_CID_CONTRAST: 208 case V4L2_CID_RED_BALANCE:
91 err += ctrl->value ? sn9c102_i2c_write(cam, 0x05, 209 err += sn9c102_write_reg(cam, ctrl->value, 0x07);
92 (ctrl->value-1) | 0x20)
93 : sn9c102_i2c_write(cam, 0x05, 0x00);
94 break; 210 break;
95 case V4L2_CID_BRIGHTNESS: 211 case V4L2_CID_BLUE_BALANCE:
96 err += sn9c102_i2c_write(cam, 0x06, ctrl->value); 212 err += sn9c102_write_reg(cam, ctrl->value, 0x06);
97 break; 213 break;
98 case V4L2_CID_SATURATION: 214 case SN9C102_V4L2_CID_GREEN_BALANCE:
99 err += sn9c102_i2c_write(cam, 0x03, ctrl->value << 4); 215 err += sn9c102_write_reg(cam, ctrl->value, 0x05);
100 break; 216 break;
101 case V4L2_CID_HUE: 217 case V4L2_CID_GAIN:
102 err += ctrl->value ? sn9c102_i2c_write(cam, 0x04, 218 err += sn9c102_i2c_write(cam, 0x00, ctrl->value);
103 (ctrl->value-1) | 0x20)
104 : sn9c102_i2c_write(cam, 0x04, 0x00);
105 break; 219 break;
106 case V4L2_CID_DO_WHITE_BALANCE: 220 case V4L2_CID_DO_WHITE_BALANCE:
107 err += sn9c102_i2c_write(cam, 0x0c, ctrl->value); 221 err += sn9c102_i2c_write(cam, 0x0c, ctrl->value);
@@ -109,23 +223,15 @@ static int ov7630_set_ctrl(struct sn9c102_device* cam,
109 case V4L2_CID_WHITENESS: 223 case V4L2_CID_WHITENESS:
110 err += sn9c102_i2c_write(cam, 0x0d, ctrl->value); 224 err += sn9c102_i2c_write(cam, 0x0d, ctrl->value);
111 break; 225 break;
112 case V4L2_CID_AUTO_WHITE_BALANCE:
113 err += sn9c102_i2c_write(cam, 0x12, (ctrl->value << 2) | 0x78);
114 break;
115 case V4L2_CID_AUTOGAIN: 226 case V4L2_CID_AUTOGAIN:
116 err += sn9c102_i2c_write(cam, 0x13, ctrl->value); 227 err += sn9c102_i2c_write(cam, 0x13, ctrl->value |
228 (ctrl->value << 1));
117 break; 229 break;
118 case V4L2_CID_VFLIP: 230 case V4L2_CID_VFLIP:
119 err += sn9c102_i2c_write(cam, 0x75, 0x0e | (ctrl->value << 7)); 231 err += sn9c102_i2c_write(cam, 0x75, 0x0e | (ctrl->value << 7));
120 break; 232 break;
121 case V4L2_CID_BLACK_LEVEL:
122 err += sn9c102_i2c_write(cam, 0x25, ctrl->value);
123 break;
124 case SN9C102_V4L2_CID_BRIGHT_LEVEL:
125 err += sn9c102_i2c_write(cam, 0x24, ctrl->value);
126 break;
127 case SN9C102_V4L2_CID_GAMMA: 233 case SN9C102_V4L2_CID_GAMMA:
128 err += sn9c102_i2c_write(cam, 0x14, (ctrl->value << 2) | 0x80); 234 err += sn9c102_i2c_write(cam, 0x14, ctrl->value << 2);
129 break; 235 break;
130 case SN9C102_V4L2_CID_BAND_FILTER: 236 case SN9C102_V4L2_CID_BAND_FILTER:
131 err += sn9c102_i2c_write(cam, 0x2d, ctrl->value << 2); 237 err += sn9c102_i2c_write(cam, 0x2d, ctrl->value << 2);
@@ -141,10 +247,12 @@ static int ov7630_set_ctrl(struct sn9c102_device* cam,
141static int ov7630_set_crop(struct sn9c102_device* cam, 247static int ov7630_set_crop(struct sn9c102_device* cam,
142 const struct v4l2_rect* rect) 248 const struct v4l2_rect* rect)
143{ 249{
144 struct sn9c102_sensor* s = &ov7630; 250 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
145 int err = 0; 251 int err = 0;
146 u8 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 1; 252 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 1,
253 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 1;
147 254
255 err += sn9c102_write_reg(cam, h_start, 0x12);
148 err += sn9c102_write_reg(cam, v_start, 0x13); 256 err += sn9c102_write_reg(cam, v_start, 0x13);
149 257
150 return err; 258 return err;
@@ -168,7 +276,8 @@ static int ov7630_set_pix_format(struct sn9c102_device* cam,
168static struct sn9c102_sensor ov7630 = { 276static struct sn9c102_sensor ov7630 = {
169 .name = "OV7630", 277 .name = "OV7630",
170 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 278 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
171 .sysfs_ops = SN9C102_I2C_WRITE, 279 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102 | BRIDGE_SN9C103,
280 .sysfs_ops = SN9C102_I2C_READ | SN9C102_I2C_WRITE,
172 .frequency = SN9C102_I2C_100KHZ, 281 .frequency = SN9C102_I2C_100KHZ,
173 .interface = SN9C102_I2C_2WIRES, 282 .interface = SN9C102_I2C_2WIRES,
174 .i2c_slave_id = 0x21, 283 .i2c_slave_id = 0x21,
@@ -185,73 +294,23 @@ static struct sn9c102_sensor ov7630 = {
185 .flags = 0, 294 .flags = 0,
186 }, 295 },
187 { 296 {
188 .id = V4L2_CID_HUE,
189 .type = V4L2_CTRL_TYPE_INTEGER,
190 .name = "hue",
191 .minimum = 0x00,
192 .maximum = 0x1f+1,
193 .step = 0x01,
194 .default_value = 0x00,
195 .flags = 0,
196 },
197 {
198 .id = V4L2_CID_SATURATION,
199 .type = V4L2_CTRL_TYPE_INTEGER,
200 .name = "saturation",
201 .minimum = 0x00,
202 .maximum = 0x0f,
203 .step = 0x01,
204 .default_value = 0x08,
205 .flags = 0,
206 },
207 {
208 .id = V4L2_CID_CONTRAST,
209 .type = V4L2_CTRL_TYPE_INTEGER,
210 .name = "contrast",
211 .minimum = 0x00,
212 .maximum = 0x1f+1,
213 .step = 0x01,
214 .default_value = 0x00,
215 .flags = 0,
216 },
217 {
218 .id = V4L2_CID_EXPOSURE, 297 .id = V4L2_CID_EXPOSURE,
219 .type = V4L2_CTRL_TYPE_INTEGER, 298 .type = V4L2_CTRL_TYPE_INTEGER,
220 .name = "exposure", 299 .name = "exposure",
221 .minimum = 0x000,
222 .maximum = 0x3ff,
223 .step = 0x001,
224 .default_value = 0x83<<2,
225 .flags = 0,
226 },
227 {
228 .id = V4L2_CID_RED_BALANCE,
229 .type = V4L2_CTRL_TYPE_INTEGER,
230 .name = "red balance",
231 .minimum = 0x00,
232 .maximum = 0xff,
233 .step = 0x01,
234 .default_value = 0x3a,
235 .flags = 0,
236 },
237 {
238 .id = V4L2_CID_BLUE_BALANCE,
239 .type = V4L2_CTRL_TYPE_INTEGER,
240 .name = "blue balance",
241 .minimum = 0x00, 300 .minimum = 0x00,
242 .maximum = 0xff, 301 .maximum = 0xff,
243 .step = 0x01, 302 .step = 0x01,
244 .default_value = 0x77, 303 .default_value = 0x60,
245 .flags = 0, 304 .flags = 0,
246 }, 305 },
247 { 306 {
248 .id = V4L2_CID_BRIGHTNESS, 307 .id = V4L2_CID_WHITENESS,
249 .type = V4L2_CTRL_TYPE_INTEGER, 308 .type = V4L2_CTRL_TYPE_INTEGER,
250 .name = "brightness", 309 .name = "white balance background: red",
251 .minimum = 0x00, 310 .minimum = 0x00,
252 .maximum = 0xff, 311 .maximum = 0x3f,
253 .step = 0x01, 312 .step = 0x01,
254 .default_value = 0xa0, 313 .default_value = 0x20,
255 .flags = 0, 314 .flags = 0,
256 }, 315 },
257 { 316 {
@@ -265,31 +324,31 @@ static struct sn9c102_sensor ov7630 = {
265 .flags = 0, 324 .flags = 0,
266 }, 325 },
267 { 326 {
268 .id = V4L2_CID_WHITENESS, 327 .id = V4L2_CID_RED_BALANCE,
269 .type = V4L2_CTRL_TYPE_INTEGER, 328 .type = V4L2_CTRL_TYPE_INTEGER,
270 .name = "white balance background: red", 329 .name = "red balance",
271 .minimum = 0x00, 330 .minimum = 0x00,
272 .maximum = 0x3f, 331 .maximum = 0x7f,
273 .step = 0x01, 332 .step = 0x01,
274 .default_value = 0x20, 333 .default_value = 0x20,
275 .flags = 0, 334 .flags = 0,
276 }, 335 },
277 { 336 {
278 .id = V4L2_CID_AUTO_WHITE_BALANCE, 337 .id = V4L2_CID_BLUE_BALANCE,
279 .type = V4L2_CTRL_TYPE_BOOLEAN, 338 .type = V4L2_CTRL_TYPE_INTEGER,
280 .name = "auto white balance", 339 .name = "blue balance",
281 .minimum = 0x00, 340 .minimum = 0x00,
282 .maximum = 0x01, 341 .maximum = 0x7f,
283 .step = 0x01, 342 .step = 0x01,
284 .default_value = 0x01, 343 .default_value = 0x20,
285 .flags = 0, 344 .flags = 0,
286 }, 345 },
287 { 346 {
288 .id = V4L2_CID_AUTOGAIN, 347 .id = V4L2_CID_AUTOGAIN,
289 .type = V4L2_CTRL_TYPE_INTEGER, 348 .type = V4L2_CTRL_TYPE_BOOLEAN,
290 .name = "gain & exposure mode", 349 .name = "auto adjust",
291 .minimum = 0x00, 350 .minimum = 0x00,
292 .maximum = 0x03, 351 .maximum = 0x01,
293 .step = 0x01, 352 .step = 0x01,
294 .default_value = 0x00, 353 .default_value = 0x00,
295 .flags = 0, 354 .flags = 0,
@@ -305,23 +364,13 @@ static struct sn9c102_sensor ov7630 = {
305 .flags = 0, 364 .flags = 0,
306 }, 365 },
307 { 366 {
308 .id = V4L2_CID_BLACK_LEVEL, 367 .id = SN9C102_V4L2_CID_GREEN_BALANCE,
309 .type = V4L2_CTRL_TYPE_INTEGER, 368 .type = V4L2_CTRL_TYPE_INTEGER,
310 .name = "black pixel ratio", 369 .name = "green balance",
311 .minimum = 0x01, 370 .minimum = 0x00,
312 .maximum = 0x9a, 371 .maximum = 0x7f,
313 .step = 0x01,
314 .default_value = 0x8a,
315 .flags = 0,
316 },
317 {
318 .id = SN9C102_V4L2_CID_BRIGHT_LEVEL,
319 .type = V4L2_CTRL_TYPE_INTEGER,
320 .name = "bright pixel ratio",
321 .minimum = 0x01,
322 .maximum = 0x9a,
323 .step = 0x01, 372 .step = 0x01,
324 .default_value = 0x10, 373 .default_value = 0x20,
325 .flags = 0, 374 .flags = 0,
326 }, 375 },
327 { 376 {
@@ -345,6 +394,7 @@ static struct sn9c102_sensor ov7630 = {
345 .flags = 0, 394 .flags = 0,
346 }, 395 },
347 }, 396 },
397 .get_ctrl = &ov7630_get_ctrl,
348 .set_ctrl = &ov7630_set_ctrl, 398 .set_ctrl = &ov7630_set_ctrl,
349 .cropcap = { 399 .cropcap = {
350 .bounds = { 400 .bounds = {
@@ -364,7 +414,7 @@ static struct sn9c102_sensor ov7630 = {
364 .pix_format = { 414 .pix_format = {
365 .width = 640, 415 .width = 640,
366 .height = 480, 416 .height = 480,
367 .pixelformat = V4L2_PIX_FMT_SBGGR8, 417 .pixelformat = V4L2_PIX_FMT_SN9C10X,
368 .priv = 8, 418 .priv = 8,
369 }, 419 },
370 .set_pix_format = &ov7630_set_pix_format 420 .set_pix_format = &ov7630_set_pix_format
@@ -373,28 +423,36 @@ static struct sn9c102_sensor ov7630 = {
373 423
374int sn9c102_probe_ov7630(struct sn9c102_device* cam) 424int sn9c102_probe_ov7630(struct sn9c102_device* cam)
375{ 425{
376 const struct usb_device_id ov7630_id_table[] = { 426 int pid, ver, err = 0;
377 { USB_DEVICE(0x0c45, 0x602c), },
378 { USB_DEVICE(0x0c45, 0x602d), },
379 { USB_DEVICE(0x0c45, 0x608f), },
380 { USB_DEVICE(0x0c45, 0x60b0), },
381 { }
382 };
383 int err = 0;
384
385 if (!sn9c102_match_id(cam, ov7630_id_table))
386 return -ENODEV;
387 427
428 switch (sn9c102_get_bridge(cam)) {
429 case BRIDGE_SN9C101:
430 case BRIDGE_SN9C102:
388 err += sn9c102_write_reg(cam, 0x01, 0x01); 431 err += sn9c102_write_reg(cam, 0x01, 0x01);
389 err += sn9c102_write_reg(cam, 0x00, 0x01); 432 err += sn9c102_write_reg(cam, 0x00, 0x01);
390 err += sn9c102_write_reg(cam, 0x28, 0x17); 433 err += sn9c102_write_reg(cam, 0x28, 0x17);
391 if (err) 434 break;
392 return -EIO; 435 case BRIDGE_SN9C103: /* do _not_ change anything! */
436 err += sn9c102_write_reg(cam, 0x09, 0x01);
437 err += sn9c102_write_reg(cam, 0x42, 0x01);
438 err += sn9c102_write_reg(cam, 0x28, 0x17);
439 err += sn9c102_write_reg(cam, 0x44, 0x02);
440 pid = sn9c102_i2c_try_read(cam, &ov7630, 0x0a);
441 if (err || pid < 0) { /* try a different initialization */
442 err = sn9c102_write_reg(cam, 0x01, 0x01);
443 err += sn9c102_write_reg(cam, 0x00, 0x01);
444 }
445 break;
446 default:
447 break;
448 }
393 449
394 err += sn9c102_i2c_try_write(cam, &ov7630, 0x0b, 0); 450 pid = sn9c102_i2c_try_read(cam, &ov7630, 0x0a);
395 if (err) 451 ver = sn9c102_i2c_try_read(cam, &ov7630, 0x0b);
452 if (err || pid < 0 || ver < 0)
453 return -EIO;
454 if (pid != 0x76 || ver != 0x31)
396 return -ENODEV; 455 return -ENODEV;
397
398 sn9c102_attach_sensor(cam, &ov7630); 456 sn9c102_attach_sensor(cam, &ov7630);
399 457
400 return 0; 458 return 0;
diff --git a/drivers/media/video/sn9c102/sn9c102_ov7660.c b/drivers/media/video/sn9c102/sn9c102_ov7660.c
new file mode 100644
index 0000000000..d670c24d44
--- /dev/null
+++ b/drivers/media/video/sn9c102/sn9c102_ov7660.c
@@ -0,0 +1,592 @@
1/***************************************************************************
2 * Plug-in for OV7660 image sensor connected to the SN9C1xx PC Camera *
3 * Controllers *
4 * *
5 * Copyright (C) 2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
20 ***************************************************************************/
21
22#include "sn9c102_sensor.h"
23
24
25static struct sn9c102_sensor ov7660;
26
27
28static int ov7660_init(struct sn9c102_device* cam)
29{
30 int err = 0;
31
32 err += sn9c102_write_reg(cam, 0x40, 0x02);
33 err += sn9c102_write_reg(cam, 0x00, 0x03);
34 err += sn9c102_write_reg(cam, 0x1a, 0x04);
35 err += sn9c102_write_reg(cam, 0x03, 0x10);
36 err += sn9c102_write_reg(cam, 0x08, 0x14);
37 err += sn9c102_write_reg(cam, 0x20, 0x17);
38 err += sn9c102_write_reg(cam, 0x8b, 0x18);
39 err += sn9c102_write_reg(cam, 0x00, 0x19);
40 err += sn9c102_write_reg(cam, 0x1d, 0x1a);
41 err += sn9c102_write_reg(cam, 0x10, 0x1b);
42 err += sn9c102_write_reg(cam, 0x02, 0x1c);
43 err += sn9c102_write_reg(cam, 0x03, 0x1d);
44 err += sn9c102_write_reg(cam, 0x0f, 0x1e);
45 err += sn9c102_write_reg(cam, 0x0c, 0x1f);
46 err += sn9c102_write_reg(cam, 0x00, 0x20);
47 err += sn9c102_write_reg(cam, 0x29, 0x21);
48 err += sn9c102_write_reg(cam, 0x40, 0x22);
49 err += sn9c102_write_reg(cam, 0x54, 0x23);
50 err += sn9c102_write_reg(cam, 0x66, 0x24);
51 err += sn9c102_write_reg(cam, 0x76, 0x25);
52 err += sn9c102_write_reg(cam, 0x85, 0x26);
53 err += sn9c102_write_reg(cam, 0x94, 0x27);
54 err += sn9c102_write_reg(cam, 0xa1, 0x28);
55 err += sn9c102_write_reg(cam, 0xae, 0x29);
56 err += sn9c102_write_reg(cam, 0xbb, 0x2a);
57 err += sn9c102_write_reg(cam, 0xc7, 0x2b);
58 err += sn9c102_write_reg(cam, 0xd3, 0x2c);
59 err += sn9c102_write_reg(cam, 0xde, 0x2d);
60 err += sn9c102_write_reg(cam, 0xea, 0x2e);
61 err += sn9c102_write_reg(cam, 0xf4, 0x2f);
62 err += sn9c102_write_reg(cam, 0xff, 0x30);
63 err += sn9c102_write_reg(cam, 0x00, 0x3F);
64 err += sn9c102_write_reg(cam, 0xC7, 0x40);
65 err += sn9c102_write_reg(cam, 0x01, 0x41);
66 err += sn9c102_write_reg(cam, 0x44, 0x42);
67 err += sn9c102_write_reg(cam, 0x00, 0x43);
68 err += sn9c102_write_reg(cam, 0x44, 0x44);
69 err += sn9c102_write_reg(cam, 0x00, 0x45);
70 err += sn9c102_write_reg(cam, 0x44, 0x46);
71 err += sn9c102_write_reg(cam, 0x00, 0x47);
72 err += sn9c102_write_reg(cam, 0xC7, 0x48);
73 err += sn9c102_write_reg(cam, 0x01, 0x49);
74 err += sn9c102_write_reg(cam, 0xC7, 0x4A);
75 err += sn9c102_write_reg(cam, 0x01, 0x4B);
76 err += sn9c102_write_reg(cam, 0xC7, 0x4C);
77 err += sn9c102_write_reg(cam, 0x01, 0x4D);
78 err += sn9c102_write_reg(cam, 0x44, 0x4E);
79 err += sn9c102_write_reg(cam, 0x00, 0x4F);
80 err += sn9c102_write_reg(cam, 0x44, 0x50);
81 err += sn9c102_write_reg(cam, 0x00, 0x51);
82 err += sn9c102_write_reg(cam, 0x44, 0x52);
83 err += sn9c102_write_reg(cam, 0x00, 0x53);
84 err += sn9c102_write_reg(cam, 0xC7, 0x54);
85 err += sn9c102_write_reg(cam, 0x01, 0x55);
86 err += sn9c102_write_reg(cam, 0xC7, 0x56);
87 err += sn9c102_write_reg(cam, 0x01, 0x57);
88 err += sn9c102_write_reg(cam, 0xC7, 0x58);
89 err += sn9c102_write_reg(cam, 0x01, 0x59);
90 err += sn9c102_write_reg(cam, 0x44, 0x5A);
91 err += sn9c102_write_reg(cam, 0x00, 0x5B);
92 err += sn9c102_write_reg(cam, 0x44, 0x5C);
93 err += sn9c102_write_reg(cam, 0x00, 0x5D);
94 err += sn9c102_write_reg(cam, 0x44, 0x5E);
95 err += sn9c102_write_reg(cam, 0x00, 0x5F);
96 err += sn9c102_write_reg(cam, 0xC7, 0x60);
97 err += sn9c102_write_reg(cam, 0x01, 0x61);
98 err += sn9c102_write_reg(cam, 0xC7, 0x62);
99 err += sn9c102_write_reg(cam, 0x01, 0x63);
100 err += sn9c102_write_reg(cam, 0xC7, 0x64);
101 err += sn9c102_write_reg(cam, 0x01, 0x65);
102 err += sn9c102_write_reg(cam, 0x44, 0x66);
103 err += sn9c102_write_reg(cam, 0x00, 0x67);
104 err += sn9c102_write_reg(cam, 0x44, 0x68);
105 err += sn9c102_write_reg(cam, 0x00, 0x69);
106 err += sn9c102_write_reg(cam, 0x44, 0x6A);
107 err += sn9c102_write_reg(cam, 0x00, 0x6B);
108 err += sn9c102_write_reg(cam, 0xC7, 0x6C);
109 err += sn9c102_write_reg(cam, 0x01, 0x6D);
110 err += sn9c102_write_reg(cam, 0xC7, 0x6E);
111 err += sn9c102_write_reg(cam, 0x01, 0x6F);
112 err += sn9c102_write_reg(cam, 0xC7, 0x70);
113 err += sn9c102_write_reg(cam, 0x01, 0x71);
114 err += sn9c102_write_reg(cam, 0x44, 0x72);
115 err += sn9c102_write_reg(cam, 0x00, 0x73);
116 err += sn9c102_write_reg(cam, 0x44, 0x74);
117 err += sn9c102_write_reg(cam, 0x00, 0x75);
118 err += sn9c102_write_reg(cam, 0x44, 0x76);
119 err += sn9c102_write_reg(cam, 0x00, 0x77);
120 err += sn9c102_write_reg(cam, 0xC7, 0x78);
121 err += sn9c102_write_reg(cam, 0x01, 0x79);
122 err += sn9c102_write_reg(cam, 0xC7, 0x7A);
123 err += sn9c102_write_reg(cam, 0x01, 0x7B);
124 err += sn9c102_write_reg(cam, 0xC7, 0x7C);
125 err += sn9c102_write_reg(cam, 0x01, 0x7D);
126 err += sn9c102_write_reg(cam, 0x44, 0x7E);
127 err += sn9c102_write_reg(cam, 0x00, 0x7F);
128 err += sn9c102_write_reg(cam, 0x14, 0x84);
129 err += sn9c102_write_reg(cam, 0x00, 0x85);
130 err += sn9c102_write_reg(cam, 0x27, 0x86);
131 err += sn9c102_write_reg(cam, 0x00, 0x87);
132 err += sn9c102_write_reg(cam, 0x07, 0x88);
133 err += sn9c102_write_reg(cam, 0x00, 0x89);
134 err += sn9c102_write_reg(cam, 0xEC, 0x8A);
135 err += sn9c102_write_reg(cam, 0x0f, 0x8B);
136 err += sn9c102_write_reg(cam, 0xD8, 0x8C);
137 err += sn9c102_write_reg(cam, 0x0f, 0x8D);
138 err += sn9c102_write_reg(cam, 0x3D, 0x8E);
139 err += sn9c102_write_reg(cam, 0x00, 0x8F);
140 err += sn9c102_write_reg(cam, 0x3D, 0x90);
141 err += sn9c102_write_reg(cam, 0x00, 0x91);
142 err += sn9c102_write_reg(cam, 0xCD, 0x92);
143 err += sn9c102_write_reg(cam, 0x0f, 0x93);
144 err += sn9c102_write_reg(cam, 0xf7, 0x94);
145 err += sn9c102_write_reg(cam, 0x0f, 0x95);
146 err += sn9c102_write_reg(cam, 0x0C, 0x96);
147 err += sn9c102_write_reg(cam, 0x00, 0x97);
148 err += sn9c102_write_reg(cam, 0x00, 0x98);
149 err += sn9c102_write_reg(cam, 0x66, 0x99);
150 err += sn9c102_write_reg(cam, 0x05, 0x9A);
151 err += sn9c102_write_reg(cam, 0x00, 0x9B);
152 err += sn9c102_write_reg(cam, 0x04, 0x9C);
153 err += sn9c102_write_reg(cam, 0x00, 0x9D);
154 err += sn9c102_write_reg(cam, 0x08, 0x9E);
155 err += sn9c102_write_reg(cam, 0x00, 0x9F);
156 err += sn9c102_write_reg(cam, 0x2D, 0xC0);
157 err += sn9c102_write_reg(cam, 0x2D, 0xC1);
158 err += sn9c102_write_reg(cam, 0x3A, 0xC2);
159 err += sn9c102_write_reg(cam, 0x05, 0xC3);
160 err += sn9c102_write_reg(cam, 0x04, 0xC4);
161 err += sn9c102_write_reg(cam, 0x3F, 0xC5);
162 err += sn9c102_write_reg(cam, 0x00, 0xC6);
163 err += sn9c102_write_reg(cam, 0x00, 0xC7);
164 err += sn9c102_write_reg(cam, 0x50, 0xC8);
165 err += sn9c102_write_reg(cam, 0x3C, 0xC9);
166 err += sn9c102_write_reg(cam, 0x28, 0xCA);
167 err += sn9c102_write_reg(cam, 0xD8, 0xCB);
168 err += sn9c102_write_reg(cam, 0x14, 0xCC);
169 err += sn9c102_write_reg(cam, 0xEC, 0xCD);
170 err += sn9c102_write_reg(cam, 0x32, 0xCE);
171 err += sn9c102_write_reg(cam, 0xDD, 0xCF);
172 err += sn9c102_write_reg(cam, 0x32, 0xD0);
173 err += sn9c102_write_reg(cam, 0xDD, 0xD1);
174 err += sn9c102_write_reg(cam, 0x6A, 0xD2);
175 err += sn9c102_write_reg(cam, 0x50, 0xD3);
176 err += sn9c102_write_reg(cam, 0x00, 0xD4);
177 err += sn9c102_write_reg(cam, 0x00, 0xD5);
178 err += sn9c102_write_reg(cam, 0x00, 0xD6);
179
180 err += sn9c102_i2c_write(cam, 0x12, 0x80);
181 err += sn9c102_i2c_write(cam, 0x11, 0x09);
182 err += sn9c102_i2c_write(cam, 0x00, 0x0A);
183 err += sn9c102_i2c_write(cam, 0x01, 0x78);
184 err += sn9c102_i2c_write(cam, 0x02, 0x90);
185 err += sn9c102_i2c_write(cam, 0x03, 0x00);
186 err += sn9c102_i2c_write(cam, 0x04, 0x00);
187 err += sn9c102_i2c_write(cam, 0x05, 0x08);
188 err += sn9c102_i2c_write(cam, 0x06, 0x0B);
189 err += sn9c102_i2c_write(cam, 0x07, 0x00);
190 err += sn9c102_i2c_write(cam, 0x08, 0x1C);
191 err += sn9c102_i2c_write(cam, 0x09, 0x01);
192 err += sn9c102_i2c_write(cam, 0x0A, 0x76);
193 err += sn9c102_i2c_write(cam, 0x0B, 0x60);
194 err += sn9c102_i2c_write(cam, 0x0C, 0x00);
195 err += sn9c102_i2c_write(cam, 0x0D, 0x08);
196 err += sn9c102_i2c_write(cam, 0x0E, 0x04);
197 err += sn9c102_i2c_write(cam, 0x0F, 0x6F);
198 err += sn9c102_i2c_write(cam, 0x10, 0x20);
199 err += sn9c102_i2c_write(cam, 0x11, 0x03);
200 err += sn9c102_i2c_write(cam, 0x12, 0x05);
201 err += sn9c102_i2c_write(cam, 0x13, 0xF8);
202 err += sn9c102_i2c_write(cam, 0x14, 0x2C);
203 err += sn9c102_i2c_write(cam, 0x15, 0x00);
204 err += sn9c102_i2c_write(cam, 0x16, 0x02);
205 err += sn9c102_i2c_write(cam, 0x17, 0x10);
206 err += sn9c102_i2c_write(cam, 0x18, 0x60);
207 err += sn9c102_i2c_write(cam, 0x19, 0x02);
208 err += sn9c102_i2c_write(cam, 0x1A, 0x7B);
209 err += sn9c102_i2c_write(cam, 0x1B, 0x02);
210 err += sn9c102_i2c_write(cam, 0x1C, 0x7F);
211 err += sn9c102_i2c_write(cam, 0x1D, 0xA2);
212 err += sn9c102_i2c_write(cam, 0x1E, 0x01);
213 err += sn9c102_i2c_write(cam, 0x1F, 0x0E);
214 err += sn9c102_i2c_write(cam, 0x20, 0x05);
215 err += sn9c102_i2c_write(cam, 0x21, 0x05);
216 err += sn9c102_i2c_write(cam, 0x22, 0x05);
217 err += sn9c102_i2c_write(cam, 0x23, 0x05);
218 err += sn9c102_i2c_write(cam, 0x24, 0x68);
219 err += sn9c102_i2c_write(cam, 0x25, 0x58);
220 err += sn9c102_i2c_write(cam, 0x26, 0xD4);
221 err += sn9c102_i2c_write(cam, 0x27, 0x80);
222 err += sn9c102_i2c_write(cam, 0x28, 0x80);
223 err += sn9c102_i2c_write(cam, 0x29, 0x30);
224 err += sn9c102_i2c_write(cam, 0x2A, 0x00);
225 err += sn9c102_i2c_write(cam, 0x2B, 0x00);
226 err += sn9c102_i2c_write(cam, 0x2C, 0x80);
227 err += sn9c102_i2c_write(cam, 0x2D, 0x00);
228 err += sn9c102_i2c_write(cam, 0x2E, 0x00);
229 err += sn9c102_i2c_write(cam, 0x2F, 0x0E);
230 err += sn9c102_i2c_write(cam, 0x30, 0x08);
231 err += sn9c102_i2c_write(cam, 0x31, 0x30);
232 err += sn9c102_i2c_write(cam, 0x32, 0xB4);
233 err += sn9c102_i2c_write(cam, 0x33, 0x00);
234 err += sn9c102_i2c_write(cam, 0x34, 0x07);
235 err += sn9c102_i2c_write(cam, 0x35, 0x84);
236 err += sn9c102_i2c_write(cam, 0x36, 0x00);
237 err += sn9c102_i2c_write(cam, 0x37, 0x0C);
238 err += sn9c102_i2c_write(cam, 0x38, 0x02);
239 err += sn9c102_i2c_write(cam, 0x39, 0x43);
240 err += sn9c102_i2c_write(cam, 0x3A, 0x00);
241 err += sn9c102_i2c_write(cam, 0x3B, 0x02);
242 err += sn9c102_i2c_write(cam, 0x3C, 0x6C);
243 err += sn9c102_i2c_write(cam, 0x3D, 0x99);
244 err += sn9c102_i2c_write(cam, 0x3E, 0x0E);
245 err += sn9c102_i2c_write(cam, 0x3F, 0x41);
246 err += sn9c102_i2c_write(cam, 0x40, 0xC1);
247 err += sn9c102_i2c_write(cam, 0x41, 0x22);
248 err += sn9c102_i2c_write(cam, 0x42, 0x08);
249 err += sn9c102_i2c_write(cam, 0x43, 0xF0);
250 err += sn9c102_i2c_write(cam, 0x44, 0x10);
251 err += sn9c102_i2c_write(cam, 0x45, 0x78);
252 err += sn9c102_i2c_write(cam, 0x46, 0xA8);
253 err += sn9c102_i2c_write(cam, 0x47, 0x60);
254 err += sn9c102_i2c_write(cam, 0x48, 0x80);
255 err += sn9c102_i2c_write(cam, 0x49, 0x00);
256 err += sn9c102_i2c_write(cam, 0x4A, 0x00);
257 err += sn9c102_i2c_write(cam, 0x4B, 0x00);
258 err += sn9c102_i2c_write(cam, 0x4C, 0x00);
259 err += sn9c102_i2c_write(cam, 0x4D, 0x00);
260 err += sn9c102_i2c_write(cam, 0x4E, 0x00);
261 err += sn9c102_i2c_write(cam, 0x4F, 0x46);
262 err += sn9c102_i2c_write(cam, 0x50, 0x36);
263 err += sn9c102_i2c_write(cam, 0x51, 0x0F);
264 err += sn9c102_i2c_write(cam, 0x52, 0x17);
265 err += sn9c102_i2c_write(cam, 0x53, 0x7F);
266 err += sn9c102_i2c_write(cam, 0x54, 0x96);
267 err += sn9c102_i2c_write(cam, 0x55, 0x40);
268 err += sn9c102_i2c_write(cam, 0x56, 0x40);
269 err += sn9c102_i2c_write(cam, 0x57, 0x40);
270 err += sn9c102_i2c_write(cam, 0x58, 0x0F);
271 err += sn9c102_i2c_write(cam, 0x59, 0xBA);
272 err += sn9c102_i2c_write(cam, 0x5A, 0x9A);
273 err += sn9c102_i2c_write(cam, 0x5B, 0x22);
274 err += sn9c102_i2c_write(cam, 0x5C, 0xB9);
275 err += sn9c102_i2c_write(cam, 0x5D, 0x9B);
276 err += sn9c102_i2c_write(cam, 0x5E, 0x10);
277 err += sn9c102_i2c_write(cam, 0x5F, 0xF0);
278 err += sn9c102_i2c_write(cam, 0x60, 0x05);
279 err += sn9c102_i2c_write(cam, 0x61, 0x60);
280 err += sn9c102_i2c_write(cam, 0x62, 0x00);
281 err += sn9c102_i2c_write(cam, 0x63, 0x00);
282 err += sn9c102_i2c_write(cam, 0x64, 0x50);
283 err += sn9c102_i2c_write(cam, 0x65, 0x30);
284 err += sn9c102_i2c_write(cam, 0x66, 0x00);
285 err += sn9c102_i2c_write(cam, 0x67, 0x80);
286 err += sn9c102_i2c_write(cam, 0x68, 0x7A);
287 err += sn9c102_i2c_write(cam, 0x69, 0x90);
288 err += sn9c102_i2c_write(cam, 0x6A, 0x80);
289 err += sn9c102_i2c_write(cam, 0x6B, 0x0A);
290 err += sn9c102_i2c_write(cam, 0x6C, 0x30);
291 err += sn9c102_i2c_write(cam, 0x6D, 0x48);
292 err += sn9c102_i2c_write(cam, 0x6E, 0x80);
293 err += sn9c102_i2c_write(cam, 0x6F, 0x74);
294 err += sn9c102_i2c_write(cam, 0x70, 0x64);
295 err += sn9c102_i2c_write(cam, 0x71, 0x60);
296 err += sn9c102_i2c_write(cam, 0x72, 0x5C);
297 err += sn9c102_i2c_write(cam, 0x73, 0x58);
298 err += sn9c102_i2c_write(cam, 0x74, 0x54);
299 err += sn9c102_i2c_write(cam, 0x75, 0x4C);
300 err += sn9c102_i2c_write(cam, 0x76, 0x40);
301 err += sn9c102_i2c_write(cam, 0x77, 0x38);
302 err += sn9c102_i2c_write(cam, 0x78, 0x34);
303 err += sn9c102_i2c_write(cam, 0x79, 0x30);
304 err += sn9c102_i2c_write(cam, 0x7A, 0x2F);
305 err += sn9c102_i2c_write(cam, 0x7B, 0x2B);
306 err += sn9c102_i2c_write(cam, 0x7C, 0x03);
307 err += sn9c102_i2c_write(cam, 0x7D, 0x07);
308 err += sn9c102_i2c_write(cam, 0x7E, 0x17);
309 err += sn9c102_i2c_write(cam, 0x7F, 0x34);
310 err += sn9c102_i2c_write(cam, 0x80, 0x41);
311 err += sn9c102_i2c_write(cam, 0x81, 0x4D);
312 err += sn9c102_i2c_write(cam, 0x82, 0x58);
313 err += sn9c102_i2c_write(cam, 0x83, 0x63);
314 err += sn9c102_i2c_write(cam, 0x84, 0x6E);
315 err += sn9c102_i2c_write(cam, 0x85, 0x77);
316 err += sn9c102_i2c_write(cam, 0x86, 0x87);
317 err += sn9c102_i2c_write(cam, 0x87, 0x95);
318 err += sn9c102_i2c_write(cam, 0x88, 0xAF);
319 err += sn9c102_i2c_write(cam, 0x89, 0xC7);
320 err += sn9c102_i2c_write(cam, 0x8A, 0xDF);
321 err += sn9c102_i2c_write(cam, 0x8B, 0x99);
322 err += sn9c102_i2c_write(cam, 0x8C, 0x99);
323 err += sn9c102_i2c_write(cam, 0x8D, 0xCF);
324 err += sn9c102_i2c_write(cam, 0x8E, 0x20);
325 err += sn9c102_i2c_write(cam, 0x8F, 0x26);
326 err += sn9c102_i2c_write(cam, 0x90, 0x10);
327 err += sn9c102_i2c_write(cam, 0x91, 0x0C);
328 err += sn9c102_i2c_write(cam, 0x92, 0x25);
329 err += sn9c102_i2c_write(cam, 0x93, 0x00);
330 err += sn9c102_i2c_write(cam, 0x94, 0x50);
331 err += sn9c102_i2c_write(cam, 0x95, 0x50);
332 err += sn9c102_i2c_write(cam, 0x96, 0x00);
333 err += sn9c102_i2c_write(cam, 0x97, 0x01);
334 err += sn9c102_i2c_write(cam, 0x98, 0x10);
335 err += sn9c102_i2c_write(cam, 0x99, 0x40);
336 err += sn9c102_i2c_write(cam, 0x9A, 0x40);
337 err += sn9c102_i2c_write(cam, 0x9B, 0x20);
338 err += sn9c102_i2c_write(cam, 0x9C, 0x00);
339 err += sn9c102_i2c_write(cam, 0x9D, 0x99);
340 err += sn9c102_i2c_write(cam, 0x9E, 0x7F);
341 err += sn9c102_i2c_write(cam, 0x9F, 0x00);
342 err += sn9c102_i2c_write(cam, 0xA0, 0x00);
343 err += sn9c102_i2c_write(cam, 0xA1, 0x00);
344
345 return err;
346}
347
348
349static int ov7660_get_ctrl(struct sn9c102_device* cam,
350 struct v4l2_control* ctrl)
351{
352 int err = 0;
353
354 switch (ctrl->id) {
355 case V4L2_CID_EXPOSURE:
356 if ((ctrl->value = sn9c102_i2c_read(cam, 0x10)) < 0)
357 return -EIO;
358 break;
359 case V4L2_CID_DO_WHITE_BALANCE:
360 ctrl->value = sn9c102_pread_reg(cam, 0x02);
361 ctrl->value = (ctrl->value & 0x04) ? 1 : 0;
362 break;
363 case V4L2_CID_RED_BALANCE:
364 ctrl->value = sn9c102_pread_reg(cam, 0x05);
365 ctrl->value &= 0x7f;
366 break;
367 case V4L2_CID_BLUE_BALANCE:
368 ctrl->value = sn9c102_pread_reg(cam, 0x06);
369 ctrl->value &= 0x7f;
370 break;
371 case SN9C102_V4L2_CID_GREEN_BALANCE:
372 ctrl->value = sn9c102_pread_reg(cam, 0x07);
373 ctrl->value &= 0x7f;
374 break;
375 case V4L2_CID_GAIN:
376 if ((ctrl->value = sn9c102_i2c_read(cam, 0x00)) < 0)
377 return -EIO;
378 ctrl->value &= 0x7f;
379 break;
380 case V4L2_CID_AUTOGAIN:
381 if ((ctrl->value = sn9c102_i2c_read(cam, 0x13)) < 0)
382 return -EIO;
383 ctrl->value &= 0x01;
384 break;
385 default:
386 return -EINVAL;
387 }
388
389 return err ? -EIO : 0;
390}
391
392
393static int ov7660_set_ctrl(struct sn9c102_device* cam,
394 const struct v4l2_control* ctrl)
395{
396 int err = 0;
397
398 switch (ctrl->id) {
399 case V4L2_CID_EXPOSURE:
400 err += sn9c102_i2c_write(cam, 0x10, ctrl->value);
401 break;
402 case V4L2_CID_DO_WHITE_BALANCE:
403 err += sn9c102_write_reg(cam, 0x43 | (ctrl->value << 2), 0x02);
404 break;
405 case V4L2_CID_RED_BALANCE:
406 err += sn9c102_write_reg(cam, ctrl->value, 0x05);
407 break;
408 case V4L2_CID_BLUE_BALANCE:
409 err += sn9c102_write_reg(cam, ctrl->value, 0x06);
410 break;
411 case SN9C102_V4L2_CID_GREEN_BALANCE:
412 err += sn9c102_write_reg(cam, ctrl->value, 0x07);
413 break;
414 case V4L2_CID_GAIN:
415 err += sn9c102_i2c_write(cam, 0x00, ctrl->value);
416 break;
417 case V4L2_CID_AUTOGAIN:
418 err += sn9c102_i2c_write(cam, 0x13, 0xf0 | ctrl->value |
419 (ctrl->value << 1));
420 break;
421 default:
422 return -EINVAL;
423 }
424
425 return err ? -EIO : 0;
426}
427
428
429static int ov7660_set_crop(struct sn9c102_device* cam,
430 const struct v4l2_rect* rect)
431{
432 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
433 int err = 0;
434 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 1,
435 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 1;
436
437 err += sn9c102_write_reg(cam, h_start, 0x12);
438 err += sn9c102_write_reg(cam, v_start, 0x13);
439
440 return err;
441}
442
443
444static int ov7660_set_pix_format(struct sn9c102_device* cam,
445 const struct v4l2_pix_format* pix)
446{
447 int r0, err = 0;
448
449 r0 = sn9c102_pread_reg(cam, 0x01);
450
451 if (pix->pixelformat == V4L2_PIX_FMT_JPEG) {
452 err += sn9c102_write_reg(cam, r0 | 0x40, 0x01);
453 err += sn9c102_write_reg(cam, 0xa2, 0x17);
454 err += sn9c102_i2c_write(cam, 0x11, 0x00);
455 } else {
456 err += sn9c102_write_reg(cam, r0 | 0x40, 0x01);
457 err += sn9c102_write_reg(cam, 0xa2, 0x17);
458 err += sn9c102_i2c_write(cam, 0x11, 0x0d);
459 }
460
461 return err;
462}
463
464
465static struct sn9c102_sensor ov7660 = {
466 .name = "OV7660",
467 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
468 .supported_bridge = BRIDGE_SN9C105 | BRIDGE_SN9C120,
469 .sysfs_ops = SN9C102_I2C_READ | SN9C102_I2C_WRITE,
470 .frequency = SN9C102_I2C_100KHZ,
471 .interface = SN9C102_I2C_2WIRES,
472 .i2c_slave_id = 0x21,
473 .init = &ov7660_init,
474 .qctrl = {
475 {
476 .id = V4L2_CID_GAIN,
477 .type = V4L2_CTRL_TYPE_INTEGER,
478 .name = "global gain",
479 .minimum = 0x00,
480 .maximum = 0x7f,
481 .step = 0x01,
482 .default_value = 0x0a,
483 .flags = 0,
484 },
485 {
486 .id = V4L2_CID_EXPOSURE,
487 .type = V4L2_CTRL_TYPE_INTEGER,
488 .name = "exposure",
489 .minimum = 0x00,
490 .maximum = 0xff,
491 .step = 0x01,
492 .default_value = 0x50,
493 .flags = 0,
494 },
495 {
496 .id = V4L2_CID_DO_WHITE_BALANCE,
497 .type = V4L2_CTRL_TYPE_BOOLEAN,
498 .name = "night mode",
499 .minimum = 0x00,
500 .maximum = 0x01,
501 .step = 0x01,
502 .default_value = 0x00,
503 .flags = 0,
504 },
505 {
506 .id = V4L2_CID_RED_BALANCE,
507 .type = V4L2_CTRL_TYPE_INTEGER,
508 .name = "red balance",
509 .minimum = 0x00,
510 .maximum = 0x7f,
511 .step = 0x01,
512 .default_value = 0x1f,
513 .flags = 0,
514 },
515 {
516 .id = V4L2_CID_BLUE_BALANCE,
517 .type = V4L2_CTRL_TYPE_INTEGER,
518 .name = "blue balance",
519 .minimum = 0x00,
520 .maximum = 0x7f,
521 .step = 0x01,
522 .default_value = 0x1e,
523 .flags = 0,
524 },
525 {
526 .id = V4L2_CID_AUTOGAIN,
527 .type = V4L2_CTRL_TYPE_BOOLEAN,
528 .name = "auto adjust",
529 .minimum = 0x00,
530 .maximum = 0x01,
531 .step = 0x01,
532 .default_value = 0x00,
533 .flags = 0,
534 },
535 {
536 .id = SN9C102_V4L2_CID_GREEN_BALANCE,
537 .type = V4L2_CTRL_TYPE_INTEGER,
538 .name = "green balance",
539 .minimum = 0x00,
540 .maximum = 0x7f,
541 .step = 0x01,
542 .default_value = 0x20,
543 .flags = 0,
544 },
545 },
546 .get_ctrl = &ov7660_get_ctrl,
547 .set_ctrl = &ov7660_set_ctrl,
548 .cropcap = {
549 .bounds = {
550 .left = 0,
551 .top = 0,
552 .width = 640,
553 .height = 480,
554 },
555 .defrect = {
556 .left = 0,
557 .top = 0,
558 .width = 640,
559 .height = 480,
560 },
561 },
562 .set_crop = &ov7660_set_crop,
563 .pix_format = {
564 .width = 640,
565 .height = 480,
566 .pixelformat = V4L2_PIX_FMT_JPEG,
567 .priv = 8,
568 },
569 .set_pix_format = &ov7660_set_pix_format
570};
571
572
573int sn9c102_probe_ov7660(struct sn9c102_device* cam)
574{
575 int pid, ver, err = 0;
576
577 err += sn9c102_write_reg(cam, 0x01, 0xf1);
578 err += sn9c102_write_reg(cam, 0x00, 0xf1);
579 err += sn9c102_write_reg(cam, 0x01, 0x01);
580 err += sn9c102_write_reg(cam, 0x00, 0x01);
581 err += sn9c102_write_reg(cam, 0x28, 0x17);
582
583 pid = sn9c102_i2c_try_read(cam, &ov7660, 0x0a);
584 ver = sn9c102_i2c_try_read(cam, &ov7660, 0x0b);
585 if (err || pid < 0 || ver < 0)
586 return -EIO;
587 if (pid != 0x76 || ver != 0x60)
588 return -ENODEV;
589 sn9c102_attach_sensor(cam, &ov7660);
590
591 return 0;
592}
diff --git a/drivers/media/video/sn9c102/sn9c102_pas106b.c b/drivers/media/video/sn9c102/sn9c102_pas106b.c
index 9915944235..8d79a5fae5 100644
--- a/drivers/media/video/sn9c102/sn9c102_pas106b.c
+++ b/drivers/media/video/sn9c102/sn9c102_pas106b.c
@@ -1,8 +1,8 @@
1/*************************************************************************** 1/***************************************************************************
2 * Plug-in for PAS106B image sensor connected to the SN9C10x PC Camera * 2 * Plug-in for PAS106B image sensor connected to the SN9C1xx PC Camera *
3 * Controllers * 3 * Controllers *
4 * * 4 * *
5 * Copyright (C) 2004-2006 by Luca Risolia <luca.risolia@studio.unibo.it> * 5 * Copyright (C) 2004-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
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 *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
@@ -143,7 +143,7 @@ static int pas106b_set_ctrl(struct sn9c102_device* cam,
143static int pas106b_set_crop(struct sn9c102_device* cam, 143static int pas106b_set_crop(struct sn9c102_device* cam,
144 const struct v4l2_rect* rect) 144 const struct v4l2_rect* rect)
145{ 145{
146 struct sn9c102_sensor* s = &pas106b; 146 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
147 int err = 0; 147 int err = 0;
148 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 4, 148 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 4,
149 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 3; 149 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 3;
@@ -172,6 +172,7 @@ static int pas106b_set_pix_format(struct sn9c102_device* cam,
172static struct sn9c102_sensor pas106b = { 172static struct sn9c102_sensor pas106b = {
173 .name = "PAS106B", 173 .name = "PAS106B",
174 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 174 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
175 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102 | BRIDGE_SN9C103,
175 .sysfs_ops = SN9C102_I2C_READ | SN9C102_I2C_WRITE, 176 .sysfs_ops = SN9C102_I2C_READ | SN9C102_I2C_WRITE,
176 .frequency = SN9C102_I2C_400KHZ | SN9C102_I2C_100KHZ, 177 .frequency = SN9C102_I2C_400KHZ | SN9C102_I2C_100KHZ,
177 .interface = SN9C102_I2C_2WIRES, 178 .interface = SN9C102_I2C_2WIRES,
diff --git a/drivers/media/video/sn9c102/sn9c102_pas202bca.c b/drivers/media/video/sn9c102/sn9c102_pas202bca.c
deleted file mode 100644
index c8f1ae2152..0000000000
--- a/drivers/media/video/sn9c102/sn9c102_pas202bca.c
+++ /dev/null
@@ -1,238 +0,0 @@
1/***************************************************************************
2 * Plug-in for PAS202BCA image sensor connected to the SN9C10x PC Camera *
3 * Controllers *
4 * *
5 * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
20 ***************************************************************************/
21
22#include <linux/delay.h>
23#include "sn9c102_sensor.h"
24
25
26static struct sn9c102_sensor pas202bca;
27
28
29static int pas202bca_init(struct sn9c102_device* cam)
30{
31 int err = 0;
32
33 err += sn9c102_write_reg(cam, 0x00, 0x10);
34 err += sn9c102_write_reg(cam, 0x00, 0x11);
35 err += sn9c102_write_reg(cam, 0x00, 0x14);
36 err += sn9c102_write_reg(cam, 0x20, 0x17);
37 err += sn9c102_write_reg(cam, 0x30, 0x19);
38 err += sn9c102_write_reg(cam, 0x09, 0x18);
39
40 err += sn9c102_i2c_write(cam, 0x02, 0x14);
41 err += sn9c102_i2c_write(cam, 0x03, 0x40);
42 err += sn9c102_i2c_write(cam, 0x0d, 0x2c);
43 err += sn9c102_i2c_write(cam, 0x0e, 0x01);
44 err += sn9c102_i2c_write(cam, 0x0f, 0xa9);
45 err += sn9c102_i2c_write(cam, 0x10, 0x08);
46 err += sn9c102_i2c_write(cam, 0x13, 0x63);
47 err += sn9c102_i2c_write(cam, 0x15, 0x70);
48 err += sn9c102_i2c_write(cam, 0x11, 0x01);
49
50 msleep(400);
51
52 return err;
53}
54
55
56static int pas202bca_set_pix_format(struct sn9c102_device* cam,
57 const struct v4l2_pix_format* pix)
58{
59 int err = 0;
60
61 if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X)
62 err += sn9c102_write_reg(cam, 0x24, 0x17);
63 else
64 err += sn9c102_write_reg(cam, 0x20, 0x17);
65
66 return err;
67}
68
69
70static int pas202bca_set_ctrl(struct sn9c102_device* cam,
71 const struct v4l2_control* ctrl)
72{
73 int err = 0;
74
75 switch (ctrl->id) {
76 case V4L2_CID_EXPOSURE:
77 err += sn9c102_i2c_write(cam, 0x04, ctrl->value >> 6);
78 err += sn9c102_i2c_write(cam, 0x05, ctrl->value & 0x3f);
79 break;
80 case V4L2_CID_RED_BALANCE:
81 err += sn9c102_i2c_write(cam, 0x09, ctrl->value);
82 break;
83 case V4L2_CID_BLUE_BALANCE:
84 err += sn9c102_i2c_write(cam, 0x07, ctrl->value);
85 break;
86 case V4L2_CID_GAIN:
87 err += sn9c102_i2c_write(cam, 0x10, ctrl->value);
88 break;
89 case SN9C102_V4L2_CID_GREEN_BALANCE:
90 err += sn9c102_i2c_write(cam, 0x08, ctrl->value);
91 break;
92 case SN9C102_V4L2_CID_DAC_MAGNITUDE:
93 err += sn9c102_i2c_write(cam, 0x0c, ctrl->value);
94 break;
95 default:
96 return -EINVAL;
97 }
98 err += sn9c102_i2c_write(cam, 0x11, 0x01);
99
100 return err ? -EIO : 0;
101}
102
103
104static int pas202bca_set_crop(struct sn9c102_device* cam,
105 const struct v4l2_rect* rect)
106{
107 struct sn9c102_sensor* s = &pas202bca;
108 int err = 0;
109 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 3,
110 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 3;
111
112 err += sn9c102_write_reg(cam, h_start, 0x12);
113 err += sn9c102_write_reg(cam, v_start, 0x13);
114
115 return err;
116}
117
118
119static struct sn9c102_sensor pas202bca = {
120 .name = "PAS202BCA",
121 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
122 .sysfs_ops = SN9C102_I2C_READ | SN9C102_I2C_WRITE,
123 .frequency = SN9C102_I2C_400KHZ | SN9C102_I2C_100KHZ,
124 .interface = SN9C102_I2C_2WIRES,
125 .i2c_slave_id = 0x40,
126 .init = &pas202bca_init,
127 .qctrl = {
128 {
129 .id = V4L2_CID_EXPOSURE,
130 .type = V4L2_CTRL_TYPE_INTEGER,
131 .name = "exposure",
132 .minimum = 0x01e5,
133 .maximum = 0x3fff,
134 .step = 0x0001,
135 .default_value = 0x01e5,
136 .flags = 0,
137 },
138 {
139 .id = V4L2_CID_GAIN,
140 .type = V4L2_CTRL_TYPE_INTEGER,
141 .name = "global gain",
142 .minimum = 0x00,
143 .maximum = 0x1f,
144 .step = 0x01,
145 .default_value = 0x0c,
146 .flags = 0,
147 },
148 {
149 .id = V4L2_CID_RED_BALANCE,
150 .type = V4L2_CTRL_TYPE_INTEGER,
151 .name = "red balance",
152 .minimum = 0x00,
153 .maximum = 0x0f,
154 .step = 0x01,
155 .default_value = 0x01,
156 .flags = 0,
157 },
158 {
159 .id = V4L2_CID_BLUE_BALANCE,
160 .type = V4L2_CTRL_TYPE_INTEGER,
161 .name = "blue balance",
162 .minimum = 0x00,
163 .maximum = 0x0f,
164 .step = 0x01,
165 .default_value = 0x05,
166 .flags = 0,
167 },
168 {
169 .id = SN9C102_V4L2_CID_GREEN_BALANCE,
170 .type = V4L2_CTRL_TYPE_INTEGER,
171 .name = "green balance",
172 .minimum = 0x00,
173 .maximum = 0x0f,
174 .step = 0x01,
175 .default_value = 0x00,
176 .flags = 0,
177 },
178 {
179 .id = SN9C102_V4L2_CID_DAC_MAGNITUDE,
180 .type = V4L2_CTRL_TYPE_INTEGER,
181 .name = "DAC magnitude",
182 .minimum = 0x00,
183 .maximum = 0xff,
184 .step = 0x01,
185 .default_value = 0x04,
186 .flags = 0,
187 },
188 },
189 .set_ctrl = &pas202bca_set_ctrl,
190 .cropcap = {
191 .bounds = {
192 .left = 0,
193 .top = 0,
194 .width = 640,
195 .height = 480,
196 },
197 .defrect = {
198 .left = 0,
199 .top = 0,
200 .width = 640,
201 .height = 480,
202 },
203 },
204 .set_crop = &pas202bca_set_crop,
205 .pix_format = {
206 .width = 640,
207 .height = 480,
208 .pixelformat = V4L2_PIX_FMT_SBGGR8,
209 .priv = 8,
210 },
211 .set_pix_format = &pas202bca_set_pix_format
212};
213
214
215int sn9c102_probe_pas202bca(struct sn9c102_device* cam)
216{
217 const struct usb_device_id pas202bca_id_table[] = {
218 { USB_DEVICE(0x0c45, 0x60af), },
219 { }
220 };
221 int err = 0;
222
223 if (!sn9c102_match_id(cam,pas202bca_id_table))
224 return -ENODEV;
225
226 err += sn9c102_write_reg(cam, 0x01, 0x01);
227 err += sn9c102_write_reg(cam, 0x40, 0x01);
228 err += sn9c102_write_reg(cam, 0x28, 0x17);
229 if (err)
230 return -EIO;
231
232 if (sn9c102_i2c_try_write(cam, &pas202bca, 0x10, 0)) /* try to write */
233 return -ENODEV;
234
235 sn9c102_attach_sensor(cam, &pas202bca);
236
237 return 0;
238}
diff --git a/drivers/media/video/sn9c102/sn9c102_pas202bcb.c b/drivers/media/video/sn9c102/sn9c102_pas202bcb.c
index e3c1178e33..7894f01b56 100644
--- a/drivers/media/video/sn9c102/sn9c102_pas202bcb.c
+++ b/drivers/media/video/sn9c102/sn9c102_pas202bcb.c
@@ -1,13 +1,13 @@
1/*************************************************************************** 1/***************************************************************************
2 * Plug-in for PAS202BCB image sensor connected to the SN9C10x PC Camera * 2 * Plug-in for PAS202BCB image sensor connected to the SN9C1xx PC Camera *
3 * Controllers * 3 * Controllers *
4 * * 4 * *
5 * Copyright (C) 2004 by Carlos Eduardo Medaglia Dyonisio * 5 * Copyright (C) 2004 by Carlos Eduardo Medaglia Dyonisio *
6 * <medaglia@undl.org.br> * 6 * <medaglia@undl.org.br> *
7 * http://cadu.homelinux.com:8080/ * 7 * http://cadu.homelinux.com:8080/ *
8 * * 8 * *
9 * DAC Magnitude, exposure and green gain controls added by * 9 * Support for SN9C103, DAC Magnitude, exposure and green gain controls *
10 * Luca Risolia <luca.risolia@studio.unibo.it> * 10 * added by Luca Risolia <luca.risolia@studio.unibo.it> *
11 * * 11 * *
12 * This program is free software; you can redistribute it and/or modify * 12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by * 13 * it under the terms of the GNU General Public License as published by *
@@ -35,12 +35,54 @@ static int pas202bcb_init(struct sn9c102_device* cam)
35{ 35{
36 int err = 0; 36 int err = 0;
37 37
38 switch (sn9c102_get_bridge(cam)) {
39 case BRIDGE_SN9C101:
40 case BRIDGE_SN9C102:
38 err += sn9c102_write_reg(cam, 0x00, 0x10); 41 err += sn9c102_write_reg(cam, 0x00, 0x10);
39 err += sn9c102_write_reg(cam, 0x00, 0x11); 42 err += sn9c102_write_reg(cam, 0x00, 0x11);
40 err += sn9c102_write_reg(cam, 0x00, 0x14); 43 err += sn9c102_write_reg(cam, 0x00, 0x14);
41 err += sn9c102_write_reg(cam, 0x20, 0x17); 44 err += sn9c102_write_reg(cam, 0x20, 0x17);
42 err += sn9c102_write_reg(cam, 0x30, 0x19); 45 err += sn9c102_write_reg(cam, 0x30, 0x19);
43 err += sn9c102_write_reg(cam, 0x09, 0x18); 46 err += sn9c102_write_reg(cam, 0x09, 0x18);
47 break;
48 case BRIDGE_SN9C103:
49 err += sn9c102_write_reg(cam, 0x00, 0x02);
50 err += sn9c102_write_reg(cam, 0x00, 0x03);
51 err += sn9c102_write_reg(cam, 0x1a, 0x04);
52 err += sn9c102_write_reg(cam, 0x20, 0x05);
53 err += sn9c102_write_reg(cam, 0x20, 0x06);
54 err += sn9c102_write_reg(cam, 0x20, 0x07);
55 err += sn9c102_write_reg(cam, 0x00, 0x10);
56 err += sn9c102_write_reg(cam, 0x00, 0x11);
57 err += sn9c102_write_reg(cam, 0x00, 0x14);
58 err += sn9c102_write_reg(cam, 0x20, 0x17);
59 err += sn9c102_write_reg(cam, 0x30, 0x19);
60 err += sn9c102_write_reg(cam, 0x09, 0x18);
61 err += sn9c102_write_reg(cam, 0x02, 0x1c);
62 err += sn9c102_write_reg(cam, 0x03, 0x1d);
63 err += sn9c102_write_reg(cam, 0x0f, 0x1e);
64 err += sn9c102_write_reg(cam, 0x0c, 0x1f);
65 err += sn9c102_write_reg(cam, 0x00, 0x20);
66 err += sn9c102_write_reg(cam, 0x10, 0x21);
67 err += sn9c102_write_reg(cam, 0x20, 0x22);
68 err += sn9c102_write_reg(cam, 0x30, 0x23);
69 err += sn9c102_write_reg(cam, 0x40, 0x24);
70 err += sn9c102_write_reg(cam, 0x50, 0x25);
71 err += sn9c102_write_reg(cam, 0x60, 0x26);
72 err += sn9c102_write_reg(cam, 0x70, 0x27);
73 err += sn9c102_write_reg(cam, 0x80, 0x28);
74 err += sn9c102_write_reg(cam, 0x90, 0x29);
75 err += sn9c102_write_reg(cam, 0xa0, 0x2a);
76 err += sn9c102_write_reg(cam, 0xb0, 0x2b);
77 err += sn9c102_write_reg(cam, 0xc0, 0x2c);
78 err += sn9c102_write_reg(cam, 0xd0, 0x2d);
79 err += sn9c102_write_reg(cam, 0xe0, 0x2e);
80 err += sn9c102_write_reg(cam, 0xf0, 0x2f);
81 err += sn9c102_write_reg(cam, 0xff, 0x30);
82 break;
83 default:
84 break;
85 }
44 86
45 err += sn9c102_i2c_write(cam, 0x02, 0x14); 87 err += sn9c102_i2c_write(cam, 0x02, 0x14);
46 err += sn9c102_i2c_write(cam, 0x03, 0x40); 88 err += sn9c102_i2c_write(cam, 0x03, 0x40);
@@ -107,7 +149,7 @@ static int pas202bcb_set_pix_format(struct sn9c102_device* cam,
107 int err = 0; 149 int err = 0;
108 150
109 if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X) 151 if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X)
110 err += sn9c102_write_reg(cam, 0x24, 0x17); 152 err += sn9c102_write_reg(cam, 0x28, 0x17);
111 else 153 else
112 err += sn9c102_write_reg(cam, 0x20, 0x17); 154 err += sn9c102_write_reg(cam, 0x20, 0x17);
113 155
@@ -152,11 +194,23 @@ static int pas202bcb_set_ctrl(struct sn9c102_device* cam,
152static int pas202bcb_set_crop(struct sn9c102_device* cam, 194static int pas202bcb_set_crop(struct sn9c102_device* cam,
153 const struct v4l2_rect* rect) 195 const struct v4l2_rect* rect)
154{ 196{
155 struct sn9c102_sensor* s = &pas202bcb; 197 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
156 int err = 0; 198 int err = 0;
157 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 4, 199 u8 h_start = 0,
158 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 3; 200 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 3;
159 201
202 switch (sn9c102_get_bridge(cam)) {
203 case BRIDGE_SN9C101:
204 case BRIDGE_SN9C102:
205 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 4;
206 break;
207 case BRIDGE_SN9C103:
208 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 3;
209 break;
210 default:
211 break;
212 }
213
160 err += sn9c102_write_reg(cam, h_start, 0x12); 214 err += sn9c102_write_reg(cam, h_start, 0x12);
161 err += sn9c102_write_reg(cam, v_start, 0x13); 215 err += sn9c102_write_reg(cam, v_start, 0x13);
162 216
@@ -166,8 +220,8 @@ static int pas202bcb_set_crop(struct sn9c102_device* cam,
166 220
167static struct sn9c102_sensor pas202bcb = { 221static struct sn9c102_sensor pas202bcb = {
168 .name = "PAS202BCB", 222 .name = "PAS202BCB",
169 .maintainer = "Carlos Eduardo Medaglia Dyonisio " 223 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
170 "<medaglia@undl.org.br>", 224 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102 | BRIDGE_SN9C103,
171 .sysfs_ops = SN9C102_I2C_READ | SN9C102_I2C_WRITE, 225 .sysfs_ops = SN9C102_I2C_READ | SN9C102_I2C_WRITE,
172 .frequency = SN9C102_I2C_400KHZ | SN9C102_I2C_100KHZ, 226 .frequency = SN9C102_I2C_400KHZ | SN9C102_I2C_100KHZ,
173 .interface = SN9C102_I2C_2WIRES, 227 .interface = SN9C102_I2C_2WIRES,
@@ -191,7 +245,7 @@ static struct sn9c102_sensor pas202bcb = {
191 .minimum = 0x00, 245 .minimum = 0x00,
192 .maximum = 0x1f, 246 .maximum = 0x1f,
193 .step = 0x01, 247 .step = 0x01,
194 .default_value = 0x0c, 248 .default_value = 0x0b,
195 .flags = 0, 249 .flags = 0,
196 }, 250 },
197 { 251 {
@@ -201,7 +255,7 @@ static struct sn9c102_sensor pas202bcb = {
201 .minimum = 0x00, 255 .minimum = 0x00,
202 .maximum = 0x0f, 256 .maximum = 0x0f,
203 .step = 0x01, 257 .step = 0x01,
204 .default_value = 0x01, 258 .default_value = 0x00,
205 .flags = 0, 259 .flags = 0,
206 }, 260 },
207 { 261 {
@@ -271,16 +325,27 @@ int sn9c102_probe_pas202bcb(struct sn9c102_device* cam)
271 * Minimal initialization to enable the I2C communication 325 * Minimal initialization to enable the I2C communication
272 * NOTE: do NOT change the values! 326 * NOTE: do NOT change the values!
273 */ 327 */
274 err += sn9c102_write_reg(cam, 0x01, 0x01); /* sensor power down */ 328 switch (sn9c102_get_bridge(cam)) {
275 err += sn9c102_write_reg(cam, 0x40, 0x01); /* sensor power on */ 329 case BRIDGE_SN9C101:
276 err += sn9c102_write_reg(cam, 0x28, 0x17); /* sensor clock at 24 MHz */ 330 case BRIDGE_SN9C102:
277 if (err) 331 err += sn9c102_write_reg(cam, 0x01, 0x01); /* power down */
278 return -EIO; 332 err += sn9c102_write_reg(cam, 0x40, 0x01); /* power on */
333 err += sn9c102_write_reg(cam, 0x28, 0x17); /* clock 24 MHz */
334 break;
335 case BRIDGE_SN9C103: /* do _not_ change anything! */
336 err += sn9c102_write_reg(cam, 0x09, 0x01);
337 err += sn9c102_write_reg(cam, 0x44, 0x01);
338 err += sn9c102_write_reg(cam, 0x44, 0x02);
339 err += sn9c102_write_reg(cam, 0x29, 0x17);
340 break;
341 default:
342 break;
343 }
279 344
280 r0 = sn9c102_i2c_try_read(cam, &pas202bcb, 0x00); 345 r0 = sn9c102_i2c_try_read(cam, &pas202bcb, 0x00);
281 r1 = sn9c102_i2c_try_read(cam, &pas202bcb, 0x01); 346 r1 = sn9c102_i2c_try_read(cam, &pas202bcb, 0x01);
282 347
283 if (r0 < 0 || r1 < 0) 348 if (err || r0 < 0 || r1 < 0)
284 return -EIO; 349 return -EIO;
285 350
286 pid = (r0 << 4) | ((r1 & 0xf0) >> 4); 351 pid = (r0 << 4) | ((r1 & 0xf0) >> 4);
diff --git a/drivers/media/video/sn9c102/sn9c102_sensor.h b/drivers/media/video/sn9c102/sn9c102_sensor.h
index 2a874ee6f9..05f2942639 100644
--- a/drivers/media/video/sn9c102/sn9c102_sensor.h
+++ b/drivers/media/video/sn9c102/sn9c102_sensor.h
@@ -1,7 +1,7 @@
1/*************************************************************************** 1/***************************************************************************
2 * API for image sensors connected to the SN9C10x PC Camera Controllers * 2 * API for image sensors connected to the SN9C1xx PC Camera Controllers *
3 * * 3 * *
4 * Copyright (C) 2004-2006 by Luca Risolia <luca.risolia@studio.unibo.it> * 4 * Copyright (C) 2004-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
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 *
@@ -36,14 +36,13 @@ struct sn9c102_sensor;
36/* 36/*
37 OVERVIEW. 37 OVERVIEW.
38 This is a small interface that allows you to add support for any CCD/CMOS 38 This is a small interface that allows you to add support for any CCD/CMOS
39 image sensors connected to the SN9C10X bridges. The entire API is documented 39 image sensors connected to the SN9C1XX bridges. The entire API is documented
40 below. In the most general case, to support a sensor there are three steps 40 below. In the most general case, to support a sensor there are three steps
41 you have to follow: 41 you have to follow:
42 1) define the main "sn9c102_sensor" structure by setting the basic fields; 42 1) define the main "sn9c102_sensor" structure by setting the basic fields;
43 2) write a probing function to be called by the core module when the USB 43 2) write a probing function to be called by the core module when the USB
44 camera is recognized, then add both the USB ids and the name of that 44 camera is recognized, then add both the USB ids and the name of that
45 function to the two corresponding tables SENSOR_TABLE and ID_TABLE (see 45 function to the two corresponding tables in sn9c102_devtable.h;
46 below);
47 3) implement the methods that you want/need (and fill the rest of the main 46 3) implement the methods that you want/need (and fill the rest of the main
48 structure accordingly). 47 structure accordingly).
49 "sn9c102_pas106b.c" is an example of all this stuff. Remember that you do 48 "sn9c102_pas106b.c" is an example of all this stuff. Remember that you do
@@ -54,42 +53,21 @@ struct sn9c102_sensor;
54 53
55/*****************************************************************************/ 54/*****************************************************************************/
56 55
57/* 56enum sn9c102_bridge {
58 Probing functions: on success, you must attach the sensor to the camera 57 BRIDGE_SN9C101 = 0x01,
59 by calling sn9c102_attach_sensor() provided below. 58 BRIDGE_SN9C102 = 0x02,
60 To enable the I2C communication, you might need to perform a really basic 59 BRIDGE_SN9C103 = 0x04,
61 initialization of the SN9C10X chip by using the write function declared 60 BRIDGE_SN9C105 = 0x08,
62 ahead. 61 BRIDGE_SN9C120 = 0x10,
63 Functions must return 0 on success, the appropriate error otherwise.
64*/
65extern int sn9c102_probe_hv7131d(struct sn9c102_device* cam);
66extern int sn9c102_probe_mi0343(struct sn9c102_device* cam);
67extern int sn9c102_probe_ov7630(struct sn9c102_device* cam);
68extern int sn9c102_probe_pas106b(struct sn9c102_device* cam);
69extern int sn9c102_probe_pas202bca(struct sn9c102_device* cam);
70extern int sn9c102_probe_pas202bcb(struct sn9c102_device* cam);
71extern int sn9c102_probe_tas5110c1b(struct sn9c102_device* cam);
72extern int sn9c102_probe_tas5130d1b(struct sn9c102_device* cam);
73
74/*
75 Add the above entries to this table. Be sure to add the entry in the right
76 place, since, on failure, the next probing routine is called according to
77 the order of the list below, from top to bottom.
78*/
79#define SN9C102_SENSOR_TABLE \
80static int (*sn9c102_sensor_table[])(struct sn9c102_device*) = { \
81 &sn9c102_probe_mi0343, /* strong detection based on SENSOR ids */ \
82 &sn9c102_probe_pas106b, /* strong detection based on SENSOR ids */ \
83 &sn9c102_probe_pas202bcb, /* strong detection based on SENSOR ids */ \
84 &sn9c102_probe_hv7131d, /* strong detection based on SENSOR ids */ \
85 &sn9c102_probe_pas202bca, /* detection mostly based on USB pid/vid */ \
86 &sn9c102_probe_ov7630, /* detection mostly based on USB pid/vid */ \
87 &sn9c102_probe_tas5110c1b, /* detection based on USB pid/vid */ \
88 &sn9c102_probe_tas5130d1b, /* detection based on USB pid/vid */ \
89 NULL, \
90}; 62};
91 63
92/* Device identification */ 64/* Return the bridge name */
65enum sn9c102_bridge sn9c102_get_bridge(struct sn9c102_device* cam);
66
67/* Return a pointer the sensor struct attached to the camera */
68struct sn9c102_sensor* sn9c102_get_sensor(struct sn9c102_device* cam);
69
70/* Identify a device */
93extern struct sn9c102_device* 71extern struct sn9c102_device*
94sn9c102_match_id(struct sn9c102_device* cam, const struct usb_device_id *id); 72sn9c102_match_id(struct sn9c102_device* cam, const struct usb_device_id *id);
95 73
@@ -99,68 +77,8 @@ sn9c102_attach_sensor(struct sn9c102_device* cam,
99 struct sn9c102_sensor* sensor); 77 struct sn9c102_sensor* sensor);
100 78
101/* 79/*
102 Each SN9C10x camera has proper PID/VID identifiers.
103 SN9C103 supports multiple interfaces, but we only handle the video class
104 interface.
105*/
106#define SN9C102_USB_DEVICE(vend, prod, intclass) \
107 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
108 USB_DEVICE_ID_MATCH_INT_CLASS, \
109 .idVendor = (vend), \
110 .idProduct = (prod), \
111 .bInterfaceClass = (intclass)
112
113#define SN9C102_ID_TABLE \
114static const struct usb_device_id sn9c102_id_table[] = { \
115 { USB_DEVICE(0x0c45, 0x6001), }, /* TAS5110C1B */ \
116 { USB_DEVICE(0x0c45, 0x6005), }, /* TAS5110C1B */ \
117 { USB_DEVICE(0x0c45, 0x6007), }, \
118 { USB_DEVICE(0x0c45, 0x6009), }, /* PAS106B */ \
119 { USB_DEVICE(0x0c45, 0x600d), }, /* PAS106B */ \
120 { USB_DEVICE(0x0c45, 0x6024), }, \
121 { USB_DEVICE(0x0c45, 0x6025), }, /* TAS5130D1B and TAS5110C1B */ \
122 { USB_DEVICE(0x0c45, 0x6028), }, /* PAS202BCB */ \
123 { USB_DEVICE(0x0c45, 0x6029), }, /* PAS106B */ \
124 { USB_DEVICE(0x0c45, 0x602a), }, /* HV7131D */ \
125 { USB_DEVICE(0x0c45, 0x602b), }, /* MI-0343 */ \
126 { USB_DEVICE(0x0c45, 0x602c), }, /* OV7630 */ \
127 { USB_DEVICE(0x0c45, 0x602d), }, \
128 { USB_DEVICE(0x0c45, 0x602e), }, /* OV7630 */ \
129 { USB_DEVICE(0x0c45, 0x6030), }, /* MI03x */ \
130 { SN9C102_USB_DEVICE(0x0c45, 0x6080, 0xff), }, \
131 { SN9C102_USB_DEVICE(0x0c45, 0x6082, 0xff), }, /* MI0343 & MI0360 */ \
132 { SN9C102_USB_DEVICE(0x0c45, 0x6083, 0xff), }, /* HV7131[D|E1] */ \
133 { SN9C102_USB_DEVICE(0x0c45, 0x6088, 0xff), }, \
134 { SN9C102_USB_DEVICE(0x0c45, 0x608a, 0xff), }, \
135 { SN9C102_USB_DEVICE(0x0c45, 0x608b, 0xff), }, \
136 { SN9C102_USB_DEVICE(0x0c45, 0x608c, 0xff), }, /* HV7131/R */ \
137 { SN9C102_USB_DEVICE(0x0c45, 0x608e, 0xff), }, /* CIS-VF10 */ \
138 { SN9C102_USB_DEVICE(0x0c45, 0x608f, 0xff), }, /* OV7630 */ \
139 { SN9C102_USB_DEVICE(0x0c45, 0x60a0, 0xff), }, \
140 { SN9C102_USB_DEVICE(0x0c45, 0x60a2, 0xff), }, \
141 { SN9C102_USB_DEVICE(0x0c45, 0x60a3, 0xff), }, \
142 { SN9C102_USB_DEVICE(0x0c45, 0x60a8, 0xff), }, /* PAS106B */ \
143 { SN9C102_USB_DEVICE(0x0c45, 0x60aa, 0xff), }, /* TAS5130D1B */ \
144 { SN9C102_USB_DEVICE(0x0c45, 0x60ab, 0xff), }, /* TAS5110C1B */ \
145 { SN9C102_USB_DEVICE(0x0c45, 0x60ac, 0xff), }, \
146 { SN9C102_USB_DEVICE(0x0c45, 0x60ae, 0xff), }, \
147 { SN9C102_USB_DEVICE(0x0c45, 0x60af, 0xff), }, /* PAS202BCB */ \
148 { SN9C102_USB_DEVICE(0x0c45, 0x60b0, 0xff), }, /* OV7630 (?) */ \
149 { SN9C102_USB_DEVICE(0x0c45, 0x60b2, 0xff), }, \
150 { SN9C102_USB_DEVICE(0x0c45, 0x60b3, 0xff), }, \
151 { SN9C102_USB_DEVICE(0x0c45, 0x60b8, 0xff), }, \
152 { SN9C102_USB_DEVICE(0x0c45, 0x60ba, 0xff), }, \
153 { SN9C102_USB_DEVICE(0x0c45, 0x60bb, 0xff), }, \
154 { SN9C102_USB_DEVICE(0x0c45, 0x60bc, 0xff), }, \
155 { SN9C102_USB_DEVICE(0x0c45, 0x60be, 0xff), }, \
156 { } \
157};
158
159/*****************************************************************************/
160
161/*
162 Read/write routines: they always return -1 on error, 0 or the read value 80 Read/write routines: they always return -1 on error, 0 or the read value
163 otherwise. NOTE that a real read operation is not supported by the SN9C10X 81 otherwise. NOTE that a real read operation is not supported by the SN9C1XX
164 chip for some of its registers. To work around this problem, a pseudo-read 82 chip for some of its registers. To work around this problem, a pseudo-read
165 call is provided instead: it returns the last successfully written value 83 call is provided instead: it returns the last successfully written value
166 on the register (0 if it has never been written), the usual -1 on error. 84 on the register (0 if it has never been written), the usual -1 on error.
@@ -176,7 +94,7 @@ extern int sn9c102_i2c_try_read(struct sn9c102_device*,struct sn9c102_sensor*,
176 These must be used if and only if the sensor doesn't implement the standard 94 These must be used if and only if the sensor doesn't implement the standard
177 I2C protocol. There are a number of good reasons why you must use the 95 I2C protocol. There are a number of good reasons why you must use the
178 single-byte versions of these functions: do not abuse. The first function 96 single-byte versions of these functions: do not abuse. The first function
179 writes n bytes, from data0 to datan, to registers 0x09 - 0x09+n of SN9C10X 97 writes n bytes, from data0 to datan, to registers 0x09 - 0x09+n of SN9C1XX
180 chip. The second one programs the registers 0x09 and 0x10 with data0 and 98 chip. The second one programs the registers 0x09 and 0x10 with data0 and
181 data1, and places the n bytes read from the sensor register table in the 99 data1, and places the n bytes read from the sensor register table in the
182 buffer pointed by 'buffer'. Both the functions return -1 on error; the write 100 buffer pointed by 'buffer'. Both the functions return -1 on error; the write
@@ -200,16 +118,6 @@ extern int sn9c102_write_regs(struct sn9c102_device*, u8* buff, u16 index);
200extern int sn9c102_write_reg(struct sn9c102_device*, u8 value, u16 index); 118extern int sn9c102_write_reg(struct sn9c102_device*, u8 value, u16 index);
201extern int sn9c102_pread_reg(struct sn9c102_device*, u16 index); 119extern int sn9c102_pread_reg(struct sn9c102_device*, u16 index);
202 120
203/*
204 NOTE: there are no exported debugging functions. To uniform the output you
205 must use the dev_info()/dev_warn()/dev_err() macros defined in device.h,
206 already included here, the argument being the struct device '&usbdev->dev'
207 of the sensor structure. Do NOT use these macros before the sensor is
208 attached or the kernel will crash! However, you should not need to notify
209 the user about common errors or other messages, since this is done by the
210 master module.
211*/
212
213/*****************************************************************************/ 121/*****************************************************************************/
214 122
215enum sn9c102_i2c_sysfs_ops { 123enum sn9c102_i2c_sysfs_ops {
@@ -227,17 +135,19 @@ enum sn9c102_i2c_interface {
227 SN9C102_I2C_3WIRES, 135 SN9C102_I2C_3WIRES,
228}; 136};
229 137
230#define SN9C102_MAX_CTRLS V4L2_CID_LASTP1-V4L2_CID_BASE+10 138#define SN9C102_MAX_CTRLS (V4L2_CID_LASTP1-V4L2_CID_BASE+10)
231 139
232struct sn9c102_sensor { 140struct sn9c102_sensor {
233 char name[32], /* sensor name */ 141 char name[32], /* sensor name */
234 maintainer[64]; /* name of the mantainer <email> */ 142 maintainer[64]; /* name of the mantainer <email> */
235 143
144 enum sn9c102_bridge supported_bridge; /* supported SN9C1xx bridges */
145
236 /* Supported operations through the 'sysfs' interface */ 146 /* Supported operations through the 'sysfs' interface */
237 enum sn9c102_i2c_sysfs_ops sysfs_ops; 147 enum sn9c102_i2c_sysfs_ops sysfs_ops;
238 148
239 /* 149 /*
240 These sensor capabilities must be provided if the SN9C10X controller 150 These sensor capabilities must be provided if the SN9C1XX controller
241 needs to communicate through the sensor serial interface by using 151 needs to communicate through the sensor serial interface by using
242 at least one of the i2c functions available. 152 at least one of the i2c functions available.
243 */ 153 */
@@ -260,7 +170,7 @@ struct sn9c102_sensor {
260 /* 170 /*
261 This function will be called after the sensor has been attached. 171 This function will be called after the sensor has been attached.
262 It should be used to initialize the sensor only, but may also 172 It should be used to initialize the sensor only, but may also
263 configure part of the SN9C10X chip if necessary. You don't need to 173 configure part of the SN9C1XX chip if necessary. You don't need to
264 setup picture settings like brightness, contrast, etc.. here, if 174 setup picture settings like brightness, contrast, etc.. here, if
265 the corrisponding controls are implemented (see below), since 175 the corrisponding controls are implemented (see below), since
266 they are adjusted in the core driver by calling the set_ctrl() 176 they are adjusted in the core driver by calling the set_ctrl()
@@ -300,7 +210,7 @@ struct sn9c102_sensor {
300 It is not always true that the largest achievable active window can 210 It is not always true that the largest achievable active window can
301 cover the whole array of pixels. The V4L2 API defines another 211 cover the whole array of pixels. The V4L2 API defines another
302 area called "source rectangle", which, in turn, is a subrectangle of 212 area called "source rectangle", which, in turn, is a subrectangle of
303 the active window. The SN9C10X chip is always programmed to read the 213 the active window. The SN9C1XX chip is always programmed to read the
304 source rectangle. 214 source rectangle.
305 The bounds of both the active window and the source rectangle are 215 The bounds of both the active window and the source rectangle are
306 specified in the cropcap substructures 'bounds' and 'defrect'. 216 specified in the cropcap substructures 'bounds' and 'defrect'.
@@ -326,13 +236,13 @@ struct sn9c102_sensor {
326 const struct v4l2_rect* rect); 236 const struct v4l2_rect* rect);
327 /* 237 /*
328 To be called on VIDIOC_C_SETCROP. The core module always calls a 238 To be called on VIDIOC_C_SETCROP. The core module always calls a
329 default routine which configures the appropriate SN9C10X regs (also 239 default routine which configures the appropriate SN9C1XX regs (also
330 scaling), but you may need to override/adjust specific stuff. 240 scaling), but you may need to override/adjust specific stuff.
331 'rect' contains width and height values that are multiple of 16: in 241 'rect' contains width and height values that are multiple of 16: in
332 case you override the default function, you always have to program 242 case you override the default function, you always have to program
333 the chip to match those values; on error return the corresponding 243 the chip to match those values; on error return the corresponding
334 error code without rolling back. 244 error code without rolling back.
335 NOTE: in case, you must program the SN9C10X chip to get rid of 245 NOTE: in case, you must program the SN9C1XX chip to get rid of
336 blank pixels or blank lines at the _start_ of each line or 246 blank pixels or blank lines at the _start_ of each line or
337 frame after each HSYNC or VSYNC, so that the image starts with 247 frame after each HSYNC or VSYNC, so that the image starts with
338 real RGB data (see regs 0x12, 0x13) (having set H_SIZE and, 248 real RGB data (see regs 0x12, 0x13) (having set H_SIZE and,
@@ -344,16 +254,16 @@ struct sn9c102_sensor {
344 /* 254 /*
345 What you have to define here are: 1) initial 'width' and 'height' of 255 What you have to define here are: 1) initial 'width' and 'height' of
346 the target rectangle 2) the initial 'pixelformat', which can be 256 the target rectangle 2) the initial 'pixelformat', which can be
347 either V4L2_PIX_FMT_SN9C10X (for compressed video) or 257 either V4L2_PIX_FMT_SN9C10X, V4L2_PIX_FMT_JPEG (for ompressed video)
348 V4L2_PIX_FMT_SBGGR8 3) 'priv', which we'll be used to indicate the 258 or V4L2_PIX_FMT_SBGGR8 3) 'priv', which we'll be used to indicate
349 number of bits per pixel for uncompressed video, 8 or 9 (despite the 259 the number of bits per pixel for uncompressed video, 8 or 9 (despite
350 current value of 'pixelformat'). 260 the current value of 'pixelformat').
351 NOTE 1: both 'width' and 'height' _must_ be either 1/1 or 1/2 or 1/4 261 NOTE 1: both 'width' and 'height' _must_ be either 1/1 or 1/2 or 1/4
352 of cropcap.defrect.width and cropcap.defrect.height. I 262 of cropcap.defrect.width and cropcap.defrect.height. I
353 suggest 1/1. 263 suggest 1/1.
354 NOTE 2: The initial compression quality is defined by the first bit 264 NOTE 2: The initial compression quality is defined by the first bit
355 of reg 0x17 during the initialization of the image sensor. 265 of reg 0x17 during the initialization of the image sensor.
356 NOTE 3: as said above, you have to program the SN9C10X chip to get 266 NOTE 3: as said above, you have to program the SN9C1XX chip to get
357 rid of any blank pixels, so that the output of the sensor 267 rid of any blank pixels, so that the output of the sensor
358 matches the RGB bayer sequence (i.e. BGBGBG...GRGRGR). 268 matches the RGB bayer sequence (i.e. BGBGBG...GRGRGR).
359 */ 269 */
@@ -378,12 +288,12 @@ struct sn9c102_sensor {
378/*****************************************************************************/ 288/*****************************************************************************/
379 289
380/* Private ioctl's for control settings supported by some image sensors */ 290/* Private ioctl's for control settings supported by some image sensors */
381#define SN9C102_V4L2_CID_DAC_MAGNITUDE V4L2_CID_PRIVATE_BASE 291#define SN9C102_V4L2_CID_DAC_MAGNITUDE (V4L2_CID_PRIVATE_BASE + 0)
382#define SN9C102_V4L2_CID_GREEN_BALANCE V4L2_CID_PRIVATE_BASE + 1 292#define SN9C102_V4L2_CID_GREEN_BALANCE (V4L2_CID_PRIVATE_BASE + 1)
383#define SN9C102_V4L2_CID_RESET_LEVEL V4L2_CID_PRIVATE_BASE + 2 293#define SN9C102_V4L2_CID_RESET_LEVEL (V4L2_CID_PRIVATE_BASE + 2)
384#define SN9C102_V4L2_CID_PIXEL_BIAS_VOLTAGE V4L2_CID_PRIVATE_BASE + 3 294#define SN9C102_V4L2_CID_PIXEL_BIAS_VOLTAGE (V4L2_CID_PRIVATE_BASE + 3)
385#define SN9C102_V4L2_CID_GAMMA V4L2_CID_PRIVATE_BASE + 4 295#define SN9C102_V4L2_CID_GAMMA (V4L2_CID_PRIVATE_BASE + 4)
386#define SN9C102_V4L2_CID_BAND_FILTER V4L2_CID_PRIVATE_BASE + 5 296#define SN9C102_V4L2_CID_BAND_FILTER (V4L2_CID_PRIVATE_BASE + 5)
387#define SN9C102_V4L2_CID_BRIGHT_LEVEL V4L2_CID_PRIVATE_BASE + 6 297#define SN9C102_V4L2_CID_BRIGHT_LEVEL (V4L2_CID_PRIVATE_BASE + 6)
388 298
389#endif /* _SN9C102_SENSOR_H_ */ 299#endif /* _SN9C102_SENSOR_H_ */
diff --git a/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c b/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c
index 294eb02fbd..90023ad63a 100644
--- a/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c
+++ b/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c
@@ -1,8 +1,8 @@
1/*************************************************************************** 1/***************************************************************************
2 * Plug-in for TAS5110C1B image sensor connected to the SN9C10x PC Camera * 2 * Plug-in for TAS5110C1B image sensor connected to the SN9C1xx PC Camera *
3 * Controllers * 3 * Controllers *
4 * * 4 * *
5 * Copyright (C) 2004-2006 by Luca Risolia <luca.risolia@studio.unibo.it> * 5 * Copyright (C) 2004-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
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 *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
@@ -64,7 +64,7 @@ static int tas5110c1b_set_ctrl(struct sn9c102_device* cam,
64static int tas5110c1b_set_crop(struct sn9c102_device* cam, 64static int tas5110c1b_set_crop(struct sn9c102_device* cam,
65 const struct v4l2_rect* rect) 65 const struct v4l2_rect* rect)
66{ 66{
67 struct sn9c102_sensor* s = &tas5110c1b; 67 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
68 int err = 0; 68 int err = 0;
69 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 69, 69 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 69,
70 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 9; 70 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 9;
@@ -98,6 +98,7 @@ static int tas5110c1b_set_pix_format(struct sn9c102_device* cam,
98static struct sn9c102_sensor tas5110c1b = { 98static struct sn9c102_sensor tas5110c1b = {
99 .name = "TAS5110C1B", 99 .name = "TAS5110C1B",
100 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 100 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
101 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102 | BRIDGE_SN9C103,
101 .sysfs_ops = SN9C102_I2C_WRITE, 102 .sysfs_ops = SN9C102_I2C_WRITE,
102 .frequency = SN9C102_I2C_100KHZ, 103 .frequency = SN9C102_I2C_100KHZ,
103 .interface = SN9C102_I2C_3WIRES, 104 .interface = SN9C102_I2C_3WIRES,
@@ -145,6 +146,7 @@ int sn9c102_probe_tas5110c1b(struct sn9c102_device* cam)
145 const struct usb_device_id tas5110c1b_id_table[] = { 146 const struct usb_device_id tas5110c1b_id_table[] = {
146 { USB_DEVICE(0x0c45, 0x6001), }, 147 { USB_DEVICE(0x0c45, 0x6001), },
147 { USB_DEVICE(0x0c45, 0x6005), }, 148 { USB_DEVICE(0x0c45, 0x6005), },
149 { USB_DEVICE(0x0c45, 0x6007), },
148 { USB_DEVICE(0x0c45, 0x60ab), }, 150 { USB_DEVICE(0x0c45, 0x60ab), },
149 { } 151 { }
150 }; 152 };
diff --git a/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c b/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c
index 9ecb09032b..cb1b318bc1 100644
--- a/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c
+++ b/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c
@@ -1,8 +1,8 @@
1/*************************************************************************** 1/***************************************************************************
2 * Plug-in for TAS5130D1B image sensor connected to the SN9C10x PC Camera * 2 * Plug-in for TAS5130D1B image sensor connected to the SN9C1xx PC Camera *
3 * Controllers * 3 * Controllers *
4 * * 4 * *
5 * Copyright (C) 2004-2006 by Luca Risolia <luca.risolia@studio.unibo.it> * 5 * Copyright (C) 2004-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
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 *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
@@ -65,7 +65,7 @@ static int tas5130d1b_set_ctrl(struct sn9c102_device* cam,
65static int tas5130d1b_set_crop(struct sn9c102_device* cam, 65static int tas5130d1b_set_crop(struct sn9c102_device* cam,
66 const struct v4l2_rect* rect) 66 const struct v4l2_rect* rect)
67{ 67{
68 struct sn9c102_sensor* s = &tas5130d1b; 68 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
69 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 104, 69 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 104,
70 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 12; 70 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 12;
71 int err = 0; 71 int err = 0;
@@ -99,6 +99,7 @@ static int tas5130d1b_set_pix_format(struct sn9c102_device* cam,
99static struct sn9c102_sensor tas5130d1b = { 99static struct sn9c102_sensor tas5130d1b = {
100 .name = "TAS5130D1B", 100 .name = "TAS5130D1B",
101 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 101 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
102 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102 | BRIDGE_SN9C103,
102 .sysfs_ops = SN9C102_I2C_WRITE, 103 .sysfs_ops = SN9C102_I2C_WRITE,
103 .frequency = SN9C102_I2C_100KHZ, 104 .frequency = SN9C102_I2C_100KHZ,
104 .interface = SN9C102_I2C_3WIRES, 105 .interface = SN9C102_I2C_3WIRES,
@@ -154,6 +155,7 @@ static struct sn9c102_sensor tas5130d1b = {
154int sn9c102_probe_tas5130d1b(struct sn9c102_device* cam) 155int sn9c102_probe_tas5130d1b(struct sn9c102_device* cam)
155{ 156{
156 const struct usb_device_id tas5130d1b_id_table[] = { 157 const struct usb_device_id tas5130d1b_id_table[] = {
158 { USB_DEVICE(0x0c45, 0x6024), },
157 { USB_DEVICE(0x0c45, 0x6025), }, 159 { USB_DEVICE(0x0c45, 0x6025), },
158 { USB_DEVICE(0x0c45, 0x60aa), }, 160 { USB_DEVICE(0x0c45, 0x60aa), },
159 { } 161 { }
diff --git a/drivers/media/video/tvmixer.c b/drivers/media/video/tvmixer.c
index 7ea9132a19..3ae5a9cd2e 100644
--- a/drivers/media/video/tvmixer.c
+++ b/drivers/media/video/tvmixer.c
@@ -212,8 +212,7 @@ static int tvmixer_release(struct inode *inode, struct file *file)
212 return -ENODEV; 212 return -ENODEV;
213 } 213 }
214 214
215 if (client->adapter->owner) 215 module_put(client->adapter->owner);
216 module_put(client->adapter->owner);
217 return 0; 216 return 0;
218} 217}
219 218
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c
index bc0a4fc27b..d5ec05f56a 100644
--- a/drivers/media/video/tvp5150.c
+++ b/drivers/media/video/tvp5150.c
@@ -950,25 +950,19 @@ static int tvp5150_command(struct i2c_client *c,
950 } 950 }
951 951
952#ifdef CONFIG_VIDEO_ADV_DEBUG 952#ifdef CONFIG_VIDEO_ADV_DEBUG
953 case VIDIOC_INT_G_REGISTER: 953 case VIDIOC_DBG_G_REGISTER:
954 case VIDIOC_DBG_S_REGISTER:
954 { 955 {
955 struct v4l2_register *reg = arg; 956 struct v4l2_register *reg = arg;
956 957
957 if (reg->i2c_id != I2C_DRIVERID_TVP5150) 958 if (!v4l2_chip_match_i2c_client(c, reg->match_type, reg->match_chip))
958 return -EINVAL;
959 reg->val = tvp5150_read(c, reg->reg & 0xff);
960 break;
961 }
962
963 case VIDIOC_INT_S_REGISTER:
964 {
965 struct v4l2_register *reg = arg;
966
967 if (reg->i2c_id != I2C_DRIVERID_TVP5150)
968 return -EINVAL; 959 return -EINVAL;
969 if (!capable(CAP_SYS_ADMIN)) 960 if (!capable(CAP_SYS_ADMIN))
970 return -EPERM; 961 return -EPERM;
971 tvp5150_write(c, reg->reg & 0xff, reg->val & 0xff); 962 if (cmd == VIDIOC_DBG_G_REGISTER)
963 reg->val = tvp5150_read(c, reg->reg & 0xff);
964 else
965 tvp5150_write(c, reg->reg & 0xff, reg->val & 0xff);
972 break; 966 break;
973 } 967 }
974#endif 968#endif
diff --git a/drivers/media/video/upd64031a.c b/drivers/media/video/upd64031a.c
index fc52201d60..28d1133a3b 100644
--- a/drivers/media/video/upd64031a.c
+++ b/drivers/media/video/upd64031a.c
@@ -162,27 +162,19 @@ static int upd64031a_command(struct i2c_client *client, unsigned int cmd, void *
162 break; 162 break;
163 163
164#ifdef CONFIG_VIDEO_ADV_DEBUG 164#ifdef CONFIG_VIDEO_ADV_DEBUG
165 case VIDIOC_INT_G_REGISTER: 165 case VIDIOC_DBG_G_REGISTER:
166 case VIDIOC_DBG_S_REGISTER:
166 { 167 {
167 struct v4l2_register *reg = arg; 168 struct v4l2_register *reg = arg;
168 169
169 if (reg->i2c_id != I2C_DRIVERID_UPD64031A) 170 if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip))
170 return -EINVAL;
171 reg->val = upd64031a_read(client, reg->reg & 0xff);
172 break;
173 }
174
175 case VIDIOC_INT_S_REGISTER:
176 {
177 struct v4l2_register *reg = arg;
178 u8 addr = reg->reg & 0xff;
179 u8 val = reg->val & 0xff;
180
181 if (reg->i2c_id != I2C_DRIVERID_UPD64031A)
182 return -EINVAL; 171 return -EINVAL;
183 if (!capable(CAP_SYS_ADMIN)) 172 if (!capable(CAP_SYS_ADMIN))
184 return -EPERM; 173 return -EPERM;
185 upd64031a_write(client, addr, val); 174 if (cmd == VIDIOC_DBG_G_REGISTER)
175 reg->val = upd64031a_read(client, reg->reg & 0xff);
176 else
177 upd64031a_write(client, reg->reg & 0xff, reg->val & 0xff);
186 break; 178 break;
187 } 179 }
188#endif 180#endif
diff --git a/drivers/media/video/upd64083.c b/drivers/media/video/upd64083.c
index c3a7ffe5c2..fe38224150 100644
--- a/drivers/media/video/upd64083.c
+++ b/drivers/media/video/upd64083.c
@@ -139,27 +139,19 @@ static int upd64083_command(struct i2c_client *client, unsigned int cmd, void *a
139 break; 139 break;
140 140
141#ifdef CONFIG_VIDEO_ADV_DEBUG 141#ifdef CONFIG_VIDEO_ADV_DEBUG
142 case VIDIOC_INT_G_REGISTER: 142 case VIDIOC_DBG_G_REGISTER:
143 case VIDIOC_DBG_S_REGISTER:
143 { 144 {
144 struct v4l2_register *reg = arg; 145 struct v4l2_register *reg = arg;
145 146
146 if (reg->i2c_id != I2C_DRIVERID_UPD64083) 147 if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip))
147 return -EINVAL;
148 reg->val = upd64083_read(client, reg->reg & 0xff);
149 break;
150 }
151
152 case VIDIOC_INT_S_REGISTER:
153 {
154 struct v4l2_register *reg = arg;
155 u8 addr = reg->reg & 0xff;
156 u8 val = reg->val & 0xff;
157
158 if (reg->i2c_id != I2C_DRIVERID_UPD64083)
159 return -EINVAL; 148 return -EINVAL;
160 if (!capable(CAP_SYS_ADMIN)) 149 if (!capable(CAP_SYS_ADMIN))
161 return -EPERM; 150 return -EPERM;
162 upd64083_write(client, addr, val); 151 if (cmd == VIDIOC_DBG_G_REGISTER)
152 reg->val = upd64083_read(client, reg->reg & 0xff);
153 else
154 upd64083_write(client, reg->reg & 0xff, reg->val & 0xff);
163 break; 155 break;
164 } 156 }
165#endif 157#endif
diff --git a/drivers/media/video/usbvision/Kconfig b/drivers/media/video/usbvision/Kconfig
index fc24ef05b3..c43a5d8990 100644
--- a/drivers/media/video/usbvision/Kconfig
+++ b/drivers/media/video/usbvision/Kconfig
@@ -1,6 +1,6 @@
1config VIDEO_USBVISION 1config VIDEO_USBVISION
2 tristate "USB video devices based on Nogatech NT1003/1004/1005" 2 tristate "USB video devices based on Nogatech NT1003/1004/1005"
3 depends on I2C && VIDEO_V4L2 3 depends on I2C && VIDEO_V4L2 && USB
4 select VIDEO_TUNER 4 select VIDEO_TUNER
5 select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO 5 select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO
6 ---help--- 6 ---help---
diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
index 901f664dc6..f2154dc072 100644
--- a/drivers/media/video/usbvision/usbvision-core.c
+++ b/drivers/media/video/usbvision/usbvision-core.c
@@ -138,7 +138,7 @@ static void *usbvision_rvmalloc(unsigned long size)
138 return mem; 138 return mem;
139} 139}
140 140
141void usbvision_rvfree(void *mem, unsigned long size) 141static void usbvision_rvfree(void *mem, unsigned long size)
142{ 142{
143 unsigned long adr; 143 unsigned long adr;
144 144
@@ -1852,28 +1852,33 @@ int usbvision_set_output(struct usb_usbvision *usbvision, int width,
1852 1852
1853/* 1853/*
1854 * usbvision_frames_alloc 1854 * usbvision_frames_alloc
1855 * allocate the maximum frames this driver can manage 1855 * allocate the required frames
1856 */ 1856 */
1857int usbvision_frames_alloc(struct usb_usbvision *usbvision) 1857int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames)
1858{ 1858{
1859 int i; 1859 int i;
1860 1860
1861 /* Allocate memory for the frame buffers */ 1861 /*needs to be page aligned cause the buffers can be mapped individually! */
1862 usbvision->max_frame_size = MAX_FRAME_SIZE; 1862 usbvision->max_frame_size = PAGE_ALIGN(usbvision->curwidth *
1863 usbvision->fbuf_size = USBVISION_NUMFRAMES * usbvision->max_frame_size; 1863 usbvision->curheight *
1864 usbvision->fbuf = usbvision_rvmalloc(usbvision->fbuf_size); 1864 usbvision->palette.bytes_per_pixel);
1865 1865
1866 if(usbvision->fbuf == NULL) { 1866 /* Try to do my best to allocate the frames the user want in the remaining memory */
1867 err("%s: unable to allocate %d bytes for fbuf ", 1867 usbvision->num_frames = number_of_frames;
1868 __FUNCTION__, usbvision->fbuf_size); 1868 while (usbvision->num_frames > 0) {
1869 return -ENOMEM; 1869 usbvision->fbuf_size = usbvision->num_frames * usbvision->max_frame_size;
1870 if((usbvision->fbuf = usbvision_rvmalloc(usbvision->fbuf_size))) {
1871 break;
1872 }
1873 usbvision->num_frames--;
1870 } 1874 }
1875
1871 spin_lock_init(&usbvision->queue_lock); 1876 spin_lock_init(&usbvision->queue_lock);
1872 init_waitqueue_head(&usbvision->wait_frame); 1877 init_waitqueue_head(&usbvision->wait_frame);
1873 init_waitqueue_head(&usbvision->wait_stream); 1878 init_waitqueue_head(&usbvision->wait_stream);
1874 1879
1875 /* Allocate all buffers */ 1880 /* Allocate all buffers */
1876 for (i = 0; i < USBVISION_NUMFRAMES; i++) { 1881 for (i = 0; i < usbvision->num_frames; i++) {
1877 usbvision->frame[i].index = i; 1882 usbvision->frame[i].index = i;
1878 usbvision->frame[i].grabstate = FrameState_Unused; 1883 usbvision->frame[i].grabstate = FrameState_Unused;
1879 usbvision->frame[i].data = usbvision->fbuf + 1884 usbvision->frame[i].data = usbvision->fbuf +
@@ -1887,7 +1892,8 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision)
1887 usbvision->frame[i].height = usbvision->curheight; 1892 usbvision->frame[i].height = usbvision->curheight;
1888 usbvision->frame[i].bytes_read = 0; 1893 usbvision->frame[i].bytes_read = 0;
1889 } 1894 }
1890 return 0; 1895 PDEBUG(DBG_FUNC, "allocated %d frames (%d bytes per frame)",usbvision->num_frames,usbvision->max_frame_size);
1896 return usbvision->num_frames;
1891} 1897}
1892 1898
1893/* 1899/*
@@ -1897,9 +1903,13 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision)
1897void usbvision_frames_free(struct usb_usbvision *usbvision) 1903void usbvision_frames_free(struct usb_usbvision *usbvision)
1898{ 1904{
1899 /* Have to free all that memory */ 1905 /* Have to free all that memory */
1906 PDEBUG(DBG_FUNC, "free %d frames",usbvision->num_frames);
1907
1900 if (usbvision->fbuf != NULL) { 1908 if (usbvision->fbuf != NULL) {
1901 usbvision_rvfree(usbvision->fbuf, usbvision->fbuf_size); 1909 usbvision_rvfree(usbvision->fbuf, usbvision->fbuf_size);
1902 usbvision->fbuf = NULL; 1910 usbvision->fbuf = NULL;
1911
1912 usbvision->num_frames = 0;
1903 } 1913 }
1904} 1914}
1905/* 1915/*
@@ -2351,6 +2361,32 @@ int usbvision_setup(struct usb_usbvision *usbvision,int format)
2351 return USBVISION_IS_OPERATIONAL(usbvision); 2361 return USBVISION_IS_OPERATIONAL(usbvision);
2352} 2362}
2353 2363
2364int usbvision_set_alternate(struct usb_usbvision *dev)
2365{
2366 int errCode, prev_alt = dev->ifaceAlt;
2367 int i;
2368
2369 dev->ifaceAlt=0;
2370 for(i=0;i< dev->num_alt; i++)
2371 if(dev->alt_max_pkt_size[i]>dev->alt_max_pkt_size[dev->ifaceAlt])
2372 dev->ifaceAlt=i;
2373
2374 if (dev->ifaceAlt != prev_alt) {
2375 dev->isocPacketSize = dev->alt_max_pkt_size[dev->ifaceAlt];
2376 PDEBUG(DBG_FUNC,"setting alternate %d with wMaxPacketSize=%u", dev->ifaceAlt,dev->isocPacketSize);
2377 errCode = usb_set_interface(dev->dev, dev->iface, dev->ifaceAlt);
2378 if (errCode < 0) {
2379 err ("cannot change alternate number to %d (error=%i)",
2380 dev->ifaceAlt, errCode);
2381 return errCode;
2382 }
2383 }
2384
2385 PDEBUG(DBG_ISOC, "ISO Packet Length:%d", dev->isocPacketSize);
2386
2387 return 0;
2388}
2389
2354/* 2390/*
2355 * usbvision_init_isoc() 2391 * usbvision_init_isoc()
2356 * 2392 *
@@ -2368,15 +2404,13 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2368 scratch_reset(usbvision); 2404 scratch_reset(usbvision);
2369 2405
2370 /* Alternate interface 1 is is the biggest frame size */ 2406 /* Alternate interface 1 is is the biggest frame size */
2371 errCode = usb_set_interface(dev, usbvision->iface, usbvision->ifaceAltActive); 2407 errCode = usbvision_set_alternate(usbvision);
2372 if (errCode < 0) { 2408 if (errCode < 0) {
2373 usbvision->last_error = errCode; 2409 usbvision->last_error = errCode;
2374 return -EBUSY; 2410 return -EBUSY;
2375 } 2411 }
2376 2412
2377 regValue = (16 - usbvision_read_reg(usbvision, USBVISION_ALTER_REG)) & 0x0F; 2413 regValue = (16 - usbvision_read_reg(usbvision, USBVISION_ALTER_REG)) & 0x0F;
2378 usbvision->isocPacketSize = (regValue == 0) ? 0 : (regValue * 64) - 1;
2379 PDEBUG(DBG_ISOC, "ISO Packet Length:%d", usbvision->isocPacketSize);
2380 2414
2381 usbvision->usb_bandwidth = regValue >> 1; 2415 usbvision->usb_bandwidth = regValue >> 1;
2382 PDEBUG(DBG_ISOC, "USB Bandwidth Usage: %dMbit/Sec", usbvision->usb_bandwidth); 2416 PDEBUG(DBG_ISOC, "USB Bandwidth Usage: %dMbit/Sec", usbvision->usb_bandwidth);
@@ -2462,8 +2496,9 @@ void usbvision_stop_isoc(struct usb_usbvision *usbvision)
2462 if (!usbvision->remove_pending) { 2496 if (!usbvision->remove_pending) {
2463 2497
2464 /* Set packet size to 0 */ 2498 /* Set packet size to 0 */
2499 usbvision->ifaceAlt=0;
2465 errCode = usb_set_interface(usbvision->dev, usbvision->iface, 2500 errCode = usb_set_interface(usbvision->dev, usbvision->iface,
2466 usbvision->ifaceAltInactive); 2501 usbvision->ifaceAlt);
2467 if (errCode < 0) { 2502 if (errCode < 0) {
2468 err("%s: usb_set_interface() failed: error %d", __FUNCTION__, errCode); 2503 err("%s: usb_set_interface() failed: error %d", __FUNCTION__, errCode);
2469 usbvision->last_error = errCode; 2504 usbvision->last_error = errCode;
@@ -2490,6 +2525,7 @@ int usbvision_muxsel(struct usb_usbvision *usbvision, int channel)
2490 RESTRICT_TO_RANGE(channel, 0, usbvision->video_inputs); 2525 RESTRICT_TO_RANGE(channel, 0, usbvision->video_inputs);
2491 usbvision->ctl_input = channel; 2526 usbvision->ctl_input = channel;
2492 route.input = SAA7115_COMPOSITE1; 2527 route.input = SAA7115_COMPOSITE1;
2528 route.output = 0;
2493 call_i2c_clients(usbvision, VIDIOC_INT_S_VIDEO_ROUTING,&route); 2529 call_i2c_clients(usbvision, VIDIOC_INT_S_VIDEO_ROUTING,&route);
2494 call_i2c_clients(usbvision, VIDIOC_S_INPUT, &usbvision->ctl_input); 2530 call_i2c_clients(usbvision, VIDIOC_S_INPUT, &usbvision->ctl_input);
2495 2531
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index af33653f0d..6fc14557d6 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -230,7 +230,7 @@ static ssize_t show_hue(struct class_device *cd, char *buf)
230 ctrl.value = 0; 230 ctrl.value = 0;
231 if(usbvision->user) 231 if(usbvision->user)
232 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 232 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
233 return sprintf(buf, "%d\n", ctrl.value >> 8); 233 return sprintf(buf, "%d\n", ctrl.value);
234} 234}
235static CLASS_DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL); 235static CLASS_DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
236 236
@@ -243,7 +243,7 @@ static ssize_t show_contrast(struct class_device *cd, char *buf)
243 ctrl.value = 0; 243 ctrl.value = 0;
244 if(usbvision->user) 244 if(usbvision->user)
245 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 245 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
246 return sprintf(buf, "%d\n", ctrl.value >> 8); 246 return sprintf(buf, "%d\n", ctrl.value);
247} 247}
248static CLASS_DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL); 248static CLASS_DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
249 249
@@ -256,7 +256,7 @@ static ssize_t show_brightness(struct class_device *cd, char *buf)
256 ctrl.value = 0; 256 ctrl.value = 0;
257 if(usbvision->user) 257 if(usbvision->user)
258 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 258 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
259 return sprintf(buf, "%d\n", ctrl.value >> 8); 259 return sprintf(buf, "%d\n", ctrl.value);
260} 260}
261static CLASS_DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL); 261static CLASS_DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
262 262
@@ -269,7 +269,7 @@ static ssize_t show_saturation(struct class_device *cd, char *buf)
269 ctrl.value = 0; 269 ctrl.value = 0;
270 if(usbvision->user) 270 if(usbvision->user)
271 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 271 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
272 return sprintf(buf, "%d\n", ctrl.value >> 8); 272 return sprintf(buf, "%d\n", ctrl.value);
273} 273}
274static CLASS_DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL); 274static CLASS_DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
275 275
@@ -391,19 +391,14 @@ static int usbvision_v4l2_open(struct inode *inode, struct file *file)
391 if (usbvision->user) 391 if (usbvision->user)
392 errCode = -EBUSY; 392 errCode = -EBUSY;
393 else { 393 else {
394 /* Allocate memory for the frame buffers */ 394 /* Allocate memory for the scratch ring buffer */
395 errCode = usbvision_frames_alloc(usbvision); 395 errCode = usbvision_scratch_alloc(usbvision);
396 if(!errCode) { 396 if (isocMode==ISOC_MODE_COMPRESS) {
397 /* Allocate memory for the scratch ring buffer */ 397 /* Allocate intermediate decompression buffers only if needed */
398 errCode = usbvision_scratch_alloc(usbvision); 398 errCode = usbvision_decompress_alloc(usbvision);
399 if ((!errCode) && (isocMode==ISOC_MODE_COMPRESS)) {
400 /* Allocate intermediate decompression buffers only if needed */
401 errCode = usbvision_decompress_alloc(usbvision);
402 }
403 } 399 }
404 if (errCode) { 400 if (errCode) {
405 /* Deallocate all buffers if trouble */ 401 /* Deallocate all buffers if trouble */
406 usbvision_frames_free(usbvision);
407 usbvision_scratch_free(usbvision); 402 usbvision_scratch_free(usbvision);
408 usbvision_decompress_free(usbvision); 403 usbvision_decompress_free(usbvision);
409 } 404 }
@@ -476,6 +471,7 @@ static int usbvision_v4l2_close(struct inode *inode, struct file *file)
476 471
477 usbvision_decompress_free(usbvision); 472 usbvision_decompress_free(usbvision);
478 usbvision_frames_free(usbvision); 473 usbvision_frames_free(usbvision);
474 usbvision_empty_framequeues(usbvision);
479 usbvision_scratch_free(usbvision); 475 usbvision_scratch_free(usbvision);
480 476
481 usbvision->user--; 477 usbvision->user--;
@@ -489,7 +485,7 @@ static int usbvision_v4l2_close(struct inode *inode, struct file *file)
489 up(&usbvision->lock); 485 up(&usbvision->lock);
490 486
491 if (usbvision->remove_pending) { 487 if (usbvision->remove_pending) {
492 info("%s: Final disconnect", __FUNCTION__); 488 printk(KERN_INFO "%s: Final disconnect\n", __FUNCTION__);
493 usbvision_release(usbvision); 489 usbvision_release(usbvision);
494 } 490 }
495 491
@@ -519,44 +515,32 @@ static int usbvision_v4l2_do_ioctl(struct inode *inode, struct file *file,
519 515
520#ifdef CONFIG_VIDEO_ADV_DEBUG 516#ifdef CONFIG_VIDEO_ADV_DEBUG
521 /* ioctls to allow direct acces to the NT100x registers */ 517 /* ioctls to allow direct acces to the NT100x registers */
522 case VIDIOC_INT_G_REGISTER: 518 case VIDIOC_DBG_G_REGISTER:
519 case VIDIOC_DBG_S_REGISTER:
523 { 520 {
524 struct v4l2_register *reg = arg; 521 struct v4l2_register *reg = arg;
525 int errCode; 522 int errCode;
526 523
527 if (reg->i2c_id != 0) 524 if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
528 return -EINVAL;
529 /* NT100x has a 8-bit register space */
530 errCode = usbvision_read_reg(usbvision, reg->reg&0xff);
531 if (errCode < 0) {
532 err("%s: VIDIOC_INT_G_REGISTER failed: error %d", __FUNCTION__, errCode);
533 }
534 else {
535 reg->val=(unsigned char)errCode;
536 PDEBUG(DBG_IOCTL, "VIDIOC_INT_G_REGISTER reg=0x%02X, value=0x%02X",
537 (unsigned int)reg->reg, reg->val);
538 errCode = 0; // No error
539 }
540 return errCode;
541 }
542 case VIDIOC_INT_S_REGISTER:
543 {
544 struct v4l2_register *reg = arg;
545 int errCode;
546
547 if (reg->i2c_id != 0)
548 return -EINVAL; 525 return -EINVAL;
549 if (!capable(CAP_SYS_ADMIN)) 526 if (!capable(CAP_SYS_ADMIN))
550 return -EPERM; 527 return -EPERM;
551 errCode = usbvision_write_reg(usbvision, reg->reg&0xff, reg->val); 528 /* NT100x has a 8-bit register space */
529 if (cmd == VIDIOC_DBG_G_REGISTER)
530 errCode = usbvision_read_reg(usbvision, reg->reg&0xff);
531 else
532 errCode = usbvision_write_reg(usbvision, reg->reg&0xff, reg->val);
552 if (errCode < 0) { 533 if (errCode < 0) {
553 err("%s: VIDIOC_INT_S_REGISTER failed: error %d", __FUNCTION__, errCode); 534 err("%s: VIDIOC_DBG_%c_REGISTER failed: error %d", __FUNCTION__,
554 } 535 cmd == VIDIOC_DBG_G_REGISTER ? 'G' : 'S', errCode);
555 else { 536 return errCode;
556 PDEBUG(DBG_IOCTL, "VIDIOC_INT_S_REGISTER reg=0x%02X, value=0x%02X",
557 (unsigned int)reg->reg, reg->val);
558 errCode = 0;
559 } 537 }
538 if (cmd == VIDIOC_DBG_S_REGISTER)
539 reg->val = (u8)errCode;
540
541 PDEBUG(DBG_IOCTL, "VIDIOC_DBG_%c_REGISTER reg=0x%02X, value=0x%02X",
542 cmd == VIDIOC_DBG_G_REGISTER ? 'G' : 'S',
543 (unsigned int)reg->reg, (unsigned int)reg->val);
560 return 0; 544 return 0;
561 } 545 }
562#endif 546#endif
@@ -792,8 +776,8 @@ static int usbvision_v4l2_do_ioctl(struct inode *inode, struct file *file,
792 case VIDIOC_G_CTRL: 776 case VIDIOC_G_CTRL:
793 { 777 {
794 struct v4l2_control *ctrl = arg; 778 struct v4l2_control *ctrl = arg;
795 PDEBUG(DBG_IOCTL,"VIDIOC_G_CTRL id=%x value=%x",ctrl->id,ctrl->value);
796 call_i2c_clients(usbvision, VIDIOC_G_CTRL, ctrl); 779 call_i2c_clients(usbvision, VIDIOC_G_CTRL, ctrl);
780 PDEBUG(DBG_IOCTL,"VIDIOC_G_CTRL id=%x value=%x",ctrl->id,ctrl->value);
797 return 0; 781 return 0;
798 } 782 }
799 case VIDIOC_S_CTRL: 783 case VIDIOC_S_CTRL:
@@ -821,7 +805,9 @@ static int usbvision_v4l2_do_ioctl(struct inode *inode, struct file *file,
821 return ret; 805 return ret;
822 } 806 }
823 807
808 usbvision_frames_free(usbvision);
824 usbvision_empty_framequeues(usbvision); 809 usbvision_empty_framequeues(usbvision);
810 vr->count = usbvision_frames_alloc(usbvision,vr->count);
825 811
826 usbvision->curFrame = NULL; 812 usbvision->curFrame = NULL;
827 813
@@ -838,7 +824,7 @@ static int usbvision_v4l2_do_ioctl(struct inode *inode, struct file *file,
838 if(vb->type != V4L2_CAP_VIDEO_CAPTURE) { 824 if(vb->type != V4L2_CAP_VIDEO_CAPTURE) {
839 return -EINVAL; 825 return -EINVAL;
840 } 826 }
841 if(vb->index>=USBVISION_NUMFRAMES) { 827 if(vb->index>=usbvision->num_frames) {
842 return -EINVAL; 828 return -EINVAL;
843 } 829 }
844 // Updating the corresponding frame state 830 // Updating the corresponding frame state
@@ -852,7 +838,7 @@ static int usbvision_v4l2_do_ioctl(struct inode *inode, struct file *file,
852 vb->flags |= V4L2_BUF_FLAG_MAPPED; 838 vb->flags |= V4L2_BUF_FLAG_MAPPED;
853 vb->memory = V4L2_MEMORY_MMAP; 839 vb->memory = V4L2_MEMORY_MMAP;
854 840
855 vb->m.offset = vb->index*usbvision->max_frame_size; 841 vb->m.offset = vb->index*PAGE_ALIGN(usbvision->max_frame_size);
856 842
857 vb->memory = V4L2_MEMORY_MMAP; 843 vb->memory = V4L2_MEMORY_MMAP;
858 vb->field = V4L2_FIELD_NONE; 844 vb->field = V4L2_FIELD_NONE;
@@ -871,7 +857,7 @@ static int usbvision_v4l2_do_ioctl(struct inode *inode, struct file *file,
871 if(vb->type != V4L2_CAP_VIDEO_CAPTURE) { 857 if(vb->type != V4L2_CAP_VIDEO_CAPTURE) {
872 return -EINVAL; 858 return -EINVAL;
873 } 859 }
874 if(vb->index>=USBVISION_NUMFRAMES) { 860 if(vb->index>=usbvision->num_frames) {
875 return -EINVAL; 861 return -EINVAL;
876 } 862 }
877 863
@@ -1041,6 +1027,7 @@ static int usbvision_v4l2_do_ioctl(struct inode *inode, struct file *file,
1041 if ((ret = usbvision_stream_interrupt(usbvision))) 1027 if ((ret = usbvision_stream_interrupt(usbvision)))
1042 return ret; 1028 return ret;
1043 } 1029 }
1030 usbvision_frames_free(usbvision);
1044 usbvision_empty_framequeues(usbvision); 1031 usbvision_empty_framequeues(usbvision);
1045 1032
1046 usbvision->curFrame = NULL; 1033 usbvision->curFrame = NULL;
@@ -1087,12 +1074,24 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1087 if (!USBVISION_IS_OPERATIONAL(usbvision) || (buf == NULL)) 1074 if (!USBVISION_IS_OPERATIONAL(usbvision) || (buf == NULL))
1088 return -EFAULT; 1075 return -EFAULT;
1089 1076
1090 /* no stream is running, make it running ! */ 1077 /* This entry point is compatible with the mmap routines so that a user can do either
1091 usbvision->streaming = Stream_On; 1078 VIDIOC_QBUF/VIDIOC_DQBUF to get frames or call read on the device. */
1092 call_i2c_clients(usbvision,VIDIOC_STREAMON , NULL); 1079 if(!usbvision->num_frames) {
1080 /* First, allocate some frames to work with if this has not been done with
1081 VIDIOC_REQBUF */
1082 usbvision_frames_free(usbvision);
1083 usbvision_empty_framequeues(usbvision);
1084 usbvision_frames_alloc(usbvision,USBVISION_NUMFRAMES);
1085 }
1086
1087 if(usbvision->streaming != Stream_On) {
1088 /* no stream is running, make it running ! */
1089 usbvision->streaming = Stream_On;
1090 call_i2c_clients(usbvision,VIDIOC_STREAMON , NULL);
1091 }
1093 1092
1094 /* First, enqueue as many frames as possible (like a user of VIDIOC_QBUF would do) */ 1093 /* Then, enqueue as many frames as possible (like a user of VIDIOC_QBUF would do) */
1095 for(i=0;i<USBVISION_NUMFRAMES;i++) { 1094 for(i=0;i<usbvision->num_frames;i++) {
1096 frame = &usbvision->frame[i]; 1095 frame = &usbvision->frame[i];
1097 if(frame->grabstate == FrameState_Unused) { 1096 if(frame->grabstate == FrameState_Unused) {
1098 /* Mark it as ready and enqueue frame */ 1097 /* Mark it as ready and enqueue frame */
@@ -1169,6 +1168,8 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1169 struct video_device *dev = video_devdata(file); 1168 struct video_device *dev = video_devdata(file);
1170 struct usb_usbvision *usbvision = (struct usb_usbvision *) video_get_drvdata(dev); 1169 struct usb_usbvision *usbvision = (struct usb_usbvision *) video_get_drvdata(dev);
1171 1170
1171 PDEBUG(DBG_MMAP, "mmap");
1172
1172 down(&usbvision->lock); 1173 down(&usbvision->lock);
1173 1174
1174 if (!USBVISION_IS_OPERATIONAL(usbvision)) { 1175 if (!USBVISION_IS_OPERATIONAL(usbvision)) {
@@ -1177,16 +1178,16 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1177 } 1178 }
1178 1179
1179 if (!(vma->vm_flags & VM_WRITE) || 1180 if (!(vma->vm_flags & VM_WRITE) ||
1180 size != PAGE_ALIGN(usbvision->curwidth*usbvision->curheight*usbvision->palette.bytes_per_pixel)) { 1181 size != PAGE_ALIGN(usbvision->max_frame_size)) {
1181 up(&usbvision->lock); 1182 up(&usbvision->lock);
1182 return -EINVAL; 1183 return -EINVAL;
1183 } 1184 }
1184 1185
1185 for (i = 0; i < USBVISION_NUMFRAMES; i++) { 1186 for (i = 0; i < usbvision->num_frames; i++) {
1186 if (((usbvision->max_frame_size*i) >> PAGE_SHIFT) == vma->vm_pgoff) 1187 if (((PAGE_ALIGN(usbvision->max_frame_size)*i) >> PAGE_SHIFT) == vma->vm_pgoff)
1187 break; 1188 break;
1188 } 1189 }
1189 if (i == USBVISION_NUMFRAMES) { 1190 if (i == usbvision->num_frames) {
1190 PDEBUG(DBG_MMAP, "mmap: user supplied mapping address is out of range"); 1191 PDEBUG(DBG_MMAP, "mmap: user supplied mapping address is out of range");
1191 up(&usbvision->lock); 1192 up(&usbvision->lock);
1192 return -EINVAL; 1193 return -EINVAL;
@@ -1242,6 +1243,13 @@ static int usbvision_radio_open(struct inode *inode, struct file *file)
1242 } 1243 }
1243 } 1244 }
1244 1245
1246 /* Alternate interface 1 is is the biggest frame size */
1247 errCode = usbvision_set_alternate(usbvision);
1248 if (errCode < 0) {
1249 usbvision->last_error = errCode;
1250 return -EBUSY;
1251 }
1252
1245 // If so far no errors then we shall start the radio 1253 // If so far no errors then we shall start the radio
1246 usbvision->radio = 1; 1254 usbvision->radio = 1;
1247 call_i2c_clients(usbvision,AUDC_SET_RADIO,&usbvision->tuner_type); 1255 call_i2c_clients(usbvision,AUDC_SET_RADIO,&usbvision->tuner_type);
@@ -1273,6 +1281,11 @@ static int usbvision_radio_close(struct inode *inode, struct file *file)
1273 1281
1274 down(&usbvision->lock); 1282 down(&usbvision->lock);
1275 1283
1284 /* Set packet size to 0 */
1285 usbvision->ifaceAlt=0;
1286 errCode = usb_set_interface(usbvision->dev, usbvision->iface,
1287 usbvision->ifaceAlt);
1288
1276 usbvision_audio_off(usbvision); 1289 usbvision_audio_off(usbvision);
1277 usbvision->radio=0; 1290 usbvision->radio=0;
1278 usbvision->user--; 1291 usbvision->user--;
@@ -1285,7 +1298,7 @@ static int usbvision_radio_close(struct inode *inode, struct file *file)
1285 up(&usbvision->lock); 1298 up(&usbvision->lock);
1286 1299
1287 if (usbvision->remove_pending) { 1300 if (usbvision->remove_pending) {
1288 info("%s: Final disconnect", __FUNCTION__); 1301 printk(KERN_INFO "%s: Final disconnect\n", __FUNCTION__);
1289 usbvision_release(usbvision); 1302 usbvision_release(usbvision);
1290 } 1303 }
1291 1304
@@ -1611,7 +1624,7 @@ static int __devinit usbvision_register_video(struct usb_usbvision *usbvision)
1611 if (video_register_device(usbvision->vdev, VFL_TYPE_GRABBER, video_nr)<0) { 1624 if (video_register_device(usbvision->vdev, VFL_TYPE_GRABBER, video_nr)<0) {
1612 goto err_exit; 1625 goto err_exit;
1613 } 1626 }
1614 info("USBVision[%d]: registered USBVision Video device /dev/video%d [v4l2]", usbvision->nr,usbvision->vdev->minor & 0x1f); 1627 printk(KERN_INFO "USBVision[%d]: registered USBVision Video device /dev/video%d [v4l2]\n", usbvision->nr,usbvision->vdev->minor & 0x1f);
1615 1628
1616 // Radio Device: 1629 // Radio Device:
1617 if (usbvision_device_data[usbvision->DevModel].Radio) { 1630 if (usbvision_device_data[usbvision->DevModel].Radio) {
@@ -1623,7 +1636,7 @@ static int __devinit usbvision_register_video(struct usb_usbvision *usbvision)
1623 if (video_register_device(usbvision->rdev, VFL_TYPE_RADIO, radio_nr)<0) { 1636 if (video_register_device(usbvision->rdev, VFL_TYPE_RADIO, radio_nr)<0) {
1624 goto err_exit; 1637 goto err_exit;
1625 } 1638 }
1626 info("USBVision[%d]: registered USBVision Radio device /dev/radio%d [v4l2]", usbvision->nr, usbvision->rdev->minor & 0x1f); 1639 printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device /dev/radio%d [v4l2]\n", usbvision->nr, usbvision->rdev->minor & 0x1f);
1627 } 1640 }
1628 // vbi Device: 1641 // vbi Device:
1629 if (usbvision_device_data[usbvision->DevModel].vbi) { 1642 if (usbvision_device_data[usbvision->DevModel].vbi) {
@@ -1634,7 +1647,7 @@ static int __devinit usbvision_register_video(struct usb_usbvision *usbvision)
1634 if (video_register_device(usbvision->vbi, VFL_TYPE_VBI, vbi_nr)<0) { 1647 if (video_register_device(usbvision->vbi, VFL_TYPE_VBI, vbi_nr)<0) {
1635 goto err_exit; 1648 goto err_exit;
1636 } 1649 }
1637 info("USBVision[%d]: registered USBVision VBI device /dev/vbi%d [v4l2] (Not Working Yet!)", usbvision->nr,usbvision->vbi->minor & 0x1f); 1650 printk(KERN_INFO "USBVision[%d]: registered USBVision VBI device /dev/vbi%d [v4l2] (Not Working Yet!)\n", usbvision->nr,usbvision->vbi->minor & 0x1f);
1638 } 1651 }
1639 // all done 1652 // all done
1640 return 0; 1653 return 0;
@@ -1764,15 +1777,17 @@ static void usbvision_configure_video(struct usb_usbvision *usbvision)
1764 */ 1777 */
1765static int __devinit usbvision_probe(struct usb_interface *intf, const struct usb_device_id *devid) 1778static int __devinit usbvision_probe(struct usb_interface *intf, const struct usb_device_id *devid)
1766{ 1779{
1767 struct usb_device *dev = interface_to_usbdev(intf); 1780 struct usb_device *dev = usb_get_dev(interface_to_usbdev(intf));
1781 struct usb_interface *uif;
1768 __u8 ifnum = intf->altsetting->desc.bInterfaceNumber; 1782 __u8 ifnum = intf->altsetting->desc.bInterfaceNumber;
1769 const struct usb_host_interface *interface; 1783 const struct usb_host_interface *interface;
1770 struct usb_usbvision *usbvision = NULL; 1784 struct usb_usbvision *usbvision = NULL;
1771 const struct usb_endpoint_descriptor *endpoint; 1785 const struct usb_endpoint_descriptor *endpoint;
1772 int model; 1786 int model,i;
1773 1787
1774 PDEBUG(DBG_PROBE, "VID=%#04x, PID=%#04x, ifnum=%u", 1788 PDEBUG(DBG_PROBE, "VID=%#04x, PID=%#04x, ifnum=%u",
1775 dev->descriptor.idVendor, dev->descriptor.idProduct, ifnum); 1789 dev->descriptor.idVendor, dev->descriptor.idProduct, ifnum);
1790
1776 /* Is it an USBVISION video dev? */ 1791 /* Is it an USBVISION video dev? */
1777 model = 0; 1792 model = 0;
1778 for(model = 0; usbvision_device_data[model].idVendor; model++) { 1793 for(model = 0; usbvision_device_data[model].idVendor; model++) {
@@ -1783,7 +1798,7 @@ static int __devinit usbvision_probe(struct usb_interface *intf, const struct us
1783 continue; 1798 continue;
1784 } 1799 }
1785 1800
1786 info("%s: %s found", __FUNCTION__, usbvision_device_data[model].ModelString); 1801 printk(KERN_INFO "%s: %s found\n", __FUNCTION__, usbvision_device_data[model].ModelString);
1787 break; 1802 break;
1788 } 1803 }
1789 1804
@@ -1799,7 +1814,7 @@ static int __devinit usbvision_probe(struct usb_interface *intf, const struct us
1799 endpoint = &interface->endpoint[1].desc; 1814 endpoint = &interface->endpoint[1].desc;
1800 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_ISOC) { 1815 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_ISOC) {
1801 err("%s: interface %d. has non-ISO endpoint!", __FUNCTION__, ifnum); 1816 err("%s: interface %d. has non-ISO endpoint!", __FUNCTION__, ifnum);
1802 err("%s: Endpoint attribures %d", __FUNCTION__, endpoint->bmAttributes); 1817 err("%s: Endpoint attributes %d", __FUNCTION__, endpoint->bmAttributes);
1803 return -ENODEV; 1818 return -ENODEV;
1804 } 1819 }
1805 if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) { 1820 if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) {
@@ -1826,6 +1841,28 @@ static int __devinit usbvision_probe(struct usb_interface *intf, const struct us
1826 1841
1827 down(&usbvision->lock); 1842 down(&usbvision->lock);
1828 1843
1844 /* compute alternate max packet sizes */
1845 uif = dev->actconfig->interface[0];
1846
1847 usbvision->num_alt=uif->num_altsetting;
1848 PDEBUG(DBG_PROBE, "Alternate settings: %i",usbvision->num_alt);
1849 usbvision->alt_max_pkt_size = kmalloc(32*
1850 usbvision->num_alt,GFP_KERNEL);
1851 if (usbvision->alt_max_pkt_size == NULL) {
1852 err("usbvision: out of memory!\n");
1853 return -ENOMEM;
1854 }
1855
1856 for (i = 0; i < usbvision->num_alt ; i++) {
1857 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[1].desc.
1858 wMaxPacketSize);
1859 usbvision->alt_max_pkt_size[i] =
1860 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1861 PDEBUG(DBG_PROBE, "Alternate setting %i, max size= %i",i,
1862 usbvision->alt_max_pkt_size[i]);
1863 }
1864
1865
1829 usbvision->nr = usbvision_nr++; 1866 usbvision->nr = usbvision_nr++;
1830 1867
1831 usbvision->have_tuner = usbvision_device_data[model].Tuner; 1868 usbvision->have_tuner = usbvision_device_data[model].Tuner;
@@ -1838,8 +1875,7 @@ static int __devinit usbvision_probe(struct usb_interface *intf, const struct us
1838 usbvision->DevModel = model; 1875 usbvision->DevModel = model;
1839 usbvision->remove_pending = 0; 1876 usbvision->remove_pending = 0;
1840 usbvision->iface = ifnum; 1877 usbvision->iface = ifnum;
1841 usbvision->ifaceAltInactive = 0; 1878 usbvision->ifaceAlt = 0;
1842 usbvision->ifaceAltActive = 1;
1843 usbvision->video_endp = endpoint->bEndpointAddress; 1879 usbvision->video_endp = endpoint->bEndpointAddress;
1844 usbvision->isocPacketSize = 0; 1880 usbvision->isocPacketSize = 0;
1845 usbvision->usb_bandwidth = 0; 1881 usbvision->usb_bandwidth = 0;
@@ -1895,7 +1931,7 @@ static void __devexit usbvision_disconnect(struct usb_interface *intf)
1895 up(&usbvision->lock); 1931 up(&usbvision->lock);
1896 1932
1897 if (usbvision->user) { 1933 if (usbvision->user) {
1898 info("%s: In use, disconnect pending", __FUNCTION__); 1934 printk(KERN_INFO "%s: In use, disconnect pending\n", __FUNCTION__);
1899 wake_up_interruptible(&usbvision->wait_frame); 1935 wake_up_interruptible(&usbvision->wait_frame);
1900 wake_up_interruptible(&usbvision->wait_stream); 1936 wake_up_interruptible(&usbvision->wait_stream);
1901 } 1937 }
@@ -2061,7 +2097,7 @@ static int __init usbvision_init(void)
2061 errCode = usb_register(&usbvision_driver); 2097 errCode = usb_register(&usbvision_driver);
2062 2098
2063 if (errCode == 0) { 2099 if (errCode == 0) {
2064 info(DRIVER_DESC " : " USBVISION_VERSION_STRING); 2100 printk(KERN_INFO DRIVER_DESC " : " USBVISION_VERSION_STRING "\n");
2065 PDEBUG(DBG_PROBE, "success"); 2101 PDEBUG(DBG_PROBE, "success");
2066 } 2102 }
2067 return errCode; 2103 return errCode;
diff --git a/drivers/media/video/usbvision/usbvision.h b/drivers/media/video/usbvision/usbvision.h
index e2bcaba938..ad6afd3e42 100644
--- a/drivers/media/video/usbvision/usbvision.h
+++ b/drivers/media/video/usbvision/usbvision.h
@@ -33,6 +33,7 @@
33 33
34#include <linux/list.h> 34#include <linux/list.h>
35#include <linux/usb.h> 35#include <linux/usb.h>
36#include <linux/i2c.h>
36#include <media/v4l2-common.h> 37#include <media/v4l2-common.h>
37#include <media/tuner.h> 38#include <media/tuner.h>
38#include <linux/videodev2.h> 39#include <linux/videodev2.h>
@@ -396,8 +397,11 @@ struct usb_usbvision {
396 397
397 /* Device structure */ 398 /* Device structure */
398 struct usb_device *dev; 399 struct usb_device *dev;
400 /* usb transfer */
401 int num_alt; /* Number of alternative settings */
402 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
399 unsigned char iface; /* Video interface number */ 403 unsigned char iface; /* Video interface number */
400 unsigned char ifaceAltActive, ifaceAltInactive; /* Alt settings */ 404 unsigned char ifaceAlt; /* Alt settings */
401 unsigned char Vin_Reg2_Preset; 405 unsigned char Vin_Reg2_Preset;
402 struct semaphore lock; 406 struct semaphore lock;
403 struct timer_list powerOffTimer; 407 struct timer_list powerOffTimer;
@@ -421,6 +425,7 @@ struct usb_usbvision {
421 wait_queue_head_t wait_stream; /* Processes waiting */ 425 wait_queue_head_t wait_stream; /* Processes waiting */
422 struct usbvision_frame *curFrame; // pointer to current frame, set by usbvision_find_header 426 struct usbvision_frame *curFrame; // pointer to current frame, set by usbvision_find_header
423 struct usbvision_frame frame[USBVISION_NUMFRAMES]; // frame buffer 427 struct usbvision_frame frame[USBVISION_NUMFRAMES]; // frame buffer
428 int num_frames; // number of frames allocated
424 struct usbvision_sbuf sbuf[USBVISION_NUMSBUF]; // S buffering 429 struct usbvision_sbuf sbuf[USBVISION_NUMSBUF]; // S buffering
425 volatile int remove_pending; /* If set then about to exit */ 430 volatile int remove_pending; /* If set then about to exit */
426 431
@@ -486,12 +491,11 @@ int usbvision_init_i2c(struct usb_usbvision *usbvision);
486void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd,void *arg); 491void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd,void *arg);
487 492
488/* defined in usbvision-core.c */ 493/* defined in usbvision-core.c */
489void usbvision_rvfree(void *mem, unsigned long size);
490int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg); 494int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg);
491int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg, 495int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg,
492 unsigned char value); 496 unsigned char value);
493 497
494int usbvision_frames_alloc(struct usb_usbvision *usbvision); 498int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames);
495void usbvision_frames_free(struct usb_usbvision *usbvision); 499void usbvision_frames_free(struct usb_usbvision *usbvision);
496int usbvision_scratch_alloc(struct usb_usbvision *usbvision); 500int usbvision_scratch_alloc(struct usb_usbvision *usbvision);
497void usbvision_scratch_free(struct usb_usbvision *usbvision); 501void usbvision_scratch_free(struct usb_usbvision *usbvision);
@@ -502,6 +506,7 @@ int usbvision_setup(struct usb_usbvision *usbvision,int format);
502int usbvision_init_isoc(struct usb_usbvision *usbvision); 506int usbvision_init_isoc(struct usb_usbvision *usbvision);
503int usbvision_restart_isoc(struct usb_usbvision *usbvision); 507int usbvision_restart_isoc(struct usb_usbvision *usbvision);
504void usbvision_stop_isoc(struct usb_usbvision *usbvision); 508void usbvision_stop_isoc(struct usb_usbvision *usbvision);
509int usbvision_set_alternate(struct usb_usbvision *dev);
505 510
506int usbvision_set_audio(struct usb_usbvision *usbvision, int AudioChannel); 511int usbvision_set_audio(struct usb_usbvision *usbvision, int AudioChannel);
507int usbvision_audio_off(struct usb_usbvision *usbvision); 512int usbvision_audio_off(struct usb_usbvision *usbvision);
diff --git a/drivers/media/video/v4l1-compat.c b/drivers/media/video/v4l1-compat.c
index 8a13e59530..d2c1ae0dbf 100644
--- a/drivers/media/video/v4l1-compat.c
+++ b/drivers/media/video/v4l1-compat.c
@@ -11,7 +11,7 @@
11 * as published by the Free Software Foundation; either version 11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version. 12 * 2 of the License, or (at your option) any later version.
13 * 13 *
14 * Author: Bill Dirks <bdirks@pacbell.net> 14 * Author: Bill Dirks <bill@thedirks.org>
15 * et al. 15 * et al.
16 * 16 *
17 */ 17 */
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index b8ee37ded3..54747606ea 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -12,7 +12,7 @@
12 * as published by the Free Software Foundation; either version 12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version. 13 * 2 of the License, or (at your option) any later version.
14 * 14 *
15 * Author: Bill Dirks <bdirks@pacbell.net> 15 * Author: Bill Dirks <bill@thedirks.org>
16 * based on code by Alan Cox, <alan@cymru.net> 16 * based on code by Alan Cox, <alan@cymru.net>
17 * 17 *
18 */ 18 */
@@ -51,6 +51,7 @@
51#include <linux/mm.h> 51#include <linux/mm.h>
52#include <linux/string.h> 52#include <linux/string.h>
53#include <linux/errno.h> 53#include <linux/errno.h>
54#include <linux/i2c.h>
54#include <asm/uaccess.h> 55#include <asm/uaccess.h>
55#include <asm/system.h> 56#include <asm/system.h>
56#include <asm/pgtable.h> 57#include <asm/pgtable.h>
@@ -271,11 +272,6 @@ char *v4l2_type_names[] = {
271 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "slicec-vbi-out", 272 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "slicec-vbi-out",
272}; 273};
273 274
274static char *v4l2_memory_names[] = {
275 [V4L2_MEMORY_MMAP] = "mmap",
276 [V4L2_MEMORY_USERPTR] = "userptr",
277 [V4L2_MEMORY_OVERLAY] = "overlay",
278};
279 275
280#define prt_names(a,arr) (((a)>=0)&&((a)<ARRAY_SIZE(arr)))?arr[a]:"unknown" 276#define prt_names(a,arr) (((a)>=0)&&((a)<ARRAY_SIZE(arr)))?arr[a]:"unknown"
281 277
@@ -370,13 +366,21 @@ static const char *v4l2_ioctls[] = {
370 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT", 366 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
371 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY", 367 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
372 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY", 368 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
373#if 1
374 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP", 369 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
375#endif
376 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS", 370 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
377 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS", 371 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
378 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS", 372 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
379 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS" 373 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
374#if 1
375 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
376 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
377 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
378 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
379 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
380
381 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
382 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
383#endif
380}; 384};
381#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls) 385#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
382 386
@@ -401,8 +405,6 @@ static const char *v4l2_int_ioctls[] = {
401 [_IOC_NR(TDA9887_SET_CONFIG)] = "TDA9887_SET_CONFIG", 405 [_IOC_NR(TDA9887_SET_CONFIG)] = "TDA9887_SET_CONFIG",
402 406
403 [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)] = "VIDIOC_INT_S_TUNER_MODE", 407 [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)] = "VIDIOC_INT_S_TUNER_MODE",
404 [_IOC_NR(VIDIOC_INT_S_REGISTER)] = "VIDIOC_INT_S_REGISTER",
405 [_IOC_NR(VIDIOC_INT_G_REGISTER)] = "VIDIOC_INT_G_REGISTER",
406 [_IOC_NR(VIDIOC_INT_RESET)] = "VIDIOC_INT_RESET", 408 [_IOC_NR(VIDIOC_INT_RESET)] = "VIDIOC_INT_RESET",
407 [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ", 409 [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ",
408 [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)] = "VIDIOC_INT_DECODE_VBI_LINE", 410 [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)] = "VIDIOC_INT_DECODE_VBI_LINE",
@@ -419,14 +421,6 @@ static const char *v4l2_int_ioctls[] = {
419}; 421};
420#define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls) 422#define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
421 423
422static void v4l_print_pix_fmt (char *s, struct v4l2_pix_format *fmt)
423{
424 printk ("%s: width=%d, height=%d, format=%d, field=%s, "
425 "bytesperline=%d sizeimage=%d, colorspace=%d\n", s,
426 fmt->width,fmt->height,fmt->pixelformat,
427 prt_names(fmt->field,v4l2_field_names),
428 fmt->bytesperline,fmt->sizeimage,fmt->colorspace);
429};
430 424
431/* Common ioctl debug function. This function can be used by 425/* Common ioctl debug function. This function can be used by
432 external ioctl messages as well as internal V4L ioctl */ 426 external ioctl messages as well as internal V4L ioctl */
@@ -466,576 +460,6 @@ void v4l_printk_ioctl(unsigned int cmd)
466 } 460 }
467} 461}
468 462
469/* Common ioctl debug function. This function can be used by
470 external ioctl messages as well as internal V4L ioctl and its
471 arguments */
472void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
473{
474 printk(s);
475 printk(": ");
476 v4l_printk_ioctl(cmd);
477 switch (cmd) {
478 case VIDIOC_INT_G_CHIP_IDENT:
479 {
480 enum v4l2_chip_ident *p=arg;
481 printk ("%s: chip ident=%d\n", s, *p);
482 break;
483 }
484 case VIDIOC_G_PRIORITY:
485 case VIDIOC_S_PRIORITY:
486 {
487 enum v4l2_priority *p=arg;
488 printk ("%s: priority=%d\n", s, *p);
489 break;
490 }
491 case VIDIOC_INT_S_TUNER_MODE:
492 {
493 enum v4l2_tuner_type *p=arg;
494 printk ("%s: tuner type=%d\n", s, *p);
495 break;
496 }
497#ifdef CONFIG_VIDEO_V4L1_COMPAT
498 case DECODER_SET_VBI_BYPASS:
499 case DECODER_ENABLE_OUTPUT:
500 case DECODER_GET_STATUS:
501 case DECODER_SET_OUTPUT:
502 case DECODER_SET_INPUT:
503 case DECODER_SET_GPIO:
504 case DECODER_SET_NORM:
505 case VIDIOCCAPTURE:
506 case VIDIOCSYNC:
507 case VIDIOCSWRITEMODE:
508#endif
509 case TUNER_SET_TYPE_ADDR:
510 case TUNER_SET_STANDBY:
511 case TDA9887_SET_CONFIG:
512#ifdef __OLD_VIDIOC_
513 case VIDIOC_OVERLAY_OLD:
514#endif
515 case VIDIOC_STREAMOFF:
516 case VIDIOC_G_OUTPUT:
517 case VIDIOC_S_OUTPUT:
518 case VIDIOC_STREAMON:
519 case VIDIOC_G_INPUT:
520 case VIDIOC_OVERLAY:
521 case VIDIOC_S_INPUT:
522 {
523 int *p=arg;
524 printk ("%s: value=%d\n", s, *p);
525 break;
526 }
527 case VIDIOC_G_AUDIO:
528 case VIDIOC_S_AUDIO:
529 case VIDIOC_ENUMAUDIO:
530#ifdef __OLD_VIDIOC_
531 case VIDIOC_G_AUDIO_OLD:
532#endif
533 {
534 struct v4l2_audio *p=arg;
535
536 printk ("%s: index=%d, name=%s, capability=%d, mode=%d\n",
537 s,p->index, p->name,p->capability, p->mode);
538 break;
539 }
540 case VIDIOC_G_AUDOUT:
541 case VIDIOC_S_AUDOUT:
542 case VIDIOC_ENUMAUDOUT:
543#ifdef __OLD_VIDIOC_
544 case VIDIOC_G_AUDOUT_OLD:
545#endif
546 {
547 struct v4l2_audioout *p=arg;
548 printk ("%s: index=%d, name=%s, capability=%d, mode=%d\n", s,
549 p->index, p->name, p->capability,p->mode);
550 break;
551 }
552 case VIDIOC_QBUF:
553 case VIDIOC_DQBUF:
554 case VIDIOC_QUERYBUF:
555 {
556 struct v4l2_buffer *p=arg;
557 struct v4l2_timecode *tc=&p->timecode;
558 printk ("%s: %02ld:%02d:%02d.%08ld index=%d, type=%s, "
559 "bytesused=%d, flags=0x%08x, "
560 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx\n",
561 s,
562 (p->timestamp.tv_sec/3600),
563 (int)(p->timestamp.tv_sec/60)%60,
564 (int)(p->timestamp.tv_sec%60),
565 p->timestamp.tv_usec,
566 p->index,
567 prt_names(p->type,v4l2_type_names),
568 p->bytesused,p->flags,
569 p->field,p->sequence,
570 prt_names(p->memory,v4l2_memory_names),
571 p->m.userptr);
572 printk ("%s: timecode= %02d:%02d:%02d type=%d, "
573 "flags=0x%08x, frames=%d, userbits=0x%08x\n",
574 s,tc->hours,tc->minutes,tc->seconds,
575 tc->type, tc->flags, tc->frames, *(__u32 *) tc->userbits);
576 break;
577 }
578 case VIDIOC_QUERYCAP:
579 {
580 struct v4l2_capability *p=arg;
581 printk ("%s: driver=%s, card=%s, bus=%s, version=0x%08x, "
582 "capabilities=0x%08x\n", s,
583 p->driver,p->card,p->bus_info,
584 p->version,
585 p->capabilities);
586 break;
587 }
588 case VIDIOC_G_CTRL:
589 case VIDIOC_S_CTRL:
590#ifdef __OLD_VIDIOC_
591 case VIDIOC_S_CTRL_OLD:
592#endif
593 {
594 struct v4l2_control *p=arg;
595 printk ("%s: id=%d, value=%d\n", s, p->id, p->value);
596 break;
597 }
598 case VIDIOC_G_EXT_CTRLS:
599 case VIDIOC_S_EXT_CTRLS:
600 case VIDIOC_TRY_EXT_CTRLS:
601 {
602 struct v4l2_ext_controls *p = arg;
603 int i;
604
605 printk("%s: ctrl_class=%d, count=%d\n", s, p->ctrl_class, p->count);
606 for (i = 0; i < p->count; i++) {
607 struct v4l2_ext_control *c = &p->controls[i];
608 if (cmd == VIDIOC_G_EXT_CTRLS)
609 printk("%s: id=%d\n", s, c->id);
610 else
611 printk("%s: id=%d, value=%d\n", s, c->id, c->value);
612 }
613 break;
614 }
615 case VIDIOC_G_CROP:
616 case VIDIOC_S_CROP:
617 {
618 struct v4l2_crop *p=arg;
619 /*FIXME: Should also show rect structs */
620 printk ("%s: type=%d\n", s, p->type);
621 break;
622 }
623 case VIDIOC_CROPCAP:
624#ifdef __OLD_VIDIOC_
625 case VIDIOC_CROPCAP_OLD:
626#endif
627 {
628 struct v4l2_cropcap *p=arg;
629 /*FIXME: Should also show rect structs */
630 printk ("%s: type=%d\n", s, p->type);
631 break;
632 }
633 case VIDIOC_INT_DECODE_VBI_LINE:
634 {
635 struct v4l2_decode_vbi_line *p=arg;
636 printk ("%s: is_second_field=%d, ptr=0x%08lx, line=%d, "
637 "type=%d\n", s,
638 p->is_second_field,(unsigned long)p->p,p->line,p->type);
639 break;
640 }
641 case VIDIOC_ENUM_FMT:
642 {
643 struct v4l2_fmtdesc *p=arg;
644 printk ("%s: index=%d, type=%d, flags=%d, description=%s,"
645 " pixelformat=%d\n", s,
646 p->index, p->type, p->flags,p->description,
647 p->pixelformat);
648
649 break;
650 }
651 case VIDIOC_G_FMT:
652 case VIDIOC_S_FMT:
653 case VIDIOC_TRY_FMT:
654 {
655 struct v4l2_format *p=arg;
656 printk ("%s: type=%s\n", s,
657 prt_names(p->type,v4l2_type_names));
658 switch (p->type) {
659 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
660 v4l_print_pix_fmt (s, &p->fmt.pix);
661 break;
662 default:
663 break;
664 }
665 }
666 case VIDIOC_G_FBUF:
667 case VIDIOC_S_FBUF:
668 {
669 struct v4l2_framebuffer *p=arg;
670 printk ("%s: capability=%d, flags=%d, base=0x%08lx\n", s,
671 p->capability,p->flags, (unsigned long)p->base);
672 v4l_print_pix_fmt (s, &p->fmt);
673 break;
674 }
675 case VIDIOC_G_FREQUENCY:
676 case VIDIOC_S_FREQUENCY:
677 {
678 struct v4l2_frequency *p=arg;
679 printk ("%s: tuner=%d, type=%d, frequency=%d\n", s,
680 p->tuner,p->type,p->frequency);
681 break;
682 }
683 case VIDIOC_ENUMINPUT:
684 {
685 struct v4l2_input *p=arg;
686 printk ("%s: index=%d, name=%s, type=%d, audioset=%d, "
687 "tuner=%d, std=%Ld, status=%d\n", s,
688 p->index,p->name,p->type,p->audioset,
689 p->tuner,
690 (unsigned long long)p->std,
691 p->status);
692 break;
693 }
694 case VIDIOC_G_JPEGCOMP:
695 case VIDIOC_S_JPEGCOMP:
696 {
697 struct v4l2_jpegcompression *p=arg;
698 printk ("%s: quality=%d, APPn=%d, APP_len=%d, COM_len=%d,"
699 " jpeg_markers=%d\n", s,
700 p->quality,p->APPn,p->APP_len,
701 p->COM_len,p->jpeg_markers);
702 break;
703 }
704 case VIDIOC_G_MODULATOR:
705 case VIDIOC_S_MODULATOR:
706 {
707 struct v4l2_modulator *p=arg;
708 printk ("%s: index=%d, name=%s, capability=%d, rangelow=%d,"
709 " rangehigh=%d, txsubchans=%d\n", s,
710 p->index, p->name,p->capability,p->rangelow,
711 p->rangehigh,p->txsubchans);
712 break;
713 }
714 case VIDIOC_G_MPEGCOMP:
715 case VIDIOC_S_MPEGCOMP:
716 {
717 struct v4l2_mpeg_compression *p=arg;
718 /*FIXME: Several fields not shown */
719 printk ("%s: ts_pid_pmt=%d, ts_pid_audio=%d, ts_pid_video=%d, "
720 "ts_pid_pcr=%d, ps_size=%d, au_sample_rate=%d, "
721 "au_pesid=%c, vi_frame_rate=%d, vi_frames_per_gop=%d, "
722 "vi_bframes_count=%d, vi_pesid=%c\n", s,
723 p->ts_pid_pmt,p->ts_pid_audio, p->ts_pid_video,
724 p->ts_pid_pcr, p->ps_size, p->au_sample_rate,
725 p->au_pesid, p->vi_frame_rate,
726 p->vi_frames_per_gop, p->vi_bframes_count,
727 p->vi_pesid);
728 break;
729 }
730 case VIDIOC_ENUMOUTPUT:
731 {
732 struct v4l2_output *p=arg;
733 printk ("%s: index=%d, name=%s,type=%d, audioset=%d, "
734 "modulator=%d, std=%Ld\n",
735 s,p->index,p->name,p->type,p->audioset,
736 p->modulator,
737 (unsigned long long)p->std);
738 break;
739 }
740 case VIDIOC_QUERYCTRL:
741 {
742 struct v4l2_queryctrl *p=arg;
743 printk ("%s: id=%d, type=%d, name=%s, min/max=%d/%d,"
744 " step=%d, default=%d, flags=0x%08x\n", s,
745 p->id,p->type,p->name,p->minimum,p->maximum,
746 p->step,p->default_value,p->flags);
747 break;
748 }
749 case VIDIOC_QUERYMENU:
750 {
751 struct v4l2_querymenu *p=arg;
752 printk ("%s: id=%d, index=%d, name=%s\n", s,
753 p->id,p->index,p->name);
754 break;
755 }
756 case VIDIOC_INT_G_REGISTER:
757 case VIDIOC_INT_S_REGISTER:
758 {
759 struct v4l2_register *p=arg;
760 printk ("%s: i2c_id=%d, reg=%lu, val=%d\n", s,
761 p->i2c_id,p->reg,p->val);
762
763 break;
764 }
765 case VIDIOC_REQBUFS:
766 {
767 struct v4l2_requestbuffers *p=arg;
768 printk ("%s: count=%d, type=%s, memory=%s\n", s,
769 p->count,
770 prt_names(p->type,v4l2_type_names),
771 prt_names(p->memory,v4l2_memory_names));
772 break;
773 }
774 case VIDIOC_INT_S_AUDIO_ROUTING:
775 case VIDIOC_INT_S_VIDEO_ROUTING:
776 case VIDIOC_INT_G_AUDIO_ROUTING:
777 case VIDIOC_INT_G_VIDEO_ROUTING:
778 {
779 struct v4l2_routing *p=arg;
780 printk ("%s: input=0x%x, output=0x%x\n", s, p->input, p->output);
781 break;
782 }
783 case VIDIOC_INT_S_CRYSTAL_FREQ:
784 {
785 struct v4l2_crystal_freq *p=arg;
786 printk ("%s: freq=%u, flags=0x%x\n", s, p->freq, p->flags);
787 break;
788 }
789 case VIDIOC_G_SLICED_VBI_CAP:
790 {
791 struct v4l2_sliced_vbi_cap *p=arg;
792 printk ("%s: service_set=%d\n", s,
793 p->service_set);
794 break;
795 }
796 case VIDIOC_INT_S_VBI_DATA:
797 case VIDIOC_INT_G_VBI_DATA:
798 {
799 struct v4l2_sliced_vbi_data *p=arg;
800 printk ("%s: id=%d, field=%d, line=%d\n", s,
801 p->id, p->field, p->line);
802 break;
803 }
804 case VIDIOC_ENUMSTD:
805 {
806 struct v4l2_standard *p=arg;
807 printk ("%s: index=%d, id=%Ld, name=%s, fps=%d/%d, "
808 "framelines=%d\n", s, p->index,
809 (unsigned long long)p->id, p->name,
810 p->frameperiod.numerator,
811 p->frameperiod.denominator,
812 p->framelines);
813
814 break;
815 }
816 case VIDIOC_G_PARM:
817 case VIDIOC_S_PARM:
818#ifdef __OLD_VIDIOC_
819 case VIDIOC_S_PARM_OLD:
820#endif
821 {
822 struct v4l2_streamparm *p=arg;
823 printk ("%s: type=%d\n", s, p->type);
824
825 break;
826 }
827 case VIDIOC_G_TUNER:
828 case VIDIOC_S_TUNER:
829 {
830 struct v4l2_tuner *p=arg;
831 printk ("%s: index=%d, name=%s, type=%d, capability=%d, "
832 "rangelow=%d, rangehigh=%d, signal=%d, afc=%d, "
833 "rxsubchans=%d, audmode=%d\n", s,
834 p->index, p->name, p->type,
835 p->capability, p->rangelow,p->rangehigh,
836 p->rxsubchans, p->audmode, p->signal,
837 p->afc);
838 break;
839 }
840#ifdef CONFIG_VIDEO_V4L1_COMPAT
841 case VIDIOCGVBIFMT:
842 case VIDIOCSVBIFMT:
843 {
844 struct vbi_format *p=arg;
845 printk ("%s: sampling_rate=%d, samples_per_line=%d, "
846 "sample_format=%d, start=%d/%d, count=%d/%d, flags=%d\n", s,
847 p->sampling_rate,p->samples_per_line,
848 p->sample_format,p->start[0],p->start[1],
849 p->count[0],p->count[1],p->flags);
850 break;
851 }
852 case VIDIOCGAUDIO:
853 case VIDIOCSAUDIO:
854 {
855 struct video_audio *p=arg;
856 printk ("%s: audio=%d, volume=%d, bass=%d, treble=%d, "
857 "flags=%d, name=%s, mode=%d, balance=%d, step=%d\n",
858 s,p->audio,p->volume,p->bass, p->treble,
859 p->flags,p->name,p->mode,p->balance,p->step);
860 break;
861 }
862 case VIDIOCGFBUF:
863 case VIDIOCSFBUF:
864 {
865 struct video_buffer *p=arg;
866 printk ("%s: base=%08lx, height=%d, width=%d, depth=%d, "
867 "bytesperline=%d\n", s,
868 (unsigned long) p->base, p->height, p->width,
869 p->depth,p->bytesperline);
870 break;
871 }
872 case VIDIOCGCAP:
873 {
874 struct video_capability *p=arg;
875 printk ("%s: name=%s, type=%d, channels=%d, audios=%d, "
876 "maxwidth=%d, maxheight=%d, minwidth=%d, minheight=%d\n",
877 s,p->name,p->type,p->channels,p->audios,
878 p->maxwidth,p->maxheight,p->minwidth,
879 p->minheight);
880
881 break;
882 }
883 case VIDIOCGCAPTURE:
884 case VIDIOCSCAPTURE:
885 {
886 struct video_capture *p=arg;
887 printk ("%s: x=%d, y=%d, width=%d, height=%d, decimation=%d,"
888 " flags=%d\n", s,
889 p->x, p->y,p->width, p->height,
890 p->decimation,p->flags);
891 break;
892 }
893 case VIDIOCGCHAN:
894 case VIDIOCSCHAN:
895 {
896 struct video_channel *p=arg;
897 printk ("%s: channel=%d, name=%s, tuners=%d, flags=%d, "
898 "type=%d, norm=%d\n", s,
899 p->channel,p->name,p->tuners,
900 p->flags,p->type,p->norm);
901
902 break;
903 }
904 case VIDIOCSMICROCODE:
905 {
906 struct video_code *p=arg;
907 printk ("%s: loadwhat=%s, datasize=%d\n", s,
908 p->loadwhat,p->datasize);
909 break;
910 }
911 case DECODER_GET_CAPABILITIES:
912 {
913 struct video_decoder_capability *p=arg;
914 printk ("%s: flags=%d, inputs=%d, outputs=%d\n", s,
915 p->flags,p->inputs,p->outputs);
916 break;
917 }
918 case DECODER_INIT:
919 {
920 struct video_decoder_init *p=arg;
921 printk ("%s: len=%c\n", s, p->len);
922 break;
923 }
924 case VIDIOCGPLAYINFO:
925 {
926 struct video_info *p=arg;
927 printk ("%s: frame_count=%d, h_size=%d, v_size=%d, "
928 "smpte_timecode=%d, picture_type=%d, "
929 "temporal_reference=%d, user_data=%s\n", s,
930 p->frame_count, p->h_size,
931 p->v_size, p->smpte_timecode,
932 p->picture_type, p->temporal_reference,
933 p->user_data);
934 break;
935 }
936 case VIDIOCKEY:
937 {
938 struct video_key *p=arg;
939 printk ("%s: key=%s, flags=%d\n", s,
940 p->key, p->flags);
941 break;
942 }
943 case VIDIOCGMBUF:
944 {
945 struct video_mbuf *p=arg;
946 printk ("%s: size=%d, frames=%d, offsets=0x%08lx\n", s,
947 p->size,
948 p->frames,
949 (unsigned long)p->offsets);
950 break;
951 }
952 case VIDIOCMCAPTURE:
953 {
954 struct video_mmap *p=arg;
955 printk ("%s: frame=%d, height=%d, width=%d, format=%d\n", s,
956 p->frame,
957 p->height, p->width,
958 p->format);
959 break;
960 }
961 case VIDIOCGPICT:
962 case VIDIOCSPICT:
963 case DECODER_SET_PICTURE:
964 {
965 struct video_picture *p=arg;
966
967 printk ("%s: brightness=%d, hue=%d, colour=%d, contrast=%d,"
968 " whiteness=%d, depth=%d, palette=%d\n", s,
969 p->brightness, p->hue, p->colour,
970 p->contrast, p->whiteness, p->depth,
971 p->palette);
972 break;
973 }
974 case VIDIOCSPLAYMODE:
975 {
976 struct video_play_mode *p=arg;
977 printk ("%s: mode=%d, p1=%d, p2=%d\n", s,
978 p->mode,p->p1,p->p2);
979 break;
980 }
981 case VIDIOCGTUNER:
982 case VIDIOCSTUNER:
983 {
984 struct video_tuner *p=arg;
985 printk ("%s: tuner=%d, name=%s, rangelow=%ld, rangehigh=%ld, "
986 "flags=%d, mode=%d, signal=%d\n", s,
987 p->tuner, p->name,p->rangelow, p->rangehigh,
988 p->flags,p->mode, p->signal);
989 break;
990 }
991 case VIDIOCGUNIT:
992 {
993 struct video_unit *p=arg;
994 printk ("%s: video=%d, vbi=%d, radio=%d, audio=%d, "
995 "teletext=%d\n", s,
996 p->video,p->vbi,p->radio,p->audio,p->teletext);
997 break;
998 }
999 case VIDIOCGWIN:
1000 case VIDIOCSWIN:
1001 {
1002 struct video_window *p=arg;
1003 printk ("%s: x=%d, y=%d, width=%d, height=%d, chromakey=%d,"
1004 " flags=%d, clipcount=%d\n", s,
1005 p->x, p->y,p->width, p->height,
1006 p->chromakey,p->flags,
1007 p->clipcount);
1008 break;
1009 }
1010 case VIDIOCGFREQ:
1011 case VIDIOCSFREQ:
1012 {
1013 unsigned long *p=arg;
1014 printk ("%s: value=%lu\n", s, *p);
1015 break;
1016 }
1017#endif
1018 case VIDIOC_INT_AUDIO_CLOCK_FREQ:
1019 case VIDIOC_INT_I2S_CLOCK_FREQ:
1020 case VIDIOC_INT_S_STANDBY:
1021 case VIDIOC_INT_RESET:
1022 {
1023 u32 *p=arg;
1024
1025 printk ("%s: value=%d\n", s, *p);
1026 break;
1027 }
1028 case VIDIOC_G_STD:
1029 case VIDIOC_S_STD:
1030 case VIDIOC_QUERYSTD:
1031 {
1032 v4l2_std_id *p=arg;
1033
1034 printk ("%s: value=%Lu\n", s, (unsigned long long)*p);
1035 break;
1036 }
1037 }
1038}
1039 463
1040/* ----------------------------------------------------------------- */ 464/* ----------------------------------------------------------------- */
1041 465
@@ -1529,6 +953,28 @@ u32 v4l2_ctrl_next(const u32 * const * ctrl_classes, u32 id)
1529 return **ctrl_classes; 953 return **ctrl_classes;
1530} 954}
1531 955
956int v4l2_chip_match_i2c_client(struct i2c_client *c, u32 match_type, u32 match_chip)
957{
958 switch (match_type) {
959 case V4L2_CHIP_MATCH_I2C_DRIVER:
960 return (c != NULL && c->driver != NULL && c->driver->id == match_chip);
961 case V4L2_CHIP_MATCH_I2C_ADDR:
962 return (c != NULL && c->addr == match_chip);
963 default:
964 return 0;
965 }
966}
967
968int v4l2_chip_match_host(u32 match_type, u32 match_chip)
969{
970 switch (match_type) {
971 case V4L2_CHIP_MATCH_HOST:
972 return match_chip == 0;
973 default:
974 return 0;
975 }
976}
977
1532/* ----------------------------------------------------------------- */ 978/* ----------------------------------------------------------------- */
1533 979
1534EXPORT_SYMBOL(v4l2_norm_to_name); 980EXPORT_SYMBOL(v4l2_norm_to_name);
@@ -1544,7 +990,6 @@ EXPORT_SYMBOL(v4l2_prio_check);
1544EXPORT_SYMBOL(v4l2_field_names); 990EXPORT_SYMBOL(v4l2_field_names);
1545EXPORT_SYMBOL(v4l2_type_names); 991EXPORT_SYMBOL(v4l2_type_names);
1546EXPORT_SYMBOL(v4l_printk_ioctl); 992EXPORT_SYMBOL(v4l_printk_ioctl);
1547EXPORT_SYMBOL(v4l_printk_ioctl_arg);
1548 993
1549EXPORT_SYMBOL(v4l2_ctrl_next); 994EXPORT_SYMBOL(v4l2_ctrl_next);
1550EXPORT_SYMBOL(v4l2_ctrl_check); 995EXPORT_SYMBOL(v4l2_ctrl_check);
@@ -1553,6 +998,9 @@ EXPORT_SYMBOL(v4l2_ctrl_query_menu);
1553EXPORT_SYMBOL(v4l2_ctrl_query_fill); 998EXPORT_SYMBOL(v4l2_ctrl_query_fill);
1554EXPORT_SYMBOL(v4l2_ctrl_query_fill_std); 999EXPORT_SYMBOL(v4l2_ctrl_query_fill_std);
1555 1000
1001EXPORT_SYMBOL(v4l2_chip_match_i2c_client);
1002EXPORT_SYMBOL(v4l2_chip_match_host);
1003
1556/* 1004/*
1557 * Local variables: 1005 * Local variables:
1558 * c-basic-offset: 8 1006 * c-basic-offset: 8
diff --git a/drivers/media/video/video-buf.c b/drivers/media/video/video-buf.c
index 6504a58668..459786ff45 100644
--- a/drivers/media/video/video-buf.c
+++ b/drivers/media/video/video-buf.c
@@ -148,6 +148,8 @@ int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
148 dprintk(1,"init user [0x%lx+0x%lx => %d pages]\n", 148 dprintk(1,"init user [0x%lx+0x%lx => %d pages]\n",
149 data,size,dma->nr_pages); 149 data,size,dma->nr_pages);
150 150
151 dma->varea = (void *) data;
152
151 down_read(&current->mm->mmap_sem); 153 down_read(&current->mm->mmap_sem);
152 err = get_user_pages(current,current->mm, 154 err = get_user_pages(current,current->mm,
153 data & PAGE_MASK, dma->nr_pages, 155 data & PAGE_MASK, dma->nr_pages,
@@ -285,6 +287,7 @@ int videobuf_dma_free(struct videobuf_dmabuf *dma)
285 287
286 vfree(dma->vmalloc); 288 vfree(dma->vmalloc);
287 dma->vmalloc = NULL; 289 dma->vmalloc = NULL;
290 dma->varea = NULL;
288 291
289 if (dma->bus_addr) { 292 if (dma->bus_addr) {
290 dma->bus_addr = 0; 293 dma->bus_addr = 0;
diff --git a/drivers/media/video/videodev.c b/drivers/media/video/videodev.c
index a786c1f5b9..011938fb7e 100644
--- a/drivers/media/video/videodev.c
+++ b/drivers/media/video/videodev.c
@@ -1342,6 +1342,42 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
1342 ret=vfd->vidioc_s_jpegcomp(file, fh, p); 1342 ret=vfd->vidioc_s_jpegcomp(file, fh, p);
1343 break; 1343 break;
1344 } 1344 }
1345 case VIDIOC_G_ENC_INDEX:
1346 {
1347 struct v4l2_enc_idx *p=arg;
1348
1349 if (!vfd->vidioc_g_enc_index)
1350 break;
1351 ret=vfd->vidioc_g_enc_index(file, fh, p);
1352 if (!ret)
1353 dbgarg (cmd, "entries=%d, entries_cap=%d\n",
1354 p->entries,p->entries_cap);
1355 break;
1356 }
1357 case VIDIOC_ENCODER_CMD:
1358 {
1359 struct v4l2_encoder_cmd *p=arg;
1360
1361 if (!vfd->vidioc_encoder_cmd)
1362 break;
1363 ret=vfd->vidioc_encoder_cmd(file, fh, p);
1364 if (!ret)
1365 dbgarg (cmd, "cmd=%d, flags=%d\n",
1366 p->cmd,p->flags);
1367 break;
1368 }
1369 case VIDIOC_TRY_ENCODER_CMD:
1370 {
1371 struct v4l2_encoder_cmd *p=arg;
1372
1373 if (!vfd->vidioc_try_encoder_cmd)
1374 break;
1375 ret=vfd->vidioc_try_encoder_cmd(file, fh, p);
1376 if (!ret)
1377 dbgarg (cmd, "cmd=%d, flags=%d\n",
1378 p->cmd,p->flags);
1379 break;
1380 }
1345 case VIDIOC_G_PARM: 1381 case VIDIOC_G_PARM:
1346 { 1382 {
1347 struct v4l2_streamparm *p=arg; 1383 struct v4l2_streamparm *p=arg;
@@ -1453,6 +1489,26 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
1453 ret=vfd->vidioc_log_status(file, fh); 1489 ret=vfd->vidioc_log_status(file, fh);
1454 break; 1490 break;
1455 } 1491 }
1492#ifdef CONFIG_VIDEO_ADV_DEBUG
1493 case VIDIOC_DBG_G_REGISTER:
1494 {
1495 struct v4l2_register *p=arg;
1496 if (!capable(CAP_SYS_ADMIN))
1497 ret=-EPERM;
1498 else if (vfd->vidioc_g_register)
1499 ret=vfd->vidioc_g_register(file, fh, p);
1500 break;
1501 }
1502 case VIDIOC_DBG_S_REGISTER:
1503 {
1504 struct v4l2_register *p=arg;
1505 if (!capable(CAP_SYS_ADMIN))
1506 ret=-EPERM;
1507 else if (vfd->vidioc_s_register)
1508 ret=vfd->vidioc_s_register(file, fh, p);
1509 break;
1510 }
1511#endif
1456 } /* switch */ 1512 } /* switch */
1457 1513
1458 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { 1514 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index cfb6b1f040..f7e1d19103 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -145,7 +145,9 @@ struct vivi_buffer {
145 145
146 struct vivi_fmt *fmt; 146 struct vivi_fmt *fmt;
147 147
148#ifdef CONFIG_VIVI_SCATTER
148 struct sg_to_addr *to_addr; 149 struct sg_to_addr *to_addr;
150#endif
149}; 151};
150 152
151struct vivi_dmaqueue { 153struct vivi_dmaqueue {
@@ -230,6 +232,7 @@ static u8 bars[8][3] = {
230#define TSTAMP_MAX_Y TSTAMP_MIN_Y+15 232#define TSTAMP_MAX_Y TSTAMP_MIN_Y+15
231#define TSTAMP_MIN_X 64 233#define TSTAMP_MIN_X 64
232 234
235#ifdef CONFIG_VIVI_SCATTER
233static void prep_to_addr(struct sg_to_addr to_addr[], 236static void prep_to_addr(struct sg_to_addr to_addr[],
234 struct videobuf_buffer *vb) 237 struct videobuf_buffer *vb)
235{ 238{
@@ -262,14 +265,24 @@ static int get_addr_pos(int pos, int pages, struct sg_to_addr to_addr[])
262 265
263 return (p1); 266 return (p1);
264} 267}
268#endif
265 269
270#ifdef CONFIG_VIVI_SCATTER
266static void gen_line(struct sg_to_addr to_addr[],int inipos,int pages,int wmax, 271static void gen_line(struct sg_to_addr to_addr[],int inipos,int pages,int wmax,
267 int hmax, int line, char *timestr) 272 int hmax, int line, char *timestr)
273#else
274static void gen_line(char *basep,int inipos,int wmax,
275 int hmax, int line, char *timestr)
276#endif
268{ 277{
269 int w,i,j,pos=inipos,pgpos,oldpg,y; 278 int w,i,j,pos=inipos,y;
270 char *p,*s,*basep; 279 char *p,*s;
271 struct page *pg;
272 u8 chr,r,g,b,color; 280 u8 chr,r,g,b,color;
281#ifdef CONFIG_VIVI_SCATTER
282 int pgpos,oldpg;
283 char *basep;
284 struct page *pg;
285
273 unsigned long flags; 286 unsigned long flags;
274 spinlock_t spinlock; 287 spinlock_t spinlock;
275 288
@@ -280,6 +293,7 @@ static void gen_line(struct sg_to_addr to_addr[],int inipos,int pages,int wmax,
280 pg=pfn_to_page(sg_dma_address(to_addr[oldpg].sg) >> PAGE_SHIFT); 293 pg=pfn_to_page(sg_dma_address(to_addr[oldpg].sg) >> PAGE_SHIFT);
281 spin_lock_irqsave(&spinlock,flags); 294 spin_lock_irqsave(&spinlock,flags);
282 basep = kmap_atomic(pg, KM_BOUNCE_READ)+to_addr[oldpg].sg->offset; 295 basep = kmap_atomic(pg, KM_BOUNCE_READ)+to_addr[oldpg].sg->offset;
296#endif
283 297
284 /* We will just duplicate the second pixel at the packet */ 298 /* We will just duplicate the second pixel at the packet */
285 wmax/=2; 299 wmax/=2;
@@ -291,6 +305,7 @@ static void gen_line(struct sg_to_addr to_addr[],int inipos,int pages,int wmax,
291 b=bars[w*7/wmax][2]; 305 b=bars[w*7/wmax][2];
292 306
293 for (color=0;color<4;color++) { 307 for (color=0;color<4;color++) {
308#ifdef CONFIG_VIVI_SCATTER
294 pgpos=get_addr_pos(pos,pages,to_addr); 309 pgpos=get_addr_pos(pos,pages,to_addr);
295 if (pgpos!=oldpg) { 310 if (pgpos!=oldpg) {
296 pg=pfn_to_page(sg_dma_address(to_addr[pgpos].sg) >> PAGE_SHIFT); 311 pg=pfn_to_page(sg_dma_address(to_addr[pgpos].sg) >> PAGE_SHIFT);
@@ -299,6 +314,9 @@ static void gen_line(struct sg_to_addr to_addr[],int inipos,int pages,int wmax,
299 oldpg=pgpos; 314 oldpg=pgpos;
300 } 315 }
301 p=basep+pos-to_addr[pgpos].pos; 316 p=basep+pos-to_addr[pgpos].pos;
317#else
318 p=basep+pos;
319#endif
302 320
303 switch (color) { 321 switch (color) {
304 case 0: 322 case 0:
@@ -343,6 +361,7 @@ static void gen_line(struct sg_to_addr to_addr[],int inipos,int pages,int wmax,
343 361
344 pos=inipos+j*2; 362 pos=inipos+j*2;
345 for (color=0;color<4;color++) { 363 for (color=0;color<4;color++) {
364#ifdef CONFIG_VIVI_SCATTER
346 pgpos=get_addr_pos(pos,pages,to_addr); 365 pgpos=get_addr_pos(pos,pages,to_addr);
347 if (pgpos!=oldpg) { 366 if (pgpos!=oldpg) {
348 pg=pfn_to_page(sg_dma_address( 367 pg=pfn_to_page(sg_dma_address(
@@ -356,6 +375,9 @@ static void gen_line(struct sg_to_addr to_addr[],int inipos,int pages,int wmax,
356 oldpg=pgpos; 375 oldpg=pgpos;
357 } 376 }
358 p=basep+pos-to_addr[pgpos].pos; 377 p=basep+pos-to_addr[pgpos].pos;
378#else
379 p=basep+pos;
380#endif
359 381
360 y=TO_Y(r,g,b); 382 y=TO_Y(r,g,b);
361 383
@@ -380,19 +402,27 @@ static void gen_line(struct sg_to_addr to_addr[],int inipos,int pages,int wmax,
380 402
381 403
382end: 404end:
405#ifdef CONFIG_VIVI_SCATTER
383 kunmap_atomic(basep, KM_BOUNCE_READ); 406 kunmap_atomic(basep, KM_BOUNCE_READ);
384 spin_unlock_irqrestore(&spinlock,flags); 407 spin_unlock_irqrestore(&spinlock,flags);
385 408#else
409 return;
410#endif
386} 411}
387static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf) 412static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf)
388{ 413{
389 int h,pos=0; 414 int h,pos=0;
390 int hmax = buf->vb.height; 415 int hmax = buf->vb.height;
391 int wmax = buf->vb.width; 416 int wmax = buf->vb.width;
392 struct videobuf_buffer *vb=&buf->vb;
393 struct sg_to_addr *to_addr=buf->to_addr;
394 struct timeval ts; 417 struct timeval ts;
418#ifdef CONFIG_VIVI_SCATTER
419 struct sg_to_addr *to_addr=buf->to_addr;
420 struct videobuf_buffer *vb=&buf->vb;
421#else
422 char *tmpbuf;
423#endif
395 424
425#ifdef CONFIG_VIVI_SCATTER
396 /* Test if DMA mapping is ready */ 426 /* Test if DMA mapping is ready */
397 if (!sg_dma_address(&vb->dma.sglist[0])) 427 if (!sg_dma_address(&vb->dma.sglist[0]))
398 return; 428 return;
@@ -401,9 +431,28 @@ static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf)
401 431
402 /* Check if there is enough memory */ 432 /* Check if there is enough memory */
403 BUG_ON(buf->vb.dma.nr_pages << PAGE_SHIFT < (buf->vb.width*buf->vb.height)*2); 433 BUG_ON(buf->vb.dma.nr_pages << PAGE_SHIFT < (buf->vb.width*buf->vb.height)*2);
434#else
435 if (buf->vb.dma.varea) {
436 tmpbuf=kmalloc (wmax*2, GFP_KERNEL);
437 } else {
438 tmpbuf=buf->vb.dma.vmalloc;
439 }
440
441#endif
404 442
405 for (h=0;h<hmax;h++) { 443 for (h=0;h<hmax;h++) {
444#ifdef CONFIG_VIVI_SCATTER
406 gen_line(to_addr,pos,vb->dma.nr_pages,wmax,hmax,h,dev->timestr); 445 gen_line(to_addr,pos,vb->dma.nr_pages,wmax,hmax,h,dev->timestr);
446#else
447 if (buf->vb.dma.varea) {
448 gen_line(tmpbuf,0,wmax,hmax,h,dev->timestr);
449 /* FIXME: replacing to __copy_to_user */
450 if (copy_to_user(buf->vb.dma.varea+pos,tmpbuf,wmax*2)!=0)
451 dprintk(2,"vivifill copy_to_user failed.\n");
452 } else {
453 gen_line(tmpbuf,pos,wmax,hmax,h,dev->timestr);
454 }
455#endif
407 pos += wmax*2; 456 pos += wmax*2;
408 } 457 }
409 458
@@ -429,7 +478,7 @@ static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf)
429 dev->h,dev->m,dev->s,(dev->us+500)/1000); 478 dev->h,dev->m,dev->s,(dev->us+500)/1000);
430 479
431 dprintk(2,"vivifill at %s: Buffer 0x%08lx size= %d\n",dev->timestr, 480 dprintk(2,"vivifill at %s: Buffer 0x%08lx size= %d\n",dev->timestr,
432 (unsigned long)buf->vb.dma.vmalloc,pos); 481 (unsigned long)buf->vb.dma.varea,pos);
433 482
434 /* Advice that buffer was filled */ 483 /* Advice that buffer was filled */
435 buf->vb.state = STATE_DONE; 484 buf->vb.state = STATE_DONE;
@@ -471,11 +520,12 @@ static void vivi_thread_tick(struct vivi_dmaqueue *dma_q)
471 520
472 /* Fill buffer */ 521 /* Fill buffer */
473 vivi_fillbuff(dev,buf); 522 vivi_fillbuff(dev,buf);
474 } 523
475 if (list_empty(&dma_q->active)) { 524 if (list_empty(&dma_q->active)) {
476 del_timer(&dma_q->timeout); 525 del_timer(&dma_q->timeout);
477 } else { 526 } else {
478 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT); 527 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
528 }
479 } 529 }
480 if (bc != 1) 530 if (bc != 1)
481 dprintk(1,"%s: %d buffers handled (should be 1)\n",__FUNCTION__,bc); 531 dprintk(1,"%s: %d buffers handled (should be 1)\n",__FUNCTION__,bc);
@@ -522,6 +572,8 @@ static int vivi_thread(void *data)
522 572
523 dprintk(1,"thread started\n"); 573 dprintk(1,"thread started\n");
524 574
575 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
576
525 for (;;) { 577 for (;;) {
526 vivi_sleep(dma_q); 578 vivi_sleep(dma_q);
527 579
@@ -538,7 +590,6 @@ static int vivi_start_thread(struct vivi_dmaqueue *dma_q)
538 dma_q->ini_jiffies=jiffies; 590 dma_q->ini_jiffies=jiffies;
539 591
540 dprintk(1,"%s\n",__FUNCTION__); 592 dprintk(1,"%s\n",__FUNCTION__);
541 init_waitqueue_head(&dma_q->wq);
542 593
543 dma_q->kthread = kthread_run(vivi_thread, dma_q, "vivi"); 594 dma_q->kthread = kthread_run(vivi_thread, dma_q, "vivi");
544 595
@@ -546,6 +597,9 @@ static int vivi_start_thread(struct vivi_dmaqueue *dma_q)
546 printk(KERN_ERR "vivi: kernel_thread() failed\n"); 597 printk(KERN_ERR "vivi: kernel_thread() failed\n");
547 return PTR_ERR(dma_q->kthread); 598 return PTR_ERR(dma_q->kthread);
548 } 599 }
600 /* Wakes thread */
601 wake_up_interruptible(&dma_q->wq);
602
549 dprintk(1,"returning from %s\n",__FUNCTION__); 603 dprintk(1,"returning from %s\n",__FUNCTION__);
550 return 0; 604 return 0;
551} 605}
@@ -663,9 +717,11 @@ static void free_buffer(struct videobuf_queue *vq, struct vivi_buffer *buf)
663 if (in_interrupt()) 717 if (in_interrupt())
664 BUG(); 718 BUG();
665 719
720#ifdef CONFIG_VIVI_SCATTER
666 /*FIXME: Maybe a spinlock is required here */ 721 /*FIXME: Maybe a spinlock is required here */
667 kfree(buf->to_addr); 722 kfree(buf->to_addr);
668 buf->to_addr=NULL; 723 buf->to_addr=NULL;
724#endif
669 725
670 videobuf_waiton(&buf->vb,0,0); 726 videobuf_waiton(&buf->vb,0,0);
671 videobuf_dma_unmap(vq, &buf->vb.dma); 727 videobuf_dma_unmap(vq, &buf->vb.dma);
@@ -711,11 +767,12 @@ buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
711 767
712 buf->vb.state = STATE_PREPARED; 768 buf->vb.state = STATE_PREPARED;
713 769
770#ifdef CONFIG_VIVI_SCATTER
714 if (NULL == (buf->to_addr = kmalloc(sizeof(*buf->to_addr) * vb->dma.nr_pages,GFP_KERNEL))) { 771 if (NULL == (buf->to_addr = kmalloc(sizeof(*buf->to_addr) * vb->dma.nr_pages,GFP_KERNEL))) {
715 rc=-ENOMEM; 772 rc=-ENOMEM;
716 goto fail; 773 goto fail;
717 } 774 }
718 775#endif
719 return 0; 776 return 0;
720 777
721fail: 778fail:
@@ -780,6 +837,7 @@ static void buffer_release(struct videobuf_queue *vq, struct videobuf_buffer *vb
780 free_buffer(vq,buf); 837 free_buffer(vq,buf);
781} 838}
782 839
840#ifdef CONFIG_VIVI_SCATTER
783static int vivi_map_sg(void *dev, struct scatterlist *sg, int nents, 841static int vivi_map_sg(void *dev, struct scatterlist *sg, int nents,
784 int direction) 842 int direction)
785{ 843{
@@ -812,6 +870,7 @@ static int vivi_dma_sync_sg(void *dev,struct scatterlist *sglist, int nr_pages,
812// flush_write_buffers(); 870// flush_write_buffers();
813 return 0; 871 return 0;
814} 872}
873#endif
815 874
816static struct videobuf_queue_ops vivi_video_qops = { 875static struct videobuf_queue_ops vivi_video_qops = {
817 .buf_setup = buffer_setup, 876 .buf_setup = buffer_setup,
@@ -820,9 +879,9 @@ static struct videobuf_queue_ops vivi_video_qops = {
820 .buf_release = buffer_release, 879 .buf_release = buffer_release,
821 880
822 /* Non-pci handling routines */ 881 /* Non-pci handling routines */
823 .vb_map_sg = vivi_map_sg, 882// .vb_map_sg = vivi_map_sg,
824 .vb_dma_sync_sg = vivi_dma_sync_sg, 883// .vb_dma_sync_sg = vivi_dma_sync_sg,
825 .vb_unmap_sg = vivi_unmap_sg, 884// .vb_unmap_sg = vivi_unmap_sg,
826}; 885};
827 886
828/* ------------------------------------------------------------------ 887/* ------------------------------------------------------------------
@@ -1200,11 +1259,19 @@ static int vivi_open(struct inode *inode, struct file *file)
1200 sprintf(dev->timestr,"%02d:%02d:%02d:%03d", 1259 sprintf(dev->timestr,"%02d:%02d:%02d:%03d",
1201 dev->h,dev->m,dev->s,(dev->us+500)/1000); 1260 dev->h,dev->m,dev->s,(dev->us+500)/1000);
1202 1261
1262#ifdef CONFIG_VIVI_SCATTER
1263 videobuf_queue_init(&fh->vb_vidq,VIDEOBUF_DMA_SCATTER, &vivi_video_qops,
1264 NULL, NULL,
1265 fh->type,
1266 V4L2_FIELD_INTERLACED,
1267 sizeof(struct vivi_buffer),fh);
1268#else
1203 videobuf_queue_init(&fh->vb_vidq, &vivi_video_qops, 1269 videobuf_queue_init(&fh->vb_vidq, &vivi_video_qops,
1204 NULL, NULL, 1270 NULL, NULL,
1205 fh->type, 1271 fh->type,
1206 V4L2_FIELD_INTERLACED, 1272 V4L2_FIELD_INTERLACED,
1207 sizeof(struct vivi_buffer),fh); 1273 sizeof(struct vivi_buffer),fh);
1274#endif
1208 1275
1209 return 0; 1276 return 0;
1210} 1277}
@@ -1352,6 +1419,7 @@ static int __init vivi_init(void)
1352 /* init video dma queues */ 1419 /* init video dma queues */
1353 INIT_LIST_HEAD(&dev->vidq.active); 1420 INIT_LIST_HEAD(&dev->vidq.active);
1354 INIT_LIST_HEAD(&dev->vidq.queued); 1421 INIT_LIST_HEAD(&dev->vidq.queued);
1422 init_waitqueue_head(&dev->vidq.wq);
1355 1423
1356 /* initialize locks */ 1424 /* initialize locks */
1357 init_MUTEX(&dev->lock); 1425 init_MUTEX(&dev->lock);
diff --git a/drivers/media/video/zc0301/zc0301.h b/drivers/media/video/zc0301/zc0301.h
index b9c93b8c16..710f12eb91 100644
--- a/drivers/media/video/zc0301/zc0301.h
+++ b/drivers/media/video/zc0301/zc0301.h
@@ -1,7 +1,7 @@
1/*************************************************************************** 1/***************************************************************************
2 * V4L2 driver for ZC0301 Image Processor and Control Chip * 2 * V4L2 driver for ZC0301[P] Image Processor and Control Chip *
3 * * 3 * *
4 * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> * 4 * Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
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 *
diff --git a/drivers/media/video/zc0301/zc0301_core.c b/drivers/media/video/zc0301/zc0301_core.c
index 8da7f15f62..f1120551c7 100644
--- a/drivers/media/video/zc0301/zc0301_core.c
+++ b/drivers/media/video/zc0301/zc0301_core.c
@@ -1,7 +1,7 @@
1/*************************************************************************** 1/***************************************************************************
2 * Video4Linux2 driver for ZC0301[P] Image Processor and Control Chip * 2 * Video4Linux2 driver for ZC0301[P] Image Processor and Control Chip *
3 * * 3 * *
4 * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> * 4 * Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
5 * * 5 * *
6 * Informations about the chip internals needed to enable the I2C protocol * 6 * Informations about the chip internals needed to enable the I2C protocol *
7 * have been taken from the documentation of the ZC030x Video4Linux1 * 7 * have been taken from the documentation of the ZC030x Video4Linux1 *
@@ -52,8 +52,8 @@
52#define ZC0301_MODULE_AUTHOR "(C) 2006 Luca Risolia" 52#define ZC0301_MODULE_AUTHOR "(C) 2006 Luca Risolia"
53#define ZC0301_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>" 53#define ZC0301_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
54#define ZC0301_MODULE_LICENSE "GPL" 54#define ZC0301_MODULE_LICENSE "GPL"
55#define ZC0301_MODULE_VERSION "1:1.05" 55#define ZC0301_MODULE_VERSION "1:1.07"
56#define ZC0301_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 5) 56#define ZC0301_MODULE_VERSION_CODE KERNEL_VERSION(1, 1, 7)
57 57
58/*****************************************************************************/ 58/*****************************************************************************/
59 59
@@ -89,7 +89,7 @@ MODULE_PARM_DESC(force_munmap,
89 "\ndetected camera." 89 "\ndetected camera."
90 "\n 0 = do not force memory unmapping" 90 "\n 0 = do not force memory unmapping"
91 "\n 1 = force memory unmapping (save memory)" 91 "\n 1 = force memory unmapping (save memory)"
92 "\nDefault value is "__MODULE_STRING(SN9C102_FORCE_MUNMAP)"." 92 "\nDefault value is "__MODULE_STRING(ZC0301_FORCE_MUNMAP)"."
93 "\n"); 93 "\n");
94 94
95static unsigned int frame_timeout[] = {[0 ... ZC0301_MAX_DEVICES-1] = 95static unsigned int frame_timeout[] = {[0 ... ZC0301_MAX_DEVICES-1] =
@@ -136,7 +136,8 @@ zc0301_request_buffers(struct zc0301_device* cam, u32 count,
136 136
137 cam->nbuffers = count; 137 cam->nbuffers = count;
138 while (cam->nbuffers > 0) { 138 while (cam->nbuffers > 0) {
139 if ((buff = vmalloc_32(cam->nbuffers * PAGE_ALIGN(imagesize)))) 139 if ((buff = vmalloc_32_user(cam->nbuffers *
140 PAGE_ALIGN(imagesize))))
140 break; 141 break;
141 cam->nbuffers--; 142 cam->nbuffers--;
142 } 143 }
@@ -430,7 +431,8 @@ static int zc0301_start_transfer(struct zc0301_device* cam)
430 struct usb_host_interface* altsetting = usb_altnum_to_altsetting( 431 struct usb_host_interface* altsetting = usb_altnum_to_altsetting(
431 usb_ifnum_to_if(udev, 0), 432 usb_ifnum_to_if(udev, 0),
432 ZC0301_ALTERNATE_SETTING); 433 ZC0301_ALTERNATE_SETTING);
433 const unsigned int psz = altsetting->endpoint[0].desc.wMaxPacketSize; 434 const unsigned int psz = le16_to_cpu(altsetting->
435 endpoint[0].desc.wMaxPacketSize);
434 struct urb* urb; 436 struct urb* urb;
435 s8 i, j; 437 s8 i, j;
436 int err = 0; 438 int err = 0;
@@ -489,7 +491,7 @@ static int zc0301_start_transfer(struct zc0301_device* cam)
489 return 0; 491 return 0;
490 492
491free_urbs: 493free_urbs:
492 for (i = 0; i < ZC0301_URBS; i++) 494 for (i = 0; (i < ZC0301_URBS) && cam->urb[i]; i++)
493 usb_free_urb(cam->urb[i]); 495 usb_free_urb(cam->urb[i]);
494 496
495free_buffers: 497free_buffers:
@@ -1288,6 +1290,35 @@ zc0301_vidioc_s_crop(struct zc0301_device* cam, void __user * arg)
1288 1290
1289 1291
1290static int 1292static int
1293zc0301_vidioc_enum_framesizes(struct zc0301_device* cam, void __user * arg)
1294{
1295 struct v4l2_frmsizeenum frmsize;
1296
1297 if (copy_from_user(&frmsize, arg, sizeof(frmsize)))
1298 return -EFAULT;
1299
1300 if (frmsize.index != 0 && frmsize.index != 1)
1301 return -EINVAL;
1302
1303 if (frmsize.pixel_format != V4L2_PIX_FMT_JPEG)
1304 return -EINVAL;
1305
1306 frmsize.type = V4L2_FRMSIZE_TYPE_DISCRETE;
1307
1308 if (frmsize.index == 1) {
1309 frmsize.discrete.width = cam->sensor.cropcap.defrect.width;
1310 frmsize.discrete.height = cam->sensor.cropcap.defrect.height;
1311 }
1312 memset(&frmsize.reserved, 0, sizeof(frmsize.reserved));
1313
1314 if (copy_to_user(arg, &frmsize, sizeof(frmsize)))
1315 return -EFAULT;
1316
1317 return 0;
1318}
1319
1320
1321static int
1291zc0301_vidioc_enum_fmt(struct zc0301_device* cam, void __user * arg) 1322zc0301_vidioc_enum_fmt(struct zc0301_device* cam, void __user * arg)
1292{ 1323{
1293 struct v4l2_fmtdesc fmtd; 1324 struct v4l2_fmtdesc fmtd;
@@ -1295,6 +1326,9 @@ zc0301_vidioc_enum_fmt(struct zc0301_device* cam, void __user * arg)
1295 if (copy_from_user(&fmtd, arg, sizeof(fmtd))) 1326 if (copy_from_user(&fmtd, arg, sizeof(fmtd)))
1296 return -EFAULT; 1327 return -EFAULT;
1297 1328
1329 if (fmtd.type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1330 return -EINVAL;
1331
1298 if (fmtd.index == 0) { 1332 if (fmtd.index == 0) {
1299 strcpy(fmtd.description, "JPEG"); 1333 strcpy(fmtd.description, "JPEG");
1300 fmtd.pixelformat = V4L2_PIX_FMT_JPEG; 1334 fmtd.pixelformat = V4L2_PIX_FMT_JPEG;
@@ -1795,6 +1829,9 @@ static int zc0301_ioctl_v4l2(struct inode* inode, struct file* filp,
1795 case VIDIOC_S_FMT: 1829 case VIDIOC_S_FMT:
1796 return zc0301_vidioc_try_s_fmt(cam, cmd, arg); 1830 return zc0301_vidioc_try_s_fmt(cam, cmd, arg);
1797 1831
1832 case VIDIOC_ENUM_FRAMESIZES:
1833 return zc0301_vidioc_enum_framesizes(cam, arg);
1834
1798 case VIDIOC_G_JPEGCOMP: 1835 case VIDIOC_G_JPEGCOMP:
1799 return zc0301_vidioc_g_jpegcomp(cam, arg); 1836 return zc0301_vidioc_g_jpegcomp(cam, arg);
1800 1837
@@ -1830,6 +1867,7 @@ static int zc0301_ioctl_v4l2(struct inode* inode, struct file* filp,
1830 case VIDIOC_QUERYSTD: 1867 case VIDIOC_QUERYSTD:
1831 case VIDIOC_ENUMSTD: 1868 case VIDIOC_ENUMSTD:
1832 case VIDIOC_QUERYMENU: 1869 case VIDIOC_QUERYMENU:
1870 case VIDIOC_ENUM_FRAMEINTERVALS:
1833 return -EINVAL; 1871 return -EINVAL;
1834 1872
1835 default: 1873 default:
@@ -1876,6 +1914,7 @@ static const struct file_operations zc0301_fops = {
1876 .open = zc0301_open, 1914 .open = zc0301_open,
1877 .release = zc0301_release, 1915 .release = zc0301_release,
1878 .ioctl = zc0301_ioctl, 1916 .ioctl = zc0301_ioctl,
1917 .compat_ioctl = v4l_compat_ioctl32,
1879 .read = zc0301_read, 1918 .read = zc0301_read,
1880 .poll = zc0301_poll, 1919 .poll = zc0301_poll,
1881 .mmap = zc0301_mmap, 1920 .mmap = zc0301_mmap,
@@ -1913,7 +1952,7 @@ zc0301_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
1913 mutex_init(&cam->dev_mutex); 1952 mutex_init(&cam->dev_mutex);
1914 1953
1915 DBG(2, "ZC0301[P] Image Processor and Control Chip detected " 1954 DBG(2, "ZC0301[P] Image Processor and Control Chip detected "
1916 "(vid/pid 0x%04X/0x%04X)",id->idVendor, id->idProduct); 1955 "(vid/pid 0x%04X:0x%04X)",id->idVendor, id->idProduct);
1917 1956
1918 for (i = 0; zc0301_sensor_table[i]; i++) { 1957 for (i = 0; zc0301_sensor_table[i]; i++) {
1919 err = zc0301_sensor_table[i](cam); 1958 err = zc0301_sensor_table[i](cam);
diff --git a/drivers/media/video/zc0301/zc0301_pas202bcb.c b/drivers/media/video/zc0301/zc0301_pas202bcb.c
index ecfd39a56d..3efb92a0d0 100644
--- a/drivers/media/video/zc0301/zc0301_pas202bcb.c
+++ b/drivers/media/video/zc0301/zc0301_pas202bcb.c
@@ -1,8 +1,8 @@
1/*************************************************************************** 1/***************************************************************************
2 * Plug-in for PAS202BCB image sensor connected to the ZC0301[P] Image * 2 * Plug-in for PAS202BCB image sensor connected to the ZC0301 Image *
3 * Processor and Control Chip * 3 * Processor and Control Chip *
4 * * 4 * *
5 * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> * 5 * Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
6 * * 6 * *
7 * Initialization values of the ZC0301[P] have been taken from the SPCA5XX * 7 * Initialization values of the ZC0301[P] have been taken from the SPCA5XX *
8 * driver maintained by Michel Xhaard <mxhaard@magic.fr> * 8 * driver maintained by Michel Xhaard <mxhaard@magic.fr> *
diff --git a/drivers/media/video/zc0301/zc0301_pb0330.c b/drivers/media/video/zc0301/zc0301_pb0330.c
index ed8542e6c5..5784b1d149 100644
--- a/drivers/media/video/zc0301/zc0301_pb0330.c
+++ b/drivers/media/video/zc0301/zc0301_pb0330.c
@@ -1,8 +1,8 @@
1/*************************************************************************** 1/***************************************************************************
2 * Plug-in for PB-0330 image sensor connected to the ZC0301[P] Image * 2 * Plug-in for PB-0330 image sensor connected to the ZC0301P Image *
3 * Processor and Control Chip * 3 * Processor and Control Chip *
4 * * 4 * *
5 * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> * 5 * Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
6 * * 6 * *
7 * Initialization values of the ZC0301[P] have been taken from the SPCA5XX * 7 * Initialization values of the ZC0301[P] have been taken from the SPCA5XX *
8 * driver maintained by Michel Xhaard <mxhaard@magic.fr> * 8 * driver maintained by Michel Xhaard <mxhaard@magic.fr> *
diff --git a/drivers/media/video/zc0301/zc0301_sensor.h b/drivers/media/video/zc0301/zc0301_sensor.h
index 3daf049a28..44e82cff93 100644
--- a/drivers/media/video/zc0301/zc0301_sensor.h
+++ b/drivers/media/video/zc0301/zc0301_sensor.h
@@ -1,8 +1,8 @@
1/*************************************************************************** 1/***************************************************************************
2 * API for image sensors connected to the ZC0301 Image Processor and * 2 * API for image sensors connected to the ZC0301[P] Image Processor and *
3 * Control Chip * 3 * Control Chip *
4 * * 4 * *
5 * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> * 5 * Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
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 *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
@@ -70,7 +70,7 @@ static const struct usb_device_id zc0301_id_table[] = { \
70 { ZC0301_USB_DEVICE(0x041e, 0x4036, 0xff), }, /* HV7131 */ \ 70 { ZC0301_USB_DEVICE(0x041e, 0x4036, 0xff), }, /* HV7131 */ \
71 { ZC0301_USB_DEVICE(0x041e, 0x403a, 0xff), }, /* HV7131 */ \ 71 { ZC0301_USB_DEVICE(0x041e, 0x403a, 0xff), }, /* HV7131 */ \
72 { ZC0301_USB_DEVICE(0x0458, 0x7007, 0xff), }, /* TAS5130 */ \ 72 { ZC0301_USB_DEVICE(0x0458, 0x7007, 0xff), }, /* TAS5130 */ \
73 { ZC0301_USB_DEVICE(0x0458, 0x700C, 0xff), }, /* TAS5130 */ \ 73 { ZC0301_USB_DEVICE(0x0458, 0x700c, 0xff), }, /* TAS5130 */ \
74 { ZC0301_USB_DEVICE(0x0458, 0x700f, 0xff), }, /* TAS5130 */ \ 74 { ZC0301_USB_DEVICE(0x0458, 0x700f, 0xff), }, /* TAS5130 */ \
75 { ZC0301_USB_DEVICE(0x046d, 0x08ae, 0xff), }, /* PAS202 */ \ 75 { ZC0301_USB_DEVICE(0x046d, 0x08ae, 0xff), }, /* PAS202 */ \
76 { ZC0301_USB_DEVICE(0x055f, 0xd003, 0xff), }, /* TAS5130 */ \ 76 { ZC0301_USB_DEVICE(0x055f, 0xd003, 0xff), }, /* TAS5130 */ \
@@ -93,9 +93,9 @@ extern int zc0301_i2c_read(struct zc0301_device*, u16 address, u8 length);
93 93
94/*****************************************************************************/ 94/*****************************************************************************/
95 95
96#define ZC0301_MAX_CTRLS V4L2_CID_LASTP1-V4L2_CID_BASE+10 96#define ZC0301_MAX_CTRLS (V4L2_CID_LASTP1 - V4L2_CID_BASE + 10)
97#define ZC0301_V4L2_CID_DAC_MAGNITUDE V4L2_CID_PRIVATE_BASE 97#define ZC0301_V4L2_CID_DAC_MAGNITUDE (V4L2_CID_PRIVATE_BASE + 0)
98#define ZC0301_V4L2_CID_GREEN_BALANCE V4L2_CID_PRIVATE_BASE + 1 98#define ZC0301_V4L2_CID_GREEN_BALANCE (V4L2_CID_PRIVATE_BASE + 1)
99 99
100struct zc0301_sensor { 100struct zc0301_sensor {
101 char name[32]; 101 char name[32];
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index fc3c8854f4..ab6e985275 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2,6 +2,20 @@
2# Multifunction miscellaneous devices 2# Multifunction miscellaneous devices
3# 3#
4 4
5menu "Multifunction device drivers"
6
7config MFD_SM501
8 tristate "Support for Silicon Motion SM501"
9 ---help---
10 This is the core driver for the Silicon Motion SM501 multimedia
11 companion chip. This device is a multifunction device which may
12 provide numerous interfaces including USB host controller USB gadget,
13 Asyncronous Serial ports, Audio functions and a dual display video
14 interface. The device may be connected by PCI or local bus with
15 varying functions enabled.
16
17endmenu
18
5menu "Multimedia Capabilities Port drivers" 19menu "Multimedia Capabilities Port drivers"
6 depends on ARCH_SA1100 20 depends on ARCH_SA1100
7 21
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index adb29b5368..51432091b3 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -2,6 +2,8 @@
2# Makefile for multifunction miscellaneous devices 2# Makefile for multifunction miscellaneous devices
3# 3#
4 4
5obj-$(CONFIG_MFD_SM501) += sm501.o
6
5obj-$(CONFIG_MCP) += mcp-core.o 7obj-$(CONFIG_MCP) += mcp-core.o
6obj-$(CONFIG_MCP_SA11X0) += mcp-sa11x0.o 8obj-$(CONFIG_MCP_SA11X0) += mcp-sa11x0.o
7obj-$(CONFIG_MCP_UCB1200) += ucb1x00-core.o 9obj-$(CONFIG_MCP_UCB1200) += ucb1x00-core.o
diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c
new file mode 100644
index 0000000000..c707c8ebc1
--- /dev/null
+++ b/drivers/mfd/sm501.c
@@ -0,0 +1,1148 @@
1/* linux/drivers/mfd/sm501.c
2 *
3 * Copyright (C) 2006 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
5 * Vincent Sanders <vince@simtec.co.uk>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * SM501 MFD driver
12*/
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/delay.h>
17#include <linux/init.h>
18#include <linux/list.h>
19#include <linux/device.h>
20#include <linux/platform_device.h>
21#include <linux/pci.h>
22
23#include <linux/sm501.h>
24#include <linux/sm501-regs.h>
25
26#include <asm/io.h>
27
28struct sm501_device {
29 struct list_head list;
30 struct platform_device pdev;
31};
32
33struct sm501_devdata {
34 spinlock_t reg_lock;
35 struct mutex clock_lock;
36 struct list_head devices;
37
38 struct device *dev;
39 struct resource *io_res;
40 struct resource *mem_res;
41 struct resource *regs_claim;
42 struct sm501_platdata *platdata;
43
44 int unit_power[20];
45 unsigned int pdev_id;
46 unsigned int irq;
47 void __iomem *regs;
48};
49
50#define MHZ (1000 * 1000)
51
52#ifdef DEBUG
53static const unsigned int misc_div[] = {
54 [0] = 1,
55 [1] = 2,
56 [2] = 4,
57 [3] = 8,
58 [4] = 16,
59 [5] = 32,
60 [6] = 64,
61 [7] = 128,
62 [8] = 3,
63 [9] = 6,
64 [10] = 12,
65 [11] = 24,
66 [12] = 48,
67 [13] = 96,
68 [14] = 192,
69 [15] = 384,
70};
71
72static const unsigned int px_div[] = {
73 [0] = 1,
74 [1] = 2,
75 [2] = 4,
76 [3] = 8,
77 [4] = 16,
78 [5] = 32,
79 [6] = 64,
80 [7] = 128,
81 [8] = 3,
82 [9] = 6,
83 [10] = 12,
84 [11] = 24,
85 [12] = 48,
86 [13] = 96,
87 [14] = 192,
88 [15] = 384,
89 [16] = 5,
90 [17] = 10,
91 [18] = 20,
92 [19] = 40,
93 [20] = 80,
94 [21] = 160,
95 [22] = 320,
96 [23] = 604,
97};
98
99static unsigned long decode_div(unsigned long pll2, unsigned long val,
100 unsigned int lshft, unsigned int selbit,
101 unsigned long mask, const unsigned int *dtab)
102{
103 if (val & selbit)
104 pll2 = 288 * MHZ;
105
106 return pll2 / dtab[(val >> lshft) & mask];
107}
108
109#define fmt_freq(x) ((x) / MHZ), ((x) % MHZ), (x)
110
111/* sm501_dump_clk
112 *
113 * Print out the current clock configuration for the device
114*/
115
116static void sm501_dump_clk(struct sm501_devdata *sm)
117{
118 unsigned long misct = readl(sm->regs + SM501_MISC_TIMING);
119 unsigned long pm0 = readl(sm->regs + SM501_POWER_MODE_0_CLOCK);
120 unsigned long pm1 = readl(sm->regs + SM501_POWER_MODE_1_CLOCK);
121 unsigned long pmc = readl(sm->regs + SM501_POWER_MODE_CONTROL);
122 unsigned long sdclk0, sdclk1;
123 unsigned long pll2 = 0;
124
125 switch (misct & 0x30) {
126 case 0x00:
127 pll2 = 336 * MHZ;
128 break;
129 case 0x10:
130 pll2 = 288 * MHZ;
131 break;
132 case 0x20:
133 pll2 = 240 * MHZ;
134 break;
135 case 0x30:
136 pll2 = 192 * MHZ;
137 break;
138 }
139
140 sdclk0 = (misct & (1<<12)) ? pll2 : 288 * MHZ;
141 sdclk0 /= misc_div[((misct >> 8) & 0xf)];
142
143 sdclk1 = (misct & (1<<20)) ? pll2 : 288 * MHZ;
144 sdclk1 /= misc_div[((misct >> 16) & 0xf)];
145
146 dev_dbg(sm->dev, "MISCT=%08lx, PM0=%08lx, PM1=%08lx\n",
147 misct, pm0, pm1);
148
149 dev_dbg(sm->dev, "PLL2 = %ld.%ld MHz (%ld), SDCLK0=%08lx, SDCLK1=%08lx\n",
150 fmt_freq(pll2), sdclk0, sdclk1);
151
152 dev_dbg(sm->dev, "SDRAM: PM0=%ld, PM1=%ld\n", sdclk0, sdclk1);
153
154 dev_dbg(sm->dev, "PM0[%c]: "
155 "P2 %ld.%ld MHz (%ld), V2 %ld.%ld (%ld), "
156x "M %ld.%ld (%ld), MX1 %ld.%ld (%ld)\n",
157 (pmc & 3 ) == 0 ? '*' : '-',
158 fmt_freq(decode_div(pll2, pm0, 24, 1<<29, 31, px_div)),
159 fmt_freq(decode_div(pll2, pm0, 16, 1<<20, 15, misc_div)),
160 fmt_freq(decode_div(pll2, pm0, 8, 1<<12, 15, misc_div)),
161 fmt_freq(decode_div(pll2, pm0, 0, 1<<4, 15, misc_div)));
162
163 dev_dbg(sm->dev, "PM1[%c]: "
164 "P2 %ld.%ld MHz (%ld), V2 %ld.%ld (%ld), "
165 "M %ld.%ld (%ld), MX1 %ld.%ld (%ld)\n",
166 (pmc & 3 ) == 1 ? '*' : '-',
167 fmt_freq(decode_div(pll2, pm1, 24, 1<<29, 31, px_div)),
168 fmt_freq(decode_div(pll2, pm1, 16, 1<<20, 15, misc_div)),
169 fmt_freq(decode_div(pll2, pm1, 8, 1<<12, 15, misc_div)),
170 fmt_freq(decode_div(pll2, pm1, 0, 1<<4, 15, misc_div)));
171}
172#else
173static void sm501_dump_clk(struct sm501_devdata *sm)
174{
175}
176#endif
177
178/* sm501_sync_regs
179 *
180 * ensure the
181*/
182
183static void sm501_sync_regs(struct sm501_devdata *sm)
184{
185 readl(sm->regs);
186}
187
188/* sm501_misc_control
189 *
190 * alters the misceleneous control parameters
191*/
192
193int sm501_misc_control(struct device *dev,
194 unsigned long set, unsigned long clear)
195{
196 struct sm501_devdata *sm = dev_get_drvdata(dev);
197 unsigned long misc;
198 unsigned long save;
199 unsigned long to;
200
201 spin_lock_irqsave(&sm->reg_lock, save);
202
203 misc = readl(sm->regs + SM501_MISC_CONTROL);
204 to = (misc & ~clear) | set;
205
206 if (to != misc) {
207 writel(to, sm->regs + SM501_MISC_CONTROL);
208 sm501_sync_regs(sm);
209
210 dev_dbg(sm->dev, "MISC_CONTROL %08lx\n", misc);
211 }
212
213 spin_unlock_irqrestore(&sm->reg_lock, save);
214 return to;
215}
216
217EXPORT_SYMBOL_GPL(sm501_misc_control);
218
219/* sm501_modify_reg
220 *
221 * Modify a register in the SM501 which may be shared with other
222 * drivers.
223*/
224
225unsigned long sm501_modify_reg(struct device *dev,
226 unsigned long reg,
227 unsigned long set,
228 unsigned long clear)
229{
230 struct sm501_devdata *sm = dev_get_drvdata(dev);
231 unsigned long data;
232 unsigned long save;
233
234 spin_lock_irqsave(&sm->reg_lock, save);
235
236 data = readl(sm->regs + reg);
237 data |= set;
238 data &= ~clear;
239
240 writel(data, sm->regs + reg);
241 sm501_sync_regs(sm);
242
243 spin_unlock_irqrestore(&sm->reg_lock, save);
244
245 return data;
246}
247
248EXPORT_SYMBOL_GPL(sm501_modify_reg);
249
250unsigned long sm501_gpio_get(struct device *dev,
251 unsigned long gpio)
252{
253 struct sm501_devdata *sm = dev_get_drvdata(dev);
254 unsigned long result;
255 unsigned long reg;
256
257 reg = (gpio > 32) ? SM501_GPIO_DATA_HIGH : SM501_GPIO_DATA_LOW;
258 result = readl(sm->regs + reg);
259
260 result >>= (gpio & 31);
261 return result & 1UL;
262}
263
264EXPORT_SYMBOL_GPL(sm501_gpio_get);
265
266void sm501_gpio_set(struct device *dev,
267 unsigned long gpio,
268 unsigned int to,
269 unsigned int dir)
270{
271 struct sm501_devdata *sm = dev_get_drvdata(dev);
272
273 unsigned long bit = 1 << (gpio & 31);
274 unsigned long base;
275 unsigned long save;
276 unsigned long val;
277
278 base = (gpio > 32) ? SM501_GPIO_DATA_HIGH : SM501_GPIO_DATA_LOW;
279 base += SM501_GPIO;
280
281 spin_lock_irqsave(&sm->reg_lock, save);
282
283 val = readl(sm->regs + base) & ~bit;
284 if (to)
285 val |= bit;
286 writel(val, sm->regs + base);
287
288 val = readl(sm->regs + SM501_GPIO_DDR_LOW) & ~bit;
289 if (dir)
290 val |= bit;
291
292 writel(val, sm->regs + SM501_GPIO_DDR_LOW);
293 sm501_sync_regs(sm);
294
295 spin_unlock_irqrestore(&sm->reg_lock, save);
296
297}
298
299EXPORT_SYMBOL_GPL(sm501_gpio_set);
300
301
302/* sm501_unit_power
303 *
304 * alters the power active gate to set specific units on or off
305 */
306
307int sm501_unit_power(struct device *dev, unsigned int unit, unsigned int to)
308{
309 struct sm501_devdata *sm = dev_get_drvdata(dev);
310 unsigned long mode;
311 unsigned long gate;
312 unsigned long clock;
313
314 mutex_lock(&sm->clock_lock);
315
316 mode = readl(sm->regs + SM501_POWER_MODE_CONTROL);
317 gate = readl(sm->regs + SM501_CURRENT_GATE);
318 clock = readl(sm->regs + SM501_CURRENT_CLOCK);
319
320 mode &= 3; /* get current power mode */
321
322 if (unit > ARRAY_SIZE(sm->unit_power)) {
323 dev_err(dev, "%s: bad unit %d\n", __FUNCTION__, unit);
324 goto already;
325 }
326
327 dev_dbg(sm->dev, "%s: unit %d, cur %d, to %d\n", __FUNCTION__, unit,
328 sm->unit_power[unit], to);
329
330 if (to == 0 && sm->unit_power[unit] == 0) {
331 dev_err(sm->dev, "unit %d is already shutdown\n", unit);
332 goto already;
333 }
334
335 sm->unit_power[unit] += to ? 1 : -1;
336 to = sm->unit_power[unit] ? 1 : 0;
337
338 if (to) {
339 if (gate & (1 << unit))
340 goto already;
341 gate |= (1 << unit);
342 } else {
343 if (!(gate & (1 << unit)))
344 goto already;
345 gate &= ~(1 << unit);
346 }
347
348 switch (mode) {
349 case 1:
350 writel(gate, sm->regs + SM501_POWER_MODE_0_GATE);
351 writel(clock, sm->regs + SM501_POWER_MODE_0_CLOCK);
352 mode = 0;
353 break;
354 case 2:
355 case 0:
356 writel(gate, sm->regs + SM501_POWER_MODE_1_GATE);
357 writel(clock, sm->regs + SM501_POWER_MODE_1_CLOCK);
358 mode = 1;
359 break;
360
361 default:
362 return -1;
363 }
364
365 writel(mode, sm->regs + SM501_POWER_MODE_CONTROL);
366 sm501_sync_regs(sm);
367
368 dev_dbg(sm->dev, "gate %08lx, clock %08lx, mode %08lx\n",
369 gate, clock, mode);
370
371 msleep(16);
372
373 already:
374 mutex_unlock(&sm->clock_lock);
375 return gate;
376}
377
378EXPORT_SYMBOL_GPL(sm501_unit_power);
379
380
381/* Perform a rounded division. */
382static long sm501fb_round_div(long num, long denom)
383{
384 /* n / d + 1 / 2 = (2n + d) / 2d */
385 return (2 * num + denom) / (2 * denom);
386}
387
388/* clock value structure. */
389struct sm501_clock {
390 unsigned long mclk;
391 int divider;
392 int shift;
393};
394
395/* sm501_select_clock
396 *
397 * selects nearest discrete clock frequency the SM501 can achive
398 * the maximum divisor is 3 or 5
399 */
400static unsigned long sm501_select_clock(unsigned long freq,
401 struct sm501_clock *clock,
402 int max_div)
403{
404 unsigned long mclk;
405 int divider;
406 int shift;
407 long diff;
408 long best_diff = 999999999;
409
410 /* Try 288MHz and 336MHz clocks. */
411 for (mclk = 288000000; mclk <= 336000000; mclk += 48000000) {
412 /* try dividers 1 and 3 for CRT and for panel,
413 try divider 5 for panel only.*/
414
415 for (divider = 1; divider <= max_div; divider += 2) {
416 /* try all 8 shift values.*/
417 for (shift = 0; shift < 8; shift++) {
418 /* Calculate difference to requested clock */
419 diff = sm501fb_round_div(mclk, divider << shift) - freq;
420 if (diff < 0)
421 diff = -diff;
422
423 /* If it is less than the current, use it */
424 if (diff < best_diff) {
425 best_diff = diff;
426
427 clock->mclk = mclk;
428 clock->divider = divider;
429 clock->shift = shift;
430 }
431 }
432 }
433 }
434
435 /* Return best clock. */
436 return clock->mclk / (clock->divider << clock->shift);
437}
438
439/* sm501_set_clock
440 *
441 * set one of the four clock sources to the closest available frequency to
442 * the one specified
443*/
444
445unsigned long sm501_set_clock(struct device *dev,
446 int clksrc,
447 unsigned long req_freq)
448{
449 struct sm501_devdata *sm = dev_get_drvdata(dev);
450 unsigned long mode = readl(sm->regs + SM501_POWER_MODE_CONTROL);
451 unsigned long gate = readl(sm->regs + SM501_CURRENT_GATE);
452 unsigned long clock = readl(sm->regs + SM501_CURRENT_CLOCK);
453 unsigned char reg;
454 unsigned long sm501_freq; /* the actual frequency acheived */
455
456 struct sm501_clock to;
457
458 /* find achivable discrete frequency and setup register value
459 * accordingly, V2XCLK, MCLK and M1XCLK are the same P2XCLK
460 * has an extra bit for the divider */
461
462 switch (clksrc) {
463 case SM501_CLOCK_P2XCLK:
464 /* This clock is divided in half so to achive the
465 * requested frequency the value must be multiplied by
466 * 2. This clock also has an additional pre divisor */
467
468 sm501_freq = (sm501_select_clock(2 * req_freq, &to, 5) / 2);
469 reg=to.shift & 0x07;/* bottom 3 bits are shift */
470 if (to.divider == 3)
471 reg |= 0x08; /* /3 divider required */
472 else if (to.divider == 5)
473 reg |= 0x10; /* /5 divider required */
474 if (to.mclk != 288000000)
475 reg |= 0x20; /* which mclk pll is source */
476 break;
477
478 case SM501_CLOCK_V2XCLK:
479 /* This clock is divided in half so to achive the
480 * requested frequency the value must be multiplied by 2. */
481
482 sm501_freq = (sm501_select_clock(2 * req_freq, &to, 3) / 2);
483 reg=to.shift & 0x07; /* bottom 3 bits are shift */
484 if (to.divider == 3)
485 reg |= 0x08; /* /3 divider required */
486 if (to.mclk != 288000000)
487 reg |= 0x10; /* which mclk pll is source */
488 break;
489
490 case SM501_CLOCK_MCLK:
491 case SM501_CLOCK_M1XCLK:
492 /* These clocks are the same and not further divided */
493
494 sm501_freq = sm501_select_clock( req_freq, &to, 3);
495 reg=to.shift & 0x07; /* bottom 3 bits are shift */
496 if (to.divider == 3)
497 reg |= 0x08; /* /3 divider required */
498 if (to.mclk != 288000000)
499 reg |= 0x10; /* which mclk pll is source */
500 break;
501
502 default:
503 return 0; /* this is bad */
504 }
505
506 mutex_lock(&sm->clock_lock);
507
508 mode = readl(sm->regs + SM501_POWER_MODE_CONTROL);
509 gate = readl(sm->regs + SM501_CURRENT_GATE);
510 clock = readl(sm->regs + SM501_CURRENT_CLOCK);
511
512 clock = clock & ~(0xFF << clksrc);
513 clock |= reg<<clksrc;
514
515 mode &= 3; /* find current mode */
516
517 switch (mode) {
518 case 1:
519 writel(gate, sm->regs + SM501_POWER_MODE_0_GATE);
520 writel(clock, sm->regs + SM501_POWER_MODE_0_CLOCK);
521 mode = 0;
522 break;
523 case 2:
524 case 0:
525 writel(gate, sm->regs + SM501_POWER_MODE_1_GATE);
526 writel(clock, sm->regs + SM501_POWER_MODE_1_CLOCK);
527 mode = 1;
528 break;
529
530 default:
531 mutex_unlock(&sm->clock_lock);
532 return -1;
533 }
534
535 writel(mode, sm->regs + SM501_POWER_MODE_CONTROL);
536 sm501_sync_regs(sm);
537
538 dev_info(sm->dev, "gate %08lx, clock %08lx, mode %08lx\n",
539 gate, clock, mode);
540
541 msleep(16);
542 mutex_unlock(&sm->clock_lock);
543
544 sm501_dump_clk(sm);
545
546 return sm501_freq;
547}
548
549EXPORT_SYMBOL_GPL(sm501_set_clock);
550
551/* sm501_find_clock
552 *
553 * finds the closest available frequency for a given clock
554*/
555
556unsigned long sm501_find_clock(int clksrc,
557 unsigned long req_freq)
558{
559 unsigned long sm501_freq; /* the frequency achiveable by the 501 */
560 struct sm501_clock to;
561
562 switch (clksrc) {
563 case SM501_CLOCK_P2XCLK:
564 sm501_freq = (sm501_select_clock(2 * req_freq, &to, 5) / 2);
565 break;
566
567 case SM501_CLOCK_V2XCLK:
568 sm501_freq = (sm501_select_clock(2 * req_freq, &to, 3) / 2);
569 break;
570
571 case SM501_CLOCK_MCLK:
572 case SM501_CLOCK_M1XCLK:
573 sm501_freq = sm501_select_clock(req_freq, &to, 3);
574 break;
575
576 default:
577 sm501_freq = 0; /* error */
578 }
579
580 return sm501_freq;
581}
582
583EXPORT_SYMBOL_GPL(sm501_find_clock);
584
585static struct sm501_device *to_sm_device(struct platform_device *pdev)
586{
587 return container_of(pdev, struct sm501_device, pdev);
588}
589
590/* sm501_device_release
591 *
592 * A release function for the platform devices we create to allow us to
593 * free any items we allocated
594*/
595
596static void sm501_device_release(struct device *dev)
597{
598 kfree(to_sm_device(to_platform_device(dev)));
599}
600
601/* sm501_create_subdev
602 *
603 * Create a skeleton platform device with resources for passing to a
604 * sub-driver
605*/
606
607static struct platform_device *
608sm501_create_subdev(struct sm501_devdata *sm,
609 char *name, unsigned int res_count)
610{
611 struct sm501_device *smdev;
612
613 smdev = kzalloc(sizeof(struct sm501_device) +
614 sizeof(struct resource) * res_count, GFP_KERNEL);
615 if (!smdev)
616 return NULL;
617
618 smdev->pdev.dev.release = sm501_device_release;
619
620 smdev->pdev.name = name;
621 smdev->pdev.id = sm->pdev_id;
622 smdev->pdev.resource = (struct resource *)(smdev+1);
623 smdev->pdev.num_resources = res_count;
624
625 smdev->pdev.dev.parent = sm->dev;
626
627 return &smdev->pdev;
628}
629
630/* sm501_register_device
631 *
632 * Register a platform device created with sm501_create_subdev()
633*/
634
635static int sm501_register_device(struct sm501_devdata *sm,
636 struct platform_device *pdev)
637{
638 struct sm501_device *smdev = to_sm_device(pdev);
639 int ptr;
640 int ret;
641
642 for (ptr = 0; ptr < pdev->num_resources; ptr++) {
643 printk("%s[%d] flags %08lx: %08llx..%08llx\n",
644 pdev->name, ptr,
645 pdev->resource[ptr].flags,
646 (unsigned long long)pdev->resource[ptr].start,
647 (unsigned long long)pdev->resource[ptr].end);
648 }
649
650 ret = platform_device_register(pdev);
651
652 if (ret >= 0) {
653 dev_dbg(sm->dev, "registered %s\n", pdev->name);
654 list_add_tail(&smdev->list, &sm->devices);
655 } else
656 dev_err(sm->dev, "error registering %s (%d)\n",
657 pdev->name, ret);
658
659 return ret;
660}
661
662/* sm501_create_subio
663 *
664 * Fill in an IO resource for a sub device
665*/
666
667static void sm501_create_subio(struct sm501_devdata *sm,
668 struct resource *res,
669 resource_size_t offs,
670 resource_size_t size)
671{
672 res->flags = IORESOURCE_MEM;
673 res->parent = sm->io_res;
674 res->start = sm->io_res->start + offs;
675 res->end = res->start + size - 1;
676}
677
678/* sm501_create_mem
679 *
680 * Fill in an MEM resource for a sub device
681*/
682
683static void sm501_create_mem(struct sm501_devdata *sm,
684 struct resource *res,
685 resource_size_t *offs,
686 resource_size_t size)
687{
688 *offs -= size; /* adjust memory size */
689
690 res->flags = IORESOURCE_MEM;
691 res->parent = sm->mem_res;
692 res->start = sm->mem_res->start + *offs;
693 res->end = res->start + size - 1;
694}
695
696/* sm501_create_irq
697 *
698 * Fill in an IRQ resource for a sub device
699*/
700
701static void sm501_create_irq(struct sm501_devdata *sm,
702 struct resource *res)
703{
704 res->flags = IORESOURCE_IRQ;
705 res->parent = NULL;
706 res->start = res->end = sm->irq;
707}
708
709static int sm501_register_usbhost(struct sm501_devdata *sm,
710 resource_size_t *mem_avail)
711{
712 struct platform_device *pdev;
713
714 pdev = sm501_create_subdev(sm, "sm501-usb", 3);
715 if (!pdev)
716 return -ENOMEM;
717
718 sm501_create_subio(sm, &pdev->resource[0], 0x40000, 0x20000);
719 sm501_create_mem(sm, &pdev->resource[1], mem_avail, 256*1024);
720 sm501_create_irq(sm, &pdev->resource[2]);
721
722 return sm501_register_device(sm, pdev);
723}
724
725static int sm501_register_display(struct sm501_devdata *sm,
726 resource_size_t *mem_avail)
727{
728 struct platform_device *pdev;
729
730 pdev = sm501_create_subdev(sm, "sm501-fb", 4);
731 if (!pdev)
732 return -ENOMEM;
733
734 sm501_create_subio(sm, &pdev->resource[0], 0x80000, 0x10000);
735 sm501_create_subio(sm, &pdev->resource[1], 0x100000, 0x50000);
736 sm501_create_mem(sm, &pdev->resource[2], mem_avail, *mem_avail);
737 sm501_create_irq(sm, &pdev->resource[3]);
738
739 return sm501_register_device(sm, pdev);
740}
741
742/* sm501_dbg_regs
743 *
744 * Debug attribute to attach to parent device to show core registers
745*/
746
747static ssize_t sm501_dbg_regs(struct device *dev,
748 struct device_attribute *attr, char *buff)
749{
750 struct sm501_devdata *sm = dev_get_drvdata(dev) ;
751 unsigned int reg;
752 char *ptr = buff;
753 int ret;
754
755 for (reg = 0x00; reg < 0x70; reg += 4) {
756 ret = sprintf(ptr, "%08x = %08x\n",
757 reg, readl(sm->regs + reg));
758 ptr += ret;
759 }
760
761 return ptr - buff;
762}
763
764
765static DEVICE_ATTR(dbg_regs, 0666, sm501_dbg_regs, NULL);
766
767/* sm501_init_reg
768 *
769 * Helper function for the init code to setup a register
770*/
771
772static inline void sm501_init_reg(struct sm501_devdata *sm,
773 unsigned long reg,
774 struct sm501_reg_init *r)
775{
776 unsigned long tmp;
777
778 tmp = readl(sm->regs + reg);
779 tmp |= r->set;
780 tmp &= ~r->mask;
781 writel(tmp, sm->regs + reg);
782}
783
784/* sm501_init_regs
785 *
786 * Setup core register values
787*/
788
789static void sm501_init_regs(struct sm501_devdata *sm,
790 struct sm501_initdata *init)
791{
792 sm501_misc_control(sm->dev,
793 init->misc_control.set,
794 init->misc_control.mask);
795
796 sm501_init_reg(sm, SM501_MISC_TIMING, &init->misc_timing);
797 sm501_init_reg(sm, SM501_GPIO31_0_CONTROL, &init->gpio_low);
798 sm501_init_reg(sm, SM501_GPIO63_32_CONTROL, &init->gpio_high);
799
800 if (init->mclk) {
801 dev_info(sm->dev, "setting MCLK to %ld\n", init->mclk);
802 sm501_set_clock(sm->dev, SM501_CLOCK_MCLK, init->mclk);
803 }
804
805 if (init->m1xclk) {
806 dev_info(sm->dev, "setting M1XCLK to %ld\n", init->m1xclk);
807 sm501_set_clock(sm->dev, SM501_CLOCK_M1XCLK, init->m1xclk);
808 }
809}
810
811static unsigned int sm501_mem_local[] = {
812 [0] = 4*1024*1024,
813 [1] = 8*1024*1024,
814 [2] = 16*1024*1024,
815 [3] = 32*1024*1024,
816 [4] = 64*1024*1024,
817 [5] = 2*1024*1024,
818};
819
820/* sm501_init_dev
821 *
822 * Common init code for an SM501
823*/
824
825static int sm501_init_dev(struct sm501_devdata *sm)
826{
827 resource_size_t mem_avail;
828 unsigned long dramctrl;
829 int ret;
830
831 mutex_init(&sm->clock_lock);
832 spin_lock_init(&sm->reg_lock);
833
834 INIT_LIST_HEAD(&sm->devices);
835
836 dramctrl = readl(sm->regs + SM501_DRAM_CONTROL);
837
838 mem_avail = sm501_mem_local[(dramctrl >> 13) & 0x7];
839
840 dev_info(sm->dev, "SM501 At %p: Version %08x, %ld Mb, IRQ %d\n",
841 sm->regs, readl(sm->regs + SM501_DEVICEID),
842 (unsigned long)mem_avail >> 20, sm->irq);
843
844 dev_info(sm->dev, "CurrentGate %08x\n", readl(sm->regs+0x38));
845 dev_info(sm->dev, "CurrentClock %08x\n", readl(sm->regs+0x3c));
846 dev_info(sm->dev, "PowerModeControl %08x\n", readl(sm->regs+0x54));
847
848 ret = device_create_file(sm->dev, &dev_attr_dbg_regs);
849 if (ret)
850 dev_err(sm->dev, "failed to create debug regs file\n");
851
852 sm501_dump_clk(sm);
853
854 /* check to see if we have some device initialisation */
855
856 if (sm->platdata) {
857 struct sm501_platdata *pdata = sm->platdata;
858
859 if (pdata->init) {
860 sm501_init_regs(sm, sm->platdata->init);
861
862 if (pdata->init->devices & SM501_USE_USB_HOST)
863 sm501_register_usbhost(sm, &mem_avail);
864 }
865 }
866
867 /* always create a framebuffer */
868 sm501_register_display(sm, &mem_avail);
869
870 return 0;
871}
872
873static int sm501_plat_probe(struct platform_device *dev)
874{
875 struct sm501_devdata *sm;
876 int err;
877
878 sm = kzalloc(sizeof(struct sm501_devdata), GFP_KERNEL);
879 if (sm == NULL) {
880 dev_err(&dev->dev, "no memory for device data\n");
881 err = -ENOMEM;
882 goto err1;
883 }
884
885 sm->dev = &dev->dev;
886 sm->pdev_id = dev->id;
887 sm->irq = platform_get_irq(dev, 0);
888 sm->io_res = platform_get_resource(dev, IORESOURCE_MEM, 1);
889 sm->mem_res = platform_get_resource(dev, IORESOURCE_MEM, 0);
890 sm->platdata = dev->dev.platform_data;
891
892 if (sm->irq < 0) {
893 dev_err(&dev->dev, "failed to get irq resource\n");
894 err = sm->irq;
895 goto err_res;
896 }
897
898 if (sm->io_res == NULL || sm->mem_res == NULL) {
899 dev_err(&dev->dev, "failed to get IO resource\n");
900 err = -ENOENT;
901 goto err_res;
902 }
903
904 sm->regs_claim = request_mem_region(sm->io_res->start,
905 0x100, "sm501");
906
907 if (sm->regs_claim == NULL) {
908 dev_err(&dev->dev, "cannot claim registers\n");
909 err= -EBUSY;
910 goto err_res;
911 }
912
913 platform_set_drvdata(dev, sm);
914
915 sm->regs = ioremap(sm->io_res->start,
916 (sm->io_res->end - sm->io_res->start) - 1);
917
918 if (sm->regs == NULL) {
919 dev_err(&dev->dev, "cannot remap registers\n");
920 err = -EIO;
921 goto err_claim;
922 }
923
924 return sm501_init_dev(sm);
925
926 err_claim:
927 release_resource(sm->regs_claim);
928 kfree(sm->regs_claim);
929 err_res:
930 kfree(sm);
931 err1:
932 return err;
933
934}
935
936/* Initialisation data for PCI devices */
937
938static struct sm501_initdata sm501_pci_initdata = {
939 .gpio_high = {
940 .set = 0x3F000000, /* 24bit panel */
941 .mask = 0x0,
942 },
943 .misc_timing = {
944 .set = 0x010100, /* SDRAM timing */
945 .mask = 0x1F1F00,
946 },
947 .misc_control = {
948 .set = SM501_MISC_PNL_24BIT,
949 .mask = 0,
950 },
951
952 .devices = SM501_USE_ALL,
953 .mclk = 100 * MHZ,
954 .m1xclk = 160 * MHZ,
955};
956
957static struct sm501_platdata_fbsub sm501_pdata_fbsub = {
958 .flags = (SM501FB_FLAG_USE_INIT_MODE |
959 SM501FB_FLAG_USE_HWCURSOR |
960 SM501FB_FLAG_USE_HWACCEL |
961 SM501FB_FLAG_DISABLE_AT_EXIT),
962};
963
964static struct sm501_platdata_fb sm501_fb_pdata = {
965 .fb_route = SM501_FB_OWN,
966 .fb_crt = &sm501_pdata_fbsub,
967 .fb_pnl = &sm501_pdata_fbsub,
968};
969
970static struct sm501_platdata sm501_pci_platdata = {
971 .init = &sm501_pci_initdata,
972 .fb = &sm501_fb_pdata,
973};
974
975static int sm501_pci_probe(struct pci_dev *dev,
976 const struct pci_device_id *id)
977{
978 struct sm501_devdata *sm;
979 int err;
980
981 sm = kzalloc(sizeof(struct sm501_devdata), GFP_KERNEL);
982 if (sm == NULL) {
983 dev_err(&dev->dev, "no memory for device data\n");
984 err = -ENOMEM;
985 goto err1;
986 }
987
988 /* set a default set of platform data */
989 dev->dev.platform_data = sm->platdata = &sm501_pci_platdata;
990
991 /* set a hopefully unique id for our child platform devices */
992 sm->pdev_id = 32 + dev->devfn;
993
994 pci_set_drvdata(dev, sm);
995
996 err = pci_enable_device(dev);
997 if (err) {
998 dev_err(&dev->dev, "cannot enable device\n");
999 goto err2;
1000 }
1001
1002 sm->dev = &dev->dev;
1003 sm->irq = dev->irq;
1004
1005#ifdef __BIG_ENDIAN
1006 /* if the system is big-endian, we most probably have a
1007 * translation in the IO layer making the PCI bus little endian
1008 * so make the framebuffer swapped pixels */
1009
1010 sm501_fb_pdata.flags |= SM501_FBPD_SWAP_FB_ENDIAN;
1011#endif
1012
1013 /* check our resources */
1014
1015 if (!(pci_resource_flags(dev, 0) & IORESOURCE_MEM)) {
1016 dev_err(&dev->dev, "region #0 is not memory?\n");
1017 err = -EINVAL;
1018 goto err3;
1019 }
1020
1021 if (!(pci_resource_flags(dev, 1) & IORESOURCE_MEM)) {
1022 dev_err(&dev->dev, "region #1 is not memory?\n");
1023 err = -EINVAL;
1024 goto err3;
1025 }
1026
1027 /* make our resources ready for sharing */
1028
1029 sm->io_res = &dev->resource[1];
1030 sm->mem_res = &dev->resource[0];
1031
1032 sm->regs_claim = request_mem_region(sm->io_res->start,
1033 0x100, "sm501");
1034 if (sm->regs_claim == NULL) {
1035 dev_err(&dev->dev, "cannot claim registers\n");
1036 err= -EBUSY;
1037 goto err3;
1038 }
1039
1040 sm->regs = ioremap(pci_resource_start(dev, 1),
1041 pci_resource_len(dev, 1));
1042
1043 if (sm->regs == NULL) {
1044 dev_err(&dev->dev, "cannot remap registers\n");
1045 err = -EIO;
1046 goto err4;
1047 }
1048
1049 sm501_init_dev(sm);
1050 return 0;
1051
1052 err4:
1053 release_resource(sm->regs_claim);
1054 kfree(sm->regs_claim);
1055 err3:
1056 pci_disable_device(dev);
1057 err2:
1058 pci_set_drvdata(dev, NULL);
1059 kfree(sm);
1060 err1:
1061 return err;
1062}
1063
1064static void sm501_remove_sub(struct sm501_devdata *sm,
1065 struct sm501_device *smdev)
1066{
1067 list_del(&smdev->list);
1068 platform_device_unregister(&smdev->pdev);
1069}
1070
1071static void sm501_dev_remove(struct sm501_devdata *sm)
1072{
1073 struct sm501_device *smdev, *tmp;
1074
1075 list_for_each_entry_safe(smdev, tmp, &sm->devices, list)
1076 sm501_remove_sub(sm, smdev);
1077
1078 device_remove_file(sm->dev, &dev_attr_dbg_regs);
1079}
1080
1081static void sm501_pci_remove(struct pci_dev *dev)
1082{
1083 struct sm501_devdata *sm = pci_get_drvdata(dev);
1084
1085 sm501_dev_remove(sm);
1086 iounmap(sm->regs);
1087
1088 release_resource(sm->regs_claim);
1089 kfree(sm->regs_claim);
1090
1091 pci_set_drvdata(dev, NULL);
1092 pci_disable_device(dev);
1093}
1094
1095static int sm501_plat_remove(struct platform_device *dev)
1096{
1097 struct sm501_devdata *sm = platform_get_drvdata(dev);
1098
1099 sm501_dev_remove(sm);
1100 iounmap(sm->regs);
1101
1102 release_resource(sm->regs_claim);
1103 kfree(sm->regs_claim);
1104
1105 return 0;
1106}
1107
1108static struct pci_device_id sm501_pci_tbl[] = {
1109 { 0x126f, 0x0501, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1110 { 0, },
1111};
1112
1113MODULE_DEVICE_TABLE(pci, sm501_pci_tbl);
1114
1115static struct pci_driver sm501_pci_drv = {
1116 .name = "sm501",
1117 .id_table = sm501_pci_tbl,
1118 .probe = sm501_pci_probe,
1119 .remove = sm501_pci_remove,
1120};
1121
1122static struct platform_driver sm501_plat_drv = {
1123 .driver = {
1124 .name = "sm501",
1125 .owner = THIS_MODULE,
1126 },
1127 .probe = sm501_plat_probe,
1128 .remove = sm501_plat_remove,
1129};
1130
1131static int __init sm501_base_init(void)
1132{
1133 platform_driver_register(&sm501_plat_drv);
1134 return pci_register_driver(&sm501_pci_drv);
1135}
1136
1137static void __exit sm501_base_exit(void)
1138{
1139 platform_driver_unregister(&sm501_plat_drv);
1140 pci_unregister_driver(&sm501_pci_drv);
1141}
1142
1143module_init(sm501_base_init);
1144module_exit(sm501_base_exit);
1145
1146MODULE_DESCRIPTION("SM501 Core Driver");
1147MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>, Vincent Sanders");
1148MODULE_LICENSE("GPL v2");
diff --git a/drivers/misc/asus-laptop.c b/drivers/misc/asus-laptop.c
index e4e2b707a3..295e931c0d 100644
--- a/drivers/misc/asus-laptop.c
+++ b/drivers/misc/asus-laptop.c
@@ -195,11 +195,9 @@ static struct backlight_device *asus_backlight_device;
195 */ 195 */
196static int read_brightness(struct backlight_device *bd); 196static int read_brightness(struct backlight_device *bd);
197static int update_bl_status(struct backlight_device *bd); 197static int update_bl_status(struct backlight_device *bd);
198static struct backlight_properties asusbl_data = { 198static struct backlight_ops asusbl_ops = {
199 .owner = THIS_MODULE,
200 .get_brightness = read_brightness, 199 .get_brightness = read_brightness,
201 .update_status = update_bl_status, 200 .update_status = update_bl_status,
202 .max_brightness = 15,
203}; 201};
204 202
205/* These functions actually update the LED's, and are called from a 203/* These functions actually update the LED's, and are called from a
@@ -349,13 +347,8 @@ static void lcd_blank(int blank)
349 struct backlight_device *bd = asus_backlight_device; 347 struct backlight_device *bd = asus_backlight_device;
350 348
351 if (bd) { 349 if (bd) {
352 down(&bd->sem); 350 bd->props.power = blank;
353 if (likely(bd->props)) { 351 backlight_update_status(bd);
354 bd->props->power = blank;
355 if (likely(bd->props->update_status))
356 bd->props->update_status(bd);
357 }
358 up(&bd->sem);
359 } 352 }
360} 353}
361 354
@@ -387,13 +380,13 @@ static int set_brightness(struct backlight_device *bd, int value)
387static int update_bl_status(struct backlight_device *bd) 380static int update_bl_status(struct backlight_device *bd)
388{ 381{
389 int rv; 382 int rv;
390 int value = bd->props->brightness; 383 int value = bd->props.brightness;
391 384
392 rv = set_brightness(bd, value); 385 rv = set_brightness(bd, value);
393 if (rv) 386 if (rv)
394 return rv; 387 return rv;
395 388
396 value = (bd->props->power == FB_BLANK_UNBLANK) ? 1 : 0; 389 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0;
397 return set_lcd_state(value); 390 return set_lcd_state(value);
398} 391}
399 392
@@ -1019,7 +1012,7 @@ static int asus_backlight_init(struct device *dev)
1019 1012
1020 if (brightness_set_handle && lcd_switch_handle) { 1013 if (brightness_set_handle && lcd_switch_handle) {
1021 bd = backlight_device_register(ASUS_HOTK_FILE, dev, 1014 bd = backlight_device_register(ASUS_HOTK_FILE, dev,
1022 NULL, &asusbl_data); 1015 NULL, &asusbl_ops);
1023 if (IS_ERR(bd)) { 1016 if (IS_ERR(bd)) {
1024 printk(ASUS_ERR 1017 printk(ASUS_ERR
1025 "Could not register asus backlight device\n"); 1018 "Could not register asus backlight device\n");
@@ -1029,14 +1022,10 @@ static int asus_backlight_init(struct device *dev)
1029 1022
1030 asus_backlight_device = bd; 1023 asus_backlight_device = bd;
1031 1024
1032 down(&bd->sem); 1025 bd->props.max_brightness = 15;
1033 if (likely(bd->props)) { 1026 bd->props.brightness = read_brightness(NULL);
1034 bd->props->brightness = read_brightness(NULL); 1027 bd->props.power = FB_BLANK_UNBLANK;
1035 bd->props->power = FB_BLANK_UNBLANK; 1028 backlight_update_status(bd);
1036 if (likely(bd->props->update_status))
1037 bd->props->update_status(bd);
1038 }
1039 up(&bd->sem);
1040 } 1029 }
1041 return 0; 1030 return 0;
1042} 1031}
diff --git a/drivers/misc/msi-laptop.c b/drivers/misc/msi-laptop.c
index 8e5e07e4c1..68c4b58525 100644
--- a/drivers/misc/msi-laptop.c
+++ b/drivers/misc/msi-laptop.c
@@ -157,14 +157,12 @@ static int bl_get_brightness(struct backlight_device *b)
157 157
158static int bl_update_status(struct backlight_device *b) 158static int bl_update_status(struct backlight_device *b)
159{ 159{
160 return set_lcd_level(b->props->brightness); 160 return set_lcd_level(b->props.brightness);
161} 161}
162 162
163static struct backlight_properties msibl_props = { 163static struct backlight_ops msibl_ops = {
164 .owner = THIS_MODULE,
165 .get_brightness = bl_get_brightness, 164 .get_brightness = bl_get_brightness,
166 .update_status = bl_update_status, 165 .update_status = bl_update_status,
167 .max_brightness = MSI_LCD_LEVEL_MAX-1,
168}; 166};
169 167
170static struct backlight_device *msibl_device; 168static struct backlight_device *msibl_device;
@@ -318,10 +316,12 @@ static int __init msi_init(void)
318 /* Register backlight stuff */ 316 /* Register backlight stuff */
319 317
320 msibl_device = backlight_device_register("msi-laptop-bl", NULL, NULL, 318 msibl_device = backlight_device_register("msi-laptop-bl", NULL, NULL,
321 &msibl_props); 319 &msibl_ops);
322 if (IS_ERR(msibl_device)) 320 if (IS_ERR(msibl_device))
323 return PTR_ERR(msibl_device); 321 return PTR_ERR(msibl_device);
324 322
323 msibl_device->props.max_brightness = MSI_LCD_LEVEL_MAX-1,
324
325 ret = platform_driver_register(&msipf_driver); 325 ret = platform_driver_register(&msipf_driver);
326 if (ret) 326 if (ret)
327 goto fail_backlight; 327 goto fail_backlight;
diff --git a/drivers/misc/sony-laptop.c b/drivers/misc/sony-laptop.c
index cabbed0015..2ebe240dd5 100644
--- a/drivers/misc/sony-laptop.c
+++ b/drivers/misc/sony-laptop.c
@@ -384,7 +384,7 @@ static void sony_snc_pf_remove(void)
384static int sony_backlight_update_status(struct backlight_device *bd) 384static int sony_backlight_update_status(struct backlight_device *bd)
385{ 385{
386 return acpi_callsetfunc(sony_acpi_handle, "SBRT", 386 return acpi_callsetfunc(sony_acpi_handle, "SBRT",
387 bd->props->brightness + 1, NULL); 387 bd->props.brightness + 1, NULL);
388} 388}
389 389
390static int sony_backlight_get_brightness(struct backlight_device *bd) 390static int sony_backlight_get_brightness(struct backlight_device *bd)
@@ -398,11 +398,9 @@ static int sony_backlight_get_brightness(struct backlight_device *bd)
398} 398}
399 399
400static struct backlight_device *sony_backlight_device; 400static struct backlight_device *sony_backlight_device;
401static struct backlight_properties sony_backlight_properties = { 401static struct backlight_ops sony_backlight_ops = {
402 .owner = THIS_MODULE,
403 .update_status = sony_backlight_update_status, 402 .update_status = sony_backlight_update_status,
404 .get_brightness = sony_backlight_get_brightness, 403 .get_brightness = sony_backlight_get_brightness,
405 .max_brightness = SONY_MAX_BRIGHTNESS - 1,
406}; 404};
407 405
408/* 406/*
@@ -484,15 +482,19 @@ static int sony_acpi_add(struct acpi_device *device)
484 if (ACPI_SUCCESS(acpi_get_handle(sony_acpi_handle, "GBRT", &handle))) { 482 if (ACPI_SUCCESS(acpi_get_handle(sony_acpi_handle, "GBRT", &handle))) {
485 sony_backlight_device = backlight_device_register("sony", NULL, 483 sony_backlight_device = backlight_device_register("sony", NULL,
486 NULL, 484 NULL,
487 &sony_backlight_properties); 485 &sony_backlight_ops);
488 486
489 if (IS_ERR(sony_backlight_device)) { 487 if (IS_ERR(sony_backlight_device)) {
490 printk(LOG_PFX "unable to register backlight device\n"); 488 printk(LOG_PFX "unable to register backlight device\n");
491 sony_backlight_device = NULL; 489 sony_backlight_device = NULL;
492 } else 490 } else {
493 sony_backlight_properties.brightness = 491 sony_backlight_device->props.brightness =
494 sony_backlight_get_brightness 492 sony_backlight_get_brightness
495 (sony_backlight_device); 493 (sony_backlight_device);
494 sony_backlight_device->props.max_brightness =
495 SONY_MAX_BRIGHTNESS - 1;
496 }
497
496 } 498 }
497 499
498 if (sony_snc_pf_add()) 500 if (sony_snc_pf_add())
diff --git a/drivers/mmc/at91_mci.c b/drivers/mmc/at91_mci.c
index 2ce50f38e3..459f4b4fed 100644
--- a/drivers/mmc/at91_mci.c
+++ b/drivers/mmc/at91_mci.c
@@ -64,6 +64,7 @@
64#include <linux/err.h> 64#include <linux/err.h>
65#include <linux/dma-mapping.h> 65#include <linux/dma-mapping.h>
66#include <linux/clk.h> 66#include <linux/clk.h>
67#include <linux/atmel_pdc.h>
67 68
68#include <linux/mmc/host.h> 69#include <linux/mmc/host.h>
69#include <linux/mmc/protocol.h> 70#include <linux/mmc/protocol.h>
@@ -75,7 +76,6 @@
75#include <asm/arch/cpu.h> 76#include <asm/arch/cpu.h>
76#include <asm/arch/gpio.h> 77#include <asm/arch/gpio.h>
77#include <asm/arch/at91_mci.h> 78#include <asm/arch/at91_mci.h>
78#include <asm/arch/at91_pdc.h>
79 79
80#define DRIVER_NAME "at91_mci" 80#define DRIVER_NAME "at91_mci"
81 81
@@ -211,13 +211,13 @@ static void at91mci_pre_dma_read(struct at91mci_host *host)
211 211
212 /* Check to see if this needs filling */ 212 /* Check to see if this needs filling */
213 if (i == 0) { 213 if (i == 0) {
214 if (at91_mci_read(host, AT91_PDC_RCR) != 0) { 214 if (at91_mci_read(host, ATMEL_PDC_RCR) != 0) {
215 pr_debug("Transfer active in current\n"); 215 pr_debug("Transfer active in current\n");
216 continue; 216 continue;
217 } 217 }
218 } 218 }
219 else { 219 else {
220 if (at91_mci_read(host, AT91_PDC_RNCR) != 0) { 220 if (at91_mci_read(host, ATMEL_PDC_RNCR) != 0) {
221 pr_debug("Transfer active in next\n"); 221 pr_debug("Transfer active in next\n");
222 continue; 222 continue;
223 } 223 }
@@ -234,12 +234,12 @@ static void at91mci_pre_dma_read(struct at91mci_host *host)
234 pr_debug("dma address = %08X, length = %d\n", sg->dma_address, sg->length); 234 pr_debug("dma address = %08X, length = %d\n", sg->dma_address, sg->length);
235 235
236 if (i == 0) { 236 if (i == 0) {
237 at91_mci_write(host, AT91_PDC_RPR, sg->dma_address); 237 at91_mci_write(host, ATMEL_PDC_RPR, sg->dma_address);
238 at91_mci_write(host, AT91_PDC_RCR, sg->length / 4); 238 at91_mci_write(host, ATMEL_PDC_RCR, sg->length / 4);
239 } 239 }
240 else { 240 else {
241 at91_mci_write(host, AT91_PDC_RNPR, sg->dma_address); 241 at91_mci_write(host, ATMEL_PDC_RNPR, sg->dma_address);
242 at91_mci_write(host, AT91_PDC_RNCR, sg->length / 4); 242 at91_mci_write(host, ATMEL_PDC_RNCR, sg->length / 4);
243 } 243 }
244 } 244 }
245 245
@@ -303,7 +303,7 @@ static void at91mci_post_dma_read(struct at91mci_host *host)
303 at91mci_pre_dma_read(host); 303 at91mci_pre_dma_read(host);
304 else { 304 else {
305 at91_mci_write(host, AT91_MCI_IER, AT91_MCI_RXBUFF); 305 at91_mci_write(host, AT91_MCI_IER, AT91_MCI_RXBUFF);
306 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS); 306 at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
307 } 307 }
308 308
309 pr_debug("post dma read done\n"); 309 pr_debug("post dma read done\n");
@@ -320,7 +320,7 @@ static void at91_mci_handle_transmitted(struct at91mci_host *host)
320 pr_debug("Handling the transmit\n"); 320 pr_debug("Handling the transmit\n");
321 321
322 /* Disable the transfer */ 322 /* Disable the transfer */
323 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS); 323 at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
324 324
325 /* Now wait for cmd ready */ 325 /* Now wait for cmd ready */
326 at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_TXBUFE); 326 at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_TXBUFE);
@@ -431,15 +431,15 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
431 cmd->opcode, cmdr, cmd->arg, blocks, block_length, at91_mci_read(host, AT91_MCI_MR)); 431 cmd->opcode, cmdr, cmd->arg, blocks, block_length, at91_mci_read(host, AT91_MCI_MR));
432 432
433 if (!data) { 433 if (!data) {
434 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_TXTDIS | AT91_PDC_RXTDIS); 434 at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTDIS | ATMEL_PDC_RXTDIS);
435 at91_mci_write(host, AT91_PDC_RPR, 0); 435 at91_mci_write(host, ATMEL_PDC_RPR, 0);
436 at91_mci_write(host, AT91_PDC_RCR, 0); 436 at91_mci_write(host, ATMEL_PDC_RCR, 0);
437 at91_mci_write(host, AT91_PDC_RNPR, 0); 437 at91_mci_write(host, ATMEL_PDC_RNPR, 0);
438 at91_mci_write(host, AT91_PDC_RNCR, 0); 438 at91_mci_write(host, ATMEL_PDC_RNCR, 0);
439 at91_mci_write(host, AT91_PDC_TPR, 0); 439 at91_mci_write(host, ATMEL_PDC_TPR, 0);
440 at91_mci_write(host, AT91_PDC_TCR, 0); 440 at91_mci_write(host, ATMEL_PDC_TCR, 0);
441 at91_mci_write(host, AT91_PDC_TNPR, 0); 441 at91_mci_write(host, ATMEL_PDC_TNPR, 0);
442 at91_mci_write(host, AT91_PDC_TNCR, 0); 442 at91_mci_write(host, ATMEL_PDC_TNCR, 0);
443 443
444 at91_mci_write(host, AT91_MCI_ARGR, cmd->arg); 444 at91_mci_write(host, AT91_MCI_ARGR, cmd->arg);
445 at91_mci_write(host, AT91_MCI_CMDR, cmdr); 445 at91_mci_write(host, AT91_MCI_CMDR, cmdr);
@@ -452,7 +452,7 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
452 /* 452 /*
453 * Disable the PDC controller 453 * Disable the PDC controller
454 */ 454 */
455 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS); 455 at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
456 456
457 if (cmdr & AT91_MCI_TRCMD_START) { 457 if (cmdr & AT91_MCI_TRCMD_START) {
458 data->bytes_xfered = 0; 458 data->bytes_xfered = 0;
@@ -481,8 +481,8 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
481 481
482 pr_debug("Transmitting %d bytes\n", host->total_length); 482 pr_debug("Transmitting %d bytes\n", host->total_length);
483 483
484 at91_mci_write(host, AT91_PDC_TPR, host->physical_address); 484 at91_mci_write(host, ATMEL_PDC_TPR, host->physical_address);
485 at91_mci_write(host, AT91_PDC_TCR, host->total_length / 4); 485 at91_mci_write(host, ATMEL_PDC_TCR, host->total_length / 4);
486 ier = AT91_MCI_TXBUFE; 486 ier = AT91_MCI_TXBUFE;
487 } 487 }
488 } 488 }
@@ -497,9 +497,9 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
497 497
498 if (cmdr & AT91_MCI_TRCMD_START) { 498 if (cmdr & AT91_MCI_TRCMD_START) {
499 if (cmdr & AT91_MCI_TRDIR) 499 if (cmdr & AT91_MCI_TRDIR)
500 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_RXTEN); 500 at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTEN);
501 else 501 else
502 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_TXTEN); 502 at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTEN);
503 } 503 }
504 return ier; 504 return ier;
505} 505}
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 5046a16613..4a73e8b242 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -376,10 +376,11 @@ static inline void mmc_set_ios(struct mmc_host *host)
376{ 376{
377 struct mmc_ios *ios = &host->ios; 377 struct mmc_ios *ios = &host->ios;
378 378
379 pr_debug("%s: clock %uHz busmode %u powermode %u cs %u Vdd %u width %u\n", 379 pr_debug("%s: clock %uHz busmode %u powermode %u cs %u Vdd %u "
380 "width %u timing %u\n",
380 mmc_hostname(host), ios->clock, ios->bus_mode, 381 mmc_hostname(host), ios->clock, ios->bus_mode,
381 ios->power_mode, ios->chip_select, ios->vdd, 382 ios->power_mode, ios->chip_select, ios->vdd,
382 ios->bus_width); 383 ios->bus_width, ios->timing);
383 384
384 host->ops->set_ios(host, ios); 385 host->ops->set_ios(host, ios);
385} 386}
@@ -809,6 +810,7 @@ static void mmc_power_up(struct mmc_host *host)
809 host->ios.chip_select = MMC_CS_DONTCARE; 810 host->ios.chip_select = MMC_CS_DONTCARE;
810 host->ios.power_mode = MMC_POWER_UP; 811 host->ios.power_mode = MMC_POWER_UP;
811 host->ios.bus_width = MMC_BUS_WIDTH_1; 812 host->ios.bus_width = MMC_BUS_WIDTH_1;
813 host->ios.timing = MMC_TIMING_LEGACY;
812 mmc_set_ios(host); 814 mmc_set_ios(host);
813 815
814 mmc_delay(1); 816 mmc_delay(1);
@@ -828,6 +830,7 @@ static void mmc_power_off(struct mmc_host *host)
828 host->ios.chip_select = MMC_CS_DONTCARE; 830 host->ios.chip_select = MMC_CS_DONTCARE;
829 host->ios.power_mode = MMC_POWER_OFF; 831 host->ios.power_mode = MMC_POWER_OFF;
830 host->ios.bus_width = MMC_BUS_WIDTH_1; 832 host->ios.bus_width = MMC_BUS_WIDTH_1;
833 host->ios.timing = MMC_TIMING_LEGACY;
831 mmc_set_ios(host); 834 mmc_set_ios(host);
832} 835}
833 836
@@ -1112,46 +1115,50 @@ static void mmc_process_ext_csds(struct mmc_host *host)
1112 continue; 1115 continue;
1113 } 1116 }
1114 1117
1115 /* Activate highspeed support. */ 1118 if (host->caps & MMC_CAP_MMC_HIGHSPEED) {
1116 cmd.opcode = MMC_SWITCH; 1119 /* Activate highspeed support. */
1117 cmd.arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | 1120 cmd.opcode = MMC_SWITCH;
1118 (EXT_CSD_HS_TIMING << 16) | 1121 cmd.arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) |
1119 (1 << 8) | 1122 (EXT_CSD_HS_TIMING << 16) |
1120 EXT_CSD_CMD_SET_NORMAL; 1123 (1 << 8) |
1121 cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; 1124 EXT_CSD_CMD_SET_NORMAL;
1125 cmd.flags = MMC_RSP_R1B | MMC_CMD_AC;
1122 1126
1123 err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES); 1127 err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES);
1124 if (err != MMC_ERR_NONE) { 1128 if (err != MMC_ERR_NONE) {
1125 printk("%s: failed to switch card to mmc v4 " 1129 printk("%s: failed to switch card to mmc v4 "
1126 "high-speed mode.\n", 1130 "high-speed mode.\n",
1127 mmc_hostname(card->host)); 1131 mmc_hostname(card->host));
1128 continue; 1132 continue;
1129 } 1133 }
1130 1134
1131 mmc_card_set_highspeed(card); 1135 mmc_card_set_highspeed(card);
1132 1136
1133 /* Check for host support for wide-bus modes. */ 1137 host->ios.timing = MMC_TIMING_SD_HS;
1134 if (!(host->caps & MMC_CAP_4_BIT_DATA)) { 1138 mmc_set_ios(host);
1135 continue;
1136 } 1139 }
1137 1140
1138 /* Activate 4-bit support. */ 1141 /* Check for host support for wide-bus modes. */
1139 cmd.opcode = MMC_SWITCH; 1142 if (host->caps & MMC_CAP_4_BIT_DATA) {
1140 cmd.arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | 1143 /* Activate 4-bit support. */
1141 (EXT_CSD_BUS_WIDTH << 16) | 1144 cmd.opcode = MMC_SWITCH;
1142 (EXT_CSD_BUS_WIDTH_4 << 8) | 1145 cmd.arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) |
1143 EXT_CSD_CMD_SET_NORMAL; 1146 (EXT_CSD_BUS_WIDTH << 16) |
1144 cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; 1147 (EXT_CSD_BUS_WIDTH_4 << 8) |
1148 EXT_CSD_CMD_SET_NORMAL;
1149 cmd.flags = MMC_RSP_R1B | MMC_CMD_AC;
1145 1150
1146 err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES); 1151 err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES);
1147 if (err != MMC_ERR_NONE) { 1152 if (err != MMC_ERR_NONE) {
1148 printk("%s: failed to switch card to " 1153 printk("%s: failed to switch card to "
1149 "mmc v4 4-bit bus mode.\n", 1154 "mmc v4 4-bit bus mode.\n",
1150 mmc_hostname(card->host)); 1155 mmc_hostname(card->host));
1151 continue; 1156 continue;
1152 } 1157 }
1153 1158
1154 host->ios.bus_width = MMC_BUS_WIDTH_4; 1159 host->ios.bus_width = MMC_BUS_WIDTH_4;
1160 mmc_set_ios(host);
1161 }
1155 } 1162 }
1156 1163
1157 kfree(ext_csd); 1164 kfree(ext_csd);
@@ -1241,6 +1248,9 @@ static void mmc_read_switch_caps(struct mmc_host *host)
1241 unsigned char *status; 1248 unsigned char *status;
1242 struct scatterlist sg; 1249 struct scatterlist sg;
1243 1250
1251 if (!(host->caps & MMC_CAP_SD_HIGHSPEED))
1252 return;
1253
1244 status = kmalloc(64, GFP_KERNEL); 1254 status = kmalloc(64, GFP_KERNEL);
1245 if (!status) { 1255 if (!status) {
1246 printk(KERN_WARNING "%s: Unable to allocate buffer for " 1256 printk(KERN_WARNING "%s: Unable to allocate buffer for "
@@ -1332,6 +1342,9 @@ static void mmc_read_switch_caps(struct mmc_host *host)
1332 } 1342 }
1333 1343
1334 mmc_card_set_highspeed(card); 1344 mmc_card_set_highspeed(card);
1345
1346 host->ios.timing = MMC_TIMING_SD_HS;
1347 mmc_set_ios(host);
1335 } 1348 }
1336 1349
1337 kfree(status); 1350 kfree(status);
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
index 7522f76b15..d749f08601 100644
--- a/drivers/mmc/sdhci.c
+++ b/drivers/mmc/sdhci.c
@@ -606,7 +606,6 @@ static void sdhci_finish_command(struct sdhci_host *host)
606static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock) 606static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
607{ 607{
608 int div; 608 int div;
609 u8 ctrl;
610 u16 clk; 609 u16 clk;
611 unsigned long timeout; 610 unsigned long timeout;
612 611
@@ -615,13 +614,6 @@ static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
615 614
616 writew(0, host->ioaddr + SDHCI_CLOCK_CONTROL); 615 writew(0, host->ioaddr + SDHCI_CLOCK_CONTROL);
617 616
618 ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL);
619 if (clock > 25000000)
620 ctrl |= SDHCI_CTRL_HISPD;
621 else
622 ctrl &= ~SDHCI_CTRL_HISPD;
623 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
624
625 if (clock == 0) 617 if (clock == 0)
626 goto out; 618 goto out;
627 619
@@ -761,10 +753,17 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
761 sdhci_set_power(host, ios->vdd); 753 sdhci_set_power(host, ios->vdd);
762 754
763 ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL); 755 ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL);
756
764 if (ios->bus_width == MMC_BUS_WIDTH_4) 757 if (ios->bus_width == MMC_BUS_WIDTH_4)
765 ctrl |= SDHCI_CTRL_4BITBUS; 758 ctrl |= SDHCI_CTRL_4BITBUS;
766 else 759 else
767 ctrl &= ~SDHCI_CTRL_4BITBUS; 760 ctrl &= ~SDHCI_CTRL_4BITBUS;
761
762 if (ios->timing == MMC_TIMING_SD_HS)
763 ctrl |= SDHCI_CTRL_HISPD;
764 else
765 ctrl &= ~SDHCI_CTRL_HISPD;
766
768 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL); 767 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
769 768
770 mmiowb(); 769 mmiowb();
@@ -994,7 +993,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
994 993
995 intmask = readl(host->ioaddr + SDHCI_INT_STATUS); 994 intmask = readl(host->ioaddr + SDHCI_INT_STATUS);
996 995
997 if (!intmask) { 996 if (!intmask || intmask == 0xffffffff) {
998 result = IRQ_NONE; 997 result = IRQ_NONE;
999 goto out; 998 goto out;
1000 } 999 }
@@ -1080,6 +1079,13 @@ static int sdhci_suspend (struct pci_dev *pdev, pm_message_t state)
1080 1079
1081 pci_save_state(pdev); 1080 pci_save_state(pdev);
1082 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0); 1081 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
1082
1083 for (i = 0;i < chip->num_slots;i++) {
1084 if (!chip->hosts[i])
1085 continue;
1086 free_irq(chip->hosts[i]->irq, chip->hosts[i]);
1087 }
1088
1083 pci_disable_device(pdev); 1089 pci_disable_device(pdev);
1084 pci_set_power_state(pdev, pci_choose_state(pdev, state)); 1090 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1085 1091
@@ -1108,6 +1114,11 @@ static int sdhci_resume (struct pci_dev *pdev)
1108 continue; 1114 continue;
1109 if (chip->hosts[i]->flags & SDHCI_USE_DMA) 1115 if (chip->hosts[i]->flags & SDHCI_USE_DMA)
1110 pci_set_master(pdev); 1116 pci_set_master(pdev);
1117 ret = request_irq(chip->hosts[i]->irq, sdhci_irq,
1118 IRQF_SHARED, chip->hosts[i]->slot_descr,
1119 chip->hosts[i]);
1120 if (ret)
1121 return ret;
1111 sdhci_init(chip->hosts[i]); 1122 sdhci_init(chip->hosts[i]);
1112 mmiowb(); 1123 mmiowb();
1113 ret = mmc_resume_host(chip->hosts[i]->mmc); 1124 ret = mmc_resume_host(chip->hosts[i]->mmc);
@@ -1274,6 +1285,9 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot)
1274 mmc->f_max = host->max_clk; 1285 mmc->f_max = host->max_clk;
1275 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE | MMC_CAP_BYTEBLOCK; 1286 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE | MMC_CAP_BYTEBLOCK;
1276 1287
1288 if (caps & SDHCI_CAN_DO_HISPD)
1289 mmc->caps |= MMC_CAP_SD_HIGHSPEED;
1290
1277 mmc->ocr_avail = 0; 1291 mmc->ocr_avail = 0;
1278 if (caps & SDHCI_CAN_VDD_330) 1292 if (caps & SDHCI_CAN_VDD_330)
1279 mmc->ocr_avail |= MMC_VDD_32_33|MMC_VDD_33_34; 1293 mmc->ocr_avail |= MMC_VDD_32_33|MMC_VDD_33_34;
@@ -1282,13 +1296,6 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot)
1282 if (caps & SDHCI_CAN_VDD_180) 1296 if (caps & SDHCI_CAN_VDD_180)
1283 mmc->ocr_avail |= MMC_VDD_17_18|MMC_VDD_18_19; 1297 mmc->ocr_avail |= MMC_VDD_17_18|MMC_VDD_18_19;
1284 1298
1285 if ((host->max_clk > 25000000) && !(caps & SDHCI_CAN_DO_HISPD)) {
1286 printk(KERN_ERR "%s: Controller reports > 25 MHz base clock,"
1287 " but no high speed support.\n",
1288 host->slot_descr);
1289 mmc->f_max = 25000000;
1290 }
1291
1292 if (mmc->ocr_avail == 0) { 1299 if (mmc->ocr_avail == 0) {
1293 printk(KERN_ERR "%s: Hardware doesn't report any " 1300 printk(KERN_ERR "%s: Hardware doesn't report any "
1294 "support voltages.\n", host->slot_descr); 1301 "support voltages.\n", host->slot_descr);
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index f69184a92e..f334959a33 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -397,9 +397,23 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
397 cfi_fixup(mtd, fixup_table); 397 cfi_fixup(mtd, fixup_table);
398 398
399 for (i=0; i< cfi->numchips; i++) { 399 for (i=0; i< cfi->numchips; i++) {
400 cfi->chips[i].word_write_time = 1<<cfi->cfiq->WordWriteTimeoutTyp; 400 if (cfi->cfiq->WordWriteTimeoutTyp)
401 cfi->chips[i].buffer_write_time = 1<<cfi->cfiq->BufWriteTimeoutTyp; 401 cfi->chips[i].word_write_time =
402 cfi->chips[i].erase_time = 1000<<cfi->cfiq->BlockEraseTimeoutTyp; 402 1<<cfi->cfiq->WordWriteTimeoutTyp;
403 else
404 cfi->chips[i].word_write_time = 50000;
405
406 if (cfi->cfiq->BufWriteTimeoutTyp)
407 cfi->chips[i].buffer_write_time =
408 1<<cfi->cfiq->BufWriteTimeoutTyp;
409 /* No default; if it isn't specified, we won't use it */
410
411 if (cfi->cfiq->BlockEraseTimeoutTyp)
412 cfi->chips[i].erase_time =
413 1000<<cfi->cfiq->BlockEraseTimeoutTyp;
414 else
415 cfi->chips[i].erase_time = 2000000;
416
403 cfi->chips[i].ref_point_counter = 0; 417 cfi->chips[i].ref_point_counter = 0;
404 init_waitqueue_head(&(cfi->chips[i].wq)); 418 init_waitqueue_head(&(cfi->chips[i].wq));
405 } 419 }
@@ -546,13 +560,11 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
546 struct cfi_intelext_programming_regioninfo *prinfo; 560 struct cfi_intelext_programming_regioninfo *prinfo;
547 prinfo = (struct cfi_intelext_programming_regioninfo *)&extp->extra[offs]; 561 prinfo = (struct cfi_intelext_programming_regioninfo *)&extp->extra[offs];
548 mtd->writesize = cfi->interleave << prinfo->ProgRegShift; 562 mtd->writesize = cfi->interleave << prinfo->ProgRegShift;
549 MTD_PROGREGION_CTRLMODE_VALID(mtd) = cfi->interleave * prinfo->ControlValid;
550 MTD_PROGREGION_CTRLMODE_INVALID(mtd) = cfi->interleave * prinfo->ControlInvalid;
551 mtd->flags &= ~MTD_BIT_WRITEABLE; 563 mtd->flags &= ~MTD_BIT_WRITEABLE;
552 printk(KERN_DEBUG "%s: program region size/ctrl_valid/ctrl_inval = %d/%d/%d\n", 564 printk(KERN_DEBUG "%s: program region size/ctrl_valid/ctrl_inval = %d/%d/%d\n",
553 map->name, mtd->writesize, 565 map->name, mtd->writesize,
554 MTD_PROGREGION_CTRLMODE_VALID(mtd), 566 cfi->interleave * prinfo->ControlValid,
555 MTD_PROGREGION_CTRLMODE_INVALID(mtd)); 567 cfi->interleave * prinfo->ControlInvalid);
556 } 568 }
557 569
558 /* 570 /*
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index e3acd398fb..1f64458404 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -359,6 +359,8 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary)
359 cfi->chips[i].word_write_time = 1<<cfi->cfiq->WordWriteTimeoutTyp; 359 cfi->chips[i].word_write_time = 1<<cfi->cfiq->WordWriteTimeoutTyp;
360 cfi->chips[i].buffer_write_time = 1<<cfi->cfiq->BufWriteTimeoutTyp; 360 cfi->chips[i].buffer_write_time = 1<<cfi->cfiq->BufWriteTimeoutTyp;
361 cfi->chips[i].erase_time = 1<<cfi->cfiq->BlockEraseTimeoutTyp; 361 cfi->chips[i].erase_time = 1<<cfi->cfiq->BlockEraseTimeoutTyp;
362 cfi->chips[i].ref_point_counter = 0;
363 init_waitqueue_head(&(cfi->chips[i].wq));
362 } 364 }
363 365
364 map->fldrv = &cfi_amdstd_chipdrv; 366 map->fldrv = &cfi_amdstd_chipdrv;
diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
index d56849f5f1..b344ff858b 100644
--- a/drivers/mtd/chips/cfi_cmdset_0020.c
+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
@@ -158,6 +158,8 @@ struct mtd_info *cfi_cmdset_0020(struct map_info *map, int primary)
158 cfi->chips[i].word_write_time = 128; 158 cfi->chips[i].word_write_time = 128;
159 cfi->chips[i].buffer_write_time = 128; 159 cfi->chips[i].buffer_write_time = 128;
160 cfi->chips[i].erase_time = 1024; 160 cfi->chips[i].erase_time = 1024;
161 cfi->chips[i].ref_point_counter = 0;
162 init_waitqueue_head(&(cfi->chips[i].wq));
161 } 163 }
162 164
163 return cfi_staa_setup(map); 165 return cfi_staa_setup(map);
@@ -662,7 +664,7 @@ static int cfi_staa_write_buffers (struct mtd_info *mtd, loff_t to,
662 * a small buffer for this. 664 * a small buffer for this.
663 * XXX: If the buffer size is not a multiple of 2, this will break 665 * XXX: If the buffer size is not a multiple of 2, this will break
664 */ 666 */
665#define ECCBUF_SIZE (mtd->eccsize) 667#define ECCBUF_SIZE (mtd->writesize)
666#define ECCBUF_DIV(x) ((x) & ~(ECCBUF_SIZE - 1)) 668#define ECCBUF_DIV(x) ((x) & ~(ECCBUF_SIZE - 1))
667#define ECCBUF_MOD(x) ((x) & (ECCBUF_SIZE - 1)) 669#define ECCBUF_MOD(x) ((x) & (ECCBUF_SIZE - 1))
668static int 670static int
diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
index 603a7951ac..8a0c4dec63 100644
--- a/drivers/mtd/devices/doc2000.c
+++ b/drivers/mtd/devices/doc2000.c
@@ -569,7 +569,6 @@ void DoC2k_init(struct mtd_info *mtd)
569 569
570 mtd->type = MTD_NANDFLASH; 570 mtd->type = MTD_NANDFLASH;
571 mtd->flags = MTD_CAP_NANDFLASH; 571 mtd->flags = MTD_CAP_NANDFLASH;
572 mtd->ecctype = MTD_ECC_RS_DiskOnChip;
573 mtd->size = 0; 572 mtd->size = 0;
574 mtd->erasesize = 0; 573 mtd->erasesize = 0;
575 mtd->writesize = 512; 574 mtd->writesize = 512;
diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
index fe71a12c26..6f368aec5d 100644
--- a/drivers/mtd/devices/doc2001.c
+++ b/drivers/mtd/devices/doc2001.c
@@ -348,7 +348,6 @@ void DoCMil_init(struct mtd_info *mtd)
348 348
349 mtd->type = MTD_NANDFLASH; 349 mtd->type = MTD_NANDFLASH;
350 mtd->flags = MTD_CAP_NANDFLASH; 350 mtd->flags = MTD_CAP_NANDFLASH;
351 mtd->ecctype = MTD_ECC_RS_DiskOnChip;
352 mtd->size = 0; 351 mtd->size = 0;
353 352
354 /* FIXME: erase size is not always 8KiB */ 353 /* FIXME: erase size is not always 8KiB */
diff --git a/drivers/mtd/devices/doc2001plus.c b/drivers/mtd/devices/doc2001plus.c
index ba4db68628..88ba82df0f 100644
--- a/drivers/mtd/devices/doc2001plus.c
+++ b/drivers/mtd/devices/doc2001plus.c
@@ -472,7 +472,6 @@ void DoCMilPlus_init(struct mtd_info *mtd)
472 472
473 mtd->type = MTD_NANDFLASH; 473 mtd->type = MTD_NANDFLASH;
474 mtd->flags = MTD_CAP_NANDFLASH; 474 mtd->flags = MTD_CAP_NANDFLASH;
475 mtd->ecctype = MTD_ECC_RS_DiskOnChip;
476 mtd->size = 0; 475 mtd->size = 0;
477 476
478 mtd->erasesize = 0; 477 mtd->erasesize = 0;
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index f457315579..bbf0553bdb 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -204,7 +204,7 @@ config MTD_ESB2ROM
204 204
205config MTD_CK804XROM 205config MTD_CK804XROM
206 tristate "BIOS flash chip on Nvidia CK804" 206 tristate "BIOS flash chip on Nvidia CK804"
207 depends on X86 && MTD_JEDECPROBE 207 depends on X86 && MTD_JEDECPROBE && PCI
208 help 208 help
209 Support for treating the BIOS flash chip on nvidia motherboards 209 Support for treating the BIOS flash chip on nvidia motherboards
210 as an MTD device - with this you can reprogram your BIOS. 210 as an MTD device - with this you can reprogram your BIOS.
diff --git a/drivers/mtd/maps/amd76xrom.c b/drivers/mtd/maps/amd76xrom.c
index 78b671172b..728aed6ad7 100644
--- a/drivers/mtd/maps/amd76xrom.c
+++ b/drivers/mtd/maps/amd76xrom.c
@@ -205,8 +205,8 @@ static int __devinit amd76xrom_init_one (struct pci_dev *pdev,
205 (((unsigned long)(window->virt)) + offset); 205 (((unsigned long)(window->virt)) + offset);
206 map->map.size = 0xffffffffUL - map_top + 1UL; 206 map->map.size = 0xffffffffUL - map_top + 1UL;
207 /* Set the name of the map to the address I am trying */ 207 /* Set the name of the map to the address I am trying */
208 sprintf(map->map_name, "%s @%08lx", 208 sprintf(map->map_name, "%s @%08Lx",
209 MOD_NAME, map->map.phys); 209 MOD_NAME, (unsigned long long)map->map.phys);
210 210
211 /* There is no generic VPP support */ 211 /* There is no generic VPP support */
212 for(map->map.bankwidth = 32; map->map.bankwidth; 212 for(map->map.bankwidth = 32; map->map.bankwidth;
diff --git a/drivers/mtd/maps/ck804xrom.c b/drivers/mtd/maps/ck804xrom.c
index 238d42e88e..3d4a4d8ac7 100644
--- a/drivers/mtd/maps/ck804xrom.c
+++ b/drivers/mtd/maps/ck804xrom.c
@@ -207,8 +207,8 @@ static int __devinit ck804xrom_init_one (struct pci_dev *pdev,
207 (((unsigned long)(window->virt)) + offset); 207 (((unsigned long)(window->virt)) + offset);
208 map->map.size = 0xffffffffUL - map_top + 1UL; 208 map->map.size = 0xffffffffUL - map_top + 1UL;
209 /* Set the name of the map to the address I am trying */ 209 /* Set the name of the map to the address I am trying */
210 sprintf(map->map_name, "%s @%08lx", 210 sprintf(map->map_name, "%s @%08Lx",
211 MOD_NAME, map->map.phys); 211 MOD_NAME, (unsigned long long)map->map.phys);
212 212
213 /* There is no generic VPP support */ 213 /* There is no generic VPP support */
214 for(map->map.bankwidth = 32; map->map.bankwidth; 214 for(map->map.bankwidth = 32; map->map.bankwidth;
@@ -327,7 +327,7 @@ static int __init init_ck804xrom(void)
327 pdev = NULL; 327 pdev = NULL;
328 328
329 for(id = ck804xrom_pci_tbl; id->vendor; id++) { 329 for(id = ck804xrom_pci_tbl; id->vendor; id++) {
330 pdev = pci_find_device(id->vendor, id->device, NULL); 330 pdev = pci_get_device(id->vendor, id->device, NULL);
331 if (pdev) 331 if (pdev)
332 break; 332 break;
333 } 333 }
diff --git a/drivers/mtd/maps/dilnetpc.c b/drivers/mtd/maps/dilnetpc.c
index b1104fe1f2..1c3b34ad73 100644
--- a/drivers/mtd/maps/dilnetpc.c
+++ b/drivers/mtd/maps/dilnetpc.c
@@ -402,8 +402,8 @@ static int __init init_dnpc(void)
402 ++higlvl_partition_info[i].name; 402 ++higlvl_partition_info[i].name;
403 } 403 }
404 404
405 printk(KERN_NOTICE "DIL/Net %s flash: 0x%lx at 0x%lx\n", 405 printk(KERN_NOTICE "DIL/Net %s flash: 0x%lx at 0x%llx\n",
406 is_dnp ? "DNPC" : "ADNP", dnpc_map.size, dnpc_map.phys); 406 is_dnp ? "DNPC" : "ADNP", dnpc_map.size, (unsigned long long)dnpc_map.phys);
407 407
408 dnpc_map.virt = ioremap_nocache(dnpc_map.phys, dnpc_map.size); 408 dnpc_map.virt = ioremap_nocache(dnpc_map.phys, dnpc_map.size);
409 409
diff --git a/drivers/mtd/maps/esb2rom.c b/drivers/mtd/maps/esb2rom.c
index a9d808a617..aa64a47527 100644
--- a/drivers/mtd/maps/esb2rom.c
+++ b/drivers/mtd/maps/esb2rom.c
@@ -30,7 +30,7 @@
30 30
31#define ROM_PROBE_STEP_SIZE (64*1024) /* 64KiB */ 31#define ROM_PROBE_STEP_SIZE (64*1024) /* 64KiB */
32 32
33#define BIOS_CNTL 0xDC 33#define BIOS_CNTL 0xDC
34#define BIOS_LOCK_ENABLE 0x02 34#define BIOS_LOCK_ENABLE 0x02
35#define BIOS_WRITE_ENABLE 0x01 35#define BIOS_WRITE_ENABLE 0x01
36 36
@@ -145,7 +145,7 @@ static void esb2rom_cleanup(struct esb2rom_window *window)
145} 145}
146 146
147static int __devinit esb2rom_init_one(struct pci_dev *pdev, 147static int __devinit esb2rom_init_one(struct pci_dev *pdev,
148 const struct pci_device_id *ent) 148 const struct pci_device_id *ent)
149{ 149{
150 static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL }; 150 static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
151 struct esb2rom_window *window = &esb2rom_window; 151 struct esb2rom_window *window = &esb2rom_window;
@@ -185,7 +185,7 @@ static int __devinit esb2rom_init_one(struct pci_dev *pdev,
185 /* Find a region continuous to the end of the ROM window */ 185 /* Find a region continuous to the end of the ROM window */
186 window->phys = 0; 186 window->phys = 0;
187 pci_read_config_word(pdev, FWH_DEC_EN1, &word); 187 pci_read_config_word(pdev, FWH_DEC_EN1, &word);
188 printk(KERN_DEBUG "pci_read_config_byte : %x\n", word); 188 printk(KERN_DEBUG "pci_read_config_word : %x\n", word);
189 189
190 if ((word & FWH_8MiB) == FWH_8MiB) 190 if ((word & FWH_8MiB) == FWH_8MiB)
191 window->phys = 0xff400000; 191 window->phys = 0xff400000;
@@ -212,6 +212,11 @@ static int __devinit esb2rom_init_one(struct pci_dev *pdev,
212 else if ((word & FWH_0_5MiB) == FWH_0_5MiB) 212 else if ((word & FWH_0_5MiB) == FWH_0_5MiB)
213 window->phys = 0xfff80000; 213 window->phys = 0xfff80000;
214 214
215 if (window->phys == 0) {
216 printk(KERN_ERR MOD_NAME ": Rom window is closed\n");
217 goto out;
218 }
219
215 /* reserved 0x0020 and 0x0010 */ 220 /* reserved 0x0020 and 0x0010 */
216 window->phys -= 0x400000UL; 221 window->phys -= 0x400000UL;
217 window->size = (0xffffffffUL - window->phys) + 1UL; 222 window->size = (0xffffffffUL - window->phys) + 1UL;
@@ -289,8 +294,8 @@ static int __devinit esb2rom_init_one(struct pci_dev *pdev,
289 (((unsigned long)(window->virt)) + offset); 294 (((unsigned long)(window->virt)) + offset);
290 map->map.size = 0xffffffffUL - map_top + 1UL; 295 map->map.size = 0xffffffffUL - map_top + 1UL;
291 /* Set the name of the map to the address I am trying */ 296 /* Set the name of the map to the address I am trying */
292 sprintf(map->map_name, "%s @%08lx", 297 sprintf(map->map_name, "%s @%08Lx",
293 MOD_NAME, map->map.phys); 298 MOD_NAME, (unsigned long long)map->map.phys);
294 299
295 /* Firmware hubs only use vpp when being programmed 300 /* Firmware hubs only use vpp when being programmed
296 * in a factory setting. So in-place programming 301 * in a factory setting. So in-place programming
diff --git a/drivers/mtd/maps/ichxrom.c b/drivers/mtd/maps/ichxrom.c
index 2bb3e63606..2c884c49e8 100644
--- a/drivers/mtd/maps/ichxrom.c
+++ b/drivers/mtd/maps/ichxrom.c
@@ -227,8 +227,8 @@ static int __devinit ichxrom_init_one (struct pci_dev *pdev,
227 (((unsigned long)(window->virt)) + offset); 227 (((unsigned long)(window->virt)) + offset);
228 map->map.size = 0xffffffffUL - map_top + 1UL; 228 map->map.size = 0xffffffffUL - map_top + 1UL;
229 /* Set the name of the map to the address I am trying */ 229 /* Set the name of the map to the address I am trying */
230 sprintf(map->map_name, "%s @%08lx", 230 sprintf(map->map_name, "%s @%08Lx",
231 MOD_NAME, map->map.phys); 231 MOD_NAME, (unsigned long long)map->map.phys);
232 232
233 /* Firmware hubs only use vpp when being programmed 233 /* Firmware hubs only use vpp when being programmed
234 * in a factory setting. So in-place programming 234 * in a factory setting. So in-place programming
diff --git a/drivers/mtd/maps/netsc520.c b/drivers/mtd/maps/netsc520.c
index ed21547015..95dcab2146 100644
--- a/drivers/mtd/maps/netsc520.c
+++ b/drivers/mtd/maps/netsc520.c
@@ -94,7 +94,9 @@ static struct mtd_info *mymtd;
94 94
95static int __init init_netsc520(void) 95static int __init init_netsc520(void)
96{ 96{
97 printk(KERN_NOTICE "NetSc520 flash device: 0x%lx at 0x%lx\n", netsc520_map.size, netsc520_map.phys); 97 printk(KERN_NOTICE "NetSc520 flash device: 0x%Lx at 0x%Lx\n",
98 (unsigned long long)netsc520_map.size,
99 (unsigned long long)netsc520_map.phys);
98 netsc520_map.virt = ioremap_nocache(netsc520_map.phys, netsc520_map.size); 100 netsc520_map.virt = ioremap_nocache(netsc520_map.phys, netsc520_map.size);
99 101
100 if (!netsc520_map.virt) { 102 if (!netsc520_map.virt) {
diff --git a/drivers/mtd/maps/sc520cdp.c b/drivers/mtd/maps/sc520cdp.c
index 9b50cfc355..4045e372b9 100644
--- a/drivers/mtd/maps/sc520cdp.c
+++ b/drivers/mtd/maps/sc520cdp.c
@@ -237,8 +237,9 @@ static int __init init_sc520cdp(void)
237#endif 237#endif
238 238
239 for (i = 0; i < NUM_FLASH_BANKS; i++) { 239 for (i = 0; i < NUM_FLASH_BANKS; i++) {
240 printk(KERN_NOTICE "SC520 CDP flash device: 0x%lx at 0x%lx\n", 240 printk(KERN_NOTICE "SC520 CDP flash device: 0x%Lx at 0x%Lx\n",
241 sc520cdp_map[i].size, sc520cdp_map[i].phys); 241 (unsigned long long)sc520cdp_map[i].size,
242 (unsigned long long)sc520cdp_map[i].phys);
242 243
243 sc520cdp_map[i].virt = ioremap_nocache(sc520cdp_map[i].phys, sc520cdp_map[i].size); 244 sc520cdp_map[i].virt = ioremap_nocache(sc520cdp_map[i].phys, sc520cdp_map[i].size);
244 245
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 61a994ea8a..1592eac64e 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -419,8 +419,9 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
419 info.erasesize = mtd->erasesize; 419 info.erasesize = mtd->erasesize;
420 info.writesize = mtd->writesize; 420 info.writesize = mtd->writesize;
421 info.oobsize = mtd->oobsize; 421 info.oobsize = mtd->oobsize;
422 info.ecctype = mtd->ecctype; 422 /* The below fields are obsolete */
423 info.eccsize = mtd->eccsize; 423 info.ecctype = -1;
424 info.eccsize = 0;
424 if (copy_to_user(argp, &info, sizeof(struct mtd_info_user))) 425 if (copy_to_user(argp, &info, sizeof(struct mtd_info_user)))
425 return -EFAULT; 426 return -EFAULT;
426 break; 427 break;
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index 06902683bc..41844ea024 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -727,8 +727,7 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
727 concat->mtd.erasesize = subdev[0]->erasesize; 727 concat->mtd.erasesize = subdev[0]->erasesize;
728 concat->mtd.writesize = subdev[0]->writesize; 728 concat->mtd.writesize = subdev[0]->writesize;
729 concat->mtd.oobsize = subdev[0]->oobsize; 729 concat->mtd.oobsize = subdev[0]->oobsize;
730 concat->mtd.ecctype = subdev[0]->ecctype; 730 concat->mtd.oobavail = subdev[0]->oobavail;
731 concat->mtd.eccsize = subdev[0]->eccsize;
732 if (subdev[0]->writev) 731 if (subdev[0]->writev)
733 concat->mtd.writev = concat_writev; 732 concat->mtd.writev = concat_writev;
734 if (subdev[0]->read_oob) 733 if (subdev[0]->read_oob)
@@ -774,8 +773,6 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
774 if (concat->mtd.writesize != subdev[i]->writesize || 773 if (concat->mtd.writesize != subdev[i]->writesize ||
775 concat->mtd.subpage_sft != subdev[i]->subpage_sft || 774 concat->mtd.subpage_sft != subdev[i]->subpage_sft ||
776 concat->mtd.oobsize != subdev[i]->oobsize || 775 concat->mtd.oobsize != subdev[i]->oobsize ||
777 concat->mtd.ecctype != subdev[i]->ecctype ||
778 concat->mtd.eccsize != subdev[i]->eccsize ||
779 !concat->mtd.read_oob != !subdev[i]->read_oob || 776 !concat->mtd.read_oob != !subdev[i]->read_oob ||
780 !concat->mtd.write_oob != !subdev[i]->write_oob) { 777 !concat->mtd.write_oob != !subdev[i]->write_oob) {
781 kfree(concat); 778 kfree(concat);
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index bafd2fba87..1af989023c 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -200,6 +200,11 @@ static int part_erase (struct mtd_info *mtd, struct erase_info *instr)
200 return -EINVAL; 200 return -EINVAL;
201 instr->addr += part->offset; 201 instr->addr += part->offset;
202 ret = part->master->erase(part->master, instr); 202 ret = part->master->erase(part->master, instr);
203 if (ret) {
204 if (instr->fail_addr != 0xffffffff)
205 instr->fail_addr -= part->offset;
206 instr->addr -= part->offset;
207 }
203 return ret; 208 return ret;
204} 209}
205 210
@@ -338,8 +343,7 @@ int add_mtd_partitions(struct mtd_info *master,
338 slave->mtd.size = parts[i].size; 343 slave->mtd.size = parts[i].size;
339 slave->mtd.writesize = master->writesize; 344 slave->mtd.writesize = master->writesize;
340 slave->mtd.oobsize = master->oobsize; 345 slave->mtd.oobsize = master->oobsize;
341 slave->mtd.ecctype = master->ecctype; 346 slave->mtd.oobavail = master->oobavail;
342 slave->mtd.eccsize = master->eccsize;
343 slave->mtd.subpage_sft = master->subpage_sft; 347 slave->mtd.subpage_sft = master->subpage_sft;
344 348
345 slave->mtd.name = parts[i].name; 349 slave->mtd.name = parts[i].name;
@@ -561,4 +565,3 @@ EXPORT_SYMBOL_GPL(deregister_mtd_parser);
561MODULE_LICENSE("GPL"); 565MODULE_LICENSE("GPL");
562MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>"); 566MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>");
563MODULE_DESCRIPTION("Generic support for partitioning of MTD devices"); 567MODULE_DESCRIPTION("Generic support for partitioning of MTD devices");
564
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 358f55a82d..2d12dcdd74 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -126,10 +126,6 @@ config MTD_NAND_S3C2410_HWECC
126 incorrect ECC generation, and if using these, the default of 126 incorrect ECC generation, and if using these, the default of
127 software ECC is preferable. 127 software ECC is preferable.
128 128
129 If you lay down a device with the hardware ECC, then you will
130 currently not be able to switch to software, as there is no
131 implementation for ECC method used by the S3C2410
132
133config MTD_NAND_NDFC 129config MTD_NAND_NDFC
134 tristate "NDFC NanD Flash Controller" 130 tristate "NDFC NanD Flash Controller"
135 depends on MTD_NAND && 44x 131 depends on MTD_NAND && 44x
@@ -221,9 +217,17 @@ config MTD_NAND_SHARPSL
221 tristate "Support for NAND Flash on Sharp SL Series (C7xx + others)" 217 tristate "Support for NAND Flash on Sharp SL Series (C7xx + others)"
222 depends on MTD_NAND && ARCH_PXA 218 depends on MTD_NAND && ARCH_PXA
223 219
220config MTD_NAND_BASLER_EXCITE
221 tristate "Support for NAND Flash on Basler eXcite"
222 depends on MTD_NAND && BASLER_EXCITE
223 help
224 This enables the driver for the NAND flash device found on the
225 Basler eXcite Smart Camera. If built as a module, the driver
226 will be named "excite_nandflash.ko".
227
224config MTD_NAND_CAFE 228config MTD_NAND_CAFE
225 tristate "NAND support for OLPC CAFÉ chip" 229 tristate "NAND support for OLPC CAFÉ chip"
226 depends on PCI 230 depends on MTD_NAND && PCI
227 help 231 help
228 Use NAND flash attached to the CAFÉ chip designed for the $100 232 Use NAND flash attached to the CAFÉ chip designed for the $100
229 laptop. 233 laptop.
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index f7a53f0b70..80f1dfc779 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_MTD_NAND_NANDSIM) += nandsim.o
24obj-$(CONFIG_MTD_NAND_CS553X) += cs553x_nand.o 24obj-$(CONFIG_MTD_NAND_CS553X) += cs553x_nand.o
25obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o 25obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o
26obj-$(CONFIG_MTD_NAND_AT91) += at91_nand.o 26obj-$(CONFIG_MTD_NAND_AT91) += at91_nand.o
27obj-$(CONFIG_MTD_NAND_BASLER_EXCITE) += excite_nandflash.o
27 28
28nand-objs := nand_base.o nand_bbt.o 29nand-objs := nand_base.o nand_bbt.o
29cafe_nand-objs := cafe.o cafe_ecc.o 30cafe_nand-objs := cafe.o cafe_ecc.o
diff --git a/drivers/mtd/nand/cafe.c b/drivers/mtd/nand/cafe.c
index 08cb060dfa..fd6bb3ed40 100644
--- a/drivers/mtd/nand/cafe.c
+++ b/drivers/mtd/nand/cafe.c
@@ -78,8 +78,9 @@ module_param(regdebug, int, 0644);
78static int checkecc = 1; 78static int checkecc = 1;
79module_param(checkecc, int, 0644); 79module_param(checkecc, int, 0644);
80 80
81static int slowtiming = 0; 81static int numtimings;
82module_param(slowtiming, int, 0644); 82static int timing[3];
83module_param_array(timing, int, &numtimings, 0644);
83 84
84/* Hrm. Why isn't this already conditional on something in the struct device? */ 85/* Hrm. Why isn't this already conditional on something in the struct device? */
85#define cafe_dev_dbg(dev, args...) do { if (debug) dev_dbg(dev, ##args); } while(0) 86#define cafe_dev_dbg(dev, args...) do { if (debug) dev_dbg(dev, ##args); } while(0)
@@ -264,10 +265,10 @@ static void cafe_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
264 ndelay(100); 265 ndelay(100);
265 266
266 if (1) { 267 if (1) {
267 int c = 500000; 268 int c;
268 uint32_t irqs; 269 uint32_t irqs;
269 270
270 while (c--) { 271 for (c = 500000; c != 0; c--) {
271 irqs = cafe_readl(cafe, NAND_IRQ); 272 irqs = cafe_readl(cafe, NAND_IRQ);
272 if (irqs & doneint) 273 if (irqs & doneint)
273 break; 274 break;
@@ -529,6 +530,7 @@ static int __devinit cafe_nand_probe(struct pci_dev *pdev,
529{ 530{
530 struct mtd_info *mtd; 531 struct mtd_info *mtd;
531 struct cafe_priv *cafe; 532 struct cafe_priv *cafe;
533 uint32_t timing1, timing2, timing3;
532 uint32_t ctrl; 534 uint32_t ctrl;
533 int err = 0; 535 int err = 0;
534 536
@@ -580,31 +582,45 @@ static int __devinit cafe_nand_probe(struct pci_dev *pdev,
580 cafe->nand.block_bad = cafe_nand_block_bad; 582 cafe->nand.block_bad = cafe_nand_block_bad;
581 } 583 }
582 584
585 if (numtimings && numtimings != 3) {
586 dev_warn(&cafe->pdev->dev, "%d timing register values ignored; precisely three are required\n", numtimings);
587 }
588
589 if (numtimings == 3) {
590 timing1 = timing[0];
591 timing2 = timing[1];
592 timing3 = timing[2];
593 cafe_dev_dbg(&cafe->pdev->dev, "Using provided timings (%08x %08x %08x)\n",
594 timing1, timing2, timing3);
595 } else {
596 timing1 = cafe_readl(cafe, NAND_TIMING1);
597 timing2 = cafe_readl(cafe, NAND_TIMING2);
598 timing3 = cafe_readl(cafe, NAND_TIMING3);
599
600 if (timing1 | timing2 | timing3) {
601 cafe_dev_dbg(&cafe->pdev->dev, "Timing registers already set (%08x %08x %08x)\n", timing1, timing2, timing3);
602 } else {
603 dev_warn(&cafe->pdev->dev, "Timing registers unset; using most conservative defaults\n");
604 timing1 = timing2 = timing3 = 0xffffffff;
605 }
606 }
607
583 /* Start off by resetting the NAND controller completely */ 608 /* Start off by resetting the NAND controller completely */
584 cafe_writel(cafe, 1, NAND_RESET); 609 cafe_writel(cafe, 1, NAND_RESET);
585 cafe_writel(cafe, 0, NAND_RESET); 610 cafe_writel(cafe, 0, NAND_RESET);
586 611
587 cafe_writel(cafe, 0xffffffff, NAND_IRQ_MASK); 612 cafe_writel(cafe, timing1, NAND_TIMING1);
613 cafe_writel(cafe, timing2, NAND_TIMING2);
614 cafe_writel(cafe, timing3, NAND_TIMING3);
588 615
589 /* Timings from Marvell's test code (not verified or calculated by us) */
590 if (!slowtiming) {
591 cafe_writel(cafe, 0x01010a0a, NAND_TIMING1);
592 cafe_writel(cafe, 0x24121212, NAND_TIMING2);
593 cafe_writel(cafe, 0x11000000, NAND_TIMING3);
594 } else {
595 cafe_writel(cafe, 0xffffffff, NAND_TIMING1);
596 cafe_writel(cafe, 0xffffffff, NAND_TIMING2);
597 cafe_writel(cafe, 0xffffffff, NAND_TIMING3);
598 }
599 cafe_writel(cafe, 0xffffffff, NAND_IRQ_MASK); 616 cafe_writel(cafe, 0xffffffff, NAND_IRQ_MASK);
600 err = request_irq(pdev->irq, &cafe_nand_interrupt, IRQF_SHARED, 617 err = request_irq(pdev->irq, &cafe_nand_interrupt, IRQF_SHARED,
601 "CAFE NAND", mtd); 618 "CAFE NAND", mtd);
602 if (err) { 619 if (err) {
603 dev_warn(&pdev->dev, "Could not register IRQ %d\n", pdev->irq); 620 dev_warn(&pdev->dev, "Could not register IRQ %d\n", pdev->irq);
604
605 goto out_free_dma; 621 goto out_free_dma;
606 } 622 }
607#if 1 623
608 /* Disable master reset, enable NAND clock */ 624 /* Disable master reset, enable NAND clock */
609 ctrl = cafe_readl(cafe, GLOBAL_CTRL); 625 ctrl = cafe_readl(cafe, GLOBAL_CTRL);
610 ctrl &= 0xffffeff0; 626 ctrl &= 0xffffeff0;
@@ -631,32 +647,8 @@ static int __devinit cafe_nand_probe(struct pci_dev *pdev,
631 cafe_writel(cafe, 0x80000007, GLOBAL_IRQ_MASK); 647 cafe_writel(cafe, 0x80000007, GLOBAL_IRQ_MASK);
632 cafe_dev_dbg(&cafe->pdev->dev, "Control %x, IRQ mask %x\n", 648 cafe_dev_dbg(&cafe->pdev->dev, "Control %x, IRQ mask %x\n",
633 cafe_readl(cafe, GLOBAL_CTRL), cafe_readl(cafe, GLOBAL_IRQ_MASK)); 649 cafe_readl(cafe, GLOBAL_CTRL), cafe_readl(cafe, GLOBAL_IRQ_MASK));
634#endif 650
635#if 1 651 /* Scan to find existence of the device */
636 mtd->writesize=2048;
637 mtd->oobsize = 0x40;
638 memset(cafe->dmabuf, 0x5a, 2112);
639 cafe->nand.cmdfunc(mtd, NAND_CMD_READID, 0, -1);
640 cafe->nand.read_byte(mtd);
641 cafe->nand.read_byte(mtd);
642 cafe->nand.read_byte(mtd);
643 cafe->nand.read_byte(mtd);
644 cafe->nand.read_byte(mtd);
645#endif
646#if 0
647 cafe->nand.cmdfunc(mtd, NAND_CMD_READ0, 0, 0);
648 // nand_wait_ready(mtd);
649 cafe->nand.read_byte(mtd);
650 cafe->nand.read_byte(mtd);
651 cafe->nand.read_byte(mtd);
652 cafe->nand.read_byte(mtd);
653#endif
654#if 0
655 writel(0x84600070, cafe->mmio);
656 udelay(10);
657 cafe_dev_dbg(&cafe->pdev->dev, "Status %x\n", cafe_readl(cafe, NAND_NONMEM));
658#endif
659 /* Scan to find existance of the device */
660 if (nand_scan_ident(mtd, 1)) { 652 if (nand_scan_ident(mtd, 1)) {
661 err = -ENXIO; 653 err = -ENXIO;
662 goto out_irq; 654 goto out_irq;
@@ -760,13 +752,4 @@ module_exit(cafe_nand_exit);
760 752
761MODULE_LICENSE("GPL"); 753MODULE_LICENSE("GPL");
762MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); 754MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
763MODULE_DESCRIPTION("NAND flash driver for OLPC CAFE chip"); 755MODULE_DESCRIPTION("NAND flash driver for OLPC CAFÉ chip");
764
765/* Correct ECC for 2048 bytes of 0xff:
766 41 a0 71 65 54 27 f3 93 ec a9 be ed 0b a1 */
767
768/* dwmw2's B-test board, in case of completely screwing it:
769Bad eraseblock 2394 at 0x12b40000
770Bad eraseblock 2627 at 0x14860000
771Bad eraseblock 3349 at 0x1a2a0000
772*/
diff --git a/drivers/mtd/nand/cafe_ecc.c b/drivers/mtd/nand/cafe_ecc.c
index 1b9fa05a44..ea5c8491d2 100644
--- a/drivers/mtd/nand/cafe_ecc.c
+++ b/drivers/mtd/nand/cafe_ecc.c
@@ -1045,7 +1045,7 @@ static unsigned short err_pos_lut[4096] = {
1045 1045
1046static unsigned short err_pos(unsigned short din) 1046static unsigned short err_pos(unsigned short din)
1047{ 1047{
1048 BUG_ON(din > 4096); 1048 BUG_ON(din >= ARRAY_SIZE(err_pos_lut));
1049 return err_pos_lut[din]; 1049 return err_pos_lut[din];
1050} 1050}
1051static int chk_no_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info) 1051static int chk_no_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c
index 12608c13cc..595208f965 100644
--- a/drivers/mtd/nand/diskonchip.c
+++ b/drivers/mtd/nand/diskonchip.c
@@ -114,7 +114,7 @@ module_param(no_autopart, int, 0);
114static int show_firmware_partition = 0; 114static int show_firmware_partition = 0;
115module_param(show_firmware_partition, int, 0); 115module_param(show_firmware_partition, int, 0);
116 116
117#ifdef MTD_NAND_DISKONCHIP_BBTWRITE 117#ifdef CONFIG_MTD_NAND_DISKONCHIP_BBTWRITE
118static int inftl_bbt_write = 1; 118static int inftl_bbt_write = 1;
119#else 119#else
120static int inftl_bbt_write = 0; 120static int inftl_bbt_write = 0;
diff --git a/drivers/mtd/nand/excite_nandflash.c b/drivers/mtd/nand/excite_nandflash.c
new file mode 100644
index 0000000000..7e9afc4c77
--- /dev/null
+++ b/drivers/mtd/nand/excite_nandflash.c
@@ -0,0 +1,248 @@
1/*
2* Copyright (C) 2005 - 2007 by Basler Vision Technologies AG
3* Author: Thomas Koeller <thomas.koeller.qbaslerweb.com>
4* Original code by Thies Moeller <thies.moeller@baslerweb.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* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19*/
20
21#include <linux/module.h>
22#include <linux/types.h>
23#include <linux/init.h>
24#include <linux/kernel.h>
25#include <linux/string.h>
26#include <linux/ioport.h>
27#include <linux/platform_device.h>
28#include <linux/delay.h>
29#include <linux/err.h>
30#include <linux/kernel.h>
31
32#include <linux/mtd/mtd.h>
33#include <linux/mtd/nand.h>
34#include <linux/mtd/nand_ecc.h>
35#include <linux/mtd/partitions.h>
36
37#include <asm/io.h>
38#include <asm/rm9k-ocd.h>
39
40#include <excite_nandflash.h>
41
42#define EXCITE_NANDFLASH_VERSION "0.1"
43
44/* I/O register offsets */
45#define EXCITE_NANDFLASH_DATA_BYTE 0x00
46#define EXCITE_NANDFLASH_STATUS_BYTE 0x0c
47#define EXCITE_NANDFLASH_ADDR_BYTE 0x10
48#define EXCITE_NANDFLASH_CMD_BYTE 0x14
49
50/* prefix for debug output */
51static const char module_id[] = "excite_nandflash";
52
53/*
54 * partition definition
55 */
56static const struct mtd_partition partition_info[] = {
57 {
58 .name = "eXcite RootFS",
59 .offset = 0,
60 .size = MTDPART_SIZ_FULL
61 }
62};
63
64static inline const struct resource *
65excite_nand_get_resource(struct platform_device *d, unsigned long flags,
66 const char *basename)
67{
68 char buf[80];
69
70 if (snprintf(buf, sizeof buf, "%s_%u", basename, d->id) >= sizeof buf)
71 return NULL;
72 return platform_get_resource_byname(d, flags, buf);
73}
74
75static inline void __iomem *
76excite_nand_map_regs(struct platform_device *d, const char *basename)
77{
78 void *result = NULL;
79 const struct resource *const r =
80 excite_nand_get_resource(d, IORESOURCE_MEM, basename);
81
82 if (r)
83 result = ioremap_nocache(r->start, r->end + 1 - r->start);
84 return result;
85}
86
87/* controller and mtd information */
88struct excite_nand_drvdata {
89 struct mtd_info board_mtd;
90 struct nand_chip board_chip;
91 void __iomem *regs;
92 void __iomem *tgt;
93};
94
95/* Control function */
96static void excite_nand_control(struct mtd_info *mtd, int cmd,
97 unsigned int ctrl)
98{
99 struct excite_nand_drvdata * const d =
100 container_of(mtd, struct excite_nand_drvdata, board_mtd);
101
102 switch (ctrl) {
103 case NAND_CTRL_CHANGE | NAND_CTRL_CLE:
104 d->tgt = d->regs + EXCITE_NANDFLASH_CMD_BYTE;
105 break;
106 case NAND_CTRL_CHANGE | NAND_CTRL_ALE:
107 d->tgt = d->regs + EXCITE_NANDFLASH_ADDR_BYTE;
108 break;
109 case NAND_CTRL_CHANGE | NAND_NCE:
110 d->tgt = d->regs + EXCITE_NANDFLASH_DATA_BYTE;
111 break;
112 }
113
114 if (cmd != NAND_CMD_NONE)
115 __raw_writeb(cmd, d->tgt);
116}
117
118/* Return 0 if flash is busy, 1 if ready */
119static int excite_nand_devready(struct mtd_info *mtd)
120{
121 struct excite_nand_drvdata * const drvdata =
122 container_of(mtd, struct excite_nand_drvdata, board_mtd);
123
124 return __raw_readb(drvdata->regs + EXCITE_NANDFLASH_STATUS_BYTE);
125}
126
127/*
128 * Called by device layer to remove the driver.
129 * The binding to the mtd and all allocated
130 * resources are released.
131 */
132static int __exit excite_nand_remove(struct device *dev)
133{
134 struct excite_nand_drvdata * const this = dev_get_drvdata(dev);
135
136 dev_set_drvdata(dev, NULL);
137
138 if (unlikely(!this)) {
139 printk(KERN_ERR "%s: called %s without private data!!",
140 module_id, __func__);
141 return -EINVAL;
142 }
143
144 /* first thing we need to do is release our mtd
145 * then go through freeing the resource used
146 */
147 nand_release(&this->board_mtd);
148
149 /* free the common resources */
150 iounmap(this->regs);
151 kfree(this);
152
153 DEBUG(MTD_DEBUG_LEVEL1, "%s: removed\n", module_id);
154 return 0;
155}
156
157/*
158 * Called by device layer when it finds a device matching
159 * one our driver can handle. This code checks to see if
160 * it can allocate all necessary resources then calls the
161 * nand layer to look for devices.
162*/
163static int __init excite_nand_probe(struct device *dev)
164{
165 struct platform_device * const pdev = to_platform_device(dev);
166 struct excite_nand_drvdata *drvdata; /* private driver data */
167 struct nand_chip *board_chip; /* private flash chip data */
168 struct mtd_info *board_mtd; /* mtd info for this board */
169 int scan_res;
170
171 drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL);
172 if (unlikely(!drvdata)) {
173 printk(KERN_ERR "%s: no memory for drvdata\n",
174 module_id);
175 return -ENOMEM;
176 }
177
178 /* bind private data into driver */
179 dev_set_drvdata(dev, drvdata);
180
181 /* allocate and map the resource */
182 drvdata->regs =
183 excite_nand_map_regs(pdev, EXCITE_NANDFLASH_RESOURCE_REGS);
184
185 if (unlikely(!drvdata->regs)) {
186 printk(KERN_ERR "%s: cannot reserve register region\n",
187 module_id);
188 kfree(drvdata);
189 return -ENXIO;
190 }
191
192 drvdata->tgt = drvdata->regs + EXCITE_NANDFLASH_DATA_BYTE;
193
194 /* initialise our chip */
195 board_chip = &drvdata->board_chip;
196 board_chip->IO_ADDR_R = board_chip->IO_ADDR_W =
197 drvdata->regs + EXCITE_NANDFLASH_DATA_BYTE;
198 board_chip->cmd_ctrl = excite_nand_control;
199 board_chip->dev_ready = excite_nand_devready;
200 board_chip->chip_delay = 25;
201 board_chip->ecc.mode = NAND_ECC_SOFT;
202
203 /* link chip to mtd */
204 board_mtd = &drvdata->board_mtd;
205 board_mtd->priv = board_chip;
206
207 DEBUG(MTD_DEBUG_LEVEL2, "%s: device scan\n", module_id);
208 scan_res = nand_scan(&drvdata->board_mtd, 1);
209
210 if (likely(!scan_res)) {
211 DEBUG(MTD_DEBUG_LEVEL2, "%s: register partitions\n", module_id);
212 add_mtd_partitions(&drvdata->board_mtd, partition_info,
213 sizeof partition_info / sizeof partition_info[0]);
214 } else {
215 iounmap(drvdata->regs);
216 kfree(drvdata);
217 printk(KERN_ERR "%s: device scan failed\n", module_id);
218 return -EIO;
219 }
220 return 0;
221}
222
223static struct device_driver excite_nand_driver = {
224 .name = "excite_nand",
225 .bus = &platform_bus_type,
226 .probe = excite_nand_probe,
227 .remove = __exit_p(excite_nand_remove)
228};
229
230static int __init excite_nand_init(void)
231{
232 pr_info("Basler eXcite nand flash driver Version "
233 EXCITE_NANDFLASH_VERSION "\n");
234 return driver_register(&excite_nand_driver);
235}
236
237static void __exit excite_nand_exit(void)
238{
239 driver_unregister(&excite_nand_driver);
240}
241
242module_init(excite_nand_init);
243module_exit(excite_nand_exit);
244
245MODULE_AUTHOR("Thomas Koeller <thomas.koeller@baslerweb.com>");
246MODULE_DESCRIPTION("Basler eXcite NAND-Flash driver");
247MODULE_LICENSE("GPL");
248MODULE_VERSION(EXCITE_NANDFLASH_VERSION)
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index dfe56e03e4..6af37b8cff 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1272,10 +1272,25 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1272 DEBUG(MTD_DEBUG_LEVEL3, "nand_read_oob: from = 0x%08Lx, len = %i\n", 1272 DEBUG(MTD_DEBUG_LEVEL3, "nand_read_oob: from = 0x%08Lx, len = %i\n",
1273 (unsigned long long)from, readlen); 1273 (unsigned long long)from, readlen);
1274 1274
1275 if (ops->mode == MTD_OOB_RAW) 1275 if (ops->mode == MTD_OOB_AUTO)
1276 len = mtd->oobsize;
1277 else
1278 len = chip->ecc.layout->oobavail; 1276 len = chip->ecc.layout->oobavail;
1277 else
1278 len = mtd->oobsize;
1279
1280 if (unlikely(ops->ooboffs >= len)) {
1281 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: "
1282 "Attempt to start read outside oob\n");
1283 return -EINVAL;
1284 }
1285
1286 /* Do not allow reads past end of device */
1287 if (unlikely(from >= mtd->size ||
1288 ops->ooboffs + readlen > ((mtd->size >> chip->page_shift) -
1289 (from >> chip->page_shift)) * len)) {
1290 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: "
1291 "Attempt read beyond end of device\n");
1292 return -EINVAL;
1293 }
1279 1294
1280 chipnr = (int)(from >> chip->chip_shift); 1295 chipnr = (int)(from >> chip->chip_shift);
1281 chip->select_chip(mtd, chipnr); 1296 chip->select_chip(mtd, chipnr);
@@ -1742,19 +1757,40 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,
1742static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, 1757static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
1743 struct mtd_oob_ops *ops) 1758 struct mtd_oob_ops *ops)
1744{ 1759{
1745 int chipnr, page, status; 1760 int chipnr, page, status, len;
1746 struct nand_chip *chip = mtd->priv; 1761 struct nand_chip *chip = mtd->priv;
1747 1762
1748 DEBUG(MTD_DEBUG_LEVEL3, "nand_write_oob: to = 0x%08x, len = %i\n", 1763 DEBUG(MTD_DEBUG_LEVEL3, "nand_write_oob: to = 0x%08x, len = %i\n",
1749 (unsigned int)to, (int)ops->ooblen); 1764 (unsigned int)to, (int)ops->ooblen);
1750 1765
1766 if (ops->mode == MTD_OOB_AUTO)
1767 len = chip->ecc.layout->oobavail;
1768 else
1769 len = mtd->oobsize;
1770
1751 /* Do not allow write past end of page */ 1771 /* Do not allow write past end of page */
1752 if ((ops->ooboffs + ops->ooblen) > mtd->oobsize) { 1772 if ((ops->ooboffs + ops->ooblen) > len) {
1753 DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: " 1773 DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: "
1754 "Attempt to write past end of page\n"); 1774 "Attempt to write past end of page\n");
1755 return -EINVAL; 1775 return -EINVAL;
1756 } 1776 }
1757 1777
1778 if (unlikely(ops->ooboffs >= len)) {
1779 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: "
1780 "Attempt to start write outside oob\n");
1781 return -EINVAL;
1782 }
1783
1784 /* Do not allow reads past end of device */
1785 if (unlikely(to >= mtd->size ||
1786 ops->ooboffs + ops->ooblen >
1787 ((mtd->size >> chip->page_shift) -
1788 (to >> chip->page_shift)) * len)) {
1789 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: "
1790 "Attempt write beyond end of device\n");
1791 return -EINVAL;
1792 }
1793
1758 chipnr = (int)(to >> chip->chip_shift); 1794 chipnr = (int)(to >> chip->chip_shift);
1759 chip->select_chip(mtd, chipnr); 1795 chip->select_chip(mtd, chipnr);
1760 1796
@@ -2488,6 +2524,7 @@ int nand_scan_tail(struct mtd_info *mtd)
2488 for (i = 0; chip->ecc.layout->oobfree[i].length; i++) 2524 for (i = 0; chip->ecc.layout->oobfree[i].length; i++)
2489 chip->ecc.layout->oobavail += 2525 chip->ecc.layout->oobavail +=
2490 chip->ecc.layout->oobfree[i].length; 2526 chip->ecc.layout->oobfree[i].length;
2527 mtd->oobavail = chip->ecc.layout->oobavail;
2491 2528
2492 /* 2529 /*
2493 * Set the number of read / write steps for one page depending on ECC 2530 * Set the number of read / write steps for one page depending on ECC
@@ -2530,7 +2567,6 @@ int nand_scan_tail(struct mtd_info *mtd)
2530 /* Fill in remaining MTD driver data */ 2567 /* Fill in remaining MTD driver data */
2531 mtd->type = MTD_NANDFLASH; 2568 mtd->type = MTD_NANDFLASH;
2532 mtd->flags = MTD_CAP_NANDFLASH; 2569 mtd->flags = MTD_CAP_NANDFLASH;
2533 mtd->ecctype = MTD_ECC_SW;
2534 mtd->erase = nand_erase; 2570 mtd->erase = nand_erase;
2535 mtd->point = NULL; 2571 mtd->point = NULL;
2536 mtd->unpoint = NULL; 2572 mtd->unpoint = NULL;
diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index 8b3203571e..5fac4c421a 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -337,17 +337,69 @@ static int s3c2412_nand_devready(struct mtd_info *mtd)
337static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat, 337static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat,
338 u_char *read_ecc, u_char *calc_ecc) 338 u_char *read_ecc, u_char *calc_ecc)
339{ 339{
340 pr_debug("s3c2410_nand_correct_data(%p,%p,%p,%p)\n", mtd, dat, read_ecc, calc_ecc); 340 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
341 unsigned int diff0, diff1, diff2;
342 unsigned int bit, byte;
341 343
342 pr_debug("eccs: read %02x,%02x,%02x vs calc %02x,%02x,%02x\n", 344 pr_debug("%s(%p,%p,%p,%p)\n", __func__, mtd, dat, read_ecc, calc_ecc);
343 read_ecc[0], read_ecc[1], read_ecc[2], calc_ecc[0], calc_ecc[1], calc_ecc[2]);
344 345
345 if (read_ecc[0] == calc_ecc[0] && read_ecc[1] == calc_ecc[1] && read_ecc[2] == calc_ecc[2]) 346 diff0 = read_ecc[0] ^ calc_ecc[0];
346 return 0; 347 diff1 = read_ecc[1] ^ calc_ecc[1];
348 diff2 = read_ecc[2] ^ calc_ecc[2];
349
350 pr_debug("%s: rd %02x%02x%02x calc %02x%02x%02x diff %02x%02x%02x\n",
351 __func__,
352 read_ecc[0], read_ecc[1], read_ecc[2],
353 calc_ecc[0], calc_ecc[1], calc_ecc[2],
354 diff0, diff1, diff2);
355
356 if (diff0 == 0 && diff1 == 0 && diff2 == 0)
357 return 0; /* ECC is ok */
358
359 /* Can we correct this ECC (ie, one row and column change).
360 * Note, this is similar to the 256 error code on smartmedia */
361
362 if (((diff0 ^ (diff0 >> 1)) & 0x55) == 0x55 &&
363 ((diff1 ^ (diff1 >> 1)) & 0x55) == 0x55 &&
364 ((diff2 ^ (diff2 >> 1)) & 0x55) == 0x55) {
365 /* calculate the bit position of the error */
366
367 bit = (diff2 >> 2) & 1;
368 bit |= (diff2 >> 3) & 2;
369 bit |= (diff2 >> 4) & 4;
370
371 /* calculate the byte position of the error */
372
373 byte = (diff1 << 1) & 0x80;
374 byte |= (diff1 << 2) & 0x40;
375 byte |= (diff1 << 3) & 0x20;
376 byte |= (diff1 << 4) & 0x10;
377
378 byte |= (diff0 >> 3) & 0x08;
379 byte |= (diff0 >> 2) & 0x04;
380 byte |= (diff0 >> 1) & 0x02;
381 byte |= (diff0 >> 0) & 0x01;
347 382
348 /* we curently have no method for correcting the error */ 383 byte |= (diff2 << 8) & 0x100;
349 384
350 return -1; 385 dev_dbg(info->device, "correcting error bit %d, byte %d\n",
386 bit, byte);
387
388 dat[byte] ^= (1 << bit);
389 return 1;
390 }
391
392 /* if there is only one bit difference in the ECC, then
393 * one of only a row or column parity has changed, which
394 * means the error is most probably in the ECC itself */
395
396 diff0 |= (diff1 << 8);
397 diff0 |= (diff2 << 16);
398
399 if ((diff0 & ~(1<<fls(diff0))) == 0)
400 return 1;
401
402 return 0;
351} 403}
352 404
353/* ECC functions 405/* ECC functions
@@ -366,6 +418,15 @@ static void s3c2410_nand_enable_hwecc(struct mtd_info *mtd, int mode)
366 writel(ctrl, info->regs + S3C2410_NFCONF); 418 writel(ctrl, info->regs + S3C2410_NFCONF);
367} 419}
368 420
421static void s3c2412_nand_enable_hwecc(struct mtd_info *mtd, int mode)
422{
423 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
424 unsigned long ctrl;
425
426 ctrl = readl(info->regs + S3C2440_NFCONT);
427 writel(ctrl | S3C2412_NFCONT_INIT_MAIN_ECC, info->regs + S3C2440_NFCONT);
428}
429
369static void s3c2440_nand_enable_hwecc(struct mtd_info *mtd, int mode) 430static void s3c2440_nand_enable_hwecc(struct mtd_info *mtd, int mode)
370{ 431{
371 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); 432 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
@@ -383,6 +444,21 @@ static int s3c2410_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u
383 ecc_code[1] = readb(info->regs + S3C2410_NFECC + 1); 444 ecc_code[1] = readb(info->regs + S3C2410_NFECC + 1);
384 ecc_code[2] = readb(info->regs + S3C2410_NFECC + 2); 445 ecc_code[2] = readb(info->regs + S3C2410_NFECC + 2);
385 446
447 pr_debug("%s: returning ecc %02x%02x%02x\n", __func__,
448 ecc_code[0], ecc_code[1], ecc_code[2]);
449
450 return 0;
451}
452
453static int s3c2412_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
454{
455 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
456 unsigned long ecc = readl(info->regs + S3C2412_NFMECC0);
457
458 ecc_code[0] = ecc;
459 ecc_code[1] = ecc >> 8;
460 ecc_code[2] = ecc >> 16;
461
386 pr_debug("calculate_ecc: returning ecc %02x,%02x,%02x\n", ecc_code[0], ecc_code[1], ecc_code[2]); 462 pr_debug("calculate_ecc: returning ecc %02x,%02x,%02x\n", ecc_code[0], ecc_code[1], ecc_code[2]);
387 463
388 return 0; 464 return 0;
@@ -397,7 +473,7 @@ static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u
397 ecc_code[1] = ecc >> 8; 473 ecc_code[1] = ecc >> 8;
398 ecc_code[2] = ecc >> 16; 474 ecc_code[2] = ecc >> 16;
399 475
400 pr_debug("calculate_ecc: returning ecc %02x,%02x,%02x\n", ecc_code[0], ecc_code[1], ecc_code[2]); 476 pr_debug("%s: returning ecc %06lx\n", __func__, ecc);
401 477
402 return 0; 478 return 0;
403} 479}
@@ -565,6 +641,10 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
565 break; 641 break;
566 642
567 case TYPE_S3C2412: 643 case TYPE_S3C2412:
644 chip->ecc.hwctl = s3c2412_nand_enable_hwecc;
645 chip->ecc.calculate = s3c2412_nand_calculate_ecc;
646 break;
647
568 case TYPE_S3C2440: 648 case TYPE_S3C2440:
569 chip->ecc.hwctl = s3c2440_nand_enable_hwecc; 649 chip->ecc.hwctl = s3c2440_nand_enable_hwecc;
570 chip->ecc.calculate = s3c2440_nand_calculate_ecc; 650 chip->ecc.calculate = s3c2440_nand_calculate_ecc;
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index 2da6bb2635..9e14a26ca4 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -1,9 +1,14 @@
1/* 1/*
2 * linux/drivers/mtd/onenand/onenand_base.c 2 * linux/drivers/mtd/onenand/onenand_base.c
3 * 3 *
4 * Copyright (C) 2005-2006 Samsung Electronics 4 * Copyright (C) 2005-2007 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com> 5 * Kyungmin Park <kyungmin.park@samsung.com>
6 * 6 *
7 * Credits:
8 * Adrian Hunter <ext-adrian.hunter@nokia.com>:
9 * auto-placement support, read-while load support, various fixes
10 * Copyright (C) Nokia Corporation, 2007
11 *
7 * 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
8 * it under the terms of the GNU General Public License version 2 as 13 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation. 14 * published by the Free Software Foundation.
@@ -94,16 +99,9 @@ static void onenand_writew(unsigned short value, void __iomem *addr)
94 */ 99 */
95static int onenand_block_address(struct onenand_chip *this, int block) 100static int onenand_block_address(struct onenand_chip *this, int block)
96{ 101{
97 if (this->device_id & ONENAND_DEVICE_IS_DDP) { 102 /* Device Flash Core select, NAND Flash Block Address */
98 /* Device Flash Core select, NAND Flash Block Address */ 103 if (block & this->density_mask)
99 int dfs = 0; 104 return ONENAND_DDP_CHIP1 | (block ^ this->density_mask);
100
101 if (block & this->density_mask)
102 dfs = 1;
103
104 return (dfs << ONENAND_DDP_SHIFT) |
105 (block & (this->density_mask - 1));
106 }
107 105
108 return block; 106 return block;
109} 107}
@@ -118,17 +116,11 @@ static int onenand_block_address(struct onenand_chip *this, int block)
118 */ 116 */
119static int onenand_bufferram_address(struct onenand_chip *this, int block) 117static int onenand_bufferram_address(struct onenand_chip *this, int block)
120{ 118{
121 if (this->device_id & ONENAND_DEVICE_IS_DDP) { 119 /* Device BufferRAM Select */
122 /* Device BufferRAM Select */ 120 if (block & this->density_mask)
123 int dbs = 0; 121 return ONENAND_DDP_CHIP1;
124
125 if (block & this->density_mask)
126 dbs = 1;
127
128 return (dbs << ONENAND_DDP_SHIFT);
129 }
130 122
131 return 0; 123 return ONENAND_DDP_CHIP0;
132} 124}
133 125
134/** 126/**
@@ -317,22 +309,25 @@ static int onenand_wait(struct mtd_info *mtd, int state)
317 ctrl = this->read_word(this->base + ONENAND_REG_CTRL_STATUS); 309 ctrl = this->read_word(this->base + ONENAND_REG_CTRL_STATUS);
318 310
319 if (ctrl & ONENAND_CTRL_ERROR) { 311 if (ctrl & ONENAND_CTRL_ERROR) {
320 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: controller error = 0x%04x\n", ctrl); 312 printk(KERN_ERR "onenand_wait: controller error = 0x%04x\n", ctrl);
321 if (ctrl & ONENAND_CTRL_LOCK) 313 if (ctrl & ONENAND_CTRL_LOCK)
322 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: it's locked error.\n"); 314 printk(KERN_ERR "onenand_wait: it's locked error.\n");
323 return ctrl; 315 return ctrl;
324 } 316 }
325 317
326 if (interrupt & ONENAND_INT_READ) { 318 if (interrupt & ONENAND_INT_READ) {
327 int ecc = this->read_word(this->base + ONENAND_REG_ECC_STATUS); 319 int ecc = this->read_word(this->base + ONENAND_REG_ECC_STATUS);
328 if (ecc) { 320 if (ecc) {
329 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: ECC error = 0x%04x\n", ecc); 321 printk(KERN_ERR "onenand_wait: ECC error = 0x%04x\n", ecc);
330 if (ecc & ONENAND_ECC_2BIT_ALL) { 322 if (ecc & ONENAND_ECC_2BIT_ALL) {
331 mtd->ecc_stats.failed++; 323 mtd->ecc_stats.failed++;
332 return ecc; 324 return ecc;
333 } else if (ecc & ONENAND_ECC_1BIT_ALL) 325 } else if (ecc & ONENAND_ECC_1BIT_ALL)
334 mtd->ecc_stats.corrected++; 326 mtd->ecc_stats.corrected++;
335 } 327 }
328 } else if (state == FL_READING) {
329 printk(KERN_ERR "onenand_wait: read timeout! ctrl=0x%04x intr=0x%04x\n", ctrl, interrupt);
330 return -EIO;
336 } 331 }
337 332
338 return 0; 333 return 0;
@@ -587,22 +582,32 @@ static int onenand_write_bufferram(struct mtd_info *mtd, int area,
587static int onenand_check_bufferram(struct mtd_info *mtd, loff_t addr) 582static int onenand_check_bufferram(struct mtd_info *mtd, loff_t addr)
588{ 583{
589 struct onenand_chip *this = mtd->priv; 584 struct onenand_chip *this = mtd->priv;
590 int block, page; 585 int blockpage, found = 0;
591 int i; 586 unsigned int i;
592 587
593 block = (int) (addr >> this->erase_shift); 588 blockpage = (int) (addr >> this->page_shift);
594 page = (int) (addr >> this->page_shift);
595 page &= this->page_mask;
596 589
590 /* Is there valid data? */
597 i = ONENAND_CURRENT_BUFFERRAM(this); 591 i = ONENAND_CURRENT_BUFFERRAM(this);
592 if (this->bufferram[i].blockpage == blockpage)
593 found = 1;
594 else {
595 /* Check another BufferRAM */
596 i = ONENAND_NEXT_BUFFERRAM(this);
597 if (this->bufferram[i].blockpage == blockpage) {
598 ONENAND_SET_NEXT_BUFFERRAM(this);
599 found = 1;
600 }
601 }
598 602
599 /* Is there valid data? */ 603 if (found && ONENAND_IS_DDP(this)) {
600 if (this->bufferram[i].block == block && 604 /* Select DataRAM for DDP */
601 this->bufferram[i].page == page && 605 int block = (int) (addr >> this->erase_shift);
602 this->bufferram[i].valid) 606 int value = onenand_bufferram_address(this, block);
603 return 1; 607 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2);
608 }
604 609
605 return 0; 610 return found;
606} 611}
607 612
608/** 613/**
@@ -613,31 +618,49 @@ static int onenand_check_bufferram(struct mtd_info *mtd, loff_t addr)
613 * 618 *
614 * Update BufferRAM information 619 * Update BufferRAM information
615 */ 620 */
616static int onenand_update_bufferram(struct mtd_info *mtd, loff_t addr, 621static void onenand_update_bufferram(struct mtd_info *mtd, loff_t addr,
617 int valid) 622 int valid)
618{ 623{
619 struct onenand_chip *this = mtd->priv; 624 struct onenand_chip *this = mtd->priv;
620 int block, page; 625 int blockpage;
621 int i; 626 unsigned int i;
622 627
623 block = (int) (addr >> this->erase_shift); 628 blockpage = (int) (addr >> this->page_shift);
624 page = (int) (addr >> this->page_shift);
625 page &= this->page_mask;
626 629
627 /* Invalidate BufferRAM */ 630 /* Invalidate another BufferRAM */
628 for (i = 0; i < MAX_BUFFERRAM; i++) { 631 i = ONENAND_NEXT_BUFFERRAM(this);
629 if (this->bufferram[i].block == block && 632 if (this->bufferram[i].blockpage == blockpage)
630 this->bufferram[i].page == page) 633 this->bufferram[i].blockpage = -1;
631 this->bufferram[i].valid = 0;
632 }
633 634
634 /* Update BufferRAM */ 635 /* Update BufferRAM */
635 i = ONENAND_CURRENT_BUFFERRAM(this); 636 i = ONENAND_CURRENT_BUFFERRAM(this);
636 this->bufferram[i].block = block; 637 if (valid)
637 this->bufferram[i].page = page; 638 this->bufferram[i].blockpage = blockpage;
638 this->bufferram[i].valid = valid; 639 else
640 this->bufferram[i].blockpage = -1;
641}
639 642
640 return 0; 643/**
644 * onenand_invalidate_bufferram - [GENERIC] Invalidate BufferRAM information
645 * @param mtd MTD data structure
646 * @param addr start address to invalidate
647 * @param len length to invalidate
648 *
649 * Invalidate BufferRAM information
650 */
651static void onenand_invalidate_bufferram(struct mtd_info *mtd, loff_t addr,
652 unsigned int len)
653{
654 struct onenand_chip *this = mtd->priv;
655 int i;
656 loff_t end_addr = addr + len;
657
658 /* Invalidate BufferRAM */
659 for (i = 0; i < MAX_BUFFERRAM; i++) {
660 loff_t buf_addr = this->bufferram[i].blockpage << this->page_shift;
661 if (buf_addr >= addr && buf_addr < end_addr)
662 this->bufferram[i].blockpage = -1;
663 }
641} 664}
642 665
643/** 666/**
@@ -716,7 +739,7 @@ static int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
716 739
717 /* Do not allow reads past end of device */ 740 /* Do not allow reads past end of device */
718 if ((from + len) > mtd->size) { 741 if ((from + len) > mtd->size) {
719 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read: Attempt read beyond end of device\n"); 742 printk(KERN_ERR "onenand_read: Attempt read beyond end of device\n");
720 *retlen = 0; 743 *retlen = 0;
721 return -EINVAL; 744 return -EINVAL;
722 } 745 }
@@ -724,8 +747,6 @@ static int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
724 /* Grab the lock and see if the device is available */ 747 /* Grab the lock and see if the device is available */
725 onenand_get_device(mtd, FL_READING); 748 onenand_get_device(mtd, FL_READING);
726 749
727 /* TODO handling oob */
728
729 stats = mtd->ecc_stats; 750 stats = mtd->ecc_stats;
730 751
731 /* Read-while-load method */ 752 /* Read-while-load method */
@@ -754,9 +775,9 @@ static int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
754 * Now we issued chip 1 read and pointed chip 1 775 * Now we issued chip 1 read and pointed chip 1
755 * bufferam so we have to point chip 0 bufferam. 776 * bufferam so we have to point chip 0 bufferam.
756 */ 777 */
757 if (this->device_id & ONENAND_DEVICE_IS_DDP && 778 if (ONENAND_IS_DDP(this) &&
758 unlikely(from == (this->chipsize >> 1))) { 779 unlikely(from == (this->chipsize >> 1))) {
759 this->write_word(0, this->base + ONENAND_REG_START_ADDRESS2); 780 this->write_word(ONENAND_DDP_CHIP0, this->base + ONENAND_REG_START_ADDRESS2);
760 boundary = 1; 781 boundary = 1;
761 } else 782 } else
762 boundary = 0; 783 boundary = 0;
@@ -770,7 +791,7 @@ static int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
770 break; 791 break;
771 /* Set up for next read from bufferRAM */ 792 /* Set up for next read from bufferRAM */
772 if (unlikely(boundary)) 793 if (unlikely(boundary))
773 this->write_word(0x8000, this->base + ONENAND_REG_START_ADDRESS2); 794 this->write_word(ONENAND_DDP_CHIP1, this->base + ONENAND_REG_START_ADDRESS2);
774 ONENAND_SET_NEXT_BUFFERRAM(this); 795 ONENAND_SET_NEXT_BUFFERRAM(this);
775 buf += thislen; 796 buf += thislen;
776 thislen = min_t(int, mtd->writesize, len - read); 797 thislen = min_t(int, mtd->writesize, len - read);
@@ -801,20 +822,60 @@ static int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
801} 822}
802 823
803/** 824/**
825 * onenand_transfer_auto_oob - [Internal] oob auto-placement transfer
826 * @param mtd MTD device structure
827 * @param buf destination address
828 * @param column oob offset to read from
829 * @param thislen oob length to read
830 */
831static int onenand_transfer_auto_oob(struct mtd_info *mtd, uint8_t *buf, int column,
832 int thislen)
833{
834 struct onenand_chip *this = mtd->priv;
835 struct nand_oobfree *free;
836 int readcol = column;
837 int readend = column + thislen;
838 int lastgap = 0;
839 uint8_t *oob_buf = this->oob_buf;
840
841 for (free = this->ecclayout->oobfree; free->length; ++free) {
842 if (readcol >= lastgap)
843 readcol += free->offset - lastgap;
844 if (readend >= lastgap)
845 readend += free->offset - lastgap;
846 lastgap = free->offset + free->length;
847 }
848 this->read_bufferram(mtd, ONENAND_SPARERAM, oob_buf, 0, mtd->oobsize);
849 for (free = this->ecclayout->oobfree; free->length; ++free) {
850 int free_end = free->offset + free->length;
851 if (free->offset < readend && free_end > readcol) {
852 int st = max_t(int,free->offset,readcol);
853 int ed = min_t(int,free_end,readend);
854 int n = ed - st;
855 memcpy(buf, oob_buf + st, n);
856 buf += n;
857 } else
858 break;
859 }
860 return 0;
861}
862
863/**
804 * onenand_do_read_oob - [MTD Interface] OneNAND read out-of-band 864 * onenand_do_read_oob - [MTD Interface] OneNAND read out-of-band
805 * @param mtd MTD device structure 865 * @param mtd MTD device structure
806 * @param from offset to read from 866 * @param from offset to read from
807 * @param len number of bytes to read 867 * @param len number of bytes to read
808 * @param retlen pointer to variable to store the number of read bytes 868 * @param retlen pointer to variable to store the number of read bytes
809 * @param buf the databuffer to put data 869 * @param buf the databuffer to put data
870 * @param mode operation mode
810 * 871 *
811 * OneNAND read out-of-band data from the spare area 872 * OneNAND read out-of-band data from the spare area
812 */ 873 */
813int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len, 874static int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
814 size_t *retlen, u_char *buf) 875 size_t *retlen, u_char *buf, mtd_oob_mode_t mode)
815{ 876{
816 struct onenand_chip *this = mtd->priv; 877 struct onenand_chip *this = mtd->priv;
817 int read = 0, thislen, column; 878 int read = 0, thislen, column, oobsize;
818 int ret = 0; 879 int ret = 0;
819 880
820 DEBUG(MTD_DEBUG_LEVEL3, "onenand_read_oob: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len); 881 DEBUG(MTD_DEBUG_LEVEL3, "onenand_read_oob: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len);
@@ -822,21 +883,33 @@ int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
822 /* Initialize return length value */ 883 /* Initialize return length value */
823 *retlen = 0; 884 *retlen = 0;
824 885
886 if (mode == MTD_OOB_AUTO)
887 oobsize = this->ecclayout->oobavail;
888 else
889 oobsize = mtd->oobsize;
890
891 column = from & (mtd->oobsize - 1);
892
893 if (unlikely(column >= oobsize)) {
894 printk(KERN_ERR "onenand_read_oob: Attempted to start read outside oob\n");
895 return -EINVAL;
896 }
897
825 /* Do not allow reads past end of device */ 898 /* Do not allow reads past end of device */
826 if (unlikely((from + len) > mtd->size)) { 899 if (unlikely(from >= mtd->size ||
827 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read_oob: Attempt read beyond end of device\n"); 900 column + len > ((mtd->size >> this->page_shift) -
901 (from >> this->page_shift)) * oobsize)) {
902 printk(KERN_ERR "onenand_read_oob: Attempted to read beyond end of device\n");
828 return -EINVAL; 903 return -EINVAL;
829 } 904 }
830 905
831 /* Grab the lock and see if the device is available */ 906 /* Grab the lock and see if the device is available */
832 onenand_get_device(mtd, FL_READING); 907 onenand_get_device(mtd, FL_READING);
833 908
834 column = from & (mtd->oobsize - 1);
835
836 while (read < len) { 909 while (read < len) {
837 cond_resched(); 910 cond_resched();
838 911
839 thislen = mtd->oobsize - column; 912 thislen = oobsize - column;
840 thislen = min_t(int, thislen, len); 913 thislen = min_t(int, thislen, len);
841 914
842 this->command(mtd, ONENAND_CMD_READOOB, from, mtd->oobsize); 915 this->command(mtd, ONENAND_CMD_READOOB, from, mtd->oobsize);
@@ -846,11 +919,14 @@ int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
846 ret = this->wait(mtd, FL_READING); 919 ret = this->wait(mtd, FL_READING);
847 /* First copy data and check return value for ECC handling */ 920 /* First copy data and check return value for ECC handling */
848 921
849 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen); 922 if (mode == MTD_OOB_AUTO)
923 onenand_transfer_auto_oob(mtd, buf, column, thislen);
924 else
925 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen);
850 926
851 if (ret) { 927 if (ret) {
852 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read_oob: read failed = 0x%x\n", ret); 928 printk(KERN_ERR "onenand_read_oob: read failed = 0x%x\n", ret);
853 goto out; 929 break;
854 } 930 }
855 931
856 read += thislen; 932 read += thislen;
@@ -868,7 +944,6 @@ int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
868 } 944 }
869 } 945 }
870 946
871out:
872 /* Deselect and wake up anyone waiting on the device */ 947 /* Deselect and wake up anyone waiting on the device */
873 onenand_release_device(mtd); 948 onenand_release_device(mtd);
874 949
@@ -878,17 +953,139 @@ out:
878 953
879/** 954/**
880 * onenand_read_oob - [MTD Interface] NAND write data and/or out-of-band 955 * onenand_read_oob - [MTD Interface] NAND write data and/or out-of-band
881 * @mtd: MTD device structure 956 * @param mtd: MTD device structure
882 * @from: offset to read from 957 * @param from: offset to read from
883 * @ops: oob operation description structure 958 * @param ops: oob operation description structure
884 */ 959 */
885static int onenand_read_oob(struct mtd_info *mtd, loff_t from, 960static int onenand_read_oob(struct mtd_info *mtd, loff_t from,
886 struct mtd_oob_ops *ops) 961 struct mtd_oob_ops *ops)
887{ 962{
888 BUG_ON(ops->mode != MTD_OOB_PLACE); 963 switch (ops->mode) {
889 964 case MTD_OOB_PLACE:
965 case MTD_OOB_AUTO:
966 break;
967 case MTD_OOB_RAW:
968 /* Not implemented yet */
969 default:
970 return -EINVAL;
971 }
890 return onenand_do_read_oob(mtd, from + ops->ooboffs, ops->ooblen, 972 return onenand_do_read_oob(mtd, from + ops->ooboffs, ops->ooblen,
891 &ops->oobretlen, ops->oobbuf); 973 &ops->oobretlen, ops->oobbuf, ops->mode);
974}
975
976/**
977 * onenand_bbt_wait - [DEFAULT] wait until the command is done
978 * @param mtd MTD device structure
979 * @param state state to select the max. timeout value
980 *
981 * Wait for command done.
982 */
983static int onenand_bbt_wait(struct mtd_info *mtd, int state)
984{
985 struct onenand_chip *this = mtd->priv;
986 unsigned long timeout;
987 unsigned int interrupt;
988 unsigned int ctrl;
989
990 /* The 20 msec is enough */
991 timeout = jiffies + msecs_to_jiffies(20);
992 while (time_before(jiffies, timeout)) {
993 interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT);
994 if (interrupt & ONENAND_INT_MASTER)
995 break;
996 }
997 /* To get correct interrupt status in timeout case */
998 interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT);
999 ctrl = this->read_word(this->base + ONENAND_REG_CTRL_STATUS);
1000
1001 if (ctrl & ONENAND_CTRL_ERROR) {
1002 printk(KERN_DEBUG "onenand_bbt_wait: controller error = 0x%04x\n", ctrl);
1003 /* Initial bad block case */
1004 if (ctrl & ONENAND_CTRL_LOAD)
1005 return ONENAND_BBT_READ_ERROR;
1006 return ONENAND_BBT_READ_FATAL_ERROR;
1007 }
1008
1009 if (interrupt & ONENAND_INT_READ) {
1010 int ecc = this->read_word(this->base + ONENAND_REG_ECC_STATUS);
1011 if (ecc & ONENAND_ECC_2BIT_ALL)
1012 return ONENAND_BBT_READ_ERROR;
1013 } else {
1014 printk(KERN_ERR "onenand_bbt_wait: read timeout!"
1015 "ctrl=0x%04x intr=0x%04x\n", ctrl, interrupt);
1016 return ONENAND_BBT_READ_FATAL_ERROR;
1017 }
1018
1019 return 0;
1020}
1021
1022/**
1023 * onenand_bbt_read_oob - [MTD Interface] OneNAND read out-of-band for bbt scan
1024 * @param mtd MTD device structure
1025 * @param from offset to read from
1026 * @param ops oob operation description structure
1027 *
1028 * OneNAND read out-of-band data from the spare area for bbt scan
1029 */
1030int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
1031 struct mtd_oob_ops *ops)
1032{
1033 struct onenand_chip *this = mtd->priv;
1034 int read = 0, thislen, column;
1035 int ret = 0;
1036 size_t len = ops->ooblen;
1037 u_char *buf = ops->oobbuf;
1038
1039 DEBUG(MTD_DEBUG_LEVEL3, "onenand_bbt_read_oob: from = 0x%08x, len = %zi\n", (unsigned int) from, len);
1040
1041 /* Initialize return value */
1042 ops->oobretlen = 0;
1043
1044 /* Do not allow reads past end of device */
1045 if (unlikely((from + len) > mtd->size)) {
1046 printk(KERN_ERR "onenand_bbt_read_oob: Attempt read beyond end of device\n");
1047 return ONENAND_BBT_READ_FATAL_ERROR;
1048 }
1049
1050 /* Grab the lock and see if the device is available */
1051 onenand_get_device(mtd, FL_READING);
1052
1053 column = from & (mtd->oobsize - 1);
1054
1055 while (read < len) {
1056 cond_resched();
1057
1058 thislen = mtd->oobsize - column;
1059 thislen = min_t(int, thislen, len);
1060
1061 this->command(mtd, ONENAND_CMD_READOOB, from, mtd->oobsize);
1062
1063 onenand_update_bufferram(mtd, from, 0);
1064
1065 ret = onenand_bbt_wait(mtd, FL_READING);
1066 if (ret)
1067 break;
1068
1069 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen);
1070 read += thislen;
1071 if (read == len)
1072 break;
1073
1074 buf += thislen;
1075
1076 /* Read more? */
1077 if (read < len) {
1078 /* Update Page size */
1079 from += mtd->writesize;
1080 column = 0;
1081 }
1082 }
1083
1084 /* Deselect and wake up anyone waiting on the device */
1085 onenand_release_device(mtd);
1086
1087 ops->oobretlen = read;
1088 return ret;
892} 1089}
893 1090
894#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE 1091#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
@@ -897,14 +1094,12 @@ static int onenand_read_oob(struct mtd_info *mtd, loff_t from,
897 * @param mtd MTD device structure 1094 * @param mtd MTD device structure
898 * @param buf the databuffer to verify 1095 * @param buf the databuffer to verify
899 * @param to offset to read from 1096 * @param to offset to read from
900 * @param len number of bytes to read and compare
901 * 1097 *
902 */ 1098 */
903static int onenand_verify_oob(struct mtd_info *mtd, const u_char *buf, loff_t to, int len) 1099static int onenand_verify_oob(struct mtd_info *mtd, const u_char *buf, loff_t to)
904{ 1100{
905 struct onenand_chip *this = mtd->priv; 1101 struct onenand_chip *this = mtd->priv;
906 char *readp = this->page_buf; 1102 char oobbuf[64];
907 int column = to & (mtd->oobsize - 1);
908 int status, i; 1103 int status, i;
909 1104
910 this->command(mtd, ONENAND_CMD_READOOB, to, mtd->oobsize); 1105 this->command(mtd, ONENAND_CMD_READOOB, to, mtd->oobsize);
@@ -913,51 +1108,60 @@ static int onenand_verify_oob(struct mtd_info *mtd, const u_char *buf, loff_t to
913 if (status) 1108 if (status)
914 return status; 1109 return status;
915 1110
916 this->read_bufferram(mtd, ONENAND_SPARERAM, readp, column, len); 1111 this->read_bufferram(mtd, ONENAND_SPARERAM, oobbuf, 0, mtd->oobsize);
917 1112 for (i = 0; i < mtd->oobsize; i++)
918 for(i = 0; i < len; i++) 1113 if (buf[i] != 0xFF && buf[i] != oobbuf[i])
919 if (buf[i] != 0xFF && buf[i] != readp[i])
920 return -EBADMSG; 1114 return -EBADMSG;
921 1115
922 return 0; 1116 return 0;
923} 1117}
924 1118
925/** 1119/**
926 * onenand_verify_page - [GENERIC] verify the chip contents after a write 1120 * onenand_verify - [GENERIC] verify the chip contents after a write
927 * @param mtd MTD device structure 1121 * @param mtd MTD device structure
928 * @param buf the databuffer to verify 1122 * @param buf the databuffer to verify
1123 * @param addr offset to read from
1124 * @param len number of bytes to read and compare
929 * 1125 *
930 * Check DataRAM area directly
931 */ 1126 */
932static int onenand_verify_page(struct mtd_info *mtd, u_char *buf, loff_t addr) 1127static int onenand_verify(struct mtd_info *mtd, const u_char *buf, loff_t addr, size_t len)
933{ 1128{
934 struct onenand_chip *this = mtd->priv; 1129 struct onenand_chip *this = mtd->priv;
935 void __iomem *dataram0, *dataram1; 1130 void __iomem *dataram;
936 int ret = 0; 1131 int ret = 0;
1132 int thislen, column;
937 1133
938 /* In partial page write, just skip it */ 1134 while (len != 0) {
939 if ((addr & (mtd->writesize - 1)) != 0) 1135 thislen = min_t(int, mtd->writesize, len);
940 return 0; 1136 column = addr & (mtd->writesize - 1);
1137 if (column + thislen > mtd->writesize)
1138 thislen = mtd->writesize - column;
941 1139
942 this->command(mtd, ONENAND_CMD_READ, addr, mtd->writesize); 1140 this->command(mtd, ONENAND_CMD_READ, addr, mtd->writesize);
943 1141
944 ret = this->wait(mtd, FL_READING); 1142 onenand_update_bufferram(mtd, addr, 0);
945 if (ret) 1143
946 return ret; 1144 ret = this->wait(mtd, FL_READING);
1145 if (ret)
1146 return ret;
947 1147
948 onenand_update_bufferram(mtd, addr, 1); 1148 onenand_update_bufferram(mtd, addr, 1);
949 1149
950 /* Check, if the two dataram areas are same */ 1150 dataram = this->base + ONENAND_DATARAM;
951 dataram0 = this->base + ONENAND_DATARAM; 1151 dataram += onenand_bufferram_offset(mtd, ONENAND_DATARAM);
952 dataram1 = dataram0 + mtd->writesize;
953 1152
954 if (memcmp(dataram0, dataram1, mtd->writesize)) 1153 if (memcmp(buf, dataram + column, thislen))
955 return -EBADMSG; 1154 return -EBADMSG;
1155
1156 len -= thislen;
1157 buf += thislen;
1158 addr += thislen;
1159 }
956 1160
957 return 0; 1161 return 0;
958} 1162}
959#else 1163#else
960#define onenand_verify_page(...) (0) 1164#define onenand_verify(...) (0)
961#define onenand_verify_oob(...) (0) 1165#define onenand_verify_oob(...) (0)
962#endif 1166#endif
963 1167
@@ -988,60 +1192,57 @@ static int onenand_write(struct mtd_info *mtd, loff_t to, size_t len,
988 1192
989 /* Do not allow writes past end of device */ 1193 /* Do not allow writes past end of device */
990 if (unlikely((to + len) > mtd->size)) { 1194 if (unlikely((to + len) > mtd->size)) {
991 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write: Attempt write to past end of device\n"); 1195 printk(KERN_ERR "onenand_write: Attempt write to past end of device\n");
992 return -EINVAL; 1196 return -EINVAL;
993 } 1197 }
994 1198
995 /* Reject writes, which are not page aligned */ 1199 /* Reject writes, which are not page aligned */
996 if (unlikely(NOTALIGNED(to)) || unlikely(NOTALIGNED(len))) { 1200 if (unlikely(NOTALIGNED(to)) || unlikely(NOTALIGNED(len))) {
997 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write: Attempt to write not page aligned data\n"); 1201 printk(KERN_ERR "onenand_write: Attempt to write not page aligned data\n");
998 return -EINVAL; 1202 return -EINVAL;
999 } 1203 }
1000 1204
1001 column = to & (mtd->writesize - 1); 1205 column = to & (mtd->writesize - 1);
1002 subpage = column || (len & (mtd->writesize - 1));
1003 1206
1004 /* Grab the lock and see if the device is available */ 1207 /* Grab the lock and see if the device is available */
1005 onenand_get_device(mtd, FL_WRITING); 1208 onenand_get_device(mtd, FL_WRITING);
1006 1209
1007 /* Loop until all data write */ 1210 /* Loop until all data write */
1008 while (written < len) { 1211 while (written < len) {
1009 int bytes = mtd->writesize; 1212 int thislen = min_t(int, mtd->writesize - column, len - written);
1010 int thislen = min_t(int, bytes, len - written);
1011 u_char *wbuf = (u_char *) buf; 1213 u_char *wbuf = (u_char *) buf;
1012 1214
1013 cond_resched(); 1215 cond_resched();
1014 1216
1015 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, bytes); 1217 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, thislen);
1016 1218
1017 /* Partial page write */ 1219 /* Partial page write */
1220 subpage = thislen < mtd->writesize;
1018 if (subpage) { 1221 if (subpage) {
1019 bytes = min_t(int, bytes - column, (int) len);
1020 memset(this->page_buf, 0xff, mtd->writesize); 1222 memset(this->page_buf, 0xff, mtd->writesize);
1021 memcpy(this->page_buf + column, buf, bytes); 1223 memcpy(this->page_buf + column, buf, thislen);
1022 wbuf = this->page_buf; 1224 wbuf = this->page_buf;
1023 /* Even though partial write, we need page size */
1024 thislen = mtd->writesize;
1025 } 1225 }
1026 1226
1027 this->write_bufferram(mtd, ONENAND_DATARAM, wbuf, 0, thislen); 1227 this->write_bufferram(mtd, ONENAND_DATARAM, wbuf, 0, mtd->writesize);
1028 this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0, mtd->oobsize); 1228 this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0, mtd->oobsize);
1029 1229
1030 this->command(mtd, ONENAND_CMD_PROG, to, mtd->writesize); 1230 this->command(mtd, ONENAND_CMD_PROG, to, mtd->writesize);
1031 1231
1232 ret = this->wait(mtd, FL_WRITING);
1233
1032 /* In partial page write we don't update bufferram */ 1234 /* In partial page write we don't update bufferram */
1033 onenand_update_bufferram(mtd, to, !subpage); 1235 onenand_update_bufferram(mtd, to, !ret && !subpage);
1034 1236
1035 ret = this->wait(mtd, FL_WRITING);
1036 if (ret) { 1237 if (ret) {
1037 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write: write filaed %d\n", ret); 1238 printk(KERN_ERR "onenand_write: write filaed %d\n", ret);
1038 break; 1239 break;
1039 } 1240 }
1040 1241
1041 /* Only check verify write turn on */ 1242 /* Only check verify write turn on */
1042 ret = onenand_verify_page(mtd, (u_char *) wbuf, to); 1243 ret = onenand_verify(mtd, (u_char *) wbuf, to, thislen);
1043 if (ret) { 1244 if (ret) {
1044 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write: verify failed %d\n", ret); 1245 printk(KERN_ERR "onenand_write: verify failed %d\n", ret);
1045 break; 1246 break;
1046 } 1247 }
1047 1248
@@ -1064,51 +1265,115 @@ static int onenand_write(struct mtd_info *mtd, loff_t to, size_t len,
1064} 1265}
1065 1266
1066/** 1267/**
1268 * onenand_fill_auto_oob - [Internal] oob auto-placement transfer
1269 * @param mtd MTD device structure
1270 * @param oob_buf oob buffer
1271 * @param buf source address
1272 * @param column oob offset to write to
1273 * @param thislen oob length to write
1274 */
1275static int onenand_fill_auto_oob(struct mtd_info *mtd, u_char *oob_buf,
1276 const u_char *buf, int column, int thislen)
1277{
1278 struct onenand_chip *this = mtd->priv;
1279 struct nand_oobfree *free;
1280 int writecol = column;
1281 int writeend = column + thislen;
1282 int lastgap = 0;
1283
1284 for (free = this->ecclayout->oobfree; free->length; ++free) {
1285 if (writecol >= lastgap)
1286 writecol += free->offset - lastgap;
1287 if (writeend >= lastgap)
1288 writeend += free->offset - lastgap;
1289 lastgap = free->offset + free->length;
1290 }
1291 for (free = this->ecclayout->oobfree; free->length; ++free) {
1292 int free_end = free->offset + free->length;
1293 if (free->offset < writeend && free_end > writecol) {
1294 int st = max_t(int,free->offset,writecol);
1295 int ed = min_t(int,free_end,writeend);
1296 int n = ed - st;
1297 memcpy(oob_buf + st, buf, n);
1298 buf += n;
1299 } else
1300 break;
1301 }
1302 return 0;
1303}
1304
1305/**
1067 * onenand_do_write_oob - [Internal] OneNAND write out-of-band 1306 * onenand_do_write_oob - [Internal] OneNAND write out-of-band
1068 * @param mtd MTD device structure 1307 * @param mtd MTD device structure
1069 * @param to offset to write to 1308 * @param to offset to write to
1070 * @param len number of bytes to write 1309 * @param len number of bytes to write
1071 * @param retlen pointer to variable to store the number of written bytes 1310 * @param retlen pointer to variable to store the number of written bytes
1072 * @param buf the data to write 1311 * @param buf the data to write
1312 * @param mode operation mode
1073 * 1313 *
1074 * OneNAND write out-of-band 1314 * OneNAND write out-of-band
1075 */ 1315 */
1076static int onenand_do_write_oob(struct mtd_info *mtd, loff_t to, size_t len, 1316static int onenand_do_write_oob(struct mtd_info *mtd, loff_t to, size_t len,
1077 size_t *retlen, const u_char *buf) 1317 size_t *retlen, const u_char *buf, mtd_oob_mode_t mode)
1078{ 1318{
1079 struct onenand_chip *this = mtd->priv; 1319 struct onenand_chip *this = mtd->priv;
1080 int column, ret = 0; 1320 int column, ret = 0, oobsize;
1081 int written = 0; 1321 int written = 0;
1322 u_char *oobbuf;
1082 1323
1083 DEBUG(MTD_DEBUG_LEVEL3, "onenand_write_oob: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len); 1324 DEBUG(MTD_DEBUG_LEVEL3, "onenand_write_oob: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len);
1084 1325
1085 /* Initialize retlen, in case of early exit */ 1326 /* Initialize retlen, in case of early exit */
1086 *retlen = 0; 1327 *retlen = 0;
1087 1328
1088 /* Do not allow writes past end of device */ 1329 if (mode == MTD_OOB_AUTO)
1089 if (unlikely((to + len) > mtd->size)) { 1330 oobsize = this->ecclayout->oobavail;
1090 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write_oob: Attempt write to past end of device\n"); 1331 else
1332 oobsize = mtd->oobsize;
1333
1334 column = to & (mtd->oobsize - 1);
1335
1336 if (unlikely(column >= oobsize)) {
1337 printk(KERN_ERR "onenand_write_oob: Attempted to start write outside oob\n");
1338 return -EINVAL;
1339 }
1340
1341 /* For compatibility with NAND: Do not allow write past end of page */
1342 if (unlikely(column + len > oobsize)) {
1343 printk(KERN_ERR "onenand_write_oob: "
1344 "Attempt to write past end of page\n");
1345 return -EINVAL;
1346 }
1347
1348 /* Do not allow reads past end of device */
1349 if (unlikely(to >= mtd->size ||
1350 column + len > ((mtd->size >> this->page_shift) -
1351 (to >> this->page_shift)) * oobsize)) {
1352 printk(KERN_ERR "onenand_write_oob: Attempted to write past end of device\n");
1091 return -EINVAL; 1353 return -EINVAL;
1092 } 1354 }
1093 1355
1094 /* Grab the lock and see if the device is available */ 1356 /* Grab the lock and see if the device is available */
1095 onenand_get_device(mtd, FL_WRITING); 1357 onenand_get_device(mtd, FL_WRITING);
1096 1358
1359 oobbuf = this->oob_buf;
1360
1097 /* Loop until all data write */ 1361 /* Loop until all data write */
1098 while (written < len) { 1362 while (written < len) {
1099 int thislen = min_t(int, mtd->oobsize, len - written); 1363 int thislen = min_t(int, oobsize, len - written);
1100 1364
1101 cond_resched(); 1365 cond_resched();
1102 1366
1103 column = to & (mtd->oobsize - 1);
1104
1105 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->oobsize); 1367 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->oobsize);
1106 1368
1107 /* We send data to spare ram with oobsize 1369 /* We send data to spare ram with oobsize
1108 * to prevent byte access */ 1370 * to prevent byte access */
1109 memset(this->page_buf, 0xff, mtd->oobsize); 1371 memset(oobbuf, 0xff, mtd->oobsize);
1110 memcpy(this->page_buf + column, buf, thislen); 1372 if (mode == MTD_OOB_AUTO)
1111 this->write_bufferram(mtd, ONENAND_SPARERAM, this->page_buf, 0, mtd->oobsize); 1373 onenand_fill_auto_oob(mtd, oobbuf, buf, column, thislen);
1374 else
1375 memcpy(oobbuf + column, buf, thislen);
1376 this->write_bufferram(mtd, ONENAND_SPARERAM, oobbuf, 0, mtd->oobsize);
1112 1377
1113 this->command(mtd, ONENAND_CMD_PROGOOB, to, mtd->oobsize); 1378 this->command(mtd, ONENAND_CMD_PROGOOB, to, mtd->oobsize);
1114 1379
@@ -1116,26 +1381,25 @@ static int onenand_do_write_oob(struct mtd_info *mtd, loff_t to, size_t len,
1116 1381
1117 ret = this->wait(mtd, FL_WRITING); 1382 ret = this->wait(mtd, FL_WRITING);
1118 if (ret) { 1383 if (ret) {
1119 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write_oob: write filaed %d\n", ret); 1384 printk(KERN_ERR "onenand_write_oob: write failed %d\n", ret);
1120 goto out; 1385 break;
1121 } 1386 }
1122 1387
1123 ret = onenand_verify_oob(mtd, buf, to, thislen); 1388 ret = onenand_verify_oob(mtd, oobbuf, to);
1124 if (ret) { 1389 if (ret) {
1125 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write_oob: verify failed %d\n", ret); 1390 printk(KERN_ERR "onenand_write_oob: verify failed %d\n", ret);
1126 goto out; 1391 break;
1127 } 1392 }
1128 1393
1129 written += thislen; 1394 written += thislen;
1130
1131 if (written == len) 1395 if (written == len)
1132 break; 1396 break;
1133 1397
1134 to += thislen; 1398 to += mtd->writesize;
1135 buf += thislen; 1399 buf += thislen;
1400 column = 0;
1136 } 1401 }
1137 1402
1138out:
1139 /* Deselect and wake up anyone waiting on the device */ 1403 /* Deselect and wake up anyone waiting on the device */
1140 onenand_release_device(mtd); 1404 onenand_release_device(mtd);
1141 1405
@@ -1146,17 +1410,24 @@ out:
1146 1410
1147/** 1411/**
1148 * onenand_write_oob - [MTD Interface] NAND write data and/or out-of-band 1412 * onenand_write_oob - [MTD Interface] NAND write data and/or out-of-band
1149 * @mtd: MTD device structure 1413 * @param mtd: MTD device structure
1150 * @from: offset to read from 1414 * @param to: offset to write
1151 * @ops: oob operation description structure 1415 * @param ops: oob operation description structure
1152 */ 1416 */
1153static int onenand_write_oob(struct mtd_info *mtd, loff_t to, 1417static int onenand_write_oob(struct mtd_info *mtd, loff_t to,
1154 struct mtd_oob_ops *ops) 1418 struct mtd_oob_ops *ops)
1155{ 1419{
1156 BUG_ON(ops->mode != MTD_OOB_PLACE); 1420 switch (ops->mode) {
1157 1421 case MTD_OOB_PLACE:
1422 case MTD_OOB_AUTO:
1423 break;
1424 case MTD_OOB_RAW:
1425 /* Not implemented yet */
1426 default:
1427 return -EINVAL;
1428 }
1158 return onenand_do_write_oob(mtd, to + ops->ooboffs, ops->ooblen, 1429 return onenand_do_write_oob(mtd, to + ops->ooboffs, ops->ooblen,
1159 &ops->oobretlen, ops->oobbuf); 1430 &ops->oobretlen, ops->oobbuf, ops->mode);
1160} 1431}
1161 1432
1162/** 1433/**
@@ -1199,19 +1470,19 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)
1199 1470
1200 /* Start address must align on block boundary */ 1471 /* Start address must align on block boundary */
1201 if (unlikely(instr->addr & (block_size - 1))) { 1472 if (unlikely(instr->addr & (block_size - 1))) {
1202 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Unaligned address\n"); 1473 printk(KERN_ERR "onenand_erase: Unaligned address\n");
1203 return -EINVAL; 1474 return -EINVAL;
1204 } 1475 }
1205 1476
1206 /* Length must align on block boundary */ 1477 /* Length must align on block boundary */
1207 if (unlikely(instr->len & (block_size - 1))) { 1478 if (unlikely(instr->len & (block_size - 1))) {
1208 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Length not block aligned\n"); 1479 printk(KERN_ERR "onenand_erase: Length not block aligned\n");
1209 return -EINVAL; 1480 return -EINVAL;
1210 } 1481 }
1211 1482
1212 /* Do not allow erase past end of device */ 1483 /* Do not allow erase past end of device */
1213 if (unlikely((instr->len + instr->addr) > mtd->size)) { 1484 if (unlikely((instr->len + instr->addr) > mtd->size)) {
1214 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Erase past end of device\n"); 1485 printk(KERN_ERR "onenand_erase: Erase past end of device\n");
1215 return -EINVAL; 1486 return -EINVAL;
1216 } 1487 }
1217 1488
@@ -1238,10 +1509,12 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)
1238 1509
1239 this->command(mtd, ONENAND_CMD_ERASE, addr, block_size); 1510 this->command(mtd, ONENAND_CMD_ERASE, addr, block_size);
1240 1511
1512 onenand_invalidate_bufferram(mtd, addr, block_size);
1513
1241 ret = this->wait(mtd, FL_ERASING); 1514 ret = this->wait(mtd, FL_ERASING);
1242 /* Check, if it is write protected */ 1515 /* Check, if it is write protected */
1243 if (ret) { 1516 if (ret) {
1244 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Failed erase, block %d\n", (unsigned) (addr >> this->erase_shift)); 1517 printk(KERN_ERR "onenand_erase: Failed erase, block %d\n", (unsigned) (addr >> this->erase_shift));
1245 instr->state = MTD_ERASE_FAILED; 1518 instr->state = MTD_ERASE_FAILED;
1246 instr->fail_addr = addr; 1519 instr->fail_addr = addr;
1247 goto erase_exit; 1520 goto erase_exit;
@@ -1322,7 +1595,7 @@ static int onenand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
1322 1595
1323 /* We write two bytes, so we dont have to mess with 16 bit access */ 1596 /* We write two bytes, so we dont have to mess with 16 bit access */
1324 ofs += mtd->oobsize + (bbm->badblockpos & ~0x01); 1597 ofs += mtd->oobsize + (bbm->badblockpos & ~0x01);
1325 return onenand_do_write_oob(mtd, ofs , 2, &retlen, buf); 1598 return onenand_do_write_oob(mtd, ofs , 2, &retlen, buf, MTD_OOB_PLACE);
1326} 1599}
1327 1600
1328/** 1601/**
@@ -1353,6 +1626,7 @@ static int onenand_block_markbad(struct mtd_info *mtd, loff_t ofs)
1353 * @param mtd MTD device structure 1626 * @param mtd MTD device structure
1354 * @param ofs offset relative to mtd start 1627 * @param ofs offset relative to mtd start
1355 * @param len number of bytes to lock or unlock 1628 * @param len number of bytes to lock or unlock
1629 * @param cmd lock or unlock command
1356 * 1630 *
1357 * Lock or unlock one or more blocks 1631 * Lock or unlock one or more blocks
1358 */ 1632 */
@@ -1491,6 +1765,8 @@ static int onenand_unlock_all(struct mtd_info *mtd)
1491 struct onenand_chip *this = mtd->priv; 1765 struct onenand_chip *this = mtd->priv;
1492 1766
1493 if (this->options & ONENAND_HAS_UNLOCK_ALL) { 1767 if (this->options & ONENAND_HAS_UNLOCK_ALL) {
1768 /* Set start block address */
1769 this->write_word(0, this->base + ONENAND_REG_START_BLOCK_ADDRESS);
1494 /* Write unlock command */ 1770 /* Write unlock command */
1495 this->command(mtd, ONENAND_CMD_UNLOCK_ALL, 0, 0); 1771 this->command(mtd, ONENAND_CMD_UNLOCK_ALL, 0, 0);
1496 1772
@@ -1503,13 +1779,10 @@ static int onenand_unlock_all(struct mtd_info *mtd)
1503 continue; 1779 continue;
1504 1780
1505 /* Workaround for all block unlock in DDP */ 1781 /* Workaround for all block unlock in DDP */
1506 if (this->device_id & ONENAND_DEVICE_IS_DDP) { 1782 if (ONENAND_IS_DDP(this)) {
1507 loff_t ofs;
1508 size_t len;
1509
1510 /* 1st block on another chip */ 1783 /* 1st block on another chip */
1511 ofs = this->chipsize >> 1; 1784 loff_t ofs = this->chipsize >> 1;
1512 len = 1 << this->erase_shift; 1785 size_t len = mtd->erasesize;
1513 1786
1514 onenand_unlock(mtd, ofs, len); 1787 onenand_unlock(mtd, ofs, len);
1515 } 1788 }
@@ -1617,7 +1890,7 @@ static int do_otp_lock(struct mtd_info *mtd, loff_t from, size_t len,
1617 this->command(mtd, ONENAND_CMD_OTP_ACCESS, 0, 0); 1890 this->command(mtd, ONENAND_CMD_OTP_ACCESS, 0, 0);
1618 this->wait(mtd, FL_OTPING); 1891 this->wait(mtd, FL_OTPING);
1619 1892
1620 ret = onenand_do_write_oob(mtd, from, len, retlen, buf); 1893 ret = onenand_do_write_oob(mtd, from, len, retlen, buf, MTD_OOB_PLACE);
1621 1894
1622 /* Exit OTP access mode */ 1895 /* Exit OTP access mode */
1623 this->command(mtd, ONENAND_CMD_RESET, 0, 0); 1896 this->command(mtd, ONENAND_CMD_RESET, 0, 0);
@@ -1823,12 +2096,13 @@ static int onenand_lock_user_prot_reg(struct mtd_info *mtd, loff_t from,
1823#endif /* CONFIG_MTD_ONENAND_OTP */ 2096#endif /* CONFIG_MTD_ONENAND_OTP */
1824 2097
1825/** 2098/**
1826 * onenand_lock_scheme - Check and set OneNAND lock scheme 2099 * onenand_check_features - Check and set OneNAND features
1827 * @param mtd MTD data structure 2100 * @param mtd MTD data structure
1828 * 2101 *
1829 * Check and set OneNAND lock scheme 2102 * Check and set OneNAND features
2103 * - lock scheme
1830 */ 2104 */
1831static void onenand_lock_scheme(struct mtd_info *mtd) 2105static void onenand_check_features(struct mtd_info *mtd)
1832{ 2106{
1833 struct onenand_chip *this = mtd->priv; 2107 struct onenand_chip *this = mtd->priv;
1834 unsigned int density, process; 2108 unsigned int density, process;
@@ -1854,10 +2128,11 @@ static void onenand_lock_scheme(struct mtd_info *mtd)
1854} 2128}
1855 2129
1856/** 2130/**
1857 * onenand_print_device_info - Print device ID 2131 * onenand_print_device_info - Print device & version ID
1858 * @param device device ID 2132 * @param device device ID
2133 * @param version version ID
1859 * 2134 *
1860 * Print device ID 2135 * Print device & version ID
1861 */ 2136 */
1862static void onenand_print_device_info(int device, int version) 2137static void onenand_print_device_info(int device, int version)
1863{ 2138{
@@ -1961,26 +2236,28 @@ static int onenand_probe(struct mtd_info *mtd)
1961 density = dev_id >> ONENAND_DEVICE_DENSITY_SHIFT; 2236 density = dev_id >> ONENAND_DEVICE_DENSITY_SHIFT;
1962 this->chipsize = (16 << density) << 20; 2237 this->chipsize = (16 << density) << 20;
1963 /* Set density mask. it is used for DDP */ 2238 /* Set density mask. it is used for DDP */
1964 this->density_mask = (1 << (density + 6)); 2239 if (ONENAND_IS_DDP(this))
2240 this->density_mask = (1 << (density + 6));
2241 else
2242 this->density_mask = 0;
1965 2243
1966 /* OneNAND page size & block size */ 2244 /* OneNAND page size & block size */
1967 /* The data buffer size is equal to page size */ 2245 /* The data buffer size is equal to page size */
1968 mtd->writesize = this->read_word(this->base + ONENAND_REG_DATA_BUFFER_SIZE); 2246 mtd->writesize = this->read_word(this->base + ONENAND_REG_DATA_BUFFER_SIZE);
1969 mtd->oobsize = mtd->writesize >> 5; 2247 mtd->oobsize = mtd->writesize >> 5;
1970 /* Pagers per block is always 64 in OneNAND */ 2248 /* Pages per a block are always 64 in OneNAND */
1971 mtd->erasesize = mtd->writesize << 6; 2249 mtd->erasesize = mtd->writesize << 6;
1972 2250
1973 this->erase_shift = ffs(mtd->erasesize) - 1; 2251 this->erase_shift = ffs(mtd->erasesize) - 1;
1974 this->page_shift = ffs(mtd->writesize) - 1; 2252 this->page_shift = ffs(mtd->writesize) - 1;
1975 this->ppb_shift = (this->erase_shift - this->page_shift); 2253 this->page_mask = (1 << (this->erase_shift - this->page_shift)) - 1;
1976 this->page_mask = (mtd->erasesize / mtd->writesize) - 1;
1977 2254
1978 /* REVIST: Multichip handling */ 2255 /* REVIST: Multichip handling */
1979 2256
1980 mtd->size = this->chipsize; 2257 mtd->size = this->chipsize;
1981 2258
1982 /* Check OneNAND lock scheme */ 2259 /* Check OneNAND features */
1983 onenand_lock_scheme(mtd); 2260 onenand_check_features(mtd);
1984 2261
1985 return 0; 2262 return 0;
1986} 2263}
@@ -2021,6 +2298,7 @@ static void onenand_resume(struct mtd_info *mtd)
2021 */ 2298 */
2022int onenand_scan(struct mtd_info *mtd, int maxchips) 2299int onenand_scan(struct mtd_info *mtd, int maxchips)
2023{ 2300{
2301 int i;
2024 struct onenand_chip *this = mtd->priv; 2302 struct onenand_chip *this = mtd->priv;
2025 2303
2026 if (!this->read_word) 2304 if (!this->read_word)
@@ -2054,15 +2332,25 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
2054 2332
2055 /* Allocate buffers, if necessary */ 2333 /* Allocate buffers, if necessary */
2056 if (!this->page_buf) { 2334 if (!this->page_buf) {
2057 size_t len; 2335 this->page_buf = kzalloc(mtd->writesize, GFP_KERNEL);
2058 len = mtd->writesize + mtd->oobsize;
2059 this->page_buf = kmalloc(len, GFP_KERNEL);
2060 if (!this->page_buf) { 2336 if (!this->page_buf) {
2061 printk(KERN_ERR "onenand_scan(): Can't allocate page_buf\n"); 2337 printk(KERN_ERR "onenand_scan(): Can't allocate page_buf\n");
2062 return -ENOMEM; 2338 return -ENOMEM;
2063 } 2339 }
2064 this->options |= ONENAND_PAGEBUF_ALLOC; 2340 this->options |= ONENAND_PAGEBUF_ALLOC;
2065 } 2341 }
2342 if (!this->oob_buf) {
2343 this->oob_buf = kzalloc(mtd->oobsize, GFP_KERNEL);
2344 if (!this->oob_buf) {
2345 printk(KERN_ERR "onenand_scan(): Can't allocate oob_buf\n");
2346 if (this->options & ONENAND_PAGEBUF_ALLOC) {
2347 this->options &= ~ONENAND_PAGEBUF_ALLOC;
2348 kfree(this->page_buf);
2349 }
2350 return -ENOMEM;
2351 }
2352 this->options |= ONENAND_OOBBUF_ALLOC;
2353 }
2066 2354
2067 this->state = FL_READY; 2355 this->state = FL_READY;
2068 init_waitqueue_head(&this->wq); 2356 init_waitqueue_head(&this->wq);
@@ -2092,12 +2380,22 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
2092 } 2380 }
2093 2381
2094 this->subpagesize = mtd->writesize >> mtd->subpage_sft; 2382 this->subpagesize = mtd->writesize >> mtd->subpage_sft;
2383
2384 /*
2385 * The number of bytes available for a client to place data into
2386 * the out of band area
2387 */
2388 this->ecclayout->oobavail = 0;
2389 for (i = 0; this->ecclayout->oobfree[i].length; i++)
2390 this->ecclayout->oobavail +=
2391 this->ecclayout->oobfree[i].length;
2392 mtd->oobavail = this->ecclayout->oobavail;
2393
2095 mtd->ecclayout = this->ecclayout; 2394 mtd->ecclayout = this->ecclayout;
2096 2395
2097 /* Fill in remaining MTD driver data */ 2396 /* Fill in remaining MTD driver data */
2098 mtd->type = MTD_NANDFLASH; 2397 mtd->type = MTD_NANDFLASH;
2099 mtd->flags = MTD_CAP_NANDFLASH; 2398 mtd->flags = MTD_CAP_NANDFLASH;
2100 mtd->ecctype = MTD_ECC_SW;
2101 mtd->erase = onenand_erase; 2399 mtd->erase = onenand_erase;
2102 mtd->point = NULL; 2400 mtd->point = NULL;
2103 mtd->unpoint = NULL; 2401 mtd->unpoint = NULL;
@@ -2144,11 +2442,16 @@ void onenand_release(struct mtd_info *mtd)
2144 del_mtd_device (mtd); 2442 del_mtd_device (mtd);
2145 2443
2146 /* Free bad block table memory, if allocated */ 2444 /* Free bad block table memory, if allocated */
2147 if (this->bbm) 2445 if (this->bbm) {
2446 struct bbm_info *bbm = this->bbm;
2447 kfree(bbm->bbt);
2148 kfree(this->bbm); 2448 kfree(this->bbm);
2149 /* Buffer allocated by onenand_scan */ 2449 }
2450 /* Buffers allocated by onenand_scan */
2150 if (this->options & ONENAND_PAGEBUF_ALLOC) 2451 if (this->options & ONENAND_PAGEBUF_ALLOC)
2151 kfree(this->page_buf); 2452 kfree(this->page_buf);
2453 if (this->options & ONENAND_OOBBUF_ALLOC)
2454 kfree(this->oob_buf);
2152} 2455}
2153 2456
2154EXPORT_SYMBOL_GPL(onenand_scan); 2457EXPORT_SYMBOL_GPL(onenand_scan);
diff --git a/drivers/mtd/onenand/onenand_bbt.c b/drivers/mtd/onenand/onenand_bbt.c
index 98f8fd1c63..aecdd50a17 100644
--- a/drivers/mtd/onenand/onenand_bbt.c
+++ b/drivers/mtd/onenand/onenand_bbt.c
@@ -17,8 +17,8 @@
17#include <linux/mtd/onenand.h> 17#include <linux/mtd/onenand.h>
18#include <linux/mtd/compatmac.h> 18#include <linux/mtd/compatmac.h>
19 19
20extern int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len, 20extern int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
21 size_t *retlen, u_char *buf); 21 struct mtd_oob_ops *ops);
22 22
23/** 23/**
24 * check_short_pattern - [GENERIC] check if a pattern is in the buffer 24 * check_short_pattern - [GENERIC] check if a pattern is in the buffer
@@ -65,10 +65,11 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
65 int startblock; 65 int startblock;
66 loff_t from; 66 loff_t from;
67 size_t readlen, ooblen; 67 size_t readlen, ooblen;
68 struct mtd_oob_ops ops;
68 69
69 printk(KERN_INFO "Scanning device for bad blocks\n"); 70 printk(KERN_INFO "Scanning device for bad blocks\n");
70 71
71 len = 1; 72 len = 2;
72 73
73 /* We need only read few bytes from the OOB area */ 74 /* We need only read few bytes from the OOB area */
74 scanlen = ooblen = 0; 75 scanlen = ooblen = 0;
@@ -82,22 +83,24 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
82 startblock = 0; 83 startblock = 0;
83 from = 0; 84 from = 0;
84 85
86 ops.mode = MTD_OOB_PLACE;
87 ops.ooblen = readlen;
88 ops.oobbuf = buf;
89 ops.len = ops.ooboffs = ops.retlen = ops.oobretlen = 0;
90
85 for (i = startblock; i < numblocks; ) { 91 for (i = startblock; i < numblocks; ) {
86 int ret; 92 int ret;
87 93
88 for (j = 0; j < len; j++) { 94 for (j = 0; j < len; j++) {
89 size_t retlen;
90
91 /* No need to read pages fully, 95 /* No need to read pages fully,
92 * just read required OOB bytes */ 96 * just read required OOB bytes */
93 ret = onenand_do_read_oob(mtd, from + j * mtd->writesize + bd->offs, 97 ret = onenand_bbt_read_oob(mtd, from + j * mtd->writesize + bd->offs, &ops);
94 readlen, &retlen, &buf[0]);
95 98
96 /* If it is a initial bad block, just ignore it */ 99 /* If it is a initial bad block, just ignore it */
97 if (ret && !(ret & ONENAND_CTRL_LOAD)) 100 if (ret == ONENAND_BBT_READ_FATAL_ERROR)
98 return ret; 101 return -EIO;
99 102
100 if (check_short_pattern(&buf[j * scanlen], scanlen, mtd->writesize, bd)) { 103 if (ret || check_short_pattern(&buf[j * scanlen], scanlen, mtd->writesize, bd)) {
101 bbm->bbt[i >> 3] |= 0x03 << (i & 0x6); 104 bbm->bbt[i >> 3] |= 0x03 << (i & 0x6);
102 printk(KERN_WARNING "Bad eraseblock %d at 0x%08x\n", 105 printk(KERN_WARNING "Bad eraseblock %d at 0x%08x\n",
103 i >> 1, (unsigned int) from); 106 i >> 1, (unsigned int) from);
@@ -168,8 +171,8 @@ static int onenand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt)
168 * marked good / bad blocks and writes the bad block table(s) to 171 * marked good / bad blocks and writes the bad block table(s) to
169 * the selected place. 172 * the selected place.
170 * 173 *
171 * The bad block table memory is allocated here. It must be freed 174 * The bad block table memory is allocated here. It is freed
172 * by calling the onenand_free_bbt function. 175 * by the onenand_release function.
173 * 176 *
174 */ 177 */
175int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) 178int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
diff --git a/drivers/mtd/redboot.c b/drivers/mtd/redboot.c
index 035cd9b0cc..a61351f88e 100644
--- a/drivers/mtd/redboot.c
+++ b/drivers/mtd/redboot.c
@@ -94,8 +94,19 @@ static int parse_redboot_partitions(struct mtd_info *master,
94 * (NOTE: this is 'size' not 'data_length'; size is 94 * (NOTE: this is 'size' not 'data_length'; size is
95 * the full size of the entry.) 95 * the full size of the entry.)
96 */ 96 */
97 if (swab32(buf[i].size) == master->erasesize) { 97
98 /* RedBoot can combine the FIS directory and
99 config partitions into a single eraseblock;
100 we assume wrong-endian if either the swapped
101 'size' matches the eraseblock size precisely,
102 or if the swapped size actually fits in an
103 eraseblock while the unswapped size doesn't. */
104 if (swab32(buf[i].size) == master->erasesize ||
105 (buf[i].size > master->erasesize
106 && swab32(buf[i].size) < master->erasesize)) {
98 int j; 107 int j;
108 /* Update numslots based on actual FIS directory size */
109 numslots = swab32(buf[i].size) / sizeof (struct fis_image_desc);
99 for (j = 0; j < numslots; ++j) { 110 for (j = 0; j < numslots; ++j) {
100 111
101 /* A single 0xff denotes a deleted entry. 112 /* A single 0xff denotes a deleted entry.
@@ -120,11 +131,11 @@ static int parse_redboot_partitions(struct mtd_info *master,
120 swab32s(&buf[j].desc_cksum); 131 swab32s(&buf[j].desc_cksum);
121 swab32s(&buf[j].file_cksum); 132 swab32s(&buf[j].file_cksum);
122 } 133 }
134 } else if (buf[i].size < master->erasesize) {
135 /* Update numslots based on actual FIS directory size */
136 numslots = buf[i].size / sizeof(struct fis_image_desc);
123 } 137 }
124 break; 138 break;
125 } else {
126 /* re-calculate of real numslots */
127 numslots = buf[i].size / sizeof(struct fis_image_desc);
128 } 139 }
129 } 140 }
130 if (i == numslots) { 141 if (i == numslots) {
diff --git a/drivers/net/3c59x.c b/drivers/net/3c59x.c
index 716a47210a..b406ecfa72 100644
--- a/drivers/net/3c59x.c
+++ b/drivers/net/3c59x.c
@@ -822,11 +822,17 @@ static int vortex_resume(struct pci_dev *pdev)
822{ 822{
823 struct net_device *dev = pci_get_drvdata(pdev); 823 struct net_device *dev = pci_get_drvdata(pdev);
824 struct vortex_private *vp = netdev_priv(dev); 824 struct vortex_private *vp = netdev_priv(dev);
825 int err;
825 826
826 if (dev && vp) { 827 if (dev && vp) {
827 pci_set_power_state(pdev, PCI_D0); 828 pci_set_power_state(pdev, PCI_D0);
828 pci_restore_state(pdev); 829 pci_restore_state(pdev);
829 pci_enable_device(pdev); 830 err = pci_enable_device(pdev);
831 if (err) {
832 printk(KERN_WARNING "%s: Could not enable device \n",
833 dev->name);
834 return err;
835 }
830 pci_set_master(pdev); 836 pci_set_master(pdev);
831 if (request_irq(dev->irq, vp->full_bus_master_rx ? 837 if (request_irq(dev->irq, vp->full_bus_master_rx ?
832 &boomerang_interrupt : &vortex_interrupt, IRQF_SHARED, dev->name, dev)) { 838 &boomerang_interrupt : &vortex_interrupt, IRQF_SHARED, dev->name, dev)) {
@@ -852,19 +858,7 @@ static struct eisa_device_id vortex_eisa_ids[] = {
852}; 858};
853MODULE_DEVICE_TABLE(eisa, vortex_eisa_ids); 859MODULE_DEVICE_TABLE(eisa, vortex_eisa_ids);
854 860
855static int vortex_eisa_probe(struct device *device); 861static int __init vortex_eisa_probe(struct device *device)
856static int vortex_eisa_remove(struct device *device);
857
858static struct eisa_driver vortex_eisa_driver = {
859 .id_table = vortex_eisa_ids,
860 .driver = {
861 .name = "3c59x",
862 .probe = vortex_eisa_probe,
863 .remove = vortex_eisa_remove
864 }
865};
866
867static int vortex_eisa_probe(struct device *device)
868{ 862{
869 void __iomem *ioaddr; 863 void __iomem *ioaddr;
870 struct eisa_device *edev; 864 struct eisa_device *edev;
@@ -887,7 +881,7 @@ static int vortex_eisa_probe(struct device *device)
887 return 0; 881 return 0;
888} 882}
889 883
890static int vortex_eisa_remove(struct device *device) 884static int __devexit vortex_eisa_remove(struct device *device)
891{ 885{
892 struct eisa_device *edev; 886 struct eisa_device *edev;
893 struct net_device *dev; 887 struct net_device *dev;
@@ -912,7 +906,17 @@ static int vortex_eisa_remove(struct device *device)
912 free_netdev(dev); 906 free_netdev(dev);
913 return 0; 907 return 0;
914} 908}
915#endif 909
910static struct eisa_driver vortex_eisa_driver = {
911 .id_table = vortex_eisa_ids,
912 .driver = {
913 .name = "3c59x",
914 .probe = vortex_eisa_probe,
915 .remove = __devexit_p(vortex_eisa_remove)
916 }
917};
918
919#endif /* CONFIG_EISA */
916 920
917/* returns count found (>= 0), or negative on error */ 921/* returns count found (>= 0), or negative on error */
918static int __init vortex_eisa_init(void) 922static int __init vortex_eisa_init(void)
diff --git a/drivers/net/8139cp.c b/drivers/net/8139cp.c
index 6f93a765e5..12c8453f44 100644
--- a/drivers/net/8139cp.c
+++ b/drivers/net/8139cp.c
@@ -448,8 +448,7 @@ static void cp_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
448 spin_lock_irqsave(&cp->lock, flags); 448 spin_lock_irqsave(&cp->lock, flags);
449 cp->cpcmd &= ~RxVlanOn; 449 cp->cpcmd &= ~RxVlanOn;
450 cpw16(CpCmd, cp->cpcmd); 450 cpw16(CpCmd, cp->cpcmd);
451 if (cp->vlgrp) 451 vlan_group_set_device(cp->vlgrp, vid, NULL);
452 cp->vlgrp->vlan_devices[vid] = NULL;
453 spin_unlock_irqrestore(&cp->lock, flags); 452 spin_unlock_irqrestore(&cp->lock, flags);
454} 453}
455#endif /* CP_VLAN_TAG_USED */ 454#endif /* CP_VLAN_TAG_USED */
diff --git a/drivers/net/8139too.c b/drivers/net/8139too.c
index 35ad5cff18..99304b2aa8 100644
--- a/drivers/net/8139too.c
+++ b/drivers/net/8139too.c
@@ -1109,6 +1109,8 @@ static void __devexit rtl8139_remove_one (struct pci_dev *pdev)
1109 1109
1110 assert (dev != NULL); 1110 assert (dev != NULL);
1111 1111
1112 flush_scheduled_work();
1113
1112 unregister_netdev (dev); 1114 unregister_netdev (dev);
1113 1115
1114 __rtl8139_cleanup_dev (dev); 1116 __rtl8139_cleanup_dev (dev);
@@ -1603,18 +1605,21 @@ static void rtl8139_thread (struct work_struct *work)
1603 struct net_device *dev = tp->mii.dev; 1605 struct net_device *dev = tp->mii.dev;
1604 unsigned long thr_delay = next_tick; 1606 unsigned long thr_delay = next_tick;
1605 1607
1608 rtnl_lock();
1609
1610 if (!netif_running(dev))
1611 goto out_unlock;
1612
1606 if (tp->watchdog_fired) { 1613 if (tp->watchdog_fired) {
1607 tp->watchdog_fired = 0; 1614 tp->watchdog_fired = 0;
1608 rtl8139_tx_timeout_task(work); 1615 rtl8139_tx_timeout_task(work);
1609 } else if (rtnl_trylock()) { 1616 } else
1610 rtl8139_thread_iter (dev, tp, tp->mmio_addr); 1617 rtl8139_thread_iter(dev, tp, tp->mmio_addr);
1611 rtnl_unlock ();
1612 } else {
1613 /* unlikely race. mitigate with fast poll. */
1614 thr_delay = HZ / 2;
1615 }
1616 1618
1617 schedule_delayed_work(&tp->thread, thr_delay); 1619 if (tp->have_thread)
1620 schedule_delayed_work(&tp->thread, thr_delay);
1621out_unlock:
1622 rtnl_unlock ();
1618} 1623}
1619 1624
1620static void rtl8139_start_thread(struct rtl8139_private *tp) 1625static void rtl8139_start_thread(struct rtl8139_private *tp)
@@ -1626,19 +1631,11 @@ static void rtl8139_start_thread(struct rtl8139_private *tp)
1626 return; 1631 return;
1627 1632
1628 tp->have_thread = 1; 1633 tp->have_thread = 1;
1634 tp->watchdog_fired = 0;
1629 1635
1630 schedule_delayed_work(&tp->thread, next_tick); 1636 schedule_delayed_work(&tp->thread, next_tick);
1631} 1637}
1632 1638
1633static void rtl8139_stop_thread(struct rtl8139_private *tp)
1634{
1635 if (tp->have_thread) {
1636 cancel_rearming_delayed_work(&tp->thread);
1637 tp->have_thread = 0;
1638 } else
1639 flush_scheduled_work();
1640}
1641
1642static inline void rtl8139_tx_clear (struct rtl8139_private *tp) 1639static inline void rtl8139_tx_clear (struct rtl8139_private *tp)
1643{ 1640{
1644 tp->cur_tx = 0; 1641 tp->cur_tx = 0;
@@ -1696,12 +1693,11 @@ static void rtl8139_tx_timeout (struct net_device *dev)
1696{ 1693{
1697 struct rtl8139_private *tp = netdev_priv(dev); 1694 struct rtl8139_private *tp = netdev_priv(dev);
1698 1695
1696 tp->watchdog_fired = 1;
1699 if (!tp->have_thread) { 1697 if (!tp->have_thread) {
1700 INIT_DELAYED_WORK(&tp->thread, rtl8139_tx_timeout_task); 1698 INIT_DELAYED_WORK(&tp->thread, rtl8139_thread);
1701 schedule_delayed_work(&tp->thread, next_tick); 1699 schedule_delayed_work(&tp->thread, next_tick);
1702 } else 1700 }
1703 tp->watchdog_fired = 1;
1704
1705} 1701}
1706 1702
1707static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev) 1703static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
@@ -2233,8 +2229,6 @@ static int rtl8139_close (struct net_device *dev)
2233 2229
2234 netif_stop_queue (dev); 2230 netif_stop_queue (dev);
2235 2231
2236 rtl8139_stop_thread(tp);
2237
2238 if (netif_msg_ifdown(tp)) 2232 if (netif_msg_ifdown(tp))
2239 printk(KERN_DEBUG "%s: Shutting down ethercard, status was 0x%4.4x.\n", 2233 printk(KERN_DEBUG "%s: Shutting down ethercard, status was 0x%4.4x.\n",
2240 dev->name, RTL_R16 (IntrStatus)); 2234 dev->name, RTL_R16 (IntrStatus));
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 38f41a593b..5ff0922e62 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -430,10 +430,10 @@ config HPLANCE
430 430
431config LASI_82596 431config LASI_82596
432 tristate "Lasi ethernet" 432 tristate "Lasi ethernet"
433 depends on NET_ETHERNET && PARISC && GSC_LASI 433 depends on NET_ETHERNET && GSC
434 help 434 help
435 Say Y here to support the on-board Intel 82596 ethernet controller 435 Say Y here to support the builtin Intel 82596 ethernet controller
436 built into Hewlett-Packard PA-RISC machines. 436 found in Hewlett-Packard PA-RISC machines with 10Mbit ethernet.
437 437
438config MIPS_JAZZ_SONIC 438config MIPS_JAZZ_SONIC
439 tristate "MIPS JAZZ onboard SONIC Ethernet support" 439 tristate "MIPS JAZZ onboard SONIC Ethernet support"
@@ -1284,8 +1284,8 @@ config PCNET32
1284 will be called pcnet32. 1284 will be called pcnet32.
1285 1285
1286config PCNET32_NAPI 1286config PCNET32_NAPI
1287 bool "Use RX polling (NAPI) (EXPERIMENTAL)" 1287 bool "Use RX polling (NAPI)"
1288 depends on PCNET32 && EXPERIMENTAL 1288 depends on PCNET32
1289 help 1289 help
1290 NAPI is a new driver API designed to reduce CPU and interrupt load 1290 NAPI is a new driver API designed to reduce CPU and interrupt load
1291 when the driver is receiving lots of packets from the card. It is 1291 when the driver is receiving lots of packets from the card. It is
@@ -2125,14 +2125,16 @@ config SKY2
2125 will be called sky2. This is recommended. 2125 will be called sky2. This is recommended.
2126 2126
2127config SK98LIN 2127config SK98LIN
2128 tristate "Marvell Yukon Chipset / SysKonnect SK-98xx Support" 2128 tristate "Marvell Yukon Chipset / SysKonnect SK-98xx Support (DEPRECATED)"
2129 depends on PCI 2129 depends on PCI
2130 ---help--- 2130 ---help---
2131 Say Y here if you have a Marvell Yukon or SysKonnect SK-98xx/SK-95xx 2131 Say Y here if you have a Marvell Yukon or SysKonnect SK-98xx/SK-95xx
2132 compliant Gigabit Ethernet Adapter. 2132 compliant Gigabit Ethernet Adapter.
2133 2133
2134 This driver supports the original Yukon chipset. A cleaner driver is 2134 This driver supports the original Yukon chipset. This driver is
2135 also available (skge) which seems to work better than this one. 2135 deprecated and will be removed from the kernel in the near future,
2136 it has been replaced by the skge driver. skge is cleaner and
2137 seems to work better.
2136 2138
2137 This driver does not support the newer Yukon2 chipset. A separate 2139 This driver does not support the newer Yukon2 chipset. A separate
2138 driver, sky2, is provided to support Yukon2-based adapters. 2140 driver, sky2, is provided to support Yukon2-based adapters.
@@ -2243,7 +2245,7 @@ config BNX2
2243 2245
2244config SPIDER_NET 2246config SPIDER_NET
2245 tristate "Spider Gigabit Ethernet driver" 2247 tristate "Spider Gigabit Ethernet driver"
2246 depends on PCI && PPC_IBM_CELL_BLADE 2248 depends on PCI && (PPC_IBM_CELL_BLADE || PPC_CELLEB)
2247 select FW_LOADER 2249 select FW_LOADER
2248 help 2250 help
2249 This driver supports the Gigabit Ethernet chips present on the 2251 This driver supports the Gigabit Ethernet chips present on the
@@ -2305,27 +2307,6 @@ config MV643XX_ETH
2305 chipset which is used in the Momenco Ocelot C and Jaguar ATX and 2307 chipset which is used in the Momenco Ocelot C and Jaguar ATX and
2306 Pegasos II, amongst other PPC and MIPS boards. 2308 Pegasos II, amongst other PPC and MIPS boards.
2307 2309
2308config MV643XX_ETH_0
2309 bool "MV-643XX Port 0"
2310 depends on MV643XX_ETH
2311 help
2312 This enables support for Port 0 of the Marvell MV643XX Gigabit
2313 Ethernet.
2314
2315config MV643XX_ETH_1
2316 bool "MV-643XX Port 1"
2317 depends on MV643XX_ETH
2318 help
2319 This enables support for Port 1 of the Marvell MV643XX Gigabit
2320 Ethernet.
2321
2322config MV643XX_ETH_2
2323 bool "MV-643XX Port 2"
2324 depends on MV643XX_ETH
2325 help
2326 This enables support for Port 2 of the Marvell MV643XX Gigabit
2327 Ethernet.
2328
2329config QLA3XXX 2310config QLA3XXX
2330 tristate "QLogic QLA3XXX Network Driver Support" 2311 tristate "QLogic QLA3XXX Network Driver Support"
2331 depends on PCI 2312 depends on PCI
@@ -2337,7 +2318,7 @@ config QLA3XXX
2337 2318
2338config ATL1 2319config ATL1
2339 tristate "Attansic L1 Gigabit Ethernet support (EXPERIMENTAL)" 2320 tristate "Attansic L1 Gigabit Ethernet support (EXPERIMENTAL)"
2340 depends on NET_PCI && PCI && EXPERIMENTAL 2321 depends on PCI && EXPERIMENTAL
2341 select CRC32 2322 select CRC32
2342 select MII 2323 select MII
2343 help 2324 help
diff --git a/drivers/net/acenic.c b/drivers/net/acenic.c
index 33c6645455..7138e0e025 100644
--- a/drivers/net/acenic.c
+++ b/drivers/net/acenic.c
@@ -2293,10 +2293,7 @@ static void ace_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2293 2293
2294 local_irq_save(flags); 2294 local_irq_save(flags);
2295 ace_mask_irq(dev); 2295 ace_mask_irq(dev);
2296 2296 vlan_group_set_device(ap->vlgrp, vid, NULL);
2297 if (ap->vlgrp)
2298 ap->vlgrp->vlan_devices[vid] = NULL;
2299
2300 ace_unmask_irq(dev); 2297 ace_unmask_irq(dev);
2301 local_irq_restore(flags); 2298 local_irq_restore(flags);
2302} 2299}
diff --git a/drivers/net/amd8111e.c b/drivers/net/amd8111e.c
index 9c399aaefb..962c954c2d 100644
--- a/drivers/net/amd8111e.c
+++ b/drivers/net/amd8111e.c
@@ -1737,8 +1737,7 @@ static void amd8111e_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid
1737{ 1737{
1738 struct amd8111e_priv *lp = netdev_priv(dev); 1738 struct amd8111e_priv *lp = netdev_priv(dev);
1739 spin_lock_irq(&lp->lock); 1739 spin_lock_irq(&lp->lock);
1740 if (lp->vlgrp) 1740 vlan_group_set_device(lp->vlgrp, vid, NULL);
1741 lp->vlgrp->vlan_devices[vid] = NULL;
1742 spin_unlock_irq(&lp->lock); 1741 spin_unlock_irq(&lp->lock);
1743} 1742}
1744#endif 1743#endif
diff --git a/drivers/net/arcnet/arc-rawmode.c b/drivers/net/arcnet/arc-rawmode.c
index e7555d4e6f..6318814a11 100644
--- a/drivers/net/arcnet/arc-rawmode.c
+++ b/drivers/net/arcnet/arc-rawmode.c
@@ -94,7 +94,7 @@ static void rx(struct net_device *dev, int bufnum,
94 94
95 BUGMSG(D_DURING, "it's a raw packet (length=%d)\n", length); 95 BUGMSG(D_DURING, "it's a raw packet (length=%d)\n", length);
96 96
97 if (length >= MinTU) 97 if (length > MTU)
98 ofs = 512 - length; 98 ofs = 512 - length;
99 else 99 else
100 ofs = 256 - length; 100 ofs = 256 - length;
@@ -183,7 +183,7 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
183 length, XMTU); 183 length, XMTU);
184 length = XMTU; 184 length = XMTU;
185 } 185 }
186 if (length > MinTU) { 186 if (length >= MinTU) {
187 hard->offset[0] = 0; 187 hard->offset[0] = 0;
188 hard->offset[1] = ofs = 512 - length; 188 hard->offset[1] = ofs = 512 - length;
189 } else if (length > MTU) { 189 } else if (length > MTU) {
diff --git a/drivers/net/arcnet/arcnet.c b/drivers/net/arcnet/arcnet.c
index 4e91dab1f1..83004fdab0 100644
--- a/drivers/net/arcnet/arcnet.c
+++ b/drivers/net/arcnet/arcnet.c
@@ -41,7 +41,7 @@
41 * <jojo@repas.de> 41 * <jojo@repas.de>
42 */ 42 */
43 43
44#define VERSION "arcnet: v3.93 BETA 2000/04/29 - by Avery Pennarun et al.\n" 44#define VERSION "arcnet: v3.94 BETA 2007/02/08 - by Avery Pennarun et al.\n"
45 45
46#include <linux/module.h> 46#include <linux/module.h>
47#include <linux/types.h> 47#include <linux/types.h>
diff --git a/drivers/net/arcnet/com20020-pci.c b/drivers/net/arcnet/com20020-pci.c
index 98d326b23c..b8c0fa6d40 100644
--- a/drivers/net/arcnet/com20020-pci.c
+++ b/drivers/net/arcnet/com20020-pci.c
@@ -155,6 +155,7 @@ static struct pci_device_id com20020pci_id_table[] = {
155 { 0x1571, 0xa00b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT }, 155 { 0x1571, 0xa00b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
156 { 0x1571, 0xa00c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT }, 156 { 0x1571, 0xa00c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
157 { 0x1571, 0xa00d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT }, 157 { 0x1571, 0xa00d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
158 { 0x1571, 0xa00e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
158 { 0x1571, 0xa201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT }, 159 { 0x1571, 0xa201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
159 { 0x1571, 0xa202, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT }, 160 { 0x1571, 0xa202, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
160 { 0x1571, 0xa203, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT }, 161 { 0x1571, 0xa203, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
@@ -163,6 +164,8 @@ static struct pci_device_id com20020pci_id_table[] = {
163 { 0x1571, 0xa206, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT }, 164 { 0x1571, 0xa206, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
164 { 0x10B5, 0x9030, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT }, 165 { 0x10B5, 0x9030, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
165 { 0x10B5, 0x9050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT }, 166 { 0x10B5, 0x9050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
167 { 0x14BA, 0x6000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
168 { 0x10B5, 0x2200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
166 {0,} 169 {0,}
167}; 170};
168 171
diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index 4218075c8a..7cf0a25116 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -104,7 +104,7 @@ int com20020_check(struct net_device *dev)
104 SET_SUBADR(SUB_SETUP1); 104 SET_SUBADR(SUB_SETUP1);
105 outb(lp->setup, _XREG); 105 outb(lp->setup, _XREG);
106 106
107 if (lp->card_flags & ARC_CAN_10MBIT) 107 if (lp->clockm != 0)
108 { 108 {
109 SET_SUBADR(SUB_SETUP2); 109 SET_SUBADR(SUB_SETUP2);
110 outb(lp->setup2, _XREG); 110 outb(lp->setup2, _XREG);
diff --git a/drivers/net/atl1/atl1_hw.c b/drivers/net/atl1/atl1_hw.c
index 08b2d78546..314dbaabb6 100644
--- a/drivers/net/atl1/atl1_hw.c
+++ b/drivers/net/atl1/atl1_hw.c
@@ -243,14 +243,8 @@ static int atl1_get_permanent_address(struct atl1_hw *hw)
243 i += 4; 243 i += 4;
244 } 244 }
245 245
246/* 246 *(u32 *) &eth_addr[2] = swab32(addr[0]);
247 * The following 2 lines are the Attansic originals. Saving for posterity. 247 *(u16 *) &eth_addr[0] = swab16(*(u16 *) &addr[1]);
248 * *(u32 *) & eth_addr[2] = LONGSWAP(addr[0]);
249 * *(u16 *) & eth_addr[0] = SHORTSWAP(*(u16 *) & addr[1]);
250 */
251 *(u32 *) & eth_addr[2] = swab32(addr[0]);
252 *(u16 *) & eth_addr[0] = swab16(*(u16 *) & addr[1]);
253
254 if (is_valid_ether_addr(eth_addr)) { 248 if (is_valid_ether_addr(eth_addr)) {
255 memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN); 249 memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN);
256 return 0; 250 return 0;
@@ -281,17 +275,28 @@ static int atl1_get_permanent_address(struct atl1_hw *hw)
281 i += 4; 275 i += 4;
282 } 276 }
283 277
284/* 278 *(u32 *) &eth_addr[2] = swab32(addr[0]);
285 * The following 2 lines are the Attansic originals. Saving for posterity. 279 *(u16 *) &eth_addr[0] = swab16(*(u16 *) &addr[1]);
286 * *(u32 *) & eth_addr[2] = LONGSWAP(addr[0]);
287 * *(u16 *) & eth_addr[0] = SHORTSWAP(*(u16 *) & addr[1]);
288 */
289 *(u32 *) & eth_addr[2] = swab32(addr[0]);
290 *(u16 *) & eth_addr[0] = swab16(*(u16 *) & addr[1]);
291 if (is_valid_ether_addr(eth_addr)) { 280 if (is_valid_ether_addr(eth_addr)) {
292 memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN); 281 memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN);
293 return 0; 282 return 0;
294 } 283 }
284
285 /*
286 * On some motherboards, the MAC address is written by the
287 * BIOS directly to the MAC register during POST, and is
288 * not stored in eeprom. If all else thus far has failed
289 * to fetch the permanent MAC address, try reading it directly.
290 */
291 addr[0] = ioread32(hw->hw_addr + REG_MAC_STA_ADDR);
292 addr[1] = ioread16(hw->hw_addr + (REG_MAC_STA_ADDR + 4));
293 *(u32 *) &eth_addr[2] = swab32(addr[0]);
294 *(u16 *) &eth_addr[0] = swab16(*(u16 *) &addr[1]);
295 if (is_valid_ether_addr(eth_addr)) {
296 memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN);
297 return 0;
298 }
299
295 return 1; 300 return 1;
296} 301}
297 302
@@ -357,7 +362,7 @@ void atl1_hash_set(struct atl1_hw *hw, u32 hash_value)
357 */ 362 */
358 hash_reg = (hash_value >> 31) & 0x1; 363 hash_reg = (hash_value >> 31) & 0x1;
359 hash_bit = (hash_value >> 26) & 0x1F; 364 hash_bit = (hash_value >> 26) & 0x1F;
360 mta = ioread32((hw + REG_RX_HASH_TABLE) + (hash_reg << 2)); 365 mta = ioread32((hw->hw_addr + REG_RX_HASH_TABLE) + (hash_reg << 2));
361 mta |= (1 << hash_bit); 366 mta |= (1 << hash_bit);
362 iowrite32(mta, (hw->hw_addr + REG_RX_HASH_TABLE) + (hash_reg << 2)); 367 iowrite32(mta, (hw->hw_addr + REG_RX_HASH_TABLE) + (hash_reg << 2));
363} 368}
diff --git a/drivers/net/atl1/atl1_main.c b/drivers/net/atl1/atl1_main.c
index 6655640eb4..88d4f70035 100644
--- a/drivers/net/atl1/atl1_main.c
+++ b/drivers/net/atl1/atl1_main.c
@@ -82,8 +82,7 @@
82 82
83#include "atl1.h" 83#include "atl1.h"
84 84
85#define RUN_REALTIME 0 85#define DRIVER_VERSION "2.0.7"
86#define DRIVER_VERSION "2.0.6"
87 86
88char atl1_driver_name[] = "atl1"; 87char atl1_driver_name[] = "atl1";
89static const char atl1_driver_string[] = "Attansic L1 Ethernet Network Driver"; 88static const char atl1_driver_string[] = "Attansic L1 Ethernet Network Driver";
@@ -100,7 +99,7 @@ MODULE_VERSION(DRIVER_VERSION);
100 * atl1_pci_tbl - PCI Device ID Table 99 * atl1_pci_tbl - PCI Device ID Table
101 */ 100 */
102static const struct pci_device_id atl1_pci_tbl[] = { 101static const struct pci_device_id atl1_pci_tbl[] = {
103 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, 0x1048)}, 102 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATTANSIC_L1)},
104 /* required last entry */ 103 /* required last entry */
105 {0,} 104 {0,}
106}; 105};
@@ -1253,8 +1252,7 @@ static void atl1_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1253 1252
1254 spin_lock_irqsave(&adapter->lock, flags); 1253 spin_lock_irqsave(&adapter->lock, flags);
1255 /* atl1_irq_disable(adapter); */ 1254 /* atl1_irq_disable(adapter); */
1256 if (adapter->vlgrp) 1255 vlan_group_set_device(adapter->vlgrp, vid, NULL);
1257 adapter->vlgrp->vlan_devices[vid] = NULL;
1258 /* atl1_irq_enable(adapter); */ 1256 /* atl1_irq_enable(adapter); */
1259 spin_unlock_irqrestore(&adapter->lock, flags); 1257 spin_unlock_irqrestore(&adapter->lock, flags);
1260 /* We don't do Vlan filtering */ 1258 /* We don't do Vlan filtering */
@@ -1267,7 +1265,7 @@ static void atl1_restore_vlan(struct atl1_adapter *adapter)
1267 if (adapter->vlgrp) { 1265 if (adapter->vlgrp) {
1268 u16 vid; 1266 u16 vid;
1269 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { 1267 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1270 if (!adapter->vlgrp->vlan_devices[vid]) 1268 if (!vlan_group_get_device(adapter->vlgrp, vid))
1271 continue; 1269 continue;
1272 atl1_vlan_rx_add_vid(adapter->netdev, vid); 1270 atl1_vlan_rx_add_vid(adapter->netdev, vid);
1273 } 1271 }
diff --git a/drivers/net/b44.c b/drivers/net/b44.c
index 5ff7882297..aaada57273 100644
--- a/drivers/net/b44.c
+++ b/drivers/net/b44.c
@@ -59,7 +59,6 @@
59#define B44_DEF_TX_RING_PENDING (B44_TX_RING_SIZE - 1) 59#define B44_DEF_TX_RING_PENDING (B44_TX_RING_SIZE - 1)
60#define B44_TX_RING_BYTES (sizeof(struct dma_desc) * \ 60#define B44_TX_RING_BYTES (sizeof(struct dma_desc) * \
61 B44_TX_RING_SIZE) 61 B44_TX_RING_SIZE)
62#define B44_DMA_MASK 0x3fffffff
63 62
64#define TX_RING_GAP(BP) \ 63#define TX_RING_GAP(BP) \
65 (B44_TX_RING_SIZE - (BP)->tx_pending) 64 (B44_TX_RING_SIZE - (BP)->tx_pending)
@@ -665,7 +664,7 @@ static int b44_alloc_rx_skb(struct b44 *bp, int src_idx, u32 dest_idx_unmasked)
665 /* Hardware bug work-around, the chip is unable to do PCI DMA 664 /* Hardware bug work-around, the chip is unable to do PCI DMA
666 to/from anything above 1GB :-( */ 665 to/from anything above 1GB :-( */
667 if (dma_mapping_error(mapping) || 666 if (dma_mapping_error(mapping) ||
668 mapping + RX_PKT_BUF_SZ > B44_DMA_MASK) { 667 mapping + RX_PKT_BUF_SZ > DMA_30BIT_MASK) {
669 /* Sigh... */ 668 /* Sigh... */
670 if (!dma_mapping_error(mapping)) 669 if (!dma_mapping_error(mapping))
671 pci_unmap_single(bp->pdev, mapping, RX_PKT_BUF_SZ,PCI_DMA_FROMDEVICE); 670 pci_unmap_single(bp->pdev, mapping, RX_PKT_BUF_SZ,PCI_DMA_FROMDEVICE);
@@ -677,7 +676,7 @@ static int b44_alloc_rx_skb(struct b44 *bp, int src_idx, u32 dest_idx_unmasked)
677 RX_PKT_BUF_SZ, 676 RX_PKT_BUF_SZ,
678 PCI_DMA_FROMDEVICE); 677 PCI_DMA_FROMDEVICE);
679 if (dma_mapping_error(mapping) || 678 if (dma_mapping_error(mapping) ||
680 mapping + RX_PKT_BUF_SZ > B44_DMA_MASK) { 679 mapping + RX_PKT_BUF_SZ > DMA_30BIT_MASK) {
681 if (!dma_mapping_error(mapping)) 680 if (!dma_mapping_error(mapping))
682 pci_unmap_single(bp->pdev, mapping, RX_PKT_BUF_SZ,PCI_DMA_FROMDEVICE); 681 pci_unmap_single(bp->pdev, mapping, RX_PKT_BUF_SZ,PCI_DMA_FROMDEVICE);
683 dev_kfree_skb_any(skb); 682 dev_kfree_skb_any(skb);
@@ -988,7 +987,7 @@ static int b44_start_xmit(struct sk_buff *skb, struct net_device *dev)
988 } 987 }
989 988
990 mapping = pci_map_single(bp->pdev, skb->data, len, PCI_DMA_TODEVICE); 989 mapping = pci_map_single(bp->pdev, skb->data, len, PCI_DMA_TODEVICE);
991 if (dma_mapping_error(mapping) || mapping + len > B44_DMA_MASK) { 990 if (dma_mapping_error(mapping) || mapping + len > DMA_30BIT_MASK) {
992 /* Chip can't handle DMA to/from >1GB, use bounce buffer */ 991 /* Chip can't handle DMA to/from >1GB, use bounce buffer */
993 if (!dma_mapping_error(mapping)) 992 if (!dma_mapping_error(mapping))
994 pci_unmap_single(bp->pdev, mapping, len, PCI_DMA_TODEVICE); 993 pci_unmap_single(bp->pdev, mapping, len, PCI_DMA_TODEVICE);
@@ -1000,7 +999,7 @@ static int b44_start_xmit(struct sk_buff *skb, struct net_device *dev)
1000 999
1001 mapping = pci_map_single(bp->pdev, bounce_skb->data, 1000 mapping = pci_map_single(bp->pdev, bounce_skb->data,
1002 len, PCI_DMA_TODEVICE); 1001 len, PCI_DMA_TODEVICE);
1003 if (dma_mapping_error(mapping) || mapping + len > B44_DMA_MASK) { 1002 if (dma_mapping_error(mapping) || mapping + len > DMA_30BIT_MASK) {
1004 if (!dma_mapping_error(mapping)) 1003 if (!dma_mapping_error(mapping))
1005 pci_unmap_single(bp->pdev, mapping, 1004 pci_unmap_single(bp->pdev, mapping,
1006 len, PCI_DMA_TODEVICE); 1005 len, PCI_DMA_TODEVICE);
@@ -1227,7 +1226,7 @@ static int b44_alloc_consistent(struct b44 *bp)
1227 DMA_BIDIRECTIONAL); 1226 DMA_BIDIRECTIONAL);
1228 1227
1229 if (dma_mapping_error(rx_ring_dma) || 1228 if (dma_mapping_error(rx_ring_dma) ||
1230 rx_ring_dma + size > B44_DMA_MASK) { 1229 rx_ring_dma + size > DMA_30BIT_MASK) {
1231 kfree(rx_ring); 1230 kfree(rx_ring);
1232 goto out_err; 1231 goto out_err;
1233 } 1232 }
@@ -1254,7 +1253,7 @@ static int b44_alloc_consistent(struct b44 *bp)
1254 DMA_TO_DEVICE); 1253 DMA_TO_DEVICE);
1255 1254
1256 if (dma_mapping_error(tx_ring_dma) || 1255 if (dma_mapping_error(tx_ring_dma) ||
1257 tx_ring_dma + size > B44_DMA_MASK) { 1256 tx_ring_dma + size > DMA_30BIT_MASK) {
1258 kfree(tx_ring); 1257 kfree(tx_ring);
1259 goto out_err; 1258 goto out_err;
1260 } 1259 }
@@ -1289,7 +1288,7 @@ static void b44_chip_reset(struct b44 *bp)
1289 if (ssb_is_core_up(bp)) { 1288 if (ssb_is_core_up(bp)) {
1290 bw32(bp, B44_RCV_LAZY, 0); 1289 bw32(bp, B44_RCV_LAZY, 0);
1291 bw32(bp, B44_ENET_CTRL, ENET_CTRL_DISABLE); 1290 bw32(bp, B44_ENET_CTRL, ENET_CTRL_DISABLE);
1292 b44_wait_bit(bp, B44_ENET_CTRL, ENET_CTRL_DISABLE, 100, 1); 1291 b44_wait_bit(bp, B44_ENET_CTRL, ENET_CTRL_DISABLE, 200, 1);
1293 bw32(bp, B44_DMATX_CTRL, 0); 1292 bw32(bp, B44_DMATX_CTRL, 0);
1294 bp->tx_prod = bp->tx_cons = 0; 1293 bp->tx_prod = bp->tx_cons = 0;
1295 if (br32(bp, B44_DMARX_STAT) & DMARX_STAT_EMASK) { 1294 if (br32(bp, B44_DMARX_STAT) & DMARX_STAT_EMASK) {
@@ -2151,13 +2150,13 @@ static int __devinit b44_init_one(struct pci_dev *pdev,
2151 2150
2152 pci_set_master(pdev); 2151 pci_set_master(pdev);
2153 2152
2154 err = pci_set_dma_mask(pdev, (u64) B44_DMA_MASK); 2153 err = pci_set_dma_mask(pdev, (u64) DMA_30BIT_MASK);
2155 if (err) { 2154 if (err) {
2156 dev_err(&pdev->dev, "No usable DMA configuration, aborting.\n"); 2155 dev_err(&pdev->dev, "No usable DMA configuration, aborting.\n");
2157 goto err_out_free_res; 2156 goto err_out_free_res;
2158 } 2157 }
2159 2158
2160 err = pci_set_consistent_dma_mask(pdev, (u64) B44_DMA_MASK); 2159 err = pci_set_consistent_dma_mask(pdev, (u64) DMA_30BIT_MASK);
2161 if (err) { 2160 if (err) {
2162 dev_err(&pdev->dev, "No usable DMA configuration, aborting.\n"); 2161 dev_err(&pdev->dev, "No usable DMA configuration, aborting.\n");
2163 goto err_out_free_res; 2162 goto err_out_free_res;
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 5a96d7611a..c12e5ea618 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -4467,9 +4467,7 @@ bnx2_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)
4467 struct bnx2 *bp = netdev_priv(dev); 4467 struct bnx2 *bp = netdev_priv(dev);
4468 4468
4469 bnx2_netif_stop(bp); 4469 bnx2_netif_stop(bp);
4470 4470 vlan_group_set_device(bp->vlgrp, vid, NULL);
4471 if (bp->vlgrp)
4472 bp->vlgrp->vlan_devices[vid] = NULL;
4473 bnx2_set_rx_mode(dev); 4471 bnx2_set_rx_mode(dev);
4474 4472
4475 bnx2_netif_start(bp); 4473 bnx2_netif_start(bp);
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index a7c8f98a89..e4724d874e 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -60,6 +60,7 @@
60#include <linux/errno.h> 60#include <linux/errno.h>
61#include <linux/netdevice.h> 61#include <linux/netdevice.h>
62#include <linux/inetdevice.h> 62#include <linux/inetdevice.h>
63#include <linux/igmp.h>
63#include <linux/etherdevice.h> 64#include <linux/etherdevice.h>
64#include <linux/skbuff.h> 65#include <linux/skbuff.h>
65#include <net/sock.h> 66#include <net/sock.h>
@@ -488,9 +489,9 @@ static void bond_vlan_rx_kill_vid(struct net_device *bond_dev, uint16_t vid)
488 /* Save and then restore vlan_dev in the grp array, 489 /* Save and then restore vlan_dev in the grp array,
489 * since the slave's driver might clear it. 490 * since the slave's driver might clear it.
490 */ 491 */
491 vlan_dev = bond->vlgrp->vlan_devices[vid]; 492 vlan_dev = vlan_group_get_device(bond->vlgrp, vid);
492 slave_dev->vlan_rx_kill_vid(slave_dev, vid); 493 slave_dev->vlan_rx_kill_vid(slave_dev, vid);
493 bond->vlgrp->vlan_devices[vid] = vlan_dev; 494 vlan_group_set_device(bond->vlgrp, vid, vlan_dev);
494 } 495 }
495 } 496 }
496 497
@@ -550,9 +551,9 @@ static void bond_del_vlans_from_slave(struct bonding *bond, struct net_device *s
550 /* Save and then restore vlan_dev in the grp array, 551 /* Save and then restore vlan_dev in the grp array,
551 * since the slave's driver might clear it. 552 * since the slave's driver might clear it.
552 */ 553 */
553 vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id]; 554 vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
554 slave_dev->vlan_rx_kill_vid(slave_dev, vlan->vlan_id); 555 slave_dev->vlan_rx_kill_vid(slave_dev, vlan->vlan_id);
555 bond->vlgrp->vlan_devices[vlan->vlan_id] = vlan_dev; 556 vlan_group_set_device(bond->vlgrp, vlan->vlan_id, vlan_dev);
556 } 557 }
557 558
558unreg: 559unreg:
@@ -861,6 +862,28 @@ static void bond_mc_delete(struct bonding *bond, void *addr, int alen)
861 } 862 }
862} 863}
863 864
865
866/*
867 * Retrieve the list of registered multicast addresses for the bonding
868 * device and retransmit an IGMP JOIN request to the current active
869 * slave.
870 */
871static void bond_resend_igmp_join_requests(struct bonding *bond)
872{
873 struct in_device *in_dev;
874 struct ip_mc_list *im;
875
876 rcu_read_lock();
877 in_dev = __in_dev_get_rcu(bond->dev);
878 if (in_dev) {
879 for (im = in_dev->mc_list; im; im = im->next) {
880 ip_mc_rejoin_group(im);
881 }
882 }
883
884 rcu_read_unlock();
885}
886
864/* 887/*
865 * Totally destroys the mc_list in bond 888 * Totally destroys the mc_list in bond
866 */ 889 */
@@ -874,6 +897,7 @@ static void bond_mc_list_destroy(struct bonding *bond)
874 kfree(dmi); 897 kfree(dmi);
875 dmi = bond->mc_list; 898 dmi = bond->mc_list;
876 } 899 }
900 bond->mc_list = NULL;
877} 901}
878 902
879/* 903/*
@@ -967,6 +991,7 @@ static void bond_mc_swap(struct bonding *bond, struct slave *new_active, struct
967 for (dmi = bond->dev->mc_list; dmi; dmi = dmi->next) { 991 for (dmi = bond->dev->mc_list; dmi; dmi = dmi->next) {
968 dev_mc_add(new_active->dev, dmi->dmi_addr, dmi->dmi_addrlen, 0); 992 dev_mc_add(new_active->dev, dmi->dmi_addr, dmi->dmi_addrlen, 0);
969 } 993 }
994 bond_resend_igmp_join_requests(bond);
970 } 995 }
971} 996}
972 997
@@ -2397,7 +2422,7 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
2397 vlan_id = 0; 2422 vlan_id = 0;
2398 list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list, 2423 list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
2399 vlan_list) { 2424 vlan_list) {
2400 vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id]; 2425 vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
2401 if (vlan_dev == rt->u.dst.dev) { 2426 if (vlan_dev == rt->u.dst.dev) {
2402 vlan_id = vlan->vlan_id; 2427 vlan_id = vlan->vlan_id;
2403 dprintk("basa: vlan match on %s %d\n", 2428 dprintk("basa: vlan match on %s %d\n",
@@ -2444,7 +2469,7 @@ static void bond_send_gratuitous_arp(struct bonding *bond)
2444 } 2469 }
2445 2470
2446 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { 2471 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
2447 vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id]; 2472 vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
2448 if (vlan->vlan_ip) { 2473 if (vlan->vlan_ip) {
2449 bond_arp_send(slave->dev, ARPOP_REPLY, vlan->vlan_ip, 2474 bond_arp_send(slave->dev, ARPOP_REPLY, vlan->vlan_ip,
2450 vlan->vlan_ip, vlan->vlan_id); 2475 vlan->vlan_ip, vlan->vlan_id);
@@ -3371,7 +3396,7 @@ static int bond_inetaddr_event(struct notifier_block *this, unsigned long event,
3371 3396
3372 list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list, 3397 list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
3373 vlan_list) { 3398 vlan_list) {
3374 vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id]; 3399 vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
3375 if (vlan_dev == event_dev) { 3400 if (vlan_dev == event_dev) {
3376 switch (event) { 3401 switch (event) {
3377 case NETDEV_UP: 3402 case NETDEV_UP:
@@ -3423,15 +3448,21 @@ void bond_register_arp(struct bonding *bond)
3423{ 3448{
3424 struct packet_type *pt = &bond->arp_mon_pt; 3449 struct packet_type *pt = &bond->arp_mon_pt;
3425 3450
3451 if (pt->type)
3452 return;
3453
3426 pt->type = htons(ETH_P_ARP); 3454 pt->type = htons(ETH_P_ARP);
3427 pt->dev = NULL; /*bond->dev;XXX*/ 3455 pt->dev = bond->dev;
3428 pt->func = bond_arp_rcv; 3456 pt->func = bond_arp_rcv;
3429 dev_add_pack(pt); 3457 dev_add_pack(pt);
3430} 3458}
3431 3459
3432void bond_unregister_arp(struct bonding *bond) 3460void bond_unregister_arp(struct bonding *bond)
3433{ 3461{
3434 dev_remove_pack(&bond->arp_mon_pt); 3462 struct packet_type *pt = &bond->arp_mon_pt;
3463
3464 dev_remove_pack(pt);
3465 pt->type = 0;
3435} 3466}
3436 3467
3437/*---------------------------- Hashing Policies -----------------------------*/ 3468/*---------------------------- Hashing Policies -----------------------------*/
@@ -4011,42 +4042,6 @@ out:
4011 return 0; 4042 return 0;
4012} 4043}
4013 4044
4014static void bond_activebackup_xmit_copy(struct sk_buff *skb,
4015 struct bonding *bond,
4016 struct slave *slave)
4017{
4018 struct sk_buff *skb2 = skb_copy(skb, GFP_ATOMIC);
4019 struct ethhdr *eth_data;
4020 u8 *hwaddr;
4021 int res;
4022
4023 if (!skb2) {
4024 printk(KERN_ERR DRV_NAME ": Error: "
4025 "bond_activebackup_xmit_copy(): skb_copy() failed\n");
4026 return;
4027 }
4028
4029 skb2->mac.raw = (unsigned char *)skb2->data;
4030 eth_data = eth_hdr(skb2);
4031
4032 /* Pick an appropriate source MAC address
4033 * -- use slave's perm MAC addr, unless used by bond
4034 * -- otherwise, borrow active slave's perm MAC addr
4035 * since that will not be used
4036 */
4037 hwaddr = slave->perm_hwaddr;
4038 if (!memcmp(eth_data->h_source, hwaddr, ETH_ALEN))
4039 hwaddr = bond->curr_active_slave->perm_hwaddr;
4040
4041 /* Set source MAC address appropriately */
4042 memcpy(eth_data->h_source, hwaddr, ETH_ALEN);
4043
4044 res = bond_dev_queue_xmit(bond, skb2, slave->dev);
4045 if (res)
4046 dev_kfree_skb(skb2);
4047
4048 return;
4049}
4050 4045
4051/* 4046/*
4052 * in active-backup mode, we know that bond->curr_active_slave is always valid if 4047 * in active-backup mode, we know that bond->curr_active_slave is always valid if
@@ -4067,21 +4062,6 @@ static int bond_xmit_activebackup(struct sk_buff *skb, struct net_device *bond_d
4067 if (!bond->curr_active_slave) 4062 if (!bond->curr_active_slave)
4068 goto out; 4063 goto out;
4069 4064
4070 /* Xmit IGMP frames on all slaves to ensure rapid fail-over
4071 for multicast traffic on snooping switches */
4072 if (skb->protocol == __constant_htons(ETH_P_IP) &&
4073 skb->nh.iph->protocol == IPPROTO_IGMP) {
4074 struct slave *slave, *active_slave;
4075 int i;
4076
4077 active_slave = bond->curr_active_slave;
4078 bond_for_each_slave_from_to(bond, slave, i, active_slave->next,
4079 active_slave->prev)
4080 if (IS_UP(slave->dev) &&
4081 (slave->link == BOND_LINK_UP))
4082 bond_activebackup_xmit_copy(skb, bond, slave);
4083 }
4084
4085 res = bond_dev_queue_xmit(bond, skb, bond->curr_active_slave->dev); 4065 res = bond_dev_queue_xmit(bond, skb, bond->curr_active_slave->dev);
4086 4066
4087out: 4067out:
diff --git a/drivers/net/chelsio/cxgb2.c b/drivers/net/chelsio/cxgb2.c
index 7d0f24f697..125c9b1058 100644
--- a/drivers/net/chelsio/cxgb2.c
+++ b/drivers/net/chelsio/cxgb2.c
@@ -889,8 +889,7 @@ static void vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
889 struct adapter *adapter = dev->priv; 889 struct adapter *adapter = dev->priv;
890 890
891 spin_lock_irq(&adapter->async_lock); 891 spin_lock_irq(&adapter->async_lock);
892 if (adapter->vlan_grp) 892 vlan_group_set_device(adapter->vlan_grp, vid, NULL);
893 adapter->vlan_grp->vlan_devices[vid] = NULL;
894 spin_unlock_irq(&adapter->async_lock); 893 spin_unlock_irq(&adapter->async_lock);
895} 894}
896#endif 895#endif
diff --git a/drivers/net/chelsio/sge.c b/drivers/net/chelsio/sge.c
index 89a682702f..326d4a6651 100644
--- a/drivers/net/chelsio/sge.c
+++ b/drivers/net/chelsio/sge.c
@@ -1696,6 +1696,7 @@ irqreturn_t t1_interrupt(int irq, void *cookie)
1696{ 1696{
1697 int work_done; 1697 int work_done;
1698 struct adapter *adapter = cookie; 1698 struct adapter *adapter = cookie;
1699 struct respQ *Q = &adapter->sge->respQ;
1699 1700
1700 spin_lock(&adapter->async_lock); 1701 spin_lock(&adapter->async_lock);
1701 1702
diff --git a/drivers/net/cxgb3/adapter.h b/drivers/net/cxgb3/adapter.h
index 5c97a64451..80c3d8f268 100644
--- a/drivers/net/cxgb3/adapter.h
+++ b/drivers/net/cxgb3/adapter.h
@@ -74,6 +74,11 @@ enum { /* adapter flags */
74struct rx_desc; 74struct rx_desc;
75struct rx_sw_desc; 75struct rx_sw_desc;
76 76
77struct sge_fl_page {
78 struct skb_frag_struct frag;
79 unsigned char *va;
80};
81
77struct sge_fl { /* SGE per free-buffer list state */ 82struct sge_fl { /* SGE per free-buffer list state */
78 unsigned int buf_size; /* size of each Rx buffer */ 83 unsigned int buf_size; /* size of each Rx buffer */
79 unsigned int credits; /* # of available Rx buffers */ 84 unsigned int credits; /* # of available Rx buffers */
@@ -81,11 +86,13 @@ struct sge_fl { /* SGE per free-buffer list state */
81 unsigned int cidx; /* consumer index */ 86 unsigned int cidx; /* consumer index */
82 unsigned int pidx; /* producer index */ 87 unsigned int pidx; /* producer index */
83 unsigned int gen; /* free list generation */ 88 unsigned int gen; /* free list generation */
89 unsigned int cntxt_id; /* SGE context id for the free list */
90 struct sge_fl_page page;
84 struct rx_desc *desc; /* address of HW Rx descriptor ring */ 91 struct rx_desc *desc; /* address of HW Rx descriptor ring */
85 struct rx_sw_desc *sdesc; /* address of SW Rx descriptor ring */ 92 struct rx_sw_desc *sdesc; /* address of SW Rx descriptor ring */
86 dma_addr_t phys_addr; /* physical address of HW ring start */ 93 dma_addr_t phys_addr; /* physical address of HW ring start */
87 unsigned int cntxt_id; /* SGE context id for the free list */
88 unsigned long empty; /* # of times queue ran out of buffers */ 94 unsigned long empty; /* # of times queue ran out of buffers */
95 unsigned long alloc_failed; /* # of times buffer allocation failed */
89}; 96};
90 97
91/* 98/*
@@ -121,6 +128,8 @@ struct sge_rspq { /* state for an SGE response queue */
121 unsigned long empty; /* # of times queue ran out of credits */ 128 unsigned long empty; /* # of times queue ran out of credits */
122 unsigned long nomem; /* # of responses deferred due to no mem */ 129 unsigned long nomem; /* # of responses deferred due to no mem */
123 unsigned long unhandled_irqs; /* # of spurious intrs */ 130 unsigned long unhandled_irqs; /* # of spurious intrs */
131 unsigned long starved;
132 unsigned long restarted;
124}; 133};
125 134
126struct tx_desc; 135struct tx_desc;
diff --git a/drivers/net/cxgb3/cxgb3_defs.h b/drivers/net/cxgb3/cxgb3_defs.h
index 16e004990c..e14862b43d 100644
--- a/drivers/net/cxgb3/cxgb3_defs.h
+++ b/drivers/net/cxgb3/cxgb3_defs.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006-2007 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/cxgb3_ioctl.h b/drivers/net/cxgb3/cxgb3_ioctl.h
index a94281861a..0a82fcddf2 100644
--- a/drivers/net/cxgb3/cxgb3_ioctl.h
+++ b/drivers/net/cxgb3/cxgb3_ioctl.h
@@ -36,28 +36,17 @@
36 * Ioctl commands specific to this driver. 36 * Ioctl commands specific to this driver.
37 */ 37 */
38enum { 38enum {
39 CHELSIO_SETREG = 1024, 39 CHELSIO_GETMTUTAB = 1029,
40 CHELSIO_GETREG, 40 CHELSIO_SETMTUTAB = 1030,
41 CHELSIO_SETTPI, 41 CHELSIO_SET_PM = 1032,
42 CHELSIO_GETTPI, 42 CHELSIO_GET_PM = 1033,
43 CHELSIO_GETMTUTAB, 43 CHELSIO_GET_MEM = 1038,
44 CHELSIO_SETMTUTAB, 44 CHELSIO_LOAD_FW = 1041,
45 CHELSIO_GETMTU, 45 CHELSIO_SET_TRACE_FILTER = 1044,
46 CHELSIO_SET_PM, 46 CHELSIO_SET_QSET_PARAMS = 1045,
47 CHELSIO_GET_PM, 47 CHELSIO_GET_QSET_PARAMS = 1046,
48 CHELSIO_GET_TCAM, 48 CHELSIO_SET_QSET_NUM = 1047,
49 CHELSIO_SET_TCAM, 49 CHELSIO_GET_QSET_NUM = 1048,
50 CHELSIO_GET_TCB,
51 CHELSIO_GET_MEM,
52 CHELSIO_LOAD_FW,
53 CHELSIO_GET_PROTO,
54 CHELSIO_SET_PROTO,
55 CHELSIO_SET_TRACE_FILTER,
56 CHELSIO_SET_QSET_PARAMS,
57 CHELSIO_GET_QSET_PARAMS,
58 CHELSIO_SET_QSET_NUM,
59 CHELSIO_GET_QSET_NUM,
60 CHELSIO_SET_PKTSCHED,
61}; 50};
62 51
63struct ch_reg { 52struct ch_reg {
diff --git a/drivers/net/cxgb3/cxgb3_main.c b/drivers/net/cxgb3/cxgb3_main.c
index 43583ed655..7ff834e45d 100644
--- a/drivers/net/cxgb3/cxgb3_main.c
+++ b/drivers/net/cxgb3/cxgb3_main.c
@@ -434,27 +434,25 @@ static int setup_sge_qsets(struct adapter *adap)
434 434
435static ssize_t attr_show(struct device *d, struct device_attribute *attr, 435static ssize_t attr_show(struct device *d, struct device_attribute *attr,
436 char *buf, 436 char *buf,
437 ssize_t(*format) (struct adapter *, char *)) 437 ssize_t(*format) (struct net_device *, char *))
438{ 438{
439 ssize_t len; 439 ssize_t len;
440 struct adapter *adap = to_net_dev(d)->priv;
441 440
442 /* Synchronize with ioctls that may shut down the device */ 441 /* Synchronize with ioctls that may shut down the device */
443 rtnl_lock(); 442 rtnl_lock();
444 len = (*format) (adap, buf); 443 len = (*format) (to_net_dev(d), buf);
445 rtnl_unlock(); 444 rtnl_unlock();
446 return len; 445 return len;
447} 446}
448 447
449static ssize_t attr_store(struct device *d, struct device_attribute *attr, 448static ssize_t attr_store(struct device *d, struct device_attribute *attr,
450 const char *buf, size_t len, 449 const char *buf, size_t len,
451 ssize_t(*set) (struct adapter *, unsigned int), 450 ssize_t(*set) (struct net_device *, unsigned int),
452 unsigned int min_val, unsigned int max_val) 451 unsigned int min_val, unsigned int max_val)
453{ 452{
454 char *endp; 453 char *endp;
455 ssize_t ret; 454 ssize_t ret;
456 unsigned int val; 455 unsigned int val;
457 struct adapter *adap = to_net_dev(d)->priv;
458 456
459 if (!capable(CAP_NET_ADMIN)) 457 if (!capable(CAP_NET_ADMIN))
460 return -EPERM; 458 return -EPERM;
@@ -464,7 +462,7 @@ static ssize_t attr_store(struct device *d, struct device_attribute *attr,
464 return -EINVAL; 462 return -EINVAL;
465 463
466 rtnl_lock(); 464 rtnl_lock();
467 ret = (*set) (adap, val); 465 ret = (*set) (to_net_dev(d), val);
468 if (!ret) 466 if (!ret)
469 ret = len; 467 ret = len;
470 rtnl_unlock(); 468 rtnl_unlock();
@@ -472,8 +470,9 @@ static ssize_t attr_store(struct device *d, struct device_attribute *attr,
472} 470}
473 471
474#define CXGB3_SHOW(name, val_expr) \ 472#define CXGB3_SHOW(name, val_expr) \
475static ssize_t format_##name(struct adapter *adap, char *buf) \ 473static ssize_t format_##name(struct net_device *dev, char *buf) \
476{ \ 474{ \
475 struct adapter *adap = dev->priv; \
477 return sprintf(buf, "%u\n", val_expr); \ 476 return sprintf(buf, "%u\n", val_expr); \
478} \ 477} \
479static ssize_t show_##name(struct device *d, struct device_attribute *attr, \ 478static ssize_t show_##name(struct device *d, struct device_attribute *attr, \
@@ -482,8 +481,10 @@ static ssize_t show_##name(struct device *d, struct device_attribute *attr, \
482 return attr_show(d, attr, buf, format_##name); \ 481 return attr_show(d, attr, buf, format_##name); \
483} 482}
484 483
485static ssize_t set_nfilters(struct adapter *adap, unsigned int val) 484static ssize_t set_nfilters(struct net_device *dev, unsigned int val)
486{ 485{
486 struct adapter *adap = dev->priv;
487
487 if (adap->flags & FULL_INIT_DONE) 488 if (adap->flags & FULL_INIT_DONE)
488 return -EBUSY; 489 return -EBUSY;
489 if (val && adap->params.rev == 0) 490 if (val && adap->params.rev == 0)
@@ -500,8 +501,10 @@ static ssize_t store_nfilters(struct device *d, struct device_attribute *attr,
500 return attr_store(d, attr, buf, len, set_nfilters, 0, ~0); 501 return attr_store(d, attr, buf, len, set_nfilters, 0, ~0);
501} 502}
502 503
503static ssize_t set_nservers(struct adapter *adap, unsigned int val) 504static ssize_t set_nservers(struct net_device *dev, unsigned int val)
504{ 505{
506 struct adapter *adap = dev->priv;
507
505 if (adap->flags & FULL_INIT_DONE) 508 if (adap->flags & FULL_INIT_DONE)
506 return -EBUSY; 509 return -EBUSY;
507 if (val > t3_mc5_size(&adap->mc5) - adap->params.mc5.nfilters) 510 if (val > t3_mc5_size(&adap->mc5) - adap->params.mc5.nfilters)
@@ -1549,32 +1552,6 @@ static int cxgb_extension_ioctl(struct net_device *dev, void __user *useraddr)
1549 return -EFAULT; 1552 return -EFAULT;
1550 1553
1551 switch (cmd) { 1554 switch (cmd) {
1552 case CHELSIO_SETREG:{
1553 struct ch_reg edata;
1554
1555 if (!capable(CAP_NET_ADMIN))
1556 return -EPERM;
1557 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1558 return -EFAULT;
1559 if ((edata.addr & 3) != 0
1560 || edata.addr >= adapter->mmio_len)
1561 return -EINVAL;
1562 writel(edata.val, adapter->regs + edata.addr);
1563 break;
1564 }
1565 case CHELSIO_GETREG:{
1566 struct ch_reg edata;
1567
1568 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1569 return -EFAULT;
1570 if ((edata.addr & 3) != 0
1571 || edata.addr >= adapter->mmio_len)
1572 return -EINVAL;
1573 edata.val = readl(adapter->regs + edata.addr);
1574 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1575 return -EFAULT;
1576 break;
1577 }
1578 case CHELSIO_SET_QSET_PARAMS:{ 1555 case CHELSIO_SET_QSET_PARAMS:{
1579 int i; 1556 int i;
1580 struct qset_params *q; 1557 struct qset_params *q;
@@ -1838,10 +1815,10 @@ static int cxgb_extension_ioctl(struct net_device *dev, void __user *useraddr)
1838 return -EINVAL; 1815 return -EINVAL;
1839 1816
1840 /* 1817 /*
1841 * Version scheme: 1818 * Version scheme:
1842 * bits 0..9: chip version 1819 * bits 0..9: chip version
1843 * bits 10..15: chip revision 1820 * bits 10..15: chip revision
1844 */ 1821 */
1845 t.version = 3 | (adapter->params.rev << 10); 1822 t.version = 3 | (adapter->params.rev << 10);
1846 if (copy_to_user(useraddr, &t, sizeof(t))) 1823 if (copy_to_user(useraddr, &t, sizeof(t)))
1847 return -EFAULT; 1824 return -EFAULT;
@@ -1890,20 +1867,6 @@ static int cxgb_extension_ioctl(struct net_device *dev, void __user *useraddr)
1890 t.trace_rx); 1867 t.trace_rx);
1891 break; 1868 break;
1892 } 1869 }
1893 case CHELSIO_SET_PKTSCHED:{
1894 struct ch_pktsched_params p;
1895
1896 if (!capable(CAP_NET_ADMIN))
1897 return -EPERM;
1898 if (!adapter->open_device_map)
1899 return -EAGAIN; /* uP and SGE must be running */
1900 if (copy_from_user(&p, useraddr, sizeof(p)))
1901 return -EFAULT;
1902 send_pktsched_cmd(adapter, p.sched, p.idx, p.min, p.max,
1903 p.binding);
1904 break;
1905
1906 }
1907 default: 1870 default:
1908 return -EOPNOTSUPP; 1871 return -EOPNOTSUPP;
1909 } 1872 }
diff --git a/drivers/net/cxgb3/cxgb3_offload.c b/drivers/net/cxgb3/cxgb3_offload.c
index c6b7266431..f6ed033efb 100644
--- a/drivers/net/cxgb3/cxgb3_offload.c
+++ b/drivers/net/cxgb3/cxgb3_offload.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006-2007 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
@@ -161,14 +160,16 @@ static struct net_device *get_iff_from_mac(struct adapter *adapter,
161 int i; 160 int i;
162 161
163 for_each_port(adapter, i) { 162 for_each_port(adapter, i) {
164 const struct vlan_group *grp; 163 struct vlan_group *grp;
165 struct net_device *dev = adapter->port[i]; 164 struct net_device *dev = adapter->port[i];
166 const struct port_info *p = netdev_priv(dev); 165 const struct port_info *p = netdev_priv(dev);
167 166
168 if (!memcmp(dev->dev_addr, mac, ETH_ALEN)) { 167 if (!memcmp(dev->dev_addr, mac, ETH_ALEN)) {
169 if (vlan && vlan != VLAN_VID_MASK) { 168 if (vlan && vlan != VLAN_VID_MASK) {
170 grp = p->vlan_grp; 169 grp = p->vlan_grp;
171 dev = grp ? grp->vlan_devices[vlan] : NULL; 170 dev = NULL;
171 if (grp)
172 dev = vlan_group_get_device(grp, vlan);
172 } else 173 } else
173 while (dev->master) 174 while (dev->master)
174 dev = dev->master; 175 dev = dev->master;
diff --git a/drivers/net/cxgb3/cxgb3_offload.h b/drivers/net/cxgb3/cxgb3_offload.h
index 0e6beb69ba..f15446a32e 100644
--- a/drivers/net/cxgb3/cxgb3_offload.h
+++ b/drivers/net/cxgb3/cxgb3_offload.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006-2007 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/l2t.c b/drivers/net/cxgb3/l2t.c
index 3c0cb85570..d660af7460 100644
--- a/drivers/net/cxgb3/l2t.c
+++ b/drivers/net/cxgb3/l2t.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006-2007 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/l2t.h b/drivers/net/cxgb3/l2t.h
index ba5d2cbd72..d79001336c 100644
--- a/drivers/net/cxgb3/l2t.h
+++ b/drivers/net/cxgb3/l2t.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006-2007 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/sge.c b/drivers/net/cxgb3/sge.c
index 3f2cf8a07c..c23783432e 100644
--- a/drivers/net/cxgb3/sge.c
+++ b/drivers/net/cxgb3/sge.c
@@ -45,9 +45,25 @@
45#define USE_GTS 0 45#define USE_GTS 0
46 46
47#define SGE_RX_SM_BUF_SIZE 1536 47#define SGE_RX_SM_BUF_SIZE 1536
48
49/*
50 * If USE_RX_PAGE is defined, the small freelist populated with (partial)
51 * pages instead of skbs. Pages are carved up into RX_PAGE_SIZE chunks (must
52 * be a multiple of the host page size).
53 */
54#define USE_RX_PAGE
55#define RX_PAGE_SIZE 2048
56
57/*
58 * skb freelist packets are copied into a new skb (and the freelist one is
59 * reused) if their len is <=
60 */
48#define SGE_RX_COPY_THRES 256 61#define SGE_RX_COPY_THRES 256
49 62
50# define SGE_RX_DROP_THRES 16 63/*
64 * Minimum number of freelist entries before we start dropping TUNNEL frames.
65 */
66#define SGE_RX_DROP_THRES 16
51 67
52/* 68/*
53 * Period of the Tx buffer reclaim timer. This timer does not need to run 69 * Period of the Tx buffer reclaim timer. This timer does not need to run
@@ -85,7 +101,10 @@ struct tx_sw_desc { /* SW state per Tx descriptor */
85}; 101};
86 102
87struct rx_sw_desc { /* SW state per Rx descriptor */ 103struct rx_sw_desc { /* SW state per Rx descriptor */
88 struct sk_buff *skb; 104 union {
105 struct sk_buff *skb;
106 struct sge_fl_page page;
107 } t;
89 DECLARE_PCI_UNMAP_ADDR(dma_addr); 108 DECLARE_PCI_UNMAP_ADDR(dma_addr);
90}; 109};
91 110
@@ -105,6 +124,15 @@ struct unmap_info { /* packet unmapping info, overlays skb->cb */
105}; 124};
106 125
107/* 126/*
127 * Holds unmapping information for Tx packets that need deferred unmapping.
128 * This structure lives at skb->head and must be allocated by callers.
129 */
130struct deferred_unmap_info {
131 struct pci_dev *pdev;
132 dma_addr_t addr[MAX_SKB_FRAGS + 1];
133};
134
135/*
108 * Maps a number of flits to the number of Tx descriptors that can hold them. 136 * Maps a number of flits to the number of Tx descriptors that can hold them.
109 * The formula is 137 * The formula is
110 * 138 *
@@ -252,10 +280,13 @@ static void free_tx_desc(struct adapter *adapter, struct sge_txq *q,
252 struct pci_dev *pdev = adapter->pdev; 280 struct pci_dev *pdev = adapter->pdev;
253 unsigned int cidx = q->cidx; 281 unsigned int cidx = q->cidx;
254 282
283 const int need_unmap = need_skb_unmap() &&
284 q->cntxt_id >= FW_TUNNEL_SGEEC_START;
285
255 d = &q->sdesc[cidx]; 286 d = &q->sdesc[cidx];
256 while (n--) { 287 while (n--) {
257 if (d->skb) { /* an SGL is present */ 288 if (d->skb) { /* an SGL is present */
258 if (need_skb_unmap()) 289 if (need_unmap)
259 unmap_skb(d->skb, q, cidx, pdev); 290 unmap_skb(d->skb, q, cidx, pdev);
260 if (d->skb->priority == cidx) 291 if (d->skb->priority == cidx)
261 kfree_skb(d->skb); 292 kfree_skb(d->skb);
@@ -320,16 +351,27 @@ static void free_rx_bufs(struct pci_dev *pdev, struct sge_fl *q)
320 351
321 pci_unmap_single(pdev, pci_unmap_addr(d, dma_addr), 352 pci_unmap_single(pdev, pci_unmap_addr(d, dma_addr),
322 q->buf_size, PCI_DMA_FROMDEVICE); 353 q->buf_size, PCI_DMA_FROMDEVICE);
323 kfree_skb(d->skb); 354
324 d->skb = NULL; 355 if (q->buf_size != RX_PAGE_SIZE) {
356 kfree_skb(d->t.skb);
357 d->t.skb = NULL;
358 } else {
359 if (d->t.page.frag.page)
360 put_page(d->t.page.frag.page);
361 d->t.page.frag.page = NULL;
362 }
325 if (++cidx == q->size) 363 if (++cidx == q->size)
326 cidx = 0; 364 cidx = 0;
327 } 365 }
366
367 if (q->page.frag.page)
368 put_page(q->page.frag.page);
369 q->page.frag.page = NULL;
328} 370}
329 371
330/** 372/**
331 * add_one_rx_buf - add a packet buffer to a free-buffer list 373 * add_one_rx_buf - add a packet buffer to a free-buffer list
332 * @skb: the buffer to add 374 * @va: va of the buffer to add
333 * @len: the buffer length 375 * @len: the buffer length
334 * @d: the HW Rx descriptor to write 376 * @d: the HW Rx descriptor to write
335 * @sd: the SW Rx descriptor to write 377 * @sd: the SW Rx descriptor to write
@@ -339,14 +381,13 @@ static void free_rx_bufs(struct pci_dev *pdev, struct sge_fl *q)
339 * Add a buffer of the given length to the supplied HW and SW Rx 381 * Add a buffer of the given length to the supplied HW and SW Rx
340 * descriptors. 382 * descriptors.
341 */ 383 */
342static inline void add_one_rx_buf(struct sk_buff *skb, unsigned int len, 384static inline void add_one_rx_buf(unsigned char *va, unsigned int len,
343 struct rx_desc *d, struct rx_sw_desc *sd, 385 struct rx_desc *d, struct rx_sw_desc *sd,
344 unsigned int gen, struct pci_dev *pdev) 386 unsigned int gen, struct pci_dev *pdev)
345{ 387{
346 dma_addr_t mapping; 388 dma_addr_t mapping;
347 389
348 sd->skb = skb; 390 mapping = pci_map_single(pdev, va, len, PCI_DMA_FROMDEVICE);
349 mapping = pci_map_single(pdev, skb->data, len, PCI_DMA_FROMDEVICE);
350 pci_unmap_addr_set(sd, dma_addr, mapping); 391 pci_unmap_addr_set(sd, dma_addr, mapping);
351 392
352 d->addr_lo = cpu_to_be32(mapping); 393 d->addr_lo = cpu_to_be32(mapping);
@@ -371,14 +412,47 @@ static void refill_fl(struct adapter *adap, struct sge_fl *q, int n, gfp_t gfp)
371{ 412{
372 struct rx_sw_desc *sd = &q->sdesc[q->pidx]; 413 struct rx_sw_desc *sd = &q->sdesc[q->pidx];
373 struct rx_desc *d = &q->desc[q->pidx]; 414 struct rx_desc *d = &q->desc[q->pidx];
415 struct sge_fl_page *p = &q->page;
374 416
375 while (n--) { 417 while (n--) {
376 struct sk_buff *skb = alloc_skb(q->buf_size, gfp); 418 unsigned char *va;
377 419
378 if (!skb) 420 if (unlikely(q->buf_size != RX_PAGE_SIZE)) {
379 break; 421 struct sk_buff *skb = alloc_skb(q->buf_size, gfp);
422
423 if (!skb) {
424 q->alloc_failed++;
425 break;
426 }
427 va = skb->data;
428 sd->t.skb = skb;
429 } else {
430 if (!p->frag.page) {
431 p->frag.page = alloc_pages(gfp, 0);
432 if (unlikely(!p->frag.page)) {
433 q->alloc_failed++;
434 break;
435 } else {
436 p->frag.size = RX_PAGE_SIZE;
437 p->frag.page_offset = 0;
438 p->va = page_address(p->frag.page);
439 }
440 }
441
442 memcpy(&sd->t, p, sizeof(*p));
443 va = p->va;
444
445 p->frag.page_offset += RX_PAGE_SIZE;
446 BUG_ON(p->frag.page_offset > PAGE_SIZE);
447 p->va += RX_PAGE_SIZE;
448 if (p->frag.page_offset == PAGE_SIZE)
449 p->frag.page = NULL;
450 else
451 get_page(p->frag.page);
452 }
453
454 add_one_rx_buf(va, q->buf_size, d, sd, q->gen, adap->pdev);
380 455
381 add_one_rx_buf(skb, q->buf_size, d, sd, q->gen, adap->pdev);
382 d++; 456 d++;
383 sd++; 457 sd++;
384 if (++q->pidx == q->size) { 458 if (++q->pidx == q->size) {
@@ -413,7 +487,7 @@ static void recycle_rx_buf(struct adapter *adap, struct sge_fl *q,
413 struct rx_desc *from = &q->desc[idx]; 487 struct rx_desc *from = &q->desc[idx];
414 struct rx_desc *to = &q->desc[q->pidx]; 488 struct rx_desc *to = &q->desc[q->pidx];
415 489
416 q->sdesc[q->pidx] = q->sdesc[idx]; 490 memcpy(&q->sdesc[q->pidx], &q->sdesc[idx], sizeof(struct rx_sw_desc));
417 to->addr_lo = from->addr_lo; /* already big endian */ 491 to->addr_lo = from->addr_lo; /* already big endian */
418 to->addr_hi = from->addr_hi; /* likewise */ 492 to->addr_hi = from->addr_hi; /* likewise */
419 wmb(); 493 wmb();
@@ -446,7 +520,7 @@ static void recycle_rx_buf(struct adapter *adap, struct sge_fl *q,
446 * of the SW ring. 520 * of the SW ring.
447 */ 521 */
448static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size, 522static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
449 size_t sw_size, dma_addr_t *phys, void *metadata) 523 size_t sw_size, dma_addr_t * phys, void *metadata)
450{ 524{
451 size_t len = nelem * elem_size; 525 size_t len = nelem * elem_size;
452 void *s = NULL; 526 void *s = NULL;
@@ -576,61 +650,6 @@ static inline unsigned int flits_to_desc(unsigned int n)
576} 650}
577 651
578/** 652/**
579 * get_packet - return the next ingress packet buffer from a free list
580 * @adap: the adapter that received the packet
581 * @fl: the SGE free list holding the packet
582 * @len: the packet length including any SGE padding
583 * @drop_thres: # of remaining buffers before we start dropping packets
584 *
585 * Get the next packet from a free list and complete setup of the
586 * sk_buff. If the packet is small we make a copy and recycle the
587 * original buffer, otherwise we use the original buffer itself. If a
588 * positive drop threshold is supplied packets are dropped and their
589 * buffers recycled if (a) the number of remaining buffers is under the
590 * threshold and the packet is too big to copy, or (b) the packet should
591 * be copied but there is no memory for the copy.
592 */
593static struct sk_buff *get_packet(struct adapter *adap, struct sge_fl *fl,
594 unsigned int len, unsigned int drop_thres)
595{
596 struct sk_buff *skb = NULL;
597 struct rx_sw_desc *sd = &fl->sdesc[fl->cidx];
598
599 prefetch(sd->skb->data);
600
601 if (len <= SGE_RX_COPY_THRES) {
602 skb = alloc_skb(len, GFP_ATOMIC);
603 if (likely(skb != NULL)) {
604 __skb_put(skb, len);
605 pci_dma_sync_single_for_cpu(adap->pdev,
606 pci_unmap_addr(sd,
607 dma_addr),
608 len, PCI_DMA_FROMDEVICE);
609 memcpy(skb->data, sd->skb->data, len);
610 pci_dma_sync_single_for_device(adap->pdev,
611 pci_unmap_addr(sd,
612 dma_addr),
613 len, PCI_DMA_FROMDEVICE);
614 } else if (!drop_thres)
615 goto use_orig_buf;
616 recycle:
617 recycle_rx_buf(adap, fl, fl->cidx);
618 return skb;
619 }
620
621 if (unlikely(fl->credits < drop_thres))
622 goto recycle;
623
624 use_orig_buf:
625 pci_unmap_single(adap->pdev, pci_unmap_addr(sd, dma_addr),
626 fl->buf_size, PCI_DMA_FROMDEVICE);
627 skb = sd->skb;
628 skb_put(skb, len);
629 __refill_fl(adap, fl);
630 return skb;
631}
632
633/**
634 * get_imm_packet - return the next ingress packet buffer from a response 653 * get_imm_packet - return the next ingress packet buffer from a response
635 * @resp: the response descriptor containing the packet data 654 * @resp: the response descriptor containing the packet data
636 * 655 *
@@ -1227,6 +1246,50 @@ int t3_mgmt_tx(struct adapter *adap, struct sk_buff *skb)
1227} 1246}
1228 1247
1229/** 1248/**
1249 * deferred_unmap_destructor - unmap a packet when it is freed
1250 * @skb: the packet
1251 *
1252 * This is the packet destructor used for Tx packets that need to remain
1253 * mapped until they are freed rather than until their Tx descriptors are
1254 * freed.
1255 */
1256static void deferred_unmap_destructor(struct sk_buff *skb)
1257{
1258 int i;
1259 const dma_addr_t *p;
1260 const struct skb_shared_info *si;
1261 const struct deferred_unmap_info *dui;
1262 const struct unmap_info *ui = (struct unmap_info *)skb->cb;
1263
1264 dui = (struct deferred_unmap_info *)skb->head;
1265 p = dui->addr;
1266
1267 if (ui->len)
1268 pci_unmap_single(dui->pdev, *p++, ui->len, PCI_DMA_TODEVICE);
1269
1270 si = skb_shinfo(skb);
1271 for (i = 0; i < si->nr_frags; i++)
1272 pci_unmap_page(dui->pdev, *p++, si->frags[i].size,
1273 PCI_DMA_TODEVICE);
1274}
1275
1276static void setup_deferred_unmapping(struct sk_buff *skb, struct pci_dev *pdev,
1277 const struct sg_ent *sgl, int sgl_flits)
1278{
1279 dma_addr_t *p;
1280 struct deferred_unmap_info *dui;
1281
1282 dui = (struct deferred_unmap_info *)skb->head;
1283 dui->pdev = pdev;
1284 for (p = dui->addr; sgl_flits >= 3; sgl++, sgl_flits -= 3) {
1285 *p++ = be64_to_cpu(sgl->addr[0]);
1286 *p++ = be64_to_cpu(sgl->addr[1]);
1287 }
1288 if (sgl_flits)
1289 *p = be64_to_cpu(sgl->addr[0]);
1290}
1291
1292/**
1230 * write_ofld_wr - write an offload work request 1293 * write_ofld_wr - write an offload work request
1231 * @adap: the adapter 1294 * @adap: the adapter
1232 * @skb: the packet to send 1295 * @skb: the packet to send
@@ -1262,8 +1325,11 @@ static void write_ofld_wr(struct adapter *adap, struct sk_buff *skb,
1262 sgp = ndesc == 1 ? (struct sg_ent *)&d->flit[flits] : sgl; 1325 sgp = ndesc == 1 ? (struct sg_ent *)&d->flit[flits] : sgl;
1263 sgl_flits = make_sgl(skb, sgp, skb->h.raw, skb->tail - skb->h.raw, 1326 sgl_flits = make_sgl(skb, sgp, skb->h.raw, skb->tail - skb->h.raw,
1264 adap->pdev); 1327 adap->pdev);
1265 if (need_skb_unmap()) 1328 if (need_skb_unmap()) {
1329 setup_deferred_unmapping(skb, adap->pdev, sgp, sgl_flits);
1330 skb->destructor = deferred_unmap_destructor;
1266 ((struct unmap_info *)skb->cb)->len = skb->tail - skb->h.raw; 1331 ((struct unmap_info *)skb->cb)->len = skb->tail - skb->h.raw;
1332 }
1267 1333
1268 write_wr_hdr_sgl(ndesc, skb, d, pidx, q, sgl, flits, sgl_flits, 1334 write_wr_hdr_sgl(ndesc, skb, d, pidx, q, sgl, flits, sgl_flits,
1269 gen, from->wr_hi, from->wr_lo); 1335 gen, from->wr_hi, from->wr_lo);
@@ -1617,7 +1683,6 @@ static void rx_eth(struct adapter *adap, struct sge_rspq *rq,
1617 struct cpl_rx_pkt *p = (struct cpl_rx_pkt *)(skb->data + pad); 1683 struct cpl_rx_pkt *p = (struct cpl_rx_pkt *)(skb->data + pad);
1618 struct port_info *pi; 1684 struct port_info *pi;
1619 1685
1620 rq->eth_pkts++;
1621 skb_pull(skb, sizeof(*p) + pad); 1686 skb_pull(skb, sizeof(*p) + pad);
1622 skb->dev = adap->port[p->iff]; 1687 skb->dev = adap->port[p->iff];
1623 skb->dev->last_rx = jiffies; 1688 skb->dev->last_rx = jiffies;
@@ -1645,6 +1710,85 @@ static void rx_eth(struct adapter *adap, struct sge_rspq *rq,
1645 netif_rx(skb); 1710 netif_rx(skb);
1646} 1711}
1647 1712
1713#define SKB_DATA_SIZE 128
1714
1715static void skb_data_init(struct sk_buff *skb, struct sge_fl_page *p,
1716 unsigned int len)
1717{
1718 skb->len = len;
1719 if (len <= SKB_DATA_SIZE) {
1720 memcpy(skb->data, p->va, len);
1721 skb->tail += len;
1722 put_page(p->frag.page);
1723 } else {
1724 memcpy(skb->data, p->va, SKB_DATA_SIZE);
1725 skb_shinfo(skb)->frags[0].page = p->frag.page;
1726 skb_shinfo(skb)->frags[0].page_offset =
1727 p->frag.page_offset + SKB_DATA_SIZE;
1728 skb_shinfo(skb)->frags[0].size = len - SKB_DATA_SIZE;
1729 skb_shinfo(skb)->nr_frags = 1;
1730 skb->data_len = len - SKB_DATA_SIZE;
1731 skb->tail += SKB_DATA_SIZE;
1732 skb->truesize += skb->data_len;
1733 }
1734}
1735
1736/**
1737* get_packet - return the next ingress packet buffer from a free list
1738* @adap: the adapter that received the packet
1739* @fl: the SGE free list holding the packet
1740* @len: the packet length including any SGE padding
1741* @drop_thres: # of remaining buffers before we start dropping packets
1742*
1743* Get the next packet from a free list and complete setup of the
1744* sk_buff. If the packet is small we make a copy and recycle the
1745* original buffer, otherwise we use the original buffer itself. If a
1746* positive drop threshold is supplied packets are dropped and their
1747* buffers recycled if (a) the number of remaining buffers is under the
1748* threshold and the packet is too big to copy, or (b) the packet should
1749* be copied but there is no memory for the copy.
1750*/
1751static struct sk_buff *get_packet(struct adapter *adap, struct sge_fl *fl,
1752 unsigned int len, unsigned int drop_thres)
1753{
1754 struct sk_buff *skb = NULL;
1755 struct rx_sw_desc *sd = &fl->sdesc[fl->cidx];
1756
1757 prefetch(sd->t.skb->data);
1758
1759 if (len <= SGE_RX_COPY_THRES) {
1760 skb = alloc_skb(len, GFP_ATOMIC);
1761 if (likely(skb != NULL)) {
1762 struct rx_desc *d = &fl->desc[fl->cidx];
1763 dma_addr_t mapping =
1764 (dma_addr_t)((u64) be32_to_cpu(d->addr_hi) << 32 |
1765 be32_to_cpu(d->addr_lo));
1766
1767 __skb_put(skb, len);
1768 pci_dma_sync_single_for_cpu(adap->pdev, mapping, len,
1769 PCI_DMA_FROMDEVICE);
1770 memcpy(skb->data, sd->t.skb->data, len);
1771 pci_dma_sync_single_for_device(adap->pdev, mapping, len,
1772 PCI_DMA_FROMDEVICE);
1773 } else if (!drop_thres)
1774 goto use_orig_buf;
1775recycle:
1776 recycle_rx_buf(adap, fl, fl->cidx);
1777 return skb;
1778 }
1779
1780 if (unlikely(fl->credits < drop_thres))
1781 goto recycle;
1782
1783use_orig_buf:
1784 pci_unmap_single(adap->pdev, pci_unmap_addr(sd, dma_addr),
1785 fl->buf_size, PCI_DMA_FROMDEVICE);
1786 skb = sd->t.skb;
1787 skb_put(skb, len);
1788 __refill_fl(adap, fl);
1789 return skb;
1790}
1791
1648/** 1792/**
1649 * handle_rsp_cntrl_info - handles control information in a response 1793 * handle_rsp_cntrl_info - handles control information in a response
1650 * @qs: the queue set corresponding to the response 1794 * @qs: the queue set corresponding to the response
@@ -1767,7 +1911,7 @@ static int process_responses(struct adapter *adap, struct sge_qset *qs,
1767 q->next_holdoff = q->holdoff_tmr; 1911 q->next_holdoff = q->holdoff_tmr;
1768 1912
1769 while (likely(budget_left && is_new_response(r, q))) { 1913 while (likely(budget_left && is_new_response(r, q))) {
1770 int eth, ethpad = 0; 1914 int eth, ethpad = 2;
1771 struct sk_buff *skb = NULL; 1915 struct sk_buff *skb = NULL;
1772 u32 len, flags = ntohl(r->flags); 1916 u32 len, flags = ntohl(r->flags);
1773 u32 rss_hi = *(const u32 *)r, rss_lo = r->rss_hdr.rss_hash_val; 1917 u32 rss_hi = *(const u32 *)r, rss_lo = r->rss_hdr.rss_hash_val;
@@ -1794,18 +1938,56 @@ static int process_responses(struct adapter *adap, struct sge_qset *qs,
1794 break; 1938 break;
1795 } 1939 }
1796 q->imm_data++; 1940 q->imm_data++;
1941 ethpad = 0;
1797 } else if ((len = ntohl(r->len_cq)) != 0) { 1942 } else if ((len = ntohl(r->len_cq)) != 0) {
1798 struct sge_fl *fl; 1943 struct sge_fl *fl =
1944 (len & F_RSPD_FLQ) ? &qs->fl[1] : &qs->fl[0];
1945
1946 if (fl->buf_size == RX_PAGE_SIZE) {
1947 struct rx_sw_desc *sd = &fl->sdesc[fl->cidx];
1948 struct sge_fl_page *p = &sd->t.page;
1949
1950 prefetch(p->va);
1951 prefetch(p->va + L1_CACHE_BYTES);
1952
1953 __refill_fl(adap, fl);
1954
1955 pci_unmap_single(adap->pdev,
1956 pci_unmap_addr(sd, dma_addr),
1957 fl->buf_size,
1958 PCI_DMA_FROMDEVICE);
1959
1960 if (eth) {
1961 if (unlikely(fl->credits <
1962 SGE_RX_DROP_THRES))
1963 goto eth_recycle;
1964
1965 skb = alloc_skb(SKB_DATA_SIZE,
1966 GFP_ATOMIC);
1967 if (unlikely(!skb)) {
1968eth_recycle:
1969 q->rx_drops++;
1970 recycle_rx_buf(adap, fl,
1971 fl->cidx);
1972 goto eth_done;
1973 }
1974 } else {
1975 skb = alloc_skb(SKB_DATA_SIZE,
1976 GFP_ATOMIC);
1977 if (unlikely(!skb))
1978 goto no_mem;
1979 }
1980
1981 skb_data_init(skb, p, G_RSPD_LEN(len));
1982eth_done:
1983 fl->credits--;
1984 q->eth_pkts++;
1985 } else {
1986 fl->credits--;
1987 skb = get_packet(adap, fl, G_RSPD_LEN(len),
1988 eth ? SGE_RX_DROP_THRES : 0);
1989 }
1799 1990
1800 fl = (len & F_RSPD_FLQ) ? &qs->fl[1] : &qs->fl[0];
1801 fl->credits--;
1802 skb = get_packet(adap, fl, G_RSPD_LEN(len),
1803 eth ? SGE_RX_DROP_THRES : 0);
1804 if (!skb)
1805 q->rx_drops++;
1806 else if (r->rss_hdr.opcode == CPL_TRACE_PKT)
1807 __skb_pull(skb, 2);
1808 ethpad = 2;
1809 if (++fl->cidx == fl->size) 1991 if (++fl->cidx == fl->size)
1810 fl->cidx = 0; 1992 fl->cidx = 0;
1811 } else 1993 } else
@@ -1829,18 +2011,23 @@ static int process_responses(struct adapter *adap, struct sge_qset *qs,
1829 q->credits = 0; 2011 q->credits = 0;
1830 } 2012 }
1831 2013
1832 if (likely(skb != NULL)) { 2014 if (skb) {
2015 /* Preserve the RSS info in csum & priority */
2016 skb->csum = rss_hi;
2017 skb->priority = rss_lo;
2018
1833 if (eth) 2019 if (eth)
1834 rx_eth(adap, q, skb, ethpad); 2020 rx_eth(adap, q, skb, ethpad);
1835 else { 2021 else {
1836 /* Preserve the RSS info in csum & priority */ 2022 if (unlikely(r->rss_hdr.opcode ==
1837 skb->csum = rss_hi; 2023 CPL_TRACE_PKT))
1838 skb->priority = rss_lo; 2024 __skb_pull(skb, ethpad);
1839 ngathered = rx_offload(&adap->tdev, q, skb, 2025
1840 offload_skbs, ngathered); 2026 ngathered = rx_offload(&adap->tdev, q,
2027 skb, offload_skbs,
2028 ngathered);
1841 } 2029 }
1842 } 2030 }
1843
1844 --budget_left; 2031 --budget_left;
1845 } 2032 }
1846 2033
@@ -2320,10 +2507,23 @@ static void sge_timer_cb(unsigned long data)
2320 &adap->sge.qs[0].rspq.lock; 2507 &adap->sge.qs[0].rspq.lock;
2321 if (spin_trylock_irq(lock)) { 2508 if (spin_trylock_irq(lock)) {
2322 if (!napi_is_scheduled(qs->netdev)) { 2509 if (!napi_is_scheduled(qs->netdev)) {
2510 u32 status = t3_read_reg(adap, A_SG_RSPQ_FL_STATUS);
2511
2323 if (qs->fl[0].credits < qs->fl[0].size) 2512 if (qs->fl[0].credits < qs->fl[0].size)
2324 __refill_fl(adap, &qs->fl[0]); 2513 __refill_fl(adap, &qs->fl[0]);
2325 if (qs->fl[1].credits < qs->fl[1].size) 2514 if (qs->fl[1].credits < qs->fl[1].size)
2326 __refill_fl(adap, &qs->fl[1]); 2515 __refill_fl(adap, &qs->fl[1]);
2516
2517 if (status & (1 << qs->rspq.cntxt_id)) {
2518 qs->rspq.starved++;
2519 if (qs->rspq.credits) {
2520 refill_rspq(adap, &qs->rspq, 1);
2521 qs->rspq.credits--;
2522 qs->rspq.restarted++;
2523 t3_write_reg(adap, A_SG_RSPQ_FL_STATUS,
2524 1 << qs->rspq.cntxt_id);
2525 }
2526 }
2327 } 2527 }
2328 spin_unlock_irq(lock); 2528 spin_unlock_irq(lock);
2329 } 2529 }
@@ -2432,13 +2632,21 @@ int t3_sge_alloc_qset(struct adapter *adapter, unsigned int id, int nports,
2432 flits_to_desc(sgl_len(MAX_SKB_FRAGS + 1) + 3); 2632 flits_to_desc(sgl_len(MAX_SKB_FRAGS + 1) + 3);
2433 2633
2434 if (ntxq == 1) { 2634 if (ntxq == 1) {
2635#ifdef USE_RX_PAGE
2636 q->fl[0].buf_size = RX_PAGE_SIZE;
2637#else
2435 q->fl[0].buf_size = SGE_RX_SM_BUF_SIZE + 2 + 2638 q->fl[0].buf_size = SGE_RX_SM_BUF_SIZE + 2 +
2436 sizeof(struct cpl_rx_pkt); 2639 sizeof(struct cpl_rx_pkt);
2640#endif
2437 q->fl[1].buf_size = MAX_FRAME_SIZE + 2 + 2641 q->fl[1].buf_size = MAX_FRAME_SIZE + 2 +
2438 sizeof(struct cpl_rx_pkt); 2642 sizeof(struct cpl_rx_pkt);
2439 } else { 2643 } else {
2644#ifdef USE_RX_PAGE
2645 q->fl[0].buf_size = RX_PAGE_SIZE;
2646#else
2440 q->fl[0].buf_size = SGE_RX_SM_BUF_SIZE + 2647 q->fl[0].buf_size = SGE_RX_SM_BUF_SIZE +
2441 sizeof(struct cpl_rx_data); 2648 sizeof(struct cpl_rx_data);
2649#endif
2442 q->fl[1].buf_size = (16 * 1024) - 2650 q->fl[1].buf_size = (16 * 1024) -
2443 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); 2651 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2444 } 2652 }
@@ -2632,7 +2840,7 @@ void __devinit t3_sge_prep(struct adapter *adap, struct sge_params *p)
2632 q->polling = adap->params.rev > 0; 2840 q->polling = adap->params.rev > 0;
2633 q->coalesce_usecs = 5; 2841 q->coalesce_usecs = 5;
2634 q->rspq_size = 1024; 2842 q->rspq_size = 1024;
2635 q->fl_size = 4096; 2843 q->fl_size = 1024;
2636 q->jumbo_size = 512; 2844 q->jumbo_size = 512;
2637 q->txq_size[TXQ_ETH] = 1024; 2845 q->txq_size[TXQ_ETH] = 1024;
2638 q->txq_size[TXQ_OFLD] = 1024; 2846 q->txq_size[TXQ_OFLD] = 1024;
diff --git a/drivers/net/cxgb3/t3_hw.c b/drivers/net/cxgb3/t3_hw.c
index 365a7f5b1f..eaa7a2e89a 100644
--- a/drivers/net/cxgb3/t3_hw.c
+++ b/drivers/net/cxgb3/t3_hw.c
@@ -884,11 +884,13 @@ int t3_check_fw_version(struct adapter *adapter)
884 major = G_FW_VERSION_MAJOR(vers); 884 major = G_FW_VERSION_MAJOR(vers);
885 minor = G_FW_VERSION_MINOR(vers); 885 minor = G_FW_VERSION_MINOR(vers);
886 886
887 if (type == FW_VERSION_T3 && major == 3 && minor == 1) 887 if (type == FW_VERSION_T3 && major == FW_VERSION_MAJOR &&
888 minor == FW_VERSION_MINOR)
888 return 0; 889 return 0;
889 890
890 CH_ERR(adapter, "found wrong FW version(%u.%u), " 891 CH_ERR(adapter, "found wrong FW version(%u.%u), "
891 "driver needs version 3.1\n", major, minor); 892 "driver needs version %u.%u\n", major, minor,
893 FW_VERSION_MAJOR, FW_VERSION_MINOR);
892 return -EINVAL; 894 return -EINVAL;
893} 895}
894 896
diff --git a/drivers/net/cxgb3/t3cdev.h b/drivers/net/cxgb3/t3cdev.h
index 9af3bcd64b..fa4099bc04 100644
--- a/drivers/net/cxgb3/t3cdev.h
+++ b/drivers/net/cxgb3/t3cdev.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (C) 2006-2007 Chelsio Communications. All rights reserved. 2 * Copyright (C) 2006-2007 Chelsio Communications. All rights reserved.
3 * Copyright (C) 2006-2007 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/version.h b/drivers/net/cxgb3/version.h
index 2b67dd523c..82278f8502 100644
--- a/drivers/net/cxgb3/version.h
+++ b/drivers/net/cxgb3/version.h
@@ -35,5 +35,7 @@
35#define DRV_DESC "Chelsio T3 Network Driver" 35#define DRV_DESC "Chelsio T3 Network Driver"
36#define DRV_NAME "cxgb3" 36#define DRV_NAME "cxgb3"
37/* Driver version */ 37/* Driver version */
38#define DRV_VERSION "1.0" 38#define DRV_VERSION "1.0-ko"
39#define FW_VERSION_MAJOR 3
40#define FW_VERSION_MINOR 2
39#endif /* __CHELSIO_VERSION_H */ 41#endif /* __CHELSIO_VERSION_H */
diff --git a/drivers/net/de600.c b/drivers/net/de600.c
index 8396e411f1..e547ce14ee 100644
--- a/drivers/net/de600.c
+++ b/drivers/net/de600.c
@@ -38,12 +38,6 @@ static const char version[] = "de600.c: $Revision: 1.41-2.5 $, Bjorn Ekwall (bj
38/* Add more time here if your adapter won't work OK: */ 38/* Add more time here if your adapter won't work OK: */
39#define DE600_SLOW_DOWN udelay(delay_time) 39#define DE600_SLOW_DOWN udelay(delay_time)
40 40
41 /*
42 * If you still have trouble reading/writing to the adapter,
43 * modify the following "#define": (see <asm/io.h> for more info)
44#define REALLY_SLOW_IO
45 */
46
47/* use 0 for production, 1 for verification, >2 for debug */ 41/* use 0 for production, 1 for verification, >2 for debug */
48#ifdef DE600_DEBUG 42#ifdef DE600_DEBUG
49#define PRINTK(x) if (de600_debug >= 2) printk x 43#define PRINTK(x) if (de600_debug >= 2) printk x
diff --git a/drivers/net/e1000/e1000.h b/drivers/net/e1000/e1000.h
index 689f158a46..dd4b728ac4 100644
--- a/drivers/net/e1000/e1000.h
+++ b/drivers/net/e1000/e1000.h
@@ -337,7 +337,6 @@ struct e1000_adapter {
337 struct e1000_rx_ring test_rx_ring; 337 struct e1000_rx_ring test_rx_ring;
338 338
339 339
340 uint32_t *config_space;
341 int msg_enable; 340 int msg_enable;
342#ifdef CONFIG_PCI_MSI 341#ifdef CONFIG_PCI_MSI
343 boolean_t have_msi; 342 boolean_t have_msi;
diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c
index 44ebc72962..6777887295 100644
--- a/drivers/net/e1000/e1000_ethtool.c
+++ b/drivers/net/e1000/e1000_ethtool.c
@@ -166,7 +166,7 @@ e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
166 ecmd->transceiver = XCVR_EXTERNAL; 166 ecmd->transceiver = XCVR_EXTERNAL;
167 } 167 }
168 168
169 if (netif_carrier_ok(adapter->netdev)) { 169 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU) {
170 170
171 e1000_get_speed_and_duplex(hw, &adapter->link_speed, 171 e1000_get_speed_and_duplex(hw, &adapter->link_speed,
172 &adapter->link_duplex); 172 &adapter->link_duplex);
diff --git a/drivers/net/e1000/e1000_hw.h b/drivers/net/e1000/e1000_hw.h
index d671058833..bd000b802e 100644
--- a/drivers/net/e1000/e1000_hw.h
+++ b/drivers/net/e1000/e1000_hw.h
@@ -3253,7 +3253,7 @@ struct e1000_host_command_info {
3253#define IFE_PMC_AUTO_MDIX 0x0080 /* 1=enable MDI/MDI-X feature, default 0=disabled */ 3253#define IFE_PMC_AUTO_MDIX 0x0080 /* 1=enable MDI/MDI-X feature, default 0=disabled */
3254#define IFE_PMC_FORCE_MDIX 0x0040 /* 1=force MDIX-X, 0=force MDI */ 3254#define IFE_PMC_FORCE_MDIX 0x0040 /* 1=force MDIX-X, 0=force MDI */
3255#define IFE_PMC_MDIX_STATUS 0x0020 /* 1=MDI-X, 0=MDI */ 3255#define IFE_PMC_MDIX_STATUS 0x0020 /* 1=MDI-X, 0=MDI */
3256#define IFE_PMC_AUTO_MDIX_COMPLETE 0x0010 /* Resolution algorthm is completed */ 3256#define IFE_PMC_AUTO_MDIX_COMPLETE 0x0010 /* Resolution algorithm is completed */
3257#define IFE_PMC_MDIX_MODE_SHIFT 6 3257#define IFE_PMC_MDIX_MODE_SHIFT 6
3258#define IFE_PHC_MDIX_RESET_ALL_MASK 0x0000 /* Disable auto MDI-X */ 3258#define IFE_PHC_MDIX_RESET_ALL_MASK 0x0000 /* Disable auto MDI-X */
3259 3259
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index 619c89218b..1d08e937af 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -376,7 +376,7 @@ e1000_update_mng_vlan(struct e1000_adapter *adapter)
376 uint16_t vid = adapter->hw.mng_cookie.vlan_id; 376 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
377 uint16_t old_vid = adapter->mng_vlan_id; 377 uint16_t old_vid = adapter->mng_vlan_id;
378 if (adapter->vlgrp) { 378 if (adapter->vlgrp) {
379 if (!adapter->vlgrp->vlan_devices[vid]) { 379 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
380 if (adapter->hw.mng_cookie.status & 380 if (adapter->hw.mng_cookie.status &
381 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) { 381 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
382 e1000_vlan_rx_add_vid(netdev, vid); 382 e1000_vlan_rx_add_vid(netdev, vid);
@@ -386,7 +386,7 @@ e1000_update_mng_vlan(struct e1000_adapter *adapter)
386 386
387 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) && 387 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
388 (vid != old_vid) && 388 (vid != old_vid) &&
389 !adapter->vlgrp->vlan_devices[old_vid]) 389 !vlan_group_get_device(adapter->vlgrp, old_vid))
390 e1000_vlan_rx_kill_vid(netdev, old_vid); 390 e1000_vlan_rx_kill_vid(netdev, old_vid);
391 } else 391 } else
392 adapter->mng_vlan_id = vid; 392 adapter->mng_vlan_id = vid;
@@ -1482,7 +1482,7 @@ e1000_close(struct net_device *netdev)
1482 if ((adapter->hw.mng_cookie.status & 1482 if ((adapter->hw.mng_cookie.status &
1483 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && 1483 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1484 !(adapter->vlgrp && 1484 !(adapter->vlgrp &&
1485 adapter->vlgrp->vlan_devices[adapter->mng_vlan_id])) { 1485 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
1486 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); 1486 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1487 } 1487 }
1488 1488
@@ -4998,10 +4998,7 @@ e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4998 uint32_t vfta, index; 4998 uint32_t vfta, index;
4999 4999
5000 e1000_irq_disable(adapter); 5000 e1000_irq_disable(adapter);
5001 5001 vlan_group_set_device(adapter->vlgrp, vid, NULL);
5002 if (adapter->vlgrp)
5003 adapter->vlgrp->vlan_devices[vid] = NULL;
5004
5005 e1000_irq_enable(adapter); 5002 e1000_irq_enable(adapter);
5006 5003
5007 if ((adapter->hw.mng_cookie.status & 5004 if ((adapter->hw.mng_cookie.status &
@@ -5027,7 +5024,7 @@ e1000_restore_vlan(struct e1000_adapter *adapter)
5027 if (adapter->vlgrp) { 5024 if (adapter->vlgrp) {
5028 uint16_t vid; 5025 uint16_t vid;
5029 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { 5026 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
5030 if (!adapter->vlgrp->vlan_devices[vid]) 5027 if (!vlan_group_get_device(adapter->vlgrp, vid))
5031 continue; 5028 continue;
5032 e1000_vlan_rx_add_vid(adapter->netdev, vid); 5029 e1000_vlan_rx_add_vid(adapter->netdev, vid);
5033 } 5030 }
@@ -5071,58 +5068,6 @@ e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
5071 return 0; 5068 return 0;
5072} 5069}
5073 5070
5074#ifdef CONFIG_PM
5075/* Save/restore 16 or 64 dwords of PCI config space depending on which
5076 * bus we're on (PCI(X) vs. PCI-E)
5077 */
5078#define PCIE_CONFIG_SPACE_LEN 256
5079#define PCI_CONFIG_SPACE_LEN 64
5080static int
5081e1000_pci_save_state(struct e1000_adapter *adapter)
5082{
5083 struct pci_dev *dev = adapter->pdev;
5084 int size;
5085 int i;
5086
5087 if (adapter->hw.mac_type >= e1000_82571)
5088 size = PCIE_CONFIG_SPACE_LEN;
5089 else
5090 size = PCI_CONFIG_SPACE_LEN;
5091
5092 WARN_ON(adapter->config_space != NULL);
5093
5094 adapter->config_space = kmalloc(size, GFP_KERNEL);
5095 if (!adapter->config_space) {
5096 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
5097 return -ENOMEM;
5098 }
5099 for (i = 0; i < (size / 4); i++)
5100 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
5101 return 0;
5102}
5103
5104static void
5105e1000_pci_restore_state(struct e1000_adapter *adapter)
5106{
5107 struct pci_dev *dev = adapter->pdev;
5108 int size;
5109 int i;
5110
5111 if (adapter->config_space == NULL)
5112 return;
5113
5114 if (adapter->hw.mac_type >= e1000_82571)
5115 size = PCIE_CONFIG_SPACE_LEN;
5116 else
5117 size = PCI_CONFIG_SPACE_LEN;
5118 for (i = 0; i < (size / 4); i++)
5119 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
5120 kfree(adapter->config_space);
5121 adapter->config_space = NULL;
5122 return;
5123}
5124#endif /* CONFIG_PM */
5125
5126static int 5071static int
5127e1000_suspend(struct pci_dev *pdev, pm_message_t state) 5072e1000_suspend(struct pci_dev *pdev, pm_message_t state)
5128{ 5073{
@@ -5142,9 +5087,7 @@ e1000_suspend(struct pci_dev *pdev, pm_message_t state)
5142 } 5087 }
5143 5088
5144#ifdef CONFIG_PM 5089#ifdef CONFIG_PM
5145 /* Implement our own version of pci_save_state(pdev) because pci- 5090 retval = pci_save_state(pdev);
5146 * express adapters have 256-byte config spaces. */
5147 retval = e1000_pci_save_state(adapter);
5148 if (retval) 5091 if (retval)
5149 return retval; 5092 return retval;
5150#endif 5093#endif
@@ -5231,7 +5174,7 @@ e1000_resume(struct pci_dev *pdev)
5231 uint32_t err; 5174 uint32_t err;
5232 5175
5233 pci_set_power_state(pdev, PCI_D0); 5176 pci_set_power_state(pdev, PCI_D0);
5234 e1000_pci_restore_state(adapter); 5177 pci_restore_state(pdev);
5235 if ((err = pci_enable_device(pdev))) { 5178 if ((err = pci_enable_device(pdev))) {
5236 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n"); 5179 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
5237 return err; 5180 return err;
diff --git a/drivers/net/eexpress.c b/drivers/net/eexpress.c
index 4a50fcb5ad..3868b80312 100644
--- a/drivers/net/eexpress.c
+++ b/drivers/net/eexpress.c
@@ -714,13 +714,6 @@ static int eexp_xmit(struct sk_buff *buf, struct net_device *dev)
714 * check to make sure we've not become wedged. 714 * check to make sure we've not become wedged.
715 */ 715 */
716 716
717/*
718 * Handle an EtherExpress interrupt
719 * If we've finished initializing, start the RU and CU up.
720 * If we've already started, reap tx buffers, handle any received packets,
721 * check to make sure we've not become wedged.
722 */
723
724static unsigned short eexp_start_irq(struct net_device *dev, 717static unsigned short eexp_start_irq(struct net_device *dev,
725 unsigned short status) 718 unsigned short status)
726{ 719{
diff --git a/drivers/net/ehea/ehea.h b/drivers/net/ehea/ehea.h
index 272e1ec51a..42295d61ec 100644
--- a/drivers/net/ehea/ehea.h
+++ b/drivers/net/ehea/ehea.h
@@ -39,7 +39,7 @@
39#include <asm/io.h> 39#include <asm/io.h>
40 40
41#define DRV_NAME "ehea" 41#define DRV_NAME "ehea"
42#define DRV_VERSION "EHEA_0045" 42#define DRV_VERSION "EHEA_0046"
43 43
44#define EHEA_MSG_DEFAULT (NETIF_MSG_LINK | NETIF_MSG_TIMER \ 44#define EHEA_MSG_DEFAULT (NETIF_MSG_LINK | NETIF_MSG_TIMER \
45 | NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR) 45 | NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
diff --git a/drivers/net/ehea/ehea_main.c b/drivers/net/ehea/ehea_main.c
index 38b2fa424b..0e4042bc0a 100644
--- a/drivers/net/ehea/ehea_main.c
+++ b/drivers/net/ehea/ehea_main.c
@@ -76,7 +76,7 @@ void ehea_dump(void *adr, int len, char *msg) {
76 int x; 76 int x;
77 unsigned char *deb = adr; 77 unsigned char *deb = adr;
78 for (x = 0; x < len; x += 16) { 78 for (x = 0; x < len; x += 16) {
79 printk(DRV_NAME "%s adr=%p ofs=%04x %016lx %016lx\n", msg, 79 printk(DRV_NAME " %s adr=%p ofs=%04x %016lx %016lx\n", msg,
80 deb, x, *((u64*)&deb[0]), *((u64*)&deb[8])); 80 deb, x, *((u64*)&deb[0]), *((u64*)&deb[8]));
81 deb += 16; 81 deb += 16;
82 } 82 }
@@ -555,6 +555,7 @@ static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
555{ 555{
556 struct ehea_port *port = param; 556 struct ehea_port *port = param;
557 struct ehea_eqe *eqe; 557 struct ehea_eqe *eqe;
558 struct ehea_qp *qp;
558 u32 qp_token; 559 u32 qp_token;
559 560
560 eqe = ehea_poll_eq(port->qp_eq); 561 eqe = ehea_poll_eq(port->qp_eq);
@@ -563,9 +564,14 @@ static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
563 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry); 564 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
564 ehea_error("QP aff_err: entry=0x%lx, token=0x%x", 565 ehea_error("QP aff_err: entry=0x%lx, token=0x%x",
565 eqe->entry, qp_token); 566 eqe->entry, qp_token);
567
568 qp = port->port_res[qp_token].qp;
569 ehea_error_data(port->adapter, qp->fw_handle);
566 eqe = ehea_poll_eq(port->qp_eq); 570 eqe = ehea_poll_eq(port->qp_eq);
567 } 571 }
568 572
573 queue_work(port->adapter->ehea_wq, &port->reset_task);
574
569 return IRQ_HANDLED; 575 return IRQ_HANDLED;
570} 576}
571 577
@@ -1933,8 +1939,7 @@ static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1933 int index; 1939 int index;
1934 u64 hret; 1940 u64 hret;
1935 1941
1936 if (port->vgrp) 1942 vlan_group_set_device(port->vgrp, vid, NULL);
1937 port->vgrp->vlan_devices[vid] = NULL;
1938 1943
1939 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL); 1944 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
1940 if (!cb1) { 1945 if (!cb1) {
diff --git a/drivers/net/ehea/ehea_phyp.c b/drivers/net/ehea/ehea_phyp.c
index 37716e05e8..bc3c005472 100644
--- a/drivers/net/ehea/ehea_phyp.c
+++ b/drivers/net/ehea/ehea_phyp.c
@@ -612,3 +612,13 @@ u64 ehea_h_reset_events(const u64 adapter_handle, const u64 neq_handle,
612 event_mask, /* R6 */ 612 event_mask, /* R6 */
613 0, 0, 0, 0); /* R7-R12 */ 613 0, 0, 0, 0); /* R7-R12 */
614} 614}
615
616u64 ehea_h_error_data(const u64 adapter_handle, const u64 ressource_handle,
617 void *rblock)
618{
619 return ehea_plpar_hcall_norets(H_ERROR_DATA,
620 adapter_handle, /* R4 */
621 ressource_handle, /* R5 */
622 virt_to_abs(rblock), /* R6 */
623 0, 0, 0, 0); /* R7-R12 */
624}
diff --git a/drivers/net/ehea/ehea_phyp.h b/drivers/net/ehea/ehea_phyp.h
index 919f94b759..90acddb068 100644
--- a/drivers/net/ehea/ehea_phyp.h
+++ b/drivers/net/ehea/ehea_phyp.h
@@ -454,4 +454,7 @@ u64 ehea_h_reg_dereg_bcmc(const u64 adapter_handle, const u16 port_num,
454u64 ehea_h_reset_events(const u64 adapter_handle, const u64 neq_handle, 454u64 ehea_h_reset_events(const u64 adapter_handle, const u64 neq_handle,
455 const u64 event_mask); 455 const u64 event_mask);
456 456
457u64 ehea_h_error_data(const u64 adapter_handle, const u64 ressource_handle,
458 void *rblock);
459
457#endif /* __EHEA_PHYP_H__ */ 460#endif /* __EHEA_PHYP_H__ */
diff --git a/drivers/net/ehea/ehea_qmr.c b/drivers/net/ehea/ehea_qmr.c
index f143e13b22..96ff3b6799 100644
--- a/drivers/net/ehea/ehea_qmr.c
+++ b/drivers/net/ehea/ehea_qmr.c
@@ -486,6 +486,7 @@ int ehea_destroy_qp(struct ehea_qp *qp)
486 if (!qp) 486 if (!qp)
487 return 0; 487 return 0;
488 488
489 ehea_h_disable_and_get_hea(qp->adapter->handle, qp->fw_handle);
489 hret = ehea_h_free_resource(qp->adapter->handle, qp->fw_handle); 490 hret = ehea_h_free_resource(qp->adapter->handle, qp->fw_handle);
490 if (hret != H_SUCCESS) { 491 if (hret != H_SUCCESS) {
491 ehea_error("destroy_qp failed"); 492 ehea_error("destroy_qp failed");
@@ -581,4 +582,45 @@ out:
581 return ret; 582 return ret;
582} 583}
583 584
585void print_error_data(u64 *data)
586{
587 int length;
588 u64 type = EHEA_BMASK_GET(ERROR_DATA_TYPE, data[2]);
589 u64 resource = data[1];
590
591 length = EHEA_BMASK_GET(ERROR_DATA_LENGTH, data[0]);
592
593 if (length > EHEA_PAGESIZE)
594 length = EHEA_PAGESIZE;
595
596 if (type == 0x8) /* Queue Pair */
597 ehea_error("QP (resource=%lX) state: AER=0x%lX, AERR=0x%lX, "
598 "port=%lX", resource, data[6], data[12], data[22]);
599
600 ehea_dump(data, length, "error data");
601}
602
603void ehea_error_data(struct ehea_adapter *adapter, u64 res_handle)
604{
605 unsigned long ret;
606 u64 *rblock;
607
608 rblock = kzalloc(PAGE_SIZE, GFP_KERNEL);
609 if (!rblock) {
610 ehea_error("Cannot allocate rblock memory.");
611 return;
612 }
584 613
614 ret = ehea_h_error_data(adapter->handle,
615 res_handle,
616 rblock);
617
618 if (ret == H_R_STATE)
619 ehea_error("No error data is available: %lX.", res_handle);
620 else if (ret == H_SUCCESS)
621 print_error_data(rblock);
622 else
623 ehea_error("Error data could not be fetched: %lX", res_handle);
624
625 kfree(rblock);
626}
diff --git a/drivers/net/ehea/ehea_qmr.h b/drivers/net/ehea/ehea_qmr.h
index 7efdc96919..1ff6098350 100644
--- a/drivers/net/ehea/ehea_qmr.h
+++ b/drivers/net/ehea/ehea_qmr.h
@@ -180,6 +180,9 @@ struct ehea_eqe {
180 u64 entry; 180 u64 entry;
181}; 181};
182 182
183#define ERROR_DATA_LENGTH EHEA_BMASK_IBM(52,63)
184#define ERROR_DATA_TYPE EHEA_BMASK_IBM(0,7)
185
183static inline void *hw_qeit_calc(struct hw_queue *queue, u64 q_offset) 186static inline void *hw_qeit_calc(struct hw_queue *queue, u64 q_offset)
184{ 187{
185 struct ehea_page *current_page; 188 struct ehea_page *current_page;
@@ -355,4 +358,6 @@ int ehea_destroy_qp(struct ehea_qp *qp);
355 358
356int ehea_reg_mr_adapter(struct ehea_adapter *adapter); 359int ehea_reg_mr_adapter(struct ehea_adapter *adapter);
357 360
361void ehea_error_data(struct ehea_adapter *adapter, u64 res_handle);
362
358#endif /* __EHEA_QMR_H__ */ 363#endif /* __EHEA_QMR_H__ */
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c
index a363148d01..46e1697d9c 100644
--- a/drivers/net/forcedeth.c
+++ b/drivers/net/forcedeth.c
@@ -839,7 +839,7 @@ enum {
839 NV_MSIX_INT_DISABLED, 839 NV_MSIX_INT_DISABLED,
840 NV_MSIX_INT_ENABLED 840 NV_MSIX_INT_ENABLED
841}; 841};
842static int msix = NV_MSIX_INT_ENABLED; 842static int msix = NV_MSIX_INT_DISABLED;
843 843
844/* 844/*
845 * DMA 64bit 845 * DMA 64bit
@@ -3104,13 +3104,17 @@ static int nv_napi_poll(struct net_device *dev, int *budget)
3104 struct fe_priv *np = netdev_priv(dev); 3104 struct fe_priv *np = netdev_priv(dev);
3105 u8 __iomem *base = get_hwbase(dev); 3105 u8 __iomem *base = get_hwbase(dev);
3106 unsigned long flags; 3106 unsigned long flags;
3107 int retcode;
3107 3108
3108 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) 3109 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
3109 pkts = nv_rx_process(dev, limit); 3110 pkts = nv_rx_process(dev, limit);
3110 else 3111 retcode = nv_alloc_rx(dev);
3112 } else {
3111 pkts = nv_rx_process_optimized(dev, limit); 3113 pkts = nv_rx_process_optimized(dev, limit);
3114 retcode = nv_alloc_rx_optimized(dev);
3115 }
3112 3116
3113 if (nv_alloc_rx(dev)) { 3117 if (retcode) {
3114 spin_lock_irqsave(&np->lock, flags); 3118 spin_lock_irqsave(&np->lock, flags);
3115 if (!np->in_shutdown) 3119 if (!np->in_shutdown)
3116 mod_timer(&np->oom_kick, jiffies + OOM_REFILL); 3120 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
@@ -5370,19 +5374,19 @@ static struct pci_device_id pci_tbl[] = {
5370 }, 5374 },
5371 { /* MCP65 Ethernet Controller */ 5375 { /* MCP65 Ethernet Controller */
5372 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_20), 5376 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_20),
5373 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, 5377 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
5374 }, 5378 },
5375 { /* MCP65 Ethernet Controller */ 5379 { /* MCP65 Ethernet Controller */
5376 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_21), 5380 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_21),
5377 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, 5381 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
5378 }, 5382 },
5379 { /* MCP65 Ethernet Controller */ 5383 { /* MCP65 Ethernet Controller */
5380 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_22), 5384 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_22),
5381 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, 5385 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
5382 }, 5386 },
5383 { /* MCP65 Ethernet Controller */ 5387 { /* MCP65 Ethernet Controller */
5384 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_23), 5388 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_23),
5385 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, 5389 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
5386 }, 5390 },
5387 { /* MCP67 Ethernet Controller */ 5391 { /* MCP67 Ethernet Controller */
5388 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_24), 5392 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_24),
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 1be4a84dce..d981d4c41d 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -10,6 +10,7 @@
10 * Maintainer: Kumar Gala 10 * Maintainer: Kumar Gala
11 * 11 *
12 * Copyright (c) 2002-2006 Freescale Semiconductor, Inc. 12 * Copyright (c) 2002-2006 Freescale Semiconductor, Inc.
13 * Copyright (c) 2007 MontaVista Software, Inc.
13 * 14 *
14 * This program is free software; you can redistribute it and/or modify it 15 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the 16 * under the terms of the GNU General Public License as published by the
@@ -1131,8 +1132,7 @@ static void gfar_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)
1131 1132
1132 spin_lock_irqsave(&priv->rxlock, flags); 1133 spin_lock_irqsave(&priv->rxlock, flags);
1133 1134
1134 if (priv->vlgrp) 1135 vlan_group_set_device(priv->vlgrp, vid, NULL);
1135 priv->vlgrp->vlan_devices[vid] = NULL;
1136 1136
1137 spin_unlock_irqrestore(&priv->rxlock, flags); 1137 spin_unlock_irqrestore(&priv->rxlock, flags);
1138} 1138}
@@ -1612,71 +1612,17 @@ static irqreturn_t gfar_interrupt(int irq, void *dev_id)
1612 /* Save ievent for future reference */ 1612 /* Save ievent for future reference */
1613 u32 events = gfar_read(&priv->regs->ievent); 1613 u32 events = gfar_read(&priv->regs->ievent);
1614 1614
1615 /* Clear IEVENT */
1616 gfar_write(&priv->regs->ievent, events);
1617
1618 /* Check for reception */ 1615 /* Check for reception */
1619 if ((events & IEVENT_RXF0) || (events & IEVENT_RXB0)) 1616 if (events & IEVENT_RX_MASK)
1620 gfar_receive(irq, dev_id); 1617 gfar_receive(irq, dev_id);
1621 1618
1622 /* Check for transmit completion */ 1619 /* Check for transmit completion */
1623 if ((events & IEVENT_TXF) || (events & IEVENT_TXB)) 1620 if (events & IEVENT_TX_MASK)
1624 gfar_transmit(irq, dev_id); 1621 gfar_transmit(irq, dev_id);
1625 1622
1626 /* Update error statistics */ 1623 /* Check for errors */
1627 if (events & IEVENT_TXE) { 1624 if (events & IEVENT_ERR_MASK)
1628 priv->stats.tx_errors++; 1625 gfar_error(irq, dev_id);
1629
1630 if (events & IEVENT_LC)
1631 priv->stats.tx_window_errors++;
1632 if (events & IEVENT_CRL)
1633 priv->stats.tx_aborted_errors++;
1634 if (events & IEVENT_XFUN) {
1635 if (netif_msg_tx_err(priv))
1636 printk(KERN_WARNING "%s: tx underrun. dropped packet\n", dev->name);
1637 priv->stats.tx_dropped++;
1638 priv->extra_stats.tx_underrun++;
1639
1640 /* Reactivate the Tx Queues */
1641 gfar_write(&priv->regs->tstat, TSTAT_CLEAR_THALT);
1642 }
1643 }
1644 if (events & IEVENT_BSY) {
1645 priv->stats.rx_errors++;
1646 priv->extra_stats.rx_bsy++;
1647
1648 gfar_receive(irq, dev_id);
1649
1650#ifndef CONFIG_GFAR_NAPI
1651 /* Clear the halt bit in RSTAT */
1652 gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT);
1653#endif
1654
1655 if (netif_msg_rx_err(priv))
1656 printk(KERN_DEBUG "%s: busy error (rhalt: %x)\n",
1657 dev->name,
1658 gfar_read(&priv->regs->rstat));
1659 }
1660 if (events & IEVENT_BABR) {
1661 priv->stats.rx_errors++;
1662 priv->extra_stats.rx_babr++;
1663
1664 if (netif_msg_rx_err(priv))
1665 printk(KERN_DEBUG "%s: babbling error\n", dev->name);
1666 }
1667 if (events & IEVENT_EBERR) {
1668 priv->extra_stats.eberr++;
1669 if (netif_msg_rx_err(priv))
1670 printk(KERN_DEBUG "%s: EBERR\n", dev->name);
1671 }
1672 if ((events & IEVENT_RXC) && (netif_msg_rx_err(priv)))
1673 printk(KERN_DEBUG "%s: control frame\n", dev->name);
1674
1675 if (events & IEVENT_BABT) {
1676 priv->extra_stats.tx_babt++;
1677 if (netif_msg_rx_err(priv))
1678 printk(KERN_DEBUG "%s: babt error\n", dev->name);
1679 }
1680 1626
1681 return IRQ_HANDLED; 1627 return IRQ_HANDLED;
1682} 1628}
@@ -1938,7 +1884,7 @@ static irqreturn_t gfar_error(int irq, void *dev_id)
1938 /* Hmm... */ 1884 /* Hmm... */
1939 if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv)) 1885 if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv))
1940 printk(KERN_DEBUG "%s: error interrupt (ievent=0x%08x imask=0x%08x)\n", 1886 printk(KERN_DEBUG "%s: error interrupt (ievent=0x%08x imask=0x%08x)\n",
1941 dev->name, events, gfar_read(&priv->regs->imask)); 1887 dev->name, events, gfar_read(&priv->regs->imask));
1942 1888
1943 /* Update the error counters */ 1889 /* Update the error counters */
1944 if (events & IEVENT_TXE) { 1890 if (events & IEVENT_TXE) {
@@ -1950,8 +1896,8 @@ static irqreturn_t gfar_error(int irq, void *dev_id)
1950 priv->stats.tx_aborted_errors++; 1896 priv->stats.tx_aborted_errors++;
1951 if (events & IEVENT_XFUN) { 1897 if (events & IEVENT_XFUN) {
1952 if (netif_msg_tx_err(priv)) 1898 if (netif_msg_tx_err(priv))
1953 printk(KERN_DEBUG "%s: underrun. packet dropped.\n", 1899 printk(KERN_DEBUG "%s: TX FIFO underrun, "
1954 dev->name); 1900 "packet dropped.\n", dev->name);
1955 priv->stats.tx_dropped++; 1901 priv->stats.tx_dropped++;
1956 priv->extra_stats.tx_underrun++; 1902 priv->extra_stats.tx_underrun++;
1957 1903
@@ -1973,30 +1919,28 @@ static irqreturn_t gfar_error(int irq, void *dev_id)
1973#endif 1919#endif
1974 1920
1975 if (netif_msg_rx_err(priv)) 1921 if (netif_msg_rx_err(priv))
1976 printk(KERN_DEBUG "%s: busy error (rhalt: %x)\n", 1922 printk(KERN_DEBUG "%s: busy error (rstat: %x)\n",
1977 dev->name, 1923 dev->name, gfar_read(&priv->regs->rstat));
1978 gfar_read(&priv->regs->rstat));
1979 } 1924 }
1980 if (events & IEVENT_BABR) { 1925 if (events & IEVENT_BABR) {
1981 priv->stats.rx_errors++; 1926 priv->stats.rx_errors++;
1982 priv->extra_stats.rx_babr++; 1927 priv->extra_stats.rx_babr++;
1983 1928
1984 if (netif_msg_rx_err(priv)) 1929 if (netif_msg_rx_err(priv))
1985 printk(KERN_DEBUG "%s: babbling error\n", dev->name); 1930 printk(KERN_DEBUG "%s: babbling RX error\n", dev->name);
1986 } 1931 }
1987 if (events & IEVENT_EBERR) { 1932 if (events & IEVENT_EBERR) {
1988 priv->extra_stats.eberr++; 1933 priv->extra_stats.eberr++;
1989 if (netif_msg_rx_err(priv)) 1934 if (netif_msg_rx_err(priv))
1990 printk(KERN_DEBUG "%s: EBERR\n", dev->name); 1935 printk(KERN_DEBUG "%s: bus error\n", dev->name);
1991 } 1936 }
1992 if ((events & IEVENT_RXC) && netif_msg_rx_status(priv)) 1937 if ((events & IEVENT_RXC) && netif_msg_rx_status(priv))
1993 if (netif_msg_rx_status(priv)) 1938 printk(KERN_DEBUG "%s: control frame\n", dev->name);
1994 printk(KERN_DEBUG "%s: control frame\n", dev->name);
1995 1939
1996 if (events & IEVENT_BABT) { 1940 if (events & IEVENT_BABT) {
1997 priv->extra_stats.tx_babt++; 1941 priv->extra_stats.tx_babt++;
1998 if (netif_msg_tx_err(priv)) 1942 if (netif_msg_tx_err(priv))
1999 printk(KERN_DEBUG "%s: babt error\n", dev->name); 1943 printk(KERN_DEBUG "%s: babbling TX error\n", dev->name);
2000 } 1944 }
2001 return IRQ_HANDLED; 1945 return IRQ_HANDLED;
2002} 1946}
diff --git a/drivers/net/gianfar_sysfs.c b/drivers/net/gianfar_sysfs.c
index 45ffb5d0ca..aec9ab17a9 100644
--- a/drivers/net/gianfar_sysfs.c
+++ b/drivers/net/gianfar_sysfs.c
@@ -38,13 +38,15 @@
38#include "gianfar.h" 38#include "gianfar.h"
39 39
40#define GFAR_ATTR(_name) \ 40#define GFAR_ATTR(_name) \
41static ssize_t gfar_show_##_name(struct class_device *cdev, char *buf); \ 41static ssize_t gfar_show_##_name(struct device *dev, \
42static ssize_t gfar_set_##_name(struct class_device *cdev, \ 42 struct device_attribute *attr, char *buf); \
43static ssize_t gfar_set_##_name(struct device *dev, \
44 struct device_attribute *attr, \
43 const char *buf, size_t count); \ 45 const char *buf, size_t count); \
44static CLASS_DEVICE_ATTR(_name, 0644, gfar_show_##_name, gfar_set_##_name) 46static DEVICE_ATTR(_name, 0644, gfar_show_##_name, gfar_set_##_name)
45 47
46#define GFAR_CREATE_FILE(_dev, _name) \ 48#define GFAR_CREATE_FILE(_dev, _name) \
47 class_device_create_file(&_dev->class_dev, &class_device_attr_##_name) 49 device_create_file(&_dev->dev, &dev_attr_##_name)
48 50
49GFAR_ATTR(bd_stash); 51GFAR_ATTR(bd_stash);
50GFAR_ATTR(rx_stash_size); 52GFAR_ATTR(rx_stash_size);
@@ -53,29 +55,28 @@ GFAR_ATTR(fifo_threshold);
53GFAR_ATTR(fifo_starve); 55GFAR_ATTR(fifo_starve);
54GFAR_ATTR(fifo_starve_off); 56GFAR_ATTR(fifo_starve_off);
55 57
56#define to_net_dev(cd) container_of(cd, struct net_device, class_dev) 58static ssize_t gfar_show_bd_stash(struct device *dev,
57 59 struct device_attribute *attr, char *buf)
58static ssize_t gfar_show_bd_stash(struct class_device *cdev, char *buf)
59{ 60{
60 struct net_device *dev = to_net_dev(cdev); 61 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
61 struct gfar_private *priv = netdev_priv(dev);
62 62
63 return sprintf(buf, "%s\n", priv->bd_stash_en? "on" : "off"); 63 return sprintf(buf, "%s\n", priv->bd_stash_en ? "on" : "off");
64} 64}
65 65
66static ssize_t gfar_set_bd_stash(struct class_device *cdev, 66static ssize_t gfar_set_bd_stash(struct device *dev,
67 const char *buf, size_t count) 67 struct device_attribute *attr,
68 const char *buf, size_t count)
68{ 69{
69 struct net_device *dev = to_net_dev(cdev); 70 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
70 struct gfar_private *priv = netdev_priv(dev);
71 int new_setting = 0; 71 int new_setting = 0;
72 u32 temp; 72 u32 temp;
73 unsigned long flags; 73 unsigned long flags;
74 74
75 /* Find out the new setting */ 75 /* Find out the new setting */
76 if (!strncmp("on", buf, count-1) || !strncmp("1", buf, count-1)) 76 if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1))
77 new_setting = 1; 77 new_setting = 1;
78 else if (!strncmp("off", buf, count-1) || !strncmp("0", buf, count-1)) 78 else if (!strncmp("off", buf, count - 1)
79 || !strncmp("0", buf, count - 1))
79 new_setting = 0; 80 new_setting = 0;
80 else 81 else
81 return count; 82 return count;
@@ -99,19 +100,19 @@ static ssize_t gfar_set_bd_stash(struct class_device *cdev,
99 return count; 100 return count;
100} 101}
101 102
102static ssize_t gfar_show_rx_stash_size(struct class_device *cdev, char *buf) 103static ssize_t gfar_show_rx_stash_size(struct device *dev,
104 struct device_attribute *attr, char *buf)
103{ 105{
104 struct net_device *dev = to_net_dev(cdev); 106 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
105 struct gfar_private *priv = netdev_priv(dev);
106 107
107 return sprintf(buf, "%d\n", priv->rx_stash_size); 108 return sprintf(buf, "%d\n", priv->rx_stash_size);
108} 109}
109 110
110static ssize_t gfar_set_rx_stash_size(struct class_device *cdev, 111static ssize_t gfar_set_rx_stash_size(struct device *dev,
111 const char *buf, size_t count) 112 struct device_attribute *attr,
113 const char *buf, size_t count)
112{ 114{
113 struct net_device *dev = to_net_dev(cdev); 115 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
114 struct gfar_private *priv = netdev_priv(dev);
115 unsigned int length = simple_strtoul(buf, NULL, 0); 116 unsigned int length = simple_strtoul(buf, NULL, 0);
116 u32 temp; 117 u32 temp;
117 unsigned long flags; 118 unsigned long flags;
@@ -145,21 +146,21 @@ static ssize_t gfar_set_rx_stash_size(struct class_device *cdev,
145 return count; 146 return count;
146} 147}
147 148
148
149/* Stashing will only be enabled when rx_stash_size != 0 */ 149/* Stashing will only be enabled when rx_stash_size != 0 */
150static ssize_t gfar_show_rx_stash_index(struct class_device *cdev, char *buf) 150static ssize_t gfar_show_rx_stash_index(struct device *dev,
151 struct device_attribute *attr,
152 char *buf)
151{ 153{
152 struct net_device *dev = to_net_dev(cdev); 154 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
153 struct gfar_private *priv = netdev_priv(dev);
154 155
155 return sprintf(buf, "%d\n", priv->rx_stash_index); 156 return sprintf(buf, "%d\n", priv->rx_stash_index);
156} 157}
157 158
158static ssize_t gfar_set_rx_stash_index(struct class_device *cdev, 159static ssize_t gfar_set_rx_stash_index(struct device *dev,
159 const char *buf, size_t count) 160 struct device_attribute *attr,
161 const char *buf, size_t count)
160{ 162{
161 struct net_device *dev = to_net_dev(cdev); 163 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
162 struct gfar_private *priv = netdev_priv(dev);
163 unsigned short index = simple_strtoul(buf, NULL, 0); 164 unsigned short index = simple_strtoul(buf, NULL, 0);
164 u32 temp; 165 u32 temp;
165 unsigned long flags; 166 unsigned long flags;
@@ -183,19 +184,20 @@ static ssize_t gfar_set_rx_stash_index(struct class_device *cdev,
183 return count; 184 return count;
184} 185}
185 186
186static ssize_t gfar_show_fifo_threshold(struct class_device *cdev, char *buf) 187static ssize_t gfar_show_fifo_threshold(struct device *dev,
188 struct device_attribute *attr,
189 char *buf)
187{ 190{
188 struct net_device *dev = to_net_dev(cdev); 191 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
189 struct gfar_private *priv = netdev_priv(dev);
190 192
191 return sprintf(buf, "%d\n", priv->fifo_threshold); 193 return sprintf(buf, "%d\n", priv->fifo_threshold);
192} 194}
193 195
194static ssize_t gfar_set_fifo_threshold(struct class_device *cdev, 196static ssize_t gfar_set_fifo_threshold(struct device *dev,
195 const char *buf, size_t count) 197 struct device_attribute *attr,
198 const char *buf, size_t count)
196{ 199{
197 struct net_device *dev = to_net_dev(cdev); 200 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
198 struct gfar_private *priv = netdev_priv(dev);
199 unsigned int length = simple_strtoul(buf, NULL, 0); 201 unsigned int length = simple_strtoul(buf, NULL, 0);
200 u32 temp; 202 u32 temp;
201 unsigned long flags; 203 unsigned long flags;
@@ -217,20 +219,19 @@ static ssize_t gfar_set_fifo_threshold(struct class_device *cdev,
217 return count; 219 return count;
218} 220}
219 221
220static ssize_t gfar_show_fifo_starve(struct class_device *cdev, char *buf) 222static ssize_t gfar_show_fifo_starve(struct device *dev,
223 struct device_attribute *attr, char *buf)
221{ 224{
222 struct net_device *dev = to_net_dev(cdev); 225 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
223 struct gfar_private *priv = netdev_priv(dev);
224 226
225 return sprintf(buf, "%d\n", priv->fifo_starve); 227 return sprintf(buf, "%d\n", priv->fifo_starve);
226} 228}
227 229
228 230static ssize_t gfar_set_fifo_starve(struct device *dev,
229static ssize_t gfar_set_fifo_starve(struct class_device *cdev, 231 struct device_attribute *attr,
230 const char *buf, size_t count) 232 const char *buf, size_t count)
231{ 233{
232 struct net_device *dev = to_net_dev(cdev); 234 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
233 struct gfar_private *priv = netdev_priv(dev);
234 unsigned int num = simple_strtoul(buf, NULL, 0); 235 unsigned int num = simple_strtoul(buf, NULL, 0);
235 u32 temp; 236 u32 temp;
236 unsigned long flags; 237 unsigned long flags;
@@ -252,19 +253,20 @@ static ssize_t gfar_set_fifo_starve(struct class_device *cdev,
252 return count; 253 return count;
253} 254}
254 255
255static ssize_t gfar_show_fifo_starve_off(struct class_device *cdev, char *buf) 256static ssize_t gfar_show_fifo_starve_off(struct device *dev,
257 struct device_attribute *attr,
258 char *buf)
256{ 259{
257 struct net_device *dev = to_net_dev(cdev); 260 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
258 struct gfar_private *priv = netdev_priv(dev);
259 261
260 return sprintf(buf, "%d\n", priv->fifo_starve_off); 262 return sprintf(buf, "%d\n", priv->fifo_starve_off);
261} 263}
262 264
263static ssize_t gfar_set_fifo_starve_off(struct class_device *cdev, 265static ssize_t gfar_set_fifo_starve_off(struct device *dev,
264 const char *buf, size_t count) 266 struct device_attribute *attr,
267 const char *buf, size_t count)
265{ 268{
266 struct net_device *dev = to_net_dev(cdev); 269 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
267 struct gfar_private *priv = netdev_priv(dev);
268 unsigned int num = simple_strtoul(buf, NULL, 0); 270 unsigned int num = simple_strtoul(buf, NULL, 0);
269 u32 temp; 271 u32 temp;
270 unsigned long flags; 272 unsigned long flags;
diff --git a/drivers/net/hamradio/Kconfig b/drivers/net/hamradio/Kconfig
index feb0ada7a0..6e90619b3b 100644
--- a/drivers/net/hamradio/Kconfig
+++ b/drivers/net/hamradio/Kconfig
@@ -138,7 +138,7 @@ config BAYCOM_SER_HDX
138 ---help--- 138 ---help---
139 This is one of two drivers for Baycom style simple amateur radio 139 This is one of two drivers for Baycom style simple amateur radio
140 modems that connect to a serial interface. The driver supports the 140 modems that connect to a serial interface. The driver supports the
141 ser12 design in full-duplex mode. This is the old driver. It is 141 ser12 design in half-duplex mode. This is the old driver. It is
142 still provided in case your serial interface chip does not work with 142 still provided in case your serial interface chip does not work with
143 the full-duplex driver. This driver is depreciated. To configure 143 the full-duplex driver. This driver is depreciated. To configure
144 the driver, use the sethdlc utility available in the standard ax25 144 the driver, use the sethdlc utility available in the standard ax25
@@ -190,3 +190,4 @@ config YAM
190 To compile this driver as a module, choose M here: the module 190 To compile this driver as a module, choose M here: the module
191 will be called yam. 191 will be called yam.
192 192
193
diff --git a/drivers/net/hamradio/baycom_epp.c b/drivers/net/hamradio/baycom_epp.c
index 153b6dc80a..84aa2117c0 100644
--- a/drivers/net/hamradio/baycom_epp.c
+++ b/drivers/net/hamradio/baycom_epp.c
@@ -52,6 +52,7 @@
52#include <linux/hdlcdrv.h> 52#include <linux/hdlcdrv.h>
53#include <linux/baycom.h> 53#include <linux/baycom.h>
54#include <linux/jiffies.h> 54#include <linux/jiffies.h>
55#include <linux/random.h>
55#include <net/ax25.h> 56#include <net/ax25.h>
56#include <asm/uaccess.h> 57#include <asm/uaccess.h>
57 58
@@ -433,16 +434,6 @@ static void encode_hdlc(struct baycom_state *bc)
433 434
434/* ---------------------------------------------------------------------- */ 435/* ---------------------------------------------------------------------- */
435 436
436static unsigned short random_seed;
437
438static inline unsigned short random_num(void)
439{
440 random_seed = 28629 * random_seed + 157;
441 return random_seed;
442}
443
444/* ---------------------------------------------------------------------- */
445
446static int transmit(struct baycom_state *bc, int cnt, unsigned char stat) 437static int transmit(struct baycom_state *bc, int cnt, unsigned char stat)
447{ 438{
448 struct parport *pp = bc->pdev->port; 439 struct parport *pp = bc->pdev->port;
@@ -464,7 +455,7 @@ static int transmit(struct baycom_state *bc, int cnt, unsigned char stat)
464 if ((--bc->hdlctx.slotcnt) > 0) 455 if ((--bc->hdlctx.slotcnt) > 0)
465 return 0; 456 return 0;
466 bc->hdlctx.slotcnt = bc->ch_params.slottime; 457 bc->hdlctx.slotcnt = bc->ch_params.slottime;
467 if ((random_num() % 256) > bc->ch_params.ppersist) 458 if ((random32() % 256) > bc->ch_params.ppersist)
468 return 0; 459 return 0;
469 } 460 }
470 } 461 }
diff --git a/drivers/net/hamradio/hdlcdrv.c b/drivers/net/hamradio/hdlcdrv.c
index 452873e7c6..f5a17ad9d3 100644
--- a/drivers/net/hamradio/hdlcdrv.c
+++ b/drivers/net/hamradio/hdlcdrv.c
@@ -56,6 +56,7 @@
56#include <linux/if_arp.h> 56#include <linux/if_arp.h>
57#include <linux/skbuff.h> 57#include <linux/skbuff.h>
58#include <linux/hdlcdrv.h> 58#include <linux/hdlcdrv.h>
59#include <linux/random.h>
59#include <net/ax25.h> 60#include <net/ax25.h>
60#include <asm/uaccess.h> 61#include <asm/uaccess.h>
61 62
@@ -371,16 +372,6 @@ static void start_tx(struct net_device *dev, struct hdlcdrv_state *s)
371 372
372/* ---------------------------------------------------------------------- */ 373/* ---------------------------------------------------------------------- */
373 374
374static unsigned short random_seed;
375
376static inline unsigned short random_num(void)
377{
378 random_seed = 28629 * random_seed + 157;
379 return random_seed;
380}
381
382/* ---------------------------------------------------------------------- */
383
384void hdlcdrv_arbitrate(struct net_device *dev, struct hdlcdrv_state *s) 375void hdlcdrv_arbitrate(struct net_device *dev, struct hdlcdrv_state *s)
385{ 376{
386 if (!s || s->magic != HDLCDRV_MAGIC || s->hdlctx.ptt || !s->skb) 377 if (!s || s->magic != HDLCDRV_MAGIC || s->hdlctx.ptt || !s->skb)
@@ -396,7 +387,7 @@ void hdlcdrv_arbitrate(struct net_device *dev, struct hdlcdrv_state *s)
396 if ((--s->hdlctx.slotcnt) > 0) 387 if ((--s->hdlctx.slotcnt) > 0)
397 return; 388 return;
398 s->hdlctx.slotcnt = s->ch_params.slottime; 389 s->hdlctx.slotcnt = s->ch_params.slottime;
399 if ((random_num() % 256) > s->ch_params.ppersist) 390 if ((random32() % 256) > s->ch_params.ppersist)
400 return; 391 return;
401 start_tx(dev, s); 392 start_tx(dev, s);
402} 393}
diff --git a/drivers/net/hamradio/yam.c b/drivers/net/hamradio/yam.c
index 08f27119a8..ee3ea4fa72 100644
--- a/drivers/net/hamradio/yam.c
+++ b/drivers/net/hamradio/yam.c
@@ -50,6 +50,7 @@
50#include <linux/slab.h> 50#include <linux/slab.h>
51#include <linux/errno.h> 51#include <linux/errno.h>
52#include <linux/bitops.h> 52#include <linux/bitops.h>
53#include <linux/random.h>
53#include <asm/io.h> 54#include <asm/io.h>
54#include <asm/system.h> 55#include <asm/system.h>
55#include <linux/interrupt.h> 56#include <linux/interrupt.h>
@@ -566,14 +567,6 @@ static void yam_start_tx(struct net_device *dev, struct yam_port *yp)
566 ptt_on(dev); 567 ptt_on(dev);
567} 568}
568 569
569static unsigned short random_seed;
570
571static inline unsigned short random_num(void)
572{
573 random_seed = 28629 * random_seed + 157;
574 return random_seed;
575}
576
577static void yam_arbitrate(struct net_device *dev) 570static void yam_arbitrate(struct net_device *dev)
578{ 571{
579 struct yam_port *yp = netdev_priv(dev); 572 struct yam_port *yp = netdev_priv(dev);
@@ -600,7 +593,7 @@ static void yam_arbitrate(struct net_device *dev)
600 yp->slotcnt = yp->slot / 10; 593 yp->slotcnt = yp->slot / 10;
601 594
602 /* is random > persist ? */ 595 /* is random > persist ? */
603 if ((random_num() % 256) > yp->pers) 596 if ((random32() % 256) > yp->pers)
604 return; 597 return;
605 598
606 yam_start_tx(dev, yp); 599 yam_start_tx(dev, yp);
diff --git a/drivers/net/ioc3-eth.c b/drivers/net/ioc3-eth.c
index f0d30cf67b..4ad780719a 100644
--- a/drivers/net/ioc3-eth.c
+++ b/drivers/net/ioc3-eth.c
@@ -836,13 +836,17 @@ static int ioc3_mii_init(struct ioc3_private *ip)
836 } 836 }
837 837
838 ip->mii.phy_id = i; 838 ip->mii.phy_id = i;
839
840out:
841 return res;
842}
843
844static void ioc3_mii_start(struct ioc3_private *ip)
845{
839 ip->ioc3_timer.expires = jiffies + (12 * HZ)/10; /* 1.2 sec. */ 846 ip->ioc3_timer.expires = jiffies + (12 * HZ)/10; /* 1.2 sec. */
840 ip->ioc3_timer.data = (unsigned long) ip; 847 ip->ioc3_timer.data = (unsigned long) ip;
841 ip->ioc3_timer.function = &ioc3_timer; 848 ip->ioc3_timer.function = &ioc3_timer;
842 add_timer(&ip->ioc3_timer); 849 add_timer(&ip->ioc3_timer);
843
844out:
845 return res;
846} 850}
847 851
848static inline void ioc3_clean_rx_ring(struct ioc3_private *ip) 852static inline void ioc3_clean_rx_ring(struct ioc3_private *ip)
@@ -1071,6 +1075,7 @@ static int ioc3_open(struct net_device *dev)
1071 ip->ehar_h = 0; 1075 ip->ehar_h = 0;
1072 ip->ehar_l = 0; 1076 ip->ehar_l = 0;
1073 ioc3_init(dev); 1077 ioc3_init(dev);
1078 ioc3_mii_start(ip);
1074 1079
1075 netif_start_queue(dev); 1080 netif_start_queue(dev);
1076 return 0; 1081 return 0;
@@ -1274,6 +1279,7 @@ static int ioc3_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1274 goto out_stop; 1279 goto out_stop;
1275 } 1280 }
1276 1281
1282 ioc3_mii_start(ip);
1277 ioc3_ssram_disc(ip); 1283 ioc3_ssram_disc(ip);
1278 ioc3_get_eaddr(ip); 1284 ioc3_get_eaddr(ip);
1279 1285
@@ -1314,6 +1320,7 @@ static int ioc3_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1314 1320
1315out_stop: 1321out_stop:
1316 ioc3_stop(ip); 1322 ioc3_stop(ip);
1323 del_timer_sync(&ip->ioc3_timer);
1317 ioc3_free_rings(ip); 1324 ioc3_free_rings(ip);
1318out_res: 1325out_res:
1319 pci_release_regions(pdev); 1326 pci_release_regions(pdev);
@@ -1335,6 +1342,8 @@ static void __devexit ioc3_remove_one (struct pci_dev *pdev)
1335 struct ioc3 *ioc3 = ip->regs; 1342 struct ioc3 *ioc3 = ip->regs;
1336 1343
1337 unregister_netdev(dev); 1344 unregister_netdev(dev);
1345 del_timer_sync(&ip->ioc3_timer);
1346
1338 iounmap(ioc3); 1347 iounmap(ioc3);
1339 pci_release_regions(pdev); 1348 pci_release_regions(pdev);
1340 free_netdev(dev); 1349 free_netdev(dev);
@@ -1492,6 +1501,7 @@ static void ioc3_timeout(struct net_device *dev)
1492 ioc3_stop(ip); 1501 ioc3_stop(ip);
1493 ioc3_init(dev); 1502 ioc3_init(dev);
1494 ioc3_mii_init(ip); 1503 ioc3_mii_init(ip);
1504 ioc3_mii_start(ip);
1495 1505
1496 spin_unlock_irq(&ip->ioc3_lock); 1506 spin_unlock_irq(&ip->ioc3_lock);
1497 1507
diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
index 0c36828893..afc2ec7252 100644
--- a/drivers/net/ixgb/ixgb_main.c
+++ b/drivers/net/ixgb/ixgb_main.c
@@ -2213,8 +2213,7 @@ ixgb_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
2213 2213
2214 ixgb_irq_disable(adapter); 2214 ixgb_irq_disable(adapter);
2215 2215
2216 if(adapter->vlgrp) 2216 vlan_group_set_device(adapter->vlgrp, vid, NULL);
2217 adapter->vlgrp->vlan_devices[vid] = NULL;
2218 2217
2219 ixgb_irq_enable(adapter); 2218 ixgb_irq_enable(adapter);
2220 2219
@@ -2234,7 +2233,7 @@ ixgb_restore_vlan(struct ixgb_adapter *adapter)
2234 if(adapter->vlgrp) { 2233 if(adapter->vlgrp) {
2235 uint16_t vid; 2234 uint16_t vid;
2236 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { 2235 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2237 if(!adapter->vlgrp->vlan_devices[vid]) 2236 if(!vlan_group_get_device(adapter->vlgrp, vid))
2238 continue; 2237 continue;
2239 ixgb_vlan_rx_add_vid(adapter->netdev, vid); 2238 ixgb_vlan_rx_add_vid(adapter->netdev, vid);
2240 } 2239 }
diff --git a/drivers/net/lasi_82596.c b/drivers/net/lasi_82596.c
index ea392f2a5a..452863d5d4 100644
--- a/drivers/net/lasi_82596.c
+++ b/drivers/net/lasi_82596.c
@@ -384,7 +384,7 @@ struct i596_private {
384 struct device *dev; 384 struct device *dev;
385}; 385};
386 386
387static char init_setup[] = 387static const char init_setup[] =
388{ 388{
389 0x8E, /* length, prefetch on */ 389 0x8E, /* length, prefetch on */
390 0xC8, /* fifo to 8, monitor off */ 390 0xC8, /* fifo to 8, monitor off */
@@ -683,7 +683,7 @@ static int init_i596_mem(struct net_device *dev)
683 enable_irq(dev->irq); /* enable IRQs from LAN */ 683 enable_irq(dev->irq); /* enable IRQs from LAN */
684 684
685 DEB(DEB_INIT, printk("%s: queuing CmdConfigure\n", dev->name)); 685 DEB(DEB_INIT, printk("%s: queuing CmdConfigure\n", dev->name));
686 memcpy(lp->cf_cmd.i596_config, init_setup, 14); 686 memcpy(lp->cf_cmd.i596_config, init_setup, sizeof(init_setup));
687 lp->cf_cmd.cmd.command = CmdConfigure; 687 lp->cf_cmd.cmd.command = CmdConfigure;
688 CHECK_WBACK(lp, &(lp->cf_cmd), sizeof(struct cf_cmd)); 688 CHECK_WBACK(lp, &(lp->cf_cmd), sizeof(struct cf_cmd));
689 i596_add_cmd(dev, &lp->cf_cmd.cmd); 689 i596_add_cmd(dev, &lp->cf_cmd.cmd);
@@ -1156,32 +1156,12 @@ static int __devinit i82596_probe(struct net_device *dev,
1156 dma_addr_t dma_addr; 1156 dma_addr_t dma_addr;
1157 1157
1158 /* This lot is ensure things have been cache line aligned. */ 1158 /* This lot is ensure things have been cache line aligned. */
1159 if (sizeof(struct i596_rfd) != 32) { 1159 BUILD_BUG_ON(sizeof(struct i596_rfd) != 32);
1160 printk("82596: sizeof(struct i596_rfd) = %d\n", 1160 BUILD_BUG_ON(sizeof(struct i596_rbd) & 31);
1161 (int)sizeof(struct i596_rfd)); 1161 BUILD_BUG_ON(sizeof(struct tx_cmd) & 31);
1162 return -ENODEV; 1162 BUILD_BUG_ON(sizeof(struct i596_tbd) != 32);
1163 }
1164 if ((sizeof(struct i596_rbd) % 32) != 0) {
1165 printk("82596: sizeof(struct i596_rbd) = %d\n",
1166 (int)sizeof(struct i596_rbd));
1167 return -ENODEV;
1168 }
1169 if ((sizeof(struct tx_cmd) % 32) != 0) {
1170 printk("82596: sizeof(struct tx_cmd) = %d\n",
1171 (int)sizeof(struct tx_cmd));
1172 return -ENODEV;
1173 }
1174 if (sizeof(struct i596_tbd) != 32) {
1175 printk("82596: sizeof(struct i596_tbd) = %d\n",
1176 (int)sizeof(struct i596_tbd));
1177 return -ENODEV;
1178 }
1179#ifndef __LP64__ 1163#ifndef __LP64__
1180 if (sizeof(struct i596_private) > 4096) { 1164 BUILD_BUG_ON(sizeof(struct i596_private) > 4096);
1181 printk("82596: sizeof(struct i596_private) = %d\n",
1182 (int)sizeof(struct i596_private));
1183 return -ENODEV;
1184 }
1185#endif 1165#endif
1186 1166
1187 if (!dev->base_addr || !dev->irq) 1167 if (!dev->base_addr || !dev->irq)
diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index a41418b3c5..2e9571bf07 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -881,27 +881,15 @@ static struct net_device_stats *macb_get_stats(struct net_device *dev)
881static int macb_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 881static int macb_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
882{ 882{
883 struct macb *bp = netdev_priv(dev); 883 struct macb *bp = netdev_priv(dev);
884 int ret;
885 unsigned long flags;
886
887 spin_lock_irqsave(&bp->lock, flags);
888 ret = mii_ethtool_gset(&bp->mii, cmd);
889 spin_unlock_irqrestore(&bp->lock, flags);
890 884
891 return ret; 885 return mii_ethtool_gset(&bp->mii, cmd);
892} 886}
893 887
894static int macb_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) 888static int macb_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
895{ 889{
896 struct macb *bp = netdev_priv(dev); 890 struct macb *bp = netdev_priv(dev);
897 int ret;
898 unsigned long flags;
899
900 spin_lock_irqsave(&bp->lock, flags);
901 ret = mii_ethtool_sset(&bp->mii, cmd);
902 spin_unlock_irqrestore(&bp->lock, flags);
903 891
904 return ret; 892 return mii_ethtool_sset(&bp->mii, cmd);
905} 893}
906 894
907static void macb_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) 895static void macb_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
@@ -930,17 +918,11 @@ static struct ethtool_ops macb_ethtool_ops = {
930static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 918static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
931{ 919{
932 struct macb *bp = netdev_priv(dev); 920 struct macb *bp = netdev_priv(dev);
933 int ret;
934 unsigned long flags;
935 921
936 if (!netif_running(dev)) 922 if (!netif_running(dev))
937 return -EINVAL; 923 return -EINVAL;
938 924
939 spin_lock_irqsave(&bp->lock, flags); 925 return generic_mii_ioctl(&bp->mii, if_mii(rq), cmd, NULL);
940 ret = generic_mii_ioctl(&bp->mii, if_mii(rq), cmd, NULL);
941 spin_unlock_irqrestore(&bp->lock, flags);
942
943 return ret;
944} 926}
945 927
946static ssize_t macb_mii_show(const struct device *_dev, char *buf, 928static ssize_t macb_mii_show(const struct device *_dev, char *buf,
diff --git a/drivers/net/meth.c b/drivers/net/meth.c
index d38b7c7236..7e69ca6edd 100644
--- a/drivers/net/meth.c
+++ b/drivers/net/meth.c
@@ -170,7 +170,7 @@ static int mdio_probe(struct meth_private *priv)
170 170
171static void meth_check_link(struct net_device *dev) 171static void meth_check_link(struct net_device *dev)
172{ 172{
173 struct meth_private *priv = (struct meth_private *) dev->priv; 173 struct meth_private *priv = netdev_priv(dev);
174 unsigned long mii_advertising = mdio_read(priv, 4); 174 unsigned long mii_advertising = mdio_read(priv, 4);
175 unsigned long mii_partner = mdio_read(priv, 5); 175 unsigned long mii_partner = mdio_read(priv, 5);
176 unsigned long negotiated = mii_advertising & mii_partner; 176 unsigned long negotiated = mii_advertising & mii_partner;
@@ -268,7 +268,7 @@ static void meth_free_rx_ring(struct meth_private *priv)
268 268
269int meth_reset(struct net_device *dev) 269int meth_reset(struct net_device *dev)
270{ 270{
271 struct meth_private *priv = (struct meth_private *) dev->priv; 271 struct meth_private *priv = netdev_priv(dev);
272 272
273 /* Reset card */ 273 /* Reset card */
274 mace->eth.mac_ctrl = SGI_MAC_RESET; 274 mace->eth.mac_ctrl = SGI_MAC_RESET;
@@ -310,7 +310,7 @@ int meth_reset(struct net_device *dev)
310 */ 310 */
311static int meth_open(struct net_device *dev) 311static int meth_open(struct net_device *dev)
312{ 312{
313 struct meth_private *priv = dev->priv; 313 struct meth_private *priv = netdev_priv(dev);
314 int ret; 314 int ret;
315 315
316 priv->phy_addr = -1; /* No PHY is known yet... */ 316 priv->phy_addr = -1; /* No PHY is known yet... */
@@ -354,7 +354,7 @@ out_free_tx_ring:
354 354
355static int meth_release(struct net_device *dev) 355static int meth_release(struct net_device *dev)
356{ 356{
357 struct meth_private *priv = dev->priv; 357 struct meth_private *priv = netdev_priv(dev);
358 358
359 DPRINTK("Stopping queue\n"); 359 DPRINTK("Stopping queue\n");
360 netif_stop_queue(dev); /* can't transmit any more */ 360 netif_stop_queue(dev); /* can't transmit any more */
@@ -376,7 +376,7 @@ static void meth_rx(struct net_device* dev, unsigned long int_status)
376{ 376{
377 struct sk_buff *skb; 377 struct sk_buff *skb;
378 unsigned long status; 378 unsigned long status;
379 struct meth_private *priv = (struct meth_private *) dev->priv; 379 struct meth_private *priv = netdev_priv(dev);
380 unsigned long fifo_rptr = (int_status & METH_INT_RX_RPTR_MASK) >> 8; 380 unsigned long fifo_rptr = (int_status & METH_INT_RX_RPTR_MASK) >> 8;
381 381
382 spin_lock(&priv->meth_lock); 382 spin_lock(&priv->meth_lock);
@@ -466,14 +466,14 @@ static void meth_rx(struct net_device* dev, unsigned long int_status)
466 466
467static int meth_tx_full(struct net_device *dev) 467static int meth_tx_full(struct net_device *dev)
468{ 468{
469 struct meth_private *priv = (struct meth_private *) dev->priv; 469 struct meth_private *priv = netdev_priv(dev);
470 470
471 return (priv->tx_count >= TX_RING_ENTRIES - 1); 471 return (priv->tx_count >= TX_RING_ENTRIES - 1);
472} 472}
473 473
474static void meth_tx_cleanup(struct net_device* dev, unsigned long int_status) 474static void meth_tx_cleanup(struct net_device* dev, unsigned long int_status)
475{ 475{
476 struct meth_private *priv = dev->priv; 476 struct meth_private *priv = netdev_priv(dev);
477 unsigned long status; 477 unsigned long status;
478 struct sk_buff *skb; 478 struct sk_buff *skb;
479 unsigned long rptr = (int_status&TX_INFO_RPTR) >> 16; 479 unsigned long rptr = (int_status&TX_INFO_RPTR) >> 16;
@@ -536,7 +536,7 @@ static void meth_tx_cleanup(struct net_device* dev, unsigned long int_status)
536 536
537static void meth_error(struct net_device* dev, unsigned status) 537static void meth_error(struct net_device* dev, unsigned status)
538{ 538{
539 struct meth_private *priv = (struct meth_private *) dev->priv; 539 struct meth_private *priv = netdev_priv(dev);
540 540
541 printk(KERN_WARNING "meth: error status: 0x%08x\n",status); 541 printk(KERN_WARNING "meth: error status: 0x%08x\n",status);
542 /* check for errors too... */ 542 /* check for errors too... */
@@ -570,7 +570,7 @@ static void meth_error(struct net_device* dev, unsigned status)
570static irqreturn_t meth_interrupt(int irq, void *dev_id) 570static irqreturn_t meth_interrupt(int irq, void *dev_id)
571{ 571{
572 struct net_device *dev = (struct net_device *)dev_id; 572 struct net_device *dev = (struct net_device *)dev_id;
573 struct meth_private *priv = (struct meth_private *) dev->priv; 573 struct meth_private *priv = netdev_priv(dev);
574 unsigned long status; 574 unsigned long status;
575 575
576 status = mace->eth.int_stat; 576 status = mace->eth.int_stat;
@@ -695,7 +695,7 @@ static void meth_add_to_tx_ring(struct meth_private *priv, struct sk_buff *skb)
695 */ 695 */
696static int meth_tx(struct sk_buff *skb, struct net_device *dev) 696static int meth_tx(struct sk_buff *skb, struct net_device *dev)
697{ 697{
698 struct meth_private *priv = (struct meth_private *) dev->priv; 698 struct meth_private *priv = netdev_priv(dev);
699 unsigned long flags; 699 unsigned long flags;
700 700
701 spin_lock_irqsave(&priv->meth_lock, flags); 701 spin_lock_irqsave(&priv->meth_lock, flags);
@@ -726,7 +726,7 @@ static int meth_tx(struct sk_buff *skb, struct net_device *dev)
726 */ 726 */
727static void meth_tx_timeout(struct net_device *dev) 727static void meth_tx_timeout(struct net_device *dev)
728{ 728{
729 struct meth_private *priv = (struct meth_private *) dev->priv; 729 struct meth_private *priv = netdev_priv(dev);
730 unsigned long flags; 730 unsigned long flags;
731 731
732 printk(KERN_WARNING "%s: transmit timed out\n", dev->name); 732 printk(KERN_WARNING "%s: transmit timed out\n", dev->name);
@@ -778,7 +778,7 @@ static int meth_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
778 */ 778 */
779static struct net_device_stats *meth_stats(struct net_device *dev) 779static struct net_device_stats *meth_stats(struct net_device *dev)
780{ 780{
781 struct meth_private *priv = (struct meth_private *) dev->priv; 781 struct meth_private *priv = netdev_priv(dev);
782 return &priv->stats; 782 return &priv->stats;
783} 783}
784 784
@@ -807,7 +807,7 @@ static struct net_device *meth_init(void)
807 dev->irq = MACE_ETHERNET_IRQ; 807 dev->irq = MACE_ETHERNET_IRQ;
808 dev->base_addr = (unsigned long)&mace->eth; 808 dev->base_addr = (unsigned long)&mace->eth;
809 809
810 priv = (struct meth_private *) dev->priv; 810 priv = netdev_priv(dev);
811 spin_lock_init(&priv->meth_lock); 811 spin_lock_init(&priv->meth_lock);
812 812
813 ret = register_netdev(dev); 813 ret = register_netdev(dev);
diff --git a/drivers/net/mv643xx_eth.c b/drivers/net/mv643xx_eth.c
index d98e53efa2..1ee27c360a 100644
--- a/drivers/net/mv643xx_eth.c
+++ b/drivers/net/mv643xx_eth.c
@@ -147,13 +147,13 @@ static void mv643xx_eth_rx_refill_descs(struct net_device *dev)
147 int unaligned; 147 int unaligned;
148 148
149 while (mp->rx_desc_count < mp->rx_ring_size) { 149 while (mp->rx_desc_count < mp->rx_ring_size) {
150 skb = dev_alloc_skb(ETH_RX_SKB_SIZE + ETH_DMA_ALIGN); 150 skb = dev_alloc_skb(ETH_RX_SKB_SIZE + dma_get_cache_alignment());
151 if (!skb) 151 if (!skb)
152 break; 152 break;
153 mp->rx_desc_count++; 153 mp->rx_desc_count++;
154 unaligned = (u32)skb->data & (ETH_DMA_ALIGN - 1); 154 unaligned = (u32)skb->data & (dma_get_cache_alignment() - 1);
155 if (unaligned) 155 if (unaligned)
156 skb_reserve(skb, ETH_DMA_ALIGN - unaligned); 156 skb_reserve(skb, dma_get_cache_alignment() - unaligned);
157 pkt_info.cmd_sts = ETH_RX_ENABLE_INTERRUPT; 157 pkt_info.cmd_sts = ETH_RX_ENABLE_INTERRUPT;
158 pkt_info.byte_cnt = ETH_RX_SKB_SIZE; 158 pkt_info.byte_cnt = ETH_RX_SKB_SIZE;
159 pkt_info.buf_ptr = dma_map_single(NULL, skb->data, 159 pkt_info.buf_ptr = dma_map_single(NULL, skb->data,
@@ -787,6 +787,12 @@ static int mv643xx_eth_open(struct net_device *dev)
787 unsigned int size; 787 unsigned int size;
788 int err; 788 int err;
789 789
790 /* Clear any pending ethernet port interrupts */
791 mv_write(MV643XX_ETH_INTERRUPT_CAUSE_REG(port_num), 0);
792 mv_write(MV643XX_ETH_INTERRUPT_CAUSE_EXTEND_REG(port_num), 0);
793 /* wait for previous write to complete */
794 mv_read (MV643XX_ETH_INTERRUPT_CAUSE_EXTEND_REG(port_num));
795
790 err = request_irq(dev->irq, mv643xx_eth_int_handler, 796 err = request_irq(dev->irq, mv643xx_eth_int_handler,
791 IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, dev); 797 IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, dev);
792 if (err) { 798 if (err) {
@@ -875,10 +881,6 @@ static int mv643xx_eth_open(struct net_device *dev)
875 881
876 mv643xx_eth_rx_refill_descs(dev); /* Fill RX ring with skb's */ 882 mv643xx_eth_rx_refill_descs(dev); /* Fill RX ring with skb's */
877 883
878 /* Clear any pending ethernet port interrupts */
879 mv_write(MV643XX_ETH_INTERRUPT_CAUSE_REG(port_num), 0);
880 mv_write(MV643XX_ETH_INTERRUPT_CAUSE_EXTEND_REG(port_num), 0);
881
882 eth_port_start(dev); 884 eth_port_start(dev);
883 885
884 /* Interrupt Coalescing */ 886 /* Interrupt Coalescing */
@@ -1309,7 +1311,7 @@ static void mv643xx_init_ethtool_cmd(struct net_device *dev, int phy_address,
1309static int mv643xx_eth_probe(struct platform_device *pdev) 1311static int mv643xx_eth_probe(struct platform_device *pdev)
1310{ 1312{
1311 struct mv643xx_eth_platform_data *pd; 1313 struct mv643xx_eth_platform_data *pd;
1312 int port_num = pdev->id; 1314 int port_num;
1313 struct mv643xx_private *mp; 1315 struct mv643xx_private *mp;
1314 struct net_device *dev; 1316 struct net_device *dev;
1315 u8 *p; 1317 u8 *p;
@@ -1319,6 +1321,12 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
1319 int duplex = DUPLEX_HALF; 1321 int duplex = DUPLEX_HALF;
1320 int speed = 0; /* default to auto-negotiation */ 1322 int speed = 0; /* default to auto-negotiation */
1321 1323
1324 pd = pdev->dev.platform_data;
1325 if (pd == NULL) {
1326 printk(KERN_ERR "No mv643xx_eth_platform_data\n");
1327 return -ENODEV;
1328 }
1329
1322 dev = alloc_etherdev(sizeof(struct mv643xx_private)); 1330 dev = alloc_etherdev(sizeof(struct mv643xx_private));
1323 if (!dev) 1331 if (!dev)
1324 return -ENOMEM; 1332 return -ENOMEM;
@@ -1331,8 +1339,6 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
1331 BUG_ON(!res); 1339 BUG_ON(!res);
1332 dev->irq = res->start; 1340 dev->irq = res->start;
1333 1341
1334 mp->port_num = port_num;
1335
1336 dev->open = mv643xx_eth_open; 1342 dev->open = mv643xx_eth_open;
1337 dev->stop = mv643xx_eth_stop; 1343 dev->stop = mv643xx_eth_stop;
1338 dev->hard_start_xmit = mv643xx_eth_start_xmit; 1344 dev->hard_start_xmit = mv643xx_eth_start_xmit;
@@ -1373,39 +1379,40 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
1373 1379
1374 spin_lock_init(&mp->lock); 1380 spin_lock_init(&mp->lock);
1375 1381
1382 port_num = pd->port_number;
1383
1376 /* set default config values */ 1384 /* set default config values */
1377 eth_port_uc_addr_get(dev, dev->dev_addr); 1385 eth_port_uc_addr_get(dev, dev->dev_addr);
1378 mp->rx_ring_size = MV643XX_ETH_PORT_DEFAULT_RECEIVE_QUEUE_SIZE; 1386 mp->rx_ring_size = MV643XX_ETH_PORT_DEFAULT_RECEIVE_QUEUE_SIZE;
1379 mp->tx_ring_size = MV643XX_ETH_PORT_DEFAULT_TRANSMIT_QUEUE_SIZE; 1387 mp->tx_ring_size = MV643XX_ETH_PORT_DEFAULT_TRANSMIT_QUEUE_SIZE;
1380 1388
1381 pd = pdev->dev.platform_data; 1389 if (is_valid_ether_addr(pd->mac_addr))
1382 if (pd) { 1390 memcpy(dev->dev_addr, pd->mac_addr, 6);
1383 if (pd->mac_addr)
1384 memcpy(dev->dev_addr, pd->mac_addr, 6);
1385
1386 if (pd->phy_addr || pd->force_phy_addr)
1387 ethernet_phy_set(port_num, pd->phy_addr);
1388 1391
1389 if (pd->rx_queue_size) 1392 if (pd->phy_addr || pd->force_phy_addr)
1390 mp->rx_ring_size = pd->rx_queue_size; 1393 ethernet_phy_set(port_num, pd->phy_addr);
1391 1394
1392 if (pd->tx_queue_size) 1395 if (pd->rx_queue_size)
1393 mp->tx_ring_size = pd->tx_queue_size; 1396 mp->rx_ring_size = pd->rx_queue_size;
1394 1397
1395 if (pd->tx_sram_size) { 1398 if (pd->tx_queue_size)
1396 mp->tx_sram_size = pd->tx_sram_size; 1399 mp->tx_ring_size = pd->tx_queue_size;
1397 mp->tx_sram_addr = pd->tx_sram_addr;
1398 }
1399 1400
1400 if (pd->rx_sram_size) { 1401 if (pd->tx_sram_size) {
1401 mp->rx_sram_size = pd->rx_sram_size; 1402 mp->tx_sram_size = pd->tx_sram_size;
1402 mp->rx_sram_addr = pd->rx_sram_addr; 1403 mp->tx_sram_addr = pd->tx_sram_addr;
1403 } 1404 }
1404 1405
1405 duplex = pd->duplex; 1406 if (pd->rx_sram_size) {
1406 speed = pd->speed; 1407 mp->rx_sram_size = pd->rx_sram_size;
1408 mp->rx_sram_addr = pd->rx_sram_addr;
1407 } 1409 }
1408 1410
1411 duplex = pd->duplex;
1412 speed = pd->speed;
1413
1414 mp->port_num = port_num;
1415
1409 /* Hook up MII support for ethtool */ 1416 /* Hook up MII support for ethtool */
1410 mp->mii.dev = dev; 1417 mp->mii.dev = dev;
1411 mp->mii.mdio_read = mv643xx_mdio_read; 1418 mp->mii.mdio_read = mv643xx_mdio_read;
diff --git a/drivers/net/mv643xx_eth.h b/drivers/net/mv643xx_eth.h
index 33c5fafdbb..7d4e90cf49 100644
--- a/drivers/net/mv643xx_eth.h
+++ b/drivers/net/mv643xx_eth.h
@@ -9,6 +9,8 @@
9 9
10#include <linux/mv643xx.h> 10#include <linux/mv643xx.h>
11 11
12#include <asm/dma-mapping.h>
13
12/* Checksum offload for Tx works for most packets, but 14/* Checksum offload for Tx works for most packets, but
13 * fails if previous packet sent did not use hw csum 15 * fails if previous packet sent did not use hw csum
14 */ 16 */
@@ -42,23 +44,12 @@
42#define MAX_DESCS_PER_SKB 1 44#define MAX_DESCS_PER_SKB 1
43#endif 45#endif
44 46
45/*
46 * The MV643XX HW requires 8-byte alignment. However, when I/O
47 * is non-cache-coherent, we need to ensure that the I/O buffers
48 * we use don't share cache lines with other data.
49 */
50#if defined(CONFIG_DMA_NONCOHERENT) || defined(CONFIG_NOT_COHERENT_CACHE)
51#define ETH_DMA_ALIGN L1_CACHE_BYTES
52#else
53#define ETH_DMA_ALIGN 8
54#endif
55
56#define ETH_VLAN_HLEN 4 47#define ETH_VLAN_HLEN 4
57#define ETH_FCS_LEN 4 48#define ETH_FCS_LEN 4
58#define ETH_HW_IP_ALIGN 2 /* hw aligns IP header */ 49#define ETH_HW_IP_ALIGN 2 /* hw aligns IP header */
59#define ETH_WRAPPER_LEN (ETH_HW_IP_ALIGN + ETH_HLEN + \ 50#define ETH_WRAPPER_LEN (ETH_HW_IP_ALIGN + ETH_HLEN + \
60 ETH_VLAN_HLEN + ETH_FCS_LEN) 51 ETH_VLAN_HLEN + ETH_FCS_LEN)
61#define ETH_RX_SKB_SIZE (dev->mtu + ETH_WRAPPER_LEN + ETH_DMA_ALIGN) 52#define ETH_RX_SKB_SIZE (dev->mtu + ETH_WRAPPER_LEN + dma_get_cache_alignment())
62 53
63#define ETH_RX_QUEUES_ENABLED (1 << 0) /* use only Q0 for receive */ 54#define ETH_RX_QUEUES_ENABLED (1 << 0) /* use only Q0 for receive */
64#define ETH_TX_QUEUES_ENABLED (1 << 0) /* use only Q0 for transmit */ 55#define ETH_TX_QUEUES_ENABLED (1 << 0) /* use only Q0 for transmit */
diff --git a/drivers/net/myri10ge/myri10ge.c b/drivers/net/myri10ge/myri10ge.c
index 030924fb1a..ac02b3b60f 100644
--- a/drivers/net/myri10ge/myri10ge.c
+++ b/drivers/net/myri10ge/myri10ge.c
@@ -1,7 +1,7 @@
1/************************************************************************* 1/*************************************************************************
2 * myri10ge.c: Myricom Myri-10G Ethernet driver. 2 * myri10ge.c: Myricom Myri-10G Ethernet driver.
3 * 3 *
4 * Copyright (C) 2005, 2006 Myricom, Inc. 4 * Copyright (C) 2005 - 2007 Myricom, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
@@ -16,17 +16,17 @@
16 * may be used to endorse or promote products derived from this software 16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission. 17 * without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 * 30 *
31 * 31 *
32 * If the eeprom on your board is not recent enough, you will need to get a 32 * If the eeprom on your board is not recent enough, you will need to get a
@@ -181,6 +181,7 @@ struct myri10ge_priv {
181 int intr_coal_delay; 181 int intr_coal_delay;
182 __be32 __iomem *intr_coal_delay_ptr; 182 __be32 __iomem *intr_coal_delay_ptr;
183 int mtrr; 183 int mtrr;
184 int wc_enabled;
184 int wake_queue; 185 int wake_queue;
185 int stop_queue; 186 int stop_queue;
186 int down_cnt; 187 int down_cnt;
@@ -195,6 +196,10 @@ struct myri10ge_priv {
195 char *fw_name; 196 char *fw_name;
196 char eeprom_strings[MYRI10GE_EEPROM_STRINGS_SIZE]; 197 char eeprom_strings[MYRI10GE_EEPROM_STRINGS_SIZE];
197 char fw_version[128]; 198 char fw_version[128];
199 int fw_ver_major;
200 int fw_ver_minor;
201 int fw_ver_tiny;
202 int adopted_rx_filter_bug;
198 u8 mac_addr[6]; /* eeprom mac address */ 203 u8 mac_addr[6]; /* eeprom mac address */
199 unsigned long serial_number; 204 unsigned long serial_number;
200 int vendor_specific_offset; 205 int vendor_specific_offset;
@@ -447,7 +452,6 @@ myri10ge_validate_firmware(struct myri10ge_priv *mgp,
447 struct mcp_gen_header *hdr) 452 struct mcp_gen_header *hdr)
448{ 453{
449 struct device *dev = &mgp->pdev->dev; 454 struct device *dev = &mgp->pdev->dev;
450 int major, minor;
451 455
452 /* check firmware type */ 456 /* check firmware type */
453 if (ntohl(hdr->mcp_type) != MCP_TYPE_ETH) { 457 if (ntohl(hdr->mcp_type) != MCP_TYPE_ETH) {
@@ -458,9 +462,11 @@ myri10ge_validate_firmware(struct myri10ge_priv *mgp,
458 /* save firmware version for ethtool */ 462 /* save firmware version for ethtool */
459 strncpy(mgp->fw_version, hdr->version, sizeof(mgp->fw_version)); 463 strncpy(mgp->fw_version, hdr->version, sizeof(mgp->fw_version));
460 464
461 sscanf(mgp->fw_version, "%d.%d", &major, &minor); 465 sscanf(mgp->fw_version, "%d.%d.%d", &mgp->fw_ver_major,
466 &mgp->fw_ver_minor, &mgp->fw_ver_tiny);
462 467
463 if (!(major == MXGEFW_VERSION_MAJOR && minor == MXGEFW_VERSION_MINOR)) { 468 if (!(mgp->fw_ver_major == MXGEFW_VERSION_MAJOR
469 && mgp->fw_ver_minor == MXGEFW_VERSION_MINOR)) {
464 dev_err(dev, "Found firmware version %s\n", mgp->fw_version); 470 dev_err(dev, "Found firmware version %s\n", mgp->fw_version);
465 dev_err(dev, "Driver needs %d.%d\n", MXGEFW_VERSION_MAJOR, 471 dev_err(dev, "Driver needs %d.%d\n", MXGEFW_VERSION_MAJOR,
466 MXGEFW_VERSION_MINOR); 472 MXGEFW_VERSION_MINOR);
@@ -561,6 +567,18 @@ static int myri10ge_adopt_running_firmware(struct myri10ge_priv *mgp)
561 memcpy_fromio(hdr, mgp->sram + hdr_offset, bytes); 567 memcpy_fromio(hdr, mgp->sram + hdr_offset, bytes);
562 status = myri10ge_validate_firmware(mgp, hdr); 568 status = myri10ge_validate_firmware(mgp, hdr);
563 kfree(hdr); 569 kfree(hdr);
570
571 /* check to see if adopted firmware has bug where adopting
572 * it will cause broadcasts to be filtered unless the NIC
573 * is kept in ALLMULTI mode */
574 if (mgp->fw_ver_major == 1 && mgp->fw_ver_minor == 4 &&
575 mgp->fw_ver_tiny >= 4 && mgp->fw_ver_tiny <= 11) {
576 mgp->adopted_rx_filter_bug = 1;
577 dev_warn(dev, "Adopting fw %d.%d.%d: "
578 "working around rx filter bug\n",
579 mgp->fw_ver_major, mgp->fw_ver_minor,
580 mgp->fw_ver_tiny);
581 }
564 return status; 582 return status;
565} 583}
566 584
@@ -700,6 +718,8 @@ static int myri10ge_reset(struct myri10ge_priv *mgp)
700 int status; 718 int status;
701 size_t bytes; 719 size_t bytes;
702 u32 len; 720 u32 len;
721 struct page *dmatest_page;
722 dma_addr_t dmatest_bus;
703 723
704 /* try to send a reset command to the card to see if it 724 /* try to send a reset command to the card to see if it
705 * is alive */ 725 * is alive */
@@ -709,6 +729,11 @@ static int myri10ge_reset(struct myri10ge_priv *mgp)
709 dev_err(&mgp->pdev->dev, "failed reset\n"); 729 dev_err(&mgp->pdev->dev, "failed reset\n");
710 return -ENXIO; 730 return -ENXIO;
711 } 731 }
732 dmatest_page = alloc_page(GFP_KERNEL);
733 if (!dmatest_page)
734 return -ENOMEM;
735 dmatest_bus = pci_map_page(mgp->pdev, dmatest_page, 0, PAGE_SIZE,
736 DMA_BIDIRECTIONAL);
712 737
713 /* Now exchange information about interrupts */ 738 /* Now exchange information about interrupts */
714 739
@@ -747,8 +772,8 @@ static int myri10ge_reset(struct myri10ge_priv *mgp)
747 772
748 len = mgp->tx.boundary; 773 len = mgp->tx.boundary;
749 774
750 cmd.data0 = MYRI10GE_LOWPART_TO_U32(mgp->rx_done.bus); 775 cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
751 cmd.data1 = MYRI10GE_HIGHPART_TO_U32(mgp->rx_done.bus); 776 cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
752 cmd.data2 = len * 0x10000; 777 cmd.data2 = len * 0x10000;
753 status = myri10ge_send_cmd(mgp, MXGEFW_DMA_TEST, &cmd, 0); 778 status = myri10ge_send_cmd(mgp, MXGEFW_DMA_TEST, &cmd, 0);
754 if (status == 0) 779 if (status == 0)
@@ -757,8 +782,8 @@ static int myri10ge_reset(struct myri10ge_priv *mgp)
757 else 782 else
758 dev_warn(&mgp->pdev->dev, "DMA read benchmark failed: %d\n", 783 dev_warn(&mgp->pdev->dev, "DMA read benchmark failed: %d\n",
759 status); 784 status);
760 cmd.data0 = MYRI10GE_LOWPART_TO_U32(mgp->rx_done.bus); 785 cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
761 cmd.data1 = MYRI10GE_HIGHPART_TO_U32(mgp->rx_done.bus); 786 cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
762 cmd.data2 = len * 0x1; 787 cmd.data2 = len * 0x1;
763 status = myri10ge_send_cmd(mgp, MXGEFW_DMA_TEST, &cmd, 0); 788 status = myri10ge_send_cmd(mgp, MXGEFW_DMA_TEST, &cmd, 0);
764 if (status == 0) 789 if (status == 0)
@@ -768,8 +793,8 @@ static int myri10ge_reset(struct myri10ge_priv *mgp)
768 dev_warn(&mgp->pdev->dev, "DMA write benchmark failed: %d\n", 793 dev_warn(&mgp->pdev->dev, "DMA write benchmark failed: %d\n",
769 status); 794 status);
770 795
771 cmd.data0 = MYRI10GE_LOWPART_TO_U32(mgp->rx_done.bus); 796 cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
772 cmd.data1 = MYRI10GE_HIGHPART_TO_U32(mgp->rx_done.bus); 797 cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
773 cmd.data2 = len * 0x10001; 798 cmd.data2 = len * 0x10001;
774 status = myri10ge_send_cmd(mgp, MXGEFW_DMA_TEST, &cmd, 0); 799 status = myri10ge_send_cmd(mgp, MXGEFW_DMA_TEST, &cmd, 0);
775 if (status == 0) 800 if (status == 0)
@@ -779,6 +804,9 @@ static int myri10ge_reset(struct myri10ge_priv *mgp)
779 dev_warn(&mgp->pdev->dev, 804 dev_warn(&mgp->pdev->dev,
780 "DMA read/write benchmark failed: %d\n", status); 805 "DMA read/write benchmark failed: %d\n", status);
781 806
807 pci_unmap_page(mgp->pdev, dmatest_bus, PAGE_SIZE, DMA_BIDIRECTIONAL);
808 put_page(dmatest_page);
809
782 memset(mgp->rx_done.entry, 0, bytes); 810 memset(mgp->rx_done.entry, 0, bytes);
783 811
784 /* reset mcp/driver shared state back to 0 */ 812 /* reset mcp/driver shared state back to 0 */
@@ -794,6 +822,8 @@ static int myri10ge_reset(struct myri10ge_priv *mgp)
794 status = myri10ge_update_mac_address(mgp, mgp->dev->dev_addr); 822 status = myri10ge_update_mac_address(mgp, mgp->dev->dev_addr);
795 myri10ge_change_promisc(mgp, 0, 0); 823 myri10ge_change_promisc(mgp, 0, 0);
796 myri10ge_change_pause(mgp, mgp->pause); 824 myri10ge_change_pause(mgp, mgp->pause);
825 if (mgp->adopted_rx_filter_bug)
826 (void)myri10ge_send_cmd(mgp, MXGEFW_ENABLE_ALLMULTI, &cmd, 1);
797 return status; 827 return status;
798} 828}
799 829
@@ -1356,7 +1386,7 @@ myri10ge_get_ethtool_stats(struct net_device *netdev,
1356 data[i] = ((unsigned long *)&mgp->stats)[i]; 1386 data[i] = ((unsigned long *)&mgp->stats)[i];
1357 1387
1358 data[i++] = (unsigned int)mgp->tx.boundary; 1388 data[i++] = (unsigned int)mgp->tx.boundary;
1359 data[i++] = (unsigned int)(mgp->mtrr >= 0); 1389 data[i++] = (unsigned int)mgp->wc_enabled;
1360 data[i++] = (unsigned int)mgp->pdev->irq; 1390 data[i++] = (unsigned int)mgp->pdev->irq;
1361 data[i++] = (unsigned int)mgp->msi_enabled; 1391 data[i++] = (unsigned int)mgp->msi_enabled;
1362 data[i++] = (unsigned int)mgp->read_dma; 1392 data[i++] = (unsigned int)mgp->read_dma;
@@ -1437,6 +1467,8 @@ static int myri10ge_allocate_rings(struct net_device *dev)
1437 status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SEND_RING_SIZE, &cmd, 0); 1467 status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SEND_RING_SIZE, &cmd, 0);
1438 tx_ring_size = cmd.data0; 1468 tx_ring_size = cmd.data0;
1439 status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_RX_RING_SIZE, &cmd, 0); 1469 status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_RX_RING_SIZE, &cmd, 0);
1470 if (status != 0)
1471 return status;
1440 rx_ring_size = cmd.data0; 1472 rx_ring_size = cmd.data0;
1441 1473
1442 tx_ring_entries = tx_ring_size / sizeof(struct mcp_kreq_ether_send); 1474 tx_ring_entries = tx_ring_size / sizeof(struct mcp_kreq_ether_send);
@@ -1444,6 +1476,8 @@ static int myri10ge_allocate_rings(struct net_device *dev)
1444 mgp->tx.mask = tx_ring_entries - 1; 1476 mgp->tx.mask = tx_ring_entries - 1;
1445 mgp->rx_small.mask = mgp->rx_big.mask = rx_ring_entries - 1; 1477 mgp->rx_small.mask = mgp->rx_big.mask = rx_ring_entries - 1;
1446 1478
1479 status = -ENOMEM;
1480
1447 /* allocate the host shadow rings */ 1481 /* allocate the host shadow rings */
1448 1482
1449 bytes = 8 + (MYRI10GE_MAX_SEND_DESC_TSO + 4) 1483 bytes = 8 + (MYRI10GE_MAX_SEND_DESC_TSO + 4)
@@ -1716,7 +1750,7 @@ static int myri10ge_open(struct net_device *dev)
1716 goto abort_with_irq; 1750 goto abort_with_irq;
1717 } 1751 }
1718 1752
1719 if (myri10ge_wcfifo && mgp->mtrr >= 0) { 1753 if (myri10ge_wcfifo && mgp->wc_enabled) {
1720 mgp->tx.wc_fifo = (u8 __iomem *) mgp->sram + MXGEFW_ETH_SEND_4; 1754 mgp->tx.wc_fifo = (u8 __iomem *) mgp->sram + MXGEFW_ETH_SEND_4;
1721 mgp->rx_small.wc_fifo = 1755 mgp->rx_small.wc_fifo =
1722 (u8 __iomem *) mgp->sram + MXGEFW_ETH_RECV_SMALL; 1756 (u8 __iomem *) mgp->sram + MXGEFW_ETH_RECV_SMALL;
@@ -2239,7 +2273,7 @@ static void myri10ge_set_multicast_list(struct net_device *dev)
2239 myri10ge_change_promisc(mgp, dev->flags & IFF_PROMISC, 1); 2273 myri10ge_change_promisc(mgp, dev->flags & IFF_PROMISC, 1);
2240 2274
2241 /* This firmware is known to not support multicast */ 2275 /* This firmware is known to not support multicast */
2242 if (!mgp->fw_multicast_support) 2276 if (!mgp->fw_multicast_support || mgp->adopted_rx_filter_bug)
2243 return; 2277 return;
2244 2278
2245 /* Disable multicast filtering */ 2279 /* Disable multicast filtering */
@@ -2491,6 +2525,12 @@ static void myri10ge_select_firmware(struct myri10ge_priv *mgp)
2491 bridge->vendor, bridge->device); 2525 bridge->vendor, bridge->device);
2492 mgp->tx.boundary = 4096; 2526 mgp->tx.boundary = 4096;
2493 mgp->fw_name = myri10ge_fw_aligned; 2527 mgp->fw_name = myri10ge_fw_aligned;
2528 } else if (bridge &&
2529 bridge->vendor == PCI_VENDOR_ID_SGI &&
2530 bridge->device == 0x4002 /* TIOCE pcie-port */ ) {
2531 /* this pcie bridge does not support 4K rdma request */
2532 mgp->tx.boundary = 2048;
2533 mgp->fw_name = myri10ge_fw_aligned;
2494 } 2534 }
2495 } else { 2535 } else {
2496 if (myri10ge_force_firmware == 1) { 2536 if (myri10ge_force_firmware == 1) {
@@ -2811,9 +2851,12 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2811 mgp->board_span = pci_resource_len(pdev, 0); 2851 mgp->board_span = pci_resource_len(pdev, 0);
2812 mgp->iomem_base = pci_resource_start(pdev, 0); 2852 mgp->iomem_base = pci_resource_start(pdev, 0);
2813 mgp->mtrr = -1; 2853 mgp->mtrr = -1;
2854 mgp->wc_enabled = 0;
2814#ifdef CONFIG_MTRR 2855#ifdef CONFIG_MTRR
2815 mgp->mtrr = mtrr_add(mgp->iomem_base, mgp->board_span, 2856 mgp->mtrr = mtrr_add(mgp->iomem_base, mgp->board_span,
2816 MTRR_TYPE_WRCOMB, 1); 2857 MTRR_TYPE_WRCOMB, 1);
2858 if (mgp->mtrr >= 0)
2859 mgp->wc_enabled = 1;
2817#endif 2860#endif
2818 /* Hack. need to get rid of these magic numbers */ 2861 /* Hack. need to get rid of these magic numbers */
2819 mgp->sram_size = 2862 mgp->sram_size =
@@ -2908,7 +2951,7 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2908 dev_info(dev, "%s IRQ %d, tx bndry %d, fw %s, WC %s\n", 2951 dev_info(dev, "%s IRQ %d, tx bndry %d, fw %s, WC %s\n",
2909 (mgp->msi_enabled ? "MSI" : "xPIC"), 2952 (mgp->msi_enabled ? "MSI" : "xPIC"),
2910 netdev->irq, mgp->tx.boundary, mgp->fw_name, 2953 netdev->irq, mgp->tx.boundary, mgp->fw_name,
2911 (mgp->mtrr >= 0 ? "Enabled" : "Disabled")); 2954 (mgp->wc_enabled ? "Enabled" : "Disabled"));
2912 2955
2913 return 0; 2956 return 0;
2914 2957
diff --git a/drivers/net/natsemi.c b/drivers/net/natsemi.c
index ffa0afd2ed..c6172a77a6 100644
--- a/drivers/net/natsemi.c
+++ b/drivers/net/natsemi.c
@@ -244,6 +244,9 @@ enum {
244 MII_EN_SCRM = 0x0004, /* enable scrambler (tp) */ 244 MII_EN_SCRM = 0x0004, /* enable scrambler (tp) */
245}; 245};
246 246
247enum {
248 NATSEMI_FLAG_IGNORE_PHY = 0x1,
249};
247 250
248/* array of board data directly indexed by pci_tbl[x].driver_data */ 251/* array of board data directly indexed by pci_tbl[x].driver_data */
249static const struct { 252static const struct {
@@ -251,11 +254,13 @@ static const struct {
251 unsigned long flags; 254 unsigned long flags;
252 unsigned int eeprom_size; 255 unsigned int eeprom_size;
253} natsemi_pci_info[] __devinitdata = { 256} natsemi_pci_info[] __devinitdata = {
257 { "Aculab E1/T1 PMXc cPCI carrier card", NATSEMI_FLAG_IGNORE_PHY, 128 },
254 { "NatSemi DP8381[56]", 0, 24 }, 258 { "NatSemi DP8381[56]", 0, 24 },
255}; 259};
256 260
257static const struct pci_device_id natsemi_pci_tbl[] __devinitdata = { 261static const struct pci_device_id natsemi_pci_tbl[] __devinitdata = {
258 { PCI_VENDOR_ID_NS, 0x0020, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 262 { PCI_VENDOR_ID_NS, 0x0020, 0x12d9, 0x000c, 0, 0, 0 },
263 { PCI_VENDOR_ID_NS, 0x0020, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
259 { } /* terminate list */ 264 { } /* terminate list */
260}; 265};
261MODULE_DEVICE_TABLE(pci, natsemi_pci_tbl); 266MODULE_DEVICE_TABLE(pci, natsemi_pci_tbl);
@@ -568,6 +573,8 @@ struct netdev_private {
568 u32 intr_status; 573 u32 intr_status;
569 /* Do not touch the nic registers */ 574 /* Do not touch the nic registers */
570 int hands_off; 575 int hands_off;
576 /* Don't pay attention to the reported link state. */
577 int ignore_phy;
571 /* external phy that is used: only valid if dev->if_port != PORT_TP */ 578 /* external phy that is used: only valid if dev->if_port != PORT_TP */
572 int mii; 579 int mii;
573 int phy_addr_external; 580 int phy_addr_external;
@@ -696,7 +703,10 @@ static void __devinit natsemi_init_media (struct net_device *dev)
696 struct netdev_private *np = netdev_priv(dev); 703 struct netdev_private *np = netdev_priv(dev);
697 u32 tmp; 704 u32 tmp;
698 705
699 netif_carrier_off(dev); 706 if (np->ignore_phy)
707 netif_carrier_on(dev);
708 else
709 netif_carrier_off(dev);
700 710
701 /* get the initial settings from hardware */ 711 /* get the initial settings from hardware */
702 tmp = mdio_read(dev, MII_BMCR); 712 tmp = mdio_read(dev, MII_BMCR);
@@ -806,8 +816,13 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
806 np->hands_off = 0; 816 np->hands_off = 0;
807 np->intr_status = 0; 817 np->intr_status = 0;
808 np->eeprom_size = natsemi_pci_info[chip_idx].eeprom_size; 818 np->eeprom_size = natsemi_pci_info[chip_idx].eeprom_size;
819 if (natsemi_pci_info[chip_idx].flags & NATSEMI_FLAG_IGNORE_PHY)
820 np->ignore_phy = 1;
821 else
822 np->ignore_phy = 0;
809 823
810 /* Initial port: 824 /* Initial port:
825 * - If configured to ignore the PHY set up for external.
811 * - If the nic was configured to use an external phy and if find_mii 826 * - If the nic was configured to use an external phy and if find_mii
812 * finds a phy: use external port, first phy that replies. 827 * finds a phy: use external port, first phy that replies.
813 * - Otherwise: internal port. 828 * - Otherwise: internal port.
@@ -815,7 +830,7 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
815 * The address would be used to access a phy over the mii bus, but 830 * The address would be used to access a phy over the mii bus, but
816 * the internal phy is accessed through mapped registers. 831 * the internal phy is accessed through mapped registers.
817 */ 832 */
818 if (readl(ioaddr + ChipConfig) & CfgExtPhy) 833 if (np->ignore_phy || readl(ioaddr + ChipConfig) & CfgExtPhy)
819 dev->if_port = PORT_MII; 834 dev->if_port = PORT_MII;
820 else 835 else
821 dev->if_port = PORT_TP; 836 dev->if_port = PORT_TP;
@@ -825,7 +840,9 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
825 840
826 if (dev->if_port != PORT_TP) { 841 if (dev->if_port != PORT_TP) {
827 np->phy_addr_external = find_mii(dev); 842 np->phy_addr_external = find_mii(dev);
828 if (np->phy_addr_external == PHY_ADDR_NONE) { 843 /* If we're ignoring the PHY it doesn't matter if we can't
844 * find one. */
845 if (!np->ignore_phy && np->phy_addr_external == PHY_ADDR_NONE) {
829 dev->if_port = PORT_TP; 846 dev->if_port = PORT_TP;
830 np->phy_addr_external = PHY_ADDR_INTERNAL; 847 np->phy_addr_external = PHY_ADDR_INTERNAL;
831 } 848 }
@@ -891,6 +908,8 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
891 printk("%02x, IRQ %d", dev->dev_addr[i], irq); 908 printk("%02x, IRQ %d", dev->dev_addr[i], irq);
892 if (dev->if_port == PORT_TP) 909 if (dev->if_port == PORT_TP)
893 printk(", port TP.\n"); 910 printk(", port TP.\n");
911 else if (np->ignore_phy)
912 printk(", port MII, ignoring PHY\n");
894 else 913 else
895 printk(", port MII, phy ad %d.\n", np->phy_addr_external); 914 printk(", port MII, phy ad %d.\n", np->phy_addr_external);
896 } 915 }
@@ -1571,9 +1590,13 @@ static void check_link(struct net_device *dev)
1571{ 1590{
1572 struct netdev_private *np = netdev_priv(dev); 1591 struct netdev_private *np = netdev_priv(dev);
1573 void __iomem * ioaddr = ns_ioaddr(dev); 1592 void __iomem * ioaddr = ns_ioaddr(dev);
1574 int duplex; 1593 int duplex = np->duplex;
1575 u16 bmsr; 1594 u16 bmsr;
1576 1595
1596 /* If we are ignoring the PHY then don't try reading it. */
1597 if (np->ignore_phy)
1598 goto propagate_state;
1599
1577 /* The link status field is latched: it remains low after a temporary 1600 /* The link status field is latched: it remains low after a temporary
1578 * link failure until it's read. We need the current link status, 1601 * link failure until it's read. We need the current link status,
1579 * thus read twice. 1602 * thus read twice.
@@ -1585,7 +1608,7 @@ static void check_link(struct net_device *dev)
1585 if (netif_carrier_ok(dev)) { 1608 if (netif_carrier_ok(dev)) {
1586 if (netif_msg_link(np)) 1609 if (netif_msg_link(np))
1587 printk(KERN_NOTICE "%s: link down.\n", 1610 printk(KERN_NOTICE "%s: link down.\n",
1588 dev->name); 1611 dev->name);
1589 netif_carrier_off(dev); 1612 netif_carrier_off(dev);
1590 undo_cable_magic(dev); 1613 undo_cable_magic(dev);
1591 } 1614 }
@@ -1609,6 +1632,7 @@ static void check_link(struct net_device *dev)
1609 duplex = 1; 1632 duplex = 1;
1610 } 1633 }
1611 1634
1635propagate_state:
1612 /* if duplex is set then bit 28 must be set, too */ 1636 /* if duplex is set then bit 28 must be set, too */
1613 if (duplex ^ !!(np->rx_config & RxAcceptTx)) { 1637 if (duplex ^ !!(np->rx_config & RxAcceptTx)) {
1614 if (netif_msg_link(np)) 1638 if (netif_msg_link(np))
@@ -2000,6 +2024,7 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
2000 struct netdev_private *np = netdev_priv(dev); 2024 struct netdev_private *np = netdev_priv(dev);
2001 void __iomem * ioaddr = ns_ioaddr(dev); 2025 void __iomem * ioaddr = ns_ioaddr(dev);
2002 unsigned entry; 2026 unsigned entry;
2027 unsigned long flags;
2003 2028
2004 /* Note: Ordering is important here, set the field with the 2029 /* Note: Ordering is important here, set the field with the
2005 "ownership" bit last, and only then increment cur_tx. */ 2030 "ownership" bit last, and only then increment cur_tx. */
@@ -2013,7 +2038,7 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
2013 2038
2014 np->tx_ring[entry].addr = cpu_to_le32(np->tx_dma[entry]); 2039 np->tx_ring[entry].addr = cpu_to_le32(np->tx_dma[entry]);
2015 2040
2016 spin_lock_irq(&np->lock); 2041 spin_lock_irqsave(&np->lock, flags);
2017 2042
2018 if (!np->hands_off) { 2043 if (!np->hands_off) {
2019 np->tx_ring[entry].cmd_status = cpu_to_le32(DescOwn | skb->len); 2044 np->tx_ring[entry].cmd_status = cpu_to_le32(DescOwn | skb->len);
@@ -2032,7 +2057,7 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
2032 dev_kfree_skb_irq(skb); 2057 dev_kfree_skb_irq(skb);
2033 np->stats.tx_dropped++; 2058 np->stats.tx_dropped++;
2034 } 2059 }
2035 spin_unlock_irq(&np->lock); 2060 spin_unlock_irqrestore(&np->lock, flags);
2036 2061
2037 dev->trans_start = jiffies; 2062 dev->trans_start = jiffies;
2038 2063
@@ -2198,6 +2223,8 @@ static void netdev_rx(struct net_device *dev, int *work_done, int work_to_do)
2198 pkt_len = (desc_status & DescSizeMask) - 4; 2223 pkt_len = (desc_status & DescSizeMask) - 4;
2199 if ((desc_status&(DescMore|DescPktOK|DescRxLong)) != DescPktOK){ 2224 if ((desc_status&(DescMore|DescPktOK|DescRxLong)) != DescPktOK){
2200 if (desc_status & DescMore) { 2225 if (desc_status & DescMore) {
2226 unsigned long flags;
2227
2201 if (netif_msg_rx_err(np)) 2228 if (netif_msg_rx_err(np))
2202 printk(KERN_WARNING 2229 printk(KERN_WARNING
2203 "%s: Oversized(?) Ethernet " 2230 "%s: Oversized(?) Ethernet "
@@ -2212,12 +2239,12 @@ static void netdev_rx(struct net_device *dev, int *work_done, int work_to_do)
2212 * reset procedure documented in 2239 * reset procedure documented in
2213 * AN-1287. */ 2240 * AN-1287. */
2214 2241
2215 spin_lock_irq(&np->lock); 2242 spin_lock_irqsave(&np->lock, flags);
2216 reset_rx(dev); 2243 reset_rx(dev);
2217 reinit_rx(dev); 2244 reinit_rx(dev);
2218 writel(np->ring_dma, ioaddr + RxRingPtr); 2245 writel(np->ring_dma, ioaddr + RxRingPtr);
2219 check_link(dev); 2246 check_link(dev);
2220 spin_unlock_irq(&np->lock); 2247 spin_unlock_irqrestore(&np->lock, flags);
2221 2248
2222 /* We'll enable RX on exit from this 2249 /* We'll enable RX on exit from this
2223 * function. */ 2250 * function. */
@@ -2372,8 +2399,19 @@ static struct net_device_stats *get_stats(struct net_device *dev)
2372#ifdef CONFIG_NET_POLL_CONTROLLER 2399#ifdef CONFIG_NET_POLL_CONTROLLER
2373static void natsemi_poll_controller(struct net_device *dev) 2400static void natsemi_poll_controller(struct net_device *dev)
2374{ 2401{
2402 struct netdev_private *np = netdev_priv(dev);
2403
2375 disable_irq(dev->irq); 2404 disable_irq(dev->irq);
2376 intr_handler(dev->irq, dev); 2405
2406 /*
2407 * A real interrupt might have already reached us at this point
2408 * but NAPI might still haven't called us back. As the interrupt
2409 * status register is cleared by reading, we should prevent an
2410 * interrupt loss in this case...
2411 */
2412 if (!np->intr_status)
2413 intr_handler(dev->irq, dev);
2414
2377 enable_irq(dev->irq); 2415 enable_irq(dev->irq);
2378} 2416}
2379#endif 2417#endif
@@ -2819,6 +2857,15 @@ static int netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2819 } 2857 }
2820 2858
2821 /* 2859 /*
2860 * If we're ignoring the PHY then autoneg and the internal
2861 * transciever are really not going to work so don't let the
2862 * user select them.
2863 */
2864 if (np->ignore_phy && (ecmd->autoneg == AUTONEG_ENABLE ||
2865 ecmd->port == PORT_TP))
2866 return -EINVAL;
2867
2868 /*
2822 * maxtxpkt, maxrxpkt: ignored for now. 2869 * maxtxpkt, maxrxpkt: ignored for now.
2823 * 2870 *
2824 * transceiver: 2871 * transceiver:
diff --git a/drivers/net/netxen/netxen_nic.h b/drivers/net/netxen/netxen_nic.h
index 3f3896e988..81742e4e56 100644
--- a/drivers/net/netxen/netxen_nic.h
+++ b/drivers/net/netxen/netxen_nic.h
@@ -72,6 +72,8 @@
72#define FLASH_SECTOR_SIZE (64 * 1024) 72#define FLASH_SECTOR_SIZE (64 * 1024)
73#define FLASH_TOTAL_SIZE (NUM_FLASH_SECTORS * FLASH_SECTOR_SIZE) 73#define FLASH_TOTAL_SIZE (NUM_FLASH_SECTORS * FLASH_SECTOR_SIZE)
74 74
75#define PHAN_VENDOR_ID 0x4040
76
75#define RCV_DESC_RINGSIZE \ 77#define RCV_DESC_RINGSIZE \
76 (sizeof(struct rcv_desc) * adapter->max_rx_desc_count) 78 (sizeof(struct rcv_desc) * adapter->max_rx_desc_count)
77#define STATUS_DESC_RINGSIZE \ 79#define STATUS_DESC_RINGSIZE \
@@ -82,7 +84,7 @@
82 (sizeof(struct netxen_cmd_buffer) * adapter->max_tx_desc_count) 84 (sizeof(struct netxen_cmd_buffer) * adapter->max_tx_desc_count)
83#define RCV_BUFFSIZE \ 85#define RCV_BUFFSIZE \
84 (sizeof(struct netxen_rx_buffer) * rcv_desc->max_rx_desc_count) 86 (sizeof(struct netxen_rx_buffer) * rcv_desc->max_rx_desc_count)
85#define find_diff_among(a,b,range) ((a)<(b)?((b)-(a)):((b)+(range)-(a))) 87#define find_diff_among(a,b,range) ((a)<=(b)?((b)-(a)):((b)+(range)-(a)))
86 88
87#define NETXEN_NETDEV_STATUS 0x1 89#define NETXEN_NETDEV_STATUS 0x1
88#define NETXEN_RCV_PRODUCER_OFFSET 0 90#define NETXEN_RCV_PRODUCER_OFFSET 0
@@ -252,7 +254,7 @@ typedef u32 netxen_ctx_msg;
252#define netxen_set_msg_ctxid(config_word, val) \ 254#define netxen_set_msg_ctxid(config_word, val) \
253 ((config_word) &= ~(0x3ff<<18), (config_word) |= (val & 0x3ff) << 18) 255 ((config_word) &= ~(0x3ff<<18), (config_word) |= (val & 0x3ff) << 18)
254#define netxen_set_msg_opcode(config_word, val) \ 256#define netxen_set_msg_opcode(config_word, val) \
255 ((config_word) &= ~(0xf<<24), (config_word) |= (val & 0xf) << 24) 257 ((config_word) &= ~(0xf<<28), (config_word) |= (val & 0xf) << 28)
256 258
257struct netxen_rcv_context { 259struct netxen_rcv_context {
258 __le64 rcv_ring_addr; 260 __le64 rcv_ring_addr;
@@ -303,14 +305,14 @@ struct netxen_ring_ctx {
303 (cmd_desc)->flags_opcode |= cpu_to_le16((val) & 0x7f)) 305 (cmd_desc)->flags_opcode |= cpu_to_le16((val) & 0x7f))
304#define netxen_set_cmd_desc_opcode(cmd_desc, val) \ 306#define netxen_set_cmd_desc_opcode(cmd_desc, val) \
305 ((cmd_desc)->flags_opcode &= ~cpu_to_le16(0x3f<<7), \ 307 ((cmd_desc)->flags_opcode &= ~cpu_to_le16(0x3f<<7), \
306 (cmd_desc)->flags_opcode |= cpu_to_le16((val) & (0x3f<<7))) 308 (cmd_desc)->flags_opcode |= cpu_to_le16(((val & 0x3f)<<7)))
307 309
308#define netxen_set_cmd_desc_num_of_buff(cmd_desc, val) \ 310#define netxen_set_cmd_desc_num_of_buff(cmd_desc, val) \
309 ((cmd_desc)->num_of_buffers_total_length &= ~cpu_to_le32(0xff), \ 311 ((cmd_desc)->num_of_buffers_total_length &= ~cpu_to_le32(0xff), \
310 (cmd_desc)->num_of_buffers_total_length |= cpu_to_le32((val) & 0xff)) 312 (cmd_desc)->num_of_buffers_total_length |= cpu_to_le32((val) & 0xff))
311#define netxen_set_cmd_desc_totallength(cmd_desc, val) \ 313#define netxen_set_cmd_desc_totallength(cmd_desc, val) \
312 ((cmd_desc)->num_of_buffers_total_length &= cpu_to_le32(0xff), \ 314 ((cmd_desc)->num_of_buffers_total_length &= ~cpu_to_le32(0xffffff00), \
313 (cmd_desc)->num_of_buffers_total_length |= cpu_to_le32(val << 24)) 315 (cmd_desc)->num_of_buffers_total_length |= cpu_to_le32(val << 8))
314 316
315#define netxen_get_cmd_desc_opcode(cmd_desc) \ 317#define netxen_get_cmd_desc_opcode(cmd_desc) \
316 ((le16_to_cpu((cmd_desc)->flags_opcode) >> 7) & 0x003F) 318 ((le16_to_cpu((cmd_desc)->flags_opcode) >> 7) & 0x003F)
@@ -1040,6 +1042,7 @@ int netxen_flash_unlock(struct netxen_adapter *adapter);
1040int netxen_backup_crbinit(struct netxen_adapter *adapter); 1042int netxen_backup_crbinit(struct netxen_adapter *adapter);
1041int netxen_flash_erase_secondary(struct netxen_adapter *adapter); 1043int netxen_flash_erase_secondary(struct netxen_adapter *adapter);
1042int netxen_flash_erase_primary(struct netxen_adapter *adapter); 1044int netxen_flash_erase_primary(struct netxen_adapter *adapter);
1045void netxen_halt_pegs(struct netxen_adapter *adapter);
1043 1046
1044int netxen_rom_fast_write(struct netxen_adapter *adapter, int addr, int data); 1047int netxen_rom_fast_write(struct netxen_adapter *adapter, int addr, int data);
1045int netxen_rom_se(struct netxen_adapter *adapter, int addr); 1048int netxen_rom_se(struct netxen_adapter *adapter, int addr);
diff --git a/drivers/net/netxen/netxen_nic_ethtool.c b/drivers/net/netxen/netxen_nic_ethtool.c
index cc0efe213e..986ef98db2 100644
--- a/drivers/net/netxen/netxen_nic_ethtool.c
+++ b/drivers/net/netxen/netxen_nic_ethtool.c
@@ -82,8 +82,7 @@ static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
82#define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats) 82#define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
83 83
84static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = { 84static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
85 "Register_Test_offline", "EEPROM_Test_offline", 85 "Register_Test_on_offline",
86 "Interrupt_Test_offline", "Loopback_Test_offline",
87 "Link_Test_on_offline" 86 "Link_Test_on_offline"
88}; 87};
89 88
@@ -394,19 +393,12 @@ netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
394 } 393 }
395} 394}
396 395
397static void 396static u32 netxen_nic_test_link(struct net_device *dev)
398netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
399{
400 wol->supported = WAKE_UCAST | WAKE_MCAST | WAKE_BCAST | WAKE_MAGIC;
401 /* options can be added depending upon the mode */
402 wol->wolopts = 0;
403}
404
405static u32 netxen_nic_get_link(struct net_device *dev)
406{ 397{
407 struct netxen_port *port = netdev_priv(dev); 398 struct netxen_port *port = netdev_priv(dev);
408 struct netxen_adapter *adapter = port->adapter; 399 struct netxen_adapter *adapter = port->adapter;
409 __u32 status; 400 __u32 status;
401 int val;
410 402
411 /* read which mode */ 403 /* read which mode */
412 if (adapter->ahw.board_type == NETXEN_NIC_GBE) { 404 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
@@ -415,11 +407,13 @@ static u32 netxen_nic_get_link(struct net_device *dev)
415 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, 407 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
416 &status) != 0) 408 &status) != 0)
417 return -EIO; 409 return -EIO;
418 else 410 else {
419 return (netxen_get_phy_link(status)); 411 val = netxen_get_phy_link(status);
412 return !val;
413 }
420 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) { 414 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
421 int val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE)); 415 val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
422 return val == XG_LINK_UP; 416 return (val == XG_LINK_UP) ? 0 : 1;
423 } 417 }
424 return -EIO; 418 return -EIO;
425} 419}
@@ -459,6 +453,7 @@ netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
459 int ret; 453 int ret;
460 454
461 if (flash_start == 0) { 455 if (flash_start == 0) {
456 netxen_halt_pegs(adapter);
462 ret = netxen_flash_unlock(adapter); 457 ret = netxen_flash_unlock(adapter);
463 if (ret < 0) { 458 if (ret < 0) {
464 printk(KERN_ERR "%s: Flash unlock failed.\n", 459 printk(KERN_ERR "%s: Flash unlock failed.\n",
@@ -605,100 +600,21 @@ netxen_nic_set_pauseparam(struct net_device *dev,
605 600
606static int netxen_nic_reg_test(struct net_device *dev) 601static int netxen_nic_reg_test(struct net_device *dev)
607{ 602{
608 struct netxen_port *port = netdev_priv(dev); 603 struct netxen_adapter *adapter = netdev_priv(dev);
609 struct netxen_adapter *adapter = port->adapter; 604 u32 data_read, data_written;
610 u32 data_read, data_written, save;
611 __u32 mode;
612
613 /*
614 * first test the "Read Only" registers by writing which mode
615 */
616 netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, &mode);
617 if (netxen_get_niu_enable_ge(mode)) { /* GB Mode */
618 netxen_nic_read_w0(adapter,
619 NETXEN_NIU_GB_MII_MGMT_STATUS(port->portnum),
620 &data_read);
621
622 save = data_read;
623 if (data_read)
624 data_written = data_read & NETXEN_NIC_INVALID_DATA;
625 else
626 data_written = NETXEN_NIC_INVALID_DATA;
627 netxen_nic_write_w0(adapter,
628 NETXEN_NIU_GB_MII_MGMT_STATUS(port->
629 portnum),
630 data_written);
631 netxen_nic_read_w0(adapter,
632 NETXEN_NIU_GB_MII_MGMT_STATUS(port->portnum),
633 &data_read);
634
635 if (data_written == data_read) {
636 netxen_nic_write_w0(adapter,
637 NETXEN_NIU_GB_MII_MGMT_STATUS(port->
638 portnum),
639 save);
640
641 return 0;
642 }
643
644 /* netxen_niu_gb_mii_mgmt_indicators is read only */
645 netxen_nic_read_w0(adapter,
646 NETXEN_NIU_GB_MII_MGMT_INDICATE(port->
647 portnum),
648 &data_read);
649
650 save = data_read;
651 if (data_read)
652 data_written = data_read & NETXEN_NIC_INVALID_DATA;
653 else
654 data_written = NETXEN_NIC_INVALID_DATA;
655 netxen_nic_write_w0(adapter,
656 NETXEN_NIU_GB_MII_MGMT_INDICATE(port->
657 portnum),
658 data_written);
659
660 netxen_nic_read_w0(adapter,
661 NETXEN_NIU_GB_MII_MGMT_INDICATE(port->
662 portnum),
663 &data_read);
664
665 if (data_written == data_read) {
666 netxen_nic_write_w0(adapter,
667 NETXEN_NIU_GB_MII_MGMT_INDICATE
668 (port->portnum), save);
669 return 0;
670 }
671 605
672 /* netxen_niu_gb_interface_status is read only */ 606 netxen_nic_read_w0(adapter, NETXEN_PCIX_PH_REG(0), &data_read);
673 netxen_nic_read_w0(adapter, 607 if ((data_read & 0xffff) != PHAN_VENDOR_ID)
674 NETXEN_NIU_GB_INTERFACE_STATUS(port-> 608 return 1;
675 portnum),
676 &data_read);
677 609
678 save = data_read; 610 data_written = (u32)0xa5a5a5a5;
679 if (data_read)
680 data_written = data_read & NETXEN_NIC_INVALID_DATA;
681 else
682 data_written = NETXEN_NIC_INVALID_DATA;
683 netxen_nic_write_w0(adapter,
684 NETXEN_NIU_GB_INTERFACE_STATUS(port->
685 portnum),
686 data_written);
687 611
688 netxen_nic_read_w0(adapter, 612 netxen_nic_reg_write(adapter, CRB_SCRATCHPAD_TEST, data_written);
689 NETXEN_NIU_GB_INTERFACE_STATUS(port-> 613 data_read = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_SCRATCHPAD_TEST));
690 portnum), 614 if (data_written != data_read)
691 &data_read); 615 return 1;
692 616
693 if (data_written == data_read) { 617 return 0;
694 netxen_nic_write_w0(adapter,
695 NETXEN_NIU_GB_INTERFACE_STATUS
696 (port->portnum), save);
697
698 return 0;
699 }
700 } /* GB Mode */
701 return 1;
702} 618}
703 619
704static int netxen_nic_diag_test_count(struct net_device *dev) 620static int netxen_nic_diag_test_count(struct net_device *dev)
@@ -712,26 +628,20 @@ netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
712{ 628{
713 if (eth_test->flags == ETH_TEST_FL_OFFLINE) { /* offline tests */ 629 if (eth_test->flags == ETH_TEST_FL_OFFLINE) { /* offline tests */
714 /* link test */ 630 /* link test */
715 if (!(data[4] = (u64) netxen_nic_get_link(dev))) 631 if ((data[1] = (u64) netxen_nic_test_link(dev)))
716 eth_test->flags |= ETH_TEST_FL_FAILED; 632 eth_test->flags |= ETH_TEST_FL_FAILED;
717 633
718 if (netif_running(dev))
719 dev->stop(dev);
720
721 /* register tests */ 634 /* register tests */
722 if (!(data[0] = netxen_nic_reg_test(dev))) 635 if ((data[0] = netxen_nic_reg_test(dev)))
723 eth_test->flags |= ETH_TEST_FL_FAILED; 636 eth_test->flags |= ETH_TEST_FL_FAILED;
724 /* other tests pass as of now */
725 data[1] = data[2] = data[3] = 1;
726 if (netif_running(dev))
727 dev->open(dev);
728 } else { /* online tests */ 637 } else { /* online tests */
729 /* link test */ 638 /* register tests */
730 if (!(data[4] = (u64) netxen_nic_get_link(dev))) 639 if((data[0] = netxen_nic_reg_test(dev)))
731 eth_test->flags |= ETH_TEST_FL_FAILED; 640 eth_test->flags |= ETH_TEST_FL_FAILED;
732 641
733 /* other tests pass by default */ 642 /* link test */
734 data[0] = data[1] = data[2] = data[3] = 1; 643 if ((data[1] = (u64) netxen_nic_test_link(dev)))
644 eth_test->flags |= ETH_TEST_FL_FAILED;
735 } 645 }
736} 646}
737 647
@@ -782,8 +692,7 @@ struct ethtool_ops netxen_nic_ethtool_ops = {
782 .get_drvinfo = netxen_nic_get_drvinfo, 692 .get_drvinfo = netxen_nic_get_drvinfo,
783 .get_regs_len = netxen_nic_get_regs_len, 693 .get_regs_len = netxen_nic_get_regs_len,
784 .get_regs = netxen_nic_get_regs, 694 .get_regs = netxen_nic_get_regs,
785 .get_wol = netxen_nic_get_wol, 695 .get_link = ethtool_op_get_link,
786 .get_link = netxen_nic_get_link,
787 .get_eeprom_len = netxen_nic_get_eeprom_len, 696 .get_eeprom_len = netxen_nic_get_eeprom_len,
788 .get_eeprom = netxen_nic_get_eeprom, 697 .get_eeprom = netxen_nic_get_eeprom,
789 .set_eeprom = netxen_nic_set_eeprom, 698 .set_eeprom = netxen_nic_set_eeprom,
diff --git a/drivers/net/netxen/netxen_nic_hw.c b/drivers/net/netxen/netxen_nic_hw.c
index f263232f49..1be5570255 100644
--- a/drivers/net/netxen/netxen_nic_hw.c
+++ b/drivers/net/netxen/netxen_nic_hw.c
@@ -228,7 +228,7 @@ int netxen_nic_hw_resources(struct netxen_adapter *adapter)
228 &adapter->ctx_desc_pdev); 228 &adapter->ctx_desc_pdev);
229 229
230 printk("ctx_desc_phys_addr: 0x%llx\n", 230 printk("ctx_desc_phys_addr: 0x%llx\n",
231 (u64) adapter->ctx_desc_phys_addr); 231 (unsigned long long) adapter->ctx_desc_phys_addr);
232 if (addr == NULL) { 232 if (addr == NULL) {
233 DPRINTK(ERR, "bad return from pci_alloc_consistent\n"); 233 DPRINTK(ERR, "bad return from pci_alloc_consistent\n");
234 err = -ENOMEM; 234 err = -ENOMEM;
@@ -242,11 +242,13 @@ int netxen_nic_hw_resources(struct netxen_adapter *adapter)
242 adapter->cmd_consumer = (uint32_t *) (((char *)addr) + 242 adapter->cmd_consumer = (uint32_t *) (((char *)addr) +
243 sizeof(struct netxen_ring_ctx)); 243 sizeof(struct netxen_ring_ctx));
244 244
245 addr = pci_alloc_consistent(adapter->ahw.pdev, 245 addr = netxen_alloc(adapter->ahw.pdev,
246 sizeof(struct cmd_desc_type0) * 246 sizeof(struct cmd_desc_type0) *
247 adapter->max_tx_desc_count, 247 adapter->max_tx_desc_count,
248 (dma_addr_t *) & hw->cmd_desc_phys_addr); 248 (dma_addr_t *) & hw->cmd_desc_phys_addr,
249 printk("cmd_desc_phys_addr: 0x%llx\n", (u64) hw->cmd_desc_phys_addr); 249 &adapter->ahw.cmd_desc_pdev);
250 printk("cmd_desc_phys_addr: 0x%llx\n",
251 (unsigned long long) hw->cmd_desc_phys_addr);
250 252
251 if (addr == NULL) { 253 if (addr == NULL) {
252 DPRINTK(ERR, "bad return from pci_alloc_consistent\n"); 254 DPRINTK(ERR, "bad return from pci_alloc_consistent\n");
@@ -420,6 +422,7 @@ static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
420 for (i = 0; i < size / sizeof(u32); i++) { 422 for (i = 0; i < size / sizeof(u32); i++) {
421 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) 423 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1)
422 return -1; 424 return -1;
425 *ptr32 = cpu_to_le32(*ptr32);
423 ptr32++; 426 ptr32++;
424 addr += sizeof(u32); 427 addr += sizeof(u32);
425 } 428 }
@@ -428,6 +431,7 @@ static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
428 431
429 if (netxen_rom_fast_read(adapter, addr, &local) == -1) 432 if (netxen_rom_fast_read(adapter, addr, &local) == -1)
430 return -1; 433 return -1;
434 local = cpu_to_le32(local);
431 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32); 435 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
432 } 436 }
433 437
@@ -505,8 +509,8 @@ void netxen_nic_pci_change_crbwindow(struct netxen_adapter *adapter, u32 wndw)
505void netxen_load_firmware(struct netxen_adapter *adapter) 509void netxen_load_firmware(struct netxen_adapter *adapter)
506{ 510{
507 int i; 511 int i;
508 long data, size = 0; 512 u32 data, size = 0;
509 long flashaddr = NETXEN_FLASH_BASE, memaddr = NETXEN_PHANTOM_MEM_BASE; 513 u32 flashaddr = NETXEN_FLASH_BASE, memaddr = NETXEN_PHANTOM_MEM_BASE;
510 u64 off; 514 u64 off;
511 void __iomem *addr; 515 void __iomem *addr;
512 516
@@ -948,6 +952,7 @@ void netxen_nic_flash_print(struct netxen_adapter *adapter)
948 netxen_nic_driver_name); 952 netxen_nic_driver_name);
949 return; 953 return;
950 } 954 }
955 *ptr32 = le32_to_cpu(*ptr32);
951 ptr32++; 956 ptr32++;
952 addr += sizeof(u32); 957 addr += sizeof(u32);
953 } 958 }
diff --git a/drivers/net/netxen/netxen_nic_init.c b/drivers/net/netxen/netxen_nic_init.c
index f7bb8c9053..586d32b676 100644
--- a/drivers/net/netxen/netxen_nic_init.c
+++ b/drivers/net/netxen/netxen_nic_init.c
@@ -38,13 +38,13 @@
38#include "netxen_nic_phan_reg.h" 38#include "netxen_nic_phan_reg.h"
39 39
40struct crb_addr_pair { 40struct crb_addr_pair {
41 long addr; 41 u32 addr;
42 long data; 42 u32 data;
43}; 43};
44 44
45#define NETXEN_MAX_CRB_XFORM 60 45#define NETXEN_MAX_CRB_XFORM 60
46static unsigned int crb_addr_xform[NETXEN_MAX_CRB_XFORM]; 46static unsigned int crb_addr_xform[NETXEN_MAX_CRB_XFORM];
47#define NETXEN_ADDR_ERROR ((unsigned long ) 0xffffffff ) 47#define NETXEN_ADDR_ERROR (0xffffffff)
48 48
49#define crb_addr_transform(name) \ 49#define crb_addr_transform(name) \
50 crb_addr_xform[NETXEN_HW_PX_MAP_CRB_##name] = \ 50 crb_addr_xform[NETXEN_HW_PX_MAP_CRB_##name] = \
@@ -252,10 +252,10 @@ void netxen_initialize_adapter_ops(struct netxen_adapter *adapter)
252 * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB 252 * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB
253 * address to external PCI CRB address. 253 * address to external PCI CRB address.
254 */ 254 */
255unsigned long netxen_decode_crb_addr(unsigned long addr) 255u32 netxen_decode_crb_addr(u32 addr)
256{ 256{
257 int i; 257 int i;
258 unsigned long base_addr, offset, pci_base; 258 u32 base_addr, offset, pci_base;
259 259
260 crb_addr_transform_setup(); 260 crb_addr_transform_setup();
261 261
@@ -499,7 +499,10 @@ static inline int do_rom_fast_write_words(struct netxen_adapter *adapter,
499 while(1) { 499 while(1) {
500 int data1; 500 int data1;
501 501
502 do_rom_fast_read(adapter, addridx, &data1); 502 ret = do_rom_fast_read(adapter, addridx, &data1);
503 if (ret < 0)
504 return ret;
505
503 if (data1 == data) 506 if (data1 == data)
504 break; 507 break;
505 508
@@ -717,6 +720,14 @@ netxen_flash_erase_primary(struct netxen_adapter *adapter)
717 return ret; 720 return ret;
718} 721}
719 722
723void netxen_halt_pegs(struct netxen_adapter *adapter)
724{
725 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_0 + 0x3c, 1);
726 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_1 + 0x3c, 1);
727 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_2 + 0x3c, 1);
728 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_3 + 0x3c, 1);
729}
730
720int netxen_flash_unlock(struct netxen_adapter *adapter) 731int netxen_flash_unlock(struct netxen_adapter *adapter)
721{ 732{
722 int ret = 0; 733 int ret = 0;
@@ -745,7 +756,7 @@ int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose)
745 int n, i; 756 int n, i;
746 int init_delay = 0; 757 int init_delay = 0;
747 struct crb_addr_pair *buf; 758 struct crb_addr_pair *buf;
748 unsigned long off; 759 u32 off;
749 760
750 /* resetall */ 761 /* resetall */
751 status = netxen_nic_get_board_info(adapter); 762 status = netxen_nic_get_board_info(adapter);
@@ -802,14 +813,13 @@ int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose)
802 if (verbose) 813 if (verbose)
803 printk("%s: PCI: 0x%08x == 0x%08x\n", 814 printk("%s: PCI: 0x%08x == 0x%08x\n",
804 netxen_nic_driver_name, (unsigned int) 815 netxen_nic_driver_name, (unsigned int)
805 netxen_decode_crb_addr((unsigned long) 816 netxen_decode_crb_addr(addr), val);
806 addr), val);
807 } 817 }
808 for (i = 0; i < n; i++) { 818 for (i = 0; i < n; i++) {
809 819
810 off = netxen_decode_crb_addr((unsigned long)buf[i].addr); 820 off = netxen_decode_crb_addr(buf[i].addr);
811 if (off == NETXEN_ADDR_ERROR) { 821 if (off == NETXEN_ADDR_ERROR) {
812 printk(KERN_ERR"CRB init value out of range %lx\n", 822 printk(KERN_ERR"CRB init value out of range %x\n",
813 buf[i].addr); 823 buf[i].addr);
814 continue; 824 continue;
815 } 825 }
@@ -916,6 +926,10 @@ int netxen_initialize_adapter_offload(struct netxen_adapter *adapter)
916void netxen_free_adapter_offload(struct netxen_adapter *adapter) 926void netxen_free_adapter_offload(struct netxen_adapter *adapter)
917{ 927{
918 if (adapter->dummy_dma.addr) { 928 if (adapter->dummy_dma.addr) {
929 writel(0, NETXEN_CRB_NORMALIZE(adapter,
930 CRB_HOST_DUMMY_BUF_ADDR_HI));
931 writel(0, NETXEN_CRB_NORMALIZE(adapter,
932 CRB_HOST_DUMMY_BUF_ADDR_LO));
919 pci_free_consistent(adapter->ahw.pdev, 933 pci_free_consistent(adapter->ahw.pdev,
920 NETXEN_HOST_DUMMY_DMA_SIZE, 934 NETXEN_HOST_DUMMY_DMA_SIZE,
921 adapter->dummy_dma.addr, 935 adapter->dummy_dma.addr,
@@ -1246,7 +1260,7 @@ int netxen_process_cmd_ring(unsigned long data)
1246 * the netdev which is associated with that device. 1260 * the netdev which is associated with that device.
1247 */ 1261 */
1248 1262
1249 consumer = *(adapter->cmd_consumer); 1263 consumer = le32_to_cpu(*(adapter->cmd_consumer));
1250 if (last_consumer == consumer) { /* Ring is empty */ 1264 if (last_consumer == consumer) { /* Ring is empty */
1251 DPRINTK(INFO, "last_consumer %d == consumer %d\n", 1265 DPRINTK(INFO, "last_consumer %d == consumer %d\n",
1252 last_consumer, consumer); 1266 last_consumer, consumer);
@@ -1340,7 +1354,7 @@ int netxen_process_cmd_ring(unsigned long data)
1340 if (adapter->last_cmd_consumer == consumer && 1354 if (adapter->last_cmd_consumer == consumer &&
1341 (((adapter->cmd_producer + 1) % 1355 (((adapter->cmd_producer + 1) %
1342 adapter->max_tx_desc_count) == adapter->last_cmd_consumer)) { 1356 adapter->max_tx_desc_count) == adapter->last_cmd_consumer)) {
1343 consumer = *(adapter->cmd_consumer); 1357 consumer = le32_to_cpu(*(adapter->cmd_consumer));
1344 } 1358 }
1345 done = (adapter->last_cmd_consumer == consumer); 1359 done = (adapter->last_cmd_consumer == consumer);
1346 1360
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c
index 36ba6a1aa3..7d2525e76a 100644
--- a/drivers/net/netxen/netxen_nic_main.c
+++ b/drivers/net/netxen/netxen_nic_main.c
@@ -42,8 +42,6 @@
42#include <linux/dma-mapping.h> 42#include <linux/dma-mapping.h>
43#include <linux/vmalloc.h> 43#include <linux/vmalloc.h>
44 44
45#define PHAN_VENDOR_ID 0x4040
46
47MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver"); 45MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver");
48MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
49MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID); 47MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
@@ -379,6 +377,8 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
379 netdev->tx_timeout = netxen_tx_timeout; 377 netdev->tx_timeout = netxen_tx_timeout;
380 netdev->watchdog_timeo = HZ; 378 netdev->watchdog_timeo = HZ;
381 379
380 netxen_nic_change_mtu(netdev, netdev->mtu);
381
382 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops); 382 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
383 netdev->poll = netxen_nic_poll; 383 netdev->poll = netxen_nic_poll;
384 netdev->weight = NETXEN_NETDEV_WEIGHT; 384 netdev->weight = NETXEN_NETDEV_WEIGHT;
@@ -434,7 +434,6 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
434 adapter->port_count++; 434 adapter->port_count++;
435 adapter->port[i] = port; 435 adapter->port[i] = port;
436 } 436 }
437
438 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)); 437 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
439 netxen_pinit_from_rom(adapter, 0); 438 netxen_pinit_from_rom(adapter, 0);
440 udelay(500); 439 udelay(500);
@@ -524,14 +523,17 @@ static void __devexit netxen_nic_remove(struct pci_dev *pdev)
524 if (adapter == NULL) 523 if (adapter == NULL)
525 return; 524 return;
526 525
526 if (adapter->irq)
527 free_irq(adapter->irq, adapter);
527 netxen_nic_stop_all_ports(adapter); 528 netxen_nic_stop_all_ports(adapter);
528 /* leave the hw in the same state as reboot */ 529 /* leave the hw in the same state as reboot */
529 netxen_pinit_from_rom(adapter, 0);
530 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)); 530 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
531 netxen_pinit_from_rom(adapter, 0);
532 udelay(500);
531 netxen_load_firmware(adapter); 533 netxen_load_firmware(adapter);
532 netxen_free_adapter_offload(adapter); 534 netxen_free_adapter_offload(adapter);
533 535
534 udelay(500); /* Delay for a while to drain the DMA engines */ 536 mdelay(1000); /* Delay for a while to drain the DMA engines */
535 for (i = 0; i < adapter->port_count; i++) { 537 for (i = 0; i < adapter->port_count; i++) {
536 port = adapter->port[i]; 538 port = adapter->port[i];
537 if ((port) && (port->netdev)) { 539 if ((port) && (port->netdev)) {
@@ -542,7 +544,6 @@ static void __devexit netxen_nic_remove(struct pci_dev *pdev)
542 544
543 if ((adapter->flags & NETXEN_NIC_MSI_ENABLED)) 545 if ((adapter->flags & NETXEN_NIC_MSI_ENABLED))
544 pci_disable_msi(pdev); 546 pci_disable_msi(pdev);
545 pci_set_drvdata(pdev, NULL);
546 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) 547 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC)
547 netxen_free_hw_resources(adapter); 548 netxen_free_hw_resources(adapter);
548 549
@@ -553,6 +554,7 @@ static void __devexit netxen_nic_remove(struct pci_dev *pdev)
553 554
554 pci_release_regions(pdev); 555 pci_release_regions(pdev);
555 pci_disable_device(pdev); 556 pci_disable_device(pdev);
557 pci_set_drvdata(pdev, NULL);
556 558
557 for (ctxid = 0; ctxid < MAX_RCV_CTX; ++ctxid) { 559 for (ctxid = 0; ctxid < MAX_RCV_CTX; ++ctxid) {
558 recv_ctx = &adapter->recv_ctx[ctxid]; 560 recv_ctx = &adapter->recv_ctx[ctxid];
@@ -671,8 +673,6 @@ static int netxen_nic_close(struct net_device *netdev)
671 673
672 if (!adapter->active_ports) { 674 if (!adapter->active_ports) {
673 netxen_nic_disable_int(adapter); 675 netxen_nic_disable_int(adapter);
674 if (adapter->irq)
675 free_irq(adapter->irq, adapter);
676 cmd_buff = adapter->cmd_buf_arr; 676 cmd_buff = adapter->cmd_buf_arr;
677 for (i = 0; i < adapter->max_tx_desc_count; i++) { 677 for (i = 0; i < adapter->max_tx_desc_count; i++) {
678 buffrag = cmd_buff->frag_array; 678 buffrag = cmd_buff->frag_array;
@@ -1154,8 +1154,8 @@ static void __exit netxen_exit_module(void)
1154 /* 1154 /*
1155 * Wait for some time to allow the dma to drain, if any. 1155 * Wait for some time to allow the dma to drain, if any.
1156 */ 1156 */
1157 destroy_workqueue(netxen_workq);
1158 pci_unregister_driver(&netxen_driver); 1157 pci_unregister_driver(&netxen_driver);
1158 destroy_workqueue(netxen_workq);
1159} 1159}
1160 1160
1161module_exit(netxen_exit_module); 1161module_exit(netxen_exit_module);
diff --git a/drivers/net/netxen/netxen_nic_niu.c b/drivers/net/netxen/netxen_nic_niu.c
index 40d7003a37..d5d95074e5 100644
--- a/drivers/net/netxen/netxen_nic_niu.c
+++ b/drivers/net/netxen/netxen_nic_niu.c
@@ -458,7 +458,7 @@ int netxen_niu_gbe_init_port(struct netxen_adapter *adapter, int port)
458 458
459int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port) 459int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port)
460{ 460{
461 long reg = 0, ret = 0; 461 u32 reg = 0, ret = 0;
462 462
463 if (adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) { 463 if (adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) {
464 netxen_crb_writelit_adapter(adapter, 464 netxen_crb_writelit_adapter(adapter,
diff --git a/drivers/net/netxen/netxen_nic_phan_reg.h b/drivers/net/netxen/netxen_nic_phan_reg.h
index 7879f855af..0c7c94328b 100644
--- a/drivers/net/netxen/netxen_nic_phan_reg.h
+++ b/drivers/net/netxen/netxen_nic_phan_reg.h
@@ -102,6 +102,9 @@
102#define CRB_CMD_CONSUMER_OFFSET_1 NETXEN_NIC_REG(0x1b0) 102#define CRB_CMD_CONSUMER_OFFSET_1 NETXEN_NIC_REG(0x1b0)
103#define CRB_TEMP_STATE NETXEN_NIC_REG(0x1b4) 103#define CRB_TEMP_STATE NETXEN_NIC_REG(0x1b4)
104 104
105/* used for ethtool tests */
106#define CRB_SCRATCHPAD_TEST NETXEN_NIC_REG(0x280)
107
105/* 108/*
106 * CrbPortPhanCntrHi/Lo is used to pass the address of HostPhantomIndex address 109 * CrbPortPhanCntrHi/Lo is used to pass the address of HostPhantomIndex address
107 * which can be read by the Phantom host to get producer/consumer indexes from 110 * which can be read by the Phantom host to get producer/consumer indexes from
diff --git a/drivers/net/ni52.c b/drivers/net/ni52.c
index 196993a29b..a6f4b24b01 100644
--- a/drivers/net/ni52.c
+++ b/drivers/net/ni52.c
@@ -104,8 +104,6 @@ static int automatic_resume; /* experimental .. better should be zero */
104static int rfdadd; /* rfdadd=1 may be better for 8K MEM cards */ 104static int rfdadd; /* rfdadd=1 may be better for 8K MEM cards */
105static int fifo=0x8; /* don't change */ 105static int fifo=0x8; /* don't change */
106 106
107/* #define REALLY_SLOW_IO */
108
109#include <linux/module.h> 107#include <linux/module.h>
110#include <linux/kernel.h> 108#include <linux/kernel.h>
111#include <linux/string.h> 109#include <linux/string.h>
diff --git a/drivers/net/ns83820.c b/drivers/net/ns83820.c
index 568daeb3e9..9ec6e9e54f 100644
--- a/drivers/net/ns83820.c
+++ b/drivers/net/ns83820.c
@@ -514,8 +514,7 @@ static void ns83820_vlan_rx_kill_vid(struct net_device *ndev, unsigned short vid
514 514
515 spin_lock_irq(&dev->misc_lock); 515 spin_lock_irq(&dev->misc_lock);
516 spin_lock(&dev->tx_lock); 516 spin_lock(&dev->tx_lock);
517 if (dev->vlgrp) 517 vlan_group_set_device(dev->vlgrp, vid, NULL);
518 dev->vlgrp->vlan_devices[vid] = NULL;
519 spin_unlock(&dev->tx_lock); 518 spin_unlock(&dev->tx_lock);
520 spin_unlock_irq(&dev->misc_lock); 519 spin_unlock_irq(&dev->misc_lock);
521} 520}
diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c
index 448bf4a780..c7bd9c1c7f 100644
--- a/drivers/net/pcmcia/3c574_cs.c
+++ b/drivers/net/pcmcia/3c574_cs.c
@@ -915,7 +915,7 @@ static void media_check(unsigned long arg)
915 if ((inw(ioaddr + EL3_STATUS) & IntLatch) && (inb(ioaddr + Timer) == 0xff)) { 915 if ((inw(ioaddr + EL3_STATUS) & IntLatch) && (inb(ioaddr + Timer) == 0xff)) {
916 if (!lp->fast_poll) 916 if (!lp->fast_poll)
917 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name); 917 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
918 el3_interrupt(dev->irq, lp); 918 el3_interrupt(dev->irq, dev);
919 lp->fast_poll = HZ; 919 lp->fast_poll = HZ;
920 } 920 }
921 if (lp->fast_poll) { 921 if (lp->fast_poll) {
diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c
index 530df8883f..2561f76033 100644
--- a/drivers/net/pcmcia/smc91c92_cs.c
+++ b/drivers/net/pcmcia/smc91c92_cs.c
@@ -1927,7 +1927,7 @@ static void media_check(u_long arg)
1927 if (smc->watchdog++ && ((i>>8) & i)) { 1927 if (smc->watchdog++ && ((i>>8) & i)) {
1928 if (!smc->fast_poll) 1928 if (!smc->fast_poll)
1929 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name); 1929 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
1930 smc_interrupt(dev->irq, smc); 1930 smc_interrupt(dev->irq, dev);
1931 smc->fast_poll = HZ; 1931 smc->fast_poll = HZ;
1932 } 1932 }
1933 if (smc->fast_poll) { 1933 if (smc->fast_poll) {
diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
index 36f9d98827..4d94ba7899 100644
--- a/drivers/net/pcnet32.c
+++ b/drivers/net/pcnet32.c
@@ -1234,14 +1234,14 @@ static void pcnet32_rx_entry(struct net_device *dev,
1234 skb_put(skb, pkt_len); /* Make room */ 1234 skb_put(skb, pkt_len); /* Make room */
1235 pci_dma_sync_single_for_cpu(lp->pci_dev, 1235 pci_dma_sync_single_for_cpu(lp->pci_dev,
1236 lp->rx_dma_addr[entry], 1236 lp->rx_dma_addr[entry],
1237 PKT_BUF_SZ - 2, 1237 pkt_len,
1238 PCI_DMA_FROMDEVICE); 1238 PCI_DMA_FROMDEVICE);
1239 eth_copy_and_sum(skb, 1239 eth_copy_and_sum(skb,
1240 (unsigned char *)(lp->rx_skbuff[entry]->data), 1240 (unsigned char *)(lp->rx_skbuff[entry]->data),
1241 pkt_len, 0); 1241 pkt_len, 0);
1242 pci_dma_sync_single_for_device(lp->pci_dev, 1242 pci_dma_sync_single_for_device(lp->pci_dev,
1243 lp->rx_dma_addr[entry], 1243 lp->rx_dma_addr[entry],
1244 PKT_BUF_SZ - 2, 1244 pkt_len,
1245 PCI_DMA_FROMDEVICE); 1245 PCI_DMA_FROMDEVICE);
1246 } 1246 }
1247 lp->stats.rx_bytes += skb->len; 1247 lp->stats.rx_bytes += skb->len;
diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index f4d4eb659c..22aec5cce6 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -42,6 +42,19 @@
42#define MII_M1011_IMASK_INIT 0x6400 42#define MII_M1011_IMASK_INIT 0x6400
43#define MII_M1011_IMASK_CLEAR 0x0000 43#define MII_M1011_IMASK_CLEAR 0x0000
44 44
45#define MII_M1011_PHY_SCR 0x10
46#define MII_M1011_PHY_SCR_AUTO_CROSS 0x0060
47
48#define MII_M1145_PHY_EXT_CR 0x14
49#define MII_M1145_RGMII_RX_DELAY 0x0080
50#define MII_M1145_RGMII_TX_DELAY 0x0002
51
52#define M1145_DEV_FLAGS_RESISTANCE 0x00000001
53
54#define MII_M1111_PHY_LED_CONTROL 0x18
55#define MII_M1111_PHY_LED_DIRECT 0x4100
56#define MII_M1111_PHY_LED_COMBINE 0x411c
57
45MODULE_DESCRIPTION("Marvell PHY driver"); 58MODULE_DESCRIPTION("Marvell PHY driver");
46MODULE_AUTHOR("Andy Fleming"); 59MODULE_AUTHOR("Andy Fleming");
47MODULE_LICENSE("GPL"); 60MODULE_LICENSE("GPL");
@@ -63,7 +76,7 @@ static int marvell_config_intr(struct phy_device *phydev)
63{ 76{
64 int err; 77 int err;
65 78
66 if(phydev->interrupts == PHY_INTERRUPT_ENABLED) 79 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
67 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_INIT); 80 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_INIT);
68 else 81 else
69 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR); 82 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR);
@@ -103,34 +116,153 @@ static int marvell_config_aneg(struct phy_device *phydev)
103 if (err < 0) 116 if (err < 0)
104 return err; 117 return err;
105 118
119 err = phy_write(phydev, MII_M1011_PHY_SCR,
120 MII_M1011_PHY_SCR_AUTO_CROSS);
121 if (err < 0)
122 return err;
123
124 err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL,
125 MII_M1111_PHY_LED_DIRECT);
126 if (err < 0)
127 return err;
106 128
107 err = genphy_config_aneg(phydev); 129 err = genphy_config_aneg(phydev);
108 130
109 return err; 131 return err;
110} 132}
111 133
134static int m88e1145_config_init(struct phy_device *phydev)
135{
136 int err;
137
138 /* Take care of errata E0 & E1 */
139 err = phy_write(phydev, 0x1d, 0x001b);
140 if (err < 0)
141 return err;
142
143 err = phy_write(phydev, 0x1e, 0x418f);
144 if (err < 0)
145 return err;
146
147 err = phy_write(phydev, 0x1d, 0x0016);
148 if (err < 0)
149 return err;
150
151 err = phy_write(phydev, 0x1e, 0xa2da);
152 if (err < 0)
153 return err;
154
155 if (phydev->interface == PHY_INTERFACE_MODE_RGMII) {
156 int temp = phy_read(phydev, MII_M1145_PHY_EXT_CR);
157 if (temp < 0)
158 return temp;
159
160 temp |= (MII_M1145_RGMII_RX_DELAY | MII_M1145_RGMII_TX_DELAY);
161
162 err = phy_write(phydev, MII_M1145_PHY_EXT_CR, temp);
163 if (err < 0)
164 return err;
165
166 if (phydev->dev_flags & M1145_DEV_FLAGS_RESISTANCE) {
167 err = phy_write(phydev, 0x1d, 0x0012);
168 if (err < 0)
169 return err;
170
171 temp = phy_read(phydev, 0x1e);
172 if (temp < 0)
173 return temp;
174
175 temp &= 0xf03f;
176 temp |= 2 << 9; /* 36 ohm */
177 temp |= 2 << 6; /* 39 ohm */
178
179 err = phy_write(phydev, 0x1e, temp);
180 if (err < 0)
181 return err;
182
183 err = phy_write(phydev, 0x1d, 0x3);
184 if (err < 0)
185 return err;
186
187 err = phy_write(phydev, 0x1e, 0x8000);
188 if (err < 0)
189 return err;
190 }
191 }
192
193 return 0;
194}
112 195
113static struct phy_driver m88e1101_driver = { 196static struct phy_driver m88e1101_driver = {
114 .phy_id = 0x01410c00, 197 .phy_id = 0x01410c60,
115 .phy_id_mask = 0xffffff00, 198 .phy_id_mask = 0xfffffff0,
116 .name = "Marvell 88E1101", 199 .name = "Marvell 88E1101",
117 .features = PHY_GBIT_FEATURES, 200 .features = PHY_GBIT_FEATURES,
118 .flags = PHY_HAS_INTERRUPT, 201 .flags = PHY_HAS_INTERRUPT,
119 .config_aneg = &marvell_config_aneg, 202 .config_aneg = &marvell_config_aneg,
120 .read_status = &genphy_read_status, 203 .read_status = &genphy_read_status,
121 .ack_interrupt = &marvell_ack_interrupt, 204 .ack_interrupt = &marvell_ack_interrupt,
122 .config_intr = &marvell_config_intr, 205 .config_intr = &marvell_config_intr,
123 .driver = { .owner = THIS_MODULE,}, 206 .driver = {.owner = THIS_MODULE,},
207};
208
209static struct phy_driver m88e1111s_driver = {
210 .phy_id = 0x01410cc0,
211 .phy_id_mask = 0xfffffff0,
212 .name = "Marvell 88E1111",
213 .features = PHY_GBIT_FEATURES,
214 .flags = PHY_HAS_INTERRUPT,
215 .config_aneg = &marvell_config_aneg,
216 .read_status = &genphy_read_status,
217 .ack_interrupt = &marvell_ack_interrupt,
218 .config_intr = &marvell_config_intr,
219 .driver = {.owner = THIS_MODULE,},
220};
221
222static struct phy_driver m88e1145_driver = {
223 .phy_id = 0x01410cd0,
224 .phy_id_mask = 0xfffffff0,
225 .name = "Marvell 88E1145",
226 .features = PHY_GBIT_FEATURES,
227 .flags = PHY_HAS_INTERRUPT,
228 .config_init = &m88e1145_config_init,
229 .config_aneg = &marvell_config_aneg,
230 .read_status = &genphy_read_status,
231 .ack_interrupt = &marvell_ack_interrupt,
232 .config_intr = &marvell_config_intr,
233 .driver = {.owner = THIS_MODULE,},
124}; 234};
125 235
126static int __init marvell_init(void) 236static int __init marvell_init(void)
127{ 237{
128 return phy_driver_register(&m88e1101_driver); 238 int ret;
239
240 ret = phy_driver_register(&m88e1101_driver);
241 if (ret)
242 return ret;
243
244 ret = phy_driver_register(&m88e1111s_driver);
245 if (ret)
246 goto err1111s;
247
248 ret = phy_driver_register(&m88e1145_driver);
249 if (ret)
250 goto err1145;
251
252 return 0;
253
254 err1145:
255 phy_driver_unregister(&m88e1111s_driver);
256 err1111s:
257 phy_driver_unregister(&m88e1101_driver);
258 return ret;
129} 259}
130 260
131static void __exit marvell_exit(void) 261static void __exit marvell_exit(void)
132{ 262{
133 phy_driver_unregister(&m88e1101_driver); 263 phy_driver_unregister(&m88e1101_driver);
264 phy_driver_unregister(&m88e1111s_driver);
265 phy_driver_unregister(&m88e1145_driver);
134} 266}
135 267
136module_init(marvell_init); 268module_init(marvell_init);
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index fdf45fdb67..7d5b6d1838 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -138,7 +138,7 @@ void phy_prepare_link(struct phy_device *phydev,
138 */ 138 */
139struct phy_device * phy_connect(struct net_device *dev, const char *phy_id, 139struct phy_device * phy_connect(struct net_device *dev, const char *phy_id,
140 void (*handler)(struct net_device *), u32 flags, 140 void (*handler)(struct net_device *), u32 flags,
141 u32 interface) 141 phy_interface_t interface)
142{ 142{
143 struct phy_device *phydev; 143 struct phy_device *phydev;
144 144
@@ -187,7 +187,7 @@ static int phy_compare_id(struct device *dev, void *data)
187} 187}
188 188
189struct phy_device *phy_attach(struct net_device *dev, 189struct phy_device *phy_attach(struct net_device *dev,
190 const char *phy_id, u32 flags, u32 interface) 190 const char *phy_id, u32 flags, phy_interface_t interface)
191{ 191{
192 struct bus_type *bus = &mdio_bus_type; 192 struct bus_type *bus = &mdio_bus_type;
193 struct phy_device *phydev; 193 struct phy_device *phydev;
diff --git a/drivers/net/pppoe.c b/drivers/net/pppoe.c
index 860bb0f60f..ebfa2967cd 100644
--- a/drivers/net/pppoe.c
+++ b/drivers/net/pppoe.c
@@ -7,6 +7,12 @@
7 * 7 *
8 * Version: 0.7.0 8 * Version: 0.7.0
9 * 9 *
10 * 070228 : Fix to allow multiple sessions with same remote MAC and same
11 * session id by including the local device ifindex in the
12 * tuple identifying a session. This also ensures packets can't
13 * be injected into a session from interfaces other than the one
14 * specified by userspace. Florian Zumbiehl <florz@florz.de>
15 * (Oh, BTW, this one is YYMMDD, in case you were wondering ...)
10 * 220102 : Fix module use count on failure in pppoe_create, pppox_sk -acme 16 * 220102 : Fix module use count on failure in pppoe_create, pppox_sk -acme
11 * 030700 : Fixed connect logic to allow for disconnect. 17 * 030700 : Fixed connect logic to allow for disconnect.
12 * 270700 : Fixed potential SMP problems; we must protect against 18 * 270700 : Fixed potential SMP problems; we must protect against
@@ -127,14 +133,14 @@ static struct pppox_sock *item_hash_table[PPPOE_HASH_SIZE];
127 * Set/get/delete/rehash items (internal versions) 133 * Set/get/delete/rehash items (internal versions)
128 * 134 *
129 **********************************************************************/ 135 **********************************************************************/
130static struct pppox_sock *__get_item(unsigned long sid, unsigned char *addr) 136static struct pppox_sock *__get_item(unsigned long sid, unsigned char *addr, int ifindex)
131{ 137{
132 int hash = hash_item(sid, addr); 138 int hash = hash_item(sid, addr);
133 struct pppox_sock *ret; 139 struct pppox_sock *ret;
134 140
135 ret = item_hash_table[hash]; 141 ret = item_hash_table[hash];
136 142
137 while (ret && !cmp_addr(&ret->pppoe_pa, sid, addr)) 143 while (ret && !(cmp_addr(&ret->pppoe_pa, sid, addr) && ret->pppoe_ifindex == ifindex))
138 ret = ret->next; 144 ret = ret->next;
139 145
140 return ret; 146 return ret;
@@ -147,21 +153,19 @@ static int __set_item(struct pppox_sock *po)
147 153
148 ret = item_hash_table[hash]; 154 ret = item_hash_table[hash];
149 while (ret) { 155 while (ret) {
150 if (cmp_2_addr(&ret->pppoe_pa, &po->pppoe_pa)) 156 if (cmp_2_addr(&ret->pppoe_pa, &po->pppoe_pa) && ret->pppoe_ifindex == po->pppoe_ifindex)
151 return -EALREADY; 157 return -EALREADY;
152 158
153 ret = ret->next; 159 ret = ret->next;
154 } 160 }
155 161
156 if (!ret) { 162 po->next = item_hash_table[hash];
157 po->next = item_hash_table[hash]; 163 item_hash_table[hash] = po;
158 item_hash_table[hash] = po;
159 }
160 164
161 return 0; 165 return 0;
162} 166}
163 167
164static struct pppox_sock *__delete_item(unsigned long sid, char *addr) 168static struct pppox_sock *__delete_item(unsigned long sid, char *addr, int ifindex)
165{ 169{
166 int hash = hash_item(sid, addr); 170 int hash = hash_item(sid, addr);
167 struct pppox_sock *ret, **src; 171 struct pppox_sock *ret, **src;
@@ -170,7 +174,7 @@ static struct pppox_sock *__delete_item(unsigned long sid, char *addr)
170 src = &item_hash_table[hash]; 174 src = &item_hash_table[hash];
171 175
172 while (ret) { 176 while (ret) {
173 if (cmp_addr(&ret->pppoe_pa, sid, addr)) { 177 if (cmp_addr(&ret->pppoe_pa, sid, addr) && ret->pppoe_ifindex == ifindex) {
174 *src = ret->next; 178 *src = ret->next;
175 break; 179 break;
176 } 180 }
@@ -188,12 +192,12 @@ static struct pppox_sock *__delete_item(unsigned long sid, char *addr)
188 * 192 *
189 **********************************************************************/ 193 **********************************************************************/
190static inline struct pppox_sock *get_item(unsigned long sid, 194static inline struct pppox_sock *get_item(unsigned long sid,
191 unsigned char *addr) 195 unsigned char *addr, int ifindex)
192{ 196{
193 struct pppox_sock *po; 197 struct pppox_sock *po;
194 198
195 read_lock_bh(&pppoe_hash_lock); 199 read_lock_bh(&pppoe_hash_lock);
196 po = __get_item(sid, addr); 200 po = __get_item(sid, addr, ifindex);
197 if (po) 201 if (po)
198 sock_hold(sk_pppox(po)); 202 sock_hold(sk_pppox(po));
199 read_unlock_bh(&pppoe_hash_lock); 203 read_unlock_bh(&pppoe_hash_lock);
@@ -203,7 +207,15 @@ static inline struct pppox_sock *get_item(unsigned long sid,
203 207
204static inline struct pppox_sock *get_item_by_addr(struct sockaddr_pppox *sp) 208static inline struct pppox_sock *get_item_by_addr(struct sockaddr_pppox *sp)
205{ 209{
206 return get_item(sp->sa_addr.pppoe.sid, sp->sa_addr.pppoe.remote); 210 struct net_device *dev = NULL;
211 int ifindex;
212
213 dev = dev_get_by_name(sp->sa_addr.pppoe.dev);
214 if(!dev)
215 return NULL;
216 ifindex = dev->ifindex;
217 dev_put(dev);
218 return get_item(sp->sa_addr.pppoe.sid, sp->sa_addr.pppoe.remote, ifindex);
207} 219}
208 220
209static inline int set_item(struct pppox_sock *po) 221static inline int set_item(struct pppox_sock *po)
@@ -220,12 +232,12 @@ static inline int set_item(struct pppox_sock *po)
220 return i; 232 return i;
221} 233}
222 234
223static inline struct pppox_sock *delete_item(unsigned long sid, char *addr) 235static inline struct pppox_sock *delete_item(unsigned long sid, char *addr, int ifindex)
224{ 236{
225 struct pppox_sock *ret; 237 struct pppox_sock *ret;
226 238
227 write_lock_bh(&pppoe_hash_lock); 239 write_lock_bh(&pppoe_hash_lock);
228 ret = __delete_item(sid, addr); 240 ret = __delete_item(sid, addr, ifindex);
229 write_unlock_bh(&pppoe_hash_lock); 241 write_unlock_bh(&pppoe_hash_lock);
230 242
231 return ret; 243 return ret;
@@ -391,7 +403,7 @@ static int pppoe_rcv(struct sk_buff *skb,
391 403
392 ph = (struct pppoe_hdr *) skb->nh.raw; 404 ph = (struct pppoe_hdr *) skb->nh.raw;
393 405
394 po = get_item((unsigned long) ph->sid, eth_hdr(skb)->h_source); 406 po = get_item((unsigned long) ph->sid, eth_hdr(skb)->h_source, dev->ifindex);
395 if (po != NULL) 407 if (po != NULL)
396 return sk_receive_skb(sk_pppox(po), skb, 0); 408 return sk_receive_skb(sk_pppox(po), skb, 0);
397drop: 409drop:
@@ -425,7 +437,7 @@ static int pppoe_disc_rcv(struct sk_buff *skb,
425 if (ph->code != PADT_CODE) 437 if (ph->code != PADT_CODE)
426 goto abort; 438 goto abort;
427 439
428 po = get_item((unsigned long) ph->sid, eth_hdr(skb)->h_source); 440 po = get_item((unsigned long) ph->sid, eth_hdr(skb)->h_source, dev->ifindex);
429 if (po) { 441 if (po) {
430 struct sock *sk = sk_pppox(po); 442 struct sock *sk = sk_pppox(po);
431 443
@@ -517,7 +529,7 @@ static int pppoe_release(struct socket *sock)
517 529
518 po = pppox_sk(sk); 530 po = pppox_sk(sk);
519 if (po->pppoe_pa.sid) { 531 if (po->pppoe_pa.sid) {
520 delete_item(po->pppoe_pa.sid, po->pppoe_pa.remote); 532 delete_item(po->pppoe_pa.sid, po->pppoe_pa.remote, po->pppoe_ifindex);
521 } 533 }
522 534
523 if (po->pppoe_dev) 535 if (po->pppoe_dev)
@@ -539,7 +551,7 @@ static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr,
539 int sockaddr_len, int flags) 551 int sockaddr_len, int flags)
540{ 552{
541 struct sock *sk = sock->sk; 553 struct sock *sk = sock->sk;
542 struct net_device *dev = NULL; 554 struct net_device *dev;
543 struct sockaddr_pppox *sp = (struct sockaddr_pppox *) uservaddr; 555 struct sockaddr_pppox *sp = (struct sockaddr_pppox *) uservaddr;
544 struct pppox_sock *po = pppox_sk(sk); 556 struct pppox_sock *po = pppox_sk(sk);
545 int error; 557 int error;
@@ -565,7 +577,7 @@ static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr,
565 pppox_unbind_sock(sk); 577 pppox_unbind_sock(sk);
566 578
567 /* Delete the old binding */ 579 /* Delete the old binding */
568 delete_item(po->pppoe_pa.sid,po->pppoe_pa.remote); 580 delete_item(po->pppoe_pa.sid,po->pppoe_pa.remote,po->pppoe_ifindex);
569 581
570 if(po->pppoe_dev) 582 if(po->pppoe_dev)
571 dev_put(po->pppoe_dev); 583 dev_put(po->pppoe_dev);
@@ -585,6 +597,7 @@ static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr,
585 goto end; 597 goto end;
586 598
587 po->pppoe_dev = dev; 599 po->pppoe_dev = dev;
600 po->pppoe_ifindex = dev->ifindex;
588 601
589 if (!(dev->flags & IFF_UP)) 602 if (!(dev->flags & IFF_UP))
590 goto err_put; 603 goto err_put;
@@ -705,7 +718,7 @@ static int pppoe_ioctl(struct socket *sock, unsigned int cmd,
705 break; 718 break;
706 719
707 /* PPPoE address from the user specifies an outbound 720 /* PPPoE address from the user specifies an outbound
708 PPPoE address to which frames are forwarded to */ 721 PPPoE address which frames are forwarded to */
709 err = -EFAULT; 722 err = -EFAULT;
710 if (copy_from_user(&po->pppoe_relay, 723 if (copy_from_user(&po->pppoe_relay,
711 (void __user *)arg, 724 (void __user *)arg,
diff --git a/drivers/net/qla3xxx.c b/drivers/net/qla3xxx.c
index a142cdfd94..d3f65dab30 100755
--- a/drivers/net/qla3xxx.c
+++ b/drivers/net/qla3xxx.c
@@ -39,7 +39,7 @@
39 39
40#define DRV_NAME "qla3xxx" 40#define DRV_NAME "qla3xxx"
41#define DRV_STRING "QLogic ISP3XXX Network Driver" 41#define DRV_STRING "QLogic ISP3XXX Network Driver"
42#define DRV_VERSION "v2.02.00-k36" 42#define DRV_VERSION "v2.03.00-k3"
43#define PFX DRV_NAME " " 43#define PFX DRV_NAME " "
44 44
45static const char ql3xxx_driver_name[] = DRV_NAME; 45static const char ql3xxx_driver_name[] = DRV_NAME;
@@ -276,7 +276,8 @@ static void ql_enable_interrupts(struct ql3_adapter *qdev)
276static void ql_release_to_lrg_buf_free_list(struct ql3_adapter *qdev, 276static void ql_release_to_lrg_buf_free_list(struct ql3_adapter *qdev,
277 struct ql_rcv_buf_cb *lrg_buf_cb) 277 struct ql_rcv_buf_cb *lrg_buf_cb)
278{ 278{
279 u64 map; 279 dma_addr_t map;
280 int err;
280 lrg_buf_cb->next = NULL; 281 lrg_buf_cb->next = NULL;
281 282
282 if (qdev->lrg_buf_free_tail == NULL) { /* The list is empty */ 283 if (qdev->lrg_buf_free_tail == NULL) { /* The list is empty */
@@ -287,9 +288,10 @@ static void ql_release_to_lrg_buf_free_list(struct ql3_adapter *qdev,
287 } 288 }
288 289
289 if (!lrg_buf_cb->skb) { 290 if (!lrg_buf_cb->skb) {
290 lrg_buf_cb->skb = dev_alloc_skb(qdev->lrg_buffer_len); 291 lrg_buf_cb->skb = netdev_alloc_skb(qdev->ndev,
292 qdev->lrg_buffer_len);
291 if (unlikely(!lrg_buf_cb->skb)) { 293 if (unlikely(!lrg_buf_cb->skb)) {
292 printk(KERN_ERR PFX "%s: failed dev_alloc_skb().\n", 294 printk(KERN_ERR PFX "%s: failed netdev_alloc_skb().\n",
293 qdev->ndev->name); 295 qdev->ndev->name);
294 qdev->lrg_buf_skb_check++; 296 qdev->lrg_buf_skb_check++;
295 } else { 297 } else {
@@ -303,6 +305,17 @@ static void ql_release_to_lrg_buf_free_list(struct ql3_adapter *qdev,
303 qdev->lrg_buffer_len - 305 qdev->lrg_buffer_len -
304 QL_HEADER_SPACE, 306 QL_HEADER_SPACE,
305 PCI_DMA_FROMDEVICE); 307 PCI_DMA_FROMDEVICE);
308 err = pci_dma_mapping_error(map);
309 if(err) {
310 printk(KERN_ERR "%s: PCI mapping failed with error: %d\n",
311 qdev->ndev->name, err);
312 dev_kfree_skb(lrg_buf_cb->skb);
313 lrg_buf_cb->skb = NULL;
314
315 qdev->lrg_buf_skb_check++;
316 return;
317 }
318
306 lrg_buf_cb->buf_phy_addr_low = 319 lrg_buf_cb->buf_phy_addr_low =
307 cpu_to_le32(LS_64BITS(map)); 320 cpu_to_le32(LS_64BITS(map));
308 lrg_buf_cb->buf_phy_addr_high = 321 lrg_buf_cb->buf_phy_addr_high =
@@ -1387,6 +1400,8 @@ static void ql_link_state_machine(struct ql3_adapter *qdev)
1387 printk(KERN_INFO PFX 1400 printk(KERN_INFO PFX
1388 "%s: Reset in progress, skip processing link " 1401 "%s: Reset in progress, skip processing link "
1389 "state.\n", qdev->ndev->name); 1402 "state.\n", qdev->ndev->name);
1403
1404 spin_unlock_irqrestore(&qdev->hw_lock, hw_flags);
1390 return; 1405 return;
1391 } 1406 }
1392 1407
@@ -1518,8 +1533,10 @@ static int ql_get_auto_cfg_status(struct ql3_adapter *qdev)
1518 spin_lock_irqsave(&qdev->hw_lock, hw_flags); 1533 spin_lock_irqsave(&qdev->hw_lock, hw_flags);
1519 if(ql_sem_spinlock(qdev, QL_PHY_GIO_SEM_MASK, 1534 if(ql_sem_spinlock(qdev, QL_PHY_GIO_SEM_MASK,
1520 (QL_RESOURCE_BITS_BASE_CODE | (qdev->mac_index) * 1535 (QL_RESOURCE_BITS_BASE_CODE | (qdev->mac_index) *
1521 2) << 7)) 1536 2) << 7)) {
1537 spin_unlock_irqrestore(&qdev->hw_lock, hw_flags);
1522 return 0; 1538 return 0;
1539 }
1523 status = ql_is_auto_cfg(qdev); 1540 status = ql_is_auto_cfg(qdev);
1524 ql_sem_unlock(qdev, QL_PHY_GIO_SEM_MASK); 1541 ql_sem_unlock(qdev, QL_PHY_GIO_SEM_MASK);
1525 spin_unlock_irqrestore(&qdev->hw_lock, hw_flags); 1542 spin_unlock_irqrestore(&qdev->hw_lock, hw_flags);
@@ -1533,8 +1550,10 @@ static u32 ql_get_speed(struct ql3_adapter *qdev)
1533 spin_lock_irqsave(&qdev->hw_lock, hw_flags); 1550 spin_lock_irqsave(&qdev->hw_lock, hw_flags);
1534 if(ql_sem_spinlock(qdev, QL_PHY_GIO_SEM_MASK, 1551 if(ql_sem_spinlock(qdev, QL_PHY_GIO_SEM_MASK,
1535 (QL_RESOURCE_BITS_BASE_CODE | (qdev->mac_index) * 1552 (QL_RESOURCE_BITS_BASE_CODE | (qdev->mac_index) *
1536 2) << 7)) 1553 2) << 7)) {
1554 spin_unlock_irqrestore(&qdev->hw_lock, hw_flags);
1537 return 0; 1555 return 0;
1556 }
1538 status = ql_get_link_speed(qdev); 1557 status = ql_get_link_speed(qdev);
1539 ql_sem_unlock(qdev, QL_PHY_GIO_SEM_MASK); 1558 ql_sem_unlock(qdev, QL_PHY_GIO_SEM_MASK);
1540 spin_unlock_irqrestore(&qdev->hw_lock, hw_flags); 1559 spin_unlock_irqrestore(&qdev->hw_lock, hw_flags);
@@ -1548,8 +1567,10 @@ static int ql_get_full_dup(struct ql3_adapter *qdev)
1548 spin_lock_irqsave(&qdev->hw_lock, hw_flags); 1567 spin_lock_irqsave(&qdev->hw_lock, hw_flags);
1549 if(ql_sem_spinlock(qdev, QL_PHY_GIO_SEM_MASK, 1568 if(ql_sem_spinlock(qdev, QL_PHY_GIO_SEM_MASK,
1550 (QL_RESOURCE_BITS_BASE_CODE | (qdev->mac_index) * 1569 (QL_RESOURCE_BITS_BASE_CODE | (qdev->mac_index) *
1551 2) << 7)) 1570 2) << 7)) {
1571 spin_unlock_irqrestore(&qdev->hw_lock, hw_flags);
1552 return 0; 1572 return 0;
1573 }
1553 status = ql_is_link_full_dup(qdev); 1574 status = ql_is_link_full_dup(qdev);
1554 ql_sem_unlock(qdev, QL_PHY_GIO_SEM_MASK); 1575 ql_sem_unlock(qdev, QL_PHY_GIO_SEM_MASK);
1555 spin_unlock_irqrestore(&qdev->hw_lock, hw_flags); 1576 spin_unlock_irqrestore(&qdev->hw_lock, hw_flags);
@@ -1615,14 +1636,16 @@ static const struct ethtool_ops ql3xxx_ethtool_ops = {
1615static int ql_populate_free_queue(struct ql3_adapter *qdev) 1636static int ql_populate_free_queue(struct ql3_adapter *qdev)
1616{ 1637{
1617 struct ql_rcv_buf_cb *lrg_buf_cb = qdev->lrg_buf_free_head; 1638 struct ql_rcv_buf_cb *lrg_buf_cb = qdev->lrg_buf_free_head;
1618 u64 map; 1639 dma_addr_t map;
1640 int err;
1619 1641
1620 while (lrg_buf_cb) { 1642 while (lrg_buf_cb) {
1621 if (!lrg_buf_cb->skb) { 1643 if (!lrg_buf_cb->skb) {
1622 lrg_buf_cb->skb = dev_alloc_skb(qdev->lrg_buffer_len); 1644 lrg_buf_cb->skb = netdev_alloc_skb(qdev->ndev,
1645 qdev->lrg_buffer_len);
1623 if (unlikely(!lrg_buf_cb->skb)) { 1646 if (unlikely(!lrg_buf_cb->skb)) {
1624 printk(KERN_DEBUG PFX 1647 printk(KERN_DEBUG PFX
1625 "%s: Failed dev_alloc_skb().\n", 1648 "%s: Failed netdev_alloc_skb().\n",
1626 qdev->ndev->name); 1649 qdev->ndev->name);
1627 break; 1650 break;
1628 } else { 1651 } else {
@@ -1636,6 +1659,17 @@ static int ql_populate_free_queue(struct ql3_adapter *qdev)
1636 qdev->lrg_buffer_len - 1659 qdev->lrg_buffer_len -
1637 QL_HEADER_SPACE, 1660 QL_HEADER_SPACE,
1638 PCI_DMA_FROMDEVICE); 1661 PCI_DMA_FROMDEVICE);
1662
1663 err = pci_dma_mapping_error(map);
1664 if(err) {
1665 printk(KERN_ERR "%s: PCI mapping failed with error: %d\n",
1666 qdev->ndev->name, err);
1667 dev_kfree_skb(lrg_buf_cb->skb);
1668 lrg_buf_cb->skb = NULL;
1669 break;
1670 }
1671
1672
1639 lrg_buf_cb->buf_phy_addr_low = 1673 lrg_buf_cb->buf_phy_addr_low =
1640 cpu_to_le32(LS_64BITS(map)); 1674 cpu_to_le32(LS_64BITS(map));
1641 lrg_buf_cb->buf_phy_addr_high = 1675 lrg_buf_cb->buf_phy_addr_high =
@@ -1690,11 +1724,11 @@ static void ql_update_lrg_bufq_prod_index(struct ql3_adapter *qdev)
1690 1724
1691 qdev->lrg_buf_q_producer_index++; 1725 qdev->lrg_buf_q_producer_index++;
1692 1726
1693 if (qdev->lrg_buf_q_producer_index == NUM_LBUFQ_ENTRIES) 1727 if (qdev->lrg_buf_q_producer_index == qdev->num_lbufq_entries)
1694 qdev->lrg_buf_q_producer_index = 0; 1728 qdev->lrg_buf_q_producer_index = 0;
1695 1729
1696 if (qdev->lrg_buf_q_producer_index == 1730 if (qdev->lrg_buf_q_producer_index ==
1697 (NUM_LBUFQ_ENTRIES - 1)) { 1731 (qdev->num_lbufq_entries - 1)) {
1698 lrg_buf_q_ele = qdev->lrg_buf_q_virt_addr; 1732 lrg_buf_q_ele = qdev->lrg_buf_q_virt_addr;
1699 } 1733 }
1700 } 1734 }
@@ -1713,8 +1747,31 @@ static void ql_process_mac_tx_intr(struct ql3_adapter *qdev,
1713{ 1747{
1714 struct ql_tx_buf_cb *tx_cb; 1748 struct ql_tx_buf_cb *tx_cb;
1715 int i; 1749 int i;
1750 int retval = 0;
1716 1751
1752 if(mac_rsp->flags & OB_MAC_IOCB_RSP_S) {
1753 printk(KERN_WARNING "Frame short but, frame was padded and sent.\n");
1754 }
1755
1717 tx_cb = &qdev->tx_buf[mac_rsp->transaction_id]; 1756 tx_cb = &qdev->tx_buf[mac_rsp->transaction_id];
1757
1758 /* Check the transmit response flags for any errors */
1759 if(mac_rsp->flags & OB_MAC_IOCB_RSP_S) {
1760 printk(KERN_ERR "Frame too short to be legal, frame not sent.\n");
1761
1762 qdev->stats.tx_errors++;
1763 retval = -EIO;
1764 goto frame_not_sent;
1765 }
1766
1767 if(tx_cb->seg_count == 0) {
1768 printk(KERN_ERR "tx_cb->seg_count == 0: %d\n", mac_rsp->transaction_id);
1769
1770 qdev->stats.tx_errors++;
1771 retval = -EIO;
1772 goto invalid_seg_count;
1773 }
1774
1718 pci_unmap_single(qdev->pdev, 1775 pci_unmap_single(qdev->pdev,
1719 pci_unmap_addr(&tx_cb->map[0], mapaddr), 1776 pci_unmap_addr(&tx_cb->map[0], mapaddr),
1720 pci_unmap_len(&tx_cb->map[0], maplen), 1777 pci_unmap_len(&tx_cb->map[0], maplen),
@@ -1731,11 +1788,32 @@ static void ql_process_mac_tx_intr(struct ql3_adapter *qdev,
1731 } 1788 }
1732 qdev->stats.tx_packets++; 1789 qdev->stats.tx_packets++;
1733 qdev->stats.tx_bytes += tx_cb->skb->len; 1790 qdev->stats.tx_bytes += tx_cb->skb->len;
1791
1792frame_not_sent:
1734 dev_kfree_skb_irq(tx_cb->skb); 1793 dev_kfree_skb_irq(tx_cb->skb);
1735 tx_cb->skb = NULL; 1794 tx_cb->skb = NULL;
1795
1796invalid_seg_count:
1736 atomic_inc(&qdev->tx_count); 1797 atomic_inc(&qdev->tx_count);
1737} 1798}
1738 1799
1800void ql_get_sbuf(struct ql3_adapter *qdev)
1801{
1802 if (++qdev->small_buf_index == NUM_SMALL_BUFFERS)
1803 qdev->small_buf_index = 0;
1804 qdev->small_buf_release_cnt++;
1805}
1806
1807struct ql_rcv_buf_cb *ql_get_lbuf(struct ql3_adapter *qdev)
1808{
1809 struct ql_rcv_buf_cb *lrg_buf_cb = NULL;
1810 lrg_buf_cb = &qdev->lrg_buf[qdev->lrg_buf_index];
1811 qdev->lrg_buf_release_cnt++;
1812 if (++qdev->lrg_buf_index == qdev->num_large_buffers)
1813 qdev->lrg_buf_index = 0;
1814 return(lrg_buf_cb);
1815}
1816
1739/* 1817/*
1740 * The difference between 3022 and 3032 for inbound completions: 1818 * The difference between 3022 and 3032 for inbound completions:
1741 * 3022 uses two buffers per completion. The first buffer contains 1819 * 3022 uses two buffers per completion. The first buffer contains
@@ -1751,47 +1829,21 @@ static void ql_process_mac_tx_intr(struct ql3_adapter *qdev,
1751static void ql_process_mac_rx_intr(struct ql3_adapter *qdev, 1829static void ql_process_mac_rx_intr(struct ql3_adapter *qdev,
1752 struct ib_mac_iocb_rsp *ib_mac_rsp_ptr) 1830 struct ib_mac_iocb_rsp *ib_mac_rsp_ptr)
1753{ 1831{
1754 long int offset;
1755 u32 lrg_buf_phy_addr_low = 0;
1756 struct ql_rcv_buf_cb *lrg_buf_cb1 = NULL; 1832 struct ql_rcv_buf_cb *lrg_buf_cb1 = NULL;
1757 struct ql_rcv_buf_cb *lrg_buf_cb2 = NULL; 1833 struct ql_rcv_buf_cb *lrg_buf_cb2 = NULL;
1758 u32 *curr_ial_ptr;
1759 struct sk_buff *skb; 1834 struct sk_buff *skb;
1760 u16 length = le16_to_cpu(ib_mac_rsp_ptr->length); 1835 u16 length = le16_to_cpu(ib_mac_rsp_ptr->length);
1761 1836
1762 /* 1837 /*
1763 * Get the inbound address list (small buffer). 1838 * Get the inbound address list (small buffer).
1764 */ 1839 */
1765 offset = qdev->small_buf_index * QL_SMALL_BUFFER_SIZE; 1840 ql_get_sbuf(qdev);
1766 if (++qdev->small_buf_index == NUM_SMALL_BUFFERS)
1767 qdev->small_buf_index = 0;
1768 1841
1769 curr_ial_ptr = (u32 *) (qdev->small_buf_virt_addr + offset); 1842 if (qdev->device_id == QL3022_DEVICE_ID)
1770 qdev->last_rsp_offset = qdev->small_buf_phy_addr_low + offset; 1843 lrg_buf_cb1 = ql_get_lbuf(qdev);
1771 qdev->small_buf_release_cnt++;
1772
1773 if (qdev->device_id == QL3022_DEVICE_ID) {
1774 /* start of first buffer (3022 only) */
1775 lrg_buf_phy_addr_low = le32_to_cpu(*curr_ial_ptr);
1776 lrg_buf_cb1 = &qdev->lrg_buf[qdev->lrg_buf_index];
1777 qdev->lrg_buf_release_cnt++;
1778 if (++qdev->lrg_buf_index == NUM_LARGE_BUFFERS) {
1779 qdev->lrg_buf_index = 0;
1780 }
1781 curr_ial_ptr++; /* 64-bit pointers require two incs. */
1782 curr_ial_ptr++;
1783 }
1784 1844
1785 /* start of second buffer */ 1845 /* start of second buffer */
1786 lrg_buf_phy_addr_low = le32_to_cpu(*curr_ial_ptr); 1846 lrg_buf_cb2 = ql_get_lbuf(qdev);
1787 lrg_buf_cb2 = &qdev->lrg_buf[qdev->lrg_buf_index];
1788
1789 /*
1790 * Second buffer gets sent up the stack.
1791 */
1792 qdev->lrg_buf_release_cnt++;
1793 if (++qdev->lrg_buf_index == NUM_LARGE_BUFFERS)
1794 qdev->lrg_buf_index = 0;
1795 skb = lrg_buf_cb2->skb; 1847 skb = lrg_buf_cb2->skb;
1796 1848
1797 qdev->stats.rx_packets++; 1849 qdev->stats.rx_packets++;
@@ -1819,11 +1871,8 @@ static void ql_process_mac_rx_intr(struct ql3_adapter *qdev,
1819static void ql_process_macip_rx_intr(struct ql3_adapter *qdev, 1871static void ql_process_macip_rx_intr(struct ql3_adapter *qdev,
1820 struct ib_ip_iocb_rsp *ib_ip_rsp_ptr) 1872 struct ib_ip_iocb_rsp *ib_ip_rsp_ptr)
1821{ 1873{
1822 long int offset;
1823 u32 lrg_buf_phy_addr_low = 0;
1824 struct ql_rcv_buf_cb *lrg_buf_cb1 = NULL; 1874 struct ql_rcv_buf_cb *lrg_buf_cb1 = NULL;
1825 struct ql_rcv_buf_cb *lrg_buf_cb2 = NULL; 1875 struct ql_rcv_buf_cb *lrg_buf_cb2 = NULL;
1826 u32 *curr_ial_ptr;
1827 struct sk_buff *skb1 = NULL, *skb2; 1876 struct sk_buff *skb1 = NULL, *skb2;
1828 struct net_device *ndev = qdev->ndev; 1877 struct net_device *ndev = qdev->ndev;
1829 u16 length = le16_to_cpu(ib_ip_rsp_ptr->length); 1878 u16 length = le16_to_cpu(ib_ip_rsp_ptr->length);
@@ -1833,35 +1882,20 @@ static void ql_process_macip_rx_intr(struct ql3_adapter *qdev,
1833 * Get the inbound address list (small buffer). 1882 * Get the inbound address list (small buffer).
1834 */ 1883 */
1835 1884
1836 offset = qdev->small_buf_index * QL_SMALL_BUFFER_SIZE; 1885 ql_get_sbuf(qdev);
1837 if (++qdev->small_buf_index == NUM_SMALL_BUFFERS)
1838 qdev->small_buf_index = 0;
1839 curr_ial_ptr = (u32 *) (qdev->small_buf_virt_addr + offset);
1840 qdev->last_rsp_offset = qdev->small_buf_phy_addr_low + offset;
1841 qdev->small_buf_release_cnt++;
1842 1886
1843 if (qdev->device_id == QL3022_DEVICE_ID) { 1887 if (qdev->device_id == QL3022_DEVICE_ID) {
1844 /* start of first buffer on 3022 */ 1888 /* start of first buffer on 3022 */
1845 lrg_buf_phy_addr_low = le32_to_cpu(*curr_ial_ptr); 1889 lrg_buf_cb1 = ql_get_lbuf(qdev);
1846 lrg_buf_cb1 = &qdev->lrg_buf[qdev->lrg_buf_index];
1847 qdev->lrg_buf_release_cnt++;
1848 if (++qdev->lrg_buf_index == NUM_LARGE_BUFFERS)
1849 qdev->lrg_buf_index = 0;
1850 skb1 = lrg_buf_cb1->skb; 1890 skb1 = lrg_buf_cb1->skb;
1851 curr_ial_ptr++; /* 64-bit pointers require two incs. */
1852 curr_ial_ptr++;
1853 size = ETH_HLEN; 1891 size = ETH_HLEN;
1854 if (*((u16 *) skb1->data) != 0xFFFF) 1892 if (*((u16 *) skb1->data) != 0xFFFF)
1855 size += VLAN_ETH_HLEN - ETH_HLEN; 1893 size += VLAN_ETH_HLEN - ETH_HLEN;
1856 } 1894 }
1857 1895
1858 /* start of second buffer */ 1896 /* start of second buffer */
1859 lrg_buf_phy_addr_low = le32_to_cpu(*curr_ial_ptr); 1897 lrg_buf_cb2 = ql_get_lbuf(qdev);
1860 lrg_buf_cb2 = &qdev->lrg_buf[qdev->lrg_buf_index];
1861 skb2 = lrg_buf_cb2->skb; 1898 skb2 = lrg_buf_cb2->skb;
1862 qdev->lrg_buf_release_cnt++;
1863 if (++qdev->lrg_buf_index == NUM_LARGE_BUFFERS)
1864 qdev->lrg_buf_index = 0;
1865 1899
1866 skb_put(skb2, length); /* Just the second buffer length here. */ 1900 skb_put(skb2, length); /* Just the second buffer length here. */
1867 pci_unmap_single(qdev->pdev, 1901 pci_unmap_single(qdev->pdev,
@@ -1914,10 +1948,13 @@ static int ql_tx_rx_clean(struct ql3_adapter *qdev,
1914 struct net_rsp_iocb *net_rsp; 1948 struct net_rsp_iocb *net_rsp;
1915 struct net_device *ndev = qdev->ndev; 1949 struct net_device *ndev = qdev->ndev;
1916 unsigned long hw_flags; 1950 unsigned long hw_flags;
1951 int work_done = 0;
1952
1953 u32 rsp_producer_index = le32_to_cpu(*(qdev->prsp_producer_index));
1917 1954
1918 /* While there are entries in the completion queue. */ 1955 /* While there are entries in the completion queue. */
1919 while ((cpu_to_le32(*(qdev->prsp_producer_index)) != 1956 while ((rsp_producer_index !=
1920 qdev->rsp_consumer_index) && (*rx_cleaned < work_to_do)) { 1957 qdev->rsp_consumer_index) && (work_done < work_to_do)) {
1921 1958
1922 net_rsp = qdev->rsp_current; 1959 net_rsp = qdev->rsp_current;
1923 switch (net_rsp->opcode) { 1960 switch (net_rsp->opcode) {
@@ -1968,37 +2005,34 @@ static int ql_tx_rx_clean(struct ql3_adapter *qdev,
1968 } else { 2005 } else {
1969 qdev->rsp_current++; 2006 qdev->rsp_current++;
1970 } 2007 }
2008
2009 work_done = *tx_cleaned + *rx_cleaned;
1971 } 2010 }
1972 2011
1973 spin_lock_irqsave(&qdev->hw_lock, hw_flags); 2012 if(work_done) {
2013 spin_lock_irqsave(&qdev->hw_lock, hw_flags);
1974 2014
1975 ql_update_lrg_bufq_prod_index(qdev); 2015 ql_update_lrg_bufq_prod_index(qdev);
1976 2016
1977 if (qdev->small_buf_release_cnt >= 16) { 2017 if (qdev->small_buf_release_cnt >= 16) {
1978 while (qdev->small_buf_release_cnt >= 16) { 2018 while (qdev->small_buf_release_cnt >= 16) {
1979 qdev->small_buf_q_producer_index++; 2019 qdev->small_buf_q_producer_index++;
1980 2020
1981 if (qdev->small_buf_q_producer_index == 2021 if (qdev->small_buf_q_producer_index ==
1982 NUM_SBUFQ_ENTRIES) 2022 NUM_SBUFQ_ENTRIES)
1983 qdev->small_buf_q_producer_index = 0; 2023 qdev->small_buf_q_producer_index = 0;
1984 qdev->small_buf_release_cnt -= 8; 2024 qdev->small_buf_release_cnt -= 8;
1985 } 2025 }
1986 2026
1987 ql_write_common_reg(qdev, 2027 wmb();
1988 &port_regs->CommonRegs. 2028 ql_write_common_reg(qdev,
1989 rxSmallQProducerIndex, 2029 &port_regs->CommonRegs.
1990 qdev->small_buf_q_producer_index); 2030 rxSmallQProducerIndex,
1991 } 2031 qdev->small_buf_q_producer_index);
1992 2032
1993 ql_write_common_reg(qdev, 2033 }
1994 &port_regs->CommonRegs.rspQConsumerIndex,
1995 qdev->rsp_consumer_index);
1996 spin_unlock_irqrestore(&qdev->hw_lock, hw_flags);
1997 2034
1998 if (unlikely(netif_queue_stopped(qdev->ndev))) { 2035 spin_unlock_irqrestore(&qdev->hw_lock, hw_flags);
1999 if (netif_queue_stopped(qdev->ndev) &&
2000 (atomic_read(&qdev->tx_count) > (NUM_REQ_Q_ENTRIES / 4)))
2001 netif_wake_queue(qdev->ndev);
2002 } 2036 }
2003 2037
2004 return *tx_cleaned + *rx_cleaned; 2038 return *tx_cleaned + *rx_cleaned;
@@ -2009,6 +2043,8 @@ static int ql_poll(struct net_device *ndev, int *budget)
2009 struct ql3_adapter *qdev = netdev_priv(ndev); 2043 struct ql3_adapter *qdev = netdev_priv(ndev);
2010 int work_to_do = min(*budget, ndev->quota); 2044 int work_to_do = min(*budget, ndev->quota);
2011 int rx_cleaned = 0, tx_cleaned = 0; 2045 int rx_cleaned = 0, tx_cleaned = 0;
2046 unsigned long hw_flags;
2047 struct ql3xxx_port_registers __iomem *port_regs = qdev->mem_map_registers;
2012 2048
2013 if (!netif_carrier_ok(ndev)) 2049 if (!netif_carrier_ok(ndev))
2014 goto quit_polling; 2050 goto quit_polling;
@@ -2017,9 +2053,17 @@ static int ql_poll(struct net_device *ndev, int *budget)
2017 *budget -= rx_cleaned; 2053 *budget -= rx_cleaned;
2018 ndev->quota -= rx_cleaned; 2054 ndev->quota -= rx_cleaned;
2019 2055
2020 if ((!tx_cleaned && !rx_cleaned) || !netif_running(ndev)) { 2056 if( tx_cleaned + rx_cleaned != work_to_do ||
2057 !netif_running(ndev)) {
2021quit_polling: 2058quit_polling:
2022 netif_rx_complete(ndev); 2059 netif_rx_complete(ndev);
2060
2061 spin_lock_irqsave(&qdev->hw_lock, hw_flags);
2062 ql_write_common_reg(qdev,
2063 &port_regs->CommonRegs.rspQConsumerIndex,
2064 qdev->rsp_consumer_index);
2065 spin_unlock_irqrestore(&qdev->hw_lock, hw_flags);
2066
2023 ql_enable_interrupts(qdev); 2067 ql_enable_interrupts(qdev);
2024 return 0; 2068 return 0;
2025 } 2069 }
@@ -2073,10 +2117,9 @@ static irqreturn_t ql3xxx_isr(int irq, void *dev_id)
2073 spin_unlock(&qdev->adapter_lock); 2117 spin_unlock(&qdev->adapter_lock);
2074 } else if (value & ISP_IMR_DISABLE_CMPL_INT) { 2118 } else if (value & ISP_IMR_DISABLE_CMPL_INT) {
2075 ql_disable_interrupts(qdev); 2119 ql_disable_interrupts(qdev);
2076 if (likely(netif_rx_schedule_prep(ndev))) 2120 if (likely(netif_rx_schedule_prep(ndev))) {
2077 __netif_rx_schedule(ndev); 2121 __netif_rx_schedule(ndev);
2078 else 2122 }
2079 ql_enable_interrupts(qdev);
2080 } else { 2123 } else {
2081 return IRQ_NONE; 2124 return IRQ_NONE;
2082 } 2125 }
@@ -2093,8 +2136,12 @@ static irqreturn_t ql3xxx_isr(int irq, void *dev_id)
2093 * the next AOL if more frags are coming. 2136 * the next AOL if more frags are coming.
2094 * That is why the frags:segment count ratio is not linear. 2137 * That is why the frags:segment count ratio is not linear.
2095 */ 2138 */
2096static int ql_get_seg_count(unsigned short frags) 2139static int ql_get_seg_count(struct ql3_adapter *qdev,
2140 unsigned short frags)
2097{ 2141{
2142 if (qdev->device_id == QL3022_DEVICE_ID)
2143 return 1;
2144
2098 switch(frags) { 2145 switch(frags) {
2099 case 0: return 1; /* just the skb->data seg */ 2146 case 0: return 1; /* just the skb->data seg */
2100 case 1: return 2; /* skb->data + 1 frag */ 2147 case 1: return 2; /* skb->data + 1 frag */
@@ -2139,11 +2186,13 @@ static void ql_hw_csum_setup(struct sk_buff *skb,
2139 2186
2140 if (ip) { 2187 if (ip) {
2141 if (ip->protocol == IPPROTO_TCP) { 2188 if (ip->protocol == IPPROTO_TCP) {
2142 mac_iocb_ptr->flags1 |= OB_3032MAC_IOCB_REQ_TC; 2189 mac_iocb_ptr->flags1 |= OB_3032MAC_IOCB_REQ_TC |
2190 OB_3032MAC_IOCB_REQ_IC;
2143 mac_iocb_ptr->ip_hdr_off = offset; 2191 mac_iocb_ptr->ip_hdr_off = offset;
2144 mac_iocb_ptr->ip_hdr_len = ip->ihl; 2192 mac_iocb_ptr->ip_hdr_len = ip->ihl;
2145 } else if (ip->protocol == IPPROTO_UDP) { 2193 } else if (ip->protocol == IPPROTO_UDP) {
2146 mac_iocb_ptr->flags1 |= OB_3032MAC_IOCB_REQ_UC; 2194 mac_iocb_ptr->flags1 |= OB_3032MAC_IOCB_REQ_UC |
2195 OB_3032MAC_IOCB_REQ_IC;
2147 mac_iocb_ptr->ip_hdr_off = offset; 2196 mac_iocb_ptr->ip_hdr_off = offset;
2148 mac_iocb_ptr->ip_hdr_len = ip->ihl; 2197 mac_iocb_ptr->ip_hdr_len = ip->ihl;
2149 } 2198 }
@@ -2151,53 +2200,42 @@ static void ql_hw_csum_setup(struct sk_buff *skb,
2151} 2200}
2152 2201
2153/* 2202/*
2154 * The difference between 3022 and 3032 sends: 2203 * Map the buffers for this transmit. This will return
2155 * 3022 only supports a simple single segment transmission. 2204 * NETDEV_TX_BUSY or NETDEV_TX_OK based on success.
2156 * 3032 supports checksumming and scatter/gather lists (fragments).
2157 * The 3032 supports sglists by using the 3 addr/len pairs (ALP)
2158 * in the IOCB plus a chain of outbound address lists (OAL) that
2159 * each contain 5 ALPs. The last ALP of the IOCB (3rd) or OAL (5th)
2160 * will used to point to an OAL when more ALP entries are required.
2161 * The IOCB is always the top of the chain followed by one or more
2162 * OALs (when necessary).
2163 */ 2205 */
2164static int ql3xxx_send(struct sk_buff *skb, struct net_device *ndev) 2206static int ql_send_map(struct ql3_adapter *qdev,
2207 struct ob_mac_iocb_req *mac_iocb_ptr,
2208 struct ql_tx_buf_cb *tx_cb,
2209 struct sk_buff *skb)
2165{ 2210{
2166 struct ql3_adapter *qdev = (struct ql3_adapter *)netdev_priv(ndev);
2167 struct ql3xxx_port_registers __iomem *port_regs = qdev->mem_map_registers;
2168 struct ql_tx_buf_cb *tx_cb;
2169 u32 tot_len = skb->len;
2170 struct oal *oal; 2211 struct oal *oal;
2171 struct oal_entry *oal_entry; 2212 struct oal_entry *oal_entry;
2172 int len; 2213 int len = skb_headlen(skb);
2173 struct ob_mac_iocb_req *mac_iocb_ptr; 2214 dma_addr_t map;
2174 u64 map; 2215 int err;
2216 int completed_segs, i;
2175 int seg_cnt, seg = 0; 2217 int seg_cnt, seg = 0;
2176 int frag_cnt = (int)skb_shinfo(skb)->nr_frags; 2218 int frag_cnt = (int)skb_shinfo(skb)->nr_frags;
2177 2219
2178 if (unlikely(atomic_read(&qdev->tx_count) < 2)) { 2220 seg_cnt = tx_cb->seg_count = ql_get_seg_count(qdev,
2179 if (!netif_queue_stopped(ndev)) 2221 (skb_shinfo(skb)->nr_frags));
2180 netif_stop_queue(ndev);
2181 return NETDEV_TX_BUSY;
2182 }
2183 tx_cb = &qdev->tx_buf[qdev->req_producer_index] ;
2184 seg_cnt = tx_cb->seg_count = ql_get_seg_count((skb_shinfo(skb)->nr_frags));
2185 if(seg_cnt == -1) { 2222 if(seg_cnt == -1) {
2186 printk(KERN_ERR PFX"%s: invalid segment count!\n",__func__); 2223 printk(KERN_ERR PFX"%s: invalid segment count!\n",__func__);
2187 return NETDEV_TX_OK; 2224 return NETDEV_TX_BUSY;
2188
2189 } 2225 }
2190 mac_iocb_ptr = tx_cb->queue_entry; 2226 /*
2191 memset((void *)mac_iocb_ptr, 0, sizeof(struct ob_mac_iocb_req)); 2227 * Map the skb buffer first.
2192 mac_iocb_ptr->opcode = qdev->mac_ob_opcode; 2228 */
2193 mac_iocb_ptr->flags |= qdev->mb_bit_mask;
2194 mac_iocb_ptr->transaction_id = qdev->req_producer_index;
2195 mac_iocb_ptr->data_len = cpu_to_le16((u16) tot_len);
2196 tx_cb->skb = skb;
2197 if (skb->ip_summed == CHECKSUM_PARTIAL)
2198 ql_hw_csum_setup(skb, mac_iocb_ptr);
2199 len = skb_headlen(skb);
2200 map = pci_map_single(qdev->pdev, skb->data, len, PCI_DMA_TODEVICE); 2229 map = pci_map_single(qdev->pdev, skb->data, len, PCI_DMA_TODEVICE);
2230
2231 err = pci_dma_mapping_error(map);
2232 if(err) {
2233 printk(KERN_ERR "%s: PCI mapping failed with error: %d\n",
2234 qdev->ndev->name, err);
2235
2236 return NETDEV_TX_BUSY;
2237 }
2238
2201 oal_entry = (struct oal_entry *)&mac_iocb_ptr->buf_addr0_low; 2239 oal_entry = (struct oal_entry *)&mac_iocb_ptr->buf_addr0_low;
2202 oal_entry->dma_lo = cpu_to_le32(LS_64BITS(map)); 2240 oal_entry->dma_lo = cpu_to_le32(LS_64BITS(map));
2203 oal_entry->dma_hi = cpu_to_le32(MS_64BITS(map)); 2241 oal_entry->dma_hi = cpu_to_le32(MS_64BITS(map));
@@ -2206,15 +2244,14 @@ static int ql3xxx_send(struct sk_buff *skb, struct net_device *ndev)
2206 pci_unmap_len_set(&tx_cb->map[seg], maplen, len); 2244 pci_unmap_len_set(&tx_cb->map[seg], maplen, len);
2207 seg++; 2245 seg++;
2208 2246
2209 if (!skb_shinfo(skb)->nr_frags) { 2247 if (seg_cnt == 1) {
2210 /* Terminate the last segment. */ 2248 /* Terminate the last segment. */
2211 oal_entry->len = 2249 oal_entry->len =
2212 cpu_to_le32(le32_to_cpu(oal_entry->len) | OAL_LAST_ENTRY); 2250 cpu_to_le32(le32_to_cpu(oal_entry->len) | OAL_LAST_ENTRY);
2213 } else { 2251 } else {
2214 int i;
2215 oal = tx_cb->oal; 2252 oal = tx_cb->oal;
2216 for (i=0; i<frag_cnt; i++,seg++) { 2253 for (completed_segs=0; completed_segs<frag_cnt; completed_segs++,seg++) {
2217 skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 2254 skb_frag_t *frag = &skb_shinfo(skb)->frags[completed_segs];
2218 oal_entry++; 2255 oal_entry++;
2219 if ((seg == 2 && seg_cnt > 3) || /* Check for continuation */ 2256 if ((seg == 2 && seg_cnt > 3) || /* Check for continuation */
2220 (seg == 7 && seg_cnt > 8) || /* requirements. It's strange */ 2257 (seg == 7 && seg_cnt > 8) || /* requirements. It's strange */
@@ -2224,6 +2261,15 @@ static int ql3xxx_send(struct sk_buff *skb, struct net_device *ndev)
2224 map = pci_map_single(qdev->pdev, oal, 2261 map = pci_map_single(qdev->pdev, oal,
2225 sizeof(struct oal), 2262 sizeof(struct oal),
2226 PCI_DMA_TODEVICE); 2263 PCI_DMA_TODEVICE);
2264
2265 err = pci_dma_mapping_error(map);
2266 if(err) {
2267
2268 printk(KERN_ERR "%s: PCI mapping outbound address list with error: %d\n",
2269 qdev->ndev->name, err);
2270 goto map_error;
2271 }
2272
2227 oal_entry->dma_lo = cpu_to_le32(LS_64BITS(map)); 2273 oal_entry->dma_lo = cpu_to_le32(LS_64BITS(map));
2228 oal_entry->dma_hi = cpu_to_le32(MS_64BITS(map)); 2274 oal_entry->dma_hi = cpu_to_le32(MS_64BITS(map));
2229 oal_entry->len = 2275 oal_entry->len =
@@ -2242,6 +2288,14 @@ static int ql3xxx_send(struct sk_buff *skb, struct net_device *ndev)
2242 pci_map_page(qdev->pdev, frag->page, 2288 pci_map_page(qdev->pdev, frag->page,
2243 frag->page_offset, frag->size, 2289 frag->page_offset, frag->size,
2244 PCI_DMA_TODEVICE); 2290 PCI_DMA_TODEVICE);
2291
2292 err = pci_dma_mapping_error(map);
2293 if(err) {
2294 printk(KERN_ERR "%s: PCI mapping frags failed with error: %d\n",
2295 qdev->ndev->name, err);
2296 goto map_error;
2297 }
2298
2245 oal_entry->dma_lo = cpu_to_le32(LS_64BITS(map)); 2299 oal_entry->dma_lo = cpu_to_le32(LS_64BITS(map));
2246 oal_entry->dma_hi = cpu_to_le32(MS_64BITS(map)); 2300 oal_entry->dma_hi = cpu_to_le32(MS_64BITS(map));
2247 oal_entry->len = cpu_to_le32(frag->size); 2301 oal_entry->len = cpu_to_le32(frag->size);
@@ -2253,6 +2307,94 @@ static int ql3xxx_send(struct sk_buff *skb, struct net_device *ndev)
2253 oal_entry->len = 2307 oal_entry->len =
2254 cpu_to_le32(le32_to_cpu(oal_entry->len) | OAL_LAST_ENTRY); 2308 cpu_to_le32(le32_to_cpu(oal_entry->len) | OAL_LAST_ENTRY);
2255 } 2309 }
2310
2311 return NETDEV_TX_OK;
2312
2313map_error:
2314 /* A PCI mapping failed and now we will need to back out
2315 * We need to traverse through the oal's and associated pages which
2316 * have been mapped and now we must unmap them to clean up properly
2317 */
2318
2319 seg = 1;
2320 oal_entry = (struct oal_entry *)&mac_iocb_ptr->buf_addr0_low;
2321 oal = tx_cb->oal;
2322 for (i=0; i<completed_segs; i++,seg++) {
2323 oal_entry++;
2324
2325 if((seg == 2 && seg_cnt > 3) || /* Check for continuation */
2326 (seg == 7 && seg_cnt > 8) || /* requirements. It's strange */
2327 (seg == 12 && seg_cnt > 13) || /* but necessary. */
2328 (seg == 17 && seg_cnt > 18)) {
2329 pci_unmap_single(qdev->pdev,
2330 pci_unmap_addr(&tx_cb->map[seg], mapaddr),
2331 pci_unmap_len(&tx_cb->map[seg], maplen),
2332 PCI_DMA_TODEVICE);
2333 oal++;
2334 seg++;
2335 }
2336
2337 pci_unmap_page(qdev->pdev,
2338 pci_unmap_addr(&tx_cb->map[seg], mapaddr),
2339 pci_unmap_len(&tx_cb->map[seg], maplen),
2340 PCI_DMA_TODEVICE);
2341 }
2342
2343 pci_unmap_single(qdev->pdev,
2344 pci_unmap_addr(&tx_cb->map[0], mapaddr),
2345 pci_unmap_addr(&tx_cb->map[0], maplen),
2346 PCI_DMA_TODEVICE);
2347
2348 return NETDEV_TX_BUSY;
2349
2350}
2351
2352/*
2353 * The difference between 3022 and 3032 sends:
2354 * 3022 only supports a simple single segment transmission.
2355 * 3032 supports checksumming and scatter/gather lists (fragments).
2356 * The 3032 supports sglists by using the 3 addr/len pairs (ALP)
2357 * in the IOCB plus a chain of outbound address lists (OAL) that
2358 * each contain 5 ALPs. The last ALP of the IOCB (3rd) or OAL (5th)
2359 * will used to point to an OAL when more ALP entries are required.
2360 * The IOCB is always the top of the chain followed by one or more
2361 * OALs (when necessary).
2362 */
2363static int ql3xxx_send(struct sk_buff *skb, struct net_device *ndev)
2364{
2365 struct ql3_adapter *qdev = (struct ql3_adapter *)netdev_priv(ndev);
2366 struct ql3xxx_port_registers __iomem *port_regs = qdev->mem_map_registers;
2367 struct ql_tx_buf_cb *tx_cb;
2368 u32 tot_len = skb->len;
2369 struct ob_mac_iocb_req *mac_iocb_ptr;
2370
2371 if (unlikely(atomic_read(&qdev->tx_count) < 2)) {
2372 return NETDEV_TX_BUSY;
2373 }
2374
2375 tx_cb = &qdev->tx_buf[qdev->req_producer_index] ;
2376 if((tx_cb->seg_count = ql_get_seg_count(qdev,
2377 (skb_shinfo(skb)->nr_frags))) == -1) {
2378 printk(KERN_ERR PFX"%s: invalid segment count!\n",__func__);
2379 return NETDEV_TX_OK;
2380 }
2381
2382 mac_iocb_ptr = tx_cb->queue_entry;
2383 mac_iocb_ptr->opcode = qdev->mac_ob_opcode;
2384 mac_iocb_ptr->flags = OB_MAC_IOCB_REQ_X;
2385 mac_iocb_ptr->flags |= qdev->mb_bit_mask;
2386 mac_iocb_ptr->transaction_id = qdev->req_producer_index;
2387 mac_iocb_ptr->data_len = cpu_to_le16((u16) tot_len);
2388 tx_cb->skb = skb;
2389 if (qdev->device_id == QL3032_DEVICE_ID &&
2390 skb->ip_summed == CHECKSUM_PARTIAL)
2391 ql_hw_csum_setup(skb, mac_iocb_ptr);
2392
2393 if(ql_send_map(qdev,mac_iocb_ptr,tx_cb,skb) != NETDEV_TX_OK) {
2394 printk(KERN_ERR PFX"%s: Could not map the segments!\n",__func__);
2395 return NETDEV_TX_BUSY;
2396 }
2397
2256 wmb(); 2398 wmb();
2257 qdev->req_producer_index++; 2399 qdev->req_producer_index++;
2258 if (qdev->req_producer_index == NUM_REQ_Q_ENTRIES) 2400 if (qdev->req_producer_index == NUM_REQ_Q_ENTRIES)
@@ -2338,12 +2480,19 @@ static int ql_alloc_buffer_queues(struct ql3_adapter *qdev)
2338{ 2480{
2339 /* Create Large Buffer Queue */ 2481 /* Create Large Buffer Queue */
2340 qdev->lrg_buf_q_size = 2482 qdev->lrg_buf_q_size =
2341 NUM_LBUFQ_ENTRIES * sizeof(struct lrg_buf_q_entry); 2483 qdev->num_lbufq_entries * sizeof(struct lrg_buf_q_entry);
2342 if (qdev->lrg_buf_q_size < PAGE_SIZE) 2484 if (qdev->lrg_buf_q_size < PAGE_SIZE)
2343 qdev->lrg_buf_q_alloc_size = PAGE_SIZE; 2485 qdev->lrg_buf_q_alloc_size = PAGE_SIZE;
2344 else 2486 else
2345 qdev->lrg_buf_q_alloc_size = qdev->lrg_buf_q_size * 2; 2487 qdev->lrg_buf_q_alloc_size = qdev->lrg_buf_q_size * 2;
2346 2488
2489 qdev->lrg_buf = kmalloc(qdev->num_large_buffers * sizeof(struct ql_rcv_buf_cb),GFP_KERNEL);
2490 if (qdev->lrg_buf == NULL) {
2491 printk(KERN_ERR PFX
2492 "%s: qdev->lrg_buf alloc failed.\n", qdev->ndev->name);
2493 return -ENOMEM;
2494 }
2495
2347 qdev->lrg_buf_q_alloc_virt_addr = 2496 qdev->lrg_buf_q_alloc_virt_addr =
2348 pci_alloc_consistent(qdev->pdev, 2497 pci_alloc_consistent(qdev->pdev,
2349 qdev->lrg_buf_q_alloc_size, 2498 qdev->lrg_buf_q_alloc_size,
@@ -2393,7 +2542,7 @@ static void ql_free_buffer_queues(struct ql3_adapter *qdev)
2393 "%s: Already done.\n", qdev->ndev->name); 2542 "%s: Already done.\n", qdev->ndev->name);
2394 return; 2543 return;
2395 } 2544 }
2396 2545 if(qdev->lrg_buf) kfree(qdev->lrg_buf);
2397 pci_free_consistent(qdev->pdev, 2546 pci_free_consistent(qdev->pdev,
2398 qdev->lrg_buf_q_alloc_size, 2547 qdev->lrg_buf_q_alloc_size,
2399 qdev->lrg_buf_q_alloc_virt_addr, 2548 qdev->lrg_buf_q_alloc_virt_addr,
@@ -2438,8 +2587,6 @@ static int ql_alloc_small_buffers(struct ql3_adapter *qdev)
2438 2587
2439 small_buf_q_entry = qdev->small_buf_q_virt_addr; 2588 small_buf_q_entry = qdev->small_buf_q_virt_addr;
2440 2589
2441 qdev->last_rsp_offset = qdev->small_buf_phy_addr_low;
2442
2443 /* Initialize the small buffer queue. */ 2590 /* Initialize the small buffer queue. */
2444 for (i = 0; i < (QL_ADDR_ELE_PER_BUFQ_ENTRY * NUM_SBUFQ_ENTRIES); i++) { 2591 for (i = 0; i < (QL_ADDR_ELE_PER_BUFQ_ENTRY * NUM_SBUFQ_ENTRIES); i++) {
2445 small_buf_q_entry->addr_high = 2592 small_buf_q_entry->addr_high =
@@ -2476,7 +2623,7 @@ static void ql_free_large_buffers(struct ql3_adapter *qdev)
2476 int i = 0; 2623 int i = 0;
2477 struct ql_rcv_buf_cb *lrg_buf_cb; 2624 struct ql_rcv_buf_cb *lrg_buf_cb;
2478 2625
2479 for (i = 0; i < NUM_LARGE_BUFFERS; i++) { 2626 for (i = 0; i < qdev->num_large_buffers; i++) {
2480 lrg_buf_cb = &qdev->lrg_buf[i]; 2627 lrg_buf_cb = &qdev->lrg_buf[i];
2481 if (lrg_buf_cb->skb) { 2628 if (lrg_buf_cb->skb) {
2482 dev_kfree_skb(lrg_buf_cb->skb); 2629 dev_kfree_skb(lrg_buf_cb->skb);
@@ -2497,7 +2644,7 @@ static void ql_init_large_buffers(struct ql3_adapter *qdev)
2497 struct ql_rcv_buf_cb *lrg_buf_cb; 2644 struct ql_rcv_buf_cb *lrg_buf_cb;
2498 struct bufq_addr_element *buf_addr_ele = qdev->lrg_buf_q_virt_addr; 2645 struct bufq_addr_element *buf_addr_ele = qdev->lrg_buf_q_virt_addr;
2499 2646
2500 for (i = 0; i < NUM_LARGE_BUFFERS; i++) { 2647 for (i = 0; i < qdev->num_large_buffers; i++) {
2501 lrg_buf_cb = &qdev->lrg_buf[i]; 2648 lrg_buf_cb = &qdev->lrg_buf[i];
2502 buf_addr_ele->addr_high = lrg_buf_cb->buf_phy_addr_high; 2649 buf_addr_ele->addr_high = lrg_buf_cb->buf_phy_addr_high;
2503 buf_addr_ele->addr_low = lrg_buf_cb->buf_phy_addr_low; 2650 buf_addr_ele->addr_low = lrg_buf_cb->buf_phy_addr_low;
@@ -2512,10 +2659,12 @@ static int ql_alloc_large_buffers(struct ql3_adapter *qdev)
2512 int i; 2659 int i;
2513 struct ql_rcv_buf_cb *lrg_buf_cb; 2660 struct ql_rcv_buf_cb *lrg_buf_cb;
2514 struct sk_buff *skb; 2661 struct sk_buff *skb;
2515 u64 map; 2662 dma_addr_t map;
2663 int err;
2516 2664
2517 for (i = 0; i < NUM_LARGE_BUFFERS; i++) { 2665 for (i = 0; i < qdev->num_large_buffers; i++) {
2518 skb = dev_alloc_skb(qdev->lrg_buffer_len); 2666 skb = netdev_alloc_skb(qdev->ndev,
2667 qdev->lrg_buffer_len);
2519 if (unlikely(!skb)) { 2668 if (unlikely(!skb)) {
2520 /* Better luck next round */ 2669 /* Better luck next round */
2521 printk(KERN_ERR PFX 2670 printk(KERN_ERR PFX
@@ -2541,6 +2690,15 @@ static int ql_alloc_large_buffers(struct ql3_adapter *qdev)
2541 qdev->lrg_buffer_len - 2690 qdev->lrg_buffer_len -
2542 QL_HEADER_SPACE, 2691 QL_HEADER_SPACE,
2543 PCI_DMA_FROMDEVICE); 2692 PCI_DMA_FROMDEVICE);
2693
2694 err = pci_dma_mapping_error(map);
2695 if(err) {
2696 printk(KERN_ERR "%s: PCI mapping failed with error: %d\n",
2697 qdev->ndev->name, err);
2698 ql_free_large_buffers(qdev);
2699 return -ENOMEM;
2700 }
2701
2544 pci_unmap_addr_set(lrg_buf_cb, mapaddr, map); 2702 pci_unmap_addr_set(lrg_buf_cb, mapaddr, map);
2545 pci_unmap_len_set(lrg_buf_cb, maplen, 2703 pci_unmap_len_set(lrg_buf_cb, maplen,
2546 qdev->lrg_buffer_len - 2704 qdev->lrg_buffer_len -
@@ -2592,9 +2750,15 @@ static int ql_create_send_free_list(struct ql3_adapter *qdev)
2592 2750
2593static int ql_alloc_mem_resources(struct ql3_adapter *qdev) 2751static int ql_alloc_mem_resources(struct ql3_adapter *qdev)
2594{ 2752{
2595 if (qdev->ndev->mtu == NORMAL_MTU_SIZE) 2753 if (qdev->ndev->mtu == NORMAL_MTU_SIZE) {
2754 qdev->num_lbufq_entries = NUM_LBUFQ_ENTRIES;
2596 qdev->lrg_buffer_len = NORMAL_MTU_SIZE; 2755 qdev->lrg_buffer_len = NORMAL_MTU_SIZE;
2756 }
2597 else if (qdev->ndev->mtu == JUMBO_MTU_SIZE) { 2757 else if (qdev->ndev->mtu == JUMBO_MTU_SIZE) {
2758 /*
2759 * Bigger buffers, so less of them.
2760 */
2761 qdev->num_lbufq_entries = JUMBO_NUM_LBUFQ_ENTRIES;
2598 qdev->lrg_buffer_len = JUMBO_MTU_SIZE; 2762 qdev->lrg_buffer_len = JUMBO_MTU_SIZE;
2599 } else { 2763 } else {
2600 printk(KERN_ERR PFX 2764 printk(KERN_ERR PFX
@@ -2602,6 +2766,7 @@ static int ql_alloc_mem_resources(struct ql3_adapter *qdev)
2602 qdev->ndev->name); 2766 qdev->ndev->name);
2603 return -ENOMEM; 2767 return -ENOMEM;
2604 } 2768 }
2769 qdev->num_large_buffers = qdev->num_lbufq_entries * QL_ADDR_ELE_PER_BUFQ_ENTRY;
2605 qdev->lrg_buffer_len += VLAN_ETH_HLEN + VLAN_ID_LEN + QL_HEADER_SPACE; 2770 qdev->lrg_buffer_len += VLAN_ETH_HLEN + VLAN_ID_LEN + QL_HEADER_SPACE;
2606 qdev->max_frame_size = 2771 qdev->max_frame_size =
2607 (qdev->lrg_buffer_len - QL_HEADER_SPACE) + ETHERNET_CRC_SIZE; 2772 (qdev->lrg_buffer_len - QL_HEADER_SPACE) + ETHERNET_CRC_SIZE;
@@ -2834,7 +2999,7 @@ static int ql_adapter_initialize(struct ql3_adapter *qdev)
2834 &hmem_regs->rxLargeQBaseAddrLow, 2999 &hmem_regs->rxLargeQBaseAddrLow,
2835 LS_64BITS(qdev->lrg_buf_q_phy_addr)); 3000 LS_64BITS(qdev->lrg_buf_q_phy_addr));
2836 3001
2837 ql_write_page1_reg(qdev, &hmem_regs->rxLargeQLength, NUM_LBUFQ_ENTRIES); 3002 ql_write_page1_reg(qdev, &hmem_regs->rxLargeQLength, qdev->num_lbufq_entries);
2838 3003
2839 ql_write_page1_reg(qdev, 3004 ql_write_page1_reg(qdev,
2840 &hmem_regs->rxLargeBufferLength, 3005 &hmem_regs->rxLargeBufferLength,
@@ -2856,7 +3021,7 @@ static int ql_adapter_initialize(struct ql3_adapter *qdev)
2856 3021
2857 qdev->small_buf_q_producer_index = NUM_SBUFQ_ENTRIES - 1; 3022 qdev->small_buf_q_producer_index = NUM_SBUFQ_ENTRIES - 1;
2858 qdev->small_buf_release_cnt = 8; 3023 qdev->small_buf_release_cnt = 8;
2859 qdev->lrg_buf_q_producer_index = NUM_LBUFQ_ENTRIES - 1; 3024 qdev->lrg_buf_q_producer_index = qdev->num_lbufq_entries - 1;
2860 qdev->lrg_buf_release_cnt = 8; 3025 qdev->lrg_buf_release_cnt = 8;
2861 qdev->lrg_buf_next_free = 3026 qdev->lrg_buf_next_free =
2862 (struct bufq_addr_element *)qdev->lrg_buf_q_virt_addr; 3027 (struct bufq_addr_element *)qdev->lrg_buf_q_virt_addr;
@@ -3292,6 +3457,7 @@ static int ql_adapter_up(struct ql3_adapter *qdev)
3292err_init: 3457err_init:
3293 ql_sem_unlock(qdev, QL_DRVR_SEM_MASK); 3458 ql_sem_unlock(qdev, QL_DRVR_SEM_MASK);
3294err_lock: 3459err_lock:
3460 spin_unlock_irqrestore(&qdev->hw_lock, hw_flags);
3295 free_irq(qdev->pdev->irq, ndev); 3461 free_irq(qdev->pdev->irq, ndev);
3296err_irq: 3462err_irq:
3297 if (qdev->msi && test_bit(QL_MSI_ENABLED,&qdev->flags)) { 3463 if (qdev->msi && test_bit(QL_MSI_ENABLED,&qdev->flags)) {
@@ -3343,27 +3509,6 @@ static struct net_device_stats *ql3xxx_get_stats(struct net_device *dev)
3343 return &qdev->stats; 3509 return &qdev->stats;
3344} 3510}
3345 3511
3346static int ql3xxx_change_mtu(struct net_device *ndev, int new_mtu)
3347{
3348 struct ql3_adapter *qdev = netdev_priv(ndev);
3349 printk(KERN_ERR PFX "%s: new mtu size = %d.\n", ndev->name, new_mtu);
3350 if (new_mtu != NORMAL_MTU_SIZE && new_mtu != JUMBO_MTU_SIZE) {
3351 printk(KERN_ERR PFX
3352 "%s: mtu size of %d is not valid. Use exactly %d or "
3353 "%d.\n", ndev->name, new_mtu, NORMAL_MTU_SIZE,
3354 JUMBO_MTU_SIZE);
3355 return -EINVAL;
3356 }
3357
3358 if (!netif_running(ndev)) {
3359 ndev->mtu = new_mtu;
3360 return 0;
3361 }
3362
3363 ndev->mtu = new_mtu;
3364 return ql_cycle_adapter(qdev,QL_DO_RESET);
3365}
3366
3367static void ql3xxx_set_multicast_list(struct net_device *ndev) 3512static void ql3xxx_set_multicast_list(struct net_device *ndev)
3368{ 3513{
3369 /* 3514 /*
@@ -3609,8 +3754,12 @@ static int __devinit ql3xxx_probe(struct pci_dev *pdev,
3609 } 3754 }
3610 3755
3611 ndev = alloc_etherdev(sizeof(struct ql3_adapter)); 3756 ndev = alloc_etherdev(sizeof(struct ql3_adapter));
3612 if (!ndev) 3757 if (!ndev) {
3758 printk(KERN_ERR PFX "%s could not alloc etherdev\n",
3759 pci_name(pdev));
3760 err = -ENOMEM;
3613 goto err_out_free_regions; 3761 goto err_out_free_regions;
3762 }
3614 3763
3615 SET_MODULE_OWNER(ndev); 3764 SET_MODULE_OWNER(ndev);
3616 SET_NETDEV_DEV(ndev, &pdev->dev); 3765 SET_NETDEV_DEV(ndev, &pdev->dev);
@@ -3639,6 +3788,7 @@ static int __devinit ql3xxx_probe(struct pci_dev *pdev,
3639 if (!qdev->mem_map_registers) { 3788 if (!qdev->mem_map_registers) {
3640 printk(KERN_ERR PFX "%s: cannot map device registers\n", 3789 printk(KERN_ERR PFX "%s: cannot map device registers\n",
3641 pci_name(pdev)); 3790 pci_name(pdev));
3791 err = -EIO;
3642 goto err_out_free_ndev; 3792 goto err_out_free_ndev;
3643 } 3793 }
3644 3794
@@ -3650,7 +3800,6 @@ static int __devinit ql3xxx_probe(struct pci_dev *pdev,
3650 ndev->hard_start_xmit = ql3xxx_send; 3800 ndev->hard_start_xmit = ql3xxx_send;
3651 ndev->stop = ql3xxx_close; 3801 ndev->stop = ql3xxx_close;
3652 ndev->get_stats = ql3xxx_get_stats; 3802 ndev->get_stats = ql3xxx_get_stats;
3653 ndev->change_mtu = ql3xxx_change_mtu;
3654 ndev->set_multicast_list = ql3xxx_set_multicast_list; 3803 ndev->set_multicast_list = ql3xxx_set_multicast_list;
3655 SET_ETHTOOL_OPS(ndev, &ql3xxx_ethtool_ops); 3804 SET_ETHTOOL_OPS(ndev, &ql3xxx_ethtool_ops);
3656 ndev->set_mac_address = ql3xxx_set_mac_address; 3805 ndev->set_mac_address = ql3xxx_set_mac_address;
@@ -3667,6 +3816,7 @@ static int __devinit ql3xxx_probe(struct pci_dev *pdev,
3667 printk(KERN_ALERT PFX 3816 printk(KERN_ALERT PFX
3668 "ql3xxx_probe: Adapter #%d, Invalid NVRAM parameters.\n", 3817 "ql3xxx_probe: Adapter #%d, Invalid NVRAM parameters.\n",
3669 qdev->index); 3818 qdev->index);
3819 err = -EIO;
3670 goto err_out_iounmap; 3820 goto err_out_iounmap;
3671 } 3821 }
3672 3822
@@ -3674,9 +3824,11 @@ static int __devinit ql3xxx_probe(struct pci_dev *pdev,
3674 3824
3675 /* Validate and set parameters */ 3825 /* Validate and set parameters */
3676 if (qdev->mac_index) { 3826 if (qdev->mac_index) {
3827 ndev->mtu = qdev->nvram_data.macCfg_port1.etherMtu_mac ;
3677 memcpy(ndev->dev_addr, &qdev->nvram_data.funcCfg_fn2.macAddress, 3828 memcpy(ndev->dev_addr, &qdev->nvram_data.funcCfg_fn2.macAddress,
3678 ETH_ALEN); 3829 ETH_ALEN);
3679 } else { 3830 } else {
3831 ndev->mtu = qdev->nvram_data.macCfg_port0.etherMtu_mac ;
3680 memcpy(ndev->dev_addr, &qdev->nvram_data.funcCfg_fn0.macAddress, 3832 memcpy(ndev->dev_addr, &qdev->nvram_data.funcCfg_fn0.macAddress,
3681 ETH_ALEN); 3833 ETH_ALEN);
3682 } 3834 }
diff --git a/drivers/net/qla3xxx.h b/drivers/net/qla3xxx.h
index b2d76ea688..34cd6580fd 100755
--- a/drivers/net/qla3xxx.h
+++ b/drivers/net/qla3xxx.h
@@ -1014,13 +1014,15 @@ struct eeprom_data {
1014 1014
1015/* Transmit and Receive Buffers */ 1015/* Transmit and Receive Buffers */
1016#define NUM_LBUFQ_ENTRIES 128 1016#define NUM_LBUFQ_ENTRIES 128
1017#define JUMBO_NUM_LBUFQ_ENTRIES \
1018(NUM_LBUFQ_ENTRIES/(JUMBO_MTU_SIZE/NORMAL_MTU_SIZE))
1017#define NUM_SBUFQ_ENTRIES 64 1019#define NUM_SBUFQ_ENTRIES 64
1018#define QL_SMALL_BUFFER_SIZE 32 1020#define QL_SMALL_BUFFER_SIZE 32
1019#define QL_ADDR_ELE_PER_BUFQ_ENTRY \ 1021#define QL_ADDR_ELE_PER_BUFQ_ENTRY \
1020(sizeof(struct lrg_buf_q_entry) / sizeof(struct bufq_addr_element)) 1022(sizeof(struct lrg_buf_q_entry) / sizeof(struct bufq_addr_element))
1021 /* Each send has at least control block. This is how many we keep. */ 1023 /* Each send has at least control block. This is how many we keep. */
1022#define NUM_SMALL_BUFFERS NUM_SBUFQ_ENTRIES * QL_ADDR_ELE_PER_BUFQ_ENTRY 1024#define NUM_SMALL_BUFFERS NUM_SBUFQ_ENTRIES * QL_ADDR_ELE_PER_BUFQ_ENTRY
1023#define NUM_LARGE_BUFFERS NUM_LBUFQ_ENTRIES * QL_ADDR_ELE_PER_BUFQ_ENTRY 1025
1024#define QL_HEADER_SPACE 32 /* make header space at top of skb. */ 1026#define QL_HEADER_SPACE 32 /* make header space at top of skb. */
1025/* 1027/*
1026 * Large & Small Buffers for Receives 1028 * Large & Small Buffers for Receives
@@ -1092,7 +1094,6 @@ struct oal_entry {
1092 u32 len; 1094 u32 len;
1093#define OAL_LAST_ENTRY 0x80000000 /* Last valid buffer in list. */ 1095#define OAL_LAST_ENTRY 0x80000000 /* Last valid buffer in list. */
1094#define OAL_CONT_ENTRY 0x40000000 /* points to an OAL. (continuation) */ 1096#define OAL_CONT_ENTRY 0x40000000 /* points to an OAL. (continuation) */
1095 u32 reserved;
1096}; 1097};
1097 1098
1098struct oal { 1099struct oal {
@@ -1193,7 +1194,7 @@ struct ql3_adapter {
1193 struct net_rsp_iocb *rsp_current; 1194 struct net_rsp_iocb *rsp_current;
1194 u16 rsp_consumer_index; 1195 u16 rsp_consumer_index;
1195 u16 reserved_06; 1196 u16 reserved_06;
1196 u32 *prsp_producer_index; 1197 volatile u32 *prsp_producer_index;
1197 u32 rsp_producer_index_phy_addr_high; 1198 u32 rsp_producer_index_phy_addr_high;
1198 u32 rsp_producer_index_phy_addr_low; 1199 u32 rsp_producer_index_phy_addr_low;
1199 1200
@@ -1207,9 +1208,11 @@ struct ql3_adapter {
1207 u32 lrg_buf_q_producer_index; 1208 u32 lrg_buf_q_producer_index;
1208 u32 lrg_buf_release_cnt; 1209 u32 lrg_buf_release_cnt;
1209 struct bufq_addr_element *lrg_buf_next_free; 1210 struct bufq_addr_element *lrg_buf_next_free;
1211 u32 num_large_buffers;
1212 u32 num_lbufq_entries;
1210 1213
1211 /* Large (Receive) Buffers */ 1214 /* Large (Receive) Buffers */
1212 struct ql_rcv_buf_cb lrg_buf[NUM_LARGE_BUFFERS]; 1215 struct ql_rcv_buf_cb *lrg_buf;
1213 struct ql_rcv_buf_cb *lrg_buf_free_head; 1216 struct ql_rcv_buf_cb *lrg_buf_free_head;
1214 struct ql_rcv_buf_cb *lrg_buf_free_tail; 1217 struct ql_rcv_buf_cb *lrg_buf_free_tail;
1215 u32 lrg_buf_free_count; 1218 u32 lrg_buf_free_count;
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index 5598d86380..521b5f0618 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -572,8 +572,8 @@ static void rtl8169_xmii_reset_enable(void __iomem *ioaddr)
572{ 572{
573 unsigned int val; 573 unsigned int val;
574 574
575 mdio_write(ioaddr, MII_BMCR, BMCR_RESET); 575 val = mdio_read(ioaddr, MII_BMCR) | BMCR_RESET;
576 val = mdio_read(ioaddr, MII_BMCR); 576 mdio_write(ioaddr, MII_BMCR, val & 0xffff);
577} 577}
578 578
579static void rtl8169_check_link_status(struct net_device *dev, 579static void rtl8169_check_link_status(struct net_device *dev,
@@ -890,8 +890,7 @@ static void rtl8169_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
890 unsigned long flags; 890 unsigned long flags;
891 891
892 spin_lock_irqsave(&tp->lock, flags); 892 spin_lock_irqsave(&tp->lock, flags);
893 if (tp->vlgrp) 893 vlan_group_set_device(tp->vlgrp, vid, NULL);
894 tp->vlgrp->vlan_devices[vid] = NULL;
895 spin_unlock_irqrestore(&tp->lock, flags); 894 spin_unlock_irqrestore(&tp->lock, flags);
896} 895}
897 896
@@ -1369,11 +1368,7 @@ static inline void rtl8169_request_timer(struct net_device *dev)
1369 (tp->phy_version >= RTL_GIGA_PHY_VER_H)) 1368 (tp->phy_version >= RTL_GIGA_PHY_VER_H))
1370 return; 1369 return;
1371 1370
1372 init_timer(timer); 1371 mod_timer(timer, jiffies + RTL8169_PHY_TIMEOUT);
1373 timer->expires = jiffies + RTL8169_PHY_TIMEOUT;
1374 timer->data = (unsigned long)(dev);
1375 timer->function = rtl8169_phy_timer;
1376 add_timer(timer);
1377} 1372}
1378 1373
1379#ifdef CONFIG_NET_POLL_CONTROLLER 1374#ifdef CONFIG_NET_POLL_CONTROLLER
@@ -1686,6 +1681,10 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1686 tp->mmio_addr = ioaddr; 1681 tp->mmio_addr = ioaddr;
1687 tp->align = rtl_cfg_info[ent->driver_data].align; 1682 tp->align = rtl_cfg_info[ent->driver_data].align;
1688 1683
1684 init_timer(&tp->timer);
1685 tp->timer.data = (unsigned long) dev;
1686 tp->timer.function = rtl8169_phy_timer;
1687
1689 spin_lock_init(&tp->lock); 1688 spin_lock_init(&tp->lock);
1690 1689
1691 rc = register_netdev(dev); 1690 rc = register_netdev(dev);
@@ -1733,6 +1732,8 @@ rtl8169_remove_one(struct pci_dev *pdev)
1733 assert(dev != NULL); 1732 assert(dev != NULL);
1734 assert(tp != NULL); 1733 assert(tp != NULL);
1735 1734
1735 flush_scheduled_work();
1736
1736 unregister_netdev(dev); 1737 unregister_netdev(dev);
1737 rtl8169_release_board(pdev, dev, tp->mmio_addr); 1738 rtl8169_release_board(pdev, dev, tp->mmio_addr);
1738 pci_set_drvdata(pdev, NULL); 1739 pci_set_drvdata(pdev, NULL);
@@ -2161,10 +2162,13 @@ static void rtl8169_reinit_task(struct work_struct *work)
2161 struct net_device *dev = tp->dev; 2162 struct net_device *dev = tp->dev;
2162 int ret; 2163 int ret;
2163 2164
2164 if (netif_running(dev)) { 2165 rtnl_lock();
2165 rtl8169_wait_for_quiescence(dev); 2166
2166 rtl8169_close(dev); 2167 if (!netif_running(dev))
2167 } 2168 goto out_unlock;
2169
2170 rtl8169_wait_for_quiescence(dev);
2171 rtl8169_close(dev);
2168 2172
2169 ret = rtl8169_open(dev); 2173 ret = rtl8169_open(dev);
2170 if (unlikely(ret < 0)) { 2174 if (unlikely(ret < 0)) {
@@ -2179,6 +2183,9 @@ static void rtl8169_reinit_task(struct work_struct *work)
2179 } 2183 }
2180 rtl8169_schedule_work(dev, rtl8169_reinit_task); 2184 rtl8169_schedule_work(dev, rtl8169_reinit_task);
2181 } 2185 }
2186
2187out_unlock:
2188 rtnl_unlock();
2182} 2189}
2183 2190
2184static void rtl8169_reset_task(struct work_struct *work) 2191static void rtl8169_reset_task(struct work_struct *work)
@@ -2187,8 +2194,10 @@ static void rtl8169_reset_task(struct work_struct *work)
2187 container_of(work, struct rtl8169_private, task.work); 2194 container_of(work, struct rtl8169_private, task.work);
2188 struct net_device *dev = tp->dev; 2195 struct net_device *dev = tp->dev;
2189 2196
2197 rtnl_lock();
2198
2190 if (!netif_running(dev)) 2199 if (!netif_running(dev))
2191 return; 2200 goto out_unlock;
2192 2201
2193 rtl8169_wait_for_quiescence(dev); 2202 rtl8169_wait_for_quiescence(dev);
2194 2203
@@ -2210,6 +2219,9 @@ static void rtl8169_reset_task(struct work_struct *work)
2210 } 2219 }
2211 rtl8169_schedule_work(dev, rtl8169_reset_task); 2220 rtl8169_schedule_work(dev, rtl8169_reset_task);
2212 } 2221 }
2222
2223out_unlock:
2224 rtnl_unlock();
2213} 2225}
2214 2226
2215static void rtl8169_tx_timeout(struct net_device *dev) 2227static void rtl8169_tx_timeout(struct net_device *dev)
@@ -2722,8 +2734,6 @@ static void rtl8169_down(struct net_device *dev)
2722 2734
2723 netif_stop_queue(dev); 2735 netif_stop_queue(dev);
2724 2736
2725 flush_scheduled_work();
2726
2727core_down: 2737core_down:
2728 spin_lock_irq(&tp->lock); 2738 spin_lock_irq(&tp->lock);
2729 2739
diff --git a/drivers/net/s2io-regs.h b/drivers/net/s2io-regs.h
index 0e345cbc2b..33fb7f3b70 100644
--- a/drivers/net/s2io-regs.h
+++ b/drivers/net/s2io-regs.h
@@ -430,6 +430,7 @@ struct XENA_dev_config {
430#define TX_PA_CFG_IGNORE_SNAP_OUI BIT(2) 430#define TX_PA_CFG_IGNORE_SNAP_OUI BIT(2)
431#define TX_PA_CFG_IGNORE_LLC_CTRL BIT(3) 431#define TX_PA_CFG_IGNORE_LLC_CTRL BIT(3)
432#define TX_PA_CFG_IGNORE_L2_ERR BIT(6) 432#define TX_PA_CFG_IGNORE_L2_ERR BIT(6)
433#define RX_PA_CFG_STRIP_VLAN_TAG BIT(15)
433 434
434/* Recent add, used only debug purposes. */ 435/* Recent add, used only debug purposes. */
435 u64 pcc_enable; 436 u64 pcc_enable;
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index e8e0d94e9b..46ebf141ee 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -42,6 +42,14 @@
42 * Possible values '1' for enable '0' for disable. Default is '0' 42 * Possible values '1' for enable '0' for disable. Default is '0'
43 * lro_max_pkts: This parameter defines maximum number of packets can be 43 * lro_max_pkts: This parameter defines maximum number of packets can be
44 * aggregated as a single large packet 44 * aggregated as a single large packet
45 * napi: This parameter used to enable/disable NAPI (polling Rx)
46 * Possible values '1' for enable and '0' for disable. Default is '1'
47 * ufo: This parameter used to enable/disable UDP Fragmentation Offload(UFO)
48 * Possible values '1' for enable and '0' for disable. Default is '0'
49 * vlan_tag_strip: This can be used to enable or disable vlan stripping.
50 * Possible values '1' for enable , '0' for disable.
51 * Default is '2' - which means disable in promisc mode
52 * and enable in non-promiscuous mode.
45 ************************************************************************/ 53 ************************************************************************/
46 54
47#include <linux/module.h> 55#include <linux/module.h>
@@ -76,7 +84,7 @@
76#include "s2io.h" 84#include "s2io.h"
77#include "s2io-regs.h" 85#include "s2io-regs.h"
78 86
79#define DRV_VERSION "2.0.16.1" 87#define DRV_VERSION "2.0.17.1"
80 88
81/* S2io Driver name & version. */ 89/* S2io Driver name & version. */
82static char s2io_driver_name[] = "Neterion"; 90static char s2io_driver_name[] = "Neterion";
@@ -131,7 +139,7 @@ static char s2io_gstrings[][ETH_GSTRING_LEN] = {
131 "BIST Test\t(offline)" 139 "BIST Test\t(offline)"
132}; 140};
133 141
134static char ethtool_stats_keys[][ETH_GSTRING_LEN] = { 142static char ethtool_xena_stats_keys[][ETH_GSTRING_LEN] = {
135 {"tmac_frms"}, 143 {"tmac_frms"},
136 {"tmac_data_octets"}, 144 {"tmac_data_octets"},
137 {"tmac_drop_frms"}, 145 {"tmac_drop_frms"},
@@ -225,7 +233,10 @@ static char ethtool_stats_keys[][ETH_GSTRING_LEN] = {
225 {"rxd_rd_cnt"}, 233 {"rxd_rd_cnt"},
226 {"rxd_wr_cnt"}, 234 {"rxd_wr_cnt"},
227 {"txf_rd_cnt"}, 235 {"txf_rd_cnt"},
228 {"rxf_wr_cnt"}, 236 {"rxf_wr_cnt"}
237};
238
239static char ethtool_enhanced_stats_keys[][ETH_GSTRING_LEN] = {
229 {"rmac_ttl_1519_4095_frms"}, 240 {"rmac_ttl_1519_4095_frms"},
230 {"rmac_ttl_4096_8191_frms"}, 241 {"rmac_ttl_4096_8191_frms"},
231 {"rmac_ttl_8192_max_frms"}, 242 {"rmac_ttl_8192_max_frms"},
@@ -241,7 +252,10 @@ static char ethtool_stats_keys[][ETH_GSTRING_LEN] = {
241 {"rmac_red_discard"}, 252 {"rmac_red_discard"},
242 {"rmac_rts_discard"}, 253 {"rmac_rts_discard"},
243 {"rmac_ingm_full_discard"}, 254 {"rmac_ingm_full_discard"},
244 {"link_fault_cnt"}, 255 {"link_fault_cnt"}
256};
257
258static char ethtool_driver_stats_keys[][ETH_GSTRING_LEN] = {
245 {"\n DRIVER STATISTICS"}, 259 {"\n DRIVER STATISTICS"},
246 {"single_bit_ecc_errs"}, 260 {"single_bit_ecc_errs"},
247 {"double_bit_ecc_errs"}, 261 {"double_bit_ecc_errs"},
@@ -269,8 +283,16 @@ static char ethtool_stats_keys[][ETH_GSTRING_LEN] = {
269 ("lro_avg_aggr_pkts"), 283 ("lro_avg_aggr_pkts"),
270}; 284};
271 285
272#define S2IO_STAT_LEN sizeof(ethtool_stats_keys)/ ETH_GSTRING_LEN 286#define S2IO_XENA_STAT_LEN sizeof(ethtool_xena_stats_keys)/ ETH_GSTRING_LEN
273#define S2IO_STAT_STRINGS_LEN S2IO_STAT_LEN * ETH_GSTRING_LEN 287#define S2IO_ENHANCED_STAT_LEN sizeof(ethtool_enhanced_stats_keys)/ \
288 ETH_GSTRING_LEN
289#define S2IO_DRIVER_STAT_LEN sizeof(ethtool_driver_stats_keys)/ ETH_GSTRING_LEN
290
291#define XFRAME_I_STAT_LEN (S2IO_XENA_STAT_LEN + S2IO_DRIVER_STAT_LEN )
292#define XFRAME_II_STAT_LEN (XFRAME_I_STAT_LEN + S2IO_ENHANCED_STAT_LEN )
293
294#define XFRAME_I_STAT_STRINGS_LEN ( XFRAME_I_STAT_LEN * ETH_GSTRING_LEN )
295#define XFRAME_II_STAT_STRINGS_LEN ( XFRAME_II_STAT_LEN * ETH_GSTRING_LEN )
274 296
275#define S2IO_TEST_LEN sizeof(s2io_gstrings) / ETH_GSTRING_LEN 297#define S2IO_TEST_LEN sizeof(s2io_gstrings) / ETH_GSTRING_LEN
276#define S2IO_STRINGS_LEN S2IO_TEST_LEN * ETH_GSTRING_LEN 298#define S2IO_STRINGS_LEN S2IO_TEST_LEN * ETH_GSTRING_LEN
@@ -293,6 +315,9 @@ static void s2io_vlan_rx_register(struct net_device *dev,
293 spin_unlock_irqrestore(&nic->tx_lock, flags); 315 spin_unlock_irqrestore(&nic->tx_lock, flags);
294} 316}
295 317
318/* A flag indicating whether 'RX_PA_CFG_STRIP_VLAN_TAG' bit is set or not */
319int vlan_strip_flag;
320
296/* Unregister the vlan */ 321/* Unregister the vlan */
297static void s2io_vlan_rx_kill_vid(struct net_device *dev, unsigned long vid) 322static void s2io_vlan_rx_kill_vid(struct net_device *dev, unsigned long vid)
298{ 323{
@@ -300,8 +325,7 @@ static void s2io_vlan_rx_kill_vid(struct net_device *dev, unsigned long vid)
300 unsigned long flags; 325 unsigned long flags;
301 326
302 spin_lock_irqsave(&nic->tx_lock, flags); 327 spin_lock_irqsave(&nic->tx_lock, flags);
303 if (nic->vlgrp) 328 vlan_group_set_device(nic->vlgrp, vid, NULL);
304 nic->vlgrp->vlan_devices[vid] = NULL;
305 spin_unlock_irqrestore(&nic->tx_lock, flags); 329 spin_unlock_irqrestore(&nic->tx_lock, flags);
306} 330}
307 331
@@ -404,6 +428,7 @@ S2IO_PARM_INT(indicate_max_pkts, 0);
404 428
405S2IO_PARM_INT(napi, 1); 429S2IO_PARM_INT(napi, 1);
406S2IO_PARM_INT(ufo, 0); 430S2IO_PARM_INT(ufo, 0);
431S2IO_PARM_INT(vlan_tag_strip, NO_STRIP_IN_PROMISC);
407 432
408static unsigned int tx_fifo_len[MAX_TX_FIFOS] = 433static unsigned int tx_fifo_len[MAX_TX_FIFOS] =
409 {DEFAULT_FIFO_0_LEN, [1 ...(MAX_TX_FIFOS - 1)] = DEFAULT_FIFO_1_7_LEN}; 434 {DEFAULT_FIFO_0_LEN, [1 ...(MAX_TX_FIFOS - 1)] = DEFAULT_FIFO_1_7_LEN};
@@ -1371,6 +1396,16 @@ static int init_nic(struct s2io_nic *nic)
1371 &bar0->rts_frm_len_n[i]); 1396 &bar0->rts_frm_len_n[i]);
1372 } 1397 }
1373 } 1398 }
1399
1400 /* Disable differentiated services steering logic */
1401 for (i = 0; i < 64; i++) {
1402 if (rts_ds_steer(nic, i, 0) == FAILURE) {
1403 DBG_PRINT(ERR_DBG, "%s: failed rts ds steering",
1404 dev->name);
1405 DBG_PRINT(ERR_DBG, "set on codepoint %d\n", i);
1406 return FAILURE;
1407 }
1408 }
1374 1409
1375 /* Program statistics memory */ 1410 /* Program statistics memory */
1376 writeq(mac_control->stats_mem_phy, &bar0->stat_addr); 1411 writeq(mac_control->stats_mem_phy, &bar0->stat_addr);
@@ -1943,6 +1978,13 @@ static int start_nic(struct s2io_nic *nic)
1943 writeq(val64, &bar0->rx_pa_cfg); 1978 writeq(val64, &bar0->rx_pa_cfg);
1944 } 1979 }
1945 1980
1981 if (vlan_tag_strip == 0) {
1982 val64 = readq(&bar0->rx_pa_cfg);
1983 val64 &= ~RX_PA_CFG_STRIP_VLAN_TAG;
1984 writeq(val64, &bar0->rx_pa_cfg);
1985 vlan_strip_flag = 0;
1986 }
1987
1946 /* 1988 /*
1947 * Enabling MC-RLDRAM. After enabling the device, we timeout 1989 * Enabling MC-RLDRAM. After enabling the device, we timeout
1948 * for around 100ms, which is approximately the time required 1990 * for around 100ms, which is approximately the time required
@@ -3195,26 +3237,37 @@ static void alarm_intr_handler(struct s2io_nic *nic)
3195 * SUCCESS on success and FAILURE on failure. 3237 * SUCCESS on success and FAILURE on failure.
3196 */ 3238 */
3197 3239
3198static int wait_for_cmd_complete(void __iomem *addr, u64 busy_bit) 3240static int wait_for_cmd_complete(void __iomem *addr, u64 busy_bit,
3241 int bit_state)
3199{ 3242{
3200 int ret = FAILURE, cnt = 0; 3243 int ret = FAILURE, cnt = 0, delay = 1;
3201 u64 val64; 3244 u64 val64;
3202 3245
3203 while (TRUE) { 3246 if ((bit_state != S2IO_BIT_RESET) && (bit_state != S2IO_BIT_SET))
3247 return FAILURE;
3248
3249 do {
3204 val64 = readq(addr); 3250 val64 = readq(addr);
3205 if (!(val64 & busy_bit)) { 3251 if (bit_state == S2IO_BIT_RESET) {
3206 ret = SUCCESS; 3252 if (!(val64 & busy_bit)) {
3207 break; 3253 ret = SUCCESS;
3254 break;
3255 }
3256 } else {
3257 if (!(val64 & busy_bit)) {
3258 ret = SUCCESS;
3259 break;
3260 }
3208 } 3261 }
3209 3262
3210 if(in_interrupt()) 3263 if(in_interrupt())
3211 mdelay(50); 3264 mdelay(delay);
3212 else 3265 else
3213 msleep(50); 3266 msleep(delay);
3214 3267
3215 if (cnt++ > 10) 3268 if (++cnt >= 10)
3216 break; 3269 delay = 50;
3217 } 3270 } while (cnt < 20);
3218 return ret; 3271 return ret;
3219} 3272}
3220/* 3273/*
@@ -3340,6 +3393,9 @@ new_way:
3340 writeq(val64, &bar0->pcc_err_reg); 3393 writeq(val64, &bar0->pcc_err_reg);
3341 } 3394 }
3342 3395
3396 /* restore the previously assigned mac address */
3397 s2io_set_mac_addr(sp->dev, (u8 *)&sp->def_mac_addr[0].mac_addr);
3398
3343 sp->device_enabled_once = FALSE; 3399 sp->device_enabled_once = FALSE;
3344} 3400}
3345 3401
@@ -3758,7 +3814,6 @@ static int s2io_close(struct net_device *dev)
3758{ 3814{
3759 struct s2io_nic *sp = dev->priv; 3815 struct s2io_nic *sp = dev->priv;
3760 3816
3761 flush_scheduled_work();
3762 netif_stop_queue(dev); 3817 netif_stop_queue(dev);
3763 /* Reset card, kill tasklet and free Tx and Rx buffers. */ 3818 /* Reset card, kill tasklet and free Tx and Rx buffers. */
3764 s2io_card_down(sp); 3819 s2io_card_down(sp);
@@ -4088,6 +4143,11 @@ static void s2io_txpic_intr_handle(struct s2io_nic *sp)
4088 val64 &= ~GPIO_INT_MASK_LINK_UP; 4143 val64 &= ~GPIO_INT_MASK_LINK_UP;
4089 val64 |= GPIO_INT_MASK_LINK_DOWN; 4144 val64 |= GPIO_INT_MASK_LINK_DOWN;
4090 writeq(val64, &bar0->gpio_int_mask); 4145 writeq(val64, &bar0->gpio_int_mask);
4146
4147 /* turn off LED */
4148 val64 = readq(&bar0->adapter_control);
4149 val64 = val64 &(~ADAPTER_LED_ON);
4150 writeq(val64, &bar0->adapter_control);
4091 } 4151 }
4092 } 4152 }
4093 val64 = readq(&bar0->gpio_int_mask); 4153 val64 = readq(&bar0->gpio_int_mask);
@@ -4297,7 +4357,8 @@ static void s2io_set_multicast(struct net_device *dev)
4297 writeq(val64, &bar0->rmac_addr_cmd_mem); 4357 writeq(val64, &bar0->rmac_addr_cmd_mem);
4298 /* Wait till command completes */ 4358 /* Wait till command completes */
4299 wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem, 4359 wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
4300 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING); 4360 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
4361 S2IO_BIT_RESET);
4301 4362
4302 sp->m_cast_flg = 1; 4363 sp->m_cast_flg = 1;
4303 sp->all_multi_pos = MAC_MC_ALL_MC_ADDR_OFFSET; 4364 sp->all_multi_pos = MAC_MC_ALL_MC_ADDR_OFFSET;
@@ -4313,7 +4374,8 @@ static void s2io_set_multicast(struct net_device *dev)
4313 writeq(val64, &bar0->rmac_addr_cmd_mem); 4374 writeq(val64, &bar0->rmac_addr_cmd_mem);
4314 /* Wait till command completes */ 4375 /* Wait till command completes */
4315 wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem, 4376 wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
4316 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING); 4377 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
4378 S2IO_BIT_RESET);
4317 4379
4318 sp->m_cast_flg = 0; 4380 sp->m_cast_flg = 0;
4319 sp->all_multi_pos = 0; 4381 sp->all_multi_pos = 0;
@@ -4330,6 +4392,13 @@ static void s2io_set_multicast(struct net_device *dev)
4330 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key); 4392 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4331 writel((u32) (val64 >> 32), (add + 4)); 4393 writel((u32) (val64 >> 32), (add + 4));
4332 4394
4395 if (vlan_tag_strip != 1) {
4396 val64 = readq(&bar0->rx_pa_cfg);
4397 val64 &= ~RX_PA_CFG_STRIP_VLAN_TAG;
4398 writeq(val64, &bar0->rx_pa_cfg);
4399 vlan_strip_flag = 0;
4400 }
4401
4333 val64 = readq(&bar0->mac_cfg); 4402 val64 = readq(&bar0->mac_cfg);
4334 sp->promisc_flg = 1; 4403 sp->promisc_flg = 1;
4335 DBG_PRINT(INFO_DBG, "%s: entered promiscuous mode\n", 4404 DBG_PRINT(INFO_DBG, "%s: entered promiscuous mode\n",
@@ -4345,6 +4414,13 @@ static void s2io_set_multicast(struct net_device *dev)
4345 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key); 4414 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4346 writel((u32) (val64 >> 32), (add + 4)); 4415 writel((u32) (val64 >> 32), (add + 4));
4347 4416
4417 if (vlan_tag_strip != 0) {
4418 val64 = readq(&bar0->rx_pa_cfg);
4419 val64 |= RX_PA_CFG_STRIP_VLAN_TAG;
4420 writeq(val64, &bar0->rx_pa_cfg);
4421 vlan_strip_flag = 1;
4422 }
4423
4348 val64 = readq(&bar0->mac_cfg); 4424 val64 = readq(&bar0->mac_cfg);
4349 sp->promisc_flg = 0; 4425 sp->promisc_flg = 0;
4350 DBG_PRINT(INFO_DBG, "%s: left promiscuous mode\n", 4426 DBG_PRINT(INFO_DBG, "%s: left promiscuous mode\n",
@@ -4379,7 +4455,8 @@ static void s2io_set_multicast(struct net_device *dev)
4379 4455
4380 /* Wait for command completes */ 4456 /* Wait for command completes */
4381 if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem, 4457 if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
4382 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING)) { 4458 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
4459 S2IO_BIT_RESET)) {
4383 DBG_PRINT(ERR_DBG, "%s: Adding ", 4460 DBG_PRINT(ERR_DBG, "%s: Adding ",
4384 dev->name); 4461 dev->name);
4385 DBG_PRINT(ERR_DBG, "Multicasts failed\n"); 4462 DBG_PRINT(ERR_DBG, "Multicasts failed\n");
@@ -4410,7 +4487,8 @@ static void s2io_set_multicast(struct net_device *dev)
4410 4487
4411 /* Wait for command completes */ 4488 /* Wait for command completes */
4412 if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem, 4489 if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
4413 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING)) { 4490 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
4491 S2IO_BIT_RESET)) {
4414 DBG_PRINT(ERR_DBG, "%s: Adding ", 4492 DBG_PRINT(ERR_DBG, "%s: Adding ",
4415 dev->name); 4493 dev->name);
4416 DBG_PRINT(ERR_DBG, "Multicasts failed\n"); 4494 DBG_PRINT(ERR_DBG, "Multicasts failed\n");
@@ -4436,6 +4514,7 @@ static int s2io_set_mac_addr(struct net_device *dev, u8 * addr)
4436 struct XENA_dev_config __iomem *bar0 = sp->bar0; 4514 struct XENA_dev_config __iomem *bar0 = sp->bar0;
4437 register u64 val64, mac_addr = 0; 4515 register u64 val64, mac_addr = 0;
4438 int i; 4516 int i;
4517 u64 old_mac_addr = 0;
4439 4518
4440 /* 4519 /*
4441 * Set the new MAC address as the new unicast filter and reflect this 4520 * Set the new MAC address as the new unicast filter and reflect this
@@ -4445,6 +4524,22 @@ static int s2io_set_mac_addr(struct net_device *dev, u8 * addr)
4445 for (i = 0; i < ETH_ALEN; i++) { 4524 for (i = 0; i < ETH_ALEN; i++) {
4446 mac_addr <<= 8; 4525 mac_addr <<= 8;
4447 mac_addr |= addr[i]; 4526 mac_addr |= addr[i];
4527 old_mac_addr <<= 8;
4528 old_mac_addr |= sp->def_mac_addr[0].mac_addr[i];
4529 }
4530
4531 if(0 == mac_addr)
4532 return SUCCESS;
4533
4534 /* Update the internal structure with this new mac address */
4535 if(mac_addr != old_mac_addr) {
4536 memset(sp->def_mac_addr[0].mac_addr, 0, sizeof(ETH_ALEN));
4537 sp->def_mac_addr[0].mac_addr[5] = (u8) (mac_addr);
4538 sp->def_mac_addr[0].mac_addr[4] = (u8) (mac_addr >> 8);
4539 sp->def_mac_addr[0].mac_addr[3] = (u8) (mac_addr >> 16);
4540 sp->def_mac_addr[0].mac_addr[2] = (u8) (mac_addr >> 24);
4541 sp->def_mac_addr[0].mac_addr[1] = (u8) (mac_addr >> 32);
4542 sp->def_mac_addr[0].mac_addr[0] = (u8) (mac_addr >> 40);
4448 } 4543 }
4449 4544
4450 writeq(RMAC_ADDR_DATA0_MEM_ADDR(mac_addr), 4545 writeq(RMAC_ADDR_DATA0_MEM_ADDR(mac_addr),
@@ -4456,7 +4551,7 @@ static int s2io_set_mac_addr(struct net_device *dev, u8 * addr)
4456 writeq(val64, &bar0->rmac_addr_cmd_mem); 4551 writeq(val64, &bar0->rmac_addr_cmd_mem);
4457 /* Wait till command completes */ 4552 /* Wait till command completes */
4458 if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem, 4553 if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
4459 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING)) { 4554 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING, S2IO_BIT_RESET)) {
4460 DBG_PRINT(ERR_DBG, "%s: set_mac_addr failed\n", dev->name); 4555 DBG_PRINT(ERR_DBG, "%s: set_mac_addr failed\n", dev->name);
4461 return FAILURE; 4556 return FAILURE;
4462 } 4557 }
@@ -4547,7 +4642,11 @@ static void s2io_ethtool_gdrvinfo(struct net_device *dev,
4547 info->regdump_len = XENA_REG_SPACE; 4642 info->regdump_len = XENA_REG_SPACE;
4548 info->eedump_len = XENA_EEPROM_SPACE; 4643 info->eedump_len = XENA_EEPROM_SPACE;
4549 info->testinfo_len = S2IO_TEST_LEN; 4644 info->testinfo_len = S2IO_TEST_LEN;
4550 info->n_stats = S2IO_STAT_LEN; 4645
4646 if (sp->device_type == XFRAME_I_DEVICE)
4647 info->n_stats = XFRAME_I_STAT_LEN;
4648 else
4649 info->n_stats = XFRAME_II_STAT_LEN;
4551} 4650}
4552 4651
4553/** 4652/**
@@ -5569,22 +5668,30 @@ static void s2io_get_ethtool_stats(struct net_device *dev,
5569 tmp_stats[i++] = le32_to_cpu(stat_info->rxd_wr_cnt); 5668 tmp_stats[i++] = le32_to_cpu(stat_info->rxd_wr_cnt);
5570 tmp_stats[i++] = le32_to_cpu(stat_info->txf_rd_cnt); 5669 tmp_stats[i++] = le32_to_cpu(stat_info->txf_rd_cnt);
5571 tmp_stats[i++] = le32_to_cpu(stat_info->rxf_wr_cnt); 5670 tmp_stats[i++] = le32_to_cpu(stat_info->rxf_wr_cnt);
5572 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_1519_4095_frms); 5671
5573 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_4096_8191_frms); 5672 /* Enhanced statistics exist only for Hercules */
5574 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_8192_max_frms); 5673 if(sp->device_type == XFRAME_II_DEVICE) {
5575 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_gt_max_frms); 5674 tmp_stats[i++] =
5576 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_osized_alt_frms); 5675 le64_to_cpu(stat_info->rmac_ttl_1519_4095_frms);
5577 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_jabber_alt_frms); 5676 tmp_stats[i++] =
5578 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_gt_max_alt_frms); 5677 le64_to_cpu(stat_info->rmac_ttl_4096_8191_frms);
5579 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_vlan_frms); 5678 tmp_stats[i++] =
5580 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_len_discard); 5679 le64_to_cpu(stat_info->rmac_ttl_8192_max_frms);
5581 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_fcs_discard); 5680 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_gt_max_frms);
5582 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_pf_discard); 5681 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_osized_alt_frms);
5583 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_da_discard); 5682 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_jabber_alt_frms);
5584 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_red_discard); 5683 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_gt_max_alt_frms);
5585 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_rts_discard); 5684 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_vlan_frms);
5586 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_ingm_full_discard); 5685 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_len_discard);
5587 tmp_stats[i++] = le32_to_cpu(stat_info->link_fault_cnt); 5686 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_fcs_discard);
5687 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_pf_discard);
5688 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_da_discard);
5689 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_red_discard);
5690 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_rts_discard);
5691 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_ingm_full_discard);
5692 tmp_stats[i++] = le32_to_cpu(stat_info->link_fault_cnt);
5693 }
5694
5588 tmp_stats[i++] = 0; 5695 tmp_stats[i++] = 0;
5589 tmp_stats[i++] = stat_info->sw_stat.single_ecc_errs; 5696 tmp_stats[i++] = stat_info->sw_stat.single_ecc_errs;
5590 tmp_stats[i++] = stat_info->sw_stat.double_ecc_errs; 5697 tmp_stats[i++] = stat_info->sw_stat.double_ecc_errs;
@@ -5664,18 +5771,42 @@ static int s2io_ethtool_self_test_count(struct net_device *dev)
5664static void s2io_ethtool_get_strings(struct net_device *dev, 5771static void s2io_ethtool_get_strings(struct net_device *dev,
5665 u32 stringset, u8 * data) 5772 u32 stringset, u8 * data)
5666{ 5773{
5774 int stat_size = 0;
5775 struct s2io_nic *sp = dev->priv;
5776
5667 switch (stringset) { 5777 switch (stringset) {
5668 case ETH_SS_TEST: 5778 case ETH_SS_TEST:
5669 memcpy(data, s2io_gstrings, S2IO_STRINGS_LEN); 5779 memcpy(data, s2io_gstrings, S2IO_STRINGS_LEN);
5670 break; 5780 break;
5671 case ETH_SS_STATS: 5781 case ETH_SS_STATS:
5672 memcpy(data, &ethtool_stats_keys, 5782 stat_size = sizeof(ethtool_xena_stats_keys);
5673 sizeof(ethtool_stats_keys)); 5783 memcpy(data, &ethtool_xena_stats_keys,stat_size);
5784 if(sp->device_type == XFRAME_II_DEVICE) {
5785 memcpy(data + stat_size,
5786 &ethtool_enhanced_stats_keys,
5787 sizeof(ethtool_enhanced_stats_keys));
5788 stat_size += sizeof(ethtool_enhanced_stats_keys);
5789 }
5790
5791 memcpy(data + stat_size, &ethtool_driver_stats_keys,
5792 sizeof(ethtool_driver_stats_keys));
5674 } 5793 }
5675} 5794}
5676static int s2io_ethtool_get_stats_count(struct net_device *dev) 5795static int s2io_ethtool_get_stats_count(struct net_device *dev)
5677{ 5796{
5678 return (S2IO_STAT_LEN); 5797 struct s2io_nic *sp = dev->priv;
5798 int stat_count = 0;
5799 switch(sp->device_type) {
5800 case XFRAME_I_DEVICE:
5801 stat_count = XFRAME_I_STAT_LEN;
5802 break;
5803
5804 case XFRAME_II_DEVICE:
5805 stat_count = XFRAME_II_STAT_LEN;
5806 break;
5807 }
5808
5809 return stat_count;
5679} 5810}
5680 5811
5681static int s2io_ethtool_op_set_tx_csum(struct net_device *dev, u32 data) 5812static int s2io_ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
@@ -5847,9 +5978,14 @@ static void s2io_set_link(struct work_struct *work)
5847 register u64 val64; 5978 register u64 val64;
5848 u16 subid; 5979 u16 subid;
5849 5980
5981 rtnl_lock();
5982
5983 if (!netif_running(dev))
5984 goto out_unlock;
5985
5850 if (test_and_set_bit(0, &(nic->link_state))) { 5986 if (test_and_set_bit(0, &(nic->link_state))) {
5851 /* The card is being reset, no point doing anything */ 5987 /* The card is being reset, no point doing anything */
5852 return; 5988 goto out_unlock;
5853 } 5989 }
5854 5990
5855 subid = nic->pdev->subsystem_device; 5991 subid = nic->pdev->subsystem_device;
@@ -5903,6 +6039,9 @@ static void s2io_set_link(struct work_struct *work)
5903 s2io_link(nic, LINK_DOWN); 6039 s2io_link(nic, LINK_DOWN);
5904 } 6040 }
5905 clear_bit(0, &(nic->link_state)); 6041 clear_bit(0, &(nic->link_state));
6042
6043out_unlock:
6044 rtnl_unlock();
5906} 6045}
5907 6046
5908static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp, 6047static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
@@ -6059,10 +6198,13 @@ static int rxd_owner_bit_reset(struct s2io_nic *sp)
6059 rx_blocks[j].rxds[k].virt_addr; 6198 rx_blocks[j].rxds[k].virt_addr;
6060 if(sp->rxd_mode >= RXD_MODE_3A) 6199 if(sp->rxd_mode >= RXD_MODE_3A)
6061 ba = &mac_control->rings[i].ba[j][k]; 6200 ba = &mac_control->rings[i].ba[j][k];
6062 set_rxd_buffer_pointer(sp, rxdp, ba, 6201 if (set_rxd_buffer_pointer(sp, rxdp, ba,
6063 &skb,(u64 *)&temp0_64, 6202 &skb,(u64 *)&temp0_64,
6064 (u64 *)&temp1_64, 6203 (u64 *)&temp1_64,
6065 (u64 *)&temp2_64, size); 6204 (u64 *)&temp2_64,
6205 size) == ENOMEM) {
6206 return 0;
6207 }
6066 6208
6067 set_rxd_buffer_size(sp, rxdp, size); 6209 set_rxd_buffer_size(sp, rxdp, size);
6068 wmb(); 6210 wmb();
@@ -6105,7 +6247,7 @@ static int s2io_add_isr(struct s2io_nic * sp)
6105 } 6247 }
6106 } 6248 }
6107 if (sp->intr_type == MSI_X) { 6249 if (sp->intr_type == MSI_X) {
6108 int i; 6250 int i, msix_tx_cnt=0,msix_rx_cnt=0;
6109 6251
6110 for (i=1; (sp->s2io_entries[i].in_use == MSIX_FLG); i++) { 6252 for (i=1; (sp->s2io_entries[i].in_use == MSIX_FLG); i++) {
6111 if (sp->s2io_entries[i].type == MSIX_FIFO_TYPE) { 6253 if (sp->s2io_entries[i].type == MSIX_FIFO_TYPE) {
@@ -6114,16 +6256,36 @@ static int s2io_add_isr(struct s2io_nic * sp)
6114 err = request_irq(sp->entries[i].vector, 6256 err = request_irq(sp->entries[i].vector,
6115 s2io_msix_fifo_handle, 0, sp->desc[i], 6257 s2io_msix_fifo_handle, 0, sp->desc[i],
6116 sp->s2io_entries[i].arg); 6258 sp->s2io_entries[i].arg);
6117 DBG_PRINT(ERR_DBG, "%s @ 0x%llx\n", sp->desc[i], 6259 /* If either data or addr is zero print it */
6118 (unsigned long long)sp->msix_info[i].addr); 6260 if(!(sp->msix_info[i].addr &&
6261 sp->msix_info[i].data)) {
6262 DBG_PRINT(ERR_DBG, "%s @ Addr:0x%llx"
6263 "Data:0x%lx\n",sp->desc[i],
6264 (unsigned long long)
6265 sp->msix_info[i].addr,
6266 (unsigned long)
6267 ntohl(sp->msix_info[i].data));
6268 } else {
6269 msix_tx_cnt++;
6270 }
6119 } else { 6271 } else {
6120 sprintf(sp->desc[i], "%s:MSI-X-%d-RX", 6272 sprintf(sp->desc[i], "%s:MSI-X-%d-RX",
6121 dev->name, i); 6273 dev->name, i);
6122 err = request_irq(sp->entries[i].vector, 6274 err = request_irq(sp->entries[i].vector,
6123 s2io_msix_ring_handle, 0, sp->desc[i], 6275 s2io_msix_ring_handle, 0, sp->desc[i],
6124 sp->s2io_entries[i].arg); 6276 sp->s2io_entries[i].arg);
6125 DBG_PRINT(ERR_DBG, "%s @ 0x%llx\n", sp->desc[i], 6277 /* If either data or addr is zero print it */
6126 (unsigned long long)sp->msix_info[i].addr); 6278 if(!(sp->msix_info[i].addr &&
6279 sp->msix_info[i].data)) {
6280 DBG_PRINT(ERR_DBG, "%s @ Addr:0x%llx"
6281 "Data:0x%lx\n",sp->desc[i],
6282 (unsigned long long)
6283 sp->msix_info[i].addr,
6284 (unsigned long)
6285 ntohl(sp->msix_info[i].data));
6286 } else {
6287 msix_rx_cnt++;
6288 }
6127 } 6289 }
6128 if (err) { 6290 if (err) {
6129 DBG_PRINT(ERR_DBG,"%s:MSI-X-%d registration " 6291 DBG_PRINT(ERR_DBG,"%s:MSI-X-%d registration "
@@ -6133,6 +6295,8 @@ static int s2io_add_isr(struct s2io_nic * sp)
6133 } 6295 }
6134 sp->s2io_entries[i].in_use = MSIX_REGISTERED_SUCCESS; 6296 sp->s2io_entries[i].in_use = MSIX_REGISTERED_SUCCESS;
6135 } 6297 }
6298 printk("MSI-X-TX %d entries enabled\n",msix_tx_cnt);
6299 printk("MSI-X-RX %d entries enabled\n",msix_rx_cnt);
6136 } 6300 }
6137 if (sp->intr_type == INTA) { 6301 if (sp->intr_type == INTA) {
6138 err = request_irq((int) sp->pdev->irq, s2io_isr, IRQF_SHARED, 6302 err = request_irq((int) sp->pdev->irq, s2io_isr, IRQF_SHARED,
@@ -6356,6 +6520,11 @@ static void s2io_restart_nic(struct work_struct *work)
6356 struct s2io_nic *sp = container_of(work, struct s2io_nic, rst_timer_task); 6520 struct s2io_nic *sp = container_of(work, struct s2io_nic, rst_timer_task);
6357 struct net_device *dev = sp->dev; 6521 struct net_device *dev = sp->dev;
6358 6522
6523 rtnl_lock();
6524
6525 if (!netif_running(dev))
6526 goto out_unlock;
6527
6359 s2io_card_down(sp); 6528 s2io_card_down(sp);
6360 if (s2io_card_up(sp)) { 6529 if (s2io_card_up(sp)) {
6361 DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n", 6530 DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
@@ -6364,7 +6533,8 @@ static void s2io_restart_nic(struct work_struct *work)
6364 netif_wake_queue(dev); 6533 netif_wake_queue(dev);
6365 DBG_PRINT(ERR_DBG, "%s: was reset by Tx watchdog timer\n", 6534 DBG_PRINT(ERR_DBG, "%s: was reset by Tx watchdog timer\n",
6366 dev->name); 6535 dev->name);
6367 6536out_unlock:
6537 rtnl_unlock();
6368} 6538}
6369 6539
6370/** 6540/**
@@ -6554,7 +6724,8 @@ static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp)
6554 6724
6555 if (!sp->lro) { 6725 if (!sp->lro) {
6556 skb->protocol = eth_type_trans(skb, dev); 6726 skb->protocol = eth_type_trans(skb, dev);
6557 if (sp->vlgrp && RXD_GET_VLAN_TAG(rxdp->Control_2)) { 6727 if ((sp->vlgrp && RXD_GET_VLAN_TAG(rxdp->Control_2) &&
6728 vlan_strip_flag)) {
6558 /* Queueing the vlan frame to the upper layer */ 6729 /* Queueing the vlan frame to the upper layer */
6559 if (napi) 6730 if (napi)
6560 vlan_hwaccel_receive_skb(skb, sp->vlgrp, 6731 vlan_hwaccel_receive_skb(skb, sp->vlgrp,
@@ -6691,8 +6862,7 @@ static int s2io_verify_parm(struct pci_dev *pdev, u8 *dev_intr_type)
6691 "Defaulting to INTA\n"); 6862 "Defaulting to INTA\n");
6692 *dev_intr_type = INTA; 6863 *dev_intr_type = INTA;
6693 } 6864 }
6694 if ( (rx_ring_num > 1) && (*dev_intr_type != INTA) ) 6865
6695 napi = 0;
6696 if (rx_ring_mode > 3) { 6866 if (rx_ring_mode > 3) {
6697 DBG_PRINT(ERR_DBG, "s2io: Requested ring mode not supported\n"); 6867 DBG_PRINT(ERR_DBG, "s2io: Requested ring mode not supported\n");
6698 DBG_PRINT(ERR_DBG, "s2io: Defaulting to 3-buffer mode\n"); 6868 DBG_PRINT(ERR_DBG, "s2io: Defaulting to 3-buffer mode\n");
@@ -6702,6 +6872,37 @@ static int s2io_verify_parm(struct pci_dev *pdev, u8 *dev_intr_type)
6702} 6872}
6703 6873
6704/** 6874/**
6875 * rts_ds_steer - Receive traffic steering based on IPv4 or IPv6 TOS
6876 * or Traffic class respectively.
6877 * @nic: device peivate variable
6878 * Description: The function configures the receive steering to
6879 * desired receive ring.
6880 * Return Value: SUCCESS on success and
6881 * '-1' on failure (endian settings incorrect).
6882 */
6883static int rts_ds_steer(struct s2io_nic *nic, u8 ds_codepoint, u8 ring)
6884{
6885 struct XENA_dev_config __iomem *bar0 = nic->bar0;
6886 register u64 val64 = 0;
6887
6888 if (ds_codepoint > 63)
6889 return FAILURE;
6890
6891 val64 = RTS_DS_MEM_DATA(ring);
6892 writeq(val64, &bar0->rts_ds_mem_data);
6893
6894 val64 = RTS_DS_MEM_CTRL_WE |
6895 RTS_DS_MEM_CTRL_STROBE_NEW_CMD |
6896 RTS_DS_MEM_CTRL_OFFSET(ds_codepoint);
6897
6898 writeq(val64, &bar0->rts_ds_mem_ctrl);
6899
6900 return wait_for_cmd_complete(&bar0->rts_ds_mem_ctrl,
6901 RTS_DS_MEM_CTRL_STROBE_CMD_BEING_EXECUTED,
6902 S2IO_BIT_RESET);
6903}
6904
6905/**
6705 * s2io_init_nic - Initialization of the adapter . 6906 * s2io_init_nic - Initialization of the adapter .
6706 * @pdev : structure containing the PCI related information of the device. 6907 * @pdev : structure containing the PCI related information of the device.
6707 * @pre: List of PCI devices supported by the driver listed in s2io_tbl. 6908 * @pre: List of PCI devices supported by the driver listed in s2io_tbl.
@@ -6995,13 +7196,11 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
6995 RMAC_ADDR_CMD_MEM_OFFSET(0 + MAC_MAC_ADDR_START_OFFSET); 7196 RMAC_ADDR_CMD_MEM_OFFSET(0 + MAC_MAC_ADDR_START_OFFSET);
6996 writeq(val64, &bar0->rmac_addr_cmd_mem); 7197 writeq(val64, &bar0->rmac_addr_cmd_mem);
6997 wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem, 7198 wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
6998 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING); 7199 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING, S2IO_BIT_RESET);
6999 tmp64 = readq(&bar0->rmac_addr_data0_mem); 7200 tmp64 = readq(&bar0->rmac_addr_data0_mem);
7000 mac_down = (u32) tmp64; 7201 mac_down = (u32) tmp64;
7001 mac_up = (u32) (tmp64 >> 32); 7202 mac_up = (u32) (tmp64 >> 32);
7002 7203
7003 memset(sp->def_mac_addr[0].mac_addr, 0, sizeof(ETH_ALEN));
7004
7005 sp->def_mac_addr[0].mac_addr[3] = (u8) (mac_up); 7204 sp->def_mac_addr[0].mac_addr[3] = (u8) (mac_up);
7006 sp->def_mac_addr[0].mac_addr[2] = (u8) (mac_up >> 8); 7205 sp->def_mac_addr[0].mac_addr[2] = (u8) (mac_up >> 8);
7007 sp->def_mac_addr[0].mac_addr[1] = (u8) (mac_up >> 16); 7206 sp->def_mac_addr[0].mac_addr[1] = (u8) (mac_up >> 16);
@@ -7173,6 +7372,8 @@ static void __devexit s2io_rem_nic(struct pci_dev *pdev)
7173 return; 7372 return;
7174 } 7373 }
7175 7374
7375 flush_scheduled_work();
7376
7176 sp = dev->priv; 7377 sp = dev->priv;
7177 unregister_netdev(dev); 7378 unregister_netdev(dev);
7178 7379
diff --git a/drivers/net/s2io.h b/drivers/net/s2io.h
index 0de0c65f94..803137ca4b 100644
--- a/drivers/net/s2io.h
+++ b/drivers/net/s2io.h
@@ -32,7 +32,8 @@
32#define FAILURE -1 32#define FAILURE -1
33#define S2IO_MINUS_ONE 0xFFFFFFFFFFFFFFFFULL 33#define S2IO_MINUS_ONE 0xFFFFFFFFFFFFFFFFULL
34#define S2IO_MAX_PCI_CONFIG_SPACE_REINIT 100 34#define S2IO_MAX_PCI_CONFIG_SPACE_REINIT 100
35 35#define S2IO_BIT_RESET 1
36#define S2IO_BIT_SET 2
36#define CHECKBIT(value, nbit) (value & (1 << nbit)) 37#define CHECKBIT(value, nbit) (value & (1 << nbit))
37 38
38/* Maximum time to flicker LED when asked to identify NIC using ethtool */ 39/* Maximum time to flicker LED when asked to identify NIC using ethtool */
@@ -296,6 +297,9 @@ struct stat_block {
296 struct xpakStat xpak_stat; 297 struct xpakStat xpak_stat;
297}; 298};
298 299
300/* Default value for 'vlan_strip_tag' configuration parameter */
301#define NO_STRIP_IN_PROMISC 2
302
299/* 303/*
300 * Structures representing different init time configuration 304 * Structures representing different init time configuration
301 * parameters of the NIC. 305 * parameters of the NIC.
@@ -1005,7 +1009,8 @@ static int s2io_set_swapper(struct s2io_nic * sp);
1005static void s2io_card_down(struct s2io_nic *nic); 1009static void s2io_card_down(struct s2io_nic *nic);
1006static int s2io_card_up(struct s2io_nic *nic); 1010static int s2io_card_up(struct s2io_nic *nic);
1007static int get_xena_rev_id(struct pci_dev *pdev); 1011static int get_xena_rev_id(struct pci_dev *pdev);
1008static int wait_for_cmd_complete(void __iomem *addr, u64 busy_bit); 1012static int wait_for_cmd_complete(void __iomem *addr, u64 busy_bit,
1013 int bit_state);
1009static int s2io_add_isr(struct s2io_nic * sp); 1014static int s2io_add_isr(struct s2io_nic * sp);
1010static void s2io_rem_isr(struct s2io_nic * sp); 1015static void s2io_rem_isr(struct s2io_nic * sp);
1011 1016
@@ -1019,6 +1024,7 @@ static void queue_rx_frame(struct sk_buff *skb);
1019static void update_L3L4_header(struct s2io_nic *sp, struct lro *lro); 1024static void update_L3L4_header(struct s2io_nic *sp, struct lro *lro);
1020static void lro_append_pkt(struct s2io_nic *sp, struct lro *lro, 1025static void lro_append_pkt(struct s2io_nic *sp, struct lro *lro,
1021 struct sk_buff *skb, u32 tcp_len); 1026 struct sk_buff *skb, u32 tcp_len);
1027static int rts_ds_steer(struct s2io_nic *nic, u8 ds_codepoint, u8 ring);
1022 1028
1023#define s2io_tcp_mss(skb) skb_shinfo(skb)->gso_size 1029#define s2io_tcp_mss(skb) skb_shinfo(skb)->gso_size
1024#define s2io_udp_mss(skb) skb_shinfo(skb)->gso_size 1030#define s2io_udp_mss(skb) skb_shinfo(skb)->gso_size
diff --git a/drivers/net/sgiseeq.c b/drivers/net/sgiseeq.c
index a833e7f975..52ed522a23 100644
--- a/drivers/net/sgiseeq.c
+++ b/drivers/net/sgiseeq.c
@@ -12,26 +12,15 @@
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/types.h> 13#include <linux/types.h>
14#include <linux/interrupt.h> 14#include <linux/interrupt.h>
15#include <linux/ioport.h>
16#include <linux/socket.h>
17#include <linux/in.h>
18#include <linux/route.h>
19#include <linux/slab.h> 15#include <linux/slab.h>
20#include <linux/string.h> 16#include <linux/string.h>
21#include <linux/delay.h> 17#include <linux/delay.h>
22#include <linux/netdevice.h> 18#include <linux/netdevice.h>
23#include <linux/etherdevice.h> 19#include <linux/etherdevice.h>
24#include <linux/skbuff.h> 20#include <linux/skbuff.h>
25#include <linux/bitops.h>
26 21
27#include <asm/byteorder.h>
28#include <asm/io.h>
29#include <asm/system.h>
30#include <asm/page.h>
31#include <asm/pgtable.h>
32#include <asm/sgi/hpc3.h> 22#include <asm/sgi/hpc3.h>
33#include <asm/sgi/ip22.h> 23#include <asm/sgi/ip22.h>
34#include <asm/sgialib.h>
35 24
36#include "sgiseeq.h" 25#include "sgiseeq.h"
37 26
diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
index 45d91b1591..b08508b358 100644
--- a/drivers/net/sis190.c
+++ b/drivers/net/sis190.c
@@ -909,6 +909,9 @@ static void sis190_phy_task(struct work_struct *work)
909 909
910 rtnl_lock(); 910 rtnl_lock();
911 911
912 if (!netif_running(dev))
913 goto out_unlock;
914
912 val = mdio_read(ioaddr, phy_id, MII_BMCR); 915 val = mdio_read(ioaddr, phy_id, MII_BMCR);
913 if (val & BMCR_RESET) { 916 if (val & BMCR_RESET) {
914 // FIXME: needlessly high ? -- FR 02/07/2005 917 // FIXME: needlessly high ? -- FR 02/07/2005
@@ -981,6 +984,7 @@ static void sis190_phy_task(struct work_struct *work)
981 netif_carrier_on(dev); 984 netif_carrier_on(dev);
982 } 985 }
983 986
987out_unlock:
984 rtnl_unlock(); 988 rtnl_unlock();
985} 989}
986 990
@@ -1102,8 +1106,6 @@ static void sis190_down(struct net_device *dev)
1102 1106
1103 netif_stop_queue(dev); 1107 netif_stop_queue(dev);
1104 1108
1105 flush_scheduled_work();
1106
1107 do { 1109 do {
1108 spin_lock_irq(&tp->lock); 1110 spin_lock_irq(&tp->lock);
1109 1111
@@ -1857,6 +1859,7 @@ static void __devexit sis190_remove_one(struct pci_dev *pdev)
1857 struct net_device *dev = pci_get_drvdata(pdev); 1859 struct net_device *dev = pci_get_drvdata(pdev);
1858 1860
1859 sis190_mii_remove(dev); 1861 sis190_mii_remove(dev);
1862 flush_scheduled_work();
1860 unregister_netdev(dev); 1863 unregister_netdev(dev);
1861 sis190_release_board(pdev); 1864 sis190_release_board(pdev);
1862 pci_set_drvdata(pdev, NULL); 1865 pci_set_drvdata(pdev, NULL);
diff --git a/drivers/net/sis900.c b/drivers/net/sis900.c
index fb2b530516..b3750f2842 100644
--- a/drivers/net/sis900.c
+++ b/drivers/net/sis900.c
@@ -968,10 +968,10 @@ static void mdio_write(struct net_device *net_dev, int phy_id, int location,
968 968
969static u16 sis900_reset_phy(struct net_device *net_dev, int phy_addr) 969static u16 sis900_reset_phy(struct net_device *net_dev, int phy_addr)
970{ 970{
971 int i = 0; 971 int i;
972 u16 status; 972 u16 status;
973 973
974 while (i++ < 2) 974 for (i = 0; i < 2; i++)
975 status = mdio_read(net_dev, phy_addr, MII_STATUS); 975 status = mdio_read(net_dev, phy_addr, MII_STATUS);
976 976
977 mdio_write( net_dev, phy_addr, MII_CONTROL, MII_CNTL_RESET ); 977 mdio_write( net_dev, phy_addr, MII_CONTROL, MII_CNTL_RESET );
@@ -1430,7 +1430,7 @@ static void sis900_auto_negotiate(struct net_device *net_dev, int phy_addr)
1430 int i = 0; 1430 int i = 0;
1431 u32 status; 1431 u32 status;
1432 1432
1433 while (i++ < 2) 1433 for (i = 0; i < 2; i++)
1434 status = mdio_read(net_dev, phy_addr, MII_STATUS); 1434 status = mdio_read(net_dev, phy_addr, MII_STATUS);
1435 1435
1436 if (!(status & MII_STAT_LINK)){ 1436 if (!(status & MII_STAT_LINK)){
@@ -1466,9 +1466,9 @@ static void sis900_read_mode(struct net_device *net_dev, int *speed, int *duplex
1466 int phy_addr = sis_priv->cur_phy; 1466 int phy_addr = sis_priv->cur_phy;
1467 u32 status; 1467 u32 status;
1468 u16 autoadv, autorec; 1468 u16 autoadv, autorec;
1469 int i = 0; 1469 int i;
1470 1470
1471 while (i++ < 2) 1471 for (i = 0; i < 2; i++)
1472 status = mdio_read(net_dev, phy_addr, MII_STATUS); 1472 status = mdio_read(net_dev, phy_addr, MII_STATUS);
1473 1473
1474 if (!(status & MII_STAT_LINK)) 1474 if (!(status & MII_STAT_LINK))
diff --git a/drivers/net/sk98lin/skge.c b/drivers/net/sk98lin/skge.c
index 92d11b961d..e94ab256b5 100644
--- a/drivers/net/sk98lin/skge.c
+++ b/drivers/net/sk98lin/skge.c
@@ -5188,6 +5188,9 @@ static struct pci_driver skge_driver = {
5188 5188
5189static int __init skge_init(void) 5189static int __init skge_init(void)
5190{ 5190{
5191 printk(KERN_NOTICE "sk98lin: driver has been replaced by the skge driver"
5192 " and is scheduled for removal\n");
5193
5191 return pci_register_driver(&skge_driver); 5194 return pci_register_driver(&skge_driver);
5192} 5195}
5193 5196
diff --git a/drivers/net/skfp/cfm.c b/drivers/net/skfp/cfm.c
index 4c8aaa7623..5310d39b57 100644
--- a/drivers/net/skfp/cfm.c
+++ b/drivers/net/skfp/cfm.c
@@ -73,7 +73,7 @@ static const char * const cfm_events[] = {
73/* 73/*
74 * map from state to downstream port type 74 * map from state to downstream port type
75 */ 75 */
76static const u_char cf_to_ptype[] = { 76static const unsigned char cf_to_ptype[] = {
77 TNONE,TNONE,TNONE,TNONE,TNONE, 77 TNONE,TNONE,TNONE,TNONE,TNONE,
78 TNONE,TB,TB,TS, 78 TNONE,TB,TB,TS,
79 TA,TB,TS,TB 79 TA,TB,TS,TB
diff --git a/drivers/net/skge.c b/drivers/net/skge.c
index e482e7fcbb..eea75a401b 100644
--- a/drivers/net/skge.c
+++ b/drivers/net/skge.c
@@ -77,13 +77,13 @@ static const struct pci_device_id skge_id_table[] = {
77 { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940B) }, 77 { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940B) },
78 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE) }, 78 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE) },
79 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_YU) }, 79 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_YU) },
80 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, PCI_DEVICE_ID_DLINK_DGE510T), }, 80 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, PCI_DEVICE_ID_DLINK_DGE510T) },
81 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b01) }, /* DGE-530T */ 81 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b01) }, /* DGE-530T */
82 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4320) }, 82 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4320) },
83 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5005) }, /* Belkin */ 83 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5005) }, /* Belkin */
84 { PCI_DEVICE(PCI_VENDOR_ID_CNET, PCI_DEVICE_ID_CNET_GIGACARD) }, 84 { PCI_DEVICE(PCI_VENDOR_ID_CNET, PCI_DEVICE_ID_CNET_GIGACARD) },
85 { PCI_DEVICE(PCI_VENDOR_ID_LINKSYS, PCI_DEVICE_ID_LINKSYS_EG1064) }, 85 { PCI_DEVICE(PCI_VENDOR_ID_LINKSYS, PCI_DEVICE_ID_LINKSYS_EG1064) },
86 { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0015, }, 86 { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0015 },
87 { 0 } 87 { 0 }
88}; 88};
89MODULE_DEVICE_TABLE(pci, skge_id_table); 89MODULE_DEVICE_TABLE(pci, skge_id_table);
@@ -1419,7 +1419,8 @@ static void xm_link_timer(struct work_struct *work)
1419 mutex_unlock(&hw->phy_mutex); 1419 mutex_unlock(&hw->phy_mutex);
1420 1420
1421nochange: 1421nochange:
1422 schedule_delayed_work(&skge->link_thread, LINK_HZ); 1422 if (netif_running(dev))
1423 schedule_delayed_work(&skge->link_thread, LINK_HZ);
1423} 1424}
1424 1425
1425static void genesis_mac_init(struct skge_hw *hw, int port) 1426static void genesis_mac_init(struct skge_hw *hw, int port)
@@ -2530,7 +2531,7 @@ static int skge_down(struct net_device *dev)
2530 2531
2531 netif_stop_queue(dev); 2532 netif_stop_queue(dev);
2532 if (hw->chip_id == CHIP_ID_GENESIS && hw->phy_type == SK_PHY_XMAC) 2533 if (hw->chip_id == CHIP_ID_GENESIS && hw->phy_type == SK_PHY_XMAC)
2533 cancel_rearming_delayed_work(&skge->link_thread); 2534 cancel_delayed_work(&skge->link_thread);
2534 2535
2535 skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_OFF); 2536 skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_OFF);
2536 if (hw->chip_id == CHIP_ID_GENESIS) 2537 if (hw->chip_id == CHIP_ID_GENESIS)
@@ -2766,6 +2767,17 @@ static int skge_change_mtu(struct net_device *dev, int new_mtu)
2766 return err; 2767 return err;
2767} 2768}
2768 2769
2770static const u8 pause_mc_addr[ETH_ALEN] = { 0x1, 0x80, 0xc2, 0x0, 0x0, 0x1 };
2771
2772static void genesis_add_filter(u8 filter[8], const u8 *addr)
2773{
2774 u32 crc, bit;
2775
2776 crc = ether_crc_le(ETH_ALEN, addr);
2777 bit = ~crc & 0x3f;
2778 filter[bit/8] |= 1 << (bit%8);
2779}
2780
2769static void genesis_set_multicast(struct net_device *dev) 2781static void genesis_set_multicast(struct net_device *dev)
2770{ 2782{
2771 struct skge_port *skge = netdev_priv(dev); 2783 struct skge_port *skge = netdev_priv(dev);
@@ -2787,24 +2799,33 @@ static void genesis_set_multicast(struct net_device *dev)
2787 memset(filter, 0xff, sizeof(filter)); 2799 memset(filter, 0xff, sizeof(filter));
2788 else { 2800 else {
2789 memset(filter, 0, sizeof(filter)); 2801 memset(filter, 0, sizeof(filter));
2790 for (i = 0; list && i < count; i++, list = list->next) { 2802
2791 u32 crc, bit; 2803 if (skge->flow_status == FLOW_STAT_REM_SEND
2792 crc = ether_crc_le(ETH_ALEN, list->dmi_addr); 2804 || skge->flow_status == FLOW_STAT_SYMMETRIC)
2793 bit = ~crc & 0x3f; 2805 genesis_add_filter(filter, pause_mc_addr);
2794 filter[bit/8] |= 1 << (bit%8); 2806
2795 } 2807 for (i = 0; list && i < count; i++, list = list->next)
2808 genesis_add_filter(filter, list->dmi_addr);
2796 } 2809 }
2797 2810
2798 xm_write32(hw, port, XM_MODE, mode); 2811 xm_write32(hw, port, XM_MODE, mode);
2799 xm_outhash(hw, port, XM_HSM, filter); 2812 xm_outhash(hw, port, XM_HSM, filter);
2800} 2813}
2801 2814
2815static void yukon_add_filter(u8 filter[8], const u8 *addr)
2816{
2817 u32 bit = ether_crc(ETH_ALEN, addr) & 0x3f;
2818 filter[bit/8] |= 1 << (bit%8);
2819}
2820
2802static void yukon_set_multicast(struct net_device *dev) 2821static void yukon_set_multicast(struct net_device *dev)
2803{ 2822{
2804 struct skge_port *skge = netdev_priv(dev); 2823 struct skge_port *skge = netdev_priv(dev);
2805 struct skge_hw *hw = skge->hw; 2824 struct skge_hw *hw = skge->hw;
2806 int port = skge->port; 2825 int port = skge->port;
2807 struct dev_mc_list *list = dev->mc_list; 2826 struct dev_mc_list *list = dev->mc_list;
2827 int rx_pause = (skge->flow_status == FLOW_STAT_REM_SEND
2828 || skge->flow_status == FLOW_STAT_SYMMETRIC);
2808 u16 reg; 2829 u16 reg;
2809 u8 filter[8]; 2830 u8 filter[8];
2810 2831
@@ -2817,16 +2838,17 @@ static void yukon_set_multicast(struct net_device *dev)
2817 reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA); 2838 reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
2818 else if (dev->flags & IFF_ALLMULTI) /* all multicast */ 2839 else if (dev->flags & IFF_ALLMULTI) /* all multicast */
2819 memset(filter, 0xff, sizeof(filter)); 2840 memset(filter, 0xff, sizeof(filter));
2820 else if (dev->mc_count == 0) /* no multicast */ 2841 else if (dev->mc_count == 0 && !rx_pause)/* no multicast */
2821 reg &= ~GM_RXCR_MCF_ENA; 2842 reg &= ~GM_RXCR_MCF_ENA;
2822 else { 2843 else {
2823 int i; 2844 int i;
2824 reg |= GM_RXCR_MCF_ENA; 2845 reg |= GM_RXCR_MCF_ENA;
2825 2846
2826 for (i = 0; list && i < dev->mc_count; i++, list = list->next) { 2847 if (rx_pause)
2827 u32 bit = ether_crc(ETH_ALEN, list->dmi_addr) & 0x3f; 2848 yukon_add_filter(filter, pause_mc_addr);
2828 filter[bit/8] |= 1 << (bit%8); 2849
2829 } 2850 for (i = 0; list && i < dev->mc_count; i++, list = list->next)
2851 yukon_add_filter(filter, list->dmi_addr);
2830 } 2852 }
2831 2853
2832 2854
@@ -3690,6 +3712,8 @@ static void __devexit skge_remove(struct pci_dev *pdev)
3690 if (!hw) 3712 if (!hw)
3691 return; 3713 return;
3692 3714
3715 flush_scheduled_work();
3716
3693 if ((dev1 = hw->dev[1])) 3717 if ((dev1 = hw->dev[1]))
3694 unregister_netdev(dev1); 3718 unregister_netdev(dev1);
3695 dev0 = hw->dev[0]; 3719 dev0 = hw->dev[0];
@@ -3704,8 +3728,6 @@ static void __devexit skge_remove(struct pci_dev *pdev)
3704 skge_write16(hw, B0_LED, LED_STAT_OFF); 3728 skge_write16(hw, B0_LED, LED_STAT_OFF);
3705 skge_write8(hw, B0_CTST, CS_RST_SET); 3729 skge_write8(hw, B0_CTST, CS_RST_SET);
3706 3730
3707 flush_scheduled_work();
3708
3709 free_irq(pdev->irq, hw); 3731 free_irq(pdev->irq, hw);
3710 pci_release_regions(pdev); 3732 pci_release_regions(pdev);
3711 pci_disable_device(pdev); 3733 pci_disable_device(pdev);
diff --git a/drivers/net/skge.h b/drivers/net/skge.h
index 17b1b479df..e9354dfa7e 100644
--- a/drivers/net/skge.h
+++ b/drivers/net/skge.h
@@ -1849,8 +1849,7 @@ enum {
1849 GMR_FS_JABBER, 1849 GMR_FS_JABBER,
1850/* Rx GMAC FIFO Flush Mask (default) */ 1850/* Rx GMAC FIFO Flush Mask (default) */
1851 RX_FF_FL_DEF_MSK = GMR_FS_CRC_ERR | GMR_FS_RX_FF_OV |GMR_FS_MII_ERR | 1851 RX_FF_FL_DEF_MSK = GMR_FS_CRC_ERR | GMR_FS_RX_FF_OV |GMR_FS_MII_ERR |
1852 GMR_FS_BAD_FC | GMR_FS_GOOD_FC | GMR_FS_UN_SIZE | 1852 GMR_FS_BAD_FC | GMR_FS_UN_SIZE | GMR_FS_JABBER,
1853 GMR_FS_JABBER,
1854}; 1853};
1855 1854
1856/* RX_GMF_CTRL_T 32 bit Rx GMAC FIFO Control/Test */ 1855/* RX_GMF_CTRL_T 32 bit Rx GMAC FIFO Control/Test */
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index f2ab3d56e5..ab0ab92583 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -49,7 +49,7 @@
49#include "sky2.h" 49#include "sky2.h"
50 50
51#define DRV_NAME "sky2" 51#define DRV_NAME "sky2"
52#define DRV_VERSION "1.12" 52#define DRV_VERSION "1.13"
53#define PFX DRV_NAME " " 53#define PFX DRV_NAME " "
54 54
55/* 55/*
@@ -1053,8 +1053,7 @@ static void sky2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1053 1053
1054 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), RX_VLAN_STRIP_OFF); 1054 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), RX_VLAN_STRIP_OFF);
1055 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_VLAN_TAG_OFF); 1055 sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_VLAN_TAG_OFF);
1056 if (sky2->vlgrp) 1056 vlan_group_set_device(sky2->vlgrp, vid, NULL);
1057 sky2->vlgrp->vlan_devices[vid] = NULL;
1058 1057
1059 netif_tx_unlock_bh(dev); 1058 netif_tx_unlock_bh(dev);
1060} 1059}
@@ -1742,13 +1741,6 @@ static void sky2_link_down(struct sky2_port *sky2)
1742 reg &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA); 1741 reg &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA);
1743 gma_write16(hw, port, GM_GP_CTRL, reg); 1742 gma_write16(hw, port, GM_GP_CTRL, reg);
1744 1743
1745 if (sky2->flow_status == FC_RX) {
1746 /* restore Asymmetric Pause bit */
1747 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV,
1748 gm_phy_read(hw, port, PHY_MARV_AUNE_ADV)
1749 | PHY_M_AN_ASP);
1750 }
1751
1752 netif_carrier_off(sky2->netdev); 1744 netif_carrier_off(sky2->netdev);
1753 netif_stop_queue(sky2->netdev); 1745 netif_stop_queue(sky2->netdev);
1754 1746
@@ -1773,10 +1765,10 @@ static int sky2_autoneg_done(struct sky2_port *sky2, u16 aux)
1773{ 1765{
1774 struct sky2_hw *hw = sky2->hw; 1766 struct sky2_hw *hw = sky2->hw;
1775 unsigned port = sky2->port; 1767 unsigned port = sky2->port;
1776 u16 lpa; 1768 u16 advert, lpa;
1777 1769
1770 advert = gm_phy_read(hw, port, PHY_MARV_AUNE_ADV);
1778 lpa = gm_phy_read(hw, port, PHY_MARV_AUNE_LP); 1771 lpa = gm_phy_read(hw, port, PHY_MARV_AUNE_LP);
1779
1780 if (lpa & PHY_M_AN_RF) { 1772 if (lpa & PHY_M_AN_RF) {
1781 printk(KERN_ERR PFX "%s: remote fault", sky2->netdev->name); 1773 printk(KERN_ERR PFX "%s: remote fault", sky2->netdev->name);
1782 return -1; 1774 return -1;
@@ -1791,20 +1783,40 @@ static int sky2_autoneg_done(struct sky2_port *sky2, u16 aux)
1791 sky2->speed = sky2_phy_speed(hw, aux); 1783 sky2->speed = sky2_phy_speed(hw, aux);
1792 sky2->duplex = (aux & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF; 1784 sky2->duplex = (aux & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
1793 1785
1794 /* Pause bits are offset (9..8) */ 1786 /* Since the pause result bits seem to in different positions on
1795 if (hw->chip_id == CHIP_ID_YUKON_XL 1787 * different chips. look at registers.
1796 || hw->chip_id == CHIP_ID_YUKON_EC_U 1788 */
1797 || hw->chip_id == CHIP_ID_YUKON_EX) 1789 if (!sky2_is_copper(hw)) {
1798 aux >>= 6; 1790 /* Shift for bits in fiber PHY */
1799 1791 advert &= ~(ADVERTISE_PAUSE_CAP|ADVERTISE_PAUSE_ASYM);
1800 sky2->flow_status = sky2_flow(aux & PHY_M_PS_RX_P_EN, 1792 lpa &= ~(LPA_PAUSE_CAP|LPA_PAUSE_ASYM);
1801 aux & PHY_M_PS_TX_P_EN); 1793
1794 if (advert & ADVERTISE_1000XPAUSE)
1795 advert |= ADVERTISE_PAUSE_CAP;
1796 if (advert & ADVERTISE_1000XPSE_ASYM)
1797 advert |= ADVERTISE_PAUSE_ASYM;
1798 if (lpa & LPA_1000XPAUSE)
1799 lpa |= LPA_PAUSE_CAP;
1800 if (lpa & LPA_1000XPAUSE_ASYM)
1801 lpa |= LPA_PAUSE_ASYM;
1802 }
1803
1804 sky2->flow_status = FC_NONE;
1805 if (advert & ADVERTISE_PAUSE_CAP) {
1806 if (lpa & LPA_PAUSE_CAP)
1807 sky2->flow_status = FC_BOTH;
1808 else if (advert & ADVERTISE_PAUSE_ASYM)
1809 sky2->flow_status = FC_RX;
1810 } else if (advert & ADVERTISE_PAUSE_ASYM) {
1811 if ((lpa & LPA_PAUSE_CAP) && (lpa & LPA_PAUSE_ASYM))
1812 sky2->flow_status = FC_TX;
1813 }
1802 1814
1803 if (sky2->duplex == DUPLEX_HALF && sky2->speed < SPEED_1000 1815 if (sky2->duplex == DUPLEX_HALF && sky2->speed < SPEED_1000
1804 && !(hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX)) 1816 && !(hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX))
1805 sky2->flow_status = FC_NONE; 1817 sky2->flow_status = FC_NONE;
1806 1818
1807 if (aux & PHY_M_PS_RX_P_EN) 1819 if (sky2->flow_status & FC_TX)
1808 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON); 1820 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON);
1809 else 1821 else
1810 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); 1822 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
@@ -1853,16 +1865,13 @@ out:
1853 spin_unlock(&sky2->phy_lock); 1865 spin_unlock(&sky2->phy_lock);
1854} 1866}
1855 1867
1856
1857/* Transmit timeout is only called if we are running, carrier is up 1868/* Transmit timeout is only called if we are running, carrier is up
1858 * and tx queue is full (stopped). 1869 * and tx queue is full (stopped).
1859 * Called with netif_tx_lock held.
1860 */ 1870 */
1861static void sky2_tx_timeout(struct net_device *dev) 1871static void sky2_tx_timeout(struct net_device *dev)
1862{ 1872{
1863 struct sky2_port *sky2 = netdev_priv(dev); 1873 struct sky2_port *sky2 = netdev_priv(dev);
1864 struct sky2_hw *hw = sky2->hw; 1874 struct sky2_hw *hw = sky2->hw;
1865 u32 imask;
1866 1875
1867 if (netif_msg_timer(sky2)) 1876 if (netif_msg_timer(sky2))
1868 printk(KERN_ERR PFX "%s: tx timeout\n", dev->name); 1877 printk(KERN_ERR PFX "%s: tx timeout\n", dev->name);
@@ -1872,19 +1881,8 @@ static void sky2_tx_timeout(struct net_device *dev)
1872 sky2_read16(hw, sky2->port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX), 1881 sky2_read16(hw, sky2->port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX),
1873 sky2_read16(hw, Q_ADDR(txqaddr[sky2->port], Q_DONE))); 1882 sky2_read16(hw, Q_ADDR(txqaddr[sky2->port], Q_DONE)));
1874 1883
1875 imask = sky2_read32(hw, B0_IMSK); /* block IRQ in hw */ 1884 /* can't restart safely under softirq */
1876 sky2_write32(hw, B0_IMSK, 0); 1885 schedule_work(&hw->restart_work);
1877 sky2_read32(hw, B0_IMSK);
1878
1879 netif_poll_disable(hw->dev[0]); /* stop NAPI poll */
1880 synchronize_irq(hw->pdev->irq);
1881
1882 netif_start_queue(dev); /* don't wakeup during flush */
1883 sky2_tx_complete(sky2, sky2->tx_prod); /* Flush transmit queue */
1884
1885 sky2_write32(hw, B0_IMSK, imask);
1886
1887 sky2_phy_reinit(sky2); /* this clears flow control etc */
1888} 1886}
1889 1887
1890static int sky2_change_mtu(struct net_device *dev, int new_mtu) 1888static int sky2_change_mtu(struct net_device *dev, int new_mtu)
@@ -2057,9 +2055,6 @@ static struct sk_buff *sky2_receive(struct net_device *dev,
2057 if (!(status & GMR_FS_RX_OK)) 2055 if (!(status & GMR_FS_RX_OK))
2058 goto resubmit; 2056 goto resubmit;
2059 2057
2060 if (length > dev->mtu + ETH_HLEN)
2061 goto oversize;
2062
2063 if (length < copybreak) 2058 if (length < copybreak)
2064 skb = receive_copy(sky2, re, length); 2059 skb = receive_copy(sky2, re, length);
2065 else 2060 else
@@ -2069,14 +2064,10 @@ resubmit:
2069 2064
2070 return skb; 2065 return skb;
2071 2066
2072oversize:
2073 ++sky2->net_stats.rx_over_errors;
2074 goto resubmit;
2075
2076error: 2067error:
2077 ++sky2->net_stats.rx_errors; 2068 ++sky2->net_stats.rx_errors;
2078 if (status & GMR_FS_RX_FF_OV) { 2069 if (status & GMR_FS_RX_FF_OV) {
2079 sky2->net_stats.rx_fifo_errors++; 2070 sky2->net_stats.rx_over_errors++;
2080 goto resubmit; 2071 goto resubmit;
2081 } 2072 }
2082 2073
@@ -2174,9 +2165,27 @@ force_update:
2174 /* fall through */ 2165 /* fall through */
2175#endif 2166#endif
2176 case OP_RXCHKS: 2167 case OP_RXCHKS:
2177 skb = sky2->rx_ring[sky2->rx_next].skb; 2168 if (!sky2->rx_csum)
2178 skb->ip_summed = CHECKSUM_COMPLETE; 2169 break;
2179 skb->csum = status & 0xffff; 2170
2171 /* Both checksum counters are programmed to start at
2172 * the same offset, so unless there is a problem they
2173 * should match. This failure is an early indication that
2174 * hardware receive checksumming won't work.
2175 */
2176 if (likely(status >> 16 == (status & 0xffff))) {
2177 skb = sky2->rx_ring[sky2->rx_next].skb;
2178 skb->ip_summed = CHECKSUM_COMPLETE;
2179 skb->csum = status & 0xffff;
2180 } else {
2181 printk(KERN_NOTICE PFX "%s: hardware receive "
2182 "checksum problem (status = %#x)\n",
2183 dev->name, status);
2184 sky2->rx_csum = 0;
2185 sky2_write32(sky2->hw,
2186 Q_ADDR(rxqaddr[le->link], Q_CSR),
2187 BMU_DIS_RX_CHKSUM);
2188 }
2180 break; 2189 break;
2181 2190
2182 case OP_TXINDEXLE: 2191 case OP_TXINDEXLE:
@@ -2638,6 +2647,49 @@ static void sky2_reset(struct sky2_hw *hw)
2638 sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START); 2647 sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START);
2639} 2648}
2640 2649
2650static void sky2_restart(struct work_struct *work)
2651{
2652 struct sky2_hw *hw = container_of(work, struct sky2_hw, restart_work);
2653 struct net_device *dev;
2654 int i, err;
2655
2656 dev_dbg(&hw->pdev->dev, "restarting\n");
2657
2658 del_timer_sync(&hw->idle_timer);
2659
2660 rtnl_lock();
2661 sky2_write32(hw, B0_IMSK, 0);
2662 sky2_read32(hw, B0_IMSK);
2663
2664 netif_poll_disable(hw->dev[0]);
2665
2666 for (i = 0; i < hw->ports; i++) {
2667 dev = hw->dev[i];
2668 if (netif_running(dev))
2669 sky2_down(dev);
2670 }
2671
2672 sky2_reset(hw);
2673 sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
2674 netif_poll_enable(hw->dev[0]);
2675
2676 for (i = 0; i < hw->ports; i++) {
2677 dev = hw->dev[i];
2678 if (netif_running(dev)) {
2679 err = sky2_up(dev);
2680 if (err) {
2681 printk(KERN_INFO PFX "%s: could not restart %d\n",
2682 dev->name, err);
2683 dev_close(dev);
2684 }
2685 }
2686 }
2687
2688 sky2_idle_start(hw);
2689
2690 rtnl_unlock();
2691}
2692
2641static inline u8 sky2_wol_supported(const struct sky2_hw *hw) 2693static inline u8 sky2_wol_supported(const struct sky2_hw *hw)
2642{ 2694{
2643 return sky2_is_copper(hw) ? (WAKE_PHY | WAKE_MAGIC) : 0; 2695 return sky2_is_copper(hw) ? (WAKE_PHY | WAKE_MAGIC) : 0;
@@ -3600,6 +3652,8 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
3600 } 3652 }
3601 3653
3602 setup_timer(&hw->idle_timer, sky2_idle, (unsigned long) hw); 3654 setup_timer(&hw->idle_timer, sky2_idle, (unsigned long) hw);
3655 INIT_WORK(&hw->restart_work, sky2_restart);
3656
3603 sky2_idle_start(hw); 3657 sky2_idle_start(hw);
3604 3658
3605 pci_set_drvdata(pdev, hw); 3659 pci_set_drvdata(pdev, hw);
@@ -3636,6 +3690,8 @@ static void __devexit sky2_remove(struct pci_dev *pdev)
3636 3690
3637 del_timer_sync(&hw->idle_timer); 3691 del_timer_sync(&hw->idle_timer);
3638 3692
3693 flush_scheduled_work();
3694
3639 sky2_write32(hw, B0_IMSK, 0); 3695 sky2_write32(hw, B0_IMSK, 0);
3640 synchronize_irq(hw->pdev->irq); 3696 synchronize_irq(hw->pdev->irq);
3641 3697
diff --git a/drivers/net/sky2.h b/drivers/net/sky2.h
index 3b0189569d..ac24bdc429 100644
--- a/drivers/net/sky2.h
+++ b/drivers/net/sky2.h
@@ -1589,7 +1589,7 @@ enum {
1589 1589
1590 GMR_FS_ANY_ERR = GMR_FS_RX_FF_OV | GMR_FS_CRC_ERR | 1590 GMR_FS_ANY_ERR = GMR_FS_RX_FF_OV | GMR_FS_CRC_ERR |
1591 GMR_FS_FRAGMENT | GMR_FS_LONG_ERR | 1591 GMR_FS_FRAGMENT | GMR_FS_LONG_ERR |
1592 GMR_FS_MII_ERR | GMR_FS_GOOD_FC | GMR_FS_BAD_FC | 1592 GMR_FS_MII_ERR | GMR_FS_BAD_FC |
1593 GMR_FS_UN_SIZE | GMR_FS_JABBER, 1593 GMR_FS_UN_SIZE | GMR_FS_JABBER,
1594}; 1594};
1595 1595
@@ -1933,6 +1933,7 @@ struct sky2_hw {
1933 dma_addr_t st_dma; 1933 dma_addr_t st_dma;
1934 1934
1935 struct timer_list idle_timer; 1935 struct timer_list idle_timer;
1936 struct work_struct restart_work;
1936 int msi; 1937 int msi;
1937 wait_queue_head_t msi_wait; 1938 wait_queue_head_t msi_wait;
1938}; 1939};
diff --git a/drivers/net/spider_net.c b/drivers/net/spider_net.c
index 64ed8ff5b0..3b91af89e4 100644
--- a/drivers/net/spider_net.c
+++ b/drivers/net/spider_net.c
@@ -1,7 +1,8 @@
1/* 1/*
2 * Network device driver for Cell Processor-Based Blade 2 * Network device driver for Cell Processor-Based Blade and Celleb platform
3 * 3 *
4 * (C) Copyright IBM Corp. 2005 4 * (C) Copyright IBM Corp. 2005
5 * (C) Copyright 2006 TOSHIBA CORPORATION
5 * 6 *
6 * Authors : Utz Bacher <utz.bacher@de.ibm.com> 7 * Authors : Utz Bacher <utz.bacher@de.ibm.com>
7 * Jens Osterkamp <Jens.Osterkamp@de.ibm.com> 8 * Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
@@ -166,6 +167,41 @@ spider_net_read_phy(struct net_device *netdev, int mii_id, int reg)
166} 167}
167 168
168/** 169/**
170 * spider_net_setup_aneg - initial auto-negotiation setup
171 * @card: device structure
172 **/
173static void
174spider_net_setup_aneg(struct spider_net_card *card)
175{
176 struct mii_phy *phy = &card->phy;
177 u32 advertise = 0;
178 u16 bmcr, bmsr, stat1000, estat;
179
180 bmcr = spider_net_read_phy(card->netdev, phy->mii_id, MII_BMCR);
181 bmsr = spider_net_read_phy(card->netdev, phy->mii_id, MII_BMSR);
182 stat1000 = spider_net_read_phy(card->netdev, phy->mii_id, MII_STAT1000);
183 estat = spider_net_read_phy(card->netdev, phy->mii_id, MII_ESTATUS);
184
185 if (bmsr & BMSR_10HALF)
186 advertise |= ADVERTISED_10baseT_Half;
187 if (bmsr & BMSR_10FULL)
188 advertise |= ADVERTISED_10baseT_Full;
189 if (bmsr & BMSR_100HALF)
190 advertise |= ADVERTISED_100baseT_Half;
191 if (bmsr & BMSR_100FULL)
192 advertise |= ADVERTISED_100baseT_Full;
193
194 if ((bmsr & BMSR_ESTATEN) && (estat & ESTATUS_1000_TFULL))
195 advertise |= SUPPORTED_1000baseT_Full;
196 if ((bmsr & BMSR_ESTATEN) && (estat & ESTATUS_1000_THALF))
197 advertise |= SUPPORTED_1000baseT_Half;
198
199 mii_phy_probe(phy, phy->mii_id);
200 phy->def->ops->setup_aneg(phy, advertise);
201
202}
203
204/**
169 * spider_net_rx_irq_off - switch off rx irq on this spider card 205 * spider_net_rx_irq_off - switch off rx irq on this spider card
170 * @card: device structure 206 * @card: device structure
171 * 207 *
@@ -263,9 +299,9 @@ spider_net_get_mac_address(struct net_device *netdev)
263 * returns the status as in the dmac_cmd_status field of the descriptor 299 * returns the status as in the dmac_cmd_status field of the descriptor
264 */ 300 */
265static inline int 301static inline int
266spider_net_get_descr_status(struct spider_net_descr *descr) 302spider_net_get_descr_status(struct spider_net_hw_descr *hwdescr)
267{ 303{
268 return descr->dmac_cmd_status & SPIDER_NET_DESCR_IND_PROC_MASK; 304 return hwdescr->dmac_cmd_status & SPIDER_NET_DESCR_IND_PROC_MASK;
269} 305}
270 306
271/** 307/**
@@ -283,12 +319,12 @@ spider_net_free_chain(struct spider_net_card *card,
283 descr = chain->ring; 319 descr = chain->ring;
284 do { 320 do {
285 descr->bus_addr = 0; 321 descr->bus_addr = 0;
286 descr->next_descr_addr = 0; 322 descr->hwdescr->next_descr_addr = 0;
287 descr = descr->next; 323 descr = descr->next;
288 } while (descr != chain->ring); 324 } while (descr != chain->ring);
289 325
290 dma_free_coherent(&card->pdev->dev, chain->num_desc, 326 dma_free_coherent(&card->pdev->dev, chain->num_desc,
291 chain->ring, chain->dma_addr); 327 chain->hwring, chain->dma_addr);
292} 328}
293 329
294/** 330/**
@@ -307,31 +343,34 @@ spider_net_init_chain(struct spider_net_card *card,
307{ 343{
308 int i; 344 int i;
309 struct spider_net_descr *descr; 345 struct spider_net_descr *descr;
346 struct spider_net_hw_descr *hwdescr;
310 dma_addr_t buf; 347 dma_addr_t buf;
311 size_t alloc_size; 348 size_t alloc_size;
312 349
313 alloc_size = chain->num_desc * sizeof (struct spider_net_descr); 350 alloc_size = chain->num_desc * sizeof(struct spider_net_hw_descr);
314 351
315 chain->ring = dma_alloc_coherent(&card->pdev->dev, alloc_size, 352 chain->hwring = dma_alloc_coherent(&card->pdev->dev, alloc_size,
316 &chain->dma_addr, GFP_KERNEL); 353 &chain->dma_addr, GFP_KERNEL);
317 354
318 if (!chain->ring) 355 if (!chain->hwring)
319 return -ENOMEM; 356 return -ENOMEM;
320 357
321 descr = chain->ring; 358 memset(chain->ring, 0, chain->num_desc * sizeof(struct spider_net_descr));
322 memset(descr, 0, alloc_size);
323 359
324 /* Set up the hardware pointers in each descriptor */ 360 /* Set up the hardware pointers in each descriptor */
361 descr = chain->ring;
362 hwdescr = chain->hwring;
325 buf = chain->dma_addr; 363 buf = chain->dma_addr;
326 for (i=0; i < chain->num_desc; i++, descr++) { 364 for (i=0; i < chain->num_desc; i++, descr++, hwdescr++) {
327 descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE; 365 hwdescr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
366 hwdescr->next_descr_addr = 0;
328 367
368 descr->hwdescr = hwdescr;
329 descr->bus_addr = buf; 369 descr->bus_addr = buf;
330 descr->next_descr_addr = 0;
331 descr->next = descr + 1; 370 descr->next = descr + 1;
332 descr->prev = descr - 1; 371 descr->prev = descr - 1;
333 372
334 buf += sizeof(struct spider_net_descr); 373 buf += sizeof(struct spider_net_hw_descr);
335 } 374 }
336 /* do actual circular list */ 375 /* do actual circular list */
337 (descr-1)->next = chain->ring; 376 (descr-1)->next = chain->ring;
@@ -357,10 +396,11 @@ spider_net_free_rx_chain_contents(struct spider_net_card *card)
357 descr = card->rx_chain.head; 396 descr = card->rx_chain.head;
358 do { 397 do {
359 if (descr->skb) { 398 if (descr->skb) {
360 dev_kfree_skb(descr->skb); 399 pci_unmap_single(card->pdev, descr->hwdescr->buf_addr,
361 pci_unmap_single(card->pdev, descr->buf_addr,
362 SPIDER_NET_MAX_FRAME, 400 SPIDER_NET_MAX_FRAME,
363 PCI_DMA_BIDIRECTIONAL); 401 PCI_DMA_BIDIRECTIONAL);
402 dev_kfree_skb(descr->skb);
403 descr->skb = NULL;
364 } 404 }
365 descr = descr->next; 405 descr = descr->next;
366 } while (descr != card->rx_chain.head); 406 } while (descr != card->rx_chain.head);
@@ -380,6 +420,7 @@ static int
380spider_net_prepare_rx_descr(struct spider_net_card *card, 420spider_net_prepare_rx_descr(struct spider_net_card *card,
381 struct spider_net_descr *descr) 421 struct spider_net_descr *descr)
382{ 422{
423 struct spider_net_hw_descr *hwdescr = descr->hwdescr;
383 dma_addr_t buf; 424 dma_addr_t buf;
384 int offset; 425 int offset;
385 int bufsize; 426 int bufsize;
@@ -398,11 +439,11 @@ spider_net_prepare_rx_descr(struct spider_net_card *card,
398 card->spider_stats.alloc_rx_skb_error++; 439 card->spider_stats.alloc_rx_skb_error++;
399 return -ENOMEM; 440 return -ENOMEM;
400 } 441 }
401 descr->buf_size = bufsize; 442 hwdescr->buf_size = bufsize;
402 descr->result_size = 0; 443 hwdescr->result_size = 0;
403 descr->valid_size = 0; 444 hwdescr->valid_size = 0;
404 descr->data_status = 0; 445 hwdescr->data_status = 0;
405 descr->data_error = 0; 446 hwdescr->data_error = 0;
406 447
407 offset = ((unsigned long)descr->skb->data) & 448 offset = ((unsigned long)descr->skb->data) &
408 (SPIDER_NET_RXBUF_ALIGN - 1); 449 (SPIDER_NET_RXBUF_ALIGN - 1);
@@ -411,21 +452,22 @@ spider_net_prepare_rx_descr(struct spider_net_card *card,
411 /* iommu-map the skb */ 452 /* iommu-map the skb */
412 buf = pci_map_single(card->pdev, descr->skb->data, 453 buf = pci_map_single(card->pdev, descr->skb->data,
413 SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE); 454 SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE);
414 descr->buf_addr = buf;
415 if (pci_dma_mapping_error(buf)) { 455 if (pci_dma_mapping_error(buf)) {
416 dev_kfree_skb_any(descr->skb); 456 dev_kfree_skb_any(descr->skb);
457 descr->skb = NULL;
417 if (netif_msg_rx_err(card) && net_ratelimit()) 458 if (netif_msg_rx_err(card) && net_ratelimit())
418 pr_err("Could not iommu-map rx buffer\n"); 459 pr_err("Could not iommu-map rx buffer\n");
419 card->spider_stats.rx_iommu_map_error++; 460 card->spider_stats.rx_iommu_map_error++;
420 descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE; 461 hwdescr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
421 } else { 462 } else {
422 descr->next_descr_addr = 0; 463 hwdescr->buf_addr = buf;
464 hwdescr->next_descr_addr = 0;
423 wmb(); 465 wmb();
424 descr->dmac_cmd_status = SPIDER_NET_DESCR_CARDOWNED | 466 hwdescr->dmac_cmd_status = SPIDER_NET_DESCR_CARDOWNED |
425 SPIDER_NET_DMAC_NOINTR_COMPLETE; 467 SPIDER_NET_DMAC_NOINTR_COMPLETE;
426 468
427 wmb(); 469 wmb();
428 descr->prev->next_descr_addr = descr->bus_addr; 470 descr->prev->hwdescr->next_descr_addr = descr->bus_addr;
429 } 471 }
430 472
431 return 0; 473 return 0;
@@ -481,7 +523,7 @@ spider_net_refill_rx_chain(struct spider_net_card *card)
481 if (!spin_trylock_irqsave(&chain->lock, flags)) 523 if (!spin_trylock_irqsave(&chain->lock, flags))
482 return; 524 return;
483 525
484 while (spider_net_get_descr_status(chain->head) == 526 while (spider_net_get_descr_status(chain->head->hwdescr) ==
485 SPIDER_NET_DESCR_NOT_IN_USE) { 527 SPIDER_NET_DESCR_NOT_IN_USE) {
486 if (spider_net_prepare_rx_descr(card, chain->head)) 528 if (spider_net_prepare_rx_descr(card, chain->head))
487 break; 529 break;
@@ -642,7 +684,9 @@ static int
642spider_net_prepare_tx_descr(struct spider_net_card *card, 684spider_net_prepare_tx_descr(struct spider_net_card *card,
643 struct sk_buff *skb) 685 struct sk_buff *skb)
644{ 686{
687 struct spider_net_descr_chain *chain = &card->tx_chain;
645 struct spider_net_descr *descr; 688 struct spider_net_descr *descr;
689 struct spider_net_hw_descr *hwdescr;
646 dma_addr_t buf; 690 dma_addr_t buf;
647 unsigned long flags; 691 unsigned long flags;
648 692
@@ -655,32 +699,39 @@ spider_net_prepare_tx_descr(struct spider_net_card *card,
655 return -ENOMEM; 699 return -ENOMEM;
656 } 700 }
657 701
658 spin_lock_irqsave(&card->tx_chain.lock, flags); 702 spin_lock_irqsave(&chain->lock, flags);
659 descr = card->tx_chain.head; 703 descr = card->tx_chain.head;
660 card->tx_chain.head = descr->next; 704 if (descr->next == chain->tail->prev) {
705 spin_unlock_irqrestore(&chain->lock, flags);
706 pci_unmap_single(card->pdev, buf, skb->len, PCI_DMA_TODEVICE);
707 return -ENOMEM;
708 }
709 hwdescr = descr->hwdescr;
710 chain->head = descr->next;
661 711
662 descr->buf_addr = buf;
663 descr->buf_size = skb->len;
664 descr->next_descr_addr = 0;
665 descr->skb = skb; 712 descr->skb = skb;
666 descr->data_status = 0; 713 hwdescr->buf_addr = buf;
714 hwdescr->buf_size = skb->len;
715 hwdescr->next_descr_addr = 0;
716 hwdescr->data_status = 0;
667 717
668 descr->dmac_cmd_status = 718 hwdescr->dmac_cmd_status =
669 SPIDER_NET_DESCR_CARDOWNED | SPIDER_NET_DMAC_NOCS; 719 SPIDER_NET_DESCR_CARDOWNED | SPIDER_NET_DMAC_NOCS;
670 spin_unlock_irqrestore(&card->tx_chain.lock, flags); 720 spin_unlock_irqrestore(&chain->lock, flags);
671 721
672 if (skb->protocol == htons(ETH_P_IP)) 722 if (skb->protocol == htons(ETH_P_IP))
673 switch (skb->nh.iph->protocol) { 723 switch (skb->nh.iph->protocol) {
674 case IPPROTO_TCP: 724 case IPPROTO_TCP:
675 descr->dmac_cmd_status |= SPIDER_NET_DMAC_TCP; 725 hwdescr->dmac_cmd_status |= SPIDER_NET_DMAC_TCP;
676 break; 726 break;
677 case IPPROTO_UDP: 727 case IPPROTO_UDP:
678 descr->dmac_cmd_status |= SPIDER_NET_DMAC_UDP; 728 hwdescr->dmac_cmd_status |= SPIDER_NET_DMAC_UDP;
679 break; 729 break;
680 } 730 }
681 731
682 /* Chain the bus address, so that the DMA engine finds this descr. */ 732 /* Chain the bus address, so that the DMA engine finds this descr. */
683 descr->prev->next_descr_addr = descr->bus_addr; 733 wmb();
734 descr->prev->hwdescr->next_descr_addr = descr->bus_addr;
684 735
685 card->netdev->trans_start = jiffies; /* set netdev watchdog timer */ 736 card->netdev->trans_start = jiffies; /* set netdev watchdog timer */
686 return 0; 737 return 0;
@@ -689,16 +740,17 @@ spider_net_prepare_tx_descr(struct spider_net_card *card,
689static int 740static int
690spider_net_set_low_watermark(struct spider_net_card *card) 741spider_net_set_low_watermark(struct spider_net_card *card)
691{ 742{
743 struct spider_net_descr *descr = card->tx_chain.tail;
744 struct spider_net_hw_descr *hwdescr;
692 unsigned long flags; 745 unsigned long flags;
693 int status; 746 int status;
694 int cnt=0; 747 int cnt=0;
695 int i; 748 int i;
696 struct spider_net_descr *descr = card->tx_chain.tail;
697 749
698 /* Measure the length of the queue. Measurement does not 750 /* Measure the length of the queue. Measurement does not
699 * need to be precise -- does not need a lock. */ 751 * need to be precise -- does not need a lock. */
700 while (descr != card->tx_chain.head) { 752 while (descr != card->tx_chain.head) {
701 status = descr->dmac_cmd_status & SPIDER_NET_DESCR_NOT_IN_USE; 753 status = descr->hwdescr->dmac_cmd_status & SPIDER_NET_DESCR_NOT_IN_USE;
702 if (status == SPIDER_NET_DESCR_NOT_IN_USE) 754 if (status == SPIDER_NET_DESCR_NOT_IN_USE)
703 break; 755 break;
704 descr = descr->next; 756 descr = descr->next;
@@ -717,10 +769,12 @@ spider_net_set_low_watermark(struct spider_net_card *card)
717 769
718 /* Set the new watermark, clear the old watermark */ 770 /* Set the new watermark, clear the old watermark */
719 spin_lock_irqsave(&card->tx_chain.lock, flags); 771 spin_lock_irqsave(&card->tx_chain.lock, flags);
720 descr->dmac_cmd_status |= SPIDER_NET_DESCR_TXDESFLG; 772 descr->hwdescr->dmac_cmd_status |= SPIDER_NET_DESCR_TXDESFLG;
721 if (card->low_watermark && card->low_watermark != descr) 773 if (card->low_watermark && card->low_watermark != descr) {
722 card->low_watermark->dmac_cmd_status = 774 hwdescr = card->low_watermark->hwdescr;
723 card->low_watermark->dmac_cmd_status & ~SPIDER_NET_DESCR_TXDESFLG; 775 hwdescr->dmac_cmd_status =
776 hwdescr->dmac_cmd_status & ~SPIDER_NET_DESCR_TXDESFLG;
777 }
724 card->low_watermark = descr; 778 card->low_watermark = descr;
725 spin_unlock_irqrestore(&card->tx_chain.lock, flags); 779 spin_unlock_irqrestore(&card->tx_chain.lock, flags);
726 return cnt; 780 return cnt;
@@ -743,16 +797,22 @@ spider_net_release_tx_chain(struct spider_net_card *card, int brutal)
743{ 797{
744 struct spider_net_descr_chain *chain = &card->tx_chain; 798 struct spider_net_descr_chain *chain = &card->tx_chain;
745 struct spider_net_descr *descr; 799 struct spider_net_descr *descr;
800 struct spider_net_hw_descr *hwdescr;
746 struct sk_buff *skb; 801 struct sk_buff *skb;
747 u32 buf_addr; 802 u32 buf_addr;
748 unsigned long flags; 803 unsigned long flags;
749 int status; 804 int status;
750 805
751 while (chain->tail != chain->head) { 806 while (1) {
752 spin_lock_irqsave(&chain->lock, flags); 807 spin_lock_irqsave(&chain->lock, flags);
808 if (chain->tail == chain->head) {
809 spin_unlock_irqrestore(&chain->lock, flags);
810 return 0;
811 }
753 descr = chain->tail; 812 descr = chain->tail;
813 hwdescr = descr->hwdescr;
754 814
755 status = spider_net_get_descr_status(descr); 815 status = spider_net_get_descr_status(hwdescr);
756 switch (status) { 816 switch (status) {
757 case SPIDER_NET_DESCR_COMPLETE: 817 case SPIDER_NET_DESCR_COMPLETE:
758 card->netdev_stats.tx_packets++; 818 card->netdev_stats.tx_packets++;
@@ -788,9 +848,10 @@ spider_net_release_tx_chain(struct spider_net_card *card, int brutal)
788 } 848 }
789 849
790 chain->tail = descr->next; 850 chain->tail = descr->next;
791 descr->dmac_cmd_status |= SPIDER_NET_DESCR_NOT_IN_USE; 851 hwdescr->dmac_cmd_status |= SPIDER_NET_DESCR_NOT_IN_USE;
792 skb = descr->skb; 852 skb = descr->skb;
793 buf_addr = descr->buf_addr; 853 descr->skb = NULL;
854 buf_addr = hwdescr->buf_addr;
794 spin_unlock_irqrestore(&chain->lock, flags); 855 spin_unlock_irqrestore(&chain->lock, flags);
795 856
796 /* unmap the skb */ 857 /* unmap the skb */
@@ -826,7 +887,7 @@ spider_net_kick_tx_dma(struct spider_net_card *card)
826 887
827 descr = card->tx_chain.tail; 888 descr = card->tx_chain.tail;
828 for (;;) { 889 for (;;) {
829 if (spider_net_get_descr_status(descr) == 890 if (spider_net_get_descr_status(descr->hwdescr) ==
830 SPIDER_NET_DESCR_CARDOWNED) { 891 SPIDER_NET_DESCR_CARDOWNED) {
831 spider_net_write_reg(card, SPIDER_NET_GDTDCHA, 892 spider_net_write_reg(card, SPIDER_NET_GDTDCHA,
832 descr->bus_addr); 893 descr->bus_addr);
@@ -855,13 +916,10 @@ spider_net_xmit(struct sk_buff *skb, struct net_device *netdev)
855{ 916{
856 int cnt; 917 int cnt;
857 struct spider_net_card *card = netdev_priv(netdev); 918 struct spider_net_card *card = netdev_priv(netdev);
858 struct spider_net_descr_chain *chain = &card->tx_chain;
859 919
860 spider_net_release_tx_chain(card, 0); 920 spider_net_release_tx_chain(card, 0);
861 921
862 if ((chain->head->next == chain->tail->prev) || 922 if (spider_net_prepare_tx_descr(card, skb) != 0) {
863 (spider_net_prepare_tx_descr(card, skb) != 0)) {
864
865 card->netdev_stats.tx_dropped++; 923 card->netdev_stats.tx_dropped++;
866 netif_stop_queue(netdev); 924 netif_stop_queue(netdev);
867 return NETDEV_TX_BUSY; 925 return NETDEV_TX_BUSY;
@@ -922,17 +980,18 @@ static void
922spider_net_pass_skb_up(struct spider_net_descr *descr, 980spider_net_pass_skb_up(struct spider_net_descr *descr,
923 struct spider_net_card *card) 981 struct spider_net_card *card)
924{ 982{
983 struct spider_net_hw_descr *hwdescr= descr->hwdescr;
925 struct sk_buff *skb; 984 struct sk_buff *skb;
926 struct net_device *netdev; 985 struct net_device *netdev;
927 u32 data_status, data_error; 986 u32 data_status, data_error;
928 987
929 data_status = descr->data_status; 988 data_status = hwdescr->data_status;
930 data_error = descr->data_error; 989 data_error = hwdescr->data_error;
931 netdev = card->netdev; 990 netdev = card->netdev;
932 991
933 skb = descr->skb; 992 skb = descr->skb;
934 skb->dev = netdev; 993 skb->dev = netdev;
935 skb_put(skb, descr->valid_size); 994 skb_put(skb, hwdescr->valid_size);
936 995
937 /* the card seems to add 2 bytes of junk in front 996 /* the card seems to add 2 bytes of junk in front
938 * of the ethernet frame */ 997 * of the ethernet frame */
@@ -994,23 +1053,25 @@ static void show_rx_chain(struct spider_net_card *card)
994#endif 1053#endif
995 1054
996/** 1055/**
997 * spider_net_decode_one_descr - processes an rx descriptor 1056 * spider_net_decode_one_descr - processes an RX descriptor
998 * @card: card structure 1057 * @card: card structure
999 * 1058 *
1000 * Returns 1 if a packet has been sent to the stack, otherwise 0 1059 * Returns 1 if a packet has been sent to the stack, otherwise 0.
1001 * 1060 *
1002 * Processes an rx descriptor by iommu-unmapping the data buffer and passing 1061 * Processes an RX descriptor by iommu-unmapping the data buffer
1003 * the packet up to the stack. This function is called in softirq 1062 * and passing the packet up to the stack. This function is called
1004 * context, e.g. either bottom half from interrupt or NAPI polling context 1063 * in softirq context, e.g. either bottom half from interrupt or
1064 * NAPI polling context.
1005 */ 1065 */
1006static int 1066static int
1007spider_net_decode_one_descr(struct spider_net_card *card) 1067spider_net_decode_one_descr(struct spider_net_card *card)
1008{ 1068{
1009 struct spider_net_descr_chain *chain = &card->rx_chain; 1069 struct spider_net_descr_chain *chain = &card->rx_chain;
1010 struct spider_net_descr *descr = chain->tail; 1070 struct spider_net_descr *descr = chain->tail;
1071 struct spider_net_hw_descr *hwdescr = descr->hwdescr;
1011 int status; 1072 int status;
1012 1073
1013 status = spider_net_get_descr_status(descr); 1074 status = spider_net_get_descr_status(hwdescr);
1014 1075
1015 /* Nothing in the descriptor, or ring must be empty */ 1076 /* Nothing in the descriptor, or ring must be empty */
1016 if ((status == SPIDER_NET_DESCR_CARDOWNED) || 1077 if ((status == SPIDER_NET_DESCR_CARDOWNED) ||
@@ -1021,7 +1082,7 @@ spider_net_decode_one_descr(struct spider_net_card *card)
1021 chain->tail = descr->next; 1082 chain->tail = descr->next;
1022 1083
1023 /* unmap descriptor */ 1084 /* unmap descriptor */
1024 pci_unmap_single(card->pdev, descr->buf_addr, 1085 pci_unmap_single(card->pdev, hwdescr->buf_addr,
1025 SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE); 1086 SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE);
1026 1087
1027 if ( (status == SPIDER_NET_DESCR_RESPONSE_ERROR) || 1088 if ( (status == SPIDER_NET_DESCR_RESPONSE_ERROR) ||
@@ -1037,34 +1098,33 @@ spider_net_decode_one_descr(struct spider_net_card *card)
1037 if ( (status != SPIDER_NET_DESCR_COMPLETE) && 1098 if ( (status != SPIDER_NET_DESCR_COMPLETE) &&
1038 (status != SPIDER_NET_DESCR_FRAME_END) ) { 1099 (status != SPIDER_NET_DESCR_FRAME_END) ) {
1039 if (netif_msg_rx_err(card)) 1100 if (netif_msg_rx_err(card))
1040 pr_err("%s: RX descriptor with unkown state %d\n", 1101 pr_err("%s: RX descriptor with unknown state %d\n",
1041 card->netdev->name, status); 1102 card->netdev->name, status);
1042 card->spider_stats.rx_desc_unk_state++; 1103 card->spider_stats.rx_desc_unk_state++;
1043 goto bad_desc; 1104 goto bad_desc;
1044 } 1105 }
1045 1106
1046 /* The cases we'll throw away the packet immediately */ 1107 /* The cases we'll throw away the packet immediately */
1047 if (descr->data_error & SPIDER_NET_DESTROY_RX_FLAGS) { 1108 if (hwdescr->data_error & SPIDER_NET_DESTROY_RX_FLAGS) {
1048 if (netif_msg_rx_err(card)) 1109 if (netif_msg_rx_err(card))
1049 pr_err("%s: error in received descriptor found, " 1110 pr_err("%s: error in received descriptor found, "
1050 "data_status=x%08x, data_error=x%08x\n", 1111 "data_status=x%08x, data_error=x%08x\n",
1051 card->netdev->name, 1112 card->netdev->name,
1052 descr->data_status, descr->data_error); 1113 hwdescr->data_status, hwdescr->data_error);
1053 goto bad_desc; 1114 goto bad_desc;
1054 } 1115 }
1055 1116
1056 if (descr->dmac_cmd_status & 0xfefe) { 1117 if (hwdescr->dmac_cmd_status & 0xfefe) {
1057 pr_err("%s: bad status, cmd_status=x%08x\n", 1118 pr_err("%s: bad status, cmd_status=x%08x\n",
1058 card->netdev->name, 1119 card->netdev->name,
1059 descr->dmac_cmd_status); 1120 hwdescr->dmac_cmd_status);
1060 pr_err("buf_addr=x%08x\n", descr->buf_addr); 1121 pr_err("buf_addr=x%08x\n", hwdescr->buf_addr);
1061 pr_err("buf_size=x%08x\n", descr->buf_size); 1122 pr_err("buf_size=x%08x\n", hwdescr->buf_size);
1062 pr_err("next_descr_addr=x%08x\n", descr->next_descr_addr); 1123 pr_err("next_descr_addr=x%08x\n", hwdescr->next_descr_addr);
1063 pr_err("result_size=x%08x\n", descr->result_size); 1124 pr_err("result_size=x%08x\n", hwdescr->result_size);
1064 pr_err("valid_size=x%08x\n", descr->valid_size); 1125 pr_err("valid_size=x%08x\n", hwdescr->valid_size);
1065 pr_err("data_status=x%08x\n", descr->data_status); 1126 pr_err("data_status=x%08x\n", hwdescr->data_status);
1066 pr_err("data_error=x%08x\n", descr->data_error); 1127 pr_err("data_error=x%08x\n", hwdescr->data_error);
1067 pr_err("bus_addr=x%08x\n", descr->bus_addr);
1068 pr_err("which=%ld\n", descr - card->rx_chain.ring); 1128 pr_err("which=%ld\n", descr - card->rx_chain.ring);
1069 1129
1070 card->spider_stats.rx_desc_error++; 1130 card->spider_stats.rx_desc_error++;
@@ -1073,12 +1133,13 @@ spider_net_decode_one_descr(struct spider_net_card *card)
1073 1133
1074 /* Ok, we've got a packet in descr */ 1134 /* Ok, we've got a packet in descr */
1075 spider_net_pass_skb_up(descr, card); 1135 spider_net_pass_skb_up(descr, card);
1076 descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE; 1136 hwdescr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
1077 return 1; 1137 return 1;
1078 1138
1079bad_desc: 1139bad_desc:
1080 dev_kfree_skb_irq(descr->skb); 1140 dev_kfree_skb_irq(descr->skb);
1081 descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE; 1141 descr->skb = NULL;
1142 hwdescr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
1082 return 0; 1143 return 0;
1083} 1144}
1084 1145
@@ -1248,6 +1309,33 @@ spider_net_set_mac(struct net_device *netdev, void *p)
1248} 1309}
1249 1310
1250/** 1311/**
1312 * spider_net_link_reset
1313 * @netdev: net device structure
1314 *
1315 * This is called when the PHY_LINK signal is asserted. For the blade this is
1316 * not connected so we should never get here.
1317 *
1318 */
1319static void
1320spider_net_link_reset(struct net_device *netdev)
1321{
1322
1323 struct spider_net_card *card = netdev_priv(netdev);
1324
1325 del_timer_sync(&card->aneg_timer);
1326
1327 /* clear interrupt, block further interrupts */
1328 spider_net_write_reg(card, SPIDER_NET_GMACST,
1329 spider_net_read_reg(card, SPIDER_NET_GMACST));
1330 spider_net_write_reg(card, SPIDER_NET_GMACINTEN, 0);
1331
1332 /* reset phy and setup aneg */
1333 spider_net_setup_aneg(card);
1334 mod_timer(&card->aneg_timer, jiffies + SPIDER_NET_ANEG_TIMER);
1335
1336}
1337
1338/**
1251 * spider_net_handle_error_irq - handles errors raised by an interrupt 1339 * spider_net_handle_error_irq - handles errors raised by an interrupt
1252 * @card: card structure 1340 * @card: card structure
1253 * @status_reg: interrupt status register 0 (GHIINT0STS) 1341 * @status_reg: interrupt status register 0 (GHIINT0STS)
@@ -1359,8 +1447,8 @@ spider_net_handle_error_irq(struct spider_net_card *card, u32 status_reg)
1359 switch (i) 1447 switch (i)
1360 { 1448 {
1361 case SPIDER_NET_GTMFLLINT: 1449 case SPIDER_NET_GTMFLLINT:
1362 if (netif_msg_intr(card) && net_ratelimit()) 1450 /* TX RAM full may happen on a usual case.
1363 pr_err("Spider TX RAM full\n"); 1451 * Logging is not needed. */
1364 show_error = 0; 1452 show_error = 0;
1365 break; 1453 break;
1366 case SPIDER_NET_GRFDFLLINT: /* fallthrough */ 1454 case SPIDER_NET_GRFDFLLINT: /* fallthrough */
@@ -1500,6 +1588,9 @@ spider_net_interrupt(int irq, void *ptr)
1500 if (status_reg & SPIDER_NET_TXINT) 1588 if (status_reg & SPIDER_NET_TXINT)
1501 netif_rx_schedule(netdev); 1589 netif_rx_schedule(netdev);
1502 1590
1591 if (status_reg & SPIDER_NET_LINKINT)
1592 spider_net_link_reset(netdev);
1593
1503 if (status_reg & SPIDER_NET_ERRINT ) 1594 if (status_reg & SPIDER_NET_ERRINT )
1504 spider_net_handle_error_irq(card, status_reg); 1595 spider_net_handle_error_irq(card, status_reg);
1505 1596
@@ -1540,6 +1631,11 @@ spider_net_init_card(struct spider_net_card *card)
1540 1631
1541 spider_net_write_reg(card, SPIDER_NET_CKRCTRL, 1632 spider_net_write_reg(card, SPIDER_NET_CKRCTRL,
1542 SPIDER_NET_CKRCTRL_RUN_VALUE); 1633 SPIDER_NET_CKRCTRL_RUN_VALUE);
1634
1635 /* trigger ETOMOD signal */
1636 spider_net_write_reg(card, SPIDER_NET_GMACOPEMD,
1637 spider_net_read_reg(card, SPIDER_NET_GMACOPEMD) | 0x4);
1638
1543} 1639}
1544 1640
1545/** 1641/**
@@ -1624,8 +1720,6 @@ spider_net_enable_card(struct spider_net_card *card)
1624 1720
1625 spider_net_write_reg(card, SPIDER_NET_GMACLENLMT, 1721 spider_net_write_reg(card, SPIDER_NET_GMACLENLMT,
1626 SPIDER_NET_LENLMT_VALUE); 1722 SPIDER_NET_LENLMT_VALUE);
1627 spider_net_write_reg(card, SPIDER_NET_GMACMODE,
1628 SPIDER_NET_MACMODE_VALUE);
1629 spider_net_write_reg(card, SPIDER_NET_GMACOPEMD, 1723 spider_net_write_reg(card, SPIDER_NET_GMACOPEMD,
1630 SPIDER_NET_OPMODE_VALUE); 1724 SPIDER_NET_OPMODE_VALUE);
1631 1725
@@ -1642,98 +1736,6 @@ spider_net_enable_card(struct spider_net_card *card)
1642} 1736}
1643 1737
1644/** 1738/**
1645 * spider_net_open - called upon ifonfig up
1646 * @netdev: interface device structure
1647 *
1648 * returns 0 on success, <0 on failure
1649 *
1650 * spider_net_open allocates all the descriptors and memory needed for
1651 * operation, sets up multicast list and enables interrupts
1652 */
1653int
1654spider_net_open(struct net_device *netdev)
1655{
1656 struct spider_net_card *card = netdev_priv(netdev);
1657 int result;
1658
1659 result = spider_net_init_chain(card, &card->tx_chain);
1660 if (result)
1661 goto alloc_tx_failed;
1662 card->low_watermark = NULL;
1663
1664 result = spider_net_init_chain(card, &card->rx_chain);
1665 if (result)
1666 goto alloc_rx_failed;
1667
1668 /* Allocate rx skbs */
1669 if (spider_net_alloc_rx_skbs(card))
1670 goto alloc_skbs_failed;
1671
1672 spider_net_set_multi(netdev);
1673
1674 /* further enhancement: setup hw vlan, if needed */
1675
1676 result = -EBUSY;
1677 if (request_irq(netdev->irq, spider_net_interrupt,
1678 IRQF_SHARED, netdev->name, netdev))
1679 goto register_int_failed;
1680
1681 spider_net_enable_card(card);
1682
1683 netif_start_queue(netdev);
1684 netif_carrier_on(netdev);
1685 netif_poll_enable(netdev);
1686
1687 return 0;
1688
1689register_int_failed:
1690 spider_net_free_rx_chain_contents(card);
1691alloc_skbs_failed:
1692 spider_net_free_chain(card, &card->rx_chain);
1693alloc_rx_failed:
1694 spider_net_free_chain(card, &card->tx_chain);
1695alloc_tx_failed:
1696 return result;
1697}
1698
1699/**
1700 * spider_net_setup_phy - setup PHY
1701 * @card: card structure
1702 *
1703 * returns 0 on success, <0 on failure
1704 *
1705 * spider_net_setup_phy is used as part of spider_net_probe. Sets
1706 * the PHY to 1000 Mbps
1707 **/
1708static int
1709spider_net_setup_phy(struct spider_net_card *card)
1710{
1711 struct mii_phy *phy = &card->phy;
1712
1713 spider_net_write_reg(card, SPIDER_NET_GDTDMASEL,
1714 SPIDER_NET_DMASEL_VALUE);
1715 spider_net_write_reg(card, SPIDER_NET_GPCCTRL,
1716 SPIDER_NET_PHY_CTRL_VALUE);
1717 phy->mii_id = 1;
1718 phy->dev = card->netdev;
1719 phy->mdio_read = spider_net_read_phy;
1720 phy->mdio_write = spider_net_write_phy;
1721
1722 mii_phy_probe(phy, phy->mii_id);
1723
1724 if (phy->def->ops->setup_forced)
1725 phy->def->ops->setup_forced(phy, SPEED_1000, DUPLEX_FULL);
1726
1727 phy->def->ops->enable_fiber(phy);
1728
1729 phy->def->ops->read_link(phy);
1730 pr_info("Found %s with %i Mbps, %s-duplex.\n", phy->def->name,
1731 phy->speed, phy->duplex==1 ? "Full" : "Half");
1732
1733 return 0;
1734}
1735
1736/**
1737 * spider_net_download_firmware - loads firmware into the adapter 1739 * spider_net_download_firmware - loads firmware into the adapter
1738 * @card: card structure 1740 * @card: card structure
1739 * @firmware_ptr: pointer to firmware data 1741 * @firmware_ptr: pointer to firmware data
@@ -1852,6 +1854,179 @@ out_err:
1852} 1854}
1853 1855
1854/** 1856/**
1857 * spider_net_open - called upon ifonfig up
1858 * @netdev: interface device structure
1859 *
1860 * returns 0 on success, <0 on failure
1861 *
1862 * spider_net_open allocates all the descriptors and memory needed for
1863 * operation, sets up multicast list and enables interrupts
1864 */
1865int
1866spider_net_open(struct net_device *netdev)
1867{
1868 struct spider_net_card *card = netdev_priv(netdev);
1869 int result;
1870
1871 result = spider_net_init_firmware(card);
1872 if (result)
1873 goto init_firmware_failed;
1874
1875 /* start probing with copper */
1876 spider_net_setup_aneg(card);
1877 if (card->phy.def->phy_id)
1878 mod_timer(&card->aneg_timer, jiffies + SPIDER_NET_ANEG_TIMER);
1879
1880 result = spider_net_init_chain(card, &card->tx_chain);
1881 if (result)
1882 goto alloc_tx_failed;
1883 card->low_watermark = NULL;
1884
1885 result = spider_net_init_chain(card, &card->rx_chain);
1886 if (result)
1887 goto alloc_rx_failed;
1888
1889 /* Allocate rx skbs */
1890 if (spider_net_alloc_rx_skbs(card))
1891 goto alloc_skbs_failed;
1892
1893 spider_net_set_multi(netdev);
1894
1895 /* further enhancement: setup hw vlan, if needed */
1896
1897 result = -EBUSY;
1898 if (request_irq(netdev->irq, spider_net_interrupt,
1899 IRQF_SHARED, netdev->name, netdev))
1900 goto register_int_failed;
1901
1902 spider_net_enable_card(card);
1903
1904 netif_start_queue(netdev);
1905 netif_carrier_on(netdev);
1906 netif_poll_enable(netdev);
1907
1908 return 0;
1909
1910register_int_failed:
1911 spider_net_free_rx_chain_contents(card);
1912alloc_skbs_failed:
1913 spider_net_free_chain(card, &card->rx_chain);
1914alloc_rx_failed:
1915 spider_net_free_chain(card, &card->tx_chain);
1916alloc_tx_failed:
1917 del_timer_sync(&card->aneg_timer);
1918init_firmware_failed:
1919 return result;
1920}
1921
1922/**
1923 * spider_net_link_phy
1924 * @data: used for pointer to card structure
1925 *
1926 */
1927static void spider_net_link_phy(unsigned long data)
1928{
1929 struct spider_net_card *card = (struct spider_net_card *)data;
1930 struct mii_phy *phy = &card->phy;
1931
1932 /* if link didn't come up after SPIDER_NET_ANEG_TIMEOUT tries, setup phy again */
1933 if (card->aneg_count > SPIDER_NET_ANEG_TIMEOUT) {
1934
1935 pr_info("%s: link is down trying to bring it up\n", card->netdev->name);
1936
1937 switch (card->medium) {
1938 case BCM54XX_COPPER:
1939 /* enable fiber with autonegotiation first */
1940 if (phy->def->ops->enable_fiber)
1941 phy->def->ops->enable_fiber(phy, 1);
1942 card->medium = BCM54XX_FIBER;
1943 break;
1944
1945 case BCM54XX_FIBER:
1946 /* fiber didn't come up, try to disable fiber autoneg */
1947 if (phy->def->ops->enable_fiber)
1948 phy->def->ops->enable_fiber(phy, 0);
1949 card->medium = BCM54XX_UNKNOWN;
1950 break;
1951
1952 case BCM54XX_UNKNOWN:
1953 /* copper, fiber with and without failed,
1954 * retry from beginning */
1955 spider_net_setup_aneg(card);
1956 card->medium = BCM54XX_COPPER;
1957 break;
1958 }
1959
1960 card->aneg_count = 0;
1961 mod_timer(&card->aneg_timer, jiffies + SPIDER_NET_ANEG_TIMER);
1962 return;
1963 }
1964
1965 /* link still not up, try again later */
1966 if (!(phy->def->ops->poll_link(phy))) {
1967 card->aneg_count++;
1968 mod_timer(&card->aneg_timer, jiffies + SPIDER_NET_ANEG_TIMER);
1969 return;
1970 }
1971
1972 /* link came up, get abilities */
1973 phy->def->ops->read_link(phy);
1974
1975 spider_net_write_reg(card, SPIDER_NET_GMACST,
1976 spider_net_read_reg(card, SPIDER_NET_GMACST));
1977 spider_net_write_reg(card, SPIDER_NET_GMACINTEN, 0x4);
1978
1979 if (phy->speed == 1000)
1980 spider_net_write_reg(card, SPIDER_NET_GMACMODE, 0x00000001);
1981 else
1982 spider_net_write_reg(card, SPIDER_NET_GMACMODE, 0);
1983
1984 card->aneg_count = 0;
1985
1986 pr_debug("Found %s with %i Mbps, %s-duplex %sautoneg.\n",
1987 phy->def->name, phy->speed, phy->duplex==1 ? "Full" : "Half",
1988 phy->autoneg==1 ? "" : "no ");
1989
1990 return;
1991}
1992
1993/**
1994 * spider_net_setup_phy - setup PHY
1995 * @card: card structure
1996 *
1997 * returns 0 on success, <0 on failure
1998 *
1999 * spider_net_setup_phy is used as part of spider_net_probe.
2000 **/
2001static int
2002spider_net_setup_phy(struct spider_net_card *card)
2003{
2004 struct mii_phy *phy = &card->phy;
2005
2006 spider_net_write_reg(card, SPIDER_NET_GDTDMASEL,
2007 SPIDER_NET_DMASEL_VALUE);
2008 spider_net_write_reg(card, SPIDER_NET_GPCCTRL,
2009 SPIDER_NET_PHY_CTRL_VALUE);
2010
2011 phy->dev = card->netdev;
2012 phy->mdio_read = spider_net_read_phy;
2013 phy->mdio_write = spider_net_write_phy;
2014
2015 for (phy->mii_id = 1; phy->mii_id <= 31; phy->mii_id++) {
2016 unsigned short id;
2017 id = spider_net_read_phy(card->netdev, phy->mii_id, MII_BMSR);
2018 if (id != 0x0000 && id != 0xffff) {
2019 if (!mii_phy_probe(phy, phy->mii_id)) {
2020 pr_info("Found %s.\n", phy->def->name);
2021 break;
2022 }
2023 }
2024 }
2025
2026 return 0;
2027}
2028
2029/**
1855 * spider_net_workaround_rxramfull - work around firmware bug 2030 * spider_net_workaround_rxramfull - work around firmware bug
1856 * @card: card structure 2031 * @card: card structure
1857 * 2032 *
@@ -1900,14 +2075,15 @@ spider_net_stop(struct net_device *netdev)
1900 netif_carrier_off(netdev); 2075 netif_carrier_off(netdev);
1901 netif_stop_queue(netdev); 2076 netif_stop_queue(netdev);
1902 del_timer_sync(&card->tx_timer); 2077 del_timer_sync(&card->tx_timer);
2078 del_timer_sync(&card->aneg_timer);
1903 2079
1904 /* disable/mask all interrupts */ 2080 /* disable/mask all interrupts */
1905 spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, 0); 2081 spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, 0);
1906 spider_net_write_reg(card, SPIDER_NET_GHIINT1MSK, 0); 2082 spider_net_write_reg(card, SPIDER_NET_GHIINT1MSK, 0);
1907 spider_net_write_reg(card, SPIDER_NET_GHIINT2MSK, 0); 2083 spider_net_write_reg(card, SPIDER_NET_GHIINT2MSK, 0);
2084 spider_net_write_reg(card, SPIDER_NET_GMACINTEN, 0);
1908 2085
1909 /* free_irq(netdev->irq, netdev);*/ 2086 free_irq(netdev->irq, netdev);
1910 free_irq(to_pci_dev(netdev->dev.parent)->irq, netdev);
1911 2087
1912 spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR, 2088 spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR,
1913 SPIDER_NET_DMA_TX_FEND_VALUE); 2089 SPIDER_NET_DMA_TX_FEND_VALUE);
@@ -1919,8 +2095,6 @@ spider_net_stop(struct net_device *netdev)
1919 spider_net_release_tx_chain(card, 1); 2095 spider_net_release_tx_chain(card, 1);
1920 spider_net_free_rx_chain_contents(card); 2096 spider_net_free_rx_chain_contents(card);
1921 2097
1922 spider_net_free_rx_chain_contents(card);
1923
1924 spider_net_free_chain(card, &card->tx_chain); 2098 spider_net_free_chain(card, &card->tx_chain);
1925 spider_net_free_chain(card, &card->rx_chain); 2099 spider_net_free_chain(card, &card->rx_chain);
1926 2100
@@ -1952,8 +2126,6 @@ spider_net_tx_timeout_task(struct work_struct *work)
1952 2126
1953 if (spider_net_setup_phy(card)) 2127 if (spider_net_setup_phy(card))
1954 goto out; 2128 goto out;
1955 if (spider_net_init_firmware(card))
1956 goto out;
1957 2129
1958 spider_net_open(netdev); 2130 spider_net_open(netdev);
1959 spider_net_kick_tx_dma(card); 2131 spider_net_kick_tx_dma(card);
@@ -2046,10 +2218,12 @@ spider_net_setup_netdev(struct spider_net_card *card)
2046 card->tx_timer.data = (unsigned long) card; 2218 card->tx_timer.data = (unsigned long) card;
2047 netdev->irq = card->pdev->irq; 2219 netdev->irq = card->pdev->irq;
2048 2220
2049 card->options.rx_csum = SPIDER_NET_RX_CSUM_DEFAULT; 2221 card->aneg_count = 0;
2222 init_timer(&card->aneg_timer);
2223 card->aneg_timer.function = spider_net_link_phy;
2224 card->aneg_timer.data = (unsigned long) card;
2050 2225
2051 card->tx_chain.num_desc = tx_descriptors; 2226 card->options.rx_csum = SPIDER_NET_RX_CSUM_DEFAULT;
2052 card->rx_chain.num_desc = rx_descriptors;
2053 2227
2054 spider_net_setup_netdev_ops(netdev); 2228 spider_net_setup_netdev_ops(netdev);
2055 2229
@@ -2098,8 +2272,11 @@ spider_net_alloc_card(void)
2098{ 2272{
2099 struct net_device *netdev; 2273 struct net_device *netdev;
2100 struct spider_net_card *card; 2274 struct spider_net_card *card;
2275 size_t alloc_size;
2101 2276
2102 netdev = alloc_etherdev(sizeof(struct spider_net_card)); 2277 alloc_size = sizeof(struct spider_net_card) +
2278 (tx_descriptors + rx_descriptors) * sizeof(struct spider_net_descr);
2279 netdev = alloc_etherdev(alloc_size);
2103 if (!netdev) 2280 if (!netdev)
2104 return NULL; 2281 return NULL;
2105 2282
@@ -2110,6 +2287,11 @@ spider_net_alloc_card(void)
2110 init_waitqueue_head(&card->waitq); 2287 init_waitqueue_head(&card->waitq);
2111 atomic_set(&card->tx_timeout_task_counter, 0); 2288 atomic_set(&card->tx_timeout_task_counter, 0);
2112 2289
2290 card->rx_chain.num_desc = rx_descriptors;
2291 card->rx_chain.ring = card->darray;
2292 card->tx_chain.num_desc = tx_descriptors;
2293 card->tx_chain.ring = card->darray + rx_descriptors;
2294
2113 return card; 2295 return card;
2114} 2296}
2115 2297
@@ -2220,10 +2402,6 @@ spider_net_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2220 if (err) 2402 if (err)
2221 goto out_undo_pci; 2403 goto out_undo_pci;
2222 2404
2223 err = spider_net_init_firmware(card);
2224 if (err)
2225 goto out_undo_pci;
2226
2227 err = spider_net_setup_netdev(card); 2405 err = spider_net_setup_netdev(card);
2228 if (err) 2406 if (err)
2229 goto out_undo_pci; 2407 goto out_undo_pci;
diff --git a/drivers/net/spider_net.h b/drivers/net/spider_net.h
index 2fec5cf769..4a1e0d28a5 100644
--- a/drivers/net/spider_net.h
+++ b/drivers/net/spider_net.h
@@ -1,7 +1,8 @@
1/* 1/*
2 * Network device driver for Cell Processor-Based Blade 2 * Network device driver for Cell Processor-Based Blade and Celleb platform
3 * 3 *
4 * (C) Copyright IBM Corp. 2005 4 * (C) Copyright IBM Corp. 2005
5 * (C) Copyright 2006 TOSHIBA CORPORATION
5 * 6 *
6 * Authors : Utz Bacher <utz.bacher@de.ibm.com> 7 * Authors : Utz Bacher <utz.bacher@de.ibm.com>
7 * Jens Osterkamp <Jens.Osterkamp@de.ibm.com> 8 * Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
@@ -24,7 +25,7 @@
24#ifndef _SPIDER_NET_H 25#ifndef _SPIDER_NET_H
25#define _SPIDER_NET_H 26#define _SPIDER_NET_H
26 27
27#define VERSION "1.6 B" 28#define VERSION "2.0 A"
28 29
29#include "sungem_phy.h" 30#include "sungem_phy.h"
30 31
@@ -50,6 +51,8 @@ extern char spider_net_driver_name[];
50#define SPIDER_NET_TX_DESCRIPTORS_MAX 512 51#define SPIDER_NET_TX_DESCRIPTORS_MAX 512
51 52
52#define SPIDER_NET_TX_TIMER (HZ/5) 53#define SPIDER_NET_TX_TIMER (HZ/5)
54#define SPIDER_NET_ANEG_TIMER (HZ)
55#define SPIDER_NET_ANEG_TIMEOUT 2
53 56
54#define SPIDER_NET_RX_CSUM_DEFAULT 1 57#define SPIDER_NET_RX_CSUM_DEFAULT 1
55 58
@@ -104,6 +107,7 @@ extern char spider_net_driver_name[];
104 107
105#define SPIDER_NET_GMACOPEMD 0x00000100 108#define SPIDER_NET_GMACOPEMD 0x00000100
106#define SPIDER_NET_GMACLENLMT 0x00000108 109#define SPIDER_NET_GMACLENLMT 0x00000108
110#define SPIDER_NET_GMACST 0x00000110
107#define SPIDER_NET_GMACINTEN 0x00000118 111#define SPIDER_NET_GMACINTEN 0x00000118
108#define SPIDER_NET_GMACPHYCTRL 0x00000120 112#define SPIDER_NET_GMACPHYCTRL 0x00000120
109 113
@@ -181,7 +185,8 @@ extern char spider_net_driver_name[];
181 185
182/* pause frames: automatic, no upper retransmission count */ 186/* pause frames: automatic, no upper retransmission count */
183/* outside loopback mode: ETOMOD signal dont matter, not connected */ 187/* outside loopback mode: ETOMOD signal dont matter, not connected */
184#define SPIDER_NET_OPMODE_VALUE 0x00000063 188/* ETOMOD signal is brought to PHY reset. bit 2 must be 1 in Celleb */
189#define SPIDER_NET_OPMODE_VALUE 0x00000067
185/*#define SPIDER_NET_OPMODE_VALUE 0x001b0062*/ 190/*#define SPIDER_NET_OPMODE_VALUE 0x001b0062*/
186#define SPIDER_NET_LENLMT_VALUE 0x00000908 191#define SPIDER_NET_LENLMT_VALUE 0x00000908
187 192
@@ -333,9 +338,12 @@ enum spider_net_int2_status {
333/* We rely on flagged descriptor interrupts */ 338/* We rely on flagged descriptor interrupts */
334#define SPIDER_NET_RXINT ( (1 << SPIDER_NET_GDAFDCINT) ) 339#define SPIDER_NET_RXINT ( (1 << SPIDER_NET_GDAFDCINT) )
335 340
341#define SPIDER_NET_LINKINT ( 1 << SPIDER_NET_GMAC2INT )
342
336#define SPIDER_NET_ERRINT ( 0xffffffff & \ 343#define SPIDER_NET_ERRINT ( 0xffffffff & \
337 (~SPIDER_NET_TXINT) & \ 344 (~SPIDER_NET_TXINT) & \
338 (~SPIDER_NET_RXINT) ) 345 (~SPIDER_NET_RXINT) & \
346 (~SPIDER_NET_LINKINT) )
339 347
340#define SPIDER_NET_GPREXEC 0x80000000 348#define SPIDER_NET_GPREXEC 0x80000000
341#define SPIDER_NET_GPRDAT_MASK 0x0000ffff 349#define SPIDER_NET_GPRDAT_MASK 0x0000ffff
@@ -356,8 +364,8 @@ enum spider_net_int2_status {
356#define SPIDER_NET_DESCR_NOT_IN_USE 0xF0000000 364#define SPIDER_NET_DESCR_NOT_IN_USE 0xF0000000
357#define SPIDER_NET_DESCR_TXDESFLG 0x00800000 365#define SPIDER_NET_DESCR_TXDESFLG 0x00800000
358 366
359struct spider_net_descr { 367/* Descriptor, as defined by the hardware */
360 /* as defined by the hardware */ 368struct spider_net_hw_descr {
361 u32 buf_addr; 369 u32 buf_addr;
362 u32 buf_size; 370 u32 buf_size;
363 u32 next_descr_addr; 371 u32 next_descr_addr;
@@ -366,13 +374,15 @@ struct spider_net_descr {
366 u32 valid_size; /* all zeroes for tx */ 374 u32 valid_size; /* all zeroes for tx */
367 u32 data_status; 375 u32 data_status;
368 u32 data_error; /* all zeroes for tx */ 376 u32 data_error; /* all zeroes for tx */
377} __attribute__((aligned(32)));
369 378
370 /* used in the driver */ 379struct spider_net_descr {
380 struct spider_net_hw_descr *hwdescr;
371 struct sk_buff *skb; 381 struct sk_buff *skb;
372 u32 bus_addr; 382 u32 bus_addr;
373 struct spider_net_descr *next; 383 struct spider_net_descr *next;
374 struct spider_net_descr *prev; 384 struct spider_net_descr *prev;
375} __attribute__((aligned(32))); 385};
376 386
377struct spider_net_descr_chain { 387struct spider_net_descr_chain {
378 spinlock_t lock; 388 spinlock_t lock;
@@ -380,6 +390,7 @@ struct spider_net_descr_chain {
380 struct spider_net_descr *tail; 390 struct spider_net_descr *tail;
381 struct spider_net_descr *ring; 391 struct spider_net_descr *ring;
382 int num_desc; 392 int num_desc;
393 struct spider_net_hw_descr *hwring;
383 dma_addr_t dma_addr; 394 dma_addr_t dma_addr;
384}; 395};
385 396
@@ -436,12 +447,16 @@ struct spider_net_card {
436 struct pci_dev *pdev; 447 struct pci_dev *pdev;
437 struct mii_phy phy; 448 struct mii_phy phy;
438 449
450 int medium;
451
439 void __iomem *regs; 452 void __iomem *regs;
440 453
441 struct spider_net_descr_chain tx_chain; 454 struct spider_net_descr_chain tx_chain;
442 struct spider_net_descr_chain rx_chain; 455 struct spider_net_descr_chain rx_chain;
443 struct spider_net_descr *low_watermark; 456 struct spider_net_descr *low_watermark;
444 457
458 int aneg_count;
459 struct timer_list aneg_timer;
445 struct timer_list tx_timer; 460 struct timer_list tx_timer;
446 struct work_struct tx_timeout_task; 461 struct work_struct tx_timeout_task;
447 atomic_t tx_timeout_task_counter; 462 atomic_t tx_timeout_task_counter;
@@ -452,6 +467,9 @@ struct spider_net_card {
452 struct net_device_stats netdev_stats; 467 struct net_device_stats netdev_stats;
453 struct spider_net_extra_stats spider_stats; 468 struct spider_net_extra_stats spider_stats;
454 struct spider_net_options options; 469 struct spider_net_options options;
470
471 /* Must be last item in struct */
472 struct spider_net_descr darray[0];
455}; 473};
456 474
457#define pr_err(fmt,arg...) \ 475#define pr_err(fmt,arg...) \
diff --git a/drivers/net/starfire.c b/drivers/net/starfire.c
index bf873ea257..8bba2e3da7 100644
--- a/drivers/net/starfire.c
+++ b/drivers/net/starfire.c
@@ -677,8 +677,7 @@ static void netdev_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
677 spin_lock(&np->lock); 677 spin_lock(&np->lock);
678 if (debug > 1) 678 if (debug > 1)
679 printk("%s: removing vlanid %d from vlan filter\n", dev->name, vid); 679 printk("%s: removing vlanid %d from vlan filter\n", dev->name, vid);
680 if (np->vlgrp) 680 vlan_group_set_device(np->vlgrp, vid, NULL);
681 np->vlgrp->vlan_devices[vid] = NULL;
682 set_rx_mode(dev); 681 set_rx_mode(dev);
683 spin_unlock(&np->lock); 682 spin_unlock(&np->lock);
684} 683}
@@ -1738,7 +1737,7 @@ static void set_rx_mode(struct net_device *dev)
1738 int vlan_count = 0; 1737 int vlan_count = 0;
1739 void __iomem *filter_addr = ioaddr + HashTable + 8; 1738 void __iomem *filter_addr = ioaddr + HashTable + 8;
1740 for (i = 0; i < VLAN_VID_MASK; i++) { 1739 for (i = 0; i < VLAN_VID_MASK; i++) {
1741 if (np->vlgrp->vlan_devices[i]) { 1740 if (vlan_group_get_device(np->vlgrp, i)) {
1742 if (vlan_count >= 32) 1741 if (vlan_count >= 32)
1743 break; 1742 break;
1744 writew(cpu_to_be16(i), filter_addr); 1743 writew(cpu_to_be16(i), filter_addr);
diff --git a/drivers/net/sun3_82586.c b/drivers/net/sun3_82586.c
index a3220a9652..4757aa647c 100644
--- a/drivers/net/sun3_82586.c
+++ b/drivers/net/sun3_82586.c
@@ -28,8 +28,6 @@ static int automatic_resume = 0; /* experimental .. better should be zero */
28static int rfdadd = 0; /* rfdadd=1 may be better for 8K MEM cards */ 28static int rfdadd = 0; /* rfdadd=1 may be better for 8K MEM cards */
29static int fifo=0x8; /* don't change */ 29static int fifo=0x8; /* don't change */
30 30
31/* #define REALLY_SLOW_IO */
32
33#include <linux/module.h> 31#include <linux/module.h>
34#include <linux/kernel.h> 32#include <linux/kernel.h>
35#include <linux/string.h> 33#include <linux/string.h>
diff --git a/drivers/net/sungem_phy.c b/drivers/net/sungem_phy.c
index 701ba4f3b6..56a110ca5e 100644
--- a/drivers/net/sungem_phy.c
+++ b/drivers/net/sungem_phy.c
@@ -310,6 +310,107 @@ static int bcm5411_init(struct mii_phy* phy)
310 return 0; 310 return 0;
311} 311}
312 312
313static int genmii_setup_aneg(struct mii_phy *phy, u32 advertise)
314{
315 u16 ctl, adv;
316
317 phy->autoneg = 1;
318 phy->speed = SPEED_10;
319 phy->duplex = DUPLEX_HALF;
320 phy->pause = 0;
321 phy->advertising = advertise;
322
323 /* Setup standard advertise */
324 adv = phy_read(phy, MII_ADVERTISE);
325 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
326 if (advertise & ADVERTISED_10baseT_Half)
327 adv |= ADVERTISE_10HALF;
328 if (advertise & ADVERTISED_10baseT_Full)
329 adv |= ADVERTISE_10FULL;
330 if (advertise & ADVERTISED_100baseT_Half)
331 adv |= ADVERTISE_100HALF;
332 if (advertise & ADVERTISED_100baseT_Full)
333 adv |= ADVERTISE_100FULL;
334 phy_write(phy, MII_ADVERTISE, adv);
335
336 /* Start/Restart aneg */
337 ctl = phy_read(phy, MII_BMCR);
338 ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
339 phy_write(phy, MII_BMCR, ctl);
340
341 return 0;
342}
343
344static int genmii_setup_forced(struct mii_phy *phy, int speed, int fd)
345{
346 u16 ctl;
347
348 phy->autoneg = 0;
349 phy->speed = speed;
350 phy->duplex = fd;
351 phy->pause = 0;
352
353 ctl = phy_read(phy, MII_BMCR);
354 ctl &= ~(BMCR_FULLDPLX|BMCR_SPEED100|BMCR_ANENABLE);
355
356 /* First reset the PHY */
357 phy_write(phy, MII_BMCR, ctl | BMCR_RESET);
358
359 /* Select speed & duplex */
360 switch(speed) {
361 case SPEED_10:
362 break;
363 case SPEED_100:
364 ctl |= BMCR_SPEED100;
365 break;
366 case SPEED_1000:
367 default:
368 return -EINVAL;
369 }
370 if (fd == DUPLEX_FULL)
371 ctl |= BMCR_FULLDPLX;
372 phy_write(phy, MII_BMCR, ctl);
373
374 return 0;
375}
376
377static int genmii_poll_link(struct mii_phy *phy)
378{
379 u16 status;
380
381 (void)phy_read(phy, MII_BMSR);
382 status = phy_read(phy, MII_BMSR);
383 if ((status & BMSR_LSTATUS) == 0)
384 return 0;
385 if (phy->autoneg && !(status & BMSR_ANEGCOMPLETE))
386 return 0;
387 return 1;
388}
389
390static int genmii_read_link(struct mii_phy *phy)
391{
392 u16 lpa;
393
394 if (phy->autoneg) {
395 lpa = phy_read(phy, MII_LPA);
396
397 if (lpa & (LPA_10FULL | LPA_100FULL))
398 phy->duplex = DUPLEX_FULL;
399 else
400 phy->duplex = DUPLEX_HALF;
401 if (lpa & (LPA_100FULL | LPA_100HALF))
402 phy->speed = SPEED_100;
403 else
404 phy->speed = SPEED_10;
405 phy->pause = 0;
406 }
407 /* On non-aneg, we assume what we put in BMCR is the speed,
408 * though magic-aneg shouldn't prevent this case from occurring
409 */
410
411 return 0;
412}
413
313static int generic_suspend(struct mii_phy* phy) 414static int generic_suspend(struct mii_phy* phy)
314{ 415{
315 phy_write(phy, MII_BMCR, BMCR_PDOWN); 416 phy_write(phy, MII_BMCR, BMCR_PDOWN);
@@ -364,30 +465,6 @@ static int bcm5421_init(struct mii_phy* phy)
364 return 0; 465 return 0;
365} 466}
366 467
367static int bcm5421_enable_fiber(struct mii_phy* phy)
368{
369 /* enable fiber mode */
370 phy_write(phy, MII_NCONFIG, 0x9020);
371 /* LEDs active in both modes, autosense prio = fiber */
372 phy_write(phy, MII_NCONFIG, 0x945f);
373
374 /* switch off fibre autoneg */
375 phy_write(phy, MII_NCONFIG, 0xfc01);
376 phy_write(phy, 0x0b, 0x0004);
377
378 return 0;
379}
380
381static int bcm5461_enable_fiber(struct mii_phy* phy)
382{
383 phy_write(phy, MII_NCONFIG, 0xfc0c);
384 phy_write(phy, MII_BMCR, 0x4140);
385 phy_write(phy, MII_NCONFIG, 0xfc0b);
386 phy_write(phy, MII_BMCR, 0x0140);
387
388 return 0;
389}
390
391static int bcm54xx_setup_aneg(struct mii_phy *phy, u32 advertise) 468static int bcm54xx_setup_aneg(struct mii_phy *phy, u32 advertise)
392{ 469{
393 u16 ctl, adv; 470 u16 ctl, adv;
@@ -515,6 +592,155 @@ static int marvell88e1111_init(struct mii_phy* phy)
515 return 0; 592 return 0;
516} 593}
517 594
595#define BCM5421_MODE_MASK (1 << 5)
596
597static int bcm5421_poll_link(struct mii_phy* phy)
598{
599 u32 phy_reg;
600 int mode;
601
602 /* find out in what mode we are */
603 phy_write(phy, MII_NCONFIG, 0x1000);
604 phy_reg = phy_read(phy, MII_NCONFIG);
605
606 mode = (phy_reg & BCM5421_MODE_MASK) >> 5;
607
608 if ( mode == BCM54XX_COPPER)
609 return genmii_poll_link(phy);
610
611 /* try to find out wether we have a link */
612 phy_write(phy, MII_NCONFIG, 0x2000);
613 phy_reg = phy_read(phy, MII_NCONFIG);
614
615 if (phy_reg & 0x0020)
616 return 0;
617 else
618 return 1;
619}
620
621static int bcm5421_read_link(struct mii_phy* phy)
622{
623 u32 phy_reg;
624 int mode;
625
626 /* find out in what mode we are */
627 phy_write(phy, MII_NCONFIG, 0x1000);
628 phy_reg = phy_read(phy, MII_NCONFIG);
629
630 mode = (phy_reg & BCM5421_MODE_MASK ) >> 5;
631
632 if ( mode == BCM54XX_COPPER)
633 return bcm54xx_read_link(phy);
634
635 phy->speed = SPEED_1000;
636
637 /* find out wether we are running half- or full duplex */
638 phy_write(phy, MII_NCONFIG, 0x2000);
639 phy_reg = phy_read(phy, MII_NCONFIG);
640
641 if ( (phy_reg & 0x0080) >> 7)
642 phy->duplex |= DUPLEX_HALF;
643 else
644 phy->duplex |= DUPLEX_FULL;
645
646 return 0;
647}
648
649static int bcm5421_enable_fiber(struct mii_phy* phy, int autoneg)
650{
651 /* enable fiber mode */
652 phy_write(phy, MII_NCONFIG, 0x9020);
653 /* LEDs active in both modes, autosense prio = fiber */
654 phy_write(phy, MII_NCONFIG, 0x945f);
655
656 if (!autoneg) {
657 /* switch off fibre autoneg */
658 phy_write(phy, MII_NCONFIG, 0xfc01);
659 phy_write(phy, 0x0b, 0x0004);
660 }
661
662 phy->autoneg = autoneg;
663
664 return 0;
665}
666
667#define BCM5461_FIBER_LINK (1 << 2)
668#define BCM5461_MODE_MASK (3 << 1)
669
670static int bcm5461_poll_link(struct mii_phy* phy)
671{
672 u32 phy_reg;
673 int mode;
674
675 /* find out in what mode we are */
676 phy_write(phy, MII_NCONFIG, 0x7c00);
677 phy_reg = phy_read(phy, MII_NCONFIG);
678
679 mode = (phy_reg & BCM5461_MODE_MASK ) >> 1;
680
681 if ( mode == BCM54XX_COPPER)
682 return genmii_poll_link(phy);
683
684 /* find out wether we have a link */
685 phy_write(phy, MII_NCONFIG, 0x7000);
686 phy_reg = phy_read(phy, MII_NCONFIG);
687
688 if (phy_reg & BCM5461_FIBER_LINK)
689 return 1;
690 else
691 return 0;
692}
693
694#define BCM5461_FIBER_DUPLEX (1 << 3)
695
696static int bcm5461_read_link(struct mii_phy* phy)
697{
698 u32 phy_reg;
699 int mode;
700
701 /* find out in what mode we are */
702 phy_write(phy, MII_NCONFIG, 0x7c00);
703 phy_reg = phy_read(phy, MII_NCONFIG);
704
705 mode = (phy_reg & BCM5461_MODE_MASK ) >> 1;
706
707 if ( mode == BCM54XX_COPPER) {
708 return bcm54xx_read_link(phy);
709 }
710
711 phy->speed = SPEED_1000;
712
713 /* find out wether we are running half- or full duplex */
714 phy_write(phy, MII_NCONFIG, 0x7000);
715 phy_reg = phy_read(phy, MII_NCONFIG);
716
717 if (phy_reg & BCM5461_FIBER_DUPLEX)
718 phy->duplex |= DUPLEX_FULL;
719 else
720 phy->duplex |= DUPLEX_HALF;
721
722 return 0;
723}
724
725static int bcm5461_enable_fiber(struct mii_phy* phy, int autoneg)
726{
727 /* select fiber mode, enable 1000 base-X registers */
728 phy_write(phy, MII_NCONFIG, 0xfc0b);
729
730 if (autoneg) {
731 /* enable fiber with no autonegotiation */
732 phy_write(phy, MII_ADVERTISE, 0x01e0);
733 phy_write(phy, MII_BMCR, 0x1140);
734 } else {
735 /* enable fiber with autonegotiation */
736 phy_write(phy, MII_BMCR, 0x0140);
737 }
738
739 phy->autoneg = autoneg;
740
741 return 0;
742}
743
518static int marvell_setup_aneg(struct mii_phy *phy, u32 advertise) 744static int marvell_setup_aneg(struct mii_phy *phy, u32 advertise)
519{ 745{
520 u16 ctl, adv; 746 u16 ctl, adv;
@@ -645,113 +871,6 @@ static int marvell_read_link(struct mii_phy *phy)
645 return 0; 871 return 0;
646} 872}
647 873
648static int genmii_setup_aneg(struct mii_phy *phy, u32 advertise)
649{
650 u16 ctl, adv;
651
652 phy->autoneg = 1;
653 phy->speed = SPEED_10;
654 phy->duplex = DUPLEX_HALF;
655 phy->pause = 0;
656 phy->advertising = advertise;
657
658 /* Setup standard advertise */
659 adv = phy_read(phy, MII_ADVERTISE);
660 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
661 if (advertise & ADVERTISED_10baseT_Half)
662 adv |= ADVERTISE_10HALF;
663 if (advertise & ADVERTISED_10baseT_Full)
664 adv |= ADVERTISE_10FULL;
665 if (advertise & ADVERTISED_100baseT_Half)
666 adv |= ADVERTISE_100HALF;
667 if (advertise & ADVERTISED_100baseT_Full)
668 adv |= ADVERTISE_100FULL;
669 if (advertise & ADVERTISED_Pause)
670 adv |= ADVERTISE_PAUSE_CAP;
671 if (advertise & ADVERTISED_Asym_Pause)
672 adv |= ADVERTISE_PAUSE_ASYM;
673 phy_write(phy, MII_ADVERTISE, adv);
674
675 /* Start/Restart aneg */
676 ctl = phy_read(phy, MII_BMCR);
677 ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
678 phy_write(phy, MII_BMCR, ctl);
679
680 return 0;
681}
682
683static int genmii_setup_forced(struct mii_phy *phy, int speed, int fd)
684{
685 u16 ctl;
686
687 phy->autoneg = 0;
688 phy->speed = speed;
689 phy->duplex = fd;
690 phy->pause = 0;
691
692 ctl = phy_read(phy, MII_BMCR);
693 ctl &= ~(BMCR_FULLDPLX|BMCR_SPEED100|BMCR_ANENABLE);
694
695 /* First reset the PHY */
696 phy_write(phy, MII_BMCR, ctl | BMCR_RESET);
697
698 /* Select speed & duplex */
699 switch(speed) {
700 case SPEED_10:
701 break;
702 case SPEED_100:
703 ctl |= BMCR_SPEED100;
704 break;
705 case SPEED_1000:
706 default:
707 return -EINVAL;
708 }
709 if (fd == DUPLEX_FULL)
710 ctl |= BMCR_FULLDPLX;
711 phy_write(phy, MII_BMCR, ctl);
712
713 return 0;
714}
715
716static int genmii_poll_link(struct mii_phy *phy)
717{
718 u16 status;
719
720 (void)phy_read(phy, MII_BMSR);
721 status = phy_read(phy, MII_BMSR);
722 if ((status & BMSR_LSTATUS) == 0)
723 return 0;
724 if (phy->autoneg && !(status & BMSR_ANEGCOMPLETE))
725 return 0;
726 return 1;
727}
728
729static int genmii_read_link(struct mii_phy *phy)
730{
731 u16 lpa;
732
733 if (phy->autoneg) {
734 lpa = phy_read(phy, MII_LPA);
735
736 if (lpa & (LPA_10FULL | LPA_100FULL))
737 phy->duplex = DUPLEX_FULL;
738 else
739 phy->duplex = DUPLEX_HALF;
740 if (lpa & (LPA_100FULL | LPA_100HALF))
741 phy->speed = SPEED_100;
742 else
743 phy->speed = SPEED_10;
744 phy->pause = (phy->duplex == DUPLEX_FULL) &&
745 ((lpa & LPA_PAUSE) != 0);
746 }
747 /* On non-aneg, we assume what we put in BMCR is the speed,
748 * though magic-aneg shouldn't prevent this case from occurring
749 */
750
751 return 0;
752}
753
754
755#define MII_BASIC_FEATURES \ 874#define MII_BASIC_FEATURES \
756 (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | \ 875 (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | \
757 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full | \ 876 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full | \
@@ -885,8 +1004,8 @@ static struct mii_phy_ops bcm5421_phy_ops = {
885 .suspend = generic_suspend, 1004 .suspend = generic_suspend,
886 .setup_aneg = bcm54xx_setup_aneg, 1005 .setup_aneg = bcm54xx_setup_aneg,
887 .setup_forced = bcm54xx_setup_forced, 1006 .setup_forced = bcm54xx_setup_forced,
888 .poll_link = genmii_poll_link, 1007 .poll_link = bcm5421_poll_link,
889 .read_link = bcm54xx_read_link, 1008 .read_link = bcm5421_read_link,
890 .enable_fiber = bcm5421_enable_fiber, 1009 .enable_fiber = bcm5421_enable_fiber,
891}; 1010};
892 1011
@@ -923,8 +1042,8 @@ static struct mii_phy_ops bcm5461_phy_ops = {
923 .suspend = generic_suspend, 1042 .suspend = generic_suspend,
924 .setup_aneg = bcm54xx_setup_aneg, 1043 .setup_aneg = bcm54xx_setup_aneg,
925 .setup_forced = bcm54xx_setup_forced, 1044 .setup_forced = bcm54xx_setup_forced,
926 .poll_link = genmii_poll_link, 1045 .poll_link = bcm5461_poll_link,
927 .read_link = bcm54xx_read_link, 1046 .read_link = bcm5461_read_link,
928 .enable_fiber = bcm5461_enable_fiber, 1047 .enable_fiber = bcm5461_enable_fiber,
929}; 1048};
930 1049
diff --git a/drivers/net/sungem_phy.h b/drivers/net/sungem_phy.h
index 1d70ba6f9f..af02f9479c 100644
--- a/drivers/net/sungem_phy.h
+++ b/drivers/net/sungem_phy.h
@@ -12,7 +12,7 @@ struct mii_phy_ops
12 int (*setup_forced)(struct mii_phy *phy, int speed, int fd); 12 int (*setup_forced)(struct mii_phy *phy, int speed, int fd);
13 int (*poll_link)(struct mii_phy *phy); 13 int (*poll_link)(struct mii_phy *phy);
14 int (*read_link)(struct mii_phy *phy); 14 int (*read_link)(struct mii_phy *phy);
15 int (*enable_fiber)(struct mii_phy *phy); 15 int (*enable_fiber)(struct mii_phy *phy, int autoneg);
16}; 16};
17 17
18/* Structure used to statically define an mii/gii based PHY */ 18/* Structure used to statically define an mii/gii based PHY */
@@ -26,6 +26,14 @@ struct mii_phy_def
26 const struct mii_phy_ops* ops; 26 const struct mii_phy_ops* ops;
27}; 27};
28 28
29enum {
30 BCM54XX_COPPER,
31 BCM54XX_FIBER,
32 BCM54XX_GBIC,
33 BCM54XX_SGMII,
34 BCM54XX_UNKNOWN,
35};
36
29/* An instance of a PHY, partially borrowed from mii_if_info */ 37/* An instance of a PHY, partially borrowed from mii_if_info */
30struct mii_phy 38struct mii_phy
31{ 39{
diff --git a/drivers/net/tc35815.c b/drivers/net/tc35815.c
index 81ed82f0b5..e3a7e3ceab 100644
--- a/drivers/net/tc35815.c
+++ b/drivers/net/tc35815.c
@@ -657,7 +657,7 @@ tc35815_init_queues(struct net_device *dev)
657 dma_cache_wback_inv((unsigned long)lp->fd_buf, PAGE_SIZE * FD_PAGE_NUM); 657 dma_cache_wback_inv((unsigned long)lp->fd_buf, PAGE_SIZE * FD_PAGE_NUM);
658#endif 658#endif
659 } else { 659 } else {
660 clear_page(lp->fd_buf); 660 memset(lp->fd_buf, 0, PAGE_SIZE * FD_PAGE_NUM);
661#ifdef __mips__ 661#ifdef __mips__
662 dma_cache_wback_inv((unsigned long)lp->fd_buf, PAGE_SIZE * FD_PAGE_NUM); 662 dma_cache_wback_inv((unsigned long)lp->fd_buf, PAGE_SIZE * FD_PAGE_NUM);
663#endif 663#endif
@@ -1703,19 +1703,6 @@ static void tc35815_chip_init(struct net_device *dev)
1703 spin_unlock_irqrestore(&lp->lock, flags); 1703 spin_unlock_irqrestore(&lp->lock, flags);
1704} 1704}
1705 1705
1706/* XXX */
1707void
1708tc35815_killall(void)
1709{
1710 struct net_device *dev;
1711
1712 for (dev = root_tc35815_dev; dev; dev = ((struct tc35815_local *)dev->priv)->next_module) {
1713 if (dev->flags&IFF_UP){
1714 dev->stop(dev);
1715 }
1716 }
1717}
1718
1719static struct pci_driver tc35815_driver = { 1706static struct pci_driver tc35815_driver = {
1720 .name = TC35815_MODULE_NAME, 1707 .name = TC35815_MODULE_NAME,
1721 .probe = tc35815_probe, 1708 .probe = tc35815_probe,
@@ -1732,6 +1719,11 @@ static void __exit tc35815_cleanup_module(void)
1732{ 1719{
1733 struct net_device *next_dev; 1720 struct net_device *next_dev;
1734 1721
1722 /*
1723 * TODO: implement a tc35815_driver.remove hook, and
1724 * move this code into that function. Then, delete
1725 * all root_tc35815_dev list handling code.
1726 */
1735 while (root_tc35815_dev) { 1727 while (root_tc35815_dev) {
1736 struct net_device *dev = root_tc35815_dev; 1728 struct net_device *dev = root_tc35815_dev;
1737 next_dev = ((struct tc35815_local *)dev->priv)->next_module; 1729 next_dev = ((struct tc35815_local *)dev->priv)->next_module;
@@ -1740,6 +1732,9 @@ static void __exit tc35815_cleanup_module(void)
1740 free_netdev(dev); 1732 free_netdev(dev);
1741 root_tc35815_dev = next_dev; 1733 root_tc35815_dev = next_dev;
1742 } 1734 }
1735
1736 pci_unregister_driver(&tc35815_driver);
1743} 1737}
1738
1744module_init(tc35815_init_module); 1739module_init(tc35815_init_module);
1745module_exit(tc35815_cleanup_module); 1740module_exit(tc35815_cleanup_module);
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 81a1c2e1a3..8c8f9f4d47 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -64,8 +64,8 @@
64 64
65#define DRV_MODULE_NAME "tg3" 65#define DRV_MODULE_NAME "tg3"
66#define PFX DRV_MODULE_NAME ": " 66#define PFX DRV_MODULE_NAME ": "
67#define DRV_MODULE_VERSION "3.73" 67#define DRV_MODULE_VERSION "3.74"
68#define DRV_MODULE_RELDATE "February 12, 2007" 68#define DRV_MODULE_RELDATE "February 20, 2007"
69 69
70#define TG3_DEF_MAC_MODE 0 70#define TG3_DEF_MAC_MODE 0
71#define TG3_DEF_RX_MODE 0 71#define TG3_DEF_RX_MODE 0
@@ -3993,7 +3993,10 @@ static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb)
3993 /* Estimate the number of fragments in the worst case */ 3993 /* Estimate the number of fragments in the worst case */
3994 if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))) { 3994 if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))) {
3995 netif_stop_queue(tp->dev); 3995 netif_stop_queue(tp->dev);
3996 return NETDEV_TX_BUSY; 3996 if (tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))
3997 return NETDEV_TX_BUSY;
3998
3999 netif_wake_queue(tp->dev);
3997 } 4000 }
3998 4001
3999 segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO); 4002 segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO);
@@ -4061,7 +4064,7 @@ static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
4061 4064
4062 hdr_len = ip_tcp_len + tcp_opt_len; 4065 hdr_len = ip_tcp_len + tcp_opt_len;
4063 if (unlikely((ETH_HLEN + hdr_len) > 80) && 4066 if (unlikely((ETH_HLEN + hdr_len) > 80) &&
4064 (tp->tg3_flags2 & TG3_FLG2_HW_TSO_1_BUG)) 4067 (tp->tg3_flags2 & TG3_FLG2_TSO_BUG))
4065 return (tg3_tso_bug(tp, skb)); 4068 return (tg3_tso_bug(tp, skb));
4066 4069
4067 base_flags |= (TXD_FLAG_CPU_PRE_DMA | 4070 base_flags |= (TXD_FLAG_CPU_PRE_DMA |
@@ -8137,7 +8140,7 @@ static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *e
8137 (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) || 8140 (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) ||
8138 (ering->tx_pending > TG3_TX_RING_SIZE - 1) || 8141 (ering->tx_pending > TG3_TX_RING_SIZE - 1) ||
8139 (ering->tx_pending <= MAX_SKB_FRAGS) || 8142 (ering->tx_pending <= MAX_SKB_FRAGS) ||
8140 ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_1_BUG) && 8143 ((tp->tg3_flags2 & TG3_FLG2_TSO_BUG) &&
8141 (ering->tx_pending <= (MAX_SKB_FRAGS * 3)))) 8144 (ering->tx_pending <= (MAX_SKB_FRAGS * 3))))
8142 return -EINVAL; 8145 return -EINVAL;
8143 8146
@@ -9111,8 +9114,7 @@ static void tg3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
9111 tg3_netif_stop(tp); 9114 tg3_netif_stop(tp);
9112 9115
9113 tg3_full_lock(tp, 0); 9116 tg3_full_lock(tp, 0);
9114 if (tp->vlgrp) 9117 vlan_group_set_device(tp->vlgrp, vid, NULL);
9115 tp->vlgrp->vlan_devices[vid] = NULL;
9116 tg3_full_unlock(tp); 9118 tg3_full_unlock(tp);
9117 9119
9118 if (netif_running(dev)) 9120 if (netif_running(dev))
@@ -10557,12 +10559,11 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10557 tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2; 10559 tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2;
10558 tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI; 10560 tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI;
10559 } else { 10561 } else {
10560 tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1 | 10562 tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1 | TG3_FLG2_TSO_BUG;
10561 TG3_FLG2_HW_TSO_1_BUG;
10562 if (GET_ASIC_REV(tp->pci_chip_rev_id) == 10563 if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
10563 ASIC_REV_5750 && 10564 ASIC_REV_5750 &&
10564 tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2) 10565 tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2)
10565 tp->tg3_flags2 &= ~TG3_FLG2_HW_TSO_1_BUG; 10566 tp->tg3_flags2 &= ~TG3_FLG2_TSO_BUG;
10566 } 10567 }
10567 } 10568 }
10568 10569
@@ -11867,7 +11868,7 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
11867 (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) { 11868 (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
11868 tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE; 11869 tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
11869 } else { 11870 } else {
11870 tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE; 11871 tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE | TG3_FLG2_TSO_BUG;
11871 } 11872 }
11872 11873
11873 /* TSO is on by default on chips that support hardware TSO. 11874 /* TSO is on by default on chips that support hardware TSO.
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index 45d477e8f3..086892d8c1 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -2227,7 +2227,7 @@ struct tg3 {
2227#define TG3_FLAG_INIT_COMPLETE 0x80000000 2227#define TG3_FLAG_INIT_COMPLETE 0x80000000
2228 u32 tg3_flags2; 2228 u32 tg3_flags2;
2229#define TG3_FLG2_RESTART_TIMER 0x00000001 2229#define TG3_FLG2_RESTART_TIMER 0x00000001
2230#define TG3_FLG2_HW_TSO_1_BUG 0x00000002 2230#define TG3_FLG2_TSO_BUG 0x00000002
2231#define TG3_FLG2_NO_ETH_WIRE_SPEED 0x00000004 2231#define TG3_FLG2_NO_ETH_WIRE_SPEED 0x00000004
2232#define TG3_FLG2_IS_5788 0x00000008 2232#define TG3_FLG2_IS_5788 0x00000008
2233#define TG3_FLG2_MAX_RXPEND_64 0x00000010 2233#define TG3_FLG2_MAX_RXPEND_64 0x00000010
diff --git a/drivers/net/tokenring/ibmtr.c b/drivers/net/tokenring/ibmtr.c
index 0d97e10cca..36202e94ee 100644
--- a/drivers/net/tokenring/ibmtr.c
+++ b/drivers/net/tokenring/ibmtr.c
@@ -186,7 +186,6 @@ static char __devinit *adapter_def(char type)
186#define TRC_INITV 0x02 /* verbose init trace points */ 186#define TRC_INITV 0x02 /* verbose init trace points */
187static unsigned char ibmtr_debug_trace = 0; 187static unsigned char ibmtr_debug_trace = 0;
188 188
189static int ibmtr_probe(struct net_device *dev);
190static int ibmtr_probe1(struct net_device *dev, int ioaddr); 189static int ibmtr_probe1(struct net_device *dev, int ioaddr);
191static unsigned char get_sram_size(struct tok_info *adapt_info); 190static unsigned char get_sram_size(struct tok_info *adapt_info);
192static int trdev_init(struct net_device *dev); 191static int trdev_init(struct net_device *dev);
@@ -335,17 +334,6 @@ static void ibmtr_cleanup_card(struct net_device *dev)
335#endif 334#endif
336} 335}
337 336
338int ibmtr_probe_card(struct net_device *dev)
339{
340 int err = ibmtr_probe(dev);
341 if (!err) {
342 err = register_netdev(dev);
343 if (err)
344 ibmtr_cleanup_card(dev);
345 }
346 return err;
347}
348
349/**************************************************************************** 337/****************************************************************************
350 * ibmtr_probe(): Routine specified in the network device structure 338 * ibmtr_probe(): Routine specified in the network device structure
351 * to probe for an IBM Token Ring Adapter. Routine outline: 339 * to probe for an IBM Token Ring Adapter. Routine outline:
@@ -358,7 +346,7 @@ int ibmtr_probe_card(struct net_device *dev)
358 * which references it. 346 * which references it.
359 ****************************************************************************/ 347 ****************************************************************************/
360 348
361static int ibmtr_probe(struct net_device *dev) 349static int __init ibmtr_probe(struct net_device *dev)
362{ 350{
363 int i; 351 int i;
364 int base_addr = dev->base_addr; 352 int base_addr = dev->base_addr;
@@ -378,6 +366,17 @@ static int ibmtr_probe(struct net_device *dev)
378 return -ENODEV; 366 return -ENODEV;
379} 367}
380 368
369int __init ibmtr_probe_card(struct net_device *dev)
370{
371 int err = ibmtr_probe(dev);
372 if (!err) {
373 err = register_netdev(dev);
374 if (err)
375 ibmtr_cleanup_card(dev);
376 }
377 return err;
378}
379
381/*****************************************************************************/ 380/*****************************************************************************/
382 381
383static int __devinit ibmtr_probe1(struct net_device *dev, int PIOaddr) 382static int __devinit ibmtr_probe1(struct net_device *dev, int PIOaddr)
diff --git a/drivers/net/tulip/de2104x.c b/drivers/net/tulip/de2104x.c
index 9d67f11422..c82befa209 100644
--- a/drivers/net/tulip/de2104x.c
+++ b/drivers/net/tulip/de2104x.c
@@ -63,7 +63,7 @@ MODULE_PARM_DESC (debug, "de2104x bitmapped message enable number");
63 63
64/* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */ 64/* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */
65#if defined(__alpha__) || defined(__arm__) || defined(__hppa__) \ 65#if defined(__alpha__) || defined(__arm__) || defined(__hppa__) \
66 || defined(__sparc_) || defined(__ia64__) \ 66 || defined(__sparc__) || defined(__ia64__) \
67 || defined(__sh__) || defined(__mips__) 67 || defined(__sh__) || defined(__mips__)
68static int rx_copybreak = 1518; 68static int rx_copybreak = 1518;
69#else 69#else
@@ -1685,7 +1685,7 @@ static const struct ethtool_ops de_ethtool_ops = {
1685 .get_regs = de_get_regs, 1685 .get_regs = de_get_regs,
1686}; 1686};
1687 1687
1688static void __init de21040_get_mac_address (struct de_private *de) 1688static void __devinit de21040_get_mac_address (struct de_private *de)
1689{ 1689{
1690 unsigned i; 1690 unsigned i;
1691 1691
@@ -1703,7 +1703,7 @@ static void __init de21040_get_mac_address (struct de_private *de)
1703 } 1703 }
1704} 1704}
1705 1705
1706static void __init de21040_get_media_info(struct de_private *de) 1706static void __devinit de21040_get_media_info(struct de_private *de)
1707{ 1707{
1708 unsigned int i; 1708 unsigned int i;
1709 1709
@@ -1765,7 +1765,7 @@ static unsigned __devinit tulip_read_eeprom(void __iomem *regs, int location, in
1765 return retval; 1765 return retval;
1766} 1766}
1767 1767
1768static void __init de21041_get_srom_info (struct de_private *de) 1768static void __devinit de21041_get_srom_info (struct de_private *de)
1769{ 1769{
1770 unsigned i, sa_offset = 0, ofs; 1770 unsigned i, sa_offset = 0, ofs;
1771 u8 ee_data[DE_EEPROM_SIZE + 6] = {}; 1771 u8 ee_data[DE_EEPROM_SIZE + 6] = {};
diff --git a/drivers/net/tulip/dmfe.c b/drivers/net/tulip/dmfe.c
index 7f59a3d4fd..24a29c99ba 100644
--- a/drivers/net/tulip/dmfe.c
+++ b/drivers/net/tulip/dmfe.c
@@ -143,9 +143,16 @@
143#define DMFE_TX_TIMEOUT ((3*HZ)/2) /* tx packet time-out time 1.5 s" */ 143#define DMFE_TX_TIMEOUT ((3*HZ)/2) /* tx packet time-out time 1.5 s" */
144#define DMFE_TX_KICK (HZ/2) /* tx packet Kick-out time 0.5 s" */ 144#define DMFE_TX_KICK (HZ/2) /* tx packet Kick-out time 0.5 s" */
145 145
146#define DMFE_DBUG(dbug_now, msg, value) if (dmfe_debug || (dbug_now)) printk(KERN_ERR DRV_NAME ": %s %lx\n", (msg), (long) (value)) 146#define DMFE_DBUG(dbug_now, msg, value) \
147 do { \
148 if (dmfe_debug || (dbug_now)) \
149 printk(KERN_ERR DRV_NAME ": %s %lx\n",\
150 (msg), (long) (value)); \
151 } while (0)
147 152
148#define SHOW_MEDIA_TYPE(mode) printk(KERN_ERR DRV_NAME ": Change Speed to %sMhz %s duplex\n",mode & 1 ?"100":"10", mode & 4 ? "full":"half"); 153#define SHOW_MEDIA_TYPE(mode) \
154 printk (KERN_INFO DRV_NAME ": Change Speed to %sMhz %s duplex\n" , \
155 (mode & 1) ? "100":"10", (mode & 4) ? "full":"half");
149 156
150 157
151/* CR9 definition: SROM/MII */ 158/* CR9 definition: SROM/MII */
@@ -163,10 +170,20 @@
163 170
164#define SROM_V41_CODE 0x14 171#define SROM_V41_CODE 0x14
165 172
166#define SROM_CLK_WRITE(data, ioaddr) outl(data|CR9_SROM_READ|CR9_SRCS,ioaddr);udelay(5);outl(data|CR9_SROM_READ|CR9_SRCS|CR9_SRCLK,ioaddr);udelay(5);outl(data|CR9_SROM_READ|CR9_SRCS,ioaddr);udelay(5); 173#define SROM_CLK_WRITE(data, ioaddr) \
174 outl(data|CR9_SROM_READ|CR9_SRCS,ioaddr); \
175 udelay(5); \
176 outl(data|CR9_SROM_READ|CR9_SRCS|CR9_SRCLK,ioaddr); \
177 udelay(5); \
178 outl(data|CR9_SROM_READ|CR9_SRCS,ioaddr); \
179 udelay(5);
180
181#define __CHK_IO_SIZE(pci_id, dev_rev) \
182 (( ((pci_id)==PCI_DM9132_ID) || ((dev_rev) >= 0x02000030) ) ? \
183 DM9102A_IO_SIZE: DM9102_IO_SIZE)
167 184
168#define __CHK_IO_SIZE(pci_id, dev_rev) ( ((pci_id)==PCI_DM9132_ID) || ((dev_rev) >= 0x02000030) ) ? DM9102A_IO_SIZE: DM9102_IO_SIZE 185#define CHK_IO_SIZE(pci_dev, dev_rev) \
169#define CHK_IO_SIZE(pci_dev, dev_rev) __CHK_IO_SIZE(((pci_dev)->device << 16) | (pci_dev)->vendor, dev_rev) 186 (__CHK_IO_SIZE(((pci_dev)->device << 16) | (pci_dev)->vendor, dev_rev))
170 187
171/* Sten Check */ 188/* Sten Check */
172#define DEVICE net_device 189#define DEVICE net_device
@@ -187,7 +204,7 @@ struct rx_desc {
187struct dmfe_board_info { 204struct dmfe_board_info {
188 u32 chip_id; /* Chip vendor/Device ID */ 205 u32 chip_id; /* Chip vendor/Device ID */
189 u32 chip_revision; /* Chip revision */ 206 u32 chip_revision; /* Chip revision */
190 struct DEVICE *dev; /* net device */ 207 struct DEVICE *next_dev; /* next device */
191 struct pci_dev *pdev; /* PCI device */ 208 struct pci_dev *pdev; /* PCI device */
192 spinlock_t lock; 209 spinlock_t lock;
193 210
@@ -231,7 +248,6 @@ struct dmfe_board_info {
231 u8 media_mode; /* user specify media mode */ 248 u8 media_mode; /* user specify media mode */
232 u8 op_mode; /* real work media mode */ 249 u8 op_mode; /* real work media mode */
233 u8 phy_addr; 250 u8 phy_addr;
234 u8 link_failed; /* Ever link failed */
235 u8 wait_reset; /* Hardware failed, need to reset */ 251 u8 wait_reset; /* Hardware failed, need to reset */
236 u8 dm910x_chk_mode; /* Operating mode check */ 252 u8 dm910x_chk_mode; /* Operating mode check */
237 u8 first_in_callback; /* Flag to record state */ 253 u8 first_in_callback; /* Flag to record state */
@@ -329,7 +345,7 @@ static void dmfe_program_DM9802(struct dmfe_board_info *);
329static void dmfe_HPNA_remote_cmd_chk(struct dmfe_board_info * ); 345static void dmfe_HPNA_remote_cmd_chk(struct dmfe_board_info * );
330static void dmfe_set_phyxcer(struct dmfe_board_info *); 346static void dmfe_set_phyxcer(struct dmfe_board_info *);
331 347
332/* DM910X network baord routine ---------------------------- */ 348/* DM910X network board routine ---------------------------- */
333 349
334/* 350/*
335 * Search DM910X board ,allocate space and register it 351 * Search DM910X board ,allocate space and register it
@@ -356,7 +372,8 @@ static int __devinit dmfe_init_one (struct pci_dev *pdev,
356 SET_NETDEV_DEV(dev, &pdev->dev); 372 SET_NETDEV_DEV(dev, &pdev->dev);
357 373
358 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) { 374 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
359 printk(KERN_WARNING DRV_NAME ": 32-bit PCI DMA not available.\n"); 375 printk(KERN_WARNING DRV_NAME
376 ": 32-bit PCI DMA not available.\n");
360 err = -ENODEV; 377 err = -ENODEV;
361 goto err_out_free; 378 goto err_out_free;
362 } 379 }
@@ -399,11 +416,12 @@ static int __devinit dmfe_init_one (struct pci_dev *pdev,
399 /* Init system & device */ 416 /* Init system & device */
400 db = netdev_priv(dev); 417 db = netdev_priv(dev);
401 418
402 db->dev = dev;
403
404 /* Allocate Tx/Rx descriptor memory */ 419 /* Allocate Tx/Rx descriptor memory */
405 db->desc_pool_ptr = pci_alloc_consistent(pdev, sizeof(struct tx_desc) * DESC_ALL_CNT + 0x20, &db->desc_pool_dma_ptr); 420 db->desc_pool_ptr = pci_alloc_consistent(pdev, sizeof(struct tx_desc) *
406 db->buf_pool_ptr = pci_alloc_consistent(pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4, &db->buf_pool_dma_ptr); 421 DESC_ALL_CNT + 0x20, &db->desc_pool_dma_ptr);
422
423 db->buf_pool_ptr = pci_alloc_consistent(pdev, TX_BUF_ALLOC *
424 TX_DESC_CNT + 4, &db->buf_pool_dma_ptr);
407 425
408 db->first_tx_desc = (struct tx_desc *) db->desc_pool_ptr; 426 db->first_tx_desc = (struct tx_desc *) db->desc_pool_ptr;
409 db->first_tx_desc_dma = db->desc_pool_dma_ptr; 427 db->first_tx_desc_dma = db->desc_pool_dma_ptr;
@@ -428,7 +446,7 @@ static int __devinit dmfe_init_one (struct pci_dev *pdev,
428 dev->poll_controller = &poll_dmfe; 446 dev->poll_controller = &poll_dmfe;
429#endif 447#endif
430 dev->ethtool_ops = &netdev_ethtool_ops; 448 dev->ethtool_ops = &netdev_ethtool_ops;
431 netif_carrier_off(db->dev); 449 netif_carrier_off(dev);
432 spin_lock_init(&db->lock); 450 spin_lock_init(&db->lock);
433 451
434 pci_read_config_dword(pdev, 0x50, &pci_pmr); 452 pci_read_config_dword(pdev, 0x50, &pci_pmr);
@@ -440,7 +458,8 @@ static int __devinit dmfe_init_one (struct pci_dev *pdev,
440 458
441 /* read 64 word srom data */ 459 /* read 64 word srom data */
442 for (i = 0; i < 64; i++) 460 for (i = 0; i < 64; i++)
443 ((u16 *) db->srom)[i] = cpu_to_le16(read_srom_word(db->ioaddr, i)); 461 ((u16 *) db->srom)[i] =
462 cpu_to_le16(read_srom_word(db->ioaddr, i));
444 463
445 /* Set Node address */ 464 /* Set Node address */
446 for (i = 0; i < 6; i++) 465 for (i = 0; i < 6; i++)
@@ -482,14 +501,17 @@ static void __devexit dmfe_remove_one (struct pci_dev *pdev)
482 DMFE_DBUG(0, "dmfe_remove_one()", 0); 501 DMFE_DBUG(0, "dmfe_remove_one()", 0);
483 502
484 if (dev) { 503 if (dev) {
504
505 unregister_netdev(dev);
506
485 pci_free_consistent(db->pdev, sizeof(struct tx_desc) * 507 pci_free_consistent(db->pdev, sizeof(struct tx_desc) *
486 DESC_ALL_CNT + 0x20, db->desc_pool_ptr, 508 DESC_ALL_CNT + 0x20, db->desc_pool_ptr,
487 db->desc_pool_dma_ptr); 509 db->desc_pool_dma_ptr);
488 pci_free_consistent(db->pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4, 510 pci_free_consistent(db->pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4,
489 db->buf_pool_ptr, db->buf_pool_dma_ptr); 511 db->buf_pool_ptr, db->buf_pool_dma_ptr);
490 unregister_netdev(dev);
491 pci_release_regions(pdev); 512 pci_release_regions(pdev);
492 free_netdev(dev); /* free board information */ 513 free_netdev(dev); /* free board information */
514
493 pci_set_drvdata(pdev, NULL); 515 pci_set_drvdata(pdev, NULL);
494 } 516 }
495 517
@@ -509,7 +531,8 @@ static int dmfe_open(struct DEVICE *dev)
509 531
510 DMFE_DBUG(0, "dmfe_open", 0); 532 DMFE_DBUG(0, "dmfe_open", 0);
511 533
512 ret = request_irq(dev->irq, &dmfe_interrupt, IRQF_SHARED, dev->name, dev); 534 ret = request_irq(dev->irq, &dmfe_interrupt,
535 IRQF_SHARED, dev->name, dev);
513 if (ret) 536 if (ret)
514 return ret; 537 return ret;
515 538
@@ -518,7 +541,6 @@ static int dmfe_open(struct DEVICE *dev)
518 db->tx_packet_cnt = 0; 541 db->tx_packet_cnt = 0;
519 db->tx_queue_cnt = 0; 542 db->tx_queue_cnt = 0;
520 db->rx_avail_cnt = 0; 543 db->rx_avail_cnt = 0;
521 db->link_failed = 1;
522 db->wait_reset = 0; 544 db->wait_reset = 0;
523 545
524 db->first_in_callback = 0; 546 db->first_in_callback = 0;
@@ -650,7 +672,8 @@ static int dmfe_start_xmit(struct sk_buff *skb, struct DEVICE *dev)
650 /* No Tx resource check, it never happen nromally */ 672 /* No Tx resource check, it never happen nromally */
651 if (db->tx_queue_cnt >= TX_FREE_DESC_CNT) { 673 if (db->tx_queue_cnt >= TX_FREE_DESC_CNT) {
652 spin_unlock_irqrestore(&db->lock, flags); 674 spin_unlock_irqrestore(&db->lock, flags);
653 printk(KERN_ERR DRV_NAME ": No Tx resource %ld\n", db->tx_queue_cnt); 675 printk(KERN_ERR DRV_NAME ": No Tx resource %ld\n",
676 db->tx_queue_cnt);
654 return 1; 677 return 1;
655 } 678 }
656 679
@@ -722,7 +745,8 @@ static int dmfe_stop(struct DEVICE *dev)
722 745
723#if 0 746#if 0
724 /* show statistic counter */ 747 /* show statistic counter */
725 printk(DRV_NAME ": FU:%lx EC:%lx LC:%lx NC:%lx LOC:%lx TXJT:%lx RESET:%lx RCR8:%lx FAL:%lx TT:%lx\n", 748 printk(DRV_NAME ": FU:%lx EC:%lx LC:%lx NC:%lx"
749 " LOC:%lx TXJT:%lx RESET:%lx RCR8:%lx FAL:%lx TT:%lx\n",
726 db->tx_fifo_underrun, db->tx_excessive_collision, 750 db->tx_fifo_underrun, db->tx_excessive_collision,
727 db->tx_late_collision, db->tx_no_carrier, db->tx_loss_carrier, 751 db->tx_late_collision, db->tx_no_carrier, db->tx_loss_carrier,
728 db->tx_jabber_timeout, db->reset_count, db->reset_cr8, 752 db->tx_jabber_timeout, db->reset_count, db->reset_cr8,
@@ -905,7 +929,7 @@ static inline u32 cal_CRC(unsigned char * Data, unsigned int Len, u8 flag)
905static void dmfe_rx_packet(struct DEVICE *dev, struct dmfe_board_info * db) 929static void dmfe_rx_packet(struct DEVICE *dev, struct dmfe_board_info * db)
906{ 930{
907 struct rx_desc *rxptr; 931 struct rx_desc *rxptr;
908 struct sk_buff *skb; 932 struct sk_buff *skb, *newskb;
909 int rxlen; 933 int rxlen;
910 u32 rdes0; 934 u32 rdes0;
911 935
@@ -919,7 +943,9 @@ static void dmfe_rx_packet(struct DEVICE *dev, struct dmfe_board_info * db)
919 db->rx_avail_cnt--; 943 db->rx_avail_cnt--;
920 db->interval_rx_cnt++; 944 db->interval_rx_cnt++;
921 945
922 pci_unmap_single(db->pdev, le32_to_cpu(rxptr->rdes2), RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE); 946 pci_unmap_single(db->pdev, le32_to_cpu(rxptr->rdes2),
947 RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE);
948
923 if ( (rdes0 & 0x300) != 0x300) { 949 if ( (rdes0 & 0x300) != 0x300) {
924 /* A packet without First/Last flag */ 950 /* A packet without First/Last flag */
925 /* reuse this SKB */ 951 /* reuse this SKB */
@@ -956,9 +982,11 @@ static void dmfe_rx_packet(struct DEVICE *dev, struct dmfe_board_info * db)
956 } else { 982 } else {
957 /* Good packet, send to upper layer */ 983 /* Good packet, send to upper layer */
958 /* Shorst packet used new SKB */ 984 /* Shorst packet used new SKB */
959 if ( (rxlen < RX_COPY_SIZE) && 985 if ((rxlen < RX_COPY_SIZE) &&
960 ( (skb = dev_alloc_skb(rxlen + 2) ) 986 ((newskb = dev_alloc_skb(rxlen + 2))
961 != NULL) ) { 987 != NULL)) {
988
989 skb = newskb;
962 /* size less than COPY_SIZE, allocate a rxlen SKB */ 990 /* size less than COPY_SIZE, allocate a rxlen SKB */
963 skb->dev = dev; 991 skb->dev = dev;
964 skb_reserve(skb, 2); /* 16byte align */ 992 skb_reserve(skb, 2); /* 16byte align */
@@ -1069,6 +1097,8 @@ static void dmfe_timer(unsigned long data)
1069 struct dmfe_board_info *db = netdev_priv(dev); 1097 struct dmfe_board_info *db = netdev_priv(dev);
1070 unsigned long flags; 1098 unsigned long flags;
1071 1099
1100 int link_ok, link_ok_phy;
1101
1072 DMFE_DBUG(0, "dmfe_timer()", 0); 1102 DMFE_DBUG(0, "dmfe_timer()", 0);
1073 spin_lock_irqsave(&db->lock, flags); 1103 spin_lock_irqsave(&db->lock, flags);
1074 1104
@@ -1078,7 +1108,8 @@ static void dmfe_timer(unsigned long data)
1078 if (db->chip_type && (db->chip_id==PCI_DM9102_ID)) { 1108 if (db->chip_type && (db->chip_id==PCI_DM9102_ID)) {
1079 db->cr6_data &= ~0x40000; 1109 db->cr6_data &= ~0x40000;
1080 update_cr6(db->cr6_data, db->ioaddr); 1110 update_cr6(db->cr6_data, db->ioaddr);
1081 phy_write(db->ioaddr, db->phy_addr, 0, 0x1000, db->chip_id); 1111 phy_write(db->ioaddr,
1112 db->phy_addr, 0, 0x1000, db->chip_id);
1082 db->cr6_data |= 0x40000; 1113 db->cr6_data |= 0x40000;
1083 update_cr6(db->cr6_data, db->ioaddr); 1114 update_cr6(db->cr6_data, db->ioaddr);
1084 db->timer.expires = DMFE_TIMER_WUT + HZ * 2; 1115 db->timer.expires = DMFE_TIMER_WUT + HZ * 2;
@@ -1139,21 +1170,41 @@ static void dmfe_timer(unsigned long data)
1139 (db->chip_revision == 0x02000010)) ) { 1170 (db->chip_revision == 0x02000010)) ) {
1140 /* DM9102A Chip */ 1171 /* DM9102A Chip */
1141 if (tmp_cr12 & 2) 1172 if (tmp_cr12 & 2)
1142 tmp_cr12 = 0x0; /* Link failed */ 1173 link_ok = 0;
1143 else 1174 else
1144 tmp_cr12 = 0x3; /* Link OK */ 1175 link_ok = 1;
1145 } 1176 }
1177 else
1178 /*0x43 is used instead of 0x3 because bit 6 should represent
1179 link status of external PHY */
1180 link_ok = (tmp_cr12 & 0x43) ? 1 : 0;
1181
1182
1183 /* If chip reports that link is failed it could be because external
1184 PHY link status pin is not conected correctly to chip
1185 To be sure ask PHY too.
1186 */
1187
1188 /* need a dummy read because of PHY's register latch*/
1189 phy_read (db->ioaddr, db->phy_addr, 1, db->chip_id);
1190 link_ok_phy = (phy_read (db->ioaddr,
1191 db->phy_addr, 1, db->chip_id) & 0x4) ? 1 : 0;
1146 1192
1147 if ( !(tmp_cr12 & 0x3) && !db->link_failed ) { 1193 if (link_ok_phy != link_ok) {
1194 DMFE_DBUG (0, "PHY and chip report different link status", 0);
1195 link_ok = link_ok | link_ok_phy;
1196 }
1197
1198 if ( !link_ok && netif_carrier_ok(dev)) {
1148 /* Link Failed */ 1199 /* Link Failed */
1149 DMFE_DBUG(0, "Link Failed", tmp_cr12); 1200 DMFE_DBUG(0, "Link Failed", tmp_cr12);
1150 db->link_failed = 1; 1201 netif_carrier_off(dev);
1151 netif_carrier_off(db->dev);
1152 1202
1153 /* For Force 10/100M Half/Full mode: Enable Auto-Nego mode */ 1203 /* For Force 10/100M Half/Full mode: Enable Auto-Nego mode */
1154 /* AUTO or force 1M Homerun/Longrun don't need */ 1204 /* AUTO or force 1M Homerun/Longrun don't need */
1155 if ( !(db->media_mode & 0x38) ) 1205 if ( !(db->media_mode & 0x38) )
1156 phy_write(db->ioaddr, db->phy_addr, 0, 0x1000, db->chip_id); 1206 phy_write(db->ioaddr, db->phy_addr,
1207 0, 0x1000, db->chip_id);
1157 1208
1158 /* AUTO mode, if INT phyxcer link failed, select EXT device */ 1209 /* AUTO mode, if INT phyxcer link failed, select EXT device */
1159 if (db->media_mode & DMFE_AUTO) { 1210 if (db->media_mode & DMFE_AUTO) {
@@ -1162,21 +1213,19 @@ static void dmfe_timer(unsigned long data)
1162 db->cr6_data&=~0x00000200; /* bit9=0, HD mode */ 1213 db->cr6_data&=~0x00000200; /* bit9=0, HD mode */
1163 update_cr6(db->cr6_data, db->ioaddr); 1214 update_cr6(db->cr6_data, db->ioaddr);
1164 } 1215 }
1165 } else 1216 } else if (!netif_carrier_ok(dev)) {
1166 if ((tmp_cr12 & 0x3) && db->link_failed) { 1217
1167 DMFE_DBUG(0, "Link link OK", tmp_cr12); 1218 DMFE_DBUG(0, "Link link OK", tmp_cr12);
1168 db->link_failed = 0; 1219
1169 1220 /* Auto Sense Speed */
1170 /* Auto Sense Speed */ 1221 if ( !(db->media_mode & DMFE_AUTO) || !dmfe_sense_speed(db)) {
1171 if ( (db->media_mode & DMFE_AUTO) && 1222 netif_carrier_on(dev);
1172 dmfe_sense_speed(db) ) 1223 SHOW_MEDIA_TYPE(db->op_mode);
1173 db->link_failed = 1;
1174 else
1175 netif_carrier_on(db->dev);
1176 dmfe_process_mode(db);
1177 /* SHOW_MEDIA_TYPE(db->op_mode); */
1178 } 1224 }
1179 1225
1226 dmfe_process_mode(db);
1227 }
1228
1180 /* HPNA remote command check */ 1229 /* HPNA remote command check */
1181 if (db->HPNA_command & 0xf00) { 1230 if (db->HPNA_command & 0xf00) {
1182 db->HPNA_timer--; 1231 db->HPNA_timer--;
@@ -1221,7 +1270,7 @@ static void dmfe_dynamic_reset(struct DEVICE *dev)
1221 db->tx_packet_cnt = 0; 1270 db->tx_packet_cnt = 0;
1222 db->tx_queue_cnt = 0; 1271 db->tx_queue_cnt = 0;
1223 db->rx_avail_cnt = 0; 1272 db->rx_avail_cnt = 0;
1224 db->link_failed = 1; 1273 netif_carrier_off(dev);
1225 db->wait_reset = 0; 1274 db->wait_reset = 0;
1226 1275
1227 /* Re-initilize DM910X board */ 1276 /* Re-initilize DM910X board */
@@ -1259,7 +1308,8 @@ static void dmfe_reuse_skb(struct dmfe_board_info *db, struct sk_buff * skb)
1259 1308
1260 if (!(rxptr->rdes0 & cpu_to_le32(0x80000000))) { 1309 if (!(rxptr->rdes0 & cpu_to_le32(0x80000000))) {
1261 rxptr->rx_skb_ptr = skb; 1310 rxptr->rx_skb_ptr = skb;
1262 rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev, skb->data, RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) ); 1311 rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev,
1312 skb->data, RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) );
1263 wmb(); 1313 wmb();
1264 rxptr->rdes0 = cpu_to_le32(0x80000000); 1314 rxptr->rdes0 = cpu_to_le32(0x80000000);
1265 db->rx_avail_cnt++; 1315 db->rx_avail_cnt++;
@@ -1291,8 +1341,11 @@ static void dmfe_descriptor_init(struct dmfe_board_info *db, unsigned long ioadd
1291 outl(db->first_tx_desc_dma, ioaddr + DCR4); /* TX DESC address */ 1341 outl(db->first_tx_desc_dma, ioaddr + DCR4); /* TX DESC address */
1292 1342
1293 /* rx descriptor start pointer */ 1343 /* rx descriptor start pointer */
1294 db->first_rx_desc = (void *)db->first_tx_desc + sizeof(struct tx_desc) * TX_DESC_CNT; 1344 db->first_rx_desc = (void *)db->first_tx_desc +
1295 db->first_rx_desc_dma = db->first_tx_desc_dma + sizeof(struct tx_desc) * TX_DESC_CNT; 1345 sizeof(struct tx_desc) * TX_DESC_CNT;
1346
1347 db->first_rx_desc_dma = db->first_tx_desc_dma +
1348 sizeof(struct tx_desc) * TX_DESC_CNT;
1296 db->rx_insert_ptr = db->first_rx_desc; 1349 db->rx_insert_ptr = db->first_rx_desc;
1297 db->rx_ready_ptr = db->first_rx_desc; 1350 db->rx_ready_ptr = db->first_rx_desc;
1298 outl(db->first_rx_desc_dma, ioaddr + DCR3); /* RX DESC address */ 1351 outl(db->first_rx_desc_dma, ioaddr + DCR3); /* RX DESC address */
@@ -1470,7 +1523,8 @@ static void allocate_rx_buffer(struct dmfe_board_info *db)
1470 if ( ( skb = dev_alloc_skb(RX_ALLOC_SIZE) ) == NULL ) 1523 if ( ( skb = dev_alloc_skb(RX_ALLOC_SIZE) ) == NULL )
1471 break; 1524 break;
1472 rxptr->rx_skb_ptr = skb; /* FIXME (?) */ 1525 rxptr->rx_skb_ptr = skb; /* FIXME (?) */
1473 rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev, skb->data, RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) ); 1526 rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev, skb->data,
1527 RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) );
1474 wmb(); 1528 wmb();
1475 rxptr->rdes0 = cpu_to_le32(0x80000000); 1529 rxptr->rdes0 = cpu_to_le32(0x80000000);
1476 rxptr = rxptr->next_rx_desc; 1530 rxptr = rxptr->next_rx_desc;
@@ -1510,7 +1564,8 @@ static u16 read_srom_word(long ioaddr, int offset)
1510 for (i = 16; i > 0; i--) { 1564 for (i = 16; i > 0; i--) {
1511 outl(CR9_SROM_READ | CR9_SRCS | CR9_SRCLK, cr9_ioaddr); 1565 outl(CR9_SROM_READ | CR9_SRCS | CR9_SRCLK, cr9_ioaddr);
1512 udelay(5); 1566 udelay(5);
1513 srom_data = (srom_data << 1) | ((inl(cr9_ioaddr) & CR9_CRDOUT) ? 1 : 0); 1567 srom_data = (srom_data << 1) |
1568 ((inl(cr9_ioaddr) & CR9_CRDOUT) ? 1 : 0);
1514 outl(CR9_SROM_READ | CR9_SRCS, cr9_ioaddr); 1569 outl(CR9_SROM_READ | CR9_SRCS, cr9_ioaddr);
1515 udelay(5); 1570 udelay(5);
1516 } 1571 }
@@ -1537,9 +1592,11 @@ static u8 dmfe_sense_speed(struct dmfe_board_info * db)
1537 1592
1538 if ( (phy_mode & 0x24) == 0x24 ) { 1593 if ( (phy_mode & 0x24) == 0x24 ) {
1539 if (db->chip_id == PCI_DM9132_ID) /* DM9132 */ 1594 if (db->chip_id == PCI_DM9132_ID) /* DM9132 */
1540 phy_mode = phy_read(db->ioaddr, db->phy_addr, 7, db->chip_id) & 0xf000; 1595 phy_mode = phy_read(db->ioaddr,
1596 db->phy_addr, 7, db->chip_id) & 0xf000;
1541 else /* DM9102/DM9102A */ 1597 else /* DM9102/DM9102A */
1542 phy_mode = phy_read(db->ioaddr, db->phy_addr, 17, db->chip_id) & 0xf000; 1598 phy_mode = phy_read(db->ioaddr,
1599 db->phy_addr, 17, db->chip_id) & 0xf000;
1543 /* printk(DRV_NAME ": Phy_mode %x ",phy_mode); */ 1600 /* printk(DRV_NAME ": Phy_mode %x ",phy_mode); */
1544 switch (phy_mode) { 1601 switch (phy_mode) {
1545 case 0x1000: db->op_mode = DMFE_10MHF; break; 1602 case 0x1000: db->op_mode = DMFE_10MHF; break;
@@ -1576,8 +1633,11 @@ static void dmfe_set_phyxcer(struct dmfe_board_info *db)
1576 1633
1577 /* DM9009 Chip: Phyxcer reg18 bit12=0 */ 1634 /* DM9009 Chip: Phyxcer reg18 bit12=0 */
1578 if (db->chip_id == PCI_DM9009_ID) { 1635 if (db->chip_id == PCI_DM9009_ID) {
1579 phy_reg = phy_read(db->ioaddr, db->phy_addr, 18, db->chip_id) & ~0x1000; 1636 phy_reg = phy_read(db->ioaddr,
1580 phy_write(db->ioaddr, db->phy_addr, 18, phy_reg, db->chip_id); 1637 db->phy_addr, 18, db->chip_id) & ~0x1000;
1638
1639 phy_write(db->ioaddr,
1640 db->phy_addr, 18, phy_reg, db->chip_id);
1581 } 1641 }
1582 1642
1583 /* Phyxcer capability setting */ 1643 /* Phyxcer capability setting */
@@ -1650,10 +1710,12 @@ static void dmfe_process_mode(struct dmfe_board_info *db)
1650 case DMFE_100MHF: phy_reg = 0x2000; break; 1710 case DMFE_100MHF: phy_reg = 0x2000; break;
1651 case DMFE_100MFD: phy_reg = 0x2100; break; 1711 case DMFE_100MFD: phy_reg = 0x2100; break;
1652 } 1712 }
1653 phy_write(db->ioaddr, db->phy_addr, 0, phy_reg, db->chip_id); 1713 phy_write(db->ioaddr,
1714 db->phy_addr, 0, phy_reg, db->chip_id);
1654 if ( db->chip_type && (db->chip_id == PCI_DM9102_ID) ) 1715 if ( db->chip_type && (db->chip_id == PCI_DM9102_ID) )
1655 mdelay(20); 1716 mdelay(20);
1656 phy_write(db->ioaddr, db->phy_addr, 0, phy_reg, db->chip_id); 1717 phy_write(db->ioaddr,
1718 db->phy_addr, 0, phy_reg, db->chip_id);
1657 } 1719 }
1658 } 1720 }
1659} 1721}
@@ -1663,7 +1725,8 @@ static void dmfe_process_mode(struct dmfe_board_info *db)
1663 * Write a word to Phy register 1725 * Write a word to Phy register
1664 */ 1726 */
1665 1727
1666static void phy_write(unsigned long iobase, u8 phy_addr, u8 offset, u16 phy_data, u32 chip_id) 1728static void phy_write(unsigned long iobase, u8 phy_addr, u8 offset,
1729 u16 phy_data, u32 chip_id)
1667{ 1730{
1668 u16 i; 1731 u16 i;
1669 unsigned long ioaddr; 1732 unsigned long ioaddr;
@@ -1689,11 +1752,13 @@ static void phy_write(unsigned long iobase, u8 phy_addr, u8 offset, u16 phy_data
1689 1752
1690 /* Send Phy address */ 1753 /* Send Phy address */
1691 for (i = 0x10; i > 0; i = i >> 1) 1754 for (i = 0x10; i > 0; i = i >> 1)
1692 phy_write_1bit(ioaddr, phy_addr & i ? PHY_DATA_1 : PHY_DATA_0); 1755 phy_write_1bit(ioaddr,
1756 phy_addr & i ? PHY_DATA_1 : PHY_DATA_0);
1693 1757
1694 /* Send register address */ 1758 /* Send register address */
1695 for (i = 0x10; i > 0; i = i >> 1) 1759 for (i = 0x10; i > 0; i = i >> 1)
1696 phy_write_1bit(ioaddr, offset & i ? PHY_DATA_1 : PHY_DATA_0); 1760 phy_write_1bit(ioaddr,
1761 offset & i ? PHY_DATA_1 : PHY_DATA_0);
1697 1762
1698 /* written trasnition */ 1763 /* written trasnition */
1699 phy_write_1bit(ioaddr, PHY_DATA_1); 1764 phy_write_1bit(ioaddr, PHY_DATA_1);
@@ -1701,7 +1766,8 @@ static void phy_write(unsigned long iobase, u8 phy_addr, u8 offset, u16 phy_data
1701 1766
1702 /* Write a word data to PHY controller */ 1767 /* Write a word data to PHY controller */
1703 for ( i = 0x8000; i > 0; i >>= 1) 1768 for ( i = 0x8000; i > 0; i >>= 1)
1704 phy_write_1bit(ioaddr, phy_data & i ? PHY_DATA_1 : PHY_DATA_0); 1769 phy_write_1bit(ioaddr,
1770 phy_data & i ? PHY_DATA_1 : PHY_DATA_0);
1705 } 1771 }
1706} 1772}
1707 1773
@@ -1738,11 +1804,13 @@ static u16 phy_read(unsigned long iobase, u8 phy_addr, u8 offset, u32 chip_id)
1738 1804
1739 /* Send Phy address */ 1805 /* Send Phy address */
1740 for (i = 0x10; i > 0; i = i >> 1) 1806 for (i = 0x10; i > 0; i = i >> 1)
1741 phy_write_1bit(ioaddr, phy_addr & i ? PHY_DATA_1 : PHY_DATA_0); 1807 phy_write_1bit(ioaddr,
1808 phy_addr & i ? PHY_DATA_1 : PHY_DATA_0);
1742 1809
1743 /* Send register address */ 1810 /* Send register address */
1744 for (i = 0x10; i > 0; i = i >> 1) 1811 for (i = 0x10; i > 0; i = i >> 1)
1745 phy_write_1bit(ioaddr, offset & i ? PHY_DATA_1 : PHY_DATA_0); 1812 phy_write_1bit(ioaddr,
1813 offset & i ? PHY_DATA_1 : PHY_DATA_0);
1746 1814
1747 /* Skip transition state */ 1815 /* Skip transition state */
1748 phy_read_1bit(ioaddr); 1816 phy_read_1bit(ioaddr);
@@ -1963,7 +2031,8 @@ static void dmfe_HPNA_remote_cmd_chk(struct dmfe_board_info * db)
1963 2031
1964 /* Check remote device status match our setting ot not */ 2032 /* Check remote device status match our setting ot not */
1965 if ( phy_reg != (db->HPNA_command & 0x0f00) ) { 2033 if ( phy_reg != (db->HPNA_command & 0x0f00) ) {
1966 phy_write(db->ioaddr, db->phy_addr, 16, db->HPNA_command, db->chip_id); 2034 phy_write(db->ioaddr, db->phy_addr, 16, db->HPNA_command,
2035 db->chip_id);
1967 db->HPNA_timer=8; 2036 db->HPNA_timer=8;
1968 } else 2037 } else
1969 db->HPNA_timer=600; /* Match, every 10 minutes, check */ 2038 db->HPNA_timer=600; /* Match, every 10 minutes, check */
@@ -2003,8 +2072,11 @@ module_param(HPNA_tx_cmd, byte, 0);
2003module_param(HPNA_NoiseFloor, byte, 0); 2072module_param(HPNA_NoiseFloor, byte, 0);
2004module_param(SF_mode, byte, 0); 2073module_param(SF_mode, byte, 0);
2005MODULE_PARM_DESC(debug, "Davicom DM9xxx enable debugging (0-1)"); 2074MODULE_PARM_DESC(debug, "Davicom DM9xxx enable debugging (0-1)");
2006MODULE_PARM_DESC(mode, "Davicom DM9xxx: Bit 0: 10/100Mbps, bit 2: duplex, bit 8: HomePNA"); 2075MODULE_PARM_DESC(mode, "Davicom DM9xxx: "
2007MODULE_PARM_DESC(SF_mode, "Davicom DM9xxx special function (bit 0: VLAN, bit 1 Flow Control, bit 2: TX pause packet)"); 2076 "Bit 0: 10/100Mbps, bit 2: duplex, bit 8: HomePNA");
2077
2078MODULE_PARM_DESC(SF_mode, "Davicom DM9xxx special function "
2079 "(bit 0: VLAN, bit 1 Flow Control, bit 2: TX pause packet)");
2008 2080
2009/* Description: 2081/* Description:
2010 * when user used insmod to add module, system invoked init_module() 2082 * when user used insmod to add module, system invoked init_module()
diff --git a/drivers/net/tulip/tulip_core.c b/drivers/net/tulip/tulip_core.c
index 5a35354aa5..e3774a5223 100644
--- a/drivers/net/tulip/tulip_core.c
+++ b/drivers/net/tulip/tulip_core.c
@@ -67,7 +67,7 @@ const char * const medianame[32] = {
67 67
68/* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */ 68/* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */
69#if defined(__alpha__) || defined(__arm__) || defined(__hppa__) \ 69#if defined(__alpha__) || defined(__arm__) || defined(__hppa__) \
70 || defined(__sparc_) || defined(__ia64__) \ 70 || defined(__sparc__) || defined(__ia64__) \
71 || defined(__sh__) || defined(__mips__) 71 || defined(__sh__) || defined(__mips__)
72static int rx_copybreak = 1518; 72static int rx_copybreak = 1518;
73#else 73#else
diff --git a/drivers/net/typhoon.c b/drivers/net/typhoon.c
index 9781b16bb8..0d91d094ed 100644
--- a/drivers/net/typhoon.c
+++ b/drivers/net/typhoon.c
@@ -746,8 +746,7 @@ typhoon_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
746{ 746{
747 struct typhoon *tp = netdev_priv(dev); 747 struct typhoon *tp = netdev_priv(dev);
748 spin_lock_bh(&tp->state_lock); 748 spin_lock_bh(&tp->state_lock);
749 if(tp->vlgrp) 749 vlan_group_set_device(tp->vlgrp, vid, NULL);
750 tp->vlgrp->vlan_devices[vid] = NULL;
751 spin_unlock_bh(&tp->state_lock); 750 spin_unlock_bh(&tp->state_lock);
752} 751}
753 752
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index a2fc2bbcf9..dab88b958d 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -3598,17 +3598,20 @@ static int ucc_geth_start_xmit(struct sk_buff *skb, struct net_device *dev)
3598 3598
3599 /* Move to next BD in the ring */ 3599 /* Move to next BD in the ring */
3600 if (!(bd_status & T_W)) 3600 if (!(bd_status & T_W))
3601 ugeth->txBd[txQ] = bd + sizeof(struct qe_bd); 3601 bd += sizeof(struct qe_bd);
3602 else 3602 else
3603 ugeth->txBd[txQ] = ugeth->p_tx_bd_ring[txQ]; 3603 bd = ugeth->p_tx_bd_ring[txQ];
3604 3604
3605 /* If the next BD still needs to be cleaned up, then the bds 3605 /* If the next BD still needs to be cleaned up, then the bds
3606 are full. We need to tell the kernel to stop sending us stuff. */ 3606 are full. We need to tell the kernel to stop sending us stuff. */
3607 if (bd == ugeth->confBd[txQ]) { 3607 if (bd == ugeth->confBd[txQ]) {
3608 if (!netif_queue_stopped(dev)) 3608 if (!netif_queue_stopped(dev))
3609 netif_stop_queue(dev); 3609 netif_stop_queue(dev);
3610 return NETDEV_TX_BUSY;
3610 } 3611 }
3611 3612
3613 ugeth->txBd[txQ] = bd;
3614
3612 if (ugeth->p_scheduler) { 3615 if (ugeth->p_scheduler) {
3613 ugeth->cpucount[txQ]++; 3616 ugeth->cpucount[txQ]++;
3614 /* Indicate to QE that there are more Tx bds ready for 3617 /* Indicate to QE that there are more Tx bds ready for
@@ -3620,7 +3623,7 @@ static int ucc_geth_start_xmit(struct sk_buff *skb, struct net_device *dev)
3620 3623
3621 spin_unlock_irq(&ugeth->lock); 3624 spin_unlock_irq(&ugeth->lock);
3622 3625
3623 return 0; 3626 return NETDEV_TX_OK;
3624} 3627}
3625 3628
3626static int ucc_geth_rx(struct ucc_geth_private *ugeth, u8 rxQ, int rx_work_limit) 3629static int ucc_geth_rx(struct ucc_geth_private *ugeth, u8 rxQ, int rx_work_limit)
@@ -3722,7 +3725,7 @@ static int ucc_geth_tx(struct net_device *dev, u8 txQ)
3722 /* Handle the transmitted buffer and release */ 3725 /* Handle the transmitted buffer and release */
3723 /* the BD to be used with the current frame */ 3726 /* the BD to be used with the current frame */
3724 3727
3725 if ((bd = ugeth->txBd[txQ]) && (netif_queue_stopped(dev) == 0)) 3728 if ((bd == ugeth->txBd[txQ]) && (netif_queue_stopped(dev) == 0))
3726 break; 3729 break;
3727 3730
3728 ugeth->stats.tx_packets++; 3731 ugeth->stats.tx_packets++;
@@ -3741,10 +3744,12 @@ static int ucc_geth_tx(struct net_device *dev, u8 txQ)
3741 3744
3742 /* Advance the confirmation BD pointer */ 3745 /* Advance the confirmation BD pointer */
3743 if (!(bd_status & T_W)) 3746 if (!(bd_status & T_W))
3744 ugeth->confBd[txQ] += sizeof(struct qe_bd); 3747 bd += sizeof(struct qe_bd);
3745 else 3748 else
3746 ugeth->confBd[txQ] = ugeth->p_tx_bd_ring[txQ]; 3749 bd = ugeth->p_tx_bd_ring[txQ];
3750 bd_status = in_be32((u32 *)bd);
3747 } 3751 }
3752 ugeth->confBd[txQ] = bd;
3748 return 0; 3753 return 0;
3749} 3754}
3750 3755
@@ -4199,9 +4204,7 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma
4199 ugeth->ug_info = ug_info; 4204 ugeth->ug_info = ug_info;
4200 ugeth->dev = dev; 4205 ugeth->dev = dev;
4201 4206
4202 mac_addr = get_property(np, "mac-address", NULL); 4207 mac_addr = of_get_mac_address(np);
4203 if (mac_addr == NULL)
4204 mac_addr = get_property(np, "local-mac-address", NULL);
4205 if (mac_addr) 4208 if (mac_addr)
4206 memcpy(dev->dev_addr, mac_addr, 6); 4209 memcpy(dev->dev_addr, mac_addr, 6);
4207 4210
diff --git a/drivers/net/via-rhine.c b/drivers/net/via-rhine.c
index ebbda1d8f5..f3a972e74e 100644
--- a/drivers/net/via-rhine.c
+++ b/drivers/net/via-rhine.c
@@ -30,8 +30,8 @@
30*/ 30*/
31 31
32#define DRV_NAME "via-rhine" 32#define DRV_NAME "via-rhine"
33#define DRV_VERSION "1.4.2" 33#define DRV_VERSION "1.4.3"
34#define DRV_RELDATE "Sept-11-2006" 34#define DRV_RELDATE "2007-03-06"
35 35
36 36
37/* A few user-configurable values. 37/* A few user-configurable values.
@@ -105,6 +105,7 @@ static const int multicast_filter_limit = 32;
105#include <asm/io.h> 105#include <asm/io.h>
106#include <asm/irq.h> 106#include <asm/irq.h>
107#include <asm/uaccess.h> 107#include <asm/uaccess.h>
108#include <linux/dmi.h>
108 109
109/* These identify the driver base version and may not be removed. */ 110/* These identify the driver base version and may not be removed. */
110static char version[] __devinitdata = 111static char version[] __devinitdata =
@@ -1995,6 +1996,23 @@ static struct pci_driver rhine_driver = {
1995 .shutdown = rhine_shutdown, 1996 .shutdown = rhine_shutdown,
1996}; 1997};
1997 1998
1999static struct dmi_system_id __initdata rhine_dmi_table[] = {
2000 {
2001 .ident = "EPIA-M",
2002 .matches = {
2003 DMI_MATCH(DMI_BIOS_VENDOR, "Award Software International, Inc."),
2004 DMI_MATCH(DMI_BIOS_VERSION, "6.00 PG"),
2005 },
2006 },
2007 {
2008 .ident = "KV7",
2009 .matches = {
2010 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies, LTD"),
2011 DMI_MATCH(DMI_BIOS_VERSION, "6.00 PG"),
2012 },
2013 },
2014 { NULL }
2015};
1998 2016
1999static int __init rhine_init(void) 2017static int __init rhine_init(void)
2000{ 2018{
@@ -2002,6 +2020,16 @@ static int __init rhine_init(void)
2002#ifdef MODULE 2020#ifdef MODULE
2003 printk(version); 2021 printk(version);
2004#endif 2022#endif
2023 if (dmi_check_system(rhine_dmi_table)) {
2024 /* these BIOSes fail at PXE boot if chip is in D3 */
2025 avoid_D3 = 1;
2026 printk(KERN_WARNING "%s: Broken BIOS detected, avoid_D3 "
2027 "enabled.\n",
2028 DRV_NAME);
2029 }
2030 else if (avoid_D3)
2031 printk(KERN_INFO "%s: avoid_D3 set.\n", DRV_NAME);
2032
2005 return pci_register_driver(&rhine_driver); 2033 return pci_register_driver(&rhine_driver);
2006} 2034}
2007 2035
diff --git a/drivers/net/wan/Kconfig b/drivers/net/wan/Kconfig
index 61708cf4c8..8897f538a7 100644
--- a/drivers/net/wan/Kconfig
+++ b/drivers/net/wan/Kconfig
@@ -26,7 +26,7 @@ config WAN
26# There is no way to detect a comtrol sv11 - force it modular for now. 26# There is no way to detect a comtrol sv11 - force it modular for now.
27config HOSTESS_SV11 27config HOSTESS_SV11
28 tristate "Comtrol Hostess SV-11 support" 28 tristate "Comtrol Hostess SV-11 support"
29 depends on WAN && ISA && m && ISA_DMA_API 29 depends on WAN && ISA && m && ISA_DMA_API && INET
30 help 30 help
31 Driver for Comtrol Hostess SV-11 network card which 31 Driver for Comtrol Hostess SV-11 network card which
32 operates on low speed synchronous serial links at up to 32 operates on low speed synchronous serial links at up to
diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
index e91b5a84a2..5b82e4fd0d 100644
--- a/drivers/net/wan/cosa.c
+++ b/drivers/net/wan/cosa.c
@@ -94,7 +94,6 @@
94#include <linux/device.h> 94#include <linux/device.h>
95 95
96#undef COSA_SLOW_IO /* for testing purposes only */ 96#undef COSA_SLOW_IO /* for testing purposes only */
97#undef REALLY_SLOW_IO
98 97
99#include <asm/io.h> 98#include <asm/io.h>
100#include <asm/dma.h> 99#include <asm/dma.h>
diff --git a/drivers/net/wan/hdlc.c b/drivers/net/wan/hdlc.c
index 9040d7cf65..65ad2e24ca 100644
--- a/drivers/net/wan/hdlc.c
+++ b/drivers/net/wan/hdlc.c
@@ -38,7 +38,7 @@
38#include <linux/hdlc.h> 38#include <linux/hdlc.h>
39 39
40 40
41static const char* version = "HDLC support module revision 1.20"; 41static const char* version = "HDLC support module revision 1.21";
42 42
43#undef DEBUG_LINK 43#undef DEBUG_LINK
44 44
@@ -222,19 +222,31 @@ int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
222 return -EINVAL; 222 return -EINVAL;
223} 223}
224 224
225static void hdlc_setup_dev(struct net_device *dev)
226{
227 /* Re-init all variables changed by HDLC protocol drivers,
228 * including ether_setup() called from hdlc_raw_eth.c.
229 */
230 dev->get_stats = hdlc_get_stats;
231 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
232 dev->mtu = HDLC_MAX_MTU;
233 dev->type = ARPHRD_RAWHDLC;
234 dev->hard_header_len = 16;
235 dev->addr_len = 0;
236 dev->hard_header = NULL;
237 dev->rebuild_header = NULL;
238 dev->set_mac_address = NULL;
239 dev->hard_header_cache = NULL;
240 dev->header_cache_update = NULL;
241 dev->change_mtu = hdlc_change_mtu;
242 dev->hard_header_parse = NULL;
243}
244
225static void hdlc_setup(struct net_device *dev) 245static void hdlc_setup(struct net_device *dev)
226{ 246{
227 hdlc_device *hdlc = dev_to_hdlc(dev); 247 hdlc_device *hdlc = dev_to_hdlc(dev);
228 248
229 dev->get_stats = hdlc_get_stats; 249 hdlc_setup_dev(dev);
230 dev->change_mtu = hdlc_change_mtu;
231 dev->mtu = HDLC_MAX_MTU;
232
233 dev->type = ARPHRD_RAWHDLC;
234 dev->hard_header_len = 16;
235
236 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
237
238 hdlc->carrier = 1; 250 hdlc->carrier = 1;
239 hdlc->open = 0; 251 hdlc->open = 0;
240 spin_lock_init(&hdlc->state_lock); 252 spin_lock_init(&hdlc->state_lock);
@@ -294,6 +306,7 @@ void detach_hdlc_protocol(struct net_device *dev)
294 } 306 }
295 kfree(hdlc->state); 307 kfree(hdlc->state);
296 hdlc->state = NULL; 308 hdlc->state = NULL;
309 hdlc_setup_dev(dev);
297} 310}
298 311
299 312
diff --git a/drivers/net/wan/hdlc_cisco.c b/drivers/net/wan/hdlc_cisco.c
index b0bc5ddcf1..c9664fd8a9 100644
--- a/drivers/net/wan/hdlc_cisco.c
+++ b/drivers/net/wan/hdlc_cisco.c
@@ -365,10 +365,7 @@ static int cisco_ioctl(struct net_device *dev, struct ifreq *ifr)
365 memcpy(&state(hdlc)->settings, &new_settings, size); 365 memcpy(&state(hdlc)->settings, &new_settings, size);
366 dev->hard_start_xmit = hdlc->xmit; 366 dev->hard_start_xmit = hdlc->xmit;
367 dev->hard_header = cisco_hard_header; 367 dev->hard_header = cisco_hard_header;
368 dev->hard_header_cache = NULL;
369 dev->type = ARPHRD_CISCO; 368 dev->type = ARPHRD_CISCO;
370 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
371 dev->addr_len = 0;
372 netif_dormant_on(dev); 369 netif_dormant_on(dev);
373 return 0; 370 return 0;
374 } 371 }
diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c
index b45ab680d2..c6c3c757d6 100644
--- a/drivers/net/wan/hdlc_fr.c
+++ b/drivers/net/wan/hdlc_fr.c
@@ -1289,10 +1289,7 @@ static int fr_ioctl(struct net_device *dev, struct ifreq *ifr)
1289 memcpy(&state(hdlc)->settings, &new_settings, size); 1289 memcpy(&state(hdlc)->settings, &new_settings, size);
1290 1290
1291 dev->hard_start_xmit = hdlc->xmit; 1291 dev->hard_start_xmit = hdlc->xmit;
1292 dev->hard_header = NULL;
1293 dev->type = ARPHRD_FRAD; 1292 dev->type = ARPHRD_FRAD;
1294 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
1295 dev->addr_len = 0;
1296 return 0; 1293 return 0;
1297 1294
1298 case IF_PROTO_FR_ADD_PVC: 1295 case IF_PROTO_FR_ADD_PVC:
diff --git a/drivers/net/wan/hdlc_ppp.c b/drivers/net/wan/hdlc_ppp.c
index e9f717070f..4591437dd2 100644
--- a/drivers/net/wan/hdlc_ppp.c
+++ b/drivers/net/wan/hdlc_ppp.c
@@ -127,9 +127,7 @@ static int ppp_ioctl(struct net_device *dev, struct ifreq *ifr)
127 if (result) 127 if (result)
128 return result; 128 return result;
129 dev->hard_start_xmit = hdlc->xmit; 129 dev->hard_start_xmit = hdlc->xmit;
130 dev->hard_header = NULL;
131 dev->type = ARPHRD_PPP; 130 dev->type = ARPHRD_PPP;
132 dev->addr_len = 0;
133 netif_dormant_off(dev); 131 netif_dormant_off(dev);
134 return 0; 132 return 0;
135 } 133 }
diff --git a/drivers/net/wan/hdlc_raw.c b/drivers/net/wan/hdlc_raw.c
index fe3cae5c6b..e23bc66562 100644
--- a/drivers/net/wan/hdlc_raw.c
+++ b/drivers/net/wan/hdlc_raw.c
@@ -88,10 +88,7 @@ static int raw_ioctl(struct net_device *dev, struct ifreq *ifr)
88 return result; 88 return result;
89 memcpy(hdlc->state, &new_settings, size); 89 memcpy(hdlc->state, &new_settings, size);
90 dev->hard_start_xmit = hdlc->xmit; 90 dev->hard_start_xmit = hdlc->xmit;
91 dev->hard_header = NULL;
92 dev->type = ARPHRD_RAWHDLC; 91 dev->type = ARPHRD_RAWHDLC;
93 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
94 dev->addr_len = 0;
95 netif_dormant_off(dev); 92 netif_dormant_off(dev);
96 return 0; 93 return 0;
97 } 94 }
diff --git a/drivers/net/wan/hdlc_x25.c b/drivers/net/wan/hdlc_x25.c
index e4bb9f8ad4..cd7b22f50e 100644
--- a/drivers/net/wan/hdlc_x25.c
+++ b/drivers/net/wan/hdlc_x25.c
@@ -215,9 +215,7 @@ static int x25_ioctl(struct net_device *dev, struct ifreq *ifr)
215 x25_rx, 0)) != 0) 215 x25_rx, 0)) != 0)
216 return result; 216 return result;
217 dev->hard_start_xmit = x25_xmit; 217 dev->hard_start_xmit = x25_xmit;
218 dev->hard_header = NULL;
219 dev->type = ARPHRD_X25; 218 dev->type = ARPHRD_X25;
220 dev->addr_len = 0;
221 netif_dormant_off(dev); 219 netif_dormant_off(dev);
222 return 0; 220 return 0;
223 } 221 }
diff --git a/drivers/net/wan/pc300too.c b/drivers/net/wan/pc300too.c
index bc156b5167..aff05dba72 100644
--- a/drivers/net/wan/pc300too.c
+++ b/drivers/net/wan/pc300too.c
@@ -542,7 +542,7 @@ static int __init pc300_init_module(void)
542 542
543 CLOCK_BASE = use_crystal_clock ? 24576000 : pci_clock_freq; 543 CLOCK_BASE = use_crystal_clock ? 24576000 : pci_clock_freq;
544 544
545 return pci_module_init(&pc300_pci_driver); 545 return pci_register_driver(&pc300_pci_driver);
546} 546}
547 547
548 548
diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
index 8dbcf83bb5..8b4540bfc1 100644
--- a/drivers/net/wan/z85230.c
+++ b/drivers/net/wan/z85230.c
@@ -407,7 +407,7 @@ static void z8530_tx(struct z8530_channel *c)
407 while(c->txcount) { 407 while(c->txcount) {
408 /* FIFO full ? */ 408 /* FIFO full ? */
409 if(!(read_zsreg(c, R0)&4)) 409 if(!(read_zsreg(c, R0)&4))
410 break; 410 return;
411 c->txcount--; 411 c->txcount--;
412 /* 412 /*
413 * Shovel out the byte 413 * Shovel out the byte
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index b08055abe8..a8c2bfe26c 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -1623,7 +1623,7 @@ static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
1623 1623
1624 crypto_cipher_setkey(tfm, pkey, 16); 1624 crypto_cipher_setkey(tfm, pkey, 16);
1625 counter = 0; 1625 counter = 0;
1626 for (i = 0; i < (sizeof(context->coeff)/sizeof(context->coeff[0])); ) { 1626 for (i = 0; i < ARRAY_SIZE(context->coeff); ) {
1627 aes_counter[15] = (u8)(counter >> 0); 1627 aes_counter[15] = (u8)(counter >> 0);
1628 aes_counter[14] = (u8)(counter >> 8); 1628 aes_counter[14] = (u8)(counter >> 8);
1629 aes_counter[13] = (u8)(counter >> 16); 1629 aes_counter[13] = (u8)(counter >> 16);
@@ -1632,7 +1632,7 @@ static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
1632 memcpy (plain, aes_counter, 16); 1632 memcpy (plain, aes_counter, 16);
1633 crypto_cipher_encrypt_one(tfm, plain, plain); 1633 crypto_cipher_encrypt_one(tfm, plain, plain);
1634 cipher = plain; 1634 cipher = plain;
1635 for (j=0; (j<16) && (i< (sizeof(context->coeff)/sizeof(context->coeff[0]))); ) { 1635 for (j = 0; (j < 16) && (i < ARRAY_SIZE(context->coeff)); ) {
1636 context->coeff[i++] = ntohl(*(u32 *)&cipher[j]); 1636 context->coeff[i++] = ntohl(*(u32 *)&cipher[j]);
1637 j += 4; 1637 j += 4;
1638 } 1638 }
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx.h b/drivers/net/wireless/bcm43xx/bcm43xx.h
index 3a064def16..95ff175d8f 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx.h
+++ b/drivers/net/wireless/bcm43xx/bcm43xx.h
@@ -21,7 +21,7 @@
21#define PFX KBUILD_MODNAME ": " 21#define PFX KBUILD_MODNAME ": "
22 22
23#define BCM43xx_SWITCH_CORE_MAX_RETRIES 50 23#define BCM43xx_SWITCH_CORE_MAX_RETRIES 50
24#define BCM43xx_IRQWAIT_MAX_RETRIES 50 24#define BCM43xx_IRQWAIT_MAX_RETRIES 100
25 25
26#define BCM43xx_IO_SIZE 8192 26#define BCM43xx_IO_SIZE 8192
27 27
@@ -333,7 +333,7 @@
333#define BCM43xx_SBF_PS2 0x04000000 333#define BCM43xx_SBF_PS2 0x04000000
334#define BCM43xx_SBF_NO_SSID_BCAST 0x08000000 334#define BCM43xx_SBF_NO_SSID_BCAST 0x08000000
335#define BCM43xx_SBF_TIME_UPDATE 0x10000000 335#define BCM43xx_SBF_TIME_UPDATE 0x10000000
336#define BCM43xx_SBF_80000000 0x80000000 /*FIXME: fix name*/ 336#define BCM43xx_SBF_MODE_G 0x80000000
337 337
338/* Microcode */ 338/* Microcode */
339#define BCM43xx_UCODE_REVISION 0x0000 339#define BCM43xx_UCODE_REVISION 0x0000
@@ -507,8 +507,6 @@ struct bcm43xx_sprominfo {
507 u8 et1macaddr[6]; 507 u8 et1macaddr[6];
508 u8 et0phyaddr:5; 508 u8 et0phyaddr:5;
509 u8 et1phyaddr:5; 509 u8 et1phyaddr:5;
510 u8 et0mdcport:1;
511 u8 et1mdcport:1;
512 u8 boardrev; 510 u8 boardrev;
513 u8 locale:4; 511 u8 locale:4;
514 u8 antennas_aphy:2; 512 u8 antennas_aphy:2;
@@ -542,7 +540,7 @@ struct bcm43xx_lopair {
542 540
543struct bcm43xx_phyinfo { 541struct bcm43xx_phyinfo {
544 /* Hardware Data */ 542 /* Hardware Data */
545 u8 version; 543 u8 analog;
546 u8 type; 544 u8 type;
547 u8 rev; 545 u8 rev;
548 u16 antenna_diversity; 546 u16 antenna_diversity;
@@ -771,6 +769,7 @@ struct bcm43xx_private {
771 * This is currently always BCM43xx_BUSTYPE_PCI 769 * This is currently always BCM43xx_BUSTYPE_PCI
772 */ 770 */
773 u8 bustype; 771 u8 bustype;
772 u64 dma_mask;
774 773
775 u16 board_vendor; 774 u16 board_vendor;
776 u16 board_type; 775 u16 board_type;
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_dma.c b/drivers/net/wireless/bcm43xx/bcm43xx_dma.c
index 978ed099e2..6e0dc76400 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_dma.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_dma.c
@@ -145,16 +145,14 @@ dma_addr_t map_descbuffer(struct bcm43xx_dmaring *ring,
145 int tx) 145 int tx)
146{ 146{
147 dma_addr_t dmaaddr; 147 dma_addr_t dmaaddr;
148 int direction = PCI_DMA_FROMDEVICE;
148 149
149 if (tx) { 150 if (tx)
150 dmaaddr = dma_map_single(&ring->bcm->pci_dev->dev, 151 direction = PCI_DMA_TODEVICE;
151 buf, len, 152
152 DMA_TO_DEVICE); 153 dmaaddr = pci_map_single(ring->bcm->pci_dev,
153 } else {
154 dmaaddr = dma_map_single(&ring->bcm->pci_dev->dev,
155 buf, len, 154 buf, len,
156 DMA_FROM_DEVICE); 155 direction);
157 }
158 156
159 return dmaaddr; 157 return dmaaddr;
160} 158}
@@ -166,13 +164,13 @@ void unmap_descbuffer(struct bcm43xx_dmaring *ring,
166 int tx) 164 int tx)
167{ 165{
168 if (tx) { 166 if (tx) {
169 dma_unmap_single(&ring->bcm->pci_dev->dev, 167 pci_unmap_single(ring->bcm->pci_dev,
170 addr, len, 168 addr, len,
171 DMA_TO_DEVICE); 169 PCI_DMA_TODEVICE);
172 } else { 170 } else {
173 dma_unmap_single(&ring->bcm->pci_dev->dev, 171 pci_unmap_single(ring->bcm->pci_dev,
174 addr, len, 172 addr, len,
175 DMA_FROM_DEVICE); 173 PCI_DMA_FROMDEVICE);
176 } 174 }
177} 175}
178 176
@@ -183,8 +181,8 @@ void sync_descbuffer_for_cpu(struct bcm43xx_dmaring *ring,
183{ 181{
184 assert(!ring->tx); 182 assert(!ring->tx);
185 183
186 dma_sync_single_for_cpu(&ring->bcm->pci_dev->dev, 184 pci_dma_sync_single_for_cpu(ring->bcm->pci_dev,
187 addr, len, DMA_FROM_DEVICE); 185 addr, len, PCI_DMA_FROMDEVICE);
188} 186}
189 187
190static inline 188static inline
@@ -194,8 +192,8 @@ void sync_descbuffer_for_device(struct bcm43xx_dmaring *ring,
194{ 192{
195 assert(!ring->tx); 193 assert(!ring->tx);
196 194
197 dma_sync_single_for_device(&ring->bcm->pci_dev->dev, 195 pci_dma_sync_single_for_cpu(ring->bcm->pci_dev,
198 addr, len, DMA_FROM_DEVICE); 196 addr, len, PCI_DMA_TODEVICE);
199} 197}
200 198
201/* Unmap and free a descriptor buffer. */ 199/* Unmap and free a descriptor buffer. */
@@ -214,17 +212,53 @@ void free_descriptor_buffer(struct bcm43xx_dmaring *ring,
214 212
215static int alloc_ringmemory(struct bcm43xx_dmaring *ring) 213static int alloc_ringmemory(struct bcm43xx_dmaring *ring)
216{ 214{
217 struct device *dev = &(ring->bcm->pci_dev->dev); 215 ring->descbase = pci_alloc_consistent(ring->bcm->pci_dev, BCM43xx_DMA_RINGMEMSIZE,
218 216 &(ring->dmabase));
219 ring->descbase = dma_alloc_coherent(dev, BCM43xx_DMA_RINGMEMSIZE,
220 &(ring->dmabase), GFP_KERNEL);
221 if (!ring->descbase) { 217 if (!ring->descbase) {
222 printk(KERN_ERR PFX "DMA ringmemory allocation failed\n"); 218 /* Allocation may have failed due to pci_alloc_consistent
223 return -ENOMEM; 219 insisting on use of GFP_DMA, which is more restrictive
220 than necessary... */
221 struct dma_desc *rx_ring;
222 dma_addr_t rx_ring_dma;
223
224 rx_ring = kzalloc(BCM43xx_DMA_RINGMEMSIZE, GFP_KERNEL);
225 if (!rx_ring)
226 goto out_err;
227
228 rx_ring_dma = pci_map_single(ring->bcm->pci_dev, rx_ring,
229 BCM43xx_DMA_RINGMEMSIZE,
230 PCI_DMA_BIDIRECTIONAL);
231
232 if (pci_dma_mapping_error(rx_ring_dma) ||
233 rx_ring_dma + BCM43xx_DMA_RINGMEMSIZE > ring->bcm->dma_mask) {
234 /* Sigh... */
235 if (!pci_dma_mapping_error(rx_ring_dma))
236 pci_unmap_single(ring->bcm->pci_dev,
237 rx_ring_dma, BCM43xx_DMA_RINGMEMSIZE,
238 PCI_DMA_BIDIRECTIONAL);
239 rx_ring_dma = pci_map_single(ring->bcm->pci_dev,
240 rx_ring, BCM43xx_DMA_RINGMEMSIZE,
241 PCI_DMA_BIDIRECTIONAL);
242 if (pci_dma_mapping_error(rx_ring_dma) ||
243 rx_ring_dma + BCM43xx_DMA_RINGMEMSIZE > ring->bcm->dma_mask) {
244 assert(0);
245 if (!pci_dma_mapping_error(rx_ring_dma))
246 pci_unmap_single(ring->bcm->pci_dev,
247 rx_ring_dma, BCM43xx_DMA_RINGMEMSIZE,
248 PCI_DMA_BIDIRECTIONAL);
249 goto out_err;
250 }
251 }
252
253 ring->descbase = rx_ring;
254 ring->dmabase = rx_ring_dma;
224 } 255 }
225 memset(ring->descbase, 0, BCM43xx_DMA_RINGMEMSIZE); 256 memset(ring->descbase, 0, BCM43xx_DMA_RINGMEMSIZE);
226 257
227 return 0; 258 return 0;
259out_err:
260 printk(KERN_ERR PFX "DMA ringmemory allocation failed\n");
261 return -ENOMEM;
228} 262}
229 263
230static void free_ringmemory(struct bcm43xx_dmaring *ring) 264static void free_ringmemory(struct bcm43xx_dmaring *ring)
@@ -407,6 +441,29 @@ static int setup_rx_descbuffer(struct bcm43xx_dmaring *ring,
407 if (unlikely(!skb)) 441 if (unlikely(!skb))
408 return -ENOMEM; 442 return -ENOMEM;
409 dmaaddr = map_descbuffer(ring, skb->data, ring->rx_buffersize, 0); 443 dmaaddr = map_descbuffer(ring, skb->data, ring->rx_buffersize, 0);
444 /* This hardware bug work-around adapted from the b44 driver.
445 The chip may be unable to do PCI DMA to/from anything above 1GB */
446 if (pci_dma_mapping_error(dmaaddr) ||
447 dmaaddr + ring->rx_buffersize > ring->bcm->dma_mask) {
448 /* This one has 30-bit addressing... */
449 if (!pci_dma_mapping_error(dmaaddr))
450 pci_unmap_single(ring->bcm->pci_dev,
451 dmaaddr, ring->rx_buffersize,
452 PCI_DMA_FROMDEVICE);
453 dev_kfree_skb_any(skb);
454 skb = __dev_alloc_skb(ring->rx_buffersize,GFP_DMA);
455 if (skb == NULL)
456 return -ENOMEM;
457 dmaaddr = pci_map_single(ring->bcm->pci_dev,
458 skb->data, ring->rx_buffersize,
459 PCI_DMA_FROMDEVICE);
460 if (pci_dma_mapping_error(dmaaddr) ||
461 dmaaddr + ring->rx_buffersize > ring->bcm->dma_mask) {
462 assert(0);
463 dev_kfree_skb_any(skb);
464 return -ENOMEM;
465 }
466 }
410 meta->skb = skb; 467 meta->skb = skb;
411 meta->dmaaddr = dmaaddr; 468 meta->dmaaddr = dmaaddr;
412 skb->dev = ring->bcm->net_dev; 469 skb->dev = ring->bcm->net_dev;
@@ -636,8 +693,10 @@ struct bcm43xx_dmaring * bcm43xx_setup_dmaring(struct bcm43xx_private *bcm,
636 err = dmacontroller_setup(ring); 693 err = dmacontroller_setup(ring);
637 if (err) 694 if (err)
638 goto err_free_ringmemory; 695 goto err_free_ringmemory;
696 return ring;
639 697
640out: 698out:
699 printk(KERN_ERR PFX "Error in bcm43xx_setup_dmaring\n");
641 return ring; 700 return ring;
642 701
643err_free_ringmemory: 702err_free_ringmemory:
@@ -705,30 +764,16 @@ int bcm43xx_dma_init(struct bcm43xx_private *bcm)
705 struct bcm43xx_dmaring *ring; 764 struct bcm43xx_dmaring *ring;
706 int err = -ENOMEM; 765 int err = -ENOMEM;
707 int dma64 = 0; 766 int dma64 = 0;
708 u64 mask = bcm43xx_get_supported_dma_mask(bcm);
709 int nobits;
710 767
711 if (mask == DMA_64BIT_MASK) { 768 bcm->dma_mask = bcm43xx_get_supported_dma_mask(bcm);
769 if (bcm->dma_mask == DMA_64BIT_MASK)
712 dma64 = 1; 770 dma64 = 1;
713 nobits = 64; 771 err = pci_set_dma_mask(bcm->pci_dev, bcm->dma_mask);
714 } else if (mask == DMA_32BIT_MASK) 772 if (err)
715 nobits = 32; 773 goto no_dma;
716 else 774 err = pci_set_consistent_dma_mask(bcm->pci_dev, bcm->dma_mask);
717 nobits = 30; 775 if (err)
718 err = pci_set_dma_mask(bcm->pci_dev, mask); 776 goto no_dma;
719 err |= pci_set_consistent_dma_mask(bcm->pci_dev, mask);
720 if (err) {
721#ifdef CONFIG_BCM43XX_PIO
722 printk(KERN_WARNING PFX "DMA not supported on this device."
723 " Falling back to PIO.\n");
724 bcm->__using_pio = 1;
725 return -ENOSYS;
726#else
727 printk(KERN_ERR PFX "FATAL: DMA not supported and PIO not configured. "
728 "Please recompile the driver with PIO support.\n");
729 return -ENODEV;
730#endif /* CONFIG_BCM43XX_PIO */
731 }
732 777
733 /* setup TX DMA channels. */ 778 /* setup TX DMA channels. */
734 ring = bcm43xx_setup_dmaring(bcm, 0, 1, dma64); 779 ring = bcm43xx_setup_dmaring(bcm, 0, 1, dma64);
@@ -774,7 +819,9 @@ int bcm43xx_dma_init(struct bcm43xx_private *bcm)
774 dma->rx_ring3 = ring; 819 dma->rx_ring3 = ring;
775 } 820 }
776 821
777 dprintk(KERN_INFO PFX "%d-bit DMA initialized\n", nobits); 822 dprintk(KERN_INFO PFX "%d-bit DMA initialized\n",
823 (bcm->dma_mask == DMA_64BIT_MASK) ? 64 :
824 (bcm->dma_mask == DMA_32BIT_MASK) ? 32 : 30);
778 err = 0; 825 err = 0;
779out: 826out:
780 return err; 827 return err;
@@ -800,7 +847,17 @@ err_destroy_tx1:
800err_destroy_tx0: 847err_destroy_tx0:
801 bcm43xx_destroy_dmaring(dma->tx_ring0); 848 bcm43xx_destroy_dmaring(dma->tx_ring0);
802 dma->tx_ring0 = NULL; 849 dma->tx_ring0 = NULL;
803 goto out; 850no_dma:
851#ifdef CONFIG_BCM43XX_PIO
852 printk(KERN_WARNING PFX "DMA not supported on this device."
853 " Falling back to PIO.\n");
854 bcm->__using_pio = 1;
855 return -ENOSYS;
856#else
857 printk(KERN_ERR PFX "FATAL: DMA not supported and PIO not configured. "
858 "Please recompile the driver with PIO support.\n");
859 return -ENODEV;
860#endif /* CONFIG_BCM43XX_PIO */
804} 861}
805 862
806/* Generate a cookie for the TX header. */ 863/* Generate a cookie for the TX header. */
@@ -905,6 +962,7 @@ static void dma_tx_fragment(struct bcm43xx_dmaring *ring,
905 struct bcm43xx_dmadesc_generic *desc; 962 struct bcm43xx_dmadesc_generic *desc;
906 struct bcm43xx_dmadesc_meta *meta; 963 struct bcm43xx_dmadesc_meta *meta;
907 dma_addr_t dmaaddr; 964 dma_addr_t dmaaddr;
965 struct sk_buff *bounce_skb;
908 966
909 assert(skb_shinfo(skb)->nr_frags == 0); 967 assert(skb_shinfo(skb)->nr_frags == 0);
910 968
@@ -924,9 +982,28 @@ static void dma_tx_fragment(struct bcm43xx_dmaring *ring,
924 skb->len - sizeof(struct bcm43xx_txhdr), 982 skb->len - sizeof(struct bcm43xx_txhdr),
925 (cur_frag == 0), 983 (cur_frag == 0),
926 generate_cookie(ring, slot)); 984 generate_cookie(ring, slot));
985 dmaaddr = map_descbuffer(ring, skb->data, skb->len, 1);
986 if (dma_mapping_error(dmaaddr) || dmaaddr + skb->len > ring->bcm->dma_mask) {
987 /* chip cannot handle DMA to/from > 1GB, use bounce buffer (copied from b44 driver) */
988 if (!dma_mapping_error(dmaaddr))
989 unmap_descbuffer(ring, dmaaddr, skb->len, 1);
990 bounce_skb = __dev_alloc_skb(skb->len, GFP_ATOMIC|GFP_DMA);
991 if (!bounce_skb)
992 return;
993 dmaaddr = map_descbuffer(ring, bounce_skb->data, bounce_skb->len, 1);
994 if (dma_mapping_error(dmaaddr) || dmaaddr + skb->len > ring->bcm->dma_mask) {
995 if (!dma_mapping_error(dmaaddr))
996 unmap_descbuffer(ring, dmaaddr, skb->len, 1);
997 dev_kfree_skb_any(bounce_skb);
998 assert(0);
999 return;
1000 }
1001 memcpy(skb_put(bounce_skb, skb->len), skb->data, skb->len);
1002 dev_kfree_skb_any(skb);
1003 skb = bounce_skb;
1004 }
927 1005
928 meta->skb = skb; 1006 meta->skb = skb;
929 dmaaddr = map_descbuffer(ring, skb->data, skb->len, 1);
930 meta->dmaaddr = dmaaddr; 1007 meta->dmaaddr = dmaaddr;
931 1008
932 fill_descriptor(ring, desc, dmaaddr, 1009 fill_descriptor(ring, desc, dmaaddr,
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_ilt.c b/drivers/net/wireless/bcm43xx/bcm43xx_ilt.c
index ad8e569d1f..f2b8dbac55 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_ilt.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_ilt.c
@@ -325,6 +325,21 @@ void bcm43xx_ilt_write(struct bcm43xx_private *bcm, u16 offset, u16 val)
325 } 325 }
326} 326}
327 327
328void bcm43xx_ilt_write32(struct bcm43xx_private *bcm, u16 offset, u32 val)
329{
330 if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A) {
331 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_CTRL, offset);
332 mmiowb();
333 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA2, (val & 0xFFFF0000) >> 16);
334 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, val & 0x0000FFFF);
335 } else {
336 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_CTRL, offset);
337 mmiowb();
338 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_DATA2, (val & 0xFFFF0000) >> 16);
339 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_DATA1, val & 0x0000FFFF);
340 }
341}
342
328u16 bcm43xx_ilt_read(struct bcm43xx_private *bcm, u16 offset) 343u16 bcm43xx_ilt_read(struct bcm43xx_private *bcm, u16 offset)
329{ 344{
330 if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A) { 345 if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A) {
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_ilt.h b/drivers/net/wireless/bcm43xx/bcm43xx_ilt.h
index 464521abf7..d7eaf5f25b 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_ilt.h
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_ilt.h
@@ -27,6 +27,7 @@ extern const u16 bcm43xx_ilt_sigmasqr2[BCM43xx_ILT_SIGMASQR_SIZE];
27 27
28 28
29void bcm43xx_ilt_write(struct bcm43xx_private *bcm, u16 offset, u16 val); 29void bcm43xx_ilt_write(struct bcm43xx_private *bcm, u16 offset, u16 val);
30void bcm43xx_ilt_write32(struct bcm43xx_private *bcm, u16 offset, u32 val);
30u16 bcm43xx_ilt_read(struct bcm43xx_private *bcm, u16 offset); 31u16 bcm43xx_ilt_read(struct bcm43xx_private *bcm, u16 offset);
31 32
32#endif /* BCM43xx_ILT_H_ */ 33#endif /* BCM43xx_ILT_H_ */
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_main.c b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
index 23aaf1ed85..80cb88eb98 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_main.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
@@ -95,13 +95,9 @@ static int modparam_noleds;
95module_param_named(noleds, modparam_noleds, int, 0444); 95module_param_named(noleds, modparam_noleds, int, 0444);
96MODULE_PARM_DESC(noleds, "Turn off all LED activity"); 96MODULE_PARM_DESC(noleds, "Turn off all LED activity");
97 97
98#ifdef CONFIG_BCM43XX_DEBUG
99static char modparam_fwpostfix[64]; 98static char modparam_fwpostfix[64];
100module_param_string(fwpostfix, modparam_fwpostfix, 64, 0444); 99module_param_string(fwpostfix, modparam_fwpostfix, 64, 0444);
101MODULE_PARM_DESC(fwpostfix, "Postfix for .fw files. Useful for debugging."); 100MODULE_PARM_DESC(fwpostfix, "Postfix for .fw files. Useful for using multiple firmware image versions.");
102#else
103# define modparam_fwpostfix ""
104#endif /* CONFIG_BCM43XX_DEBUG*/
105 101
106 102
107/* If you want to debug with just a single device, enable this, 103/* If you want to debug with just a single device, enable this,
@@ -855,8 +851,6 @@ static int bcm43xx_sprom_extract(struct bcm43xx_private *bcm)
855 value = sprom[BCM43xx_SPROM_ETHPHY]; 851 value = sprom[BCM43xx_SPROM_ETHPHY];
856 bcm->sprom.et0phyaddr = (value & 0x001F); 852 bcm->sprom.et0phyaddr = (value & 0x001F);
857 bcm->sprom.et1phyaddr = (value & 0x03E0) >> 5; 853 bcm->sprom.et1phyaddr = (value & 0x03E0) >> 5;
858 bcm->sprom.et0mdcport = (value & (1 << 14)) >> 14;
859 bcm->sprom.et1mdcport = (value & (1 << 15)) >> 15;
860 854
861 /* boardrev, antennas, locale */ 855 /* boardrev, antennas, locale */
862 value = sprom[BCM43xx_SPROM_BOARDREV]; 856 value = sprom[BCM43xx_SPROM_BOARDREV];
@@ -1453,12 +1447,10 @@ static void handle_irq_transmit_status(struct bcm43xx_private *bcm)
1453 1447
1454 bcm43xx_debugfs_log_txstat(bcm, &stat); 1448 bcm43xx_debugfs_log_txstat(bcm, &stat);
1455 1449
1456 if (stat.flags & BCM43xx_TXSTAT_FLAG_IGNORE) 1450 if (stat.flags & BCM43xx_TXSTAT_FLAG_AMPDU)
1451 continue;
1452 if (stat.flags & BCM43xx_TXSTAT_FLAG_INTER)
1457 continue; 1453 continue;
1458 if (!(stat.flags & BCM43xx_TXSTAT_FLAG_ACK)) {
1459 //TODO: packet was not acked (was lost)
1460 }
1461 //TODO: There are more (unknown) flags to test. see bcm43xx_main.h
1462 1454
1463 if (bcm43xx_using_pio(bcm)) 1455 if (bcm43xx_using_pio(bcm))
1464 bcm43xx_pio_handle_xmitstatus(bcm, &stat); 1456 bcm43xx_pio_handle_xmitstatus(bcm, &stat);
@@ -1866,9 +1858,6 @@ static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id)
1866 1858
1867 spin_lock(&bcm->irq_lock); 1859 spin_lock(&bcm->irq_lock);
1868 1860
1869 assert(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED);
1870 assert(bcm->current_core->id == BCM43xx_COREID_80211);
1871
1872 reason = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); 1861 reason = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
1873 if (reason == 0xffffffff) { 1862 if (reason == 0xffffffff) {
1874 /* irq not for us (shared irq) */ 1863 /* irq not for us (shared irq) */
@@ -1879,6 +1868,9 @@ static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id)
1879 if (!reason) 1868 if (!reason)
1880 goto out; 1869 goto out;
1881 1870
1871 assert(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED);
1872 assert(bcm->current_core->id == BCM43xx_COREID_80211);
1873
1882 bcm->dma_reason[0] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA0_REASON) 1874 bcm->dma_reason[0] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA0_REASON)
1883 & 0x0001DC00; 1875 & 0x0001DC00;
1884 bcm->dma_reason[1] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA1_REASON) 1876 bcm->dma_reason[1] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA1_REASON)
@@ -2741,8 +2733,9 @@ static int bcm43xx_probe_cores(struct bcm43xx_private *bcm)
2741 * dangling pins on the second core. Be careful 2733 * dangling pins on the second core. Be careful
2742 * and ignore these cores here. 2734 * and ignore these cores here.
2743 */ 2735 */
2744 if (bcm->pci_dev->device != 0x4324) { 2736 if (1 /*bcm->pci_dev->device != 0x4324*/ ) {
2745 dprintk(KERN_INFO PFX "Ignoring additional 802.11 core.\n"); 2737 /* TODO: A PHY */
2738 dprintk(KERN_INFO PFX "Ignoring additional 802.11a core.\n");
2746 continue; 2739 continue;
2747 } 2740 }
2748 } 2741 }
@@ -2983,8 +2976,10 @@ static int bcm43xx_chipset_attach(struct bcm43xx_private *bcm)
2983 err = bcm43xx_pctl_set_crystal(bcm, 1); 2976 err = bcm43xx_pctl_set_crystal(bcm, 1);
2984 if (err) 2977 if (err)
2985 goto out; 2978 goto out;
2986 bcm43xx_pci_read_config16(bcm, PCI_STATUS, &pci_status); 2979 err = bcm43xx_pci_read_config16(bcm, PCI_STATUS, &pci_status);
2987 bcm43xx_pci_write_config16(bcm, PCI_STATUS, pci_status & ~PCI_STATUS_SIG_TARGET_ABORT); 2980 if (err)
2981 goto out;
2982 err = bcm43xx_pci_write_config16(bcm, PCI_STATUS, pci_status & ~PCI_STATUS_SIG_TARGET_ABORT);
2988 2983
2989out: 2984out:
2990 return err; 2985 return err;
@@ -3698,7 +3693,7 @@ static int bcm43xx_read_phyinfo(struct bcm43xx_private *bcm)
3698{ 3693{
3699 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm); 3694 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
3700 u16 value; 3695 u16 value;
3701 u8 phy_version; 3696 u8 phy_analog;
3702 u8 phy_type; 3697 u8 phy_type;
3703 u8 phy_rev; 3698 u8 phy_rev;
3704 int phy_rev_ok = 1; 3699 int phy_rev_ok = 1;
@@ -3706,12 +3701,12 @@ static int bcm43xx_read_phyinfo(struct bcm43xx_private *bcm)
3706 3701
3707 value = bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_VER); 3702 value = bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_VER);
3708 3703
3709 phy_version = (value & 0xF000) >> 12; 3704 phy_analog = (value & 0xF000) >> 12;
3710 phy_type = (value & 0x0F00) >> 8; 3705 phy_type = (value & 0x0F00) >> 8;
3711 phy_rev = (value & 0x000F); 3706 phy_rev = (value & 0x000F);
3712 3707
3713 dprintk(KERN_INFO PFX "Detected PHY: Version: %x, Type %x, Revision %x\n", 3708 dprintk(KERN_INFO PFX "Detected PHY: Analog: %x, Type %x, Revision %x\n",
3714 phy_version, phy_type, phy_rev); 3709 phy_analog, phy_type, phy_rev);
3715 3710
3716 switch (phy_type) { 3711 switch (phy_type) {
3717 case BCM43xx_PHYTYPE_A: 3712 case BCM43xx_PHYTYPE_A:
@@ -3754,7 +3749,7 @@ static int bcm43xx_read_phyinfo(struct bcm43xx_private *bcm)
3754 phy_rev); 3749 phy_rev);
3755 } 3750 }
3756 3751
3757 phy->version = phy_version; 3752 phy->analog = phy_analog;
3758 phy->type = phy_type; 3753 phy->type = phy_type;
3759 phy->rev = phy_rev; 3754 phy->rev = phy_rev;
3760 if ((phy_type == BCM43xx_PHYTYPE_B) || (phy_type == BCM43xx_PHYTYPE_G)) { 3755 if ((phy_type == BCM43xx_PHYTYPE_B) || (phy_type == BCM43xx_PHYTYPE_G)) {
@@ -3796,12 +3791,18 @@ static int bcm43xx_attach_board(struct bcm43xx_private *bcm)
3796 } 3791 }
3797 net_dev->base_addr = (unsigned long)bcm->mmio_addr; 3792 net_dev->base_addr = (unsigned long)bcm->mmio_addr;
3798 3793
3799 bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_VENDOR_ID, 3794 err = bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_VENDOR_ID,
3800 &bcm->board_vendor); 3795 &bcm->board_vendor);
3801 bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_ID, 3796 if (err)
3797 goto err_iounmap;
3798 err = bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_ID,
3802 &bcm->board_type); 3799 &bcm->board_type);
3803 bcm43xx_pci_read_config16(bcm, PCI_REVISION_ID, 3800 if (err)
3801 goto err_iounmap;
3802 err = bcm43xx_pci_read_config16(bcm, PCI_REVISION_ID,
3804 &bcm->board_revision); 3803 &bcm->board_revision);
3804 if (err)
3805 goto err_iounmap;
3805 3806
3806 err = bcm43xx_chipset_attach(bcm); 3807 err = bcm43xx_chipset_attach(bcm);
3807 if (err) 3808 if (err)
@@ -3892,6 +3893,7 @@ err_pci_release:
3892 pci_release_regions(pci_dev); 3893 pci_release_regions(pci_dev);
3893err_pci_disable: 3894err_pci_disable:
3894 pci_disable_device(pci_dev); 3895 pci_disable_device(pci_dev);
3896 printk(KERN_ERR PFX "Unable to attach board\n");
3895 goto out; 3897 goto out;
3896} 3898}
3897 3899
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_phy.c b/drivers/net/wireless/bcm43xx/bcm43xx_phy.c
index 52ce2a9334..cae89258a6 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_phy.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_phy.c
@@ -205,8 +205,8 @@ static void bcm43xx_phy_init_pctl(struct bcm43xx_private *bcm)
205 (bcm->board_type == 0x0416)) 205 (bcm->board_type == 0x0416))
206 return; 206 return;
207 207
208 bcm43xx_write16(bcm, 0x03E6, bcm43xx_read16(bcm, 0x03E6) & 0xFFDF);
209 bcm43xx_phy_write(bcm, 0x0028, 0x8018); 208 bcm43xx_phy_write(bcm, 0x0028, 0x8018);
209 bcm43xx_write16(bcm, 0x03E6, bcm43xx_read16(bcm, 0x03E6) & 0xFFDF);
210 210
211 if (phy->type == BCM43xx_PHYTYPE_G) { 211 if (phy->type == BCM43xx_PHYTYPE_G) {
212 if (!phy->connected) 212 if (!phy->connected)
@@ -317,6 +317,13 @@ static void bcm43xx_phy_agcsetup(struct bcm43xx_private *bcm)
317 bcm43xx_ilt_write(bcm, offset + 0x0801, 7); 317 bcm43xx_ilt_write(bcm, offset + 0x0801, 7);
318 bcm43xx_ilt_write(bcm, offset + 0x0802, 16); 318 bcm43xx_ilt_write(bcm, offset + 0x0802, 16);
319 bcm43xx_ilt_write(bcm, offset + 0x0803, 28); 319 bcm43xx_ilt_write(bcm, offset + 0x0803, 28);
320
321 if (phy->rev >= 6) {
322 bcm43xx_phy_write(bcm, 0x0426, (bcm43xx_phy_read(bcm, 0x0426)
323 & 0xFFFC));
324 bcm43xx_phy_write(bcm, 0x0426, (bcm43xx_phy_read(bcm, 0x0426)
325 & 0xEFFF));
326 }
320} 327}
321 328
322static void bcm43xx_phy_setupg(struct bcm43xx_private *bcm) 329static void bcm43xx_phy_setupg(struct bcm43xx_private *bcm)
@@ -337,7 +344,7 @@ static void bcm43xx_phy_setupg(struct bcm43xx_private *bcm)
337 for (i = 0; i < BCM43xx_ILT_NOISEG1_SIZE; i++) 344 for (i = 0; i < BCM43xx_ILT_NOISEG1_SIZE; i++)
338 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noiseg1[i]); 345 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noiseg1[i]);
339 for (i = 0; i < BCM43xx_ILT_ROTOR_SIZE; i++) 346 for (i = 0; i < BCM43xx_ILT_ROTOR_SIZE; i++)
340 bcm43xx_ilt_write(bcm, 0x2000 + i, bcm43xx_ilt_rotor[i]); 347 bcm43xx_ilt_write32(bcm, 0x2000 + i, bcm43xx_ilt_rotor[i]);
341 } else { 348 } else {
342 /* nrssi values are signed 6-bit values. Not sure why we write 0x7654 here... */ 349 /* nrssi values are signed 6-bit values. Not sure why we write 0x7654 here... */
343 bcm43xx_nrssi_hw_write(bcm, 0xBA98, (s16)0x7654); 350 bcm43xx_nrssi_hw_write(bcm, 0xBA98, (s16)0x7654);
@@ -377,7 +384,7 @@ static void bcm43xx_phy_setupg(struct bcm43xx_private *bcm)
377 384
378 if (phy->rev == 1) { 385 if (phy->rev == 1) {
379 for (i = 0; i < BCM43xx_ILT_RETARD_SIZE; i++) 386 for (i = 0; i < BCM43xx_ILT_RETARD_SIZE; i++)
380 bcm43xx_ilt_write(bcm, 0x2400 + i, bcm43xx_ilt_retard[i]); 387 bcm43xx_ilt_write32(bcm, 0x2400 + i, bcm43xx_ilt_retard[i]);
381 for (i = 0; i < 4; i++) { 388 for (i = 0; i < 4; i++) {
382 bcm43xx_ilt_write(bcm, 0x5404 + i, 0x0020); 389 bcm43xx_ilt_write(bcm, 0x5404 + i, 0x0020);
383 bcm43xx_ilt_write(bcm, 0x5408 + i, 0x0020); 390 bcm43xx_ilt_write(bcm, 0x5408 + i, 0x0020);
@@ -500,10 +507,10 @@ static void bcm43xx_phy_setupa(struct bcm43xx_private *bcm)
500 for (i = 0; i < BCM43xx_ILT_NOISEA2_SIZE; i++) 507 for (i = 0; i < BCM43xx_ILT_NOISEA2_SIZE; i++)
501 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noisea2[i]); 508 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noisea2[i]);
502 for (i = 0; i < BCM43xx_ILT_ROTOR_SIZE; i++) 509 for (i = 0; i < BCM43xx_ILT_ROTOR_SIZE; i++)
503 bcm43xx_ilt_write(bcm, 0x2000 + i, bcm43xx_ilt_rotor[i]); 510 bcm43xx_ilt_write32(bcm, 0x2000 + i, bcm43xx_ilt_rotor[i]);
504 bcm43xx_phy_init_noisescaletbl(bcm); 511 bcm43xx_phy_init_noisescaletbl(bcm);
505 for (i = 0; i < BCM43xx_ILT_RETARD_SIZE; i++) 512 for (i = 0; i < BCM43xx_ILT_RETARD_SIZE; i++)
506 bcm43xx_ilt_write(bcm, 0x2400 + i, bcm43xx_ilt_retard[i]); 513 bcm43xx_ilt_write32(bcm, 0x2400 + i, bcm43xx_ilt_retard[i]);
507 break; 514 break;
508 case 3: 515 case 3:
509 for (i = 0; i < 64; i++) 516 for (i = 0; i < 64; i++)
@@ -729,19 +736,19 @@ static void bcm43xx_phy_initb5(struct bcm43xx_private *bcm)
729 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm); 736 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
730 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm); 737 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
731 u16 offset; 738 u16 offset;
739 u16 value;
740 u8 old_channel;
732 741
733 if (phy->version == 1 && 742 if (phy->analog == 1)
734 radio->version == 0x2050) {
735 bcm43xx_radio_write16(bcm, 0x007A, 743 bcm43xx_radio_write16(bcm, 0x007A,
736 bcm43xx_radio_read16(bcm, 0x007A) 744 bcm43xx_radio_read16(bcm, 0x007A)
737 | 0x0050); 745 | 0x0050);
738 }
739 if ((bcm->board_vendor != PCI_VENDOR_ID_BROADCOM) && 746 if ((bcm->board_vendor != PCI_VENDOR_ID_BROADCOM) &&
740 (bcm->board_type != 0x0416)) { 747 (bcm->board_type != 0x0416)) {
748 value = 0x2120;
741 for (offset = 0x00A8 ; offset < 0x00C7; offset++) { 749 for (offset = 0x00A8 ; offset < 0x00C7; offset++) {
742 bcm43xx_phy_write(bcm, offset, 750 bcm43xx_phy_write(bcm, offset, value);
743 (bcm43xx_phy_read(bcm, offset) + 0x2020) 751 value += 0x0202;
744 & 0x3F3F);
745 } 752 }
746 } 753 }
747 bcm43xx_phy_write(bcm, 0x0035, 754 bcm43xx_phy_write(bcm, 0x0035,
@@ -750,7 +757,7 @@ static void bcm43xx_phy_initb5(struct bcm43xx_private *bcm)
750 if (radio->version == 0x2050) 757 if (radio->version == 0x2050)
751 bcm43xx_phy_write(bcm, 0x0038, 0x0667); 758 bcm43xx_phy_write(bcm, 0x0038, 0x0667);
752 759
753 if (phy->connected) { 760 if (phy->type == BCM43xx_PHYTYPE_G) {
754 if (radio->version == 0x2050) { 761 if (radio->version == 0x2050) {
755 bcm43xx_radio_write16(bcm, 0x007A, 762 bcm43xx_radio_write16(bcm, 0x007A,
756 bcm43xx_radio_read16(bcm, 0x007A) 763 bcm43xx_radio_read16(bcm, 0x007A)
@@ -776,7 +783,7 @@ static void bcm43xx_phy_initb5(struct bcm43xx_private *bcm)
776 bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD) | (1 << 11)); 783 bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD) | (1 << 11));
777 } 784 }
778 785
779 if (phy->version == 1 && radio->version == 0x2050) { 786 if (phy->analog == 1) {
780 bcm43xx_phy_write(bcm, 0x0026, 0xCE00); 787 bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
781 bcm43xx_phy_write(bcm, 0x0021, 0x3763); 788 bcm43xx_phy_write(bcm, 0x0021, 0x3763);
782 bcm43xx_phy_write(bcm, 0x0022, 0x1BC3); 789 bcm43xx_phy_write(bcm, 0x0022, 0x1BC3);
@@ -787,14 +794,15 @@ static void bcm43xx_phy_initb5(struct bcm43xx_private *bcm)
787 bcm43xx_phy_write(bcm, 0x0030, 0x00C6); 794 bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
788 bcm43xx_write16(bcm, 0x03EC, 0x3F22); 795 bcm43xx_write16(bcm, 0x03EC, 0x3F22);
789 796
790 if (phy->version == 1 && radio->version == 0x2050) 797 if (phy->analog == 1)
791 bcm43xx_phy_write(bcm, 0x0020, 0x3E1C); 798 bcm43xx_phy_write(bcm, 0x0020, 0x3E1C);
792 else 799 else
793 bcm43xx_phy_write(bcm, 0x0020, 0x301C); 800 bcm43xx_phy_write(bcm, 0x0020, 0x301C);
794 801
795 if (phy->version == 0) 802 if (phy->analog == 0)
796 bcm43xx_write16(bcm, 0x03E4, 0x3000); 803 bcm43xx_write16(bcm, 0x03E4, 0x3000);
797 804
805 old_channel = radio->channel;
798 /* Force to channel 7, even if not supported. */ 806 /* Force to channel 7, even if not supported. */
799 bcm43xx_radio_selectchannel(bcm, 7, 0); 807 bcm43xx_radio_selectchannel(bcm, 7, 0);
800 808
@@ -816,11 +824,11 @@ static void bcm43xx_phy_initb5(struct bcm43xx_private *bcm)
816 824
817 bcm43xx_radio_write16(bcm, 0x007A, bcm43xx_radio_read16(bcm, 0x007A) | 0x0007); 825 bcm43xx_radio_write16(bcm, 0x007A, bcm43xx_radio_read16(bcm, 0x007A) | 0x0007);
818 826
819 bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0); 827 bcm43xx_radio_selectchannel(bcm, old_channel, 0);
820 828
821 bcm43xx_phy_write(bcm, 0x0014, 0x0080); 829 bcm43xx_phy_write(bcm, 0x0014, 0x0080);
822 bcm43xx_phy_write(bcm, 0x0032, 0x00CA); 830 bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
823 bcm43xx_phy_write(bcm, 0x88A3, 0x002A); 831 bcm43xx_phy_write(bcm, 0x002A, 0x88A3);
824 832
825 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF); 833 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
826 834
@@ -835,61 +843,29 @@ static void bcm43xx_phy_initb6(struct bcm43xx_private *bcm)
835 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm); 843 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
836 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm); 844 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
837 u16 offset, val; 845 u16 offset, val;
846 u8 old_channel;
838 847
839 bcm43xx_phy_write(bcm, 0x003E, 0x817A); 848 bcm43xx_phy_write(bcm, 0x003E, 0x817A);
840 bcm43xx_radio_write16(bcm, 0x007A, 849 bcm43xx_radio_write16(bcm, 0x007A,
841 (bcm43xx_radio_read16(bcm, 0x007A) | 0x0058)); 850 (bcm43xx_radio_read16(bcm, 0x007A) | 0x0058));
842 if ((radio->manufact == 0x17F) && 851 if (radio->revision == 4 ||
843 (radio->version == 0x2050) && 852 radio->revision == 5) {
844 (radio->revision == 3 || 853 bcm43xx_radio_write16(bcm, 0x0051, 0x0037);
845 radio->revision == 4 || 854 bcm43xx_radio_write16(bcm, 0x0052, 0x0070);
846 radio->revision == 5)) { 855 bcm43xx_radio_write16(bcm, 0x0053, 0x00B3);
847 bcm43xx_radio_write16(bcm, 0x0051, 0x001F); 856 bcm43xx_radio_write16(bcm, 0x0054, 0x009B);
848 bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
849 bcm43xx_radio_write16(bcm, 0x0053, 0x005B);
850 bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
851 bcm43xx_radio_write16(bcm, 0x005A, 0x0088); 857 bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
852 bcm43xx_radio_write16(bcm, 0x005B, 0x0088); 858 bcm43xx_radio_write16(bcm, 0x005B, 0x0088);
853 bcm43xx_radio_write16(bcm, 0x005D, 0x0088); 859 bcm43xx_radio_write16(bcm, 0x005D, 0x0088);
854 bcm43xx_radio_write16(bcm, 0x005E, 0x0088); 860 bcm43xx_radio_write16(bcm, 0x005E, 0x0088);
855 bcm43xx_radio_write16(bcm, 0x007D, 0x0088); 861 bcm43xx_radio_write16(bcm, 0x007D, 0x0088);
862 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
863 BCM43xx_UCODEFLAGS_OFFSET,
864 (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
865 BCM43xx_UCODEFLAGS_OFFSET)
866 | 0x00000200));
856 } 867 }
857 if ((radio->manufact == 0x17F) && 868 if (radio->revision == 8) {
858 (radio->version == 0x2050) &&
859 (radio->revision == 6)) {
860 bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
861 bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
862 bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
863 bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
864 bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
865 bcm43xx_radio_write16(bcm, 0x005B, 0x008B);
866 bcm43xx_radio_write16(bcm, 0x005C, 0x00B5);
867 bcm43xx_radio_write16(bcm, 0x005D, 0x0088);
868 bcm43xx_radio_write16(bcm, 0x005E, 0x0088);
869 bcm43xx_radio_write16(bcm, 0x007D, 0x0088);
870 bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
871 bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
872 }
873 if ((radio->manufact == 0x17F) &&
874 (radio->version == 0x2050) &&
875 (radio->revision == 7)) {
876 bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
877 bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
878 bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
879 bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
880 bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
881 bcm43xx_radio_write16(bcm, 0x005B, 0x00A8);
882 bcm43xx_radio_write16(bcm, 0x005C, 0x0075);
883 bcm43xx_radio_write16(bcm, 0x005D, 0x00F5);
884 bcm43xx_radio_write16(bcm, 0x005E, 0x00B8);
885 bcm43xx_radio_write16(bcm, 0x007D, 0x00E8);
886 bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
887 bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
888 bcm43xx_radio_write16(bcm, 0x007B, 0x0000);
889 }
890 if ((radio->manufact == 0x17F) &&
891 (radio->version == 0x2050) &&
892 (radio->revision == 8)) {
893 bcm43xx_radio_write16(bcm, 0x0051, 0x0000); 869 bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
894 bcm43xx_radio_write16(bcm, 0x0052, 0x0040); 870 bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
895 bcm43xx_radio_write16(bcm, 0x0053, 0x00B7); 871 bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
@@ -933,20 +909,26 @@ static void bcm43xx_phy_initb6(struct bcm43xx_private *bcm)
933 bcm43xx_phy_read(bcm, 0x0802) | 0x0100); 909 bcm43xx_phy_read(bcm, 0x0802) | 0x0100);
934 bcm43xx_phy_write(bcm, 0x042B, 910 bcm43xx_phy_write(bcm, 0x042B,
935 bcm43xx_phy_read(bcm, 0x042B) | 0x2000); 911 bcm43xx_phy_read(bcm, 0x042B) | 0x2000);
912 bcm43xx_phy_write(bcm, 0x5B, 0x0000);
913 bcm43xx_phy_write(bcm, 0x5C, 0x0000);
936 } 914 }
937 915
938 /* Force to channel 7, even if not supported. */ 916 old_channel = radio->channel;
939 bcm43xx_radio_selectchannel(bcm, 7, 0); 917 if (old_channel >= 8)
918 bcm43xx_radio_selectchannel(bcm, 1, 0);
919 else
920 bcm43xx_radio_selectchannel(bcm, 13, 0);
940 921
941 bcm43xx_radio_write16(bcm, 0x0050, 0x0020); 922 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
942 bcm43xx_radio_write16(bcm, 0x0050, 0x0023); 923 bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
943 udelay(40); 924 udelay(40);
944 bcm43xx_radio_write16(bcm, 0x007C, (bcm43xx_radio_read16(bcm, 0x007C) | 0x0002)); 925 if (radio->revision < 6 || radio-> revision == 8) {
945 bcm43xx_radio_write16(bcm, 0x0050, 0x0020); 926 bcm43xx_radio_write16(bcm, 0x007C, (bcm43xx_radio_read16(bcm, 0x007C)
946 if (radio->manufact == 0x17F && 927 | 0x0002));
947 radio->version == 0x2050 &&
948 radio->revision <= 2) {
949 bcm43xx_radio_write16(bcm, 0x0050, 0x0020); 928 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
929 }
930 if (radio->revision <= 2) {
931 bcm43xx_radio_write16(bcm, 0x007C, 0x0020);
950 bcm43xx_radio_write16(bcm, 0x005A, 0x0070); 932 bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
951 bcm43xx_radio_write16(bcm, 0x005B, 0x007B); 933 bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
952 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0); 934 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
@@ -954,46 +936,42 @@ static void bcm43xx_phy_initb6(struct bcm43xx_private *bcm)
954 bcm43xx_radio_write16(bcm, 0x007A, 936 bcm43xx_radio_write16(bcm, 0x007A,
955 (bcm43xx_radio_read16(bcm, 0x007A) & 0x00F8) | 0x0007); 937 (bcm43xx_radio_read16(bcm, 0x007A) & 0x00F8) | 0x0007);
956 938
957 bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0); 939 bcm43xx_radio_selectchannel(bcm, old_channel, 0);
958 940
959 bcm43xx_phy_write(bcm, 0x0014, 0x0200); 941 bcm43xx_phy_write(bcm, 0x0014, 0x0200);
960 if (radio->version == 0x2050){ 942 if (radio->revision >= 6)
961 if (radio->revision == 3 || 943 bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
962 radio->revision == 4 || 944 else
963 radio->revision == 5) 945 bcm43xx_phy_write(bcm, 0x002A, 0x8AC0);
964 bcm43xx_phy_write(bcm, 0x002A, 0x8AC0);
965 else
966 bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
967 }
968 bcm43xx_phy_write(bcm, 0x0038, 0x0668); 946 bcm43xx_phy_write(bcm, 0x0038, 0x0668);
969 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF); 947 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
970 if (radio->version == 0x2050) { 948 if (radio->revision <= 5)
971 if (radio->revision == 3 || 949 bcm43xx_phy_write(bcm, 0x005D, (bcm43xx_phy_read(bcm, 0x005D)
972 radio->revision == 4 || 950 & 0xFF80) | 0x0003);
973 radio->revision == 5) 951 if (radio->revision <= 2)
974 bcm43xx_phy_write(bcm, 0x005D, bcm43xx_phy_read(bcm, 0x005D) | 0x0003); 952 bcm43xx_radio_write16(bcm, 0x005D, 0x000D);
975 else if (radio->revision <= 2)
976 bcm43xx_radio_write16(bcm, 0x005D, 0x000D);
977 }
978 953
979 if (phy->rev == 4) 954 if (phy->analog == 4){
980 bcm43xx_phy_write(bcm, 0x0002, (bcm43xx_phy_read(bcm, 0x0002) & 0xFFC0) | 0x0004);
981 else
982 bcm43xx_write16(bcm, 0x03E4, 0x0009); 955 bcm43xx_write16(bcm, 0x03E4, 0x0009);
956 bcm43xx_phy_write(bcm, 0x61, bcm43xx_phy_read(bcm, 0x61) & 0xFFF);
957 } else {
958 bcm43xx_phy_write(bcm, 0x0002, (bcm43xx_phy_read(bcm, 0x0002) & 0xFFC0) | 0x0004);
959 }
960 if (phy->type == BCM43xx_PHYTYPE_G)
961 bcm43xx_write16(bcm, 0x03E6, 0x0);
983 if (phy->type == BCM43xx_PHYTYPE_B) { 962 if (phy->type == BCM43xx_PHYTYPE_B) {
984 bcm43xx_write16(bcm, 0x03E6, 0x8140); 963 bcm43xx_write16(bcm, 0x03E6, 0x8140);
985 bcm43xx_phy_write(bcm, 0x0016, 0x0410); 964 bcm43xx_phy_write(bcm, 0x0016, 0x0410);
986 bcm43xx_phy_write(bcm, 0x0017, 0x0820); 965 bcm43xx_phy_write(bcm, 0x0017, 0x0820);
987 bcm43xx_phy_write(bcm, 0x0062, 0x0007); 966 bcm43xx_phy_write(bcm, 0x0062, 0x0007);
988 (void) bcm43xx_radio_calibrationvalue(bcm); 967 bcm43xx_radio_init2050(bcm);
989 bcm43xx_phy_lo_b_measure(bcm); 968 bcm43xx_phy_lo_g_measure(bcm);
990 if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) { 969 if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
991 bcm43xx_calc_nrssi_slope(bcm); 970 bcm43xx_calc_nrssi_slope(bcm);
992 bcm43xx_calc_nrssi_threshold(bcm); 971 bcm43xx_calc_nrssi_threshold(bcm);
993 } 972 }
994 bcm43xx_phy_init_pctl(bcm); 973 bcm43xx_phy_init_pctl(bcm);
995 } else 974 }
996 bcm43xx_write16(bcm, 0x03E6, 0x0);
997} 975}
998 976
999static void bcm43xx_calc_loopback_gain(struct bcm43xx_private *bcm) 977static void bcm43xx_calc_loopback_gain(struct bcm43xx_private *bcm)
@@ -1063,7 +1041,7 @@ static void bcm43xx_calc_loopback_gain(struct bcm43xx_private *bcm)
1063 bcm43xx_phy_write(bcm, 0x005A, 0x0780); 1041 bcm43xx_phy_write(bcm, 0x005A, 0x0780);
1064 bcm43xx_phy_write(bcm, 0x0059, 0xC810); 1042 bcm43xx_phy_write(bcm, 0x0059, 0xC810);
1065 bcm43xx_phy_write(bcm, 0x0058, 0x000D); 1043 bcm43xx_phy_write(bcm, 0x0058, 0x000D);
1066 if (phy->version == 0) { 1044 if (phy->analog == 0) {
1067 bcm43xx_phy_write(bcm, 0x0003, 0x0122); 1045 bcm43xx_phy_write(bcm, 0x0003, 0x0122);
1068 } else { 1046 } else {
1069 bcm43xx_phy_write(bcm, 0x000A, 1047 bcm43xx_phy_write(bcm, 0x000A,
@@ -1205,27 +1183,30 @@ static void bcm43xx_phy_initg(struct bcm43xx_private *bcm)
1205 if (phy->rev >= 2) { 1183 if (phy->rev >= 2) {
1206 bcm43xx_phy_write(bcm, 0x0814, 0x0000); 1184 bcm43xx_phy_write(bcm, 0x0814, 0x0000);
1207 bcm43xx_phy_write(bcm, 0x0815, 0x0000); 1185 bcm43xx_phy_write(bcm, 0x0815, 0x0000);
1208 if (phy->rev == 2) 1186 }
1209 bcm43xx_phy_write(bcm, 0x0811, 0x0000); 1187 if (phy->rev == 2) {
1210 else if (phy->rev >= 3) 1188 bcm43xx_phy_write(bcm, 0x0811, 0x0000);
1211 bcm43xx_phy_write(bcm, 0x0811, 0x0400);
1212 bcm43xx_phy_write(bcm, 0x0015, 0x00C0); 1189 bcm43xx_phy_write(bcm, 0x0015, 0x00C0);
1213 if (phy->connected) { 1190 }
1214 tmp = bcm43xx_phy_read(bcm, 0x0400) & 0xFF; 1191 if (phy->rev >= 3) {
1215 if (tmp < 6) { 1192 bcm43xx_phy_write(bcm, 0x0811, 0x0400);
1216 bcm43xx_phy_write(bcm, 0x04C2, 0x1816); 1193 bcm43xx_phy_write(bcm, 0x0015, 0x00C0);
1217 bcm43xx_phy_write(bcm, 0x04C3, 0x8006); 1194 }
1218 if (tmp != 3) { 1195 if (phy->connected) {
1219 bcm43xx_phy_write(bcm, 0x04CC, 1196 tmp = bcm43xx_phy_read(bcm, 0x0400) & 0xFF;
1220 (bcm43xx_phy_read(bcm, 0x04CC) 1197 if (tmp < 6) {
1221 & 0x00FF) | 0x1F00); 1198 bcm43xx_phy_write(bcm, 0x04C2, 0x1816);
1222 } 1199 bcm43xx_phy_write(bcm, 0x04C3, 0x8006);
1200 if (tmp != 3) {
1201 bcm43xx_phy_write(bcm, 0x04CC,
1202 (bcm43xx_phy_read(bcm, 0x04CC)
1203 & 0x00FF) | 0x1F00);
1223 } 1204 }
1224 } 1205 }
1225 } 1206 }
1226 if (phy->rev < 3 && phy->connected) 1207 if (phy->rev < 3 && phy->connected)
1227 bcm43xx_phy_write(bcm, 0x047E, 0x0078); 1208 bcm43xx_phy_write(bcm, 0x047E, 0x0078);
1228 if (phy->rev >= 6 && phy->rev <= 8) { 1209 if (radio->revision == 8) {
1229 bcm43xx_phy_write(bcm, 0x0801, bcm43xx_phy_read(bcm, 0x0801) | 0x0080); 1210 bcm43xx_phy_write(bcm, 0x0801, bcm43xx_phy_read(bcm, 0x0801) | 0x0080);
1230 bcm43xx_phy_write(bcm, 0x043E, bcm43xx_phy_read(bcm, 0x043E) | 0x0004); 1211 bcm43xx_phy_write(bcm, 0x043E, bcm43xx_phy_read(bcm, 0x043E) | 0x0004);
1231 } 1212 }
@@ -1638,14 +1619,14 @@ void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private *bcm,
1638 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm); 1619 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1639 u16 value; 1620 u16 value;
1640 1621
1641 if (phy->version == 0) { 1622 if (phy->analog == 0) {
1642 value = (bcm43xx_read16(bcm, 0x03E6) & 0xFFF0); 1623 value = (bcm43xx_read16(bcm, 0x03E6) & 0xFFF0);
1643 value |= (baseband_attenuation & 0x000F); 1624 value |= (baseband_attenuation & 0x000F);
1644 bcm43xx_write16(bcm, 0x03E6, value); 1625 bcm43xx_write16(bcm, 0x03E6, value);
1645 return; 1626 return;
1646 } 1627 }
1647 1628
1648 if (phy->version > 1) { 1629 if (phy->analog > 1) {
1649 value = bcm43xx_phy_read(bcm, 0x0060) & ~0x003C; 1630 value = bcm43xx_phy_read(bcm, 0x0060) & ~0x003C;
1650 value |= (baseband_attenuation << 2) & 0x003C; 1631 value |= (baseband_attenuation << 2) & 0x003C;
1651 } else { 1632 } else {
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_radio.c b/drivers/net/wireless/bcm43xx/bcm43xx_radio.c
index af19a07032..32beb91b71 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_radio.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_radio.c
@@ -1393,11 +1393,12 @@ u16 bcm43xx_radio_init2050(struct bcm43xx_private *bcm)
1393 backup[12] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT); 1393 backup[12] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT);
1394 1394
1395 // Initialization 1395 // Initialization
1396 if (phy->version == 0) { 1396 if (phy->analog == 0) {
1397 bcm43xx_write16(bcm, 0x03E6, 0x0122); 1397 bcm43xx_write16(bcm, 0x03E6, 0x0122);
1398 } else { 1398 } else {
1399 if (phy->version >= 2) 1399 if (phy->analog >= 2)
1400 bcm43xx_write16(bcm, 0x03E6, 0x0040); 1400 bcm43xx_phy_write(bcm, 0x0003, (bcm43xx_phy_read(bcm, 0x0003)
1401 & 0xFFBF) | 0x0040);
1401 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 1402 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
1402 (bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT) | 0x2000)); 1403 (bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT) | 0x2000));
1403 } 1404 }
@@ -1405,7 +1406,7 @@ u16 bcm43xx_radio_init2050(struct bcm43xx_private *bcm)
1405 ret = bcm43xx_radio_calibrationvalue(bcm); 1406 ret = bcm43xx_radio_calibrationvalue(bcm);
1406 1407
1407 if (phy->type == BCM43xx_PHYTYPE_B) 1408 if (phy->type == BCM43xx_PHYTYPE_B)
1408 bcm43xx_radio_write16(bcm, 0x0078, 0x0003); 1409 bcm43xx_radio_write16(bcm, 0x0078, 0x0026);
1409 1410
1410 bcm43xx_phy_write(bcm, 0x0015, 0xBFAF); 1411 bcm43xx_phy_write(bcm, 0x0015, 0xBFAF);
1411 bcm43xx_phy_write(bcm, 0x002B, 0x1403); 1412 bcm43xx_phy_write(bcm, 0x002B, 0x1403);
@@ -1416,7 +1417,7 @@ u16 bcm43xx_radio_init2050(struct bcm43xx_private *bcm)
1416 (bcm43xx_radio_read16(bcm, 0x0051) | 0x0004)); 1417 (bcm43xx_radio_read16(bcm, 0x0051) | 0x0004));
1417 bcm43xx_radio_write16(bcm, 0x0052, 0x0000); 1418 bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
1418 bcm43xx_radio_write16(bcm, 0x0043, 1419 bcm43xx_radio_write16(bcm, 0x0043,
1419 bcm43xx_radio_read16(bcm, 0x0043) | 0x0009); 1420 (bcm43xx_radio_read16(bcm, 0x0043) & 0xFFF0) | 0x0009);
1420 bcm43xx_phy_write(bcm, 0x0058, 0x0000); 1421 bcm43xx_phy_write(bcm, 0x0058, 0x0000);
1421 1422
1422 for (i = 0; i < 16; i++) { 1423 for (i = 0; i < 16; i++) {
@@ -1488,7 +1489,7 @@ u16 bcm43xx_radio_init2050(struct bcm43xx_private *bcm)
1488 bcm43xx_phy_write(bcm, 0x0059, backup[17]); 1489 bcm43xx_phy_write(bcm, 0x0059, backup[17]);
1489 bcm43xx_phy_write(bcm, 0x0058, backup[18]); 1490 bcm43xx_phy_write(bcm, 0x0058, backup[18]);
1490 bcm43xx_write16(bcm, 0x03E6, backup[11]); 1491 bcm43xx_write16(bcm, 0x03E6, backup[11]);
1491 if (phy->version != 0) 1492 if (phy->analog != 0)
1492 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, backup[12]); 1493 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, backup[12]);
1493 bcm43xx_phy_write(bcm, 0x0035, backup[10]); 1494 bcm43xx_phy_write(bcm, 0x0035, backup[10]);
1494 bcm43xx_radio_selectchannel(bcm, radio->channel, 1); 1495 bcm43xx_radio_selectchannel(bcm, radio->channel, 1);
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_wx.c b/drivers/net/wireless/bcm43xx/bcm43xx_wx.c
index d2ca949174..d6d9413d7f 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_wx.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_wx.c
@@ -105,18 +105,24 @@ static int bcm43xx_wx_set_channelfreq(struct net_device *net_dev,
105 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev); 105 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
106 unsigned long flags; 106 unsigned long flags;
107 u8 channel; 107 u8 channel;
108 s8 expon;
108 int freq; 109 int freq;
109 int err = -EINVAL; 110 int err = -EINVAL;
110 111
111 mutex_lock(&bcm->mutex); 112 mutex_lock(&bcm->mutex);
112 spin_lock_irqsave(&bcm->irq_lock, flags); 113 spin_lock_irqsave(&bcm->irq_lock, flags);
113 114
114 if ((data->freq.m >= 0) && (data->freq.m <= 1000)) { 115 if ((data->freq.e == 0) &&
116 (data->freq.m >= 0) && (data->freq.m <= 1000)) {
115 channel = data->freq.m; 117 channel = data->freq.m;
116 freq = bcm43xx_channel_to_freq(bcm, channel); 118 freq = bcm43xx_channel_to_freq(bcm, channel);
117 } else { 119 } else {
118 channel = bcm43xx_freq_to_channel(bcm, data->freq.m);
119 freq = data->freq.m; 120 freq = data->freq.m;
121 expon = 6 - data->freq.e;
122 while (--expon >= 0) /* scale down the frequency to MHz */
123 freq /= 10;
124 assert(freq > 1000);
125 channel = bcm43xx_freq_to_channel(bcm, freq);
120 } 126 }
121 if (!ieee80211_is_valid_channel(bcm->ieee, channel)) 127 if (!ieee80211_is_valid_channel(bcm->ieee, channel))
122 goto out_unlock; 128 goto out_unlock;
@@ -260,22 +266,22 @@ static int bcm43xx_wx_get_rangeparams(struct net_device *net_dev,
260 if (phy->type == BCM43xx_PHYTYPE_A || 266 if (phy->type == BCM43xx_PHYTYPE_A ||
261 phy->type == BCM43xx_PHYTYPE_G) { 267 phy->type == BCM43xx_PHYTYPE_G) {
262 range->num_bitrates = 8; 268 range->num_bitrates = 8;
263 range->bitrate[i++] = IEEE80211_OFDM_RATE_6MB; 269 range->bitrate[i++] = IEEE80211_OFDM_RATE_6MB * 500000;
264 range->bitrate[i++] = IEEE80211_OFDM_RATE_9MB; 270 range->bitrate[i++] = IEEE80211_OFDM_RATE_9MB * 500000;
265 range->bitrate[i++] = IEEE80211_OFDM_RATE_12MB; 271 range->bitrate[i++] = IEEE80211_OFDM_RATE_12MB * 500000;
266 range->bitrate[i++] = IEEE80211_OFDM_RATE_18MB; 272 range->bitrate[i++] = IEEE80211_OFDM_RATE_18MB * 500000;
267 range->bitrate[i++] = IEEE80211_OFDM_RATE_24MB; 273 range->bitrate[i++] = IEEE80211_OFDM_RATE_24MB * 500000;
268 range->bitrate[i++] = IEEE80211_OFDM_RATE_36MB; 274 range->bitrate[i++] = IEEE80211_OFDM_RATE_36MB * 500000;
269 range->bitrate[i++] = IEEE80211_OFDM_RATE_48MB; 275 range->bitrate[i++] = IEEE80211_OFDM_RATE_48MB * 500000;
270 range->bitrate[i++] = IEEE80211_OFDM_RATE_54MB; 276 range->bitrate[i++] = IEEE80211_OFDM_RATE_54MB * 500000;
271 } 277 }
272 if (phy->type == BCM43xx_PHYTYPE_B || 278 if (phy->type == BCM43xx_PHYTYPE_B ||
273 phy->type == BCM43xx_PHYTYPE_G) { 279 phy->type == BCM43xx_PHYTYPE_G) {
274 range->num_bitrates += 4; 280 range->num_bitrates += 4;
275 range->bitrate[i++] = IEEE80211_CCK_RATE_1MB; 281 range->bitrate[i++] = IEEE80211_CCK_RATE_1MB * 500000;
276 range->bitrate[i++] = IEEE80211_CCK_RATE_2MB; 282 range->bitrate[i++] = IEEE80211_CCK_RATE_2MB * 500000;
277 range->bitrate[i++] = IEEE80211_CCK_RATE_5MB; 283 range->bitrate[i++] = IEEE80211_CCK_RATE_5MB * 500000;
278 range->bitrate[i++] = IEEE80211_CCK_RATE_11MB; 284 range->bitrate[i++] = IEEE80211_CCK_RATE_11MB * 500000;
279 } 285 }
280 286
281 geo = ieee80211_get_geo(bcm->ieee); 287 geo = ieee80211_get_geo(bcm->ieee);
@@ -285,7 +291,7 @@ static int bcm43xx_wx_get_rangeparams(struct net_device *net_dev,
285 if (j == IW_MAX_FREQUENCIES) 291 if (j == IW_MAX_FREQUENCIES)
286 break; 292 break;
287 range->freq[j].i = j + 1; 293 range->freq[j].i = j + 1;
288 range->freq[j].m = geo->a[i].freq;//FIXME? 294 range->freq[j].m = geo->a[i].freq * 100000;
289 range->freq[j].e = 1; 295 range->freq[j].e = 1;
290 j++; 296 j++;
291 } 297 }
@@ -293,7 +299,7 @@ static int bcm43xx_wx_get_rangeparams(struct net_device *net_dev,
293 if (j == IW_MAX_FREQUENCIES) 299 if (j == IW_MAX_FREQUENCIES)
294 break; 300 break;
295 range->freq[j].i = j + 1; 301 range->freq[j].i = j + 1;
296 range->freq[j].m = geo->bg[i].freq;//FIXME? 302 range->freq[j].m = geo->bg[i].freq * 100000;
297 range->freq[j].e = 1; 303 range->freq[j].e = 1;
298 j++; 304 j++;
299 } 305 }
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_xmit.h b/drivers/net/wireless/bcm43xx/bcm43xx_xmit.h
index 2aed19e35c..9ecf2bf0d2 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_xmit.h
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_xmit.h
@@ -137,14 +137,8 @@ struct bcm43xx_xmitstatus {
137 u16 unknown; //FIXME 137 u16 unknown; //FIXME
138}; 138};
139 139
140#define BCM43xx_TXSTAT_FLAG_ACK 0x01 140#define BCM43xx_TXSTAT_FLAG_AMPDU 0x10
141//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x02 141#define BCM43xx_TXSTAT_FLAG_INTER 0x20
142//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x04
143//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x08
144//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x10
145#define BCM43xx_TXSTAT_FLAG_IGNORE 0x20
146//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x40
147//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x80
148 142
149u8 bcm43xx_plcp_get_ratecode_cck(const u8 bitrate); 143u8 bcm43xx_plcp_get_ratecode_cck(const u8 bitrate);
150u8 bcm43xx_plcp_get_ratecode_ofdm(const u8 bitrate); 144u8 bcm43xx_plcp_get_ratecode_ofdm(const u8 bitrate);
diff --git a/drivers/net/wireless/hostap/hostap.h b/drivers/net/wireless/hostap/hostap.h
index e89c890d16..ef37a75d55 100644
--- a/drivers/net/wireless/hostap/hostap.h
+++ b/drivers/net/wireless/hostap/hostap.h
@@ -2,13 +2,14 @@
2#define HOSTAP_H 2#define HOSTAP_H
3 3
4#include <linux/ethtool.h> 4#include <linux/ethtool.h>
5#include <linux/kernel.h>
5 6
6#include "hostap_wlan.h" 7#include "hostap_wlan.h"
7#include "hostap_ap.h" 8#include "hostap_ap.h"
8 9
9static const long freq_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442, 10static const long freq_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
10 2447, 2452, 2457, 2462, 2467, 2472, 2484 }; 11 2447, 2452, 2457, 2462, 2467, 2472, 2484 };
11#define FREQ_COUNT (sizeof(freq_list) / sizeof(freq_list[0])) 12#define FREQ_COUNT ARRAY_SIZE(freq_list)
12 13
13/* hostap.c */ 14/* hostap.c */
14 15
diff --git a/drivers/net/wireless/ipw2100.c b/drivers/net/wireless/ipw2100.c
index b85857a848..ad6e4a4283 100644
--- a/drivers/net/wireless/ipw2100.c
+++ b/drivers/net/wireless/ipw2100.c
@@ -175,7 +175,7 @@ that only one external action is invoked at a time.
175 175
176/* Debugging stuff */ 176/* Debugging stuff */
177#ifdef CONFIG_IPW2100_DEBUG 177#ifdef CONFIG_IPW2100_DEBUG
178#define CONFIG_IPW2100_RX_DEBUG /* Reception debugging */ 178#define IPW2100_RX_DEBUG /* Reception debugging */
179#endif 179#endif
180 180
181MODULE_DESCRIPTION(DRV_DESCRIPTION); 181MODULE_DESCRIPTION(DRV_DESCRIPTION);
@@ -2239,7 +2239,7 @@ static void ipw2100_snapshot_free(struct ipw2100_priv *priv)
2239 priv->snapshot[0] = NULL; 2239 priv->snapshot[0] = NULL;
2240} 2240}
2241 2241
2242#ifdef CONFIG_IPW2100_DEBUG_C3 2242#ifdef IPW2100_DEBUG_C3
2243static int ipw2100_snapshot_alloc(struct ipw2100_priv *priv) 2243static int ipw2100_snapshot_alloc(struct ipw2100_priv *priv)
2244{ 2244{
2245 int i; 2245 int i;
@@ -2314,13 +2314,13 @@ static u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 * in_buf,
2314 * The size of the constructed ethernet 2314 * The size of the constructed ethernet
2315 * 2315 *
2316 */ 2316 */
2317#ifdef CONFIG_IPW2100_RX_DEBUG 2317#ifdef IPW2100_RX_DEBUG
2318static u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH]; 2318static u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH];
2319#endif 2319#endif
2320 2320
2321static void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i) 2321static void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i)
2322{ 2322{
2323#ifdef CONFIG_IPW2100_DEBUG_C3 2323#ifdef IPW2100_DEBUG_C3
2324 struct ipw2100_status *status = &priv->status_queue.drv[i]; 2324 struct ipw2100_status *status = &priv->status_queue.drv[i];
2325 u32 match, reg; 2325 u32 match, reg;
2326 int j; 2326 int j;
@@ -2342,7 +2342,7 @@ static void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i)
2342 } 2342 }
2343#endif 2343#endif
2344 2344
2345#ifdef CONFIG_IPW2100_DEBUG_C3 2345#ifdef IPW2100_DEBUG_C3
2346 /* Halt the fimrware so we can get a good image */ 2346 /* Halt the fimrware so we can get a good image */
2347 write_register(priv->net_dev, IPW_REG_RESET_REG, 2347 write_register(priv->net_dev, IPW_REG_RESET_REG,
2348 IPW_AUX_HOST_RESET_REG_STOP_MASTER); 2348 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
@@ -2413,7 +2413,7 @@ static void isr_rx(struct ipw2100_priv *priv, int i,
2413 2413
2414 skb_put(packet->skb, status->frame_size); 2414 skb_put(packet->skb, status->frame_size);
2415 2415
2416#ifdef CONFIG_IPW2100_RX_DEBUG 2416#ifdef IPW2100_RX_DEBUG
2417 /* Make a copy of the frame so we can dump it to the logs if 2417 /* Make a copy of the frame so we can dump it to the logs if
2418 * ieee80211_rx fails */ 2418 * ieee80211_rx fails */
2419 memcpy(packet_data, packet->skb->data, 2419 memcpy(packet_data, packet->skb->data,
@@ -2421,7 +2421,7 @@ static void isr_rx(struct ipw2100_priv *priv, int i,
2421#endif 2421#endif
2422 2422
2423 if (!ieee80211_rx(priv->ieee, packet->skb, stats)) { 2423 if (!ieee80211_rx(priv->ieee, packet->skb, stats)) {
2424#ifdef CONFIG_IPW2100_RX_DEBUG 2424#ifdef IPW2100_RX_DEBUG
2425 IPW_DEBUG_DROP("%s: Non consumed packet:\n", 2425 IPW_DEBUG_DROP("%s: Non consumed packet:\n",
2426 priv->net_dev->name); 2426 priv->net_dev->name);
2427 printk_buf(IPW_DL_DROP, packet_data, status->frame_size); 2427 printk_buf(IPW_DL_DROP, packet_data, status->frame_size);
@@ -2888,7 +2888,7 @@ static int __ipw2100_tx_process(struct ipw2100_priv *priv)
2888 2888
2889#ifdef CONFIG_IPW2100_DEBUG 2889#ifdef CONFIG_IPW2100_DEBUG
2890 if (packet->info.c_struct.cmd->host_command_reg < 2890 if (packet->info.c_struct.cmd->host_command_reg <
2891 sizeof(command_types) / sizeof(*command_types)) 2891 ARRAY_SIZE(command_types))
2892 IPW_DEBUG_TX("Command '%s (%d)' processed: %d.\n", 2892 IPW_DEBUG_TX("Command '%s (%d)' processed: %d.\n",
2893 command_types[packet->info.c_struct.cmd-> 2893 command_types[packet->info.c_struct.cmd->
2894 host_command_reg], 2894 host_command_reg],
@@ -3736,7 +3736,7 @@ static ssize_t show_registers(struct device *d, struct device_attribute *attr,
3736 3736
3737 out += sprintf(out, "%30s [Address ] : Hex\n", "Register"); 3737 out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
3738 3738
3739 for (i = 0; i < (sizeof(hw_data) / sizeof(*hw_data)); i++) { 3739 for (i = 0; i < ARRAY_SIZE(hw_data); i++) {
3740 read_register(dev, hw_data[i].addr, &val); 3740 read_register(dev, hw_data[i].addr, &val);
3741 out += sprintf(out, "%30s [%08X] : %08X\n", 3741 out += sprintf(out, "%30s [%08X] : %08X\n",
3742 hw_data[i].name, hw_data[i].addr, val); 3742 hw_data[i].name, hw_data[i].addr, val);
@@ -3757,7 +3757,7 @@ static ssize_t show_hardware(struct device *d, struct device_attribute *attr,
3757 3757
3758 out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry"); 3758 out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
3759 3759
3760 for (i = 0; i < (sizeof(nic_data) / sizeof(*nic_data)); i++) { 3760 for (i = 0; i < ARRAY_SIZE(nic_data); i++) {
3761 u8 tmp8; 3761 u8 tmp8;
3762 u16 tmp16; 3762 u16 tmp16;
3763 u32 tmp32; 3763 u32 tmp32;
@@ -3894,13 +3894,11 @@ static ssize_t show_ordinals(struct device *d, struct device_attribute *attr,
3894 if (priv->status & STATUS_RF_KILL_MASK) 3894 if (priv->status & STATUS_RF_KILL_MASK)
3895 return 0; 3895 return 0;
3896 3896
3897 if (loop >= sizeof(ord_data) / sizeof(*ord_data)) 3897 if (loop >= ARRAY_SIZE(ord_data))
3898 loop = 0; 3898 loop = 0;
3899 3899
3900 /* sysfs provides us PAGE_SIZE buffer */ 3900 /* sysfs provides us PAGE_SIZE buffer */
3901 while (len < PAGE_SIZE - 128 && 3901 while (len < PAGE_SIZE - 128 && loop < ARRAY_SIZE(ord_data)) {
3902 loop < (sizeof(ord_data) / sizeof(*ord_data))) {
3903
3904 val_len = sizeof(u32); 3902 val_len = sizeof(u32);
3905 3903
3906 if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val, 3904 if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
@@ -4912,7 +4910,7 @@ static int ipw2100_set_power_mode(struct ipw2100_priv *priv, int power_level)
4912 else 4910 else
4913 priv->power_mode = IPW_POWER_ENABLED | power_level; 4911 priv->power_mode = IPW_POWER_ENABLED | power_level;
4914 4912
4915#ifdef CONFIG_IPW2100_TX_POWER 4913#ifdef IPW2100_TX_POWER
4916 if (priv->port_type == IBSS && priv->adhoc_power != DFTL_IBSS_TX_POWER) { 4914 if (priv->port_type == IBSS && priv->adhoc_power != DFTL_IBSS_TX_POWER) {
4917 /* Set beacon interval */ 4915 /* Set beacon interval */
4918 cmd.host_command = TX_POWER_INDEX; 4916 cmd.host_command = TX_POWER_INDEX;
@@ -6589,7 +6587,7 @@ static const long ipw2100_rates_11b[] = {
6589 11000000 6587 11000000
6590}; 6588};
6591 6589
6592#define RATE_COUNT (sizeof(ipw2100_rates_11b) / sizeof(ipw2100_rates_11b[0])) 6590#define RATE_COUNT ARRAY_SIZE(ipw2100_rates_11b)
6593 6591
6594static int ipw2100_wx_get_name(struct net_device *dev, 6592static int ipw2100_wx_get_name(struct net_device *dev,
6595 struct iw_request_info *info, 6593 struct iw_request_info *info,
diff --git a/drivers/net/wireless/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c
index 838d510213..841b3c136a 100644
--- a/drivers/net/wireless/prism54/isl_ioctl.c
+++ b/drivers/net/wireless/prism54/isl_ioctl.c
@@ -1395,11 +1395,16 @@ static int prism54_set_auth(struct net_device *ndev,
1395 break; 1395 break;
1396 1396
1397 case IW_AUTH_RX_UNENCRYPTED_EAPOL: 1397 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1398 dot1x = param->value ? 1 : 0; 1398 /* dot1x should be the opposite of RX_UNENCRYPTED_EAPOL;
1399 * turn off dot1x when allowing receipt of unencrypted EAPOL
1400 * frames, turn on dot1x when receipt should be disallowed
1401 */
1402 dot1x = param->value ? 0 : 0x01;
1399 break; 1403 break;
1400 1404
1401 case IW_AUTH_PRIVACY_INVOKED: 1405 case IW_AUTH_PRIVACY_INVOKED:
1402 privinvoked = param->value ? 1 : 0; 1406 privinvoked = param->value ? 1 : 0;
1407 break;
1403 1408
1404 case IW_AUTH_DROP_UNENCRYPTED: 1409 case IW_AUTH_DROP_UNENCRYPTED:
1405 exunencrypt = param->value ? 1 : 0; 1410 exunencrypt = param->value ? 1 : 0;
@@ -1589,6 +1594,7 @@ static int prism54_set_encodeext(struct net_device *ndev,
1589 } 1594 }
1590 key.type = DOT11_PRIV_TKIP; 1595 key.type = DOT11_PRIV_TKIP;
1591 key.length = KEY_SIZE_TKIP; 1596 key.length = KEY_SIZE_TKIP;
1597 break;
1592 default: 1598 default:
1593 return -EINVAL; 1599 return -EINVAL;
1594 } 1600 }
diff --git a/drivers/net/wireless/prism54/oid_mgt.c b/drivers/net/wireless/prism54/oid_mgt.c
index e6cf9df2c2..42780320cd 100644
--- a/drivers/net/wireless/prism54/oid_mgt.c
+++ b/drivers/net/wireless/prism54/oid_mgt.c
@@ -16,6 +16,8 @@
16 * 16 *
17 */ 17 */
18 18
19#include <linux/kernel.h>
20
19#include "prismcompat.h" 21#include "prismcompat.h"
20#include "islpci_dev.h" 22#include "islpci_dev.h"
21#include "islpci_mgt.h" 23#include "islpci_mgt.h"
@@ -692,7 +694,7 @@ mgt_update_addr(islpci_private *priv)
692 return ret; 694 return ret;
693} 695}
694 696
695#define VEC_SIZE(a) (sizeof(a)/sizeof(a[0])) 697#define VEC_SIZE(a) ARRAY_SIZE(a)
696 698
697int 699int
698mgt_commit(islpci_private *priv) 700mgt_commit(islpci_private *priv)
diff --git a/drivers/net/wireless/wavelan.c b/drivers/net/wireless/wavelan.c
index 24221e476c..2aa3c761dd 100644
--- a/drivers/net/wireless/wavelan.c
+++ b/drivers/net/wireless/wavelan.c
@@ -28,7 +28,7 @@
28 */ 28 */
29static u8 wv_irq_to_psa(int irq) 29static u8 wv_irq_to_psa(int irq)
30{ 30{
31 if (irq < 0 || irq >= NELS(irqvals)) 31 if (irq < 0 || irq >= ARRAY_SIZE(irqvals))
32 return 0; 32 return 0;
33 33
34 return irqvals[irq]; 34 return irqvals[irq];
@@ -42,7 +42,7 @@ static int __init wv_psa_to_irq(u8 irqval)
42{ 42{
43 int irq; 43 int irq;
44 44
45 for (irq = 0; irq < NELS(irqvals); irq++) 45 for (irq = 0; irq < ARRAY_SIZE(irqvals); irq++)
46 if (irqvals[irq] == irqval) 46 if (irqvals[irq] == irqval)
47 return irq; 47 return irq;
48 48
@@ -1695,7 +1695,7 @@ static int wv_frequency_list(unsigned long ioaddr, /* I/O port of the card */
1695 /* Look in the table if the frequency is allowed */ 1695 /* Look in the table if the frequency is allowed */
1696 if (table[9 - (freq / 16)] & (1 << (freq % 16))) { 1696 if (table[9 - (freq / 16)] & (1 << (freq % 16))) {
1697 /* Compute approximate channel number */ 1697 /* Compute approximate channel number */
1698 while ((c < NELS(channel_bands)) && 1698 while ((c < ARRAY_SIZE(channel_bands)) &&
1699 (((channel_bands[c] >> 1) - 24) < freq)) 1699 (((channel_bands[c] >> 1) - 24) < freq))
1700 c++; 1700 c++;
1701 list[i].i = c; /* Set the list index */ 1701 list[i].i = c; /* Set the list index */
@@ -4269,7 +4269,7 @@ struct net_device * __init wavelan_probe(int unit)
4269 printk(KERN_DEBUG "%s: <-wavelan_probe()\n", dev->name); 4269 printk(KERN_DEBUG "%s: <-wavelan_probe()\n", dev->name);
4270#endif 4270#endif
4271 } else { /* Scan all possible addresses of the WaveLAN hardware. */ 4271 } else { /* Scan all possible addresses of the WaveLAN hardware. */
4272 for (i = 0; i < NELS(iobase); i++) { 4272 for (i = 0; i < ARRAY_SIZE(iobase); i++) {
4273 dev->irq = def_irq; 4273 dev->irq = def_irq;
4274 if (wavelan_config(dev, iobase[i]) == 0) { 4274 if (wavelan_config(dev, iobase[i]) == 0) {
4275#ifdef DEBUG_CALLBACK_TRACE 4275#ifdef DEBUG_CALLBACK_TRACE
@@ -4280,7 +4280,7 @@ struct net_device * __init wavelan_probe(int unit)
4280 break; 4280 break;
4281 } 4281 }
4282 } 4282 }
4283 if (i == NELS(iobase)) 4283 if (i == ARRAY_SIZE(iobase))
4284 r = -ENODEV; 4284 r = -ENODEV;
4285 } 4285 }
4286 if (r) 4286 if (r)
@@ -4327,14 +4327,14 @@ int __init init_module(void)
4327#endif 4327#endif
4328 4328
4329 /* Copy the basic set of address to be probed. */ 4329 /* Copy the basic set of address to be probed. */
4330 for (i = 0; i < NELS(iobase); i++) 4330 for (i = 0; i < ARRAY_SIZE(iobase); i++)
4331 io[i] = iobase[i]; 4331 io[i] = iobase[i];
4332 } 4332 }
4333 4333
4334 4334
4335 /* Loop on all possible base addresses. */ 4335 /* Loop on all possible base addresses. */
4336 i = -1; 4336 i = -1;
4337 while ((io[++i] != 0) && (i < NELS(io))) { 4337 while ((io[++i] != 0) && (i < ARRAY_SIZE(io))) {
4338 struct net_device *dev = alloc_etherdev(sizeof(net_local)); 4338 struct net_device *dev = alloc_etherdev(sizeof(net_local));
4339 if (!dev) 4339 if (!dev)
4340 break; 4340 break;
diff --git a/drivers/net/wireless/wavelan.p.h b/drivers/net/wireless/wavelan.p.h
index 72b646c77d..fe242812d8 100644
--- a/drivers/net/wireless/wavelan.p.h
+++ b/drivers/net/wireless/wavelan.p.h
@@ -449,9 +449,6 @@ static const char *version = "wavelan.c : v24 (SMP + wireless extensions) 11/12/
449/* Watchdog temporisation */ 449/* Watchdog temporisation */
450#define WATCHDOG_JIFFIES (512*HZ/100) 450#define WATCHDOG_JIFFIES (512*HZ/100)
451 451
452/* Macro to get the number of elements in an array */
453#define NELS(a) (sizeof(a) / sizeof(a[0]))
454
455/* ------------------------ PRIVATE IOCTL ------------------------ */ 452/* ------------------------ PRIVATE IOCTL ------------------------ */
456 453
457#define SIOCSIPQTHR SIOCIWFIRSTPRIV /* Set quality threshold */ 454#define SIOCSIPQTHR SIOCIWFIRSTPRIV /* Set quality threshold */
diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c
index 5eb81638e8..b04239792f 100644
--- a/drivers/net/wireless/wavelan_cs.c
+++ b/drivers/net/wireless/wavelan_cs.c
@@ -1168,7 +1168,7 @@ wv_mmc_show(struct net_device * dev)
1168 m.mmr_unused0[6], 1168 m.mmr_unused0[6],
1169 m.mmr_unused0[7]); 1169 m.mmr_unused0[7]);
1170#endif /* DEBUG_SHOW_UNUSED */ 1170#endif /* DEBUG_SHOW_UNUSED */
1171 printk(KERN_DEBUG "Encryption algorythm: %02X - Status: %02X\n", 1171 printk(KERN_DEBUG "Encryption algorithm: %02X - Status: %02X\n",
1172 m.mmr_des_avail, m.mmr_des_status); 1172 m.mmr_des_avail, m.mmr_des_status);
1173#ifdef DEBUG_SHOW_UNUSED 1173#ifdef DEBUG_SHOW_UNUSED
1174 printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n", 1174 printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n",
@@ -3590,9 +3590,9 @@ wv_82593_config(struct net_device * dev)
3590 cfblk.acloc = TRUE; /* Disable source addr insertion by i82593 */ 3590 cfblk.acloc = TRUE; /* Disable source addr insertion by i82593 */
3591 cfblk.preamb_len = 0; /* 2 bytes preamble (SFD) */ 3591 cfblk.preamb_len = 0; /* 2 bytes preamble (SFD) */
3592 cfblk.loopback = FALSE; 3592 cfblk.loopback = FALSE;
3593 cfblk.lin_prio = 0; /* conform to 802.3 backoff algoritm */ 3593 cfblk.lin_prio = 0; /* conform to 802.3 backoff algorithm */
3594 cfblk.exp_prio = 5; /* conform to 802.3 backoff algoritm */ 3594 cfblk.exp_prio = 5; /* conform to 802.3 backoff algorithm */
3595 cfblk.bof_met = 1; /* conform to 802.3 backoff algoritm */ 3595 cfblk.bof_met = 1; /* conform to 802.3 backoff algorithm */
3596 cfblk.ifrm_spc = 0x20 >> 4; /* 32 bit times interframe spacing */ 3596 cfblk.ifrm_spc = 0x20 >> 4; /* 32 bit times interframe spacing */
3597 cfblk.slottim_low = 0x20 >> 5; /* 32 bit times slot time */ 3597 cfblk.slottim_low = 0x20 >> 5; /* 32 bit times slot time */
3598 cfblk.slottim_hi = 0x0; 3598 cfblk.slottim_hi = 0x0;
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index c250f08c8d..ce9230b2f6 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -26,7 +26,6 @@
26 * Tested with Planet AP in 2.5.73-bk, 216 Kbytes/s in Infrastructure mode 26 * Tested with Planet AP in 2.5.73-bk, 216 Kbytes/s in Infrastructure mode
27 * with a SMP machine (dual pentium 100), using pktgen, 432 pps (pkt_size = 60) 27 * with a SMP machine (dual pentium 100), using pktgen, 432 pps (pkt_size = 60)
28 */ 28 */
29#undef REALLY_SLOW_IO /* most systems can safely undef this */
30 29
31#include <linux/delay.h> 30#include <linux/delay.h>
32#include <linux/types.h> 31#include <linux/types.h>
diff --git a/drivers/net/wireless/zd1211rw/zd_chip.c b/drivers/net/wireless/zd1211rw/zd_chip.c
index 12dfc0b6ef..9c64f894b7 100644
--- a/drivers/net/wireless/zd1211rw/zd_chip.c
+++ b/drivers/net/wireless/zd1211rw/zd_chip.c
@@ -113,7 +113,7 @@ int zd_ioread32v_locked(struct zd_chip *chip, u32 *values, const zd_addr_t *addr
113 113
114 /* Allocate a single memory block for values and addresses. */ 114 /* Allocate a single memory block for values and addresses. */
115 count16 = 2*count; 115 count16 = 2*count;
116 a16 = kmalloc(count16 * (sizeof(zd_addr_t) + sizeof(u16)), 116 a16 = (zd_addr_t *) kmalloc(count16 * (sizeof(zd_addr_t) + sizeof(u16)),
117 GFP_NOFS); 117 GFP_NOFS);
118 if (!a16) { 118 if (!a16) {
119 dev_dbg_f(zd_chip_dev(chip), 119 dev_dbg_f(zd_chip_dev(chip),
diff --git a/drivers/net/wireless/zd1211rw/zd_mac.c b/drivers/net/wireless/zd1211rw/zd_mac.c
index a08524191b..4c5f78eac3 100644
--- a/drivers/net/wireless/zd1211rw/zd_mac.c
+++ b/drivers/net/wireless/zd1211rw/zd_mac.c
@@ -156,7 +156,7 @@ void zd_mac_clear(struct zd_mac *mac)
156static int reset_mode(struct zd_mac *mac) 156static int reset_mode(struct zd_mac *mac)
157{ 157{
158 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac); 158 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
159 struct zd_ioreq32 ioreqs[3] = { 159 struct zd_ioreq32 ioreqs[] = {
160 { CR_RX_FILTER, STA_RX_FILTER }, 160 { CR_RX_FILTER, STA_RX_FILTER },
161 { CR_SNIFFER_ON, 0U }, 161 { CR_SNIFFER_ON, 0U },
162 }; 162 };
@@ -164,10 +164,9 @@ static int reset_mode(struct zd_mac *mac)
164 if (ieee->iw_mode == IW_MODE_MONITOR) { 164 if (ieee->iw_mode == IW_MODE_MONITOR) {
165 ioreqs[0].value = 0xffffffff; 165 ioreqs[0].value = 0xffffffff;
166 ioreqs[1].value = 0x1; 166 ioreqs[1].value = 0x1;
167 ioreqs[2].value = ENC_SNIFFER;
168 } 167 }
169 168
170 return zd_iowrite32a(&mac->chip, ioreqs, 3); 169 return zd_iowrite32a(&mac->chip, ioreqs, ARRAY_SIZE(ioreqs));
171} 170}
172 171
173int zd_mac_open(struct net_device *netdev) 172int zd_mac_open(struct net_device *netdev)
@@ -904,16 +903,21 @@ static int fill_ctrlset(struct zd_mac *mac,
904static int zd_mac_tx(struct zd_mac *mac, struct ieee80211_txb *txb, int pri) 903static int zd_mac_tx(struct zd_mac *mac, struct ieee80211_txb *txb, int pri)
905{ 904{
906 int i, r; 905 int i, r;
906 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
907 907
908 for (i = 0; i < txb->nr_frags; i++) { 908 for (i = 0; i < txb->nr_frags; i++) {
909 struct sk_buff *skb = txb->fragments[i]; 909 struct sk_buff *skb = txb->fragments[i];
910 910
911 r = fill_ctrlset(mac, txb, i); 911 r = fill_ctrlset(mac, txb, i);
912 if (r) 912 if (r) {
913 ieee->stats.tx_dropped++;
913 return r; 914 return r;
915 }
914 r = zd_usb_tx(&mac->chip.usb, skb->data, skb->len); 916 r = zd_usb_tx(&mac->chip.usb, skb->data, skb->len);
915 if (r) 917 if (r) {
918 ieee->stats.tx_dropped++;
916 return r; 919 return r;
920 }
917 } 921 }
918 922
919 /* FIXME: shouldn't this be handled by the upper layers? */ 923 /* FIXME: shouldn't this be handled by the upper layers? */
@@ -1063,9 +1067,23 @@ static int fill_rx_stats(struct ieee80211_rx_stats *stats,
1063 1067
1064 *pstatus = status = zd_tail(buffer, length, sizeof(struct rx_status)); 1068 *pstatus = status = zd_tail(buffer, length, sizeof(struct rx_status));
1065 if (status->frame_status & ZD_RX_ERROR) { 1069 if (status->frame_status & ZD_RX_ERROR) {
1066 /* FIXME: update? */ 1070 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
1071 ieee->stats.rx_errors++;
1072 if (status->frame_status & ZD_RX_TIMEOUT_ERROR)
1073 ieee->stats.rx_missed_errors++;
1074 else if (status->frame_status & ZD_RX_FIFO_OVERRUN_ERROR)
1075 ieee->stats.rx_fifo_errors++;
1076 else if (status->frame_status & ZD_RX_DECRYPTION_ERROR)
1077 ieee->ieee_stats.rx_discards_undecryptable++;
1078 else if (status->frame_status & ZD_RX_CRC32_ERROR) {
1079 ieee->stats.rx_crc_errors++;
1080 ieee->ieee_stats.rx_fcs_errors++;
1081 }
1082 else if (status->frame_status & ZD_RX_CRC16_ERROR)
1083 ieee->stats.rx_crc_errors++;
1067 return -EINVAL; 1084 return -EINVAL;
1068 } 1085 }
1086
1069 memset(stats, 0, sizeof(struct ieee80211_rx_stats)); 1087 memset(stats, 0, sizeof(struct ieee80211_rx_stats));
1070 stats->len = length - (ZD_PLCP_HEADER_SIZE + IEEE80211_FCS_LEN + 1088 stats->len = length - (ZD_PLCP_HEADER_SIZE + IEEE80211_FCS_LEN +
1071 + sizeof(struct rx_status)); 1089 + sizeof(struct rx_status));
@@ -1094,14 +1112,16 @@ static void zd_mac_rx(struct zd_mac *mac, struct sk_buff *skb)
1094 if (skb->len < ZD_PLCP_HEADER_SIZE + IEEE80211_1ADDR_LEN + 1112 if (skb->len < ZD_PLCP_HEADER_SIZE + IEEE80211_1ADDR_LEN +
1095 IEEE80211_FCS_LEN + sizeof(struct rx_status)) 1113 IEEE80211_FCS_LEN + sizeof(struct rx_status))
1096 { 1114 {
1097 dev_dbg_f(zd_mac_dev(mac), "Packet with length %u to small.\n", 1115 ieee->stats.rx_errors++;
1098 skb->len); 1116 ieee->stats.rx_length_errors++;
1099 goto free_skb; 1117 goto free_skb;
1100 } 1118 }
1101 1119
1102 r = fill_rx_stats(&stats, &status, mac, skb->data, skb->len); 1120 r = fill_rx_stats(&stats, &status, mac, skb->data, skb->len);
1103 if (r) { 1121 if (r) {
1104 /* Only packets with rx errors are included here. */ 1122 /* Only packets with rx errors are included here.
1123 * The error stats have already been set in fill_rx_stats.
1124 */
1105 goto free_skb; 1125 goto free_skb;
1106 } 1126 }
1107 1127
@@ -1114,8 +1134,10 @@ static void zd_mac_rx(struct zd_mac *mac, struct sk_buff *skb)
1114 1134
1115 r = filter_rx(ieee, skb->data, skb->len, &stats); 1135 r = filter_rx(ieee, skb->data, skb->len, &stats);
1116 if (r <= 0) { 1136 if (r <= 0) {
1117 if (r < 0) 1137 if (r < 0) {
1138 ieee->stats.rx_errors++;
1118 dev_dbg_f(zd_mac_dev(mac), "Error in packet.\n"); 1139 dev_dbg_f(zd_mac_dev(mac), "Error in packet.\n");
1140 }
1119 goto free_skb; 1141 goto free_skb;
1120 } 1142 }
1121 1143
@@ -1146,7 +1168,9 @@ int zd_mac_rx_irq(struct zd_mac *mac, const u8 *buffer, unsigned int length)
1146 1168
1147 skb = dev_alloc_skb(sizeof(struct zd_rt_hdr) + length); 1169 skb = dev_alloc_skb(sizeof(struct zd_rt_hdr) + length);
1148 if (!skb) { 1170 if (!skb) {
1171 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
1149 dev_warn(zd_mac_dev(mac), "Could not allocate skb.\n"); 1172 dev_warn(zd_mac_dev(mac), "Could not allocate skb.\n");
1173 ieee->stats.rx_dropped++;
1150 return -ENOMEM; 1174 return -ENOMEM;
1151 } 1175 }
1152 skb_reserve(skb, sizeof(struct zd_rt_hdr)); 1176 skb_reserve(skb, sizeof(struct zd_rt_hdr));
diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
index 75ef55624d..aac8a1c5ba 100644
--- a/drivers/net/wireless/zd1211rw/zd_usb.c
+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
@@ -313,6 +313,12 @@ out:
313 313
314static inline void handle_retry_failed_int(struct urb *urb) 314static inline void handle_retry_failed_int(struct urb *urb)
315{ 315{
316 struct zd_usb *usb = urb->context;
317 struct zd_mac *mac = zd_usb_to_mac(usb);
318 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
319
320 ieee->stats.tx_errors++;
321 ieee->ieee_stats.tx_retry_limit_exceeded++;
316 dev_dbg_f(urb_dev(urb), "retry failed interrupt\n"); 322 dev_dbg_f(urb_dev(urb), "retry failed interrupt\n");
317} 323}
318 324
@@ -487,6 +493,9 @@ static void handle_rx_packet(struct zd_usb *usb, const u8 *buffer,
487 493
488 if (length < sizeof(struct rx_length_info)) { 494 if (length < sizeof(struct rx_length_info)) {
489 /* It's not a complete packet anyhow. */ 495 /* It's not a complete packet anyhow. */
496 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
497 ieee->stats.rx_errors++;
498 ieee->stats.rx_length_errors++;
490 return; 499 return;
491 } 500 }
492 length_info = (struct rx_length_info *) 501 length_info = (struct rx_length_info *)
@@ -923,6 +932,8 @@ static int probe(struct usb_interface *intf, const struct usb_device_id *id)
923 goto error; 932 goto error;
924 } 933 }
925 934
935 usb_reset_device(interface_to_usbdev(intf));
936
926 netdev = zd_netdev_alloc(intf); 937 netdev = zd_netdev_alloc(intf);
927 if (netdev == NULL) { 938 if (netdev == NULL) {
928 r = -ENOMEM; 939 r = -ENOMEM;
@@ -1024,6 +1035,7 @@ static int __init usb_init(void)
1024 1035
1025 r = usb_register(&driver); 1036 r = usb_register(&driver);
1026 if (r) { 1037 if (r) {
1038 destroy_workqueue(zd_workqueue);
1027 printk(KERN_ERR "%s usb_register() failed. Error number %d\n", 1039 printk(KERN_ERR "%s usb_register() failed. Error number %d\n",
1028 driver.name, r); 1040 driver.name, r);
1029 return r; 1041 return r;
diff --git a/drivers/parisc/hppb.c b/drivers/parisc/hppb.c
index 07dc2b6d4e..9bb4db552f 100644
--- a/drivers/parisc/hppb.c
+++ b/drivers/parisc/hppb.c
@@ -10,10 +10,6 @@
10** the Free Software Foundation; either version 2 of the License, or 10** the Free Software Foundation; either version 2 of the License, or
11** (at your option) any later version. 11** (at your option) any later version.
12** 12**
13** This Driver currently only supports the console (port 0) on the MUX.
14** Additional work will be needed on this driver to enable the full
15** functionality of the MUX.
16**
17*/ 13*/
18 14
19#include <linux/types.h> 15#include <linux/types.h>
@@ -67,7 +63,7 @@ static int hppb_probe(struct parisc_device *dev)
67 } 63 }
68 card = card->next; 64 card = card->next;
69 } 65 }
70 printk(KERN_INFO "Found GeckoBoa at 0x%lx\n", dev->hpa.start); 66 printk(KERN_INFO "Found GeckoBoa at 0x%x\n", dev->hpa.start);
71 67
72 card->hpa = dev->hpa.start; 68 card->hpa = dev->hpa.start;
73 card->mmio_region.name = "HP-PB Bus"; 69 card->mmio_region.name = "HP-PB Bus";
@@ -78,16 +74,18 @@ static int hppb_probe(struct parisc_device *dev)
78 74
79 status = ccio_request_resource(dev, &card->mmio_region); 75 status = ccio_request_resource(dev, &card->mmio_region);
80 if(status < 0) { 76 if(status < 0) {
81 printk(KERN_ERR "%s: failed to claim HP-PB bus space (%08lx, %08lx)\n", 77 printk(KERN_ERR "%s: failed to claim HP-PB bus space (%08x, %08x)\n",
82 __FILE__, card->mmio_region.start, card->mmio_region.end); 78 __FILE__, card->mmio_region.start, card->mmio_region.end);
83 } 79 }
84 80
85 return 0; 81 return 0;
86} 82}
87 83
88
89static struct parisc_device_id hppb_tbl[] = { 84static struct parisc_device_id hppb_tbl[] = {
90 { HPHW_BCPORT, HVERSION_REV_ANY_ID, 0x500, 0xc }, 85 { HPHW_BCPORT, HVERSION_REV_ANY_ID, 0x500, 0xc }, /* E25 and K */
86 { HPHW_BCPORT, 0x0, 0x501, 0xc }, /* E35 */
87 { HPHW_BCPORT, 0x0, 0x502, 0xc }, /* E45 */
88 { HPHW_BCPORT, 0x0, 0x503, 0xc }, /* E55 */
91 { 0, } 89 { 0, }
92}; 90};
93 91
diff --git a/drivers/parisc/iosapic_private.h b/drivers/parisc/iosapic_private.h
index 41e7ec2a44..6e05e30a24 100644
--- a/drivers/parisc/iosapic_private.h
+++ b/drivers/parisc/iosapic_private.h
@@ -132,7 +132,7 @@ struct iosapic_irt {
132struct vector_info { 132struct vector_info {
133 struct iosapic_info *iosapic; /* I/O SAPIC this vector is on */ 133 struct iosapic_info *iosapic; /* I/O SAPIC this vector is on */
134 struct irt_entry *irte; /* IRT entry */ 134 struct irt_entry *irte; /* IRT entry */
135 u32 *eoi_addr; /* precalculate EOI reg address */ 135 u32 __iomem *eoi_addr; /* precalculate EOI reg address */
136 u32 eoi_data; /* IA64: ? PA: swapped txn_data */ 136 u32 eoi_data; /* IA64: ? PA: swapped txn_data */
137 int txn_irq; /* virtual IRQ number for processor */ 137 int txn_irq; /* virtual IRQ number for processor */
138 ulong txn_addr; /* IA64: id_eid PA: partial HPA */ 138 ulong txn_addr; /* IA64: id_eid PA: partial HPA */
diff --git a/drivers/parisc/lba_pci.c b/drivers/parisc/lba_pci.c
index ba6769934c..21c4c299b3 100644
--- a/drivers/parisc/lba_pci.c
+++ b/drivers/parisc/lba_pci.c
@@ -168,7 +168,8 @@ lba_dump_res(struct resource *r, int d)
168 168
169 printk(KERN_DEBUG "(%p)", r->parent); 169 printk(KERN_DEBUG "(%p)", r->parent);
170 for (i = d; i ; --i) printk(" "); 170 for (i = d; i ; --i) printk(" ");
171 printk(KERN_DEBUG "%p [%lx,%lx]/%lx\n", r, r->start, r->end, r->flags); 171 printk(KERN_DEBUG "%p [%lx,%lx]/%lx\n", r,
172 (long)r->start, (long)r->end, r->flags);
172 lba_dump_res(r->child, d+2); 173 lba_dump_res(r->child, d+2);
173 lba_dump_res(r->sibling, d); 174 lba_dump_res(r->sibling, d);
174} 175}
@@ -647,7 +648,7 @@ truncate_pat_collision(struct resource *root, struct resource *new)
647 printk(KERN_WARNING "LBA: Truncating lmmio_space [%lx/%lx] " 648 printk(KERN_WARNING "LBA: Truncating lmmio_space [%lx/%lx] "
648 "to [%lx,%lx]\n", 649 "to [%lx,%lx]\n",
649 start, end, 650 start, end,
650 new->start, new->end ); 651 (long)new->start, (long)new->end );
651 652
652 return 0; /* truncation successful */ 653 return 0; /* truncation successful */
653} 654}
@@ -715,8 +716,8 @@ lba_fixup_bus(struct pci_bus *bus)
715 716
716 printk("FAILED: lba_fixup_bus() request for " 717 printk("FAILED: lba_fixup_bus() request for "
717 "elmmio_space [%lx/%lx]\n", 718 "elmmio_space [%lx/%lx]\n",
718 ldev->hba.elmmio_space.start, 719 (long)ldev->hba.elmmio_space.start,
719 ldev->hba.elmmio_space.end); 720 (long)ldev->hba.elmmio_space.end);
720 721
721 /* lba_dump_res(&iomem_resource, 2); */ 722 /* lba_dump_res(&iomem_resource, 2); */
722 /* BUG(); */ 723 /* BUG(); */
@@ -738,15 +739,15 @@ lba_fixup_bus(struct pci_bus *bus)
738 &(ldev->hba.lmmio_space))) { 739 &(ldev->hba.lmmio_space))) {
739 740
740 printk(KERN_WARNING "LBA: lmmio_space [%lx/%lx] duplicate!\n", 741 printk(KERN_WARNING "LBA: lmmio_space [%lx/%lx] duplicate!\n",
741 ldev->hba.lmmio_space.start, 742 (long)ldev->hba.lmmio_space.start,
742 ldev->hba.lmmio_space.end); 743 (long)ldev->hba.lmmio_space.end);
743 } else { 744 } else {
744 err = request_resource(&iomem_resource, &(ldev->hba.lmmio_space)); 745 err = request_resource(&iomem_resource, &(ldev->hba.lmmio_space));
745 if (err < 0) { 746 if (err < 0) {
746 printk(KERN_ERR "FAILED: lba_fixup_bus() request for " 747 printk(KERN_ERR "FAILED: lba_fixup_bus() request for "
747 "lmmio_space [%lx/%lx]\n", 748 "lmmio_space [%lx/%lx]\n",
748 ldev->hba.lmmio_space.start, 749 (long)ldev->hba.lmmio_space.start,
749 ldev->hba.lmmio_space.end); 750 (long)ldev->hba.lmmio_space.end);
750 } else 751 } else
751 bus->resource[i++] = &(ldev->hba.lmmio_space); 752 bus->resource[i++] = &(ldev->hba.lmmio_space);
752 } 753 }
@@ -758,8 +759,8 @@ lba_fixup_bus(struct pci_bus *bus)
758 if (err < 0) { 759 if (err < 0) {
759 printk("FAILED: lba_fixup_bus() request for " 760 printk("FAILED: lba_fixup_bus() request for "
760 "gmmio_space [%lx/%lx]\n", 761 "gmmio_space [%lx/%lx]\n",
761 ldev->hba.gmmio_space.start, 762 (long)ldev->hba.gmmio_space.start,
762 ldev->hba.gmmio_space.end); 763 (long)ldev->hba.gmmio_space.end);
763 lba_dump_res(&iomem_resource, 2); 764 lba_dump_res(&iomem_resource, 2);
764 BUG(); 765 BUG();
765 } 766 }
@@ -980,7 +981,7 @@ LBA_PORT_IN(32, 0)
980#define LBA_PORT_OUT(size, mask) \ 981#define LBA_PORT_OUT(size, mask) \
981static void lba_pat_out##size (struct pci_hba_data *l, u16 addr, u##size val) \ 982static void lba_pat_out##size (struct pci_hba_data *l, u16 addr, u##size val) \
982{ \ 983{ \
983 void *where = (void *) PIOP_TO_GMMIO(LBA_DEV(l), addr); \ 984 void __iomem *where = PIOP_TO_GMMIO(LBA_DEV(l), addr); \
984 DBG_PORT("%s(0x%p, 0x%x, 0x%x)\n", __FUNCTION__, l, addr, val); \ 985 DBG_PORT("%s(0x%p, 0x%x, 0x%x)\n", __FUNCTION__, l, addr, val); \
985 WRITE_REG##size(val, where); \ 986 WRITE_REG##size(val, where); \
986 /* flush the I/O down to the elroy at least */ \ 987 /* flush the I/O down to the elroy at least */ \
@@ -1063,16 +1064,16 @@ lba_pat_resources(struct parisc_device *pa_dev, struct lba_device *lba_dev)
1063 /* used to fix up pre-initialized MEM BARs */ 1064 /* used to fix up pre-initialized MEM BARs */
1064 if (!lba_dev->hba.lmmio_space.start) { 1065 if (!lba_dev->hba.lmmio_space.start) {
1065 sprintf(lba_dev->hba.lmmio_name, 1066 sprintf(lba_dev->hba.lmmio_name,
1066 "PCI%02lx LMMIO", 1067 "PCI%02x LMMIO",
1067 lba_dev->hba.bus_num.start); 1068 (int)lba_dev->hba.bus_num.start);
1068 lba_dev->hba.lmmio_space_offset = p->start - 1069 lba_dev->hba.lmmio_space_offset = p->start -
1069 io->start; 1070 io->start;
1070 r = &lba_dev->hba.lmmio_space; 1071 r = &lba_dev->hba.lmmio_space;
1071 r->name = lba_dev->hba.lmmio_name; 1072 r->name = lba_dev->hba.lmmio_name;
1072 } else if (!lba_dev->hba.elmmio_space.start) { 1073 } else if (!lba_dev->hba.elmmio_space.start) {
1073 sprintf(lba_dev->hba.elmmio_name, 1074 sprintf(lba_dev->hba.elmmio_name,
1074 "PCI%02lx ELMMIO", 1075 "PCI%02x ELMMIO",
1075 lba_dev->hba.bus_num.start); 1076 (int)lba_dev->hba.bus_num.start);
1076 r = &lba_dev->hba.elmmio_space; 1077 r = &lba_dev->hba.elmmio_space;
1077 r->name = lba_dev->hba.elmmio_name; 1078 r->name = lba_dev->hba.elmmio_name;
1078 } else { 1079 } else {
@@ -1089,8 +1090,8 @@ lba_pat_resources(struct parisc_device *pa_dev, struct lba_device *lba_dev)
1089 1090
1090 case PAT_GMMIO: 1091 case PAT_GMMIO:
1091 /* MMIO space > 4GB phys addr; for 64-bit BAR */ 1092 /* MMIO space > 4GB phys addr; for 64-bit BAR */
1092 sprintf(lba_dev->hba.gmmio_name, "PCI%02lx GMMIO", 1093 sprintf(lba_dev->hba.gmmio_name, "PCI%02x GMMIO",
1093 lba_dev->hba.bus_num.start); 1094 (int)lba_dev->hba.bus_num.start);
1094 r = &lba_dev->hba.gmmio_space; 1095 r = &lba_dev->hba.gmmio_space;
1095 r->name = lba_dev->hba.gmmio_name; 1096 r->name = lba_dev->hba.gmmio_name;
1096 r->start = p->start; 1097 r->start = p->start;
@@ -1112,8 +1113,8 @@ lba_pat_resources(struct parisc_device *pa_dev, struct lba_device *lba_dev)
1112 */ 1113 */
1113 lba_dev->iop_base = ioremap_nocache(p->start, 64 * 1024 * 1024); 1114 lba_dev->iop_base = ioremap_nocache(p->start, 64 * 1024 * 1024);
1114 1115
1115 sprintf(lba_dev->hba.io_name, "PCI%02lx Ports", 1116 sprintf(lba_dev->hba.io_name, "PCI%02x Ports",
1116 lba_dev->hba.bus_num.start); 1117 (int)lba_dev->hba.bus_num.start);
1117 r = &lba_dev->hba.io_space; 1118 r = &lba_dev->hba.io_space;
1118 r->name = lba_dev->hba.io_name; 1119 r->name = lba_dev->hba.io_name;
1119 r->start = HBA_PORT_BASE(lba_dev->hba.hba_num); 1120 r->start = HBA_PORT_BASE(lba_dev->hba.hba_num);
@@ -1166,8 +1167,8 @@ lba_legacy_resources(struct parisc_device *pa_dev, struct lba_device *lba_dev)
1166 ** Legacy boxes but it's nice to see in /proc/iomem. 1167 ** Legacy boxes but it's nice to see in /proc/iomem.
1167 */ 1168 */
1168 r = &(lba_dev->hba.lmmio_space); 1169 r = &(lba_dev->hba.lmmio_space);
1169 sprintf(lba_dev->hba.lmmio_name, "PCI%02lx LMMIO", 1170 sprintf(lba_dev->hba.lmmio_name, "PCI%02x LMMIO",
1170 lba_dev->hba.bus_num.start); 1171 (int)lba_dev->hba.bus_num.start);
1171 r->name = lba_dev->hba.lmmio_name; 1172 r->name = lba_dev->hba.lmmio_name;
1172 1173
1173#if 1 1174#if 1
@@ -1275,8 +1276,8 @@ lba_legacy_resources(struct parisc_device *pa_dev, struct lba_device *lba_dev)
1275 ** an existing (but unused portion of) distributed range. 1276 ** an existing (but unused portion of) distributed range.
1276 */ 1277 */
1277 r = &(lba_dev->hba.elmmio_space); 1278 r = &(lba_dev->hba.elmmio_space);
1278 sprintf(lba_dev->hba.elmmio_name, "PCI%02lx ELMMIO", 1279 sprintf(lba_dev->hba.elmmio_name, "PCI%02x ELMMIO",
1279 lba_dev->hba.bus_num.start); 1280 (int)lba_dev->hba.bus_num.start);
1280 r->name = lba_dev->hba.elmmio_name; 1281 r->name = lba_dev->hba.elmmio_name;
1281 1282
1282#if 1 1283#if 1
@@ -1297,8 +1298,8 @@ lba_legacy_resources(struct parisc_device *pa_dev, struct lba_device *lba_dev)
1297#endif 1298#endif
1298 1299
1299 r = &(lba_dev->hba.io_space); 1300 r = &(lba_dev->hba.io_space);
1300 sprintf(lba_dev->hba.io_name, "PCI%02lx Ports", 1301 sprintf(lba_dev->hba.io_name, "PCI%02x Ports",
1301 lba_dev->hba.bus_num.start); 1302 (int)lba_dev->hba.bus_num.start);
1302 r->name = lba_dev->hba.io_name; 1303 r->name = lba_dev->hba.io_name;
1303 r->flags = IORESOURCE_IO; 1304 r->flags = IORESOURCE_IO;
1304 r->start = READ_REG32(lba_dev->hba.base_addr + LBA_IOS_BASE) & ~1L; 1305 r->start = READ_REG32(lba_dev->hba.base_addr + LBA_IOS_BASE) & ~1L;
@@ -1406,13 +1407,20 @@ lba_hw_init(struct lba_device *d)
1406 return 0; 1407 return 0;
1407} 1408}
1408 1409
1409 1410/*
1411 * Unfortunately, when firmware numbers busses, it doesn't take into account
1412 * Cardbus bridges. So we have to renumber the busses to suit ourselves.
1413 * Elroy/Mercury don't actually know what bus number they're attached to;
1414 * we use bus 0 to indicate the directly attached bus and any other bus
1415 * number will be taken care of by the PCI-PCI bridge.
1416 */
1417static unsigned int lba_next_bus = 0;
1410 1418
1411/* 1419/*
1412** Determine if lba should claim this chip (return 0) or not (return 1). 1420 * Determine if lba should claim this chip (return 0) or not (return 1).
1413** If so, initialize the chip and tell other partners in crime they 1421 * If so, initialize the chip and tell other partners in crime they
1414** have work to do. 1422 * have work to do.
1415*/ 1423 */
1416static int __init 1424static int __init
1417lba_driver_probe(struct parisc_device *dev) 1425lba_driver_probe(struct parisc_device *dev)
1418{ 1426{
@@ -1440,7 +1448,7 @@ lba_driver_probe(struct parisc_device *dev)
1440 } 1448 }
1441 1449
1442 printk(KERN_INFO "Elroy version %s (0x%x) found at 0x%lx\n", 1450 printk(KERN_INFO "Elroy version %s (0x%x) found at 0x%lx\n",
1443 version, func_class & 0xf, dev->hpa.start); 1451 version, func_class & 0xf, (long)dev->hpa.start);
1444 1452
1445 if (func_class < 2) { 1453 if (func_class < 2) {
1446 printk(KERN_WARNING "Can't support LBA older than " 1454 printk(KERN_WARNING "Can't support LBA older than "
@@ -1470,17 +1478,16 @@ lba_driver_probe(struct parisc_device *dev)
1470 */ 1478 */
1471 printk(KERN_INFO "%s version TR%d.%d (0x%x) found at 0x%lx\n", 1479 printk(KERN_INFO "%s version TR%d.%d (0x%x) found at 0x%lx\n",
1472 IS_MERCURY(dev) ? "Mercury" : "Quicksilver", major, 1480 IS_MERCURY(dev) ? "Mercury" : "Quicksilver", major,
1473 minor, func_class, dev->hpa.start); 1481 minor, func_class, (long)dev->hpa.start);
1474 1482
1475 cfg_ops = &mercury_cfg_ops; 1483 cfg_ops = &mercury_cfg_ops;
1476 } else { 1484 } else {
1477 printk(KERN_ERR "Unknown LBA found at 0x%lx\n", dev->hpa.start); 1485 printk(KERN_ERR "Unknown LBA found at 0x%lx\n",
1486 (long)dev->hpa.start);
1478 return -ENODEV; 1487 return -ENODEV;
1479 } 1488 }
1480 1489
1481 /* 1490 /* Tell I/O SAPIC driver we have a IRQ handler/region. */
1482 ** Tell I/O SAPIC driver we have a IRQ handler/region.
1483 */
1484 tmp_obj = iosapic_register(dev->hpa.start + LBA_IOSAPIC_BASE); 1491 tmp_obj = iosapic_register(dev->hpa.start + LBA_IOSAPIC_BASE);
1485 1492
1486 /* NOTE: PCI devices (e.g. 103c:1005 graphics card) which don't 1493 /* NOTE: PCI devices (e.g. 103c:1005 graphics card) which don't
@@ -1529,16 +1536,17 @@ lba_driver_probe(struct parisc_device *dev)
1529 lba_legacy_resources(dev, lba_dev); 1536 lba_legacy_resources(dev, lba_dev);
1530 } 1537 }
1531 1538
1532 /* 1539 if (lba_dev->hba.bus_num.start < lba_next_bus)
1533 ** Tell PCI support another PCI bus was found. 1540 lba_dev->hba.bus_num.start = lba_next_bus;
1534 ** Walks PCI bus for us too. 1541
1535 */
1536 dev->dev.platform_data = lba_dev; 1542 dev->dev.platform_data = lba_dev;
1537 lba_bus = lba_dev->hba.hba_bus = 1543 lba_bus = lba_dev->hba.hba_bus =
1538 pci_scan_bus_parented(&dev->dev, lba_dev->hba.bus_num.start, 1544 pci_scan_bus_parented(&dev->dev, lba_dev->hba.bus_num.start,
1539 cfg_ops, NULL); 1545 cfg_ops, NULL);
1540 if (lba_bus) 1546 if (lba_bus) {
1547 lba_next_bus = lba_bus->subordinate + 1;
1541 pci_bus_add_devices(lba_bus); 1548 pci_bus_add_devices(lba_bus);
1549 }
1542 1550
1543 /* This is in lieu of calling pci_assign_unassigned_resources() */ 1551 /* This is in lieu of calling pci_assign_unassigned_resources() */
1544 if (is_pdc_pat()) { 1552 if (is_pdc_pat()) {
diff --git a/drivers/parisc/led.c b/drivers/parisc/led.c
index 9a731c101d..d190c05d87 100644
--- a/drivers/parisc/led.c
+++ b/drivers/parisc/led.c
@@ -66,8 +66,8 @@ static char lcd_text_default[32] __read_mostly;
66 66
67 67
68static struct workqueue_struct *led_wq; 68static struct workqueue_struct *led_wq;
69static void led_work_func(void *); 69static void led_work_func(struct work_struct *);
70static DECLARE_WORK(led_task, led_work_func, NULL); 70static DECLARE_DELAYED_WORK(led_task, led_work_func);
71 71
72#if 0 72#if 0
73#define DPRINTK(x) printk x 73#define DPRINTK(x) printk x
@@ -136,7 +136,7 @@ static int start_task(void)
136 136
137 /* Create the work queue and queue the LED task */ 137 /* Create the work queue and queue the LED task */
138 led_wq = create_singlethread_workqueue("led_wq"); 138 led_wq = create_singlethread_workqueue("led_wq");
139 queue_work(led_wq, &led_task); 139 queue_delayed_work(led_wq, &led_task, 0);
140 140
141 return 0; 141 return 0;
142} 142}
@@ -441,7 +441,7 @@ static __inline__ int led_get_diskio_activity(void)
441 441
442#define LED_UPDATE_INTERVAL (1 + (HZ*19/1000)) 442#define LED_UPDATE_INTERVAL (1 + (HZ*19/1000))
443 443
444static void led_work_func (void *unused) 444static void led_work_func (struct work_struct *unused)
445{ 445{
446 static unsigned long last_jiffies; 446 static unsigned long last_jiffies;
447 static unsigned long count_HZ; /* counter in range 0..HZ */ 447 static unsigned long count_HZ; /* counter in range 0..HZ */
@@ -588,7 +588,7 @@ int __init register_led_driver(int model, unsigned long cmd_reg, unsigned long d
588 588
589 /* Ensure the work is queued */ 589 /* Ensure the work is queued */
590 if (led_wq) { 590 if (led_wq) {
591 queue_work(led_wq, &led_task); 591 queue_delayed_work(led_wq, &led_task, 0);
592 } 592 }
593 593
594 return 0; 594 return 0;
@@ -629,7 +629,7 @@ void __init register_led_regions(void)
629 ** avoid a race condition while writing the CMD/DATA register pair. 629 ** avoid a race condition while writing the CMD/DATA register pair.
630 ** 630 **
631 */ 631 */
632int lcd_print( char *str ) 632int lcd_print( const char *str )
633{ 633{
634 int i; 634 int i;
635 635
@@ -658,7 +658,7 @@ int lcd_print( char *str )
658 658
659 /* re-queue the work */ 659 /* re-queue the work */
660 if (led_wq) { 660 if (led_wq) {
661 queue_work(led_wq, &led_task); 661 queue_delayed_work(led_wq, &led_task, 0);
662 } 662 }
663 663
664 return lcd_info.lcd_width; 664 return lcd_info.lcd_width;
diff --git a/drivers/parisc/power.c b/drivers/parisc/power.c
index 97e9dc066f..6dedbdef71 100644
--- a/drivers/parisc/power.c
+++ b/drivers/parisc/power.c
@@ -2,7 +2,7 @@
2 * linux/drivers/parisc/power.c 2 * linux/drivers/parisc/power.c
3 * HP PARISC soft power switch support driver 3 * HP PARISC soft power switch support driver
4 * 4 *
5 * Copyright (c) 2001-2005 Helge Deller <deller@gmx.de> 5 * Copyright (c) 2001-2007 Helge Deller <deller@gmx.de>
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * 8 *
@@ -29,7 +29,6 @@
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * 30 *
31 * 31 *
32 *
33 * HINT: 32 * HINT:
34 * Support of the soft power switch button may be enabled or disabled at 33 * Support of the soft power switch button may be enabled or disabled at
35 * runtime through the "/proc/sys/kernel/power" procfs entry. 34 * runtime through the "/proc/sys/kernel/power" procfs entry.
@@ -38,34 +37,28 @@
38#include <linux/module.h> 37#include <linux/module.h>
39#include <linux/init.h> 38#include <linux/init.h>
40#include <linux/kernel.h> 39#include <linux/kernel.h>
41#include <linux/string.h>
42#include <linux/notifier.h> 40#include <linux/notifier.h>
43#include <linux/reboot.h> 41#include <linux/reboot.h>
44#include <linux/sched.h> 42#include <linux/sched.h>
45#include <linux/interrupt.h> 43#include <linux/kthread.h>
46#include <linux/workqueue.h>
47 44
48#include <asm/pdc.h> 45#include <asm/pdc.h>
49#include <asm/io.h> 46#include <asm/io.h>
50#include <asm/led.h> 47#include <asm/led.h>
51#include <asm/uaccess.h>
52 48
49#define DRIVER_NAME "powersw"
50#define KTHREAD_NAME "kpowerswd"
53 51
54#ifdef DEBUG 52/* how often should the power button be polled ? */
55# define DPRINTK(x...) printk(x) 53#define POWERSWITCH_POLL_PER_SEC 2
56#else
57# define DPRINTK(x...)
58#endif
59
60
61/* filename in /proc which can be used to enable/disable the power switch */
62#define SYSCTL_FILENAME "sys/kernel/power"
63 54
55/* how long does the power button needs to be down until we react ? */
56#define POWERSWITCH_DOWN_SEC 2
64 57
58/* assembly code to access special registers */
59/* taken from PCXL ERS page 82 */
65#define DIAG_CODE(code) (0x14000000 + ((code)<<5)) 60#define DIAG_CODE(code) (0x14000000 + ((code)<<5))
66 61
67/* this will go to processor.h or any other place... */
68/* taken from PCXL ERS page 82 */
69#define MFCPU_X(rDiagReg, t_ch, t_th, code) \ 62#define MFCPU_X(rDiagReg, t_ch, t_th, code) \
70 (DIAG_CODE(code) + ((rDiagReg)<<21) + ((t_ch)<<16) + ((t_th)<<0) ) 63 (DIAG_CODE(code) + ((rDiagReg)<<21) + ((t_ch)<<16) + ((t_th)<<0) )
71 64
@@ -76,111 +69,95 @@
76#define __getDIAG(dr) ( { \ 69#define __getDIAG(dr) ( { \
77 register unsigned long __res asm("r28");\ 70 register unsigned long __res asm("r28");\
78 __asm__ __volatile__ ( \ 71 __asm__ __volatile__ ( \
79 ".word %1\n nop\n" : "=&r" (__res) : "i" (MFCPU_T(dr,28)) \ 72 ".word %1" : "=&r" (__res) : "i" (MFCPU_T(dr,28) ) \
80 ); \ 73 ); \
81 __res; \ 74 __res; \
82} ) 75} )
83 76
84 77/* local shutdown counter */
85static void deferred_poweroff(void *dummy)
86{
87 if (kill_cad_pid(SIGINT, 1)) {
88 /* just in case killing init process failed */
89 machine_power_off();
90 }
91}
92
93/*
94 * This function gets called from interrupt context.
95 * As it's called within an interrupt, it wouldn't sync if we don't
96 * use schedule_work().
97 */
98
99static DECLARE_WORK(poweroff_work, deferred_poweroff, NULL);
100
101static void poweroff(void)
102{
103 static int powering_off __read_mostly;
104
105 if (powering_off)
106 return;
107
108 powering_off++;
109 schedule_work(&poweroff_work);
110}
111
112
113/* local time-counter for shutdown */
114static int shutdown_timer __read_mostly; 78static int shutdown_timer __read_mostly;
115 79
116/* check, give feedback and start shutdown after one second */ 80/* check, give feedback and start shutdown after one second */
117static void process_shutdown(void) 81static void process_shutdown(void)
118{ 82{
119 if (shutdown_timer == 0) 83 if (shutdown_timer == 0)
120 DPRINTK(KERN_INFO "Shutdown requested...\n"); 84 printk(KERN_ALERT KTHREAD_NAME ": Shutdown requested...\n");
121 85
122 shutdown_timer++; 86 shutdown_timer++;
123 87
124 /* wait until the button was pressed for 1 second */ 88 /* wait until the button was pressed for 1 second */
125 if (shutdown_timer == HZ) { 89 if (shutdown_timer == (POWERSWITCH_DOWN_SEC*POWERSWITCH_POLL_PER_SEC)) {
126#if defined (DEBUG) || defined(CONFIG_CHASSIS_LCD_LED) 90 static const char msg[] = "Shutting down...";
127 static char msg[] = "Shutting down..."; 91 printk(KERN_INFO KTHREAD_NAME ": %s\n", msg);
128#endif
129 DPRINTK(KERN_INFO "%s\n", msg);
130 lcd_print(msg); 92 lcd_print(msg);
131 poweroff(); 93
94 /* send kill signal */
95 if (kill_cad_pid(SIGINT, 1)) {
96 /* just in case killing init process failed */
97 if (pm_power_off)
98 pm_power_off();
99 }
132 } 100 }
133} 101}
134 102
135 103
136/* main power switch tasklet struct (scheduled from time.c) */ 104/* main power switch task struct */
137DECLARE_TASKLET_DISABLED(power_tasklet, NULL, 0); 105static struct task_struct *power_task;
106
107/* filename in /proc which can be used to enable/disable the power switch */
108#define SYSCTL_FILENAME "sys/kernel/power"
138 109
139/* soft power switch enabled/disabled */ 110/* soft power switch enabled/disabled */
140int pwrsw_enabled __read_mostly = 1; 111int pwrsw_enabled __read_mostly = 1;
141 112
142/* 113/* main kernel thread worker. It polls the button state */
143 * On gecko style machines (e.g. 712/xx and 715/xx) 114static int kpowerswd(void *param)
144 * the power switch status is stored in Bit 0 ("the highest bit")
145 * of CPU diagnose register 25.
146 *
147 */
148static void gecko_tasklet_func(unsigned long unused)
149{ 115{
150 if (unlikely(!pwrsw_enabled)) 116 __set_current_state(TASK_RUNNING);
151 return; 117
152 118 do {
153 if (__getDIAG(25) & 0x80000000) { 119 int button_not_pressed;
154 /* power switch button not pressed or released again */ 120 unsigned long soft_power_reg = (unsigned long) param;
155 /* Warning: Some machines do never reset this DIAG flag! */ 121
156 shutdown_timer = 0; 122 schedule_timeout_interruptible(pwrsw_enabled ? HZ : HZ/POWERSWITCH_POLL_PER_SEC);
157 } else { 123 __set_current_state(TASK_RUNNING);
158 process_shutdown(); 124
159 } 125 if (unlikely(!pwrsw_enabled))
160} 126 continue;
161 127
128 if (soft_power_reg) {
129 /*
130 * Non-Gecko-style machines:
131 * Check the power switch status which is read from the
132 * real I/O location at soft_power_reg.
133 * Bit 31 ("the lowest bit) is the status of the power switch.
134 * This bit is "1" if the button is NOT pressed.
135 */
136 button_not_pressed = (gsc_readl(soft_power_reg) & 0x1);
137 } else {
138 /*
139 * On gecko style machines (e.g. 712/xx and 715/xx)
140 * the power switch status is stored in Bit 0 ("the highest bit")
141 * of CPU diagnose register 25.
142 * Warning: Some machines never reset the DIAG flag, even if
143 * the button has been released again.
144 */
145 button_not_pressed = (__getDIAG(25) & 0x80000000);
146 }
147
148 if (likely(button_not_pressed)) {
149 if (unlikely(shutdown_timer && /* avoid writing if not necessary */
150 shutdown_timer < (POWERSWITCH_DOWN_SEC*POWERSWITCH_POLL_PER_SEC))) {
151 shutdown_timer = 0;
152 printk(KERN_INFO KTHREAD_NAME ": Shutdown request aborted.\n");
153 }
154 } else
155 process_shutdown();
156
157
158 } while (!kthread_should_stop());
162 159
163 160 return 0;
164/*
165 * Check the power switch status which is read from the
166 * real I/O location at soft_power_reg.
167 * Bit 31 ("the lowest bit) is the status of the power switch.
168 */
169
170static void polling_tasklet_func(unsigned long soft_power_reg)
171{
172 unsigned long current_status;
173
174 if (unlikely(!pwrsw_enabled))
175 return;
176
177 current_status = gsc_readl(soft_power_reg);
178 if (current_status & 0x1) {
179 /* power switch button not pressed */
180 shutdown_timer = 0;
181 } else {
182 process_shutdown();
183 }
184} 161}
185 162
186 163
@@ -220,7 +197,7 @@ static struct notifier_block parisc_panic_block = {
220static int __init power_init(void) 197static int __init power_init(void)
221{ 198{
222 unsigned long ret; 199 unsigned long ret;
223 unsigned long soft_power_reg = 0; 200 unsigned long soft_power_reg;
224 201
225#if 0 202#if 0
226 request_irq( IRQ_FROM_REGION(CPU_IRQ_REGION)+2, &powerfail_interrupt, 203 request_irq( IRQ_FROM_REGION(CPU_IRQ_REGION)+2, &powerfail_interrupt,
@@ -235,44 +212,44 @@ static int __init power_init(void)
235 soft_power_reg = -1UL; 212 soft_power_reg = -1UL;
236 213
237 switch (soft_power_reg) { 214 switch (soft_power_reg) {
238 case 0: printk(KERN_INFO "Gecko-style soft power switch enabled.\n"); 215 case 0: printk(KERN_INFO DRIVER_NAME ": Gecko-style soft power switch enabled.\n");
239 power_tasklet.func = gecko_tasklet_func;
240 break; 216 break;
241 217
242 case -1UL: printk(KERN_INFO "Soft power switch support not available.\n"); 218 case -1UL: printk(KERN_INFO DRIVER_NAME ": Soft power switch support not available.\n");
243 return -ENODEV; 219 return -ENODEV;
244 220
245 default: printk(KERN_INFO "Soft power switch enabled, polling @ 0x%08lx.\n", 221 default: printk(KERN_INFO DRIVER_NAME ": Soft power switch at 0x%08lx enabled.\n",
246 soft_power_reg); 222 soft_power_reg);
247 power_tasklet.data = soft_power_reg; 223 }
248 power_tasklet.func = polling_tasklet_func; 224
225 power_task = kthread_run(kpowerswd, (void*)soft_power_reg, KTHREAD_NAME);
226 if (IS_ERR(power_task)) {
227 printk(KERN_ERR DRIVER_NAME ": thread creation failed. Driver not loaded.\n");
228 pdc_soft_power_button(0);
229 return -EIO;
249 } 230 }
250 231
251 /* Register a call for panic conditions. */ 232 /* Register a call for panic conditions. */
252 atomic_notifier_chain_register(&panic_notifier_list, 233 atomic_notifier_chain_register(&panic_notifier_list,
253 &parisc_panic_block); 234 &parisc_panic_block);
254 235
255 tasklet_enable(&power_tasklet);
256
257 return 0; 236 return 0;
258} 237}
259 238
260static void __exit power_exit(void) 239static void __exit power_exit(void)
261{ 240{
262 if (!power_tasklet.func) 241 kthread_stop(power_task);
263 return;
264 242
265 tasklet_disable(&power_tasklet);
266 atomic_notifier_chain_unregister(&panic_notifier_list, 243 atomic_notifier_chain_unregister(&panic_notifier_list,
267 &parisc_panic_block); 244 &parisc_panic_block);
268 power_tasklet.func = NULL; 245
269 pdc_soft_power_button(0); 246 pdc_soft_power_button(0);
270} 247}
271 248
272module_init(power_init); 249arch_initcall(power_init);
273module_exit(power_exit); 250module_exit(power_exit);
274 251
275 252
276MODULE_AUTHOR("Helge Deller"); 253MODULE_AUTHOR("Helge Deller <deller@gmx.de>");
277MODULE_DESCRIPTION("Soft power switch driver"); 254MODULE_DESCRIPTION("Soft power switch driver");
278MODULE_LICENSE("Dual BSD/GPL"); 255MODULE_LICENSE("Dual BSD/GPL");
diff --git a/drivers/parisc/sba_iommu.c b/drivers/parisc/sba_iommu.c
index 76a29dadd5..322957ac2a 100644
--- a/drivers/parisc/sba_iommu.c
+++ b/drivers/parisc/sba_iommu.c
@@ -109,7 +109,7 @@ static unsigned long piranha_bad_128k = 0;
109 109
110#ifdef SBA_AGP_SUPPORT 110#ifdef SBA_AGP_SUPPORT
111static int sba_reserve_agpgart = 1; 111static int sba_reserve_agpgart = 1;
112module_param(sba_reserve_agpgart, int, 1); 112module_param(sba_reserve_agpgart, int, 0444);
113MODULE_PARM_DESC(sba_reserve_agpgart, "Reserve half of IO pdir as AGPGART"); 113MODULE_PARM_DESC(sba_reserve_agpgart, "Reserve half of IO pdir as AGPGART");
114#endif 114#endif
115 115
@@ -846,7 +846,7 @@ static void *sba_alloc_consistent(struct device *hwdev, size_t size,
846 if (!hwdev) { 846 if (!hwdev) {
847 /* only support PCI */ 847 /* only support PCI */
848 *dma_handle = 0; 848 *dma_handle = 0;
849 return 0; 849 return NULL;
850 } 850 }
851 851
852 ret = (void *) __get_free_pages(gfp, get_order(size)); 852 ret = (void *) __get_free_pages(gfp, get_order(size));
diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c
index b61c17b3e2..3de2623afa 100644
--- a/drivers/parport/parport_pc.c
+++ b/drivers/parport/parport_pc.c
@@ -1546,7 +1546,7 @@ static void __devinit detect_and_report_smsc (void)
1546} 1546}
1547#endif /* CONFIG_PARPORT_PC_SUPERIO */ 1547#endif /* CONFIG_PARPORT_PC_SUPERIO */
1548 1548
1549static int __devinit get_superio_dma (struct parport *p) 1549static int get_superio_dma (struct parport *p)
1550{ 1550{
1551 int i=0; 1551 int i=0;
1552 while( (superios[i].io != p->base) && (i<NR_SUPERIOS)) 1552 while( (superios[i].io != p->base) && (i<NR_SUPERIOS))
@@ -2106,7 +2106,7 @@ static int parport_irq_probe(struct parport *pb)
2106/* --- DMA detection -------------------------------------- */ 2106/* --- DMA detection -------------------------------------- */
2107 2107
2108/* Only if chipset conforms to ECP ISA Interface Standard */ 2108/* Only if chipset conforms to ECP ISA Interface Standard */
2109static int __devinit programmable_dma_support (struct parport *p) 2109static int programmable_dma_support (struct parport *p)
2110{ 2110{
2111 unsigned char oecr = inb (ECONTROL (p)); 2111 unsigned char oecr = inb (ECONTROL (p));
2112 int dma; 2112 int dma;
@@ -2123,7 +2123,7 @@ static int __devinit programmable_dma_support (struct parport *p)
2123 return dma; 2123 return dma;
2124} 2124}
2125 2125
2126static int __devinit parport_dma_probe (struct parport *p) 2126static int parport_dma_probe (struct parport *p)
2127{ 2127{
2128 const struct parport_pc_private *priv = p->private_data; 2128 const struct parport_pc_private *priv = p->private_data;
2129 if (priv->ecr) 2129 if (priv->ecr)
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 68555c11f5..01869b1782 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -38,6 +38,36 @@ static int msi_cache_init(void)
38 return 0; 38 return 0;
39} 39}
40 40
41static void msi_set_enable(struct pci_dev *dev, int enable)
42{
43 int pos;
44 u16 control;
45
46 pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
47 if (pos) {
48 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control);
49 control &= ~PCI_MSI_FLAGS_ENABLE;
50 if (enable)
51 control |= PCI_MSI_FLAGS_ENABLE;
52 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control);
53 }
54}
55
56static void msix_set_enable(struct pci_dev *dev, int enable)
57{
58 int pos;
59 u16 control;
60
61 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
62 if (pos) {
63 pci_read_config_word(dev, pos + PCI_MSIX_FLAGS, &control);
64 control &= ~PCI_MSIX_FLAGS_ENABLE;
65 if (enable)
66 control |= PCI_MSIX_FLAGS_ENABLE;
67 pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control);
68 }
69}
70
41static void msi_set_mask_bit(unsigned int irq, int flag) 71static void msi_set_mask_bit(unsigned int irq, int flag)
42{ 72{
43 struct msi_desc *entry; 73 struct msi_desc *entry;
@@ -55,6 +85,8 @@ static void msi_set_mask_bit(unsigned int irq, int flag)
55 mask_bits &= ~(1); 85 mask_bits &= ~(1);
56 mask_bits |= flag; 86 mask_bits |= flag;
57 pci_write_config_dword(entry->dev, pos, mask_bits); 87 pci_write_config_dword(entry->dev, pos, mask_bits);
88 } else {
89 msi_set_enable(entry->dev, !flag);
58 } 90 }
59 break; 91 break;
60 case PCI_CAP_ID_MSIX: 92 case PCI_CAP_ID_MSIX:
@@ -192,44 +224,6 @@ static struct msi_desc* alloc_msi_entry(void)
192 return entry; 224 return entry;
193} 225}
194 226
195static void enable_msi_mode(struct pci_dev *dev, int pos, int type)
196{
197 u16 control;
198
199 pci_read_config_word(dev, msi_control_reg(pos), &control);
200 if (type == PCI_CAP_ID_MSI) {
201 /* Set enabled bits to single MSI & enable MSI_enable bit */
202 msi_enable(control, 1);
203 pci_write_config_word(dev, msi_control_reg(pos), control);
204 dev->msi_enabled = 1;
205 } else {
206 msix_enable(control);
207 pci_write_config_word(dev, msi_control_reg(pos), control);
208 dev->msix_enabled = 1;
209 }
210
211 pci_intx(dev, 0); /* disable intx */
212}
213
214void disable_msi_mode(struct pci_dev *dev, int pos, int type)
215{
216 u16 control;
217
218 pci_read_config_word(dev, msi_control_reg(pos), &control);
219 if (type == PCI_CAP_ID_MSI) {
220 /* Set enabled bits to single MSI & enable MSI_enable bit */
221 msi_disable(control);
222 pci_write_config_word(dev, msi_control_reg(pos), control);
223 dev->msi_enabled = 0;
224 } else {
225 msix_disable(control);
226 pci_write_config_word(dev, msi_control_reg(pos), control);
227 dev->msix_enabled = 0;
228 }
229
230 pci_intx(dev, 1); /* enable intx */
231}
232
233#ifdef CONFIG_PM 227#ifdef CONFIG_PM
234static int __pci_save_msi_state(struct pci_dev *dev) 228static int __pci_save_msi_state(struct pci_dev *dev)
235{ 229{
@@ -238,12 +232,11 @@ static int __pci_save_msi_state(struct pci_dev *dev)
238 struct pci_cap_saved_state *save_state; 232 struct pci_cap_saved_state *save_state;
239 u32 *cap; 233 u32 *cap;
240 234
241 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 235 if (!dev->msi_enabled)
242 if (pos <= 0 || dev->no_msi)
243 return 0; 236 return 0;
244 237
245 pci_read_config_word(dev, msi_control_reg(pos), &control); 238 pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
246 if (!(control & PCI_MSI_FLAGS_ENABLE)) 239 if (pos <= 0)
247 return 0; 240 return 0;
248 241
249 save_state = kzalloc(sizeof(struct pci_cap_saved_state) + sizeof(u32) * 5, 242 save_state = kzalloc(sizeof(struct pci_cap_saved_state) + sizeof(u32) * 5,
@@ -276,13 +269,18 @@ static void __pci_restore_msi_state(struct pci_dev *dev)
276 struct pci_cap_saved_state *save_state; 269 struct pci_cap_saved_state *save_state;
277 u32 *cap; 270 u32 *cap;
278 271
272 if (!dev->msi_enabled)
273 return;
274
279 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_MSI); 275 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_MSI);
280 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 276 pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
281 if (!save_state || pos <= 0) 277 if (!save_state || pos <= 0)
282 return; 278 return;
283 cap = &save_state->data[0]; 279 cap = &save_state->data[0];
284 280
281 pci_intx(dev, 0); /* disable intx */
285 control = cap[i++] >> 16; 282 control = cap[i++] >> 16;
283 msi_set_enable(dev, 0);
286 pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, cap[i++]); 284 pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, cap[i++]);
287 if (control & PCI_MSI_FLAGS_64BIT) { 285 if (control & PCI_MSI_FLAGS_64BIT) {
288 pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI, cap[i++]); 286 pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI, cap[i++]);
@@ -292,7 +290,6 @@ static void __pci_restore_msi_state(struct pci_dev *dev)
292 if (control & PCI_MSI_FLAGS_MASKBIT) 290 if (control & PCI_MSI_FLAGS_MASKBIT)
293 pci_write_config_dword(dev, pos + PCI_MSI_MASK_BIT, cap[i++]); 291 pci_write_config_dword(dev, pos + PCI_MSI_MASK_BIT, cap[i++]);
294 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control); 292 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control);
295 enable_msi_mode(dev, pos, PCI_CAP_ID_MSI);
296 pci_remove_saved_cap(save_state); 293 pci_remove_saved_cap(save_state);
297 kfree(save_state); 294 kfree(save_state);
298} 295}
@@ -308,13 +305,11 @@ static int __pci_save_msix_state(struct pci_dev *dev)
308 return 0; 305 return 0;
309 306
310 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); 307 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
311 if (pos <= 0 || dev->no_msi) 308 if (pos <= 0)
312 return 0; 309 return 0;
313 310
314 /* save the capability */ 311 /* save the capability */
315 pci_read_config_word(dev, msi_control_reg(pos), &control); 312 pci_read_config_word(dev, msi_control_reg(pos), &control);
316 if (!(control & PCI_MSIX_FLAGS_ENABLE))
317 return 0;
318 save_state = kzalloc(sizeof(struct pci_cap_saved_state) + sizeof(u16), 313 save_state = kzalloc(sizeof(struct pci_cap_saved_state) + sizeof(u16),
319 GFP_KERNEL); 314 GFP_KERNEL);
320 if (!save_state) { 315 if (!save_state) {
@@ -376,6 +371,8 @@ static void __pci_restore_msix_state(struct pci_dev *dev)
376 return; 371 return;
377 372
378 /* route the table */ 373 /* route the table */
374 pci_intx(dev, 0); /* disable intx */
375 msix_set_enable(dev, 0);
379 irq = head = dev->first_msi_irq; 376 irq = head = dev->first_msi_irq;
380 while (head != tail) { 377 while (head != tail) {
381 entry = get_irq_msi(irq); 378 entry = get_irq_msi(irq);
@@ -386,7 +383,6 @@ static void __pci_restore_msix_state(struct pci_dev *dev)
386 } 383 }
387 384
388 pci_write_config_word(dev, msi_control_reg(pos), save); 385 pci_write_config_word(dev, msi_control_reg(pos), save);
389 enable_msi_mode(dev, pos, PCI_CAP_ID_MSIX);
390} 386}
391 387
392void pci_restore_msi_state(struct pci_dev *dev) 388void pci_restore_msi_state(struct pci_dev *dev)
@@ -411,6 +407,8 @@ static int msi_capability_init(struct pci_dev *dev)
411 int pos, irq; 407 int pos, irq;
412 u16 control; 408 u16 control;
413 409
410 msi_set_enable(dev, 0); /* Ensure msi is disabled as I set it up */
411
414 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 412 pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
415 pci_read_config_word(dev, msi_control_reg(pos), &control); 413 pci_read_config_word(dev, msi_control_reg(pos), &control);
416 /* MSI Entry Initialization */ 414 /* MSI Entry Initialization */
@@ -454,7 +452,9 @@ static int msi_capability_init(struct pci_dev *dev)
454 set_irq_msi(irq, entry); 452 set_irq_msi(irq, entry);
455 453
456 /* Set MSI enabled bits */ 454 /* Set MSI enabled bits */
457 enable_msi_mode(dev, pos, PCI_CAP_ID_MSI); 455 pci_intx(dev, 0); /* disable intx */
456 msi_set_enable(dev, 1);
457 dev->msi_enabled = 1;
458 458
459 dev->irq = irq; 459 dev->irq = irq;
460 return 0; 460 return 0;
@@ -481,6 +481,8 @@ static int msix_capability_init(struct pci_dev *dev,
481 u8 bir; 481 u8 bir;
482 void __iomem *base; 482 void __iomem *base;
483 483
484 msix_set_enable(dev, 0);/* Ensure msix is disabled as I set it up */
485
484 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); 486 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
485 /* Request & Map MSI-X table region */ 487 /* Request & Map MSI-X table region */
486 pci_read_config_word(dev, msi_control_reg(pos), &control); 488 pci_read_config_word(dev, msi_control_reg(pos), &control);
@@ -549,7 +551,9 @@ static int msix_capability_init(struct pci_dev *dev,
549 } 551 }
550 dev->first_msi_irq = entries[0].vector; 552 dev->first_msi_irq = entries[0].vector;
551 /* Set MSI-X enabled bits */ 553 /* Set MSI-X enabled bits */
552 enable_msi_mode(dev, pos, PCI_CAP_ID_MSIX); 554 pci_intx(dev, 0); /* disable intx */
555 msix_set_enable(dev, 1);
556 dev->msix_enabled = 1;
553 557
554 return 0; 558 return 0;
555} 559}
@@ -611,12 +615,11 @@ int pci_enable_msi(struct pci_dev* dev)
611 WARN_ON(!!dev->msi_enabled); 615 WARN_ON(!!dev->msi_enabled);
612 616
613 /* Check whether driver already requested for MSI-X irqs */ 617 /* Check whether driver already requested for MSI-X irqs */
614 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); 618 if (dev->msix_enabled) {
615 if (pos > 0 && dev->msix_enabled) { 619 printk(KERN_INFO "PCI: %s: Can't enable MSI. "
616 printk(KERN_INFO "PCI: %s: Can't enable MSI. " 620 "Device already has MSI-X enabled\n",
617 "Device already has MSI-X enabled\n", 621 pci_name(dev));
618 pci_name(dev)); 622 return -EINVAL;
619 return -EINVAL;
620 } 623 }
621 status = msi_capability_init(dev); 624 status = msi_capability_init(dev);
622 return status; 625 return status;
@@ -625,8 +628,7 @@ int pci_enable_msi(struct pci_dev* dev)
625void pci_disable_msi(struct pci_dev* dev) 628void pci_disable_msi(struct pci_dev* dev)
626{ 629{
627 struct msi_desc *entry; 630 struct msi_desc *entry;
628 int pos, default_irq; 631 int default_irq;
629 u16 control;
630 632
631 if (!pci_msi_enable) 633 if (!pci_msi_enable)
632 return; 634 return;
@@ -636,16 +638,9 @@ void pci_disable_msi(struct pci_dev* dev)
636 if (!dev->msi_enabled) 638 if (!dev->msi_enabled)
637 return; 639 return;
638 640
639 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 641 msi_set_enable(dev, 0);
640 if (!pos) 642 pci_intx(dev, 1); /* enable intx */
641 return; 643 dev->msi_enabled = 0;
642
643 pci_read_config_word(dev, msi_control_reg(pos), &control);
644 if (!(control & PCI_MSI_FLAGS_ENABLE))
645 return;
646
647
648 disable_msi_mode(dev, pos, PCI_CAP_ID_MSI);
649 644
650 entry = get_irq_msi(dev->first_msi_irq); 645 entry = get_irq_msi(dev->first_msi_irq);
651 if (!entry || !entry->dev || entry->msi_attrib.type != PCI_CAP_ID_MSI) { 646 if (!entry || !entry->dev || entry->msi_attrib.type != PCI_CAP_ID_MSI) {
@@ -746,8 +741,7 @@ int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec)
746 WARN_ON(!!dev->msix_enabled); 741 WARN_ON(!!dev->msix_enabled);
747 742
748 /* Check whether driver already requested for MSI irq */ 743 /* Check whether driver already requested for MSI irq */
749 if (pci_find_capability(dev, PCI_CAP_ID_MSI) > 0 && 744 if (dev->msi_enabled) {
750 dev->msi_enabled) {
751 printk(KERN_INFO "PCI: %s: Can't enable MSI-X. " 745 printk(KERN_INFO "PCI: %s: Can't enable MSI-X. "
752 "Device already has an MSI irq assigned\n", 746 "Device already has an MSI irq assigned\n",
753 pci_name(dev)); 747 pci_name(dev));
@@ -760,8 +754,6 @@ int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec)
760void pci_disable_msix(struct pci_dev* dev) 754void pci_disable_msix(struct pci_dev* dev)
761{ 755{
762 int irq, head, tail = 0, warning = 0; 756 int irq, head, tail = 0, warning = 0;
763 int pos;
764 u16 control;
765 757
766 if (!pci_msi_enable) 758 if (!pci_msi_enable)
767 return; 759 return;
@@ -771,15 +763,9 @@ void pci_disable_msix(struct pci_dev* dev)
771 if (!dev->msix_enabled) 763 if (!dev->msix_enabled)
772 return; 764 return;
773 765
774 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); 766 msix_set_enable(dev, 0);
775 if (!pos) 767 pci_intx(dev, 1); /* enable intx */
776 return; 768 dev->msix_enabled = 0;
777
778 pci_read_config_word(dev, msi_control_reg(pos), &control);
779 if (!(control & PCI_MSIX_FLAGS_ENABLE))
780 return;
781
782 disable_msi_mode(dev, pos, PCI_CAP_ID_MSIX);
783 769
784 irq = head = dev->first_msi_irq; 770 irq = head = dev->first_msi_irq;
785 while (head != tail) { 771 while (head != tail) {
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 4438ae1ede..a3c1755b2f 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -415,6 +415,7 @@ static struct kobj_type pci_driver_kobj_type = {
415 * __pci_register_driver - register a new pci driver 415 * __pci_register_driver - register a new pci driver
416 * @drv: the driver structure to register 416 * @drv: the driver structure to register
417 * @owner: owner module of drv 417 * @owner: owner module of drv
418 * @mod_name: module name string
418 * 419 *
419 * Adds the driver structure to the list of registered drivers. 420 * Adds the driver structure to the list of registered drivers.
420 * Returns a negative value on error, otherwise 0. 421 * Returns a negative value on error, otherwise 0.
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 7a94076752..cd913a2a41 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -143,6 +143,14 @@ static ssize_t is_enabled_show(struct device *dev,
143 return sprintf (buf, "%u\n", atomic_read(&pdev->enable_cnt)); 143 return sprintf (buf, "%u\n", atomic_read(&pdev->enable_cnt));
144} 144}
145 145
146#ifdef CONFIG_NUMA
147static ssize_t
148numa_node_show(struct device *dev, struct device_attribute *attr, char *buf)
149{
150 return sprintf (buf, "%d\n", dev->numa_node);
151}
152#endif
153
146static ssize_t 154static ssize_t
147msi_bus_show(struct device *dev, struct device_attribute *attr, char *buf) 155msi_bus_show(struct device *dev, struct device_attribute *attr, char *buf)
148{ 156{
@@ -194,6 +202,9 @@ struct device_attribute pci_dev_attrs[] = {
194 __ATTR_RO(irq), 202 __ATTR_RO(irq),
195 __ATTR_RO(local_cpus), 203 __ATTR_RO(local_cpus),
196 __ATTR_RO(modalias), 204 __ATTR_RO(modalias),
205#ifdef CONFIG_NUMA
206 __ATTR_RO(numa_node),
207#endif
197 __ATTR(enable, 0600, is_enabled_show, is_enabled_store), 208 __ATTR(enable, 0600, is_enabled_show, is_enabled_store),
198 __ATTR(broken_parity_status,(S_IRUGO|S_IWUSR), 209 __ATTR(broken_parity_status,(S_IRUGO|S_IWUSR),
199 broken_parity_status_show,broken_parity_status_store), 210 broken_parity_status_show,broken_parity_status_store),
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 8b44cff2c1..df495300ce 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -21,6 +21,12 @@
21 21
22unsigned int pci_pm_d3_delay = 10; 22unsigned int pci_pm_d3_delay = 10;
23 23
24#define DEFAULT_CARDBUS_IO_SIZE (256)
25#define DEFAULT_CARDBUS_MEM_SIZE (64*1024*1024)
26/* pci=cbmemsize=nnM,cbiosize=nn can override this */
27unsigned long pci_cardbus_io_size = DEFAULT_CARDBUS_IO_SIZE;
28unsigned long pci_cardbus_mem_size = DEFAULT_CARDBUS_MEM_SIZE;
29
24/** 30/**
25 * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children 31 * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children
26 * @bus: pointer to PCI bus structure to search 32 * @bus: pointer to PCI bus structure to search
@@ -875,13 +881,6 @@ pci_disable_device(struct pci_dev *dev)
875 if (atomic_sub_return(1, &dev->enable_cnt) != 0) 881 if (atomic_sub_return(1, &dev->enable_cnt) != 0)
876 return; 882 return;
877 883
878 if (dev->msi_enabled)
879 disable_msi_mode(dev, pci_find_capability(dev, PCI_CAP_ID_MSI),
880 PCI_CAP_ID_MSI);
881 if (dev->msix_enabled)
882 disable_msi_mode(dev, pci_find_capability(dev, PCI_CAP_ID_MSI),
883 PCI_CAP_ID_MSIX);
884
885 pci_read_config_word(dev, PCI_COMMAND, &pci_command); 884 pci_read_config_word(dev, PCI_COMMAND, &pci_command);
886 if (pci_command & PCI_COMMAND_MASTER) { 885 if (pci_command & PCI_COMMAND_MASTER) {
887 pci_command &= ~PCI_COMMAND_MASTER; 886 pci_command &= ~PCI_COMMAND_MASTER;
@@ -1271,6 +1270,33 @@ pci_intx(struct pci_dev *pdev, int enable)
1271 } 1270 }
1272} 1271}
1273 1272
1273/**
1274 * pci_msi_off - disables any msi or msix capabilities
1275 * @pdev: the PCI device to operate on
1276 *
1277 * If you want to use msi see pci_enable_msi and friends.
1278 * This is a lower level primitive that allows us to disable
1279 * msi operation at the device level.
1280 */
1281void pci_msi_off(struct pci_dev *dev)
1282{
1283 int pos;
1284 u16 control;
1285
1286 pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
1287 if (pos) {
1288 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control);
1289 control &= ~PCI_MSI_FLAGS_ENABLE;
1290 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control);
1291 }
1292 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
1293 if (pos) {
1294 pci_read_config_word(dev, pos + PCI_MSIX_FLAGS, &control);
1295 control &= ~PCI_MSIX_FLAGS_ENABLE;
1296 pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control);
1297 }
1298}
1299
1274#ifndef HAVE_ARCH_PCI_SET_DMA_MASK 1300#ifndef HAVE_ARCH_PCI_SET_DMA_MASK
1275/* 1301/*
1276 * These can be overridden by arch-specific implementations 1302 * These can be overridden by arch-specific implementations
@@ -1300,7 +1326,7 @@ pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask)
1300 1326
1301/** 1327/**
1302 * pci_select_bars - Make BAR mask from the type of resource 1328 * pci_select_bars - Make BAR mask from the type of resource
1303 * @pdev: the PCI device for which BAR mask is made 1329 * @dev: the PCI device for which BAR mask is made
1304 * @flags: resource type mask to be selected 1330 * @flags: resource type mask to be selected
1305 * 1331 *
1306 * This helper routine makes bar mask from the type of resource. 1332 * This helper routine makes bar mask from the type of resource.
@@ -1333,6 +1359,10 @@ static int __devinit pci_setup(char *str)
1333 if (*str && (str = pcibios_setup(str)) && *str) { 1359 if (*str && (str = pcibios_setup(str)) && *str) {
1334 if (!strcmp(str, "nomsi")) { 1360 if (!strcmp(str, "nomsi")) {
1335 pci_no_msi(); 1361 pci_no_msi();
1362 } else if (!strncmp(str, "cbiosize=", 9)) {
1363 pci_cardbus_io_size = memparse(str + 9, &str);
1364 } else if (!strncmp(str, "cbmemsize=", 10)) {
1365 pci_cardbus_mem_size = memparse(str + 10, &str);
1336 } else { 1366 } else {
1337 printk(KERN_ERR "PCI: Unknown option `%s'\n", 1367 printk(KERN_ERR "PCI: Unknown option `%s'\n",
1338 str); 1368 str);
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index a4f2d58062..ae7a975995 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -46,10 +46,8 @@ extern struct rw_semaphore pci_bus_sem;
46extern unsigned int pci_pm_d3_delay; 46extern unsigned int pci_pm_d3_delay;
47 47
48#ifdef CONFIG_PCI_MSI 48#ifdef CONFIG_PCI_MSI
49void disable_msi_mode(struct pci_dev *dev, int pos, int type);
50void pci_no_msi(void); 49void pci_no_msi(void);
51#else 50#else
52static inline void disable_msi_mode(struct pci_dev *dev, int pos, int type) { }
53static inline void pci_no_msi(void) { } 51static inline void pci_no_msi(void) { }
54#endif 52#endif
55 53
diff --git a/drivers/pci/pcie/aer/aerdrv.h b/drivers/pci/pcie/aer/aerdrv.h
index 3c0a58f64d..bf655dbaf8 100644
--- a/drivers/pci/pcie/aer/aerdrv.h
+++ b/drivers/pci/pcie/aer/aerdrv.h
@@ -85,7 +85,7 @@ struct aer_rpc {
85 struct mutex rpc_mutex; /* 85 struct mutex rpc_mutex; /*
86 * only one thread could do 86 * only one thread could do
87 * recovery on the same 87 * recovery on the same
88 * root port hierachy 88 * root port hierarchy
89 */ 89 */
90 wait_queue_head_t wait_release; 90 wait_queue_head_t wait_release;
91}; 91};
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 2fe1d690eb..a4a96826d9 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -682,7 +682,34 @@ static void pci_read_irq(struct pci_dev *dev)
682 dev->irq = irq; 682 dev->irq = irq;
683} 683}
684 684
685#define LEGACY_IO_RESOURCE (IORESOURCE_IO | IORESOURCE_PCI_FIXED) 685static void change_legacy_io_resource(struct pci_dev * dev, unsigned index,
686 unsigned start, unsigned end)
687{
688 unsigned base = start & PCI_BASE_ADDRESS_IO_MASK;
689 unsigned len = (end | ~PCI_BASE_ADDRESS_IO_MASK) - base + 1;
690
691 /*
692 * Some X versions get confused when the BARs reported through
693 * /sys or /proc differ from those seen in config space, thus
694 * try to update the config space values, too.
695 */
696 if (!(pci_resource_flags(dev, index) & IORESOURCE_IO))
697 printk(KERN_WARNING "%s: cannot adjust BAR%u (not I/O)\n",
698 pci_name(dev), index);
699 else if (pci_resource_len(dev, index) != len)
700 printk(KERN_WARNING "%s: cannot adjust BAR%u (size %04X)\n",
701 pci_name(dev), index, (unsigned)pci_resource_len(dev, index));
702 else {
703 printk(KERN_INFO "%s: trying to change BAR%u from %04X to %04X\n",
704 pci_name(dev), index,
705 (unsigned)pci_resource_start(dev, index), base);
706 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + index * 4, base);
707 }
708 pci_resource_start(dev, index) = start;
709 pci_resource_end(dev, index) = end;
710 pci_resource_flags(dev, index) =
711 IORESOURCE_IO | IORESOURCE_PCI_FIXED | PCI_BASE_ADDRESS_SPACE_IO;
712}
686 713
687/** 714/**
688 * pci_setup_device - fill in class and map information of a device 715 * pci_setup_device - fill in class and map information of a device
@@ -735,20 +762,12 @@ static int pci_setup_device(struct pci_dev * dev)
735 u8 progif; 762 u8 progif;
736 pci_read_config_byte(dev, PCI_CLASS_PROG, &progif); 763 pci_read_config_byte(dev, PCI_CLASS_PROG, &progif);
737 if ((progif & 1) == 0) { 764 if ((progif & 1) == 0) {
738 dev->resource[0].start = 0x1F0; 765 change_legacy_io_resource(dev, 0, 0x1F0, 0x1F7);
739 dev->resource[0].end = 0x1F7; 766 change_legacy_io_resource(dev, 1, 0x3F6, 0x3F6);
740 dev->resource[0].flags = LEGACY_IO_RESOURCE;
741 dev->resource[1].start = 0x3F6;
742 dev->resource[1].end = 0x3F6;
743 dev->resource[1].flags = LEGACY_IO_RESOURCE;
744 } 767 }
745 if ((progif & 4) == 0) { 768 if ((progif & 4) == 0) {
746 dev->resource[2].start = 0x170; 769 change_legacy_io_resource(dev, 2, 0x170, 0x177);
747 dev->resource[2].end = 0x177; 770 change_legacy_io_resource(dev, 3, 0x376, 0x376);
748 dev->resource[2].flags = LEGACY_IO_RESOURCE;
749 dev->resource[3].start = 0x376;
750 dev->resource[3].end = 0x376;
751 dev->resource[3].flags = LEGACY_IO_RESOURCE;
752 } 771 }
753 } 772 }
754 break; 773 break;
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 1e6eda25c0..7f94fc098c 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -1218,45 +1218,68 @@ DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_a
1218 * do this early on to make the additional device appear during 1218 * do this early on to make the additional device appear during
1219 * the PCI scanning. 1219 * the PCI scanning.
1220 */ 1220 */
1221 1221static void quirk_jmicron_ata(struct pci_dev *pdev)
1222static void quirk_jmicron_dualfn(struct pci_dev *pdev)
1223{ 1222{
1224 u32 conf; 1223 u32 conf1, conf5, class;
1225 u8 hdr; 1224 u8 hdr;
1226 1225
1227 /* Only poke fn 0 */ 1226 /* Only poke fn 0 */
1228 if (PCI_FUNC(pdev->devfn)) 1227 if (PCI_FUNC(pdev->devfn))
1229 return; 1228 return;
1230 1229
1231 switch(pdev->device) { 1230 pci_read_config_dword(pdev, 0x40, &conf1);
1232 case PCI_DEVICE_ID_JMICRON_JMB365: 1231 pci_read_config_dword(pdev, 0x80, &conf5);
1233 case PCI_DEVICE_ID_JMICRON_JMB366:
1234 /* Redirect IDE second PATA port to the right spot */
1235 pci_read_config_dword(pdev, 0x80, &conf);
1236 conf |= (1 << 24);
1237 /* Fall through */
1238 pci_write_config_dword(pdev, 0x80, conf);
1239 case PCI_DEVICE_ID_JMICRON_JMB361:
1240 case PCI_DEVICE_ID_JMICRON_JMB363:
1241 pci_read_config_dword(pdev, 0x40, &conf);
1242 /* Enable dual function mode, AHCI on fn 0, IDE fn1 */
1243 /* Set the class codes correctly and then direct IDE 0 */
1244 conf &= ~0x000FF200; /* Clear bit 9 and 12-19 */
1245 conf |= 0x00C2A102; /* Set 1, 8, 13, 15, 17, 22, 23 */
1246 pci_write_config_dword(pdev, 0x40, conf);
1247
1248 /* Reconfigure so that the PCI scanner discovers the
1249 device is now multifunction */
1250
1251 pci_read_config_byte(pdev, PCI_HEADER_TYPE, &hdr);
1252 pdev->hdr_type = hdr & 0x7f;
1253 pdev->multifunction = !!(hdr & 0x80);
1254 1232
1255 break; 1233 conf1 &= ~0x00CFF302; /* Clear bit 1, 8, 9, 12-19, 22, 23 */
1234 conf5 &= ~(1 << 24); /* Clear bit 24 */
1235
1236 switch (pdev->device) {
1237 case PCI_DEVICE_ID_JMICRON_JMB360:
1238 /* The controller should be in single function ahci mode */
1239 conf1 |= 0x0002A100; /* Set 8, 13, 15, 17 */
1240 break;
1241
1242 case PCI_DEVICE_ID_JMICRON_JMB365:
1243 case PCI_DEVICE_ID_JMICRON_JMB366:
1244 /* Redirect IDE second PATA port to the right spot */
1245 conf5 |= (1 << 24);
1246 /* Fall through */
1247 case PCI_DEVICE_ID_JMICRON_JMB361:
1248 case PCI_DEVICE_ID_JMICRON_JMB363:
1249 /* Enable dual function mode, AHCI on fn 0, IDE fn1 */
1250 /* Set the class codes correctly and then direct IDE 0 */
1251 conf1 |= 0x00C2A102; /* Set 1, 8, 13, 15, 17, 22, 23 */
1252 break;
1253
1254 case PCI_DEVICE_ID_JMICRON_JMB368:
1255 /* The controller should be in single function IDE mode */
1256 conf1 |= 0x00C00000; /* Set 22, 23 */
1257 break;
1256 } 1258 }
1257} 1259
1258DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, quirk_jmicron_dualfn); 1260 pci_write_config_dword(pdev, 0x40, conf1);
1259DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, quirk_jmicron_dualfn); 1261 pci_write_config_dword(pdev, 0x80, conf5);
1262
1263 /* Update pdev accordingly */
1264 pci_read_config_byte(pdev, PCI_HEADER_TYPE, &hdr);
1265 pdev->hdr_type = hdr & 0x7f;
1266 pdev->multifunction = !!(hdr & 0x80);
1267
1268 pci_read_config_dword(pdev, PCI_CLASS_REVISION, &class);
1269 pdev->class = class >> 8;
1270}
1271DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB360, quirk_jmicron_ata);
1272DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, quirk_jmicron_ata);
1273DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, quirk_jmicron_ata);
1274DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata);
1275DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata);
1276DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata);
1277DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB360, quirk_jmicron_ata);
1278DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, quirk_jmicron_ata);
1279DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, quirk_jmicron_ata);
1280DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata);
1281DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata);
1282DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata);
1260 1283
1261#endif 1284#endif
1262 1285
@@ -1415,8 +1438,8 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7525_MCH, quir
1415 */ 1438 */
1416static void __devinit quirk_pcie_pxh(struct pci_dev *dev) 1439static void __devinit quirk_pcie_pxh(struct pci_dev *dev)
1417{ 1440{
1418 disable_msi_mode(dev, pci_find_capability(dev, PCI_CAP_ID_MSI), 1441 pci_msi_off(dev);
1419 PCI_CAP_ID_MSI); 1442
1420 dev->no_msi = 1; 1443 dev->no_msi = 1;
1421 1444
1422 printk(KERN_WARNING "PCI: PXH quirk detected, " 1445 printk(KERN_WARNING "PCI: PXH quirk detected, "
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 89f3036f0d..3554f39488 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -36,13 +36,6 @@
36 36
37#define ROUND_UP(x, a) (((x) + (a) - 1) & ~((a) - 1)) 37#define ROUND_UP(x, a) (((x) + (a) - 1) & ~((a) - 1))
38 38
39/*
40 * FIXME: IO should be max 256 bytes. However, since we may
41 * have a P2P bridge below a cardbus bridge, we need 4K.
42 */
43#define CARDBUS_IO_SIZE (256)
44#define CARDBUS_MEM_SIZE (64*1024*1024)
45
46static void __devinit 39static void __devinit
47pbus_assign_resources_sorted(struct pci_bus *bus) 40pbus_assign_resources_sorted(struct pci_bus *bus)
48{ 41{
@@ -415,12 +408,12 @@ pci_bus_size_cardbus(struct pci_bus *bus)
415 * Reserve some resources for CardBus. We reserve 408 * Reserve some resources for CardBus. We reserve
416 * a fixed amount of bus space for CardBus bridges. 409 * a fixed amount of bus space for CardBus bridges.
417 */ 410 */
418 b_res[0].start = CARDBUS_IO_SIZE; 411 b_res[0].start = pci_cardbus_io_size;
419 b_res[0].end = b_res[0].start + CARDBUS_IO_SIZE - 1; 412 b_res[0].end = b_res[0].start + pci_cardbus_io_size - 1;
420 b_res[0].flags |= IORESOURCE_IO; 413 b_res[0].flags |= IORESOURCE_IO;
421 414
422 b_res[1].start = CARDBUS_IO_SIZE; 415 b_res[1].start = pci_cardbus_io_size;
423 b_res[1].end = b_res[1].start + CARDBUS_IO_SIZE - 1; 416 b_res[1].end = b_res[1].start + pci_cardbus_io_size - 1;
424 b_res[1].flags |= IORESOURCE_IO; 417 b_res[1].flags |= IORESOURCE_IO;
425 418
426 /* 419 /*
@@ -440,16 +433,16 @@ pci_bus_size_cardbus(struct pci_bus *bus)
440 * twice the size. 433 * twice the size.
441 */ 434 */
442 if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) { 435 if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) {
443 b_res[2].start = CARDBUS_MEM_SIZE; 436 b_res[2].start = pci_cardbus_mem_size;
444 b_res[2].end = b_res[2].start + CARDBUS_MEM_SIZE - 1; 437 b_res[2].end = b_res[2].start + pci_cardbus_mem_size - 1;
445 b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH; 438 b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH;
446 439
447 b_res[3].start = CARDBUS_MEM_SIZE; 440 b_res[3].start = pci_cardbus_mem_size;
448 b_res[3].end = b_res[3].start + CARDBUS_MEM_SIZE - 1; 441 b_res[3].end = b_res[3].start + pci_cardbus_mem_size - 1;
449 b_res[3].flags |= IORESOURCE_MEM; 442 b_res[3].flags |= IORESOURCE_MEM;
450 } else { 443 } else {
451 b_res[3].start = CARDBUS_MEM_SIZE * 2; 444 b_res[3].start = pci_cardbus_mem_size * 2;
452 b_res[3].end = b_res[3].start + CARDBUS_MEM_SIZE * 2 - 1; 445 b_res[3].end = b_res[3].start + pci_cardbus_mem_size * 2 - 1;
453 b_res[3].flags |= IORESOURCE_MEM; 446 b_res[3].flags |= IORESOURCE_MEM;
454 } 447 }
455} 448}
diff --git a/drivers/pci/setup-irq.c b/drivers/pci/setup-irq.c
index a251289c99..568f187731 100644
--- a/drivers/pci/setup-irq.c
+++ b/drivers/pci/setup-irq.c
@@ -24,7 +24,7 @@ pdev_fixup_irq(struct pci_dev *dev,
24 int (*map_irq)(struct pci_dev *, u8, u8)) 24 int (*map_irq)(struct pci_dev *, u8, u8))
25{ 25{
26 u8 pin, slot; 26 u8 pin, slot;
27 int irq; 27 int irq = 0;
28 28
29 /* If this device is not on the primary bus, we need to figure out 29 /* If this device is not on the primary bus, we need to figure out
30 which interrupt pin it will come in on. We know which slot it 30 which interrupt pin it will come in on. We know which slot it
@@ -33,16 +33,18 @@ pdev_fixup_irq(struct pci_dev *dev,
33 apply the swizzle function. */ 33 apply the swizzle function. */
34 34
35 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin); 35 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
36 /* Cope with 0 and illegal. */ 36 /* Cope with illegal. */
37 if (pin == 0 || pin > 4) 37 if (pin > 4)
38 pin = 1; 38 pin = 1;
39 39
40 /* Follow the chain of bridges, swizzling as we go. */ 40 if (pin != 0) {
41 slot = (*swizzle)(dev, &pin); 41 /* Follow the chain of bridges, swizzling as we go. */
42 slot = (*swizzle)(dev, &pin);
42 43
43 irq = (*map_irq)(dev, slot, pin); 44 irq = (*map_irq)(dev, slot, pin);
44 if (irq == -1) 45 if (irq == -1)
45 irq = 0; 46 irq = 0;
47 }
46 dev->irq = irq; 48 dev->irq = irq;
47 49
48 pr_debug("PCI: fixup irq: (%s) got %d\n", 50 pr_debug("PCI: fixup irq: (%s) got %d\n",
diff --git a/drivers/pcmcia/at91_cf.c b/drivers/pcmcia/at91_cf.c
index b318628375..99baabc235 100644
--- a/drivers/pcmcia/at91_cf.c
+++ b/drivers/pcmcia/at91_cf.c
@@ -277,7 +277,7 @@ static int __init at91_cf_probe(struct platform_device *pdev)
277 board->det_pin, board->irq_pin); 277 board->det_pin, board->irq_pin);
278 278
279 cf->socket.owner = THIS_MODULE; 279 cf->socket.owner = THIS_MODULE;
280 cf->socket.dev.dev = &pdev->dev; 280 cf->socket.dev.parent = &pdev->dev;
281 cf->socket.ops = &at91_cf_ops; 281 cf->socket.ops = &at91_cf_ops;
282 cf->socket.resource_ops = &pccard_static_ops; 282 cf->socket.resource_ops = &pccard_static_ops;
283 cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP 283 cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP
diff --git a/drivers/pcmcia/cardbus.c b/drivers/pcmcia/cardbus.c
index 2d7effe799..a1bd763b4e 100644
--- a/drivers/pcmcia/cardbus.c
+++ b/drivers/pcmcia/cardbus.c
@@ -40,8 +40,6 @@
40 40
41/*====================================================================*/ 41/*====================================================================*/
42 42
43#define FIND_FIRST_BIT(n) ((n) - ((n) & ((n)-1)))
44
45/* Offsets in the Expansion ROM Image Header */ 43/* Offsets in the Expansion ROM Image Header */
46#define ROM_SIGNATURE 0x0000 /* 2 bytes */ 44#define ROM_SIGNATURE 0x0000 /* 2 bytes */
47#define ROM_DATA_PTR 0x0018 /* 2 bytes */ 45#define ROM_DATA_PTR 0x0018 /* 2 bytes */
diff --git a/drivers/pcmcia/hd64465_ss.c b/drivers/pcmcia/hd64465_ss.c
index caca0dc9d3..f2e810f53c 100644
--- a/drivers/pcmcia/hd64465_ss.c
+++ b/drivers/pcmcia/hd64465_ss.c
@@ -907,7 +907,7 @@ static int __init init_hs(void)
907 907
908 for (i=0; i<HS_MAX_SOCKETS; i++) { 908 for (i=0; i<HS_MAX_SOCKETS; i++) {
909 unsigned int ret; 909 unsigned int ret;
910 hs_sockets[i].socket.dev.dev = &hd64465_device.dev; 910 hs_sockets[i].socket.dev.parent = &hd64465_device.dev;
911 hs_sockets[i].number = i; 911 hs_sockets[i].number = i;
912 ret = pcmcia_register_socket(&hs_sockets[i].socket); 912 ret = pcmcia_register_socket(&hs_sockets[i].socket);
913 if (ret && i) 913 if (ret && i)
diff --git a/drivers/pcmcia/m32r_cfc.c b/drivers/pcmcia/m32r_cfc.c
index e4a94108aa..91da15b5a8 100644
--- a/drivers/pcmcia/m32r_cfc.c
+++ b/drivers/pcmcia/m32r_cfc.c
@@ -760,7 +760,7 @@ static int __init init_m32r_pcc(void)
760 /* Set up interrupt handler(s) */ 760 /* Set up interrupt handler(s) */
761 761
762 for (i = 0 ; i < pcc_sockets ; i++) { 762 for (i = 0 ; i < pcc_sockets ; i++) {
763 socket[i].socket.dev.dev = &pcc_device.dev; 763 socket[i].socket.dev.parent = &pcc_device.dev;
764 socket[i].socket.ops = &pcc_operations; 764 socket[i].socket.ops = &pcc_operations;
765 socket[i].socket.resource_ops = &pccard_nonstatic_ops; 765 socket[i].socket.resource_ops = &pccard_nonstatic_ops;
766 socket[i].socket.owner = THIS_MODULE; 766 socket[i].socket.owner = THIS_MODULE;
diff --git a/drivers/pcmcia/m8xx_pcmcia.c b/drivers/pcmcia/m8xx_pcmcia.c
index d059c91961..9721ed7bf5 100644
--- a/drivers/pcmcia/m8xx_pcmcia.c
+++ b/drivers/pcmcia/m8xx_pcmcia.c
@@ -1321,7 +1321,7 @@ static int __init m8xx_init(void)
1321 socket[i].socket.ops = &m8xx_services; 1321 socket[i].socket.ops = &m8xx_services;
1322 socket[i].socket.resource_ops = &pccard_iodyn_ops; 1322 socket[i].socket.resource_ops = &pccard_iodyn_ops;
1323 socket[i].socket.cb_dev = NULL; 1323 socket[i].socket.cb_dev = NULL;
1324 socket[i].socket.dev.dev = &m8xx_device.dev; 1324 socket[i].socket.dev.parent = &m8xx_device.dev;
1325 } 1325 }
1326 1326
1327 for (i = 0; i < PCMCIA_SOCKETS_NO; i++) 1327 for (i = 0; i < PCMCIA_SOCKETS_NO; i++)
diff --git a/drivers/pcmcia/omap_cf.c b/drivers/pcmcia/omap_cf.c
index 76f7cbc62a..d77f75129f 100644
--- a/drivers/pcmcia/omap_cf.c
+++ b/drivers/pcmcia/omap_cf.c
@@ -291,7 +291,7 @@ static int __devinit omap_cf_probe(struct device *dev)
291 omap_cf_present() ? "present" : "(not present)"); 291 omap_cf_present() ? "present" : "(not present)");
292 292
293 cf->socket.owner = THIS_MODULE; 293 cf->socket.owner = THIS_MODULE;
294 cf->socket.dev.dev = dev; 294 cf->socket.dev.parent = dev;
295 cf->socket.ops = &omap_cf_ops; 295 cf->socket.ops = &omap_cf_ops;
296 cf->socket.resource_ops = &pccard_static_ops; 296 cf->socket.resource_ops = &pccard_static_ops;
297 cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP 297 cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP
diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c
index 81dfc2cac2..ce2226273a 100644
--- a/drivers/pcmcia/rsrc_mgr.c
+++ b/drivers/pcmcia/rsrc_mgr.c
@@ -232,7 +232,7 @@ static struct resource *iodyn_find_io_region(unsigned long base, int num,
232 unsigned long align, struct pcmcia_socket *s) 232 unsigned long align, struct pcmcia_socket *s)
233{ 233{
234 struct resource *res = make_resource(0, num, IORESOURCE_IO, 234 struct resource *res = make_resource(0, num, IORESOURCE_IO,
235 s->dev.class_id); 235 s->dev.bus_id);
236 struct pcmcia_align_data data; 236 struct pcmcia_align_data data;
237 unsigned long min = base; 237 unsigned long min = base;
238 int ret; 238 int ret;
diff --git a/drivers/pcmcia/soc_common.c b/drivers/pcmcia/soc_common.c
index d2a3bea55d..aa7779d897 100644
--- a/drivers/pcmcia/soc_common.c
+++ b/drivers/pcmcia/soc_common.c
@@ -478,7 +478,7 @@ dump_bits(char **p, const char *prefix, unsigned int val, struct bittbl *bits, i
478 * 478 *
479 * Returns: the number of characters added to the buffer 479 * Returns: the number of characters added to the buffer
480 */ 480 */
481static ssize_t show_status(struct device *dev, char *buf) 481static ssize_t show_status(struct device *dev, struct device_attribute *attr, char *buf)
482{ 482{
483 struct soc_pcmcia_socket *skt = 483 struct soc_pcmcia_socket *skt =
484 container_of(dev, struct soc_pcmcia_socket, socket.dev); 484 container_of(dev, struct soc_pcmcia_socket, socket.dev);
@@ -501,7 +501,7 @@ static ssize_t show_status(struct device *dev, char *buf)
501 501
502 return p-buf; 502 return p-buf;
503} 503}
504static CLASS_DEVICE_ATTR(status, S_IRUGO, show_status, NULL); 504static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
505 505
506 506
507static struct pccard_operations soc_common_pcmcia_operations = { 507static struct pccard_operations soc_common_pcmcia_operations = {
@@ -660,7 +660,7 @@ int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops
660 660
661 skt->socket.ops = &soc_common_pcmcia_operations; 661 skt->socket.ops = &soc_common_pcmcia_operations;
662 skt->socket.owner = ops->owner; 662 skt->socket.owner = ops->owner;
663 skt->socket.dev.dev = dev; 663 skt->socket.dev.parent = dev;
664 664
665 init_timer(&skt->poll_timer); 665 init_timer(&skt->poll_timer);
666 skt->poll_timer.function = soc_common_pcmcia_poll_event; 666 skt->poll_timer.function = soc_common_pcmcia_poll_event;
@@ -747,7 +747,7 @@ int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops
747 747
748 add_timer(&skt->poll_timer); 748 add_timer(&skt->poll_timer);
749 749
750 device_create_file(&skt->socket.dev, &device_attr_status); 750 device_create_file(&skt->socket.dev, &dev_attr_status);
751 } 751 }
752 752
753 dev_set_drvdata(dev, sinfo); 753 dev_set_drvdata(dev, sinfo);
diff --git a/drivers/pcmcia/vrc4171_card.c b/drivers/pcmcia/vrc4171_card.c
index 206e26c918..eee2f1cb21 100644
--- a/drivers/pcmcia/vrc4171_card.c
+++ b/drivers/pcmcia/vrc4171_card.c
@@ -596,7 +596,7 @@ static int __devinit vrc4171_add_sockets(void)
596 } 596 }
597 597
598 sprintf(socket->name, "NEC VRC4171 Card Slot %1c", 'A' + slot); 598 sprintf(socket->name, "NEC VRC4171 Card Slot %1c", 'A' + slot);
599 socket->pcmcia_socket.dev.dev = &vrc4171_card_device.dev; 599 socket->pcmcia_socket.dev.parent = &vrc4171_card_device.dev;
600 socket->pcmcia_socket.ops = &vrc4171_pccard_operations; 600 socket->pcmcia_socket.ops = &vrc4171_pccard_operations;
601 socket->pcmcia_socket.owner = THIS_MODULE; 601 socket->pcmcia_socket.owner = THIS_MODULE;
602 602
diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c
index 7a535542fe..118ac9779b 100644
--- a/drivers/pnp/pnpacpi/rsparser.c
+++ b/drivers/pnp/pnpacpi/rsparser.c
@@ -89,6 +89,7 @@ pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res, u32 gsi,
89 return; 89 return;
90 90
91 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag 91 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag
92 res->irq_resource[i].flags |= irq_flags(triggering, polarity);
92 irq = acpi_register_gsi(gsi, triggering, polarity); 93 irq = acpi_register_gsi(gsi, triggering, polarity);
93 if (irq < 0) { 94 if (irq < 0) {
94 res->irq_resource[i].flags |= IORESOURCE_DISABLED; 95 res->irq_resource[i].flags |= IORESOURCE_DISABLED;
@@ -103,8 +104,52 @@ pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res, u32 gsi,
103 pcibios_penalize_isa_irq(irq, 1); 104 pcibios_penalize_isa_irq(irq, 1);
104} 105}
105 106
107static int dma_flags(int type, int bus_master, int transfer)
108{
109 int flags = 0;
110
111 if (bus_master)
112 flags |= IORESOURCE_DMA_MASTER;
113 switch (type) {
114 case ACPI_COMPATIBILITY:
115 flags |= IORESOURCE_DMA_COMPATIBLE;
116 break;
117 case ACPI_TYPE_A:
118 flags |= IORESOURCE_DMA_TYPEA;
119 break;
120 case ACPI_TYPE_B:
121 flags |= IORESOURCE_DMA_TYPEB;
122 break;
123 case ACPI_TYPE_F:
124 flags |= IORESOURCE_DMA_TYPEF;
125 break;
126 default:
127 /* Set a default value ? */
128 flags |= IORESOURCE_DMA_COMPATIBLE;
129 pnp_err("Invalid DMA type");
130 }
131 switch (transfer) {
132 case ACPI_TRANSFER_8:
133 flags |= IORESOURCE_DMA_8BIT;
134 break;
135 case ACPI_TRANSFER_8_16:
136 flags |= IORESOURCE_DMA_8AND16BIT;
137 break;
138 case ACPI_TRANSFER_16:
139 flags |= IORESOURCE_DMA_16BIT;
140 break;
141 default:
142 /* Set a default value ? */
143 flags |= IORESOURCE_DMA_8AND16BIT;
144 pnp_err("Invalid DMA transfer type");
145 }
146
147 return flags;
148}
149
106static void 150static void
107pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res, u32 dma) 151pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res, u32 dma,
152 int type, int bus_master, int transfer)
108{ 153{
109 int i = 0; 154 int i = 0;
110 while (i < PNP_MAX_DMA && 155 while (i < PNP_MAX_DMA &&
@@ -112,6 +157,7 @@ pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res, u32 dma)
112 i++; 157 i++;
113 if (i < PNP_MAX_DMA) { 158 if (i < PNP_MAX_DMA) {
114 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag 159 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
160 res->dma_resource[i].flags |= dma_flags(type, bus_master, transfer);
115 if (dma == -1) { 161 if (dma == -1) {
116 res->dma_resource[i].flags |= IORESOURCE_DISABLED; 162 res->dma_resource[i].flags |= IORESOURCE_DISABLED;
117 return; 163 return;
@@ -123,7 +169,7 @@ pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res, u32 dma)
123 169
124static void 170static void
125pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res, 171pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res,
126 u64 io, u64 len) 172 u64 io, u64 len, int io_decode)
127{ 173{
128 int i = 0; 174 int i = 0;
129 while (!(res->port_resource[i].flags & IORESOURCE_UNSET) && 175 while (!(res->port_resource[i].flags & IORESOURCE_UNSET) &&
@@ -131,6 +177,8 @@ pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res,
131 i++; 177 i++;
132 if (i < PNP_MAX_PORT) { 178 if (i < PNP_MAX_PORT) {
133 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag 179 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
180 if (io_decode == ACPI_DECODE_16)
181 res->port_resource[i].flags |= PNP_PORT_FLAG_16BITADDR;
134 if (len <= 0 || (io + len -1) >= 0x10003) { 182 if (len <= 0 || (io + len -1) >= 0x10003) {
135 res->port_resource[i].flags |= IORESOURCE_DISABLED; 183 res->port_resource[i].flags |= IORESOURCE_DISABLED;
136 return; 184 return;
@@ -142,7 +190,7 @@ pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res,
142 190
143static void 191static void
144pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res, 192pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res,
145 u64 mem, u64 len) 193 u64 mem, u64 len, int write_protect)
146{ 194{
147 int i = 0; 195 int i = 0;
148 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) && 196 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) &&
@@ -154,6 +202,9 @@ pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res,
154 res->mem_resource[i].flags |= IORESOURCE_DISABLED; 202 res->mem_resource[i].flags |= IORESOURCE_DISABLED;
155 return; 203 return;
156 } 204 }
205 if(write_protect == ACPI_READ_WRITE_MEMORY)
206 res->mem_resource[i].flags |= IORESOURCE_MEM_WRITEABLE;
207
157 res->mem_resource[i].start = mem; 208 res->mem_resource[i].start = mem;
158 res->mem_resource[i].end = mem + len - 1; 209 res->mem_resource[i].end = mem + len - 1;
159 } 210 }
@@ -178,10 +229,11 @@ pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
178 229
179 if (p->resource_type == ACPI_MEMORY_RANGE) 230 if (p->resource_type == ACPI_MEMORY_RANGE)
180 pnpacpi_parse_allocated_memresource(res_table, 231 pnpacpi_parse_allocated_memresource(res_table,
181 p->minimum, p->address_length); 232 p->minimum, p->address_length, p->info.mem.write_protect);
182 else if (p->resource_type == ACPI_IO_RANGE) 233 else if (p->resource_type == ACPI_IO_RANGE)
183 pnpacpi_parse_allocated_ioresource(res_table, 234 pnpacpi_parse_allocated_ioresource(res_table,
184 p->minimum, p->address_length); 235 p->minimum, p->address_length,
236 p->granularity == 0xfff ? ACPI_DECODE_10 : ACPI_DECODE_16);
185} 237}
186 238
187static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res, 239static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
@@ -208,13 +260,17 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
208 case ACPI_RESOURCE_TYPE_DMA: 260 case ACPI_RESOURCE_TYPE_DMA:
209 if (res->data.dma.channel_count > 0) 261 if (res->data.dma.channel_count > 0)
210 pnpacpi_parse_allocated_dmaresource(res_table, 262 pnpacpi_parse_allocated_dmaresource(res_table,
211 res->data.dma.channels[0]); 263 res->data.dma.channels[0],
264 res->data.dma.type,
265 res->data.dma.bus_master,
266 res->data.dma.transfer);
212 break; 267 break;
213 268
214 case ACPI_RESOURCE_TYPE_IO: 269 case ACPI_RESOURCE_TYPE_IO:
215 pnpacpi_parse_allocated_ioresource(res_table, 270 pnpacpi_parse_allocated_ioresource(res_table,
216 res->data.io.minimum, 271 res->data.io.minimum,
217 res->data.io.address_length); 272 res->data.io.address_length,
273 res->data.io.io_decode);
218 break; 274 break;
219 275
220 case ACPI_RESOURCE_TYPE_START_DEPENDENT: 276 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
@@ -224,7 +280,8 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
224 case ACPI_RESOURCE_TYPE_FIXED_IO: 280 case ACPI_RESOURCE_TYPE_FIXED_IO:
225 pnpacpi_parse_allocated_ioresource(res_table, 281 pnpacpi_parse_allocated_ioresource(res_table,
226 res->data.fixed_io.address, 282 res->data.fixed_io.address,
227 res->data.fixed_io.address_length); 283 res->data.fixed_io.address_length,
284 ACPI_DECODE_10);
228 break; 285 break;
229 286
230 case ACPI_RESOURCE_TYPE_VENDOR: 287 case ACPI_RESOURCE_TYPE_VENDOR:
@@ -236,17 +293,20 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
236 case ACPI_RESOURCE_TYPE_MEMORY24: 293 case ACPI_RESOURCE_TYPE_MEMORY24:
237 pnpacpi_parse_allocated_memresource(res_table, 294 pnpacpi_parse_allocated_memresource(res_table,
238 res->data.memory24.minimum, 295 res->data.memory24.minimum,
239 res->data.memory24.address_length); 296 res->data.memory24.address_length,
297 res->data.memory24.write_protect);
240 break; 298 break;
241 case ACPI_RESOURCE_TYPE_MEMORY32: 299 case ACPI_RESOURCE_TYPE_MEMORY32:
242 pnpacpi_parse_allocated_memresource(res_table, 300 pnpacpi_parse_allocated_memresource(res_table,
243 res->data.memory32.minimum, 301 res->data.memory32.minimum,
244 res->data.memory32.address_length); 302 res->data.memory32.address_length,
303 res->data.memory32.write_protect);
245 break; 304 break;
246 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: 305 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
247 pnpacpi_parse_allocated_memresource(res_table, 306 pnpacpi_parse_allocated_memresource(res_table,
248 res->data.fixed_memory32.address, 307 res->data.fixed_memory32.address,
249 res->data.fixed_memory32.address_length); 308 res->data.fixed_memory32.address_length,
309 res->data.fixed_memory32.write_protect);
250 break; 310 break;
251 case ACPI_RESOURCE_TYPE_ADDRESS16: 311 case ACPI_RESOURCE_TYPE_ADDRESS16:
252 case ACPI_RESOURCE_TYPE_ADDRESS32: 312 case ACPI_RESOURCE_TYPE_ADDRESS32:
@@ -304,42 +364,8 @@ static void pnpacpi_parse_dma_option(struct pnp_option *option, struct acpi_reso
304 364
305 for(i = 0; i < p->channel_count; i++) 365 for(i = 0; i < p->channel_count; i++)
306 dma->map |= 1 << p->channels[i]; 366 dma->map |= 1 << p->channels[i];
307 dma->flags = 0; 367
308 if (p->bus_master) 368 dma->flags = dma_flags(p->type, p->bus_master, p->transfer);
309 dma->flags |= IORESOURCE_DMA_MASTER;
310 switch (p->type) {
311 case ACPI_COMPATIBILITY:
312 dma->flags |= IORESOURCE_DMA_COMPATIBLE;
313 break;
314 case ACPI_TYPE_A:
315 dma->flags |= IORESOURCE_DMA_TYPEA;
316 break;
317 case ACPI_TYPE_B:
318 dma->flags |= IORESOURCE_DMA_TYPEB;
319 break;
320 case ACPI_TYPE_F:
321 dma->flags |= IORESOURCE_DMA_TYPEF;
322 break;
323 default:
324 /* Set a default value ? */
325 dma->flags |= IORESOURCE_DMA_COMPATIBLE;
326 pnp_err("Invalid DMA type");
327 }
328 switch (p->transfer) {
329 case ACPI_TRANSFER_8:
330 dma->flags |= IORESOURCE_DMA_8BIT;
331 break;
332 case ACPI_TRANSFER_8_16:
333 dma->flags |= IORESOURCE_DMA_8AND16BIT;
334 break;
335 case ACPI_TRANSFER_16:
336 dma->flags |= IORESOURCE_DMA_16BIT;
337 break;
338 default:
339 /* Set a default value ? */
340 dma->flags |= IORESOURCE_DMA_8AND16BIT;
341 pnp_err("Invalid DMA transfer type");
342 }
343 369
344 pnp_register_dma_resource(option, dma); 370 pnp_register_dma_resource(option, dma);
345 return; 371 return;
diff --git a/drivers/ps3/Makefile b/drivers/ps3/Makefile
index 96958c03cf..e251d1c117 100644
--- a/drivers/ps3/Makefile
+++ b/drivers/ps3/Makefile
@@ -1,2 +1,3 @@
1obj-$(CONFIG_PS3_VUART) += vuart.o 1obj-$(CONFIG_PS3_VUART) += vuart.o
2obj-$(CONFIG_PS3_PS3AV) += ps3av.o ps3av_cmd.o 2obj-$(CONFIG_PS3_PS3AV) += ps3av.o ps3av_cmd.o
3obj-$(CONFIG_PS3_SYS_MANAGER) += sys-manager.o
diff --git a/drivers/ps3/sys-manager.c b/drivers/ps3/sys-manager.c
new file mode 100644
index 0000000000..0fc30be8b8
--- /dev/null
+++ b/drivers/ps3/sys-manager.c
@@ -0,0 +1,604 @@
1/*
2 * PS3 System Manager.
3 *
4 * Copyright (C) 2007 Sony Computer Entertainment Inc.
5 * Copyright 2007 Sony Corp.
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; version 2 of the License.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/workqueue.h>
24#include <linux/reboot.h>
25#include <asm/ps3.h>
26#include "vuart.h"
27
28MODULE_AUTHOR("Sony Corporation");
29MODULE_LICENSE("GPL v2");
30MODULE_DESCRIPTION("PS3 System Manager");
31
32/**
33 * ps3_sys_manager - PS3 system manager driver.
34 *
35 * The system manager provides an asyncronous system event notification
36 * mechanism for reporting events like thermal alert and button presses to
37 * guests. It also provides support to control system shutdown and startup.
38 *
39 * The actual system manager is implemented as an application running in the
40 * system policy module in lpar_1. Guests communicate with the system manager
41 * through port 2 of the vuart using a simple packet message protocol.
42 * Messages are comprised of a fixed field header followed by a message
43 * specific payload.
44 */
45
46/**
47 * struct ps3_sys_manager_header - System manager message header.
48 * @version: Header version, currently 1.
49 * @size: Header size in bytes, curently 16.
50 * @payload_size: Message payload size in bytes.
51 * @service_id: Message type, one of enum ps3_sys_manager_service_id.
52 */
53
54struct ps3_sys_manager_header {
55 /* version 1 */
56 u8 version;
57 u8 size;
58 u16 reserved_1;
59 u32 payload_size;
60 u16 service_id;
61 u16 reserved_2[3];
62};
63
64/**
65 * @PS3_SM_RX_MSG_LEN - System manager received message length.
66 *
67 * Currently all messages received from the system manager are the same length
68 * (16 bytes header + 16 bytes payload = 32 bytes). This knowlege is used to
69 * simplify the logic.
70 */
71
72enum {
73 PS3_SM_RX_MSG_LEN = 32,
74};
75
76/**
77 * enum ps3_sys_manager_service_id - Message header service_id.
78 * @PS3_SM_SERVICE_ID_REQUEST: guest --> sys_manager.
79 * @PS3_SM_SERVICE_ID_COMMAND: guest <-- sys_manager.
80 * @PS3_SM_SERVICE_ID_RESPONSE: guest --> sys_manager.
81 * @PS3_SM_SERVICE_ID_SET_ATTR: guest --> sys_manager.
82 * @PS3_SM_SERVICE_ID_EXTERN_EVENT: guest <-- sys_manager.
83 * @PS3_SM_SERVICE_ID_SET_NEXT_OP: guest --> sys_manager.
84 */
85
86enum ps3_sys_manager_service_id {
87 /* version 1 */
88 PS3_SM_SERVICE_ID_REQUEST = 1,
89 PS3_SM_SERVICE_ID_RESPONSE = 2,
90 PS3_SM_SERVICE_ID_COMMAND = 3,
91 PS3_SM_SERVICE_ID_EXTERN_EVENT = 4,
92 PS3_SM_SERVICE_ID_SET_NEXT_OP = 5,
93 PS3_SM_SERVICE_ID_SET_ATTR = 8,
94};
95
96/**
97 * enum ps3_sys_manager_attr - Notification attribute (bit position mask).
98 * @PS3_SM_ATTR_POWER: Power button.
99 * @PS3_SM_ATTR_RESET: Reset button, not available on retail console.
100 * @PS3_SM_ATTR_THERMAL: Sytem thermal alert.
101 * @PS3_SM_ATTR_CONTROLLER: Remote controller event.
102 * @PS3_SM_ATTR_ALL: Logical OR of all.
103 *
104 * The guest tells the system manager which events it is interested in receiving
105 * notice of by sending the system manager a logical OR of notification
106 * attributes via the ps3_sys_manager_send_attr() routine.
107 */
108
109enum ps3_sys_manager_attr {
110 /* version 1 */
111 PS3_SM_ATTR_POWER = 1,
112 PS3_SM_ATTR_RESET = 2,
113 PS3_SM_ATTR_THERMAL = 4,
114 PS3_SM_ATTR_CONTROLLER = 8, /* bogus? */
115 PS3_SM_ATTR_ALL = 0x0f,
116};
117
118/**
119 * enum ps3_sys_manager_event - External event type, reported by system manager.
120 * @PS3_SM_EVENT_POWER_PRESSED: payload.value not used.
121 * @PS3_SM_EVENT_POWER_RELEASED: payload.value = time pressed in millisec.
122 * @PS3_SM_EVENT_RESET_PRESSED: payload.value not used.
123 * @PS3_SM_EVENT_RESET_RELEASED: payload.value = time pressed in millisec.
124 * @PS3_SM_EVENT_THERMAL_ALERT: payload.value = thermal zone id.
125 * @PS3_SM_EVENT_THERMAL_CLEARED: payload.value = thermal zone id.
126 */
127
128enum ps3_sys_manager_event {
129 /* version 1 */
130 PS3_SM_EVENT_POWER_PRESSED = 3,
131 PS3_SM_EVENT_POWER_RELEASED = 4,
132 PS3_SM_EVENT_RESET_PRESSED = 5,
133 PS3_SM_EVENT_RESET_RELEASED = 6,
134 PS3_SM_EVENT_THERMAL_ALERT = 7,
135 PS3_SM_EVENT_THERMAL_CLEARED = 8,
136 /* no info on controller events */
137};
138
139/**
140 * enum ps3_sys_manager_next_op - Operation to perform after lpar is destroyed.
141 */
142
143enum ps3_sys_manager_next_op {
144 /* version 3 */
145 PS3_SM_NEXT_OP_SYS_SHUTDOWN = 1,
146 PS3_SM_NEXT_OP_SYS_REBOOT = 2,
147 PS3_SM_NEXT_OP_LPAR_REBOOT = 0x82,
148};
149
150/**
151 * enum ps3_sys_manager_wake_source - Next-op wakeup source (bit position mask).
152 * @PS3_SM_WAKE_DEFAULT: Disk insert, power button, eject button, IR
153 * controller, and bluetooth controller.
154 * @PS3_SM_WAKE_RTC:
155 * @PS3_SM_WAKE_RTC_ERROR:
156 * @PS3_SM_WAKE_P_O_R: Power on reset.
157 *
158 * Additional wakeup sources when specifying PS3_SM_NEXT_OP_SYS_SHUTDOWN.
159 * System will always wake from the PS3_SM_WAKE_DEFAULT sources.
160 */
161
162enum ps3_sys_manager_wake_source {
163 /* version 3 */
164 PS3_SM_WAKE_DEFAULT = 0,
165 PS3_SM_WAKE_RTC = 0x00000040,
166 PS3_SM_WAKE_RTC_ERROR = 0x00000080,
167 PS3_SM_WAKE_P_O_R = 0x10000000,
168};
169
170/**
171 * enum ps3_sys_manager_cmd - Command from system manager to guest.
172 *
173 * The guest completes the actions needed, then acks or naks the command via
174 * ps3_sys_manager_send_response(). In the case of @PS3_SM_CMD_SHUTDOWN,
175 * the guest must be fully prepared for a system poweroff prior to acking the
176 * command.
177 */
178
179enum ps3_sys_manager_cmd {
180 /* version 1 */
181 PS3_SM_CMD_SHUTDOWN = 1, /* shutdown guest OS */
182};
183
184/**
185 * ps3_sys_manager_write - Helper to write a two part message to the vuart.
186 *
187 */
188
189static int ps3_sys_manager_write(struct ps3_vuart_port_device *dev,
190 const struct ps3_sys_manager_header *header, const void *payload)
191{
192 int result;
193
194 BUG_ON(header->version != 1);
195 BUG_ON(header->size != 16);
196 BUG_ON(header->payload_size != 8 && header->payload_size != 16);
197 BUG_ON(header->service_id > 8);
198
199 result = ps3_vuart_write(dev, header,
200 sizeof(struct ps3_sys_manager_header));
201
202 if (!result)
203 result = ps3_vuart_write(dev, payload, header->payload_size);
204
205 return result;
206}
207
208/**
209 * ps3_sys_manager_send_attr - Send a 'set attribute' to the system manager.
210 *
211 */
212
213static int ps3_sys_manager_send_attr(struct ps3_vuart_port_device *dev,
214 enum ps3_sys_manager_attr attr)
215{
216 static const struct ps3_sys_manager_header header = {
217 .version = 1,
218 .size = 16,
219 .payload_size = 16,
220 .service_id = PS3_SM_SERVICE_ID_SET_ATTR,
221 };
222 struct {
223 u8 version;
224 u8 reserved_1[3];
225 u32 attribute;
226 } payload;
227
228 BUILD_BUG_ON(sizeof(payload) != 8);
229
230 dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, attr);
231
232 memset(&payload, 0, sizeof(payload));
233 payload.version = 1;
234 payload.attribute = attr;
235
236 return ps3_sys_manager_write(dev, &header, &payload);
237}
238
239/**
240 * ps3_sys_manager_send_next_op - Send a 'set next op' to the system manager.
241 *
242 * Tell the system manager what to do after this lpar is destroyed.
243 */
244
245static int ps3_sys_manager_send_next_op(struct ps3_vuart_port_device *dev,
246 enum ps3_sys_manager_next_op op,
247 enum ps3_sys_manager_wake_source wake_source)
248{
249 static const struct ps3_sys_manager_header header = {
250 .version = 1,
251 .size = 16,
252 .payload_size = 16,
253 .service_id = PS3_SM_SERVICE_ID_SET_NEXT_OP,
254 };
255 struct {
256 u8 version;
257 u8 type;
258 u8 gos_id;
259 u8 reserved_1;
260 u32 wake_source;
261 u8 reserved_2[8];
262 } payload;
263
264 BUILD_BUG_ON(sizeof(payload) != 16);
265
266 dev_dbg(&dev->core, "%s:%d: (%xh)\n", __func__, __LINE__, op);
267
268 memset(&payload, 0, sizeof(payload));
269 payload.version = 3;
270 payload.type = op;
271 payload.gos_id = 3; /* other os */
272 payload.wake_source = wake_source;
273
274 return ps3_sys_manager_write(dev, &header, &payload);
275}
276
277/**
278 * ps3_sys_manager_send_request_shutdown - Send 'request' to the system manager.
279 *
280 * The guest sends this message to request an operation or action of the system
281 * manager. The reply is a command message from the system manager. In the
282 * command handler the guest performs the requested operation. The result of
283 * the command is then communicated back to the system manager with a response
284 * message.
285 *
286 * Currently, the only supported request it the 'shutdown self' request.
287 */
288
289static int ps3_sys_manager_send_request_shutdown(struct ps3_vuart_port_device *dev)
290{
291 static const struct ps3_sys_manager_header header = {
292 .version = 1,
293 .size = 16,
294 .payload_size = 16,
295 .service_id = PS3_SM_SERVICE_ID_REQUEST,
296 };
297 struct {
298 u8 version;
299 u8 type;
300 u8 gos_id;
301 u8 reserved_1[13];
302 } static const payload = {
303 .version = 1,
304 .type = 1, /* shutdown */
305 .gos_id = 0, /* self */
306 };
307
308 BUILD_BUG_ON(sizeof(payload) != 16);
309
310 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
311
312 return ps3_sys_manager_write(dev, &header, &payload);
313}
314
315/**
316 * ps3_sys_manager_send_response - Send a 'response' to the system manager.
317 * @status: zero = success, others fail.
318 *
319 * The guest sends this message to the system manager to acnowledge success or
320 * failure of a command sent by the system manager.
321 */
322
323static int ps3_sys_manager_send_response(struct ps3_vuart_port_device *dev,
324 u64 status)
325{
326 static const struct ps3_sys_manager_header header = {
327 .version = 1,
328 .size = 16,
329 .payload_size = 16,
330 .service_id = PS3_SM_SERVICE_ID_RESPONSE,
331 };
332 struct {
333 u8 version;
334 u8 reserved_1[3];
335 u8 status;
336 u8 reserved_2[11];
337 } payload;
338
339 BUILD_BUG_ON(sizeof(payload) != 16);
340
341 dev_dbg(&dev->core, "%s:%d: (%s)\n", __func__, __LINE__,
342 (status ? "nak" : "ack"));
343
344 memset(&payload, 0, sizeof(payload));
345 payload.version = 1;
346 payload.status = status;
347
348 return ps3_sys_manager_write(dev, &header, &payload);
349}
350
351/**
352 * ps3_sys_manager_handle_event - Second stage event msg handler.
353 *
354 */
355
356static int ps3_sys_manager_handle_event(struct ps3_vuart_port_device *dev)
357{
358 int result;
359 struct {
360 u8 version;
361 u8 type;
362 u8 reserved_1[2];
363 u32 value;
364 u8 reserved_2[8];
365 } event;
366
367 BUILD_BUG_ON(sizeof(event) != 16);
368
369 result = ps3_vuart_read(dev, &event, sizeof(event));
370 BUG_ON(result);
371
372 if (event.version != 1) {
373 dev_dbg(&dev->core, "%s:%d: unsupported event version (%u)\n",
374 __func__, __LINE__, event.version);
375 return -EIO;
376 }
377
378 switch (event.type) {
379 case PS3_SM_EVENT_POWER_PRESSED:
380 dev_dbg(&dev->core, "%s:%d: POWER_PRESSED\n",
381 __func__, __LINE__);
382 break;
383 case PS3_SM_EVENT_POWER_RELEASED:
384 dev_dbg(&dev->core, "%s:%d: POWER_RELEASED (%u ms)\n",
385 __func__, __LINE__, event.value);
386 kill_cad_pid(SIGINT, 1);
387 break;
388 case PS3_SM_EVENT_THERMAL_ALERT:
389 dev_dbg(&dev->core, "%s:%d: THERMAL_ALERT (zone %u)\n",
390 __func__, __LINE__, event.value);
391 printk(KERN_INFO "PS3 Thermal Alert Zone %u\n", event.value);
392 break;
393 case PS3_SM_EVENT_THERMAL_CLEARED:
394 dev_dbg(&dev->core, "%s:%d: THERMAL_CLEARED (zone %u)\n",
395 __func__, __LINE__, event.value);
396 break;
397 default:
398 dev_dbg(&dev->core, "%s:%d: unknown event (%u)\n",
399 __func__, __LINE__, event.type);
400 return -EIO;
401 }
402
403 return 0;
404}
405/**
406 * ps3_sys_manager_handle_cmd - Second stage command msg handler.
407 *
408 * The system manager sends this in reply to a 'request' message from the guest.
409 */
410
411static int ps3_sys_manager_handle_cmd(struct ps3_vuart_port_device *dev)
412{
413 int result;
414 struct {
415 u8 version;
416 u8 type;
417 u8 reserved_1[14];
418 } cmd;
419
420 BUILD_BUG_ON(sizeof(cmd) != 16);
421
422 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
423
424 result = ps3_vuart_read(dev, &cmd, sizeof(cmd));
425
426 if(result)
427 return result;
428
429 if (cmd.version != 1) {
430 dev_dbg(&dev->core, "%s:%d: unsupported cmd version (%u)\n",
431 __func__, __LINE__, cmd.version);
432 return -EIO;
433 }
434
435 if (cmd.type != PS3_SM_CMD_SHUTDOWN) {
436 dev_dbg(&dev->core, "%s:%d: unknown cmd (%u)\n",
437 __func__, __LINE__, cmd.type);
438 return -EIO;
439 }
440
441 ps3_sys_manager_send_response(dev, 0);
442 return 0;
443}
444
445/**
446 * ps3_sys_manager_handle_msg - First stage msg handler.
447 *
448 */
449
450static int ps3_sys_manager_handle_msg(struct ps3_vuart_port_device *dev)
451{
452 int result;
453 struct ps3_sys_manager_header header;
454
455 result = ps3_vuart_read(dev, &header,
456 sizeof(struct ps3_sys_manager_header));
457
458 if(result)
459 return result;
460
461 if (header.version != 1) {
462 dev_dbg(&dev->core, "%s:%d: unsupported header version (%u)\n",
463 __func__, __LINE__, header.version);
464 goto fail_header;
465 }
466
467 BUILD_BUG_ON(sizeof(header) != 16);
468 BUG_ON(header.size != 16);
469 BUG_ON(header.payload_size != 16);
470
471 switch (header.service_id) {
472 case PS3_SM_SERVICE_ID_EXTERN_EVENT:
473 dev_dbg(&dev->core, "%s:%d: EVENT\n", __func__, __LINE__);
474 return ps3_sys_manager_handle_event(dev);
475 case PS3_SM_SERVICE_ID_COMMAND:
476 dev_dbg(&dev->core, "%s:%d: COMMAND\n", __func__, __LINE__);
477 return ps3_sys_manager_handle_cmd(dev);
478 default:
479 dev_dbg(&dev->core, "%s:%d: unknown service_id (%u)\n",
480 __func__, __LINE__, header.service_id);
481 break;
482 }
483 goto fail_id;
484
485fail_header:
486 ps3_vuart_clear_rx_bytes(dev, 0);
487 return -EIO;
488fail_id:
489 ps3_vuart_clear_rx_bytes(dev, header.payload_size);
490 return -EIO;
491}
492
493/**
494 * ps3_sys_manager_work - Asyncronous read handler.
495 *
496 * Signaled when a complete message arrives at the vuart port.
497 */
498
499static void ps3_sys_manager_work(struct work_struct *work)
500{
501 struct ps3_vuart_port_device *dev = ps3_vuart_work_to_port_device(work);
502
503 ps3_sys_manager_handle_msg(dev);
504 ps3_vuart_read_async(dev, ps3_sys_manager_work, PS3_SM_RX_MSG_LEN);
505}
506
507struct {
508 struct ps3_vuart_port_device *dev;
509} static drv_priv;
510
511/**
512 * ps3_sys_manager_restart - The final platform machine_restart routine.
513 *
514 * This routine never returns. The routine disables asyncronous vuart reads
515 * then spins calling ps3_sys_manager_handle_msg() to receive and acknowledge
516 * the shutdown command sent from the system manager. Soon after the
517 * acknowledgement is sent the lpar is destroyed by the HV. This routine
518 * should only be called from ps3_restart().
519 */
520
521void ps3_sys_manager_restart(void)
522{
523 struct ps3_vuart_port_device *dev = drv_priv.dev;
524
525 BUG_ON(!drv_priv.dev);
526
527 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
528
529 ps3_vuart_cancel_async(dev);
530
531 ps3_sys_manager_send_attr(dev, 0);
532 ps3_sys_manager_send_next_op(dev, PS3_SM_NEXT_OP_LPAR_REBOOT,
533 PS3_SM_WAKE_DEFAULT);
534 ps3_sys_manager_send_request_shutdown(dev);
535
536 printk(KERN_EMERG "System Halted, OK to turn off power\n");
537
538 while(1)
539 ps3_sys_manager_handle_msg(dev);
540}
541
542/**
543 * ps3_sys_manager_power_off - The final platform machine_power_off routine.
544 *
545 * This routine never returns. The routine disables asyncronous vuart reads
546 * then spins calling ps3_sys_manager_handle_msg() to receive and acknowledge
547 * the shutdown command sent from the system manager. Soon after the
548 * acknowledgement is sent the lpar is destroyed by the HV. This routine
549 * should only be called from ps3_power_off().
550 */
551
552void ps3_sys_manager_power_off(void)
553{
554 struct ps3_vuart_port_device *dev = drv_priv.dev;
555
556 BUG_ON(!drv_priv.dev);
557
558 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
559
560 ps3_vuart_cancel_async(dev);
561
562 ps3_sys_manager_send_next_op(dev, PS3_SM_NEXT_OP_SYS_SHUTDOWN,
563 PS3_SM_WAKE_DEFAULT);
564 ps3_sys_manager_send_request_shutdown(dev);
565
566 printk(KERN_EMERG "System Halted, OK to turn off power\n");
567
568 while(1)
569 ps3_sys_manager_handle_msg(dev);
570}
571
572static int ps3_sys_manager_probe(struct ps3_vuart_port_device *dev)
573{
574 int result;
575
576 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
577
578 BUG_ON(drv_priv.dev);
579 drv_priv.dev = dev;
580
581 result = ps3_sys_manager_send_attr(dev, PS3_SM_ATTR_ALL);
582 BUG_ON(result);
583
584 result = ps3_vuart_read_async(dev, ps3_sys_manager_work,
585 PS3_SM_RX_MSG_LEN);
586 BUG_ON(result);
587
588 return result;
589}
590
591static struct ps3_vuart_port_driver ps3_sys_manager = {
592 .match_id = PS3_MATCH_ID_SYSTEM_MANAGER,
593 .core = {
594 .name = "ps3_sys_manager",
595 },
596 .probe = ps3_sys_manager_probe,
597};
598
599static int __init ps3_sys_manager_init(void)
600{
601 return ps3_vuart_port_driver_register(&ps3_sys_manager);
602}
603
604module_init(ps3_sys_manager_init);
diff --git a/drivers/ps3/vuart.c b/drivers/ps3/vuart.c
index ef8fd4c308..746298107d 100644
--- a/drivers/ps3/vuart.c
+++ b/drivers/ps3/vuart.c
@@ -21,8 +21,10 @@
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/workqueue.h>
24#include <asm/ps3.h> 25#include <asm/ps3.h>
25 26
27#include <asm/firmware.h>
26#include <asm/lv1call.h> 28#include <asm/lv1call.h>
27#include <asm/bitops.h> 29#include <asm/bitops.h>
28 30
@@ -30,7 +32,7 @@
30 32
31MODULE_AUTHOR("Sony Corporation"); 33MODULE_AUTHOR("Sony Corporation");
32MODULE_LICENSE("GPL v2"); 34MODULE_LICENSE("GPL v2");
33MODULE_DESCRIPTION("ps3 vuart"); 35MODULE_DESCRIPTION("PS3 vuart");
34 36
35/** 37/**
36 * vuart - An inter-partition data link service. 38 * vuart - An inter-partition data link service.
@@ -157,7 +159,7 @@ int ps3_vuart_get_triggers(struct ps3_vuart_port_device *dev,
157 unsigned long size; 159 unsigned long size;
158 unsigned long val; 160 unsigned long val;
159 161
160 result = lv1_get_virtual_uart_param(dev->port_number, 162 result = lv1_get_virtual_uart_param(dev->priv->port_number,
161 PARAM_TX_TRIGGER, &trig->tx); 163 PARAM_TX_TRIGGER, &trig->tx);
162 164
163 if (result) { 165 if (result) {
@@ -166,7 +168,7 @@ int ps3_vuart_get_triggers(struct ps3_vuart_port_device *dev,
166 return result; 168 return result;
167 } 169 }
168 170
169 result = lv1_get_virtual_uart_param(dev->port_number, 171 result = lv1_get_virtual_uart_param(dev->priv->port_number,
170 PARAM_RX_BUF_SIZE, &size); 172 PARAM_RX_BUF_SIZE, &size);
171 173
172 if (result) { 174 if (result) {
@@ -175,7 +177,7 @@ int ps3_vuart_get_triggers(struct ps3_vuart_port_device *dev,
175 return result; 177 return result;
176 } 178 }
177 179
178 result = lv1_get_virtual_uart_param(dev->port_number, 180 result = lv1_get_virtual_uart_param(dev->priv->port_number,
179 PARAM_RX_TRIGGER, &val); 181 PARAM_RX_TRIGGER, &val);
180 182
181 if (result) { 183 if (result) {
@@ -198,7 +200,7 @@ int ps3_vuart_set_triggers(struct ps3_vuart_port_device *dev, unsigned int tx,
198 int result; 200 int result;
199 unsigned long size; 201 unsigned long size;
200 202
201 result = lv1_set_virtual_uart_param(dev->port_number, 203 result = lv1_set_virtual_uart_param(dev->priv->port_number,
202 PARAM_TX_TRIGGER, tx); 204 PARAM_TX_TRIGGER, tx);
203 205
204 if (result) { 206 if (result) {
@@ -207,7 +209,7 @@ int ps3_vuart_set_triggers(struct ps3_vuart_port_device *dev, unsigned int tx,
207 return result; 209 return result;
208 } 210 }
209 211
210 result = lv1_get_virtual_uart_param(dev->port_number, 212 result = lv1_get_virtual_uart_param(dev->priv->port_number,
211 PARAM_RX_BUF_SIZE, &size); 213 PARAM_RX_BUF_SIZE, &size);
212 214
213 if (result) { 215 if (result) {
@@ -216,7 +218,7 @@ int ps3_vuart_set_triggers(struct ps3_vuart_port_device *dev, unsigned int tx,
216 return result; 218 return result;
217 } 219 }
218 220
219 result = lv1_set_virtual_uart_param(dev->port_number, 221 result = lv1_set_virtual_uart_param(dev->priv->port_number,
220 PARAM_RX_TRIGGER, size - rx); 222 PARAM_RX_TRIGGER, size - rx);
221 223
222 if (result) { 224 if (result) {
@@ -232,9 +234,9 @@ int ps3_vuart_set_triggers(struct ps3_vuart_port_device *dev, unsigned int tx,
232} 234}
233 235
234static int ps3_vuart_get_rx_bytes_waiting(struct ps3_vuart_port_device *dev, 236static int ps3_vuart_get_rx_bytes_waiting(struct ps3_vuart_port_device *dev,
235 unsigned long *bytes_waiting) 237 u64 *bytes_waiting)
236{ 238{
237 int result = lv1_get_virtual_uart_param(dev->port_number, 239 int result = lv1_get_virtual_uart_param(dev->priv->port_number,
238 PARAM_RX_BYTES, bytes_waiting); 240 PARAM_RX_BYTES, bytes_waiting);
239 241
240 if (result) 242 if (result)
@@ -253,10 +255,10 @@ static int ps3_vuart_set_interrupt_mask(struct ps3_vuart_port_device *dev,
253 255
254 dev_dbg(&dev->core, "%s:%d: %lxh\n", __func__, __LINE__, mask); 256 dev_dbg(&dev->core, "%s:%d: %lxh\n", __func__, __LINE__, mask);
255 257
256 dev->interrupt_mask = mask; 258 dev->priv->interrupt_mask = mask;
257 259
258 result = lv1_set_virtual_uart_param(dev->port_number, 260 result = lv1_set_virtual_uart_param(dev->priv->port_number,
259 PARAM_INTERRUPT_MASK, dev->interrupt_mask); 261 PARAM_INTERRUPT_MASK, dev->priv->interrupt_mask);
260 262
261 if (result) 263 if (result)
262 dev_dbg(&dev->core, "%s:%d: interrupt_mask failed: %s\n", 264 dev_dbg(&dev->core, "%s:%d: interrupt_mask failed: %s\n",
@@ -265,62 +267,64 @@ static int ps3_vuart_set_interrupt_mask(struct ps3_vuart_port_device *dev,
265 return result; 267 return result;
266} 268}
267 269
268static int ps3_vuart_get_interrupt_mask(struct ps3_vuart_port_device *dev, 270static int ps3_vuart_get_interrupt_status(struct ps3_vuart_port_device *dev,
269 unsigned long *status) 271 unsigned long *status)
270{ 272{
271 int result = lv1_get_virtual_uart_param(dev->port_number, 273 u64 tmp;
272 PARAM_INTERRUPT_STATUS, status); 274 int result = lv1_get_virtual_uart_param(dev->priv->port_number,
275 PARAM_INTERRUPT_STATUS, &tmp);
273 276
274 if (result) 277 if (result)
275 dev_dbg(&dev->core, "%s:%d: interrupt_status failed: %s\n", 278 dev_dbg(&dev->core, "%s:%d: interrupt_status failed: %s\n",
276 __func__, __LINE__, ps3_result(result)); 279 __func__, __LINE__, ps3_result(result));
277 280
281 *status = tmp & dev->priv->interrupt_mask;
282
278 dev_dbg(&dev->core, "%s:%d: m %lxh, s %lxh, m&s %lxh\n", 283 dev_dbg(&dev->core, "%s:%d: m %lxh, s %lxh, m&s %lxh\n",
279 __func__, __LINE__, dev->interrupt_mask, *status, 284 __func__, __LINE__, dev->priv->interrupt_mask, tmp, *status);
280 dev->interrupt_mask & *status);
281 285
282 return result; 286 return result;
283} 287}
284 288
285int ps3_vuart_enable_interrupt_tx(struct ps3_vuart_port_device *dev) 289int ps3_vuart_enable_interrupt_tx(struct ps3_vuart_port_device *dev)
286{ 290{
287 return (dev->interrupt_mask & INTERRUPT_MASK_TX) ? 0 291 return (dev->priv->interrupt_mask & INTERRUPT_MASK_TX) ? 0
288 : ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask 292 : ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
289 | INTERRUPT_MASK_TX); 293 | INTERRUPT_MASK_TX);
290} 294}
291 295
292int ps3_vuart_enable_interrupt_rx(struct ps3_vuart_port_device *dev) 296int ps3_vuart_enable_interrupt_rx(struct ps3_vuart_port_device *dev)
293{ 297{
294 return (dev->interrupt_mask & INTERRUPT_MASK_RX) ? 0 298 return (dev->priv->interrupt_mask & INTERRUPT_MASK_RX) ? 0
295 : ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask 299 : ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
296 | INTERRUPT_MASK_RX); 300 | INTERRUPT_MASK_RX);
297} 301}
298 302
299int ps3_vuart_enable_interrupt_disconnect(struct ps3_vuart_port_device *dev) 303int ps3_vuart_enable_interrupt_disconnect(struct ps3_vuart_port_device *dev)
300{ 304{
301 return (dev->interrupt_mask & INTERRUPT_MASK_DISCONNECT) ? 0 305 return (dev->priv->interrupt_mask & INTERRUPT_MASK_DISCONNECT) ? 0
302 : ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask 306 : ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
303 | INTERRUPT_MASK_DISCONNECT); 307 | INTERRUPT_MASK_DISCONNECT);
304} 308}
305 309
306int ps3_vuart_disable_interrupt_tx(struct ps3_vuart_port_device *dev) 310int ps3_vuart_disable_interrupt_tx(struct ps3_vuart_port_device *dev)
307{ 311{
308 return (dev->interrupt_mask & INTERRUPT_MASK_TX) 312 return (dev->priv->interrupt_mask & INTERRUPT_MASK_TX)
309 ? ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask 313 ? ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
310 & ~INTERRUPT_MASK_TX) : 0; 314 & ~INTERRUPT_MASK_TX) : 0;
311} 315}
312 316
313int ps3_vuart_disable_interrupt_rx(struct ps3_vuart_port_device *dev) 317int ps3_vuart_disable_interrupt_rx(struct ps3_vuart_port_device *dev)
314{ 318{
315 return (dev->interrupt_mask & INTERRUPT_MASK_RX) 319 return (dev->priv->interrupt_mask & INTERRUPT_MASK_RX)
316 ? ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask 320 ? ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
317 & ~INTERRUPT_MASK_RX) : 0; 321 & ~INTERRUPT_MASK_RX) : 0;
318} 322}
319 323
320int ps3_vuart_disable_interrupt_disconnect(struct ps3_vuart_port_device *dev) 324int ps3_vuart_disable_interrupt_disconnect(struct ps3_vuart_port_device *dev)
321{ 325{
322 return (dev->interrupt_mask & INTERRUPT_MASK_DISCONNECT) 326 return (dev->priv->interrupt_mask & INTERRUPT_MASK_DISCONNECT)
323 ? ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask 327 ? ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
324 & ~INTERRUPT_MASK_DISCONNECT) : 0; 328 & ~INTERRUPT_MASK_DISCONNECT) : 0;
325} 329}
326 330
@@ -335,9 +339,7 @@ static int ps3_vuart_raw_write(struct ps3_vuart_port_device *dev,
335{ 339{
336 int result; 340 int result;
337 341
338 dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, bytes); 342 result = lv1_write_virtual_uart(dev->priv->port_number,
339
340 result = lv1_write_virtual_uart(dev->port_number,
341 ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_written); 343 ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_written);
342 344
343 if (result) { 345 if (result) {
@@ -346,10 +348,10 @@ static int ps3_vuart_raw_write(struct ps3_vuart_port_device *dev,
346 return result; 348 return result;
347 } 349 }
348 350
349 dev->stats.bytes_written += *bytes_written; 351 dev->priv->stats.bytes_written += *bytes_written;
350 352
351 dev_dbg(&dev->core, "%s:%d: wrote %lxh/%xh=>%lxh\n", __func__, 353 dev_dbg(&dev->core, "%s:%d: wrote %lxh/%xh=>%lxh\n", __func__, __LINE__,
352 __LINE__, *bytes_written, bytes, dev->stats.bytes_written); 354 *bytes_written, bytes, dev->priv->stats.bytes_written);
353 355
354 return result; 356 return result;
355} 357}
@@ -367,7 +369,7 @@ static int ps3_vuart_raw_read(struct ps3_vuart_port_device *dev, void* buf,
367 369
368 dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, bytes); 370 dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, bytes);
369 371
370 result = lv1_read_virtual_uart(dev->port_number, 372 result = lv1_read_virtual_uart(dev->priv->port_number,
371 ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_read); 373 ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_read);
372 374
373 if (result) { 375 if (result) {
@@ -376,15 +378,58 @@ static int ps3_vuart_raw_read(struct ps3_vuart_port_device *dev, void* buf,
376 return result; 378 return result;
377 } 379 }
378 380
379 dev->stats.bytes_read += *bytes_read; 381 dev->priv->stats.bytes_read += *bytes_read;
380 382
381 dev_dbg(&dev->core, "%s:%d: read %lxh/%xh=>%lxh\n", __func__, __LINE__, 383 dev_dbg(&dev->core, "%s:%d: read %lxh/%xh=>%lxh\n", __func__, __LINE__,
382 *bytes_read, bytes, dev->stats.bytes_read); 384 *bytes_read, bytes, dev->priv->stats.bytes_read);
383 385
384 return result; 386 return result;
385} 387}
386 388
387/** 389/**
390 * ps3_vuart_clear_rx_bytes - Discard bytes received.
391 * @bytes: Max byte count to discard, zero = all pending.
392 *
393 * Used to clear pending rx interrupt source. Will not block.
394 */
395
396void ps3_vuart_clear_rx_bytes(struct ps3_vuart_port_device *dev,
397 unsigned int bytes)
398{
399 int result;
400 u64 bytes_waiting;
401 void* tmp;
402
403 result = ps3_vuart_get_rx_bytes_waiting(dev, &bytes_waiting);
404
405 BUG_ON(result);
406
407 bytes = bytes ? min(bytes, (unsigned int)bytes_waiting) : bytes_waiting;
408
409 dev_dbg(&dev->core, "%s:%d: %u\n", __func__, __LINE__, bytes);
410
411 if (!bytes)
412 return;
413
414 /* Add some extra space for recently arrived data. */
415
416 bytes += 128;
417
418 tmp = kmalloc(bytes, GFP_KERNEL);
419
420 if (!tmp)
421 return;
422
423 ps3_vuart_raw_read(dev, tmp, bytes, &bytes_waiting);
424
425 kfree(tmp);
426
427 /* Don't include these bytes in the stats. */
428
429 dev->priv->stats.bytes_read -= bytes_waiting;
430}
431
432/**
388 * struct list_buffer - An element for a port device fifo buffer list. 433 * struct list_buffer - An element for a port device fifo buffer list.
389 */ 434 */
390 435
@@ -416,14 +461,14 @@ int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf,
416 dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__, 461 dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__,
417 bytes, bytes); 462 bytes, bytes);
418 463
419 spin_lock_irqsave(&dev->tx_list.lock, flags); 464 spin_lock_irqsave(&dev->priv->tx_list.lock, flags);
420 465
421 if (list_empty(&dev->tx_list.head)) { 466 if (list_empty(&dev->priv->tx_list.head)) {
422 unsigned long bytes_written; 467 unsigned long bytes_written;
423 468
424 result = ps3_vuart_raw_write(dev, buf, bytes, &bytes_written); 469 result = ps3_vuart_raw_write(dev, buf, bytes, &bytes_written);
425 470
426 spin_unlock_irqrestore(&dev->tx_list.lock, flags); 471 spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
427 472
428 if (result) { 473 if (result) {
429 dev_dbg(&dev->core, 474 dev_dbg(&dev->core,
@@ -441,7 +486,7 @@ int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf,
441 bytes -= bytes_written; 486 bytes -= bytes_written;
442 buf += bytes_written; 487 buf += bytes_written;
443 } else 488 } else
444 spin_unlock_irqrestore(&dev->tx_list.lock, flags); 489 spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
445 490
446 lb = kmalloc(sizeof(struct list_buffer) + bytes, GFP_KERNEL); 491 lb = kmalloc(sizeof(struct list_buffer) + bytes, GFP_KERNEL);
447 492
@@ -454,10 +499,10 @@ int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf,
454 lb->tail = lb->data + bytes; 499 lb->tail = lb->data + bytes;
455 lb->dbg_number = ++dbg_number; 500 lb->dbg_number = ++dbg_number;
456 501
457 spin_lock_irqsave(&dev->tx_list.lock, flags); 502 spin_lock_irqsave(&dev->priv->tx_list.lock, flags);
458 list_add_tail(&lb->link, &dev->tx_list.head); 503 list_add_tail(&lb->link, &dev->priv->tx_list.head);
459 ps3_vuart_enable_interrupt_tx(dev); 504 ps3_vuart_enable_interrupt_tx(dev);
460 spin_unlock_irqrestore(&dev->tx_list.lock, flags); 505 spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
461 506
462 dev_dbg(&dev->core, "%s:%d: queued buf_%lu, %xh bytes\n", 507 dev_dbg(&dev->core, "%s:%d: queued buf_%lu, %xh bytes\n",
463 __func__, __LINE__, lb->dbg_number, bytes); 508 __func__, __LINE__, lb->dbg_number, bytes);
@@ -484,47 +529,83 @@ int ps3_vuart_read(struct ps3_vuart_port_device *dev, void* buf,
484 dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__, 529 dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__,
485 bytes, bytes); 530 bytes, bytes);
486 531
487 spin_lock_irqsave(&dev->rx_list.lock, flags); 532 spin_lock_irqsave(&dev->priv->rx_list.lock, flags);
488 533
489 if (dev->rx_list.bytes_held < bytes) { 534 if (dev->priv->rx_list.bytes_held < bytes) {
490 spin_unlock_irqrestore(&dev->rx_list.lock, flags); 535 spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
491 dev_dbg(&dev->core, "%s:%d: starved for %lxh bytes\n", 536 dev_dbg(&dev->core, "%s:%d: starved for %lxh bytes\n",
492 __func__, __LINE__, bytes - dev->rx_list.bytes_held); 537 __func__, __LINE__,
538 bytes - dev->priv->rx_list.bytes_held);
493 return -EAGAIN; 539 return -EAGAIN;
494 } 540 }
495 541
496 list_for_each_entry_safe(lb, n, &dev->rx_list.head, link) { 542 list_for_each_entry_safe(lb, n, &dev->priv->rx_list.head, link) {
497 bytes_read = min((unsigned int)(lb->tail - lb->head), bytes); 543 bytes_read = min((unsigned int)(lb->tail - lb->head), bytes);
498 544
499 memcpy(buf, lb->head, bytes_read); 545 memcpy(buf, lb->head, bytes_read);
500 buf += bytes_read; 546 buf += bytes_read;
501 bytes -= bytes_read; 547 bytes -= bytes_read;
502 dev->rx_list.bytes_held -= bytes_read; 548 dev->priv->rx_list.bytes_held -= bytes_read;
503 549
504 if (bytes_read < lb->tail - lb->head) { 550 if (bytes_read < lb->tail - lb->head) {
505 lb->head += bytes_read; 551 lb->head += bytes_read;
506 spin_unlock_irqrestore(&dev->rx_list.lock, flags); 552 dev_dbg(&dev->core, "%s:%d: buf_%lu: dequeued %lxh "
507 553 "bytes\n", __func__, __LINE__, lb->dbg_number,
508 dev_dbg(&dev->core, 554 bytes_read);
509 "%s:%d: dequeued buf_%lu, %lxh bytes\n", 555 spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
510 __func__, __LINE__, lb->dbg_number, bytes_read);
511 return 0; 556 return 0;
512 } 557 }
513 558
514 dev_dbg(&dev->core, "%s:%d free buf_%lu\n", __func__, __LINE__, 559 dev_dbg(&dev->core, "%s:%d: buf_%lu: free, dequeued %lxh "
515 lb->dbg_number); 560 "bytes\n", __func__, __LINE__, lb->dbg_number,
561 bytes_read);
516 562
517 list_del(&lb->link); 563 list_del(&lb->link);
518 kfree(lb); 564 kfree(lb);
519 } 565 }
520 spin_unlock_irqrestore(&dev->rx_list.lock, flags);
521 566
522 dev_dbg(&dev->core, "%s:%d: dequeued buf_%lu, %xh bytes\n", 567 spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
523 __func__, __LINE__, lb->dbg_number, bytes); 568 return 0;
569}
570
571int ps3_vuart_read_async(struct ps3_vuart_port_device *dev, work_func_t func,
572 unsigned int bytes)
573{
574 unsigned long flags;
575
576 if(dev->priv->work.trigger) {
577 dev_dbg(&dev->core, "%s:%d: warning, multiple calls\n",
578 __func__, __LINE__);
579 return -EAGAIN;
580 }
581
582 BUG_ON(!bytes);
583
584 PREPARE_WORK(&dev->priv->work.work, func);
585
586 spin_lock_irqsave(&dev->priv->work.lock, flags);
587 if(dev->priv->rx_list.bytes_held >= bytes) {
588 dev_dbg(&dev->core, "%s:%d: schedule_work %xh bytes\n",
589 __func__, __LINE__, bytes);
590 schedule_work(&dev->priv->work.work);
591 spin_unlock_irqrestore(&dev->priv->work.lock, flags);
592 return 0;
593 }
594
595 dev->priv->work.trigger = bytes;
596 spin_unlock_irqrestore(&dev->priv->work.lock, flags);
597
598 dev_dbg(&dev->core, "%s:%d: waiting for %u(%xh) bytes\n", __func__,
599 __LINE__, bytes, bytes);
524 600
525 return 0; 601 return 0;
526} 602}
527 603
604void ps3_vuart_cancel_async(struct ps3_vuart_port_device *dev)
605{
606 dev->priv->work.trigger = 0;
607}
608
528/** 609/**
529 * ps3_vuart_handle_interrupt_tx - third stage transmit interrupt handler 610 * ps3_vuart_handle_interrupt_tx - third stage transmit interrupt handler
530 * 611 *
@@ -542,9 +623,9 @@ static int ps3_vuart_handle_interrupt_tx(struct ps3_vuart_port_device *dev)
542 623
543 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__); 624 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
544 625
545 spin_lock_irqsave(&dev->tx_list.lock, flags); 626 spin_lock_irqsave(&dev->priv->tx_list.lock, flags);
546 627
547 list_for_each_entry_safe(lb, n, &dev->tx_list.head, link) { 628 list_for_each_entry_safe(lb, n, &dev->priv->tx_list.head, link) {
548 629
549 unsigned long bytes_written; 630 unsigned long bytes_written;
550 631
@@ -578,7 +659,7 @@ static int ps3_vuart_handle_interrupt_tx(struct ps3_vuart_port_device *dev)
578 659
579 ps3_vuart_disable_interrupt_tx(dev); 660 ps3_vuart_disable_interrupt_tx(dev);
580port_full: 661port_full:
581 spin_unlock_irqrestore(&dev->tx_list.lock, flags); 662 spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
582 dev_dbg(&dev->core, "%s:%d wrote %lxh bytes total\n", 663 dev_dbg(&dev->core, "%s:%d wrote %lxh bytes total\n",
583 __func__, __LINE__, bytes_total); 664 __func__, __LINE__, bytes_total);
584 return result; 665 return result;
@@ -609,7 +690,7 @@ static int ps3_vuart_handle_interrupt_rx(struct ps3_vuart_port_device *dev)
609 690
610 BUG_ON(!bytes); 691 BUG_ON(!bytes);
611 692
612 /* add some extra space for recently arrived data */ 693 /* Add some extra space for recently arrived data. */
613 694
614 bytes += 128; 695 bytes += 128;
615 696
@@ -624,14 +705,23 @@ static int ps3_vuart_handle_interrupt_rx(struct ps3_vuart_port_device *dev)
624 lb->tail = lb->data + bytes; 705 lb->tail = lb->data + bytes;
625 lb->dbg_number = ++dbg_number; 706 lb->dbg_number = ++dbg_number;
626 707
627 spin_lock_irqsave(&dev->rx_list.lock, flags); 708 spin_lock_irqsave(&dev->priv->rx_list.lock, flags);
628 list_add_tail(&lb->link, &dev->rx_list.head); 709 list_add_tail(&lb->link, &dev->priv->rx_list.head);
629 dev->rx_list.bytes_held += bytes; 710 dev->priv->rx_list.bytes_held += bytes;
630 spin_unlock_irqrestore(&dev->rx_list.lock, flags); 711 spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
631 712
632 dev_dbg(&dev->core, "%s:%d: queued buf_%lu, %lxh bytes\n", 713 dev_dbg(&dev->core, "%s:%d: buf_%lu: queued %lxh bytes\n",
633 __func__, __LINE__, lb->dbg_number, bytes); 714 __func__, __LINE__, lb->dbg_number, bytes);
634 715
716 spin_lock_irqsave(&dev->priv->work.lock, flags);
717 if(dev->priv->work.trigger
718 && dev->priv->rx_list.bytes_held >= dev->priv->work.trigger) {
719 dev_dbg(&dev->core, "%s:%d: schedule_work %lxh bytes\n",
720 __func__, __LINE__, dev->priv->work.trigger);
721 dev->priv->work.trigger = 0;
722 schedule_work(&dev->priv->work.work);
723 }
724 spin_unlock_irqrestore(&dev->priv->work.lock, flags);
635 return 0; 725 return 0;
636} 726}
637 727
@@ -656,7 +746,7 @@ static int ps3_vuart_handle_port_interrupt(struct ps3_vuart_port_device *dev)
656 int result; 746 int result;
657 unsigned long status; 747 unsigned long status;
658 748
659 result = ps3_vuart_get_interrupt_mask(dev, &status); 749 result = ps3_vuart_get_interrupt_status(dev, &status);
660 750
661 if (result) 751 if (result)
662 return result; 752 return result;
@@ -665,21 +755,21 @@ static int ps3_vuart_handle_port_interrupt(struct ps3_vuart_port_device *dev)
665 status); 755 status);
666 756
667 if (status & INTERRUPT_MASK_DISCONNECT) { 757 if (status & INTERRUPT_MASK_DISCONNECT) {
668 dev->stats.disconnect_interrupts++; 758 dev->priv->stats.disconnect_interrupts++;
669 result = ps3_vuart_handle_interrupt_disconnect(dev); 759 result = ps3_vuart_handle_interrupt_disconnect(dev);
670 if (result) 760 if (result)
671 ps3_vuart_disable_interrupt_disconnect(dev); 761 ps3_vuart_disable_interrupt_disconnect(dev);
672 } 762 }
673 763
674 if (status & INTERRUPT_MASK_TX) { 764 if (status & INTERRUPT_MASK_TX) {
675 dev->stats.tx_interrupts++; 765 dev->priv->stats.tx_interrupts++;
676 result = ps3_vuart_handle_interrupt_tx(dev); 766 result = ps3_vuart_handle_interrupt_tx(dev);
677 if (result) 767 if (result)
678 ps3_vuart_disable_interrupt_tx(dev); 768 ps3_vuart_disable_interrupt_tx(dev);
679 } 769 }
680 770
681 if (status & INTERRUPT_MASK_RX) { 771 if (status & INTERRUPT_MASK_RX) {
682 dev->stats.rx_interrupts++; 772 dev->priv->stats.rx_interrupts++;
683 result = ps3_vuart_handle_interrupt_rx(dev); 773 result = ps3_vuart_handle_interrupt_rx(dev);
684 if (result) 774 if (result)
685 ps3_vuart_disable_interrupt_rx(dev); 775 ps3_vuart_disable_interrupt_rx(dev);
@@ -688,12 +778,13 @@ static int ps3_vuart_handle_port_interrupt(struct ps3_vuart_port_device *dev)
688 return 0; 778 return 0;
689} 779}
690 780
691struct vuart_private { 781struct vuart_bus_priv {
692 unsigned int in_use; 782 const struct ports_bmp bmp;
693 unsigned int virq; 783 unsigned int virq;
784 struct semaphore probe_mutex;
785 int use_count;
694 struct ps3_vuart_port_device *devices[PORT_COUNT]; 786 struct ps3_vuart_port_device *devices[PORT_COUNT];
695 const struct ports_bmp bmp; 787} static vuart_bus_priv;
696};
697 788
698/** 789/**
699 * ps3_vuart_irq_handler - first stage interrupt handler 790 * ps3_vuart_irq_handler - first stage interrupt handler
@@ -705,25 +796,25 @@ struct vuart_private {
705 796
706static irqreturn_t ps3_vuart_irq_handler(int irq, void *_private) 797static irqreturn_t ps3_vuart_irq_handler(int irq, void *_private)
707{ 798{
708 struct vuart_private *private; 799 struct vuart_bus_priv *bus_priv;
709 800
710 BUG_ON(!_private); 801 BUG_ON(!_private);
711 private = (struct vuart_private *)_private; 802 bus_priv = (struct vuart_bus_priv *)_private;
712 803
713 while (1) { 804 while (1) {
714 unsigned int port; 805 unsigned int port;
715 806
716 dump_ports_bmp(&private->bmp); 807 dump_ports_bmp(&bus_priv->bmp);
717 808
718 port = (BITS_PER_LONG - 1) - __ilog2(private->bmp.status); 809 port = (BITS_PER_LONG - 1) - __ilog2(bus_priv->bmp.status);
719 810
720 if (port == BITS_PER_LONG) 811 if (port == BITS_PER_LONG)
721 break; 812 break;
722 813
723 BUG_ON(port >= PORT_COUNT); 814 BUG_ON(port >= PORT_COUNT);
724 BUG_ON(!private->devices[port]); 815 BUG_ON(!bus_priv->devices[port]);
725 816
726 ps3_vuart_handle_port_interrupt(private->devices[port]); 817 ps3_vuart_handle_port_interrupt(bus_priv->devices[port]);
727 } 818 }
728 819
729 return IRQ_HANDLED; 820 return IRQ_HANDLED;
@@ -744,12 +835,10 @@ static int ps3_vuart_match(struct device *_dev, struct device_driver *_drv)
744 return result; 835 return result;
745} 836}
746 837
747static struct vuart_private vuart_private;
748
749static int ps3_vuart_probe(struct device *_dev) 838static int ps3_vuart_probe(struct device *_dev)
750{ 839{
751 int result; 840 int result;
752 unsigned long tmp; 841 unsigned int port_number;
753 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev); 842 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
754 struct ps3_vuart_port_driver *drv = 843 struct ps3_vuart_port_driver *drv =
755 to_ps3_vuart_port_driver(_dev->driver); 844 to_ps3_vuart_port_driver(_dev->driver);
@@ -758,7 +847,12 @@ static int ps3_vuart_probe(struct device *_dev)
758 847
759 BUG_ON(!drv); 848 BUG_ON(!drv);
760 849
761 result = ps3_vuart_match_id_to_port(dev->match_id, &dev->port_number); 850 down(&vuart_bus_priv.probe_mutex);
851
852 /* Setup vuart_bus_priv.devices[]. */
853
854 result = ps3_vuart_match_id_to_port(dev->match_id,
855 &port_number);
762 856
763 if (result) { 857 if (result) {
764 dev_dbg(&dev->core, "%s:%d: unknown match_id (%d)\n", 858 dev_dbg(&dev->core, "%s:%d: unknown match_id (%d)\n",
@@ -767,24 +861,41 @@ static int ps3_vuart_probe(struct device *_dev)
767 goto fail_match; 861 goto fail_match;
768 } 862 }
769 863
770 if (vuart_private.devices[dev->port_number]) { 864 if (vuart_bus_priv.devices[port_number]) {
771 dev_dbg(&dev->core, "%s:%d: port busy (%d)\n", __func__, 865 dev_dbg(&dev->core, "%s:%d: port busy (%d)\n", __func__,
772 __LINE__, dev->port_number); 866 __LINE__, port_number);
773 result = -EBUSY; 867 result = -EBUSY;
774 goto fail_match; 868 goto fail_match;
775 } 869 }
776 870
777 vuart_private.devices[dev->port_number] = dev; 871 vuart_bus_priv.devices[port_number] = dev;
872
873 /* Setup dev->priv. */
874
875 dev->priv = kzalloc(sizeof(struct ps3_vuart_port_priv), GFP_KERNEL);
876
877 if (!dev->priv) {
878 result = -ENOMEM;
879 goto fail_alloc;
880 }
778 881
779 INIT_LIST_HEAD(&dev->tx_list.head); 882 dev->priv->port_number = port_number;
780 spin_lock_init(&dev->tx_list.lock); 883
781 INIT_LIST_HEAD(&dev->rx_list.head); 884 INIT_LIST_HEAD(&dev->priv->tx_list.head);
782 spin_lock_init(&dev->rx_list.lock); 885 spin_lock_init(&dev->priv->tx_list.lock);
886
887 INIT_LIST_HEAD(&dev->priv->rx_list.head);
888 spin_lock_init(&dev->priv->rx_list.lock);
889
890 INIT_WORK(&dev->priv->work.work, NULL);
891 spin_lock_init(&dev->priv->work.lock);
892 dev->priv->work.trigger = 0;
893 dev->priv->work.dev = dev;
894
895 if (++vuart_bus_priv.use_count == 1) {
783 896
784 vuart_private.in_use++;
785 if (vuart_private.in_use == 1) {
786 result = ps3_alloc_vuart_irq(PS3_BINDING_CPU_ANY, 897 result = ps3_alloc_vuart_irq(PS3_BINDING_CPU_ANY,
787 (void*)&vuart_private.bmp.status, &vuart_private.virq); 898 (void*)&vuart_bus_priv.bmp.status, &vuart_bus_priv.virq);
788 899
789 if (result) { 900 if (result) {
790 dev_dbg(&dev->core, 901 dev_dbg(&dev->core,
@@ -794,8 +905,8 @@ static int ps3_vuart_probe(struct device *_dev)
794 goto fail_alloc_irq; 905 goto fail_alloc_irq;
795 } 906 }
796 907
797 result = request_irq(vuart_private.virq, ps3_vuart_irq_handler, 908 result = request_irq(vuart_bus_priv.virq, ps3_vuart_irq_handler,
798 IRQF_DISABLED, "vuart", &vuart_private); 909 IRQF_DISABLED, "vuart", &vuart_bus_priv);
799 910
800 if (result) { 911 if (result) {
801 dev_info(&dev->core, "%s:%d: request_irq failed (%d)\n", 912 dev_info(&dev->core, "%s:%d: request_irq failed (%d)\n",
@@ -804,10 +915,11 @@ static int ps3_vuart_probe(struct device *_dev)
804 } 915 }
805 } 916 }
806 917
807 ps3_vuart_set_interrupt_mask(dev, INTERRUPT_MASK_RX);
808
809 /* clear stale pending interrupts */ 918 /* clear stale pending interrupts */
810 ps3_vuart_get_interrupt_mask(dev, &tmp); 919
920 ps3_vuart_clear_rx_bytes(dev, 0);
921
922 ps3_vuart_set_interrupt_mask(dev, INTERRUPT_MASK_RX);
811 923
812 ps3_vuart_set_triggers(dev, 1, 1); 924 ps3_vuart_set_triggers(dev, 1, 1);
813 925
@@ -822,20 +934,27 @@ static int ps3_vuart_probe(struct device *_dev)
822 if (result) { 934 if (result) {
823 dev_dbg(&dev->core, "%s:%d: drv->probe failed\n", 935 dev_dbg(&dev->core, "%s:%d: drv->probe failed\n",
824 __func__, __LINE__); 936 __func__, __LINE__);
937 down(&vuart_bus_priv.probe_mutex);
825 goto fail_probe; 938 goto fail_probe;
826 } 939 }
827 940
941 up(&vuart_bus_priv.probe_mutex);
942
828 return result; 943 return result;
829 944
830fail_probe: 945fail_probe:
946 ps3_vuart_set_interrupt_mask(dev, 0);
831fail_request_irq: 947fail_request_irq:
832 vuart_private.in_use--; 948 ps3_free_vuart_irq(vuart_bus_priv.virq);
833 if (!vuart_private.in_use) { 949 vuart_bus_priv.virq = NO_IRQ;
834 ps3_free_vuart_irq(vuart_private.virq);
835 vuart_private.virq = NO_IRQ;
836 }
837fail_alloc_irq: 950fail_alloc_irq:
951 --vuart_bus_priv.use_count;
952 kfree(dev->priv);
953 dev->priv = NULL;
954fail_alloc:
955 vuart_bus_priv.devices[port_number] = 0;
838fail_match: 956fail_match:
957 up(&vuart_bus_priv.probe_mutex);
839 dev_dbg(&dev->core, "%s:%d failed\n", __func__, __LINE__); 958 dev_dbg(&dev->core, "%s:%d failed\n", __func__, __LINE__);
840 return result; 959 return result;
841} 960}
@@ -846,10 +965,12 @@ static int ps3_vuart_remove(struct device *_dev)
846 struct ps3_vuart_port_driver *drv = 965 struct ps3_vuart_port_driver *drv =
847 to_ps3_vuart_port_driver(_dev->driver); 966 to_ps3_vuart_port_driver(_dev->driver);
848 967
968 down(&vuart_bus_priv.probe_mutex);
969
849 dev_dbg(&dev->core, "%s:%d: %s\n", __func__, __LINE__, 970 dev_dbg(&dev->core, "%s:%d: %s\n", __func__, __LINE__,
850 dev->core.bus_id); 971 dev->core.bus_id);
851 972
852 BUG_ON(vuart_private.in_use < 1); 973 BUG_ON(vuart_bus_priv.use_count < 1);
853 974
854 if (drv->remove) 975 if (drv->remove)
855 drv->remove(dev); 976 drv->remove(dev);
@@ -857,13 +978,19 @@ static int ps3_vuart_remove(struct device *_dev)
857 dev_dbg(&dev->core, "%s:%d: %s no remove method\n", __func__, 978 dev_dbg(&dev->core, "%s:%d: %s no remove method\n", __func__,
858 __LINE__, dev->core.bus_id); 979 __LINE__, dev->core.bus_id);
859 980
860 vuart_private.in_use--; 981 vuart_bus_priv.devices[dev->priv->port_number] = 0;
861 982
862 if (!vuart_private.in_use) { 983 if (--vuart_bus_priv.use_count == 0) {
863 free_irq(vuart_private.virq, &vuart_private); 984 BUG();
864 ps3_free_vuart_irq(vuart_private.virq); 985 free_irq(vuart_bus_priv.virq, &vuart_bus_priv);
865 vuart_private.virq = NO_IRQ; 986 ps3_free_vuart_irq(vuart_bus_priv.virq);
987 vuart_bus_priv.virq = NO_IRQ;
866 } 988 }
989
990 kfree(dev->priv);
991 dev->priv = NULL;
992
993 up(&vuart_bus_priv.probe_mutex);
867 return 0; 994 return 0;
868} 995}
869 996
@@ -884,12 +1011,12 @@ static void ps3_vuart_shutdown(struct device *_dev)
884} 1011}
885 1012
886/** 1013/**
887 * ps3_vuart - The vuart instance. 1014 * ps3_vuart_bus - The vuart bus instance.
888 * 1015 *
889 * The vuart is managed as a bus that port devices connect to. 1016 * The vuart is managed as a bus that port devices connect to.
890 */ 1017 */
891 1018
892struct bus_type ps3_vuart = { 1019struct bus_type ps3_vuart_bus = {
893 .name = "ps3_vuart", 1020 .name = "ps3_vuart",
894 .match = ps3_vuart_match, 1021 .match = ps3_vuart_match,
895 .probe = ps3_vuart_probe, 1022 .probe = ps3_vuart_probe,
@@ -897,24 +1024,30 @@ struct bus_type ps3_vuart = {
897 .shutdown = ps3_vuart_shutdown, 1024 .shutdown = ps3_vuart_shutdown,
898}; 1025};
899 1026
900int __init ps3_vuart_init(void) 1027int __init ps3_vuart_bus_init(void)
901{ 1028{
902 int result; 1029 int result;
903 1030
904 pr_debug("%s:%d:\n", __func__, __LINE__); 1031 pr_debug("%s:%d:\n", __func__, __LINE__);
905 result = bus_register(&ps3_vuart); 1032
1033 if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
1034 return 0;
1035
1036 init_MUTEX(&vuart_bus_priv.probe_mutex);
1037 result = bus_register(&ps3_vuart_bus);
906 BUG_ON(result); 1038 BUG_ON(result);
1039
907 return result; 1040 return result;
908} 1041}
909 1042
910void __exit ps3_vuart_exit(void) 1043void __exit ps3_vuart_bus_exit(void)
911{ 1044{
912 pr_debug("%s:%d:\n", __func__, __LINE__); 1045 pr_debug("%s:%d:\n", __func__, __LINE__);
913 bus_unregister(&ps3_vuart); 1046 bus_unregister(&ps3_vuart_bus);
914} 1047}
915 1048
916core_initcall(ps3_vuart_init); 1049core_initcall(ps3_vuart_bus_init);
917module_exit(ps3_vuart_exit); 1050module_exit(ps3_vuart_bus_exit);
918 1051
919/** 1052/**
920 * ps3_vuart_port_release_device - Remove a vuart port device. 1053 * ps3_vuart_port_release_device - Remove a vuart port device.
@@ -922,11 +1055,14 @@ module_exit(ps3_vuart_exit);
922 1055
923static void ps3_vuart_port_release_device(struct device *_dev) 1056static void ps3_vuart_port_release_device(struct device *_dev)
924{ 1057{
925 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
926#if defined(DEBUG) 1058#if defined(DEBUG)
927 memset(dev, 0xad, sizeof(struct ps3_vuart_port_device)); 1059 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
1060
1061 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
1062
1063 BUG_ON(dev->priv && "forgot to free");
1064 memset(&dev->core, 0, sizeof(dev->core));
928#endif 1065#endif
929 kfree(dev);
930} 1066}
931 1067
932/** 1068/**
@@ -935,11 +1071,12 @@ static void ps3_vuart_port_release_device(struct device *_dev)
935 1071
936int ps3_vuart_port_device_register(struct ps3_vuart_port_device *dev) 1072int ps3_vuart_port_device_register(struct ps3_vuart_port_device *dev)
937{ 1073{
938 int result;
939 static unsigned int dev_count = 1; 1074 static unsigned int dev_count = 1;
940 1075
1076 BUG_ON(dev->priv && "forgot to free");
1077
941 dev->core.parent = NULL; 1078 dev->core.parent = NULL;
942 dev->core.bus = &ps3_vuart; 1079 dev->core.bus = &ps3_vuart_bus;
943 dev->core.release = ps3_vuart_port_release_device; 1080 dev->core.release = ps3_vuart_port_release_device;
944 1081
945 snprintf(dev->core.bus_id, sizeof(dev->core.bus_id), "vuart_%02x", 1082 snprintf(dev->core.bus_id, sizeof(dev->core.bus_id), "vuart_%02x",
@@ -947,9 +1084,7 @@ int ps3_vuart_port_device_register(struct ps3_vuart_port_device *dev)
947 1084
948 dev_dbg(&dev->core, "%s:%d register\n", __func__, __LINE__); 1085 dev_dbg(&dev->core, "%s:%d register\n", __func__, __LINE__);
949 1086
950 result = device_register(&dev->core); 1087 return device_register(&dev->core);
951
952 return result;
953} 1088}
954 1089
955EXPORT_SYMBOL_GPL(ps3_vuart_port_device_register); 1090EXPORT_SYMBOL_GPL(ps3_vuart_port_device_register);
@@ -963,7 +1098,7 @@ int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv)
963 int result; 1098 int result;
964 1099
965 pr_debug("%s:%d: (%s)\n", __func__, __LINE__, drv->core.name); 1100 pr_debug("%s:%d: (%s)\n", __func__, __LINE__, drv->core.name);
966 drv->core.bus = &ps3_vuart; 1101 drv->core.bus = &ps3_vuart_bus;
967 result = driver_register(&drv->core); 1102 result = driver_register(&drv->core);
968 return result; 1103 return result;
969} 1104}
@@ -976,6 +1111,7 @@ EXPORT_SYMBOL_GPL(ps3_vuart_port_driver_register);
976 1111
977void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv) 1112void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv)
978{ 1113{
1114 pr_debug("%s:%d: (%s)\n", __func__, __LINE__, drv->core.name);
979 driver_unregister(&drv->core); 1115 driver_unregister(&drv->core);
980} 1116}
981 1117
diff --git a/drivers/ps3/vuart.h b/drivers/ps3/vuart.h
index 2cbf728a3a..1be992d568 100644
--- a/drivers/ps3/vuart.h
+++ b/drivers/ps3/vuart.h
@@ -21,6 +21,44 @@
21#if !defined(_PS3_VUART_H) 21#if !defined(_PS3_VUART_H)
22#define _PS3_VUART_H 22#define _PS3_VUART_H
23 23
24#include <asm/ps3.h>
25
26struct ps3_vuart_stats {
27 unsigned long bytes_written;
28 unsigned long bytes_read;
29 unsigned long tx_interrupts;
30 unsigned long rx_interrupts;
31 unsigned long disconnect_interrupts;
32};
33
34struct ps3_vuart_work {
35 struct work_struct work;
36 unsigned long trigger;
37 spinlock_t lock;
38 struct ps3_vuart_port_device* dev; /* to convert work to device */
39};
40
41/**
42 * struct ps3_vuart_port_priv - private vuart device data.
43 */
44
45struct ps3_vuart_port_priv {
46 unsigned int port_number;
47 u64 interrupt_mask;
48
49 struct {
50 spinlock_t lock;
51 struct list_head head;
52 } tx_list;
53 struct {
54 unsigned long bytes_held;
55 spinlock_t lock;
56 struct list_head head;
57 } rx_list;
58 struct ps3_vuart_stats stats;
59 struct ps3_vuart_work work;
60};
61
24/** 62/**
25 * struct ps3_vuart_port_driver - a driver for a device on a vuart port 63 * struct ps3_vuart_port_driver - a driver for a device on a vuart port
26 */ 64 */
@@ -41,10 +79,6 @@ struct ps3_vuart_port_driver {
41int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv); 79int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv);
42void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv); 80void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv);
43 81
44int ps3_vuart_write(struct ps3_vuart_port_device *dev,
45 const void* buf, unsigned int bytes);
46int ps3_vuart_read(struct ps3_vuart_port_device *dev, void* buf,
47 unsigned int bytes);
48static inline struct ps3_vuart_port_driver *to_ps3_vuart_port_driver( 82static inline struct ps3_vuart_port_driver *to_ps3_vuart_port_driver(
49 struct device_driver *_drv) 83 struct device_driver *_drv)
50{ 84{
@@ -55,5 +89,22 @@ static inline struct ps3_vuart_port_device *to_ps3_vuart_port_device(
55{ 89{
56 return container_of(_dev, struct ps3_vuart_port_device, core); 90 return container_of(_dev, struct ps3_vuart_port_device, core);
57} 91}
92static inline struct ps3_vuart_port_device *ps3_vuart_work_to_port_device(
93 struct work_struct *_work)
94{
95 struct ps3_vuart_work *vw = container_of(_work, struct ps3_vuart_work,
96 work);
97 return vw->dev;
98}
99
100int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf,
101 unsigned int bytes);
102int ps3_vuart_read(struct ps3_vuart_port_device *dev, void* buf,
103 unsigned int bytes);
104int ps3_vuart_read_async(struct ps3_vuart_port_device *dev, work_func_t func,
105 unsigned int bytes);
106void ps3_vuart_cancel_async(struct ps3_vuart_port_device *dev);
107void ps3_vuart_clear_rx_bytes(struct ps3_vuart_port_device *dev,
108 unsigned int bytes);
58 109
59#endif 110#endif
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 4bbca500d3..95826b92ca 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -101,7 +101,7 @@ comment "RTC drivers"
101 101
102config RTC_DRV_CMOS 102config RTC_DRV_CMOS
103 tristate "PC-style 'CMOS' real time clock" 103 tristate "PC-style 'CMOS' real time clock"
104 depends on RTC_CLASS && (X86_PC || ALPHA || ARM26 || ARM \ 104 depends on RTC_CLASS && (X86 || ALPHA || ARM26 || ARM \
105 || M32R || ATARI || POWERPC) 105 || M32R || ATARI || POWERPC)
106 help 106 help
107 Say "yes" here to get direct support for the real time clock 107 Say "yes" here to get direct support for the real time clock
@@ -207,10 +207,12 @@ config RTC_DRV_PCF8563
207 207
208config RTC_DRV_PCF8583 208config RTC_DRV_PCF8583
209 tristate "Philips PCF8583" 209 tristate "Philips PCF8583"
210 depends on RTC_CLASS && I2C 210 depends on RTC_CLASS && I2C && ARCH_RPC
211 help 211 help
212 If you say yes here you get support for the 212 If you say yes here you get support for the Philips PCF8583
213 Philips PCF8583 RTC chip. 213 RTC chip found on Acorn RiscPCs. This driver supports the
214 platform specific method of retrieving the current year from
215 the RTC's SRAM.
214 216
215 This driver can also be built as a module. If so, the module 217 This driver can also be built as a module. If so, the module
216 will be called rtc-pcf8583. 218 will be called rtc-pcf8583.
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 7a0d8ee2de..04aaa63472 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -113,10 +113,16 @@ EXPORT_SYMBOL_GPL(rtc_device_register);
113 */ 113 */
114void rtc_device_unregister(struct rtc_device *rtc) 114void rtc_device_unregister(struct rtc_device *rtc)
115{ 115{
116 mutex_lock(&rtc->ops_lock); 116 if (class_device_get(&rtc->class_dev) != NULL) {
117 rtc->ops = NULL; 117 mutex_lock(&rtc->ops_lock);
118 mutex_unlock(&rtc->ops_lock); 118 /* remove innards of this RTC, then disable it, before
119 class_device_unregister(&rtc->class_dev); 119 * letting any rtc_class_open() users access it again
120 */
121 class_device_unregister(&rtc->class_dev);
122 rtc->ops = NULL;
123 mutex_unlock(&rtc->ops_lock);
124 class_device_put(&rtc->class_dev);
125 }
120} 126}
121EXPORT_SYMBOL_GPL(rtc_device_unregister); 127EXPORT_SYMBOL_GPL(rtc_device_unregister);
122 128
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 6f11f6dfdd..ef40df0f16 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -179,7 +179,7 @@ struct class_device *rtc_class_open(char *name)
179 down(&rtc_class->sem); 179 down(&rtc_class->sem);
180 list_for_each_entry(class_dev_tmp, &rtc_class->children, node) { 180 list_for_each_entry(class_dev_tmp, &rtc_class->children, node) {
181 if (strncmp(class_dev_tmp->class_id, name, BUS_ID_SIZE) == 0) { 181 if (strncmp(class_dev_tmp->class_id, name, BUS_ID_SIZE) == 0) {
182 class_dev = class_dev_tmp; 182 class_dev = class_device_get(class_dev_tmp);
183 break; 183 break;
184 } 184 }
185 } 185 }
@@ -197,6 +197,7 @@ EXPORT_SYMBOL_GPL(rtc_class_open);
197void rtc_class_close(struct class_device *class_dev) 197void rtc_class_close(struct class_device *class_dev)
198{ 198{
199 module_put(to_rtc_device(class_dev)->owner); 199 module_put(to_rtc_device(class_dev)->owner);
200 class_device_put(class_dev);
200} 201}
201EXPORT_SYMBOL_GPL(rtc_class_close); 202EXPORT_SYMBOL_GPL(rtc_class_close);
202 203
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index a724ab49a7..ac0e68e2f0 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -164,6 +164,7 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
164 tm.tm_min = alrm->time.tm_min; 164 tm.tm_min = alrm->time.tm_min;
165 tm.tm_sec = alrm->time.tm_sec; 165 tm.tm_sec = alrm->time.tm_sec;
166 166
167 at91_sys_write(AT91_RTC_IDR, AT91_RTC_ALARM);
167 at91_sys_write(AT91_RTC_TIMALR, 168 at91_sys_write(AT91_RTC_TIMALR,
168 BIN2BCD(tm.tm_sec) << 0 169 BIN2BCD(tm.tm_sec) << 0
169 | BIN2BCD(tm.tm_min) << 8 170 | BIN2BCD(tm.tm_min) << 8
@@ -174,6 +175,9 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
174 | BIN2BCD(tm.tm_mday) << 24 175 | BIN2BCD(tm.tm_mday) << 24
175 | AT91_RTC_DATEEN | AT91_RTC_MTHEN); 176 | AT91_RTC_DATEEN | AT91_RTC_MTHEN);
176 177
178 if (alrm->enabled)
179 at91_sys_write(AT91_RTC_IER, AT91_RTC_ALARM);
180
177 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__, 181 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__,
178 at91_alarm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, 182 at91_alarm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour,
179 tm.tm_min, tm.tm_sec); 183 tm.tm_min, tm.tm_sec);
@@ -303,6 +307,12 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
303 return ret; 307 return ret;
304 } 308 }
305 309
310 /* cpu init code should really have flagged this device as
311 * being wake-capable; if it didn't, do that here.
312 */
313 if (!device_can_wakeup(&pdev->dev))
314 device_init_wakeup(&pdev->dev, 1);
315
306 rtc = rtc_device_register(pdev->name, &pdev->dev, 316 rtc = rtc_device_register(pdev->name, &pdev->dev,
307 &at91_rtc_ops, THIS_MODULE); 317 &at91_rtc_ops, THIS_MODULE);
308 if (IS_ERR(rtc)) { 318 if (IS_ERR(rtc)) {
@@ -310,7 +320,6 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
310 return PTR_ERR(rtc); 320 return PTR_ERR(rtc);
311 } 321 }
312 platform_set_drvdata(pdev, rtc); 322 platform_set_drvdata(pdev, rtc);
313 device_init_wakeup(&pdev->dev, 1);
314 323
315 printk(KERN_INFO "AT91 Real Time Clock driver.\n"); 324 printk(KERN_INFO "AT91 Real Time Clock driver.\n");
316 return 0; 325 return 0;
@@ -319,7 +328,7 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
319/* 328/*
320 * Disable and remove the RTC driver 329 * Disable and remove the RTC driver
321 */ 330 */
322static int __devexit at91_rtc_remove(struct platform_device *pdev) 331static int __exit at91_rtc_remove(struct platform_device *pdev)
323{ 332{
324 struct rtc_device *rtc = platform_get_drvdata(pdev); 333 struct rtc_device *rtc = platform_get_drvdata(pdev);
325 334
@@ -331,7 +340,6 @@ static int __devexit at91_rtc_remove(struct platform_device *pdev)
331 340
332 rtc_device_unregister(rtc); 341 rtc_device_unregister(rtc);
333 platform_set_drvdata(pdev, NULL); 342 platform_set_drvdata(pdev, NULL);
334 device_init_wakeup(&pdev->dev, 0);
335 343
336 return 0; 344 return 0;
337} 345}
@@ -404,8 +412,7 @@ static int at91_rtc_resume(struct platform_device *pdev)
404#endif 412#endif
405 413
406static struct platform_driver at91_rtc_driver = { 414static struct platform_driver at91_rtc_driver = {
407 .probe = at91_rtc_probe, 415 .remove = __exit_p(at91_rtc_remove),
408 .remove = at91_rtc_remove,
409 .suspend = at91_rtc_suspend, 416 .suspend = at91_rtc_suspend,
410 .resume = at91_rtc_resume, 417 .resume = at91_rtc_resume,
411 .driver = { 418 .driver = {
@@ -416,7 +423,7 @@ static struct platform_driver at91_rtc_driver = {
416 423
417static int __init at91_rtc_init(void) 424static int __init at91_rtc_init(void)
418{ 425{
419 return platform_driver_register(&at91_rtc_driver); 426 return platform_driver_probe(&at91_rtc_driver, at91_rtc_probe);
420} 427}
421 428
422static void __exit at91_rtc_exit(void) 429static void __exit at91_rtc_exit(void)
diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c
index 5875ebb8c7..d48b033745 100644
--- a/drivers/rtc/rtc-pcf8583.c
+++ b/drivers/rtc/rtc-pcf8583.c
@@ -40,7 +40,7 @@ struct pcf8583 {
40#define CTRL_ALARM 0x02 40#define CTRL_ALARM 0x02
41#define CTRL_TIMER 0x01 41#define CTRL_TIMER 0x01
42 42
43static unsigned short normal_i2c[] = { I2C_CLIENT_END }; 43static unsigned short normal_i2c[] = { 0x50, I2C_CLIENT_END };
44 44
45/* Module parameters */ 45/* Module parameters */
46I2C_CLIENT_INSMOD; 46I2C_CLIENT_INSMOD;
@@ -81,11 +81,11 @@ static int pcf8583_get_datetime(struct i2c_client *client, struct rtc_time *dt)
81 buf[4] &= 0x3f; 81 buf[4] &= 0x3f;
82 buf[5] &= 0x1f; 82 buf[5] &= 0x1f;
83 83
84 dt->tm_sec = BCD_TO_BIN(buf[1]); 84 dt->tm_sec = BCD2BIN(buf[1]);
85 dt->tm_min = BCD_TO_BIN(buf[2]); 85 dt->tm_min = BCD2BIN(buf[2]);
86 dt->tm_hour = BCD_TO_BIN(buf[3]); 86 dt->tm_hour = BCD2BIN(buf[3]);
87 dt->tm_mday = BCD_TO_BIN(buf[4]); 87 dt->tm_mday = BCD2BIN(buf[4]);
88 dt->tm_mon = BCD_TO_BIN(buf[5]); 88 dt->tm_mon = BCD2BIN(buf[5]) - 1;
89 } 89 }
90 90
91 return ret == 2 ? 0 : -EIO; 91 return ret == 2 ? 0 : -EIO;
@@ -99,14 +99,14 @@ static int pcf8583_set_datetime(struct i2c_client *client, struct rtc_time *dt,
99 buf[0] = 0; 99 buf[0] = 0;
100 buf[1] = get_ctrl(client) | 0x80; 100 buf[1] = get_ctrl(client) | 0x80;
101 buf[2] = 0; 101 buf[2] = 0;
102 buf[3] = BIN_TO_BCD(dt->tm_sec); 102 buf[3] = BIN2BCD(dt->tm_sec);
103 buf[4] = BIN_TO_BCD(dt->tm_min); 103 buf[4] = BIN2BCD(dt->tm_min);
104 buf[5] = BIN_TO_BCD(dt->tm_hour); 104 buf[5] = BIN2BCD(dt->tm_hour);
105 105
106 if (datetoo) { 106 if (datetoo) {
107 len = 8; 107 len = 8;
108 buf[6] = BIN_TO_BCD(dt->tm_mday) | (dt->tm_year << 6); 108 buf[6] = BIN2BCD(dt->tm_mday) | (dt->tm_year << 6);
109 buf[7] = BIN_TO_BCD(dt->tm_mon) | (dt->tm_wday << 5); 109 buf[7] = BIN2BCD(dt->tm_mon + 1) | (dt->tm_wday << 5);
110 } 110 }
111 111
112 ret = i2c_master_send(client, (char *)buf, len); 112 ret = i2c_master_send(client, (char *)buf, len);
@@ -226,7 +226,7 @@ static int pcf8583_rtc_read_time(struct device *dev, struct rtc_time *tm)
226 */ 226 */
227 year_offset += 4; 227 year_offset += 4;
228 228
229 tm->tm_year = real_year + year_offset + year[1] * 100; 229 tm->tm_year = (real_year + year_offset + year[1] * 100) - 1900;
230 230
231 return 0; 231 return 0;
232} 232}
@@ -237,6 +237,7 @@ static int pcf8583_rtc_set_time(struct device *dev, struct rtc_time *tm)
237 unsigned char year[2], chk; 237 unsigned char year[2], chk;
238 struct rtc_mem cmos_year = { CMOS_YEAR, sizeof(year), year }; 238 struct rtc_mem cmos_year = { CMOS_YEAR, sizeof(year), year };
239 struct rtc_mem cmos_check = { CMOS_CHECKSUM, 1, &chk }; 239 struct rtc_mem cmos_check = { CMOS_CHECKSUM, 1, &chk };
240 unsigned int proper_year = tm->tm_year + 1900;
240 int ret; 241 int ret;
241 242
242 /* 243 /*
@@ -258,8 +259,8 @@ static int pcf8583_rtc_set_time(struct device *dev, struct rtc_time *tm)
258 259
259 chk -= year[1] + year[0]; 260 chk -= year[1] + year[0];
260 261
261 year[1] = tm->tm_year / 100; 262 year[1] = proper_year / 100;
262 year[0] = tm->tm_year % 100; 263 year[0] = proper_year % 100;
263 264
264 chk += year[1] + year[0]; 265 chk += year[1] + year[0];
265 266
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index 9c8ead43a5..677bae820d 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -263,8 +263,12 @@ static int sa1100_rtc_set_time(struct device *dev, struct rtc_time *tm)
263 263
264static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) 264static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
265{ 265{
266 u32 rtsr;
267
266 memcpy(&alrm->time, &rtc_alarm, sizeof(struct rtc_time)); 268 memcpy(&alrm->time, &rtc_alarm, sizeof(struct rtc_time));
267 alrm->pending = RTSR & RTSR_AL ? 1 : 0; 269 rtsr = RTSR;
270 alrm->enabled = (rtsr & RTSR_ALE) ? 1 : 0;
271 alrm->pending = (rtsr & RTSR_AL) ? 1 : 0;
268 return 0; 272 return 0;
269} 273}
270 274
@@ -275,12 +279,10 @@ static int sa1100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
275 spin_lock_irq(&sa1100_rtc_lock); 279 spin_lock_irq(&sa1100_rtc_lock);
276 ret = rtc_update_alarm(&alrm->time); 280 ret = rtc_update_alarm(&alrm->time);
277 if (ret == 0) { 281 if (ret == 0) {
278 memcpy(&rtc_alarm, &alrm->time, sizeof(struct rtc_time));
279
280 if (alrm->enabled) 282 if (alrm->enabled)
281 enable_irq_wake(IRQ_RTCAlrm); 283 RTSR |= RTSR_ALE;
282 else 284 else
283 disable_irq_wake(IRQ_RTCAlrm); 285 RTSR &= ~RTSR_ALE;
284 } 286 }
285 spin_unlock_irq(&sa1100_rtc_lock); 287 spin_unlock_irq(&sa1100_rtc_lock);
286 288
diff --git a/drivers/s390/block/dasd_eer.c b/drivers/s390/block/dasd_eer.c
index 4b8a95fba1..a1dc8c466e 100644
--- a/drivers/s390/block/dasd_eer.c
+++ b/drivers/s390/block/dasd_eer.c
@@ -461,6 +461,7 @@ int dasd_eer_enable(struct dasd_device *device)
461 cqr->device = device; 461 cqr->device = device;
462 cqr->retries = 255; 462 cqr->retries = 255;
463 cqr->expires = 10 * HZ; 463 cqr->expires = 10 * HZ;
464 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
464 465
465 cqr->cpaddr->cmd_code = DASD_ECKD_CCW_SNSS; 466 cqr->cpaddr->cmd_code = DASD_ECKD_CCW_SNSS;
466 cqr->cpaddr->count = SNSS_DATA_SIZE; 467 cqr->cpaddr->count = SNSS_DATA_SIZE;
diff --git a/drivers/s390/char/sclp_quiesce.c b/drivers/s390/char/sclp_quiesce.c
index ffa9282ce9..baa8fe669e 100644
--- a/drivers/s390/char/sclp_quiesce.c
+++ b/drivers/s390/char/sclp_quiesce.c
@@ -16,6 +16,7 @@
16#include <asm/atomic.h> 16#include <asm/atomic.h>
17#include <asm/ptrace.h> 17#include <asm/ptrace.h>
18#include <asm/sigp.h> 18#include <asm/sigp.h>
19#include <asm/smp.h>
19 20
20#include "sclp.h" 21#include "sclp.h"
21 22
diff --git a/drivers/s390/char/tape_std.c b/drivers/s390/char/tape_std.c
index 7a76ec413a..2a1af4e60b 100644
--- a/drivers/s390/char/tape_std.c
+++ b/drivers/s390/char/tape_std.c
@@ -647,7 +647,10 @@ tape_std_mtcompression(struct tape_device *device, int mt_count)
647 return PTR_ERR(request); 647 return PTR_ERR(request);
648 request->op = TO_NOP; 648 request->op = TO_NOP;
649 /* setup ccws */ 649 /* setup ccws */
650 *device->modeset_byte = (mt_count == 0) ? 0x00 : 0x08; 650 if (mt_count == 0)
651 *device->modeset_byte &= ~0x08;
652 else
653 *device->modeset_byte |= 0x08;
651 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte); 654 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
652 tape_ccw_end(request->cpaddr + 1, NOP, 0, NULL); 655 tape_ccw_end(request->cpaddr + 1, NOP, 0, NULL);
653 /* execute it */ 656 /* execute it */
diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c
index b3a56dc5f6..9cb129ab5b 100644
--- a/drivers/s390/cio/cio.c
+++ b/drivers/s390/cio/cio.c
@@ -21,6 +21,7 @@
21#include <asm/irq_regs.h> 21#include <asm/irq_regs.h>
22#include <asm/setup.h> 22#include <asm/setup.h>
23#include <asm/reset.h> 23#include <asm/reset.h>
24#include <asm/ipl.h>
24#include "airq.h" 25#include "airq.h"
25#include "cio.h" 26#include "cio.h"
26#include "css.h" 27#include "css.h"
@@ -1047,7 +1048,7 @@ void reipl_ccw_dev(struct ccw_dev_id *devid)
1047 do_reipl_asm(*((__u32*)&schid)); 1048 do_reipl_asm(*((__u32*)&schid));
1048} 1049}
1049 1050
1050extern struct schib ipl_schib; 1051static struct schib __initdata ipl_schib;
1051 1052
1052/* 1053/*
1053 * ipl_save_parameters gets called very early. It is not allowed to access 1054 * ipl_save_parameters gets called very early. It is not allowed to access
diff --git a/drivers/s390/cio/device_fsm.c b/drivers/s390/cio/device_fsm.c
index 51238e7555..089a3ddd62 100644
--- a/drivers/s390/cio/device_fsm.c
+++ b/drivers/s390/cio/device_fsm.c
@@ -144,8 +144,8 @@ ccw_device_cancel_halt_clear(struct ccw_device *cdev)
144 ret = stsch(sch->schid, &sch->schib); 144 ret = stsch(sch->schid, &sch->schib);
145 if (ret || !sch->schib.pmcw.dnv) 145 if (ret || !sch->schib.pmcw.dnv)
146 return -ENODEV; 146 return -ENODEV;
147 if (!sch->schib.pmcw.ena || sch->schib.scsw.actl == 0) 147 if (!sch->schib.pmcw.ena)
148 /* Not operational or no activity -> done. */ 148 /* Not operational -> done. */
149 return 0; 149 return 0;
150 /* Stage 1: cancel io. */ 150 /* Stage 1: cancel io. */
151 if (!(sch->schib.scsw.actl & SCSW_ACTL_HALT_PEND) && 151 if (!(sch->schib.scsw.actl & SCSW_ACTL_HALT_PEND) &&
@@ -334,20 +334,29 @@ ccw_device_oper_notify(struct work_struct *work)
334 struct ccw_device *cdev; 334 struct ccw_device *cdev;
335 struct subchannel *sch; 335 struct subchannel *sch;
336 int ret; 336 int ret;
337 unsigned long flags;
337 338
338 priv = container_of(work, struct ccw_device_private, kick_work); 339 priv = container_of(work, struct ccw_device_private, kick_work);
339 cdev = priv->cdev; 340 cdev = priv->cdev;
341 spin_lock_irqsave(cdev->ccwlock, flags);
340 sch = to_subchannel(cdev->dev.parent); 342 sch = to_subchannel(cdev->dev.parent);
341 ret = (sch->driver && sch->driver->notify) ? 343 if (sch->driver && sch->driver->notify) {
342 sch->driver->notify(&sch->dev, CIO_OPER) : 0; 344 spin_unlock_irqrestore(cdev->ccwlock, flags);
343 if (!ret) 345 ret = sch->driver->notify(&sch->dev, CIO_OPER);
344 /* Driver doesn't want device back. */ 346 spin_lock_irqsave(cdev->ccwlock, flags);
345 ccw_device_do_unreg_rereg(work); 347 } else
346 else { 348 ret = 0;
349 if (ret) {
347 /* Reenable channel measurements, if needed. */ 350 /* Reenable channel measurements, if needed. */
351 spin_unlock_irqrestore(cdev->ccwlock, flags);
348 cmf_reenable(cdev); 352 cmf_reenable(cdev);
353 spin_lock_irqsave(cdev->ccwlock, flags);
349 wake_up(&cdev->private->wait_q); 354 wake_up(&cdev->private->wait_q);
350 } 355 }
356 spin_unlock_irqrestore(cdev->ccwlock, flags);
357 if (!ret)
358 /* Driver doesn't want device back. */
359 ccw_device_do_unreg_rereg(work);
351} 360}
352 361
353/* 362/*
@@ -534,15 +543,21 @@ ccw_device_nopath_notify(struct work_struct *work)
534 struct ccw_device *cdev; 543 struct ccw_device *cdev;
535 struct subchannel *sch; 544 struct subchannel *sch;
536 int ret; 545 int ret;
546 unsigned long flags;
537 547
538 priv = container_of(work, struct ccw_device_private, kick_work); 548 priv = container_of(work, struct ccw_device_private, kick_work);
539 cdev = priv->cdev; 549 cdev = priv->cdev;
550 spin_lock_irqsave(cdev->ccwlock, flags);
540 sch = to_subchannel(cdev->dev.parent); 551 sch = to_subchannel(cdev->dev.parent);
541 /* Extra sanity. */ 552 /* Extra sanity. */
542 if (sch->lpm) 553 if (sch->lpm)
543 return; 554 goto out_unlock;
544 ret = (sch->driver && sch->driver->notify) ? 555 if (sch->driver && sch->driver->notify) {
545 sch->driver->notify(&sch->dev, CIO_NO_PATH) : 0; 556 spin_unlock_irqrestore(cdev->ccwlock, flags);
557 ret = sch->driver->notify(&sch->dev, CIO_NO_PATH);
558 spin_lock_irqsave(cdev->ccwlock, flags);
559 } else
560 ret = 0;
546 if (!ret) { 561 if (!ret) {
547 if (get_device(&sch->dev)) { 562 if (get_device(&sch->dev)) {
548 /* Driver doesn't want to keep device. */ 563 /* Driver doesn't want to keep device. */
@@ -562,6 +577,8 @@ ccw_device_nopath_notify(struct work_struct *work)
562 cdev->private->state = DEV_STATE_DISCONNECTED; 577 cdev->private->state = DEV_STATE_DISCONNECTED;
563 wake_up(&cdev->private->wait_q); 578 wake_up(&cdev->private->wait_q);
564 } 579 }
580out_unlock:
581 spin_unlock_irqrestore(cdev->ccwlock, flags);
565} 582}
566 583
567void 584void
@@ -607,10 +624,13 @@ ccw_device_verify_done(struct ccw_device *cdev, int err)
607 default: 624 default:
608 /* Reset oper notify indication after verify error. */ 625 /* Reset oper notify indication after verify error. */
609 cdev->private->flags.donotify = 0; 626 cdev->private->flags.donotify = 0;
610 PREPARE_WORK(&cdev->private->kick_work, 627 if (cdev->online) {
611 ccw_device_nopath_notify); 628 PREPARE_WORK(&cdev->private->kick_work,
612 queue_work(ccw_device_notify_work, &cdev->private->kick_work); 629 ccw_device_nopath_notify);
613 ccw_device_done(cdev, DEV_STATE_NOT_OPER); 630 queue_work(ccw_device_notify_work,
631 &cdev->private->kick_work);
632 } else
633 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
614 break; 634 break;
615 } 635 }
616} 636}
@@ -756,15 +776,22 @@ static void
756ccw_device_online_notoper(struct ccw_device *cdev, enum dev_event dev_event) 776ccw_device_online_notoper(struct ccw_device *cdev, enum dev_event dev_event)
757{ 777{
758 struct subchannel *sch; 778 struct subchannel *sch;
779 int ret;
759 780
760 sch = to_subchannel(cdev->dev.parent); 781 sch = to_subchannel(cdev->dev.parent);
761 if (sch->driver->notify && 782 if (sch->driver->notify) {
762 sch->driver->notify(&sch->dev, sch->lpm ? CIO_GONE : CIO_NO_PATH)) { 783 spin_unlock_irq(cdev->ccwlock);
763 ccw_device_set_timeout(cdev, 0); 784 ret = sch->driver->notify(&sch->dev,
764 cdev->private->flags.fake_irb = 0; 785 sch->lpm ? CIO_GONE : CIO_NO_PATH);
765 cdev->private->state = DEV_STATE_DISCONNECTED; 786 spin_lock_irq(cdev->ccwlock);
766 wake_up(&cdev->private->wait_q); 787 } else
767 return; 788 ret = 0;
789 if (ret) {
790 ccw_device_set_timeout(cdev, 0);
791 cdev->private->flags.fake_irb = 0;
792 cdev->private->state = DEV_STATE_DISCONNECTED;
793 wake_up(&cdev->private->wait_q);
794 return;
768 } 795 }
769 cdev->private->state = DEV_STATE_NOT_OPER; 796 cdev->private->state = DEV_STATE_NOT_OPER;
770 cio_disable_subchannel(sch); 797 cio_disable_subchannel(sch);
@@ -969,18 +996,12 @@ ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
969 996
970 sch = to_subchannel(cdev->dev.parent); 997 sch = to_subchannel(cdev->dev.parent);
971 ccw_device_set_timeout(cdev, 0); 998 ccw_device_set_timeout(cdev, 0);
999 /* Start delayed path verification. */
1000 ccw_device_online_verify(cdev, 0);
972 /* OK, i/o is dead now. Call interrupt handler. */ 1001 /* OK, i/o is dead now. Call interrupt handler. */
973 cdev->private->state = DEV_STATE_ONLINE;
974 if (cdev->handler) 1002 if (cdev->handler)
975 cdev->handler(cdev, cdev->private->intparm, 1003 cdev->handler(cdev, cdev->private->intparm,
976 ERR_PTR(-EIO)); 1004 ERR_PTR(-EIO));
977 if (!sch->lpm) {
978 PREPARE_WORK(&cdev->private->kick_work,
979 ccw_device_nopath_notify);
980 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
981 } else if (cdev->private->flags.doverify)
982 /* Start delayed path verification. */
983 ccw_device_online_verify(cdev, 0);
984} 1005}
985 1006
986static void 1007static void
@@ -993,21 +1014,8 @@ ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
993 ccw_device_set_timeout(cdev, 3*HZ); 1014 ccw_device_set_timeout(cdev, 3*HZ);
994 return; 1015 return;
995 } 1016 }
996 if (ret == -ENODEV) { 1017 /* Start delayed path verification. */
997 struct subchannel *sch; 1018 ccw_device_online_verify(cdev, 0);
998
999 sch = to_subchannel(cdev->dev.parent);
1000 if (!sch->lpm) {
1001 PREPARE_WORK(&cdev->private->kick_work,
1002 ccw_device_nopath_notify);
1003 queue_work(ccw_device_notify_work,
1004 &cdev->private->kick_work);
1005 } else
1006 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
1007 return;
1008 }
1009 //FIXME: Can we get here?
1010 cdev->private->state = DEV_STATE_ONLINE;
1011 if (cdev->handler) 1019 if (cdev->handler)
1012 cdev->handler(cdev, cdev->private->intparm, 1020 cdev->handler(cdev, cdev->private->intparm,
1013 ERR_PTR(-EIO)); 1021 ERR_PTR(-EIO));
@@ -1025,26 +1033,11 @@ void device_kill_io(struct subchannel *sch)
1025 cdev->private->state = DEV_STATE_TIMEOUT_KILL; 1033 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
1026 return; 1034 return;
1027 } 1035 }
1028 if (ret == -ENODEV) { 1036 /* Start delayed path verification. */
1029 if (!sch->lpm) { 1037 ccw_device_online_verify(cdev, 0);
1030 PREPARE_WORK(&cdev->private->kick_work,
1031 ccw_device_nopath_notify);
1032 queue_work(ccw_device_notify_work,
1033 &cdev->private->kick_work);
1034 } else
1035 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
1036 return;
1037 }
1038 if (cdev->handler) 1038 if (cdev->handler)
1039 cdev->handler(cdev, cdev->private->intparm, 1039 cdev->handler(cdev, cdev->private->intparm,
1040 ERR_PTR(-EIO)); 1040 ERR_PTR(-EIO));
1041 if (!sch->lpm) {
1042 PREPARE_WORK(&cdev->private->kick_work,
1043 ccw_device_nopath_notify);
1044 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
1045 } else
1046 /* Start delayed path verification. */
1047 ccw_device_online_verify(cdev, 0);
1048} 1041}
1049 1042
1050static void 1043static void
diff --git a/drivers/s390/net/qeth_main.c b/drivers/s390/net/qeth_main.c
index 2257e45594..d8a86f5af3 100644
--- a/drivers/s390/net/qeth_main.c
+++ b/drivers/s390/net/qeth_main.c
@@ -3654,7 +3654,7 @@ qeth_verify_vlan_dev(struct net_device *dev, struct qeth_card *card)
3654 return rc; 3654 return rc;
3655 3655
3656 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++){ 3656 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++){
3657 if (vg->vlan_devices[i] == dev){ 3657 if (vlan_group_get_device(vg, i) == dev){
3658 rc = QETH_VLAN_CARD; 3658 rc = QETH_VLAN_CARD;
3659 break; 3659 break;
3660 } 3660 }
@@ -5261,7 +5261,7 @@ qeth_free_vlan_addresses4(struct qeth_card *card, unsigned short vid)
5261 QETH_DBF_TEXT(trace, 4, "frvaddr4"); 5261 QETH_DBF_TEXT(trace, 4, "frvaddr4");
5262 5262
5263 rcu_read_lock(); 5263 rcu_read_lock();
5264 in_dev = __in_dev_get_rcu(card->vlangrp->vlan_devices[vid]); 5264 in_dev = __in_dev_get_rcu(vlan_group_get_device(card->vlangrp, vid));
5265 if (!in_dev) 5265 if (!in_dev)
5266 goto out; 5266 goto out;
5267 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) { 5267 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
@@ -5288,7 +5288,7 @@ qeth_free_vlan_addresses6(struct qeth_card *card, unsigned short vid)
5288 5288
5289 QETH_DBF_TEXT(trace, 4, "frvaddr6"); 5289 QETH_DBF_TEXT(trace, 4, "frvaddr6");
5290 5290
5291 in6_dev = in6_dev_get(card->vlangrp->vlan_devices[vid]); 5291 in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
5292 if (!in6_dev) 5292 if (!in6_dev)
5293 return; 5293 return;
5294 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next){ 5294 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next){
@@ -5360,7 +5360,7 @@ qeth_layer2_process_vlans(struct qeth_card *card, int clear)
5360 if (!card->vlangrp) 5360 if (!card->vlangrp)
5361 return; 5361 return;
5362 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { 5362 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5363 if (card->vlangrp->vlan_devices[i] == NULL) 5363 if (vlan_group_get_device(card->vlangrp, i) == NULL)
5364 continue; 5364 continue;
5365 if (clear) 5365 if (clear)
5366 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_DELVLAN); 5366 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_DELVLAN);
@@ -5398,8 +5398,7 @@ qeth_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
5398 spin_lock_irqsave(&card->vlanlock, flags); 5398 spin_lock_irqsave(&card->vlanlock, flags);
5399 /* unregister IP addresses of vlan device */ 5399 /* unregister IP addresses of vlan device */
5400 qeth_free_vlan_addresses(card, vid); 5400 qeth_free_vlan_addresses(card, vid);
5401 if (card->vlangrp) 5401 vlan_group_set_device(card->vlangrp, vid, NULL);
5402 card->vlangrp->vlan_devices[vid] = NULL;
5403 spin_unlock_irqrestore(&card->vlanlock, flags); 5402 spin_unlock_irqrestore(&card->vlanlock, flags);
5404 if (card->options.layer2) 5403 if (card->options.layer2)
5405 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN); 5404 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
@@ -5662,10 +5661,11 @@ qeth_add_vlan_mc(struct qeth_card *card)
5662 5661
5663 vg = card->vlangrp; 5662 vg = card->vlangrp;
5664 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { 5663 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5665 if (vg->vlan_devices[i] == NULL || 5664 struct net_device *netdev = vlan_group_get_device(vg, i);
5666 !(vg->vlan_devices[i]->flags & IFF_UP)) 5665 if (netdev == NULL ||
5666 !(netdev->flags & IFF_UP))
5667 continue; 5667 continue;
5668 in_dev = in_dev_get(vg->vlan_devices[i]); 5668 in_dev = in_dev_get(netdev);
5669 if (!in_dev) 5669 if (!in_dev)
5670 continue; 5670 continue;
5671 read_lock(&in_dev->mc_list_lock); 5671 read_lock(&in_dev->mc_list_lock);
@@ -5749,10 +5749,11 @@ qeth_add_vlan_mc6(struct qeth_card *card)
5749 5749
5750 vg = card->vlangrp; 5750 vg = card->vlangrp;
5751 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { 5751 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5752 if (vg->vlan_devices[i] == NULL || 5752 struct net_device *netdev = vlan_group_get_device(vg, i);
5753 !(vg->vlan_devices[i]->flags & IFF_UP)) 5753 if (netdev == NULL ||
5754 !(netdev->flags & IFF_UP))
5754 continue; 5755 continue;
5755 in_dev = in6_dev_get(vg->vlan_devices[i]); 5756 in_dev = in6_dev_get(netdev);
5756 if (!in_dev) 5757 if (!in_dev)
5757 continue; 5758 continue;
5758 read_lock(&in_dev->lock); 5759 read_lock(&in_dev->lock);
diff --git a/drivers/sbus/char/Kconfig b/drivers/sbus/char/Kconfig
index 3a8152906b..35a7316833 100644
--- a/drivers/sbus/char/Kconfig
+++ b/drivers/sbus/char/Kconfig
@@ -46,13 +46,6 @@ config SUN_VIDEOPIX
46 based on the Phillips SAA9051, can handle NTSC and PAL/SECAM and 46 based on the Phillips SAA9051, can handle NTSC and PAL/SECAM and
47 SVIDEO signals. 47 SVIDEO signals.
48 48
49config SUN_AURORA
50 tristate "Aurora Multiboard 1600se (EXPERIMENTAL)"
51 depends on EXPERIMENTAL && BROKEN
52 help
53 The Aurora Multiboard is a multi-port high-speed serial controller.
54 If you have one of these, say Y.
55
56config TADPOLE_TS102_UCTRL 49config TADPOLE_TS102_UCTRL
57 tristate "Tadpole TS102 Microcontroller support (EXPERIMENTAL)" 50 tristate "Tadpole TS102 Microcontroller support (EXPERIMENTAL)"
58 depends on EXPERIMENTAL && SPARC32 51 depends on EXPERIMENTAL && SPARC32
diff --git a/drivers/sbus/char/Makefile b/drivers/sbus/char/Makefile
index 3a5ea1dc78..7ab060e9a5 100644
--- a/drivers/sbus/char/Makefile
+++ b/drivers/sbus/char/Makefile
@@ -19,7 +19,6 @@ obj-$(CONFIG_SUN_OPENPROMIO) += openprom.o
19obj-$(CONFIG_SUN_MOSTEK_RTC) += rtc.o 19obj-$(CONFIG_SUN_MOSTEK_RTC) += rtc.o
20obj-$(CONFIG_SUN_BPP) += bpp.o 20obj-$(CONFIG_SUN_BPP) += bpp.o
21obj-$(CONFIG_SUN_VIDEOPIX) += vfc.o 21obj-$(CONFIG_SUN_VIDEOPIX) += vfc.o
22obj-$(CONFIG_SUN_AURORA) += aurora.o
23obj-$(CONFIG_TADPOLE_TS102_UCTRL) += uctrl.o 22obj-$(CONFIG_TADPOLE_TS102_UCTRL) += uctrl.o
24obj-$(CONFIG_SUN_JSFLASH) += jsflash.o 23obj-$(CONFIG_SUN_JSFLASH) += jsflash.o
25obj-$(CONFIG_BBC_I2C) += bbc.o 24obj-$(CONFIG_BBC_I2C) += bbc.o
diff --git a/drivers/sbus/char/aurora.c b/drivers/sbus/char/aurora.c
deleted file mode 100644
index a54b4ac675..0000000000
--- a/drivers/sbus/char/aurora.c
+++ /dev/null
@@ -1,2364 +0,0 @@
1/* $Id: aurora.c,v 1.19 2002/01/08 16:00:16 davem Exp $
2 * linux/drivers/sbus/char/aurora.c -- Aurora multiport driver
3 *
4 * Copyright (c) 1999 by Oliver Aldulea (oli at bv dot ro)
5 *
6 * This code is based on the RISCom/8 multiport serial driver written
7 * by Dmitry Gorodchanin (pgmdsg@ibi.com), based on the Linux serial
8 * driver, written by Linus Torvalds, Theodore T'so and others.
9 * The Aurora multiport programming info was obtained mainly from the
10 * Cirrus Logic CD180 documentation (available on the web), and by
11 * doing heavy tests on the board. Many thanks to Eddie C. Dost for the
12 * help on the sbus interface.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 *
28 * Revision 1.0
29 *
30 * This is the first public release.
31 *
32 * Most of the information you need is in the aurora.h file. Please
33 * read that file before reading this one.
34 *
35 * Several parts of the code do not have comments yet.
36 *
37 * n.b. The board can support 115.2 bit rates, but only on a few
38 * ports. The total badwidth of one chip (ports 0-7 or 8-15) is equal
39 * to OSC_FREQ div 16. In case of my board, each chip can take 6
40 * channels of 115.2 kbaud. This information is not well-tested.
41 *
42 * Fixed to use tty_get_baud_rate().
43 * Theodore Ts'o <tytso@mit.edu>, 2001-Oct-12
44 */
45
46#include <linux/module.h>
47
48#include <linux/errno.h>
49#include <linux/sched.h>
50#ifdef AURORA_INT_DEBUG
51#include <linux/timer.h>
52#endif
53#include <linux/interrupt.h>
54#include <linux/tty.h>
55#include <linux/tty_flip.h>
56#include <linux/major.h>
57#include <linux/string.h>
58#include <linux/fcntl.h>
59#include <linux/mm.h>
60#include <linux/kernel.h>
61#include <linux/init.h>
62#include <linux/delay.h>
63#include <linux/bitops.h>
64
65#include <asm/io.h>
66#include <asm/irq.h>
67#include <asm/oplib.h>
68#include <asm/system.h>
69#include <asm/kdebug.h>
70#include <asm/sbus.h>
71#include <asm/uaccess.h>
72
73#include "aurora.h"
74#include "cd180.h"
75
76unsigned char irqs[4] = {
77 0, 0, 0, 0
78};
79
80#ifdef AURORA_INT_DEBUG
81int irqhit=0;
82#endif
83
84static struct tty_driver *aurora_driver;
85static struct Aurora_board aurora_board[AURORA_NBOARD] = {
86 {0,},
87};
88
89static struct Aurora_port aurora_port[AURORA_TNPORTS] = {
90 { 0, },
91};
92
93/* no longer used. static struct Aurora_board * IRQ_to_board[16] = { NULL, } ;*/
94static unsigned char * tmp_buf = NULL;
95
96DECLARE_TASK_QUEUE(tq_aurora);
97
98static inline int aurora_paranoia_check(struct Aurora_port const * port,
99 char *name, const char *routine)
100{
101#ifdef AURORA_PARANOIA_CHECK
102 static const char *badmagic =
103 KERN_DEBUG "aurora: Warning: bad aurora port magic number for device %s in %s\n";
104 static const char *badinfo =
105 KERN_DEBUG "aurora: Warning: null aurora port for device %s in %s\n";
106
107 if (!port) {
108 printk(badinfo, name, routine);
109 return 1;
110 }
111 if (port->magic != AURORA_MAGIC) {
112 printk(badmagic, name, routine);
113 return 1;
114 }
115#endif
116 return 0;
117}
118
119/*
120 *
121 * Service functions for aurora driver.
122 *
123 */
124
125/* Get board number from pointer */
126static inline int board_No (struct Aurora_board const * bp)
127{
128 return bp - aurora_board;
129}
130
131/* Get port number from pointer */
132static inline int port_No (struct Aurora_port const * port)
133{
134 return AURORA_PORT(port - aurora_port);
135}
136
137/* Get pointer to board from pointer to port */
138static inline struct Aurora_board * port_Board(struct Aurora_port const * port)
139{
140 return &aurora_board[AURORA_BOARD(port - aurora_port)];
141}
142
143/* Wait for Channel Command Register ready */
144static inline void aurora_wait_CCR(struct aurora_reg128 * r)
145{
146 unsigned long delay;
147
148#ifdef AURORA_DEBUG
149printk("aurora_wait_CCR\n");
150#endif
151 /* FIXME: need something more descriptive than 100000 :) */
152 for (delay = 100000; delay; delay--)
153 if (!sbus_readb(&r->r[CD180_CCR]))
154 return;
155 printk(KERN_DEBUG "aurora: Timeout waiting for CCR.\n");
156}
157
158/*
159 * aurora probe functions.
160 */
161
162/* Must be called with enabled interrupts */
163static inline void aurora_long_delay(unsigned long delay)
164{
165 unsigned long i;
166
167#ifdef AURORA_DEBUG
168 printk("aurora_long_delay: start\n");
169#endif
170 for (i = jiffies + delay; time_before(jiffies, i); ) ;
171#ifdef AURORA_DEBUG
172 printk("aurora_long_delay: end\n");
173#endif
174}
175
176/* Reset and setup CD180 chip */
177static int aurora_init_CD180(struct Aurora_board * bp, int chip)
178{
179 unsigned long flags;
180 int id;
181
182#ifdef AURORA_DEBUG
183 printk("aurora_init_CD180: start %d:%d\n",
184 board_No(bp), chip);
185#endif
186 save_flags(flags); cli();
187 sbus_writeb(0, &bp->r[chip]->r[CD180_CAR]);
188 sbus_writeb(0, &bp->r[chip]->r[CD180_GSVR]);
189
190 /* Wait for CCR ready */
191 aurora_wait_CCR(bp->r[chip]);
192
193 /* Reset CD180 chip */
194 sbus_writeb(CCR_HARDRESET, &bp->r[chip]->r[CD180_CCR]);
195 udelay(1);
196 sti();
197 id=1000;
198 while((--id) &&
199 (sbus_readb(&bp->r[chip]->r[CD180_GSVR])!=0xff))udelay(100);
200 if(!id) {
201 printk(KERN_ERR "aurora%d: Chip %d failed init.\n",
202 board_No(bp), chip);
203 restore_flags(flags);
204 return(-1);
205 }
206 cli();
207 sbus_writeb((board_No(bp)<<5)|((chip+1)<<3),
208 &bp->r[chip]->r[CD180_GSVR]); /* Set ID for this chip */
209 sbus_writeb(0x80|bp->ACK_MINT,
210 &bp->r[chip]->r[CD180_MSMR]); /* Prio for modem intr */
211 sbus_writeb(0x80|bp->ACK_TINT,
212 &bp->r[chip]->r[CD180_TSMR]); /* Prio for transmitter intr */
213 sbus_writeb(0x80|bp->ACK_RINT,
214 &bp->r[chip]->r[CD180_RSMR]); /* Prio for receiver intr */
215 /* Setting up prescaler. We need 4 tick per 1 ms */
216 sbus_writeb((bp->oscfreq/(1000000/AURORA_TPS)) >> 8,
217 &bp->r[chip]->r[CD180_PPRH]);
218 sbus_writeb((bp->oscfreq/(1000000/AURORA_TPS)) & 0xff,
219 &bp->r[chip]->r[CD180_PPRL]);
220
221 sbus_writeb(SRCR_AUTOPRI|SRCR_GLOBPRI,
222 &bp->r[chip]->r[CD180_SRCR]);
223
224 id = sbus_readb(&bp->r[chip]->r[CD180_GFRCR]);
225 printk(KERN_INFO "aurora%d: Chip %d id %02x: ",
226 board_No(bp), chip,id);
227 if(sbus_readb(&bp->r[chip]->r[CD180_SRCR]) & 128) {
228 switch (id) {
229 case 0x82:printk("CL-CD1864 rev A\n");break;
230 case 0x83:printk("CL-CD1865 rev A\n");break;
231 case 0x84:printk("CL-CD1865 rev B\n");break;
232 case 0x85:printk("CL-CD1865 rev C\n");break;
233 default:printk("Unknown.\n");
234 };
235 } else {
236 switch (id) {
237 case 0x81:printk("CL-CD180 rev B\n");break;
238 case 0x82:printk("CL-CD180 rev C\n");break;
239 default:printk("Unknown.\n");
240 };
241 }
242 restore_flags(flags);
243#ifdef AURORA_DEBUG
244 printk("aurora_init_CD180: end\n");
245#endif
246 return 0;
247}
248
249static int valid_irq(unsigned char irq)
250{
251int i;
252for(i=0;i<TYPE_1_IRQS;i++)
253 if (type_1_irq[i]==irq) return 1;
254return 0;
255}
256
257static irqreturn_t aurora_interrupt(int irq, void * dev_id);
258
259/* Main probing routine, also sets irq. */
260static int aurora_probe(void)
261{
262 struct sbus_bus *sbus;
263 struct sbus_dev *sdev;
264 int grrr;
265 char buf[30];
266 int bn = 0;
267 struct Aurora_board *bp;
268
269 for_each_sbus(sbus) {
270 for_each_sbusdev(sdev, sbus) {
271/* printk("Try: %x %s\n",sdev,sdev->prom_name);*/
272 if (!strcmp(sdev->prom_name, "sio16")) {
273#ifdef AURORA_DEBUG
274 printk(KERN_INFO "aurora: sio16 at %p\n",sdev);
275#endif
276 if((sdev->reg_addrs[0].reg_size!=1) &&
277 (sdev->reg_addrs[1].reg_size!=128) &&
278 (sdev->reg_addrs[2].reg_size!=128) &&
279 (sdev->reg_addrs[3].reg_size!=4)) {
280 printk(KERN_ERR "aurora%d: registers' sizes "
281 "do not match.\n", bn);
282 break;
283 }
284 bp = &aurora_board[bn];
285 bp->r0 = (struct aurora_reg1 *)
286 sbus_ioremap(&sdev->resource[0], 0,
287 sdev->reg_addrs[0].reg_size,
288 "sio16");
289 if (bp->r0 == NULL) {
290 printk(KERN_ERR "aurora%d: can't map "
291 "reg_addrs[0]\n", bn);
292 break;
293 }
294#ifdef AURORA_DEBUG
295 printk("Map reg 0: %p\n", bp->r0);
296#endif
297 bp->r[0] = (struct aurora_reg128 *)
298 sbus_ioremap(&sdev->resource[1], 0,
299 sdev->reg_addrs[1].reg_size,
300 "sio16");
301 if (bp->r[0] == NULL) {
302 printk(KERN_ERR "aurora%d: can't map "
303 "reg_addrs[1]\n", bn);
304 break;
305 }
306#ifdef AURORA_DEBUG
307 printk("Map reg 1: %p\n", bp->r[0]);
308#endif
309 bp->r[1] = (struct aurora_reg128 *)
310 sbus_ioremap(&sdev->resource[2], 0,
311 sdev->reg_addrs[2].reg_size,
312 "sio16");
313 if (bp->r[1] == NULL) {
314 printk(KERN_ERR "aurora%d: can't map "
315 "reg_addrs[2]\n", bn);
316 break;
317 }
318#ifdef AURORA_DEBUG
319 printk("Map reg 2: %p\n", bp->r[1]);
320#endif
321 bp->r3 = (struct aurora_reg4 *)
322 sbus_ioremap(&sdev->resource[3], 0,
323 sdev->reg_addrs[3].reg_size,
324 "sio16");
325 if (bp->r3 == NULL) {
326 printk(KERN_ERR "aurora%d: can't map "
327 "reg_addrs[3]\n", bn);
328 break;
329 }
330#ifdef AURORA_DEBUG
331 printk("Map reg 3: %p\n", bp->r3);
332#endif
333 /* Variables setup */
334 bp->flags = 0;
335#ifdef AURORA_DEBUG
336 grrr=prom_getint(sdev->prom_node,"intr");
337 printk("intr pri %d\n", grrr);
338#endif
339 if ((bp->irq=irqs[bn]) && valid_irq(bp->irq) &&
340 !request_irq(bp->irq|0x30, aurora_interrupt, IRQF_SHARED, "sio16", bp)) {
341 free_irq(bp->irq|0x30, bp);
342 } else
343 if ((bp->irq=prom_getint(sdev->prom_node, "bintr")) && valid_irq(bp->irq) &&
344 !request_irq(bp->irq|0x30, aurora_interrupt, IRQF_SHARED, "sio16", bp)) {
345 free_irq(bp->irq|0x30, bp);
346 } else
347 if ((bp->irq=prom_getint(sdev->prom_node, "intr")) && valid_irq(bp->irq) &&
348 !request_irq(bp->irq|0x30, aurora_interrupt, IRQF_SHARED, "sio16", bp)) {
349 free_irq(bp->irq|0x30, bp);
350 } else
351 for(grrr=0;grrr<TYPE_1_IRQS;grrr++) {
352 if ((bp->irq=type_1_irq[grrr])&&!request_irq(bp->irq|0x30, aurora_interrupt, IRQF_SHARED, "sio16", bp)) {
353 free_irq(bp->irq|0x30, bp);
354 break;
355 } else {
356 printk(KERN_ERR "aurora%d: Could not get an irq for this board !!!\n",bn);
357 bp->flags=0xff;
358 }
359 }
360 if(bp->flags==0xff)break;
361 printk(KERN_INFO "aurora%d: irq %d\n",bn,bp->irq&0x0f);
362 buf[0]=0;
363 grrr=prom_getproperty(sdev->prom_node,"dtr_rts",buf,sizeof(buf));
364 if(!strcmp(buf,"swapped")){
365 printk(KERN_INFO "aurora%d: Swapped DTR and RTS\n",bn);
366 bp->DTR=MSVR_RTS;
367 bp->RTS=MSVR_DTR;
368 bp->MSVDTR=CD180_MSVRTS;
369 bp->MSVRTS=CD180_MSVDTR;
370 bp->flags|=AURORA_BOARD_DTR_FLOW_OK;
371 }else{
372 #ifdef AURORA_FORCE_DTR_FLOW
373 printk(KERN_INFO "aurora%d: Forcing swapped DTR-RTS\n",bn);
374 bp->DTR=MSVR_RTS;
375 bp->RTS=MSVR_DTR;
376 bp->MSVDTR=CD180_MSVRTS;
377 bp->MSVRTS=CD180_MSVDTR;
378 bp->flags|=AURORA_BOARD_DTR_FLOW_OK;
379 #else
380 printk(KERN_INFO "aurora%d: Normal DTR and RTS\n",bn);
381 bp->DTR=MSVR_DTR;
382 bp->RTS=MSVR_RTS;
383 bp->MSVDTR=CD180_MSVDTR;
384 bp->MSVRTS=CD180_MSVRTS;
385 #endif
386 }
387 bp->oscfreq=prom_getint(sdev->prom_node,"clk")*100;
388 printk(KERN_INFO "aurora%d: Oscillator: %d Hz\n",bn,bp->oscfreq);
389 grrr=prom_getproperty(sdev->prom_node,"chip",buf,sizeof(buf));
390 printk(KERN_INFO "aurora%d: Chips: %s\n",bn,buf);
391 grrr=prom_getproperty(sdev->prom_node,"manu",buf,sizeof(buf));
392 printk(KERN_INFO "aurora%d: Manufacturer: %s\n",bn,buf);
393 grrr=prom_getproperty(sdev->prom_node,"model",buf,sizeof(buf));
394 printk(KERN_INFO "aurora%d: Model: %s\n",bn,buf);
395 grrr=prom_getproperty(sdev->prom_node,"rev",buf,sizeof(buf));
396 printk(KERN_INFO "aurora%d: Revision: %s\n",bn,buf);
397 grrr=prom_getproperty(sdev->prom_node,"mode",buf,sizeof(buf));
398 printk(KERN_INFO "aurora%d: Mode: %s\n",bn,buf);
399 #ifdef MODULE
400 bp->count=0;
401 #endif
402 bp->flags = AURORA_BOARD_PRESENT;
403 /* hardware ack */
404 bp->ACK_MINT=1;
405 bp->ACK_TINT=2;
406 bp->ACK_RINT=3;
407 bn++;
408 }
409 }
410 }
411 return bn;
412}
413
414static void aurora_release_io_range(struct Aurora_board *bp)
415{
416 sbus_iounmap((unsigned long)bp->r0, 1);
417 sbus_iounmap((unsigned long)bp->r[0], 128);
418 sbus_iounmap((unsigned long)bp->r[1], 128);
419 sbus_iounmap((unsigned long)bp->r3, 4);
420}
421
422static inline void aurora_mark_event(struct Aurora_port * port, int event)
423{
424#ifdef AURORA_DEBUG
425 printk("aurora_mark_event: start\n");
426#endif
427 set_bit(event, &port->event);
428 queue_task(&port->tqueue, &tq_aurora);
429 mark_bh(AURORA_BH);
430#ifdef AURORA_DEBUG
431 printk("aurora_mark_event: end\n");
432#endif
433}
434
435static __inline__ struct Aurora_port * aurora_get_port(struct Aurora_board const * bp,
436 int chip,
437 unsigned char const *what)
438{
439 unsigned char channel;
440 struct Aurora_port * port;
441
442 channel = ((chip << 3) |
443 ((sbus_readb(&bp->r[chip]->r[CD180_GSCR]) & GSCR_CHAN) >> GSCR_CHAN_OFF));
444 port = &aurora_port[board_No(bp) * AURORA_NPORT * AURORA_NCD180 + channel];
445 if (port->flags & ASYNC_INITIALIZED)
446 return port;
447
448 printk(KERN_DEBUG "aurora%d: %s interrupt from invalid port %d\n",
449 board_No(bp), what, channel);
450 return NULL;
451}
452
453static void aurora_receive_exc(struct Aurora_board const * bp, int chip)
454{
455 struct Aurora_port *port;
456 struct tty_struct *tty;
457 unsigned char status;
458 unsigned char ch;
459
460 if (!(port = aurora_get_port(bp, chip, "Receive_x")))
461 return;
462
463 tty = port->tty;
464 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
465#ifdef AURORA_INTNORM
466 printk("aurora%d: port %d: Working around flip buffer overflow.\n",
467 board_No(bp), port_No(port));
468#endif
469 return;
470 }
471
472#ifdef AURORA_REPORT_OVERRUN
473 status = sbus_readb(&bp->r[chip]->r[CD180_RCSR]);
474 if (status & RCSR_OE) {
475 port->overrun++;
476#if 1
477 printk("aurora%d: port %d: Overrun. Total %ld overruns.\n",
478 board_No(bp), port_No(port), port->overrun);
479#endif
480 }
481 status &= port->mark_mask;
482#else
483 status = sbus_readb(&bp->r[chip]->r[CD180_RCSR]) & port->mark_mask;
484#endif
485 ch = sbus_readb(&bp->r[chip]->r[CD180_RDR]);
486 if (!status)
487 return;
488
489 if (status & RCSR_TOUT) {
490/* printk("aurora%d: port %d: Receiver timeout. Hardware problems ?\n",
491 board_No(bp), port_No(port));*/
492 return;
493
494 } else if (status & RCSR_BREAK) {
495 printk(KERN_DEBUG "aurora%d: port %d: Handling break...\n",
496 board_No(bp), port_No(port));
497 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
498 if (port->flags & ASYNC_SAK)
499 do_SAK(tty);
500
501 } else if (status & RCSR_PE)
502 *tty->flip.flag_buf_ptr++ = TTY_PARITY;
503
504 else if (status & RCSR_FE)
505 *tty->flip.flag_buf_ptr++ = TTY_FRAME;
506
507 else if (status & RCSR_OE)
508 *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
509
510 else
511 *tty->flip.flag_buf_ptr++ = 0;
512
513 *tty->flip.char_buf_ptr++ = ch;
514 tty->flip.count++;
515 queue_task(&tty->flip.tqueue, &tq_timer);
516}
517
518static void aurora_receive(struct Aurora_board const * bp, int chip)
519{
520 struct Aurora_port *port;
521 struct tty_struct *tty;
522 unsigned char count,cnt;
523
524 if (!(port = aurora_get_port(bp, chip, "Receive")))
525 return;
526
527 tty = port->tty;
528
529 count = sbus_readb(&bp->r[chip]->r[CD180_RDCR]);
530
531#ifdef AURORA_REPORT_FIFO
532 port->hits[count > 8 ? 9 : count]++;
533#endif
534
535 while (count--) {
536 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
537#ifdef AURORA_INTNORM
538 printk("aurora%d: port %d: Working around flip buffer overflow.\n",
539 board_No(bp), port_No(port));
540#endif
541 break;
542 }
543 cnt = sbus_readb(&bp->r[chip]->r[CD180_RDR]);
544 *tty->flip.char_buf_ptr++ = cnt;
545 *tty->flip.flag_buf_ptr++ = 0;
546 tty->flip.count++;
547 }
548 queue_task(&tty->flip.tqueue, &tq_timer);
549}
550
551static void aurora_transmit(struct Aurora_board const * bp, int chip)
552{
553 struct Aurora_port *port;
554 struct tty_struct *tty;
555 unsigned char count;
556
557 if (!(port = aurora_get_port(bp, chip, "Transmit")))
558 return;
559
560 tty = port->tty;
561
562 if (port->SRER & SRER_TXEMPTY) {
563 /* FIFO drained */
564 sbus_writeb(port_No(port) & 7,
565 &bp->r[chip]->r[CD180_CAR]);
566 udelay(1);
567 port->SRER &= ~SRER_TXEMPTY;
568 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
569 return;
570 }
571
572 if ((port->xmit_cnt <= 0 && !port->break_length)
573 || tty->stopped || tty->hw_stopped) {
574 sbus_writeb(port_No(port) & 7,
575 &bp->r[chip]->r[CD180_CAR]);
576 udelay(1);
577 port->SRER &= ~SRER_TXRDY;
578 sbus_writeb(port->SRER,
579 &bp->r[chip]->r[CD180_SRER]);
580 return;
581 }
582
583 if (port->break_length) {
584 if (port->break_length > 0) {
585 if (port->COR2 & COR2_ETC) {
586 sbus_writeb(CD180_C_ESC,
587 &bp->r[chip]->r[CD180_TDR]);
588 sbus_writeb(CD180_C_SBRK,
589 &bp->r[chip]->r[CD180_TDR]);
590 port->COR2 &= ~COR2_ETC;
591 }
592 count = min(port->break_length, 0xff);
593 sbus_writeb(CD180_C_ESC,
594 &bp->r[chip]->r[CD180_TDR]);
595 sbus_writeb(CD180_C_DELAY,
596 &bp->r[chip]->r[CD180_TDR]);
597 sbus_writeb(count,
598 &bp->r[chip]->r[CD180_TDR]);
599 if (!(port->break_length -= count))
600 port->break_length--;
601 } else {
602 sbus_writeb(CD180_C_ESC,
603 &bp->r[chip]->r[CD180_TDR]);
604 sbus_writeb(CD180_C_EBRK,
605 &bp->r[chip]->r[CD180_TDR]);
606 sbus_writeb(port->COR2,
607 &bp->r[chip]->r[CD180_COR2]);
608 aurora_wait_CCR(bp->r[chip]);
609 sbus_writeb(CCR_CORCHG2,
610 &bp->r[chip]->r[CD180_CCR]);
611 port->break_length = 0;
612 }
613 return;
614 }
615
616 count = CD180_NFIFO;
617 do {
618 u8 byte = port->xmit_buf[port->xmit_tail++];
619
620 sbus_writeb(byte, &bp->r[chip]->r[CD180_TDR]);
621 port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1);
622 if (--port->xmit_cnt <= 0)
623 break;
624 } while (--count > 0);
625
626 if (port->xmit_cnt <= 0) {
627 sbus_writeb(port_No(port) & 7,
628 &bp->r[chip]->r[CD180_CAR]);
629 udelay(1);
630 port->SRER &= ~SRER_TXRDY;
631 sbus_writeb(port->SRER,
632 &bp->r[chip]->r[CD180_SRER]);
633 }
634 if (port->xmit_cnt <= port->wakeup_chars)
635 aurora_mark_event(port, RS_EVENT_WRITE_WAKEUP);
636}
637
638static void aurora_check_modem(struct Aurora_board const * bp, int chip)
639{
640 struct Aurora_port *port;
641 struct tty_struct *tty;
642 unsigned char mcr;
643
644 if (!(port = aurora_get_port(bp, chip, "Modem")))
645 return;
646
647 tty = port->tty;
648
649 mcr = sbus_readb(&bp->r[chip]->r[CD180_MCR]);
650 if (mcr & MCR_CDCHG) {
651 if (sbus_readb(&bp->r[chip]->r[CD180_MSVR]) & MSVR_CD)
652 wake_up_interruptible(&port->open_wait);
653 else
654 schedule_task(&port->tqueue_hangup);
655 }
656
657/* We don't have such things yet. My aurora board has DTR and RTS swapped, but that doesn't count in this driver. Let's hope
658 * Aurora didn't made any boards with CTS or DSR broken...
659 */
660/* #ifdef AURORA_BRAIN_DAMAGED_CTS
661 if (mcr & MCR_CTSCHG) {
662 if (aurora_in(bp, CD180_MSVR) & MSVR_CTS) {
663 tty->hw_stopped = 0;
664 port->SRER |= SRER_TXRDY;
665 if (port->xmit_cnt <= port->wakeup_chars)
666 aurora_mark_event(port, RS_EVENT_WRITE_WAKEUP);
667 } else {
668 tty->hw_stopped = 1;
669 port->SRER &= ~SRER_TXRDY;
670 }
671 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
672 }
673 if (mcr & MCR_DSRCHG) {
674 if (aurora_in(bp, CD180_MSVR) & MSVR_DSR) {
675 tty->hw_stopped = 0;
676 port->SRER |= SRER_TXRDY;
677 if (port->xmit_cnt <= port->wakeup_chars)
678 aurora_mark_event(port, RS_EVENT_WRITE_WAKEUP);
679 } else {
680 tty->hw_stopped = 1;
681 port->SRER &= ~SRER_TXRDY;
682 }
683 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
684 }
685#endif AURORA_BRAIN_DAMAGED_CTS */
686
687 /* Clear change bits */
688 sbus_writeb(0, &bp->r[chip]->r[CD180_MCR]);
689}
690
691/* The main interrupt processing routine */
692static irqreturn_t aurora_interrupt(int irq, void * dev_id)
693{
694 unsigned char status;
695 unsigned char ack,chip/*,chip_id*/;
696 struct Aurora_board * bp = (struct Aurora_board *) dev_id;
697 unsigned long loop = 0;
698
699#ifdef AURORA_INT_DEBUG
700 printk("IRQ%d %d\n",irq,++irqhit);
701#ifdef AURORA_FLOODPRO
702 if (irqhit>=AURORA_FLOODPRO)
703 sbus_writeb(8, &bp->r0->r);
704#endif
705#endif
706
707/* old bp = IRQ_to_board[irq&0x0f];*/
708
709 if (!bp || !(bp->flags & AURORA_BOARD_ACTIVE))
710 return IRQ_NONE;
711
712/* The while() below takes care of this.
713 status = sbus_readb(&bp->r[0]->r[CD180_SRSR]);
714#ifdef AURORA_INT_DEBUG
715 printk("mumu: %02x\n", status);
716#endif
717 if (!(status&SRSR_ANYINT))
718 return IRQ_NONE; * Nobody has anything to say, so exit *
719*/
720 while ((loop++ < 48) &&
721 (status = sbus_readb(&bp->r[0]->r[CD180_SRSR]) & SRSR_ANYINT)){
722#ifdef AURORA_INT_DEBUG
723 printk("SRSR: %02x\n", status);
724#endif
725 if (status & SRSR_REXT) {
726 ack = sbus_readb(&bp->r3->r[bp->ACK_RINT]);
727#ifdef AURORA_INT_DEBUG
728 printk("R-ACK %02x\n", ack);
729#endif
730 if ((ack >> 5) == board_No(bp)) {
731 if ((chip=((ack>>3)&3)-1) < AURORA_NCD180) {
732 if ((ack&GSVR_ITMASK)==GSVR_IT_RGD) {
733 aurora_receive(bp,chip);
734 sbus_writeb(0,
735 &bp->r[chip]->r[CD180_EOSRR]);
736 } else if ((ack & GSVR_ITMASK) == GSVR_IT_REXC) {
737 aurora_receive_exc(bp,chip);
738 sbus_writeb(0,
739 &bp->r[chip]->r[CD180_EOSRR]);
740 }
741 }
742 }
743 } else if (status & SRSR_TEXT) {
744 ack = sbus_readb(&bp->r3->r[bp->ACK_TINT]);
745#ifdef AURORA_INT_DEBUG
746 printk("T-ACK %02x\n", ack);
747#endif
748 if ((ack >> 5) == board_No(bp)) {
749 if ((chip=((ack>>3)&3)-1) < AURORA_NCD180) {
750 if ((ack&GSVR_ITMASK)==GSVR_IT_TX) {
751 aurora_transmit(bp,chip);
752 sbus_writeb(0,
753 &bp->r[chip]->r[CD180_EOSRR]);
754 }
755 }
756 }
757 } else if (status & SRSR_MEXT) {
758 ack = sbus_readb(&bp->r3->r[bp->ACK_MINT]);
759#ifdef AURORA_INT_DEBUG
760 printk("M-ACK %02x\n", ack);
761#endif
762 if ((ack >> 5) == board_No(bp)) {
763 if ((chip = ((ack>>3)&3)-1) < AURORA_NCD180) {
764 if ((ack&GSVR_ITMASK)==GSVR_IT_MDM) {
765 aurora_check_modem(bp,chip);
766 sbus_writeb(0,
767 &bp->r[chip]->r[CD180_EOSRR]);
768 }
769 }
770 }
771 }
772 }
773/* I guess this faster code can be used with CD1865, using AUROPRI and GLOBPRI. */
774#if 0
775 while ((loop++ < 48)&&(status=bp->r[0]->r[CD180_SRSR]&SRSR_ANYINT)){
776#ifdef AURORA_INT_DEBUG
777 printk("SRSR: %02x\n",status);
778#endif
779 ack = sbus_readb(&bp->r3->r[0]);
780#ifdef AURORA_INT_DEBUG
781 printk("ACK: %02x\n",ack);
782#endif
783 if ((ack>>5)==board_No(bp)) {
784 if ((chip=((ack>>3)&3)-1) < AURORA_NCD180) {
785 ack&=GSVR_ITMASK;
786 if (ack==GSVR_IT_RGD) {
787 aurora_receive(bp,chip);
788 sbus_writeb(0,
789 &bp->r[chip]->r[CD180_EOSRR]);
790 } else if (ack==GSVR_IT_REXC) {
791 aurora_receive_exc(bp,chip);
792 sbus_writeb(0,
793 &bp->r[chip]->r[CD180_EOSRR]);
794 } else if (ack==GSVR_IT_TX) {
795 aurora_transmit(bp,chip);
796 sbus_writeb(0,
797 &bp->r[chip]->r[CD180_EOSRR]);
798 } else if (ack==GSVR_IT_MDM) {
799 aurora_check_modem(bp,chip);
800 sbus_writeb(0,
801 &bp->r[chip]->r[CD180_EOSRR]);
802 }
803 }
804 }
805 }
806#endif
807
808/* This is the old handling routine, used in riscom8 for only one CD180. I keep it here for reference. */
809#if 0
810 for(chip=0;chip<AURORA_NCD180;chip++){
811 chip_id=(board_No(bp)<<5)|((chip+1)<<3);
812 loop=0;
813 while ((loop++ < 1) &&
814 ((status = sbus_readb(&bp->r[chip]->r[CD180_SRSR])) &
815 (SRSR_TEXT | SRSR_MEXT | SRSR_REXT))) {
816
817 if (status & SRSR_REXT) {
818 ack = sbus_readb(&bp->r3->r[bp->ACK_RINT]);
819 if (ack == (chip_id | GSVR_IT_RGD)) {
820#ifdef AURORA_INTMSG
821 printk("RX ACK\n");
822#endif
823 aurora_receive(bp,chip);
824 } else if (ack == (chip_id | GSVR_IT_REXC)) {
825#ifdef AURORA_INTMSG
826 printk("RXC ACK\n");
827#endif
828 aurora_receive_exc(bp,chip);
829 } else {
830#ifdef AURORA_INTNORM
831 printk("aurora%d-%d: Bad receive ack 0x%02x.\n",
832 board_No(bp), chip, ack);
833#endif
834 }
835 } else if (status & SRSR_TEXT) {
836 ack = sbus_readb(&bp->r3->r[bp->ACK_TINT]);
837 if (ack == (chip_id | GSVR_IT_TX)){
838#ifdef AURORA_INTMSG
839 printk("TX ACK\n");
840#endif
841 aurora_transmit(bp,chip);
842 } else {
843#ifdef AURORA_INTNORM
844 printk("aurora%d-%d: Bad transmit ack 0x%02x.\n",
845 board_No(bp), chip, ack);
846#endif
847 }
848 } else if (status & SRSR_MEXT) {
849 ack = sbus_readb(&bp->r3->r[bp->ACK_MINT]);
850 if (ack == (chip_id | GSVR_IT_MDM)){
851#ifdef AURORA_INTMSG
852 printk("MDM ACK\n");
853#endif
854 aurora_check_modem(bp,chip);
855 } else {
856#ifdef AURORA_INTNORM
857 printk("aurora%d-%d: Bad modem ack 0x%02x.\n",
858 board_No(bp), chip, ack);
859#endif
860 }
861 }
862 sbus_writeb(0, &bp->r[chip]->r[CD180_EOSRR]);
863 }
864 }
865#endif
866
867 return IRQ_HANDLED;
868}
869
870#ifdef AURORA_INT_DEBUG
871static void aurora_timer (unsigned long ignored);
872
873static DEFINE_TIMER(aurora_poll_timer, aurora_timer, 0, 0);
874
875static void
876aurora_timer (unsigned long ignored)
877{
878 unsigned long flags;
879 int i;
880
881 save_flags(flags); cli();
882
883 printk("SRSR: %02x,%02x - ",
884 sbus_readb(&aurora_board[0].r[0]->r[CD180_SRSR]),
885 sbus_readb(&aurora_board[0].r[1]->r[CD180_SRSR]));
886 for (i = 0; i < 4; i++) {
887 udelay(1);
888 printk("%02x ",
889 sbus_readb(&aurora_board[0].r3->r[i]));
890 }
891 printk("\n");
892
893 aurora_poll_timer.expires = jiffies + 300;
894 add_timer (&aurora_poll_timer);
895
896 restore_flags(flags);
897}
898#endif
899
900/*
901 * Routines for open & close processing.
902 */
903
904/* Called with disabled interrupts */
905static int aurora_setup_board(struct Aurora_board * bp)
906{
907 int error;
908
909#ifdef AURORA_ALLIRQ
910 int i;
911 for (i = 0; i < AURORA_ALLIRQ; i++) {
912 error = request_irq(allirq[i]|0x30, aurora_interrupt, IRQF_SHARED,
913 "sio16", bp);
914 if (error)
915 printk(KERN_ERR "IRQ%d request error %d\n",
916 allirq[i], error);
917 }
918#else
919 error = request_irq(bp->irq|0x30, aurora_interrupt, IRQF_SHARED,
920 "sio16", bp);
921 if (error) {
922 printk(KERN_ERR "IRQ request error %d\n", error);
923 return error;
924 }
925#endif
926 /* Board reset */
927 sbus_writeb(0, &bp->r0->r);
928 udelay(1);
929 if (bp->flags & AURORA_BOARD_TYPE_2) {
930 /* unknown yet */
931 } else {
932 sbus_writeb((AURORA_CFG_ENABLE_IO | AURORA_CFG_ENABLE_IRQ |
933 (((bp->irq)&0x0f)>>2)),
934 &bp->r0->r);
935 }
936 udelay(10000);
937
938 if (aurora_init_CD180(bp,0))error=1;error=0;
939 if (aurora_init_CD180(bp,1))error++;
940 if (error == AURORA_NCD180) {
941 printk(KERN_ERR "Both chips failed initialisation.\n");
942 return -EIO;
943 }
944
945#ifdef AURORA_INT_DEBUG
946 aurora_poll_timer.expires= jiffies + 1;
947 add_timer(&aurora_poll_timer);
948#endif
949#ifdef AURORA_DEBUG
950 printk("aurora_setup_board: end\n");
951#endif
952 return 0;
953}
954
955/* Called with disabled interrupts */
956static void aurora_shutdown_board(struct Aurora_board *bp)
957{
958 int i;
959
960#ifdef AURORA_DEBUG
961 printk("aurora_shutdown_board: start\n");
962#endif
963
964#ifdef AURORA_INT_DEBUG
965 del_timer(&aurora_poll_timer);
966#endif
967
968#ifdef AURORA_ALLIRQ
969 for(i=0;i<AURORA_ALLIRQ;i++){
970 free_irq(allirq[i]|0x30, bp);
971/* IRQ_to_board[allirq[i]&0xf] = NULL;*/
972 }
973#else
974 free_irq(bp->irq|0x30, bp);
975/* IRQ_to_board[bp->irq&0xf] = NULL;*/
976#endif
977 /* Drop all DTR's */
978 for(i=0;i<16;i++){
979 sbus_writeb(i & 7, &bp->r[i>>3]->r[CD180_CAR]);
980 udelay(1);
981 sbus_writeb(0, &bp->r[i>>3]->r[CD180_MSVR]);
982 udelay(1);
983 }
984 /* Board shutdown */
985 sbus_writeb(0, &bp->r0->r);
986
987#ifdef AURORA_DEBUG
988 printk("aurora_shutdown_board: end\n");
989#endif
990}
991
992/* Setting up port characteristics.
993 * Must be called with disabled interrupts
994 */
995static void aurora_change_speed(struct Aurora_board *bp, struct Aurora_port *port)
996{
997 struct tty_struct *tty;
998 unsigned long baud;
999 long tmp;
1000 unsigned char cor1 = 0, cor3 = 0;
1001 unsigned char mcor1 = 0, mcor2 = 0,chip;
1002
1003#ifdef AURORA_DEBUG
1004 printk("aurora_change_speed: start\n");
1005#endif
1006 if (!(tty = port->tty) || !tty->termios)
1007 return;
1008
1009 chip = AURORA_CD180(port_No(port));
1010
1011 port->SRER = 0;
1012 port->COR2 = 0;
1013 port->MSVR = MSVR_RTS|MSVR_DTR;
1014
1015 baud = tty_get_baud_rate(tty);
1016
1017 /* Select port on the board */
1018 sbus_writeb(port_No(port) & 7,
1019 &bp->r[chip]->r[CD180_CAR]);
1020 udelay(1);
1021
1022 if (!baud) {
1023 /* Drop DTR & exit */
1024 port->MSVR &= ~(bp->DTR|bp->RTS);
1025 sbus_writeb(port->MSVR,
1026 &bp->r[chip]->r[CD180_MSVR]);
1027 return;
1028 } else {
1029 /* Set DTR on */
1030 port->MSVR |= bp->DTR;
1031 sbus_writeb(port->MSVR,
1032 &bp->r[chip]->r[CD180_MSVR]);
1033 }
1034
1035 /* Now we must calculate some speed dependent things. */
1036
1037 /* Set baud rate for port. */
1038 tmp = (((bp->oscfreq + baud/2) / baud +
1039 CD180_TPC/2) / CD180_TPC);
1040
1041/* tmp = (bp->oscfreq/7)/baud;
1042 if((tmp%10)>4)tmp=tmp/10+1;else tmp=tmp/10;*/
1043/* printk("Prescaler period: %d\n",tmp);*/
1044
1045 sbus_writeb((tmp >> 8) & 0xff,
1046 &bp->r[chip]->r[CD180_RBPRH]);
1047 sbus_writeb((tmp >> 8) & 0xff,
1048 &bp->r[chip]->r[CD180_TBPRH]);
1049 sbus_writeb(tmp & 0xff, &bp->r[chip]->r[CD180_RBPRL]);
1050 sbus_writeb(tmp & 0xff, &bp->r[chip]->r[CD180_TBPRL]);
1051
1052 baud = (baud + 5) / 10; /* Estimated CPS */
1053
1054 /* Two timer ticks seems enough to wakeup something like SLIP driver */
1055 tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO;
1056 port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
1057 SERIAL_XMIT_SIZE - 1 : tmp);
1058
1059 /* Receiver timeout will be transmission time for 1.5 chars */
1060 tmp = (AURORA_TPS + AURORA_TPS/2 + baud/2) / baud;
1061 tmp = (tmp > 0xff) ? 0xff : tmp;
1062 sbus_writeb(tmp, &bp->r[chip]->r[CD180_RTPR]);
1063
1064 switch (C_CSIZE(tty)) {
1065 case CS5:
1066 cor1 |= COR1_5BITS;
1067 break;
1068 case CS6:
1069 cor1 |= COR1_6BITS;
1070 break;
1071 case CS7:
1072 cor1 |= COR1_7BITS;
1073 break;
1074 case CS8:
1075 cor1 |= COR1_8BITS;
1076 break;
1077 }
1078
1079 if (C_CSTOPB(tty))
1080 cor1 |= COR1_2SB;
1081
1082 cor1 |= COR1_IGNORE;
1083 if (C_PARENB(tty)) {
1084 cor1 |= COR1_NORMPAR;
1085 if (C_PARODD(tty))
1086 cor1 |= COR1_ODDP;
1087 if (I_INPCK(tty))
1088 cor1 &= ~COR1_IGNORE;
1089 }
1090 /* Set marking of some errors */
1091 port->mark_mask = RCSR_OE | RCSR_TOUT;
1092 if (I_INPCK(tty))
1093 port->mark_mask |= RCSR_FE | RCSR_PE;
1094 if (I_BRKINT(tty) || I_PARMRK(tty))
1095 port->mark_mask |= RCSR_BREAK;
1096 if (I_IGNPAR(tty))
1097 port->mark_mask &= ~(RCSR_FE | RCSR_PE);
1098 if (I_IGNBRK(tty)) {
1099 port->mark_mask &= ~RCSR_BREAK;
1100 if (I_IGNPAR(tty))
1101 /* Real raw mode. Ignore all */
1102 port->mark_mask &= ~RCSR_OE;
1103 }
1104 /* Enable Hardware Flow Control */
1105 if (C_CRTSCTS(tty)) {
1106/*#ifdef AURORA_BRAIN_DAMAGED_CTS
1107 port->SRER |= SRER_DSR | SRER_CTS;
1108 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
1109 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
1110 tty->hw_stopped = !(aurora_in(bp, CD180_MSVR) & (MSVR_CTS|MSVR_DSR));
1111#else*/
1112 port->COR2 |= COR2_CTSAE;
1113/*#endif*/
1114 if (bp->flags&AURORA_BOARD_DTR_FLOW_OK) {
1115 mcor1 |= AURORA_RXTH;
1116 }
1117 }
1118 /* Enable Software Flow Control. FIXME: I'm not sure about this */
1119 /* Some people reported that it works, but I still doubt */
1120 if (I_IXON(tty)) {
1121 port->COR2 |= COR2_TXIBE;
1122 cor3 |= (COR3_FCT | COR3_SCDE);
1123 if (I_IXANY(tty))
1124 port->COR2 |= COR2_IXM;
1125 sbus_writeb(START_CHAR(tty),
1126 &bp->r[chip]->r[CD180_SCHR1]);
1127 sbus_writeb(STOP_CHAR(tty),
1128 &bp->r[chip]->r[CD180_SCHR2]);
1129 sbus_writeb(START_CHAR(tty),
1130 &bp->r[chip]->r[CD180_SCHR3]);
1131 sbus_writeb(STOP_CHAR(tty),
1132 &bp->r[chip]->r[CD180_SCHR4]);
1133 }
1134 if (!C_CLOCAL(tty)) {
1135 /* Enable CD check */
1136 port->SRER |= SRER_CD;
1137 mcor1 |= MCOR1_CDZD;
1138 mcor2 |= MCOR2_CDOD;
1139 }
1140
1141 if (C_CREAD(tty))
1142 /* Enable receiver */
1143 port->SRER |= SRER_RXD;
1144
1145 /* Set input FIFO size (1-8 bytes) */
1146 cor3 |= AURORA_RXFIFO;
1147 /* Setting up CD180 channel registers */
1148 sbus_writeb(cor1, &bp->r[chip]->r[CD180_COR1]);
1149 sbus_writeb(port->COR2, &bp->r[chip]->r[CD180_COR2]);
1150 sbus_writeb(cor3, &bp->r[chip]->r[CD180_COR3]);
1151 /* Make CD180 know about registers change */
1152 aurora_wait_CCR(bp->r[chip]);
1153 sbus_writeb(CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3,
1154 &bp->r[chip]->r[CD180_CCR]);
1155 /* Setting up modem option registers */
1156 sbus_writeb(mcor1, &bp->r[chip]->r[CD180_MCOR1]);
1157 sbus_writeb(mcor2, &bp->r[chip]->r[CD180_MCOR2]);
1158 /* Enable CD180 transmitter & receiver */
1159 aurora_wait_CCR(bp->r[chip]);
1160 sbus_writeb(CCR_TXEN | CCR_RXEN, &bp->r[chip]->r[CD180_CCR]);
1161 /* Enable interrupts */
1162 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
1163 /* And finally set RTS on */
1164 sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
1165#ifdef AURORA_DEBUG
1166 printk("aurora_change_speed: end\n");
1167#endif
1168}
1169
1170/* Must be called with interrupts enabled */
1171static int aurora_setup_port(struct Aurora_board *bp, struct Aurora_port *port)
1172{
1173 unsigned long flags;
1174
1175#ifdef AURORA_DEBUG
1176 printk("aurora_setup_port: start %d\n",port_No(port));
1177#endif
1178 if (port->flags & ASYNC_INITIALIZED)
1179 return 0;
1180
1181 if (!port->xmit_buf) {
1182 /* We may sleep in get_zeroed_page() */
1183 unsigned long tmp;
1184
1185 if (!(tmp = get_zeroed_page(GFP_KERNEL)))
1186 return -ENOMEM;
1187
1188 if (port->xmit_buf) {
1189 free_page(tmp);
1190 return -ERESTARTSYS;
1191 }
1192 port->xmit_buf = (unsigned char *) tmp;
1193 }
1194
1195 save_flags(flags); cli();
1196
1197 if (port->tty)
1198 clear_bit(TTY_IO_ERROR, &port->tty->flags);
1199
1200#ifdef MODULE
1201 if ((port->count == 1) && ((++bp->count) == 1))
1202 bp->flags |= AURORA_BOARD_ACTIVE;
1203#endif
1204
1205 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1206 aurora_change_speed(bp, port);
1207 port->flags |= ASYNC_INITIALIZED;
1208
1209 restore_flags(flags);
1210#ifdef AURORA_DEBUG
1211 printk("aurora_setup_port: end\n");
1212#endif
1213 return 0;
1214}
1215
1216/* Must be called with interrupts disabled */
1217static void aurora_shutdown_port(struct Aurora_board *bp, struct Aurora_port *port)
1218{
1219 struct tty_struct *tty;
1220 unsigned char chip;
1221
1222#ifdef AURORA_DEBUG
1223 printk("aurora_shutdown_port: start\n");
1224#endif
1225 if (!(port->flags & ASYNC_INITIALIZED))
1226 return;
1227
1228 chip = AURORA_CD180(port_No(port));
1229
1230#ifdef AURORA_REPORT_OVERRUN
1231 printk("aurora%d: port %d: Total %ld overruns were detected.\n",
1232 board_No(bp), port_No(port), port->overrun);
1233#endif
1234#ifdef AURORA_REPORT_FIFO
1235 {
1236 int i;
1237
1238 printk("aurora%d: port %d: FIFO hits [ ",
1239 board_No(bp), port_No(port));
1240 for (i = 0; i < 10; i++) {
1241 printk("%ld ", port->hits[i]);
1242 }
1243 printk("].\n");
1244 }
1245#endif
1246 if (port->xmit_buf) {
1247 free_page((unsigned long) port->xmit_buf);
1248 port->xmit_buf = NULL;
1249 }
1250
1251 if (!(tty = port->tty) || C_HUPCL(tty)) {
1252 /* Drop DTR */
1253 port->MSVR &= ~(bp->DTR|bp->RTS);
1254 sbus_writeb(port->MSVR,
1255 &bp->r[chip]->r[CD180_MSVR]);
1256 }
1257
1258 /* Select port */
1259 sbus_writeb(port_No(port) & 7,
1260 &bp->r[chip]->r[CD180_CAR]);
1261 udelay(1);
1262
1263 /* Reset port */
1264 aurora_wait_CCR(bp->r[chip]);
1265 sbus_writeb(CCR_SOFTRESET, &bp->r[chip]->r[CD180_CCR]);
1266
1267 /* Disable all interrupts from this port */
1268 port->SRER = 0;
1269 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
1270
1271 if (tty)
1272 set_bit(TTY_IO_ERROR, &tty->flags);
1273 port->flags &= ~ASYNC_INITIALIZED;
1274
1275#ifdef MODULE
1276 if (--bp->count < 0) {
1277 printk(KERN_DEBUG "aurora%d: aurora_shutdown_port: "
1278 "bad board count: %d\n",
1279 board_No(bp), bp->count);
1280 bp->count = 0;
1281 }
1282
1283 if (!bp->count)
1284 bp->flags &= ~AURORA_BOARD_ACTIVE;
1285#endif
1286
1287#ifdef AURORA_DEBUG
1288 printk("aurora_shutdown_port: end\n");
1289#endif
1290}
1291
1292
1293static int block_til_ready(struct tty_struct *tty, struct file * filp,
1294 struct Aurora_port *port)
1295{
1296 DECLARE_WAITQUEUE(wait, current);
1297 struct Aurora_board *bp = port_Board(port);
1298 int retval;
1299 int do_clocal = 0;
1300 int CD;
1301 unsigned char chip;
1302
1303#ifdef AURORA_DEBUG
1304 printk("block_til_ready: start\n");
1305#endif
1306 chip = AURORA_CD180(port_No(port));
1307
1308 /* If the device is in the middle of being closed, then block
1309 * until it's done, and then try again.
1310 */
1311 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
1312 interruptible_sleep_on(&port->close_wait);
1313 if (port->flags & ASYNC_HUP_NOTIFY)
1314 return -EAGAIN;
1315 else
1316 return -ERESTARTSYS;
1317 }
1318
1319 /* If non-blocking mode is set, or the port is not enabled,
1320 * then make the check up front and then exit.
1321 */
1322 if ((filp->f_flags & O_NONBLOCK) ||
1323 (tty->flags & (1 << TTY_IO_ERROR))) {
1324 port->flags |= ASYNC_NORMAL_ACTIVE;
1325 return 0;
1326 }
1327
1328 if (C_CLOCAL(tty))
1329 do_clocal = 1;
1330
1331 /* Block waiting for the carrier detect and the line to become
1332 * free (i.e., not in use by the callout). While we are in
1333 * this loop, info->count is dropped by one, so that
1334 * rs_close() knows when to free things. We restore it upon
1335 * exit, either normal or abnormal.
1336 */
1337 retval = 0;
1338 add_wait_queue(&port->open_wait, &wait);
1339 cli();
1340 if (!tty_hung_up_p(filp))
1341 port->count--;
1342 sti();
1343 port->blocked_open++;
1344 while (1) {
1345 cli();
1346 sbus_writeb(port_No(port) & 7,
1347 &bp->r[chip]->r[CD180_CAR]);
1348 udelay(1);
1349 CD = sbus_readb(&bp->r[chip]->r[CD180_MSVR]) & MSVR_CD;
1350 port->MSVR=bp->RTS;
1351
1352 /* auto drops DTR */
1353 sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
1354 sti();
1355 set_current_state(TASK_INTERRUPTIBLE);
1356 if (tty_hung_up_p(filp) ||
1357 !(port->flags & ASYNC_INITIALIZED)) {
1358 if (port->flags & ASYNC_HUP_NOTIFY)
1359 retval = -EAGAIN;
1360 else
1361 retval = -ERESTARTSYS;
1362 break;
1363 }
1364 if (!(port->flags & ASYNC_CLOSING) &&
1365 (do_clocal || CD))
1366 break;
1367 if (signal_pending(current)) {
1368 retval = -ERESTARTSYS;
1369 break;
1370 }
1371 schedule();
1372 }
1373 current->state = TASK_RUNNING;
1374 remove_wait_queue(&port->open_wait, &wait);
1375 if (!tty_hung_up_p(filp))
1376 port->count++;
1377 port->blocked_open--;
1378 if (retval)
1379 return retval;
1380
1381 port->flags |= ASYNC_NORMAL_ACTIVE;
1382#ifdef AURORA_DEBUG
1383 printk("block_til_ready: end\n");
1384#endif
1385 return 0;
1386}
1387
1388static int aurora_open(struct tty_struct * tty, struct file * filp)
1389{
1390 int board;
1391 int error;
1392 struct Aurora_port * port;
1393 struct Aurora_board * bp;
1394 unsigned long flags;
1395
1396#ifdef AURORA_DEBUG
1397 printk("aurora_open: start\n");
1398#endif
1399
1400 board = AURORA_BOARD(tty->index);
1401 if (board > AURORA_NBOARD ||
1402 !(aurora_board[board].flags & AURORA_BOARD_PRESENT)) {
1403#ifdef AURORA_DEBUG
1404 printk("aurora_open: error board %d present %d\n",
1405 board, aurora_board[board].flags & AURORA_BOARD_PRESENT);
1406#endif
1407 return -ENODEV;
1408 }
1409
1410 bp = &aurora_board[board];
1411 port = aurora_port + board * AURORA_NPORT * AURORA_NCD180 + AURORA_PORT(tty->index);
1412 if ((aurora_paranoia_check(port, tty->name, "aurora_open")) {
1413#ifdef AURORA_DEBUG
1414 printk("aurora_open: error paranoia check\n");
1415#endif
1416 return -ENODEV;
1417 }
1418
1419 port->count++;
1420 tty->driver_data = port;
1421 port->tty = tty;
1422
1423 if ((error = aurora_setup_port(bp, port))) {
1424#ifdef AURORA_DEBUG
1425 printk("aurora_open: error aurora_setup_port ret %d\n",error);
1426#endif
1427 return error;
1428 }
1429
1430 if ((error = block_til_ready(tty, filp, port))) {
1431#ifdef AURORA_DEBUG
1432 printk("aurora_open: error block_til_ready ret %d\n",error);
1433#endif
1434 return error;
1435 }
1436
1437#ifdef AURORA_DEBUG
1438 printk("aurora_open: end\n");
1439#endif
1440 return 0;
1441}
1442
1443static void aurora_close(struct tty_struct * tty, struct file * filp)
1444{
1445 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1446 struct Aurora_board *bp;
1447 unsigned long flags;
1448 unsigned long timeout;
1449 unsigned char chip;
1450
1451#ifdef AURORA_DEBUG
1452 printk("aurora_close: start\n");
1453#endif
1454
1455 if (!port || (aurora_paranoia_check(port, tty->name, "close"))
1456 return;
1457
1458 chip = AURORA_CD180(port_No(port));
1459
1460 save_flags(flags); cli();
1461 if (tty_hung_up_p(filp)) {
1462 restore_flags(flags);
1463 return;
1464 }
1465
1466 bp = port_Board(port);
1467 if ((tty->count == 1) && (port->count != 1)) {
1468 printk(KERN_DEBUG "aurora%d: aurora_close: bad port count; "
1469 "tty->count is 1, port count is %d\n",
1470 board_No(bp), port->count);
1471 port->count = 1;
1472 }
1473 if (--port->count < 0) {
1474 printk(KERN_DEBUG "aurora%d: aurora_close: bad port "
1475 "count for tty%d: %d\n",
1476 board_No(bp), port_No(port), port->count);
1477 port->count = 0;
1478 }
1479 if (port->count) {
1480 restore_flags(flags);
1481 return;
1482 }
1483 port->flags |= ASYNC_CLOSING;
1484
1485 /* Now we wait for the transmit buffer to clear; and we notify
1486 * the line discipline to only process XON/XOFF characters.
1487 */
1488 tty->closing = 1;
1489 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE){
1490#ifdef AURORA_DEBUG
1491 printk("aurora_close: waiting to flush...\n");
1492#endif
1493 tty_wait_until_sent(tty, port->closing_wait);
1494 }
1495
1496 /* At this point we stop accepting input. To do this, we
1497 * disable the receive line status interrupts, and tell the
1498 * interrupt driver to stop checking the data ready bit in the
1499 * line status register.
1500 */
1501 port->SRER &= ~SRER_RXD;
1502 if (port->flags & ASYNC_INITIALIZED) {
1503 port->SRER &= ~SRER_TXRDY;
1504 port->SRER |= SRER_TXEMPTY;
1505 sbus_writeb(port_No(port) & 7,
1506 &bp->r[chip]->r[CD180_CAR]);
1507 udelay(1);
1508 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
1509 /*
1510 * Before we drop DTR, make sure the UART transmitter
1511 * has completely drained; this is especially
1512 * important if there is a transmit FIFO!
1513 */
1514 timeout = jiffies+HZ;
1515 while(port->SRER & SRER_TXEMPTY) {
1516 msleep_interruptible(jiffies_to_msecs(port->timeout));
1517 if (time_after(jiffies, timeout))
1518 break;
1519 }
1520 }
1521#ifdef AURORA_DEBUG
1522 printk("aurora_close: shutdown_port\n");
1523#endif
1524 aurora_shutdown_port(bp, port);
1525 if (tty->driver->flush_buffer)
1526 tty->driver->flush_buffer(tty);
1527 tty_ldisc_flush(tty);
1528 tty->closing = 0;
1529 port->event = 0;
1530 port->tty = 0;
1531 if (port->blocked_open) {
1532 if (port->close_delay) {
1533 msleep_interruptible(jiffies_to_msecs(port->close_delay));
1534 }
1535 wake_up_interruptible(&port->open_wait);
1536 }
1537 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1538 wake_up_interruptible(&port->close_wait);
1539 restore_flags(flags);
1540#ifdef AURORA_DEBUG
1541 printk("aurora_close: end\n");
1542#endif
1543}
1544
1545static int aurora_write(struct tty_struct * tty,
1546 const unsigned char *buf, int count)
1547{
1548 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1549 struct Aurora_board *bp;
1550 int c, total = 0;
1551 unsigned long flags;
1552 unsigned char chip;
1553
1554#ifdef AURORA_DEBUG
1555 printk("aurora_write: start %d\n",count);
1556#endif
1557 if ((aurora_paranoia_check(port, tty->name, "aurora_write"))
1558 return 0;
1559
1560 chip = AURORA_CD180(port_No(port));
1561
1562 bp = port_Board(port);
1563
1564 if (!tty || !port->xmit_buf || !tmp_buf)
1565 return 0;
1566
1567 save_flags(flags);
1568 while (1) {
1569 cli();
1570 c = min(count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1571 SERIAL_XMIT_SIZE - port->xmit_head));
1572 if (c <= 0) {
1573 restore_flags(flags);
1574 break;
1575 }
1576 memcpy(port->xmit_buf + port->xmit_head, buf, c);
1577 port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1578 port->xmit_cnt += c;
1579 restore_flags(flags);
1580
1581 buf += c;
1582 count -= c;
1583 total += c;
1584 }
1585
1586 cli();
1587 if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1588 !(port->SRER & SRER_TXRDY)) {
1589 port->SRER |= SRER_TXRDY;
1590 sbus_writeb(port_No(port) & 7,
1591 &bp->r[chip]->r[CD180_CAR]);
1592 udelay(1);
1593 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
1594 }
1595 restore_flags(flags);
1596#ifdef AURORA_DEBUG
1597 printk("aurora_write: end %d\n",total);
1598#endif
1599 return total;
1600}
1601
1602static void aurora_put_char(struct tty_struct * tty, unsigned char ch)
1603{
1604 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1605 unsigned long flags;
1606
1607#ifdef AURORA_DEBUG
1608 printk("aurora_put_char: start %c\n",ch);
1609#endif
1610 if ((aurora_paranoia_check(port, tty->name, "aurora_put_char"))
1611 return;
1612
1613 if (!tty || !port->xmit_buf)
1614 return;
1615
1616 save_flags(flags); cli();
1617
1618 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
1619 restore_flags(flags);
1620 return;
1621 }
1622
1623 port->xmit_buf[port->xmit_head++] = ch;
1624 port->xmit_head &= SERIAL_XMIT_SIZE - 1;
1625 port->xmit_cnt++;
1626 restore_flags(flags);
1627#ifdef AURORA_DEBUG
1628 printk("aurora_put_char: end\n");
1629#endif
1630}
1631
1632static void aurora_flush_chars(struct tty_struct * tty)
1633{
1634 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1635 unsigned long flags;
1636 unsigned char chip;
1637
1638/*#ifdef AURORA_DEBUG
1639 printk("aurora_flush_chars: start\n");
1640#endif*/
1641 if ((aurora_paranoia_check(port, tty->name, "aurora_flush_chars"))
1642 return;
1643
1644 chip = AURORA_CD180(port_No(port));
1645
1646 if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
1647 !port->xmit_buf)
1648 return;
1649
1650 save_flags(flags); cli();
1651 port->SRER |= SRER_TXRDY;
1652 sbus_writeb(port_No(port) & 7,
1653 &port_Board(port)->r[chip]->r[CD180_CAR]);
1654 udelay(1);
1655 sbus_writeb(port->SRER,
1656 &port_Board(port)->r[chip]->r[CD180_SRER]);
1657 restore_flags(flags);
1658/*#ifdef AURORA_DEBUG
1659 printk("aurora_flush_chars: end\n");
1660#endif*/
1661}
1662
1663static int aurora_write_room(struct tty_struct * tty)
1664{
1665 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1666 int ret;
1667
1668#ifdef AURORA_DEBUG
1669 printk("aurora_write_room: start\n");
1670#endif
1671 if ((aurora_paranoia_check(port, tty->name, "aurora_write_room"))
1672 return 0;
1673
1674 ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
1675 if (ret < 0)
1676 ret = 0;
1677#ifdef AURORA_DEBUG
1678 printk("aurora_write_room: end\n");
1679#endif
1680 return ret;
1681}
1682
1683static int aurora_chars_in_buffer(struct tty_struct *tty)
1684{
1685 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1686
1687 if ((aurora_paranoia_check(port, tty->name, "aurora_chars_in_buffer"))
1688 return 0;
1689
1690 return port->xmit_cnt;
1691}
1692
1693static void aurora_flush_buffer(struct tty_struct *tty)
1694{
1695 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1696 unsigned long flags;
1697
1698#ifdef AURORA_DEBUG
1699 printk("aurora_flush_buffer: start\n");
1700#endif
1701 if ((aurora_paranoia_check(port, tty->name, "aurora_flush_buffer"))
1702 return;
1703
1704 save_flags(flags); cli();
1705 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1706 restore_flags(flags);
1707
1708 tty_wakeup(tty);
1709#ifdef AURORA_DEBUG
1710 printk("aurora_flush_buffer: end\n");
1711#endif
1712}
1713
1714static int aurora_tiocmget(struct tty_struct *tty, struct file *file)
1715{
1716 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1717 struct Aurora_board * bp;
1718 unsigned char status,chip;
1719 unsigned int result;
1720 unsigned long flags;
1721
1722#ifdef AURORA_DEBUG
1723 printk("aurora_get_modem_info: start\n");
1724#endif
1725 if ((aurora_paranoia_check(port, tty->name, __FUNCTION__))
1726 return -ENODEV;
1727
1728 chip = AURORA_CD180(port_No(port));
1729
1730 bp = port_Board(port);
1731
1732 save_flags(flags); cli();
1733
1734 sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
1735 udelay(1);
1736
1737 status = sbus_readb(&bp->r[chip]->r[CD180_MSVR]);
1738 result = 0/*bp->r[chip]->r[AURORA_RI] & (1u << port_No(port)) ? 0 : TIOCM_RNG*/;
1739
1740 restore_flags(flags);
1741
1742 result |= ((status & bp->RTS) ? TIOCM_RTS : 0)
1743 | ((status & bp->DTR) ? TIOCM_DTR : 0)
1744 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1745 | ((status & MSVR_DSR) ? TIOCM_DSR : 0)
1746 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1747
1748#ifdef AURORA_DEBUG
1749 printk("aurora_get_modem_info: end\n");
1750#endif
1751 return result;
1752}
1753
1754static int aurora_tiocmset(struct tty_struct *tty, struct file *file,
1755 unsigned int set, unsigned int clear)
1756{
1757 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1758 unsigned int arg;
1759 unsigned long flags;
1760 struct Aurora_board *bp = port_Board(port);
1761 unsigned char chip;
1762
1763#ifdef AURORA_DEBUG
1764 printk("aurora_set_modem_info: start\n");
1765#endif
1766 if ((aurora_paranoia_check(port, tty->name, __FUNCTION__))
1767 return -ENODEV;
1768
1769 chip = AURORA_CD180(port_No(port));
1770
1771 save_flags(flags); cli();
1772 if (set & TIOCM_RTS)
1773 port->MSVR |= bp->RTS;
1774 if (set & TIOCM_DTR)
1775 port->MSVR |= bp->DTR;
1776 if (clear & TIOCM_RTS)
1777 port->MSVR &= ~bp->RTS;
1778 if (clear & TIOCM_DTR)
1779 port->MSVR &= ~bp->DTR;
1780
1781 sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
1782 udelay(1);
1783
1784 sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
1785
1786 restore_flags(flags);
1787#ifdef AURORA_DEBUG
1788 printk("aurora_set_modem_info: end\n");
1789#endif
1790 return 0;
1791}
1792
1793static void aurora_send_break(struct Aurora_port * port, unsigned long length)
1794{
1795 struct Aurora_board *bp = port_Board(port);
1796 unsigned long flags;
1797 unsigned char chip;
1798
1799#ifdef AURORA_DEBUG
1800 printk("aurora_send_break: start\n");
1801#endif
1802 chip = AURORA_CD180(port_No(port));
1803
1804 save_flags(flags); cli();
1805
1806 port->break_length = AURORA_TPS / HZ * length;
1807 port->COR2 |= COR2_ETC;
1808 port->SRER |= SRER_TXRDY;
1809 sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
1810 udelay(1);
1811
1812 sbus_writeb(port->COR2, &bp->r[chip]->r[CD180_COR2]);
1813 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
1814 aurora_wait_CCR(bp->r[chip]);
1815
1816 sbus_writeb(CCR_CORCHG2, &bp->r[chip]->r[CD180_CCR]);
1817 aurora_wait_CCR(bp->r[chip]);
1818
1819 restore_flags(flags);
1820#ifdef AURORA_DEBUG
1821 printk("aurora_send_break: end\n");
1822#endif
1823}
1824
1825static int aurora_set_serial_info(struct Aurora_port * port,
1826 struct serial_struct * newinfo)
1827{
1828 struct serial_struct tmp;
1829 struct Aurora_board *bp = port_Board(port);
1830 int change_speed;
1831 unsigned long flags;
1832
1833#ifdef AURORA_DEBUG
1834 printk("aurora_set_serial_info: start\n");
1835#endif
1836 if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
1837 return -EFAULT;
1838#if 0
1839 if ((tmp.irq != bp->irq) ||
1840 (tmp.port != bp->base) ||
1841 (tmp.type != PORT_CIRRUS) ||
1842 (tmp.baud_base != (bp->oscfreq + CD180_TPC/2) / CD180_TPC) ||
1843 (tmp.custom_divisor != 0) ||
1844 (tmp.xmit_fifo_size != CD180_NFIFO) ||
1845 (tmp.flags & ~AURORA_LEGAL_FLAGS))
1846 return -EINVAL;
1847#endif
1848
1849 change_speed = ((port->flags & ASYNC_SPD_MASK) !=
1850 (tmp.flags & ASYNC_SPD_MASK));
1851
1852 if (!capable(CAP_SYS_ADMIN)) {
1853 if ((tmp.close_delay != port->close_delay) ||
1854 (tmp.closing_wait != port->closing_wait) ||
1855 ((tmp.flags & ~ASYNC_USR_MASK) !=
1856 (port->flags & ~ASYNC_USR_MASK)))
1857 return -EPERM;
1858 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
1859 (tmp.flags & ASYNC_USR_MASK));
1860 } else {
1861 port->flags = ((port->flags & ~ASYNC_FLAGS) |
1862 (tmp.flags & ASYNC_FLAGS));
1863 port->close_delay = tmp.close_delay;
1864 port->closing_wait = tmp.closing_wait;
1865 }
1866 if (change_speed) {
1867 save_flags(flags); cli();
1868 aurora_change_speed(bp, port);
1869 restore_flags(flags);
1870 }
1871#ifdef AURORA_DEBUG
1872 printk("aurora_set_serial_info: end\n");
1873#endif
1874 return 0;
1875}
1876
1877extern int aurora_get_serial_info(struct Aurora_port * port,
1878 struct serial_struct * retinfo)
1879{
1880 struct serial_struct tmp;
1881 struct Aurora_board *bp = port_Board(port);
1882
1883#ifdef AURORA_DEBUG
1884 printk("aurora_get_serial_info: start\n");
1885#endif
1886 if (!access_ok(VERIFY_WRITE, (void *) retinfo, sizeof(tmp)))
1887 return -EFAULT;
1888
1889 memset(&tmp, 0, sizeof(tmp));
1890 tmp.type = PORT_CIRRUS;
1891 tmp.line = port - aurora_port;
1892 tmp.port = 0;
1893 tmp.irq = bp->irq;
1894 tmp.flags = port->flags;
1895 tmp.baud_base = (bp->oscfreq + CD180_TPC/2) / CD180_TPC;
1896 tmp.close_delay = port->close_delay * HZ/100;
1897 tmp.closing_wait = port->closing_wait * HZ/100;
1898 tmp.xmit_fifo_size = CD180_NFIFO;
1899 copy_to_user(retinfo, &tmp, sizeof(tmp));
1900#ifdef AURORA_DEBUG
1901printk("aurora_get_serial_info: end\n");
1902#endif
1903 return 0;
1904}
1905
1906static int aurora_ioctl(struct tty_struct * tty, struct file * filp,
1907 unsigned int cmd, unsigned long arg)
1908
1909{
1910 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1911 int retval;
1912
1913#ifdef AURORA_DEBUG
1914 printk("aurora_ioctl: start\n");
1915#endif
1916 if ((aurora_paranoia_check(port, tty->name, "aurora_ioctl"))
1917 return -ENODEV;
1918
1919 switch (cmd) {
1920 case TCSBRK: /* SVID version: non-zero arg --> no break */
1921 retval = tty_check_change(tty);
1922 if (retval)
1923 return retval;
1924 tty_wait_until_sent(tty, 0);
1925 if (!arg)
1926 aurora_send_break(port, HZ/4); /* 1/4 second */
1927 return 0;
1928 case TCSBRKP: /* support for POSIX tcsendbreak() */
1929 retval = tty_check_change(tty);
1930 if (retval)
1931 return retval;
1932 tty_wait_until_sent(tty, 0);
1933 aurora_send_break(port, arg ? arg*(HZ/10) : HZ/4);
1934 return 0;
1935 case TIOCGSOFTCAR:
1936 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long *)arg);
1937 case TIOCSSOFTCAR:
1938 if (get_user(arg,(unsigned long *)arg))
1939 return -EFAULT;
1940 tty->termios->c_cflag =
1941 ((tty->termios->c_cflag & ~CLOCAL) |
1942 (arg ? CLOCAL : 0));
1943 return 0;
1944 case TIOCGSERIAL:
1945 return aurora_get_serial_info(port, (struct serial_struct *) arg);
1946 case TIOCSSERIAL:
1947 return aurora_set_serial_info(port, (struct serial_struct *) arg);
1948 default:
1949 return -ENOIOCTLCMD;
1950 };
1951#ifdef AURORA_DEBUG
1952 printk("aurora_ioctl: end\n");
1953#endif
1954 return 0;
1955}
1956
1957static void aurora_throttle(struct tty_struct * tty)
1958{
1959 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1960 struct Aurora_board *bp;
1961 unsigned long flags;
1962 unsigned char chip;
1963
1964#ifdef AURORA_DEBUG
1965 printk("aurora_throttle: start\n");
1966#endif
1967 if ((aurora_paranoia_check(port, tty->name, "aurora_throttle"))
1968 return;
1969
1970 bp = port_Board(port);
1971 chip = AURORA_CD180(port_No(port));
1972
1973 save_flags(flags); cli();
1974 port->MSVR &= ~bp->RTS;
1975 sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
1976 udelay(1);
1977 if (I_IXOFF(tty)) {
1978 aurora_wait_CCR(bp->r[chip]);
1979 sbus_writeb(CCR_SSCH2, &bp->r[chip]->r[CD180_CCR]);
1980 aurora_wait_CCR(bp->r[chip]);
1981 }
1982 sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
1983 restore_flags(flags);
1984#ifdef AURORA_DEBUG
1985 printk("aurora_throttle: end\n");
1986#endif
1987}
1988
1989static void aurora_unthrottle(struct tty_struct * tty)
1990{
1991 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1992 struct Aurora_board *bp;
1993 unsigned long flags;
1994 unsigned char chip;
1995
1996#ifdef AURORA_DEBUG
1997 printk("aurora_unthrottle: start\n");
1998#endif
1999 if ((aurora_paranoia_check(port, tty->name, "aurora_unthrottle"))
2000 return;
2001
2002 bp = port_Board(port);
2003
2004 chip = AURORA_CD180(port_No(port));
2005
2006 save_flags(flags); cli();
2007 port->MSVR |= bp->RTS;
2008 sbus_writeb(port_No(port) & 7,
2009 &bp->r[chip]->r[CD180_CAR]);
2010 udelay(1);
2011 if (I_IXOFF(tty)) {
2012 aurora_wait_CCR(bp->r[chip]);
2013 sbus_writeb(CCR_SSCH1,
2014 &bp->r[chip]->r[CD180_CCR]);
2015 aurora_wait_CCR(bp->r[chip]);
2016 }
2017 sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
2018 restore_flags(flags);
2019#ifdef AURORA_DEBUG
2020 printk("aurora_unthrottle: end\n");
2021#endif
2022}
2023
2024static void aurora_stop(struct tty_struct * tty)
2025{
2026 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2027 struct Aurora_board *bp;
2028 unsigned long flags;
2029 unsigned char chip;
2030
2031#ifdef AURORA_DEBUG
2032 printk("aurora_stop: start\n");
2033#endif
2034 if ((aurora_paranoia_check(port, tty->name, "aurora_stop"))
2035 return;
2036
2037 bp = port_Board(port);
2038
2039 chip = AURORA_CD180(port_No(port));
2040
2041 save_flags(flags); cli();
2042 port->SRER &= ~SRER_TXRDY;
2043 sbus_writeb(port_No(port) & 7,
2044 &bp->r[chip]->r[CD180_CAR]);
2045 udelay(1);
2046 sbus_writeb(port->SRER,
2047 &bp->r[chip]->r[CD180_SRER]);
2048 restore_flags(flags);
2049#ifdef AURORA_DEBUG
2050 printk("aurora_stop: end\n");
2051#endif
2052}
2053
2054static void aurora_start(struct tty_struct * tty)
2055{
2056 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2057 struct Aurora_board *bp;
2058 unsigned long flags;
2059 unsigned char chip;
2060
2061#ifdef AURORA_DEBUG
2062 printk("aurora_start: start\n");
2063#endif
2064 if ((aurora_paranoia_check(port, tty->name, "aurora_start"))
2065 return;
2066
2067 bp = port_Board(port);
2068
2069 chip = AURORA_CD180(port_No(port));
2070
2071 save_flags(flags); cli();
2072 if (port->xmit_cnt && port->xmit_buf && !(port->SRER & SRER_TXRDY)) {
2073 port->SRER |= SRER_TXRDY;
2074 sbus_writeb(port_No(port) & 7,
2075 &bp->r[chip]->r[CD180_CAR]);
2076 udelay(1);
2077 sbus_writeb(port->SRER,
2078 &bp->r[chip]->r[CD180_SRER]);
2079 }
2080 restore_flags(flags);
2081#ifdef AURORA_DEBUG
2082 printk("aurora_start: end\n");
2083#endif
2084}
2085
2086/*
2087 * This routine is called from the scheduler tqueue when the interrupt
2088 * routine has signalled that a hangup has occurred. The path of
2089 * hangup processing is:
2090 *
2091 * serial interrupt routine -> (scheduler tqueue) ->
2092 * do_aurora_hangup() -> tty->hangup() -> aurora_hangup()
2093 *
2094 */
2095static void do_aurora_hangup(void *private_)
2096{
2097 struct Aurora_port *port = (struct Aurora_port *) private_;
2098 struct tty_struct *tty;
2099
2100#ifdef AURORA_DEBUG
2101 printk("do_aurora_hangup: start\n");
2102#endif
2103 tty = port->tty;
2104 if (tty != NULL) {
2105 tty_hangup(tty); /* FIXME: module removal race - AKPM */
2106#ifdef AURORA_DEBUG
2107 printk("do_aurora_hangup: end\n");
2108#endif
2109 }
2110}
2111
2112static void aurora_hangup(struct tty_struct * tty)
2113{
2114 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2115 struct Aurora_board *bp;
2116
2117#ifdef AURORA_DEBUG
2118 printk("aurora_hangup: start\n");
2119#endif
2120 if ((aurora_paranoia_check(port, tty->name, "aurora_hangup"))
2121 return;
2122
2123 bp = port_Board(port);
2124
2125 aurora_shutdown_port(bp, port);
2126 port->event = 0;
2127 port->count = 0;
2128 port->flags &= ~ASYNC_NORMAL_ACTIVE;
2129 port->tty = 0;
2130 wake_up_interruptible(&port->open_wait);
2131#ifdef AURORA_DEBUG
2132 printk("aurora_hangup: end\n");
2133#endif
2134}
2135
2136static void aurora_set_termios(struct tty_struct * tty, struct termios * old_termios)
2137{
2138 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2139 unsigned long flags;
2140
2141#ifdef AURORA_DEBUG
2142 printk("aurora_set_termios: start\n");
2143#endif
2144 if ((aurora_paranoia_check(port, tty->name, "aurora_set_termios"))
2145 return;
2146
2147 if (tty->termios->c_cflag == old_termios->c_cflag &&
2148 tty->termios->c_iflag == old_termios->c_iflag)
2149 return;
2150
2151 save_flags(flags); cli();
2152 aurora_change_speed(port_Board(port), port);
2153 restore_flags(flags);
2154
2155 if ((old_termios->c_cflag & CRTSCTS) &&
2156 !(tty->termios->c_cflag & CRTSCTS)) {
2157 tty->hw_stopped = 0;
2158 aurora_start(tty);
2159 }
2160#ifdef AURORA_DEBUG
2161 printk("aurora_set_termios: end\n");
2162#endif
2163}
2164
2165static void do_aurora_bh(void)
2166{
2167 run_task_queue(&tq_aurora);
2168}
2169
2170static void do_softint(void *private_)
2171{
2172 struct Aurora_port *port = (struct Aurora_port *) private_;
2173 struct tty_struct *tty;
2174
2175#ifdef AURORA_DEBUG
2176 printk("do_softint: start\n");
2177#endif
2178 tty = port->tty;
2179 if (tty == NULL)
2180 return;
2181
2182 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) {
2183 tty_wakeup(tty);
2184 }
2185#ifdef AURORA_DEBUG
2186 printk("do_softint: end\n");
2187#endif
2188}
2189
2190static const struct tty_operations aurora_ops = {
2191 .open = aurora_open,
2192 .close = aurora_close,
2193 .write = aurora_write,
2194 .put_char = aurora_put_char,
2195 .flush_chars = aurora_flush_chars,
2196 .write_room = aurora_write_room,
2197 .chars_in_buffer = aurora_chars_in_buffer,
2198 .flush_buffer = aurora_flush_buffer,
2199 .ioctl = aurora_ioctl,
2200 .throttle = aurora_throttle,
2201 .unthrottle = aurora_unthrottle,
2202 .set_termios = aurora_set_termios,
2203 .stop = aurora_stop,
2204 .start = aurora_start,
2205 .hangup = aurora_hangup,
2206 .tiocmget = aurora_tiocmget,
2207 .tiocmset = aurora_tiocmset,
2208};
2209
2210static int aurora_init_drivers(void)
2211{
2212 int error;
2213 int i;
2214
2215#ifdef AURORA_DEBUG
2216 printk("aurora_init_drivers: start\n");
2217#endif
2218 tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL);
2219 if (tmp_buf == NULL) {
2220 printk(KERN_ERR "aurora: Couldn't get free page.\n");
2221 return 1;
2222 }
2223 init_bh(AURORA_BH, do_aurora_bh);
2224 aurora_driver = alloc_tty_driver(AURORA_INPORTS);
2225 if (!aurora_driver) {
2226 printk(KERN_ERR "aurora: Couldn't allocate tty driver.\n");
2227 free_page((unsigned long) tmp_buf);
2228 return 1;
2229 }
2230 aurora_driver->owner = THIS_MODULE;
2231 aurora_driver->name = "ttyA";
2232 aurora_driver->major = AURORA_MAJOR;
2233 aurora_driver->type = TTY_DRIVER_TYPE_SERIAL;
2234 aurora_driver->subtype = SERIAL_TYPE_NORMAL;
2235 aurora_driver->init_termios = tty_std_termios;
2236 aurora_driver->init_termios.c_cflag =
2237 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2238 aurora_driver->flags = TTY_DRIVER_REAL_RAW;
2239 tty_set_operations(aurora_driver, &aurora_ops);
2240 error = tty_register_driver(aurora_driver);
2241 if (error) {
2242 put_tty_driver(aurora_driver);
2243 free_page((unsigned long) tmp_buf);
2244 printk(KERN_ERR "aurora: Couldn't register aurora driver, error = %d\n",
2245 error);
2246 return 1;
2247 }
2248
2249 memset(aurora_port, 0, sizeof(aurora_port));
2250 for (i = 0; i < AURORA_TNPORTS; i++) {
2251 aurora_port[i].magic = AURORA_MAGIC;
2252 aurora_port[i].tqueue.routine = do_softint;
2253 aurora_port[i].tqueue.data = &aurora_port[i];
2254 aurora_port[i].tqueue_hangup.routine = do_aurora_hangup;
2255 aurora_port[i].tqueue_hangup.data = &aurora_port[i];
2256 aurora_port[i].close_delay = 50 * HZ/100;
2257 aurora_port[i].closing_wait = 3000 * HZ/100;
2258 init_waitqueue_head(&aurora_port[i].open_wait);
2259 init_waitqueue_head(&aurora_port[i].close_wait);
2260 }
2261#ifdef AURORA_DEBUG
2262 printk("aurora_init_drivers: end\n");
2263#endif
2264 return 0;
2265}
2266
2267static void aurora_release_drivers(void)
2268{
2269#ifdef AURORA_DEBUG
2270 printk("aurora_release_drivers: start\n");
2271#endif
2272 free_page((unsigned long)tmp_buf);
2273 tty_unregister_driver(aurora_driver);
2274 put_tty_driver(aurora_driver);
2275#ifdef AURORA_DEBUG
2276 printk("aurora_release_drivers: end\n");
2277#endif
2278}
2279
2280/*
2281 * Called at boot time.
2282 *
2283 * You can specify IO base for up to RC_NBOARD cards,
2284 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
2285 * Note that there will be no probing at default
2286 * addresses in this case.
2287 *
2288 */
2289void __init aurora_setup(char *str, int *ints)
2290{
2291 int i;
2292
2293 for(i=0;(i<ints[0])&&(i<4);i++) {
2294 if (ints[i+1]) irqs[i]=ints[i+1];
2295 }
2296}
2297
2298static int __init aurora_real_init(void)
2299{
2300 int found;
2301 int i;
2302
2303 printk(KERN_INFO "aurora: Driver starting.\n");
2304 if(aurora_init_drivers())
2305 return -EIO;
2306 found = aurora_probe();
2307 if(!found) {
2308 aurora_release_drivers();
2309 printk(KERN_INFO "aurora: No Aurora Multiport boards detected.\n");
2310 return -EIO;
2311 } else {
2312 printk(KERN_INFO "aurora: %d boards found.\n", found);
2313 }
2314 for (i = 0; i < found; i++) {
2315 int ret = aurora_setup_board(&aurora_board[i]);
2316
2317 if (ret) {
2318#ifdef AURORA_DEBUG
2319 printk(KERN_ERR "aurora_init: error aurora_setup_board ret %d\n",
2320 ret);
2321#endif
2322 return ret;
2323 }
2324 }
2325 return 0;
2326}
2327
2328int irq = 0;
2329int irq1 = 0;
2330int irq2 = 0;
2331int irq3 = 0;
2332module_param(irq , int, 0);
2333module_param(irq1, int, 0);
2334module_param(irq2, int, 0);
2335module_param(irq3, int, 0);
2336
2337static int __init aurora_init(void)
2338{
2339 if (irq ) irqs[0]=irq ;
2340 if (irq1) irqs[1]=irq1;
2341 if (irq2) irqs[2]=irq2;
2342 if (irq3) irqs[3]=irq3;
2343 return aurora_real_init();
2344}
2345
2346static void __exit aurora_cleanup(void)
2347{
2348 int i;
2349
2350#ifdef AURORA_DEBUG
2351printk("cleanup_module: aurora_release_drivers\n");
2352#endif
2353
2354 aurora_release_drivers();
2355 for (i = 0; i < AURORA_NBOARD; i++)
2356 if (aurora_board[i].flags & AURORA_BOARD_PRESENT) {
2357 aurora_shutdown_board(&aurora_board[i]);
2358 aurora_release_io_range(&aurora_board[i]);
2359 }
2360}
2361
2362module_init(aurora_init);
2363module_exit(aurora_cleanup);
2364MODULE_LICENSE("GPL");
diff --git a/drivers/sbus/char/aurora.h b/drivers/sbus/char/aurora.h
deleted file mode 100644
index b8b5476d98..0000000000
--- a/drivers/sbus/char/aurora.h
+++ /dev/null
@@ -1,276 +0,0 @@
1/* $Id: aurora.h,v 1.6 2001/06/05 12:23:38 davem Exp $
2 * linux/drivers/sbus/char/aurora.h -- Aurora multiport driver
3 *
4 * Copyright (c) 1999 by Oliver Aldulea (oli@bv.ro)
5 *
6 * This code is based on the RISCom/8 multiport serial driver written
7 * by Dmitry Gorodchanin (pgmdsg@ibi.com), based on the Linux serial
8 * driver, written by Linus Torvalds, Theodore T'so and others.
9 * The Aurora multiport programming info was obtained mainly from the
10 * Cirrus Logic CD180 documentation (available on the web), and by
11 * doing heavy tests on the board. Many thanks to Eddie C. Dost for the
12 * help on the sbus interface.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 *
28 * Revision 1.0
29 *
30 * This is the first public release.
31 *
32 * This version needs a lot of feedback. This is the version that works
33 * with _my_ board. My board is model 1600se, revision '@(#)1600se.fth
34 * 1.2 3/28/95 1'. The driver might work with your board, but I do not
35 * guarantee it. If you have _any_ type of board, I need to know if the
36 * driver works or not, I need to know exactly your board parameters
37 * (get them with 'cd /proc/openprom/iommu/sbus/sio16/; ls *; cat *')
38 * Also, I need your board revision code, which is written on the board.
39 * Send me the output of my driver too (it outputs through klogd).
40 *
41 * If the driver does not work, you can try enabling the debug options
42 * to see what's wrong or what should be done.
43 *
44 * I'm sorry about the alignment of the code. It was written in a
45 * 128x48 environment.
46 *
47 * I must say that I do not like Aurora Technologies' policy. I asked
48 * them to help me do this driver faster, but they ended by something
49 * like "don't call us, we'll call you", and I never heard anything
50 * from them. They told me "knowing the way the board works, I don't
51 * doubt you and others on the net will make the driver."
52 * The truth about this board is that it has nothing intelligent on it.
53 * If you want to say to somebody what kind of board you have, say that
54 * it uses Cirrus Logic processors (CD180). The power of the board is
55 * in those two chips. The rest of the board is the interface to the
56 * sbus and to the peripherals. Still, they did something smart: they
57 * reversed DTR and RTS to make on-board automatic hardware flow
58 * control usable.
59 * Thanks to Aurora Technologies for wasting my time, nerves and money.
60 */
61
62#ifndef __LINUX_AURORA_H
63#define __LINUX_AURORA_H
64
65#include <linux/serial.h>
66#include <linux/serialP.h>
67
68#ifdef __KERNEL__
69
70/* This is the number of boards to support. I've only tested this driver with
71 * one board, so it might not work.
72 */
73#define AURORA_NBOARD 1
74
75/* Useful ? Yes. But you can safely comment the warnings if they annoy you
76 * (let me say that again: the warnings in the code, not this define).
77 */
78#define AURORA_PARANOIA_CHECK
79
80/* Well, after many lost nights, I found that the IRQ for this board is
81 * selected from four built-in values by writing some bits in the
82 * configuration register. This causes a little problem to occur: which
83 * IRQ to select ? Which one is the best for the user ? Well, I finally
84 * decided for the following algorithm: if the "bintr" value is not acceptable
85 * (not within type_1_irq[], then test the "intr" value, if that fails too,
86 * try each value from type_1_irq until succeded. Hope it's ok.
87 * You can safely reorder the irq's.
88 */
89#define TYPE_1_IRQS 4
90unsigned char type_1_irq[TYPE_1_IRQS] = {
91 3, 5, 9, 13
92};
93/* I know something about another method of interrupt setting, but not enough.
94 * Also, this is for another type of board, so I first have to learn how to
95 * detect it.
96#define TYPE_2_IRQS 3
97unsigned char type_2_irq[TYPE_2_IRQS] = {
98 0, 0, 0 ** could anyone find these for me ? (see AURORA_ALLIRQ below) **
99 };
100unsigned char type_2_mask[TYPE_2_IRQS] = {
101 32, 64, 128
102 };
103*/
104
105/* The following section should only be modified by those who know what
106 * they're doing (or don't, but want to help with some feedback). Modifying
107 * anything raises a _big_ probability for your system to hang, but the
108 * sacrifice worths. (I sacrificed my ext2fs many, many times...)
109 */
110
111/* This one tries to dump to console the name of almost every function called,
112 * and many other debugging info.
113 */
114#undef AURORA_DEBUG
115
116/* These are the most dangerous and useful defines. They do printk() during
117 * the interrupt processing routine(s), so if you manage to get "flooded" by
118 * irq's, start thinking about the "Power off/on" button...
119 */
120#undef AURORA_INTNORM /* This one enables the "normal" messages, but some
121 * of them cause flood, so I preffered putting
122 * them under a define */
123#undef AURORA_INT_DEBUG /* This one is really bad. */
124
125/* Here's something helpful: after n irq's, the board will be disabled. This
126 * prevents irq flooding during debug (no need to think about power
127 * off/on anymore...)
128 */
129#define AURORA_FLOODPRO 10
130
131/* This one helps finding which irq the board calls, in case of a strange/
132 * unsupported board. AURORA_INT_DEBUG should be enabled, because I don't
133 * think /proc/interrupts or any command will be available in case of an irq
134 * flood... "allirq" is the list of all free irq's.
135 */
136/*
137#define AURORA_ALLIRQ 6
138int allirq[AURORA_ALLIRQ]={
139 2,3,5,7,9,13
140 };
141*/
142
143/* These must not be modified. These values are assumed during the code for
144 * performance optimisations.
145 */
146#define AURORA_NCD180 2 /* two chips per board */
147#define AURORA_NPORT 8 /* 8 ports per chip */
148
149/* several utilities */
150#define AURORA_BOARD(line) (((line) >> 4) & 0x01)
151#define AURORA_CD180(line) (((line) >> 3) & 0x01)
152#define AURORA_PORT(line) ((line) & 15)
153
154#define AURORA_TNPORTS (AURORA_NBOARD*AURORA_NCD180*AURORA_NPORT)
155
156/* Ticks per sec. Used for setting receiver timeout and break length */
157#define AURORA_TPS 4000
158
159#define AURORA_MAGIC 0x0A18
160
161/* Yeah, after heavy testing I decided it must be 6.
162 * Sure, You can change it if needed.
163 */
164#define AURORA_RXFIFO 6 /* Max. receiver FIFO size (1-8) */
165
166#define AURORA_RXTH 7
167
168struct aurora_reg1 {
169 __volatile__ unsigned char r;
170};
171
172struct aurora_reg128 {
173 __volatile__ unsigned char r[128];
174};
175
176struct aurora_reg4 {
177 __volatile__ unsigned char r[4];
178};
179
180struct Aurora_board {
181 unsigned long flags;
182 struct aurora_reg1 * r0; /* This is the board configuration
183 * register (write-only). */
184 struct aurora_reg128 * r[2]; /* These are the registers for the
185 * two chips. */
186 struct aurora_reg4 * r3; /* These are used for hardware-based
187 * acknowledge. Software-based ack is
188 * not supported by CD180. */
189 unsigned int oscfreq; /* The on-board oscillator
190 * frequency, in Hz. */
191 unsigned char irq;
192#ifdef MODULE
193 signed char count; /* counts the use of the board */
194#endif
195 /* Values for the dtr_rts swapped mode. */
196 unsigned char DTR;
197 unsigned char RTS;
198 unsigned char MSVDTR;
199 unsigned char MSVRTS;
200 /* Values for hardware acknowledge. */
201 unsigned char ACK_MINT, ACK_TINT, ACK_RINT;
202};
203
204/* Board configuration register */
205#define AURORA_CFG_ENABLE_IO 8
206#define AURORA_CFG_ENABLE_IRQ 4
207
208/* Board flags */
209#define AURORA_BOARD_PRESENT 0x00000001
210#define AURORA_BOARD_ACTIVE 0x00000002
211#define AURORA_BOARD_TYPE_2 0x00000004 /* don't know how to
212 * detect this yet */
213#define AURORA_BOARD_DTR_FLOW_OK 0x00000008
214
215/* The story goes like this: Cirrus programmed the CD-180 chip to do automatic
216 * hardware flow control, and do it using CTS and DTR. CTS is ok, but, if you
217 * have a modem and the chip drops DTR, then the modem will drop the carrier
218 * (ain't that cute...). Luckily, the guys at Aurora decided to swap DTR and
219 * RTS, which makes the flow control usable. I hope that all the boards made
220 * by Aurora have these two signals swapped. If your's doesn't but you have a
221 * breakout box, you can try to reverse them yourself, then set the following
222 * flag.
223 */
224#undef AURORA_FORCE_DTR_FLOW
225
226/* In fact, a few more words have to be said about hardware flow control.
227 * This driver handles "output" flow control through the on-board facility
228 * CTS Auto Enable. For the "input" flow control there are two cases when
229 * the flow should be controlled. The first case is when the kernel is so
230 * busy that it cannot process IRQ's in time; this flow control can only be
231 * activated by the on-board chip, and if the board has RTS and DTR swapped,
232 * this facility is usable. The second case is when the application is so
233 * busy that it cannot receive bytes from the kernel, and this flow must be
234 * activated by software. This second case is not yet implemented in this
235 * driver. Unfortunately, I estimate that the second case is the one that
236 * occurs the most.
237 */
238
239
240struct Aurora_port {
241 int magic;
242 int baud_base;
243 int flags;
244 struct tty_struct * tty;
245 int count;
246 int blocked_open;
247 long event;
248 int timeout;
249 int close_delay;
250 unsigned char * xmit_buf;
251 int custom_divisor;
252 int xmit_head;
253 int xmit_tail;
254 int xmit_cnt;
255 wait_queue_head_t open_wait;
256 wait_queue_head_t close_wait;
257 struct tq_struct tqueue;
258 struct tq_struct tqueue_hangup;
259 short wakeup_chars;
260 short break_length;
261 unsigned short closing_wait;
262 unsigned char mark_mask;
263 unsigned char SRER;
264 unsigned char MSVR;
265 unsigned char COR2;
266#ifdef AURORA_REPORT_OVERRUN
267 unsigned long overrun;
268#endif
269#ifdef AURORA_REPORT_FIFO
270 unsigned long hits[10];
271#endif
272};
273
274#endif
275#endif /*__LINUX_AURORA_H*/
276
diff --git a/drivers/sbus/char/bbc_i2c.c b/drivers/sbus/char/bbc_i2c.c
index 22631f8b9b..8410587348 100644
--- a/drivers/sbus/char/bbc_i2c.c
+++ b/drivers/sbus/char/bbc_i2c.c
@@ -187,19 +187,20 @@ static int wait_for_pin(struct bbc_i2c_bus *bp, u8 *status)
187 bp->waiting = 1; 187 bp->waiting = 1;
188 add_wait_queue(&bp->wq, &wait); 188 add_wait_queue(&bp->wq, &wait);
189 while (limit-- > 0) { 189 while (limit-- > 0) {
190 u8 val; 190 unsigned long val;
191 191
192 set_current_state(TASK_INTERRUPTIBLE); 192 val = wait_event_interruptible_timeout(
193 *status = val = readb(bp->i2c_control_regs + 0); 193 bp->wq,
194 if ((val & I2C_PCF_PIN) == 0) { 194 (((*status = readb(bp->i2c_control_regs + 0))
195 & I2C_PCF_PIN) == 0),
196 msecs_to_jiffies(250));
197 if (val > 0) {
195 ret = 0; 198 ret = 0;
196 break; 199 break;
197 } 200 }
198 msleep_interruptible(250);
199 } 201 }
200 remove_wait_queue(&bp->wq, &wait); 202 remove_wait_queue(&bp->wq, &wait);
201 bp->waiting = 0; 203 bp->waiting = 0;
202 current->state = TASK_RUNNING;
203 204
204 return ret; 205 return ret;
205} 206}
@@ -340,7 +341,7 @@ static irqreturn_t bbc_i2c_interrupt(int irq, void *dev_id)
340 */ 341 */
341 if (bp->waiting && 342 if (bp->waiting &&
342 !(readb(bp->i2c_control_regs + 0x0) & I2C_PCF_PIN)) 343 !(readb(bp->i2c_control_regs + 0x0) & I2C_PCF_PIN))
343 wake_up(&bp->wq); 344 wake_up_interruptible(&bp->wq);
344 345
345 return IRQ_HANDLED; 346 return IRQ_HANDLED;
346} 347}
diff --git a/drivers/sbus/char/cd180.h b/drivers/sbus/char/cd180.h
deleted file mode 100644
index 445b86cc65..0000000000
--- a/drivers/sbus/char/cd180.h
+++ /dev/null
@@ -1,240 +0,0 @@
1
2/* Definitions for Cirrus Logic CL-CD180 8-port async mux chip */
3#define CD180_NCH 8 /* Total number of channels */
4#define CD180_TPC 16 /* Ticks per character */
5#define CD180_NFIFO 8 /* TX FIFO size */
6
7/* Global registers */
8#define CD180_GFRCR 0x6b /* Global Firmware Revision Code Register */
9#define CD180_SRCR 0x66 /* Service Request Configuration Register */
10#define CD180_PPRH 0x70 /* Prescaler Period Register High */
11#define CD180_PPRL 0x71 /* Prescaler Period Register Low */
12#define CD180_MSMR 0x61 /* Modem Service Match Register */
13#define CD180_TSMR 0x62 /* Transmit Service Match Register */
14#define CD180_RSMR 0x63 /* Receive Service Match Register */
15#define CD180_GSVR 0x40 /* Global Service Vector Register */
16#define CD180_SRSR 0x65 /* Service Request Status Register */
17#define CD180_GSCR 0x41 /* Global Service Channel Register */
18#define CD180_CAR 0x64 /* Channel Access Register */
19
20/* Indexed registers */
21#define CD180_RDCR 0x07 /* Receive Data Count Register */
22#define CD180_RDR 0x78 /* Receiver Data Register */
23#define CD180_RCSR 0x7a /* Receiver Character Status Register */
24#define CD180_TDR 0x7b /* Transmit Data Register */
25#define CD180_EOSRR 0x7f /* End of Service Request Register */
26
27/* Channel Registers */
28#define CD180_SRER 0x02 /* Service Request Enable Register */
29#define CD180_CCR 0x01 /* Channel Command Register */
30#define CD180_COR1 0x03 /* Channel Option Register 1 */
31#define CD180_COR2 0x04 /* Channel Option Register 2 */
32#define CD180_COR3 0x05 /* Channel Option Register 3 */
33#define CD180_CCSR 0x06 /* Channel Control Status Register */
34#define CD180_RTPR 0x18 /* Receive Timeout Period Register */
35#define CD180_RBPRH 0x31 /* Receive Bit Rate Period Register High */
36#define CD180_RBPRL 0x32 /* Receive Bit Rate Period Register Low */
37#define CD180_TBPRH 0x39 /* Transmit Bit Rate Period Register High */
38#define CD180_TBPRL 0x3a /* Transmit Bit Rate Period Register Low */
39#define CD180_SCHR1 0x09 /* Special Character Register 1 */
40#define CD180_SCHR2 0x0a /* Special Character Register 2 */
41#define CD180_SCHR3 0x0b /* Special Character Register 3 */
42#define CD180_SCHR4 0x0c /* Special Character Register 4 */
43#define CD180_MCR 0x12 /* Modem Change Register */
44#define CD180_MCOR1 0x10 /* Modem Change Option 1 Register */
45#define CD180_MCOR2 0x11 /* Modem Change Option 2 Register */
46#define CD180_MSVR 0x28 /* Modem Signal Value Register */
47#define CD180_MSVRTS 0x29 /* Modem Signal Value RTS */
48#define CD180_MSVDTR 0x2a /* Modem Signal Value DTR */
49
50/* Global Interrupt Vector Register (R/W) */
51
52#define GSVR_ITMASK 0x07 /* Interrupt type mask */
53#define GSVR_IT_MDM 0x01 /* Modem Signal Change Interrupt */
54#define GSVR_IT_TX 0x02 /* Transmit Data Interrupt */
55#define GSVR_IT_RGD 0x03 /* Receive Good Data Interrupt */
56#define GSVR_IT_REXC 0x07 /* Receive Exception Interrupt */
57
58
59/* Global Interrupt Channel Register (R/W) */
60
61#define GSCR_CHAN 0x1c /* Channel Number Mask */
62#define GSCR_CHAN_OFF 2 /* Channel Number Offset */
63
64
65/* Channel Address Register (R/W) */
66
67#define CAR_CHAN 0x07 /* Channel Number Mask */
68
69
70/* Receive Character Status Register (R/O) */
71
72#define RCSR_TOUT 0x80 /* Rx Timeout */
73#define RCSR_SCDET 0x70 /* Special Character Detected Mask */
74#define RCSR_NO_SC 0x00 /* No Special Characters Detected */
75#define RCSR_SC_1 0x10 /* Special Char 1 (or 1 & 3) Detected */
76#define RCSR_SC_2 0x20 /* Special Char 2 (or 2 & 4) Detected */
77#define RCSR_SC_3 0x30 /* Special Char 3 Detected */
78#define RCSR_SC_4 0x40 /* Special Char 4 Detected */
79#define RCSR_BREAK 0x08 /* Break has been detected */
80#define RCSR_PE 0x04 /* Parity Error */
81#define RCSR_FE 0x02 /* Frame Error */
82#define RCSR_OE 0x01 /* Overrun Error */
83
84
85/* Channel Command Register (R/W) (commands in groups can be OR-ed) */
86
87#define CCR_HARDRESET 0x81 /* Reset the chip */
88
89#define CCR_SOFTRESET 0x80 /* Soft Channel Reset */
90
91#define CCR_CORCHG1 0x42 /* Channel Option Register 1 Changed */
92#define CCR_CORCHG2 0x44 /* Channel Option Register 2 Changed */
93#define CCR_CORCHG3 0x48 /* Channel Option Register 3 Changed */
94
95#define CCR_SSCH1 0x21 /* Send Special Character 1 */
96
97#define CCR_SSCH2 0x22 /* Send Special Character 2 */
98
99#define CCR_SSCH3 0x23 /* Send Special Character 3 */
100
101#define CCR_SSCH4 0x24 /* Send Special Character 4 */
102
103#define CCR_TXEN 0x18 /* Enable Transmitter */
104#define CCR_RXEN 0x12 /* Enable Receiver */
105
106#define CCR_TXDIS 0x14 /* Disable Transmitter */
107#define CCR_RXDIS 0x11 /* Disable Receiver */
108
109
110/* Service Request Enable Register (R/W) */
111
112#define SRER_DSR 0x80 /* Enable interrupt on DSR change */
113#define SRER_CD 0x40 /* Enable interrupt on CD change */
114#define SRER_CTS 0x20 /* Enable interrupt on CTS change */
115#define SRER_RXD 0x10 /* Enable interrupt on Receive Data */
116#define SRER_RXSC 0x08 /* Enable interrupt on Receive Spec. Char */
117#define SRER_TXRDY 0x04 /* Enable interrupt on TX FIFO empty */
118#define SRER_TXEMPTY 0x02 /* Enable interrupt on TX completely empty */
119#define SRER_RET 0x01 /* Enable interrupt on RX Exc. Timeout */
120
121
122/* Channel Option Register 1 (R/W) */
123
124#define COR1_ODDP 0x80 /* Odd Parity */
125#define COR1_PARMODE 0x60 /* Parity Mode mask */
126#define COR1_NOPAR 0x00 /* No Parity */
127#define COR1_FORCEPAR 0x20 /* Force Parity */
128#define COR1_NORMPAR 0x40 /* Normal Parity */
129#define COR1_IGNORE 0x10 /* Ignore Parity on RX */
130#define COR1_STOPBITS 0x0c /* Number of Stop Bits */
131#define COR1_1SB 0x00 /* 1 Stop Bit */
132#define COR1_15SB 0x04 /* 1.5 Stop Bits */
133#define COR1_2SB 0x08 /* 2 Stop Bits */
134#define COR1_CHARLEN 0x03 /* Character Length */
135#define COR1_5BITS 0x00 /* 5 bits */
136#define COR1_6BITS 0x01 /* 6 bits */
137#define COR1_7BITS 0x02 /* 7 bits */
138#define COR1_8BITS 0x03 /* 8 bits */
139
140
141/* Channel Option Register 2 (R/W) */
142
143#define COR2_IXM 0x80 /* Implied XON mode */
144#define COR2_TXIBE 0x40 /* Enable In-Band (XON/XOFF) Flow Control */
145#define COR2_ETC 0x20 /* Embedded Tx Commands Enable */
146#define COR2_LLM 0x10 /* Local Loopback Mode */
147#define COR2_RLM 0x08 /* Remote Loopback Mode */
148#define COR2_RTSAO 0x04 /* RTS Automatic Output Enable */
149#define COR2_CTSAE 0x02 /* CTS Automatic Enable */
150#define COR2_DSRAE 0x01 /* DSR Automatic Enable */
151
152
153/* Channel Option Register 3 (R/W) */
154
155#define COR3_XONCH 0x80 /* XON is a pair of characters (1 & 3) */
156#define COR3_XOFFCH 0x40 /* XOFF is a pair of characters (2 & 4) */
157#define COR3_FCT 0x20 /* Flow-Control Transparency Mode */
158#define COR3_SCDE 0x10 /* Special Character Detection Enable */
159#define COR3_RXTH 0x0f /* RX FIFO Threshold value (1-8) */
160
161
162/* Channel Control Status Register (R/O) */
163
164#define CCSR_RXEN 0x80 /* Receiver Enabled */
165#define CCSR_RXFLOFF 0x40 /* Receive Flow Off (XOFF was sent) */
166#define CCSR_RXFLON 0x20 /* Receive Flow On (XON was sent) */
167#define CCSR_TXEN 0x08 /* Transmitter Enabled */
168#define CCSR_TXFLOFF 0x04 /* Transmit Flow Off (got XOFF) */
169#define CCSR_TXFLON 0x02 /* Transmit Flow On (got XON) */
170
171
172/* Modem Change Option Register 1 (R/W) */
173
174#define MCOR1_DSRZD 0x80 /* Detect 0->1 transition of DSR */
175#define MCOR1_CDZD 0x40 /* Detect 0->1 transition of CD */
176#define MCOR1_CTSZD 0x20 /* Detect 0->1 transition of CTS */
177#define MCOR1_DTRTH 0x0f /* Auto DTR flow control Threshold (1-8) */
178#define MCOR1_NODTRFC 0x0 /* Automatic DTR flow control disabled */
179
180
181/* Modem Change Option Register 2 (R/W) */
182
183#define MCOR2_DSROD 0x80 /* Detect 1->0 transition of DSR */
184#define MCOR2_CDOD 0x40 /* Detect 1->0 transition of CD */
185#define MCOR2_CTSOD 0x20 /* Detect 1->0 transition of CTS */
186
187
188/* Modem Change Register (R/W) */
189
190#define MCR_DSRCHG 0x80 /* DSR Changed */
191#define MCR_CDCHG 0x40 /* CD Changed */
192#define MCR_CTSCHG 0x20 /* CTS Changed */
193
194
195/* Modem Signal Value Register (R/W) */
196
197#define MSVR_DSR 0x80 /* Current state of DSR input */
198#define MSVR_CD 0x40 /* Current state of CD input */
199#define MSVR_CTS 0x20 /* Current state of CTS input */
200#define MSVR_DTR 0x02 /* Current state of DTR output */
201#define MSVR_RTS 0x01 /* Current state of RTS output */
202
203
204/* Service Request Status Register */
205
206#define SRSR_CMASK 0xC0 /* Current Service Context Mask */
207#define SRSR_CNONE 0x00 /* Not in a service context */
208#define SRSR_CRX 0x40 /* Rx Context */
209#define SRSR_CTX 0x80 /* Tx Context */
210#define SRSR_CMDM 0xC0 /* Modem Context */
211#define SRSR_ANYINT 0x6F /* Any interrupt flag */
212#define SRSR_RINT 0x10 /* Receive Interrupt */
213#define SRSR_TINT 0x04 /* Transmit Interrupt */
214#define SRSR_MINT 0x01 /* Modem Interrupt */
215#define SRSR_REXT 0x20 /* Receive External Interrupt */
216#define SRSR_TEXT 0x08 /* Transmit External Interrupt */
217#define SRSR_MEXT 0x02 /* Modem External Interrupt */
218
219
220/* Service Request Configuration Register */
221
222#define SRCR_PKGTYPE 0x80
223#define SRCR_REGACKEN 0x40
224#define SRCR_DAISYEN 0x20
225#define SRCR_GLOBPRI 0x10
226#define SRCR_UNFAIR 0x08
227#define SRCR_AUTOPRI 0x02
228#define SRCR_PRISEL 0x01
229
230/* Values for register-based Interrupt ACKs */
231#define CD180_ACK_MINT 0x75 /* goes to MSMR */
232#define CD180_ACK_TINT 0x76 /* goes to TSMR */
233#define CD180_ACK_RINT 0x77 /* goes to RSMR */
234
235/* Escape characters */
236
237#define CD180_C_ESC 0x00 /* Escape character */
238#define CD180_C_SBRK 0x81 /* Start sending BREAK */
239#define CD180_C_DELAY 0x82 /* Delay output */
240#define CD180_C_EBRK 0x83 /* Stop sending BREAK */
diff --git a/drivers/sbus/char/uctrl.c b/drivers/sbus/char/uctrl.c
index 45cf5bc0bb..44d2ef906a 100644
--- a/drivers/sbus/char/uctrl.c
+++ b/drivers/sbus/char/uctrl.c
@@ -364,6 +364,7 @@ static int __init ts102_uctrl_init(void)
364 struct linux_prom_irqs tmp_irq[2]; 364 struct linux_prom_irqs tmp_irq[2];
365 unsigned int vaddr[2] = { 0, 0 }; 365 unsigned int vaddr[2] = { 0, 0 };
366 int tmpnode, uctrlnode = prom_getchild(prom_root_node); 366 int tmpnode, uctrlnode = prom_getchild(prom_root_node);
367 int err;
367 368
368 tmpnode = prom_searchsiblings(uctrlnode, "obio"); 369 tmpnode = prom_searchsiblings(uctrlnode, "obio");
369 370
@@ -389,7 +390,12 @@ static int __init ts102_uctrl_init(void)
389 if(!driver->irq) 390 if(!driver->irq)
390 driver->irq = tmp_irq[0].pri; 391 driver->irq = tmp_irq[0].pri;
391 392
392 request_irq(driver->irq, uctrl_interrupt, 0, "uctrl", driver); 393 err = request_irq(driver->irq, uctrl_interrupt, 0, "uctrl", driver);
394 if (err) {
395 printk("%s: unable to register irq %d\n",
396 __FUNCTION__, driver->irq);
397 return err;
398 }
393 399
394 if (misc_register(&uctrl_dev)) { 400 if (misc_register(&uctrl_dev)) {
395 printk("%s: unable to get misc minor %d\n", 401 printk("%s: unable to get misc minor %d\n",
diff --git a/drivers/sbus/char/vfc_i2c.c b/drivers/sbus/char/vfc_i2c.c
index ceec30648f..9efed771f6 100644
--- a/drivers/sbus/char/vfc_i2c.c
+++ b/drivers/sbus/char/vfc_i2c.c
@@ -14,7 +14,7 @@
14/* NOTE: It seems to me that the documentation regarding the 14/* NOTE: It seems to me that the documentation regarding the
15pcd8584t/pcf8584 does not show the correct way to address the i2c bus. 15pcd8584t/pcf8584 does not show the correct way to address the i2c bus.
16Based on the information on the I2C bus itself and the remainder of 16Based on the information on the I2C bus itself and the remainder of
17the Phillips docs the following algorithims apper to be correct. I am 17the Phillips docs the following algorithms appear to be correct. I am
18fairly certain that the flowcharts in the phillips docs are wrong. */ 18fairly certain that the flowcharts in the phillips docs are wrong. */
19 19
20 20
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 5bf3f07870..4cd280e869 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -230,6 +230,7 @@ config SCSI_SCAN_ASYNC
230 The SCSI subsystem can probe for devices while the rest of the 230 The SCSI subsystem can probe for devices while the rest of the
231 system continues booting, and even probe devices on different 231 system continues booting, and even probe devices on different
232 busses in parallel, leading to a significant speed-up. 232 busses in parallel, leading to a significant speed-up.
233
233 If you have built SCSI as modules, enabling this option can 234 If you have built SCSI as modules, enabling this option can
234 be a problem as the devices may not have been found by the 235 be a problem as the devices may not have been found by the
235 time your system expects them to have been. You can load the 236 time your system expects them to have been. You can load the
@@ -237,8 +238,8 @@ config SCSI_SCAN_ASYNC
237 If you build your SCSI drivers into the kernel, then everything 238 If you build your SCSI drivers into the kernel, then everything
238 will work fine if you say Y here. 239 will work fine if you say Y here.
239 240
240 You can override this choice by specifying scsi_mod.scan="sync" 241 You can override this choice by specifying "scsi_mod.scan=sync"
241 or "async" on the kernel's command line. 242 or async on the kernel's command line.
242 243
243menu "SCSI Transports" 244menu "SCSI Transports"
244 depends on SCSI 245 depends on SCSI
diff --git a/drivers/scsi/a100u2w.c b/drivers/scsi/a100u2w.c
index 2650a5d0a1..7f4241bfb9 100644
--- a/drivers/scsi/a100u2w.c
+++ b/drivers/scsi/a100u2w.c
@@ -1067,7 +1067,7 @@ static int __devinit inia100_probe_one(struct pci_dev *pdev,
1067 goto out_disable_device; 1067 goto out_disable_device;
1068 } 1068 }
1069 1069
1070 /* <02> read from base address + 0x50 offset to get the bios balue. */ 1070 /* <02> read from base address + 0x50 offset to get the bios value. */
1071 bios = ORC_RDWORD(port, 0x50); 1071 bios = ORC_RDWORD(port, 0x50);
1072 1072
1073 1073
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index c7fe478f48..2be03e975d 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -418,7 +418,6 @@ ahd_linux_info(struct Scsi_Host *host)
418 strcat(bp, " "); 418 strcat(bp, " ");
419 ahd_controller_info(ahd, ahd_info); 419 ahd_controller_info(ahd, ahd_info);
420 strcat(bp, ahd_info); 420 strcat(bp, ahd_info);
421 strcat(bp, "\n");
422 421
423 return (bp); 422 return (bp);
424} 423}
diff --git a/drivers/scsi/aic94xx/aic94xx_seq.c b/drivers/scsi/aic94xx/aic94xx_seq.c
index eae7a247be..c750fbf701 100644
--- a/drivers/scsi/aic94xx/aic94xx_seq.c
+++ b/drivers/scsi/aic94xx/aic94xx_seq.c
@@ -44,7 +44,6 @@
44#define PAUSE_TRIES 1000 44#define PAUSE_TRIES 1000
45 45
46static const struct firmware *sequencer_fw; 46static const struct firmware *sequencer_fw;
47static const char *sequencer_version;
48static u16 cseq_vecs[CSEQ_NUM_VECS], lseq_vecs[LSEQ_NUM_VECS], mode2_task, 47static u16 cseq_vecs[CSEQ_NUM_VECS], lseq_vecs[LSEQ_NUM_VECS], mode2_task,
49 cseq_idle_loop, lseq_idle_loop; 48 cseq_idle_loop, lseq_idle_loop;
50static u8 *cseq_code, *lseq_code; 49static u8 *cseq_code, *lseq_code;
@@ -1276,7 +1275,6 @@ static int asd_request_firmware(struct asd_ha_struct *asd_ha)
1276 header.csum = le32_to_cpu(hdr_ptr->csum); 1275 header.csum = le32_to_cpu(hdr_ptr->csum);
1277 header.major = le32_to_cpu(hdr_ptr->major); 1276 header.major = le32_to_cpu(hdr_ptr->major);
1278 header.minor = le32_to_cpu(hdr_ptr->minor); 1277 header.minor = le32_to_cpu(hdr_ptr->minor);
1279 sequencer_version = hdr_ptr->version;
1280 header.cseq_table_offset = le32_to_cpu(hdr_ptr->cseq_table_offset); 1278 header.cseq_table_offset = le32_to_cpu(hdr_ptr->cseq_table_offset);
1281 header.cseq_table_size = le32_to_cpu(hdr_ptr->cseq_table_size); 1279 header.cseq_table_size = le32_to_cpu(hdr_ptr->cseq_table_size);
1282 header.lseq_table_offset = le32_to_cpu(hdr_ptr->lseq_table_offset); 1280 header.lseq_table_offset = le32_to_cpu(hdr_ptr->lseq_table_offset);
@@ -1303,6 +1301,16 @@ static int asd_request_firmware(struct asd_ha_struct *asd_ha)
1303 return -EINVAL; 1301 return -EINVAL;
1304 } 1302 }
1305 1303
1304 asd_printk("Found sequencer Firmware version %d.%d (%s)\n",
1305 header.major, header.minor, hdr_ptr->version);
1306
1307 if (header.major != SAS_RAZOR_SEQUENCER_FW_MAJOR) {
1308 asd_printk("Firmware Major Version Mismatch;"
1309 "driver requires version %d.X",
1310 SAS_RAZOR_SEQUENCER_FW_MAJOR);
1311 return -EINVAL;
1312 }
1313
1306 ptr_cseq_vecs = (u16 *)&sequencer_fw->data[header.cseq_table_offset]; 1314 ptr_cseq_vecs = (u16 *)&sequencer_fw->data[header.cseq_table_offset];
1307 ptr_lseq_vecs = (u16 *)&sequencer_fw->data[header.lseq_table_offset]; 1315 ptr_lseq_vecs = (u16 *)&sequencer_fw->data[header.lseq_table_offset];
1308 mode2_task = header.mode2_task; 1316 mode2_task = header.mode2_task;
@@ -1335,7 +1343,6 @@ int asd_init_seqs(struct asd_ha_struct *asd_ha)
1335 return err; 1343 return err;
1336 } 1344 }
1337 1345
1338 asd_printk("using sequencer %s\n", sequencer_version);
1339 err = asd_seq_download_seqs(asd_ha); 1346 err = asd_seq_download_seqs(asd_ha);
1340 if (err) { 1347 if (err) {
1341 asd_printk("couldn't download sequencers for %s\n", 1348 asd_printk("couldn't download sequencers for %s\n",
diff --git a/drivers/scsi/aic94xx/aic94xx_seq.h b/drivers/scsi/aic94xx/aic94xx_seq.h
index 9437ff0ae3..2ea6a0d522 100644
--- a/drivers/scsi/aic94xx/aic94xx_seq.h
+++ b/drivers/scsi/aic94xx/aic94xx_seq.h
@@ -31,6 +31,7 @@
31#define LSEQ_NUM_VECS 11 31#define LSEQ_NUM_VECS 11
32 32
33#define SAS_RAZOR_SEQUENCER_FW_FILE "aic94xx-seq.fw" 33#define SAS_RAZOR_SEQUENCER_FW_FILE "aic94xx-seq.fw"
34#define SAS_RAZOR_SEQUENCER_FW_MAJOR 1
34 35
35/* Note: All quantites in the sequencer file are little endian */ 36/* Note: All quantites in the sequencer file are little endian */
36struct sequencer_file_header { 37struct sequencer_file_header {
diff --git a/drivers/scsi/arm/cumana_2.c b/drivers/scsi/arm/cumana_2.c
index d2d51dc51a..82add77ad1 100644
--- a/drivers/scsi/arm/cumana_2.c
+++ b/drivers/scsi/arm/cumana_2.c
@@ -178,10 +178,10 @@ cumanascsi_2_dma_setup(struct Scsi_Host *host, struct scsi_pointer *SCp,
178 dma_dir = DMA_MODE_READ, 178 dma_dir = DMA_MODE_READ,
179 alatch_dir = ALATCH_DMA_IN; 179 alatch_dir = ALATCH_DMA_IN;
180 180
181 dma_map_sg(dev, info->sg, bufs + 1, map_dir); 181 dma_map_sg(dev, info->sg, bufs, map_dir);
182 182
183 disable_dma(dmach); 183 disable_dma(dmach);
184 set_dma_sg(dmach, info->sg, bufs + 1); 184 set_dma_sg(dmach, info->sg, bufs);
185 writeb(alatch_dir, info->base + CUMANASCSI2_ALATCH); 185 writeb(alatch_dir, info->base + CUMANASCSI2_ALATCH);
186 set_dma_mode(dmach, dma_dir); 186 set_dma_mode(dmach, dma_dir);
187 enable_dma(dmach); 187 enable_dma(dmach);
diff --git a/drivers/scsi/arm/eesox.c b/drivers/scsi/arm/eesox.c
index 4677152142..ed06a8c19a 100644
--- a/drivers/scsi/arm/eesox.c
+++ b/drivers/scsi/arm/eesox.c
@@ -175,10 +175,10 @@ eesoxscsi_dma_setup(struct Scsi_Host *host, struct scsi_pointer *SCp,
175 map_dir = DMA_FROM_DEVICE, 175 map_dir = DMA_FROM_DEVICE,
176 dma_dir = DMA_MODE_READ; 176 dma_dir = DMA_MODE_READ;
177 177
178 dma_map_sg(dev, info->sg, bufs + 1, map_dir); 178 dma_map_sg(dev, info->sg, bufs, map_dir);
179 179
180 disable_dma(dmach); 180 disable_dma(dmach);
181 set_dma_sg(dmach, info->sg, bufs + 1); 181 set_dma_sg(dmach, info->sg, bufs);
182 set_dma_mode(dmach, dma_dir); 182 set_dma_mode(dmach, dma_dir);
183 enable_dma(dmach); 183 enable_dma(dmach);
184 return fasdma_real_all; 184 return fasdma_real_all;
@@ -196,7 +196,7 @@ static void eesoxscsi_buffer_in(void *buf, int length, void __iomem *base)
196 const void __iomem *reg_fas = base + EESOX_FAS216_OFFSET; 196 const void __iomem *reg_fas = base + EESOX_FAS216_OFFSET;
197 const void __iomem *reg_dmastat = base + EESOX_DMASTAT; 197 const void __iomem *reg_dmastat = base + EESOX_DMASTAT;
198 const void __iomem *reg_dmadata = base + EESOX_DMADATA; 198 const void __iomem *reg_dmadata = base + EESOX_DMADATA;
199 const register unsigned long mask = 0xffff; 199 register const unsigned long mask = 0xffff;
200 200
201 do { 201 do {
202 unsigned int status; 202 unsigned int status;
diff --git a/drivers/scsi/arm/fas216.c b/drivers/scsi/arm/fas216.c
index 2969cc0ff2..fb5f202843 100644
--- a/drivers/scsi/arm/fas216.c
+++ b/drivers/scsi/arm/fas216.c
@@ -633,7 +633,7 @@ static void fas216_updateptrs(FAS216_Info *info, int bytes_transferred)
633 633
634 BUG_ON(bytes_transferred < 0); 634 BUG_ON(bytes_transferred < 0);
635 635
636 info->SCpnt->request_bufflen -= bytes_transferred; 636 SCp->phase -= bytes_transferred;
637 637
638 while (bytes_transferred != 0) { 638 while (bytes_transferred != 0) {
639 if (SCp->this_residual > bytes_transferred) 639 if (SCp->this_residual > bytes_transferred)
@@ -715,7 +715,7 @@ static void fas216_cleanuptransfer(FAS216_Info *info)
715 return; 715 return;
716 716
717 if (dmatype == fasdma_real_all) 717 if (dmatype == fasdma_real_all)
718 total = info->SCpnt->request_bufflen; 718 total = info->scsi.SCp.phase;
719 else 719 else
720 total = info->scsi.SCp.this_residual; 720 total = info->scsi.SCp.this_residual;
721 721
@@ -753,7 +753,7 @@ static void fas216_transfer(FAS216_Info *info)
753 fas216_log(info, LOG_BUFFER, 753 fas216_log(info, LOG_BUFFER,
754 "starttransfer: buffer %p length 0x%06x reqlen 0x%06x", 754 "starttransfer: buffer %p length 0x%06x reqlen 0x%06x",
755 info->scsi.SCp.ptr, info->scsi.SCp.this_residual, 755 info->scsi.SCp.ptr, info->scsi.SCp.this_residual,
756 info->SCpnt->request_bufflen); 756 info->scsi.SCp.phase);
757 757
758 if (!info->scsi.SCp.ptr) { 758 if (!info->scsi.SCp.ptr) {
759 fas216_log(info, LOG_ERROR, "null buffer passed to " 759 fas216_log(info, LOG_ERROR, "null buffer passed to "
@@ -784,7 +784,7 @@ static void fas216_transfer(FAS216_Info *info)
784 info->dma.transfer_type = dmatype; 784 info->dma.transfer_type = dmatype;
785 785
786 if (dmatype == fasdma_real_all) 786 if (dmatype == fasdma_real_all)
787 fas216_set_stc(info, info->SCpnt->request_bufflen); 787 fas216_set_stc(info, info->scsi.SCp.phase);
788 else 788 else
789 fas216_set_stc(info, info->scsi.SCp.this_residual); 789 fas216_set_stc(info, info->scsi.SCp.this_residual);
790 790
@@ -2114,6 +2114,7 @@ request_sense:
2114 SCpnt->SCp.buffers_residual = 0; 2114 SCpnt->SCp.buffers_residual = 0;
2115 SCpnt->SCp.ptr = (char *)SCpnt->sense_buffer; 2115 SCpnt->SCp.ptr = (char *)SCpnt->sense_buffer;
2116 SCpnt->SCp.this_residual = sizeof(SCpnt->sense_buffer); 2116 SCpnt->SCp.this_residual = sizeof(SCpnt->sense_buffer);
2117 SCpnt->SCp.phase = sizeof(SCpnt->sense_buffer);
2117 SCpnt->SCp.Message = 0; 2118 SCpnt->SCp.Message = 0;
2118 SCpnt->SCp.Status = 0; 2119 SCpnt->SCp.Status = 0;
2119 SCpnt->request_bufflen = sizeof(SCpnt->sense_buffer); 2120 SCpnt->request_bufflen = sizeof(SCpnt->sense_buffer);
diff --git a/drivers/scsi/arm/powertec.c b/drivers/scsi/arm/powertec.c
index f9cd20bfb9..159047a349 100644
--- a/drivers/scsi/arm/powertec.c
+++ b/drivers/scsi/arm/powertec.c
@@ -148,10 +148,10 @@ powertecscsi_dma_setup(struct Scsi_Host *host, struct scsi_pointer *SCp,
148 map_dir = DMA_FROM_DEVICE, 148 map_dir = DMA_FROM_DEVICE,
149 dma_dir = DMA_MODE_READ; 149 dma_dir = DMA_MODE_READ;
150 150
151 dma_map_sg(dev, info->sg, bufs + 1, map_dir); 151 dma_map_sg(dev, info->sg, bufs, map_dir);
152 152
153 disable_dma(dmach); 153 disable_dma(dmach);
154 set_dma_sg(dmach, info->sg, bufs + 1); 154 set_dma_sg(dmach, info->sg, bufs);
155 set_dma_mode(dmach, dma_dir); 155 set_dma_mode(dmach, dma_dir);
156 enable_dma(dmach); 156 enable_dma(dmach);
157 return fasdma_real_all; 157 return fasdma_real_all;
@@ -342,6 +342,7 @@ powertecscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
342 info->base = base; 342 info->base = base;
343 powertecscsi_terminator_ctl(host, term[ec->slot_no]); 343 powertecscsi_terminator_ctl(host, term[ec->slot_no]);
344 344
345 info->ec = ec;
345 info->info.scsi.io_base = base + POWERTEC_FAS216_OFFSET; 346 info->info.scsi.io_base = base + POWERTEC_FAS216_OFFSET;
346 info->info.scsi.io_shift = POWERTEC_FAS216_SHIFT; 347 info->info.scsi.io_shift = POWERTEC_FAS216_SHIFT;
347 info->info.scsi.irq = ec->irq; 348 info->info.scsi.irq = ec->irq;
diff --git a/drivers/scsi/arm/scsi.h b/drivers/scsi/arm/scsi.h
index 3a39579bd0..21ba57155b 100644
--- a/drivers/scsi/arm/scsi.h
+++ b/drivers/scsi/arm/scsi.h
@@ -80,6 +80,7 @@ static inline void init_SCp(struct scsi_cmnd *SCpnt)
80 (page_address(SCpnt->SCp.buffer->page) + 80 (page_address(SCpnt->SCp.buffer->page) +
81 SCpnt->SCp.buffer->offset); 81 SCpnt->SCp.buffer->offset);
82 SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length; 82 SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
83 SCpnt->SCp.phase = SCpnt->request_bufflen;
83 84
84#ifdef BELT_AND_BRACES 85#ifdef BELT_AND_BRACES
85 /* 86 /*
@@ -98,6 +99,7 @@ static inline void init_SCp(struct scsi_cmnd *SCpnt)
98 } else { 99 } else {
99 SCpnt->SCp.ptr = (unsigned char *)SCpnt->request_buffer; 100 SCpnt->SCp.ptr = (unsigned char *)SCpnt->request_buffer;
100 SCpnt->SCp.this_residual = SCpnt->request_bufflen; 101 SCpnt->SCp.this_residual = SCpnt->request_bufflen;
102 SCpnt->SCp.phase = SCpnt->request_bufflen;
101 } 103 }
102 104
103 /* 105 /*
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index 8f6b5bf580..2b5b8a93bc 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -801,15 +801,10 @@ static int idescsi_ide_open(struct inode *inode, struct file *filp)
801{ 801{
802 struct gendisk *disk = inode->i_bdev->bd_disk; 802 struct gendisk *disk = inode->i_bdev->bd_disk;
803 struct ide_scsi_obj *scsi; 803 struct ide_scsi_obj *scsi;
804 ide_drive_t *drive;
805 804
806 if (!(scsi = ide_scsi_get(disk))) 805 if (!(scsi = ide_scsi_get(disk)))
807 return -ENXIO; 806 return -ENXIO;
808 807
809 drive = scsi->drive;
810
811 drive->usage++;
812
813 return 0; 808 return 0;
814} 809}
815 810
@@ -817,9 +812,6 @@ static int idescsi_ide_release(struct inode *inode, struct file *filp)
817{ 812{
818 struct gendisk *disk = inode->i_bdev->bd_disk; 813 struct gendisk *disk = inode->i_bdev->bd_disk;
819 struct ide_scsi_obj *scsi = ide_scsi_g(disk); 814 struct ide_scsi_obj *scsi = ide_scsi_g(disk);
820 ide_drive_t *drive = scsi->drive;
821
822 drive->usage--;
823 815
824 ide_scsi_put(scsi); 816 ide_scsi_put(scsi);
825 817
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index afca45cdbc..9d014e5a81 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -518,6 +518,10 @@ lpfc_handle_eratt(struct lpfc_hba * phba)
518 struct lpfc_sli *psli = &phba->sli; 518 struct lpfc_sli *psli = &phba->sli;
519 struct lpfc_sli_ring *pring; 519 struct lpfc_sli_ring *pring;
520 uint32_t event_data; 520 uint32_t event_data;
521 /* If the pci channel is offline, ignore possible errors,
522 * since we cannot communicate with the pci card anyway. */
523 if (pci_channel_offline(phba->pcidev))
524 return;
521 525
522 if (phba->work_hs & HS_FFER6 || 526 if (phba->work_hs & HS_FFER6 ||
523 phba->work_hs & HS_FFER5) { 527 phba->work_hs & HS_FFER5) {
@@ -1797,6 +1801,92 @@ lpfc_pci_remove_one(struct pci_dev *pdev)
1797 pci_set_drvdata(pdev, NULL); 1801 pci_set_drvdata(pdev, NULL);
1798} 1802}
1799 1803
1804/**
1805 * lpfc_io_error_detected - called when PCI error is detected
1806 * @pdev: Pointer to PCI device
1807 * @state: The current pci conneection state
1808 *
1809 * This function is called after a PCI bus error affecting
1810 * this device has been detected.
1811 */
1812static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
1813 pci_channel_state_t state)
1814{
1815 struct Scsi_Host *host = pci_get_drvdata(pdev);
1816 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
1817 struct lpfc_sli *psli = &phba->sli;
1818 struct lpfc_sli_ring *pring;
1819
1820 if (state == pci_channel_io_perm_failure) {
1821 lpfc_pci_remove_one(pdev);
1822 return PCI_ERS_RESULT_DISCONNECT;
1823 }
1824 pci_disable_device(pdev);
1825 /*
1826 * There may be I/Os dropped by the firmware.
1827 * Error iocb (I/O) on txcmplq and let the SCSI layer
1828 * retry it after re-establishing link.
1829 */
1830 pring = &psli->ring[psli->fcp_ring];
1831 lpfc_sli_abort_iocb_ring(phba, pring);
1832
1833 /* Request a slot reset. */
1834 return PCI_ERS_RESULT_NEED_RESET;
1835}
1836
1837/**
1838 * lpfc_io_slot_reset - called after the pci bus has been reset.
1839 * @pdev: Pointer to PCI device
1840 *
1841 * Restart the card from scratch, as if from a cold-boot.
1842 */
1843static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
1844{
1845 struct Scsi_Host *host = pci_get_drvdata(pdev);
1846 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
1847 struct lpfc_sli *psli = &phba->sli;
1848 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
1849
1850 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
1851 if (pci_enable_device_bars(pdev, bars)) {
1852 printk(KERN_ERR "lpfc: Cannot re-enable "
1853 "PCI device after reset.\n");
1854 return PCI_ERS_RESULT_DISCONNECT;
1855 }
1856
1857 pci_set_master(pdev);
1858
1859 /* Re-establishing Link */
1860 spin_lock_irq(phba->host->host_lock);
1861 phba->fc_flag |= FC_ESTABLISH_LINK;
1862 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
1863 spin_unlock_irq(phba->host->host_lock);
1864
1865
1866 /* Take device offline; this will perform cleanup */
1867 lpfc_offline(phba);
1868 lpfc_sli_brdrestart(phba);
1869
1870 return PCI_ERS_RESULT_RECOVERED;
1871}
1872
1873/**
1874 * lpfc_io_resume - called when traffic can start flowing again.
1875 * @pdev: Pointer to PCI device
1876 *
1877 * This callback is called when the error recovery driver tells us that
1878 * its OK to resume normal operation.
1879 */
1880static void lpfc_io_resume(struct pci_dev *pdev)
1881{
1882 struct Scsi_Host *host = pci_get_drvdata(pdev);
1883 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
1884
1885 if (lpfc_online(phba) == 0) {
1886 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
1887 }
1888}
1889
1800static struct pci_device_id lpfc_id_table[] = { 1890static struct pci_device_id lpfc_id_table[] = {
1801 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, 1891 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
1802 PCI_ANY_ID, PCI_ANY_ID, }, 1892 PCI_ANY_ID, PCI_ANY_ID, },
@@ -1857,11 +1947,18 @@ static struct pci_device_id lpfc_id_table[] = {
1857 1947
1858MODULE_DEVICE_TABLE(pci, lpfc_id_table); 1948MODULE_DEVICE_TABLE(pci, lpfc_id_table);
1859 1949
1950static struct pci_error_handlers lpfc_err_handler = {
1951 .error_detected = lpfc_io_error_detected,
1952 .slot_reset = lpfc_io_slot_reset,
1953 .resume = lpfc_io_resume,
1954};
1955
1860static struct pci_driver lpfc_driver = { 1956static struct pci_driver lpfc_driver = {
1861 .name = LPFC_DRIVER_NAME, 1957 .name = LPFC_DRIVER_NAME,
1862 .id_table = lpfc_id_table, 1958 .id_table = lpfc_id_table,
1863 .probe = lpfc_pci_probe_one, 1959 .probe = lpfc_pci_probe_one,
1864 .remove = __devexit_p(lpfc_pci_remove_one), 1960 .remove = __devexit_p(lpfc_pci_remove_one),
1961 .err_handler = &lpfc_err_handler,
1865}; 1962};
1866 1963
1867static int __init 1964static int __init
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index a4128e1933..9fb6960a8a 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -2104,6 +2104,10 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2104 volatile uint32_t word0, ldata; 2104 volatile uint32_t word0, ldata;
2105 void __iomem *to_slim; 2105 void __iomem *to_slim;
2106 2106
2107 /* If the PCI channel is in offline state, do not post mbox. */
2108 if (unlikely(pci_channel_offline(phba->pcidev)))
2109 return MBX_NOT_FINISHED;
2110
2107 psli = &phba->sli; 2111 psli = &phba->sli;
2108 2112
2109 spin_lock_irqsave(phba->host->host_lock, drvr_flag); 2113 spin_lock_irqsave(phba->host->host_lock, drvr_flag);
@@ -2407,6 +2411,10 @@ lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2407 struct lpfc_iocbq *nextiocb; 2411 struct lpfc_iocbq *nextiocb;
2408 IOCB_t *iocb; 2412 IOCB_t *iocb;
2409 2413
2414 /* If the PCI channel is in offline state, do not post iocbs. */
2415 if (unlikely(pci_channel_offline(phba->pcidev)))
2416 return IOCB_ERROR;
2417
2410 /* 2418 /*
2411 * We should never get an IOCB if we are in a < LINK_DOWN state 2419 * We should never get an IOCB if we are in a < LINK_DOWN state
2412 */ 2420 */
@@ -3154,6 +3162,10 @@ lpfc_intr_handler(int irq, void *dev_id)
3154 if (unlikely(!phba)) 3162 if (unlikely(!phba))
3155 return IRQ_NONE; 3163 return IRQ_NONE;
3156 3164
3165 /* If the pci channel is offline, ignore all the interrupts. */
3166 if (unlikely(pci_channel_offline(phba->pcidev)))
3167 return IRQ_NONE;
3168
3157 phba->sli.slistat.sli_intr++; 3169 phba->sli.slistat.sli_intr++;
3158 3170
3159 /* 3171 /*
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 808a1b8c40..0aa3304f6b 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -5072,7 +5072,7 @@ static int __init megaraid_init(void)
5072 "megaraid: failed to create megaraid root\n"); 5072 "megaraid: failed to create megaraid root\n");
5073 } 5073 }
5074#endif 5074#endif
5075 error = pci_module_init(&megaraid_pci_driver); 5075 error = pci_register_driver(&megaraid_pci_driver);
5076 if (error) { 5076 if (error) {
5077#ifdef CONFIG_PROC_FS 5077#ifdef CONFIG_PROC_FS
5078 remove_proc_entry("megaraid", &proc_root); 5078 remove_proc_entry("megaraid", &proc_root);
diff --git a/drivers/scsi/megaraid/megaraid_sas.c b/drivers/scsi/megaraid/megaraid_sas.c
index 15e24fcc84..7a812677ff 100644
--- a/drivers/scsi/megaraid/megaraid_sas.c
+++ b/drivers/scsi/megaraid/megaraid_sas.c
@@ -10,11 +10,13 @@
10 * 2 of the License, or (at your option) any later version. 10 * 2 of the License, or (at your option) any later version.
11 * 11 *
12 * FILE : megaraid_sas.c 12 * FILE : megaraid_sas.c
13 * Version : v00.00.03.05 13 * Version : v00.00.03.10-rc1
14 * 14 *
15 * Authors: 15 * Authors:
16 * Sreenivas Bagalkote <Sreenivas.Bagalkote@lsi.com> 16 * (email-id : megaraidlinux@lsi.com)
17 * Sumant Patro <Sumant.Patro@lsi.com> 17 * Sreenivas Bagalkote
18 * Sumant Patro
19 * Bo Yang
18 * 20 *
19 * List of supported controllers 21 * List of supported controllers
20 * 22 *
@@ -35,6 +37,7 @@
35#include <asm/uaccess.h> 37#include <asm/uaccess.h>
36#include <linux/fs.h> 38#include <linux/fs.h>
37#include <linux/compat.h> 39#include <linux/compat.h>
40#include <linux/blkdev.h>
38#include <linux/mutex.h> 41#include <linux/mutex.h>
39 42
40#include <scsi/scsi.h> 43#include <scsi/scsi.h>
@@ -841,6 +844,11 @@ megasas_queue_command(struct scsi_cmnd *scmd, void (*done) (struct scsi_cmnd *))
841 844
842 instance = (struct megasas_instance *) 845 instance = (struct megasas_instance *)
843 scmd->device->host->hostdata; 846 scmd->device->host->hostdata;
847
848 /* Don't process if we have already declared adapter dead */
849 if (instance->hw_crit_error)
850 return SCSI_MLQUEUE_HOST_BUSY;
851
844 scmd->scsi_done = done; 852 scmd->scsi_done = done;
845 scmd->result = 0; 853 scmd->result = 0;
846 854
@@ -850,6 +858,18 @@ megasas_queue_command(struct scsi_cmnd *scmd, void (*done) (struct scsi_cmnd *))
850 goto out_done; 858 goto out_done;
851 } 859 }
852 860
861 switch (scmd->cmnd[0]) {
862 case SYNCHRONIZE_CACHE:
863 /*
864 * FW takes care of flush cache on its own
865 * No need to send it down
866 */
867 scmd->result = DID_OK << 16;
868 goto out_done;
869 default:
870 break;
871 }
872
853 cmd = megasas_get_cmd(instance); 873 cmd = megasas_get_cmd(instance);
854 if (!cmd) 874 if (!cmd)
855 return SCSI_MLQUEUE_HOST_BUSY; 875 return SCSI_MLQUEUE_HOST_BUSY;
@@ -1010,6 +1030,49 @@ static int megasas_reset_bus_host(struct scsi_cmnd *scmd)
1010} 1030}
1011 1031
1012/** 1032/**
1033 * megasas_bios_param - Returns disk geometry for a disk
1034 * @sdev: device handle
1035 * @bdev: block device
1036 * @capacity: drive capacity
1037 * @geom: geometry parameters
1038 */
1039static int
1040megasas_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1041 sector_t capacity, int geom[])
1042{
1043 int heads;
1044 int sectors;
1045 sector_t cylinders;
1046 unsigned long tmp;
1047 /* Default heads (64) & sectors (32) */
1048 heads = 64;
1049 sectors = 32;
1050
1051 tmp = heads * sectors;
1052 cylinders = capacity;
1053
1054 sector_div(cylinders, tmp);
1055
1056 /*
1057 * Handle extended translation size for logical drives > 1Gb
1058 */
1059
1060 if (capacity >= 0x200000) {
1061 heads = 255;
1062 sectors = 63;
1063 tmp = heads*sectors;
1064 cylinders = capacity;
1065 sector_div(cylinders, tmp);
1066 }
1067
1068 geom[0] = heads;
1069 geom[1] = sectors;
1070 geom[2] = cylinders;
1071
1072 return 0;
1073}
1074
1075/**
1013 * megasas_service_aen - Processes an event notification 1076 * megasas_service_aen - Processes an event notification
1014 * @instance: Adapter soft state 1077 * @instance: Adapter soft state
1015 * @cmd: AEN command completed by the ISR 1078 * @cmd: AEN command completed by the ISR
@@ -1049,6 +1112,7 @@ static struct scsi_host_template megasas_template = {
1049 .eh_device_reset_handler = megasas_reset_device, 1112 .eh_device_reset_handler = megasas_reset_device,
1050 .eh_bus_reset_handler = megasas_reset_bus_host, 1113 .eh_bus_reset_handler = megasas_reset_bus_host,
1051 .eh_host_reset_handler = megasas_reset_bus_host, 1114 .eh_host_reset_handler = megasas_reset_bus_host,
1115 .bios_param = megasas_bios_param,
1052 .use_clustering = ENABLE_CLUSTERING, 1116 .use_clustering = ENABLE_CLUSTERING,
1053}; 1117};
1054 1118
@@ -1282,11 +1346,13 @@ megasas_deplete_reply_queue(struct megasas_instance *instance, u8 alt_status)
1282 if(instance->instancet->clear_intr(instance->reg_set)) 1346 if(instance->instancet->clear_intr(instance->reg_set))
1283 return IRQ_NONE; 1347 return IRQ_NONE;
1284 1348
1349 if (instance->hw_crit_error)
1350 goto out_done;
1285 /* 1351 /*
1286 * Schedule the tasklet for cmd completion 1352 * Schedule the tasklet for cmd completion
1287 */ 1353 */
1288 tasklet_schedule(&instance->isr_tasklet); 1354 tasklet_schedule(&instance->isr_tasklet);
1289 1355out_done:
1290 return IRQ_HANDLED; 1356 return IRQ_HANDLED;
1291} 1357}
1292 1358
@@ -1741,6 +1807,10 @@ static void megasas_complete_cmd_dpc(unsigned long instance_addr)
1741 struct megasas_cmd *cmd; 1807 struct megasas_cmd *cmd;
1742 struct megasas_instance *instance = (struct megasas_instance *)instance_addr; 1808 struct megasas_instance *instance = (struct megasas_instance *)instance_addr;
1743 1809
1810 /* If we have already declared adapter dead, donot complete cmds */
1811 if (instance->hw_crit_error)
1812 return;
1813
1744 producer = *instance->producer; 1814 producer = *instance->producer;
1745 consumer = *instance->consumer; 1815 consumer = *instance->consumer;
1746 1816
@@ -2655,9 +2725,9 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
2655 * For each user buffer, create a mirror buffer and copy in 2725 * For each user buffer, create a mirror buffer and copy in
2656 */ 2726 */
2657 for (i = 0; i < ioc->sge_count; i++) { 2727 for (i = 0; i < ioc->sge_count; i++) {
2658 kbuff_arr[i] = pci_alloc_consistent(instance->pdev, 2728 kbuff_arr[i] = dma_alloc_coherent(&instance->pdev->dev,
2659 ioc->sgl[i].iov_len, 2729 ioc->sgl[i].iov_len,
2660 &buf_handle); 2730 &buf_handle, GFP_KERNEL);
2661 if (!kbuff_arr[i]) { 2731 if (!kbuff_arr[i]) {
2662 printk(KERN_DEBUG "megasas: Failed to alloc " 2732 printk(KERN_DEBUG "megasas: Failed to alloc "
2663 "kernel SGL buffer for IOCTL \n"); 2733 "kernel SGL buffer for IOCTL \n");
@@ -2684,8 +2754,8 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
2684 } 2754 }
2685 2755
2686 if (ioc->sense_len) { 2756 if (ioc->sense_len) {
2687 sense = pci_alloc_consistent(instance->pdev, ioc->sense_len, 2757 sense = dma_alloc_coherent(&instance->pdev->dev, ioc->sense_len,
2688 &sense_handle); 2758 &sense_handle, GFP_KERNEL);
2689 if (!sense) { 2759 if (!sense) {
2690 error = -ENOMEM; 2760 error = -ENOMEM;
2691 goto out; 2761 goto out;
@@ -2744,12 +2814,12 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
2744 2814
2745 out: 2815 out:
2746 if (sense) { 2816 if (sense) {
2747 pci_free_consistent(instance->pdev, ioc->sense_len, 2817 dma_free_coherent(&instance->pdev->dev, ioc->sense_len,
2748 sense, sense_handle); 2818 sense, sense_handle);
2749 } 2819 }
2750 2820
2751 for (i = 0; i < ioc->sge_count && kbuff_arr[i]; i++) { 2821 for (i = 0; i < ioc->sge_count && kbuff_arr[i]; i++) {
2752 pci_free_consistent(instance->pdev, 2822 dma_free_coherent(&instance->pdev->dev,
2753 kern_sge32[i].length, 2823 kern_sge32[i].length,
2754 kbuff_arr[i], kern_sge32[i].phys_addr); 2824 kbuff_arr[i], kern_sge32[i].phys_addr);
2755 } 2825 }
diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index cacb3ad925..e862992ee3 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -18,9 +18,9 @@
18/* 18/*
19 * MegaRAID SAS Driver meta data 19 * MegaRAID SAS Driver meta data
20 */ 20 */
21#define MEGASAS_VERSION "00.00.03.05" 21#define MEGASAS_VERSION "00.00.03.10-rc1"
22#define MEGASAS_RELDATE "Oct 02, 2006" 22#define MEGASAS_RELDATE "Feb 14, 2007"
23#define MEGASAS_EXT_VERSION "Mon Oct 02 11:21:32 PDT 2006" 23#define MEGASAS_EXT_VERSION "Wed Feb 14 10:14:25 PST 2007"
24 24
25/* 25/*
26 * Device IDs 26 * Device IDs
diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
index 9668b73872..a967fadb74 100644
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -5574,14 +5574,14 @@ static ssize_t osst_version_show(struct device_driver *ddd, char *buf)
5574 5574
5575static DRIVER_ATTR(version, S_IRUGO, osst_version_show, NULL); 5575static DRIVER_ATTR(version, S_IRUGO, osst_version_show, NULL);
5576 5576
5577static int osst_create_driverfs_files(struct device_driver *driverfs) 5577static int osst_create_sysfs_files(struct device_driver *sysfs)
5578{ 5578{
5579 return driver_create_file(driverfs, &driver_attr_version); 5579 return driver_create_file(sysfs, &driver_attr_version);
5580} 5580}
5581 5581
5582static void osst_remove_driverfs_files(struct device_driver *driverfs) 5582static void osst_remove_sysfs_files(struct device_driver *sysfs)
5583{ 5583{
5584 driver_remove_file(driverfs, &driver_attr_version); 5584 driver_remove_file(sysfs, &driver_attr_version);
5585} 5585}
5586 5586
5587/* 5587/*
@@ -5953,7 +5953,7 @@ static int __init init_osst(void)
5953 if (err) 5953 if (err)
5954 goto err_out_chrdev; 5954 goto err_out_chrdev;
5955 5955
5956 err = osst_create_driverfs_files(&osst_template.gendrv); 5956 err = osst_create_sysfs_files(&osst_template.gendrv);
5957 if (err) 5957 if (err)
5958 goto err_out_scsidrv; 5958 goto err_out_scsidrv;
5959 5959
@@ -5973,7 +5973,7 @@ static void __exit exit_osst (void)
5973 int i; 5973 int i;
5974 struct osst_tape * STp; 5974 struct osst_tape * STp;
5975 5975
5976 osst_remove_driverfs_files(&osst_template.gendrv); 5976 osst_remove_sysfs_files(&osst_template.gendrv);
5977 scsi_unregister_driver(&osst_template.gendrv); 5977 scsi_unregister_driver(&osst_template.gendrv);
5978 unregister_chrdev(OSST_MAJOR, "osst"); 5978 unregister_chrdev(OSST_MAJOR, "osst");
5979 osst_sysfs_cleanup(); 5979 osst_sysfs_cleanup();
diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c
index 69d6e9b198..bb6f051bed 100644
--- a/drivers/scsi/scsi_proc.c
+++ b/drivers/scsi/scsi_proc.c
@@ -179,9 +179,8 @@ static int proc_print_scsidevice(struct device *dev, void *data)
179 seq_printf(s, "\n"); 179 seq_printf(s, "\n");
180 180
181 seq_printf(s, " Type: %s ", scsi_device_type(sdev->type)); 181 seq_printf(s, " Type: %s ", scsi_device_type(sdev->type));
182 seq_printf(s, " ANSI" 182 seq_printf(s, " ANSI SCSI revision: %02x",
183 " SCSI revision: %02x", (sdev->scsi_level - 1) ? 183 sdev->scsi_level - (sdev->scsi_level > 1));
184 sdev->scsi_level - 1 : 1);
185 if (sdev->scsi_level == 2) 184 if (sdev->scsi_level == 2)
186 seq_printf(s, " CCS\n"); 185 seq_printf(s, " CCS\n");
187 else 186 else
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index a43b9ec3ae..0949145304 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -54,7 +54,7 @@
54#define SCSI_TIMEOUT (2*HZ) 54#define SCSI_TIMEOUT (2*HZ)
55 55
56/* 56/*
57 * Prefix values for the SCSI id's (stored in driverfs name field) 57 * Prefix values for the SCSI id's (stored in sysfs name field)
58 */ 58 */
59#define SCSI_UID_SER_NUM 'S' 59#define SCSI_UID_SER_NUM 'S'
60#define SCSI_UID_UNKNOWN 'Z' 60#define SCSI_UID_UNKNOWN 'Z'
@@ -385,6 +385,7 @@ static struct scsi_target *scsi_alloc_target(struct device *parent,
385 INIT_LIST_HEAD(&starget->siblings); 385 INIT_LIST_HEAD(&starget->siblings);
386 INIT_LIST_HEAD(&starget->devices); 386 INIT_LIST_HEAD(&starget->devices);
387 starget->state = STARGET_RUNNING; 387 starget->state = STARGET_RUNNING;
388 starget->scsi_level = SCSI_2;
388 retry: 389 retry:
389 spin_lock_irqsave(shost->host_lock, flags); 390 spin_lock_irqsave(shost->host_lock, flags);
390 391
@@ -654,6 +655,19 @@ static int scsi_probe_lun(struct scsi_device *sdev, unsigned char *inq_result,
654 * short INQUIRY), an abort here prevents any further use of the 655 * short INQUIRY), an abort here prevents any further use of the
655 * device, including spin up. 656 * device, including spin up.
656 * 657 *
658 * On the whole, the best approach seems to be to assume the first
659 * 36 bytes are valid no matter what the device says. That's
660 * better than copying < 36 bytes to the inquiry-result buffer
661 * and displaying garbage for the Vendor, Product, or Revision
662 * strings.
663 */
664 if (sdev->inquiry_len < 36) {
665 printk(KERN_INFO "scsi scan: INQUIRY result too short (%d),"
666 " using 36\n", sdev->inquiry_len);
667 sdev->inquiry_len = 36;
668 }
669
670 /*
657 * Related to the above issue: 671 * Related to the above issue:
658 * 672 *
659 * XXX Devices (disk or all?) should be sent a TEST UNIT READY, 673 * XXX Devices (disk or all?) should be sent a TEST UNIT READY,
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 259c90cfa3..c275dcac3f 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -922,7 +922,7 @@ void scsi_sysfs_device_initialize(struct scsi_device *sdev)
922 snprintf(sdev->sdev_classdev.class_id, BUS_ID_SIZE, 922 snprintf(sdev->sdev_classdev.class_id, BUS_ID_SIZE,
923 "%d:%d:%d:%d", sdev->host->host_no, 923 "%d:%d:%d:%d", sdev->host->host_no,
924 sdev->channel, sdev->id, sdev->lun); 924 sdev->channel, sdev->id, sdev->lun);
925 sdev->scsi_level = SCSI_2; 925 sdev->scsi_level = starget->scsi_level;
926 transport_setup_device(&sdev->sdev_gendev); 926 transport_setup_device(&sdev->sdev_gendev);
927 spin_lock_irqsave(shost->host_lock, flags); 927 spin_lock_irqsave(shost->host_lock, flags);
928 list_add_tail(&sdev->same_target_siblings, &starget->devices); 928 list_add_tail(&sdev->same_target_siblings, &starget->devices);
diff --git a/drivers/scsi/scsi_tgt_if.c b/drivers/scsi/scsi_tgt_if.c
index f2344ab8de..0e08817fde 100644
--- a/drivers/scsi/scsi_tgt_if.c
+++ b/drivers/scsi/scsi_tgt_if.c
@@ -33,6 +33,14 @@
33 33
34#include "scsi_tgt_priv.h" 34#include "scsi_tgt_priv.h"
35 35
36#if TGT_RING_SIZE < PAGE_SIZE
37# define TGT_RING_SIZE PAGE_SIZE
38#endif
39
40#define TGT_RING_PAGES (TGT_RING_SIZE >> PAGE_SHIFT)
41#define TGT_EVENT_PER_PAGE (PAGE_SIZE / sizeof(struct tgt_event))
42#define TGT_MAX_EVENTS (TGT_EVENT_PER_PAGE * TGT_RING_PAGES)
43
36struct tgt_ring { 44struct tgt_ring {
37 u32 tr_idx; 45 u32 tr_idx;
38 unsigned long tr_pages[TGT_RING_PAGES]; 46 unsigned long tr_pages[TGT_RING_PAGES];
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 0d3c10f213..58afdb4017 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -855,7 +855,7 @@ static FC_CLASS_DEVICE_ATTR(rport, fast_io_fail_tmo, S_IRUGO | S_IWUSR,
855 855
856/* 856/*
857 * Note: in the target show function we recognize when the remote 857 * Note: in the target show function we recognize when the remote
858 * port is in the heirarchy and do not allow the driver to get 858 * port is in the hierarchy and do not allow the driver to get
859 * involved in sysfs functions. The driver only gets involved if 859 * involved in sysfs functions. The driver only gets involved if
860 * it's the "old" style that doesn't use rports. 860 * it's the "old" style that doesn't use rports.
861 */ 861 */
diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c
index 6d39150e20..b2ef71a862 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -500,7 +500,7 @@ struct sas_phy *sas_phy_alloc(struct device *parent, int number)
500EXPORT_SYMBOL(sas_phy_alloc); 500EXPORT_SYMBOL(sas_phy_alloc);
501 501
502/** 502/**
503 * sas_phy_add -- add a SAS PHY to the device hierachy 503 * sas_phy_add -- add a SAS PHY to the device hierarchy
504 * @phy: The PHY to be added 504 * @phy: The PHY to be added
505 * 505 *
506 * Publishes a SAS PHY to the rest of the system. 506 * Publishes a SAS PHY to the rest of the system.
@@ -1265,7 +1265,7 @@ struct sas_rphy *sas_expander_alloc(struct sas_port *parent,
1265EXPORT_SYMBOL(sas_expander_alloc); 1265EXPORT_SYMBOL(sas_expander_alloc);
1266 1266
1267/** 1267/**
1268 * sas_rphy_add -- add a SAS remote PHY to the device hierachy 1268 * sas_rphy_add -- add a SAS remote PHY to the device hierarchy
1269 * @rphy: The remote PHY to be added 1269 * @rphy: The remote PHY to be added
1270 * 1270 *
1271 * Publishes a SAS remote PHY to the rest of the system. 1271 * Publishes a SAS remote PHY to the rest of the system.
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 3f048bd632..5a8f55fea5 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1269,9 +1269,18 @@ repeat:
1269 1269
1270 /* Some devices return the total number of sectors, not the 1270 /* Some devices return the total number of sectors, not the
1271 * highest sector number. Make the necessary adjustment. */ 1271 * highest sector number. Make the necessary adjustment. */
1272 if (sdp->fix_capacity) 1272 if (sdp->fix_capacity) {
1273 --sdkp->capacity; 1273 --sdkp->capacity;
1274 1274
1275 /* Some devices have version which report the correct sizes
1276 * and others which do not. We guess size according to a heuristic
1277 * and err on the side of lowering the capacity. */
1278 } else {
1279 if (sdp->guess_capacity)
1280 if (sdkp->capacity & 0x01) /* odd sizes are odd */
1281 --sdkp->capacity;
1282 }
1283
1275got_data: 1284got_data:
1276 if (sector_size == 0) { 1285 if (sector_size == 0) {
1277 sector_size = 512; 1286 sector_size = 512;
diff --git a/drivers/scsi/sgiwd93.c b/drivers/scsi/sgiwd93.c
index e81f97a35b..a15752b379 100644
--- a/drivers/scsi/sgiwd93.c
+++ b/drivers/scsi/sgiwd93.c
@@ -244,9 +244,10 @@ static struct Scsi_Host * __init sgiwd93_setup_scsi(
244 regs.SASR = wdregs + 3; 244 regs.SASR = wdregs + 3;
245 regs.SCMD = wdregs + 7; 245 regs.SCMD = wdregs + 7;
246 246
247 wd33c93_init(host, regs, dma_setup, dma_stop, WD33C93_FS_16_20); 247 wd33c93_init(host, regs, dma_setup, dma_stop, WD33C93_FS_MHZ(20));
248 248
249 hdata->wh.no_sync = 0; 249 if (hdata->wh.no_sync == 0xff)
250 hdata->wh.no_sync = 0;
250 251
251 if (request_irq(irq, sgiwd93_intr, 0, "SGI WD93", (void *) host)) { 252 if (request_irq(irq, sgiwd93_intr, 0, "SGI WD93", (void *) host)) {
252 printk(KERN_WARNING "sgiwd93: Could not register irq %d " 253 printk(KERN_WARNING "sgiwd93: Could not register irq %d "
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 3d2e02381e..98d8411bbc 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -195,8 +195,8 @@ static int sgl_unmap_user_pages(struct scatterlist *, const unsigned int, int);
195static int st_probe(struct device *); 195static int st_probe(struct device *);
196static int st_remove(struct device *); 196static int st_remove(struct device *);
197 197
198static int do_create_driverfs_files(void); 198static int do_create_sysfs_files(void);
199static void do_remove_driverfs_files(void); 199static void do_remove_sysfs_files(void);
200static int do_create_class_files(struct scsi_tape *, int, int); 200static int do_create_class_files(struct scsi_tape *, int, int);
201 201
202static struct scsi_driver st_template = { 202static struct scsi_driver st_template = {
@@ -4193,7 +4193,7 @@ static int __init init_st(void)
4193 if (err) 4193 if (err)
4194 goto err_chrdev; 4194 goto err_chrdev;
4195 4195
4196 err = do_create_driverfs_files(); 4196 err = do_create_sysfs_files();
4197 if (err) 4197 if (err)
4198 goto err_scsidrv; 4198 goto err_scsidrv;
4199 4199
@@ -4211,7 +4211,7 @@ err_class:
4211 4211
4212static void __exit exit_st(void) 4212static void __exit exit_st(void)
4213{ 4213{
4214 do_remove_driverfs_files(); 4214 do_remove_sysfs_files();
4215 scsi_unregister_driver(&st_template.gendrv); 4215 scsi_unregister_driver(&st_template.gendrv);
4216 unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0), 4216 unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0),
4217 ST_MAX_TAPE_ENTRIES); 4217 ST_MAX_TAPE_ENTRIES);
@@ -4249,43 +4249,43 @@ static ssize_t st_version_show(struct device_driver *ddd, char *buf)
4249} 4249}
4250static DRIVER_ATTR(version, S_IRUGO, st_version_show, NULL); 4250static DRIVER_ATTR(version, S_IRUGO, st_version_show, NULL);
4251 4251
4252static int do_create_driverfs_files(void) 4252static int do_create_sysfs_files(void)
4253{ 4253{
4254 struct device_driver *driverfs = &st_template.gendrv; 4254 struct device_driver *sysfs = &st_template.gendrv;
4255 int err; 4255 int err;
4256 4256
4257 err = driver_create_file(driverfs, &driver_attr_try_direct_io); 4257 err = driver_create_file(sysfs, &driver_attr_try_direct_io);
4258 if (err) 4258 if (err)
4259 return err; 4259 return err;
4260 err = driver_create_file(driverfs, &driver_attr_fixed_buffer_size); 4260 err = driver_create_file(sysfs, &driver_attr_fixed_buffer_size);
4261 if (err) 4261 if (err)
4262 goto err_try_direct_io; 4262 goto err_try_direct_io;
4263 err = driver_create_file(driverfs, &driver_attr_max_sg_segs); 4263 err = driver_create_file(sysfs, &driver_attr_max_sg_segs);
4264 if (err) 4264 if (err)
4265 goto err_attr_fixed_buf; 4265 goto err_attr_fixed_buf;
4266 err = driver_create_file(driverfs, &driver_attr_version); 4266 err = driver_create_file(sysfs, &driver_attr_version);
4267 if (err) 4267 if (err)
4268 goto err_attr_max_sg; 4268 goto err_attr_max_sg;
4269 4269
4270 return 0; 4270 return 0;
4271 4271
4272err_attr_max_sg: 4272err_attr_max_sg:
4273 driver_remove_file(driverfs, &driver_attr_max_sg_segs); 4273 driver_remove_file(sysfs, &driver_attr_max_sg_segs);
4274err_attr_fixed_buf: 4274err_attr_fixed_buf:
4275 driver_remove_file(driverfs, &driver_attr_fixed_buffer_size); 4275 driver_remove_file(sysfs, &driver_attr_fixed_buffer_size);
4276err_try_direct_io: 4276err_try_direct_io:
4277 driver_remove_file(driverfs, &driver_attr_try_direct_io); 4277 driver_remove_file(sysfs, &driver_attr_try_direct_io);
4278 return err; 4278 return err;
4279} 4279}
4280 4280
4281static void do_remove_driverfs_files(void) 4281static void do_remove_sysfs_files(void)
4282{ 4282{
4283 struct device_driver *driverfs = &st_template.gendrv; 4283 struct device_driver *sysfs = &st_template.gendrv;
4284 4284
4285 driver_remove_file(driverfs, &driver_attr_version); 4285 driver_remove_file(sysfs, &driver_attr_version);
4286 driver_remove_file(driverfs, &driver_attr_max_sg_segs); 4286 driver_remove_file(sysfs, &driver_attr_max_sg_segs);
4287 driver_remove_file(driverfs, &driver_attr_fixed_buffer_size); 4287 driver_remove_file(sysfs, &driver_attr_fixed_buffer_size);
4288 driver_remove_file(driverfs, &driver_attr_try_direct_io); 4288 driver_remove_file(sysfs, &driver_attr_try_direct_io);
4289} 4289}
4290 4290
4291 4291
diff --git a/drivers/scsi/sym53c8xx_2/sym_fw1.h b/drivers/scsi/sym53c8xx_2/sym_fw1.h
index 7b39f4a35e..7b08d6caaa 100644
--- a/drivers/scsi/sym53c8xx_2/sym_fw1.h
+++ b/drivers/scsi/sym53c8xx_2/sym_fw1.h
@@ -1020,7 +1020,7 @@ static struct SYM_FWA_SCR SYM_FWA_SCR = {
1020 * It shall be a tagged command. 1020 * It shall be a tagged command.
1021 * Read SIMPLE+TAG. 1021 * Read SIMPLE+TAG.
1022 * The C code will deal with errors. 1022 * The C code will deal with errors.
1023 * Agressive optimization, is'nt it? :) 1023 * Aggressive optimization, isn't it? :)
1024 */ 1024 */
1025 SCR_MOVE_ABS (2) ^ SCR_MSG_IN, 1025 SCR_MOVE_ABS (2) ^ SCR_MSG_IN,
1026 HADDR_1 (msgin), 1026 HADDR_1 (msgin),
@@ -1044,7 +1044,7 @@ static struct SYM_FWA_SCR SYM_FWA_SCR = {
1044 RADDR_1 (dsa), 1044 RADDR_1 (dsa),
1045 /* 1045 /*
1046 * The SIDL still contains the TAG value. 1046 * The SIDL still contains the TAG value.
1047 * Agressive optimization, isn't it? :):) 1047 * Aggressive optimization, isn't it? :):)
1048 */ 1048 */
1049 SCR_REG_SFBR (sidl, SCR_SHL, 0), 1049 SCR_REG_SFBR (sidl, SCR_SHL, 0),
1050 0, 1050 0,
diff --git a/drivers/scsi/sym53c8xx_2/sym_fw2.h b/drivers/scsi/sym53c8xx_2/sym_fw2.h
index 851f2706f2..6e5b952312 100644
--- a/drivers/scsi/sym53c8xx_2/sym_fw2.h
+++ b/drivers/scsi/sym53c8xx_2/sym_fw2.h
@@ -956,7 +956,7 @@ static struct SYM_FWA_SCR SYM_FWA_SCR = {
956 * It shall be a tagged command. 956 * It shall be a tagged command.
957 * Read SIMPLE+TAG. 957 * Read SIMPLE+TAG.
958 * The C code will deal with errors. 958 * The C code will deal with errors.
959 * Agressive optimization, is'nt it? :) 959 * Aggressive optimization, isn't it? :)
960 */ 960 */
961 SCR_MOVE_ABS (2) ^ SCR_MSG_IN, 961 SCR_MOVE_ABS (2) ^ SCR_MSG_IN,
962 HADDR_1 (msgin), 962 HADDR_1 (msgin),
@@ -968,7 +968,7 @@ static struct SYM_FWA_SCR SYM_FWA_SCR = {
968 offsetof(struct sym_lcb, head.itlq_tbl_sa), 968 offsetof(struct sym_lcb, head.itlq_tbl_sa),
969 /* 969 /*
970 * The SIDL still contains the TAG value. 970 * The SIDL still contains the TAG value.
971 * Agressive optimization, isn't it? :):) 971 * Aggressive optimization, isn't it? :):)
972 */ 972 */
973 SCR_REG_SFBR (sidl, SCR_SHL, 0), 973 SCR_REG_SFBR (sidl, SCR_SHL, 0),
974 0, 974 0,
diff --git a/drivers/scsi/wd33c93.c b/drivers/scsi/wd33c93.c
index 835751600e..fa4e08e508 100644
--- a/drivers/scsi/wd33c93.c
+++ b/drivers/scsi/wd33c93.c
@@ -69,6 +69,11 @@
69 * Added support for pre -A chips, which don't have advanced features 69 * Added support for pre -A chips, which don't have advanced features
70 * and will generate CSR_RESEL rather than CSR_RESEL_AM. 70 * and will generate CSR_RESEL rather than CSR_RESEL_AM.
71 * Richard Hirst <richard@sleepie.demon.co.uk> August 2000 71 * Richard Hirst <richard@sleepie.demon.co.uk> August 2000
72 *
73 * Added support for Burst Mode DMA and Fast SCSI. Enabled the use of
74 * default_sx_per for asynchronous data transfers. Added adjustment
75 * of transfer periods in sx_table to the actual input-clock.
76 * peter fuerst <post@pfrst.de> February 2007
72 */ 77 */
73 78
74#include <linux/module.h> 79#include <linux/module.h>
@@ -86,9 +91,11 @@
86 91
87#include "wd33c93.h" 92#include "wd33c93.h"
88 93
94#define optimum_sx_per(hostdata) (hostdata)->sx_table[1].period_ns
95
89 96
90#define WD33C93_VERSION "1.26" 97#define WD33C93_VERSION "1.26++"
91#define WD33C93_DATE "22/Feb/2003" 98#define WD33C93_DATE "10/Feb/2007"
92 99
93MODULE_AUTHOR("John Shifflett"); 100MODULE_AUTHOR("John Shifflett");
94MODULE_DESCRIPTION("Generic WD33C93 SCSI driver"); 101MODULE_DESCRIPTION("Generic WD33C93 SCSI driver");
@@ -122,6 +129,13 @@ MODULE_LICENSE("GPL");
122 * defines in wd33c93.h 129 * defines in wd33c93.h
123 * - clock:x -x = clock input in MHz for WD33c93 chip. Normal values 130 * - clock:x -x = clock input in MHz for WD33c93 chip. Normal values
124 * would be from 8 through 20. Default is 8. 131 * would be from 8 through 20. Default is 8.
132 * - burst:x -x = 1 to use Burst Mode (or Demand-Mode) DMA, x = 0 to use
133 * Single Byte DMA, which is the default. Argument is
134 * optional - if not present, same as "burst:1".
135 * - fast:x -x = 1 to enable Fast SCSI, which is only effective with
136 * input-clock divisor 4 (WD33C93_FS_16_20), x = 0 to disable
137 * it, which is the default. Argument is optional - if not
138 * present, same as "fast:1".
125 * - next -No argument. Used to separate blocks of keywords when 139 * - next -No argument. Used to separate blocks of keywords when
126 * there's more than one host adapter in the system. 140 * there's more than one host adapter in the system.
127 * 141 *
@@ -148,7 +162,7 @@ MODULE_LICENSE("GPL");
148 */ 162 */
149 163
150/* Normally, no defaults are specified */ 164/* Normally, no defaults are specified */
151static char *setup_args[] = { "", "", "", "", "", "", "", "", "" }; 165static char *setup_args[] = { "", "", "", "", "", "", "", "", "", "" };
152 166
153static char *setup_strings; 167static char *setup_strings;
154module_param(setup_strings, charp, 0); 168module_param(setup_strings, charp, 0);
@@ -298,20 +312,8 @@ read_1_byte(const wd33c93_regs regs)
298 return x; 312 return x;
299} 313}
300 314
301static struct sx_period sx_table[] = {
302 {1, 0x20},
303 {252, 0x20},
304 {376, 0x30},
305 {500, 0x40},
306 {624, 0x50},
307 {752, 0x60},
308 {876, 0x70},
309 {1000, 0x00},
310 {0, 0}
311};
312
313static int 315static int
314round_period(unsigned int period) 316round_period(unsigned int period, const struct sx_period *sx_table)
315{ 317{
316 int x; 318 int x;
317 319
@@ -324,17 +326,49 @@ round_period(unsigned int period)
324 return 7; 326 return 7;
325} 327}
326 328
329/*
330 * Calculate Synchronous Transfer Register value from SDTR code.
331 */
327static uchar 332static uchar
328calc_sync_xfer(unsigned int period, unsigned int offset) 333calc_sync_xfer(unsigned int period, unsigned int offset, unsigned int fast,
334 const struct sx_period *sx_table)
329{ 335{
336 /* When doing Fast SCSI synchronous data transfers, the corresponding
337 * value in 'sx_table' is two times the actually used transfer period.
338 */
330 uchar result; 339 uchar result;
331 340
341 if (offset && fast) {
342 fast = STR_FSS;
343 period *= 2;
344 } else {
345 fast = 0;
346 }
332 period *= 4; /* convert SDTR code to ns */ 347 period *= 4; /* convert SDTR code to ns */
333 result = sx_table[round_period(period)].reg_value; 348 result = sx_table[round_period(period,sx_table)].reg_value;
334 result |= (offset < OPTIMUM_SX_OFF) ? offset : OPTIMUM_SX_OFF; 349 result |= (offset < OPTIMUM_SX_OFF) ? offset : OPTIMUM_SX_OFF;
350 result |= fast;
335 return result; 351 return result;
336} 352}
337 353
354/*
355 * Calculate SDTR code bytes [3],[4] from period and offset.
356 */
357static inline void
358calc_sync_msg(unsigned int period, unsigned int offset, unsigned int fast,
359 uchar msg[2])
360{
361 /* 'period' is a "normal"-mode value, like the ones in 'sx_table'. The
362 * actually used transfer period for Fast SCSI synchronous data
363 * transfers is half that value.
364 */
365 period /= 4;
366 if (offset && fast)
367 period /= 2;
368 msg[0] = period;
369 msg[1] = offset;
370}
371
338int 372int
339wd33c93_queuecommand(struct scsi_cmnd *cmd, 373wd33c93_queuecommand(struct scsi_cmnd *cmd,
340 void (*done)(struct scsi_cmnd *)) 374 void (*done)(struct scsi_cmnd *))
@@ -632,7 +666,7 @@ wd33c93_execute(struct Scsi_Host *instance)
632 write_wd33c93_count(regs, 666 write_wd33c93_count(regs,
633 cmd->SCp.this_residual); 667 cmd->SCp.this_residual);
634 write_wd33c93(regs, WD_CONTROL, 668 write_wd33c93(regs, WD_CONTROL,
635 CTRL_IDI | CTRL_EDI | CTRL_DMA); 669 CTRL_IDI | CTRL_EDI | hostdata->dma_mode);
636 hostdata->dma = D_DMA_RUNNING; 670 hostdata->dma = D_DMA_RUNNING;
637 } 671 }
638 } else 672 } else
@@ -712,6 +746,8 @@ transfer_bytes(const wd33c93_regs regs, struct scsi_cmnd *cmd,
712 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) + 746 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) +
713 cmd->SCp.buffer->offset; 747 cmd->SCp.buffer->offset;
714 } 748 }
749 if (!cmd->SCp.this_residual) /* avoid bogus setups */
750 return;
715 751
716 write_wd33c93(regs, WD_SYNCHRONOUS_TRANSFER, 752 write_wd33c93(regs, WD_SYNCHRONOUS_TRANSFER,
717 hostdata->sync_xfer[cmd->device->id]); 753 hostdata->sync_xfer[cmd->device->id]);
@@ -744,7 +780,7 @@ transfer_bytes(const wd33c93_regs regs, struct scsi_cmnd *cmd,
744#ifdef PROC_STATISTICS 780#ifdef PROC_STATISTICS
745 hostdata->dma_cnt++; 781 hostdata->dma_cnt++;
746#endif 782#endif
747 write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_DMA); 783 write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | hostdata->dma_mode);
748 write_wd33c93_count(regs, cmd->SCp.this_residual); 784 write_wd33c93_count(regs, cmd->SCp.this_residual);
749 785
750 if ((hostdata->level2 >= L2_DATA) || 786 if ((hostdata->level2 >= L2_DATA) ||
@@ -862,9 +898,6 @@ wd33c93_intr(struct Scsi_Host *instance)
862 hostdata->outgoing_msg[0] |= 0x40; 898 hostdata->outgoing_msg[0] |= 0x40;
863 899
864 if (hostdata->sync_stat[cmd->device->id] == SS_FIRST) { 900 if (hostdata->sync_stat[cmd->device->id] == SS_FIRST) {
865#ifdef SYNC_DEBUG
866 printk(" sending SDTR ");
867#endif
868 901
869 hostdata->sync_stat[cmd->device->id] = SS_WAITING; 902 hostdata->sync_stat[cmd->device->id] = SS_WAITING;
870 903
@@ -878,14 +911,20 @@ wd33c93_intr(struct Scsi_Host *instance)
878 hostdata->outgoing_msg[2] = 3; 911 hostdata->outgoing_msg[2] = 3;
879 hostdata->outgoing_msg[3] = EXTENDED_SDTR; 912 hostdata->outgoing_msg[3] = EXTENDED_SDTR;
880 if (hostdata->no_sync & (1 << cmd->device->id)) { 913 if (hostdata->no_sync & (1 << cmd->device->id)) {
881 hostdata->outgoing_msg[4] = 914 calc_sync_msg(hostdata->default_sx_per, 0,
882 hostdata->default_sx_per / 4; 915 0, hostdata->outgoing_msg + 4);
883 hostdata->outgoing_msg[5] = 0;
884 } else { 916 } else {
885 hostdata->outgoing_msg[4] = OPTIMUM_SX_PER / 4; 917 calc_sync_msg(optimum_sx_per(hostdata),
886 hostdata->outgoing_msg[5] = OPTIMUM_SX_OFF; 918 OPTIMUM_SX_OFF,
919 hostdata->fast,
920 hostdata->outgoing_msg + 4);
887 } 921 }
888 hostdata->outgoing_len = 6; 922 hostdata->outgoing_len = 6;
923#ifdef SYNC_DEBUG
924 ucp = hostdata->outgoing_msg + 1;
925 printk(" sending SDTR %02x03%02x%02x%02x ",
926 ucp[0], ucp[2], ucp[3], ucp[4]);
927#endif
889 } else 928 } else
890 hostdata->outgoing_len = 1; 929 hostdata->outgoing_len = 1;
891 930
@@ -1001,8 +1040,13 @@ wd33c93_intr(struct Scsi_Host *instance)
1001#ifdef SYNC_DEBUG 1040#ifdef SYNC_DEBUG
1002 printk("-REJ-"); 1041 printk("-REJ-");
1003#endif 1042#endif
1004 if (hostdata->sync_stat[cmd->device->id] == SS_WAITING) 1043 if (hostdata->sync_stat[cmd->device->id] == SS_WAITING) {
1005 hostdata->sync_stat[cmd->device->id] = SS_SET; 1044 hostdata->sync_stat[cmd->device->id] = SS_SET;
1045 /* we want default_sx_per, not DEFAULT_SX_PER */
1046 hostdata->sync_xfer[cmd->device->id] =
1047 calc_sync_xfer(hostdata->default_sx_per
1048 / 4, 0, 0, hostdata->sx_table);
1049 }
1006 write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK); 1050 write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
1007 hostdata->state = S_CONNECTED; 1051 hostdata->state = S_CONNECTED;
1008 break; 1052 break;
@@ -1022,7 +1066,10 @@ wd33c93_intr(struct Scsi_Host *instance)
1022 1066
1023 switch (ucp[2]) { /* what's the EXTENDED code? */ 1067 switch (ucp[2]) { /* what's the EXTENDED code? */
1024 case EXTENDED_SDTR: 1068 case EXTENDED_SDTR:
1025 id = calc_sync_xfer(ucp[3], ucp[4]); 1069 /* default to default async period */
1070 id = calc_sync_xfer(hostdata->
1071 default_sx_per / 4, 0,
1072 0, hostdata->sx_table);
1026 if (hostdata->sync_stat[cmd->device->id] != 1073 if (hostdata->sync_stat[cmd->device->id] !=
1027 SS_WAITING) { 1074 SS_WAITING) {
1028 1075
@@ -1041,20 +1088,22 @@ wd33c93_intr(struct Scsi_Host *instance)
1041 hostdata->outgoing_msg[1] = 3; 1088 hostdata->outgoing_msg[1] = 3;
1042 hostdata->outgoing_msg[2] = 1089 hostdata->outgoing_msg[2] =
1043 EXTENDED_SDTR; 1090 EXTENDED_SDTR;
1044 hostdata->outgoing_msg[3] = 1091 calc_sync_msg(hostdata->
1045 hostdata->default_sx_per / 1092 default_sx_per, 0,
1046 4; 1093 0, hostdata->outgoing_msg + 3);
1047 hostdata->outgoing_msg[4] = 0;
1048 hostdata->outgoing_len = 5; 1094 hostdata->outgoing_len = 5;
1049 hostdata->sync_xfer[cmd->device->id] =
1050 calc_sync_xfer(hostdata->
1051 default_sx_per
1052 / 4, 0);
1053 } else { 1095 } else {
1054 hostdata->sync_xfer[cmd->device->id] = id; 1096 if (ucp[4]) /* well, sync transfer */
1097 id = calc_sync_xfer(ucp[3], ucp[4],
1098 hostdata->fast,
1099 hostdata->sx_table);
1100 else if (ucp[3]) /* very unlikely... */
1101 id = calc_sync_xfer(ucp[3], ucp[4],
1102 0, hostdata->sx_table);
1055 } 1103 }
1104 hostdata->sync_xfer[cmd->device->id] = id;
1056#ifdef SYNC_DEBUG 1105#ifdef SYNC_DEBUG
1057 printk("sync_xfer=%02x", 1106 printk(" sync_xfer=%02x\n",
1058 hostdata->sync_xfer[cmd->device->id]); 1107 hostdata->sync_xfer[cmd->device->id]);
1059#endif 1108#endif
1060 hostdata->sync_stat[cmd->device->id] = 1109 hostdata->sync_stat[cmd->device->id] =
@@ -1486,7 +1535,7 @@ reset_wd33c93(struct Scsi_Host *instance)
1486 write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED); 1535 write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
1487 write_wd33c93(regs, WD_SYNCHRONOUS_TRANSFER, 1536 write_wd33c93(regs, WD_SYNCHRONOUS_TRANSFER,
1488 calc_sync_xfer(hostdata->default_sx_per / 4, 1537 calc_sync_xfer(hostdata->default_sx_per / 4,
1489 DEFAULT_SX_OFF)); 1538 DEFAULT_SX_OFF, 0, hostdata->sx_table));
1490 write_wd33c93(regs, WD_COMMAND, WD_CMD_RESET); 1539 write_wd33c93(regs, WD_COMMAND, WD_CMD_RESET);
1491 1540
1492 1541
@@ -1512,6 +1561,9 @@ reset_wd33c93(struct Scsi_Host *instance)
1512 } else 1561 } else
1513 hostdata->chip = C_UNKNOWN_CHIP; 1562 hostdata->chip = C_UNKNOWN_CHIP;
1514 1563
1564 if (hostdata->chip != C_WD33C93B) /* Fast SCSI unavailable */
1565 hostdata->fast = 0;
1566
1515 write_wd33c93(regs, WD_TIMEOUT_PERIOD, TIMEOUT_PERIOD_VALUE); 1567 write_wd33c93(regs, WD_TIMEOUT_PERIOD, TIMEOUT_PERIOD_VALUE);
1516 write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED); 1568 write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
1517} 1569}
@@ -1533,7 +1585,8 @@ wd33c93_host_reset(struct scsi_cmnd * SCpnt)
1533 for (i = 0; i < 8; i++) { 1585 for (i = 0; i < 8; i++) {
1534 hostdata->busy[i] = 0; 1586 hostdata->busy[i] = 0;
1535 hostdata->sync_xfer[i] = 1587 hostdata->sync_xfer[i] =
1536 calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF); 1588 calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF,
1589 0, hostdata->sx_table);
1537 hostdata->sync_stat[i] = SS_UNSET; /* using default sync values */ 1590 hostdata->sync_stat[i] = SS_UNSET; /* using default sync values */
1538 } 1591 }
1539 hostdata->input_Q = NULL; 1592 hostdata->input_Q = NULL;
@@ -1782,6 +1835,98 @@ check_setup_args(char *key, int *flags, int *val, char *buf)
1782 return ++x; 1835 return ++x;
1783} 1836}
1784 1837
1838/*
1839 * Calculate internal data-transfer-clock cycle from input-clock
1840 * frequency (/MHz) and fill 'sx_table'.
1841 *
1842 * The original driver used to rely on a fixed sx_table, containing periods
1843 * for (only) the lower limits of the respective input-clock-frequency ranges
1844 * (8-10/12-15/16-20 MHz). Although it seems, that no problems ocurred with
1845 * this setting so far, it might be desirable to adjust the transfer periods
1846 * closer to the really attached, possibly 25% higher, input-clock, since
1847 * - the wd33c93 may really use a significant shorter period, than it has
1848 * negotiated (eg. thrashing the target, which expects 4/8MHz, with 5/10MHz
1849 * instead).
1850 * - the wd33c93 may ask the target for a lower transfer rate, than the target
1851 * is capable of (eg. negotiating for an assumed minimum of 252ns instead of
1852 * possible 200ns, which indeed shows up in tests as an approx. 10% lower
1853 * transfer rate).
1854 */
1855static inline unsigned int
1856round_4(unsigned int x)
1857{
1858 switch (x & 3) {
1859 case 1: --x;
1860 break;
1861 case 2: ++x;
1862 case 3: ++x;
1863 }
1864 return x;
1865}
1866
1867static void
1868calc_sx_table(unsigned int mhz, struct sx_period sx_table[9])
1869{
1870 unsigned int d, i;
1871 if (mhz < 11)
1872 d = 2; /* divisor for 8-10 MHz input-clock */
1873 else if (mhz < 16)
1874 d = 3; /* divisor for 12-15 MHz input-clock */
1875 else
1876 d = 4; /* divisor for 16-20 MHz input-clock */
1877
1878 d = (100000 * d) / 2 / mhz; /* 100 x DTCC / nanosec */
1879
1880 sx_table[0].period_ns = 1;
1881 sx_table[0].reg_value = 0x20;
1882 for (i = 1; i < 8; i++) {
1883 sx_table[i].period_ns = round_4((i+1)*d / 100);
1884 sx_table[i].reg_value = (i+1)*0x10;
1885 }
1886 sx_table[7].reg_value = 0;
1887 sx_table[8].period_ns = 0;
1888 sx_table[8].reg_value = 0;
1889}
1890
1891/*
1892 * check and, maybe, map an init- or "clock:"- argument.
1893 */
1894static uchar
1895set_clk_freq(int freq, int *mhz)
1896{
1897 int x = freq;
1898 if (WD33C93_FS_8_10 == freq)
1899 freq = 8;
1900 else if (WD33C93_FS_12_15 == freq)
1901 freq = 12;
1902 else if (WD33C93_FS_16_20 == freq)
1903 freq = 16;
1904 else if (freq > 7 && freq < 11)
1905 x = WD33C93_FS_8_10;
1906 else if (freq > 11 && freq < 16)
1907 x = WD33C93_FS_12_15;
1908 else if (freq > 15 && freq < 21)
1909 x = WD33C93_FS_16_20;
1910 else {
1911 /* Hmm, wouldn't it be safer to assume highest freq here? */
1912 x = WD33C93_FS_8_10;
1913 freq = 8;
1914 }
1915 *mhz = freq;
1916 return x;
1917}
1918
1919/*
1920 * to be used with the resync: fast: ... options
1921 */
1922static inline void set_resync ( struct WD33C93_hostdata *hd, int mask )
1923{
1924 int i;
1925 for (i = 0; i < 8; i++)
1926 if (mask & (1 << i))
1927 hd->sync_stat[i] = SS_UNSET;
1928}
1929
1785void 1930void
1786wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs, 1931wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs,
1787 dma_setup_t setup, dma_stop_t stop, int clock_freq) 1932 dma_setup_t setup, dma_stop_t stop, int clock_freq)
@@ -1798,7 +1943,8 @@ wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs,
1798 hostdata = (struct WD33C93_hostdata *) instance->hostdata; 1943 hostdata = (struct WD33C93_hostdata *) instance->hostdata;
1799 1944
1800 hostdata->regs = regs; 1945 hostdata->regs = regs;
1801 hostdata->clock_freq = clock_freq; 1946 hostdata->clock_freq = set_clk_freq(clock_freq, &i);
1947 calc_sx_table(i, hostdata->sx_table);
1802 hostdata->dma_setup = setup; 1948 hostdata->dma_setup = setup;
1803 hostdata->dma_stop = stop; 1949 hostdata->dma_stop = stop;
1804 hostdata->dma_bounce_buffer = NULL; 1950 hostdata->dma_bounce_buffer = NULL;
@@ -1806,7 +1952,8 @@ wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs,
1806 for (i = 0; i < 8; i++) { 1952 for (i = 0; i < 8; i++) {
1807 hostdata->busy[i] = 0; 1953 hostdata->busy[i] = 0;
1808 hostdata->sync_xfer[i] = 1954 hostdata->sync_xfer[i] =
1809 calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF); 1955 calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF,
1956 0, hostdata->sx_table);
1810 hostdata->sync_stat[i] = SS_UNSET; /* using default sync values */ 1957 hostdata->sync_stat[i] = SS_UNSET; /* using default sync values */
1811#ifdef PROC_STATISTICS 1958#ifdef PROC_STATISTICS
1812 hostdata->cmd_cnt[i] = 0; 1959 hostdata->cmd_cnt[i] = 0;
@@ -1828,6 +1975,8 @@ wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs,
1828 hostdata->default_sx_per = DEFAULT_SX_PER; 1975 hostdata->default_sx_per = DEFAULT_SX_PER;
1829 hostdata->no_sync = 0xff; /* sync defaults to off */ 1976 hostdata->no_sync = 0xff; /* sync defaults to off */
1830 hostdata->no_dma = 0; /* default is DMA enabled */ 1977 hostdata->no_dma = 0; /* default is DMA enabled */
1978 hostdata->fast = 0; /* default is Fast SCSI transfers disabled */
1979 hostdata->dma_mode = CTRL_DMA; /* default is Single Byte DMA */
1831 1980
1832#ifdef PROC_INTERFACE 1981#ifdef PROC_INTERFACE
1833 hostdata->proc = PR_VERSION | PR_INFO | PR_STATISTICS | 1982 hostdata->proc = PR_VERSION | PR_INFO | PR_STATISTICS |
@@ -1839,6 +1988,11 @@ wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs,
1839#endif 1988#endif
1840#endif 1989#endif
1841 1990
1991 if (check_setup_args("clock", &flags, &val, buf)) {
1992 hostdata->clock_freq = set_clk_freq(val, &val);
1993 calc_sx_table(val, hostdata->sx_table);
1994 }
1995
1842 if (check_setup_args("nosync", &flags, &val, buf)) 1996 if (check_setup_args("nosync", &flags, &val, buf))
1843 hostdata->no_sync = val; 1997 hostdata->no_sync = val;
1844 1998
@@ -1847,7 +2001,8 @@ wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs,
1847 2001
1848 if (check_setup_args("period", &flags, &val, buf)) 2002 if (check_setup_args("period", &flags, &val, buf))
1849 hostdata->default_sx_per = 2003 hostdata->default_sx_per =
1850 sx_table[round_period((unsigned int) val)].period_ns; 2004 hostdata->sx_table[round_period((unsigned int) val,
2005 hostdata->sx_table)].period_ns;
1851 2006
1852 if (check_setup_args("disconnect", &flags, &val, buf)) { 2007 if (check_setup_args("disconnect", &flags, &val, buf)) {
1853 if ((val >= DIS_NEVER) && (val <= DIS_ALWAYS)) 2008 if ((val >= DIS_NEVER) && (val <= DIS_ALWAYS))
@@ -1862,17 +2017,12 @@ wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs,
1862 if (check_setup_args("debug", &flags, &val, buf)) 2017 if (check_setup_args("debug", &flags, &val, buf))
1863 hostdata->args = val & DB_MASK; 2018 hostdata->args = val & DB_MASK;
1864 2019
1865 if (check_setup_args("clock", &flags, &val, buf)) { 2020 if (check_setup_args("burst", &flags, &val, buf))
1866 if (val > 7 && val < 11) 2021 hostdata->dma_mode = val ? CTRL_BURST:CTRL_DMA;
1867 val = WD33C93_FS_8_10; 2022
1868 else if (val > 11 && val < 16) 2023 if (WD33C93_FS_16_20 == hostdata->clock_freq /* divisor 4 */
1869 val = WD33C93_FS_12_15; 2024 && check_setup_args("fast", &flags, &val, buf))
1870 else if (val > 15 && val < 21) 2025 hostdata->fast = !!val;
1871 val = WD33C93_FS_16_20;
1872 else
1873 val = WD33C93_FS_8_10;
1874 hostdata->clock_freq = val;
1875 }
1876 2026
1877 if ((i = check_setup_args("next", &flags, &val, buf))) { 2027 if ((i = check_setup_args("next", &flags, &val, buf))) {
1878 while (i) 2028 while (i)
@@ -1917,53 +2067,65 @@ wd33c93_proc_info(struct Scsi_Host *instance, char *buf, char **start, off_t off
1917 char tbuf[128]; 2067 char tbuf[128];
1918 struct WD33C93_hostdata *hd; 2068 struct WD33C93_hostdata *hd;
1919 struct scsi_cmnd *cmd; 2069 struct scsi_cmnd *cmd;
1920 int x, i; 2070 int x;
1921 static int stop = 0; 2071 static int stop = 0;
1922 2072
1923 hd = (struct WD33C93_hostdata *) instance->hostdata; 2073 hd = (struct WD33C93_hostdata *) instance->hostdata;
1924 2074
1925/* If 'in' is TRUE we need to _read_ the proc file. We accept the following 2075/* If 'in' is TRUE we need to _read_ the proc file. We accept the following
1926 * keywords (same format as command-line, but only ONE per read): 2076 * keywords (same format as command-line, but arguments are not optional):
1927 * debug 2077 * debug
1928 * disconnect 2078 * disconnect
1929 * period 2079 * period
1930 * resync 2080 * resync
1931 * proc 2081 * proc
1932 * nodma 2082 * nodma
2083 * level2
2084 * burst
2085 * fast
2086 * nosync
1933 */ 2087 */
1934 2088
1935 if (in) { 2089 if (in) {
1936 buf[len] = '\0'; 2090 buf[len] = '\0';
1937 bp = buf; 2091 for (bp = buf; *bp; ) {
2092 while (',' == *bp || ' ' == *bp)
2093 ++bp;
1938 if (!strncmp(bp, "debug:", 6)) { 2094 if (!strncmp(bp, "debug:", 6)) {
1939 bp += 6; 2095 hd->args = simple_strtoul(bp+6, &bp, 0) & DB_MASK;
1940 hd->args = simple_strtoul(bp, NULL, 0) & DB_MASK;
1941 } else if (!strncmp(bp, "disconnect:", 11)) { 2096 } else if (!strncmp(bp, "disconnect:", 11)) {
1942 bp += 11; 2097 x = simple_strtoul(bp+11, &bp, 0);
1943 x = simple_strtoul(bp, NULL, 0);
1944 if (x < DIS_NEVER || x > DIS_ALWAYS) 2098 if (x < DIS_NEVER || x > DIS_ALWAYS)
1945 x = DIS_ADAPTIVE; 2099 x = DIS_ADAPTIVE;
1946 hd->disconnect = x; 2100 hd->disconnect = x;
1947 } else if (!strncmp(bp, "period:", 7)) { 2101 } else if (!strncmp(bp, "period:", 7)) {
1948 bp += 7; 2102 x = simple_strtoul(bp+7, &bp, 0);
1949 x = simple_strtoul(bp, NULL, 0);
1950 hd->default_sx_per = 2103 hd->default_sx_per =
1951 sx_table[round_period((unsigned int) x)].period_ns; 2104 hd->sx_table[round_period((unsigned int) x,
2105 hd->sx_table)].period_ns;
1952 } else if (!strncmp(bp, "resync:", 7)) { 2106 } else if (!strncmp(bp, "resync:", 7)) {
1953 bp += 7; 2107 set_resync(hd, (int)simple_strtoul(bp+7, &bp, 0));
1954 x = simple_strtoul(bp, NULL, 0);
1955 for (i = 0; i < 7; i++)
1956 if (x & (1 << i))
1957 hd->sync_stat[i] = SS_UNSET;
1958 } else if (!strncmp(bp, "proc:", 5)) { 2108 } else if (!strncmp(bp, "proc:", 5)) {
1959 bp += 5; 2109 hd->proc = simple_strtoul(bp+5, &bp, 0);
1960 hd->proc = simple_strtoul(bp, NULL, 0);
1961 } else if (!strncmp(bp, "nodma:", 6)) { 2110 } else if (!strncmp(bp, "nodma:", 6)) {
1962 bp += 6; 2111 hd->no_dma = simple_strtoul(bp+6, &bp, 0);
1963 hd->no_dma = simple_strtoul(bp, NULL, 0);
1964 } else if (!strncmp(bp, "level2:", 7)) { 2112 } else if (!strncmp(bp, "level2:", 7)) {
1965 bp += 7; 2113 hd->level2 = simple_strtoul(bp+7, &bp, 0);
1966 hd->level2 = simple_strtoul(bp, NULL, 0); 2114 } else if (!strncmp(bp, "burst:", 6)) {
2115 hd->dma_mode =
2116 simple_strtol(bp+6, &bp, 0) ? CTRL_BURST:CTRL_DMA;
2117 } else if (!strncmp(bp, "fast:", 5)) {
2118 x = !!simple_strtol(bp+5, &bp, 0);
2119 if (x != hd->fast)
2120 set_resync(hd, 0xff);
2121 hd->fast = x;
2122 } else if (!strncmp(bp, "nosync:", 7)) {
2123 x = simple_strtoul(bp+7, &bp, 0);
2124 set_resync(hd, x ^ hd->no_sync);
2125 hd->no_sync = x;
2126 } else {
2127 break; /* unknown keyword,syntax-error,... */
2128 }
1967 } 2129 }
1968 return len; 2130 return len;
1969 } 2131 }
@@ -1977,8 +2139,9 @@ wd33c93_proc_info(struct Scsi_Host *instance, char *buf, char **start, off_t off
1977 strcat(bp, tbuf); 2139 strcat(bp, tbuf);
1978 } 2140 }
1979 if (hd->proc & PR_INFO) { 2141 if (hd->proc & PR_INFO) {
1980 sprintf(tbuf, "\nclock_freq=%02x no_sync=%02x no_dma=%d", 2142 sprintf(tbuf, "\nclock_freq=%02x no_sync=%02x no_dma=%d"
1981 hd->clock_freq, hd->no_sync, hd->no_dma); 2143 " dma_mode=%02x fast=%d",
2144 hd->clock_freq, hd->no_sync, hd->no_dma, hd->dma_mode, hd->fast);
1982 strcat(bp, tbuf); 2145 strcat(bp, tbuf);
1983 strcat(bp, "\nsync_xfer[] = "); 2146 strcat(bp, "\nsync_xfer[] = ");
1984 for (x = 0; x < 7; x++) { 2147 for (x = 0; x < 7; x++) {
diff --git a/drivers/scsi/wd33c93.h b/drivers/scsi/wd33c93.h
index edcb0365cf..61ffb860da 100644
--- a/drivers/scsi/wd33c93.h
+++ b/drivers/scsi/wd33c93.h
@@ -155,6 +155,9 @@
155#define WD33C93_FS_12_15 OWNID_FS_12 155#define WD33C93_FS_12_15 OWNID_FS_12
156#define WD33C93_FS_16_20 OWNID_FS_16 156#define WD33C93_FS_16_20 OWNID_FS_16
157 157
158 /* pass input-clock explicitely. accepted mhz values are 8-10,12-20 */
159#define WD33C93_FS_MHZ(mhz) (mhz)
160
158 /* Control register */ 161 /* Control register */
159#define CTRL_HSP 0x01 162#define CTRL_HSP 0x01
160#define CTRL_HA 0x02 163#define CTRL_HA 0x02
@@ -253,6 +256,9 @@ struct WD33C93_hostdata {
253 uchar sync_stat[8]; /* status of sync negotiation per target */ 256 uchar sync_stat[8]; /* status of sync negotiation per target */
254 uchar no_sync; /* bitmask: don't do sync on these targets */ 257 uchar no_sync; /* bitmask: don't do sync on these targets */
255 uchar no_dma; /* set this flag to disable DMA */ 258 uchar no_dma; /* set this flag to disable DMA */
259 uchar dma_mode; /* DMA Burst Mode or Single Byte DMA */
260 uchar fast; /* set this flag to enable Fast SCSI */
261 struct sx_period sx_table[9]; /* transfer periods for actual DTC-setting */
256#ifdef PROC_INTERFACE 262#ifdef PROC_INTERFACE
257 uchar proc; /* bitmask: what's in proc output */ 263 uchar proc; /* bitmask: what's in proc output */
258#ifdef PROC_STATISTICS 264#ifdef PROC_STATISTICS
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 98ec861853..c129a0e8e8 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -1196,7 +1196,7 @@ static void serial8250_enable_ms(struct uart_port *port)
1196} 1196}
1197 1197
1198static void 1198static void
1199receive_chars(struct uart_8250_port *up, int *status) 1199receive_chars(struct uart_8250_port *up, unsigned int *status)
1200{ 1200{
1201 struct tty_struct *tty = up->port.info->tty; 1201 struct tty_struct *tty = up->port.info->tty;
1202 unsigned char ch, lsr = *status; 1202 unsigned char ch, lsr = *status;
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index e8dd71df91..ad9f321968 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -262,7 +262,8 @@ config SERIAL_AMBA_PL010
262 select SERIAL_CORE 262 select SERIAL_CORE
263 help 263 help
264 This selects the ARM(R) AMBA(R) PrimeCell PL010 UART. If you have 264 This selects the ARM(R) AMBA(R) PrimeCell PL010 UART. If you have
265 an Integrator/AP or Integrator/PP2 platform, say Y or M here. 265 an Integrator/AP or Integrator/PP2 platform, or if you have a
266 Cirrus Logic EP93xx CPU, say Y or M here.
266 267
267 If unsure, say N. 268 If unsure, say N.
268 269
diff --git a/drivers/serial/atmel_serial.c b/drivers/serial/atmel_serial.c
index df45a7ac77..935f48fa50 100644
--- a/drivers/serial/atmel_serial.c
+++ b/drivers/serial/atmel_serial.c
@@ -33,12 +33,13 @@
33#include <linux/sysrq.h> 33#include <linux/sysrq.h>
34#include <linux/tty_flip.h> 34#include <linux/tty_flip.h>
35#include <linux/platform_device.h> 35#include <linux/platform_device.h>
36#include <linux/atmel_pdc.h>
36 37
37#include <asm/io.h> 38#include <asm/io.h>
38 39
39#include <asm/mach/serial_at91.h> 40#include <asm/mach/serial_at91.h>
40#include <asm/arch/board.h> 41#include <asm/arch/board.h>
41#include <asm/arch/at91_pdc.h> 42
42#ifdef CONFIG_ARM 43#ifdef CONFIG_ARM
43#include <asm/arch/cpu.h> 44#include <asm/arch/cpu.h>
44#include <asm/arch/gpio.h> 45#include <asm/arch/gpio.h>
diff --git a/drivers/serial/cpm_uart/cpm_uart_cpm2.c b/drivers/serial/cpm_uart/cpm_uart_cpm2.c
index 787a8f1346..fa455996ad 100644
--- a/drivers/serial/cpm_uart/cpm_uart_cpm2.c
+++ b/drivers/serial/cpm_uart/cpm_uart_cpm2.c
@@ -285,7 +285,7 @@ void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
285int __init cpm_uart_init_portdesc(void) 285int __init cpm_uart_init_portdesc(void)
286{ 286{
287#if defined(CONFIG_SERIAL_CPM_SMC1) || defined(CONFIG_SERIAL_CPM_SMC2) 287#if defined(CONFIG_SERIAL_CPM_SMC1) || defined(CONFIG_SERIAL_CPM_SMC2)
288 u32 addr; 288 u16 *addr;
289#endif 289#endif
290 pr_debug("CPM uart[-]:init portdesc\n"); 290 pr_debug("CPM uart[-]:init portdesc\n");
291 291
diff --git a/drivers/serial/dz.c b/drivers/serial/dz.c
index 587d87b9eb..d31721f274 100644
--- a/drivers/serial/dz.c
+++ b/drivers/serial/dz.c
@@ -170,8 +170,7 @@ static void dz_enable_ms(struct uart_port *port)
170 * This routine deals with inputs from any lines. 170 * This routine deals with inputs from any lines.
171 * ------------------------------------------------------------ 171 * ------------------------------------------------------------
172 */ 172 */
173static inline void dz_receive_chars(struct dz_port *dport_in, 173static inline void dz_receive_chars(struct dz_port *dport_in)
174 struct pt_regs *regs)
175{ 174{
176 struct dz_port *dport; 175 struct dz_port *dport;
177 struct tty_struct *tty = NULL; 176 struct tty_struct *tty = NULL;
@@ -226,7 +225,7 @@ static inline void dz_receive_chars(struct dz_port *dport_in,
226 break; 225 break;
227 } 226 }
228 227
229 if (uart_handle_sysrq_char(&dport->port, ch, regs)) 228 if (uart_handle_sysrq_char(&dport->port, ch))
230 continue; 229 continue;
231 230
232 if ((status & dport->port.ignore_status_mask) == 0) { 231 if ((status & dport->port.ignore_status_mask) == 0) {
@@ -332,7 +331,7 @@ static irqreturn_t dz_interrupt(int irq, void *dev)
332 status = dz_in(dport, DZ_CSR); 331 status = dz_in(dport, DZ_CSR);
333 332
334 if ((status & (DZ_RDONE | DZ_RIE)) == (DZ_RDONE | DZ_RIE)) 333 if ((status & (DZ_RDONE | DZ_RIE)) == (DZ_RDONE | DZ_RIE))
335 dz_receive_chars(dport, regs); 334 dz_receive_chars(dport);
336 335
337 if ((status & (DZ_TRDY | DZ_TIE)) == (DZ_TRDY | DZ_TIE)) 336 if ((status & (DZ_TRDY | DZ_TIE)) == (DZ_TRDY | DZ_TIE))
338 dz_transmit_chars(dport); 337 dz_transmit_chars(dport);
diff --git a/drivers/serial/imx.c b/drivers/serial/imx.c
index e216dcf293..04cc88cc52 100644
--- a/drivers/serial/imx.c
+++ b/drivers/serial/imx.c
@@ -154,7 +154,7 @@ static inline void imx_transmit_buffer(struct imx_port *sport)
154{ 154{
155 struct circ_buf *xmit = &sport->port.info->xmit; 155 struct circ_buf *xmit = &sport->port.info->xmit;
156 156
157 do { 157 while (!(UTS((u32)sport->port.membase) & UTS_TXFULL)) {
158 /* send xmit->buf[xmit->tail] 158 /* send xmit->buf[xmit->tail]
159 * out the port here */ 159 * out the port here */
160 URTX0((u32)sport->port.membase) = xmit->buf[xmit->tail]; 160 URTX0((u32)sport->port.membase) = xmit->buf[xmit->tail];
@@ -163,7 +163,7 @@ static inline void imx_transmit_buffer(struct imx_port *sport)
163 sport->port.icount.tx++; 163 sport->port.icount.tx++;
164 if (uart_circ_empty(xmit)) 164 if (uart_circ_empty(xmit))
165 break; 165 break;
166 } while (!(UTS((u32)sport->port.membase) & UTS_TXFULL)); 166 }
167 167
168 if (uart_circ_empty(xmit)) 168 if (uart_circ_empty(xmit))
169 imx_stop_tx(&sport->port); 169 imx_stop_tx(&sport->port);
@@ -178,8 +178,7 @@ static void imx_start_tx(struct uart_port *port)
178 178
179 UCR1((u32)sport->port.membase) |= UCR1_TXMPTYEN; 179 UCR1((u32)sport->port.membase) |= UCR1_TXMPTYEN;
180 180
181 if(UTS((u32)sport->port.membase) & UTS_TXEMPTY) 181 imx_transmit_buffer(sport);
182 imx_transmit_buffer(sport);
183} 182}
184 183
185static irqreturn_t imx_rtsint(int irq, void *dev_id) 184static irqreturn_t imx_rtsint(int irq, void *dev_id)
@@ -404,7 +403,8 @@ static int imx_startup(struct uart_port *port)
404 if (retval) goto error_out2; 403 if (retval) goto error_out2;
405 404
406 retval = request_irq(sport->rtsirq, imx_rtsint, 405 retval = request_irq(sport->rtsirq, imx_rtsint,
407 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, 406 (sport->rtsirq < IMX_IRQS) ? 0 :
407 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
408 DRIVER_NAME, sport); 408 DRIVER_NAME, sport);
409 if (retval) goto error_out3; 409 if (retval) goto error_out3;
410 410
@@ -678,7 +678,7 @@ static struct imx_port imx_ports[] = {
678 .mapbase = IMX_UART1_BASE, /* FIXME */ 678 .mapbase = IMX_UART1_BASE, /* FIXME */
679 .irq = UART1_MINT_RX, 679 .irq = UART1_MINT_RX,
680 .uartclk = 16000000, 680 .uartclk = 16000000,
681 .fifosize = 8, 681 .fifosize = 32,
682 .flags = UPF_BOOT_AUTOCONF, 682 .flags = UPF_BOOT_AUTOCONF,
683 .ops = &imx_pops, 683 .ops = &imx_pops,
684 .line = 0, 684 .line = 0,
@@ -694,7 +694,7 @@ static struct imx_port imx_ports[] = {
694 .mapbase = IMX_UART2_BASE, /* FIXME */ 694 .mapbase = IMX_UART2_BASE, /* FIXME */
695 .irq = UART2_MINT_RX, 695 .irq = UART2_MINT_RX,
696 .uartclk = 16000000, 696 .uartclk = 16000000,
697 .fifosize = 8, 697 .fifosize = 32,
698 .flags = UPF_BOOT_AUTOCONF, 698 .flags = UPF_BOOT_AUTOCONF,
699 .ops = &imx_pops, 699 .ops = &imx_pops,
700 .line = 1, 700 .line = 1,
diff --git a/drivers/serial/mcfserial.c b/drivers/serial/mcfserial.c
index 08430961a8..99af084c7c 100644
--- a/drivers/serial/mcfserial.c
+++ b/drivers/serial/mcfserial.c
@@ -425,15 +425,13 @@ irqreturn_t mcfrs_interrupt(int irq, void *dev_id)
425 * ------------------------------------------------------------------- 425 * -------------------------------------------------------------------
426 */ 426 */
427 427
428static void mcfrs_offintr(void *private) 428static void mcfrs_offintr(struct work_struct *work)
429{ 429{
430 struct mcf_serial *info = (struct mcf_serial *) private; 430 struct mcf_serial *info = container_of(work, struct mcf_serial, tqueue);
431 struct tty_struct *tty; 431 struct tty_struct *tty = info->tty;
432 432
433 tty = info->tty; 433 if (tty)
434 if (!tty) 434 tty_wakeup(tty);
435 return;
436 tty_wakeup(tty);
437} 435}
438 436
439 437
@@ -497,16 +495,13 @@ static void mcfrs_timer(void)
497 * do_serial_hangup() -> tty->hangup() -> mcfrs_hangup() 495 * do_serial_hangup() -> tty->hangup() -> mcfrs_hangup()
498 * 496 *
499 */ 497 */
500static void do_serial_hangup(void *private) 498static void do_serial_hangup(struct work_struct *work)
501{ 499{
502 struct mcf_serial *info = (struct mcf_serial *) private; 500 struct mcf_serial *info = container_of(work, struct mcf_serial, tqueue_hangup);
503 struct tty_struct *tty; 501 struct tty_struct *tty = info->tty;
504 502
505 tty = info->tty; 503 if (tty)
506 if (!tty) 504 tty_hangup(tty);
507 return;
508
509 tty_hangup(tty);
510} 505}
511 506
512static int startup(struct mcf_serial * info) 507static int startup(struct mcf_serial * info)
@@ -857,7 +852,7 @@ static void mcfrs_throttle(struct tty_struct * tty)
857#ifdef SERIAL_DEBUG_THROTTLE 852#ifdef SERIAL_DEBUG_THROTTLE
858 char buf[64]; 853 char buf[64];
859 854
860 printk("throttle %s: %d....\n", _tty_name(tty, buf), 855 printk("throttle %s: %d....\n", tty_name(tty, buf),
861 tty->ldisc.chars_in_buffer(tty)); 856 tty->ldisc.chars_in_buffer(tty));
862#endif 857#endif
863 858
@@ -876,7 +871,7 @@ static void mcfrs_unthrottle(struct tty_struct * tty)
876#ifdef SERIAL_DEBUG_THROTTLE 871#ifdef SERIAL_DEBUG_THROTTLE
877 char buf[64]; 872 char buf[64];
878 873
879 printk("unthrottle %s: %d....\n", _tty_name(tty, buf), 874 printk("unthrottle %s: %d....\n", tty_name(tty, buf),
880 tty->ldisc.chars_in_buffer(tty)); 875 tty->ldisc.chars_in_buffer(tty));
881#endif 876#endif
882 877
@@ -1541,8 +1536,8 @@ static void mcfrs_irqinit(struct mcf_serial *info)
1541 * External Pin Mask Setting & Enable External Pin for Interface 1536 * External Pin Mask Setting & Enable External Pin for Interface
1542 * mrcbis@aliceposta.it 1537 * mrcbis@aliceposta.it
1543 */ 1538 */
1544 unsigned short *serpin_enable_mask; 1539 u16 *serpin_enable_mask;
1545 serpin_enable_mask = (MCF_IPSBAR + MCF_GPIO_PAR_UART); 1540 serpin_enable_mask = (u16 *) (MCF_IPSBAR + MCF_GPIO_PAR_UART);
1546 if (info->line == 0) 1541 if (info->line == 0)
1547 *serpin_enable_mask |= UART0_ENABLE_MASK; 1542 *serpin_enable_mask |= UART0_ENABLE_MASK;
1548 else if (info->line == 1) 1543 else if (info->line == 1)
@@ -1551,6 +1546,13 @@ static void mcfrs_irqinit(struct mcf_serial *info)
1551 *serpin_enable_mask |= UART2_ENABLE_MASK; 1546 *serpin_enable_mask |= UART2_ENABLE_MASK;
1552 } 1547 }
1553#endif 1548#endif
1549#if defined(CONFIG_M528x)
1550 /* make sure PUAPAR is set for UART0 and UART1 */
1551 if (info->line < 2) {
1552 volatile unsigned char *portp = (volatile unsigned char *) (MCF_MBAR + MCF5282_GPIO_PUAPAR);
1553 *portp |= (0x03 << (info->line * 2));
1554 }
1555#endif
1554#elif defined(CONFIG_M520x) 1556#elif defined(CONFIG_M520x)
1555 volatile unsigned char *icrp, *uartp; 1557 volatile unsigned char *icrp, *uartp;
1556 volatile unsigned long *imrp; 1558 volatile unsigned long *imrp;
@@ -1783,8 +1785,8 @@ mcfrs_init(void)
1783 info->event = 0; 1785 info->event = 0;
1784 info->count = 0; 1786 info->count = 0;
1785 info->blocked_open = 0; 1787 info->blocked_open = 0;
1786 INIT_WORK(&info->tqueue, mcfrs_offintr, info); 1788 INIT_WORK(&info->tqueue, mcfrs_offintr);
1787 INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info); 1789 INIT_WORK(&info->tqueue_hangup, do_serial_hangup);
1788 init_waitqueue_head(&info->open_wait); 1790 init_waitqueue_head(&info->open_wait);
1789 init_waitqueue_head(&info->close_wait); 1791 init_waitqueue_head(&info->close_wait);
1790 1792
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 955bbd653e..8d24cd5210 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -995,8 +995,10 @@ mpc52xx_uart_of_remove(struct of_device *op)
995 struct uart_port *port = dev_get_drvdata(&op->dev); 995 struct uart_port *port = dev_get_drvdata(&op->dev);
996 dev_set_drvdata(&op->dev, NULL); 996 dev_set_drvdata(&op->dev, NULL);
997 997
998 if (port) 998 if (port) {
999 uart_remove_one_port(&mpc52xx_uart_driver, port); 999 uart_remove_one_port(&mpc52xx_uart_driver, port);
1000 irq_dispose_mapping(port->irq);
1001 }
1000 1002
1001 return 0; 1003 return 0;
1002} 1004}
diff --git a/drivers/serial/mux.c b/drivers/serial/mux.c
index ccb8fa1800..83211013de 100644
--- a/drivers/serial/mux.c
+++ b/drivers/serial/mux.c
@@ -51,7 +51,11 @@
51 51
52#define MUX_NR 256 52#define MUX_NR 256
53static unsigned int port_cnt __read_mostly; 53static unsigned int port_cnt __read_mostly;
54static struct uart_port mux_ports[MUX_NR]; 54struct mux_port {
55 struct uart_port port;
56 int enabled;
57};
58static struct mux_port mux_ports[MUX_NR];
55 59
56static struct uart_driver mux_driver = { 60static struct uart_driver mux_driver = {
57 .owner = THIS_MODULE, 61 .owner = THIS_MODULE,
@@ -66,7 +70,36 @@ static struct timer_list mux_timer;
66 70
67#define UART_PUT_CHAR(p, c) __raw_writel((c), (p)->membase + IO_DATA_REG_OFFSET) 71#define UART_PUT_CHAR(p, c) __raw_writel((c), (p)->membase + IO_DATA_REG_OFFSET)
68#define UART_GET_FIFO_CNT(p) __raw_readl((p)->membase + IO_DCOUNT_REG_OFFSET) 72#define UART_GET_FIFO_CNT(p) __raw_readl((p)->membase + IO_DCOUNT_REG_OFFSET)
69#define GET_MUX_PORTS(iodc_data) ((((iodc_data)[4] & 0xf0) >> 4) * 8) + 8 73
74/**
75 * get_mux_port_count - Get the number of available ports on the Mux.
76 * @dev: The parisc device.
77 *
78 * This function is used to determine the number of ports the Mux
79 * supports. The IODC data reports the number of ports the Mux
80 * can support, but there are cases where not all the Mux ports
81 * are connected. This function can override the IODC and
82 * return the true port count.
83 */
84static int __init get_mux_port_count(struct parisc_device *dev)
85{
86 int status;
87 u8 iodc_data[32];
88 unsigned long bytecnt;
89
90 /* If this is the built-in Mux for the K-Class (Eole CAP/MUX),
91 * we only need to allocate resources for 1 port since the
92 * other 7 ports are not connected.
93 */
94 if(dev->id.hversion == 0x15)
95 return 1;
96
97 status = pdc_iodc_read(&bytecnt, dev->hpa.start, 0, iodc_data, 32);
98 BUG_ON(status != PDC_OK);
99
100 /* Return the number of ports specified in the iodc data. */
101 return ((((iodc_data)[4] & 0xf0) >> 4) * 8) + 8;
102}
70 103
71/** 104/**
72 * mux_tx_empty - Check if the transmitter fifo is empty. 105 * mux_tx_empty - Check if the transmitter fifo is empty.
@@ -250,7 +283,7 @@ static void mux_read(struct uart_port *port)
250 */ 283 */
251static int mux_startup(struct uart_port *port) 284static int mux_startup(struct uart_port *port)
252{ 285{
253 mod_timer(&mux_timer, jiffies + MUX_POLL_DELAY); 286 mux_ports[port->line].enabled = 1;
254 return 0; 287 return 0;
255} 288}
256 289
@@ -262,6 +295,7 @@ static int mux_startup(struct uart_port *port)
262 */ 295 */
263static void mux_shutdown(struct uart_port *port) 296static void mux_shutdown(struct uart_port *port)
264{ 297{
298 mux_ports[port->line].enabled = 0;
265} 299}
266 300
267/** 301/**
@@ -319,7 +353,7 @@ static int mux_request_port(struct uart_port *port)
319 * @port: Ptr to the uart_port. 353 * @port: Ptr to the uart_port.
320 * @type: Bitmask of required configurations. 354 * @type: Bitmask of required configurations.
321 * 355 *
322 * Perform any autoconfiguration steps for the port. This functino is 356 * Perform any autoconfiguration steps for the port. This function is
323 * called if the UPF_BOOT_AUTOCONF flag is specified for the port. 357 * called if the UPF_BOOT_AUTOCONF flag is specified for the port.
324 * [Note: This is required for now because of a bug in the Serial core. 358 * [Note: This is required for now because of a bug in the Serial core.
325 * rmk has already submitted a patch to linus, should be available for 359 * rmk has already submitted a patch to linus, should be available for
@@ -357,11 +391,11 @@ static void mux_poll(unsigned long unused)
357 int i; 391 int i;
358 392
359 for(i = 0; i < port_cnt; ++i) { 393 for(i = 0; i < port_cnt; ++i) {
360 if(!mux_ports[i].info) 394 if(!mux_ports[i].enabled)
361 continue; 395 continue;
362 396
363 mux_read(&mux_ports[i]); 397 mux_read(&mux_ports[i].port);
364 mux_write(&mux_ports[i]); 398 mux_write(&mux_ports[i].port);
365 } 399 }
366 400
367 mod_timer(&mux_timer, jiffies + MUX_POLL_DELAY); 401 mod_timer(&mux_timer, jiffies + MUX_POLL_DELAY);
@@ -371,8 +405,17 @@ static void mux_poll(unsigned long unused)
371#ifdef CONFIG_SERIAL_MUX_CONSOLE 405#ifdef CONFIG_SERIAL_MUX_CONSOLE
372static void mux_console_write(struct console *co, const char *s, unsigned count) 406static void mux_console_write(struct console *co, const char *s, unsigned count)
373{ 407{
374 while(count--) 408 /* Wait until the FIFO drains. */
375 pdc_iodc_putc(*s++); 409 while(UART_GET_FIFO_CNT(&mux_ports[0].port))
410 udelay(1);
411
412 while(count--) {
413 if(*s == '\n') {
414 UART_PUT_CHAR(&mux_ports[0].port, '\r');
415 }
416 UART_PUT_CHAR(&mux_ports[0].port, *s++);
417 }
418
376} 419}
377 420
378static int mux_console_setup(struct console *co, char *options) 421static int mux_console_setup(struct console *co, char *options)
@@ -428,19 +471,14 @@ static struct uart_ops mux_pops = {
428 */ 471 */
429static int __init mux_probe(struct parisc_device *dev) 472static int __init mux_probe(struct parisc_device *dev)
430{ 473{
431 int i, status, ports; 474 int i, status;
432 u8 iodc_data[32];
433 unsigned long bytecnt;
434 struct uart_port *port;
435 475
436 status = pdc_iodc_read(&bytecnt, dev->hpa.start, 0, iodc_data, 32); 476 int port_count = get_mux_port_count(dev);
437 if(status != PDC_OK) { 477 printk(KERN_INFO "Serial mux driver (%d ports) Revision: 0.6\n", port_count);
438 printk(KERN_ERR "Serial mux: Unable to read IODC.\n");
439 return 1;
440 }
441 478
442 ports = GET_MUX_PORTS(iodc_data); 479 dev_set_drvdata(&dev->dev, (void *)(long)port_count);
443 printk(KERN_INFO "Serial mux driver (%d ports) Revision: 0.3\n", ports); 480 request_mem_region(dev->hpa.start + MUX_OFFSET,
481 port_count * MUX_LINE_OFFSET, "Mux");
444 482
445 if(!port_cnt) { 483 if(!port_cnt) {
446 mux_driver.cons = MUX_CONSOLE; 484 mux_driver.cons = MUX_CONSOLE;
@@ -450,13 +488,10 @@ static int __init mux_probe(struct parisc_device *dev)
450 printk(KERN_ERR "Serial mux: Unable to register driver.\n"); 488 printk(KERN_ERR "Serial mux: Unable to register driver.\n");
451 return 1; 489 return 1;
452 } 490 }
453
454 init_timer(&mux_timer);
455 mux_timer.function = mux_poll;
456 } 491 }
457 492
458 for(i = 0; i < ports; ++i, ++port_cnt) { 493 for(i = 0; i < port_count; ++i, ++port_cnt) {
459 port = &mux_ports[port_cnt]; 494 struct uart_port *port = &mux_ports[port_cnt].port;
460 port->iobase = 0; 495 port->iobase = 0;
461 port->mapbase = dev->hpa.start + MUX_OFFSET + 496 port->mapbase = dev->hpa.start + MUX_OFFSET +
462 (i * MUX_LINE_OFFSET); 497 (i * MUX_LINE_OFFSET);
@@ -477,27 +512,73 @@ static int __init mux_probe(struct parisc_device *dev)
477 */ 512 */
478 port->timeout = HZ / 50; 513 port->timeout = HZ / 50;
479 spin_lock_init(&port->lock); 514 spin_lock_init(&port->lock);
515
480 status = uart_add_one_port(&mux_driver, port); 516 status = uart_add_one_port(&mux_driver, port);
481 BUG_ON(status); 517 BUG_ON(status);
482 } 518 }
483 519
484#ifdef CONFIG_SERIAL_MUX_CONSOLE
485 register_console(&mux_console);
486#endif
487 return 0; 520 return 0;
488} 521}
489 522
523static int __devexit mux_remove(struct parisc_device *dev)
524{
525 int i, j;
526 int port_count = (long)dev_get_drvdata(&dev->dev);
527
528 /* Find Port 0 for this card in the mux_ports list. */
529 for(i = 0; i < port_cnt; ++i) {
530 if(mux_ports[i].port.mapbase == dev->hpa.start + MUX_OFFSET)
531 break;
532 }
533 BUG_ON(i + port_count > port_cnt);
534
535 /* Release the resources associated with each port on the device. */
536 for(j = 0; j < port_count; ++j, ++i) {
537 struct uart_port *port = &mux_ports[i].port;
538
539 uart_remove_one_port(&mux_driver, port);
540 if(port->membase)
541 iounmap(port->membase);
542 }
543
544 release_mem_region(dev->hpa.start + MUX_OFFSET, port_count * MUX_LINE_OFFSET);
545 return 0;
546}
547
548/* Hack. This idea was taken from the 8250_gsc.c on how to properly order
549 * the serial port detection in the proper order. The idea is we always
550 * want the builtin mux to be detected before addin mux cards, so we
551 * specifically probe for the builtin mux cards first.
552 *
553 * This table only contains the parisc_device_id of known builtin mux
554 * devices. All other mux cards will be detected by the generic mux_tbl.
555 */
556static struct parisc_device_id builtin_mux_tbl[] = {
557 { HPHW_A_DIRECT, HVERSION_REV_ANY_ID, 0x15, 0x0000D }, /* All K-class */
558 { HPHW_A_DIRECT, HVERSION_REV_ANY_ID, 0x44, 0x0000D }, /* E35, E45, and E55 */
559 { 0, }
560};
561
490static struct parisc_device_id mux_tbl[] = { 562static struct parisc_device_id mux_tbl[] = {
491 { HPHW_A_DIRECT, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0000D }, 563 { HPHW_A_DIRECT, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0000D },
492 { 0, } 564 { 0, }
493}; 565};
494 566
567MODULE_DEVICE_TABLE(parisc, builtin_mux_tbl);
495MODULE_DEVICE_TABLE(parisc, mux_tbl); 568MODULE_DEVICE_TABLE(parisc, mux_tbl);
496 569
570static struct parisc_driver builtin_serial_mux_driver = {
571 .name = "builtin_serial_mux",
572 .id_table = builtin_mux_tbl,
573 .probe = mux_probe,
574 .remove = __devexit_p(mux_remove),
575};
576
497static struct parisc_driver serial_mux_driver = { 577static struct parisc_driver serial_mux_driver = {
498 .name = "serial_mux", 578 .name = "serial_mux",
499 .id_table = mux_tbl, 579 .id_table = mux_tbl,
500 .probe = mux_probe, 580 .probe = mux_probe,
581 .remove = __devexit_p(mux_remove),
501}; 582};
502 583
503/** 584/**
@@ -507,7 +588,21 @@ static struct parisc_driver serial_mux_driver = {
507 */ 588 */
508static int __init mux_init(void) 589static int __init mux_init(void)
509{ 590{
510 return register_parisc_driver(&serial_mux_driver); 591 register_parisc_driver(&builtin_serial_mux_driver);
592 register_parisc_driver(&serial_mux_driver);
593
594 if(port_cnt > 0) {
595 /* Start the Mux timer */
596 init_timer(&mux_timer);
597 mux_timer.function = mux_poll;
598 mod_timer(&mux_timer, jiffies + MUX_POLL_DELAY);
599
600#ifdef CONFIG_SERIAL_MUX_CONSOLE
601 register_console(&mux_console);
602#endif
603 }
604
605 return 0;
511} 606}
512 607
513/** 608/**
@@ -517,14 +612,16 @@ static int __init mux_init(void)
517 */ 612 */
518static void __exit mux_exit(void) 613static void __exit mux_exit(void)
519{ 614{
520 int i; 615 /* Delete the Mux timer. */
521 616 if(port_cnt > 0) {
522 for (i = 0; i < port_cnt; i++) { 617 del_timer(&mux_timer);
523 uart_remove_one_port(&mux_driver, &mux_ports[i]); 618#ifdef CONFIG_SERIAL_MUX_CONSOLE
524 if (mux_ports[i].membase) 619 unregister_console(&mux_console);
525 iounmap(mux_ports[i].membase); 620#endif
526 } 621 }
527 622
623 unregister_parisc_driver(&builtin_serial_mux_driver);
624 unregister_parisc_driver(&serial_mux_driver);
528 uart_unregister_driver(&mux_driver); 625 uart_unregister_driver(&mux_driver);
529} 626}
530 627
diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c
index c2f1012449..6b76babc7f 100644
--- a/drivers/serial/serial_cs.c
+++ b/drivers/serial/serial_cs.c
@@ -248,6 +248,10 @@ static const struct serial_quirk quirks[] = {
248 .multi = 2, 248 .multi = 2,
249 }, { 249 }, {
250 .manfid = MANFID_QUATECH, 250 .manfid = MANFID_QUATECH,
251 .prodid = PRODID_QUATECH_DUAL_RS232_G,
252 .multi = 2,
253 }, {
254 .manfid = MANFID_QUATECH,
251 .prodid = PRODID_QUATECH_QUAD_RS232, 255 .prodid = PRODID_QUATECH_QUAD_RS232,
252 .multi = 4, 256 .multi = 4,
253 }, { 257 }, {
@@ -891,6 +895,7 @@ static struct pcmcia_device_id serial_ids[] = {
891 PCMCIA_DEVICE_PROD_ID12("OEM ", "C288MX ", 0xb572d360, 0xd2385b7a), 895 PCMCIA_DEVICE_PROD_ID12("OEM ", "C288MX ", 0xb572d360, 0xd2385b7a),
892 PCMCIA_DEVICE_PROD_ID12("PCMCIA ", "C336MX ", 0x99bcafe9, 0xaa25bcab), 896 PCMCIA_DEVICE_PROD_ID12("PCMCIA ", "C336MX ", 0x99bcafe9, 0xaa25bcab),
893 PCMCIA_DEVICE_PROD_ID12("Quatech Inc", "PCMCIA Dual RS-232 Serial Port Card", 0xc4420b35, 0x92abc92f), 897 PCMCIA_DEVICE_PROD_ID12("Quatech Inc", "PCMCIA Dual RS-232 Serial Port Card", 0xc4420b35, 0x92abc92f),
898 PCMCIA_DEVICE_PROD_ID12("Quatech Inc", "Dual RS-232 Serial Port PC Card", 0xc4420b35, 0x031a380d),
894 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "EN2218-LAN/MODEM", 0x281f1c5d, 0x570f348e, "PCMLM28.cis"), 899 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "EN2218-LAN/MODEM", 0x281f1c5d, 0x570f348e, "PCMLM28.cis"),
895 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "UE2218-LAN/MODEM", 0x281f1c5d, 0x6fdcacee, "PCMLM28.cis"), 900 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "UE2218-LAN/MODEM", 0x281f1c5d, 0x6fdcacee, "PCMLM28.cis"),
896 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "Psion Dacom", "Gold Card V34 Ethernet", 0xf5f025c2, 0x338e8155, "PCMLM28.cis"), 901 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "Psion Dacom", "Gold Card V34 Ethernet", 0xf5f025c2, 0x338e8155, "PCMLM28.cis"),
diff --git a/drivers/serial/serial_txx9.c b/drivers/serial/serial_txx9.c
index f4440d3293..509ace7e68 100644
--- a/drivers/serial/serial_txx9.c
+++ b/drivers/serial/serial_txx9.c
@@ -38,6 +38,8 @@
38 * Fix some spin_locks. 38 * Fix some spin_locks.
39 * Do not call uart_add_one_port for absent ports. 39 * Do not call uart_add_one_port for absent ports.
40 * 1.07 Use CONFIG_SERIAL_TXX9_NR_UARTS. Cleanup. 40 * 1.07 Use CONFIG_SERIAL_TXX9_NR_UARTS. Cleanup.
41 * 1.08 Use platform_device.
42 * Fix and cleanup suspend/resume/initialization codes.
41 */ 43 */
42 44
43#if defined(CONFIG_SERIAL_TXX9_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 45#if defined(CONFIG_SERIAL_TXX9_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
@@ -50,7 +52,7 @@
50#include <linux/console.h> 52#include <linux/console.h>
51#include <linux/sysrq.h> 53#include <linux/sysrq.h>
52#include <linux/delay.h> 54#include <linux/delay.h>
53#include <linux/device.h> 55#include <linux/platform_device.h>
54#include <linux/pci.h> 56#include <linux/pci.h>
55#include <linux/tty.h> 57#include <linux/tty.h>
56#include <linux/tty_flip.h> 58#include <linux/tty_flip.h>
@@ -60,7 +62,7 @@
60 62
61#include <asm/io.h> 63#include <asm/io.h>
62 64
63static char *serial_version = "1.07"; 65static char *serial_version = "1.08";
64static char *serial_name = "TX39/49 Serial driver"; 66static char *serial_name = "TX39/49 Serial driver";
65 67
66#define PASS_LIMIT 256 68#define PASS_LIMIT 256
@@ -94,12 +96,7 @@ static char *serial_name = "TX39/49 Serial driver";
94 96
95struct uart_txx9_port { 97struct uart_txx9_port {
96 struct uart_port port; 98 struct uart_port port;
97 99 /* No additional info for now */
98 /*
99 * We provide a per-port pm hook.
100 */
101 void (*pm)(struct uart_port *port,
102 unsigned int state, unsigned int old);
103}; 100};
104 101
105#define TXX9_REGION_SIZE 0x24 102#define TXX9_REGION_SIZE 0x24
@@ -277,6 +274,31 @@ static void serial_txx9_enable_ms(struct uart_port *port)
277 /* TXX9-SIO can not control DTR... */ 274 /* TXX9-SIO can not control DTR... */
278} 275}
279 276
277static void serial_txx9_initialize(struct uart_port *port)
278{
279 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
280 unsigned int tmout = 10000;
281
282 sio_out(up, TXX9_SIFCR, TXX9_SIFCR_SWRST);
283 /* TX4925 BUG WORKAROUND. Accessing SIOC register
284 * immediately after soft reset causes bus error. */
285 mmiowb();
286 udelay(1);
287 while ((sio_in(up, TXX9_SIFCR) & TXX9_SIFCR_SWRST) && --tmout)
288 udelay(1);
289 /* TX Int by FIFO Empty, RX Int by Receiving 1 char. */
290 sio_set(up, TXX9_SIFCR,
291 TXX9_SIFCR_TDIL_MAX | TXX9_SIFCR_RDIL_1);
292 /* initial settings */
293 sio_out(up, TXX9_SILCR,
294 TXX9_SILCR_UMODE_8BIT | TXX9_SILCR_USBL_1BIT |
295 ((up->port.flags & UPF_TXX9_USE_SCLK) ?
296 TXX9_SILCR_SCS_SCLK_BG : TXX9_SILCR_SCS_IMCLK_BG));
297 sio_quot_set(up, uart_get_divisor(port, 9600));
298 sio_out(up, TXX9_SIFLCR, TXX9_SIFLCR_RTSTL_MAX /* 15 */);
299 sio_out(up, TXX9_SIDICR, 0);
300}
301
280static inline void 302static inline void
281receive_chars(struct uart_txx9_port *up, unsigned int *status) 303receive_chars(struct uart_txx9_port *up, unsigned int *status)
282{ 304{
@@ -657,9 +679,8 @@ static void
657serial_txx9_pm(struct uart_port *port, unsigned int state, 679serial_txx9_pm(struct uart_port *port, unsigned int state,
658 unsigned int oldstate) 680 unsigned int oldstate)
659{ 681{
660 struct uart_txx9_port *up = (struct uart_txx9_port *)port; 682 if (state == 0)
661 if (up->pm) 683 serial_txx9_initialize(port);
662 up->pm(port, state, oldstate);
663} 684}
664 685
665static int serial_txx9_request_resource(struct uart_txx9_port *up) 686static int serial_txx9_request_resource(struct uart_txx9_port *up)
@@ -732,7 +753,6 @@ static int serial_txx9_request_port(struct uart_port *port)
732static void serial_txx9_config_port(struct uart_port *port, int uflags) 753static void serial_txx9_config_port(struct uart_port *port, int uflags)
733{ 754{
734 struct uart_txx9_port *up = (struct uart_txx9_port *)port; 755 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
735 unsigned long flags;
736 int ret; 756 int ret;
737 757
738 /* 758 /*
@@ -749,30 +769,7 @@ static void serial_txx9_config_port(struct uart_port *port, int uflags)
749 if (up->port.line == up->port.cons->index) 769 if (up->port.line == up->port.cons->index)
750 return; 770 return;
751#endif 771#endif
752 spin_lock_irqsave(&up->port.lock, flags); 772 serial_txx9_initialize(port);
753 /*
754 * Reset the UART.
755 */
756 sio_out(up, TXX9_SIFCR, TXX9_SIFCR_SWRST);
757#ifdef CONFIG_CPU_TX49XX
758 /* TX4925 BUG WORKAROUND. Accessing SIOC register
759 * immediately after soft reset causes bus error. */
760 iob();
761 udelay(1);
762#endif
763 while (sio_in(up, TXX9_SIFCR) & TXX9_SIFCR_SWRST)
764 ;
765 /* TX Int by FIFO Empty, RX Int by Receiving 1 char. */
766 sio_set(up, TXX9_SIFCR,
767 TXX9_SIFCR_TDIL_MAX | TXX9_SIFCR_RDIL_1);
768 /* initial settings */
769 sio_out(up, TXX9_SILCR,
770 TXX9_SILCR_UMODE_8BIT | TXX9_SILCR_USBL_1BIT |
771 ((up->port.flags & UPF_TXX9_USE_SCLK) ?
772 TXX9_SILCR_SCS_SCLK_BG : TXX9_SILCR_SCS_IMCLK_BG));
773 sio_quot_set(up, uart_get_divisor(port, 9600));
774 sio_out(up, TXX9_SIFLCR, TXX9_SIFLCR_RTSTL_MAX /* 15 */);
775 spin_unlock_irqrestore(&up->port.lock, flags);
776} 773}
777 774
778static int 775static int
@@ -818,7 +815,8 @@ static struct uart_ops serial_txx9_pops = {
818 815
819static struct uart_txx9_port serial_txx9_ports[UART_NR]; 816static struct uart_txx9_port serial_txx9_ports[UART_NR];
820 817
821static void __init serial_txx9_register_ports(struct uart_driver *drv) 818static void __init serial_txx9_register_ports(struct uart_driver *drv,
819 struct device *dev)
822{ 820{
823 int i; 821 int i;
824 822
@@ -827,6 +825,7 @@ static void __init serial_txx9_register_ports(struct uart_driver *drv)
827 825
828 up->port.line = i; 826 up->port.line = i;
829 up->port.ops = &serial_txx9_pops; 827 up->port.ops = &serial_txx9_pops;
828 up->port.dev = dev;
830 if (up->port.iobase || up->port.mapbase) 829 if (up->port.iobase || up->port.mapbase)
831 uart_add_one_port(drv, &up->port); 830 uart_add_one_port(drv, &up->port);
832 } 831 }
@@ -898,7 +897,7 @@ serial_txx9_console_write(struct console *co, const char *s, unsigned int count)
898 sio_out(up, TXX9_SIDICR, ier); 897 sio_out(up, TXX9_SIDICR, ier);
899} 898}
900 899
901static int serial_txx9_console_setup(struct console *co, char *options) 900static int __init serial_txx9_console_setup(struct console *co, char *options)
902{ 901{
903 struct uart_port *port; 902 struct uart_port *port;
904 struct uart_txx9_port *up; 903 struct uart_txx9_port *up;
@@ -919,17 +918,7 @@ static int serial_txx9_console_setup(struct console *co, char *options)
919 if (!port->ops) 918 if (!port->ops)
920 return -ENODEV; 919 return -ENODEV;
921 920
922 /* 921 serial_txx9_initialize(&up->port);
923 * Disable UART interrupts, set DTR and RTS high
924 * and set speed.
925 */
926 sio_out(up, TXX9_SIDICR, 0);
927 /* initial settings */
928 sio_out(up, TXX9_SILCR,
929 TXX9_SILCR_UMODE_8BIT | TXX9_SILCR_USBL_1BIT |
930 ((port->flags & UPF_TXX9_USE_SCLK) ?
931 TXX9_SILCR_SCS_SCLK_BG : TXX9_SILCR_SCS_IMCLK_BG));
932 sio_out(up, TXX9_SIFLCR, TXX9_SIFLCR_RTSTL_MAX /* 15 */);
933 922
934 if (options) 923 if (options)
935 uart_parse_options(options, &baud, &parity, &bits, &flow); 924 uart_parse_options(options, &baud, &parity, &bits, &flow);
@@ -981,31 +970,6 @@ int __init early_serial_txx9_setup(struct uart_port *port)
981 return 0; 970 return 0;
982} 971}
983 972
984#ifdef ENABLE_SERIAL_TXX9_PCI
985#ifdef CONFIG_PM
986/**
987 * serial_txx9_suspend_port - suspend one serial port
988 * @line: serial line number
989 *
990 * Suspend one serial port.
991 */
992static void serial_txx9_suspend_port(int line)
993{
994 uart_suspend_port(&serial_txx9_reg, &serial_txx9_ports[line].port);
995}
996
997/**
998 * serial_txx9_resume_port - resume one serial port
999 * @line: serial line number
1000 *
1001 * Resume one serial port.
1002 */
1003static void serial_txx9_resume_port(int line)
1004{
1005 uart_resume_port(&serial_txx9_reg, &serial_txx9_ports[line].port);
1006}
1007#endif
1008
1009static DEFINE_MUTEX(serial_txx9_mutex); 973static DEFINE_MUTEX(serial_txx9_mutex);
1010 974
1011/** 975/**
@@ -1028,8 +992,18 @@ static int __devinit serial_txx9_register_port(struct uart_port *port)
1028 mutex_lock(&serial_txx9_mutex); 992 mutex_lock(&serial_txx9_mutex);
1029 for (i = 0; i < UART_NR; i++) { 993 for (i = 0; i < UART_NR; i++) {
1030 uart = &serial_txx9_ports[i]; 994 uart = &serial_txx9_ports[i];
1031 if (!(uart->port.iobase || uart->port.mapbase)) 995 if (uart_match_port(&uart->port, port)) {
996 uart_remove_one_port(&serial_txx9_reg, &uart->port);
1032 break; 997 break;
998 }
999 }
1000 if (i == UART_NR) {
1001 /* Find unused port */
1002 for (i = 0; i < UART_NR; i++) {
1003 uart = &serial_txx9_ports[i];
1004 if (!(uart->port.iobase || uart->port.mapbase))
1005 break;
1006 }
1033 } 1007 }
1034 if (i < UART_NR) { 1008 if (i < UART_NR) {
1035 uart->port.iobase = port->iobase; 1009 uart->port.iobase = port->iobase;
@@ -1072,6 +1046,95 @@ static void __devexit serial_txx9_unregister_port(int line)
1072} 1046}
1073 1047
1074/* 1048/*
1049 * Register a set of serial devices attached to a platform device.
1050 */
1051static int __devinit serial_txx9_probe(struct platform_device *dev)
1052{
1053 struct uart_port *p = dev->dev.platform_data;
1054 struct uart_port port;
1055 int ret, i;
1056
1057 memset(&port, 0, sizeof(struct uart_port));
1058 for (i = 0; p && p->uartclk != 0; p++, i++) {
1059 port.iobase = p->iobase;
1060 port.membase = p->membase;
1061 port.irq = p->irq;
1062 port.uartclk = p->uartclk;
1063 port.iotype = p->iotype;
1064 port.flags = p->flags;
1065 port.mapbase = p->mapbase;
1066 port.dev = &dev->dev;
1067 ret = serial_txx9_register_port(&port);
1068 if (ret < 0) {
1069 dev_err(&dev->dev, "unable to register port at index %d "
1070 "(IO%x MEM%lx IRQ%d): %d\n", i,
1071 p->iobase, p->mapbase, p->irq, ret);
1072 }
1073 }
1074 return 0;
1075}
1076
1077/*
1078 * Remove serial ports registered against a platform device.
1079 */
1080static int __devexit serial_txx9_remove(struct platform_device *dev)
1081{
1082 int i;
1083
1084 for (i = 0; i < UART_NR; i++) {
1085 struct uart_txx9_port *up = &serial_txx9_ports[i];
1086
1087 if (up->port.dev == &dev->dev)
1088 serial_txx9_unregister_port(i);
1089 }
1090 return 0;
1091}
1092
1093#ifdef CONFIG_PM
1094static int serial_txx9_suspend(struct platform_device *dev, pm_message_t state)
1095{
1096 int i;
1097
1098 for (i = 0; i < UART_NR; i++) {
1099 struct uart_txx9_port *up = &serial_txx9_ports[i];
1100
1101 if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
1102 uart_suspend_port(&serial_txx9_reg, &up->port);
1103 }
1104
1105 return 0;
1106}
1107
1108static int serial_txx9_resume(struct platform_device *dev)
1109{
1110 int i;
1111
1112 for (i = 0; i < UART_NR; i++) {
1113 struct uart_txx9_port *up = &serial_txx9_ports[i];
1114
1115 if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
1116 uart_resume_port(&serial_txx9_reg, &up->port);
1117 }
1118
1119 return 0;
1120}
1121#endif
1122
1123static struct platform_driver serial_txx9_plat_driver = {
1124 .probe = serial_txx9_probe,
1125 .remove = __devexit_p(serial_txx9_remove),
1126#ifdef CONFIG_PM
1127 .suspend = serial_txx9_suspend,
1128 .resume = serial_txx9_resume,
1129#endif
1130 .driver = {
1131 .name = "serial_txx9",
1132 .owner = THIS_MODULE,
1133 },
1134};
1135
1136#ifdef ENABLE_SERIAL_TXX9_PCI
1137/*
1075 * Probe one serial board. Unfortunately, there is no rhyme nor reason 1138 * Probe one serial board. Unfortunately, there is no rhyme nor reason
1076 * to the arrangement of serial ports on a PCI card. 1139 * to the arrangement of serial ports on a PCI card.
1077 */ 1140 */
@@ -1097,20 +1160,22 @@ pciserial_txx9_init_one(struct pci_dev *dev, const struct pci_device_id *ent)
1097 line = serial_txx9_register_port(&port); 1160 line = serial_txx9_register_port(&port);
1098 if (line < 0) { 1161 if (line < 0) {
1099 printk(KERN_WARNING "Couldn't register serial port %s: %d\n", pci_name(dev), line); 1162 printk(KERN_WARNING "Couldn't register serial port %s: %d\n", pci_name(dev), line);
1163 pci_disable_device(dev);
1164 return line;
1100 } 1165 }
1101 pci_set_drvdata(dev, (void *)(long)line); 1166 pci_set_drvdata(dev, &serial_txx9_ports[line]);
1102 1167
1103 return 0; 1168 return 0;
1104} 1169}
1105 1170
1106static void __devexit pciserial_txx9_remove_one(struct pci_dev *dev) 1171static void __devexit pciserial_txx9_remove_one(struct pci_dev *dev)
1107{ 1172{
1108 int line = (int)(long)pci_get_drvdata(dev); 1173 struct uart_txx9_port *up = pci_get_drvdata(dev);
1109 1174
1110 pci_set_drvdata(dev, NULL); 1175 pci_set_drvdata(dev, NULL);
1111 1176
1112 if (line) { 1177 if (up) {
1113 serial_txx9_unregister_port(line); 1178 serial_txx9_unregister_port(up->port.line);
1114 pci_disable_device(dev); 1179 pci_disable_device(dev);
1115 } 1180 }
1116} 1181}
@@ -1118,10 +1183,10 @@ static void __devexit pciserial_txx9_remove_one(struct pci_dev *dev)
1118#ifdef CONFIG_PM 1183#ifdef CONFIG_PM
1119static int pciserial_txx9_suspend_one(struct pci_dev *dev, pm_message_t state) 1184static int pciserial_txx9_suspend_one(struct pci_dev *dev, pm_message_t state)
1120{ 1185{
1121 int line = (int)(long)pci_get_drvdata(dev); 1186 struct uart_txx9_port *up = pci_get_drvdata(dev);
1122 1187
1123 if (line) 1188 if (up)
1124 serial_txx9_suspend_port(line); 1189 uart_suspend_port(&serial_txx9_reg, &up->port);
1125 pci_save_state(dev); 1190 pci_save_state(dev);
1126 pci_set_power_state(dev, pci_choose_state(dev, state)); 1191 pci_set_power_state(dev, pci_choose_state(dev, state));
1127 return 0; 1192 return 0;
@@ -1129,15 +1194,12 @@ static int pciserial_txx9_suspend_one(struct pci_dev *dev, pm_message_t state)
1129 1194
1130static int pciserial_txx9_resume_one(struct pci_dev *dev) 1195static int pciserial_txx9_resume_one(struct pci_dev *dev)
1131{ 1196{
1132 int line = (int)(long)pci_get_drvdata(dev); 1197 struct uart_txx9_port *up = pci_get_drvdata(dev);
1133 1198
1134 pci_set_power_state(dev, PCI_D0); 1199 pci_set_power_state(dev, PCI_D0);
1135 pci_restore_state(dev); 1200 pci_restore_state(dev);
1136 1201 if (up)
1137 if (line) { 1202 uart_resume_port(&serial_txx9_reg, &up->port);
1138 pci_enable_device(dev);
1139 serial_txx9_resume_port(line);
1140 }
1141 return 0; 1203 return 0;
1142} 1204}
1143#endif 1205#endif
@@ -1161,6 +1223,8 @@ static struct pci_driver serial_txx9_pci_driver = {
1161MODULE_DEVICE_TABLE(pci, serial_txx9_pci_tbl); 1223MODULE_DEVICE_TABLE(pci, serial_txx9_pci_tbl);
1162#endif /* ENABLE_SERIAL_TXX9_PCI */ 1224#endif /* ENABLE_SERIAL_TXX9_PCI */
1163 1225
1226static struct platform_device *serial_txx9_plat_devs;
1227
1164static int __init serial_txx9_init(void) 1228static int __init serial_txx9_init(void)
1165{ 1229{
1166 int ret; 1230 int ret;
@@ -1168,13 +1232,39 @@ static int __init serial_txx9_init(void)
1168 printk(KERN_INFO "%s version %s\n", serial_name, serial_version); 1232 printk(KERN_INFO "%s version %s\n", serial_name, serial_version);
1169 1233
1170 ret = uart_register_driver(&serial_txx9_reg); 1234 ret = uart_register_driver(&serial_txx9_reg);
1171 if (ret >= 0) { 1235 if (ret)
1172 serial_txx9_register_ports(&serial_txx9_reg); 1236 goto out;
1237
1238 serial_txx9_plat_devs = platform_device_alloc("serial_txx9", -1);
1239 if (!serial_txx9_plat_devs) {
1240 ret = -ENOMEM;
1241 goto unreg_uart_drv;
1242 }
1243
1244 ret = platform_device_add(serial_txx9_plat_devs);
1245 if (ret)
1246 goto put_dev;
1247
1248 serial_txx9_register_ports(&serial_txx9_reg,
1249 &serial_txx9_plat_devs->dev);
1250
1251 ret = platform_driver_register(&serial_txx9_plat_driver);
1252 if (ret)
1253 goto del_dev;
1173 1254
1174#ifdef ENABLE_SERIAL_TXX9_PCI 1255#ifdef ENABLE_SERIAL_TXX9_PCI
1175 ret = pci_register_driver(&serial_txx9_pci_driver); 1256 ret = pci_register_driver(&serial_txx9_pci_driver);
1176#endif 1257#endif
1177 } 1258 if (ret == 0)
1259 goto out;
1260
1261 del_dev:
1262 platform_device_del(serial_txx9_plat_devs);
1263 put_dev:
1264 platform_device_put(serial_txx9_plat_devs);
1265 unreg_uart_drv:
1266 uart_unregister_driver(&serial_txx9_reg);
1267 out:
1178 return ret; 1268 return ret;
1179} 1269}
1180 1270
@@ -1185,6 +1275,8 @@ static void __exit serial_txx9_exit(void)
1185#ifdef ENABLE_SERIAL_TXX9_PCI 1275#ifdef ENABLE_SERIAL_TXX9_PCI
1186 pci_unregister_driver(&serial_txx9_pci_driver); 1276 pci_unregister_driver(&serial_txx9_pci_driver);
1187#endif 1277#endif
1278 platform_driver_unregister(&serial_txx9_plat_driver);
1279 platform_device_unregister(serial_txx9_plat_devs);
1188 for (i = 0; i < UART_NR; i++) { 1280 for (i = 0; i < UART_NR; i++) {
1189 struct uart_txx9_port *up = &serial_txx9_ports[i]; 1281 struct uart_txx9_port *up = &serial_txx9_ports[i];
1190 if (up->port.iobase || up->port.mapbase) 1282 if (up->port.iobase || up->port.mapbase)
diff --git a/drivers/serial/sn_console.c b/drivers/serial/sn_console.c
index 253ceb895c..a27e9e92cb 100644
--- a/drivers/serial/sn_console.c
+++ b/drivers/serial/sn_console.c
@@ -636,25 +636,6 @@ static irqreturn_t sn_sal_interrupt(int irq, void *dev_id)
636} 636}
637 637
638/** 638/**
639 * sn_sal_connect_interrupt - Request interrupt, handled by sn_sal_interrupt
640 * @port: Our sn_cons_port (which contains the uart port)
641 *
642 * returns the console irq if interrupt is successfully registered, else 0
643 *
644 */
645static int sn_sal_connect_interrupt(struct sn_cons_port *port)
646{
647 if (request_irq(SGI_UART_VECTOR, sn_sal_interrupt,
648 IRQF_DISABLED | IRQF_SHARED,
649 "SAL console driver", port) >= 0) {
650 return SGI_UART_VECTOR;
651 }
652
653 printk(KERN_INFO "sn_console: console proceeding in polled mode\n");
654 return 0;
655}
656
657/**
658 * sn_sal_timer_poll - this function handles polled console mode 639 * sn_sal_timer_poll - this function handles polled console mode
659 * @data: A pointer to our sn_cons_port (which contains the uart port) 640 * @data: A pointer to our sn_cons_port (which contains the uart port)
660 * 641 *
@@ -746,30 +727,31 @@ static void __init sn_sal_switch_to_asynch(struct sn_cons_port *port)
746 * mode. We were previously in asynch/polling mode (using init_timer). 727 * mode. We were previously in asynch/polling mode (using init_timer).
747 * 728 *
748 * We attempt to switch to interrupt mode here by calling 729 * We attempt to switch to interrupt mode here by calling
749 * sn_sal_connect_interrupt. If that works out, we enable receive interrupts. 730 * request_irq. If that works out, we enable receive interrupts.
750 */ 731 */
751static void __init sn_sal_switch_to_interrupts(struct sn_cons_port *port) 732static void __init sn_sal_switch_to_interrupts(struct sn_cons_port *port)
752{ 733{
753 int irq;
754 unsigned long flags; 734 unsigned long flags;
755 735
756 if (!port) 736 if (port) {
757 return; 737 DPRINTF("sn_console: switching to interrupt driven console\n");
758
759 DPRINTF("sn_console: switching to interrupt driven console\n");
760
761 spin_lock_irqsave(&port->sc_port.lock, flags);
762 738
763 irq = sn_sal_connect_interrupt(port); 739 if (request_irq(SGI_UART_VECTOR, sn_sal_interrupt,
740 IRQF_DISABLED | IRQF_SHARED,
741 "SAL console driver", port) >= 0) {
742 spin_lock_irqsave(&port->sc_port.lock, flags);
743 port->sc_port.irq = SGI_UART_VECTOR;
744 port->sc_ops = &intr_ops;
764 745
765 if (irq) { 746 /* turn on receive interrupts */
766 port->sc_port.irq = irq; 747 ia64_sn_console_intr_enable(SAL_CONSOLE_INTR_RECV);
767 port->sc_ops = &intr_ops; 748 spin_unlock_irqrestore(&port->sc_port.lock, flags);
768 749 }
769 /* turn on receive interrupts */ 750 else {
770 ia64_sn_console_intr_enable(SAL_CONSOLE_INTR_RECV); 751 printk(KERN_INFO
752 "sn_console: console proceeding in polled mode\n");
753 }
771 } 754 }
772 spin_unlock_irqrestore(&port->sc_port.lock, flags);
773} 755}
774 756
775/* 757/*
diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
index c2a9fef58e..6fa260d1a9 100644
--- a/drivers/spi/atmel_spi.c
+++ b/drivers/spi/atmel_spi.c
@@ -23,6 +23,10 @@
23#include <asm/arch/board.h> 23#include <asm/arch/board.h>
24#include <asm/arch/gpio.h> 24#include <asm/arch/gpio.h>
25 25
26#ifdef CONFIG_ARCH_AT91
27#include <asm/arch/cpu.h>
28#endif
29
26#include "atmel_spi.h" 30#include "atmel_spi.h"
27 31
28/* 32/*
@@ -491,7 +495,7 @@ static int atmel_spi_transfer(struct spi_device *spi, struct spi_message *msg)
491 return 0; 495 return 0;
492} 496}
493 497
494static void atmel_spi_cleanup(const struct spi_device *spi) 498static void atmel_spi_cleanup(struct spi_device *spi)
495{ 499{
496 if (spi->controller_state) 500 if (spi->controller_state)
497 gpio_free((unsigned int)spi->controller_data); 501 gpio_free((unsigned int)spi->controller_data);
diff --git a/drivers/spi/omap_uwire.c b/drivers/spi/omap_uwire.c
index 366af4959a..96f62b2df3 100644
--- a/drivers/spi/omap_uwire.c
+++ b/drivers/spi/omap_uwire.c
@@ -459,7 +459,7 @@ static int uwire_setup(struct spi_device *spi)
459 return uwire_setup_transfer(spi, NULL); 459 return uwire_setup_transfer(spi, NULL);
460} 460}
461 461
462static void uwire_cleanup(const struct spi_device *spi) 462static void uwire_cleanup(struct spi_device *spi)
463{ 463{
464 kfree(spi->controller_state); 464 kfree(spi->controller_state);
465} 465}
diff --git a/drivers/spi/spi_imx.c b/drivers/spi/spi_imx.c
index 6ccf8a12a2..51daa212c6 100644
--- a/drivers/spi/spi_imx.c
+++ b/drivers/spi/spi_imx.c
@@ -1361,10 +1361,9 @@ err_first_setup:
1361 return status; 1361 return status;
1362} 1362}
1363 1363
1364static void cleanup(const struct spi_device *spi) 1364static void cleanup(struct spi_device *spi)
1365{ 1365{
1366 struct chip_data *chip = spi_get_ctldata((struct spi_device *)spi); 1366 kfree(spi_get_ctldata(spi));
1367 kfree(chip);
1368} 1367}
1369 1368
1370static int init_queue(struct driver_data *drv_data) 1369static int init_queue(struct driver_data *drv_data)
diff --git a/drivers/spi/spi_s3c24xx_gpio.c b/drivers/spi/spi_s3c24xx_gpio.c
index eda53ed04c..611ac22b7c 100644
--- a/drivers/spi/spi_s3c24xx_gpio.c
+++ b/drivers/spi/spi_s3c24xx_gpio.c
@@ -73,6 +73,19 @@ static u32 s3c2410_spigpio_txrx_mode1(struct spi_device *spi,
73 return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits); 73 return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
74} 74}
75 75
76static u32 s3c2410_spigpio_txrx_mode2(struct spi_device *spi,
77 unsigned nsecs, u32 word, u8 bits)
78{
79 return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
80}
81
82static u32 s3c2410_spigpio_txrx_mode3(struct spi_device *spi,
83 unsigned nsecs, u32 word, u8 bits)
84{
85 return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
86}
87
88
76static void s3c2410_spigpio_chipselect(struct spi_device *dev, int value) 89static void s3c2410_spigpio_chipselect(struct spi_device *dev, int value)
77{ 90{
78 struct s3c2410_spigpio *sg = spidev_to_sg(dev); 91 struct s3c2410_spigpio *sg = spidev_to_sg(dev);
@@ -108,6 +121,8 @@ static int s3c2410_spigpio_probe(struct platform_device *dev)
108 121
109 sp->bitbang.txrx_word[SPI_MODE_0] = s3c2410_spigpio_txrx_mode0; 122 sp->bitbang.txrx_word[SPI_MODE_0] = s3c2410_spigpio_txrx_mode0;
110 sp->bitbang.txrx_word[SPI_MODE_1] = s3c2410_spigpio_txrx_mode1; 123 sp->bitbang.txrx_word[SPI_MODE_1] = s3c2410_spigpio_txrx_mode1;
124 sp->bitbang.txrx_word[SPI_MODE_2] = s3c2410_spigpio_txrx_mode2;
125 sp->bitbang.txrx_word[SPI_MODE_3] = s3c2410_spigpio_txrx_mode3;
111 126
112 /* set state of spi pins */ 127 /* set state of spi pins */
113 s3c2410_gpio_setpin(sp->info->pin_clk, 0); 128 s3c2410_gpio_setpin(sp->info->pin_clk, 0);
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 825bf88453..8b7ff467d2 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_USB_SERIAL) += serial/
51obj-$(CONFIG_USB_ADUTUX) += misc/ 51obj-$(CONFIG_USB_ADUTUX) += misc/
52obj-$(CONFIG_USB_APPLEDISPLAY) += misc/ 52obj-$(CONFIG_USB_APPLEDISPLAY) += misc/
53obj-$(CONFIG_USB_AUERSWALD) += misc/ 53obj-$(CONFIG_USB_AUERSWALD) += misc/
54obj-$(CONFIG_USB_BERRY_CHARGE) += misc/
54obj-$(CONFIG_USB_CYPRESS_CY7C63)+= misc/ 55obj-$(CONFIG_USB_CYPRESS_CY7C63)+= misc/
55obj-$(CONFIG_USB_CYTHERM) += misc/ 56obj-$(CONFIG_USB_CYTHERM) += misc/
56obj-$(CONFIG_USB_EMI26) += misc/ 57obj-$(CONFIG_USB_EMI26) += misc/
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index dae4ef1e8f..4973e147bc 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -61,6 +61,7 @@
61#include <linux/usb.h> 61#include <linux/usb.h>
62#include <linux/firmware.h> 62#include <linux/firmware.h>
63#include <linux/ctype.h> 63#include <linux/ctype.h>
64#include <linux/sched.h>
64#include <linux/kthread.h> 65#include <linux/kthread.h>
65#include <linux/version.h> 66#include <linux/version.h>
66#include <linux/mutex.h> 67#include <linux/mutex.h>
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 98199628e3..d38a25f36e 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -326,10 +326,16 @@ static void acm_rx_tasklet(unsigned long _acm)
326 struct tty_struct *tty = acm->tty; 326 struct tty_struct *tty = acm->tty;
327 struct acm_ru *rcv; 327 struct acm_ru *rcv;
328 unsigned long flags; 328 unsigned long flags;
329 int i = 0; 329 unsigned char throttled;
330 dbg("Entering acm_rx_tasklet"); 330 dbg("Entering acm_rx_tasklet");
331 331
332 if (!ACM_READY(acm) || acm->throttle) 332 if (!ACM_READY(acm))
333 return;
334
335 spin_lock(&acm->throttle_lock);
336 throttled = acm->throttle;
337 spin_unlock(&acm->throttle_lock);
338 if (throttled)
333 return; 339 return;
334 340
335next_buffer: 341next_buffer:
@@ -346,22 +352,20 @@ next_buffer:
346 dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size); 352 dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size);
347 353
348 tty_buffer_request_room(tty, buf->size); 354 tty_buffer_request_room(tty, buf->size);
349 if (!acm->throttle) 355 spin_lock(&acm->throttle_lock);
356 throttled = acm->throttle;
357 spin_unlock(&acm->throttle_lock);
358 if (!throttled)
350 tty_insert_flip_string(tty, buf->base, buf->size); 359 tty_insert_flip_string(tty, buf->base, buf->size);
351 tty_flip_buffer_push(tty); 360 tty_flip_buffer_push(tty);
352 361
353 spin_lock(&acm->throttle_lock); 362 if (throttled) {
354 if (acm->throttle) { 363 dbg("Throttling noticed");
355 dbg("Throtteling noticed");
356 memmove(buf->base, buf->base + i, buf->size - i);
357 buf->size -= i;
358 spin_unlock(&acm->throttle_lock);
359 spin_lock_irqsave(&acm->read_lock, flags); 364 spin_lock_irqsave(&acm->read_lock, flags);
360 list_add(&buf->list, &acm->filled_read_bufs); 365 list_add(&buf->list, &acm->filled_read_bufs);
361 spin_unlock_irqrestore(&acm->read_lock, flags); 366 spin_unlock_irqrestore(&acm->read_lock, flags);
362 return; 367 return;
363 } 368 }
364 spin_unlock(&acm->throttle_lock);
365 369
366 spin_lock_irqsave(&acm->read_lock, flags); 370 spin_lock_irqsave(&acm->read_lock, flags);
367 list_add(&buf->list, &acm->spare_read_bufs); 371 list_add(&buf->list, &acm->spare_read_bufs);
@@ -467,7 +471,8 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
467 goto bail_out; 471 goto bail_out;
468 } 472 }
469 473
470 if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS)) 474 if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) &&
475 (acm->ctrl_caps & USB_CDC_CAP_LINE))
471 goto full_bailout; 476 goto full_bailout;
472 477
473 INIT_LIST_HEAD(&acm->spare_read_urbs); 478 INIT_LIST_HEAD(&acm->spare_read_urbs);
@@ -480,6 +485,8 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
480 list_add(&(acm->rb[i].list), &acm->spare_read_bufs); 485 list_add(&(acm->rb[i].list), &acm->spare_read_bufs);
481 } 486 }
482 487
488 acm->throttle = 0;
489
483 tasklet_schedule(&acm->urb_task); 490 tasklet_schedule(&acm->urb_task);
484 491
485done: 492done:
@@ -1092,6 +1099,10 @@ static struct usb_device_id acm_ids[] = {
1092 { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */ 1099 { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */
1093 .driver_info = SINGLE_RX_URB, /* firmware bug */ 1100 .driver_info = SINGLE_RX_URB, /* firmware bug */
1094 }, 1101 },
1102 { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */
1103 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1104 },
1105
1095 /* control interfaces with various AT-command sets */ 1106 /* control interfaces with various AT-command sets */
1096 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, 1107 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1097 USB_CDC_ACM_PROTO_AT_V25TER) }, 1108 USB_CDC_ACM_PROTO_AT_V25TER) },
diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile
index 34e9bac319..b6078706fb 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 generic.o 7 devio.o notify.o generic.o quirks.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/devices.c b/drivers/usb/core/devices.c
index a47c30b2d7..aefc798712 100644
--- a/drivers/usb/core/devices.c
+++ b/drivers/usb/core/devices.c
@@ -604,10 +604,6 @@ static unsigned int usb_device_poll(struct file *file, struct poll_table_struct
604 lock_kernel(); 604 lock_kernel();
605 if (!st) { 605 if (!st) {
606 st = kmalloc(sizeof(struct usb_device_status), GFP_KERNEL); 606 st = kmalloc(sizeof(struct usb_device_status), GFP_KERNEL);
607 if (!st) {
608 unlock_kernel();
609 return POLLIN;
610 }
611 607
612 /* we may have dropped BKL - need to check for having lost the race */ 608 /* we may have dropped BKL - need to check for having lost the race */
613 if (file->private_data) { 609 if (file->private_data) {
@@ -615,6 +611,11 @@ static unsigned int usb_device_poll(struct file *file, struct poll_table_struct
615 st = file->private_data; 611 st = file->private_data;
616 goto lost_race; 612 goto lost_race;
617 } 613 }
614 /* we haven't lost - check for allocation failure now */
615 if (!st) {
616 unlock_kernel();
617 return POLLIN;
618 }
618 619
619 /* 620 /*
620 * need to prevent the module from being unloaded, since 621 * need to prevent the module from being unloaded, since
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 2087766f9e..274f14f163 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -857,11 +857,11 @@ static int proc_setintf(struct dev_state *ps, void __user *arg)
857 857
858static int proc_setconfig(struct dev_state *ps, void __user *arg) 858static int proc_setconfig(struct dev_state *ps, void __user *arg)
859{ 859{
860 unsigned int u; 860 int u;
861 int status = 0; 861 int status = 0;
862 struct usb_host_config *actconfig; 862 struct usb_host_config *actconfig;
863 863
864 if (get_user(u, (unsigned int __user *)arg)) 864 if (get_user(u, (int __user *)arg))
865 return -EFAULT; 865 return -EFAULT;
866 866
867 actconfig = ps->dev->actconfig; 867 actconfig = ps->dev->actconfig;
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 600d1bc827..9e3e943f31 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -366,19 +366,8 @@ void usb_driver_release_interface(struct usb_driver *driver,
366EXPORT_SYMBOL(usb_driver_release_interface); 366EXPORT_SYMBOL(usb_driver_release_interface);
367 367
368/* returns 0 if no match, 1 if match */ 368/* returns 0 if no match, 1 if match */
369int usb_match_one_id(struct usb_interface *interface, 369int usb_match_device(struct usb_device *dev, const struct usb_device_id *id)
370 const struct usb_device_id *id)
371{ 370{
372 struct usb_host_interface *intf;
373 struct usb_device *dev;
374
375 /* proc_connectinfo in devio.c may call us with id == NULL. */
376 if (id == NULL)
377 return 0;
378
379 intf = interface->cur_altsetting;
380 dev = interface_to_usbdev(interface);
381
382 if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) && 371 if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
383 id->idVendor != le16_to_cpu(dev->descriptor.idVendor)) 372 id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
384 return 0; 373 return 0;
@@ -409,6 +398,26 @@ int usb_match_one_id(struct usb_interface *interface,
409 (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol)) 398 (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
410 return 0; 399 return 0;
411 400
401 return 1;
402}
403
404/* returns 0 if no match, 1 if match */
405int usb_match_one_id(struct usb_interface *interface,
406 const struct usb_device_id *id)
407{
408 struct usb_host_interface *intf;
409 struct usb_device *dev;
410
411 /* proc_connectinfo in devio.c may call us with id == NULL. */
412 if (id == NULL)
413 return 0;
414
415 intf = interface->cur_altsetting;
416 dev = interface_to_usbdev(interface);
417
418 if (!usb_match_device(dev, id))
419 return 0;
420
412 /* The interface class, subclass, and protocol should never be 421 /* The interface class, subclass, and protocol should never be
413 * checked for a match if the device class is Vendor Specific, 422 * checked for a match if the device class is Vendor Specific,
414 * unless the match record specifies the Vendor ID. */ 423 * unless the match record specifies the Vendor ID. */
@@ -743,6 +752,7 @@ EXPORT_SYMBOL_GPL(usb_deregister_device_driver);
743 * usb_register_driver - register a USB interface driver 752 * usb_register_driver - register a USB interface driver
744 * @new_driver: USB operations for the interface driver 753 * @new_driver: USB operations for the interface driver
745 * @owner: module owner of this driver. 754 * @owner: module owner of this driver.
755 * @mod_name: module name string
746 * 756 *
747 * Registers a USB interface driver with the USB core. The list of 757 * Registers a USB interface driver with the USB core. The list of
748 * unattached interfaces will be rescanned whenever a new driver is 758 * unattached interfaces will be rescanned whenever a new driver is
@@ -953,12 +963,16 @@ static int autosuspend_check(struct usb_device *udev)
953 int i; 963 int i;
954 struct usb_interface *intf; 964 struct usb_interface *intf;
955 965
956 /* For autosuspend, fail fast if anything is in use. 966 /* For autosuspend, fail fast if anything is in use or autosuspend
957 * Also fail if any interfaces require remote wakeup but it 967 * is disabled. Also fail if any interfaces require remote wakeup
958 * isn't available. */ 968 * but it isn't available.
969 */
959 udev->do_remote_wakeup = device_may_wakeup(&udev->dev); 970 udev->do_remote_wakeup = device_may_wakeup(&udev->dev);
960 if (udev->pm_usage_cnt > 0) 971 if (udev->pm_usage_cnt > 0)
961 return -EBUSY; 972 return -EBUSY;
973 if (!udev->autosuspend_delay)
974 return -EPERM;
975
962 if (udev->actconfig) { 976 if (udev->actconfig) {
963 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { 977 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) {
964 intf = udev->actconfig->interface[i]; 978 intf = udev->actconfig->interface[i];
@@ -981,7 +995,7 @@ static int autosuspend_check(struct usb_device *udev)
981 995
982#define autosuspend_check(udev) 0 996#define autosuspend_check(udev) 0
983 997
984#endif 998#endif /* CONFIG_USB_SUSPEND */
985 999
986/** 1000/**
987 * usb_suspend_both - suspend a USB device and its interfaces 1001 * usb_suspend_both - suspend a USB device and its interfaces
@@ -1176,7 +1190,7 @@ static int usb_autopm_do_device(struct usb_device *udev, int inc_usage_cnt)
1176 udev->pm_usage_cnt -= inc_usage_cnt; 1190 udev->pm_usage_cnt -= inc_usage_cnt;
1177 } else if (inc_usage_cnt <= 0 && autosuspend_check(udev) == 0) 1191 } else if (inc_usage_cnt <= 0 && autosuspend_check(udev) == 0)
1178 queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, 1192 queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend,
1179 USB_AUTOSUSPEND_DELAY); 1193 udev->autosuspend_delay);
1180 usb_pm_unlock(udev); 1194 usb_pm_unlock(udev);
1181 return status; 1195 return status;
1182} 1196}
@@ -1211,6 +1225,26 @@ void usb_autosuspend_device(struct usb_device *udev)
1211} 1225}
1212 1226
1213/** 1227/**
1228 * usb_try_autosuspend_device - attempt an autosuspend of a USB device and its interfaces
1229 * @udev: the usb_device to autosuspend
1230 *
1231 * This routine should be called when a core subsystem thinks @udev may
1232 * be ready to autosuspend.
1233 *
1234 * @udev's usage counter left unchanged. If it or any of the usage counters
1235 * for an active interface is greater than 0, or autosuspend is not allowed
1236 * for any other reason, no autosuspend request will be queued.
1237 *
1238 * This routine can run only in process context.
1239 */
1240void usb_try_autosuspend_device(struct usb_device *udev)
1241{
1242 usb_autopm_do_device(udev, 0);
1243 // dev_dbg(&udev->dev, "%s: cnt %d\n",
1244 // __FUNCTION__, udev->pm_usage_cnt);
1245}
1246
1247/**
1214 * usb_autoresume_device - immediately autoresume a USB device and its interfaces 1248 * usb_autoresume_device - immediately autoresume a USB device and its interfaces
1215 * @udev: the usb_device to autoresume 1249 * @udev: the usb_device to autoresume
1216 * 1250 *
@@ -1260,7 +1294,7 @@ static int usb_autopm_do_interface(struct usb_interface *intf,
1260 intf->pm_usage_cnt -= inc_usage_cnt; 1294 intf->pm_usage_cnt -= inc_usage_cnt;
1261 } else if (inc_usage_cnt <= 0 && autosuspend_check(udev) == 0) 1295 } else if (inc_usage_cnt <= 0 && autosuspend_check(udev) == 0)
1262 queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, 1296 queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend,
1263 USB_AUTOSUSPEND_DELAY); 1297 udev->autosuspend_delay);
1264 } 1298 }
1265 usb_pm_unlock(udev); 1299 usb_pm_unlock(udev);
1266 return status; 1300 return status;
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
index 5e628ae3ae..e0ec7045e8 100644
--- a/drivers/usb/core/endpoint.c
+++ b/drivers/usb/core/endpoint.c
@@ -229,7 +229,7 @@ static int init_endpoint_class(void)
229 kref_init(&ep_class->kref); 229 kref_init(&ep_class->kref);
230 ep_class->class = class_create(THIS_MODULE, "usb_endpoint"); 230 ep_class->class = class_create(THIS_MODULE, "usb_endpoint");
231 if (IS_ERR(ep_class->class)) { 231 if (IS_ERR(ep_class->class)) {
232 result = IS_ERR(ep_class->class); 232 result = PTR_ERR(ep_class->class);
233 goto class_create_error; 233 goto class_create_error;
234 } 234 }
235 235
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c
index b531a4fd30..9bbcb20e2d 100644
--- a/drivers/usb/core/generic.c
+++ b/drivers/usb/core/generic.c
@@ -184,7 +184,7 @@ static void generic_disconnect(struct usb_device *udev)
184 /* if this is only an unbind, not a physical disconnect, then 184 /* if this is only an unbind, not a physical disconnect, then
185 * unconfigure the device */ 185 * unconfigure the device */
186 if (udev->actconfig) 186 if (udev->actconfig)
187 usb_set_configuration(udev, 0); 187 usb_set_configuration(udev, -1);
188 188
189 usb_remove_sysfs_dev_files(udev); 189 usb_remove_sysfs_dev_files(udev);
190} 190}
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 590ec82d05..41400743ce 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -44,6 +44,7 @@ struct usb_hub {
44 struct usb_hub_status hub; 44 struct usb_hub_status hub;
45 struct usb_port_status port; 45 struct usb_port_status port;
46 } *status; /* buffer for status reports */ 46 } *status; /* buffer for status reports */
47 struct mutex status_mutex; /* for the status buffer */
47 48
48 int error; /* last reported error */ 49 int error; /* last reported error */
49 int nerrors; /* track consecutive errors */ 50 int nerrors; /* track consecutive errors */
@@ -535,6 +536,7 @@ static int hub_hub_status(struct usb_hub *hub,
535{ 536{
536 int ret; 537 int ret;
537 538
539 mutex_lock(&hub->status_mutex);
538 ret = get_hub_status(hub->hdev, &hub->status->hub); 540 ret = get_hub_status(hub->hdev, &hub->status->hub);
539 if (ret < 0) 541 if (ret < 0)
540 dev_err (hub->intfdev, 542 dev_err (hub->intfdev,
@@ -544,6 +546,7 @@ static int hub_hub_status(struct usb_hub *hub,
544 *change = le16_to_cpu(hub->status->hub.wHubChange); 546 *change = le16_to_cpu(hub->status->hub.wHubChange);
545 ret = 0; 547 ret = 0;
546 } 548 }
549 mutex_unlock(&hub->status_mutex);
547 return ret; 550 return ret;
548} 551}
549 552
@@ -617,6 +620,7 @@ static int hub_configure(struct usb_hub *hub,
617 ret = -ENOMEM; 620 ret = -ENOMEM;
618 goto fail; 621 goto fail;
619 } 622 }
623 mutex_init(&hub->status_mutex);
620 624
621 hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL); 625 hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL);
622 if (!hub->descriptor) { 626 if (!hub->descriptor) {
@@ -1283,6 +1287,9 @@ int usb_new_device(struct usb_device *udev)
1283 if (!try_module_get(THIS_MODULE)) 1287 if (!try_module_get(THIS_MODULE))
1284 return -EINVAL; 1288 return -EINVAL;
1285 1289
1290 /* Determine quirks */
1291 usb_detect_quirks(udev);
1292
1286 err = usb_get_configuration(udev); 1293 err = usb_get_configuration(udev);
1287 if (err < 0) { 1294 if (err < 0) {
1288 dev_err(&udev->dev, "can't read configurations, error %d\n", 1295 dev_err(&udev->dev, "can't read configurations, error %d\n",
@@ -1396,6 +1403,7 @@ static int hub_port_status(struct usb_hub *hub, int port1,
1396{ 1403{
1397 int ret; 1404 int ret;
1398 1405
1406 mutex_lock(&hub->status_mutex);
1399 ret = get_port_status(hub->hdev, port1, &hub->status->port); 1407 ret = get_port_status(hub->hdev, port1, &hub->status->port);
1400 if (ret < 4) { 1408 if (ret < 4) {
1401 dev_err (hub->intfdev, 1409 dev_err (hub->intfdev,
@@ -1407,6 +1415,7 @@ static int hub_port_status(struct usb_hub *hub, int port1,
1407 *change = le16_to_cpu(hub->status->port.wPortChange); 1415 *change = le16_to_cpu(hub->status->port.wPortChange);
1408 ret = 0; 1416 ret = 0;
1409 } 1417 }
1418 mutex_unlock(&hub->status_mutex);
1410 return ret; 1419 return ret;
1411} 1420}
1412 1421
@@ -1904,6 +1913,7 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg)
1904 struct usb_hub *hub = usb_get_intfdata (intf); 1913 struct usb_hub *hub = usb_get_intfdata (intf);
1905 struct usb_device *hdev = hub->hdev; 1914 struct usb_device *hdev = hub->hdev;
1906 unsigned port1; 1915 unsigned port1;
1916 int status = 0;
1907 1917
1908 /* fail if children aren't already suspended */ 1918 /* fail if children aren't already suspended */
1909 for (port1 = 1; port1 <= hdev->maxchild; port1++) { 1919 for (port1 = 1; port1 <= hdev->maxchild; port1++) {
@@ -1927,24 +1937,18 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg)
1927 1937
1928 dev_dbg(&intf->dev, "%s\n", __FUNCTION__); 1938 dev_dbg(&intf->dev, "%s\n", __FUNCTION__);
1929 1939
1940 /* stop khubd and related activity */
1941 hub_quiesce(hub);
1942
1930 /* "global suspend" of the downstream HC-to-USB interface */ 1943 /* "global suspend" of the downstream HC-to-USB interface */
1931 if (!hdev->parent) { 1944 if (!hdev->parent) {
1932 struct usb_bus *bus = hdev->bus; 1945 status = hcd_bus_suspend(hdev->bus);
1933 if (bus) { 1946 if (status != 0) {
1934 int status = hcd_bus_suspend (bus); 1947 dev_dbg(&hdev->dev, "'global' suspend %d\n", status);
1935 1948 hub_activate(hub);
1936 if (status != 0) { 1949 }
1937 dev_dbg(&hdev->dev, "'global' suspend %d\n",
1938 status);
1939 return status;
1940 }
1941 } else
1942 return -EOPNOTSUPP;
1943 } 1950 }
1944 1951 return status;
1945 /* stop khubd and related activity */
1946 hub_quiesce(hub);
1947 return 0;
1948} 1952}
1949 1953
1950static int hub_resume(struct usb_interface *intf) 1954static int hub_resume(struct usb_interface *intf)
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 8aca3574c2..2f17468b5c 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -11,6 +11,7 @@
11#include <linux/timer.h> 11#include <linux/timer.h>
12#include <linux/ctype.h> 12#include <linux/ctype.h>
13#include <linux/device.h> 13#include <linux/device.h>
14#include <linux/usb/quirks.h>
14#include <asm/byteorder.h> 15#include <asm/byteorder.h>
15#include <asm/scatterlist.h> 16#include <asm/scatterlist.h>
16 17
@@ -685,7 +686,10 @@ static int usb_string_sub(struct usb_device *dev, unsigned int langid,
685 686
686 /* Try to read the string descriptor by asking for the maximum 687 /* Try to read the string descriptor by asking for the maximum
687 * possible number of bytes */ 688 * possible number of bytes */
688 rc = usb_get_string(dev, langid, index, buf, 255); 689 if (dev->quirks & USB_QUIRK_STRING_FETCH_255)
690 rc = -EIO;
691 else
692 rc = usb_get_string(dev, langid, index, buf, 255);
689 693
690 /* If that failed try to read the descriptor length, then 694 /* If that failed try to read the descriptor length, then
691 * ask for just that many bytes */ 695 * ask for just that many bytes */
@@ -1316,6 +1320,14 @@ static void release_interface(struct device *dev)
1316 * use this kind of configurability; many devices only have one 1320 * use this kind of configurability; many devices only have one
1317 * configuration. 1321 * configuration.
1318 * 1322 *
1323 * @configuration is the value of the configuration to be installed.
1324 * According to the USB spec (e.g. section 9.1.1.5), configuration values
1325 * must be non-zero; a value of zero indicates that the device in
1326 * unconfigured. However some devices erroneously use 0 as one of their
1327 * configuration values. To help manage such devices, this routine will
1328 * accept @configuration = -1 as indicating the device should be put in
1329 * an unconfigured state.
1330 *
1319 * USB device configurations may affect Linux interoperability, 1331 * USB device configurations may affect Linux interoperability,
1320 * power consumption and the functionality available. For example, 1332 * power consumption and the functionality available. For example,
1321 * the default configuration is limited to using 100mA of bus power, 1333 * the default configuration is limited to using 100mA of bus power,
@@ -1347,10 +1359,15 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
1347 struct usb_interface **new_interfaces = NULL; 1359 struct usb_interface **new_interfaces = NULL;
1348 int n, nintf; 1360 int n, nintf;
1349 1361
1350 for (i = 0; i < dev->descriptor.bNumConfigurations; i++) { 1362 if (configuration == -1)
1351 if (dev->config[i].desc.bConfigurationValue == configuration) { 1363 configuration = 0;
1352 cp = &dev->config[i]; 1364 else {
1353 break; 1365 for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {
1366 if (dev->config[i].desc.bConfigurationValue ==
1367 configuration) {
1368 cp = &dev->config[i];
1369 break;
1370 }
1354 } 1371 }
1355 } 1372 }
1356 if ((!cp && configuration != 0)) 1373 if ((!cp && configuration != 0))
@@ -1359,6 +1376,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
1359 /* The USB spec says configuration 0 means unconfigured. 1376 /* The USB spec says configuration 0 means unconfigured.
1360 * But if a device includes a configuration numbered 0, 1377 * But if a device includes a configuration numbered 0,
1361 * we will accept it as a correctly configured state. 1378 * we will accept it as a correctly configured state.
1379 * Use -1 if you really want to unconfigure the device.
1362 */ 1380 */
1363 if (cp && configuration == 0) 1381 if (cp && configuration == 0)
1364 dev_warn(&dev->dev, "config 0 descriptor??\n"); 1382 dev_warn(&dev->dev, "config 0 descriptor??\n");
diff --git a/drivers/usb/core/otg_whitelist.h b/drivers/usb/core/otg_whitelist.h
index 627a5a2fc9..7f31a495a2 100644
--- a/drivers/usb/core/otg_whitelist.h
+++ b/drivers/usb/core/otg_whitelist.h
@@ -31,7 +31,7 @@ static struct usb_device_id whitelist_table [] = {
31{ USB_DEVICE_INFO(7, 1, 3) }, 31{ USB_DEVICE_INFO(7, 1, 3) },
32#endif 32#endif
33 33
34#ifdef CONFIG_USB_CDCETHER 34#ifdef CONFIG_USB_NET_CDCETHER
35/* Linux-USB CDC Ethernet gadget */ 35/* Linux-USB CDC Ethernet gadget */
36{ USB_DEVICE(0x0525, 0xa4a1), }, 36{ USB_DEVICE(0x0525, 0xa4a1), },
37/* Linux-USB CDC Ethernet + RNDIS gadget */ 37/* Linux-USB CDC Ethernet + RNDIS gadget */
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
new file mode 100644
index 0000000000..0e5c646cb4
--- /dev/null
+++ b/drivers/usb/core/quirks.c
@@ -0,0 +1,77 @@
1/*
2 * USB device quirk handling logic and table
3 *
4 * Copyright (c) 2007 Oliver Neukum
5 * Copyright (c) 2007 Greg Kroah-Hartman <gregkh@suse.de>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation, version 2.
10 *
11 *
12 */
13
14#include <linux/usb.h>
15#include <linux/usb/quirks.h>
16#include "usb.h"
17
18/* List of quirky USB devices. Please keep this list ordered by:
19 * 1) Vendor ID
20 * 2) Product ID
21 * 3) Class ID
22 *
23 * as we want specific devices to be overridden first, and only after that, any
24 * class specific quirks.
25 *
26 * Right now the logic aborts if it finds a valid device in the table, we might
27 * want to change that in the future if it turns out that a whole class of
28 * devices is broken...
29 */
30static const struct usb_device_id usb_quirk_list[] = {
31 /* HP 5300/5370C scanner */
32 { USB_DEVICE(0x03f0, 0x0701), .driver_info = USB_QUIRK_STRING_FETCH_255 },
33
34 /* Elsa MicroLink 56k (V.250) */
35 { USB_DEVICE(0x05cc, 0x2267), .driver_info = USB_QUIRK_NO_AUTOSUSPEND },
36
37 { } /* terminating entry must be last */
38};
39
40static void usb_autosuspend_quirk(struct usb_device *udev)
41{
42#ifdef CONFIG_USB_SUSPEND
43 /* disable autosuspend, but allow the user to re-enable it via sysfs */
44 udev->autosuspend_delay = 0;
45#endif
46}
47
48static const struct usb_device_id *find_id(struct usb_device *udev)
49{
50 const struct usb_device_id *id = usb_quirk_list;
51
52 for (; id->idVendor || id->bDeviceClass || id->bInterfaceClass ||
53 id->driver_info; id++) {
54 if (usb_match_device(udev, id))
55 return id;
56 }
57 return NULL;
58}
59
60/*
61 * Detect any quirks the device has, and do any housekeeping for it if needed.
62 */
63void usb_detect_quirks(struct usb_device *udev)
64{
65 const struct usb_device_id *id = usb_quirk_list;
66
67 id = find_id(udev);
68 if (id)
69 udev->quirks = (u32)(id->driver_info);
70 if (udev->quirks)
71 dev_dbg(&udev->dev, "USB quirks for this device: %x\n",
72 udev->quirks);
73
74 /* do any special quirk handling here if needed */
75 if (udev->quirks & USB_QUIRK_NO_AUTOSUSPEND)
76 usb_autosuspend_quirk(udev);
77}
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 4eaa0ee8e7..311d5df803 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -63,7 +63,7 @@ set_bConfigurationValue(struct device *dev, struct device_attribute *attr,
63 struct usb_device *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, "%d", &config) != 1 || config < -1 || config > 255)
67 return -EINVAL; 67 return -EINVAL;
68 usb_lock_device(udev); 68 usb_lock_device(udev);
69 value = usb_set_configuration(udev, config); 69 value = usb_set_configuration(udev, config);
@@ -148,6 +148,75 @@ show_maxchild(struct device *dev, struct device_attribute *attr, char *buf)
148} 148}
149static DEVICE_ATTR(maxchild, S_IRUGO, show_maxchild, NULL); 149static DEVICE_ATTR(maxchild, S_IRUGO, show_maxchild, NULL);
150 150
151static ssize_t
152show_quirks(struct device *dev, struct device_attribute *attr, char *buf)
153{
154 struct usb_device *udev;
155
156 udev = to_usb_device(dev);
157 return sprintf(buf, "0x%x\n", udev->quirks);
158}
159static DEVICE_ATTR(quirks, S_IRUGO, show_quirks, NULL);
160
161#ifdef CONFIG_USB_SUSPEND
162
163static ssize_t
164show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf)
165{
166 struct usb_device *udev = to_usb_device(dev);
167
168 return sprintf(buf, "%u\n", udev->autosuspend_delay / HZ);
169}
170
171static ssize_t
172set_autosuspend(struct device *dev, struct device_attribute *attr,
173 const char *buf, size_t count)
174{
175 struct usb_device *udev = to_usb_device(dev);
176 unsigned value, old;
177
178 if (sscanf(buf, "%u", &value) != 1 || value >= INT_MAX/HZ)
179 return -EINVAL;
180 value *= HZ;
181
182 old = udev->autosuspend_delay;
183 udev->autosuspend_delay = value;
184 if (value > 0 && old == 0)
185 usb_try_autosuspend_device(udev);
186
187 return count;
188}
189
190static DEVICE_ATTR(autosuspend, S_IRUGO | S_IWUSR,
191 show_autosuspend, set_autosuspend);
192
193static char power_group[] = "power";
194
195static int add_power_attributes(struct device *dev)
196{
197 int rc = 0;
198
199 if (is_usb_device(dev))
200 rc = sysfs_add_file_to_group(&dev->kobj,
201 &dev_attr_autosuspend.attr,
202 power_group);
203 return rc;
204}
205
206static void remove_power_attributes(struct device *dev)
207{
208 sysfs_remove_file_from_group(&dev->kobj,
209 &dev_attr_autosuspend.attr,
210 power_group);
211}
212
213#else
214
215#define add_power_attributes(dev) 0
216#define remove_power_attributes(dev) do {} while (0)
217
218#endif /* CONFIG_USB_SUSPEND */
219
151/* Descriptor fields */ 220/* Descriptor fields */
152#define usb_descriptor_attr_le16(field, format_string) \ 221#define usb_descriptor_attr_le16(field, format_string) \
153static ssize_t \ 222static ssize_t \
@@ -204,6 +273,7 @@ static struct attribute *dev_attrs[] = {
204 &dev_attr_devnum.attr, 273 &dev_attr_devnum.attr,
205 &dev_attr_version.attr, 274 &dev_attr_version.attr,
206 &dev_attr_maxchild.attr, 275 &dev_attr_maxchild.attr,
276 &dev_attr_quirks.attr,
207 NULL, 277 NULL,
208}; 278};
209static struct attribute_group dev_attr_grp = { 279static struct attribute_group dev_attr_grp = {
@@ -219,6 +289,10 @@ int usb_create_sysfs_dev_files(struct usb_device *udev)
219 if (retval) 289 if (retval)
220 return retval; 290 return retval;
221 291
292 retval = add_power_attributes(dev);
293 if (retval)
294 goto error;
295
222 if (udev->manufacturer) { 296 if (udev->manufacturer) {
223 retval = device_create_file(dev, &dev_attr_manufacturer); 297 retval = device_create_file(dev, &dev_attr_manufacturer);
224 if (retval) 298 if (retval)
@@ -239,10 +313,7 @@ int usb_create_sysfs_dev_files(struct usb_device *udev)
239 goto error; 313 goto error;
240 return 0; 314 return 0;
241error: 315error:
242 usb_remove_ep_files(&udev->ep0); 316 usb_remove_sysfs_dev_files(udev);
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; 317 return retval;
247} 318}
248 319
@@ -251,14 +322,11 @@ void usb_remove_sysfs_dev_files(struct usb_device *udev)
251 struct device *dev = &udev->dev; 322 struct device *dev = &udev->dev;
252 323
253 usb_remove_ep_files(&udev->ep0); 324 usb_remove_ep_files(&udev->ep0);
325 device_remove_file(dev, &dev_attr_manufacturer);
326 device_remove_file(dev, &dev_attr_product);
327 device_remove_file(dev, &dev_attr_serial);
328 remove_power_attributes(dev);
254 sysfs_remove_group(&dev->kobj, &dev_attr_grp); 329 sysfs_remove_group(&dev->kobj, &dev_attr_grp);
255
256 if (udev->manufacturer)
257 device_remove_file(dev, &dev_attr_manufacturer);
258 if (udev->product)
259 device_remove_file(dev, &dev_attr_product);
260 if (udev->serial)
261 device_remove_file(dev, &dev_attr_serial);
262} 330}
263 331
264/* Interface fields */ 332/* Interface fields */
@@ -362,33 +430,28 @@ static inline void usb_remove_intf_ep_files(struct usb_interface *intf)
362 430
363int usb_create_sysfs_intf_files(struct usb_interface *intf) 431int usb_create_sysfs_intf_files(struct usb_interface *intf)
364{ 432{
433 struct device *dev = &intf->dev;
365 struct usb_device *udev = interface_to_usbdev(intf); 434 struct usb_device *udev = interface_to_usbdev(intf);
366 struct usb_host_interface *alt = intf->cur_altsetting; 435 struct usb_host_interface *alt = intf->cur_altsetting;
367 int retval; 436 int retval;
368 437
369 retval = sysfs_create_group(&intf->dev.kobj, &intf_attr_grp); 438 retval = sysfs_create_group(&dev->kobj, &intf_attr_grp);
370 if (retval) 439 if (retval)
371 goto error; 440 return retval;
372 441
373 if (alt->string == NULL) 442 if (alt->string == NULL)
374 alt->string = usb_cache_string(udev, alt->desc.iInterface); 443 alt->string = usb_cache_string(udev, alt->desc.iInterface);
375 if (alt->string) 444 if (alt->string)
376 retval = device_create_file(&intf->dev, &dev_attr_interface); 445 retval = device_create_file(dev, &dev_attr_interface);
377 usb_create_intf_ep_files(intf, udev); 446 usb_create_intf_ep_files(intf, udev);
378 return 0; 447 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;
385} 448}
386 449
387void usb_remove_sysfs_intf_files(struct usb_interface *intf) 450void usb_remove_sysfs_intf_files(struct usb_interface *intf)
388{ 451{
389 usb_remove_intf_ep_files(intf); 452 struct device *dev = &intf->dev;
390 sysfs_remove_group(&intf->dev.kobj, &intf_attr_grp);
391 453
392 if (intf->cur_altsetting->string) 454 usb_remove_intf_ep_files(intf);
393 device_remove_file(&intf->dev, &dev_attr_interface); 455 device_remove_file(dev, &dev_attr_interface);
456 sysfs_remove_group(&dev->kobj, &intf_attr_grp);
394} 457}
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 3db721cd55..54b42ce311 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/moduleparam.h>
25#include <linux/string.h> 26#include <linux/string.h>
26#include <linux/bitops.h> 27#include <linux/bitops.h>
27#include <linux/slab.h> 28#include <linux/slab.h>
@@ -50,6 +51,16 @@ static int nousb; /* Disable USB when built into kernel image */
50 51
51struct workqueue_struct *ksuspend_usb_wq; /* For autosuspend */ 52struct workqueue_struct *ksuspend_usb_wq; /* For autosuspend */
52 53
54#ifdef CONFIG_USB_SUSPEND
55static int usb_autosuspend_delay = 2; /* Default delay value,
56 * in seconds */
57module_param_named(autosuspend, usb_autosuspend_delay, uint, 0644);
58MODULE_PARM_DESC(autosuspend, "default autosuspend delay");
59
60#else
61#define usb_autosuspend_delay 0
62#endif
63
53 64
54/** 65/**
55 * usb_ifnum_to_if - get the interface object with a given interface number 66 * usb_ifnum_to_if - get the interface object with a given interface number
@@ -306,6 +317,7 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1)
306#ifdef CONFIG_PM 317#ifdef CONFIG_PM
307 mutex_init(&dev->pm_mutex); 318 mutex_init(&dev->pm_mutex);
308 INIT_DELAYED_WORK(&dev->autosuspend, usb_autosuspend_work); 319 INIT_DELAYED_WORK(&dev->autosuspend, usb_autosuspend_work);
320 dev->autosuspend_delay = usb_autosuspend_delay * HZ;
309#endif 321#endif
310 return dev; 322 return dev;
311} 323}
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 17830a81be..08b5a04e37 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -13,6 +13,7 @@ extern void usb_disable_interface (struct usb_device *dev,
13 struct usb_interface *intf); 13 struct usb_interface *intf);
14extern void usb_release_interface_cache(struct kref *ref); 14extern void usb_release_interface_cache(struct kref *ref);
15extern void usb_disable_device (struct usb_device *dev, int skip_ep0); 15extern void usb_disable_device (struct usb_device *dev, int skip_ep0);
16extern void usb_detect_quirks(struct usb_device *udev);
16 17
17extern int usb_get_device_descriptor(struct usb_device *dev, 18extern int usb_get_device_descriptor(struct usb_device *dev,
18 unsigned int size); 19 unsigned int size);
@@ -21,6 +22,8 @@ extern int usb_set_configuration(struct usb_device *dev, int configuration);
21 22
22extern void usb_kick_khubd(struct usb_device *dev); 23extern void usb_kick_khubd(struct usb_device *dev);
23extern void usb_resume_root_hub(struct usb_device *dev); 24extern void usb_resume_root_hub(struct usb_device *dev);
25extern int usb_match_device(struct usb_device *dev,
26 const struct usb_device_id *id);
24 27
25extern int usb_hub_init(void); 28extern int usb_hub_init(void);
26extern void usb_hub_cleanup(void); 29extern void usb_hub_cleanup(void);
@@ -62,14 +65,14 @@ static inline void usb_pm_unlock(struct usb_device *udev) {}
62 65
63#ifdef CONFIG_USB_SUSPEND 66#ifdef CONFIG_USB_SUSPEND
64 67
65#define USB_AUTOSUSPEND_DELAY (HZ*2)
66
67extern void usb_autosuspend_device(struct usb_device *udev); 68extern void usb_autosuspend_device(struct usb_device *udev);
69extern void usb_try_autosuspend_device(struct usb_device *udev);
68extern int usb_autoresume_device(struct usb_device *udev); 70extern int usb_autoresume_device(struct usb_device *udev);
69 71
70#else 72#else
71 73
72#define usb_autosuspend_device(udev) do {} while (0) 74#define usb_autosuspend_device(udev) do {} while (0)
75#define usb_try_autosuspend_device(udev) do {} while (0)
73static inline int usb_autoresume_device(struct usb_device *udev) 76static inline int usb_autoresume_device(struct usb_device *udev)
74{ 77{
75 return 0; 78 return 0;
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 36b36e0175..a4677802fb 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -784,7 +784,7 @@ static int at91_ep_set_halt(struct usb_ep *_ep, int value)
784 return status; 784 return status;
785} 785}
786 786
787static struct usb_ep_ops at91_ep_ops = { 787static const struct usb_ep_ops at91_ep_ops = {
788 .enable = at91_ep_enable, 788 .enable = at91_ep_enable,
789 .disable = at91_ep_disable, 789 .disable = at91_ep_disable,
790 .alloc_request = at91_ep_alloc_request, 790 .alloc_request = at91_ep_alloc_request,
@@ -912,7 +912,7 @@ static void pullup(struct at91_udc *udc, int is_on)
912 at91_udp_write(udc, AT91_UDP_TXVC, 0); 912 at91_udp_write(udc, AT91_UDP_TXVC, 0);
913 if (cpu_is_at91rm9200()) 913 if (cpu_is_at91rm9200())
914 at91_set_gpio_value(udc->board.pullup_pin, 1); 914 at91_set_gpio_value(udc->board.pullup_pin, 1);
915 else if (cpu_is_at91sam9260()) { 915 else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) {
916 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC); 916 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC);
917 917
918 txvc |= AT91_UDP_TXVC_PUON; 918 txvc |= AT91_UDP_TXVC_PUON;
@@ -929,7 +929,7 @@ static void pullup(struct at91_udc *udc, int is_on)
929 at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); 929 at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
930 if (cpu_is_at91rm9200()) 930 if (cpu_is_at91rm9200())
931 at91_set_gpio_value(udc->board.pullup_pin, 0); 931 at91_set_gpio_value(udc->board.pullup_pin, 0);
932 else if (cpu_is_at91sam9260()) { 932 else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) {
933 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC); 933 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC);
934 934
935 txvc &= ~AT91_UDP_TXVC_PUON; 935 txvc &= ~AT91_UDP_TXVC_PUON;
@@ -1651,7 +1651,7 @@ static void at91udc_shutdown(struct platform_device *dev)
1651 pullup(platform_get_drvdata(dev), 0); 1651 pullup(platform_get_drvdata(dev), 0);
1652} 1652}
1653 1653
1654static int __devinit at91udc_probe(struct platform_device *pdev) 1654static int __init at91udc_probe(struct platform_device *pdev)
1655{ 1655{
1656 struct device *dev = &pdev->dev; 1656 struct device *dev = &pdev->dev;
1657 struct at91_udc *udc; 1657 struct at91_udc *udc;
@@ -1762,7 +1762,7 @@ fail0:
1762 return retval; 1762 return retval;
1763} 1763}
1764 1764
1765static int __devexit at91udc_remove(struct platform_device *pdev) 1765static int __exit at91udc_remove(struct platform_device *pdev)
1766{ 1766{
1767 struct at91_udc *udc = platform_get_drvdata(pdev); 1767 struct at91_udc *udc = platform_get_drvdata(pdev);
1768 struct resource *res; 1768 struct resource *res;
@@ -1836,8 +1836,7 @@ static int at91udc_resume(struct platform_device *pdev)
1836#endif 1836#endif
1837 1837
1838static struct platform_driver at91_udc = { 1838static struct platform_driver at91_udc = {
1839 .probe = at91udc_probe, 1839 .remove = __exit_p(at91udc_remove),
1840 .remove = __devexit_p(at91udc_remove),
1841 .shutdown = at91udc_shutdown, 1840 .shutdown = at91udc_shutdown,
1842 .suspend = at91udc_suspend, 1841 .suspend = at91udc_suspend,
1843 .resume = at91udc_resume, 1842 .resume = at91udc_resume,
@@ -1847,13 +1846,13 @@ static struct platform_driver at91_udc = {
1847 }, 1846 },
1848}; 1847};
1849 1848
1850static int __devinit udc_init_module(void) 1849static int __init udc_init_module(void)
1851{ 1850{
1852 return platform_driver_register(&at91_udc); 1851 return platform_driver_probe(&at91_udc, at91udc_probe);
1853} 1852}
1854module_init(udc_init_module); 1853module_init(udc_init_module);
1855 1854
1856static void __devexit udc_exit_module(void) 1855static void __exit udc_exit_module(void)
1857{ 1856{
1858 platform_driver_unregister(&at91_udc); 1857 platform_driver_unregister(&at91_udc);
1859} 1858}
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 34296e79ed..188c74a952 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -553,6 +553,7 @@ static ssize_t ep_aio_read_retry(struct kiocb *iocb)
553{ 553{
554 struct kiocb_priv *priv = iocb->private; 554 struct kiocb_priv *priv = iocb->private;
555 ssize_t len, total; 555 ssize_t len, total;
556 void *to_copy;
556 int i; 557 int i;
557 558
558 /* we "retry" to get the right mm context for this: */ 559 /* we "retry" to get the right mm context for this: */
@@ -560,10 +561,11 @@ static ssize_t ep_aio_read_retry(struct kiocb *iocb)
560 /* copy stuff into user buffers */ 561 /* copy stuff into user buffers */
561 total = priv->actual; 562 total = priv->actual;
562 len = 0; 563 len = 0;
564 to_copy = priv->buf;
563 for (i=0; i < priv->nr_segs; i++) { 565 for (i=0; i < priv->nr_segs; i++) {
564 ssize_t this = min((ssize_t)(priv->iv[i].iov_len), total); 566 ssize_t this = min((ssize_t)(priv->iv[i].iov_len), total);
565 567
566 if (copy_to_user(priv->iv[i].iov_base, priv->buf, this)) { 568 if (copy_to_user(priv->iv[i].iov_base, to_copy, this)) {
567 if (len == 0) 569 if (len == 0)
568 len = -EFAULT; 570 len = -EFAULT;
569 break; 571 break;
@@ -571,6 +573,7 @@ static ssize_t ep_aio_read_retry(struct kiocb *iocb)
571 573
572 total -= this; 574 total -= this;
573 len += this; 575 len += this;
576 to_copy += this;
574 if (total == 0) 577 if (total == 0)
575 break; 578 break;
576 } 579 }
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
index 27904a5649..f01890dc87 100644
--- a/drivers/usb/gadget/pxa2xx_udc.c
+++ b/drivers/usb/gadget/pxa2xx_udc.c
@@ -155,7 +155,7 @@ static int is_vbus_present(void)
155 struct pxa2xx_udc_mach_info *mach = the_controller->mach; 155 struct pxa2xx_udc_mach_info *mach = the_controller->mach;
156 156
157 if (mach->gpio_vbus) 157 if (mach->gpio_vbus)
158 return pxa_gpio_get(mach->gpio_vbus); 158 return udc_gpio_get(mach->gpio_vbus);
159 if (mach->udc_is_connected) 159 if (mach->udc_is_connected)
160 return mach->udc_is_connected(); 160 return mach->udc_is_connected();
161 return 1; 161 return 1;
@@ -167,7 +167,7 @@ static void pullup_off(void)
167 struct pxa2xx_udc_mach_info *mach = the_controller->mach; 167 struct pxa2xx_udc_mach_info *mach = the_controller->mach;
168 168
169 if (mach->gpio_pullup) 169 if (mach->gpio_pullup)
170 pxa_gpio_set(mach->gpio_pullup, 0); 170 udc_gpio_set(mach->gpio_pullup, 0);
171 else if (mach->udc_command) 171 else if (mach->udc_command)
172 mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT); 172 mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
173} 173}
@@ -177,7 +177,7 @@ static void pullup_on(void)
177 struct pxa2xx_udc_mach_info *mach = the_controller->mach; 177 struct pxa2xx_udc_mach_info *mach = the_controller->mach;
178 178
179 if (mach->gpio_pullup) 179 if (mach->gpio_pullup)
180 pxa_gpio_set(mach->gpio_pullup, 1); 180 udc_gpio_set(mach->gpio_pullup, 1);
181 else if (mach->udc_command) 181 else if (mach->udc_command)
182 mach->udc_command(PXA2XX_UDC_CMD_CONNECT); 182 mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
183} 183}
@@ -1755,7 +1755,7 @@ lubbock_vbus_irq(int irq, void *_dev)
1755static irqreturn_t udc_vbus_irq(int irq, void *_dev) 1755static irqreturn_t udc_vbus_irq(int irq, void *_dev)
1756{ 1756{
1757 struct pxa2xx_udc *dev = _dev; 1757 struct pxa2xx_udc *dev = _dev;
1758 int vbus = pxa_gpio_get(dev->mach->gpio_vbus); 1758 int vbus = udc_gpio_get(dev->mach->gpio_vbus);
1759 1759
1760 pxa2xx_udc_vbus_session(&dev->gadget, vbus); 1760 pxa2xx_udc_vbus_session(&dev->gadget, vbus);
1761 return IRQ_HANDLED; 1761 return IRQ_HANDLED;
@@ -2545,15 +2545,13 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
2545 dev->dev = &pdev->dev; 2545 dev->dev = &pdev->dev;
2546 dev->mach = pdev->dev.platform_data; 2546 dev->mach = pdev->dev.platform_data;
2547 if (dev->mach->gpio_vbus) { 2547 if (dev->mach->gpio_vbus) {
2548 vbus_irq = IRQ_GPIO(dev->mach->gpio_vbus & GPIO_MD_MASK_NR); 2548 udc_gpio_init_vbus(dev->mach->gpio_vbus);
2549 pxa_gpio_mode((dev->mach->gpio_vbus & GPIO_MD_MASK_NR) 2549 vbus_irq = udc_gpio_to_irq(dev->mach->gpio_vbus);
2550 | GPIO_IN);
2551 set_irq_type(vbus_irq, IRQT_BOTHEDGE); 2550 set_irq_type(vbus_irq, IRQT_BOTHEDGE);
2552 } else 2551 } else
2553 vbus_irq = 0; 2552 vbus_irq = 0;
2554 if (dev->mach->gpio_pullup) 2553 if (dev->mach->gpio_pullup)
2555 pxa_gpio_mode((dev->mach->gpio_pullup & GPIO_MD_MASK_NR) 2554 udc_gpio_init_pullup(dev->mach->gpio_pullup);
2556 | GPIO_OUT | GPIO_DFLT_LOW);
2557 2555
2558 init_timer(&dev->timer); 2556 init_timer(&dev->timer);
2559 dev->timer.function = udc_watchdog; 2557 dev->timer.function = udc_watchdog;
diff --git a/drivers/usb/gadget/pxa2xx_udc.h b/drivers/usb/gadget/pxa2xx_udc.h
index 8e598c8bf4..773e549aff 100644
--- a/drivers/usb/gadget/pxa2xx_udc.h
+++ b/drivers/usb/gadget/pxa2xx_udc.h
@@ -177,21 +177,6 @@ struct pxa2xx_udc {
177 177
178static struct pxa2xx_udc *the_controller; 178static struct pxa2xx_udc *the_controller;
179 179
180static inline int pxa_gpio_get(unsigned gpio)
181{
182 return (GPLR(gpio) & GPIO_bit(gpio)) != 0;
183}
184
185static inline void pxa_gpio_set(unsigned gpio, int is_on)
186{
187 int mask = GPIO_bit(gpio);
188
189 if (is_on)
190 GPSR(gpio) = mask;
191 else
192 GPCR(gpio) = mask;
193}
194
195/*-------------------------------------------------------------------------*/ 180/*-------------------------------------------------------------------------*/
196 181
197/* 182/*
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index e6c19aa4be..e552668d36 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -1699,6 +1699,7 @@ static int gs_setup_class(struct usb_gadget *gadget,
1699 memcpy(&port->port_line_coding, req->buf, ret); 1699 memcpy(&port->port_line_coding, req->buf, ret);
1700 spin_unlock(&port->port_lock); 1700 spin_unlock(&port->port_lock);
1701 } 1701 }
1702 ret = 0;
1702 break; 1703 break;
1703 1704
1704 case USB_CDC_REQ_GET_LINE_CODING: 1705 case USB_CDC_REQ_GET_LINE_CODING:
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 246afea9e8..43eddaecc3 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -322,7 +322,7 @@ static inline void remove_debug_files (struct ehci_hcd *bus) { }
322 322
323#else 323#else
324 324
325/* troubleshooting help: expose state in driverfs */ 325/* troubleshooting help: expose state in sysfs */
326 326
327#define speed_char(info1) ({ char tmp; \ 327#define speed_char(info1) ({ char tmp; \
328 switch (info1 & (3 << 12)) { \ 328 switch (info1 & (3 << 12)) { \
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 185721dba4..a740564882 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -42,6 +42,9 @@
42#include <asm/irq.h> 42#include <asm/irq.h>
43#include <asm/system.h> 43#include <asm/system.h>
44#include <asm/unaligned.h> 44#include <asm/unaligned.h>
45#ifdef CONFIG_PPC_PS3
46#include <asm/firmware.h>
47#endif
45 48
46 49
47/*-------------------------------------------------------------------------*/ 50/*-------------------------------------------------------------------------*/
@@ -299,6 +302,19 @@ static void ehci_watchdog (unsigned long param)
299 spin_unlock_irqrestore (&ehci->lock, flags); 302 spin_unlock_irqrestore (&ehci->lock, flags);
300} 303}
301 304
305/* On some systems, leaving remote wakeup enabled prevents system shutdown.
306 * The firmware seems to think that powering off is a wakeup event!
307 * This routine turns off remote wakeup and everything else, on all ports.
308 */
309static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
310{
311 int port = HCS_N_PORTS(ehci->hcs_params);
312
313 while (port--)
314 ehci_writel(ehci, PORT_RWC_BITS,
315 &ehci->regs->port_status[port]);
316}
317
302/* ehci_shutdown kick in for silicon on any bus (not just pci, etc). 318/* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
303 * This forcibly disables dma and IRQs, helping kexec and other cases 319 * This forcibly disables dma and IRQs, helping kexec and other cases
304 * where the next system software may expect clean state. 320 * where the next system software may expect clean state.
@@ -310,9 +326,13 @@ ehci_shutdown (struct usb_hcd *hcd)
310 326
311 ehci = hcd_to_ehci (hcd); 327 ehci = hcd_to_ehci (hcd);
312 (void) ehci_halt (ehci); 328 (void) ehci_halt (ehci);
329 ehci_turn_off_all_ports(ehci);
313 330
314 /* make BIOS/etc use companion controller during reboot */ 331 /* make BIOS/etc use companion controller during reboot */
315 ehci_writel(ehci, 0, &ehci->regs->configured_flag); 332 ehci_writel(ehci, 0, &ehci->regs->configured_flag);
333
334 /* unblock posted writes */
335 ehci_readl(ehci, &ehci->regs->configured_flag);
316} 336}
317 337
318static void ehci_port_power (struct ehci_hcd *ehci, int is_on) 338static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
@@ -951,15 +971,18 @@ static int __init ehci_hcd_init(void)
951#endif 971#endif
952 972
953#ifdef PS3_SYSTEM_BUS_DRIVER 973#ifdef PS3_SYSTEM_BUS_DRIVER
954 retval = ps3_system_bus_driver_register(&PS3_SYSTEM_BUS_DRIVER); 974 if (firmware_has_feature(FW_FEATURE_PS3_LV1)) {
955 if (retval < 0) { 975 retval = ps3_system_bus_driver_register(
976 &PS3_SYSTEM_BUS_DRIVER);
977 if (retval < 0) {
956#ifdef PLATFORM_DRIVER 978#ifdef PLATFORM_DRIVER
957 platform_driver_unregister(&PLATFORM_DRIVER); 979 platform_driver_unregister(&PLATFORM_DRIVER);
958#endif 980#endif
959#ifdef PCI_DRIVER 981#ifdef PCI_DRIVER
960 pci_unregister_driver(&PCI_DRIVER); 982 pci_unregister_driver(&PCI_DRIVER);
961#endif 983#endif
962 return retval; 984 return retval;
985 }
963 } 986 }
964#endif 987#endif
965 988
@@ -976,7 +999,8 @@ static void __exit ehci_hcd_cleanup(void)
976 pci_unregister_driver(&PCI_DRIVER); 999 pci_unregister_driver(&PCI_DRIVER);
977#endif 1000#endif
978#ifdef PS3_SYSTEM_BUS_DRIVER 1001#ifdef PS3_SYSTEM_BUS_DRIVER
979 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1002 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
1003 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
980#endif 1004#endif
981} 1005}
982module_exit(ehci_hcd_cleanup); 1006module_exit(ehci_hcd_cleanup);
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 0d83c6df1a..9af529d22b 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -36,6 +36,8 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
36 int port; 36 int port;
37 int mask; 37 int mask;
38 38
39 ehci_dbg(ehci, "suspend root hub\n");
40
39 if (time_before (jiffies, ehci->next_statechange)) 41 if (time_before (jiffies, ehci->next_statechange))
40 msleep(5); 42 msleep(5);
41 43
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 2718b5dc4e..46873f2534 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -1577,7 +1577,7 @@ static int isp116x_remove(struct platform_device *pdev)
1577 1577
1578#define resource_len(r) (((r)->end - (r)->start) + 1) 1578#define resource_len(r) (((r)->end - (r)->start) + 1)
1579 1579
1580static int __init isp116x_probe(struct platform_device *pdev) 1580static int __devinit isp116x_probe(struct platform_device *pdev)
1581{ 1581{
1582 struct usb_hcd *hcd; 1582 struct usb_hcd *hcd;
1583 struct isp116x *isp116x; 1583 struct isp116x *isp116x;
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 9303464872..d849c809ac 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -18,19 +18,38 @@
18#include <asm/mach-types.h> 18#include <asm/mach-types.h>
19#include <asm/hardware.h> 19#include <asm/hardware.h>
20#include <asm/arch/board.h> 20#include <asm/arch/board.h>
21#include <asm/arch/cpu.h>
21 22
22#ifndef CONFIG_ARCH_AT91 23#ifndef CONFIG_ARCH_AT91
23#error "CONFIG_ARCH_AT91 must be defined." 24#error "CONFIG_ARCH_AT91 must be defined."
24#endif 25#endif
25 26
26/* interface and function clocks */ 27/* interface and function clocks; sometimes also an AHB clock */
27static struct clk *iclk, *fclk; 28static struct clk *iclk, *fclk, *hclk;
28static int clocked; 29static int clocked;
29 30
30extern int usb_disabled(void); 31extern int usb_disabled(void);
31 32
32/*-------------------------------------------------------------------------*/ 33/*-------------------------------------------------------------------------*/
33 34
35static void at91_start_clock(void)
36{
37 if (cpu_is_at91sam9261())
38 clk_enable(hclk);
39 clk_enable(iclk);
40 clk_enable(fclk);
41 clocked = 1;
42}
43
44static void at91_stop_clock(void)
45{
46 clk_disable(fclk);
47 clk_disable(iclk);
48 if (cpu_is_at91sam9261())
49 clk_disable(hclk);
50 clocked = 0;
51}
52
34static void at91_start_hc(struct platform_device *pdev) 53static void at91_start_hc(struct platform_device *pdev)
35{ 54{
36 struct usb_hcd *hcd = platform_get_drvdata(pdev); 55 struct usb_hcd *hcd = platform_get_drvdata(pdev);
@@ -41,9 +60,7 @@ static void at91_start_hc(struct platform_device *pdev)
41 /* 60 /*
42 * Start the USB clocks. 61 * Start the USB clocks.
43 */ 62 */
44 clk_enable(iclk); 63 at91_start_clock();
45 clk_enable(fclk);
46 clocked = 1;
47 64
48 /* 65 /*
49 * The USB host controller must remain in reset. 66 * The USB host controller must remain in reset.
@@ -66,9 +83,7 @@ static void at91_stop_hc(struct platform_device *pdev)
66 /* 83 /*
67 * Stop the USB clocks. 84 * Stop the USB clocks.
68 */ 85 */
69 clk_disable(fclk); 86 at91_stop_clock();
70 clk_disable(iclk);
71 clocked = 0;
72} 87}
73 88
74 89
@@ -126,6 +141,8 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
126 141
127 iclk = clk_get(&pdev->dev, "ohci_clk"); 142 iclk = clk_get(&pdev->dev, "ohci_clk");
128 fclk = clk_get(&pdev->dev, "uhpck"); 143 fclk = clk_get(&pdev->dev, "uhpck");
144 if (cpu_is_at91sam9261())
145 hclk = clk_get(&pdev->dev, "hck0");
129 146
130 at91_start_hc(pdev); 147 at91_start_hc(pdev);
131 ohci_hcd_init(hcd_to_ohci(hcd)); 148 ohci_hcd_init(hcd_to_ohci(hcd));
@@ -137,6 +154,8 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
137 /* Error handling */ 154 /* Error handling */
138 at91_stop_hc(pdev); 155 at91_stop_hc(pdev);
139 156
157 if (cpu_is_at91sam9261())
158 clk_put(hclk);
140 clk_put(fclk); 159 clk_put(fclk);
141 clk_put(iclk); 160 clk_put(iclk);
142 161
@@ -171,9 +190,11 @@ static int usb_hcd_at91_remove(struct usb_hcd *hcd,
171 iounmap(hcd->regs); 190 iounmap(hcd->regs);
172 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 191 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
173 192
193 if (cpu_is_at91sam9261())
194 clk_put(hclk);
174 clk_put(fclk); 195 clk_put(fclk);
175 clk_put(iclk); 196 clk_put(iclk);
176 fclk = iclk = NULL; 197 fclk = iclk = hclk = NULL;
177 198
178 dev_set_drvdata(&pdev->dev, NULL); 199 dev_set_drvdata(&pdev->dev, NULL);
179 return 0; 200 return 0;
@@ -280,9 +301,7 @@ ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg)
280 */ 301 */
281 if (at91_suspend_entering_slow_clock()) { 302 if (at91_suspend_entering_slow_clock()) {
282 ohci_usb_reset (ohci); 303 ohci_usb_reset (ohci);
283 clk_disable(fclk); 304 at91_stop_clock();
284 clk_disable(iclk);
285 clocked = 0;
286 } 305 }
287 306
288 return 0; 307 return 0;
@@ -295,11 +314,8 @@ static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
295 if (device_may_wakeup(&pdev->dev)) 314 if (device_may_wakeup(&pdev->dev))
296 disable_irq_wake(hcd->irq); 315 disable_irq_wake(hcd->irq);
297 316
298 if (!clocked) { 317 if (!clocked)
299 clk_enable(iclk); 318 at91_start_clock();
300 clk_enable(fclk);
301 clocked = 1;
302 }
303 319
304 return 0; 320 return 0;
305} 321}
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index fa6a7ceaa0..f0d29eda3c 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -42,6 +42,9 @@
42#include <asm/system.h> 42#include <asm/system.h>
43#include <asm/unaligned.h> 43#include <asm/unaligned.h>
44#include <asm/byteorder.h> 44#include <asm/byteorder.h>
45#ifdef CONFIG_PPC_PS3
46#include <asm/firmware.h>
47#endif
45 48
46#include "../core/hcd.h" 49#include "../core/hcd.h"
47 50
@@ -944,9 +947,12 @@ static int __init ohci_hcd_mod_init(void)
944 sizeof (struct ed), sizeof (struct td)); 947 sizeof (struct ed), sizeof (struct td));
945 948
946#ifdef PS3_SYSTEM_BUS_DRIVER 949#ifdef PS3_SYSTEM_BUS_DRIVER
947 retval = ps3_system_bus_driver_register(&PS3_SYSTEM_BUS_DRIVER); 950 if (firmware_has_feature(FW_FEATURE_PS3_LV1)) {
948 if (retval < 0) 951 retval = ps3_system_bus_driver_register(
949 goto error_ps3; 952 &PS3_SYSTEM_BUS_DRIVER);
953 if (retval < 0)
954 goto error_ps3;
955 }
950#endif 956#endif
951 957
952#ifdef PLATFORM_DRIVER 958#ifdef PLATFORM_DRIVER
@@ -992,7 +998,8 @@ static int __init ohci_hcd_mod_init(void)
992 error_platform: 998 error_platform:
993#endif 999#endif
994#ifdef PS3_SYSTEM_BUS_DRIVER 1000#ifdef PS3_SYSTEM_BUS_DRIVER
995 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1001 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
1002 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
996 error_ps3: 1003 error_ps3:
997#endif 1004#endif
998 return retval; 1005 return retval;
@@ -1014,7 +1021,8 @@ static void __exit ohci_hcd_mod_exit(void)
1014 platform_driver_unregister(&PLATFORM_DRIVER); 1021 platform_driver_unregister(&PLATFORM_DRIVER);
1015#endif 1022#endif
1016#ifdef PS3_SYSTEM_BUS_DRIVER 1023#ifdef PS3_SYSTEM_BUS_DRIVER
1017 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1024 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
1025 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1018#endif 1026#endif
1019} 1027}
1020module_exit(ohci_hcd_mod_exit); 1028module_exit(ohci_hcd_mod_exit);
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c
index 5d6c06bc45..8d24d3dc0a 100644
--- a/drivers/usb/host/uhci-debug.c
+++ b/drivers/usb/host/uhci-debug.c
@@ -196,7 +196,7 @@ static int uhci_show_qh(struct uhci_qh *qh, char *buf, int len, int space)
196 struct uhci_td *td = list_entry(urbp->td_list.next, 196 struct uhci_td *td = list_entry(urbp->td_list.next,
197 struct uhci_td, list); 197 struct uhci_td, list);
198 198
199 if (cpu_to_le32(td->dma_handle) != (element & ~UHCI_PTR_BITS)) 199 if (element != LINK_TO_TD(td))
200 out += sprintf(out, "%*s Element != First TD\n", 200 out += sprintf(out, "%*s Element != First TD\n",
201 space, ""); 201 space, "");
202 i = nurbs = 0; 202 i = nurbs = 0;
@@ -220,16 +220,6 @@ static int uhci_show_qh(struct uhci_qh *qh, char *buf, int len, int space)
220 return out - buf; 220 return out - buf;
221} 221}
222 222
223static const char * const qh_names[] = {
224 "skel_unlink_qh", "skel_iso_qh",
225 "skel_int128_qh", "skel_int64_qh",
226 "skel_int32_qh", "skel_int16_qh",
227 "skel_int8_qh", "skel_int4_qh",
228 "skel_int2_qh", "skel_int1_qh",
229 "skel_ls_control_qh", "skel_fs_control_qh",
230 "skel_bulk_qh", "skel_term_qh"
231};
232
233static int uhci_show_sc(int port, unsigned short status, char *buf, int len) 223static int uhci_show_sc(int port, unsigned short status, char *buf, int len)
234{ 224{
235 char *out = buf; 225 char *out = buf;
@@ -352,6 +342,12 @@ static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
352 struct uhci_td *td; 342 struct uhci_td *td;
353 struct list_head *tmp, *head; 343 struct list_head *tmp, *head;
354 int nframes, nerrs; 344 int nframes, nerrs;
345 __le32 link;
346
347 static const char * const qh_names[] = {
348 "unlink", "iso", "int128", "int64", "int32", "int16",
349 "int8", "int4", "int2", "async", "term"
350 };
355 351
356 out += uhci_show_root_hub_state(uhci, out, len - (out - buf)); 352 out += uhci_show_root_hub_state(uhci, out, len - (out - buf));
357 out += sprintf(out, "HC status\n"); 353 out += sprintf(out, "HC status\n");
@@ -374,7 +370,7 @@ static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
374 nframes = 10; 370 nframes = 10;
375 nerrs = 0; 371 nerrs = 0;
376 for (i = 0; i < UHCI_NUMFRAMES; ++i) { 372 for (i = 0; i < UHCI_NUMFRAMES; ++i) {
377 __le32 link, qh_dma; 373 __le32 qh_dma;
378 374
379 j = 0; 375 j = 0;
380 td = uhci->frame_cpu[i]; 376 td = uhci->frame_cpu[i];
@@ -393,7 +389,7 @@ static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
393 do { 389 do {
394 td = list_entry(tmp, struct uhci_td, fl_list); 390 td = list_entry(tmp, struct uhci_td, fl_list);
395 tmp = tmp->next; 391 tmp = tmp->next;
396 if (cpu_to_le32(td->dma_handle) != link) { 392 if (link != LINK_TO_TD(td)) {
397 if (nframes > 0) 393 if (nframes > 0)
398 out += sprintf(out, " link does " 394 out += sprintf(out, " link does "
399 "not match list entry!\n"); 395 "not match list entry!\n");
@@ -430,23 +426,21 @@ check_link:
430 426
431 for (i = 0; i < UHCI_NUM_SKELQH; ++i) { 427 for (i = 0; i < UHCI_NUM_SKELQH; ++i) {
432 int cnt = 0; 428 int cnt = 0;
429 __le32 fsbr_link = 0;
433 430
434 qh = uhci->skelqh[i]; 431 qh = uhci->skelqh[i];
435 out += sprintf(out, "- %s\n", qh_names[i]); \ 432 out += sprintf(out, "- skel_%s_qh\n", qh_names[i]); \
436 out += uhci_show_qh(qh, out, len - (out - buf), 4); 433 out += uhci_show_qh(qh, out, len - (out - buf), 4);
437 434
438 /* Last QH is the Terminating QH, it's different */ 435 /* Last QH is the Terminating QH, it's different */
439 if (i == UHCI_NUM_SKELQH - 1) { 436 if (i == SKEL_TERM) {
440 if (qh->link != UHCI_PTR_TERM) 437 if (qh_element(qh) != LINK_TO_TD(uhci->term_td))
441 out += sprintf(out, " bandwidth reclamation on!\n");
442
443 if (qh_element(qh) != cpu_to_le32(uhci->term_td->dma_handle))
444 out += sprintf(out, " skel_term_qh element is not set to term_td!\n"); 438 out += sprintf(out, " skel_term_qh element is not set to term_td!\n");
445 439 if (link == LINK_TO_QH(uhci->skel_term_qh))
440 goto check_qh_link;
446 continue; 441 continue;
447 } 442 }
448 443
449 j = (i < 9) ? 9 : i+1; /* Next skeleton */
450 head = &qh->node; 444 head = &qh->node;
451 tmp = head->next; 445 tmp = head->next;
452 446
@@ -456,15 +450,26 @@ check_link:
456 if (++cnt <= 10) 450 if (++cnt <= 10)
457 out += uhci_show_qh(qh, out, 451 out += uhci_show_qh(qh, out,
458 len - (out - buf), 4); 452 len - (out - buf), 4);
453 if (!fsbr_link && qh->skel >= SKEL_FSBR)
454 fsbr_link = LINK_TO_QH(qh);
459 } 455 }
460 if ((cnt -= 10) > 0) 456 if ((cnt -= 10) > 0)
461 out += sprintf(out, " Skipped %d QHs\n", cnt); 457 out += sprintf(out, " Skipped %d QHs\n", cnt);
462 458
463 if (i > 1 && i < UHCI_NUM_SKELQH - 1) { 459 link = UHCI_PTR_TERM;
464 if (qh->link != 460 if (i <= SKEL_ISO)
465 (cpu_to_le32(uhci->skelqh[j]->dma_handle) | UHCI_PTR_QH)) 461 ;
466 out += sprintf(out, " last QH not linked to next skeleton!\n"); 462 else if (i < SKEL_ASYNC)
467 } 463 link = LINK_TO_QH(uhci->skel_async_qh);
464 else if (!uhci->fsbr_is_on)
465 ;
466 else if (fsbr_link)
467 link = fsbr_link;
468 else
469 link = LINK_TO_QH(uhci->skel_term_qh);
470check_qh_link:
471 if (qh->link != link)
472 out += sprintf(out, " last QH not linked to next skeleton!\n");
468 } 473 }
469 474
470 return out - buf; 475 return out - buf;
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index ded4df30a6..44da4334f1 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -13,7 +13,7 @@
13 * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface 13 * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface
14 * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). 14 * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com).
15 * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) 15 * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c)
16 * (C) Copyright 2004-2006 Alan Stern, stern@rowland.harvard.edu 16 * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu
17 * 17 *
18 * Intel documents this fairly well, and as far as I know there 18 * Intel documents this fairly well, and as far as I know there
19 * are no royalties or anything like that, but even so there are 19 * are no royalties or anything like that, but even so there are
@@ -107,16 +107,16 @@ static __le32 uhci_frame_skel_link(struct uhci_hcd *uhci, int frame)
107 * interrupt QHs, which will help spread out bandwidth utilization. 107 * interrupt QHs, which will help spread out bandwidth utilization.
108 * 108 *
109 * ffs (Find First bit Set) does exactly what we need: 109 * ffs (Find First bit Set) does exactly what we need:
110 * 1,3,5,... => ffs = 0 => use skel_int2_qh = skelqh[8], 110 * 1,3,5,... => ffs = 0 => use period-2 QH = skelqh[8],
111 * 2,6,10,... => ffs = 1 => use skel_int4_qh = skelqh[7], etc. 111 * 2,6,10,... => ffs = 1 => use period-4 QH = skelqh[7], etc.
112 * ffs >= 7 => not on any high-period queue, so use 112 * ffs >= 7 => not on any high-period queue, so use
113 * skel_int1_qh = skelqh[9]. 113 * period-1 QH = skelqh[9].
114 * Add in UHCI_NUMFRAMES to insure at least one bit is set. 114 * Add in UHCI_NUMFRAMES to insure at least one bit is set.
115 */ 115 */
116 skelnum = 8 - (int) __ffs(frame | UHCI_NUMFRAMES); 116 skelnum = 8 - (int) __ffs(frame | UHCI_NUMFRAMES);
117 if (skelnum <= 1) 117 if (skelnum <= 1)
118 skelnum = 9; 118 skelnum = 9;
119 return UHCI_PTR_QH | cpu_to_le32(uhci->skelqh[skelnum]->dma_handle); 119 return LINK_TO_QH(uhci->skelqh[skelnum]);
120} 120}
121 121
122#include "uhci-debug.c" 122#include "uhci-debug.c"
@@ -540,16 +540,18 @@ static void uhci_shutdown(struct pci_dev *pdev)
540 * 540 *
541 * The hardware doesn't really know any difference 541 * The hardware doesn't really know any difference
542 * in the queues, but the order does matter for the 542 * in the queues, but the order does matter for the
543 * protocols higher up. The order is: 543 * protocols higher up. The order in which the queues
544 * are encountered by the hardware is:
544 * 545 *
545 * - any isochronous events handled before any 546 * - All isochronous events are handled before any
546 * of the queues. We don't do that here, because 547 * of the queues. We don't do that here, because
547 * we'll create the actual TD entries on demand. 548 * we'll create the actual TD entries on demand.
548 * - The first queue is the interrupt queue. 549 * - The first queue is the high-period interrupt queue.
549 * - The second queue is the control queue, split into low- and full-speed 550 * - The second queue is the period-1 interrupt and async
550 * - The third queue is bulk queue. 551 * (low-speed control, full-speed control, then bulk) queue.
551 * - The fourth queue is the bandwidth reclamation queue, which loops back 552 * - The third queue is the terminating bandwidth reclamation queue,
552 * to the full-speed control queue. 553 * which contains no members, loops back to itself, and is present
554 * only when FSBR is on and there are no full-speed control or bulk QHs.
553 */ 555 */
554static int uhci_start(struct usb_hcd *hcd) 556static int uhci_start(struct usb_hcd *hcd)
555{ 557{
@@ -626,34 +628,18 @@ static int uhci_start(struct usb_hcd *hcd)
626 } 628 }
627 629
628 /* 630 /*
629 * 8 Interrupt queues; link all higher int queues to int1, 631 * 8 Interrupt queues; link all higher int queues to int1 = async
630 * then link int1 to control and control to bulk
631 */ 632 */
632 uhci->skel_int128_qh->link = 633 for (i = SKEL_ISO + 1; i < SKEL_ASYNC; ++i)
633 uhci->skel_int64_qh->link = 634 uhci->skelqh[i]->link = LINK_TO_QH(uhci->skel_async_qh);
634 uhci->skel_int32_qh->link = 635 uhci->skel_async_qh->link = uhci->skel_term_qh->link = UHCI_PTR_TERM;
635 uhci->skel_int16_qh->link =
636 uhci->skel_int8_qh->link =
637 uhci->skel_int4_qh->link =
638 uhci->skel_int2_qh->link = UHCI_PTR_QH |
639 cpu_to_le32(uhci->skel_int1_qh->dma_handle);
640
641 uhci->skel_int1_qh->link = UHCI_PTR_QH |
642 cpu_to_le32(uhci->skel_ls_control_qh->dma_handle);
643 uhci->skel_ls_control_qh->link = UHCI_PTR_QH |
644 cpu_to_le32(uhci->skel_fs_control_qh->dma_handle);
645 uhci->skel_fs_control_qh->link = UHCI_PTR_QH |
646 cpu_to_le32(uhci->skel_bulk_qh->dma_handle);
647 uhci->skel_bulk_qh->link = UHCI_PTR_QH |
648 cpu_to_le32(uhci->skel_term_qh->dma_handle);
649 636
650 /* This dummy TD is to work around a bug in Intel PIIX controllers */ 637 /* This dummy TD is to work around a bug in Intel PIIX controllers */
651 uhci_fill_td(uhci->term_td, 0, uhci_explen(0) | 638 uhci_fill_td(uhci->term_td, 0, uhci_explen(0) |
652 (0x7f << TD_TOKEN_DEVADDR_SHIFT) | USB_PID_IN, 0); 639 (0x7f << TD_TOKEN_DEVADDR_SHIFT) | USB_PID_IN, 0);
653 uhci->term_td->link = cpu_to_le32(uhci->term_td->dma_handle); 640 uhci->term_td->link = UHCI_PTR_TERM;
654 641 uhci->skel_async_qh->element = uhci->skel_term_qh->element =
655 uhci->skel_term_qh->link = UHCI_PTR_TERM; 642 LINK_TO_TD(uhci->term_td);
656 uhci->skel_term_qh->element = cpu_to_le32(uhci->term_td->dma_handle);
657 643
658 /* 644 /*
659 * Fill the frame list: make all entries point to the proper 645 * Fill the frame list: make all entries point to the proper
diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h
index 74469b5bcb..1b3d23406a 100644
--- a/drivers/usb/host/uhci-hcd.h
+++ b/drivers/usb/host/uhci-hcd.h
@@ -129,11 +129,12 @@ struct uhci_qh {
129 __le32 element; /* Queue element (TD) pointer */ 129 __le32 element; /* Queue element (TD) pointer */
130 130
131 /* Software fields */ 131 /* Software fields */
132 dma_addr_t dma_handle;
133
132 struct list_head node; /* Node in the list of QHs */ 134 struct list_head node; /* Node in the list of QHs */
133 struct usb_host_endpoint *hep; /* Endpoint information */ 135 struct usb_host_endpoint *hep; /* Endpoint information */
134 struct usb_device *udev; 136 struct usb_device *udev;
135 struct list_head queue; /* Queue of urbps for this QH */ 137 struct list_head queue; /* Queue of urbps for this QH */
136 struct uhci_qh *skel; /* Skeleton for this QH */
137 struct uhci_td *dummy_td; /* Dummy TD to end the queue */ 138 struct uhci_td *dummy_td; /* Dummy TD to end the queue */
138 struct uhci_td *post_td; /* Last TD completed */ 139 struct uhci_td *post_td; /* Last TD completed */
139 140
@@ -149,8 +150,7 @@ struct uhci_qh {
149 150
150 int state; /* QH_STATE_xxx; see above */ 151 int state; /* QH_STATE_xxx; see above */
151 int type; /* Queue type (control, bulk, etc) */ 152 int type; /* Queue type (control, bulk, etc) */
152 153 int skel; /* Skeleton queue number */
153 dma_addr_t dma_handle;
154 154
155 unsigned int initial_toggle:1; /* Endpoint's current toggle value */ 155 unsigned int initial_toggle:1; /* Endpoint's current toggle value */
156 unsigned int needs_fixup:1; /* Must fix the TD toggle values */ 156 unsigned int needs_fixup:1; /* Must fix the TD toggle values */
@@ -171,6 +171,8 @@ static inline __le32 qh_element(struct uhci_qh *qh) {
171 return element; 171 return element;
172} 172}
173 173
174#define LINK_TO_QH(qh) (UHCI_PTR_QH | cpu_to_le32((qh)->dma_handle))
175
174 176
175/* 177/*
176 * Transfer Descriptors 178 * Transfer Descriptors
@@ -264,6 +266,8 @@ static inline u32 td_status(struct uhci_td *td) {
264 return le32_to_cpu(status); 266 return le32_to_cpu(status);
265} 267}
266 268
269#define LINK_TO_TD(td) (cpu_to_le32((td)->dma_handle))
270
267 271
268/* 272/*
269 * Skeleton Queue Headers 273 * Skeleton Queue Headers
@@ -272,12 +276,13 @@ static inline u32 td_status(struct uhci_td *td) {
272/* 276/*
273 * The UHCI driver uses QHs with Interrupt, Control and Bulk URBs for 277 * The UHCI driver uses QHs with Interrupt, Control and Bulk URBs for
274 * automatic queuing. To make it easy to insert entries into the schedule, 278 * automatic queuing. To make it easy to insert entries into the schedule,
275 * we have a skeleton of QHs for each predefined Interrupt latency, 279 * we have a skeleton of QHs for each predefined Interrupt latency.
276 * low-speed control, full-speed control, bulk, and terminating QH 280 * Asynchronous QHs (low-speed control, full-speed control, and bulk)
277 * (see explanation for the terminating QH below). 281 * go onto the period-1 interrupt list, since they all get accessed on
282 * every frame.
278 * 283 *
279 * When we want to add a new QH, we add it to the end of the list for the 284 * When we want to add a new QH, we add it to the list starting from the
280 * skeleton QH. For instance, the schedule list can look like this: 285 * appropriate skeleton QH. For instance, the schedule can look like this:
281 * 286 *
282 * skel int128 QH 287 * skel int128 QH
283 * dev 1 interrupt QH 288 * dev 1 interrupt QH
@@ -285,50 +290,47 @@ static inline u32 td_status(struct uhci_td *td) {
285 * skel int64 QH 290 * skel int64 QH
286 * skel int32 QH 291 * skel int32 QH
287 * ... 292 * ...
288 * skel int1 QH 293 * skel int1 + async QH
289 * skel low-speed control QH 294 * dev 5 low-speed control QH
290 * dev 5 control QH
291 * skel full-speed control QH
292 * skel bulk QH
293 * dev 1 bulk QH 295 * dev 1 bulk QH
294 * dev 2 bulk QH 296 * dev 2 bulk QH
295 * skel terminating QH
296 * 297 *
297 * The terminating QH is used for 2 reasons: 298 * There is a special terminating QH used to keep full-speed bandwidth
298 * - To place a terminating TD which is used to workaround a PIIX bug 299 * reclamation active when no full-speed control or bulk QHs are linked
299 * (see Intel errata for explanation), and 300 * into the schedule. It has an inactive TD (to work around a PIIX bug,
300 * - To loop back to the full-speed control queue for full-speed bandwidth 301 * see the Intel errata) and it points back to itself.
301 * reclamation.
302 * 302 *
303 * There's a special skeleton QH for Isochronous QHs. It never appears 303 * There's a special skeleton QH for Isochronous QHs which never appears
304 * on the schedule, and Isochronous TDs go on the schedule before the 304 * on the schedule. Isochronous TDs go on the schedule before the
305 * the skeleton QHs. The hardware accesses them directly rather than 305 * the skeleton QHs. The hardware accesses them directly rather than
306 * through their QH, which is used only for bookkeeping purposes. 306 * through their QH, which is used only for bookkeeping purposes.
307 * While the UHCI spec doesn't forbid the use of QHs for Isochronous, 307 * While the UHCI spec doesn't forbid the use of QHs for Isochronous,
308 * it doesn't use them either. And the spec says that queues never 308 * it doesn't use them either. And the spec says that queues never
309 * advance on an error completion status, which makes them totally 309 * advance on an error completion status, which makes them totally
310 * unsuitable for Isochronous transfers. 310 * unsuitable for Isochronous transfers.
311 *
312 * There's also a special skeleton QH used for QHs which are in the process
313 * of unlinking and so may still be in use by the hardware. It too never
314 * appears on the schedule.
311 */ 315 */
312 316
313#define UHCI_NUM_SKELQH 14 317#define UHCI_NUM_SKELQH 11
314#define skel_unlink_qh skelqh[0] 318#define SKEL_UNLINK 0
315#define skel_iso_qh skelqh[1] 319#define skel_unlink_qh skelqh[SKEL_UNLINK]
316#define skel_int128_qh skelqh[2] 320#define SKEL_ISO 1
317#define skel_int64_qh skelqh[3] 321#define skel_iso_qh skelqh[SKEL_ISO]
318#define skel_int32_qh skelqh[4] 322 /* int128, int64, ..., int1 = 2, 3, ..., 9 */
319#define skel_int16_qh skelqh[5] 323#define SKEL_INDEX(exponent) (9 - exponent)
320#define skel_int8_qh skelqh[6] 324#define SKEL_ASYNC 9
321#define skel_int4_qh skelqh[7] 325#define skel_async_qh skelqh[SKEL_ASYNC]
322#define skel_int2_qh skelqh[8] 326#define SKEL_TERM 10
323#define skel_int1_qh skelqh[9] 327#define skel_term_qh skelqh[SKEL_TERM]
324#define skel_ls_control_qh skelqh[10] 328
325#define skel_fs_control_qh skelqh[11] 329/* The following entries refer to sublists of skel_async_qh */
326#define skel_bulk_qh skelqh[12] 330#define SKEL_LS_CONTROL 20
327#define skel_term_qh skelqh[13] 331#define SKEL_FS_CONTROL 21
328 332#define SKEL_FSBR SKEL_FS_CONTROL
329/* Find the skelqh entry corresponding to an interval exponent */ 333#define SKEL_BULK 22
330#define UHCI_SKEL_INDEX(exponent) (9 - exponent)
331
332 334
333/* 335/*
334 * The UHCI controller and root hub 336 * The UHCI controller and root hub
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index 68e66b33e7..f4ebdb3e48 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -13,7 +13,7 @@
13 * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface 13 * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface
14 * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). 14 * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com).
15 * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) 15 * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c)
16 * (C) Copyright 2004-2006 Alan Stern, stern@rowland.harvard.edu 16 * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu
17 */ 17 */
18 18
19 19
@@ -45,15 +45,43 @@ static inline void uhci_clear_next_interrupt(struct uhci_hcd *uhci)
45 */ 45 */
46static void uhci_fsbr_on(struct uhci_hcd *uhci) 46static void uhci_fsbr_on(struct uhci_hcd *uhci)
47{ 47{
48 struct uhci_qh *fsbr_qh, *lqh, *tqh;
49
48 uhci->fsbr_is_on = 1; 50 uhci->fsbr_is_on = 1;
49 uhci->skel_term_qh->link = cpu_to_le32( 51 lqh = list_entry(uhci->skel_async_qh->node.prev,
50 uhci->skel_fs_control_qh->dma_handle) | UHCI_PTR_QH; 52 struct uhci_qh, node);
53
54 /* Find the first FSBR QH. Linear search through the list is
55 * acceptable because normally FSBR gets turned on as soon as
56 * one QH needs it. */
57 fsbr_qh = NULL;
58 list_for_each_entry_reverse(tqh, &uhci->skel_async_qh->node, node) {
59 if (tqh->skel < SKEL_FSBR)
60 break;
61 fsbr_qh = tqh;
62 }
63
64 /* No FSBR QH means we must insert the terminating skeleton QH */
65 if (!fsbr_qh) {
66 uhci->skel_term_qh->link = LINK_TO_QH(uhci->skel_term_qh);
67 wmb();
68 lqh->link = uhci->skel_term_qh->link;
69
70 /* Otherwise loop the last QH to the first FSBR QH */
71 } else
72 lqh->link = LINK_TO_QH(fsbr_qh);
51} 73}
52 74
53static void uhci_fsbr_off(struct uhci_hcd *uhci) 75static void uhci_fsbr_off(struct uhci_hcd *uhci)
54{ 76{
77 struct uhci_qh *lqh;
78
55 uhci->fsbr_is_on = 0; 79 uhci->fsbr_is_on = 0;
56 uhci->skel_term_qh->link = UHCI_PTR_TERM; 80 lqh = list_entry(uhci->skel_async_qh->node.prev,
81 struct uhci_qh, node);
82
83 /* End the async list normally and unlink the terminating QH */
84 lqh->link = uhci->skel_term_qh->link = UHCI_PTR_TERM;
57} 85}
58 86
59static void uhci_add_fsbr(struct uhci_hcd *uhci, struct urb *urb) 87static void uhci_add_fsbr(struct uhci_hcd *uhci, struct urb *urb)
@@ -158,11 +186,11 @@ static inline void uhci_insert_td_in_frame_list(struct uhci_hcd *uhci,
158 186
159 td->link = ltd->link; 187 td->link = ltd->link;
160 wmb(); 188 wmb();
161 ltd->link = cpu_to_le32(td->dma_handle); 189 ltd->link = LINK_TO_TD(td);
162 } else { 190 } else {
163 td->link = uhci->frame[framenum]; 191 td->link = uhci->frame[framenum];
164 wmb(); 192 wmb();
165 uhci->frame[framenum] = cpu_to_le32(td->dma_handle); 193 uhci->frame[framenum] = LINK_TO_TD(td);
166 uhci->frame_cpu[framenum] = td; 194 uhci->frame_cpu[framenum] = td;
167 } 195 }
168} 196}
@@ -184,7 +212,7 @@ static inline void uhci_remove_td_from_frame_list(struct uhci_hcd *uhci,
184 struct uhci_td *ntd; 212 struct uhci_td *ntd;
185 213
186 ntd = list_entry(td->fl_list.next, struct uhci_td, fl_list); 214 ntd = list_entry(td->fl_list.next, struct uhci_td, fl_list);
187 uhci->frame[td->frame] = cpu_to_le32(ntd->dma_handle); 215 uhci->frame[td->frame] = LINK_TO_TD(ntd);
188 uhci->frame_cpu[td->frame] = ntd; 216 uhci->frame_cpu[td->frame] = ntd;
189 } 217 }
190 } else { 218 } else {
@@ -405,12 +433,81 @@ static void uhci_fixup_toggles(struct uhci_qh *qh, int skip_first)
405} 433}
406 434
407/* 435/*
408 * Put a QH on the schedule in both hardware and software 436 * Link an Isochronous QH into its skeleton's list
409 */ 437 */
410static void uhci_activate_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) 438static inline void link_iso(struct uhci_hcd *uhci, struct uhci_qh *qh)
439{
440 list_add_tail(&qh->node, &uhci->skel_iso_qh->node);
441
442 /* Isochronous QHs aren't linked by the hardware */
443}
444
445/*
446 * Link a high-period interrupt QH into the schedule at the end of its
447 * skeleton's list
448 */
449static void link_interrupt(struct uhci_hcd *uhci, struct uhci_qh *qh)
411{ 450{
412 struct uhci_qh *pqh; 451 struct uhci_qh *pqh;
413 452
453 list_add_tail(&qh->node, &uhci->skelqh[qh->skel]->node);
454
455 pqh = list_entry(qh->node.prev, struct uhci_qh, node);
456 qh->link = pqh->link;
457 wmb();
458 pqh->link = LINK_TO_QH(qh);
459}
460
461/*
462 * Link a period-1 interrupt or async QH into the schedule at the
463 * correct spot in the async skeleton's list, and update the FSBR link
464 */
465static void link_async(struct uhci_hcd *uhci, struct uhci_qh *qh)
466{
467 struct uhci_qh *pqh, *lqh;
468 __le32 link_to_new_qh;
469 __le32 *extra_link = &link_to_new_qh;
470
471 /* Find the predecessor QH for our new one and insert it in the list.
472 * The list of QHs is expected to be short, so linear search won't
473 * take too long. */
474 list_for_each_entry_reverse(pqh, &uhci->skel_async_qh->node, node) {
475 if (pqh->skel <= qh->skel)
476 break;
477 }
478 list_add(&qh->node, &pqh->node);
479 qh->link = pqh->link;
480
481 link_to_new_qh = LINK_TO_QH(qh);
482
483 /* If this is now the first FSBR QH, take special action */
484 if (uhci->fsbr_is_on && pqh->skel < SKEL_FSBR &&
485 qh->skel >= SKEL_FSBR) {
486 lqh = list_entry(uhci->skel_async_qh->node.prev,
487 struct uhci_qh, node);
488
489 /* If the new QH is also the last one, we must unlink
490 * the terminating skeleton QH and make the new QH point
491 * back to itself. */
492 if (qh == lqh) {
493 qh->link = link_to_new_qh;
494 extra_link = &uhci->skel_term_qh->link;
495
496 /* Otherwise the last QH must point to the new QH */
497 } else
498 extra_link = &lqh->link;
499 }
500
501 /* Link it into the schedule */
502 wmb();
503 *extra_link = pqh->link = link_to_new_qh;
504}
505
506/*
507 * Put a QH on the schedule in both hardware and software
508 */
509static void uhci_activate_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
510{
414 WARN_ON(list_empty(&qh->queue)); 511 WARN_ON(list_empty(&qh->queue));
415 512
416 /* Set the element pointer if it isn't set already. 513 /* Set the element pointer if it isn't set already.
@@ -421,7 +518,7 @@ static void uhci_activate_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
421 struct uhci_td *td = list_entry(urbp->td_list.next, 518 struct uhci_td *td = list_entry(urbp->td_list.next,
422 struct uhci_td, list); 519 struct uhci_td, list);
423 520
424 qh->element = cpu_to_le32(td->dma_handle); 521 qh->element = LINK_TO_TD(td);
425 } 522 }
426 523
427 /* Treat the queue as if it has just advanced */ 524 /* Treat the queue as if it has just advanced */
@@ -432,18 +529,64 @@ static void uhci_activate_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
432 return; 529 return;
433 qh->state = QH_STATE_ACTIVE; 530 qh->state = QH_STATE_ACTIVE;
434 531
435 /* Move the QH from its old list to the end of the appropriate 532 /* Move the QH from its old list to the correct spot in the appropriate
436 * skeleton's list */ 533 * skeleton's list */
437 if (qh == uhci->next_qh) 534 if (qh == uhci->next_qh)
438 uhci->next_qh = list_entry(qh->node.next, struct uhci_qh, 535 uhci->next_qh = list_entry(qh->node.next, struct uhci_qh,
439 node); 536 node);
440 list_move_tail(&qh->node, &qh->skel->node); 537 list_del(&qh->node);
538
539 if (qh->skel == SKEL_ISO)
540 link_iso(uhci, qh);
541 else if (qh->skel < SKEL_ASYNC)
542 link_interrupt(uhci, qh);
543 else
544 link_async(uhci, qh);
545}
546
547/*
548 * Unlink a high-period interrupt QH from the schedule
549 */
550static void unlink_interrupt(struct uhci_hcd *uhci, struct uhci_qh *qh)
551{
552 struct uhci_qh *pqh;
441 553
442 /* Link it into the schedule */
443 pqh = list_entry(qh->node.prev, struct uhci_qh, node); 554 pqh = list_entry(qh->node.prev, struct uhci_qh, node);
444 qh->link = pqh->link; 555 pqh->link = qh->link;
445 wmb(); 556 mb();
446 pqh->link = UHCI_PTR_QH | cpu_to_le32(qh->dma_handle); 557}
558
559/*
560 * Unlink a period-1 interrupt or async QH from the schedule
561 */
562static void unlink_async(struct uhci_hcd *uhci, struct uhci_qh *qh)
563{
564 struct uhci_qh *pqh, *lqh;
565 __le32 link_to_next_qh = qh->link;
566
567 pqh = list_entry(qh->node.prev, struct uhci_qh, node);
568
569 /* If this is the first FSBQ QH, take special action */
570 if (uhci->fsbr_is_on && pqh->skel < SKEL_FSBR &&
571 qh->skel >= SKEL_FSBR) {
572 lqh = list_entry(uhci->skel_async_qh->node.prev,
573 struct uhci_qh, node);
574
575 /* If this QH is also the last one, we must link in
576 * the terminating skeleton QH. */
577 if (qh == lqh) {
578 link_to_next_qh = LINK_TO_QH(uhci->skel_term_qh);
579 uhci->skel_term_qh->link = link_to_next_qh;
580 wmb();
581 qh->link = link_to_next_qh;
582
583 /* Otherwise the last QH must point to the new first FSBR QH */
584 } else
585 lqh->link = link_to_next_qh;
586 }
587
588 pqh->link = link_to_next_qh;
589 mb();
447} 590}
448 591
449/* 592/*
@@ -451,17 +594,18 @@ static void uhci_activate_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
451 */ 594 */
452static void uhci_unlink_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) 595static void uhci_unlink_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
453{ 596{
454 struct uhci_qh *pqh;
455
456 if (qh->state == QH_STATE_UNLINKING) 597 if (qh->state == QH_STATE_UNLINKING)
457 return; 598 return;
458 WARN_ON(qh->state != QH_STATE_ACTIVE || !qh->udev); 599 WARN_ON(qh->state != QH_STATE_ACTIVE || !qh->udev);
459 qh->state = QH_STATE_UNLINKING; 600 qh->state = QH_STATE_UNLINKING;
460 601
461 /* Unlink the QH from the schedule and record when we did it */ 602 /* Unlink the QH from the schedule and record when we did it */
462 pqh = list_entry(qh->node.prev, struct uhci_qh, node); 603 if (qh->skel == SKEL_ISO)
463 pqh->link = qh->link; 604 ;
464 mb(); 605 else if (qh->skel < SKEL_ASYNC)
606 unlink_interrupt(uhci, qh);
607 else
608 unlink_async(uhci, qh);
465 609
466 uhci_get_current_frame_number(uhci); 610 uhci_get_current_frame_number(uhci);
467 qh->unlink_frame = uhci->frame_number; 611 qh->unlink_frame = uhci->frame_number;
@@ -697,6 +841,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
697 dma_addr_t data = urb->transfer_dma; 841 dma_addr_t data = urb->transfer_dma;
698 __le32 *plink; 842 __le32 *plink;
699 struct urb_priv *urbp = urb->hcpriv; 843 struct urb_priv *urbp = urb->hcpriv;
844 int skel;
700 845
701 /* The "pipe" thing contains the destination in bits 8--18 */ 846 /* The "pipe" thing contains the destination in bits 8--18 */
702 destination = (urb->pipe & PIPE_DEVEP_MASK) | USB_PID_SETUP; 847 destination = (urb->pipe & PIPE_DEVEP_MASK) | USB_PID_SETUP;
@@ -737,7 +882,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
737 td = uhci_alloc_td(uhci); 882 td = uhci_alloc_td(uhci);
738 if (!td) 883 if (!td)
739 goto nomem; 884 goto nomem;
740 *plink = cpu_to_le32(td->dma_handle); 885 *plink = LINK_TO_TD(td);
741 886
742 /* Alternate Data0/1 (start with Data1) */ 887 /* Alternate Data0/1 (start with Data1) */
743 destination ^= TD_TOKEN_TOGGLE; 888 destination ^= TD_TOKEN_TOGGLE;
@@ -757,7 +902,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
757 td = uhci_alloc_td(uhci); 902 td = uhci_alloc_td(uhci);
758 if (!td) 903 if (!td)
759 goto nomem; 904 goto nomem;
760 *plink = cpu_to_le32(td->dma_handle); 905 *plink = LINK_TO_TD(td);
761 906
762 /* 907 /*
763 * It's IN if the pipe is an output pipe or we're not expecting 908 * It's IN if the pipe is an output pipe or we're not expecting
@@ -784,7 +929,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
784 td = uhci_alloc_td(uhci); 929 td = uhci_alloc_td(uhci);
785 if (!td) 930 if (!td)
786 goto nomem; 931 goto nomem;
787 *plink = cpu_to_le32(td->dma_handle); 932 *plink = LINK_TO_TD(td);
788 933
789 uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0); 934 uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0);
790 wmb(); 935 wmb();
@@ -797,11 +942,13 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
797 * isn't in the CONFIGURED state. */ 942 * isn't in the CONFIGURED state. */
798 if (urb->dev->speed == USB_SPEED_LOW || 943 if (urb->dev->speed == USB_SPEED_LOW ||
799 urb->dev->state != USB_STATE_CONFIGURED) 944 urb->dev->state != USB_STATE_CONFIGURED)
800 qh->skel = uhci->skel_ls_control_qh; 945 skel = SKEL_LS_CONTROL;
801 else { 946 else {
802 qh->skel = uhci->skel_fs_control_qh; 947 skel = SKEL_FS_CONTROL;
803 uhci_add_fsbr(uhci, urb); 948 uhci_add_fsbr(uhci, urb);
804 } 949 }
950 if (qh->state != QH_STATE_ACTIVE)
951 qh->skel = skel;
805 952
806 urb->actual_length = -8; /* Account for the SETUP packet */ 953 urb->actual_length = -8; /* Account for the SETUP packet */
807 return 0; 954 return 0;
@@ -860,7 +1007,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb,
860 td = uhci_alloc_td(uhci); 1007 td = uhci_alloc_td(uhci);
861 if (!td) 1008 if (!td)
862 goto nomem; 1009 goto nomem;
863 *plink = cpu_to_le32(td->dma_handle); 1010 *plink = LINK_TO_TD(td);
864 } 1011 }
865 uhci_add_td_to_urbp(td, urbp); 1012 uhci_add_td_to_urbp(td, urbp);
866 uhci_fill_td(td, status, 1013 uhci_fill_td(td, status,
@@ -888,7 +1035,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb,
888 td = uhci_alloc_td(uhci); 1035 td = uhci_alloc_td(uhci);
889 if (!td) 1036 if (!td)
890 goto nomem; 1037 goto nomem;
891 *plink = cpu_to_le32(td->dma_handle); 1038 *plink = LINK_TO_TD(td);
892 1039
893 uhci_add_td_to_urbp(td, urbp); 1040 uhci_add_td_to_urbp(td, urbp);
894 uhci_fill_td(td, status, 1041 uhci_fill_td(td, status,
@@ -914,7 +1061,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb,
914 td = uhci_alloc_td(uhci); 1061 td = uhci_alloc_td(uhci);
915 if (!td) 1062 if (!td)
916 goto nomem; 1063 goto nomem;
917 *plink = cpu_to_le32(td->dma_handle); 1064 *plink = LINK_TO_TD(td);
918 1065
919 uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0); 1066 uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0);
920 wmb(); 1067 wmb();
@@ -931,7 +1078,7 @@ nomem:
931 return -ENOMEM; 1078 return -ENOMEM;
932} 1079}
933 1080
934static inline int uhci_submit_bulk(struct uhci_hcd *uhci, struct urb *urb, 1081static int uhci_submit_bulk(struct uhci_hcd *uhci, struct urb *urb,
935 struct uhci_qh *qh) 1082 struct uhci_qh *qh)
936{ 1083{
937 int ret; 1084 int ret;
@@ -940,7 +1087,8 @@ static inline int uhci_submit_bulk(struct uhci_hcd *uhci, struct urb *urb,
940 if (urb->dev->speed == USB_SPEED_LOW) 1087 if (urb->dev->speed == USB_SPEED_LOW)
941 return -EINVAL; 1088 return -EINVAL;
942 1089
943 qh->skel = uhci->skel_bulk_qh; 1090 if (qh->state != QH_STATE_ACTIVE)
1091 qh->skel = SKEL_BULK;
944 ret = uhci_submit_common(uhci, urb, qh); 1092 ret = uhci_submit_common(uhci, urb, qh);
945 if (ret == 0) 1093 if (ret == 0)
946 uhci_add_fsbr(uhci, urb); 1094 uhci_add_fsbr(uhci, urb);
@@ -968,7 +1116,7 @@ static int uhci_submit_interrupt(struct uhci_hcd *uhci, struct urb *urb,
968 if (exponent < 0) 1116 if (exponent < 0)
969 return -EINVAL; 1117 return -EINVAL;
970 qh->period = 1 << exponent; 1118 qh->period = 1 << exponent;
971 qh->skel = uhci->skelqh[UHCI_SKEL_INDEX(exponent)]; 1119 qh->skel = SKEL_INDEX(exponent);
972 1120
973 /* For now, interrupt phase is fixed by the layout 1121 /* For now, interrupt phase is fixed by the layout
974 * of the QH lists. */ 1122 * of the QH lists. */
@@ -1005,7 +1153,7 @@ static int uhci_fixup_short_transfer(struct uhci_hcd *uhci,
1005 * the queue at the status stage transaction, which is 1153 * the queue at the status stage transaction, which is
1006 * the last TD. */ 1154 * the last TD. */
1007 WARN_ON(list_empty(&urbp->td_list)); 1155 WARN_ON(list_empty(&urbp->td_list));
1008 qh->element = cpu_to_le32(td->dma_handle); 1156 qh->element = LINK_TO_TD(td);
1009 tmp = td->list.prev; 1157 tmp = td->list.prev;
1010 ret = -EINPROGRESS; 1158 ret = -EINPROGRESS;
1011 1159
@@ -1216,7 +1364,7 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb,
1216 qh->iso_status = 0; 1364 qh->iso_status = 0;
1217 } 1365 }
1218 1366
1219 qh->skel = uhci->skel_iso_qh; 1367 qh->skel = SKEL_ISO;
1220 if (!qh->bandwidth_reserved) 1368 if (!qh->bandwidth_reserved)
1221 uhci_reserve_bandwidth(uhci, qh); 1369 uhci_reserve_bandwidth(uhci, qh);
1222 return 0; 1370 return 0;
@@ -1566,8 +1714,7 @@ static int uhci_advance_check(struct uhci_hcd *uhci, struct uhci_qh *qh)
1566 if (time_after(jiffies, qh->advance_jiffies + QH_WAIT_TIMEOUT)) { 1714 if (time_after(jiffies, qh->advance_jiffies + QH_WAIT_TIMEOUT)) {
1567 1715
1568 /* Detect the Intel bug and work around it */ 1716 /* Detect the Intel bug and work around it */
1569 if (qh->post_td && qh_element(qh) == 1717 if (qh->post_td && qh_element(qh) == LINK_TO_TD(qh->post_td)) {
1570 cpu_to_le32(qh->post_td->dma_handle)) {
1571 qh->element = qh->post_td->link; 1718 qh->element = qh->post_td->link;
1572 qh->advance_jiffies = jiffies; 1719 qh->advance_jiffies = jiffies;
1573 ret = 1; 1720 ret = 1;
diff --git a/drivers/usb/input/Kconfig b/drivers/usb/input/Kconfig
index 2e71d3cca1..69a9f3b6d0 100644
--- a/drivers/usb/input/Kconfig
+++ b/drivers/usb/input/Kconfig
@@ -58,13 +58,17 @@ config HID_PID
58 devices. 58 devices.
59 59
60config LOGITECH_FF 60config LOGITECH_FF
61 bool "Logitech WingMan *3D support" 61 bool "Logitech devices support"
62 depends on HID_FF 62 depends on HID_FF
63 select INPUT_FF_MEMLESS if USB_HID 63 select INPUT_FF_MEMLESS if USB_HID
64 help 64 help
65 Say Y here if you have one of these devices: 65 Say Y here if you have one of these devices:
66 - Logitech WingMan Cordless RumblePad 66 - Logitech WingMan Cordless RumblePad
67 - Logitech WingMan Cordless RumblePad 2
67 - Logitech WingMan Force 3D 68 - Logitech WingMan Force 3D
69 - Logitech Formula Force EX
70 - Logitech MOMO Force wheel
71
68 and if you want to enable force feedback for them. 72 and if you want to enable force feedback for them.
69 Note: if you say N here, this device will still be supported, but without 73 Note: if you say N here, this device will still be supported, but without
70 force feedback. 74 force feedback.
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 4d8ed3d71a..827a75a186 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -4,7 +4,7 @@
4 * Copyright (c) 1999 Andreas Gal 4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006 Jiri Kosina 7 * Copyright (c) 2006-2007 Jiri Kosina
8 */ 8 */
9 9
10/* 10/*
@@ -27,9 +27,6 @@
27#include <linux/input.h> 27#include <linux/input.h>
28#include <linux/wait.h> 28#include <linux/wait.h>
29 29
30#undef DEBUG
31#undef DEBUG_DATA
32
33#include <linux/usb.h> 30#include <linux/usb.h>
34 31
35#include <linux/hid.h> 32#include <linux/hid.h>
@@ -515,6 +512,7 @@ void usbhid_close(struct hid_device *hid)
515 512
516#define USB_VENDOR_ID_TURBOX 0x062a 513#define USB_VENDOR_ID_TURBOX 0x062a
517#define USB_DEVICE_ID_TURBOX_KEYBOARD 0x0201 514#define USB_DEVICE_ID_TURBOX_KEYBOARD 0x0201
515#define USB_VENDOR_ID_CIDC 0x1677
518 516
519/* 517/*
520 * Initialize all reports 518 * Initialize all reports
@@ -548,7 +546,6 @@ void usbhid_init_reports(struct hid_device *hid)
548} 546}
549 547
550#define USB_VENDOR_ID_GTCO 0x078c 548#define USB_VENDOR_ID_GTCO 0x078c
551#define USB_VENDOR_ID_GTCO_IPANEL_2 0x5543
552#define USB_DEVICE_ID_GTCO_90 0x0090 549#define USB_DEVICE_ID_GTCO_90 0x0090
553#define USB_DEVICE_ID_GTCO_100 0x0100 550#define USB_DEVICE_ID_GTCO_100 0x0100
554#define USB_DEVICE_ID_GTCO_101 0x0101 551#define USB_DEVICE_ID_GTCO_101 0x0101
@@ -594,8 +591,6 @@ void usbhid_init_reports(struct hid_device *hid)
594#define USB_DEVICE_ID_GTCO_1004 0x1004 591#define USB_DEVICE_ID_GTCO_1004 0x1004
595#define USB_DEVICE_ID_GTCO_1005 0x1005 592#define USB_DEVICE_ID_GTCO_1005 0x1005
596#define USB_DEVICE_ID_GTCO_1006 0x1006 593#define USB_DEVICE_ID_GTCO_1006 0x1006
597#define USB_DEVICE_ID_GTCO_8 0x0008
598#define USB_DEVICE_ID_GTCO_d 0x000d
599 594
600#define USB_VENDOR_ID_WACOM 0x056a 595#define USB_VENDOR_ID_WACOM 0x056a
601 596
@@ -691,10 +686,8 @@ void usbhid_init_reports(struct hid_device *hid)
691#define USB_DEVICE_ID_SMARTJOY_DUAL_PLUS 0x8802 686#define USB_DEVICE_ID_SMARTJOY_DUAL_PLUS 0x8802
692 687
693#define USB_VENDOR_ID_CODEMERCS 0x07c0 688#define USB_VENDOR_ID_CODEMERCS 0x07c0
694#define USB_DEVICE_ID_CODEMERCS_IOW40 0x1500 689#define USB_DEVICE_ID_CODEMERCS_IOW_FIRST 0x1500
695#define USB_DEVICE_ID_CODEMERCS_IOW24 0x1501 690#define USB_DEVICE_ID_CODEMERCS_IOW_LAST 0x15ff
696#define USB_DEVICE_ID_CODEMERCS_IOW48 0x1502
697#define USB_DEVICE_ID_CODEMERCS_IOW28 0x1503
698 691
699#define USB_VENDOR_ID_DELORME 0x1163 692#define USB_VENDOR_ID_DELORME 0x1163
700#define USB_DEVICE_ID_DELORME_EARTHMATE 0x0100 693#define USB_DEVICE_ID_DELORME_EARTHMATE 0x0100
@@ -760,6 +753,8 @@ void usbhid_init_reports(struct hid_device *hid)
760 753
761#define USB_VENDOR_ID_LOGITECH 0x046d 754#define USB_VENDOR_ID_LOGITECH 0x046d
762#define USB_DEVICE_ID_LOGITECH_USB_RECEIVER 0xc101 755#define USB_DEVICE_ID_LOGITECH_USB_RECEIVER 0xc101
756#define USB_DEVICE_ID_LOGITECH_USB_RECEIVER_2 0xc517
757#define USB_DEVICE_ID_DINOVO_EDGE 0xc714
763 758
764#define USB_VENDOR_ID_IMATION 0x0718 759#define USB_VENDOR_ID_IMATION 0x0718
765#define USB_DEVICE_ID_DISC_STAKKA 0xd000 760#define USB_DEVICE_ID_DISC_STAKKA 0xd000
@@ -780,6 +775,8 @@ static const struct hid_blacklist {
780 unsigned quirks; 775 unsigned quirks;
781} hid_blacklist[] = { 776} hid_blacklist[] = {
782 777
778 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE, HID_QUIRK_DUPLICATE_USAGES },
779
783 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01, HID_QUIRK_IGNORE }, 780 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01, HID_QUIRK_IGNORE },
784 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10, HID_QUIRK_IGNORE }, 781 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10, HID_QUIRK_IGNORE },
785 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20, HID_QUIRK_IGNORE }, 782 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20, HID_QUIRK_IGNORE },
@@ -790,10 +787,6 @@ static const struct hid_blacklist {
790 { USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1, HID_QUIRK_IGNORE }, 787 { USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1, HID_QUIRK_IGNORE },
791 { USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232, HID_QUIRK_IGNORE }, 788 { USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232, HID_QUIRK_IGNORE },
792 { USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD, HID_QUIRK_IGNORE }, 789 { USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD, HID_QUIRK_IGNORE },
793 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW40, HID_QUIRK_IGNORE },
794 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW24, HID_QUIRK_IGNORE },
795 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW48, HID_QUIRK_IGNORE },
796 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW28, HID_QUIRK_IGNORE },
797 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM, HID_QUIRK_IGNORE }, 790 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM, HID_QUIRK_IGNORE },
798 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE, HID_QUIRK_IGNORE }, 791 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE, HID_QUIRK_IGNORE },
799 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE, HID_QUIRK_IGNORE }, 792 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE, HID_QUIRK_IGNORE },
@@ -854,8 +847,6 @@ static const struct hid_blacklist {
854 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE }, 847 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE },
855 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE }, 848 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE },
856 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE }, 849 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE },
857 { USB_VENDOR_ID_GTCO_IPANEL_2, USB_DEVICE_ID_GTCO_8, HID_QUIRK_IGNORE },
858 { USB_VENDOR_ID_GTCO_IPANEL_2, USB_DEVICE_ID_GTCO_d, HID_QUIRK_IGNORE },
859 { USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA, HID_QUIRK_IGNORE }, 850 { USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA, HID_QUIRK_IGNORE },
860 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE }, 851 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE },
861 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE }, 852 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE },
@@ -948,11 +939,14 @@ static const struct hid_blacklist {
948 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET }, 939 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET },
949 940
950 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_USB_RECEIVER, HID_QUIRK_BAD_RELATIVE_KEYS }, 941 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_USB_RECEIVER, HID_QUIRK_BAD_RELATIVE_KEYS },
942 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_USB_RECEIVER_2, HID_QUIRK_LOGITECH_S510_DESCRIPTOR },
951 943
952 { USB_VENDOR_ID_PANTHERLORD, USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK, HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS }, 944 { USB_VENDOR_ID_PANTHERLORD, USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK, HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS },
953 945
954 { USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER, HID_QUIRK_SONY_PS3_CONTROLLER }, 946 { USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER, HID_QUIRK_SONY_PS3_CONTROLLER },
955 947
948 { USB_VENDOR_ID_CIDC, 0x0103, HID_QUIRK_IGNORE },
949
956 { 0, 0 } 950 { 0, 0 }
957}; 951};
958 952
@@ -1043,6 +1037,22 @@ static void hid_fixup_sony_ps3_controller(struct usb_device *dev, int ifnum)
1043 kfree(buf); 1037 kfree(buf);
1044} 1038}
1045 1039
1040/*
1041 * Logitech S510 keyboard sends in report #3 keys which are far
1042 * above the logical maximum described in descriptor. This extends
1043 * the original value of 0x28c of logical maximum to 0x104d
1044 */
1045static void hid_fixup_s510_descriptor(unsigned char *rdesc, int rsize)
1046{
1047 if (rsize >= 90 && rdesc[83] == 0x26
1048 && rdesc[84] == 0x8c
1049 && rdesc[85] == 0x02) {
1050 info("Fixing up Logitech S510 report descriptor");
1051 rdesc[84] = rdesc[89] = 0x4d;
1052 rdesc[85] = rdesc[90] = 0x10;
1053 }
1054}
1055
1046static struct hid_device *usb_hid_configure(struct usb_interface *intf) 1056static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1047{ 1057{
1048 struct usb_host_interface *interface = intf->cur_altsetting; 1058 struct usb_host_interface *interface = intf->cur_altsetting;
@@ -1054,9 +1064,14 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1054 int n, len, insize = 0; 1064 int n, len, insize = 0;
1055 struct usbhid_device *usbhid; 1065 struct usbhid_device *usbhid;
1056 1066
1057 /* Ignore all Wacom devices */ 1067 /* Ignore all Wacom devices */
1058 if (le16_to_cpu(dev->descriptor.idVendor) == USB_VENDOR_ID_WACOM) 1068 if (le16_to_cpu(dev->descriptor.idVendor) == USB_VENDOR_ID_WACOM)
1059 return NULL; 1069 return NULL;
1070 /* ignore all Code Mercenaries IOWarrior devices */
1071 if (le16_to_cpu(dev->descriptor.idVendor) == USB_VENDOR_ID_CODEMERCS)
1072 if (le16_to_cpu(dev->descriptor.idProduct) >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
1073 le16_to_cpu(dev->descriptor.idProduct) <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
1074 return NULL;
1060 1075
1061 for (n = 0; hid_blacklist[n].idVendor; n++) 1076 for (n = 0; hid_blacklist[n].idVendor; n++)
1062 if ((hid_blacklist[n].idVendor == le16_to_cpu(dev->descriptor.idVendor)) && 1077 if ((hid_blacklist[n].idVendor == le16_to_cpu(dev->descriptor.idVendor)) &&
@@ -1111,7 +1126,10 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1111 if ((quirks & HID_QUIRK_CYMOTION)) 1126 if ((quirks & HID_QUIRK_CYMOTION))
1112 hid_fixup_cymotion_descriptor(rdesc, rsize); 1127 hid_fixup_cymotion_descriptor(rdesc, rsize);
1113 1128
1114#ifdef DEBUG_DATA 1129 if (quirks & HID_QUIRK_LOGITECH_S510_DESCRIPTOR)
1130 hid_fixup_s510_descriptor(rdesc, rsize);
1131
1132#ifdef CONFIG_HID_DEBUG
1115 printk(KERN_DEBUG __FILE__ ": report descriptor (size %u, read %d) = ", rsize, n); 1133 printk(KERN_DEBUG __FILE__ ": report descriptor (size %u, read %d) = ", rsize, n);
1116 for (n = 0; n < rsize; n++) 1134 for (n = 0; n < rsize; n++)
1117 printk(" %02x", (unsigned char) rdesc[n]); 1135 printk(" %02x", (unsigned char) rdesc[n]);
@@ -1227,8 +1245,8 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1227 le16_to_cpu(dev->descriptor.idProduct)); 1245 le16_to_cpu(dev->descriptor.idProduct));
1228 1246
1229 hid->bus = BUS_USB; 1247 hid->bus = BUS_USB;
1230 hid->vendor = dev->descriptor.idVendor; 1248 hid->vendor = le16_to_cpu(dev->descriptor.idVendor);
1231 hid->product = dev->descriptor.idProduct; 1249 hid->product = le16_to_cpu(dev->descriptor.idProduct);
1232 1250
1233 usb_make_path(dev, hid->phys, sizeof(hid->phys)); 1251 usb_make_path(dev, hid->phys, sizeof(hid->phys));
1234 strlcat(hid->phys, "/input", sizeof(hid->phys)); 1252 strlcat(hid->phys, "/input", sizeof(hid->phys));
diff --git a/drivers/usb/input/hid-ff.c b/drivers/usb/input/hid-ff.c
index bc7f8e6f8c..e431faaa6a 100644
--- a/drivers/usb/input/hid-ff.c
+++ b/drivers/usb/input/hid-ff.c
@@ -54,9 +54,10 @@ struct hid_ff_initializer {
54static struct hid_ff_initializer inits[] = { 54static struct hid_ff_initializer inits[] = {
55#ifdef CONFIG_LOGITECH_FF 55#ifdef CONFIG_LOGITECH_FF
56 { 0x46d, 0xc211, hid_lgff_init }, /* Logitech Cordless rumble pad */ 56 { 0x46d, 0xc211, hid_lgff_init }, /* Logitech Cordless rumble pad */
57 { 0x46d, 0xc219, hid_lgff_init }, /* Logitech Cordless rumble pad 2 */
57 { 0x46d, 0xc283, hid_lgff_init }, /* Logitech Wingman Force 3d */ 58 { 0x46d, 0xc283, hid_lgff_init }, /* Logitech Wingman Force 3d */
59 { 0x46d, 0xc294, hid_lgff_init }, /* Logitech Formula Force EX */
58 { 0x46d, 0xc295, hid_lgff_init }, /* Logitech MOMO force wheel */ 60 { 0x46d, 0xc295, hid_lgff_init }, /* Logitech MOMO force wheel */
59 { 0x46d, 0xc219, hid_lgff_init }, /* Logitech Cordless rumble pad 2 */
60 { 0x46d, 0xca03, hid_lgff_init }, /* Logitech MOMO force wheel */ 61 { 0x46d, 0xca03, hid_lgff_init }, /* Logitech MOMO force wheel */
61#endif 62#endif
62#ifdef CONFIG_PANTHERLORD_FF 63#ifdef CONFIG_PANTHERLORD_FF
diff --git a/drivers/usb/input/hid-lgff.c b/drivers/usb/input/hid-lgff.c
index 4df0968f85..e6f3af3e66 100644
--- a/drivers/usb/input/hid-lgff.c
+++ b/drivers/usb/input/hid-lgff.c
@@ -52,8 +52,9 @@ static const struct dev_type devices[] = {
52 { 0x046d, 0xc211, ff_rumble }, 52 { 0x046d, 0xc211, ff_rumble },
53 { 0x046d, 0xc219, ff_rumble }, 53 { 0x046d, 0xc219, ff_rumble },
54 { 0x046d, 0xc283, ff_joystick }, 54 { 0x046d, 0xc283, ff_joystick },
55 { 0x046d, 0xc294, ff_joystick },
56 { 0x046d, 0xc295, ff_joystick },
55 { 0x046d, 0xca03, ff_joystick }, 57 { 0x046d, 0xca03, ff_joystick },
56 { 0x0000, 0x0000, ff_joystick }
57}; 58};
58 59
59static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *effect) 60static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
@@ -105,8 +106,9 @@ int hid_lgff_init(struct hid_device* hid)
105 struct input_dev *dev = hidinput->input; 106 struct input_dev *dev = hidinput->input;
106 struct hid_report *report; 107 struct hid_report *report;
107 struct hid_field *field; 108 struct hid_field *field;
109 const signed short *ff_bits = ff_joystick;
108 int error; 110 int error;
109 int i, j; 111 int i;
110 112
111 /* Find the report to use */ 113 /* Find the report to use */
112 if (list_empty(report_list)) { 114 if (list_empty(report_list)) {
@@ -130,12 +132,14 @@ int hid_lgff_init(struct hid_device* hid)
130 for (i = 0; i < ARRAY_SIZE(devices); i++) { 132 for (i = 0; i < ARRAY_SIZE(devices); i++) {
131 if (dev->id.vendor == devices[i].idVendor && 133 if (dev->id.vendor == devices[i].idVendor &&
132 dev->id.product == devices[i].idProduct) { 134 dev->id.product == devices[i].idProduct) {
133 for (j = 0; devices[i].ff[j] >= 0; j++) 135 ff_bits = devices[i].ff;
134 set_bit(devices[i].ff[j], dev->ffbit);
135 break; 136 break;
136 } 137 }
137 } 138 }
138 139
140 for (i = 0; ff_bits[i] >= 0; i++)
141 set_bit(ff_bits[i], dev->ffbit);
142
139 error = input_ff_create_memless(dev, NULL, hid_lgff_play); 143 error = input_ff_create_memless(dev, NULL, hid_lgff_play);
140 if (error) 144 if (error)
141 return error; 145 return error;
diff --git a/drivers/usb/input/usbkbd.c b/drivers/usb/input/usbkbd.c
index 8505824848..3749f4a235 100644
--- a/drivers/usb/input/usbkbd.c
+++ b/drivers/usb/input/usbkbd.c
@@ -31,6 +31,7 @@
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/usb/input.h> 33#include <linux/usb/input.h>
34#include <linux/hid.h>
34 35
35/* 36/*
36 * Version Information 37 * Version Information
@@ -330,7 +331,8 @@ static void usb_kbd_disconnect(struct usb_interface *intf)
330} 331}
331 332
332static struct usb_device_id usb_kbd_id_table [] = { 333static struct usb_device_id usb_kbd_id_table [] = {
333 { USB_INTERFACE_INFO(3, 1, 1) }, 334 { USB_INTERFACE_INFO(USB_INTERFACE_CLASS_HID, USB_INTERFACE_SUBCLASS_BOOT,
335 USB_INTERFACE_PROTOCOL_KEYBOARD) },
334 { } /* Terminating entry */ 336 { } /* Terminating entry */
335}; 337};
336 338
diff --git a/drivers/usb/input/usbmouse.c b/drivers/usb/input/usbmouse.c
index 64a33e420c..692fd60877 100644
--- a/drivers/usb/input/usbmouse.c
+++ b/drivers/usb/input/usbmouse.c
@@ -31,6 +31,7 @@
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/usb/input.h> 33#include <linux/usb/input.h>
34#include <linux/hid.h>
34 35
35/* 36/*
36 * Version Information 37 * Version Information
@@ -213,7 +214,8 @@ static void usb_mouse_disconnect(struct usb_interface *intf)
213} 214}
214 215
215static struct usb_device_id usb_mouse_id_table [] = { 216static struct usb_device_id usb_mouse_id_table [] = {
216 { USB_INTERFACE_INFO(3, 1, 2) }, 217 { USB_INTERFACE_INFO(USB_INTERFACE_CLASS_HID, USB_INTERFACE_SUBCLASS_BOOT,
218 USB_INTERFACE_PROTOCOL_MOUSE) },
217 { } /* Terminating entry */ 219 { } /* Terminating entry */
218}; 220};
219 221
diff --git a/drivers/usb/input/wacom_wac.c b/drivers/usb/input/wacom_wac.c
index 4142e36730..4f3e9bc717 100644
--- a/drivers/usb/input/wacom_wac.c
+++ b/drivers/usb/input/wacom_wac.c
@@ -163,7 +163,7 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
163 } 163 }
164 164
165 id = STYLUS_DEVICE_ID; 165 id = STYLUS_DEVICE_ID;
166 if (data[1] & 0x10) { /* in prox */ 166 if (data[1] & 0x80) { /* in prox */
167 167
168 switch ((data[1] >> 5) & 3) { 168 switch ((data[1] >> 5) & 3) {
169 169
@@ -196,9 +196,6 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
196 wacom_report_abs(wcombo, ABS_DISTANCE, data[7] & 0x3f); 196 wacom_report_abs(wcombo, ABS_DISTANCE, data[7] & 0x3f);
197 break; 197 break;
198 } 198 }
199 }
200
201 if (data[1] & 0x90) {
202 x = wacom_le16_to_cpu(&data[2]); 199 x = wacom_le16_to_cpu(&data[2]);
203 y = wacom_le16_to_cpu(&data[4]); 200 y = wacom_le16_to_cpu(&data[4]);
204 wacom_report_abs(wcombo, ABS_X, x); 201 wacom_report_abs(wcombo, ABS_X, x);
@@ -210,19 +207,28 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
210 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x04); 207 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x04);
211 } 208 }
212 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */ 209 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */
213 }
214 else
215 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */
216
217 if (data[1] & 0x10) /* only report prox-in when in area */
218 wacom_report_key(wcombo, wacom->tool[0], 1); 210 wacom_report_key(wcombo, wacom->tool[0], 1);
219 if (!(data[1] & 0x90)) /* report prox-out when physically out */ 211 } else if (!(data[1] & 0x90)) {
212 wacom_report_abs(wcombo, ABS_X, 0);
213 wacom_report_abs(wcombo, ABS_Y, 0);
214 if (wacom->tool[0] == BTN_TOOL_MOUSE) {
215 wacom_report_key(wcombo, BTN_LEFT, 0);
216 wacom_report_key(wcombo, BTN_RIGHT, 0);
217 wacom_report_abs(wcombo, ABS_DISTANCE, 0);
218 } else {
219 wacom_report_abs(wcombo, ABS_PRESSURE, 0);
220 wacom_report_key(wcombo, BTN_TOUCH, 0);
221 wacom_report_key(wcombo, BTN_STYLUS, 0);
222 wacom_report_key(wcombo, BTN_STYLUS2, 0);
223 }
224 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */
220 wacom_report_key(wcombo, wacom->tool[0], 0); 225 wacom_report_key(wcombo, wacom->tool[0], 0);
221 wacom_input_sync(wcombo); 226 }
222 227
223 /* send pad data */ 228 /* send pad data */
224 if (wacom->features->type == WACOM_G4) { 229 if (wacom->features->type == WACOM_G4) {
225 if ( (wacom->serial[1] & 0xc0) != (data[7] & 0xf8) ) { 230 if (data[7] & 0xf8) {
231 wacom_input_sync(wcombo); /* sync last event */
226 wacom->id[1] = 1; 232 wacom->id[1] = 1;
227 wacom->serial[1] = (data[7] & 0xf8); 233 wacom->serial[1] = (data[7] & 0xf8);
228 wacom_report_key(wcombo, BTN_0, (data[7] & 0x40)); 234 wacom_report_key(wcombo, BTN_0, (data[7] & 0x40));
@@ -230,10 +236,15 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
230 rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3); 236 rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
231 wacom_report_rel(wcombo, REL_WHEEL, rw); 237 wacom_report_rel(wcombo, REL_WHEEL, rw);
232 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0); 238 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0);
239 wacom_report_abs(wcombo, ABS_MISC, PAD_DEVICE_ID);
233 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0); 240 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
234 } else if (wacom->id[1]) { 241 } else if (wacom->id[1]) {
242 wacom_input_sync(wcombo); /* sync last event */
235 wacom->id[1] = 0; 243 wacom->id[1] = 0;
244 wacom_report_key(wcombo, BTN_0, (data[7] & 0x40));
245 wacom_report_key(wcombo, BTN_4, (data[7] & 0x80));
236 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0); 246 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0);
247 wacom_report_abs(wcombo, ABS_MISC, 0);
237 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0); 248 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
238 } 249 }
239 } 250 }
@@ -304,28 +315,35 @@ static int wacom_intuos_inout(struct wacom_wac *wacom, void *wcombo)
304 default: /* Unknown tool */ 315 default: /* Unknown tool */
305 wacom->tool[idx] = BTN_TOOL_PEN; 316 wacom->tool[idx] = BTN_TOOL_PEN;
306 } 317 }
307 /* only large I3 support Lens Cursor */
308 if(!((wacom->tool[idx] == BTN_TOOL_LENS)
309 && ((wacom->features->type == INTUOS3)
310 || (wacom->features->type == INTUOS3S)))) {
311 wacom_report_abs(wcombo, ABS_MISC, wacom->id[idx]); /* report tool id */
312 wacom_report_key(wcombo, wacom->tool[idx], 1);
313 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
314 return 2;
315 }
316 return 1; 318 return 1;
317 } 319 }
318 320
319 /* Exit report */ 321 /* Exit report */
320 if ((data[1] & 0xfe) == 0x80) { 322 if ((data[1] & 0xfe) == 0x80) {
321 if(!((wacom->tool[idx] == BTN_TOOL_LENS) 323 wacom_report_abs(wcombo, ABS_X, 0);
322 && ((wacom->features->type == INTUOS3) 324 wacom_report_abs(wcombo, ABS_Y, 0);
323 || (wacom->features->type == INTUOS3S)))) { 325 wacom_report_abs(wcombo, ABS_DISTANCE, 0);
324 wacom_report_key(wcombo, wacom->tool[idx], 0); 326 if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
325 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */ 327 wacom_report_key(wcombo, BTN_LEFT, 0);
326 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]); 328 wacom_report_key(wcombo, BTN_MIDDLE, 0);
327 return 2; 329 wacom_report_key(wcombo, BTN_RIGHT, 0);
330 wacom_report_key(wcombo, BTN_SIDE, 0);
331 wacom_report_key(wcombo, BTN_EXTRA, 0);
332 wacom_report_abs(wcombo, ABS_THROTTLE, 0);
333 wacom_report_abs(wcombo, ABS_RZ, 0);
334 } else {
335 wacom_report_abs(wcombo, ABS_PRESSURE, 0);
336 wacom_report_abs(wcombo, ABS_TILT_X, 0);
337 wacom_report_abs(wcombo, ABS_TILT_Y, 0);
338 wacom_report_key(wcombo, BTN_STYLUS, 0);
339 wacom_report_key(wcombo, BTN_STYLUS2, 0);
340 wacom_report_key(wcombo, BTN_TOUCH, 0);
341 wacom_report_abs(wcombo, ABS_WHEEL, 0);
328 } 342 }
343 wacom_report_key(wcombo, wacom->tool[idx], 0);
344 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */
345 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
346 return 2;
329 } 347 }
330 return 0; 348 return 0;
331} 349}
@@ -394,6 +412,7 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
394 wacom_report_key(wcombo, wacom->tool[1], 1); 412 wacom_report_key(wcombo, wacom->tool[1], 1);
395 else 413 else
396 wacom_report_key(wcombo, wacom->tool[1], 0); 414 wacom_report_key(wcombo, wacom->tool[1], 0);
415 wacom_report_abs(wcombo, ABS_MISC, PAD_DEVICE_ID);
397 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xffffffff); 416 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xffffffff);
398 return 1; 417 return 1;
399 } 418 }
@@ -403,6 +422,12 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
403 if (result) 422 if (result)
404 return result-1; 423 return result-1;
405 424
425 /* Only large I3 and I1 & I2 support Lense Cursor */
426 if((wacom->tool[idx] == BTN_TOOL_LENS)
427 && ((wacom->features->type == INTUOS3)
428 || (wacom->features->type == INTUOS3S)))
429 return 0;
430
406 /* Cintiq doesn't send data when RDY bit isn't set */ 431 /* Cintiq doesn't send data when RDY bit isn't set */
407 if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40)) 432 if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40))
408 return 0; 433 return 0;
@@ -554,11 +579,11 @@ static struct wacom_features wacom_features[] = {
554 { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 63, GRAPHIRE }, 579 { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 63, GRAPHIRE },
555 { "Wacom Volito2 2x3", 8, 3248, 2320, 511, 63, GRAPHIRE }, 580 { "Wacom Volito2 2x3", 8, 3248, 2320, 511, 63, GRAPHIRE },
556 { "Wacom PenPartner2", 8, 3250, 2320, 255, 63, GRAPHIRE }, 581 { "Wacom PenPartner2", 8, 3250, 2320, 255, 63, GRAPHIRE },
557 { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 63, INTUOS }, 582 { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 31, INTUOS },
558 { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 63, INTUOS }, 583 { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 31, INTUOS },
559 { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 63, INTUOS }, 584 { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 31, INTUOS },
560 { "Wacom Intuos 12x12", 10, 30480, 31680, 1023, 63, INTUOS }, 585 { "Wacom Intuos 12x12", 10, 30480, 31680, 1023, 31, INTUOS },
561 { "Wacom Intuos 12x18", 10, 45720, 31680, 1023, 63, INTUOS }, 586 { "Wacom Intuos 12x18", 10, 45720, 31680, 1023, 31, INTUOS },
562 { "Wacom PL400", 8, 5408, 4056, 255, 0, PL }, 587 { "Wacom PL400", 8, 5408, 4056, 255, 0, PL },
563 { "Wacom PL500", 8, 6144, 4608, 255, 0, PL }, 588 { "Wacom PL500", 8, 6144, 4608, 255, 0, PL },
564 { "Wacom PL600", 8, 6126, 4604, 255, 0, PL }, 589 { "Wacom PL600", 8, 6126, 4604, 255, 0, PL },
@@ -571,11 +596,11 @@ static struct wacom_features wacom_features[] = {
571 { "Wacom DTF521", 8, 6282, 4762, 511, 0, PL }, 596 { "Wacom DTF521", 8, 6282, 4762, 511, 0, PL },
572 { "Wacom DTF720", 8, 6858, 5506, 511, 0, PL }, 597 { "Wacom DTF720", 8, 6858, 5506, 511, 0, PL },
573 { "Wacom Cintiq Partner",8, 20480, 15360, 511, 0, PTU }, 598 { "Wacom Cintiq Partner",8, 20480, 15360, 511, 0, PTU },
574 { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 63, INTUOS }, 599 { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 31, INTUOS },
575 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 63, INTUOS }, 600 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 31, INTUOS },
576 { "Wacom Intuos2 9x12", 10, 30480, 24060, 1023, 63, INTUOS }, 601 { "Wacom Intuos2 9x12", 10, 30480, 24060, 1023, 31, INTUOS },
577 { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 63, INTUOS }, 602 { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 31, INTUOS },
578 { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 63, INTUOS }, 603 { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 31, INTUOS },
579 { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 63, INTUOS3S }, 604 { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 63, INTUOS3S },
580 { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 63, INTUOS3 }, 605 { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 63, INTUOS3 },
581 { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 63, INTUOS3 }, 606 { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 63, INTUOS3 },
@@ -584,7 +609,7 @@ static struct wacom_features wacom_features[] = {
584 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 63, INTUOS3 }, 609 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 63, INTUOS3 },
585 { "Wacom Intuos3 4x6", 10, 31496, 19685, 1023, 63, INTUOS3S }, 610 { "Wacom Intuos3 4x6", 10, 31496, 19685, 1023, 63, INTUOS3S },
586 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 63, CINTIQ }, 611 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 63, CINTIQ },
587 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 63, INTUOS }, 612 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 31, INTUOS },
588 { } 613 { }
589}; 614};
590 615
diff --git a/drivers/usb/input/wacom_wac.h b/drivers/usb/input/wacom_wac.h
index a1d9ce0079..a230222872 100644
--- a/drivers/usb/input/wacom_wac.h
+++ b/drivers/usb/input/wacom_wac.h
@@ -12,6 +12,7 @@
12#define STYLUS_DEVICE_ID 0x02 12#define STYLUS_DEVICE_ID 0x02
13#define CURSOR_DEVICE_ID 0x06 13#define CURSOR_DEVICE_ID 0x06
14#define ERASER_DEVICE_ID 0x0A 14#define ERASER_DEVICE_ID 0x0A
15#define PAD_DEVICE_ID 0x0F
15 16
16enum { 17enum {
17 PENPARTNER = 0, 18 PENPARTNER = 0,
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index a74bf8617e..9c7eb6144d 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -88,6 +88,17 @@ config USB_LCD
88 To compile this driver as a module, choose M here: the 88 To compile this driver as a module, choose M here: the
89 module will be called usblcd. 89 module will be called usblcd.
90 90
91config USB_BERRY_CHARGE
92 tristate "USB BlackBerry recharge support"
93 depends on USB
94 help
95 Say Y here if you want to connect a BlackBerry device to your
96 computer's USB port and have it automatically switch to "recharge"
97 mode.
98
99 To compile this driver as a module, choose M here: the
100 module will be called berry_charge.
101
91config USB_LED 102config USB_LED
92 tristate "USB LED driver support" 103 tristate "USB LED driver support"
93 depends on USB 104 depends on USB
@@ -233,6 +244,20 @@ config USB_TRANCEVIBRATOR
233 To compile this driver as a module, choose M here: the 244 To compile this driver as a module, choose M here: the
234 module will be called trancevibrator. 245 module will be called trancevibrator.
235 246
247config USB_IOWARRIOR
248 tristate "IO Warrior driver support"
249 depends on USB
250 help
251 Say Y here if you want to support the IO Warrior devices from Code
252 Mercenaries. This includes support for the following devices:
253 IO Warrior 40
254 IO Warrior 24
255 IO Warrior 56
256 IO Warrior 24 Power Vampire
257
258 To compile this driver as a module, choose M here: the
259 module will be called iowarrior.
260
236config USB_TEST 261config USB_TEST
237 tristate "USB testing driver (DEVELOPMENT)" 262 tristate "USB testing driver (DEVELOPMENT)"
238 depends on USB && USB_DEVICEFS && EXPERIMENTAL 263 depends on USB && USB_DEVICEFS && EXPERIMENTAL
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index 2cba07d319..b68e6b774f 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -6,12 +6,14 @@
6obj-$(CONFIG_USB_ADUTUX) += adutux.o 6obj-$(CONFIG_USB_ADUTUX) += adutux.o
7obj-$(CONFIG_USB_APPLEDISPLAY) += appledisplay.o 7obj-$(CONFIG_USB_APPLEDISPLAY) += appledisplay.o
8obj-$(CONFIG_USB_AUERSWALD) += auerswald.o 8obj-$(CONFIG_USB_AUERSWALD) += auerswald.o
9obj-$(CONFIG_USB_BERRY_CHARGE) += berry_charge.o
9obj-$(CONFIG_USB_CYPRESS_CY7C63)+= cypress_cy7c63.o 10obj-$(CONFIG_USB_CYPRESS_CY7C63)+= cypress_cy7c63.o
10obj-$(CONFIG_USB_CYTHERM) += cytherm.o 11obj-$(CONFIG_USB_CYTHERM) += cytherm.o
11obj-$(CONFIG_USB_EMI26) += emi26.o 12obj-$(CONFIG_USB_EMI26) += emi26.o
12obj-$(CONFIG_USB_EMI62) += emi62.o 13obj-$(CONFIG_USB_EMI62) += emi62.o
13obj-$(CONFIG_USB_FTDI_ELAN) += ftdi-elan.o 14obj-$(CONFIG_USB_FTDI_ELAN) += ftdi-elan.o
14obj-$(CONFIG_USB_IDMOUSE) += idmouse.o 15obj-$(CONFIG_USB_IDMOUSE) += idmouse.o
16obj-$(CONFIG_USB_IOWARRIOR) += iowarrior.o
15obj-$(CONFIG_USB_LCD) += usblcd.o 17obj-$(CONFIG_USB_LCD) += usblcd.o
16obj-$(CONFIG_USB_LD) += ldusb.o 18obj-$(CONFIG_USB_LD) += ldusb.o
17obj-$(CONFIG_USB_LED) += usbled.o 19obj-$(CONFIG_USB_LED) += usbled.o
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
index e573c8ba97..cf70c16f0e 100644
--- a/drivers/usb/misc/appledisplay.c
+++ b/drivers/usb/misc/appledisplay.c
@@ -141,7 +141,7 @@ static int appledisplay_bl_update_status(struct backlight_device *bd)
141 int retval; 141 int retval;
142 142
143 pdata->msgdata[0] = 0x10; 143 pdata->msgdata[0] = 0x10;
144 pdata->msgdata[1] = bd->props->brightness; 144 pdata->msgdata[1] = bd->props.brightness;
145 145
146 retval = usb_control_msg( 146 retval = usb_control_msg(
147 pdata->udev, 147 pdata->udev,
@@ -177,11 +177,9 @@ static int appledisplay_bl_get_brightness(struct backlight_device *bd)
177 return pdata->msgdata[1]; 177 return pdata->msgdata[1];
178} 178}
179 179
180static struct backlight_properties appledisplay_bl_data = { 180static struct backlight_ops appledisplay_bl_data = {
181 .owner = THIS_MODULE,
182 .get_brightness = appledisplay_bl_get_brightness, 181 .get_brightness = appledisplay_bl_get_brightness,
183 .update_status = appledisplay_bl_update_status, 182 .update_status = appledisplay_bl_update_status,
184 .max_brightness = 0xFF
185}; 183};
186 184
187static void appledisplay_work(struct work_struct *work) 185static void appledisplay_work(struct work_struct *work)
@@ -190,11 +188,9 @@ static void appledisplay_work(struct work_struct *work)
190 container_of(work, struct appledisplay, work.work); 188 container_of(work, struct appledisplay, work.work);
191 int retval; 189 int retval;
192 190
193 up(&pdata->bd->sem);
194 retval = appledisplay_bl_get_brightness(pdata->bd); 191 retval = appledisplay_bl_get_brightness(pdata->bd);
195 if (retval >= 0) 192 if (retval >= 0)
196 pdata->bd->props->brightness = retval; 193 pdata->bd->props.brightness = retval;
197 down(&pdata->bd->sem);
198 194
199 /* Poll again in about 125ms if there's still a button pressed */ 195 /* Poll again in about 125ms if there's still a button pressed */
200 if (pdata->button_pressed) 196 if (pdata->button_pressed)
@@ -288,10 +284,10 @@ static int appledisplay_probe(struct usb_interface *iface,
288 goto error; 284 goto error;
289 } 285 }
290 286
287 pdata->bd->props.max_brightness = 0xff;
288
291 /* Try to get brightness */ 289 /* Try to get brightness */
292 up(&pdata->bd->sem);
293 brightness = appledisplay_bl_get_brightness(pdata->bd); 290 brightness = appledisplay_bl_get_brightness(pdata->bd);
294 down(&pdata->bd->sem);
295 291
296 if (brightness < 0) { 292 if (brightness < 0) {
297 retval = brightness; 293 retval = brightness;
@@ -300,9 +296,7 @@ static int appledisplay_probe(struct usb_interface *iface,
300 } 296 }
301 297
302 /* Set brightness in backlight device */ 298 /* Set brightness in backlight device */
303 up(&pdata->bd->sem); 299 pdata->bd->props.brightness = brightness;
304 pdata->bd->props->brightness = brightness;
305 down(&pdata->bd->sem);
306 300
307 /* save our data pointer in the interface device */ 301 /* save our data pointer in the interface device */
308 usb_set_intfdata(iface, pdata); 302 usb_set_intfdata(iface, pdata);
diff --git a/drivers/usb/misc/berry_charge.c b/drivers/usb/misc/berry_charge.c
new file mode 100644
index 0000000000..60893c6c82
--- /dev/null
+++ b/drivers/usb/misc/berry_charge.c
@@ -0,0 +1,140 @@
1/*
2 * USB BlackBerry charging module
3 *
4 * Copyright (C) 2007 Greg Kroah-Hartman <gregkh@suse.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 * Information on how to switch configs was taken by the bcharge.cc file
11 * created by the barry.sf.net project.
12 *
13 * bcharge.cc has the following copyright:
14 * Copyright (C) 2006, Net Direct Inc. (http://www.netdirect.ca/)
15 * and is released under the GPLv2.
16 *
17 *
18 */
19
20#include <linux/kernel.h>
21#include <linux/errno.h>
22#include <linux/init.h>
23#include <linux/slab.h>
24#include <linux/module.h>
25#include <linux/usb.h>
26
27#define RIM_VENDOR 0x0fca
28#define BLACKBERRY 0x0001
29
30static int debug;
31
32#ifdef dbg
33#undef dbg
34#endif
35#define dbg(dev, format, arg...) \
36 if (debug) \
37 dev_printk(KERN_DEBUG , dev , format , ## arg)
38
39static struct usb_device_id id_table [] = {
40 { USB_DEVICE(RIM_VENDOR, BLACKBERRY) },
41 { }, /* Terminating entry */
42};
43MODULE_DEVICE_TABLE(usb, id_table);
44
45static int magic_charge(struct usb_device *udev)
46{
47 char *dummy_buffer = kzalloc(2, GFP_KERNEL);
48 int retval;
49
50 if (!dummy_buffer)
51 return -ENOMEM;
52
53 /* send two magic commands and then set the configuration. The device
54 * will then reset itself with the new power usage and should start
55 * charging. */
56
57 /* Note, with testing, it only seems that the first message is really
58 * needed (at least for the 8700c), but to be safe, we emulate what
59 * other operating systems seem to be sending to their device. We
60 * really need to get some specs for this device to be sure about what
61 * is going on here.
62 */
63 dbg(&udev->dev, "Sending first magic command\n");
64 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
65 0xa5, 0xc0, 0, 1, dummy_buffer, 2, 100);
66 if (retval != 2) {
67 dev_err(&udev->dev, "First magic command failed: %d.\n",
68 retval);
69 return retval;
70 }
71
72 dbg(&udev->dev, "Sending first magic command\n");
73 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
74 0xa2, 0x40, 0, 1, dummy_buffer, 0, 100);
75 if (retval != 0) {
76 dev_err(&udev->dev, "Second magic command failed: %d.\n",
77 retval);
78 return retval;
79 }
80
81 dbg(&udev->dev, "Calling set_configuration\n");
82 retval = usb_driver_set_configuration(udev, 1);
83 if (retval)
84 dev_err(&udev->dev, "Set Configuration failed :%d.\n", retval);
85
86 return retval;
87}
88
89static int berry_probe(struct usb_interface *intf,
90 const struct usb_device_id *id)
91{
92 struct usb_device *udev = interface_to_usbdev(intf);
93
94 dbg(&udev->dev, "Power is set to %dmA\n",
95 udev->actconfig->desc.bMaxPower * 2);
96
97 /* check the power usage so we don't try to enable something that is
98 * already enabled */
99 if ((udev->actconfig->desc.bMaxPower * 2) == 500) {
100 dbg(&udev->dev, "device is already charging, power is "
101 "set to %dmA\n", udev->actconfig->desc.bMaxPower * 2);
102 return -ENODEV;
103 }
104
105 /* turn the power on */
106 magic_charge(udev);
107
108 /* we don't really want to bind to the device, userspace programs can
109 * handle the syncing just fine, so get outta here. */
110 return -ENODEV;
111}
112
113static void berry_disconnect(struct usb_interface *intf)
114{
115}
116
117static struct usb_driver berry_driver = {
118 .name = "berry_charge",
119 .probe = berry_probe,
120 .disconnect = berry_disconnect,
121 .id_table = id_table,
122};
123
124static int __init berry_init(void)
125{
126 return usb_register(&berry_driver);
127}
128
129static void __exit berry_exit(void)
130{
131 usb_deregister(&berry_driver);
132}
133
134module_init(berry_init);
135module_exit(berry_exit);
136
137MODULE_LICENSE("GPL");
138MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
139module_param(debug, bool, S_IRUGO | S_IWUSR);
140MODULE_PARM_DESC(debug, "Debug enabled or not");
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
new file mode 100644
index 0000000000..d69665c8de
--- /dev/null
+++ b/drivers/usb/misc/iowarrior.c
@@ -0,0 +1,925 @@
1/*
2 * Native support for the I/O-Warrior USB devices
3 *
4 * Copyright (c) 2003-2005 Code Mercenaries GmbH
5 * written by Christian Lucht <lucht@codemercs.com>
6 *
7 * based on
8
9 * usb-skeleton.c by Greg Kroah-Hartman <greg@kroah.com>
10 * brlvger.c by Stephane Dalton <sdalton@videotron.ca>
11 * and St�hane Doyon <s.doyon@videotron.ca>
12 *
13 * Released under the GPLv2.
14 */
15
16#include <linux/module.h>
17#include <linux/usb.h>
18#include <linux/init.h>
19#include <linux/slab.h>
20#include <linux/sched.h>
21#include <linux/poll.h>
22#include <linux/version.h>
23#include <linux/usb/iowarrior.h>
24
25/* Version Information */
26#define DRIVER_VERSION "v0.4.0"
27#define DRIVER_AUTHOR "Christian Lucht <lucht@codemercs.com>"
28#define DRIVER_DESC "USB IO-Warrior driver (Linux 2.6.x)"
29
30#define USB_VENDOR_ID_CODEMERCS 1984
31/* low speed iowarrior */
32#define USB_DEVICE_ID_CODEMERCS_IOW40 0x1500
33#define USB_DEVICE_ID_CODEMERCS_IOW24 0x1501
34#define USB_DEVICE_ID_CODEMERCS_IOWPV1 0x1511
35#define USB_DEVICE_ID_CODEMERCS_IOWPV2 0x1512
36/* full speed iowarrior */
37#define USB_DEVICE_ID_CODEMERCS_IOW56 0x1503
38
39/* Get a minor range for your devices from the usb maintainer */
40#ifdef CONFIG_USB_DYNAMIC_MINORS
41#define IOWARRIOR_MINOR_BASE 0
42#else
43#define IOWARRIOR_MINOR_BASE 208 // SKELETON_MINOR_BASE 192 + 16, not offical yet
44#endif
45
46/* interrupt input queue size */
47#define MAX_INTERRUPT_BUFFER 16
48/*
49 maximum number of urbs that are submitted for writes at the same time,
50 this applies to the IOWarrior56 only!
51 IOWarrior24 and IOWarrior40 use synchronous usb_control_msg calls.
52*/
53#define MAX_WRITES_IN_FLIGHT 4
54
55/* Use our own dbg macro */
56#undef dbg
57#define dbg( format, arg... ) do { if( debug ) printk( KERN_DEBUG __FILE__ ": " format "\n" , ## arg ); } while ( 0 )
58
59MODULE_AUTHOR(DRIVER_AUTHOR);
60MODULE_DESCRIPTION(DRIVER_DESC);
61MODULE_LICENSE("GPL");
62
63/* Module parameters */
64static int debug = 0;
65module_param(debug, bool, 0644);
66MODULE_PARM_DESC(debug, "debug=1 enables debugging messages");
67
68static struct usb_driver iowarrior_driver;
69
70/*--------------*/
71/* data */
72/*--------------*/
73
74/* Structure to hold all of our device specific stuff */
75struct iowarrior {
76 struct mutex mutex; /* locks this structure */
77 struct usb_device *udev; /* save off the usb device pointer */
78 struct usb_interface *interface; /* the interface for this device */
79 unsigned char minor; /* the starting minor number for this device */
80 struct usb_endpoint_descriptor *int_out_endpoint; /* endpoint for reading (needed for IOW56 only) */
81 struct usb_endpoint_descriptor *int_in_endpoint; /* endpoint for reading */
82 struct urb *int_in_urb; /* the urb for reading data */
83 unsigned char *int_in_buffer; /* buffer for data to be read */
84 unsigned char serial_number; /* to detect lost packages */
85 unsigned char *read_queue; /* size is MAX_INTERRUPT_BUFFER * packet size */
86 wait_queue_head_t read_wait;
87 wait_queue_head_t write_wait; /* wait-queue for writing to the device */
88 atomic_t write_busy; /* number of write-urbs submitted */
89 atomic_t read_idx;
90 atomic_t intr_idx;
91 spinlock_t intr_idx_lock; /* protects intr_idx */
92 atomic_t overflow_flag; /* signals an index 'rollover' */
93 int present; /* this is 1 as long as the device is connected */
94 int opened; /* this is 1 if the device is currently open */
95 char chip_serial[9]; /* the serial number string of the chip connected */
96 int report_size; /* number of bytes in a report */
97 u16 product_id;
98};
99
100/*--------------*/
101/* globals */
102/*--------------*/
103/* prevent races between open() and disconnect() */
104static DECLARE_MUTEX(disconnect_sem);
105
106/*
107 * USB spec identifies 5 second timeouts.
108 */
109#define GET_TIMEOUT 5
110#define USB_REQ_GET_REPORT 0x01
111//#if 0
112static int usb_get_report(struct usb_device *dev,
113 struct usb_host_interface *inter, unsigned char type,
114 unsigned char id, void *buf, int size)
115{
116 return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
117 USB_REQ_GET_REPORT,
118 USB_DIR_IN | USB_TYPE_CLASS |
119 USB_RECIP_INTERFACE, (type << 8) + id,
120 inter->desc.bInterfaceNumber, buf, size,
121 GET_TIMEOUT);
122}
123//#endif
124
125#define USB_REQ_SET_REPORT 0x09
126
127static int usb_set_report(struct usb_interface *intf, unsigned char type,
128 unsigned char id, void *buf, int size)
129{
130 return usb_control_msg(interface_to_usbdev(intf),
131 usb_sndctrlpipe(interface_to_usbdev(intf), 0),
132 USB_REQ_SET_REPORT,
133 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
134 (type << 8) + id,
135 intf->cur_altsetting->desc.bInterfaceNumber, buf,
136 size, 1);
137}
138
139/*---------------------*/
140/* driver registration */
141/*---------------------*/
142/* table of devices that work with this driver */
143static struct usb_device_id iowarrior_ids[] = {
144 {USB_DEVICE(USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW40)},
145 {USB_DEVICE(USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW24)},
146 {USB_DEVICE(USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOWPV1)},
147 {USB_DEVICE(USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOWPV2)},
148 {USB_DEVICE(USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW56)},
149 {} /* Terminating entry */
150};
151MODULE_DEVICE_TABLE(usb, iowarrior_ids);
152
153/*
154 * USB callback handler for reading data
155 */
156static void iowarrior_callback(struct urb *urb)
157{
158 struct iowarrior *dev = (struct iowarrior *)urb->context;
159 int intr_idx;
160 int read_idx;
161 int aux_idx;
162 int offset;
163 int status;
164
165 switch (urb->status) {
166 case 0:
167 /* success */
168 break;
169 case -ECONNRESET:
170 case -ENOENT:
171 case -ESHUTDOWN:
172 return;
173 default:
174 goto exit;
175 }
176
177 spin_lock(&dev->intr_idx_lock);
178 intr_idx = atomic_read(&dev->intr_idx);
179 /* aux_idx become previous intr_idx */
180 aux_idx = (intr_idx == 0) ? (MAX_INTERRUPT_BUFFER - 1) : (intr_idx - 1);
181 read_idx = atomic_read(&dev->read_idx);
182
183 /* queue is not empty and it's interface 0 */
184 if ((intr_idx != read_idx)
185 && (dev->interface->cur_altsetting->desc.bInterfaceNumber == 0)) {
186 /* + 1 for serial number */
187 offset = aux_idx * (dev->report_size + 1);
188 if (!memcmp
189 (dev->read_queue + offset, urb->transfer_buffer,
190 dev->report_size)) {
191 /* equal values on interface 0 will be ignored */
192 spin_unlock(&dev->intr_idx_lock);
193 goto exit;
194 }
195 }
196
197 /* aux_idx become next intr_idx */
198 aux_idx = (intr_idx == (MAX_INTERRUPT_BUFFER - 1)) ? 0 : (intr_idx + 1);
199 if (read_idx == aux_idx) {
200 /* queue full, dropping oldest input */
201 read_idx = (++read_idx == MAX_INTERRUPT_BUFFER) ? 0 : read_idx;
202 atomic_set(&dev->read_idx, read_idx);
203 atomic_set(&dev->overflow_flag, 1);
204 }
205
206 /* +1 for serial number */
207 offset = intr_idx * (dev->report_size + 1);
208 memcpy(dev->read_queue + offset, urb->transfer_buffer,
209 dev->report_size);
210 *(dev->read_queue + offset + (dev->report_size)) = dev->serial_number++;
211
212 atomic_set(&dev->intr_idx, aux_idx);
213 spin_unlock(&dev->intr_idx_lock);
214 /* tell the blocking read about the new data */
215 wake_up_interruptible(&dev->read_wait);
216
217exit:
218 status = usb_submit_urb(urb, GFP_ATOMIC);
219 if (status)
220 dev_err(&dev->interface->dev, "%s - usb_submit_urb failed with result %d",
221 __FUNCTION__, status);
222
223}
224
225/*
226 * USB Callback handler for write-ops
227 */
228static void iowarrior_write_callback(struct urb *urb)
229{
230 struct iowarrior *dev;
231 dev = (struct iowarrior *)urb->context;
232 /* sync/async unlink faults aren't errors */
233 if (urb->status &&
234 !(urb->status == -ENOENT ||
235 urb->status == -ECONNRESET || urb->status == -ESHUTDOWN)) {
236 dbg("%s - nonzero write bulk status received: %d",
237 __func__, urb->status);
238 }
239 /* free up our allocated buffer */
240 usb_buffer_free(urb->dev, urb->transfer_buffer_length,
241 urb->transfer_buffer, urb->transfer_dma);
242 /* tell a waiting writer the interrupt-out-pipe is available again */
243 atomic_dec(&dev->write_busy);
244 wake_up_interruptible(&dev->write_wait);
245}
246
247/**
248 * iowarrior_delete
249 */
250static inline void iowarrior_delete(struct iowarrior *dev)
251{
252 dbg("%s - minor %d", __func__, dev->minor);
253 kfree(dev->int_in_buffer);
254 usb_free_urb(dev->int_in_urb);
255 kfree(dev->read_queue);
256 kfree(dev);
257}
258
259/*---------------------*/
260/* fops implementation */
261/*---------------------*/
262
263static int read_index(struct iowarrior *dev)
264{
265 int intr_idx, read_idx;
266
267 read_idx = atomic_read(&dev->read_idx);
268 intr_idx = atomic_read(&dev->intr_idx);
269
270 return (read_idx == intr_idx ? -1 : read_idx);
271}
272
273/**
274 * iowarrior_read
275 */
276static ssize_t iowarrior_read(struct file *file, char __user *buffer,
277 size_t count, loff_t *ppos)
278{
279 struct iowarrior *dev;
280 int read_idx;
281 int offset;
282
283 dev = (struct iowarrior *)file->private_data;
284
285 /* verify that the device wasn't unplugged */
286 if (dev == NULL || !dev->present)
287 return -ENODEV;
288
289 dbg("%s - minor %d, count = %zd", __func__, dev->minor, count);
290
291 /* read count must be packet size (+ time stamp) */
292 if ((count != dev->report_size)
293 && (count != (dev->report_size + 1)))
294 return -EINVAL;
295
296 /* repeat until no buffer overrun in callback handler occur */
297 do {
298 atomic_set(&dev->overflow_flag, 0);
299 if ((read_idx = read_index(dev)) == -1) {
300 /* queue emty */
301 if (file->f_flags & O_NONBLOCK)
302 return -EAGAIN;
303 else {
304 //next line will return when there is either new data, or the device is unplugged
305 int r = wait_event_interruptible(dev->read_wait,
306 (!dev->present
307 || (read_idx =
308 read_index
309 (dev)) !=
310 -1));
311 if (r) {
312 //we were interrupted by a signal
313 return -ERESTART;
314 }
315 if (!dev->present) {
316 //The device was unplugged
317 return -ENODEV;
318 }
319 if (read_idx == -1) {
320 // Can this happen ???
321 return 0;
322 }
323 }
324 }
325
326 offset = read_idx * (dev->report_size + 1);
327 if (copy_to_user(buffer, dev->read_queue + offset, count)) {
328 return -EFAULT;
329 }
330 } while (atomic_read(&dev->overflow_flag));
331
332 read_idx = ++read_idx == MAX_INTERRUPT_BUFFER ? 0 : read_idx;
333 atomic_set(&dev->read_idx, read_idx);
334 return count;
335}
336
337/*
338 * iowarrior_write
339 */
340static ssize_t iowarrior_write(struct file *file,
341 const char __user *user_buffer,
342 size_t count, loff_t *ppos)
343{
344 struct iowarrior *dev;
345 int retval = 0;
346 char *buf = NULL; /* for IOW24 and IOW56 we need a buffer */
347 struct urb *int_out_urb = NULL;
348
349 dev = (struct iowarrior *)file->private_data;
350
351 mutex_lock(&dev->mutex);
352 /* verify that the device wasn't unplugged */
353 if (dev == NULL || !dev->present) {
354 retval = -ENODEV;
355 goto exit;
356 }
357 dbg("%s - minor %d, count = %zd", __func__, dev->minor, count);
358 /* if count is 0 we're already done */
359 if (count == 0) {
360 retval = 0;
361 goto exit;
362 }
363 /* We only accept full reports */
364 if (count != dev->report_size) {
365 retval = -EINVAL;
366 goto exit;
367 }
368 switch (dev->product_id) {
369 case USB_DEVICE_ID_CODEMERCS_IOW24:
370 case USB_DEVICE_ID_CODEMERCS_IOWPV1:
371 case USB_DEVICE_ID_CODEMERCS_IOWPV2:
372 case USB_DEVICE_ID_CODEMERCS_IOW40:
373 /* IOW24 and IOW40 use a synchronous call */
374 buf = kmalloc(8, GFP_KERNEL); /* 8 bytes are enough for both products */
375 if (!buf) {
376 retval = -ENOMEM;
377 goto exit;
378 }
379 if (copy_from_user(buf, user_buffer, count)) {
380 retval = -EFAULT;
381 kfree(buf);
382 goto exit;
383 }
384 retval = usb_set_report(dev->interface, 2, 0, buf, count);
385 kfree(buf);
386 goto exit;
387 break;
388 case USB_DEVICE_ID_CODEMERCS_IOW56:
389 /* The IOW56 uses asynchronous IO and more urbs */
390 if (atomic_read(&dev->write_busy) == MAX_WRITES_IN_FLIGHT) {
391 /* Wait until we are below the limit for submitted urbs */
392 if (file->f_flags & O_NONBLOCK) {
393 retval = -EAGAIN;
394 goto exit;
395 } else {
396 retval = wait_event_interruptible(dev->write_wait,
397 (!dev->present || (atomic_read (&dev-> write_busy) < MAX_WRITES_IN_FLIGHT)));
398 if (retval) {
399 /* we were interrupted by a signal */
400 retval = -ERESTART;
401 goto exit;
402 }
403 if (!dev->present) {
404 /* The device was unplugged */
405 retval = -ENODEV;
406 goto exit;
407 }
408 if (!dev->opened) {
409 /* We were closed while waiting for an URB */
410 retval = -ENODEV;
411 goto exit;
412 }
413 }
414 }
415 atomic_inc(&dev->write_busy);
416 int_out_urb = usb_alloc_urb(0, GFP_KERNEL);
417 if (!int_out_urb) {
418 retval = -ENOMEM;
419 dbg("%s Unable to allocate urb ", __func__);
420 goto error;
421 }
422 buf = usb_buffer_alloc(dev->udev, dev->report_size,
423 GFP_KERNEL, &int_out_urb->transfer_dma);
424 if (!buf) {
425 retval = -ENOMEM;
426 dbg("%s Unable to allocate buffer ", __func__);
427 goto error;
428 }
429 usb_fill_int_urb(int_out_urb, dev->udev,
430 usb_sndintpipe(dev->udev,
431 dev->int_out_endpoint->bEndpointAddress),
432 buf, dev->report_size,
433 iowarrior_write_callback, dev,
434 dev->int_out_endpoint->bInterval);
435 int_out_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
436 if (copy_from_user(buf, user_buffer, count)) {
437 retval = -EFAULT;
438 goto error;
439 }
440 retval = usb_submit_urb(int_out_urb, GFP_KERNEL);
441 if (retval) {
442 dbg("%s submit error %d for urb nr.%d", __func__,
443 retval, atomic_read(&dev->write_busy));
444 goto error;
445 }
446 /* submit was ok */
447 retval = count;
448 usb_free_urb(int_out_urb);
449 goto exit;
450 break;
451 default:
452 /* what do we have here ? An unsupported Product-ID ? */
453 dev_err(&dev->interface->dev, "%s - not supported for product=0x%x",
454 __FUNCTION__, dev->product_id);
455 retval = -EFAULT;
456 goto exit;
457 break;
458 }
459error:
460 usb_buffer_free(dev->udev, dev->report_size, buf,
461 int_out_urb->transfer_dma);
462 usb_free_urb(int_out_urb);
463 atomic_dec(&dev->write_busy);
464 wake_up_interruptible(&dev->write_wait);
465exit:
466 mutex_unlock(&dev->mutex);
467 return retval;
468}
469
470/**
471 * iowarrior_ioctl
472 */
473static int iowarrior_ioctl(struct inode *inode, struct file *file,
474 unsigned int cmd, unsigned long arg)
475{
476 struct iowarrior *dev = NULL;
477 __u8 *buffer;
478 __u8 __user *user_buffer;
479 int retval;
480 int io_res; /* checks for bytes read/written and copy_to/from_user results */
481
482 dev = (struct iowarrior *)file->private_data;
483 if (dev == NULL) {
484 return -ENODEV;
485 }
486
487 buffer = kzalloc(dev->report_size, GFP_KERNEL);
488 if (!buffer)
489 return -ENOMEM;
490
491 /* lock this object */
492 mutex_lock(&dev->mutex);
493
494 /* verify that the device wasn't unplugged */
495 if (!dev->present) {
496 mutex_unlock(&dev->mutex);
497 return -ENODEV;
498 }
499
500 dbg("%s - minor %d, cmd 0x%.4x, arg %ld", __func__, dev->minor, cmd,
501 arg);
502
503 retval = 0;
504 io_res = 0;
505 switch (cmd) {
506 case IOW_WRITE:
507 if (dev->product_id == USB_DEVICE_ID_CODEMERCS_IOW24 ||
508 dev->product_id == USB_DEVICE_ID_CODEMERCS_IOWPV1 ||
509 dev->product_id == USB_DEVICE_ID_CODEMERCS_IOWPV2 ||
510 dev->product_id == USB_DEVICE_ID_CODEMERCS_IOW40) {
511 user_buffer = (__u8 __user *)arg;
512 io_res = copy_from_user(buffer, user_buffer,
513 dev->report_size);
514 if (io_res) {
515 retval = -EFAULT;
516 } else {
517 io_res = usb_set_report(dev->interface, 2, 0,
518 buffer,
519 dev->report_size);
520 if (io_res < 0)
521 retval = io_res;
522 }
523 } else {
524 retval = -EINVAL;
525 dev_err(&dev->interface->dev,
526 "ioctl 'IOW_WRITE' is not supported for product=0x%x.",
527 dev->product_id);
528 }
529 break;
530 case IOW_READ:
531 user_buffer = (__u8 __user *)arg;
532 io_res = usb_get_report(dev->udev,
533 dev->interface->cur_altsetting, 1, 0,
534 buffer, dev->report_size);
535 if (io_res < 0)
536 retval = io_res;
537 else {
538 io_res = copy_to_user(user_buffer, buffer, dev->report_size);
539 if (io_res < 0)
540 retval = -EFAULT;
541 }
542 break;
543 case IOW_GETINFO:
544 {
545 /* Report available information for the device */
546 struct iowarrior_info info;
547 /* needed for power consumption */
548 struct usb_config_descriptor *cfg_descriptor = &dev->udev->actconfig->desc;
549
550 /* directly from the descriptor */
551 info.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
552 info.product = dev->product_id;
553 info.revision = le16_to_cpu(dev->udev->descriptor.bcdDevice);
554
555 /* 0==UNKNOWN, 1==LOW(usb1.1) ,2=FULL(usb1.1), 3=HIGH(usb2.0) */
556 info.speed = le16_to_cpu(dev->udev->speed);
557 info.if_num = dev->interface->cur_altsetting->desc.bInterfaceNumber;
558 info.report_size = dev->report_size;
559
560 /* serial number string has been read earlier 8 chars or empty string */
561 memcpy(info.serial, dev->chip_serial,
562 sizeof(dev->chip_serial));
563 if (cfg_descriptor == NULL) {
564 info.power = -1; /* no information available */
565 } else {
566 /* the MaxPower is stored in units of 2mA to make it fit into a byte-value */
567 info.power = cfg_descriptor->bMaxPower * 2;
568 }
569 io_res = copy_to_user((struct iowarrior_info __user *)arg, &info,
570 sizeof(struct iowarrior_info));
571 if (io_res < 0)
572 retval = -EFAULT;
573 break;
574 }
575 default:
576 /* return that we did not understand this ioctl call */
577 retval = -ENOTTY;
578 break;
579 }
580
581 /* unlock the device */
582 mutex_unlock(&dev->mutex);
583 return retval;
584}
585
586/**
587 * iowarrior_open
588 */
589static int iowarrior_open(struct inode *inode, struct file *file)
590{
591 struct iowarrior *dev = NULL;
592 struct usb_interface *interface;
593 int subminor;
594 int retval = 0;
595
596 dbg("%s", __func__);
597
598 subminor = iminor(inode);
599
600 /* prevent disconnects */
601 down(&disconnect_sem);
602
603 interface = usb_find_interface(&iowarrior_driver, subminor);
604 if (!interface) {
605 err("%s - error, can't find device for minor %d", __FUNCTION__,
606 subminor);
607 retval = -ENODEV;
608 goto out;
609 }
610
611 dev = usb_get_intfdata(interface);
612 if (!dev) {
613 retval = -ENODEV;
614 goto out;
615 }
616
617 /* Only one process can open each device, no sharing. */
618 if (dev->opened) {
619 retval = -EBUSY;
620 goto out;
621 }
622
623 /* setup interrupt handler for receiving values */
624 if ((retval = usb_submit_urb(dev->int_in_urb, GFP_KERNEL)) < 0) {
625 dev_err(&interface->dev, "Error %d while submitting URB\n", retval);
626 retval = -EFAULT;
627 goto out;
628 }
629 /* increment our usage count for the driver */
630 ++dev->opened;
631 /* save our object in the file's private structure */
632 file->private_data = dev;
633 retval = 0;
634
635out:
636 up(&disconnect_sem);
637 return retval;
638}
639
640/**
641 * iowarrior_release
642 */
643static int iowarrior_release(struct inode *inode, struct file *file)
644{
645 struct iowarrior *dev;
646 int retval = 0;
647
648 dev = (struct iowarrior *)file->private_data;
649 if (dev == NULL) {
650 return -ENODEV;
651 }
652
653 dbg("%s - minor %d", __func__, dev->minor);
654
655 /* lock our device */
656 mutex_lock(&dev->mutex);
657
658 if (dev->opened <= 0) {
659 retval = -ENODEV; /* close called more than once */
660 mutex_unlock(&dev->mutex);
661 } else {
662 dev->opened = 0; /* we're closeing now */
663 retval = 0;
664 if (dev->present) {
665 /*
666 The device is still connected so we only shutdown
667 pending read-/write-ops.
668 */
669 usb_kill_urb(dev->int_in_urb);
670 wake_up_interruptible(&dev->read_wait);
671 wake_up_interruptible(&dev->write_wait);
672 mutex_unlock(&dev->mutex);
673 } else {
674 /* The device was unplugged, cleanup resources */
675 mutex_unlock(&dev->mutex);
676 iowarrior_delete(dev);
677 }
678 }
679 return retval;
680}
681
682static unsigned iowarrior_poll(struct file *file, poll_table * wait)
683{
684 struct iowarrior *dev = file->private_data;
685 unsigned int mask = 0;
686
687 if (!dev->present)
688 return POLLERR | POLLHUP;
689
690 poll_wait(file, &dev->read_wait, wait);
691 poll_wait(file, &dev->write_wait, wait);
692
693 if (!dev->present)
694 return POLLERR | POLLHUP;
695
696 if (read_index(dev) != -1)
697 mask |= POLLIN | POLLRDNORM;
698
699 if (atomic_read(&dev->write_busy) < MAX_WRITES_IN_FLIGHT)
700 mask |= POLLOUT | POLLWRNORM;
701 return mask;
702}
703
704/*
705 * File operations needed when we register this driver.
706 * This assumes that this driver NEEDS file operations,
707 * of course, which means that the driver is expected
708 * to have a node in the /dev directory. If the USB
709 * device were for a network interface then the driver
710 * would use "struct net_driver" instead, and a serial
711 * device would use "struct tty_driver".
712 */
713static struct file_operations iowarrior_fops = {
714 .owner = THIS_MODULE,
715 .write = iowarrior_write,
716 .read = iowarrior_read,
717 .ioctl = iowarrior_ioctl,
718 .open = iowarrior_open,
719 .release = iowarrior_release,
720 .poll = iowarrior_poll,
721};
722
723/*
724 * usb class driver info in order to get a minor number from the usb core,
725 * and to have the device registered with devfs and the driver core
726 */
727static struct usb_class_driver iowarrior_class = {
728 .name = "iowarrior%d",
729 .fops = &iowarrior_fops,
730 .minor_base = IOWARRIOR_MINOR_BASE,
731};
732
733/*---------------------------------*/
734/* probe and disconnect functions */
735/*---------------------------------*/
736/**
737 * iowarrior_probe
738 *
739 * Called by the usb core when a new device is connected that it thinks
740 * this driver might be interested in.
741 */
742static int iowarrior_probe(struct usb_interface *interface,
743 const struct usb_device_id *id)
744{
745 struct usb_device *udev = interface_to_usbdev(interface);
746 struct iowarrior *dev = NULL;
747 struct usb_host_interface *iface_desc;
748 struct usb_endpoint_descriptor *endpoint;
749 int i;
750 int retval = -ENOMEM;
751 int idele = 0;
752
753 /* allocate memory for our device state and intialize it */
754 dev = kzalloc(sizeof(struct iowarrior), GFP_KERNEL);
755 if (dev == NULL) {
756 dev_err(&interface->dev, "Out of memory");
757 return retval;
758 }
759
760 mutex_init(&dev->mutex);
761
762 atomic_set(&dev->intr_idx, 0);
763 atomic_set(&dev->read_idx, 0);
764 spin_lock_init(&dev->intr_idx_lock);
765 atomic_set(&dev->overflow_flag, 0);
766 init_waitqueue_head(&dev->read_wait);
767 atomic_set(&dev->write_busy, 0);
768 init_waitqueue_head(&dev->write_wait);
769
770 dev->udev = udev;
771 dev->interface = interface;
772
773 iface_desc = interface->cur_altsetting;
774 dev->product_id = le16_to_cpu(udev->descriptor.idProduct);
775
776 /* set up the endpoint information */
777 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
778 endpoint = &iface_desc->endpoint[i].desc;
779
780 if (usb_endpoint_is_int_in(endpoint))
781 dev->int_in_endpoint = endpoint;
782 if (usb_endpoint_is_int_out(endpoint))
783 /* this one will match for the IOWarrior56 only */
784 dev->int_out_endpoint = endpoint;
785 }
786 /* we have to check the report_size often, so remember it in the endianess suitable for our machine */
787 dev->report_size = le16_to_cpu(dev->int_in_endpoint->wMaxPacketSize);
788 if ((dev->interface->cur_altsetting->desc.bInterfaceNumber == 0) &&
789 (dev->product_id == USB_DEVICE_ID_CODEMERCS_IOW56))
790 /* IOWarrior56 has wMaxPacketSize different from report size */
791 dev->report_size = 7;
792
793 /* create the urb and buffer for reading */
794 dev->int_in_urb = usb_alloc_urb(0, GFP_KERNEL);
795 if (!dev->int_in_urb) {
796 dev_err(&interface->dev, "Couldn't allocate interrupt_in_urb\n");
797 goto error;
798 }
799 dev->int_in_buffer = kmalloc(dev->report_size, GFP_KERNEL);
800 if (!dev->int_in_buffer) {
801 dev_err(&interface->dev, "Couldn't allocate int_in_buffer\n");
802 goto error;
803 }
804 usb_fill_int_urb(dev->int_in_urb, dev->udev,
805 usb_rcvintpipe(dev->udev,
806 dev->int_in_endpoint->bEndpointAddress),
807 dev->int_in_buffer, dev->report_size,
808 iowarrior_callback, dev,
809 dev->int_in_endpoint->bInterval);
810 /* create an internal buffer for interrupt data from the device */
811 dev->read_queue =
812 kmalloc(((dev->report_size + 1) * MAX_INTERRUPT_BUFFER),
813 GFP_KERNEL);
814 if (!dev->read_queue) {
815 dev_err(&interface->dev, "Couldn't allocate read_queue\n");
816 goto error;
817 }
818 /* Get the serial-number of the chip */
819 memset(dev->chip_serial, 0x00, sizeof(dev->chip_serial));
820 usb_string(udev, udev->descriptor.iSerialNumber, dev->chip_serial,
821 sizeof(dev->chip_serial));
822 if (strlen(dev->chip_serial) != 8)
823 memset(dev->chip_serial, 0x00, sizeof(dev->chip_serial));
824
825 /* Set the idle timeout to 0, if this is interface 0 */
826 if (dev->interface->cur_altsetting->desc.bInterfaceNumber == 0) {
827 idele = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
828 0x0A,
829 USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0,
830 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
831 dbg("idele = %d", idele);
832 }
833 /* allow device read and ioctl */
834 dev->present = 1;
835
836 /* we can register the device now, as it is ready */
837 usb_set_intfdata(interface, dev);
838
839 retval = usb_register_dev(interface, &iowarrior_class);
840 if (retval) {
841 /* something prevented us from registering this driver */
842 dev_err(&interface->dev, "Not able to get a minor for this device.\n");
843 usb_set_intfdata(interface, NULL);
844 goto error;
845 }
846
847 dev->minor = interface->minor;
848
849 /* let the user know what node this device is now attached to */
850 dev_info(&interface->dev, "IOWarrior product=0x%x, serial=%s interface=%d "
851 "now attached to iowarrior%d\n", dev->product_id, dev->chip_serial,
852 iface_desc->desc.bInterfaceNumber, dev->minor - IOWARRIOR_MINOR_BASE);
853 return retval;
854
855error:
856 iowarrior_delete(dev);
857 return retval;
858}
859
860/**
861 * iowarrior_disconnect
862 *
863 * Called by the usb core when the device is removed from the system.
864 */
865static void iowarrior_disconnect(struct usb_interface *interface)
866{
867 struct iowarrior *dev;
868 int minor;
869
870 /* prevent races with open() */
871 down(&disconnect_sem);
872
873 dev = usb_get_intfdata(interface);
874 usb_set_intfdata(interface, NULL);
875
876 mutex_lock(&dev->mutex);
877
878 minor = dev->minor;
879
880 /* give back our minor */
881 usb_deregister_dev(interface, &iowarrior_class);
882
883 /* prevent device read, write and ioctl */
884 dev->present = 0;
885
886 mutex_unlock(&dev->mutex);
887
888 if (dev->opened) {
889 /* There is a process that holds a filedescriptor to the device ,
890 so we only shutdown read-/write-ops going on.
891 Deleting the device is postponed until close() was called.
892 */
893 usb_kill_urb(dev->int_in_urb);
894 wake_up_interruptible(&dev->read_wait);
895 wake_up_interruptible(&dev->write_wait);
896 } else {
897 /* no process is using the device, cleanup now */
898 iowarrior_delete(dev);
899 }
900 up(&disconnect_sem);
901
902 dev_info(&interface->dev, "I/O-Warror #%d now disconnected\n",
903 minor - IOWARRIOR_MINOR_BASE);
904}
905
906/* usb specific object needed to register this driver with the usb subsystem */
907static struct usb_driver iowarrior_driver = {
908 .name = "iowarrior",
909 .probe = iowarrior_probe,
910 .disconnect = iowarrior_disconnect,
911 .id_table = iowarrior_ids,
912};
913
914static int __init iowarrior_init(void)
915{
916 return usb_register(&iowarrior_driver);
917}
918
919static void __exit iowarrior_exit(void)
920{
921 usb_deregister(&iowarrior_driver);
922}
923
924module_init(iowarrior_init);
925module_exit(iowarrior_exit);
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index c01dfe6036..b2bedd974a 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -1165,7 +1165,7 @@ err_dev:
1165 return rc; 1165 return rc;
1166} 1166}
1167 1167
1168void __exit mon_bin_exit(void) 1168void mon_bin_exit(void)
1169{ 1169{
1170 cdev_del(&mon_bin_cdev); 1170 cdev_del(&mon_bin_cdev);
1171 unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR); 1171 unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR);
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index d38a1279d9..494ee3b9a2 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -520,7 +520,7 @@ int __init mon_text_init(void)
520 return 0; 520 return 0;
521} 521}
522 522
523void __exit mon_text_exit(void) 523void mon_text_exit(void)
524{ 524{
525 debugfs_remove(mon_dir); 525 debugfs_remove(mon_dir);
526} 526}
diff --git a/drivers/usb/mon/usb_mon.h b/drivers/usb/mon/usb_mon.h
index 4f949ce8a7..efdfd8993d 100644
--- a/drivers/usb/mon/usb_mon.h
+++ b/drivers/usb/mon/usb_mon.h
@@ -57,9 +57,9 @@ void mon_text_del(struct mon_bus *mbus);
57// void mon_bin_add(struct mon_bus *); 57// void mon_bin_add(struct mon_bus *);
58 58
59int __init mon_text_init(void); 59int __init mon_text_init(void);
60void __exit mon_text_exit(void); 60void mon_text_exit(void);
61int __init mon_bin_init(void); 61int __init mon_bin_init(void);
62void __exit mon_bin_exit(void); 62void mon_bin_exit(void);
63 63
64/* 64/*
65 * DMA interface. 65 * DMA interface.
diff --git a/drivers/usb/net/Kconfig b/drivers/usb/net/Kconfig
index a2b94ef512..3de564b231 100644
--- a/drivers/usb/net/Kconfig
+++ b/drivers/usb/net/Kconfig
@@ -84,6 +84,7 @@ config USB_PEGASUS
84config USB_RTL8150 84config USB_RTL8150
85 tristate "USB RTL8150 based ethernet device support (EXPERIMENTAL)" 85 tristate "USB RTL8150 based ethernet device support (EXPERIMENTAL)"
86 depends on EXPERIMENTAL 86 depends on EXPERIMENTAL
87 select MII
87 help 88 help
88 Say Y here if you have RTL8150 based usb-ethernet adapter. 89 Say Y here if you have RTL8150 based usb-ethernet adapter.
89 Send me <petkan@users.sourceforge.net> any comments you may have. 90 Send me <petkan@users.sourceforge.net> any comments you may have.
@@ -98,7 +99,7 @@ config USB_USBNET_MII
98 99
99config USB_USBNET 100config USB_USBNET
100 tristate "Multi-purpose USB Networking Framework" 101 tristate "Multi-purpose USB Networking Framework"
101 select MII if USBNET_MII != n 102 select MII if USB_USBNET_MII != n
102 ---help--- 103 ---help---
103 This driver supports several kinds of network links over USB, 104 This driver supports several kinds of network links over USB,
104 with "minidrivers" built around a common network driver core 105 with "minidrivers" built around a common network driver core
@@ -185,6 +186,15 @@ config USB_NET_CDCETHER
185 IEEE 802 "local assignment" bit is set in the address, a "usbX" 186 IEEE 802 "local assignment" bit is set in the address, a "usbX"
186 name is used instead. 187 name is used instead.
187 188
189config USB_NET_DM9601
190 tristate "Davicom DM9601 based USB 1.1 10/100 ethernet devices"
191 depends on USB_USBNET
192 select CRC32
193 select USB_USBNET_MII
194 help
195 This option adds support for Davicom DM9601 based USB 1.1
196 10/100 Ethernet adapters.
197
188config USB_NET_GL620A 198config USB_NET_GL620A
189 tristate "GeneSys GL620USB-A based cables" 199 tristate "GeneSys GL620USB-A based cables"
190 depends on USB_USBNET 200 depends on USB_USBNET
@@ -239,6 +249,7 @@ config USB_NET_RNDIS_HOST
239config USB_NET_CDC_SUBSET 249config USB_NET_CDC_SUBSET
240 tristate "Simple USB Network Links (CDC Ethernet subset)" 250 tristate "Simple USB Network Links (CDC Ethernet subset)"
241 depends on USB_USBNET 251 depends on USB_USBNET
252 default y
242 help 253 help
243 This driver module supports USB network devices that can work 254 This driver module supports USB network devices that can work
244 without any device-specific information. Select it if you have 255 without any device-specific information. Select it if you have
@@ -298,6 +309,13 @@ config USB_EPSON2888
298 Choose this option to support the usb networking links used 309 Choose this option to support the usb networking links used
299 by some sample firmware from Epson. 310 by some sample firmware from Epson.
300 311
312config USB_KC2190
313 boolean "KT Technology KC2190 based cables (InstaNet)"
314 depends on USB_NET_CDC_SUBSET && EXPERIMENTAL
315 help
316  Choose this option if you're using a host-to-host cable
317  with one of these chips.
318
301config USB_NET_ZAURUS 319config USB_NET_ZAURUS
302 tristate "Sharp Zaurus (stock ROMs) and compatible" 320 tristate "Sharp Zaurus (stock ROMs) and compatible"
303 depends on USB_USBNET 321 depends on USB_USBNET
diff --git a/drivers/usb/net/Makefile b/drivers/usb/net/Makefile
index 7b51964de1..595a539f83 100644
--- a/drivers/usb/net/Makefile
+++ b/drivers/usb/net/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_USB_PEGASUS) += pegasus.o
8obj-$(CONFIG_USB_RTL8150) += rtl8150.o 8obj-$(CONFIG_USB_RTL8150) += rtl8150.o
9obj-$(CONFIG_USB_NET_AX8817X) += asix.o 9obj-$(CONFIG_USB_NET_AX8817X) += asix.o
10obj-$(CONFIG_USB_NET_CDCETHER) += cdc_ether.o 10obj-$(CONFIG_USB_NET_CDCETHER) += cdc_ether.o
11obj-$(CONFIG_USB_NET_DM9601) += dm9601.o
11obj-$(CONFIG_USB_NET_GL620A) += gl620a.o 12obj-$(CONFIG_USB_NET_GL620A) += gl620a.o
12obj-$(CONFIG_USB_NET_NET1080) += net1080.o 13obj-$(CONFIG_USB_NET_NET1080) += net1080.o
13obj-$(CONFIG_USB_NET_PLUSB) += plusb.o 14obj-$(CONFIG_USB_NET_PLUSB) += plusb.o
diff --git a/drivers/usb/net/asix.c b/drivers/usb/net/asix.c
index bd357e178e..5808ea0824 100644
--- a/drivers/usb/net/asix.c
+++ b/drivers/usb/net/asix.c
@@ -351,9 +351,11 @@ static struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
351 351
352 skb_push(skb, 4); 352 skb_push(skb, 4);
353 packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4); 353 packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4);
354 cpu_to_le32s(&packet_len);
354 memcpy(skb->data, &packet_len, sizeof(packet_len)); 355 memcpy(skb->data, &packet_len, sizeof(packet_len));
355 356
356 if ((skb->len % 512) == 0) { 357 if ((skb->len % 512) == 0) {
358 cpu_to_le32s(&padbytes);
357 memcpy( skb->tail, &padbytes, sizeof(padbytes)); 359 memcpy( skb->tail, &padbytes, sizeof(padbytes));
358 skb_put(skb, sizeof(padbytes)); 360 skb_put(skb, sizeof(padbytes));
359 } 361 }
@@ -1393,9 +1395,9 @@ static const struct usb_device_id products [] = {
1393 USB_DEVICE (0x07b8, 0x420a), 1395 USB_DEVICE (0x07b8, 0x420a),
1394 .driver_info = (unsigned long) &hawking_uf200_info, 1396 .driver_info = (unsigned long) &hawking_uf200_info,
1395}, { 1397}, {
1396 // Billionton Systems, USB2AR 1398 // Billionton Systems, USB2AR
1397 USB_DEVICE (0x08dd, 0x90ff), 1399 USB_DEVICE (0x08dd, 0x90ff),
1398 .driver_info = (unsigned long) &ax8817x_info, 1400 .driver_info = (unsigned long) &ax8817x_info,
1399}, { 1401}, {
1400 // ATEN UC210T 1402 // ATEN UC210T
1401 USB_DEVICE (0x0557, 0x2009), 1403 USB_DEVICE (0x0557, 0x2009),
@@ -1421,9 +1423,13 @@ static const struct usb_device_id products [] = {
1421 USB_DEVICE (0x1631, 0x6200), 1423 USB_DEVICE (0x1631, 0x6200),
1422 .driver_info = (unsigned long) &ax8817x_info, 1424 .driver_info = (unsigned long) &ax8817x_info,
1423}, { 1425}, {
1426 // JVC MP-PRX1 Port Replicator
1427 USB_DEVICE (0x04f1, 0x3008),
1428 .driver_info = (unsigned long) &ax8817x_info,
1429}, {
1424 // ASIX AX88772 10/100 1430 // ASIX AX88772 10/100
1425 USB_DEVICE (0x0b95, 0x7720), 1431 USB_DEVICE (0x0b95, 0x7720),
1426 .driver_info = (unsigned long) &ax88772_info, 1432 .driver_info = (unsigned long) &ax88772_info,
1427}, { 1433}, {
1428 // ASIX AX88178 10/100/1000 1434 // ASIX AX88178 10/100/1000
1429 USB_DEVICE (0x0b95, 0x1780), 1435 USB_DEVICE (0x0b95, 0x1780),
diff --git a/drivers/usb/net/cdc_subset.c b/drivers/usb/net/cdc_subset.c
index ae8fb06cf3..bc62b01260 100644
--- a/drivers/usb/net/cdc_subset.c
+++ b/drivers/usb/net/cdc_subset.c
@@ -79,13 +79,19 @@ static int always_connected (struct usbnet *dev)
79 * 79 *
80 * ALi M5632 driver ... does high speed 80 * ALi M5632 driver ... does high speed
81 * 81 *
82 * NOTE that the MS-Windows drivers for this chip use some funky and
83 * (naturally) undocumented 7-byte prefix to each packet, so this is a
84 * case where we don't currently interoperate. Also, once you unplug
85 * one end of the cable, you need to replug the other end too ... since
86 * chip docs are unavailable, there's no way to reset the relevant state
87 * short of a power cycle.
88 *
82 *-------------------------------------------------------------------------*/ 89 *-------------------------------------------------------------------------*/
83 90
84static const struct driver_info ali_m5632_info = { 91static const struct driver_info ali_m5632_info = {
85 .description = "ALi M5632", 92 .description = "ALi M5632",
86}; 93};
87 94
88
89#endif 95#endif
90 96
91 97
@@ -159,6 +165,11 @@ static const struct driver_info epson2888_info = {
159#endif /* CONFIG_USB_EPSON2888 */ 165#endif /* CONFIG_USB_EPSON2888 */
160 166
161 167
168/*-------------------------------------------------------------------------
169 *
170 * info from Jonathan McDowell <noodles@earth.li>
171 *
172 *-------------------------------------------------------------------------*/
162#ifdef CONFIG_USB_KC2190 173#ifdef CONFIG_USB_KC2190
163#define HAVE_HARDWARE 174#define HAVE_HARDWARE
164static const struct driver_info kc2190_info = { 175static const struct driver_info kc2190_info = {
@@ -223,6 +234,10 @@ static const struct usb_device_id products [] = {
223 USB_DEVICE (0x0402, 0x5632), // ALi defaults 234 USB_DEVICE (0x0402, 0x5632), // ALi defaults
224 .driver_info = (unsigned long) &ali_m5632_info, 235 .driver_info = (unsigned long) &ali_m5632_info,
225}, 236},
237{
238 USB_DEVICE (0x182d,0x207c), // SiteCom CN-124
239 .driver_info = (unsigned long) &ali_m5632_info,
240},
226#endif 241#endif
227 242
228#ifdef CONFIG_USB_AN2720 243#ifdef CONFIG_USB_AN2720
@@ -314,13 +329,13 @@ static struct usb_driver cdc_subset_driver = {
314 329
315static int __init cdc_subset_init(void) 330static int __init cdc_subset_init(void)
316{ 331{
317 return usb_register(&cdc_subset_driver); 332 return usb_register(&cdc_subset_driver);
318} 333}
319module_init(cdc_subset_init); 334module_init(cdc_subset_init);
320 335
321static void __exit cdc_subset_exit(void) 336static void __exit cdc_subset_exit(void)
322{ 337{
323 usb_deregister(&cdc_subset_driver); 338 usb_deregister(&cdc_subset_driver);
324} 339}
325module_exit(cdc_subset_exit); 340module_exit(cdc_subset_exit);
326 341
diff --git a/drivers/usb/net/dm9601.c b/drivers/usb/net/dm9601.c
new file mode 100644
index 0000000000..4a932e1cd9
--- /dev/null
+++ b/drivers/usb/net/dm9601.c
@@ -0,0 +1,606 @@
1/*
2 * Davicom DM9601 USB 1.1 10/100Mbps ethernet devices
3 *
4 * Peter Korsgaard <jacmet@sunsite.dk>
5 *
6 * This file is licensed under the terms of the GNU General Public License
7 * version 2. This program is licensed "as is" without any warranty of any
8 * kind, whether express or implied.
9 */
10
11//#define DEBUG
12
13#include <linux/module.h>
14#include <linux/sched.h>
15#include <linux/init.h>
16#include <linux/netdevice.h>
17#include <linux/etherdevice.h>
18#include <linux/ethtool.h>
19#include <linux/mii.h>
20#include <linux/usb.h>
21#include <linux/crc32.h>
22
23#include "usbnet.h"
24
25/* datasheet:
26 http://www.davicom.com.tw/big5/download/Data%20Sheet/DM9601-DS-P01-930914.pdf
27*/
28
29/* control requests */
30#define DM_READ_REGS 0x00
31#define DM_WRITE_REGS 0x01
32#define DM_READ_MEMS 0x02
33#define DM_WRITE_REG 0x03
34#define DM_WRITE_MEMS 0x05
35#define DM_WRITE_MEM 0x07
36
37/* registers */
38#define DM_NET_CTRL 0x00
39#define DM_RX_CTRL 0x05
40#define DM_SHARED_CTRL 0x0b
41#define DM_SHARED_ADDR 0x0c
42#define DM_SHARED_DATA 0x0d /* low + high */
43#define DM_PHY_ADDR 0x10 /* 6 bytes */
44#define DM_MCAST_ADDR 0x16 /* 8 bytes */
45#define DM_GPR_CTRL 0x1e
46#define DM_GPR_DATA 0x1f
47
48#define DM_MAX_MCAST 64
49#define DM_MCAST_SIZE 8
50#define DM_EEPROM_LEN 256
51#define DM_TX_OVERHEAD 2 /* 2 byte header */
52#define DM_RX_OVERHEAD 7 /* 3 byte header + 4 byte crc tail */
53#define DM_TIMEOUT 1000
54
55
56static int dm_read(struct usbnet *dev, u8 reg, u16 length, void *data)
57{
58 devdbg(dev, "dm_read() reg=0x%02x length=%d", reg, length);
59 return usb_control_msg(dev->udev,
60 usb_rcvctrlpipe(dev->udev, 0),
61 DM_READ_REGS,
62 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
63 0, reg, data, length, USB_CTRL_SET_TIMEOUT);
64}
65
66static int dm_read_reg(struct usbnet *dev, u8 reg, u8 *value)
67{
68 return dm_read(dev, reg, 1, value);
69}
70
71static int dm_write(struct usbnet *dev, u8 reg, u16 length, void *data)
72{
73 devdbg(dev, "dm_write() reg=0x%02x, length=%d", reg, length);
74 return usb_control_msg(dev->udev,
75 usb_sndctrlpipe(dev->udev, 0),
76 DM_WRITE_REGS,
77 USB_DIR_OUT | USB_TYPE_VENDOR |USB_RECIP_DEVICE,
78 0, reg, data, length, USB_CTRL_SET_TIMEOUT);
79}
80
81static int dm_write_reg(struct usbnet *dev, u8 reg, u8 value)
82{
83 devdbg(dev, "dm_write_reg() reg=0x%02x, value=0x%02x", reg, value);
84 return usb_control_msg(dev->udev,
85 usb_sndctrlpipe(dev->udev, 0),
86 DM_WRITE_REG,
87 USB_DIR_OUT | USB_TYPE_VENDOR |USB_RECIP_DEVICE,
88 value, reg, 0, 0, USB_CTRL_SET_TIMEOUT);
89}
90
91static void dm_write_async_callback(struct urb *urb)
92{
93 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
94
95 if (urb->status < 0)
96 printk(KERN_DEBUG "dm_write_async_callback() failed with %d",
97 urb->status);
98
99 kfree(req);
100 usb_free_urb(urb);
101}
102
103static void dm_write_async(struct usbnet *dev, u8 reg, u16 length, void *data)
104{
105 struct usb_ctrlrequest *req;
106 struct urb *urb;
107 int status;
108
109 devdbg(dev, "dm_write_async() reg=0x%02x length=%d", reg, length);
110
111 urb = usb_alloc_urb(0, GFP_ATOMIC);
112 if (!urb) {
113 deverr(dev, "Error allocating URB in dm_write_async!");
114 return;
115 }
116
117 req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
118 if (!req) {
119 deverr(dev, "Failed to allocate memory for control request");
120 usb_free_urb(urb);
121 return;
122 }
123
124 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
125 req->bRequest = DM_WRITE_REGS;
126 req->wValue = 0;
127 req->wIndex = cpu_to_le16(reg);
128 req->wLength = cpu_to_le16(length);
129
130 usb_fill_control_urb(urb, dev->udev,
131 usb_sndctrlpipe(dev->udev, 0),
132 (void *)req, data, length,
133 dm_write_async_callback, req);
134
135 status = usb_submit_urb(urb, GFP_ATOMIC);
136 if (status < 0) {
137 deverr(dev, "Error submitting the control message: status=%d",
138 status);
139 kfree(req);
140 usb_free_urb(urb);
141 }
142}
143
144static void dm_write_reg_async(struct usbnet *dev, u8 reg, u8 value)
145{
146 struct usb_ctrlrequest *req;
147 struct urb *urb;
148 int status;
149
150 devdbg(dev, "dm_write_reg_async() reg=0x%02x value=0x%02x",
151 reg, value);
152
153 urb = usb_alloc_urb(0, GFP_ATOMIC);
154 if (!urb) {
155 deverr(dev, "Error allocating URB in dm_write_async!");
156 return;
157 }
158
159 req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
160 if (!req) {
161 deverr(dev, "Failed to allocate memory for control request");
162 usb_free_urb(urb);
163 return;
164 }
165
166 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
167 req->bRequest = DM_WRITE_REG;
168 req->wValue = cpu_to_le16(value);
169 req->wIndex = cpu_to_le16(reg);
170 req->wLength = 0;
171
172 usb_fill_control_urb(urb, dev->udev,
173 usb_sndctrlpipe(dev->udev, 0),
174 (void *)req, 0, 0, dm_write_async_callback, req);
175
176 status = usb_submit_urb(urb, GFP_ATOMIC);
177 if (status < 0) {
178 deverr(dev, "Error submitting the control message: status=%d",
179 status);
180 kfree(req);
181 usb_free_urb(urb);
182 }
183}
184
185static int dm_read_shared_word(struct usbnet *dev, int phy, u8 reg, u16 *value)
186{
187 int ret, i;
188
189 mutex_lock(&dev->phy_mutex);
190
191 dm_write_reg(dev, DM_SHARED_ADDR, phy ? (reg | 0x40) : reg);
192 dm_write_reg(dev, DM_SHARED_CTRL, phy ? 0xc : 0x4);
193
194 for (i = 0; i < DM_TIMEOUT; i++) {
195 u8 tmp;
196
197 udelay(1);
198 ret = dm_read_reg(dev, DM_SHARED_CTRL, &tmp);
199 if (ret < 0)
200 goto out;
201
202 /* ready */
203 if ((tmp & 1) == 0)
204 break;
205 }
206
207 if (i == DM_TIMEOUT) {
208 deverr(dev, "%s read timed out!", phy ? "phy" : "eeprom");
209 ret = -EIO;
210 goto out;
211 }
212
213 dm_write_reg(dev, DM_SHARED_CTRL, 0x0);
214 ret = dm_read(dev, DM_SHARED_DATA, 2, value);
215
216 devdbg(dev, "read shared %d 0x%02x returned 0x%04x, %d",
217 phy, reg, *value, ret);
218
219 out:
220 mutex_unlock(&dev->phy_mutex);
221 return ret;
222}
223
224static int dm_write_shared_word(struct usbnet *dev, int phy, u8 reg, u16 value)
225{
226 int ret, i;
227
228 mutex_lock(&dev->phy_mutex);
229
230 ret = dm_write(dev, DM_SHARED_DATA, 2, &value);
231 if (ret < 0)
232 goto out;
233
234 dm_write_reg(dev, DM_SHARED_ADDR, phy ? (reg | 0x40) : reg);
235 dm_write_reg(dev, DM_SHARED_CTRL, phy ? 0x1c : 0x14);
236
237 for (i = 0; i < DM_TIMEOUT; i++) {
238 u8 tmp;
239
240 udelay(1);
241 ret = dm_read_reg(dev, DM_SHARED_CTRL, &tmp);
242 if (ret < 0)
243 goto out;
244
245 /* ready */
246 if ((tmp & 1) == 0)
247 break;
248 }
249
250 if (i == DM_TIMEOUT) {
251 deverr(dev, "%s write timed out!", phy ? "phy" : "eeprom");
252 ret = -EIO;
253 goto out;
254 }
255
256 dm_write_reg(dev, DM_SHARED_CTRL, 0x0);
257
258out:
259 mutex_unlock(&dev->phy_mutex);
260 return ret;
261}
262
263static int dm_read_eeprom_word(struct usbnet *dev, u8 offset, void *value)
264{
265 return dm_read_shared_word(dev, 0, offset, value);
266}
267
268
269
270static int dm9601_get_eeprom_len(struct net_device *dev)
271{
272 return DM_EEPROM_LEN;
273}
274
275static int dm9601_get_eeprom(struct net_device *net,
276 struct ethtool_eeprom *eeprom, u8 * data)
277{
278 struct usbnet *dev = netdev_priv(net);
279 u16 *ebuf = (u16 *) data;
280 int i;
281
282 /* access is 16bit */
283 if ((eeprom->offset % 2) || (eeprom->len % 2))
284 return -EINVAL;
285
286 for (i = 0; i < eeprom->len / 2; i++) {
287 if (dm_read_eeprom_word(dev, eeprom->offset / 2 + i,
288 &ebuf[i]) < 0)
289 return -EINVAL;
290 }
291 return 0;
292}
293
294static int dm9601_mdio_read(struct net_device *netdev, int phy_id, int loc)
295{
296 struct usbnet *dev = netdev_priv(netdev);
297
298 u16 res;
299
300 if (phy_id) {
301 devdbg(dev, "Only internal phy supported");
302 return 0;
303 }
304
305 dm_read_shared_word(dev, 1, loc, &res);
306
307 devdbg(dev,
308 "dm9601_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x",
309 phy_id, loc, le16_to_cpu(res));
310
311 return le16_to_cpu(res);
312}
313
314static void dm9601_mdio_write(struct net_device *netdev, int phy_id, int loc,
315 int val)
316{
317 struct usbnet *dev = netdev_priv(netdev);
318 u16 res = cpu_to_le16(val);
319
320 if (phy_id) {
321 devdbg(dev, "Only internal phy supported");
322 return;
323 }
324
325 devdbg(dev,"dm9601_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x",
326 phy_id, loc, val);
327
328 dm_write_shared_word(dev, 1, loc, res);
329}
330
331static void dm9601_get_drvinfo(struct net_device *net,
332 struct ethtool_drvinfo *info)
333{
334 /* Inherit standard device info */
335 usbnet_get_drvinfo(net, info);
336 info->eedump_len = DM_EEPROM_LEN;
337}
338
339static u32 dm9601_get_link(struct net_device *net)
340{
341 struct usbnet *dev = netdev_priv(net);
342
343 return mii_link_ok(&dev->mii);
344}
345
346static int dm9601_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
347{
348 struct usbnet *dev = netdev_priv(net);
349
350 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
351}
352
353static struct ethtool_ops dm9601_ethtool_ops = {
354 .get_drvinfo = dm9601_get_drvinfo,
355 .get_link = dm9601_get_link,
356 .get_msglevel = usbnet_get_msglevel,
357 .set_msglevel = usbnet_set_msglevel,
358 .get_eeprom_len = dm9601_get_eeprom_len,
359 .get_eeprom = dm9601_get_eeprom,
360 .get_settings = usbnet_get_settings,
361 .set_settings = usbnet_set_settings,
362 .nway_reset = usbnet_nway_reset,
363};
364
365static void dm9601_set_multicast(struct net_device *net)
366{
367 struct usbnet *dev = netdev_priv(net);
368 /* We use the 20 byte dev->data for our 8 byte filter buffer
369 * to avoid allocating memory that is tricky to free later */
370 u8 *hashes = (u8 *) & dev->data;
371 u8 rx_ctl = 0x01;
372
373 memset(hashes, 0x00, DM_MCAST_SIZE);
374 hashes[DM_MCAST_SIZE - 1] |= 0x80; /* broadcast address */
375
376 if (net->flags & IFF_PROMISC) {
377 rx_ctl |= 0x02;
378 } else if (net->flags & IFF_ALLMULTI || net->mc_count > DM_MAX_MCAST) {
379 rx_ctl |= 0x04;
380 } else if (net->mc_count) {
381 struct dev_mc_list *mc_list = net->mc_list;
382 int i;
383
384 for (i = 0; i < net->mc_count; i++) {
385 u32 crc = ether_crc(ETH_ALEN, mc_list->dmi_addr) >> 26;
386 hashes[crc >> 3] |= 1 << (crc & 0x7);
387 }
388 }
389
390 dm_write_async(dev, DM_MCAST_ADDR, DM_MCAST_SIZE, hashes);
391 dm_write_reg_async(dev, DM_RX_CTRL, rx_ctl);
392}
393
394static int dm9601_bind(struct usbnet *dev, struct usb_interface *intf)
395{
396 int ret;
397
398 ret = usbnet_get_endpoints(dev, intf);
399 if (ret)
400 goto out;
401
402 dev->net->do_ioctl = dm9601_ioctl;
403 dev->net->set_multicast_list = dm9601_set_multicast;
404 dev->net->ethtool_ops = &dm9601_ethtool_ops;
405 dev->net->hard_header_len += DM_TX_OVERHEAD;
406 dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
407 dev->rx_urb_size = dev->net->mtu + DM_RX_OVERHEAD;
408
409 dev->mii.dev = dev->net;
410 dev->mii.mdio_read = dm9601_mdio_read;
411 dev->mii.mdio_write = dm9601_mdio_write;
412 dev->mii.phy_id_mask = 0x1f;
413 dev->mii.reg_num_mask = 0x1f;
414
415 /* reset */
416 ret = dm_write_reg(dev, DM_NET_CTRL, 1);
417 udelay(20);
418
419 /* read MAC */
420 ret = dm_read(dev, DM_PHY_ADDR, ETH_ALEN, dev->net->dev_addr);
421 if (ret < 0) {
422 printk(KERN_ERR "Error reading MAC address\n");
423 ret = -ENODEV;
424 goto out;
425 }
426
427
428 /* power up phy */
429 dm_write_reg(dev, DM_GPR_CTRL, 1);
430 dm_write_reg(dev, DM_GPR_DATA, 0);
431
432 /* receive broadcast packets */
433 dm9601_set_multicast(dev->net);
434
435 dm9601_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
436 dm9601_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
437 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
438 mii_nway_restart(&dev->mii);
439
440out:
441 return ret;
442}
443
444static int dm9601_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
445{
446 u8 status;
447 int len;
448
449 /* format:
450 b0: rx status
451 b1: packet length (incl crc) low
452 b2: packet length (incl crc) high
453 b3..n-4: packet data
454 bn-3..bn: ethernet crc
455 */
456
457 if (unlikely(skb->len < DM_RX_OVERHEAD)) {
458 dev_err(&dev->udev->dev, "unexpected tiny rx frame\n");
459 return 0;
460 }
461
462 status = skb->data[0];
463 len = (skb->data[1] | (skb->data[2] << 8)) - 4;
464
465 if (unlikely(status & 0xbf)) {
466 if (status & 0x01) dev->stats.rx_fifo_errors++;
467 if (status & 0x02) dev->stats.rx_crc_errors++;
468 if (status & 0x04) dev->stats.rx_frame_errors++;
469 if (status & 0x20) dev->stats.rx_missed_errors++;
470 if (status & 0x90) dev->stats.rx_length_errors++;
471 return 0;
472 }
473
474 skb_pull(skb, 3);
475 skb_trim(skb, len);
476
477 return 1;
478}
479
480static struct sk_buff *dm9601_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
481 gfp_t flags)
482{
483 int len;
484
485 /* format:
486 b0: packet length low
487 b1: packet length high
488 b3..n: packet data
489 */
490
491 if (skb_headroom(skb) < DM_TX_OVERHEAD) {
492 struct sk_buff *skb2;
493
494 skb2 = skb_copy_expand(skb, DM_TX_OVERHEAD, 0, flags);
495 dev_kfree_skb_any(skb);
496 skb = skb2;
497 if (!skb)
498 return NULL;
499 }
500
501 __skb_push(skb, DM_TX_OVERHEAD);
502
503 len = skb->len;
504 /* usbnet adds padding if length is a multiple of packet size
505 if so, adjust length value in header */
506 if ((len % dev->maxpacket) == 0)
507 len++;
508
509 skb->data[0] = len;
510 skb->data[1] = len >> 8;
511
512 return skb;
513}
514
515static void dm9601_status(struct usbnet *dev, struct urb *urb)
516{
517 int link;
518 u8 *buf;
519
520 /* format:
521 b0: net status
522 b1: tx status 1
523 b2: tx status 2
524 b3: rx status
525 b4: rx overflow
526 b5: rx count
527 b6: tx count
528 b7: gpr
529 */
530
531 if (urb->actual_length < 8)
532 return;
533
534 buf = urb->transfer_buffer;
535
536 link = !!(buf[0] & 0x40);
537 if (netif_carrier_ok(dev->net) != link) {
538 if (link) {
539 netif_carrier_on(dev->net);
540 usbnet_defer_kevent (dev, EVENT_LINK_RESET);
541 }
542 else
543 netif_carrier_off(dev->net);
544 devdbg(dev, "Link Status is: %d", link);
545 }
546}
547
548static int dm9601_link_reset(struct usbnet *dev)
549{
550 struct ethtool_cmd ecmd;
551
552 mii_check_media(&dev->mii, 1, 1);
553 mii_ethtool_gset(&dev->mii, &ecmd);
554
555 devdbg(dev, "link_reset() speed: %d duplex: %d",
556 ecmd.speed, ecmd.duplex);
557
558 return 0;
559}
560
561static const struct driver_info dm9601_info = {
562 .description = "Davicom DM9601 USB Ethernet",
563 .flags = FLAG_ETHER,
564 .bind = dm9601_bind,
565 .rx_fixup = dm9601_rx_fixup,
566 .tx_fixup = dm9601_tx_fixup,
567 .status = dm9601_status,
568 .link_reset = dm9601_link_reset,
569 .reset = dm9601_link_reset,
570};
571
572static const struct usb_device_id products[] = {
573 {
574 USB_DEVICE(0x0a46, 0x9601), /* Davicom USB-100 */
575 .driver_info = (unsigned long)&dm9601_info,
576 },
577 {}, // END
578};
579
580MODULE_DEVICE_TABLE(usb, products);
581
582static struct usb_driver dm9601_driver = {
583 .name = "dm9601",
584 .id_table = products,
585 .probe = usbnet_probe,
586 .disconnect = usbnet_disconnect,
587 .suspend = usbnet_suspend,
588 .resume = usbnet_resume,
589};
590
591static int __init dm9601_init(void)
592{
593 return usb_register(&dm9601_driver);
594}
595
596static void __exit dm9601_exit(void)
597{
598 usb_deregister(&dm9601_driver);
599}
600
601module_init(dm9601_init);
602module_exit(dm9601_exit);
603
604MODULE_AUTHOR("Peter Korsgaard <jacmet@sunsite.dk>");
605MODULE_DESCRIPTION("Davicom DM9601 USB 1.1 ethernet devices");
606MODULE_LICENSE("GPL");
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c
index 43ba61abfc..de69b183bd 100644
--- a/drivers/usb/net/usbnet.c
+++ b/drivers/usb/net/usbnet.c
@@ -147,7 +147,7 @@ int usbnet_get_endpoints(struct usbnet *dev, struct usb_interface *intf)
147 if (tmp < 0) 147 if (tmp < 0)
148 return tmp; 148 return tmp;
149 } 149 }
150 150
151 dev->in = usb_rcvbulkpipe (dev->udev, 151 dev->in = usb_rcvbulkpipe (dev->udev,
152 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 152 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
153 dev->out = usb_sndbulkpipe (dev->udev, 153 dev->out = usb_sndbulkpipe (dev->udev,
@@ -327,7 +327,7 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
327 if (netif_running (dev->net) 327 if (netif_running (dev->net)
328 && netif_device_present (dev->net) 328 && netif_device_present (dev->net)
329 && !test_bit (EVENT_RX_HALT, &dev->flags)) { 329 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
330 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){ 330 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){
331 case -EPIPE: 331 case -EPIPE:
332 usbnet_defer_kevent (dev, EVENT_RX_HALT); 332 usbnet_defer_kevent (dev, EVENT_RX_HALT);
333 break; 333 break;
@@ -443,7 +443,7 @@ block:
443 case -EOVERFLOW: 443 case -EOVERFLOW:
444 dev->stats.rx_over_errors++; 444 dev->stats.rx_over_errors++;
445 // FALLTHROUGH 445 // FALLTHROUGH
446 446
447 default: 447 default:
448 entry->state = rx_cleanup; 448 entry->state = rx_cleanup;
449 dev->stats.rx_errors++; 449 dev->stats.rx_errors++;
@@ -560,7 +560,7 @@ static int usbnet_stop (struct net_device *net)
560 560
561 if (netif_msg_ifdown (dev)) 561 if (netif_msg_ifdown (dev))
562 devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld", 562 devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld",
563 dev->stats.rx_packets, dev->stats.tx_packets, 563 dev->stats.rx_packets, dev->stats.tx_packets,
564 dev->stats.rx_errors, dev->stats.tx_errors 564 dev->stats.rx_errors, dev->stats.tx_errors
565 ); 565 );
566 566
@@ -578,7 +578,7 @@ static int usbnet_stop (struct net_device *net)
578 devdbg (dev, "waited for %d urb completions", temp); 578 devdbg (dev, "waited for %d urb completions", temp);
579 } 579 }
580 dev->wait = NULL; 580 dev->wait = NULL;
581 remove_wait_queue (&unlink_wakeup, &wait); 581 remove_wait_queue (&unlink_wakeup, &wait);
582 582
583 usb_kill_urb(dev->interrupt); 583 usb_kill_urb(dev->interrupt);
584 584
@@ -834,7 +834,7 @@ kevent (struct work_struct *work)
834 } 834 }
835 835
836 if (test_bit (EVENT_LINK_RESET, &dev->flags)) { 836 if (test_bit (EVENT_LINK_RESET, &dev->flags)) {
837 struct driver_info *info = dev->driver_info; 837 struct driver_info *info = dev->driver_info;
838 int retval = 0; 838 int retval = 0;
839 839
840 clear_bit (EVENT_LINK_RESET, &dev->flags); 840 clear_bit (EVENT_LINK_RESET, &dev->flags);
@@ -1066,7 +1066,7 @@ static void usbnet_bh (unsigned long param)
1066 * USB Device Driver support 1066 * USB Device Driver support
1067 * 1067 *
1068 *-------------------------------------------------------------------------*/ 1068 *-------------------------------------------------------------------------*/
1069 1069
1070// precondition: never called in_interrupt 1070// precondition: never called in_interrupt
1071 1071
1072void usbnet_disconnect (struct usb_interface *intf) 1072void usbnet_disconnect (struct usb_interface *intf)
@@ -1087,7 +1087,7 @@ void usbnet_disconnect (struct usb_interface *intf)
1087 intf->dev.driver->name, 1087 intf->dev.driver->name,
1088 xdev->bus->bus_name, xdev->devpath, 1088 xdev->bus->bus_name, xdev->devpath,
1089 dev->driver_info->description); 1089 dev->driver_info->description);
1090 1090
1091 net = dev->net; 1091 net = dev->net;
1092 unregister_netdev (net); 1092 unregister_netdev (net);
1093 1093
@@ -1111,7 +1111,7 @@ int
1111usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) 1111usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1112{ 1112{
1113 struct usbnet *dev; 1113 struct usbnet *dev;
1114 struct net_device *net; 1114 struct net_device *net;
1115 struct usb_host_interface *interface; 1115 struct usb_host_interface *interface;
1116 struct driver_info *info; 1116 struct driver_info *info;
1117 struct usb_device *xdev; 1117 struct usb_device *xdev;
@@ -1181,6 +1181,9 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1181 // NOTE net->name still not usable ... 1181 // NOTE net->name still not usable ...
1182 if (info->bind) { 1182 if (info->bind) {
1183 status = info->bind (dev, udev); 1183 status = info->bind (dev, udev);
1184 if (status < 0)
1185 goto out1;
1186
1184 // heuristic: "usb%d" for links we know are two-host, 1187 // heuristic: "usb%d" for links we know are two-host,
1185 // else "eth%d" when there's reasonable doubt. userspace 1188 // else "eth%d" when there's reasonable doubt. userspace
1186 // can rename the link if it knows better. 1189 // can rename the link if it knows better.
@@ -1207,12 +1210,12 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1207 if (status == 0 && dev->status) 1210 if (status == 0 && dev->status)
1208 status = init_status (dev, udev); 1211 status = init_status (dev, udev);
1209 if (status < 0) 1212 if (status < 0)
1210 goto out1; 1213 goto out3;
1211 1214
1212 if (!dev->rx_urb_size) 1215 if (!dev->rx_urb_size)
1213 dev->rx_urb_size = dev->hard_mtu; 1216 dev->rx_urb_size = dev->hard_mtu;
1214 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1); 1217 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
1215 1218
1216 SET_NETDEV_DEV(net, &udev->dev); 1219 SET_NETDEV_DEV(net, &udev->dev);
1217 status = register_netdev (net); 1220 status = register_netdev (net);
1218 if (status) 1221 if (status)
@@ -1255,7 +1258,7 @@ EXPORT_SYMBOL_GPL(usbnet_probe);
1255int usbnet_suspend (struct usb_interface *intf, pm_message_t message) 1258int usbnet_suspend (struct usb_interface *intf, pm_message_t message)
1256{ 1259{
1257 struct usbnet *dev = usb_get_intfdata(intf); 1260 struct usbnet *dev = usb_get_intfdata(intf);
1258 1261
1259 /* accelerate emptying of the rx and queues, to avoid 1262 /* accelerate emptying of the rx and queues, to avoid
1260 * having everything error out. 1263 * having everything error out.
1261 */ 1264 */
@@ -1286,7 +1289,7 @@ static int __init usbnet_init(void)
1286 < sizeof (struct skb_data)); 1289 < sizeof (struct skb_data));
1287 1290
1288 random_ether_addr(node_id); 1291 random_ether_addr(node_id);
1289 return 0; 1292 return 0;
1290} 1293}
1291module_init(usbnet_init); 1294module_init(usbnet_init);
1292 1295
diff --git a/drivers/usb/serial/airprime.c b/drivers/usb/serial/airprime.c
index 0af42e32fa..18816bf96a 100644
--- a/drivers/usb/serial/airprime.c
+++ b/drivers/usb/serial/airprime.c
@@ -58,11 +58,6 @@ static void airprime_read_bulk_callback(struct urb *urb)
58 if (urb->status) { 58 if (urb->status) {
59 dbg("%s - nonzero read bulk status received: %d", 59 dbg("%s - nonzero read bulk status received: %d",
60 __FUNCTION__, urb->status); 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; 61 return;
67 } 62 }
68 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 63 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
@@ -146,6 +141,8 @@ static int airprime_open(struct usb_serial_port *port, struct file *filp)
146 airprime_read_bulk_callback, port); 141 airprime_read_bulk_callback, port);
147 result = usb_submit_urb(urb, GFP_KERNEL); 142 result = usb_submit_urb(urb, GFP_KERNEL);
148 if (result) { 143 if (result) {
144 usb_free_urb(urb);
145 kfree(buffer);
149 dev_err(&port->dev, 146 dev_err(&port->dev,
150 "%s - failed submitting read urb %d for port %d, error %d\n", 147 "%s - failed submitting read urb %d for port %d, error %d\n",
151 __FUNCTION__, i, port->number, result); 148 __FUNCTION__, i, port->number, result);
@@ -160,27 +157,12 @@ static int airprime_open(struct usb_serial_port *port, struct file *filp)
160 /* some error happened, cancel any submitted urbs and clean up anything that 157 /* some error happened, cancel any submitted urbs and clean up anything that
161 got allocated successfully */ 158 got allocated successfully */
162 159
163 for ( ; i >= 0; --i) { 160 while (i-- != 0) {
164 urb = priv->read_urbp[i]; 161 urb = priv->read_urbp[i];
165 if (urb) { 162 buffer = urb->transfer_buffer;
166 /* This urb was submitted successfully. So we have to 163 usb_kill_urb (urb);
167 cancel it. 164 usb_free_urb (urb);
168 Unlinking the urb will invoke read_bulk_callback() 165 kfree (buffer);
169 with an error status, so its transfer buffer will
170 be freed there */
171 if (usb_unlink_urb (urb) != -EINPROGRESS) {
172 /* comments in drivers/usb/core/urb.c say this
173 can only happen if the urb was never submitted,
174 or has completed already.
175 Either way we may have to free the transfer
176 buffer here. */
177 if (urb->transfer_buffer) {
178 kfree (urb->transfer_buffer);
179 urb->transfer_buffer = NULL;
180 }
181 }
182 usb_free_urb (urb);
183 }
184 } 166 }
185 167
186 out: 168 out:
@@ -194,10 +176,9 @@ static void airprime_close(struct usb_serial_port *port, struct file * filp)
194 176
195 dbg("%s - port %d", __FUNCTION__, port->number); 177 dbg("%s - port %d", __FUNCTION__, port->number);
196 178
197 /* killing the urb will invoke read_bulk_callback() with an error status,
198 so the transfer buffer will be freed there */
199 for (i = 0; i < NUM_READ_URBS; ++i) { 179 for (i = 0; i < NUM_READ_URBS; ++i) {
200 usb_kill_urb (priv->read_urbp[i]); 180 usb_kill_urb (priv->read_urbp[i]);
181 kfree (priv->read_urbp[i]->transfer_buffer);
201 usb_free_urb (priv->read_urbp[i]); 182 usb_free_urb (priv->read_urbp[i]);
202 } 183 }
203 184
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c
index 3ec24870bc..db623e7548 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp2101.c
@@ -69,6 +69,7 @@ static struct usb_device_id id_table [] = {
69 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ 69 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */
70 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ 70 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
71 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ 71 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
72 { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */
72 { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */ 73 { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */
73 { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */ 74 { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */
74 { } /* Terminating Entry */ 75 { } /* Terminating Entry */
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 4695952b64..c525b42dad 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -513,6 +513,7 @@ static struct usb_device_id id_table_combined [] = {
513 { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13S_PID) }, 513 { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13S_PID) },
514 { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13U_PID) }, 514 { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13U_PID) },
515 { USB_DEVICE(ELEKTOR_VID, ELEKTOR_FT323R_PID) }, 515 { USB_DEVICE(ELEKTOR_VID, ELEKTOR_FT323R_PID) },
516 { USB_DEVICE(TELLDUS_VID, TELLDUS_TELLSTICK_PID) },
516 { }, /* Optional parameter entry */ 517 { }, /* Optional parameter entry */
517 { } /* Terminating entry */ 518 { } /* Terminating entry */
518}; 519};
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index 7eff1c03ba..1bdda935f7 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -491,6 +491,12 @@
491#define FTDI_TACTRIX_OPENPORT_13S_PID 0xCC49 /* OpenPort 1.3 Subaru */ 491#define FTDI_TACTRIX_OPENPORT_13S_PID 0xCC49 /* OpenPort 1.3 Subaru */
492#define FTDI_TACTRIX_OPENPORT_13U_PID 0xCC4A /* OpenPort 1.3 Universal */ 492#define FTDI_TACTRIX_OPENPORT_13U_PID 0xCC4A /* OpenPort 1.3 Universal */
493 493
494/*
495 * Telldus Technologies
496 */
497#define TELLDUS_VID 0x1781 /* Vendor ID */
498#define TELLDUS_TELLSTICK_PID 0x0C30 /* RF control dongle 433 MHz using FT232RL */
499
494/* Commands */ 500/* Commands */
495#define FTDI_SIO_RESET 0 /* Reset the port */ 501#define FTDI_SIO_RESET 0 /* Reset the port */
496#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */ 502#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 601e0648de..53baeec8f2 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -66,6 +66,8 @@ struct usb_serial_driver usb_serial_generic_device = {
66 .num_bulk_out = NUM_DONT_CARE, 66 .num_bulk_out = NUM_DONT_CARE,
67 .num_ports = 1, 67 .num_ports = 1,
68 .shutdown = usb_serial_generic_shutdown, 68 .shutdown = usb_serial_generic_shutdown,
69 .throttle = usb_serial_generic_throttle,
70 .unthrottle = usb_serial_generic_unthrottle,
69}; 71};
70 72
71static int generic_probe(struct usb_interface *interface, 73static int generic_probe(struct usb_interface *interface,
@@ -115,6 +117,7 @@ int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
115{ 117{
116 struct usb_serial *serial = port->serial; 118 struct usb_serial *serial = port->serial;
117 int result = 0; 119 int result = 0;
120 unsigned long flags;
118 121
119 dbg("%s - port %d", __FUNCTION__, port->number); 122 dbg("%s - port %d", __FUNCTION__, port->number);
120 123
@@ -124,7 +127,13 @@ int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
124 if (port->tty) 127 if (port->tty)
125 port->tty->low_latency = 1; 128 port->tty->low_latency = 1;
126 129
127 /* if we have a bulk interrupt, start reading from it */ 130 /* clear the throttle flags */
131 spin_lock_irqsave(&port->lock, flags);
132 port->throttled = 0;
133 port->throttle_req = 0;
134 spin_unlock_irqrestore(&port->lock, flags);
135
136 /* if we have a bulk endpoint, start reading from it */
128 if (serial->num_bulk_in) { 137 if (serial->num_bulk_in) {
129 /* Start reading from the device */ 138 /* Start reading from the device */
130 usb_fill_bulk_urb (port->read_urb, serial->dev, 139 usb_fill_bulk_urb (port->read_urb, serial->dev,
@@ -253,31 +262,22 @@ int usb_serial_generic_chars_in_buffer (struct usb_serial_port *port)
253 return (chars); 262 return (chars);
254} 263}
255 264
256void usb_serial_generic_read_bulk_callback (struct urb *urb) 265/* Push data to tty layer and resubmit the bulk read URB */
266static void flush_and_resubmit_read_urb (struct usb_serial_port *port)
257{ 267{
258 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
259 struct usb_serial *serial = port->serial; 268 struct usb_serial *serial = port->serial;
260 struct tty_struct *tty; 269 struct urb *urb = port->read_urb;
261 unsigned char *data = urb->transfer_buffer; 270 struct tty_struct *tty = port->tty;
262 int result; 271 int result;
263 272
264 dbg("%s - port %d", __FUNCTION__, port->number); 273 /* Push data to tty */
265
266 if (urb->status) {
267 dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
268 return;
269 }
270
271 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
272
273 tty = port->tty;
274 if (tty && urb->actual_length) { 274 if (tty && urb->actual_length) {
275 tty_buffer_request_room(tty, urb->actual_length); 275 tty_buffer_request_room(tty, urb->actual_length);
276 tty_insert_flip_string(tty, data, urb->actual_length); 276 tty_insert_flip_string(tty, urb->transfer_buffer, urb->actual_length);
277 tty_flip_buffer_push(tty); 277 tty_flip_buffer_push(tty); /* is this allowed from an URB callback ? */
278 } 278 }
279 279
280 /* Continue trying to always read */ 280 /* Continue reading from device */
281 usb_fill_bulk_urb (port->read_urb, serial->dev, 281 usb_fill_bulk_urb (port->read_urb, serial->dev,
282 usb_rcvbulkpipe (serial->dev, 282 usb_rcvbulkpipe (serial->dev,
283 port->bulk_in_endpointAddress), 283 port->bulk_in_endpointAddress),
@@ -290,6 +290,40 @@ void usb_serial_generic_read_bulk_callback (struct urb *urb)
290 if (result) 290 if (result)
291 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); 291 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
292} 292}
293
294void usb_serial_generic_read_bulk_callback (struct urb *urb)
295{
296 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
297 unsigned char *data = urb->transfer_buffer;
298 int is_throttled;
299 unsigned long flags;
300
301 dbg("%s - port %d", __FUNCTION__, port->number);
302
303 if (urb->status) {
304 dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
305 return;
306 }
307
308 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
309
310 /* Throttle the device if requested by tty */
311 if (urb->actual_length) {
312 spin_lock_irqsave(&port->lock, flags);
313 is_throttled = port->throttled = port->throttle_req;
314 spin_unlock_irqrestore(&port->lock, flags);
315 if (is_throttled) {
316 /* Let the received data linger in the read URB;
317 * usb_serial_generic_unthrottle() will pick it
318 * up later. */
319 dbg("%s - throttling device", __FUNCTION__);
320 return;
321 }
322 }
323
324 /* Handle data and continue reading from device */
325 flush_and_resubmit_read_urb(port);
326}
293EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback); 327EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback);
294 328
295void usb_serial_generic_write_bulk_callback (struct urb *urb) 329void usb_serial_generic_write_bulk_callback (struct urb *urb)
@@ -308,6 +342,38 @@ void usb_serial_generic_write_bulk_callback (struct urb *urb)
308} 342}
309EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); 343EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback);
310 344
345void usb_serial_generic_throttle (struct usb_serial_port *port)
346{
347 unsigned long flags;
348
349 dbg("%s - port %d", __FUNCTION__, port->number);
350
351 /* Set the throttle request flag. It will be picked up
352 * by usb_serial_generic_read_bulk_callback(). */
353 spin_lock_irqsave(&port->lock, flags);
354 port->throttle_req = 1;
355 spin_unlock_irqrestore(&port->lock, flags);
356}
357
358void usb_serial_generic_unthrottle (struct usb_serial_port *port)
359{
360 int was_throttled;
361 unsigned long flags;
362
363 dbg("%s - port %d", __FUNCTION__, port->number);
364
365 /* Clear the throttle flags */
366 spin_lock_irqsave(&port->lock, flags);
367 was_throttled = port->throttled;
368 port->throttled = port->throttle_req = 0;
369 spin_unlock_irqrestore(&port->lock, flags);
370
371 if (was_throttled) {
372 /* Handle pending data and resume reading from device */
373 flush_and_resubmit_read_urb(port);
374 }
375}
376
311void usb_serial_generic_shutdown (struct usb_serial *serial) 377void usb_serial_generic_shutdown (struct usb_serial *serial)
312{ 378{
313 int i; 379 int i;
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index ced9f32b29..db92a7fb1f 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -67,54 +67,95 @@ static int option_tiocmset(struct usb_serial_port *port, struct file *file,
67static int option_send_setup(struct usb_serial_port *port); 67static int option_send_setup(struct usb_serial_port *port);
68 68
69/* Vendor and product IDs */ 69/* Vendor and product IDs */
70#define OPTION_VENDOR_ID 0x0AF0 70#define OPTION_VENDOR_ID 0x0AF0
71#define HUAWEI_VENDOR_ID 0x12D1 71#define OPTION_PRODUCT_COLT 0x5000
72#define AUDIOVOX_VENDOR_ID 0x0F3D 72#define OPTION_PRODUCT_RICOLA 0x6000
73#define NOVATELWIRELESS_VENDOR_ID 0x1410 73#define OPTION_PRODUCT_RICOLA_LIGHT 0x6100
74#define ANYDATA_VENDOR_ID 0x16d5 74#define OPTION_PRODUCT_RICOLA_QUAD 0x6200
75 75#define OPTION_PRODUCT_RICOLA_QUAD_LIGHT 0x6300
76#define OPTION_PRODUCT_OLD 0x5000 76#define OPTION_PRODUCT_RICOLA_NDIS 0x6050
77#define OPTION_PRODUCT_FUSION 0x6000 77#define OPTION_PRODUCT_RICOLA_NDIS_LIGHT 0x6150
78#define OPTION_PRODUCT_FUSION2 0x6300 78#define OPTION_PRODUCT_RICOLA_NDIS_QUAD 0x6250
79#define OPTION_PRODUCT_COBRA 0x6500 79#define OPTION_PRODUCT_RICOLA_NDIS_QUAD_LIGHT 0x6350
80#define OPTION_PRODUCT_COBRA2 0x6600 80#define OPTION_PRODUCT_COBRA 0x6500
81#define OPTION_PRODUCT_GTMAX36 0x6701 81#define OPTION_PRODUCT_COBRA_BUS 0x6501
82#define HUAWEI_PRODUCT_E600 0x1001 82#define OPTION_PRODUCT_VIPER 0x6600
83#define HUAWEI_PRODUCT_E220 0x1003 83#define OPTION_PRODUCT_VIPER_BUS 0x6601
84#define AUDIOVOX_PRODUCT_AIRCARD 0x0112 84#define OPTION_PRODUCT_GT_MAX_READY 0x6701
85#define NOVATELWIRELESS_PRODUCT_U740 0x1400 85#define OPTION_PRODUCT_GT_MAX 0x6711
86#define ANYDATA_PRODUCT_ID 0x6501 86#define OPTION_PRODUCT_FUJI_MODEM_LIGHT 0x6721
87#define OPTION_PRODUCT_FUJI_MODEM_GT 0x6741
88#define OPTION_PRODUCT_FUJI_MODEM_EX 0x6761
89#define OPTION_PRODUCT_FUJI_NETWORK_LIGHT 0x6731
90#define OPTION_PRODUCT_FUJI_NETWORK_GT 0x6751
91#define OPTION_PRODUCT_FUJI_NETWORK_EX 0x6771
92#define OPTION_PRODUCT_KOI_MODEM 0x6800
93#define OPTION_PRODUCT_KOI_NETWORK 0x6811
94#define OPTION_PRODUCT_SCORPION_MODEM 0x6901
95#define OPTION_PRODUCT_SCORPION_NETWORK 0x6911
96#define OPTION_PRODUCT_ETNA_MODEM 0x7001
97#define OPTION_PRODUCT_ETNA_NETWORK 0x7011
98#define OPTION_PRODUCT_ETNA_MODEM_LITE 0x7021
99#define OPTION_PRODUCT_ETNA_MODEM_GT 0x7041
100#define OPTION_PRODUCT_ETNA_MODEM_EX 0x7061
101#define OPTION_PRODUCT_ETNA_NETWORK_LITE 0x7031
102#define OPTION_PRODUCT_ETNA_NETWORK_GT 0x7051
103#define OPTION_PRODUCT_ETNA_NETWORK_EX 0x7071
104#define OPTION_PRODUCT_ETNA_KOI_MODEM 0x7100
105#define OPTION_PRODUCT_ETNA_KOI_NETWORK 0x7111
106
107#define HUAWEI_VENDOR_ID 0x12D1
108#define HUAWEI_PRODUCT_E600 0x1001
109#define HUAWEI_PRODUCT_E220 0x1003
110
111#define NOVATELWIRELESS_VENDOR_ID 0x1410
112#define NOVATELWIRELESS_PRODUCT_U740 0x1400
113
114#define ANYDATA_VENDOR_ID 0x16d5
115#define ANYDATA_PRODUCT_ID 0x6501
87 116
88static struct usb_device_id option_ids[] = { 117static struct usb_device_id option_ids[] = {
89 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) }, 118 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) },
90 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) }, 119 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) },
91 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) }, 120 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_LIGHT) },
121 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_QUAD) },
122 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_QUAD_LIGHT) },
123 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_NDIS) },
124 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_NDIS_LIGHT) },
125 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_NDIS_QUAD) },
126 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_NDIS_QUAD_LIGHT) },
92 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) }, 127 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) },
93 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) }, 128 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA_BUS) },
94 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GTMAX36) }, 129 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_VIPER) },
130 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_VIPER_BUS) },
131 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GT_MAX_READY) },
132 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GT_MAX) },
133 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUJI_MODEM_LIGHT) },
134 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUJI_MODEM_GT) },
135 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUJI_MODEM_EX) },
136 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUJI_NETWORK_LIGHT) },
137 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUJI_NETWORK_GT) },
138 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUJI_NETWORK_EX) },
139 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_KOI_MODEM) },
140 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_KOI_NETWORK) },
141 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_SCORPION_MODEM) },
142 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_SCORPION_NETWORK) },
143 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_MODEM) },
144 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_NETWORK) },
145 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_MODEM_LITE) },
146 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_MODEM_GT) },
147 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_MODEM_EX) },
148 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_NETWORK_LITE) },
149 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_NETWORK_GT) },
150 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_NETWORK_EX) },
151 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_KOI_MODEM) },
152 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_KOI_NETWORK) },
95 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) }, 153 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
96 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) }, 154 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) },
97 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
98 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) }, 155 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) },
99 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) }, 156 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) },
100 { } /* Terminating entry */ 157 { } /* Terminating entry */
101}; 158};
102
103static struct usb_device_id option_ids1[] = {
104 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) },
105 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) },
106 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) },
107 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) },
108 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) },
109 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GTMAX36) },
110 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
111 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) },
112 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
113 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) },
114 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) },
115 { } /* Terminating entry */
116};
117
118MODULE_DEVICE_TABLE(usb, option_ids); 159MODULE_DEVICE_TABLE(usb, option_ids);
119 160
120static struct usb_driver option_driver = { 161static struct usb_driver option_driver = {
@@ -136,7 +177,7 @@ static struct usb_serial_driver option_1port_device = {
136 }, 177 },
137 .description = "GSM modem (1-port)", 178 .description = "GSM modem (1-port)",
138 .usb_driver = &option_driver, 179 .usb_driver = &option_driver,
139 .id_table = option_ids1, 180 .id_table = option_ids,
140 .num_interrupt_in = NUM_DONT_CARE, 181 .num_interrupt_in = NUM_DONT_CARE,
141 .num_bulk_in = NUM_DONT_CARE, 182 .num_bulk_in = NUM_DONT_CARE,
142 .num_bulk_out = NUM_DONT_CARE, 183 .num_bulk_out = NUM_DONT_CARE,
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 6c083d4e2c..83dfae93a4 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -83,6 +83,7 @@ static struct usb_device_id id_table [] = {
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) }, 84 { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) },
85 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ID) }, 85 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ID) },
86 { USB_DEVICE(WS002IN_VENDOR_ID, WS002IN_PRODUCT_ID) },
86 { } /* Terminating entry */ 87 { } /* Terminating entry */
87}; 88};
88 89
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index 65a5039665..f9a71d0c10 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -97,3 +97,8 @@
97/* Huawei E620 UMTS/HSDPA card (ID: 12d1:1001) */ 97/* Huawei E620 UMTS/HSDPA card (ID: 12d1:1001) */
98#define HUAWEI_VENDOR_ID 0x12d1 98#define HUAWEI_VENDOR_ID 0x12d1
99#define HUAWEI_PRODUCT_ID 0x1001 99#define HUAWEI_PRODUCT_ID 0x1001
100
101/* Willcom WS002IN Data Driver (by NetIndex Inc.) */
102#define WS002IN_VENDOR_ID 0x11f6
103#define WS002IN_PRODUCT_ID 0x2001
104
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 70234f5dbe..e227f64d56 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -153,6 +153,12 @@ static int slave_configure(struct scsi_device *sdev)
153 if (us->flags & US_FL_FIX_CAPACITY) 153 if (us->flags & US_FL_FIX_CAPACITY)
154 sdev->fix_capacity = 1; 154 sdev->fix_capacity = 1;
155 155
156 /* A few disks have two indistinguishable version, one of
157 * which reports the correct capacity and the other does not.
158 * The sd driver has to guess which is the case. */
159 if (us->flags & US_FL_CAPACITY_HEURISTICS)
160 sdev->guess_capacity = 1;
161
156 /* Some devices report a SCSI revision level above 2 but are 162 /* Some devices report a SCSI revision level above 2 but are
157 * unable to handle the REPORT LUNS command (for which 163 * unable to handle the REPORT LUNS command (for which
158 * support is mandatory at level 3). Since we already have 164 * support is mandatory at level 3). Since we already have
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index f49a62fc32..9644a8ea4a 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -1101,6 +1101,15 @@ UNUSUAL_DEV( 0x08bd, 0x1100, 0x0000, 0x0000,
1101 US_SC_DEVICE, US_PR_DEVICE, NULL, 1101 US_SC_DEVICE, US_PR_DEVICE, NULL,
1102 US_FL_SINGLE_LUN), 1102 US_FL_SINGLE_LUN),
1103 1103
1104/* Submitted by Dylan Taft <d13f00l@gmail.com>
1105 * US_FL_IGNORE_RESIDUE Needed
1106 */
1107UNUSUAL_DEV( 0x08ca, 0x3103, 0x0100, 0x0100,
1108 "AIPTEK",
1109 "Aiptek USB Keychain MP3 Player",
1110 US_SC_DEVICE, US_PR_DEVICE, NULL,
1111 US_FL_IGNORE_RESIDUE),
1112
1104/* Entry needed for flags. Moreover, all devices with this ID use 1113/* Entry needed for flags. Moreover, all devices with this ID use
1105 * bulk-only transport, but _some_ falsely report Control/Bulk instead. 1114 * bulk-only transport, but _some_ falsely report Control/Bulk instead.
1106 * One example is "Trumpion Digital Research MYMP3". 1115 * One example is "Trumpion Digital Research MYMP3".
@@ -1311,12 +1320,13 @@ UNUSUAL_DEV( 0x0fce, 0xd008, 0x0000, 0x0000,
1311 US_SC_DEVICE, US_PR_DEVICE, NULL, 1320 US_SC_DEVICE, US_PR_DEVICE, NULL,
1312 US_FL_NO_WP_DETECT ), 1321 US_FL_NO_WP_DETECT ),
1313 1322
1314/* Reported by Jan Mate <mate@fiit.stuba.sk> */ 1323/* Reported by Jan Mate <mate@fiit.stuba.sk>
1324 * and by Soeren Sonnenburg <kernel@nn7.de> */
1315UNUSUAL_DEV( 0x0fce, 0xe030, 0x0000, 0x0000, 1325UNUSUAL_DEV( 0x0fce, 0xe030, 0x0000, 0x0000,
1316 "Sony Ericsson", 1326 "Sony Ericsson",
1317 "P990i", 1327 "P990i",
1318 US_SC_DEVICE, US_PR_DEVICE, NULL, 1328 US_SC_DEVICE, US_PR_DEVICE, NULL,
1319 US_FL_FIX_CAPACITY ), 1329 US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ),
1320 1330
1321/* Reported by Emmanuel Vasilakis <evas@forthnet.gr> */ 1331/* Reported by Emmanuel Vasilakis <evas@forthnet.gr> */
1322UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000, 1332UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000,
@@ -1385,6 +1395,16 @@ UNUSUAL_DEV( 0x1652, 0x6600, 0x0201, 0x0201,
1385 US_SC_DEVICE, US_PR_DEVICE, NULL, 1395 US_SC_DEVICE, US_PR_DEVICE, NULL,
1386 US_FL_IGNORE_RESIDUE ), 1396 US_FL_IGNORE_RESIDUE ),
1387 1397
1398/* Reported by Thomas Baechler <thomas@archlinux.org>
1399 * Fixes I/O errors with Teac HD-35PU devices
1400 */
1401
1402UNUSUAL_DEV( 0x1652, 0x6600, 0x0201, 0x0201,
1403 "Super Top",
1404 "USB 2.0 IDE DEVICE",
1405 US_SC_DEVICE, US_PR_DEVICE, NULL,
1406 US_FL_IGNORE_RESIDUE),
1407
1388/* patch submitted by Davide Perini <perini.davide@dpsoftware.org> 1408/* patch submitted by Davide Perini <perini.davide@dpsoftware.org>
1389 * and Renato Perini <rperini@email.it> 1409 * and Renato Perini <rperini@email.it>
1390 */ 1410 */
@@ -1423,7 +1443,7 @@ UNUSUAL_DEV( 0xed06, 0x4500, 0x0001, 0x0001,
1423 "DataStor", 1443 "DataStor",
1424 "USB4500 FW1.04", 1444 "USB4500 FW1.04",
1425 US_SC_DEVICE, US_PR_DEVICE, NULL, 1445 US_SC_DEVICE, US_PR_DEVICE, NULL,
1426 US_FL_FIX_CAPACITY), 1446 US_FL_CAPACITY_HEURISTICS),
1427 1447
1428/* Control/Bulk transport for all SubClass values */ 1448/* Control/Bulk transport for all SubClass values */
1429USUAL_DEV(US_SC_RBC, US_PR_CB, USB_US_TYPE_STOR), 1449USUAL_DEV(US_SC_RBC, US_PR_CB, USB_US_TYPE_STOR),
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 7e7ec29782..8e898e3d86 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -55,7 +55,7 @@
55#include <linux/slab.h> 55#include <linux/slab.h>
56#include <linux/kthread.h> 56#include <linux/kthread.h>
57#include <linux/mutex.h> 57#include <linux/mutex.h>
58#include <linux/utsrelease.h> 58#include <linux/utsname.h>
59 59
60#include <scsi/scsi.h> 60#include <scsi/scsi.h>
61#include <scsi/scsi_cmnd.h> 61#include <scsi/scsi_cmnd.h>
@@ -547,7 +547,7 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id)
547 idesc->bInterfaceSubClass, 547 idesc->bInterfaceSubClass,
548 idesc->bInterfaceProtocol, 548 idesc->bInterfaceProtocol,
549 msgs[msg], 549 msgs[msg],
550 UTS_RELEASE); 550 utsname()->release);
551 } 551 }
552 552
553 return 0; 553 return 0;
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index 296b091cf1..46929a1b6f 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -90,13 +90,15 @@ static int skel_open(struct inode *inode, struct file *file)
90 goto exit; 90 goto exit;
91 } 91 }
92 92
93 /* increment our usage count for the device */
94 kref_get(&dev->kref);
95
93 /* prevent the device from being autosuspended */ 96 /* prevent the device from being autosuspended */
94 retval = usb_autopm_get_interface(interface); 97 retval = usb_autopm_get_interface(interface);
95 if (retval) 98 if (retval) {
99 kref_put(&dev->kref, skel_delete);
96 goto exit; 100 goto exit;
97 101 }
98 /* increment our usage count for the device */
99 kref_get(&dev->kref);
100 102
101 /* save our object in the file's private structure */ 103 /* save our object in the file's private structure */
102 file->private_data = dev; 104 file->private_data = dev;
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 8874cf2fd2..7f5a598368 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -4,20 +4,7 @@
4 4
5menu "Graphics support" 5menu "Graphics support"
6 6
7config FIRMWARE_EDID 7source "drivers/video/backlight/Kconfig"
8 bool "Enable firmware EDID"
9 default y
10 ---help---
11 This enables access to the EDID transferred from the firmware.
12 On the i386, this is from the Video BIOS. Enable this if DDC/I2C
13 transfers do not work for your driver and if you are using
14 nvidiafb, i810fb or savagefb.
15
16 In general, choosing Y for this option is safe. If you
17 experience extremely long delays while booting before you get
18 something on your display, try setting this to N. Matrox cards in
19 combination with certain motherboards and monitors are known to
20 suffer from this problem.
21 8
22config FB 9config FB
23 tristate "Support for frame buffer devices" 10 tristate "Support for frame buffer devices"
@@ -53,9 +40,27 @@ config FB
53 (e.g. an accelerated X server) and that are not frame buffer 40 (e.g. an accelerated X server) and that are not frame buffer
54 device-aware may cause unexpected results. If unsure, say N. 41 device-aware may cause unexpected results. If unsure, say N.
55 42
43config FIRMWARE_EDID
44 bool "Enable firmware EDID"
45 depends on FB
46 default n
47 ---help---
48 This enables access to the EDID transferred from the firmware.
49 On the i386, this is from the Video BIOS. Enable this if DDC/I2C
50 transfers do not work for your driver and if you are using
51 nvidiafb, i810fb or savagefb.
52
53 In general, choosing Y for this option is safe. If you
54 experience extremely long delays while booting before you get
55 something on your display, try setting this to N. Matrox cards in
56 combination with certain motherboards and monitors are known to
57 suffer from this problem.
58
56config FB_DDC 59config FB_DDC
57 tristate 60 tristate
58 depends on FB && I2C && I2C_ALGOBIT 61 depends on FB
62 select I2C_ALGOBIT
63 select I2C
59 default n 64 default n
60 65
61config FB_CFB_FILLRECT 66config FB_CFB_FILLRECT
@@ -134,6 +139,9 @@ config FB_TILEBLITTING
134 This is particularly important to one driver, matroxfb. If 139 This is particularly important to one driver, matroxfb. If
135 unsure, say N. 140 unsure, say N.
136 141
142comment "Frambuffer hardware drivers"
143 depends on FB
144
137config FB_CIRRUS 145config FB_CIRRUS
138 tristate "Cirrus Logic support" 146 tristate "Cirrus Logic support"
139 depends on FB && (ZORRO || PCI) 147 depends on FB && (ZORRO || PCI)
@@ -669,8 +677,7 @@ config FB_S1D13XXX
669config FB_NVIDIA 677config FB_NVIDIA
670 tristate "nVidia Framebuffer Support" 678 tristate "nVidia Framebuffer Support"
671 depends on FB && PCI 679 depends on FB && PCI
672 select I2C_ALGOBIT if FB_NVIDIA_I2C 680 select FB_BACKLIGHT if FB_NVIDIA_BACKLIGHT
673 select I2C if FB_NVIDIA_I2C
674 select FB_MODE_HELPERS 681 select FB_MODE_HELPERS
675 select FB_CFB_FILLRECT 682 select FB_CFB_FILLRECT
676 select FB_CFB_COPYAREA 683 select FB_CFB_COPYAREA
@@ -688,6 +695,7 @@ config FB_NVIDIA
688config FB_NVIDIA_I2C 695config FB_NVIDIA_I2C
689 bool "Enable DDC Support" 696 bool "Enable DDC Support"
690 depends on FB_NVIDIA 697 depends on FB_NVIDIA
698 select FB_DDC
691 help 699 help
692 This enables I2C support for nVidia Chipsets. This is used 700 This enables I2C support for nVidia Chipsets. This is used
693 only for getting EDID information from the attached display 701 only for getting EDID information from the attached display
@@ -699,8 +707,7 @@ config FB_NVIDIA_I2C
699 707
700config FB_NVIDIA_BACKLIGHT 708config FB_NVIDIA_BACKLIGHT
701 bool "Support for backlight control" 709 bool "Support for backlight control"
702 depends on FB_NVIDIA && PMAC_BACKLIGHT 710 depends on FB_NVIDIA
703 select FB_BACKLIGHT
704 default y 711 default y
705 help 712 help
706 Say Y here if you want to control the backlight of your display. 713 Say Y here if you want to control the backlight of your display.
@@ -708,9 +715,7 @@ config FB_NVIDIA_BACKLIGHT
708config FB_RIVA 715config FB_RIVA
709 tristate "nVidia Riva support" 716 tristate "nVidia Riva support"
710 depends on FB && PCI 717 depends on FB && PCI
711 select I2C_ALGOBIT if FB_RIVA_I2C 718 select FB_BACKLIGHT if FB_RIVA_BACKLIGHT
712 select I2C if FB_RIVA_I2C
713 select FB_DDC if FB_RIVA_I2C
714 select FB_MODE_HELPERS 719 select FB_MODE_HELPERS
715 select FB_CFB_FILLRECT 720 select FB_CFB_FILLRECT
716 select FB_CFB_COPYAREA 721 select FB_CFB_COPYAREA
@@ -727,6 +732,7 @@ config FB_RIVA
727config FB_RIVA_I2C 732config FB_RIVA_I2C
728 bool "Enable DDC Support" 733 bool "Enable DDC Support"
729 depends on FB_RIVA 734 depends on FB_RIVA
735 select FB_DDC
730 help 736 help
731 This enables I2C support for nVidia Chipsets. This is used 737 This enables I2C support for nVidia Chipsets. This is used
732 only for getting EDID information from the attached display 738 only for getting EDID information from the attached display
@@ -747,8 +753,7 @@ config FB_RIVA_DEBUG
747 753
748config FB_RIVA_BACKLIGHT 754config FB_RIVA_BACKLIGHT
749 bool "Support for backlight control" 755 bool "Support for backlight control"
750 depends on FB_RIVA && PMAC_BACKLIGHT 756 depends on FB_RIVA
751 select FB_BACKLIGHT
752 default y 757 default y
753 help 758 help
754 Say Y here if you want to control the backlight of your display. 759 Say Y here if you want to control the backlight of your display.
@@ -798,8 +803,6 @@ config FB_I810_GTF
798config FB_I810_I2C 803config FB_I810_I2C
799 bool "Enable DDC Support" 804 bool "Enable DDC Support"
800 depends on FB_I810 && FB_I810_GTF 805 depends on FB_I810 && FB_I810_GTF
801 select I2C
802 select I2C_ALGOBIT
803 select FB_DDC 806 select FB_DDC
804 help 807 help
805 808
@@ -808,8 +811,6 @@ config FB_INTEL
808 depends on FB && EXPERIMENTAL && PCI && X86 811 depends on FB && EXPERIMENTAL && PCI && X86
809 select AGP 812 select AGP
810 select AGP_INTEL 813 select AGP_INTEL
811 select I2C_ALGOBIT if FB_INTEL_I2C
812 select I2C if FB_INTEL_I2C
813 select FB_MODE_HELPERS 814 select FB_MODE_HELPERS
814 select FB_CFB_FILLRECT 815 select FB_CFB_FILLRECT
815 select FB_CFB_COPYAREA 816 select FB_CFB_COPYAREA
@@ -842,6 +843,7 @@ config FB_INTEL_DEBUG
842config FB_INTEL_I2C 843config FB_INTEL_I2C
843 bool "DDC/I2C for Intel framebuffer support" 844 bool "DDC/I2C for Intel framebuffer support"
844 depends on FB_INTEL 845 depends on FB_INTEL
846 select FB_DDC
845 default y 847 default y
846 help 848 help
847 Say Y here if you want DDC/I2C support for your on-board Intel graphics. 849 Say Y here if you want DDC/I2C support for your on-board Intel graphics.
@@ -920,8 +922,8 @@ config FB_MATROX_G
920 922
921config FB_MATROX_I2C 923config FB_MATROX_I2C
922 tristate "Matrox I2C support" 924 tristate "Matrox I2C support"
923 depends on FB_MATROX && I2C 925 depends on FB_MATROX
924 select I2C_ALGOBIT 926 select FB_DDC
925 ---help--- 927 ---help---
926 This drivers creates I2C buses which are needed for accessing the 928 This drivers creates I2C buses which are needed for accessing the
927 DDC (I2C) bus present on all Matroxes, an I2C bus which 929 DDC (I2C) bus present on all Matroxes, an I2C bus which
@@ -989,9 +991,7 @@ config FB_MATROX_MULTIHEAD
989config FB_RADEON 991config FB_RADEON
990 tristate "ATI Radeon display support" 992 tristate "ATI Radeon display support"
991 depends on FB && PCI 993 depends on FB && PCI
992 select I2C_ALGOBIT if FB_RADEON_I2C 994 select FB_BACKLIGHT if FB_RADEON_BACKLIGHT
993 select I2C if FB_RADEON_I2C
994 select FB_DDC if FB_RADEON_I2C
995 select FB_MODE_HELPERS 995 select FB_MODE_HELPERS
996 select FB_CFB_FILLRECT 996 select FB_CFB_FILLRECT
997 select FB_CFB_COPYAREA 997 select FB_CFB_COPYAREA
@@ -1015,14 +1015,14 @@ config FB_RADEON
1015config FB_RADEON_I2C 1015config FB_RADEON_I2C
1016 bool "DDC/I2C for ATI Radeon support" 1016 bool "DDC/I2C for ATI Radeon support"
1017 depends on FB_RADEON 1017 depends on FB_RADEON
1018 select FB_DDC
1018 default y 1019 default y
1019 help 1020 help
1020 Say Y here if you want DDC/I2C support for your Radeon board. 1021 Say Y here if you want DDC/I2C support for your Radeon board.
1021 1022
1022config FB_RADEON_BACKLIGHT 1023config FB_RADEON_BACKLIGHT
1023 bool "Support for backlight control" 1024 bool "Support for backlight control"
1024 depends on FB_RADEON && PMAC_BACKLIGHT 1025 depends on FB_RADEON
1025 select FB_BACKLIGHT
1026 default y 1026 default y
1027 help 1027 help
1028 Say Y here if you want to control the backlight of your display. 1028 Say Y here if you want to control the backlight of your display.
@@ -1042,6 +1042,7 @@ config FB_ATY128
1042 select FB_CFB_FILLRECT 1042 select FB_CFB_FILLRECT
1043 select FB_CFB_COPYAREA 1043 select FB_CFB_COPYAREA
1044 select FB_CFB_IMAGEBLIT 1044 select FB_CFB_IMAGEBLIT
1045 select FB_BACKLIGHT if FB_ATY128_BACKLIGHT
1045 select FB_MACMODES if PPC_PMAC 1046 select FB_MACMODES if PPC_PMAC
1046 help 1047 help
1047 This driver supports graphics boards with the ATI Rage128 chips. 1048 This driver supports graphics boards with the ATI Rage128 chips.
@@ -1053,8 +1054,7 @@ config FB_ATY128
1053 1054
1054config FB_ATY128_BACKLIGHT 1055config FB_ATY128_BACKLIGHT
1055 bool "Support for backlight control" 1056 bool "Support for backlight control"
1056 depends on FB_ATY128 && PMAC_BACKLIGHT 1057 depends on FB_ATY128
1057 select FB_BACKLIGHT
1058 default y 1058 default y
1059 help 1059 help
1060 Say Y here if you want to control the backlight of your display. 1060 Say Y here if you want to control the backlight of your display.
@@ -1065,6 +1065,7 @@ config FB_ATY
1065 select FB_CFB_FILLRECT 1065 select FB_CFB_FILLRECT
1066 select FB_CFB_COPYAREA 1066 select FB_CFB_COPYAREA
1067 select FB_CFB_IMAGEBLIT 1067 select FB_CFB_IMAGEBLIT
1068 select FB_BACKLIGHT if FB_ATY_BACKLIGHT
1068 select FB_MACMODES if PPC 1069 select FB_MACMODES if PPC
1069 help 1070 help
1070 This driver supports graphics boards with the ATI Mach64 chips. 1071 This driver supports graphics boards with the ATI Mach64 chips.
@@ -1103,8 +1104,7 @@ config FB_ATY_GX
1103 1104
1104config FB_ATY_BACKLIGHT 1105config FB_ATY_BACKLIGHT
1105 bool "Support for backlight control" 1106 bool "Support for backlight control"
1106 depends on FB_ATY && PMAC_BACKLIGHT 1107 depends on FB_ATY
1107 select FB_BACKLIGHT
1108 default y 1108 default y
1109 help 1109 help
1110 Say Y here if you want to control the backlight of your display. 1110 Say Y here if you want to control the backlight of your display.
@@ -1123,9 +1123,6 @@ config FB_S3
1123config FB_SAVAGE 1123config FB_SAVAGE
1124 tristate "S3 Savage support" 1124 tristate "S3 Savage support"
1125 depends on FB && PCI && EXPERIMENTAL 1125 depends on FB && PCI && EXPERIMENTAL
1126 select I2C_ALGOBIT if FB_SAVAGE_I2C
1127 select I2C if FB_SAVAGE_I2C
1128 select FB_DDC if FB_SAVAGE_I2C
1129 select FB_MODE_HELPERS 1126 select FB_MODE_HELPERS
1130 select FB_CFB_FILLRECT 1127 select FB_CFB_FILLRECT
1131 select FB_CFB_COPYAREA 1128 select FB_CFB_COPYAREA
@@ -1142,6 +1139,7 @@ config FB_SAVAGE
1142config FB_SAVAGE_I2C 1139config FB_SAVAGE_I2C
1143 bool "Enable DDC2 Support" 1140 bool "Enable DDC2 Support"
1144 depends on FB_SAVAGE 1141 depends on FB_SAVAGE
1142 select FB_DDC
1145 help 1143 help
1146 This enables I2C support for S3 Savage Chipsets. This is used 1144 This enables I2C support for S3 Savage Chipsets. This is used
1147 only for getting EDID information from the attached display 1145 only for getting EDID information from the attached display
@@ -1573,6 +1571,24 @@ config FB_S3C2410_DEBUG
1573 Turn on debugging messages. Note that you can set/unset at run time 1571 Turn on debugging messages. Note that you can set/unset at run time
1574 through sysfs 1572 through sysfs
1575 1573
1574config FB_SM501
1575 tristate "Silicon Motion SM501 framebuffer support"
1576 depends on FB && MFD_SM501
1577 select FB_CFB_FILLRECT
1578 select FB_CFB_COPYAREA
1579 select FB_CFB_IMAGEBLIT
1580 ---help---
1581 Frame buffer driver for the CRT and LCD controllers in the Silicon
1582 Motion SM501.
1583
1584 This driver is also available as a module ( = code which can be
1585 inserted and removed from the running kernel whenever you want). The
1586 module will be called sm501fb. If you want to compile it as a module,
1587 say M here and read <file:Documentation/modules.txt>.
1588
1589 If unsure, say N.
1590
1591
1576config FB_PNX4008_DUM 1592config FB_PNX4008_DUM
1577 tristate "Display Update Module support on Philips PNX4008 board" 1593 tristate "Display Update Module support on Philips PNX4008 board"
1578 depends on FB && ARCH_PNX4008 1594 depends on FB && ARCH_PNX4008
@@ -1600,8 +1616,7 @@ config FB_IBM_GXT4500
1600 1616
1601config FB_PS3 1617config FB_PS3
1602 bool "PS3 GPU framebuffer driver" 1618 bool "PS3 GPU framebuffer driver"
1603 depends on FB && PPC_PS3 1619 depends on FB && PS3_PS3AV
1604 select PS3_PS3AV
1605 select FB_CFB_FILLRECT 1620 select FB_CFB_FILLRECT
1606 select FB_CFB_COPYAREA 1621 select FB_CFB_COPYAREA
1607 select FB_CFB_IMAGEBLIT 1622 select FB_CFB_IMAGEBLIT
@@ -1639,6 +1654,7 @@ config FB_VIRTUAL
1639 the vfb_enable=1 option. 1654 the vfb_enable=1 option.
1640 1655
1641 If unsure, say N. 1656 If unsure, say N.
1657
1642if VT 1658if VT
1643 source "drivers/video/console/Kconfig" 1659 source "drivers/video/console/Kconfig"
1644endif 1660endif
@@ -1647,9 +1663,5 @@ if FB || SGI_NEWPORT_CONSOLE
1647 source "drivers/video/logo/Kconfig" 1663 source "drivers/video/logo/Kconfig"
1648endif 1664endif
1649 1665
1650if SYSFS
1651 source "drivers/video/backlight/Kconfig"
1652endif
1653
1654endmenu 1666endmenu
1655 1667
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 6801edff36..760305c8a8 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -12,7 +12,7 @@ fb-objs := $(fb-y)
12 12
13obj-$(CONFIG_VT) += console/ 13obj-$(CONFIG_VT) += console/
14obj-$(CONFIG_LOGO) += logo/ 14obj-$(CONFIG_LOGO) += logo/
15obj-$(CONFIG_SYSFS) += backlight/ 15obj-y += backlight/
16 16
17obj-$(CONFIG_FB_CFB_FILLRECT) += cfbfillrect.o 17obj-$(CONFIG_FB_CFB_FILLRECT) += cfbfillrect.o
18obj-$(CONFIG_FB_CFB_COPYAREA) += cfbcopyarea.o 18obj-$(CONFIG_FB_CFB_COPYAREA) += cfbcopyarea.o
@@ -98,6 +98,7 @@ obj-$(CONFIG_FB_PNX4008_DUM) += pnx4008/
98obj-$(CONFIG_FB_PNX4008_DUM_RGB) += pnx4008/ 98obj-$(CONFIG_FB_PNX4008_DUM_RGB) += pnx4008/
99obj-$(CONFIG_FB_IBM_GXT4500) += gxt4500.o 99obj-$(CONFIG_FB_IBM_GXT4500) += gxt4500.o
100obj-$(CONFIG_FB_PS3) += ps3fb.o 100obj-$(CONFIG_FB_PS3) += ps3fb.o
101obj-$(CONFIG_FB_SM501) += sm501fb.o
101 102
102# Platform or fallback drivers go here 103# Platform or fallback drivers go here
103obj-$(CONFIG_FB_VESA) += vesafb.o 104obj-$(CONFIG_FB_VESA) += vesafb.o
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index 2e976ffcde..e86d7e0c98 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -357,6 +357,12 @@ static int default_lcd_on __devinitdata = 1;
357static int mtrr = 1; 357static int mtrr = 1;
358#endif 358#endif
359 359
360#ifdef CONFIG_PMAC_BACKLIGHT
361static int backlight __devinitdata = 1;
362#else
363static int backlight __devinitdata = 0;
364#endif
365
360/* PLL constants */ 366/* PLL constants */
361struct aty128_constants { 367struct aty128_constants {
362 u32 ref_clk; 368 u32 ref_clk;
@@ -1652,6 +1658,9 @@ static int __devinit aty128fb_setup(char *options)
1652 } else if (!strncmp(this_opt, "crt:", 4)) { 1658 } else if (!strncmp(this_opt, "crt:", 4)) {
1653 default_crt_on = simple_strtoul(this_opt+4, NULL, 0); 1659 default_crt_on = simple_strtoul(this_opt+4, NULL, 0);
1654 continue; 1660 continue;
1661 } else if (!strncmp(this_opt, "backlight:", 10)) {
1662 backlight = simple_strtoul(this_opt+10, NULL, 0);
1663 continue;
1655 } 1664 }
1656#ifdef CONFIG_MTRR 1665#ifdef CONFIG_MTRR
1657 if(!strncmp(this_opt, "nomtrr", 6)) { 1666 if(!strncmp(this_opt, "nomtrr", 6)) {
@@ -1695,9 +1704,6 @@ static int __devinit aty128fb_setup(char *options)
1695#ifdef CONFIG_FB_ATY128_BACKLIGHT 1704#ifdef CONFIG_FB_ATY128_BACKLIGHT
1696#define MAX_LEVEL 0xFF 1705#define MAX_LEVEL 0xFF
1697 1706
1698static struct backlight_properties aty128_bl_data;
1699
1700/* Call with fb_info->bl_mutex held */
1701static int aty128_bl_get_level_brightness(struct aty128fb_par *par, 1707static int aty128_bl_get_level_brightness(struct aty128fb_par *par,
1702 int level) 1708 int level)
1703{ 1709{
@@ -1705,6 +1711,7 @@ static int aty128_bl_get_level_brightness(struct aty128fb_par *par,
1705 int atylevel; 1711 int atylevel;
1706 1712
1707 /* Get and convert the value */ 1713 /* Get and convert the value */
1714 /* No locking of bl_curve since we read a single value */
1708 atylevel = MAX_LEVEL - 1715 atylevel = MAX_LEVEL -
1709 (info->bl_curve[level] * FB_BACKLIGHT_MAX / MAX_LEVEL); 1716 (info->bl_curve[level] * FB_BACKLIGHT_MAX / MAX_LEVEL);
1710 1717
@@ -1724,19 +1731,18 @@ static int aty128_bl_get_level_brightness(struct aty128fb_par *par,
1724/* That one prevents proper CRT output with LCD off */ 1731/* That one prevents proper CRT output with LCD off */
1725#undef BACKLIGHT_DAC_OFF 1732#undef BACKLIGHT_DAC_OFF
1726 1733
1727/* Call with fb_info->bl_mutex held */ 1734static int aty128_bl_update_status(struct backlight_device *bd)
1728static int __aty128_bl_update_status(struct backlight_device *bd)
1729{ 1735{
1730 struct aty128fb_par *par = class_get_devdata(&bd->class_dev); 1736 struct aty128fb_par *par = class_get_devdata(&bd->class_dev);
1731 unsigned int reg = aty_ld_le32(LVDS_GEN_CNTL); 1737 unsigned int reg = aty_ld_le32(LVDS_GEN_CNTL);
1732 int level; 1738 int level;
1733 1739
1734 if (bd->props->power != FB_BLANK_UNBLANK || 1740 if (bd->props.power != FB_BLANK_UNBLANK ||
1735 bd->props->fb_blank != FB_BLANK_UNBLANK || 1741 bd->props.fb_blank != FB_BLANK_UNBLANK ||
1736 !par->lcd_on) 1742 !par->lcd_on)
1737 level = 0; 1743 level = 0;
1738 else 1744 else
1739 level = bd->props->brightness; 1745 level = bd->props.brightness;
1740 1746
1741 reg |= LVDS_BL_MOD_EN | LVDS_BLON; 1747 reg |= LVDS_BL_MOD_EN | LVDS_BLON;
1742 if (level > 0) { 1748 if (level > 0) {
@@ -1778,43 +1784,22 @@ static int __aty128_bl_update_status(struct backlight_device *bd)
1778 return 0; 1784 return 0;
1779} 1785}
1780 1786
1781static int aty128_bl_update_status(struct backlight_device *bd)
1782{
1783 struct aty128fb_par *par = class_get_devdata(&bd->class_dev);
1784 struct fb_info *info = pci_get_drvdata(par->pdev);
1785 int ret;
1786
1787 mutex_lock(&info->bl_mutex);
1788 ret = __aty128_bl_update_status(bd);
1789 mutex_unlock(&info->bl_mutex);
1790
1791 return ret;
1792}
1793
1794static int aty128_bl_get_brightness(struct backlight_device *bd) 1787static int aty128_bl_get_brightness(struct backlight_device *bd)
1795{ 1788{
1796 return bd->props->brightness; 1789 return bd->props.brightness;
1797} 1790}
1798 1791
1799static struct backlight_properties aty128_bl_data = { 1792static struct backlight_ops aty128_bl_data = {
1800 .owner = THIS_MODULE,
1801 .get_brightness = aty128_bl_get_brightness, 1793 .get_brightness = aty128_bl_get_brightness,
1802 .update_status = aty128_bl_update_status, 1794 .update_status = aty128_bl_update_status,
1803 .max_brightness = (FB_BACKLIGHT_LEVELS - 1),
1804}; 1795};
1805 1796
1806static void aty128_bl_set_power(struct fb_info *info, int power) 1797static void aty128_bl_set_power(struct fb_info *info, int power)
1807{ 1798{
1808 mutex_lock(&info->bl_mutex);
1809
1810 if (info->bl_dev) { 1799 if (info->bl_dev) {
1811 down(&info->bl_dev->sem); 1800 info->bl_dev->props.power = power;
1812 info->bl_dev->props->power = power; 1801 backlight_update_status(info->bl_dev);
1813 __aty128_bl_update_status(info->bl_dev);
1814 up(&info->bl_dev->sem);
1815 } 1802 }
1816
1817 mutex_unlock(&info->bl_mutex);
1818} 1803}
1819 1804
1820static void aty128_bl_init(struct aty128fb_par *par) 1805static void aty128_bl_init(struct aty128fb_par *par)
@@ -1841,25 +1826,15 @@ static void aty128_bl_init(struct aty128fb_par *par)
1841 goto error; 1826 goto error;
1842 } 1827 }
1843 1828
1844 mutex_lock(&info->bl_mutex);
1845 info->bl_dev = bd; 1829 info->bl_dev = bd;
1846 fb_bl_default_curve(info, 0, 1830 fb_bl_default_curve(info, 0,
1847 63 * FB_BACKLIGHT_MAX / MAX_LEVEL, 1831 63 * FB_BACKLIGHT_MAX / MAX_LEVEL,
1848 219 * FB_BACKLIGHT_MAX / MAX_LEVEL); 1832 219 * FB_BACKLIGHT_MAX / MAX_LEVEL);
1849 mutex_unlock(&info->bl_mutex);
1850 1833
1851 down(&bd->sem); 1834 bd->props.max_brightness = FB_BACKLIGHT_LEVELS - 1;
1852 bd->props->brightness = aty128_bl_data.max_brightness; 1835 bd->props.brightness = bd->props.max_brightness;
1853 bd->props->power = FB_BLANK_UNBLANK; 1836 bd->props.power = FB_BLANK_UNBLANK;
1854 bd->props->update_status(bd); 1837 backlight_update_status(bd);
1855 up(&bd->sem);
1856
1857#ifdef CONFIG_PMAC_BACKLIGHT
1858 mutex_lock(&pmac_backlight_mutex);
1859 if (!pmac_backlight)
1860 pmac_backlight = bd;
1861 mutex_unlock(&pmac_backlight_mutex);
1862#endif
1863 1838
1864 printk("aty128: Backlight initialized (%s)\n", name); 1839 printk("aty128: Backlight initialized (%s)\n", name);
1865 1840
@@ -1869,31 +1844,10 @@ error:
1869 return; 1844 return;
1870} 1845}
1871 1846
1872static void aty128_bl_exit(struct aty128fb_par *par) 1847static void aty128_bl_exit(struct backlight_device *bd)
1873{ 1848{
1874 struct fb_info *info = pci_get_drvdata(par->pdev); 1849 backlight_device_unregister(bd);
1875 1850 printk("aty128: Backlight unloaded\n");
1876#ifdef CONFIG_PMAC_BACKLIGHT
1877 mutex_lock(&pmac_backlight_mutex);
1878#endif
1879
1880 mutex_lock(&info->bl_mutex);
1881 if (info->bl_dev) {
1882#ifdef CONFIG_PMAC_BACKLIGHT
1883 if (pmac_backlight == info->bl_dev)
1884 pmac_backlight = NULL;
1885#endif
1886
1887 backlight_device_unregister(info->bl_dev);
1888 info->bl_dev = NULL;
1889
1890 printk("aty128: Backlight unloaded\n");
1891 }
1892 mutex_unlock(&info->bl_mutex);
1893
1894#ifdef CONFIG_PMAC_BACKLIGHT
1895 mutex_unlock(&pmac_backlight_mutex);
1896#endif
1897} 1851}
1898#endif /* CONFIG_FB_ATY128_BACKLIGHT */ 1852#endif /* CONFIG_FB_ATY128_BACKLIGHT */
1899 1853
@@ -2040,7 +1994,8 @@ static int __devinit aty128_init(struct pci_dev *pdev, const struct pci_device_i
2040 par->lock_blank = 0; 1994 par->lock_blank = 0;
2041 1995
2042#ifdef CONFIG_FB_ATY128_BACKLIGHT 1996#ifdef CONFIG_FB_ATY128_BACKLIGHT
2043 aty128_bl_init(par); 1997 if (backlight)
1998 aty128_bl_init(par);
2044#endif 1999#endif
2045 2000
2046 if (register_framebuffer(info) < 0) 2001 if (register_framebuffer(info) < 0)
@@ -2180,11 +2135,12 @@ static void __devexit aty128_remove(struct pci_dev *pdev)
2180 2135
2181 par = info->par; 2136 par = info->par;
2182 2137
2138 unregister_framebuffer(info);
2139
2183#ifdef CONFIG_FB_ATY128_BACKLIGHT 2140#ifdef CONFIG_FB_ATY128_BACKLIGHT
2184 aty128_bl_exit(par); 2141 aty128_bl_exit(info->bl_dev);
2185#endif 2142#endif
2186 2143
2187 unregister_framebuffer(info);
2188#ifdef CONFIG_MTRR 2144#ifdef CONFIG_MTRR
2189 if (par->mtrr.vram_valid) 2145 if (par->mtrr.vram_valid)
2190 mtrr_del(par->mtrr.vram, info->fix.smem_start, 2146 mtrr_del(par->mtrr.vram, info->fix.smem_start,
@@ -2214,11 +2170,6 @@ static int aty128fb_blank(int blank, struct fb_info *fb)
2214 if (par->lock_blank || par->asleep) 2170 if (par->lock_blank || par->asleep)
2215 return 0; 2171 return 0;
2216 2172
2217#ifdef CONFIG_FB_ATY128_BACKLIGHT
2218 if (machine_is(powermac) && blank)
2219 aty128_bl_set_power(fb, FB_BLANK_POWERDOWN);
2220#endif
2221
2222 if (blank & FB_BLANK_VSYNC_SUSPEND) 2173 if (blank & FB_BLANK_VSYNC_SUSPEND)
2223 state |= 2; 2174 state |= 2;
2224 if (blank & FB_BLANK_HSYNC_SUSPEND) 2175 if (blank & FB_BLANK_HSYNC_SUSPEND)
@@ -2233,11 +2184,6 @@ static int aty128fb_blank(int blank, struct fb_info *fb)
2233 aty128_set_lcd_enable(par, par->lcd_on && !blank); 2184 aty128_set_lcd_enable(par, par->lcd_on && !blank);
2234 } 2185 }
2235 2186
2236#ifdef CONFIG_FB_ATY128_BACKLIGHT
2237 if (machine_is(powermac) && !blank)
2238 aty128_bl_set_power(fb, FB_BLANK_UNBLANK);
2239#endif
2240
2241 return 0; 2187 return 0;
2242} 2188}
2243 2189
diff --git a/drivers/video/aty/atyfb.h b/drivers/video/aty/atyfb.h
index f72faff33c..dc62f8e282 100644
--- a/drivers/video/aty/atyfb.h
+++ b/drivers/video/aty/atyfb.h
@@ -284,7 +284,8 @@ static inline void aty_st_8(int regindex, u8 val, const struct atyfb_par *par)
284#endif 284#endif
285} 285}
286 286
287#if defined(CONFIG_PM) || defined(CONFIG_PMAC_BACKLIGHT) || defined (CONFIG_FB_ATY_GENERIC_LCD) 287#if defined(CONFIG_PM) || defined(CONFIG_PMAC_BACKLIGHT) || \
288defined (CONFIG_FB_ATY_GENERIC_LCD) || defined (CONFIG_FB_ATY_BACKLIGHT)
288extern void aty_st_lcd(int index, u32 val, const struct atyfb_par *par); 289extern void aty_st_lcd(int index, u32 val, const struct atyfb_par *par);
289extern u32 aty_ld_lcd(int index, const struct atyfb_par *par); 290extern u32 aty_ld_lcd(int index, const struct atyfb_par *par);
290#endif 291#endif
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index 301612cef3..d7627fc4f1 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -131,7 +131,8 @@
131#define PRINTKI(fmt, args...) printk(KERN_INFO "atyfb: " fmt, ## args) 131#define PRINTKI(fmt, args...) printk(KERN_INFO "atyfb: " fmt, ## args)
132#define PRINTKE(fmt, args...) printk(KERN_ERR "atyfb: " fmt, ## args) 132#define PRINTKE(fmt, args...) printk(KERN_ERR "atyfb: " fmt, ## args)
133 133
134#if defined(CONFIG_PM) || defined(CONFIG_PMAC_BACKLIGHT) || defined (CONFIG_FB_ATY_GENERIC_LCD) 134#if defined(CONFIG_PM) || defined(CONFIG_PMAC_BACKLIGHT) || \
135defined (CONFIG_FB_ATY_GENERIC_LCD) || defined(CONFIG_FB_ATY_BACKLIGHT)
135static const u32 lt_lcd_regs[] = { 136static const u32 lt_lcd_regs[] = {
136 CONFIG_PANEL_LG, 137 CONFIG_PANEL_LG,
137 LCD_GEN_CNTL_LG, 138 LCD_GEN_CNTL_LG,
@@ -308,6 +309,12 @@ static int xclk;
308static int comp_sync __devinitdata = -1; 309static int comp_sync __devinitdata = -1;
309static char *mode; 310static char *mode;
310 311
312#ifdef CONFIG_PMAC_BACKLIGHT
313static int backlight __devinitdata = 1;
314#else
315static int backlight __devinitdata = 0;
316#endif
317
311#ifdef CONFIG_PPC 318#ifdef CONFIG_PPC
312static int default_vmode __devinitdata = VMODE_CHOOSE; 319static int default_vmode __devinitdata = VMODE_CHOOSE;
313static int default_cmode __devinitdata = CMODE_CHOOSE; 320static int default_cmode __devinitdata = CMODE_CHOOSE;
@@ -2114,15 +2121,13 @@ static int atyfb_pci_resume(struct pci_dev *pdev)
2114#ifdef CONFIG_FB_ATY_BACKLIGHT 2121#ifdef CONFIG_FB_ATY_BACKLIGHT
2115#define MAX_LEVEL 0xFF 2122#define MAX_LEVEL 0xFF
2116 2123
2117static struct backlight_properties aty_bl_data;
2118
2119/* Call with fb_info->bl_mutex held */
2120static int aty_bl_get_level_brightness(struct atyfb_par *par, int level) 2124static int aty_bl_get_level_brightness(struct atyfb_par *par, int level)
2121{ 2125{
2122 struct fb_info *info = pci_get_drvdata(par->pdev); 2126 struct fb_info *info = pci_get_drvdata(par->pdev);
2123 int atylevel; 2127 int atylevel;
2124 2128
2125 /* Get and convert the value */ 2129 /* Get and convert the value */
2130 /* No locking of bl_curve since we read a single value */
2126 atylevel = info->bl_curve[level] * FB_BACKLIGHT_MAX / MAX_LEVEL; 2131 atylevel = info->bl_curve[level] * FB_BACKLIGHT_MAX / MAX_LEVEL;
2127 2132
2128 if (atylevel < 0) 2133 if (atylevel < 0)
@@ -2133,18 +2138,17 @@ static int aty_bl_get_level_brightness(struct atyfb_par *par, int level)
2133 return atylevel; 2138 return atylevel;
2134} 2139}
2135 2140
2136/* Call with fb_info->bl_mutex held */ 2141static int aty_bl_update_status(struct backlight_device *bd)
2137static int __aty_bl_update_status(struct backlight_device *bd)
2138{ 2142{
2139 struct atyfb_par *par = class_get_devdata(&bd->class_dev); 2143 struct atyfb_par *par = class_get_devdata(&bd->class_dev);
2140 unsigned int reg = aty_ld_lcd(LCD_MISC_CNTL, par); 2144 unsigned int reg = aty_ld_lcd(LCD_MISC_CNTL, par);
2141 int level; 2145 int level;
2142 2146
2143 if (bd->props->power != FB_BLANK_UNBLANK || 2147 if (bd->props.power != FB_BLANK_UNBLANK ||
2144 bd->props->fb_blank != FB_BLANK_UNBLANK) 2148 bd->props.fb_blank != FB_BLANK_UNBLANK)
2145 level = 0; 2149 level = 0;
2146 else 2150 else
2147 level = bd->props->brightness; 2151 level = bd->props.brightness;
2148 2152
2149 reg |= (BLMOD_EN | BIASMOD_EN); 2153 reg |= (BLMOD_EN | BIASMOD_EN);
2150 if (level > 0) { 2154 if (level > 0) {
@@ -2159,45 +2163,16 @@ static int __aty_bl_update_status(struct backlight_device *bd)
2159 return 0; 2163 return 0;
2160} 2164}
2161 2165
2162static int aty_bl_update_status(struct backlight_device *bd)
2163{
2164 struct atyfb_par *par = class_get_devdata(&bd->class_dev);
2165 struct fb_info *info = pci_get_drvdata(par->pdev);
2166 int ret;
2167
2168 mutex_lock(&info->bl_mutex);
2169 ret = __aty_bl_update_status(bd);
2170 mutex_unlock(&info->bl_mutex);
2171
2172 return ret;
2173}
2174
2175static int aty_bl_get_brightness(struct backlight_device *bd) 2166static int aty_bl_get_brightness(struct backlight_device *bd)
2176{ 2167{
2177 return bd->props->brightness; 2168 return bd->props.brightness;
2178} 2169}
2179 2170
2180static struct backlight_properties aty_bl_data = { 2171static struct backlight_ops aty_bl_data = {
2181 .owner = THIS_MODULE,
2182 .get_brightness = aty_bl_get_brightness, 2172 .get_brightness = aty_bl_get_brightness,
2183 .update_status = aty_bl_update_status, 2173 .update_status = aty_bl_update_status,
2184 .max_brightness = (FB_BACKLIGHT_LEVELS - 1),
2185}; 2174};
2186 2175
2187static void aty_bl_set_power(struct fb_info *info, int power)
2188{
2189 mutex_lock(&info->bl_mutex);
2190
2191 if (info->bl_dev) {
2192 down(&info->bl_dev->sem);
2193 info->bl_dev->props->power = power;
2194 __aty_bl_update_status(info->bl_dev);
2195 up(&info->bl_dev->sem);
2196 }
2197
2198 mutex_unlock(&info->bl_mutex);
2199}
2200
2201static void aty_bl_init(struct atyfb_par *par) 2176static void aty_bl_init(struct atyfb_par *par)
2202{ 2177{
2203 struct fb_info *info = pci_get_drvdata(par->pdev); 2178 struct fb_info *info = pci_get_drvdata(par->pdev);
@@ -2218,25 +2193,15 @@ static void aty_bl_init(struct atyfb_par *par)
2218 goto error; 2193 goto error;
2219 } 2194 }
2220 2195
2221 mutex_lock(&info->bl_mutex);
2222 info->bl_dev = bd; 2196 info->bl_dev = bd;
2223 fb_bl_default_curve(info, 0, 2197 fb_bl_default_curve(info, 0,
2224 0x3F * FB_BACKLIGHT_MAX / MAX_LEVEL, 2198 0x3F * FB_BACKLIGHT_MAX / MAX_LEVEL,
2225 0xFF * FB_BACKLIGHT_MAX / MAX_LEVEL); 2199 0xFF * FB_BACKLIGHT_MAX / MAX_LEVEL);
2226 mutex_unlock(&info->bl_mutex);
2227
2228 down(&bd->sem);
2229 bd->props->brightness = aty_bl_data.max_brightness;
2230 bd->props->power = FB_BLANK_UNBLANK;
2231 bd->props->update_status(bd);
2232 up(&bd->sem);
2233 2200
2234#ifdef CONFIG_PMAC_BACKLIGHT 2201 bd->props.max_brightness = FB_BACKLIGHT_LEVELS - 1;
2235 mutex_lock(&pmac_backlight_mutex); 2202 bd->props.brightness = bd->props.max_brightness;
2236 if (!pmac_backlight) 2203 bd->props.power = FB_BLANK_UNBLANK;
2237 pmac_backlight = bd; 2204 backlight_update_status(bd);
2238 mutex_unlock(&pmac_backlight_mutex);
2239#endif
2240 2205
2241 printk("aty: Backlight initialized (%s)\n", name); 2206 printk("aty: Backlight initialized (%s)\n", name);
2242 2207
@@ -2246,30 +2211,10 @@ error:
2246 return; 2211 return;
2247} 2212}
2248 2213
2249static void aty_bl_exit(struct atyfb_par *par) 2214static void aty_bl_exit(struct backlight_device *bd)
2250{ 2215{
2251 struct fb_info *info = pci_get_drvdata(par->pdev); 2216 backlight_device_unregister(bd);
2252 2217 printk("aty: Backlight unloaded\n");
2253#ifdef CONFIG_PMAC_BACKLIGHT
2254 mutex_lock(&pmac_backlight_mutex);
2255#endif
2256
2257 mutex_lock(&info->bl_mutex);
2258 if (info->bl_dev) {
2259#ifdef CONFIG_PMAC_BACKLIGHT
2260 if (pmac_backlight == info->bl_dev)
2261 pmac_backlight = NULL;
2262#endif
2263
2264 backlight_device_unregister(info->bl_dev);
2265
2266 printk("aty: Backlight unloaded\n");
2267 }
2268 mutex_unlock(&info->bl_mutex);
2269
2270#ifdef CONFIG_PMAC_BACKLIGHT
2271 mutex_unlock(&pmac_backlight_mutex);
2272#endif
2273} 2218}
2274 2219
2275#endif /* CONFIG_FB_ATY_BACKLIGHT */ 2220#endif /* CONFIG_FB_ATY_BACKLIGHT */
@@ -2637,7 +2582,7 @@ static int __devinit aty_init(struct fb_info *info)
2637 | (USE_F32KHZ | TRISTATE_MEM_EN), par); 2582 | (USE_F32KHZ | TRISTATE_MEM_EN), par);
2638 } else 2583 } else
2639#endif 2584#endif
2640 if (M64_HAS(MOBIL_BUS)) { 2585 if (M64_HAS(MOBIL_BUS) && backlight) {
2641#ifdef CONFIG_FB_ATY_BACKLIGHT 2586#ifdef CONFIG_FB_ATY_BACKLIGHT
2642 aty_bl_init (par); 2587 aty_bl_init (par);
2643#endif 2588#endif
@@ -2814,8 +2759,6 @@ static int atyfb_blank(int blank, struct fb_info *info)
2814 return 0; 2759 return 0;
2815 2760
2816#ifdef CONFIG_FB_ATY_BACKLIGHT 2761#ifdef CONFIG_FB_ATY_BACKLIGHT
2817 if (machine_is(powermac) && blank > FB_BLANK_NORMAL)
2818 aty_bl_set_power(info, FB_BLANK_POWERDOWN);
2819#elif defined(CONFIG_FB_ATY_GENERIC_LCD) 2762#elif defined(CONFIG_FB_ATY_GENERIC_LCD)
2820 if (par->lcd_table && blank > FB_BLANK_NORMAL && 2763 if (par->lcd_table && blank > FB_BLANK_NORMAL &&
2821 (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) { 2764 (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) {
@@ -2846,8 +2789,6 @@ static int atyfb_blank(int blank, struct fb_info *info)
2846 aty_st_le32(CRTC_GEN_CNTL, gen_cntl, par); 2789 aty_st_le32(CRTC_GEN_CNTL, gen_cntl, par);
2847 2790
2848#ifdef CONFIG_FB_ATY_BACKLIGHT 2791#ifdef CONFIG_FB_ATY_BACKLIGHT
2849 if (machine_is(powermac) && blank <= FB_BLANK_NORMAL)
2850 aty_bl_set_power(info, FB_BLANK_UNBLANK);
2851#elif defined(CONFIG_FB_ATY_GENERIC_LCD) 2792#elif defined(CONFIG_FB_ATY_GENERIC_LCD)
2852 if (par->lcd_table && blank <= FB_BLANK_NORMAL && 2793 if (par->lcd_table && blank <= FB_BLANK_NORMAL &&
2853 (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) { 2794 (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) {
@@ -3726,13 +3667,13 @@ static void __devexit atyfb_remove(struct fb_info *info)
3726 aty_set_crtc(par, &saved_crtc); 3667 aty_set_crtc(par, &saved_crtc);
3727 par->pll_ops->set_pll(info, &saved_pll); 3668 par->pll_ops->set_pll(info, &saved_pll);
3728 3669
3670 unregister_framebuffer(info);
3671
3729#ifdef CONFIG_FB_ATY_BACKLIGHT 3672#ifdef CONFIG_FB_ATY_BACKLIGHT
3730 if (M64_HAS(MOBIL_BUS)) 3673 if (M64_HAS(MOBIL_BUS))
3731 aty_bl_exit(par); 3674 aty_bl_exit(info->bl_dev);
3732#endif 3675#endif
3733 3676
3734 unregister_framebuffer(info);
3735
3736#ifdef CONFIG_MTRR 3677#ifdef CONFIG_MTRR
3737 if (par->mtrr_reg >= 0) { 3678 if (par->mtrr_reg >= 0) {
3738 mtrr_del(par->mtrr_reg, 0, 0); 3679 mtrr_del(par->mtrr_reg, 0, 0);
@@ -3823,6 +3764,8 @@ static int __init atyfb_setup(char *options)
3823 xclk = simple_strtoul(this_opt+5, NULL, 0); 3764 xclk = simple_strtoul(this_opt+5, NULL, 0);
3824 else if (!strncmp(this_opt, "comp_sync:", 10)) 3765 else if (!strncmp(this_opt, "comp_sync:", 10))
3825 comp_sync = simple_strtoul(this_opt+10, NULL, 0); 3766 comp_sync = simple_strtoul(this_opt+10, NULL, 0);
3767 else if (!strncmp(this_opt, "backlight:", 10))
3768 backlight = simple_strtoul(this_opt+10, NULL, 0);
3826#ifdef CONFIG_PPC 3769#ifdef CONFIG_PPC
3827 else if (!strncmp(this_opt, "vmode:", 6)) { 3770 else if (!strncmp(this_opt, "vmode:", 6)) {
3828 unsigned int vmode = 3771 unsigned int vmode =
diff --git a/drivers/video/aty/mach64_ct.c b/drivers/video/aty/mach64_ct.c
index f3b487b871..1fdcfdbf66 100644
--- a/drivers/video/aty/mach64_ct.c
+++ b/drivers/video/aty/mach64_ct.c
@@ -598,7 +598,6 @@ static void aty_resume_pll_ct(const struct fb_info *info,
598 struct atyfb_par *par = info->par; 598 struct atyfb_par *par = info->par;
599 599
600 if (par->mclk_per != par->xclk_per) { 600 if (par->mclk_per != par->xclk_per) {
601 int i;
602 /* 601 /*
603 * This disables the sclk, crashes the computer as reported: 602 * This disables the sclk, crashes the computer as reported:
604 * aty_st_pll_ct(SPLL_CNTL2, 3, info); 603 * aty_st_pll_ct(SPLL_CNTL2, 3, info);
@@ -614,7 +613,7 @@ static void aty_resume_pll_ct(const struct fb_info *info,
614 * helps for Rage Mobilities that sometimes crash when 613 * helps for Rage Mobilities that sometimes crash when
615 * we switch to sclk. (Daniel Mantione, 13-05-2003) 614 * we switch to sclk. (Daniel Mantione, 13-05-2003)
616 */ 615 */
617 for (i=0;i<=0x1ffff;i++); 616 udelay(500);
618 } 617 }
619 618
620 aty_st_pll_ct(PLL_REF_DIV, pll->ct.pll_ref_div, par); 619 aty_st_pll_ct(PLL_REF_DIV, pll->ct.pll_ref_div, par);
diff --git a/drivers/video/aty/radeon_backlight.c b/drivers/video/aty/radeon_backlight.c
index 3abfd4a380..0be25fa554 100644
--- a/drivers/video/aty/radeon_backlight.c
+++ b/drivers/video/aty/radeon_backlight.c
@@ -19,8 +19,6 @@
19 19
20#define MAX_RADEON_LEVEL 0xFF 20#define MAX_RADEON_LEVEL 0xFF
21 21
22static struct backlight_properties radeon_bl_data;
23
24struct radeon_bl_privdata { 22struct radeon_bl_privdata {
25 struct radeonfb_info *rinfo; 23 struct radeonfb_info *rinfo;
26 uint8_t negative; 24 uint8_t negative;
@@ -29,17 +27,13 @@ struct radeon_bl_privdata {
29static int radeon_bl_get_level_brightness(struct radeon_bl_privdata *pdata, 27static int radeon_bl_get_level_brightness(struct radeon_bl_privdata *pdata,
30 int level) 28 int level)
31{ 29{
32 struct fb_info *info = pdata->rinfo->info;
33 int rlevel; 30 int rlevel;
34 31
35 mutex_lock(&info->bl_mutex);
36
37 /* Get and convert the value */ 32 /* Get and convert the value */
33 /* No locking of bl_curve since we read a single value */
38 rlevel = pdata->rinfo->info->bl_curve[level] * 34 rlevel = pdata->rinfo->info->bl_curve[level] *
39 FB_BACKLIGHT_MAX / MAX_RADEON_LEVEL; 35 FB_BACKLIGHT_MAX / MAX_RADEON_LEVEL;
40 36
41 mutex_unlock(&info->bl_mutex);
42
43 if (rlevel < 0) 37 if (rlevel < 0)
44 rlevel = 0; 38 rlevel = 0;
45 else if (rlevel > MAX_RADEON_LEVEL) 39 else if (rlevel > MAX_RADEON_LEVEL)
@@ -65,11 +59,11 @@ static int radeon_bl_update_status(struct backlight_device *bd)
65 * backlight. This provides some greater power saving and the display 59 * backlight. This provides some greater power saving and the display
66 * is useless without backlight anyway. 60 * is useless without backlight anyway.
67 */ 61 */
68 if (bd->props->power != FB_BLANK_UNBLANK || 62 if (bd->props.power != FB_BLANK_UNBLANK ||
69 bd->props->fb_blank != FB_BLANK_UNBLANK) 63 bd->props.fb_blank != FB_BLANK_UNBLANK)
70 level = 0; 64 level = 0;
71 else 65 else
72 level = bd->props->brightness; 66 level = bd->props.brightness;
73 67
74 del_timer_sync(&rinfo->lvds_timer); 68 del_timer_sync(&rinfo->lvds_timer);
75 radeon_engine_idle(); 69 radeon_engine_idle();
@@ -130,14 +124,12 @@ static int radeon_bl_update_status(struct backlight_device *bd)
130 124
131static int radeon_bl_get_brightness(struct backlight_device *bd) 125static int radeon_bl_get_brightness(struct backlight_device *bd)
132{ 126{
133 return bd->props->brightness; 127 return bd->props.brightness;
134} 128}
135 129
136static struct backlight_properties radeon_bl_data = { 130static struct backlight_ops radeon_bl_data = {
137 .owner = THIS_MODULE,
138 .get_brightness = radeon_bl_get_brightness, 131 .get_brightness = radeon_bl_get_brightness,
139 .update_status = radeon_bl_update_status, 132 .update_status = radeon_bl_update_status,
140 .max_brightness = (FB_BACKLIGHT_LEVELS - 1),
141}; 133};
142 134
143void radeonfb_bl_init(struct radeonfb_info *rinfo) 135void radeonfb_bl_init(struct radeonfb_info *rinfo)
@@ -188,25 +180,15 @@ void radeonfb_bl_init(struct radeonfb_info *rinfo)
188 machine_is_compatible("PowerBook6,5"); 180 machine_is_compatible("PowerBook6,5");
189#endif 181#endif
190 182
191 mutex_lock(&rinfo->info->bl_mutex);
192 rinfo->info->bl_dev = bd; 183 rinfo->info->bl_dev = bd;
193 fb_bl_default_curve(rinfo->info, 0, 184 fb_bl_default_curve(rinfo->info, 0,
194 63 * FB_BACKLIGHT_MAX / MAX_RADEON_LEVEL, 185 63 * FB_BACKLIGHT_MAX / MAX_RADEON_LEVEL,
195 217 * FB_BACKLIGHT_MAX / MAX_RADEON_LEVEL); 186 217 * FB_BACKLIGHT_MAX / MAX_RADEON_LEVEL);
196 mutex_unlock(&rinfo->info->bl_mutex);
197 187
198 down(&bd->sem); 188 bd->props.max_brightness = FB_BACKLIGHT_LEVELS - 1;
199 bd->props->brightness = radeon_bl_data.max_brightness; 189 bd->props.brightness = bd->props.max_brightness;
200 bd->props->power = FB_BLANK_UNBLANK; 190 bd->props.power = FB_BLANK_UNBLANK;
201 bd->props->update_status(bd); 191 backlight_update_status(bd);
202 up(&bd->sem);
203
204#ifdef CONFIG_PMAC_BACKLIGHT
205 mutex_lock(&pmac_backlight_mutex);
206 if (!pmac_backlight)
207 pmac_backlight = bd;
208 mutex_unlock(&pmac_backlight_mutex);
209#endif
210 192
211 printk("radeonfb: Backlight initialized (%s)\n", name); 193 printk("radeonfb: Backlight initialized (%s)\n", name);
212 194
@@ -219,29 +201,16 @@ error:
219 201
220void radeonfb_bl_exit(struct radeonfb_info *rinfo) 202void radeonfb_bl_exit(struct radeonfb_info *rinfo)
221{ 203{
222#ifdef CONFIG_PMAC_BACKLIGHT 204 struct backlight_device *bd = rinfo->info->bl_dev;
223 mutex_lock(&pmac_backlight_mutex);
224#endif
225 205
226 mutex_lock(&rinfo->info->bl_mutex); 206 if (bd) {
227 if (rinfo->info->bl_dev) {
228 struct radeon_bl_privdata *pdata; 207 struct radeon_bl_privdata *pdata;
229 208
230#ifdef CONFIG_PMAC_BACKLIGHT 209 pdata = class_get_devdata(&bd->class_dev);
231 if (pmac_backlight == rinfo->info->bl_dev) 210 backlight_device_unregister(bd);
232 pmac_backlight = NULL;
233#endif
234
235 pdata = class_get_devdata(&rinfo->info->bl_dev->class_dev);
236 backlight_device_unregister(rinfo->info->bl_dev);
237 kfree(pdata); 211 kfree(pdata);
238 rinfo->info->bl_dev = NULL; 212 rinfo->info->bl_dev = NULL;
239 213
240 printk("radeonfb: Backlight unloaded\n"); 214 printk("radeonfb: Backlight unloaded\n");
241 } 215 }
242 mutex_unlock(&rinfo->info->bl_mutex);
243
244#ifdef CONFIG_PMAC_BACKLIGHT
245 mutex_unlock(&pmac_backlight_mutex);
246#endif
247} 216}
diff --git a/drivers/video/aty/radeon_base.c b/drivers/video/aty/radeon_base.c
index 0ed577e7cc..1bf6f42eb4 100644
--- a/drivers/video/aty/radeon_base.c
+++ b/drivers/video/aty/radeon_base.c
@@ -268,6 +268,11 @@ static int nomtrr = 0;
268#endif 268#endif
269static int force_sleep; 269static int force_sleep;
270static int ignore_devlist; 270static int ignore_devlist;
271#ifdef CONFIG_PMAC_BACKLIGHT
272static int backlight = 1;
273#else
274static int backlight = 0;
275#endif
271 276
272/* 277/*
273 * prototypes 278 * prototypes
@@ -1026,8 +1031,7 @@ int radeon_screen_blank(struct radeonfb_info *rinfo, int blank, int mode_switch)
1026 break; 1031 break;
1027 } 1032 }
1028 1033
1029 /* let fbcon do a soft blank for us */ 1034 return 0;
1030 return (blank == FB_BLANK_NORMAL) ? -EINVAL : 0;
1031} 1035}
1032 1036
1033static int radeonfb_blank (int blank, struct fb_info *info) 1037static int radeonfb_blank (int blank, struct fb_info *info)
@@ -2349,7 +2353,8 @@ static int __devinit radeonfb_pci_register (struct pci_dev *pdev,
2349 MTRR_TYPE_WRCOMB, 1); 2353 MTRR_TYPE_WRCOMB, 1);
2350#endif 2354#endif
2351 2355
2352 radeonfb_bl_init(rinfo); 2356 if (backlight)
2357 radeonfb_bl_init(rinfo);
2353 2358
2354 printk ("radeonfb (%s): %s\n", pci_name(rinfo->pdev), rinfo->name); 2359 printk ("radeonfb (%s): %s\n", pci_name(rinfo->pdev), rinfo->name);
2355 2360
@@ -2393,7 +2398,6 @@ static void __devexit radeonfb_pci_unregister (struct pci_dev *pdev)
2393 if (!rinfo) 2398 if (!rinfo)
2394 return; 2399 return;
2395 2400
2396 radeonfb_bl_exit(rinfo);
2397 radeonfb_pm_exit(rinfo); 2401 radeonfb_pm_exit(rinfo);
2398 2402
2399 if (rinfo->mon1_EDID) 2403 if (rinfo->mon1_EDID)
@@ -2420,6 +2424,8 @@ static void __devexit radeonfb_pci_unregister (struct pci_dev *pdev)
2420 2424
2421 unregister_framebuffer(info); 2425 unregister_framebuffer(info);
2422 2426
2427 radeonfb_bl_exit(rinfo);
2428
2423 iounmap(rinfo->mmio_base); 2429 iounmap(rinfo->mmio_base);
2424 iounmap(rinfo->fb_base); 2430 iounmap(rinfo->fb_base);
2425 2431
@@ -2469,6 +2475,8 @@ static int __init radeonfb_setup (char *options)
2469 force_dfp = 1; 2475 force_dfp = 1;
2470 } else if (!strncmp(this_opt, "panel_yres:", 11)) { 2476 } else if (!strncmp(this_opt, "panel_yres:", 11)) {
2471 panel_yres = simple_strtoul((this_opt+11), NULL, 0); 2477 panel_yres = simple_strtoul((this_opt+11), NULL, 0);
2478 } else if (!strncmp(this_opt, "backlight:", 10)) {
2479 backlight = simple_strtoul(this_opt+10, NULL, 0);
2472#ifdef CONFIG_MTRR 2480#ifdef CONFIG_MTRR
2473 } else if (!strncmp(this_opt, "nomtrr", 6)) { 2481 } else if (!strncmp(this_opt, "nomtrr", 6)) {
2474 nomtrr = 1; 2482 nomtrr = 1;
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index 02f15297a0..47d15b5d98 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -19,11 +19,6 @@ config BACKLIGHT_CLASS_DEVICE
19 To have support for your specific LCD panel you will have to 19 To have support for your specific LCD panel you will have to
20 select the proper drivers which depend on this option. 20 select the proper drivers which depend on this option.
21 21
22config BACKLIGHT_DEVICE
23 bool
24 depends on BACKLIGHT_CLASS_DEVICE
25 default y
26
27config LCD_CLASS_DEVICE 22config LCD_CLASS_DEVICE
28 tristate "Lowlevel LCD controls" 23 tristate "Lowlevel LCD controls"
29 depends on BACKLIGHT_LCD_SUPPORT 24 depends on BACKLIGHT_LCD_SUPPORT
@@ -37,14 +32,9 @@ config LCD_CLASS_DEVICE
37 To have support for your specific LCD panel you will have to 32 To have support for your specific LCD panel you will have to
38 select the proper drivers which depend on this option. 33 select the proper drivers which depend on this option.
39 34
40config LCD_DEVICE
41 bool
42 depends on LCD_CLASS_DEVICE
43 default y
44
45config BACKLIGHT_CORGI 35config BACKLIGHT_CORGI
46 tristate "Sharp Corgi Backlight Driver (SL Series)" 36 tristate "Sharp Corgi Backlight Driver (SL Series)"
47 depends on BACKLIGHT_DEVICE && PXA_SHARPSL 37 depends on BACKLIGHT_CLASS_DEVICE && PXA_SHARPSL
48 default y 38 default y
49 help 39 help
50 If you have a Sharp Zaurus SL-C7xx, SL-Cxx00 or SL-6000x say y to enable the 40 If you have a Sharp Zaurus SL-C7xx, SL-Cxx00 or SL-6000x say y to enable the
@@ -52,7 +42,7 @@ config BACKLIGHT_CORGI
52 42
53config BACKLIGHT_LOCOMO 43config BACKLIGHT_LOCOMO
54 tristate "Sharp LOCOMO LCD/Backlight Driver" 44 tristate "Sharp LOCOMO LCD/Backlight Driver"
55 depends on BACKLIGHT_DEVICE && SHARP_LOCOMO 45 depends on BACKLIGHT_CLASS_DEVICE && SHARP_LOCOMO
56 default y 46 default y
57 help 47 help
58 If you have a Sharp Zaurus SL-5500 (Collie) or SL-5600 (Poodle) say y to 48 If you have a Sharp Zaurus SL-5500 (Collie) or SL-5600 (Poodle) say y to
@@ -60,9 +50,16 @@ config BACKLIGHT_LOCOMO
60 50
61config BACKLIGHT_HP680 51config BACKLIGHT_HP680
62 tristate "HP Jornada 680 Backlight Driver" 52 tristate "HP Jornada 680 Backlight Driver"
63 depends on BACKLIGHT_DEVICE && SH_HP6XX 53 depends on BACKLIGHT_CLASS_DEVICE && SH_HP6XX
64 default y 54 default y
65 help 55 help
66 If you have a HP Jornada 680, say y to enable the 56 If you have a HP Jornada 680, say y to enable the
67 backlight driver. 57 backlight driver.
68 58
59config BACKLIGHT_PROGEAR
60 tristate "Frontpath ProGear Backlight Driver"
61 depends on BACKLIGHT_CLASS_DEVICE && PCI && X86
62 default n
63 help
64 If you have a Frontpath ProGear say Y to enable the
65 backlight driver.
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index 65e5553fc8..0c3ce46f50 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -5,3 +5,4 @@ obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o
5obj-$(CONFIG_BACKLIGHT_CORGI) += corgi_bl.o 5obj-$(CONFIG_BACKLIGHT_CORGI) += corgi_bl.o
6obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o 6obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o
7obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o 7obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o
8obj-$(CONFIG_BACKLIGHT_PROGEAR) += progear_bl.o
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index 9601bfe309..c65e81ff35 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -14,6 +14,9 @@
14#include <linux/err.h> 14#include <linux/err.h>
15#include <linux/fb.h> 15#include <linux/fb.h>
16 16
17#ifdef CONFIG_PMAC_BACKLIGHT
18#include <asm/backlight.h>
19#endif
17 20
18#if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \ 21#if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \
19 defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)) 22 defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE))
@@ -28,19 +31,18 @@ static int fb_notifier_callback(struct notifier_block *self,
28 struct fb_event *evdata = data; 31 struct fb_event *evdata = data;
29 32
30 /* If we aren't interested in this event, skip it immediately ... */ 33 /* If we aren't interested in this event, skip it immediately ... */
31 if (event != FB_EVENT_BLANK) 34 if (event != FB_EVENT_BLANK && event != FB_EVENT_CONBLANK)
32 return 0; 35 return 0;
33 36
34 bd = container_of(self, struct backlight_device, fb_notif); 37 bd = container_of(self, struct backlight_device, fb_notif);
35 down(&bd->sem); 38 mutex_lock(&bd->ops_lock);
36 if (bd->props) 39 if (bd->ops)
37 if (!bd->props->check_fb || 40 if (!bd->ops->check_fb ||
38 bd->props->check_fb(evdata->info)) { 41 bd->ops->check_fb(evdata->info)) {
39 bd->props->fb_blank = *(int *)evdata->data; 42 bd->props.fb_blank = *(int *)evdata->data;
40 if (likely(bd->props && bd->props->update_status)) 43 backlight_update_status(bd);
41 bd->props->update_status(bd);
42 } 44 }
43 up(&bd->sem); 45 mutex_unlock(&bd->ops_lock);
44 return 0; 46 return 0;
45} 47}
46 48
@@ -69,15 +71,9 @@ static inline void backlight_unregister_fb(struct backlight_device *bd)
69 71
70static ssize_t backlight_show_power(struct class_device *cdev, char *buf) 72static ssize_t backlight_show_power(struct class_device *cdev, char *buf)
71{ 73{
72 int rc = -ENXIO;
73 struct backlight_device *bd = to_backlight_device(cdev); 74 struct backlight_device *bd = to_backlight_device(cdev);
74 75
75 down(&bd->sem); 76 return sprintf(buf, "%d\n", bd->props.power);
76 if (likely(bd->props))
77 rc = sprintf(buf, "%d\n", bd->props->power);
78 up(&bd->sem);
79
80 return rc;
81} 77}
82 78
83static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, size_t count) 79static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, size_t count)
@@ -93,30 +89,23 @@ static ssize_t backlight_store_power(struct class_device *cdev, const char *buf,
93 if (size != count) 89 if (size != count)
94 return -EINVAL; 90 return -EINVAL;
95 91
96 down(&bd->sem); 92 mutex_lock(&bd->ops_lock);
97 if (likely(bd->props)) { 93 if (bd->ops) {
98 pr_debug("backlight: set power to %d\n", power); 94 pr_debug("backlight: set power to %d\n", power);
99 bd->props->power = power; 95 bd->props.power = power;
100 if (likely(bd->props->update_status)) 96 backlight_update_status(bd);
101 bd->props->update_status(bd);
102 rc = count; 97 rc = count;
103 } 98 }
104 up(&bd->sem); 99 mutex_unlock(&bd->ops_lock);
105 100
106 return rc; 101 return rc;
107} 102}
108 103
109static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf) 104static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf)
110{ 105{
111 int rc = -ENXIO;
112 struct backlight_device *bd = to_backlight_device(cdev); 106 struct backlight_device *bd = to_backlight_device(cdev);
113 107
114 down(&bd->sem); 108 return sprintf(buf, "%d\n", bd->props.brightness);
115 if (likely(bd->props))
116 rc = sprintf(buf, "%d\n", bd->props->brightness);
117 up(&bd->sem);
118
119 return rc;
120} 109}
121 110
122static ssize_t backlight_store_brightness(struct class_device *cdev, const char *buf, size_t count) 111static ssize_t backlight_store_brightness(struct class_device *cdev, const char *buf, size_t count)
@@ -132,35 +121,28 @@ static ssize_t backlight_store_brightness(struct class_device *cdev, const char
132 if (size != count) 121 if (size != count)
133 return -EINVAL; 122 return -EINVAL;
134 123
135 down(&bd->sem); 124 mutex_lock(&bd->ops_lock);
136 if (likely(bd->props)) { 125 if (bd->ops) {
137 if (brightness > bd->props->max_brightness) 126 if (brightness > bd->props.max_brightness)
138 rc = -EINVAL; 127 rc = -EINVAL;
139 else { 128 else {
140 pr_debug("backlight: set brightness to %d\n", 129 pr_debug("backlight: set brightness to %d\n",
141 brightness); 130 brightness);
142 bd->props->brightness = brightness; 131 bd->props.brightness = brightness;
143 if (likely(bd->props->update_status)) 132 backlight_update_status(bd);
144 bd->props->update_status(bd);
145 rc = count; 133 rc = count;
146 } 134 }
147 } 135 }
148 up(&bd->sem); 136 mutex_unlock(&bd->ops_lock);
149 137
150 return rc; 138 return rc;
151} 139}
152 140
153static ssize_t backlight_show_max_brightness(struct class_device *cdev, char *buf) 141static ssize_t backlight_show_max_brightness(struct class_device *cdev, char *buf)
154{ 142{
155 int rc = -ENXIO;
156 struct backlight_device *bd = to_backlight_device(cdev); 143 struct backlight_device *bd = to_backlight_device(cdev);
157 144
158 down(&bd->sem); 145 return sprintf(buf, "%d\n", bd->props.max_brightness);
159 if (likely(bd->props))
160 rc = sprintf(buf, "%d\n", bd->props->max_brightness);
161 up(&bd->sem);
162
163 return rc;
164} 146}
165 147
166static ssize_t backlight_show_actual_brightness(struct class_device *cdev, 148static ssize_t backlight_show_actual_brightness(struct class_device *cdev,
@@ -169,10 +151,10 @@ static ssize_t backlight_show_actual_brightness(struct class_device *cdev,
169 int rc = -ENXIO; 151 int rc = -ENXIO;
170 struct backlight_device *bd = to_backlight_device(cdev); 152 struct backlight_device *bd = to_backlight_device(cdev);
171 153
172 down(&bd->sem); 154 mutex_lock(&bd->ops_lock);
173 if (likely(bd->props && bd->props->get_brightness)) 155 if (bd->ops && bd->ops->get_brightness)
174 rc = sprintf(buf, "%d\n", bd->props->get_brightness(bd)); 156 rc = sprintf(buf, "%d\n", bd->ops->get_brightness(bd));
175 up(&bd->sem); 157 mutex_unlock(&bd->ops_lock);
176 158
177 return rc; 159 return rc;
178} 160}
@@ -211,7 +193,7 @@ static const struct class_device_attribute bl_class_device_attributes[] = {
211 * respective framebuffer device). 193 * respective framebuffer device).
212 * @devdata: an optional pointer to be stored in the class_device. The 194 * @devdata: an optional pointer to be stored in the class_device. The
213 * methods may retrieve it by using class_get_devdata(&bd->class_dev). 195 * methods may retrieve it by using class_get_devdata(&bd->class_dev).
214 * @bp: the backlight properties structure. 196 * @ops: the backlight operations structure.
215 * 197 *
216 * Creates and registers new backlight class_device. Returns either an 198 * Creates and registers new backlight class_device. Returns either an
217 * ERR_PTR() or a pointer to the newly allocated device. 199 * ERR_PTR() or a pointer to the newly allocated device.
@@ -219,39 +201,42 @@ static const struct class_device_attribute bl_class_device_attributes[] = {
219struct backlight_device *backlight_device_register(const char *name, 201struct backlight_device *backlight_device_register(const char *name,
220 struct device *dev, 202 struct device *dev,
221 void *devdata, 203 void *devdata,
222 struct backlight_properties *bp) 204 struct backlight_ops *ops)
223{ 205{
224 int i, rc; 206 int i, rc;
225 struct backlight_device *new_bd; 207 struct backlight_device *new_bd;
226 208
227 pr_debug("backlight_device_alloc: name=%s\n", name); 209 pr_debug("backlight_device_alloc: name=%s\n", name);
228 210
229 new_bd = kmalloc(sizeof(struct backlight_device), GFP_KERNEL); 211 new_bd = kzalloc(sizeof(struct backlight_device), GFP_KERNEL);
230 if (unlikely(!new_bd)) 212 if (!new_bd)
231 return ERR_PTR(-ENOMEM); 213 return ERR_PTR(-ENOMEM);
232 214
233 init_MUTEX(&new_bd->sem); 215 mutex_init(&new_bd->update_lock);
234 new_bd->props = bp; 216 mutex_init(&new_bd->ops_lock);
235 memset(&new_bd->class_dev, 0, sizeof(new_bd->class_dev)); 217 new_bd->ops = ops;
236 new_bd->class_dev.class = &backlight_class; 218 new_bd->class_dev.class = &backlight_class;
237 new_bd->class_dev.dev = dev; 219 new_bd->class_dev.dev = dev;
238 strlcpy(new_bd->class_dev.class_id, name, KOBJ_NAME_LEN); 220 strlcpy(new_bd->class_dev.class_id, name, KOBJ_NAME_LEN);
239 class_set_devdata(&new_bd->class_dev, devdata); 221 class_set_devdata(&new_bd->class_dev, devdata);
240 222
241 rc = class_device_register(&new_bd->class_dev); 223 rc = class_device_register(&new_bd->class_dev);
242 if (unlikely(rc)) { 224 if (rc) {
243error: kfree(new_bd); 225 kfree(new_bd);
244 return ERR_PTR(rc); 226 return ERR_PTR(rc);
245 } 227 }
246 228
247 rc = backlight_register_fb(new_bd); 229 rc = backlight_register_fb(new_bd);
248 if (unlikely(rc)) 230 if (rc) {
249 goto error; 231 class_device_unregister(&new_bd->class_dev);
232 return ERR_PTR(rc);
233 }
234
250 235
251 for (i = 0; i < ARRAY_SIZE(bl_class_device_attributes); i++) { 236 for (i = 0; i < ARRAY_SIZE(bl_class_device_attributes); i++) {
252 rc = class_device_create_file(&new_bd->class_dev, 237 rc = class_device_create_file(&new_bd->class_dev,
253 &bl_class_device_attributes[i]); 238 &bl_class_device_attributes[i]);
254 if (unlikely(rc)) { 239 if (rc) {
255 while (--i >= 0) 240 while (--i >= 0)
256 class_device_remove_file(&new_bd->class_dev, 241 class_device_remove_file(&new_bd->class_dev,
257 &bl_class_device_attributes[i]); 242 &bl_class_device_attributes[i]);
@@ -261,6 +246,13 @@ error: kfree(new_bd);
261 } 246 }
262 } 247 }
263 248
249#ifdef CONFIG_PMAC_BACKLIGHT
250 mutex_lock(&pmac_backlight_mutex);
251 if (!pmac_backlight)
252 pmac_backlight = new_bd;
253 mutex_unlock(&pmac_backlight_mutex);
254#endif
255
264 return new_bd; 256 return new_bd;
265} 257}
266EXPORT_SYMBOL(backlight_device_register); 258EXPORT_SYMBOL(backlight_device_register);
@@ -280,13 +272,20 @@ void backlight_device_unregister(struct backlight_device *bd)
280 272
281 pr_debug("backlight_device_unregister: name=%s\n", bd->class_dev.class_id); 273 pr_debug("backlight_device_unregister: name=%s\n", bd->class_dev.class_id);
282 274
275#ifdef CONFIG_PMAC_BACKLIGHT
276 mutex_lock(&pmac_backlight_mutex);
277 if (pmac_backlight == bd)
278 pmac_backlight = NULL;
279 mutex_unlock(&pmac_backlight_mutex);
280#endif
281
283 for (i = 0; i < ARRAY_SIZE(bl_class_device_attributes); i++) 282 for (i = 0; i < ARRAY_SIZE(bl_class_device_attributes); i++)
284 class_device_remove_file(&bd->class_dev, 283 class_device_remove_file(&bd->class_dev,
285 &bl_class_device_attributes[i]); 284 &bl_class_device_attributes[i]);
286 285
287 down(&bd->sem); 286 mutex_lock(&bd->ops_lock);
288 bd->props = NULL; 287 bd->ops = NULL;
289 up(&bd->sem); 288 mutex_unlock(&bd->ops_lock);
290 289
291 backlight_unregister_fb(bd); 290 backlight_unregister_fb(bd);
292 291
diff --git a/drivers/video/backlight/corgi_bl.c b/drivers/video/backlight/corgi_bl.c
index fde1d95181..ce00e18a4e 100644
--- a/drivers/video/backlight/corgi_bl.c
+++ b/drivers/video/backlight/corgi_bl.c
@@ -22,7 +22,6 @@
22#include <asm/hardware/sharpsl_pm.h> 22#include <asm/hardware/sharpsl_pm.h>
23 23
24static int corgibl_intensity; 24static int corgibl_intensity;
25static DEFINE_MUTEX(bl_mutex);
26static struct backlight_properties corgibl_data; 25static struct backlight_properties corgibl_data;
27static struct backlight_device *corgi_backlight_device; 26static struct backlight_device *corgi_backlight_device;
28static struct corgibl_machinfo *bl_machinfo; 27static struct corgibl_machinfo *bl_machinfo;
@@ -34,20 +33,18 @@ static unsigned long corgibl_flags;
34static int corgibl_send_intensity(struct backlight_device *bd) 33static int corgibl_send_intensity(struct backlight_device *bd)
35{ 34{
36 void (*corgi_kick_batt)(void); 35 void (*corgi_kick_batt)(void);
37 int intensity = bd->props->brightness; 36 int intensity = bd->props.brightness;
38 37
39 if (bd->props->power != FB_BLANK_UNBLANK) 38 if (bd->props.power != FB_BLANK_UNBLANK)
40 intensity = 0; 39 intensity = 0;
41 if (bd->props->fb_blank != FB_BLANK_UNBLANK) 40 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
42 intensity = 0; 41 intensity = 0;
43 if (corgibl_flags & CORGIBL_SUSPENDED) 42 if (corgibl_flags & CORGIBL_SUSPENDED)
44 intensity = 0; 43 intensity = 0;
45 if (corgibl_flags & CORGIBL_BATTLOW) 44 if (corgibl_flags & CORGIBL_BATTLOW)
46 intensity &= bl_machinfo->limit_mask; 45 intensity &= bl_machinfo->limit_mask;
47 46
48 mutex_lock(&bl_mutex);
49 bl_machinfo->set_bl_intensity(intensity); 47 bl_machinfo->set_bl_intensity(intensity);
50 mutex_unlock(&bl_mutex);
51 48
52 corgibl_intensity = intensity; 49 corgibl_intensity = intensity;
53 50
@@ -61,17 +58,21 @@ static int corgibl_send_intensity(struct backlight_device *bd)
61} 58}
62 59
63#ifdef CONFIG_PM 60#ifdef CONFIG_PM
64static int corgibl_suspend(struct platform_device *dev, pm_message_t state) 61static int corgibl_suspend(struct platform_device *pdev, pm_message_t state)
65{ 62{
63 struct backlight_device *bd = platform_get_drvdata(pdev);
64
66 corgibl_flags |= CORGIBL_SUSPENDED; 65 corgibl_flags |= CORGIBL_SUSPENDED;
67 corgibl_send_intensity(corgi_backlight_device); 66 backlight_update_status(bd);
68 return 0; 67 return 0;
69} 68}
70 69
71static int corgibl_resume(struct platform_device *dev) 70static int corgibl_resume(struct platform_device *pdev)
72{ 71{
72 struct backlight_device *bd = platform_get_drvdata(pdev);
73
73 corgibl_flags &= ~CORGIBL_SUSPENDED; 74 corgibl_flags &= ~CORGIBL_SUSPENDED;
74 corgibl_send_intensity(corgi_backlight_device); 75 backlight_update_status(bd);
75 return 0; 76 return 0;
76} 77}
77#else 78#else
@@ -84,12 +85,6 @@ static int corgibl_get_intensity(struct backlight_device *bd)
84 return corgibl_intensity; 85 return corgibl_intensity;
85} 86}
86 87
87static int corgibl_set_intensity(struct backlight_device *bd)
88{
89 corgibl_send_intensity(corgi_backlight_device);
90 return 0;
91}
92
93/* 88/*
94 * Called when the battery is low to limit the backlight intensity. 89 * Called when the battery is low to limit the backlight intensity.
95 * If limit==0 clear any limit, otherwise limit the intensity 90 * If limit==0 clear any limit, otherwise limit the intensity
@@ -100,15 +95,14 @@ void corgibl_limit_intensity(int limit)
100 corgibl_flags |= CORGIBL_BATTLOW; 95 corgibl_flags |= CORGIBL_BATTLOW;
101 else 96 else
102 corgibl_flags &= ~CORGIBL_BATTLOW; 97 corgibl_flags &= ~CORGIBL_BATTLOW;
103 corgibl_send_intensity(corgi_backlight_device); 98 backlight_update_status(corgi_backlight_device);
104} 99}
105EXPORT_SYMBOL(corgibl_limit_intensity); 100EXPORT_SYMBOL(corgibl_limit_intensity);
106 101
107 102
108static struct backlight_properties corgibl_data = { 103static struct backlight_ops corgibl_ops = {
109 .owner = THIS_MODULE,
110 .get_brightness = corgibl_get_intensity, 104 .get_brightness = corgibl_get_intensity,
111 .update_status = corgibl_set_intensity, 105 .update_status = corgibl_send_intensity,
112}; 106};
113 107
114static int corgibl_probe(struct platform_device *pdev) 108static int corgibl_probe(struct platform_device *pdev)
@@ -116,30 +110,34 @@ static int corgibl_probe(struct platform_device *pdev)
116 struct corgibl_machinfo *machinfo = pdev->dev.platform_data; 110 struct corgibl_machinfo *machinfo = pdev->dev.platform_data;
117 111
118 bl_machinfo = machinfo; 112 bl_machinfo = machinfo;
119 corgibl_data.max_brightness = machinfo->max_intensity;
120 if (!machinfo->limit_mask) 113 if (!machinfo->limit_mask)
121 machinfo->limit_mask = -1; 114 machinfo->limit_mask = -1;
122 115
123 corgi_backlight_device = backlight_device_register ("corgi-bl", 116 corgi_backlight_device = backlight_device_register ("corgi-bl",
124 &pdev->dev, NULL, &corgibl_data); 117 &pdev->dev, NULL, &corgibl_ops);
125 if (IS_ERR (corgi_backlight_device)) 118 if (IS_ERR (corgi_backlight_device))
126 return PTR_ERR (corgi_backlight_device); 119 return PTR_ERR (corgi_backlight_device);
127 120
128 corgibl_data.power = FB_BLANK_UNBLANK; 121 platform_set_drvdata(pdev, corgi_backlight_device);
129 corgibl_data.brightness = machinfo->default_intensity; 122
130 corgibl_send_intensity(corgi_backlight_device); 123 corgi_backlight_device->props.max_brightness = machinfo->max_intensity;
124 corgi_backlight_device->props.power = FB_BLANK_UNBLANK;
125 corgi_backlight_device->props.brightness = machinfo->default_intensity;
126 backlight_update_status(corgi_backlight_device);
131 127
132 printk("Corgi Backlight Driver Initialized.\n"); 128 printk("Corgi Backlight Driver Initialized.\n");
133 return 0; 129 return 0;
134} 130}
135 131
136static int corgibl_remove(struct platform_device *dev) 132static int corgibl_remove(struct platform_device *pdev)
137{ 133{
134 struct backlight_device *bd = platform_get_drvdata(pdev);
135
138 corgibl_data.power = 0; 136 corgibl_data.power = 0;
139 corgibl_data.brightness = 0; 137 corgibl_data.brightness = 0;
140 corgibl_send_intensity(corgi_backlight_device); 138 backlight_update_status(bd);
141 139
142 backlight_device_unregister(corgi_backlight_device); 140 backlight_device_unregister(bd);
143 141
144 printk("Corgi Backlight Driver Unloaded\n"); 142 printk("Corgi Backlight Driver Unloaded\n");
145 return 0; 143 return 0;
diff --git a/drivers/video/backlight/hp680_bl.c b/drivers/video/backlight/hp680_bl.c
index c07d8207fb..0899fccbd5 100644
--- a/drivers/video/backlight/hp680_bl.c
+++ b/drivers/video/backlight/hp680_bl.c
@@ -28,17 +28,16 @@
28static int hp680bl_suspended; 28static int hp680bl_suspended;
29static int current_intensity = 0; 29static int current_intensity = 0;
30static DEFINE_SPINLOCK(bl_lock); 30static DEFINE_SPINLOCK(bl_lock);
31static struct backlight_device *hp680_backlight_device;
32 31
33static void hp680bl_send_intensity(struct backlight_device *bd) 32static void hp680bl_send_intensity(struct backlight_device *bd)
34{ 33{
35 unsigned long flags; 34 unsigned long flags;
36 u16 v; 35 u16 v;
37 int intensity = bd->props->brightness; 36 int intensity = bd->props.brightness;
38 37
39 if (bd->props->power != FB_BLANK_UNBLANK) 38 if (bd->props.power != FB_BLANK_UNBLANK)
40 intensity = 0; 39 intensity = 0;
41 if (bd->props->fb_blank != FB_BLANK_UNBLANK) 40 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
42 intensity = 0; 41 intensity = 0;
43 if (hp680bl_suspended) 42 if (hp680bl_suspended)
44 intensity = 0; 43 intensity = 0;
@@ -66,17 +65,21 @@ static void hp680bl_send_intensity(struct backlight_device *bd)
66 65
67 66
68#ifdef CONFIG_PM 67#ifdef CONFIG_PM
69static int hp680bl_suspend(struct platform_device *dev, pm_message_t state) 68static int hp680bl_suspend(struct platform_device *pdev, pm_message_t state)
70{ 69{
70 struct backlight_device *bd = platform_get_drvdata(pdev);
71
71 hp680bl_suspended = 1; 72 hp680bl_suspended = 1;
72 hp680bl_send_intensity(hp680_backlight_device); 73 hp680bl_send_intensity(bd);
73 return 0; 74 return 0;
74} 75}
75 76
76static int hp680bl_resume(struct platform_device *dev) 77static int hp680bl_resume(struct platform_device *pdev)
77{ 78{
79 struct backlight_device *bd = platform_get_drvdata(pdev);
80
78 hp680bl_suspended = 0; 81 hp680bl_suspended = 0;
79 hp680bl_send_intensity(hp680_backlight_device); 82 hp680bl_send_intensity(bd);
80 return 0; 83 return 0;
81} 84}
82#else 85#else
@@ -95,33 +98,38 @@ static int hp680bl_get_intensity(struct backlight_device *bd)
95 return current_intensity; 98 return current_intensity;
96} 99}
97 100
98static struct backlight_properties hp680bl_data = { 101static struct backlight_ops hp680bl_ops = {
99 .owner = THIS_MODULE,
100 .max_brightness = HP680_MAX_INTENSITY,
101 .get_brightness = hp680bl_get_intensity, 102 .get_brightness = hp680bl_get_intensity,
102 .update_status = hp680bl_set_intensity, 103 .update_status = hp680bl_set_intensity,
103}; 104};
104 105
105static int __init hp680bl_probe(struct platform_device *dev) 106static int __init hp680bl_probe(struct platform_device *pdev)
106{ 107{
107 hp680_backlight_device = backlight_device_register ("hp680-bl", 108 struct backlight_device *bd;
108 &dev->dev, NULL, &hp680bl_data); 109
109 if (IS_ERR (hp680_backlight_device)) 110 bd = backlight_device_register ("hp680-bl", &pdev->dev, NULL,
110 return PTR_ERR (hp680_backlight_device); 111 &hp680bl_ops);
112 if (IS_ERR(bd))
113 return PTR_ERR(bd);
111 114
112 hp680_backlight_device->props->brightness = HP680_DEFAULT_INTENSITY; 115 platform_set_drvdata(pdev, bd);
113 hp680bl_send_intensity(hp680_backlight_device); 116
117 bd->props.max_brightness = HP680_MAX_INTENSITY;
118 bd->props.brightness = HP680_DEFAULT_INTENSITY;
119 hp680bl_send_intensity(bd);
114 120
115 return 0; 121 return 0;
116} 122}
117 123
118static int hp680bl_remove(struct platform_device *dev) 124static int hp680bl_remove(struct platform_device *pdev)
119{ 125{
126 struct backlight_device *bd = platform_get_drvdata(pdev);
127
120 hp680bl_data.brightness = 0; 128 hp680bl_data.brightness = 0;
121 hp680bl_data.power = 0; 129 hp680bl_data.power = 0;
122 hp680bl_send_intensity(hp680_backlight_device); 130 hp680bl_send_intensity(bd);
123 131
124 backlight_device_unregister(hp680_backlight_device); 132 backlight_device_unregister(bd);
125 133
126 return 0; 134 return 0;
127} 135}
diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c
index f6e041627e..6ef8f0a7a1 100644
--- a/drivers/video/backlight/lcd.c
+++ b/drivers/video/backlight/lcd.c
@@ -31,11 +31,11 @@ static int fb_notifier_callback(struct notifier_block *self,
31 return 0; 31 return 0;
32 32
33 ld = container_of(self, struct lcd_device, fb_notif); 33 ld = container_of(self, struct lcd_device, fb_notif);
34 down(&ld->sem); 34 mutex_lock(&ld->ops_lock);
35 if (ld->props) 35 if (ld->ops)
36 if (!ld->props->check_fb || ld->props->check_fb(evdata->info)) 36 if (!ld->ops->check_fb || ld->ops->check_fb(evdata->info))
37 ld->props->set_power(ld, *(int *)evdata->data); 37 ld->ops->set_power(ld, *(int *)evdata->data);
38 up(&ld->sem); 38 mutex_unlock(&ld->ops_lock);
39 return 0; 39 return 0;
40} 40}
41 41
@@ -66,12 +66,12 @@ static ssize_t lcd_show_power(struct class_device *cdev, char *buf)
66 int rc; 66 int rc;
67 struct lcd_device *ld = to_lcd_device(cdev); 67 struct lcd_device *ld = to_lcd_device(cdev);
68 68
69 down(&ld->sem); 69 mutex_lock(&ld->ops_lock);
70 if (likely(ld->props && ld->props->get_power)) 70 if (ld->ops && ld->ops->get_power)
71 rc = sprintf(buf, "%d\n", ld->props->get_power(ld)); 71 rc = sprintf(buf, "%d\n", ld->ops->get_power(ld));
72 else 72 else
73 rc = -ENXIO; 73 rc = -ENXIO;
74 up(&ld->sem); 74 mutex_unlock(&ld->ops_lock);
75 75
76 return rc; 76 return rc;
77} 77}
@@ -89,13 +89,13 @@ static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_
89 if (size != count) 89 if (size != count)
90 return -EINVAL; 90 return -EINVAL;
91 91
92 down(&ld->sem); 92 mutex_lock(&ld->ops_lock);
93 if (likely(ld->props && ld->props->set_power)) { 93 if (ld->ops && ld->ops->set_power) {
94 pr_debug("lcd: set power to %d\n", power); 94 pr_debug("lcd: set power to %d\n", power);
95 ld->props->set_power(ld, power); 95 ld->ops->set_power(ld, power);
96 rc = count; 96 rc = count;
97 } 97 }
98 up(&ld->sem); 98 mutex_unlock(&ld->ops_lock);
99 99
100 return rc; 100 return rc;
101} 101}
@@ -105,10 +105,10 @@ static ssize_t lcd_show_contrast(struct class_device *cdev, char *buf)
105 int rc = -ENXIO; 105 int rc = -ENXIO;
106 struct lcd_device *ld = to_lcd_device(cdev); 106 struct lcd_device *ld = to_lcd_device(cdev);
107 107
108 down(&ld->sem); 108 mutex_lock(&ld->ops_lock);
109 if (likely(ld->props && ld->props->get_contrast)) 109 if (ld->ops && ld->ops->get_contrast)
110 rc = sprintf(buf, "%d\n", ld->props->get_contrast(ld)); 110 rc = sprintf(buf, "%d\n", ld->ops->get_contrast(ld));
111 up(&ld->sem); 111 mutex_unlock(&ld->ops_lock);
112 112
113 return rc; 113 return rc;
114} 114}
@@ -126,28 +126,22 @@ static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, si
126 if (size != count) 126 if (size != count)
127 return -EINVAL; 127 return -EINVAL;
128 128
129 down(&ld->sem); 129 mutex_lock(&ld->ops_lock);
130 if (likely(ld->props && ld->props->set_contrast)) { 130 if (ld->ops && ld->ops->set_contrast) {
131 pr_debug("lcd: set contrast to %d\n", contrast); 131 pr_debug("lcd: set contrast to %d\n", contrast);
132 ld->props->set_contrast(ld, contrast); 132 ld->ops->set_contrast(ld, contrast);
133 rc = count; 133 rc = count;
134 } 134 }
135 up(&ld->sem); 135 mutex_unlock(&ld->ops_lock);
136 136
137 return rc; 137 return rc;
138} 138}
139 139
140static ssize_t lcd_show_max_contrast(struct class_device *cdev, char *buf) 140static ssize_t lcd_show_max_contrast(struct class_device *cdev, char *buf)
141{ 141{
142 int rc = -ENXIO;
143 struct lcd_device *ld = to_lcd_device(cdev); 142 struct lcd_device *ld = to_lcd_device(cdev);
144 143
145 down(&ld->sem); 144 return sprintf(buf, "%d\n", ld->props.max_contrast);
146 if (likely(ld->props))
147 rc = sprintf(buf, "%d\n", ld->props->max_contrast);
148 up(&ld->sem);
149
150 return rc;
151} 145}
152 146
153static void lcd_class_release(struct class_device *dev) 147static void lcd_class_release(struct class_device *dev)
@@ -180,45 +174,46 @@ static const struct class_device_attribute lcd_class_device_attributes[] = {
180 * respective framebuffer device). 174 * respective framebuffer device).
181 * @devdata: an optional pointer to be stored in the class_device. The 175 * @devdata: an optional pointer to be stored in the class_device. The
182 * methods may retrieve it by using class_get_devdata(ld->class_dev). 176 * methods may retrieve it by using class_get_devdata(ld->class_dev).
183 * @lp: the lcd properties structure. 177 * @ops: the lcd operations structure.
184 * 178 *
185 * Creates and registers a new lcd class_device. Returns either an ERR_PTR() 179 * Creates and registers a new lcd class_device. Returns either an ERR_PTR()
186 * or a pointer to the newly allocated device. 180 * or a pointer to the newly allocated device.
187 */ 181 */
188struct lcd_device *lcd_device_register(const char *name, void *devdata, 182struct lcd_device *lcd_device_register(const char *name, void *devdata,
189 struct lcd_properties *lp) 183 struct lcd_ops *ops)
190{ 184{
191 int i, rc; 185 int i, rc;
192 struct lcd_device *new_ld; 186 struct lcd_device *new_ld;
193 187
194 pr_debug("lcd_device_register: name=%s\n", name); 188 pr_debug("lcd_device_register: name=%s\n", name);
195 189
196 new_ld = kmalloc(sizeof(struct lcd_device), GFP_KERNEL); 190 new_ld = kzalloc(sizeof(struct lcd_device), GFP_KERNEL);
197 if (unlikely(!new_ld)) 191 if (!new_ld)
198 return ERR_PTR(-ENOMEM); 192 return ERR_PTR(-ENOMEM);
199 193
200 init_MUTEX(&new_ld->sem); 194 mutex_init(&new_ld->ops_lock);
201 new_ld->props = lp; 195 mutex_init(&new_ld->update_lock);
202 memset(&new_ld->class_dev, 0, sizeof(new_ld->class_dev)); 196 new_ld->ops = ops;
203 new_ld->class_dev.class = &lcd_class; 197 new_ld->class_dev.class = &lcd_class;
204 strlcpy(new_ld->class_dev.class_id, name, KOBJ_NAME_LEN); 198 strlcpy(new_ld->class_dev.class_id, name, KOBJ_NAME_LEN);
205 class_set_devdata(&new_ld->class_dev, devdata); 199 class_set_devdata(&new_ld->class_dev, devdata);
206 200
207 rc = class_device_register(&new_ld->class_dev); 201 rc = class_device_register(&new_ld->class_dev);
208 if (unlikely(rc)) { 202 if (rc) {
209error: kfree(new_ld); 203 kfree(new_ld);
210 return ERR_PTR(rc); 204 return ERR_PTR(rc);
211 } 205 }
212 206
213 rc = lcd_register_fb(new_ld); 207 rc = lcd_register_fb(new_ld);
214 208 if (rc) {
215 if (unlikely(rc)) 209 class_device_unregister(&new_ld->class_dev);
216 goto error; 210 return ERR_PTR(rc);
211 }
217 212
218 for (i = 0; i < ARRAY_SIZE(lcd_class_device_attributes); i++) { 213 for (i = 0; i < ARRAY_SIZE(lcd_class_device_attributes); i++) {
219 rc = class_device_create_file(&new_ld->class_dev, 214 rc = class_device_create_file(&new_ld->class_dev,
220 &lcd_class_device_attributes[i]); 215 &lcd_class_device_attributes[i]);
221 if (unlikely(rc)) { 216 if (rc) {
222 while (--i >= 0) 217 while (--i >= 0)
223 class_device_remove_file(&new_ld->class_dev, 218 class_device_remove_file(&new_ld->class_dev,
224 &lcd_class_device_attributes[i]); 219 &lcd_class_device_attributes[i]);
@@ -251,9 +246,9 @@ void lcd_device_unregister(struct lcd_device *ld)
251 class_device_remove_file(&ld->class_dev, 246 class_device_remove_file(&ld->class_dev,
252 &lcd_class_device_attributes[i]); 247 &lcd_class_device_attributes[i]);
253 248
254 down(&ld->sem); 249 mutex_lock(&ld->ops_lock);
255 ld->props = NULL; 250 ld->ops = NULL;
256 up(&ld->sem); 251 mutex_unlock(&ld->ops_lock);
257 lcd_unregister_fb(ld); 252 lcd_unregister_fb(ld);
258 class_device_unregister(&ld->class_dev); 253 class_device_unregister(&ld->class_dev);
259} 254}
diff --git a/drivers/video/backlight/locomolcd.c b/drivers/video/backlight/locomolcd.c
index fc812d96c3..d131247781 100644
--- a/drivers/video/backlight/locomolcd.c
+++ b/drivers/video/backlight/locomolcd.c
@@ -112,11 +112,11 @@ static int current_intensity;
112 112
113static int locomolcd_set_intensity(struct backlight_device *bd) 113static int locomolcd_set_intensity(struct backlight_device *bd)
114{ 114{
115 int intensity = bd->props->brightness; 115 int intensity = bd->props.brightness;
116 116
117 if (bd->props->power != FB_BLANK_UNBLANK) 117 if (bd->props.power != FB_BLANK_UNBLANK)
118 intensity = 0; 118 intensity = 0;
119 if (bd->props->fb_blank != FB_BLANK_UNBLANK) 119 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
120 intensity = 0; 120 intensity = 0;
121 if (locomolcd_flags & LOCOMOLCD_SUSPENDED) 121 if (locomolcd_flags & LOCOMOLCD_SUSPENDED)
122 intensity = 0; 122 intensity = 0;
@@ -141,11 +141,9 @@ static int locomolcd_get_intensity(struct backlight_device *bd)
141 return current_intensity; 141 return current_intensity;
142} 142}
143 143
144static struct backlight_properties locomobl_data = { 144static struct backlight_ops locomobl_data = {
145 .owner = THIS_MODULE,
146 .get_brightness = locomolcd_get_intensity, 145 .get_brightness = locomolcd_get_intensity,
147 .update_status = locomolcd_set_intensity, 146 .update_status = locomolcd_set_intensity,
148 .max_brightness = 4,
149}; 147};
150 148
151#ifdef CONFIG_PM 149#ifdef CONFIG_PM
@@ -190,7 +188,8 @@ static int locomolcd_probe(struct locomo_dev *ldev)
190 return PTR_ERR (locomolcd_bl_device); 188 return PTR_ERR (locomolcd_bl_device);
191 189
192 /* Set up frontlight so that screen is readable */ 190 /* Set up frontlight so that screen is readable */
193 locomobl_data.brightness = 2; 191 locomolcd_bl_device->props.max_brightness = 4,
192 locomolcd_bl_device->props.brightness = 2;
194 locomolcd_set_intensity(locomolcd_bl_device); 193 locomolcd_set_intensity(locomolcd_bl_device);
195 194
196 return 0; 195 return 0;
diff --git a/drivers/video/backlight/progear_bl.c b/drivers/video/backlight/progear_bl.c
new file mode 100644
index 0000000000..7022693578
--- /dev/null
+++ b/drivers/video/backlight/progear_bl.c
@@ -0,0 +1,153 @@
1/*
2 * Backlight Driver for Frontpath ProGear HX1050+
3 *
4 * Copyright (c) 2006 Marcin Juszkiewicz
5 *
6 * Based on Progear LCD driver by M Schacht
7 * <mschacht at alumni dot washington dot edu>
8 *
9 * Based on Sharp's Corgi Backlight Driver
10 * Based on Backlight Driver for HP Jornada 680
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/kernel.h>
20#include <linux/init.h>
21#include <linux/platform_device.h>
22#include <linux/mutex.h>
23#include <linux/fb.h>
24#include <linux/backlight.h>
25#include <linux/pci.h>
26#include <asm/uaccess.h>
27
28#define PMU_LPCR 0xB0
29#define SB_MPS1 0x61
30#define HW_LEVEL_MAX 0x77
31#define HW_LEVEL_MIN 0x4f
32
33static struct pci_dev *pmu_dev = NULL;
34static struct pci_dev *sb_dev = NULL;
35
36static int progearbl_set_intensity(struct backlight_device *bd)
37{
38 int intensity = bd->props.brightness;
39
40 if (bd->props.power != FB_BLANK_UNBLANK)
41 intensity = 0;
42 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
43 intensity = 0;
44
45 pci_write_config_byte(pmu_dev, PMU_LPCR, intensity + HW_LEVEL_MIN);
46
47 return 0;
48}
49
50static int progearbl_get_intensity(struct backlight_device *bd)
51{
52 u8 intensity;
53 pci_read_config_byte(pmu_dev, PMU_LPCR, &intensity);
54
55 return intensity - HW_LEVEL_MIN;
56}
57
58static struct backlight_ops progearbl_ops = {
59 .get_brightness = progearbl_get_intensity,
60 .update_status = progearbl_set_intensity,
61};
62
63static int progearbl_probe(struct platform_device *pdev)
64{
65 u8 temp;
66 struct backlight_device *progear_backlight_device;
67
68 pmu_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101, 0);
69 if (!pmu_dev) {
70 printk("ALI M7101 PMU not found.\n");
71 return -ENODEV;
72 }
73
74 sb_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, 0);
75 if (!sb_dev) {
76 printk("ALI 1533 SB not found.\n");
77 pci_dev_put(pmu_dev);
78 return -ENODEV;
79 }
80
81 /* Set SB_MPS1 to enable brightness control. */
82 pci_read_config_byte(sb_dev, SB_MPS1, &temp);
83 pci_write_config_byte(sb_dev, SB_MPS1, temp | 0x20);
84
85 progear_backlight_device = backlight_device_register("progear-bl",
86 &pdev->dev, NULL,
87 &progearbl_ops);
88 if (IS_ERR(progear_backlight_device))
89 return PTR_ERR(progear_backlight_device);
90
91 platform_set_drvdata(pdev, progear_backlight_device);
92
93 progear_backlight_device->props.power = FB_BLANK_UNBLANK;
94 progear_backlight_device->props.brightness = HW_LEVEL_MAX - HW_LEVEL_MIN;
95 progear_backlight_device->props.max_brightness = HW_LEVEL_MAX - HW_LEVEL_MIN;
96 progearbl_set_intensity(progear_backlight_device);
97
98 return 0;
99}
100
101static int progearbl_remove(struct platform_device *pdev)
102{
103 struct backlight_device *bd = platform_get_drvdata(pdev);
104 backlight_device_unregister(bd);
105
106 return 0;
107}
108
109static struct platform_driver progearbl_driver = {
110 .probe = progearbl_probe,
111 .remove = progearbl_remove,
112 .driver = {
113 .name = "progear-bl",
114 },
115};
116
117static struct platform_device *progearbl_device;
118
119static int __init progearbl_init(void)
120{
121 int ret = platform_driver_register(&progearbl_driver);
122
123 if (!ret) {
124 progearbl_device = platform_device_alloc("progear-bl", -1);
125 if (!progearbl_device)
126 return -ENOMEM;
127
128 ret = platform_device_add(progearbl_device);
129
130 if (ret) {
131 platform_device_put(progearbl_device);
132 platform_driver_unregister(&progearbl_driver);
133 }
134 }
135
136 return ret;
137}
138
139static void __exit progearbl_exit(void)
140{
141 pci_dev_put(pmu_dev);
142 pci_dev_put(sb_dev);
143
144 platform_device_unregister(progearbl_device);
145 platform_driver_unregister(&progearbl_driver);
146}
147
148module_init(progearbl_init);
149module_exit(progearbl_exit);
150
151MODULE_AUTHOR("Marcin Juszkiewicz <linux@hrw.one.pl>");
152MODULE_DESCRIPTION("ProGear Backlight Driver");
153MODULE_LICENSE("GPL");
diff --git a/drivers/video/chipsfb.c b/drivers/video/chipsfb.c
index 73cb426bf2..af313bf1a2 100644
--- a/drivers/video/chipsfb.c
+++ b/drivers/video/chipsfb.c
@@ -145,26 +145,6 @@ static int chipsfb_set_par(struct fb_info *info)
145 145
146static int chipsfb_blank(int blank, struct fb_info *info) 146static int chipsfb_blank(int blank, struct fb_info *info)
147{ 147{
148#ifdef CONFIG_PMAC_BACKLIGHT
149 mutex_lock(&pmac_backlight_mutex);
150
151 if (pmac_backlight) {
152 /* used to disable backlight only for blank > 1, but it seems
153 * useful at blank = 1 too (saves battery, extends backlight
154 * life)
155 */
156 down(&pmac_backlight->sem);
157 if (blank)
158 pmac_backlight->props->power = FB_BLANK_POWERDOWN;
159 else
160 pmac_backlight->props->power = FB_BLANK_UNBLANK;
161 pmac_backlight->props->update_status(pmac_backlight);
162 up(&pmac_backlight->sem);
163 }
164
165 mutex_unlock(&pmac_backlight_mutex);
166#endif /* CONFIG_PMAC_BACKLIGHT */
167
168 return 1; /* get fb_blank to set the colormap to all black */ 148 return 1; /* get fb_blank to set the colormap to all black */
169} 149}
170 150
@@ -415,10 +395,8 @@ chipsfb_pci_init(struct pci_dev *dp, const struct pci_device_id *ent)
415 /* turn on the backlight */ 395 /* turn on the backlight */
416 mutex_lock(&pmac_backlight_mutex); 396 mutex_lock(&pmac_backlight_mutex);
417 if (pmac_backlight) { 397 if (pmac_backlight) {
418 down(&pmac_backlight->sem); 398 pmac_backlight->props.power = FB_BLANK_UNBLANK;
419 pmac_backlight->props->power = FB_BLANK_UNBLANK; 399 backlight_update_status(pmac_backlight);
420 pmac_backlight->props->update_status(pmac_backlight);
421 up(&pmac_backlight->sem);
422 } 400 }
423 mutex_unlock(&pmac_backlight_mutex); 401 mutex_unlock(&pmac_backlight_mutex);
424#endif /* CONFIG_PMAC_BACKLIGHT */ 402#endif /* CONFIG_PMAC_BACKLIGHT */
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index be3f2c3f13..0429fd2cec 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -2233,6 +2233,8 @@ static int fbcon_switch(struct vc_data *vc)
2233static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info, 2233static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2234 int blank) 2234 int blank)
2235{ 2235{
2236 struct fb_event event;
2237
2236 if (blank) { 2238 if (blank) {
2237 unsigned short charmask = vc->vc_hi_font_mask ? 2239 unsigned short charmask = vc->vc_hi_font_mask ?
2238 0x1ff : 0xff; 2240 0x1ff : 0xff;
@@ -2243,6 +2245,11 @@ static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2243 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols); 2245 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2244 vc->vc_video_erase_char = oldc; 2246 vc->vc_video_erase_char = oldc;
2245 } 2247 }
2248
2249
2250 event.info = info;
2251 event.data = &blank;
2252 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2246} 2253}
2247 2254
2248static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch) 2255static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
diff --git a/drivers/video/fbsysfs.c b/drivers/video/fbsysfs.c
index 818fb09105..40c80c8190 100644
--- a/drivers/video/fbsysfs.c
+++ b/drivers/video/fbsysfs.c
@@ -59,7 +59,7 @@ struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
59 info->device = dev; 59 info->device = dev;
60 60
61#ifdef CONFIG_FB_BACKLIGHT 61#ifdef CONFIG_FB_BACKLIGHT
62 mutex_init(&info->bl_mutex); 62 mutex_init(&info->bl_curve_mutex);
63#endif 63#endif
64 64
65 return info; 65 return info;
@@ -445,10 +445,10 @@ static ssize_t store_bl_curve(struct device *device,
445 /* If there has been an error in the input data, we won't 445 /* If there has been an error in the input data, we won't
446 * reach this loop. 446 * reach this loop.
447 */ 447 */
448 mutex_lock(&fb_info->bl_mutex); 448 mutex_lock(&fb_info->bl_curve_mutex);
449 for (i = 0; i < FB_BACKLIGHT_LEVELS; ++i) 449 for (i = 0; i < FB_BACKLIGHT_LEVELS; ++i)
450 fb_info->bl_curve[i] = tmp_curve[i]; 450 fb_info->bl_curve[i] = tmp_curve[i];
451 mutex_unlock(&fb_info->bl_mutex); 451 mutex_unlock(&fb_info->bl_curve_mutex);
452 452
453 return count; 453 return count;
454} 454}
@@ -466,7 +466,7 @@ static ssize_t show_bl_curve(struct device *device,
466 if (!fb_info || !fb_info->bl_dev) 466 if (!fb_info || !fb_info->bl_dev)
467 return -ENODEV; 467 return -ENODEV;
468 468
469 mutex_lock(&fb_info->bl_mutex); 469 mutex_lock(&fb_info->bl_curve_mutex);
470 for (i = 0; i < FB_BACKLIGHT_LEVELS; i += 8) 470 for (i = 0; i < FB_BACKLIGHT_LEVELS; i += 8)
471 len += snprintf(&buf[len], PAGE_SIZE, 471 len += snprintf(&buf[len], PAGE_SIZE,
472 "%02x %02x %02x %02x %02x %02x %02x %02x\n", 472 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
@@ -478,7 +478,7 @@ static ssize_t show_bl_curve(struct device *device,
478 fb_info->bl_curve[i + 5], 478 fb_info->bl_curve[i + 5],
479 fb_info->bl_curve[i + 6], 479 fb_info->bl_curve[i + 6],
480 fb_info->bl_curve[i + 7]); 480 fb_info->bl_curve[i + 7]);
481 mutex_unlock(&fb_info->bl_mutex); 481 mutex_unlock(&fb_info->bl_curve_mutex);
482 482
483 return len; 483 return len;
484} 484}
@@ -552,6 +552,8 @@ void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max)
552{ 552{
553 unsigned int i, flat, count, range = (max - min); 553 unsigned int i, flat, count, range = (max - min);
554 554
555 mutex_lock(&fb_info->bl_curve_mutex);
556
555 fb_info->bl_curve[0] = off; 557 fb_info->bl_curve[0] = off;
556 558
557 for (flat = 1; flat < (FB_BACKLIGHT_LEVELS / 16); ++flat) 559 for (flat = 1; flat < (FB_BACKLIGHT_LEVELS / 16); ++flat)
@@ -560,6 +562,8 @@ void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max)
560 count = FB_BACKLIGHT_LEVELS * 15 / 16; 562 count = FB_BACKLIGHT_LEVELS * 15 / 16;
561 for (i = 0; i < count; ++i) 563 for (i = 0; i < count; ++i)
562 fb_info->bl_curve[flat + i] = min + (range * (i + 1) / count); 564 fb_info->bl_curve[flat + i] = min + (range * (i + 1) / count);
565
566 mutex_unlock(&fb_info->bl_curve_mutex);
563} 567}
564EXPORT_SYMBOL_GPL(fb_bl_default_curve); 568EXPORT_SYMBOL_GPL(fb_bl_default_curve);
565#endif 569#endif
diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
index ab1b8fe34d..7e760197cf 100644
--- a/drivers/video/i810/i810_main.c
+++ b/drivers/video/i810/i810_main.c
@@ -142,7 +142,7 @@ static int hsync2 __devinitdata;
142static int vsync1 __devinitdata; 142static int vsync1 __devinitdata;
143static int vsync2 __devinitdata; 143static int vsync2 __devinitdata;
144static int xres __devinitdata; 144static int xres __devinitdata;
145static int yres __devinitdata; 145static int yres;
146static int vyres __devinitdata; 146static int vyres __devinitdata;
147static int sync __devinitdata; 147static int sync __devinitdata;
148static int extvga __devinitdata; 148static int extvga __devinitdata;
diff --git a/drivers/video/nvidia/nv_backlight.c b/drivers/video/nvidia/nv_backlight.c
index df934bd218..43f62d8ee4 100644
--- a/drivers/video/nvidia/nv_backlight.c
+++ b/drivers/video/nvidia/nv_backlight.c
@@ -12,15 +12,15 @@
12#include <linux/backlight.h> 12#include <linux/backlight.h>
13#include <linux/fb.h> 13#include <linux/fb.h>
14#include <linux/pci.h> 14#include <linux/pci.h>
15#include "nv_local.h"
16#include "nv_type.h"
17#include "nv_proto.h"
18 15
19#ifdef CONFIG_PMAC_BACKLIGHT 16#ifdef CONFIG_PMAC_BACKLIGHT
20#include <asm/backlight.h> 17#include <asm/backlight.h>
21#include <asm/machdep.h>
22#endif 18#endif
23 19
20#include "nv_local.h"
21#include "nv_type.h"
22#include "nv_proto.h"
23
24/* We do not have any information about which values are allowed, thus 24/* We do not have any information about which values are allowed, thus
25 * we used safe values. 25 * we used safe values.
26 */ 26 */
@@ -28,9 +28,6 @@
28#define MAX_LEVEL 0x534 28#define MAX_LEVEL 0x534
29#define LEVEL_STEP ((MAX_LEVEL - MIN_LEVEL) / FB_BACKLIGHT_MAX) 29#define LEVEL_STEP ((MAX_LEVEL - MIN_LEVEL) / FB_BACKLIGHT_MAX)
30 30
31static struct backlight_properties nvidia_bl_data;
32
33/* Call with fb_info->bl_mutex held */
34static int nvidia_bl_get_level_brightness(struct nvidia_par *par, 31static int nvidia_bl_get_level_brightness(struct nvidia_par *par,
35 int level) 32 int level)
36{ 33{
@@ -38,6 +35,7 @@ static int nvidia_bl_get_level_brightness(struct nvidia_par *par,
38 int nlevel; 35 int nlevel;
39 36
40 /* Get and convert the value */ 37 /* Get and convert the value */
38 /* No locking of bl_curve since we read a single value */
41 nlevel = MIN_LEVEL + info->bl_curve[level] * LEVEL_STEP; 39 nlevel = MIN_LEVEL + info->bl_curve[level] * LEVEL_STEP;
42 40
43 if (nlevel < 0) 41 if (nlevel < 0)
@@ -50,8 +48,7 @@ static int nvidia_bl_get_level_brightness(struct nvidia_par *par,
50 return nlevel; 48 return nlevel;
51} 49}
52 50
53/* Call with fb_info->bl_mutex held */ 51static int nvidia_bl_update_status(struct backlight_device *bd)
54static int __nvidia_bl_update_status(struct backlight_device *bd)
55{ 52{
56 struct nvidia_par *par = class_get_devdata(&bd->class_dev); 53 struct nvidia_par *par = class_get_devdata(&bd->class_dev);
57 u32 tmp_pcrt, tmp_pmc, fpcontrol; 54 u32 tmp_pcrt, tmp_pmc, fpcontrol;
@@ -60,11 +57,11 @@ static int __nvidia_bl_update_status(struct backlight_device *bd)
60 if (!par->FlatPanel) 57 if (!par->FlatPanel)
61 return 0; 58 return 0;
62 59
63 if (bd->props->power != FB_BLANK_UNBLANK || 60 if (bd->props.power != FB_BLANK_UNBLANK ||
64 bd->props->fb_blank != FB_BLANK_UNBLANK) 61 bd->props.fb_blank != FB_BLANK_UNBLANK)
65 level = 0; 62 level = 0;
66 else 63 else
67 level = bd->props->brightness; 64 level = bd->props.brightness;
68 65
69 tmp_pmc = NV_RD32(par->PMC, 0x10F0) & 0x0000FFFF; 66 tmp_pmc = NV_RD32(par->PMC, 0x10F0) & 0x0000FFFF;
70 tmp_pcrt = NV_RD32(par->PCRTC0, 0x081C) & 0xFFFFFFFC; 67 tmp_pcrt = NV_RD32(par->PCRTC0, 0x081C) & 0xFFFFFFFC;
@@ -85,45 +82,16 @@ static int __nvidia_bl_update_status(struct backlight_device *bd)
85 return 0; 82 return 0;
86} 83}
87 84
88static int nvidia_bl_update_status(struct backlight_device *bd)
89{
90 struct nvidia_par *par = class_get_devdata(&bd->class_dev);
91 struct fb_info *info = pci_get_drvdata(par->pci_dev);
92 int ret;
93
94 mutex_lock(&info->bl_mutex);
95 ret = __nvidia_bl_update_status(bd);
96 mutex_unlock(&info->bl_mutex);
97
98 return ret;
99}
100
101static int nvidia_bl_get_brightness(struct backlight_device *bd) 85static int nvidia_bl_get_brightness(struct backlight_device *bd)
102{ 86{
103 return bd->props->brightness; 87 return bd->props.brightness;
104} 88}
105 89
106static struct backlight_properties nvidia_bl_data = { 90static struct backlight_ops nvidia_bl_ops = {
107 .owner = THIS_MODULE,
108 .get_brightness = nvidia_bl_get_brightness, 91 .get_brightness = nvidia_bl_get_brightness,
109 .update_status = nvidia_bl_update_status, 92 .update_status = nvidia_bl_update_status,
110 .max_brightness = (FB_BACKLIGHT_LEVELS - 1),
111}; 93};
112 94
113void nvidia_bl_set_power(struct fb_info *info, int power)
114{
115 mutex_lock(&info->bl_mutex);
116
117 if (info->bl_dev) {
118 down(&info->bl_dev->sem);
119 info->bl_dev->props->power = power;
120 __nvidia_bl_update_status(info->bl_dev);
121 up(&info->bl_dev->sem);
122 }
123
124 mutex_unlock(&info->bl_mutex);
125}
126
127void nvidia_bl_init(struct nvidia_par *par) 95void nvidia_bl_init(struct nvidia_par *par)
128{ 96{
129 struct fb_info *info = pci_get_drvdata(par->pci_dev); 97 struct fb_info *info = pci_get_drvdata(par->pci_dev);
@@ -141,32 +109,22 @@ void nvidia_bl_init(struct nvidia_par *par)
141 109
142 snprintf(name, sizeof(name), "nvidiabl%d", info->node); 110 snprintf(name, sizeof(name), "nvidiabl%d", info->node);
143 111
144 bd = backlight_device_register(name, info->dev, par, &nvidia_bl_data); 112 bd = backlight_device_register(name, info->dev, par, &nvidia_bl_ops);
145 if (IS_ERR(bd)) { 113 if (IS_ERR(bd)) {
146 info->bl_dev = NULL; 114 info->bl_dev = NULL;
147 printk(KERN_WARNING "nvidia: Backlight registration failed\n"); 115 printk(KERN_WARNING "nvidia: Backlight registration failed\n");
148 goto error; 116 goto error;
149 } 117 }
150 118
151 mutex_lock(&info->bl_mutex);
152 info->bl_dev = bd; 119 info->bl_dev = bd;
153 fb_bl_default_curve(info, 0, 120 fb_bl_default_curve(info, 0,
154 0x158 * FB_BACKLIGHT_MAX / MAX_LEVEL, 121 0x158 * FB_BACKLIGHT_MAX / MAX_LEVEL,
155 0x534 * FB_BACKLIGHT_MAX / MAX_LEVEL); 122 0x534 * FB_BACKLIGHT_MAX / MAX_LEVEL);
156 mutex_unlock(&info->bl_mutex);
157 123
158 down(&bd->sem); 124 bd->props.max_brightness = FB_BACKLIGHT_LEVELS - 1;
159 bd->props->brightness = nvidia_bl_data.max_brightness; 125 bd->props.brightness = bd->props.max_brightness;
160 bd->props->power = FB_BLANK_UNBLANK; 126 bd->props.power = FB_BLANK_UNBLANK;
161 bd->props->update_status(bd); 127 backlight_update_status(bd);
162 up(&bd->sem);
163
164#ifdef CONFIG_PMAC_BACKLIGHT
165 mutex_lock(&pmac_backlight_mutex);
166 if (!pmac_backlight)
167 pmac_backlight = bd;
168 mutex_unlock(&pmac_backlight_mutex);
169#endif
170 128
171 printk("nvidia: Backlight initialized (%s)\n", name); 129 printk("nvidia: Backlight initialized (%s)\n", name);
172 130
@@ -179,25 +137,8 @@ error:
179void nvidia_bl_exit(struct nvidia_par *par) 137void nvidia_bl_exit(struct nvidia_par *par)
180{ 138{
181 struct fb_info *info = pci_get_drvdata(par->pci_dev); 139 struct fb_info *info = pci_get_drvdata(par->pci_dev);
140 struct backlight_device *bd = info->bl_dev;
182 141
183#ifdef CONFIG_PMAC_BACKLIGHT 142 backlight_device_unregister(bd);
184 mutex_lock(&pmac_backlight_mutex); 143 printk("nvidia: Backlight unloaded\n");
185#endif
186
187 mutex_lock(&info->bl_mutex);
188 if (info->bl_dev) {
189#ifdef CONFIG_PMAC_BACKLIGHT
190 if (pmac_backlight == info->bl_dev)
191 pmac_backlight = NULL;
192#endif
193
194 backlight_device_unregister(info->bl_dev);
195
196 printk("nvidia: Backlight unloaded\n");
197 }
198 mutex_unlock(&info->bl_mutex);
199
200#ifdef CONFIG_PMAC_BACKLIGHT
201 mutex_unlock(&pmac_backlight_mutex);
202#endif
203} 144}
diff --git a/drivers/video/nvidia/nv_proto.h b/drivers/video/nvidia/nv_proto.h
index 43058d0cf5..ff5c410355 100644
--- a/drivers/video/nvidia/nv_proto.h
+++ b/drivers/video/nvidia/nv_proto.h
@@ -67,11 +67,9 @@ extern int nvidiafb_sync(struct fb_info *info);
67#ifdef CONFIG_FB_NVIDIA_BACKLIGHT 67#ifdef CONFIG_FB_NVIDIA_BACKLIGHT
68extern void nvidia_bl_init(struct nvidia_par *par); 68extern void nvidia_bl_init(struct nvidia_par *par);
69extern void nvidia_bl_exit(struct nvidia_par *par); 69extern void nvidia_bl_exit(struct nvidia_par *par);
70extern void nvidia_bl_set_power(struct fb_info *info, int power);
71#else 70#else
72static inline void nvidia_bl_init(struct nvidia_par *par) {} 71static inline void nvidia_bl_init(struct nvidia_par *par) {}
73static inline void nvidia_bl_exit(struct nvidia_par *par) {} 72static inline void nvidia_bl_exit(struct nvidia_par *par) {}
74static inline void nvidia_bl_set_power(struct fb_info *info, int power) {}
75#endif 73#endif
76 74
77#endif /* __NV_PROTO_H__ */ 75#endif /* __NV_PROTO_H__ */
diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
index 8e5b484db6..b97ec69012 100644
--- a/drivers/video/nvidia/nvidia.c
+++ b/drivers/video/nvidia/nvidia.c
@@ -83,6 +83,11 @@ static int bpp __devinitdata = 8;
83#ifdef CONFIG_MTRR 83#ifdef CONFIG_MTRR
84static int nomtrr __devinitdata = 0; 84static int nomtrr __devinitdata = 0;
85#endif 85#endif
86#ifdef CONFIG_PMAC_BACKLIGHT
87static int backlight __devinitdata = 1;
88#else
89static int backlight __devinitdata = 0;
90#endif
86 91
87static char *mode_option __devinitdata = NULL; 92static char *mode_option __devinitdata = NULL;
88 93
@@ -938,8 +943,6 @@ static int nvidiafb_blank(int blank, struct fb_info *info)
938 NVWriteSeq(par, 0x01, tmp); 943 NVWriteSeq(par, 0x01, tmp);
939 NVWriteCrtc(par, 0x1a, vesa); 944 NVWriteCrtc(par, 0x1a, vesa);
940 945
941 nvidia_bl_set_power(info, blank);
942
943 NVTRACE_LEAVE(); 946 NVTRACE_LEAVE();
944 947
945 return 0; 948 return 0;
@@ -1313,7 +1316,10 @@ static int __devinit nvidiafb_probe(struct pci_dev *pd,
1313 nvidia_save_vga(par, &par->SavedReg); 1316 nvidia_save_vga(par, &par->SavedReg);
1314 1317
1315 pci_set_drvdata(pd, info); 1318 pci_set_drvdata(pd, info);
1316 nvidia_bl_init(par); 1319
1320 if (backlight)
1321 nvidia_bl_init(par);
1322
1317 if (register_framebuffer(info) < 0) { 1323 if (register_framebuffer(info) < 0) {
1318 printk(KERN_ERR PFX "error registering nVidia framebuffer\n"); 1324 printk(KERN_ERR PFX "error registering nVidia framebuffer\n");
1319 goto err_out_iounmap_fb; 1325 goto err_out_iounmap_fb;
@@ -1352,9 +1358,10 @@ static void __devexit nvidiafb_remove(struct pci_dev *pd)
1352 1358
1353 NVTRACE_ENTER(); 1359 NVTRACE_ENTER();
1354 1360
1361 unregister_framebuffer(info);
1362
1355 nvidia_bl_exit(par); 1363 nvidia_bl_exit(par);
1356 1364
1357 unregister_framebuffer(info);
1358#ifdef CONFIG_MTRR 1365#ifdef CONFIG_MTRR
1359 if (par->mtrr.vram_valid) 1366 if (par->mtrr.vram_valid)
1360 mtrr_del(par->mtrr.vram, info->fix.smem_start, 1367 mtrr_del(par->mtrr.vram, info->fix.smem_start,
@@ -1409,6 +1416,8 @@ static int __devinit nvidiafb_setup(char *options)
1409 paneltweak = simple_strtoul(this_opt+11, NULL, 0); 1416 paneltweak = simple_strtoul(this_opt+11, NULL, 0);
1410 } else if (!strncmp(this_opt, "vram:", 5)) { 1417 } else if (!strncmp(this_opt, "vram:", 5)) {
1411 vram = simple_strtoul(this_opt+5, NULL, 0); 1418 vram = simple_strtoul(this_opt+5, NULL, 0);
1419 } else if (!strncmp(this_opt, "backlight:", 10)) {
1420 backlight = simple_strtoul(this_opt+10, NULL, 0);
1412#ifdef CONFIG_MTRR 1421#ifdef CONFIG_MTRR
1413 } else if (!strncmp(this_opt, "nomtrr", 6)) { 1422 } else if (!strncmp(this_opt, "nomtrr", 6)) {
1414 nomtrr = 1; 1423 nomtrr = 1;
diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
index f2e9b742c9..1d1c7c624d 100644
--- a/drivers/video/riva/fbdev.c
+++ b/drivers/video/riva/fbdev.c
@@ -215,6 +215,11 @@ static int noaccel __devinitdata = 0;
215#ifdef CONFIG_MTRR 215#ifdef CONFIG_MTRR
216static int nomtrr __devinitdata = 0; 216static int nomtrr __devinitdata = 0;
217#endif 217#endif
218#ifdef CONFIG_PMAC_BACKLIGHT
219static int backlight __devinitdata = 1;
220#else
221static int backlight __devinitdata = 0;
222#endif
218 223
219static char *mode_option __devinitdata = NULL; 224static char *mode_option __devinitdata = NULL;
220static int strictmode = 0; 225static int strictmode = 0;
@@ -282,7 +287,6 @@ static const struct riva_regs reg_template = {
282 287
283static struct backlight_properties riva_bl_data; 288static struct backlight_properties riva_bl_data;
284 289
285/* Call with fb_info->bl_mutex held */
286static int riva_bl_get_level_brightness(struct riva_par *par, 290static int riva_bl_get_level_brightness(struct riva_par *par,
287 int level) 291 int level)
288{ 292{
@@ -290,6 +294,7 @@ static int riva_bl_get_level_brightness(struct riva_par *par,
290 int nlevel; 294 int nlevel;
291 295
292 /* Get and convert the value */ 296 /* Get and convert the value */
297 /* No locking on bl_curve since accessing a single value */
293 nlevel = MIN_LEVEL + info->bl_curve[level] * LEVEL_STEP; 298 nlevel = MIN_LEVEL + info->bl_curve[level] * LEVEL_STEP;
294 299
295 if (nlevel < 0) 300 if (nlevel < 0)
@@ -302,18 +307,17 @@ static int riva_bl_get_level_brightness(struct riva_par *par,
302 return nlevel; 307 return nlevel;
303} 308}
304 309
305/* Call with fb_info->bl_mutex held */ 310static int riva_bl_update_status(struct backlight_device *bd)
306static int __riva_bl_update_status(struct backlight_device *bd)
307{ 311{
308 struct riva_par *par = class_get_devdata(&bd->class_dev); 312 struct riva_par *par = class_get_devdata(&bd->class_dev);
309 U032 tmp_pcrt, tmp_pmc; 313 U032 tmp_pcrt, tmp_pmc;
310 int level; 314 int level;
311 315
312 if (bd->props->power != FB_BLANK_UNBLANK || 316 if (bd->props.power != FB_BLANK_UNBLANK ||
313 bd->props->fb_blank != FB_BLANK_UNBLANK) 317 bd->props.fb_blank != FB_BLANK_UNBLANK)
314 level = 0; 318 level = 0;
315 else 319 else
316 level = bd->props->brightness; 320 level = bd->props.brightness;
317 321
318 tmp_pmc = par->riva.PMC[0x10F0/4] & 0x0000FFFF; 322 tmp_pmc = par->riva.PMC[0x10F0/4] & 0x0000FFFF;
319 tmp_pcrt = par->riva.PCRTC0[0x081C/4] & 0xFFFFFFFC; 323 tmp_pcrt = par->riva.PCRTC0[0x081C/4] & 0xFFFFFFFC;
@@ -328,45 +332,16 @@ static int __riva_bl_update_status(struct backlight_device *bd)
328 return 0; 332 return 0;
329} 333}
330 334
331static int riva_bl_update_status(struct backlight_device *bd)
332{
333 struct riva_par *par = class_get_devdata(&bd->class_dev);
334 struct fb_info *info = pci_get_drvdata(par->pdev);
335 int ret;
336
337 mutex_lock(&info->bl_mutex);
338 ret = __riva_bl_update_status(bd);
339 mutex_unlock(&info->bl_mutex);
340
341 return ret;
342}
343
344static int riva_bl_get_brightness(struct backlight_device *bd) 335static int riva_bl_get_brightness(struct backlight_device *bd)
345{ 336{
346 return bd->props->brightness; 337 return bd->props.brightness;
347} 338}
348 339
349static struct backlight_properties riva_bl_data = { 340static struct backlight_ops riva_bl_ops = {
350 .owner = THIS_MODULE,
351 .get_brightness = riva_bl_get_brightness, 341 .get_brightness = riva_bl_get_brightness,
352 .update_status = riva_bl_update_status, 342 .update_status = riva_bl_update_status,
353 .max_brightness = (FB_BACKLIGHT_LEVELS - 1),
354}; 343};
355 344
356static void riva_bl_set_power(struct fb_info *info, int power)
357{
358 mutex_lock(&info->bl_mutex);
359
360 if (info->bl_dev) {
361 down(&info->bl_dev->sem);
362 info->bl_dev->props->power = power;
363 __riva_bl_update_status(info->bl_dev);
364 up(&info->bl_dev->sem);
365 }
366
367 mutex_unlock(&info->bl_mutex);
368}
369
370static void riva_bl_init(struct riva_par *par) 345static void riva_bl_init(struct riva_par *par)
371{ 346{
372 struct fb_info *info = pci_get_drvdata(par->pdev); 347 struct fb_info *info = pci_get_drvdata(par->pdev);
@@ -384,32 +359,22 @@ static void riva_bl_init(struct riva_par *par)
384 359
385 snprintf(name, sizeof(name), "rivabl%d", info->node); 360 snprintf(name, sizeof(name), "rivabl%d", info->node);
386 361
387 bd = backlight_device_register(name, info->dev, par, &riva_bl_data); 362 bd = backlight_device_register(name, info->dev, par, &riva_bl_ops);
388 if (IS_ERR(bd)) { 363 if (IS_ERR(bd)) {
389 info->bl_dev = NULL; 364 info->bl_dev = NULL;
390 printk(KERN_WARNING "riva: Backlight registration failed\n"); 365 printk(KERN_WARNING "riva: Backlight registration failed\n");
391 goto error; 366 goto error;
392 } 367 }
393 368
394 mutex_lock(&info->bl_mutex);
395 info->bl_dev = bd; 369 info->bl_dev = bd;
396 fb_bl_default_curve(info, 0, 370 fb_bl_default_curve(info, 0,
397 MIN_LEVEL * FB_BACKLIGHT_MAX / MAX_LEVEL, 371 MIN_LEVEL * FB_BACKLIGHT_MAX / MAX_LEVEL,
398 FB_BACKLIGHT_MAX); 372 FB_BACKLIGHT_MAX);
399 mutex_unlock(&info->bl_mutex);
400 373
401 down(&bd->sem); 374 bd->props.max_brightness = FB_BACKLIGHT_LEVELS - 1;
402 bd->props->brightness = riva_bl_data.max_brightness; 375 bd->props.brightness = riva_bl_data.max_brightness;
403 bd->props->power = FB_BLANK_UNBLANK; 376 bd->props.power = FB_BLANK_UNBLANK;
404 bd->props->update_status(bd); 377 backlight_update_status(bd);
405 up(&bd->sem);
406
407#ifdef CONFIG_PMAC_BACKLIGHT
408 mutex_lock(&pmac_backlight_mutex);
409 if (!pmac_backlight)
410 pmac_backlight = bd;
411 mutex_unlock(&pmac_backlight_mutex);
412#endif
413 378
414 printk("riva: Backlight initialized (%s)\n", name); 379 printk("riva: Backlight initialized (%s)\n", name);
415 380
@@ -419,35 +384,16 @@ error:
419 return; 384 return;
420} 385}
421 386
422static void riva_bl_exit(struct riva_par *par) 387static void riva_bl_exit(struct fb_info *info)
423{ 388{
424 struct fb_info *info = pci_get_drvdata(par->pdev); 389 struct backlight_device *bd = info->bl_dev;
425
426#ifdef CONFIG_PMAC_BACKLIGHT
427 mutex_lock(&pmac_backlight_mutex);
428#endif
429
430 mutex_lock(&info->bl_mutex);
431 if (info->bl_dev) {
432#ifdef CONFIG_PMAC_BACKLIGHT
433 if (pmac_backlight == info->bl_dev)
434 pmac_backlight = NULL;
435#endif
436
437 backlight_device_unregister(info->bl_dev);
438 390
439 printk("riva: Backlight unloaded\n"); 391 backlight_device_unregister(bd);
440 } 392 printk("riva: Backlight unloaded\n");
441 mutex_unlock(&info->bl_mutex);
442
443#ifdef CONFIG_PMAC_BACKLIGHT
444 mutex_unlock(&pmac_backlight_mutex);
445#endif
446} 393}
447#else 394#else
448static inline void riva_bl_init(struct riva_par *par) {} 395static inline void riva_bl_init(struct riva_par *par) {}
449static inline void riva_bl_exit(struct riva_par *par) {} 396static inline void riva_bl_exit(struct fb_info *info) {}
450static inline void riva_bl_set_power(struct fb_info *info, int power) {}
451#endif /* CONFIG_FB_RIVA_BACKLIGHT */ 397#endif /* CONFIG_FB_RIVA_BACKLIGHT */
452 398
453/* ------------------------------------------------------------------------- * 399/* ------------------------------------------------------------------------- *
@@ -1348,8 +1294,6 @@ static int rivafb_blank(int blank, struct fb_info *info)
1348 SEQout(par, 0x01, tmp); 1294 SEQout(par, 0x01, tmp);
1349 CRTCout(par, 0x1a, vesa); 1295 CRTCout(par, 0x1a, vesa);
1350 1296
1351 riva_bl_set_power(info, blank);
1352
1353 NVTRACE_LEAVE(); 1297 NVTRACE_LEAVE();
1354 1298
1355 return 0; 1299 return 0;
@@ -2120,7 +2064,10 @@ static int __devinit rivafb_probe(struct pci_dev *pd,
2120 info->monspecs.modedb = NULL; 2064 info->monspecs.modedb = NULL;
2121 2065
2122 pci_set_drvdata(pd, info); 2066 pci_set_drvdata(pd, info);
2123 riva_bl_init(info->par); 2067
2068 if (backlight)
2069 riva_bl_init(info->par);
2070
2124 ret = register_framebuffer(info); 2071 ret = register_framebuffer(info);
2125 if (ret < 0) { 2072 if (ret < 0) {
2126 printk(KERN_ERR PFX 2073 printk(KERN_ERR PFX
@@ -2166,14 +2113,15 @@ static void __exit rivafb_remove(struct pci_dev *pd)
2166 2113
2167 NVTRACE_ENTER(); 2114 NVTRACE_ENTER();
2168 2115
2169 riva_bl_exit(par);
2170
2171#ifdef CONFIG_FB_RIVA_I2C 2116#ifdef CONFIG_FB_RIVA_I2C
2172 riva_delete_i2c_busses(par); 2117 riva_delete_i2c_busses(par);
2173 kfree(par->EDID); 2118 kfree(par->EDID);
2174#endif 2119#endif
2175 2120
2176 unregister_framebuffer(info); 2121 unregister_framebuffer(info);
2122
2123 riva_bl_exit(info);
2124
2177#ifdef CONFIG_MTRR 2125#ifdef CONFIG_MTRR
2178 if (par->mtrr.vram_valid) 2126 if (par->mtrr.vram_valid)
2179 mtrr_del(par->mtrr.vram, info->fix.smem_start, 2127 mtrr_del(par->mtrr.vram, info->fix.smem_start,
@@ -2217,6 +2165,8 @@ static int __init rivafb_setup(char *options)
2217 forceCRTC = -1; 2165 forceCRTC = -1;
2218 } else if (!strncmp(this_opt, "flatpanel", 9)) { 2166 } else if (!strncmp(this_opt, "flatpanel", 9)) {
2219 flatpanel = 1; 2167 flatpanel = 1;
2168 } else if (!strncmp(this_opt, "backlight:", 10)) {
2169 backlight = simple_strtoul(this_opt+10, NULL, 0);
2220#ifdef CONFIG_MTRR 2170#ifdef CONFIG_MTRR
2221 } else if (!strncmp(this_opt, "nomtrr", 6)) { 2171 } else if (!strncmp(this_opt, "nomtrr", 6)) {
2222 nomtrr = 1; 2172 nomtrr = 1;
diff --git a/drivers/video/s3fb.c b/drivers/video/s3fb.c
index 3162c37b14..98919a6975 100644
--- a/drivers/video/s3fb.c
+++ b/drivers/video/s3fb.c
@@ -1134,11 +1134,11 @@ static int __init s3fb_setup(char *options)
1134 if (!*opt) 1134 if (!*opt)
1135 continue; 1135 continue;
1136#ifdef CONFIG_MTRR 1136#ifdef CONFIG_MTRR
1137 else if (!strcmp(opt, "mtrr:")) 1137 else if (!strncmp(opt, "mtrr:", 5))
1138 mtrr = simple_strtoul(opt + 5, NULL, 0); 1138 mtrr = simple_strtoul(opt + 5, NULL, 0);
1139#endif 1139#endif
1140 else if (!strcmp(opt, "fasttext:")) 1140 else if (!strncmp(opt, "fasttext:", 9))
1141 mtrr = simple_strtoul(opt + 9, NULL, 0); 1141 fasttext = simple_strtoul(opt + 9, NULL, 0);
1142 else 1142 else
1143 mode = opt; 1143 mode = opt;
1144 } 1144 }
diff --git a/drivers/video/sm501fb.c b/drivers/video/sm501fb.c
new file mode 100644
index 0000000000..0a44c44672
--- /dev/null
+++ b/drivers/video/sm501fb.c
@@ -0,0 +1,1786 @@
1/* linux/drivers/video/sm501fb.c
2 *
3 * Copyright (c) 2006 Simtec Electronics
4 * Vincent Sanders <vince@simtec.co.uk>
5 * Ben Dooks <ben@simtec.co.uk>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * Framebuffer driver for the Silicon Motion SM501
12 */
13
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/errno.h>
17#include <linux/string.h>
18#include <linux/mm.h>
19#include <linux/tty.h>
20#include <linux/slab.h>
21#include <linux/delay.h>
22#include <linux/fb.h>
23#include <linux/init.h>
24#include <linux/vmalloc.h>
25#include <linux/dma-mapping.h>
26#include <linux/interrupt.h>
27#include <linux/workqueue.h>
28#include <linux/wait.h>
29#include <linux/platform_device.h>
30#include <linux/clk.h>
31
32#include <asm/io.h>
33#include <asm/uaccess.h>
34#include <asm/div64.h>
35
36#ifdef CONFIG_PM
37#include <linux/pm.h>
38#endif
39
40#include <linux/sm501.h>
41#include <linux/sm501-regs.h>
42
43#define NR_PALETTE 256
44
45enum sm501_controller {
46 HEAD_CRT = 0,
47 HEAD_PANEL = 1,
48};
49
50/* SM501 memory adress */
51struct sm501_mem {
52 unsigned long size;
53 unsigned long sm_addr;
54 void __iomem *k_addr;
55};
56
57/* private data that is shared between all frambuffers* */
58struct sm501fb_info {
59 struct device *dev;
60 struct fb_info *fb[2]; /* fb info for both heads */
61 struct resource *fbmem_res; /* framebuffer resource */
62 struct resource *regs_res; /* registers resource */
63 struct sm501_platdata_fb *pdata; /* our platform data */
64
65 int irq;
66 int swap_endian; /* set to swap rgb=>bgr */
67 void __iomem *regs; /* remapped registers */
68 void __iomem *fbmem; /* remapped framebuffer */
69 size_t fbmem_len; /* length of remapped region */
70};
71
72/* per-framebuffer private data */
73struct sm501fb_par {
74 u32 pseudo_palette[16];
75
76 enum sm501_controller head;
77 struct sm501_mem cursor;
78 struct sm501_mem screen;
79 struct fb_ops ops;
80
81 void *store_fb;
82 void *store_cursor;
83 void __iomem *cursor_regs;
84 struct sm501fb_info *info;
85};
86
87/* Helper functions */
88
89static inline int h_total(struct fb_var_screeninfo *var)
90{
91 return var->xres + var->left_margin +
92 var->right_margin + var->hsync_len;
93}
94
95static inline int v_total(struct fb_var_screeninfo *var)
96{
97 return var->yres + var->upper_margin +
98 var->lower_margin + var->vsync_len;
99}
100
101/* sm501fb_sync_regs()
102 *
103 * This call is mainly for PCI bus systems where we need to
104 * ensure that any writes to the bus are completed before the
105 * next phase, or after completing a function.
106*/
107
108static inline void sm501fb_sync_regs(struct sm501fb_info *info)
109{
110 readl(info->regs);
111}
112
113/* sm501_alloc_mem
114 *
115 * This is an attempt to lay out memory for the two framebuffers and
116 * everything else
117 *
118 * |fbmem_res->start fbmem_res->end|
119 * | |
120 * |fb[0].fix.smem_start | |fb[1].fix.smem_start | 2K |
121 * |-> fb[0].fix.smem_len <-| spare |-> fb[1].fix.smem_len <-|-> cursors <-|
122 *
123 * The "spare" space is for the 2d engine data
124 * the fixed is space for the cursors (2x1Kbyte)
125 *
126 * we need to allocate memory for the 2D acceleration engine
127 * command list and the data for the engine to deal with.
128 *
129 * - all allocations must be 128bit aligned
130 * - cursors are 64x64x2 bits (1Kbyte)
131 *
132 */
133
134#define SM501_MEMF_CURSOR (1)
135#define SM501_MEMF_PANEL (2)
136#define SM501_MEMF_CRT (4)
137#define SM501_MEMF_ACCEL (8)
138
139static int sm501_alloc_mem(struct sm501fb_info *inf, struct sm501_mem *mem,
140 unsigned int why, size_t size)
141{
142 unsigned int ptr = 0;
143
144 switch (why) {
145 case SM501_MEMF_CURSOR:
146 ptr = inf->fbmem_len - size;
147 inf->fbmem_len = ptr;
148 break;
149
150 case SM501_MEMF_PANEL:
151 ptr = inf->fbmem_len - size;
152 if (ptr < inf->fb[0]->fix.smem_len)
153 return -ENOMEM;
154
155 break;
156
157 case SM501_MEMF_CRT:
158 ptr = 0;
159 break;
160
161 case SM501_MEMF_ACCEL:
162 ptr = inf->fb[0]->fix.smem_len;
163
164 if ((ptr + size) >
165 (inf->fb[1]->fix.smem_start - inf->fbmem_res->start))
166 return -ENOMEM;
167 break;
168
169 default:
170 return -EINVAL;
171 }
172
173 mem->size = size;
174 mem->sm_addr = ptr;
175 mem->k_addr = inf->fbmem + ptr;
176
177 dev_dbg(inf->dev, "%s: result %08lx, %p - %u, %zd\n",
178 __func__, mem->sm_addr, mem->k_addr, why, size);
179
180 return 0;
181}
182
183/* sm501fb_ps_to_hz
184 *
185 * Converts a period in picoseconds to Hz.
186 *
187 * Note, we try to keep this in Hz to minimise rounding with
188 * the limited PLL settings on the SM501.
189*/
190
191static unsigned long sm501fb_ps_to_hz(unsigned long psvalue)
192{
193 unsigned long long numerator=1000000000000ULL;
194
195 /* 10^12 / picosecond period gives frequency in Hz */
196 do_div(numerator, psvalue);
197 return (unsigned long)numerator;
198}
199
200/* sm501fb_hz_to_ps is identical to the oposite transform */
201
202#define sm501fb_hz_to_ps(x) sm501fb_ps_to_hz(x)
203
204/* sm501fb_setup_gamma
205 *
206 * Programs a linear 1.0 gamma ramp in case the gamma
207 * correction is enabled without programming anything else.
208*/
209
210static void sm501fb_setup_gamma(struct sm501fb_info *fbi,
211 unsigned long palette)
212{
213 unsigned long value = 0;
214 int offset;
215
216 /* set gamma values */
217 for (offset = 0; offset < 256 * 4; offset += 4) {
218 writel(value, fbi->regs + palette + offset);
219 value += 0x010101; /* Advance RGB by 1,1,1.*/
220 }
221}
222
223/* sm501fb_check_var
224 *
225 * check common variables for both panel and crt
226*/
227
228static int sm501fb_check_var(struct fb_var_screeninfo *var,
229 struct fb_info *info)
230{
231 struct sm501fb_par *par = info->par;
232 struct sm501fb_info *sm = par->info;
233 unsigned long tmp;
234
235 /* check we can fit these values into the registers */
236
237 if (var->hsync_len > 255 || var->vsync_len > 255)
238 return -EINVAL;
239
240 if ((var->xres + var->right_margin) >= 4096)
241 return -EINVAL;
242
243 if ((var->yres + var->lower_margin) > 2048)
244 return -EINVAL;
245
246 /* hard limits of device */
247
248 if (h_total(var) > 4096 || v_total(var) > 2048)
249 return -EINVAL;
250
251 /* check our line length is going to be 128 bit aligned */
252
253 tmp = (var->xres * var->bits_per_pixel) / 8;
254 if ((tmp & 15) != 0)
255 return -EINVAL;
256
257 /* check the virtual size */
258
259 if (var->xres_virtual > 4096 || var->yres_virtual > 2048)
260 return -EINVAL;
261
262 /* can cope with 8,16 or 32bpp */
263
264 if (var->bits_per_pixel <= 8)
265 var->bits_per_pixel = 8;
266 else if (var->bits_per_pixel <= 16)
267 var->bits_per_pixel = 16;
268 else if (var->bits_per_pixel == 24)
269 var->bits_per_pixel = 32;
270
271 /* set r/g/b positions and validate bpp */
272 switch(var->bits_per_pixel) {
273 case 8:
274 var->red.length = var->bits_per_pixel;
275 var->red.offset = 0;
276 var->green.length = var->bits_per_pixel;
277 var->green.offset = 0;
278 var->blue.length = var->bits_per_pixel;
279 var->blue.offset = 0;
280 var->transp.length = 0;
281
282 break;
283
284 case 16:
285 if (sm->pdata->flags & SM501_FBPD_SWAP_FB_ENDIAN) {
286 var->red.offset = 11;
287 var->green.offset = 5;
288 var->blue.offset = 0;
289 } else {
290 var->blue.offset = 11;
291 var->green.offset = 5;
292 var->red.offset = 0;
293 }
294
295 var->red.length = 5;
296 var->green.length = 6;
297 var->blue.length = 5;
298 var->transp.length = 0;
299 break;
300
301 case 32:
302 if (sm->pdata->flags & SM501_FBPD_SWAP_FB_ENDIAN) {
303 var->transp.offset = 0;
304 var->red.offset = 8;
305 var->green.offset = 16;
306 var->blue.offset = 24;
307 } else {
308 var->transp.offset = 24;
309 var->red.offset = 16;
310 var->green.offset = 8;
311 var->blue.offset = 0;
312 }
313
314 var->red.length = 8;
315 var->green.length = 8;
316 var->blue.length = 8;
317 var->transp.length = 0;
318 break;
319
320 default:
321 return -EINVAL;
322 }
323
324 return 0;
325}
326
327/*
328 * sm501fb_check_var_crt():
329 *
330 * check the parameters for the CRT head, and either bring them
331 * back into range, or return -EINVAL.
332*/
333
334static int sm501fb_check_var_crt(struct fb_var_screeninfo *var,
335 struct fb_info *info)
336{
337 return sm501fb_check_var(var, info);
338}
339
340/* sm501fb_check_var_pnl():
341 *
342 * check the parameters for the CRT head, and either bring them
343 * back into range, or return -EINVAL.
344*/
345
346static int sm501fb_check_var_pnl(struct fb_var_screeninfo *var,
347 struct fb_info *info)
348{
349 return sm501fb_check_var(var, info);
350}
351
352/* sm501fb_set_par_common
353 *
354 * set common registers for framebuffers
355*/
356
357static int sm501fb_set_par_common(struct fb_info *info,
358 struct fb_var_screeninfo *var)
359{
360 struct sm501fb_par *par = info->par;
361 struct sm501fb_info *fbi = par->info;
362 unsigned long pixclock; /* pixelclock in Hz */
363 unsigned long sm501pixclock; /* pixelclock the 501 can achive in Hz */
364 unsigned int mem_type;
365 unsigned int clock_type;
366 unsigned int head_addr;
367
368 dev_dbg(fbi->dev, "%s: %dx%d, bpp = %d, virtual %dx%d\n",
369 __func__, var->xres, var->yres, var->bits_per_pixel,
370 var->xres_virtual, var->yres_virtual);
371
372 switch (par->head) {
373 case HEAD_CRT:
374 mem_type = SM501_MEMF_CRT;
375 clock_type = SM501_CLOCK_V2XCLK;
376 head_addr = SM501_DC_CRT_FB_ADDR;
377 break;
378
379 case HEAD_PANEL:
380 mem_type = SM501_MEMF_PANEL;
381 clock_type = SM501_CLOCK_P2XCLK;
382 head_addr = SM501_DC_PANEL_FB_ADDR;
383 break;
384
385 default:
386 mem_type = 0; /* stop compiler warnings */
387 head_addr = 0;
388 clock_type = 0;
389 }
390
391 switch (var->bits_per_pixel) {
392 case 8:
393 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
394 break;
395
396 case 16:
397 info->fix.visual = FB_VISUAL_DIRECTCOLOR;
398 break;
399
400 case 32:
401 info->fix.visual = FB_VISUAL_TRUECOLOR;
402 break;
403 }
404
405 /* allocate fb memory within 501 */
406 info->fix.line_length = (var->xres_virtual * var->bits_per_pixel)/8;
407 info->fix.smem_len = info->fix.line_length * var->yres_virtual;
408
409 dev_dbg(fbi->dev, "%s: line length = %u\n", __func__,
410 info->fix.line_length);
411
412 if (sm501_alloc_mem(fbi, &par->screen, mem_type,
413 info->fix.smem_len)) {
414 dev_err(fbi->dev, "no memory available\n");
415 return -ENOMEM;
416 }
417
418 info->fix.smem_start = fbi->fbmem_res->start + par->screen.sm_addr;
419
420 info->screen_base = fbi->fbmem + par->screen.sm_addr;
421 info->screen_size = info->fix.smem_len;
422
423 /* set start of framebuffer to the screen */
424
425 writel(par->screen.sm_addr | SM501_ADDR_FLIP, fbi->regs + head_addr);
426
427 /* program CRT clock */
428
429 pixclock = sm501fb_ps_to_hz(var->pixclock);
430
431 sm501pixclock = sm501_set_clock(fbi->dev->parent, clock_type,
432 pixclock);
433
434 /* update fb layer with actual clock used */
435 var->pixclock = sm501fb_hz_to_ps(sm501pixclock);
436
437 dev_dbg(fbi->dev, "%s: pixclock(ps) = %u, pixclock(Hz) = %lu, "
438 "sm501pixclock = %lu, error = %ld%%\n",
439 __func__, var->pixclock, pixclock, sm501pixclock,
440 ((pixclock - sm501pixclock)*100)/pixclock);
441
442 return 0;
443}
444
445/* sm501fb_set_par_geometry
446 *
447 * set the geometry registers for specified framebuffer.
448*/
449
450static void sm501fb_set_par_geometry(struct fb_info *info,
451 struct fb_var_screeninfo *var)
452{
453 struct sm501fb_par *par = info->par;
454 struct sm501fb_info *fbi = par->info;
455 void __iomem *base = fbi->regs;
456 unsigned long reg;
457
458 if (par->head == HEAD_CRT)
459 base += SM501_DC_CRT_H_TOT;
460 else
461 base += SM501_DC_PANEL_H_TOT;
462
463 /* set framebuffer width and display width */
464
465 reg = info->fix.line_length;
466 reg |= ((var->xres * var->bits_per_pixel)/8) << 16;
467
468 writel(reg, fbi->regs + (par->head == HEAD_CRT ?
469 SM501_DC_CRT_FB_OFFSET : SM501_DC_PANEL_FB_OFFSET));
470
471 /* program horizontal total */
472
473 reg = (h_total(var) - 1) << 16;
474 reg |= (var->xres - 1);
475
476 writel(reg, base + SM501_OFF_DC_H_TOT);
477
478 /* program horizontal sync */
479
480 reg = var->hsync_len << 16;
481 reg |= var->xres + var->right_margin - 1;
482
483 writel(reg, base + SM501_OFF_DC_H_SYNC);
484
485 /* program vertical total */
486
487 reg = (v_total(var) - 1) << 16;
488 reg |= (var->yres - 1);
489
490 writel(reg, base + SM501_OFF_DC_V_TOT);
491
492 /* program vertical sync */
493 reg = var->vsync_len << 16;
494 reg |= var->yres + var->lower_margin - 1;
495
496 writel(reg, base + SM501_OFF_DC_V_SYNC);
497}
498
499/* sm501fb_pan_crt
500 *
501 * pan the CRT display output within an virtual framebuffer
502*/
503
504static int sm501fb_pan_crt(struct fb_var_screeninfo *var,
505 struct fb_info *info)
506{
507 struct sm501fb_par *par = info->par;
508 struct sm501fb_info *fbi = par->info;
509 unsigned int bytes_pixel = var->bits_per_pixel / 8;
510 unsigned long reg;
511 unsigned long xoffs;
512
513 xoffs = var->xoffset * bytes_pixel;
514
515 reg = readl(fbi->regs + SM501_DC_CRT_CONTROL);
516
517 reg &= ~SM501_DC_CRT_CONTROL_PIXEL_MASK;
518 reg |= ((xoffs & 15) / bytes_pixel) << 4;
519 writel(reg, fbi->regs + SM501_DC_CRT_CONTROL);
520
521 reg = (par->screen.sm_addr + xoffs +
522 var->yoffset * info->fix.line_length);
523 writel(reg | SM501_ADDR_FLIP, fbi->regs + SM501_DC_CRT_FB_ADDR);
524
525 sm501fb_sync_regs(fbi);
526 return 0;
527}
528
529/* sm501fb_pan_pnl
530 *
531 * pan the panel display output within an virtual framebuffer
532*/
533
534static int sm501fb_pan_pnl(struct fb_var_screeninfo *var,
535 struct fb_info *info)
536{
537 struct sm501fb_par *par = info->par;
538 struct sm501fb_info *fbi = par->info;
539 unsigned long reg;
540
541 reg = var->xoffset | (var->xres_virtual << 16);
542 writel(reg, fbi->regs + SM501_DC_PANEL_FB_WIDTH);
543
544 reg = var->yoffset | (var->yres_virtual << 16);
545 writel(reg, fbi->regs + SM501_DC_PANEL_FB_HEIGHT);
546
547 sm501fb_sync_regs(fbi);
548 return 0;
549}
550
551/* sm501fb_set_par_crt
552 *
553 * Set the CRT video mode from the fb_info structure
554*/
555
556static int sm501fb_set_par_crt(struct fb_info *info)
557{
558 struct sm501fb_par *par = info->par;
559 struct sm501fb_info *fbi = par->info;
560 struct fb_var_screeninfo *var = &info->var;
561 unsigned long control; /* control register */
562 int ret;
563
564 /* activate new configuration */
565
566 dev_dbg(fbi->dev, "%s(%p)\n", __func__, info);
567
568 /* enable CRT DAC - note 0 is on!*/
569 sm501_misc_control(fbi->dev->parent, 0, SM501_MISC_DAC_POWER);
570
571 control = readl(fbi->regs + SM501_DC_CRT_CONTROL);
572
573 control &= (SM501_DC_CRT_CONTROL_PIXEL_MASK |
574 SM501_DC_CRT_CONTROL_GAMMA |
575 SM501_DC_CRT_CONTROL_BLANK |
576 SM501_DC_CRT_CONTROL_SEL |
577 SM501_DC_CRT_CONTROL_CP |
578 SM501_DC_CRT_CONTROL_TVP);
579
580 /* set the sync polarities before we check data source */
581
582 if ((var->sync & FB_SYNC_HOR_HIGH_ACT) == 0)
583 control |= SM501_DC_CRT_CONTROL_HSP;
584
585 if ((var->sync & FB_SYNC_VERT_HIGH_ACT) == 0)
586 control |= SM501_DC_CRT_CONTROL_VSP;
587
588 if ((control & SM501_DC_CRT_CONTROL_SEL) == 0) {
589 /* the head is displaying panel data... */
590
591 sm501_alloc_mem(fbi, &par->screen, SM501_MEMF_CRT, 0);
592 goto out_update;
593 }
594
595 ret = sm501fb_set_par_common(info, var);
596 if (ret) {
597 dev_err(fbi->dev, "failed to set common parameters\n");
598 return ret;
599 }
600
601 sm501fb_pan_crt(var, info);
602 sm501fb_set_par_geometry(info, var);
603
604 control |= SM501_FIFO_3; /* fill if >3 free slots */
605
606 switch(var->bits_per_pixel) {
607 case 8:
608 control |= SM501_DC_CRT_CONTROL_8BPP;
609 break;
610
611 case 16:
612 control |= SM501_DC_CRT_CONTROL_16BPP;
613 break;
614
615 case 32:
616 control |= SM501_DC_CRT_CONTROL_32BPP;
617 sm501fb_setup_gamma(fbi, SM501_DC_CRT_PALETTE);
618 break;
619
620 default:
621 BUG();
622 }
623
624 control |= SM501_DC_CRT_CONTROL_SEL; /* CRT displays CRT data */
625 control |= SM501_DC_CRT_CONTROL_TE; /* enable CRT timing */
626 control |= SM501_DC_CRT_CONTROL_ENABLE; /* enable CRT plane */
627
628 out_update:
629 dev_dbg(fbi->dev, "new control is %08lx\n", control);
630
631 writel(control, fbi->regs + SM501_DC_CRT_CONTROL);
632 sm501fb_sync_regs(fbi);
633
634 return 0;
635}
636
637static void sm501fb_panel_power(struct sm501fb_info *fbi, int to)
638{
639 unsigned long control;
640 void __iomem *ctrl_reg = fbi->regs + SM501_DC_PANEL_CONTROL;
641
642 control = readl(ctrl_reg);
643
644 if (to && (control & SM501_DC_PANEL_CONTROL_VDD) == 0) {
645 /* enable panel power */
646
647 control |= SM501_DC_PANEL_CONTROL_VDD; /* FPVDDEN */
648 writel(control, ctrl_reg);
649 sm501fb_sync_regs(fbi);
650 mdelay(10);
651
652 control |= SM501_DC_PANEL_CONTROL_DATA; /* DATA */
653 writel(control, ctrl_reg);
654 sm501fb_sync_regs(fbi);
655 mdelay(10);
656
657 control |= SM501_DC_PANEL_CONTROL_BIAS; /* VBIASEN */
658 writel(control, ctrl_reg);
659 sm501fb_sync_regs(fbi);
660 mdelay(10);
661
662 control |= SM501_DC_PANEL_CONTROL_FPEN;
663 writel(control, ctrl_reg);
664
665 } else if (!to && (control & SM501_DC_PANEL_CONTROL_VDD) != 0) {
666 /* disable panel power */
667
668 control &= ~SM501_DC_PANEL_CONTROL_FPEN;
669 writel(control, ctrl_reg);
670 sm501fb_sync_regs(fbi);
671 mdelay(10);
672
673 control &= ~SM501_DC_PANEL_CONTROL_BIAS;
674 writel(control, ctrl_reg);
675 sm501fb_sync_regs(fbi);
676 mdelay(10);
677
678 control &= ~SM501_DC_PANEL_CONTROL_DATA;
679 writel(control, ctrl_reg);
680 sm501fb_sync_regs(fbi);
681 mdelay(10);
682
683 control &= ~SM501_DC_PANEL_CONTROL_VDD;
684 writel(control, ctrl_reg);
685 sm501fb_sync_regs(fbi);
686 mdelay(10);
687 }
688
689 sm501fb_sync_regs(fbi);
690}
691
692/* sm501fb_set_par_pnl
693 *
694 * Set the panel video mode from the fb_info structure
695*/
696
697static int sm501fb_set_par_pnl(struct fb_info *info)
698{
699 struct sm501fb_par *par = info->par;
700 struct sm501fb_info *fbi = par->info;
701 struct fb_var_screeninfo *var = &info->var;
702 unsigned long control;
703 unsigned long reg;
704 int ret;
705
706 dev_dbg(fbi->dev, "%s(%p)\n", __func__, info);
707
708 /* activate this new configuration */
709
710 ret = sm501fb_set_par_common(info, var);
711 if (ret)
712 return ret;
713
714 sm501fb_pan_pnl(var, info);
715 sm501fb_set_par_geometry(info, var);
716
717 /* update control register */
718
719 control = readl(fbi->regs + SM501_DC_PANEL_CONTROL);
720 control &= (SM501_DC_PANEL_CONTROL_GAMMA |
721 SM501_DC_PANEL_CONTROL_VDD |
722 SM501_DC_PANEL_CONTROL_DATA |
723 SM501_DC_PANEL_CONTROL_BIAS |
724 SM501_DC_PANEL_CONTROL_FPEN |
725 SM501_DC_PANEL_CONTROL_CP |
726 SM501_DC_PANEL_CONTROL_CK |
727 SM501_DC_PANEL_CONTROL_HP |
728 SM501_DC_PANEL_CONTROL_VP |
729 SM501_DC_PANEL_CONTROL_HPD |
730 SM501_DC_PANEL_CONTROL_VPD);
731
732 control |= SM501_FIFO_3; /* fill if >3 free slots */
733
734 switch(var->bits_per_pixel) {
735 case 8:
736 control |= SM501_DC_PANEL_CONTROL_8BPP;
737 break;
738
739 case 16:
740 control |= SM501_DC_PANEL_CONTROL_16BPP;
741 break;
742
743 case 32:
744 control |= SM501_DC_PANEL_CONTROL_32BPP;
745 sm501fb_setup_gamma(fbi, SM501_DC_PANEL_PALETTE);
746 break;
747
748 default:
749 BUG();
750 }
751
752 writel(0x0, fbi->regs + SM501_DC_PANEL_PANNING_CONTROL);
753
754 /* panel plane top left and bottom right location */
755
756 writel(0x00, fbi->regs + SM501_DC_PANEL_TL_LOC);
757
758 reg = var->xres - 1;
759 reg |= (var->yres - 1) << 16;
760
761 writel(reg, fbi->regs + SM501_DC_PANEL_BR_LOC);
762
763 /* program panel control register */
764
765 control |= SM501_DC_PANEL_CONTROL_TE; /* enable PANEL timing */
766 control |= SM501_DC_PANEL_CONTROL_EN; /* enable PANEL gfx plane */
767
768 if ((var->sync & FB_SYNC_HOR_HIGH_ACT) == 0)
769 control |= SM501_DC_PANEL_CONTROL_HSP;
770
771 if ((var->sync & FB_SYNC_VERT_HIGH_ACT) == 0)
772 control |= SM501_DC_PANEL_CONTROL_VSP;
773
774 writel(control, fbi->regs + SM501_DC_PANEL_CONTROL);
775 sm501fb_sync_regs(fbi);
776
777 /* power the panel up */
778 sm501fb_panel_power(fbi, 1);
779 return 0;
780}
781
782
783/* chan_to_field
784 *
785 * convert a colour value into a field position
786 *
787 * from pxafb.c
788*/
789
790static inline unsigned int chan_to_field(unsigned int chan,
791 struct fb_bitfield *bf)
792{
793 chan &= 0xffff;
794 chan >>= 16 - bf->length;
795 return chan << bf->offset;
796}
797
798/* sm501fb_setcolreg
799 *
800 * set the colour mapping for modes that support palettised data
801*/
802
803static int sm501fb_setcolreg(unsigned regno,
804 unsigned red, unsigned green, unsigned blue,
805 unsigned transp, struct fb_info *info)
806{
807 struct sm501fb_par *par = info->par;
808 struct sm501fb_info *fbi = par->info;
809 void __iomem *base = fbi->regs;
810 unsigned int val;
811
812 if (par->head == HEAD_CRT)
813 base += SM501_DC_CRT_PALETTE;
814 else
815 base += SM501_DC_PANEL_PALETTE;
816
817 switch (info->fix.visual) {
818 case FB_VISUAL_TRUECOLOR:
819 /* true-colour, use pseuo-palette */
820
821 if (regno < 16) {
822 u32 *pal = par->pseudo_palette;
823
824 val = chan_to_field(red, &info->var.red);
825 val |= chan_to_field(green, &info->var.green);
826 val |= chan_to_field(blue, &info->var.blue);
827
828 pal[regno] = val;
829 }
830 break;
831
832 case FB_VISUAL_PSEUDOCOLOR:
833 if (regno < 256) {
834 val = (red >> 8) << 16;
835 val |= (green >> 8) << 8;
836 val |= blue >> 8;
837
838 writel(val, base + (regno * 4));
839 }
840
841 break;
842
843 default:
844 return 1; /* unknown type */
845 }
846
847 return 0;
848}
849
850/* sm501fb_blank_pnl
851 *
852 * Blank or un-blank the panel interface
853*/
854
855static int sm501fb_blank_pnl(int blank_mode, struct fb_info *info)
856{
857 struct sm501fb_par *par = info->par;
858 struct sm501fb_info *fbi = par->info;
859
860 dev_dbg(fbi->dev, "%s(mode=%d, %p)\n", __func__, blank_mode, info);
861
862 switch (blank_mode) {
863 case FB_BLANK_POWERDOWN:
864 sm501fb_panel_power(fbi, 0);
865 break;
866
867 case FB_BLANK_UNBLANK:
868 sm501fb_panel_power(fbi, 1);
869 break;
870
871 case FB_BLANK_NORMAL:
872 case FB_BLANK_VSYNC_SUSPEND:
873 case FB_BLANK_HSYNC_SUSPEND:
874 default:
875 return 1;
876 }
877
878 return 0;
879}
880
881/* sm501fb_blank_crt
882 *
883 * Blank or un-blank the crt interface
884*/
885
886static int sm501fb_blank_crt(int blank_mode, struct fb_info *info)
887{
888 struct sm501fb_par *par = info->par;
889 struct sm501fb_info *fbi = par->info;
890 unsigned long ctrl;
891
892 dev_dbg(fbi->dev, "%s(mode=%d, %p)\n", __func__, blank_mode, info);
893
894 ctrl = readl(fbi->regs + SM501_DC_CRT_CONTROL);
895
896 switch (blank_mode) {
897 case FB_BLANK_POWERDOWN:
898 ctrl &= ~SM501_DC_CRT_CONTROL_ENABLE;
899 sm501_misc_control(fbi->dev->parent, SM501_MISC_DAC_POWER, 0);
900
901 case FB_BLANK_NORMAL:
902 ctrl |= SM501_DC_CRT_CONTROL_BLANK;
903 break;
904
905 case FB_BLANK_UNBLANK:
906 ctrl &= ~SM501_DC_CRT_CONTROL_BLANK;
907 ctrl |= SM501_DC_CRT_CONTROL_ENABLE;
908 sm501_misc_control(fbi->dev->parent, 0, SM501_MISC_DAC_POWER);
909 break;
910
911 case FB_BLANK_VSYNC_SUSPEND:
912 case FB_BLANK_HSYNC_SUSPEND:
913 default:
914 return 1;
915
916 }
917
918 writel(ctrl, fbi->regs + SM501_DC_CRT_CONTROL);
919 sm501fb_sync_regs(fbi);
920
921 return 0;
922}
923
924/* sm501fb_cursor
925 *
926 * set or change the hardware cursor parameters
927*/
928
929static int sm501fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
930{
931 struct sm501fb_par *par = info->par;
932 struct sm501fb_info *fbi = par->info;
933 void __iomem *base = fbi->regs;
934 unsigned long hwc_addr;
935 unsigned long fg, bg;
936
937 dev_dbg(fbi->dev, "%s(%p,%p)\n", __func__, info, cursor);
938
939 if (par->head == HEAD_CRT)
940 base += SM501_DC_CRT_HWC_BASE;
941 else
942 base += SM501_DC_PANEL_HWC_BASE;
943
944 /* check not being asked to exceed capabilities */
945
946 if (cursor->image.width > 64)
947 return -EINVAL;
948
949 if (cursor->image.height > 64)
950 return -EINVAL;
951
952 if (cursor->image.depth > 1)
953 return -EINVAL;
954
955 hwc_addr = readl(base + SM501_OFF_HWC_ADDR);
956
957 if (cursor->enable)
958 writel(hwc_addr | SM501_HWC_EN, base + SM501_OFF_HWC_ADDR);
959 else
960 writel(hwc_addr & ~SM501_HWC_EN, base + SM501_OFF_HWC_ADDR);
961
962 /* set data */
963 if (cursor->set & FB_CUR_SETPOS) {
964 unsigned int x = cursor->image.dx;
965 unsigned int y = cursor->image.dy;
966
967 if (x >= 2048 || y >= 2048 )
968 return -EINVAL;
969
970 dev_dbg(fbi->dev, "set position %d,%d\n", x, y);
971
972 //y += cursor->image.height;
973
974 writel(x | (y << 16), base + SM501_OFF_HWC_LOC);
975 }
976
977 if (cursor->set & FB_CUR_SETCMAP) {
978 unsigned int bg_col = cursor->image.bg_color;
979 unsigned int fg_col = cursor->image.fg_color;
980
981 dev_dbg(fbi->dev, "%s: update cmap (%08x,%08x)\n",
982 __func__, bg_col, fg_col);
983
984 bg = ((info->cmap.red[bg_col] & 0xF8) << 8) |
985 ((info->cmap.green[bg_col] & 0xFC) << 3) |
986 ((info->cmap.blue[bg_col] & 0xF8) >> 3);
987
988 fg = ((info->cmap.red[fg_col] & 0xF8) << 8) |
989 ((info->cmap.green[fg_col] & 0xFC) << 3) |
990 ((info->cmap.blue[fg_col] & 0xF8) >> 3);
991
992 dev_dbg(fbi->dev, "fgcol %08x, bgcol %08x\n", fg, bg);
993
994 writel(bg, base + SM501_OFF_HWC_COLOR_1_2);
995 writel(fg, base + SM501_OFF_HWC_COLOR_3);
996 }
997
998 if (cursor->set & FB_CUR_SETSIZE ||
999 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE)) {
1000 /* SM501 cursor is a two bpp 64x64 bitmap this routine
1001 * clears it to transparent then combines the cursor
1002 * shape plane with the colour plane to set the
1003 * cursor */
1004 int x, y;
1005 const unsigned char *pcol = cursor->image.data;
1006 const unsigned char *pmsk = cursor->mask;
1007 void __iomem *dst = par->cursor.k_addr;
1008 unsigned char dcol = 0;
1009 unsigned char dmsk = 0;
1010 unsigned int op;
1011
1012 dev_dbg(fbi->dev, "%s: setting shape (%d,%d)\n",
1013 __func__, cursor->image.width, cursor->image.height);
1014
1015 for (op = 0; op < (64*64*2)/8; op+=4)
1016 writel(0x0, dst + op);
1017
1018 for (y = 0; y < cursor->image.height; y++) {
1019 for (x = 0; x < cursor->image.width; x++) {
1020 if ((x % 8) == 0) {
1021 dcol = *pcol++;
1022 dmsk = *pmsk++;
1023 } else {
1024 dcol >>= 1;
1025 dmsk >>= 1;
1026 }
1027
1028 if (dmsk & 1) {
1029 op = (dcol & 1) ? 1 : 3;
1030 op <<= ((x % 4) * 2);
1031
1032 op |= readb(dst + (x / 4));
1033 writeb(op, dst + (x / 4));
1034 }
1035 }
1036 dst += (64*2)/8;
1037 }
1038 }
1039
1040 sm501fb_sync_regs(fbi); /* ensure cursor data flushed */
1041 return 0;
1042}
1043
1044/* sm501fb_crtsrc_show
1045 *
1046 * device attribute code to show where the crt output is sourced from
1047*/
1048
1049static ssize_t sm501fb_crtsrc_show(struct device *dev,
1050 struct device_attribute *attr, char *buf)
1051{
1052 struct sm501fb_info *info = dev_get_drvdata(dev);
1053 unsigned long ctrl;
1054
1055 ctrl = readl(info->regs + SM501_DC_CRT_CONTROL);
1056 ctrl &= SM501_DC_CRT_CONTROL_SEL;
1057
1058 return snprintf(buf, PAGE_SIZE, "%s\n", ctrl ? "crt" : "panel");
1059}
1060
1061/* sm501fb_crtsrc_show
1062 *
1063 * device attribute code to set where the crt output is sourced from
1064*/
1065
1066static ssize_t sm501fb_crtsrc_store(struct device *dev,
1067 struct device_attribute *attr,
1068 const char *buf, size_t len)
1069{
1070 struct sm501fb_info *info = dev_get_drvdata(dev);
1071 enum sm501_controller head;
1072 unsigned long ctrl;
1073
1074 if (len < 1)
1075 return -EINVAL;
1076
1077 if (strnicmp(buf, "crt", 3) == 0)
1078 head = HEAD_CRT;
1079 else if (strnicmp(buf, "panel", 5) == 0)
1080 head = HEAD_PANEL;
1081 else
1082 return -EINVAL;
1083
1084 dev_info(dev, "setting crt source to head %d\n", head);
1085
1086 ctrl = readl(info->regs + SM501_DC_CRT_CONTROL);
1087
1088 if (head == HEAD_CRT) {
1089 ctrl |= SM501_DC_CRT_CONTROL_SEL;
1090 ctrl |= SM501_DC_CRT_CONTROL_ENABLE;
1091 ctrl |= SM501_DC_CRT_CONTROL_TE;
1092 } else {
1093 ctrl &= ~SM501_DC_CRT_CONTROL_SEL;
1094 ctrl &= ~SM501_DC_CRT_CONTROL_ENABLE;
1095 ctrl &= ~SM501_DC_CRT_CONTROL_TE;
1096 }
1097
1098 writel(ctrl, info->regs + SM501_DC_CRT_CONTROL);
1099 sm501fb_sync_regs(info);
1100
1101 return len;
1102}
1103
1104/* Prepare the device_attr for registration with sysfs later */
1105static DEVICE_ATTR(crt_src, 0666, sm501fb_crtsrc_show, sm501fb_crtsrc_store);
1106
1107/* sm501fb_show_regs
1108 *
1109 * show the primary sm501 registers
1110*/
1111static int sm501fb_show_regs(struct sm501fb_info *info, char *ptr,
1112 unsigned int start, unsigned int len)
1113{
1114 void __iomem *mem = info->regs;
1115 char *buf = ptr;
1116 unsigned int reg;
1117
1118 for (reg = start; reg < (len + start); reg += 4)
1119 ptr += sprintf(ptr, "%08x = %08x\n", reg, readl(mem + reg));
1120
1121 return ptr - buf;
1122}
1123
1124/* sm501fb_debug_show_crt
1125 *
1126 * show the crt control and cursor registers
1127*/
1128
1129static ssize_t sm501fb_debug_show_crt(struct device *dev,
1130 struct device_attribute *attr, char *buf)
1131{
1132 struct sm501fb_info *info = dev_get_drvdata(dev);
1133 char *ptr = buf;
1134
1135 ptr += sm501fb_show_regs(info, ptr, SM501_DC_CRT_CONTROL, 0x40);
1136 ptr += sm501fb_show_regs(info, ptr, SM501_DC_CRT_HWC_BASE, 0x10);
1137
1138 return ptr - buf;
1139}
1140
1141static DEVICE_ATTR(fbregs_crt, 0444, sm501fb_debug_show_crt, NULL);
1142
1143/* sm501fb_debug_show_pnl
1144 *
1145 * show the panel control and cursor registers
1146*/
1147
1148static ssize_t sm501fb_debug_show_pnl(struct device *dev,
1149 struct device_attribute *attr, char *buf)
1150{
1151 struct sm501fb_info *info = dev_get_drvdata(dev);
1152 char *ptr = buf;
1153
1154 ptr += sm501fb_show_regs(info, ptr, 0x0, 0x40);
1155 ptr += sm501fb_show_regs(info, ptr, SM501_DC_PANEL_HWC_BASE, 0x10);
1156
1157 return ptr - buf;
1158}
1159
1160static DEVICE_ATTR(fbregs_pnl, 0444, sm501fb_debug_show_pnl, NULL);
1161
1162/* framebuffer ops */
1163
1164static struct fb_ops sm501fb_ops_crt = {
1165 .owner = THIS_MODULE,
1166 .fb_check_var = sm501fb_check_var_crt,
1167 .fb_set_par = sm501fb_set_par_crt,
1168 .fb_blank = sm501fb_blank_crt,
1169 .fb_setcolreg = sm501fb_setcolreg,
1170 .fb_pan_display = sm501fb_pan_crt,
1171 .fb_cursor = sm501fb_cursor,
1172 .fb_fillrect = cfb_fillrect,
1173 .fb_copyarea = cfb_copyarea,
1174 .fb_imageblit = cfb_imageblit,
1175};
1176
1177static struct fb_ops sm501fb_ops_pnl = {
1178 .owner = THIS_MODULE,
1179 .fb_check_var = sm501fb_check_var_pnl,
1180 .fb_set_par = sm501fb_set_par_pnl,
1181 .fb_pan_display = sm501fb_pan_pnl,
1182 .fb_blank = sm501fb_blank_pnl,
1183 .fb_setcolreg = sm501fb_setcolreg,
1184 .fb_cursor = sm501fb_cursor,
1185 .fb_fillrect = cfb_fillrect,
1186 .fb_copyarea = cfb_copyarea,
1187 .fb_imageblit = cfb_imageblit,
1188};
1189
1190/* sm501fb_info_alloc
1191 *
1192 * creates and initialises an sm501fb_info structure
1193*/
1194
1195static struct sm501fb_info *sm501fb_info_alloc(struct fb_info *fbinfo_crt,
1196 struct fb_info *fbinfo_pnl)
1197{
1198 struct sm501fb_info *info;
1199 struct sm501fb_par *par;
1200
1201 info = kzalloc(sizeof(struct sm501fb_info), GFP_KERNEL);
1202 if (info) {
1203 /* set the references back */
1204
1205 par = fbinfo_crt->par;
1206 par->info = info;
1207 par->head = HEAD_CRT;
1208 fbinfo_crt->pseudo_palette = &par->pseudo_palette;
1209
1210 par = fbinfo_pnl->par;
1211 par->info = info;
1212 par->head = HEAD_PANEL;
1213 fbinfo_pnl->pseudo_palette = &par->pseudo_palette;
1214
1215 /* store the two fbs into our info */
1216 info->fb[HEAD_CRT] = fbinfo_crt;
1217 info->fb[HEAD_PANEL] = fbinfo_pnl;
1218 }
1219
1220 return info;
1221}
1222
1223/* sm501_init_cursor
1224 *
1225 * initialise hw cursor parameters
1226*/
1227
1228static int sm501_init_cursor(struct fb_info *fbi, unsigned int reg_base)
1229{
1230 struct sm501fb_par *par = fbi->par;
1231 struct sm501fb_info *info = par->info;
1232 int ret;
1233
1234 par->cursor_regs = info->regs + reg_base;
1235
1236 ret = sm501_alloc_mem(info, &par->cursor, SM501_MEMF_CURSOR, 1024);
1237 if (ret < 0)
1238 return ret;
1239
1240 /* initialise the colour registers */
1241
1242 writel(par->cursor.sm_addr, par->cursor_regs + SM501_OFF_HWC_ADDR);
1243
1244 writel(0x00, par->cursor_regs + SM501_OFF_HWC_LOC);
1245 writel(0x00, par->cursor_regs + SM501_OFF_HWC_COLOR_1_2);
1246 writel(0x00, par->cursor_regs + SM501_OFF_HWC_COLOR_3);
1247 sm501fb_sync_regs(info);
1248
1249 return 0;
1250}
1251
1252/* sm501fb_info_start
1253 *
1254 * fills the par structure claiming resources and remapping etc.
1255*/
1256
1257static int sm501fb_start(struct sm501fb_info *info,
1258 struct platform_device *pdev)
1259{
1260 struct resource *res;
1261 struct device *dev;
1262 int ret;
1263
1264 info->dev = dev = &pdev->dev;
1265 platform_set_drvdata(pdev, info);
1266
1267 info->irq = ret = platform_get_irq(pdev, 0);
1268 if (ret < 0) {
1269 /* we currently do not use the IRQ */
1270 dev_warn(dev, "no irq for device\n");
1271 }
1272
1273 /* allocate, reserve and remap resources for registers */
1274 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1275 if (res == NULL) {
1276 dev_err(dev, "no resource definition for registers\n");
1277 ret = -ENOENT;
1278 goto err_release;
1279 }
1280
1281 info->regs_res = request_mem_region(res->start,
1282 res->end - res->start,
1283 pdev->name);
1284
1285 if (info->regs_res == NULL) {
1286 dev_err(dev, "cannot claim registers\n");
1287 ret = -ENXIO;
1288 goto err_release;
1289 }
1290
1291 info->regs = ioremap(res->start, (res->end - res->start)+1);
1292 if (info->regs == NULL) {
1293 dev_err(dev, "cannot remap registers\n");
1294 ret = -ENXIO;
1295 goto err_regs_res;
1296 }
1297
1298 /* allocate, reserve resources for framebuffer */
1299 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
1300 if (res == NULL) {
1301 dev_err(dev, "no memory resource defined\n");
1302 ret = -ENXIO;
1303 goto err_regs_map;
1304 }
1305
1306 info->fbmem_res = request_mem_region(res->start,
1307 (res->end - res->start)+1,
1308 pdev->name);
1309 if (info->fbmem_res == NULL) {
1310 dev_err(dev, "cannot claim framebuffer\n");
1311 ret = -ENXIO;
1312 goto err_regs_map;
1313 }
1314
1315 info->fbmem = ioremap(res->start, (res->end - res->start)+1);
1316 if (info->fbmem == NULL) {
1317 dev_err(dev, "cannot remap framebuffer\n");
1318 goto err_mem_res;
1319 }
1320
1321 info->fbmem_len = (res->end - res->start)+1;
1322
1323 /* enable display controller */
1324 sm501_unit_power(dev->parent, SM501_GATE_DISPLAY, 1);
1325
1326 /* setup cursors */
1327
1328 sm501_init_cursor(info->fb[HEAD_CRT], SM501_DC_CRT_HWC_ADDR);
1329 sm501_init_cursor(info->fb[HEAD_PANEL], SM501_DC_PANEL_HWC_ADDR);
1330
1331 return 0; /* everything is setup */
1332
1333 err_mem_res:
1334 release_resource(info->fbmem_res);
1335 kfree(info->fbmem_res);
1336
1337 err_regs_map:
1338 iounmap(info->regs);
1339
1340 err_regs_res:
1341 release_resource(info->regs_res);
1342 kfree(info->regs_res);
1343
1344 err_release:
1345 return ret;
1346}
1347
1348static void sm501fb_stop(struct sm501fb_info *info)
1349{
1350 /* disable display controller */
1351 sm501_unit_power(info->dev->parent, SM501_GATE_DISPLAY, 0);
1352
1353 iounmap(info->fbmem);
1354 release_resource(info->fbmem_res);
1355 kfree(info->fbmem_res);
1356
1357 iounmap(info->regs);
1358 release_resource(info->regs_res);
1359 kfree(info->regs_res);
1360}
1361
1362static void sm501fb_info_release(struct sm501fb_info *info)
1363{
1364 kfree(info);
1365}
1366
1367static int sm501fb_init_fb(struct fb_info *fb,
1368 enum sm501_controller head,
1369 const char *fbname)
1370{
1371 struct sm501_platdata_fbsub *pd;
1372 struct sm501fb_par *par = fb->par;
1373 struct sm501fb_info *info = par->info;
1374 unsigned long ctrl;
1375 unsigned int enable;
1376 int ret;
1377
1378 switch (head) {
1379 case HEAD_CRT:
1380 pd = info->pdata->fb_crt;
1381 ctrl = readl(info->regs + SM501_DC_CRT_CONTROL);
1382 enable = (ctrl & SM501_DC_CRT_CONTROL_ENABLE) ? 1 : 0;
1383
1384 /* ensure we set the correct source register */
1385 if (info->pdata->fb_route != SM501_FB_CRT_PANEL) {
1386 ctrl |= SM501_DC_CRT_CONTROL_SEL;
1387 writel(ctrl, info->regs + SM501_DC_CRT_CONTROL);
1388 }
1389
1390 break;
1391
1392 case HEAD_PANEL:
1393 pd = info->pdata->fb_pnl;
1394 ctrl = readl(info->regs + SM501_DC_PANEL_CONTROL);
1395 enable = (ctrl & SM501_DC_PANEL_CONTROL_EN) ? 1 : 0;
1396 break;
1397
1398 default:
1399 pd = NULL; /* stop compiler warnings */
1400 ctrl = 0;
1401 enable = 0;
1402 BUG();
1403 }
1404
1405 dev_info(info->dev, "fb %s %sabled at start\n",
1406 fbname, enable ? "en" : "dis");
1407
1408 /* check to see if our routing allows this */
1409
1410 if (head == HEAD_CRT && info->pdata->fb_route == SM501_FB_CRT_PANEL) {
1411 ctrl &= ~SM501_DC_CRT_CONTROL_SEL;
1412 writel(ctrl, info->regs + SM501_DC_CRT_CONTROL);
1413 enable = 0;
1414 }
1415
1416 strlcpy(fb->fix.id, fbname, sizeof(fb->fix.id));
1417
1418 memcpy(&par->ops,
1419 (head == HEAD_CRT) ? &sm501fb_ops_crt : &sm501fb_ops_pnl,
1420 sizeof(struct fb_ops));
1421
1422 /* update ops dependant on what we've been passed */
1423
1424 if ((pd->flags & SM501FB_FLAG_USE_HWCURSOR) == 0)
1425 par->ops.fb_cursor = NULL;
1426
1427 fb->fbops = &par->ops;
1428 fb->flags = FBINFO_FLAG_DEFAULT |
1429 FBINFO_HWACCEL_XPAN | FBINFO_HWACCEL_YPAN;
1430
1431 /* fixed data */
1432
1433 fb->fix.type = FB_TYPE_PACKED_PIXELS;
1434 fb->fix.type_aux = 0;
1435 fb->fix.xpanstep = 1;
1436 fb->fix.ypanstep = 1;
1437 fb->fix.ywrapstep = 0;
1438 fb->fix.accel = FB_ACCEL_NONE;
1439
1440 /* screenmode */
1441
1442 fb->var.nonstd = 0;
1443 fb->var.activate = FB_ACTIVATE_NOW;
1444 fb->var.accel_flags = 0;
1445 fb->var.vmode = FB_VMODE_NONINTERLACED;
1446 fb->var.bits_per_pixel = 16;
1447
1448 if (enable && (pd->flags & SM501FB_FLAG_USE_INIT_MODE) && 0) {
1449 /* TODO read the mode from the current display */
1450
1451 } else {
1452 if (pd->def_mode) {
1453 dev_info(info->dev, "using supplied mode\n");
1454 fb_videomode_to_var(&fb->var, pd->def_mode);
1455
1456 fb->var.bits_per_pixel = pd->def_bpp ? pd->def_bpp : 8;
1457 fb->var.xres_virtual = fb->var.xres;
1458 fb->var.yres_virtual = fb->var.yres;
1459 } else {
1460 ret = fb_find_mode(&fb->var, fb,
1461 NULL, NULL, 0, NULL, 8);
1462
1463 if (ret == 0 || ret == 4) {
1464 dev_err(info->dev,
1465 "failed to get initial mode\n");
1466 return -EINVAL;
1467 }
1468 }
1469 }
1470
1471 /* initialise and set the palette */
1472 fb_alloc_cmap(&fb->cmap, NR_PALETTE, 0);
1473 fb_set_cmap(&fb->cmap, fb);
1474
1475 ret = (fb->fbops->fb_check_var)(&fb->var, fb);
1476 if (ret)
1477 dev_err(info->dev, "check_var() failed on initial setup?\n");
1478
1479 /* ensure we've activated our new configuration */
1480 (fb->fbops->fb_set_par)(fb);
1481
1482 return 0;
1483}
1484
1485/* default platform data if none is supplied (ie, PCI device) */
1486
1487static struct sm501_platdata_fbsub sm501fb_pdata_crt = {
1488 .flags = (SM501FB_FLAG_USE_INIT_MODE |
1489 SM501FB_FLAG_USE_HWCURSOR |
1490 SM501FB_FLAG_USE_HWACCEL |
1491 SM501FB_FLAG_DISABLE_AT_EXIT),
1492
1493};
1494
1495static struct sm501_platdata_fbsub sm501fb_pdata_pnl = {
1496 .flags = (SM501FB_FLAG_USE_INIT_MODE |
1497 SM501FB_FLAG_USE_HWCURSOR |
1498 SM501FB_FLAG_USE_HWACCEL |
1499 SM501FB_FLAG_DISABLE_AT_EXIT),
1500};
1501
1502static struct sm501_platdata_fb sm501fb_def_pdata = {
1503 .fb_route = SM501_FB_OWN,
1504 .fb_crt = &sm501fb_pdata_crt,
1505 .fb_pnl = &sm501fb_pdata_pnl,
1506};
1507
1508static char driver_name_crt[] = "sm501fb-crt";
1509static char driver_name_pnl[] = "sm501fb-panel";
1510
1511static int __init sm501fb_probe(struct platform_device *pdev)
1512{
1513 struct sm501fb_info *info;
1514 struct device *dev = &pdev->dev;
1515 struct fb_info *fbinfo_crt;
1516 struct fb_info *fbinfo_pnl;
1517 int ret;
1518
1519 /* allocate our framebuffers */
1520
1521 fbinfo_crt = framebuffer_alloc(sizeof(struct sm501fb_par), dev);
1522 if (fbinfo_crt == NULL) {
1523 dev_err(dev, "cannot allocate crt framebuffer\n");
1524 return -ENOMEM;
1525 }
1526
1527 fbinfo_pnl = framebuffer_alloc(sizeof(struct sm501fb_par), dev);
1528 if (fbinfo_pnl == NULL) {
1529 dev_err(dev, "cannot allocate panel framebuffer\n");
1530 ret = -ENOMEM;
1531 goto fbinfo_crt_alloc_fail;
1532 }
1533
1534 info = sm501fb_info_alloc(fbinfo_crt, fbinfo_pnl);
1535 if (info == NULL) {
1536 dev_err(dev, "cannot allocate par\n");
1537 ret = -ENOMEM;
1538 goto sm501fb_alloc_fail;
1539 }
1540
1541 if (dev->parent->platform_data) {
1542 struct sm501_platdata *pd = dev->parent->platform_data;
1543 info->pdata = pd->fb;
1544 }
1545
1546 if (info->pdata == NULL) {
1547 dev_info(dev, "using default configuration data\n");
1548 info->pdata = &sm501fb_def_pdata;
1549 }
1550
1551 /* start the framebuffers */
1552
1553 ret = sm501fb_start(info, pdev);
1554 if (ret) {
1555 dev_err(dev, "cannot initialise SM501\n");
1556 goto sm501fb_start_fail;
1557 }
1558
1559 /* CRT framebuffer setup */
1560
1561 ret = sm501fb_init_fb(fbinfo_crt, HEAD_CRT, driver_name_crt);
1562 if (ret) {
1563 dev_err(dev, "cannot initialise CRT fb\n");
1564 goto sm501fb_start_fail;
1565 }
1566
1567 /* Panel framebuffer setup */
1568
1569 ret = sm501fb_init_fb(fbinfo_pnl, HEAD_PANEL, driver_name_pnl);
1570 if (ret) {
1571 dev_err(dev, "cannot initialise Panel fb\n");
1572 goto sm501fb_start_fail;
1573 }
1574
1575 /* register framebuffers */
1576
1577 ret = register_framebuffer(fbinfo_crt);
1578 if (ret < 0) {
1579 dev_err(dev, "failed to register CRT fb (%d)\n", ret);
1580 goto register_crt_fail;
1581 }
1582
1583 ret = register_framebuffer(fbinfo_pnl);
1584 if (ret < 0) {
1585 dev_err(dev, "failed to register panel fb (%d)\n", ret);
1586 goto register_pnl_fail;
1587 }
1588
1589 dev_info(dev, "fb%d: %s frame buffer device\n",
1590 fbinfo_crt->node, fbinfo_crt->fix.id);
1591
1592 dev_info(dev, "fb%d: %s frame buffer device\n",
1593 fbinfo_pnl->node, fbinfo_pnl->fix.id);
1594
1595 /* create device files */
1596
1597 ret = device_create_file(dev, &dev_attr_crt_src);
1598 if (ret)
1599 goto crtsrc_fail;
1600
1601 ret = device_create_file(dev, &dev_attr_fbregs_pnl);
1602 if (ret)
1603 goto fbregs_pnl_fail;
1604
1605 ret = device_create_file(dev, &dev_attr_fbregs_crt);
1606 if (ret)
1607 goto fbregs_crt_fail;
1608
1609 /* we registered, return ok */
1610 return 0;
1611
1612 fbregs_crt_fail:
1613 device_remove_file(dev, &dev_attr_fbregs_pnl);
1614
1615 fbregs_pnl_fail:
1616 device_remove_file(dev, &dev_attr_crt_src);
1617
1618 crtsrc_fail:
1619 unregister_framebuffer(fbinfo_pnl);
1620
1621 register_pnl_fail:
1622 unregister_framebuffer(fbinfo_crt);
1623
1624 register_crt_fail:
1625 sm501fb_stop(info);
1626
1627 sm501fb_start_fail:
1628 sm501fb_info_release(info);
1629
1630 sm501fb_alloc_fail:
1631 framebuffer_release(fbinfo_pnl);
1632
1633 fbinfo_crt_alloc_fail:
1634 framebuffer_release(fbinfo_crt);
1635
1636 return ret;
1637}
1638
1639
1640/*
1641 * Cleanup
1642 */
1643static int sm501fb_remove(struct platform_device *pdev)
1644{
1645 struct sm501fb_info *info = platform_get_drvdata(pdev);
1646 struct fb_info *fbinfo_crt = info->fb[0];
1647 struct fb_info *fbinfo_pnl = info->fb[1];
1648
1649 device_remove_file(&pdev->dev, &dev_attr_fbregs_crt);
1650 device_remove_file(&pdev->dev, &dev_attr_fbregs_pnl);
1651 device_remove_file(&pdev->dev, &dev_attr_crt_src);
1652
1653 unregister_framebuffer(fbinfo_crt);
1654 unregister_framebuffer(fbinfo_pnl);
1655
1656 sm501fb_stop(info);
1657 sm501fb_info_release(info);
1658
1659 framebuffer_release(fbinfo_pnl);
1660 framebuffer_release(fbinfo_crt);
1661
1662 return 0;
1663}
1664
1665#ifdef CONFIG_PM
1666
1667static int sm501fb_suspend_fb(struct sm501fb_info *info,
1668 enum sm501_controller head)
1669{
1670 struct fb_info *fbi = info->fb[head];
1671 struct sm501fb_par *par = fbi->par;
1672
1673 if (par->screen.size == 0)
1674 return 0;
1675
1676 /* backup copies in case chip is powered down over suspend */
1677
1678 par->store_fb = vmalloc(par->screen.size);
1679 if (par->store_fb == NULL) {
1680 dev_err(info->dev, "no memory to store screen\n");
1681 return -ENOMEM;
1682 }
1683
1684 par->store_cursor = vmalloc(par->cursor.size);
1685 if (par->store_cursor == NULL) {
1686 dev_err(info->dev, "no memory to store cursor\n");
1687 goto err_nocursor;
1688 }
1689
1690 memcpy_fromio(par->store_fb, par->screen.k_addr, par->screen.size);
1691 memcpy_fromio(par->store_cursor, par->cursor.k_addr, par->cursor.size);
1692
1693 /* blank the relevant interface to ensure unit power minimised */
1694 (par->ops.fb_blank)(FB_BLANK_POWERDOWN, fbi);
1695
1696 return 0;
1697
1698 err_nocursor:
1699 vfree(par->store_fb);
1700
1701 return -ENOMEM;
1702
1703}
1704
1705static void sm501fb_resume_fb(struct sm501fb_info *info,
1706 enum sm501_controller head)
1707{
1708 struct fb_info *fbi = info->fb[head];
1709 struct sm501fb_par *par = fbi->par;
1710
1711 if (par->screen.size == 0)
1712 return;
1713
1714 /* re-activate the configuration */
1715
1716 (par->ops.fb_set_par)(fbi);
1717
1718 /* restore the data */
1719
1720 memcpy_toio(par->screen.k_addr, par->store_fb, par->screen.size);
1721 memcpy_toio(par->cursor.k_addr, par->store_cursor, par->cursor.size);
1722
1723 vfree(par->store_fb);
1724 vfree(par->store_cursor);
1725}
1726
1727
1728/* suspend and resume support */
1729
1730static int sm501fb_suspend(struct platform_device *pdev, pm_message_t state)
1731{
1732 struct sm501fb_info *info = platform_get_drvdata(pdev);
1733
1734 sm501fb_suspend_fb(info, HEAD_CRT);
1735 sm501fb_suspend_fb(info, HEAD_PANEL);
1736
1737 /* turn off the clocks, in case the device is not powered down */
1738 sm501_unit_power(info->dev->parent, SM501_GATE_DISPLAY, 0);
1739
1740 return 0;
1741}
1742
1743static int sm501fb_resume(struct platform_device *pdev)
1744{
1745 struct sm501fb_info *info = platform_get_drvdata(pdev);
1746
1747 sm501_unit_power(info->dev->parent, SM501_GATE_DISPLAY, 1);
1748
1749 sm501fb_resume_fb(info, HEAD_CRT);
1750 sm501fb_resume_fb(info, HEAD_PANEL);
1751
1752 return 0;
1753}
1754
1755#else
1756#define sm501fb_suspend NULL
1757#define sm501fb_resume NULL
1758#endif
1759
1760static struct platform_driver sm501fb_driver = {
1761 .probe = sm501fb_probe,
1762 .remove = sm501fb_remove,
1763 .suspend = sm501fb_suspend,
1764 .resume = sm501fb_resume,
1765 .driver = {
1766 .name = "sm501-fb",
1767 .owner = THIS_MODULE,
1768 },
1769};
1770
1771static int __devinit sm501fb_init(void)
1772{
1773 return platform_driver_register(&sm501fb_driver);
1774}
1775
1776static void __exit sm501fb_cleanup(void)
1777{
1778 platform_driver_unregister(&sm501fb_driver);
1779}
1780
1781module_init(sm501fb_init);
1782module_exit(sm501fb_cleanup);
1783
1784MODULE_AUTHOR("Ben Dooks, Vincent Sanders");
1785MODULE_DESCRIPTION("SM501 Framebuffer driver");
1786MODULE_LICENSE("GPL v2");